@opencrvs/toolkit 1.8.0-rc.f988087 → 1.8.0-rc.f988670
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 +13703 -10688
- package/dist/commons/conditionals/conditionals.d.ts +32 -12
- package/dist/commons/conditionals/validate.d.ts +53 -17
- package/dist/commons/events/ActionConfig.d.ts +128971 -2093
- package/dist/commons/events/ActionDocument.d.ts +13021 -780
- package/dist/commons/events/ActionInput.d.ts +8135 -1182
- package/dist/commons/events/ActionType.d.ts +31 -12
- package/dist/commons/events/AdvancedSearchConfig.d.ts +1300 -22
- package/dist/commons/events/CompositeFieldValue.d.ts +192 -11
- 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 +4132 -0
- package/dist/commons/events/CreatedAtLocation.d.ts +2 -0
- package/dist/commons/events/Draft.d.ts +608 -117
- package/dist/commons/events/EventConfig.d.ts +61501 -1806
- package/dist/commons/events/EventConfigInput.d.ts +6 -3
- package/dist/commons/events/EventDocument.d.ts +5806 -1003
- package/dist/commons/events/EventIndex.d.ts +2350 -26
- package/dist/commons/events/EventMetadata.d.ts +347 -44
- package/dist/commons/events/FieldConfig.d.ts +7394 -956
- package/dist/commons/events/FieldType.d.ts +16 -2
- package/dist/commons/events/FieldTypeMapping.d.ts +269 -37
- package/dist/commons/events/FieldValue.d.ts +164 -20
- package/dist/commons/events/FormConfig.d.ts +54435 -90
- package/dist/commons/events/PageConfig.d.ts +13647 -0
- package/dist/commons/events/SummaryConfig.d.ts +93 -42
- package/dist/commons/events/TemplateConfig.d.ts +38 -0
- package/dist/commons/events/User.d.ts +34 -2
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +53 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +8240 -20
- package/dist/commons/events/defineConfig.d.ts +10034 -307
- package/dist/commons/events/event.d.ts +54 -0
- package/dist/commons/events/field.d.ts +108 -0
- package/dist/commons/events/index.d.ts +11 -1
- package/dist/commons/events/scopes.d.ts +44 -0
- package/dist/commons/events/serializer.d.ts +2 -0
- package/dist/commons/events/test.utils.d.ts +281 -237
- package/dist/commons/events/transactions.d.ts +1 -1
- package/dist/commons/events/utils.d.ts +16549 -70
- package/dist/commons/events/workqueueDefaultColumns.d.ts +3 -0
- package/dist/conditionals/index.js +228 -116
- package/dist/events/index.js +5572 -1907
- package/dist/scopes/index.d.ts +247 -1
- package/dist/scopes/index.js +231 -1
- package/package.json +4 -3
- package/tsconfig.json +1 -1
- package/dist/commons/conditionals/conditionals.test.d.ts +0 -2
@@ -1,7 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __create = Object.create;
|
2
3
|
var __defProp = Object.defineProperty;
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
8
|
var __export = (target, all) => {
|
7
9
|
for (var name in all)
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
15
17
|
}
|
16
18
|
return to;
|
17
19
|
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
29
|
|
20
30
|
// src/conditionals/index.ts
|
@@ -22,18 +32,53 @@ var conditionals_exports = {};
|
|
22
32
|
__export(conditionals_exports, {
|
23
33
|
alwaysTrue: () => alwaysTrue,
|
24
34
|
and: () => and,
|
35
|
+
createFieldConditionals: () => createFieldConditionals,
|
25
36
|
defineConditional: () => defineConditional,
|
26
|
-
|
27
|
-
|
37
|
+
defineFormConditional: () => defineFormConditional,
|
38
|
+
never: () => never,
|
28
39
|
not: () => not,
|
29
40
|
or: () => or,
|
30
41
|
user: () => user
|
31
42
|
});
|
32
43
|
module.exports = __toCommonJS(conditionals_exports);
|
33
44
|
|
45
|
+
// ../commons/src/conditionals/conditionals.ts
|
46
|
+
var objectHash = __toESM(require("object-hash"));
|
47
|
+
|
48
|
+
// ../commons/src/events/serializers/user/serializer.ts
|
49
|
+
var import_zod = require("zod");
|
50
|
+
var SerializedUserField = import_zod.z.object({
|
51
|
+
$userField: import_zod.z.enum([
|
52
|
+
"id",
|
53
|
+
"name",
|
54
|
+
"role",
|
55
|
+
"signature",
|
56
|
+
"avatar",
|
57
|
+
"primaryOfficeId"
|
58
|
+
])
|
59
|
+
});
|
60
|
+
function userSerializer(userField) {
|
61
|
+
return {
|
62
|
+
$userField: userField
|
63
|
+
};
|
64
|
+
}
|
65
|
+
|
34
66
|
// ../commons/src/conditionals/conditionals.ts
|
35
67
|
function defineConditional(schema) {
|
36
|
-
return
|
68
|
+
return {
|
69
|
+
$id: `https://opencrvs.org/conditionals/${objectHash.sha1(schema)}`,
|
70
|
+
...schema
|
71
|
+
};
|
72
|
+
}
|
73
|
+
function defineFormConditional(schema) {
|
74
|
+
const schemaWithForm = {
|
75
|
+
type: "object",
|
76
|
+
properties: {
|
77
|
+
$form: schema
|
78
|
+
},
|
79
|
+
required: ["$form"]
|
80
|
+
};
|
81
|
+
return defineConditional(schemaWithForm);
|
37
82
|
}
|
38
83
|
function alwaysTrue() {
|
39
84
|
return {};
|
@@ -59,7 +104,10 @@ function not(condition) {
|
|
59
104
|
required: []
|
60
105
|
});
|
61
106
|
}
|
62
|
-
|
107
|
+
function never() {
|
108
|
+
return not(alwaysTrue());
|
109
|
+
}
|
110
|
+
var user = Object.assign(userSerializer, {
|
63
111
|
hasScope: (scope) => defineConditional({
|
64
112
|
type: "object",
|
65
113
|
properties: {
|
@@ -79,96 +127,124 @@ var user = {
|
|
79
127
|
},
|
80
128
|
required: ["$user"]
|
81
129
|
})
|
82
|
-
};
|
83
|
-
|
84
|
-
|
130
|
+
});
|
131
|
+
function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
|
132
|
+
return {
|
85
133
|
type: "object",
|
86
134
|
properties: {
|
87
|
-
|
88
|
-
type: "
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
135
|
+
[fieldId]: {
|
136
|
+
type: "string",
|
137
|
+
format: "date",
|
138
|
+
[clause]: { $data: `1/${comparedFieldId}` }
|
139
|
+
},
|
140
|
+
[comparedFieldId]: { type: "string", format: "date" }
|
141
|
+
},
|
142
|
+
required: [fieldId]
|
143
|
+
};
|
144
|
+
}
|
145
|
+
function isFieldReference(value) {
|
146
|
+
return typeof value === "object" && value !== null && "$$field" in value;
|
147
|
+
}
|
148
|
+
function createFieldConditionals(fieldId) {
|
149
|
+
const getDayRange = (days, clause) => ({
|
150
|
+
type: "object",
|
151
|
+
properties: {
|
152
|
+
[fieldId]: {
|
153
|
+
type: "string",
|
154
|
+
format: "date",
|
155
|
+
daysFromNow: {
|
156
|
+
days,
|
157
|
+
clause
|
158
|
+
}
|
104
159
|
}
|
105
160
|
},
|
106
|
-
required: [
|
107
|
-
})
|
108
|
-
};
|
109
|
-
function field(fieldId) {
|
110
|
-
const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
|
161
|
+
required: [fieldId]
|
162
|
+
});
|
111
163
|
const getDateRange = (date, clause) => ({
|
112
164
|
type: "object",
|
113
165
|
properties: {
|
114
|
-
|
115
|
-
type: "
|
116
|
-
|
117
|
-
|
118
|
-
type: "string",
|
119
|
-
format: "date",
|
120
|
-
[clause]: date
|
121
|
-
}
|
122
|
-
},
|
123
|
-
required: [fieldId]
|
166
|
+
[fieldId]: {
|
167
|
+
type: "string",
|
168
|
+
format: "date",
|
169
|
+
[clause]: date
|
124
170
|
}
|
125
171
|
},
|
126
|
-
required: [
|
172
|
+
required: [fieldId]
|
127
173
|
});
|
128
174
|
return {
|
175
|
+
/**
|
176
|
+
* @private Internal property used for field reference tracking.
|
177
|
+
*/
|
178
|
+
$$field: fieldId,
|
129
179
|
isAfter: () => ({
|
130
180
|
days: (days) => ({
|
131
|
-
inPast: () =>
|
132
|
-
|
133
|
-
),
|
134
|
-
inFuture: () => defineConditional(
|
135
|
-
getDateRange(getDateFromNow(-days), "formatMinimum")
|
136
|
-
)
|
181
|
+
inPast: () => defineFormConditional(getDayRange(-days, "after")),
|
182
|
+
inFuture: () => defineFormConditional(getDayRange(days, "after"))
|
137
183
|
}),
|
138
|
-
date: (date) =>
|
139
|
-
|
184
|
+
date: (date) => {
|
185
|
+
if (isFieldReference(date)) {
|
186
|
+
const comparedFieldId = date.$$field;
|
187
|
+
return defineFormConditional(
|
188
|
+
getDateRangeToFieldReference(
|
189
|
+
fieldId,
|
190
|
+
comparedFieldId,
|
191
|
+
"formatMinimum"
|
192
|
+
)
|
193
|
+
);
|
194
|
+
}
|
195
|
+
return defineFormConditional(getDateRange(date, "formatMinimum"));
|
196
|
+
},
|
197
|
+
now: () => defineFormConditional(getDateRange({ $data: "/$now" }, "formatMinimum"))
|
140
198
|
}),
|
141
199
|
isBefore: () => ({
|
142
200
|
days: (days) => ({
|
143
|
-
inPast: () =>
|
144
|
-
|
145
|
-
),
|
146
|
-
inFuture: () => defineConditional(
|
147
|
-
getDateRange(getDateFromNow(-days), "formatMaximum")
|
148
|
-
)
|
201
|
+
inPast: () => defineFormConditional(getDayRange(days, "before")),
|
202
|
+
inFuture: () => defineFormConditional(getDayRange(-days, "before"))
|
149
203
|
}),
|
150
|
-
date: (date) =>
|
151
|
-
|
204
|
+
date: (date) => {
|
205
|
+
if (isFieldReference(date)) {
|
206
|
+
const comparedFieldId = date.$$field;
|
207
|
+
return defineFormConditional(
|
208
|
+
getDateRangeToFieldReference(
|
209
|
+
fieldId,
|
210
|
+
comparedFieldId,
|
211
|
+
"formatMaximum"
|
212
|
+
)
|
213
|
+
);
|
214
|
+
}
|
215
|
+
return defineFormConditional(getDateRange(date, "formatMaximum"));
|
216
|
+
},
|
217
|
+
now: () => defineFormConditional(getDateRange({ $data: "/$now" }, "formatMaximum"))
|
152
218
|
}),
|
153
|
-
isEqualTo: (value) =>
|
154
|
-
|
155
|
-
|
156
|
-
|
219
|
+
isEqualTo: (value) => {
|
220
|
+
if (isFieldReference(value)) {
|
221
|
+
const comparedFieldId = value.$$field;
|
222
|
+
return defineFormConditional({
|
157
223
|
type: "object",
|
158
224
|
properties: {
|
159
225
|
[fieldId]: {
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
const: value
|
165
|
-
}
|
226
|
+
type: ["string", "boolean"],
|
227
|
+
const: { $data: `/$form/${comparedFieldId}` }
|
228
|
+
},
|
229
|
+
[comparedFieldId]: { type: ["string", "boolean"] }
|
166
230
|
},
|
167
|
-
required: [fieldId]
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
|
231
|
+
required: [fieldId, comparedFieldId]
|
232
|
+
});
|
233
|
+
}
|
234
|
+
return defineFormConditional({
|
235
|
+
type: "object",
|
236
|
+
properties: {
|
237
|
+
[fieldId]: {
|
238
|
+
oneOf: [
|
239
|
+
{ type: "string", const: value },
|
240
|
+
{ type: "boolean", const: value }
|
241
|
+
],
|
242
|
+
const: value
|
243
|
+
}
|
244
|
+
},
|
245
|
+
required: [fieldId]
|
246
|
+
});
|
247
|
+
},
|
172
248
|
/**
|
173
249
|
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
174
250
|
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|
@@ -177,68 +253,104 @@ function field(fieldId) {
|
|
177
253
|
* NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
|
178
254
|
*
|
179
255
|
*/
|
180
|
-
isFalsy: () =>
|
256
|
+
isFalsy: () => defineFormConditional({
|
181
257
|
type: "object",
|
182
258
|
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
|
-
},
|
259
|
+
[fieldId]: {
|
195
260
|
anyOf: [
|
196
|
-
{
|
197
|
-
|
198
|
-
},
|
199
|
-
{
|
200
|
-
not: {
|
201
|
-
required: [fieldId]
|
202
|
-
}
|
203
|
-
}
|
261
|
+
{ const: "undefined" },
|
262
|
+
{ const: false },
|
263
|
+
{ const: null },
|
264
|
+
{ const: "" }
|
204
265
|
]
|
205
266
|
}
|
206
267
|
},
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
$form: {
|
213
|
-
type: "object",
|
214
|
-
properties: {
|
215
|
-
[fieldId]: {
|
216
|
-
type: "string",
|
217
|
-
enum: ["undefined"]
|
218
|
-
}
|
219
|
-
},
|
268
|
+
anyOf: [
|
269
|
+
{
|
270
|
+
required: [fieldId]
|
271
|
+
},
|
272
|
+
{
|
220
273
|
not: {
|
221
274
|
required: [fieldId]
|
222
275
|
}
|
223
276
|
}
|
277
|
+
]
|
278
|
+
}),
|
279
|
+
isUndefined: () => defineFormConditional({
|
280
|
+
type: "object",
|
281
|
+
properties: {
|
282
|
+
[fieldId]: {
|
283
|
+
type: "string",
|
284
|
+
enum: ["undefined"]
|
285
|
+
}
|
224
286
|
},
|
225
|
-
|
287
|
+
not: {
|
288
|
+
required: [fieldId]
|
289
|
+
}
|
290
|
+
}),
|
291
|
+
inArray: (values) => defineFormConditional({
|
292
|
+
type: "object",
|
293
|
+
properties: {
|
294
|
+
[fieldId]: {
|
295
|
+
type: "string",
|
296
|
+
enum: values
|
297
|
+
}
|
298
|
+
},
|
299
|
+
required: [fieldId]
|
226
300
|
}),
|
227
|
-
|
301
|
+
isValidEnglishName: () => defineFormConditional({
|
228
302
|
type: "object",
|
229
303
|
properties: {
|
230
|
-
|
304
|
+
[fieldId]: {
|
305
|
+
type: "string",
|
306
|
+
minLength: 1,
|
307
|
+
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'.-]*)*$",
|
308
|
+
description: "Name must contain only letters, numbers, and allowed special characters ('.-). No double spaces."
|
309
|
+
}
|
310
|
+
}
|
311
|
+
}),
|
312
|
+
/**
|
313
|
+
* Checks if the field value matches a given regular expression pattern.
|
314
|
+
* @param pattern - The regular expression pattern to match the field value against.
|
315
|
+
* @returns A JSONSchema conditional that validates the field value against the pattern.
|
316
|
+
*/
|
317
|
+
matches: (pattern) => defineFormConditional({
|
318
|
+
type: "object",
|
319
|
+
properties: {
|
320
|
+
[fieldId]: {
|
321
|
+
type: "string",
|
322
|
+
pattern
|
323
|
+
}
|
324
|
+
},
|
325
|
+
required: [fieldId]
|
326
|
+
}),
|
327
|
+
isBetween: (min, max) => defineFormConditional({
|
328
|
+
type: "object",
|
329
|
+
properties: {
|
330
|
+
[fieldId]: {
|
331
|
+
type: "number",
|
332
|
+
minimum: min,
|
333
|
+
maximum: max
|
334
|
+
}
|
335
|
+
},
|
336
|
+
required: [fieldId]
|
337
|
+
}),
|
338
|
+
getId: () => ({ fieldId }),
|
339
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
340
|
+
object: (options) => defineFormConditional({
|
341
|
+
type: "object",
|
342
|
+
properties: {
|
343
|
+
[fieldId]: {
|
231
344
|
type: "object",
|
232
|
-
properties:
|
233
|
-
[
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
required: [fieldId]
|
345
|
+
properties: Object.fromEntries(
|
346
|
+
Object.entries(options).map(([key, value]) => {
|
347
|
+
return [key, value.properties.$form.properties[key]];
|
348
|
+
})
|
349
|
+
),
|
350
|
+
required: Object.keys(options)
|
239
351
|
}
|
240
352
|
},
|
241
|
-
required: [
|
353
|
+
required: [fieldId]
|
242
354
|
})
|
243
355
|
};
|
244
356
|
}
|