@genesislcap/mock-server 15.74.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.
Files changed (100) hide show
  1. package/README.md +296 -58
  2. package/dist/db/schema.d.ts +9 -1
  3. package/dist/db/schema.js +40 -11
  4. package/dist/db/store.d.ts +1 -0
  5. package/dist/db/store.js +4 -0
  6. package/dist/handlers/auth.d.ts +15 -6
  7. package/dist/handlers/auth.js +152 -33
  8. package/dist/handlers/commitEvent.js +43 -20
  9. package/dist/handlers/crudEvents.d.ts +3 -1
  10. package/dist/handlers/crudEvents.js +3 -2
  11. package/dist/handlers/eventValidation.js +6 -3
  12. package/dist/handlers/http.d.ts +2 -2
  13. package/dist/handlers/http.js +66 -43
  14. package/dist/handlers/jsonSchema.d.ts +1 -0
  15. package/dist/handlers/jsonSchema.js +72 -21
  16. package/dist/handlers/meta.d.ts +1 -1
  17. package/dist/handlers/meta.js +59 -10
  18. package/dist/handlers/requestReply.js +36 -9
  19. package/dist/index.d.ts +1 -1
  20. package/dist/presets/auth.d.ts +25 -0
  21. package/dist/presets/auth.js +855 -0
  22. package/dist/presets/cronExpression.d.ts +1 -0
  23. package/dist/presets/cronExpression.js +429 -0
  24. package/dist/presets/fileServer.d.ts +13 -0
  25. package/dist/presets/fileServer.js +399 -0
  26. package/dist/presets/gsf.d.ts +24 -0
  27. package/dist/presets/gsf.js +450 -0
  28. package/dist/presets/index.d.ts +1 -0
  29. package/dist/presets/index.js +1 -0
  30. package/dist/presets/javaTime.d.ts +7 -0
  31. package/dist/presets/javaTime.js +322 -0
  32. package/dist/presets/multipart.d.ts +14 -0
  33. package/dist/presets/multipart.js +91 -0
  34. package/dist/presets/notify.d.ts +27 -0
  35. package/dist/presets/notify.js +250 -0
  36. package/dist/presets/notifyDispatch.d.ts +28 -0
  37. package/dist/presets/notifyDispatch.js +570 -0
  38. package/dist/presets/notifyRules.d.ts +9 -0
  39. package/dist/presets/notifyRules.js +754 -0
  40. package/dist/presets/platform/backing.json +8058 -217
  41. package/dist/presets/platform/criteria-model.json +362 -0
  42. package/dist/presets/platform/time-zones.json +608 -0
  43. package/dist/presets/platform.d.ts +7 -0
  44. package/dist/presets/platform.js +145 -103
  45. package/dist/presets/products.d.ts +9 -7
  46. package/dist/presets/products.js +89 -21
  47. package/dist/presets/reconciliation.d.ts +18 -0
  48. package/dist/presets/reconciliation.js +721 -0
  49. package/dist/presets/reporting.d.ts +14 -0
  50. package/dist/presets/reporting.js +862 -0
  51. package/dist/protocol/connection.d.ts +2 -0
  52. package/dist/protocol/connection.js +4 -0
  53. package/dist/protocol/dtoTypes.d.ts +30 -0
  54. package/dist/protocol/dtoTypes.js +250 -0
  55. package/dist/protocol/errors.d.ts +3 -1
  56. package/dist/protocol/errors.js +2 -0
  57. package/dist/protocol/fieldTypes.js +5 -0
  58. package/dist/protocol/router.d.ts +1 -0
  59. package/dist/protocol/router.js +3 -3
  60. package/dist/protocol/schemaValidation.d.ts +1 -1
  61. package/dist/protocol/schemaValidation.js +53 -8
  62. package/dist/server.js +34 -2
  63. package/dist/types.d.ts +50 -2
  64. package/package.json +1 -1
  65. package/src/db/schema.ts +56 -13
  66. package/src/db/store.ts +5 -0
  67. package/src/handlers/auth.ts +211 -37
  68. package/src/handlers/commitEvent.ts +44 -19
  69. package/src/handlers/crudEvents.ts +9 -2
  70. package/src/handlers/eventValidation.ts +6 -3
  71. package/src/handlers/http.ts +83 -42
  72. package/src/handlers/jsonSchema.ts +86 -23
  73. package/src/handlers/meta.ts +77 -9
  74. package/src/handlers/requestReply.ts +42 -6
  75. package/src/index.ts +7 -0
  76. package/src/presets/auth.ts +961 -0
  77. package/src/presets/cronExpression.ts +445 -0
  78. package/src/presets/fileServer.ts +475 -0
  79. package/src/presets/gsf.ts +475 -0
  80. package/src/presets/index.ts +5 -0
  81. package/src/presets/javaTime.ts +354 -0
  82. package/src/presets/multipart.ts +110 -0
  83. package/src/presets/notify.ts +312 -0
  84. package/src/presets/notifyDispatch.ts +685 -0
  85. package/src/presets/notifyRules.ts +866 -0
  86. package/src/presets/platform/backing.json +8058 -217
  87. package/src/presets/platform/criteria-model.json +362 -0
  88. package/src/presets/platform/time-zones.json +608 -0
  89. package/src/presets/platform.ts +204 -115
  90. package/src/presets/products.ts +125 -19
  91. package/src/presets/reconciliation.ts +824 -0
  92. package/src/presets/reporting.ts +953 -0
  93. package/src/protocol/connection.ts +4 -0
  94. package/src/protocol/dtoTypes.ts +310 -0
  95. package/src/protocol/errors.ts +13 -1
  96. package/src/protocol/fieldTypes.ts +5 -0
  97. package/src/protocol/router.ts +3 -3
  98. package/src/protocol/schemaValidation.ts +61 -8
  99. package/src/server.ts +38 -2
  100. package/src/types.ts +147 -3
