@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.
Files changed (43) hide show
  1. package/README.md +1 -1
  2. package/dist/commons/api/router.d.ts +14000 -10258
  3. package/dist/commons/conditionals/conditionals.d.ts +31 -5
  4. package/dist/commons/conditionals/validate-address.test.d.ts +2 -0
  5. package/dist/commons/conditionals/validate.d.ts +39 -17
  6. package/dist/commons/conditionals/validate.test.d.ts +2 -0
  7. package/dist/commons/events/ActionConfig.d.ts +96433 -2024
  8. package/dist/commons/events/ActionDocument.d.ts +9819 -312
  9. package/dist/commons/events/ActionInput.d.ts +5362 -497
  10. package/dist/commons/events/ActionType.d.ts +26 -11
  11. package/dist/commons/events/AdvancedSearchConfig.d.ts +957 -22
  12. package/dist/commons/events/CompositeFieldValue.d.ts +155 -2
  13. package/dist/commons/events/Conditional.d.ts +21 -5
  14. package/dist/commons/events/Draft.d.ts +367 -51
  15. package/dist/commons/events/EventConfig.d.ts +46117 -1819
  16. package/dist/commons/events/EventConfigInput.d.ts +6 -3
  17. package/dist/commons/events/EventDocument.d.ts +3521 -424
  18. package/dist/commons/events/EventIndex.d.ts +1735 -10
  19. package/dist/commons/events/EventInput.d.ts +13 -0
  20. package/dist/commons/events/EventMetadata.d.ts +274 -8
  21. package/dist/commons/events/FieldConfig.d.ts +4765 -787
  22. package/dist/commons/events/FieldType.d.ts +4 -3
  23. package/dist/commons/events/FieldTypeMapping.d.ts +164 -6
  24. package/dist/commons/events/FieldValue.d.ts +82 -5
  25. package/dist/commons/events/FormConfig.d.ts +43810 -73
  26. package/dist/commons/events/PageConfig.d.ts +10991 -0
  27. package/dist/commons/events/SummaryConfig.d.ts +95 -39
  28. package/dist/commons/events/TemplateConfig.d.ts +5 -5
  29. package/dist/commons/events/User.d.ts +5 -0
  30. package/dist/commons/events/WorkqueueConfig.d.ts +1549 -19
  31. package/dist/commons/events/defineConfig.d.ts +7282 -230
  32. package/dist/commons/events/event.d.ts +54 -0
  33. package/dist/commons/events/field.d.ts +82 -0
  34. package/dist/commons/events/index.d.ts +5 -1
  35. package/dist/commons/events/scopes.d.ts +45 -0
  36. package/dist/commons/events/test.utils.d.ts +129 -239
  37. package/dist/commons/events/utils.d.ts +3793 -73
  38. package/dist/commons/events/utils.test.d.ts +2 -0
  39. package/dist/conditionals/index.js +196 -108
  40. package/dist/events/index.js +3033 -1382
  41. package/dist/scopes/index.d.ts +158 -1
  42. package/dist/scopes/index.js +152 -1
  43. package/package.json +3 -2
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utils.test.d.ts.map
@@ -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
- event: () => event,
27
- field: () => field,
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
- var event = {
84
- hasAction: (action) => defineConditional({
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
- $event: {
88
- type: "object",
89
- properties: {
90
- actions: {
91
- type: "array",
92
- contains: {
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: ["$event"]
107
- })
108
- };
109
- function field(fieldId) {
110
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
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
- $form: {
115
- type: "object",
116
- properties: {
117
- [fieldId]: {
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: ["$form"]
160
+ required: [fieldId]
127
161
  });
128
162
  return {
129
163
  isAfter: () => ({
130
164
  days: (days) => ({
131
- inPast: () => defineConditional(
165
+ inPast: () => defineFormConditional(
132
166
  getDateRange(getDateFromNow(days), "formatMinimum")
133
167
  ),
134
- inFuture: () => defineConditional(
168
+ inFuture: () => defineFormConditional(
135
169
  getDateRange(getDateFromNow(-days), "formatMinimum")
136
170
  )
137
171
  }),
138
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
139
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
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: () => defineConditional(
189
+ inPast: () => defineFormConditional(
144
190
  getDateRange(getDateFromNow(days), "formatMaximum")
145
191
  ),
146
- inFuture: () => defineConditional(
192
+ inFuture: () => defineFormConditional(
147
193
  getDateRange(getDateFromNow(-days), "formatMaximum")
148
194
  )
149
195
  }),
150
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
151
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
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) => defineConditional({
154
- type: "object",
155
- properties: {
156
- $form: {
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
- oneOf: [
161
- { type: "string", const: value },
162
- { type: "boolean", const: value }
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
- required: ["$form"]
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: () => defineConditional({
248
+ isFalsy: () => defineFormConditional({
181
249
  type: "object",
182
250
  properties: {
183
- $form: {
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
- required: [fieldId]
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
- required: ["$form"]
208
- }),
209
- isUndefined: () => defineConditional({
210
- type: "object",
211
- properties: {
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
- required: ["$form"]
279
+ not: {
280
+ required: [fieldId]
281
+ }
226
282
  }),
227
- inArray: (values) => defineConditional({
283
+ inArray: (values) => defineFormConditional({
228
284
  type: "object",
229
285
  properties: {
230
- $form: {
231
- type: "object",
232
- properties: {
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: ["$form"]
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
  }