@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
|
@@ -5,38 +5,50 @@ export declare class MailDefaults {
|
|
|
5
5
|
static readonly FALLBACK_FROM = "noreply@example.com";
|
|
6
6
|
/** Bytes of attachment content one message may carry, all attachments together. */
|
|
7
7
|
static readonly MAX_ATTACHMENT_BYTES: number;
|
|
8
|
+
/** The subject of a template mail that has none of its own. */
|
|
9
|
+
static readonly SUBJECT = "No Subject";
|
|
10
|
+
/** Tries per queued mail, the first included, unless the job options say otherwise. */
|
|
11
|
+
static readonly ATTEMPTS = 3;
|
|
12
|
+
static readonly BACKOFF_DELAY_MS = 1000;
|
|
13
|
+
/** How long a failed BullMQ mail job stays in Redis (it holds a recipient address), and the most that stay. */
|
|
14
|
+
static readonly FAILED_JOB_RETENTION: {
|
|
15
|
+
age: number;
|
|
16
|
+
count: number;
|
|
17
|
+
};
|
|
8
18
|
}
|
|
9
|
-
/**
|
|
19
|
+
/** Where a rendered template is going: `HTML` escapes every double-brace placeholder, `TEXT` (a subject, a plain-text part) inserts it as it is. A triple-brace placeholder is raw in both. */
|
|
20
|
+
export declare class MailTemplateFormats {
|
|
21
|
+
static readonly HTML = "html";
|
|
22
|
+
static readonly TEXT = "text";
|
|
23
|
+
}
|
|
24
|
+
/** Union of the `MailTemplateFormats` values. */
|
|
25
|
+
export type TMailTemplateFormat = TConstValue<typeof MailTemplateFormats>;
|
|
26
|
+
/** Names of the jobs the BullMQ mail executor adds. */
|
|
27
|
+
export declare class MailQueueJobNames {
|
|
28
|
+
static readonly SEND_VERIFICATION_EMAIL = "send-verification-email";
|
|
29
|
+
}
|
|
30
|
+
/** The codes of the server-side failures, which are not in the 4xx `MailErrors` catalog. Built via {@link MessageCode.build}: `ApplicationError` lower-cases codes, so a SCREAMING_CASE literal would reach the client in a spelling no const here matches. */
|
|
10
31
|
export declare class MailErrorCodes {
|
|
11
|
-
static readonly INVALID_CONFIGURATION: string;
|
|
12
32
|
static readonly SEND_FAILED: string;
|
|
13
33
|
static readonly VERIFICATION_FAILED: string;
|
|
14
|
-
static readonly INVALID_RECIPIENT: string;
|
|
15
34
|
static readonly BATCH_SEND_FAILED: string;
|
|
16
|
-
static readonly TEMPLATE_NOT_FOUND: string;
|
|
17
|
-
static readonly ATTACHMENT_PATH_REFUSED: string;
|
|
18
|
-
static readonly ATTACHMENT_TOO_LARGE: string;
|
|
19
|
-
static readonly BODY_SOURCE_REFUSED: string;
|
|
20
35
|
}
|
|
21
36
|
/** Messages thrown by the mail queue executors. */
|
|
22
37
|
export declare class MailExecutorErrors {
|
|
23
38
|
static readonly PROCESSOR_NOT_SET = "Processor not set. Call setProcessor() first.";
|
|
39
|
+
static readonly CLOSED = "The executor is closed and takes no more jobs.";
|
|
24
40
|
}
|
|
25
|
-
/** Values of `
|
|
41
|
+
/** Values of `TMailQueueExecutorConfig.type`, selecting how verification mails are queued: sent inline, held in process, or handed to BullMQ. */
|
|
26
42
|
export declare class MailQueueExecutorTypes {
|
|
27
43
|
static readonly DIRECT = "direct";
|
|
28
44
|
static readonly INTERNAL_QUEUE = "internal-queue";
|
|
29
45
|
static readonly BULLMQ = "bullmq";
|
|
30
|
-
static readonly SCHEME_SET: Set<string>;
|
|
31
|
-
static isValid(value: string): boolean;
|
|
32
46
|
}
|
|
33
47
|
/** Values of `IBullMQMailExecutorOpts.mode`: `queue-only` enqueues jobs without starting workers, `worker-only` starts workers without a queue, `both` does each. */
|
|
34
48
|
export declare class BullMQExecutorModes {
|
|
35
49
|
static readonly QUEUE_ONLY = "queue-only";
|
|
36
50
|
static readonly WORKER_ONLY = "worker-only";
|
|
37
51
|
static readonly BOTH = "both";
|
|
38
|
-
static readonly MODE_SET: Set<string>;
|
|
39
|
-
static isValid(value: string): boolean;
|
|
40
52
|
}
|
|
41
53
|
/** Values of `TMailOptions.provider`, naming the transport the mail component builds. */
|
|
42
54
|
export declare class MailProviders {
|
|
@@ -51,8 +63,6 @@ export type TMailProvider = TConstValue<typeof MailProviders>;
|
|
|
51
63
|
export declare class MailBackoffTypes {
|
|
52
64
|
static readonly FIXED = "fixed";
|
|
53
65
|
static readonly EXPONENTIAL = "exponential";
|
|
54
|
-
static readonly SCHEME_SET: Set<string>;
|
|
55
|
-
static isValid(value: string): boolean;
|
|
56
66
|
}
|
|
57
67
|
/** Valid mail backoff type values. */
|
|
58
68
|
export type TMailBackoffType = TConstValue<typeof MailBackoffTypes>;
|
|
@@ -5,58 +5,49 @@ export class MailDefaults {
|
|
|
5
5
|
static { this.FALLBACK_FROM = 'noreply@example.com'; }
|
|
6
6
|
/** Bytes of attachment content one message may carry, all attachments together. */
|
|
7
7
|
static { this.MAX_ATTACHMENT_BYTES = 25 * 1024 * 1024; }
|
|
8
|
+
/** The subject of a template mail that has none of its own. */
|
|
9
|
+
static { this.SUBJECT = 'No Subject'; }
|
|
10
|
+
/** Tries per queued mail, the first included, unless the job options say otherwise. */
|
|
11
|
+
static { this.ATTEMPTS = 3; }
|
|
12
|
+
static { this.BACKOFF_DELAY_MS = 1000; }
|
|
13
|
+
/** How long a failed BullMQ mail job stays in Redis (it holds a recipient address), and the most that stay. */
|
|
14
|
+
static { this.FAILED_JOB_RETENTION = { age: 7 * 24 * 60 * 60, count: 1000 }; }
|
|
8
15
|
}
|
|
9
|
-
/**
|
|
16
|
+
/** Where a rendered template is going: `HTML` escapes every double-brace placeholder, `TEXT` (a subject, a plain-text part) inserts it as it is. A triple-brace placeholder is raw in both. */
|
|
17
|
+
export class MailTemplateFormats {
|
|
18
|
+
static { this.HTML = 'html'; }
|
|
19
|
+
static { this.TEXT = 'text'; }
|
|
20
|
+
}
|
|
21
|
+
/** Names of the jobs the BullMQ mail executor adds. */
|
|
22
|
+
export class MailQueueJobNames {
|
|
23
|
+
static { this.SEND_VERIFICATION_EMAIL = 'send-verification-email'; }
|
|
24
|
+
}
|
|
25
|
+
/** The codes of the server-side failures, which are not in the 4xx `MailErrors` catalog. Built via {@link MessageCode.build}: `ApplicationError` lower-cases codes, so a SCREAMING_CASE literal would reach the client in a spelling no const here matches. */
|
|
10
26
|
export class MailErrorCodes {
|
|
11
|
-
static { this.INVALID_CONFIGURATION = MessageCode.build({
|
|
12
|
-
parts: ['core', 'mail', 'invalid_configuration'],
|
|
13
|
-
}); }
|
|
14
27
|
static { this.SEND_FAILED = MessageCode.build({ parts: ['core', 'mail', 'send_failed'] }); }
|
|
15
28
|
static { this.VERIFICATION_FAILED = MessageCode.build({
|
|
16
29
|
parts: ['core', 'mail', 'verification_failed'],
|
|
17
30
|
}); }
|
|
18
|
-
static { this.INVALID_RECIPIENT = MessageCode.build({
|
|
19
|
-
parts: ['core', 'mail', 'invalid_recipient'],
|
|
20
|
-
}); }
|
|
21
31
|
static { this.BATCH_SEND_FAILED = MessageCode.build({
|
|
22
32
|
parts: ['core', 'mail', 'batch_send_failed'],
|
|
23
33
|
}); }
|
|
24
|
-
static { this.TEMPLATE_NOT_FOUND = MessageCode.build({
|
|
25
|
-
parts: ['core', 'mail', 'template_not_found'],
|
|
26
|
-
}); }
|
|
27
|
-
static { this.ATTACHMENT_PATH_REFUSED = MessageCode.build({
|
|
28
|
-
parts: ['core', 'mail', 'attachment_path_refused'],
|
|
29
|
-
}); }
|
|
30
|
-
static { this.ATTACHMENT_TOO_LARGE = MessageCode.build({
|
|
31
|
-
parts: ['core', 'mail', 'attachment_too_large'],
|
|
32
|
-
}); }
|
|
33
|
-
static { this.BODY_SOURCE_REFUSED = MessageCode.build({
|
|
34
|
-
parts: ['core', 'mail', 'body_source_refused'],
|
|
35
|
-
}); }
|
|
36
34
|
}
|
|
37
35
|
/** Messages thrown by the mail queue executors. */
|
|
38
36
|
export class MailExecutorErrors {
|
|
39
37
|
static { this.PROCESSOR_NOT_SET = 'Processor not set. Call setProcessor() first.'; }
|
|
38
|
+
static { this.CLOSED = 'The executor is closed and takes no more jobs.'; }
|
|
40
39
|
}
|
|
41
|
-
/** Values of `
|
|
40
|
+
/** Values of `TMailQueueExecutorConfig.type`, selecting how verification mails are queued: sent inline, held in process, or handed to BullMQ. */
|
|
42
41
|
export class MailQueueExecutorTypes {
|
|
43
42
|
static { this.DIRECT = 'direct'; }
|
|
44
43
|
static { this.INTERNAL_QUEUE = 'internal-queue'; }
|
|
45
44
|
static { this.BULLMQ = 'bullmq'; }
|
|
46
|
-
static { this.SCHEME_SET = new Set([this.DIRECT, this.INTERNAL_QUEUE, this.BULLMQ]); }
|
|
47
|
-
static isValid(value) {
|
|
48
|
-
return this.SCHEME_SET.has(value);
|
|
49
|
-
}
|
|
50
45
|
}
|
|
51
46
|
/** Values of `IBullMQMailExecutorOpts.mode`: `queue-only` enqueues jobs without starting workers, `worker-only` starts workers without a queue, `both` does each. */
|
|
52
47
|
export class BullMQExecutorModes {
|
|
53
48
|
static { this.QUEUE_ONLY = 'queue-only'; }
|
|
54
49
|
static { this.WORKER_ONLY = 'worker-only'; }
|
|
55
50
|
static { this.BOTH = 'both'; }
|
|
56
|
-
static { this.MODE_SET = new Set([this.QUEUE_ONLY, this.WORKER_ONLY, this.BOTH]); }
|
|
57
|
-
static isValid(value) {
|
|
58
|
-
return this.MODE_SET.has(value);
|
|
59
|
-
}
|
|
60
51
|
}
|
|
61
52
|
/** Values of `TMailOptions.provider`, naming the transport the mail component builds. */
|
|
62
53
|
export class MailProviders {
|
|
@@ -70,9 +61,5 @@ export class MailProviders {
|
|
|
70
61
|
export class MailBackoffTypes {
|
|
71
62
|
static { this.FIXED = 'fixed'; }
|
|
72
63
|
static { this.EXPONENTIAL = 'exponential'; }
|
|
73
|
-
static { this.SCHEME_SET = new Set([this.FIXED, this.EXPONENTIAL]); }
|
|
74
|
-
static isValid(value) {
|
|
75
|
-
return this.SCHEME_SET.has(value);
|
|
76
|
-
}
|
|
77
64
|
}
|
|
78
65
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/components/mail/common/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,gKAAgK;AAChK,MAAM,OAAO,YAAY;aACP,sBAAiB,GAAG,CAAC,CAAC;aACtB,kBAAa,GAAG,qBAAqB,CAAC;IACtD,mFAAmF;aACnE,yBAAoB,GAAG,EAAE,GAAG,IAAI,GAA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AAG,+CAA+C,CAAC;aACpE,WAAM,GAAG,gDAAgD,CAAC;;AAG5E,iJAAiJ;AACjJ,MAAM,OAAO,sBAAsB;aACjB,WAAM,GAAG,QAAQ,CAAC;aAClB,mBAAc,GAAG,gBAAgB,CAAC;aAClC,WAAM,GAAG,QAAQ,CAAC;;AAGpC,qKAAqK;AACrK,MAAM,OAAO,mBAAmB;aACd,eAAU,GAAG,YAAY,CAAC;aAC1B,gBAAW,GAAG,aAAa,CAAC;aAC5B,SAAI,GAAG,MAAM,CAAC;;AAGhC,yFAAyF;AACzF,MAAM,OAAO,aAAa;aACR,eAAU,GAAG,YAAY,CAAC;aAC1B,YAAO,GAAG,SAAS,CAAC;aACpB,WAAM,GAAG,QAAQ,CAAC;IAClC,uHAAuH;aACvG,eAAU,GAAG,YAAY,CAAC;;AAM5C,iHAAiH;AACjH,MAAM,OAAO,gBAAgB;aACX,UAAK,GAAG,OAAO,CAAC;aAChB,gBAAW,GAAG,aAAa,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { MessageCode } from '@venizia/ignis-helpers/core';\n\n/** Fallbacks for mail sending: the batch concurrency, the `from` address used when neither the message nor the options set one, and the attachment size cap. */\nexport class MailDefaults {\n static readonly BATCH_CONCURRENCY = 5;\n static readonly FALLBACK_FROM = 'noreply@example.com';\n /** Bytes of attachment content one message may carry, all attachments together. */\n static readonly MAX_ATTACHMENT_BYTES = 25 * 1024 * 1024;\n /** The subject of a template mail that has none of its own. */\n static readonly SUBJECT = 'No Subject';\n /** Tries per queued mail, the first included, unless the job options say otherwise. */\n static readonly ATTEMPTS = 3;\n static readonly BACKOFF_DELAY_MS = 1000;\n /** How long a failed BullMQ mail job stays in Redis (it holds a recipient address), and the most that stay. */\n static readonly FAILED_JOB_RETENTION = { age: 7 * 24 * 60 * 60, count: 1000 };\n}\n\n/** Where a rendered template is going: `HTML` escapes every double-brace placeholder, `TEXT` (a subject, a plain-text part) inserts it as it is. A triple-brace placeholder is raw in both. */\nexport class MailTemplateFormats {\n static readonly HTML = 'html';\n static readonly TEXT = 'text';\n}\n\n/** Union of the `MailTemplateFormats` values. */\nexport type TMailTemplateFormat = TConstValue<typeof MailTemplateFormats>;\n\n/** Names of the jobs the BullMQ mail executor adds. */\nexport class MailQueueJobNames {\n static readonly SEND_VERIFICATION_EMAIL = 'send-verification-email';\n}\n\n/** The codes of the server-side failures, which are not in the 4xx `MailErrors` catalog. Built via {@link MessageCode.build}: `ApplicationError` lower-cases codes, so a SCREAMING_CASE literal would reach the client in a spelling no const here matches. */\nexport class MailErrorCodes {\n static readonly SEND_FAILED = MessageCode.build({ parts: ['core', 'mail', 'send_failed'] });\n static readonly VERIFICATION_FAILED = MessageCode.build({\n parts: ['core', 'mail', 'verification_failed'],\n });\n\n static readonly BATCH_SEND_FAILED = MessageCode.build({\n parts: ['core', 'mail', 'batch_send_failed'],\n });\n}\n\n/** Messages thrown by the mail queue executors. */\nexport class MailExecutorErrors {\n static readonly PROCESSOR_NOT_SET = 'Processor not set. Call setProcessor() first.';\n static readonly CLOSED = 'The executor is closed and takes no more jobs.';\n}\n\n/** Values of `TMailQueueExecutorConfig.type`, selecting how verification mails are queued: sent inline, held in process, or handed to BullMQ. */\nexport class MailQueueExecutorTypes {\n static readonly DIRECT = 'direct';\n static readonly INTERNAL_QUEUE = 'internal-queue';\n static readonly BULLMQ = 'bullmq';\n}\n\n/** Values of `IBullMQMailExecutorOpts.mode`: `queue-only` enqueues jobs without starting workers, `worker-only` starts workers without a queue, `both` does each. */\nexport class BullMQExecutorModes {\n static readonly QUEUE_ONLY = 'queue-only';\n static readonly WORKER_ONLY = 'worker-only';\n static readonly BOTH = 'both';\n}\n\n/** Values of `TMailOptions.provider`, naming the transport the mail component builds. */\nexport class MailProviders {\n static readonly NODEMAILER = 'nodemailer';\n static readonly MAILGUN = 'mailgun';\n static readonly CUSTOM = 'custom';\n // Amazon SES supports both SMTP and HTTPS - this provider is the HTTPS API path; SMTP goes through NODEMAILER instead.\n static readonly AMAZON_SES = 'amazon-ses';\n}\n\n/** Union of the `MailProviders` values. */\nexport type TMailProvider = TConstValue<typeof MailProviders>;\n\n/** How the delay between two attempts to send a queued mail grows: FIXED stays the same, EXPONENTIAL doubles. */\nexport class MailBackoffTypes {\n static readonly FIXED = 'fixed';\n static readonly EXPONENTIAL = 'exponential';\n}\n\n/** Valid mail backoff type values. */\nexport type TMailBackoffType = TConstValue<typeof MailBackoffTypes>;\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TRegisterErrors } from '@venizia/ignis-helpers/core';
|
|
2
2
|
/** Codes a client branches on for a mail request it can fix - a missing template, a message that is not sendable. Delivery failures are NOT here: they are 5xx and stay codeless, because a client cannot act on the remote provider being down. */
|
|
3
|
-
/** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete.
|
|
3
|
+
/** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete. `MailErrorCodes` holds only the codes of the server-side failures, which are not in this 4xx catalog: every code string has one home. They are a public contract and must not shift. */
|
|
4
4
|
export declare const MailErrors: {
|
|
5
5
|
readonly TEMPLATE_NOT_FOUND: {
|
|
6
6
|
readonly message: {
|
|
@@ -43,6 +43,15 @@ export declare const MailErrors: {
|
|
|
43
43
|
readonly statusCode: 413;
|
|
44
44
|
readonly category: "validation";
|
|
45
45
|
};
|
|
46
|
+
/** An address, the subject or a header holds a line break or another control character, or a header name is not printable ASCII: it would break out of its header line. */
|
|
47
|
+
readonly INVALID_HEADER: {
|
|
48
|
+
readonly message: {
|
|
49
|
+
readonly text: "Invalid mail header";
|
|
50
|
+
readonly code: "core.mail.invalid_header";
|
|
51
|
+
};
|
|
52
|
+
readonly statusCode: 400;
|
|
53
|
+
readonly category: "validation";
|
|
54
|
+
};
|
|
46
55
|
readonly BODY_SOURCE_REFUSED: {
|
|
47
56
|
readonly message: {
|
|
48
57
|
readonly text: "Mail body must be text";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ErrorScopes } from '@venizia/ignis-helpers/core';
|
|
2
2
|
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
3
3
|
/** Codes a client branches on for a mail request it can fix - a missing template, a message that is not sendable. Delivery failures are NOT here: they are 5xx and stay codeless, because a client cannot act on the remote provider being down. */
|
|
4
|
-
/** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete.
|
|
4
|
+
/** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete. `MailErrorCodes` holds only the codes of the server-side failures, which are not in this 4xx catalog: every code string has one home. They are a public contract and must not shift. */
|
|
5
5
|
export const MailErrors = {
|
|
6
6
|
TEMPLATE_NOT_FOUND: {
|
|
7
7
|
message: { text: 'Mail template not found', code: 'core.mail.template_not_found' },
|
|
@@ -35,6 +35,12 @@ export const MailErrors = {
|
|
|
35
35
|
statusCode: HTTP.ResultCodes.RS_4.ContentTooLarge,
|
|
36
36
|
category: ErrorScopes.VALIDATION,
|
|
37
37
|
},
|
|
38
|
+
/** An address, the subject or a header holds a line break or another control character, or a header name is not printable ASCII: it would break out of its header line. */
|
|
39
|
+
INVALID_HEADER: {
|
|
40
|
+
message: { text: 'Invalid mail header', code: 'core.mail.invalid_header' },
|
|
41
|
+
statusCode: HTTP.ResultCodes.RS_4.BadRequest,
|
|
42
|
+
category: ErrorScopes.VALIDATION,
|
|
43
|
+
},
|
|
38
44
|
BODY_SOURCE_REFUSED: {
|
|
39
45
|
message: { text: 'Mail body must be text', code: 'core.mail.body_source_refused' },
|
|
40
46
|
statusCode: HTTP.ResultCodes.RS_4.BadRequest,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/components/mail/common/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,oPAAoP;AACpP,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/components/mail/common/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,oPAAoP;AACpP,gYAAgY;AAChY,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,kBAAkB,EAAE;QAClB,OAAO,EAAE,EAAE,IAAI,EAAE,yBAAyB,EAAE,IAAI,EAAE,8BAA8B,EAAE;QAClF,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ;QAC1C,QAAQ,EAAE,WAAW,CAAC,QAAQ;KAC/B;IACD,qBAAqB,EAAE;QACrB,OAAO,EAAE,EAAE,IAAI,EAAE,4BAA4B,EAAE,IAAI,EAAE,iCAAiC,EAAE;QACxF,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,iBAAiB,EAAE;QACjB,OAAO,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,IAAI,EAAE,6BAA6B,EAAE;QAChF,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,gIAAgI;IAChI,uBAAuB,EAAE;QACvB,OAAO,EAAE;YACP,IAAI,EAAE,8BAA8B;YACpC,IAAI,EAAE,mCAAmC;SAC1C;QACD,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,oBAAoB,EAAE;QACpB,OAAO,EAAE;YACP,IAAI,EAAE,sDAAsD;YAC5D,IAAI,EAAE,gCAAgC;SACvC;QACD,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe;QACjD,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,2KAA2K;IAC3K,cAAc,EAAE;QACd,OAAO,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,0BAA0B,EAAE;QAC1E,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,mBAAmB,EAAE;QACnB,OAAO,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,IAAI,EAAE,+BAA+B,EAAE;QAClF,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;CACkD,CAAC","sourcesContent":["import type { TErrorDefinition, TRegisterErrors } from '@venizia/ignis-helpers/core';\nimport { ErrorScopes } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\n\n/** Codes a client branches on for a mail request it can fix - a missing template, a message that is not sendable. Delivery failures are NOT here: they are 5xx and stay codeless, because a client cannot act on the remote provider being down. */\n/** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete. `MailErrorCodes` holds only the codes of the server-side failures, which are not in this 4xx catalog: every code string has one home. They are a public contract and must not shift. */\nexport const MailErrors = {\n TEMPLATE_NOT_FOUND: {\n message: { text: 'Mail template not found', code: 'core.mail.template_not_found' },\n statusCode: HTTP.ResultCodes.RS_4.NotFound,\n category: ErrorScopes.BUSINESS,\n },\n INVALID_CONFIGURATION: {\n message: { text: 'Invalid mail configuration', code: 'core.mail.invalid_configuration' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n INVALID_RECIPIENT: {\n message: { text: 'Invalid mail recipient', code: 'core.mail.invalid_recipient' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n /** One answer for every refused source - outside the root, missing, not a file - so a caller cannot probe which files exist. */\n ATTACHMENT_PATH_REFUSED: {\n message: {\n text: 'Mail attachment path refused',\n code: 'core.mail.attachment_path_refused',\n },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n ATTACHMENT_TOO_LARGE: {\n message: {\n text: 'Mail attachments are larger than the maximum allowed',\n code: 'core.mail.attachment_too_large',\n },\n statusCode: HTTP.ResultCodes.RS_4.ContentTooLarge,\n category: ErrorScopes.VALIDATION,\n },\n /** An address, the subject or a header holds a line break or another control character, or a header name is not printable ASCII: it would break out of its header line. */\n INVALID_HEADER: {\n message: { text: 'Invalid mail header', code: 'core.mail.invalid_header' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n BODY_SOURCE_REFUSED: {\n message: { text: 'Mail body must be text', code: 'core.mail.body_source_refused' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n} as const satisfies Record<string, TErrorDefinition>;\n\n/** Registers these codes with the shared key registry so a consumer gets autocomplete on `messageCode`. */\ndeclare module '@venizia/ignis-helpers' {\n interface IErrorKeyRegistry extends TRegisterErrors<typeof MailErrors> {}\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TMailBackoffType } from '../constants.js';
|
|
2
|
-
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
2
|
+
import type { TConstValue, ValueOrPromise } from '@venizia/ignis-helpers/common';
|
|
3
3
|
import type { IRedisHelper } from '@venizia/ignis-helpers';
|
|
4
4
|
import type { BullMQExecutorModes, MailQueueExecutorTypes } from '../constants.js';
|
|
5
5
|
/** Per-job options for a queued verification mail. `delay` and `backoff.delay` are milliseconds; `attempts` is the total number of tries, first included. */
|
|
@@ -29,7 +29,9 @@ export interface IMailQueueResult {
|
|
|
29
29
|
/** Queues verification mails and runs them through the processor registered with `setProcessor`. */
|
|
30
30
|
export interface IMailQueueExecutor {
|
|
31
31
|
enqueueVerificationEmail(email: string, options?: IMailQueueOptions): Promise<IMailQueueResult>;
|
|
32
|
-
setProcessor(processor: (email: string) => Promise<IMailProcessorResult>): void
|
|
32
|
+
setProcessor(processor: (email: string) => Promise<IMailProcessorResult>): ValueOrPromise<void>;
|
|
33
|
+
/** Releases what the executor holds: timers, workers, the queue. The application stop hook calls it. */
|
|
34
|
+
close?(): Promise<void>;
|
|
33
35
|
}
|
|
34
36
|
/** Envelope every queue-backed executor stores for one pending verification email. */
|
|
35
37
|
export interface IQueueJobPayload {
|
|
@@ -59,10 +61,15 @@ export interface IBullMQMailExecutorOpts {
|
|
|
59
61
|
/** `bullmq` itself, for a `bun build --compile` binary that has no `node_modules` to load it from. */
|
|
60
62
|
module?: typeof import('bullmq');
|
|
61
63
|
}
|
|
62
|
-
/** Selects and configures the mail queue executor
|
|
63
|
-
export
|
|
64
|
-
type:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
/** Selects and configures the mail queue executor: `type` picks one of three, and the options its executor needs are required by the types. */
|
|
65
|
+
export type TMailQueueExecutorConfig = {
|
|
66
|
+
type: typeof MailQueueExecutorTypes.DIRECT;
|
|
67
|
+
options?: never;
|
|
68
|
+
} | {
|
|
69
|
+
type: typeof MailQueueExecutorTypes.INTERNAL_QUEUE;
|
|
70
|
+
options: IInternalQueueMailExecutorOpts;
|
|
71
|
+
} | {
|
|
72
|
+
type: typeof MailQueueExecutorTypes.BULLMQ;
|
|
73
|
+
options: IBullMQMailExecutorOpts;
|
|
74
|
+
};
|
|
68
75
|
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../../../src/components/mail/common/types/queue.ts"],"names":[],"mappings":"","sourcesContent":["import type { TMailBackoffType } from '../constants';\nimport type { TConstValue } from '@venizia/ignis-helpers/common';\nimport type { IRedisHelper } from '@venizia/ignis-helpers';\nimport type { BullMQExecutorModes, MailQueueExecutorTypes } from '../constants';\n\n/** Per-job options for a queued verification mail. `delay` and `backoff.delay` are milliseconds; `attempts` is the total number of tries, first included. */\nexport interface IMailQueueOptions {\n priority?: number;\n delay?: number;\n attempts?: number;\n backoff?: {\n type: TMailBackoffType;\n delay: number;\n };\n}\n\n/** Result a queue processor returns for one verification mail; returning `success: false` marks the job failed so it is retried. */\nexport interface IMailProcessorResult {\n success: boolean;\n message: string;\n expiresInMinutes: number;\n nextResendAt?: string;\n}\n\n/** Result of enqueueing a verification mail; `queued` is `false` and `result` is set when the executor ran the mail inline. */\nexport interface IMailQueueResult {\n jobId?: string;\n queued: boolean;\n message: string;\n result?: IMailProcessorResult;\n}\n\n/** Queues verification mails and runs them through the processor registered with `setProcessor`. */\nexport interface IMailQueueExecutor {\n enqueueVerificationEmail(email: string, options?: IMailQueueOptions): Promise<IMailQueueResult>;\n setProcessor(processor: (email: string) => Promise<IMailProcessorResult>): void
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../../../src/components/mail/common/types/queue.ts"],"names":[],"mappings":"","sourcesContent":["import type { TMailBackoffType } from '../constants';\nimport type { TConstValue, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport type { IRedisHelper } from '@venizia/ignis-helpers';\nimport type { BullMQExecutorModes, MailQueueExecutorTypes } from '../constants';\n\n/** Per-job options for a queued verification mail. `delay` and `backoff.delay` are milliseconds; `attempts` is the total number of tries, first included. */\nexport interface IMailQueueOptions {\n priority?: number;\n delay?: number;\n attempts?: number;\n backoff?: {\n type: TMailBackoffType;\n delay: number;\n };\n}\n\n/** Result a queue processor returns for one verification mail; returning `success: false` marks the job failed so it is retried. */\nexport interface IMailProcessorResult {\n success: boolean;\n message: string;\n expiresInMinutes: number;\n nextResendAt?: string;\n}\n\n/** Result of enqueueing a verification mail; `queued` is `false` and `result` is set when the executor ran the mail inline. */\nexport interface IMailQueueResult {\n jobId?: string;\n queued: boolean;\n message: string;\n result?: IMailProcessorResult;\n}\n\n/** Queues verification mails and runs them through the processor registered with `setProcessor`. */\nexport interface IMailQueueExecutor {\n enqueueVerificationEmail(email: string, options?: IMailQueueOptions): Promise<IMailQueueResult>;\n setProcessor(processor: (email: string) => Promise<IMailProcessorResult>): ValueOrPromise<void>;\n /** Releases what the executor holds: timers, workers, the queue. The application stop hook calls it. */\n close?(): Promise<void>;\n}\n\n/** Envelope every queue-backed executor stores for one pending verification email. */\nexport interface IQueueJobPayload {\n id: string;\n email: string;\n options?: IMailQueueOptions;\n attempts: number;\n scheduledAt: number;\n}\n\n/** Options of the in-process queue executor; `identifier` names its queue. */\nexport interface IInternalQueueMailExecutorOpts {\n identifier: string;\n}\n\n/** Options of the BullMQ mail executor: the Redis helper, the queue `identifier` and BullMQ `name`, and which of queue and workers this process runs. */\nexport interface IBullMQMailExecutorOpts {\n /**\n * A ready single, cluster or sentinel helper. The queue and each worker duplicate its client, and the\n * application closes it: the executor never disconnects a connection it did not create. On a cluster\n * the queue name is wrapped in a `{hash tag}` so its keys share one slot.\n */\n redis: IRedisHelper;\n queue: { identifier: string; name: string };\n mode: TConstValue<typeof BullMQExecutorModes>;\n /** `bullmq` itself, for a `bun build --compile` binary that has no `node_modules` to load it from. */\n module?: typeof import('bullmq');\n}\n\n/** Selects and configures the mail queue executor: `type` picks one of three, and the options its executor needs are required by the types. */\nexport type TMailQueueExecutorConfig =\n | { type: typeof MailQueueExecutorTypes.DIRECT; options?: never }\n | {\n type: typeof MailQueueExecutorTypes.INTERNAL_QUEUE;\n options: IInternalQueueMailExecutorOpts;\n }\n | { type: typeof MailQueueExecutorTypes.BULLMQ; options: IBullMQMailExecutorOpts };\n"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TMailTemplateFormat } from '../constants.js';
|
|
2
2
|
/** A registered mail template: `content` is the body, `subject` and `description` are optional. */
|
|
3
3
|
export interface ITemplate {
|
|
4
4
|
name: string;
|
|
5
5
|
content?: string;
|
|
6
|
-
render?: (data: Record<string, AnyType>) => string;
|
|
7
6
|
subject?: string;
|
|
8
7
|
description?: string;
|
|
9
8
|
}
|
|
@@ -14,6 +13,8 @@ export interface IMailTemplateEngine {
|
|
|
14
13
|
templateName?: string;
|
|
15
14
|
data: Record<string, any>;
|
|
16
15
|
requireValidate?: boolean;
|
|
16
|
+
/** @default MailTemplateFormats.HTML */
|
|
17
|
+
format?: TMailTemplateFormat;
|
|
17
18
|
}): string;
|
|
18
19
|
registerTemplate(opts: {
|
|
19
20
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../../../../src/components/mail/common/types/template.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../../../../src/components/mail/common/types/template.ts"],"names":[],"mappings":"","sourcesContent":["import type { TMailTemplateFormat } from '../constants';\n\n/** A registered mail template: `content` is the body, `subject` and `description` are optional. */\nexport interface ITemplate {\n name: string;\n content?: string;\n subject?: string;\n description?: string;\n}\n\n/** Stores and renders mail templates. Render with a registered `templateName` or inline `templateData`. */\nexport interface IMailTemplateEngine {\n render(opts: {\n templateData?: string;\n templateName?: string;\n data: Record<string, any>;\n requireValidate?: boolean;\n /** @default MailTemplateFormats.HTML */\n format?: TMailTemplateFormat;\n }): string;\n registerTemplate(opts: { name: string; content: string }): void;\n validateTemplateData(opts: { template: string; data: Record<string, any> }): {\n isValid: boolean;\n missingKeys: string[];\n allKeys: string[];\n };\n getTemplate(name: string): ITemplate | undefined;\n listTemplates(): ITemplate[];\n hasTemplate(name: string): boolean;\n removeTemplate(name: string): boolean;\n}\n"]}
|
|
@@ -18,7 +18,7 @@ import { getError } from '@venizia/ignis-helpers/core';
|
|
|
18
18
|
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
19
19
|
import { statSync } from 'node:fs';
|
|
20
20
|
import { isAbsolute } from 'node:path';
|
|
21
|
-
import {
|
|
21
|
+
import { MailErrors, MailKeys, MailQueueExecutorTypes } from './common/index.js';
|
|
22
22
|
import { MailQueueExecutorProvider, MailTransportProvider } from './providers/index.js';
|
|
23
23
|
import { DefaultVerificationDataGenerator, MailService, NumericCodeGenerator, RandomTokenGenerator, TemplateEngineService, } from './services/index.js';
|
|
24
24
|
/** Registers the mail transport, queue executor, template engine, `MailService` and verification generators under `MailKeys`. Options come from `MailKeys.MAIL_OPTIONS` or from the options passed to `application.component`; boot throws when they are missing or when `attachmentRoot` or `maxAttachmentBytes` is invalid. */
|
|
@@ -95,7 +95,7 @@ let MailComponent = MailComponent_1 = class MailComponent extends BaseComponent
|
|
|
95
95
|
const buildOptionError = (details) => {
|
|
96
96
|
return getError({
|
|
97
97
|
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
98
|
-
|
|
98
|
+
error: MailErrors.INVALID_CONFIGURATION,
|
|
99
99
|
message: `Invalid mail options | ${details.message}`,
|
|
100
100
|
cause: details.cause,
|
|
101
101
|
});
|
|
@@ -155,6 +155,15 @@ let MailComponent = MailComponent_1 = class MailComponent extends BaseComponent
|
|
|
155
155
|
this.application
|
|
156
156
|
.bind({ key: MailKeys.MAIL_QUEUE_EXECUTOR_INSTANCE })
|
|
157
157
|
.toValue(queueExecutorInstance);
|
|
158
|
+
// Workers, timers and SMTP pools outlive the application unless something closes them. Executor first, so a job in flight finishes against a live transport.
|
|
159
|
+
this.application.registerPostStopHook({
|
|
160
|
+
identifier: 'mail.queue-executor.close',
|
|
161
|
+
hook: () => queueExecutorInstance.close?.(),
|
|
162
|
+
});
|
|
163
|
+
this.application.registerPostStopHook({
|
|
164
|
+
identifier: 'mail.transport.close',
|
|
165
|
+
hook: () => mailTransportInstance.close?.(),
|
|
166
|
+
});
|
|
158
167
|
}
|
|
159
168
|
};
|
|
160
169
|
MailComponent = MailComponent_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../src/components/mail/component.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE5E,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EACL,gCAAgC,EAChC,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAEpB,iUAAiU;AACjU,IAAa,aAAa,qBAA1B,MAAa,aAAc,SAAQ,aAA2B;IAC5D,YAC8D,WAA4B;QAExF,KAAK,CAAC;YACJ,KAAK,EAAE,eAAa,CAAC,IAAI;YACzB,WAAW,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE;YACrD,QAAQ,EAAE,EAAE;SACb,CAAC,CAAC;QANyD,gBAAW,GAAX,WAAW,CAAiB;IAO1F,CAAC;IAED,kHAAkH;IACzG,KAAK,CAAC,SAAS,CAAC,IAAmB;QAC1C,0FAA0F;QAC1F,gEAAgE;QAChE,IAAI,IA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AC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC;aACrC,IAAI,CAAC,mBAAmB,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;QAEnD,MAAM,qBAAqB,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;QAC3D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,uBAAuB,EAAE,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;QAEhG,QAAQ;QACR,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAA0B;YAChE,GAAG,EAAE,QAAQ,CAAC,4BAA4B;SAC3C,CAAC,CAAC;QAEH,oJAAoJ;QACpJ,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAA2B;YACjE,GAAG,EAAE,QAAQ,CAAC,0BAA0B;YACxC,UAAU,EAAE,IAAI;SACjB,CAAC,IAAI,EAAE,IAAI,EAAE,sBAAsB,CAAC,MAAM,EAAE,CAAC;QAE9C,oEAAoE;QACpE,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC;aACrC,IAAI,CAAC,8BAA8B,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QAE1D,MAAM,qBAAqB,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;QACvD,IAAI,CAAC,WAAW;aACb,IAAI,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,4BAA4B,EAAE,CAAC;aACpD,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AApKY,aAAa;IAErB,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAF1C,aAAa,CAoKzB","sourcesContent":["import { type BaseApplication } from '@/base/applications';\nimport { BaseComponent } from '@venizia/ignis-kernel';\nimport { inject } from '@/base/metadata';\nimport { CoreBindings } from '@/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { statSync } from 'node:fs';\nimport { isAbsolute } from 'node:path';\nimport type { IMailQueueExecutorConfig, TMailOptions } from './common';\nimport { MailErrorCodes, MailKeys, MailQueueExecutorTypes } from './common';\nimport type { TGetMailQueueExecutorFn, TGetMailTransportFn } from './providers';\nimport { MailQueueExecutorProvider, MailTransportProvider } from './providers';\nimport {\n DefaultVerificationDataGenerator,\n MailService,\n NumericCodeGenerator,\n RandomTokenGenerator,\n TemplateEngineService,\n} from './services';\n\n/** Registers the mail transport, queue executor, template engine, `MailService` and verification generators under `MailKeys`. Options come from `MailKeys.MAIL_OPTIONS` or from the options passed to `application.component`; boot throws when they are missing or when `attachmentRoot` or `maxAttachmentBytes` is invalid. */\nexport class MailComponent extends BaseComponent<TMailOptions> {\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: MailComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {},\n });\n }\n\n /** `application.component(MailComponent, { options })` lands here; the call site outranks a key bound earlier. */\n override async configure(opts?: TMailOptions): Promise<void> {\n // The base short-circuits a second call; binding before that check would swap the options\n // under a transport that was already built from the first ones.\n if (this.isConfigured) {\n return;\n }\n\n if (opts !== undefined) {\n this.application.bind<TMailOptions>({ key: MailKeys.MAIL_OPTIONS }).toValue(opts);\n }\n\n await super.configure(opts);\n }\n\n override binding(): void | Promise<void> {\n if (!this.application.isBound({ key: MailKeys.MAIL_OPTIONS })) {\n this.logger\n .for(this.binding.name)\n .error(\n 'Mail options not configured. Please bind MailKeys.MAIL_OPTIONS before adding MailComponent.',\n );\n\n throw getError({\n message: 'Mail options not configured',\n });\n }\n\n this.initGenerators();\n this.initProviders();\n this.initServices();\n\n this.createAndBindInstances();\n\n this.logger.for(this.binding.name).info('Mail component initialized successfully');\n }\n\n initGenerators() {\n this.application\n .bind({ key: MailKeys.MAIL_VERIFICATION_CODE_GENERATOR })\n .toClass(NumericCodeGenerator);\n this.application\n .bind({ key: MailKeys.MAIL_VERIFICATION_TOKEN_GENERATOR })\n .toClass(RandomTokenGenerator);\n this.application\n .bind({ key: MailKeys.MAIL_VERIFICATION_DATA_GENERATOR })\n .toClass(DefaultVerificationDataGenerator);\n }\n\n initProviders() {\n this.application\n .bind({ key: MailKeys.MAIL_TRANSPORT_PROVIDER })\n .toProvider(MailTransportProvider)\n .setScope('singleton');\n this.application\n .bind({ key: MailKeys.MAIL_QUEUE_EXECUTOR_PROVIDER })\n .toProvider(MailQueueExecutorProvider)\n .setScope('singleton');\n }\n\n initServices() {\n this.application\n .bind({ key: MailKeys.MAIL_SERVICE })\n .toClass(MailService)\n .setScope('singleton');\n this.application\n .bind({ key: MailKeys.MAIL_TEMPLATE_ENGINE })\n .toClass(TemplateEngineService)\n .setScope('singleton');\n }\n\n /** A bad limit or root would otherwise surface on every send, as a 400 that blames the caller. */\n private validateAttachmentOptions(opts: { options: TMailOptions }): void {\n const { attachmentRoot, maxAttachmentBytes } = opts.options;\n\n const buildOptionError = (details: { message: string; cause?: unknown }) => {\n return getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.INVALID_CONFIGURATION,\n message: `Invalid mail options | ${details.message}`,\n cause: details.cause,\n });\n };\n\n const isValidLimit =\n maxAttachmentBytes === undefined ||\n (Number.isSafeInteger(maxAttachmentBytes) && maxAttachmentBytes > 0);\n\n if (!isValidLimit) {\n throw buildOptionError({ message: 'maxAttachmentBytes must be a positive integer' });\n }\n\n if (attachmentRoot === undefined) {\n return;\n }\n\n if (typeof attachmentRoot !== 'string' || !isAbsolute(attachmentRoot)) {\n throw buildOptionError({ message: 'attachmentRoot must be an absolute path' });\n }\n\n let isDirectory: boolean;\n\n try {\n isDirectory = statSync(attachmentRoot).isDirectory();\n } catch (error) {\n throw buildOptionError({\n message: 'attachmentRoot must be an existing directory',\n cause: error,\n });\n }\n\n if (!isDirectory) {\n throw buildOptionError({ message: 'attachmentRoot must be an existing directory' });\n }\n }\n\n createAndBindInstances(): void {\n // Transport\n const transportGetter = this.application.get<TGetMailTransportFn>({\n key: MailKeys.MAIL_TRANSPORT_PROVIDER,\n });\n const mailOptions = this.application.get<TMailOptions>({ key: MailKeys.MAIL_OPTIONS });\n this.validateAttachmentOptions({ options: mailOptions });\n\n // Only the provider is logged: the options carry SMTP / API credentials, which must never reach a log sink.\n this.logger\n .for(this.createAndBindInstances.name)\n .info('Mail provider: %s', mailOptions.provider);\n\n const mailTransportInstance = transportGetter(mailOptions);\n this.application.bind({ key: MailKeys.MAIL_TRANSPORT_INSTANCE }).toValue(mailTransportInstance);\n\n // Queue\n const queueGetter = this.application.get<TGetMailQueueExecutorFn>({\n key: MailKeys.MAIL_QUEUE_EXECUTOR_PROVIDER,\n });\n\n // Queueing is opt-in: with no executor config bound, fall back to the direct (inline) executor instead of a \"binding is not bounded\" crash at boot.\n const queueConfig = this.application.get<IMailQueueExecutorConfig>({\n key: MailKeys.MAIL_QUEUE_EXECUTOR_CONFIG,\n isOptional: true,\n }) ?? { type: MailQueueExecutorTypes.DIRECT };\n\n // Same reason as above: a bullmq config carries the Redis password.\n this.logger\n .for(this.createAndBindInstances.name)\n .info('Mail queue executor type: %s', queueConfig.type);\n\n const queueExecutorInstance = queueGetter(queueConfig);\n this.application\n .bind({ key: MailKeys.MAIL_QUEUE_EXECUTOR_INSTANCE })\n .toValue(queueExecutorInstance);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../src/components/mail/component.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,I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AM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAA2B;YACjE,GAAG,EAAE,QAAQ,CAAC,0BAA0B;YACxC,UAAU,EAAE,IAAI;SACjB,CAAC,IAAI,EAAE,IAAI,EAAE,sBAAsB,CAAC,MAAM,EAAE,CAAC;QAE9C,oEAAoE;QACpE,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC;aACrC,IAAI,CAAC,8BAA8B,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QAE1D,MAAM,qBAAqB,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;QACvD,IAAI,CAAC,WAAW;aACb,IAAI,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,4BAA4B,EAAE,CAAC;aACpD,OAAO,CAAC,qBAAqB,CAAC,CAAC;QAElC,6JAA6J;QAC7J,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC;YACpC,UAAU,EAAE,2BAA2B;YACvC,IAAI,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,KAAK,EAAE,EAAE;SAC5C,CAAC,CAAC;QACH,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC;YACpC,UAAU,EAAE,sBAAsB;YAClC,IAAI,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,KAAK,EAAE,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA9KY,aAAa;IAErB,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAF1C,aAAa,CA8KzB","sourcesContent":["import { type BaseApplication } from '@/base/applications';\nimport { BaseComponent } from '@venizia/ignis-kernel';\nimport { inject } from '@/base/metadata';\nimport { CoreBindings } from '@/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { statSync } from 'node:fs';\nimport { isAbsolute } from 'node:path';\nimport type { TMailQueueExecutorConfig, TMailOptions } from './common';\nimport { MailErrors, MailKeys, MailQueueExecutorTypes } from './common';\nimport type { TGetMailQueueExecutorFn, TGetMailTransportFn } from './providers';\nimport { MailQueueExecutorProvider, MailTransportProvider } from './providers';\nimport {\n DefaultVerificationDataGenerator,\n MailService,\n NumericCodeGenerator,\n RandomTokenGenerator,\n TemplateEngineService,\n} from './services';\n\n/** Registers the mail transport, queue executor, template engine, `MailService` and verification generators under `MailKeys`. Options come from `MailKeys.MAIL_OPTIONS` or from the options passed to `application.component`; boot throws when they are missing or when `attachmentRoot` or `maxAttachmentBytes` is invalid. */\nexport class MailComponent extends BaseComponent<TMailOptions> {\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: MailComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {},\n });\n }\n\n /** `application.component(MailComponent, { options })` lands here; the call site outranks a key bound earlier. */\n override async configure(opts?: TMailOptions): Promise<void> {\n // The base short-circuits a second call; binding before that check would swap the options\n // under a transport that was already built from the first ones.\n if (this.isConfigured) {\n return;\n }\n\n if (opts !== undefined) {\n this.application.bind<TMailOptions>({ key: MailKeys.MAIL_OPTIONS }).toValue(opts);\n }\n\n await super.configure(opts);\n }\n\n override binding(): void | Promise<void> {\n if (!this.application.isBound({ key: MailKeys.MAIL_OPTIONS })) {\n this.logger\n .for(this.binding.name)\n .error(\n 'Mail options not configured. Please bind MailKeys.MAIL_OPTIONS before adding MailComponent.',\n );\n\n throw getError({\n message: 'Mail options not configured',\n });\n }\n\n this.initGenerators();\n this.initProviders();\n this.initServices();\n\n this.createAndBindInstances();\n\n this.logger.for(this.binding.name).info('Mail component initialized successfully');\n }\n\n initGenerators() {\n this.application\n .bind({ key: MailKeys.MAIL_VERIFICATION_CODE_GENERATOR })\n .toClass(NumericCodeGenerator);\n this.application\n .bind({ key: MailKeys.MAIL_VERIFICATION_TOKEN_GENERATOR })\n .toClass(RandomTokenGenerator);\n this.application\n .bind({ key: MailKeys.MAIL_VERIFICATION_DATA_GENERATOR })\n .toClass(DefaultVerificationDataGenerator);\n }\n\n initProviders() {\n this.application\n .bind({ key: MailKeys.MAIL_TRANSPORT_PROVIDER })\n .toProvider(MailTransportProvider)\n .setScope('singleton');\n this.application\n .bind({ key: MailKeys.MAIL_QUEUE_EXECUTOR_PROVIDER })\n .toProvider(MailQueueExecutorProvider)\n .setScope('singleton');\n }\n\n initServices() {\n this.application\n .bind({ key: MailKeys.MAIL_SERVICE })\n .toClass(MailService)\n .setScope('singleton');\n this.application\n .bind({ key: MailKeys.MAIL_TEMPLATE_ENGINE })\n .toClass(TemplateEngineService)\n .setScope('singleton');\n }\n\n /** A bad limit or root would otherwise surface on every send, as a 400 that blames the caller. */\n private validateAttachmentOptions(opts: { options: TMailOptions }): void {\n const { attachmentRoot, maxAttachmentBytes } = opts.options;\n\n const buildOptionError = (details: { message: string; cause?: unknown }) => {\n return getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n error: MailErrors.INVALID_CONFIGURATION,\n message: `Invalid mail options | ${details.message}`,\n cause: details.cause,\n });\n };\n\n const isValidLimit =\n maxAttachmentBytes === undefined ||\n (Number.isSafeInteger(maxAttachmentBytes) && maxAttachmentBytes > 0);\n\n if (!isValidLimit) {\n throw buildOptionError({ message: 'maxAttachmentBytes must be a positive integer' });\n }\n\n if (attachmentRoot === undefined) {\n return;\n }\n\n if (typeof attachmentRoot !== 'string' || !isAbsolute(attachmentRoot)) {\n throw buildOptionError({ message: 'attachmentRoot must be an absolute path' });\n }\n\n let isDirectory: boolean;\n\n try {\n isDirectory = statSync(attachmentRoot).isDirectory();\n } catch (error) {\n throw buildOptionError({\n message: 'attachmentRoot must be an existing directory',\n cause: error,\n });\n }\n\n if (!isDirectory) {\n throw buildOptionError({ message: 'attachmentRoot must be an existing directory' });\n }\n }\n\n createAndBindInstances(): void {\n // Transport\n const transportGetter = this.application.get<TGetMailTransportFn>({\n key: MailKeys.MAIL_TRANSPORT_PROVIDER,\n });\n const mailOptions = this.application.get<TMailOptions>({ key: MailKeys.MAIL_OPTIONS });\n this.validateAttachmentOptions({ options: mailOptions });\n\n // Only the provider is logged: the options carry SMTP / API credentials, which must never reach a log sink.\n this.logger\n .for(this.createAndBindInstances.name)\n .info('Mail provider: %s', mailOptions.provider);\n\n const mailTransportInstance = transportGetter(mailOptions);\n this.application.bind({ key: MailKeys.MAIL_TRANSPORT_INSTANCE }).toValue(mailTransportInstance);\n\n // Queue\n const queueGetter = this.application.get<TGetMailQueueExecutorFn>({\n key: MailKeys.MAIL_QUEUE_EXECUTOR_PROVIDER,\n });\n\n // Queueing is opt-in: with no executor config bound, fall back to the direct (inline) executor instead of a \"binding is not bounded\" crash at boot.\n const queueConfig = this.application.get<TMailQueueExecutorConfig>({\n key: MailKeys.MAIL_QUEUE_EXECUTOR_CONFIG,\n isOptional: true,\n }) ?? { type: MailQueueExecutorTypes.DIRECT };\n\n // Same reason as above: a bullmq config carries the Redis password.\n this.logger\n .for(this.createAndBindInstances.name)\n .info('Mail queue executor type: %s', queueConfig.type);\n\n const queueExecutorInstance = queueGetter(queueConfig);\n this.application\n .bind({ key: MailKeys.MAIL_QUEUE_EXECUTOR_INSTANCE })\n .toValue(queueExecutorInstance);\n\n // Workers, timers and SMTP pools outlive the application unless something closes them. Executor first, so a job in flight finishes against a live transport.\n this.application.registerPostStopHook({\n identifier: 'mail.queue-executor.close',\n hook: () => queueExecutorInstance.close?.(),\n });\n this.application.registerPostStopHook({\n identifier: 'mail.transport.close',\n hook: () => mailTransportInstance.close?.(),\n });\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseHelper, getError } from '@venizia/ignis-helpers/core';
|
|
2
2
|
import { BullMQHelper } from '@venizia/ignis-helpers/bullmq';
|
|
3
|
-
import { BullMQExecutorModes, MailBackoffTypes, MailErrorCodes, MailExecutorErrors, } from '../../common/index.js';
|
|
3
|
+
import { BullMQExecutorModes, MailBackoffTypes, MailDefaults, MailErrorCodes, MailExecutorErrors, MailQueueJobNames, } from '../../common/index.js';
|
|
4
4
|
/** 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. */
|
|
5
5
|
export class BullMQMailExecutorHelper extends BaseHelper {
|
|
6
6
|
constructor(opts) {
|
|
@@ -77,7 +77,7 @@ export class BullMQMailExecutorHelper extends BaseHelper {
|
|
|
77
77
|
numberOfWorker: concurrency,
|
|
78
78
|
lockDuration,
|
|
79
79
|
onWorkerData: async (job) => {
|
|
80
|
-
const maxAttempts = job.data.options?.attempts ??
|
|
80
|
+
const maxAttempts = job.data.options?.attempts ?? MailDefaults.ATTEMPTS;
|
|
81
81
|
this.logger
|
|
82
82
|
.for('onWorkerData')
|
|
83
83
|
.info('Processing job | Worker: %s | jobId: %s | email: %s | attempt: %d/%d', workerIdentifier, job.data.id, job.data.email, job.attemptsMade + 1, maxAttempts);
|
|
@@ -105,7 +105,7 @@ export class BullMQMailExecutorHelper extends BaseHelper {
|
|
|
105
105
|
},
|
|
106
106
|
onWorkerDataFail: async (job, error) => {
|
|
107
107
|
if (job) {
|
|
108
|
-
const maxAttempts = job.data.options?.attempts ??
|
|
108
|
+
const maxAttempts = job.data.options?.attempts ?? MailDefaults.ATTEMPTS;
|
|
109
109
|
this.logger
|
|
110
110
|
.for('onWorkerDataFail')
|
|
111
111
|
.error('Job failed | Worker: %s | jobId: %s | email: %s | attempt: %d/%d | error: %s', workerIdentifier, job.data.id, job.data.email, job.attemptsMade, maxAttempts, error.message);
|
|
@@ -127,9 +127,9 @@ export class BullMQMailExecutorHelper extends BaseHelper {
|
|
|
127
127
|
this.logger.for(this.removeWorker.name).warn('Invalid worker index: %d', index);
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
|
-
// 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.
|
|
130
|
+
// 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.
|
|
131
131
|
const [workerHelper] = this.workerHelpers.splice(index, 1);
|
|
132
|
-
await workerHelper.
|
|
132
|
+
await workerHelper.close();
|
|
133
133
|
this.logger
|
|
134
134
|
.for(this.removeWorker.name)
|
|
135
135
|
.info('Worker removed | Index: %d | Remaining workers: %d', index, this.workerHelpers.length);
|
|
@@ -139,7 +139,7 @@ export class BullMQMailExecutorHelper extends BaseHelper {
|
|
|
139
139
|
async closeWorkers() {
|
|
140
140
|
const workerHelpers = this.workerHelpers;
|
|
141
141
|
this.workerHelpers = [];
|
|
142
|
-
const results = await Promise.allSettled(workerHelpers.map((workerHelper) => workerHelper.
|
|
142
|
+
const results = await Promise.allSettled(workerHelpers.map((workerHelper) => workerHelper.close()));
|
|
143
143
|
const failures = [];
|
|
144
144
|
for (const result of results) {
|
|
145
145
|
if (result.status !== 'rejected') {
|
|
@@ -164,7 +164,7 @@ export class BullMQMailExecutorHelper extends BaseHelper {
|
|
|
164
164
|
const failures = [...result];
|
|
165
165
|
if (this.queueHelper) {
|
|
166
166
|
try {
|
|
167
|
-
await this.queueHelper.
|
|
167
|
+
await this.queueHelper.close();
|
|
168
168
|
}
|
|
169
169
|
catch (error) {
|
|
170
170
|
const closeError = error instanceof Error ? error : getError({ message: String(error) });
|
|
@@ -211,17 +211,18 @@ export class BullMQMailExecutorHelper extends BaseHelper {
|
|
|
211
211
|
};
|
|
212
212
|
this.logger
|
|
213
213
|
.for(this.enqueueVerificationEmail.name)
|
|
214
|
-
.
|
|
215
|
-
const bullJob = await this.queueHelper.queue.add(
|
|
214
|
+
.debug('Queuing email to BullMQ/Redis | jobId: %s | mode: %s', jobId, this.mode);
|
|
215
|
+
const bullJob = await this.queueHelper.queue.add(MailQueueJobNames.SEND_VERIFICATION_EMAIL, job, {
|
|
216
216
|
priority: options?.priority,
|
|
217
217
|
delay: options?.delay,
|
|
218
|
-
attempts: options?.attempts ??
|
|
218
|
+
attempts: options?.attempts ?? MailDefaults.ATTEMPTS,
|
|
219
219
|
backoff: {
|
|
220
220
|
type: options?.backoff?.type ?? MailBackoffTypes.EXPONENTIAL,
|
|
221
|
-
delay: options?.backoff?.delay ??
|
|
221
|
+
delay: options?.backoff?.delay ?? MailDefaults.BACKOFF_DELAY_MS,
|
|
222
222
|
},
|
|
223
223
|
removeOnComplete: true,
|
|
224
|
-
|
|
224
|
+
// Bounded: a failed job holds the recipient's address, and `false` kept every one forever.
|
|
225
|
+
removeOnFail: MailDefaults.FAILED_JOB_RETENTION,
|
|
225
226
|
});
|
|
226
227
|
return {
|
|
227
228
|
jobId: bullJob.id ?? jobId,
|