From 277c85dd41bf900491aed65ece2477acdf8fa6c9 Mon Sep 17 00:00:00 2001 From: golobitch Date: Sun, 5 May 2024 19:27:51 +0200 Subject: [PATCH 1/3] feat(env)default variables and rename some of them --- packages/auth/src/config/app.ts | 25 +++++++-------- packages/backend/src/config/app.ts | 51 +++++++++++++----------------- 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/packages/auth/src/config/app.ts b/packages/auth/src/config/app.ts index d738cd004c..138d99a6f5 100644 --- a/packages/auth/src/config/app.ts +++ b/packages/auth/src/config/app.ts @@ -1,9 +1,14 @@ -import * as crypto from 'crypto' import dotenv from 'dotenv' -function envString(name: string, value: string): string { +function envString(name: string, value?: string): string { const envValue = process.env[name] - return envValue == null ? value : envValue + if (envValue) return envValue + + if (typeof(value) === 'undefined') { + throw new Error(`Missing required key value (${name})`) + } + + return value } function envInt(name: string, value: number): number { @@ -36,17 +41,11 @@ export const Config = { 'AUTH_DATABASE_URL', 'postgresql://postgres:password@localhost:5432/auth_development' ), - identityServerDomain: envString( - 'IDENTITY_SERVER_DOMAIN', - 'http://localhost:3030/mock-idp/' - ), - identityServerSecret: envString('IDENTITY_SERVER_SECRET', 'replace-me'), - authServerDomain: envString( - 'AUTH_SERVER_DOMAIN', - `http://localhost:${envInt('AUTH_PORT', 3006)}` - ), + identityServerDomain: envString('IDENTITY_SERVER_URL'), + identityServerSecret: envString('IDENTITY_SERVER_SECRET'), + authServerDomain: envString('AUTH_SERVER_URL'), waitTimeSeconds: envInt('WAIT_SECONDS', 5), - cookieKey: envString('COOKIE_KEY', crypto.randomBytes(32).toString('hex')), + cookieKey: envString('COOKIE_KEY'), interactionExpirySeconds: envInt('INTERACTION_EXPIRY_SECONDS', 10 * 60), // Default 10 minutes accessTokenExpirySeconds: envInt('ACCESS_TOKEN_EXPIRY_SECONDS', 10 * 60), // Default 10 minutes databaseCleanupWorkers: envInt('DATABASE_CLEANUP_WORKERS', 1), diff --git a/packages/backend/src/config/app.ts b/packages/backend/src/config/app.ts index b60a6bd163..81cd91eec9 100644 --- a/packages/backend/src/config/app.ts +++ b/packages/backend/src/config/app.ts @@ -1,12 +1,17 @@ import { loadOrGenerateKey } from '@interledger/http-signature-utils' -import * as crypto from 'crypto' import dotenv from 'dotenv' import * as fs from 'fs' import { ConnectionOptions } from 'tls' -function envString(name: string, value: string): string { +function envString(name: string, value?: string): string { const envValue = process.env[name] - return envValue == null ? value : envValue + if (envValue) return envValue + + if (typeof(value) === 'undefined') { + throw new Error(`Missing required key value (${name})`) + } + + return value } function envStringArray(name: string, value: string[]): string[] { @@ -37,7 +42,7 @@ dotenv.config({ export const Config = { logLevel: envString('LOG_LEVEL', 'info'), - enableTelemetry: envBool('ENABLE_TELEMETRY', true), + enableTelemetry: envBool('ENABLE_TELEMETRY', false), livenet: envBool('LIVENET', false), openTelemetryCollectors: envStringArray( 'OPEN_TELEMETRY_COLLECTOR_URLS', @@ -59,7 +64,7 @@ export const Config = { 86_400_000 ), adminPort: envInt('ADMIN_PORT', 3001), - openPaymentsUrl: envString('OPEN_PAYMENTS_URL', 'http://127.0.0.1:3000'), + openPaymentsUrl: envString('OPEN_PAYMENTS_URL'), openPaymentsPort: envInt('OPEN_PAYMENTS_PORT', 3003), connectorPort: envInt('CONNECTOR_PORT', 3002), autoPeeringServerPort: envInt('AUTO_PEERING_SERVER_PORT', 3005), @@ -84,23 +89,17 @@ export const Config = { envString('REDIS_TLS_KEY_FILE_PATH', ''), envString('REDIS_TLS_CERT_FILE_PATH', '') ), - ilpAddress: envString('ILP_ADDRESS', 'test.rafiki'), - ilpConnectorAddress: envString( - 'ILP_CONNECTOR_ADDRESS', - 'http://127.0.0.1:3002' - ), - instanceName: envString('INSTANCE_NAME', 'Rafiki'), - streamSecret: process.env.STREAM_SECRET - ? Buffer.from(process.env.STREAM_SECRET, 'base64') - : crypto.randomBytes(32), - - useTigerbeetle: envBool('USE_TIGERBEETLE', false), + ilpAddress: envString('ILP_ADDRESS'), + ilpConnectorAddress: envString('ILP_CONNECTOR_ADDRESS'), + instanceName: envString('INSTANCE_NAME'), + streamSecret: Buffer.from(process.env.STREAM_SECRET as string, 'base64'), + useTigerbeetle: envBool('USE_TIGERBEETLE', true), tigerbeetleClusterId: envInt('TIGERBEETLE_CLUSTER_ID', 0), tigerbeetleReplicaAddresses: process.env.TIGERBEETLE_REPLICA_ADDRESSES ? process.env.TIGERBEETLE_REPLICA_ADDRESSES.split(',') : ['3004'], - exchangeRatesUrl: process.env.EXCHANGE_RATES_URL, // optional + exchangeRatesUrl: envString('EXCHANGE_RATES_URL'), exchangeRatesLifetime: +(process.env.EXCHANGE_RATES_LIFETIME || 15_000), slippage: envFloat('SLIPPAGE', 0.01), @@ -109,14 +108,8 @@ export const Config = { walletAddressWorkers: envInt('WALLET_ADDRESS_WORKERS', 1), walletAddressWorkerIdle: envInt('WALLET_ADDRESS_WORKER_IDLE', 200), // milliseconds - authServerGrantUrl: envString( - 'AUTH_SERVER_GRANT_URL', - 'http://127.0.0.1:3006' - ), - authServerIntrospectionUrl: envString( - 'AUTH_SERVER_INTROSPECTION_URL', - 'http://127.0.0.1:3007/' - ), + authServerGrantUrl: envString('AUTH_SERVER_GRANT_URL'), + authServerIntrospectionUrl: envString('AUTH_SERVER_INTROSPECTION_URL'), outgoingPaymentWorkers: envInt('OUTGOING_PAYMENT_WORKERS', 4), outgoingPaymentWorkerIdle: envInt('OUTGOING_PAYMENT_WORKER_IDLE', 200), // milliseconds @@ -126,7 +119,7 @@ export const Config = { webhookWorkers: envInt('WEBHOOK_WORKERS', 1), webhookWorkerIdle: envInt('WEBHOOK_WORKER_IDLE', 200), // milliseconds - webhookUrl: envString('WEBHOOK_URL', 'http://127.0.0.1:4001/webhook'), + webhookUrl: envString('WEBHOOK_URL'), webhookTimeout: envInt('WEBHOOK_TIMEOUT', 2000), // milliseconds webhookMaxRetry: envInt('WEBHOOK_MAX_RETRY', 10), @@ -135,13 +128,13 @@ export const Config = { ? undefined : +process.env.WITHDRAWAL_THROTTLE_DELAY, // optional - signatureSecret: process.env.SIGNATURE_SECRET, // optional + signatureSecret: envString('SIGNATURE_SECRET'), signatureVersion: envInt('SIGNATURE_VERSION', 1), apiSecret: process.env.API_SECRET, // optional apiSignatureVersion: envInt('API_SIGNATURE_VERSION', 1), - keyId: envString('KEY_ID', 'rafiki'), + keyId: envString('KEY_ID'), privateKey: loadOrGenerateKey(envString('PRIVATE_KEY_FILE', '')), graphQLIdempotencyKeyLockMs: envInt('GRAPHQL_IDEMPOTENCY_KEY_LOCK_MS', 2000), @@ -165,7 +158,7 @@ export const Config = { 'INCOMING_PAYMENT_EXPIRY_MAX_MS', 2592000000 ), // 30 days - spspEnabled: envBool('ENABLE_SPSP', true) + spspEnabled: envBool('ENABLE_INTERLEDGER_PAYMENT_POINTERS', true) } function parseRedisTlsConfig( From a831a5635396514727e531d2507b8a1e4b19f677 Mon Sep 17 00:00:00 2001 From: golobitch Date: Sun, 12 May 2024 13:30:59 +0200 Subject: [PATCH 2/3] feat(env)!: rename some env variables --- .../src/accounting/psql/balance.test.ts | 3 +- .../psql/ledger-account/index.test.ts | 3 +- .../psql/ledger-transfer/index.test.ts | 3 +- .../psql/ledger-transfer/model.test.ts | 3 +- .../src/accounting/psql/service.test.ts | 3 +- .../accounting/tigerbeetle/service.test.ts | 8 +- packages/backend/src/asset/model.test.ts | 3 +- packages/backend/src/asset/service.test.ts | 3 +- packages/backend/src/config/app.ts | 655 +++++++++++++----- packages/backend/src/fee/model.test.ts | 3 +- packages/backend/src/fee/service.test.ts | 3 +- .../src/graphql/middleware/index.test.ts | 3 +- .../src/graphql/resolvers/asset.test.ts | 3 +- .../graphql/resolvers/auto-peering.test.ts | 3 +- .../resolvers/combined_payments.test.ts | 2 +- .../backend/src/graphql/resolvers/fee.test.ts | 3 +- .../resolvers/incoming_payment.test.ts | 3 +- .../src/graphql/resolvers/index.test.ts | 3 +- .../src/graphql/resolvers/liquidity.test.ts | 2 +- .../resolvers/outgoing_payment.test.ts | 2 +- .../src/graphql/resolvers/peer.test.ts | 3 +- .../src/graphql/resolvers/quote.test.ts | 3 +- .../src/graphql/resolvers/receiver.test.ts | 3 +- .../resolvers/walletAddressKey.test.ts | 3 +- .../graphql/resolvers/wallet_address.test.ts | 3 +- .../src/graphql/resolvers/webhooks.test.ts | 3 +- packages/backend/src/index.ts | 16 +- .../src/open_payments/auth/middleware.test.ts | 6 +- .../open_payments/authServer/service.test.ts | 3 +- .../src/open_payments/grant/service.test.ts | 3 +- .../payment/combined/service.test.ts | 3 +- .../payment/incoming/model.test.ts | 3 +- .../payment/incoming/routes.test.ts | 2 +- .../payment/incoming/service.test.ts | 4 +- .../payment/incoming_remote/service.test.ts | 3 +- .../payment/outgoing/model.test.ts | 3 +- .../payment/outgoing/routes.test.ts | 5 +- .../payment/outgoing/service.test.ts | 3 +- .../src/open_payments/quote/routes.test.ts | 5 +- .../src/open_payments/quote/service.test.ts | 2 +- .../src/open_payments/receiver/model.test.ts | 3 +- .../open_payments/receiver/service.test.ts | 2 +- .../src/open_payments/route-errors.test.ts | 3 +- .../wallet_address/key/routes.test.ts | 3 +- .../wallet_address/key/service.test.ts | 3 +- .../wallet_address/middleware.test.ts | 4 +- .../wallet_address/model.test.ts | 5 +- .../wallet_address/routes.test.ts | 2 +- .../wallet_address/service.test.ts | 4 +- .../payment-method/handler/service.test.ts | 3 +- .../ilp/auto-peering/routes.test.ts | 3 +- .../ilp/auto-peering/service.test.ts | 3 +- .../ilp/peer-http-token/service.test.ts | 3 +- .../src/payment-method/ilp/peer/model.test.ts | 3 +- .../payment-method/ilp/peer/service.test.ts | 3 +- .../src/payment-method/ilp/service.test.ts | 8 +- .../ilp/spsp/middleware.test.ts | 3 +- .../payment-method/ilp/spsp/routes.test.ts | 3 +- .../ilp/stream-credentials/service.test.ts | 3 +- packages/backend/src/rates/service.test.ts | 8 +- .../backend/src/shared/pagination.test.ts | 2 +- .../backend/src/telemetry/service.test.ts | 12 +- packages/backend/src/tests/tigerbeetle.ts | 1 - packages/backend/src/webhook/service.test.ts | 2 +- packages/backend/tsconfig.json | 4 +- 65 files changed, 595 insertions(+), 291 deletions(-) diff --git a/packages/backend/src/accounting/psql/balance.test.ts b/packages/backend/src/accounting/psql/balance.test.ts index 65aa5eb656..13efe81f49 100644 --- a/packages/backend/src/accounting/psql/balance.test.ts +++ b/packages/backend/src/accounting/psql/balance.test.ts @@ -20,7 +20,8 @@ describe('Balances', (): void => { let asset: Asset beforeAll(async (): Promise => { - const deps = initIocContainer({ ...Config, useTigerbeetle: false }) + Config.useTigerbeetle = false + const deps = initIocContainer() appContainer = await createTestApp(deps) serviceDeps = { logger: await deps.use('logger'), diff --git a/packages/backend/src/accounting/psql/ledger-account/index.test.ts b/packages/backend/src/accounting/psql/ledger-account/index.test.ts index c6165c342e..b7726bb794 100644 --- a/packages/backend/src/accounting/psql/ledger-account/index.test.ts +++ b/packages/backend/src/accounting/psql/ledger-account/index.test.ts @@ -21,7 +21,8 @@ describe('Ledger Account', (): void => { let asset: Asset beforeAll(async (): Promise => { - const deps = initIocContainer({ ...Config, useTigerbeetle: false }) + Config.useTigerbeetle = false + const deps = initIocContainer() appContainer = await createTestApp(deps) serviceDeps = { logger: await deps.use('logger'), diff --git a/packages/backend/src/accounting/psql/ledger-transfer/index.test.ts b/packages/backend/src/accounting/psql/ledger-transfer/index.test.ts index 3c1106adda..d9805a6ade 100644 --- a/packages/backend/src/accounting/psql/ledger-transfer/index.test.ts +++ b/packages/backend/src/accounting/psql/ledger-transfer/index.test.ts @@ -33,7 +33,8 @@ describe('Ledger Transfer', (): void => { let asset: Asset beforeAll(async (): Promise => { - const deps = initIocContainer({ ...Config, useTigerbeetle: false }) + Config.useTigerbeetle = false + const deps = initIocContainer() appContainer = await createTestApp(deps) serviceDeps = { logger: await deps.use('logger'), diff --git a/packages/backend/src/accounting/psql/ledger-transfer/model.test.ts b/packages/backend/src/accounting/psql/ledger-transfer/model.test.ts index 50535fe6e8..b732363a60 100644 --- a/packages/backend/src/accounting/psql/ledger-transfer/model.test.ts +++ b/packages/backend/src/accounting/psql/ledger-transfer/model.test.ts @@ -16,7 +16,8 @@ describe('Ledger Transfer Model', (): void => { let asset: Asset beforeAll(async (): Promise => { - const deps = initIocContainer({ ...Config, useTigerbeetle: false }) + Config.useTigerbeetle = false + const deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex }) diff --git a/packages/backend/src/accounting/psql/service.test.ts b/packages/backend/src/accounting/psql/service.test.ts index 0e5d62b36b..29cc852b7d 100644 --- a/packages/backend/src/accounting/psql/service.test.ts +++ b/packages/backend/src/accounting/psql/service.test.ts @@ -46,7 +46,8 @@ describe('Psql Accounting Service', (): void => { let asset: Asset beforeAll(async (): Promise => { - deps = initIocContainer({ ...Config, useTigerbeetle: false }) + Config.useTigerbeetle = false + const deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex accountingService = await deps.use('accountingService') diff --git a/packages/backend/src/accounting/tigerbeetle/service.test.ts b/packages/backend/src/accounting/tigerbeetle/service.test.ts index 799f365ab2..d1b99f8ce3 100644 --- a/packages/backend/src/accounting/tigerbeetle/service.test.ts +++ b/packages/backend/src/accounting/tigerbeetle/service.test.ts @@ -39,11 +39,9 @@ describe('Tigerbeetle Accounting Service', (): void => { const tigerbeetlePort = (global as unknown as { tigerbeetlePort: number }) .tigerbeetlePort - deps = initIocContainer({ - ...Config, - tigerbeetleReplicaAddresses: [tigerbeetlePort.toString()], - useTigerbeetle: true - }) + Config.useTigerbeetle = true + Config.tigerbeetleReplicaAddresses = [tigerbeetlePort.toString()] + deps = initIocContainer() appContainer = await createTestApp(deps) accountingService = await deps.use('accountingService') accountFactory = new AccountFactory(accountingService, newLedger) diff --git a/packages/backend/src/asset/model.test.ts b/packages/backend/src/asset/model.test.ts index 461fb043e5..936a4776e9 100644 --- a/packages/backend/src/asset/model.test.ts +++ b/packages/backend/src/asset/model.test.ts @@ -1,7 +1,6 @@ import { Knex } from 'knex' import { AssetService } from './service' -import { Config } from '../config/app' import { createTestApp, TestContainer } from '../tests/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../' @@ -18,7 +17,7 @@ describe('Models', (): void => { let knex: Knex beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) assetService = await deps.use('assetService') knex = await deps.use('knex') diff --git a/packages/backend/src/asset/service.test.ts b/packages/backend/src/asset/service.test.ts index 3fce127654..fc7ee619a7 100644 --- a/packages/backend/src/asset/service.test.ts +++ b/packages/backend/src/asset/service.test.ts @@ -9,7 +9,6 @@ import { getPageTests } from '../shared/baseModel.test' import { createTestApp, TestContainer } from '../tests/app' import { createAsset, randomAsset } from '../tests/asset' import { truncateTables } from '../tests/tableManager' -import { Config } from '../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../' import { AppServices } from '../app' @@ -22,7 +21,7 @@ describe('Asset Service', (): void => { let assetService: AssetService beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) assetService = await deps.use('assetService') }) diff --git a/packages/backend/src/config/app.ts b/packages/backend/src/config/app.ts index 81cd91eec9..8244bcac63 100644 --- a/packages/backend/src/config/app.ts +++ b/packages/backend/src/config/app.ts @@ -2,170 +2,23 @@ import { loadOrGenerateKey } from '@interledger/http-signature-utils' import dotenv from 'dotenv' import * as fs from 'fs' import { ConnectionOptions } from 'tls' +import * as crypto from 'crypto' -function envString(name: string, value?: string): string { - const envValue = process.env[name] - if (envValue) return envValue - - if (typeof(value) === 'undefined') { - throw new Error(`Missing required key value (${name})`) - } - - return value -} - -function envStringArray(name: string, value: string[]): string[] { - const envValue = process.env[name] - return envValue == null ? value : envValue.split(',').map((s) => s.trim()) -} - -function envInt(name: string, value: number): number { - const envValue = process.env[name] - return envValue == null ? value : parseInt(envValue) -} - -function envFloat(name: string, value: number): number { - const envValue = process.env[name] - return envValue == null ? value : +envValue -} - -function envBool(name: string, value: boolean): boolean { - const envValue = process.env[name] - return envValue == null ? value : envValue === 'true' -} - -export type IAppConfig = typeof Config +export type IAppConfig = Config dotenv.config({ path: process.env.ENV_FILE || '.env' }) -export const Config = { - logLevel: envString('LOG_LEVEL', 'info'), - enableTelemetry: envBool('ENABLE_TELEMETRY', false), - livenet: envBool('LIVENET', false), - openTelemetryCollectors: envStringArray( - 'OPEN_TELEMETRY_COLLECTOR_URLS', - envBool('LIVENET', false) - ? [ - 'http://livenet-otel-collector-NLB-f7992547e797f23d.elb.eu-west-2.amazonaws.com:4317' - ] - : [ - 'http://otel-collector-NLB-e3172ff9d2f4bc8a.elb.eu-west-2.amazonaws.com:4317' - ] - ), - openTelemetryExportInterval: envInt('OPEN_TELEMETRY_EXPORT_INTERVAL', 15000), - telemetryExchangeRatesUrl: envString( - 'TELEMETRY_EXCHANGE_RATES_URL', - 'https://telemetry-exchange-rates.s3.amazonaws.com/exchange-rates-usd.json' - ), - telemetryExchangeRatesLifetime: envInt( - 'TELEMETRY_EXCHANGE_RATES_LIFETIME', - 86_400_000 - ), - adminPort: envInt('ADMIN_PORT', 3001), - openPaymentsUrl: envString('OPEN_PAYMENTS_URL'), - openPaymentsPort: envInt('OPEN_PAYMENTS_PORT', 3003), - connectorPort: envInt('CONNECTOR_PORT', 3002), - autoPeeringServerPort: envInt('AUTO_PEERING_SERVER_PORT', 3005), - enableAutoPeering: envBool('ENABLE_AUTO_PEERING', false), - enableManualMigrations: envBool('ENABLE_MANUAL_MIGRATIONS', false), - databaseUrl: - process.env.NODE_ENV === 'test' - ? `${process.env.DATABASE_URL}_${process.env.JEST_WORKER_ID}` - : envString( - 'DATABASE_URL', - 'postgresql://postgres:password@localhost:5432/development' - ), - walletAddressUrl: envString( - 'WALLET_ADDRESS_URL', - 'http://127.0.0.1:3001/.well-known/pay' - ), - env: envString('NODE_ENV', 'development'), - trustProxy: envBool('TRUST_PROXY', false), - redisUrl: envString('REDIS_URL', 'redis://127.0.0.1:6379'), - redisTls: parseRedisTlsConfig( - envString('REDIS_TLS_CA_FILE_PATH', ''), - envString('REDIS_TLS_KEY_FILE_PATH', ''), - envString('REDIS_TLS_CERT_FILE_PATH', '') - ), - ilpAddress: envString('ILP_ADDRESS'), - ilpConnectorAddress: envString('ILP_CONNECTOR_ADDRESS'), - instanceName: envString('INSTANCE_NAME'), - streamSecret: Buffer.from(process.env.STREAM_SECRET as string, 'base64'), - useTigerbeetle: envBool('USE_TIGERBEETLE', true), - tigerbeetleClusterId: envInt('TIGERBEETLE_CLUSTER_ID', 0), - tigerbeetleReplicaAddresses: process.env.TIGERBEETLE_REPLICA_ADDRESSES - ? process.env.TIGERBEETLE_REPLICA_ADDRESSES.split(',') - : ['3004'], - - exchangeRatesUrl: envString('EXCHANGE_RATES_URL'), - exchangeRatesLifetime: +(process.env.EXCHANGE_RATES_LIFETIME || 15_000), - - slippage: envFloat('SLIPPAGE', 0.01), - quoteLifespan: envInt('QUOTE_LIFESPAN', 5 * 60_000), // milliseconds - - walletAddressWorkers: envInt('WALLET_ADDRESS_WORKERS', 1), - walletAddressWorkerIdle: envInt('WALLET_ADDRESS_WORKER_IDLE', 200), // milliseconds - - authServerGrantUrl: envString('AUTH_SERVER_GRANT_URL'), - authServerIntrospectionUrl: envString('AUTH_SERVER_INTROSPECTION_URL'), - - outgoingPaymentWorkers: envInt('OUTGOING_PAYMENT_WORKERS', 4), - outgoingPaymentWorkerIdle: envInt('OUTGOING_PAYMENT_WORKER_IDLE', 200), // milliseconds - - incomingPaymentWorkers: envInt('INCOMING_PAYMENT_WORKERS', 1), - incomingPaymentWorkerIdle: envInt('INCOMING_PAYMENT_WORKER_IDLE', 200), // milliseconds - - webhookWorkers: envInt('WEBHOOK_WORKERS', 1), - webhookWorkerIdle: envInt('WEBHOOK_WORKER_IDLE', 200), // milliseconds - webhookUrl: envString('WEBHOOK_URL'), - webhookTimeout: envInt('WEBHOOK_TIMEOUT', 2000), // milliseconds - webhookMaxRetry: envInt('WEBHOOK_MAX_RETRY', 10), - - withdrawalThrottleDelay: - process.env.WITHDRAWAL_THROTTLE_DELAY == null - ? undefined - : +process.env.WITHDRAWAL_THROTTLE_DELAY, // optional - - signatureSecret: envString('SIGNATURE_SECRET'), - signatureVersion: envInt('SIGNATURE_VERSION', 1), - - apiSecret: process.env.API_SECRET, // optional - apiSignatureVersion: envInt('API_SIGNATURE_VERSION', 1), - - keyId: envString('KEY_ID'), - privateKey: loadOrGenerateKey(envString('PRIVATE_KEY_FILE', '')), - - graphQLIdempotencyKeyLockMs: envInt('GRAPHQL_IDEMPOTENCY_KEY_LOCK_MS', 2000), - graphQLIdempotencyKeyTtlMs: envInt( - 'GRAPHQL_IDEMPOTENCY_KEY_TTL_MS', - 86400000 - ), - walletAddressLookupTimeoutMs: envInt( - 'WALLET_ADDRESS_LOOKUP_TIMEOUT_MS', - 1500 - ), - walletAddressPollingFrequencyMs: envInt( - 'WALLET_ADDRESS_POLLING_FREQUENCY_MS', - 100 - ), - walletAddressDeactivationPaymentGracePeriodMs: envInt( - 'WALLET_ADDRESS_DEACTIVATION_PAYMENT_GRACE_PERIOD_MS', - 86400000 - ), - incomingPaymentExpiryMaxMs: envInt( - 'INCOMING_PAYMENT_EXPIRY_MAX_MS', - 2592000000 - ), // 30 days - spspEnabled: envBool('ENABLE_INTERLEDGER_PAYMENT_POINTERS', true) -} - function parseRedisTlsConfig( - caFile: string, - keyFile: string, - certFile: string + caFile?: string, + keyFile?: string, + certFile?: string ): ConnectionOptions | undefined { + if (!caFile || !keyFile || !certFile) { + return undefined + } + const options: ConnectionOptions = {} // self-signed certs. @@ -184,3 +37,493 @@ function parseRedisTlsConfig( return Object.keys(options).length > 0 ? options : undefined } + +type EnvType = 'int' | 'float' | 'boolean' | 'string' | 'string[]' + +function convertValue(type: EnvType, value: string): T { + switch (type) { + case 'int': + return parseInt(value, 10) as unknown as T + case 'float': + return parseFloat(value) as unknown as T + case 'boolean': + return (value === 'true') as unknown as T + case 'string[]': + return value.split(',').map((item) => item.trim()) as unknown as T + case 'string': + default: + return value as unknown as T + } +} + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +type DefaultValueFunction = (configInstance: any) => T + +interface EnvOptions { + type: EnvType + optional?: boolean + defaultValue?: T | DefaultValueFunction + transformer?: (value: string) => T +} + +function Env( + variableName: string, + options: EnvOptions = { type: 'string' } +) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return function (target: any, propertyKey: string): void { + const envValue = process.env[variableName] + let transformedValue: T | undefined + + if (envValue !== undefined) { + transformedValue = convertValue(options.type, envValue) + if (options.transformer) { + transformedValue = options.transformer(envValue) + } + } else if (options.optional) { + if (typeof options.defaultValue === 'function') { + Object.defineProperty(target, propertyKey, { + get() { + const defaultVal = ( + options.defaultValue as DefaultValueFunction + )(this) + return options.transformer + ? options.transformer(String(defaultVal)) + : defaultVal + }, + set(value) { + target[propertyKey] = value + }, + enumerable: true, + configurable: true + }) + return + } else if (options.defaultValue !== undefined) { + transformedValue = options.defaultValue + if (options.transformer) { + transformedValue = options.transformer(String(options.defaultValue)) + } + } + } else { + throw new Error( + `Environment variable ${variableName} is mandatory but not provided.` + ) + } + + if (transformedValue !== undefined) { + target[propertyKey] = transformedValue + } + } +} + +export interface IConfig { + logLevel: string + enableTelemetry: boolean + livenet: boolean + openTelemetryCollectors: string[] + openTelemetryExportInterval: number + telemetryExchangeRatesUrl: string + telemetryExchangeRatesLifetime: number + adminPort: number + openPaymentsUrl: string + openPaymentsPort: number + connectorPort: number + autoPeeringServerPort: number + enableAutoPeering: boolean + enableManualMigrations: boolean + databaseUrl: string + walletAddressUrl: string + env: string + trustProxy: boolean + redisUrl: string + ilpAddress: string + ilpConnectorAddress: string + instanceName: string + streamSecret: Buffer + useTigerbeetle: boolean + tigerbeetleClusterId: number + tigerbeetleReplicaAddresses: string[] + exchangeRatesUrl: string + exchangeRatesLifetime: number + slippage: number + quoteLifespan: number + walletAddressWorkers: number + walletAddressWorkerIdle: number + authServerGrantUrl: string + authServerIntrospectionUrl: string + outgoingPaymentWorkers: number + outgoingPaymentWorkerIdle: number + incomingPaymentWorkers: number + incomingPaymentWorkerIdle: number + webhookWorkers: number + webhookWorkerIdle: number + webhookUrl: string + webhookTimeout: number + webhookMaxRetry: number + withdrawalThrottleDelay: number + signatureSecret: string + signatureVersion: number + apiSecret: string + apiSignatureVersion: number + keyId: string | undefined + privateKey: crypto.KeyObject + graphQLIdempotencyKeyLockMs: number + graphQLIdempotencyKeyTtlMs: number + walletAddressLookupTimeoutMs: number + walletAddressPollingFrequencyMs: number + walletAddressDeactivationPaymentGracePeriodMs: number + incomingPaymentExpiryMaxMs: number + spspEnabled: boolean +} + +class Config implements IConfig { + @Env('LOG_LEVEL', { type: 'string', optional: true, defaultValue: 'info' }) + public logLevel!: string + + @Env('ENABLE_TELEMETRY', { + type: 'boolean', + optional: true, + defaultValue: false + }) + public enableTelemetry!: boolean + + @Env('LIVENET', { type: 'boolean', optional: true, defaultValue: false }) + public livenet!: boolean + + @Env('OPEN_TELEMETRY_COLLECTOR_URLS', { + type: 'string[]', + optional: true, + defaultValue: (config: Config) => { + if (config.livenet) { + return [ + 'http://livenet-otel-collector-NLB-f7992547e797f23d.elb.eu-west-2.amazonaws.com:4317' + ] + } + return [ + 'http://otel-collector-NLB-e3172ff9d2f4bc8a.elb.eu-west-2.amazonaws.com:4317' + ] + } + }) + public openTelemetryCollectors!: string[] + + @Env('OPEN_TELEMETRY_EXPORT_INTERVAL', { + type: 'int', + optional: true, + defaultValue: 15000 + }) + public openTelemetryExportInterval!: number + + @Env('TELEMETRY_EXCHANGE_RATES_URL', { + type: 'string', + optional: true, + defaultValue: + 'https://telemetry-exchange-rates.s3.amazonaws.com/exchange-rates-usd.json' + }) + public telemetryExchangeRatesUrl!: string + + @Env('TELEMETRY_EXCHANGE_RATES_LIFETIME', { + type: 'int', + optional: true, + defaultValue: 86_400_000 + }) + public telemetryExchangeRatesLifetime!: number + + @Env('ADMIN_PORT', { type: 'int', optional: true, defaultValue: 3001 }) + public adminPort!: number + + @Env('OPEN_PAYMENTS_URL', { type: 'string' }) + public openPaymentsUrl!: string + + @Env('OPEN_PAYMENTS_PORT', { + type: 'int', + optional: true, + defaultValue: 3003 + }) + public openPaymentsPort!: number + + @Env('CONNECTOR_PORT', { + type: 'string', + optional: true, + defaultValue: '3002' + }) + public connectorPort!: number + + @Env('AUTO_PEERING_SERVER_PORT', { + type: 'int', + optional: true, + defaultValue: 3005 + }) + public autoPeeringServerPort!: number + + @Env('ENABLE_AUTO_PEERING', { + type: 'boolean', + optional: true, + defaultValue: false + }) + public enableAutoPeering!: boolean + + @Env('ENABLE_MANUAL_MIGRATIONS', { + type: 'boolean', + optional: true, + defaultValue: false + }) + public enableManualMigrations!: boolean + + @Env('DATABASE_URL', { type: 'string' }) + public databaseUrl!: string + + @Env('WALLET_ADDRESS_URL', { type: 'string' }) + public walletAddressUrl!: string + + @Env('NODE_ENV', { + type: 'string', + optional: true, + defaultValue: 'development' + }) + public env!: string + + @Env('TRUST_PROXY', { type: 'boolean', optional: true, defaultValue: false }) + public trustProxy!: boolean + + @Env('REDIS_URL', { type: 'string' }) + public redisUrl!: string + + @Env('REDIS_TLS_CA_FILE_PATH', { type: 'string', optional: true }) + public redisTlsCaFilePath!: string + + @Env('REDIS_TLS_KEY_FILE_PATH', { type: 'string', optional: true }) + public redisTlsKeyFilePath!: string + + @Env('REDIS_TLS_CERT_FILE_PATH', { type: 'string', optional: true }) + public redisTlsCertFilePath!: string + + @Env('REDIS_TLS', { + type: 'string', + optional: true, + defaultValue: (c: Config) => { + return parseRedisTlsConfig( + c.redisTlsCaFilePath, + c.redisTlsKeyFilePath, + c.redisTlsCertFilePath + ) + } + }) + public redisTls!: ConnectionOptions + + @Env('ILP_ADDRESS', { type: 'string' }) + public ilpAddress!: string + + @Env('ILP_CONNECTOR_ADDRESS', { type: 'string' }) + public ilpConnectorAddress!: string + + @Env('INSTANCE_NAME', { type: 'string', optional: true }) + public instanceName!: string + + // Add support for transforming + @Env('STREAM_SECRET', { + type: 'string', + transformer: (value: string) => { + return Buffer.from(value, 'base64') + } + }) + public streamSecret!: Buffer + + @Env('USE_TIGERBEETLE', { + type: 'boolean', + optional: true, + defaultValue: true + }) + public useTigerbeetle!: boolean + + @Env('TIGERBEETLE_CLUSTER_ID', { + type: 'int', + optional: true, + defaultValue: 0 + }) + public tigerbeetleClusterId!: number + + @Env('TIGERBEETLE_REPLICA_ADDRESSES', { + type: 'string[]', + optional: true, + defaultValue: ['3004'] + }) + public tigerbeetleReplicaAddresses!: string[] + + @Env('EXCHANGE_RATES_URL', { type: 'string' }) + public exchangeRatesUrl!: string + + @Env('EXCHANGE_RATES_LIFETIME', { + type: 'int', + optional: true, + defaultValue: 15_000 + }) + public exchangeRatesLifetime!: number + + @Env('SLIPPAGE', { type: 'float', optional: true, defaultValue: 0.01 }) + public slippage!: number + + @Env('QUOTE_LIFESPAN', { + type: 'int', + optional: true, + defaultValue: 5 * 60_000 + }) + public quoteLifespan!: number + + @Env('WALLET_ADDRESS_WORKERS', { + type: 'int', + optional: true, + defaultValue: 1 + }) + public walletAddressWorkers!: number + + @Env('WALLET_ADDRESS_WORKER_IDLE', { + type: 'int', + optional: true, + defaultValue: 200 + }) + public walletAddressWorkerIdle!: number + + @Env('AUTH_SERVER_GRANT_URL', { type: 'string' }) + public authServerGrantUrl!: string + + @Env('AUTH_SERVER_INTROSPECTION_URL', { type: 'string' }) + public authServerIntrospectionUrl!: string + + @Env('OUTGOING_PAYMENT_WORKERS', { + type: 'int', + optional: true, + defaultValue: 4 + }) + public outgoingPaymentWorkers!: number + + @Env('OUTGOING_PAYMENT_WORKER_IDLE', { + type: 'int', + optional: true, + defaultValue: 200 + }) //milliseconds + public outgoingPaymentWorkerIdle!: number + + @Env('INCOMING_PAYMENT_WORKERS', { + type: 'int', + optional: true, + defaultValue: 1 + }) + public incomingPaymentWorkers!: number + + @Env('INCOMING_PAYMENT_WORKER_IDLE', { + type: 'int', + optional: true, + defaultValue: 200 + }) //milliseconds + public incomingPaymentWorkerIdle!: number + + @Env('WEBHOOK_WORKERS', { type: 'int', optional: true, defaultValue: 1 }) + public webhookWorkers!: number + + @Env('WEBHOOK_WORKER_IDLE', { + type: 'int', + optional: true, + defaultValue: 200 + }) + public webhookWorkerIdle!: number + + @Env('WEBHOOK_URL', { type: 'string' }) + public webhookUrl!: string + + @Env('WEBHOOK_TIMEOUT', { type: 'int', optional: true, defaultValue: 2000 }) //milliseconds + public webhookTimeout!: number + + @Env('WEBHOOK_MAX_RETRY', { type: 'int', optional: true, defaultValue: 10 }) + public webhookMaxRetry!: number + + @Env('WITHDRAWAL_THROTTLE_DELAY', { type: 'int', optional: true }) + public withdrawalThrottleDelay!: number + + @Env('SIGNATURE_SECRET', { type: 'string' }) + public signatureSecret!: string + + @Env('SIGNATURE_VERSION', { type: 'int', optional: true, defaultValue: 1 }) + public signatureVersion!: number + + @Env('API_SECRET', { type: 'string', optional: true }) + public apiSecret!: string + + @Env('API_SIGNATURE_VERSION', { + type: 'int', + optional: true, + defaultValue: 1 + }) + public apiSignatureVersion!: number + + @Env('KEY_ID', { type: 'string', optional: true }) + public keyId!: string + + @Env('PRIVATE_KEY_FILE', { + type: 'string', + optional: true, + transformer(value: string) { + return loadOrGenerateKey(value) + } + }) + public privateKey!: crypto.KeyObject + + @Env('GRAPHQL_IDEMPOTENCY_KEY_LOCK_MS', { + type: 'int', + optional: true, + defaultValue: 2000 + }) + public graphQLIdempotencyKeyLockMs!: number + + @Env('GRAPHQL_IDEMPOTENCY_KEY_TTL_MS', { + type: 'int', + optional: true, + defaultValue: 86400000 + }) + public graphQLIdempotencyKeyTtlMs!: number + + @Env('WALLET_ADDRESS_LOOKUP_TIMEOUT_MS', { + type: 'int', + optional: true, + defaultValue: 1500 + }) + public walletAddressLookupTimeoutMs!: number + + @Env('WALLET_ADDRESS_POLLING_FREQUENCY_MS', { + type: 'int', + optional: true, + defaultValue: 100 + }) + public walletAddressPollingFrequencyMs!: number + + @Env('WALLET_ADDRESS_DEACTIVATION_PAYMENT_GRACE_PERIOD_MS', { + type: 'int', + optional: true, + defaultValue: 86400000 + }) + public walletAddressDeactivationPaymentGracePeriodMs!: number + + @Env('INCOMING_PAYMENT_EXPIRY_MAX_MS', { + type: 'int', + optional: true, + defaultValue: 2592000000 + }) + public incomingPaymentExpiryMaxMs!: number + + @Env('ENABLE_SPSP', { type: 'boolean', optional: true, defaultValue: true }) + public spspEnabled!: boolean + + private static _instance: Config + + private constructor() {} + + public static getInstance() { + if (!Config._instance) { + Config._instance = new Config() + } + + return Config._instance + } +} + +const configInstance = Config.getInstance() +export { configInstance as Config } diff --git a/packages/backend/src/fee/model.test.ts b/packages/backend/src/fee/model.test.ts index 35c39d4d1b..2da87c8b86 100644 --- a/packages/backend/src/fee/model.test.ts +++ b/packages/backend/src/fee/model.test.ts @@ -1,4 +1,3 @@ -import { Config } from '../config/app' import { createTestApp, TestContainer } from '../tests/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../' @@ -14,7 +13,7 @@ describe('Fee Model', (): void => { let asset: Asset beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) diff --git a/packages/backend/src/fee/service.test.ts b/packages/backend/src/fee/service.test.ts index e57068f7e3..de451f0107 100644 --- a/packages/backend/src/fee/service.test.ts +++ b/packages/backend/src/fee/service.test.ts @@ -2,7 +2,6 @@ import { IocContract } from '@adonisjs/fold' import { AppServices } from '../app' import { TestContainer, createTestApp } from '../tests/app' import { initIocContainer } from '..' -import { Config } from '../config/app' import { FeeService } from './service' import { Knex } from 'knex' import { truncateTables } from '../tests/tableManager' @@ -23,7 +22,7 @@ describe('Fee Service', (): void => { let asset: Asset beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex feeService = await deps.use('feeService') diff --git a/packages/backend/src/graphql/middleware/index.test.ts b/packages/backend/src/graphql/middleware/index.test.ts index 977fa56d5c..3013747d48 100644 --- a/packages/backend/src/graphql/middleware/index.test.ts +++ b/packages/backend/src/graphql/middleware/index.test.ts @@ -6,7 +6,6 @@ import { createTestApp, TestContainer } from '../../tests/app' import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { initIocContainer } from '../..' -import { Config } from '../../config/app' import { truncateTables } from '../../tests/tableManager' import { AssetService } from '../../asset/service' import { randomAsset } from '../../tests/asset' @@ -19,7 +18,7 @@ describe('GraphQL Middleware', (): void => { let assetService: AssetService beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) assetService = await deps.use('assetService') }) diff --git a/packages/backend/src/graphql/resolvers/asset.test.ts b/packages/backend/src/graphql/resolvers/asset.test.ts index 67cd088b1c..9cd085c852 100644 --- a/packages/backend/src/graphql/resolvers/asset.test.ts +++ b/packages/backend/src/graphql/resolvers/asset.test.ts @@ -8,7 +8,6 @@ import { createTestApp, TestContainer } from '../../tests/app' import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { initIocContainer } from '../..' -import { Config } from '../../config/app' import { truncateTables } from '../../tests/tableManager' import { isAssetError } from '../../asset/errors' import { Asset as AssetModel } from '../../asset/model' @@ -36,7 +35,7 @@ describe('Asset Resolvers', (): void => { let feeService: FeeService beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) assetService = await deps.use('assetService') accountingService = await deps.use('accountingService') diff --git a/packages/backend/src/graphql/resolvers/auto-peering.test.ts b/packages/backend/src/graphql/resolvers/auto-peering.test.ts index 86f0f0a0ad..8871a91cae 100644 --- a/packages/backend/src/graphql/resolvers/auto-peering.test.ts +++ b/packages/backend/src/graphql/resolvers/auto-peering.test.ts @@ -7,7 +7,6 @@ import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { Asset } from '../../asset/model' import { initIocContainer } from '../..' -import { Config } from '../../config/app' import { truncateTables } from '../../tests/tableManager' import { errorToCode, @@ -86,7 +85,7 @@ describe('Auto Peering Resolvers', (): void => { } beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) autoPeeringService = await deps.use('autoPeeringService') }) diff --git a/packages/backend/src/graphql/resolvers/combined_payments.test.ts b/packages/backend/src/graphql/resolvers/combined_payments.test.ts index 50af7a5d4c..dc9ae7c85c 100644 --- a/packages/backend/src/graphql/resolvers/combined_payments.test.ts +++ b/packages/backend/src/graphql/resolvers/combined_payments.test.ts @@ -25,7 +25,7 @@ describe('Payment', (): void => { let asset: Asset beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) diff --git a/packages/backend/src/graphql/resolvers/fee.test.ts b/packages/backend/src/graphql/resolvers/fee.test.ts index 99954a97ef..fdc15714bd 100644 --- a/packages/backend/src/graphql/resolvers/fee.test.ts +++ b/packages/backend/src/graphql/resolvers/fee.test.ts @@ -1,7 +1,6 @@ import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { initIocContainer } from '../..' -import { Config } from '../../config/app' import { createTestApp, TestContainer } from '../../tests/app' import { truncateTables } from '../../tests/tableManager' import { gql } from '@apollo/client' @@ -19,7 +18,7 @@ describe('Fee Resolvers', () => { let feeService: FeeService beforeAll(async () => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) feeService = await deps.use('feeService') }) diff --git a/packages/backend/src/graphql/resolvers/incoming_payment.test.ts b/packages/backend/src/graphql/resolvers/incoming_payment.test.ts index 5f005a1f8d..365fe75a62 100644 --- a/packages/backend/src/graphql/resolvers/incoming_payment.test.ts +++ b/packages/backend/src/graphql/resolvers/incoming_payment.test.ts @@ -5,7 +5,6 @@ import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { initIocContainer } from '../..' import { Asset } from '../../asset/model' -import { Config } from '../../config/app' import { createAsset } from '../../tests/asset' import { createIncomingPayment } from '../../tests/incomingPayment' import { createWalletAddress } from '../../tests/walletAddress' @@ -38,7 +37,7 @@ describe('Incoming Payment Resolver', (): void => { let asset: Asset beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) incomingPaymentService = await deps.use('incomingPaymentService') accountingService = await deps.use('accountingService') diff --git a/packages/backend/src/graphql/resolvers/index.test.ts b/packages/backend/src/graphql/resolvers/index.test.ts index df459b25b9..4fd7991442 100644 --- a/packages/backend/src/graphql/resolvers/index.test.ts +++ b/packages/backend/src/graphql/resolvers/index.test.ts @@ -2,7 +2,6 @@ import { IocContract } from '@adonisjs/fold' import axios from 'axios' import { initIocContainer } from '../..' import { AppServices } from '../../app' -import { Config } from '../../config/app' import { TestContainer, createTestApp } from '../../tests/app' describe('Rafiki Graphql', (): void => { @@ -10,7 +9,7 @@ describe('Rafiki Graphql', (): void => { let appContainer: TestContainer beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) diff --git a/packages/backend/src/graphql/resolvers/liquidity.test.ts b/packages/backend/src/graphql/resolvers/liquidity.test.ts index 132929524f..02c70a320c 100644 --- a/packages/backend/src/graphql/resolvers/liquidity.test.ts +++ b/packages/backend/src/graphql/resolvers/liquidity.test.ts @@ -53,7 +53,7 @@ describe('Liquidity Resolvers', (): void => { const timeout = 10 beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex accountingService = await deps.use('accountingService') diff --git a/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts b/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts index 0d63b4886a..491341b103 100644 --- a/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts +++ b/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts @@ -39,7 +39,7 @@ describe('OutgoingPayment Resolvers', (): void => { let asset: Asset beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) accountingService = await deps.use('accountingService') outgoingPaymentService = await deps.use('outgoingPaymentService') diff --git a/packages/backend/src/graphql/resolvers/peer.test.ts b/packages/backend/src/graphql/resolvers/peer.test.ts index a24997566b..bffc0a97d2 100644 --- a/packages/backend/src/graphql/resolvers/peer.test.ts +++ b/packages/backend/src/graphql/resolvers/peer.test.ts @@ -10,7 +10,6 @@ import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { Asset } from '../../asset/model' import { initIocContainer } from '../..' -import { Config } from '../../config/app' import { truncateTables } from '../../tests/tableManager' import { errorToCode, @@ -56,7 +55,7 @@ describe('Peer Resolvers', (): void => { }) beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) peerService = await deps.use('peerService') accountingService = await deps.use('accountingService') diff --git a/packages/backend/src/graphql/resolvers/quote.test.ts b/packages/backend/src/graphql/resolvers/quote.test.ts index 1f39f81952..a0d8f8502d 100644 --- a/packages/backend/src/graphql/resolvers/quote.test.ts +++ b/packages/backend/src/graphql/resolvers/quote.test.ts @@ -6,7 +6,6 @@ import { createTestApp, TestContainer } from '../../tests/app' import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { initIocContainer } from '../..' -import { Config } from '../../config/app' import { Asset } from '../../asset/model' import { createAsset } from '../../tests/asset' import { createWalletAddress } from '../../tests/walletAddress' @@ -28,7 +27,7 @@ describe('Quote Resolvers', (): void => { const receiver = `${receivingWalletAddress}/incoming-payments/${uuid()}` beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) quoteService = await deps.use('quoteService') }) diff --git a/packages/backend/src/graphql/resolvers/receiver.test.ts b/packages/backend/src/graphql/resolvers/receiver.test.ts index 42339016e8..296a1f8e25 100644 --- a/packages/backend/src/graphql/resolvers/receiver.test.ts +++ b/packages/backend/src/graphql/resolvers/receiver.test.ts @@ -4,7 +4,6 @@ import { createTestApp, TestContainer } from '../../tests/app' import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { initIocContainer } from '../..' -import { Config } from '../../config/app' import { Amount, serializeAmount } from '../../open_payments/amount' import { mockIncomingPaymentWithPaymentMethods, @@ -21,7 +20,7 @@ describe('Receiver Resolver', (): void => { let receiverService: ReceiverService beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) receiverService = await deps.use('receiverService') }) diff --git a/packages/backend/src/graphql/resolvers/walletAddressKey.test.ts b/packages/backend/src/graphql/resolvers/walletAddressKey.test.ts index c0f0fbf272..17fe206efd 100644 --- a/packages/backend/src/graphql/resolvers/walletAddressKey.test.ts +++ b/packages/backend/src/graphql/resolvers/walletAddressKey.test.ts @@ -7,7 +7,6 @@ import { createTestApp, TestContainer } from '../../tests/app' import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { initIocContainer } from '../..' -import { Config } from '../../config/app' import { truncateTables } from '../../tests/tableManager' import { CreateWalletAddressKeyInput, @@ -28,7 +27,7 @@ describe('Wallet Address Key Resolvers', (): void => { let walletAddressKeyService: WalletAddressKeyService beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) walletAddressKeyService = await deps.use('walletAddressKeyService') }) diff --git a/packages/backend/src/graphql/resolvers/wallet_address.test.ts b/packages/backend/src/graphql/resolvers/wallet_address.test.ts index 7d27b77042..d59e77864f 100644 --- a/packages/backend/src/graphql/resolvers/wallet_address.test.ts +++ b/packages/backend/src/graphql/resolvers/wallet_address.test.ts @@ -9,7 +9,6 @@ import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { Asset } from '../../asset/model' import { initIocContainer } from '../..' -import { Config } from '../../config/app' import { truncateTables } from '../../tests/tableManager' import { WalletAddressError, @@ -42,7 +41,7 @@ describe('Wallet Address Resolvers', (): void => { let walletAddressService: WalletAddressService beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex walletAddressService = await deps.use('walletAddressService') diff --git a/packages/backend/src/graphql/resolvers/webhooks.test.ts b/packages/backend/src/graphql/resolvers/webhooks.test.ts index b5ecda5ccb..ab702e95dd 100644 --- a/packages/backend/src/graphql/resolvers/webhooks.test.ts +++ b/packages/backend/src/graphql/resolvers/webhooks.test.ts @@ -4,7 +4,6 @@ import { createTestApp, TestContainer } from '../../tests/app' import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { initIocContainer } from '../..' -import { Config } from '../../config/app' import { truncateTables } from '../../tests/tableManager' import { WebhookEventsConnection } from '../generated/graphql' import { createWebhookEvent, webhookEventTypes } from '../../tests/webhook' @@ -15,7 +14,7 @@ describe('Webhook Events Query', (): void => { let appContainer: TestContainer beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index 930f0f3535..276616c5bd 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -56,11 +56,9 @@ BigInt.prototype.toJSON = function () { return this.toString() } -export function initIocContainer( - config: typeof Config -): IocContract { +export function initIocContainer(): IocContract { const container: IocContract = new Ioc() - container.singleton('config', async () => config) + container.singleton('config', async () => Config) container.singleton('axios', async () => axios.create()) container.singleton('logger', async (deps: IocContract) => { const config = await deps.use('config') @@ -130,12 +128,12 @@ export function initIocContainer( }) }) - if (config.enableTelemetry) { + if (Config.enableTelemetry) { container.singleton('internalRatesService', async (deps) => { return createRatesService({ logger: await deps.use('logger'), - exchangeRatesUrl: config.telemetryExchangeRatesUrl, - exchangeRatesLifetime: config.telemetryExchangeRatesLifetime + exchangeRatesUrl: Config.telemetryExchangeRatesUrl, + exchangeRatesLifetime: Config.telemetryExchangeRatesLifetime }) }) @@ -295,7 +293,7 @@ export function initIocContainer( logger: await deps.use('logger'), knex: await deps.use('knex'), grantService: await deps.use('grantService'), - openPaymentsUrl: config.openPaymentsUrl, + openPaymentsUrl: Config.openPaymentsUrl, openPaymentsClient: await deps.use('openPaymentsClient') }) }) @@ -608,7 +606,7 @@ export const start = async ( // If this script is run directly, start the server if (require.main === module) { - const container = initIocContainer(Config) + const container = initIocContainer() const app = new App(container) start(container, app).catch(async (e): Promise => { diff --git a/packages/backend/src/open_payments/auth/middleware.test.ts b/packages/backend/src/open_payments/auth/middleware.test.ts index b7d6256fa3..2b81c5a799 100644 --- a/packages/backend/src/open_payments/auth/middleware.test.ts +++ b/packages/backend/src/open_payments/auth/middleware.test.ts @@ -52,7 +52,7 @@ describe('Auth Middleware', (): void => { const action: AccessAction = 'create' beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) middleware = createTokenIntrospectionMiddleware({ requestType: type, @@ -421,7 +421,7 @@ describe('authenticatedStatusMiddleware', (): void => { let appContainer: TestContainer beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) @@ -495,7 +495,7 @@ describe('HTTP Signature Middleware', (): void => { let key: JWK beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) diff --git a/packages/backend/src/open_payments/authServer/service.test.ts b/packages/backend/src/open_payments/authServer/service.test.ts index 1fd758a204..80755e4dfc 100644 --- a/packages/backend/src/open_payments/authServer/service.test.ts +++ b/packages/backend/src/open_payments/authServer/service.test.ts @@ -6,7 +6,6 @@ import { AuthServer } from './model' import { AuthServerService } from './service' import { initIocContainer } from '../../' import { AppServices } from '../../app' -import { Config } from '../../config/app' import { createTestApp, TestContainer } from '../../tests/app' import { truncateTables } from '../../tests/tableManager' @@ -17,7 +16,7 @@ describe('Auth Server Service', (): void => { let knex: Knex beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex authServerService = await deps.use('authServerService') diff --git a/packages/backend/src/open_payments/grant/service.test.ts b/packages/backend/src/open_payments/grant/service.test.ts index d0e219bfc0..005e42b846 100644 --- a/packages/backend/src/open_payments/grant/service.test.ts +++ b/packages/backend/src/open_payments/grant/service.test.ts @@ -7,7 +7,6 @@ import { CreateOptions, GrantService } from './service' import { AuthServer } from '../authServer/model' import { initIocContainer } from '../..' import { AppServices } from '../../app' -import { Config } from '../../config/app' import { createTestApp, TestContainer } from '../../tests/app' import { truncateTables } from '../../tests/tableManager' import { AccessType, AccessAction } from '@interledger/open-payments' @@ -20,7 +19,7 @@ describe('Grant Service', (): void => { let knex: Knex beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex }) diff --git a/packages/backend/src/open_payments/payment/combined/service.test.ts b/packages/backend/src/open_payments/payment/combined/service.test.ts index fddb5efd43..2622105670 100644 --- a/packages/backend/src/open_payments/payment/combined/service.test.ts +++ b/packages/backend/src/open_payments/payment/combined/service.test.ts @@ -2,7 +2,6 @@ import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../../app' import { TestContainer, createTestApp } from '../../../tests/app' import { initIocContainer } from '../../..' -import { Config } from '../../../config/app' import { CombinedPaymentService } from './service' import { Knex } from 'knex' import { truncateTables } from '../../../tests/tableManager' @@ -33,7 +32,7 @@ describe('Combined Payment Service', (): void => { let receiveWalletAddress: MockWalletAddress beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex combinedPaymentService = await deps.use('combinedPaymentService') diff --git a/packages/backend/src/open_payments/payment/incoming/model.test.ts b/packages/backend/src/open_payments/payment/incoming/model.test.ts index e4577af3ad..31db7daaee 100644 --- a/packages/backend/src/open_payments/payment/incoming/model.test.ts +++ b/packages/backend/src/open_payments/payment/incoming/model.test.ts @@ -1,6 +1,5 @@ import { IocContract } from '@adonisjs/fold' import { createTestApp, TestContainer } from '../../../tests/app' -import { Config } from '../../../config/app' import { initIocContainer } from '../../..' import { AppServices } from '../../../app' import { createIncomingPayment } from '../../../tests/incomingPayment' @@ -23,7 +22,7 @@ describe('Models', (): void => { let appContainer: TestContainer beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) diff --git a/packages/backend/src/open_payments/payment/incoming/routes.test.ts b/packages/backend/src/open_payments/payment/incoming/routes.test.ts index d6357e0b62..d14d6ffc54 100644 --- a/packages/backend/src/open_payments/payment/incoming/routes.test.ts +++ b/packages/backend/src/open_payments/payment/incoming/routes.test.ts @@ -33,7 +33,7 @@ describe('Incoming Payment Routes', (): void => { beforeAll(async (): Promise => { config = Config - deps = await initIocContainer(config) + deps = initIocContainer() appContainer = await createTestApp(deps) const { resourceServerSpec } = await deps.use('openApi') jestOpenAPI(resourceServerSpec) diff --git a/packages/backend/src/open_payments/payment/incoming/service.test.ts b/packages/backend/src/open_payments/payment/incoming/service.test.ts index 710056ba40..eb17207edd 100644 --- a/packages/backend/src/open_payments/payment/incoming/service.test.ts +++ b/packages/backend/src/open_payments/payment/incoming/service.test.ts @@ -12,7 +12,7 @@ import { IncomingPaymentEventType, IncomingPaymentState } from './model' -import { Config, IAppConfig } from '../../../config/app' +import { IAppConfig } from '../../../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' import { AppServices } from '../../../app' @@ -38,7 +38,7 @@ describe('Incoming Payment Service', (): void => { let config: IAppConfig beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) accountingService = await deps.use('accountingService') knex = appContainer.knex diff --git a/packages/backend/src/open_payments/payment/incoming_remote/service.test.ts b/packages/backend/src/open_payments/payment/incoming_remote/service.test.ts index ac7ea45c38..c8847e7f78 100644 --- a/packages/backend/src/open_payments/payment/incoming_remote/service.test.ts +++ b/packages/backend/src/open_payments/payment/incoming_remote/service.test.ts @@ -1,7 +1,6 @@ import { Knex } from 'knex' import { RemoteIncomingPaymentService } from './service' import { createTestApp, TestContainer } from '../../../tests/app' -import { Config } from '../../../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' import { AppServices } from '../../../app' @@ -30,7 +29,7 @@ describe('Remote Incoming Payment Service', (): void => { let grantService: GrantService beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) openPaymentsClient = await deps.use('openPaymentsClient') grantService = await deps.use('grantService') diff --git a/packages/backend/src/open_payments/payment/outgoing/model.test.ts b/packages/backend/src/open_payments/payment/outgoing/model.test.ts index f724192d6c..eb9de43329 100644 --- a/packages/backend/src/open_payments/payment/outgoing/model.test.ts +++ b/packages/backend/src/open_payments/payment/outgoing/model.test.ts @@ -1,5 +1,4 @@ import { Knex } from 'knex' -import { Config } from '../../../config/app' import { createTestApp, TestContainer } from '../../../tests/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' @@ -17,7 +16,7 @@ describe('Outgoing Payment Event Model', (): void => { let knex: Knex beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) knex = await deps.use('knex') }) diff --git a/packages/backend/src/open_payments/payment/outgoing/routes.test.ts b/packages/backend/src/open_payments/payment/outgoing/routes.test.ts index 85a327e69f..6f05555a6d 100644 --- a/packages/backend/src/open_payments/payment/outgoing/routes.test.ts +++ b/packages/backend/src/open_payments/payment/outgoing/routes.test.ts @@ -4,7 +4,7 @@ import { Knex } from 'knex' import { v4 as uuid } from 'uuid' import assert from 'assert' import { createTestApp, TestContainer } from '../../../tests/app' -import { Config, IAppConfig } from '../../../config/app' +import { Config } from '../../../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' import { AppServices, CreateContext } from '../../../app' @@ -36,7 +36,6 @@ describe('Outgoing Payment Routes', (): void => { let deps: IocContract let appContainer: TestContainer let knex: Knex - let config: IAppConfig let outgoingPaymentRoutes: OutgoingPaymentRoutes let outgoingPaymentService: OutgoingPaymentService let walletAddress: WalletAddress @@ -65,7 +64,7 @@ describe('Outgoing Payment Routes', (): void => { beforeAll(async (): Promise => { config = Config - deps = await initIocContainer(config) + deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex config = await deps.use('config') diff --git a/packages/backend/src/open_payments/payment/outgoing/service.test.ts b/packages/backend/src/open_payments/payment/outgoing/service.test.ts index a3543cc600..2cd67eb9c6 100644 --- a/packages/backend/src/open_payments/payment/outgoing/service.test.ts +++ b/packages/backend/src/open_payments/payment/outgoing/service.test.ts @@ -240,7 +240,8 @@ describe('OutgoingPaymentService', (): void => { XRP: exchangeRate })) - deps = await initIocContainer({ ...Config, exchangeRatesUrl }) + Config.exchangeRatesUrl = exchangeRatesUrl + deps = initIocContainer() appContainer = await createTestApp(deps) outgoingPaymentService = await deps.use('outgoingPaymentService') accountingService = await deps.use('accountingService') diff --git a/packages/backend/src/open_payments/quote/routes.test.ts b/packages/backend/src/open_payments/quote/routes.test.ts index 422759bd73..270151651b 100644 --- a/packages/backend/src/open_payments/quote/routes.test.ts +++ b/packages/backend/src/open_payments/quote/routes.test.ts @@ -5,7 +5,7 @@ import { v4 as uuid } from 'uuid' import { IocContract } from '@adonisjs/fold' import { createTestApp, TestContainer } from '../../tests/app' -import { Config, IAppConfig } from '../../config/app' +import { Config } from '../../config/app' import { initIocContainer } from '../..' import { AppServices, CreateContext } from '../../app' import { truncateTables } from '../../tests/tableManager' @@ -26,7 +26,6 @@ describe('Quote Routes', (): void => { let deps: IocContract let appContainer: TestContainer let quoteService: QuoteService - let config: IAppConfig let quoteRoutes: QuoteRoutes let walletAddress: WalletAddress let baseUrl: string @@ -62,7 +61,7 @@ describe('Quote Routes', (): void => { beforeAll(async (): Promise => { config = Config - deps = await initIocContainer(config) + deps = initIocContainer() appContainer = await createTestApp(deps) config = await deps.use('config') quoteRoutes = await deps.use('quoteRoutes') diff --git a/packages/backend/src/open_payments/quote/service.test.ts b/packages/backend/src/open_payments/quote/service.test.ts index a01db31150..528eaff785 100644 --- a/packages/backend/src/open_payments/quote/service.test.ts +++ b/packages/backend/src/open_payments/quote/service.test.ts @@ -65,7 +65,7 @@ describe('QuoteService', (): void => { } beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex diff --git a/packages/backend/src/open_payments/receiver/model.test.ts b/packages/backend/src/open_payments/receiver/model.test.ts index c062e1370c..c057a93a92 100644 --- a/packages/backend/src/open_payments/receiver/model.test.ts +++ b/packages/backend/src/open_payments/receiver/model.test.ts @@ -1,6 +1,5 @@ import { IocContract } from '@adonisjs/fold' import { createTestApp, TestContainer } from '../../tests/app' -import { Config } from '../../config/app' import { initIocContainer } from '../..' import { AppServices } from '../../app' import { createIncomingPayment } from '../../tests/incomingPayment' @@ -22,7 +21,7 @@ describe('Receiver Model', (): void => { let streamCredentialsService: StreamCredentialsService beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) streamCredentialsService = await deps.use('streamCredentialsService') }) diff --git a/packages/backend/src/open_payments/receiver/service.test.ts b/packages/backend/src/open_payments/receiver/service.test.ts index 088d6812d0..5efe1cfdb3 100644 --- a/packages/backend/src/open_payments/receiver/service.test.ts +++ b/packages/backend/src/open_payments/receiver/service.test.ts @@ -53,7 +53,7 @@ describe('Receiver Service', (): void => { let remoteIncomingPaymentService: RemoteIncomingPaymentService beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) receiverService = await deps.use('receiverService') incomingPaymentService = await deps.use('incomingPaymentService') diff --git a/packages/backend/src/open_payments/route-errors.test.ts b/packages/backend/src/open_payments/route-errors.test.ts index c837c2a0e5..f7fa09a163 100644 --- a/packages/backend/src/open_payments/route-errors.test.ts +++ b/packages/backend/src/open_payments/route-errors.test.ts @@ -6,7 +6,6 @@ import { } from './route-errors' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '..' -import { Config } from '../config/app' import { OpenAPIValidatorMiddlewareError } from '@interledger/openapi' describe('openPaymentServerErrorMiddleware', (): void => { @@ -14,7 +13,7 @@ describe('openPaymentServerErrorMiddleware', (): void => { let ctx: AppContext beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() }) beforeEach(async (): Promise => { diff --git a/packages/backend/src/open_payments/wallet_address/key/routes.test.ts b/packages/backend/src/open_payments/wallet_address/key/routes.test.ts index 69ac364e2c..fecd9acff8 100644 --- a/packages/backend/src/open_payments/wallet_address/key/routes.test.ts +++ b/packages/backend/src/open_payments/wallet_address/key/routes.test.ts @@ -4,7 +4,6 @@ import { v4 as uuid } from 'uuid' import { createContext } from '../../../tests/context' import { createTestApp, TestContainer } from '../../../tests/app' -import { Config } from '../../../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' import { AppServices, WalletAddressKeysContext } from '../../../app' @@ -25,7 +24,7 @@ describe('Wallet Address Keys Routes', (): void => { } beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() deps.bind('messageProducer', async () => mockMessageProducer) appContainer = await createTestApp(deps) const { walletAddressServerSpec } = await deps.use('openApi') diff --git a/packages/backend/src/open_payments/wallet_address/key/service.test.ts b/packages/backend/src/open_payments/wallet_address/key/service.test.ts index 6cf6972a0b..12a218a94d 100644 --- a/packages/backend/src/open_payments/wallet_address/key/service.test.ts +++ b/packages/backend/src/open_payments/wallet_address/key/service.test.ts @@ -4,7 +4,6 @@ import { v4 as uuid } from 'uuid' import { WalletAddressKeyService } from './service' import { createTestApp, TestContainer } from '../../../tests/app' import { truncateTables } from '../../../tests/tableManager' -import { Config } from '../../../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' import { AppServices } from '../../../app' @@ -23,7 +22,7 @@ describe('Wallet Address Key Service', (): void => { let walletAddressKeyService: WalletAddressKeyService beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) walletAddressKeyService = await deps.use('walletAddressKeyService') }) diff --git a/packages/backend/src/open_payments/wallet_address/middleware.test.ts b/packages/backend/src/open_payments/wallet_address/middleware.test.ts index 699557fea1..6221551f75 100644 --- a/packages/backend/src/open_payments/wallet_address/middleware.test.ts +++ b/packages/backend/src/open_payments/wallet_address/middleware.test.ts @@ -1,7 +1,5 @@ import { URL } from 'url' import { createWalletAddressMiddleware } from './middleware' -import { Config } from '../../config/app' -import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../' import { AppContext, AppServices } from '../../app' import { createTestApp, TestContainer } from '../../tests/app' @@ -22,7 +20,7 @@ describe('Wallet Address Middleware', (): void => { let next: jest.MockedFunction<() => Promise> beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) middleware = createWalletAddressMiddleware() }) diff --git a/packages/backend/src/open_payments/wallet_address/model.test.ts b/packages/backend/src/open_payments/wallet_address/model.test.ts index 7026f4dfa8..4a2411aa87 100644 --- a/packages/backend/src/open_payments/wallet_address/model.test.ts +++ b/packages/backend/src/open_payments/wallet_address/model.test.ts @@ -27,7 +27,6 @@ import { createWalletAddress } from '../../tests/walletAddress' import { truncateTables } from '../../tests/tableManager' import { initIocContainer } from '../..' import { createTestApp, TestContainer } from '../../tests/app' -import { Config } from '../../config/app' import { IocContract } from '@adonisjs/fold' import assert from 'assert' import { ReadContextWithAuthenticatedStatus } from '../payment/incoming/routes' @@ -372,7 +371,7 @@ describe('Models', (): void => { let knex: Knex beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() knex = await deps.use('knex') appContainer = await createTestApp(deps) }) @@ -470,7 +469,7 @@ describe('throwIfMissingWalletAddress', (): void => { let appContainer: TestContainer beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) diff --git a/packages/backend/src/open_payments/wallet_address/routes.test.ts b/packages/backend/src/open_payments/wallet_address/routes.test.ts index d4ca9cfa3f..1517b6c964 100644 --- a/packages/backend/src/open_payments/wallet_address/routes.test.ts +++ b/packages/backend/src/open_payments/wallet_address/routes.test.ts @@ -19,7 +19,7 @@ describe('Wallet Address Routes', (): void => { beforeAll(async (): Promise => { config = Config config.authServerGrantUrl = 'https://auth.wallet.example/authorize' - deps = await initIocContainer(config) + deps = initIocContainer() appContainer = await createTestApp(deps) const { walletAddressServerSpec } = await deps.use('openApi') jestOpenAPI(walletAddressServerSpec) diff --git a/packages/backend/src/open_payments/wallet_address/service.test.ts b/packages/backend/src/open_payments/wallet_address/service.test.ts index 2307a628e5..f6ace82c0c 100644 --- a/packages/backend/src/open_payments/wallet_address/service.test.ts +++ b/packages/backend/src/open_payments/wallet_address/service.test.ts @@ -14,7 +14,7 @@ import { createTestApp, TestContainer } from '../../tests/app' import { createAsset } from '../../tests/asset' import { createWalletAddress } from '../../tests/walletAddress' import { truncateTables } from '../../tests/tableManager' -import { Config, IAppConfig } from '../../config/app' +import { IAppConfig } from '../../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../' import { AppServices } from '../../app' @@ -34,7 +34,7 @@ describe('Open Payments Wallet Address Service', (): void => { let knex: Knex beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() config = await deps.use('config') appContainer = await createTestApp(deps) knex = appContainer.knex diff --git a/packages/backend/src/payment-method/handler/service.test.ts b/packages/backend/src/payment-method/handler/service.test.ts index 2a80feed5c..6aba5544f5 100644 --- a/packages/backend/src/payment-method/handler/service.test.ts +++ b/packages/backend/src/payment-method/handler/service.test.ts @@ -5,7 +5,6 @@ import { } from './service' import { initIocContainer } from '../../' import { createTestApp, TestContainer } from '../../tests/app' -import { Config } from '../../config/app' import { IocContract } from '@adonisjs/fold' import { AppServices } from '../../app' import { createAsset } from '../../tests/asset' @@ -23,7 +22,7 @@ describe('PaymentMethodHandlerService', (): void => { let ilpPaymentService: IlpPaymentService beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) paymentMethodHandlerService = await deps.use('paymentMethodHandlerService') diff --git a/packages/backend/src/payment-method/ilp/auto-peering/routes.test.ts b/packages/backend/src/payment-method/ilp/auto-peering/routes.test.ts index f3bc49b3a9..dd7f79ffd8 100644 --- a/packages/backend/src/payment-method/ilp/auto-peering/routes.test.ts +++ b/packages/backend/src/payment-method/ilp/auto-peering/routes.test.ts @@ -16,7 +16,8 @@ describe('Auto Peering Routes', (): void => { let config: IAppConfig beforeAll(async (): Promise => { - deps = initIocContainer({ ...Config, enableAutoPeering: true }) + Config.enableAutoPeering = true + deps = initIocContainer() appContainer = await createTestApp(deps) autoPeeringRoutes = await deps.use('autoPeeringRoutes') config = await deps.use('config') diff --git a/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts b/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts index 7789d20101..51fbeadd45 100644 --- a/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts +++ b/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts @@ -29,7 +29,8 @@ describe('Auto Peering Service', (): void => { let accountingService: AccountingService beforeAll(async (): Promise => { - deps = initIocContainer({ ...Config, enableAutoPeering: true }) + Config.enableAutoPeering = true + deps = initIocContainer() appContainer = await createTestApp(deps) config = await deps.use('config') autoPeeringService = await deps.use('autoPeeringService') diff --git a/packages/backend/src/payment-method/ilp/peer-http-token/service.test.ts b/packages/backend/src/payment-method/ilp/peer-http-token/service.test.ts index d9624fbb0b..b1b3fe6393 100644 --- a/packages/backend/src/payment-method/ilp/peer-http-token/service.test.ts +++ b/packages/backend/src/payment-method/ilp/peer-http-token/service.test.ts @@ -5,7 +5,6 @@ import { HttpTokenError } from './errors' import { createTestApp, TestContainer } from '../../../tests/app' import { createPeer } from '../../../tests/peer' import { truncateTables } from '../../../tests/tableManager' -import { Config } from '../../../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' import { AppServices } from '../../../app' @@ -18,7 +17,7 @@ describe('HTTP Token Service', (): void => { let peer: Peer beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) httpTokenService = await deps.use('httpTokenService') }) diff --git a/packages/backend/src/payment-method/ilp/peer/model.test.ts b/packages/backend/src/payment-method/ilp/peer/model.test.ts index a664509eb1..6db9909f91 100644 --- a/packages/backend/src/payment-method/ilp/peer/model.test.ts +++ b/packages/backend/src/payment-method/ilp/peer/model.test.ts @@ -3,7 +3,6 @@ import { faker } from '@faker-js/faker' import { v4 as uuid } from 'uuid' import { PeerService } from './service' -import { Config } from '../../../config/app' import { createTestApp, TestContainer } from '../../../tests/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' @@ -22,7 +21,7 @@ describe('Models', (): void => { let asset: Asset beforeAll(async (): Promise => { - deps = initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) peerService = await deps.use('peerService') knex = await deps.use('knex') diff --git a/packages/backend/src/payment-method/ilp/peer/service.test.ts b/packages/backend/src/payment-method/ilp/peer/service.test.ts index 9d0a7ae430..a8690c9404 100644 --- a/packages/backend/src/payment-method/ilp/peer/service.test.ts +++ b/packages/backend/src/payment-method/ilp/peer/service.test.ts @@ -5,7 +5,6 @@ import { v4 as uuid } from 'uuid' import { isPeerError, PeerError } from './errors' import { CreateOptions, PeerService, UpdateOptions } from './service' import { createTestApp, TestContainer } from '../../../tests/app' -import { Config } from '../../../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' import { AppServices } from '../../../app' @@ -44,7 +43,7 @@ describe('Peer Service', (): void => { }) beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) peerService = await deps.use('peerService') accountingService = await deps.use('accountingService') diff --git a/packages/backend/src/payment-method/ilp/service.test.ts b/packages/backend/src/payment-method/ilp/service.test.ts index 54f7b71025..549a8c808c 100644 --- a/packages/backend/src/payment-method/ilp/service.test.ts +++ b/packages/backend/src/payment-method/ilp/service.test.ts @@ -36,11 +36,9 @@ describe('IlpPaymentService', (): void => { const walletAddressMap: Record = {} beforeAll(async (): Promise => { - deps = initIocContainer({ - ...Config, - exchangeRatesUrl, - exchangeRatesLifetime: 0 - }) + Config.exchangeRatesUrl = exchangeRatesUrl + Config.exchangeRatesLifetime = 0 + deps = initIocContainer() appContainer = await createTestApp(deps) config = await deps.use('config') diff --git a/packages/backend/src/payment-method/ilp/spsp/middleware.test.ts b/packages/backend/src/payment-method/ilp/spsp/middleware.test.ts index 0bf9fd7ed1..04aaa5deeb 100644 --- a/packages/backend/src/payment-method/ilp/spsp/middleware.test.ts +++ b/packages/backend/src/payment-method/ilp/spsp/middleware.test.ts @@ -1,6 +1,5 @@ import { createSpspMiddleware, SPSPWalletAddressContext } from './middleware' import { setup } from '../../../open_payments/wallet_address/model.test' -import { Config } from '../../../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' import { AppServices } from '../../../app' @@ -15,7 +14,7 @@ describe('SPSP Middleware', (): void => { let next: jest.MockedFunction<() => Promise> beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) diff --git a/packages/backend/src/payment-method/ilp/spsp/routes.test.ts b/packages/backend/src/payment-method/ilp/spsp/routes.test.ts index 95385c7078..3efc04b546 100644 --- a/packages/backend/src/payment-method/ilp/spsp/routes.test.ts +++ b/packages/backend/src/payment-method/ilp/spsp/routes.test.ts @@ -6,7 +6,6 @@ import { SPSPRoutes } from './routes' import { createTestApp, TestContainer } from '../../../tests/app' import { initIocContainer } from '../../..' import { AssetOptions } from '../../../asset/service' -import { Config } from '../../../config/app' import { IocContract } from '@adonisjs/fold' import { StreamServer } from '@interledger/stream-receiver' @@ -29,7 +28,7 @@ describe('SPSP Routes', (): void => { const secret = crypto.randomBytes(32).toString('base64') beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) diff --git a/packages/backend/src/payment-method/ilp/stream-credentials/service.test.ts b/packages/backend/src/payment-method/ilp/stream-credentials/service.test.ts index 22c4f4842b..99c968a1fd 100644 --- a/packages/backend/src/payment-method/ilp/stream-credentials/service.test.ts +++ b/packages/backend/src/payment-method/ilp/stream-credentials/service.test.ts @@ -2,7 +2,6 @@ import { Knex } from 'knex' import { createTestApp, TestContainer } from '../../../tests/app' import { StreamCredentialsService } from './service' import { IncomingPayment } from '../../../open_payments/payment/incoming/model' -import { Config } from '../../../config/app' import { IocContract } from '@adonisjs/fold' import { initIocContainer } from '../../..' import { AppServices } from '../../../app' @@ -20,7 +19,7 @@ describe('Stream Credentials Service', (): void => { let incomingPayment: IncomingPayment beforeAll(async (): Promise => { - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) streamCredentialsService = await deps.use('streamCredentialsService') knex = appContainer.knex diff --git a/packages/backend/src/rates/service.test.ts b/packages/backend/src/rates/service.test.ts index 5778a54fc6..be2fb562ee 100644 --- a/packages/backend/src/rates/service.test.ts +++ b/packages/backend/src/rates/service.test.ts @@ -33,11 +33,9 @@ describe('Rates service', function () { } beforeAll(async (): Promise => { - deps = initIocContainer({ - ...Config, - exchangeRatesUrl, - exchangeRatesLifetime - }) + Config.exchangeRatesUrl = exchangeRatesUrl + Config.exchangeRatesLifetime = exchangeRatesLifetime + deps = initIocContainer() appContainer = await createTestApp(deps) service = await deps.use('ratesService') diff --git a/packages/backend/src/shared/pagination.test.ts b/packages/backend/src/shared/pagination.test.ts index 18be4c5541..bab7c4687c 100644 --- a/packages/backend/src/shared/pagination.test.ts +++ b/packages/backend/src/shared/pagination.test.ts @@ -30,7 +30,7 @@ describe('Pagination', (): void => { beforeAll(async (): Promise => { config = Config config.openPaymentsUrl = 'https://wallet.example' - deps = await initIocContainer(config) + deps = initIocContainer() appContainer = await createTestApp(deps) }) diff --git a/packages/backend/src/telemetry/service.test.ts b/packages/backend/src/telemetry/service.test.ts index 08616ee218..c760888cee 100644 --- a/packages/backend/src/telemetry/service.test.ts +++ b/packages/backend/src/telemetry/service.test.ts @@ -34,13 +34,11 @@ describe('TelemetryServiceImpl', () => { let internalRatesService: RatesService beforeAll(async (): Promise => { - deps = initIocContainer({ - ...Config, - enableTelemetry: true, - telemetryExchangeRatesUrl: 'http://example-rates.com', - telemetryExchangeRatesLifetime: 100, - openTelemetryCollectors: [] - }) + Config.enableTelemetry = true + Config.telemetryExchangeRatesUrl = 'http://example-rates.com' + Config.telemetryExchangeRatesLifetime = 100 + Config.openTelemetryCollectors = [] + deps = initIocContainer() appContainer = await createTestApp(deps) telemetryService = await deps.use('telemetry')! diff --git a/packages/backend/src/tests/tigerbeetle.ts b/packages/backend/src/tests/tigerbeetle.ts index e56b363f70..3716130620 100644 --- a/packages/backend/src/tests/tigerbeetle.ts +++ b/packages/backend/src/tests/tigerbeetle.ts @@ -1,6 +1,5 @@ import { GenericContainer, StartedTestContainer, Wait } from 'testcontainers' import tmp from 'tmp' - import { Config } from '../config/app' const TIGERBEETLE_PORT = 3004 diff --git a/packages/backend/src/webhook/service.test.ts b/packages/backend/src/webhook/service.test.ts index bb33fdec72..d5ab48a220 100644 --- a/packages/backend/src/webhook/service.test.ts +++ b/packages/backend/src/webhook/service.test.ts @@ -64,7 +64,7 @@ describe('Webhook Service', (): void => { beforeAll(async (): Promise => { Config.signatureSecret = WEBHOOK_SECRET Config.webhookMaxRetry = 10 - deps = await initIocContainer(Config) + deps = initIocContainer() appContainer = await createTestApp(deps) knex = appContainer.knex webhookService = await deps.use('webhookService') diff --git a/packages/backend/tsconfig.json b/packages/backend/tsconfig.json index a980bcb4f4..d3ae893a16 100644 --- a/packages/backend/tsconfig.json +++ b/packages/backend/tsconfig.json @@ -3,7 +3,9 @@ "compilerOptions": { "lib": ["ESNext"], "outDir": "./dist", - "rootDir": "./src" + "rootDir": "./src", + "emitDecoratorMetadata": true, + "experimentalDecorators": true }, "include": ["src/**/*"] } From 20f1030affaa6d55ed6db37bcfdfc4e2c80be4e9 Mon Sep 17 00:00:00 2001 From: golobitch Date: Sun, 12 May 2024 16:39:16 +0200 Subject: [PATCH 3/3] fix(auth): throw error if value is undefined --- packages/auth/src/config/app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/auth/src/config/app.ts b/packages/auth/src/config/app.ts index 138d99a6f5..035786c7c8 100644 --- a/packages/auth/src/config/app.ts +++ b/packages/auth/src/config/app.ts @@ -4,7 +4,7 @@ function envString(name: string, value?: string): string { const envValue = process.env[name] if (envValue) return envValue - if (typeof(value) === 'undefined') { + if (typeof value === 'undefined') { throw new Error(`Missing required key value (${name})`) }