@vendure/email-plugin 2.2.7 → 2.3.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/lib/src/handler/event-handler.d.ts +3 -2
- package/lib/src/handler/event-handler.js +11 -2
- package/lib/src/handler/event-handler.js.map +1 -1
- package/lib/src/plugin.d.ts +32 -0
- package/lib/src/plugin.js +37 -1
- package/lib/src/plugin.js.map +1 -1
- package/lib/src/types.d.ts +46 -4
- package/package.json +4 -4
|
@@ -2,7 +2,7 @@ import { LanguageCode } from '@vendure/common/lib/generated-types';
|
|
|
2
2
|
import { Type } from '@vendure/common/lib/shared-types';
|
|
3
3
|
import { Injector } from '@vendure/core';
|
|
4
4
|
import { EmailEventListener } from '../event-listener';
|
|
5
|
-
import { EmailTemplateConfig, EventWithAsyncData, EventWithContext, IntermediateEmailDetails, LoadDataFn, SetAttachmentsFn, SetOptionalAddressFieldsFn, SetTemplateVarsFn } from '../types';
|
|
5
|
+
import { EmailTemplateConfig, EventWithAsyncData, EventWithContext, IntermediateEmailDetails, LoadDataFn, SetAttachmentsFn, SetOptionalAddressFieldsFn, SetSubjectFn, SetTemplateVarsFn } from '../types';
|
|
6
6
|
/**
|
|
7
7
|
* @description
|
|
8
8
|
* The EmailEventHandler defines how the EmailPlugin will respond to a given event.
|
|
@@ -123,6 +123,7 @@ export declare class EmailEventHandler<T extends string = string, Event extends
|
|
|
123
123
|
event: Type<Event>;
|
|
124
124
|
private setRecipientFn;
|
|
125
125
|
private setLanguageCodeFn;
|
|
126
|
+
private setSubjectFn?;
|
|
126
127
|
private setTemplateVarsFn;
|
|
127
128
|
private setAttachmentsFn?;
|
|
128
129
|
private setOptionalAddressFieldsFn?;
|
|
@@ -170,7 +171,7 @@ export declare class EmailEventHandler<T extends string = string, Event extends
|
|
|
170
171
|
* Sets the default subject of the email. The subject string may use Handlebars variables defined by the
|
|
171
172
|
* setTemplateVars() method.
|
|
172
173
|
*/
|
|
173
|
-
setSubject(defaultSubject: string): EmailEventHandler<T, Event>;
|
|
174
|
+
setSubject(defaultSubject: string | SetSubjectFn<Event>): EmailEventHandler<T, Event>;
|
|
174
175
|
/**
|
|
175
176
|
* @description
|
|
176
177
|
* Sets the default from field of the email. The from string may use Handlebars variables defined by the
|
|
@@ -180,7 +180,12 @@ class EmailEventHandler {
|
|
|
180
180
|
* setTemplateVars() method.
|
|
181
181
|
*/
|
|
182
182
|
setSubject(defaultSubject) {
|
|
183
|
-
|
|
183
|
+
if (typeof defaultSubject === 'string') {
|
|
184
|
+
this.defaultSubject = defaultSubject;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
this.setSubjectFn = defaultSubject;
|
|
188
|
+
}
|
|
184
189
|
return this;
|
|
185
190
|
}
|
|
186
191
|
/**
|
|
@@ -322,7 +327,11 @@ class EmailEventHandler {
|
|
|
322
327
|
const { ctx } = event;
|
|
323
328
|
const languageCode = ((_a = this.setLanguageCodeFn) === null || _a === void 0 ? void 0 : _a.call(this, event)) || ctx.languageCode;
|
|
324
329
|
const configuration = this.getBestConfiguration(ctx.channel.code, languageCode);
|
|
325
|
-
const subject = configuration
|
|
330
|
+
const subject = configuration
|
|
331
|
+
? configuration.subject
|
|
332
|
+
: this.setSubjectFn
|
|
333
|
+
? await this.setSubjectFn(event, ctx, injector)
|
|
334
|
+
: this.defaultSubject;
|
|
326
335
|
if (subject == null) {
|
|
327
336
|
throw new Error(`No subject field has been defined. ` +
|
|
328
337
|
`Remember to call ".setSubject()" when setting up the EmailEventHandler for ${this.type}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-handler.js","sourceRoot":"","sources":["../../../src/handler/event-handler.ts"],"names":[],"mappings":";;;AAEA,wCAAiD;AAEjD,0DAA2D;AAC3D,4CAAyC;
|
|
1
|
+
{"version":3,"file":"event-handler.js","sourceRoot":"","sources":["../../../src/handler/event-handler.ts"],"names":[],"mappings":";;;AAEA,wCAAiD;AAEjD,0DAA2D;AAC3D,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/B,KAAuB;QAEvB,KAAK,CAAC,QAAQ,EAAE,KAAY,CAAC,CAAC;QAJvB,gBAAW,GAAX,WAAW,CAA8B;IAKpD,CAAC;CACJ;AAbD,wEAaC"}
|
package/lib/src/plugin.d.ts
CHANGED
|
@@ -94,6 +94,38 @@ import { EmailPluginDevModeOptions, EmailPluginOptions, InitializedEmailPluginOp
|
|
|
94
94
|
* </mj-table>
|
|
95
95
|
* ```
|
|
96
96
|
*
|
|
97
|
+
* ### Setting global variables using `globalTemplateVars`
|
|
98
|
+
*
|
|
99
|
+
* `globalTemplateVars` is an object that can be passed to the configuration of the Email Plugin with static object variables.
|
|
100
|
+
* You can also pass an async function that will be called with the `RequestContext` and the `Injector` so you can access services
|
|
101
|
+
* and e.g. load channel specific theme configurations.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* EmailPlugin.init({
|
|
106
|
+
* globalTemplateVars: {
|
|
107
|
+
* primaryColor: '#FF0000',
|
|
108
|
+
* fromAddress: 'no-reply@ourstore.com'
|
|
109
|
+
* }
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
* or
|
|
113
|
+
* ```ts
|
|
114
|
+
* EmailPlugin.init({
|
|
115
|
+
* globalTemplateVars: async (ctx, injector) => {
|
|
116
|
+
* const myAsyncService = injector.get(MyAsyncService);
|
|
117
|
+
* const asyncValue = await myAsyncService.get(ctx);
|
|
118
|
+
* const channel = ctx.channel;
|
|
119
|
+
* const { primaryColor } = channel.customFields.theme;
|
|
120
|
+
* const theme = {
|
|
121
|
+
* primaryColor,
|
|
122
|
+
* asyncValue,
|
|
123
|
+
* };
|
|
124
|
+
* return theme;
|
|
125
|
+
* }
|
|
126
|
+
* })
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
97
129
|
* ### Handlebars helpers
|
|
98
130
|
*
|
|
99
131
|
* The following helper functions are available for use in email templates:
|
package/lib/src/plugin.js
CHANGED
|
@@ -113,6 +113,38 @@ const file_based_template_loader_1 = require("./template-loader/file-based-templ
|
|
|
113
113
|
* </mj-table>
|
|
114
114
|
* ```
|
|
115
115
|
*
|
|
116
|
+
* ### Setting global variables using `globalTemplateVars`
|
|
117
|
+
*
|
|
118
|
+
* `globalTemplateVars` is an object that can be passed to the configuration of the Email Plugin with static object variables.
|
|
119
|
+
* You can also pass an async function that will be called with the `RequestContext` and the `Injector` so you can access services
|
|
120
|
+
* and e.g. load channel specific theme configurations.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* EmailPlugin.init({
|
|
125
|
+
* globalTemplateVars: {
|
|
126
|
+
* primaryColor: '#FF0000',
|
|
127
|
+
* fromAddress: 'no-reply@ourstore.com'
|
|
128
|
+
* }
|
|
129
|
+
* })
|
|
130
|
+
* ```
|
|
131
|
+
* or
|
|
132
|
+
* ```ts
|
|
133
|
+
* EmailPlugin.init({
|
|
134
|
+
* globalTemplateVars: async (ctx, injector) => {
|
|
135
|
+
* const myAsyncService = injector.get(MyAsyncService);
|
|
136
|
+
* const asyncValue = await myAsyncService.get(ctx);
|
|
137
|
+
* const channel = ctx.channel;
|
|
138
|
+
* const { primaryColor } = channel.customFields.theme;
|
|
139
|
+
* const theme = {
|
|
140
|
+
* primaryColor,
|
|
141
|
+
* asyncValue,
|
|
142
|
+
* };
|
|
143
|
+
* return theme;
|
|
144
|
+
* }
|
|
145
|
+
* })
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
116
148
|
* ### Handlebars helpers
|
|
117
149
|
*
|
|
118
150
|
* The following helper functions are available for use in email templates:
|
|
@@ -351,7 +383,11 @@ let EmailPlugin = EmailPlugin_1 = class EmailPlugin {
|
|
|
351
383
|
const { type } = handler;
|
|
352
384
|
try {
|
|
353
385
|
const injector = new core_2.Injector(this.moduleRef);
|
|
354
|
-
|
|
386
|
+
let globalTemplateVars = this.options.globalTemplateVars;
|
|
387
|
+
if (typeof globalTemplateVars === 'function') {
|
|
388
|
+
globalTemplateVars = await globalTemplateVars(event.ctx, injector);
|
|
389
|
+
}
|
|
390
|
+
const result = await handler.handle(event, globalTemplateVars, injector);
|
|
355
391
|
if (!result) {
|
|
356
392
|
return;
|
|
357
393
|
}
|
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,wCAWuB;AAEvB,qCAAsE;AACtE,2CAA8D;AAC9D,+CAA2C;AAC3C,uDAAmD;AAEnD,6FAAuF;AASvF
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,uCAAyC;AACzC,wCAWuB;AAEvB,qCAAsE;AACtE,2CAA8D;AAC9D,+CAA2C;AAC3C,uDAAmD;AAEnD,6FAAuF;AASvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2QG;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,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAiB;QAChC,mBAAc,GAAd,c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CAAoB,CAAC,CAAA;qCALX,eAAQ;QACP,gBAAS;QACJ,gCAAc;QACb,sBAAe;QAChB,qBAAc;GAZjC,WAAW,CA6HvB"}
|
package/lib/src/types.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { Injector, RequestContext, SerializedRequestContext, VendureEvent } from
|
|
|
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';
|
|
7
|
-
import { EmailEventHandler } from './handler/event-handler';
|
|
8
7
|
import { EmailGenerator } from './generator/email-generator';
|
|
8
|
+
import { EmailEventHandler } from './handler/event-handler';
|
|
9
9
|
import { EmailSender } from './sender/email-sender';
|
|
10
10
|
import { TemplateLoader } from './template-loader/template-loader';
|
|
11
11
|
/**
|
|
@@ -31,12 +31,46 @@ export type EventWithContext = VendureEvent & {
|
|
|
31
31
|
export type EventWithAsyncData<Event extends EventWithContext, R> = Event & {
|
|
32
32
|
data: R;
|
|
33
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* @description
|
|
36
|
+
* Allows you to dynamically load the "globalTemplateVars" key async and access Vendure services
|
|
37
|
+
* to create the object. This is not a requirement. You can also specify a simple static object if your
|
|
38
|
+
* projects doesn't need to access async or dynamic values.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
*
|
|
43
|
+
* EmailPlugin.init({
|
|
44
|
+
* globalTemplateVars: async (ctx, injector) => {
|
|
45
|
+
* const myAsyncService = injector.get(MyAsyncService);
|
|
46
|
+
* const asyncValue = await myAsyncService.get(ctx);
|
|
47
|
+
* const channel = ctx.channel;
|
|
48
|
+
* const { primaryColor } = channel.customFields.theme;
|
|
49
|
+
* const theme = {
|
|
50
|
+
* primaryColor,
|
|
51
|
+
* asyncValue,
|
|
52
|
+
* };
|
|
53
|
+
* return theme;
|
|
54
|
+
* }
|
|
55
|
+
* [...]
|
|
56
|
+
* })
|
|
57
|
+
*
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @docsCategory core plugins/EmailPlugin
|
|
61
|
+
* @docsPage EmailPluginOptions
|
|
62
|
+
* @since 2.3.0
|
|
63
|
+
*/
|
|
64
|
+
export type GlobalTemplateVarsFn = (ctx: RequestContext, injector: Injector) => Promise<{
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
}>;
|
|
34
67
|
/**
|
|
35
68
|
* @description
|
|
36
69
|
* Configuration for the EmailPlugin.
|
|
37
70
|
*
|
|
38
71
|
* @docsCategory core plugins/EmailPlugin
|
|
39
72
|
* @docsPage EmailPluginOptions
|
|
73
|
+
* @docsWeight 0
|
|
40
74
|
* */
|
|
41
75
|
export interface EmailPluginOptions {
|
|
42
76
|
/**
|
|
@@ -70,11 +104,12 @@ export interface EmailPluginOptions {
|
|
|
70
104
|
* @description
|
|
71
105
|
* An object containing variables which are made available to all templates. For example,
|
|
72
106
|
* the storefront URL could be defined here and then used in the "email address verification"
|
|
73
|
-
* email.
|
|
107
|
+
* email. Use the GlobalTemplateVarsFn if you need to retrieve variables from Vendure or
|
|
108
|
+
* plugin services.
|
|
74
109
|
*/
|
|
75
110
|
globalTemplateVars?: {
|
|
76
111
|
[key: string]: any;
|
|
77
|
-
};
|
|
112
|
+
} | GlobalTemplateVarsFn;
|
|
78
113
|
/**
|
|
79
114
|
* @description
|
|
80
115
|
* An optional allowed EmailSender, used to allow custom implementations of the send functionality
|
|
@@ -93,7 +128,7 @@ export interface EmailPluginOptions {
|
|
|
93
128
|
emailGenerator?: EmailGenerator;
|
|
94
129
|
}
|
|
95
130
|
/**
|
|
96
|
-
* EmailPLuginOptions type after initialization, where templateLoader
|
|
131
|
+
* EmailPLuginOptions type after initialization, where templateLoader and themeInjector are no longer optional
|
|
97
132
|
*/
|
|
98
133
|
export type InitializedEmailPluginOptions = EmailPluginOptions & {
|
|
99
134
|
templateLoader: TemplateLoader;
|
|
@@ -362,6 +397,13 @@ export type SetTemplateVarsFn<Event> = (event: Event, globals: {
|
|
|
362
397
|
* @docsPage Email Plugin Types
|
|
363
398
|
*/
|
|
364
399
|
export type SetAttachmentsFn<Event> = (event: Event) => EmailAttachment[] | Promise<EmailAttachment[]>;
|
|
400
|
+
/**
|
|
401
|
+
* @description
|
|
402
|
+
* A function used to define the subject to be sent with the email.
|
|
403
|
+
* @docsCategory core plugins/EmailPlugin
|
|
404
|
+
* @docsPage Email Plugin Types
|
|
405
|
+
*/
|
|
406
|
+
export type SetSubjectFn<Event> = (event: Event, ctx: RequestContext, injector: Injector) => string | Promise<string>;
|
|
365
407
|
/**
|
|
366
408
|
* @description
|
|
367
409
|
* Optional address-related fields for sending the email.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vendure/email-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@types/express": "^4.17.21",
|
|
35
35
|
"@types/fs-extra": "^11.0.4",
|
|
36
36
|
"@types/mjml": "^4.7.4",
|
|
37
|
-
"@vendure/common": "^2.
|
|
38
|
-
"@vendure/core": "^2.
|
|
37
|
+
"@vendure/common": "^2.3.0",
|
|
38
|
+
"@vendure/core": "^2.3.0",
|
|
39
39
|
"rimraf": "^5.0.5",
|
|
40
40
|
"typescript": "5.3.3"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "41727f7f099582981422a174e165d79a9f21ff1e"
|
|
43
43
|
}
|