@opencrvs/toolkit 1.8.0-rc.ff2e7b6 → 1.8.0-rc.ff5b3f3
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/README.md +1 -1
- package/dist/commons/api/router.d.ts +14000 -10258
- package/dist/commons/conditionals/conditionals.d.ts +31 -5
- package/dist/commons/conditionals/validate-address.test.d.ts +2 -0
- package/dist/commons/conditionals/validate.d.ts +39 -17
- package/dist/commons/conditionals/validate.test.d.ts +2 -0
- package/dist/commons/events/ActionConfig.d.ts +96433 -2024
- package/dist/commons/events/ActionDocument.d.ts +9819 -312
- package/dist/commons/events/ActionInput.d.ts +5362 -497
- package/dist/commons/events/ActionType.d.ts +26 -11
- package/dist/commons/events/AdvancedSearchConfig.d.ts +957 -22
- package/dist/commons/events/CompositeFieldValue.d.ts +155 -2
- package/dist/commons/events/Conditional.d.ts +21 -5
- package/dist/commons/events/Draft.d.ts +367 -51
- package/dist/commons/events/EventConfig.d.ts +46117 -1819
- package/dist/commons/events/EventConfigInput.d.ts +6 -3
- package/dist/commons/events/EventDocument.d.ts +3521 -424
- package/dist/commons/events/EventIndex.d.ts +1735 -10
- package/dist/commons/events/EventInput.d.ts +13 -0
- package/dist/commons/events/EventMetadata.d.ts +274 -8
- package/dist/commons/events/FieldConfig.d.ts +4765 -787
- package/dist/commons/events/FieldType.d.ts +4 -3
- package/dist/commons/events/FieldTypeMapping.d.ts +164 -6
- package/dist/commons/events/FieldValue.d.ts +82 -5
- package/dist/commons/events/FormConfig.d.ts +43810 -73
- package/dist/commons/events/PageConfig.d.ts +10991 -0
- package/dist/commons/events/SummaryConfig.d.ts +95 -39
- package/dist/commons/events/TemplateConfig.d.ts +5 -5
- package/dist/commons/events/User.d.ts +5 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +1549 -19
- package/dist/commons/events/defineConfig.d.ts +7282 -230
- package/dist/commons/events/event.d.ts +54 -0
- package/dist/commons/events/field.d.ts +82 -0
- package/dist/commons/events/index.d.ts +5 -1
- package/dist/commons/events/scopes.d.ts +45 -0
- package/dist/commons/events/test.utils.d.ts +129 -239
- package/dist/commons/events/utils.d.ts +3793 -73
- package/dist/commons/events/utils.test.d.ts +2 -0
- package/dist/conditionals/index.js +196 -108
- package/dist/events/index.js +3033 -1382
- package/dist/scopes/index.d.ts +158 -1
- package/dist/scopes/index.js +152 -1
- package/package.json +3 -2
@@ -22,9 +22,11 @@ var conditionals_exports = {};
|
|
22
22
|
__export(conditionals_exports, {
|
23
23
|
alwaysTrue: () => alwaysTrue,
|
24
24
|
and: () => and,
|
25
|
+
createEventConditionals: () => createEventConditionals,
|
26
|
+
createFieldConditionals: () => createFieldConditionals,
|
25
27
|
defineConditional: () => defineConditional,
|
26
|
-
|
27
|
-
|
28
|
+
defineFormConditional: () => defineFormConditional,
|
29
|
+
never: () => never,
|
28
30
|
not: () => not,
|
29
31
|
or: () => or,
|
30
32
|
user: () => user
|
@@ -35,6 +37,16 @@ module.exports = __toCommonJS(conditionals_exports);
|
|
35
37
|
function defineConditional(schema) {
|
36
38
|
return schema;
|
37
39
|
}
|
40
|
+
function defineFormConditional(schema) {
|
41
|
+
const schemaWithForm = {
|
42
|
+
type: "object",
|
43
|
+
properties: {
|
44
|
+
$form: schema
|
45
|
+
},
|
46
|
+
required: ["$form"]
|
47
|
+
};
|
48
|
+
return defineConditional(schemaWithForm);
|
49
|
+
}
|
38
50
|
function alwaysTrue() {
|
39
51
|
return {};
|
40
52
|
}
|
@@ -59,6 +71,9 @@ function not(condition) {
|
|
59
71
|
required: []
|
60
72
|
});
|
61
73
|
}
|
74
|
+
function never() {
|
75
|
+
return not(alwaysTrue());
|
76
|
+
}
|
62
77
|
var user = {
|
63
78
|
hasScope: (scope) => defineConditional({
|
64
79
|
type: "object",
|
@@ -80,95 +95,148 @@ var user = {
|
|
80
95
|
required: ["$user"]
|
81
96
|
})
|
82
97
|
};
|
83
|
-
|
84
|
-
|
98
|
+
function createEventConditionals() {
|
99
|
+
return {
|
100
|
+
/**
|
101
|
+
* Checks if the event contains a specific action type.
|
102
|
+
* @param action - The action type to check for.
|
103
|
+
*/
|
104
|
+
hasAction: (action) => defineConditional({
|
105
|
+
type: "object",
|
106
|
+
properties: {
|
107
|
+
$event: {
|
108
|
+
type: "object",
|
109
|
+
properties: {
|
110
|
+
actions: {
|
111
|
+
type: "array",
|
112
|
+
contains: {
|
113
|
+
type: "object",
|
114
|
+
properties: {
|
115
|
+
type: {
|
116
|
+
const: action
|
117
|
+
}
|
118
|
+
},
|
119
|
+
required: ["type"]
|
120
|
+
}
|
121
|
+
}
|
122
|
+
},
|
123
|
+
required: ["actions"]
|
124
|
+
}
|
125
|
+
},
|
126
|
+
required: ["$event"]
|
127
|
+
})
|
128
|
+
};
|
129
|
+
}
|
130
|
+
function getDateFromNow(days) {
|
131
|
+
return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
|
132
|
+
}
|
133
|
+
function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
|
134
|
+
return {
|
85
135
|
type: "object",
|
86
136
|
properties: {
|
87
|
-
|
88
|
-
type: "
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
type: "object",
|
94
|
-
properties: {
|
95
|
-
type: {
|
96
|
-
const: action
|
97
|
-
}
|
98
|
-
},
|
99
|
-
required: ["type"]
|
100
|
-
}
|
101
|
-
}
|
102
|
-
},
|
103
|
-
required: ["actions"]
|
104
|
-
}
|
137
|
+
[fieldId]: {
|
138
|
+
type: "string",
|
139
|
+
format: "date",
|
140
|
+
[clause]: { $data: `1/${comparedFieldId}` }
|
141
|
+
},
|
142
|
+
[comparedFieldId]: { type: "string", format: "date" }
|
105
143
|
},
|
106
|
-
required: [
|
107
|
-
}
|
108
|
-
}
|
109
|
-
function
|
110
|
-
|
144
|
+
required: [fieldId]
|
145
|
+
};
|
146
|
+
}
|
147
|
+
function isFieldReference(value) {
|
148
|
+
return typeof value === "object" && value !== null && "_fieldId" in value;
|
149
|
+
}
|
150
|
+
function createFieldConditionals(fieldId) {
|
111
151
|
const getDateRange = (date, clause) => ({
|
112
152
|
type: "object",
|
113
153
|
properties: {
|
114
|
-
|
115
|
-
type: "
|
116
|
-
|
117
|
-
|
118
|
-
type: "string",
|
119
|
-
format: "date",
|
120
|
-
[clause]: date
|
121
|
-
}
|
122
|
-
},
|
123
|
-
required: [fieldId]
|
154
|
+
[fieldId]: {
|
155
|
+
type: "string",
|
156
|
+
format: "date",
|
157
|
+
[clause]: date
|
124
158
|
}
|
125
159
|
},
|
126
|
-
required: [
|
160
|
+
required: [fieldId]
|
127
161
|
});
|
128
162
|
return {
|
129
163
|
isAfter: () => ({
|
130
164
|
days: (days) => ({
|
131
|
-
inPast: () =>
|
165
|
+
inPast: () => defineFormConditional(
|
132
166
|
getDateRange(getDateFromNow(days), "formatMinimum")
|
133
167
|
),
|
134
|
-
inFuture: () =>
|
168
|
+
inFuture: () => defineFormConditional(
|
135
169
|
getDateRange(getDateFromNow(-days), "formatMinimum")
|
136
170
|
)
|
137
171
|
}),
|
138
|
-
date: (date) =>
|
139
|
-
|
172
|
+
date: (date) => {
|
173
|
+
if (isFieldReference(date)) {
|
174
|
+
const comparedFieldId = date._fieldId;
|
175
|
+
return defineFormConditional(
|
176
|
+
getDateRangeToFieldReference(
|
177
|
+
fieldId,
|
178
|
+
comparedFieldId,
|
179
|
+
"formatMinimum"
|
180
|
+
)
|
181
|
+
);
|
182
|
+
}
|
183
|
+
return defineFormConditional(getDateRange(date, "formatMinimum"));
|
184
|
+
},
|
185
|
+
now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
|
140
186
|
}),
|
141
187
|
isBefore: () => ({
|
142
188
|
days: (days) => ({
|
143
|
-
inPast: () =>
|
189
|
+
inPast: () => defineFormConditional(
|
144
190
|
getDateRange(getDateFromNow(days), "formatMaximum")
|
145
191
|
),
|
146
|
-
inFuture: () =>
|
192
|
+
inFuture: () => defineFormConditional(
|
147
193
|
getDateRange(getDateFromNow(-days), "formatMaximum")
|
148
194
|
)
|
149
195
|
}),
|
150
|
-
date: (date) =>
|
151
|
-
|
196
|
+
date: (date) => {
|
197
|
+
if (isFieldReference(date)) {
|
198
|
+
const comparedFieldId = date._fieldId;
|
199
|
+
return defineFormConditional(
|
200
|
+
getDateRangeToFieldReference(
|
201
|
+
fieldId,
|
202
|
+
comparedFieldId,
|
203
|
+
"formatMaximum"
|
204
|
+
)
|
205
|
+
);
|
206
|
+
}
|
207
|
+
return defineFormConditional(getDateRange(date, "formatMaximum"));
|
208
|
+
},
|
209
|
+
now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
|
152
210
|
}),
|
153
|
-
isEqualTo: (value) =>
|
154
|
-
|
155
|
-
|
156
|
-
|
211
|
+
isEqualTo: (value) => {
|
212
|
+
if (isFieldReference(value)) {
|
213
|
+
const comparedFieldId = value._fieldId;
|
214
|
+
return defineFormConditional({
|
157
215
|
type: "object",
|
158
216
|
properties: {
|
159
217
|
[fieldId]: {
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
const: value
|
165
|
-
}
|
218
|
+
type: ["string", "boolean"],
|
219
|
+
const: { $data: `1/${comparedFieldId}` }
|
220
|
+
},
|
221
|
+
[comparedFieldId]: { type: ["string", "boolean"] }
|
166
222
|
},
|
167
|
-
required: [fieldId]
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
|
223
|
+
required: [fieldId, comparedFieldId]
|
224
|
+
});
|
225
|
+
}
|
226
|
+
return defineFormConditional({
|
227
|
+
type: "object",
|
228
|
+
properties: {
|
229
|
+
[fieldId]: {
|
230
|
+
oneOf: [
|
231
|
+
{ type: "string", const: value },
|
232
|
+
{ type: "boolean", const: value }
|
233
|
+
],
|
234
|
+
const: value
|
235
|
+
}
|
236
|
+
},
|
237
|
+
required: [fieldId]
|
238
|
+
});
|
239
|
+
},
|
172
240
|
/**
|
173
241
|
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
174
242
|
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|
@@ -177,68 +245,88 @@ function field(fieldId) {
|
|
177
245
|
* NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
|
178
246
|
*
|
179
247
|
*/
|
180
|
-
isFalsy: () =>
|
248
|
+
isFalsy: () => defineFormConditional({
|
181
249
|
type: "object",
|
182
250
|
properties: {
|
183
|
-
|
184
|
-
type: "object",
|
185
|
-
properties: {
|
186
|
-
[fieldId]: {
|
187
|
-
anyOf: [
|
188
|
-
{ const: "undefined" },
|
189
|
-
{ const: false },
|
190
|
-
{ const: null },
|
191
|
-
{ const: "" }
|
192
|
-
]
|
193
|
-
}
|
194
|
-
},
|
251
|
+
[fieldId]: {
|
195
252
|
anyOf: [
|
196
|
-
{
|
197
|
-
|
198
|
-
},
|
199
|
-
{
|
200
|
-
not: {
|
201
|
-
required: [fieldId]
|
202
|
-
}
|
203
|
-
}
|
253
|
+
{ const: "undefined" },
|
254
|
+
{ const: false },
|
255
|
+
{ const: null },
|
256
|
+
{ const: "" }
|
204
257
|
]
|
205
258
|
}
|
206
259
|
},
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
$form: {
|
213
|
-
type: "object",
|
214
|
-
properties: {
|
215
|
-
[fieldId]: {
|
216
|
-
type: "string",
|
217
|
-
enum: ["undefined"]
|
218
|
-
}
|
219
|
-
},
|
260
|
+
anyOf: [
|
261
|
+
{
|
262
|
+
required: [fieldId]
|
263
|
+
},
|
264
|
+
{
|
220
265
|
not: {
|
221
266
|
required: [fieldId]
|
222
267
|
}
|
223
268
|
}
|
269
|
+
]
|
270
|
+
}),
|
271
|
+
isUndefined: () => defineFormConditional({
|
272
|
+
type: "object",
|
273
|
+
properties: {
|
274
|
+
[fieldId]: {
|
275
|
+
type: "string",
|
276
|
+
enum: ["undefined"]
|
277
|
+
}
|
224
278
|
},
|
225
|
-
|
279
|
+
not: {
|
280
|
+
required: [fieldId]
|
281
|
+
}
|
226
282
|
}),
|
227
|
-
inArray: (values) =>
|
283
|
+
inArray: (values) => defineFormConditional({
|
228
284
|
type: "object",
|
229
285
|
properties: {
|
230
|
-
|
231
|
-
type: "
|
232
|
-
|
233
|
-
[fieldId]: {
|
234
|
-
type: "string",
|
235
|
-
enum: values
|
236
|
-
}
|
237
|
-
},
|
238
|
-
required: [fieldId]
|
286
|
+
[fieldId]: {
|
287
|
+
type: "string",
|
288
|
+
enum: values
|
239
289
|
}
|
240
290
|
},
|
241
|
-
required: [
|
242
|
-
})
|
291
|
+
required: [fieldId]
|
292
|
+
}),
|
293
|
+
isValidEnglishName: () => defineFormConditional({
|
294
|
+
type: "object",
|
295
|
+
properties: {
|
296
|
+
[fieldId]: {
|
297
|
+
type: "string",
|
298
|
+
pattern: "^[\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*( [\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*)*$",
|
299
|
+
description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
|
300
|
+
}
|
301
|
+
},
|
302
|
+
required: [fieldId]
|
303
|
+
}),
|
304
|
+
/**
|
305
|
+
* Checks if the field value matches a given regular expression pattern.
|
306
|
+
* @param pattern - The regular expression pattern to match the field value against.
|
307
|
+
* @returns A JSONSchema conditional that validates the field value against the pattern.
|
308
|
+
*/
|
309
|
+
matches: (pattern) => defineFormConditional({
|
310
|
+
type: "object",
|
311
|
+
properties: {
|
312
|
+
[fieldId]: {
|
313
|
+
type: "string",
|
314
|
+
pattern
|
315
|
+
}
|
316
|
+
},
|
317
|
+
required: [fieldId]
|
318
|
+
}),
|
319
|
+
isBetween: (min, max) => defineFormConditional({
|
320
|
+
type: "object",
|
321
|
+
properties: {
|
322
|
+
[fieldId]: {
|
323
|
+
type: "number",
|
324
|
+
minimum: min,
|
325
|
+
maximum: max
|
326
|
+
}
|
327
|
+
},
|
328
|
+
required: [fieldId]
|
329
|
+
}),
|
330
|
+
getId: () => ({ fieldId })
|
243
331
|
};
|
244
332
|
}
|