|
@@ -2,7 +2,7 @@ import { LanguageCode } from '@vendure/common/lib/generated-types';
|
|
|
import { Omit } from '@vendure/common/lib/omit';
|
|
import { Omit } from '@vendure/common/lib/omit';
|
|
|
import { Injector, RequestContext, SerializedRequestContext, VendureEvent } from '@vendure/core';
|
|
import { Injector, RequestContext, SerializedRequestContext, VendureEvent } from '@vendure/core';
|
|
|
import { Attachment } from 'nodemailer/lib/mailer';
|
|
import { Attachment } from 'nodemailer/lib/mailer';
|
|
|
-import SESTransport from 'nodemailer/lib/ses-transport'
|
|
|
|
|
|
|
+import SESTransport from 'nodemailer/lib/ses-transport';
|
|
|
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
|
|
|
|
|
|
import { EmailGenerator } from './email-generator';
|
|
import { EmailGenerator } from './email-generator';
|
|
@@ -15,7 +15,7 @@ import { EmailEventHandler } from './event-handler';
|
|
|
* {@link RequestContext}, which is used to determine the channel and language
|
|
* {@link RequestContext}, which is used to determine the channel and language
|
|
|
* to use when generating the email.
|
|
* to use when generating the email.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Email Plugin Types
|
|
* @docsPage Email Plugin Types
|
|
|
*/
|
|
*/
|
|
|
export type EventWithContext = VendureEvent & { ctx: RequestContext };
|
|
export type EventWithContext = VendureEvent & { ctx: RequestContext };
|
|
@@ -25,7 +25,7 @@ export type EventWithContext = VendureEvent & { ctx: RequestContext };
|
|
|
* A VendureEvent with a {@link RequestContext} and a `data` property which contains the
|
|
* A VendureEvent with a {@link RequestContext} and a `data` property which contains the
|
|
|
* value resolved from the {@link EmailEventHandler}`.loadData()` callback.
|
|
* value resolved from the {@link EmailEventHandler}`.loadData()` callback.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Email Plugin Types
|
|
* @docsPage Email Plugin Types
|
|
|
*/
|
|
*/
|
|
|
export type EventWithAsyncData<Event extends EventWithContext, R> = Event & { data: R };
|
|
export type EventWithAsyncData<Event extends EventWithContext, R> = Event & { data: R };
|
|
@@ -34,7 +34,7 @@ export type EventWithAsyncData<Event extends EventWithContext, R> = Event & { da
|
|
|
* @description
|
|
* @description
|
|
|
* Configuration for the EmailPlugin.
|
|
* Configuration for the EmailPlugin.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage EmailPluginOptions
|
|
* @docsPage EmailPluginOptions
|
|
|
* */
|
|
* */
|
|
|
export interface EmailPluginOptions {
|
|
export interface EmailPluginOptions {
|
|
@@ -42,7 +42,7 @@ export interface EmailPluginOptions {
|
|
|
* @description
|
|
* @description
|
|
|
* The path to the location of the email templates. In a default Vendure installation,
|
|
* The path to the location of the email templates. In a default Vendure installation,
|
|
|
* the templates are installed to `<project root>/vendure/email/templates`.
|
|
* the templates are installed to `<project root>/vendure/email/templates`.
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @deprecated Use `templateLoader` to define a template path: `templateLoader: new FileBasedTemplateLoader('../your-path/templates')`
|
|
* @deprecated Use `templateLoader` to define a template path: `templateLoader: new FileBasedTemplateLoader('../your-path/templates')`
|
|
|
*/
|
|
*/
|
|
|
templatePath?: string;
|
|
templatePath?: string;
|
|
@@ -58,7 +58,12 @@ export interface EmailPluginOptions {
|
|
|
* @description
|
|
* @description
|
|
|
* Configures how the emails are sent.
|
|
* Configures how the emails are sent.
|
|
|
*/
|
|
*/
|
|
|
- transport: EmailTransportOptions | ((injector?: Injector, ctx?: RequestContext) => EmailTransportOptions | Promise<EmailTransportOptions>)
|
|
|
|
|
|
|
+ transport:
|
|
|
|
|
+ | EmailTransportOptions
|
|
|
|
|
+ | ((
|
|
|
|
|
+ injector?: Injector,
|
|
|
|
|
+ ctx?: RequestContext,
|
|
|
|
|
+ ) => EmailTransportOptions | Promise<EmailTransportOptions>);
|
|
|
/**
|
|
/**
|
|
|
* @description
|
|
* @description
|
|
|
* An array of {@link EmailEventHandler}s which define which Vendure events will trigger
|
|
* An array of {@link EmailEventHandler}s which define which Vendure events will trigger
|
|
@@ -99,7 +104,7 @@ export type InitializedEmailPluginOptions = EmailPluginOptions & { templateLoade
|
|
|
* @description
|
|
* @description
|
|
|
* Configuration for running the EmailPlugin in development mode.
|
|
* Configuration for running the EmailPlugin in development mode.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage EmailPluginOptions
|
|
* @docsPage EmailPluginOptions
|
|
|
*/
|
|
*/
|
|
|
export interface EmailPluginDevModeOptions extends Omit<EmailPluginOptions, 'transport'> {
|
|
export interface EmailPluginDevModeOptions extends Omit<EmailPluginOptions, 'transport'> {
|
|
@@ -120,7 +125,7 @@ export interface EmailPluginDevModeOptions extends Omit<EmailPluginOptions, 'tra
|
|
|
* @description
|
|
* @description
|
|
|
* A union of all the possible transport options for sending emails.
|
|
* A union of all the possible transport options for sending emails.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Transport Options
|
|
* @docsPage Transport Options
|
|
|
*/
|
|
*/
|
|
|
export type EmailTransportOptions =
|
|
export type EmailTransportOptions =
|
|
@@ -135,7 +140,7 @@ export type EmailTransportOptions =
|
|
|
* @description
|
|
* @description
|
|
|
* The SMTP transport options of [Nodemailer](https://nodemailer.com/smtp/)
|
|
* The SMTP transport options of [Nodemailer](https://nodemailer.com/smtp/)
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Transport Options
|
|
* @docsPage Transport Options
|
|
|
*/
|
|
*/
|
|
|
export interface SMTPTransportOptions extends SMTPTransport.Options {
|
|
export interface SMTPTransportOptions extends SMTPTransport.Options {
|
|
@@ -184,7 +189,7 @@ export interface SMTPTransportOptions extends SMTPTransport.Options {
|
|
|
* ],
|
|
* ],
|
|
|
* };
|
|
* };
|
|
|
* ```
|
|
* ```
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Transport Options
|
|
* @docsPage Transport Options
|
|
|
*/
|
|
*/
|
|
|
export interface SESTransportOptions extends SESTransport.Options {
|
|
export interface SESTransportOptions extends SESTransport.Options {
|
|
@@ -195,7 +200,7 @@ export interface SESTransportOptions extends SESTransport.Options {
|
|
|
* @description
|
|
* @description
|
|
|
* Uses the local Sendmail program to send the email.
|
|
* Uses the local Sendmail program to send the email.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Transport Options
|
|
* @docsPage Transport Options
|
|
|
*/
|
|
*/
|
|
|
export interface SendmailTransportOptions {
|
|
export interface SendmailTransportOptions {
|
|
@@ -210,7 +215,7 @@ export interface SendmailTransportOptions {
|
|
|
* @description
|
|
* @description
|
|
|
* Outputs the email as an HTML file for development purposes.
|
|
* Outputs the email as an HTML file for development purposes.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Transport Options
|
|
* @docsPage Transport Options
|
|
|
*/
|
|
*/
|
|
|
export interface FileTransportOptions {
|
|
export interface FileTransportOptions {
|
|
@@ -226,7 +231,7 @@ export interface FileTransportOptions {
|
|
|
* Does nothing with the generated email. Intended for use in testing where we don't care about the email transport,
|
|
* Does nothing with the generated email. Intended for use in testing where we don't care about the email transport,
|
|
|
* or when using a custom {@link EmailSender} which does not require transport options.
|
|
* or when using a custom {@link EmailSender} which does not require transport options.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Transport Options
|
|
* @docsPage Transport Options
|
|
|
*/
|
|
*/
|
|
|
export interface NoopTransportOptions {
|
|
export interface NoopTransportOptions {
|
|
@@ -237,7 +242,7 @@ export interface NoopTransportOptions {
|
|
|
* @description
|
|
* @description
|
|
|
* The final, generated email details to be sent.
|
|
* The final, generated email details to be sent.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Email Plugin Types
|
|
* @docsPage Email Plugin Types
|
|
|
*/
|
|
*/
|
|
|
export interface EmailDetails<Type extends 'serialized' | 'unserialized' = 'unserialized'> {
|
|
export interface EmailDetails<Type extends 'serialized' | 'unserialized' = 'unserialized'> {
|
|
@@ -255,7 +260,7 @@ export interface EmailDetails<Type extends 'serialized' | 'unserialized' = 'unse
|
|
|
* @description
|
|
* @description
|
|
|
* Forwards the raw GeneratedEmailContext object to a provided callback, for use in testing.
|
|
* Forwards the raw GeneratedEmailContext object to a provided callback, for use in testing.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Transport Options
|
|
* @docsPage Transport Options
|
|
|
*/
|
|
*/
|
|
|
export interface TestingTransportOptions {
|
|
export interface TestingTransportOptions {
|
|
@@ -271,7 +276,7 @@ export interface TestingTransportOptions {
|
|
|
* @description
|
|
* @description
|
|
|
* A function used to load async data for use by an {@link EmailEventHandler}.
|
|
* A function used to load async data for use by an {@link EmailEventHandler}.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Email Plugin Types
|
|
* @docsPage Email Plugin Types
|
|
|
*/
|
|
*/
|
|
|
export type LoadDataFn<Event extends EventWithContext, R> = (context: {
|
|
export type LoadDataFn<Event extends EventWithContext, R> = (context: {
|
|
@@ -290,7 +295,7 @@ export type OptionalToNullable<O> = {
|
|
|
* only uses the `path` property to define a filesystem path or a URL pointing to
|
|
* only uses the `path` property to define a filesystem path or a URL pointing to
|
|
|
* the attachment file.
|
|
* the attachment file.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Email Plugin Types
|
|
* @docsPage Email Plugin Types
|
|
|
*/
|
|
*/
|
|
|
export type EmailAttachment = Omit<Attachment, 'raw'> & { path?: string };
|
|
export type EmailAttachment = Omit<Attachment, 'raw'> & { path?: string };
|
|
@@ -317,8 +322,8 @@ export type IntermediateEmailDetails = {
|
|
|
* @description
|
|
* @description
|
|
|
* Configures the {@link EmailEventHandler} to handle a particular channel & languageCode
|
|
* Configures the {@link EmailEventHandler} to handle a particular channel & languageCode
|
|
|
* combination.
|
|
* combination.
|
|
|
- *
|
|
|
|
|
- * @deprecated Use a custom {@link TemplateLoader} instead.
|
|
|
|
|
|
|
+ *
|
|
|
|
|
+ * @deprecated Use a custom {@link TemplateLoader} instead.
|
|
|
*/
|
|
*/
|
|
|
export interface EmailTemplateConfig {
|
|
export interface EmailTemplateConfig {
|
|
|
/**
|
|
/**
|
|
@@ -347,30 +352,30 @@ export interface EmailTemplateConfig {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface LoadTemplateInput {
|
|
export interface LoadTemplateInput {
|
|
|
- type: string,
|
|
|
|
|
- templateName: string
|
|
|
|
|
|
|
+ type: string;
|
|
|
|
|
+ templateName: string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface Partial {
|
|
export interface Partial {
|
|
|
- name: string,
|
|
|
|
|
- content: string
|
|
|
|
|
|
|
+ name: string;
|
|
|
|
|
+ content: string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @description
|
|
* @description
|
|
|
* Load an email template based on the given request context, type and template name
|
|
* Load an email template based on the given request context, type and template name
|
|
|
* and return the template as a string.
|
|
* and return the template as a string.
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @example
|
|
* @example
|
|
|
* ```TypeScript
|
|
* ```TypeScript
|
|
|
* import { EmailPlugin, TemplateLoader } from '@vendure/email-plugin';
|
|
* import { EmailPlugin, TemplateLoader } from '@vendure/email-plugin';
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* class MyTemplateLoader implements TemplateLoader {
|
|
* class MyTemplateLoader implements TemplateLoader {
|
|
|
* loadTemplate(injector, ctx, { type, templateName }){
|
|
* loadTemplate(injector, ctx, { type, templateName }){
|
|
|
* return myCustomTemplateFunction(ctx);
|
|
* return myCustomTemplateFunction(ctx);
|
|
|
* }
|
|
* }
|
|
|
* }
|
|
* }
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* // In vendure-config.ts:
|
|
* // In vendure-config.ts:
|
|
|
* ...
|
|
* ...
|
|
|
* EmailPlugin.init({
|
|
* EmailPlugin.init({
|
|
@@ -379,7 +384,7 @@ export interface Partial {
|
|
|
* })
|
|
* })
|
|
|
* ```
|
|
* ```
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Custom Template Loader
|
|
* @docsPage Custom Template Loader
|
|
|
*/
|
|
*/
|
|
|
export interface TemplateLoader {
|
|
export interface TemplateLoader {
|
|
@@ -388,8 +393,8 @@ export interface TemplateLoader {
|
|
|
*/
|
|
*/
|
|
|
loadTemplate(injector: Injector, ctx: RequestContext, input: LoadTemplateInput): Promise<string>;
|
|
loadTemplate(injector: Injector, ctx: RequestContext, input: LoadTemplateInput): Promise<string>;
|
|
|
/**
|
|
/**
|
|
|
- * Load partials and return their contents.
|
|
|
|
|
- * This method is only called during initalization, i.e. during server startup.
|
|
|
|
|
|
|
+ * Load partials and return their contents.
|
|
|
|
|
+ * This method is only called during initalization, i.e. during server startup.
|
|
|
*/
|
|
*/
|
|
|
loadPartials?(): Promise<Partial[]>;
|
|
loadPartials?(): Promise<Partial[]>;
|
|
|
}
|
|
}
|
|
@@ -399,7 +404,7 @@ export interface TemplateLoader {
|
|
|
* A function used to define template variables available to email templates.
|
|
* A function used to define template variables available to email templates.
|
|
|
* See {@link EmailEventHandler}.setTemplateVars().
|
|
* See {@link EmailEventHandler}.setTemplateVars().
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Email Plugin Types
|
|
* @docsPage Email Plugin Types
|
|
|
*/
|
|
*/
|
|
|
export type SetTemplateVarsFn<Event> = (
|
|
export type SetTemplateVarsFn<Event> = (
|
|
@@ -413,7 +418,7 @@ export type SetTemplateVarsFn<Event> = (
|
|
|
* See https://nodemailer.com/message/attachments/ for more information about
|
|
* See https://nodemailer.com/message/attachments/ for more information about
|
|
|
* how attachments work in Nodemailer.
|
|
* how attachments work in Nodemailer.
|
|
|
*
|
|
*
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Email Plugin Types
|
|
* @docsPage Email Plugin Types
|
|
|
*/
|
|
*/
|
|
|
export type SetAttachmentsFn<Event> = (event: Event) => EmailAttachment[] | Promise<EmailAttachment[]>;
|
|
export type SetAttachmentsFn<Event> = (event: Event) => EmailAttachment[] | Promise<EmailAttachment[]>;
|
|
@@ -423,7 +428,7 @@ export type SetAttachmentsFn<Event> = (event: Event) => EmailAttachment[] | Prom
|
|
|
* Optional address-related fields for sending the email.
|
|
* Optional address-related fields for sending the email.
|
|
|
*
|
|
*
|
|
|
* @since 1.1.0
|
|
* @since 1.1.0
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Email Plugin Types
|
|
* @docsPage Email Plugin Types
|
|
|
*/
|
|
*/
|
|
|
export interface OptionalAddressFields {
|
|
export interface OptionalAddressFields {
|
|
@@ -449,7 +454,7 @@ export interface OptionalAddressFields {
|
|
|
* A function used to set the {@link OptionalAddressFields}.
|
|
* A function used to set the {@link OptionalAddressFields}.
|
|
|
*
|
|
*
|
|
|
* @since 1.1.0
|
|
* @since 1.1.0
|
|
|
- * @docsCategory EmailPlugin
|
|
|
|
|
|
|
+ * @docsCategory core plugins/EmailPlugin
|
|
|
* @docsPage Email Plugin Types
|
|
* @docsPage Email Plugin Types
|
|
|
*/
|
|
*/
|
|
|
export type SetOptionalAddressFieldsFn<Event> = (
|
|
export type SetOptionalAddressFieldsFn<Event> = (
|