@@ -0,0 +1,312 @@
1
+ // genesis-notify's event handlers and computed request servers, as the
2
+ // product's scripts at the version the showcase pins run them
3
+ // (genesis-notify v8.15.16, scripts/platform-preset/seeds/genesis-notify@8.15.16/
4
+ // scripts: genesis-notify-eventhandler.kts below as EH). Each DTO's fields come
5
+ // from the product's messages jar (global.genesis.notify.message.event.*).
6
+ // What happens outside the database (email, Teams, Slack, a log line) isn't
7
+ // modelled: an event validates, writes its rows and acks.
8
+ import type { Store } from '../db/store.ts';
9
+ import { NackError } from '../protocol/errors.ts';
10
+ import type {
11
+ EventHandler,
12
+ EventHandlerCtx,
13
+ EventSchemaOverride,
14
+ FieldDef,
15
+ Row,
16
+ } from '../types.ts';
17
+
18
+ const ENTITY_ID_TYPES = ['USER_NAME', 'PROFILE_NAME', 'ALL', 'SELF'];
19
+ // The package the product's enums are generated in: their DTOs take
20
+ // global.genesis.gen.dao.enums.EntityIdType, not a table's own.
21
+ export const ENUMS = 'global.genesis.gen.dao.enums';
22
+
23
+ export const TTL_TIME_UNITS = ['NONE', 'SECONDS', 'MINUTES', 'HOURS', 'DAYS'];
24
+
25
+ // A DTO property. `optional`: it has a Kotlin default (which metadata doesn't
26
+ // show), so DETAILS may leave it out.
27
+ export const dto = (
28
+ name: string,
29
+ type: FieldDef['type'],
30
+ more: Partial<FieldDef> = {},
31
+ ): FieldDef => ({
32
+ name,
33
+ type,
34
+ nullable: false,
35
+ ...more,
36
+ });
37
+ export const nullable = { nullable: true, optional: true };
38
+
39
+ // GSF checks rights by user name in its rights cache (`userHasRight`), a live
40
+ // copy of RIGHT_SUMMARY, for the event's user and for anyone else alike.
41
+ export interface NotifyUsers {
42
+ // Who an event runs as: its connection's login, else the session user.
43
+ userOf(ctx: EventHandlerCtx): string;
44
+ // Who a request runs as when its connection never logged in.
45
+ fallback: string | undefined;
46
+ hasRight(store: Store, userName: string | undefined, code: string): boolean;
47
+ }
48
+
49
+ // RouteCreate (NotifyRouteCreate.kt): every route DTO's own four.
50
+ const ROUTE_FIELDS: FieldDef[] = [
51
+ dto('GATEWAY_ID', 'STRING'),
52
+ dto('TOPIC_MATCH', 'STRING'),
53
+ dto('ROUTE_ENABLED', 'BOOLEAN', { optional: true }),
54
+ dto('DISPLAY_NAME', 'STRING', nullable),
55
+ ];
56
+
57
+ const entityIdType = () =>
58
+ dto('ENTITY_ID_TYPE', 'ENUM', { values: ENTITY_ID_TYPES, enumClass: `${ENUMS}.EntityIdType` });
59
+
60
+ // A route family: its events' name part, its ext table, the view its grid
61
+ // and its delete DTO (`<View>.ById`) are named after, its DTOs' own fields,
62
+ // and its ext row as a create or an update writes it from DETAILS.
63
+ interface RouteFamily {
64
+ events: string;
65
+ ext: string;
66
+ view: string;
67
+ createClass: string;
68
+ updateClass: string;
69
+ createFields: FieldDef[];
70
+ updateFields?: FieldDef[];
71
+ extRow(details: Row): Row;
72
+ }
73
+
74
+ const or = <T>(value: T | undefined | null, fallback: T) => value ?? fallback;
75
+ // A Set<String> joined as EH stores it: `set?.joinToString(",") ?: ""`. A
76
+ // string is a one-element set (Jackson's ACCEPT_SINGLE_VALUE_AS_ARRAY).
77
+ const joined = (value: unknown) =>
78
+ Array.isArray(value) ? value.join(',') : typeof value === 'string' ? value : '';
79
+ export const stringSet = {
80
+ type: 'ARRAY' as const,
81
+ items: { type: 'STRING' as const },
82
+ unique: true,
83
+ };
84
+
85
+ export const EVENT_CLASS = 'global.genesis.notify.message.event';
86
+
87
+ const ROUTE_FAMILIES: RouteFamily[] = [
88
+ {
89
+ // EH :45, :74, :106
90
+ events: 'SCREEN_NOTIFY_ROUTE',
91
+ ext: 'SCREEN_NOTIFY_ROUTE_EXT',
92
+ view: 'ScreenRoute',
93
+ createClass: `${EVENT_CLASS}.ScreenRouteCreate`,
94
+ updateClass: `${EVENT_CLASS}.ScreenRouteUpdate`,
95
+ createFields: [
96
+ dto('ENTITY_ID', 'STRING', nullable),
97
+ entityIdType(),
98
+ dto('TTL', 'LONG', nullable),
99
+ dto('TTL_TIME_UNIT', 'ENUM', {
100
+ values: TTL_TIME_UNITS,
101
+ enumClass: `${ENUMS}.TtlTimeUnit`,
102
+ optional: true,
103
+ }),
104
+ dto('RIGHT_CODE', 'STRING', nullable),
105
+ dto('AUTH_CACHE_NAME', 'STRING', nullable),
106
+ dto('EXCLUDE_SENDER', 'BOOLEAN', { optional: true }),
107
+ dto('SHOW_TOAST', 'BOOLEAN', { optional: true }),
108
+ ],
109
+ extRow: (d) => ({
110
+ ENTITY_ID: d.ENTITY_ID ?? null,
111
+ ENTITY_ID_TYPE: d.ENTITY_ID_TYPE,
112
+ TTL: d.TTL ?? null,
113
+ TTL_TIME_UNIT: or(d.TTL_TIME_UNIT, 'NONE'),
114
+ AUTH_CACHE_NAME: d.AUTH_CACHE_NAME ?? null,
115
+ RIGHT_CODE: d.RIGHT_CODE ?? null,
116
+ EXCLUDE_SENDER: or(d.EXCLUDE_SENDER, false),
117
+ SHOW_TOAST: or(d.SHOW_TOAST, true),
118
+ }),
119
+ },
120
+ {
121
+ // EH :242, :266, :293
122
+ events: 'EMAIL_DISTRIBUTION_ROUTE',
123
+ ext: 'EMAIL_DIST_NOTIFY_ROUTE_EXT',
124
+ view: 'EmailDistributionRoute',
125
+ createClass: `${EVENT_CLASS}.EmailDistributionRouteCreate`,
126
+ updateClass: `${EVENT_CLASS}.EmailDistributionRouteUpdate`,
127
+ // val emailTo: Set<String>?, with no default: nullable, but required.
128
+ createFields: ['EMAIL_TO', 'EMAIL_CC', 'EMAIL_BCC'].map((name) => ({
129
+ name,
130
+ ...stringSet,
131
+ nullable: true,
132
+ })),
133
+ extRow: (d) => ({
134
+ EMAIL_TO: joined(d.EMAIL_TO),
135
+ EMAIL_CC: joined(d.EMAIL_CC),
136
+ EMAIL_BCC: joined(d.EMAIL_BCC),
137
+ }),
138
+ },
139
+ {
140
+ // EH :307, :331, :358. The create DTO takes RIGHT_CODE and
141
+ // AUTH_CACHE_NAME but never writes them; the update DTO has neither, and
142
+ // its whole-row modify nulls them.
143
+ events: 'EMAIL_USER_ROUTE',
144
+ ext: 'EMAIL_USER_NOTIFY_ROUTE_EXT',
145
+ view: 'EmailUserRoute',
146
+ createClass: `${EVENT_CLASS}.EmailUserRouteCreate`,
147
+ updateClass: `${EVENT_CLASS}.EmailUserRouteUpdate`,
148
+ createFields: [
149
+ dto('ENTITY_ID', 'STRING', nullable),
150
+ entityIdType(),
151
+ dto('RIGHT_CODE', 'STRING', nullable),
152
+ dto('AUTH_CACHE_NAME', 'STRING', nullable),
153
+ dto('EXCLUDE_SENDER', 'BOOLEAN', { optional: true }),
154
+ ],
155
+ updateFields: [
156
+ dto('ENTITY_ID', 'STRING', nullable),
157
+ entityIdType(),
158
+ dto('EXCLUDE_SENDER', 'BOOLEAN', { optional: true }),
159
+ ],
160
+ extRow: (d) => ({
161
+ ENTITY_ID: d.ENTITY_ID ?? null,
162
+ ENTITY_ID_TYPE: d.ENTITY_ID_TYPE,
163
+ RIGHT_CODE: null,
164
+ AUTH_CACHE_NAME: null,
165
+ EXCLUDE_SENDER: or(d.EXCLUDE_SENDER, false),
166
+ }),
167
+ },
168
+ {
169
+ // EH :120, :142, :167
170
+ events: 'MS_TEAMS_ROUTE',
171
+ ext: 'MS_TEAMS_NOTIFY_ROUTE_EXT',
172
+ view: 'MsTeamsRoute',
173
+ createClass: `${EVENT_CLASS}.MsTeamsRouteCreate`,
174
+ updateClass: `${EVENT_CLASS}.MsTeamsRouteUpdate`,
175
+ createFields: [dto('URL', 'STRING')],
176
+ extRow: (d) => ({ URL: d.URL }),
177
+ },
178
+ {
179
+ // EH :181, :203, :228
180
+ events: 'SLACK_ROUTE',
181
+ ext: 'SLACK_NOTIFY_ROUTE_EXT',
182
+ view: 'SlackRoute',
183
+ createClass: `${EVENT_CLASS}.SlackRouteCreate`,
184
+ updateClass: `${EVENT_CLASS}.SlackRouteUpdate`,
185
+ createFields: [dto('URL', 'STRING')],
186
+ extRow: (d) => ({ URL: d.URL }),
187
+ },
188
+ {
189
+ // EH :372, :393, :417
190
+ events: 'LOG_ROUTE',
191
+ ext: 'LOG_NOTIFY_ROUTE_EXT',
192
+ view: 'LogRoute',
193
+ createClass: `${EVENT_CLASS}.LogRouteCreate`,
194
+ updateClass: `${EVENT_CLASS}.LogRouteUpdate`,
195
+ createFields: [],
196
+ extRow: () => ({}),
197
+ },
198
+ ];
199
+
200
+ // notifyRouteOf (EH :20-30): DISPLAY_NAME trimmed, null when blank.
201
+ const displayName = (value: unknown) => {
202
+ const trimmed = typeof value === 'string' ? value.trim() : '';
203
+ return trimmed === '' ? null : trimmed;
204
+ };
205
+
206
+ const routeColumns = (d: Row): Row => ({
207
+ GATEWAY_ID: d.GATEWAY_ID,
208
+ TOPIC_MATCH: d.TOPIC_MATCH,
209
+ ROUTE_ENABLED: or(d.ROUTE_ENABLED, true),
210
+ });
211
+
212
+ // Writes a row and pushes it live, as entityDb does through the update queue.
213
+ function write(
214
+ ctx: EventHandlerCtx,
215
+ table: string,
216
+ operation: 'INSERT' | 'MODIFY' | 'DELETE',
217
+ key: string,
218
+ row?: Row,
219
+ ): Row | undefined {
220
+ const { store } = ctx;
221
+ let written: Row | undefined;
222
+ if (operation === 'INSERT') written = store.insertRow(table, row!);
223
+ else if (operation === 'MODIFY') written = store.updateRow(table, key, row!);
224
+ else store.deleteRow(table, key);
225
+ ctx.broadcastTableChange(table, operation, written ? store.rowKey(table, written) : key);
226
+ return written;
227
+ }
228
+
229
+ function routeHandlers(family: RouteFamily): Record<string, EventHandler> {
230
+ const { ext } = family;
231
+ return {
232
+ // No onValidate: VALIDATE acks. Insert NOTIFY_ROUTE (its NR sequence
233
+ // mints the key), then the ext row on that key; ack with GENERATED [].
234
+ [`EVENT_${family.events}_CREATE`]: (details, ctx) => {
235
+ if (ctx.validate) return {};
236
+ const route = write(ctx, 'NOTIFY_ROUTE', 'INSERT', '', {
237
+ ...routeColumns(details),
238
+ DISPLAY_NAME: displayName(details.DISPLAY_NAME),
239
+ })!;
240
+ write(ctx, ext, 'INSERT', '', {
241
+ NOTIFY_ROUTE_ID: route.NOTIFY_ROUTE_ID,
242
+ ...family.extRow(details),
243
+ });
244
+ return {};
245
+ },
246
+ // applyRouteUpdate (EH :32-42): DISPLAY_NAME changes only when sent; the
247
+ // ext row is replaced whole, and missing is RECORD_NOT_FOUND by its key.
248
+ [`EVENT_${family.events}_UPDATE`]: (details, ctx) => {
249
+ if (ctx.validate) return {};
250
+ const id = details.NOTIFY_ROUTE_ID;
251
+ const route = ctx.store.getRow('NOTIFY_ROUTE', id);
252
+ if (!route) throw new NackError(`NOTIFY_ROUTE ${id} not found`);
253
+ write(ctx, 'NOTIFY_ROUTE', 'MODIFY', id, {
254
+ ...routeColumns(details),
255
+ ...(details.DISPLAY_NAME === undefined || details.DISPLAY_NAME === null
256
+ ? {}
257
+ : { DISPLAY_NAME: displayName(details.DISPLAY_NAME) }),
258
+ });
259
+ if (!ctx.store.getRow(ext, id)) {
260
+ throw NackError.recordNotFound(ext, `${ext}_BY_NOTIFY_ROUTE_ID`);
261
+ }
262
+ write(ctx, ext, 'MODIFY', id, family.extRow(details));
263
+ return {};
264
+ },
265
+ // The route, then its ext row; either missing is RECORD_NOT_FOUND.
266
+ [`EVENT_${family.events}_DELETE`]: (details, ctx) => {
267
+ if (ctx.validate) return {};
268
+ const id = details.NOTIFY_ROUTE_ID;
269
+ for (const table of ['NOTIFY_ROUTE', ext]) {
270
+ if (!ctx.store.getRow(table, id)) throw NackError.recordNotFound(table);
271
+ write(ctx, table, 'DELETE', id);
272
+ }
273
+ return {};
274
+ },
275
+ };
276
+ }
277
+
278
+ function routeSchemas(family: RouteFamily): Record<string, EventSchemaOverride> {
279
+ const id = dto('NOTIFY_ROUTE_ID', 'STRING');
280
+ return {
281
+ // Its ENUMs are the ext table's columns' (enum class names).
282
+ [`EVENT_${family.events}_CREATE`]: {
283
+ table: family.ext,
284
+ className: family.createClass,
285
+ fields: [...ROUTE_FIELDS, ...family.createFields],
286
+ },
287
+ [`EVENT_${family.events}_UPDATE`]: {
288
+ table: family.ext,
289
+ className: family.updateClass,
290
+ fields: [id, ...ROUTE_FIELDS, ...(family.updateFields ?? family.createFields)],
291
+ },
292
+ [`EVENT_${family.events}_DELETE`]: {
293
+ table: 'NOTIFY_ROUTE',
294
+ pkOnly: true,
295
+ className: `global.genesis.gen.view.entity.${family.view}.ById`,
296
+ },
297
+ };
298
+ }
299
+
300
+ export interface NotifyBacking {
301
+ eventHandlers: Record<string, EventHandler>;
302
+ eventSchemas: Record<string, EventSchemaOverride>;
303
+ }
304
+
305
+ // genesis-notify's backing, for platformPreset to add when the app includes
306
+ // the product.
307
+ export function notifyBacking(): NotifyBacking {
308
+ return {
309
+ eventHandlers: Object.assign({}, ...ROUTE_FAMILIES.map(routeHandlers)),
310
+ eventSchemas: Object.assign({}, ...ROUTE_FAMILIES.map(routeSchemas)),
311
+ };
312
+ }