@opencrvs/toolkit 2.0.0-rc.f2d9566 → 2.0.0-rc.f3705df
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 +50 -20
- package/dist/commons/conditionals/conditionals.d.ts +6 -0
- package/dist/commons/events/index.d.ts +1 -0
- package/dist/commons/events/state/flags.d.ts +16 -0
- package/dist/conditionals/index.js +4 -0
- package/dist/events/index.js +63 -25
- package/opencrvs-toolkit-2.0.0-rc.f3705df.tgz +0 -0
- package/package.json +2 -2
- package/opencrvs-toolkit-2.0.0-rc.f2d9566.tgz +0 -0
|
@@ -15,7 +15,10 @@ const { execSync } = require('child_process')
|
|
|
15
15
|
const path = require('path')
|
|
16
16
|
const fs = require('fs')
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const COUNTRYCONFIG_REPO_URL =
|
|
19
|
+
'https://github.com/opencrvs/opencrvs-countryconfig.git'
|
|
20
|
+
const INFRASTRUCTURE_REPO_URL =
|
|
21
|
+
'https://github.com/opencrvs/infrastructure.git'
|
|
19
22
|
|
|
20
23
|
const projectName = process.argv[2]
|
|
21
24
|
|
|
@@ -26,48 +29,75 @@ if (!projectName) {
|
|
|
26
29
|
process.exit(1)
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
const
|
|
32
|
+
const countryconfigDirName = projectName + '-countryconfig'
|
|
33
|
+
const infrastructureDirName = projectName + '-infrastructure'
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
const countryconfigTargetDir = path.resolve(process.cwd(), countryconfigDirName)
|
|
36
|
+
const infrastructureTargetDir = path.resolve(process.cwd(), infrastructureDirName)
|
|
37
|
+
|
|
38
|
+
if (fs.existsSync(countryconfigTargetDir)) {
|
|
39
|
+
console.error('Error: Directory "' + countryconfigDirName + '" already exists.')
|
|
40
|
+
process.exit(1)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (fs.existsSync(infrastructureTargetDir)) {
|
|
44
|
+
console.error('Error: Directory "' + infrastructureDirName + '" already exists.')
|
|
33
45
|
process.exit(1)
|
|
34
46
|
}
|
|
35
47
|
|
|
36
|
-
console.log(
|
|
48
|
+
console.log('\nScaffolding OpenCRVS country config in ./' + countryconfigDirName + '...\n')
|
|
37
49
|
|
|
38
50
|
try {
|
|
39
|
-
execSync(
|
|
40
|
-
stdio: 'inherit'
|
|
41
|
-
})
|
|
51
|
+
execSync('git clone --depth 1 ' + COUNTRYCONFIG_REPO_URL + ' ' + countryconfigDirName, { stdio: 'inherit' })
|
|
42
52
|
} catch (err) {
|
|
43
|
-
console.error('Failed to clone the repository:', err.message)
|
|
53
|
+
console.error('Failed to clone the country config repository:', err.message)
|
|
44
54
|
process.exit(1)
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
try {
|
|
48
|
-
fs.rmSync(path.join(
|
|
58
|
+
fs.rmSync(path.join(countryconfigTargetDir, '.git'), { recursive: true, force: true })
|
|
49
59
|
} catch (err) {
|
|
50
|
-
console.error('Failed to remove .git directory:', err.message)
|
|
60
|
+
console.error('Failed to remove .git directory from country config:', err.message)
|
|
51
61
|
process.exit(1)
|
|
52
62
|
}
|
|
53
63
|
|
|
54
|
-
const pkgPath = path.join(
|
|
64
|
+
const pkgPath = path.join(countryconfigTargetDir, 'package.json')
|
|
55
65
|
if (fs.existsSync(pkgPath)) {
|
|
56
66
|
try {
|
|
57
67
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
58
|
-
pkg.name =
|
|
68
|
+
pkg.name = countryconfigDirName
|
|
59
69
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
|
|
60
70
|
} catch (err) {
|
|
61
71
|
console.error('Failed to update package.json:', err.message)
|
|
62
72
|
process.exit(1)
|
|
63
73
|
}
|
|
64
74
|
} else {
|
|
65
|
-
console.warn(
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
console.warn('Warning: No package.json found in the cloned country config repository. Project name was not updated.')
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log('\nScaffolding OpenCRVS infrastructure in ./' + infrastructureDirName + '...\n')
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
execSync('git clone --depth 1 ' + INFRASTRUCTURE_REPO_URL + ' ' + infrastructureDirName, { stdio: 'inherit' })
|
|
82
|
+
} catch (err) {
|
|
83
|
+
console.error('Failed to clone the infrastructure repository:', err.message)
|
|
84
|
+
process.exit(1)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
fs.rmSync(path.join(infrastructureTargetDir, '.git'), { recursive: true, force: true })
|
|
89
|
+
} catch (err) {
|
|
90
|
+
console.error('Failed to remove .git directory from infrastructure:', err.message)
|
|
91
|
+
process.exit(1)
|
|
68
92
|
}
|
|
69
93
|
|
|
70
|
-
console.log(
|
|
71
|
-
console.log(
|
|
72
|
-
console.log(
|
|
73
|
-
console.log(
|
|
94
|
+
console.log('\nDone! Your project has been set up in two directories:\n')
|
|
95
|
+
console.log(' ./' + countryconfigDirName + ' -- country configuration')
|
|
96
|
+
console.log(' ./' + infrastructureDirName + ' -- server infrastructure\n')
|
|
97
|
+
console.log('To get started with the country config:\n')
|
|
98
|
+
console.log(' cd ' + countryconfigDirName)
|
|
99
|
+
console.log(' git init')
|
|
100
|
+
console.log(' npm install\n')
|
|
101
|
+
console.log('To get started with the infrastructure:\n')
|
|
102
|
+
console.log(' cd ' + infrastructureDirName)
|
|
103
|
+
console.log(' git init\n')
|
|
@@ -67,6 +67,12 @@ export declare function not(condition: AjvJSONSchema): JSONSchema;
|
|
|
67
67
|
* @returns {JSONSchema} An schema object that always evaluates to false.
|
|
68
68
|
*/
|
|
69
69
|
export declare function never(): JSONSchema;
|
|
70
|
+
/**
|
|
71
|
+
* Returns an JSON Schema object, which is treated as always valid.
|
|
72
|
+
*
|
|
73
|
+
* @returns {JSONSchema} An schema object that always evaluates to true.
|
|
74
|
+
*/
|
|
75
|
+
export declare function always(): JSONSchema;
|
|
70
76
|
/**
|
|
71
77
|
* Generate conditional rules for current date
|
|
72
78
|
*/
|
|
@@ -22,6 +22,7 @@ export * from './FieldValue';
|
|
|
22
22
|
export * from './FormConfig';
|
|
23
23
|
export * from './CompositeFieldValue';
|
|
24
24
|
export * from './state';
|
|
25
|
+
export * from './state/flags';
|
|
25
26
|
export * from './utils';
|
|
26
27
|
export * from './defineConfig';
|
|
27
28
|
export * from './DeduplicationConfig';
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { Action, RequestedCorrectionAction } from '../ActionDocument';
|
|
1
2
|
import { Flag, CustomFlag } from '../Flag';
|
|
2
3
|
import { EventConfig } from '../EventConfig';
|
|
3
4
|
import { EventDocument } from '../EventDocument';
|
|
5
|
+
export declare function findPendingCorrectionAction(writeActions: Action[]): RequestedCorrectionAction | undefined;
|
|
6
|
+
export declare function isPotentialDuplicate(actions: Action[]): boolean;
|
|
4
7
|
/**
|
|
5
8
|
* This function resolves custom flags for an event based on its actions.
|
|
6
9
|
* Flags are not stored to the event state or any database directly, instead they are always computed/evaluated from the event actions.
|
|
@@ -18,5 +21,18 @@ import { EventDocument } from '../EventDocument';
|
|
|
18
21
|
* // Returns: ['flag-1', 'flag-3']
|
|
19
22
|
*/
|
|
20
23
|
export declare function resolveEventCustomFlags(event: EventDocument, eventConfiguration: EventConfig): CustomFlag[];
|
|
24
|
+
/**
|
|
25
|
+
* Computes all flags (inherent, action status, and custom) that should be attached to the given event,
|
|
26
|
+
* based on its actions and event-specific configuration.
|
|
27
|
+
*
|
|
28
|
+
* Flags are determined by combining:
|
|
29
|
+
* - Action status flags (format 'ActionType:ActionStatus')
|
|
30
|
+
* - Inherent flags (e.g. incomplete, rejected, correction requested, potential duplicate, edit in progress)
|
|
31
|
+
* - Event type-specific custom flags defined in the event configuration
|
|
32
|
+
*
|
|
33
|
+
* @param event - The EventDocument containing the action history and payload
|
|
34
|
+
* @param config - The EventConfig providing rules for custom flag evaluation
|
|
35
|
+
* @returns An array of flags currently relevant/applicable to the event
|
|
36
|
+
*/
|
|
21
37
|
export declare function getEventFlags(event: EventDocument, config: EventConfig): Flag[];
|
|
22
38
|
//# sourceMappingURL=flags.d.ts.map
|
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/conditionals/index.ts
|
|
31
31
|
var conditionals_exports = {};
|
|
32
32
|
__export(conditionals_exports, {
|
|
33
|
+
always: () => always,
|
|
33
34
|
alwaysTrue: () => alwaysTrue,
|
|
34
35
|
and: () => and,
|
|
35
36
|
createFieldConditionals: () => createFieldConditionals,
|
|
@@ -454,6 +455,9 @@ function not(condition) {
|
|
|
454
455
|
function never() {
|
|
455
456
|
return not(alwaysTrue());
|
|
456
457
|
}
|
|
458
|
+
function always() {
|
|
459
|
+
return defineConditional(alwaysTrue());
|
|
460
|
+
}
|
|
457
461
|
function jsonFieldPath(field) {
|
|
458
462
|
return [field.$$field, ...field.$$subfield].join("/");
|
|
459
463
|
}
|
package/dist/events/index.js
CHANGED
|
@@ -238,6 +238,7 @@ __export(events_exports, {
|
|
|
238
238
|
ageToDate: () => ageToDate,
|
|
239
239
|
aggregateActionAnnotations: () => aggregateActionAnnotations,
|
|
240
240
|
aggregateActionDeclarations: () => aggregateActionDeclarations,
|
|
241
|
+
always: () => always,
|
|
241
242
|
alwaysTrue: () => alwaysTrue,
|
|
242
243
|
and: () => and,
|
|
243
244
|
annotationActions: () => annotationActions,
|
|
@@ -281,6 +282,7 @@ __export(events_exports, {
|
|
|
281
282
|
findActiveDraftForEvent: () => findActiveDraftForEvent,
|
|
282
283
|
findAllFields: () => findAllFields,
|
|
283
284
|
findLastAssignmentAction: () => findLastAssignmentAction,
|
|
285
|
+
findPendingCorrectionAction: () => findPendingCorrectionAction,
|
|
284
286
|
findRecordActionPages: () => findRecordActionPages,
|
|
285
287
|
flag: () => flag,
|
|
286
288
|
flattenFieldReference: () => flattenFieldReference,
|
|
@@ -322,6 +324,7 @@ __export(events_exports, {
|
|
|
322
324
|
getDeclarationFields: () => getDeclarationFields,
|
|
323
325
|
getDeclarationPages: () => getDeclarationPages,
|
|
324
326
|
getEventConfigById: () => getEventConfigById,
|
|
327
|
+
getEventFlags: () => getEventFlags,
|
|
325
328
|
getFilePathsFromEvent: () => getFilePathsFromEvent,
|
|
326
329
|
getLocationHierarchy: () => getLocationHierarchy,
|
|
327
330
|
getMixedPath: () => getMixedPath,
|
|
@@ -384,6 +387,7 @@ __export(events_exports, {
|
|
|
384
387
|
isPageVisible: () => isPageVisible,
|
|
385
388
|
isParagraphFieldType: () => isParagraphFieldType,
|
|
386
389
|
isPhoneFieldType: () => isPhoneFieldType,
|
|
390
|
+
isPotentialDuplicate: () => isPotentialDuplicate,
|
|
387
391
|
isPrintButtonFieldType: () => isPrintButtonFieldType,
|
|
388
392
|
isQrReaderFieldType: () => isQrReaderFieldType,
|
|
389
393
|
isQueryParamReaderFieldType: () => isQueryParamReaderFieldType,
|
|
@@ -417,6 +421,7 @@ __export(events_exports, {
|
|
|
417
421
|
plainDateToLocalDate: () => plainDateToLocalDate,
|
|
418
422
|
precompileActionSchemas: () => precompileActionSchemas,
|
|
419
423
|
resolveDateOfEvent: () => resolveDateOfEvent,
|
|
424
|
+
resolveEventCustomFlags: () => resolveEventCustomFlags,
|
|
420
425
|
resolvePlaceOfEvent: () => resolvePlaceOfEvent,
|
|
421
426
|
runFieldValidations: () => runFieldValidations,
|
|
422
427
|
runStructuralValidations: () => runStructuralValidations,
|
|
@@ -4854,6 +4859,9 @@ function not(condition) {
|
|
|
4854
4859
|
function never2() {
|
|
4855
4860
|
return not(alwaysTrue());
|
|
4856
4861
|
}
|
|
4862
|
+
function always() {
|
|
4863
|
+
return defineConditional(alwaysTrue());
|
|
4864
|
+
}
|
|
4857
4865
|
function jsonFieldPath(field3) {
|
|
4858
4866
|
return [field3.$$field, ...field3.$$subfield].join("/");
|
|
4859
4867
|
}
|
|
@@ -6384,26 +6392,43 @@ var import_date_fns3 = require("date-fns");
|
|
|
6384
6392
|
function isEditInProgress(actions) {
|
|
6385
6393
|
return actions.at(-1)?.type === ActionType.EDIT;
|
|
6386
6394
|
}
|
|
6395
|
+
function findPendingCorrectionAction(writeActions2) {
|
|
6396
|
+
let correctionRequestAction;
|
|
6397
|
+
for (let i = writeActions2.length - 1; i >= 0; i--) {
|
|
6398
|
+
const action = writeActions2[i];
|
|
6399
|
+
if (action.type === ActionType.APPROVE_CORRECTION || action.type === ActionType.REJECT_CORRECTION) {
|
|
6400
|
+
break;
|
|
6401
|
+
}
|
|
6402
|
+
if (action.type === ActionType.REQUEST_CORRECTION) {
|
|
6403
|
+
correctionRequestAction = action;
|
|
6404
|
+
break;
|
|
6405
|
+
}
|
|
6406
|
+
}
|
|
6407
|
+
return correctionRequestAction;
|
|
6408
|
+
}
|
|
6387
6409
|
function isCorrectionRequested(actions) {
|
|
6410
|
+
return findPendingCorrectionAction(actions) !== void 0;
|
|
6411
|
+
}
|
|
6412
|
+
function isDeclarationIncomplete(actions) {
|
|
6413
|
+
return getStatusFromActions(actions) === EventStatus.enum.NOTIFIED;
|
|
6414
|
+
}
|
|
6415
|
+
function isRejected(actions) {
|
|
6416
|
+
const resettingActionTypes = [
|
|
6417
|
+
ActionType.NOTIFY,
|
|
6418
|
+
ActionType.DECLARE,
|
|
6419
|
+
ActionType.EDIT,
|
|
6420
|
+
ActionType.REGISTER
|
|
6421
|
+
];
|
|
6388
6422
|
return actions.reduce((prev, { type }) => {
|
|
6389
|
-
if (type === ActionType.
|
|
6423
|
+
if (type === ActionType.REJECT) {
|
|
6390
6424
|
return true;
|
|
6391
6425
|
}
|
|
6392
|
-
if (type
|
|
6393
|
-
return false;
|
|
6394
|
-
}
|
|
6395
|
-
if (type === ActionType.REJECT_CORRECTION) {
|
|
6426
|
+
if (resettingActionTypes.includes(type)) {
|
|
6396
6427
|
return false;
|
|
6397
6428
|
}
|
|
6398
6429
|
return prev;
|
|
6399
6430
|
}, false);
|
|
6400
6431
|
}
|
|
6401
|
-
function isDeclarationIncomplete(actions) {
|
|
6402
|
-
return getStatusFromActions(actions) === EventStatus.enum.NOTIFIED;
|
|
6403
|
-
}
|
|
6404
|
-
function isRejected(actions) {
|
|
6405
|
-
return actions.at(-1)?.type === ActionType.REJECT;
|
|
6406
|
-
}
|
|
6407
6432
|
function isPotentialDuplicate(actions) {
|
|
6408
6433
|
return actions.reduce((prev, { type }) => {
|
|
6409
6434
|
if (type === ActionType.DUPLICATE_DETECTED) {
|
|
@@ -6466,8 +6491,7 @@ function resolveEventCustomFlags(event2, eventConfiguration) {
|
|
|
6466
6491
|
return (0, import_lodash3.uniq)(flags);
|
|
6467
6492
|
}, []);
|
|
6468
6493
|
}
|
|
6469
|
-
function
|
|
6470
|
-
const sortedActions = event2.actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
6494
|
+
function getActionStatusFlags(sortedActions) {
|
|
6471
6495
|
const actionStatus = sortedActions.reduce(
|
|
6472
6496
|
(actionStatuses, { type, status: status2 }) => ({
|
|
6473
6497
|
...actionStatuses,
|
|
@@ -6475,26 +6499,40 @@ function getEventFlags(event2, config) {
|
|
|
6475
6499
|
}),
|
|
6476
6500
|
{}
|
|
6477
6501
|
);
|
|
6478
|
-
|
|
6502
|
+
return Object.entries(actionStatus).filter(([, status2]) => status2 !== ActionStatus.Accepted).map(([type, status2]) => {
|
|
6479
6503
|
const flag2 = joinValues([type, status2], ":").toLowerCase();
|
|
6480
6504
|
return flag2;
|
|
6481
6505
|
});
|
|
6482
|
-
|
|
6483
|
-
|
|
6506
|
+
}
|
|
6507
|
+
function getInherentFlags(sortedActions) {
|
|
6508
|
+
const acceptedActions = sortedActions.filter(
|
|
6509
|
+
({ status: status2 }) => status2 === ActionStatus.Accepted
|
|
6510
|
+
);
|
|
6511
|
+
const inherentFlags = [];
|
|
6512
|
+
if (isCorrectionRequested(acceptedActions)) {
|
|
6513
|
+
inherentFlags.push(InherentFlags.CORRECTION_REQUESTED);
|
|
6484
6514
|
}
|
|
6485
|
-
if (isDeclarationIncomplete(
|
|
6486
|
-
|
|
6515
|
+
if (isDeclarationIncomplete(acceptedActions)) {
|
|
6516
|
+
inherentFlags.push(InherentFlags.INCOMPLETE);
|
|
6487
6517
|
}
|
|
6488
|
-
if (isRejected(
|
|
6489
|
-
|
|
6518
|
+
if (isRejected(acceptedActions)) {
|
|
6519
|
+
inherentFlags.push(InherentFlags.REJECTED);
|
|
6490
6520
|
}
|
|
6491
|
-
if (isPotentialDuplicate(
|
|
6492
|
-
|
|
6521
|
+
if (isPotentialDuplicate(acceptedActions)) {
|
|
6522
|
+
inherentFlags.push(InherentFlags.POTENTIAL_DUPLICATE);
|
|
6493
6523
|
}
|
|
6494
|
-
if (isEditInProgress(
|
|
6495
|
-
|
|
6524
|
+
if (isEditInProgress(acceptedActions)) {
|
|
6525
|
+
inherentFlags.push(InherentFlags.EDIT_IN_PROGRESS);
|
|
6496
6526
|
}
|
|
6497
|
-
return
|
|
6527
|
+
return inherentFlags;
|
|
6528
|
+
}
|
|
6529
|
+
function getEventFlags(event2, config) {
|
|
6530
|
+
const sortedActions = event2.actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
6531
|
+
return [
|
|
6532
|
+
...getActionStatusFlags(sortedActions),
|
|
6533
|
+
...getInherentFlags(sortedActions),
|
|
6534
|
+
...resolveEventCustomFlags(event2, config)
|
|
6535
|
+
];
|
|
6498
6536
|
}
|
|
6499
6537
|
|
|
6500
6538
|
// ../commons/src/events/state/index.ts
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencrvs/toolkit",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.f3705df",
|
|
4
4
|
"description": "OpenCRVS toolkit for building country configurations",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"bin": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"jwt-decode": "^3.0.0",
|
|
34
34
|
"lodash": "^4.17.10",
|
|
35
35
|
"object-hash": "^3.0.0",
|
|
36
|
-
"qs": "6.
|
|
36
|
+
"qs": "6.15.2",
|
|
37
37
|
"superjson": "1.9.0-0",
|
|
38
38
|
"ts-morph": "^27.0.2",
|
|
39
39
|
"uuid": "^9.0.0",
|
|
Binary file
|