@things-factory/integration-notification 7.0.1-rc.0 → 7.0.1-rc.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-notification",
3
- "version": "7.0.1-rc.0",
3
+ "version": "7.0.1-rc.10",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -23,8 +23,9 @@
23
23
  "clean": "npm run clean:server"
24
24
  },
25
25
  "dependencies": {
26
- "@things-factory/integration-base": "^7.0.1-rc.0",
27
- "@things-factory/notification": "^7.0.1-rc.0"
26
+ "@things-factory/integration-base": "^7.0.1-rc.10",
27
+ "@things-factory/notification": "^7.0.1-rc.10",
28
+ "ses": "^1.5.0"
28
29
  },
29
- "gitHead": "45476b164b69aef2c211d9a5257897f42d8e2f5f"
30
+ "gitHead": "259524f7aeb4368a5a4792aa31e4d11b525dbb28"
30
31
  }
@@ -1,6 +1,5 @@
1
1
  import { ILike } from 'typeorm'
2
- import { VM } from 'vm2'
3
-
2
+ import 'ses'
4
3
  import { User } from '@things-factory/auth-base'
5
4
  import { TaskRegistry } from '@things-factory/integration-base'
6
5
  import { notify } from '@things-factory/notification'
@@ -12,7 +11,9 @@ async function Notification(step, { logger, domain, user, data, variables }) {
12
11
  } = step
13
12
 
14
13
  if (!receivers || !title || !body) {
15
- throw Error(`receivers, title and body should be defined: receivers - '${receivers}', title - '${title}', body - '${body}'`)
14
+ throw Error(
15
+ `receivers, title and body should be defined: receivers - '${receivers}', title - '${title}', body - '${body}'`
16
+ )
16
17
  }
17
18
 
18
19
  const repository = getRepository(User)
@@ -30,16 +31,22 @@ async function Notification(step, { logger, domain, user, data, variables }) {
30
31
  )
31
32
  ).filter(receiver => !!receiver)
32
33
 
33
- const vm = new VM({
34
- sandbox: {
35
- domain,
36
- user,
37
- data,
38
- variables
39
- }
34
+ const compartment = new Compartment({
35
+ domain,
36
+ user,
37
+ data,
38
+ variables,
39
+ console
40
40
  })
41
41
 
42
- body = vm.run('`' + body + '`')
42
+ let evalBody
43
+ try {
44
+ evalBody = compartment.evaluate('`' + body + '`')
45
+ } catch (err) {
46
+ throw new Error(`Failed to evaluate body: ${err.message}`)
47
+ }
48
+
49
+ body = evalBody
43
50
  const timestamp = String(Date.now())
44
51
 
45
52
  if (push) {