@opencrvs/toolkit 1.8.0-rc.ffe8c17 → 1.8.1-rc.0c972dc

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