@live-change/phone-service 0.9.182 → 0.9.183

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 (2) hide show
  1. package/package.json +4 -4
  2. package/render.js +32 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/phone-service",
3
- "version": "0.9.182",
3
+ "version": "0.9.183",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,12 +22,12 @@
22
22
  },
23
23
  "type": "module",
24
24
  "dependencies": {
25
- "@live-change/framework": "^0.9.182",
26
- "@live-change/relations-plugin": "^0.9.182",
25
+ "@live-change/framework": "^0.9.183",
26
+ "@live-change/relations-plugin": "^0.9.183",
27
27
  "got": "^11.8.6",
28
28
  "html-to-text": "8.1.0",
29
29
  "jsdom": "^24.1.0",
30
30
  "smsapi": "2.0.9"
31
31
  },
32
- "gitHead": "e12068c10b76a5661032a3df85d7168f228192af"
32
+ "gitHead": "a61bc04560d627571a9c511b29b22357800e4927"
33
33
  }
package/render.js CHANGED
@@ -5,6 +5,37 @@ import { convert as htmlToText } from 'html-to-text'
5
5
  import definition from './definition.js'
6
6
  const config = definition.config
7
7
 
8
+ import crypto from 'crypto'
9
+ import { ObservableValue } from '@live-change/dao'
10
+
11
+ const authenticationKey = new ObservableValue(
12
+ config.rendererAuthenticationKey ?? crypto.randomBytes(24).toString('hex')
13
+ )
14
+ definition.view({
15
+ internal: true,
16
+ global: true,
17
+ remote: true,
18
+ name: 'smsRendererAuthenticationKey',
19
+ properties: { },
20
+ returns: { type: String },
21
+ async get() {
22
+ return authenticationKey.getValue()
23
+ },
24
+ observable() {
25
+ return authenticationKey
26
+ }
27
+ })
28
+
29
+ definition.authenticator({
30
+ async prepareCredentials(credentials) {
31
+ //console.log("SMS AUTHENTICATOR", credentials, authenticationKey.getValue())
32
+ if(credentials.sessionKey === authenticationKey.getValue()) {
33
+ credentials.roles.push('admin')
34
+ credentials.internal = true
35
+ }
36
+ }
37
+ })
38
+
8
39
  const getValue = (configValue, envValue, defaultValue) => configValue ?? envValue ?? defaultValue
9
40
 
10
41
  async function renderSms(data) {
@@ -17,6 +48,7 @@ async function renderSms(data) {
17
48
 
18
49
  const encodedData = encodeURIComponent(JSON.stringify(data))
19
50
  const url = `${baseUrl}/_sms/${data.action}/${data.contact}/${encodedData}`
51
+ +`?sessionKey=${await authenticationKey.getValue()}`
20
52
  console.log("RENDER SMS", data, "URL", url)
21
53
  const response = await got(url)
22
54
  let body = response.body