@stacksjs/email 0.58.72 → 0.59.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/README.md +0 -1
- package/dist/drivers/index.d.ts +1 -0
- package/dist/drivers/ses.d.ts +1 -0
- package/dist/email.d.ts +19 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +66 -274
- package/dist/template.d.ts +6 -0
- package/dist/types.d.ts +41 -0
- package/package.json +4 -31
- package/src/drivers/index.ts +2 -8
- package/src/drivers/mailgun.ts +21 -21
- package/src/drivers/nodemailer.ts +23 -23
- package/src/drivers/ses.ts +18 -17
- package/src/email.ts +84 -0
- package/src/index.ts +2 -0
- package/src/send.ts +22 -25
- package/src/server/converter.ts +305 -305
- package/src/server/inbound.ts +406 -406
- package/src/server/outbound.ts +296 -296
- package/src/template.ts +18 -0
- package/src/types.ts +39 -0
- package/src/drivers/emailjs.ts +0 -23
- package/src/drivers/mailjet.ts +0 -21
- package/src/drivers/mandrill.ts +0 -19
- package/src/drivers/netcore.ts +0 -19
- package/src/drivers/postmark.ts +0 -19
- package/src/drivers/sendgrid.ts +0 -20
- package/src/tailwind.config.ts +0 -39
- package/src/utils/template.html +0 -8
package/src/email.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { SES } from '@aws-sdk/client-ses'
|
|
2
|
+
import type { RenderOptions } from './template'
|
|
3
|
+
import { template } from './template'
|
|
4
|
+
import type { Message, SendEmailParams } from './types'
|
|
5
|
+
|
|
6
|
+
export class Email {
|
|
7
|
+
private client: SES
|
|
8
|
+
|
|
9
|
+
constructor(private message: Message) {
|
|
10
|
+
this.client = new SES({ region: 'us-east-1' })
|
|
11
|
+
this.message = message
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public async send(options?: RenderOptions) {
|
|
15
|
+
log.info('Sending email...')
|
|
16
|
+
const path = this.message.template
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const templ = await template(path, options)
|
|
20
|
+
|
|
21
|
+
const params: SendEmailParams = {
|
|
22
|
+
Source: this.message.from?.address || '',
|
|
23
|
+
|
|
24
|
+
Destination: {
|
|
25
|
+
ToAddresses: [this.message.to],
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
Message: {
|
|
29
|
+
Body: {
|
|
30
|
+
Html: {
|
|
31
|
+
Charset: 'UTF-8',
|
|
32
|
+
Data: templ.html,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
Subject: {
|
|
37
|
+
Charset: 'UTF-8',
|
|
38
|
+
Data: this.message.subject,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await this.client.sendEmail(params)
|
|
44
|
+
|
|
45
|
+
let returnMsg: { message: string } = { message: 'Email sent' }
|
|
46
|
+
|
|
47
|
+
if (this.message.handle)
|
|
48
|
+
returnMsg = await this.message.handle()
|
|
49
|
+
|
|
50
|
+
await this.onSuccess()
|
|
51
|
+
|
|
52
|
+
return returnMsg
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return this.onError(error as Error)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public async onError(error: Error) {
|
|
60
|
+
log.error(error)
|
|
61
|
+
|
|
62
|
+
if (!this.message.onError)
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
return await this.message.onError(error)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public onSuccess() {
|
|
69
|
+
try {
|
|
70
|
+
if (!this.message.onSuccess)
|
|
71
|
+
return
|
|
72
|
+
|
|
73
|
+
this.message.onSuccess()
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return this.onError(error as Error)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type { Message }
|
|
82
|
+
|
|
83
|
+
export const email = (options: Message) => new Email(options)
|
|
84
|
+
export default Email
|
package/src/index.ts
CHANGED
package/src/send.ts
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
import { italic
|
|
1
|
+
import { italic } from '@stacksjs/cli'
|
|
2
2
|
import { ResultAsync } from '@stacksjs/error-handling'
|
|
3
3
|
import type { EmailOptions } from '@stacksjs/types'
|
|
4
|
-
import * as Maizzle from '@maizzle/framework'
|
|
5
4
|
|
|
6
5
|
// import { stringify } from 'json5'
|
|
7
|
-
import * as maizzleConfig from './utils/config'
|
|
8
6
|
|
|
9
|
-
export async function send(options: EmailOptions, provider: any, providerName: string
|
|
10
|
-
const template = `
|
|
11
|
-
<extends src="./src/notifications/src/utils/template.html">
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
</extends>`
|
|
7
|
+
export async function send(options: EmailOptions, provider: any, providerName: string): Promise<ResultAsync<any, Error>> {
|
|
8
|
+
// const template = `
|
|
9
|
+
// <extends src="./src/notifications/src/utils/template.html">
|
|
10
|
+
// <block name="template">
|
|
11
|
+
// ${options.html}
|
|
12
|
+
// </block>
|
|
13
|
+
// </extends>`
|
|
16
14
|
|
|
17
|
-
await Maizzle.render(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
// await Maizzle.render(
|
|
16
|
+
// template,
|
|
17
|
+
// {
|
|
18
|
+
// tailwind: {
|
|
19
|
+
// // config: stringify(config),
|
|
20
|
+
// css,
|
|
21
|
+
// maizzle: maizzleConfig,
|
|
22
|
+
// },
|
|
23
|
+
// },
|
|
24
|
+
// )
|
|
25
|
+
// .then(({ html }: any) => {
|
|
26
|
+
// options.html = html
|
|
27
|
+
// })
|
|
28
|
+
// .catch((error: any) => log.error(`Failed to render email template using provider: ${italic(providerName)}.`, error))
|
|
31
29
|
|
|
32
30
|
return ResultAsync.fromPromise(
|
|
33
|
-
|
|
34
31
|
provider.sendMessage(options),
|
|
35
32
|
() => new Error(`Failed to send message using provider: ${italic(providerName)}`),
|
|
36
33
|
)
|