@opencrvs/toolkit 1.8.0-rc.fca3e39 → 1.8.0-rc.fcb9386

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 (46) hide show
  1. package/README.md +1 -1
  2. package/dist/commons/api/router.d.ts +12639 -14167
  3. package/dist/commons/conditionals/conditionals.d.ts +32 -6
  4. package/dist/commons/conditionals/validate.d.ts +12 -17
  5. package/dist/commons/events/ActionConfig.d.ts +92869 -2005
  6. package/dist/commons/events/ActionDocument.d.ts +8019 -401
  7. package/dist/commons/events/ActionInput.d.ts +2365 -548
  8. package/dist/commons/events/ActionType.d.ts +26 -16
  9. package/dist/commons/events/AdvancedSearchConfig.d.ts +957 -22
  10. package/dist/commons/events/CompositeFieldValue.d.ts +3 -0
  11. package/dist/commons/events/Conditional.d.ts +21 -5
  12. package/dist/commons/events/Constants.d.ts +2 -0
  13. package/dist/commons/events/CountryConfigQueryInput.d.ts +2982 -0
  14. package/dist/commons/events/CreatedAtLocation.d.ts +3 -0
  15. package/dist/commons/events/Draft.d.ts +93 -60
  16. package/dist/commons/events/EventConfig.d.ts +42302 -1760
  17. package/dist/commons/events/EventConfigInput.d.ts +6 -3
  18. package/dist/commons/events/EventDocument.d.ts +1225 -529
  19. package/dist/commons/events/EventIndex.d.ts +1328 -13
  20. package/dist/commons/events/EventMetadata.d.ts +270 -11
  21. package/dist/commons/events/FieldConfig.d.ts +4704 -786
  22. package/dist/commons/events/FieldType.d.ts +4 -3
  23. package/dist/commons/events/FieldTypeMapping.d.ts +33 -5
  24. package/dist/commons/events/FieldValue.d.ts +12 -7
  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 +31 -2
  30. package/dist/commons/events/WorkqueueColumnConfig.d.ts +53 -0
  31. package/dist/commons/events/WorkqueueConfig.d.ts +4525 -20
  32. package/dist/commons/events/defineConfig.d.ts +6560 -223
  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 +9 -1
  36. package/dist/commons/events/scopes.d.ts +45 -0
  37. package/dist/commons/events/serializer.d.ts +2 -0
  38. package/dist/commons/events/test.utils.d.ts +93 -327
  39. package/dist/commons/events/utils.d.ts +3701 -96
  40. package/dist/commons/events/utils.test.d.ts +2 -0
  41. package/dist/commons/events/workqueueDefaultColumns.d.ts +3 -0
  42. package/dist/conditionals/index.js +210 -122
  43. package/dist/events/index.js +4464 -1981
  44. package/dist/scopes/index.d.ts +158 -1
  45. package/dist/scopes/index.js +152 -1
  46. package/package.json +3 -2
