@opencrvs/toolkit 2.0.0-rc.db7e47e → 2.0.0-rc.dc48f9b
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/create-countryconfig/index.js +73 -0
- package/create-countryconfig/package.json +11 -0
- package/dist/application-config/index.js +9 -7
- package/dist/cli.js +115 -43
- package/dist/commons/api/router.d.ts +20 -20
- 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 +21 -0
- package/dist/commons/events/mocks.test.utils.d.ts +19 -0
- package/dist/commons/events/scopes.d.ts +24 -1
- package/dist/conditionals/index.js +5 -3
- package/dist/events/index.js +60 -3
- 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 +115 -43
- 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 +5 -3
- package/dist/scopes/index.d.ts +6 -1
- package/dist/scopes/index.js +5 -3
- package/opencrvs-toolkit-2.0.0-rc.dc48f9b.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.db7e47e.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
|
}
|
|
@@ -226,12 +226,14 @@ var SystemScopeType = z2.enum([
|
|
|
226
226
|
"organisation.read-locations",
|
|
227
227
|
"user.read",
|
|
228
228
|
"user.create",
|
|
229
|
-
"user.edit"
|
|
229
|
+
"user.edit",
|
|
230
|
+
"user.search"
|
|
230
231
|
]);
|
|
231
232
|
var UserScopeType = SystemScopeType.extract([
|
|
232
233
|
"user.read",
|
|
233
234
|
"user.create",
|
|
234
|
-
"user.edit"
|
|
235
|
+
"user.edit",
|
|
236
|
+
"user.search"
|
|
235
237
|
]);
|
|
236
238
|
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
237
239
|
var UserScopeV2 = z2.discriminatedUnion("type", [
|
|
@@ -240,7 +242,7 @@ var UserScopeV2 = z2.discriminatedUnion("type", [
|
|
|
240
242
|
options: AllUserScopeOptions.optional()
|
|
241
243
|
}),
|
|
242
244
|
z2.object({
|
|
243
|
-
type: UserScopeType.extract(["user.read"]),
|
|
245
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
244
246
|
options: AccessLevelOptions.optional()
|
|
245
247
|
})
|
|
246
248
|
]);
|
package/dist/scopes/index.d.ts
CHANGED
|
@@ -227,12 +227,14 @@ declare const SystemScopeType: z.ZodEnum<{
|
|
|
227
227
|
"user.read": "user.read";
|
|
228
228
|
"user.create": "user.create";
|
|
229
229
|
"user.edit": "user.edit";
|
|
230
|
+
"user.search": "user.search";
|
|
230
231
|
}>;
|
|
231
232
|
export type SystemScopeType = z.infer<typeof SystemScopeType>;
|
|
232
233
|
declare const UserScopeType: z.ZodEnum<{
|
|
233
234
|
"user.read": "user.read";
|
|
234
235
|
"user.create": "user.create";
|
|
235
236
|
"user.edit": "user.edit";
|
|
237
|
+
"user.search": "user.search";
|
|
236
238
|
}>;
|
|
237
239
|
export type UserScopeType = z.infer<typeof UserScopeType>;
|
|
238
240
|
declare const ScopesWithRoleOption: z.ZodEnum<{
|
|
@@ -256,6 +258,7 @@ export declare const UserScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
256
258
|
}, z.core.$strip>, z.ZodObject<{
|
|
257
259
|
type: z.ZodEnum<{
|
|
258
260
|
"user.read": "user.read";
|
|
261
|
+
"user.search": "user.search";
|
|
259
262
|
}>;
|
|
260
263
|
options: z.ZodOptional<z.ZodObject<{
|
|
261
264
|
accessLevel: z.ZodOptional<z.ZodEnum<{
|
|
@@ -493,6 +496,7 @@ export declare const Scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
493
496
|
}, z.core.$strip>, z.ZodObject<{
|
|
494
497
|
type: z.ZodEnum<{
|
|
495
498
|
"user.read": "user.read";
|
|
499
|
+
"user.search": "user.search";
|
|
496
500
|
}>;
|
|
497
501
|
options: z.ZodOptional<z.ZodObject<{
|
|
498
502
|
accessLevel: z.ZodOptional<z.ZodEnum<{
|
|
@@ -556,6 +560,7 @@ export declare const ScopeType: z.ZodEnum<{
|
|
|
556
560
|
"user.read": "user.read";
|
|
557
561
|
"user.create": "user.create";
|
|
558
562
|
"user.edit": "user.edit";
|
|
563
|
+
"user.search": "user.search";
|
|
559
564
|
workqueue: "workqueue";
|
|
560
565
|
"dashboard.view": "dashboard.view";
|
|
561
566
|
}>;
|
|
@@ -635,7 +640,7 @@ export declare const decodeScope: (query: EncodedScope) => {
|
|
|
635
640
|
role?: string[] | undefined;
|
|
636
641
|
} | undefined;
|
|
637
642
|
} | {
|
|
638
|
-
type: "user.read";
|
|
643
|
+
type: "user.read" | "user.search";
|
|
639
644
|
options?: {
|
|
640
645
|
accessLevel?: "administrativeArea" | "location" | "all" | undefined;
|
|
641
646
|
} | undefined;
|
package/dist/scopes/index.js
CHANGED
|
@@ -257,12 +257,14 @@ var SystemScopeType = z3.enum([
|
|
|
257
257
|
"organisation.read-locations",
|
|
258
258
|
"user.read",
|
|
259
259
|
"user.create",
|
|
260
|
-
"user.edit"
|
|
260
|
+
"user.edit",
|
|
261
|
+
"user.search"
|
|
261
262
|
]);
|
|
262
263
|
var UserScopeType = SystemScopeType.extract([
|
|
263
264
|
"user.read",
|
|
264
265
|
"user.create",
|
|
265
|
-
"user.edit"
|
|
266
|
+
"user.edit",
|
|
267
|
+
"user.search"
|
|
266
268
|
]);
|
|
267
269
|
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
268
270
|
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
@@ -271,7 +273,7 @@ var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
|
271
273
|
options: AllUserScopeOptions.optional()
|
|
272
274
|
}),
|
|
273
275
|
z3.object({
|
|
274
|
-
type: UserScopeType.extract(["user.read"]),
|
|
276
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
275
277
|
options: AccessLevelOptions.optional()
|
|
276
278
|
})
|
|
277
279
|
]);
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|