@venizia/ignis 0.4.8-13 → 0.4.8-15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/components/mail/common/constants.d.ts +24 -14
- package/dist/esm/components/mail/common/constants.js +19 -32
- package/dist/esm/components/mail/common/constants.js.map +1 -1
- package/dist/esm/components/mail/common/errors.d.ts +10 -1
- package/dist/esm/components/mail/common/errors.js +7 -1
- package/dist/esm/components/mail/common/errors.js.map +1 -1
- package/dist/esm/components/mail/common/types/queue.d.ts +15 -8
- package/dist/esm/components/mail/common/types/queue.js.map +1 -1
- package/dist/esm/components/mail/common/types/template.d.ts +3 -2
- package/dist/esm/components/mail/common/types/template.js.map +1 -1
- package/dist/esm/components/mail/component.js +11 -2
- package/dist/esm/components/mail/component.js.map +1 -1
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +13 -12
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +2 -0
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +17 -10
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +4 -4
- package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +15 -6
- package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +2 -2
- package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -2
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +7 -9
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
- package/dist/esm/components/mail/providers/mail-transporter.provider.js +7 -7
- package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
- package/dist/esm/components/mail/services/mail.service.js +21 -19
- package/dist/esm/components/mail/services/mail.service.js.map +1 -1
- package/dist/esm/components/mail/services/template.service.d.ts +4 -1
- package/dist/esm/components/mail/services/template.service.js +24 -16
- package/dist/esm/components/mail/services/template.service.js.map +1 -1
- package/dist/esm/components/mail/utilities/attachment.utility.js +8 -6
- package/dist/esm/components/mail/utilities/attachment.utility.js.map +1 -1
- package/dist/esm/components/mail/utilities/header.utility.d.ts +14 -0
- package/dist/esm/components/mail/utilities/header.utility.js +44 -0
- package/dist/esm/components/mail/utilities/header.utility.js.map +1 -0
- package/dist/esm/components/mail/utilities/index.d.ts +1 -0
- package/dist/esm/components/mail/utilities/index.js +1 -0
- package/dist/esm/components/mail/utilities/index.js.map +1 -1
- package/dist/esm/components/mail/utilities/mime.utility.d.ts +5 -1
- package/dist/esm/components/mail/utilities/mime.utility.js +9 -55
- package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
- package/dist/esm/components/static-asset/common/constants.d.ts +5 -4
- package/dist/esm/components/static-asset/common/constants.js +5 -9
- package/dist/esm/components/static-asset/common/constants.js.map +1 -1
- package/dist/esm/components/static-asset/common/errors.d.ts +18 -0
- package/dist/esm/components/static-asset/common/errors.js +18 -0
- package/dist/esm/components/static-asset/common/errors.js.map +1 -1
- package/dist/esm/components/static-asset/common/types.d.ts +47 -18
- package/dist/esm/components/static-asset/common/types.js.map +1 -1
- package/dist/esm/components/static-asset/component.js +1 -1
- package/dist/esm/components/static-asset/component.js.map +1 -1
- package/dist/esm/components/static-asset/controller/factory.d.ts +2 -166
- package/dist/esm/components/static-asset/controller/factory.js +7 -20
- package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
- package/dist/esm/components/static-asset/controller/index.d.ts +1 -0
- package/dist/esm/components/static-asset/controller/index.js +1 -0
- package/dist/esm/components/static-asset/controller/index.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/context.d.ts +1 -1
- package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/definition.js +15 -6
- package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/direct-upload.js +24 -2
- package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/serve.d.ts +14 -2
- package/dist/esm/components/static-asset/controller/routes/serve.js +40 -15
- package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/upload.js +11 -10
- package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -1
- package/dist/esm/components/static-asset/services/commitment.service.d.ts +35 -16
- package/dist/esm/components/static-asset/services/commitment.service.js +92 -30
- package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -1
- package/dist/esm/components/static-asset/services/policy.service.d.ts +7 -3
- package/dist/esm/components/static-asset/services/policy.service.js +21 -2
- package/dist/esm/components/static-asset/services/policy.service.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +2 -1
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js +14 -5
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/entry.utility.js +9 -2
- package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +6 -7
- package/dist/esm/components/static-asset/utilities/route-options.utility.js +9 -23
- package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -1
- package/dist/presets/app/preset.json +4 -4
- package/dist/presets/lib/preset.json +3 -3
- package/dist/presets/shared/preset.json +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bull-mq-executor.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/executors/bull-mq-executor.helper.ts"],"names":[],"mappings":"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AO,EAAE,0CAA0C;SACpD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport type { IRedisHelper } from '@venizia/ignis-helpers';\nimport type { TConstValue } from '@/helpers';\nimport { BullMQHelper } from '@venizia/ignis-helpers/bullmq';\nimport type {\n IBullMQMailExecutorOpts,\n IMailProcessorResult,\n IMailQueueExecutor,\n IMailQueueOptions,\n IMailQueueResult,\n IQueueJobPayload,\n} from '../../common';\nimport {\n BullMQExecutorModes,\n MailBackoffTypes,\n MailErrorCodes,\n MailExecutorErrors,\n} from '../../common';\nimport type { Job } from 'bullmq';\n\n/** Mail queue executor backed by BullMQ. The `mode` option decides whether this process holds the queue, the workers, or both; a processor returning `success: false` fails the job so BullMQ retries it. */\nexport class BullMQMailExecutorHelper extends BaseHelper implements IMailQueueExecutor {\n private queueIdentifier: string;\n private queueName: string;\n private mode: TConstValue<typeof BullMQExecutorModes>;\n\n private queueHelper?: BullMQHelper<IQueueJobPayload, IMailQueueResult>;\n private workerHelpers: BullMQHelper<IQueueJobPayload, IMailProcessorResult>[] = [];\n private redisConnection: IRedisHelper;\n private readonly bullmqModule?: typeof import('bullmq');\n private jobIdCounter = 0;\n\n private processor?: (email: string) => Promise<IMailProcessorResult>;\n\n constructor(opts: IBullMQMailExecutorOpts) {\n super({ scope: BullMQMailExecutorHelper.name });\n\n this.mode = opts.mode;\n\n this.redisConnection = opts.redis;\n\n this.bullmqModule = opts.module;\n this.queueIdentifier = opts.queue.identifier;\n this.queueName = opts.queue.name;\n\n this.initQueue(opts.queue);\n }\n\n initQueue(queue: { identifier: string; name: string }) {\n switch (this.mode) {\n case BullMQExecutorModes.QUEUE_ONLY:\n case BullMQExecutorModes.BOTH: {\n this.queueHelper = new BullMQHelper<IQueueJobPayload, IMailQueueResult>({\n identifier: queue.identifier,\n queueName: queue.name,\n redisConnection: this.redisConnection,\n role: 'queue',\n module: this.bullmqModule,\n });\n\n this.logger\n .for(this.constructor.name)\n .info(\n 'BullMQ queue executor initialized (queue enabled) | Identifier: %s | Mode: %s',\n this.queueIdentifier,\n this.mode,\n );\n break;\n }\n default: {\n this.logger\n .for(this.constructor.name)\n .info(\n 'BullMQ queue executor initialized (worker-only mode) | Identifier: %s | Mode: %s',\n this.queueIdentifier,\n this.mode,\n );\n\n break;\n }\n }\n }\n\n async setProcessor(\n processor: (email: string) => Promise<IMailProcessorResult>,\n opts?: {\n numberOfWorkers?: number;\n concurrencyPerWorker?: number;\n lockDuration?: number;\n },\n ): Promise<void> {\n this.processor = processor;\n\n if (this.mode === BullMQExecutorModes.QUEUE_ONLY) {\n this.logger\n .for(this.setProcessor.name)\n .warn('Skipping worker creation in queue-only mode. Workers will not be started.');\n\n return;\n }\n\n const numberOfWorkers = opts?.numberOfWorkers ?? 1;\n const concurrencyPerWorker = opts?.concurrencyPerWorker ?? 5;\n const lockDuration = opts?.lockDuration ?? 30000;\n\n await this.clearWorkers();\n\n for (let i = 0; i < numberOfWorkers; i++) {\n this.addWorker({\n workerIdentifier: `${this.queueIdentifier}-worker-${i}`,\n concurrency: concurrencyPerWorker,\n lockDuration,\n });\n }\n\n this.logger\n .for(this.setProcessor.name)\n .info(\n 'Processor registered | Mode: %s | Workers: %d | Concurrency per worker: %d',\n this.mode,\n numberOfWorkers,\n concurrencyPerWorker,\n );\n }\n\n addWorker(opts: { workerIdentifier: string; concurrency?: number; lockDuration?: number }): void {\n if (!this.processor) {\n throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });\n }\n\n const workerIdentifier = opts.workerIdentifier;\n const concurrency = opts?.concurrency ?? 5;\n const lockDuration = opts?.lockDuration ?? 30000;\n\n const workerHelper = new BullMQHelper<IQueueJobPayload, IMailProcessorResult>({\n identifier: workerIdentifier,\n queueName: this.queueName,\n redisConnection: this.redisConnection,\n role: 'worker',\n module: this.bullmqModule,\n numberOfWorker: concurrency,\n lockDuration,\n onWorkerData: async (job: Job<IQueueJobPayload, IMailProcessorResult>) => {\n const maxAttempts = job.data.options?.attempts ?? 3;\n\n this.logger\n .for('onWorkerData')\n .info(\n 'Processing job | Worker: %s | jobId: %s | email: %s | attempt: %d/%d',\n workerIdentifier,\n job.data.id,\n job.data.email,\n job.attemptsMade + 1,\n maxAttempts,\n );\n\n if (!this.processor) {\n // Returning undefined would let BullMQ mark the job COMPLETED and (with removeOnComplete) delete it - mail silently dropped.\n throw getError({\n messageCode: MailErrorCodes.SEND_FAILED,\n message: `[onWorkerData] ${MailExecutorErrors.PROCESSOR_NOT_SET} | jobId: ${job.data.id}`,\n });\n }\n\n const result = await this.processor(job.data.email);\n\n // A processor reports SMTP rejection by RETURNING `{ success: false }`; BullMQ only treats a REJECTION as failure, so resolving completes the job - no retry, no DLQ.\n if (result?.success === false) {\n throw getError({\n messageCode: MailErrorCodes.SEND_FAILED,\n message: `[onWorkerData] Processor reported failure | jobId: ${job.data.id} | reason: ${result.message}`,\n });\n }\n\n return result;\n },\n onWorkerDataCompleted: async (job: Job<IQueueJobPayload, IMailProcessorResult>) => {\n this.logger\n .for('onWorkerDataCompleted')\n .info(\n 'Job completed | Worker: %s | jobId: %s | email: %s',\n workerIdentifier,\n job.data.id,\n job.data.email,\n );\n },\n onWorkerDataFail: async (\n job: Job<IQueueJobPayload, IMailProcessorResult> | undefined,\n error: Error,\n ) => {\n if (job) {\n const maxAttempts = job.data.options?.attempts ?? 3;\n this.logger\n .for('onWorkerDataFail')\n .error(\n 'Job failed | Worker: %s | jobId: %s | email: %s | attempt: %d/%d | error: %s',\n workerIdentifier,\n job.data.id,\n job.data.email,\n job.attemptsMade,\n maxAttempts,\n error.message,\n );\n } else {\n this.logger\n .for('onWorkerDataFail')\n .error(\n 'Worker error (no job) | Worker: %s | error: %s',\n workerIdentifier,\n error.message,\n );\n }\n },\n });\n\n this.workerHelpers.push(workerHelper);\n\n this.logger\n .for(this.addWorker.name)\n .info(\n 'Worker added | Identifier: %s | Concurrency: %d | Total workers: %d',\n workerIdentifier,\n concurrency,\n this.workerHelpers.length,\n );\n }\n\n async removeWorker(index: number): Promise<boolean> {\n if (index < 0 || index >= this.workerHelpers.length) {\n this.logger.for(this.removeWorker.name).warn('Invalid worker index: %d', index);\n\n return false;\n }\n\n // Dropped from the list BEFORE the close is awaited: a rejecting close must not leave a half-closed worker still counted and still handed jobs.\n const [workerHelper] = this.workerHelpers.splice(index, 1);\n await workerHelper.worker.close();\n\n this.logger\n .for(this.removeWorker.name)\n .info('Worker removed | Index: %d | Remaining workers: %d', index, this.workerHelpers.length);\n\n return true;\n }\n\n /** Closes every worker without stopping at the first failure, always empties the list, and returns failures instead of throwing so teardown can continue. */\n private async closeWorkers(): Promise<Error[]> {\n const workerHelpers = this.workerHelpers;\n this.workerHelpers = [];\n\n const results = await Promise.allSettled(\n workerHelpers.map((workerHelper) => workerHelper.worker.close()),\n );\n\n const failures: Error[] = [];\n\n for (const result of results) {\n if (result.status !== 'rejected') {\n continue;\n }\n\n const error =\n result.reason instanceof Error\n ? result.reason\n : getError({ message: `Worker close failed | reason: ${String(result.reason)}` });\n\n failures.push(error);\n this.logger.for('closeWorkers').error('Failed to close worker | error: %s', error.message);\n }\n\n return failures;\n }\n\n async clearWorkers(): Promise<void> {\n const count = this.workerHelpers.length;\n await this.closeWorkers();\n\n this.logger.for(this.clearWorkers.name).info('All workers cleared | Count: %d', count);\n }\n\n /** Closes the workers, then the queue. Every step runs even if an earlier one failed; failures are reported once, at the end. The Redis helper is the application's, so it stays open. */\n async close(): Promise<void> {\n const result = await this.closeWorkers();\n const failures: Error[] = [...result];\n\n if (this.queueHelper) {\n try {\n await this.queueHelper.queue.close();\n } catch (error) {\n const closeError = error instanceof Error ? error : getError({ message: String(error) });\n failures.push(closeError);\n this.logger.for(this.close.name).error('Failed to close queue | error: %s', closeError);\n }\n }\n\n if (failures.length > 0) {\n throw getError({\n message: `[close] Incomplete BullMQ mail executor teardown | failures: ${failures\n .map((failure) => failure.message)\n .join(' | ')}`,\n });\n }\n\n this.logger.for(this.close.name).info('BullMQ mail executor closed | Mode: %s', this.mode);\n }\n\n getWorkerCount(): number {\n return this.workerHelpers.length;\n }\n\n getMode(): TConstValue<typeof BullMQExecutorModes> {\n return this.mode;\n }\n\n async enqueueVerificationEmail(\n email: string,\n options?: IMailQueueOptions,\n ): Promise<IMailQueueResult> {\n if (this.mode === BullMQExecutorModes.WORKER_ONLY) {\n throw getError({\n message: 'Cannot enqueue jobs in worker-only mode. Set mode to \"queue-only\" or \"both\".',\n });\n }\n\n if (!this.queueHelper) {\n throw getError({\n message: 'Queue helper not initialized. This should not happen in queue-enabled mode.',\n });\n }\n\n if (!this.processor && this.mode !== BullMQExecutorModes.QUEUE_ONLY) {\n throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });\n }\n\n const jobId = `job_${++this.jobIdCounter}_${Date.now()}`;\n const job: IQueueJobPayload = {\n id: jobId,\n email,\n options,\n attempts: 0,\n scheduledAt: Date.now() + (options?.delay ?? 0),\n };\n\n this.logger\n .for(this.enqueueVerificationEmail.name)\n .info(\n 'Queuing email to BullMQ/Redis | jobId: %s | email: %s | mode: %s',\n jobId,\n email,\n this.mode,\n );\n\n const bullJob = await this.queueHelper.queue.add('send-verification-email', job, {\n priority: options?.priority,\n delay: options?.delay,\n attempts: options?.attempts ?? 3,\n backoff: {\n type: options?.backoff?.type ?? MailBackoffTypes.EXPONENTIAL,\n delay: options?.backoff?.delay ?? 1000,\n },\n removeOnComplete: true,\n removeOnFail: false,\n });\n\n return {\n jobId: bullJob.id ?? jobId,\n queued: true,\n message: 'Email queued successfully (BullMQ/Redis)',\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bull-mq-executor.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/executors/bull-mq-executor.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGnE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAS7D,OAAO,EACL,mBAAm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seHelper, getError } from '@venizia/ignis-helpers/core';\nimport type { IRedisHelper } from '@venizia/ignis-helpers';\nimport type { TConstValue } from '@/helpers';\nimport { BullMQHelper } from '@venizia/ignis-helpers/bullmq';\nimport type {\n IBullMQMailExecutorOpts,\n IMailProcessorResult,\n IMailQueueExecutor,\n IMailQueueOptions,\n IMailQueueResult,\n IQueueJobPayload,\n} from '../../common';\nimport {\n BullMQExecutorModes,\n MailBackoffTypes,\n MailDefaults,\n MailErrorCodes,\n MailExecutorErrors,\n MailQueueJobNames,\n} from '../../common';\nimport type { Job } from 'bullmq';\n\n/** Mail queue executor backed by BullMQ. The `mode` option decides whether this process holds the queue, the workers, or both; a processor returning `success: false` fails the job so BullMQ retries it. */\nexport class BullMQMailExecutorHelper extends BaseHelper implements IMailQueueExecutor {\n private queueIdentifier: string;\n private queueName: string;\n private mode: TConstValue<typeof BullMQExecutorModes>;\n\n private queueHelper?: BullMQHelper<IQueueJobPayload, IMailQueueResult>;\n private workerHelpers: BullMQHelper<IQueueJobPayload, IMailProcessorResult>[] = [];\n private redisConnection: IRedisHelper;\n private readonly bullmqModule?: typeof import('bullmq');\n private jobIdCounter = 0;\n\n private processor?: (email: string) => Promise<IMailProcessorResult>;\n\n constructor(opts: IBullMQMailExecutorOpts) {\n super({ scope: BullMQMailExecutorHelper.name });\n\n this.mode = opts.mode;\n\n this.redisConnection = opts.redis;\n\n this.bullmqModule = opts.module;\n this.queueIdentifier = opts.queue.identifier;\n this.queueName = opts.queue.name;\n\n this.initQueue(opts.queue);\n }\n\n initQueue(queue: { identifier: string; name: string }) {\n switch (this.mode) {\n case BullMQExecutorModes.QUEUE_ONLY:\n case BullMQExecutorModes.BOTH: {\n this.queueHelper = new BullMQHelper<IQueueJobPayload, IMailQueueResult>({\n identifier: queue.identifier,\n queueName: queue.name,\n redisConnection: this.redisConnection,\n role: 'queue',\n module: this.bullmqModule,\n });\n\n this.logger\n .for(this.constructor.name)\n .info(\n 'BullMQ queue executor initialized (queue enabled) | Identifier: %s | Mode: %s',\n this.queueIdentifier,\n this.mode,\n );\n break;\n }\n default: {\n this.logger\n .for(this.constructor.name)\n .info(\n 'BullMQ queue executor initialized (worker-only mode) | Identifier: %s | Mode: %s',\n this.queueIdentifier,\n this.mode,\n );\n\n break;\n }\n }\n }\n\n async setProcessor(\n processor: (email: string) => Promise<IMailProcessorResult>,\n opts?: {\n numberOfWorkers?: number;\n concurrencyPerWorker?: number;\n lockDuration?: number;\n },\n ): Promise<void> {\n this.processor = processor;\n\n if (this.mode === BullMQExecutorModes.QUEUE_ONLY) {\n this.logger\n .for(this.setProcessor.name)\n .warn('Skipping worker creation in queue-only mode. Workers will not be started.');\n\n return;\n }\n\n const numberOfWorkers = opts?.numberOfWorkers ?? 1;\n const concurrencyPerWorker = opts?.concurrencyPerWorker ?? 5;\n const lockDuration = opts?.lockDuration ?? 30000;\n\n await this.clearWorkers();\n\n for (let i = 0; i < numberOfWorkers; i++) {\n this.addWorker({\n workerIdentifier: `${this.queueIdentifier}-worker-${i}`,\n concurrency: concurrencyPerWorker,\n lockDuration,\n });\n }\n\n this.logger\n .for(this.setProcessor.name)\n .info(\n 'Processor registered | Mode: %s | Workers: %d | Concurrency per worker: %d',\n this.mode,\n numberOfWorkers,\n concurrencyPerWorker,\n );\n }\n\n addWorker(opts: { workerIdentifier: string; concurrency?: number; lockDuration?: number }): void {\n if (!this.processor) {\n throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });\n }\n\n const workerIdentifier = opts.workerIdentifier;\n const concurrency = opts?.concurrency ?? 5;\n const lockDuration = opts?.lockDuration ?? 30000;\n\n const workerHelper = new BullMQHelper<IQueueJobPayload, IMailProcessorResult>({\n identifier: workerIdentifier,\n queueName: this.queueName,\n redisConnection: this.redisConnection,\n role: 'worker',\n module: this.bullmqModule,\n numberOfWorker: concurrency,\n lockDuration,\n onWorkerData: async (job: Job<IQueueJobPayload, IMailProcessorResult>) => {\n const maxAttempts = job.data.options?.attempts ?? MailDefaults.ATTEMPTS;\n\n this.logger\n .for('onWorkerData')\n .info(\n 'Processing job | Worker: %s | jobId: %s | email: %s | attempt: %d/%d',\n workerIdentifier,\n job.data.id,\n job.data.email,\n job.attemptsMade + 1,\n maxAttempts,\n );\n\n if (!this.processor) {\n // Returning undefined would let BullMQ mark the job COMPLETED and (with removeOnComplete) delete it - mail silently dropped.\n throw getError({\n messageCode: MailErrorCodes.SEND_FAILED,\n message: `[onWorkerData] ${MailExecutorErrors.PROCESSOR_NOT_SET} | jobId: ${job.data.id}`,\n });\n }\n\n const result = await this.processor(job.data.email);\n\n // A processor reports SMTP rejection by RETURNING `{ success: false }`; BullMQ only treats a REJECTION as failure, so resolving completes the job - no retry, no DLQ.\n if (result?.success === false) {\n throw getError({\n messageCode: MailErrorCodes.SEND_FAILED,\n message: `[onWorkerData] Processor reported failure | jobId: ${job.data.id} | reason: ${result.message}`,\n });\n }\n\n return result;\n },\n onWorkerDataCompleted: async (job: Job<IQueueJobPayload, IMailProcessorResult>) => {\n this.logger\n .for('onWorkerDataCompleted')\n .info(\n 'Job completed | Worker: %s | jobId: %s | email: %s',\n workerIdentifier,\n job.data.id,\n job.data.email,\n );\n },\n onWorkerDataFail: async (\n job: Job<IQueueJobPayload, IMailProcessorResult> | undefined,\n error: Error,\n ) => {\n if (job) {\n const maxAttempts = job.data.options?.attempts ?? MailDefaults.ATTEMPTS;\n this.logger\n .for('onWorkerDataFail')\n .error(\n 'Job failed | Worker: %s | jobId: %s | email: %s | attempt: %d/%d | error: %s',\n workerIdentifier,\n job.data.id,\n job.data.email,\n job.attemptsMade,\n maxAttempts,\n error.message,\n );\n } else {\n this.logger\n .for('onWorkerDataFail')\n .error(\n 'Worker error (no job) | Worker: %s | error: %s',\n workerIdentifier,\n error.message,\n );\n }\n },\n });\n\n this.workerHelpers.push(workerHelper);\n\n this.logger\n .for(this.addWorker.name)\n .info(\n 'Worker added | Identifier: %s | Concurrency: %d | Total workers: %d',\n workerIdentifier,\n concurrency,\n this.workerHelpers.length,\n );\n }\n\n async removeWorker(index: number): Promise<boolean> {\n if (index < 0 || index >= this.workerHelpers.length) {\n this.logger.for(this.removeWorker.name).warn('Invalid worker index: %d', index);\n\n return false;\n }\n\n // The helper closes the worker, then quits the connections it handed to BullMQ. Dropped from the list BEFORE the close is awaited: a rejecting close must not leave a half-closed worker still counted and still handed jobs.\n const [workerHelper] = this.workerHelpers.splice(index, 1);\n await workerHelper.close();\n\n this.logger\n .for(this.removeWorker.name)\n .info('Worker removed | Index: %d | Remaining workers: %d', index, this.workerHelpers.length);\n\n return true;\n }\n\n /** Closes every worker without stopping at the first failure, always empties the list, and returns failures instead of throwing so teardown can continue. */\n private async closeWorkers(): Promise<Error[]> {\n const workerHelpers = this.workerHelpers;\n this.workerHelpers = [];\n\n const results = await Promise.allSettled(\n workerHelpers.map((workerHelper) => workerHelper.close()),\n );\n\n const failures: Error[] = [];\n\n for (const result of results) {\n if (result.status !== 'rejected') {\n continue;\n }\n\n const error =\n result.reason instanceof Error\n ? result.reason\n : getError({ message: `Worker close failed | reason: ${String(result.reason)}` });\n\n failures.push(error);\n this.logger.for('closeWorkers').error('Failed to close worker | error: %s', error.message);\n }\n\n return failures;\n }\n\n async clearWorkers(): Promise<void> {\n const count = this.workerHelpers.length;\n await this.closeWorkers();\n\n this.logger.for(this.clearWorkers.name).info('All workers cleared | Count: %d', count);\n }\n\n /** Closes the workers, then the queue. Every step runs even if an earlier one failed; failures are reported once, at the end. The Redis helper is the application's, so it stays open. */\n async close(): Promise<void> {\n const result = await this.closeWorkers();\n const failures: Error[] = [...result];\n\n if (this.queueHelper) {\n try {\n await this.queueHelper.close();\n } catch (error) {\n const closeError = error instanceof Error ? error : getError({ message: String(error) });\n failures.push(closeError);\n this.logger.for(this.close.name).error('Failed to close queue | error: %s', closeError);\n }\n }\n\n if (failures.length > 0) {\n throw getError({\n message: `[close] Incomplete BullMQ mail executor teardown | failures: ${failures\n .map((failure) => failure.message)\n .join(' | ')}`,\n });\n }\n\n this.logger.for(this.close.name).info('BullMQ mail executor closed | Mode: %s', this.mode);\n }\n\n getWorkerCount(): number {\n return this.workerHelpers.length;\n }\n\n getMode(): TConstValue<typeof BullMQExecutorModes> {\n return this.mode;\n }\n\n async enqueueVerificationEmail(\n email: string,\n options?: IMailQueueOptions,\n ): Promise<IMailQueueResult> {\n if (this.mode === BullMQExecutorModes.WORKER_ONLY) {\n throw getError({\n message: 'Cannot enqueue jobs in worker-only mode. Set mode to \"queue-only\" or \"both\".',\n });\n }\n\n if (!this.queueHelper) {\n throw getError({\n message: 'Queue helper not initialized. This should not happen in queue-enabled mode.',\n });\n }\n\n if (!this.processor && this.mode !== BullMQExecutorModes.QUEUE_ONLY) {\n throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });\n }\n\n const jobId = `job_${++this.jobIdCounter}_${Date.now()}`;\n const job: IQueueJobPayload = {\n id: jobId,\n email,\n options,\n attempts: 0,\n scheduledAt: Date.now() + (options?.delay ?? 0),\n };\n\n this.logger\n .for(this.enqueueVerificationEmail.name)\n .debug('Queuing email to BullMQ/Redis | jobId: %s | mode: %s', jobId, this.mode);\n\n const bullJob = await this.queueHelper.queue.add(\n MailQueueJobNames.SEND_VERIFICATION_EMAIL,\n job,\n {\n priority: options?.priority,\n delay: options?.delay,\n attempts: options?.attempts ?? MailDefaults.ATTEMPTS,\n backoff: {\n type: options?.backoff?.type ?? MailBackoffTypes.EXPONENTIAL,\n delay: options?.backoff?.delay ?? MailDefaults.BACKOFF_DELAY_MS,\n },\n removeOnComplete: true,\n // Bounded: a failed job holds the recipient's address, and `false` kept every one forever.\n removeOnFail: MailDefaults.FAILED_JOB_RETENTION,\n },\n );\n\n return {\n jobId: bullJob.id ?? jobId,\n queued: true,\n message: 'Email queued successfully (BullMQ/Redis)',\n };\n }\n}\n"]}
|
|
@@ -5,6 +5,8 @@ export declare class InternalQueueMailExecutorHelper extends BaseHelper implemen
|
|
|
5
5
|
private queue;
|
|
6
6
|
private jobIdCounter;
|
|
7
7
|
private delayedJobs;
|
|
8
|
+
/** Set by `close`: a job that fails afterwards must not arm a retry timer nobody will clear. */
|
|
9
|
+
private isClosed;
|
|
8
10
|
private processor?;
|
|
9
11
|
constructor(opts: IInternalQueueMailExecutorOpts);
|
|
10
12
|
setProcessor(processor: (email: string) => Promise<IMailProcessorResult>): void;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { BaseHelper, getError } from '@venizia/ignis-helpers/core';
|
|
2
2
|
import { SequentialQueueHelper } from '@venizia/ignis-helpers';
|
|
3
|
-
import { MailBackoffTypes, MailErrorCodes, MailExecutorErrors } from '../../common/index.js';
|
|
3
|
+
import { MailBackoffTypes, MailDefaults, MailErrorCodes, MailExecutorErrors } from '../../common/index.js';
|
|
4
4
|
/** In-process mail queue executor: jobs are lost on restart. Supports `delay`, `attempts` and `backoff`; call `close` to clear pending timers. */
|
|
5
5
|
export class InternalQueueMailExecutorHelper extends BaseHelper {
|
|
6
6
|
constructor(opts) {
|
|
7
7
|
super({ scope: InternalQueueMailExecutorHelper.name });
|
|
8
8
|
this.jobIdCounter = 0;
|
|
9
9
|
this.delayedJobs = new Map();
|
|
10
|
+
/** Set by `close`: a job that fails afterwards must not arm a retry timer nobody will clear. */
|
|
11
|
+
this.isClosed = false;
|
|
10
12
|
this.queue = new SequentialQueueHelper({
|
|
11
13
|
identifier: opts.identifier,
|
|
12
14
|
autoDispatch: true,
|
|
@@ -14,9 +16,7 @@ export class InternalQueueMailExecutorHelper extends BaseHelper {
|
|
|
14
16
|
await this.processJob(queueElement.payload);
|
|
15
17
|
},
|
|
16
18
|
onDataEnqueue: ({ queueElement }) => {
|
|
17
|
-
this.logger
|
|
18
|
-
.for('onDataEnqueue')
|
|
19
|
-
.info('Job enqueued | jobId: %s | email: %s', queueElement.payload.id, queueElement.payload.email);
|
|
19
|
+
this.logger.for('onDataEnqueue').debug('Job enqueued | jobId: %s', queueElement.payload.id);
|
|
20
20
|
},
|
|
21
21
|
onStateChange: ({ from, to }) => {
|
|
22
22
|
this.logger.for('onStateChange').debug('Queue state changed | from: %s | to: %s', from, to);
|
|
@@ -32,6 +32,9 @@ export class InternalQueueMailExecutorHelper extends BaseHelper {
|
|
|
32
32
|
if (!this.processor) {
|
|
33
33
|
throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });
|
|
34
34
|
}
|
|
35
|
+
if (this.isClosed) {
|
|
36
|
+
throw getError({ message: MailExecutorErrors.CLOSED });
|
|
37
|
+
}
|
|
35
38
|
const jobId = `job_${++this.jobIdCounter}_${Date.now()}`;
|
|
36
39
|
const job = {
|
|
37
40
|
id: jobId,
|
|
@@ -40,9 +43,7 @@ export class InternalQueueMailExecutorHelper extends BaseHelper {
|
|
|
40
43
|
attempts: 0,
|
|
41
44
|
scheduledAt: Date.now() + (options?.delay ?? 0),
|
|
42
45
|
};
|
|
43
|
-
this.logger
|
|
44
|
-
.for(this.enqueueVerificationEmail.name)
|
|
45
|
-
.info('Queuing email | jobId: %s | email: %s', jobId, email);
|
|
46
|
+
this.logger.for(this.enqueueVerificationEmail.name).debug('Queuing email | jobId: %s', jobId);
|
|
46
47
|
if (options?.delay && options.delay > 0) {
|
|
47
48
|
const timeout = setTimeout(() => {
|
|
48
49
|
this.queue.enqueue(job).catch((error) => {
|
|
@@ -68,6 +69,7 @@ export class InternalQueueMailExecutorHelper extends BaseHelper {
|
|
|
68
69
|
}
|
|
69
70
|
/** Releases every pending delayed/backoff timer - a live `setTimeout` holds the event loop open past the executor. */
|
|
70
71
|
async close() {
|
|
72
|
+
this.isClosed = true;
|
|
71
73
|
const pendingCount = this.delayedJobs.size;
|
|
72
74
|
const delayedJobsValues = this.delayedJobs.values();
|
|
73
75
|
for (const timeout of delayedJobsValues) {
|
|
@@ -81,7 +83,7 @@ export class InternalQueueMailExecutorHelper extends BaseHelper {
|
|
|
81
83
|
this.logger.for(this.processJob.name).error('Processor not set | jobId: %s', job.id);
|
|
82
84
|
return;
|
|
83
85
|
}
|
|
84
|
-
const maxAttempts = job.options?.attempts ??
|
|
86
|
+
const maxAttempts = job.options?.attempts ?? MailDefaults.ATTEMPTS;
|
|
85
87
|
this.logger
|
|
86
88
|
.for(this.processJob.name)
|
|
87
89
|
.info('Processing job | jobId: %s | email: %s | attempt: %d/%d', job.id, job.email, job.attempts + 1, maxAttempts);
|
|
@@ -99,7 +101,12 @@ export class InternalQueueMailExecutorHelper extends BaseHelper {
|
|
|
99
101
|
catch (error) {
|
|
100
102
|
const errorMsg = error instanceof Error ? error.message : error;
|
|
101
103
|
job.attempts++;
|
|
102
|
-
if (
|
|
104
|
+
if (this.isClosed) {
|
|
105
|
+
this.logger
|
|
106
|
+
.for(this.processJob.name)
|
|
107
|
+
.warn('Job failed after close, not retried | jobId: %s | error: %s', job.id, errorMsg);
|
|
108
|
+
}
|
|
109
|
+
else if (job.attempts < maxAttempts) {
|
|
103
110
|
const backoffDelay = this.calculateBackoff(job);
|
|
104
111
|
this.logger
|
|
105
112
|
.for(this.processJob.name)
|
|
@@ -124,7 +131,7 @@ export class InternalQueueMailExecutorHelper extends BaseHelper {
|
|
|
124
131
|
calculateBackoff(job) {
|
|
125
132
|
const backoff = job.options?.backoff;
|
|
126
133
|
if (!backoff) {
|
|
127
|
-
return
|
|
134
|
+
return MailDefaults.BACKOFF_DELAY_MS;
|
|
128
135
|
}
|
|
129
136
|
if (backoff.type === MailBackoffTypes.EXPONENTIAL) {
|
|
130
137
|
return backoff.delay * Math.pow(2, job.attempts - 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-queue-executor.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/executors/internal-queue-executor.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAS/D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEpF,kJA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c,EAAE,EAAE;wBAC/C,IAAI,CAAC,MAAM;6BACR,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;6BACzB,KAAK,CAAC,kDAAkD,EAAE,GAAG,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;oBACvF,CAAC,CAAC,CAAC;oBACH,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAClC,CAAC,EAAE,YAAY,CAAC,CAAC;gBAEjB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;YACxC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,MAAM;qBACR,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;qBACzB,KAAK,CACJ,kEAAkE,EAClE,WAAW,EACX,GAAG,CAAC,EAAE,EACN,QAAQ,CACT,CAAC;YACN,CAAC;QACH,CAAC;IACH,CAAC;IAEO,gBAAgB,CAAC,GAAqB;QAC5C,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC;QAErC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,CAAC,WAAW,EAAE,CAAC;YAClD,OAAO,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,OAAO,CAAC,KAAK,CAAC;IACvB,CAAC;CACF","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { SequentialQueueHelper } from '@venizia/ignis-helpers';\nimport type {\n IMailQueueOptions,\n IMailQueueExecutor,\n IMailProcessorResult,\n IInternalQueueMailExecutorOpts,\n IMailQueueResult,\n IQueueJobPayload,\n} from '../../common';\nimport { MailBackoffTypes, MailErrorCodes, MailExecutorErrors } from '../../common';\n\n/** In-process mail queue executor: jobs are lost on restart. Supports `delay`, `attempts` and `backoff`; call `close` to clear pending timers. */\nexport class InternalQueueMailExecutorHelper extends BaseHelper implements IMailQueueExecutor {\n private queue: SequentialQueueHelper<IQueueJobPayload>;\n private jobIdCounter = 0;\n private delayedJobs: Map<string, NodeJS.Timeout> = new Map();\n\n private processor?: (email: string) => Promise<IMailProcessorResult>;\n\n constructor(opts: IInternalQueueMailExecutorOpts) {\n super({ scope: InternalQueueMailExecutorHelper.name });\n\n this.queue = new SequentialQueueHelper<IQueueJobPayload>({\n identifier: opts.identifier,\n autoDispatch: true,\n onMessage: async ({ queueElement }) => {\n await this.processJob(queueElement.payload);\n },\n onDataEnqueue: ({ queueElement }) => {\n this.logger\n .for('onDataEnqueue')\n .info(\n 'Job enqueued | jobId: %s | email: %s',\n queueElement.payload.id,\n queueElement.payload.email,\n );\n },\n onStateChange: ({ from, to }) => {\n this.logger.for('onStateChange').debug('Queue state changed | from: %s | to: %s', from, to);\n },\n });\n\n this.logger.for(this.constructor.name).info('Internal queue executor initialized');\n }\n\n setProcessor(processor: (email: string) => Promise<IMailProcessorResult>): void {\n this.processor = processor;\n this.logger.for(this.setProcessor.name).info('Processor registered');\n }\n\n async enqueueVerificationEmail(\n email: string,\n options?: IMailQueueOptions,\n ): Promise<IMailQueueResult> {\n if (!this.processor) {\n throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });\n }\n\n const jobId = `job_${++this.jobIdCounter}_${Date.now()}`;\n const job: IQueueJobPayload = {\n id: jobId,\n email,\n options,\n attempts: 0,\n scheduledAt: Date.now() + (options?.delay ?? 0),\n };\n\n this.logger\n .for(this.enqueueVerificationEmail.name)\n .info('Queuing email | jobId: %s | email: %s', jobId, email);\n\n if (options?.delay && options.delay > 0) {\n const timeout = setTimeout(() => {\n this.queue.enqueue(job).catch((error) => {\n this.logger\n .for(this.enqueueVerificationEmail.name)\n .error('Failed to enqueue delayed job | jobId: %s | error: %s', jobId, error);\n });\n this.delayedJobs.delete(jobId);\n }, options.delay);\n\n this.delayedJobs.set(jobId, timeout);\n\n this.logger\n .for(this.enqueueVerificationEmail.name)\n .info('Job scheduled with delay | jobId: %s | delay: %dms', jobId, options.delay);\n } else {\n await this.queue.enqueue(job);\n }\n\n return {\n jobId,\n queued: true,\n message: 'Email queued successfully (internal queue)',\n };\n }\n\n /** Releases every pending delayed/backoff timer - a live `setTimeout` holds the event loop open past the executor. */\n async close(): Promise<void> {\n const pendingCount = this.delayedJobs.size;\n\n const delayedJobsValues = this.delayedJobs.values();\n\n for (const timeout of delayedJobsValues) {\n clearTimeout(timeout);\n }\n\n this.delayedJobs.clear();\n\n this.logger.for(this.close.name).info('Executor closed | Cleared timers: %d', pendingCount);\n }\n\n private async processJob(job: IQueueJobPayload): Promise<void> {\n if (!this.processor) {\n this.logger.for(this.processJob.name).error('Processor not set | jobId: %s', job.id);\n\n return;\n }\n\n const maxAttempts = job.options?.attempts ?? 3;\n\n this.logger\n .for(this.processJob.name)\n .info(\n 'Processing job | jobId: %s | email: %s | attempt: %d/%d',\n job.id,\n job.email,\n job.attempts + 1,\n maxAttempts,\n );\n\n try {\n const result = await this.processor(job.email);\n\n // A processor reports SMTP rejection by RETURNING `{ success: false }`; watching only for throws completes the job and drops the mail.\n if (result?.success === false) {\n throw getError({\n messageCode: MailErrorCodes.SEND_FAILED,\n message: `[processJob] Processor reported failure | jobId: ${job.id} | reason: ${result.message}`,\n });\n }\n\n this.logger.for(this.processJob.name).info('Job completed successfully | jobId: %s', job.id);\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : error;\n job.attempts++;\n\n if (job.attempts < maxAttempts) {\n const backoffDelay = this.calculateBackoff(job);\n\n this.logger\n .for(this.processJob.name)\n .warn(\n 'Job failed, retrying | jobId: %s | attempt: %d/%d | retryIn: %dms | error: %s',\n job.id,\n job.attempts,\n maxAttempts,\n backoffDelay,\n errorMsg,\n );\n\n const timeout = setTimeout(() => {\n this.queue.enqueue(job).catch((reenqueueError) => {\n this.logger\n .for(this.processJob.name)\n .error('Failed to re-enqueue job | jobId: %s | error: %s', job.id, reenqueueError);\n });\n this.delayedJobs.delete(job.id);\n }, backoffDelay);\n\n this.delayedJobs.set(job.id, timeout);\n } else {\n this.logger\n .for(this.processJob.name)\n .error(\n 'Job failed permanently after %d attempts | jobId: %s | error: %s',\n maxAttempts,\n job.id,\n errorMsg,\n );\n }\n }\n }\n\n private calculateBackoff(job: IQueueJobPayload): number {\n const backoff = job.options?.backoff;\n\n if (!backoff) {\n return 1000;\n }\n\n if (backoff.type === MailBackoffTypes.EXPONENTIAL) {\n return backoff.delay * Math.pow(2, job.attempts - 1);\n }\n\n return backoff.delay;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"internal-queue-executor.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/executors/internal-queue-executor.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAS/D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElG,kJAAkJ;AAClJ,MAAM,OAAO,+BAAgC,SAAQ,UAAU;IAS7D,YAAY,IAAoC;QAC9C,KAAK,CAAC,EAAE,KAAK,EAAE,+BAA+B,CAAC,IAAI,EAAE,CAAC,CAAC;QARjD,iBAAY,GAAG,CAAC,CAAC;QACjB,gBAAW,GAAgC,IAAI,GAAG,EAAE,CAAC;QAC7D,gGAAgG;QACxF,aAAQ,GAAG,KAAK,CAAC;QAOvB,IAAI,CAAC,KAAK,GAAG,IAAI,qBAAqB,CAAmB;YACvD,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,YAAY,EAAE,IAAI;YAClB,SAAS,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE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C,MAAM;6BACR,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;6BACzB,KAAK,CAAC,kDAAkD,EAAE,GAAG,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;oBACvF,CAAC,CAAC,CAAC;oBACH,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAClC,CAAC,EAAE,YAAY,CAAC,CAAC;gBAEjB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;YACxC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,MAAM;qBACR,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;qBACzB,KAAK,CACJ,kEAAkE,EAClE,WAAW,EACX,GAAG,CAAC,EAAE,EACN,QAAQ,CACT,CAAC;YACN,CAAC;QACH,CAAC;IACH,CAAC;IAEO,gBAAgB,CAAC,GAAqB;QAC5C,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC;QAErC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,YAAY,CAAC,gBAAgB,CAAC;QACvC,CAAC;QAED,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,CAAC,WAAW,EAAE,CAAC;YAClD,OAAO,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,OAAO,CAAC,KAAK,CAAC;IACvB,CAAC;CACF","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { SequentialQueueHelper } from '@venizia/ignis-helpers';\nimport type {\n IMailQueueOptions,\n IMailQueueExecutor,\n IMailProcessorResult,\n IInternalQueueMailExecutorOpts,\n IMailQueueResult,\n IQueueJobPayload,\n} from '../../common';\nimport { MailBackoffTypes, MailDefaults, MailErrorCodes, MailExecutorErrors } from '../../common';\n\n/** In-process mail queue executor: jobs are lost on restart. Supports `delay`, `attempts` and `backoff`; call `close` to clear pending timers. */\nexport class InternalQueueMailExecutorHelper extends BaseHelper implements IMailQueueExecutor {\n private queue: SequentialQueueHelper<IQueueJobPayload>;\n private jobIdCounter = 0;\n private delayedJobs: Map<string, NodeJS.Timeout> = new Map();\n /** Set by `close`: a job that fails afterwards must not arm a retry timer nobody will clear. */\n private isClosed = false;\n\n private processor?: (email: string) => Promise<IMailProcessorResult>;\n\n constructor(opts: IInternalQueueMailExecutorOpts) {\n super({ scope: InternalQueueMailExecutorHelper.name });\n\n this.queue = new SequentialQueueHelper<IQueueJobPayload>({\n identifier: opts.identifier,\n autoDispatch: true,\n onMessage: async ({ queueElement }) => {\n await this.processJob(queueElement.payload);\n },\n onDataEnqueue: ({ queueElement }) => {\n this.logger.for('onDataEnqueue').debug('Job enqueued | jobId: %s', queueElement.payload.id);\n },\n onStateChange: ({ from, to }) => {\n this.logger.for('onStateChange').debug('Queue state changed | from: %s | to: %s', from, to);\n },\n });\n\n this.logger.for(this.constructor.name).info('Internal queue executor initialized');\n }\n\n setProcessor(processor: (email: string) => Promise<IMailProcessorResult>): void {\n this.processor = processor;\n this.logger.for(this.setProcessor.name).info('Processor registered');\n }\n\n async enqueueVerificationEmail(\n email: string,\n options?: IMailQueueOptions,\n ): Promise<IMailQueueResult> {\n if (!this.processor) {\n throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });\n }\n\n if (this.isClosed) {\n throw getError({ message: MailExecutorErrors.CLOSED });\n }\n\n const jobId = `job_${++this.jobIdCounter}_${Date.now()}`;\n const job: IQueueJobPayload = {\n id: jobId,\n email,\n options,\n attempts: 0,\n scheduledAt: Date.now() + (options?.delay ?? 0),\n };\n\n this.logger.for(this.enqueueVerificationEmail.name).debug('Queuing email | jobId: %s', jobId);\n\n if (options?.delay && options.delay > 0) {\n const timeout = setTimeout(() => {\n this.queue.enqueue(job).catch((error) => {\n this.logger\n .for(this.enqueueVerificationEmail.name)\n .error('Failed to enqueue delayed job | jobId: %s | error: %s', jobId, error);\n });\n this.delayedJobs.delete(jobId);\n }, options.delay);\n\n this.delayedJobs.set(jobId, timeout);\n\n this.logger\n .for(this.enqueueVerificationEmail.name)\n .info('Job scheduled with delay | jobId: %s | delay: %dms', jobId, options.delay);\n } else {\n await this.queue.enqueue(job);\n }\n\n return {\n jobId,\n queued: true,\n message: 'Email queued successfully (internal queue)',\n };\n }\n\n /** Releases every pending delayed/backoff timer - a live `setTimeout` holds the event loop open past the executor. */\n async close(): Promise<void> {\n this.isClosed = true;\n\n const pendingCount = this.delayedJobs.size;\n\n const delayedJobsValues = this.delayedJobs.values();\n\n for (const timeout of delayedJobsValues) {\n clearTimeout(timeout);\n }\n\n this.delayedJobs.clear();\n\n this.logger.for(this.close.name).info('Executor closed | Cleared timers: %d', pendingCount);\n }\n\n private async processJob(job: IQueueJobPayload): Promise<void> {\n if (!this.processor) {\n this.logger.for(this.processJob.name).error('Processor not set | jobId: %s', job.id);\n\n return;\n }\n\n const maxAttempts = job.options?.attempts ?? MailDefaults.ATTEMPTS;\n\n this.logger\n .for(this.processJob.name)\n .info(\n 'Processing job | jobId: %s | email: %s | attempt: %d/%d',\n job.id,\n job.email,\n job.attempts + 1,\n maxAttempts,\n );\n\n try {\n const result = await this.processor(job.email);\n\n // A processor reports SMTP rejection by RETURNING `{ success: false }`; watching only for throws completes the job and drops the mail.\n if (result?.success === false) {\n throw getError({\n messageCode: MailErrorCodes.SEND_FAILED,\n message: `[processJob] Processor reported failure | jobId: ${job.id} | reason: ${result.message}`,\n });\n }\n\n this.logger.for(this.processJob.name).info('Job completed successfully | jobId: %s', job.id);\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : error;\n job.attempts++;\n\n if (this.isClosed) {\n this.logger\n .for(this.processJob.name)\n .warn('Job failed after close, not retried | jobId: %s | error: %s', job.id, errorMsg);\n } else if (job.attempts < maxAttempts) {\n const backoffDelay = this.calculateBackoff(job);\n\n this.logger\n .for(this.processJob.name)\n .warn(\n 'Job failed, retrying | jobId: %s | attempt: %d/%d | retryIn: %dms | error: %s',\n job.id,\n job.attempts,\n maxAttempts,\n backoffDelay,\n errorMsg,\n );\n\n const timeout = setTimeout(() => {\n this.queue.enqueue(job).catch((reenqueueError) => {\n this.logger\n .for(this.processJob.name)\n .error('Failed to re-enqueue job | jobId: %s | error: %s', job.id, reenqueueError);\n });\n this.delayedJobs.delete(job.id);\n }, backoffDelay);\n\n this.delayedJobs.set(job.id, timeout);\n } else {\n this.logger\n .for(this.processJob.name)\n .error(\n 'Job failed permanently after %d attempts | jobId: %s | error: %s',\n maxAttempts,\n job.id,\n errorMsg,\n );\n }\n }\n }\n\n private calculateBackoff(job: IQueueJobPayload): number {\n const backoff = job.options?.backoff;\n\n if (!backoff) {\n return MailDefaults.BACKOFF_DELAY_MS;\n }\n\n if (backoff.type === MailBackoffTypes.EXPONENTIAL) {\n return backoff.delay * Math.pow(2, job.attempts - 1);\n }\n\n return backoff.delay;\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
2
|
-
import { ModuleUtility } from '@venizia/ignis-helpers';
|
|
2
|
+
import { ErrorUtility, ModuleUtility } from '@venizia/ignis-helpers';
|
|
3
3
|
import { BaseHelper, getError } from '@venizia/ignis-helpers/core';
|
|
4
|
-
import {
|
|
4
|
+
import { MailErrors, } from '../../common/index.js';
|
|
5
5
|
import { MailAddressUtility, MailMimeUtility } from '../../utilities/index.js';
|
|
6
6
|
import { MailAttachmentUtility } from '../../utilities/attachment.utility.js';
|
|
7
7
|
/** Amazon SES transport over the HTTPS API (`@aws-sdk/client-sesv2`), sending each message as a raw MIME body. */
|
|
@@ -53,7 +53,7 @@ export class AmazonSesTransportHelper extends BaseHelper {
|
|
|
53
53
|
MailAttachmentUtility.release({ attachments: message.attachments });
|
|
54
54
|
return {
|
|
55
55
|
success: false,
|
|
56
|
-
error: error
|
|
56
|
+
error: ErrorUtility.toError({ error }).message,
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -107,7 +107,7 @@ export class AmazonSesTransportHelper extends BaseHelper {
|
|
|
107
107
|
}
|
|
108
108
|
throw getError({
|
|
109
109
|
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
110
|
-
|
|
110
|
+
error: MailErrors.INVALID_CONFIGURATION,
|
|
111
111
|
message: 'Invalid Amazon SES Configuration | Missing region',
|
|
112
112
|
});
|
|
113
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amazon-ses-transporter.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/transporters/amazon-ses-transporter.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAgB,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACL,cAAc,GAOf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E,kHAAkH;AAClH,MAAM,OAAO,wBAAyB,SAAQ,UAAU;IAMtD,YAAY,IAA6D;QACvE,KAAK,CAAC,EAAE,KAAK,EAAE,wBAAwB,CAAC,IAAI,EAAE,CAAC,CAAC;QAEhD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAED,uFAAuF;IACvF,KAAK,CAAC,IAAI,CAAC,OAAqB;QAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CA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AAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;YACrD,WAAW,EAAE,cAAc,CAAC,qBAAqB;YACjD,OAAO,EAAE,mDAAmD;SAC7D,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { ModuleUtility, type AnyType } from '@venizia/ignis-helpers';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport {\n MailErrorCodes,\n type IMailMessage,\n type IMailSendResult,\n type IMailTransport,\n type TAmazonSesClient,\n type TAmazonSesConfig,\n type TAmazonSesModule,\n} from '../../common';\nimport { MailAddressUtility, MailMimeUtility } from '../../utilities';\nimport { MailAttachmentUtility } from '../../utilities/attachment.utility';\n\n/** Amazon SES transport over the HTTPS API (`@aws-sdk/client-sesv2`), sending each message as a raw MIME body. */\nexport class AmazonSesTransportHelper extends BaseHelper implements IMailTransport {\n private client: AnyType;\n private sendEmailCommandConstructor: AnyType;\n private getAccountCommandConstructor: AnyType;\n private module?: TAmazonSesModule<TAmazonSesConfig>;\n\n constructor(opts: { config: TAmazonSesConfig; module?: TAmazonSesModule }) {\n super({ scope: AmazonSesTransportHelper.name });\n\n this.module = opts.module;\n this.configure(opts.config);\n }\n\n // ------------------------------------------------------------------------------------\n async send(message: IMailMessage): Promise<IMailSendResult> {\n const logger = this.logger.for(this.send.name);\n\n try {\n logger.debug('Sending email with Amazon SES to: %s', message.to);\n\n const rawMessage = await MailMimeUtility.buildRawMessage({ message });\n const command = new this.sendEmailCommandConstructor({\n // `FromEmailAddress` carries the same RFC 5321/5322 mailbox syntax as the raw `From:`\n // header and is subject to the same 7-bit-ASCII requirement - encoding it separately\n // here (instead of passing `message.from` through untouched) is what keeps a non-ASCII\n // display name from reaching the SES API as raw UTF-8 bytes.\n FromEmailAddress: message.from\n ? MailMimeUtility.formatAddressHeader({ value: message.from })\n : message.from,\n Destination: {\n ToAddresses: MailAddressUtility.splitList({ value: message.to }),\n CcAddresses: message.cc ? MailAddressUtility.splitList({ value: message.cc }) : undefined,\n BccAddresses: message.bcc\n ? MailAddressUtility.splitList({ value: message.bcc })\n : undefined,\n },\n // No `ReplyToAddresses` here: `MailMimeUtility.buildRawMessage` already writes a single, RFC\n // 2047-encoded `Reply-To` header into the raw content. Setting both sends the same\n // address through two channels SES treats independently - a client can end up showing a\n // reply-to derived from whichever one SES prioritizes, and the other becomes a silent,\n // unencoded duplicate that skipped the address encoding path entirely.\n Content: {\n Raw: { Data: rawMessage },\n },\n });\n\n const result = await this.client.send(command);\n\n return {\n success: true,\n messageId: result.MessageId,\n response: result,\n };\n } catch (error) {\n logger.error(\n 'Amazon SES send failed | error: %s',\n error instanceof Error ? error.message : error,\n );\n MailAttachmentUtility.release({ attachments: message.attachments });\n\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n }\n\n // ------------------------------------------------------------------------------------\n async verify(): Promise<boolean> {\n const logger = this.logger.for(this.verify.name);\n\n try {\n logger.info('Verifying Amazon SES account status');\n\n const command = new this.getAccountCommandConstructor({});\n const result = await this.client.send(command);\n const enabled = result.SendingEnabled === true;\n\n logger.info('Amazon SES account status: %s', enabled ? 'enabled' : 'disabled');\n\n return enabled;\n } catch (error) {\n logger.error(\n 'Amazon SES verification failed | error: %s',\n error instanceof Error ? error.message : error,\n );\n\n return false;\n }\n }\n\n // ------------------------------------------------------------------------------------\n async close(): Promise<void> {\n this.logger.for(this.close.name).info('Closing Amazon SES client');\n this.client.destroy?.();\n }\n\n // ------------------------------------------------------------------------------------\n configure(config: TAmazonSesConfig): void {\n this.validateConfig(config);\n\n const { client, SendEmailCommand, GetAccountCommand } = this.buildClient(config);\n\n this.client = client;\n this.sendEmailCommandConstructor = SendEmailCommand;\n this.getAccountCommandConstructor = GetAccountCommand;\n }\n\n // ------------------------------------------------------------------------------------\n protected buildClient(config: TAmazonSesConfig): TAmazonSesClient {\n const sesModule =\n this.module ?? ModuleUtility.loadSync<TAmazonSesModule>({ module: '@aws-sdk/client-sesv2' });\n\n const client = new sesModule.SESv2Client({\n region: config.region,\n credentials: config.credentials,\n endpoint: config.endpoint,\n });\n\n return {\n client,\n SendEmailCommand: sesModule.SendEmailCommand,\n GetAccountCommand: sesModule.GetAccountCommand,\n };\n }\n\n // ------------------------------------------------------------------------------------\n private validateConfig(config: TAmazonSesConfig): void {\n if (config.region) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.INVALID_CONFIGURATION,\n message: 'Invalid Amazon SES Configuration | Missing region',\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"amazon-ses-transporter.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/transporters/amazon-ses-transporter.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAgB,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACL,UAAU,GAOX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E,kHAAkH;AAClH,MAAM,OAAO,wBAAyB,SAAQ,UAAU;IAMtD,YAAY,IAA6D;QACvE,KAAK,CAAC,EAAE,KAAK,EAAE,wBAAwB,CAAC,IAAI,EAAE,CAAC,CAAC;QAEhD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAED,uFAAuF;IACvF,KAAK,CAAC,IAAI,CAAC,OAAqB;QAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,C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,CAAC,IAAI,CAAC,mBAAmB;YACrD,KAAK,EAAE,UAAU,CAAC,qBAAqB;YACvC,OAAO,EAAE,mDAAmD;SAC7D,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { ErrorUtility, ModuleUtility, type AnyType } from '@venizia/ignis-helpers';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport {\n MailErrors,\n type IMailMessage,\n type IMailSendResult,\n type IMailTransport,\n type TAmazonSesClient,\n type TAmazonSesConfig,\n type TAmazonSesModule,\n} from '../../common';\nimport { MailAddressUtility, MailMimeUtility } from '../../utilities';\nimport { MailAttachmentUtility } from '../../utilities/attachment.utility';\n\n/** Amazon SES transport over the HTTPS API (`@aws-sdk/client-sesv2`), sending each message as a raw MIME body. */\nexport class AmazonSesTransportHelper extends BaseHelper implements IMailTransport {\n private client: AnyType;\n private sendEmailCommandConstructor: AnyType;\n private getAccountCommandConstructor: AnyType;\n private module?: TAmazonSesModule<TAmazonSesConfig>;\n\n constructor(opts: { config: TAmazonSesConfig; module?: TAmazonSesModule }) {\n super({ scope: AmazonSesTransportHelper.name });\n\n this.module = opts.module;\n this.configure(opts.config);\n }\n\n // ------------------------------------------------------------------------------------\n async send(message: IMailMessage): Promise<IMailSendResult> {\n const logger = this.logger.for(this.send.name);\n\n try {\n logger.debug('Sending email with Amazon SES to: %s', message.to);\n\n const rawMessage = await MailMimeUtility.buildRawMessage({ message });\n const command = new this.sendEmailCommandConstructor({\n // `FromEmailAddress` carries the same RFC 5321/5322 mailbox syntax as the raw `From:`\n // header and is subject to the same 7-bit-ASCII requirement - encoding it separately\n // here (instead of passing `message.from` through untouched) is what keeps a non-ASCII\n // display name from reaching the SES API as raw UTF-8 bytes.\n FromEmailAddress: message.from\n ? MailMimeUtility.formatAddressHeader({ value: message.from })\n : message.from,\n Destination: {\n ToAddresses: MailAddressUtility.splitList({ value: message.to }),\n CcAddresses: message.cc ? MailAddressUtility.splitList({ value: message.cc }) : undefined,\n BccAddresses: message.bcc\n ? MailAddressUtility.splitList({ value: message.bcc })\n : undefined,\n },\n // No `ReplyToAddresses` here: `MailMimeUtility.buildRawMessage` already writes a single, RFC\n // 2047-encoded `Reply-To` header into the raw content. Setting both sends the same\n // address through two channels SES treats independently - a client can end up showing a\n // reply-to derived from whichever one SES prioritizes, and the other becomes a silent,\n // unencoded duplicate that skipped the address encoding path entirely.\n Content: {\n Raw: { Data: rawMessage },\n },\n });\n\n const result = await this.client.send(command);\n\n return {\n success: true,\n messageId: result.MessageId,\n response: result,\n };\n } catch (error) {\n logger.error(\n 'Amazon SES send failed | error: %s',\n error instanceof Error ? error.message : error,\n );\n MailAttachmentUtility.release({ attachments: message.attachments });\n\n return {\n success: false,\n error: ErrorUtility.toError({ error }).message,\n };\n }\n }\n\n // ------------------------------------------------------------------------------------\n async verify(): Promise<boolean> {\n const logger = this.logger.for(this.verify.name);\n\n try {\n logger.info('Verifying Amazon SES account status');\n\n const command = new this.getAccountCommandConstructor({});\n const result = await this.client.send(command);\n const enabled = result.SendingEnabled === true;\n\n logger.info('Amazon SES account status: %s', enabled ? 'enabled' : 'disabled');\n\n return enabled;\n } catch (error) {\n logger.error(\n 'Amazon SES verification failed | error: %s',\n error instanceof Error ? error.message : error,\n );\n\n return false;\n }\n }\n\n // ------------------------------------------------------------------------------------\n async close(): Promise<void> {\n this.logger.for(this.close.name).info('Closing Amazon SES client');\n this.client.destroy?.();\n }\n\n // ------------------------------------------------------------------------------------\n configure(config: TAmazonSesConfig): void {\n this.validateConfig(config);\n\n const { client, SendEmailCommand, GetAccountCommand } = this.buildClient(config);\n\n this.client = client;\n this.sendEmailCommandConstructor = SendEmailCommand;\n this.getAccountCommandConstructor = GetAccountCommand;\n }\n\n // ------------------------------------------------------------------------------------\n protected buildClient(config: TAmazonSesConfig): TAmazonSesClient {\n const sesModule =\n this.module ?? ModuleUtility.loadSync<TAmazonSesModule>({ module: '@aws-sdk/client-sesv2' });\n\n const client = new sesModule.SESv2Client({\n region: config.region,\n credentials: config.credentials,\n endpoint: config.endpoint,\n });\n\n return {\n client,\n SendEmailCommand: sesModule.SendEmailCommand,\n GetAccountCommand: sesModule.GetAccountCommand,\n };\n }\n\n // ------------------------------------------------------------------------------------\n private validateConfig(config: TAmazonSesConfig): void {\n if (config.region) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n error: MailErrors.INVALID_CONFIGURATION,\n message: 'Invalid Amazon SES Configuration | Missing region',\n });\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
2
2
|
import { BaseHelper, getError } from '@venizia/ignis-helpers/core';
|
|
3
|
-
import { ModuleUtility } from '@venizia/ignis-helpers';
|
|
4
|
-
import {
|
|
3
|
+
import { ErrorUtility, ModuleUtility } from '@venizia/ignis-helpers';
|
|
4
|
+
import { MailErrors } from '../../common/index.js';
|
|
5
5
|
import { MailAttachmentUtility } from '../../utilities/attachment.utility.js';
|
|
6
6
|
/** Mailgun transport (`mailgun.js`). The constructor throws when `username`, `key` or `domain` is missing. */
|
|
7
7
|
export class MailgunTransportHelper extends BaseHelper {
|
|
@@ -28,7 +28,7 @@ export class MailgunTransportHelper extends BaseHelper {
|
|
|
28
28
|
.error('Invalid Mailgun configuration | Missing keys: %s', missingKeys.join(', '));
|
|
29
29
|
throw getError({
|
|
30
30
|
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
31
|
-
|
|
31
|
+
error: MailErrors.INVALID_CONFIGURATION,
|
|
32
32
|
message: `Invalid Mailgun configuration | Missing required keys: ${missingKeys.join(', ')}`,
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -63,9 +63,18 @@ export class MailgunTransportHelper extends BaseHelper {
|
|
|
63
63
|
const attachments = await MailAttachmentUtility.resolve({
|
|
64
64
|
attachments: message.attachments,
|
|
65
65
|
});
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
// Mailgun reads `inline` parts by file name: `cid:<name>` in the HTML, so the cid is the name.
|
|
67
|
+
const toPart = (attachment, filename) => ({
|
|
68
|
+
filename: filename ?? attachment.filename,
|
|
69
|
+
data: attachment.content,
|
|
70
|
+
contentType: attachment.contentType,
|
|
68
71
|
});
|
|
72
|
+
mailgunMessage.attachment = attachments
|
|
73
|
+
.filter((attachment) => !attachment.cid)
|
|
74
|
+
.map((attachment) => toPart(attachment));
|
|
75
|
+
mailgunMessage.inline = attachments
|
|
76
|
+
.filter((attachment) => attachment.cid)
|
|
77
|
+
.map((attachment) => toPart(attachment, attachment.cid));
|
|
69
78
|
}
|
|
70
79
|
this.logger.for(this.send.name).debug('Sending email with Mailgun to: %s', mailgunMessage.to);
|
|
71
80
|
const result = await this.client.create(this.domain, mailgunMessage);
|
|
@@ -80,7 +89,7 @@ export class MailgunTransportHelper extends BaseHelper {
|
|
|
80
89
|
MailAttachmentUtility.release({ attachments: message.attachments });
|
|
81
90
|
return {
|
|
82
91
|
success: false,
|
|
83
|
-
error: error
|
|
92
|
+
error: ErrorUtility.toError({ error }).message,
|
|
84
93
|
};
|
|
85
94
|
}
|
|
86
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mailgun-transporter.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/transporters/mailgun-transporter.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"mailgun-transporter.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/transporters/mailgun-transporter.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,QAAQ,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CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;YAEtF,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { ErrorUtility, ModuleUtility } from '@venizia/ignis-helpers';\nimport type {\n IMailAttachment,\n IMailMessage,\n IMailSendResult,\n IMailTransport,\n TMailgunConfig,\n TMailgunModule,\n} from '../../common';\nimport { MailErrors } from '../../common';\nimport { MailAttachmentUtility } from '../../utilities/attachment.utility';\n\n/** Mailgun transport (`mailgun.js`). The constructor throws when `username`, `key` or `domain` is missing. */\nexport class MailgunTransportHelper extends BaseHelper implements IMailTransport {\n private client: AnyType; // IMessagesClient from mailgun.js\n private domain: string;\n private module?: TMailgunModule;\n\n constructor(opts: { config: TMailgunConfig; module?: TMailgunModule }) {\n super({ scope: MailgunTransportHelper.name });\n\n this.module = opts.module;\n this.configure(opts.config);\n }\n\n configure(config: TMailgunConfig) {\n this.validateConfig(config);\n\n this.domain = config.domain;\n this.client = this.buildClient(config);\n }\n\n /** Credentials and domain are checked here, not on the first send; the error never echoes a credential value back. */\n private validateConfig(config: TMailgunConfig): void {\n const missingKeys = (['username', 'key', 'domain'] as const).filter((key) => {\n return !config?.[key];\n });\n\n if (missingKeys.length === 0) {\n return;\n }\n\n this.logger\n .for(this.configure.name)\n .error('Invalid Mailgun configuration | Missing keys: %s', missingKeys.join(', '));\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n error: MailErrors.INVALID_CONFIGURATION,\n message: `Invalid Mailgun configuration | Missing required keys: ${missingKeys.join(', ')}`,\n });\n }\n\n /** Client factory seam - overridden in tests to run the helper without the mailgun.js peer. */\n protected buildClient(config: TMailgunConfig): AnyType {\n const Mailgun = this.module ?? ModuleUtility.loadSync<AnyType>({ module: 'mailgun.js' });\n const mailgun = new Mailgun(FormData);\n const client = mailgun.client(config);\n\n return client.messages;\n }\n\n async send(message: IMailMessage): Promise<IMailSendResult> {\n try {\n const mailgunMessage: AnyType = {\n from: message.from,\n to: Array.isArray(message.to) ? message.to : [message.to],\n subject: message.subject,\n text: message.text,\n html: message.html,\n cc: message.cc,\n bcc: message.bcc,\n };\n\n if (message.replyTo) {\n mailgunMessage['h:Reply-To'] = message.replyTo;\n }\n\n if (message.headers) {\n Object.entries(message.headers).forEach(([key, value]) => {\n mailgunMessage[`h:${key}`] = value;\n });\n }\n\n if (message.attachments && message.attachments.length > 0) {\n // No root: MailService resolved paths already; one that reaches here is refused, not read.\n const attachments = await MailAttachmentUtility.resolve({\n attachments: message.attachments,\n });\n\n // Mailgun reads `inline` parts by file name: `cid:<name>` in the HTML, so the cid is the name.\n const toPart = (attachment: IMailAttachment, filename?: string) => ({\n filename: filename ?? attachment.filename,\n data: attachment.content,\n contentType: attachment.contentType,\n });\n\n mailgunMessage.attachment = attachments\n .filter((attachment) => !attachment.cid)\n .map((attachment) => toPart(attachment));\n mailgunMessage.inline = attachments\n .filter((attachment) => attachment.cid)\n .map((attachment) => toPart(attachment, attachment.cid));\n }\n\n this.logger.for(this.send.name).debug('Sending email with Mailgun to: %s', mailgunMessage.to);\n const result: AnyType = await this.client.create(this.domain, mailgunMessage);\n\n return {\n success: true,\n messageId: result.id,\n response: result,\n };\n } catch (error) {\n this.logger.for(this.send.name).error('Mailgun send failed: %s', error);\n MailAttachmentUtility.release({ attachments: message.attachments });\n\n return {\n success: false,\n error: ErrorUtility.toError({ error }).message,\n };\n }\n }\n\n async verify(): Promise<boolean> {\n try {\n this.logger.for(this.verify.name).info('Verifying Mailgun API connection');\n // Mailgun has no verify endpoint - a test-mode send is the lightweight credential check.\n await this.client.create(this.domain, {\n from: 'verify@' + this.domain,\n to: ['verify@' + this.domain],\n subject: 'Verification Test',\n text: 'This is a verification test',\n 'o:testmode': 'yes', // Use test mode to avoid actually sending\n });\n\n this.logger.for(this.verify.name).info('Mailgun API connection verified successfully');\n\n return true;\n } catch (error) {\n this.logger.for(this.verify.name).error('Mailgun API verification failed: %s', error);\n\n return false;\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
|
-
import { ModuleUtility } from '@venizia/ignis-helpers';
|
|
2
|
+
import { ErrorUtility, ModuleUtility } from '@venizia/ignis-helpers';
|
|
3
3
|
import { MailAttachmentUtility } from '../../utilities/attachment.utility.js';
|
|
4
4
|
import { MailBodyUtility } from '../../utilities/body.utility.js';
|
|
5
5
|
/** SMTP transport on `nodemailer`, with its file and URL access switched off. */
|
|
@@ -54,7 +54,7 @@ export class NodemailerTransportHelper extends BaseHelper {
|
|
|
54
54
|
MailAttachmentUtility.release({ attachments: message.attachments });
|
|
55
55
|
return {
|
|
56
56
|
success: false,
|
|
57
|
-
error: error
|
|
57
|
+
error: ErrorUtility.toError({ error }).message,
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodemail-transporter.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/transporters/nodemail-transporter.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"nodemail-transporter.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/transporters/nodemail-transporter.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAQrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CA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A2B,CAAC,CAAC;YACpE,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;YAEhF,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;YAE/E,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QACtE,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import type { AnyType } from '@venizia/ignis-helpers/common';\nimport { BaseHelper } from '@venizia/ignis-helpers/core';\nimport { ErrorUtility, ModuleUtility } from '@venizia/ignis-helpers';\nimport type {\n IMailMessage,\n IMailSendResult,\n IMailTransport,\n TNodemailerConfig,\n TNodemailerModule,\n} from '../../common';\nimport { MailAttachmentUtility } from '../../utilities/attachment.utility';\nimport { MailBodyUtility } from '../../utilities/body.utility';\n\n/** SMTP transport on `nodemailer`, with its file and URL access switched off. */\nexport class NodemailerTransportHelper extends BaseHelper implements IMailTransport {\n private transporter: AnyType;\n private module?: TNodemailerModule;\n\n constructor(opts: { config: TNodemailerConfig; module?: TNodemailerModule }) {\n super({ scope: NodemailerTransportHelper.name });\n\n this.module = opts.module;\n this.configure(opts.config);\n }\n\n configure(config: TNodemailerConfig) {\n this.transporter = this.buildTransporter(config);\n }\n\n /** Client factory seam - overridden in tests to run the helper without a real SMTP client. */\n protected buildTransporter(config: TNodemailerConfig): AnyType {\n const nodemailer = this.module ?? ModuleUtility.loadSync<AnyType>({ module: 'nodemailer' });\n\n return nodemailer.createTransport(config);\n }\n\n async send(message: IMailMessage): Promise<IMailSendResult> {\n try {\n MailBodyUtility.assertIsText({ message });\n\n // No root: MailService resolved paths already; one that reaches here is refused, not read.\n let attachments: Awaited<ReturnType<typeof MailAttachmentUtility.resolve>> | undefined;\n\n if (message.attachments) {\n const resolved = await MailAttachmentUtility.resolve({ attachments: message.attachments });\n attachments = resolved;\n }\n\n const mailOptions = {\n from: message.from,\n to: Array.isArray(message.to) ? message.to.join(', ') : message.to,\n cc: message.cc,\n bcc: message.bcc,\n replyTo: message.replyTo,\n subject: message.subject,\n text: message.text,\n html: message.html,\n attachments,\n headers: message.headers,\n // Nodemailer's own switches: no field it is handed can make it open a file or fetch a URL.\n disableFileAccess: true,\n disableUrlAccess: true,\n };\n\n this.logger.for(this.send.name).debug('Sending email with nodemailer to: %s', mailOptions.to);\n const info = await this.transporter.sendMail(mailOptions);\n\n return {\n success: true,\n messageId: info.messageId,\n response: info.response,\n };\n } catch (error) {\n this.logger.for(this.send.name).error('Nodemailer send failed: %s', error);\n MailAttachmentUtility.release({ attachments: message.attachments });\n\n return {\n success: false,\n error: ErrorUtility.toError({ error }).message,\n };\n }\n }\n\n async verify(): Promise<boolean> {\n try {\n this.logger.for(this.verify.name).info('Verifying SMTP connection');\n await this.transporter.verify();\n this.logger.for(this.verify.name).info('SMTP connection verified successfully');\n\n return true;\n } catch (error) {\n this.logger.for(this.verify.name).error('SMTP verification failed: %s', error);\n\n return false;\n }\n }\n\n async close(): Promise<void> {\n this.logger.for(this.close.name).info('Closing nodemailer transport');\n this.transporter.close();\n }\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseProvider } from '@venizia/ignis-kernel';
|
|
2
2
|
import type { Container } from '../../../helpers/index.js';
|
|
3
|
-
import type { IMailQueueExecutor,
|
|
3
|
+
import type { IMailQueueExecutor, TMailQueueExecutorConfig } from '../common/index.js';
|
|
4
4
|
/** Builds the queue executor for a config; throws when the config for its `type` is missing or the type is unknown. */
|
|
5
|
-
export type TGetMailQueueExecutorFn = (config:
|
|
5
|
+
export type TGetMailQueueExecutorFn = (config: TMailQueueExecutorConfig) => IMailQueueExecutor;
|
|
6
6
|
/** Provides the `TGetMailQueueExecutorFn` factory bound at `MailKeys.MAIL_QUEUE_EXECUTOR_PROVIDER`. */
|
|
7
7
|
export declare class MailQueueExecutorProvider extends BaseProvider<TGetMailQueueExecutorFn> {
|
|
8
8
|
constructor();
|
|
@@ -17,21 +17,19 @@ export class MailQueueExecutorProvider extends BaseProvider {
|
|
|
17
17
|
return new DirectMailExecutorHelper();
|
|
18
18
|
}
|
|
19
19
|
case MailQueueExecutorTypes.INTERNAL_QUEUE: {
|
|
20
|
-
if (!config.internalQueue) {
|
|
21
|
-
throw getError({ message: 'Internal queue configuration is missing' });
|
|
22
|
-
}
|
|
23
20
|
return new InternalQueueMailExecutorHelper({
|
|
24
|
-
identifier: config.
|
|
21
|
+
identifier: config.options.identifier,
|
|
25
22
|
});
|
|
26
23
|
}
|
|
27
24
|
case MailQueueExecutorTypes.BULLMQ: {
|
|
28
|
-
|
|
29
|
-
throw getError({ message: 'BullMQ configuration is missing' });
|
|
30
|
-
}
|
|
31
|
-
return new BullMQMailExecutorHelper(config.bullmq);
|
|
25
|
+
return new BullMQMailExecutorHelper(config.options);
|
|
32
26
|
}
|
|
33
27
|
default: {
|
|
34
|
-
|
|
28
|
+
// Only plain-JS input gets here: the union is exhausted for a typed caller. The type alone is named, the rest of the config can hold a Redis password.
|
|
29
|
+
const unknownConfig = config;
|
|
30
|
+
throw getError({
|
|
31
|
+
message: `Unknown mail queue executor type: ${String(Reflect.get(unknownConfig, 'type'))}`,
|
|
32
|
+
});
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mail-queue-executor.provider.js","sourceRoot":"","sources":["../../../../../src/components/mail/providers/mail-queue-executor.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,+BAA+B,GAChC,MAAM,YAAY,CAAC;AAKpB,uGAAuG;AACvG,MAAM,OAAO,yBAA0B,SAAQ,YAAqC;IAClF;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,yBAAyB,CAAC,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,UAAqB;QACzB,OAAO,CAAC,MAAgC,EAAE,EAAE;YAC1C,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;iBACpB,IAAI,CAAC,0CAA0C,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YAEjE,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;gBACpB,KAAK,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC;oBACnC,OAAO,IAAI,wBAAwB,EAAE,CAAC;gBACxC,CAAC;gBAED,KAAK,sBAAsB,CAAC,cAAc,CAAC,CAAC,CAAC;oBAC3C,
|
|
1
|
+
{"version":3,"file":"mail-queue-executor.provider.js","sourceRoot":"","sources":["../../../../../src/components/mail/providers/mail-queue-executor.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,+BAA+B,GAChC,MAAM,YAAY,CAAC;AAKpB,uGAAuG;AACvG,MAAM,OAAO,yBAA0B,SAAQ,YAAqC;IAClF;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,yBAAyB,CAAC,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,UAAqB;QACzB,OAAO,CAAC,MAAgC,EAAE,EAAE;YAC1C,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;iBACpB,IAAI,CAAC,0CAA0C,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YAEjE,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;gBACpB,KAAK,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC;oBACnC,OAAO,IAAI,wBAAwB,EAAE,CAAC;gBACxC,CAAC;gBAED,KAAK,sBAAsB,CAAC,cAAc,CAAC,CAAC,CAAC;oBAC3C,OAAO,IAAI,+BAA+B,CAAC;wBACzC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,UAAU;qBACtC,CAAC,CAAC;gBACL,CAAC;gBAED,KAAK,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC;oBACnC,OAAO,IAAI,wBAAwB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACtD,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,uJAAuJ;oBACvJ,MAAM,aAAa,GAAU,MAAM,CAAC;oBAEpC,MAAM,QAAQ,CAAC;wBACb,OAAO,EAAE,qCAAqC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,EAAE;qBAC3F,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { BaseProvider } from '@venizia/ignis-kernel';\nimport type { Container } from '@/helpers';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IMailQueueExecutor, TMailQueueExecutorConfig } from '../common';\nimport { MailQueueExecutorTypes } from '../common';\nimport {\n BullMQMailExecutorHelper,\n DirectMailExecutorHelper,\n InternalQueueMailExecutorHelper,\n} from '../helpers';\n\n/** Builds the queue executor for a config; throws when the config for its `type` is missing or the type is unknown. */\nexport type TGetMailQueueExecutorFn = (config: TMailQueueExecutorConfig) => IMailQueueExecutor;\n\n/** Provides the `TGetMailQueueExecutorFn` factory bound at `MailKeys.MAIL_QUEUE_EXECUTOR_PROVIDER`. */\nexport class MailQueueExecutorProvider extends BaseProvider<TGetMailQueueExecutorFn> {\n constructor() {\n super({ scope: MailQueueExecutorProvider.name });\n }\n\n value(_container: Container): TGetMailQueueExecutorFn {\n return (config: TMailQueueExecutorConfig) => {\n this.logger\n .for(this.value.name)\n .info('Creating mail queue executor of type: %s', config.type);\n\n switch (config.type) {\n case MailQueueExecutorTypes.DIRECT: {\n return new DirectMailExecutorHelper();\n }\n\n case MailQueueExecutorTypes.INTERNAL_QUEUE: {\n return new InternalQueueMailExecutorHelper({\n identifier: config.options.identifier,\n });\n }\n\n case MailQueueExecutorTypes.BULLMQ: {\n return new BullMQMailExecutorHelper(config.options);\n }\n\n default: {\n // Only plain-JS input gets here: the union is exhausted for a typed caller. The type alone is named, the rest of the config can hold a Redis password.\n const unknownConfig: never = config;\n\n throw getError({\n message: `Unknown mail queue executor type: ${String(Reflect.get(unknownConfig, 'type'))}`,\n });\n }\n }\n };\n }\n}\n"]}
|