@live-change/email-service 0.8.9 → 0.8.10
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 +3 -3
- package/render.js +32 -3
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.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/framework": "^0.8.
|
|
24
|
+
"@live-change/framework": "^0.8.10",
|
|
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": "b6d6d60903abd25c8da4a55f653aafafb6cf04f7",
|
|
33
33
|
"type": "module"
|
|
34
34
|
}
|
package/render.js
CHANGED
|
@@ -1,16 +1,45 @@
|
|
|
1
1
|
import got from 'got'
|
|
2
|
-
import inlineCss from 'inline-css'
|
|
3
2
|
import juice from 'juice'
|
|
4
3
|
import { JSDOM } from 'jsdom'
|
|
5
4
|
import { convert as htmlToText } from 'html-to-text'
|
|
6
5
|
import path from 'path'
|
|
7
6
|
import { URL } from 'url'
|
|
8
7
|
|
|
8
|
+
import crypto from 'crypto'
|
|
9
|
+
import { ObservableValue } from '@live-change/dao'
|
|
10
|
+
|
|
9
11
|
import definition from './definition.js'
|
|
10
12
|
const config = definition.config
|
|
11
13
|
|
|
12
14
|
const publicDir = config.publicDir || 'front/public/'
|
|
13
15
|
|
|
16
|
+
const authenticationKey = new ObservableValue(crypto.randomBytes(24).toString('hex'))
|
|
17
|
+
definition.view({
|
|
18
|
+
internal: true,
|
|
19
|
+
global: true,
|
|
20
|
+
remote: true,
|
|
21
|
+
name: 'emailRendererAuthenticationKey',
|
|
22
|
+
properties: { },
|
|
23
|
+
returns: { type: String },
|
|
24
|
+
async get() {
|
|
25
|
+
return authenticationKey.getValue()
|
|
26
|
+
},
|
|
27
|
+
observable() {
|
|
28
|
+
return authenticationKey
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
definition.authenticator({
|
|
33
|
+
async prepareCredentials(credentials) {
|
|
34
|
+
console.log("EMAIL AUTHENTICATOR", credentials, authenticationKey.getValue())
|
|
35
|
+
if(credentials.sessionKey === authenticationKey.getValue()) {
|
|
36
|
+
credentials.roles.push('admin')
|
|
37
|
+
credentials.internal = true
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
|
|
14
43
|
function processElement(element, images) {
|
|
15
44
|
for(let i = 0; i < element.attributes.length; i++) {
|
|
16
45
|
const attribute = element.attributes[i]
|
|
@@ -50,11 +79,11 @@ async function renderEmail(data) {
|
|
|
50
79
|
|
|
51
80
|
const encodedData = encodeURIComponent(JSON.stringify(data))
|
|
52
81
|
const url = `${baseUrl}/_email/${data.action}/${data.contact}/${encodedData}`
|
|
82
|
+
+`?sessionKey=${await authenticationKey.getValue()}`
|
|
53
83
|
console.log("RENDER EMAIL", data, "URL", url)
|
|
54
84
|
const response = await got(url)
|
|
55
85
|
let body = response.body
|
|
56
86
|
console.log("BASE URL", baseUrl)
|
|
57
|
-
//body = await inlineCss(body, { url })
|
|
58
87
|
const juiceOptions = {
|
|
59
88
|
webResources: {
|
|
60
89
|
scripts: false,
|
|
@@ -70,7 +99,7 @@ async function renderEmail(data) {
|
|
|
70
99
|
else resolve(html)
|
|
71
100
|
})
|
|
72
101
|
})
|
|
73
|
-
console.log("HTML", body)
|
|
102
|
+
//console.log("HTML", body)
|
|
74
103
|
const dom = new JSDOM(body)
|
|
75
104
|
const headers = JSON.parse(dom.window.document.querySelector('[data-headers]').textContent)
|
|
76
105
|
const messageElements = dom.window.document.querySelectorAll("[data-html],[data-text]")
|