@venizia/ignis 0.4.8-16 → 0.4.8-17

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.
Files changed (48) hide show
  1. package/dist/esm/base/applications/base.js.map +1 -1
  2. package/dist/esm/components/api-reference/common/types.d.ts +4 -1
  3. package/dist/esm/components/api-reference/common/types.js.map +1 -1
  4. package/dist/esm/components/api-reference/component.js +8 -3
  5. package/dist/esm/components/api-reference/component.js.map +1 -1
  6. package/dist/esm/components/auth/authenticate/component.js +2 -1
  7. package/dist/esm/components/auth/authenticate/component.js.map +1 -1
  8. package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +2 -2
  9. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.d.ts +1 -1
  10. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
  11. package/dist/esm/components/auth/authorize/adapters/common/types.d.ts +1 -2
  12. package/dist/esm/components/auth/authorize/adapters/common/types.js.map +1 -1
  13. package/dist/esm/components/mail/common/types/options.d.ts +54 -10
  14. package/dist/esm/components/mail/common/types/options.js.map +1 -1
  15. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +7 -2
  16. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
  17. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.d.ts +2 -3
  18. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
  19. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.d.ts +2 -3
  20. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
  21. package/dist/esm/components/mail/services/mail.service.d.ts +1 -2
  22. package/dist/esm/components/mail/services/mail.service.js.map +1 -1
  23. package/dist/esm/components/mail/services/template.service.d.ts +3 -4
  24. package/dist/esm/components/mail/services/template.service.js +1 -1
  25. package/dist/esm/components/mail/services/template.service.js.map +1 -1
  26. package/dist/esm/components/mail/utilities/header.utility.d.ts +1 -1
  27. package/dist/esm/components/mail/utilities/header.utility.js +1 -1
  28. package/dist/esm/components/mail/utilities/header.utility.js.map +1 -1
  29. package/dist/esm/components/mail/utilities/type.utility.d.ts +2 -3
  30. package/dist/esm/components/mail/utilities/type.utility.js +6 -7
  31. package/dist/esm/components/mail/utilities/type.utility.js.map +1 -1
  32. package/dist/esm/components/static-asset/common/types.d.ts +35 -13
  33. package/dist/esm/components/static-asset/common/types.js.map +1 -1
  34. package/dist/esm/components/static-asset/controller/factory.d.ts +2 -2
  35. package/dist/esm/components/static-asset/controller/routes/context.d.ts +4 -3
  36. package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -1
  37. package/dist/esm/components/static-asset/utilities/meta-link.utility.d.ts +5 -5
  38. package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -1
  39. package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +3 -11
  40. package/dist/esm/components/static-asset/utilities/toggle.utility.js +3 -14
  41. package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -1
  42. package/dist/esm/testing/assert-application-boots.d.ts +2 -2
  43. package/dist/esm/testing/assert-application-boots.js +6 -2
  44. package/dist/esm/testing/assert-application-boots.js.map +1 -1
  45. package/dist/presets/app/preset.json +4 -4
  46. package/dist/presets/lib/preset.json +3 -3
  47. package/dist/presets/shared/preset.json +1 -1
  48. package/package.json +8 -8
@@ -1,5 +1,4 @@
1
1
  import type { IdType } from '../../../../../base/index.js';
2
- import type { AnyType } from '@venizia/ignis-helpers/common';
3
2
  import type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
4
3
  /** Filter passed to loadFilteredPolicy: which principal's policies to load. */
5
4
  export interface ICasbinPolicyFilter {
@@ -9,7 +8,7 @@ export interface ICasbinPolicyFilter {
9
8
  };
10
9
  }
11
10
  /** Drizzle connector for policy queries, typed on the shared `PgDatabase` base so postgres-js fits too. Declared here rather than imported from `@/connectors/postgres`: components depend on a minimal local contract, never a connector class. */
12
- export type TCasbinPolicyConnector = PgDatabase<PgQueryResultHKT, Record<string, AnyType>>;
11
+ export type TCasbinPolicyConnector = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;
13
12
  /** Minimal source the adapters depend on - any drizzle-backed datasource satisfies it. */
