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

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