@@ -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,149 @@ 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 getDateFromNow(days) {
148
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
149
+ }
150
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
151
+ return {
85
152
  type: "object",
86
153
  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
- }
154
+ [fieldId]: {
155
+ type: "string",
156
+ format: "date",
157
+ [clause]: { $data: `1/${comparedFieldId}` }
158
+ },
159
+ [comparedFieldId]: { type: "string", format: "date" }
105
160
  },
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];
161
+ required: [fieldId]
162
+ };
163
+ }
164
+ function isFieldReference(value) {
165
+ return typeof value === "object" && value !== null && "_fieldId" in value;
166
+ }
167
+ function createFieldConditionals(fieldId) {
111
168
  const getDateRange = (date, clause) => ({
112
169
  type: "object",
113
170
  properties: {
114
- $form: {
115
- type: "object",
116
- properties: {
117
- [fieldId]: {
118
- type: "string",
119
- format: "date",
120
- [clause]: date
121
- }
122
- },
123
- required: [fieldId]
171
+ [fieldId]: {
172
+ type: "string",
173
+ format: "date",
174
+ [clause]: date
124
175
  }
125
176
  },
126
- required: ["$form"]
177
+ required: [fieldId]
127
178
  });
128
179
  return {
129
180
  isAfter: () => ({
130
181
  days: (days) => ({
131
- inPast: () => defineConditional(
182
+ inPast: () => defineFormConditional(
132
183
  getDateRange(getDateFromNow(days), "formatMinimum")
133
184
  ),
134
- inFuture: () => defineConditional(
185
+ inFuture: () => defineFormConditional(
135
186
  getDateRange(getDateFromNow(-days), "formatMinimum")
136
187
  )
137
188
  }),
138
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
139
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
189
+ date: (date) => {
190
+ if (isFieldReference(date)) {
191
+ const comparedFieldId = date._fieldId;
192
+ return defineFormConditional(
193
+ getDateRangeToFieldReference(
194
+ fieldId,
195
+ comparedFieldId,
196
+ "formatMinimum"
197
+ )
198
+ );
199
+ }
200
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
201
+ },
202
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
140
203
  }),
141
204
  isBefore: () => ({
142
205
  days: (days) => ({
143
- inPast: () => defineConditional(
206
+ inPast: () => defineFormConditional(
144
207
  getDateRange(getDateFromNow(days), "formatMaximum")
145
208
  ),
146
- inFuture: () => defineConditional(
209
+ inFuture: () => defineFormConditional(
147
210
  getDateRange(getDateFromNow(-days), "formatMaximum")
148
211
  )
149
212
  }),
150
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
151
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
213
+ date: (date) => {
214
+ if (isFieldReference(date)) {
215
+ const comparedFieldId = date._fieldId;
216
+ return defineFormConditional(
217
+ getDateRangeToFieldReference(
218
+ fieldId,
219
+ comparedFieldId,
220
+ "formatMaximum"
221
+ )
222
+ );
223
+ }
224
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
225
+ },
226
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
152
227
  }),
153
- isEqualTo: (value) => defineConditional({
154
- type: "object",
155
- properties: {
156
- $form: {
228
+ isEqualTo: (value) => {
229
+ if (isFieldReference(value)) {
230
+ const comparedFieldId = value._fieldId;
231
+ return defineFormConditional({
157
232
  type: "object",
158
233
  properties: {
159
234
  [fieldId]: {
160
- oneOf: [
161
- { type: "string", const: value },
162
- { type: "boolean", const: value }
163
- ],
164
- const: value
165
- }
235
+ type: ["string", "boolean"],
236
+ const: { $data: `1/${comparedFieldId}` }
237
+ },
238
+ [comparedFieldId]: { type: ["string", "boolean"] }
166
239
  },
167
- required: [fieldId]
168
- }
169
- },
170
- required: ["$form"]
171
- }),
240
+ required: [fieldId, comparedFieldId]
241
+ });
242
+ }
243
+ return defineFormConditional({
244
+ type: "object",
245
+ properties: {
246
+ [fieldId]: {
247
+ oneOf: [
248
+ { type: "string", const: value },
249
+ { type: "boolean", const: value }
250
+ ],
251
+ const: value
252
+ }
253
+ },
254
+ required: [fieldId]
255
+ });
256
+ },
172
257
  /**
173
258
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
174
259
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -177,85 +262,88 @@ function field(fieldId) {
177
262
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
178
263
  *
179
264
  */
180
- isFalsy: () => defineConditional({
265
+ isFalsy: () => defineFormConditional({
181
266
  type: "object",
182
267
  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
- },
268
+ [fieldId]: {
195
269
  anyOf: [
196
- {
197
- required: [fieldId]
198
- },
199
- {
200
- not: {
201
- required: [fieldId]
202
- }
203
- }
270
+ { const: "undefined" },
271
+ { const: false },
272
+ { const: null },
273
+ { const: "" }
204
274
  ]
205
275
  }
206
276
  },
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
- },
277
+ anyOf: [
278
+ {
279
+ required: [fieldId]
280
+ },
281
+ {
220
282
  not: {
221
283
  required: [fieldId]
222
284
  }
223
285
  }
286
+ ]
287
+ }),
288
+ isUndefined: () => defineFormConditional({
289
+ type: "object",
290
+ properties: {
291
+ [fieldId]: {
292
+ type: "string",
293
+ enum: ["undefined"]
294
+ }
224
295
  },
225
- required: ["$form"]
296
+ not: {
297
+ required: [fieldId]
298
+ }
226
299
  }),
227
- inArray: (values) => defineConditional({
300
+ inArray: (values) => defineFormConditional({
228
301
  type: "object",
229
302
  properties: {
230
- $form: {
231
- type: "object",
232
- properties: {
233
- [fieldId]: {
234
- type: "string",
235
- enum: values
236
- }
237
- },
238
- required: [fieldId]
303
+ [fieldId]: {
304
+ type: "string",
305
+ enum: values
239
306
  }
240
307
  },
241
- required: ["$form"]
308
+ required: [fieldId]
242
309
  }),
243
- isValidEnglishName: () => defineConditional({
310
+ isValidEnglishName: () => defineFormConditional({
244
311
  type: "object",
245
312
  properties: {
246
- $form: {
247
- type: "object",
248
- properties: {
249
- [fieldId]: {
250
- type: "string",
251
- 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'._-]*)*$",
252
- description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
253
- }
254
- },
255
- required: [fieldId]
313
+ [fieldId]: {
314
+ type: "string",
315
+ 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'._-]*)*$",
316
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
256
317
  }
257
318
  },
258
- required: ["$form"]
259
- })
319
+ required: [fieldId]
320
+ }),
321
+ /**
322
+ * Checks if the field value matches a given regular expression pattern.
323
+ * @param pattern - The regular expression pattern to match the field value against.
324
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
325
+ */
326
+ matches: (pattern) => defineFormConditional({
327
+ type: "object",
328
+ properties: {
329
+ [fieldId]: {
330
+ type: "string",
331
+ pattern
332
+ }
333
+ },
334
+ required: [fieldId]
335
+ }),
336
+ isBetween: (min, max) => defineFormConditional({
337
+ type: "object",
338
+ properties: {
339
+ [fieldId]: {
340
+ type: "number",
341
+ minimum: min,
342
+ maximum: max
343
+ }
344
+ },
345
+ required: [fieldId]
346
+ }),
347
+ getId: () => ({ fieldId })
260
348
  };
261
349
  }