@genesislcap/mock-server 15.73.0 → 15.75.0
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 +296 -58
- package/dist/db/schema.d.ts +9 -1
- package/dist/db/schema.js +40 -11
- package/dist/db/store.d.ts +1 -0
- package/dist/db/store.js +4 -0
- package/dist/handlers/auth.d.ts +15 -6
- package/dist/handlers/auth.js +152 -33
- package/dist/handlers/commitEvent.js +43 -20
- package/dist/handlers/crudEvents.d.ts +3 -1
- package/dist/handlers/crudEvents.js +3 -2
- package/dist/handlers/eventValidation.js +6 -3
- package/dist/handlers/http.d.ts +2 -2
- package/dist/handlers/http.js +66 -43
- package/dist/handlers/jsonSchema.d.ts +1 -0
- package/dist/handlers/jsonSchema.js +72 -21
- package/dist/handlers/meta.d.ts +1 -1
- package/dist/handlers/meta.js +59 -10
- package/dist/handlers/requestReply.js +36 -9
- package/dist/index.d.ts +1 -1
- package/dist/presets/auth.d.ts +25 -0
- package/dist/presets/auth.js +855 -0
- package/dist/presets/cronExpression.d.ts +1 -0
- package/dist/presets/cronExpression.js +429 -0
- package/dist/presets/fileServer.d.ts +13 -0
- package/dist/presets/fileServer.js +399 -0
- package/dist/presets/gsf.d.ts +24 -0
- package/dist/presets/gsf.js +450 -0
- package/dist/presets/index.d.ts +1 -0
- package/dist/presets/index.js +1 -0
- package/dist/presets/javaTime.d.ts +7 -0
- package/dist/presets/javaTime.js +322 -0
- package/dist/presets/multipart.d.ts +14 -0
- package/dist/presets/multipart.js +91 -0
- package/dist/presets/notify.d.ts +27 -0
- package/dist/presets/notify.js +250 -0
- package/dist/presets/notifyDispatch.d.ts +28 -0
- package/dist/presets/notifyDispatch.js +570 -0
- package/dist/presets/notifyRules.d.ts +9 -0
- package/dist/presets/notifyRules.js +754 -0
- package/dist/presets/platform/backing.json +8058 -217
- package/dist/presets/platform/criteria-model.json +362 -0
- package/dist/presets/platform/time-zones.json +608 -0
- package/dist/presets/platform.d.ts +7 -0
- package/dist/presets/platform.js +145 -103
- package/dist/presets/products.d.ts +9 -7
- package/dist/presets/products.js +89 -21
- package/dist/presets/reconciliation.d.ts +18 -0
- package/dist/presets/reconciliation.js +721 -0
- package/dist/presets/reporting.d.ts +14 -0
- package/dist/presets/reporting.js +862 -0
- package/dist/protocol/connection.d.ts +2 -0
- package/dist/protocol/connection.js +4 -0
- package/dist/protocol/dtoTypes.d.ts +30 -0
- package/dist/protocol/dtoTypes.js +250 -0
- package/dist/protocol/errors.d.ts +3 -1
- package/dist/protocol/errors.js +2 -0
- package/dist/protocol/fieldTypes.js +5 -0
- package/dist/protocol/router.d.ts +1 -0
- package/dist/protocol/router.js +3 -3
- package/dist/protocol/schemaValidation.d.ts +1 -1
- package/dist/protocol/schemaValidation.js +53 -8
- package/dist/server.js +34 -2
- package/dist/types.d.ts +50 -2
- package/package.json +1 -1
- package/src/db/schema.ts +56 -13
- package/src/db/store.ts +5 -0
- package/src/handlers/auth.ts +211 -37
- package/src/handlers/commitEvent.ts +44 -19
- package/src/handlers/crudEvents.ts +9 -2
- package/src/handlers/eventValidation.ts +6 -3
- package/src/handlers/http.ts +83 -42
- package/src/handlers/jsonSchema.ts +86 -23
- package/src/handlers/meta.ts +77 -9
- package/src/handlers/requestReply.ts +42 -6
- package/src/index.ts +7 -0
- package/src/presets/auth.ts +961 -0
- package/src/presets/cronExpression.ts +445 -0
- package/src/presets/fileServer.ts +475 -0
- package/src/presets/gsf.ts +475 -0
- package/src/presets/index.ts +5 -0
- package/src/presets/javaTime.ts +354 -0
- package/src/presets/multipart.ts +110 -0
- package/src/presets/notify.ts +312 -0
- package/src/presets/notifyDispatch.ts +685 -0
- package/src/presets/notifyRules.ts +866 -0
- package/src/presets/platform/backing.json +8058 -217
- package/src/presets/platform/criteria-model.json +362 -0
- package/src/presets/platform/time-zones.json +608 -0
- package/src/presets/platform.ts +204 -115
- package/src/presets/products.ts +125 -19
- package/src/presets/reconciliation.ts +824 -0
- package/src/presets/reporting.ts +953 -0
- package/src/protocol/connection.ts +4 -0
- package/src/protocol/dtoTypes.ts +310 -0
- package/src/protocol/errors.ts +13 -1
- package/src/protocol/fieldTypes.ts +5 -0
- package/src/protocol/router.ts +3 -3
- package/src/protocol/schemaValidation.ts +61 -8
- package/src/server.ts +38 -2
- package/src/types.ts +147 -3
package/dist/presets/platform.js
CHANGED
|
@@ -9,11 +9,20 @@
|
|
|
9
9
|
// genesis-notify 8.15.16, reporting 8.15.3, file-server 8.15.9,
|
|
10
10
|
// reconciliation 8.15.4).
|
|
11
11
|
import { NackError } from "../protocol/errors.js";
|
|
12
|
+
import { authBacking, changePasswordRoute, hasRight } from "./auth.js";
|
|
13
|
+
import { fileServerBacking } from "./fileServer.js";
|
|
14
|
+
import { statusQueries, SYSTEM_STATUS_BYTES, systemInfoRequestReplies } from "./gsf.js";
|
|
15
|
+
import { notifyBacking } from "./notify.js";
|
|
16
|
+
import { DEFAULT_NOTIFY_GATEWAYS, dispatchBacking } from "./notifyDispatch.js";
|
|
17
|
+
import { ruleBacking } from "./notifyRules.js";
|
|
12
18
|
import defaultUser from './platform/default-user.json' with { type: 'json' };
|
|
13
19
|
import platformProfileRights from './platform/profile-rights.json' with { type: 'json' };
|
|
14
20
|
import platformProfiles from './platform/profiles.json' with { type: 'json' };
|
|
15
21
|
import platformRights from './platform/rights.json' with { type: 'json' };
|
|
16
|
-
import { includedProducts, ofIncluded, productBacking, productResources, } from "./products.js";
|
|
22
|
+
import { includedProducts, ofIncluded, platformTable, productBacking, productResources, typedRequestReply, } from "./products.js";
|
|
23
|
+
import { reconciliationBacking } from "./reconciliation.js";
|
|
24
|
+
import { reportingBacking } from "./reporting.js";
|
|
25
|
+
const RECONCILIATION_RUN_MS = 1000;
|
|
17
26
|
const DEFAULT_PASSWORD = 'admin';
|
|
18
27
|
// --- tables --------------------------------------------------------------------
|
|
19
28
|
const field = (name, type = 'STRING', more = {}) => ({
|
|
@@ -21,91 +30,53 @@ const field = (name, type = 'STRING', more = {}) => ({
|
|
|
21
30
|
type,
|
|
22
31
|
...more,
|
|
23
32
|
});
|
|
24
|
-
// USER
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
field('USER_NAME', 'STRING', { maxSize: 255 }),
|
|
42
|
-
field('USER_TYPE', 'ENUM', {
|
|
43
|
-
values: ['USER', 'ADVISOR', 'CLIENT', 'SYSTEM', 'API'],
|
|
44
|
-
default: 'USER',
|
|
45
|
-
}),
|
|
46
|
-
field('ACCESS_TYPE', 'ENUM', { values: ['ALL', 'ENTITY', 'MULTI_ENTITY'], default: 'ALL' }),
|
|
47
|
-
...['ADDRESS_LINE1', 'ADDRESS_LINE2', 'ADDRESS_LINE3', 'ADDRESS_LINE4'].map((name) => field(name, 'STRING', { maxSize: 400 })),
|
|
48
|
-
...[
|
|
49
|
-
'CITY',
|
|
50
|
-
'REGION',
|
|
51
|
-
'POSTAL_CODE',
|
|
52
|
-
'COUNTRY',
|
|
53
|
-
'TITLE',
|
|
54
|
-
'WEBSITE',
|
|
55
|
-
'MOBILE_NUMBER',
|
|
56
|
-
'TELEPHONE_NUMBER_DIRECT',
|
|
57
|
-
'TELEPHONE_NUMBER_OFFICE',
|
|
58
|
-
].map((name) => field(name)),
|
|
59
|
-
];
|
|
60
|
-
const fieldNames = (fields) => fields.map(({ name }) => name);
|
|
61
|
-
const USER_COLUMNS = new Set(fieldNames(USER_FIELDS));
|
|
62
|
-
const ATTRIBUTE_COLUMNS = new Set(fieldNames(USER_ATTRIBUTE_FIELDS));
|
|
63
|
-
// auth-tables-dictionary.kts (auth v8.15.5): KEY_VALUE :2, PROFILE :12,
|
|
64
|
-
// PROFILE_USER :22, RIGHT :46, PROFILE_RIGHT :54; types from
|
|
65
|
-
// auth-fields-dictionary.kts. NOTIFY_ALERT: genesis-notify-tables-dictionary.kts:112
|
|
66
|
-
// (genesis-notify v8.15.16), types from genesis-notify-fields-dictionary.kts.
|
|
33
|
+
// USER as GSF declares it (genesis-tables-dictionary.kts:360, v8.15.29) but
|
|
34
|
+
// for PASSWORD, which auth.ts keeps beside the store.
|
|
35
|
+
const userTable = () => {
|
|
36
|
+
const table = platformTable('USER');
|
|
37
|
+
return { ...table, fields: table.fields?.filter(({ name }) => name !== 'PASSWORD') };
|
|
38
|
+
};
|
|
39
|
+
// What a PlatformUser's `user` may set.
|
|
40
|
+
const columnsOf = (table) => new Set((table.fields ?? []).map(({ name }) => name));
|
|
41
|
+
const USER_COLUMNS = columnsOf(userTable());
|
|
42
|
+
const ATTRIBUTE_COLUMNS = columnsOf(platformTable('USER_ATTRIBUTES'));
|
|
43
|
+
// The users, profiles and rights, in GSF's and auth's own tables (their
|
|
44
|
+
// audits included): USER, USER_ATTRIBUTES and RIGHT_SUMMARY (GSF v8.15.29),
|
|
45
|
+
// PROFILE, PROFILE_USER, RIGHT and PROFILE_RIGHT (auth v8.15.5). A user's
|
|
46
|
+
// RIGHT_SUMMARY rows are their rights, as auth's consolidation keeps them.
|
|
47
|
+
// KEY_VALUE: auth-tables-dictionary.kts:2. NOTIFY_ALERT:
|
|
48
|
+
// genesis-notify-tables-dictionary.kts:112 (genesis-notify v8.15.16), types
|
|
49
|
+
// from genesis-notify-fields-dictionary.kts.
|
|
67
50
|
function platformTables(seed, users) {
|
|
68
51
|
return {
|
|
69
52
|
USER: {
|
|
70
|
-
|
|
71
|
-
fields: USER_FIELDS,
|
|
53
|
+
...userTable(),
|
|
72
54
|
rows: users.map(({ username, user = {} }) => ({
|
|
73
55
|
...pick(user, USER_COLUMNS),
|
|
74
56
|
USER_NAME: username,
|
|
57
|
+
STATUS: user.STATUS ?? 'ENABLED',
|
|
75
58
|
})),
|
|
76
59
|
},
|
|
77
60
|
USER_ATTRIBUTES: {
|
|
78
|
-
|
|
79
|
-
fields: USER_ATTRIBUTE_FIELDS,
|
|
61
|
+
...platformTable('USER_ATTRIBUTES'),
|
|
80
62
|
rows: users.map(({ username, user = {} }) => ({
|
|
81
63
|
...pick(user, ATTRIBUTE_COLUMNS),
|
|
82
64
|
USER_NAME: username,
|
|
83
65
|
})),
|
|
84
66
|
},
|
|
85
|
-
PROFILE: {
|
|
86
|
-
pkField: 'NAME',
|
|
87
|
-
fields: [
|
|
88
|
-
field('NAME', 'STRING', { maxSize: 255 }),
|
|
89
|
-
field('DESCRIPTION'),
|
|
90
|
-
field('STATUS'),
|
|
91
|
-
field('IS_PRIMARY', 'BOOLEAN', { nullable: false, default: true }),
|
|
92
|
-
],
|
|
93
|
-
rows: seed.PROFILE,
|
|
94
|
-
},
|
|
67
|
+
PROFILE: { ...platformTable('PROFILE'), rows: seed.PROFILE },
|
|
95
68
|
PROFILE_USER: {
|
|
96
|
-
|
|
97
|
-
fields: [field('PROFILE_NAME'), field('USER_NAME', 'STRING', { maxSize: 255 })],
|
|
69
|
+
...platformTable('PROFILE_USER'),
|
|
98
70
|
rows: users.flatMap(({ username, profile = [] }) => profile.map((PROFILE_NAME) => ({ PROFILE_NAME, USER_NAME: username }))),
|
|
99
71
|
},
|
|
100
|
-
RIGHT: {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
rows: seed.PROFILE_RIGHT,
|
|
72
|
+
RIGHT: { ...platformTable('RIGHT'), rows: seed.RIGHT },
|
|
73
|
+
PROFILE_RIGHT: { ...platformTable('PROFILE_RIGHT'), rows: seed.PROFILE_RIGHT },
|
|
74
|
+
RIGHT_SUMMARY: {
|
|
75
|
+
...platformTable('RIGHT_SUMMARY'),
|
|
76
|
+
rows: users.flatMap((user) => permissionOf(user, seed.PROFILE_RIGHT).map((RIGHT_CODE) => ({
|
|
77
|
+
USER_NAME: user.username,
|
|
78
|
+
RIGHT_CODE,
|
|
79
|
+
}))),
|
|
109
80
|
},
|
|
110
81
|
// USER_NAME, KV_KEY, KV_VALUE (RAW). Left undeclared: a declared table
|
|
111
82
|
// would have the engine check EVENT_KEY_VALUE_PUT's DETAILS against it,
|
|
@@ -113,9 +84,10 @@ function platformTables(seed, users) {
|
|
|
113
84
|
KEY_VALUE: { pkField: ['USER_NAME', 'KV_KEY'], rows: seed.KEY_VALUE },
|
|
114
85
|
NOTIFY_ALERT: {
|
|
115
86
|
pkField: 'ALERT_ID',
|
|
116
|
-
// sequence(ALERT_ID, "AL")
|
|
87
|
+
// sequence(ALERT_ID, "AL"), audit = details(..., sequence = "NA")
|
|
117
88
|
sequencePrefix: 'AL',
|
|
118
89
|
sequenceFormat: 'genesis',
|
|
90
|
+
audit: { sequencePrefix: 'NA' },
|
|
119
91
|
fields: [
|
|
120
92
|
field('ALERT_ID'),
|
|
121
93
|
field('MESSAGE'),
|
|
@@ -265,11 +237,13 @@ function alertHandlers(fallback) {
|
|
|
265
237
|
};
|
|
266
238
|
}
|
|
267
239
|
// --- the preset ------------------------------------------------------------------
|
|
268
|
-
// A user's rights: their profiles' PROFILE_RIGHT codes,
|
|
269
|
-
// login ack lists them.
|
|
270
|
-
function
|
|
240
|
+
// A user's rights: `permission`, else their profiles' PROFILE_RIGHT codes,
|
|
241
|
+
// sorted as the real login ack lists them.
|
|
242
|
+
function permissionOf({ profile = [], permission }, profileRights) {
|
|
243
|
+
if (permission)
|
|
244
|
+
return permission;
|
|
271
245
|
const codes = profileRights
|
|
272
|
-
.filter((row) =>
|
|
246
|
+
.filter((row) => profile.includes(row.PROFILE_NAME))
|
|
273
247
|
.map((row) => row.RIGHT_CODE);
|
|
274
248
|
return [...new Set(codes)].sort();
|
|
275
249
|
}
|
|
@@ -303,12 +277,16 @@ export function platformPreset(options = {}) {
|
|
|
303
277
|
NOTIFY_ALERT: options.seed?.NOTIFY_ALERT ?? [],
|
|
304
278
|
KEY_VALUE: options.seed?.KEY_VALUE ?? [],
|
|
305
279
|
};
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
280
|
+
// What the users log in as at first. Logins read the store
|
|
281
|
+
// (authDirectory), so they follow what auth's events change; these name the
|
|
282
|
+
// user httpAutoLogin: true logs in as.
|
|
283
|
+
const authUsers = users.map((platformUser) => ({
|
|
284
|
+
username: platformUser.username,
|
|
285
|
+
password: platformUser.password,
|
|
286
|
+
profile: [...(platformUser.profile ?? [])].sort(),
|
|
287
|
+
permission: permissionOf(platformUser, seed.PROFILE_RIGHT),
|
|
288
|
+
user: platformUser.user && pick(platformUser.user, LOGIN_USER_FIELDS),
|
|
289
|
+
status: platformUser.user?.STATUS ?? 'ENABLED',
|
|
312
290
|
}));
|
|
313
291
|
// NOTIFY_ALERT is genesis-notify's; the rest are GSF's and auth's.
|
|
314
292
|
const { NOTIFY_ALERT, ...always } = platformTables(seed, users);
|
|
@@ -316,25 +294,43 @@ export function platformPreset(options = {}) {
|
|
|
316
294
|
// What the included products' screens read, generated from their scripts;
|
|
317
295
|
// the pieces written out here replace any of the same name.
|
|
318
296
|
const generated = productBacking(included, tables);
|
|
297
|
+
const notifyEvents = notifyBacking();
|
|
298
|
+
const notifyUsers = {
|
|
299
|
+
userOf: (ctx) => sessionUserOf(ctx.connection.userName, fallback),
|
|
300
|
+
fallback,
|
|
301
|
+
hasRight: (store, name, code) => name !== undefined && hasRight(store, name, code),
|
|
302
|
+
};
|
|
303
|
+
const auth = authBacking({
|
|
304
|
+
userOf: notifyUsers.userOf,
|
|
305
|
+
fixedRights: new Map(users.flatMap(({ username, permission }) => permission ? [[username, permission]] : [])),
|
|
306
|
+
passwords: new Map(users.flatMap(({ username, password }) => password === undefined ? [] : [[username, password]])),
|
|
307
|
+
});
|
|
308
|
+
const notifyRules = ruleBacking(notifyUsers);
|
|
309
|
+
const notifyDispatch = dispatchBacking({
|
|
310
|
+
users: notifyUsers,
|
|
311
|
+
gateways: options.notifyGateways ?? DEFAULT_NOTIFY_GATEWAYS,
|
|
312
|
+
entities: options.notifyEntities,
|
|
313
|
+
});
|
|
314
|
+
const fileServer = fileServerBacking();
|
|
315
|
+
const files = included.has('file-server');
|
|
316
|
+
const reconciliation = reconciliationBacking({
|
|
317
|
+
userOf: notifyUsers.userOf,
|
|
318
|
+
runMs: options.reconciliationRunMs ?? RECONCILIATION_RUN_MS,
|
|
319
|
+
pipelines: options.reconciliationPipelines,
|
|
320
|
+
fileContent: files ? fileServer.fileContent : undefined,
|
|
321
|
+
});
|
|
322
|
+
const reporting = reportingBacking({
|
|
323
|
+
userOf: notifyUsers.userOf,
|
|
324
|
+
timeZone: options.reportingTimeZone,
|
|
325
|
+
datasources: options.reportingDatasources,
|
|
326
|
+
notify: notify ? notifyDispatch.raise : undefined,
|
|
327
|
+
});
|
|
319
328
|
return {
|
|
320
329
|
tables: { ...generated.tables, ...tables },
|
|
321
330
|
views: {
|
|
322
331
|
...generated.views,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
USER_VIEW: {
|
|
326
|
-
base: 'USER',
|
|
327
|
-
joins: [
|
|
328
|
-
{
|
|
329
|
-
table: 'USER_ATTRIBUTES',
|
|
330
|
-
on: ['USER_NAME', 'USER_NAME'],
|
|
331
|
-
backwardsJoin: true,
|
|
332
|
-
select: Object.fromEntries([...ATTRIBUTE_COLUMNS]
|
|
333
|
-
.filter((name) => name !== 'USER_NAME')
|
|
334
|
-
.map((name) => [name, name])),
|
|
335
|
-
},
|
|
336
|
-
],
|
|
337
|
-
},
|
|
332
|
+
...auth.views,
|
|
333
|
+
SYSTEM_STATUS_BYTES,
|
|
338
334
|
// auth-view-dictionary.kts (auth v8.15.5) :50 and :65.
|
|
339
335
|
PROFILE_RIGHT_VIEW: {
|
|
340
336
|
base: 'PROFILE_RIGHT',
|
|
@@ -369,13 +365,32 @@ export function platformPreset(options = {}) {
|
|
|
369
365
|
// The preset's own, over the generated ones, for the included products.
|
|
370
366
|
queries: {
|
|
371
367
|
...generated.queries,
|
|
372
|
-
...ofIncluded(ownQueries(fallback), 'DATASERVER', included),
|
|
368
|
+
...ofIncluded({ ...ownQueries(fallback), ...statusQueries(), ...notifyRules.queries }, 'DATASERVER', included),
|
|
373
369
|
},
|
|
374
|
-
requestReplies: {
|
|
370
|
+
requestReplies: typedWhereTheyAre({
|
|
375
371
|
...generated.requestReplies,
|
|
376
|
-
...ofIncluded(
|
|
377
|
-
|
|
378
|
-
|
|
372
|
+
...ofIncluded({
|
|
373
|
+
...ownRequestReplies(fallback),
|
|
374
|
+
...systemInfoRequestReplies(),
|
|
375
|
+
...auth.requestReplies,
|
|
376
|
+
...notifyRules.requestReplies,
|
|
377
|
+
...notifyDispatch.requestReplies,
|
|
378
|
+
...reporting.requestReplies,
|
|
379
|
+
...reconciliation.requestReplies,
|
|
380
|
+
...fileServer.requestReplies,
|
|
381
|
+
}, 'REQUEST_SERVER', included),
|
|
382
|
+
}),
|
|
383
|
+
eventHandlers: ofIncluded({
|
|
384
|
+
...keyValueHandlers(fallback),
|
|
385
|
+
...auth.eventHandlers,
|
|
386
|
+
...alertHandlers(fallback),
|
|
387
|
+
...notifyEvents.eventHandlers,
|
|
388
|
+
...notifyRules.eventHandlers,
|
|
389
|
+
...notifyDispatch.eventHandlers,
|
|
390
|
+
...reporting.eventHandlers,
|
|
391
|
+
...reconciliation.eventHandlers,
|
|
392
|
+
...fileServer.eventHandlers,
|
|
393
|
+
}, 'EVENT_HANDLER', included),
|
|
379
394
|
// The DETAILS classes of the alert events, which their names alone would
|
|
380
395
|
// make NOTIFY_ALERT table events.
|
|
381
396
|
eventSchemas: ofIncluded({
|
|
@@ -385,11 +400,29 @@ export function platformPreset(options = {}) {
|
|
|
385
400
|
className: 'global.genesis.gen.dao.NotifyAlert.ByAlertId',
|
|
386
401
|
},
|
|
387
402
|
EVENT_DISMISS_ALL_NOTIFY_ALERT: { fields: [], className: 'kotlin.Unit' },
|
|
403
|
+
...auth.eventSchemas,
|
|
404
|
+
...notifyEvents.eventSchemas,
|
|
405
|
+
...notifyRules.eventSchemas,
|
|
406
|
+
...notifyDispatch.eventSchemas,
|
|
407
|
+
...reporting.eventSchemas,
|
|
408
|
+
...reconciliation.eventSchemas,
|
|
409
|
+
...fileServer.eventSchemas,
|
|
388
410
|
}, 'EVENT_HANDLER', included),
|
|
389
|
-
auth: { users: authUsers },
|
|
411
|
+
auth: { users: authUsers, directory: auth.directory },
|
|
412
|
+
// auth's change of password, which an expired-password login needs, and
|
|
413
|
+
// file-server's endpoints.
|
|
414
|
+
httpRoutes: [changePasswordRoute, ...(files ? fileServer.httpRoutes : [])],
|
|
390
415
|
additionalResources: [...productResources(included), ...(options.resources ?? [])],
|
|
391
416
|
};
|
|
392
417
|
}
|
|
418
|
+
// The products' typed request servers (requestReply<In, Out>) say so: their
|
|
419
|
+
// META as GSF builds it, PARAMETRIC_TYPE and MAX_ROWS (RequestReplyDef.typed).
|
|
420
|
+
function typedWhereTheyAre(requestReplies) {
|
|
421
|
+
return Object.fromEntries(Object.entries(requestReplies).map(([name, definition]) => {
|
|
422
|
+
const typed = typedRequestReply(name);
|
|
423
|
+
return [name, typed ? { ...definition, typed } : definition];
|
|
424
|
+
}));
|
|
425
|
+
}
|
|
393
426
|
// auth-dataserver.kts (auth v8.15.5) and genesis-notify-rules-dataserver.kts
|
|
394
427
|
// (genesis-notify v8.15.16): the ones the generated backing can't say, as
|
|
395
428
|
// they rename columns or filter the alerts by user.
|
|
@@ -412,9 +445,18 @@ function ownQueries(fallback) {
|
|
|
412
445
|
},
|
|
413
446
|
};
|
|
414
447
|
}
|
|
415
|
-
// auth-reqrep.kts (auth v8.15.5): the ones that rename columns
|
|
416
|
-
|
|
448
|
+
// auth-reqrep.kts (auth v8.15.5): the ones that rename columns; and
|
|
449
|
+
// genesis-notify-rules-reqrep.kts (genesis-notify v8.15.16) :162, which filters
|
|
450
|
+
// the alerts' audit by user.
|
|
451
|
+
function ownRequestReplies(fallback) {
|
|
417
452
|
return {
|
|
453
|
+
// requestReply("NOTIFY_ALERT", NOTIFY_ALERT_AUDIT) { permissioning { auth {
|
|
454
|
+
// filterWithUserName { userName == data.userName } } } }
|
|
455
|
+
NOTIFY_ALERT: {
|
|
456
|
+
source: 'NOTIFY_ALERT_AUDIT',
|
|
457
|
+
requestFields: ['NOTIFY_ALERT_AUDIT_ID'],
|
|
458
|
+
auth: { rowFilter: (row, user) => row.USER_NAME === (user.userName ?? fallback) },
|
|
459
|
+
},
|
|
418
460
|
// :57 request { CODE } reply { CODE DESCRIPTION }, so its rows carry no
|
|
419
461
|
// RECORD_ID.
|
|
420
462
|
RIGHT: { source: 'RIGHT', fields: ['CODE', 'DESCRIPTION'] },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MockServerConfig, ResourceItem, TableDef } from '../types.ts';
|
|
1
|
+
import type { MockServerConfig, ResourceItem, TableDef, TypedRequestReply } from '../types.ts';
|
|
2
2
|
/**
|
|
3
3
|
* A platform product an app may include beside GSF and auth, by its GSF
|
|
4
4
|
* product name: Create's Notifications, Reporting, Document Management and
|
|
@@ -10,14 +10,16 @@ export declare function includedProducts(products?: readonly string[]): Set<stri
|
|
|
10
10
|
export declare function productOf(type: ResourceItem['RESOURCE_TYPE'], name: string): string | undefined;
|
|
11
11
|
export declare function productResources(included: Set<string>): ResourceItem[];
|
|
12
12
|
export declare function ofIncluded<T>(record: Record<string, T>, type: ResourceItem['RESOURCE_TYPE'], included: Set<string>): Record<string, T>;
|
|
13
|
+
export declare function platformTable(name: string): TableDef;
|
|
14
|
+
export declare const isPlatformTable: (name: string) => boolean;
|
|
15
|
+
export declare const aliasedEnumKeys: (table: string, field: string) => string[] | undefined;
|
|
16
|
+
export declare const fieldFormat: (field: string) => string | undefined;
|
|
17
|
+
export declare const typedRequestReply: (name: string) => TypedRequestReply | undefined;
|
|
13
18
|
/**
|
|
14
19
|
* The generated backing for the included products, a fresh copy each call:
|
|
15
20
|
* their queries and request servers over a table or view, those tables
|
|
16
|
-
* (empty, or holding the product's own seed rows) and views
|
|
17
|
-
* the
|
|
18
|
-
*
|
|
19
|
-
* by platform processes the mock doesn't run, so an empty table would be a
|
|
20
|
-
* wrong answer rather than a fresh one. A table in `presetTables` is the
|
|
21
|
-
* caller's, and isn't repeated here.
|
|
21
|
+
* (empty, or holding the product's own seed rows) and their views, read or
|
|
22
|
+
* not, as the real dictionary holds them all. A table in `presetTables` is
|
|
23
|
+
* the caller's, and isn't repeated here.
|
|
22
24
|
*/
|
|
23
25
|
export declare function productBacking(included: Set<string>, presetTables: Record<string, TableDef>): Pick<MockServerConfig, 'tables' | 'views' | 'queries' | 'requestReplies'>;
|
package/dist/presets/products.js
CHANGED
|
@@ -43,33 +43,101 @@ export function ofIncluded(record, type, included) {
|
|
|
43
43
|
return product === undefined || included.has(product);
|
|
44
44
|
}));
|
|
45
45
|
}
|
|
46
|
-
//
|
|
47
|
-
|
|
46
|
+
// 'genesis-notify@8.15.16' -> 'genesis-notify'.
|
|
47
|
+
const productOfOrigin = (origin) => origin.slice(0, origin.lastIndexOf('@'));
|
|
48
|
+
const input = (sources, table, field) => sources.tables[table]?.[field] ?? null;
|
|
49
|
+
const DERIVED = {
|
|
50
|
+
// genesis-notify-view-dictionary.kts:117: timestamp!!.shr(22)
|
|
51
|
+
DYNAMIC_RULE_VIEW: { DATETIME: (_row, s) => input(s, 'DYNAMIC_RULE', 'TIMESTAMP') },
|
|
52
|
+
// reporting-view-dictionary.kts:42-64
|
|
53
|
+
GENERATED_REPORT_VIEW: {
|
|
54
|
+
LAST_UPDATED_AT: (_row, s) => input(s, 'GENERATED_REPORT', 'TIMESTAMP'),
|
|
55
|
+
FILE_NAME: (_row, s) => {
|
|
56
|
+
const name = input(s, 'GENERATED_REPORT', 'FILE_NAME');
|
|
57
|
+
// Status.GENERATED, whose label the column holds.
|
|
58
|
+
if (input(s, 'GENERATED_REPORT', 'STATUS') !== 'Generated')
|
|
59
|
+
return name;
|
|
60
|
+
const configName = input(s, 'REPORT_CONFIG', 'FILE_NAME');
|
|
61
|
+
const format = input(s, 'REPORT_CONFIG', 'OUTPUT_FORMAT');
|
|
62
|
+
return (name ??
|
|
63
|
+
(configName !== null && format !== null
|
|
64
|
+
? `${configName}.${String(format).toLowerCase()}`
|
|
65
|
+
: null));
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
// reconciliation-view-dictionary.kts:30-38: the start, else the timestamp.
|
|
69
|
+
RECONCILIATION_VIEW: {
|
|
70
|
+
DATETIME: (_row, s) => {
|
|
71
|
+
const start = input(s, 'RECONCILIATION', 'START_TIMESTAMP');
|
|
72
|
+
return start === null || start === 0 ? input(s, 'RECONCILIATION', 'TIMESTAMP') : start;
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
// :59-63: the comment's timestamp.
|
|
76
|
+
RECONCILIATION_RECORD_RESULT_VIEW: {
|
|
77
|
+
DATETIME: (_row, s) => input(s, 'RECONCILIATION_RECORD_RESULT_COMMENT', 'TIMESTAMP'),
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
// A derived field the list above doesn't know is declared, and null.
|
|
48
81
|
const unmodelledValue = () => null;
|
|
82
|
+
// A platform table as its product's dictionary declares it (fields, key,
|
|
83
|
+
// indexes, sequence, audit), a fresh copy, for the preset to fill.
|
|
84
|
+
export function platformTable(name) {
|
|
85
|
+
const { dictionary: _dictionary, ...table } = structuredClone(backing.tables[name]);
|
|
86
|
+
return table;
|
|
87
|
+
}
|
|
88
|
+
export const isPlatformTable = (name) => Object.hasOwn(backing.tables, name);
|
|
89
|
+
// An ALIASED_ENUM column's keys, in its labels' order; undefined for any
|
|
90
|
+
// other column.
|
|
91
|
+
export const aliasedEnumKeys = (table, field) => backing.aliasedEnums[`${table}.${field}`];
|
|
92
|
+
// A platform RAW field's format (BASE_64, UTF_8), if it has one.
|
|
93
|
+
export const fieldFormat = (field) => backing.fieldFormats[field];
|
|
94
|
+
// A product's typed request server (requestReply<In, Out>), a fresh copy, if
|
|
95
|
+
// `name` is one.
|
|
96
|
+
export const typedRequestReply = (name) => Object.hasOwn(backing.typedRequestReplies, name)
|
|
97
|
+
? structuredClone(backing.typedRequestReplies[name])
|
|
98
|
+
: undefined;
|
|
99
|
+
const AUDIT_SUFFIX = '_AUDIT';
|
|
49
100
|
/**
|
|
50
101
|
* The generated backing for the included products, a fresh copy each call:
|
|
51
102
|
* their queries and request servers over a table or view, those tables
|
|
52
|
-
* (empty, or holding the product's own seed rows) and views
|
|
53
|
-
* the
|
|
54
|
-
*
|
|
55
|
-
* by platform processes the mock doesn't run, so an empty table would be a
|
|
56
|
-
* wrong answer rather than a fresh one. A table in `presetTables` is the
|
|
57
|
-
* caller's, and isn't repeated here.
|
|
103
|
+
* (empty, or holding the product's own seed rows) and their views, read or
|
|
104
|
+
* not, as the real dictionary holds them all. A table in `presetTables` is
|
|
105
|
+
* the caller's, and isn't repeated here.
|
|
58
106
|
*/
|
|
59
107
|
export function productBacking(included, presetTables) {
|
|
60
|
-
|
|
61
|
-
|
|
108
|
+
// Every table of an included product, which its event handlers write; a
|
|
109
|
+
// query or request server reads some. An audit table is the engine's to
|
|
110
|
+
// derive from its table's `audit`.
|
|
111
|
+
const tables = new Set(Object.entries(backing.tables)
|
|
112
|
+
.filter(([, table]) => included.has(productOfOrigin(table.dictionary)))
|
|
113
|
+
.map(([name]) => name));
|
|
114
|
+
// A table the app has: a preset or product one, or the audit table the
|
|
115
|
+
// engine derives from an audited one.
|
|
116
|
+
const definitionOf = (name) => presetTables[name] ?? (tables.has(name) ? backing.tables[name] : undefined);
|
|
117
|
+
const hasTable = (name) => definitionOf(name) !== undefined ||
|
|
118
|
+
(name.endsWith(AUDIT_SUFFIX) &&
|
|
119
|
+
Boolean(definitionOf(name.slice(0, -AUDIT_SUFFIX.length))?.audit));
|
|
120
|
+
const views = new Set(Object.entries(backing.views)
|
|
121
|
+
.filter(([, view]) => included.has(productOfOrigin(view.dictionary)) &&
|
|
122
|
+
[view.base, ...(view.joins ?? []).map(({ table }) => table)].every(hasTable))
|
|
123
|
+
.map(([name]) => name));
|
|
62
124
|
const pick = (entries) => Object.fromEntries(Object.entries(entries).flatMap(([name, entry]) => {
|
|
63
|
-
const { product, script: _script, reads, unmodelled: _unmodelled, ...definition } = structuredClone(entry);
|
|
125
|
+
const { product, script: _script, reads: _reads, unmodelled: _unmodelled, ...definition } = structuredClone(entry);
|
|
64
126
|
if (!included.has(product))
|
|
65
127
|
return [];
|
|
66
|
-
if (ALWAYS.includes(product) && !reads.every((table) => table in presetTables))
|
|
67
|
-
return [];
|
|
68
|
-
for (const table of reads)
|
|
69
|
-
tables.add(table);
|
|
70
128
|
const { source } = definition;
|
|
71
|
-
|
|
129
|
+
// A source the app can't build is never served, should a product
|
|
130
|
+
// read another's view or table.
|
|
131
|
+
if (source && source in backing.views) {
|
|
132
|
+
const view = backing.views[source];
|
|
133
|
+
if (![view.base, ...(view.joins ?? []).map(({ table }) => table)].every(hasTable)) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
72
136
|
views.add(source);
|
|
137
|
+
}
|
|
138
|
+
else if (source && !hasTable(source)) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
73
141
|
return [[name, definition]];
|
|
74
142
|
}));
|
|
75
143
|
const queries = pick(backing.queries);
|
|
@@ -77,15 +145,15 @@ export function productBacking(included, presetTables) {
|
|
|
77
145
|
return {
|
|
78
146
|
tables: Object.fromEntries([...tables]
|
|
79
147
|
.filter((name) => !(name in presetTables))
|
|
80
|
-
.map((name) =>
|
|
81
|
-
const { dictionary: _dictionary, ...table } = structuredClone(backing.tables[name]);
|
|
82
|
-
return [name, table];
|
|
83
|
-
})),
|
|
148
|
+
.map((name) => [name, platformTable(name)])),
|
|
84
149
|
views: Object.fromEntries([...views].map((name) => {
|
|
85
150
|
const { dictionary: _dictionary, derivedTypes, ...view } = structuredClone(backing.views[name]);
|
|
86
151
|
const derived = derivedTypes && {
|
|
87
152
|
derivedTypes: derivedTypes,
|
|
88
|
-
derived: Object.fromEntries(Object.keys(derivedTypes).map((field) => [
|
|
153
|
+
derived: Object.fromEntries(Object.keys(derivedTypes).map((field) => [
|
|
154
|
+
field,
|
|
155
|
+
DERIVED[name]?.[field] ?? unmodelledValue,
|
|
156
|
+
])),
|
|
89
157
|
};
|
|
90
158
|
return [name, { ...view, ...derived }];
|
|
91
159
|
})),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EventHandler, EventHandlerCtx, EventSchemaOverride, RequestReplyDef } from '../types.ts';
|
|
2
|
+
export type FileContent = (store: EventHandlerCtx['store'], fileStorageId: string) => {
|
|
3
|
+
fileName: string;
|
|
4
|
+
} | {
|
|
5
|
+
error: string;
|
|
6
|
+
};
|
|
7
|
+
export interface ReconciliationOptions {
|
|
8
|
+
userOf(ctx: EventHandlerCtx): string;
|
|
9
|
+
runMs: number;
|
|
10
|
+
pipelines?: string[];
|
|
11
|
+
fileContent?: FileContent;
|
|
12
|
+
}
|
|
13
|
+
export interface ReconciliationBacking {
|
|
14
|
+
eventHandlers: Record<string, EventHandler>;
|
|
15
|
+
eventSchemas: Record<string, EventSchemaOverride>;
|
|
16
|
+
requestReplies: Record<string, RequestReplyDef>;
|
|
17
|
+
}
|
|
18
|
+
export declare function reconciliationBacking(options: ReconciliationOptions): ReconciliationBacking;
|