14
13
  export interface ICasbinPolicySource {
15
14
  /** A datasource that opens on first use opens here; one that opens at start resolves at once. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authorize/adapters/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { IdType } from '@/base';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';\n\n/** Filter passed to loadFilteredPolicy: which principal's policies to load. */\nexport interface ICasbinPolicyFilter {\n principal: { type: string; id: IdType };\n}\n\n/** Drizzle connector for policy queries, typed on the shared `PgDatabase` base so postgres-js fits too. Declared here rather than imported from `@/connectors/postgres`: components depend on a minimal local contract, never a connector class. */\nexport type TCasbinPolicyConnector = PgDatabase<PgQueryResultHKT, Record<string, AnyType>>;\n\n/** Minimal source the adapters depend on - any drizzle-backed datasource satisfies it. */\nexport interface ICasbinPolicySource {\n /** A datasource that opens on first use opens here; one that opens at start resolves at once. */\n ensureOpen?(): Promise<void>;\n\n /** Preferred: lazily wires the driver on first read and survives pool rotation, mirroring repositories. */\n getConnector?(): TCasbinPolicyConnector;\n\n /** Back-compat: a pre-wired connector. Prefer getConnector on a real datasource. */\n connector?: TCasbinPolicyConnector;\n}\n\n/** Maps a logical table onto its physical name + schema. */\nexport interface IScopedCasbinTable {\n tableName: string;\n schemaName?: string;\n}\n\n/** All physical mapping the ScopedCasbinAdapter needs. App provides this; framework stays decoupled. */\nexport interface IScopedCasbinEntities {\n policyDefinition: IScopedCasbinTable & {\n metadata?: { columnName: string };\n };\n\n /** Permission catalog (id, code, ...). */\n permission: IScopedCasbinTable;\n\n /** Principal type labels used as casbin name prefixes. */\n principals: { user: string; role: string };\n\n /** Domain type labels (e.g. ['Merchant', 'Organizer']). */\n domainTypes: string[];\n\n /** Soft-delete handling for both tables. */\n softDelete?: { use: false } | { use: true; columnName: string };\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authorize/adapters/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { IdType } from '@/base';\nimport type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';\n\n/** Filter passed to loadFilteredPolicy: which principal's policies to load. */\nexport interface ICasbinPolicyFilter {\n principal: { type: string; id: IdType };\n}\n\n/** Drizzle connector for policy queries, typed on the shared `PgDatabase` base so postgres-js fits too. Declared here rather than imported from `@/connectors/postgres`: components depend on a minimal local contract, never a connector class. */\nexport type TCasbinPolicyConnector = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;\n\n/** Minimal source the adapters depend on - any drizzle-backed datasource satisfies it. */\nexport interface ICasbinPolicySource {\n /** A datasource that opens on first use opens here; one that opens at start resolves at once. */\n ensureOpen?(): Promise<void>;\n\n /** Preferred: lazily wires the driver on first read and survives pool rotation, mirroring repositories. */\n getConnector?(): TCasbinPolicyConnector;\n\n /** Back-compat: a pre-wired connector. Prefer getConnector on a real datasource. */\n connector?: TCasbinPolicyConnector;\n}\n\n/** Maps a logical table onto its physical name + schema. */\nexport interface IScopedCasbinTable {\n tableName: string;\n schemaName?: string;\n}\n\n/** All physical mapping the ScopedCasbinAdapter needs. App provides this; framework stays decoupled. */\nexport interface IScopedCasbinEntities {\n policyDefinition: IScopedCasbinTable & {\n metadata?: { columnName: string };\n };\n\n /** Permission catalog (id, code, ...). */\n permission: IScopedCasbinTable;\n\n /** Principal type labels used as casbin name prefixes. */\n principals: { user: string; role: string };\n\n /** Domain type labels (e.g. ['Merchant', 'Organizer']). */\n domainTypes: string[];\n\n /** Soft-delete handling for both tables. */\n softDelete?: { use: false } | { use: true; columnName: string };\n}\n"]}
@@ -1,4 +1,3 @@
1
- import type { AnyType } from '@venizia/ignis-helpers/common';
2
1
  import type SMTPTransport from 'nodemailer/lib/smtp-transport';
3
2
  import type { IMailTransport } from './message.js';
4
3
  /** Options shared by every mail provider. */
@@ -48,15 +47,19 @@ export interface ICustomMailOptions extends IBaseMailOptions {
48
47
  /** Mail options with an arbitrary provider name and config; accepted by the type, but the transport provider throws on a name it does not support. */
49
48
  export interface IGenericMailOptions extends IBaseMailOptions {
50
49
  provider: string;
51
- config: Record<string, AnyType>;
50
+ config: Record<string, unknown>;
52
51
  }
53
52
  /** Options passed to the mail component, discriminated by `provider`. */
54
53
  export type TMailOptions = INodemailerMailOptions | IAmazonSesMailOptions | IMailgunMailOptions | ICustomMailOptions | IGenericMailOptions;
55
54
  /** Nodemailer `createTransport` argument: a transport instance, SMTP options or a connection URL. */
56
55
  export type TNodemailerConfig = SMTPTransport | SMTPTransport.Options | string;
57
- /** Mailgun client options (`mailgun.js`) plus the sending `domain`. */
58
- export type TMailgunConfig = AnyType & {
56
+ /** Mailgun client options (`mailgun.js`) plus the sending `domain`; the transport throws on a missing `username`, `key` or `domain`. */
57
+ export type TMailgunConfig = {
58
+ username: string;
59
+ key: string;
59
60
  domain: string;
61
+ url?: string;
62
+ [option: string]: unknown;
60
63
  };
61
64
  /**
62
65
  * The peer module itself, handed over by an application that already holds it. A `bun build
@@ -66,10 +69,31 @@ export type TMailgunConfig = AnyType & {
66
69
  * a compile error rather than a boot crash.
67
70
  */
68
71
  export type TNodemailerModule = {
69
- createTransport: (config: AnyType, defaults?: AnyType) => AnyType;
72
+ createTransport(config: TNodemailerConfig): INodemailerTransporter;
70
73
  };
74
+ /** The part of a `nodemailer` transporter the transport calls. */
75
+ export interface INodemailerTransporter {
76
+ sendMail(mailOptions: object): Promise<{
77
+ messageId?: string;
78
+ response?: unknown;
79
+ }>;
80
+ verify(): Promise<unknown>;
81
+ close(): void;
82
+ }
83
+ /** The result of one `mailgun.js` send; `id` is the message id. */
84
+ export interface IMailgunSendResult {
85
+ id?: string;
86
+ }
87
+ /** The part of the `mailgun.js` messages client the transport calls. */
88
+ export interface IMailgunMessagesClient {
89
+ create(domain: string, message: object): Promise<IMailgunSendResult>;
90
+ }
71
91
  /** The `mailgun.js` class, as a constructor taking the form-data implementation. */
72
- export type TMailgunModule = new (formData: AnyType) => AnyType;
92
+ export type TMailgunModule = new (formData: typeof FormData) => {
93
+ client(config: object): {
94
+ messages: IMailgunMessagesClient;
95
+ };
96
+ };
73
97
  /** Amazon SES client configuration: `region` is required; `credentials` and `endpoint` are optional. */
74
98
  export type TAmazonSesConfig = {
75
99
  region: string;
@@ -80,14 +104,34 @@ export type TAmazonSesConfig = {
80
104
  };
81
105
  endpoint?: string;
82
106
  };
107
+ /** The part of an `@aws-sdk/client-sesv2` client the transport calls; `send` resolves with the command's output. */
108
+ export interface IAmazonSesClient {
109
+ send(command: object): Promise<unknown>;
110
+ destroy?(): void;
111
+ }
112
+ /** The input of a `SendEmailCommand`: the sender, the recipients and the raw MIME body. */
113
+ export interface IAmazonSesSendEmailInput {
114
+ FromEmailAddress?: string;
115
+ Destination: {
116
+ ToAddresses: string[];
117
+ CcAddresses?: string[];
118
+ BccAddresses?: string[];
119
+ };
120
+ ReplyToAddresses?: string[];
121
+ Content: {
122
+ Raw: {
123
+ Data: Uint8Array;
124
+ };
125
+ };
126
+ }
83
127
  /** Same story as {@link TNodemailerModule} - a compiled binary hands this over explicitly since there is no `node_modules` to resolve `@aws-sdk/client-sesv2` against. */
84
- export type TAmazonSesModule<TConfig extends AnyType = AnyType, TClient extends AnyType = AnyType> = {
128
+ export type TAmazonSesModule<TConfig = TAmazonSesConfig, TClient extends IAmazonSesClient = IAmazonSesClient> = {
85
129
  SESv2Client: new (config: TConfig) => TClient;
86
- SendEmailCommand: new (input: AnyType) => AnyType;
87
- GetAccountCommand: new (input?: AnyType) => AnyType;
130
+ SendEmailCommand: new (input: IAmazonSesSendEmailInput) => object;
131
+ GetAccountCommand: new (input: object) => object;
88
132
  };
89
133
  /** An Amazon SES client with the command classes the transport sends and verifies with. */
90
134
  export type TAmazonSesClient = Pick<TAmazonSesModule, 'SendEmailCommand' | 'GetAccountCommand'> & {
91
- client: AnyType;
135
+ client: IAmazonSesClient;
92
136
  };
93
137
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../../../src/components/mail/common/types/options.ts"],"names":[],"mappings":"","sourcesContent":["import type { AnyType } from '@venizia/ignis-helpers/common';\nimport type SMTPTransport from 'nodemailer/lib/smtp-transport';\nimport type { IMailTransport } from './message';\n\n/** Options shared by every mail provider. */\nexport interface IBaseMailOptions {\n /**\n * Sender used when a message sets none.\n *\n * @default MailDefaults.FALLBACK_FROM\n */\n from?: string;\n fromName?: string;\n /**\n * The only directory an `attachment.path` may be read from; `path` is resolved against it and\n * refused if it lands outside, symlinks included. Unset, every `path` is refused.\n */\n attachmentRoot?: string;\n /**\n * Bytes of attachment content one message may carry, all attachments together.\n *\n * @default MailDefaults.MAX_ATTACHMENT_BYTES\n */\n maxAttachmentBytes?: number;\n}\n\n/** Mail options for the `nodemailer` provider; `module` hands over the `nodemailer` module instead of loading it by name. */\nexport interface INodemailerMailOptions extends IBaseMailOptions {\n provider: 'nodemailer';\n config: TNodemailerConfig;\n module?: TNodemailerModule;\n}\n\n/** Mail options for the `mailgun` provider; `config` needs `username`, `key` and `domain`, and `module` hands over the `mailgun.js` module. */\nexport interface IMailgunMailOptions extends IBaseMailOptions {\n provider: 'mailgun';\n config: TMailgunConfig;\n module?: TMailgunModule;\n}\n\n/** Mail options for the `amazon-ses` provider (SES HTTPS API); use `nodemailer` for SES over SMTP. */\nexport interface IAmazonSesMailOptions extends IBaseMailOptions {\n provider: 'amazon-ses';\n config: TAmazonSesConfig;\n module?: TAmazonSesModule;\n}\n\n/** Mail options for the `custom` provider; `config` is the transport to use as is. */\nexport interface ICustomMailOptions extends IBaseMailOptions {\n provider: 'custom';\n config: IMailTransport;\n}\n\n/** Mail options with an arbitrary provider name and config; accepted by the type, but the transport provider throws on a name it does not support. */\nexport interface IGenericMailOptions extends IBaseMailOptions {\n provider: string;\n config: Record<string, AnyType>;\n}\n\n/** Options passed to the mail component, discriminated by `provider`. */\nexport type TMailOptions =\n | INodemailerMailOptions\n | IAmazonSesMailOptions\n | IMailgunMailOptions\n | ICustomMailOptions\n | IGenericMailOptions;\n\n/** Nodemailer `createTransport` argument: a transport instance, SMTP options or a connection URL. */\nexport type TNodemailerConfig = SMTPTransport | SMTPTransport.Options | string;\n\n// MailgunClientOptions & {domain: string}\n/** Mailgun client options (`mailgun.js`) plus the sending `domain`. */\nexport type TMailgunConfig = AnyType & { domain: string };\n\n/**\n * The peer module itself, handed over by an application that already holds it. A `bun build\n * --compile` binary carries no `node_modules`, so the runtime lookup these transports fall back to\n * has nothing to resolve against - passing the module through the options is what a compiled\n * application does instead. Typed as the shape each transport actually uses, so a wrong module is\n * a compile error rather than a boot crash.\n */\nexport type TNodemailerModule = {\n createTransport: (config: AnyType, defaults?: AnyType) => AnyType;\n};\n\n/** The `mailgun.js` class, as a constructor taking the form-data implementation. */\nexport type TMailgunModule = new (formData: AnyType) => AnyType;\n\n/** Amazon SES client configuration: `region` is required; `credentials` and `endpoint` are optional. */\nexport type TAmazonSesConfig = {\n region: string;\n credentials?: { accessKeyId: string; secretAccessKey: string; sessionToken?: string };\n endpoint?: string;\n};\n\n/** Same story as {@link TNodemailerModule} - a compiled binary hands this over explicitly since there is no `node_modules` to resolve `@aws-sdk/client-sesv2` against. */\nexport type TAmazonSesModule<\n TConfig extends AnyType = AnyType,\n TClient extends AnyType = AnyType,\n> = {\n SESv2Client: new (config: TConfig) => TClient;\n SendEmailCommand: new (input: AnyType) => AnyType;\n GetAccountCommand: new (input?: AnyType) => AnyType;\n};\n\n/** An Amazon SES client with the command classes the transport sends and verifies with. */\nexport type TAmazonSesClient = Pick<TAmazonSesModule, 'SendEmailCommand' | 'GetAccountCommand'> & {\n client: AnyType;\n};\n"]}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../../../src/components/mail/common/types/options.ts"],"names":[],"mappings":"","sourcesContent":["import type SMTPTransport from 'nodemailer/lib/smtp-transport';\nimport type { IMailTransport } from './message';\n\n/** Options shared by every mail provider. */\nexport interface IBaseMailOptions {\n /**\n * Sender used when a message sets none.\n *\n * @default MailDefaults.FALLBACK_FROM\n */\n from?: string;\n fromName?: string;\n /**\n * The only directory an `attachment.path` may be read from; `path` is resolved against it and\n * refused if it lands outside, symlinks included. Unset, every `path` is refused.\n */\n attachmentRoot?: string;\n /**\n * Bytes of attachment content one message may carry, all attachments together.\n *\n * @default MailDefaults.MAX_ATTACHMENT_BYTES\n */\n maxAttachmentBytes?: number;\n}\n\n/** Mail options for the `nodemailer` provider; `module` hands over the `nodemailer` module instead of loading it by name. */\nexport interface INodemailerMailOptions extends IBaseMailOptions {\n provider: 'nodemailer';\n config: TNodemailerConfig;\n module?: TNodemailerModule;\n}\n\n/** Mail options for the `mailgun` provider; `config` needs `username`, `key` and `domain`, and `module` hands over the `mailgun.js` module. */\nexport interface IMailgunMailOptions extends IBaseMailOptions {\n provider: 'mailgun';\n config: TMailgunConfig;\n module?: TMailgunModule;\n}\n\n/** Mail options for the `amazon-ses` provider (SES HTTPS API); use `nodemailer` for SES over SMTP. */\nexport interface IAmazonSesMailOptions extends IBaseMailOptions {\n provider: 'amazon-ses';\n config: TAmazonSesConfig;\n module?: TAmazonSesModule;\n}\n\n/** Mail options for the `custom` provider; `config` is the transport to use as is. */\nexport interface ICustomMailOptions extends IBaseMailOptions {\n provider: 'custom';\n config: IMailTransport;\n}\n\n/** Mail options with an arbitrary provider name and config; accepted by the type, but the transport provider throws on a name it does not support. */\nexport interface IGenericMailOptions extends IBaseMailOptions {\n provider: string;\n config: Record<string, unknown>;\n}\n\n/** Options passed to the mail component, discriminated by `provider`. */\nexport type TMailOptions =\n | INodemailerMailOptions\n | IAmazonSesMailOptions\n | IMailgunMailOptions\n | ICustomMailOptions\n | IGenericMailOptions;\n\n/** Nodemailer `createTransport` argument: a transport instance, SMTP options or a connection URL. */\nexport type TNodemailerConfig = SMTPTransport | SMTPTransport.Options | string;\n\n/** Mailgun client options (`mailgun.js`) plus the sending `domain`; the transport throws on a missing `username`, `key` or `domain`. */\nexport type TMailgunConfig = {\n username: string;\n key: string;\n domain: string;\n url?: string;\n [option: string]: unknown;\n};\n\n/**\n * The peer module itself, handed over by an application that already holds it. A `bun build\n * --compile` binary carries no `node_modules`, so the runtime lookup these transports fall back to\n * has nothing to resolve against - passing the module through the options is what a compiled\n * application does instead. Typed as the shape each transport actually uses, so a wrong module is\n * a compile error rather than a boot crash.\n */\nexport type TNodemailerModule = {\n createTransport(config: TNodemailerConfig): INodemailerTransporter;\n};\n\n/** The part of a `nodemailer` transporter the transport calls. */\nexport interface INodemailerTransporter {\n sendMail(mailOptions: object): Promise<{ messageId?: string; response?: unknown }>;\n verify(): Promise<unknown>;\n close(): void;\n}\n\n/** The result of one `mailgun.js` send; `id` is the message id. */\nexport interface IMailgunSendResult {\n id?: string;\n}\n\n/** The part of the `mailgun.js` messages client the transport calls. */\nexport interface IMailgunMessagesClient {\n create(domain: string, message: object): Promise<IMailgunSendResult>;\n}\n\n/** The `mailgun.js` class, as a constructor taking the form-data implementation. */\nexport type TMailgunModule = new (formData: typeof FormData) => {\n client(config: object): { messages: IMailgunMessagesClient };\n};\n\n/** Amazon SES client configuration: `region` is required; `credentials` and `endpoint` are optional. */\nexport type TAmazonSesConfig = {\n region: string;\n credentials?: { accessKeyId: string; secretAccessKey: string; sessionToken?: string };\n endpoint?: string;\n};\n\n/** The part of an `@aws-sdk/client-sesv2` client the transport calls; `send` resolves with the command's output. */\nexport interface IAmazonSesClient {\n send(command: object): Promise<unknown>;\n destroy?(): void;\n}\n\n/** The input of a `SendEmailCommand`: the sender, the recipients and the raw MIME body. */\nexport interface IAmazonSesSendEmailInput {\n FromEmailAddress?: string;\n Destination: { ToAddresses: string[]; CcAddresses?: string[]; BccAddresses?: string[] };\n ReplyToAddresses?: string[];\n Content: { Raw: { Data: Uint8Array } };\n}\n\n/** Same story as {@link TNodemailerModule} - a compiled binary hands this over explicitly since there is no `node_modules` to resolve `@aws-sdk/client-sesv2` against. */\nexport type TAmazonSesModule<\n TConfig = TAmazonSesConfig,\n TClient extends IAmazonSesClient = IAmazonSesClient,\n> = {\n SESv2Client: new (config: TConfig) => TClient;\n SendEmailCommand: new (input: IAmazonSesSendEmailInput) => object;\n GetAccountCommand: new (input: object) => object;\n};\n\n/** An Amazon SES client with the command classes the transport sends and verifies with. */\nexport type TAmazonSesClient = Pick<TAmazonSesModule, 'SendEmailCommand' | 'GetAccountCommand'> & {\n client: IAmazonSesClient;\n};\n"]}
@@ -42,9 +42,12 @@ export class AmazonSesTransportHelper extends BaseHelper {
42
42
  },
43
43
  });
44
44
  const result = await this.client.send(command);
45
+ const messageId = typeof result === 'object' && result !== null
46
+ ? Reflect.get(result, 'MessageId')
47
+ : undefined;
45
48
  return {
46
49
  success: true,
47
- messageId: result.MessageId,
50
+ messageId: typeof messageId === 'string' ? messageId : undefined,
48
51
  response: result,
49
52
  };
50
53
  }
@@ -64,7 +67,9 @@ export class AmazonSesTransportHelper extends BaseHelper {
64
67
  logger.info('Verifying Amazon SES account status');
65
68
  const command = new this.getAccountCommandConstructor({});
66
69
  const result = await this.client.send(command);
67
- const enabled = result.SendingEnabled === true;
70
+ const enabled = typeof result === 'object' &&
71
+ result !== null &&
72
+ Reflect.get(result, 'SendingEnabled') === true;
68
73
  logger.info('Amazon SES account status: %s', enabled ? 'enabled' : 'disabled');
69
74
  return enabled;
70
75
  }
@@ -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,YAAY,EAAE,aAAa,EAAgB,MAAM,wBAAwB,CAAC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C;IAED,uFAAuF;IAC7E,WAAW,CAAC,MAAwB;QAC5C,MAAM,SAAS,GACb,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAAmB,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC,CAAC;QAE/F,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,WAAW,CAAC;YACvC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAC;QAEH,OAAO;YACL,MAAM;YACN,gBAAgB,EAAE,SAAS,CAAC,gBAAgB;YAC5C,iBAAiB,EAAE,SAAS,CAAC,iBAAiB;SAC/C,CAAC;IACJ,CAAC;IAED,uFAAuF;IAC/E,cAAc,CAAC,MAAwB;QAC7C,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,UAAU,EAAE,IAAI,CAAC,WAAW,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
+ {"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,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE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,cAAc,CAAC,MAAM,CAAC,CAAC;QAE5B,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEjF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,2BAA2B,GAAG,gBAAgB,CAAC;QACpD,IAAI,CAAC,4BAA4B,GAAG,iBAAiB,CAAC;IACxD,CAAC;IAED,uFAAuF;IAC7E,WAAW,CAAC,MAAwB;QAC5C,MAAM,SAAS,GACb,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAAmB,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC,CAAC;QAE/F,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,WAAW,CAAC;YACvC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAC;QAEH,OAAO;YACL,MAAM;YACN,gBAAgB,EAAE,SAAS,CAAC,gBAAgB;YAC5C,iBAAiB,EAAE,SAAS,CAAC,iBAAiB;SAC/C,CAAC;IACJ,CAAC;IAED,uFAAuF;IAC/E,cAAc,CAAC,MAAwB;QAC7C,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,UAAU,EAAE,IAAI,CAAC,WAAW,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 } from '@venizia/ignis-helpers';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport {\n MailErrors,\n type IMailMessage,\n type IMailSendResult,\n type IAmazonSesClient,\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: IAmazonSesClient;\n private sendEmailCommandConstructor: TAmazonSesClient['SendEmailCommand'];\n private getAccountCommandConstructor: TAmazonSesClient['GetAccountCommand'];\n private module?: TAmazonSesModule;\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 const messageId: unknown =\n typeof result === 'object' && result !== null\n ? Reflect.get(result, 'MessageId')\n : undefined;\n\n return {\n success: true,\n messageId: typeof messageId === 'string' ? messageId : undefined,\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 =\n typeof result === 'object' &&\n result !== null &&\n Reflect.get(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,6 +1,5 @@
1
- import type { AnyType } from '@venizia/ignis-helpers/common';
2
1
  import { BaseHelper } from '@venizia/ignis-helpers/core';
3
- import type { IMailMessage, IMailSendResult, IMailTransport, TMailgunConfig, TMailgunModule } from '../../common/index.js';
2
+ import type { IMailgunMessagesClient, IMailMessage, IMailSendResult, IMailTransport, TMailgunConfig, TMailgunModule } from '../../common/index.js';
4
3
  /** Mailgun transport (`mailgun.js`). The constructor throws when `username`, `key` or `domain` is missing. */
5
4
  export declare class MailgunTransportHelper extends BaseHelper implements IMailTransport {
6
5
  private client;
@@ -14,7 +13,7 @@ export declare class MailgunTransportHelper extends BaseHelper implements IMailT
14
13
  /** Credentials and domain are checked here, not on the first send; the error never echoes a credential value back. */
15
14
  private validateConfig;
16
15
  /** Client factory seam - overridden in tests to run the helper without the mailgun.js peer. */
17
- protected buildClient(config: TMailgunConfig): AnyType;
16
+ protected buildClient(config: TMailgunConfig): IMailgunMessagesClient;
18
17
  send(message: IMailMessage): Promise<IMailSendResult>;
19
18
  verify(): Promise<boolean>;
20
19
  }
@@ -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,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AASrE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE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Type } 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
+ {"version":3,"file":"mailgun-transporter.helper.js","sourceR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,IAAI,CAAC,8CAA8C,CAAC,CAAC;YAEvF,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,qCAAqC,EAAE,KAAK,CAAC,CAAC;YAEtF,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF","sourcesContent":["import { HTTP } 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 IMailgunMessagesClient,\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: IMailgunMessagesClient;\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): IMailgunMessagesClient {\n const Mailgun = this.module ?? ModuleUtility.loadSync<TMailgunModule>({ 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: Record<string, unknown> = {\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 = 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,6 +1,5 @@
1
- import type { AnyType } from '@venizia/ignis-helpers/common';
2
1
  import { BaseHelper } from '@venizia/ignis-helpers/core';
3
- import type { IMailMessage, IMailSendResult, IMailTransport, TNodemailerConfig, TNodemailerModule } from '../../common/index.js';
2
+ import type { IMailMessage, IMailSendResult, IMailTransport, INodemailerTransporter, TNodemailerConfig, TNodemailerModule } from '../../common/index.js';
4
3
  /** SMTP transport on `nodemailer`, with its file and URL access switched off. */
5
4
  export declare class NodemailerTransportHelper extends BaseHelper implements IMailTransport {
6
5
  private transporter;
@@ -11,7 +10,7 @@ export declare class NodemailerTransportHelper extends BaseHelper implements IMa
11
10
  });
12
11
  configure(config: TNodemailerConfig): void;
13
12
  /** Client factory seam - overridden in tests to run the helper without a real SMTP client. */
14
- protected buildTransporter(config: TNodemailerConfig): AnyType;
13
+ protected buildTransporter(config: TNodemailerConfig): INodemailerTransporter;
15
14
  send(message: IMailMessage): Promise<IMailSendResult>;
16
15
  verify(): Promise<boolean>;
17
16
  close(): Promise<void>;
@@ -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,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAQrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,M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IAAI,CAAC,2BAA2B,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
+ {"version":3,"file":"nodemail-transporter.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/transporters/nodemail-transporter.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAA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AC;QACJ,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,2BAA2B,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 { BaseHelper } from '@venizia/ignis-helpers/core';\nimport { ErrorUtility, ModuleUtility } from '@venizia/ignis-helpers';\nimport type {\n IMailMessage,\n IMailSendResult,\n IMailTransport,\n INodemailerTransporter,\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: INodemailerTransporter;\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): INodemailerTransporter {\n const nodemailer =\n this.module ?? ModuleUtility.loadSync<TNodemailerModule>({ 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,6 +1,5 @@
1
1
  import { BaseService } from '@venizia/ignis-kernel';
2
2
  import type { IMailMessage, IMailSendResult, IMailService, IMailTemplateEngine, IMailTransport, TMailOptions } from '../common/index.js';
3
- import { type AnyType } from '@venizia/ignis-helpers/common';
4
3
  /** Sends mail through the bound transport. `send` validates the message, applies the attachment policy and defaults `from`; failures are thrown as application errors with a mail message code, except `sendBatch`, which reports each failure in its result. */
5
4
  export declare class MailService extends BaseService implements IMailService {
6
5
  protected options: TMailOptions;
@@ -13,7 +12,7 @@ export declare class MailService extends BaseService implements IMailService {
13
12
  }): Promise<IMailSendResult[]>;
14
13
  sendTemplate(opts: {
15
14
  templateName: string;
16
- data: Record<string, AnyType>;
15
+ data: Record<string, unknown>;
17
16
  recipients: string | string[];
18
17
  options?: Partial<IMailMessage>;
19
18
  }): Promise<IMailSendResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"mail.service.js","sourceRoot":"","sources":["../../../../../src/components/mail/services/mail.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AASpD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACpG,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,iQ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,CAAC,uBAAuB,EAAE,CAAC,CAAA;IAEjD,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,oBAAoB,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAA;;GANxD,WAAW,CA8NvB","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { BaseService } from '@venizia/ignis-kernel';\nimport type {\n IMailMessage,\n IMailSendResult,\n IMailService,\n IMailTemplateEngine,\n IMailTransport,\n TMailOptions,\n} from '../common';\nimport { MailDefaults, MailErrorCodes, MailErrors, MailKeys, MailTemplateFormats } from '../common';\nimport { inject } from '@/base/metadata';\nimport { getError, isApplicationError } from '@venizia/ignis-helpers/core';\nimport { type AnyType } from '@venizia/ignis-helpers/common';\nimport { ErrorUtility, PromiseUtility } from '@venizia/ignis-helpers';\nimport { MailAttachmentUtility } from '../utilities/attachment.utility';\nimport { MailBodyUtility } from '../utilities/body.utility';\nimport { MailHeaderUtility } from '../utilities/header.utility';\nimport { MailMimeUtility } from '../utilities/mime.utility';\n\n/** Sends mail through the bound transport. `send` validates the message, applies the attachment policy and defaults `from`; failures are thrown as application errors with a mail message code, except `sendBatch`, which reports each failure in its result. */\nexport class MailService extends BaseService implements IMailService {\n constructor(\n @inject({ key: MailKeys.MAIL_OPTIONS })\n protected options: TMailOptions,\n @inject({ key: MailKeys.MAIL_TRANSPORT_INSTANCE })\n protected transport: IMailTransport,\n @inject({ key: MailKeys.MAIL_TEMPLATE_ENGINE, isOptional: true })\n protected templateEngine?: IMailTemplateEngine,\n ) {\n super({ scope: MailService.name });\n this.logger\n .for(this.constructor.name)\n .info('Mail service initialized with provider: %s', this.options.provider);\n }\n\n async send(message: IMailMessage): Promise<IMailSendResult> {\n try {\n this.validateMessage(message);\n\n const emailMessage: IMailMessage = {\n ...message,\n from: message.from ?? this.getDefaultFrom(),\n };\n\n // The one place the attachment policy applies: every transport receives bytes, never a path.\n if (message.attachments) {\n const result2 = await MailAttachmentUtility.resolve({\n attachments: message.attachments,\n attachmentRoot: this.options.attachmentRoot,\n maxBytes: this.options.maxAttachmentBytes ?? MailDefaults.MAX_ATTACHMENT_BYTES,\n });\n emailMessage.attachments = result2;\n }\n\n this.logger.for(this.send.name).debug('Sending email to: %s', emailMessage.to);\n const result = await this.transport.send(emailMessage);\n\n if (result.success) {\n this.logger\n .for(this.send.name)\n .debug('Email sent successfully. MessageId: %s', result.messageId);\n } else {\n this.logger.for(this.send.name).debug('Email send failed: %s', result.error);\n }\n\n return result;\n } catch (error) {\n this.logger.for(this.send.name).error('Error sending email: %s', error);\n MailAttachmentUtility.release({ attachments: message.attachments });\n\n // An error the framework already shaped carries its own status and message code; re-wrapping as 500 would report a caller mistake as a server fault.\n if (isApplicationError(error)) {\n throw error;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.SEND_FAILED,\n // The raw text can carry a file path or a provider detail; it rides in `cause`, which only development responses show.\n message: 'Failed to send email',\n cause: error,\n });\n }\n }\n\n async sendBatch(\n messages: IMailMessage[],\n options?: { concurrency?: number },\n ): Promise<IMailSendResult[]> {\n try {\n const concurrency = options?.concurrency ?? MailDefaults.BATCH_CONCURRENCY;\n this.logger\n .for(this.sendBatch.name)\n .info('Sending batch of %d emails with concurrency: %d', messages.length, concurrency);\n\n const tasks = messages.map((message) => async () => {\n try {\n const result = await this.send(message);\n\n return result;\n } catch (error) {\n return {\n success: false,\n error: ErrorUtility.toError({ error }).message,\n };\n }\n });\n\n const results = await PromiseUtility.executeWithLimit<IMailSendResult>({\n tasks,\n limit: concurrency,\n });\n\n const successCount = results.filter((r) => r.success).length;\n this.logger\n .for(this.sendBatch.name)\n .info(\n 'Batch send completed. Success: %d, Failed: %d',\n successCount,\n results.length - successCount,\n );\n\n return results;\n } catch (error) {\n this.logger.for(this.sendBatch.name).error('Error sending batch emails: %s', error);\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.BATCH_SEND_FAILED,\n message: 'Failed to send batch emails',\n cause: error,\n });\n }\n }\n\n async sendTemplate(opts: {\n templateName: string;\n data: Record<string, AnyType>;\n recipients: string | string[];\n options?: Partial<IMailMessage>;\n }): Promise<IMailSendResult> {\n const { templateName, data, recipients, options } = opts;\n\n try {\n if (!this.templateEngine) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n error: MailErrors.INVALID_CONFIGURATION,\n message: 'Template engine not configured',\n });\n }\n\n // `rest` goes first below: the recipients, the subject and the body this call rendered are not the options' to replace, and `requireValidate` is a render switch, not a message field.\n const { requireValidate, subject, ...rest } = options ?? {};\n\n this.logger.for(this.sendTemplate.name).debug('Rendering template: %s', templateName);\n const html = this.templateEngine.render({ templateName, data, requireValidate });\n\n const templateData = this.templateEngine.getTemplate(templateName);\n const renderedSubject =\n templateData?.subject === undefined\n ? MailDefaults.SUBJECT\n : this.templateEngine.render({\n templateData: templateData.subject,\n data,\n requireValidate,\n format: MailTemplateFormats.TEXT,\n });\n\n const message: IMailMessage = {\n ...rest,\n to: recipients,\n subject: subject ?? renderedSubject,\n html,\n };\n\n const result = await this.send(message);\n\n return result;\n } catch (error) {\n this.logger.for(this.sendTemplate.name).error('Error sending template email: %s', error);\n throw error;\n }\n }\n\n async verify(): Promise<boolean> {\n try {\n this.logger.for(this.verify.name).debug('Verifying mail transport connection');\n const isValid = await this.transport.verify();\n this.logger.for(this.verify.name).debug('Verification result: %s', isValid);\n\n return isValid;\n } catch (error) {\n this.logger.for(this.verify.name).error('Verification failed: %s', error);\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.VERIFICATION_FAILED,\n message: 'Mail transport verification failed',\n cause: error,\n });\n }\n }\n\n protected validateMessage(message: IMailMessage): void {\n if (!message.to || (Array.isArray(message.to) && message.to.length === 0)) {\n throw getError({\n error: MailErrors.INVALID_RECIPIENT,\n message: 'Recipient email address is required',\n });\n }\n\n if (!message.subject) {\n throw getError({\n error: MailErrors.INVALID_CONFIGURATION,\n message: 'Email subject is required',\n });\n }\n\n if (!message.text && !message.html) {\n throw getError({\n error: MailErrors.INVALID_CONFIGURATION,\n message: 'Email must have either text or html content',\n });\n }\n\n MailBodyUtility.assertIsText({ message });\n MailHeaderUtility.assert({ message });\n }\n\n protected getDefaultFrom(): string {\n const { from, fromName } = this.options;\n\n // A display name is only renderable around an address: `\"Name\" <undefined>` is not a sender.\n if (!from) {\n return MailDefaults.FALLBACK_FROM;\n }\n\n if (!fromName) {\n return from;\n }\n\n return `\"${MailMimeUtility.escapeQuotedString({ value: fromName })}\" <${from}>`;\n }\n}\n"]}
1
+ {"version":3,"file":"mail.service.js","sourceRoot":"","sources":["../../../../../src/components/mail/services/mail.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AASpD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACpG,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,iQAAiQ;AACjQ,IAAa,WAAW,mBAAxB,MAAa,WAAY,SAAQ,WAAW;IAC1C,YAEY,OAAqB,EAErB,SAAyB,EAEzB,cAAoC;QAE9C,KAAK,CAAC,EAAE,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C,CAAA;;GANxD,WAAW,CA8NvB","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { BaseService } from '@venizia/ignis-kernel';\nimport type {\n IMailMessage,\n IMailSendResult,\n IMailService,\n IMailTemplateEngine,\n IMailTransport,\n TMailOptions,\n} from '../common';\nimport { MailDefaults, MailErrorCodes, MailErrors, MailKeys, MailTemplateFormats } from '../common';\nimport { inject } from '@/base/metadata';\nimport { getError, isApplicationError } from '@venizia/ignis-helpers/core';\nimport { ErrorUtility, PromiseUtility } from '@venizia/ignis-helpers';\nimport { MailAttachmentUtility } from '../utilities/attachment.utility';\nimport { MailBodyUtility } from '../utilities/body.utility';\nimport { MailHeaderUtility } from '../utilities/header.utility';\nimport { MailMimeUtility } from '../utilities/mime.utility';\n\n/** Sends mail through the bound transport. `send` validates the message, applies the attachment policy and defaults `from`; failures are thrown as application errors with a mail message code, except `sendBatch`, which reports each failure in its result. */\nexport class MailService extends BaseService implements IMailService {\n constructor(\n @inject({ key: MailKeys.MAIL_OPTIONS })\n protected options: TMailOptions,\n @inject({ key: MailKeys.MAIL_TRANSPORT_INSTANCE })\n protected transport: IMailTransport,\n @inject({ key: MailKeys.MAIL_TEMPLATE_ENGINE, isOptional: true })\n protected templateEngine?: IMailTemplateEngine,\n ) {\n super({ scope: MailService.name });\n this.logger\n .for(this.constructor.name)\n .info('Mail service initialized with provider: %s', this.options.provider);\n }\n\n async send(message: IMailMessage): Promise<IMailSendResult> {\n try {\n this.validateMessage(message);\n\n const emailMessage: IMailMessage = {\n ...message,\n from: message.from ?? this.getDefaultFrom(),\n };\n\n // The one place the attachment policy applies: every transport receives bytes, never a path.\n if (message.attachments) {\n const result2 = await MailAttachmentUtility.resolve({\n attachments: message.attachments,\n attachmentRoot: this.options.attachmentRoot,\n maxBytes: this.options.maxAttachmentBytes ?? MailDefaults.MAX_ATTACHMENT_BYTES,\n });\n emailMessage.attachments = result2;\n }\n\n this.logger.for(this.send.name).debug('Sending email to: %s', emailMessage.to);\n const result = await this.transport.send(emailMessage);\n\n if (result.success) {\n this.logger\n .for(this.send.name)\n .debug('Email sent successfully. MessageId: %s', result.messageId);\n } else {\n this.logger.for(this.send.name).debug('Email send failed: %s', result.error);\n }\n\n return result;\n } catch (error) {\n this.logger.for(this.send.name).error('Error sending email: %s', error);\n MailAttachmentUtility.release({ attachments: message.attachments });\n\n // An error the framework already shaped carries its own status and message code; re-wrapping as 500 would report a caller mistake as a server fault.\n if (isApplicationError(error)) {\n throw error;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.SEND_FAILED,\n // The raw text can carry a file path or a provider detail; it rides in `cause`, which only development responses show.\n message: 'Failed to send email',\n cause: error,\n });\n }\n }\n\n async sendBatch(\n messages: IMailMessage[],\n options?: { concurrency?: number },\n ): Promise<IMailSendResult[]> {\n try {\n const concurrency = options?.concurrency ?? MailDefaults.BATCH_CONCURRENCY;\n this.logger\n .for(this.sendBatch.name)\n .info('Sending batch of %d emails with concurrency: %d', messages.length, concurrency);\n\n const tasks = messages.map((message) => async () => {\n try {\n const result = await this.send(message);\n\n return result;\n } catch (error) {\n return {\n success: false,\n error: ErrorUtility.toError({ error }).message,\n };\n }\n });\n\n const results = await PromiseUtility.executeWithLimit<IMailSendResult>({\n tasks,\n limit: concurrency,\n });\n\n const successCount = results.filter((r) => r.success).length;\n this.logger\n .for(this.sendBatch.name)\n .info(\n 'Batch send completed. Success: %d, Failed: %d',\n successCount,\n results.length - successCount,\n );\n\n return results;\n } catch (error) {\n this.logger.for(this.sendBatch.name).error('Error sending batch emails: %s', error);\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.BATCH_SEND_FAILED,\n message: 'Failed to send batch emails',\n cause: error,\n });\n }\n }\n\n async sendTemplate(opts: {\n templateName: string;\n data: Record<string, unknown>;\n recipients: string | string[];\n options?: Partial<IMailMessage>;\n }): Promise<IMailSendResult> {\n const { templateName, data, recipients, options } = opts;\n\n try {\n if (!this.templateEngine) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n error: MailErrors.INVALID_CONFIGURATION,\n message: 'Template engine not configured',\n });\n }\n\n // `rest` goes first below: the recipients, the subject and the body this call rendered are not the options' to replace, and `requireValidate` is a render switch, not a message field.\n const { requireValidate, subject, ...rest } = options ?? {};\n\n this.logger.for(this.sendTemplate.name).debug('Rendering template: %s', templateName);\n const html = this.templateEngine.render({ templateName, data, requireValidate });\n\n const templateData = this.templateEngine.getTemplate(templateName);\n const renderedSubject =\n templateData?.subject === undefined\n ? MailDefaults.SUBJECT\n : this.templateEngine.render({\n templateData: templateData.subject,\n data,\n requireValidate,\n format: MailTemplateFormats.TEXT,\n });\n\n const message: IMailMessage = {\n ...rest,\n to: recipients,\n subject: subject ?? renderedSubject,\n html,\n };\n\n const result = await this.send(message);\n\n return result;\n } catch (error) {\n this.logger.for(this.sendTemplate.name).error('Error sending template email: %s', error);\n throw error;\n }\n }\n\n async verify(): Promise<boolean> {\n try {\n this.logger.for(this.verify.name).debug('Verifying mail transport connection');\n const isValid = await this.transport.verify();\n this.logger.for(this.verify.name).debug('Verification result: %s', isValid);\n\n return isValid;\n } catch (error) {\n this.logger.for(this.verify.name).error('Verification failed: %s', error);\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.VERIFICATION_FAILED,\n message: 'Mail transport verification failed',\n cause: error,\n });\n }\n }\n\n protected validateMessage(message: IMailMessage): void {\n if (!message.to || (Array.isArray(message.to) && message.to.length === 0)) {\n throw getError({\n error: MailErrors.INVALID_RECIPIENT,\n message: 'Recipient email address is required',\n });\n }\n\n if (!message.subject) {\n throw getError({\n error: MailErrors.INVALID_CONFIGURATION,\n message: 'Email subject is required',\n });\n }\n\n if (!message.text && !message.html) {\n throw getError({\n error: MailErrors.INVALID_CONFIGURATION,\n message: 'Email must have either text or html content',\n });\n }\n\n MailBodyUtility.assertIsText({ message });\n MailHeaderUtility.assert({ message });\n }\n\n protected getDefaultFrom(): string {\n const { from, fromName } = this.options;\n\n // A display name is only renderable around an address: `\"Name\" <undefined>` is not a sender.\n if (!from) {\n return MailDefaults.FALLBACK_FROM;\n }\n\n if (!fromName) {\n return from;\n }\n\n return `\"${MailMimeUtility.escapeQuotedString({ value: fromName })}\" <${from}>`;\n }\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  import { BaseService } from '@venizia/ignis-kernel';
2
2
  import type { IMailTemplateEngine, ITemplate, TMailTemplateFormat } from '../common/index.js';
3
- import type { AnyType } from '@venizia/ignis-helpers/common';
4
3
  /** In-memory template store and renderer. Templates registered here are lost on restart. */
5
4
  export declare class TemplateEngineService extends BaseService implements IMailTemplateEngine {
6
5
  private templates;
@@ -13,7 +12,7 @@ export declare class TemplateEngineService extends BaseService implements IMailT
13
12
  render(opts: {
14
13
  templateData?: string;
15
14
  templateName?: string;
16
- data: Record<string, AnyType>;
15
+ data: Record<string, unknown>;
17
16
  requireValidate?: boolean;
18
17
  format?: TMailTemplateFormat;
19
18
  }): string;
@@ -24,13 +23,13 @@ export declare class TemplateEngineService extends BaseService implements IMailT
24
23
  clearTemplates(): void;
25
24
  validateTemplateData(opts: {
26
25
  template: string;
27
- data: Record<string, AnyType>;
26
+ data: Record<string, unknown>;
28
27
  }): {
29
28
  isValid: boolean;
30
29
  missingKeys: string[];
31
30
  allKeys: string[];
32
31
  };
33
- renderSimpleTemplate(template: string, data: Record<string, AnyType>, opts?: {
32
+ renderSimpleTemplate(template: string, data: Record<string, unknown>, opts?: {
34
33
  requireValidate?: boolean;
35
34
  format?: TMailTemplateFormat;
36
35
  }): string;
@@ -112,7 +112,7 @@ export class TemplateEngineService extends BaseService {
112
112
  getNestedValue(obj, path) {
113
113
  return path.split('.').reduce((current, key) => {
114
114
  return current !== null && typeof current === 'object' && Object.hasOwn(current, key)
115
- ? current[key]
115
+ ? Reflect.get(current, key)
116
116
  : undefined;
117
117
  }, obj);
118
118
  }
@@ -1 +1 @@
1
- {"version":3,"file":"template.service.js","sourceRoot":"","sources":["../../../../../src/components/mail/services/template.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAE5D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,qHAAqH;AACrH,MAAM,WAAW,GAAG,oDAAoD,CAAC;AAEzE,4FAA4F;AAC5F,MAAM,OAAO,qBAAsB,SAAQ,WAAW;IAGpD;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC;QAHvC,cAAS,GAA2B,IAAI,GAAG,EAAE,CAAC;QAIpD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IAC7E,CAAC;IAED,gBAAgB,CAAC,IAAqE;QACpF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACxC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAC;QAEnF,MAAM,QAAQ,GAAc;YAC1B,IAAI;YACJ,OAAO;YACP,OAAO,EAAE,OAAO,EAAE,OAAO;YACzB,WAAW,EAAE,OAAO,EAAE,WAAW;SAClC,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,IAMN;QACC,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAE3E,IAAI,CAAC,YAAY,IAAI,CAAC,YAA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/D,OAAO,MAAM,IAAI,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3F,CAAC,CAAC,CAAC;IACL,CAAC;IAED,4GAA4G;IACpG,cAAc,CAAC,GAAY,EAAE,IAAY;QAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE;YAC7C,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC;gBACnF,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;gBACd,CAAC,CAAC,SAAS,CAAC;QAChB,CAAC,EAAE,GAAG,CAAC,CAAC;IACV,CAAC;CACF","sourcesContent":["import { BaseService } from '@venizia/ignis-kernel';\nimport type { IMailTemplateEngine, ITemplate, TMailTemplateFormat } from '../common';\nimport { MailErrors, MailTemplateFormats } from '../common';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\n\n/** `{{{key}}}` (group 1, raw) or `{{key}}` (group 2). The raw form comes first: `{{key}}` also matches inside it. */\nconst PLACEHOLDER = /\\{\\{\\{\\s*([\\w.]+)\\s*\\}\\}\\}|\\{\\{\\s*([\\w.]+)\\s*\\}\\}/g;\n\n/** In-memory template store and renderer. Templates registered here are lost on restart. */\nexport class TemplateEngineService extends BaseService implements IMailTemplateEngine {\n private templates: Map<string, ITemplate> = new Map();\n\n constructor() {\n super({ scope: TemplateEngineService.name });\n this.logger.for(this.constructor.name).info('Template engine initialized');\n }\n\n registerTemplate(opts: { name: string; content: string; options?: Partial<ITemplate> }): void {\n const { name, content, options } = opts;\n this.logger.for(this.registerTemplate.name).info('Registering template: %s', name);\n\n const template: ITemplate = {\n name,\n content,\n subject: options?.subject,\n description: options?.description,\n };\n\n this.templates.set(name, template);\n }\n\n render(opts: {\n templateData?: string;\n templateName?: string;\n data: Record<string, AnyType>;\n requireValidate?: boolean;\n format?: TMailTemplateFormat;\n }): string {\n const { templateData, templateName, data, requireValidate, format } = opts;\n\n if (!templateData && !templateName) {\n throw getError({ message: 'Either templateName or templateData must be provided' });\n }\n\n let content = templateData;\n\n if (!content && templateName) {\n const template = this.templates.get(templateName);\n\n if (!template) {\n throw getError({\n error: MailErrors.TEMPLATE_NOT_FOUND,\n message: `Template not found: ${templateName}`,\n });\n }\n\n this.logger.for(this.render.name).debug('Rendering template: %s', templateName);\n\n content = template.content;\n }\n\n if (content === undefined) {\n throw getError({\n error: MailErrors.INVALID_CONFIGURATION,\n message: `Template has no content: ${templateName}`,\n });\n }\n\n return this.renderSimpleTemplate(content, data, { requireValidate, format });\n }\n\n getTemplate(name: string): ITemplate | undefined {\n return this.templates.get(name);\n }\n\n listTemplates(): ITemplate[] {\n return Array.from(this.templates.values());\n }\n\n hasTemplate(name: string): boolean {\n return this.templates.has(name);\n }\n\n removeTemplate(name: string): boolean {\n this.logger.for(this.removeTemplate.name).info('Removing template: %s', name);\n\n return this.templates.delete(name);\n }\n\n clearTemplates(): void {\n this.logger.for(this.clearTemplates.name).info('Clearing all templates');\n this.templates.clear();\n }\n\n validateTemplateData(opts: { template: string; data: Record<string, AnyType> }): {\n isValid: boolean;\n missingKeys: string[];\n allKeys: string[];\n } {\n const { template, data } = opts;\n const allKeys: string[] = [];\n const missingKeys: string[] = [];\n\n for (const match of template.matchAll(PLACEHOLDER)) {\n const key = match[1] ?? match[2];\n\n if (allKeys.includes(key)) {\n continue;\n }\n\n allKeys.push(key);\n\n const value = this.getNestedValue(data, key);\n\n if (value === undefined || value === null) {\n missingKeys.push(key);\n }\n }\n\n const isValid = missingKeys.length === 0;\n\n if (!isValid) {\n this.logger\n .for(this.validateTemplateData.name)\n .warn('Template validation failed | Missing keys: %s', missingKeys.join(', '));\n }\n\n return { isValid, missingKeys, allKeys };\n }\n\n renderSimpleTemplate(\n template: string,\n data: Record<string, AnyType>,\n opts?: { requireValidate?: boolean; format?: TMailTemplateFormat },\n ): string {\n if (opts?.requireValidate) {\n const validation = this.validateTemplateData({ template, data });\n\n if (!validation.isValid) {\n throw getError({\n error: MailErrors.INVALID_CONFIGURATION,\n message: `Missing template data for keys: ${validation.missingKeys.join(', ')}`,\n });\n }\n }\n\n const isHtml = (opts?.format ?? MailTemplateFormats.HTML) === MailTemplateFormats.HTML;\n\n return template.replace(PLACEHOLDER, (match, tripleKey?: string, doubleKey?: string) => {\n const key = tripleKey ?? doubleKey ?? '';\n const value = this.getNestedValue(data, key);\n\n if (value === undefined || value === null) {\n this.logger.for(this.renderSimpleTemplate.name).warn('Missing value for key: %s', key);\n\n return match;\n }\n\n // `{{{key}}}` inserts as it is; `{{key}}` is escaped for HTML.\n return isHtml && tripleKey === undefined ? Bun.escapeHTML(String(value)) : String(value);\n });\n }\n\n /** Reads own properties only: `{{constructor}}` or `{{__proto__.x}}` must not reach the prototype chain. */\n private getNestedValue(obj: AnyType, path: string) {\n return path.split('.').reduce((current, key) => {\n return current !== null && typeof current === 'object' && Object.hasOwn(current, key)\n ? current[key]\n : undefined;\n }, obj);\n }\n}\n"]}
1
+ {"version":3,"file":"template.service.js","sourceRoot":"","sources":["../../../../../src/components/mail/services/template.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,qHAAqH;AACrH,MAAM,WAAW,GAAG,oDAAoD,CAAC;AAEzE,4FAA4F;AAC5F,MAAM,OAAO,qBAAsB,SAAQ,WAAW;IAGpD;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,qBAAqB,CAAC,IAAI,EAAE,CAAC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OAAO,EAAE,GAAG,CAAC;gBACnF,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC;gBAC3B,CAAC,CAAC,SAAS,CAAC;QAChB,CAAC,EAAE,GAAG,CAAC,CAAC;IACV,CAAC;CACF","sourcesContent":["import { BaseService } from '@venizia/ignis-kernel';\nimport type { IMailTemplateEngine, ITemplate, TMailTemplateFormat } from '../common';\nimport { MailErrors, MailTemplateFormats } from '../common';\nimport { getError } from '@venizia/ignis-helpers/core';\n\n/** `{{{key}}}` (group 1, raw) or `{{key}}` (group 2). The raw form comes first: `{{key}}` also matches inside it. */\nconst PLACEHOLDER = /\\{\\{\\{\\s*([\\w.]+)\\s*\\}\\}\\}|\\{\\{\\s*([\\w.]+)\\s*\\}\\}/g;\n\n/** In-memory template store and renderer. Templates registered here are lost on restart. */\nexport class TemplateEngineService extends BaseService implements IMailTemplateEngine {\n private templates: Map<string, ITemplate> = new Map();\n\n constructor() {\n super({ scope: TemplateEngineService.name });\n this.logger.for(this.constructor.name).info('Template engine initialized');\n }\n\n registerTemplate(opts: { name: string; content: string; options?: Partial<ITemplate> }): void {\n const { name, content, options } = opts;\n this.logger.for(this.registerTemplate.name).info('Registering template: %s', name);\n\n const template: ITemplate = {\n name,\n content,\n subject: options?.subject,\n description: options?.description,\n };\n\n this.templates.set(name, template);\n }\n\n render(opts: {\n templateData?: string;\n templateName?: string;\n data: Record<string, unknown>;\n requireValidate?: boolean;\n format?: TMailTemplateFormat;\n }): string {\n const { templateData, templateName, data, requireValidate, format } = opts;\n\n if (!templateData && !templateName) {\n throw getError({ message: 'Either templateName or templateData must be provided' });\n }\n\n let content = templateData;\n\n if (!content && templateName) {\n const template = this.templates.get(templateName);\n\n if (!template) {\n throw getError({\n error: MailErrors.TEMPLATE_NOT_FOUND,\n message: `Template not found: ${templateName}`,\n });\n }\n\n this.logger.for(this.render.name).debug('Rendering template: %s', templateName);\n\n content = template.content;\n }\n\n if (content === undefined) {\n throw getError({\n error: MailErrors.INVALID_CONFIGURATION,\n message: `Template has no content: ${templateName}`,\n });\n }\n\n return this.renderSimpleTemplate(content, data, { requireValidate, format });\n }\n\n getTemplate(name: string): ITemplate | undefined {\n return this.templates.get(name);\n }\n\n listTemplates(): ITemplate[] {\n return Array.from(this.templates.values());\n }\n\n hasTemplate(name: string): boolean {\n return this.templates.has(name);\n }\n\n removeTemplate(name: string): boolean {\n this.logger.for(this.removeTemplate.name).info('Removing template: %s', name);\n\n return this.templates.delete(name);\n }\n\n clearTemplates(): void {\n this.logger.for(this.clearTemplates.name).info('Clearing all templates');\n this.templates.clear();\n }\n\n validateTemplateData(opts: { template: string; data: Record<string, unknown> }): {\n isValid: boolean;\n missingKeys: string[];\n allKeys: string[];\n } {\n const { template, data } = opts;\n const allKeys: string[] = [];\n const missingKeys: string[] = [];\n\n for (const match of template.matchAll(PLACEHOLDER)) {\n const key = match[1] ?? match[2];\n\n if (allKeys.includes(key)) {\n continue;\n }\n\n allKeys.push(key);\n\n const value = this.getNestedValue(data, key);\n\n if (value === undefined || value === null) {\n missingKeys.push(key);\n }\n }\n\n const isValid = missingKeys.length === 0;\n\n if (!isValid) {\n this.logger\n .for(this.validateTemplateData.name)\n .warn('Template validation failed | Missing keys: %s', missingKeys.join(', '));\n }\n\n return { isValid, missingKeys, allKeys };\n }\n\n renderSimpleTemplate(\n template: string,\n data: Record<string, unknown>,\n opts?: { requireValidate?: boolean; format?: TMailTemplateFormat },\n ): string {\n if (opts?.requireValidate) {\n const validation = this.validateTemplateData({ template, data });\n\n if (!validation.isValid) {\n throw getError({\n error: MailErrors.INVALID_CONFIGURATION,\n message: `Missing template data for keys: ${validation.missingKeys.join(', ')}`,\n });\n }\n }\n\n const isHtml = (opts?.format ?? MailTemplateFormats.HTML) === MailTemplateFormats.HTML;\n\n return template.replace(PLACEHOLDER, (match, tripleKey?: string, doubleKey?: string) => {\n const key = tripleKey ?? doubleKey ?? '';\n const value = this.getNestedValue(data, key);\n\n if (value === undefined || value === null) {\n this.logger.for(this.renderSimpleTemplate.name).warn('Missing value for key: %s', key);\n\n return match;\n }\n\n // `{{{key}}}` inserts as it is; `{{key}}` is escaped for HTML.\n return isHtml && tripleKey === undefined ? Bun.escapeHTML(String(value)) : String(value);\n });\n }\n\n /** Reads own properties only: `{{constructor}}` or `{{__proto__.x}}` must not reach the prototype chain. */\n private getNestedValue(obj: unknown, path: string): unknown {\n return path.split('.').reduce<unknown>((current, key) => {\n return current !== null && typeof current === 'object' && Object.hasOwn(current, key)\n ? Reflect.get(current, key)\n : undefined;\n }, obj);\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { type IMailMessage } from '../common/index.js';
2
2
  /** The one place a message is checked for header injection, before any transport sees it. A transport called directly skips it. */
3
3
  export declare class MailHeaderUtility {
4
- /** `value` is `unknown`: the message types end in `[key: string]: any`, so nothing stops a controller forwarding a request body from putting an array where a string is declared. */
4
+ /** `value` is `unknown`: the message types end in `[key: string]: unknown`, so nothing stops a controller forwarding a request body from putting an array where a string is declared. */
5
5
  static assertValue(opts: {
6
6
  field: string;
7
7
  value: unknown;
@@ -6,7 +6,7 @@ const HEADER_NAME_PATTERN = /^[\x21-\x39\x3b-\x7e]+$/;
6
6
  const HEADER_VALUE_FORBIDDEN = /[\r\n\0]/;
7
7
  /** The one place a message is checked for header injection, before any transport sees it. A transport called directly skips it. */
8
8
  export class MailHeaderUtility {
9
- /** `value` is `unknown`: the message types end in `[key: string]: any`, so nothing stops a controller forwarding a request body from putting an array where a string is declared. */
9
+ /** `value` is `unknown`: the message types end in `[key: string]: unknown`, so nothing stops a controller forwarding a request body from putting an array where a string is declared. */
10
10
  static assertValue(opts) {
11
11
  const { field, value } = opts;
12
12
  if (typeof value === 'string' && !HEADER_VALUE_FORBIDDEN.test(value)) {
@@ -1 +1 @@
1
- {"version":3,"file":"header.utility.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/header.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,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,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;QAED,iBAAiB,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QAEpE,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;YAC1D,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpC,MAAM,QAAQ,CAAC;oBACb,KAAK,EAAE,UAAU,CAAC,cAAc;oBAChC,OAAO,EAAE,6EAA6E;iBACvF,CAAC,CAAC;YACL,CAAC;YAED,iBAAiB,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,WAAW,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF","sourcesContent":["import { getError } from '@venizia/ignis-helpers/core';\nimport { MailErrors, type IMailMessage } from '../common';\n\n/** Printable ASCII without the colon: what RFC 5322 allows in a header field name. */\nconst HEADER_NAME_PATTERN = /^[\\x21-\\x39\\x3b-\\x7e]+$/;\n\n/** A value spliced into a header line cannot hold a line break or NUL: it would break out of its line and forge headers or smuggle body content. */\nconst HEADER_VALUE_FORBIDDEN = /[\\r\\n\\0]/;\n\n/** The one place a message is checked for header injection, before any transport sees it. A transport called directly skips it. */\nexport class MailHeaderUtility {\n /** `value` is `unknown`: the message types end in `[key: string]: any`, so nothing stops a controller forwarding a request body from putting an array where a string is declared. */\n static assertValue(opts: { field: string; value: unknown }): void {\n const { field, value } = opts;\n\n if (typeof value === 'string' && !HEADER_VALUE_FORBIDDEN.test(value)) {\n return;\n }\n\n throw getError({\n error: MailErrors.INVALID_HEADER,\n message: `Invalid mail header | ${field} must be a string without line breaks or control characters`,\n });\n }\n\n /** Every address field, the subject and the custom headers, names included. */\n static assert(opts: { message: IMailMessage }): void {\n const { from, to, cc, bcc, replyTo, subject, headers } = opts.message;\n const addresses = { from, to, cc, bcc, replyTo };\n\n for (const [field, value] of Object.entries(addresses)) {\n if (value === undefined || value === null) {\n continue;\n }\n\n for (const item of Array.isArray(value) ? value : [value]) {\n MailHeaderUtility.assertValue({ field, value: item });\n }\n }\n\n MailHeaderUtility.assertValue({ field: 'subject', value: subject });\n\n for (const [name, value] of Object.entries(headers ?? {})) {\n if (!HEADER_NAME_PATTERN.test(name)) {\n throw getError({\n error: MailErrors.INVALID_HEADER,\n message: 'Invalid mail header | a header name must be printable ASCII without a colon',\n });\n }\n\n MailHeaderUtility.assertValue({ field: `headers.${name}`, value });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"header.utility.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/header.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAqB,MAAM,WAAW,CAAC;AAE1D,sFAAsF;AACtF,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAEtD,oJAAoJ;AACpJ,MAAM,sBAAsB,GAAG,UAAU,CAAC;AAE1C,mIAAmI;AACnI,MAAM,OAAO,iBAAiB;IAC5B,yLAAyL;IACzL,MAAM,CAAC,WAAW,CAAC,IAAuC;QACxD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAE9B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACrE,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,KAAK,EAAE,UAAU,CAAC,cAAc;YAChC,OAAO,EAAE,yBAAyB,KAAK,6DAA6D;SACrG,CAAC,CAAC;IACL,CAAC;IAED,+EAA+E;IAC/E,MAAM,CAAC,MAAM,CAAC,IAA+B;QAC3C,MAAM,EAAE,IA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MailMessage } from '../common';\n\n/** Printable ASCII without the colon: what RFC 5322 allows in a header field name. */\nconst HEADER_NAME_PATTERN = /^[\\x21-\\x39\\x3b-\\x7e]+$/;\n\n/** A value spliced into a header line cannot hold a line break or NUL: it would break out of its line and forge headers or smuggle body content. */\nconst HEADER_VALUE_FORBIDDEN = /[\\r\\n\\0]/;\n\n/** The one place a message is checked for header injection, before any transport sees it. A transport called directly skips it. */\nexport class MailHeaderUtility {\n /** `value` is `unknown`: the message types end in `[key: string]: unknown`, so nothing stops a controller forwarding a request body from putting an array where a string is declared. */\n static assertValue(opts: { field: string; value: unknown }): void {\n const { field, value } = opts;\n\n if (typeof value === 'string' && !HEADER_VALUE_FORBIDDEN.test(value)) {\n return;\n }\n\n throw getError({\n error: MailErrors.INVALID_HEADER,\n message: `Invalid mail header | ${field} must be a string without line breaks or control characters`,\n });\n }\n\n /** Every address field, the subject and the custom headers, names included. */\n static assert(opts: { message: IMailMessage }): void {\n const { from, to, cc, bcc, replyTo, subject, headers } = opts.message;\n const addresses = { from, to, cc, bcc, replyTo };\n\n for (const [field, value] of Object.entries(addresses)) {\n if (value === undefined || value === null) {\n continue;\n }\n\n for (const item of Array.isArray(value) ? value : [value]) {\n MailHeaderUtility.assertValue({ field, value: item });\n }\n }\n\n MailHeaderUtility.assertValue({ field: 'subject', value: subject });\n\n for (const [name, value] of Object.entries(headers ?? {})) {\n if (!HEADER_NAME_PATTERN.test(name)) {\n throw getError({\n error: MailErrors.INVALID_HEADER,\n message: 'Invalid mail header | a header name must be printable ASCII without a colon',\n });\n }\n\n MailHeaderUtility.assertValue({ field: `headers.${name}`, value });\n }\n }\n}\n"]}