From 7170e125a76e76bced20f2005996c444ed69da4d Mon Sep 17 00:00:00 2001 From: Marcelo Lazaroni Date: Tue, 14 Oct 2025 13:52:21 +0100 Subject: [PATCH] Incorporate services module into integrations module --- src/app/handleCommand.ts | 2 +- src/app/integrations.ts | 38 ++++++++++++++++++++++++++++++++++-- src/app/services/index.ts | 41 --------------------------------------- 3 files changed, 37 insertions(+), 44 deletions(-) delete mode 100644 src/app/services/index.ts diff --git a/src/app/handleCommand.ts b/src/app/handleCommand.ts index 593e8c2..d76f44c 100644 --- a/src/app/handleCommand.ts +++ b/src/app/handleCommand.ts @@ -8,7 +8,7 @@ import * as router from '@/lib/router'; import { Future } from '@/lib/Future'; import { Result, Failure } from '@/lib/Result'; import { Repositories, Projections, allProjections } from '@/app/projections'; -import { Services } from '@/app/services'; +import { Services } from '@/app/integrations'; import { WithProjectionStore } from '@/app/projectionStore'; import { WithEventStore } from '@/app/eventStore'; diff --git a/src/app/integrations.ts b/src/app/integrations.ts index fd76a97..bf802c2 100644 --- a/src/app/integrations.ts +++ b/src/app/integrations.ts @@ -1,4 +1,4 @@ -export { type Dependencies, configureDependencies }; +export { type Dependencies, configureDependencies, type Services }; import env from '@/app/environment'; import { Postgres, defaultPoolSettings } from '@/lib/postgres'; @@ -7,11 +7,12 @@ import { MongoProjectionStore, WithProjectionStore, } from '@/app/projectionStore'; +import { EmailService } from '@/app/services/email'; +import { FileStorageService } from '@/app/services/file-storage'; import { ServerApiVersion } from 'mongodb'; import * as eventStore from '@/app/eventStore'; import { PostgresEventStore, WithEventStore } from '@/app/eventStore'; import { schemas } from '@/app/events'; -import { Services, initializeServices } from '@/app/services'; import { Repositories, initializeRepositories } from '@/app/projections'; type Dependencies = { @@ -21,6 +22,11 @@ type Dependencies = { repositories: Repositories; }; +type Services = { + fileStorage: FileStorageService; + email: EmailService; +}; + async function configureDependencies(): Promise { const postgres = new Postgres({ user: env.EVENT_STORE_USER, @@ -87,3 +93,31 @@ async function configureDependencies(): Promise { repositories, }; } + +function initializeServices(): Services { + const url = new URL(env.S3_ENDPOINT_URL); + return { + fileStorage: new FileStorageService({ + endPoint: url.hostname, + port: url.port + ? parseInt(url.port) + : url.protocol === 'https:' + ? 443 + : 80, + useSSL: url.protocol === 'https:', + accessKey: env.S3_ACCESS_KEY, + secretKey: env.S3_SECRET_KEY, + region: env.S3_REGION, + }), + email: new EmailService({ + host: env.SMTP_HOST, + port: env.SMTP_PORT, + secure: true, + auth: { + user: env.SMTP_USERNAME, + pass: env.SMTP_PASSWORD, + }, + defaultFrom: env.SMTP_FROM_EMAIL, + }), + }; +} diff --git a/src/app/services/index.ts b/src/app/services/index.ts deleted file mode 100644 index 717555c..0000000 --- a/src/app/services/index.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* - All application services -*/ -export { type Services, initializeServices }; - -import { EmailService } from '@/app/services/email'; -import { FileStorageService } from '@/app/services/file-storage'; -import env from '@/app/environment'; - -type Services = { - fileStorage: FileStorageService; - email: EmailService; -}; - -function initializeServices(): Services { - const url = new URL(env.S3_ENDPOINT_URL); - return { - fileStorage: new FileStorageService({ - endPoint: url.hostname, - port: url.port - ? parseInt(url.port) - : url.protocol === 'https:' - ? 443 - : 80, - useSSL: url.protocol === 'https:', - accessKey: env.S3_ACCESS_KEY, - secretKey: env.S3_SECRET_KEY, - region: env.S3_REGION, - }), - email: new EmailService({ - host: env.SMTP_HOST, - port: env.SMTP_PORT, - secure: true, - auth: { - user: env.SMTP_USERNAME, - pass: env.SMTP_PASSWORD, - }, - defaultFrom: env.SMTP_FROM_EMAIL, - }), - }; -}