@postxl/generators 1.25.0 → 1.26.0

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 (37) hide show
  1. package/dist/backend-actions/actions.generator.d.ts +11 -0
  2. package/dist/backend-actions/actions.generator.js.map +1 -1
  3. package/dist/backend-actions/generators/actions-module.generator.js +11 -3
  4. package/dist/backend-actions/generators/actions-module.generator.js.map +1 -1
  5. package/dist/backend-actions/generators/dispatcher-service.generator.js +12 -4
  6. package/dist/backend-actions/generators/dispatcher-service.generator.js.map +1 -1
  7. package/dist/backend-mail/generators/conditional-files.d.ts +15 -0
  8. package/dist/backend-mail/generators/conditional-files.js +410 -0
  9. package/dist/backend-mail/generators/conditional-files.js.map +1 -0
  10. package/dist/backend-mail/generators/env-config.generator.d.ts +16 -0
  11. package/dist/backend-mail/generators/env-config.generator.js +167 -0
  12. package/dist/backend-mail/generators/env-config.generator.js.map +1 -0
  13. package/dist/backend-mail/generators/mail.service.generator.d.ts +11 -0
  14. package/dist/backend-mail/generators/mail.service.generator.js +243 -0
  15. package/dist/backend-mail/generators/mail.service.generator.js.map +1 -0
  16. package/dist/backend-mail/index.d.ts +5 -0
  17. package/dist/backend-mail/index.js +41 -0
  18. package/dist/backend-mail/index.js.map +1 -0
  19. package/dist/backend-mail/mail.generator.d.ts +78 -0
  20. package/dist/backend-mail/mail.generator.js +162 -0
  21. package/dist/backend-mail/mail.generator.js.map +1 -0
  22. package/dist/backend-mail/template/src/adapters/log.adapter.ts +14 -0
  23. package/dist/backend-mail/template/src/adapters/mail-adapter.interface.ts +27 -0
  24. package/dist/backend-mail/template/src/mail.config.ts +42 -0
  25. package/dist/backend-mail/template/src/mail.module.ts +37 -0
  26. package/dist/backend-mail/template/src/mail.service.test.ts +195 -0
  27. package/dist/backend-mail/template/src/mail.types.ts +67 -0
  28. package/dist/backend-mail/template/src/templates/simple.renderer.test.ts +155 -0
  29. package/dist/backend-mail/template/src/templates/simple.renderer.ts +171 -0
  30. package/dist/backend-mail/template/src/templates/template-renderer.interface.ts +5 -0
  31. package/dist/backend-mail/template/tsconfig.lib.json +10 -0
  32. package/dist/generators.js +2 -0
  33. package/dist/generators.js.map +1 -1
  34. package/dist/index.d.ts +2 -0
  35. package/dist/index.js +6 -2
  36. package/dist/index.js.map +1 -1
  37. package/package.json +4 -4
@@ -101,6 +101,17 @@ export type ActionProvider<Actions extends Record<string, ActionProviderTypes>>
101
101
  variableName: Generator.VariableName;
102
102
  };
103
103
  scopes: Set<ScopeName>;
104
+ /**
105
+ * Whether the dispatcher needs to wrap the service injection in `forwardRef`.
106
+ *
107
+ * Default `true` for backwards compatibility — the existing model-oriented
108
+ * providers (update/import) have circular module dependencies with the
109
+ * dispatcher and rely on the wrapper.
110
+ *
111
+ * Set to `false` for self-contained providers (e.g. mail) so real circular
112
+ * dependencies are not silently papered over.
113
+ */
114
+ needsForwardRef?: boolean;
104
115
  actions: {
105
116
  summary: ActionProviderTypes;
106
117
  } & Actions;
