@stacksjs/email 0.66.0 → 0.68.0

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.
@@ -1,296 +0,0 @@
1
- // /* eslint-disable eslint-comments/no-unlimited-disable */
2
- // /* eslint-disable */
3
- //
4
- // const AWS = require('aws-sdk')
5
- // const moment = require('moment')
6
- // const uuidv1 = require('uuid/v1')
7
- // const MailComposer = require('nodemailer/lib/mail-composer')
8
- //
9
- // // Initialize S3
10
- // const s3 = new AWS.S3({
11
- // apiVersion: '2006-03-01',
12
- // })
13
- //
14
- // // Initialize SES
15
- // const ses = new AWS.SES({
16
- // apiVersion: '2010-12-01',
17
- // })
18
- //
19
- // // This lambda will read outgoing emails formatted in JSON, convert them
20
- // // in to a raw email, send them using SES, and store them in S3.
21
- // exports.handler = (event: any) => {
22
- // // This JS object will contain all the data within the chain
23
- // const container = {
24
- // bucket: event.Records[0].s3.bucket.name,
25
- // key: event.Records[0].s3.object.key,
26
- // email: {
27
- // json: {},
28
- // raw: '',
29
- // },
30
- // uuid: uuidv1(),
31
- // }
32
- //
33
- // // -> Start the chain.
34
- // load_the_email(container)
35
- // .then((container) => {
36
- // return extract_data(container)
37
- // }).then((container) => {
38
- // return generate_the_raw_email(container)
39
- // }).then((container) => {
40
- // return send_email(container)
41
- // }).then((container) => {
42
- // return save_raw_email(container)
43
- // }).then((container) => {
44
- // return copy_raw_email(container)
45
- // }).then((container) => {
46
- // return delete_json_email(container)
47
- // }).then((container) => {
48
- // return delete_raw_email(container)
49
- // }).then((container) => {
50
- // return true
51
- // }).catch((error) => {
52
- // console.error(error)
53
- //
54
- // return false
55
- // })
56
- // }
57
- //
58
- // // Load the JSON email that triggered this Lambda.
59
- // function load_the_email(container: any) {
60
- // return new Promise((resolve, reject) => {
61
- // console.info('load_the_email')
62
- //
63
- // // 1. Set the query.
64
- // const params = {
65
- // Bucket: container.bucket,
66
- // Key: container.key,
67
- // }
68
- //
69
- // // -> Execute the query.
70
- // s3.getObject(params, (error: any, data: any) => {
71
- // // 1. Check for internal errors.
72
- // if (error)
73
- // return reject(error)
74
- //
75
- // // 2. Save the email for the next promise.
76
- // container.email.json = JSON.parse(data.Body)
77
- //
78
- // // -> Move to the next chain.
79
- // return resolve(container)
80
- // })
81
- // })
82
- // }
83
- //
84
- // // Extract all the data necessary to organize the incoming emails.
85
- // function extract_data(container: any) {
86
- // return new Promise((resolve, reject) => {
87
- // console.info('extract_data')
88
- //
89
- // // 1. Extract all the information
90
- // const tmp_to = container.email.json
91
- // .to
92
- // .match(/[a-z0-9-+]{1,30}@[a-z0-9-]{1,65}.[a-z]{1,}/gm)[0]
93
- // .split('@')
94
- //
95
- // const tmp_from = container.email.json
96
- // .from
97
- // .match(/[a-z0-9-+]{1,30}@[a-z0-9-]{1,65}.[a-z]{1,}/gm)[0]
98
- // .split('@')
99
- //
100
- // // 2. Get the domain name of the receiving end, so we can group
101
- // // emails by all the domain that were added to SES.
102
- // const to_domain = tmp_to[1]
103
- //
104
- // // 3. Based on the email name, we replace all the + characters, that
105
- // // can be used to organize ones on-line accounts in to /, this way
106
- // // we can build a S3 patch which will automatically organize
107
- // // all the email in structured folder.
108
- // const to_account = tmp_to[0].replace(/\+/g, '/')
109
- //
110
- // // 4. Get the domain name of the email which in our case will
111
- // // become the company name.
112
- // const from_domain = tmp_from[1]
113
- //
114
- // // 5. Get the name of who sent us the email.
115
- // const from_account = tmp_from[0]
116
- //
117
- // // 6. Create a human readable time stamp that matches the format
118
- // // S3 Provides in its Event.
119
- // const date = moment().format('ddd, DD MMM YYYY HH:MM:SS ZZ')
120
- //
121
- // // 7. Create the path where the email needs to be moved
122
- // // so it is properly organized.
123
- // const path = `sent/${
124
- // to_domain
125
- // }/${
126
- // to_account
127
- // }/${
128
- // from_domain
129
- // }/${
130
- // from_account
131
- // }/${
132
- // date
133
- // } - ${
134
- // container.email.json.subject
135
- // }/`
136
- // + 'email'
137
- //
138
- // // 8. Save the path for the next promise.
139
- // container.path = path
140
- //
141
- // // -> Move to the next chain.
142
- // return resolve(container)
143
- // })
144
- // }
145
- //
146
- // // From the JSON file that we loaded in to memory we generate a RAW version that
147
- // // can be used by SES, and later on stored and converted in multiple formats
148
- // function generate_the_raw_email(container: any) {
149
- // return new Promise((resolve, reject) => {
150
- // console.info('generate_the_raw_email')
151
- //
152
- // // 1. Crete the email based on the message object which holds all the
153
- // // necessary information.
154
- // const mail = new MailComposer(container.email.json)
155
- //
156
- // // 2. Take the email and compile it down to its text form for storage.
157
- // mail.compile().build((error: any, raw_message: any) => {
158
- // // 1. Check if there was an error
159
- // if (error)
160
- // return reject(error)
161
- //
162
- // // 2. Save the raw email so we can save it as is in to S3.
163
- // container.email.raw = raw_message
164
- //
165
- // // -> Move to the next promise
166
- // return resolve(container)
167
- // })
168
- // })
169
- // }
170
- //
171
- // // Use the newly generated RAW email and send it using SES.
172
- // function send_email(container: any) {
173
- // return new Promise((resolve, reject) => {
174
- // console.info('send_email')
175
- //
176
- // // 1. Create the message
177
- // const params = {
178
- // RawMessage: {
179
- // Data: container.email.raw,
180
- // },
181
- // }
182
- //
183
- // // -> Send the email out
184
- // ses.sendRawEmail(params, (error: any, data: any) => {
185
- // // 1. Check if there was an error
186
- // if (error)
187
- // return reject(error)
188
- //
189
- // // -> Move to the next chain
190
- // return resolve(container)
191
- // })
192
- // })
193
- // }
194
- //
195
- // // We now save the RAW email to S3 in a temporary folder. We do this because
196
- // // we don't want to create a PUT action in the Sent folder. The reason is
197
- // // that if we were to put the object directly to the destination, it would
198
- // // create a PUT action which would trigger the Convert Lambda. And this is
199
- // // fine. But then then Convert Lambda would save the object with a PUT action
200
- // // which would trigger the Convert Lambda once more, and until infinity.
201
- // // To prevent this loop, we make a temporary PUT event with no triggers,
202
- // // and then we copy the object to the final destination, which triggers
203
- // // the Convert action, and once the convert action makes a PUT nothing else
204
- // // happens.
205
- // function save_raw_email(container: any) {
206
- // return new Promise((resolve, reject) => {
207
- // console.info('save_raw_email')
208
- //
209
- // // 1. Set the query.
210
- // const params = {
211
- // Bucket: container.bucket,
212
- // Key: `tmp/email_out/raw/${container.uuid}`,
213
- // Body: container.email.raw,
214
- // }
215
- //
216
- // // -> Execute the query.
217
- // s3.putObject(params, (error: any, data: any) => {
218
- // // 1. Check for internal errors.
219
- // if (error)
220
- // return reject(error)
221
- //
222
- // // -> Move to the next chain.
223
- // return resolve(container)
224
- // })
225
- // })
226
- // }
227
- //
228
- // // Now that we have our RAW email saved we do a copy event so it will trigger the Conversion Lambda
229
- // function copy_raw_email(container: any) {
230
- // return new Promise((resolve, reject) => {
231
- // console.info('copy_raw_email')
232
- //
233
- // // 1. Set the query.
234
- // const params = {
235
- // Bucket: container.bucket,
236
- // CopySource: `${container.bucket}/tmp/email_out/raw/${container.uuid}`,
237
- // Key: container.path,
238
- // }
239
- //
240
- // // -> Execute the query.
241
- // s3.copyObject(params, (error: any, data: any) => {
242
- // // 1. Check for internal errors.
243
- // if (error)
244
- // return reject(error)
245
- //
246
- // // -> Move to the next chain.
247
- // return resolve(container)
248
- // })
249
- // })
250
- // }
251
- //
252
- // // And before we finish we clean up the environment by deleting the JSON email,
253
- // function delete_json_email(container: any) {
254
- // return new Promise((resolve, reject) => {
255
- // console.info('delete_json_email')
256
- //
257
- // // 1. Set the query.
258
- // const params = {
259
- // Bucket: container.bucket,
260
- // Key: container.key,
261
- // }
262
- //
263
- // // -> Execute the query.
264
- // s3.deleteObject(params, (error: any, data: any) => {
265
- // // 1. Check for internal errors.
266
- // if (error)
267
- // return reject(error)
268
- //
269
- // // -> Move to the next chain.
270
- // return resolve(container)
271
- // })
272
- // })
273
- // }
274
- //
275
- // // And the temporary RAW email.
276
- // function delete_raw_email(container: any) {
277
- // return new Promise((resolve, reject) => {
278
- // console.info('delete_raw_email')
279
- //
280
- // // 1. Set the query.
281
- // const params = {
282
- // Bucket: container.bucket,
283
- // Key: `tmp/email_out/raw/${container.uuid}`,
284
- // }
285
- //
286
- // // -> Execute the query.
287
- // s3.deleteObject(params, (error: any, data: any) => {
288
- // // 1. Check for internal errors.
289
- // if (error)
290
- // return reject(error)
291
- //
292
- // // -> Move to the next chain.
293
- // return resolve(container)
294
- // })
295
- // })
296
- // }
package/src/template.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { I18n } from 'vue-email'
2
- import process from 'node:process'
3
- import { resourcesPath } from '@stacksjs/path'
4
- import { config } from '@vue-email/compiler'
5
-
6
- export interface RenderOptions {
7
- props?: Record<string, unknown>
8
- i18n?: I18n
9
- }
10
-
11
- export async function template(path: string, options?: RenderOptions): Promise<string> {
12
- const email = config(resourcesPath('emails'), {
13
- verbose: !!process.env.DEBUG,
14
- // options: {
15
- // baseUrl: 'https://APP_URL/',
16
- // },
17
- })
18
-
19
- return await email.render(path, options)
20
- }
package/src/types.ts DELETED
@@ -1,39 +0,0 @@
1
- export interface Message {
2
- name: string
3
- subject: string
4
- to: string
5
- from?: {
6
- name: string
7
- address: string
8
- }
9
- template: string
10
- handle?: () => Promise<{ message: string }> // optional because it may be a simple template
11
- onError?: (error: Error) => Promise<{ message: string }>
12
- onSuccess?: () => void
13
- }
14
-
15
- export interface SendEmailParams {
16
- Source: string
17
- Destination: {
18
- ToAddresses: string[]
19
- }
20
- Message: {
21
- Body: {
22
- Html: {
23
- Charset: 'UTF-8'
24
- Data: string
25
- }
26
- }
27
- Subject: {
28
- Charset: 'UTF-8'
29
- Data: string
30
- }
31
- }
32
- }
33
-
34
- export interface EmailParams {
35
- to: string
36
- from: string
37
- subject: string
38
- html: string
39
- }
@@ -1,5 +0,0 @@
1
- import { notification } from '@stacksjs/config'
2
-
3
- export const email: typeof notification.email = notification.email
4
-
5
- export default email