@live-change/email-service 0.8.9 → 0.8.11

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.
Files changed (3) hide show
  1. package/index.js +1 -4
  2. package/package.json +3 -3
  3. package/render.js +30 -3
package/index.js CHANGED
@@ -7,9 +7,6 @@ import './send.js'
7
7
  import './auth.js'
8
8
 
9
9
  import validator from './emailValidator.js'
10
-
11
- definition.processor(function(service, app) {
12
- service.validators.email = validator
13
- })
10
+ definition.validator('email', validator)
14
11
 
15
12
  export default definition
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/email-service",
3
- "version": "0.8.9",
3
+ "version": "0.8.11",
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.9",
24
+ "@live-change/framework": "^0.8.11",
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": "362dd55bd2773195e4cefd84080c10bd9fbaaf45",
32
+ "gitHead": "c69f8c0c5b1f9c8b62d74bd44e97dccbdc789c5a",
33
33
  "type": "module"
34
34
  }
package/render.js CHANGED
@@ -1,16 +1,43 @@
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
+ })
14
41
  function processElement(element, images) {
15
42
  for(let i = 0; i < element.attributes.length; i++) {
16
43
  const attribute = element.attributes[i]
@@ -50,11 +77,11 @@ async function renderEmail(data) {
50
77
 
51
78
  const encodedData = encodeURIComponent(JSON.stringify(data))
52
79
  const url = `${baseUrl}/_email/${data.action}/${data.contact}/${encodedData}`
80
+ +`?sessionKey=${await authenticationKey.getValue()}`
53
81
  console.log("RENDER EMAIL", data, "URL", url)
54
82
  const response = await got(url)
55
83
  let body = response.body
56
84
  console.log("BASE URL", baseUrl)
57
- //body = await inlineCss(body, { url })
58
85
  const juiceOptions = {
59
86
  webResources: {
60
87
  scripts: false,
@@ -70,7 +97,7 @@ async function renderEmail(data) {
70
97
  else resolve(html)
71
98
  })
72
99
  })
73
- console.log("HTML", body)
100
+ //console.log("HTML", body)
74
101
  const dom = new JSDOM(body)
75
102
  const headers = JSON.parse(dom.window.document.querySelector('[data-headers]').textContent)
76
103
  const messageElements = dom.window.document.querySelectorAll("[data-html],[data-text]")