@opencrvs/toolkit 1.8.0-rc.fd16d13 → 1.8.0-rc.fd1df48

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