@@ -1 +1 @@
1
- {"version":3,"file":"actions.generator.js","sourceRoot":"","sources":["../../src/backend-actions/actions.generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAmC;AACnC,8CAAmB;AAEnB,6DAA8C;AAC9C,uDAAwC;AAExC,kDAA+E;AAC/E,wEAA8E;AAC9E,kCAAmD;AACnD,oCAAsD;AAEtD,gFAAyE;AACzE,gGAAmF;AACnF,oFAA6E;AAC7E,gHAAwG;AACxG,kGAA2F;AAC3F,4FAA8E;AAC9E,sFAAqF;AACrF,8FAA6F;AAgH7F,MAAM,UAAU,GAAG,aAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;AAK7C,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AAAxD,QAAA,WAAW,eAA6C;AAmBxD,QAAA,WAAW,GA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IACzE,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;IAC3E,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;AAC3E,CAAC"}
@@ -14,15 +14,23 @@ function generateActionsModule({ actions, database }) {
14
14
  .addType(actions.config.options)
15
15
  .add(database.module.moduleClass); // NOSONAR
16
16
  const moduleImports = [];
17
- for (const { module: { moduleClass }, } of actions.providers) {
17
+ let anyProviderUsesForwardRef = false;
18
+ for (const { module: { moduleClass }, needsForwardRef = true, } of actions.providers) {
18
19
  if (!moduleClass) {
19
20
  continue;
20
21
  }
21
22
  imports.add(moduleClass);
22
- moduleImports.push(`forwardRef(() => ${moduleClass.name})`);
23
+ if (needsForwardRef) {
24
+ anyProviderUsesForwardRef = true;
25
+ moduleImports.push(`forwardRef(() => ${moduleClass.name})`);
26
+ }
27
+ else {
28
+ moduleImports.push(moduleClass.name);
29
+ }
23
30
  }
31
+ const nestImports = anyProviderUsesForwardRef ? 'DynamicModule, forwardRef, Provider' : 'DynamicModule, Provider';
24
32
  return /* ts */ `
25
- import { DynamicModule, forwardRef, Provider } from '@nestjs/common'
33
+ import { ${nestImports} } from '@nestjs/common'
26
34
 
27
35
  ${imports.generate()}
28
36
 
@@ -1 +1 @@
1
- {"version":3,"file":"actions-module.generator.js","sourceRoot":"","sources":["../../../src/backend-actions/generators/actions-module.generator.ts"],"names":[],"mappings":";;AAIA,sDA8CC;AAlDD,iDAAmD;AAInD,SAAgB,qBAAqB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAiB;IACxE,MAAM,OAAO,GAAG,2BAAe;QAC7B,EAAE;SACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;SAC7B,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC;SAC5B,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC;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AK,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI;;;;EAIrJ,CAAA;AACF,CAAC"}
1
+ {"version":3,"file":"actions-module.generator.js","sourceRoot":"","sources":["../../../src/backend-actions/generators/actions-module.generator.ts"],"names":[],"mappings":";;AAIA,sDAuDC;AA3DD,iDAAmD;AAInD,SAAgB,qBAAqB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAiB;IACxE,MAAM,OAAO,GAAG,2BAAe;QAC7B,EAAE;SACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;SAC7B,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC;SAC5B,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC;SACvB,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC;SACjC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC;SAClC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;SACnB,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;SAC/B,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAY,CAAC,CAAA,CAAC,UAAU;IAE/C,MAAM,aAAa,GAAa,EAAE,CAAA;IAClC,IAAI,yBAAyB,GAAG,KAAK,CAAA;IACrC,KAAK,MAAM,EACT,MAAM,EAAE,EAAE,WAAW,EAAE,EACvB,eAAe,GAAG,IAAI,GACvB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACvB,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,SAAQ;QACV,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QACxB,IAAI,eAAe,EAAE,CAAC;YACpB,yBAAyB,GAAG,IAAI,CAAA;YAChC,aAAa,CAAC,IAAI,CAAC,oBAAoB,WAAW,CAAC,IAAI,GAAG,CAAC,CAAA;QAC7D,CAAC;aAAM,CAAC;YACN,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QACtC,CAAC;IACH,CAAC;IAED,MAAM,WAAW,GAAG,yBAAyB,CAAC,CAAC,CAAC,qCAAqC,CAAC,CAAC,CAAC,yBAAyB,CAAA;IAEjH,OAAO,QAAQ,CAAC;WACP,WAAW;;EAEpB,OAAO,CAAC,QAAQ,EAAE;;eAEL,OAAO,CAAC,MAAM,CAAC,IAAI;mCACC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI;;iBAE7C,OAAO,CAAC,MAAM,CAAC,IAAI;sBACd,OAAO,CAAC,MAAM,CAAC,IAAI;;;gBAGzB,OAAO,CAAC,MAAM,CAAC,IAAI;;UAEzB,QAAQ,CAAC,MAAM,CAAC,WAAY,CAAC,IAAI;UACjC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;;oBAEf,OAAO,CAAC,UAAU,CAAC,IAAI,KAAK,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI;kBACvI,OAAO,CAAC,UAAU,CAAC,IAAI,KAAK,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI;;;;EAIrJ,CAAA;AACF,CAAC"}
@@ -20,17 +20,25 @@ function generateDispatcher({ actions, database, types }) {
20
20
  throw new Error('This is only added to ensure it compiles. To be deleted once more actions are added!')
21
21
  `);
22
22
  }
23
- for (const { service, scopes } of actions.providers) {
23
+ let anyProviderUsesForwardRef = false;
24
+ for (const { service, scopes, needsForwardRef = true } of actions.providers) {
24
25
  imports.add(service);
25
- injections.push(`@Inject(forwardRef(() => ${service.name})) private readonly ${service.variableName}: ${service.name}`);
26
+ if (needsForwardRef) {
27
+ anyProviderUsesForwardRef = true;
28
+ injections.push(`@Inject(forwardRef(() => ${service.name})) private readonly ${service.variableName}: ${service.name}`);
29
+ }
30
+ else {
31
+ injections.push(`private readonly ${service.variableName}: ${service.name}`);
32
+ }
26
33
  for (const scopeName of scopes) {
27
34
  executeMethods.push(`
28
- case '${scopeName}':
35
+ case '${scopeName}':
29
36
  return this.${service.variableName}.dispatch({ action, execution }) as Promise<Result>`);
30
37
  }
31
38
  }
39
+ const nestImports = anyProviderUsesForwardRef ? 'forwardRef, Inject, Injectable, Logger' : 'Injectable, Logger';
32
40
  return /* ts */ `
33
- import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common'
41
+ import { ${nestImports} } from '@nestjs/common'
34
42
 
35
43
  import { ExhaustiveSwitchCheck } from '@postxl/utils'
36
44
  ${imports.generate()}
@@ -1 +1 @@
1
- {"version":3,"file":"dispatcher-service.generator.js","sourceRoot":"","sources":["../../../src/backend-actions/generators/dispatcher-service.generator.ts"],"names":[],"mappings":";;AAIA,gDAyGC;AA7GD,iDAAmD;AAInD,SAAgB,kBAAkB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAiB;IAC5E,MAAM,OAAO,GAAG,2BAAe,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IACjE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC7B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACpC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;IACxC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACnC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACnC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,C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,IAAI,CAAC;;;;;;;CAOhC,CAAA;AACD,CAAC"}
1
+ {"version":3,"file":"dispatcher-service.generator.js","sourceRoot":"","sources":["../../../src/backend-actions/generators/dispatcher-service.generator.ts"],"names":[],"mappings":";;AAIA,gDAgHC;AApHD,iDAAmD;AAInD,SAAgB,kBAAkB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAiB;IAC5E,MAAM,OAAO,GAAG,2BAAe,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IACjE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC7B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACpC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;IACxC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACnC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACnC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACjD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IAC1C,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IAEhC,MAAM,UAAU,GAAa,EAAE,CAAA;IAC/B,MAAM,cAAc,GAAa,EAAE,CAAA;IACnC,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,cAAc,CAAC,IAAI,CACjB;;KAED,CACA,CAAA;IACH,CAAC;IAED,IAAI,yBAAyB,GAAG,KAAK,CAAA;IACrC,KAAK,MAAM,EAAE,OAAO,EAAE,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the matching
5
+ * adapter or renderer is enabled via `configureBackendMailGenerator`.
6
+ * Keeping them as plain string constants (rather than in the `template/`
7
+ * folder) means the generator never copies files the project will not
8
+ * compile and lets us gate both file emission and `package.json`
9
+ * dependencies on the same boolean.
10
+ */
11
+ export declare const sesAdapterSource = "import { SendEmailCommand, SESClient } from '@aws-sdk/client-ses'\nimport { Logger } from '@nestjs/common'\n\nimport type { IMailAdapter, MailPayload, MailSendResult, MailSendResultErrorStatus } from './mail-adapter.interface'\n\nexport type SesAdapterConfig = {\n region: string\n useCredentials: boolean\n accessKey?: string\n secretAccessKey?: string\n}\n\nconst SES_INVALID_ADDRESS_ERRORS = new Set([\n 'InvalidParameterValue',\n 'InvalidParameterCombination',\n 'InvalidEmailAddress',\n 'MailFromDomainNotVerifiedException',\n])\n\nexport class SesAdapter implements IMailAdapter {\n private readonly logger = new Logger(SesAdapter.name)\n private readonly client: SESClient\n\n constructor(config: SesAdapterConfig) {\n this.client = new SESClient({\n region: config.region,\n credentials: config.useCredentials\n ? {\n accessKeyId: config.accessKey ?? '',\n secretAccessKey: config.secretAccessKey ?? '',\n }\n : undefined,\n })\n }\n\n public async send(payload: MailPayload): Promise<MailSendResult> {\n try {\n const result = await this.client.send(\n new SendEmailCommand({\n Source: payload.from,\n Destination: {\n ToAddresses: [payload.to],\n BccAddresses: payload.bcc ?? [],\n },\n Message: {\n Subject: { Charset: 'UTF-8', Data: payload.subject },\n Body: {\n Html: { Charset: 'UTF-8', Data: payload.html },\n Text: { Charset: 'UTF-8', Data: payload.text ?? '' },\n },\n },\n }),\n )\n return { success: true, status: 'sent', details: result.MessageId }\n } catch (error) {\n const status = classifySesError(error)\n const message = describeError(error)\n if (status === 'errorInvalidEmail') {\n this.logger.warn(`SES rejected invalid address: ${message}`)\n } else if (status === 'errorRejected') {\n this.logger.warn(`SES rejected mail: ${message}`)\n } else {\n this.logger.error(`SES send failed: ${message}`, error instanceof Error ? error.stack : undefined)\n }\n return { success: false, status, details: message }\n }\n }\n}\n\nfunction classifySesError(error: unknown): MailSendResultErrorStatus {\n if (!(error instanceof Error)) {\n return 'errorOther'\n }\n if (SES_INVALID_ADDRESS_ERRORS.has(error.name)) {\n return 'errorInvalidEmail'\n }\n if (error.name === 'MessageRejected') {\n return 'errorRejected'\n }\n return 'errorOther'\n}\n\nfunction describeError(error: unknown): string {\n return error instanceof Error ? `${error.name}: ${error.message}` : String(error)\n}\n";
12
+ export declare const smtpAdapterSource = "/** Runtime verified on Node 24; Bun: untested. */\nimport { Logger } from '@nestjs/common'\nimport nodemailer, { type Transporter } from 'nodemailer'\n\nimport type { IMailAdapter, MailPayload, MailSendResult, MailSendResultErrorStatus } from './mail-adapter.interface'\n\nexport type SmtpAdapterConfig = {\n host: string\n port: number\n secure: boolean\n user: string\n password: string\n}\n\ntype NodemailerTransportOptions = {\n host: string\n port: number\n secure: boolean\n auth?: { user: string; pass: string }\n}\n\n/**\n * Builds the nodemailer `createTransport` options from our adapter config.\n *\n * Exported so the auth-gating logic can be unit-tested directly - passing a\n * partial credential pair (only user, only password) must result in auth\n * being omitted entirely rather than sent with an empty field.\n */\nexport function buildSmtpTransportOptions(config: SmtpAdapterConfig): NodemailerTransportOptions {\n const hasAuth = config.user.length > 0 && config.password.length > 0\n return {\n host: config.host,\n port: config.port,\n secure: config.secure,\n auth: hasAuth ? { user: config.user, pass: config.password } : undefined,\n }\n}\n\nexport class SmtpAdapter implements IMailAdapter {\n private readonly logger = new Logger(SmtpAdapter.name)\n private readonly transporter: Transporter\n\n constructor(config: SmtpAdapterConfig, transporter?: Transporter) {\n this.transporter = transporter ?? nodemailer.createTransport(buildSmtpTransportOptions(config))\n }\n\n public async send(payload: MailPayload): Promise<MailSendResult> {\n try {\n const info = (await this.transporter.sendMail({\n from: payload.from,\n to: payload.to,\n bcc: payload.bcc,\n subject: payload.subject,\n html: payload.html,\n text: payload.text,\n })) as { messageId?: string }\n return { success: true, status: 'sent', details: info.messageId }\n } catch (error) {\n const classified = classifySmtpError(error)\n const message = describeError(error)\n if (classified === 'errorRejected') {\n this.logger.warn(`SMTP rejected mail: ${message}`)\n } else if (classified === 'errorInvalidEmail') {\n this.logger.warn(`SMTP invalid address: ${message}`)\n } else {\n this.logger.error(`SMTP send failed: ${message}`, error instanceof Error ? error.stack : undefined)\n }\n return { success: false, status: classified, details: message }\n }\n }\n}\n\n/**\n * Maps nodemailer / SMTP errors onto our adapter-agnostic status enum.\n *\n * `errorInvalidEmail` is reserved for errors that unambiguously point at a\n * malformed or syntactically-invalid address (EENVELOPE, EMESSAGE, and the\n * classic 501/553 response codes).\n *\n * Every other 5xx response is bucketed into `errorRejected`. Note that this\n * deliberately groups \"recipient does not exist\" (550 mailbox unavailable)\n * together with \"your account is blocked\" (550 spam-related) - SMTP does\n * not give us enough signal to tell them apart reliably, and splitting them\n * would make the enum less stable. Callers needing that distinction should\n * inspect the `details` string.\n */\nfunction classifySmtpError(error: unknown): MailSendResultErrorStatus {\n if (!(error instanceof Error)) {\n return 'errorOther'\n }\n const code = (error as Error & { code?: string; responseCode?: number }).code\n const responseCode = (error as Error & { responseCode?: number }).responseCode\n if (code === 'EENVELOPE' || code === 'EMESSAGE' || responseCode === 501 || responseCode === 553) {\n return 'errorInvalidEmail'\n }\n if (responseCode && responseCode >= 500 && responseCode < 600) {\n return 'errorRejected'\n }\n return 'errorOther'\n}\n\nfunction describeError(error: unknown): string {\n if (error instanceof Error) {\n const withCode = error as Error & { code?: string; responseCode?: number }\n const codeTag = withCode.code ?? (withCode.responseCode ? String(withCode.responseCode) : error.name)\n return `${codeTag}: ${error.message}`\n }\n return String(error)\n}\n";
13
+ export declare const smtpAdapterTestSource = "import { describe, expect, it, jest } from '@jest/globals'\nimport type { Transporter } from 'nodemailer'\n\nimport { buildSmtpTransportOptions, SmtpAdapter } from './smtp.adapter'\n\nfunction createSpyTransporter(): { transporter: Transporter; sendMail: jest.Mock } {\n const sendMail = jest.fn(() => Promise.resolve({ messageId: 'msg-123' }))\n const transporter = { sendMail } as unknown as Transporter\n return { transporter, sendMail }\n}\n\ndescribe('buildSmtpTransportOptions', () => {\n const base = { host: 'smtp.example.com', port: 587, secure: false }\n\n it('includes auth when both user and password are set', () => {\n expect(buildSmtpTransportOptions({ ...base, user: 'alice', password: 'secret' })).toEqual({\n ...base,\n auth: { user: 'alice', pass: 'secret' },\n })\n })\n\n it('omits auth entirely when only user is set', () => {\n expect(buildSmtpTransportOptions({ ...base, user: 'alice', password: '' }).auth).toBeUndefined()\n })\n\n it('omits auth entirely when only password is set', () => {\n expect(buildSmtpTransportOptions({ ...base, user: '', password: 'secret' }).auth).toBeUndefined()\n })\n\n it('omits auth entirely when neither is set', () => {\n expect(buildSmtpTransportOptions({ ...base, user: '', password: '' }).auth).toBeUndefined()\n })\n})\n\ndescribe('SmtpAdapter', () => {\n it('marshals the payload through the transporter and returns success with the messageId', async () => {\n const { transporter, sendMail } = createSpyTransporter()\n const adapter = new SmtpAdapter({ host: 'unused', port: 587, secure: false, user: '', password: '' }, transporter)\n\n const result = await adapter.send({\n from: 'noreply@example.com',\n to: 'user@example.com',\n bcc: ['admin@example.com'],\n subject: 'Hi there',\n html: '<p>hello</p>',\n text: 'hello',\n })\n\n expect(result.success).toBe(true)\n if (!result.success) {\n throw new Error('unreachable')\n }\n expect(result.status).toBe('sent')\n expect(result.details).toBe('msg-123')\n\n expect(sendMail).toHaveBeenCalledTimes(1)\n expect(sendMail).toHaveBeenCalledWith({\n from: 'noreply@example.com',\n to: 'user@example.com',\n bcc: ['admin@example.com'],\n subject: 'Hi there',\n html: '<p>hello</p>',\n text: 'hello',\n })\n })\n\n it('classifies invalid-address errors and returns a serialized details string', async () => {\n const invalidErr = Object.assign(new Error('Bad recipient'), { code: 'EENVELOPE', responseCode: 501 })\n const sendMail = jest.fn(() => Promise.reject(invalidErr))\n const adapter = new SmtpAdapter({ host: 'unused', port: 587, secure: false, user: '', password: '' }, {\n sendMail,\n } as unknown as Transporter)\n\n const result = await adapter.send({\n from: 'noreply@example.com',\n to: 'bad',\n subject: 'x',\n html: '<p>x</p>',\n })\n\n expect(result).toEqual({\n success: false,\n status: 'errorInvalidEmail',\n details: 'EENVELOPE: Bad recipient',\n })\n })\n\n it('classifies 5xx rejects as errorRejected', async () => {\n const rejected = Object.assign(new Error('Mailbox unavailable'), { responseCode: 550 })\n const sendMail = jest.fn(() => Promise.reject(rejected))\n const adapter = new SmtpAdapter({ host: 'unused', port: 587, secure: false, user: '', password: '' }, {\n sendMail,\n } as unknown as Transporter)\n\n const result = await adapter.send({\n from: 'noreply@example.com',\n to: 'user@example.com',\n subject: 'x',\n html: '<p>x</p>',\n })\n\n expect(result.success).toBe(false)\n if (result.success) {\n throw new Error('unreachable')\n }\n expect(result.status).toBe('errorRejected')\n expect(result.details).toBe('550: Mailbox unavailable')\n })\n})\n";
14
+ export declare const emailmdRendererSource = "import { Logger } from '@nestjs/common'\nimport { render } from 'emailmd'\n\nimport { htmlEscape, stripTags, substituteVariables, substituteVariablesRaw } from './simple.renderer'\nimport type { ITemplateRenderer, RenderedMail } from './template-renderer.interface'\n\nexport class EmailmdRenderer implements ITemplateRenderer {\n private readonly logger = new Logger(EmailmdRenderer.name)\n\n public render(source: string, data: Record<string, unknown>): RenderedMail {\n const substituted = substituteVariables(source, data)\n try {\n const { html, text } = render(substituted)\n return { html, text }\n } catch (error) {\n // `emailmd` is a pre-1.0 package that parses markdown via MJML;\n // malformed input, internal MJML bugs, or upstream API churn can\n // surface as thrown errors. Swallowing them would lose the mail, but\n // letting them propagate through the dispatcher would fail the\n // action with a confusing stack trace. Log + fall back to a simple\n // escaped HTML + raw plain-text render so the mail still goes out.\n const message = error instanceof Error ? `${error.name}: ${error.message}` : String(error)\n this.logger.warn(`emailmd render failed, falling back to plain text: ${message}`)\n const rawText = stripTags(substituteVariablesRaw(source, data))\n return {\n html: `<pre>${htmlEscape(rawText)}</pre>`,\n text: rawText,\n }\n }\n }\n}\n";
15
+ export declare const emailmdRendererTestSource = "import { describe, expect, it, jest } from '@jest/globals'\n\njest.mock('emailmd', () => ({\n render: jest.fn(),\n}))\n\nimport { render as emailmdRender } from 'emailmd'\n\nimport { EmailmdRenderer } from './emailmd.renderer'\n\nconst mockedRender = emailmdRender as unknown as jest.Mock\n\ndescribe('EmailmdRenderer', () => {\n it('returns the emailmd render output on success', () => {\n mockedRender.mockReturnValueOnce({\n html: '<html><body>Hello</body></html>',\n text: 'Hello',\n meta: {},\n })\n\n const renderer = new EmailmdRenderer()\n const result = renderer.render('Hello {{name}}', { name: 'Ada' })\n\n expect(result).toEqual({\n html: '<html><body>Hello</body></html>',\n text: 'Hello',\n })\n expect(mockedRender).toHaveBeenCalledWith('Hello Ada')\n })\n\n it('falls back to a plaintext render when emailmd throws', () => {\n mockedRender.mockImplementationOnce(() => {\n throw new Error('MJML parse error')\n })\n\n const renderer = new EmailmdRenderer()\n const result = renderer.render('Hello {{name}}', { name: 'Ada' })\n\n expect(result.text).toBe('Hello Ada')\n expect(result.html).toBe('<pre>Hello Ada</pre>')\n })\n\n it('preserves raw characters in fallback text and escapes them in fallback html', () => {\n mockedRender.mockImplementationOnce(() => {\n throw new Error('boom')\n })\n\n const renderer = new EmailmdRenderer()\n const result = renderer.render('Plain {{name}}', { name: '<script>alert(1)</script>' })\n\n // Text body is the plain-text MIME part \u2014 stripTags removes the\n // literal `<script>` wrapper and `alert(1)` survives.\n expect(result.text).toBe('Plain alert(1)')\n // HTML body wraps the text in `<pre>` with all angle brackets escaped.\n expect(result.html).toBe('<pre>Plain alert(1)</pre>')\n })\n})\n";
@@ -0,0 +1,410 @@
1
+ "use strict";
2
+ /**
3
+ * Content for the optional adapter / renderer source files.
4
+ *
5
+ * These files are emitted to the generated project only when the matching
6
+ * adapter or renderer is enabled via `configureBackendMailGenerator`.
7
+ * Keeping them as plain string constants (rather than in the `template/`
8
+ * folder) means the generator never copies files the project will not
9
+ * compile and lets us gate both file emission and `package.json`
10
+ * dependencies on the same boolean.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.emailmdRendererTestSource = exports.emailmdRendererSource = exports.smtpAdapterTestSource = exports.smtpAdapterSource = exports.sesAdapterSource = void 0;
14
+ exports.sesAdapterSource = `import { SendEmailCommand, SESClient } from '@aws-sdk/client-ses'
15
+ import { Logger } from '@nestjs/common'
16
+
17
+ import type { IMailAdapter, MailPayload, MailSendResult, MailSendResultErrorStatus } from './mail-adapter.interface'
18
+
19
+ export type SesAdapterConfig = {
20
+ region: string
21
+ useCredentials: boolean
22
+ accessKey?: string
23
+ secretAccessKey?: string
24
+ }
25
+
26
+ const SES_INVALID_ADDRESS_ERRORS = new Set([
27
+ 'InvalidParameterValue',
28
+ 'InvalidParameterCombination',
29
+ 'InvalidEmailAddress',
30
+ 'MailFromDomainNotVerifiedException',
31
+ ])
32
+
33
+ export class SesAdapter implements IMailAdapter {
34
+ private readonly logger = new Logger(SesAdapter.name)
35
+ private readonly client: SESClient
36
+
37
+ constructor(config: SesAdapterConfig) {
38
+ this.client = new SESClient({
39
+ region: config.region,
40
+ credentials: config.useCredentials
41
+ ? {
42
+ accessKeyId: config.accessKey ?? '',
43
+ secretAccessKey: config.secretAccessKey ?? '',
44
+ }
45
+ : undefined,
46
+ })
47
+ }
48
+
49
+ public async send(payload: MailPayload): Promise<MailSendResult> {
50
+ try {
51
+ const result = await this.client.send(
52
+ new SendEmailCommand({
53
+ Source: payload.from,
54
+ Destination: {
55
+ ToAddresses: [payload.to],
56
+ BccAddresses: payload.bcc ?? [],
57
+ },
58
+ Message: {
59
+ Subject: { Charset: 'UTF-8', Data: payload.subject },
60
+ Body: {
61
+ Html: { Charset: 'UTF-8', Data: payload.html },
62
+ Text: { Charset: 'UTF-8', Data: payload.text ?? '' },
63
+ },
64
+ },
65
+ }),
66
+ )
67
+ return { success: true, status: 'sent', details: result.MessageId }
68
+ } catch (error) {
69
+ const status = classifySesError(error)
70
+ const message = describeError(error)
71
+ if (status === 'errorInvalidEmail') {
72
+ this.logger.warn(\`SES rejected invalid address: \${message}\`)
73
+ } else if (status === 'errorRejected') {
74
+ this.logger.warn(\`SES rejected mail: \${message}\`)
75
+ } else {
76
+ this.logger.error(\`SES send failed: \${message}\`, error instanceof Error ? error.stack : undefined)
77
+ }
78
+ return { success: false, status, details: message }
79
+ }
80
+ }
81
+ }
82
+
83
+ function classifySesError(error: unknown): MailSendResultErrorStatus {
84
+ if (!(error instanceof Error)) {
85
+ return 'errorOther'
86
+ }
87
+ if (SES_INVALID_ADDRESS_ERRORS.has(error.name)) {
88
+ return 'errorInvalidEmail'
89
+ }
90
+ if (error.name === 'MessageRejected') {
91
+ return 'errorRejected'
92
+ }
93
+ return 'errorOther'
94
+ }
95
+
96
+ function describeError(error: unknown): string {
97
+ return error instanceof Error ? \`\${error.name}: \${error.message}\` : String(error)
98
+ }
99
+ `;
100
+ exports.smtpAdapterSource = `/** Runtime verified on Node 24; Bun: untested. */
101
+ import { Logger } from '@nestjs/common'
102
+ import nodemailer, { type Transporter } from 'nodemailer'
103
+
104
+ import type { IMailAdapter, MailPayload, MailSendResult, MailSendResultErrorStatus } from './mail-adapter.interface'
105
+
106
+ export type SmtpAdapterConfig = {
107
+ host: string
108
+ port: number
109
+ secure: boolean
110
+ user: string
111
+ password: string
112
+ }
113
+
114
+ type NodemailerTransportOptions = {
115
+ host: string
116
+ port: number
117
+ secure: boolean
118
+ auth?: { user: string; pass: string }
119
+ }
120
+
121
+ /**
122
+ * Builds the nodemailer \`createTransport\` options from our adapter config.
123
+ *
124
+ * Exported so the auth-gating logic can be unit-tested directly - passing a
125
+ * partial credential pair (only user, only password) must result in auth
126
+ * being omitted entirely rather than sent with an empty field.
127
+ */
128
+ export function buildSmtpTransportOptions(config: SmtpAdapterConfig): NodemailerTransportOptions {
129
+ const hasAuth = config.user.length > 0 && config.password.length > 0
130
+ return {
131
+ host: config.host,
132
+ port: config.port,
133
+ secure: config.secure,
134
+ auth: hasAuth ? { user: config.user, pass: config.password } : undefined,
135
+ }
136
+ }
137
+
138
+ export class SmtpAdapter implements IMailAdapter {
139
+ private readonly logger = new Logger(SmtpAdapter.name)
140
+ private readonly transporter: Transporter
141
+
142
+ constructor(config: SmtpAdapterConfig, transporter?: Transporter) {
143
+ this.transporter = transporter ?? nodemailer.createTransport(buildSmtpTransportOptions(config))
144
+ }
145
+
146
+ public async send(payload: MailPayload): Promise<MailSendResult> {
147
+ try {
148
+ const info = (await this.transporter.sendMail({
149
+ from: payload.from,
150
+ to: payload.to,
151
+ bcc: payload.bcc,
152
+ subject: payload.subject,
153
+ html: payload.html,
154
+ text: payload.text,
155
+ })) as { messageId?: string }
156
+ return { success: true, status: 'sent', details: info.messageId }
157
+ } catch (error) {
158
+ const classified = classifySmtpError(error)
159
+ const message = describeError(error)
160
+ if (classified === 'errorRejected') {
161
+ this.logger.warn(\`SMTP rejected mail: \${message}\`)
162
+ } else if (classified === 'errorInvalidEmail') {
163
+ this.logger.warn(\`SMTP invalid address: \${message}\`)
164
+ } else {
165
+ this.logger.error(\`SMTP send failed: \${message}\`, error instanceof Error ? error.stack : undefined)
166
+ }
167
+ return { success: false, status: classified, details: message }
168
+ }
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Maps nodemailer / SMTP errors onto our adapter-agnostic status enum.
174
+ *
175
+ * \`errorInvalidEmail\` is reserved for errors that unambiguously point at a
176
+ * malformed or syntactically-invalid address (EENVELOPE, EMESSAGE, and the
177
+ * classic 501/553 response codes).
178
+ *
179
+ * Every other 5xx response is bucketed into \`errorRejected\`. Note that this
180
+ * deliberately groups "recipient does not exist" (550 mailbox unavailable)
181
+ * together with "your account is blocked" (550 spam-related) - SMTP does
182
+ * not give us enough signal to tell them apart reliably, and splitting them
183
+ * would make the enum less stable. Callers needing that distinction should
184
+ * inspect the \`details\` string.
185
+ */
186
+ function classifySmtpError(error: unknown): MailSendResultErrorStatus {
187
+ if (!(error instanceof Error)) {
188
+ return 'errorOther'
189
+ }
190
+ const code = (error as Error & { code?: string; responseCode?: number }).code
191
+ const responseCode = (error as Error & { responseCode?: number }).responseCode
192
+ if (code === 'EENVELOPE' || code === 'EMESSAGE' || responseCode === 501 || responseCode === 553) {
193
+ return 'errorInvalidEmail'
194
+ }
195
+ if (responseCode && responseCode >= 500 && responseCode < 600) {
196
+ return 'errorRejected'
197
+ }
198
+ return 'errorOther'
199
+ }
200
+
201
+ function describeError(error: unknown): string {
202
+ if (error instanceof Error) {
203
+ const withCode = error as Error & { code?: string; responseCode?: number }
204
+ const codeTag = withCode.code ?? (withCode.responseCode ? String(withCode.responseCode) : error.name)
205
+ return \`\${codeTag}: \${error.message}\`
206
+ }
207
+ return String(error)
208
+ }
209
+ `;
210
+ exports.smtpAdapterTestSource = `import { describe, expect, it, jest } from '@jest/globals'
211
+ import type { Transporter } from 'nodemailer'
212
+
213
+ import { buildSmtpTransportOptions, SmtpAdapter } from './smtp.adapter'
214
+
215
+ function createSpyTransporter(): { transporter: Transporter; sendMail: jest.Mock } {
216
+ const sendMail = jest.fn(() => Promise.resolve({ messageId: 'msg-123' }))
217
+ const transporter = { sendMail } as unknown as Transporter
218
+ return { transporter, sendMail }
219
+ }
220
+
221
+ describe('buildSmtpTransportOptions', () => {
222
+ const base = { host: 'smtp.example.com', port: 587, secure: false }
223
+
224
+ it('includes auth when both user and password are set', () => {
225
+ expect(buildSmtpTransportOptions({ ...base, user: 'alice', password: 'secret' })).toEqual({
226
+ ...base,
227
+ auth: { user: 'alice', pass: 'secret' },
228
+ })
229
+ })
230
+
231
+ it('omits auth entirely when only user is set', () => {
232
+ expect(buildSmtpTransportOptions({ ...base, user: 'alice', password: '' }).auth).toBeUndefined()
233
+ })
234
+
235
+ it('omits auth entirely when only password is set', () => {
236
+ expect(buildSmtpTransportOptions({ ...base, user: '', password: 'secret' }).auth).toBeUndefined()
237
+ })
238
+
239
+ it('omits auth entirely when neither is set', () => {
240
+ expect(buildSmtpTransportOptions({ ...base, user: '', password: '' }).auth).toBeUndefined()
241
+ })
242
+ })
243
+
244
+ describe('SmtpAdapter', () => {
245
+ it('marshals the payload through the transporter and returns success with the messageId', async () => {
246
+ const { transporter, sendMail } = createSpyTransporter()
247
+ const adapter = new SmtpAdapter({ host: 'unused', port: 587, secure: false, user: '', password: '' }, transporter)
248
+
249
+ const result = await adapter.send({
250
+ from: 'noreply@example.com',
251
+ to: 'user@example.com',
252
+ bcc: ['admin@example.com'],
253
+ subject: 'Hi there',
254
+ html: '<p>hello</p>',
255
+ text: 'hello',
256
+ })
257
+
258
+ expect(result.success).toBe(true)
259
+ if (!result.success) {
260
+ throw new Error('unreachable')
261
+ }
262
+ expect(result.status).toBe('sent')
263
+ expect(result.details).toBe('msg-123')
264
+
265
+ expect(sendMail).toHaveBeenCalledTimes(1)
266
+ expect(sendMail).toHaveBeenCalledWith({
267
+ from: 'noreply@example.com',
268
+ to: 'user@example.com',
269
+ bcc: ['admin@example.com'],
270
+ subject: 'Hi there',
271
+ html: '<p>hello</p>',
272
+ text: 'hello',
273
+ })
274
+ })
275
+
276
+ it('classifies invalid-address errors and returns a serialized details string', async () => {
277
+ const invalidErr = Object.assign(new Error('Bad recipient'), { code: 'EENVELOPE', responseCode: 501 })
278
+ const sendMail = jest.fn(() => Promise.reject(invalidErr))
279
+ const adapter = new SmtpAdapter({ host: 'unused', port: 587, secure: false, user: '', password: '' }, {
280
+ sendMail,
281
+ } as unknown as Transporter)
282
+
283
+ const result = await adapter.send({
284
+ from: 'noreply@example.com',
285
+ to: 'bad',
286
+ subject: 'x',
287
+ html: '<p>x</p>',
288
+ })
289
+
290
+ expect(result).toEqual({
291
+ success: false,
292
+ status: 'errorInvalidEmail',
293
+ details: 'EENVELOPE: Bad recipient',
294
+ })
295
+ })
296
+
297
+ it('classifies 5xx rejects as errorRejected', async () => {
298
+ const rejected = Object.assign(new Error('Mailbox unavailable'), { responseCode: 550 })
299
+ const sendMail = jest.fn(() => Promise.reject(rejected))
300
+ const adapter = new SmtpAdapter({ host: 'unused', port: 587, secure: false, user: '', password: '' }, {
301
+ sendMail,
302
+ } as unknown as Transporter)
303
+
304
+ const result = await adapter.send({
305
+ from: 'noreply@example.com',
306
+ to: 'user@example.com',
307
+ subject: 'x',
308
+ html: '<p>x</p>',
309
+ })
310
+
311
+ expect(result.success).toBe(false)
312
+ if (result.success) {
313
+ throw new Error('unreachable')
314
+ }
315
+ expect(result.status).toBe('errorRejected')
316
+ expect(result.details).toBe('550: Mailbox unavailable')
317
+ })
318
+ })
319
+ `;
320
+ exports.emailmdRendererSource = `import { Logger } from '@nestjs/common'
321
+ import { render } from 'emailmd'
322
+
323
+ import { htmlEscape, stripTags, substituteVariables, substituteVariablesRaw } from './simple.renderer'
324
+ import type { ITemplateRenderer, RenderedMail } from './template-renderer.interface'
325
+
326
+ export class EmailmdRenderer implements ITemplateRenderer {
327
+ private readonly logger = new Logger(EmailmdRenderer.name)
328
+
329
+ public render(source: string, data: Record<string, unknown>): RenderedMail {
330
+ const substituted = substituteVariables(source, data)
331
+ try {
332
+ const { html, text } = render(substituted)
333
+ return { html, text }
334
+ } catch (error) {
335
+ // \`emailmd\` is a pre-1.0 package that parses markdown via MJML;
336
+ // malformed input, internal MJML bugs, or upstream API churn can
337
+ // surface as thrown errors. Swallowing them would lose the mail, but
338
+ // letting them propagate through the dispatcher would fail the
339
+ // action with a confusing stack trace. Log + fall back to a simple
340
+ // escaped HTML + raw plain-text render so the mail still goes out.
341
+ const message = error instanceof Error ? \`\${error.name}: \${error.message}\` : String(error)
342
+ this.logger.warn(\`emailmd render failed, falling back to plain text: \${message}\`)
343
+ const rawText = stripTags(substituteVariablesRaw(source, data))
344
+ return {
345
+ html: \`<pre>\${htmlEscape(rawText)}</pre>\`,
346
+ text: rawText,
347
+ }
348
+ }
349
+ }
350
+ }
351
+ `;
352
+ exports.emailmdRendererTestSource = `import { describe, expect, it, jest } from '@jest/globals'
353
+
354
+ jest.mock('emailmd', () => ({
355
+ render: jest.fn(),
356
+ }))
357
+
358
+ import { render as emailmdRender } from 'emailmd'
359
+
360
+ import { EmailmdRenderer } from './emailmd.renderer'
361
+
362
+ const mockedRender = emailmdRender as unknown as jest.Mock
363
+
364
+ describe('EmailmdRenderer', () => {
365
+ it('returns the emailmd render output on success', () => {
366
+ mockedRender.mockReturnValueOnce({
367
+ html: '<html><body>Hello</body></html>',
368
+ text: 'Hello',
369
+ meta: {},
370
+ })
371
+
372
+ const renderer = new EmailmdRenderer()
373
+ const result = renderer.render('Hello {{name}}', { name: 'Ada' })
374
+
375
+ expect(result).toEqual({
376
+ html: '<html><body>Hello</body></html>',
377
+ text: 'Hello',
378
+ })
379
+ expect(mockedRender).toHaveBeenCalledWith('Hello Ada')
380
+ })
381
+
382
+ it('falls back to a plaintext render when emailmd throws', () => {
383
+ mockedRender.mockImplementationOnce(() => {
384
+ throw new Error('MJML parse error')
385
+ })
386
+
387
+ const renderer = new EmailmdRenderer()
388
+ const result = renderer.render('Hello {{name}}', { name: 'Ada' })
389
+
390
+ expect(result.text).toBe('Hello Ada')
391
+ expect(result.html).toBe('<pre>Hello Ada</pre>')
392
+ })
393
+
394
+ it('preserves raw characters in fallback text and escapes them in fallback html', () => {
395
+ mockedRender.mockImplementationOnce(() => {
396
+ throw new Error('boom')
397
+ })
398
+
399
+ const renderer = new EmailmdRenderer()
400
+ const result = renderer.render('Plain {{name}}', { name: '<script>alert(1)</script>' })
401
+
402
+ // Text body is the plain-text MIME part — stripTags removes the
403
+ // literal \`<script>\` wrapper and \`alert(1)\` survives.
404
+ expect(result.text).toBe('Plain alert(1)')
405
+ // HTML body wraps the text in \`<pre>\` with all angle brackets escaped.
406
+ expect(result.html).toBe('<pre>Plain alert(1)</pre>')
407
+ })
408
+ })
409
+ `;
410
+ //# sourceMappingURL=conditional-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditional-files.js","sourceRoot":"","sources":["../../../src/backend-mail/generators/conditional-files.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEU,QAAA,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqF/B,CAAA;AAEY,QAAA,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6GhC,CAAA;AAEY,QAAA,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6GpC,CAAA;AAEY,QAAA,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BpC,CAAA;AAEY,QAAA,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDxC,CAAA"}
@@ -0,0 +1,16 @@
1
+ import type { EnvConfig } from '../../backend-core';
2
+ import type { MailDeliveryAdapter, MailTemplateRenderer } from '../mail.generator';
3
+ export type BuildEnvConfigOptions = {
4
+ adapters: readonly ('log' | MailDeliveryAdapter)[];
5
+ renderers: readonly ('simple' | MailTemplateRenderer)[];
6
+ };
7
+ /**
8
+ * Builds the `dotEnvExample`, zod decoder, and transformer blocks for the
9
+ * mail module, only emitting the env vars, decoder entries, and
10
+ * transformer sub-objects for the adapters and renderers that were enabled
11
+ * via `configureBackendMailGenerator`.
12
+ *
13
+ * All three blocks are kept in sync through a single function so that
14
+ * adding a new adapter requires touching exactly one place.
15
+ */
16
+ export declare function buildEnvConfig({ adapters, renderers }: BuildEnvConfigOptions): EnvConfig;