@live-change/email-service 0.1.0 → 0.2.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/auth.js +94 -3
- package/index.js +0 -35
- package/package.json +9 -8
- package/render.js +3 -2
package/auth.js
CHANGED
|
@@ -14,11 +14,49 @@ const Email = definition.model({
|
|
|
14
14
|
}
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
+
definition.event({
|
|
18
|
+
name: 'emailConnected',
|
|
19
|
+
properties: {
|
|
20
|
+
email: {
|
|
21
|
+
type: String,
|
|
22
|
+
validation: ['nonEmpty', 'email']
|
|
23
|
+
},
|
|
24
|
+
user: {
|
|
25
|
+
type: User,
|
|
26
|
+
validation: ['nonEmpty']
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
async execute({ user, email }) {
|
|
30
|
+
await Email.create({
|
|
31
|
+
id: email,
|
|
32
|
+
user, email
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
definition.event({
|
|
38
|
+
name: "emailDisconnected",
|
|
39
|
+
properties: {
|
|
40
|
+
email: {
|
|
41
|
+
type: String,
|
|
42
|
+
validation: ['nonEmpty', 'email']
|
|
43
|
+
},
|
|
44
|
+
user: {
|
|
45
|
+
type: User,
|
|
46
|
+
validation: ['nonEmpty']
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
async execute({ user, email }) {
|
|
50
|
+
await Email.delete(email)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
17
54
|
definition.trigger({
|
|
18
55
|
name: "checkNewEmail",
|
|
19
56
|
properties: {
|
|
20
57
|
email: {
|
|
21
|
-
type: String
|
|
58
|
+
type: String,
|
|
59
|
+
validation: ['nonEmpty', 'email']
|
|
22
60
|
}
|
|
23
61
|
},
|
|
24
62
|
async execute({ email }, context, emit) {
|
|
@@ -29,13 +67,66 @@ definition.trigger({
|
|
|
29
67
|
})
|
|
30
68
|
|
|
31
69
|
definition.trigger({
|
|
32
|
-
name: "
|
|
70
|
+
name: "connectEmail",
|
|
71
|
+
properties: {
|
|
72
|
+
email: {
|
|
73
|
+
type: String,
|
|
74
|
+
validation: ['nonEmpty', 'email']
|
|
75
|
+
},
|
|
76
|
+
user: {
|
|
77
|
+
type: User,
|
|
78
|
+
validation: ['nonEmpty']
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
async execute({ user, email }, { client, service }, emit) {
|
|
82
|
+
const emailData = await Email.get(email)
|
|
83
|
+
if(emailData) throw 'taken'
|
|
84
|
+
emit({
|
|
85
|
+
type: 'emailConnected',
|
|
86
|
+
user, email
|
|
87
|
+
})
|
|
88
|
+
return true
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
definition.trigger({
|
|
93
|
+
name: "disconnectEmail",
|
|
94
|
+
properties: {
|
|
95
|
+
email: {
|
|
96
|
+
type: String,
|
|
97
|
+
validation: ['nonEmpty', 'email']
|
|
98
|
+
},
|
|
99
|
+
user: {
|
|
100
|
+
type: User,
|
|
101
|
+
validation: ['nonEmpty']
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
async execute({ user, email }, { client, service }, emit) {
|
|
105
|
+
const emailData = await Email.get(email)
|
|
106
|
+
if(!emailData) throw 'notFound'
|
|
107
|
+
emit({
|
|
108
|
+
type: 'emailDisconnected',
|
|
109
|
+
user, email
|
|
110
|
+
})
|
|
111
|
+
return true
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
definition.trigger({
|
|
116
|
+
name: "signInEmail",
|
|
33
117
|
properties: {
|
|
34
118
|
email: {
|
|
35
119
|
type: String
|
|
36
120
|
}
|
|
37
121
|
},
|
|
38
|
-
async execute(
|
|
122
|
+
async execute({ email }, { client, service }, emit) {
|
|
123
|
+
const emailData = await Email.get(email)
|
|
124
|
+
if(!emailData) throw 'emailNotFound'
|
|
125
|
+
const { user } = emailData
|
|
126
|
+
return service.trigger({
|
|
127
|
+
type: 'signIn',
|
|
128
|
+
user, session
|
|
129
|
+
})
|
|
39
130
|
}
|
|
40
131
|
})
|
|
41
132
|
|
package/index.js
CHANGED
|
@@ -9,39 +9,4 @@ definition.processor(function(service, app) {
|
|
|
9
9
|
service.validators.email = require('./emailValidator.js')
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
definition.action({
|
|
13
|
-
name: "sendContactFormMail",
|
|
14
|
-
properties: {
|
|
15
|
-
from: { type: String, validation: ['nonEmpty'] },
|
|
16
|
-
name: { type: String, validation: ['nonEmpty']},
|
|
17
|
-
subject: { type: String, validation: ['nonEmpty'] },
|
|
18
|
-
text: { type: String, validation: ['nonEmpty'] },
|
|
19
|
-
html: { type: String },
|
|
20
|
-
},
|
|
21
|
-
async execute({ from, name, subject, text, html }, { client, service }, emit) {
|
|
22
|
-
if(!html) {
|
|
23
|
-
const encodedStr = text.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
|
|
24
|
-
return '&#'+i.charCodeAt(0)+';'
|
|
25
|
-
})
|
|
26
|
-
const multiline = encodedStr.replace(/\n/gi, /*'↵*/'<br>')
|
|
27
|
-
const withLinks = multiline.replace(
|
|
28
|
-
/(?![^<]*>|[^<>]*<\/)((https?:)\/\/[a-z0-9&#%=.\/?_,-]+)/gi, '<a href="$1" target="_blank">$1</a>')
|
|
29
|
-
html = withLinks
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
await service.trigger({
|
|
33
|
-
type:"sendEmailMessage",
|
|
34
|
-
email: {
|
|
35
|
-
from: `${name} <${process.env.CONTACT_FORM_FROM_EMAIL}>`,
|
|
36
|
-
to: `${ process.env.CONTACT_FORM_TARGET_NAME} <${process.env.CONTACT_FORM_TARGET_EMAIL}>`,
|
|
37
|
-
subject: subject,
|
|
38
|
-
text,
|
|
39
|
-
html,
|
|
40
|
-
replyTo: `${name} <${from}>`
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
|
|
47
12
|
module.exports = definition
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/email-service",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/live-change/
|
|
11
|
+
"url": "git+https://github.com/live-change/live-change-services.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/live-change/
|
|
15
|
+
"url": "https://github.com/live-change/live-change-services/issues"
|
|
16
16
|
},
|
|
17
|
-
"homepage": "https://github.com/live-change/
|
|
17
|
+
"homepage": "https://github.com/live-change/live-change-services",
|
|
18
18
|
"author": {
|
|
19
19
|
"email": "michal@laszczewski.pl",
|
|
20
20
|
"name": "Michał Łaszczewski",
|
|
@@ -22,10 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@live-change/framework": "^0.5.7",
|
|
25
|
-
"nodemailer": "^6.7.2",
|
|
26
25
|
"got": "^11.8.3",
|
|
27
|
-
"
|
|
26
|
+
"html-to-text": "8.1.0",
|
|
28
27
|
"inline-css": "3.0.0",
|
|
29
|
-
"
|
|
30
|
-
|
|
28
|
+
"jsdom": "^18.1.1",
|
|
29
|
+
"nodemailer": "^6.7.2"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "e7b365e7bcc4512d9922d9fbe5eb21ed1b418c63"
|
|
31
32
|
}
|
package/render.js
CHANGED
|
@@ -8,8 +8,6 @@ const { URL } = require('url')
|
|
|
8
8
|
const definition = require('./definition.js')
|
|
9
9
|
const config = definition.config
|
|
10
10
|
|
|
11
|
-
const baseUrl = `http://${config.ssrHost||process.env.SSR_HOST||'localhost'}`+
|
|
12
|
-
`:${config.ssrHost||process.env.SSR_PORT||'8001'}`
|
|
13
11
|
const publicDir = config.publicDir || 'front/public/'
|
|
14
12
|
|
|
15
13
|
function processElement(element, images) {
|
|
@@ -46,6 +44,9 @@ function processElement(element, images) {
|
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
async function renderEmail(data) {
|
|
47
|
+
const baseUrl = `http://${config.ssrHost||process.env.SSR_HOST||'localhost'}`+
|
|
48
|
+
`:${config.ssrPort||process.env.SSR_PORT||'8001'}`
|
|
49
|
+
|
|
49
50
|
const encodedData = encodeURIComponent(JSON.stringify(data))
|
|
50
51
|
const url = `${baseUrl}/_email/${data.action}/${data.contact}/${encodedData}`
|
|
51
52
|
console.log("RENDER EMAIL", data, "URL", url)
|