@opencrvs/toolkit 1.8.0-rc.f876361 → 1.8.0-rc.f881988

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 (36) hide show
  1. package/dist/commons/api/router.d.ts +7334 -1430
  2. package/dist/commons/conditionals/conditionals.d.ts +23 -13
  3. package/dist/commons/conditionals/validate.d.ts +12 -17
  4. package/dist/commons/events/ActionConfig.d.ts +86380 -1682
  5. package/dist/commons/events/ActionDocument.d.ts +420 -103
  6. package/dist/commons/events/ActionInput.d.ts +1135 -232
  7. package/dist/commons/events/ActionType.d.ts +5 -3
  8. package/dist/commons/events/AdvancedSearchConfig.d.ts +371 -25
  9. package/dist/commons/events/CompositeFieldValue.d.ts +3 -0
  10. package/dist/commons/events/Conditional.d.ts +21 -5
  11. package/dist/commons/events/Draft.d.ts +37 -15
  12. package/dist/commons/events/EventConfig.d.ts +41061 -1337
  13. package/dist/commons/events/EventDocument.d.ts +334 -77
  14. package/dist/commons/events/EventIndex.d.ts +915 -4
  15. package/dist/commons/events/EventInput.d.ts +13 -0
  16. package/dist/commons/events/EventMetadata.d.ts +13 -3
  17. package/dist/commons/events/FieldConfig.d.ts +3628 -745
  18. package/dist/commons/events/FieldType.d.ts +1 -2
  19. package/dist/commons/events/FieldValue.d.ts +1 -1
  20. package/dist/commons/events/FormConfig.d.ts +38845 -517
  21. package/dist/commons/events/PageConfig.d.ts +9655 -211
  22. package/dist/commons/events/SummaryConfig.d.ts +81 -42
  23. package/dist/commons/events/TemplateConfig.d.ts +5 -5
  24. package/dist/commons/events/User.d.ts +5 -0
  25. package/dist/commons/events/WorkqueueConfig.d.ts +44 -20
  26. package/dist/commons/events/defineConfig.d.ts +6681 -31
  27. package/dist/commons/events/event.d.ts +25 -0
  28. package/dist/commons/events/field.d.ts +68 -0
  29. package/dist/commons/events/index.d.ts +3 -0
  30. package/dist/commons/events/scopes.d.ts +26 -0
  31. package/dist/commons/events/test.utils.d.ts +20 -149
  32. package/dist/commons/events/utils.d.ts +3417 -97
  33. package/dist/commons/events/utils.test.d.ts +2 -0
  34. package/dist/conditionals/index.js +164 -181
  35. package/dist/events/index.js +1336 -889
  36. 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,126 +95,146 @@ 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
