@postxl/generators 1.24.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.
- package/dist/backend-actions/actions.generator.d.ts +11 -0
- package/dist/backend-actions/actions.generator.js.map +1 -1
- package/dist/backend-actions/generators/actions-module.generator.js +11 -3
- package/dist/backend-actions/generators/actions-module.generator.js.map +1 -1
- package/dist/backend-actions/generators/dispatcher-service.generator.js +12 -4
- package/dist/backend-actions/generators/dispatcher-service.generator.js.map +1 -1
- package/dist/backend-core/backend.generator.js +72 -40
- package/dist/backend-core/backend.generator.js.map +1 -1
- package/dist/backend-mail/generators/conditional-files.d.ts +15 -0
- package/dist/backend-mail/generators/conditional-files.js +410 -0
- package/dist/backend-mail/generators/conditional-files.js.map +1 -0
- package/dist/backend-mail/generators/env-config.generator.d.ts +16 -0
- package/dist/backend-mail/generators/env-config.generator.js +167 -0
- package/dist/backend-mail/generators/env-config.generator.js.map +1 -0
- package/dist/backend-mail/generators/mail.service.generator.d.ts +11 -0
- package/dist/backend-mail/generators/mail.service.generator.js +243 -0
- package/dist/backend-mail/generators/mail.service.generator.js.map +1 -0
- package/dist/backend-mail/index.d.ts +5 -0
- package/dist/backend-mail/index.js +41 -0
- package/dist/backend-mail/index.js.map +1 -0
- package/dist/backend-mail/mail.generator.d.ts +78 -0
- package/dist/backend-mail/mail.generator.js +162 -0
- package/dist/backend-mail/mail.generator.js.map +1 -0
- package/dist/backend-mail/template/src/adapters/log.adapter.ts +14 -0
- package/dist/backend-mail/template/src/adapters/mail-adapter.interface.ts +27 -0
- package/dist/backend-mail/template/src/mail.config.ts +42 -0
- package/dist/backend-mail/template/src/mail.module.ts +37 -0
- package/dist/backend-mail/template/src/mail.service.test.ts +195 -0
- package/dist/backend-mail/template/src/mail.types.ts +67 -0
- package/dist/backend-mail/template/src/templates/simple.renderer.test.ts +155 -0
- package/dist/backend-mail/template/src/templates/simple.renderer.ts +171 -0
- package/dist/backend-mail/template/src/templates/template-renderer.interface.ts +5 -0
- package/dist/backend-mail/template/tsconfig.lib.json +10 -0
- package/dist/decoders/field-decoder.helper.js +7 -0
- package/dist/decoders/field-decoder.helper.js.map +1 -1
- package/dist/frontend-admin/generators/admin-overview-page.generator.js +24 -2
- package/dist/frontend-admin/generators/admin-overview-page.generator.js.map +1 -1
- package/dist/frontend-forms/generators/discriminated-union/fields.generator.js +6 -4
- package/dist/frontend-forms/generators/discriminated-union/fields.generator.js.map +1 -1
- package/dist/frontend-forms/generators/model/forms.generator.js +6 -4
- package/dist/frontend-forms/generators/model/forms.generator.js.map +1 -1
- package/dist/generators.js +2 -0
- package/dist/generators.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/types/generators/model-type.generator.js +1 -1
- package/dist/types/generators/model-type.generator.js.map +1 -1
- package/dist/types/types.generator.js +3 -4
- package/dist/types/types.generator.js.map +1 -1
- 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;
|
|
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;AA4H7F,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,GAAG,SAAS,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,CAAA;AAEjE,QAAA,SAAS,GAAiC;IACrD,EAAE,EAAE,mBAAW;IACf,QAAQ,EAAE,CAAC,iCAAkB,EAAE,sBAAe,EAAE,wBAAgB,EAAE,6CAAmB,CAAC;IAEtF,QAAQ,EAAE,CAAsC,OAAgB,EAAwB,EAAE;QACxF,aAAa,CAAC,OAAO,CAAC,CAAA;QAEtB,MAAM,MAAM,GAA6B;YACvC,IAAI,EAAE,SAAS,CAAC,WAAW,CAAC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,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
|
-
|
|
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
|
-
|
|
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 {
|
|
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,
|
|
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,GAA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AI;;;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
|
-
|
|
23
|
+
let anyProviderUsesForwardRef = false;
|
|
24
|
+
for (const { service, scopes, needsForwardRef = true } of actions.providers) {
|
|
24
25
|
imports.add(service);
|
|
25
|
-
|
|
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 {
|
|
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,
|
|
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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;;;;;;;;;;;;;;;;eAgC3E,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,IAAI,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI;;;;;;;;;;QAUlF,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;CAOhC,CAAA;AACD,CAAC"}
|
|
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.backendGenerator = exports.backendGeneratorId = void 0;
|
|
37
37
|
const path = __importStar(require("node:path"));
|
|
38
38
|
const Generator = __importStar(require("@postxl/generator"));
|
|
39
|
+
const schema_1 = require("@postxl/schema");
|
|
39
40
|
const api_config_generator_1 = require("./generators/api-config.generator");
|
|
40
41
|
const api_module_generator_1 = require("./generators/api-module.generator");
|
|
41
42
|
const dotenv_example_generator_1 = require("./generators/dotenv-example.generator");
|
|
@@ -73,45 +74,76 @@ const baseDevDependencies = [
|
|
|
73
74
|
{ packageName: 'typescript', version: '5.9.3' },
|
|
74
75
|
{ packageName: 'webpack', version: '5.105.2' },
|
|
75
76
|
];
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
77
|
+
function devRoleCommand(role) {
|
|
78
|
+
return `dotenvx run -f ./apps/api/.env --env STATEFUL=false --env AUTH=false --env AUTH_MOCK_ROLES=${role} -- nest start --debug --watch`;
|
|
79
|
+
}
|
|
80
|
+
function collectAdminUiRoles(context) {
|
|
81
|
+
const modelRoles = [...(context.schema.models?.values() ?? [])].flatMap((model) => model.auth?.adminUi?.visibleFor ?? []);
|
|
82
|
+
const schemaRoles = [...(context.schema.schemaAuth?.values() ?? [])].flatMap((rules) => rules?.adminUi?.visibleFor ?? []);
|
|
83
|
+
return [...modelRoles, ...schemaRoles];
|
|
84
|
+
}
|
|
85
|
+
function roleWithHighestCount(roleCounts, fallback) {
|
|
86
|
+
let bestRole = fallback;
|
|
87
|
+
let bestCount = -1;
|
|
88
|
+
for (const [role, count] of roleCounts) {
|
|
89
|
+
if (count > bestCount) {
|
|
90
|
+
bestCount = count;
|
|
91
|
+
bestRole = role;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return bestRole;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Determines the default role for the `dev` script.
|
|
98
|
+
* Prefers 'superadmin' if present, otherwise picks the role with the most
|
|
99
|
+
* adminUi model/schema visibility. When no adminUi rules exist (all counts
|
|
100
|
+
* are 0), falls back to the first role in the list.
|
|
101
|
+
*/
|
|
102
|
+
function getDefaultDevRole(context) {
|
|
103
|
+
const roles = context.schema.defaultRoles ?? [...schema_1.defaultProjectRoles];
|
|
104
|
+
if (roles.includes('superadmin')) {
|
|
105
|
+
return 'superadmin';
|
|
106
|
+
}
|
|
107
|
+
const roleCounts = new Map(roles.map((role) => [role, 0]));
|
|
108
|
+
for (const role of collectAdminUiRoles(context)) {
|
|
109
|
+
if (roleCounts.has(role)) {
|
|
110
|
+
roleCounts.set(role, roleCounts.get(role) + 1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return roleWithHighestCount(roleCounts, roles[0]);
|
|
114
|
+
}
|
|
115
|
+
function createBaseScripts(context) {
|
|
116
|
+
const roles = context.schema.defaultRoles ?? [...schema_1.defaultProjectRoles];
|
|
117
|
+
const defaultRole = getDefaultDevRole(context);
|
|
118
|
+
const roleScripts = roles.map((role) => ({
|
|
119
|
+
name: `dev:${role}`,
|
|
120
|
+
command: devRoleCommand(role),
|
|
121
|
+
}));
|
|
122
|
+
return [
|
|
123
|
+
{ name: 'build', command: 'nest build' },
|
|
124
|
+
{ name: 'start', command: 'node ./dist/apps/api/apps/api/src/main.js' },
|
|
125
|
+
{
|
|
126
|
+
name: 'dev',
|
|
127
|
+
command: devRoleCommand(defaultRole),
|
|
128
|
+
},
|
|
129
|
+
...roleScripts,
|
|
130
|
+
{
|
|
131
|
+
name: 'dev:auth',
|
|
132
|
+
command: 'dotenvx run -f ./apps/api/.env --env STATEFUL=false --env AUTH=true -- nest start --debug --watch',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'dev:stateful',
|
|
136
|
+
command: 'dotenvx run -f ./apps/api/.env --env STATEFUL=true --env AUTH=false -- nest start --debug --watch',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'dev:stateful:auth',
|
|
140
|
+
command: 'dotenvx run -f ./apps/api/.env --env STATEFUL=true --env AUTH=true -- nest start --debug --watch',
|
|
141
|
+
},
|
|
142
|
+
{ name: 'lint', command: 'eslint .' },
|
|
143
|
+
{ name: 'test:jest', command: 'jest' },
|
|
144
|
+
{ name: 'test:types', command: 'tsc --noEmit' },
|
|
145
|
+
];
|
|
146
|
+
}
|
|
115
147
|
exports.backendGeneratorId = Generator.toGeneratorInterfaceId('backend-core');
|
|
116
148
|
exports.backendGenerator = {
|
|
117
149
|
id: exports.backendGeneratorId,
|
|
@@ -123,7 +155,7 @@ exports.backendGenerator = {
|
|
|
123
155
|
description: `API for the ${context.schema.name} project`,
|
|
124
156
|
dependencies: baseDependencies,
|
|
125
157
|
devDependencies: baseDevDependencies,
|
|
126
|
-
scripts:
|
|
158
|
+
scripts: createBaseScripts(context),
|
|
127
159
|
isInPostXlWorkspace: context.schema.projectType === 'workspace',
|
|
128
160
|
},
|
|
129
161
|
tsConfigReferences: ['utils'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend.generator.js","sourceRoot":"","sources":["../../src/backend-core/backend.generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAiC;AAEjC,6DAA8C;
|
|
1
|
+
{"version":3,"file":"backend.generator.js","sourceRoot":"","sources":["../../src/backend-core/backend.generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAiC;AAEjC,6DAA8C;AAC9C,2CAAoD;AAEpD,4EAAqE;AACrE,4EAAqE;AACrE,oFAA6E;AAC7E,8EAAuE;AACvE,gEAA0D;AAC1D,wEAAkE;AAGlE,MAAM,gBAAgB,GAAkC;IACtD,EAAE,WAAW,EAAE,iBAAiB,EAAE,OAAO,EAAE,QAAQ,EAAE;IACrD,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE;IACnD,EAAE,WAAW,EAAE,iBAAiB,EAAE,OAAO,EAAE,QAAQ,EAAE;IACrD,EAAE,WAAW,EAAE,gBAAgB,EAAE,OAAO,EAAE,SAAS,EAAE;IACrD,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE;IACnD,EAAE,WAAW,EAAE,0BAA0B,EAAE,OAAO,EAAE,SAAS,EAAE;IAC/D,EAAE,WAAW,EAAE,oBAAoB,EAAE,OAAO,EAAE,QAAQ,EAAE;IACxD,EAAE,WAAW,EAAE,SAAS,CAAC,mBAAmB,CAAC,eAAe,CAAC,EAAE;IAC/D,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE;IAC3C,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE;IACjD,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE;IAC7C,8FAA8F;IAC9F,EAAE,WAAW,E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CAAC,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAA;QAClF,GAAG,CAAC,KAAK,CAAC,gBAAgB,EAAE,IAAA,qCAAgB,EAAC,GAAG,CAAC,CAAC,CAAA;QAClD,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,IAAA,0CAAkB,EAAC,GAAG,CAAC,CAAC,CAAA;QACrD,GAAG,CAAC,KAAK,CAAC,6BAA6B,EAAE,IAAA,wCAAiB,EAAC,GAAG,CAAC,CAAC,CAAA;QAChE,GAAG,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAA,6BAAY,EAAC,GAAG,CAAC,CAAC,CAAA;QACrD,GAAG,CAAC,KAAK,CAAC,6BAA6B,EAAE,IAAA,wCAAiB,EAAC,GAAG,CAAC,CAAC,CAAA;QAEhE,MAAM,GAAG,GAAG,IAAA,gDAAqB,EAAC,GAAG,CAAC,CAAA;QACtC,GAAG,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAA;QAExC,0BAA0B;QAC1B,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACzC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;gBACf,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAA;YACxC,CAAC;QACH,CAAC;QAED,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAA;QACtD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content for the optional adapter / renderer source files.
|
|
3
|
+
*
|
|
4
|
+
* These files are emitted to the generated project only when 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";
|