@opencrvs/toolkit 1.8.0-rc.ffe8c17 → 1.8.1-rc.a372970

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 (33) hide show
  1. package/README.md +1 -1
  2. package/dist/commons/api/router.d.ts +6644 -9555
  3. package/dist/commons/conditionals/conditionals.d.ts +26 -3
  4. package/dist/commons/conditionals/validate-address.test.d.ts +2 -0
  5. package/dist/commons/conditionals/validate.d.ts +14 -17
  6. package/dist/commons/events/ActionConfig.d.ts +1008 -3209
  7. package/dist/commons/events/ActionDocument.d.ts +9488 -312
  8. package/dist/commons/events/ActionInput.d.ts +5329 -472
  9. package/dist/commons/events/ActionType.d.ts +26 -11
  10. package/dist/commons/events/CompositeFieldValue.d.ts +152 -2
  11. package/dist/commons/events/Conditional.d.ts +21 -5
  12. package/dist/commons/events/Draft.d.ts +351 -48
  13. package/dist/commons/events/EventConfig.d.ts +639 -2862
  14. package/dist/commons/events/EventConfigInput.d.ts +6 -3
  15. package/dist/commons/events/EventDocument.d.ts +3340 -424
  16. package/dist/commons/events/EventIndex.d.ts +6 -3
  17. package/dist/commons/events/EventMetadata.d.ts +3 -0
  18. package/dist/commons/events/FieldConfig.d.ts +383 -104
  19. package/dist/commons/events/FieldTypeMapping.d.ts +104 -207
  20. package/dist/commons/events/FieldValue.d.ts +71 -76
  21. package/dist/commons/events/FormConfig.d.ts +527 -279
  22. package/dist/commons/events/PageConfig.d.ts +335 -0
  23. package/dist/commons/events/TemplateConfig.d.ts +5 -5
  24. package/dist/commons/events/defineConfig.d.ts +40 -417
  25. package/dist/commons/events/index.d.ts +2 -1
  26. package/dist/commons/events/test.utils.d.ts +140 -213
  27. package/dist/commons/events/utils.d.ts +126 -156
  28. package/dist/commons/events/utils.test.d.ts +2 -0
  29. package/dist/conditionals/index.js +166 -81
  30. package/dist/events/index.js +1287 -795
  31. package/dist/scopes/index.d.ts +70 -1
  32. package/dist/scopes/index.js +130 -0
  33. package/package.json +1 -1
@@ -23,8 +23,10 @@ __export(conditionals_exports, {
23
23
  alwaysTrue: () => alwaysTrue,
24
24
  and: () => and,
25
25
  defineConditional: () => defineConditional,
26
+ defineFormConditional: () => defineFormConditional,
26
27
  event: () => event,
27
28
  field: () => field,
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",
@@ -106,69 +121,120 @@ var event = {
106
121
  required: ["$event"]
107
122
  })
108
123
  };
