@opencrvs/toolkit 1.9.8-rc.0cafd28 → 1.9.8-rc.0cf339f
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/commons/api/router.d.ts +31001 -2467
- package/dist/commons/conditionals/conditionals.d.ts +1037 -1
- package/dist/commons/conditionals/validate.d.ts +11 -4
- package/dist/commons/events/ActionConfig.d.ts +26853 -1552
- package/dist/commons/events/ActionDocument.d.ts +846 -1899
- package/dist/commons/events/ActionInput.d.ts +277 -1073
- package/dist/commons/events/ActionType.d.ts +86 -9
- package/dist/commons/events/AdvancedSearchConfig.d.ts +228 -1238
- package/dist/commons/events/CompositeFieldValue.d.ts +29 -190
- package/dist/commons/events/Conditional.d.ts +26 -38
- package/dist/commons/events/Constants.d.ts +1 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +1195 -4223
- package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
- package/dist/commons/events/Draft.d.ts +71 -106
- package/dist/commons/events/DynamicFieldValue.d.ts +7 -91
- package/dist/commons/events/EventConfig.d.ts +21436 -2120
- package/dist/commons/events/EventConfigInput.d.ts +1 -1
- package/dist/commons/events/EventDocument.d.ts +337 -1349
- package/dist/commons/events/EventIndex.d.ts +196 -983
- package/dist/commons/events/EventInput.d.ts +3 -8
- package/dist/commons/events/EventMetadata.d.ts +113 -354
- package/dist/commons/events/FieldConfig.d.ts +4974 -12346
- package/dist/commons/events/FieldType.d.ts +20 -4
- package/dist/commons/events/FieldTypeMapping.d.ts +193 -897
- package/dist/commons/events/FieldValue.d.ts +87 -396
- package/dist/commons/events/Flag.d.ts +67 -0
- package/dist/commons/events/FormConfig.d.ts +15108 -721
- package/dist/commons/events/PageConfig.d.ts +10092 -319
- package/dist/commons/events/SummaryConfig.d.ts +14 -161
- package/dist/commons/events/TemplateConfig.d.ts +2 -3
- package/dist/commons/events/TranslationConfig.d.ts +2 -2
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
- package/dist/commons/events/WorkqueueConfig.d.ts +1865 -7177
- package/dist/commons/events/deduplication.d.ts +3 -3
- package/dist/commons/events/defineConfig.d.ts +28019 -147
- package/dist/commons/events/eventConfigValidation.d.ts +8 -0
- package/dist/commons/events/field.d.ts +154 -0
- package/dist/commons/events/index.d.ts +1 -0
- package/dist/commons/events/locations.d.ts +26 -19
- package/dist/commons/events/scopes.d.ts +5 -4
- package/dist/commons/events/state/availableActions.d.ts +0 -2
- package/dist/commons/events/state/flags.d.ts +21 -3
- package/dist/commons/events/state/index.d.ts +24 -21
- package/dist/commons/events/state/utils.d.ts +150 -132
- package/dist/commons/events/test.utils.d.ts +31 -8
- package/dist/commons/events/transactions.d.ts +1 -1
- package/dist/commons/events/utils.d.ts +56079 -370
- package/dist/commons/notification/UserNotifications.d.ts +55 -636
- package/dist/conditionals/index.d.ts.map +1 -1
- package/dist/conditionals/index.js +155 -11
- package/dist/events/deduplication.d.ts +3 -3
- package/dist/events/index.js +2210 -1734
- package/dist/notification/index.d.ts.map +1 -1
- package/dist/notification/index.js +1802 -1571
- package/dist/scopes/index.d.ts +169 -133
- package/dist/scopes/index.d.ts.map +1 -1
- package/dist/scopes/index.js +135 -94
- package/package.json +5 -5
- package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/conditionals/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/conditionals/index.ts"],"names":[],"mappings":"AAaA,cAAc,gCAAgC,CAAA"}
|
|
@@ -35,22 +35,26 @@ __export(conditionals_exports, {
|
|
|
35
35
|
createFieldConditionals: () => createFieldConditionals,
|
|
36
36
|
defineConditional: () => defineConditional,
|
|
37
37
|
defineFormConditional: () => defineFormConditional,
|
|
38
|
+
flag: () => flag,
|
|
39
|
+
isCodeToEvaluate: () => isCodeToEvaluate,
|
|
38
40
|
isFieldReference: () => isFieldReference,
|
|
39
41
|
never: () => never,
|
|
40
42
|
not: () => not,
|
|
41
43
|
now: () => now,
|
|
42
44
|
or: () => or,
|
|
45
|
+
status: () => status,
|
|
43
46
|
user: () => user
|
|
44
47
|
});
|
|
45
48
|
module.exports = __toCommonJS(conditionals_exports);
|
|
49
|
+
var z4 = __toESM(require("zod/v4"));
|
|
46
50
|
|
|
47
51
|
// ../commons/src/conditionals/conditionals.ts
|
|
48
52
|
var objectHash = __toESM(require("object-hash"));
|
|
49
53
|
|
|
50
54
|
// ../commons/src/events/serializers/user/serializer.ts
|
|
51
|
-
var
|
|
52
|
-
var SerializedUserField =
|
|
53
|
-
$userField:
|
|
55
|
+
var z = __toESM(require("zod/v4"));
|
|
56
|
+
var SerializedUserField = z.object({
|
|
57
|
+
$userField: z.enum([
|
|
54
58
|
"id",
|
|
55
59
|
"name",
|
|
56
60
|
"role",
|
|
@@ -59,11 +63,12 @@ var SerializedUserField = import_zod.z.object({
|
|
|
59
63
|
"firstname",
|
|
60
64
|
"middlename",
|
|
61
65
|
"surname",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"primaryOfficeId"
|
|
66
|
+
"signature",
|
|
67
|
+
"avatar",
|
|
68
|
+
"primaryOfficeId",
|
|
69
|
+
"administrativeAreaId"
|
|
65
70
|
]),
|
|
66
|
-
$location:
|
|
71
|
+
$location: z.string().optional()
|
|
67
72
|
});
|
|
68
73
|
function userSerializer(userField) {
|
|
69
74
|
return {
|
|
@@ -83,7 +88,7 @@ function userSerializer(userField) {
|
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
// ../commons/src/utils.ts
|
|
86
|
-
var z2 = __toESM(require("zod"));
|
|
91
|
+
var z2 = __toESM(require("zod/v4"));
|
|
87
92
|
var FullNameV1 = z2.array(
|
|
88
93
|
z2.object({
|
|
89
94
|
use: z2.string(),
|
|
@@ -108,9 +113,9 @@ function omitKeyDeep(obj, keyToRemove) {
|
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
// ../commons/src/events/serializers/date/serializer.ts
|
|
111
|
-
var
|
|
112
|
-
var SerializedNowDateTime =
|
|
113
|
-
$$now:
|
|
116
|
+
var import_zod = require("zod");
|
|
117
|
+
var SerializedNowDateTime = import_zod.z.object({
|
|
118
|
+
$$now: import_zod.z.literal(true)
|
|
114
119
|
});
|
|
115
120
|
function todayDateTimeValueSerializer() {
|
|
116
121
|
return { $$now: true };
|
|
@@ -245,6 +250,9 @@ var user = Object.assign(userSerializer, {
|
|
|
245
250
|
function isFieldReference(value) {
|
|
246
251
|
return typeof value === "object" && value !== null && "$$field" in value;
|
|
247
252
|
}
|
|
253
|
+
function isCodeToEvaluate(value) {
|
|
254
|
+
return typeof value === "object" && value !== null && "$$code" in value;
|
|
255
|
+
}
|
|
248
256
|
function getDateRangeToFieldReference(field, comparedField, clause) {
|
|
249
257
|
return {
|
|
250
258
|
type: "object",
|
|
@@ -329,6 +337,33 @@ function defineComparison(field, value, keyword) {
|
|
|
329
337
|
required: [field.$$field]
|
|
330
338
|
});
|
|
331
339
|
}
|
|
340
|
+
function flag(flagvalue) {
|
|
341
|
+
return defineConditional({
|
|
342
|
+
type: "object",
|
|
343
|
+
properties: {
|
|
344
|
+
$flags: {
|
|
345
|
+
type: "array",
|
|
346
|
+
contains: {
|
|
347
|
+
type: "string",
|
|
348
|
+
const: flagvalue
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
required: ["$flags"]
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
function status(statusValue) {
|
|
356
|
+
return defineConditional({
|
|
357
|
+
type: "object",
|
|
358
|
+
properties: {
|
|
359
|
+
$status: {
|
|
360
|
+
type: "string",
|
|
361
|
+
const: statusValue
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
required: ["$status"]
|
|
365
|
+
});
|
|
366
|
+
}
|
|
332
367
|
function createFieldConditionals(fieldId) {
|
|
333
368
|
const getDayRange = (field, days, clause, referenceDate) => ({
|
|
334
369
|
type: "object",
|
|
@@ -654,6 +689,112 @@ function createFieldConditionals(fieldId) {
|
|
|
654
689
|
required: [fieldId]
|
|
655
690
|
});
|
|
656
691
|
},
|
|
692
|
+
/**
|
|
693
|
+
* Executes a custom validation function defined by country configuration.
|
|
694
|
+
*
|
|
695
|
+
* **Use this as a last resort when predefined toolkit methods are insufficient.**
|
|
696
|
+
*
|
|
697
|
+
* The function is serialized via toString() and transmitted as part of the JSON Schema.
|
|
698
|
+
* It is deserialized just-in-time during validation on the client.
|
|
699
|
+
*
|
|
700
|
+
* @param fn - Validation function that receives the field value and form context.
|
|
701
|
+
* Must return true if valid, false if invalid.
|
|
702
|
+
*
|
|
703
|
+
* @returns JSONSchema conditional for AJV validation
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* // Simple age validation
|
|
707
|
+
* field('age').customClientValidator((value, ctx) => {
|
|
708
|
+
* return value >= 18
|
|
709
|
+
* })
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* // Cross-field validation: child DOB must be after mother DOB
|
|
713
|
+
* field('child.dob').customClientValidator((value, ctx) => {
|
|
714
|
+
* const motherDob = ctx.$form['mother.dob']
|
|
715
|
+
* if (!motherDob || !value) return false
|
|
716
|
+
* return new Date(value) > new Date(motherDob)
|
|
717
|
+
* })
|
|
718
|
+
*
|
|
719
|
+
* @example
|
|
720
|
+
* // Two number fields validated together
|
|
721
|
+
* field('fieldA').customClientValidator((value, ctx) => {
|
|
722
|
+
* const fieldB = ctx.$form['fieldB']
|
|
723
|
+
* if (!fieldB) return false
|
|
724
|
+
* return value + fieldB > 100
|
|
725
|
+
* })
|
|
726
|
+
*
|
|
727
|
+
* @remarks
|
|
728
|
+
* Limitations:
|
|
729
|
+
* - Client-side only. For backend validation, use country config event triggers.
|
|
730
|
+
* - Cannot reference external libraries (lodash, etc.)
|
|
731
|
+
* - Function must be pure — no side effects, no closures over external state
|
|
732
|
+
* - Function must be serialisable via toString()
|
|
733
|
+
* - Receives (value, context) parameters where context contains $form, $now, $online, etc.
|
|
734
|
+
* - Must return boolean: true = valid, false = invalid
|
|
735
|
+
*
|
|
736
|
+
* @see https://github.com/opencrvs/opencrvs-core/issues/11653
|
|
737
|
+
*/
|
|
738
|
+
customClientValidator(fn) {
|
|
739
|
+
const serializedFn = fn.toString();
|
|
740
|
+
return defineFormConditional({
|
|
741
|
+
type: "object",
|
|
742
|
+
properties: {
|
|
743
|
+
[fieldId]: wrapToPath(
|
|
744
|
+
{
|
|
745
|
+
customClientValidator: serializedFn
|
|
746
|
+
},
|
|
747
|
+
this.$$subfield
|
|
748
|
+
)
|
|
749
|
+
},
|
|
750
|
+
required: [fieldId]
|
|
751
|
+
});
|
|
752
|
+
},
|
|
753
|
+
/**
|
|
754
|
+
* Defines a client-side computation function for dynamic field values.
|
|
755
|
+
*
|
|
756
|
+
* **Use this as a last resort when predefined toolkit methods are insufficient.**
|
|
757
|
+
*
|
|
758
|
+
* The function is serialized via toString() and transmitted to the client,
|
|
759
|
+
* where it is deserialized and executed to compute field values dynamically.
|
|
760
|
+
*
|
|
761
|
+
* @param fn - Computation function that receives the field value and form context.
|
|
762
|
+
* Returns the computed value (any type).
|
|
763
|
+
*
|
|
764
|
+
* @returns CodeToEvaluate object for client-side execution
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* // Concatenate first and last name
|
|
768
|
+
* field('fullName').customClientEvaluation((value, ctx) => {
|
|
769
|
+
* return `${ctx.$form.firstName} ${ctx.$form.lastName}`
|
|
770
|
+
* })
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
* // Calculate age from date of birth
|
|
774
|
+
* field('childAge').customClientEvaluation((value, ctx) => {
|
|
775
|
+
* const dob = ctx.$form['child.dob']
|
|
776
|
+
* if (!dob) return undefined
|
|
777
|
+
* const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
|
|
778
|
+
* return age
|
|
779
|
+
* })
|
|
780
|
+
*
|
|
781
|
+
* @remarks
|
|
782
|
+
* Limitations:
|
|
783
|
+
* - Client-side only. For backend computation, use country config event triggers.
|
|
784
|
+
* - Cannot reference external libraries (lodash, etc.)
|
|
785
|
+
* - Function must be pure — no side effects, no closures over external state
|
|
786
|
+
* - Function must be serialisable via toString()
|
|
787
|
+
* - Receives (value, context) parameters where context contains $form, $now, $online, etc.
|
|
788
|
+
* - Should return the computed value (any type)
|
|
789
|
+
*
|
|
790
|
+
* @see https://github.com/opencrvs/opencrvs-core/issues/11653
|
|
791
|
+
*/
|
|
792
|
+
customClientEvaluation(fn) {
|
|
793
|
+
const serializedFn = fn.toString();
|
|
794
|
+
return {
|
|
795
|
+
$$code: serializedFn
|
|
796
|
+
};
|
|
797
|
+
},
|
|
657
798
|
getId: () => ({ fieldId }),
|
|
658
799
|
/**
|
|
659
800
|
* @deprecated
|
|
@@ -682,3 +823,6 @@ function createFieldConditionals(fieldId) {
|
|
|
682
823
|
})
|
|
683
824
|
};
|
|
684
825
|
}
|
|
826
|
+
|
|
827
|
+
// src/conditionals/index.ts
|
|
828
|
+
z4.globalRegistry.clear();
|
|
@@ -7,17 +7,17 @@ export declare function field(fieldId: string): {
|
|
|
7
7
|
fieldId: string;
|
|
8
8
|
type: "fuzzy";
|
|
9
9
|
options: {
|
|
10
|
+
fuzziness?: string | number | undefined;
|
|
10
11
|
boost?: number | undefined;
|
|
11
12
|
matchAgainst?: string | undefined;
|
|
12
|
-
fuzziness?: string | number | undefined;
|
|
13
13
|
} | undefined;
|
|
14
14
|
};
|
|
15
15
|
strictMatches: (options?: StrictMatcherOptions) => {
|
|
16
16
|
fieldId: string;
|
|
17
17
|
type: "strict";
|
|
18
18
|
options: {
|
|
19
|
-
value?: string | undefined;
|
|
20
19
|
boost?: number | undefined;
|
|
20
|
+
value?: string | undefined;
|
|
21
21
|
matchAgainst?: string | undefined;
|
|
22
22
|
} | undefined;
|
|
23
23
|
};
|
|
@@ -60,9 +60,9 @@ export declare function field(fieldId: string): {
|
|
|
60
60
|
type: "dateRange";
|
|
61
61
|
options: {
|
|
62
62
|
days: number;
|
|
63
|
+
pivot?: number | undefined;
|
|
63
64
|
boost?: number | undefined;
|
|
64
65
|
matchAgainst?: string | undefined;
|
|
65
|
-
pivot?: number | undefined;
|
|
66
66
|
};
|
|
67
67
|
};
|
|
68
68
|
};
|