@genesislcap/mock-server 15.65.0 → 15.66.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 +71 -1
- package/dist/handlers/resources.d.ts +2 -1
- package/dist/handlers/resources.js +18 -2
- package/dist/presets/csv.d.ts +2 -0
- package/dist/presets/csv.js +52 -0
- package/dist/presets/index.d.ts +3 -0
- package/dist/presets/index.js +3 -0
- package/dist/presets/merge.d.ts +15 -0
- package/dist/presets/merge.js +76 -0
- package/dist/presets/platform/default-user.json +30 -0
- package/dist/presets/platform/profile-rights.json +242 -0
- package/dist/presets/platform/profiles.json +62 -0
- package/dist/presets/platform/resources.json +710 -0
- package/dist/presets/platform/rights.json +238 -0
- package/dist/presets/platform.d.ts +27 -0
- package/dist/presets/platform.js +410 -0
- package/dist/types.d.ts +1 -0
- package/package.json +8 -2
- package/src/handlers/resources.ts +19 -2
- package/src/presets/csv.ts +50 -0
- package/src/presets/index.ts +8 -0
- package/src/presets/merge.ts +79 -0
- package/src/presets/platform/default-user.json +30 -0
- package/src/presets/platform/profile-rights.json +242 -0
- package/src/presets/platform/profiles.json +62 -0
- package/src/presets/platform/resources.json +710 -0
- package/src/presets/platform/rights.json +238 -0
- package/src/presets/platform.ts +503 -0
- package/src/types.ts +7 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"CODE": "INSERT_PROFILE",
|
|
4
|
+
"DESCRIPTION": "Add a new Profile"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"CODE": "INSERT_USER",
|
|
8
|
+
"DESCRIPTION": "Add a new User"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"CODE": "AMEND_PROFILE",
|
|
12
|
+
"DESCRIPTION": "Amend an existing Profile"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"CODE": "AMEND_USER",
|
|
16
|
+
"DESCRIPTION": "Amend an existing User"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"CODE": "CHANGE_PWD",
|
|
20
|
+
"DESCRIPTION": "Change another User's password"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"CODE": "DELETE_PROFILE",
|
|
24
|
+
"DESCRIPTION": "Delete a Profile"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"CODE": "DELETE_USER",
|
|
28
|
+
"DESCRIPTION": "Delete a User"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"CODE": "DISABLE_USER",
|
|
32
|
+
"DESCRIPTION": "Disable a User"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"CODE": "ENABLE_USER",
|
|
36
|
+
"DESCRIPTION": "Enable a User"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"CODE": "EXPIRE_PWD",
|
|
40
|
+
"DESCRIPTION": "Expire another User's password"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"CODE": "FileStorageView",
|
|
44
|
+
"DESCRIPTION": "Ability to view any file storage resource"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"CODE": "FileStorageUpload",
|
|
48
|
+
"DESCRIPTION": "Ability to upload to file storage"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"CODE": "FileStorageDownload",
|
|
52
|
+
"DESCRIPTION": "Ability to download from file storage"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"CODE": "FileStorageReplace",
|
|
56
|
+
"DESCRIPTION": "Ability to overwrite a file in file storage"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"CODE": "FileStorageDelete",
|
|
60
|
+
"DESCRIPTION": "Ability to delete a file from file storage"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"CODE": "FileStorageAdminAction",
|
|
64
|
+
"DESCRIPTION": "Ability to perform any file storage admin action"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"CODE": "TemplateAssetsInsert",
|
|
68
|
+
"DESCRIPTION": "Ability to link a template file to an asset"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"CODE": "NotificationAdminAction",
|
|
72
|
+
"DESCRIPTION": "Ability to perform any notification admin action"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"CODE": "NotificationRuleCreate",
|
|
76
|
+
"DESCRIPTION": "Create a notification rule"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"CODE": "NotificationRuleUpdate",
|
|
80
|
+
"DESCRIPTION": "Update a notification rule"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"CODE": "NotificationRuleDelete",
|
|
84
|
+
"DESCRIPTION": "Delete a notification rule"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"CODE": "NotificationRuleSubscribe",
|
|
88
|
+
"DESCRIPTION": "Subscribe to a notification rule"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"CODE": "NotificationRuleUnsubscribe",
|
|
92
|
+
"DESCRIPTION": "Unsubscribe from a notification rule"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"CODE": "NotificationRuleEnable",
|
|
96
|
+
"DESCRIPTION": "Enable a notification rule"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"CODE": "NotificationRuleDisable",
|
|
100
|
+
"DESCRIPTION": "Disable a notification rule"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"CODE": "NotificationRuleTemplateCreate",
|
|
104
|
+
"DESCRIPTION": "Create a notification rule template"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"CODE": "NotificationRuleTemplateUpdate",
|
|
108
|
+
"DESCRIPTION": "Update a notification rule template"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"CODE": "NotificationRuleTemplateDelete",
|
|
112
|
+
"DESCRIPTION": "Delete a notification rule template"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"CODE": "NotificationRuleTemplateView",
|
|
116
|
+
"DESCRIPTION": "View a notification rule template"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"CODE": "NotificationRuleView",
|
|
120
|
+
"DESCRIPTION": "View notification rules"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"CODE": "NotificationRouteTopicsView",
|
|
124
|
+
"DESCRIPTION": "View notification route topics"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"CODE": "NotificationRouteCreate",
|
|
128
|
+
"DESCRIPTION": "Create a notification route"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"CODE": "NotificationRouteUpdate",
|
|
132
|
+
"DESCRIPTION": "Update a notification route"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"CODE": "NotificationRouteDelete",
|
|
136
|
+
"DESCRIPTION": "Delete a notification route"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"CODE": "NotificationRouteView",
|
|
140
|
+
"DESCRIPTION": "View a notification route"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"CODE": "NotificationView",
|
|
144
|
+
"DESCRIPTION": "View notify records"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"CODE": "NotificationAuditView",
|
|
148
|
+
"DESCRIPTION": "View notify audit records"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"CODE": "SendNotificationOnBehalfOfOthers",
|
|
152
|
+
"DESCRIPTION": "Service user role that allows an account to send notitications where the SENDER is another user in the system"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"CODE": "ReconciliationConfigView",
|
|
156
|
+
"DESCRIPTION": "Ability to view any reconciliation configuration resource"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"CODE": "ReconciliationConfigInsert",
|
|
160
|
+
"DESCRIPTION": "Ability to insert reconciliation configurations"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"CODE": "ReconciliationConfigUpdate",
|
|
164
|
+
"DESCRIPTION": "Ability to update reconciliation configurations"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"CODE": "ReconciliationConfigDelete",
|
|
168
|
+
"DESCRIPTION": "Ability to delete reconciliation configurations"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"CODE": "ReconciliationDictionaryView",
|
|
172
|
+
"DESCRIPTION": "Ability to view any reconciliation dictionary resource"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"CODE": "ReconciliationDictionaryInsert",
|
|
176
|
+
"DESCRIPTION": "Ability to insert reconciliation dictionaries"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"CODE": "ReconciliationDictionaryUpdate",
|
|
180
|
+
"DESCRIPTION": "Ability to update reconciliation dictionaries"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"CODE": "ReconciliationDictionaryDelete",
|
|
184
|
+
"DESCRIPTION": "Ability to delete reconciliation dictionaries"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"CODE": "ReconciliationResultView",
|
|
188
|
+
"DESCRIPTION": "Ability to view any reconciliation result resource"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"CODE": "ReconciliationComment",
|
|
192
|
+
"DESCRIPTION": "Ability to comment on a reconciliation record result"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"CODE": "ReconciliationRun",
|
|
196
|
+
"DESCRIPTION": "Ability to run a reconciliation"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"CODE": "ReconciliationCancel",
|
|
200
|
+
"DESCRIPTION": "Ability to cancel a reconciliation"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"CODE": "ReportConfigurationView",
|
|
204
|
+
"DESCRIPTION": "Ability to view report configurations"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"CODE": "ReportConfigurationUpdate",
|
|
208
|
+
"DESCRIPTION": "Ability to create and update report configurations"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"CODE": "ReportConfigurationDelete",
|
|
212
|
+
"DESCRIPTION": "Ability to delete report configurations"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"CODE": "ReportDestinationView",
|
|
216
|
+
"DESCRIPTION": "Ability to view report destinations"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"CODE": "ReportDestinationUpdate",
|
|
220
|
+
"DESCRIPTION": "Ability to create and edit report destinations"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"CODE": "ReportDestinationDelete",
|
|
224
|
+
"DESCRIPTION": "Ability to delete report destinations"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"CODE": "ReportRun",
|
|
228
|
+
"DESCRIPTION": "Ability to execute an existing report config, and view generated reports"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"CODE": "ReportView",
|
|
232
|
+
"DESCRIPTION": "Ability to view generated reports"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"CODE": "ReportDelete",
|
|
236
|
+
"DESCRIPTION": "Ability to delete generated reports"
|
|
237
|
+
}
|
|
238
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MockServerConfig, ResourceItem, Row } from '../types.ts';
|
|
2
|
+
export interface PlatformUser {
|
|
3
|
+
username: string;
|
|
4
|
+
password?: string;
|
|
5
|
+
profile?: string[];
|
|
6
|
+
permission?: string[];
|
|
7
|
+
user?: Row;
|
|
8
|
+
}
|
|
9
|
+
export interface PlatformSeed {
|
|
10
|
+
RIGHT?: Row[];
|
|
11
|
+
PROFILE?: Row[];
|
|
12
|
+
PROFILE_RIGHT?: Row[];
|
|
13
|
+
NOTIFY_ALERT?: Row[];
|
|
14
|
+
KEY_VALUE?: Row[];
|
|
15
|
+
}
|
|
16
|
+
export interface PlatformPresetOptions {
|
|
17
|
+
users?: PlatformUser[];
|
|
18
|
+
seed?: PlatformSeed;
|
|
19
|
+
resources?: ResourceItem[];
|
|
20
|
+
sessionUser?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The Genesis platform's data and handlers, to merge with an app's own config:
|
|
24
|
+
* `createMockServer(mergeConfigs(platformPreset(), appConfig))`. See the
|
|
25
|
+
* README's "Platform preset".
|
|
26
|
+
*/
|
|
27
|
+
export declare function platformPreset(options?: PlatformPresetOptions): MockServerConfig;
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
// The Genesis platform a GSF 8.15.x app runs beside its own processes: auth
|
|
2
|
+
// (users, profiles, rights, the key-value store), notify's alerts, and the
|
|
3
|
+
// RESOURCES every platform PBC registers. Data comes from ./platform/*.json,
|
|
4
|
+
// which scripts/platform-preset/generate.ts builds from real recordings and the
|
|
5
|
+
// PBCs' own seed files; behaviour and texts cite the PBC scripts at the
|
|
6
|
+
// versions the showcase server pins (server/gradle.properties: GSF 8.15.29,
|
|
7
|
+
// auth 8.15.5, genesis-notify 8.15.16).
|
|
8
|
+
import { NackError } from "../protocol/errors.js";
|
|
9
|
+
import defaultUser from './platform/default-user.json' with { type: 'json' };
|
|
10
|
+
import platformProfileRights from './platform/profile-rights.json' with { type: 'json' };
|
|
11
|
+
import platformProfiles from './platform/profiles.json' with { type: 'json' };
|
|
12
|
+
import platformResources from './platform/resources.json' with { type: 'json' };
|
|
13
|
+
import platformRights from './platform/rights.json' with { type: 'json' };
|
|
14
|
+
const DEFAULT_PASSWORD = 'admin';
|
|
15
|
+
// --- tables --------------------------------------------------------------------
|
|
16
|
+
const field = (name, type = 'STRING', more = {}) => ({
|
|
17
|
+
name,
|
|
18
|
+
type,
|
|
19
|
+
...more,
|
|
20
|
+
});
|
|
21
|
+
// USER, genesis-tables-dictionary.kts:360 (GSF v8.15.29), types from
|
|
22
|
+
// genesis-fields-dictionary.kts. PASSWORD and PASSWORD_EXPIRY_DATETIME are left
|
|
23
|
+
// out: credentials are PlatformUser.password, and no query exposes them.
|
|
24
|
+
const USER_FIELDS = [
|
|
25
|
+
field('USER_NAME', 'STRING', { maxSize: 255 }),
|
|
26
|
+
field('FIRST_NAME'),
|
|
27
|
+
field('LAST_NAME'),
|
|
28
|
+
field('EMAIL_ADDRESS'),
|
|
29
|
+
field('LAST_LOGIN', 'DATE'),
|
|
30
|
+
field('STATUS'),
|
|
31
|
+
field('ONLINE', 'BOOLEAN', { default: false }),
|
|
32
|
+
field('COMPANY_NAME'),
|
|
33
|
+
field('COMPANY_ID'),
|
|
34
|
+
field('DOMAIN'),
|
|
35
|
+
];
|
|
36
|
+
// USER_ATTRIBUTES, genesis-tables-dictionary.kts:378 (GSF v8.15.29).
|
|
37
|
+
const USER_ATTRIBUTE_FIELDS = [
|
|
38
|
+
field('USER_NAME', 'STRING', { maxSize: 255 }),
|
|
39
|
+
field('USER_TYPE', 'ENUM', {
|
|
40
|
+
values: ['USER', 'ADVISOR', 'CLIENT', 'SYSTEM', 'API'],
|
|
41
|
+
default: 'USER',
|
|
42
|
+
}),
|
|
43
|
+
field('ACCESS_TYPE', 'ENUM', { values: ['ALL', 'ENTITY', 'MULTI_ENTITY'], default: 'ALL' }),
|
|
44
|
+
...['ADDRESS_LINE1', 'ADDRESS_LINE2', 'ADDRESS_LINE3', 'ADDRESS_LINE4'].map((name) => field(name, 'STRING', { maxSize: 400 })),
|
|
45
|
+
...[
|
|
46
|
+
'CITY',
|
|
47
|
+
'REGION',
|
|
48
|
+
'POSTAL_CODE',
|
|
49
|
+
'COUNTRY',
|
|
50
|
+
'TITLE',
|
|
51
|
+
'WEBSITE',
|
|
52
|
+
'MOBILE_NUMBER',
|
|
53
|
+
'TELEPHONE_NUMBER_DIRECT',
|
|
54
|
+
'TELEPHONE_NUMBER_OFFICE',
|
|
55
|
+
].map((name) => field(name)),
|
|
56
|
+
];
|
|
57
|
+
const fieldNames = (fields) => fields.map(({ name }) => name);
|
|
58
|
+
const USER_COLUMNS = new Set(fieldNames(USER_FIELDS));
|
|
59
|
+
const ATTRIBUTE_COLUMNS = new Set(fieldNames(USER_ATTRIBUTE_FIELDS));
|
|
60
|
+
// auth-tables-dictionary.kts (auth v8.15.5): KEY_VALUE :2, PROFILE :12,
|
|
61
|
+
// PROFILE_USER :22, RIGHT :46, PROFILE_RIGHT :54; types from
|
|
62
|
+
// auth-fields-dictionary.kts. NOTIFY_ALERT: genesis-notify-tables-dictionary.kts:112
|
|
63
|
+
// (genesis-notify v8.15.16), types from genesis-notify-fields-dictionary.kts.
|
|
64
|
+
function platformTables(seed, users) {
|
|
65
|
+
return {
|
|
66
|
+
USER: {
|
|
67
|
+
pkField: 'USER_NAME',
|
|
68
|
+
fields: USER_FIELDS,
|
|
69
|
+
rows: users.map(({ username, user = {} }) => ({
|
|
70
|
+
...pick(user, USER_COLUMNS),
|
|
71
|
+
USER_NAME: username,
|
|
72
|
+
})),
|
|
73
|
+
},
|
|
74
|
+
USER_ATTRIBUTES: {
|
|
75
|
+
pkField: 'USER_NAME',
|
|
76
|
+
fields: USER_ATTRIBUTE_FIELDS,
|
|
77
|
+
rows: users.map(({ username, user = {} }) => ({
|
|
78
|
+
...pick(user, ATTRIBUTE_COLUMNS),
|
|
79
|
+
USER_NAME: username,
|
|
80
|
+
})),
|
|
81
|
+
},
|
|
82
|
+
PROFILE: {
|
|
83
|
+
pkField: 'NAME',
|
|
84
|
+
fields: [
|
|
85
|
+
field('NAME', 'STRING', { maxSize: 255 }),
|
|
86
|
+
field('DESCRIPTION'),
|
|
87
|
+
field('STATUS'),
|
|
88
|
+
field('IS_PRIMARY', 'BOOLEAN', { nullable: false, default: true }),
|
|
89
|
+
],
|
|
90
|
+
rows: seed.PROFILE,
|
|
91
|
+
},
|
|
92
|
+
PROFILE_USER: {
|
|
93
|
+
pkField: ['PROFILE_NAME', 'USER_NAME'],
|
|
94
|
+
fields: [field('PROFILE_NAME'), field('USER_NAME', 'STRING', { maxSize: 255 })],
|
|
95
|
+
rows: users.flatMap(({ username, profile = [] }) => profile.map((PROFILE_NAME) => ({ PROFILE_NAME, USER_NAME: username }))),
|
|
96
|
+
},
|
|
97
|
+
RIGHT: {
|
|
98
|
+
pkField: 'CODE',
|
|
99
|
+
fields: [field('CODE'), field('DESCRIPTION')],
|
|
100
|
+
rows: seed.RIGHT,
|
|
101
|
+
},
|
|
102
|
+
PROFILE_RIGHT: {
|
|
103
|
+
pkField: ['RIGHT_CODE', 'PROFILE_NAME'],
|
|
104
|
+
fields: [field('RIGHT_CODE'), field('PROFILE_NAME')],
|
|
105
|
+
rows: seed.PROFILE_RIGHT,
|
|
106
|
+
},
|
|
107
|
+
// USER_NAME, KV_KEY, KV_VALUE (RAW). Left undeclared: a declared table
|
|
108
|
+
// would have the engine check EVENT_KEY_VALUE_PUT's DETAILS against it,
|
|
109
|
+
// and the real handler skips the schema check (`schemaValidation = false`).
|
|
110
|
+
KEY_VALUE: { pkField: ['USER_NAME', 'KV_KEY'], rows: seed.KEY_VALUE },
|
|
111
|
+
NOTIFY_ALERT: {
|
|
112
|
+
pkField: 'ALERT_ID',
|
|
113
|
+
// sequence(ALERT_ID, "AL")
|
|
114
|
+
sequencePrefix: 'AL',
|
|
115
|
+
sequenceFormat: 'genesis',
|
|
116
|
+
fields: [
|
|
117
|
+
field('ALERT_ID'),
|
|
118
|
+
field('MESSAGE'),
|
|
119
|
+
field('HEADER'),
|
|
120
|
+
field('USER_NAME', 'STRING', { maxSize: 255 }),
|
|
121
|
+
field('EXPIRY', 'DATETIME'),
|
|
122
|
+
field('NOTIFY_SEVERITY', 'ENUM', {
|
|
123
|
+
values: ['Information', 'Warning', 'Serious', 'Critical'],
|
|
124
|
+
default: 'Information',
|
|
125
|
+
}),
|
|
126
|
+
field('CREATED_AT', 'DATETIME'),
|
|
127
|
+
field('TABLE_ENTITY_ID'),
|
|
128
|
+
field('DYNAMIC_RULE_ID'),
|
|
129
|
+
field('TOPIC'),
|
|
130
|
+
field('ALERT_STATUS', 'ENUM', { values: ['NEW', 'DISMISSED', 'EXPIRED'], default: 'NEW' }),
|
|
131
|
+
field('SHOW_TOAST', 'BOOLEAN', { default: true }),
|
|
132
|
+
],
|
|
133
|
+
rows: seed.NOTIFY_ALERT,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function pick(row, columns) {
|
|
138
|
+
return Object.fromEntries(Object.entries(row).filter(([name]) => columns.has(name)));
|
|
139
|
+
}
|
|
140
|
+
// A later row with the same key replaces an earlier one (GSF's data load
|
|
141
|
+
// upserts), keeping the first one's place.
|
|
142
|
+
function upsert(rows, extra, key) {
|
|
143
|
+
const byKey = new Map();
|
|
144
|
+
for (const row of [...rows, ...(extra ?? [])])
|
|
145
|
+
byKey.set(key(row), row);
|
|
146
|
+
return [...byKey.values()];
|
|
147
|
+
}
|
|
148
|
+
// --- the session user ------------------------------------------------------------
|
|
149
|
+
// The user an event or request runs as: the connection's login, else the
|
|
150
|
+
// sessionUser (see PlatformPresetOptions.sessionUser).
|
|
151
|
+
function sessionUserOf(userName, fallback) {
|
|
152
|
+
const user = userName ?? fallback;
|
|
153
|
+
// GSF never runs a handler without a user: its WebSocket is authenticated.
|
|
154
|
+
if (user === undefined)
|
|
155
|
+
throw NackError.standard('NOT_AUTHORISED', 'No user is logged in');
|
|
156
|
+
return user;
|
|
157
|
+
}
|
|
158
|
+
// --- auth: the key-value store ---------------------------------------------------
|
|
159
|
+
// A RAW column's value on the wire: its bytes in base64
|
|
160
|
+
// (GenesisSetMaskingJsonSerializer: gen.writeBinary). foundation-comms'
|
|
161
|
+
// kv.service base64-decodes every VALUE it reads.
|
|
162
|
+
const rawValue = (value) => Buffer.from(String(value ?? ''), 'utf8').toString('base64');
|
|
163
|
+
function keyValueHandlers(fallback) {
|
|
164
|
+
const userOf = (ctx) => sessionUserOf(ctx.connection.userName, fallback);
|
|
165
|
+
return {
|
|
166
|
+
// auth-key-value-eventhandler.kts (auth v8.15.5), KEY_VALUE_PUT:
|
|
167
|
+
// `schemaValidation = false`, then entityDb.upsertAll of DETAILS.RECORDS
|
|
168
|
+
// [{KEY, VALUE}] under the event's user. foundation-comms' kvStorage.put
|
|
169
|
+
// sends them; grid column-state persistence rides on this. VALUE is kept
|
|
170
|
+
// as sent (KeyValueRecord's Utf8ByteArrayDeserializer stores its UTF-8
|
|
171
|
+
// bytes); REQ_KEY_VALUE_READ hands it back in base64.
|
|
172
|
+
EVENT_KEY_VALUE_PUT: (details, ctx) => {
|
|
173
|
+
const { store, broadcastTableChange } = ctx;
|
|
174
|
+
const userName = userOf(ctx);
|
|
175
|
+
const records = (Array.isArray(details.RECORDS) ? details.RECORDS : []);
|
|
176
|
+
for (const record of records) {
|
|
177
|
+
// A record without a KEY fails KeyValueRecord's non-null `key` before
|
|
178
|
+
// the upsert, and onException NACKs with its text.
|
|
179
|
+
if (typeof record?.KEY !== 'string') {
|
|
180
|
+
const keys = records.map((each) => each?.KEY).join(',');
|
|
181
|
+
throw NackError.nack(`Error when upserting record for user: ${userName} with keys: '${keys}'.`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
for (const { KEY, VALUE } of records) {
|
|
185
|
+
const existing = store.findRow('KEY_VALUE', { USER_NAME: userName, KV_KEY: KEY });
|
|
186
|
+
if (existing) {
|
|
187
|
+
const key = store.rowKey('KEY_VALUE', existing);
|
|
188
|
+
store.updateRow('KEY_VALUE', key, { KV_VALUE: VALUE });
|
|
189
|
+
broadcastTableChange('KEY_VALUE', 'MODIFY', key);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const row = store.insertRow('KEY_VALUE', {
|
|
193
|
+
USER_NAME: userName,
|
|
194
|
+
KV_KEY: KEY,
|
|
195
|
+
KV_VALUE: VALUE,
|
|
196
|
+
});
|
|
197
|
+
broadcastTableChange('KEY_VALUE', 'INSERT', store.rowKey('KEY_VALUE', row));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return {};
|
|
201
|
+
},
|
|
202
|
+
// KEY_VALUE_DELETE: DETAILS.KEYS (KeyValueSelectByKeys), deleted in order;
|
|
203
|
+
// a key that isn't there fails the delete, and onException NACKs with its
|
|
204
|
+
// own text. The real handler isn't transactional, so the keys deleted
|
|
205
|
+
// before the missing one stay deleted there; here the NACK rolls them back
|
|
206
|
+
// (the engine commits an event only when it acks).
|
|
207
|
+
EVENT_KEY_VALUE_DELETE: (details, ctx) => {
|
|
208
|
+
const { store, broadcastTableChange } = ctx;
|
|
209
|
+
const userName = userOf(ctx);
|
|
210
|
+
const keys = (Array.isArray(details.KEYS) ? details.KEYS : []);
|
|
211
|
+
for (const key of keys) {
|
|
212
|
+
const pk = store.rowKey('KEY_VALUE', { USER_NAME: userName, KV_KEY: key });
|
|
213
|
+
if (!store.deleteRow('KEY_VALUE', pk)) {
|
|
214
|
+
throw NackError.nack(`Error when deleting records for user: ${userName} with Keys '${keys.join(',')}'`);
|
|
215
|
+
}
|
|
216
|
+
broadcastTableChange('KEY_VALUE', 'DELETE', pk);
|
|
217
|
+
}
|
|
218
|
+
return {};
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
// The KEY_VALUE records a REQ_KEY_VALUE_* request names: the REQUEST user's,
|
|
223
|
+
// and only the REQUEST's KEY when it has one (auth-reqrep.kts
|
|
224
|
+
// filterWithParameters).
|
|
225
|
+
function keyValues(rows, request) {
|
|
226
|
+
return rows.filter((row) => row.USER_NAME === request.USER_NAME &&
|
|
227
|
+
(request.KEY === undefined || request.KEY === null || row.KV_KEY === request.KEY));
|
|
228
|
+
}
|
|
229
|
+
// --- notify: alerts --------------------------------------------------------------
|
|
230
|
+
// genesis-notify-eventhandler.kts (genesis-notify v8.15.16).
|
|
231
|
+
function alertHandlers(fallback) {
|
|
232
|
+
return {
|
|
233
|
+
// :431 contextEventHandler<NotifyAlert.ByAlertId>: onValidate NACKs an
|
|
234
|
+
// alert that isn't there or is another user's; onCommit sets
|
|
235
|
+
// ALERT_STATUS DISMISSED (the inbox subscribes to ALERT_STATUS == 'NEW', so
|
|
236
|
+
// the engine pushes the row out of it as a DELETE).
|
|
237
|
+
EVENT_DISMISS_NOTIFY_ALERT: (details, ctx) => {
|
|
238
|
+
const { store, broadcastTableChange } = ctx;
|
|
239
|
+
const alert = store.findRow('NOTIFY_ALERT', { ALERT_ID: details.ALERT_ID });
|
|
240
|
+
if (!alert)
|
|
241
|
+
throw NackError.nack(`Alert with ID ${details.ALERT_ID} does not exist`);
|
|
242
|
+
if (alert.USER_NAME !== sessionUserOf(ctx.connection.userName, fallback)) {
|
|
243
|
+
throw NackError.nack('Dismissing an alert targeted at another user is forbidden');
|
|
244
|
+
}
|
|
245
|
+
store.updateRow('NOTIFY_ALERT', alert.ALERT_ID, { ALERT_STATUS: 'DISMISSED' });
|
|
246
|
+
broadcastTableChange('NOTIFY_ALERT', 'MODIFY', alert.ALERT_ID);
|
|
247
|
+
return {};
|
|
248
|
+
},
|
|
249
|
+
// :453 eventHandler<Unit>: the event user's NEW alerts (NotifyAlert
|
|
250
|
+
// .byUserNameAlertStatus), DISMISSED in batches.
|
|
251
|
+
EVENT_DISMISS_ALL_NOTIFY_ALERT: (_details, ctx) => {
|
|
252
|
+
const { store, broadcastTableChange } = ctx;
|
|
253
|
+
const userName = sessionUserOf(ctx.connection.userName, fallback);
|
|
254
|
+
for (const alert of store.getAllRows('NOTIFY_ALERT')) {
|
|
255
|
+
if (alert.USER_NAME !== userName || alert.ALERT_STATUS !== 'NEW')
|
|
256
|
+
continue;
|
|
257
|
+
store.updateRow('NOTIFY_ALERT', alert.ALERT_ID, { ALERT_STATUS: 'DISMISSED' });
|
|
258
|
+
broadcastTableChange('NOTIFY_ALERT', 'MODIFY', alert.ALERT_ID);
|
|
259
|
+
}
|
|
260
|
+
return {};
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
// --- the preset ------------------------------------------------------------------
|
|
265
|
+
// A user's rights: their profiles' PROFILE_RIGHT codes, sorted as the real
|
|
266
|
+
// login ack lists them.
|
|
267
|
+
function rightsOf(profiles, profileRights) {
|
|
268
|
+
const codes = profileRights
|
|
269
|
+
.filter((row) => profiles.includes(row.PROFILE_NAME))
|
|
270
|
+
.map((row) => row.RIGHT_CODE);
|
|
271
|
+
return [...new Set(codes)].sort();
|
|
272
|
+
}
|
|
273
|
+
const DEFAULT_USER = {
|
|
274
|
+
username: defaultUser.USER.USER_NAME,
|
|
275
|
+
password: DEFAULT_PASSWORD,
|
|
276
|
+
profile: defaultUser.PROFILE,
|
|
277
|
+
user: { ...defaultUser.USER, ...defaultUser.USER_ATTRIBUTES },
|
|
278
|
+
};
|
|
279
|
+
// The login ack's USER object: what the mock sent before this preset existed
|
|
280
|
+
// (the real ack's USER is null and its USER_DETAILS {FIRST_NAME, LAST_NAME},
|
|
281
|
+
// which plan item 1.19 aligns).
|
|
282
|
+
const LOGIN_USER_FIELDS = new Set(['FIRST_NAME', 'LAST_NAME', 'EMAIL_ADDRESS', 'COMPANY_NAME']);
|
|
283
|
+
/**
|
|
284
|
+
* The Genesis platform's data and handlers, to merge with an app's own config:
|
|
285
|
+
* `createMockServer(mergeConfigs(platformPreset(), appConfig))`. See the
|
|
286
|
+
* README's "Platform preset".
|
|
287
|
+
*/
|
|
288
|
+
export function platformPreset(options = {}) {
|
|
289
|
+
const users = options.users ?? [DEFAULT_USER];
|
|
290
|
+
const fallback = options.sessionUser ?? users[0]?.username;
|
|
291
|
+
const seed = {
|
|
292
|
+
RIGHT: upsert(platformRights, options.seed?.RIGHT, (row) => row.CODE),
|
|
293
|
+
PROFILE: upsert(platformProfiles, options.seed?.PROFILE, (row) => row.NAME),
|
|
294
|
+
PROFILE_RIGHT: upsert(platformProfileRights, options.seed?.PROFILE_RIGHT, (row) => `${row.PROFILE_NAME}|${row.RIGHT_CODE}`),
|
|
295
|
+
NOTIFY_ALERT: options.seed?.NOTIFY_ALERT ?? [],
|
|
296
|
+
KEY_VALUE: options.seed?.KEY_VALUE ?? [],
|
|
297
|
+
};
|
|
298
|
+
const authUsers = users.map(({ username, password, profile = [], permission, user }) => ({
|
|
299
|
+
username,
|
|
300
|
+
password,
|
|
301
|
+
profile: [...profile].sort(),
|
|
302
|
+
permission: permission ?? rightsOf(profile, seed.PROFILE_RIGHT),
|
|
303
|
+
user: user && pick(user, LOGIN_USER_FIELDS),
|
|
304
|
+
}));
|
|
305
|
+
return {
|
|
306
|
+
tables: platformTables(seed, users),
|
|
307
|
+
views: {
|
|
308
|
+
// genesis-view-dictionary.kts:2 (GSF v8.15.29): USER and its
|
|
309
|
+
// USER_ATTRIBUTES, without the password, RECORD_ID and TIMESTAMP columns.
|
|
310
|
+
USER_VIEW: {
|
|
311
|
+
base: 'USER',
|
|
312
|
+
joins: [
|
|
313
|
+
{
|
|
314
|
+
table: 'USER_ATTRIBUTES',
|
|
315
|
+
on: ['USER_NAME', 'USER_NAME'],
|
|
316
|
+
backwardsJoin: true,
|
|
317
|
+
select: Object.fromEntries([...ATTRIBUTE_COLUMNS]
|
|
318
|
+
.filter((name) => name !== 'USER_NAME')
|
|
319
|
+
.map((name) => [name, name])),
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
},
|
|
323
|
+
// auth-view-dictionary.kts (auth v8.15.5) :50 and :65.
|
|
324
|
+
PROFILE_RIGHT_VIEW: {
|
|
325
|
+
base: 'PROFILE_RIGHT',
|
|
326
|
+
joins: [
|
|
327
|
+
{ table: 'PROFILE', on: ['PROFILE_NAME', 'NAME'], type: 'INNER' },
|
|
328
|
+
{ table: 'RIGHT', on: ['RIGHT_CODE', 'CODE'], type: 'INNER' },
|
|
329
|
+
],
|
|
330
|
+
fields: ['PROFILE_NAME', 'RIGHT_CODE'],
|
|
331
|
+
},
|
|
332
|
+
PROFILE_USER_VIEW: {
|
|
333
|
+
base: 'PROFILE_USER',
|
|
334
|
+
joins: [
|
|
335
|
+
{ table: 'USER', on: ['USER_NAME', 'USER_NAME'], type: 'INNER', backwardsJoin: true },
|
|
336
|
+
],
|
|
337
|
+
fields: ['PROFILE_NAME', 'USER_NAME'],
|
|
338
|
+
},
|
|
339
|
+
// query(PROFILE) / requestReply(PROFILE) `NAME withPrefix PROFILE` and
|
|
340
|
+
// query(RIGHT) `CODE withPrefix RIGHT`, `DESCRIPTION withPrefix RIGHT`.
|
|
341
|
+
PROFILE_PREFIXED: {
|
|
342
|
+
base: 'PROFILE',
|
|
343
|
+
pkField: 'PROFILE_NAME',
|
|
344
|
+
select: { PROFILE_NAME: 'NAME' },
|
|
345
|
+
fields: ['PROFILE_NAME', 'DESCRIPTION', 'STATUS'],
|
|
346
|
+
},
|
|
347
|
+
RIGHT_PREFIXED: {
|
|
348
|
+
base: 'RIGHT',
|
|
349
|
+
pkField: 'RIGHT_CODE',
|
|
350
|
+
select: { RIGHT_CODE: 'CODE', RIGHT_DESCRIPTION: 'DESCRIPTION' },
|
|
351
|
+
fields: ['RIGHT_CODE', 'RIGHT_DESCRIPTION'],
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
// auth-dataserver.kts (auth v8.15.5) and genesis-notify-rules-dataserver.kts
|
|
355
|
+
// (genesis-notify v8.15.16).
|
|
356
|
+
queries: {
|
|
357
|
+
ALL_USERS: { source: 'USER_VIEW' },
|
|
358
|
+
ALL_PROFILES: { source: 'PROFILE_PREFIXED' },
|
|
359
|
+
ALL_RIGHTS: { source: 'RIGHT_PREFIXED' },
|
|
360
|
+
ALL_PROFILE_RIGHTS: { source: 'PROFILE_RIGHT_VIEW' },
|
|
361
|
+
ALL_PROFILE_USERS: { source: 'PROFILE_USER_VIEW' },
|
|
362
|
+
// `permissioning { auth { filterWithUserName { userName == data.userName } } }`
|
|
363
|
+
ALL_NOTIFY_ALERT_RECORDS: {
|
|
364
|
+
source: 'NOTIFY_ALERT',
|
|
365
|
+
auth: { rowFilter: (row, user) => row.USER_NAME === (user.userName ?? fallback) },
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
// auth-reqrep.kts (auth v8.15.5).
|
|
369
|
+
requestReplies: {
|
|
370
|
+
// :57 request { CODE } reply { CODE DESCRIPTION }, so its rows carry no
|
|
371
|
+
// RECORD_ID.
|
|
372
|
+
RIGHT: { source: 'RIGHT', fields: ['CODE', 'DESCRIPTION'] },
|
|
373
|
+
// :7 request { NAME withPrefix PROFILE } reply { ..., STATUS, DESCRIPTION }
|
|
374
|
+
PROFILE: {
|
|
375
|
+
source: 'PROFILE_PREFIXED',
|
|
376
|
+
requestFields: ['PROFILE_NAME'],
|
|
377
|
+
fields: ['PROFILE_NAME', 'STATUS', 'DESCRIPTION'],
|
|
378
|
+
},
|
|
379
|
+
// :212 request { USER_NAME } reply { KV_KEY withAlias "KEY" }
|
|
380
|
+
KEY_VALUE_LIST: {
|
|
381
|
+
requestFields: ['USER_NAME'],
|
|
382
|
+
resolver: ({ request, store }) => keyValues(store.getAllRows('KEY_VALUE'), request).map((row) => ({ KEY: row.KV_KEY })),
|
|
383
|
+
metadataRows: [{ KEY: 'example' }],
|
|
384
|
+
},
|
|
385
|
+
// :232 request { USER_NAME, KV_KEY withAlias "KEY" }
|
|
386
|
+
// reply { KV_KEY withAlias "KEY", KV_VALUE withAlias "VALUE" }
|
|
387
|
+
KEY_VALUE_READ: {
|
|
388
|
+
requestFields: ['USER_NAME', 'KEY'],
|
|
389
|
+
resolver: ({ request, store }) => keyValues(store.getAllRows('KEY_VALUE'), request).map((row) => ({
|
|
390
|
+
KEY: row.KV_KEY,
|
|
391
|
+
VALUE: rawValue(row.KV_VALUE),
|
|
392
|
+
})),
|
|
393
|
+
metadataRows: [{ KEY: 'example', VALUE: '' }],
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
eventHandlers: { ...keyValueHandlers(fallback), ...alertHandlers(fallback) },
|
|
397
|
+
// The DETAILS classes of the alert events, which their names alone would
|
|
398
|
+
// make NOTIFY_ALERT table events.
|
|
399
|
+
eventSchemas: {
|
|
400
|
+
EVENT_DISMISS_NOTIFY_ALERT: {
|
|
401
|
+
table: 'NOTIFY_ALERT',
|
|
402
|
+
pkOnly: true,
|
|
403
|
+
className: 'global.genesis.gen.dao.NotifyAlert.ByAlertId',
|
|
404
|
+
},
|
|
405
|
+
EVENT_DISMISS_ALL_NOTIFY_ALERT: { fields: [], className: 'kotlin.Unit' },
|
|
406
|
+
},
|
|
407
|
+
auth: { users: authUsers },
|
|
408
|
+
additionalResources: [...platformResources, ...(options.resources ?? [])],
|
|
409
|
+
};
|
|
410
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -198,6 +198,7 @@ export interface MockServerConfig {
|
|
|
198
198
|
eventSchemas?: Record<string, EventSchemaOverride>;
|
|
199
199
|
auth?: AuthConfig;
|
|
200
200
|
resources?: ResourceItem[];
|
|
201
|
+
additionalResources?: ResourceItem[];
|
|
201
202
|
httpRoutes?: HttpRouteDef[];
|
|
202
203
|
onMessage?: OnMessageHook;
|
|
203
204
|
productName?: string;
|