@opencrvs/toolkit 1.8.0-rc.f988087 → 1.8.0-rc.f9b51fa

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 (35) hide show
  1. package/README.md +1 -1
  2. package/dist/commons/api/router.d.ts +6687 -9364
  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 +41 -17
  6. package/dist/commons/conditionals/validate.test.d.ts +2 -0
  7. package/dist/commons/events/ActionConfig.d.ts +1116 -2067
  8. package/dist/commons/events/ActionDocument.d.ts +9488 -312
  9. package/dist/commons/events/ActionInput.d.ts +5331 -558
  10. package/dist/commons/events/ActionType.d.ts +27 -12
  11. package/dist/commons/events/CompositeFieldValue.d.ts +152 -2
  12. package/dist/commons/events/Conditional.d.ts +21 -5
  13. package/dist/commons/events/Draft.d.ts +351 -51
  14. package/dist/commons/events/EventConfig.d.ts +559 -1238
  15. package/dist/commons/events/EventConfigInput.d.ts +6 -3
  16. package/dist/commons/events/EventDocument.d.ts +3345 -429
  17. package/dist/commons/events/EventIndex.d.ts +6 -3
  18. package/dist/commons/events/EventMetadata.d.ts +3 -0
  19. package/dist/commons/events/FieldConfig.d.ts +527 -74
  20. package/dist/commons/events/FieldType.d.ts +6 -1
  21. package/dist/commons/events/FieldTypeMapping.d.ts +154 -3
  22. package/dist/commons/events/FieldValue.d.ts +76 -2
  23. package/dist/commons/events/FormConfig.d.ts +633 -48
  24. package/dist/commons/events/PageConfig.d.ts +335 -0
  25. package/dist/commons/events/TemplateConfig.d.ts +38 -0
  26. package/dist/commons/events/defineConfig.d.ts +91 -222
  27. package/dist/commons/events/index.d.ts +3 -1
  28. package/dist/commons/events/test.utils.d.ts +141 -214
  29. package/dist/commons/events/utils.d.ts +196 -69
  30. package/dist/commons/events/utils.test.d.ts +2 -0
  31. package/dist/conditionals/index.js +166 -81
  32. package/dist/events/index.js +1524 -817
  33. package/dist/scopes/index.d.ts +70 -1
  34. package/dist/scopes/index.js +130 -0
  35. package/package.json +1 -1
@@ -30,19 +30,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/events/index.ts
31
31
  var events_exports = {};
