@opencrvs/toolkit 1.8.0-rc.fe799b0 → 1.8.0-rc.fe7c504

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