@vendure/email-plugin 2.0.0-beta.1 → 2.0.0-beta.2
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/lib/src/common.d.ts +3 -1
- package/lib/src/common.js +10 -1
- package/lib/src/common.js.map +1 -1
- package/lib/src/email-processor.d.ts +8 -6
- package/lib/src/email-processor.js +30 -12
- package/lib/src/email-processor.js.map +1 -1
- package/lib/src/event-handler.d.ts +3 -0
- package/lib/src/event-handler.js +7 -4
- package/lib/src/event-handler.js.map +1 -1
- package/lib/src/handlebars-mjml-generator.d.ts +2 -3
- package/lib/src/handlebars-mjml-generator.js +5 -12
- package/lib/src/handlebars-mjml-generator.js.map +1 -1
- package/lib/src/mock-events.js.map +1 -1
- package/lib/src/plugin.d.ts +40 -2
- package/lib/src/plugin.js +54 -2
- package/lib/src/plugin.js.map +1 -1
- package/lib/src/template-loader.d.ts +5 -2
- package/lib/src/template-loader.js +17 -9
- package/lib/src/template-loader.js.map +1 -1
- package/lib/src/types.d.ts +66 -5
- package/package.json +4 -4
package/lib/src/common.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Injector, RequestContext } from '@vendure/core';
|
|
2
|
+
import { EmailPluginDevModeOptions, EmailPluginOptions, EmailTransportOptions } from './types';
|
|
2
3
|
export declare function isDevModeOptions(input: EmailPluginOptions | EmailPluginDevModeOptions): input is EmailPluginDevModeOptions;
|
|
4
|
+
export declare function resolveTransportSettings(options: EmailPluginOptions, injector: Injector, ctx?: RequestContext): Promise<EmailTransportOptions>;
|
package/lib/src/common.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDevModeOptions = void 0;
|
|
3
|
+
exports.resolveTransportSettings = exports.isDevModeOptions = void 0;
|
|
4
4
|
function isDevModeOptions(input) {
|
|
5
5
|
return input.devMode === true;
|
|
6
6
|
}
|
|
7
7
|
exports.isDevModeOptions = isDevModeOptions;
|
|
8
|
+
async function resolveTransportSettings(options, injector, ctx) {
|
|
9
|
+
if (typeof options.transport === 'function') {
|
|
10
|
+
return options.transport(injector, ctx);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return options.transport;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.resolveTransportSettings = resolveTransportSettings;
|
|
8
17
|
//# sourceMappingURL=common.js.map
|
package/lib/src/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":";;;AAIA,SAAgB,gBAAgB,CAC5B,KAAqD;IAErD,OAAQ,KAAmC,CAAC,OAAO,KAAK,IAAI,CAAC;AACjE,CAAC;AAJD,4CAIC;AAEM,KAAK,UAAU,wBAAwB,CAC1C,OAA2B,EAC3B,QAAkB,EAClB,GAAoB;IAEpB,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK,UAAU,EAAE;QACzC,OAAO,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;KAC3C;SAAM;QACH,OAAO,OAAO,CAAC,SAAS,CAAC;KAC5B;AACL,CAAC;AAVD,4DAUC"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
+
import { ModuleRef } from '@nestjs/core';
|
|
2
|
+
import { Injector, RequestContext } from '@vendure/core';
|
|
1
3
|
import { EmailGenerator } from './email-generator';
|
|
2
4
|
import { EmailSender } from './email-sender';
|
|
3
|
-
import {
|
|
4
|
-
import { EmailPluginOptions, EmailTransportOptions, IntermediateEmailDetails } from './types';
|
|
5
|
+
import { EmailTransportOptions, InitializedEmailPluginOptions, IntermediateEmailDetails } from './types';
|
|
5
6
|
/**
|
|
6
7
|
* This class combines the template loading, generation, and email sending - the actual "work" of
|
|
7
8
|
* the EmailPlugin. It is arranged this way primarily to accommodate easier testing, so that the
|
|
8
9
|
* tests can be run without needing all the JobQueue stuff which would require a full e2e test.
|
|
9
10
|
*/
|
|
10
11
|
export declare class EmailProcessor {
|
|
11
|
-
protected options:
|
|
12
|
-
|
|
12
|
+
protected options: InitializedEmailPluginOptions;
|
|
13
|
+
private moduleRef;
|
|
13
14
|
protected emailSender: EmailSender;
|
|
14
15
|
protected generator: EmailGenerator;
|
|
15
|
-
protected transport: EmailTransportOptions;
|
|
16
|
-
constructor(options:
|
|
16
|
+
protected transport: EmailTransportOptions | ((injector?: Injector, ctx?: RequestContext) => EmailTransportOptions | Promise<EmailTransportOptions>);
|
|
17
|
+
constructor(options: InitializedEmailPluginOptions, moduleRef: ModuleRef);
|
|
17
18
|
init(): Promise<void>;
|
|
18
19
|
process(data: IntermediateEmailDetails): Promise<boolean>;
|
|
20
|
+
getTransportSettings(ctx?: RequestContext): Promise<EmailTransportOptions>;
|
|
19
21
|
}
|
|
@@ -17,25 +17,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.EmailProcessor = void 0;
|
|
19
19
|
const common_1 = require("@nestjs/common");
|
|
20
|
-
const core_1 = require("@
|
|
20
|
+
const core_1 = require("@nestjs/core");
|
|
21
|
+
const core_2 = require("@vendure/core");
|
|
21
22
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
22
23
|
const attachment_utils_1 = require("./attachment-utils");
|
|
23
24
|
const common_2 = require("./common");
|
|
24
25
|
const constants_1 = require("./constants");
|
|
25
26
|
const handlebars_mjml_generator_1 = require("./handlebars-mjml-generator");
|
|
26
27
|
const nodemailer_email_sender_1 = require("./nodemailer-email-sender");
|
|
27
|
-
const template_loader_1 = require("./template-loader");
|
|
28
28
|
/**
|
|
29
29
|
* This class combines the template loading, generation, and email sending - the actual "work" of
|
|
30
30
|
* the EmailPlugin. It is arranged this way primarily to accommodate easier testing, so that the
|
|
31
31
|
* tests can be run without needing all the JobQueue stuff which would require a full e2e test.
|
|
32
32
|
*/
|
|
33
33
|
let EmailProcessor = class EmailProcessor {
|
|
34
|
-
constructor(options) {
|
|
34
|
+
constructor(options, moduleRef) {
|
|
35
35
|
this.options = options;
|
|
36
|
+
this.moduleRef = moduleRef;
|
|
36
37
|
}
|
|
37
38
|
async init() {
|
|
38
|
-
this.templateLoader = new template_loader_1.TemplateLoader(this.options.templatePath);
|
|
39
39
|
this.emailSender = this.options.emailSender ? this.options.emailSender : new nodemailer_email_sender_1.NodemailerEmailSender();
|
|
40
40
|
this.generator = this.options.emailGenerator
|
|
41
41
|
? this.options.emailGenerator
|
|
@@ -52,40 +52,58 @@ let EmailProcessor = class EmailProcessor {
|
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
54
|
if (!this.options.transport) {
|
|
55
|
-
throw new
|
|
55
|
+
throw new core_2.InternalServerError("When devMode is not set to true, the 'transport' property must be set.");
|
|
56
56
|
}
|
|
57
57
|
this.transport = this.options.transport;
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
const transport = await this.getTransportSettings();
|
|
60
|
+
if (transport.type === 'file') {
|
|
60
61
|
// ensure the configured directory exists before
|
|
61
62
|
// we attempt to write files to it
|
|
62
|
-
const emailPath =
|
|
63
|
+
const emailPath = transport.outputPath;
|
|
63
64
|
await fs_extra_1.default.ensureDir(emailPath);
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
async process(data) {
|
|
67
68
|
try {
|
|
68
|
-
const
|
|
69
|
+
const ctx = core_2.RequestContext.deserialize(data.ctx);
|
|
70
|
+
const bodySource = await this.options.templateLoader.loadTemplate(new core_2.Injector(this.moduleRef), ctx, {
|
|
71
|
+
templateName: data.templateFile,
|
|
72
|
+
type: data.type,
|
|
73
|
+
});
|
|
69
74
|
const generated = this.generator.generate(data.from, data.subject, bodySource, data.templateVars);
|
|
70
75
|
const emailDetails = Object.assign(Object.assign({}, generated), { recipient: data.recipient, attachments: (0, attachment_utils_1.deserializeAttachments)(data.attachments), cc: data.cc, bcc: data.bcc, replyTo: data.replyTo });
|
|
71
|
-
await this.
|
|
76
|
+
const transportSettings = await this.getTransportSettings(ctx);
|
|
77
|
+
await this.emailSender.send(emailDetails, transportSettings);
|
|
72
78
|
return true;
|
|
73
79
|
}
|
|
74
80
|
catch (err) {
|
|
75
81
|
if (err instanceof Error) {
|
|
76
|
-
|
|
82
|
+
core_2.Logger.error(err.message, constants_1.loggerCtx, err.stack);
|
|
77
83
|
}
|
|
78
84
|
else {
|
|
79
|
-
|
|
85
|
+
core_2.Logger.error(String(err), constants_1.loggerCtx);
|
|
80
86
|
}
|
|
81
87
|
throw err;
|
|
82
88
|
}
|
|
83
89
|
}
|
|
90
|
+
async getTransportSettings(ctx) {
|
|
91
|
+
if ((0, common_2.isDevModeOptions)(this.options)) {
|
|
92
|
+
return {
|
|
93
|
+
type: 'file',
|
|
94
|
+
raw: false,
|
|
95
|
+
outputPath: this.options.outputPath,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return (0, common_2.resolveTransportSettings)(this.options, new core_2.Injector(this.moduleRef), ctx);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
84
102
|
};
|
|
85
103
|
EmailProcessor = __decorate([
|
|
86
104
|
(0, common_1.Injectable)(),
|
|
87
105
|
__param(0, (0, common_1.Inject)(constants_1.EMAIL_PLUGIN_OPTIONS)),
|
|
88
|
-
__metadata("design:paramtypes", [Object])
|
|
106
|
+
__metadata("design:paramtypes", [Object, core_1.ModuleRef])
|
|
89
107
|
], EmailProcessor);
|
|
90
108
|
exports.EmailProcessor = EmailProcessor;
|
|
91
109
|
//# sourceMappingURL=email-processor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email-processor.js","sourceRoot":"","sources":["../../src/email-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,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iB,CAAC,CAAC;YAC7D,OAAO,IAAI,CAAC;SACf;QAAC,OAAO,GAAY,EAAE;YACnB,IAAI,GAAG,YAAY,KAAK,EAAE;gBACtB,aAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,qBAAS,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;aACnD;iBAAM;gBACH,aAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,qBAAS,CAAC,CAAC;aACxC;YACD,MAAM,GAAG,CAAC;SACb;IACL,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,GAAoB;QAC3C,IAAI,IAAA,yBAAgB,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YAChC,OAAO;gBACH,IAAI,EAAE,MAAM;gBACZ,GAAG,EAAE,KAAK;gBACV,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;aACtC,CAAC;SACL;aAAM;YACH,OAAO,IAAA,iCAAwB,EAAC,IAAI,CAAC,OAAO,EAAE,IAAI,eAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;SACpF;IACL,CAAC;CACJ,CAAA;AA1FY,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAYJ,WAAA,IAAA,eAAM,EAAC,gCAAoB,CAAC,CAAA;6CACV,gBAAS;GAZvB,cAAc,CA0F1B;AA1FY,wCAAc"}
|
|
@@ -211,6 +211,9 @@ export declare class EmailEventHandler<T extends string = string, Event extends
|
|
|
211
211
|
* @description
|
|
212
212
|
* Add configuration for another template other than the default `"body.hbs"`. Use this method to define specific
|
|
213
213
|
* templates for channels or languageCodes other than the default.
|
|
214
|
+
*
|
|
215
|
+
* @deprecated Define a custom TemplateLoader on plugin initalization to define templates based on the RequestContext.
|
|
216
|
+
* E.g. `EmailPlugin.init({ templateLoader: new CustomTemplateLoader() })`
|
|
214
217
|
*/
|
|
215
218
|
addTemplate(config: EmailTemplateConfig): EmailEventHandler<T, Event>;
|
|
216
219
|
/**
|
package/lib/src/event-handler.js
CHANGED
|
@@ -232,6 +232,9 @@ class EmailEventHandler {
|
|
|
232
232
|
* @description
|
|
233
233
|
* Add configuration for another template other than the default `"body.hbs"`. Use this method to define specific
|
|
234
234
|
* templates for channels or languageCodes other than the default.
|
|
235
|
+
*
|
|
236
|
+
* @deprecated Define a custom TemplateLoader on plugin initalization to define templates based on the RequestContext.
|
|
237
|
+
* E.g. `EmailPlugin.init({ templateLoader: new CustomTemplateLoader() })`
|
|
235
238
|
*/
|
|
236
239
|
addTemplate(config) {
|
|
237
240
|
this.configurations.push(config);
|
|
@@ -304,11 +307,11 @@ class EmailEventHandler {
|
|
|
304
307
|
}
|
|
305
308
|
}
|
|
306
309
|
if (!this.setRecipientFn) {
|
|
307
|
-
throw new Error(
|
|
310
|
+
throw new Error(`No setRecipientFn has been defined. ` +
|
|
308
311
|
`Remember to call ".setRecipient()" when setting up the EmailEventHandler for ${this.type}`);
|
|
309
312
|
}
|
|
310
313
|
if (this.from === undefined) {
|
|
311
|
-
throw new Error(
|
|
314
|
+
throw new Error(`No from field has been defined. ` +
|
|
312
315
|
`Remember to call ".setFrom()" when setting up the EmailEventHandler for ${this.type}`);
|
|
313
316
|
}
|
|
314
317
|
const { ctx } = event;
|
|
@@ -316,7 +319,7 @@ class EmailEventHandler {
|
|
|
316
319
|
const configuration = this.getBestConfiguration(ctx.channel.code, languageCode);
|
|
317
320
|
const subject = configuration ? configuration.subject : this.defaultSubject;
|
|
318
321
|
if (subject == null) {
|
|
319
|
-
throw new Error(
|
|
322
|
+
throw new Error(`No subject field has been defined. ` +
|
|
320
323
|
`Remember to call ".setSubject()" when setting up the EmailEventHandler for ${this.type}`);
|
|
321
324
|
}
|
|
322
325
|
const recipient = this.setRecipientFn(event);
|
|
@@ -330,7 +333,7 @@ class EmailEventHandler {
|
|
|
330
333
|
}
|
|
331
334
|
const attachments = await (0, attachment_utils_1.serializeAttachments)(attachmentsArray);
|
|
332
335
|
const optionalAddressFields = (_e = (await ((_d = this.setOptionalAddressFieldsFn) === null || _d === void 0 ? void 0 : _d.call(this, event)))) !== null && _e !== void 0 ? _e : {};
|
|
333
|
-
return Object.assign({ type: this.type, recipient, from: this.from, templateVars: Object.assign(Object.assign({}, globals), templateVars), subject, templateFile: configuration ? configuration.templateFile : 'body.hbs', attachments }, optionalAddressFields);
|
|
336
|
+
return Object.assign({ ctx: event.ctx.serialize(), type: this.type, recipient, from: this.from, templateVars: Object.assign(Object.assign({}, globals), templateVars), subject, templateFile: configuration ? configuration.templateFile : 'body.hbs', attachments }, optionalAddressFields);
|
|
334
337
|
}
|
|
335
338
|
/**
|
|
336
339
|
* @description
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-handler.js","sourceRoot":"","sources":["../../src/event-handler.ts"],"names":[],"mappings":";;;AAEA,wCAAiD;AAEjD,yDAA0D;AAC1D,2CAAwC;AAcxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8GG;AACH,MAAa,iBAAiB;IAgB1B,YAAmB,QAA+B,EAAS,KAAkB;QAA1D,aAAQ,GAAR,QAAQ,CAAuB;QAAS,UAAK,GAAL,KAAK,CAAa;QAVrE,cAAS,GAAqC,EAAE,CAAC;QACjD,mBAAc,GAA0B,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"event-handler.js","sourceRoot":"","sources":["../../src/event-handler.ts"],"names":[],"mappings":";;;AAEA,wCAAiD;AAEjD,yDAA0D;AAC1D,2CAAwC;AAcxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8GG;AACH,MAAa,iBAAiB;IAgB1B,YAAmB,QAA+B,EAAS,KAAkB;QAA1D,aAAQ,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AC,EAAE;YAC5C,OAAO,CACH,CAAC,CAAC,CAAC,WAAW,KAAK,WAAW,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS,CAAC;gBAC9D,CAAC,CAAC,YAAY,KAAK,YAAY,CAClC,CAAC;QACN,CAAC,CAAC,CAAC;QACH,IAAI,UAAU,EAAE;YACZ,OAAO,UAAU,CAAC;SACrB;QACD,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CACzC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,KAAK,WAAW,IAAI,CAAC,CAAC,YAAY,KAAK,SAAS,CACrE,CAAC;QACF,IAAI,YAAY,EAAE;YACd,OAAO,YAAY,CAAC;SACvB;QACD,OAAO;IACX,CAAC;CACJ;AA1SD,8CA0SC;AAED;;;;;;GAMG;AACH,MAAa,8BAKX,SAAQ,iBAA2B;IACjC,YACW,WAAyC,EAChD,QAA+B,EAC/B,KAAuB;QAEvB,KAAK,CAAC,QAAQ,EAAE,KAAY,CAAC,CAAC;QAJvB,gBAAW,GAAX,WAAW,CAA8B;IAKpD,CAAC;CACJ;AAbD,wEAaC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EmailGenerator } from './email-generator';
|
|
2
|
-
import {
|
|
2
|
+
import { InitializedEmailPluginOptions } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* @description
|
|
5
5
|
* Uses Handlebars (https://handlebarsjs.com/) to output MJML (https://mjml.io) which is then
|
|
@@ -9,12 +9,11 @@ import { EmailPluginDevModeOptions, EmailPluginOptions } from './types';
|
|
|
9
9
|
* @docsPage EmailGenerator
|
|
10
10
|
*/
|
|
11
11
|
export declare class HandlebarsMjmlGenerator implements EmailGenerator {
|
|
12
|
-
onInit(options:
|
|
12
|
+
onInit(options: InitializedEmailPluginOptions): Promise<void>;
|
|
13
13
|
generate(from: string, subject: string, template: string, templateVars: any): {
|
|
14
14
|
from: string;
|
|
15
15
|
subject: string;
|
|
16
16
|
body: string;
|
|
17
17
|
};
|
|
18
|
-
private registerPartials;
|
|
19
18
|
private registerHelpers;
|
|
20
19
|
}
|
|
@@ -5,10 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.HandlebarsMjmlGenerator = void 0;
|
|
7
7
|
const dateformat_1 = __importDefault(require("dateformat"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
8
|
const handlebars_1 = __importDefault(require("handlebars"));
|
|
10
9
|
const mjml_1 = __importDefault(require("mjml"));
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
10
|
/**
|
|
13
11
|
* @description
|
|
14
12
|
* Uses Handlebars (https://handlebarsjs.com/) to output MJML (https://mjml.io) which is then
|
|
@@ -18,9 +16,11 @@ const path_1 = __importDefault(require("path"));
|
|
|
18
16
|
* @docsPage EmailGenerator
|
|
19
17
|
*/
|
|
20
18
|
class HandlebarsMjmlGenerator {
|
|
21
|
-
onInit(options) {
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
async onInit(options) {
|
|
20
|
+
if (options.templateLoader.loadPartials) {
|
|
21
|
+
const partials = await options.templateLoader.loadPartials();
|
|
22
|
+
partials.forEach(({ name, content }) => handlebars_1.default.registerPartial(name, content));
|
|
23
|
+
}
|
|
24
24
|
this.registerHelpers();
|
|
25
25
|
}
|
|
26
26
|
generate(from, subject, template, templateVars) {
|
|
@@ -38,13 +38,6 @@ class HandlebarsMjmlGenerator {
|
|
|
38
38
|
const body = (0, mjml_1.default)(mjml).html;
|
|
39
39
|
return { from: fromResult, subject: subjectResult, body };
|
|
40
40
|
}
|
|
41
|
-
registerPartials(partialsPath) {
|
|
42
|
-
const partialsFiles = fs_extra_1.default.readdirSync(partialsPath);
|
|
43
|
-
for (const partialFile of partialsFiles) {
|
|
44
|
-
const partialContent = fs_extra_1.default.readFileSync(path_1.default.join(partialsPath, partialFile), 'utf-8');
|
|
45
|
-
handlebars_1.default.registerPartial(path_1.default.basename(partialFile, '.hbs'), partialContent);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
41
|
registerHelpers() {
|
|
49
42
|
handlebars_1.default.registerHelper('formatDate', (date, format) => {
|
|
50
43
|
if (!date) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlebars-mjml-generator.js","sourceRoot":"","sources":["../../src/handlebars-mjml-generator.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;
|
|
1
|
+
{"version":3,"file":"handlebars-mjml-generator.js","sourceRoot":"","sources":["../../src/handlebars-mjml-generator.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AAEpC,4DAAoC;AACpC,gDAA6B;AAW7B;;;;;;;GAOG;AACH,MAAa,uBAAuB;IAChC,KAAK,CAAC,MAAM,CAAC,OAAsC;QAC/C,IAAI,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE;YACrC,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC;YAC7D,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,oBAAU,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;SACtF;QACD,IAAI,CAAC,eAAe,EAAE,CAAC;IAC3B,CAAC;IAED,QAAQ,CAAC,IAAY,EAAE,OAAe,EAAE,QAAgB,EAAE,YAAiB;QACvE,MAAM,YAAY,GAAG,oBAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,eAAe,GAAG,oBAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACpD,MAAM,gBAAgB,GAAG,oBAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtD,0EAA0E;QAC1E,kHAAkH;QAClH,yEAAyE;QACzE,kEAAkE;QAClE,MAAM,e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AE,sBAAsB;YACzC,qBAAqB,EAAE,mDAAmD;SAC7E,CAAC;KACL;CACJ,CAAC,CACL,CAAC"}
|
package/lib/src/plugin.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { MiddlewareConsumer, NestModule, OnApplicationBootstrap, OnApplicationSh
|
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
3
|
import { EventBus, JobQueueService, ProcessContext, Type } from '@vendure/core';
|
|
4
4
|
import { EmailProcessor } from './email-processor';
|
|
5
|
-
import { EmailPluginDevModeOptions, EmailPluginOptions } from './types';
|
|
5
|
+
import { EmailPluginDevModeOptions, EmailPluginOptions, InitializedEmailPluginOptions } from './types';
|
|
6
6
|
/**
|
|
7
7
|
* @description
|
|
8
8
|
* The EmailPlugin creates and sends transactional emails based on Vendure events. By default, it uses an [MJML](https://mjml.io/)-based
|
|
@@ -63,6 +63,14 @@ import { EmailPluginDevModeOptions, EmailPluginOptions } from './types';
|
|
|
63
63
|
* `node_modules/\@vendure/email-plugin/templates` to a location of your choice, and then point the `templatePath` config
|
|
64
64
|
* property at that directory.
|
|
65
65
|
*
|
|
66
|
+
* * ### Dynamic Email Templates
|
|
67
|
+
* Instead of passing a static value to `templatePath`, use `templateLoader` to define a template path.
|
|
68
|
+
* ```ts
|
|
69
|
+
* EmailPlugin.init({
|
|
70
|
+
* ...,
|
|
71
|
+
* templateLoader: new FileBasedTemplateLoader(my/order-confirmation/templates)
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
66
74
|
* ## Customizing templates
|
|
67
75
|
*
|
|
68
76
|
* Emails are generated from templates which use [MJML](https://mjml.io/) syntax. MJML is an open-source HTML-like markup
|
|
@@ -150,6 +158,36 @@ import { EmailPluginDevModeOptions, EmailPluginOptions } from './types';
|
|
|
150
158
|
*
|
|
151
159
|
* For all available methods of extending a handler, see the {@link EmailEventHandler} documentation.
|
|
152
160
|
*
|
|
161
|
+
* ## Dynamic SMTP settings
|
|
162
|
+
*
|
|
163
|
+
* Instead of defining static transport settings, you can also provide a function that dynamically resolves
|
|
164
|
+
* channel aware transport settings.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* import { defaultEmailHandlers, EmailPlugin } from '\@vendure/email-plugin';
|
|
169
|
+
* import { MyTransportService } from './transport.services.ts';
|
|
170
|
+
* const config: VendureConfig = {
|
|
171
|
+
* plugins: [
|
|
172
|
+
* EmailPlugin.init({
|
|
173
|
+
* handlers: defaultEmailHandlers,
|
|
174
|
+
* templatePath: path.join(__dirname, 'static/email/templates'),
|
|
175
|
+
* transport: (injector, ctx) => {
|
|
176
|
+
* if (ctx) {
|
|
177
|
+
* return injector.get(MyTransportService).getSettings(ctx);
|
|
178
|
+
* } else {
|
|
179
|
+
* return {
|
|
180
|
+
type: 'smtp',
|
|
181
|
+
host: 'smtp.example.com',
|
|
182
|
+
// ... etc.
|
|
183
|
+
}
|
|
184
|
+
* }
|
|
185
|
+
* }
|
|
186
|
+
* }),
|
|
187
|
+
* ],
|
|
188
|
+
* };
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
153
191
|
* ## Dev mode
|
|
154
192
|
*
|
|
155
193
|
* For development, the `transport` option can be replaced by `devMode: true`. Doing so configures Vendure to use the
|
|
@@ -214,7 +252,7 @@ export declare class EmailPlugin implements OnApplicationBootstrap, OnApplicatio
|
|
|
214
252
|
private jobQueue;
|
|
215
253
|
private testingProcessor;
|
|
216
254
|
/** @internal */
|
|
217
|
-
constructor(eventBus: EventBus, moduleRef: ModuleRef, emailProcessor: EmailProcessor, jobQueueService: JobQueueService, processContext: ProcessContext, options:
|
|
255
|
+
constructor(eventBus: EventBus, moduleRef: ModuleRef, emailProcessor: EmailProcessor, jobQueueService: JobQueueService, processContext: ProcessContext, options: InitializedEmailPluginOptions);
|
|
218
256
|
/**
|
|
219
257
|
* Set the plugin options.
|
|
220
258
|
*/
|
package/lib/src/plugin.js
CHANGED
|
@@ -21,6 +21,7 @@ const common_2 = require("./common");
|
|
|
21
21
|
const constants_1 = require("./constants");
|
|
22
22
|
const dev_mailbox_1 = require("./dev-mailbox");
|
|
23
23
|
const email_processor_1 = require("./email-processor");
|
|
24
|
+
const template_loader_1 = require("./template-loader");
|
|
24
25
|
/**
|
|
25
26
|
* @description
|
|
26
27
|
* The EmailPlugin creates and sends transactional emails based on Vendure events. By default, it uses an [MJML](https://mjml.io/)-based
|
|
@@ -81,6 +82,14 @@ const email_processor_1 = require("./email-processor");
|
|
|
81
82
|
* `node_modules/\@vendure/email-plugin/templates` to a location of your choice, and then point the `templatePath` config
|
|
82
83
|
* property at that directory.
|
|
83
84
|
*
|
|
85
|
+
* * ### Dynamic Email Templates
|
|
86
|
+
* Instead of passing a static value to `templatePath`, use `templateLoader` to define a template path.
|
|
87
|
+
* ```ts
|
|
88
|
+
* EmailPlugin.init({
|
|
89
|
+
* ...,
|
|
90
|
+
* templateLoader: new FileBasedTemplateLoader(my/order-confirmation/templates)
|
|
91
|
+
* })
|
|
92
|
+
* ```
|
|
84
93
|
* ## Customizing templates
|
|
85
94
|
*
|
|
86
95
|
* Emails are generated from templates which use [MJML](https://mjml.io/) syntax. MJML is an open-source HTML-like markup
|
|
@@ -168,6 +177,36 @@ const email_processor_1 = require("./email-processor");
|
|
|
168
177
|
*
|
|
169
178
|
* For all available methods of extending a handler, see the {@link EmailEventHandler} documentation.
|
|
170
179
|
*
|
|
180
|
+
* ## Dynamic SMTP settings
|
|
181
|
+
*
|
|
182
|
+
* Instead of defining static transport settings, you can also provide a function that dynamically resolves
|
|
183
|
+
* channel aware transport settings.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* import { defaultEmailHandlers, EmailPlugin } from '\@vendure/email-plugin';
|
|
188
|
+
* import { MyTransportService } from './transport.services.ts';
|
|
189
|
+
* const config: VendureConfig = {
|
|
190
|
+
* plugins: [
|
|
191
|
+
* EmailPlugin.init({
|
|
192
|
+
* handlers: defaultEmailHandlers,
|
|
193
|
+
* templatePath: path.join(__dirname, 'static/email/templates'),
|
|
194
|
+
* transport: (injector, ctx) => {
|
|
195
|
+
* if (ctx) {
|
|
196
|
+
* return injector.get(MyTransportService).getSettings(ctx);
|
|
197
|
+
* } else {
|
|
198
|
+
* return {
|
|
199
|
+
type: 'smtp',
|
|
200
|
+
host: 'smtp.example.com',
|
|
201
|
+
// ... etc.
|
|
202
|
+
}
|
|
203
|
+
* }
|
|
204
|
+
* }
|
|
205
|
+
* }),
|
|
206
|
+
* ],
|
|
207
|
+
* };
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
171
210
|
* ## Dev mode
|
|
172
211
|
*
|
|
173
212
|
* For development, the `transport` option can be replaced by `devMode: true`. Doing so configures Vendure to use the
|
|
@@ -234,6 +273,18 @@ let EmailPlugin = EmailPlugin_1 = class EmailPlugin {
|
|
|
234
273
|
* Set the plugin options.
|
|
235
274
|
*/
|
|
236
275
|
static init(options) {
|
|
276
|
+
if (options.templateLoader) {
|
|
277
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
278
|
+
core_2.Logger.info(`Using custom template loader '${options.templateLoader.constructor.name}'`);
|
|
279
|
+
}
|
|
280
|
+
else if (!options.templateLoader && options.templatePath) {
|
|
281
|
+
// TODO: this else-if can be removed when deprecated templatePath is removed,
|
|
282
|
+
// because we will either have a custom template loader, or the default loader with a default path
|
|
283
|
+
options.templateLoader = new template_loader_1.FileBasedTemplateLoader(options.templatePath);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
throw new Error('You must either supply a templatePath or provide a custom templateLoader');
|
|
287
|
+
}
|
|
237
288
|
this.options = options;
|
|
238
289
|
return EmailPlugin_1;
|
|
239
290
|
}
|
|
@@ -241,10 +292,11 @@ let EmailPlugin = EmailPlugin_1 = class EmailPlugin {
|
|
|
241
292
|
async onApplicationBootstrap() {
|
|
242
293
|
await this.initInjectableStrategies();
|
|
243
294
|
await this.setupEventSubscribers();
|
|
244
|
-
|
|
295
|
+
const transport = await (0, common_2.resolveTransportSettings)(this.options, new core_2.Injector(this.moduleRef));
|
|
296
|
+
if (!(0, common_2.isDevModeOptions)(this.options) && transport.type === 'testing') {
|
|
245
297
|
// When running tests, we don't want to go through the JobQueue system,
|
|
246
298
|
// so we just call the email sending logic directly.
|
|
247
|
-
this.testingProcessor = new email_processor_1.EmailProcessor(this.options);
|
|
299
|
+
this.testingProcessor = new email_processor_1.EmailProcessor(this.options, this.moduleRef);
|
|
248
300
|
await this.testingProcessor.init();
|
|
249
301
|
}
|
|
250
302
|
else {
|
package/lib/src/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,uCAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,uCAAyC;AACzC,wCAauB;AAGvB,qCAAsE;AACtE,2CAA8D;AAC9D,+CAA2C;AAC3C,uDAAmD;AAEnD,uDAA4D;AAU5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4OG;AAMI,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAMpB,gBAAgB;IAChB,YACY,QAAkB,EAClB,SAAoB,EACpB,cAA8B,EAC9B,eAAgC,EAChC,cAA8B,EACA,OAAsC;QALpE,aAAQ,GAAR,QAAQ,CAAU;QAClB,cAAS,GAAT,SAAS,CAAW;QACpB,mB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C,SAAS,CAAC,CAAC;YAC9C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAC/B,KAAY,EACZ,aAAW,CAAC,OAAO,CAAC,kBAAkB,EACtC,QAAQ,CACX,CAAC;YACF,IAAI,CAAC,MAAM,EAAE;gBACT,OAAO;aACV;YACD,IAAI,IAAI,CAAC,QAAQ,EAAE;gBACf,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;aACnD;iBAAM,IAAI,IAAI,CAAC,gBAAgB,EAAE;gBAC9B,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aAC/C;SACJ;QAAC,OAAO,CAAM,EAAE;YACb,aAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,qBAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;SAC/C;IACL,CAAC;CACJ,CAAA;AAzHY,WAAW;IALvB,IAAA,oBAAa,EAAC;QACX,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,gCAAoB,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,aAAW,CAAC,OAAO,EAAE,EAAE,gCAAc,CAAC;QACrG,aAAa,EAAE,eAAe;KACjC,CAAC;IAcO,WAAA,IAAA,eAAM,EAAC,gCAAoB,CAAC,CAAA;qCALX,eAAQ;QACP,gBAAS;QACJ,gCAAc;QACb,sBAAe;QAChB,qBAAc;GAZjC,WAAW,CAyHvB;AAzHY,kCAAW"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { Injector, RequestContext } from '@vendure/core';
|
|
2
|
+
import { LoadTemplateInput, Partial, TemplateLoader } from './types';
|
|
1
3
|
/**
|
|
2
4
|
* Loads email templates according to the configured TemplateConfig values.
|
|
3
5
|
*/
|
|
4
|
-
export declare class TemplateLoader {
|
|
6
|
+
export declare class FileBasedTemplateLoader implements TemplateLoader {
|
|
5
7
|
private templatePath;
|
|
6
8
|
constructor(templatePath: string);
|
|
7
|
-
loadTemplate(
|
|
9
|
+
loadTemplate(_injector: Injector, _ctx: RequestContext, { type, templateName }: LoadTemplateInput): Promise<string>;
|
|
10
|
+
loadPartials(): Promise<Partial[]>;
|
|
8
11
|
}
|
|
@@ -3,22 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
6
|
+
exports.FileBasedTemplateLoader = void 0;
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
/**
|
|
10
10
|
* Loads email templates according to the configured TemplateConfig values.
|
|
11
11
|
*/
|
|
12
|
-
class
|
|
12
|
+
class FileBasedTemplateLoader {
|
|
13
13
|
constructor(templatePath) {
|
|
14
14
|
this.templatePath = templatePath;
|
|
15
15
|
}
|
|
16
|
-
async loadTemplate(type,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
async loadTemplate(_injector, _ctx, { type, templateName }) {
|
|
17
|
+
const templatePath = path_1.default.join(this.templatePath, type, templateName);
|
|
18
|
+
return promises_1.default.readFile(templatePath, 'utf-8');
|
|
19
|
+
}
|
|
20
|
+
async loadPartials() {
|
|
21
|
+
const partialsPath = path_1.default.join(this.templatePath, 'partials');
|
|
22
|
+
const partialsFiles = await promises_1.default.readdir(partialsPath);
|
|
23
|
+
return Promise.all(partialsFiles.map(async (file) => {
|
|
24
|
+
return {
|
|
25
|
+
name: path_1.default.basename(file, '.hbs'),
|
|
26
|
+
content: await promises_1.default.readFile(path_1.default.join(partialsPath, file), 'utf-8')
|
|
27
|
+
};
|
|
28
|
+
}));
|
|
21
29
|
}
|
|
22
30
|
}
|
|
23
|
-
exports.
|
|
31
|
+
exports.FileBasedTemplateLoader = FileBasedTemplateLoader;
|
|
24
32
|
//# sourceMappingURL=template-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-loader.js","sourceRoot":"","sources":["../../src/template-loader.ts"],"names":[],"mappings":";;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"template-loader.js","sourceRoot":"","sources":["../../src/template-loader.ts"],"names":[],"mappings":";;;;;;AACA,2DAA6B;AAC7B,gDAAwB;AAGxB;;GAEG;AACH,MAAa,uBAAuB;IAEhC,YAAoB,YAAoB;QAApB,iBAAY,GAAZ,YAAY,CAAQ;IAAI,CAAC;IAE7C,KAAK,CAAC,YAAY,CACd,SAAmB,EACnB,IAAoB,EACpB,EAAE,IAAI,EAAE,YAAY,EAAqB;QAEzC,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QACtE,OAAO,kBAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,YAAY;QACd,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QAC9D,MAAM,aAAa,GAAG,MAAM,kBAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACrD,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAChD,OAAO;gBACH,IAAI,EAAE,cAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBACjC,OAAO,EAAE,MAAM,kBAAE,CAAC,QAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC;aACrE,CAAA;QACL,CAAC,CAAC,CAAC,CAAC;IACR,CAAC;CACJ;AAvBD,0DAuBC"}
|
package/lib/src/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LanguageCode } from '@vendure/common/lib/generated-types';
|
|
2
2
|
import { Omit } from '@vendure/common/lib/omit';
|
|
3
|
-
import { Injector, RequestContext, VendureEvent } from '@vendure/core';
|
|
3
|
+
import { Injector, RequestContext, SerializedRequestContext, VendureEvent } from '@vendure/core';
|
|
4
4
|
import { Attachment } from 'nodemailer/lib/mailer';
|
|
5
5
|
import SESTransport from 'nodemailer/lib/ses-transport';
|
|
6
6
|
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
@@ -42,13 +42,23 @@ export interface EmailPluginOptions {
|
|
|
42
42
|
* @description
|
|
43
43
|
* The path to the location of the email templates. In a default Vendure installation,
|
|
44
44
|
* the templates are installed to `<project root>/vendure/email/templates`.
|
|
45
|
+
*
|
|
46
|
+
* @deprecated Use `templateLoader` to define a template path: `templateLoader: new FileBasedTemplateLoader('../your-path/templates')`
|
|
45
47
|
*/
|
|
46
|
-
templatePath
|
|
48
|
+
templatePath?: string;
|
|
49
|
+
/**
|
|
50
|
+
* @description
|
|
51
|
+
* An optional TemplateLoader which can be used to load templates from a custom location or async service.
|
|
52
|
+
* The default uses the FileBasedTemplateLoader which loads templates from `<project root>/vendure/email/templates`
|
|
53
|
+
*
|
|
54
|
+
* @since 2.0.0
|
|
55
|
+
*/
|
|
56
|
+
templateLoader?: TemplateLoader;
|
|
47
57
|
/**
|
|
48
58
|
* @description
|
|
49
59
|
* Configures how the emails are sent.
|
|
50
60
|
*/
|
|
51
|
-
transport: EmailTransportOptions;
|
|
61
|
+
transport: EmailTransportOptions | ((injector?: Injector, ctx?: RequestContext) => EmailTransportOptions | Promise<EmailTransportOptions>);
|
|
52
62
|
/**
|
|
53
63
|
* @description
|
|
54
64
|
* An array of {@link EmailEventHandler}s which define which Vendure events will trigger
|
|
@@ -81,6 +91,12 @@ export interface EmailPluginOptions {
|
|
|
81
91
|
*/
|
|
82
92
|
emailGenerator?: EmailGenerator;
|
|
83
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* EmailPLuginOptions type after initialization, where templateLoader is no longer optional
|
|
96
|
+
*/
|
|
97
|
+
export type InitializedEmailPluginOptions = EmailPluginOptions & {
|
|
98
|
+
templateLoader: TemplateLoader;
|
|
99
|
+
};
|
|
84
100
|
/**
|
|
85
101
|
* @description
|
|
86
102
|
* Configuration for running the EmailPlugin in development mode.
|
|
@@ -269,6 +285,7 @@ export type SerializedAttachment = OptionalToNullable<Omit<EmailAttachment, 'con
|
|
|
269
285
|
content: string | null;
|
|
270
286
|
}>;
|
|
271
287
|
export type IntermediateEmailDetails = {
|
|
288
|
+
ctx: SerializedRequestContext;
|
|
272
289
|
type: string;
|
|
273
290
|
from: string;
|
|
274
291
|
recipient: string;
|
|
@@ -285,8 +302,7 @@ export type IntermediateEmailDetails = {
|
|
|
285
302
|
* Configures the {@link EmailEventHandler} to handle a particular channel & languageCode
|
|
286
303
|
* combination.
|
|
287
304
|
*
|
|
288
|
-
* @
|
|
289
|
-
* @docsPage Email Plugin Types
|
|
305
|
+
* @deprecated Use a custom {@link TemplateLoader} instead.
|
|
290
306
|
*/
|
|
291
307
|
export interface EmailTemplateConfig {
|
|
292
308
|
/**
|
|
@@ -313,6 +329,51 @@ export interface EmailTemplateConfig {
|
|
|
313
329
|
*/
|
|
314
330
|
subject: string;
|
|
315
331
|
}
|
|
332
|
+
export interface LoadTemplateInput {
|
|
333
|
+
type: string;
|
|
334
|
+
templateName: string;
|
|
335
|
+
}
|
|
336
|
+
export interface Partial {
|
|
337
|
+
name: string;
|
|
338
|
+
content: string;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* @description
|
|
342
|
+
* Load an email template based on the given request context, type and template name
|
|
343
|
+
* and return the template as a string.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```TypeScript
|
|
347
|
+
* import { EmailPlugin, TemplateLoader } from '@vendure/email-plugin';
|
|
348
|
+
*
|
|
349
|
+
* class MyTemplateLoader implements TemplateLoader {
|
|
350
|
+
* loadTemplate(injector, ctx, { type, templateName }){
|
|
351
|
+
* return myCustomTemplateFunction(ctx);
|
|
352
|
+
* }
|
|
353
|
+
* }
|
|
354
|
+
*
|
|
355
|
+
* // In vendure-config.ts:
|
|
356
|
+
* ...
|
|
357
|
+
* EmailPlugin.init({
|
|
358
|
+
* templateLoader: new MyTemplateLoader()
|
|
359
|
+
* ...
|
|
360
|
+
* })
|
|
361
|
+
* ```
|
|
362
|
+
*
|
|
363
|
+
* @docsCategory EmailPlugin
|
|
364
|
+
* @docsPage Custom Template Loader
|
|
365
|
+
*/
|
|
366
|
+
export interface TemplateLoader {
|
|
367
|
+
/**
|
|
368
|
+
* Load template and return it's content as a string
|
|
369
|
+
*/
|
|
370
|
+
loadTemplate(injector: Injector, ctx: RequestContext, input: LoadTemplateInput): Promise<string>;
|
|
371
|
+
/**
|
|
372
|
+
* Load partials and return their contents.
|
|
373
|
+
* This method is only called during initalization, i.e. during server startup.
|
|
374
|
+
*/
|
|
375
|
+
loadPartials?(): Promise<Partial[]>;
|
|
376
|
+
}
|
|
316
377
|
/**
|
|
317
378
|
* @description
|
|
318
379
|
* A function used to define template variables available to email templates.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vendure/email-plugin",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"@types/fs-extra": "^9.0.1",
|
|
36
36
|
"@types/handlebars": "^4.1.0",
|
|
37
37
|
"@types/mjml": "^4.0.4",
|
|
38
|
-
"@vendure/common": "
|
|
39
|
-
"@vendure/core": "
|
|
38
|
+
"@vendure/common": "2.0.0-beta.2",
|
|
39
|
+
"@vendure/core": "2.0.0-beta.2",
|
|
40
40
|
"rimraf": "^3.0.2",
|
|
41
41
|
"typescript": "4.9.5"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "30a297e9afabcfd129d30c843cabd1b5761046a6"
|
|
44
44
|
}
|