@opencrvs/toolkit 2.0.0-rc.e1f588f → 2.0.0-rc.e52417d
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/dist/application-config/index.js +39 -11
- package/dist/cli.js +145 -47
- package/dist/commons/api/router.d.ts +33 -24
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/FieldConfig.d.ts +5 -0
- package/dist/commons/events/locations.d.ts +17 -1
- package/dist/conditionals/index.js +35 -7
- package/dist/events/index.js +73 -7
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +60 -35
- package/dist/migrations/v2.0/index.js +145 -47
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +90 -1
- package/dist/notification/index.js +35 -7
- package/dist/scopes/index.d.ts +82 -10
- package/dist/scopes/index.js +41 -8
- package/opencrvs-toolkit-2.0.0-rc.e52417d.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.e1f588f.tgz +0 -0
|
@@ -41,6 +41,10 @@ exports.main = main;
|
|
|
41
41
|
* - Removes the `deduplication` property from those objects
|
|
42
42
|
* - Replaces `review: { fields: <value> }` with `form: <value>`, or
|
|
43
43
|
* `review: <expr>` with `form: <expr>.fields` when the value is not an inline object
|
|
44
|
+
* - Adds the top-level `validated` flag definition and `{ id: 'validated',
|
|
45
|
+
* operation: 'add' }` to the (now custom) validate action
|
|
46
|
+
* - Adds `{ id: 'validated', operation: 'remove' }` to every `REGISTER` action
|
|
47
|
+
* in the same config, closing the flag's lifecycle when registration happens
|
|
44
48
|
* - Saves the modified files in-place
|
|
45
49
|
*/
|
|
46
50
|
const ts_morph_1 = require("ts-morph");
|
|
@@ -74,6 +78,8 @@ function ensureImports(sourceFile) {
|
|
|
74
78
|
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
75
79
|
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
76
80
|
const TYPE_PROPERTY_NAME = 'type';
|
|
81
|
+
const ID_PROPERTY_NAME = 'id';
|
|
82
|
+
const FLAGS_PROPERTY_NAME = 'flags';
|
|
77
83
|
const CUSTOM_ACTION_TYPE_PROPERTY_NAME = 'customActionType';
|
|
78
84
|
const AUDIT_HISTORY_LABEL_PROPERTY_NAME = 'auditHistoryLabel';
|
|
79
85
|
const DEDUPLICATION_PROPERTY_NAME = 'deduplication';
|
|
@@ -83,9 +89,12 @@ const FORM_PROPERTY_NAME = 'form';
|
|
|
83
89
|
const ACTION_TYPE_ENUM_NAME = 'ActionType';
|
|
84
90
|
const VALIDATE_MEMBER_NAME = 'VALIDATE';
|
|
85
91
|
const CUSTOM_MEMBER_NAME = 'CUSTOM';
|
|
92
|
+
const REGISTER_MEMBER_NAME = 'REGISTER';
|
|
86
93
|
const VALIDATE_STRING_LITERAL = 'VALIDATE';
|
|
87
94
|
const CUSTOM_STRING_LITERAL = 'CUSTOM';
|
|
95
|
+
const REGISTER_STRING_LITERAL = 'REGISTER';
|
|
88
96
|
const VALIDATE_DECLARATION_VALUE = 'VALIDATE_DECLARATION';
|
|
97
|
+
const VALIDATED_FLAG_VALUE = 'validated';
|
|
89
98
|
function isValidateType(typeInitializer) {
|
|
90
99
|
// Matches: ActionType.VALIDATE
|
|
91
100
|
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
@@ -230,6 +239,72 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
230
239
|
}
|
|
231
240
|
return true;
|
|
232
241
|
}
|
|
242
|
+
function isRegisterAction(action) {
|
|
243
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME);
|
|
244
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
|
|
245
|
+
return false;
|
|
246
|
+
const typeInit = typeProperty.getInitializer();
|
|
247
|
+
if (!typeInit)
|
|
248
|
+
return false;
|
|
249
|
+
// Matches: ActionType.REGISTER
|
|
250
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(typeInit)) {
|
|
251
|
+
const enumExpr = typeInit.getExpression();
|
|
252
|
+
return (ts_morph_1.Node.isIdentifier(enumExpr) &&
|
|
253
|
+
enumExpr.getText() === ACTION_TYPE_ENUM_NAME &&
|
|
254
|
+
typeInit.getName() === REGISTER_MEMBER_NAME);
|
|
255
|
+
}
|
|
256
|
+
// Matches: "REGISTER"
|
|
257
|
+
if (ts_morph_1.Node.isStringLiteral(typeInit)) {
|
|
258
|
+
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL;
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Returns true if an array literal contains an object literal with `id: <id>`.
|
|
264
|
+
*/
|
|
265
|
+
function arrayHasElementWithId(array, id) {
|
|
266
|
+
for (const el of array.getElements()) {
|
|
267
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(el))
|
|
268
|
+
continue;
|
|
269
|
+
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
270
|
+
if (!idProp || !ts_morph_1.Node.isPropertyAssignment(idProp))
|
|
271
|
+
continue;
|
|
272
|
+
const idInit = idProp.getInitializer();
|
|
273
|
+
if (idInit &&
|
|
274
|
+
ts_morph_1.Node.isStringLiteral(idInit) &&
|
|
275
|
+
idInit.getLiteralValue() === id) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Adds `{ id: 'validated', operation: 'remove' }` to a REGISTER action's
|
|
283
|
+
* `flags` array. Skips if any `validated` flag entry is already present —
|
|
284
|
+
* this keeps the codemod idempotent and avoids stomping on an intentional
|
|
285
|
+
* `add` op a maintainer may have authored manually.
|
|
286
|
+
*
|
|
287
|
+
* Returns true if a change was made.
|
|
288
|
+
*/
|
|
289
|
+
function ensureRegisterRemovesValidatedFlag(action) {
|
|
290
|
+
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
291
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
292
|
+
if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
|
|
293
|
+
const flagsInit = flagsProp.getInitializer();
|
|
294
|
+
if (flagsInit && ts_morph_1.Node.isArrayLiteralExpression(flagsInit)) {
|
|
295
|
+
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE))
|
|
296
|
+
return false;
|
|
297
|
+
flagsInit.addElement(entry);
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
action.addPropertyAssignment({
|
|
303
|
+
name: FLAGS_PROPERTY_NAME,
|
|
304
|
+
initializer: `[${entry}]`
|
|
305
|
+
});
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
233
308
|
function processFile(filePath, project) {
|
|
234
309
|
const sourceFile = project.getSourceFile(filePath);
|
|
235
310
|
if (!sourceFile)
|
|
@@ -297,6 +372,20 @@ function processFile(filePath, project) {
|
|
|
297
372
|
});
|
|
298
373
|
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`);
|
|
299
374
|
}
|
|
375
|
+
// Close the `validated` flag's lifecycle: when the validate action adds the
|
|
376
|
+
// flag, the matching REGISTER action(s) must remove it on registration.
|
|
377
|
+
if (configHadValidateAction) {
|
|
378
|
+
for (const element of actionsInitializer.getElements()) {
|
|
379
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
380
|
+
continue;
|
|
381
|
+
if (!isRegisterAction(element))
|
|
382
|
+
continue;
|
|
383
|
+
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
384
|
+
transformedCount++;
|
|
385
|
+
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
300
389
|
if (fileNeedsImports) {
|
|
301
390
|
ensureImports(sourceFile);
|
|
302
391
|
}
|
|
@@ -338,6 +427,6 @@ function main() {
|
|
|
338
427
|
yield sourceFile.save();
|
|
339
428
|
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
340
429
|
}
|
|
341
|
-
console.log(`\nDone.
|
|
430
|
+
console.log(`\nDone. Applied ${totalTransformed} change(s): VALIDATE → CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`);
|
|
342
431
|
});
|
|
343
432
|
}
|
|
@@ -110,6 +110,10 @@ var scopeByEvent = z2.preprocess(
|
|
|
110
110
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
111
111
|
z2.array(z2.string()).optional()
|
|
112
112
|
).describe("Event type, e.g. birth, death");
|
|
113
|
+
var userRole = z2.preprocess(
|
|
114
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
115
|
+
z2.array(z2.string()).optional()
|
|
116
|
+
).describe("User role, e.g. admin, field agent");
|
|
113
117
|
var scopeOptionsPlaceEvent = z2.object({
|
|
114
118
|
event: scopeByEvent,
|
|
115
119
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -133,6 +137,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
133
137
|
var AccessLevelOptions = z2.object({
|
|
134
138
|
accessLevel: JurisdictionFilter.optional()
|
|
135
139
|
});
|
|
140
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
141
|
+
role: userRole.optional()
|
|
142
|
+
});
|
|
136
143
|
var WorkqueueOrDashboardOptions = z2.object({
|
|
137
144
|
ids: z2.preprocess(
|
|
138
145
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -142,6 +149,7 @@ var WorkqueueOrDashboardOptions = z2.object({
|
|
|
142
149
|
var AllScopeOptions = z2.object({
|
|
143
150
|
...AllRecordScopeOptions.shape,
|
|
144
151
|
...AccessLevelOptions.shape,
|
|
152
|
+
...AllUserScopeOptions.shape,
|
|
145
153
|
...WorkqueueOrDashboardOptions.shape
|
|
146
154
|
});
|
|
147
155
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -214,6 +222,28 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
|
|
|
214
222
|
]).describe(
|
|
215
223
|
"Scopes used to check user's permission to perform actions on a record."
|
|
216
224
|
);
|
|
225
|
+
var SystemScopeType = z2.enum([
|
|
226
|
+
"organisation.read-locations",
|
|
227
|
+
"user.read",
|
|
228
|
+
"user.create",
|
|
229
|
+
"user.edit"
|
|
230
|
+
]);
|
|
231
|
+
var UserScopeType = SystemScopeType.extract([
|
|
232
|
+
"user.read",
|
|
233
|
+
"user.create",
|
|
234
|
+
"user.edit"
|
|
235
|
+
]);
|
|
236
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
237
|
+
var UserScopeV2 = z2.discriminatedUnion("type", [
|
|
238
|
+
z2.object({
|
|
239
|
+
type: ScopesWithRoleOption,
|
|
240
|
+
options: AllUserScopeOptions.optional()
|
|
241
|
+
}),
|
|
242
|
+
z2.object({
|
|
243
|
+
type: UserScopeType.extract(["user.read"]),
|
|
244
|
+
options: AccessLevelOptions.optional()
|
|
245
|
+
})
|
|
246
|
+
]);
|
|
217
247
|
var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
|
|
218
248
|
z2.object({
|
|
219
249
|
type: ScopesWithPlaceEventOptions,
|
|
@@ -234,16 +264,14 @@ var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
|
|
|
234
264
|
}).optional()
|
|
235
265
|
})
|
|
236
266
|
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
237
|
-
var SystemScopeType = z2.enum([
|
|
238
|
-
"organisation.read-locations",
|
|
239
|
-
"user.read",
|
|
240
|
-
"user.create",
|
|
241
|
-
"user.edit"
|
|
242
|
-
]);
|
|
243
267
|
var Scope = z2.discriminatedUnion("type", [
|
|
244
268
|
z2.object({ type: PlainScopeType }),
|
|
245
269
|
...RecordScopeV2.options,
|
|
246
|
-
|
|
270
|
+
...UserScopeV2.options,
|
|
271
|
+
z2.object({
|
|
272
|
+
type: z2.literal("organisation.read-locations"),
|
|
273
|
+
options: AccessLevelOptions.optional()
|
|
274
|
+
}),
|
|
247
275
|
z2.object({
|
|
248
276
|
type: z2.literal("workqueue"),
|
|
249
277
|
options: WorkqueueOrDashboardOptions
|
package/dist/scopes/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ declare const AllScopeOptions: z.ZodObject<{
|
|
|
41
41
|
location: "location";
|
|
42
42
|
all: "all";
|
|
43
43
|
}>>;
|
|
44
|
+
role: z.ZodOptional<z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>>;
|
|
44
45
|
event: z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
45
46
|
placeOfEvent: z.ZodOptional<z.ZodEnum<{
|
|
46
47
|
administrativeArea: "administrativeArea";
|
|
@@ -66,6 +67,7 @@ declare const AllScopeOptions: z.ZodObject<{
|
|
|
66
67
|
}, z.core.$strip>;
|
|
67
68
|
type AllScopeOptions = z.infer<typeof AllScopeOptions>;
|
|
68
69
|
export declare const ScopeOptionKey: z.ZodEnum<{
|
|
70
|
+
role: "role";
|
|
69
71
|
event: "event";
|
|
70
72
|
placeOfEvent: "placeOfEvent";
|
|
71
73
|
declaredIn: "declaredIn";
|
|
@@ -220,6 +222,53 @@ export declare const RecordScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
220
222
|
templates: z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
221
223
|
}, z.core.$strip>>;
|
|
222
224
|
}, z.core.$strip>], "type">;
|
|
225
|
+
declare const SystemScopeType: z.ZodEnum<{
|
|
226
|
+
"organisation.read-locations": "organisation.read-locations";
|
|
227
|
+
"user.read": "user.read";
|
|
228
|
+
"user.create": "user.create";
|
|
229
|
+
"user.edit": "user.edit";
|
|
230
|
+
}>;
|
|
231
|
+
export type SystemScopeType = z.infer<typeof SystemScopeType>;
|
|
232
|
+
declare const UserScopeType: z.ZodEnum<{
|
|
233
|
+
"user.read": "user.read";
|
|
234
|
+
"user.create": "user.create";
|
|
235
|
+
"user.edit": "user.edit";
|
|
236
|
+
}>;
|
|
237
|
+
export type UserScopeType = z.infer<typeof UserScopeType>;
|
|
238
|
+
declare const ScopesWithRoleOption: z.ZodEnum<{
|
|
239
|
+
"user.create": "user.create";
|
|
240
|
+
"user.edit": "user.edit";
|
|
241
|
+
}>;
|
|
242
|
+
export type ScopesWithRoleOption = z.infer<typeof ScopesWithRoleOption>;
|
|
243
|
+
export declare const UserScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
244
|
+
type: z.ZodEnum<{
|
|
245
|
+
"user.create": "user.create";
|
|
246
|
+
"user.edit": "user.edit";
|
|
247
|
+
}>;
|
|
248
|
+
options: z.ZodOptional<z.ZodObject<{
|
|
249
|
+
accessLevel: z.ZodOptional<z.ZodEnum<{
|
|
250
|
+
administrativeArea: "administrativeArea";
|
|
251
|
+
location: "location";
|
|
252
|
+
all: "all";
|
|
253
|
+
}>>;
|
|
254
|
+
role: z.ZodOptional<z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>>;
|
|
255
|
+
}, z.core.$strip>>;
|
|
256
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
257
|
+
type: z.ZodEnum<{
|
|
258
|
+
"user.read": "user.read";
|
|
259
|
+
}>;
|
|
260
|
+
options: z.ZodOptional<z.ZodObject<{
|
|
261
|
+
accessLevel: z.ZodOptional<z.ZodEnum<{
|
|
262
|
+
administrativeArea: "administrativeArea";
|
|
263
|
+
location: "location";
|
|
264
|
+
all: "all";
|
|
265
|
+
}>>;
|
|
266
|
+
}, z.core.$strip>>;
|
|
267
|
+
}, z.core.$strip>], "type">;
|
|
268
|
+
export type UserScopeV2 = z.infer<typeof UserScopeV2>;
|
|
269
|
+
export declare function scopeUsesRoleOptions(scope: UserScopeV2): scope is Extract<UserScopeV2, {
|
|
270
|
+
type: ScopesWithRoleOption;
|
|
271
|
+
}>;
|
|
223
272
|
export declare function scopeUsesDeclaredOptions(scope: Scope): scope is Extract<Scope, {
|
|
224
273
|
type: z.infer<typeof ScopesWithDeclaredOptions>;
|
|
225
274
|
}>;
|
|
@@ -286,13 +335,6 @@ export declare const ResolvedRecordScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject
|
|
|
286
335
|
}, z.core.$strip>], "type">;
|
|
287
336
|
export type RecordScopeV2 = z.infer<typeof RecordScopeV2>;
|
|
288
337
|
export type ResolvedRecordScopeV2 = z.infer<typeof ResolvedRecordScopeV2>;
|
|
289
|
-
declare const SystemScopeType: z.ZodEnum<{
|
|
290
|
-
"organisation.read-locations": "organisation.read-locations";
|
|
291
|
-
"user.read": "user.read";
|
|
292
|
-
"user.create": "user.create";
|
|
293
|
-
"user.edit": "user.edit";
|
|
294
|
-
}>;
|
|
295
|
-
export type SystemScopeType = z.infer<typeof SystemScopeType>;
|
|
296
338
|
/** The primary scope schema which gathers all scope types together. All scopes are discriminated by type and options are determined according to the type. */
|
|
297
339
|
export declare const Scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
298
340
|
type: z.ZodEnum<{
|
|
@@ -437,11 +479,30 @@ export declare const Scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
437
479
|
}, z.core.$strip>>;
|
|
438
480
|
}, z.core.$strip>, z.ZodObject<{
|
|
439
481
|
type: z.ZodEnum<{
|
|
440
|
-
"organisation.read-locations": "organisation.read-locations";
|
|
441
|
-
"user.read": "user.read";
|
|
442
482
|
"user.create": "user.create";
|
|
443
483
|
"user.edit": "user.edit";
|
|
444
484
|
}>;
|
|
485
|
+
options: z.ZodOptional<z.ZodObject<{
|
|
486
|
+
accessLevel: z.ZodOptional<z.ZodEnum<{
|
|
487
|
+
administrativeArea: "administrativeArea";
|
|
488
|
+
location: "location";
|
|
489
|
+
all: "all";
|
|
490
|
+
}>>;
|
|
491
|
+
role: z.ZodOptional<z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>>;
|
|
492
|
+
}, z.core.$strip>>;
|
|
493
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
494
|
+
type: z.ZodEnum<{
|
|
495
|
+
"user.read": "user.read";
|
|
496
|
+
}>;
|
|
497
|
+
options: z.ZodOptional<z.ZodObject<{
|
|
498
|
+
accessLevel: z.ZodOptional<z.ZodEnum<{
|
|
499
|
+
administrativeArea: "administrativeArea";
|
|
500
|
+
location: "location";
|
|
501
|
+
all: "all";
|
|
502
|
+
}>>;
|
|
503
|
+
}, z.core.$strip>>;
|
|
504
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
505
|
+
type: z.ZodLiteral<"organisation.read-locations">;
|
|
445
506
|
options: z.ZodOptional<z.ZodObject<{
|
|
446
507
|
accessLevel: z.ZodOptional<z.ZodEnum<{
|
|
447
508
|
administrativeArea: "administrativeArea";
|
|
@@ -567,10 +628,21 @@ export declare const decodeScope: (query: EncodedScope) => {
|
|
|
567
628
|
registeredBy?: "user" | undefined;
|
|
568
629
|
templates?: string[] | undefined;
|
|
569
630
|
} | undefined;
|
|
631
|
+
} | {
|
|
632
|
+
type: "user.create" | "user.edit";
|
|
633
|
+
options?: {
|
|
634
|
+
accessLevel?: "administrativeArea" | "location" | "all" | undefined;
|
|
635
|
+
role?: string[] | undefined;
|
|
636
|
+
} | undefined;
|
|
637
|
+
} | {
|
|
638
|
+
type: "user.read";
|
|
639
|
+
options?: {
|
|
640
|
+
accessLevel?: "administrativeArea" | "location" | "all" | undefined;
|
|
641
|
+
} | undefined;
|
|
570
642
|
} | {
|
|
571
643
|
type: "bypassratelimit" | "record.reindex" | "user.data-seeding" | "integration.create" | "record.import" | "config.update-all" | "attachment.upload" | "profile.electronic-signature" | "user.read-only-my-audit" | "performance.read" | "performance.read-dashboards" | "performance.vital-statistics-export" | "record.confirm-registration" | "record.reject-registration";
|
|
572
644
|
} | {
|
|
573
|
-
type: "organisation.read-locations"
|
|
645
|
+
type: "organisation.read-locations";
|
|
574
646
|
options?: {
|
|
575
647
|
accessLevel?: "administrativeArea" | "location" | "all" | undefined;
|
|
576
648
|
} | undefined;
|
package/dist/scopes/index.js
CHANGED
|
@@ -42,6 +42,7 @@ __export(scopes_exports, {
|
|
|
42
42
|
ScopesWithFullOptions: () => ScopesWithFullOptions,
|
|
43
43
|
ScopesWithPlaceEventOptions: () => ScopesWithPlaceEventOptions,
|
|
44
44
|
UserFilter: () => UserFilter,
|
|
45
|
+
UserScopeV2: () => UserScopeV2,
|
|
45
46
|
canUserCreateEvent: () => canUserCreateEvent,
|
|
46
47
|
decodeScope: () => decodeScope,
|
|
47
48
|
defineRoles: () => defineRoles,
|
|
@@ -54,7 +55,8 @@ __export(scopes_exports, {
|
|
|
54
55
|
isCustomActionScope: () => isCustomActionScope,
|
|
55
56
|
scopeUsesDeclaredOptions: () => scopeUsesDeclaredOptions,
|
|
56
57
|
scopeUsesFullOptions: () => scopeUsesFullOptions,
|
|
57
|
-
scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions
|
|
58
|
+
scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions,
|
|
59
|
+
scopeUsesRoleOptions: () => scopeUsesRoleOptions
|
|
58
60
|
});
|
|
59
61
|
module.exports = __toCommonJS(scopes_exports);
|
|
60
62
|
var z4 = __toESM(require("zod/v4"));
|
|
@@ -139,6 +141,10 @@ var scopeByEvent = z3.preprocess(
|
|
|
139
141
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
140
142
|
z3.array(z3.string()).optional()
|
|
141
143
|
).describe("Event type, e.g. birth, death");
|
|
144
|
+
var userRole = z3.preprocess(
|
|
145
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
146
|
+
z3.array(z3.string()).optional()
|
|
147
|
+
).describe("User role, e.g. admin, field agent");
|
|
142
148
|
var scopeOptionsPlaceEvent = z3.object({
|
|
143
149
|
event: scopeByEvent,
|
|
144
150
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -162,6 +168,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
162
168
|
var AccessLevelOptions = z3.object({
|
|
163
169
|
accessLevel: JurisdictionFilter.optional()
|
|
164
170
|
});
|
|
171
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
172
|
+
role: userRole.optional()
|
|
173
|
+
});
|
|
165
174
|
var WorkqueueOrDashboardOptions = z3.object({
|
|
166
175
|
ids: z3.preprocess(
|
|
167
176
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -171,6 +180,7 @@ var WorkqueueOrDashboardOptions = z3.object({
|
|
|
171
180
|
var AllScopeOptions = z3.object({
|
|
172
181
|
...AllRecordScopeOptions.shape,
|
|
173
182
|
...AccessLevelOptions.shape,
|
|
183
|
+
...AllUserScopeOptions.shape,
|
|
174
184
|
...WorkqueueOrDashboardOptions.shape
|
|
175
185
|
});
|
|
176
186
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -243,6 +253,31 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
243
253
|
]).describe(
|
|
244
254
|
"Scopes used to check user's permission to perform actions on a record."
|
|
245
255
|
);
|
|
256
|
+
var SystemScopeType = z3.enum([
|
|
257
|
+
"organisation.read-locations",
|
|
258
|
+
"user.read",
|
|
259
|
+
"user.create",
|
|
260
|
+
"user.edit"
|
|
261
|
+
]);
|
|
262
|
+
var UserScopeType = SystemScopeType.extract([
|
|
263
|
+
"user.read",
|
|
264
|
+
"user.create",
|
|
265
|
+
"user.edit"
|
|
266
|
+
]);
|
|
267
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
268
|
+
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
269
|
+
z3.object({
|
|
270
|
+
type: ScopesWithRoleOption,
|
|
271
|
+
options: AllUserScopeOptions.optional()
|
|
272
|
+
}),
|
|
273
|
+
z3.object({
|
|
274
|
+
type: UserScopeType.extract(["user.read"]),
|
|
275
|
+
options: AccessLevelOptions.optional()
|
|
276
|
+
})
|
|
277
|
+
]);
|
|
278
|
+
function scopeUsesRoleOptions(scope) {
|
|
279
|
+
return ScopesWithRoleOption?.options.some((opt) => opt === scope.type);
|
|
280
|
+
}
|
|
246
281
|
function scopeUsesDeclaredOptions(scope) {
|
|
247
282
|
return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
|
|
248
283
|
}
|
|
@@ -275,16 +310,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
275
310
|
}).optional()
|
|
276
311
|
})
|
|
277
312
|
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
278
|
-
var SystemScopeType = z3.enum([
|
|
279
|
-
"organisation.read-locations",
|
|
280
|
-
"user.read",
|
|
281
|
-
"user.create",
|
|
282
|
-
"user.edit"
|
|
283
|
-
]);
|
|
284
313
|
var Scope2 = z3.discriminatedUnion("type", [
|
|
285
314
|
z3.object({ type: PlainScopeType }),
|
|
286
315
|
...RecordScopeV2.options,
|
|
287
|
-
|
|
316
|
+
...UserScopeV2.options,
|
|
317
|
+
z3.object({
|
|
318
|
+
type: z3.literal("organisation.read-locations"),
|
|
319
|
+
options: AccessLevelOptions.optional()
|
|
320
|
+
}),
|
|
288
321
|
z3.object({
|
|
289
322
|
type: z3.literal("workqueue"),
|
|
290
323
|
options: WorkqueueOrDashboardOptions
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|