webdaemon 11.5.0 → 11.5.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/README.md +28 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +7 -0
- package/package.json +15 -4
- package/index.js +0 -17
- package/js/Alert.js +0 -33
- package/js/BrowserApp.js +0 -334
- package/js/Digest.js +0 -45
- package/js/KeyPair.js +0 -38
- package/js/ParentHelper.js +0 -302
- package/js/QrCode.js +0 -37
- package/js/README.html +0 -13
- package/js/README.md +0 -4
- package/js/README.pdf +0 -0
- package/js/Storage.js +0 -155
- package/js/Token.js +0 -529
- package/package.json.template +0 -13
- package/ts/Assertions.ts +0 -41
- package/ts/Lifecycle.ts +0 -307
- package/ts/README.html +0 -13
- package/ts/README.md +0 -4
- package/ts/README.pdf +0 -0
- package/ts/Requests.ts +0 -131
- package/ts/Responses.ts +0 -132
package/js/QrCode.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility class to generate a QR code img element which is placed
|
|
3
|
-
* under a parent element.
|
|
4
|
-
*/
|
|
5
|
-
const BASE_URL = 'https://qrcode.tec-it.com/API/QRCode'
|
|
6
|
-
export const IMG_CLASS = 'qrcode'
|
|
7
|
-
|
|
8
|
-
export class QrCode {
|
|
9
|
-
#img
|
|
10
|
-
#content
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Constructor takes img element and
|
|
14
|
-
* the string to show in the QR code.
|
|
15
|
-
* @param {HTMLImageElement} img the image element to use.
|
|
16
|
-
* @param {string} content the content of the qr code.
|
|
17
|
-
*/
|
|
18
|
-
constructor(img, content) {
|
|
19
|
-
this.#img = img
|
|
20
|
-
this.#content = content
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Returns a promise that is resolved when the image loads
|
|
25
|
-
* successfully, or rejected if the image load fails.
|
|
26
|
-
*/
|
|
27
|
-
generate() {
|
|
28
|
-
const url = new URL(BASE_URL)
|
|
29
|
-
url.searchParams.append('data', this.#content)
|
|
30
|
-
this.#img.classList.add(IMG_CLASS)
|
|
31
|
-
this.#img.src = url.toString()
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
this.#img.onload = resolve
|
|
34
|
-
this.#img.onerror = reject
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
}
|
package/js/README.html
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<title>Readme</title>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<h1 id="javascript-library">Javascript library</h1>
|
|
9
|
-
<p>This directory holds Javascript source files designed to be used in
|
|
10
|
-
either the browser or a daemon runner, served from a public site such as
|
|
11
|
-
https://webdaemon.online.</p>
|
|
12
|
-
</body>
|
|
13
|
-
</html>
|
package/js/README.md
DELETED
package/js/README.pdf
DELETED
|
Binary file
|
package/js/Storage.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Storage keys are 1 or more slash-separated components
|
|
3
|
-
* using the characters a-z, A-Z, 0-9, hyphen and period.
|
|
4
|
-
*
|
|
5
|
-
* Examples:
|
|
6
|
-
* - acmeSetting
|
|
7
|
-
* - acme.com/applicant/22fc01-b0d3084870b-fcae49ac2-892668
|
|
8
|
-
* - address/line1
|
|
9
|
-
* - url/acme.com
|
|
10
|
-
*
|
|
11
|
-
* The key needs to work as part of a REST/HTTP pathname.
|
|
12
|
-
*/
|
|
13
|
-
const KEY_PATTERN = /^[\w\-.]+(?:\/[\w\-.]+)*$/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* As above, but % and _ are both allowed as a wildcards.
|
|
17
|
-
*/
|
|
18
|
-
const KEYLIKE_PATTERN = /^[\w\-.%_]+(?:\/[\w\-.%_]+)*$/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @typedef {Object} Ok
|
|
22
|
-
* @property {Plain} ok
|
|
23
|
-
*
|
|
24
|
-
* @typedef {Object} Error
|
|
25
|
-
* @property {string} error
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Throws an exception if the key being used is not
|
|
30
|
-
* in a valid format.
|
|
31
|
-
*/
|
|
32
|
-
function assertValid(key) {
|
|
33
|
-
if (key.match(KEY_PATTERN) == null) {
|
|
34
|
-
throw `DaemonStorage: Invalid key: '${key}`
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Throws an exception if the key like pattern being used
|
|
40
|
-
* is not in a valid format.
|
|
41
|
-
*/
|
|
42
|
-
function assertValidLike(keylike) {
|
|
43
|
-
if (keylike.match(KEYLIKE_PATTERN) == null) {
|
|
44
|
-
throw `DaemonStorage: Invalid like key: ${keylike}`
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Returns the value as a JSON string
|
|
50
|
-
*
|
|
51
|
-
* @return {string} JSON string.
|
|
52
|
-
* @throws {string} exception if the value is not JSON.
|
|
53
|
-
*/
|
|
54
|
-
function serialise(value) {
|
|
55
|
-
try {
|
|
56
|
-
return JSON.stringify(value)
|
|
57
|
-
}
|
|
58
|
-
catch (_e) {
|
|
59
|
-
throw `DaemonStorage: Invalid value`
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Sets an item in daemon storage.
|
|
65
|
-
*
|
|
66
|
-
* The value must be an object or primitive
|
|
67
|
-
* which is serialised before saving.
|
|
68
|
-
*
|
|
69
|
-
* @param {Token} token to use.
|
|
70
|
-
* @param {string} key the item key.
|
|
71
|
-
* @param {any} value the serialisable value for the item.
|
|
72
|
-
* @return {Promise<Ok | Error>} ok or error object.
|
|
73
|
-
*/
|
|
74
|
-
export async function setItem(token, key, value) {
|
|
75
|
-
assertValid(key)
|
|
76
|
-
const body = serialise(value)
|
|
77
|
-
const url = `${token.getAud()}/storage/${key}`
|
|
78
|
-
const response = await fetch(url, {
|
|
79
|
-
method: 'PUT',
|
|
80
|
-
headers: {
|
|
81
|
-
'X-Tabserver-Token': token.asSignedBase64(),
|
|
82
|
-
'Content-Type': 'application/json'
|
|
83
|
-
},
|
|
84
|
-
body
|
|
85
|
-
})
|
|
86
|
-
return response.json()
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Gets an item from daemon storage.
|
|
91
|
-
*
|
|
92
|
-
* Returns an 'ok' object with the value if present, otherwise
|
|
93
|
-
* returns an 'error' object.
|
|
94
|
-
*
|
|
95
|
-
* @param {Token} token to use.
|
|
96
|
-
* @param {string} key the item key to retrieve.
|
|
97
|
-
* @return {Promise<Ok | Error>} ok object with value, or error.
|
|
98
|
-
*/
|
|
99
|
-
export async function getItem(token, key) {
|
|
100
|
-
assertValid(key)
|
|
101
|
-
const url = `${token.getAud()}/storage/${key}`
|
|
102
|
-
const response = await fetch(url, {
|
|
103
|
-
method: 'GET',
|
|
104
|
-
headers: {
|
|
105
|
-
'X-Tabserver-Token': token.asSignedBase64()
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
return response.json()
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Gets zero or more items from daemon storage, whose
|
|
113
|
-
* keys match the keyLike pattern. This is normally
|
|
114
|
-
* something like 'my/prefix/%' which gets all values
|
|
115
|
-
* with that prefix.
|
|
116
|
-
*
|
|
117
|
-
* You can use both '%' and '_' as wildcards for string
|
|
118
|
-
* of any length and single character respectively.
|
|
119
|
-
*
|
|
120
|
-
* @param {Token} token to use.
|
|
121
|
-
* @param {string} the item keylike pattern to match.
|
|
122
|
-
* @return {Promise<Ok>} ok object with list, or error.
|
|
123
|
-
*/
|
|
124
|
-
export async function getItemsLike(token, keylike) {
|
|
125
|
-
assertValidLike(keylike)
|
|
126
|
-
const url = new URL(`${token.getAud()}/storage`)
|
|
127
|
-
url.searchParams.append('like', keylike)
|
|
128
|
-
console.log(url)
|
|
129
|
-
const response = await fetch(url, {
|
|
130
|
-
method: 'GET',
|
|
131
|
-
headers: {
|
|
132
|
-
'X-Tabserver-Token': token.asSignedBase64()
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
return await response.json()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Removes an item from daemon storage.
|
|
140
|
-
*
|
|
141
|
-
* @param {Token} token to use.
|
|
142
|
-
* @param {string} key the item key to remove.
|
|
143
|
-
* @return {Promise<Ok | Error>} ok or error object.
|
|
144
|
-
*/
|
|
145
|
-
export async function removeItem(token, key) {
|
|
146
|
-
assertValid(key)
|
|
147
|
-
const url =`${token.getAud()}/storage/${key}`
|
|
148
|
-
const response = await fetch(url, {
|
|
149
|
-
method: 'DELETE',
|
|
150
|
-
headers: {
|
|
151
|
-
'X-Tabserver-Token': token.asSignedBase64()
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
return response.json()
|
|
155
|
-
}
|