- /**
130
- * @private Internal property used for field reference tracking.
131
- */
132
- _returning: fieldId,
133
163
  isAfter: () => ({
134
164
  days: (days) => ({
135
- inPast: () => defineConditional(
165
+ inPast: () => defineFormConditional(
136
166
  getDateRange(getDateFromNow(days), "formatMinimum")
137
167
  ),
138
- inFuture: () => defineConditional(
168
+ inFuture: () => defineFormConditional(
139
169
  getDateRange(getDateFromNow(-days), "formatMinimum")
140
170
  )
141
171
  }),
142
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
143
- 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"))
144
186
  }),
145
187
  isBefore: () => ({
146
188
  days: (days) => ({
147
- inPast: () => defineConditional(
189
+ inPast: () => defineFormConditional(
148
190
  getDateRange(getDateFromNow(days), "formatMaximum")
149
191
  ),
150
- inFuture: () => defineConditional(
192
+ inFuture: () => defineFormConditional(
151
193
  getDateRange(getDateFromNow(-days), "formatMaximum")
152
194
  )
153
195
  }),
154
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
155
- 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"))
156
210
  }),
157
- // TODO CIHAN: typing
158
211
  isEqualTo: (value) => {
159
- if (typeof value === "object" && value._returning) {
160
- const comparedFieldId = value._returning;
161
- return defineConditional({
212
+ if (isFieldReference(value)) {
213
+ const comparedFieldId = value._fieldId;
214
+ return defineFormConditional({
162
215
  type: "object",
163
216
  properties: {
164
- $form: {
165
- type: "object",
166
- properties: {
167
- [fieldId]: { type: ["string", "boolean"] },
168
- [comparedFieldId]: { type: ["string", "boolean"] }
169
- },
170
- required: [fieldId, comparedFieldId],
171
- allOf: [
172
- {
173
- properties: {
174
- [fieldId]: {
175
- const: { $data: `1/${comparedFieldId}` }
176
- }
177
- }
178
- }
179
- ]
180
- }
217
+ [fieldId]: {
218
+ type: ["string", "boolean"],
219
+ const: { $data: `1/${comparedFieldId}` }
220
+ },
221
+ [comparedFieldId]: { type: ["string", "boolean"] }
181
222
  },
182
- required: ["$form"]
223
+ required: [fieldId, comparedFieldId]
183
224
  });
184
225
  }
185
- return defineConditional({
226
+ return defineFormConditional({
186
227
  type: "object",
187
228
  properties: {
188
- $form: {
189
- type: "object",
190
- properties: {
191
- [fieldId]: {
192
- oneOf: [
193
- { type: "string", const: value },
194
- { type: "boolean", const: value }
195
- ],
196
- const: value
197
- }
198
- },
199
- required: [fieldId]
229
+ [fieldId]: {
230
+ oneOf: [
231
+ { type: "string", const: value },
232
+ { type: "boolean", const: value }
233
+ ],
234
+ const: value
200
235
  }
201
236
  },
202
- required: ["$form"]
237
+ required: [fieldId]
203
238
  });
204
239
  },
205
240
  /**
@@ -210,140 +245,88 @@ function field(fieldId) {
210
245
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
211
246
  *
212
247
  */
213
- isFalsy: () => defineConditional({
248
+ isFalsy: () => defineFormConditional({
214
249
  type: "object",
215
250
  properties: {
216
- $form: {
217
- type: "object",
218
- properties: {
219
- [fieldId]: {
220
- anyOf: [
221
- { const: "undefined" },
222
- { const: false },
223
- { const: null },
224
- { const: "" }
225
- ]
226
- }
227
- },
251
+ [fieldId]: {
228
252
  anyOf: [
229
- {
230
- required: [fieldId]
231
- },
232
- {
233
- not: {
234
- required: [fieldId]
235
- }
236
- }
253
+ { const: "undefined" },
254
+ { const: false },
255
+ { const: null },
256
+ { const: "" }
237
257
  ]
238
258
  }
239
259
  },
240
- required: ["$form"]
241
- }),
242
- isUndefined: () => defineConditional({
243
- type: "object",
244
- properties: {
245
- $form: {
246
- type: "object",
247
- properties: {
248
- [fieldId]: {
249
- type: "string",
250
- enum: ["undefined"]
251
- }
252
- },
260
+ anyOf: [
261
+ {
262
+ required: [fieldId]
263
+ },
264
+ {
253
265
  not: {
254
266
  required: [fieldId]
255
267
  }
256
268
  }
257
- },
258
- required: ["$form"]
269
+ ]
259
270
  }),
260
- inArray: (values) => defineConditional({
271
+ isUndefined: () => defineFormConditional({
261
272
  type: "object",
262
273
  properties: {
263
- $form: {
264
- type: "object",
265
- properties: {
266
- [fieldId]: {
267
- type: "string",
268
- enum: values
269
- }
270
- },
271
- required: [fieldId]
274
+ [fieldId]: {
275
+ type: "string",
276
+ enum: ["undefined"]
272
277
  }
273
278
  },
274
- required: ["$form"]
279
+ not: {
280
+ required: [fieldId]
281
+ }
275
282
  }),
276
- isValidEnglishName: () => defineConditional({
283
+ inArray: (values) => defineFormConditional({
277
284
  type: "object",
278
285
  properties: {
279
- $form: {
280
- type: "object",
281
- properties: {
282
- [fieldId]: {
283
- type: "string",
284
- 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'._-]*)*$",
285
- description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
286
- }
287
- },
288
- required: [fieldId]
286
+ [fieldId]: {
287
+ type: "string",
288
+ enum: values
289
289
  }
290
290
  },
291
- required: ["$form"]
291
+ required: [fieldId]
292
292
  }),
293
- isValidNationalId: () => defineConditional({
293
+ isValidEnglishName: () => defineFormConditional({
294
294
  type: "object",
295
295
  properties: {
296
- $form: {
297
- type: "object",
298
- properties: {
299
- [fieldId]: {
300
- type: "string",
301
- pattern: "^[0-9]{9}$",
302
- description: "The National ID can only be numeric and must be 9 digits long."
303
- }
304
- },
305
- required: [fieldId]
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."
306
300
  }
307
301
  },
308
- required: ["$form"]
302
+ required: [fieldId]
309
303
  }),
310
304
  /**
311
305
  * Checks if the field value matches a given regular expression pattern.
312
306
  * @param pattern - The regular expression pattern to match the field value against.
313
307
  * @returns A JSONSchema conditional that validates the field value against the pattern.
314
308
  */
315
- matches: (pattern) => defineConditional({
309
+ matches: (pattern) => defineFormConditional({
316
310
  type: "object",
317
311
  properties: {
318
- $form: {
319
- type: "object",
320
- properties: {
321
- [fieldId]: {
322
- type: "string",
323
- pattern
324
- }
325
- },
326
- required: [fieldId]
312
+ [fieldId]: {
313
+ type: "string",
314
+ pattern
327
315
  }
328
316
  },
329
- required: ["$form"]
317
+ required: [fieldId]
330
318
  }),
331
- isBetween: (min, max) => defineConditional({
319
+ isBetween: (min, max) => defineFormConditional({
332
320
  type: "object",
333
321
  properties: {
334
- $form: {
335
- type: "object",
336
- properties: {
337
- [fieldId]: {
338
- type: "number",
339
- minimum: min,
340
- maximum: max
341
- }
342
- },
343
- required: [fieldId]
322
+ [fieldId]: {
323
+ type: "number",
324
+ minimum: min,
325
+ maximum: max
344
326
  }
345
327
  },
346
- required: ["$form"]
347
- })
328
+ required: [fieldId]
329
+ }),
330
+ getId: () => ({ fieldId })
348
331
  };
349
332
  }