@opencrvs/toolkit 1.8.0-rc.ff2e7b6 → 1.8.0-rc.ff62f9e

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.
@@ -40,6 +40,7 @@ __export(events_exports, {
40
40
  ActionUpdate: () => ActionUpdate,
41
41
  AddressFieldUpdateValue: () => AddressFieldUpdateValue,
42
42
  AddressFieldValue: () => AddressFieldValue,
43
+ AddressType: () => AddressType,
43
44
  AdministrativeAreas: () => AdministrativeAreas,
44
45
  AdvancedSearchConfig: () => AdvancedSearchConfig,
45
46
  ApproveCorrectionActionInput: () => ApproveCorrectionActionInput,
@@ -51,6 +52,7 @@ __export(events_exports, {
51
52
  Clause: () => Clause,
52
53
  Conditional: () => Conditional,
53
54
  ConditionalType: () => ConditionalType,
55
+ DataFieldValue: () => DataFieldValue,
54
56
  DateValue: () => DateValue,
55
57
  DeclareActionInput: () => DeclareActionInput,
56
58
  DeduplicationConfig: () => DeduplicationConfig,
@@ -76,12 +78,20 @@ __export(events_exports, {
76
78
  FileFieldWithOptionValue: () => FileFieldWithOptionValue,
77
79
  FormConfig: () => FormConfig,
78
80
  FormPage: () => FormPage,
81
+ FormPageConfig: () => FormPageConfig,
82
+ FormPageType: () => FormPageType,
83
+ GenericAddressUpdateValue: () => GenericAddressUpdateValue,
84
+ GenericAddressValue: () => GenericAddressValue,
79
85
  GeographicalArea: () => GeographicalArea,
86
+ ImageMimeType: () => ImageMimeType,
80
87
  LanguageConfig: () => LanguageConfig,
88
+ LatentActions: () => LatentActions,
81
89
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
90
+ MimeType: () => MimeType,
82
91
  NotifyActionInput: () => NotifyActionInput,
83
92
  NumberFieldValue: () => NumberFieldValue,
84
93
  PrintCertificateActionInput: () => PrintCertificateActionInput,
94
+ ReadActionInput: () => ReadActionInput,
85
95
  RegisterActionInput: () => RegisterActionInput,
86
96
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
87
97
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
@@ -97,17 +107,21 @@ __export(events_exports, {
97
107
  UrbanAddressUpdateValue: () => UrbanAddressUpdateValue,
98
108
  UrbanAddressValue: () => UrbanAddressValue,
99
109
  ValidateActionInput: () => ValidateActionInput,
110
+ VerificationPage: () => VerificationPage,
111
+ VerificationPageConfig: () => VerificationPageConfig,
100
112
  WorkqueueConfig: () => WorkqueueConfig,
101
113
  alwaysTrue: () => alwaysTrue,
102
114
  and: () => and,
103
115
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
104
116
  compositeFieldTypes: () => compositeFieldTypes,
117
+ createEmptyDraft: () => createEmptyDraft,
105
118
  createValidationSchema: () => createValidationSchema,
106
119
  deepDropNulls: () => deepDropNulls,
107
120
  defineConditional: () => defineConditional,
108
121
  defineConfig: () => defineConfig,
109
122
  defineForm: () => defineForm,
110
123
  defineFormPage: () => defineFormPage,
124
+ errorMessages: () => errorMessages,
111
125
  event: () => event,
112
126
  eventMetadataLabelMap: () => eventMetadataLabelMap,
113
127
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -119,13 +133,16 @@ __export(events_exports, {
119
133
  findActiveActionForm: () => findActiveActionForm,
120
134
  findActiveActionFormFields: () => findActiveActionFormFields,
121
135
  findActiveActionFormPages: () => findActiveActionFormPages,
136
+ findActiveDrafts: () => findActiveDrafts,
122
137
  findInputPageFields: () => findInputPageFields,
123
138
  findPageFields: () => findPageFields,
124
139
  generateActionDocument: () => generateActionDocument,
125
140
  generateActionInput: () => generateActionInput,
141
+ generateActionMetadataInput: () => generateActionMetadataInput,
126
142
  generateEventDocument: () => generateEventDocument,
127
143
  generateEventDraftDocument: () => generateEventDraftDocument,
128
144
  generateTransactionId: () => generateTransactionId,
145
+ generateTranslationConfig: () => generateTranslationConfig,
129
146
  getActiveActionFields: () => getActiveActionFields,
130
147
  getActiveActionFormPages: () => getActiveActionFormPages,
131
148
  getAllFields: () => getAllFields,
@@ -136,11 +153,13 @@ __export(events_exports, {
136
153
  getFieldValidationErrors: () => getFieldValidationErrors,
137
154
  getFormFields: () => getFormFields,
138
155
  getMetadataForAction: () => getMetadataForAction,
156
+ getVisiblePagesFormFields: () => getVisiblePagesFormFields,
139
157
  isAddressFieldType: () => isAddressFieldType,
140
158
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
141
159
  isBulletListFieldType: () => isBulletListFieldType,
142
160
  isCheckboxFieldType: () => isCheckboxFieldType,
143
161
  isCountryFieldType: () => isCountryFieldType,
162
+ isDataFieldType: () => isDataFieldType,
144
163
  isDateFieldType: () => isDateFieldType,
145
164
  isDividerFieldType: () => isDividerFieldType,
146
165
  isEmailFieldType: () => isEmailFieldType,
@@ -156,6 +175,7 @@ __export(events_exports, {
156
175
  isNumberFieldType: () => isNumberFieldType,
157
176
  isOfficeFieldType: () => isOfficeFieldType,
158
177
  isPageHeaderFieldType: () => isPageHeaderFieldType,
178
+ isPageVisible: () => isPageVisible,
159
179
  isParagraphFieldType: () => isParagraphFieldType,
160
180
  isRadioGroupFieldType: () => isRadioGroupFieldType,
161
181
  isSelectFieldType: () => isSelectFieldType,
@@ -164,6 +184,8 @@ __export(events_exports, {
164
184
  isTextAreaFieldType: () => isTextAreaFieldType,
165
185
  isTextFieldType: () => isTextFieldType,
166
186
  isUndeclaredDraft: () => isUndeclaredDraft,
187
+ isVerificationPage: () => isVerificationPage,
188
+ mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
167
189
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
168
190
  mapFieldTypeToZod: () => mapFieldTypeToZod,
169
191
  not: () => not,
@@ -247,7 +269,8 @@ var FieldType = {
247
269
  ADMINISTRATIVE_AREA: "ADMINISTRATIVE_AREA",
248
270
  FACILITY: "FACILITY",
249
271
  OFFICE: "OFFICE",
250
- SIGNATURE: "SIGNATURE"
272
+ SIGNATURE: "SIGNATURE",
273
+ DATA: "DATA"
251
274
  };
252
275
  var fieldTypes = Object.values(FieldType);
253
276
  var compositeFieldTypes = [
@@ -265,6 +288,10 @@ var GeographicalArea = {
265
288
  URBAN: "URBAN",
266
289
  RURAL: "RURAL"
267
290
  };
291
+ var AddressType = {
292
+ DOMESTIC: "DOMESTIC",
293
+ INTERNATIONAL: "INTERNATIONAL"
294
+ };
268
295
  var FileFieldValue = import_zod3.z.object({
269
296
  filename: import_zod3.z.string(),
270
297
  originalFilename: import_zod3.z.string(),
@@ -272,6 +299,7 @@ var FileFieldValue = import_zod3.z.object({
272
299
  });
273
300
  var AdminStructure = import_zod3.z.object({
274
301
  country: import_zod3.z.string(),
302
+ addressType: import_zod3.z.literal(AddressType.DOMESTIC),
275
303
  province: import_zod3.z.string(),
276
304
  district: import_zod3.z.string()
277
305
  });
@@ -299,14 +327,33 @@ var RuralAddressUpdateValue = AdminStructure.extend({
299
327
  urbanOrRural: import_zod3.z.literal(GeographicalArea.RURAL),
300
328
  village: import_zod3.z.string().nullish()
301
329
  });
302
- var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
303
- UrbanAddressValue,
304
- RuralAddressValue
305
- ]);
330
+ var GenericAddressValue = import_zod3.z.object({
331
+ country: import_zod3.z.string(),
332
+ addressType: import_zod3.z.literal(AddressType.INTERNATIONAL),
333
+ state: import_zod3.z.string(),
334
+ district2: import_zod3.z.string(),
335
+ cityOrTown: import_zod3.z.string().optional(),
336
+ addressLine1: import_zod3.z.string().optional(),
337
+ addressLine2: import_zod3.z.string().optional(),
338
+ addressLine3: import_zod3.z.string().optional(),
339
+ postcodeOrZip: import_zod3.z.string().optional()
340
+ });
341
+ var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [UrbanAddressValue, RuralAddressValue]).or(GenericAddressValue);
342
+ var GenericAddressUpdateValue = import_zod3.z.object({
343
+ country: import_zod3.z.string(),
344
+ addressType: import_zod3.z.literal(AddressType.INTERNATIONAL),
345
+ state: import_zod3.z.string(),
346
+ district2: import_zod3.z.string(),
347
+ cityOrTown: import_zod3.z.string().nullish(),
348
+ addressLine1: import_zod3.z.string().nullish(),
349
+ addressLine2: import_zod3.z.string().nullish(),
350
+ addressLine3: import_zod3.z.string().nullish(),
351
+ postcodeOrZip: import_zod3.z.string().nullish()
352
+ });
306
353
  var AddressFieldUpdateValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
307
354
  UrbanAddressUpdateValue,
308
355
  RuralAddressUpdateValue
309
- ]);
356
+ ]).or(GenericAddressUpdateValue);
310
357
  var FileFieldValueWithOption = import_zod3.z.object({
311
358
  filename: import_zod3.z.string(),
312
359
  originalFilename: import_zod3.z.string(),
@@ -322,6 +369,7 @@ var DateValue = import_zod4.z.string().date().describe("Date in the format YYYY-
322
369
  var EmailValue = import_zod4.z.string().email();
323
370
  var CheckboxFieldValue = import_zod4.z.boolean();
324
371
  var NumberFieldValue = import_zod4.z.number();
372
+ var DataFieldValue = import_zod4.z.undefined();
325
373
  var FieldValue = import_zod4.z.union([
326
374
  TextValue,
327
375
  DateValue,
@@ -330,7 +378,9 @@ var FieldValue = import_zod4.z.union([
330
378
  FileFieldValue,
331
379
  FileFieldWithOptionValue,
332
380
  UrbanAddressValue,
333
- RuralAddressValue
381
+ RuralAddressValue,
382
+ DataFieldValue,
383
+ GenericAddressValue
334
384
  ]);
335
385
  var FieldUpdateValue = import_zod4.z.union([
336
386
  TextValue,
@@ -340,7 +390,9 @@ var FieldUpdateValue = import_zod4.z.union([
340
390
  FileFieldValue,
341
391
  FileFieldWithOptionValue,
342
392
  UrbanAddressUpdateValue,
343
- RuralAddressUpdateValue
393
+ RuralAddressUpdateValue,
394
+ DataFieldValue,
395
+ GenericAddressUpdateValue
344
396
  ]);
345
397
 
346
398
  // ../commons/src/events/FieldConfig.ts
@@ -411,15 +463,25 @@ var TextAreaField = BaseField.extend({
411
463
  postfix: TranslationConfig.optional()
412
464
  }).default({ rows: 4 }).optional()
413
465
  }).describe("Multiline text input");
466
+ var ImageMimeType = import_zod5.z.enum([
467
+ "image/png",
468
+ "image/jpg",
469
+ "image/jpeg",
470
+ "image/svg+xml"
471
+ ]);
472
+ var MimeType = ImageMimeType;
473
+ var DEFAULT_MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
414
474
  var SignatureField = BaseField.extend({
415
475
  type: import_zod5.z.literal(FieldType.SIGNATURE),
416
476
  signaturePromptLabel: TranslationConfig.describe(
417
477
  "Title of the signature modal"
418
478
  ),
419
479
  configuration: import_zod5.z.object({
420
- maxSizeMb: import_zod5.z.number().optional().describe("Maximum file size in MB"),
421
- allowedFileFormats: import_zod5.z.array(import_zod5.z.string()).optional().describe("List of allowed file formats for the signature")
422
- }).default({}).optional()
480
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
481
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
482
+ }).default({
483
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
484
+ })
423
485
  }).describe("Signature input field");
424
486
  var EmailField = BaseField.extend({
425
487
  type: import_zod5.z.literal(FieldType.EMAIL),
@@ -462,13 +524,17 @@ var PageHeader = BaseField.extend({
462
524
  }).describe("A read-only header component for form pages");
463
525
  var File = BaseField.extend({
464
526
  type: import_zod5.z.literal(FieldType.FILE),
465
- options: import_zod5.z.object({
527
+ configuration: import_zod5.z.object({
528
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
529
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
466
530
  style: import_zod5.z.object({
467
- fullWidth: import_zod5.z.boolean().describe(
531
+ width: import_zod5.z.enum(["full", "auto"]).optional().describe(
468
532
  "Whether the file upload button should take the full width of the container or not"
469
533
  )
470
- })
471
- }).optional()
534
+ }).optional()
535
+ }).default({
536
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
537
+ })
472
538
  }).describe("File upload");
473
539
  var SelectOption = import_zod5.z.object({
474
540
  value: import_zod5.z.string().describe("The value of the option"),
@@ -529,8 +595,14 @@ var Location = BaseField.extend({
529
595
  }).describe("Input field for a location");
530
596
  var FileUploadWithOptions = BaseField.extend({
531
597
  type: import_zod5.z.literal(FieldType.FILE_WITH_OPTIONS),
532
- options: import_zod5.z.array(SelectOption).describe("A list of options")
533
- }).describe("Select input");
598
+ options: import_zod5.z.array(SelectOption).describe("A list of options"),
599
+ configuration: import_zod5.z.object({
600
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
601
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
602
+ }).default({
603
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
604
+ })
605
+ });
534
606
  var Facility = BaseField.extend({
535
607
  type: import_zod5.z.literal(FieldType.FACILITY),
536
608
  defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
@@ -543,6 +615,13 @@ var Address = BaseField.extend({
543
615
  type: import_zod5.z.literal(FieldType.ADDRESS),
544
616
  defaultValue: AddressFieldValue.optional()
545
617
  }).describe("Address input field \u2013 a combination of location and text fields");
618
+ var DataField = BaseField.extend({
619
+ type: import_zod5.z.literal(FieldType.DATA),
620
+ configuration: import_zod5.z.object({
621
+ subtitle: TranslationConfig.optional(),
622
+ data: import_zod5.z.array(import_zod5.z.object({ fieldId: import_zod5.z.string() }))
623
+ })
624
+ }).describe("Data field for displaying read-only data");
546
625
  var FieldConfig = import_zod5.z.discriminatedUnion("type", [
547
626
  Address,
548
627
  TextField,
@@ -564,15 +643,46 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
564
643
  Office,
565
644
  SignatureField,
566
645
  EmailField,
567
- FileUploadWithOptions
646
+ FileUploadWithOptions,
647
+ DataField
568
648
  ]);
569
649
 
570
650
  // ../commons/src/events/FormConfig.ts
651
+ var FormPageType = {
652
+ FORM: "FORM",
653
+ VERIFICATION: "VERIFICATION"
654
+ };
571
655
  var FormPage = import_zod6.z.object({
572
656
  id: import_zod6.z.string().describe("Unique identifier for the page"),
657
+ type: import_zod6.z.literal(FormPageType.FORM).default(FormPageType.FORM),
573
658
  title: TranslationConfig.describe("Header title of the page"),
574
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page")
659
+ fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page"),
660
+ conditional: Conditional().optional().describe(
661
+ "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
662
+ )
575
663
  });
664
+ var VerificationPageConfig = import_zod6.z.object({
665
+ verify: import_zod6.z.object({ label: TranslationConfig }),
666
+ cancel: import_zod6.z.object({
667
+ label: TranslationConfig,
668
+ confirmation: import_zod6.z.object({
669
+ title: TranslationConfig,
670
+ body: TranslationConfig
671
+ })
672
+ })
673
+ }).describe("Actions available on the verification page");
674
+ var VerificationPage = FormPage.extend({
675
+ type: import_zod6.z.literal(FormPageType.VERIFICATION),
676
+ actions: VerificationPageConfig
677
+ });
678
+ var FormPageConfig = import_zod6.z.preprocess(
679
+ (pageConfig) => ({
680
+ ...pageConfig,
681
+ type: pageConfig.type ?? FormPageType.FORM
682
+ // Default type to "FORM" if not provided
683
+ }),
684
+ import_zod6.z.discriminatedUnion("type", [FormPage, VerificationPage])
685
+ );
576
686
  var FormConfig = import_zod6.z.object({
577
687
  label: TranslationConfig.describe("Human readable description of the form"),
578
688
  version: import_zod6.z.object({
@@ -584,7 +694,7 @@ var FormConfig = import_zod6.z.object({
584
694
  )
585
695
  }),
586
696
  active: import_zod6.z.boolean().default(false).describe("Whether the form is active"),
587
- pages: import_zod6.z.array(FormPage),
697
+ pages: import_zod6.z.array(FormPageConfig),
588
698
  review: import_zod6.z.object({
589
699
  title: TranslationConfig.describe(
590
700
  "Title of the form to show in review page"
@@ -611,8 +721,10 @@ var ActionType = {
611
721
  CUSTOM: "CUSTOM",
612
722
  REJECT: "REJECT",
613
723
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
614
- ARCHIVE: "ARCHIVE"
724
+ ARCHIVE: "ARCHIVE",
725
+ READ: "READ"
615
726
  };
727
+ var LatentActions = [ActionType.ARCHIVE, ActionType.REJECT];
616
728
 
617
729
  // ../commons/src/events/ActionConfig.ts
618
730
  var ActionConditional2 = import_zod7.z.discriminatedUnion("type", [
@@ -639,23 +751,17 @@ var ValidateConfig = ActionConfigBase.merge(
639
751
  );
640
752
  var RejectDeclarationConfig = ActionConfigBase.merge(
641
753
  import_zod7.z.object({
642
- type: import_zod7.z.literal(ActionType.REJECT),
643
- comment: import_zod7.z.string(),
644
- isDuplicate: import_zod7.z.boolean()
754
+ type: import_zod7.z.literal(ActionType.REJECT)
645
755
  })
646
756
  );
647
757
  var MarkedAsDuplicateConfig = ActionConfigBase.merge(
648
758
  import_zod7.z.object({
649
- type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE),
650
- comment: import_zod7.z.string(),
651
- duplicates: import_zod7.z.array(import_zod7.z.string()).describe("UUIDs of duplicate records")
759
+ type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE)
652
760
  })
653
761
  );
654
762
  var ArchiveConfig = ActionConfigBase.merge(
655
763
  import_zod7.z.object({
656
- type: import_zod7.z.literal(ActionType.ARCHIVE),
657
- comment: import_zod7.z.string(),
658
- isDuplicate: import_zod7.z.boolean()
764
+ type: import_zod7.z.literal(ActionType.ARCHIVE)
659
765
  })
660
766
  );
661
767
  var RegisterConfig = ActionConfigBase.merge(
@@ -676,8 +782,8 @@ var PrintCertificateActionConfig = ActionConfigBase.merge(
676
782
  var RequestCorrectionConfig = ActionConfigBase.merge(
677
783
  import_zod7.z.object({
678
784
  type: import_zod7.z.literal(ActionType.REQUEST_CORRECTION),
679
- onboardingForm: import_zod7.z.array(FormPage),
680
- additionalDetailsForm: import_zod7.z.array(FormPage)
785
+ onboardingForm: import_zod7.z.array(FormPageConfig),
786
+ additionalDetailsForm: import_zod7.z.array(FormPageConfig)
681
787
  })
682
788
  );
683
789
  var RejectCorrectionConfig = ActionConfigBase.merge(
@@ -1119,6 +1225,9 @@ function mapFieldTypeToZod(type, required) {
1119
1225
  case FieldType.ADDRESS:
1120
1226
  schema = AddressFieldUpdateValue;
1121
1227
  break;
1228
+ case FieldType.DATA:
1229
+ schema = DataFieldValue;
1230
+ break;
1122
1231
  }
1123
1232
  return required ? schema : schema.nullish();
1124
1233
  }
@@ -1153,6 +1262,7 @@ function mapFieldTypeToMockValue(field2, i) {
1153
1262
  case FieldType.ADDRESS:
1154
1263
  return {
1155
1264
  country: "FAR",
1265
+ addressType: AddressType.DOMESTIC,
1156
1266
  province: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
1157
1267
  district: "5ef450bc-712d-48ad-93f3-8da0fa453baa",
1158
1268
  urbanOrRural: "URBAN",
@@ -1174,6 +1284,54 @@ function mapFieldTypeToMockValue(field2, i) {
1174
1284
  };
1175
1285
  case FieldType.FILE_WITH_OPTIONS:
1176
1286
  return null;
1287
+ case FieldType.DATA:
1288
+ return {};
1289
+ }
1290
+ }
1291
+ function mapFieldTypeToEmptyValue(field2) {
1292
+ switch (field2.type) {
1293
+ case FieldType.DIVIDER:
1294
+ case FieldType.TEXT:
1295
+ case FieldType.TEXTAREA:
1296
+ case FieldType.BULLET_LIST:
1297
+ case FieldType.PAGE_HEADER:
1298
+ case FieldType.LOCATION:
1299
+ case FieldType.SELECT:
1300
+ case FieldType.COUNTRY:
1301
+ case FieldType.RADIO_GROUP:
1302
+ case FieldType.SIGNATURE:
1303
+ case FieldType.PARAGRAPH:
1304
+ case FieldType.ADMINISTRATIVE_AREA:
1305
+ case FieldType.FACILITY:
1306
+ case FieldType.OFFICE:
1307
+ case FieldType.NUMBER:
1308
+ case FieldType.EMAIL:
1309
+ case FieldType.DATE:
1310
+ case FieldType.CHECKBOX:
1311
+ case FieldType.DATA:
1312
+ return null;
1313
+ case FieldType.ADDRESS:
1314
+ return {
1315
+ country: null,
1316
+ addressType: AddressType.DOMESTIC,
1317
+ province: null,
1318
+ district: null,
1319
+ urbanOrRural: "URBAN",
1320
+ // Default to urban needed for validation
1321
+ town: null,
1322
+ residentialArea: null,
1323
+ street: null,
1324
+ number: null,
1325
+ zipCode: null
1326
+ };
1327
+ case FieldType.FILE:
1328
+ return {
1329
+ filename: "",
1330
+ originalFilename: "",
1331
+ type: ""
1332
+ };
1333
+ case FieldType.FILE_WITH_OPTIONS:
1334
+ return [];
1177
1335
  }
1178
1336
  }
1179
1337
  var isParagraphFieldType = (field2) => {
@@ -1239,6 +1397,9 @@ var isFacilityFieldType = (field2) => {
1239
1397
  var isOfficeFieldType = (field2) => {
1240
1398
  return field2.config.type === FieldType.OFFICE;
1241
1399
  };
1400
+ var isDataFieldType = (field2) => {
1401
+ return field2.config.type === FieldType.DATA;
1402
+ };
1242
1403
 
1243
1404
  // ../commons/src/conditionals/validate.ts
1244
1405
  var ajv = new import_ajv.default({
@@ -1275,49 +1436,76 @@ function isFieldVisible(field2, form) {
1275
1436
  function isFieldEnabled(field2, form) {
1276
1437
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1277
1438
  }
1439
+ var errorMessages = {
1440
+ hiddenField: {
1441
+ id: "v2.error.hidden",
1442
+ defaultMessage: "Hidden or disabled field should not receive a value",
1443
+ description: "Error message when field is hidden or disabled, but a value was received"
1444
+ },
1445
+ invalidDate: {
1446
+ defaultMessage: "Invalid date field",
1447
+ description: "Error message when date field is invalid",
1448
+ id: "v2.error.invalidDate"
1449
+ },
1450
+ invalidEmail: {
1451
+ defaultMessage: "Invalid email address",
1452
+ description: "Error message when email address is invalid",
1453
+ id: "v2.error.invalidEmail"
1454
+ },
1455
+ requiredField: {
1456
+ defaultMessage: "Required for registration",
1457
+ description: "Error message when required field is missing",
1458
+ id: "v2.error.required"
1459
+ },
1460
+ invalidInput: {
1461
+ defaultMessage: "Invalid input",
1462
+ description: "Error message when generic field is invalid",
1463
+ id: "v2.error.invalid"
1464
+ }
1465
+ };
1466
+ var createIntlError = (message) => ({
1467
+ message: {
1468
+ message
1469
+ }
1470
+ });
1278
1471
  var zodToIntlErrorMap = (issue, _ctx) => {
1279
- if (issue.code === "invalid_string" && issue.validation === "date") {
1280
- return {
1281
- message: {
1282
- message: {
1283
- defaultMessage: "Invalid date. Please use the format YYYY-MM-DD",
1284
- description: "This is the error message for invalid date fields",
1285
- id: "v2.error.invalidDate"
1286
- }
1472
+ switch (issue.code) {
1473
+ case "invalid_string": {
1474
+ if (_ctx.data === "") {
1475
+ return createIntlError(errorMessages.requiredField);
1287
1476
  }
1288
- };
1289
- }
1290
- if (issue.code === "invalid_string" && issue.validation === "email") {
1291
- return {
1292
- message: {
1293
- message: {
1294
- defaultMessage: "Invalid email address",
1295
- description: "This is the error message for invalid email fields",
1296
- id: "v2.error.invalidEmail"
1297
- }
1477
+ if (issue.validation === "date") {
1478
+ return createIntlError(errorMessages.invalidDate);
1298
1479
  }
1299
- };
1300
- }
1301
- if (issue.code === "invalid_type" && issue.expected !== issue.received && issue.received === "undefined" || issue.code === "too_small" && issue.message === void 0) {
1302
- return {
1303
- message: {
1304
- message: {
1305
- defaultMessage: "Required for registration",
1306
- description: "This is the error message for required fields",
1307
- id: "v2.error.required"
1308
- }
1480
+ if (issue.validation === "email") {
1481
+ return createIntlError(errorMessages.invalidEmail);
1309
1482
  }
1310
- };
1311
- }
1312
- return {
1313
- message: {
1314
- message: {
1315
- defaultMessage: "Invalid input",
1316
- description: "This is the error message for invalid field value",
1317
- id: "v2.error.invalid"
1483
+ break;
1484
+ }
1485
+ case "invalid_type": {
1486
+ if (issue.expected !== issue.received && issue.received === "undefined") {
1487
+ return createIntlError(errorMessages.requiredField);
1318
1488
  }
1489
+ break;
1319
1490
  }
1320
- };
1491
+ case "too_small": {
1492
+ if (issue.message === void 0) {
1493
+ return createIntlError(errorMessages.requiredField);
1494
+ }
1495
+ break;
1496
+ }
1497
+ case "invalid_union": {
1498
+ for (const { issues } of issue.unionErrors) {
1499
+ for (const e of issues) {
1500
+ if (zodToIntlErrorMap(e, _ctx).message.message.id !== "v2.error.required") {
1501
+ return createIntlError(errorMessages.invalidInput);
1502
+ }
1503
+ }
1504
+ }
1505
+ return createIntlError(errorMessages.requiredField);
1506
+ }
1507
+ }
1508
+ return createIntlError(errorMessages.invalidInput);
1321
1509
  };
1322
1510
  function getFieldValidationErrors({
1323
1511
  field: field2,
@@ -1332,11 +1520,7 @@ function getFieldValidationErrors({
1332
1520
  return {
1333
1521
  errors: [
1334
1522
  {
1335
- message: {
1336
- id: "v2.error.hidden",
1337
- defaultMessage: "Hidden or disabled field should not receive a value",
1338
- description: "Error message when field is hidden or disabled, but a value was received"
1339
- }
1523
+ message: errorMessages.hiddenField
1340
1524
  }
1341
1525
  ]
1342
1526
  };
@@ -1354,8 +1538,8 @@ function getFieldValidationErrors({
1354
1538
  conditionalParameters
1355
1539
  });
1356
1540
  return {
1357
- // Assumes that custom validation errors are more important than field validation errors
1358
- errors: [...customValidationResults, ...fieldValidationResult]
1541
+ // Assumes that custom validation errors are based on the field type, and extend the validation.
1542
+ errors: [...fieldValidationResult, ...customValidationResults]
1359
1543
  };
1360
1544
  }
1361
1545
  function runCustomFieldValidations({
@@ -1388,7 +1572,14 @@ function getOrThrow(x, message) {
1388
1572
  return x;
1389
1573
  }
1390
1574
 
1575
+ // ../commons/src/uuid.ts
1576
+ var import_uuid = require("uuid");
1577
+ function getUUID() {
1578
+ return (0, import_uuid.v4)();
1579
+ }
1580
+
1391
1581
  // ../commons/src/events/utils.ts
1582
+ var import_date_fns2 = require("date-fns");
1392
1583
  function isMetadataField(field2) {
1393
1584
  return field2 in eventMetadataLabelMap;
1394
1585
  }
@@ -1457,7 +1648,7 @@ function validateWorkqueueConfig(workqueueConfigs) {
1457
1648
  );
1458
1649
  if (!rootWorkqueue) {
1459
1650
  throw new Error(
1460
- `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1651
+ `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1461
1652
  );
1462
1653
  }
1463
1654
  });
@@ -1473,14 +1664,29 @@ var findActiveActionFormPages = (configuration, action) => {
1473
1664
  var getFormFields = (formConfig) => {
1474
1665
  return formConfig.pages.flatMap((p) => p.fields);
1475
1666
  };
1667
+ function isPageVisible(page, formValues) {
1668
+ if (!page.conditional) {
1669
+ return true;
1670
+ }
1671
+ return validate(page.conditional, {
1672
+ $form: formValues,
1673
+ $now: (0, import_date_fns2.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1674
+ });
1675
+ }
1676
+ var getVisiblePagesFormFields = (formConfig, formData) => {
1677
+ return formConfig.pages.filter((p) => isPageVisible(p, formData)).flatMap((p) => p.fields);
1678
+ };
1476
1679
  var findActiveActionFormFields = (configuration, action) => {
1477
1680
  const form = findActiveActionForm(configuration, action);
1478
1681
  return form ? getFormFields(form) : void 0;
1479
1682
  };
1480
- var findActiveActionFields = (configuration, action) => {
1683
+ var findActiveActionFields = (configuration, action, formData) => {
1481
1684
  const form = findActiveActionForm(configuration, action);
1482
1685
  const reviewFields = form?.review.fields;
1483
- const formFields = form ? getFormFields(form) : void 0;
1686
+ let formFields = void 0;
1687
+ if (form) {
1688
+ formFields = formData ? getVisiblePagesFormFields(form, formData) : getFormFields(form);
1689
+ }
1484
1690
  const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1485
1691
  return allFields;
1486
1692
  };
@@ -1491,6 +1697,9 @@ var getActiveActionFormPages = (configuration, action) => {
1491
1697
  );
1492
1698
  };
1493
1699
  function getActiveActionFields(configuration, action) {
1700
+ if (LatentActions.some((latentAction) => latentAction === action)) {
1701
+ return getActiveActionFields(configuration, ActionType.DECLARE);
1702
+ }
1494
1703
  const fields = findActiveActionFields(configuration, action);
1495
1704
  if (!fields) {
1496
1705
  throw new Error(`No active field config found for action type ${action}`);
@@ -1522,6 +1731,30 @@ function stripHiddenFields(fields, data) {
1522
1731
  return !isFieldVisible(field2, data);
1523
1732
  });
1524
1733
  }
1734
+ function findActiveDrafts(event2, drafts) {
1735
+ const actions = event2.actions.slice().filter(({ type }) => type !== ActionType.READ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1736
+ const lastAction = actions[actions.length - 1];
1737
+ return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
1738
+ }
1739
+ function createEmptyDraft(eventId, draftId, actionType) {
1740
+ return {
1741
+ id: draftId,
1742
+ eventId,
1743
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1744
+ transactionId: getUUID(),
1745
+ action: {
1746
+ type: actionType,
1747
+ data: {},
1748
+ metadata: {},
1749
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1750
+ createdBy: "@todo",
1751
+ createdAtLocation: "@todo"
1752
+ }
1753
+ };
1754
+ }
1755
+ function isVerificationPage(page) {
1756
+ return page.type === FormPageType.VERIFICATION;
1757
+ }
1525
1758
 
1526
1759
  // ../commons/src/events/EventConfig.ts
1527
1760
  var EventConfig = import_zod18.z.object({
@@ -1563,7 +1796,7 @@ var EventConfig = import_zod18.z.object({
1563
1796
 
1564
1797
  // ../commons/src/events/EventConfigInput.ts
1565
1798
  var defineForm = (form) => FormConfig.parse(form);
1566
- var defineFormPage = (formPage) => FormPage.parse(formPage);
1799
+ var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1567
1800
 
1568
1801
  // ../commons/src/events/Draft.ts
1569
1802
  var import_zod21 = require("zod");
@@ -1656,6 +1889,11 @@ var RejectedCorrectionAction = ActionBase.merge(
1656
1889
  requestId: import_zod19.z.string()
1657
1890
  })
1658
1891
  );
1892
+ var ReadAction = ActionBase.merge(
1893
+ import_zod19.z.object({
1894
+ type: import_zod19.z.literal(ActionType.READ)
1895
+ })
1896
+ );
1659
1897
  var CustomAction = ActionBase.merge(
1660
1898
  import_zod19.z.object({
1661
1899
  type: import_zod19.z.literal(ActionType.CUSTOM)
@@ -1676,6 +1914,7 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1676
1914
  RejectedCorrectionAction,
1677
1915
  UnassignedAction,
1678
1916
  PrintCertificateAction,
1917
+ ReadAction,
1679
1918
  CustomAction
1680
1919
  ]);
1681
1920
  var ResolvedUser = import_zod19.z.object({
@@ -1777,6 +2016,11 @@ var ApproveCorrectionActionInput = BaseActionInput.merge(
1777
2016
  type: import_zod20.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
1778
2017
  })
1779
2018
  );
2019
+ var ReadActionInput = BaseActionInput.merge(
2020
+ import_zod20.z.object({
2021
+ type: import_zod20.z.literal(ActionType.READ).default(ActionType.READ)
2022
+ })
2023
+ );
1780
2024
  var ActionInput = import_zod20.z.discriminatedUnion("type", [
1781
2025
  CreateActionInput,
1782
2026
  ValidateActionInput,
@@ -1791,7 +2035,8 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
1791
2035
  PrintCertificateActionInput,
1792
2036
  RequestCorrectionActionInput,
1793
2037
  RejectCorrectionActionInput,
1794
- ApproveCorrectionActionInput
2038
+ ApproveCorrectionActionInput,
2039
+ ReadActionInput
1795
2040
  ]);
1796
2041
 
1797
2042
  // ../commons/src/events/Draft.ts
@@ -1955,9 +2200,8 @@ function getCurrentEventState(event2) {
1955
2200
  });
1956
2201
  }
1957
2202
  function getCurrentEventStateWithDrafts(event2, drafts) {
1958
- const actions = event2.actions.slice().sort();
1959
- const lastAction = actions[actions.length - 1];
1960
- const activeDrafts = drafts.filter(({ eventId }) => eventId === event2.id).filter(({ createdAt }) => createdAt > lastAction.createdAt).map((draft) => draft.action).flatMap((action) => {
2203
+ const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2204
+ const activeDrafts = findActiveDrafts(event2, drafts).map((draft) => draft.action).flatMap((action) => {
1961
2205
  if (action.type === ActionType.REQUEST_CORRECTION) {
1962
2206
  return [
1963
2207
  action,
@@ -2018,12 +2262,6 @@ var defineConfig = (config) => {
2018
2262
  });
2019
2263
  };
2020
2264
 
2021
- // ../commons/src/uuid.ts
2022
- var import_uuid = require("uuid");
2023
- function getUUID() {
2024
- return (0, import_uuid.v4)();
2025
- }
2026
-
2027
2265
  // ../commons/src/events/transactions.ts
2028
2266
  function generateTransactionId() {
2029
2267
  return getUUID();
@@ -2240,6 +2478,23 @@ function field(fieldId) {
2240
2478
  }
2241
2479
  },
2242
2480
  required: ["$form"]
2481
+ }),
2482
+ isValidEnglishName: () => defineConditional({
2483
+ type: "object",
2484
+ properties: {
2485
+ $form: {
2486
+ type: "object",
2487
+ properties: {
2488
+ [fieldId]: {
2489
+ type: "string",
2490
+ 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'._-]*)*$",
2491
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2492
+ }
2493
+ },
2494
+ required: [fieldId]
2495
+ }
2496
+ },
2497
+ required: ["$form"]
2243
2498
  })
2244
2499
  };
2245
2500
  }
@@ -2866,6 +3121,45 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2866
3121
  type: "FILE"
2867
3122
  }
2868
3123
  ]
3124
+ },
3125
+ {
3126
+ id: "collector.identity.verify",
3127
+ type: FormPageType.VERIFICATION,
3128
+ conditional: field("collector.requesterId").isEqualTo("INFORMANT"),
3129
+ title: {
3130
+ id: "event.tennis-club-membership.action.print.verifyIdentity",
3131
+ defaultMessage: "Verify their identity",
3132
+ description: "This is the title of the section"
3133
+ },
3134
+ fields: [],
3135
+ actions: {
3136
+ verify: {
3137
+ label: {
3138
+ defaultMessage: "Verified",
3139
+ description: "This is the label for the verification button",
3140
+ id: "v2.event.tennis-club-membership.action.certificate.form.verify"
3141
+ }
3142
+ },
3143
+ cancel: {
3144
+ label: {
3145
+ defaultMessage: "Identity does not match",
3146
+ description: "This is the label for the verification cancellation button",
3147
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel"
3148
+ },
3149
+ confirmation: {
3150
+ title: {
3151
+ defaultMessage: "Print without proof of ID?",
3152
+ description: "This is the title for the verification cancellation modal",
3153
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel.confirmation.title"
3154
+ },
3155
+ body: {
3156
+ 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",
3157
+ description: "This is the body for the verification cancellation modal",
3158
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel.confirmation.body"
3159
+ }
3160
+ }
3161
+ }
3162
+ }
2869
3163
  }
2870
3164
  ],
2871
3165
  review: {
@@ -3010,6 +3304,27 @@ var TENNIS_CLUB_FORM = defineForm({
3010
3304
  }
3011
3305
  ]
3012
3306
  },
3307
+ {
3308
+ id: "senior-pass",
3309
+ conditional: field("applicant.dob").isBefore().date("1950-01-01"),
3310
+ title: {
3311
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.title",
3312
+ defaultMessage: "Assign senior pass for applicant",
3313
+ description: "This is the title of the section"
3314
+ },
3315
+ fields: [
3316
+ {
3317
+ id: "senior-pass.id",
3318
+ type: "TEXT",
3319
+ required: true,
3320
+ label: {
3321
+ defaultMessage: "Senior pass ID",
3322
+ description: "This is the label for the field",
3323
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.field.id.label"
3324
+ }
3325
+ }
3326
+ ]
3327
+ },
3013
3328
  {
3014
3329
  id: "recommender",
3015
3330
  title: {
@@ -3443,6 +3758,24 @@ var tennisClubMembershipEvent = defineConfig({
3443
3758
  })
3444
3759
  }
3445
3760
  ]
3761
+ },
3762
+ {
3763
+ type: ActionType.ARCHIVE,
3764
+ label: {
3765
+ id: "v2.event.tennis-club-membership.action.archive.label",
3766
+ defaultMessage: "Archive",
3767
+ description: "This is shown as the action name anywhere the user can trigger the action from"
3768
+ },
3769
+ forms: [TENNIS_CLUB_FORM]
3770
+ },
3771
+ {
3772
+ type: ActionType.REJECT,
3773
+ label: {
3774
+ id: "v2.event.tennis-club-membership.action.reject.label",
3775
+ defaultMessage: "Reject",
3776
+ description: "This is shown as the action name anywhere the user can trigger the action from"
3777
+ },
3778
+ forms: [TENNIS_CLUB_FORM]
3446
3779
  }
3447
3780
  ],
3448
3781
  advancedSearch: [
@@ -3473,6 +3806,19 @@ function generateActionInput(configuration, action) {
3473
3806
  );
3474
3807
  return stripHiddenFields(fields, data);
3475
3808
  }
3809
+ function generateActionMetadataInput(configuration, action) {
3810
+ const visibleVerificationPageIds = getActiveActionFormPages(
3811
+ configuration,
3812
+ action
3813
+ ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, {})).map((page) => page.id);
3814
+ return visibleVerificationPageIds.reduce(
3815
+ (acc, pageId) => ({
3816
+ ...acc,
3817
+ [pageId]: true
3818
+ }),
3819
+ {}
3820
+ );
3821
+ }
3476
3822
  var eventPayloadGenerator = {
3477
3823
  create: (input = {}) => ({
3478
3824
  transactionId: input.transactionId ?? getUUID(),
@@ -3525,7 +3871,7 @@ var eventPayloadGenerator = {
3525
3871
  archive: (eventId, input = {}, isDuplicate) => ({
3526
3872
  type: ActionType.ARCHIVE,
3527
3873
  transactionId: input.transactionId ?? getUUID(),
3528
- data: input.data ?? {},
3874
+ data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.ARCHIVE),
3529
3875
  metadata: { isDuplicate: isDuplicate ?? false },
3530
3876
  duplicates: [],
3531
3877
  eventId
@@ -3533,7 +3879,7 @@ var eventPayloadGenerator = {
3533
3879
  reject: (eventId, input = {}) => ({
3534
3880
  type: ActionType.REJECT,
3535
3881
  transactionId: input.transactionId ?? getUUID(),
3536
- data: input.data ?? {},
3882
+ data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REJECT),
3537
3883
  duplicates: [],
3538
3884
  eventId
3539
3885
  }),
@@ -3550,6 +3896,10 @@ var eventPayloadGenerator = {
3550
3896
  tennisClubMembershipEvent,
3551
3897
  ActionType.PRINT_CERTIFICATE
3552
3898
  ),
3899
+ metadata: input.metadata ?? generateActionMetadataInput(
3900
+ tennisClubMembershipEvent,
3901
+ ActionType.PRINT_CERTIFICATE
3902
+ ),
3553
3903
  eventId
3554
3904
  }),
3555
3905
  correction: {
@@ -3592,7 +3942,9 @@ function generateActionDocument({
3592
3942
  defaults = {}
3593
3943
  }) {
3594
3944
  const actionBase = {
3595
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3945
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
3946
+ // @TODO: This should be fixed in the future.
3947
+ createdAt: new Date(Date.now() - 500).toISOString(),
3596
3948
  createdBy: getUUID(),
3597
3949
  id: getUUID(),
3598
3950
  createdAtLocation: "TODO",
@@ -3647,9 +3999,13 @@ function generateEventDocument({
3647
3999
  actions: actions.map(
3648
4000
  (action) => generateActionDocument({ configuration, action })
3649
4001
  ),
3650
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4002
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4003
+ // @TODO: This should be fixed in the future.
4004
+ createdAt: new Date(Date.now() - 1e3).toISOString(),
3651
4005
  id: getUUID(),
3652
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
4006
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4007
+ // @TODO: This should be fixed in the future.
4008
+ updatedAt: new Date(Date.now() - 1e3).toISOString()
3653
4009
  };
3654
4010
  }
3655
4011
  function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, data = {}) {
@@ -3689,6 +4045,11 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3689
4045
  },
3690
4046
  trackingId: overrides.trackingId ?? "M3F8YQ"
3691
4047
  });
4048
+ var generateTranslationConfig = (message) => ({
4049
+ defaultMessage: message,
4050
+ description: "Description for ${message}",
4051
+ id: message
4052
+ });
3692
4053
 
3693
4054
  // ../commons/src/events/TemplateConfig.ts
3694
4055
  function isTemplateVariable(value) {