@live-change/email-service 0.8.12 → 0.8.14
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/package.json +6 -6
- package/render.js +1 -1
- package/send.js +32 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/email-service",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,20 +8,20 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/live-change/live-change-
|
|
11
|
+
"url": "git+https://github.com/live-change/live-change-stack.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/live-change/live-change-
|
|
15
|
+
"url": "https://github.com/live-change/live-change-stack/issues"
|
|
16
16
|
},
|
|
17
|
-
"homepage": "https://github.com/live-change/live-change-
|
|
17
|
+
"homepage": "https://github.com/live-change/live-change-stack",
|
|
18
18
|
"author": {
|
|
19
19
|
"email": "michal@laszczewski.pl",
|
|
20
20
|
"name": "Michał Łaszczewski",
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/framework": "^0.8.
|
|
24
|
+
"@live-change/framework": "^0.8.14",
|
|
25
25
|
"got": "^11.8.3",
|
|
26
26
|
"html-to-text": "8.1.0",
|
|
27
27
|
"inline-css": "4.0.2",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"juice": "9.1.0",
|
|
30
30
|
"nodemailer": "^6.7.2"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "d81b573fb8891746ae1c67f4f68558123c9f85f7",
|
|
33
33
|
"type": "module"
|
|
34
34
|
}
|
package/render.js
CHANGED
|
@@ -31,7 +31,7 @@ definition.view({
|
|
|
31
31
|
|
|
32
32
|
definition.authenticator({
|
|
33
33
|
async prepareCredentials(credentials) {
|
|
34
|
-
console.log("EMAIL AUTHENTICATOR", credentials, authenticationKey.getValue())
|
|
34
|
+
//console.log("EMAIL AUTHENTICATOR", credentials, authenticationKey.getValue())
|
|
35
35
|
if(credentials.sessionKey === authenticationKey.getValue()) {
|
|
36
36
|
credentials.roles.push('admin')
|
|
37
37
|
credentials.internal = true
|
package/send.js
CHANGED
|
@@ -27,8 +27,8 @@ const smtp = nodemailer.createTransport(config.transport || {
|
|
|
27
27
|
const SentEmail = definition.model({
|
|
28
28
|
name: "SentEmail",
|
|
29
29
|
properties: {
|
|
30
|
-
|
|
31
|
-
type: Object
|
|
30
|
+
content: {
|
|
31
|
+
type: Object,
|
|
32
32
|
},
|
|
33
33
|
error: {
|
|
34
34
|
type: Object
|
|
@@ -42,7 +42,7 @@ const SentEmail = definition.model({
|
|
|
42
42
|
definition.trigger({
|
|
43
43
|
name: "sendEmailMessage",
|
|
44
44
|
properties: {
|
|
45
|
-
|
|
45
|
+
message: {
|
|
46
46
|
type: String
|
|
47
47
|
},
|
|
48
48
|
email: {
|
|
@@ -52,19 +52,22 @@ definition.trigger({
|
|
|
52
52
|
type: Object
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
-
async execute({
|
|
56
|
-
if(render)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
async execute({ message, content, render }, context, emit) {
|
|
56
|
+
if(render) content = await renderEmail(render)
|
|
57
|
+
if(!message) message = app.generateUid()
|
|
58
|
+
if(!content) throw new Error('email must be defined')
|
|
59
|
+
|
|
60
|
+
const { to, text } = content
|
|
61
|
+
if(!to) throw new Error('to must be defined')
|
|
62
|
+
if(!text) throw new Error('text must be defined')
|
|
60
63
|
|
|
61
|
-
if(
|
|
62
|
-
console.log("TEST EMAIL TO",
|
|
64
|
+
if(to.match(/@test\.com>?$/)) {
|
|
65
|
+
console.log("TEST EMAIL TO", content.to)
|
|
63
66
|
emit({
|
|
64
67
|
type: 'sent',
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
message,
|
|
69
|
+
content,
|
|
70
|
+
result: {
|
|
68
71
|
test: true
|
|
69
72
|
}
|
|
70
73
|
})
|
|
@@ -72,13 +75,13 @@ definition.trigger({
|
|
|
72
75
|
}
|
|
73
76
|
const doSendEmail = async () => { // async it can be very slow :/
|
|
74
77
|
try {
|
|
75
|
-
console.log("SEND EMAIL",
|
|
76
|
-
const info = await smtp.sendMail(
|
|
78
|
+
console.log("SEND EMAIL", content);
|
|
79
|
+
const info = await smtp.sendMail(content)
|
|
77
80
|
emit({
|
|
78
81
|
type: 'sent',
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
message,
|
|
83
|
+
content,
|
|
84
|
+
result: {
|
|
82
85
|
messageId: info.messageId,
|
|
83
86
|
response: info.response
|
|
84
87
|
}
|
|
@@ -88,8 +91,8 @@ definition.trigger({
|
|
|
88
91
|
console.error("EMAIL ERROR", error)
|
|
89
92
|
emit({
|
|
90
93
|
type: 'error',
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
message,
|
|
95
|
+
content,
|
|
93
96
|
error: error
|
|
94
97
|
})
|
|
95
98
|
}
|
|
@@ -101,36 +104,35 @@ definition.trigger({
|
|
|
101
104
|
definition.event({
|
|
102
105
|
name: "sent",
|
|
103
106
|
properties: {
|
|
104
|
-
|
|
107
|
+
message: {
|
|
105
108
|
type: String
|
|
106
109
|
},
|
|
107
|
-
|
|
110
|
+
content: {
|
|
108
111
|
type: Object
|
|
109
112
|
},
|
|
110
|
-
|
|
113
|
+
result: {
|
|
111
114
|
type: Object
|
|
112
115
|
}
|
|
113
116
|
},
|
|
114
|
-
async execute(
|
|
115
|
-
await SentEmail.create({ id:
|
|
117
|
+
async execute({ message, content, result }) {
|
|
118
|
+
await SentEmail.create({ id: message, content, result })
|
|
116
119
|
}
|
|
117
120
|
})
|
|
118
121
|
|
|
119
|
-
|
|
120
122
|
definition.event({
|
|
121
123
|
name: "error",
|
|
122
124
|
properties: {
|
|
123
|
-
|
|
125
|
+
message: {
|
|
124
126
|
type: String
|
|
125
127
|
},
|
|
126
|
-
|
|
128
|
+
content: {
|
|
127
129
|
type: Object
|
|
128
130
|
},
|
|
129
131
|
error: {
|
|
130
132
|
type: Object
|
|
131
133
|
}
|
|
132
134
|
},
|
|
133
|
-
async execute(
|
|
134
|
-
await SentEmail.create({ id:
|
|
135
|
+
async execute({ message, content, error }) {
|
|
136
|
+
await SentEmail.create({ id: message, content, error })
|
|
135
137
|
}
|
|
136
138
|
})
|