124
+ function getDateFromNow(days) {
125
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
126
+ }
127
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
128
+ return {
129
+ type: "object",
130
+ properties: {
131
+ [fieldId]: {
132
+ type: "string",
133
+ format: "date",
134
+ [clause]: { $data: `1/${comparedFieldId}` }
135
+ },
136
+ [comparedFieldId]: { type: "string", format: "date" }
137
+ },
138
+ required: [fieldId]
139
+ };
140
+ }
141
+ function isFieldReference(value) {
142
+ return typeof value === "object" && value !== null && "_fieldId" in value;
143
+ }
109
144
  function field(fieldId) {
110
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
111
145
  const getDateRange = (date, clause) => ({
112
146
  type: "object",
113
147
  properties: {
114
- $form: {
115
- type: "object",
116
- properties: {
117
- [fieldId]: {
118
- type: "string",
119
- format: "date",
120
- [clause]: date
121
- }
122
- },
123
- required: [fieldId]
148
+ [fieldId]: {
149
+ type: "string",
150
+ format: "date",
151
+ [clause]: date
124
152
  }
125
153
  },
126
- required: ["$form"]
154
+ required: [fieldId]
127
155
  });
128
156
  return {
157
+ /**
158
+ * @private Internal property used for field reference tracking.
159
+ */
160
+ _fieldId: fieldId,
129
161
  isAfter: () => ({
130
162
  days: (days) => ({
131
- inPast: () => defineConditional(
163
+ inPast: () => defineFormConditional(
132
164
  getDateRange(getDateFromNow(days), "formatMinimum")
133
165
  ),
134
- inFuture: () => defineConditional(
166
+ inFuture: () => defineFormConditional(
135
167
  getDateRange(getDateFromNow(-days), "formatMinimum")
136
168
  )
137
169
  }),
138
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
139
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
170
+ date: (date) => {
171
+ if (isFieldReference(date)) {
172
+ const comparedFieldId = date._fieldId;
173
+ return defineFormConditional(
174
+ getDateRangeToFieldReference(
175
+ fieldId,
176
+ comparedFieldId,
177
+ "formatMinimum"
178
+ )
179
+ );
180
+ }
181
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
182
+ },
183
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
140
184
  }),
141
185
  isBefore: () => ({
142
186
  days: (days) => ({
143
- inPast: () => defineConditional(
187
+ inPast: () => defineFormConditional(
144
188
  getDateRange(getDateFromNow(days), "formatMaximum")
145
189
  ),
146
- inFuture: () => defineConditional(
190
+ inFuture: () => defineFormConditional(
147
191
  getDateRange(getDateFromNow(-days), "formatMaximum")
148
192
  )
149
193
  }),
150
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
151
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
194
+ date: (date) => {
195
+ if (isFieldReference(date)) {
196
+ const comparedFieldId = date._fieldId;
197
+ return defineFormConditional(
198
+ getDateRangeToFieldReference(
199
+ fieldId,
200
+ comparedFieldId,
201
+ "formatMaximum"
202
+ )
203
+ );
204
+ }
205
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
206
+ },
207
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
152
208
  }),
153
- isEqualTo: (value) => defineConditional({
154
- type: "object",
155
- properties: {
156
- $form: {
209
+ isEqualTo: (value) => {
210
+ if (isFieldReference(value)) {
211
+ const comparedFieldId = value._fieldId;
212
+ return defineFormConditional({
157
213
  type: "object",
158
214
  properties: {
159
215
  [fieldId]: {
160
- oneOf: [
161
- { type: "string", const: value },
162
- { type: "boolean", const: value }
163
- ],
164
- const: value
165
- }
216
+ type: ["string", "boolean"],
217
+ const: { $data: `1/${comparedFieldId}` }
218
+ },
219
+ [comparedFieldId]: { type: ["string", "boolean"] }
166
220
  },
167
- required: [fieldId]
168
- }
169
- },
170
- required: ["$form"]
171
- }),
221
+ required: [fieldId, comparedFieldId]
222
+ });
223
+ }
224
+ return defineFormConditional({
225
+ type: "object",
226
+ properties: {
227
+ [fieldId]: {
228
+ oneOf: [
229
+ { type: "string", const: value },
230
+ { type: "boolean", const: value }
231
+ ],
232
+ const: value
233
+ }
234
+ },
235
+ required: [fieldId]
236
+ });
237
+ },
172
238
  /**
173
239
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
174
240
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -177,68 +243,87 @@ function field(fieldId) {
177
243
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
178
244
  *
179
245
  */
180
- isFalsy: () => defineConditional({
246
+ isFalsy: () => defineFormConditional({
181
247
  type: "object",
182
248
  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
- },
249
+ [fieldId]: {
195
250
  anyOf: [
196
- {
197
- required: [fieldId]
198
- },
199
- {
200
- not: {
201
- required: [fieldId]
202
- }
203
- }
251
+ { const: "undefined" },
252
+ { const: false },
253
+ { const: null },
254
+ { const: "" }
204
255
  ]
205
256
  }
206
257
  },
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
- },
258
+ anyOf: [
259
+ {
260
+ required: [fieldId]
261
+ },
262
+ {
220
263
  not: {
221
264
  required: [fieldId]
222
265
  }
223
266
  }
267
+ ]
268
+ }),
269
+ isUndefined: () => defineFormConditional({
270
+ type: "object",
271
+ properties: {
272
+ [fieldId]: {
273
+ type: "string",
274
+ enum: ["undefined"]
275
+ }
224
276
  },
225
- required: ["$form"]
277
+ not: {
278
+ required: [fieldId]
279
+ }
226
280
  }),
227
- inArray: (values) => defineConditional({
281
+ inArray: (values) => defineFormConditional({
228
282
  type: "object",
229
283
  properties: {
230
- $form: {
231
- type: "object",
232
- properties: {
233
- [fieldId]: {
234
- type: "string",
235
- enum: values
236
- }
237
- },
238
- required: [fieldId]
284
+ [fieldId]: {
285
+ type: "string",
286
+ enum: values
287
+ }
288
+ },
289
+ required: [fieldId]
290
+ }),
291
+ isValidEnglishName: () => defineFormConditional({
292
+ type: "object",
293
+ properties: {
294
+ [fieldId]: {
295
+ type: "string",
296
+ 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'._-]*)*$",
297
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
298
+ }
299
+ },
300
+ required: [fieldId]
301
+ }),
302
+ /**
303
+ * Checks if the field value matches a given regular expression pattern.
304
+ * @param pattern - The regular expression pattern to match the field value against.
305
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
306
+ */
307
+ matches: (pattern) => defineFormConditional({
308
+ type: "object",
309
+ properties: {
310
+ [fieldId]: {
311
+ type: "string",
312
+ pattern
313
+ }
314
+ },
315
+ required: [fieldId]
316
+ }),
317
+ isBetween: (min, max) => defineFormConditional({
318
+ type: "object",
319
+ properties: {
320
+ [fieldId]: {
321
+ type: "number",
322
+ minimum: min,
323
+ maximum: max
239
324
  }
240
325
  },
241
- required: ["$form"]
326
+ required: [fieldId]
242
327
  })
243
328
  };
244
329
  }