@opencrvs/toolkit 1.8.0-rc.fb261c5 → 1.8.0-rc.fbcec4c

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.
@@ -30,13 +30,17 @@ 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,
@@ -45,6 +49,8 @@ __export(events_exports, {
45
49
  AdvancedSearchConfig: () => AdvancedSearchConfig,
46
50
  ApproveCorrectionActionInput: () => ApproveCorrectionActionInput,
47
51
  ArchiveActionInput: () => ArchiveActionInput,
52
+ AssignActionInput: () => AssignActionInput,
53
+ AsyncRejectActionDocument: () => AsyncRejectActionDocument,
48
54
  BaseActionInput: () => BaseActionInput,
49
55
  CertificateConfig: () => CertificateConfig,
50
56
  CertificateTemplateConfig: () => CertificateTemplateConfig,
@@ -52,10 +58,18 @@ __export(events_exports, {
52
58
  Clause: () => Clause,
53
59
  Conditional: () => Conditional,
54
60
  ConditionalType: () => ConditionalType,
61
+ ConfirmableActions: () => ConfirmableActions,
62
+ DataEntry: () => DataEntry,
55
63
  DataFieldValue: () => DataFieldValue,
56
64
  DateValue: () => DateValue,
65
+ DeclarationActionConfig: () => DeclarationActionConfig,
66
+ DeclarationActions: () => DeclarationActions,
67
+ DeclarationFormConfig: () => DeclarationFormConfig,
68
+ DeclarationReviewConfig: () => DeclarationReviewConfig,
69
+ DeclarationUpdateActions: () => DeclarationUpdateActions,
57
70
  DeclareActionInput: () => DeclareActionInput,
58
71
  DeduplicationConfig: () => DeduplicationConfig,
72
+ DisplayOnReviewConditional: () => DisplayOnReviewConditional,
59
73
  Draft: () => Draft,
60
74
  DraftInput: () => DraftInput,
61
75
  EmailField: () => EmailField,
@@ -69,6 +83,7 @@ __export(events_exports, {
69
83
  EventSearchIndex: () => EventSearchIndex,
70
84
  EventStatus: () => EventStatus,
71
85
  EventStatuses: () => EventStatuses,
86
+ FieldConditional: () => FieldConditional,
72
87
  FieldConfig: () => FieldConfig,
73
88
  FieldType: () => FieldType,
74
89
  FieldUpdateValue: () => FieldUpdateValue,
@@ -77,20 +92,21 @@ __export(events_exports, {
77
92
  FileFieldValueWithOption: () => FileFieldValueWithOption,
78
93
  FileFieldWithOptionValue: () => FileFieldWithOptionValue,
79
94
  FormConfig: () => FormConfig,
80
- FormPage: () => FormPage,
81
95
  FormPageConfig: () => FormPageConfig,
82
- FormPageType: () => FormPageType,
83
96
  GenericAddressUpdateValue: () => GenericAddressUpdateValue,
84
97
  GenericAddressValue: () => GenericAddressValue,
85
98
  GeographicalArea: () => GeographicalArea,
86
99
  ImageMimeType: () => ImageMimeType,
87
100
  LanguageConfig: () => LanguageConfig,
88
- LatentActions: () => LatentActions,
89
101
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
90
102
  MimeType: () => MimeType,
91
103
  NotifyActionInput: () => NotifyActionInput,
92
104
  NumberFieldValue: () => NumberFieldValue,
105
+ PageConfig: () => PageConfig,
106
+ PageTypes: () => PageTypes,
93
107
  PrintCertificateActionInput: () => PrintCertificateActionInput,
108
+ ReadActionInput: () => ReadActionInput,
109
+ RegisterAction: () => RegisterAction,
94
110
  RegisterActionInput: () => RegisterActionInput,
95
111
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
96
112
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
@@ -103,23 +119,29 @@ __export(events_exports, {
103
119
  SummaryConfig: () => SummaryConfig,
104
120
  TextValue: () => TextValue,
105
121
  TranslationConfig: () => TranslationConfig,
122
+ UnassignActionInput: () => UnassignActionInput,
106
123
  UrbanAddressUpdateValue: () => UrbanAddressUpdateValue,
107
124
  UrbanAddressValue: () => UrbanAddressValue,
108
125
  ValidateActionInput: () => ValidateActionInput,
109
- VerificationPage: () => VerificationPage,
126
+ VerificationActionConfig: () => VerificationActionConfig,
110
127
  VerificationPageConfig: () => VerificationPageConfig,
111
128
  WorkqueueConfig: () => WorkqueueConfig,
112
129
  alwaysTrue: () => alwaysTrue,
113
130
  and: () => and,
131
+ annotationActions: () => annotationActions,
114
132
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
115
133
  compositeFieldTypes: () => compositeFieldTypes,
116
134
  createEmptyDraft: () => createEmptyDraft,
117
135
  createValidationSchema: () => createValidationSchema,
118
136
  deepDropNulls: () => deepDropNulls,
137
+ deepMerge: () => deepMerge,
138
+ defineActionForm: () => defineActionForm,
119
139
  defineConditional: () => defineConditional,
120
140
  defineConfig: () => defineConfig,
121
- defineForm: () => defineForm,
141
+ defineDeclarationForm: () => defineDeclarationForm,
142
+ defineFormConditional: () => defineFormConditional,
122
143
  defineFormPage: () => defineFormPage,
144
+ definePage: () => definePage,
123
145
  errorMessages: () => errorMessages,
124
146
  event: () => event,
125
147
  eventMetadataLabelMap: () => eventMetadataLabelMap,
@@ -128,14 +150,9 @@ __export(events_exports, {
128
150
  eventStatuses: () => eventStatuses,
129
151
  field: () => field,
130
152
  fieldTypes: () => fieldTypes,
131
- findActiveActionFields: () => findActiveActionFields,
132
- findActiveActionForm: () => findActiveActionForm,
133
- findActiveActionFormFields: () => findActiveActionFormFields,
134
- findActiveActionFormPages: () => findActiveActionFormPages,
135
- findActiveActionVerificationPageIds: () => findActiveActionVerificationPageIds,
136
153
  findActiveDrafts: () => findActiveDrafts,
137
- findInputPageFields: () => findInputPageFields,
138
- findPageFields: () => findPageFields,
154
+ findAllFields: () => findAllFields,
155
+ findRecordActionPages: () => findRecordActionPages,
139
156
  generateActionDocument: () => generateActionDocument,
140
157
  generateActionInput: () => generateActionInput,
141
158
  generateActionMetadataInput: () => generateActionMetadataInput,
@@ -143,16 +160,20 @@ __export(events_exports, {
143
160
  generateEventDraftDocument: () => generateEventDraftDocument,
144
161
  generateTransactionId: () => generateTransactionId,
145
162
  generateTranslationConfig: () => generateTranslationConfig,
146
- getActiveActionFields: () => getActiveActionFields,
147
- getActiveActionFormPages: () => getActiveActionFormPages,
148
- getAllFields: () => getAllFields,
149
- getAllPages: () => getAllPages,
163
+ getAcceptedActions: () => getAcceptedActions,
164
+ getActionAnnotation: () => getActionAnnotation,
165
+ getActionAnnotationFields: () => getActionAnnotationFields,
166
+ getActionReview: () => getActionReview,
167
+ getActionReviewFields: () => getActionReviewFields,
168
+ getAllAnnotationFields: () => getAllAnnotationFields,
169
+ getAnnotationFromDrafts: () => getAnnotationFromDrafts,
150
170
  getCurrentEventState: () => getCurrentEventState,
151
171
  getCurrentEventStateWithDrafts: () => getCurrentEventStateWithDrafts,
152
- getEventConfiguration: () => getEventConfiguration,
172
+ getDeclaration: () => getDeclaration,
173
+ getDeclarationFields: () => getDeclarationFields,
174
+ getDeclarationPages: () => getDeclarationPages,
153
175
  getFieldValidationErrors: () => getFieldValidationErrors,
154
- getFormFields: () => getFormFields,
155
- getMetadataForAction: () => getMetadataForAction,
176
+ getVisiblePagesFormFields: () => getVisiblePagesFormFields,
156
177
  isAddressFieldType: () => isAddressFieldType,
157
178
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
158
179
  isBulletListFieldType: () => isBulletListFieldType,
@@ -164,6 +185,7 @@ __export(events_exports, {
164
185
  isEmailFieldType: () => isEmailFieldType,
165
186
  isFacilityFieldType: () => isFacilityFieldType,
166
187
  isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
188
+ isFieldDisplayedOnReview: () => isFieldDisplayedOnReview,
167
189
  isFieldEnabled: () => isFieldEnabled,
168
190
  isFieldValue: () => isFieldValue,
169
191
  isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
@@ -174,6 +196,7 @@ __export(events_exports, {
174
196
  isNumberFieldType: () => isNumberFieldType,
175
197
  isOfficeFieldType: () => isOfficeFieldType,
176
198
  isPageHeaderFieldType: () => isPageHeaderFieldType,
199
+ isPageVisible: () => isPageVisible,
177
200
  isParagraphFieldType: () => isParagraphFieldType,
178
201
  isRadioGroupFieldType: () => isRadioGroupFieldType,
179
202
  isSelectFieldType: () => isSelectFieldType,
@@ -182,12 +205,13 @@ __export(events_exports, {
182
205
  isTextAreaFieldType: () => isTextAreaFieldType,
183
206
  isTextFieldType: () => isTextFieldType,
184
207
  isUndeclaredDraft: () => isUndeclaredDraft,
208
+ isVerificationPage: () => isVerificationPage,
185
209
  mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
186
210
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
187
211
  mapFieldTypeToZod: () => mapFieldTypeToZod,
212
+ never: () => never,
188
213
  not: () => not,
189
214
  or: () => or,
190
- resolveLabelsFromKnownFields: () => resolveLabelsFromKnownFields,
191
215
  stripHiddenFields: () => stripHiddenFields,
192
216
  user: () => user,
193
217
  validate: () => validate,
@@ -197,35 +221,52 @@ __export(events_exports, {
197
221
  module.exports = __toCommonJS(events_exports);
198
222
 
199
223
  // ../commons/src/events/ActionConfig.ts
200
- var import_zod7 = require("zod");
224
+ var import_zod9 = require("zod");
201
225
 
202
226
  // ../commons/src/events/Conditional.ts
203
227
  var import_zod = require("zod");
204
- function Conditional() {
205
- return import_zod.z.custom((val) => typeof val === "object" && val !== null);
206
- }
228
+ var Conditional = import_zod.z.custom(
229
+ (val) => typeof val === "object" && val !== null
230
+ );
207
231
  var ConditionalType = {
208
- /** When 'SHOW' conditional is defined, the action is shown to the user only if the condition is met */
209
232
  SHOW: "SHOW",
210
- /** If 'ENABLE' conditional is defined, the action is enabled only if the condition is met */
211
- ENABLE: "ENABLE"
233
+ ENABLE: "ENABLE",
234
+ DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
212
235
  };
213
236
  var ShowConditional = import_zod.z.object({
214
237
  type: import_zod.z.literal(ConditionalType.SHOW),
215
- conditional: Conditional()
216
- });
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
+ );
217
242
  var EnableConditional = import_zod.z.object({
218
243
  type: import_zod.z.literal(ConditionalType.ENABLE),
219
- conditional: Conditional()
220
- });
244
+ conditional: Conditional
245
+ }).describe(
246
+ "If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
247
+ );
221
248
  var ActionConditional = import_zod.z.discriminatedUnion("type", [
222
249
  // Action can be shown / hidden
223
250
  ShowConditional,
224
251
  // Action can be shown to the user in the list but as disabled
225
252
  EnableConditional
226
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
+ ]);
227
268
 
228
- // ../commons/src/events/FormConfig.ts
269
+ // ../commons/src/events/PageConfig.ts
229
270
  var import_zod6 = require("zod");
230
271
 
231
272
  // ../commons/src/events/FieldConfig.ts
@@ -411,14 +452,14 @@ var BaseField = import_zod5.z.object({
411
452
  ]),
412
453
  DependencyExpression
413
454
  ]).optional(),
414
- conditionals: import_zod5.z.array(ActionConditional).default([]).optional(),
455
+ conditionals: import_zod5.z.array(FieldConditional).default([]).optional(),
415
456
  required: import_zod5.z.boolean().default(false).optional(),
416
457
  disabled: import_zod5.z.boolean().default(false).optional(),
417
458
  hidden: import_zod5.z.boolean().default(false).optional(),
418
459
  placeholder: TranslationConfig.optional(),
419
460
  validation: import_zod5.z.array(
420
461
  import_zod5.z.object({
421
- validator: Conditional(),
462
+ validator: Conditional,
422
463
  message: TranslationConfig
423
464
  })
424
465
  ).default([]).optional(),
@@ -577,7 +618,7 @@ var AdministrativeAreas = import_zod5.z.enum([
577
618
  ]);
578
619
  var AdministrativeAreaConfiguration = import_zod5.z.object({
579
620
  partOf: import_zod5.z.object({
580
- $data: import_zod5.z.string()
621
+ $declaration: import_zod5.z.string()
581
622
  }).optional().describe("Parent location"),
582
623
  type: AdministrativeAreas
583
624
  }).describe("Administrative area options");
@@ -612,11 +653,20 @@ var Address = BaseField.extend({
612
653
  type: import_zod5.z.literal(FieldType.ADDRESS),
613
654
  defaultValue: AddressFieldValue.optional()
614
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
+ ]);
615
665
  var DataField = BaseField.extend({
616
666
  type: import_zod5.z.literal(FieldType.DATA),
617
667
  configuration: import_zod5.z.object({
618
668
  subtitle: TranslationConfig.optional(),
619
- data: import_zod5.z.array(import_zod5.z.object({ fieldId: import_zod5.z.string() }))
669
+ data: import_zod5.z.array(DataEntry)
620
670
  })
621
671
  }).describe("Data field for displaying read-only data");
622
672
  var FieldConfig = import_zod5.z.discriminatedUnion("type", [
@@ -642,20 +692,23 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
642
692
  EmailField,
643
693
  FileUploadWithOptions,
644
694
  DataField
695
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
645
696
  ]);
646
697
 
647
- // ../commons/src/events/FormConfig.ts
648
- var FormPageType = {
649
- FORM: "FORM",
650
- VERIFICATION: "VERIFICATION"
651
- };
652
- 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({
653
701
  id: import_zod6.z.string().describe("Unique identifier for the page"),
654
702
  title: TranslationConfig.describe("Header title of the page"),
655
703
  fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page"),
656
- type: import_zod6.z.literal(FormPageType.FORM).default(FormPageType.FORM)
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
+ )
707
+ });
708
+ var FormPageConfig = PageConfigBase.extend({
709
+ type: import_zod6.z.literal(PageTypes.enum.FORM).default(PageTypes.enum.FORM)
657
710
  });
658
- var VerificationPageConfig = import_zod6.z.object({
711
+ var VerificationActionConfig = import_zod6.z.object({
659
712
  verify: import_zod6.z.object({ label: TranslationConfig }),
660
713
  cancel: import_zod6.z.object({
661
714
  label: TranslationConfig,
@@ -665,136 +718,176 @@ var VerificationPageConfig = import_zod6.z.object({
665
718
  })
666
719
  })
667
720
  }).describe("Actions available on the verification page");
668
- var VerificationPage = FormPage.extend({
669
- type: import_zod6.z.literal(FormPageType.VERIFICATION),
670
- actions: VerificationPageConfig
671
- });
672
- var FormPageConfig = import_zod6.z.preprocess(
673
- (pageConfig) => ({
674
- ...pageConfig,
675
- type: pageConfig.type ?? FormPageType.FORM
676
- // Default type to "FORM" if not provided
677
- }),
678
- import_zod6.z.discriminatedUnion("type", [FormPage, VerificationPage])
679
- );
680
- var FormConfig = import_zod6.z.object({
681
- label: TranslationConfig.describe("Human readable description of the form"),
682
- version: import_zod6.z.object({
683
- id: import_zod6.z.string().describe(
684
- "Form version. Semantic versioning recommended. Example: 0.0.1"
685
- ),
686
- label: TranslationConfig.describe(
687
- "Human readable description of the version"
688
- )
689
- }),
690
- active: import_zod6.z.boolean().default(false).describe("Whether the form is active"),
691
- pages: import_zod6.z.array(FormPageConfig),
692
- review: import_zod6.z.object({
693
- title: TranslationConfig.describe(
694
- "Title of the form to show in review page"
695
- ),
696
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the review page for metadata")
697
- })
721
+ var VerificationPageConfig = FormPageConfig.extend({
722
+ type: import_zod6.z.literal(PageTypes.enum.VERIFICATION),
723
+ actions: VerificationActionConfig
698
724
  });
725
+ var PageConfig = import_zod6.z.discriminatedUnion("type", [
726
+ FormPageConfig,
727
+ VerificationPageConfig
728
+ ]);
699
729
 
700
730
  // ../commons/src/events/ActionType.ts
731
+ var import_zod7 = require("zod");
701
732
  var ActionType = {
733
+ // Pre-declaration actions
734
+ DELETE: "DELETE",
702
735
  CREATE: "CREATE",
703
- ASSIGN: "ASSIGN",
704
- UNASSIGN: "UNASSIGN",
705
- REGISTER: "REGISTER",
706
- VALIDATE: "VALIDATE",
707
- REQUEST_CORRECTION: "REQUEST_CORRECTION",
708
- REJECT_CORRECTION: "REJECT_CORRECTION",
709
- APPROVE_CORRECTION: "APPROVE_CORRECTION",
710
- DETECT_DUPLICATE: "DETECT_DUPLICATE",
711
736
  NOTIFY: "NOTIFY",
737
+ // Declaration actions
712
738
  DECLARE: "DECLARE",
713
- DELETE: "DELETE",
714
- PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
715
- CUSTOM: "CUSTOM",
739
+ VALIDATE: "VALIDATE",
740
+ REGISTER: "REGISTER",
741
+ // Declaration system actions. Non-configurable.
742
+ DETECT_DUPLICATE: "DETECT_DUPLICATE",
716
743
  REJECT: "REJECT",
744
+ // REJECT_DECLARATION
717
745
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
718
- ARCHIVE: "ARCHIVE"
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"
719
757
  };
720
- var LatentActions = [ActionType.ARCHIVE, ActionType.REJECT];
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]);
721
812
 
722
813
  // ../commons/src/events/ActionConfig.ts
723
- var ActionConditional2 = import_zod7.z.discriminatedUnion("type", [
814
+ var ActionConditional2 = import_zod9.z.discriminatedUnion("type", [
724
815
  /** If conditional is defined, the action is shown to the user only if the condition is met */
725
816
  ShowConditional,
726
817
  /** If conditional is defined, the action is enabled only if the condition is met */
727
818
  EnableConditional
728
819
  ]);
729
- 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({
730
825
  label: TranslationConfig,
731
- conditionals: import_zod7.z.array(ActionConditional2).optional().default([]),
732
- draft: import_zod7.z.boolean().optional(),
733
- forms: import_zod7.z.array(FormConfig)
826
+ conditionals: import_zod9.z.array(ActionConditional2).optional().default([]),
827
+ draft: import_zod9.z.boolean().optional()
734
828
  });
735
829
  var DeclareConfig = ActionConfigBase.merge(
736
- import_zod7.z.object({
737
- type: import_zod7.z.literal(ActionType.DECLARE)
830
+ import_zod9.z.object({
831
+ type: import_zod9.z.literal(ActionType.DECLARE),
832
+ review: DeclarationReviewConfig
738
833
  })
739
834
  );
740
835
  var ValidateConfig = ActionConfigBase.merge(
741
- import_zod7.z.object({
742
- type: import_zod7.z.literal(ActionType.VALIDATE)
836
+ import_zod9.z.object({
837
+ type: import_zod9.z.literal(ActionType.VALIDATE),
838
+ review: DeclarationReviewConfig
839
+ })
840
+ );
841
+ var RegisterConfig = ActionConfigBase.merge(
842
+ import_zod9.z.object({
843
+ type: import_zod9.z.literal(ActionType.REGISTER),
844
+ review: DeclarationReviewConfig
743
845
  })
744
846
  );
745
847
  var RejectDeclarationConfig = ActionConfigBase.merge(
746
- import_zod7.z.object({
747
- type: import_zod7.z.literal(ActionType.REJECT)
848
+ import_zod9.z.object({
849
+ type: import_zod9.z.literal(ActionType.REJECT)
748
850
  })
749
851
  );
750
852
  var MarkedAsDuplicateConfig = ActionConfigBase.merge(
751
- import_zod7.z.object({
752
- type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE)
853
+ import_zod9.z.object({
854
+ type: import_zod9.z.literal(ActionType.MARKED_AS_DUPLICATE)
753
855
  })
754
856
  );
755
857
  var ArchiveConfig = ActionConfigBase.merge(
756
- import_zod7.z.object({
757
- type: import_zod7.z.literal(ActionType.ARCHIVE)
758
- })
759
- );
760
- var RegisterConfig = ActionConfigBase.merge(
761
- import_zod7.z.object({
762
- type: import_zod7.z.literal(ActionType.REGISTER)
858
+ import_zod9.z.object({
859
+ type: import_zod9.z.literal(ActionType.ARCHIVE)
763
860
  })
764
861
  );
765
862
  var DeleteConfig = ActionConfigBase.merge(
766
- import_zod7.z.object({
767
- type: import_zod7.z.literal(ActionType.DELETE)
863
+ import_zod9.z.object({
864
+ type: import_zod9.z.literal(ActionType.DELETE)
768
865
  })
769
866
  );
770
867
  var PrintCertificateActionConfig = ActionConfigBase.merge(
771
- import_zod7.z.object({
772
- 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
773
871
  })
774
872
  );
775
873
  var RequestCorrectionConfig = ActionConfigBase.merge(
776
- import_zod7.z.object({
777
- type: import_zod7.z.literal(ActionType.REQUEST_CORRECTION),
778
- onboardingForm: import_zod7.z.array(FormPageConfig),
779
- additionalDetailsForm: import_zod7.z.array(FormPageConfig)
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)
780
878
  })
781
879
  );
782
880
  var RejectCorrectionConfig = ActionConfigBase.merge(
783
- import_zod7.z.object({
784
- type: import_zod7.z.literal(ActionType.REJECT_CORRECTION)
881
+ import_zod9.z.object({
882
+ type: import_zod9.z.literal(ActionType.REJECT_CORRECTION)
785
883
  })
786
884
  );
787
885
  var ApproveCorrectionConfig = ActionConfigBase.merge(
788
- import_zod7.z.object({
789
- type: import_zod7.z.literal(ActionType.APPROVE_CORRECTION)
886
+ import_zod9.z.object({
887
+ type: import_zod9.z.literal(ActionType.APPROVE_CORRECTION)
790
888
  })
791
889
  );
792
- var CustomConfig = ActionConfigBase.merge(
793
- import_zod7.z.object({
794
- type: import_zod7.z.literal(ActionType.CUSTOM)
795
- })
796
- );
797
- var ActionConfig = import_zod7.z.discriminatedUnion("type", [
890
+ var ActionConfig = import_zod9.z.discriminatedUnion("type", [
798
891
  DeclareConfig,
799
892
  ValidateConfig,
800
893
  RejectDeclarationConfig,
@@ -805,102 +898,108 @@ var ActionConfig = import_zod7.z.discriminatedUnion("type", [
805
898
  PrintCertificateActionConfig,
806
899
  RequestCorrectionConfig,
807
900
  RejectCorrectionConfig,
808
- ApproveCorrectionConfig,
809
- CustomConfig
901
+ ApproveCorrectionConfig
902
+ ]);
903
+ var DeclarationActionConfig = import_zod9.z.discriminatedUnion("type", [
904
+ DeclareConfig,
905
+ ValidateConfig,
906
+ RegisterConfig
810
907
  ]);
811
908
 
812
909
  // ../commons/src/events/offline/CertificateConfig.ts
813
- var import_zod8 = require("zod");
814
- var FontFamily = import_zod8.z.object({
815
- normal: import_zod8.z.string(),
816
- bold: import_zod8.z.string(),
817
- italics: import_zod8.z.string(),
818
- 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()
819
916
  });
820
- var CertificateConfig = import_zod8.z.object({
821
- id: import_zod8.z.string(),
822
- event: import_zod8.z.string(),
917
+ var CertificateConfig = import_zod10.z.object({
918
+ id: import_zod10.z.string(),
919
+ event: import_zod10.z.string(),
823
920
  label: TranslationConfig,
824
- isDefault: import_zod8.z.boolean(),
825
- fee: import_zod8.z.object({
826
- onTime: import_zod8.z.number(),
827
- late: import_zod8.z.number(),
828
- 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()
829
926
  }),
830
- svgUrl: import_zod8.z.string(),
831
- fonts: import_zod8.z.record(FontFamily).optional()
927
+ svgUrl: import_zod10.z.string(),
928
+ fonts: import_zod10.z.record(FontFamily).optional()
832
929
  });
833
930
  var CertificateTemplateConfig = CertificateConfig.extend({
834
- hash: import_zod8.z.string().optional(),
835
- svg: import_zod8.z.string()
931
+ hash: import_zod10.z.string().optional(),
932
+ svg: import_zod10.z.string()
836
933
  });
837
934
 
838
935
  // ../commons/src/events/offline/LanguageConfig.ts
839
- var import_zod9 = require("zod");
840
- var LanguageConfig = import_zod9.z.object({
841
- lang: import_zod9.z.string(),
936
+ var import_zod11 = require("zod");
937
+ var LanguageConfig = import_zod11.z.object({
938
+ lang: import_zod11.z.string(),
842
939
  /**
843
940
  * client.csv contents
844
941
  */
845
- messages: import_zod9.z.record(import_zod9.z.string())
942
+ messages: import_zod11.z.record(import_zod11.z.string())
846
943
  });
847
944
 
848
945
  // ../commons/src/events/EventConfig.ts
849
- var import_zod18 = require("zod");
946
+ var import_zod20 = require("zod");
850
947
 
851
948
  // ../commons/src/events/DeduplicationConfig.ts
852
- var import_zod10 = require("zod");
853
- var FieldReference = import_zod10.z.string();
854
- var Matcher = import_zod10.z.object({
855
- fieldId: import_zod10.z.string(),
856
- options: import_zod10.z.object({
857
- 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()
858
955
  }).optional().default({})
859
956
  });
860
957
  var FuzzyMatcher = Matcher.extend({
861
- type: import_zod10.z.literal("fuzzy"),
862
- options: import_zod10.z.object({
958
+ type: import_zod12.z.literal("fuzzy"),
959
+ options: import_zod12.z.object({
863
960
  /**
864
961
  * Names of length 3 or less characters = 0 edits allowed
865
962
  * Names of length 4 - 6 characters = 1 edit allowed
866
963
  * Names of length >7 characters = 2 edits allowed
867
964
  */
868
- fuzziness: import_zod10.z.union([import_zod10.z.string(), import_zod10.z.number()]).optional().default("AUTO:4,7"),
869
- 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)
870
967
  }).optional().default({})
871
968
  });
872
969
  var StrictMatcher = Matcher.extend({
873
- type: import_zod10.z.literal("strict"),
874
- options: import_zod10.z.object({
875
- 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)
876
973
  }).optional().default({})
877
974
  });
878
975
  var DateRangeMatcher = Matcher.extend({
879
- type: import_zod10.z.literal("dateRange"),
880
- options: import_zod10.z.object({
881
- days: import_zod10.z.number(),
976
+ type: import_zod12.z.literal("dateRange"),
977
+ options: import_zod12.z.object({
978
+ days: import_zod12.z.number(),
882
979
  origin: FieldReference,
883
- boost: import_zod10.z.number().optional().default(1)
980
+ boost: import_zod12.z.number().optional().default(1)
884
981
  })
885
982
  });
886
983
  var DateDistanceMatcher = Matcher.extend({
887
- type: import_zod10.z.literal("dateDistance"),
888
- options: import_zod10.z.object({
889
- days: import_zod10.z.number(),
984
+ type: import_zod12.z.literal("dateDistance"),
985
+ options: import_zod12.z.object({
986
+ days: import_zod12.z.number(),
890
987
  origin: FieldReference,
891
- boost: import_zod10.z.number().optional().default(1)
988
+ boost: import_zod12.z.number().optional().default(1)
892
989
  })
893
990
  });
894
- var And = import_zod10.z.object({
895
- type: import_zod10.z.literal("and"),
896
- 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())
897
995
  });
898
- var Or = import_zod10.z.object({
899
- type: import_zod10.z.literal("or"),
900
- 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())
901
1000
  });
902
- var Clause = import_zod10.z.lazy(
903
- () => import_zod10.z.discriminatedUnion("type", [
1001
+ var Clause = import_zod12.z.lazy(
1002
+ () => import_zod12.z.discriminatedUnion("type", [
904
1003
  And,
905
1004
  Or,
906
1005
  FuzzyMatcher,
@@ -909,37 +1008,37 @@ var Clause = import_zod10.z.lazy(
909
1008
  DateDistanceMatcher
910
1009
  ])
911
1010
  );
912
- var DeduplicationConfig = import_zod10.z.object({
913
- id: import_zod10.z.string(),
1011
+ var DeduplicationConfig = import_zod12.z.object({
1012
+ id: import_zod12.z.string(),
914
1013
  label: TranslationConfig,
915
1014
  query: Clause
916
1015
  });
917
1016
 
918
1017
  // ../commons/src/events/SummaryConfig.ts
919
- var import_zod11 = require("zod");
920
- var Field = import_zod11.z.object({
921
- 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"),
922
1021
  value: TranslationConfig.describe(
923
1022
  "Summary field value. Can utilise values defined in configuration and EventMetadata"
924
1023
  ),
925
1024
  label: TranslationConfig,
926
1025
  emptyValueMessage: TranslationConfig.optional()
927
1026
  });
928
- var Title = import_zod11.z.object({
929
- id: import_zod11.z.string(),
1027
+ var Title = import_zod13.z.object({
1028
+ id: import_zod13.z.string(),
930
1029
  label: TranslationConfig.describe("Title content"),
931
1030
  emptyValueMessage: TranslationConfig.optional()
932
1031
  });
933
- var SummaryConfig = import_zod11.z.object({
1032
+ var SummaryConfig = import_zod13.z.object({
934
1033
  title: Title.describe("Title of summary view."),
935
- 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.")
936
1035
  }).describe("Configuration for summary in event.");
937
1036
 
938
1037
  // ../commons/src/events/WorkqueueConfig.ts
939
- var import_zod13 = require("zod");
1038
+ var import_zod15 = require("zod");
940
1039
 
941
1040
  // ../commons/src/events/EventMetadata.ts
942
- var import_zod12 = require("zod");
1041
+ var import_zod14 = require("zod");
943
1042
  var EventStatus = {
944
1043
  CREATED: "CREATED",
945
1044
  NOTIFIED: "NOTIFIED",
@@ -951,18 +1050,20 @@ var EventStatus = {
951
1050
  ARCHIVED: "ARCHIVED"
952
1051
  };
953
1052
  var eventStatuses = Object.values(EventStatus);
954
- var EventStatuses = import_zod12.z.nativeEnum(EventStatus);
955
- var EventMetadata = import_zod12.z.object({
956
- id: import_zod12.z.string(),
957
- 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(),
958
1057
  status: EventStatuses,
959
- createdAt: import_zod12.z.string().datetime(),
960
- createdBy: import_zod12.z.string(),
961
- createdAtLocation: import_zod12.z.string(),
962
- modifiedAt: import_zod12.z.string().datetime(),
963
- assignedTo: import_zod12.z.string().nullish(),
964
- updatedBy: import_zod12.z.string(),
965
- 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
+ updatedAtLocation: import_zod14.z.string(),
1062
+ modifiedAt: import_zod14.z.string().datetime(),
1063
+ assignedTo: import_zod14.z.string().nullish(),
1064
+ updatedBy: import_zod14.z.string(),
1065
+ trackingId: import_zod14.z.string(),
1066
+ registrationNumber: import_zod14.z.string().nullish()
966
1067
  });
967
1068
  var eventMetadataLabelMap = {
968
1069
  "event.assignedTo": {
@@ -980,6 +1081,11 @@ var eventMetadataLabelMap = {
980
1081
  defaultMessage: "Location",
981
1082
  description: "Created At Location"
982
1083
  },
1084
+ "event.updatedAtLocation": {
1085
+ id: "event.updatedAtLocation.label",
1086
+ defaultMessage: "Location",
1087
+ description: "Updated At Location"
1088
+ },
983
1089
  "event.createdBy": {
984
1090
  id: "event.createdBy.label",
985
1091
  defaultMessage: "Created By",
@@ -1014,28 +1120,33 @@ var eventMetadataLabelMap = {
1014
1120
  id: "event.trackingId.label",
1015
1121
  defaultMessage: "Tracking ID",
1016
1122
  description: "Tracking ID"
1123
+ },
1124
+ "event.registrationNumber": {
1125
+ id: "event.registrationNumber.label",
1126
+ defaultMessage: "Registration Number",
1127
+ description: "Registration Number"
1017
1128
  }
1018
1129
  };
1019
1130
 
1020
1131
  // ../commons/src/events/WorkqueueConfig.ts
1021
- var WorkqueueConfig = import_zod13.z.object({
1022
- id: import_zod13.z.string().describe("Unique identifier for workqueue."),
1023
- filters: import_zod13.z.array(
1024
- import_zod13.z.object({
1025
- status: import_zod13.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
1132
+ var WorkqueueConfig = import_zod15.z.object({
1133
+ id: import_zod15.z.string().describe("Unique identifier for workqueue."),
1134
+ filters: import_zod15.z.array(
1135
+ import_zod15.z.object({
1136
+ status: import_zod15.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
1026
1137
  })
1027
1138
  ).describe("Filters to be applied to workqueue.")
1028
1139
  }).describe("Configuration for workqueue.");
1029
1140
 
1030
1141
  // ../commons/src/events/AdvancedSearchConfig.ts
1031
- var import_zod14 = require("zod");
1032
- var AdvancedSearchConfig = import_zod14.z.object({
1142
+ var import_zod16 = require("zod");
1143
+ var AdvancedSearchConfig = import_zod16.z.object({
1033
1144
  title: TranslationConfig.describe("Advanced search tab title"),
1034
- fields: import_zod14.z.array(
1035
- import_zod14.z.object({
1036
- fieldId: import_zod14.z.string(),
1037
- config: import_zod14.z.object({
1038
- type: import_zod14.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
1145
+ fields: import_zod16.z.array(
1146
+ import_zod16.z.object({
1147
+ fieldId: import_zod16.z.string(),
1148
+ config: import_zod16.z.object({
1149
+ type: import_zod16.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
1039
1150
  }).optional().describe("Configuration options for the field")
1040
1151
  })
1041
1152
  ).optional().default([]).describe("Advanced search fields.")
@@ -1045,12 +1156,12 @@ var AdvancedSearchConfig = import_zod14.z.object({
1045
1156
  var import_lodash = require("lodash");
1046
1157
 
1047
1158
  // ../commons/src/workqueues/WorkqueueConfig.ts
1048
- var import_zod16 = require("zod");
1159
+ var import_zod18 = require("zod");
1049
1160
 
1050
1161
  // ../commons/src/workqueues/defaultColumns.ts
1051
- var import_zod15 = require("zod");
1052
- var WorkQueueColumnConfig = import_zod15.z.object({
1053
- id: import_zod15.z.string(),
1162
+ var import_zod17 = require("zod");
1163
+ var WorkQueueColumnConfig = import_zod17.z.object({
1164
+ id: import_zod17.z.string(),
1054
1165
  label: TranslationConfig
1055
1166
  });
1056
1167
  var defaultColumns = {
@@ -1087,16 +1198,16 @@ var defaultColumns = {
1087
1198
  }
1088
1199
  }
1089
1200
  };
1090
- var DefaultColumnKeys = import_zod15.z.enum(
1201
+ var DefaultColumnKeys = import_zod17.z.enum(
1091
1202
  Object.keys(defaultColumns)
1092
1203
  );
1093
1204
 
1094
1205
  // ../commons/src/workqueues/WorkqueueConfig.ts
1095
- var rootWorkqueueConfig = import_zod16.z.object({
1096
- id: import_zod16.z.string(),
1206
+ var rootWorkqueueConfig = import_zod18.z.object({
1207
+ id: import_zod18.z.string(),
1097
1208
  title: TranslationConfig,
1098
- columns: import_zod16.z.array(WorkQueueColumnConfig),
1099
- defaultColumns: import_zod16.z.array(DefaultColumnKeys)
1209
+ columns: import_zod18.z.array(WorkQueueColumnConfig),
1210
+ defaultColumns: import_zod18.z.array(DefaultColumnKeys)
1100
1211
  });
1101
1212
  var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
1102
1213
 
@@ -1176,7 +1287,7 @@ var import_ajv_formats = __toESM(require("ajv-formats"));
1176
1287
  var import_date_fns = require("date-fns");
1177
1288
 
1178
1289
  // ../commons/src/events/FieldTypeMapping.ts
1179
- var import_zod17 = require("zod");
1290
+ var import_zod19 = require("zod");
1180
1291
  function mapFieldTypeToZod(type, required) {
1181
1292
  let schema;
1182
1293
  switch (type) {
@@ -1229,7 +1340,7 @@ function createValidationSchema(config) {
1229
1340
  for (const field2 of config) {
1230
1341
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1231
1342
  }
1232
- return import_zod17.z.object(shape);
1343
+ return import_zod19.z.object(shape);
1233
1344
  }
1234
1345
  function mapFieldTypeToMockValue(field2, i) {
1235
1346
  switch (field2.type) {
@@ -1396,7 +1507,8 @@ var isDataFieldType = (field2) => {
1396
1507
 
1397
1508
  // ../commons/src/conditionals/validate.ts
1398
1509
  var ajv = new import_ajv.default({
1399
- $data: true
1510
+ $data: true,
1511
+ allowUnionTypes: true
1400
1512
  });
1401
1513
  (0, import_ajv_formats.default)(ajv);
1402
1514
  function validate(schema, data) {
@@ -1429,6 +1541,9 @@ function isFieldVisible(field2, form) {
1429
1541
  function isFieldEnabled(field2, form) {
1430
1542
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1431
1543
  }
1544
+ function isFieldDisplayedOnReview(field2, form) {
1545
+ return isFieldVisible(field2, form) && isFieldConditionMet(field2, form, ConditionalType.DISPLAY_ON_REVIEW);
1546
+ }
1432
1547
  var errorMessages = {
1433
1548
  hiddenField: {
1434
1549
  id: "v2.error.hidden",
@@ -1456,12 +1571,14 @@ var errorMessages = {
1456
1571
  id: "v2.error.invalid"
1457
1572
  }
1458
1573
  };
1459
- var createIntlError = (message) => ({
1460
- message: {
1461
- message
1462
- }
1463
- });
1464
- var zodToIntlErrorMap = (issue, _ctx) => {
1574
+ function createIntlError(message) {
1575
+ return {
1576
+ message: {
1577
+ message
1578
+ }
1579
+ };
1580
+ }
1581
+ function zodToIntlErrorMap(issue, _ctx) {
1465
1582
  switch (issue.code) {
1466
1583
  case "invalid_string": {
1467
1584
  if (_ctx.data === "") {
@@ -1499,7 +1616,28 @@ var zodToIntlErrorMap = (issue, _ctx) => {
1499
1616
  }
1500
1617
  }
1501
1618
  return createIntlError(errorMessages.invalidInput);
1502
- };
1619
+ }
1620
+ function runCustomFieldValidations({
1621
+ field: field2,
1622
+ conditionalParameters
1623
+ }) {
1624
+ return (field2.validation ?? []).filter((validation) => {
1625
+ return !validate(validation.validator, conditionalParameters);
1626
+ }).map((validation) => ({ message: validation.message }));
1627
+ }
1628
+ function validateFieldInput({
1629
+ field: field2,
1630
+ value
1631
+ }) {
1632
+ const rawError = mapFieldTypeToZod(field2.type, field2.required).safeParse(
1633
+ value,
1634
+ {
1635
+ // @ts-expect-error
1636
+ errorMap: zodToIntlErrorMap
1637
+ }
1638
+ );
1639
+ return rawError.error?.issues.map((issue) => issue.message) ?? [];
1640
+ }
1503
1641
  function getFieldValidationErrors({
1504
1642
  field: field2,
1505
1643
  values
@@ -1535,28 +1673,16 @@ function getFieldValidationErrors({
1535
1673
  errors: [...fieldValidationResult, ...customValidationResults]
1536
1674
  };
1537
1675
  }
1538
- function runCustomFieldValidations({
1539
- field: field2,
1540
- conditionalParameters
1541
- }) {
1542
- return (field2.validation ?? []).filter((validation) => {
1543
- return !validate(validation.validator, conditionalParameters);
1544
- }).map((validation) => ({ message: validation.message }));
1545
- }
1546
- function validateFieldInput({
1547
- field: field2,
1548
- value
1549
- }) {
1550
- const rawError = mapFieldTypeToZod(field2.type, field2.required).safeParse(
1551
- value,
1552
- {
1553
- // @ts-expect-error
1554
- errorMap: zodToIntlErrorMap
1555
- }
1556
- );
1557
- return rawError.error?.issues.map((issue) => issue.message) ?? [];
1676
+
1677
+ // ../commons/src/uuid.ts
1678
+ var import_uuid = require("uuid");
1679
+ function getUUID() {
1680
+ return (0, import_uuid.v4)();
1558
1681
  }
1559
1682
 
1683
+ // ../commons/src/events/utils.ts
1684
+ var import_date_fns2 = require("date-fns");
1685
+
1560
1686
  // ../commons/src/utils.ts
1561
1687
  function getOrThrow(x, message) {
1562
1688
  if (x === void 0 || x === null) {
@@ -1565,73 +1691,64 @@ function getOrThrow(x, message) {
1565
1691
  return x;
1566
1692
  }
1567
1693
 
1568
- // ../commons/src/uuid.ts
1569
- var import_uuid = require("uuid");
1570
- function getUUID() {
1571
- return (0, import_uuid.v4)();
1572
- }
1573
-
1574
1694
  // ../commons/src/events/utils.ts
1575
- function isMetadataField(field2) {
1576
- return field2 in eventMetadataLabelMap;
1577
- }
1578
- var findInputPageFields = (config) => {
1579
- return (0, import_lodash.flattenDeep)(
1580
- config.actions.map(
1581
- ({ forms }) => forms.map(
1582
- ({ pages }) => pages.map(
1583
- ({ fields }) => fields.map(({ id, label }) => ({ id, label }))
1584
- )
1585
- )
1586
- )
1587
- );
1695
+ function isDeclarationActionConfig(action) {
1696
+ return DeclarationActions.safeParse(action.type).success;
1697
+ }
1698
+ function getDeclarationFields(configuration) {
1699
+ return configuration.declaration.pages.flatMap(({ fields }) => fields);
1700
+ }
1701
+ function getDeclarationPages(configuration) {
1702
+ return configuration.declaration.pages;
1703
+ }
1704
+ function getDeclaration(configuration) {
1705
+ return configuration.declaration;
1706
+ }
1707
+ var getActionAnnotationFields = (actionConfig) => {
1708
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1709
+ return [
1710
+ ...actionConfig.onboardingForm.flatMap(({ fields }) => fields),
1711
+ ...actionConfig.additionalDetailsForm.flatMap(({ fields }) => fields)
1712
+ ];
1713
+ }
1714
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1715
+ return actionConfig.printForm.pages.flatMap(({ fields }) => fields);
1716
+ }
1717
+ if (isDeclarationActionConfig(actionConfig)) {
1718
+ return actionConfig.review.fields;
1719
+ }
1720
+ return [];
1588
1721
  };
1589
- var findPageFields = (config) => {
1590
- return (0, import_lodash.flattenDeep)(
1591
- config.actions.map((action) => {
1592
- if (action.type === ActionType.REQUEST_CORRECTION) {
1593
- return [
1594
- ...action.forms.map(({ pages }) => pages.map(({ fields }) => fields)),
1595
- ...action.onboardingForm.flatMap(({ fields }) => fields),
1596
- ...action.additionalDetailsForm.flatMap(({ fields }) => fields)
1597
- ];
1598
- }
1599
- return action.forms.map(({ pages }) => pages.map(({ fields }) => fields));
1600
- })
1601
- );
1722
+ var getAllAnnotationFields = (config) => {
1723
+ return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1602
1724
  };
1603
- var resolveLabelsFromKnownFields = ({
1604
- pageFields,
1605
- refFields
1606
- }) => {
1607
- return refFields.map((field2) => {
1608
- if (field2.label) {
1609
- return field2;
1610
- }
1611
- if (isMetadataField(field2.id)) {
1612
- return {
1613
- ...field2,
1614
- label: eventMetadataLabelMap[field2.id]
1615
- };
1616
- }
1617
- const pageLabel = pageFields.find((pageField) => pageField.id === field2.id);
1618
- if (!pageLabel) {
1619
- throw new Error(`Referenced field ${field2.id} does not have a label`);
1620
- }
1621
- return {
1622
- ...field2,
1623
- label: pageLabel.label
1624
- };
1625
- });
1626
- };
1627
- function getAllFields(configuration) {
1628
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => [
1629
- ...form.review.fields,
1630
- ...form.pages.flatMap((page) => page.fields)
1725
+ var findAllFields = (config) => {
1726
+ return (0, import_lodash.flattenDeep)([
1727
+ ...getDeclarationFields(config),
1728
+ ...getAllAnnotationFields(config)
1631
1729
  ]);
1730
+ };
1731
+ var findRecordActionPages = (config, actionType) => {
1732
+ const action = config.actions.find((a) => a.type === actionType);
1733
+ if (action?.type === ActionType.REQUEST_CORRECTION) {
1734
+ return [...action.onboardingForm, ...action.additionalDetailsForm];
1735
+ }
1736
+ if (action?.type === ActionType.PRINT_CERTIFICATE) {
1737
+ return action.printForm.pages;
1738
+ }
1739
+ return [];
1740
+ };
1741
+ function getActionReview(configuration, actionType) {
1742
+ const [actionConfig] = configuration.actions.filter(
1743
+ (a) => a.type === actionType
1744
+ );
1745
+ return getOrThrow(
1746
+ actionConfig.review,
1747
+ `No review config found for ${actionType}`
1748
+ );
1632
1749
  }
1633
- function getAllPages(configuration) {
1634
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => form.pages);
1750
+ function getActionReviewFields(configuration, actionType) {
1751
+ return getActionReview(configuration, actionType).fields;
1635
1752
  }
1636
1753
  function validateWorkqueueConfig(workqueueConfigs) {
1637
1754
  workqueueConfigs.map((workqueue) => {
@@ -1645,71 +1762,38 @@ function validateWorkqueueConfig(workqueueConfigs) {
1645
1762
  }
1646
1763
  });
1647
1764
  }
1648
- var findActiveActionForm = (configuration, action) => {
1649
- const actionConfig = configuration.actions.find((a) => a.type === action);
1650
- const form = actionConfig?.forms.find((f) => f.active);
1651
- return form;
1652
- };
1653
- var findActiveActionFormPages = (configuration, action) => {
1654
- return findActiveActionForm(configuration, action)?.pages;
1655
- };
1656
- var getFormFields = (formConfig) => {
1657
- return formConfig.pages.flatMap((p) => p.fields);
1658
- };
1659
- var findActiveActionFormFields = (configuration, action) => {
1660
- const form = findActiveActionForm(configuration, action);
1661
- return form ? getFormFields(form) : void 0;
1662
- };
1663
- var findActiveActionFields = (configuration, action) => {
1664
- const form = findActiveActionForm(configuration, action);
1665
- const reviewFields = form?.review.fields;
1666
- const formFields = form ? getFormFields(form) : void 0;
1667
- const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1668
- return allFields;
1669
- };
1670
- var getActiveActionFormPages = (configuration, action) => {
1671
- return getOrThrow(
1672
- findActiveActionForm(configuration, action)?.pages,
1673
- "Form configuration not found for type: " + configuration.id
1674
- );
1675
- };
1676
- function getActiveActionFields(configuration, action) {
1677
- if (LatentActions.some((latentAction) => latentAction === action)) {
1678
- return getActiveActionFields(configuration, ActionType.DECLARE);
1679
- }
1680
- const fields = findActiveActionFields(configuration, action);
1681
- if (!fields) {
1682
- throw new Error(`No active field config found for action type ${action}`);
1683
- }
1684
- return fields;
1685
- }
1686
- function getEventConfiguration(eventConfigurations, type) {
1687
- const config = eventConfigurations.find((config2) => config2.id === type);
1688
- if (!config) {
1689
- throw new Error(`Event configuration not found for type: ${type}`);
1765
+ function isPageVisible(page, formValues) {
1766
+ if (!page.conditional) {
1767
+ return true;
1690
1768
  }
1691
- return config;
1769
+ return validate(page.conditional, {
1770
+ $form: formValues,
1771
+ $now: (0, import_date_fns2.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1772
+ });
1692
1773
  }
1774
+ var getVisiblePagesFormFields = (formConfig, formData) => {
1775
+ return formConfig.pages.filter((p) => isPageVisible(p, formData)).flatMap((p) => p.fields);
1776
+ };
1693
1777
  function isOptionalUncheckedCheckbox(field2, form) {
1694
1778
  if (field2.type !== FieldType.CHECKBOX || field2.required) {
1695
1779
  return false;
1696
1780
  }
1697
1781
  return !form[field2.id];
1698
1782
  }
1699
- function stripHiddenFields(fields, data) {
1700
- return (0, import_lodash.omitBy)(data, (_2, fieldId) => {
1783
+ function stripHiddenFields(fields, declaration) {
1784
+ return (0, import_lodash.omitBy)(declaration, (_, fieldId) => {
1701
1785
  const field2 = fields.find((f) => f.id === fieldId);
1702
1786
  if (!field2) {
1703
1787
  return true;
1704
1788
  }
1705
- if (isOptionalUncheckedCheckbox(field2, data)) {
1789
+ if (isOptionalUncheckedCheckbox(field2, declaration)) {
1706
1790
  return true;
1707
1791
  }
1708
- return !isFieldVisible(field2, data);
1792
+ return !isFieldVisible(field2, declaration);
1709
1793
  });
1710
1794
  }
1711
1795
  function findActiveDrafts(event2, drafts) {
1712
- const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1796
+ const actions = event2.actions.slice().filter(({ type }) => type !== ActionType.READ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1713
1797
  const lastAction = actions[actions.length - 1];
1714
1798
  return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
1715
1799
  }
@@ -1721,35 +1805,50 @@ function createEmptyDraft(eventId, draftId, actionType) {
1721
1805
  transactionId: getUUID(),
1722
1806
  action: {
1723
1807
  type: actionType,
1724
- data: {},
1725
- metadata: {},
1808
+ declaration: {},
1809
+ annotation: {},
1726
1810
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1727
1811
  createdBy: "@todo",
1728
1812
  createdAtLocation: "@todo"
1729
1813
  }
1730
1814
  };
1731
1815
  }
1732
- function findActiveActionVerificationPageIds(configuration, action) {
1733
- const pages = findActiveActionFormPages(configuration, action);
1734
- if (!pages) {
1735
- return [];
1736
- }
1737
- return pages.filter((page) => page.type === FormPageType.VERIFICATION).map((page) => page.id);
1816
+ function isVerificationPage(page) {
1817
+ return page.type === PageTypes.enum.VERIFICATION;
1818
+ }
1819
+ function deepMerge(currentDocument, actionDocument) {
1820
+ return (0, import_lodash.mergeWith)(
1821
+ currentDocument,
1822
+ actionDocument,
1823
+ (previousValue, incomingValue) => {
1824
+ if (incomingValue === void 0) {
1825
+ return previousValue;
1826
+ }
1827
+ if ((0, import_lodash.isArray)(incomingValue)) {
1828
+ return incomingValue;
1829
+ }
1830
+ if ((0, import_lodash.isObject)(previousValue) && (0, import_lodash.isObject)(incomingValue)) {
1831
+ return void 0;
1832
+ }
1833
+ return incomingValue;
1834
+ }
1835
+ );
1738
1836
  }
1739
1837
 
1740
1838
  // ../commons/src/events/EventConfig.ts
1741
- var EventConfig = import_zod18.z.object({
1742
- id: import_zod18.z.string().describe(
1839
+ var EventConfig = import_zod20.z.object({
1840
+ id: import_zod20.z.string().describe(
1743
1841
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1744
1842
  ),
1745
1843
  summary: SummaryConfig,
1746
1844
  label: TranslationConfig,
1747
- actions: import_zod18.z.array(ActionConfig),
1748
- workqueues: import_zod18.z.array(WorkqueueConfig),
1749
- deduplication: import_zod18.z.array(DeduplicationConfig).optional().default([]),
1750
- advancedSearch: import_zod18.z.array(AdvancedSearchConfig).optional().default([])
1845
+ actions: import_zod20.z.array(ActionConfig),
1846
+ declaration: DeclarationFormConfig,
1847
+ workqueues: import_zod20.z.array(WorkqueueConfig),
1848
+ deduplication: import_zod20.z.array(DeduplicationConfig).optional().default([]),
1849
+ advancedSearch: import_zod20.z.array(AdvancedSearchConfig).optional().default([])
1751
1850
  }).superRefine((event2, ctx) => {
1752
- const allFields = findPageFields(event2);
1851
+ const allFields = findAllFields(event2);
1753
1852
  const fieldIds = allFields.map((field2) => field2.id);
1754
1853
  const advancedSearchFields = event2.advancedSearch.flatMap(
1755
1854
  (section) => section.fields.flatMap((field2) => field2.fieldId)
@@ -1776,106 +1875,117 @@ var EventConfig = import_zod18.z.object({
1776
1875
  });
1777
1876
 
1778
1877
  // ../commons/src/events/EventConfigInput.ts
1779
- var defineForm = (form) => FormConfig.parse(form);
1878
+ var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
1879
+ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1880
+ var definePage = (page) => PageConfig.parse(page);
1780
1881
  var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1781
1882
 
1782
1883
  // ../commons/src/events/Draft.ts
1783
- var import_zod21 = require("zod");
1884
+ var import_zod23 = require("zod");
1784
1885
 
1785
1886
  // ../commons/src/events/ActionDocument.ts
1786
- var import_zod19 = require("zod");
1787
- var ActionUpdate = import_zod19.z.record(import_zod19.z.string(), FieldUpdateValue);
1788
- var ActionBase = import_zod19.z.object({
1789
- id: import_zod19.z.string(),
1790
- createdAt: import_zod19.z.string().datetime(),
1791
- createdBy: import_zod19.z.string(),
1792
- data: ActionUpdate,
1793
- metadata: ActionUpdate.optional(),
1794
- createdAtLocation: import_zod19.z.string()
1887
+ var import_zod21 = require("zod");
1888
+ var ActionUpdate = import_zod21.z.record(import_zod21.z.string(), FieldUpdateValue);
1889
+ var ActionStatus = {
1890
+ Requested: "Requested",
1891
+ Accepted: "Accepted",
1892
+ Rejected: "Rejected"
1893
+ };
1894
+ var ActionBase = import_zod21.z.object({
1895
+ id: import_zod21.z.string(),
1896
+ createdAt: import_zod21.z.string().datetime(),
1897
+ createdBy: import_zod21.z.string(),
1898
+ declaration: ActionUpdate,
1899
+ annotation: ActionUpdate.optional(),
1900
+ createdAtLocation: import_zod21.z.string(),
1901
+ status: import_zod21.z.enum([
1902
+ ActionStatus.Requested,
1903
+ ActionStatus.Accepted,
1904
+ ActionStatus.Rejected
1905
+ ]),
1906
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1907
+ originalActionId: import_zod21.z.string().optional()
1795
1908
  });
1796
1909
  var AssignedAction = ActionBase.merge(
1797
- import_zod19.z.object({
1798
- type: import_zod19.z.literal(ActionType.ASSIGN),
1799
- assignedTo: import_zod19.z.string()
1910
+ import_zod21.z.object({
1911
+ type: import_zod21.z.literal(ActionType.ASSIGN),
1912
+ assignedTo: import_zod21.z.string()
1800
1913
  })
1801
1914
  );
1802
1915
  var UnassignedAction = ActionBase.merge(
1803
- import_zod19.z.object({
1804
- type: import_zod19.z.literal(ActionType.UNASSIGN)
1916
+ import_zod21.z.object({
1917
+ type: import_zod21.z.literal(ActionType.UNASSIGN)
1805
1918
  })
1806
1919
  );
1807
1920
  var RegisterAction = ActionBase.merge(
1808
- import_zod19.z.object({
1809
- type: import_zod19.z.literal(ActionType.REGISTER),
1810
- identifiers: import_zod19.z.object({
1811
- trackingId: import_zod19.z.string(),
1812
- registrationNumber: import_zod19.z.string()
1813
- })
1921
+ import_zod21.z.object({
1922
+ type: import_zod21.z.literal(ActionType.REGISTER),
1923
+ registrationNumber: import_zod21.z.string().optional()
1814
1924
  })
1815
1925
  );
1816
1926
  var DeclareAction = ActionBase.merge(
1817
- import_zod19.z.object({
1818
- type: import_zod19.z.literal(ActionType.DECLARE)
1927
+ import_zod21.z.object({
1928
+ type: import_zod21.z.literal(ActionType.DECLARE)
1819
1929
  })
1820
1930
  );
1821
1931
  var ValidateAction = ActionBase.merge(
1822
- import_zod19.z.object({
1823
- type: import_zod19.z.literal(ActionType.VALIDATE)
1932
+ import_zod21.z.object({
1933
+ type: import_zod21.z.literal(ActionType.VALIDATE)
1824
1934
  })
1825
1935
  );
1826
1936
  var RejectAction = ActionBase.merge(
1827
- import_zod19.z.object({
1828
- type: import_zod19.z.literal(ActionType.REJECT)
1937
+ import_zod21.z.object({
1938
+ type: import_zod21.z.literal(ActionType.REJECT)
1829
1939
  })
1830
1940
  );
1831
1941
  var MarkAsDuplicateAction = ActionBase.merge(
1832
- import_zod19.z.object({
1833
- type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1942
+ import_zod21.z.object({
1943
+ type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE)
1834
1944
  })
1835
1945
  );
1836
1946
  var ArchiveAction = ActionBase.merge(
1837
- import_zod19.z.object({
1838
- type: import_zod19.z.literal(ActionType.ARCHIVE)
1947
+ import_zod21.z.object({
1948
+ type: import_zod21.z.literal(ActionType.ARCHIVE)
1839
1949
  })
1840
1950
  );
1841
1951
  var CreatedAction = ActionBase.merge(
1842
- import_zod19.z.object({
1843
- type: import_zod19.z.literal(ActionType.CREATE)
1952
+ import_zod21.z.object({
1953
+ type: import_zod21.z.literal(ActionType.CREATE)
1844
1954
  })
1845
1955
  );
1846
1956
  var NotifiedAction = ActionBase.merge(
1847
- import_zod19.z.object({
1848
- type: import_zod19.z.literal(ActionType.NOTIFY)
1957
+ import_zod21.z.object({
1958
+ type: import_zod21.z.literal(ActionType.NOTIFY)
1849
1959
  })
1850
1960
  );
1851
1961
  var PrintCertificateAction = ActionBase.merge(
1852
- import_zod19.z.object({
1853
- type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE)
1962
+ import_zod21.z.object({
1963
+ type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE)
1854
1964
  })
1855
1965
  );
1856
1966
  var RequestedCorrectionAction = ActionBase.merge(
1857
- import_zod19.z.object({
1858
- type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION)
1967
+ import_zod21.z.object({
1968
+ type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION)
1859
1969
  })
1860
1970
  );
1861
1971
  var ApprovedCorrectionAction = ActionBase.merge(
1862
- import_zod19.z.object({
1863
- type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION),
1864
- requestId: import_zod19.z.string()
1972
+ import_zod21.z.object({
1973
+ type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION),
1974
+ requestId: import_zod21.z.string()
1865
1975
  })
1866
1976
  );
1867
1977
  var RejectedCorrectionAction = ActionBase.merge(
1868
- import_zod19.z.object({
1869
- type: import_zod19.z.literal(ActionType.REJECT_CORRECTION),
1870
- requestId: import_zod19.z.string()
1978
+ import_zod21.z.object({
1979
+ type: import_zod21.z.literal(ActionType.REJECT_CORRECTION),
1980
+ requestId: import_zod21.z.string()
1871
1981
  })
1872
1982
  );
1873
- var CustomAction = ActionBase.merge(
1874
- import_zod19.z.object({
1875
- type: import_zod19.z.literal(ActionType.CUSTOM)
1983
+ var ReadAction = ActionBase.merge(
1984
+ import_zod21.z.object({
1985
+ type: import_zod21.z.literal(ActionType.READ)
1876
1986
  })
1877
1987
  );
1878
- var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1988
+ var ActionDocument = import_zod21.z.discriminatedUnion("type", [
1879
1989
  CreatedAction,
1880
1990
  ValidateAction,
1881
1991
  RejectAction,
@@ -1890,108 +2000,124 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1890
2000
  RejectedCorrectionAction,
1891
2001
  UnassignedAction,
1892
2002
  PrintCertificateAction,
1893
- CustomAction
2003
+ ReadAction
1894
2004
  ]);
1895
- var ResolvedUser = import_zod19.z.object({
1896
- id: import_zod19.z.string(),
1897
- role: import_zod19.z.string(),
1898
- name: import_zod19.z.array(
1899
- import_zod19.z.object({
1900
- use: import_zod19.z.string(),
1901
- given: import_zod19.z.array(import_zod19.z.string()),
1902
- family: import_zod19.z.string()
2005
+ var AsyncRejectActionDocument = ActionBase.omit({
2006
+ declaration: true,
2007
+ annotation: true,
2008
+ createdBy: true,
2009
+ createdAtLocation: true
2010
+ }).merge(
2011
+ import_zod21.z.object({
2012
+ type: import_zod21.z.enum(ConfirmableActions),
2013
+ status: import_zod21.z.literal(ActionStatus.Rejected)
2014
+ })
2015
+ );
2016
+ var Action = import_zod21.z.union([ActionDocument, AsyncRejectActionDocument]);
2017
+ var ResolvedUser = import_zod21.z.object({
2018
+ id: import_zod21.z.string(),
2019
+ role: import_zod21.z.string(),
2020
+ name: import_zod21.z.array(
2021
+ import_zod21.z.object({
2022
+ use: import_zod21.z.string(),
2023
+ given: import_zod21.z.array(import_zod21.z.string()),
2024
+ family: import_zod21.z.string()
1903
2025
  })
1904
2026
  )
1905
2027
  });
1906
2028
 
1907
2029
  // ../commons/src/events/ActionInput.ts
1908
- var import_zod20 = require("zod");
1909
- var BaseActionInput = import_zod20.z.object({
1910
- eventId: import_zod20.z.string(),
1911
- transactionId: import_zod20.z.string(),
1912
- data: ActionUpdate,
1913
- metadata: ActionUpdate.optional()
2030
+ var import_zod22 = require("zod");
2031
+ var BaseActionInput = import_zod22.z.object({
2032
+ eventId: import_zod22.z.string(),
2033
+ transactionId: import_zod22.z.string(),
2034
+ declaration: ActionUpdate.default({}),
2035
+ annotation: ActionUpdate.optional(),
2036
+ originalActionId: import_zod22.z.string().optional()
1914
2037
  });
1915
2038
  var CreateActionInput = BaseActionInput.merge(
1916
- import_zod20.z.object({
1917
- type: import_zod20.z.literal(ActionType.CREATE).default(ActionType.CREATE),
1918
- createdAtLocation: import_zod20.z.string()
2039
+ import_zod22.z.object({
2040
+ type: import_zod22.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2041
+ createdAtLocation: import_zod22.z.string()
1919
2042
  })
1920
2043
  );
1921
2044
  var RegisterActionInput = BaseActionInput.merge(
1922
- import_zod20.z.object({
1923
- type: import_zod20.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
1924
- identifiers: import_zod20.z.object({
1925
- trackingId: import_zod20.z.string(),
1926
- registrationNumber: import_zod20.z.string()
1927
- })
2045
+ import_zod22.z.object({
2046
+ type: import_zod22.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2047
+ registrationNumber: import_zod22.z.string().optional()
1928
2048
  })
1929
2049
  );
1930
2050
  var ValidateActionInput = BaseActionInput.merge(
1931
- import_zod20.z.object({
1932
- type: import_zod20.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
1933
- duplicates: import_zod20.z.array(import_zod20.z.string())
2051
+ import_zod22.z.object({
2052
+ type: import_zod22.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2053
+ duplicates: import_zod22.z.array(import_zod22.z.string())
1934
2054
  })
1935
2055
  );
1936
2056
  var NotifyActionInput = BaseActionInput.merge(
1937
- import_zod20.z.object({
1938
- type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2057
+ import_zod22.z.object({
2058
+ type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1939
2059
  })
1940
2060
  );
1941
2061
  var DeclareActionInput = BaseActionInput.merge(
1942
- import_zod20.z.object({
1943
- type: import_zod20.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2062
+ import_zod22.z.object({
2063
+ type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1944
2064
  })
1945
2065
  );
1946
2066
  var PrintCertificateActionInput = BaseActionInput.merge(
1947
- import_zod20.z.object({
1948
- type: import_zod20.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2067
+ import_zod22.z.object({
2068
+ type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1949
2069
  })
1950
2070
  );
1951
2071
  var RejectDeclarationActionInput = BaseActionInput.merge(
1952
- import_zod20.z.object({
1953
- type: import_zod20.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2072
+ import_zod22.z.object({
2073
+ type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1954
2074
  })
1955
2075
  );
1956
2076
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1957
- import_zod20.z.object({
1958
- type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2077
+ import_zod22.z.object({
2078
+ type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1959
2079
  })
1960
2080
  );
1961
2081
  var ArchiveActionInput = BaseActionInput.merge(
1962
- import_zod20.z.object({
1963
- type: import_zod20.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2082
+ import_zod22.z.object({
2083
+ type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1964
2084
  })
1965
2085
  );
1966
2086
  var AssignActionInput = BaseActionInput.merge(
1967
- import_zod20.z.object({
1968
- type: import_zod20.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
1969
- assignedTo: import_zod20.z.string()
2087
+ import_zod22.z.object({
2088
+ type: import_zod22.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2089
+ assignedTo: import_zod22.z.string()
1970
2090
  })
1971
2091
  );
1972
2092
  var UnassignActionInput = BaseActionInput.merge(
1973
- import_zod20.z.object({
1974
- type: import_zod20.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN)
2093
+ import_zod22.z.object({
2094
+ type: import_zod22.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2095
+ assignedTo: import_zod22.z.literal(null).default(null)
1975
2096
  })
1976
2097
  );
1977
2098
  var RequestCorrectionActionInput = BaseActionInput.merge(
1978
- import_zod20.z.object({
1979
- type: import_zod20.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2099
+ import_zod22.z.object({
2100
+ type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
1980
2101
  })
1981
2102
  );
1982
2103
  var RejectCorrectionActionInput = BaseActionInput.merge(
1983
- import_zod20.z.object({
1984
- requestId: import_zod20.z.string(),
1985
- type: import_zod20.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2104
+ import_zod22.z.object({
2105
+ requestId: import_zod22.z.string(),
2106
+ type: import_zod22.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
1986
2107
  })
1987
2108
  );
1988
2109
  var ApproveCorrectionActionInput = BaseActionInput.merge(
1989
- import_zod20.z.object({
1990
- requestId: import_zod20.z.string(),
1991
- type: import_zod20.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2110
+ import_zod22.z.object({
2111
+ requestId: import_zod22.z.string(),
2112
+ type: import_zod22.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
1992
2113
  })
1993
2114
  );
1994
- var ActionInput = import_zod20.z.discriminatedUnion("type", [
2115
+ var ReadActionInput = BaseActionInput.merge(
2116
+ import_zod22.z.object({
2117
+ type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
2118
+ })
2119
+ );
2120
+ var ActionInput = import_zod22.z.discriminatedUnion("type", [
1995
2121
  CreateActionInput,
1996
2122
  ValidateActionInput,
1997
2123
  RegisterActionInput,
@@ -2005,56 +2131,63 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
2005
2131
  PrintCertificateActionInput,
2006
2132
  RequestCorrectionActionInput,
2007
2133
  RejectCorrectionActionInput,
2008
- ApproveCorrectionActionInput
2134
+ ApproveCorrectionActionInput,
2135
+ ReadActionInput
2009
2136
  ]);
2010
2137
 
2011
2138
  // ../commons/src/events/Draft.ts
2012
- var Draft = import_zod21.z.object({
2013
- id: import_zod21.z.string(),
2014
- eventId: import_zod21.z.string(),
2015
- transactionId: import_zod21.z.string(),
2016
- createdAt: import_zod21.z.string().datetime(),
2139
+ var Draft = import_zod23.z.object({
2140
+ id: import_zod23.z.string(),
2141
+ eventId: import_zod23.z.string(),
2142
+ transactionId: import_zod23.z.string(),
2143
+ createdAt: import_zod23.z.string().datetime(),
2017
2144
  action: ActionBase.extend({
2018
- type: import_zod21.z.enum(Object.values(ActionType))
2145
+ type: ActionTypes
2019
2146
  }).omit({ id: true })
2020
2147
  });
2021
2148
  var DraftInput = BaseActionInput.extend({
2022
- type: import_zod21.z.enum(Object.values(ActionType))
2149
+ type: ActionTypes
2023
2150
  });
2024
2151
 
2025
2152
  // ../commons/src/events/EventInput.ts
2026
- var import_zod22 = require("zod");
2027
- var EventInput = import_zod22.z.object({
2028
- transactionId: import_zod22.z.string(),
2029
- type: import_zod22.z.string()
2153
+ var import_zod24 = require("zod");
2154
+ var EventInput = import_zod24.z.object({
2155
+ transactionId: import_zod24.z.string(),
2156
+ type: import_zod24.z.string()
2030
2157
  });
2031
2158
 
2032
2159
  // ../commons/src/events/EventDocument.ts
2033
- var import_zod23 = require("zod");
2034
- var EventDocument = import_zod23.z.object({
2035
- id: import_zod23.z.string(),
2036
- type: import_zod23.z.string(),
2037
- createdAt: import_zod23.z.string().datetime(),
2038
- updatedAt: import_zod23.z.string().datetime(),
2039
- actions: import_zod23.z.array(ActionDocument),
2040
- trackingId: import_zod23.z.string()
2160
+ var import_zod25 = require("zod");
2161
+ var EventDocument = import_zod25.z.object({
2162
+ id: import_zod25.z.string(),
2163
+ type: import_zod25.z.string(),
2164
+ createdAt: import_zod25.z.string().datetime(),
2165
+ updatedAt: import_zod25.z.string().datetime(),
2166
+ updatedAtLocation: import_zod25.z.string(),
2167
+ actions: import_zod25.z.array(Action),
2168
+ trackingId: import_zod25.z.string()
2041
2169
  });
2042
2170
 
2043
2171
  // ../commons/src/events/EventIndex.ts
2044
- var import_zod24 = require("zod");
2172
+ var import_zod26 = require("zod");
2045
2173
  var EventIndex = EventMetadata.extend({
2046
- data: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any())
2174
+ declaration: import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any())
2047
2175
  });
2048
- var EventSearchIndex = import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any()).and(
2049
- import_zod24.z.object({
2050
- type: import_zod24.z.string()
2176
+ var EventSearchIndex = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any()).and(
2177
+ import_zod26.z.object({
2178
+ type: import_zod26.z.string()
2051
2179
  // Ensures "type" (event-id) exists and is a string
2052
2180
  })
2053
2181
  );
2054
2182
 
2055
2183
  // ../commons/src/events/state/index.ts
2056
- var _ = __toESM(require("lodash"));
2057
2184
  function getStatusFromActions(actions) {
2185
+ const hasRejectedAction = actions.some(
2186
+ (a) => a.status === ActionStatus.Rejected
2187
+ );
2188
+ if (hasRejectedAction) {
2189
+ return EventStatus.REJECTED;
2190
+ }
2058
2191
  return actions.reduce((status, action) => {
2059
2192
  if (action.type === ActionType.CREATE) {
2060
2193
  return EventStatus.CREATED;
@@ -2091,7 +2224,7 @@ function getAssignedUserFromActions(actions) {
2091
2224
  return user2;
2092
2225
  }, null);
2093
2226
  }
2094
- function getData(actions) {
2227
+ function aggregateActionDeclarations(actions) {
2095
2228
  const excludedActions = [
2096
2229
  ActionType.REQUEST_CORRECTION,
2097
2230
  ActionType.PRINT_CERTIFICATE
@@ -2105,47 +2238,35 @@ function getData(actions) {
2105
2238
  if (!requestAction) {
2106
2239
  return status;
2107
2240
  }
2108
- return deepMerge(status, requestAction.data);
2241
+ return deepMerge(status, requestAction.declaration);
2109
2242
  }
2110
- return deepMerge(status, action.data);
2243
+ return deepMerge(status, action.declaration);
2111
2244
  }, {});
2112
2245
  }
2113
2246
  function deepDropNulls(obj) {
2114
- if (!_.isObject(obj)) return obj;
2115
- return Object.entries(obj).reduce((acc, [key, value]) => {
2116
- if (_.isObject(value)) {
2117
- value = deepDropNulls(value);
2118
- }
2119
- if (value !== null) {
2120
- return {
2121
- ...acc,
2122
- [key]: value
2123
- };
2124
- }
2125
- return acc;
2126
- }, {});
2127
- }
2128
- function deepMerge(currentDocument, actionDocument) {
2129
- return _.mergeWith(
2130
- currentDocument,
2131
- actionDocument,
2132
- (previousValue, incomingValue) => {
2133
- if (incomingValue === void 0) {
2134
- return previousValue;
2135
- }
2136
- if (_.isArray(incomingValue)) {
2137
- return incomingValue;
2138
- }
2139
- if (_.isObject(previousValue) && _.isObject(incomingValue)) {
2140
- return void 0;
2247
+ if (Array.isArray(obj)) {
2248
+ return obj;
2249
+ }
2250
+ if (obj !== null && typeof obj === "object") {
2251
+ return Object.entries(obj).reduce((acc, [key, value]) => {
2252
+ const cleanedValue = deepDropNulls(value);
2253
+ if (cleanedValue !== null) {
2254
+ ;
2255
+ acc[key] = cleanedValue;
2141
2256
  }
2142
- return incomingValue;
2143
- }
2144
- );
2257
+ return acc;
2258
+ }, {});
2259
+ }
2260
+ return obj;
2145
2261
  }
2146
2262
  function isUndeclaredDraft(status) {
2147
2263
  return status === EventStatus.CREATED;
2148
2264
  }
2265
+ function getAcceptedActions(event2) {
2266
+ return event2.actions.filter(
2267
+ (a) => a.status === ActionStatus.Accepted
2268
+ );
2269
+ }
2149
2270
  function getCurrentEventState(event2) {
2150
2271
  const creationAction = event2.actions.find(
2151
2272
  (action) => action.type === ActionType.CREATE
@@ -2153,7 +2274,12 @@ function getCurrentEventState(event2) {
2153
2274
  if (!creationAction) {
2154
2275
  throw new Error(`Event ${event2.id} has no creation action`);
2155
2276
  }
2156
- const latestAction = event2.actions[event2.actions.length - 1];
2277
+ const activeActions = getAcceptedActions(event2);
2278
+ const latestAction = activeActions[activeActions.length - 1];
2279
+ const registrationAction = activeActions.find(
2280
+ (a) => a.type === ActionType.REGISTER && a.status === ActionStatus.Accepted
2281
+ );
2282
+ const registrationNumber = registrationAction?.registrationNumber ?? null;
2157
2283
  return deepDropNulls({
2158
2284
  id: event2.id,
2159
2285
  type: event2.type,
@@ -2162,10 +2288,12 @@ function getCurrentEventState(event2) {
2162
2288
  createdBy: creationAction.createdBy,
2163
2289
  createdAtLocation: creationAction.createdAtLocation,
2164
2290
  modifiedAt: latestAction.createdAt,
2165
- assignedTo: getAssignedUserFromActions(event2.actions),
2291
+ assignedTo: getAssignedUserFromActions(activeActions),
2166
2292
  updatedBy: latestAction.createdBy,
2167
- data: getData(event2.actions),
2168
- trackingId: event2.trackingId
2293
+ updatedAtLocation: event2.updatedAtLocation,
2294
+ declaration: aggregateActionDeclarations(activeActions),
2295
+ trackingId: event2.trackingId,
2296
+ registrationNumber
2169
2297
  });
2170
2298
  }
2171
2299
  function getCurrentEventStateWithDrafts(event2, drafts) {
@@ -2197,38 +2325,44 @@ function applyDraftsToEventIndex(eventIndex, drafts) {
2197
2325
  }
2198
2326
  return {
2199
2327
  ...eventIndex,
2200
- data: {
2201
- ...eventIndex.data,
2202
- ...activeDrafts[activeDrafts.length - 1].data
2328
+ declaration: {
2329
+ ...eventIndex.declaration,
2330
+ ...activeDrafts[activeDrafts.length - 1].declaration
2203
2331
  }
2204
2332
  };
2205
2333
  }
2206
- function getMetadataForAction({
2334
+ function getAnnotationFromDrafts(drafts) {
2335
+ const actions = drafts.map((draft) => draft.action);
2336
+ const annotation = actions.reduce((ann, action) => {
2337
+ return deepMerge(ann, action.annotation ?? {});
2338
+ }, {});
2339
+ return deepDropNulls(annotation);
2340
+ }
2341
+ function getActionAnnotation({
2207
2342
  event: event2,
2208
2343
  actionType,
2209
2344
  drafts
2210
2345
  }) {
2211
- const action = event2.actions.find((action2) => actionType === action2.type);
2346
+ const activeActions = getAcceptedActions(event2);
2347
+ const action = activeActions.find(
2348
+ (activeAction) => actionType === activeAction.type
2349
+ );
2212
2350
  const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
2213
2351
  const sorted = [
2214
2352
  ...action ? [action] : [],
2215
2353
  ...eventDrafts.map((draft) => draft.action)
2216
2354
  ].sort();
2217
- const metadata = sorted.reduce((metadata2, action2) => {
2218
- return deepMerge(metadata2, action2.metadata ?? {});
2355
+ const annotation = sorted.reduce((ann, sortedAction) => {
2356
+ return deepMerge(ann, sortedAction.annotation ?? {});
2219
2357
  }, {});
2220
- return deepDropNulls(metadata);
2358
+ return deepDropNulls(annotation);
2221
2359
  }
2222
2360
 
2223
2361
  // ../commons/src/events/defineConfig.ts
2224
2362
  var defineConfig = (config) => {
2225
2363
  validateWorkqueueConfig(config.workqueues);
2226
2364
  const input = EventConfig.parse(config);
2227
- const pageFields = findInputPageFields(input);
2228
- return EventConfig.parse({
2229
- ...input,
2230
- pageFields
2231
- });
2365
+ return input;
2232
2366
  };
2233
2367
 
2234
2368
  // ../commons/src/events/transactions.ts
@@ -2243,6 +2377,16 @@ var import_lodash2 = require("lodash");
2243
2377
  function defineConditional(schema) {
2244
2378
  return schema;
2245
2379
  }
2380
+ function defineFormConditional(schema) {
2381
+ const schemaWithForm = {
2382
+ type: "object",
2383
+ properties: {
2384
+ $form: schema
2385
+ },
2386
+ required: ["$form"]
2387
+ };
2388
+ return defineConditional(schemaWithForm);
2389
+ }
2246
2390
  function alwaysTrue() {
2247
2391
  return {};
2248
2392
  }
@@ -2267,6 +2411,9 @@ function not(condition) {
2267
2411
  required: []
2268
2412
  });
2269
2413
  }
2414
+ function never() {
2415
+ return not(alwaysTrue());
2416
+ }
2270
2417
  var user = {
2271
2418
  hasScope: (scope) => defineConditional({
2272
2419
  type: "object",
@@ -2314,69 +2461,120 @@ var event = {
2314
2461
  required: ["$event"]
2315
2462
  })
2316
2463
  };
2464
+ function getDateFromNow(days) {
2465
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2466
+ }
2467
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2468
+ return {
2469
+ type: "object",
2470
+ properties: {
2471
+ [fieldId]: {
2472
+ type: "string",
2473
+ format: "date",
2474
+ [clause]: { $data: `1/${comparedFieldId}` }
2475
+ },
2476
+ [comparedFieldId]: { type: "string", format: "date" }
2477
+ },
2478
+ required: [fieldId]
2479
+ };
2480
+ }
2481
+ function isFieldReference(value) {
2482
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2483
+ }
2317
2484
  function field(fieldId) {
2318
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2319
2485
  const getDateRange = (date, clause) => ({
2320
2486
  type: "object",
2321
2487
  properties: {
2322
- $form: {
2323
- type: "object",
2324
- properties: {
2325
- [fieldId]: {
2326
- type: "string",
2327
- format: "date",
2328
- [clause]: date
2329
- }
2330
- },
2331
- required: [fieldId]
2488
+ [fieldId]: {
2489
+ type: "string",
2490
+ format: "date",
2491
+ [clause]: date
2332
2492
  }
2333
2493
  },
2334
- required: ["$form"]
2494
+ required: [fieldId]
2335
2495
  });
2336
2496
  return {
2497
+ /**
2498
+ * @private Internal property used for field reference tracking.
2499
+ */
2500
+ _fieldId: fieldId,
2337
2501
  isAfter: () => ({
2338
2502
  days: (days) => ({
2339
- inPast: () => defineConditional(
2503
+ inPast: () => defineFormConditional(
2340
2504
  getDateRange(getDateFromNow(days), "formatMinimum")
2341
2505
  ),
2342
- inFuture: () => defineConditional(
2506
+ inFuture: () => defineFormConditional(
2343
2507
  getDateRange(getDateFromNow(-days), "formatMinimum")
2344
2508
  )
2345
2509
  }),
2346
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
2347
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2510
+ date: (date) => {
2511
+ if (isFieldReference(date)) {
2512
+ const comparedFieldId = date._fieldId;
2513
+ return defineFormConditional(
2514
+ getDateRangeToFieldReference(
2515
+ fieldId,
2516
+ comparedFieldId,
2517
+ "formatMinimum"
2518
+ )
2519
+ );
2520
+ }
2521
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2522
+ },
2523
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2348
2524
  }),
2349
2525
  isBefore: () => ({
2350
2526
  days: (days) => ({
2351
- inPast: () => defineConditional(
2527
+ inPast: () => defineFormConditional(
2352
2528
  getDateRange(getDateFromNow(days), "formatMaximum")
2353
2529
  ),
2354
- inFuture: () => defineConditional(
2530
+ inFuture: () => defineFormConditional(
2355
2531
  getDateRange(getDateFromNow(-days), "formatMaximum")
2356
2532
  )
2357
2533
  }),
2358
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
2359
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2534
+ date: (date) => {
2535
+ if (isFieldReference(date)) {
2536
+ const comparedFieldId = date._fieldId;
2537
+ return defineFormConditional(
2538
+ getDateRangeToFieldReference(
2539
+ fieldId,
2540
+ comparedFieldId,
2541
+ "formatMaximum"
2542
+ )
2543
+ );
2544
+ }
2545
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2546
+ },
2547
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2360
2548
  }),
2361
- isEqualTo: (value) => defineConditional({
2362
- type: "object",
2363
- properties: {
2364
- $form: {
2549
+ isEqualTo: (value) => {
2550
+ if (isFieldReference(value)) {
2551
+ const comparedFieldId = value._fieldId;
2552
+ return defineFormConditional({
2365
2553
  type: "object",
2366
2554
  properties: {
2367
2555
  [fieldId]: {
2368
- oneOf: [
2369
- { type: "string", const: value },
2370
- { type: "boolean", const: value }
2371
- ],
2372
- const: value
2373
- }
2556
+ type: ["string", "boolean"],
2557
+ const: { $data: `1/${comparedFieldId}` }
2558
+ },
2559
+ [comparedFieldId]: { type: ["string", "boolean"] }
2374
2560
  },
2375
- required: [fieldId]
2376
- }
2377
- },
2378
- required: ["$form"]
2379
- }),
2561
+ required: [fieldId, comparedFieldId]
2562
+ });
2563
+ }
2564
+ return defineFormConditional({
2565
+ type: "object",
2566
+ properties: {
2567
+ [fieldId]: {
2568
+ oneOf: [
2569
+ { type: "string", const: value },
2570
+ { type: "boolean", const: value }
2571
+ ],
2572
+ const: value
2573
+ }
2574
+ },
2575
+ required: [fieldId]
2576
+ });
2577
+ },
2380
2578
  /**
2381
2579
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
2382
2580
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -2385,108 +2583,102 @@ function field(fieldId) {
2385
2583
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2386
2584
  *
2387
2585
  */
2388
- isFalsy: () => defineConditional({
2586
+ isFalsy: () => defineFormConditional({
2389
2587
  type: "object",
2390
2588
  properties: {
2391
- $form: {
2392
- type: "object",
2393
- properties: {
2394
- [fieldId]: {
2395
- anyOf: [
2396
- { const: "undefined" },
2397
- { const: false },
2398
- { const: null },
2399
- { const: "" }
2400
- ]
2401
- }
2402
- },
2589
+ [fieldId]: {
2403
2590
  anyOf: [
2404
- {
2405
- required: [fieldId]
2406
- },
2407
- {
2408
- not: {
2409
- required: [fieldId]
2410
- }
2411
- }
2591
+ { const: "undefined" },
2592
+ { const: false },
2593
+ { const: null },
2594
+ { const: "" }
2412
2595
  ]
2413
2596
  }
2414
2597
  },
2415
- required: ["$form"]
2416
- }),
2417
- isUndefined: () => defineConditional({
2418
- type: "object",
2419
- properties: {
2420
- $form: {
2421
- type: "object",
2422
- properties: {
2423
- [fieldId]: {
2424
- type: "string",
2425
- enum: ["undefined"]
2426
- }
2427
- },
2598
+ anyOf: [
2599
+ {
2600
+ required: [fieldId]
2601
+ },
2602
+ {
2428
2603
  not: {
2429
2604
  required: [fieldId]
2430
2605
  }
2431
2606
  }
2607
+ ]
2608
+ }),
2609
+ isUndefined: () => defineFormConditional({
2610
+ type: "object",
2611
+ properties: {
2612
+ [fieldId]: {
2613
+ type: "string",
2614
+ enum: ["undefined"]
2615
+ }
2432
2616
  },
2433
- required: ["$form"]
2617
+ not: {
2618
+ required: [fieldId]
2619
+ }
2434
2620
  }),
2435
- inArray: (values) => defineConditional({
2621
+ inArray: (values) => defineFormConditional({
2436
2622
  type: "object",
2437
2623
  properties: {
2438
- $form: {
2439
- type: "object",
2440
- properties: {
2441
- [fieldId]: {
2442
- type: "string",
2443
- enum: values
2444
- }
2445
- },
2446
- required: [fieldId]
2624
+ [fieldId]: {
2625
+ type: "string",
2626
+ enum: values
2447
2627
  }
2448
2628
  },
2449
- required: ["$form"]
2629
+ required: [fieldId]
2450
2630
  }),
2451
- isValidEnglishName: () => defineConditional({
2631
+ isValidEnglishName: () => defineFormConditional({
2452
2632
  type: "object",
2453
2633
  properties: {
2454
- $form: {
2455
- type: "object",
2456
- properties: {
2457
- [fieldId]: {
2458
- type: "string",
2459
- 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'._-]*)*$",
2460
- description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2461
- }
2462
- },
2463
- required: [fieldId]
2634
+ [fieldId]: {
2635
+ type: "string",
2636
+ 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'._-]*)*$",
2637
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2638
+ }
2639
+ },
2640
+ required: [fieldId]
2641
+ }),
2642
+ /**
2643
+ * Checks if the field value matches a given regular expression pattern.
2644
+ * @param pattern - The regular expression pattern to match the field value against.
2645
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2646
+ */
2647
+ matches: (pattern) => defineFormConditional({
2648
+ type: "object",
2649
+ properties: {
2650
+ [fieldId]: {
2651
+ type: "string",
2652
+ pattern
2464
2653
  }
2465
2654
  },
2466
- required: ["$form"]
2655
+ required: [fieldId]
2656
+ }),
2657
+ isBetween: (min, max) => defineFormConditional({
2658
+ type: "object",
2659
+ properties: {
2660
+ [fieldId]: {
2661
+ type: "number",
2662
+ minimum: min,
2663
+ maximum: max
2664
+ }
2665
+ },
2666
+ required: [fieldId]
2467
2667
  })
2468
2668
  };
2469
2669
  }
2470
2670
 
2471
2671
  // ../commons/src/fixtures/tennis-club-membership-event.ts
2472
- var PRINT_CERTIFICATE_FORM = defineForm({
2672
+ var PRINT_CERTIFICATE_FORM = defineActionForm({
2473
2673
  label: {
2474
2674
  id: "v2.event.tennis-club-membership.action.certificate.form.label",
2475
2675
  defaultMessage: "Tennis club membership certificate collector",
2476
2676
  description: "This is what this form is referred as in the system"
2477
2677
  },
2478
- version: {
2479
- id: "1.0.0",
2480
- label: {
2481
- id: "v2.event.tennis-club-membership.action.certificate.form.version.1",
2482
- defaultMessage: "Version 1",
2483
- description: "This is the first version of the form"
2484
- }
2485
- },
2486
- active: true,
2487
2678
  pages: [
2488
2679
  {
2489
2680
  id: "collector",
2681
+ type: PageTypes.enum.FORM,
2490
2682
  title: {
2491
2683
  id: "v2.event.tennis-club-membership.action.certificate.form.section.who.title",
2492
2684
  defaultMessage: "Print certified copy",
@@ -2501,7 +2693,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2501
2693
  defaultMessage: "Requester",
2502
2694
  description: "This is the label for the field"
2503
2695
  },
2504
- type: "SELECT",
2696
+ type: FieldType.SELECT,
2505
2697
  options: [
2506
2698
  {
2507
2699
  value: "INFORMANT",
@@ -2578,7 +2770,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2578
2770
  defaultMessage: "Select Type of ID",
2579
2771
  description: "This is the label for selecting the type of ID"
2580
2772
  },
2581
- type: "SELECT",
2773
+ type: FieldType.SELECT,
2582
2774
  options: [
2583
2775
  {
2584
2776
  value: "PASSPORT",
@@ -2679,7 +2871,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2679
2871
  defaultMessage: "Passport Details",
2680
2872
  description: "Field for entering Passport details"
2681
2873
  },
2682
- type: "TEXT"
2874
+ type: FieldType.TEXT
2683
2875
  },
2684
2876
  {
2685
2877
  id: "collector.DRIVING_LICENSE.details",
@@ -2730,7 +2922,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2730
2922
  defaultMessage: "Driving License Details",
2731
2923
  description: "Field for entering Driving License details"
2732
2924
  },
2733
- type: "TEXT"
2925
+ type: FieldType.TEXT
2734
2926
  },
2735
2927
  {
2736
2928
  id: "collector.REFUGEE_NUMBER.details",
@@ -2781,7 +2973,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2781
2973
  defaultMessage: "Refugee Number Details",
2782
2974
  description: "Field for entering Refugee Number details"
2783
2975
  },
2784
- type: "TEXT"
2976
+ type: FieldType.TEXT
2785
2977
  },
2786
2978
  {
2787
2979
  id: "collector.ALIEN_NUMBER.details",
@@ -2832,7 +3024,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2832
3024
  defaultMessage: "Alien Number Details",
2833
3025
  description: "Field for entering Alien Number details"
2834
3026
  },
2835
- type: "TEXT"
3027
+ type: FieldType.TEXT
2836
3028
  },
2837
3029
  {
2838
3030
  id: "collector.OTHER.idTypeOther",
@@ -2883,7 +3075,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2883
3075
  defaultMessage: "Other ID Type (if applicable)",
2884
3076
  description: 'Field for entering ID type if "Other" is selected'
2885
3077
  },
2886
- type: "TEXT"
3078
+ type: FieldType.TEXT
2887
3079
  },
2888
3080
  {
2889
3081
  id: "collector.OTHER.firstName",
@@ -2934,7 +3126,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2934
3126
  defaultMessage: "First Name",
2935
3127
  description: "This is the label for the first name field"
2936
3128
  },
2937
- type: "TEXT"
3129
+ type: FieldType.TEXT
2938
3130
  },
2939
3131
  {
2940
3132
  id: "collector.OTHER.lastName",
@@ -2985,7 +3177,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2985
3177
  defaultMessage: "Last Name",
2986
3178
  description: "This is the label for the last name field"
2987
3179
  },
2988
- type: "TEXT"
3180
+ type: FieldType.TEXT
2989
3181
  },
2990
3182
  {
2991
3183
  id: "collector.OTHER.relationshipToMember",
@@ -3036,7 +3228,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
3036
3228
  defaultMessage: "Relationship to Member",
3037
3229
  description: "This is the label for the relationship to member field"
3038
3230
  },
3039
- type: "TEXT"
3231
+ type: FieldType.TEXT
3040
3232
  },
3041
3233
  {
3042
3234
  id: "collector.OTHER.signedAffidavit",
@@ -3087,13 +3279,14 @@ var PRINT_CERTIFICATE_FORM = defineForm({
3087
3279
  defaultMessage: "Signed Affidavit (Optional)",
3088
3280
  description: "This is the label for uploading a signed affidavit"
3089
3281
  },
3090
- type: "FILE"
3282
+ type: FieldType.FILE
3091
3283
  }
3092
3284
  ]
3093
3285
  },
3094
3286
  {
3095
3287
  id: "collector.identity.verify",
3096
- type: FormPageType.VERIFICATION,
3288
+ type: PageTypes.enum.VERIFICATION,
3289
+ conditional: field("collector.requesterId").isEqualTo("INFORMANT"),
3097
3290
  title: {
3098
3291
  id: "event.tennis-club-membership.action.print.verifyIdentity",
3099
3292
  defaultMessage: "Verify their identity",
@@ -3129,62 +3322,45 @@ var PRINT_CERTIFICATE_FORM = defineForm({
3129
3322
  }
3130
3323
  }
3131
3324
  }
3132
- ],
3133
- review: {
3134
- title: {
3135
- id: "v2.event.tennis-club-membership.action.certificate.form.review.title",
3136
- defaultMessage: "Member certificate collector for {firstname} {surname}",
3137
- description: "Title of the form to show in review page"
3138
- },
3139
- fields: []
3140
- }
3325
+ ]
3141
3326
  });
3142
- var TENNIS_CLUB_FORM = defineForm({
3143
- label: {
3144
- id: "v2.event.tennis-club-membership.action.declare.form.label",
3145
- defaultMessage: "Tennis club membership application",
3146
- description: "This is what this form is referred as in the system"
3147
- },
3148
- active: true,
3149
- version: {
3150
- id: "1.0.0",
3151
- label: {
3152
- id: "v2.event.tennis-club-membership.action.declare.form.version.1",
3153
- defaultMessage: "Version 1",
3154
- description: "This is the first version of the form"
3155
- }
3327
+ var TENNIS_CLUB_DECLARATION_REVIEW = {
3328
+ title: {
3329
+ id: "v2.event.tennis-club-membership.action.declare.form.review.title",
3330
+ defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
3331
+ description: "Title of the review page"
3156
3332
  },
3157
- review: {
3158
- title: {
3159
- id: "v2.event.tennis-club-membership.action.declare.form.review.title",
3160
- defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
3161
- description: "Title of the form to show in review page"
3333
+ fields: [
3334
+ {
3335
+ id: "review.comment",
3336
+ type: FieldType.TEXTAREA,
3337
+ label: {
3338
+ defaultMessage: "Comment",
3339
+ id: "v2.event.birth.action.declare.form.review.comment.label",
3340
+ description: "Label for the comment field in the review section"
3341
+ }
3162
3342
  },
3163
- fields: [
3164
- {
3165
- id: "review.comment",
3166
- type: "TEXTAREA",
3167
- label: {
3168
- defaultMessage: "Comment",
3169
- id: "v2.event.birth.action.declare.form.review.comment.label",
3170
- description: "Label for the comment field in the review section"
3171
- }
3343
+ {
3344
+ type: FieldType.SIGNATURE,
3345
+ id: "review.signature",
3346
+ label: {
3347
+ defaultMessage: "Signature of informant",
3348
+ id: "v2.event.birth.action.declare.form.review.signature.label",
3349
+ description: "Label for the signature field in the review section"
3172
3350
  },
3173
- {
3174
- type: "SIGNATURE",
3175
- id: "review.signature",
3176
- label: {
3177
- defaultMessage: "Signature of informant",
3178
- id: "v2.event.birth.action.declare.form.review.signature.label",
3179
- description: "Label for the signature field in the review section"
3180
- },
3181
- signaturePromptLabel: {
3182
- id: "v2.signature.upload.modal.title",
3183
- defaultMessage: "Draw signature",
3184
- description: "Title for the modal to draw signature"
3185
- }
3351
+ signaturePromptLabel: {
3352
+ id: "v2.signature.upload.modal.title",
3353
+ defaultMessage: "Draw signature",
3354
+ description: "Title for the modal to draw signature"
3186
3355
  }
3187
- ]
3356
+ }
3357
+ ]
3358
+ };
3359
+ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3360
+ label: {
3361
+ id: "v2.event.tennis-club-membership.action.declare.form.label",
3362
+ defaultMessage: "Tennis club membership application",
3363
+ description: "This is what this form is referred as in the system"
3188
3364
  },
3189
3365
  pages: [
3190
3366
  {
@@ -3197,7 +3373,7 @@ var TENNIS_CLUB_FORM = defineForm({
3197
3373
  fields: [
3198
3374
  {
3199
3375
  id: "applicant.firstname",
3200
- type: "TEXT",
3376
+ type: FieldType.TEXT,
3201
3377
  required: true,
3202
3378
  conditionals: [],
3203
3379
  label: {
@@ -3208,7 +3384,7 @@ var TENNIS_CLUB_FORM = defineForm({
3208
3384
  },
3209
3385
  {
3210
3386
  id: "applicant.surname",
3211
- type: "TEXT",
3387
+ type: FieldType.TEXT,
3212
3388
  required: true,
3213
3389
  conditionals: [],
3214
3390
  label: {
@@ -3251,7 +3427,7 @@ var TENNIS_CLUB_FORM = defineForm({
3251
3427
  },
3252
3428
  {
3253
3429
  id: "applicant.image",
3254
- type: "FILE",
3430
+ type: FieldType.FILE,
3255
3431
  required: false,
3256
3432
  label: {
3257
3433
  defaultMessage: "Applicant's profile picture",
@@ -3272,6 +3448,27 @@ var TENNIS_CLUB_FORM = defineForm({
3272
3448
  }
3273
3449
  ]
3274
3450
  },
3451
+ {
3452
+ id: "senior-pass",
3453
+ conditional: field("applicant.dob").isBefore().date("1950-01-01"),
3454
+ title: {
3455
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.title",
3456
+ defaultMessage: "Assign senior pass for applicant",
3457
+ description: "This is the title of the section"
3458
+ },
3459
+ fields: [
3460
+ {
3461
+ id: "senior-pass.id",
3462
+ type: FieldType.TEXT,
3463
+ required: true,
3464
+ label: {
3465
+ defaultMessage: "Senior pass ID",
3466
+ description: "This is the label for the field",
3467
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.field.id.label"
3468
+ }
3469
+ }
3470
+ ]
3471
+ },
3275
3472
  {
3276
3473
  id: "recommender",
3277
3474
  title: {
@@ -3293,7 +3490,7 @@ var TENNIS_CLUB_FORM = defineForm({
3293
3490
  },
3294
3491
  {
3295
3492
  id: "recommender.firstname",
3296
- type: "TEXT",
3493
+ type: FieldType.TEXT,
3297
3494
  required: true,
3298
3495
  conditionals: [
3299
3496
  {
@@ -3309,7 +3506,7 @@ var TENNIS_CLUB_FORM = defineForm({
3309
3506
  },
3310
3507
  {
3311
3508
  id: "recommender.surname",
3312
- type: "TEXT",
3509
+ type: FieldType.TEXT,
3313
3510
  required: true,
3314
3511
  conditionals: [
3315
3512
  {
@@ -3325,7 +3522,7 @@ var TENNIS_CLUB_FORM = defineForm({
3325
3522
  },
3326
3523
  {
3327
3524
  id: "recommender.id",
3328
- type: "TEXT",
3525
+ type: FieldType.TEXT,
3329
3526
  required: true,
3330
3527
  conditionals: [
3331
3528
  {
@@ -3433,7 +3630,7 @@ var tennisClubMembershipEvent = defineConfig({
3433
3630
  description: "This is shown as the action name anywhere the user can trigger the action from",
3434
3631
  id: "event.tennis-club-membership.action.declare.label"
3435
3632
  },
3436
- forms: [TENNIS_CLUB_FORM]
3633
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3437
3634
  },
3438
3635
  {
3439
3636
  type: ActionType.VALIDATE,
@@ -3442,7 +3639,7 @@ var tennisClubMembershipEvent = defineConfig({
3442
3639
  description: "This is shown as the action name anywhere the user can trigger the action from",
3443
3640
  id: "event.tennis-club-membership.action.validate.label"
3444
3641
  },
3445
- forms: [TENNIS_CLUB_FORM]
3642
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3446
3643
  },
3447
3644
  {
3448
3645
  type: ActionType.REGISTER,
@@ -3451,7 +3648,7 @@ var tennisClubMembershipEvent = defineConfig({
3451
3648
  description: "This is shown as the action name anywhere the user can trigger the action from",
3452
3649
  id: "event.tennis-club-membership.action.register.label"
3453
3650
  },
3454
- forms: [TENNIS_CLUB_FORM]
3651
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3455
3652
  },
3456
3653
  {
3457
3654
  type: ActionType.REQUEST_CORRECTION,
@@ -3460,10 +3657,10 @@ var tennisClubMembershipEvent = defineConfig({
3460
3657
  description: "This is shown as the action name anywhere the user can trigger the action from",
3461
3658
  id: "event.tennis-club-membership.action.correction.request.label"
3462
3659
  },
3463
- forms: [TENNIS_CLUB_FORM],
3464
3660
  onboardingForm: [
3465
3661
  {
3466
3662
  id: "correction-requester",
3663
+ type: PageTypes.enum.FORM,
3467
3664
  title: {
3468
3665
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3469
3666
  defaultMessage: "Correction requester",
@@ -3527,6 +3724,7 @@ var tennisClubMembershipEvent = defineConfig({
3527
3724
  },
3528
3725
  {
3529
3726
  id: "identity-check",
3727
+ type: PageTypes.enum.FORM,
3530
3728
  title: {
3531
3729
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3532
3730
  defaultMessage: "Verify their identity",
@@ -3569,6 +3767,7 @@ var tennisClubMembershipEvent = defineConfig({
3569
3767
  additionalDetailsForm: [
3570
3768
  {
3571
3769
  id: "correction-request.supporting-documents",
3770
+ type: PageTypes.enum.FORM,
3572
3771
  title: {
3573
3772
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3574
3773
  defaultMessage: "Upload supporting documents",
@@ -3586,7 +3785,7 @@ var tennisClubMembershipEvent = defineConfig({
3586
3785
  },
3587
3786
  {
3588
3787
  id: "correction.supportingDocs",
3589
- type: "FILE",
3788
+ type: FieldType.FILE,
3590
3789
  label: {
3591
3790
  id: "correction.corrector.title",
3592
3791
  defaultMessage: "Upload supporting documents",
@@ -3630,6 +3829,7 @@ var tennisClubMembershipEvent = defineConfig({
3630
3829
  },
3631
3830
  {
3632
3831
  id: "correction-request.additional-details",
3832
+ type: PageTypes.enum.FORM,
3633
3833
  title: {
3634
3834
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3635
3835
  defaultMessage: "Reason for correction",
@@ -3638,7 +3838,7 @@ var tennisClubMembershipEvent = defineConfig({
3638
3838
  fields: [
3639
3839
  {
3640
3840
  id: "correction.request.reason",
3641
- type: "TEXT",
3841
+ type: FieldType.TEXT,
3642
3842
  label: {
3643
3843
  id: "correction.reason.title",
3644
3844
  defaultMessage: "Reason for correction?",
@@ -3651,7 +3851,6 @@ var tennisClubMembershipEvent = defineConfig({
3651
3851
  },
3652
3852
  {
3653
3853
  type: ActionType.APPROVE_CORRECTION,
3654
- forms: [TENNIS_CLUB_FORM],
3655
3854
  label: {
3656
3855
  defaultMessage: "Approve correction",
3657
3856
  description: "This is shown as the action name anywhere the user can trigger the action from",
@@ -3665,7 +3864,7 @@ var tennisClubMembershipEvent = defineConfig({
3665
3864
  defaultMessage: "Print certificate",
3666
3865
  description: "This is shown as the action name anywhere the user can trigger the action from"
3667
3866
  },
3668
- forms: [PRINT_CERTIFICATE_FORM],
3867
+ printForm: PRINT_CERTIFICATE_FORM,
3669
3868
  conditionals: [
3670
3869
  {
3671
3870
  type: "SHOW",
@@ -3712,8 +3911,7 @@ var tennisClubMembershipEvent = defineConfig({
3712
3911
  id: "v2.event.tennis-club-membership.action.archive.label",
3713
3912
  defaultMessage: "Archive",
3714
3913
  description: "This is shown as the action name anywhere the user can trigger the action from"
3715
- },
3716
- forms: [TENNIS_CLUB_FORM]
3914
+ }
3717
3915
  },
3718
3916
  {
3719
3917
  type: ActionType.REJECT,
@@ -3721,8 +3919,7 @@ var tennisClubMembershipEvent = defineConfig({
3721
3919
  id: "v2.event.tennis-club-membership.action.reject.label",
3722
3920
  defaultMessage: "Reject",
3723
3921
  description: "This is shown as the action name anywhere the user can trigger the action from"
3724
- },
3725
- forms: [TENNIS_CLUB_FORM]
3922
+ }
3726
3923
  }
3727
3924
  ],
3728
3925
  advancedSearch: [
@@ -3738,33 +3935,52 @@ var tennisClubMembershipEvent = defineConfig({
3738
3935
  }
3739
3936
  ]
3740
3937
  }
3741
- ]
3938
+ ],
3939
+ declaration: TENNIS_CLUB_DECLARATION_FORM
3742
3940
  });
3743
3941
 
3744
3942
  // ../commons/src/events/test.utils.ts
3745
- function generateActionInput(configuration, action) {
3746
- const fields = findActiveActionFormFields(configuration, action) ?? [];
3747
- const data = fields.reduce(
3943
+ function fieldConfigsToActionAnnotation(fields) {
3944
+ return fields.reduce(
3748
3945
  (acc, field2, i) => ({
3749
3946
  ...acc,
3750
3947
  [field2.id]: mapFieldTypeToMockValue(field2, i)
3751
3948
  }),
3752
3949
  {}
3753
3950
  );
3754
- return stripHiddenFields(fields, data);
3951
+ }
3952
+ function generateActionInput(configuration, action) {
3953
+ const parsed = DeclarationUpdateActions.safeParse(action);
3954
+ if (parsed.success) {
3955
+ const fields = getDeclarationFields(configuration);
3956
+ const annotation = fieldConfigsToActionAnnotation(fields);
3957
+ return stripHiddenFields(fields, annotation);
3958
+ }
3959
+ console.warn(`${action} is not a declaration action. Setting data as {}.`);
3960
+ return {};
3755
3961
  }
3756
3962
  function generateActionMetadataInput(configuration, action) {
3757
- const verificationPageIds = findActiveActionVerificationPageIds(
3963
+ const actionConfig = configuration.actions.find(
3964
+ (ac) => ac.type === action
3965
+ );
3966
+ const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
3967
+ const annotation = fieldConfigsToActionAnnotation(annotationFields);
3968
+ const visibleVerificationPageIds = findRecordActionPages(
3758
3969
  configuration,
3759
3970
  action
3760
- );
3761
- return verificationPageIds.reduce(
3971
+ ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
3972
+ const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
3762
3973
  (acc, pageId) => ({
3763
3974
  ...acc,
3764
3975
  [pageId]: true
3765
3976
  }),
3766
3977
  {}
3767
3978
  );
3979
+ const fieldBasedPayload = stripHiddenFields(annotationFields, annotation);
3980
+ return {
3981
+ ...fieldBasedPayload,
3982
+ ...visiblePageVerificationMap
3983
+ };
3768
3984
  }
3769
3985
  var eventPayloadGenerator = {
3770
3986
  create: (input = {}) => ({
@@ -3776,21 +3992,22 @@ var eventPayloadGenerator = {
3776
3992
  type: input.type ?? "TENNIS_CLUB_MEMBERSHIP",
3777
3993
  id
3778
3994
  }),
3779
- draft: (eventId, input = {}) => (0, import_lodash2.merge)(
3995
+ draft: ({ eventId, actionType }, input = {}) => (0, import_lodash2.merge)(
3780
3996
  {
3781
3997
  id: getUUID(),
3782
3998
  eventId,
3783
3999
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3784
4000
  transactionId: getUUID(),
3785
4001
  action: {
3786
- type: ActionType.REQUEST_CORRECTION,
3787
- data: {
4002
+ type: actionType,
4003
+ status: ActionStatus.Accepted,
4004
+ declaration: {
3788
4005
  "applicant.firstname": "Max",
3789
4006
  "applicant.surname": "McLaren",
3790
4007
  "applicant.dob": "2020-01-02",
3791
4008
  "recommender.none": true
3792
4009
  },
3793
- metadata: {
4010
+ annotation: {
3794
4011
  "correction.requester.relationship": "ANOTHER_AGENT",
3795
4012
  "correction.request.reason": "Child's name was incorrect"
3796
4013
  },
@@ -3805,45 +4022,92 @@ var eventPayloadGenerator = {
3805
4022
  declare: (eventId, input = {}) => ({
3806
4023
  type: ActionType.DECLARE,
3807
4024
  transactionId: input.transactionId ?? getUUID(),
3808
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4025
+ declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4026
+ annotation: input.annotation ?? generateActionMetadataInput(
4027
+ tennisClubMembershipEvent,
4028
+ ActionType.DECLARE
4029
+ ),
3809
4030
  eventId
3810
4031
  }),
4032
+ /**
4033
+ * Notify allows sending incomplete data. Think it as 'partial declare' for now.
4034
+ */
4035
+ notify: (eventId, input = {}) => {
4036
+ let declaration = input.declaration;
4037
+ if (!declaration) {
4038
+ const partialDeclaration = (0, import_lodash2.omitBy)(
4039
+ generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4040
+ import_lodash2.isString
4041
+ );
4042
+ declaration = partialDeclaration;
4043
+ }
4044
+ return {
4045
+ type: ActionType.NOTIFY,
4046
+ transactionId: input.transactionId ?? getUUID(),
4047
+ declaration,
4048
+ eventId
4049
+ };
4050
+ },
3811
4051
  validate: (eventId, input = {}) => ({
3812
4052
  type: ActionType.VALIDATE,
3813
4053
  transactionId: input.transactionId ?? getUUID(),
3814
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4054
+ declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4055
+ annotation: input.annotation ?? generateActionMetadataInput(
4056
+ tennisClubMembershipEvent,
4057
+ ActionType.VALIDATE
4058
+ ),
3815
4059
  duplicates: [],
3816
4060
  eventId
3817
4061
  }),
4062
+ assign: (eventId, input = {}) => ({
4063
+ type: ActionType.ASSIGN,
4064
+ transactionId: input.transactionId ?? getUUID(),
4065
+ declaration: {},
4066
+ assignedTo: input.assignedTo ?? getUUID(),
4067
+ eventId
4068
+ }),
4069
+ unassign: (eventId, input = {}) => ({
4070
+ type: ActionType.UNASSIGN,
4071
+ transactionId: input.transactionId ?? getUUID(),
4072
+ declaration: {},
4073
+ assignedTo: null,
4074
+ eventId
4075
+ }),
3818
4076
  archive: (eventId, input = {}, isDuplicate) => ({
3819
4077
  type: ActionType.ARCHIVE,
3820
4078
  transactionId: input.transactionId ?? getUUID(),
3821
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.ARCHIVE),
3822
- metadata: { isDuplicate: isDuplicate ?? false },
4079
+ declaration: {},
4080
+ // @TODO: Check whether generator is needed?
4081
+ annotation: { isDuplicate: isDuplicate ?? false },
3823
4082
  duplicates: [],
3824
4083
  eventId
3825
4084
  }),
3826
4085
  reject: (eventId, input = {}) => ({
3827
4086
  type: ActionType.REJECT,
3828
4087
  transactionId: input.transactionId ?? getUUID(),
3829
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REJECT),
4088
+ declaration: {},
4089
+ annotation: input.annotation ?? generateActionMetadataInput(
4090
+ tennisClubMembershipEvent,
4091
+ ActionType.REJECT
4092
+ ),
3830
4093
  duplicates: [],
3831
4094
  eventId
3832
4095
  }),
3833
4096
  register: (eventId, input = {}) => ({
3834
4097
  type: ActionType.REGISTER,
3835
4098
  transactionId: input.transactionId ?? getUUID(),
3836
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4099
+ declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4100
+ annotation: input.annotation ?? generateActionMetadataInput(
4101
+ tennisClubMembershipEvent,
4102
+ ActionType.REGISTER
4103
+ ),
3837
4104
  eventId
3838
4105
  }),
3839
4106
  printCertificate: (eventId, input = {}) => ({
3840
4107
  type: ActionType.PRINT_CERTIFICATE,
3841
4108
  transactionId: input.transactionId ?? getUUID(),
3842
- data: input.data ?? generateActionInput(
3843
- tennisClubMembershipEvent,
3844
- ActionType.PRINT_CERTIFICATE
3845
- ),
3846
- metadata: input.metadata ?? generateActionMetadataInput(
4109
+ declaration: {},
4110
+ annotation: input.annotation ?? generateActionMetadataInput(
3847
4111
  tennisClubMembershipEvent,
3848
4112
  ActionType.PRINT_CERTIFICATE
3849
4113
  ),
@@ -3853,17 +4117,21 @@ var eventPayloadGenerator = {
3853
4117
  request: (eventId, input = {}) => ({
3854
4118
  type: ActionType.REQUEST_CORRECTION,
3855
4119
  transactionId: input.transactionId ?? getUUID(),
3856
- data: input.data ?? generateActionInput(
4120
+ declaration: input.declaration ?? generateActionInput(
4121
+ tennisClubMembershipEvent,
4122
+ ActionType.REQUEST_CORRECTION
4123
+ ),
4124
+ annotation: input.annotation ?? generateActionMetadataInput(
3857
4125
  tennisClubMembershipEvent,
3858
4126
  ActionType.REQUEST_CORRECTION
3859
4127
  ),
3860
- metadata: {},
3861
4128
  eventId
3862
4129
  }),
3863
4130
  approve: (eventId, requestId, input = {}) => ({
3864
4131
  type: ActionType.APPROVE_CORRECTION,
3865
4132
  transactionId: input.transactionId ?? getUUID(),
3866
- data: input.data ?? generateActionInput(
4133
+ declaration: {},
4134
+ annotation: input.annotation ?? generateActionMetadataInput(
3867
4135
  tennisClubMembershipEvent,
3868
4136
  ActionType.APPROVE_CORRECTION
3869
4137
  ),
@@ -3873,7 +4141,8 @@ var eventPayloadGenerator = {
3873
4141
  reject: (eventId, requestId, input = {}) => ({
3874
4142
  type: ActionType.REJECT_CORRECTION,
3875
4143
  transactionId: input.transactionId ?? getUUID(),
3876
- data: input.data ?? generateActionInput(
4144
+ declaration: {},
4145
+ annotation: input.annotation ?? generateActionMetadataInput(
3877
4146
  tennisClubMembershipEvent,
3878
4147
  ActionType.REJECT_CORRECTION
3879
4148
  ),
@@ -3895,11 +4164,16 @@ function generateActionDocument({
3895
4164
  createdBy: getUUID(),
3896
4165
  id: getUUID(),
3897
4166
  createdAtLocation: "TODO",
3898
- data: generateActionInput(configuration, action),
3899
- metadata: {},
3900
- ...defaults
4167
+ declaration: generateActionInput(configuration, action),
4168
+ annotation: {},
4169
+ ...defaults,
4170
+ status: ActionStatus.Accepted
3901
4171
  };
3902
4172
  switch (action) {
4173
+ case ActionType.READ:
4174
+ return { ...actionBase, type: action };
4175
+ case ActionType.MARKED_AS_DUPLICATE:
4176
+ return { ...actionBase, type: action };
3903
4177
  case ActionType.DECLARE:
3904
4178
  return { ...actionBase, type: action };
3905
4179
  case ActionType.UNASSIGN:
@@ -3924,14 +4198,13 @@ function generateActionDocument({
3924
4198
  return { ...actionBase, requestId: getUUID(), type: action };
3925
4199
  case ActionType.REJECT_CORRECTION:
3926
4200
  return { ...actionBase, requestId: getUUID(), type: action };
3927
- case ActionType.CUSTOM:
3928
- return { ...actionBase, type: action };
3929
4201
  case ActionType.REGISTER:
3930
4202
  return {
3931
4203
  ...actionBase,
3932
- type: action,
3933
- identifiers: { trackingId: getUUID(), registrationNumber: getUUID() }
4204
+ type: action
3934
4205
  };
4206
+ case ActionType.DELETE:
4207
+ case ActionType.DETECT_DUPLICATE:
3935
4208
  default:
3936
4209
  throw new Error(`Unsupported action type: ${action}`);
3937
4210
  }
@@ -3952,10 +4225,11 @@ function generateEventDocument({
3952
4225
  id: getUUID(),
3953
4226
  // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
3954
4227
  // @TODO: This should be fixed in the future.
3955
- updatedAt: new Date(Date.now() - 1e3).toISOString()
4228
+ updatedAt: new Date(Date.now() - 1e3).toISOString(),
4229
+ updatedAtLocation: "TODO"
3956
4230
  };
3957
4231
  }
3958
- function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, data = {}) {
4232
+ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
3959
4233
  const action = generateActionDocument({
3960
4234
  configuration: tennisClubMembershipEvent,
3961
4235
  action: actionType
@@ -3965,9 +4239,9 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, da
3965
4239
  transactionId: getUUID(),
3966
4240
  action: {
3967
4241
  ...action,
3968
- data: {
3969
- ...action.data,
3970
- ...data
4242
+ declaration: {
4243
+ ...action.declaration,
4244
+ ...declaration
3971
4245
  }
3972
4246
  },
3973
4247
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3981,10 +4255,11 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3981
4255
  createdAt: overrides.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3982
4256
  createdBy: overrides.createdBy ?? getUUID(),
3983
4257
  createdAtLocation: overrides.createdAtLocation ?? getUUID(),
4258
+ updatedAtLocation: overrides.updatedAtLocation ?? getUUID(),
3984
4259
  modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3985
4260
  assignedTo: overrides.assignedTo ?? null,
3986
4261
  updatedBy: overrides.updatedBy ?? getUUID(),
3987
- data: overrides.data ?? {
4262
+ declaration: overrides.declaration ?? {
3988
4263
  "recommender.none": true,
3989
4264
  "applicant.firstname": "Danny",
3990
4265
  "applicant.surname": "Doe",
@@ -4015,7 +4290,9 @@ function isFieldValueWithoutTemplates(value) {
4015
4290
  return true;
4016
4291
  }
4017
4292
  function isFieldConfigDefaultValue(value) {
4018
- if (!value) return false;
4293
+ if (!value) {
4294
+ return false;
4295
+ }
4019
4296
  if (isFieldValue(value)) {
4020
4297
  return true;
4021
4298
  }