@vendure/email-plugin 2.0.0-next.19 → 2.0.0-next.20
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 +2 -0
- package/lib/index.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 +3 -1
- 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/handlebars-mjml-generator.d.ts +2 -1
- package/lib/src/handlebars-mjml-generator.js.map +1 -1
- package/lib/src/nodemailer-email-sender.d.ts +2 -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 +59 -6
- package/lib/src/plugin.js +89 -13
- package/lib/src/plugin.js.map +1 -1
- package/lib/src/types.d.ts +2 -66
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -19,4 +19,6 @@ __exportStar(require("./src/noop-email-generator"), exports);
|
|
|
19
19
|
__exportStar(require("./src/plugin"), exports);
|
|
20
20
|
__exportStar(require("./src/template-loader"), exports);
|
|
21
21
|
__exportStar(require("./src/types"), exports);
|
|
22
|
+
__exportStar(require("./src/email-generator"), exports);
|
|
23
|
+
__exportStar(require("./src/email-sender"), exports);
|
|
22
24
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+DAA6C;AAC7C,gEAA8C;AAC9C,sDAAoC;AACpC,uDAAqC;AACrC,kEAAgD;AAChD,6DAA2C;AAC3C,+CAA6B;AAC7B,wDAAsC;AACtC,8CAA4B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+DAA6C;AAC7C,gEAA8C;AAC9C,sDAAoC;AACpC,uDAAqC;AACrC,kEAAgD;AAChD,6DAA2C;AAC3C,+CAA6B;AAC7B,wDAAsC;AACtC,8CAA4B;AAC5B,wDAAsC;AACtC,qDAAmC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { InjectableStrategy, VendureEvent } from '@vendure/core';
|
|
2
|
+
import { EmailDetails, EmailPluginOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* An EmailGenerator generates the subject and body details of an email.
|
|
6
|
+
*
|
|
7
|
+
* @docsCategory EmailPlugin
|
|
8
|
+
* @docsPage EmailGenerator
|
|
9
|
+
* @docsWeight 0
|
|
10
|
+
*/
|
|
11
|
+
export interface EmailGenerator<T extends string = any, E extends VendureEvent = any> extends InjectableStrategy {
|
|
12
|
+
/**
|
|
13
|
+
* @description
|
|
14
|
+
* Any necessary setup can be performed here.
|
|
15
|
+
*/
|
|
16
|
+
onInit?(options: EmailPluginOptions): void | Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* @description
|
|
19
|
+
* Given a subject and body from an email template, this method generates the final
|
|
20
|
+
* interpolated email text.
|
|
21
|
+
*/
|
|
22
|
+
generate(from: string, subject: string, body: string, templateVars: {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}): Pick<EmailDetails, 'from' | 'subject' | 'body'>;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-generator.js","sourceRoot":"","sources":["../../src/email-generator.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { EmailGenerator } from './email-generator';
|
|
2
|
+
import { EmailSender } from './email-sender';
|
|
1
3
|
import { TemplateLoader } from './template-loader';
|
|
2
|
-
import {
|
|
4
|
+
import { EmailPluginOptions, EmailTransportOptions, IntermediateEmailDetails } from './types';
|
|
3
5
|
/**
|
|
4
6
|
* This class combines the template loading, generation, and email sending - the actual "work" of
|
|
5
7
|
* the EmailPlugin. It is arranged this way primarily to accommodate easier testing, so that the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email-processor.js","sourceRoot":"","sources":["../../src/email-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,wCAA4D;AAC5D,wDAA0B;AAE1B,yDAA4D;AAC5D,qCAA4C;AAC5C,2CAA8D;
|
|
1
|
+
{"version":3,"file":"email-processor.js","sourceRoot":"","sources":["../../src/email-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,wCAA4D;AAC5D,wDAA0B;AAE1B,yDAA4D;AAC5D,qCAA4C;AAC5C,2CAA8D;AAG9D,2EAAsE;AACtE,uEAAkE;AAClE,uDAAmD;AAGnD;;;;GAIG;AAEH,IAAa,cAAc,GAA3B,MAAa,cAAc;IAMvB,YAAoD,OAA2B;QAA3B,YAAO,GAAP,OAAO,CAAoB;IAAG,CAAC;IAEnF,KAAK,CAAC,IAAI;QACN,IAAI,CAAC,cAAc,GAAG,IAAI,gCAAc,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACpE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,+CAAqB,EAAE,CAAC;QACrG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc;YACxC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc;YAC7B,CAAC,CAAC,IAAI,mDAAuB,EAAE,CAAC;QACpC,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;YACvB,MAAM,IAAI,CAAC,SAAS,CAAC,MAA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EAAE,IAAI,CAAC,OAAO,GACxB,CAAC;YACF,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAC1D,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;CACJ,CAAA;AAnEY,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAOI,WAAA,IAAA,eAAM,EAAC,gCAAoB,CAAC,CAAA;;GANhC,cAAc,CAmE1B;AAnEY,wCAAc"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { InjectableStrategy } from '@vendure/core';
|
|
2
|
+
import { EmailDetails, EmailTransportOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* An EmailSender is responsible for sending the email, e.g. via an SMTP connection
|
|
6
|
+
* or using some other mail-sending API. By default, the EmailPlugin uses the
|
|
7
|
+
* {@link NodemailerEmailSender}, but it is also possible to supply a custom implementation:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```TypeScript
|
|
11
|
+
* const sgMail = require('\@sendgrid/mail');
|
|
12
|
+
*
|
|
13
|
+
* sgMail.setApiKey(process.env.SENDGRID_API_KEY);
|
|
14
|
+
*
|
|
15
|
+
* class SendgridEmailSender implements EmailSender {
|
|
16
|
+
* async send(email: EmailDetails) {
|
|
17
|
+
* await sgMail.send({
|
|
18
|
+
* to: email.recipient,
|
|
19
|
+
* from: email.from,
|
|
20
|
+
* subject: email.subject,
|
|
21
|
+
* html: email.body,
|
|
22
|
+
* });
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* const config: VendureConfig = {
|
|
27
|
+
* logger: new DefaultLogger({ level: LogLevel.Debug })
|
|
28
|
+
* // ...
|
|
29
|
+
* plugins: [
|
|
30
|
+
* EmailPlugin.init({
|
|
31
|
+
* // ... template, handlers config omitted
|
|
32
|
+
* transport: { type: 'none' },
|
|
33
|
+
* emailSender: new SendgridEmailSender(),
|
|
34
|
+
* }),
|
|
35
|
+
* ],
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @docsCategory EmailPlugin
|
|
40
|
+
* @docsPage EmailSender
|
|
41
|
+
* @docsWeight 0
|
|
42
|
+
*/
|
|
43
|
+
export interface EmailSender extends InjectableStrategy {
|
|
44
|
+
send: (email: EmailDetails, options: EmailTransportOptions) => void | Promise<void>;
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-sender.js","sourceRoot":"","sources":["../../src/email-sender.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { EmailGenerator
|
|
1
|
+
import { EmailGenerator } from './email-generator';
|
|
2
|
+
import { EmailPluginDevModeOptions, EmailPluginOptions } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* @description
|
|
4
5
|
* Uses Handlebars (https://handlebarsjs.com/) to output MJML (https://mjml.io) which is then
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlebars-mjml-generator.js","sourceRoot":"","sources":["../../src/handlebars-mjml-generator.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AACpC,wDAA0B;AAC1B,4DAAoC;AACpC,gDAA6B;AAC7B,gDAAwB;
|
|
1
|
+
{"version":3,"file":"handlebars-mjml-generator.js","sourceRoot":"","sources":["../../src/handlebars-mjml-generator.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AACpC,wDAA0B;AAC1B,4DAA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C,WAAW,CAAC,YAAY,CAAC,CAAC;QACnD,KAAK,MAAM,WAAW,IAAI,aAAa,EAAE;YACrC,MAAM,cAAc,GAAG,kBAAE,CAAC,YAAY,CAAC,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,EAAE,OAAO,CAAC,CAAC;YACtF,oBAAU,CAAC,eAAe,CAAC,cAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,cAAc,CAAC,CAAC;SAClF;IACL,CAAC;IAEO,eAAe;QACnB,oBAAU,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,IAAsB,EAAE,MAAuB,EAAE,EAAE;YACxF,IAAI,CAAC,IAAI,EAAE;gBACP,OAAO,IAAI,CAAC;aACf;YACD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;gBAC5B,MAAM,GAAG,SAAS,CAAC;aACtB;YACD,OAAO,IAAA,oBAAU,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,oBAAU,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC,MAAe,EAAE,EAAE;YACzD,IAAI,MAAM,IAAI,IAAI,EAAE;gBAChB,OAAO,MAAM,CAAC;aACjB;YACD,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAjDD,0DAiDC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Stream } from 'stream';
|
|
3
|
-
import {
|
|
3
|
+
import { EmailSender } from './email-sender';
|
|
4
|
+
import { EmailDetails, EmailTransportOptions } from './types';
|
|
4
5
|
export declare type StreamTransportInfo = {
|
|
5
6
|
envelope: {
|
|
6
7
|
from: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodemailer-email-sender.js","sourceRoot":"","sources":["../../src/nodemailer-email-sender.ts"],"names":[],"mappings":";;;;;;AAAA,2EAAuE;AACvE,mEAA+D;AAC/D,wCAAuC;AACvC,wDAA0B;AAC1B,2CAA6C;AAG7C,gDAAwB;AAExB,+BAA8B;AAE9B,2CAAwC;
|
|
1
|
+
{"version":3,"file":"nodemailer-email-sender.js","sourceRoot":"","sources":["../../src/nodemailer-email-sender.ts"],"names":[],"mappings":";;;;;;AAAA,2EAAuE;AACvE,mEAA+D;AAC/D,wCAAuC;AACvC,wDAA0B;AAC1B,2CAA6C;AAG7C,gDAAwB;AAExB,+BAA8B;AAE9B,2CAAwC;AAaxC;;;;;;GAMG;AACH,MAAa,qBAAqB;IAI9B,KAAK,CAAC,IAAI,CAAC,KAAmB,EAAE,OAA8B;QAC1D,QAAQ,OAAO,CAAC,IAAI,EAAE;YAClB,KAAK,MAAM;gBACP,OAAO;gBACP,MAAM;YACV,KAAK,MAAM;gBACP,MAAM,QAAQ,GAAG,IAAA,kCAAe,EAC5B,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,OAAO,EAAE,EACjE,GAAG,CACN,CAAC;gBACF,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;gBACzD,IAAI,OAAO,CAAC,GAAG,EAAE;oBACb,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;iBAC3C;qBAAM;oBACH,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;iBAC5C;gBACD,MAAM;YACV,KAAK,UAAU;gBACX,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC/D,MAAM;YACV,KAAK,MAAM;gBACP,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,g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AC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACK,YAAY;QAChB,SAAS,WAAW,CAAC,IAAmC;YACpD,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC;YACvC,OAAO,IAAA,aAAM,EAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;QACtC,CAAC;QACD,OAAO;YACH,KAAK,CAAC,KAAkB;gBACpB,UAAU;YACd,CAAC;YACD,KAAK,CAAC,GAAG,MAAW;gBAChB,aAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,qBAAS,CAAC,CAAC;YACjD,CAAC;YACD,KAAK,CAAC,GAAG,MAAW;gBAChB,aAAM,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,qBAAS,CAAC,CAAC;YACnD,CAAC;YACD,IAAI,CAAC,GAAG,MAAW;gBACf,aAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,qBAAS,CAAC,CAAC;YAChD,CAAC;YACD,IAAI,CAAC,GAAG,MAAW;gBACf,aAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,qBAAS,CAAC,CAAC;YAChD,CAAC;YACD,KAAK,CAAC,GAAG,MAAW;gBAChB,aAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,qBAAS,CAAC,CAAC;YACjD,CAAC;YACD,KAAK,CAAC,GAAG,MAAW;gBAChB,aAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,qBAAS,CAAC,CAAC;YACjD,CAAC;SACJ,CAAC;IACN,CAAC;CACJ;AAlID,sDAkIC"}
|
package/lib/src/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MiddlewareConsumer, NestModule, OnApplicationBootstrap } from '@nestjs/common';
|
|
1
|
+
import { MiddlewareConsumer, NestModule, OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
3
|
import { EventBus, JobQueueService, ProcessContext, Type } from '@vendure/core';
|
|
4
4
|
import { EmailProcessor } from './email-processor';
|
|
@@ -98,8 +98,57 @@ import { EmailPluginDevModeOptions, EmailPluginOptions } from './types';
|
|
|
98
98
|
*
|
|
99
99
|
* The `defaultEmailHandlers` array defines the default handlers such as for handling new account registration, order confirmation, password reset
|
|
100
100
|
* etc. These defaults can be extended by adding custom templates for languages other than the default, or even completely new types of emails
|
|
101
|
-
* which respond to any of the available [VendureEvents](/docs/typescript-api/events/).
|
|
102
|
-
*
|
|
101
|
+
* which respond to any of the available [VendureEvents](/docs/typescript-api/events/).
|
|
102
|
+
*
|
|
103
|
+
* A good way to learn how to create your own email handlers is to take a look at the
|
|
104
|
+
* [source code of the default handlers](https://github.com/vendure-ecommerce/vendure/blob/master/packages/email-plugin/src/default-email-handlers.ts).
|
|
105
|
+
* New handlers are defined in exactly the same way.
|
|
106
|
+
*
|
|
107
|
+
* It is also possible to modify the default handlers:
|
|
108
|
+
*
|
|
109
|
+
* ```TypeScript
|
|
110
|
+
* // Rather than importing `defaultEmailHandlers`, you can
|
|
111
|
+
* // import the handlers individually
|
|
112
|
+
* import {
|
|
113
|
+
* orderConfirmationHandler,
|
|
114
|
+
* emailVerificationHandler,
|
|
115
|
+
* passwordResetHandler,
|
|
116
|
+
* emailAddressChangeHandler,
|
|
117
|
+
* } from '\@vendure/email-plugin';
|
|
118
|
+
* import { CustomerService } from '\@vendure/core';
|
|
119
|
+
*
|
|
120
|
+
* // This allows you to then customize each handler to your needs.
|
|
121
|
+
* // For example, let's set a new subject line to the order confirmation:
|
|
122
|
+
* orderConfirmationHandler
|
|
123
|
+
* .setSubject(`We received your order!`);
|
|
124
|
+
*
|
|
125
|
+
* // Another example: loading additional data and setting new
|
|
126
|
+
* // template variables.
|
|
127
|
+
* passwordResetHandler
|
|
128
|
+
* .loadData(async ({ event, injector }) => {
|
|
129
|
+
* const customerService = injector.get(CustomerService);
|
|
130
|
+
* const customer = await customerService.findOneByUserId(event.ctx, event.user.id);
|
|
131
|
+
* return { customer };
|
|
132
|
+
* })
|
|
133
|
+
* .setTemplateVars(event => ({
|
|
134
|
+
* passwordResetToken: event.user.getNativeAuthenticationMethod().passwordResetToken,
|
|
135
|
+
* customer: event.data.customer,
|
|
136
|
+
* }));
|
|
137
|
+
*
|
|
138
|
+
* // Then you pass the handlers to the EmailPlugin init method
|
|
139
|
+
* // individually
|
|
140
|
+
* EmailPlugin.init({
|
|
141
|
+
* handlers: [
|
|
142
|
+
* orderConfirmationHandler,
|
|
143
|
+
* emailVerificationHandler,
|
|
144
|
+
* passwordResetHandler,
|
|
145
|
+
* emailAddressChangeHandler,
|
|
146
|
+
* ],
|
|
147
|
+
* // ...
|
|
148
|
+
* }),
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* For all available methods of extending a handler, see the {@link EmailEventHandler} documentation.
|
|
103
152
|
*
|
|
104
153
|
* ## Dev mode
|
|
105
154
|
*
|
|
@@ -107,7 +156,7 @@ import { EmailPluginDevModeOptions, EmailPluginOptions } from './types';
|
|
|
107
156
|
* file transport (See {@link FileTransportOptions}) and outputs emails as rendered HTML files in the directory specified by the
|
|
108
157
|
* `outputPath` property.
|
|
109
158
|
*
|
|
110
|
-
* ```
|
|
159
|
+
* ```TypeScript
|
|
111
160
|
* EmailPlugin.init({
|
|
112
161
|
* devMode: true,
|
|
113
162
|
* route: 'mailbox',
|
|
@@ -153,25 +202,29 @@ import { EmailPluginDevModeOptions, EmailPluginOptions } from './types';
|
|
|
153
202
|
*
|
|
154
203
|
* @docsCategory EmailPlugin
|
|
155
204
|
*/
|
|
156
|
-
export declare class EmailPlugin implements OnApplicationBootstrap, NestModule {
|
|
205
|
+
export declare class EmailPlugin implements OnApplicationBootstrap, OnApplicationShutdown, NestModule {
|
|
157
206
|
private eventBus;
|
|
158
207
|
private moduleRef;
|
|
159
208
|
private emailProcessor;
|
|
160
209
|
private jobQueueService;
|
|
161
210
|
private processContext;
|
|
211
|
+
private options;
|
|
162
212
|
private static options;
|
|
163
213
|
private devMailbox;
|
|
164
214
|
private jobQueue;
|
|
165
215
|
private testingProcessor;
|
|
166
216
|
/** @internal */
|
|
167
|
-
constructor(eventBus: EventBus, moduleRef: ModuleRef, emailProcessor: EmailProcessor, jobQueueService: JobQueueService, processContext: ProcessContext);
|
|
217
|
+
constructor(eventBus: EventBus, moduleRef: ModuleRef, emailProcessor: EmailProcessor, jobQueueService: JobQueueService, processContext: ProcessContext, options: EmailPluginOptions);
|
|
168
218
|
/**
|
|
169
219
|
* Set the plugin options.
|
|
170
220
|
*/
|
|
171
221
|
static init(options: EmailPluginOptions | EmailPluginDevModeOptions): Type<EmailPlugin>;
|
|
172
222
|
/** @internal */
|
|
173
223
|
onApplicationBootstrap(): Promise<void>;
|
|
224
|
+
onApplicationShutdown(): Promise<void>;
|
|
174
225
|
configure(consumer: MiddlewareConsumer): void;
|
|
226
|
+
private initInjectableStrategies;
|
|
227
|
+
private destroyInjectableStrategies;
|
|
175
228
|
private setupEventSubscribers;
|
|
176
229
|
private handleEvent;
|
|
177
230
|
}
|
package/lib/src/plugin.js
CHANGED
|
@@ -8,12 +8,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
var EmailPlugin_1;
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
16
|
exports.EmailPlugin = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
14
18
|
const core_1 = require("@nestjs/core");
|
|
15
19
|
const core_2 = require("@vendure/core");
|
|
16
|
-
const
|
|
20
|
+
const common_2 = require("./common");
|
|
17
21
|
const constants_1 = require("./constants");
|
|
18
22
|
const dev_mailbox_1 = require("./dev-mailbox");
|
|
19
23
|
const email_processor_1 = require("./email-processor");
|
|
@@ -112,8 +116,57 @@ const email_processor_1 = require("./email-processor");
|
|
|
112
116
|
*
|
|
113
117
|
* The `defaultEmailHandlers` array defines the default handlers such as for handling new account registration, order confirmation, password reset
|
|
114
118
|
* etc. These defaults can be extended by adding custom templates for languages other than the default, or even completely new types of emails
|
|
115
|
-
* which respond to any of the available [VendureEvents](/docs/typescript-api/events/).
|
|
116
|
-
*
|
|
119
|
+
* which respond to any of the available [VendureEvents](/docs/typescript-api/events/).
|
|
120
|
+
*
|
|
121
|
+
* A good way to learn how to create your own email handlers is to take a look at the
|
|
122
|
+
* [source code of the default handlers](https://github.com/vendure-ecommerce/vendure/blob/master/packages/email-plugin/src/default-email-handlers.ts).
|
|
123
|
+
* New handlers are defined in exactly the same way.
|
|
124
|
+
*
|
|
125
|
+
* It is also possible to modify the default handlers:
|
|
126
|
+
*
|
|
127
|
+
* ```TypeScript
|
|
128
|
+
* // Rather than importing `defaultEmailHandlers`, you can
|
|
129
|
+
* // import the handlers individually
|
|
130
|
+
* import {
|
|
131
|
+
* orderConfirmationHandler,
|
|
132
|
+
* emailVerificationHandler,
|
|
133
|
+
* passwordResetHandler,
|
|
134
|
+
* emailAddressChangeHandler,
|
|
135
|
+
* } from '\@vendure/email-plugin';
|
|
136
|
+
* import { CustomerService } from '\@vendure/core';
|
|
137
|
+
*
|
|
138
|
+
* // This allows you to then customize each handler to your needs.
|
|
139
|
+
* // For example, let's set a new subject line to the order confirmation:
|
|
140
|
+
* orderConfirmationHandler
|
|
141
|
+
* .setSubject(`We received your order!`);
|
|
142
|
+
*
|
|
143
|
+
* // Another example: loading additional data and setting new
|
|
144
|
+
* // template variables.
|
|
145
|
+
* passwordResetHandler
|
|
146
|
+
* .loadData(async ({ event, injector }) => {
|
|
147
|
+
* const customerService = injector.get(CustomerService);
|
|
148
|
+
* const customer = await customerService.findOneByUserId(event.ctx, event.user.id);
|
|
149
|
+
* return { customer };
|
|
150
|
+
* })
|
|
151
|
+
* .setTemplateVars(event => ({
|
|
152
|
+
* passwordResetToken: event.user.getNativeAuthenticationMethod().passwordResetToken,
|
|
153
|
+
* customer: event.data.customer,
|
|
154
|
+
* }));
|
|
155
|
+
*
|
|
156
|
+
* // Then you pass the handlers to the EmailPlugin init method
|
|
157
|
+
* // individually
|
|
158
|
+
* EmailPlugin.init({
|
|
159
|
+
* handlers: [
|
|
160
|
+
* orderConfirmationHandler,
|
|
161
|
+
* emailVerificationHandler,
|
|
162
|
+
* passwordResetHandler,
|
|
163
|
+
* emailAddressChangeHandler,
|
|
164
|
+
* ],
|
|
165
|
+
* // ...
|
|
166
|
+
* }),
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* For all available methods of extending a handler, see the {@link EmailEventHandler} documentation.
|
|
117
170
|
*
|
|
118
171
|
* ## Dev mode
|
|
119
172
|
*
|
|
@@ -121,7 +174,7 @@ const email_processor_1 = require("./email-processor");
|
|
|
121
174
|
* file transport (See {@link FileTransportOptions}) and outputs emails as rendered HTML files in the directory specified by the
|
|
122
175
|
* `outputPath` property.
|
|
123
176
|
*
|
|
124
|
-
* ```
|
|
177
|
+
* ```TypeScript
|
|
125
178
|
* EmailPlugin.init({
|
|
126
179
|
* devMode: true,
|
|
127
180
|
* route: 'mailbox',
|
|
@@ -169,12 +222,13 @@ const email_processor_1 = require("./email-processor");
|
|
|
169
222
|
*/
|
|
170
223
|
let EmailPlugin = EmailPlugin_1 = class EmailPlugin {
|
|
171
224
|
/** @internal */
|
|
172
|
-
constructor(eventBus, moduleRef, emailProcessor, jobQueueService, processContext) {
|
|
225
|
+
constructor(eventBus, moduleRef, emailProcessor, jobQueueService, processContext, options) {
|
|
173
226
|
this.eventBus = eventBus;
|
|
174
227
|
this.moduleRef = moduleRef;
|
|
175
228
|
this.emailProcessor = emailProcessor;
|
|
176
229
|
this.jobQueueService = jobQueueService;
|
|
177
230
|
this.processContext = processContext;
|
|
231
|
+
this.options = options;
|
|
178
232
|
}
|
|
179
233
|
/**
|
|
180
234
|
* Set the plugin options.
|
|
@@ -185,12 +239,12 @@ let EmailPlugin = EmailPlugin_1 = class EmailPlugin {
|
|
|
185
239
|
}
|
|
186
240
|
/** @internal */
|
|
187
241
|
async onApplicationBootstrap() {
|
|
188
|
-
|
|
242
|
+
await this.initInjectableStrategies();
|
|
189
243
|
await this.setupEventSubscribers();
|
|
190
|
-
if (!(0,
|
|
244
|
+
if (!(0, common_2.isDevModeOptions)(this.options) && this.options.transport.type === 'testing') {
|
|
191
245
|
// When running tests, we don't want to go through the JobQueue system,
|
|
192
246
|
// so we just call the email sending logic directly.
|
|
193
|
-
this.testingProcessor = new email_processor_1.EmailProcessor(options);
|
|
247
|
+
this.testingProcessor = new email_processor_1.EmailProcessor(this.options);
|
|
194
248
|
await this.testingProcessor.init();
|
|
195
249
|
}
|
|
196
250
|
else {
|
|
@@ -203,14 +257,35 @@ let EmailPlugin = EmailPlugin_1 = class EmailPlugin {
|
|
|
203
257
|
});
|
|
204
258
|
}
|
|
205
259
|
}
|
|
260
|
+
async onApplicationShutdown() {
|
|
261
|
+
await this.destroyInjectableStrategies();
|
|
262
|
+
}
|
|
206
263
|
configure(consumer) {
|
|
207
|
-
|
|
208
|
-
if ((0, common_1.isDevModeOptions)(options) && this.processContext.isServer) {
|
|
264
|
+
if ((0, common_2.isDevModeOptions)(this.options) && this.processContext.isServer) {
|
|
209
265
|
core_2.Logger.info('Creating dev mailbox middleware', constants_1.loggerCtx);
|
|
210
266
|
this.devMailbox = new dev_mailbox_1.DevMailbox();
|
|
211
|
-
consumer.apply(this.devMailbox.serve(options)).forRoutes(options.route);
|
|
267
|
+
consumer.apply(this.devMailbox.serve(this.options)).forRoutes(this.options.route);
|
|
212
268
|
this.devMailbox.handleMockEvent((handler, event) => this.handleEvent(handler, event));
|
|
213
|
-
(0, core_2.registerPluginStartupMessage)('Dev mailbox', options.route);
|
|
269
|
+
(0, core_2.registerPluginStartupMessage)('Dev mailbox', this.options.route);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async initInjectableStrategies() {
|
|
273
|
+
var _a, _b;
|
|
274
|
+
const injector = new core_2.Injector(this.moduleRef);
|
|
275
|
+
if (typeof ((_a = this.options.emailGenerator) === null || _a === void 0 ? void 0 : _a.init) === 'function') {
|
|
276
|
+
await this.options.emailGenerator.init(injector);
|
|
277
|
+
}
|
|
278
|
+
if (typeof ((_b = this.options.emailSender) === null || _b === void 0 ? void 0 : _b.init) === 'function') {
|
|
279
|
+
await this.options.emailSender.init(injector);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async destroyInjectableStrategies() {
|
|
283
|
+
var _a, _b;
|
|
284
|
+
if (typeof ((_a = this.options.emailGenerator) === null || _a === void 0 ? void 0 : _a.destroy) === 'function') {
|
|
285
|
+
await this.options.emailGenerator.destroy();
|
|
286
|
+
}
|
|
287
|
+
if (typeof ((_b = this.options.emailSender) === null || _b === void 0 ? void 0 : _b.destroy) === 'function') {
|
|
288
|
+
await this.options.emailSender.destroy();
|
|
214
289
|
}
|
|
215
290
|
}
|
|
216
291
|
async setupEventSubscribers() {
|
|
@@ -246,11 +321,12 @@ EmailPlugin = EmailPlugin_1 = __decorate([
|
|
|
246
321
|
imports: [core_2.PluginCommonModule],
|
|
247
322
|
providers: [{ provide: constants_1.EMAIL_PLUGIN_OPTIONS, useFactory: () => EmailPlugin_1.options }, email_processor_1.EmailProcessor],
|
|
248
323
|
}),
|
|
324
|
+
__param(5, (0, common_1.Inject)(constants_1.EMAIL_PLUGIN_OPTIONS)),
|
|
249
325
|
__metadata("design:paramtypes", [core_2.EventBus,
|
|
250
326
|
core_1.ModuleRef,
|
|
251
327
|
email_processor_1.EmailProcessor,
|
|
252
328
|
core_2.JobQueueService,
|
|
253
|
-
core_2.ProcessContext])
|
|
329
|
+
core_2.ProcessContext, Object])
|
|
254
330
|
], EmailPlugin);
|
|
255
331
|
exports.EmailPlugin = EmailPlugin;
|
|
256
332
|
//# sourceMappingURL=plugin.js.map
|
package/lib/src/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,uCAAyC;AACzC,wCAWuB;AAEvB,qCAA4C;AAC5C,2CAA8D;AAC9D,+CAA2C;AAC3C,uDAAmD;AASnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsMG;AAKH,IAAa,WAAW,mBAAxB,MAAa,WAAW;IAMpB,gBAAgB;IAChB,YACY,QAAkB,EAClB,SAAoB,EACpB,cAA8B,EAC9B,eAAgC,EAChC,cAA8B,EACA,OAA2B;QALzD,aAAQ,GAAR,QAAQ,CAAU;QAClB,cAAS,GAAT,SAAS,CAAW;QACpB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAiB;QAChC,mBAAc,GAAd,cAAc,CAAgB;QACA,YAAO,GAAP,OAAO,CAAoB;IAClE,CAAC;IAEJ;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,OAAuD;QAC/D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,aAAW,CAAC;IACvB,CAAC;IAED,gBAAgB;IAChB,KAAK,CAAC,sBAAsB;QACx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A,IAAA,eAAM,EAAC,gCAAoB,CAAC,CAAA;qCALX,eAAQ;QACP,gBAAS;QACJ,gCAAc;QACb,sBAAe;QAChB,qBAAc;GAZjC,WAAW,CA8GvB;AA9GY,kCAAW"}
|
package/lib/src/types.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { Omit } from '@vendure/common/lib/omit';
|
|
|
3
3
|
import { Injector, RequestContext, VendureEvent } from '@vendure/core';
|
|
4
4
|
import { Attachment } from 'nodemailer/lib/mailer';
|
|
5
5
|
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
6
|
+
import { EmailGenerator } from './email-generator';
|
|
7
|
+
import { EmailSender } from './email-sender';
|
|
6
8
|
import { EmailEventHandler } from './event-handler';
|
|
7
9
|
/**
|
|
8
10
|
* @description
|
|
@@ -195,72 +197,6 @@ export interface TestingTransportOptions {
|
|
|
195
197
|
*/
|
|
196
198
|
onSend: (details: EmailDetails) => void;
|
|
197
199
|
}
|
|
198
|
-
/**
|
|
199
|
-
* @description
|
|
200
|
-
* An EmailSender is responsible for sending the email, e.g. via an SMTP connection
|
|
201
|
-
* or using some other mail-sending API. By default, the EmailPlugin uses the
|
|
202
|
-
* {@link NodemailerEmailSender}, but it is also possible to supply a custom implementation:
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```TypeScript
|
|
206
|
-
* const sgMail = require('\@sendgrid/mail');
|
|
207
|
-
*
|
|
208
|
-
* sgMail.setApiKey(process.env.SENDGRID_API_KEY);
|
|
209
|
-
*
|
|
210
|
-
* class SendgridEmailSender implements EmailSender {
|
|
211
|
-
* async send(email: EmailDetails) {
|
|
212
|
-
* await sgMail.send({
|
|
213
|
-
* to: email.recipient,
|
|
214
|
-
* from: email.from,
|
|
215
|
-
* subject: email.subject,
|
|
216
|
-
* html: email.body,
|
|
217
|
-
* });
|
|
218
|
-
* }
|
|
219
|
-
* }
|
|
220
|
-
*
|
|
221
|
-
* const config: VendureConfig = {
|
|
222
|
-
* logger: new DefaultLogger({ level: LogLevel.Debug })
|
|
223
|
-
* // ...
|
|
224
|
-
* plugins: [
|
|
225
|
-
* EmailPlugin.init({
|
|
226
|
-
* // ... template, handlers config omitted
|
|
227
|
-
* transport: { type: 'none' },
|
|
228
|
-
* emailSender: new SendgridEmailSender(),
|
|
229
|
-
* }),
|
|
230
|
-
* ],
|
|
231
|
-
* };
|
|
232
|
-
* ```
|
|
233
|
-
*
|
|
234
|
-
* @docsCategory EmailPlugin
|
|
235
|
-
* @docsPage EmailSender
|
|
236
|
-
* @docsWeight 0
|
|
237
|
-
*/
|
|
238
|
-
export interface EmailSender {
|
|
239
|
-
send: (email: EmailDetails, options: EmailTransportOptions) => void | Promise<void>;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* @description
|
|
243
|
-
* An EmailGenerator generates the subject and body details of an email.
|
|
244
|
-
*
|
|
245
|
-
* @docsCategory EmailPlugin
|
|
246
|
-
* @docsPage EmailGenerator
|
|
247
|
-
* @docsWeight 0
|
|
248
|
-
*/
|
|
249
|
-
export interface EmailGenerator<T extends string = any, E extends VendureEvent = any> {
|
|
250
|
-
/**
|
|
251
|
-
* @description
|
|
252
|
-
* Any necessary setup can be performed here.
|
|
253
|
-
*/
|
|
254
|
-
onInit?(options: EmailPluginOptions): void | Promise<void>;
|
|
255
|
-
/**
|
|
256
|
-
* @description
|
|
257
|
-
* Given a subject and body from an email template, this method generates the final
|
|
258
|
-
* interpolated email text.
|
|
259
|
-
*/
|
|
260
|
-
generate(from: string, subject: string, body: string, templateVars: {
|
|
261
|
-
[key: string]: any;
|
|
262
|
-
}): Pick<EmailDetails, 'from' | 'subject' | 'body'>;
|
|
263
|
-
}
|
|
264
200
|
/**
|
|
265
201
|
* @description
|
|
266
202
|
* A function used to load async data for use by an {@link EmailEventHandler}.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vendure/email-plugin",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.20",
|
|
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": "^2.0.0-next.
|
|
39
|
-
"@vendure/core": "^2.0.0-next.
|
|
38
|
+
"@vendure/common": "^2.0.0-next.20",
|
|
39
|
+
"@vendure/core": "^2.0.0-next.20",
|
|
40
40
|
"rimraf": "^3.0.2",
|
|
41
41
|
"typescript": "4.5.5"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "f0766a7fa72cc56e647d3b4c3f213920c3fc7316"
|
|
44
44
|
}
|