@opencrvs/toolkit 2.0.0-rc.b63fd2e → 2.0.0-rc.bba732d
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 +41 -11
- package/dist/cli.js +147 -47
- package/dist/commons/api/router.d.ts +55 -54
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/events/FieldConfig.d.ts +10 -0
- package/dist/commons/events/locations.d.ts +38 -1
- 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 +37 -7
- package/dist/events/index.js +130 -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 +147 -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 +37 -7
- package/dist/scopes/index.d.ts +87 -10
- package/dist/scopes/index.js +43 -8
- package/opencrvs-toolkit-2.0.0-rc.bba732d.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.b63fd2e.tgz +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
*
|
|
8
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
9
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
10
|
+
*
|
|
11
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const { execSync } = require('child_process')
|
|
15
|
+
const path = require('path')
|
|
16
|
+
const fs = require('fs')
|
|
17
|
+
|
|
18
|
+
const REPO_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git'
|
|
19
|
+
|
|
20
|
+
const projectName = process.argv[2]
|
|
21
|
+
|
|
22
|
+
if (!projectName) {
|
|
23
|
+
console.error(
|
|
24
|
+
'Please specify a project name:\n\n npm create @opencrvs/countryconfig <project-name>\n'
|
|
25
|
+
)
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const targetDir = path.resolve(process.cwd(), projectName)
|
|
30
|
+
|
|
31
|
+
if (fs.existsSync(targetDir)) {
|
|
32
|
+
console.error(`Error: Directory "${projectName}" already exists.`)
|
|
33
|
+
process.exit(1)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log(`\nScaffolding OpenCRVS country config in ./${projectName}...\n`)
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
execSync(`git clone --depth 1 ${REPO_URL} ${projectName}`, {
|
|
40
|
+
stdio: 'inherit'
|
|
41
|
+
})
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.error('Failed to clone the repository:', err.message)
|
|
44
|
+
process.exit(1)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
fs.rmSync(path.join(targetDir, '.git'), { recursive: true, force: true })
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.error('Failed to remove .git directory:', err.message)
|
|
51
|
+
process.exit(1)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const pkgPath = path.join(targetDir, 'package.json')
|
|
55
|
+
if (fs.existsSync(pkgPath)) {
|
|
56
|
+
try {
|
|
57
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
58
|
+
pkg.name = projectName
|
|
59
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.error('Failed to update package.json:', err.message)
|
|
62
|
+
process.exit(1)
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
console.warn(
|
|
66
|
+
`Warning: No package.json found in the cloned repository. Project name was not updated.`
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
console.log(`\nDone! To get started:\n`)
|
|
71
|
+
console.log(` cd ${projectName}`)
|
|
72
|
+
console.log(` git init`)
|
|
73
|
+
console.log(` npm install\n`)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opencrvs/create-countryconfig",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Scaffold a new OpenCRVS country configuration",
|
|
5
|
+
"bin": {
|
|
6
|
+
"create-countryconfig": "./index.js"
|
|
7
|
+
},
|
|
8
|
+
"files": ["index.js"],
|
|
9
|
+
"keywords": ["opencrvs", "countryconfig", "create"],
|
|
10
|
+
"license": "MPL-2.0"
|
|
11
|
+
}
|
|
@@ -656,6 +656,10 @@ var scopeByEvent = z11.preprocess(
|
|
|
656
656
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
657
657
|
z11.array(z11.string()).optional()
|
|
658
658
|
).describe("Event type, e.g. birth, death");
|
|
659
|
+
var userRole = z11.preprocess(
|
|
660
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
661
|
+
z11.array(z11.string()).optional()
|
|
662
|
+
).describe("User role, e.g. admin, field agent");
|
|
659
663
|
var scopeOptionsPlaceEvent = z11.object({
|
|
660
664
|
event: scopeByEvent,
|
|
661
665
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -679,6 +683,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
679
683
|
var AccessLevelOptions = z11.object({
|
|
680
684
|
accessLevel: JurisdictionFilter.optional()
|
|
681
685
|
});
|
|
686
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
687
|
+
role: userRole.optional()
|
|
688
|
+
});
|
|
682
689
|
var WorkqueueOrDashboardOptions = z11.object({
|
|
683
690
|
ids: z11.preprocess(
|
|
684
691
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -688,6 +695,7 @@ var WorkqueueOrDashboardOptions = z11.object({
|
|
|
688
695
|
var AllScopeOptions = z11.object({
|
|
689
696
|
...AllRecordScopeOptions.shape,
|
|
690
697
|
...AccessLevelOptions.shape,
|
|
698
|
+
...AllUserScopeOptions.shape,
|
|
691
699
|
...WorkqueueOrDashboardOptions.shape
|
|
692
700
|
});
|
|
693
701
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -760,6 +768,30 @@ var RecordScopeV2 = z11.discriminatedUnion("type", [
|
|
|
760
768
|
]).describe(
|
|
761
769
|
"Scopes used to check user's permission to perform actions on a record."
|
|
762
770
|
);
|
|
771
|
+
var SystemScopeType = z11.enum([
|
|
772
|
+
"organisation.read-locations",
|
|
773
|
+
"user.read",
|
|
774
|
+
"user.create",
|
|
775
|
+
"user.edit",
|
|
776
|
+
"user.search"
|
|
777
|
+
]);
|
|
778
|
+
var UserScopeType = SystemScopeType.extract([
|
|
779
|
+
"user.read",
|
|
780
|
+
"user.create",
|
|
781
|
+
"user.edit",
|
|
782
|
+
"user.search"
|
|
783
|
+
]);
|
|
784
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
785
|
+
var UserScopeV2 = z11.discriminatedUnion("type", [
|
|
786
|
+
z11.object({
|
|
787
|
+
type: ScopesWithRoleOption,
|
|
788
|
+
options: AllUserScopeOptions.optional()
|
|
789
|
+
}),
|
|
790
|
+
z11.object({
|
|
791
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
792
|
+
options: AccessLevelOptions.optional()
|
|
793
|
+
})
|
|
794
|
+
]);
|
|
763
795
|
var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
|
|
764
796
|
z11.object({
|
|
765
797
|
type: ScopesWithPlaceEventOptions,
|
|
@@ -780,16 +812,14 @@ var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
|
|
|
780
812
|
}).optional()
|
|
781
813
|
})
|
|
782
814
|
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
783
|
-
var SystemScopeType = z11.enum([
|
|
784
|
-
"organisation.read-locations",
|
|
785
|
-
"user.read",
|
|
786
|
-
"user.create",
|
|
787
|
-
"user.edit"
|
|
788
|
-
]);
|
|
789
815
|
var Scope = z11.discriminatedUnion("type", [
|
|
790
816
|
z11.object({ type: PlainScopeType }),
|
|
791
817
|
...RecordScopeV2.options,
|
|
792
|
-
|
|
818
|
+
...UserScopeV2.options,
|
|
819
|
+
z11.object({
|
|
820
|
+
type: z11.literal("organisation.read-locations"),
|
|
821
|
+
options: AccessLevelOptions.optional()
|
|
822
|
+
}),
|
|
793
823
|
z11.object({
|
|
794
824
|
type: z11.literal("workqueue"),
|
|
795
825
|
options: WorkqueueOrDashboardOptions
|
|
@@ -2078,8 +2108,8 @@ var ApplicationConfig = z20.object({
|
|
|
2078
2108
|
})
|
|
2079
2109
|
),
|
|
2080
2110
|
PHONE_NUMBER_PATTERN: z20.string().or(z20.instanceof(RegExp)),
|
|
2081
|
-
USER_NOTIFICATION_DELIVERY_METHOD: z20.
|
|
2082
|
-
INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.
|
|
2111
|
+
USER_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
|
|
2112
|
+
INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
|
|
2083
2113
|
SEARCH_DEFAULT_CRITERIA: SearchCriteria.optional().default("TRACKING_ID"),
|
|
2084
2114
|
ADDITIONAL_USER_FIELDS: z20.array(FieldConfig).optional().default([])
|
|
2085
2115
|
});
|
|
@@ -2097,8 +2127,8 @@ var BackgroundConfig = z20.object({
|
|
|
2097
2127
|
var LoginConfig = z20.object({
|
|
2098
2128
|
COUNTRY: z20.string(),
|
|
2099
2129
|
LANGUAGES: z20.array(z20.string()),
|
|
2100
|
-
USER_NOTIFICATION_DELIVERY_METHOD: z20.
|
|
2101
|
-
INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.
|
|
2130
|
+
USER_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
|
|
2131
|
+
INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
|
|
2102
2132
|
PHONE_NUMBER_PATTERN: z20.string().or(z20.instanceof(RegExp)),
|
|
2103
2133
|
LOGIN_BACKGROUND: BackgroundConfig,
|
|
2104
2134
|
SENTRY: z20.string().optional()
|
package/dist/cli.js
CHANGED
|
@@ -178,6 +178,8 @@ function ensureImports(sourceFile) {
|
|
|
178
178
|
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
179
179
|
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
180
180
|
var TYPE_PROPERTY_NAME2 = "type";
|
|
181
|
+
var ID_PROPERTY_NAME = "id";
|
|
182
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
181
183
|
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
182
184
|
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
183
185
|
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
@@ -187,9 +189,12 @@ var FORM_PROPERTY_NAME = "form";
|
|
|
187
189
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
188
190
|
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
189
191
|
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
192
|
+
var REGISTER_MEMBER_NAME2 = "REGISTER";
|
|
190
193
|
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
191
194
|
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
195
|
+
var REGISTER_STRING_LITERAL2 = "REGISTER";
|
|
192
196
|
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
197
|
+
var VALIDATED_FLAG_VALUE = "validated";
|
|
193
198
|
function isValidateType(typeInitializer) {
|
|
194
199
|
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
195
200
|
const propAccess = typeInitializer.asKindOrThrow(
|
|
@@ -313,6 +318,50 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
313
318
|
}
|
|
314
319
|
return true;
|
|
315
320
|
}
|
|
321
|
+
function isRegisterAction(action) {
|
|
322
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME2);
|
|
323
|
+
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) return false;
|
|
324
|
+
const typeInit = typeProperty.getInitializer();
|
|
325
|
+
if (!typeInit) return false;
|
|
326
|
+
if (import_ts_morph2.Node.isPropertyAccessExpression(typeInit)) {
|
|
327
|
+
const enumExpr = typeInit.getExpression();
|
|
328
|
+
return import_ts_morph2.Node.isIdentifier(enumExpr) && enumExpr.getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === REGISTER_MEMBER_NAME2;
|
|
329
|
+
}
|
|
330
|
+
if (import_ts_morph2.Node.isStringLiteral(typeInit)) {
|
|
331
|
+
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL2;
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
function arrayHasElementWithId(array3, id) {
|
|
336
|
+
for (const el of array3.getElements()) {
|
|
337
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(el)) continue;
|
|
338
|
+
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
339
|
+
if (!idProp || !import_ts_morph2.Node.isPropertyAssignment(idProp)) continue;
|
|
340
|
+
const idInit = idProp.getInitializer();
|
|
341
|
+
if (idInit && import_ts_morph2.Node.isStringLiteral(idInit) && idInit.getLiteralValue() === id) {
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
function ensureRegisterRemovesValidatedFlag(action) {
|
|
348
|
+
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
349
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
350
|
+
if (flagsProp && import_ts_morph2.Node.isPropertyAssignment(flagsProp)) {
|
|
351
|
+
const flagsInit = flagsProp.getInitializer();
|
|
352
|
+
if (flagsInit && import_ts_morph2.Node.isArrayLiteralExpression(flagsInit)) {
|
|
353
|
+
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE)) return false;
|
|
354
|
+
flagsInit.addElement(entry);
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
action.addPropertyAssignment({
|
|
360
|
+
name: FLAGS_PROPERTY_NAME,
|
|
361
|
+
initializer: `[${entry}]`
|
|
362
|
+
});
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
316
365
|
function processFile2(filePath, project) {
|
|
317
366
|
const sourceFile = project.getSourceFile(filePath);
|
|
318
367
|
if (!sourceFile) return 0;
|
|
@@ -378,6 +427,18 @@ function processFile2(filePath, project) {
|
|
|
378
427
|
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
379
428
|
);
|
|
380
429
|
}
|
|
430
|
+
if (configHadValidateAction) {
|
|
431
|
+
for (const element of actionsInitializer.getElements()) {
|
|
432
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(element)) continue;
|
|
433
|
+
if (!isRegisterAction(element)) continue;
|
|
434
|
+
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
435
|
+
transformedCount++;
|
|
436
|
+
console.log(
|
|
437
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
381
442
|
if (fileNeedsImports) {
|
|
382
443
|
ensureImports(sourceFile);
|
|
383
444
|
}
|
|
@@ -424,7 +485,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
424
485
|
}
|
|
425
486
|
console.log(
|
|
426
487
|
`
|
|
427
|
-
Done.
|
|
488
|
+
Done. Applied ${totalTransformed} change(s): VALIDATE \u2192 CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`
|
|
428
489
|
);
|
|
429
490
|
}
|
|
430
491
|
|
|
@@ -667,14 +728,14 @@ var QUERY_PROPERTY_NAME = "query";
|
|
|
667
728
|
var TYPE_PROPERTY_NAME5 = "type";
|
|
668
729
|
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
669
730
|
var STATUS_PROPERTY_NAME = "status";
|
|
670
|
-
var
|
|
731
|
+
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
671
732
|
var TERMS_PROPERTY_NAME = "terms";
|
|
672
733
|
var TERM_PROPERTY_NAME = "term";
|
|
673
734
|
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
674
735
|
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
675
|
-
var
|
|
736
|
+
var VALIDATED_FLAG_VALUE2 = "validated";
|
|
676
737
|
function addValidatedFlag(clause) {
|
|
677
|
-
const flagsProperty = clause.getProperty(
|
|
738
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
678
739
|
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
679
740
|
const flagsInit = flagsProperty.getInitializer();
|
|
680
741
|
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -682,19 +743,19 @@ function addValidatedFlag(clause) {
|
|
|
682
743
|
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
683
744
|
const anyOfInit = anyOfProperty.getInitializer();
|
|
684
745
|
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
685
|
-
anyOfInit.addElement(`'${
|
|
746
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE2}'`);
|
|
686
747
|
}
|
|
687
748
|
} else {
|
|
688
749
|
flagsInit.addPropertyAssignment({
|
|
689
750
|
name: ANY_OF_PROPERTY_NAME,
|
|
690
|
-
initializer: `['${
|
|
751
|
+
initializer: `['${VALIDATED_FLAG_VALUE2}']`
|
|
691
752
|
});
|
|
692
753
|
}
|
|
693
754
|
}
|
|
694
755
|
} else {
|
|
695
756
|
clause.addPropertyAssignment({
|
|
696
|
-
name:
|
|
697
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${
|
|
757
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
758
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE2}'] }`
|
|
698
759
|
});
|
|
699
760
|
}
|
|
700
761
|
}
|
|
@@ -860,23 +921,26 @@ var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
|
860
921
|
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
861
922
|
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
862
923
|
var ACTION_PROPERTY_NAME = "action";
|
|
863
|
-
var
|
|
924
|
+
var FLAGS_PROPERTY_NAME3 = "flags";
|
|
864
925
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
865
926
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
927
|
+
var ID_PROPERTY_NAME2 = "id";
|
|
866
928
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
867
929
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
868
930
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
869
931
|
var REGISTER_TYPE = "REGISTER";
|
|
870
932
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
871
|
-
|
|
933
|
+
function flagDefinitionInitializer(eventType) {
|
|
934
|
+
return `{
|
|
872
935
|
id: '${FLAG_ID}',
|
|
873
936
|
label: {
|
|
874
|
-
id: 'event.
|
|
937
|
+
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
875
938
|
defaultMessage: 'Pending first certificate issuance',
|
|
876
939
|
description: 'Flag label for first certificate issuance'
|
|
877
940
|
},
|
|
878
941
|
requiresAction: true
|
|
879
942
|
}`;
|
|
943
|
+
}
|
|
880
944
|
function isActionOfType(obj, typeName) {
|
|
881
945
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
882
946
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -890,18 +954,20 @@ function isActionOfType(obj, typeName) {
|
|
|
890
954
|
}
|
|
891
955
|
return false;
|
|
892
956
|
}
|
|
893
|
-
function
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
957
|
+
function getEventType(configArg) {
|
|
958
|
+
for (const propName of [TYPE_PROPERTY_NAME6, ID_PROPERTY_NAME2]) {
|
|
959
|
+
const prop = configArg.getProperty(propName);
|
|
960
|
+
if (!prop || !import_ts_morph6.Node.isPropertyAssignment(prop)) continue;
|
|
961
|
+
const initializer = prop.getInitializer();
|
|
962
|
+
if (!initializer) continue;
|
|
963
|
+
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
964
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
965
|
+
}
|
|
966
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
967
|
+
return initializer.getName().toLowerCase();
|
|
968
|
+
}
|
|
903
969
|
}
|
|
904
|
-
return
|
|
970
|
+
return null;
|
|
905
971
|
}
|
|
906
972
|
function hasElementWithId(array3, id) {
|
|
907
973
|
for (const el of array3.getElements()) {
|
|
@@ -915,27 +981,28 @@ function hasElementWithId(array3, id) {
|
|
|
915
981
|
}
|
|
916
982
|
return false;
|
|
917
983
|
}
|
|
918
|
-
function ensureTopLevelFlagDefinition(configArg) {
|
|
919
|
-
const
|
|
984
|
+
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
985
|
+
const initializer = flagDefinitionInitializer(eventType);
|
|
986
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME3);
|
|
920
987
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
921
988
|
const flagsInit = flagsProp.getInitializer();
|
|
922
989
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
923
990
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
924
|
-
flagsInit.addElement(
|
|
991
|
+
flagsInit.addElement(initializer);
|
|
925
992
|
return true;
|
|
926
993
|
}
|
|
927
994
|
return false;
|
|
928
995
|
}
|
|
929
996
|
configArg.addPropertyAssignment({
|
|
930
|
-
name:
|
|
997
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
931
998
|
initializer: `[
|
|
932
|
-
${
|
|
999
|
+
${initializer}
|
|
933
1000
|
]`
|
|
934
1001
|
});
|
|
935
1002
|
return true;
|
|
936
1003
|
}
|
|
937
1004
|
function ensureActionOperationFlag(action, operation) {
|
|
938
|
-
const flagsProp = action.getProperty(
|
|
1005
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME3);
|
|
939
1006
|
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
940
1007
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
941
1008
|
const flagsInit = flagsProp.getInitializer();
|
|
@@ -947,16 +1014,18 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
947
1014
|
return false;
|
|
948
1015
|
}
|
|
949
1016
|
action.addPropertyAssignment({
|
|
950
|
-
name:
|
|
1017
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
951
1018
|
initializer: `[${entry}]`
|
|
952
1019
|
});
|
|
953
1020
|
return true;
|
|
954
1021
|
}
|
|
955
|
-
function
|
|
1022
|
+
function processConfig(configArg, eventType, relPath) {
|
|
956
1023
|
let changes = 0;
|
|
957
|
-
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
1024
|
+
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
958
1025
|
changes++;
|
|
959
|
-
console.log(
|
|
1026
|
+
console.log(
|
|
1027
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
1028
|
+
);
|
|
960
1029
|
}
|
|
961
1030
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
962
1031
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -970,7 +1039,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
970
1039
|
if (ensureActionOperationFlag(element, "add")) {
|
|
971
1040
|
changes++;
|
|
972
1041
|
console.log(
|
|
973
|
-
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
1042
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
974
1043
|
);
|
|
975
1044
|
}
|
|
976
1045
|
}
|
|
@@ -978,7 +1047,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
978
1047
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
979
1048
|
changes++;
|
|
980
1049
|
console.log(
|
|
981
|
-
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1050
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
982
1051
|
);
|
|
983
1052
|
}
|
|
984
1053
|
}
|
|
@@ -1007,7 +1076,7 @@ function hasPrintCertificateAction(workqueue) {
|
|
|
1007
1076
|
return false;
|
|
1008
1077
|
}
|
|
1009
1078
|
function addFlagToQueryClause(clause) {
|
|
1010
|
-
const flagsProp = clause.getProperty(
|
|
1079
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME3);
|
|
1011
1080
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1012
1081
|
const flagsInit = flagsProp.getInitializer();
|
|
1013
1082
|
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -1032,7 +1101,7 @@ function addFlagToQueryClause(clause) {
|
|
|
1032
1101
|
}
|
|
1033
1102
|
} else {
|
|
1034
1103
|
clause.addPropertyAssignment({
|
|
1035
|
-
name:
|
|
1104
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
1036
1105
|
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1037
1106
|
});
|
|
1038
1107
|
return true;
|
|
@@ -1076,8 +1145,9 @@ function processFile6(filePath, project) {
|
|
|
1076
1145
|
if (args2.length === 0) continue;
|
|
1077
1146
|
const configArg = args2[0];
|
|
1078
1147
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1079
|
-
|
|
1080
|
-
|
|
1148
|
+
const eventType = getEventType(configArg);
|
|
1149
|
+
if (!eventType) continue;
|
|
1150
|
+
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1081
1151
|
}
|
|
1082
1152
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1083
1153
|
const args2 = call.getArguments();
|
|
@@ -1106,7 +1176,7 @@ function processFile6(filePath, project) {
|
|
|
1106
1176
|
async function main6() {
|
|
1107
1177
|
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1108
1178
|
console.log(
|
|
1109
|
-
`Scanning for
|
|
1179
|
+
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1110
1180
|
`
|
|
1111
1181
|
);
|
|
1112
1182
|
const project = new import_ts_morph6.Project({
|
|
@@ -1131,7 +1201,7 @@ async function main6() {
|
|
|
1131
1201
|
}
|
|
1132
1202
|
if (modifiedFiles.length === 0) {
|
|
1133
1203
|
console.log(
|
|
1134
|
-
"No
|
|
1204
|
+
"No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1135
1205
|
);
|
|
1136
1206
|
return;
|
|
1137
1207
|
}
|
|
@@ -2110,6 +2180,10 @@ var scopeByEvent = z3.preprocess(
|
|
|
2110
2180
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2111
2181
|
z3.array(z3.string()).optional()
|
|
2112
2182
|
).describe("Event type, e.g. birth, death");
|
|
2183
|
+
var userRole = z3.preprocess(
|
|
2184
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2185
|
+
z3.array(z3.string()).optional()
|
|
2186
|
+
).describe("User role, e.g. admin, field agent");
|
|
2113
2187
|
var scopeOptionsPlaceEvent = z3.object({
|
|
2114
2188
|
event: scopeByEvent,
|
|
2115
2189
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -2133,6 +2207,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
2133
2207
|
var AccessLevelOptions = z3.object({
|
|
2134
2208
|
accessLevel: JurisdictionFilter.optional()
|
|
2135
2209
|
});
|
|
2210
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
2211
|
+
role: userRole.optional()
|
|
2212
|
+
});
|
|
2136
2213
|
var WorkqueueOrDashboardOptions = z3.object({
|
|
2137
2214
|
ids: z3.preprocess(
|
|
2138
2215
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -2142,6 +2219,7 @@ var WorkqueueOrDashboardOptions = z3.object({
|
|
|
2142
2219
|
var AllScopeOptions = z3.object({
|
|
2143
2220
|
...AllRecordScopeOptions.shape,
|
|
2144
2221
|
...AccessLevelOptions.shape,
|
|
2222
|
+
...AllUserScopeOptions.shape,
|
|
2145
2223
|
...WorkqueueOrDashboardOptions.shape
|
|
2146
2224
|
});
|
|
2147
2225
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -2214,6 +2292,30 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2214
2292
|
]).describe(
|
|
2215
2293
|
"Scopes used to check user's permission to perform actions on a record."
|
|
2216
2294
|
);
|
|
2295
|
+
var SystemScopeType = z3.enum([
|
|
2296
|
+
"organisation.read-locations",
|
|
2297
|
+
"user.read",
|
|
2298
|
+
"user.create",
|
|
2299
|
+
"user.edit",
|
|
2300
|
+
"user.search"
|
|
2301
|
+
]);
|
|
2302
|
+
var UserScopeType = SystemScopeType.extract([
|
|
2303
|
+
"user.read",
|
|
2304
|
+
"user.create",
|
|
2305
|
+
"user.edit",
|
|
2306
|
+
"user.search"
|
|
2307
|
+
]);
|
|
2308
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
2309
|
+
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
2310
|
+
z3.object({
|
|
2311
|
+
type: ScopesWithRoleOption,
|
|
2312
|
+
options: AllUserScopeOptions.optional()
|
|
2313
|
+
}),
|
|
2314
|
+
z3.object({
|
|
2315
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
2316
|
+
options: AccessLevelOptions.optional()
|
|
2317
|
+
})
|
|
2318
|
+
]);
|
|
2217
2319
|
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
2218
2320
|
z3.object({
|
|
2219
2321
|
type: ScopesWithPlaceEventOptions,
|
|
@@ -2234,16 +2336,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2234
2336
|
}).optional()
|
|
2235
2337
|
})
|
|
2236
2338
|
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
2237
|
-
var SystemScopeType = z3.enum([
|
|
2238
|
-
"organisation.read-locations",
|
|
2239
|
-
"user.read",
|
|
2240
|
-
"user.create",
|
|
2241
|
-
"user.edit"
|
|
2242
|
-
]);
|
|
2243
2339
|
var Scope2 = z3.discriminatedUnion("type", [
|
|
2244
2340
|
z3.object({ type: PlainScopeType }),
|
|
2245
2341
|
...RecordScopeV2.options,
|
|
2246
|
-
|
|
2342
|
+
...UserScopeV2.options,
|
|
2343
|
+
z3.object({
|
|
2344
|
+
type: z3.literal("organisation.read-locations"),
|
|
2345
|
+
options: AccessLevelOptions.optional()
|
|
2346
|
+
}),
|
|
2247
2347
|
z3.object({
|
|
2248
2348
|
type: z3.literal("workqueue"),
|
|
2249
2349
|
options: WorkqueueOrDashboardOptions
|