32
32
  __export(events_exports, {
33
+ Action: () => Action,
33
34
  ActionBase: () => ActionBase,
34
35
  ActionConditional: () => ActionConditional,
35
36
  ActionConfig: () => ActionConfig,
36
37
  ActionConfigBase: () => ActionConfigBase,
37
38
  ActionDocument: () => ActionDocument,
39
+ ActionFormConfig: () => ActionFormConfig,
38
40
  ActionInput: () => ActionInput,
41
+ ActionStatus: () => ActionStatus,
39
42
  ActionType: () => ActionType,
43
+ ActionTypes: () => ActionTypes,
40
44
  ActionUpdate: () => ActionUpdate,
41
45
  AddressFieldUpdateValue: () => AddressFieldUpdateValue,
42
46
  AddressFieldValue: () => AddressFieldValue,
47
+ AddressType: () => AddressType,
48
+ AdministrativeAreas: () => AdministrativeAreas,
43
49
  AdvancedSearchConfig: () => AdvancedSearchConfig,
44
50
  ApproveCorrectionActionInput: () => ApproveCorrectionActionInput,
45
- ArchivedActionInput: () => ArchivedActionInput,
51
+ ArchiveActionInput: () => ArchiveActionInput,
52
+ AssignActionInput: () => AssignActionInput,
53
+ AsyncRejectActionDocument: () => AsyncRejectActionDocument,
46
54
  BaseActionInput: () => BaseActionInput,
47
55
  CertificateConfig: () => CertificateConfig,
48
56
  CertificateTemplateConfig: () => CertificateTemplateConfig,
@@ -50,9 +58,18 @@ __export(events_exports, {
50
58
  Clause: () => Clause,
51
59
  Conditional: () => Conditional,
52
60
  ConditionalType: () => ConditionalType,
61
+ ConfirmableActions: () => ConfirmableActions,
62
+ DataEntry: () => DataEntry,
63
+ DataFieldValue: () => DataFieldValue,
53
64
  DateValue: () => DateValue,
65
+ DeclarationActionConfig: () => DeclarationActionConfig,
66
+ DeclarationActions: () => DeclarationActions,
67
+ DeclarationFormConfig: () => DeclarationFormConfig,
68
+ DeclarationReviewConfig: () => DeclarationReviewConfig,
69
+ DeclarationUpdateActions: () => DeclarationUpdateActions,
54
70
  DeclareActionInput: () => DeclareActionInput,
55
71
  DeduplicationConfig: () => DeduplicationConfig,
72
+ DisplayOnReviewConditional: () => DisplayOnReviewConditional,
56
73
  Draft: () => Draft,
57
74
  DraftInput: () => DraftInput,
58
75
  EmailField: () => EmailField,
@@ -66,6 +83,7 @@ __export(events_exports, {
66
83
  EventSearchIndex: () => EventSearchIndex,
67
84
  EventStatus: () => EventStatus,
68
85
  EventStatuses: () => EventStatuses,
86
+ FieldConditional: () => FieldConditional,
69
87
  FieldConfig: () => FieldConfig,
70
88
  FieldType: () => FieldType,
71
89
  FieldUpdateValue: () => FieldUpdateValue,
@@ -74,13 +92,21 @@ __export(events_exports, {
74
92
  FileFieldValueWithOption: () => FileFieldValueWithOption,
75
93
  FileFieldWithOptionValue: () => FileFieldWithOptionValue,
76
94
  FormConfig: () => FormConfig,
77
- FormPage: () => FormPage,
95
+ FormPageConfig: () => FormPageConfig,
96
+ GenericAddressUpdateValue: () => GenericAddressUpdateValue,
97
+ GenericAddressValue: () => GenericAddressValue,
78
98
  GeographicalArea: () => GeographicalArea,
99
+ ImageMimeType: () => ImageMimeType,
79
100
  LanguageConfig: () => LanguageConfig,
80
101
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
102
+ MimeType: () => MimeType,
81
103
  NotifyActionInput: () => NotifyActionInput,
82
104
  NumberFieldValue: () => NumberFieldValue,
105
+ PageConfig: () => PageConfig,
106
+ PageTypes: () => PageTypes,
83
107
  PrintCertificateActionInput: () => PrintCertificateActionInput,
108
+ ReadActionInput: () => ReadActionInput,
109
+ RegisterAction: () => RegisterAction,
84
110
  RegisterActionInput: () => RegisterActionInput,
85
111
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
86
112
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
@@ -93,19 +119,30 @@ __export(events_exports, {
93
119
  SummaryConfig: () => SummaryConfig,
94
120
  TextValue: () => TextValue,
95
121
  TranslationConfig: () => TranslationConfig,
122
+ UnassignActionInput: () => UnassignActionInput,
96
123
  UrbanAddressUpdateValue: () => UrbanAddressUpdateValue,
97
124
  UrbanAddressValue: () => UrbanAddressValue,
98
125
  ValidateActionInput: () => ValidateActionInput,
126
+ VerificationActionConfig: () => VerificationActionConfig,
127
+ VerificationPageConfig: () => VerificationPageConfig,
99
128
  WorkqueueConfig: () => WorkqueueConfig,
100
129
  alwaysTrue: () => alwaysTrue,
101
130
  and: () => and,
131
+ annotationActions: () => annotationActions,
102
132
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
133
+ compositeFieldTypes: () => compositeFieldTypes,
134
+ createEmptyDraft: () => createEmptyDraft,
103
135
  createValidationSchema: () => createValidationSchema,
104
136
  deepDropNulls: () => deepDropNulls,
137
+ deepMerge: () => deepMerge,
138
+ defineActionForm: () => defineActionForm,
105
139
  defineConditional: () => defineConditional,
106
140
  defineConfig: () => defineConfig,
107
- defineForm: () => defineForm,
141
+ defineDeclarationForm: () => defineDeclarationForm,
142
+ defineFormConditional: () => defineFormConditional,
108
143
  defineFormPage: () => defineFormPage,
144
+ definePage: () => definePage,
145
+ errorMessages: () => errorMessages,
109
146
  event: () => event,
110
147
  eventMetadataLabelMap: () => eventMetadataLabelMap,
111
148
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -113,36 +150,45 @@ __export(events_exports, {
113
150
  eventStatuses: () => eventStatuses,
114
151
  field: () => field,
115
152
  fieldTypes: () => fieldTypes,
116
- findActiveActionFields: () => findActiveActionFields,
117
- findActiveActionForm: () => findActiveActionForm,
118
- findActiveActionFormFields: () => findActiveActionFormFields,
119
- findActiveActionFormPages: () => findActiveActionFormPages,
120
- findInputPageFields: () => findInputPageFields,
121
- findPageFields: () => findPageFields,
153
+ findActiveDrafts: () => findActiveDrafts,
154
+ findAllFields: () => findAllFields,
155
+ findLastAssignmentAction: () => findLastAssignmentAction,
156
+ findRecordActionPages: () => findRecordActionPages,
157
+ generateActionAnnotationInput: () => generateActionAnnotationInput,
158
+ generateActionDeclarationInput: () => generateActionDeclarationInput,
122
159
  generateActionDocument: () => generateActionDocument,
123
- generateActionInput: () => generateActionInput,
124
160
  generateEventDocument: () => generateEventDocument,
125
161
  generateEventDraftDocument: () => generateEventDraftDocument,
126
162
  generateTransactionId: () => generateTransactionId,
127
- getActiveActionFields: () => getActiveActionFields,
128
- getAllFields: () => getAllFields,
129
- getAllPages: () => getAllPages,
163
+ generateTranslationConfig: () => generateTranslationConfig,
164
+ getAcceptedActions: () => getAcceptedActions,
165
+ getActionAnnotation: () => getActionAnnotation,
166
+ getActionAnnotationFields: () => getActionAnnotationFields,
167
+ getActionReview: () => getActionReview,
168
+ getActionReviewFields: () => getActionReviewFields,
169
+ getAllAnnotationFields: () => getAllAnnotationFields,
170
+ getAnnotationFromDrafts: () => getAnnotationFromDrafts,
130
171
  getCurrentEventState: () => getCurrentEventState,
131
172
  getCurrentEventStateWithDrafts: () => getCurrentEventStateWithDrafts,
132
- getEventConfiguration: () => getEventConfiguration,
173
+ getDeclaration: () => getDeclaration,
174
+ getDeclarationFields: () => getDeclarationFields,
175
+ getDeclarationPages: () => getDeclarationPages,
133
176
  getFieldValidationErrors: () => getFieldValidationErrors,
134
- getFormFields: () => getFormFields,
135
- getMetadataForAction: () => getMetadataForAction,
136
177
  isAddressFieldType: () => isAddressFieldType,
137
178
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
138
179
  isBulletListFieldType: () => isBulletListFieldType,
139
180
  isCheckboxFieldType: () => isCheckboxFieldType,
140
181
  isCountryFieldType: () => isCountryFieldType,
182
+ isDataFieldType: () => isDataFieldType,
141
183
  isDateFieldType: () => isDateFieldType,
142
184
  isDividerFieldType: () => isDividerFieldType,
143
185
  isEmailFieldType: () => isEmailFieldType,
144
186
  isFacilityFieldType: () => isFacilityFieldType,
187
+ isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
188
+ isFieldDisplayedOnReview: () => isFieldDisplayedOnReview,
145
189
  isFieldEnabled: () => isFieldEnabled,
190
+ isFieldValue: () => isFieldValue,
191
+ isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
146
192
  isFieldVisible: () => isFieldVisible,
147
193
  isFileFieldType: () => isFileFieldType,
148
194
  isFileFieldWithOptionType: () => isFileFieldWithOptionType,
@@ -150,56 +196,80 @@ __export(events_exports, {
150
196
  isNumberFieldType: () => isNumberFieldType,
151
197
  isOfficeFieldType: () => isOfficeFieldType,
152
198
  isPageHeaderFieldType: () => isPageHeaderFieldType,
199
+ isPageVisible: () => isPageVisible,
153
200
  isParagraphFieldType: () => isParagraphFieldType,
154
201
  isRadioGroupFieldType: () => isRadioGroupFieldType,
155
202
  isSelectFieldType: () => isSelectFieldType,
156
203
  isSignatureFieldType: () => isSignatureFieldType,
204
+ isTemplateVariable: () => isTemplateVariable,
157
205
  isTextAreaFieldType: () => isTextAreaFieldType,
158
206
  isTextFieldType: () => isTextFieldType,
159
207
  isUndeclaredDraft: () => isUndeclaredDraft,
208
+ isVerificationPage: () => isVerificationPage,
209
+ isWriteAction: () => isWriteAction,
210
+ mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
160
211
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
161
212
  mapFieldTypeToZod: () => mapFieldTypeToZod,
213
+ never: () => never,
162
214
  not: () => not,
215
+ omitHiddenFields: () => omitHiddenFields,
216
+ omitHiddenPaginatedFields: () => omitHiddenPaginatedFields,
163
217
  or: () => or,
164
- resolveLabelsFromKnownFields: () => resolveLabelsFromKnownFields,
165
- stripHiddenFields: () => stripHiddenFields,
166
218
  user: () => user,
167
219
  validate: () => validate,
168
220
  validateFieldInput: () => validateFieldInput,
169
- validateWorkqueueConfig: () => validateWorkqueueConfig
221
+ validateWorkqueueConfig: () => validateWorkqueueConfig,
222
+ writeActions: () => writeActions
170
223
  });
171
224
  module.exports = __toCommonJS(events_exports);
172
225
 
173
226
  // ../commons/src/events/ActionConfig.ts
174
- var import_zod7 = require("zod");
227
+ var import_zod9 = require("zod");
175
228
 
176
229
  // ../commons/src/events/Conditional.ts
177
230
  var import_zod = require("zod");
178
- function Conditional() {
179
- return import_zod.z.custom((val) => typeof val === "object" && val !== null);
180
- }
231
+ var Conditional = import_zod.z.custom(
232
+ (val) => typeof val === "object" && val !== null
233
+ );
181
234
  var ConditionalType = {
182
- /** When 'SHOW' conditional is defined, the action is shown to the user only if the condition is met */
183
235
  SHOW: "SHOW",
184
- /** If 'ENABLE' conditional is defined, the action is enabled only if the condition is met */
185
- ENABLE: "ENABLE"
236
+ ENABLE: "ENABLE",
237
+ DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
186
238
  };
187
239
  var ShowConditional = import_zod.z.object({
188
240
  type: import_zod.z.literal(ConditionalType.SHOW),
189
- conditional: Conditional()
190
- });
241
+ conditional: Conditional
242
+ }).describe(
243
+ "If 'SHOW' conditional is defined, the component is shown to the user only if the condition is met"
244
+ );
191
245
  var EnableConditional = import_zod.z.object({
192
246
  type: import_zod.z.literal(ConditionalType.ENABLE),
193
- conditional: Conditional()
194
- });
247
+ conditional: Conditional
248
+ }).describe(
249
+ "If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
250
+ );
195
251
  var ActionConditional = import_zod.z.discriminatedUnion("type", [
196
252
  // Action can be shown / hidden
197
253
  ShowConditional,
198
254
  // Action can be shown to the user in the list but as disabled
199
255
  EnableConditional
200
256
  ]);
257
+ var DisplayOnReviewConditional = import_zod.z.object({
258
+ type: import_zod.z.literal(ConditionalType.DISPLAY_ON_REVIEW),
259
+ conditional: Conditional
260
+ }).describe(
261
+ "If 'DISPLAY_ON_REVIEW' conditional is defined, the component is shown on the review page only if both the 'DISPLAY_ON_REVIEW' and 'SHOW' conditions are met. This should only be used for fields within declaration forms, as they are the only ones with review pages."
262
+ );
263
+ var FieldConditional = import_zod.z.discriminatedUnion("type", [
264
+ // Field input can be shown / hidden
265
+ ShowConditional,
266
+ // Field input can be shown to the user but as disabled
267
+ EnableConditional,
268
+ // Field output can be shown / hidden on the review page
269
+ DisplayOnReviewConditional
270
+ ]);
201
271
 
202
- // ../commons/src/events/FormConfig.ts
272
+ // ../commons/src/events/PageConfig.ts
203
273
  var import_zod6 = require("zod");
204
274
 
205
275
  // ../commons/src/events/FieldConfig.ts
@@ -240,9 +310,15 @@ var FieldType = {
240
310
  ADMINISTRATIVE_AREA: "ADMINISTRATIVE_AREA",
241
311
  FACILITY: "FACILITY",
242
312
  OFFICE: "OFFICE",
243
- SIGNATURE: "SIGNATURE"
313
+ SIGNATURE: "SIGNATURE",
314
+ DATA: "DATA"
244
315
  };
245
316
  var fieldTypes = Object.values(FieldType);
317
+ var compositeFieldTypes = [
318
+ FieldType.ADDRESS,
319
+ FieldType.FILE_WITH_OPTIONS,
320
+ FieldType.FILE
321
+ ];
246
322
 
247
323
  // ../commons/src/events/FieldValue.ts
248
324
  var import_zod4 = require("zod");
@@ -253,6 +329,10 @@ var GeographicalArea = {
253
329
  URBAN: "URBAN",
254
330
  RURAL: "RURAL"
255
331
  };
332
+ var AddressType = {
333
+ DOMESTIC: "DOMESTIC",
334
+ INTERNATIONAL: "INTERNATIONAL"
335
+ };
256
336
  var FileFieldValue = import_zod3.z.object({
257
337
  filename: import_zod3.z.string(),
258
338
  originalFilename: import_zod3.z.string(),
@@ -260,6 +340,7 @@ var FileFieldValue = import_zod3.z.object({
260
340
  });
261
341
  var AdminStructure = import_zod3.z.object({
262
342
  country: import_zod3.z.string(),
343
+ addressType: import_zod3.z.literal(AddressType.DOMESTIC),
263
344
  province: import_zod3.z.string(),
264
345
  district: import_zod3.z.string()
265
346
  });
@@ -287,14 +368,33 @@ var RuralAddressUpdateValue = AdminStructure.extend({
287
368
  urbanOrRural: import_zod3.z.literal(GeographicalArea.RURAL),
288
369
  village: import_zod3.z.string().nullish()
289
370
  });
290
- var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
291
- UrbanAddressValue,
292
- RuralAddressValue
293
- ]);
371
+ var GenericAddressValue = import_zod3.z.object({
372
+ country: import_zod3.z.string(),
373
+ addressType: import_zod3.z.literal(AddressType.INTERNATIONAL),
374
+ state: import_zod3.z.string(),
375
+ district2: import_zod3.z.string(),
376
+ cityOrTown: import_zod3.z.string().optional(),
377
+ addressLine1: import_zod3.z.string().optional(),
378
+ addressLine2: import_zod3.z.string().optional(),
379
+ addressLine3: import_zod3.z.string().optional(),
380
+ postcodeOrZip: import_zod3.z.string().optional()
381
+ });
382
+ var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [UrbanAddressValue, RuralAddressValue]).or(GenericAddressValue);
383
+ var GenericAddressUpdateValue = import_zod3.z.object({
384
+ country: import_zod3.z.string(),
385
+ addressType: import_zod3.z.literal(AddressType.INTERNATIONAL),
386
+ state: import_zod3.z.string(),
387
+ district2: import_zod3.z.string(),
388
+ cityOrTown: import_zod3.z.string().nullish(),
389
+ addressLine1: import_zod3.z.string().nullish(),
390
+ addressLine2: import_zod3.z.string().nullish(),
391
+ addressLine3: import_zod3.z.string().nullish(),
392
+ postcodeOrZip: import_zod3.z.string().nullish()
393
+ });
294
394
  var AddressFieldUpdateValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
295
395
  UrbanAddressUpdateValue,
296
396
  RuralAddressUpdateValue
297
- ]);
397
+ ]).or(GenericAddressUpdateValue);
298
398
  var FileFieldValueWithOption = import_zod3.z.object({
299
399
  filename: import_zod3.z.string(),
300
400
  originalFilename: import_zod3.z.string(),
@@ -310,6 +410,7 @@ var DateValue = import_zod4.z.string().date().describe("Date in the format YYYY-
310
410
  var EmailValue = import_zod4.z.string().email();
311
411
  var CheckboxFieldValue = import_zod4.z.boolean();
312
412
  var NumberFieldValue = import_zod4.z.number();
413
+ var DataFieldValue = import_zod4.z.undefined();
313
414
  var FieldValue = import_zod4.z.union([
314
415
  TextValue,
315
416
  DateValue,
@@ -318,7 +419,9 @@ var FieldValue = import_zod4.z.union([
318
419
  FileFieldValue,
319
420
  FileFieldWithOptionValue,
320
421
  UrbanAddressValue,
321
- RuralAddressValue
422
+ RuralAddressValue,
423
+ DataFieldValue,
424
+ GenericAddressValue
322
425
  ]);
323
426
  var FieldUpdateValue = import_zod4.z.union([
324
427
  TextValue,
@@ -328,7 +431,9 @@ var FieldUpdateValue = import_zod4.z.union([
328
431
  FileFieldValue,
329
432
  FileFieldWithOptionValue,
330
433
  UrbanAddressUpdateValue,
331
- RuralAddressUpdateValue
434
+ RuralAddressUpdateValue,
435
+ DataFieldValue,
436
+ GenericAddressUpdateValue
332
437
  ]);
333
438
 
334
439
  // ../commons/src/events/FieldConfig.ts
@@ -350,14 +455,14 @@ var BaseField = import_zod5.z.object({
350
455
  ]),
351
456
  DependencyExpression
352
457
  ]).optional(),
353
- conditionals: import_zod5.z.array(ActionConditional).default([]).optional(),
458
+ conditionals: import_zod5.z.array(FieldConditional).default([]).optional(),
354
459
  required: import_zod5.z.boolean().default(false).optional(),
355
460
  disabled: import_zod5.z.boolean().default(false).optional(),
356
461
  hidden: import_zod5.z.boolean().default(false).optional(),
357
462
  placeholder: TranslationConfig.optional(),
358
463
  validation: import_zod5.z.array(
359
464
  import_zod5.z.object({
360
- validator: Conditional(),
465
+ validator: Conditional,
361
466
  message: TranslationConfig
362
467
  })
363
468
  ).default([]).optional(),
@@ -399,15 +504,25 @@ var TextAreaField = BaseField.extend({
399
504
  postfix: TranslationConfig.optional()
400
505
  }).default({ rows: 4 }).optional()
401
506
  }).describe("Multiline text input");
507
+ var ImageMimeType = import_zod5.z.enum([
508
+ "image/png",
509
+ "image/jpg",
510
+ "image/jpeg",
511
+ "image/svg+xml"
512
+ ]);
513
+ var MimeType = ImageMimeType;
514
+ var DEFAULT_MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
402
515
  var SignatureField = BaseField.extend({
403
516
  type: import_zod5.z.literal(FieldType.SIGNATURE),
404
517
  signaturePromptLabel: TranslationConfig.describe(
405
518
  "Title of the signature modal"
406
519
  ),
407
520
  configuration: import_zod5.z.object({
408
- maxSizeMb: import_zod5.z.number().optional().describe("Maximum file size in MB"),
409
- allowedFileFormats: import_zod5.z.array(import_zod5.z.string()).optional().describe("List of allowed file formats for the signature")
410
- }).default({}).optional()
521
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
522
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
523
+ }).default({
524
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
525
+ })
411
526
  }).describe("Signature input field");
412
527
  var EmailField = BaseField.extend({
413
528
  type: import_zod5.z.literal(FieldType.EMAIL),
@@ -450,13 +565,17 @@ var PageHeader = BaseField.extend({
450
565
  }).describe("A read-only header component for form pages");
451
566
  var File = BaseField.extend({
452
567
  type: import_zod5.z.literal(FieldType.FILE),
453
- options: import_zod5.z.object({
568
+ configuration: import_zod5.z.object({
569
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
570
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
454
571
  style: import_zod5.z.object({
455
- fullWidth: import_zod5.z.boolean().describe(
572
+ width: import_zod5.z.enum(["full", "auto"]).optional().describe(
456
573
  "Whether the file upload button should take the full width of the container or not"
457
574
  )
458
- })
459
- }).optional()
575
+ }).optional()
576
+ }).default({
577
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
578
+ })
460
579
  }).describe("File upload");
461
580
  var SelectOption = import_zod5.z.object({
462
581
  value: import_zod5.z.string().describe("The value of the option"),
@@ -495,11 +614,16 @@ var Country = BaseField.extend({
495
614
  type: import_zod5.z.literal(FieldType.COUNTRY),
496
615
  defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
497
616
  }).describe("Country select field");
617
+ var AdministrativeAreas = import_zod5.z.enum([
618
+ "ADMIN_STRUCTURE",
619
+ "HEALTH_FACILITY",
620
+ "CRVS_OFFICE"
621
+ ]);
498
622
  var AdministrativeAreaConfiguration = import_zod5.z.object({
499
623
  partOf: import_zod5.z.object({
500
- $data: import_zod5.z.string()
624
+ $declaration: import_zod5.z.string()
501
625
  }).optional().describe("Parent location"),
502
- type: import_zod5.z.enum(["ADMIN_STRUCTURE", "HEALTH_FACILITY", "CRVS_OFFICE"])
626
+ type: AdministrativeAreas
503
627
  }).describe("Administrative area options");
504
628
  var AdministrativeArea = BaseField.extend({
505
629
  type: import_zod5.z.literal(FieldType.ADMINISTRATIVE_AREA),
@@ -512,8 +636,14 @@ var Location = BaseField.extend({
512
636
  }).describe("Input field for a location");
513
637
  var FileUploadWithOptions = BaseField.extend({
514
638
  type: import_zod5.z.literal(FieldType.FILE_WITH_OPTIONS),
515
- options: import_zod5.z.array(SelectOption).describe("A list of options")
516
- }).describe("Select input");
639
+ options: import_zod5.z.array(SelectOption).describe("A list of options"),
640
+ configuration: import_zod5.z.object({
641
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
642
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
643
+ }).default({
644
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
645
+ })
646
+ });
517
647
  var Facility = BaseField.extend({
518
648
  type: import_zod5.z.literal(FieldType.FACILITY),
519
649
  defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
@@ -526,6 +656,22 @@ var Address = BaseField.extend({
526
656
  type: import_zod5.z.literal(FieldType.ADDRESS),
527
657
  defaultValue: AddressFieldValue.optional()
528
658
  }).describe("Address input field \u2013 a combination of location and text fields");
659
+ var DataEntry = import_zod5.z.union([
660
+ import_zod5.z.object({
661
+ label: TranslationConfig,
662
+ value: import_zod5.z.string()
663
+ }),
664
+ import_zod5.z.object({
665
+ fieldId: import_zod5.z.string()
666
+ })
667
+ ]);
668
+ var DataField = BaseField.extend({
669
+ type: import_zod5.z.literal(FieldType.DATA),
670
+ configuration: import_zod5.z.object({
671
+ subtitle: TranslationConfig.optional(),
672
+ data: import_zod5.z.array(DataEntry)
673
+ })
674
+ }).describe("Data field for displaying read-only data");
529
675
  var FieldConfig = import_zod5.z.discriminatedUnion("type", [
530
676
  Address,
531
677
  TextField,
@@ -547,244 +693,322 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
547
693
  Office,
548
694
  SignatureField,
549
695
  EmailField,
550
- FileUploadWithOptions
696
+ FileUploadWithOptions,
697
+ DataField
698
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
551
699
  ]);
552
700
 
553
- // ../commons/src/events/FormConfig.ts
554
- var FormPage = import_zod6.z.object({
701
+ // ../commons/src/events/PageConfig.ts
702
+ var PageTypes = import_zod6.z.enum(["FORM", "VERIFICATION"]);
703
+ var PageConfigBase = import_zod6.z.object({
555
704
  id: import_zod6.z.string().describe("Unique identifier for the page"),
556
705
  title: TranslationConfig.describe("Header title of the page"),
557
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page")
706
+ fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page"),
707
+ conditional: Conditional.optional().describe(
708
+ "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
709
+ )
558
710
  });
559
- var FormConfig = import_zod6.z.object({
560
- label: TranslationConfig.describe("Human readable description of the form"),
561
- version: import_zod6.z.object({
562
- id: import_zod6.z.string().describe(
563
- "Form version. Semantic versioning recommended. Example: 0.0.1"
564
- ),
565
- label: TranslationConfig.describe(
566
- "Human readable description of the version"
567
- )
568
- }),
569
- active: import_zod6.z.boolean().default(false).describe("Whether the form is active"),
570
- pages: import_zod6.z.array(FormPage),
571
- review: import_zod6.z.object({
572
- title: TranslationConfig.describe(
573
- "Title of the form to show in review page"
574
- ),
575
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the review page for metadata")
711
+ var FormPageConfig = PageConfigBase.extend({
712
+ type: import_zod6.z.literal(PageTypes.enum.FORM).default(PageTypes.enum.FORM)
713
+ });
714
+ var VerificationActionConfig = import_zod6.z.object({
715
+ verify: import_zod6.z.object({ label: TranslationConfig }),
716
+ cancel: import_zod6.z.object({
717
+ label: TranslationConfig,
718
+ confirmation: import_zod6.z.object({
719
+ title: TranslationConfig,
720
+ body: TranslationConfig
721
+ })
576
722
  })
723
+ }).describe("Actions available on the verification page");
724
+ var VerificationPageConfig = FormPageConfig.extend({
725
+ type: import_zod6.z.literal(PageTypes.enum.VERIFICATION),
726
+ actions: VerificationActionConfig
577
727
  });
728
+ var PageConfig = import_zod6.z.discriminatedUnion("type", [
729
+ FormPageConfig,
730
+ VerificationPageConfig
731
+ ]);
578
732
 
579
733
  // ../commons/src/events/ActionType.ts
734
+ var import_zod7 = require("zod");
580
735
  var ActionType = {
736
+ // Pre-declaration actions
737
+ DELETE: "DELETE",
581
738
  CREATE: "CREATE",
582
- ASSIGN: "ASSIGN",
583
- UNASSIGN: "UNASSIGN",
584
- REGISTER: "REGISTER",
585
- VALIDATE: "VALIDATE",
586
- REQUEST_CORRECTION: "REQUEST_CORRECTION",
587
- REJECT_CORRECTION: "REJECT_CORRECTION",
588
- APPROVE_CORRECTION: "APPROVE_CORRECTION",
589
- DETECT_DUPLICATE: "DETECT_DUPLICATE",
590
739
  NOTIFY: "NOTIFY",
740
+ // Declaration actions
591
741
  DECLARE: "DECLARE",
592
- DELETE: "DELETE",
593
- PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
594
- CUSTOM: "CUSTOM",
742
+ VALIDATE: "VALIDATE",
743
+ REGISTER: "REGISTER",
744
+ // Declaration system actions. Non-configurable.
745
+ DETECT_DUPLICATE: "DETECT_DUPLICATE",
595
746
  REJECT: "REJECT",
747
+ // REJECT_DECLARATION
596
748
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
597
- ARCHIVED: "ARCHIVED"
749
+ // MARK_AS_DUPLICATE
750
+ ARCHIVE: "ARCHIVE",
751
+ // Record actions
752
+ PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
753
+ REQUEST_CORRECTION: "REQUEST_CORRECTION",
754
+ REJECT_CORRECTION: "REJECT_CORRECTION",
755
+ APPROVE_CORRECTION: "APPROVE_CORRECTION",
756
+ // General actions
757
+ READ: "READ",
758
+ ASSIGN: "ASSIGN",
759
+ UNASSIGN: "UNASSIGN"
598
760
  };
761
+ var ConfirmableActions = [
762
+ ActionType.NOTIFY,
763
+ ActionType.DECLARE,
764
+ ActionType.VALIDATE,
765
+ ActionType.REGISTER,
766
+ ActionType.REJECT,
767
+ ActionType.ARCHIVE,
768
+ ActionType.PRINT_CERTIFICATE
769
+ ];
770
+ var ActionTypes = import_zod7.z.enum([
771
+ "DELETE",
772
+ "CREATE",
773
+ "NOTIFY",
774
+ "DECLARE",
775
+ "VALIDATE",
776
+ "REGISTER",
777
+ "DETECT_DUPLICATE",
778
+ "REJECT",
779
+ "MARKED_AS_DUPLICATE",
780
+ "ARCHIVE",
781
+ "PRINT_CERTIFICATE",
782
+ "REQUEST_CORRECTION",
783
+ "REJECT_CORRECTION",
784
+ "APPROVE_CORRECTION",
785
+ "READ",
786
+ "ASSIGN",
787
+ "UNASSIGN"
788
+ ]);
789
+ var declarationActionValues = [
790
+ ActionTypes.enum.DECLARE,
791
+ ActionTypes.enum.VALIDATE,
792
+ ActionTypes.enum.REGISTER
793
+ ];
794
+ var DeclarationActions = ActionTypes.extract(declarationActionValues);
795
+ var declarationUpdateActionValues = [
796
+ ...declarationActionValues,
797
+ ActionTypes.enum.REQUEST_CORRECTION
798
+ ];
799
+ var DeclarationUpdateActions = ActionTypes.extract(
800
+ declarationUpdateActionValues
801
+ );
802
+ var annotationActions = ActionTypes.exclude(declarationActionValues);
803
+ var writeActions = ActionTypes.exclude([
804
+ ActionType.CREATE,
805
+ ActionType.READ,
806
+ ActionType.ASSIGN,
807
+ ActionType.UNASSIGN
808
+ ]);
809
+
810
+ // ../commons/src/events/FormConfig.ts
811
+ var import_zod8 = require("zod");
812
+ var DeclarationFormConfig = import_zod8.z.object({
813
+ label: TranslationConfig.describe("Human readable description of the form"),
814
+ pages: import_zod8.z.array(FormPageConfig)
815
+ }).describe("Configuration for a declaration form");
816
+ var ActionFormConfig = import_zod8.z.object({
817
+ label: TranslationConfig.describe("Human readable description of the form"),
818
+ pages: import_zod8.z.array(PageConfig)
819
+ });
820
+ var FormConfig = import_zod8.z.union([DeclarationFormConfig, ActionFormConfig]);
599
821
 
600
822
  // ../commons/src/events/ActionConfig.ts
601
- var ActionConditional2 = import_zod7.z.discriminatedUnion("type", [
823
+ var ActionConditional2 = import_zod9.z.discriminatedUnion("type", [
602
824
  /** If conditional is defined, the action is shown to the user only if the condition is met */
603
825
  ShowConditional,
604
826
  /** If conditional is defined, the action is enabled only if the condition is met */
605
827
  EnableConditional
606
828
  ]);
607
- var ActionConfigBase = import_zod7.z.object({
829
+ var DeclarationReviewConfig = import_zod9.z.object({
830
+ title: TranslationConfig.describe("Title of the review page"),
831
+ fields: import_zod9.z.array(FieldConfig).describe("Fields to be rendered on the review page for annotations.")
832
+ }).describe("Configuration for **declaration** review page.");
833
+ var ActionConfigBase = import_zod9.z.object({
608
834
  label: TranslationConfig,
609
- conditionals: import_zod7.z.array(ActionConditional2).optional().default([]),
610
- draft: import_zod7.z.boolean().optional(),
611
- forms: import_zod7.z.array(FormConfig)
835
+ conditionals: import_zod9.z.array(ActionConditional2).optional().default([]),
836
+ draft: import_zod9.z.boolean().optional()
612
837
  });
613
838
  var DeclareConfig = ActionConfigBase.merge(
614
- import_zod7.z.object({
615
- type: import_zod7.z.literal(ActionType.DECLARE)
839
+ import_zod9.z.object({
840
+ type: import_zod9.z.literal(ActionType.DECLARE),
841
+ review: DeclarationReviewConfig
616
842
  })
617
843
  );
618
844
  var ValidateConfig = ActionConfigBase.merge(
619
- import_zod7.z.object({
620
- type: import_zod7.z.literal(ActionType.VALIDATE)
845
+ import_zod9.z.object({
846
+ type: import_zod9.z.literal(ActionType.VALIDATE),
847
+ review: DeclarationReviewConfig
621
848
  })
622
849
  );
623
- var RejectDeclarationConfig = ActionConfigBase.merge(
624
- import_zod7.z.object({
625
- type: import_zod7.z.literal(ActionType.REJECT),
626
- comment: import_zod7.z.string(),
627
- isDuplicate: import_zod7.z.boolean()
850
+ var RegisterConfig = ActionConfigBase.merge(
851
+ import_zod9.z.object({
852
+ type: import_zod9.z.literal(ActionType.REGISTER),
853
+ review: DeclarationReviewConfig
628
854
  })
629
855
  );
630
- var MarkedAsDuplicateConfig = ActionConfigBase.merge(
631
- import_zod7.z.object({
632
- type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE),
633
- comment: import_zod7.z.string(),
634
- duplicates: import_zod7.z.array(import_zod7.z.string()).describe("UUIDs of duplicate records")
856
+ var RejectDeclarationConfig = ActionConfigBase.merge(
857
+ import_zod9.z.object({
858
+ type: import_zod9.z.literal(ActionType.REJECT)
635
859
  })
636
860
  );
637
- var ArchivedConfig = ActionConfigBase.merge(
638
- import_zod7.z.object({
639
- type: import_zod7.z.literal(ActionType.ARCHIVED),
640
- comment: import_zod7.z.string(),
641
- isDuplicate: import_zod7.z.boolean()
861
+ var MarkedAsDuplicateConfig = ActionConfigBase.merge(
862
+ import_zod9.z.object({
863
+ type: import_zod9.z.literal(ActionType.MARKED_AS_DUPLICATE)
642
864
  })
643
865
  );
644
- var RegisterConfig = ActionConfigBase.merge(
645
- import_zod7.z.object({
646
- type: import_zod7.z.literal(ActionType.REGISTER)
866
+ var ArchiveConfig = ActionConfigBase.merge(
867
+ import_zod9.z.object({
868
+ type: import_zod9.z.literal(ActionType.ARCHIVE)
647
869
  })
648
870
  );
649
871
  var DeleteConfig = ActionConfigBase.merge(
650
- import_zod7.z.object({
651
- type: import_zod7.z.literal(ActionType.DELETE)
872
+ import_zod9.z.object({
873
+ type: import_zod9.z.literal(ActionType.DELETE)
652
874
  })
653
875
  );
654
876
  var PrintCertificateActionConfig = ActionConfigBase.merge(
655
- import_zod7.z.object({
656
- type: import_zod7.z.literal(ActionType.PRINT_CERTIFICATE)
877
+ import_zod9.z.object({
878
+ type: import_zod9.z.literal(ActionType.PRINT_CERTIFICATE),
879
+ printForm: ActionFormConfig
657
880
  })
658
881
  );
659
882
  var RequestCorrectionConfig = ActionConfigBase.merge(
660
- import_zod7.z.object({
661
- type: import_zod7.z.literal(ActionType.REQUEST_CORRECTION),
662
- onboardingForm: import_zod7.z.array(FormPage),
663
- additionalDetailsForm: import_zod7.z.array(FormPage)
883
+ import_zod9.z.object({
884
+ type: import_zod9.z.literal(ActionType.REQUEST_CORRECTION),
885
+ onboardingForm: import_zod9.z.array(PageConfig),
886
+ additionalDetailsForm: import_zod9.z.array(PageConfig)
664
887
  })
665
888
  );
666
889
  var RejectCorrectionConfig = ActionConfigBase.merge(
667
- import_zod7.z.object({
668
- type: import_zod7.z.literal(ActionType.REJECT_CORRECTION)
890
+ import_zod9.z.object({
891
+ type: import_zod9.z.literal(ActionType.REJECT_CORRECTION)
669
892
  })
670
893
  );
671
894
  var ApproveCorrectionConfig = ActionConfigBase.merge(
672
- import_zod7.z.object({
673
- type: import_zod7.z.literal(ActionType.APPROVE_CORRECTION)
895
+ import_zod9.z.object({
896
+ type: import_zod9.z.literal(ActionType.APPROVE_CORRECTION)
674
897
  })
675
898
  );
676
- var CustomConfig = ActionConfigBase.merge(
677
- import_zod7.z.object({
678
- type: import_zod7.z.literal(ActionType.CUSTOM)
679
- })
680
- );
681
- var ActionConfig = import_zod7.z.discriminatedUnion("type", [
899
+ var ActionConfig = import_zod9.z.discriminatedUnion("type", [
682
900
  DeclareConfig,
683
901
  ValidateConfig,
684
902
  RejectDeclarationConfig,
685
903
  MarkedAsDuplicateConfig,
686
- ArchivedConfig,
904
+ ArchiveConfig,
687
905
  RegisterConfig,
688
906
  DeleteConfig,
689
907
  PrintCertificateActionConfig,
690
908
  RequestCorrectionConfig,
691
909
  RejectCorrectionConfig,
692
- ApproveCorrectionConfig,
693
- CustomConfig
910
+ ApproveCorrectionConfig
911
+ ]);
912
+ var DeclarationActionConfig = import_zod9.z.discriminatedUnion("type", [
913
+ DeclareConfig,
914
+ ValidateConfig,
915
+ RegisterConfig
694
916
  ]);
695
917
 
696
918
  // ../commons/src/events/offline/CertificateConfig.ts
697
- var import_zod8 = require("zod");
698
- var FontFamily = import_zod8.z.object({
699
- normal: import_zod8.z.string(),
700
- bold: import_zod8.z.string(),
701
- italics: import_zod8.z.string(),
702
- bolditalics: import_zod8.z.string()
919
+ var import_zod10 = require("zod");
920
+ var FontFamily = import_zod10.z.object({
921
+ normal: import_zod10.z.string(),
922
+ bold: import_zod10.z.string(),
923
+ italics: import_zod10.z.string(),
924
+ bolditalics: import_zod10.z.string()
703
925
  });
704
- var CertificateConfig = import_zod8.z.object({
705
- id: import_zod8.z.string(),
706
- event: import_zod8.z.string(),
926
+ var CertificateConfig = import_zod10.z.object({
927
+ id: import_zod10.z.string(),
928
+ event: import_zod10.z.string(),
707
929
  label: TranslationConfig,
708
- isDefault: import_zod8.z.boolean(),
709
- fee: import_zod8.z.object({
710
- onTime: import_zod8.z.number(),
711
- late: import_zod8.z.number(),
712
- delayed: import_zod8.z.number()
930
+ isDefault: import_zod10.z.boolean(),
931
+ fee: import_zod10.z.object({
932
+ onTime: import_zod10.z.number(),
933
+ late: import_zod10.z.number(),
934
+ delayed: import_zod10.z.number()
713
935
  }),
714
- svgUrl: import_zod8.z.string(),
715
- fonts: import_zod8.z.record(FontFamily).optional()
936
+ svgUrl: import_zod10.z.string(),
937
+ fonts: import_zod10.z.record(FontFamily).optional()
716
938
  });
717
939
  var CertificateTemplateConfig = CertificateConfig.extend({
718
- hash: import_zod8.z.string().optional(),
719
- svg: import_zod8.z.string()
940
+ hash: import_zod10.z.string().optional(),
941
+ svg: import_zod10.z.string()
720
942
  });
721
943
 
722
944
  // ../commons/src/events/offline/LanguageConfig.ts
723
- var import_zod9 = require("zod");
724
- var LanguageConfig = import_zod9.z.object({
725
- lang: import_zod9.z.string(),
945
+ var import_zod11 = require("zod");
946
+ var LanguageConfig = import_zod11.z.object({
947
+ lang: import_zod11.z.string(),
726
948
  /**
727
949
  * client.csv contents
728
950
  */
729
- messages: import_zod9.z.record(import_zod9.z.string())
951
+ messages: import_zod11.z.record(import_zod11.z.string())
730
952
  });
731
953
 
732
954
  // ../commons/src/events/EventConfig.ts
733
- var import_zod18 = require("zod");
955
+ var import_zod20 = require("zod");
734
956
 
735
957
  // ../commons/src/events/DeduplicationConfig.ts
736
- var import_zod10 = require("zod");
737
- var FieldReference = import_zod10.z.string();
738
- var Matcher = import_zod10.z.object({
739
- fieldId: import_zod10.z.string(),
740
- options: import_zod10.z.object({
741
- boost: import_zod10.z.number().optional()
958
+ var import_zod12 = require("zod");
959
+ var FieldReference = import_zod12.z.string();
960
+ var Matcher = import_zod12.z.object({
961
+ fieldId: import_zod12.z.string(),
962
+ options: import_zod12.z.object({
963
+ boost: import_zod12.z.number().optional()
742
964
  }).optional().default({})
743
965
  });
744
966
  var FuzzyMatcher = Matcher.extend({
745
- type: import_zod10.z.literal("fuzzy"),
746
- options: import_zod10.z.object({
967
+ type: import_zod12.z.literal("fuzzy"),
968
+ options: import_zod12.z.object({
747
969
  /**
748
970
  * Names of length 3 or less characters = 0 edits allowed
749
971
  * Names of length 4 - 6 characters = 1 edit allowed
750
972
  * Names of length >7 characters = 2 edits allowed
751
973
  */
752
- fuzziness: import_zod10.z.union([import_zod10.z.string(), import_zod10.z.number()]).optional().default("AUTO:4,7"),
753
- boost: import_zod10.z.number().optional().default(1)
974
+ fuzziness: import_zod12.z.union([import_zod12.z.string(), import_zod12.z.number()]).optional().default("AUTO:4,7"),
975
+ boost: import_zod12.z.number().optional().default(1)
754
976
  }).optional().default({})
755
977
  });
756
978
  var StrictMatcher = Matcher.extend({
757
- type: import_zod10.z.literal("strict"),
758
- options: import_zod10.z.object({
759
- boost: import_zod10.z.number().optional().default(1)
979
+ type: import_zod12.z.literal("strict"),
980
+ options: import_zod12.z.object({
981
+ boost: import_zod12.z.number().optional().default(1)
760
982
  }).optional().default({})
761
983
  });
762
984
  var DateRangeMatcher = Matcher.extend({
763
- type: import_zod10.z.literal("dateRange"),
764
- options: import_zod10.z.object({
765
- days: import_zod10.z.number(),
985
+ type: import_zod12.z.literal("dateRange"),
986
+ options: import_zod12.z.object({
987
+ days: import_zod12.z.number(),
766
988
  origin: FieldReference,
767
- boost: import_zod10.z.number().optional().default(1)
989
+ boost: import_zod12.z.number().optional().default(1)
768
990
  })
769
991
  });
770
992
  var DateDistanceMatcher = Matcher.extend({
771
- type: import_zod10.z.literal("dateDistance"),
772
- options: import_zod10.z.object({
773
- days: import_zod10.z.number(),
993
+ type: import_zod12.z.literal("dateDistance"),
994
+ options: import_zod12.z.object({
995
+ days: import_zod12.z.number(),
774
996
  origin: FieldReference,
775
- boost: import_zod10.z.number().optional().default(1)
997
+ boost: import_zod12.z.number().optional().default(1)
776
998
  })
777
999
  });
778
- var And = import_zod10.z.object({
779
- type: import_zod10.z.literal("and"),
780
- clauses: import_zod10.z.lazy(() => Clause.array())
1000
+ var And = import_zod12.z.object({
1001
+ type: import_zod12.z.literal("and"),
1002
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
1003
+ clauses: import_zod12.z.lazy(() => Clause.array())
781
1004
  });
782
- var Or = import_zod10.z.object({
783
- type: import_zod10.z.literal("or"),
784
- clauses: import_zod10.z.lazy(() => Clause.array())
1005
+ var Or = import_zod12.z.object({
1006
+ type: import_zod12.z.literal("or"),
1007
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
1008
+ clauses: import_zod12.z.lazy(() => Clause.array())
785
1009
  });
786
- var Clause = import_zod10.z.lazy(
787
- () => import_zod10.z.discriminatedUnion("type", [
1010
+ var Clause = import_zod12.z.lazy(
1011
+ () => import_zod12.z.discriminatedUnion("type", [
788
1012
  And,
789
1013
  Or,
790
1014
  FuzzyMatcher,
@@ -793,37 +1017,37 @@ var Clause = import_zod10.z.lazy(
793
1017
  DateDistanceMatcher
794
1018
  ])
795
1019
  );
796
- var DeduplicationConfig = import_zod10.z.object({
797
- id: import_zod10.z.string(),
1020
+ var DeduplicationConfig = import_zod12.z.object({
1021
+ id: import_zod12.z.string(),
798
1022
  label: TranslationConfig,
799
1023
  query: Clause
800
1024
  });
801
1025
 
802
1026
  // ../commons/src/events/SummaryConfig.ts
803
- var import_zod11 = require("zod");
804
- var Field = import_zod11.z.object({
805
- id: import_zod11.z.string().describe("Id of summary field"),
1027
+ var import_zod13 = require("zod");
1028
+ var Field = import_zod13.z.object({
1029
+ id: import_zod13.z.string().describe("Id of summary field"),
806
1030
  value: TranslationConfig.describe(
807
1031
  "Summary field value. Can utilise values defined in configuration and EventMetadata"
808
1032
  ),
809
1033
  label: TranslationConfig,
810
1034
  emptyValueMessage: TranslationConfig.optional()
811
1035
  });
812
- var Title = import_zod11.z.object({
813
- id: import_zod11.z.string(),
1036
+ var Title = import_zod13.z.object({
1037
+ id: import_zod13.z.string(),
814
1038
  label: TranslationConfig.describe("Title content"),
815
1039
  emptyValueMessage: TranslationConfig.optional()
816
1040
  });
817
- var SummaryConfig = import_zod11.z.object({
1041
+ var SummaryConfig = import_zod13.z.object({
818
1042
  title: Title.describe("Title of summary view."),
819
- fields: import_zod11.z.array(Field).describe("Fields rendered in summary view.")
1043
+ fields: import_zod13.z.array(Field).describe("Fields rendered in summary view.")
820
1044
  }).describe("Configuration for summary in event.");
821
1045
 
822
1046
  // ../commons/src/events/WorkqueueConfig.ts
823
- var import_zod13 = require("zod");
1047
+ var import_zod15 = require("zod");
824
1048
 
825
1049
  // ../commons/src/events/EventMetadata.ts
826
- var import_zod12 = require("zod");
1050
+ var import_zod14 = require("zod");
827
1051
  var EventStatus = {
828
1052
  CREATED: "CREATED",
829
1053
  NOTIFIED: "NOTIFIED",
@@ -835,18 +1059,19 @@ var EventStatus = {
835
1059
  ARCHIVED: "ARCHIVED"
836
1060
  };
837
1061
  var eventStatuses = Object.values(EventStatus);
838
- var EventStatuses = import_zod12.z.nativeEnum(EventStatus);
839
- var EventMetadata = import_zod12.z.object({
840
- id: import_zod12.z.string(),
841
- type: import_zod12.z.string(),
1062
+ var EventStatuses = import_zod14.z.nativeEnum(EventStatus);
1063
+ var EventMetadata = import_zod14.z.object({
1064
+ id: import_zod14.z.string(),
1065
+ type: import_zod14.z.string(),
842
1066
  status: EventStatuses,
843
- createdAt: import_zod12.z.string().datetime(),
844
- createdBy: import_zod12.z.string(),
845
- createdAtLocation: import_zod12.z.string(),
846
- modifiedAt: import_zod12.z.string().datetime(),
847
- assignedTo: import_zod12.z.string().nullish(),
848
- updatedBy: import_zod12.z.string(),
849
- trackingId: import_zod12.z.string()
1067
+ createdAt: import_zod14.z.string().datetime(),
1068
+ createdBy: import_zod14.z.string(),
1069
+ createdAtLocation: import_zod14.z.string(),
1070
+ modifiedAt: import_zod14.z.string().datetime(),
1071
+ assignedTo: import_zod14.z.string().nullish(),
1072
+ updatedBy: import_zod14.z.string(),
1073
+ trackingId: import_zod14.z.string(),
1074
+ registrationNumber: import_zod14.z.string().nullish()
850
1075
  });
851
1076
  var eventMetadataLabelMap = {
852
1077
  "event.assignedTo": {
@@ -898,28 +1123,33 @@ var eventMetadataLabelMap = {
898
1123
  id: "event.trackingId.label",
899
1124
  defaultMessage: "Tracking ID",
900
1125
  description: "Tracking ID"
1126
+ },
1127
+ "event.registrationNumber": {
1128
+ id: "event.registrationNumber.label",
1129
+ defaultMessage: "Registration Number",
1130
+ description: "Registration Number"
901
1131
  }
902
1132
  };
903
1133
 
904
1134
  // ../commons/src/events/WorkqueueConfig.ts
905
- var WorkqueueConfig = import_zod13.z.object({
906
- id: import_zod13.z.string().describe("Unique identifier for workqueue."),
907
- filters: import_zod13.z.array(
908
- import_zod13.z.object({
909
- status: import_zod13.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
1135
+ var WorkqueueConfig = import_zod15.z.object({
1136
+ id: import_zod15.z.string().describe("Unique identifier for workqueue."),
1137
+ filters: import_zod15.z.array(
1138
+ import_zod15.z.object({
1139
+ status: import_zod15.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
910
1140
  })
911
1141
  ).describe("Filters to be applied to workqueue.")
912
1142
  }).describe("Configuration for workqueue.");
913
1143
 
914
1144
  // ../commons/src/events/AdvancedSearchConfig.ts
915
- var import_zod14 = require("zod");
916
- var AdvancedSearchConfig = import_zod14.z.object({
1145
+ var import_zod16 = require("zod");
1146
+ var AdvancedSearchConfig = import_zod16.z.object({
917
1147
  title: TranslationConfig.describe("Advanced search tab title"),
918
- fields: import_zod14.z.array(
919
- import_zod14.z.object({
920
- fieldId: import_zod14.z.string(),
921
- config: import_zod14.z.object({
922
- type: import_zod14.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
1148
+ fields: import_zod16.z.array(
1149
+ import_zod16.z.object({
1150
+ fieldId: import_zod16.z.string(),
1151
+ config: import_zod16.z.object({
1152
+ type: import_zod16.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
923
1153
  }).optional().describe("Configuration options for the field")
924
1154
  })
925
1155
  ).optional().default([]).describe("Advanced search fields.")
@@ -929,12 +1159,12 @@ var AdvancedSearchConfig = import_zod14.z.object({
929
1159
  var import_lodash = require("lodash");
930
1160
 
931
1161
  // ../commons/src/workqueues/WorkqueueConfig.ts
932
- var import_zod16 = require("zod");
1162
+ var import_zod18 = require("zod");
933
1163
 
934
1164
  // ../commons/src/workqueues/defaultColumns.ts
935
- var import_zod15 = require("zod");
936
- var WorkQueueColumnConfig = import_zod15.z.object({
937
- id: import_zod15.z.string(),
1165
+ var import_zod17 = require("zod");
1166
+ var WorkQueueColumnConfig = import_zod17.z.object({
1167
+ id: import_zod17.z.string(),
938
1168
  label: TranslationConfig
939
1169
  });
940
1170
  var defaultColumns = {
@@ -971,16 +1201,16 @@ var defaultColumns = {
971
1201
  }
972
1202
  }
973
1203
  };
974
- var DefaultColumnKeys = import_zod15.z.enum(
1204
+ var DefaultColumnKeys = import_zod17.z.enum(
975
1205
  Object.keys(defaultColumns)
976
1206
  );
977
1207
 
978
1208
  // ../commons/src/workqueues/WorkqueueConfig.ts
979
- var rootWorkqueueConfig = import_zod16.z.object({
980
- id: import_zod16.z.string(),
1209
+ var rootWorkqueueConfig = import_zod18.z.object({
1210
+ id: import_zod18.z.string(),
981
1211
  title: TranslationConfig,
982
- columns: import_zod16.z.array(WorkQueueColumnConfig),
983
- defaultColumns: import_zod16.z.array(DefaultColumnKeys)
1212
+ columns: import_zod18.z.array(WorkQueueColumnConfig),
1213
+ defaultColumns: import_zod18.z.array(DefaultColumnKeys)
984
1214
  });
985
1215
  var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
986
1216
 
@@ -1060,7 +1290,7 @@ var import_ajv_formats = __toESM(require("ajv-formats"));
1060
1290
  var import_date_fns = require("date-fns");
1061
1291
 
1062
1292
  // ../commons/src/events/FieldTypeMapping.ts
1063
- var import_zod17 = require("zod");
1293
+ var import_zod19 = require("zod");
1064
1294
  function mapFieldTypeToZod(type, required) {
1065
1295
  let schema;
1066
1296
  switch (type) {
@@ -1102,6 +1332,9 @@ function mapFieldTypeToZod(type, required) {
1102
1332
  case FieldType.ADDRESS:
1103
1333
  schema = AddressFieldUpdateValue;
1104
1334
  break;
1335
+ case FieldType.DATA:
1336
+ schema = DataFieldValue;
1337
+ break;
1105
1338
  }
1106
1339
  return required ? schema : schema.nullish();
1107
1340
  }
@@ -1110,7 +1343,7 @@ function createValidationSchema(config) {
1110
1343
  for (const field2 of config) {
1111
1344
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1112
1345
  }
1113
- return import_zod17.z.object(shape);
1346
+ return import_zod19.z.object(shape);
1114
1347
  }
1115
1348
  function mapFieldTypeToMockValue(field2, i) {
1116
1349
  switch (field2.type) {
@@ -1136,6 +1369,7 @@ function mapFieldTypeToMockValue(field2, i) {
1136
1369
  case FieldType.ADDRESS:
1137
1370
  return {
1138
1371
  country: "FAR",
1372
+ addressType: AddressType.DOMESTIC,
1139
1373
  province: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
1140
1374
  district: "5ef450bc-712d-48ad-93f3-8da0fa453baa",
1141
1375
  urbanOrRural: "URBAN",
@@ -1157,6 +1391,54 @@ function mapFieldTypeToMockValue(field2, i) {
1157
1391
  };
1158
1392
  case FieldType.FILE_WITH_OPTIONS:
1159
1393
  return null;
1394
+ case FieldType.DATA:
1395
+ return {};
1396
+ }
1397
+ }
1398
+ function mapFieldTypeToEmptyValue(field2) {
1399
+ switch (field2.type) {
1400
+ case FieldType.DIVIDER:
1401
+ case FieldType.TEXT:
1402
+ case FieldType.TEXTAREA:
1403
+ case FieldType.BULLET_LIST:
1404
+ case FieldType.PAGE_HEADER:
1405
+ case FieldType.LOCATION:
1406
+ case FieldType.SELECT:
1407
+ case FieldType.COUNTRY:
1408
+ case FieldType.RADIO_GROUP:
1409
+ case FieldType.SIGNATURE:
1410
+ case FieldType.PARAGRAPH:
1411
+ case FieldType.ADMINISTRATIVE_AREA:
1412
+ case FieldType.FACILITY:
1413
+ case FieldType.OFFICE:
1414
+ case FieldType.NUMBER:
1415
+ case FieldType.EMAIL:
1416
+ case FieldType.DATE:
1417
+ case FieldType.CHECKBOX:
1418
+ case FieldType.DATA:
1419
+ return null;
1420
+ case FieldType.ADDRESS:
1421
+ return {
1422
+ country: null,
1423
+ addressType: AddressType.DOMESTIC,
1424
+ province: null,
1425
+ district: null,
1426
+ urbanOrRural: "URBAN",
1427
+ // Default to urban needed for validation
1428
+ town: null,
1429
+ residentialArea: null,
1430
+ street: null,
1431
+ number: null,
1432
+ zipCode: null
1433
+ };
1434
+ case FieldType.FILE:
1435
+ return {
1436
+ filename: "",
1437
+ originalFilename: "",
1438
+ type: ""
1439
+ };
1440
+ case FieldType.FILE_WITH_OPTIONS:
1441
+ return [];
1160
1442
  }
1161
1443
  }
1162
1444
  var isParagraphFieldType = (field2) => {
@@ -1222,10 +1504,14 @@ var isFacilityFieldType = (field2) => {
1222
1504
  var isOfficeFieldType = (field2) => {
1223
1505
  return field2.config.type === FieldType.OFFICE;
1224
1506
  };
1507
+ var isDataFieldType = (field2) => {
1508
+ return field2.config.type === FieldType.DATA;
1509
+ };
1225
1510
 
1226
1511
  // ../commons/src/conditionals/validate.ts
1227
1512
  var ajv = new import_ajv.default({
1228
- $data: true
1513
+ $data: true,
1514
+ allowUnionTypes: true
1229
1515
  });
1230
1516
  (0, import_ajv_formats.default)(ajv);
1231
1517
  function validate(schema, data) {
@@ -1258,88 +1544,81 @@ function isFieldVisible(field2, form) {
1258
1544
  function isFieldEnabled(field2, form) {
1259
1545
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1260
1546
  }
1261
- var zodToIntlErrorMap = (issue, _ctx) => {
1262
- if (issue.code === "invalid_string" && issue.validation === "date") {
1263
- return {
1264
- message: {
1265
- message: {
1266
- defaultMessage: "Invalid date. Please use the format YYYY-MM-DD",
1267
- description: "This is the error message for invalid date fields",
1268
- id: "v2.error.invalidDate"
1269
- }
1270
- }
1271
- };
1272
- }
1273
- if (issue.code === "invalid_string" && issue.validation === "email") {
1274
- return {
1275
- message: {
1276
- message: {
1277
- defaultMessage: "Invalid email address",
1278
- description: "This is the error message for invalid email fields",
1279
- id: "v2.error.invalidEmail"
1280
- }
1281
- }
1282
- };
1283
- }
1284
- if (issue.code === "invalid_type" && issue.expected !== issue.received && issue.received === "undefined" || issue.code === "too_small" && issue.message === void 0) {
1285
- return {
1286
- message: {
1287
- message: {
1288
- defaultMessage: "Required for registration",
1289
- description: "This is the error message for required fields",
1290
- id: "v2.error.required"
1291
- }
1292
- }
1293
- };
1547
+ function isFieldDisplayedOnReview(field2, form) {
1548
+ return isFieldVisible(field2, form) && isFieldConditionMet(field2, form, ConditionalType.DISPLAY_ON_REVIEW);
1549
+ }
1550
+ var errorMessages = {
1551
+ hiddenField: {
1552
+ id: "v2.error.hidden",
1553
+ defaultMessage: "Hidden or disabled field should not receive a value",
1554
+ description: "Error message when field is hidden or disabled, but a value was received"
1555
+ },
1556
+ invalidDate: {
1557
+ defaultMessage: "Invalid date field",
1558
+ description: "Error message when date field is invalid",
1559
+ id: "v2.error.invalidDate"
1560
+ },
1561
+ invalidEmail: {
1562
+ defaultMessage: "Invalid email address",
1563
+ description: "Error message when email address is invalid",
1564
+ id: "v2.error.invalidEmail"
1565
+ },
1566
+ requiredField: {
1567
+ defaultMessage: "Required for registration",
1568
+ description: "Error message when required field is missing",
1569
+ id: "v2.error.required"
1570
+ },
1571
+ invalidInput: {
1572
+ defaultMessage: "Invalid input",
1573
+ description: "Error message when generic field is invalid",
1574
+ id: "v2.error.invalid"
1294
1575
  }
1576
+ };
1577
+ function createIntlError(message) {
1295
1578
  return {
1296
1579
  message: {
1297
- message: {
1298
- defaultMessage: "Invalid input",
1299
- description: "This is the error message for invalid field value",
1300
- id: "v2.error.invalid"
1301
- }
1580
+ message
1302
1581
  }
1303
1582
  };
1304
- };
1305
- function getFieldValidationErrors({
1306
- field: field2,
1307
- values
1308
- }) {
1309
- const conditionalParameters = {
1310
- $form: values,
1311
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1312
- };
1313
- if (!isFieldVisible(field2, values) || !isFieldEnabled(field2, values)) {
1314
- if (values[field2.id]) {
1315
- return {
1316
- errors: [
1317
- {
1318
- message: {
1319
- id: "v2.error.hidden",
1320
- defaultMessage: "Hidden or disabled field should not receive a value",
1321
- description: "Error message when field is hidden or disabled, but a value was received"
1322
- }
1583
+ }
1584
+ function zodToIntlErrorMap(issue, _ctx) {
1585
+ switch (issue.code) {
1586
+ case "invalid_string": {
1587
+ if (_ctx.data === "") {
1588
+ return createIntlError(errorMessages.requiredField);
1589
+ }
1590
+ if (issue.validation === "date") {
1591
+ return createIntlError(errorMessages.invalidDate);
1592
+ }
1593
+ if (issue.validation === "email") {
1594
+ return createIntlError(errorMessages.invalidEmail);
1595
+ }
1596
+ break;
1597
+ }
1598
+ case "invalid_type": {
1599
+ if (issue.expected !== issue.received && issue.received === "undefined") {
1600
+ return createIntlError(errorMessages.requiredField);
1601
+ }
1602
+ break;
1603
+ }
1604
+ case "too_small": {
1605
+ if (issue.message === void 0) {
1606
+ return createIntlError(errorMessages.requiredField);
1607
+ }
1608
+ break;
1609
+ }
1610
+ case "invalid_union": {
1611
+ for (const { issues } of issue.unionErrors) {
1612
+ for (const e of issues) {
1613
+ if (zodToIntlErrorMap(e, _ctx).message.message.id !== "v2.error.required") {
1614
+ return createIntlError(errorMessages.invalidInput);
1323
1615
  }
1324
- ]
1325
- };
1616
+ }
1617
+ }
1618
+ return createIntlError(errorMessages.requiredField);
1326
1619
  }
1327
- return {
1328
- errors: []
1329
- };
1330
1620
  }
1331
- const fieldValidationResult = validateFieldInput({
1332
- field: field2,
1333
- value: values[field2.id]
1334
- });
1335
- const customValidationResults = runCustomFieldValidations({
1336
- field: field2,
1337
- conditionalParameters
1338
- });
1339
- return {
1340
- // Assumes that custom validation errors are more important than field validation errors
1341
- errors: [...customValidationResults, ...fieldValidationResult]
1342
- };
1621
+ return createIntlError(errorMessages.invalidInput);
1343
1622
  }
1344
1623
  function runCustomFieldValidations({
1345
1624
  field: field2,
@@ -1362,68 +1641,126 @@ function validateFieldInput({
1362
1641
  );
1363
1642
  return rawError.error?.issues.map((issue) => issue.message) ?? [];
1364
1643
  }
1365
-
1366
- // ../commons/src/events/utils.ts
1367
- function isMetadataField(field2) {
1368
- return field2 in eventMetadataLabelMap;
1369
- }
1370
- var findInputPageFields = (config) => {
1371
- return (0, import_lodash.flattenDeep)(
1372
- config.actions.map(
1373
- ({ forms }) => forms.map(
1374
- ({ pages }) => pages.map(
1375
- ({ fields }) => fields.map(({ id, label }) => ({ id, label }))
1376
- )
1377
- )
1378
- )
1379
- );
1380
- };
1381
- var findPageFields = (config) => {
1382
- return (0, import_lodash.flattenDeep)(
1383
- config.actions.map((action) => {
1384
- if (action.type === ActionType.REQUEST_CORRECTION) {
1385
- return [
1386
- ...action.forms.map(({ pages }) => pages.map(({ fields }) => fields)),
1387
- ...action.onboardingForm.flatMap(({ fields }) => fields),
1388
- ...action.additionalDetailsForm.flatMap(({ fields }) => fields)
1389
- ];
1390
- }
1391
- return action.forms.map(({ pages }) => pages.map(({ fields }) => fields));
1392
- })
1393
- );
1394
- };
1395
- var resolveLabelsFromKnownFields = ({
1396
- pageFields,
1397
- refFields
1398
- }) => {
1399
- return refFields.map((field2) => {
1400
- if (field2.label) {
1401
- return field2;
1402
- }
1403
- if (isMetadataField(field2.id)) {
1644
+ function runFieldValidations({
1645
+ field: field2,
1646
+ values
1647
+ }) {
1648
+ const conditionalParameters = {
1649
+ $form: values,
1650
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1651
+ };
1652
+ const fieldValidationResult = validateFieldInput({
1653
+ field: field2,
1654
+ value: values[field2.id]
1655
+ });
1656
+ const customValidationResults = runCustomFieldValidations({
1657
+ field: field2,
1658
+ conditionalParameters
1659
+ });
1660
+ return {
1661
+ // Assumes that custom validation errors are based on the field type, and extend the validation.
1662
+ errors: [...fieldValidationResult, ...customValidationResults]
1663
+ };
1664
+ }
1665
+ function getFieldValidationErrors({
1666
+ field: field2,
1667
+ values
1668
+ }) {
1669
+ if (!isFieldVisible(field2, values) || !isFieldEnabled(field2, values)) {
1670
+ if (values[field2.id]) {
1404
1671
  return {
1405
- ...field2,
1406
- label: eventMetadataLabelMap[field2.id]
1672
+ errors: [
1673
+ {
1674
+ message: errorMessages.hiddenField
1675
+ }
1676
+ ]
1407
1677
  };
1408
1678
  }
1409
- const pageLabel = pageFields.find((pageField) => pageField.id === field2.id);
1410
- if (!pageLabel) {
1411
- throw new Error(`Referenced field ${field2.id} does not have a label`);
1412
- }
1413
1679
  return {
1414
- ...field2,
1415
- label: pageLabel.label
1680
+ errors: []
1416
1681
  };
1682
+ }
1683
+ return runFieldValidations({
1684
+ field: field2,
1685
+ values
1417
1686
  });
1687
+ }
1688
+
1689
+ // ../commons/src/uuid.ts
1690
+ var import_uuid = require("uuid");
1691
+ function getUUID() {
1692
+ return (0, import_uuid.v4)();
1693
+ }
1694
+
1695
+ // ../commons/src/events/utils.ts
1696
+ var import_date_fns2 = require("date-fns");
1697
+
1698
+ // ../commons/src/utils.ts
1699
+ function getOrThrow(x, message) {
1700
+ if (x === void 0 || x === null) {
1701
+ throw new Error(message);
1702
+ }
1703
+ return x;
1704
+ }
1705
+
1706
+ // ../commons/src/events/utils.ts
1707
+ function isDeclarationActionConfig(action) {
1708
+ return DeclarationActions.safeParse(action.type).success;
1709
+ }
1710
+ function getDeclarationFields(configuration) {
1711
+ return configuration.declaration.pages.flatMap(({ fields }) => fields);
1712
+ }
1713
+ function getDeclarationPages(configuration) {
1714
+ return configuration.declaration.pages;
1715
+ }
1716
+ function getDeclaration(configuration) {
1717
+ return configuration.declaration;
1718
+ }
1719
+ var getActionAnnotationFields = (actionConfig) => {
1720
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1721
+ return [
1722
+ ...actionConfig.onboardingForm.flatMap(({ fields }) => fields),
1723
+ ...actionConfig.additionalDetailsForm.flatMap(({ fields }) => fields)
1724
+ ];
1725
+ }
1726
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1727
+ return actionConfig.printForm.pages.flatMap(({ fields }) => fields);
1728
+ }
1729
+ if (isDeclarationActionConfig(actionConfig)) {
1730
+ return actionConfig.review.fields;
1731
+ }
1732
+ return [];
1733
+ };
1734
+ var getAllAnnotationFields = (config) => {
1735
+ return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1418
1736
  };
1419
- function getAllFields(configuration) {
1420
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => [
1421
- ...form.review.fields,
1422
- ...form.pages.flatMap((page) => page.fields)
1737
+ var findAllFields = (config) => {
1738
+ return (0, import_lodash.flattenDeep)([
1739
+ ...getDeclarationFields(config),
1740
+ ...getAllAnnotationFields(config)
1423
1741
  ]);
1742
+ };
1743
+ var findRecordActionPages = (config, actionType) => {
1744
+ const action = config.actions.find((a) => a.type === actionType);
1745
+ if (action?.type === ActionType.REQUEST_CORRECTION) {
1746
+ return [...action.onboardingForm, ...action.additionalDetailsForm];
1747
+ }
1748
+ if (action?.type === ActionType.PRINT_CERTIFICATE) {
1749
+ return action.printForm.pages;
1750
+ }
1751
+ return [];
1752
+ };
1753
+ function getActionReview(configuration, actionType) {
1754
+ const [actionConfig] = configuration.actions.filter(
1755
+ (a) => a.type === actionType
1756
+ );
1757
+ return getOrThrow(
1758
+ actionConfig.review,
1759
+ `No review config found for ${actionType}`
1760
+ );
1424
1761
  }
1425
- function getAllPages(configuration) {
1426
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => form.pages);
1762
+ function getActionReviewFields(configuration, actionType) {
1763
+ return getActionReview(configuration, actionType).fields;
1427
1764
  }
1428
1765
  function validateWorkqueueConfig(workqueueConfigs) {
1429
1766
  workqueueConfigs.map((workqueue) => {
@@ -1432,79 +1769,98 @@ function validateWorkqueueConfig(workqueueConfigs) {
1432
1769
  );
1433
1770
  if (!rootWorkqueue) {
1434
1771
  throw new Error(
1435
- `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1772
+ `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1436
1773
  );
1437
1774
  }
1438
1775
  });
1439
1776
  }
1440
- var findActiveActionForm = (configuration, action) => {
1441
- const actionConfig = configuration.actions.find((a) => a.type === action);
1442
- const form = actionConfig?.forms.find((f) => f.active);
1443
- return form;
1444
- };
1445
- var findActiveActionFormPages = (configuration, action) => {
1446
- return findActiveActionForm(configuration, action)?.pages;
1447
- };
1448
- var getFormFields = (formConfig) => {
1449
- return formConfig.pages.flatMap((p) => p.fields);
1450
- };
1451
- var findActiveActionFormFields = (configuration, action) => {
1452
- const form = findActiveActionForm(configuration, action);
1453
- return form ? getFormFields(form) : void 0;
1454
- };
1455
- var findActiveActionFields = (configuration, action) => {
1456
- const form = findActiveActionForm(configuration, action);
1457
- const reviewFields = form?.review.fields;
1458
- const formFields = form ? getFormFields(form) : void 0;
1459
- const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1460
- return allFields;
1461
- };
1462
- function getActiveActionFields(configuration, action) {
1463
- const fields = findActiveActionFields(configuration, action);
1464
- if (!fields) {
1465
- throw new Error(`No active field config found for action type ${action}`);
1466
- }
1467
- return fields;
1468
- }
1469
- function getEventConfiguration(eventConfigurations, type) {
1470
- const config = eventConfigurations.find((config2) => config2.id === type);
1471
- if (!config) {
1472
- throw new Error(`Event configuration not found for type: ${type}`);
1473
- }
1474
- return config;
1475
- }
1476
- function isOptionalUncheckedCheckbox(field2, form) {
1477
- if (field2.type !== FieldType.CHECKBOX || field2.required) {
1478
- return false;
1777
+ function isPageVisible(page, formValues) {
1778
+ if (!page.conditional) {
1779
+ return true;
1479
1780
  }
1480
- return !form[field2.id];
1781
+ return validate(page.conditional, {
1782
+ $form: formValues,
1783
+ $now: (0, import_date_fns2.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1784
+ });
1481
1785
  }
1482
- function stripHiddenFields(fields, data) {
1483
- return (0, import_lodash.omitBy)(data, (_2, fieldId) => {
1786
+ function omitHiddenFields(fields, values) {
1787
+ return (0, import_lodash.omitBy)(values, (_, fieldId) => {
1484
1788
  const field2 = fields.find((f) => f.id === fieldId);
1485
1789
  if (!field2) {
1486
1790
  return true;
1487
1791
  }
1488
- if (isOptionalUncheckedCheckbox(field2, data)) {
1489
- return true;
1490
- }
1491
- return !isFieldVisible(field2, data);
1792
+ return !isFieldVisible(field2, values);
1492
1793
  });
1493
1794
  }
1795
+ function omitHiddenPaginatedFields(formConfig, declaration) {
1796
+ const visiblePagesFormFields = formConfig.pages.filter((p) => isPageVisible(p, declaration)).flatMap((p) => p.fields);
1797
+ return omitHiddenFields(visiblePagesFormFields, declaration);
1798
+ }
1799
+ function findActiveDrafts(event2, drafts) {
1800
+ const actions = event2.actions.slice().filter(({ type }) => type !== ActionType.READ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1801
+ const lastAction = actions[actions.length - 1];
1802
+ return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
1803
+ }
1804
+ function createEmptyDraft(eventId, draftId, actionType) {
1805
+ return {
1806
+ id: draftId,
1807
+ eventId,
1808
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1809
+ transactionId: getUUID(),
1810
+ action: {
1811
+ type: actionType,
1812
+ declaration: {},
1813
+ annotation: {},
1814
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1815
+ createdBy: "@todo",
1816
+ createdAtLocation: "@todo"
1817
+ }
1818
+ };
1819
+ }
1820
+ function isVerificationPage(page) {
1821
+ return page.type === PageTypes.enum.VERIFICATION;
1822
+ }
1823
+ function deepMerge(currentDocument, actionDocument) {
1824
+ return (0, import_lodash.mergeWith)(
1825
+ currentDocument,
1826
+ actionDocument,
1827
+ (previousValue, incomingValue) => {
1828
+ if (incomingValue === void 0) {
1829
+ return previousValue;
1830
+ }
1831
+ if ((0, import_lodash.isArray)(incomingValue)) {
1832
+ return incomingValue;
1833
+ }
1834
+ if ((0, import_lodash.isObject)(previousValue) && (0, import_lodash.isObject)(incomingValue)) {
1835
+ return void 0;
1836
+ }
1837
+ return incomingValue;
1838
+ }
1839
+ );
1840
+ }
1841
+ function findLastAssignmentAction(actions) {
1842
+ return actions.filter(
1843
+ ({ type }) => type === ActionType.ASSIGN || type === ActionType.UNASSIGN
1844
+ ).reduce((latestAction, action) => !latestAction || action.createdAt > latestAction.createdAt ? action : latestAction, void 0);
1845
+ }
1846
+ function isWriteAction(actionType) {
1847
+ return writeActions.safeParse(actionType).success;
1848
+ }
1494
1849
 
1495
1850
  // ../commons/src/events/EventConfig.ts
1496
- var EventConfig = import_zod18.z.object({
1497
- id: import_zod18.z.string().describe(
1851
+ var EventConfig = import_zod20.z.object({
1852
+ id: import_zod20.z.string().describe(
1498
1853
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1499
1854
  ),
1500
1855
  summary: SummaryConfig,
1501
1856
  label: TranslationConfig,
1502
- actions: import_zod18.z.array(ActionConfig),
1503
- workqueues: import_zod18.z.array(WorkqueueConfig),
1504
- deduplication: import_zod18.z.array(DeduplicationConfig).optional().default([]),
1505
- advancedSearch: import_zod18.z.array(AdvancedSearchConfig).optional().default([])
1857
+ actions: import_zod20.z.array(ActionConfig),
1858
+ declaration: DeclarationFormConfig,
1859
+ workqueues: import_zod20.z.array(WorkqueueConfig),
1860
+ deduplication: import_zod20.z.array(DeduplicationConfig).optional().default([]),
1861
+ advancedSearch: import_zod20.z.array(AdvancedSearchConfig).optional().default([])
1506
1862
  }).superRefine((event2, ctx) => {
1507
- const allFields = findPageFields(event2);
1863
+ const allFields = findAllFields(event2);
1508
1864
  const fieldIds = allFields.map((field2) => field2.id);
1509
1865
  const advancedSearchFields = event2.advancedSearch.flatMap(
1510
1866
  (section) => section.fields.flatMap((field2) => field2.fieldId)
@@ -1531,111 +1887,123 @@ var EventConfig = import_zod18.z.object({
1531
1887
  });
1532
1888
 
1533
1889
  // ../commons/src/events/EventConfigInput.ts
1534
- var defineForm = (form) => FormConfig.parse(form);
1535
- var defineFormPage = (formPage) => FormPage.parse(formPage);
1890
+ var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
1891
+ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1892
+ var definePage = (page) => PageConfig.parse(page);
1893
+ var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1536
1894
 
1537
1895
  // ../commons/src/events/Draft.ts
1538
- var import_zod21 = require("zod");
1896
+ var import_zod23 = require("zod");
1539
1897
 
1540
1898
  // ../commons/src/events/ActionDocument.ts
1541
- var import_zod19 = require("zod");
1542
- var ActionUpdate = import_zod19.z.record(import_zod19.z.string(), FieldUpdateValue);
1543
- var ActionBase = import_zod19.z.object({
1544
- id: import_zod19.z.string(),
1545
- createdAt: import_zod19.z.string().datetime(),
1546
- createdBy: import_zod19.z.string(),
1547
- data: ActionUpdate,
1548
- metadata: ActionUpdate.optional(),
1549
- createdAtLocation: import_zod19.z.string()
1899
+ var import_zod21 = require("zod");
1900
+ var ActionUpdate = import_zod21.z.record(import_zod21.z.string(), FieldUpdateValue);
1901
+ var ActionStatus = {
1902
+ Requested: "Requested",
1903
+ Accepted: "Accepted",
1904
+ Rejected: "Rejected"
1905
+ };
1906
+ var ActionBase = import_zod21.z.object({
1907
+ id: import_zod21.z.string(),
1908
+ createdAt: import_zod21.z.string().datetime(),
1909
+ createdBy: import_zod21.z.string(),
1910
+ declaration: ActionUpdate,
1911
+ annotation: ActionUpdate.optional(),
1912
+ createdAtLocation: import_zod21.z.string(),
1913
+ status: import_zod21.z.enum([
1914
+ ActionStatus.Requested,
1915
+ ActionStatus.Accepted,
1916
+ ActionStatus.Rejected
1917
+ ]),
1918
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1919
+ originalActionId: import_zod21.z.string().optional()
1550
1920
  });
1551
1921
  var AssignedAction = ActionBase.merge(
1552
- import_zod19.z.object({
1553
- type: import_zod19.z.literal(ActionType.ASSIGN),
1554
- assignedTo: import_zod19.z.string()
1922
+ import_zod21.z.object({
1923
+ type: import_zod21.z.literal(ActionType.ASSIGN),
1924
+ assignedTo: import_zod21.z.string()
1555
1925
  })
1556
1926
  );
1557
1927
  var UnassignedAction = ActionBase.merge(
1558
- import_zod19.z.object({
1559
- type: import_zod19.z.literal(ActionType.UNASSIGN)
1928
+ import_zod21.z.object({
1929
+ type: import_zod21.z.literal(ActionType.UNASSIGN),
1930
+ assignedTo: import_zod21.z.literal(null).default(null)
1560
1931
  })
1561
1932
  );
1562
1933
  var RegisterAction = ActionBase.merge(
1563
- import_zod19.z.object({
1564
- type: import_zod19.z.literal(ActionType.REGISTER),
1565
- identifiers: import_zod19.z.object({
1566
- trackingId: import_zod19.z.string(),
1567
- registrationNumber: import_zod19.z.string()
1568
- })
1934
+ import_zod21.z.object({
1935
+ type: import_zod21.z.literal(ActionType.REGISTER),
1936
+ registrationNumber: import_zod21.z.string().optional()
1569
1937
  })
1570
1938
  );
1571
1939
  var DeclareAction = ActionBase.merge(
1572
- import_zod19.z.object({
1573
- type: import_zod19.z.literal(ActionType.DECLARE)
1940
+ import_zod21.z.object({
1941
+ type: import_zod21.z.literal(ActionType.DECLARE)
1574
1942
  })
1575
1943
  );
1576
1944
  var ValidateAction = ActionBase.merge(
1577
- import_zod19.z.object({
1578
- type: import_zod19.z.literal(ActionType.VALIDATE)
1945
+ import_zod21.z.object({
1946
+ type: import_zod21.z.literal(ActionType.VALIDATE)
1579
1947
  })
1580
1948
  );
1581
1949
  var RejectAction = ActionBase.merge(
1582
- import_zod19.z.object({
1583
- type: import_zod19.z.literal(ActionType.REJECT)
1950
+ import_zod21.z.object({
1951
+ type: import_zod21.z.literal(ActionType.REJECT)
1584
1952
  })
1585
1953
  );
1586
1954
  var MarkAsDuplicateAction = ActionBase.merge(
1587
- import_zod19.z.object({
1588
- type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1955
+ import_zod21.z.object({
1956
+ type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE)
1589
1957
  })
1590
1958
  );
1591
- var ArchivedAction = ActionBase.merge(
1592
- import_zod19.z.object({
1593
- type: import_zod19.z.literal(ActionType.ARCHIVED)
1959
+ var ArchiveAction = ActionBase.merge(
1960
+ import_zod21.z.object({
1961
+ type: import_zod21.z.literal(ActionType.ARCHIVE)
1594
1962
  })
1595
1963
  );
1596
1964
  var CreatedAction = ActionBase.merge(
1597
- import_zod19.z.object({
1598
- type: import_zod19.z.literal(ActionType.CREATE)
1965
+ import_zod21.z.object({
1966
+ type: import_zod21.z.literal(ActionType.CREATE)
1599
1967
  })
1600
1968
  );
1601
1969
  var NotifiedAction = ActionBase.merge(
1602
- import_zod19.z.object({
1603
- type: import_zod19.z.literal(ActionType.NOTIFY)
1970
+ import_zod21.z.object({
1971
+ type: import_zod21.z.literal(ActionType.NOTIFY)
1604
1972
  })
1605
1973
  );
1606
1974
  var PrintCertificateAction = ActionBase.merge(
1607
- import_zod19.z.object({
1608
- type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE)
1975
+ import_zod21.z.object({
1976
+ type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE)
1609
1977
  })
1610
1978
  );
1611
1979
  var RequestedCorrectionAction = ActionBase.merge(
1612
- import_zod19.z.object({
1613
- type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION)
1980
+ import_zod21.z.object({
1981
+ type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION)
1614
1982
  })
1615
1983
  );
1616
1984
  var ApprovedCorrectionAction = ActionBase.merge(
1617
- import_zod19.z.object({
1618
- type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION),
1619
- requestId: import_zod19.z.string()
1985
+ import_zod21.z.object({
1986
+ type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION),
1987
+ requestId: import_zod21.z.string()
1620
1988
  })
1621
1989
  );
1622
1990
  var RejectedCorrectionAction = ActionBase.merge(
1623
- import_zod19.z.object({
1624
- type: import_zod19.z.literal(ActionType.REJECT_CORRECTION),
1625
- requestId: import_zod19.z.string()
1991
+ import_zod21.z.object({
1992
+ type: import_zod21.z.literal(ActionType.REJECT_CORRECTION),
1993
+ requestId: import_zod21.z.string()
1626
1994
  })
1627
1995
  );
1628
- var CustomAction = ActionBase.merge(
1629
- import_zod19.z.object({
1630
- type: import_zod19.z.literal(ActionType.CUSTOM)
1996
+ var ReadAction = ActionBase.merge(
1997
+ import_zod21.z.object({
1998
+ type: import_zod21.z.literal(ActionType.READ)
1631
1999
  })
1632
2000
  );
1633
- var ActionDocument = import_zod19.z.discriminatedUnion("type", [
2001
+ var ActionDocument = import_zod21.z.discriminatedUnion("type", [
1634
2002
  CreatedAction,
1635
2003
  ValidateAction,
1636
2004
  RejectAction,
1637
2005
  MarkAsDuplicateAction,
1638
- ArchivedAction,
2006
+ ArchiveAction,
1639
2007
  NotifiedAction,
1640
2008
  RegisterAction,
1641
2009
  DeclareAction,
@@ -1645,110 +2013,125 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1645
2013
  RejectedCorrectionAction,
1646
2014
  UnassignedAction,
1647
2015
  PrintCertificateAction,
1648
- CustomAction
2016
+ ReadAction
1649
2017
  ]);
1650
- var ResolvedUser = import_zod19.z.object({
1651
- id: import_zod19.z.string(),
1652
- role: import_zod19.z.string(),
1653
- name: import_zod19.z.array(
1654
- import_zod19.z.object({
1655
- use: import_zod19.z.string(),
1656
- given: import_zod19.z.array(import_zod19.z.string()),
1657
- family: import_zod19.z.string()
2018
+ var AsyncRejectActionDocument = ActionBase.omit({
2019
+ declaration: true,
2020
+ annotation: true,
2021
+ createdBy: true,
2022
+ createdAtLocation: true
2023
+ }).merge(
2024
+ import_zod21.z.object({
2025
+ type: import_zod21.z.enum(ConfirmableActions),
2026
+ status: import_zod21.z.literal(ActionStatus.Rejected)
2027
+ })
2028
+ );
2029
+ var Action = import_zod21.z.union([ActionDocument, AsyncRejectActionDocument]);
2030
+ var ResolvedUser = import_zod21.z.object({
2031
+ id: import_zod21.z.string(),
2032
+ role: import_zod21.z.string(),
2033
+ name: import_zod21.z.array(
2034
+ import_zod21.z.object({
2035
+ use: import_zod21.z.string(),
2036
+ given: import_zod21.z.array(import_zod21.z.string()),
2037
+ family: import_zod21.z.string()
1658
2038
  })
1659
2039
  )
1660
2040
  });
1661
2041
 
1662
2042
  // ../commons/src/events/ActionInput.ts
1663
- var import_zod20 = require("zod");
1664
- var BaseActionInput = import_zod20.z.object({
1665
- eventId: import_zod20.z.string(),
1666
- transactionId: import_zod20.z.string(),
1667
- incomplete: import_zod20.z.boolean().optional().default(false).describe("Allows action with partial data to be saved"),
1668
- data: ActionUpdate,
1669
- metadata: ActionUpdate.optional()
2043
+ var import_zod22 = require("zod");
2044
+ var BaseActionInput = import_zod22.z.object({
2045
+ eventId: import_zod22.z.string(),
2046
+ transactionId: import_zod22.z.string(),
2047
+ declaration: ActionUpdate.default({}),
2048
+ annotation: ActionUpdate.optional(),
2049
+ originalActionId: import_zod22.z.string().optional(),
2050
+ keepAssignment: import_zod22.z.boolean().optional()
1670
2051
  });
1671
2052
  var CreateActionInput = BaseActionInput.merge(
1672
- import_zod20.z.object({
1673
- type: import_zod20.z.literal(ActionType.CREATE).default(ActionType.CREATE),
1674
- createdAtLocation: import_zod20.z.string()
2053
+ import_zod22.z.object({
2054
+ type: import_zod22.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2055
+ createdAtLocation: import_zod22.z.string()
1675
2056
  })
1676
2057
  );
1677
2058
  var RegisterActionInput = BaseActionInput.merge(
1678
- import_zod20.z.object({
1679
- type: import_zod20.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
1680
- identifiers: import_zod20.z.object({
1681
- trackingId: import_zod20.z.string(),
1682
- registrationNumber: import_zod20.z.string()
1683
- })
2059
+ import_zod22.z.object({
2060
+ type: import_zod22.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2061
+ registrationNumber: import_zod22.z.string().optional()
1684
2062
  })
1685
2063
  );
1686
2064
  var ValidateActionInput = BaseActionInput.merge(
1687
- import_zod20.z.object({
1688
- type: import_zod20.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
1689
- duplicates: import_zod20.z.array(import_zod20.z.string())
2065
+ import_zod22.z.object({
2066
+ type: import_zod22.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2067
+ duplicates: import_zod22.z.array(import_zod22.z.string())
1690
2068
  })
1691
2069
  );
1692
2070
  var NotifyActionInput = BaseActionInput.merge(
1693
- import_zod20.z.object({
1694
- type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY),
1695
- createdAtLocation: import_zod20.z.string()
2071
+ import_zod22.z.object({
2072
+ type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1696
2073
  })
1697
2074
  );
1698
2075
  var DeclareActionInput = BaseActionInput.merge(
1699
- import_zod20.z.object({
1700
- type: import_zod20.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2076
+ import_zod22.z.object({
2077
+ type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1701
2078
  })
1702
2079
  );
1703
2080
  var PrintCertificateActionInput = BaseActionInput.merge(
1704
- import_zod20.z.object({
1705
- type: import_zod20.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2081
+ import_zod22.z.object({
2082
+ type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1706
2083
  })
1707
2084
  );
1708
2085
  var RejectDeclarationActionInput = BaseActionInput.merge(
1709
- import_zod20.z.object({
1710
- type: import_zod20.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2086
+ import_zod22.z.object({
2087
+ type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1711
2088
  })
1712
2089
  );
1713
2090
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1714
- import_zod20.z.object({
1715
- type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2091
+ import_zod22.z.object({
2092
+ type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1716
2093
  })
1717
2094
  );
1718
- var ArchivedActionInput = BaseActionInput.merge(
1719
- import_zod20.z.object({
1720
- type: import_zod20.z.literal(ActionType.ARCHIVED).default(ActionType.ARCHIVED)
2095
+ var ArchiveActionInput = BaseActionInput.merge(
2096
+ import_zod22.z.object({
2097
+ type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1721
2098
  })
1722
2099
  );
1723
2100
  var AssignActionInput = BaseActionInput.merge(
1724
- import_zod20.z.object({
1725
- type: import_zod20.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
1726
- assignedTo: import_zod20.z.string()
2101
+ import_zod22.z.object({
2102
+ type: import_zod22.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2103
+ assignedTo: import_zod22.z.string()
1727
2104
  })
1728
2105
  );
1729
2106
  var UnassignActionInput = BaseActionInput.merge(
1730
- import_zod20.z.object({
1731
- type: import_zod20.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN)
2107
+ import_zod22.z.object({
2108
+ type: import_zod22.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2109
+ assignedTo: import_zod22.z.literal(null).default(null)
1732
2110
  })
1733
2111
  );
1734
2112
  var RequestCorrectionActionInput = BaseActionInput.merge(
1735
- import_zod20.z.object({
1736
- type: import_zod20.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2113
+ import_zod22.z.object({
2114
+ type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
1737
2115
  })
1738
2116
  );
1739
2117
  var RejectCorrectionActionInput = BaseActionInput.merge(
1740
- import_zod20.z.object({
1741
- requestId: import_zod20.z.string(),
1742
- type: import_zod20.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2118
+ import_zod22.z.object({
2119
+ requestId: import_zod22.z.string(),
2120
+ type: import_zod22.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
1743
2121
  })
1744
2122
  );
1745
2123
  var ApproveCorrectionActionInput = BaseActionInput.merge(
1746
- import_zod20.z.object({
1747
- requestId: import_zod20.z.string(),
1748
- type: import_zod20.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2124
+ import_zod22.z.object({
2125
+ requestId: import_zod22.z.string(),
2126
+ type: import_zod22.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2127
+ })
2128
+ );
2129
+ var ReadActionInput = BaseActionInput.merge(
2130
+ import_zod22.z.object({
2131
+ type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
1749
2132
  })
1750
2133
  );
1751
- var ActionInput = import_zod20.z.discriminatedUnion("type", [
2134
+ var ActionInput = import_zod22.z.discriminatedUnion("type", [
1752
2135
  CreateActionInput,
1753
2136
  ValidateActionInput,
1754
2137
  RegisterActionInput,
@@ -1756,62 +2139,68 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
1756
2139
  DeclareActionInput,
1757
2140
  RejectDeclarationActionInput,
1758
2141
  MarkedAsDuplicateActionInput,
1759
- ArchivedActionInput,
2142
+ ArchiveActionInput,
1760
2143
  AssignActionInput,
1761
2144
  UnassignActionInput,
1762
2145
  PrintCertificateActionInput,
1763
2146
  RequestCorrectionActionInput,
1764
2147
  RejectCorrectionActionInput,
1765
- ApproveCorrectionActionInput
2148
+ ApproveCorrectionActionInput,
2149
+ ReadActionInput
1766
2150
  ]);
1767
2151
 
1768
2152
  // ../commons/src/events/Draft.ts
1769
- var Draft = import_zod21.z.object({
1770
- id: import_zod21.z.string(),
1771
- eventId: import_zod21.z.string(),
1772
- transactionId: import_zod21.z.string(),
1773
- createdAt: import_zod21.z.string().datetime(),
2153
+ var Draft = import_zod23.z.object({
2154
+ id: import_zod23.z.string(),
2155
+ eventId: import_zod23.z.string(),
2156
+ transactionId: import_zod23.z.string(),
2157
+ createdAt: import_zod23.z.string().datetime(),
1774
2158
  action: ActionBase.extend({
1775
- type: import_zod21.z.enum(Object.values(ActionType))
2159
+ type: ActionTypes
1776
2160
  }).omit({ id: true })
1777
2161
  });
1778
2162
  var DraftInput = BaseActionInput.extend({
1779
- type: import_zod21.z.enum(Object.values(ActionType))
2163
+ type: ActionTypes
1780
2164
  });
1781
2165
 
1782
2166
  // ../commons/src/events/EventInput.ts
1783
- var import_zod22 = require("zod");
1784
- var EventInput = import_zod22.z.object({
1785
- transactionId: import_zod22.z.string(),
1786
- type: import_zod22.z.string()
2167
+ var import_zod24 = require("zod");
2168
+ var EventInput = import_zod24.z.object({
2169
+ transactionId: import_zod24.z.string(),
2170
+ type: import_zod24.z.string()
1787
2171
  });
1788
2172
 
1789
2173
  // ../commons/src/events/EventDocument.ts
1790
- var import_zod23 = require("zod");
1791
- var EventDocument = import_zod23.z.object({
1792
- id: import_zod23.z.string(),
1793
- type: import_zod23.z.string(),
1794
- createdAt: import_zod23.z.string().datetime(),
1795
- updatedAt: import_zod23.z.string().datetime(),
1796
- actions: import_zod23.z.array(ActionDocument),
1797
- trackingId: import_zod23.z.string()
2174
+ var import_zod25 = require("zod");
2175
+ var EventDocument = import_zod25.z.object({
2176
+ id: import_zod25.z.string(),
2177
+ type: import_zod25.z.string(),
2178
+ createdAt: import_zod25.z.string().datetime(),
2179
+ updatedAt: import_zod25.z.string().datetime(),
2180
+ actions: import_zod25.z.array(Action),
2181
+ trackingId: import_zod25.z.string()
1798
2182
  });
1799
2183
 
1800
2184
  // ../commons/src/events/EventIndex.ts
1801
- var import_zod24 = require("zod");
2185
+ var import_zod26 = require("zod");
1802
2186
  var EventIndex = EventMetadata.extend({
1803
- data: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any())
2187
+ declaration: import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any())
1804
2188
  });
1805
- var EventSearchIndex = import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any()).and(
1806
- import_zod24.z.object({
1807
- type: import_zod24.z.string()
2189
+ var EventSearchIndex = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any()).and(
2190
+ import_zod26.z.object({
2191
+ type: import_zod26.z.string()
1808
2192
  // Ensures "type" (event-id) exists and is a string
1809
2193
  })
1810
2194
  );
1811
2195
 
1812
2196
  // ../commons/src/events/state/index.ts
1813
- var _ = __toESM(require("lodash"));
1814
2197
  function getStatusFromActions(actions) {
2198
+ const hasRejectedAction = actions.some(
2199
+ (a) => a.status === ActionStatus.Rejected
2200
+ );
2201
+ if (hasRejectedAction) {
2202
+ return EventStatus.REJECTED;
2203
+ }
1815
2204
  return actions.reduce((status, action) => {
1816
2205
  if (action.type === ActionType.CREATE) {
1817
2206
  return EventStatus.CREATED;
@@ -1828,9 +2217,12 @@ function getStatusFromActions(actions) {
1828
2217
  if (action.type === ActionType.REJECT) {
1829
2218
  return EventStatus.REJECTED;
1830
2219
  }
1831
- if (action.type === ActionType.ARCHIVED) {
2220
+ if (action.type === ActionType.ARCHIVE) {
1832
2221
  return EventStatus.ARCHIVED;
1833
2222
  }
2223
+ if (action.type === ActionType.NOTIFY) {
2224
+ return EventStatus.NOTIFIED;
2225
+ }
1834
2226
  return status;
1835
2227
  }, EventStatus.CREATED);
1836
2228
  }
@@ -1845,7 +2237,7 @@ function getAssignedUserFromActions(actions) {
1845
2237
  return user2;
1846
2238
  }, null);
1847
2239
  }
1848
- function getData(actions) {
2240
+ function aggregateActionDeclarations(actions) {
1849
2241
  const excludedActions = [
1850
2242
  ActionType.REQUEST_CORRECTION,
1851
2243
  ActionType.PRINT_CERTIFICATE
@@ -1859,46 +2251,34 @@ function getData(actions) {
1859
2251
  if (!requestAction) {
1860
2252
  return status;
1861
2253
  }
1862
- return deepMerge(status, requestAction.data);
2254
+ return deepMerge(status, requestAction.declaration);
1863
2255
  }
1864
- return deepMerge(status, action.data);
2256
+ return deepMerge(status, action.declaration);
1865
2257
  }, {});
1866
2258
  }
1867
2259
  function deepDropNulls(obj) {
1868
- if (!_.isObject(obj)) return obj;
1869
- return Object.entries(obj).reduce((acc, [key, value]) => {
1870
- if (_.isObject(value)) {
1871
- value = deepDropNulls(value);
1872
- }
1873
- if (value !== null) {
1874
- return {
1875
- ...acc,
1876
- [key]: value
1877
- };
1878
- }
1879
- return acc;
1880
- }, {});
1881
- }
1882
- function deepMerge(currentDocument, actionDocument) {
1883
- return _.mergeWith(
1884
- currentDocument,
1885
- actionDocument,
1886
- (previousValue, incomingValue) => {
1887
- if (incomingValue === void 0) {
1888
- return previousValue;
1889
- }
1890
- if (_.isArray(incomingValue)) {
1891
- return incomingValue;
1892
- }
1893
- if (_.isObject(previousValue) && _.isObject(incomingValue)) {
1894
- return void 0;
2260
+ if (Array.isArray(obj)) {
2261
+ return obj.map(deepDropNulls);
2262
+ }
2263
+ if (obj !== null && typeof obj === "object") {
2264
+ return Object.entries(obj).reduce((acc, [key, value]) => {
2265
+ const cleanedValue = deepDropNulls(value);
2266
+ if (cleanedValue !== null) {
2267
+ ;
2268
+ acc[key] = cleanedValue;
1895
2269
  }
1896
- return incomingValue;
1897
- }
1898
- );
2270
+ return acc;
2271
+ }, {});
2272
+ }
2273
+ return obj;
2274
+ }
2275
+ function isUndeclaredDraft(status) {
2276
+ return status === EventStatus.CREATED;
1899
2277
  }
1900
- function isUndeclaredDraft(event2) {
1901
- return event2.actions.every(({ type }) => type === ActionType.CREATE);
2278
+ function getAcceptedActions(event2) {
2279
+ return event2.actions.filter(
2280
+ (a) => a.status === ActionStatus.Accepted
2281
+ );
1902
2282
  }
1903
2283
  function getCurrentEventState(event2) {
1904
2284
  const creationAction = event2.actions.find(
@@ -1907,7 +2287,12 @@ function getCurrentEventState(event2) {
1907
2287
  if (!creationAction) {
1908
2288
  throw new Error(`Event ${event2.id} has no creation action`);
1909
2289
  }
1910
- const latestAction = event2.actions[event2.actions.length - 1];
2290
+ const activeActions = getAcceptedActions(event2);
2291
+ const latestAction = activeActions[activeActions.length - 1];
2292
+ const registrationAction = activeActions.find(
2293
+ (a) => a.type === ActionType.REGISTER && a.status === ActionStatus.Accepted
2294
+ );
2295
+ const registrationNumber = registrationAction?.registrationNumber ?? null;
1911
2296
  return deepDropNulls({
1912
2297
  id: event2.id,
1913
2298
  type: event2.type,
@@ -1916,16 +2301,16 @@ function getCurrentEventState(event2) {
1916
2301
  createdBy: creationAction.createdBy,
1917
2302
  createdAtLocation: creationAction.createdAtLocation,
1918
2303
  modifiedAt: latestAction.createdAt,
1919
- assignedTo: getAssignedUserFromActions(event2.actions),
2304
+ assignedTo: getAssignedUserFromActions(activeActions),
1920
2305
  updatedBy: latestAction.createdBy,
1921
- data: getData(event2.actions),
1922
- trackingId: event2.trackingId
2306
+ declaration: aggregateActionDeclarations(activeActions),
2307
+ trackingId: event2.trackingId,
2308
+ registrationNumber
1923
2309
  });
1924
2310
  }
1925
2311
  function getCurrentEventStateWithDrafts(event2, drafts) {
1926
- const actions = event2.actions.slice().sort();
1927
- const lastAction = actions[actions.length - 1];
1928
- const activeDrafts = drafts.filter(({ eventId }) => eventId === event2.id).filter(({ createdAt }) => createdAt > lastAction.createdAt).map((draft) => draft.action).flatMap((action) => {
2312
+ const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2313
+ const activeDrafts = findActiveDrafts(event2, drafts).map((draft) => draft.action).flatMap((action) => {
1929
2314
  if (action.type === ActionType.REQUEST_CORRECTION) {
1930
2315
  return [
1931
2316
  action,
@@ -1952,46 +2337,46 @@ function applyDraftsToEventIndex(eventIndex, drafts) {
1952
2337
  }
1953
2338
  return {
1954
2339
  ...eventIndex,
1955
- data: {
1956
- ...eventIndex.data,
1957
- ...activeDrafts[activeDrafts.length - 1].data
2340
+ declaration: {
2341
+ ...eventIndex.declaration,
2342
+ ...activeDrafts[activeDrafts.length - 1].declaration
1958
2343
  }
1959
2344
  };
1960
2345
  }
1961
- function getMetadataForAction({
2346
+ function getAnnotationFromDrafts(drafts) {
2347
+ const actions = drafts.map((draft) => draft.action);
2348
+ const annotation = actions.reduce((ann, action) => {
2349
+ return deepMerge(ann, action.annotation ?? {});
2350
+ }, {});
2351
+ return deepDropNulls(annotation);
2352
+ }
2353
+ function getActionAnnotation({
1962
2354
  event: event2,
1963
2355
  actionType,
1964
2356
  drafts
1965
2357
  }) {
1966
- const action = event2.actions.find((action2) => actionType === action2.type);
2358
+ const activeActions = getAcceptedActions(event2);
2359
+ const action = activeActions.find(
2360
+ (activeAction) => actionType === activeAction.type
2361
+ );
1967
2362
  const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
1968
2363
  const sorted = [
1969
2364
  ...action ? [action] : [],
1970
2365
  ...eventDrafts.map((draft) => draft.action)
1971
2366
  ].sort();
1972
- const metadata = sorted.reduce((metadata2, action2) => {
1973
- return deepMerge(metadata2, action2.metadata ?? {});
2367
+ const annotation = sorted.reduce((ann, sortedAction) => {
2368
+ return deepMerge(ann, sortedAction.annotation ?? {});
1974
2369
  }, {});
1975
- return deepDropNulls(metadata);
2370
+ return deepDropNulls(annotation);
1976
2371
  }
1977
2372
 
1978
2373
  // ../commons/src/events/defineConfig.ts
1979
2374
  var defineConfig = (config) => {
1980
2375
  validateWorkqueueConfig(config.workqueues);
1981
2376
  const input = EventConfig.parse(config);
1982
- const pageFields = findInputPageFields(input);
1983
- return EventConfig.parse({
1984
- ...input,
1985
- pageFields
1986
- });
2377
+ return input;
1987
2378
  };
1988
2379
 
1989
- // ../commons/src/uuid.ts
1990
- var import_uuid = require("uuid");
1991
- function getUUID() {
1992
- return (0, import_uuid.v4)();
1993
- }
1994
-
1995
2380
  // ../commons/src/events/transactions.ts
1996
2381
  function generateTransactionId() {
1997
2382
  return getUUID();
@@ -2004,6 +2389,16 @@ var import_lodash2 = require("lodash");
2004
2389
  function defineConditional(schema) {
2005
2390
  return schema;
2006
2391
  }
2392
+ function defineFormConditional(schema) {
2393
+ const schemaWithForm = {
2394
+ type: "object",
2395
+ properties: {
2396
+ $form: schema
2397
+ },
2398
+ required: ["$form"]
2399
+ };
2400
+ return defineConditional(schemaWithForm);
2401
+ }
2007
2402
  function alwaysTrue() {
2008
2403
  return {};
2009
2404
  }
@@ -2028,6 +2423,9 @@ function not(condition) {
2028
2423
  required: []
2029
2424
  });
2030
2425
  }
2426
+ function never() {
2427
+ return not(alwaysTrue());
2428
+ }
2031
2429
  var user = {
2032
2430
  hasScope: (scope) => defineConditional({
2033
2431
  type: "object",
@@ -2075,69 +2473,120 @@ var event = {
2075
2473
  required: ["$event"]
2076
2474
  })
2077
2475
  };
2476
+ function getDateFromNow(days) {
2477
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2478
+ }
2479
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2480
+ return {
2481
+ type: "object",
2482
+ properties: {
2483
+ [fieldId]: {
2484
+ type: "string",
2485
+ format: "date",
2486
+ [clause]: { $data: `1/${comparedFieldId}` }
2487
+ },
2488
+ [comparedFieldId]: { type: "string", format: "date" }
2489
+ },
2490
+ required: [fieldId]
2491
+ };
2492
+ }
2493
+ function isFieldReference(value) {
2494
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2495
+ }
2078
2496
  function field(fieldId) {
2079
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2080
2497
  const getDateRange = (date, clause) => ({
2081
2498
  type: "object",
2082
2499
  properties: {
2083
- $form: {
2084
- type: "object",
2085
- properties: {
2086
- [fieldId]: {
2087
- type: "string",
2088
- format: "date",
2089
- [clause]: date
2090
- }
2091
- },
2092
- required: [fieldId]
2500
+ [fieldId]: {
2501
+ type: "string",
2502
+ format: "date",
2503
+ [clause]: date
2093
2504
  }
2094
2505
  },
2095
- required: ["$form"]
2506
+ required: [fieldId]
2096
2507
  });
2097
2508
  return {
2509
+ /**
2510
+ * @private Internal property used for field reference tracking.
2511
+ */
2512
+ _fieldId: fieldId,
2098
2513
  isAfter: () => ({
2099
2514
  days: (days) => ({
2100
- inPast: () => defineConditional(
2515
+ inPast: () => defineFormConditional(
2101
2516
  getDateRange(getDateFromNow(days), "formatMinimum")
2102
2517
  ),
2103
- inFuture: () => defineConditional(
2518
+ inFuture: () => defineFormConditional(
2104
2519
  getDateRange(getDateFromNow(-days), "formatMinimum")
2105
2520
  )
2106
2521
  }),
2107
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
2108
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2522
+ date: (date) => {
2523
+ if (isFieldReference(date)) {
2524
+ const comparedFieldId = date._fieldId;
2525
+ return defineFormConditional(
2526
+ getDateRangeToFieldReference(
2527
+ fieldId,
2528
+ comparedFieldId,
2529
+ "formatMinimum"
2530
+ )
2531
+ );
2532
+ }
2533
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2534
+ },
2535
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2109
2536
  }),
2110
2537
  isBefore: () => ({
2111
2538
  days: (days) => ({
2112
- inPast: () => defineConditional(
2539
+ inPast: () => defineFormConditional(
2113
2540
  getDateRange(getDateFromNow(days), "formatMaximum")
2114
2541
  ),
2115
- inFuture: () => defineConditional(
2542
+ inFuture: () => defineFormConditional(
2116
2543
  getDateRange(getDateFromNow(-days), "formatMaximum")
2117
2544
  )
2118
2545
  }),
2119
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
2120
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2546
+ date: (date) => {
2547
+ if (isFieldReference(date)) {
2548
+ const comparedFieldId = date._fieldId;
2549
+ return defineFormConditional(
2550
+ getDateRangeToFieldReference(
2551
+ fieldId,
2552
+ comparedFieldId,
2553
+ "formatMaximum"
2554
+ )
2555
+ );
2556
+ }
2557
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2558
+ },
2559
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2121
2560
  }),
2122
- isEqualTo: (value) => defineConditional({
2123
- type: "object",
2124
- properties: {
2125
- $form: {
2561
+ isEqualTo: (value) => {
2562
+ if (isFieldReference(value)) {
2563
+ const comparedFieldId = value._fieldId;
2564
+ return defineFormConditional({
2126
2565
  type: "object",
2127
2566
  properties: {
2128
2567
  [fieldId]: {
2129
- oneOf: [
2130
- { type: "string", const: value },
2131
- { type: "boolean", const: value }
2132
- ],
2133
- const: value
2134
- }
2568
+ type: ["string", "boolean"],
2569
+ const: { $data: `1/${comparedFieldId}` }
2570
+ },
2571
+ [comparedFieldId]: { type: ["string", "boolean"] }
2135
2572
  },
2136
- required: [fieldId]
2137
- }
2138
- },
2139
- required: ["$form"]
2140
- }),
2573
+ required: [fieldId, comparedFieldId]
2574
+ });
2575
+ }
2576
+ return defineFormConditional({
2577
+ type: "object",
2578
+ properties: {
2579
+ [fieldId]: {
2580
+ oneOf: [
2581
+ { type: "string", const: value },
2582
+ { type: "boolean", const: value }
2583
+ ],
2584
+ const: value
2585
+ }
2586
+ },
2587
+ required: [fieldId]
2588
+ });
2589
+ },
2141
2590
  /**
2142
2591
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
2143
2592
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -2146,91 +2595,102 @@ function field(fieldId) {
2146
2595
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2147
2596
  *
2148
2597
  */
2149
- isFalsy: () => defineConditional({
2598
+ isFalsy: () => defineFormConditional({
2150
2599
  type: "object",
2151
2600
  properties: {
2152
- $form: {
2153
- type: "object",
2154
- properties: {
2155
- [fieldId]: {
2156
- anyOf: [
2157
- { const: "undefined" },
2158
- { const: false },
2159
- { const: null },
2160
- { const: "" }
2161
- ]
2162
- }
2163
- },
2601
+ [fieldId]: {
2164
2602
  anyOf: [
2165
- {
2166
- required: [fieldId]
2167
- },
2168
- {
2169
- not: {
2170
- required: [fieldId]
2171
- }
2172
- }
2603
+ { const: "undefined" },
2604
+ { const: false },
2605
+ { const: null },
2606
+ { const: "" }
2173
2607
  ]
2174
2608
  }
2175
2609
  },
2176
- required: ["$form"]
2177
- }),
2178
- isUndefined: () => defineConditional({
2179
- type: "object",
2180
- properties: {
2181
- $form: {
2182
- type: "object",
2183
- properties: {
2184
- [fieldId]: {
2185
- type: "string",
2186
- enum: ["undefined"]
2187
- }
2188
- },
2610
+ anyOf: [
2611
+ {
2612
+ required: [fieldId]
2613
+ },
2614
+ {
2189
2615
  not: {
2190
2616
  required: [fieldId]
2191
2617
  }
2192
2618
  }
2619
+ ]
2620
+ }),
2621
+ isUndefined: () => defineFormConditional({
2622
+ type: "object",
2623
+ properties: {
2624
+ [fieldId]: {
2625
+ type: "string",
2626
+ enum: ["undefined"]
2627
+ }
2193
2628
  },
2194
- required: ["$form"]
2629
+ not: {
2630
+ required: [fieldId]
2631
+ }
2195
2632
  }),
2196
- inArray: (values) => defineConditional({
2633
+ inArray: (values) => defineFormConditional({
2197
2634
  type: "object",
2198
2635
  properties: {
2199
- $form: {
2200
- type: "object",
2201
- properties: {
2202
- [fieldId]: {
2203
- type: "string",
2204
- enum: values
2205
- }
2206
- },
2207
- required: [fieldId]
2636
+ [fieldId]: {
2637
+ type: "string",
2638
+ enum: values
2639
+ }
2640
+ },
2641
+ required: [fieldId]
2642
+ }),
2643
+ isValidEnglishName: () => defineFormConditional({
2644
+ type: "object",
2645
+ properties: {
2646
+ [fieldId]: {
2647
+ type: "string",
2648
+ 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'._-]*)*$",
2649
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2650
+ }
2651
+ },
2652
+ required: [fieldId]
2653
+ }),
2654
+ /**
2655
+ * Checks if the field value matches a given regular expression pattern.
2656
+ * @param pattern - The regular expression pattern to match the field value against.
2657
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2658
+ */
2659
+ matches: (pattern) => defineFormConditional({
2660
+ type: "object",
2661
+ properties: {
2662
+ [fieldId]: {
2663
+ type: "string",
2664
+ pattern
2665
+ }
2666
+ },
2667
+ required: [fieldId]
2668
+ }),
2669
+ isBetween: (min, max) => defineFormConditional({
2670
+ type: "object",
2671
+ properties: {
2672
+ [fieldId]: {
2673
+ type: "number",
2674
+ minimum: min,
2675
+ maximum: max
2208
2676
  }
2209
2677
  },
2210
- required: ["$form"]
2678
+ required: [fieldId]
2211
2679
  })
2212
2680
  };
2213
2681
  }
2214
2682
 
2215
2683
  // ../commons/src/fixtures/tennis-club-membership-event.ts
2216
- var PRINT_CERTIFICATE_FORM = defineForm({
2684
+ var PRINT_CERTIFICATE_FORM = defineActionForm({
2217
2685
  label: {
2218
2686
  id: "v2.event.tennis-club-membership.action.certificate.form.label",
2219
2687
  defaultMessage: "Tennis club membership certificate collector",
2220
2688
  description: "This is what this form is referred as in the system"
2221
2689
  },
2222
- version: {
2223
- id: "1.0.0",
2224
- label: {
2225
- id: "v2.event.tennis-club-membership.action.certificate.form.version.1",
2226
- defaultMessage: "Version 1",
2227
- description: "This is the first version of the form"
2228
- }
2229
- },
2230
- active: true,
2231
2690
  pages: [
2232
2691
  {
2233
2692
  id: "collector",
2693
+ type: PageTypes.enum.FORM,
2234
2694
  title: {
2235
2695
  id: "v2.event.tennis-club-membership.action.certificate.form.section.who.title",
2236
2696
  defaultMessage: "Print certified copy",
@@ -2245,7 +2705,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2245
2705
  defaultMessage: "Requester",
2246
2706
  description: "This is the label for the field"
2247
2707
  },
2248
- type: "SELECT",
2708
+ type: FieldType.SELECT,
2249
2709
  options: [
2250
2710
  {
2251
2711
  value: "INFORMANT",
@@ -2322,7 +2782,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2322
2782
  defaultMessage: "Select Type of ID",
2323
2783
  description: "This is the label for selecting the type of ID"
2324
2784
  },
2325
- type: "SELECT",
2785
+ type: FieldType.SELECT,
2326
2786
  options: [
2327
2787
  {
2328
2788
  value: "PASSPORT",
@@ -2423,7 +2883,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2423
2883
  defaultMessage: "Passport Details",
2424
2884
  description: "Field for entering Passport details"
2425
2885
  },
2426
- type: "TEXT"
2886
+ type: FieldType.TEXT
2427
2887
  },
2428
2888
  {
2429
2889
  id: "collector.DRIVING_LICENSE.details",
@@ -2474,7 +2934,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2474
2934
  defaultMessage: "Driving License Details",
2475
2935
  description: "Field for entering Driving License details"
2476
2936
  },
2477
- type: "TEXT"
2937
+ type: FieldType.TEXT
2478
2938
  },
2479
2939
  {
2480
2940
  id: "collector.REFUGEE_NUMBER.details",
@@ -2525,7 +2985,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2525
2985
  defaultMessage: "Refugee Number Details",
2526
2986
  description: "Field for entering Refugee Number details"
2527
2987
  },
2528
- type: "TEXT"
2988
+ type: FieldType.TEXT
2529
2989
  },
2530
2990
  {
2531
2991
  id: "collector.ALIEN_NUMBER.details",
@@ -2576,7 +3036,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2576
3036
  defaultMessage: "Alien Number Details",
2577
3037
  description: "Field for entering Alien Number details"
2578
3038
  },
2579
- type: "TEXT"
3039
+ type: FieldType.TEXT
2580
3040
  },
2581
3041
  {
2582
3042
  id: "collector.OTHER.idTypeOther",
@@ -2627,7 +3087,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2627
3087
  defaultMessage: "Other ID Type (if applicable)",
2628
3088
  description: 'Field for entering ID type if "Other" is selected'
2629
3089
  },
2630
- type: "TEXT"
3090
+ type: FieldType.TEXT
2631
3091
  },
2632
3092
  {
2633
3093
  id: "collector.OTHER.firstName",
@@ -2678,7 +3138,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2678
3138
  defaultMessage: "First Name",
2679
3139
  description: "This is the label for the first name field"
2680
3140
  },
2681
- type: "TEXT"
3141
+ type: FieldType.TEXT
2682
3142
  },
2683
3143
  {
2684
3144
  id: "collector.OTHER.lastName",
@@ -2729,7 +3189,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2729
3189
  defaultMessage: "Last Name",
2730
3190
  description: "This is the label for the last name field"
2731
3191
  },
2732
- type: "TEXT"
3192
+ type: FieldType.TEXT
2733
3193
  },
2734
3194
  {
2735
3195
  id: "collector.OTHER.relationshipToMember",
@@ -2780,7 +3240,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2780
3240
  defaultMessage: "Relationship to Member",
2781
3241
  description: "This is the label for the relationship to member field"
2782
3242
  },
2783
- type: "TEXT"
3243
+ type: FieldType.TEXT
2784
3244
  },
2785
3245
  {
2786
3246
  id: "collector.OTHER.signedAffidavit",
@@ -2831,66 +3291,88 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2831
3291
  defaultMessage: "Signed Affidavit (Optional)",
2832
3292
  description: "This is the label for uploading a signed affidavit"
2833
3293
  },
2834
- type: "FILE"
3294
+ type: FieldType.FILE
2835
3295
  }
2836
3296
  ]
2837
- }
2838
- ],
2839
- review: {
2840
- title: {
2841
- id: "v2.event.tennis-club-membership.action.certificate.form.review.title",
2842
- defaultMessage: "Member certificate collector for {firstname} {surname}",
2843
- description: "Title of the form to show in review page"
2844
3297
  },
2845
- fields: []
2846
- }
2847
- });
2848
- var TENNIS_CLUB_FORM = defineForm({
2849
- label: {
2850
- id: "v2.event.tennis-club-membership.action.declare.form.label",
2851
- defaultMessage: "Tennis club membership application",
2852
- description: "This is what this form is referred as in the system"
2853
- },
2854
- active: true,
2855
- version: {
2856
- id: "1.0.0",
2857
- label: {
2858
- id: "v2.event.tennis-club-membership.action.declare.form.version.1",
2859
- defaultMessage: "Version 1",
2860
- description: "This is the first version of the form"
3298
+ {
3299
+ id: "collector.identity.verify",
3300
+ type: PageTypes.enum.VERIFICATION,
3301
+ conditional: field("collector.requesterId").isEqualTo("INFORMANT"),
3302
+ title: {
3303
+ id: "event.tennis-club-membership.action.print.verifyIdentity",
3304
+ defaultMessage: "Verify their identity",
3305
+ description: "This is the title of the section"
3306
+ },
3307
+ fields: [],
3308
+ actions: {
3309
+ verify: {
3310
+ label: {
3311
+ defaultMessage: "Verified",
3312
+ description: "This is the label for the verification button",
3313
+ id: "v2.event.tennis-club-membership.action.certificate.form.verify"
3314
+ }
3315
+ },
3316
+ cancel: {
3317
+ label: {
3318
+ defaultMessage: "Identity does not match",
3319
+ description: "This is the label for the verification cancellation button",
3320
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel"
3321
+ },
3322
+ confirmation: {
3323
+ title: {
3324
+ defaultMessage: "Print without proof of ID?",
3325
+ description: "This is the title for the verification cancellation modal",
3326
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel.confirmation.title"
3327
+ },
3328
+ body: {
3329
+ defaultMessage: "Please be aware that if you proceed, you will be responsible for issuing a certificate without the necessary proof of ID from the collector",
3330
+ description: "This is the body for the verification cancellation modal",
3331
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel.confirmation.body"
3332
+ }
3333
+ }
3334
+ }
3335
+ }
2861
3336
  }
3337
+ ]
3338
+ });
3339
+ var TENNIS_CLUB_DECLARATION_REVIEW = {
3340
+ title: {
3341
+ id: "v2.event.tennis-club-membership.action.declare.form.review.title",
3342
+ defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
3343
+ description: "Title of the review page"
2862
3344
  },
2863
- review: {
2864
- title: {
2865
- id: "v2.event.tennis-club-membership.action.declare.form.review.title",
2866
- defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
2867
- description: "Title of the form to show in review page"
3345
+ fields: [
3346
+ {
3347
+ id: "review.comment",
3348
+ type: FieldType.TEXTAREA,
3349
+ label: {
3350
+ defaultMessage: "Comment",
3351
+ id: "v2.event.birth.action.declare.form.review.comment.label",
3352
+ description: "Label for the comment field in the review section"
3353
+ }
2868
3354
  },
2869
- fields: [
2870
- {
2871
- id: "review.comment",
2872
- type: "TEXTAREA",
2873
- label: {
2874
- defaultMessage: "Comment",
2875
- id: "v2.event.birth.action.declare.form.review.comment.label",
2876
- description: "Label for the comment field in the review section"
2877
- }
3355
+ {
3356
+ type: FieldType.SIGNATURE,
3357
+ id: "review.signature",
3358
+ label: {
3359
+ defaultMessage: "Signature of informant",
3360
+ id: "v2.event.birth.action.declare.form.review.signature.label",
3361
+ description: "Label for the signature field in the review section"
2878
3362
  },
2879
- {
2880
- type: "SIGNATURE",
2881
- id: "review.signature",
2882
- label: {
2883
- defaultMessage: "Signature of informant",
2884
- id: "v2.event.birth.action.declare.form.review.signature.label",
2885
- description: "Label for the signature field in the review section"
2886
- },
2887
- signaturePromptLabel: {
2888
- id: "v2.signature.upload.modal.title",
2889
- defaultMessage: "Draw signature",
2890
- description: "Title for the modal to draw signature"
2891
- }
3363
+ signaturePromptLabel: {
3364
+ id: "v2.signature.upload.modal.title",
3365
+ defaultMessage: "Draw signature",
3366
+ description: "Title for the modal to draw signature"
2892
3367
  }
2893
- ]
3368
+ }
3369
+ ]
3370
+ };
3371
+ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3372
+ label: {
3373
+ id: "v2.event.tennis-club-membership.action.declare.form.label",
3374
+ defaultMessage: "Tennis club membership application",
3375
+ description: "This is what this form is referred as in the system"
2894
3376
  },
2895
3377
  pages: [
2896
3378
  {
@@ -2903,7 +3385,7 @@ var TENNIS_CLUB_FORM = defineForm({
2903
3385
  fields: [
2904
3386
  {
2905
3387
  id: "applicant.firstname",
2906
- type: "TEXT",
3388
+ type: FieldType.TEXT,
2907
3389
  required: true,
2908
3390
  conditionals: [],
2909
3391
  label: {
@@ -2914,7 +3396,7 @@ var TENNIS_CLUB_FORM = defineForm({
2914
3396
  },
2915
3397
  {
2916
3398
  id: "applicant.surname",
2917
- type: "TEXT",
3399
+ type: FieldType.TEXT,
2918
3400
  required: true,
2919
3401
  conditionals: [],
2920
3402
  label: {
@@ -2936,9 +3418,8 @@ var TENNIS_CLUB_FORM = defineForm({
2936
3418
  },
2937
3419
  {
2938
3420
  id: "applicant.dob",
2939
- type: "DATE",
3421
+ type: FieldType.DATE,
2940
3422
  required: true,
2941
- conditionals: [],
2942
3423
  validation: [
2943
3424
  {
2944
3425
  message: {
@@ -2949,15 +3430,53 @@ var TENNIS_CLUB_FORM = defineForm({
2949
3430
  validator: field("applicant.dob").isBefore().now()
2950
3431
  }
2951
3432
  ],
3433
+ conditionals: [
3434
+ {
3435
+ type: ConditionalType.SHOW,
3436
+ conditional: field("applicant.dobUnknown").isFalsy()
3437
+ }
3438
+ ],
2952
3439
  label: {
2953
3440
  defaultMessage: "Applicant's date of birth",
2954
3441
  description: "This is the label for the field",
2955
3442
  id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dob.label"
2956
3443
  }
2957
3444
  },
3445
+ {
3446
+ id: "applicant.dobUnknown",
3447
+ type: FieldType.CHECKBOX,
3448
+ required: false,
3449
+ label: {
3450
+ defaultMessage: "Exact date of birth unknown",
3451
+ description: "This is the label for the field",
3452
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dobUnknown.label"
3453
+ },
3454
+ conditionals: [
3455
+ {
3456
+ type: ConditionalType.DISPLAY_ON_REVIEW,
3457
+ conditional: never()
3458
+ }
3459
+ ]
3460
+ },
3461
+ {
3462
+ id: "applicant.age",
3463
+ type: FieldType.NUMBER,
3464
+ required: true,
3465
+ label: {
3466
+ defaultMessage: "Age of tennis-member",
3467
+ description: "This is the label for the field",
3468
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.age.label"
3469
+ },
3470
+ conditionals: [
3471
+ {
3472
+ type: ConditionalType.SHOW,
3473
+ conditional: field("applicant.dobUnknown").isEqualTo(true)
3474
+ }
3475
+ ]
3476
+ },
2958
3477
  {
2959
3478
  id: "applicant.image",
2960
- type: "FILE",
3479
+ type: FieldType.FILE,
2961
3480
  required: false,
2962
3481
  label: {
2963
3482
  defaultMessage: "Applicant's profile picture",
@@ -2978,6 +3497,27 @@ var TENNIS_CLUB_FORM = defineForm({
2978
3497
  }
2979
3498
  ]
2980
3499
  },
3500
+ {
3501
+ id: "senior-pass",
3502
+ conditional: field("applicant.dob").isBefore().date("1950-01-01"),
3503
+ title: {
3504
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.title",
3505
+ defaultMessage: "Assign senior pass for applicant",
3506
+ description: "This is the title of the section"
3507
+ },
3508
+ fields: [
3509
+ {
3510
+ id: "senior-pass.id",
3511
+ type: FieldType.TEXT,
3512
+ required: true,
3513
+ label: {
3514
+ defaultMessage: "Senior pass ID",
3515
+ description: "This is the label for the field",
3516
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.field.id.label"
3517
+ }
3518
+ }
3519
+ ]
3520
+ },
2981
3521
  {
2982
3522
  id: "recommender",
2983
3523
  title: {
@@ -2999,7 +3539,7 @@ var TENNIS_CLUB_FORM = defineForm({
2999
3539
  },
3000
3540
  {
3001
3541
  id: "recommender.firstname",
3002
- type: "TEXT",
3542
+ type: FieldType.TEXT,
3003
3543
  required: true,
3004
3544
  conditionals: [
3005
3545
  {
@@ -3015,7 +3555,7 @@ var TENNIS_CLUB_FORM = defineForm({
3015
3555
  },
3016
3556
  {
3017
3557
  id: "recommender.surname",
3018
- type: "TEXT",
3558
+ type: FieldType.TEXT,
3019
3559
  required: true,
3020
3560
  conditionals: [
3021
3561
  {
@@ -3031,7 +3571,7 @@ var TENNIS_CLUB_FORM = defineForm({
3031
3571
  },
3032
3572
  {
3033
3573
  id: "recommender.id",
3034
- type: "TEXT",
3574
+ type: FieldType.TEXT,
3035
3575
  required: true,
3036
3576
  conditionals: [
3037
3577
  {
@@ -3139,7 +3679,7 @@ var tennisClubMembershipEvent = defineConfig({
3139
3679
  description: "This is shown as the action name anywhere the user can trigger the action from",
3140
3680
  id: "event.tennis-club-membership.action.declare.label"
3141
3681
  },
3142
- forms: [TENNIS_CLUB_FORM]
3682
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3143
3683
  },
3144
3684
  {
3145
3685
  type: ActionType.VALIDATE,
@@ -3148,7 +3688,7 @@ var tennisClubMembershipEvent = defineConfig({
3148
3688
  description: "This is shown as the action name anywhere the user can trigger the action from",
3149
3689
  id: "event.tennis-club-membership.action.validate.label"
3150
3690
  },
3151
- forms: [TENNIS_CLUB_FORM]
3691
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3152
3692
  },
3153
3693
  {
3154
3694
  type: ActionType.REGISTER,
@@ -3157,7 +3697,7 @@ var tennisClubMembershipEvent = defineConfig({
3157
3697
  description: "This is shown as the action name anywhere the user can trigger the action from",
3158
3698
  id: "event.tennis-club-membership.action.register.label"
3159
3699
  },
3160
- forms: [TENNIS_CLUB_FORM]
3700
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3161
3701
  },
3162
3702
  {
3163
3703
  type: ActionType.REQUEST_CORRECTION,
@@ -3166,10 +3706,10 @@ var tennisClubMembershipEvent = defineConfig({
3166
3706
  description: "This is shown as the action name anywhere the user can trigger the action from",
3167
3707
  id: "event.tennis-club-membership.action.correction.request.label"
3168
3708
  },
3169
- forms: [TENNIS_CLUB_FORM],
3170
3709
  onboardingForm: [
3171
3710
  {
3172
3711
  id: "correction-requester",
3712
+ type: PageTypes.enum.FORM,
3173
3713
  title: {
3174
3714
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3175
3715
  defaultMessage: "Correction requester",
@@ -3233,6 +3773,7 @@ var tennisClubMembershipEvent = defineConfig({
3233
3773
  },
3234
3774
  {
3235
3775
  id: "identity-check",
3776
+ type: PageTypes.enum.FORM,
3236
3777
  title: {
3237
3778
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3238
3779
  defaultMessage: "Verify their identity",
@@ -3275,6 +3816,7 @@ var tennisClubMembershipEvent = defineConfig({
3275
3816
  additionalDetailsForm: [
3276
3817
  {
3277
3818
  id: "correction-request.supporting-documents",
3819
+ type: PageTypes.enum.FORM,
3278
3820
  title: {
3279
3821
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3280
3822
  defaultMessage: "Upload supporting documents",
@@ -3292,7 +3834,7 @@ var tennisClubMembershipEvent = defineConfig({
3292
3834
  },
3293
3835
  {
3294
3836
  id: "correction.supportingDocs",
3295
- type: "FILE",
3837
+ type: FieldType.FILE,
3296
3838
  label: {
3297
3839
  id: "correction.corrector.title",
3298
3840
  defaultMessage: "Upload supporting documents",
@@ -3336,6 +3878,7 @@ var tennisClubMembershipEvent = defineConfig({
3336
3878
  },
3337
3879
  {
3338
3880
  id: "correction-request.additional-details",
3881
+ type: PageTypes.enum.FORM,
3339
3882
  title: {
3340
3883
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3341
3884
  defaultMessage: "Reason for correction",
@@ -3344,7 +3887,7 @@ var tennisClubMembershipEvent = defineConfig({
3344
3887
  fields: [
3345
3888
  {
3346
3889
  id: "correction.request.reason",
3347
- type: "TEXT",
3890
+ type: FieldType.TEXT,
3348
3891
  label: {
3349
3892
  id: "correction.reason.title",
3350
3893
  defaultMessage: "Reason for correction?",
@@ -3357,7 +3900,6 @@ var tennisClubMembershipEvent = defineConfig({
3357
3900
  },
3358
3901
  {
3359
3902
  type: ActionType.APPROVE_CORRECTION,
3360
- forms: [TENNIS_CLUB_FORM],
3361
3903
  label: {
3362
3904
  defaultMessage: "Approve correction",
3363
3905
  description: "This is shown as the action name anywhere the user can trigger the action from",
@@ -3371,7 +3913,7 @@ var tennisClubMembershipEvent = defineConfig({
3371
3913
  defaultMessage: "Print certificate",
3372
3914
  description: "This is shown as the action name anywhere the user can trigger the action from"
3373
3915
  },
3374
- forms: [PRINT_CERTIFICATE_FORM],
3916
+ printForm: PRINT_CERTIFICATE_FORM,
3375
3917
  conditionals: [
3376
3918
  {
3377
3919
  type: "SHOW",
@@ -3411,6 +3953,22 @@ var tennisClubMembershipEvent = defineConfig({
3411
3953
  })
3412
3954
  }
3413
3955
  ]
3956
+ },
3957
+ {
3958
+ type: ActionType.ARCHIVE,
3959
+ label: {
3960
+ id: "v2.event.tennis-club-membership.action.archive.label",
3961
+ defaultMessage: "Archive",
3962
+ description: "This is shown as the action name anywhere the user can trigger the action from"
3963
+ }
3964
+ },
3965
+ {
3966
+ type: ActionType.REJECT,
3967
+ label: {
3968
+ id: "v2.event.tennis-club-membership.action.reject.label",
3969
+ defaultMessage: "Reject",
3970
+ description: "This is shown as the action name anywhere the user can trigger the action from"
3971
+ }
3414
3972
  }
3415
3973
  ],
3416
3974
  advancedSearch: [
@@ -3426,20 +3984,53 @@ var tennisClubMembershipEvent = defineConfig({
3426
3984
  }
3427
3985
  ]
3428
3986
  }
3429
- ]
3987
+ ],
3988
+ declaration: TENNIS_CLUB_DECLARATION_FORM
3430
3989
  });
3431
3990
 
3432
3991
  // ../commons/src/events/test.utils.ts
3433
- function generateActionInput(configuration, action) {
3434
- const fields = findActiveActionFormFields(configuration, action) ?? [];
3435
- const data = fields.reduce(
3992
+ function fieldConfigsToActionPayload(fields) {
3993
+ return fields.reduce(
3436
3994
  (acc, field2, i) => ({
3437
3995
  ...acc,
3438
3996
  [field2.id]: mapFieldTypeToMockValue(field2, i)
3439
3997
  }),
3440
3998
  {}
3441
3999
  );
3442
- return stripHiddenFields(fields, data);
4000
+ }
4001
+ function generateActionDeclarationInput(configuration, action) {
4002
+ const parsed = DeclarationUpdateActions.safeParse(action);
4003
+ if (parsed.success) {
4004
+ const fields = getDeclarationFields(configuration);
4005
+ const declarationConfig = getDeclaration(configuration);
4006
+ const declaration = fieldConfigsToActionPayload(fields);
4007
+ return omitHiddenPaginatedFields(declarationConfig, declaration);
4008
+ }
4009
+ console.warn(`${action} is not a declaration action. Setting data as {}.`);
4010
+ return {};
4011
+ }
4012
+ function generateActionAnnotationInput(configuration, action) {
4013
+ const actionConfig = configuration.actions.find(
4014
+ (ac) => ac.type === action
4015
+ );
4016
+ const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
4017
+ const annotation = fieldConfigsToActionPayload(annotationFields);
4018
+ const visibleVerificationPageIds = findRecordActionPages(
4019
+ configuration,
4020
+ action
4021
+ ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
4022
+ const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
4023
+ (acc, pageId) => ({
4024
+ ...acc,
4025
+ [pageId]: true
4026
+ }),
4027
+ {}
4028
+ );
4029
+ const fieldBasedPayload = omitHiddenFields(annotationFields, annotation);
4030
+ return {
4031
+ ...fieldBasedPayload,
4032
+ ...visiblePageVerificationMap
4033
+ };
3443
4034
  }
3444
4035
  var eventPayloadGenerator = {
3445
4036
  create: (input = {}) => ({
@@ -3451,21 +4042,22 @@ var eventPayloadGenerator = {
3451
4042
  type: input.type ?? "TENNIS_CLUB_MEMBERSHIP",
3452
4043
  id
3453
4044
  }),
3454
- draft: (eventId, input = {}) => (0, import_lodash2.merge)(
4045
+ draft: ({ eventId, actionType }, input = {}) => (0, import_lodash2.merge)(
3455
4046
  {
3456
4047
  id: getUUID(),
3457
4048
  eventId,
3458
4049
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3459
4050
  transactionId: getUUID(),
3460
4051
  action: {
3461
- type: ActionType.REQUEST_CORRECTION,
3462
- data: {
4052
+ type: actionType,
4053
+ status: ActionStatus.Accepted,
4054
+ declaration: {
3463
4055
  "applicant.firstname": "Max",
3464
4056
  "applicant.surname": "McLaren",
3465
4057
  "applicant.dob": "2020-01-02",
3466
4058
  "recommender.none": true
3467
4059
  },
3468
- metadata: {
4060
+ annotation: {
3469
4061
  "correction.requester.relationship": "ANOTHER_AGENT",
3470
4062
  "correction.request.reason": "Child's name was incorrect"
3471
4063
  },
@@ -3480,41 +4072,104 @@ var eventPayloadGenerator = {
3480
4072
  declare: (eventId, input = {}) => ({
3481
4073
  type: ActionType.DECLARE,
3482
4074
  transactionId: input.transactionId ?? getUUID(),
3483
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4075
+ declaration: input.declaration ?? generateActionDeclarationInput(
4076
+ tennisClubMembershipEvent,
4077
+ ActionType.DECLARE
4078
+ ),
4079
+ annotation: input.annotation ?? generateActionAnnotationInput(
4080
+ tennisClubMembershipEvent,
4081
+ ActionType.DECLARE
4082
+ ),
3484
4083
  eventId
3485
4084
  }),
4085
+ /**
4086
+ * Notify allows sending incomplete data. Think it as 'partial declare' for now.
4087
+ */
4088
+ notify: (eventId, input = {}) => {
4089
+ let declaration = input.declaration;
4090
+ if (!declaration) {
4091
+ const partialDeclaration = (0, import_lodash2.omitBy)(
4092
+ generateActionDeclarationInput(
4093
+ tennisClubMembershipEvent,
4094
+ ActionType.DECLARE
4095
+ ),
4096
+ import_lodash2.isString
4097
+ );
4098
+ declaration = partialDeclaration;
4099
+ }
4100
+ return {
4101
+ type: ActionType.NOTIFY,
4102
+ transactionId: input.transactionId ?? getUUID(),
4103
+ declaration,
4104
+ eventId
4105
+ };
4106
+ },
3486
4107
  validate: (eventId, input = {}) => ({
3487
4108
  type: ActionType.VALIDATE,
3488
4109
  transactionId: input.transactionId ?? getUUID(),
3489
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4110
+ declaration: input.declaration ?? generateActionDeclarationInput(
4111
+ tennisClubMembershipEvent,
4112
+ ActionType.VALIDATE
4113
+ ),
4114
+ annotation: input.annotation ?? generateActionAnnotationInput(
4115
+ tennisClubMembershipEvent,
4116
+ ActionType.VALIDATE
4117
+ ),
3490
4118
  duplicates: [],
3491
4119
  eventId
3492
4120
  }),
4121
+ assign: (eventId, input = {}) => ({
4122
+ type: ActionType.ASSIGN,
4123
+ transactionId: input.transactionId ?? getUUID(),
4124
+ declaration: {},
4125
+ assignedTo: input.assignedTo ?? getUUID(),
4126
+ eventId
4127
+ }),
4128
+ unassign: (eventId, input = {}) => ({
4129
+ type: ActionType.UNASSIGN,
4130
+ transactionId: input.transactionId ?? getUUID(),
4131
+ declaration: {},
4132
+ assignedTo: null,
4133
+ eventId
4134
+ }),
3493
4135
  archive: (eventId, input = {}, isDuplicate) => ({
3494
- type: ActionType.ARCHIVED,
4136
+ type: ActionType.ARCHIVE,
3495
4137
  transactionId: input.transactionId ?? getUUID(),
3496
- data: input.data ?? {},
3497
- metadata: { isDuplicate: isDuplicate ?? false },
4138
+ declaration: {},
4139
+ // @TODO: Check whether generator is needed?
4140
+ annotation: { isDuplicate: isDuplicate ?? false },
3498
4141
  duplicates: [],
3499
4142
  eventId
3500
4143
  }),
3501
4144
  reject: (eventId, input = {}) => ({
3502
4145
  type: ActionType.REJECT,
3503
4146
  transactionId: input.transactionId ?? getUUID(),
3504
- data: input.data ?? {},
4147
+ declaration: {},
4148
+ annotation: input.annotation ?? generateActionAnnotationInput(
4149
+ tennisClubMembershipEvent,
4150
+ ActionType.REJECT
4151
+ ),
3505
4152
  duplicates: [],
3506
4153
  eventId
3507
4154
  }),
3508
4155
  register: (eventId, input = {}) => ({
3509
4156
  type: ActionType.REGISTER,
3510
4157
  transactionId: input.transactionId ?? getUUID(),
3511
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4158
+ declaration: input.declaration ?? generateActionDeclarationInput(
4159
+ tennisClubMembershipEvent,
4160
+ ActionType.REGISTER
4161
+ ),
4162
+ annotation: input.annotation ?? generateActionAnnotationInput(
4163
+ tennisClubMembershipEvent,
4164
+ ActionType.REGISTER
4165
+ ),
3512
4166
  eventId
3513
4167
  }),
3514
4168
  printCertificate: (eventId, input = {}) => ({
3515
4169
  type: ActionType.PRINT_CERTIFICATE,
3516
4170
  transactionId: input.transactionId ?? getUUID(),
3517
- data: input.data ?? generateActionInput(
4171
+ declaration: {},
4172
+ annotation: input.annotation ?? generateActionAnnotationInput(
3518
4173
  tennisClubMembershipEvent,
3519
4174
  ActionType.PRINT_CERTIFICATE
3520
4175
  ),
@@ -3524,17 +4179,21 @@ var eventPayloadGenerator = {
3524
4179
  request: (eventId, input = {}) => ({
3525
4180
  type: ActionType.REQUEST_CORRECTION,
3526
4181
  transactionId: input.transactionId ?? getUUID(),
3527
- data: input.data ?? generateActionInput(
4182
+ declaration: input.declaration ?? generateActionDeclarationInput(
4183
+ tennisClubMembershipEvent,
4184
+ ActionType.REQUEST_CORRECTION
4185
+ ),
4186
+ annotation: input.annotation ?? generateActionAnnotationInput(
3528
4187
  tennisClubMembershipEvent,
3529
4188
  ActionType.REQUEST_CORRECTION
3530
4189
  ),
3531
- metadata: {},
3532
4190
  eventId
3533
4191
  }),
3534
4192
  approve: (eventId, requestId, input = {}) => ({
3535
4193
  type: ActionType.APPROVE_CORRECTION,
3536
4194
  transactionId: input.transactionId ?? getUUID(),
3537
- data: input.data ?? generateActionInput(
4195
+ declaration: {},
4196
+ annotation: input.annotation ?? generateActionAnnotationInput(
3538
4197
  tennisClubMembershipEvent,
3539
4198
  ActionType.APPROVE_CORRECTION
3540
4199
  ),
@@ -3544,7 +4203,8 @@ var eventPayloadGenerator = {
3544
4203
  reject: (eventId, requestId, input = {}) => ({
3545
4204
  type: ActionType.REJECT_CORRECTION,
3546
4205
  transactionId: input.transactionId ?? getUUID(),
3547
- data: input.data ?? generateActionInput(
4206
+ declaration: {},
4207
+ annotation: input.annotation ?? generateActionAnnotationInput(
3548
4208
  tennisClubMembershipEvent,
3549
4209
  ActionType.REJECT_CORRECTION
3550
4210
  ),
@@ -3560,24 +4220,31 @@ function generateActionDocument({
3560
4220
  defaults = {}
3561
4221
  }) {
3562
4222
  const actionBase = {
3563
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4223
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4224
+ // @TODO: This should be fixed in the future.
4225
+ createdAt: new Date(Date.now() - 500).toISOString(),
3564
4226
  createdBy: getUUID(),
3565
4227
  id: getUUID(),
3566
4228
  createdAtLocation: "TODO",
3567
- data: generateActionInput(configuration, action),
3568
- metadata: {},
3569
- ...defaults
4229
+ declaration: generateActionDeclarationInput(configuration, action),
4230
+ annotation: {},
4231
+ ...defaults,
4232
+ status: ActionStatus.Accepted
3570
4233
  };
3571
4234
  switch (action) {
4235
+ case ActionType.READ:
4236
+ return { ...actionBase, type: action };
4237
+ case ActionType.MARKED_AS_DUPLICATE:
4238
+ return { ...actionBase, type: action };
3572
4239
  case ActionType.DECLARE:
3573
4240
  return { ...actionBase, type: action };
3574
4241
  case ActionType.UNASSIGN:
3575
- return { ...actionBase, type: action };
4242
+ return { ...actionBase, type: action, assignedTo: null };
3576
4243
  case ActionType.ASSIGN:
3577
4244
  return { ...actionBase, assignedTo: getUUID(), type: action };
3578
4245
  case ActionType.VALIDATE:
3579
4246
  return { ...actionBase, type: action };
3580
- case ActionType.ARCHIVED:
4247
+ case ActionType.ARCHIVE:
3581
4248
  return { ...actionBase, type: action };
3582
4249
  case ActionType.REJECT:
3583
4250
  return { ...actionBase, type: action };
@@ -3593,14 +4260,13 @@ function generateActionDocument({
3593
4260
  return { ...actionBase, requestId: getUUID(), type: action };
3594
4261
  case ActionType.REJECT_CORRECTION:
3595
4262
  return { ...actionBase, requestId: getUUID(), type: action };
3596
- case ActionType.CUSTOM:
3597
- return { ...actionBase, type: action };
3598
4263
  case ActionType.REGISTER:
3599
4264
  return {
3600
4265
  ...actionBase,
3601
- type: action,
3602
- identifiers: { trackingId: getUUID(), registrationNumber: getUUID() }
4266
+ type: action
3603
4267
  };
4268
+ case ActionType.DELETE:
4269
+ case ActionType.DETECT_DUPLICATE:
3604
4270
  default:
3605
4271
  throw new Error(`Unsupported action type: ${action}`);
3606
4272
  }
@@ -3615,12 +4281,16 @@ function generateEventDocument({
3615
4281
  actions: actions.map(
3616
4282
  (action) => generateActionDocument({ configuration, action })
3617
4283
  ),
3618
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4284
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4285
+ // @TODO: This should be fixed in the future.
4286
+ createdAt: new Date(Date.now() - 1e3).toISOString(),
3619
4287
  id: getUUID(),
3620
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
4288
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4289
+ // @TODO: This should be fixed in the future.
4290
+ updatedAt: new Date(Date.now() - 1e3).toISOString()
3621
4291
  };
3622
4292
  }
3623
- function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, data = {}) {
4293
+ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
3624
4294
  const action = generateActionDocument({
3625
4295
  configuration: tennisClubMembershipEvent,
3626
4296
  action: actionType
@@ -3630,9 +4300,9 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, da
3630
4300
  transactionId: getUUID(),
3631
4301
  action: {
3632
4302
  ...action,
3633
- data: {
3634
- ...action.data,
3635
- ...data
4303
+ declaration: {
4304
+ ...action.declaration,
4305
+ ...declaration
3636
4306
  }
3637
4307
  },
3638
4308
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3649,7 +4319,7 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3649
4319
  modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3650
4320
  assignedTo: overrides.assignedTo ?? null,
3651
4321
  updatedBy: overrides.updatedBy ?? getUUID(),
3652
- data: overrides.data ?? {
4322
+ declaration: overrides.declaration ?? {
3653
4323
  "recommender.none": true,
3654
4324
  "applicant.firstname": "Danny",
3655
4325
  "applicant.surname": "Doe",
@@ -3657,3 +4327,40 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3657
4327
  },
3658
4328
  trackingId: overrides.trackingId ?? "M3F8YQ"
3659
4329
  });
4330
+ var generateTranslationConfig = (message) => ({
4331
+ defaultMessage: message,
4332
+ description: "Description for ${message}",
4333
+ id: message
4334
+ });
4335
+
4336
+ // ../commons/src/events/TemplateConfig.ts
4337
+ function isTemplateVariable(value) {
4338
+ return typeof value === "string" && value.startsWith("$");
4339
+ }
4340
+ function isFieldValue(value) {
4341
+ return FieldValue.safeParse(value).success;
4342
+ }
4343
+ function isFieldValueWithoutTemplates(value) {
4344
+ if (isTemplateVariable(value)) {
4345
+ return false;
4346
+ }
4347
+ if (typeof value === "object" && Object.values(value).some((val) => isTemplateVariable(val))) {
4348
+ return false;
4349
+ }
4350
+ return true;
4351
+ }
4352
+ function isFieldConfigDefaultValue(value) {
4353
+ if (!value) {
4354
+ return false;
4355
+ }
4356
+ if (isFieldValue(value)) {
4357
+ return true;
4358
+ }
4359
+ if (isTemplateVariable(value)) {
4360
+ return true;
4361
+ }
4362
+ if (typeof value === "object" && Object.values(value).every((v) => typeof v === "object" && v !== null)) {
4363
+ return Object.values(value).every((v) => isFieldConfigDefaultValue(v));
4364
+ }
4365
+ return false;
4366
+ }