@opencrvs/toolkit 1.8.0-rc.feaeeb7 → 1.8.0-rc.fec1d5d
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 +21731 -10342
- package/dist/commons/conditionals/conditionals.d.ts +37 -6
- package/dist/commons/conditionals/validate-address.test.d.ts +2 -0
- package/dist/commons/conditionals/validate.d.ts +45 -17
- package/dist/commons/conditionals/validate.test.d.ts +2 -0
- package/dist/commons/events/ActionConfig.d.ts +119422 -2084
- package/dist/commons/events/ActionDocument.d.ts +11499 -401
- package/dist/commons/events/ActionInput.d.ts +6662 -609
- package/dist/commons/events/ActionType.d.ts +31 -12
- package/dist/commons/events/AdvancedSearchConfig.d.ts +1029 -22
- package/dist/commons/events/CompositeFieldValue.d.ts +183 -2
- package/dist/commons/events/Conditional.d.ts +21 -5
- package/dist/commons/events/Constants.d.ts +3 -0
- package/dist/commons/events/CountryConfigQueryInput.d.ts +2982 -0
- package/dist/commons/events/CreatedAtLocation.d.ts +3 -0
- package/dist/commons/events/Draft.d.ts +476 -62
- package/dist/commons/events/EventConfig.d.ts +57486 -1824
- package/dist/commons/events/EventConfigInput.d.ts +6 -3
- package/dist/commons/events/EventDocument.d.ts +4653 -573
- package/dist/commons/events/EventIndex.d.ts +1600 -22
- package/dist/commons/events/EventMetadata.d.ts +299 -40
- package/dist/commons/events/FieldConfig.d.ts +5984 -974
- package/dist/commons/events/FieldType.d.ts +10 -2
- package/dist/commons/events/FieldTypeMapping.d.ts +218 -18
- package/dist/commons/events/FieldValue.d.ts +123 -8
- package/dist/commons/events/FormConfig.d.ts +50409 -90
- package/dist/commons/events/PageConfig.d.ts +12597 -0
- package/dist/commons/events/SummaryConfig.d.ts +93 -42
- package/dist/commons/events/TemplateConfig.d.ts +30 -10
- package/dist/commons/events/User.d.ts +31 -2
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +53 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +4812 -20
- package/dist/commons/events/defineConfig.d.ts +9397 -307
- package/dist/commons/events/event.d.ts +54 -0
- package/dist/commons/events/field.d.ts +77 -0
- package/dist/commons/events/index.d.ts +9 -1
- package/dist/commons/events/scopes.d.ts +45 -0
- package/dist/commons/events/serializer.d.ts +2 -0
- package/dist/commons/events/test.utils.d.ts +220 -224
- package/dist/commons/events/utils.d.ts +13896 -69
- package/dist/commons/events/utils.test.d.ts +2 -0
- package/dist/commons/events/workqueueDefaultColumns.d.ts +3 -0
- package/dist/conditionals/index.js +233 -108
- package/dist/events/index.js +4868 -1923
- package/dist/scopes/index.d.ts +158 -1
- package/dist/scopes/index.js +152 -1
- package/package.json +3 -2
@@ -22,19 +22,48 @@ 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
|
31
33
|
});
|
32
34
|
module.exports = __toCommonJS(conditionals_exports);
|
33
35
|
|
36
|
+
// ../commons/src/events/serializers/user/serializer.ts
|
37
|
+
var import_zod = require("zod");
|
38
|
+
var SerializedUserField = import_zod.z.object({
|
39
|
+
$userField: import_zod.z.enum([
|
40
|
+
"id",
|
41
|
+
"name",
|
42
|
+
"role",
|
43
|
+
"signatureFilename",
|
44
|
+
"primaryOfficeId"
|
45
|
+
])
|
46
|
+
});
|
47
|
+
function userSerializer(userField) {
|
48
|
+
return {
|
49
|
+
$userField: userField
|
50
|
+
};
|
51
|
+
}
|
52
|
+
|
34
53
|
// ../commons/src/conditionals/conditionals.ts
|
35
54
|
function defineConditional(schema) {
|
36
55
|
return schema;
|
37
56
|
}
|
57
|
+
function defineFormConditional(schema) {
|
58
|
+
const schemaWithForm = {
|
59
|
+
type: "object",
|
60
|
+
properties: {
|
61
|
+
$form: schema
|
62
|
+
},
|
63
|
+
required: ["$form"]
|
64
|
+
};
|
65
|
+
return defineConditional(schemaWithForm);
|
66
|
+
}
|
38
67
|
function alwaysTrue() {
|
39
68
|
return {};
|
40
69
|
}
|
@@ -59,7 +88,10 @@ function not(condition) {
|
|
59
88
|
required: []
|
60
89
|
});
|
61
90
|
}
|
62
|
-
|
91
|
+
function never() {
|
92
|
+
return not(alwaysTrue());
|
93
|
+
}
|
94
|
+
var user = Object.assign(userSerializer, {
|
63
95
|
hasScope: (scope) => defineConditional({
|
64
96
|
type: "object",
|
65
97
|
properties: {
|
@@ -79,96 +111,153 @@ var user = {
|
|
79
111
|
},
|
80
112
|
required: ["$user"]
|
81
113
|
})
|
82
|
-
};
|
83
|
-
|
84
|
-
|
114
|
+
});
|
115
|
+
function createEventConditionals() {
|
116
|
+
return {
|
117
|
+
/**
|
118
|
+
* Checks if the event contains a specific action type.
|
119
|
+
* @param action - The action type to check for.
|
120
|
+
*/
|
121
|
+
hasAction: (action) => defineConditional({
|
122
|
+
type: "object",
|
123
|
+
properties: {
|
124
|
+
$event: {
|
125
|
+
type: "object",
|
126
|
+
properties: {
|
127
|
+
actions: {
|
128
|
+
type: "array",
|
129
|
+
contains: {
|
130
|
+
type: "object",
|
131
|
+
properties: {
|
132
|
+
type: {
|
133
|
+
const: action
|
134
|
+
}
|
135
|
+
},
|
136
|
+
required: ["type"]
|
137
|
+
}
|
138
|
+
}
|
139
|
+
},
|
140
|
+
required: ["actions"]
|
141
|
+
}
|
142
|
+
},
|
143
|
+
required: ["$event"]
|
144
|
+
})
|
145
|
+
};
|
146
|
+
}
|
147
|
+
function getDateFromNow(days) {
|
148
|
+
return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
|
149
|
+
}
|
150
|
+
function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
|
151
|
+
return {
|
85
152
|
type: "object",
|
86
153
|
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
|
-
}
|
154
|
+
[fieldId]: {
|
155
|
+
type: "string",
|
156
|
+
format: "date",
|
157
|
+
[clause]: { $data: `1/${comparedFieldId}` }
|
158
|
+
},
|
159
|
+
[comparedFieldId]: { type: "string", format: "date" }
|
105
160
|
},
|
106
|
-
required: [
|
107
|
-
}
|
108
|
-
}
|
109
|
-
function
|
110
|
-
|
161
|
+
required: [fieldId]
|
162
|
+
};
|
163
|
+
}
|
164
|
+
function isFieldReference(value) {
|
165
|
+
return typeof value === "object" && value !== null && "$$field" in value;
|
166
|
+
}
|
167
|
+
function createFieldConditionals(fieldId) {
|
111
168
|
const getDateRange = (date, clause) => ({
|
112
169
|
type: "object",
|
113
170
|
properties: {
|
114
|
-
|
115
|
-
type: "
|
116
|
-
|
117
|
-
|
118
|
-
type: "string",
|
119
|
-
format: "date",
|
120
|
-
[clause]: date
|
121
|
-
}
|
122
|
-
},
|
123
|
-
required: [fieldId]
|
171
|
+
[fieldId]: {
|
172
|
+
type: "string",
|
173
|
+
format: "date",
|
174
|
+
[clause]: date
|
124
175
|
}
|
125
176
|
},
|
126
|
-
required: [
|
177
|
+
required: [fieldId]
|
127
178
|
});
|
128
179
|
return {
|
180
|
+
/**
|
181
|
+
* @private Internal property used for field reference tracking.
|
182
|
+
*/
|
183
|
+
$$field: fieldId,
|
129
184
|
isAfter: () => ({
|
130
185
|
days: (days) => ({
|
131
|
-
inPast: () =>
|
186
|
+
inPast: () => defineFormConditional(
|
132
187
|
getDateRange(getDateFromNow(days), "formatMinimum")
|
133
188
|
),
|
134
|
-
inFuture: () =>
|
189
|
+
inFuture: () => defineFormConditional(
|
135
190
|
getDateRange(getDateFromNow(-days), "formatMinimum")
|
136
191
|
)
|
137
192
|
}),
|
138
|
-
date: (date) =>
|
139
|
-
|
193
|
+
date: (date) => {
|
194
|
+
if (isFieldReference(date)) {
|
195
|
+
const comparedFieldId = date.$$field;
|
196
|
+
return defineFormConditional(
|
197
|
+
getDateRangeToFieldReference(
|
198
|
+
fieldId,
|
199
|
+
comparedFieldId,
|
200
|
+
"formatMinimum"
|
201
|
+
)
|
202
|
+
);
|
203
|
+
}
|
204
|
+
return defineFormConditional(getDateRange(date, "formatMinimum"));
|
205
|
+
},
|
206
|
+
now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
|
140
207
|
}),
|
141
208
|
isBefore: () => ({
|
142
209
|
days: (days) => ({
|
143
|
-
inPast: () =>
|
210
|
+
inPast: () => defineFormConditional(
|
144
211
|
getDateRange(getDateFromNow(days), "formatMaximum")
|
145
212
|
),
|
146
|
-
inFuture: () =>
|
213
|
+
inFuture: () => defineFormConditional(
|
147
214
|
getDateRange(getDateFromNow(-days), "formatMaximum")
|
148
215
|
)
|
149
216
|
}),
|
150
|
-
date: (date) =>
|
151
|
-
|
217
|
+
date: (date) => {
|
218
|
+
if (isFieldReference(date)) {
|
219
|
+
const comparedFieldId = date.$$field;
|
220
|
+
return defineFormConditional(
|
221
|
+
getDateRangeToFieldReference(
|
222
|
+
fieldId,
|
223
|
+
comparedFieldId,
|
224
|
+
"formatMaximum"
|
225
|
+
)
|
226
|
+
);
|
227
|
+
}
|
228
|
+
return defineFormConditional(getDateRange(date, "formatMaximum"));
|
229
|
+
},
|
230
|
+
now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
|
152
231
|
}),
|
153
|
-
isEqualTo: (value) =>
|
154
|
-
|
155
|
-
|
156
|
-
|
232
|
+
isEqualTo: (value) => {
|
233
|
+
if (isFieldReference(value)) {
|
234
|
+
const comparedFieldId = value.$$field;
|
235
|
+
return defineFormConditional({
|
157
236
|
type: "object",
|
158
237
|
properties: {
|
159
238
|
[fieldId]: {
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
const: value
|
165
|
-
}
|
239
|
+
type: ["string", "boolean"],
|
240
|
+
const: { $data: `/$form/${comparedFieldId}` }
|
241
|
+
},
|
242
|
+
[comparedFieldId]: { type: ["string", "boolean"] }
|
166
243
|
},
|
167
|
-
required: [fieldId]
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
|
244
|
+
required: [fieldId, comparedFieldId]
|
245
|
+
});
|
246
|
+
}
|
247
|
+
return defineFormConditional({
|
248
|
+
type: "object",
|
249
|
+
properties: {
|
250
|
+
[fieldId]: {
|
251
|
+
oneOf: [
|
252
|
+
{ type: "string", const: value },
|
253
|
+
{ type: "boolean", const: value }
|
254
|
+
],
|
255
|
+
const: value
|
256
|
+
}
|
257
|
+
},
|
258
|
+
required: [fieldId]
|
259
|
+
});
|
260
|
+
},
|
172
261
|
/**
|
173
262
|
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
174
263
|
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|
@@ -177,68 +266,104 @@ function field(fieldId) {
|
|
177
266
|
* NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
|
178
267
|
*
|
179
268
|
*/
|
180
|
-
isFalsy: () =>
|
269
|
+
isFalsy: () => defineFormConditional({
|
181
270
|
type: "object",
|
182
271
|
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
|
-
},
|
272
|
+
[fieldId]: {
|
195
273
|
anyOf: [
|
196
|
-
{
|
197
|
-
|
198
|
-
},
|
199
|
-
{
|
200
|
-
not: {
|
201
|
-
required: [fieldId]
|
202
|
-
}
|
203
|
-
}
|
274
|
+
{ const: "undefined" },
|
275
|
+
{ const: false },
|
276
|
+
{ const: null },
|
277
|
+
{ const: "" }
|
204
278
|
]
|
205
279
|
}
|
206
280
|
},
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
$form: {
|
213
|
-
type: "object",
|
214
|
-
properties: {
|
215
|
-
[fieldId]: {
|
216
|
-
type: "string",
|
217
|
-
enum: ["undefined"]
|
218
|
-
}
|
219
|
-
},
|
281
|
+
anyOf: [
|
282
|
+
{
|
283
|
+
required: [fieldId]
|
284
|
+
},
|
285
|
+
{
|
220
286
|
not: {
|
221
287
|
required: [fieldId]
|
222
288
|
}
|
223
289
|
}
|
290
|
+
]
|
291
|
+
}),
|
292
|
+
isUndefined: () => defineFormConditional({
|
293
|
+
type: "object",
|
294
|
+
properties: {
|
295
|
+
[fieldId]: {
|
296
|
+
type: "string",
|
297
|
+
enum: ["undefined"]
|
298
|
+
}
|
299
|
+
},
|
300
|
+
not: {
|
301
|
+
required: [fieldId]
|
302
|
+
}
|
303
|
+
}),
|
304
|
+
inArray: (values) => defineFormConditional({
|
305
|
+
type: "object",
|
306
|
+
properties: {
|
307
|
+
[fieldId]: {
|
308
|
+
type: "string",
|
309
|
+
enum: values
|
310
|
+
}
|
224
311
|
},
|
225
|
-
required: [
|
312
|
+
required: [fieldId]
|
226
313
|
}),
|
227
|
-
|
314
|
+
isValidEnglishName: () => defineFormConditional({
|
228
315
|
type: "object",
|
229
316
|
properties: {
|
230
|
-
|
317
|
+
[fieldId]: {
|
318
|
+
type: "string",
|
319
|
+
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'._-]*)*$",
|
320
|
+
description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
|
321
|
+
}
|
322
|
+
},
|
323
|
+
required: [fieldId]
|
324
|
+
}),
|
325
|
+
/**
|
326
|
+
* Checks if the field value matches a given regular expression pattern.
|
327
|
+
* @param pattern - The regular expression pattern to match the field value against.
|
328
|
+
* @returns A JSONSchema conditional that validates the field value against the pattern.
|
329
|
+
*/
|
330
|
+
matches: (pattern) => defineFormConditional({
|
331
|
+
type: "object",
|
332
|
+
properties: {
|
333
|
+
[fieldId]: {
|
334
|
+
type: "string",
|
335
|
+
pattern
|
336
|
+
}
|
337
|
+
},
|
338
|
+
required: [fieldId]
|
339
|
+
}),
|
340
|
+
isBetween: (min, max) => defineFormConditional({
|
341
|
+
type: "object",
|
342
|
+
properties: {
|
343
|
+
[fieldId]: {
|
344
|
+
type: "number",
|
345
|
+
minimum: min,
|
346
|
+
maximum: max
|
347
|
+
}
|
348
|
+
},
|
349
|
+
required: [fieldId]
|
350
|
+
}),
|
351
|
+
getId: () => ({ fieldId }),
|
352
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
353
|
+
object: (options) => defineFormConditional({
|
354
|
+
type: "object",
|
355
|
+
properties: {
|
356
|
+
[fieldId]: {
|
231
357
|
type: "object",
|
232
|
-
properties:
|
233
|
-
[
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
required: [fieldId]
|
358
|
+
properties: Object.fromEntries(
|
359
|
+
Object.entries(options).map(([key, value]) => {
|
360
|
+
return [key, value.properties.$form.properties[key]];
|
361
|
+
})
|
362
|
+
),
|
363
|
+
required: Object.keys(options)
|
239
364
|
}
|
240
365
|
},
|
241
|
-
required: [
|
366
|
+
required: [fieldId]
|
242
367
|
})
|
243
368
|
};
|
244
369
|
}
|