@payloadcms/email-nodemailer 3.0.0-alpha.63 → 3.0.0-beta.12

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/dist/index.d.ts CHANGED
@@ -8,11 +8,12 @@ export type NodemailerAdapterArgs = {
8
8
  transport?: Transporter;
9
9
  transportOptions?: SMTPConnection.Options;
10
10
  };
11
- export type NodemailerAdapter = EmailAdapter<unknown>;
11
+ type NodemailerAdapter = EmailAdapter<unknown>;
12
12
  /**
13
13
  * Creates an email adapter using nodemailer
14
14
  *
15
15
  * If no email configuration is provided, an ethereal email test account is returned
16
16
  */
17
17
  export declare const nodemailerAdapter: (args?: NodemailerAdapterArgs) => Promise<NodemailerAdapter>;
18
+ export {};
18
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAKlD,MAAM,MAAM,qBAAqB,GAAG;IAClC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,gBAAgB,CAAC,EAAE,cAAc,CAAC,OAAO,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;AAErD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,UACrB,qBAAqB,KAC3B,QAAQ,iBAAiB,CAc3B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAKlD,MAAM,MAAM,qBAAqB,GAAG;IAClC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,gBAAgB,CAAC,EAAE,cAAc,CAAC,OAAO,CAAA;CAC1C,CAAA;AAED,KAAK,iBAAiB,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;AAE9C;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,UACrB,qBAAqB,KAC3B,QAAQ,iBAAiB,CAc3B,CAAA"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport type { Transporter } from 'nodemailer'\nimport type SMTPConnection from 'nodemailer/lib/smtp-connection'\nimport type { EmailAdapter } from 'payload/config'\n\nimport nodemailer from 'nodemailer'\nimport { InvalidConfiguration } from 'payload/errors'\n\nexport type NodemailerAdapterArgs = {\n defaultFromAddress: string\n defaultFromName: string\n skipVerify?: boolean\n transport?: Transporter\n transportOptions?: SMTPConnection.Options\n}\n\nexport type NodemailerAdapter = EmailAdapter<unknown>\n\n/**\n * Creates an email adapter using nodemailer\n *\n * If no email configuration is provided, an ethereal email test account is returned\n */\nexport const nodemailerAdapter = async (\n args?: NodemailerAdapterArgs,\n): Promise<NodemailerAdapter> => {\n const { defaultFromAddress, defaultFromName, transport } = await buildEmail(args)\n\n const adapter: NodemailerAdapter = () => ({\n defaultFromAddress,\n defaultFromName,\n sendEmail: async (message) => {\n return await transport.sendMail({\n from: `${defaultFromName} <${defaultFromAddress}>`,\n ...message,\n })\n },\n })\n return adapter\n}\n\nasync function buildEmail(emailConfig?: NodemailerAdapterArgs): Promise<{\n defaultFromAddress: string\n defaultFromName: string\n transport: Transporter\n}> {\n if (!emailConfig) {\n const transport = await createMockAccount(emailConfig)\n if (!transport) throw new InvalidConfiguration('Unable to create Nodemailer test account.')\n\n return {\n defaultFromAddress: 'info@payloadcms.com',\n defaultFromName: 'Payload',\n transport,\n }\n }\n\n // Create or extract transport\n let transport: Transporter\n if ('transport' in emailConfig && emailConfig.transport) {\n ;({ transport } = emailConfig)\n } else if ('transportOptions' in emailConfig && emailConfig.transportOptions) {\n transport = nodemailer.createTransport(emailConfig.transportOptions)\n } else {\n transport = await createMockAccount(emailConfig)\n }\n\n if (emailConfig.skipVerify !== false) {\n await verifyTransport(transport)\n }\n\n return {\n defaultFromAddress: emailConfig.defaultFromAddress,\n defaultFromName: emailConfig.defaultFromName,\n transport,\n }\n}\n\nasync function verifyTransport(transport: Transporter) {\n try {\n await transport.verify()\n } catch (err: unknown) {\n console.error({ err, msg: 'Error verifying Nodemailer transport.' })\n }\n}\n\n/**\n * Use ethereal.email to create a mock email account\n */\nasync function createMockAccount(emailConfig?: NodemailerAdapterArgs) {\n try {\n const etherealAccount = await nodemailer.createTestAccount()\n\n const smtpOptions = {\n ...(emailConfig || {}),\n auth: {\n pass: etherealAccount.pass,\n user: etherealAccount.user,\n },\n fromAddress: emailConfig?.defaultFromAddress,\n fromName: emailConfig?.defaultFromName,\n host: 'smtp.ethereal.email',\n port: 587,\n secure: false,\n }\n const transport = nodemailer.createTransport(smtpOptions)\n const { pass, user, web } = etherealAccount\n\n console.info('E-mail configured with ethereal.email test account. ')\n console.info(`Log into mock email provider at ${web}`)\n console.info(`Mock email account username: ${user}`)\n console.info(`Mock email account password: ${pass}`)\n return transport\n } catch (err: unknown) {\n if (err instanceof Error) {\n console.error({ err, msg: 'There was a problem setting up the mock email handler' })\n throw new InvalidConfiguration(\n `Unable to create Nodemailer test account. Error: ${err.message}`,\n )\n }\n throw new InvalidConfiguration('Unable to create Nodemailer test account.')\n }\n}\n"],"names":["nodemailer","InvalidConfiguration","nodemailerAdapter","args","defaultFromAddress","defaultFromName","transport","buildEmail","adapter","sendEmail","message","sendMail","from","emailConfig","createMockAccount","transportOptions","createTransport","skipVerify","verifyTransport","verify","err","console","error","msg","etherealAccount","createTestAccount","smtpOptions","auth","pass","user","fromAddress","fromName","host","port","secure","web","info","Error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,6BAA6B,GAK7B,OAAOA,gBAAgB,aAAY;AACnC,SAASC,oBAAoB,QAAQ,iBAAgB;AAYrD;;;;CAIC,GACD,OAAO,MAAMC,oBAAoB,OAC/BC;IAEA,MAAM,EAAEC,kBAAkB,EAAEC,eAAe,EAAEC,SAAS,EAAE,GAAG,MAAMC,WAAWJ;IAE5E,MAAMK,UAA6B,IAAO,CAAA;YACxCJ;YACAC;YACAI,WAAW,OAAOC;gBAChB,OAAO,MAAMJ,UAAUK,QAAQ,CAAC;oBAC9BC,MAAM,CAAC,EAAEP,gBAAgB,EAAE,EAAED,mBAAmB,CAAC,CAAC;oBAClD,GAAGM,OAAO;gBACZ;YACF;QACF,CAAA;IACA,OAAOF;AACT,EAAC;AAED,eAAeD,WAAWM,WAAmC;IAK3D,IAAI,CAACA,aAAa;QAChB,MAAMP,YAAY,MAAMQ,kBAAkBD;QAC1C,IAAI,CAACP,WAAW,MAAM,IAAIL,qBAAqB;QAE/C,OAAO;YACLG,oBAAoB;YACpBC,iBAAiB;YACjBC;QACF;IACF;IAEA,8BAA8B;IAC9B,IAAIA;IACJ,IAAI,eAAeO,eAAeA,YAAYP,SAAS,EAAE;QACrD,CAAA,EAAEA,SAAS,EAAE,GAAGO,WAAU;IAC9B,OAAO,IAAI,sBAAsBA,eAAeA,YAAYE,gBAAgB,EAAE;QAC5ET,YAAYN,WAAWgB,eAAe,CAACH,YAAYE,gBAAgB;IACrE,OAAO;QACLT,YAAY,MAAMQ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":["../src/index.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport type { Transporter } from 'nodemailer'\nimport type SMTPConnection from 'nodemailer/lib/smtp-connection'\nimport type { EmailAdapter } from 'payload/config'\n\nimport nodemailer from 'nodemailer'\nimport { InvalidConfiguration } from 'payload/errors'\n\nexport type NodemailerAdapterArgs = {\n defaultFromAddress: string\n defaultFromName: string\n skipVerify?: boolean\n transport?: Transporter\n transportOptions?: SMTPConnection.Options\n}\n\ntype NodemailerAdapter = EmailAdapter<unknown>\n\n/**\n * Creates an email adapter using nodemailer\n *\n * If no email configuration is provided, an ethereal email test account is returned\n */\nexport const nodemailerAdapter = async (\n args?: NodemailerAdapterArgs,\n): Promise<NodemailerAdapter> => {\n const { defaultFromAddress, defaultFromName, transport } = await buildEmail(args)\n\n const adapter: NodemailerAdapter = () => ({\n defaultFromAddress,\n defaultFromName,\n sendEmail: async (message) => {\n return await transport.sendMail({\n from: `${defaultFromName} <${defaultFromAddress}>`,\n ...message,\n })\n },\n })\n return adapter\n}\n\nasync function buildEmail(emailConfig?: NodemailerAdapterArgs): Promise<{\n defaultFromAddress: string\n defaultFromName: string\n transport: Transporter\n}> {\n if (!emailConfig) {\n const transport = await createMockAccount(emailConfig)\n if (!transport) throw new InvalidConfiguration('Unable to create Nodemailer test account.')\n\n return {\n defaultFromAddress: 'info@payloadcms.com',\n defaultFromName: 'Payload',\n transport,\n }\n }\n\n // Create or extract transport\n let transport: Transporter\n if ('transport' in emailConfig && emailConfig.transport) {\n ;({ transport } = emailConfig)\n } else if ('transportOptions' in emailConfig && emailConfig.transportOptions) {\n transport = nodemailer.createTransport(emailConfig.transportOptions)\n } else {\n transport = await createMockAccount(emailConfig)\n }\n\n if (emailConfig.skipVerify !== false) {\n await verifyTransport(transport)\n }\n\n return {\n defaultFromAddress: emailConfig.defaultFromAddress,\n defaultFromName: emailConfig.defaultFromName,\n transport,\n }\n}\n\nasync function verifyTransport(transport: Transporter) {\n try {\n await transport.verify()\n } catch (err: unknown) {\n console.error({ err, msg: 'Error verifying Nodemailer transport.' })\n }\n}\n\n/**\n * Use ethereal.email to create a mock email account\n */\nasync function createMockAccount(emailConfig?: NodemailerAdapterArgs) {\n try {\n const etherealAccount = await nodemailer.createTestAccount()\n\n const smtpOptions = {\n ...(emailConfig || {}),\n auth: {\n pass: etherealAccount.pass,\n user: etherealAccount.user,\n },\n fromAddress: emailConfig?.defaultFromAddress,\n fromName: emailConfig?.defaultFromName,\n host: 'smtp.ethereal.email',\n port: 587,\n secure: false,\n }\n const transport = nodemailer.createTransport(smtpOptions)\n const { pass, user, web } = etherealAccount\n\n console.info('E-mail configured with ethereal.email test account. ')\n console.info(`Log into mock email provider at ${web}`)\n console.info(`Mock email account username: ${user}`)\n console.info(`Mock email account password: ${pass}`)\n return transport\n } catch (err: unknown) {\n if (err instanceof Error) {\n console.error({ err, msg: 'There was a problem setting up the mock email handler' })\n throw new InvalidConfiguration(\n `Unable to create Nodemailer test account. Error: ${err.message}`,\n )\n }\n throw new InvalidConfiguration('Unable to create Nodemailer test account.')\n }\n}\n"],"names":["nodemailer","InvalidConfiguration","nodemailerAdapter","args","defaultFromAddress","defaultFromName","transport","buildEmail","adapter","sendEmail","message","sendMail","from","emailConfig","createMockAccount","transportOptions","createTransport","skipVerify","verifyTransport","verify","err","console","error","msg","etherealAccount","createTestAccount","smtpOptions","auth","pass","user","fromAddress","fromName","host","port","secure","web","info","Error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,6BAA6B,GAK7B,OAAOA,gBAAgB,aAAY;AACnC,SAASC,oBAAoB,QAAQ,iBAAgB;AAYrD;;;;CAIC,GACD,OAAO,MAAMC,oBAAoB,OAC/BC;IAEA,MAAM,EAAEC,kBAAkB,EAAEC,eAAe,EAAEC,SAAS,EAAE,GAAG,MAAMC,WAAWJ;IAE5E,MAAMK,UAA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gBAAgBK,IAAI;YAC5B;YACAC,aAAajB,aAAaT;YAC1B2B,UAAUlB,aAAaR;YACvB2B,MAAM;YACNC,MAAM;YACNC,QAAQ;QACV;QACA,MAAM5B,YAAYN,WAAWgB,eAAe,CAACU;QAC7C,MAAM,EAAEE,IAAI,EAAEC,IAAI,EAAEM,GAAG,EAAE,GAAGX;QAE5BH,QAAQe,IAAI,CAAC;QACbf,QAAQe,IAAI,CAAC,CAAC,gCAAgC,EAAED,IAAI,CAAC;QACrDd,QAAQe,IAAI,CAAC,CAAC,6BAA6B,EAAEP,KAAK,CAAC;QACnDR,QAAQe,IAAI,CAAC,CAAC,6BAA6B,EAAER,KAAK,CAAC;QACnD,OAAOtB;IACT,EAAE,OAAOc,KAAc;QACrB,IAAIA,eAAeiB,OAAO;YACxBhB,QAAQC,KAAK,CAAC;gBAAEF;gBAAKG,KAAK;YAAwD;YAClF,MAAM,IAAItB,qBACR,CAAC,iDAAiD,EAAEmB,IAAIV,OAAO,CAAC,CAAC;QAErE;QACA,MAAM,IAAIT,qBAAqB;IACjC;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/email-nodemailer",
3
- "version": "3.0.0-alpha.63",
3
+ "version": "3.0.0-beta.12",
4
4
  "description": "Payload Nodemailer Email Adapter",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,7 @@
17
17
  "nodemailer": "6.9.10"
18
18
  },
19
19
  "peerDependencies": {
20
- "payload": "3.0.0-alpha.63"
20
+ "payload": "3.0.0-beta.12"
21
21
  },
22
22
  "exports": {
23
23
  ".": {
@@ -37,7 +37,7 @@
37
37
  ],
38
38
  "devDependencies": {
39
39
  "@types/nodemailer": "6.4.14",
40
- "payload": "3.0.0-alpha.63"
40
+ "payload": "3.0.0-beta.12"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "pnpm build:swc && pnpm build:types",
package/src/index.ts DELETED
@@ -1,123 +0,0 @@
1
- /* eslint-disable no-console */
2
- import type { Transporter } from 'nodemailer'
3
- import type SMTPConnection from 'nodemailer/lib/smtp-connection'
4
- import type { EmailAdapter } from 'payload/config'
5
-
6
- import nodemailer from 'nodemailer'
7
- import { InvalidConfiguration } from 'payload/errors'
8
-
9
- export type NodemailerAdapterArgs = {
10
- defaultFromAddress: string
11
- defaultFromName: string
12
- skipVerify?: boolean
13
- transport?: Transporter
14
- transportOptions?: SMTPConnection.Options
15
- }
16
-
17
- export type NodemailerAdapter = EmailAdapter<unknown>
18
-
19
- /**
20
- * Creates an email adapter using nodemailer
21
- *
22
- * If no email configuration is provided, an ethereal email test account is returned
23
- */
24
- export const nodemailerAdapter = async (
25
- args?: NodemailerAdapterArgs,
26
- ): Promise<NodemailerAdapter> => {
27
- const { defaultFromAddress, defaultFromName, transport } = await buildEmail(args)
28
-
29
- const adapter: NodemailerAdapter = () => ({
30
- defaultFromAddress,
31
- defaultFromName,
32
- sendEmail: async (message) => {
33
- return await transport.sendMail({
34
- from: `${defaultFromName} <${defaultFromAddress}>`,
35
- ...message,
36
- })
37
- },
38
- })
39
- return adapter
40
- }
41
-
42
- async function buildEmail(emailConfig?: NodemailerAdapterArgs): Promise<{
43
- defaultFromAddress: string
44
- defaultFromName: string
45
- transport: Transporter
46
- }> {
47
- if (!emailConfig) {
48
- const transport = await createMockAccount(emailConfig)
49
- if (!transport) throw new InvalidConfiguration('Unable to create Nodemailer test account.')
50
-
51
- return {
52
- defaultFromAddress: 'info@payloadcms.com',
53
- defaultFromName: 'Payload',
54
- transport,
55
- }
56
- }
57
-
58
- // Create or extract transport
59
- let transport: Transporter
60
- if ('transport' in emailConfig && emailConfig.transport) {
61
- ;({ transport } = emailConfig)
62
- } else if ('transportOptions' in emailConfig && emailConfig.transportOptions) {
63
- transport = nodemailer.createTransport(emailConfig.transportOptions)
64
- } else {
65
- transport = await createMockAccount(emailConfig)
66
- }
67
-
68
- if (emailConfig.skipVerify !== false) {
69
- await verifyTransport(transport)
70
- }
71
-
72
- return {
73
- defaultFromAddress: emailConfig.defaultFromAddress,
74
- defaultFromName: emailConfig.defaultFromName,
75
- transport,
76
- }
77
- }
78
-
79
- async function verifyTransport(transport: Transporter) {
80
- try {
81
- await transport.verify()
82
- } catch (err: unknown) {
83
- console.error({ err, msg: 'Error verifying Nodemailer transport.' })
84
- }
85
- }
86
-
87
- /**
88
- * Use ethereal.email to create a mock email account
89
- */
90
- async function createMockAccount(emailConfig?: NodemailerAdapterArgs) {
91
- try {
92
- const etherealAccount = await nodemailer.createTestAccount()
93
-
94
- const smtpOptions = {
95
- ...(emailConfig || {}),
96
- auth: {
97
- pass: etherealAccount.pass,
98
- user: etherealAccount.user,
99
- },
100
- fromAddress: emailConfig?.defaultFromAddress,
101
- fromName: emailConfig?.defaultFromName,
102
- host: 'smtp.ethereal.email',
103
- port: 587,
104
- secure: false,
105
- }
106
- const transport = nodemailer.createTransport(smtpOptions)
107
- const { pass, user, web } = etherealAccount
108
-
109
- console.info('E-mail configured with ethereal.email test account. ')
110
- console.info(`Log into mock email provider at ${web}`)
111
- console.info(`Mock email account username: ${user}`)
112
- console.info(`Mock email account password: ${pass}`)
113
- return transport
114
- } catch (err: unknown) {
115
- if (err instanceof Error) {
116
- console.error({ err, msg: 'There was a problem setting up the mock email handler' })
117
- throw new InvalidConfiguration(
118
- `Unable to create Nodemailer test account. Error: ${err.message}`,
119
- )
120
- }
121
- throw new InvalidConfiguration('Unable to create Nodemailer test account.')
122
- }
123
- }