@vendure/email-plugin 2.0.0-next.9 → 2.0.1
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/index.d.ts +2 -0
- package/lib/index.js +7 -1
- package/lib/index.js.map +1 -1
- 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/default-email-handlers.js +9 -9
- package/lib/src/default-email-handlers.js.map +1 -1
- package/lib/src/dev-mailbox.js +9 -6
- package/lib/src/dev-mailbox.js.map +1 -1
- package/lib/src/email-generator.d.ts +25 -0
- package/lib/src/email-generator.js +3 -0
- package/lib/src/email-generator.js.map +1 -0
- package/lib/src/email-processor.d.ts +10 -6
- package/lib/src/email-processor.js +31 -13
- package/lib/src/email-processor.js.map +1 -1
- package/lib/src/email-sender.d.ts +45 -0
- package/lib/src/email-sender.js +3 -0
- package/lib/src/email-sender.js.map +1 -0
- package/lib/src/event-handler.d.ts +14 -2
- package/lib/src/event-handler.js +21 -7
- package/lib/src/event-handler.js.map +1 -1
- package/lib/src/event-listener.d.ts +1 -1
- package/lib/src/event-listener.js +1 -1
- package/lib/src/handlebars-mjml-generator.d.ts +4 -4
- package/lib/src/handlebars-mjml-generator.js +6 -13
- package/lib/src/handlebars-mjml-generator.js.map +1 -1
- package/lib/src/mock-events.js +17 -26
- package/lib/src/mock-events.js.map +1 -1
- package/lib/src/nodemailer-email-sender.d.ts +6 -3
- package/lib/src/nodemailer-email-sender.js +10 -1
- package/lib/src/nodemailer-email-sender.js.map +1 -1
- package/lib/src/noop-email-generator.d.ts +1 -1
- package/lib/src/plugin.d.ts +99 -8
- package/lib/src/plugin.js +143 -14
- 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 +140 -173
- package/package.json +42 -42
package/lib/src/types.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
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
|
+
import SESTransport from 'nodemailer/lib/ses-transport';
|
|
6
|
+
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
7
|
+
import { EmailGenerator } from './email-generator';
|
|
8
|
+
import { EmailSender } from './email-sender';
|
|
5
9
|
import { EmailEventHandler } from './event-handler';
|
|
6
10
|
/**
|
|
7
11
|
* @description
|
|
@@ -9,10 +13,10 @@ import { EmailEventHandler } from './event-handler';
|
|
|
9
13
|
* {@link RequestContext}, which is used to determine the channel and language
|
|
10
14
|
* to use when generating the email.
|
|
11
15
|
*
|
|
12
|
-
* @docsCategory EmailPlugin
|
|
16
|
+
* @docsCategory core plugins/EmailPlugin
|
|
13
17
|
* @docsPage Email Plugin Types
|
|
14
18
|
*/
|
|
15
|
-
export
|
|
19
|
+
export type EventWithContext = VendureEvent & {
|
|
16
20
|
ctx: RequestContext;
|
|
17
21
|
};
|
|
18
22
|
/**
|
|
@@ -20,17 +24,17 @@ export declare type EventWithContext = VendureEvent & {
|
|
|
20
24
|
* A VendureEvent with a {@link RequestContext} and a `data` property which contains the
|
|
21
25
|
* value resolved from the {@link EmailEventHandler}`.loadData()` callback.
|
|
22
26
|
*
|
|
23
|
-
* @docsCategory EmailPlugin
|
|
27
|
+
* @docsCategory core plugins/EmailPlugin
|
|
24
28
|
* @docsPage Email Plugin Types
|
|
25
29
|
*/
|
|
26
|
-
export
|
|
30
|
+
export type EventWithAsyncData<Event extends EventWithContext, R> = Event & {
|
|
27
31
|
data: R;
|
|
28
32
|
};
|
|
29
33
|
/**
|
|
30
34
|
* @description
|
|
31
35
|
* Configuration for the EmailPlugin.
|
|
32
36
|
*
|
|
33
|
-
* @docsCategory EmailPlugin
|
|
37
|
+
* @docsCategory core plugins/EmailPlugin
|
|
34
38
|
* @docsPage EmailPluginOptions
|
|
35
39
|
* */
|
|
36
40
|
export interface EmailPluginOptions {
|
|
@@ -38,13 +42,23 @@ export interface EmailPluginOptions {
|
|
|
38
42
|
* @description
|
|
39
43
|
* The path to the location of the email templates. In a default Vendure installation,
|
|
40
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')`
|
|
47
|
+
*/
|
|
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
|
|
41
55
|
*/
|
|
42
|
-
|
|
56
|
+
templateLoader?: TemplateLoader;
|
|
43
57
|
/**
|
|
44
58
|
* @description
|
|
45
59
|
* Configures how the emails are sent.
|
|
46
60
|
*/
|
|
47
|
-
transport: EmailTransportOptions;
|
|
61
|
+
transport: EmailTransportOptions | ((injector?: Injector, ctx?: RequestContext) => EmailTransportOptions | Promise<EmailTransportOptions>);
|
|
48
62
|
/**
|
|
49
63
|
* @description
|
|
50
64
|
* An array of {@link EmailEventHandler}s which define which Vendure events will trigger
|
|
@@ -77,11 +91,17 @@ export interface EmailPluginOptions {
|
|
|
77
91
|
*/
|
|
78
92
|
emailGenerator?: EmailGenerator;
|
|
79
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* EmailPLuginOptions type after initialization, where templateLoader is no longer optional
|
|
96
|
+
*/
|
|
97
|
+
export type InitializedEmailPluginOptions = EmailPluginOptions & {
|
|
98
|
+
templateLoader: TemplateLoader;
|
|
99
|
+
};
|
|
80
100
|
/**
|
|
81
101
|
* @description
|
|
82
102
|
* Configuration for running the EmailPlugin in development mode.
|
|
83
103
|
*
|
|
84
|
-
* @docsCategory EmailPlugin
|
|
104
|
+
* @docsCategory core plugins/EmailPlugin
|
|
85
105
|
* @docsPage EmailPluginOptions
|
|
86
106
|
*/
|
|
87
107
|
export interface EmailPluginDevModeOptions extends Omit<EmailPluginOptions, 'transport'> {
|
|
@@ -97,81 +117,23 @@ export interface EmailPluginDevModeOptions extends Omit<EmailPluginOptions, 'tra
|
|
|
97
117
|
*/
|
|
98
118
|
route: string;
|
|
99
119
|
}
|
|
100
|
-
/**
|
|
101
|
-
* @description
|
|
102
|
-
* The credentials used for sending email via SMTP
|
|
103
|
-
*
|
|
104
|
-
* @docsCategory EmailPlugin
|
|
105
|
-
* @docsPage Email Plugin Types
|
|
106
|
-
*/
|
|
107
|
-
export interface SMTPCredentials {
|
|
108
|
-
/** @description The username */
|
|
109
|
-
user: string;
|
|
110
|
-
/** @description The password */
|
|
111
|
-
pass: string;
|
|
112
|
-
}
|
|
113
120
|
/**
|
|
114
121
|
* @description
|
|
115
122
|
* A union of all the possible transport options for sending emails.
|
|
116
123
|
*
|
|
117
|
-
* @docsCategory EmailPlugin
|
|
124
|
+
* @docsCategory core plugins/EmailPlugin
|
|
118
125
|
* @docsPage Transport Options
|
|
119
126
|
*/
|
|
120
|
-
export
|
|
127
|
+
export type EmailTransportOptions = SMTPTransportOptions | SendmailTransportOptions | FileTransportOptions | NoopTransportOptions | SESTransportOptions | TestingTransportOptions;
|
|
121
128
|
/**
|
|
122
129
|
* @description
|
|
123
|
-
*
|
|
130
|
+
* The SMTP transport options of [Nodemailer](https://nodemailer.com/smtp/)
|
|
124
131
|
*
|
|
125
|
-
* @docsCategory EmailPlugin
|
|
132
|
+
* @docsCategory core plugins/EmailPlugin
|
|
126
133
|
* @docsPage Transport Options
|
|
127
134
|
*/
|
|
128
|
-
export interface SMTPTransportOptions {
|
|
135
|
+
export interface SMTPTransportOptions extends SMTPTransport.Options {
|
|
129
136
|
type: 'smtp';
|
|
130
|
-
/**
|
|
131
|
-
* @description
|
|
132
|
-
* the hostname or IP address to connect to (defaults to ‘localhost’)
|
|
133
|
-
*/
|
|
134
|
-
host: string;
|
|
135
|
-
/**
|
|
136
|
-
* @description
|
|
137
|
-
* The port to connect to (defaults to 25 or 465)
|
|
138
|
-
*/
|
|
139
|
-
port: number;
|
|
140
|
-
/**
|
|
141
|
-
* @description
|
|
142
|
-
* Defines authentication data
|
|
143
|
-
*/
|
|
144
|
-
auth: SMTPCredentials;
|
|
145
|
-
/**
|
|
146
|
-
* @description
|
|
147
|
-
* Defines if the connection should use SSL (if true) or not (if false)
|
|
148
|
-
*/
|
|
149
|
-
secure?: boolean;
|
|
150
|
-
/**
|
|
151
|
-
* @description
|
|
152
|
-
* Turns off STARTTLS support if true
|
|
153
|
-
*/
|
|
154
|
-
ignoreTLS?: boolean;
|
|
155
|
-
/**
|
|
156
|
-
* @description
|
|
157
|
-
* Forces the client to use STARTTLS. Returns an error if upgrading the connection is not possible or fails.
|
|
158
|
-
*/
|
|
159
|
-
requireTLS?: boolean;
|
|
160
|
-
/**
|
|
161
|
-
* @description
|
|
162
|
-
* Optional hostname of the client, used for identifying to the server
|
|
163
|
-
*/
|
|
164
|
-
name?: string;
|
|
165
|
-
/**
|
|
166
|
-
* @description
|
|
167
|
-
* The local interface to bind to for network connections
|
|
168
|
-
*/
|
|
169
|
-
localAddress?: string;
|
|
170
|
-
/**
|
|
171
|
-
* @description
|
|
172
|
-
* Defines preferred authentication method, e.g. ‘PLAIN’
|
|
173
|
-
*/
|
|
174
|
-
authMethod?: string;
|
|
175
137
|
/**
|
|
176
138
|
* @description
|
|
177
139
|
* If true, uses the configured {@link VendureLogger} to log messages from Nodemailer as it interacts with
|
|
@@ -180,26 +142,52 @@ export interface SMTPTransportOptions {
|
|
|
180
142
|
* @default false
|
|
181
143
|
*/
|
|
182
144
|
logging?: boolean;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @description
|
|
148
|
+
* The SES transport options of [Nodemailer](https://nodemailer.com/transports/ses//)
|
|
149
|
+
*
|
|
150
|
+
* See [Nodemailers's SES docs](https://nodemailer.com/transports/ses/) for more details
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```TypeScript
|
|
154
|
+
* import { SES, SendRawEmailCommand } from '\@aws-sdk/client-ses'
|
|
155
|
+
*
|
|
156
|
+
* const ses = new SES({
|
|
157
|
+
* apiVersion: '2010-12-01',
|
|
158
|
+
* region: 'eu-central-1',
|
|
159
|
+
* credentials: {
|
|
160
|
+
* accessKeyId: process.env.SES_ACCESS_KEY || '',
|
|
161
|
+
* secretAccessKey: process.env.SES_SECRET_KEY || '',
|
|
162
|
+
* },
|
|
163
|
+
* })
|
|
164
|
+
*
|
|
165
|
+
* const config: VendureConfig = {
|
|
166
|
+
* // Add an instance of the plugin to the plugins array
|
|
167
|
+
* plugins: [
|
|
168
|
+
* EmailPlugin.init({
|
|
169
|
+
* handlers: defaultEmailHandlers,
|
|
170
|
+
* templatePath: path.join(__dirname, 'static/email/templates'),
|
|
171
|
+
* transport: {
|
|
172
|
+
* type: 'ses',
|
|
173
|
+
* SES: { ses, aws: { SendRawEmailCommand } },
|
|
174
|
+
* sendingRate: 10, // optional messages per second sending rate
|
|
175
|
+
* },
|
|
176
|
+
* }),
|
|
177
|
+
* ],
|
|
178
|
+
* };
|
|
179
|
+
* ```
|
|
180
|
+
* @docsCategory core plugins/EmailPlugin
|
|
181
|
+
* @docsPage Transport Options
|
|
182
|
+
*/
|
|
183
|
+
export interface SESTransportOptions extends SESTransport.Options {
|
|
184
|
+
type: 'ses';
|
|
197
185
|
}
|
|
198
186
|
/**
|
|
199
187
|
* @description
|
|
200
188
|
* Uses the local Sendmail program to send the email.
|
|
201
189
|
*
|
|
202
|
-
* @docsCategory EmailPlugin
|
|
190
|
+
* @docsCategory core plugins/EmailPlugin
|
|
203
191
|
* @docsPage Transport Options
|
|
204
192
|
*/
|
|
205
193
|
export interface SendmailTransportOptions {
|
|
@@ -213,7 +201,7 @@ export interface SendmailTransportOptions {
|
|
|
213
201
|
* @description
|
|
214
202
|
* Outputs the email as an HTML file for development purposes.
|
|
215
203
|
*
|
|
216
|
-
* @docsCategory EmailPlugin
|
|
204
|
+
* @docsCategory core plugins/EmailPlugin
|
|
217
205
|
* @docsPage Transport Options
|
|
218
206
|
*/
|
|
219
207
|
export interface FileTransportOptions {
|
|
@@ -228,7 +216,7 @@ export interface FileTransportOptions {
|
|
|
228
216
|
* Does nothing with the generated email. Intended for use in testing where we don't care about the email transport,
|
|
229
217
|
* or when using a custom {@link EmailSender} which does not require transport options.
|
|
230
218
|
*
|
|
231
|
-
* @docsCategory EmailPlugin
|
|
219
|
+
* @docsCategory core plugins/EmailPlugin
|
|
232
220
|
* @docsPage Transport Options
|
|
233
221
|
*/
|
|
234
222
|
export interface NoopTransportOptions {
|
|
@@ -238,7 +226,7 @@ export interface NoopTransportOptions {
|
|
|
238
226
|
* @description
|
|
239
227
|
* The final, generated email details to be sent.
|
|
240
228
|
*
|
|
241
|
-
* @docsCategory EmailPlugin
|
|
229
|
+
* @docsCategory core plugins/EmailPlugin
|
|
242
230
|
* @docsPage Email Plugin Types
|
|
243
231
|
*/
|
|
244
232
|
export interface EmailDetails<Type extends 'serialized' | 'unserialized' = 'unserialized'> {
|
|
@@ -255,7 +243,7 @@ export interface EmailDetails<Type extends 'serialized' | 'unserialized' = 'unse
|
|
|
255
243
|
* @description
|
|
256
244
|
* Forwards the raw GeneratedEmailContext object to a provided callback, for use in testing.
|
|
257
245
|
*
|
|
258
|
-
* @docsCategory EmailPlugin
|
|
246
|
+
* @docsCategory core plugins/EmailPlugin
|
|
259
247
|
* @docsPage Transport Options
|
|
260
248
|
*/
|
|
261
249
|
export interface TestingTransportOptions {
|
|
@@ -266,84 +254,18 @@ export interface TestingTransportOptions {
|
|
|
266
254
|
*/
|
|
267
255
|
onSend: (details: EmailDetails) => void;
|
|
268
256
|
}
|
|
269
|
-
/**
|
|
270
|
-
* @description
|
|
271
|
-
* An EmailSender is responsible for sending the email, e.g. via an SMTP connection
|
|
272
|
-
* or using some other mail-sending API. By default, the EmailPlugin uses the
|
|
273
|
-
* {@link NodemailerEmailSender}, but it is also possible to supply a custom implementation:
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
* ```TypeScript
|
|
277
|
-
* const sgMail = require('\@sendgrid/mail');
|
|
278
|
-
*
|
|
279
|
-
* sgMail.setApiKey(process.env.SENDGRID_API_KEY);
|
|
280
|
-
*
|
|
281
|
-
* class SendgridEmailSender implements EmailSender {
|
|
282
|
-
* async send(email: EmailDetails) {
|
|
283
|
-
* await sgMail.send({
|
|
284
|
-
* to: email.recipient,
|
|
285
|
-
* from: email.from,
|
|
286
|
-
* subject: email.subject,
|
|
287
|
-
* html: email.body,
|
|
288
|
-
* });
|
|
289
|
-
* }
|
|
290
|
-
* }
|
|
291
|
-
*
|
|
292
|
-
* const config: VendureConfig = {
|
|
293
|
-
* logger: new DefaultLogger({ level: LogLevel.Debug })
|
|
294
|
-
* // ...
|
|
295
|
-
* plugins: [
|
|
296
|
-
* EmailPlugin.init({
|
|
297
|
-
* // ... template, handlers config omitted
|
|
298
|
-
* transport: { type: 'none' },
|
|
299
|
-
* emailSender: new SendgridEmailSender(),
|
|
300
|
-
* }),
|
|
301
|
-
* ],
|
|
302
|
-
* };
|
|
303
|
-
* ```
|
|
304
|
-
*
|
|
305
|
-
* @docsCategory EmailPlugin
|
|
306
|
-
* @docsPage EmailSender
|
|
307
|
-
* @docsWeight 0
|
|
308
|
-
*/
|
|
309
|
-
export interface EmailSender {
|
|
310
|
-
send: (email: EmailDetails, options: EmailTransportOptions) => void | Promise<void>;
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* @description
|
|
314
|
-
* An EmailGenerator generates the subject and body details of an email.
|
|
315
|
-
*
|
|
316
|
-
* @docsCategory EmailPlugin
|
|
317
|
-
* @docsPage EmailGenerator
|
|
318
|
-
* @docsWeight 0
|
|
319
|
-
*/
|
|
320
|
-
export interface EmailGenerator<T extends string = any, E extends VendureEvent = any> {
|
|
321
|
-
/**
|
|
322
|
-
* @description
|
|
323
|
-
* Any necessary setup can be performed here.
|
|
324
|
-
*/
|
|
325
|
-
onInit?(options: EmailPluginOptions): void | Promise<void>;
|
|
326
|
-
/**
|
|
327
|
-
* @description
|
|
328
|
-
* Given a subject and body from an email template, this method generates the final
|
|
329
|
-
* interpolated email text.
|
|
330
|
-
*/
|
|
331
|
-
generate(from: string, subject: string, body: string, templateVars: {
|
|
332
|
-
[key: string]: any;
|
|
333
|
-
}): Pick<EmailDetails, 'from' | 'subject' | 'body'>;
|
|
334
|
-
}
|
|
335
257
|
/**
|
|
336
258
|
* @description
|
|
337
259
|
* A function used to load async data for use by an {@link EmailEventHandler}.
|
|
338
260
|
*
|
|
339
|
-
* @docsCategory EmailPlugin
|
|
261
|
+
* @docsCategory core plugins/EmailPlugin
|
|
340
262
|
* @docsPage Email Plugin Types
|
|
341
263
|
*/
|
|
342
|
-
export
|
|
264
|
+
export type LoadDataFn<Event extends EventWithContext, R> = (context: {
|
|
343
265
|
event: Event;
|
|
344
266
|
injector: Injector;
|
|
345
267
|
}) => Promise<R>;
|
|
346
|
-
export
|
|
268
|
+
export type OptionalToNullable<O> = {
|
|
347
269
|
[K in keyof O]-?: undefined extends O[K] ? NonNullable<O[K]> | null : O[K];
|
|
348
270
|
};
|
|
349
271
|
/**
|
|
@@ -353,16 +275,17 @@ export declare type OptionalToNullable<O> = {
|
|
|
353
275
|
* only uses the `path` property to define a filesystem path or a URL pointing to
|
|
354
276
|
* the attachment file.
|
|
355
277
|
*
|
|
356
|
-
* @docsCategory EmailPlugin
|
|
278
|
+
* @docsCategory core plugins/EmailPlugin
|
|
357
279
|
* @docsPage Email Plugin Types
|
|
358
280
|
*/
|
|
359
|
-
export
|
|
281
|
+
export type EmailAttachment = Omit<Attachment, 'raw'> & {
|
|
360
282
|
path?: string;
|
|
361
283
|
};
|
|
362
|
-
export
|
|
284
|
+
export type SerializedAttachment = OptionalToNullable<Omit<EmailAttachment, 'content'> & {
|
|
363
285
|
content: string | null;
|
|
364
286
|
}>;
|
|
365
|
-
export
|
|
287
|
+
export type IntermediateEmailDetails = {
|
|
288
|
+
ctx: SerializedRequestContext;
|
|
366
289
|
type: string;
|
|
367
290
|
from: string;
|
|
368
291
|
recipient: string;
|
|
@@ -379,8 +302,7 @@ export declare type IntermediateEmailDetails = {
|
|
|
379
302
|
* Configures the {@link EmailEventHandler} to handle a particular channel & languageCode
|
|
380
303
|
* combination.
|
|
381
304
|
*
|
|
382
|
-
* @
|
|
383
|
-
* @docsPage Email Plugin Types
|
|
305
|
+
* @deprecated Use a custom {@link TemplateLoader} instead.
|
|
384
306
|
*/
|
|
385
307
|
export interface EmailTemplateConfig {
|
|
386
308
|
/**
|
|
@@ -407,15 +329,60 @@ export interface EmailTemplateConfig {
|
|
|
407
329
|
*/
|
|
408
330
|
subject: string;
|
|
409
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 core plugins/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
|
+
}
|
|
410
377
|
/**
|
|
411
378
|
* @description
|
|
412
379
|
* A function used to define template variables available to email templates.
|
|
413
380
|
* See {@link EmailEventHandler}.setTemplateVars().
|
|
414
381
|
*
|
|
415
|
-
* @docsCategory EmailPlugin
|
|
382
|
+
* @docsCategory core plugins/EmailPlugin
|
|
416
383
|
* @docsPage Email Plugin Types
|
|
417
384
|
*/
|
|
418
|
-
export
|
|
385
|
+
export type SetTemplateVarsFn<Event> = (event: Event, globals: {
|
|
419
386
|
[key: string]: any;
|
|
420
387
|
}) => {
|
|
421
388
|
[key: string]: any;
|
|
@@ -426,16 +393,16 @@ export declare type SetTemplateVarsFn<Event> = (event: Event, globals: {
|
|
|
426
393
|
* See https://nodemailer.com/message/attachments/ for more information about
|
|
427
394
|
* how attachments work in Nodemailer.
|
|
428
395
|
*
|
|
429
|
-
* @docsCategory EmailPlugin
|
|
396
|
+
* @docsCategory core plugins/EmailPlugin
|
|
430
397
|
* @docsPage Email Plugin Types
|
|
431
398
|
*/
|
|
432
|
-
export
|
|
399
|
+
export type SetAttachmentsFn<Event> = (event: Event) => EmailAttachment[] | Promise<EmailAttachment[]>;
|
|
433
400
|
/**
|
|
434
401
|
* @description
|
|
435
402
|
* Optional address-related fields for sending the email.
|
|
436
403
|
*
|
|
437
404
|
* @since 1.1.0
|
|
438
|
-
* @docsCategory EmailPlugin
|
|
405
|
+
* @docsCategory core plugins/EmailPlugin
|
|
439
406
|
* @docsPage Email Plugin Types
|
|
440
407
|
*/
|
|
441
408
|
export interface OptionalAddressFields {
|
|
@@ -460,7 +427,7 @@ export interface OptionalAddressFields {
|
|
|
460
427
|
* A function used to set the {@link OptionalAddressFields}.
|
|
461
428
|
*
|
|
462
429
|
* @since 1.1.0
|
|
463
|
-
* @docsCategory EmailPlugin
|
|
430
|
+
* @docsCategory core plugins/EmailPlugin
|
|
464
431
|
* @docsPage Email Plugin Types
|
|
465
432
|
*/
|
|
466
|
-
export
|
|
433
|
+
export type SetOptionalAddressFieldsFn<Event> = (event: Event) => OptionalAddressFields | Promise<OptionalAddressFields>;
|
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
2
|
+
"name": "@vendure/email-plugin",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**/*",
|
|
9
|
+
"templates/**/*",
|
|
10
|
+
"dev-mailbox.html"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"watch": "tsc -p ./tsconfig.build.json --watch",
|
|
14
|
+
"build": "rimraf lib && tsc -p ./tsconfig.build.json",
|
|
15
|
+
"lint": "eslint --fix .",
|
|
16
|
+
"test": "vitest --config ./vitest.config.ts --run"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://www.vendure.io/",
|
|
19
|
+
"funding": "https://github.com/sponsors/michaelbromley",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@types/nodemailer": "^6.4.0",
|
|
25
|
+
"dateformat": "^3.0.3",
|
|
26
|
+
"express": "^4.17.1",
|
|
27
|
+
"fs-extra": "^10.0.0",
|
|
28
|
+
"handlebars": "^4.7.6",
|
|
29
|
+
"mjml": "^4.7.1",
|
|
30
|
+
"nodemailer": "^6.4.13"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/dateformat": "^3.0.1",
|
|
34
|
+
"@types/express": "^4.17.8",
|
|
35
|
+
"@types/fs-extra": "^9.0.1",
|
|
36
|
+
"@types/handlebars": "^4.1.0",
|
|
37
|
+
"@types/mjml": "^4.0.4",
|
|
38
|
+
"@vendure/common": "^2.0.1",
|
|
39
|
+
"@vendure/core": "^2.0.1",
|
|
40
|
+
"rimraf": "^3.0.2",
|
|
41
|
+
"typescript": "4.9.5"
|
|
42
|
+
},
|
|
43
|
+
"gitHead": "d55a4f405d13c8031a4910513bfc240e859e75ed"
|
|
44
44
|
}
|