@opencrvs/toolkit 2.2.0-rc.045257f → 2.2.0-rc.19ec10b
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/build.sh +7 -2
- package/dist/application-config/index.js +16 -5
- package/dist/authentication/index.d.ts +1 -1
- package/dist/authentication/index.js +4 -8
- package/dist/cli.js +927 -356
- package/dist/commons/api/router.d.ts +17 -4
- package/dist/commons/application-config/index.d.ts +1 -1
- package/dist/commons/conditionals/conditionals.d.ts +55 -4
- package/dist/commons/conditionals/validate.d.ts +1 -1
- package/dist/commons/events/ActionStatus.d.ts +2 -2
- package/dist/commons/events/ActionType.d.ts +2 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +3 -0
- package/dist/commons/events/Draft.d.ts +34 -1
- package/dist/commons/events/EventConfig.d.ts +446 -0
- package/dist/commons/events/EventDocument.d.ts +2 -0
- package/dist/commons/events/EventIndex.d.ts +1 -0
- package/dist/commons/events/EventInput.d.ts +1 -0
- package/dist/commons/events/EventMetadata.d.ts +1 -0
- package/dist/commons/events/FieldTypeMapping.d.ts +19 -19
- package/dist/commons/events/PlainDate.d.ts +5 -0
- package/dist/commons/events/defineConfig.d.ts +7 -2
- package/dist/commons/events/event.d.ts +20 -1
- package/dist/commons/events/field.d.ts +37 -0
- package/dist/commons/events/locations.d.ts +1 -1
- package/dist/commons/events/scopes.d.ts +2 -1
- package/dist/commons/events/state/index.d.ts +1 -0
- package/dist/commons/events/test.utils.d.ts +59 -6
- package/dist/commons/events/utils.d.ts +28 -2
- package/dist/commons/users/Role.d.ts +23 -0
- package/dist/commons/users/User.d.ts +263 -0
- package/dist/commons/users/authentication.d.ts +67 -0
- package/dist/commons/users/index.d.ts +5 -0
- package/dist/commons/users/roleValidations.d.ts +15 -0
- package/dist/commons/users/scopes.d.ts +1402 -0
- package/dist/commons/users/userReferences.d.ts +176 -0
- package/dist/conditionals/index.js +13 -5
- package/dist/environment/custom-types.d.ts +1 -0
- package/dist/environment/custom-types.d.ts.map +1 -1
- package/dist/environment/derived-variables.d.ts +8 -0
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +9 -0
- package/dist/environment/questions.d.ts +42 -9
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +70 -47
- package/dist/environment/registry.d.ts +15 -0
- package/dist/environment/registry.d.ts.map +1 -0
- package/dist/environment/registry.js +112 -0
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +104 -23
- package/dist/events/index.js +1627 -1100
- package/dist/migrations/add-notify-config.d.ts +40 -0
- package/dist/migrations/add-notify-config.d.ts.map +1 -0
- package/dist/migrations/add-notify-config.js +249 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +602 -143
- package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -1
- package/dist/migrations/move-declaration-to-declare-action.js +27 -144
- package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -1
- package/dist/migrations/read-declaration-through-helper.js +3 -61
- package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
- package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
- package/dist/migrations/resolve-versioned-event-config.js +353 -0
- package/dist/migrations/utils.d.ts +61 -0
- package/dist/migrations/utils.d.ts.map +1 -0
- package/dist/migrations/utils.js +218 -0
- package/dist/notification/index.js +707 -119
- package/dist/roles/index.d.ts +2 -0
- package/dist/roles/index.d.ts.map +1 -0
- package/dist/roles/index.js +730 -0
- package/dist/scopes/index.d.ts +0 -10
- package/dist/scopes/index.js +3 -7
- package/dist/templates/charts-values/dependencies/values.yaml +5 -2
- package/dist/templates/charts-values/opencrvs-services/values.yaml +2 -5
- package/dist/verify/endpoints.d.ts +11 -0
- package/dist/verify/endpoints.d.ts.map +1 -1
- package/dist/verify/endpoints.js +21 -27
- package/opencrvs-toolkit-2.2.0-rc.19ec10b.tgz +0 -0
- package/package.json +4 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +3 -5
- package/dist/environment/dockerhub.d.ts +0 -15
- package/dist/environment/dockerhub.d.ts.map +0 -1
- package/dist/environment/dockerhub.js +0 -104
- package/opencrvs-toolkit-2.2.0-rc.045257f.tgz +0 -0
|
@@ -0,0 +1,730 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/roles/index.ts
|
|
31
|
+
var roles_exports = {};
|
|
32
|
+
__export(roles_exports, {
|
|
33
|
+
Role: () => Role,
|
|
34
|
+
Roles: () => Roles,
|
|
35
|
+
defineRoles: () => defineRoles
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(roles_exports);
|
|
38
|
+
var z10 = __toESM(require("zod/v4"));
|
|
39
|
+
|
|
40
|
+
// ../commons/src/users/Role.ts
|
|
41
|
+
var import_zod = require("zod");
|
|
42
|
+
|
|
43
|
+
// ../commons/src/users/scopes.ts
|
|
44
|
+
var z8 = __toESM(require("zod/v4"));
|
|
45
|
+
var qs = __toESM(require("qs"));
|
|
46
|
+
|
|
47
|
+
// ../commons/src/uuid.ts
|
|
48
|
+
var import_uuid = require("uuid");
|
|
49
|
+
var z = __toESM(require("zod/v4"));
|
|
50
|
+
var UUID = z.uuid().brand("UUID");
|
|
51
|
+
|
|
52
|
+
// ../commons/src/users/authentication.ts
|
|
53
|
+
var import_jwt_decode = __toESM(require("jwt-decode"));
|
|
54
|
+
var z2 = __toESM(require("zod/v4"));
|
|
55
|
+
var TokenUserType = z2.enum(["user", "system"]);
|
|
56
|
+
var TokenWithBearer = z2.string().regex(/^Bearer\s/);
|
|
57
|
+
|
|
58
|
+
// ../commons/src/events/ActionType.ts
|
|
59
|
+
var z3 = __toESM(require("zod/v4"));
|
|
60
|
+
var ActionType = {
|
|
61
|
+
// Pre-declaration actions
|
|
62
|
+
DELETE: "DELETE",
|
|
63
|
+
CREATE: "CREATE",
|
|
64
|
+
NOTIFY: "NOTIFY",
|
|
65
|
+
// Declaration actions
|
|
66
|
+
DECLARE: "DECLARE",
|
|
67
|
+
REGISTER: "REGISTER",
|
|
68
|
+
EDIT: "EDIT",
|
|
69
|
+
// Declaration system actions. Non-configurable.
|
|
70
|
+
DUPLICATE_DETECTED: "DUPLICATE_DETECTED",
|
|
71
|
+
REJECT: "REJECT",
|
|
72
|
+
// REJECT_DECLARATION
|
|
73
|
+
MARK_AS_DUPLICATE: "MARK_AS_DUPLICATE",
|
|
74
|
+
MARK_AS_NOT_DUPLICATE: "MARK_AS_NOT_DUPLICATE",
|
|
75
|
+
ARCHIVE: "ARCHIVE",
|
|
76
|
+
UNARCHIVE: "UNARCHIVE",
|
|
77
|
+
// Record actions
|
|
78
|
+
PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
|
|
79
|
+
REQUEST_CORRECTION: "REQUEST_CORRECTION",
|
|
80
|
+
REJECT_CORRECTION: "REJECT_CORRECTION",
|
|
81
|
+
APPROVE_CORRECTION: "APPROVE_CORRECTION",
|
|
82
|
+
REVOKE_REGISTRATION: "REVOKE_REGISTRATION",
|
|
83
|
+
REINSTATE_REGISTRATION: "REINSTATE_REGISTRATION",
|
|
84
|
+
// General actions
|
|
85
|
+
READ: "READ",
|
|
86
|
+
ASSIGN: "ASSIGN",
|
|
87
|
+
UNASSIGN: "UNASSIGN",
|
|
88
|
+
// Custom action
|
|
89
|
+
CUSTOM: "CUSTOM"
|
|
90
|
+
};
|
|
91
|
+
var ConfirmableActions = [
|
|
92
|
+
ActionType.NOTIFY,
|
|
93
|
+
ActionType.DECLARE,
|
|
94
|
+
ActionType.EDIT,
|
|
95
|
+
ActionType.REGISTER,
|
|
96
|
+
ActionType.REJECT,
|
|
97
|
+
ActionType.ARCHIVE,
|
|
98
|
+
ActionType.UNARCHIVE,
|
|
99
|
+
ActionType.PRINT_CERTIFICATE,
|
|
100
|
+
ActionType.REQUEST_CORRECTION,
|
|
101
|
+
ActionType.APPROVE_CORRECTION,
|
|
102
|
+
ActionType.REJECT_CORRECTION,
|
|
103
|
+
ActionType.REVOKE_REGISTRATION,
|
|
104
|
+
ActionType.REINSTATE_REGISTRATION,
|
|
105
|
+
ActionType.CUSTOM
|
|
106
|
+
];
|
|
107
|
+
var ActionTypes = z3.enum([
|
|
108
|
+
"DELETE",
|
|
109
|
+
"CREATE",
|
|
110
|
+
"NOTIFY",
|
|
111
|
+
"DECLARE",
|
|
112
|
+
"EDIT",
|
|
113
|
+
"REGISTER",
|
|
114
|
+
"DUPLICATE_DETECTED",
|
|
115
|
+
"REJECT",
|
|
116
|
+
"MARK_AS_DUPLICATE",
|
|
117
|
+
"MARK_AS_NOT_DUPLICATE",
|
|
118
|
+
"ARCHIVE",
|
|
119
|
+
"UNARCHIVE",
|
|
120
|
+
"PRINT_CERTIFICATE",
|
|
121
|
+
"REQUEST_CORRECTION",
|
|
122
|
+
"REJECT_CORRECTION",
|
|
123
|
+
"APPROVE_CORRECTION",
|
|
124
|
+
"REVOKE_REGISTRATION",
|
|
125
|
+
"REINSTATE_REGISTRATION",
|
|
126
|
+
"READ",
|
|
127
|
+
"ASSIGN",
|
|
128
|
+
"UNASSIGN",
|
|
129
|
+
"CUSTOM"
|
|
130
|
+
]);
|
|
131
|
+
var declarationActionValues = [
|
|
132
|
+
ActionTypes.enum.DECLARE,
|
|
133
|
+
ActionTypes.enum.EDIT,
|
|
134
|
+
ActionTypes.enum.REGISTER,
|
|
135
|
+
ActionTypes.enum.NOTIFY,
|
|
136
|
+
ActionTypes.enum.DUPLICATE_DETECTED
|
|
137
|
+
];
|
|
138
|
+
var DeclarationActions = ActionTypes.extract(declarationActionValues);
|
|
139
|
+
var declarationUpdateActionValues = [
|
|
140
|
+
...declarationActionValues,
|
|
141
|
+
ActionTypes.enum.REQUEST_CORRECTION
|
|
142
|
+
];
|
|
143
|
+
var DeclarationUpdateActions = ActionTypes.extract(
|
|
144
|
+
declarationUpdateActionValues
|
|
145
|
+
);
|
|
146
|
+
var annotationActions = ActionTypes.exclude(declarationActionValues);
|
|
147
|
+
var writeActions = ActionTypes.exclude([
|
|
148
|
+
ActionType.CREATE,
|
|
149
|
+
ActionType.READ,
|
|
150
|
+
ActionType.ASSIGN,
|
|
151
|
+
ActionType.UNASSIGN
|
|
152
|
+
]);
|
|
153
|
+
var WorkqueueActionType = ActionTypes.extract([
|
|
154
|
+
ActionType.READ,
|
|
155
|
+
ActionType.DELETE,
|
|
156
|
+
ActionType.DECLARE,
|
|
157
|
+
ActionType.REGISTER,
|
|
158
|
+
ActionType.EDIT,
|
|
159
|
+
ActionType.REJECT,
|
|
160
|
+
ActionType.MARK_AS_DUPLICATE,
|
|
161
|
+
ActionType.ARCHIVE,
|
|
162
|
+
ActionType.UNARCHIVE,
|
|
163
|
+
ActionType.PRINT_CERTIFICATE,
|
|
164
|
+
ActionType.REQUEST_CORRECTION,
|
|
165
|
+
ActionType.REVOKE_REGISTRATION,
|
|
166
|
+
ActionType.REINSTATE_REGISTRATION
|
|
167
|
+
]);
|
|
168
|
+
var META_ACTIONS = [
|
|
169
|
+
ActionType.ASSIGN,
|
|
170
|
+
ActionType.UNASSIGN,
|
|
171
|
+
ActionType.READ
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
// ../commons/src/events/ActionStatus.ts
|
|
175
|
+
var ActionStatus = {
|
|
176
|
+
Requested: "Requested",
|
|
177
|
+
Accepted: "Accepted",
|
|
178
|
+
Rejected: "Rejected"
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// ../commons/src/events/Flag.ts
|
|
182
|
+
var z6 = __toESM(require("zod"));
|
|
183
|
+
|
|
184
|
+
// ../commons/src/events/TranslationConfig.ts
|
|
185
|
+
var z4 = __toESM(require("zod/v4"));
|
|
186
|
+
var TranslationConfig = z4.object({
|
|
187
|
+
id: z4.string().describe(
|
|
188
|
+
"The identifier of the translation referred in translation CSV files"
|
|
189
|
+
),
|
|
190
|
+
defaultMessage: z4.string().describe("Default translation message"),
|
|
191
|
+
description: z4.string().describe(
|
|
192
|
+
"Describe the translation for a translator to be able to identify it."
|
|
193
|
+
)
|
|
194
|
+
}).meta({
|
|
195
|
+
description: "Translation configuration",
|
|
196
|
+
id: "TranslationConfig"
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// ../commons/src/events/Conditional.ts
|
|
200
|
+
var z5 = __toESM(require("zod/v4"));
|
|
201
|
+
var Conditional = z5.any().describe("JSONSchema").meta({
|
|
202
|
+
description: "JSON schema conditional configuration",
|
|
203
|
+
id: "Conditional"
|
|
204
|
+
});
|
|
205
|
+
var ConditionalType = {
|
|
206
|
+
SHOW: "SHOW",
|
|
207
|
+
ENABLE: "ENABLE",
|
|
208
|
+
DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
|
|
209
|
+
};
|
|
210
|
+
var ShowConditional = z5.object({
|
|
211
|
+
type: z5.literal(ConditionalType.SHOW),
|
|
212
|
+
conditional: Conditional
|
|
213
|
+
}).describe(
|
|
214
|
+
"If 'SHOW' conditional is defined, the component is shown to the user only if the condition is met"
|
|
215
|
+
);
|
|
216
|
+
var EnableConditional = z5.object({
|
|
217
|
+
type: z5.literal(ConditionalType.ENABLE),
|
|
218
|
+
conditional: Conditional
|
|
219
|
+
}).describe(
|
|
220
|
+
"If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
|
|
221
|
+
);
|
|
222
|
+
var ActionConditional = z5.discriminatedUnion("type", [
|
|
223
|
+
// Action can be shown / hidden
|
|
224
|
+
ShowConditional,
|
|
225
|
+
// Action can be shown to the user in the list but as disabled
|
|
226
|
+
EnableConditional
|
|
227
|
+
]).meta({
|
|
228
|
+
id: "ActionConditional",
|
|
229
|
+
description: "Conditional gating whether an action is shown (SHOW) or enabled (ENABLE). When omitted from an action, the action is shown and enabled for everyone."
|
|
230
|
+
});
|
|
231
|
+
var DisplayOnReviewConditional = z5.object({
|
|
232
|
+
type: z5.literal(ConditionalType.DISPLAY_ON_REVIEW),
|
|
233
|
+
conditional: Conditional
|
|
234
|
+
}).describe(
|
|
235
|
+
"If 'DISPLAY_ON_REVIEW' conditional is defined, the component is shown on the review page only if both the 'DISPLAY_ON_REVIEW' and 'SHOW' conditions are met. This should only be used for fields within declaration forms, as they are the only ones with review pages."
|
|
236
|
+
);
|
|
237
|
+
var FieldConditional = z5.discriminatedUnion("type", [
|
|
238
|
+
// Field input can be shown / hidden
|
|
239
|
+
ShowConditional,
|
|
240
|
+
// Field input can be shown to the user but as disabled
|
|
241
|
+
EnableConditional,
|
|
242
|
+
// Field output can be shown / hidden on the review page
|
|
243
|
+
DisplayOnReviewConditional
|
|
244
|
+
]).meta({
|
|
245
|
+
id: "FieldConditional",
|
|
246
|
+
description: "Conditional gating whether a form field is shown (SHOW), enabled (ENABLE), or displayed on the review page (DISPLAY_ON_REVIEW). When omitted, the field is shown and enabled for everyone, and is displayed on review whenever it has a value."
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// ../commons/src/events/Flag.ts
|
|
250
|
+
var InherentFlags = {
|
|
251
|
+
REJECTED: "rejected",
|
|
252
|
+
CORRECTION_REQUESTED: "correction-requested",
|
|
253
|
+
POTENTIAL_DUPLICATE: "potential-duplicate",
|
|
254
|
+
/**
|
|
255
|
+
* This flag is set by the Edit-action and removed after the declaration or registration.
|
|
256
|
+
* A record should never stay with the EDIT_IN_PROGRESS flag, since it should always be declared or registered right after.
|
|
257
|
+
*
|
|
258
|
+
* We only use this flag to determine that a NOTIFY, DECLARE or REGISTER action is allowed next.
|
|
259
|
+
*/
|
|
260
|
+
EDIT_IN_PROGRESS: "edit-in-progress"
|
|
261
|
+
};
|
|
262
|
+
var actionFlagPattern;
|
|
263
|
+
function getActionFlagPattern() {
|
|
264
|
+
actionFlagPattern ??= new RegExp(
|
|
265
|
+
`^(${Object.values(ActionType).join("|").toLowerCase()}):(${Object.values(
|
|
266
|
+
ActionStatus
|
|
267
|
+
).join("|").toLowerCase()})$`
|
|
268
|
+
);
|
|
269
|
+
return actionFlagPattern;
|
|
270
|
+
}
|
|
271
|
+
var ActionFlag = z6.string().refine((value) => getActionFlagPattern().test(value), {
|
|
272
|
+
message: "Flag must be in the format ActionType:ActionStatus (lowerCase)"
|
|
273
|
+
});
|
|
274
|
+
var CustomFlag = z6.string().refine((val) => !Object.values(InherentFlags).includes(val), {
|
|
275
|
+
message: `Custom flag cannot be one of the inherent flags: ${Object.values(
|
|
276
|
+
InherentFlags
|
|
277
|
+
).join(", ")}`
|
|
278
|
+
}).refine((val) => !ActionFlag.validate(val), {
|
|
279
|
+
message: "Custom flag cannot match the ActionFlag pattern (ActionType:ActionStatus)."
|
|
280
|
+
}).describe("Custom flag identifier defined by the country config.");
|
|
281
|
+
var Flag = ActionFlag.or(z6.enum(InherentFlags)).or(CustomFlag);
|
|
282
|
+
var ContainsFlags = z6.object({
|
|
283
|
+
anyOf: z6.array(Flag).optional(),
|
|
284
|
+
noneOf: z6.array(Flag).optional(),
|
|
285
|
+
allOf: z6.array(Flag).optional()
|
|
286
|
+
}).meta({
|
|
287
|
+
id: "ContainsFlags"
|
|
288
|
+
});
|
|
289
|
+
var FlagConfig = z6.object({
|
|
290
|
+
id: CustomFlag,
|
|
291
|
+
requiresAction: z6.boolean().describe(
|
|
292
|
+
"Indicates if this flag expects an action to be performed to be cleared."
|
|
293
|
+
),
|
|
294
|
+
label: TranslationConfig.describe("Human readable label of the flag.")
|
|
295
|
+
}).meta({
|
|
296
|
+
id: "FlagConfig",
|
|
297
|
+
description: "Configuration for a custom flag that can be added to or removed from records by event actions."
|
|
298
|
+
});
|
|
299
|
+
var ActionFlagConfig = z6.object({
|
|
300
|
+
id: Flag,
|
|
301
|
+
operation: z6.enum(["add", "remove"]).describe("Operation to perform on the flag."),
|
|
302
|
+
conditional: Conditional.optional().describe(
|
|
303
|
+
"When conditional is met, the operation is performed on the flag. If not provided, the operation is performed unconditionally."
|
|
304
|
+
)
|
|
305
|
+
}).meta({
|
|
306
|
+
id: "ActionFlagConfig",
|
|
307
|
+
description: "Add or remove operation applied to a flag when the parent action is accepted. Optionally gated by a conditional."
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
// ../commons/src/events/EventStatus.ts
|
|
311
|
+
var z7 = __toESM(require("zod/v4"));
|
|
312
|
+
var EventStatus = z7.enum([
|
|
313
|
+
"CREATED",
|
|
314
|
+
"NOTIFIED",
|
|
315
|
+
"DECLARED",
|
|
316
|
+
"REGISTERED",
|
|
317
|
+
"REVOKED",
|
|
318
|
+
"ARCHIVED"
|
|
319
|
+
]);
|
|
320
|
+
|
|
321
|
+
// ../commons/src/users/scopes.ts
|
|
322
|
+
var JurisdictionFilter = z8.enum(["administrativeArea", "location", "all"]).describe(
|
|
323
|
+
"Filters based on user jurisdiction relative to their office location in hierarchy."
|
|
324
|
+
);
|
|
325
|
+
var UserFilter = z8.enum(["user"]).describe("Filters based on the user. Limits to self.");
|
|
326
|
+
var RecordScopeTypeV2 = z8.enum([
|
|
327
|
+
"record.search",
|
|
328
|
+
"record.create",
|
|
329
|
+
"record.read",
|
|
330
|
+
"record.declare",
|
|
331
|
+
"record.notify",
|
|
332
|
+
"record.edit",
|
|
333
|
+
"record.reject",
|
|
334
|
+
"record.archive",
|
|
335
|
+
"record.unarchive",
|
|
336
|
+
"record.review-duplicates",
|
|
337
|
+
"record.register",
|
|
338
|
+
"record.print-certified-copies",
|
|
339
|
+
"record.request-correction",
|
|
340
|
+
"record.correct",
|
|
341
|
+
"record.revoke-registration",
|
|
342
|
+
"record.reinstate-registration",
|
|
343
|
+
"record.unassign-others",
|
|
344
|
+
"record.custom-action",
|
|
345
|
+
"record.action.accept",
|
|
346
|
+
"record.action.reject"
|
|
347
|
+
]);
|
|
348
|
+
var PlainScopeType = z8.enum([
|
|
349
|
+
// Misc. system scopes
|
|
350
|
+
"bypassratelimit",
|
|
351
|
+
"record.reindex",
|
|
352
|
+
"user.data-seeding",
|
|
353
|
+
"integration.create",
|
|
354
|
+
// Reading an integration's audit log. Deliberately separate from
|
|
355
|
+
// 'integration.create' so read-only oversight can be granted on its own, and
|
|
356
|
+
// deliberately option-less: system clients have no office and no
|
|
357
|
+
// administrative area, so jurisdiction options would have nothing to bind to.
|
|
358
|
+
"integration.audit.read",
|
|
359
|
+
"record.import",
|
|
360
|
+
"config.update-all",
|
|
361
|
+
"location.edit",
|
|
362
|
+
"attachment.upload",
|
|
363
|
+
"profile.electronic-signature",
|
|
364
|
+
"user.read-only-my-audit",
|
|
365
|
+
// Performance dashboard
|
|
366
|
+
"performance.read",
|
|
367
|
+
"performance.read-dashboards",
|
|
368
|
+
"performance.vital-statistics-export"
|
|
369
|
+
]);
|
|
370
|
+
var scopeByEvent = z8.preprocess(
|
|
371
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
372
|
+
z8.array(z8.string()).optional()
|
|
373
|
+
).describe("Event type, e.g. birth, death");
|
|
374
|
+
var scopeByStatus = z8.preprocess(
|
|
375
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
376
|
+
z8.array(EventStatus).optional()
|
|
377
|
+
).describe(
|
|
378
|
+
"Restricts the scope to records currently in one of these statuses."
|
|
379
|
+
);
|
|
380
|
+
var userRole = z8.preprocess(
|
|
381
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
382
|
+
z8.array(z8.string()).optional()
|
|
383
|
+
).describe("User role, e.g. admin, field agent");
|
|
384
|
+
var scopeOptionsPlaceEvent = z8.object({
|
|
385
|
+
event: scopeByEvent,
|
|
386
|
+
placeOfEvent: JurisdictionFilter.optional(),
|
|
387
|
+
createdBy: UserFilter.optional(),
|
|
388
|
+
createdIn: JurisdictionFilter.optional()
|
|
389
|
+
}).describe("Options applicable to all record scopes.");
|
|
390
|
+
var scopeOptionsDeclaredOrNotified = scopeOptionsPlaceEvent.extend({
|
|
391
|
+
notifiedIn: JurisdictionFilter.optional(),
|
|
392
|
+
notifiedBy: UserFilter.optional(),
|
|
393
|
+
declaredIn: JurisdictionFilter.optional(),
|
|
394
|
+
declaredBy: UserFilter.optional(),
|
|
395
|
+
status: scopeByStatus
|
|
396
|
+
}).describe("Options applicable to actions that may take place after DECLARE");
|
|
397
|
+
var AllRecordScopeOptions = scopeOptionsDeclaredOrNotified.extend({
|
|
398
|
+
registeredIn: JurisdictionFilter.optional(),
|
|
399
|
+
registeredBy: UserFilter.optional(),
|
|
400
|
+
flags: ContainsFlags.optional()
|
|
401
|
+
}).describe(
|
|
402
|
+
"Options applicable to actions that may take place after REGISTER, with full filtering capabilities."
|
|
403
|
+
);
|
|
404
|
+
var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
405
|
+
customActionTypes: z8.preprocess(
|
|
406
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
407
|
+
z8.array(z8.string()).optional()
|
|
408
|
+
).describe("Allowed custom action types")
|
|
409
|
+
});
|
|
410
|
+
var AccessLevelOptions = z8.object({
|
|
411
|
+
accessLevel: JurisdictionFilter.optional()
|
|
412
|
+
});
|
|
413
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
414
|
+
role: userRole.optional()
|
|
415
|
+
});
|
|
416
|
+
var WorkqueueOrDashboardOptions = z8.object({
|
|
417
|
+
ids: z8.preprocess(
|
|
418
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
419
|
+
z8.array(z8.string())
|
|
420
|
+
).describe("Must contain a list of workqueue or dashboard ids.")
|
|
421
|
+
});
|
|
422
|
+
var AllScopeOptions = z8.object({
|
|
423
|
+
...AllRecordScopeOptions.shape,
|
|
424
|
+
...AccessLevelOptions.shape,
|
|
425
|
+
...AllUserScopeOptions.shape,
|
|
426
|
+
...WorkqueueOrDashboardOptions.shape
|
|
427
|
+
});
|
|
428
|
+
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
429
|
+
var ResolvedScopeOptionsPlaceEvent = z8.object({
|
|
430
|
+
event: scopeByEvent,
|
|
431
|
+
placeOfEvent: UUID.nullish(),
|
|
432
|
+
createdBy: z8.string().optional(),
|
|
433
|
+
createdIn: UUID.nullish()
|
|
434
|
+
}).describe(
|
|
435
|
+
"Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
|
|
436
|
+
);
|
|
437
|
+
var ResolvedScopeOptionsDeclared = ResolvedScopeOptionsPlaceEvent.extend({
|
|
438
|
+
notifiedIn: UUID.nullish(),
|
|
439
|
+
notifiedBy: z8.string().optional(),
|
|
440
|
+
declaredIn: UUID.nullish(),
|
|
441
|
+
declaredBy: z8.string().optional()
|
|
442
|
+
}).describe(
|
|
443
|
+
"Resolved options applicable to actions that may take place after DECLARE, with location ID and user ID instead of filters."
|
|
444
|
+
);
|
|
445
|
+
var ResolvedScopeOptionsFull = ResolvedScopeOptionsDeclared.extend({
|
|
446
|
+
registeredIn: UUID.nullish(),
|
|
447
|
+
registeredBy: z8.string().optional(),
|
|
448
|
+
flags: ContainsFlags.optional()
|
|
449
|
+
}).describe(
|
|
450
|
+
"Resolved options applicable to actions that may take place after REGISTER, with full filtering capabilities and location/user IDs instead of filters."
|
|
451
|
+
);
|
|
452
|
+
var ScopesWithPlaceEventOptions = RecordScopeTypeV2.extract([
|
|
453
|
+
"record.create",
|
|
454
|
+
"record.declare",
|
|
455
|
+
"record.notify"
|
|
456
|
+
]);
|
|
457
|
+
var ScopesWithDeclaredOptions = RecordScopeTypeV2.extract([
|
|
458
|
+
"record.edit",
|
|
459
|
+
"record.reject",
|
|
460
|
+
"record.archive",
|
|
461
|
+
"record.unarchive",
|
|
462
|
+
"record.register"
|
|
463
|
+
]);
|
|
464
|
+
var ScopesWithFullOptions = RecordScopeTypeV2.extract([
|
|
465
|
+
"record.search",
|
|
466
|
+
"record.read",
|
|
467
|
+
"record.request-correction",
|
|
468
|
+
"record.correct",
|
|
469
|
+
"record.revoke-registration",
|
|
470
|
+
"record.reinstate-registration",
|
|
471
|
+
"record.unassign-others",
|
|
472
|
+
"record.review-duplicates"
|
|
473
|
+
]);
|
|
474
|
+
var ScopeOptionsPrintCertifiedCopies = AllRecordScopeOptions.extend({
|
|
475
|
+
templates: z8.preprocess(
|
|
476
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
477
|
+
z8.array(z8.string()).optional()
|
|
478
|
+
).describe(
|
|
479
|
+
"Template IDs for certified copies. Controls which certificate templates are returned to the client via the config service. Certificate printing is a client-side operation \u2014 this option is not validated when the printCertificate action is submitted."
|
|
480
|
+
)
|
|
481
|
+
});
|
|
482
|
+
var ActionConfirmationScopeType = RecordScopeTypeV2.extract([
|
|
483
|
+
"record.action.accept",
|
|
484
|
+
"record.action.reject"
|
|
485
|
+
]);
|
|
486
|
+
var ActionConfirmationScopeOptions = AllRecordScopeOptions.describe(
|
|
487
|
+
"Options for confirming (accepting or rejecting) an action."
|
|
488
|
+
);
|
|
489
|
+
var RecordScopeV2 = z8.discriminatedUnion("type", [
|
|
490
|
+
z8.object({
|
|
491
|
+
type: ScopesWithPlaceEventOptions,
|
|
492
|
+
options: scopeOptionsPlaceEvent.optional()
|
|
493
|
+
}),
|
|
494
|
+
z8.object({
|
|
495
|
+
type: ScopesWithDeclaredOptions,
|
|
496
|
+
options: scopeOptionsDeclaredOrNotified.optional()
|
|
497
|
+
}),
|
|
498
|
+
z8.object({
|
|
499
|
+
type: ScopesWithFullOptions,
|
|
500
|
+
options: AllRecordScopeOptions.optional()
|
|
501
|
+
}),
|
|
502
|
+
z8.object({
|
|
503
|
+
type: z8.literal("record.custom-action"),
|
|
504
|
+
options: CustomActionScopeOptions.optional()
|
|
505
|
+
}),
|
|
506
|
+
z8.object({
|
|
507
|
+
type: z8.literal("record.print-certified-copies"),
|
|
508
|
+
options: ScopeOptionsPrintCertifiedCopies.optional()
|
|
509
|
+
}),
|
|
510
|
+
z8.object({
|
|
511
|
+
type: ActionConfirmationScopeType,
|
|
512
|
+
options: ActionConfirmationScopeOptions.optional()
|
|
513
|
+
})
|
|
514
|
+
]).describe(
|
|
515
|
+
"Scopes used to check user's permission to perform actions on a record."
|
|
516
|
+
);
|
|
517
|
+
var SystemScopeType = z8.enum([
|
|
518
|
+
"organisation.read-locations",
|
|
519
|
+
"user.read",
|
|
520
|
+
"user.create",
|
|
521
|
+
"user.edit",
|
|
522
|
+
"user.search"
|
|
523
|
+
]);
|
|
524
|
+
var UserScopeType = SystemScopeType.extract([
|
|
525
|
+
"user.read",
|
|
526
|
+
"user.create",
|
|
527
|
+
"user.edit",
|
|
528
|
+
"user.search"
|
|
529
|
+
]);
|
|
530
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
531
|
+
var UserScopeV2 = z8.discriminatedUnion("type", [
|
|
532
|
+
z8.object({
|
|
533
|
+
type: ScopesWithRoleOption,
|
|
534
|
+
options: AllUserScopeOptions.optional()
|
|
535
|
+
}),
|
|
536
|
+
z8.object({
|
|
537
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
538
|
+
options: AccessLevelOptions.optional()
|
|
539
|
+
})
|
|
540
|
+
]);
|
|
541
|
+
var ResolvedRecordScopeV2 = z8.discriminatedUnion("type", [
|
|
542
|
+
z8.object({
|
|
543
|
+
type: ScopesWithPlaceEventOptions,
|
|
544
|
+
options: ResolvedScopeOptionsPlaceEvent.optional()
|
|
545
|
+
}),
|
|
546
|
+
z8.object({
|
|
547
|
+
type: ScopesWithDeclaredOptions,
|
|
548
|
+
options: ResolvedScopeOptionsDeclared.optional()
|
|
549
|
+
}),
|
|
550
|
+
z8.object({
|
|
551
|
+
type: ScopesWithFullOptions,
|
|
552
|
+
options: ResolvedScopeOptionsFull.optional()
|
|
553
|
+
}),
|
|
554
|
+
z8.object({
|
|
555
|
+
type: z8.literal("record.print-certified-copies"),
|
|
556
|
+
options: ResolvedScopeOptionsFull.extend({
|
|
557
|
+
templates: z8.array(z8.string()).optional()
|
|
558
|
+
}).optional()
|
|
559
|
+
})
|
|
560
|
+
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
561
|
+
var Scope2 = z8.discriminatedUnion("type", [
|
|
562
|
+
z8.object({ type: PlainScopeType }),
|
|
563
|
+
...RecordScopeV2.options,
|
|
564
|
+
...UserScopeV2.options,
|
|
565
|
+
z8.object({
|
|
566
|
+
type: z8.literal("organisation.read-locations"),
|
|
567
|
+
options: AccessLevelOptions.optional()
|
|
568
|
+
}),
|
|
569
|
+
z8.object({
|
|
570
|
+
type: z8.literal("workqueue"),
|
|
571
|
+
options: WorkqueueOrDashboardOptions
|
|
572
|
+
}),
|
|
573
|
+
z8.object({
|
|
574
|
+
type: z8.literal("dashboard.view"),
|
|
575
|
+
options: WorkqueueOrDashboardOptions
|
|
576
|
+
})
|
|
577
|
+
]);
|
|
578
|
+
var ScopeType2 = z8.enum([
|
|
579
|
+
...SystemScopeType.options,
|
|
580
|
+
...RecordScopeTypeV2.options,
|
|
581
|
+
...PlainScopeType.options,
|
|
582
|
+
"workqueue",
|
|
583
|
+
"dashboard.view"
|
|
584
|
+
]);
|
|
585
|
+
var unflattenScope = (input) => {
|
|
586
|
+
const { type, ...options } = input;
|
|
587
|
+
return { type, options };
|
|
588
|
+
};
|
|
589
|
+
var EncodedScope2 = z8.string().brand("EncodedScope");
|
|
590
|
+
var decodedScopeCache = /* @__PURE__ */ new Map();
|
|
591
|
+
var decodeScope = (encodedScope) => {
|
|
592
|
+
if (decodedScopeCache.has(encodedScope)) {
|
|
593
|
+
return decodedScopeCache.get(encodedScope);
|
|
594
|
+
}
|
|
595
|
+
const scope = qs.parse(encodedScope, {
|
|
596
|
+
ignoreQueryPrefix: true,
|
|
597
|
+
comma: true,
|
|
598
|
+
allowDots: true
|
|
599
|
+
});
|
|
600
|
+
const unflattenedScope = unflattenScope(scope);
|
|
601
|
+
const result = Scope2.safeParse(unflattenedScope)?.data;
|
|
602
|
+
decodedScopeCache.set(encodedScope, result);
|
|
603
|
+
return result;
|
|
604
|
+
};
|
|
605
|
+
var DEFAULT_SCOPE_OPTIONS = {
|
|
606
|
+
placeOfEvent: JurisdictionFilter.enum.all,
|
|
607
|
+
accessLevel: JurisdictionFilter.enum.all,
|
|
608
|
+
notifiedIn: JurisdictionFilter.enum.all,
|
|
609
|
+
declaredIn: JurisdictionFilter.enum.all,
|
|
610
|
+
registeredIn: JurisdictionFilter.enum.all
|
|
611
|
+
};
|
|
612
|
+
function getScopeOptionValue(scope, option) {
|
|
613
|
+
const options = "options" in scope ? scope.options : void 0;
|
|
614
|
+
const value = options?.[option];
|
|
615
|
+
const defaultValue = option in DEFAULT_SCOPE_OPTIONS ? DEFAULT_SCOPE_OPTIONS[option] : void 0;
|
|
616
|
+
return value ?? defaultValue;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// ../commons/src/users/roleValidations.ts
|
|
620
|
+
var import_lodash = require("lodash");
|
|
621
|
+
function eventsWithScope(role, type, include = () => true) {
|
|
622
|
+
const scopes = role.scopes.map(decodeScope).filter((scope) => scope?.type === type).filter(include);
|
|
623
|
+
const eventIds = scopes.map((scope) => getScopeOptionValue(scope, "event"));
|
|
624
|
+
if (eventIds.some((ids) => ids === void 0)) {
|
|
625
|
+
return "all";
|
|
626
|
+
}
|
|
627
|
+
return (0, import_lodash.uniq)(eventIds.flatMap((ids) => ids ?? []));
|
|
628
|
+
}
|
|
629
|
+
function overlap(a, b) {
|
|
630
|
+
if (a === "all") {
|
|
631
|
+
return b;
|
|
632
|
+
}
|
|
633
|
+
if (b === "all") {
|
|
634
|
+
return a;
|
|
635
|
+
}
|
|
636
|
+
return a.filter((id) => b.includes(id));
|
|
637
|
+
}
|
|
638
|
+
function describeEvents(events) {
|
|
639
|
+
if (events === "all") {
|
|
640
|
+
return "all events";
|
|
641
|
+
}
|
|
642
|
+
return events.length > 0 ? `events: ${events.join(", ")}` : void 0;
|
|
643
|
+
}
|
|
644
|
+
function matchesDeclared(scope) {
|
|
645
|
+
const status = getScopeOptionValue(scope, "status");
|
|
646
|
+
return status === void 0 || status.includes(EventStatus.enum.DECLARED);
|
|
647
|
+
}
|
|
648
|
+
function validateEventIds(role, eventConfigs) {
|
|
649
|
+
const eventIds = eventConfigs.map(({ id }) => id);
|
|
650
|
+
return role.scopes.flatMap((scope) => {
|
|
651
|
+
const decoded = decodeScope(scope);
|
|
652
|
+
const unknownIds = ((decoded && getScopeOptionValue(decoded, "event")) ?? []).filter((id) => !eventIds.includes(id));
|
|
653
|
+
return unknownIds.length > 0 ? [
|
|
654
|
+
`Scope "${scope}" contains invalid event IDs: ${unknownIds.join(", ")}`
|
|
655
|
+
] : [];
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
function validateNoNotifyAndDeclare(role) {
|
|
659
|
+
const events = describeEvents(
|
|
660
|
+
overlap(
|
|
661
|
+
eventsWithScope(role, "record.notify"),
|
|
662
|
+
eventsWithScope(role, "record.declare")
|
|
663
|
+
)
|
|
664
|
+
);
|
|
665
|
+
return events ? [
|
|
666
|
+
`record.notify and record.declare are both granted for ${events}. A role can notify or declare an event, not both.`
|
|
667
|
+
] : [];
|
|
668
|
+
}
|
|
669
|
+
function validateNoNotifyAndEditDeclared(role) {
|
|
670
|
+
const events = describeEvents(
|
|
671
|
+
overlap(
|
|
672
|
+
eventsWithScope(role, "record.notify"),
|
|
673
|
+
eventsWithScope(role, "record.edit", matchesDeclared)
|
|
674
|
+
)
|
|
675
|
+
);
|
|
676
|
+
return events ? [
|
|
677
|
+
`record.notify and a record.edit that can match DECLARED records are both granted for ${events}. Limit the role's record.edit to status NOTIFIED.`
|
|
678
|
+
] : [];
|
|
679
|
+
}
|
|
680
|
+
function validateNotifyConfigExistsIfItsUsedInRole(role, eventConfigs) {
|
|
681
|
+
const notified = eventsWithScope(role, "record.notify");
|
|
682
|
+
const withoutNotifyAction = eventConfigs.filter(({ id }) => notified === "all" || notified.includes(id)).filter(
|
|
683
|
+
({ versions }) => versions.every(
|
|
684
|
+
({ actions }) => actions.every(({ type }) => type !== ActionType.NOTIFY)
|
|
685
|
+
)
|
|
686
|
+
).map(({ id }) => id);
|
|
687
|
+
return withoutNotifyAction.length > 0 ? [
|
|
688
|
+
`record.notify is granted for events without a NOTIFY action: ${withoutNotifyAction.join(", ")}`
|
|
689
|
+
] : [];
|
|
690
|
+
}
|
|
691
|
+
function validateRole(role, eventConfigs) {
|
|
692
|
+
return [
|
|
693
|
+
...validateEventIds(role, eventConfigs),
|
|
694
|
+
...validateNotifyConfigExistsIfItsUsedInRole(role, eventConfigs),
|
|
695
|
+
...validateNoNotifyAndDeclare(role),
|
|
696
|
+
...validateNoNotifyAndEditDeclared(role)
|
|
697
|
+
];
|
|
698
|
+
}
|
|
699
|
+
function validateRoles(roles, eventConfigs) {
|
|
700
|
+
const validationErrors = roles.flatMap(
|
|
701
|
+
(role) => validateRole(role, eventConfigs).map(
|
|
702
|
+
(error) => `- Role '${role.id}': ${error}`
|
|
703
|
+
)
|
|
704
|
+
);
|
|
705
|
+
if (validationErrors.length) {
|
|
706
|
+
throw new Error(`Invalid roles:
|
|
707
|
+
${validationErrors.join("\n")}`);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// ../commons/src/users/Role.ts
|
|
712
|
+
var Role = import_zod.z.object({
|
|
713
|
+
id: import_zod.z.string().min(1),
|
|
714
|
+
scopes: import_zod.z.array(
|
|
715
|
+
EncodedScope2.superRefine((scope, ctx) => {
|
|
716
|
+
if (!decodeScope(scope)) {
|
|
717
|
+
ctx.addIssue({ code: "custom", message: `Invalid scope: "${scope}"` });
|
|
718
|
+
}
|
|
719
|
+
})
|
|
720
|
+
)
|
|
721
|
+
});
|
|
722
|
+
var Roles = import_zod.z.array(Role);
|
|
723
|
+
function defineRoles(roles, eventConfigs) {
|
|
724
|
+
const parsed = Roles.parse(roles);
|
|
725
|
+
validateRoles(parsed, eventConfigs);
|
|
726
|
+
return parsed;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// src/roles/index.ts
|
|
730
|
+
z10.globalRegistry.clear();
|