@docstack/client 0.0.3 → 0.0.5
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/lib/core/attribute.js +406 -0
- package/lib/core/attribute.js.map +1 -0
- package/lib/core/class.d.ts +13 -14
- package/lib/core/class.js +761 -0
- package/lib/core/class.js.map +1 -0
- package/lib/core/crypto-engine/index.js +229 -0
- package/lib/core/crypto-engine/index.js.map +1 -0
- package/lib/core/crypto-engine/utils.js +88 -0
- package/lib/core/crypto-engine/utils.js.map +1 -0
- package/lib/core/datamodel/index.js +1308 -0
- package/lib/core/datamodel/index.js.map +1 -0
- package/lib/core/domain.js +423 -0
- package/lib/core/domain.js.map +1 -0
- package/lib/core/index.js +520 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/job-engine/index.js +220 -0
- package/lib/core/job-engine/index.js.map +1 -0
- package/lib/core/policy-engine/index.js +232 -0
- package/lib/core/policy-engine/index.js.map +1 -0
- package/lib/core/query-engine/accumulators.js +258 -0
- package/lib/core/query-engine/accumulators.js.map +1 -0
- package/lib/core/query-engine/evaluator.js +179 -0
- package/lib/core/query-engine/evaluator.js.map +1 -0
- package/lib/core/query-engine/executor.js +405 -0
- package/lib/core/query-engine/executor.js.map +1 -0
- package/lib/core/query-engine/index.js +4 -0
- package/lib/core/query-engine/index.js.map +1 -0
- package/lib/core/query-engine/parser.js +515 -0
- package/lib/core/query-engine/parser.js.map +1 -0
- package/lib/core/query-engine/planner.js +330 -0
- package/lib/core/query-engine/planner.js.map +1 -0
- package/lib/core/stack.js +1817 -0
- package/lib/core/stack.js.map +1 -0
- package/lib/core/test-utils/docstack.js +222 -0
- package/lib/core/test-utils/docstack.js.map +1 -0
- package/lib/core/trigger/index.js +81 -0
- package/lib/core/trigger/index.js.map +1 -0
- package/lib/index.js +10 -4
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +10 -4
- package/lib/plugins/pouchdb.js +368 -0
- package/lib/plugins/pouchdb.js.map +1 -0
- package/lib/utils/crypto/index.js +34 -0
- package/lib/utils/crypto/index.js.map +1 -0
- package/lib/utils/index.js +58 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/logger/index.js +20 -0
- package/lib/utils/logger/index.js.map +1 -0
- package/lib/utils/logger/transport.js +28 -0
- package/lib/utils/logger/transport.js.map +1 -0
- package/lib/workers/dataModel.js +48 -0
- package/lib/workers/dataModel.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,1308 @@
|
|
|
1
|
+
import semver from "semver";
|
|
2
|
+
const syspatches = [];
|
|
3
|
+
const hashContent = async (content) => {
|
|
4
|
+
const data = new TextEncoder().encode(content);
|
|
5
|
+
const hashBuffer = await globalThis.crypto.subtle.digest('SHA-256', data);
|
|
6
|
+
return Array.from(new Uint8Array(hashBuffer)).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
7
|
+
};
|
|
8
|
+
// TODO: implement _rev auto handler:
|
|
9
|
+
// If patches include updates to existing documents,
|
|
10
|
+
// we need to ensure that the _rev field is handled correctly to avoid conflicts.
|
|
11
|
+
const sys_001 = {
|
|
12
|
+
"_id": "~sys-0.0.1",
|
|
13
|
+
"~class": "patch",
|
|
14
|
+
"version": "0.0.1",
|
|
15
|
+
"target": "system",
|
|
16
|
+
"changelog": "### Initial patch with originators: Class and Domain",
|
|
17
|
+
"docs": [
|
|
18
|
+
{
|
|
19
|
+
"_id": "class",
|
|
20
|
+
"active": true,
|
|
21
|
+
"name": "class",
|
|
22
|
+
"description": "A class document representing a data model class",
|
|
23
|
+
"~class": "~self",
|
|
24
|
+
"schema": {
|
|
25
|
+
"name": {
|
|
26
|
+
"name": "name",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"config": {
|
|
29
|
+
"primaryKey": true,
|
|
30
|
+
"mandatory": true,
|
|
31
|
+
"isArray": false,
|
|
32
|
+
"maxLength": 100
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"description": {
|
|
36
|
+
"name": "description",
|
|
37
|
+
"type": "string",
|
|
38
|
+
"config": {
|
|
39
|
+
"mandatory": false,
|
|
40
|
+
"isArray": false,
|
|
41
|
+
"maxLength": 500
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"~class": {
|
|
45
|
+
"name": "~class",
|
|
46
|
+
"type": "string",
|
|
47
|
+
"config": {
|
|
48
|
+
"mandatory": true,
|
|
49
|
+
"isArray": false,
|
|
50
|
+
"maxLength": 50,
|
|
51
|
+
"defaultValue": "class"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"schema": { "name": "schema", "type": "object", "config": { "maxLength": 1000, "isArray": false } },
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"_id": "domain",
|
|
59
|
+
"active": true,
|
|
60
|
+
"name": "domain",
|
|
61
|
+
"description": "A domain document representing a data model domain",
|
|
62
|
+
"~class": "~self",
|
|
63
|
+
"schema": {
|
|
64
|
+
"~class": { name: "~class", type: "string", config: { defaultValue: "domain" } },
|
|
65
|
+
"relation": {
|
|
66
|
+
name: "relation", type: "enum", config: {
|
|
67
|
+
isArray: false, values: [
|
|
68
|
+
{ value: "1:1" }, { value: "1:N" }, { value: "N:1" }, { value: "N:N" }
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"sourceClass": {
|
|
73
|
+
name: "sourceClass",
|
|
74
|
+
type: "foreign_key",
|
|
75
|
+
config: {
|
|
76
|
+
targetClass: "class",
|
|
77
|
+
isArray: false
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"targetClass": {
|
|
81
|
+
name: "targetClass",
|
|
82
|
+
type: "foreign_key",
|
|
83
|
+
config: {
|
|
84
|
+
targetClass: "class",
|
|
85
|
+
isArray: false
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
};
|
|
92
|
+
// const sys_002: Patch = {
|
|
93
|
+
// "_id": "~sys-0.0.2",
|
|
94
|
+
// "~class": "patch",
|
|
95
|
+
// "version": "0.0.2",
|
|
96
|
+
// "target": "system",
|
|
97
|
+
// "changelog": "### Initial patch with system classes and domains",
|
|
98
|
+
// "docs": [
|
|
99
|
+
// {
|
|
100
|
+
// "_id": "log",
|
|
101
|
+
// "active": true,
|
|
102
|
+
// "name": "log",
|
|
103
|
+
// "description": "Contains the system logs",
|
|
104
|
+
// "~class": "class",
|
|
105
|
+
// "schema": {
|
|
106
|
+
// "log": {
|
|
107
|
+
// "name": "log",
|
|
108
|
+
// "type": "object",
|
|
109
|
+
// "config": {
|
|
110
|
+
// "isArray": false
|
|
111
|
+
// }
|
|
112
|
+
// }
|
|
113
|
+
// }
|
|
114
|
+
// }
|
|
115
|
+
// ]
|
|
116
|
+
// }
|
|
117
|
+
const sys_003 = {
|
|
118
|
+
"_id": "~sys-0.0.3",
|
|
119
|
+
"~class": "patch",
|
|
120
|
+
"version": "0.0.3",
|
|
121
|
+
"target": "system",
|
|
122
|
+
"changelog": "### Schema Patch: v0.0.3\\\n#### New Classes: ~User, ~UserSession",
|
|
123
|
+
"docs": [
|
|
124
|
+
{
|
|
125
|
+
"_id": "~User",
|
|
126
|
+
"active": true,
|
|
127
|
+
"name": "User",
|
|
128
|
+
"description": "A user class for secure login",
|
|
129
|
+
"~class": "class",
|
|
130
|
+
"schema": {
|
|
131
|
+
"username": {
|
|
132
|
+
"name": "username",
|
|
133
|
+
"type": "string",
|
|
134
|
+
"config": {
|
|
135
|
+
"primaryKey": true,
|
|
136
|
+
"maxLength": 50,
|
|
137
|
+
"mandatory": true,
|
|
138
|
+
"isArray": false
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"password": {
|
|
142
|
+
"name": "password",
|
|
143
|
+
"type": "string",
|
|
144
|
+
"config": {
|
|
145
|
+
"maxLength": 50,
|
|
146
|
+
"mandatory": true,
|
|
147
|
+
"isArray": false
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"email": {
|
|
151
|
+
"name": "email",
|
|
152
|
+
"type": "string",
|
|
153
|
+
"config": {
|
|
154
|
+
"maxLength": 50,
|
|
155
|
+
"isArray": false
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
"firstName": {
|
|
159
|
+
"name": "firstName",
|
|
160
|
+
"type": "string",
|
|
161
|
+
"config": {
|
|
162
|
+
"maxLength": 50,
|
|
163
|
+
"isArray": false
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"lastName": {
|
|
167
|
+
"name": "lastName",
|
|
168
|
+
"type": "string",
|
|
169
|
+
"config": {
|
|
170
|
+
"maxLength": 50,
|
|
171
|
+
"isArray": false
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"_id": "~UserSession",
|
|
178
|
+
"name": "UserSession",
|
|
179
|
+
"active": true,
|
|
180
|
+
"description": "Tracks user sessions",
|
|
181
|
+
"~class": "class",
|
|
182
|
+
"schema": {
|
|
183
|
+
"username": {
|
|
184
|
+
"name": "username",
|
|
185
|
+
"type": "string",
|
|
186
|
+
"config": {
|
|
187
|
+
"maxLength": 50,
|
|
188
|
+
"isArray": false,
|
|
189
|
+
"primaryKey": true,
|
|
190
|
+
"mandatory": true
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
"sessionId": {
|
|
194
|
+
"name": "sessionId",
|
|
195
|
+
"type": "string",
|
|
196
|
+
"config": {
|
|
197
|
+
"maxLength": 200,
|
|
198
|
+
"primaryKey": true,
|
|
199
|
+
"isArray": false,
|
|
200
|
+
"mandatory": true
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
"sessionStart": {
|
|
204
|
+
"name": "sessionStart",
|
|
205
|
+
"type": "string",
|
|
206
|
+
"config": {
|
|
207
|
+
"maxLength": 100,
|
|
208
|
+
"isArray": false,
|
|
209
|
+
"mandatory": true
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
"sessionStatus": {
|
|
213
|
+
"name": "sessionStatus",
|
|
214
|
+
"type": "string",
|
|
215
|
+
"config": {
|
|
216
|
+
"maxLength": 100,
|
|
217
|
+
"isArray": false,
|
|
218
|
+
"mandatory": true
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
"sessionEnd": {
|
|
222
|
+
"name": "sessionEnd",
|
|
223
|
+
"type": "string",
|
|
224
|
+
"config": {
|
|
225
|
+
"maxLength": 100,
|
|
226
|
+
"isArray": false,
|
|
227
|
+
"mandatory": false
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
};
|
|
234
|
+
const classicAuthJobContent = `
|
|
235
|
+
const toHex = (buffer) => Array.from(new Uint8Array(buffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
236
|
+
|
|
237
|
+
async function deriveKeyMaterial(password, salt, iterations = 120000, length = 32) {
|
|
238
|
+
if (!globalThis.crypto || !globalThis.crypto.subtle) {
|
|
239
|
+
throw new Error("WebCrypto unavailable for key derivation");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const encoder = new TextEncoder();
|
|
243
|
+
const keyMaterial = await globalThis.crypto.subtle.importKey(
|
|
244
|
+
"raw",
|
|
245
|
+
encoder.encode(String(password)),
|
|
246
|
+
{ name: "PBKDF2" },
|
|
247
|
+
false,
|
|
248
|
+
["deriveBits"]
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const derived = await globalThis.crypto.subtle.deriveBits(
|
|
252
|
+
{
|
|
253
|
+
name: "PBKDF2",
|
|
254
|
+
salt: encoder.encode(String(salt)),
|
|
255
|
+
iterations,
|
|
256
|
+
hash: "SHA-256",
|
|
257
|
+
},
|
|
258
|
+
keyMaterial,
|
|
259
|
+
length * 8
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
return toHex(derived);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function execute(_stack, params) {
|
|
266
|
+
const password = params?.password ?? "";
|
|
267
|
+
const salt = params?.salt ?? params?.keyDerivationSalt ?? "";
|
|
268
|
+
|
|
269
|
+
if (!password) {
|
|
270
|
+
throw new Error("Password is required for key derivation");
|
|
271
|
+
}
|
|
272
|
+
if (!salt) {
|
|
273
|
+
throw new Error("Salt is required for key derivation");
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const derivedKey = await deriveKeyMaterial(password, salt);
|
|
277
|
+
const metadata = { derivedKey, derivedAt: Date.now() };
|
|
278
|
+
return { metadata };
|
|
279
|
+
}
|
|
280
|
+
`;
|
|
281
|
+
const sys_004 = {
|
|
282
|
+
"_id": "~sys-0.0.4",
|
|
283
|
+
"~class": "patch",
|
|
284
|
+
"version": "0.0.4",
|
|
285
|
+
"target": "system",
|
|
286
|
+
"changelog": "### Schema Patch: v0.0.4\\n#### New Classes: ~Job, ~JobRun, ~Policy, ~AuthModule\\n#### Updates: ~User authentication fields",
|
|
287
|
+
"docs": [
|
|
288
|
+
{
|
|
289
|
+
"_id": "~User",
|
|
290
|
+
"_rev": "auto",
|
|
291
|
+
"active": true,
|
|
292
|
+
"name": "User",
|
|
293
|
+
"description": "A user class for secure login",
|
|
294
|
+
"~class": "class",
|
|
295
|
+
"schema": {
|
|
296
|
+
"username": {
|
|
297
|
+
"name": "username",
|
|
298
|
+
"type": "string",
|
|
299
|
+
"config": {
|
|
300
|
+
"primaryKey": true,
|
|
301
|
+
"maxLength": 50,
|
|
302
|
+
"mandatory": true,
|
|
303
|
+
"isArray": false
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
"password": {
|
|
307
|
+
"name": "password",
|
|
308
|
+
"type": "string",
|
|
309
|
+
"config": {
|
|
310
|
+
"maxLength": 50,
|
|
311
|
+
"mandatory": true,
|
|
312
|
+
"isArray": false
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
"email": {
|
|
316
|
+
"name": "email",
|
|
317
|
+
"type": "string",
|
|
318
|
+
"config": {
|
|
319
|
+
"maxLength": 50,
|
|
320
|
+
"isArray": false
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
"firstName": {
|
|
324
|
+
"name": "firstName",
|
|
325
|
+
"type": "string",
|
|
326
|
+
"config": {
|
|
327
|
+
"maxLength": 50,
|
|
328
|
+
"isArray": false
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
"lastName": {
|
|
332
|
+
"name": "lastName",
|
|
333
|
+
"type": "string",
|
|
334
|
+
"config": {
|
|
335
|
+
"maxLength": 50,
|
|
336
|
+
"isArray": false
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
"authMethod": {
|
|
340
|
+
"name": "authMethod",
|
|
341
|
+
"type": "string",
|
|
342
|
+
"config": {
|
|
343
|
+
"mandatory": true,
|
|
344
|
+
"maxLength": 100,
|
|
345
|
+
"isArray": false
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
"externalId": {
|
|
349
|
+
"name": "externalId",
|
|
350
|
+
"type": "string",
|
|
351
|
+
"config": {
|
|
352
|
+
"maxLength": 200,
|
|
353
|
+
"isArray": false
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
"keyDerivationSalt": {
|
|
357
|
+
"name": "keyDerivationSalt",
|
|
358
|
+
"type": "string",
|
|
359
|
+
"config": {
|
|
360
|
+
"mandatory": true,
|
|
361
|
+
"maxLength": 200,
|
|
362
|
+
"isArray": false
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
"_id": "~Job",
|
|
369
|
+
"active": true,
|
|
370
|
+
"name": "Job",
|
|
371
|
+
"description": "A long running or scheduled job",
|
|
372
|
+
"~class": "class",
|
|
373
|
+
"schema": {
|
|
374
|
+
"_id": { "name": "_id", "type": "string", "config": { "primaryKey": true, "mandatory": true } },
|
|
375
|
+
"name": { "name": "name", "type": "string", "config": { "mandatory": true } },
|
|
376
|
+
"description": { "name": "description", "type": "string", "config": { "isArray": false } },
|
|
377
|
+
"type": { "name": "type", "type": "string", "config": { "mandatory": true } },
|
|
378
|
+
"workerPlatform": { "name": "workerPlatform", "type": "string", "config": { "mandatory": true } },
|
|
379
|
+
"content": { "name": "content", "type": "string", "config": { "mandatory": true } },
|
|
380
|
+
"hash": { "name": "hash", "type": "string", "config": { "mandatory": true } },
|
|
381
|
+
"schedule": { "name": "schedule", "type": "string", "config": { "mandatory": false } },
|
|
382
|
+
"isSingleton": { "name": "isSingleton", "type": "boolean", "config": { "defaultValue": false } },
|
|
383
|
+
"isEnabled": { "name": "isEnabled", "type": "boolean", "config": { "mandatory": true, "defaultValue": true } },
|
|
384
|
+
"nextRunTimestamp": { "name": "nextRunTimestamp", "type": "integer", "config": { "mandatory": false } },
|
|
385
|
+
"defaultParams": { "name": "defaultParams", "type": "object", "config": { "mandatory": false } },
|
|
386
|
+
"metadata": { "name": "metadata", "type": "object", "config": { "mandatory": false } }
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
"_id": "~JobRun",
|
|
391
|
+
"active": true,
|
|
392
|
+
"name": "JobRun",
|
|
393
|
+
"description": "Execution history for jobs",
|
|
394
|
+
"~class": "class",
|
|
395
|
+
"schema": {
|
|
396
|
+
"_id": { "name": "_id", "type": "string", "config": { "primaryKey": true, "mandatory": true } },
|
|
397
|
+
"~class": { "name": "~class", "type": "string", "config": { "mandatory": true, "defaultValue": "~JobRun" } },
|
|
398
|
+
"jobId": { "name": "jobId", "type": "string", "config": { "mandatory": true } },
|
|
399
|
+
"status": { "name": "status", "type": "string", "config": { "mandatory": true } },
|
|
400
|
+
"triggerType": { "name": "triggerType", "type": "string", "config": { "mandatory": true } },
|
|
401
|
+
"startTime": { "name": "startTime", "type": "integer", "config": { "mandatory": true } },
|
|
402
|
+
"endTime": { "name": "endTime", "type": "integer", "config": { "mandatory": false } },
|
|
403
|
+
"durationMs": { "name": "durationMs", "type": "integer", "config": { "mandatory": false } },
|
|
404
|
+
"runtimeArgs": { "name": "runtimeArgs", "type": "object", "config": { "mandatory": false } },
|
|
405
|
+
"initialMetadata": { "name": "initialMetadata", "type": "object", "config": { "mandatory": false } },
|
|
406
|
+
"finalMetadata": { "name": "finalMetadata", "type": "object", "config": { "mandatory": false } },
|
|
407
|
+
"errorMessage": { "name": "errorMessage", "type": "string", "config": { "mandatory": false } },
|
|
408
|
+
"errorStack": { "name": "errorStack", "type": "string", "config": { "mandatory": false } },
|
|
409
|
+
"logs": { "name": "logs", "type": "object", "config": { "mandatory": false } },
|
|
410
|
+
"workerId": { "name": "workerId", "type": "string", "config": { "mandatory": false } }
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
"_id": "~Policy",
|
|
415
|
+
"active": true,
|
|
416
|
+
"name": "Policy",
|
|
417
|
+
"description": "Access policies for classes and documents",
|
|
418
|
+
"~class": "class",
|
|
419
|
+
"schema": {
|
|
420
|
+
"userId": { "name": "userId", "type": "string", "config": { "mandatory": true } },
|
|
421
|
+
"rule": { "name": "rule", "type": "string", "config": { "mandatory": true, "maxLength": 2000 } },
|
|
422
|
+
"description": { "name": "description", "type": "string", "config": { "mandatory": false } },
|
|
423
|
+
"targetClass": { "name": "targetClass", "type": "foreign_key", "config": { "mandatory": true, "isArray": true, "targetClass": "class" } }
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
"_id": "~AuthModule",
|
|
428
|
+
"active": true,
|
|
429
|
+
"name": "AuthModule",
|
|
430
|
+
"description": "Authentication module descriptor",
|
|
431
|
+
"~class": "class",
|
|
432
|
+
"schema": {
|
|
433
|
+
"name": { "name": "name", "type": "string", "config": { "mandatory": true } },
|
|
434
|
+
"config": { "name": "config", "type": "object", "config": { "mandatory": false } },
|
|
435
|
+
"jobId": { "name": "jobId", "type": "foreign_key", "config": { "mandatory": true, "targetClass": "~Job" } }
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
]
|
|
439
|
+
};
|
|
440
|
+
const sys_005 = {
|
|
441
|
+
"_id": "~sys-0.0.5",
|
|
442
|
+
"~class": "patch",
|
|
443
|
+
"version": "0.0.5",
|
|
444
|
+
"target": "system",
|
|
445
|
+
"changelog": "### Schema Patch: v0.0.5\\n#### New Documents: Job-Auth-Classic, AuthMod-Classic, Policy-System-Classes",
|
|
446
|
+
"docs": [
|
|
447
|
+
{
|
|
448
|
+
"_id": "Job-Auth-Classic",
|
|
449
|
+
"~class": "~Job",
|
|
450
|
+
"active": true,
|
|
451
|
+
"name": "Classic authentication",
|
|
452
|
+
"description": "Derive key material from password and salt",
|
|
453
|
+
"type": "user",
|
|
454
|
+
"workerPlatform": "client",
|
|
455
|
+
"content": classicAuthJobContent,
|
|
456
|
+
"hash": "e63887145113429477843420c388d35116e255403148163f4c4a436f0b8338b1", // Pre-calculated hash
|
|
457
|
+
"isEnabled": true,
|
|
458
|
+
"isSingleton": true,
|
|
459
|
+
"defaultParams": {},
|
|
460
|
+
"metadata": {}
|
|
461
|
+
},
|
|
462
|
+
]
|
|
463
|
+
};
|
|
464
|
+
const sys_006 = {
|
|
465
|
+
"_id": "~sys-00.6",
|
|
466
|
+
"~class": "patch",
|
|
467
|
+
"version": "0.0.6",
|
|
468
|
+
"target": "system",
|
|
469
|
+
"changelog": "### Schema Patch: v0.0.6\\n#### New Documents: AuthMod-Classic, Policy-System-Classes",
|
|
470
|
+
"docs": [
|
|
471
|
+
{
|
|
472
|
+
"_id": "AuthMod-Classic",
|
|
473
|
+
"~class": "~AuthModule",
|
|
474
|
+
"active": true,
|
|
475
|
+
"name": "Classic Email/Password",
|
|
476
|
+
"config": { "mode": "password" },
|
|
477
|
+
"jobId": "Job-Auth-Classic"
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
"_id": "Policy-System-Classes",
|
|
481
|
+
"~class": "~Policy",
|
|
482
|
+
"active": true,
|
|
483
|
+
"userId": "system",
|
|
484
|
+
"rule": "return true;",
|
|
485
|
+
"description": "Default system policy",
|
|
486
|
+
"targetClass": ["class", "~User", "~UserSession", "~Policy", "~Job", "~JobRun", "~AuthModule"]
|
|
487
|
+
}
|
|
488
|
+
]
|
|
489
|
+
};
|
|
490
|
+
const sys_007 = {
|
|
491
|
+
"_id": "~sys-0.0.7",
|
|
492
|
+
"~class": "patch",
|
|
493
|
+
"version": "0.0.7",
|
|
494
|
+
"target": "system",
|
|
495
|
+
"changelog": "### Schema Patch: v0.0.7\\n#### Updates: enforce enum/foreign key definitions for job, policy, and user auth fields",
|
|
496
|
+
"docs": [
|
|
497
|
+
{
|
|
498
|
+
"_id": "~User",
|
|
499
|
+
"_rev": "auto",
|
|
500
|
+
"active": true,
|
|
501
|
+
"name": "User",
|
|
502
|
+
"description": "A user class for secure login",
|
|
503
|
+
"~class": "class",
|
|
504
|
+
"schema": {
|
|
505
|
+
"username": {
|
|
506
|
+
"name": "username",
|
|
507
|
+
"type": "string",
|
|
508
|
+
"config": {
|
|
509
|
+
"primaryKey": true,
|
|
510
|
+
"maxLength": 50,
|
|
511
|
+
"mandatory": true,
|
|
512
|
+
"isArray": false
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
"password": {
|
|
516
|
+
"name": "password",
|
|
517
|
+
"type": "string",
|
|
518
|
+
"config": {
|
|
519
|
+
"maxLength": 50,
|
|
520
|
+
"mandatory": true,
|
|
521
|
+
"isArray": false
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
"email": {
|
|
525
|
+
"name": "email",
|
|
526
|
+
"type": "string",
|
|
527
|
+
"config": {
|
|
528
|
+
"maxLength": 50,
|
|
529
|
+
"isArray": false
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
"firstName": {
|
|
533
|
+
"name": "firstName",
|
|
534
|
+
"type": "string",
|
|
535
|
+
"config": {
|
|
536
|
+
"maxLength": 50,
|
|
537
|
+
"isArray": false
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
"lastName": {
|
|
541
|
+
"name": "lastName",
|
|
542
|
+
"type": "string",
|
|
543
|
+
"config": {
|
|
544
|
+
"maxLength": 50,
|
|
545
|
+
"isArray": false
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
"authMethod": {
|
|
549
|
+
"name": "authMethod",
|
|
550
|
+
"type": "foreign_key",
|
|
551
|
+
"config": { "mandatory": true, "targetClass": "~AuthModule" }
|
|
552
|
+
},
|
|
553
|
+
"externalId": {
|
|
554
|
+
"name": "externalId",
|
|
555
|
+
"type": "string",
|
|
556
|
+
"config": {
|
|
557
|
+
"maxLength": 200,
|
|
558
|
+
"isArray": false
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
"keyDerivationSalt": {
|
|
562
|
+
"name": "keyDerivationSalt",
|
|
563
|
+
"type": "string",
|
|
564
|
+
"config": {
|
|
565
|
+
"mandatory": true,
|
|
566
|
+
"maxLength": 200,
|
|
567
|
+
"isArray": false
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
"_id": "~Job",
|
|
574
|
+
"_rev": "auto",
|
|
575
|
+
"active": true,
|
|
576
|
+
"name": "Job",
|
|
577
|
+
"description": "A long running or scheduled job",
|
|
578
|
+
"~class": "class",
|
|
579
|
+
"schema": {
|
|
580
|
+
"_id": { "name": "_id", "type": "string", "config": { "primaryKey": true, "mandatory": true } },
|
|
581
|
+
"name": { "name": "name", "type": "string", "config": { "mandatory": true } },
|
|
582
|
+
"description": { "name": "description", "type": "string", "config": { "isArray": false } },
|
|
583
|
+
"type": {
|
|
584
|
+
"name": "type",
|
|
585
|
+
"type": "enum",
|
|
586
|
+
"config": { "mandatory": true, "values": [{ value: "system" }, { value: "user" }] }
|
|
587
|
+
},
|
|
588
|
+
"workerPlatform": {
|
|
589
|
+
"name": "workerPlatform",
|
|
590
|
+
"type": "enum",
|
|
591
|
+
"config": { "mandatory": true, "values": [{ value: "client" }, { value: "server" }, { value: "hybrid" }] }
|
|
592
|
+
},
|
|
593
|
+
"content": { "name": "content", "type": "string", "config": { "mandatory": true } },
|
|
594
|
+
"hash": { "name": "hash", "type": "string", "config": { "mandatory": true } },
|
|
595
|
+
"schedule": { "name": "schedule", "type": "string", "config": { "mandatory": false } },
|
|
596
|
+
"isSingleton": { "name": "isSingleton", "type": "boolean", "config": { "defaultValue": false } },
|
|
597
|
+
"isEnabled": { "name": "isEnabled", "type": "boolean", "config": { "mandatory": true, "defaultValue": true } },
|
|
598
|
+
"nextRunTimestamp": { "name": "nextRunTimestamp", "type": "integer", "config": { "mandatory": false } },
|
|
599
|
+
"defaultParams": { "name": "defaultParams", "type": "object", "config": { "mandatory": false } },
|
|
600
|
+
"metadata": { "name": "metadata", "type": "object", "config": { "mandatory": false } }
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
"_id": "~JobRun",
|
|
605
|
+
"_rev": "auto",
|
|
606
|
+
"active": true,
|
|
607
|
+
"name": "JobRun",
|
|
608
|
+
"description": "Execution history for jobs",
|
|
609
|
+
"~class": "class",
|
|
610
|
+
"schema": {
|
|
611
|
+
"_id": { "name": "_id", "type": "string", "config": { "primaryKey": true, "mandatory": true } },
|
|
612
|
+
"~class": { "name": "~class", "type": "string", "config": { "mandatory": true, "defaultValue": "~JobRun" } },
|
|
613
|
+
"jobId": { "name": "jobId", "type": "foreign_key", "config": { "mandatory": true, "targetClass": "~Job" } },
|
|
614
|
+
"status": {
|
|
615
|
+
"name": "status",
|
|
616
|
+
"type": "enum",
|
|
617
|
+
"config": {
|
|
618
|
+
"mandatory": true,
|
|
619
|
+
"values": [
|
|
620
|
+
{ value: "PENDING" },
|
|
621
|
+
{ value: "RUNNING" },
|
|
622
|
+
{ value: "SUCCESS" },
|
|
623
|
+
{ value: "FAILURE" },
|
|
624
|
+
{ value: "CANCELED" },
|
|
625
|
+
{ value: "SKIPPED" }
|
|
626
|
+
]
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
"triggerType": {
|
|
630
|
+
"name": "triggerType",
|
|
631
|
+
"type": "enum",
|
|
632
|
+
"config": { "mandatory": true, "values": [{ value: "manual" }, { value: "scheduled" }, { value: "event" }] }
|
|
633
|
+
},
|
|
634
|
+
"startTime": { "name": "startTime", "type": "integer", "config": { "mandatory": true } },
|
|
635
|
+
"endTime": { "name": "endTime", "type": "integer", "config": { "mandatory": false } },
|
|
636
|
+
"durationMs": { "name": "durationMs", "type": "integer", "config": { "mandatory": false } },
|
|
637
|
+
"runtimeArgs": { "name": "runtimeArgs", "type": "object", "config": { "mandatory": false } },
|
|
638
|
+
"initialMetadata": { "name": "initialMetadata", "type": "object", "config": { "mandatory": false } },
|
|
639
|
+
"finalMetadata": { "name": "finalMetadata", "type": "object", "config": { "mandatory": false } },
|
|
640
|
+
"errorMessage": { "name": "errorMessage", "type": "string", "config": { "mandatory": false } },
|
|
641
|
+
"errorStack": { "name": "errorStack", "type": "string", "config": { "mandatory": false } },
|
|
642
|
+
"logs": { "name": "logs", "type": "object", "config": { "mandatory": false } },
|
|
643
|
+
"workerId": { "name": "workerId", "type": "string", "config": { "mandatory": false } }
|
|
644
|
+
}
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
"_id": "~Policy",
|
|
648
|
+
"_rev": "auto",
|
|
649
|
+
"active": true,
|
|
650
|
+
"name": "Policy",
|
|
651
|
+
"description": "Access policies for classes and documents",
|
|
652
|
+
"~class": "class",
|
|
653
|
+
"schema": {
|
|
654
|
+
"userId": { "name": "userId", "type": "foreign_key", "config": { "mandatory": false, "targetClass": "~User" } },
|
|
655
|
+
"rule": { "name": "rule", "type": "string", "config": { "mandatory": true, "maxLength": 2000 } },
|
|
656
|
+
"description": { "name": "description", "type": "string", "config": { "mandatory": false } },
|
|
657
|
+
"targetClass": { "name": "targetClass", "type": "foreign_key", "config": { "mandatory": true, "isArray": true, "targetClass": "class" } }
|
|
658
|
+
}
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
"_id": "system",
|
|
662
|
+
"~class": "~User",
|
|
663
|
+
"active": true,
|
|
664
|
+
"username": "system",
|
|
665
|
+
"password": "system",
|
|
666
|
+
"email": "",
|
|
667
|
+
"firstName": "System",
|
|
668
|
+
"lastName": "User",
|
|
669
|
+
"authMethod": "AuthMod-Classic",
|
|
670
|
+
"externalId": "",
|
|
671
|
+
"keyDerivationSalt": "system-salt"
|
|
672
|
+
}
|
|
673
|
+
]
|
|
674
|
+
};
|
|
675
|
+
const sys_008 = {
|
|
676
|
+
"_id": "~sys-0.0.8",
|
|
677
|
+
"~class": "patch",
|
|
678
|
+
"version": "0.0.8",
|
|
679
|
+
"target": "system",
|
|
680
|
+
"changelog": "### Schema Patch: v0.0.8\\n#### Updates: support wrapped document keys and encrypted user secrets",
|
|
681
|
+
"docs": [
|
|
682
|
+
{
|
|
683
|
+
"_id": "~User",
|
|
684
|
+
"_rev": "auto",
|
|
685
|
+
"active": true,
|
|
686
|
+
"name": "User",
|
|
687
|
+
"description": "A user class for secure login",
|
|
688
|
+
"~class": "class",
|
|
689
|
+
"schema": {
|
|
690
|
+
"username": {
|
|
691
|
+
"name": "username",
|
|
692
|
+
"type": "string",
|
|
693
|
+
"config": {
|
|
694
|
+
"primaryKey": true,
|
|
695
|
+
"maxLength": 50,
|
|
696
|
+
"mandatory": true,
|
|
697
|
+
"isArray": false
|
|
698
|
+
}
|
|
699
|
+
},
|
|
700
|
+
"password": {
|
|
701
|
+
"name": "password",
|
|
702
|
+
"type": "string",
|
|
703
|
+
"config": {
|
|
704
|
+
"maxLength": 50,
|
|
705
|
+
"mandatory": true,
|
|
706
|
+
"isArray": false,
|
|
707
|
+
"encrypted": true
|
|
708
|
+
}
|
|
709
|
+
},
|
|
710
|
+
"email": {
|
|
711
|
+
"name": "email",
|
|
712
|
+
"type": "string",
|
|
713
|
+
"config": {
|
|
714
|
+
"maxLength": 50,
|
|
715
|
+
"isArray": false
|
|
716
|
+
}
|
|
717
|
+
},
|
|
718
|
+
"firstName": {
|
|
719
|
+
"name": "firstName",
|
|
720
|
+
"type": "string",
|
|
721
|
+
"config": {
|
|
722
|
+
"maxLength": 50,
|
|
723
|
+
"isArray": false
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
"lastName": {
|
|
727
|
+
"name": "lastName",
|
|
728
|
+
"type": "string",
|
|
729
|
+
"config": {
|
|
730
|
+
"maxLength": 50,
|
|
731
|
+
"isArray": false
|
|
732
|
+
}
|
|
733
|
+
},
|
|
734
|
+
"authMethod": {
|
|
735
|
+
"name": "authMethod",
|
|
736
|
+
"type": "foreign_key",
|
|
737
|
+
"config": { "mandatory": true, "targetClass": "~AuthModule" }
|
|
738
|
+
},
|
|
739
|
+
"externalId": {
|
|
740
|
+
"name": "externalId",
|
|
741
|
+
"type": "string",
|
|
742
|
+
"config": {
|
|
743
|
+
"maxLength": 200,
|
|
744
|
+
"isArray": false
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
"keyDerivationSalt": {
|
|
748
|
+
"name": "keyDerivationSalt",
|
|
749
|
+
"type": "string",
|
|
750
|
+
"config": {
|
|
751
|
+
"mandatory": true,
|
|
752
|
+
"maxLength": 200,
|
|
753
|
+
"isArray": false
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
"wrappedDocumentKey": {
|
|
757
|
+
"name": "wrappedDocumentKey",
|
|
758
|
+
"type": "string",
|
|
759
|
+
"config": {
|
|
760
|
+
"mandatory": false,
|
|
761
|
+
"maxLength": 4096,
|
|
762
|
+
"isArray": false,
|
|
763
|
+
"encrypted": false
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
"_id": "system",
|
|
770
|
+
"_rev": "auto",
|
|
771
|
+
"~class": "~User",
|
|
772
|
+
"active": true,
|
|
773
|
+
"username": "system",
|
|
774
|
+
"password": "system",
|
|
775
|
+
"email": "",
|
|
776
|
+
"firstName": "System",
|
|
777
|
+
"lastName": "User",
|
|
778
|
+
"authMethod": "AuthMod-Classic",
|
|
779
|
+
"externalId": "",
|
|
780
|
+
"keyDerivationSalt": "system-salt",
|
|
781
|
+
"wrappedDocumentKey": ""
|
|
782
|
+
}
|
|
783
|
+
]
|
|
784
|
+
};
|
|
785
|
+
const sys_009 = {
|
|
786
|
+
"_id": "~sys-0.0.9",
|
|
787
|
+
"~class": "patch",
|
|
788
|
+
"version": "0.0.9",
|
|
789
|
+
"target": "system",
|
|
790
|
+
"changelog": "### Schema Patch: v0.0.9\\n#### Updates: restrict ~User access to the owner and system user",
|
|
791
|
+
"docs": [
|
|
792
|
+
{
|
|
793
|
+
"_id": "Policy-System-Classes",
|
|
794
|
+
"_rev": "auto",
|
|
795
|
+
"~class": "~Policy",
|
|
796
|
+
"active": true,
|
|
797
|
+
"userId": "system",
|
|
798
|
+
"rule": "return true;",
|
|
799
|
+
"description": "Default system policy",
|
|
800
|
+
"targetClass": ["class", "~UserSession", "~Policy", "~Job", "~JobRun", "~AuthModule"]
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
"_id": "Policy-User-SelfAccess",
|
|
804
|
+
"~class": "~Policy",
|
|
805
|
+
"active": true,
|
|
806
|
+
"rule": "if (!session || session.sessionStatus !== 'active') return false; if (session.username === 'system') return true; const targetUsername = document?.username || document?._id; return targetUsername === session.username;",
|
|
807
|
+
"description": "Allow users to access only their own user document or the system user",
|
|
808
|
+
"targetClass": ["~User"]
|
|
809
|
+
}
|
|
810
|
+
]
|
|
811
|
+
};
|
|
812
|
+
const sys_010 = {
|
|
813
|
+
"_id": "~sys-0.0.10",
|
|
814
|
+
"~class": "patch",
|
|
815
|
+
"version": "0.0.10",
|
|
816
|
+
"target": "system",
|
|
817
|
+
"changelog": "### Schema Patch: v0.0.10\\n#### Updates: enforce ~UserSession references an existing ~User via userId",
|
|
818
|
+
"docs": [
|
|
819
|
+
{
|
|
820
|
+
"_id": "~UserSession",
|
|
821
|
+
"_rev": "auto",
|
|
822
|
+
"name": "UserSession",
|
|
823
|
+
"active": true,
|
|
824
|
+
"description": "Tracks user sessions",
|
|
825
|
+
"~class": "class",
|
|
826
|
+
"schema": {
|
|
827
|
+
"userId": {
|
|
828
|
+
"name": "userId",
|
|
829
|
+
"type": "foreign_key",
|
|
830
|
+
"config": {
|
|
831
|
+
"mandatory": true,
|
|
832
|
+
"targetClass": "~User",
|
|
833
|
+
"isArray": false
|
|
834
|
+
}
|
|
835
|
+
},
|
|
836
|
+
"username": {
|
|
837
|
+
"name": "username",
|
|
838
|
+
"type": "string",
|
|
839
|
+
"config": {
|
|
840
|
+
"maxLength": 50,
|
|
841
|
+
"isArray": false,
|
|
842
|
+
"primaryKey": true,
|
|
843
|
+
"mandatory": true
|
|
844
|
+
}
|
|
845
|
+
},
|
|
846
|
+
"sessionId": {
|
|
847
|
+
"name": "sessionId",
|
|
848
|
+
"type": "string",
|
|
849
|
+
"config": {
|
|
850
|
+
"maxLength": 200,
|
|
851
|
+
"primaryKey": true,
|
|
852
|
+
"isArray": false,
|
|
853
|
+
"mandatory": true
|
|
854
|
+
}
|
|
855
|
+
},
|
|
856
|
+
"sessionStart": {
|
|
857
|
+
"name": "sessionStart",
|
|
858
|
+
"type": "string",
|
|
859
|
+
"config": {
|
|
860
|
+
"maxLength": 100,
|
|
861
|
+
"isArray": false,
|
|
862
|
+
"mandatory": true
|
|
863
|
+
}
|
|
864
|
+
},
|
|
865
|
+
"sessionStatus": {
|
|
866
|
+
"name": "sessionStatus",
|
|
867
|
+
"type": "string",
|
|
868
|
+
"config": {
|
|
869
|
+
"maxLength": 100,
|
|
870
|
+
"isArray": false,
|
|
871
|
+
"mandatory": true
|
|
872
|
+
}
|
|
873
|
+
},
|
|
874
|
+
"sessionEnd": {
|
|
875
|
+
"name": "sessionEnd",
|
|
876
|
+
"type": "string",
|
|
877
|
+
"config": {
|
|
878
|
+
"maxLength": 100,
|
|
879
|
+
"isArray": false,
|
|
880
|
+
"mandatory": false
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
]
|
|
886
|
+
};
|
|
887
|
+
syspatches.push(sys_001, /* sys_002 ,*/ sys_003, sys_004, sys_005, sys_006, sys_007, sys_008, sys_009, sys_010);
|
|
888
|
+
const sys_011 = {
|
|
889
|
+
"_id": "~sys-0.0.11",
|
|
890
|
+
"~class": "patch",
|
|
891
|
+
"version": "0.0.11",
|
|
892
|
+
"target": "system",
|
|
893
|
+
"changelog": "### Schema Patch: v0.0.11\\n#### New Class: ~Group",
|
|
894
|
+
"docs": [
|
|
895
|
+
{
|
|
896
|
+
"_id": "~Group",
|
|
897
|
+
"active": true,
|
|
898
|
+
"name": "Group",
|
|
899
|
+
"description": "Represents a user group",
|
|
900
|
+
"~class": "class",
|
|
901
|
+
"schema": {
|
|
902
|
+
"name": { "name": "name", "type": "string", "config": { "primaryKey": true, "mandatory": true, "maxLength": 100, "isArray": false } }
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
]
|
|
906
|
+
};
|
|
907
|
+
const sys_012 = {
|
|
908
|
+
"_id": "~sys-0.0.12",
|
|
909
|
+
"~class": "patch",
|
|
910
|
+
"version": "0.0.12",
|
|
911
|
+
"target": "system",
|
|
912
|
+
"changelog": "### Schema Patch: v0.0.12\\n#### Updates: introduce groups, optional policy principals, and group-aware sessions",
|
|
913
|
+
"docs": [
|
|
914
|
+
{
|
|
915
|
+
"_id": "~User",
|
|
916
|
+
"_rev": "auto",
|
|
917
|
+
"active": true,
|
|
918
|
+
"name": "User",
|
|
919
|
+
"description": "A user class for secure login",
|
|
920
|
+
"~class": "class",
|
|
921
|
+
"schema": {
|
|
922
|
+
"username": {
|
|
923
|
+
"name": "username",
|
|
924
|
+
"type": "string",
|
|
925
|
+
"config": {
|
|
926
|
+
"primaryKey": true,
|
|
927
|
+
"maxLength": 50,
|
|
928
|
+
"mandatory": true,
|
|
929
|
+
"isArray": false
|
|
930
|
+
}
|
|
931
|
+
},
|
|
932
|
+
"password": {
|
|
933
|
+
"name": "password",
|
|
934
|
+
"type": "string",
|
|
935
|
+
"config": {
|
|
936
|
+
"maxLength": 50,
|
|
937
|
+
"mandatory": true,
|
|
938
|
+
"isArray": false,
|
|
939
|
+
"encrypted": true
|
|
940
|
+
}
|
|
941
|
+
},
|
|
942
|
+
"groupId": {
|
|
943
|
+
"name": "groupId",
|
|
944
|
+
"type": "foreign_key",
|
|
945
|
+
"config": {
|
|
946
|
+
"mandatory": true,
|
|
947
|
+
"isArray": true,
|
|
948
|
+
"targetClass": "~Group"
|
|
949
|
+
}
|
|
950
|
+
},
|
|
951
|
+
"email": {
|
|
952
|
+
"name": "email",
|
|
953
|
+
"type": "string",
|
|
954
|
+
"config": {
|
|
955
|
+
"maxLength": 50,
|
|
956
|
+
"isArray": false
|
|
957
|
+
}
|
|
958
|
+
},
|
|
959
|
+
"firstName": {
|
|
960
|
+
"name": "firstName",
|
|
961
|
+
"type": "string",
|
|
962
|
+
"config": {
|
|
963
|
+
"maxLength": 50,
|
|
964
|
+
"isArray": false
|
|
965
|
+
}
|
|
966
|
+
},
|
|
967
|
+
"lastName": {
|
|
968
|
+
"name": "lastName",
|
|
969
|
+
"type": "string",
|
|
970
|
+
"config": {
|
|
971
|
+
"maxLength": 50,
|
|
972
|
+
"isArray": false
|
|
973
|
+
}
|
|
974
|
+
},
|
|
975
|
+
"authMethod": {
|
|
976
|
+
"name": "authMethod",
|
|
977
|
+
"type": "foreign_key",
|
|
978
|
+
"config": { "mandatory": true, "targetClass": "~AuthModule" }
|
|
979
|
+
},
|
|
980
|
+
"externalId": {
|
|
981
|
+
"name": "externalId",
|
|
982
|
+
"type": "string",
|
|
983
|
+
"config": {
|
|
984
|
+
"maxLength": 200,
|
|
985
|
+
"isArray": false
|
|
986
|
+
}
|
|
987
|
+
},
|
|
988
|
+
"keyDerivationSalt": {
|
|
989
|
+
"name": "keyDerivationSalt",
|
|
990
|
+
"type": "string",
|
|
991
|
+
"config": {
|
|
992
|
+
"mandatory": true,
|
|
993
|
+
"maxLength": 200,
|
|
994
|
+
"isArray": false
|
|
995
|
+
}
|
|
996
|
+
},
|
|
997
|
+
"wrappedDocumentKey": {
|
|
998
|
+
"name": "wrappedDocumentKey",
|
|
999
|
+
"type": "string",
|
|
1000
|
+
"config": {
|
|
1001
|
+
"mandatory": false,
|
|
1002
|
+
"maxLength": 4096,
|
|
1003
|
+
"isArray": false,
|
|
1004
|
+
"encrypted": false
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
"_id": "~UserSession",
|
|
1011
|
+
"_rev": "auto",
|
|
1012
|
+
"name": "UserSession",
|
|
1013
|
+
"active": true,
|
|
1014
|
+
"description": "Tracks user sessions",
|
|
1015
|
+
"~class": "class",
|
|
1016
|
+
"schema": {
|
|
1017
|
+
"userId": {
|
|
1018
|
+
"name": "userId",
|
|
1019
|
+
"type": "foreign_key",
|
|
1020
|
+
"config": {
|
|
1021
|
+
"mandatory": true,
|
|
1022
|
+
"targetClass": "~User",
|
|
1023
|
+
"isArray": false
|
|
1024
|
+
}
|
|
1025
|
+
},
|
|
1026
|
+
"groupId": {
|
|
1027
|
+
"name": "groupId",
|
|
1028
|
+
"type": "foreign_key",
|
|
1029
|
+
"config": {
|
|
1030
|
+
"mandatory": true,
|
|
1031
|
+
"targetClass": "~Group",
|
|
1032
|
+
"isArray": true
|
|
1033
|
+
}
|
|
1034
|
+
},
|
|
1035
|
+
"username": {
|
|
1036
|
+
"name": "username",
|
|
1037
|
+
"type": "string",
|
|
1038
|
+
"config": {
|
|
1039
|
+
"maxLength": 50,
|
|
1040
|
+
"isArray": false,
|
|
1041
|
+
"primaryKey": true,
|
|
1042
|
+
"mandatory": true
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
1045
|
+
"sessionId": {
|
|
1046
|
+
"name": "sessionId",
|
|
1047
|
+
"type": "string",
|
|
1048
|
+
"config": {
|
|
1049
|
+
"maxLength": 200,
|
|
1050
|
+
"primaryKey": true,
|
|
1051
|
+
"isArray": false,
|
|
1052
|
+
"mandatory": true
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
"sessionStart": {
|
|
1056
|
+
"name": "sessionStart",
|
|
1057
|
+
"type": "string",
|
|
1058
|
+
"config": {
|
|
1059
|
+
"maxLength": 100,
|
|
1060
|
+
"isArray": false,
|
|
1061
|
+
"mandatory": true
|
|
1062
|
+
}
|
|
1063
|
+
},
|
|
1064
|
+
"sessionStatus": {
|
|
1065
|
+
"name": "sessionStatus",
|
|
1066
|
+
"type": "string",
|
|
1067
|
+
"config": {
|
|
1068
|
+
"maxLength": 100,
|
|
1069
|
+
"isArray": false,
|
|
1070
|
+
"mandatory": true
|
|
1071
|
+
}
|
|
1072
|
+
},
|
|
1073
|
+
"sessionEnd": {
|
|
1074
|
+
"name": "sessionEnd",
|
|
1075
|
+
"type": "string",
|
|
1076
|
+
"config": {
|
|
1077
|
+
"maxLength": 100,
|
|
1078
|
+
"isArray": false,
|
|
1079
|
+
"mandatory": false
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
"_id": "~Policy",
|
|
1086
|
+
"_rev": "auto",
|
|
1087
|
+
"active": true,
|
|
1088
|
+
"name": "Policy",
|
|
1089
|
+
"description": "Access policies for classes and documents",
|
|
1090
|
+
"~class": "class",
|
|
1091
|
+
"schema": {
|
|
1092
|
+
"userId": { "name": "userId", "type": "foreign_key", "config": { "mandatory": false, "targetClass": "~User" } },
|
|
1093
|
+
"groupId": { "name": "groupId", "type": "foreign_key", "config": { "mandatory": false, "targetClass": "~Group" } },
|
|
1094
|
+
"rule": { "name": "rule", "type": "string", "config": { "mandatory": true, "maxLength": 2000 } },
|
|
1095
|
+
"description": { "name": "description", "type": "string", "config": { "mandatory": false } },
|
|
1096
|
+
"targetClass": { "name": "targetClass", "type": "foreign_key", "config": { "mandatory": true, "isArray": true, "targetClass": "class" } }
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
]
|
|
1100
|
+
};
|
|
1101
|
+
const sys_013 = {
|
|
1102
|
+
"_id": "~sys-0.0.13",
|
|
1103
|
+
"~class": "patch",
|
|
1104
|
+
"version": "0.0.13",
|
|
1105
|
+
"target": "system",
|
|
1106
|
+
"changelog": "### Schema Patch: v0.0.13\\n#### New Documents: Group-Admin, Group-Default\\n#### Updates: ~User with after trigger for wrappedDocumentKey",
|
|
1107
|
+
"docs": [
|
|
1108
|
+
{
|
|
1109
|
+
"_id": "Group-Admin",
|
|
1110
|
+
"~class": "~Group",
|
|
1111
|
+
"active": true,
|
|
1112
|
+
"name": "Admin"
|
|
1113
|
+
},
|
|
1114
|
+
{
|
|
1115
|
+
"_id": "Group-Default",
|
|
1116
|
+
"~class": "~Group",
|
|
1117
|
+
"active": true,
|
|
1118
|
+
"name": "Default"
|
|
1119
|
+
},
|
|
1120
|
+
{
|
|
1121
|
+
"_id": "~User",
|
|
1122
|
+
"_rev": "auto",
|
|
1123
|
+
"active": true,
|
|
1124
|
+
"name": "User",
|
|
1125
|
+
"description": "A user class for secure login",
|
|
1126
|
+
"~class": "class",
|
|
1127
|
+
"triggers": [
|
|
1128
|
+
{
|
|
1129
|
+
"name": "ensure-salt",
|
|
1130
|
+
"order": "before",
|
|
1131
|
+
"run": `if (!document.keyDerivationSalt) {
|
|
1132
|
+
const salt = stack.cryptoEngine.generateRandomString(32);
|
|
1133
|
+
document.keyDerivationSalt = salt;
|
|
1134
|
+
}
|
|
1135
|
+
return document;`
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
"name": "auto-wrap-document-key",
|
|
1139
|
+
"order": "before",
|
|
1140
|
+
"run": `if (document.password && document.keyDerivationSalt && stack.cryptoEngine.getDocumentKey()) {
|
|
1141
|
+
let shouldRecalculate = true;
|
|
1142
|
+
if (document._id) {
|
|
1143
|
+
try {
|
|
1144
|
+
const currentDoc = await stack.db.get(document._id);
|
|
1145
|
+
if (currentDoc && currentDoc.password === document.password && currentDoc.keyDerivationSalt === document.keyDerivationSalt && currentDoc.wrappedDocumentKey) {
|
|
1146
|
+
shouldRecalculate = false;
|
|
1147
|
+
if (!document.wrappedDocumentKey) {
|
|
1148
|
+
document.wrappedDocumentKey = currentDoc.wrappedDocumentKey;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
} catch (e) { }
|
|
1152
|
+
}
|
|
1153
|
+
if (shouldRecalculate) {
|
|
1154
|
+
const authModuleId = document.authMethod || "AuthMod-Classic";
|
|
1155
|
+
const authModule = await stack.db.get(authModuleId);
|
|
1156
|
+
const jobId = authModule.jobId;
|
|
1157
|
+
const run = await stack.jobEngine.executeJob(jobId, {
|
|
1158
|
+
password: document.password,
|
|
1159
|
+
salt: document.keyDerivationSalt,
|
|
1160
|
+
keyDerivationSalt: document.keyDerivationSalt,
|
|
1161
|
+
});
|
|
1162
|
+
const derivedKey = (run.finalMetadata)?.derivedKey ?? (run.initialMetadata)?.derivedKey;
|
|
1163
|
+
const wrappedKey = await stack.cryptoEngine.wrapDocumentKey(stack.cryptoEngine.getDocumentKey(), derivedKey);
|
|
1164
|
+
document.wrappedDocumentKey = wrappedKey;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
return document;`
|
|
1168
|
+
}
|
|
1169
|
+
],
|
|
1170
|
+
"schema": {
|
|
1171
|
+
"username": {
|
|
1172
|
+
"name": "username",
|
|
1173
|
+
"type": "string",
|
|
1174
|
+
"config": {
|
|
1175
|
+
"primaryKey": true,
|
|
1176
|
+
"maxLength": 50,
|
|
1177
|
+
"mandatory": true,
|
|
1178
|
+
"isArray": false
|
|
1179
|
+
}
|
|
1180
|
+
},
|
|
1181
|
+
"password": {
|
|
1182
|
+
"name": "password",
|
|
1183
|
+
"type": "string",
|
|
1184
|
+
"config": {
|
|
1185
|
+
"maxLength": 50,
|
|
1186
|
+
"mandatory": true,
|
|
1187
|
+
"isArray": false,
|
|
1188
|
+
"encrypted": true
|
|
1189
|
+
}
|
|
1190
|
+
},
|
|
1191
|
+
"groupId": {
|
|
1192
|
+
"name": "groupId",
|
|
1193
|
+
"type": "foreign_key",
|
|
1194
|
+
"config": {
|
|
1195
|
+
"mandatory": true,
|
|
1196
|
+
"isArray": true,
|
|
1197
|
+
"targetClass": "~Group"
|
|
1198
|
+
}
|
|
1199
|
+
},
|
|
1200
|
+
"email": {
|
|
1201
|
+
"name": "email",
|
|
1202
|
+
"type": "string",
|
|
1203
|
+
"config": {
|
|
1204
|
+
"maxLength": 50,
|
|
1205
|
+
"isArray": false
|
|
1206
|
+
}
|
|
1207
|
+
},
|
|
1208
|
+
"firstName": {
|
|
1209
|
+
"name": "firstName",
|
|
1210
|
+
"type": "string",
|
|
1211
|
+
"config": {
|
|
1212
|
+
"maxLength": 50,
|
|
1213
|
+
"isArray": false
|
|
1214
|
+
}
|
|
1215
|
+
},
|
|
1216
|
+
"lastName": {
|
|
1217
|
+
"name": "lastName",
|
|
1218
|
+
"type": "string",
|
|
1219
|
+
"config": {
|
|
1220
|
+
"maxLength": 50,
|
|
1221
|
+
"isArray": false
|
|
1222
|
+
}
|
|
1223
|
+
},
|
|
1224
|
+
"authMethod": {
|
|
1225
|
+
"name": "authMethod",
|
|
1226
|
+
"type": "foreign_key",
|
|
1227
|
+
"config": { "mandatory": true, "targetClass": "~AuthModule" }
|
|
1228
|
+
},
|
|
1229
|
+
"externalId": {
|
|
1230
|
+
"name": "externalId",
|
|
1231
|
+
"type": "string",
|
|
1232
|
+
"config": { "maxLength": 200, "isArray": false }
|
|
1233
|
+
},
|
|
1234
|
+
"keyDerivationSalt": {
|
|
1235
|
+
"name": "keyDerivationSalt",
|
|
1236
|
+
"type": "string",
|
|
1237
|
+
"config": { "mandatory": true, "maxLength": 200, "isArray": false }
|
|
1238
|
+
},
|
|
1239
|
+
"wrappedDocumentKey": {
|
|
1240
|
+
"name": "wrappedDocumentKey",
|
|
1241
|
+
"type": "string",
|
|
1242
|
+
"config": { "mandatory": false, "maxLength": 4096, "isArray": false, "encrypted": false }
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
]
|
|
1247
|
+
};
|
|
1248
|
+
const sys_014 = {
|
|
1249
|
+
"_id": "~sys-0.0.14",
|
|
1250
|
+
"~class": "patch",
|
|
1251
|
+
"version": "0.0.14",
|
|
1252
|
+
"target": "system",
|
|
1253
|
+
"changelog": "### Schema Patch: v0.0.14\\n#### New Documents: Policy-Admin, Policy-User-SelfAccess\\n#### Updates: system user with groupId",
|
|
1254
|
+
"docs": [
|
|
1255
|
+
{
|
|
1256
|
+
"_id": "system",
|
|
1257
|
+
"_rev": "auto",
|
|
1258
|
+
"~class": "~User",
|
|
1259
|
+
"active": true,
|
|
1260
|
+
"username": "system",
|
|
1261
|
+
"password": "system",
|
|
1262
|
+
"groupId": ["Group-Admin"],
|
|
1263
|
+
"email": "",
|
|
1264
|
+
"firstName": "System",
|
|
1265
|
+
"lastName": "User",
|
|
1266
|
+
"authMethod": "AuthMod-Classic",
|
|
1267
|
+
"externalId": "",
|
|
1268
|
+
},
|
|
1269
|
+
{
|
|
1270
|
+
"_id": "Policy-Admin",
|
|
1271
|
+
"~class": "~Policy",
|
|
1272
|
+
"active": true,
|
|
1273
|
+
"groupId": "Group-Admin",
|
|
1274
|
+
"rule": "return true;",
|
|
1275
|
+
"description": "Default admin policy",
|
|
1276
|
+
"targetClass": ["class", "~UserSession", "~Policy", "~Job", "~JobRun", "~AuthModule", "~Group"]
|
|
1277
|
+
},
|
|
1278
|
+
{
|
|
1279
|
+
"_id": "Policy-User-SelfAccess",
|
|
1280
|
+
"_rev": "auto",
|
|
1281
|
+
"~class": "~Policy",
|
|
1282
|
+
"active": true,
|
|
1283
|
+
"rule": "if (!session || session.sessionStatus !== 'active') return false; if (session.username === 'system') return true; const targetUsername = document?.username || document?._id; return targetUsername === session.username;",
|
|
1284
|
+
"description": "Allow users to access only their own user document or the system user",
|
|
1285
|
+
"targetClass": ["~User"]
|
|
1286
|
+
}
|
|
1287
|
+
]
|
|
1288
|
+
};
|
|
1289
|
+
syspatches.push(sys_011, sys_012, sys_013, sys_014);
|
|
1290
|
+
export async function getSystemPatches(currentVersion) {
|
|
1291
|
+
const classicAuthJobHash = await hashContent(classicAuthJobContent);
|
|
1292
|
+
const jobAuthClassic = sys_005.docs.find(d => d._id === 'Job-Auth-Classic');
|
|
1293
|
+
if (jobAuthClassic) {
|
|
1294
|
+
jobAuthClassic.hash = classicAuthJobHash;
|
|
1295
|
+
}
|
|
1296
|
+
return syspatches
|
|
1297
|
+
.sort((a, b) => semver.compare(a.version, b.version))
|
|
1298
|
+
.filter((patch) => semver.gt(patch.version, currentVersion));
|
|
1299
|
+
}
|
|
1300
|
+
export async function getAllSystemPatches() {
|
|
1301
|
+
const classicAuthJobHash = await hashContent(classicAuthJobContent);
|
|
1302
|
+
const jobAuthClassic = sys_005.docs.find(d => d._id === 'Job-Auth-Classic');
|
|
1303
|
+
if (jobAuthClassic) {
|
|
1304
|
+
jobAuthClassic.hash = classicAuthJobHash;
|
|
1305
|
+
}
|
|
1306
|
+
return syspatches.sort((a, b) => semver.compare(a.version, b.version));
|
|
1307
|
+
}
|
|
1308
|
+
//# sourceMappingURL=index.js.map
|