@opencrvs/toolkit 2.0.0-rc.61bee9f → 2.0.0-rc.660de90
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 +3 -5
- package/dist/cli.js +43 -115
- package/dist/commons/api/router.d.ts +38 -23
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/FieldConfig.d.ts +0 -5
- package/dist/conditionals/index.js +3 -5
- package/dist/events/index.js +3 -5
- 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 +35 -60
- package/dist/migrations/v2.0/index.js +43 -115
- 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 +1 -90
- package/dist/notification/index.js +3 -5
- package/dist/scopes/index.d.ts +1 -6
- package/dist/scopes/index.js +3 -5
- package/opencrvs-toolkit-2.0.0-rc.660de90.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.61bee9f.tgz +0 -0
|
@@ -41,10 +41,6 @@ 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
|
|
48
44
|
* - Saves the modified files in-place
|
|
49
45
|
*/
|
|
50
46
|
const ts_morph_1 = require("ts-morph");
|
|
@@ -78,8 +74,6 @@ function ensureImports(sourceFile) {
|
|
|
78
74
|
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
79
75
|
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
80
76
|
const TYPE_PROPERTY_NAME = 'type';
|
|
81
|
-
const ID_PROPERTY_NAME = 'id';
|
|
82
|
-
const FLAGS_PROPERTY_NAME = 'flags';
|
|
83
77
|
const CUSTOM_ACTION_TYPE_PROPERTY_NAME = 'customActionType';
|
|
84
78
|
const AUDIT_HISTORY_LABEL_PROPERTY_NAME = 'auditHistoryLabel';
|
|
85
79
|
const DEDUPLICATION_PROPERTY_NAME = 'deduplication';
|
|
@@ -89,12 +83,9 @@ const FORM_PROPERTY_NAME = 'form';
|
|
|
89
83
|
const ACTION_TYPE_ENUM_NAME = 'ActionType';
|
|
90
84
|
const VALIDATE_MEMBER_NAME = 'VALIDATE';
|
|
91
85
|
const CUSTOM_MEMBER_NAME = 'CUSTOM';
|
|
92
|
-
const REGISTER_MEMBER_NAME = 'REGISTER';
|
|
93
86
|
const VALIDATE_STRING_LITERAL = 'VALIDATE';
|
|
94
87
|
const CUSTOM_STRING_LITERAL = 'CUSTOM';
|
|
95
|
-
const REGISTER_STRING_LITERAL = 'REGISTER';
|
|
96
88
|
const VALIDATE_DECLARATION_VALUE = 'VALIDATE_DECLARATION';
|
|
97
|
-
const VALIDATED_FLAG_VALUE = 'validated';
|
|
98
89
|
function isValidateType(typeInitializer) {
|
|
99
90
|
// Matches: ActionType.VALIDATE
|
|
100
91
|
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
@@ -239,72 +230,6 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
239
230
|
}
|
|
240
231
|
return true;
|
|
241
232
|
}
|
|
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
|
-
}
|
|
308
233
|
function processFile(filePath, project) {
|
|
309
234
|
const sourceFile = project.getSourceFile(filePath);
|
|
310
235
|
if (!sourceFile)
|
|
@@ -372,20 +297,6 @@ function processFile(filePath, project) {
|
|
|
372
297
|
});
|
|
373
298
|
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`);
|
|
374
299
|
}
|
|
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
|
-
}
|
|
389
300
|
if (fileNeedsImports) {
|
|
390
301
|
ensureImports(sourceFile);
|
|
391
302
|
}
|
|
@@ -427,6 +338,6 @@ function main() {
|
|
|
427
338
|
yield sourceFile.save();
|
|
428
339
|
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
429
340
|
}
|
|
430
|
-
console.log(`\nDone.
|
|
341
|
+
console.log(`\nDone. Transformed ${totalTransformed} VALIDATE action(s) to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'.`);
|
|
431
342
|
});
|
|
432
343
|
}
|
|
@@ -226,14 +226,12 @@ var SystemScopeType = z2.enum([
|
|
|
226
226
|
"organisation.read-locations",
|
|
227
227
|
"user.read",
|
|
228
228
|
"user.create",
|
|
229
|
-
"user.edit"
|
|
230
|
-
"user.search"
|
|
229
|
+
"user.edit"
|
|
231
230
|
]);
|
|
232
231
|
var UserScopeType = SystemScopeType.extract([
|
|
233
232
|
"user.read",
|
|
234
233
|
"user.create",
|
|
235
|
-
"user.edit"
|
|
236
|
-
"user.search"
|
|
234
|
+
"user.edit"
|
|
237
235
|
]);
|
|
238
236
|
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
239
237
|
var UserScopeV2 = z2.discriminatedUnion("type", [
|
|
@@ -242,7 +240,7 @@ var UserScopeV2 = z2.discriminatedUnion("type", [
|
|
|
242
240
|
options: AllUserScopeOptions.optional()
|
|
243
241
|
}),
|
|
244
242
|
z2.object({
|
|
245
|
-
type: UserScopeType.extract(["user.read"
|
|
243
|
+
type: UserScopeType.extract(["user.read"]),
|
|
246
244
|
options: AccessLevelOptions.optional()
|
|
247
245
|
})
|
|
248
246
|
]);
|
package/dist/scopes/index.d.ts
CHANGED
|
@@ -227,14 +227,12 @@ 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";
|
|
231
230
|
}>;
|
|
232
231
|
export type SystemScopeType = z.infer<typeof SystemScopeType>;
|
|
233
232
|
declare const UserScopeType: z.ZodEnum<{
|
|
234
233
|
"user.read": "user.read";
|
|
235
234
|
"user.create": "user.create";
|
|
236
235
|
"user.edit": "user.edit";
|
|
237
|
-
"user.search": "user.search";
|
|
238
236
|
}>;
|
|
239
237
|
export type UserScopeType = z.infer<typeof UserScopeType>;
|
|
240
238
|
declare const ScopesWithRoleOption: z.ZodEnum<{
|
|
@@ -258,7 +256,6 @@ export declare const UserScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
258
256
|
}, z.core.$strip>, z.ZodObject<{
|
|
259
257
|
type: z.ZodEnum<{
|
|
260
258
|
"user.read": "user.read";
|
|
261
|
-
"user.search": "user.search";
|
|
262
259
|
}>;
|
|
263
260
|
options: z.ZodOptional<z.ZodObject<{
|
|
264
261
|
accessLevel: z.ZodOptional<z.ZodEnum<{
|
|
@@ -496,7 +493,6 @@ export declare const Scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
496
493
|
}, z.core.$strip>, z.ZodObject<{
|
|
497
494
|
type: z.ZodEnum<{
|
|
498
495
|
"user.read": "user.read";
|
|
499
|
-
"user.search": "user.search";
|
|
500
496
|
}>;
|
|
501
497
|
options: z.ZodOptional<z.ZodObject<{
|
|
502
498
|
accessLevel: z.ZodOptional<z.ZodEnum<{
|
|
@@ -560,7 +556,6 @@ export declare const ScopeType: z.ZodEnum<{
|
|
|
560
556
|
"user.read": "user.read";
|
|
561
557
|
"user.create": "user.create";
|
|
562
558
|
"user.edit": "user.edit";
|
|
563
|
-
"user.search": "user.search";
|
|
564
559
|
workqueue: "workqueue";
|
|
565
560
|
"dashboard.view": "dashboard.view";
|
|
566
561
|
}>;
|
|
@@ -640,7 +635,7 @@ export declare const decodeScope: (query: EncodedScope) => {
|
|
|
640
635
|
role?: string[] | undefined;
|
|
641
636
|
} | undefined;
|
|
642
637
|
} | {
|
|
643
|
-
type: "user.read"
|
|
638
|
+
type: "user.read";
|
|
644
639
|
options?: {
|
|
645
640
|
accessLevel?: "administrativeArea" | "location" | "all" | undefined;
|
|
646
641
|
} | undefined;
|
package/dist/scopes/index.js
CHANGED
|
@@ -257,14 +257,12 @@ var SystemScopeType = z3.enum([
|
|
|
257
257
|
"organisation.read-locations",
|
|
258
258
|
"user.read",
|
|
259
259
|
"user.create",
|
|
260
|
-
"user.edit"
|
|
261
|
-
"user.search"
|
|
260
|
+
"user.edit"
|
|
262
261
|
]);
|
|
263
262
|
var UserScopeType = SystemScopeType.extract([
|
|
264
263
|
"user.read",
|
|
265
264
|
"user.create",
|
|
266
|
-
"user.edit"
|
|
267
|
-
"user.search"
|
|
265
|
+
"user.edit"
|
|
268
266
|
]);
|
|
269
267
|
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
270
268
|
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
@@ -273,7 +271,7 @@ var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
|
273
271
|
options: AllUserScopeOptions.optional()
|
|
274
272
|
}),
|
|
275
273
|
z3.object({
|
|
276
|
-
type: UserScopeType.extract(["user.read"
|
|
274
|
+
type: UserScopeType.extract(["user.read"]),
|
|
277
275
|
options: AccessLevelOptions.optional()
|
|
278
276
|
})
|
|
279
277
|
]);
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|