@genesislcap/mock-server 15.74.0 → 15.76.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
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { NackError } from "../protocol/errors.js";
|
|
2
|
+
const ENTITY_ID_TYPES = ['USER_NAME', 'PROFILE_NAME', 'ALL', 'SELF'];
|
|
3
|
+
// The package the product's enums are generated in: their DTOs take
|
|
4
|
+
// global.genesis.gen.dao.enums.EntityIdType, not a table's own.
|
|
5
|
+
export const ENUMS = 'global.genesis.gen.dao.enums';
|
|
6
|
+
export const TTL_TIME_UNITS = ['NONE', 'SECONDS', 'MINUTES', 'HOURS', 'DAYS'];
|
|
7
|
+
// A DTO property. `optional`: it has a Kotlin default (which metadata doesn't
|
|
8
|
+
// show), so DETAILS may leave it out.
|
|
9
|
+
export const dto = (name, type, more = {}) => ({
|
|
10
|
+
name,
|
|
11
|
+
type,
|
|
12
|
+
nullable: false,
|
|
13
|
+
...more,
|
|
14
|
+
});
|
|
15
|
+
export const nullable = { nullable: true, optional: true };
|
|
16
|
+
// RouteCreate (NotifyRouteCreate.kt): every route DTO's own four.
|
|
17
|
+
const ROUTE_FIELDS = [
|
|
18
|
+
dto('GATEWAY_ID', 'STRING'),
|
|
19
|
+
dto('TOPIC_MATCH', 'STRING'),
|
|
20
|
+
dto('ROUTE_ENABLED', 'BOOLEAN', { optional: true }),
|
|
21
|
+
dto('DISPLAY_NAME', 'STRING', nullable),
|
|
22
|
+
];
|
|
23
|
+
const entityIdType = () => dto('ENTITY_ID_TYPE', 'ENUM', { values: ENTITY_ID_TYPES, enumClass: `${ENUMS}.EntityIdType` });
|
|
24
|
+
const or = (value, fallback) => value ?? fallback;
|
|
25
|
+
// A Set<String> joined as EH stores it: `set?.joinToString(",") ?: ""`. A
|
|
26
|
+
// string is a one-element set (Jackson's ACCEPT_SINGLE_VALUE_AS_ARRAY).
|
|
27
|
+
const joined = (value) => Array.isArray(value) ? value.join(',') : typeof value === 'string' ? value : '';
|
|
28
|
+
export const stringSet = {
|
|
29
|
+
type: 'ARRAY',
|
|
30
|
+
items: { type: 'STRING' },
|
|
31
|
+
unique: true,
|
|
32
|
+
};
|
|
33
|
+
export const EVENT_CLASS = 'global.genesis.notify.message.event';
|
|
34
|
+
const ROUTE_FAMILIES = [
|
|
35
|
+
{
|
|
36
|
+
// EH :45, :74, :106
|
|
37
|
+
events: 'SCREEN_NOTIFY_ROUTE',
|
|
38
|
+
ext: 'SCREEN_NOTIFY_ROUTE_EXT',
|
|
39
|
+
view: 'ScreenRoute',
|
|
40
|
+
createClass: `${EVENT_CLASS}.ScreenRouteCreate`,
|
|
41
|
+
updateClass: `${EVENT_CLASS}.ScreenRouteUpdate`,
|
|
42
|
+
createFields: [
|
|
43
|
+
dto('ENTITY_ID', 'STRING', nullable),
|
|
44
|
+
entityIdType(),
|
|
45
|
+
dto('TTL', 'LONG', nullable),
|
|
46
|
+
dto('TTL_TIME_UNIT', 'ENUM', {
|
|
47
|
+
values: TTL_TIME_UNITS,
|
|
48
|
+
enumClass: `${ENUMS}.TtlTimeUnit`,
|
|
49
|
+
optional: true,
|
|
50
|
+
}),
|
|
51
|
+
dto('RIGHT_CODE', 'STRING', nullable),
|
|
52
|
+
dto('AUTH_CACHE_NAME', 'STRING', nullable),
|
|
53
|
+
dto('EXCLUDE_SENDER', 'BOOLEAN', { optional: true }),
|
|
54
|
+
dto('SHOW_TOAST', 'BOOLEAN', { optional: true }),
|
|
55
|
+
],
|
|
56
|
+
extRow: (d) => ({
|
|
57
|
+
ENTITY_ID: d.ENTITY_ID ?? null,
|
|
58
|
+
ENTITY_ID_TYPE: d.ENTITY_ID_TYPE,
|
|
59
|
+
TTL: d.TTL ?? null,
|
|
60
|
+
TTL_TIME_UNIT: or(d.TTL_TIME_UNIT, 'NONE'),
|
|
61
|
+
AUTH_CACHE_NAME: d.AUTH_CACHE_NAME ?? null,
|
|
62
|
+
RIGHT_CODE: d.RIGHT_CODE ?? null,
|
|
63
|
+
EXCLUDE_SENDER: or(d.EXCLUDE_SENDER, false),
|
|
64
|
+
SHOW_TOAST: or(d.SHOW_TOAST, true),
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
// EH :242, :266, :293
|
|
69
|
+
events: 'EMAIL_DISTRIBUTION_ROUTE',
|
|
70
|
+
ext: 'EMAIL_DIST_NOTIFY_ROUTE_EXT',
|
|
71
|
+
view: 'EmailDistributionRoute',
|
|
72
|
+
createClass: `${EVENT_CLASS}.EmailDistributionRouteCreate`,
|
|
73
|
+
updateClass: `${EVENT_CLASS}.EmailDistributionRouteUpdate`,
|
|
74
|
+
// val emailTo: Set<String>?, with no default: nullable, but required.
|
|
75
|
+
createFields: ['EMAIL_TO', 'EMAIL_CC', 'EMAIL_BCC'].map((name) => ({
|
|
76
|
+
name,
|
|
77
|
+
...stringSet,
|
|
78
|
+
nullable: true,
|
|
79
|
+
})),
|
|
80
|
+
extRow: (d) => ({
|
|
81
|
+
EMAIL_TO: joined(d.EMAIL_TO),
|
|
82
|
+
EMAIL_CC: joined(d.EMAIL_CC),
|
|
83
|
+
EMAIL_BCC: joined(d.EMAIL_BCC),
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
// EH :307, :331, :358. The create DTO takes RIGHT_CODE and
|
|
88
|
+
// AUTH_CACHE_NAME but never writes them; the update DTO has neither, and
|
|
89
|
+
// its whole-row modify nulls them.
|
|
90
|
+
events: 'EMAIL_USER_ROUTE',
|
|
91
|
+
ext: 'EMAIL_USER_NOTIFY_ROUTE_EXT',
|
|
92
|
+
view: 'EmailUserRoute',
|
|
93
|
+
createClass: `${EVENT_CLASS}.EmailUserRouteCreate`,
|
|
94
|
+
updateClass: `${EVENT_CLASS}.EmailUserRouteUpdate`,
|
|
95
|
+
createFields: [
|
|
96
|
+
dto('ENTITY_ID', 'STRING', nullable),
|
|
97
|
+
entityIdType(),
|
|
98
|
+
dto('RIGHT_CODE', 'STRING', nullable),
|
|
99
|
+
dto('AUTH_CACHE_NAME', 'STRING', nullable),
|
|
100
|
+
dto('EXCLUDE_SENDER', 'BOOLEAN', { optional: true }),
|
|
101
|
+
],
|
|
102
|
+
updateFields: [
|
|
103
|
+
dto('ENTITY_ID', 'STRING', nullable),
|
|
104
|
+
entityIdType(),
|
|
105
|
+
dto('EXCLUDE_SENDER', 'BOOLEAN', { optional: true }),
|
|
106
|
+
],
|
|
107
|
+
extRow: (d) => ({
|
|
108
|
+
ENTITY_ID: d.ENTITY_ID ?? null,
|
|
109
|
+
ENTITY_ID_TYPE: d.ENTITY_ID_TYPE,
|
|
110
|
+
RIGHT_CODE: null,
|
|
111
|
+
AUTH_CACHE_NAME: null,
|
|
112
|
+
EXCLUDE_SENDER: or(d.EXCLUDE_SENDER, false),
|
|
113
|
+
}),
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
// EH :120, :142, :167
|
|
117
|
+
events: 'MS_TEAMS_ROUTE',
|
|
118
|
+
ext: 'MS_TEAMS_NOTIFY_ROUTE_EXT',
|
|
119
|
+
view: 'MsTeamsRoute',
|
|
120
|
+
createClass: `${EVENT_CLASS}.MsTeamsRouteCreate`,
|
|
121
|
+
updateClass: `${EVENT_CLASS}.MsTeamsRouteUpdate`,
|
|
122
|
+
createFields: [dto('URL', 'STRING')],
|
|
123
|
+
extRow: (d) => ({ URL: d.URL }),
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
// EH :181, :203, :228
|
|
127
|
+
events: 'SLACK_ROUTE',
|
|
128
|
+
ext: 'SLACK_NOTIFY_ROUTE_EXT',
|
|
129
|
+
view: 'SlackRoute',
|
|
130
|
+
createClass: `${EVENT_CLASS}.SlackRouteCreate`,
|
|
131
|
+
updateClass: `${EVENT_CLASS}.SlackRouteUpdate`,
|
|
132
|
+
createFields: [dto('URL', 'STRING')],
|
|
133
|
+
extRow: (d) => ({ URL: d.URL }),
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
// EH :372, :393, :417
|
|
137
|
+
events: 'LOG_ROUTE',
|
|
138
|
+
ext: 'LOG_NOTIFY_ROUTE_EXT',
|
|
139
|
+
view: 'LogRoute',
|
|
140
|
+
createClass: `${EVENT_CLASS}.LogRouteCreate`,
|
|
141
|
+
updateClass: `${EVENT_CLASS}.LogRouteUpdate`,
|
|
142
|
+
createFields: [],
|
|
143
|
+
extRow: () => ({}),
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
// notifyRouteOf (EH :20-30): DISPLAY_NAME trimmed, null when blank.
|
|
147
|
+
const displayName = (value) => {
|
|
148
|
+
const trimmed = typeof value === 'string' ? value.trim() : '';
|
|
149
|
+
return trimmed === '' ? null : trimmed;
|
|
150
|
+
};
|
|
151
|
+
const routeColumns = (d) => ({
|
|
152
|
+
GATEWAY_ID: d.GATEWAY_ID,
|
|
153
|
+
TOPIC_MATCH: d.TOPIC_MATCH,
|
|
154
|
+
ROUTE_ENABLED: or(d.ROUTE_ENABLED, true),
|
|
155
|
+
});
|
|
156
|
+
// Writes a row and pushes it live, as entityDb does through the update queue.
|
|
157
|
+
function write(ctx, table, operation, key, row) {
|
|
158
|
+
const { store } = ctx;
|
|
159
|
+
let written;
|
|
160
|
+
if (operation === 'INSERT')
|
|
161
|
+
written = store.insertRow(table, row);
|
|
162
|
+
else if (operation === 'MODIFY')
|
|
163
|
+
written = store.updateRow(table, key, row);
|
|
164
|
+
else
|
|
165
|
+
store.deleteRow(table, key);
|
|
166
|
+
ctx.broadcastTableChange(table, operation, written ? store.rowKey(table, written) : key);
|
|
167
|
+
return written;
|
|
168
|
+
}
|
|
169
|
+
function routeHandlers(family) {
|
|
170
|
+
const { ext } = family;
|
|
171
|
+
return {
|
|
172
|
+
// No onValidate: VALIDATE acks. Insert NOTIFY_ROUTE (its NR sequence
|
|
173
|
+
// mints the key), then the ext row on that key; ack with GENERATED [].
|
|
174
|
+
[`EVENT_${family.events}_CREATE`]: (details, ctx) => {
|
|
175
|
+
if (ctx.validate)
|
|
176
|
+
return {};
|
|
177
|
+
const route = write(ctx, 'NOTIFY_ROUTE', 'INSERT', '', {
|
|
178
|
+
...routeColumns(details),
|
|
179
|
+
DISPLAY_NAME: displayName(details.DISPLAY_NAME),
|
|
180
|
+
});
|
|
181
|
+
write(ctx, ext, 'INSERT', '', {
|
|
182
|
+
NOTIFY_ROUTE_ID: route.NOTIFY_ROUTE_ID,
|
|
183
|
+
...family.extRow(details),
|
|
184
|
+
});
|
|
185
|
+
return {};
|
|
186
|
+
},
|
|
187
|
+
// applyRouteUpdate (EH :32-42): DISPLAY_NAME changes only when sent; the
|
|
188
|
+
// ext row is replaced whole, and missing is RECORD_NOT_FOUND by its key.
|
|
189
|
+
[`EVENT_${family.events}_UPDATE`]: (details, ctx) => {
|
|
190
|
+
if (ctx.validate)
|
|
191
|
+
return {};
|
|
192
|
+
const id = details.NOTIFY_ROUTE_ID;
|
|
193
|
+
const route = ctx.store.getRow('NOTIFY_ROUTE', id);
|
|
194
|
+
if (!route)
|
|
195
|
+
throw new NackError(`NOTIFY_ROUTE ${id} not found`);
|
|
196
|
+
write(ctx, 'NOTIFY_ROUTE', 'MODIFY', id, {
|
|
197
|
+
...routeColumns(details),
|
|
198
|
+
...(details.DISPLAY_NAME === undefined || details.DISPLAY_NAME === null
|
|
199
|
+
? {}
|
|
200
|
+
: { DISPLAY_NAME: displayName(details.DISPLAY_NAME) }),
|
|
201
|
+
});
|
|
202
|
+
if (!ctx.store.getRow(ext, id)) {
|
|
203
|
+
throw NackError.recordNotFound(ext, `${ext}_BY_NOTIFY_ROUTE_ID`);
|
|
204
|
+
}
|
|
205
|
+
write(ctx, ext, 'MODIFY', id, family.extRow(details));
|
|
206
|
+
return {};
|
|
207
|
+
},
|
|
208
|
+
// The route, then its ext row; either missing is RECORD_NOT_FOUND.
|
|
209
|
+
[`EVENT_${family.events}_DELETE`]: (details, ctx) => {
|
|
210
|
+
if (ctx.validate)
|
|
211
|
+
return {};
|
|
212
|
+
const id = details.NOTIFY_ROUTE_ID;
|
|
213
|
+
for (const table of ['NOTIFY_ROUTE', ext]) {
|
|
214
|
+
if (!ctx.store.getRow(table, id))
|
|
215
|
+
throw NackError.recordNotFound(table);
|
|
216
|
+
write(ctx, table, 'DELETE', id);
|
|
217
|
+
}
|
|
218
|
+
return {};
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function routeSchemas(family) {
|
|
223
|
+
const id = dto('NOTIFY_ROUTE_ID', 'STRING');
|
|
224
|
+
return {
|
|
225
|
+
// Its ENUMs are the ext table's columns' (enum class names).
|
|
226
|
+
[`EVENT_${family.events}_CREATE`]: {
|
|
227
|
+
table: family.ext,
|
|
228
|
+
className: family.createClass,
|
|
229
|
+
fields: [...ROUTE_FIELDS, ...family.createFields],
|
|
230
|
+
},
|
|
231
|
+
[`EVENT_${family.events}_UPDATE`]: {
|
|
232
|
+
table: family.ext,
|
|
233
|
+
className: family.updateClass,
|
|
234
|
+
fields: [id, ...ROUTE_FIELDS, ...(family.updateFields ?? family.createFields)],
|
|
235
|
+
},
|
|
236
|
+
[`EVENT_${family.events}_DELETE`]: {
|
|
237
|
+
table: 'NOTIFY_ROUTE',
|
|
238
|
+
pkOnly: true,
|
|
239
|
+
className: `global.genesis.gen.view.entity.${family.view}.ById`,
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
// genesis-notify's backing, for platformPreset to add when the app includes
|
|
244
|
+
// the product.
|
|
245
|
+
export function notifyBacking() {
|
|
246
|
+
return {
|
|
247
|
+
eventHandlers: Object.assign({}, ...ROUTE_FAMILIES.map(routeHandlers)),
|
|
248
|
+
eventSchemas: Object.assign({}, ...ROUTE_FAMILIES.map(routeSchemas)),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { EventHandler, EventHandlerCtx, EventSchemaOverride, RequestReplyDef } from '../types.ts';
|
|
2
|
+
import { type NotifyUsers } from './notify.ts';
|
|
3
|
+
export type NotifyGatewayKind = 'screen' | 'email' | 'sendGrid' | 'teams' | 'slack' | 'log';
|
|
4
|
+
export interface NotifyGateway {
|
|
5
|
+
id: string;
|
|
6
|
+
kind: NotifyGatewayKind;
|
|
7
|
+
}
|
|
8
|
+
export declare const DEFAULT_NOTIFY_GATEWAYS: NotifyGateway[];
|
|
9
|
+
export interface DispatchOptions {
|
|
10
|
+
users: NotifyUsers;
|
|
11
|
+
gateways: NotifyGateway[];
|
|
12
|
+
entities?: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface RaisedNotification {
|
|
15
|
+
HEADER: string;
|
|
16
|
+
BODY: string;
|
|
17
|
+
NOTIFY_SEVERITY: string;
|
|
18
|
+
ROUTING_TYPE: string;
|
|
19
|
+
ROUTING_DATA: string | null;
|
|
20
|
+
NOTIFY_ATTACHMENTS?: string[];
|
|
21
|
+
}
|
|
22
|
+
export interface DispatchBacking {
|
|
23
|
+
eventHandlers: Record<string, EventHandler>;
|
|
24
|
+
eventSchemas: Record<string, EventSchemaOverride>;
|
|
25
|
+
requestReplies: Record<string, RequestReplyDef>;
|
|
26
|
+
raise(ctx: EventHandlerCtx, user: string, notification: RaisedNotification): void;
|
|
27
|
+
}
|
|
28
|
+
export declare function dispatchBacking({ users, gateways, entities }: DispatchOptions): DispatchBacking;
|