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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,31 +150,29 @@ __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,
156
+ generateActionAnnotationInput: () => generateActionAnnotationInput,
157
+ generateActionDeclarationInput: () => generateActionDeclarationInput,
139
158
  generateActionDocument: () => generateActionDocument,
140
- generateActionInput: () => generateActionInput,
141
- generateActionMetadataInput: () => generateActionMetadataInput,
142
159
  generateEventDocument: () => generateEventDocument,
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,
156
176
  isAddressFieldType: () => isAddressFieldType,
157
177
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
158
178
  isBulletListFieldType: () => isBulletListFieldType,
@@ -164,6 +184,7 @@ __export(events_exports, {
164
184
  isEmailFieldType: () => isEmailFieldType,
165
185
  isFacilityFieldType: () => isFacilityFieldType,
166
186
  isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
187
+ isFieldDisplayedOnReview: () => isFieldDisplayedOnReview,
167
188
  isFieldEnabled: () => isFieldEnabled,
168
189
  isFieldValue: () => isFieldValue,
169
190
  isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
@@ -174,6 +195,7 @@ __export(events_exports, {
174
195
  isNumberFieldType: () => isNumberFieldType,
175
196
  isOfficeFieldType: () => isOfficeFieldType,
176
197
  isPageHeaderFieldType: () => isPageHeaderFieldType,
198
+ isPageVisible: () => isPageVisible,
177
199
  isParagraphFieldType: () => isParagraphFieldType,
178
200
  isRadioGroupFieldType: () => isRadioGroupFieldType,
179
201
  isSelectFieldType: () => isSelectFieldType,
@@ -182,13 +204,15 @@ __export(events_exports, {
182
204
  isTextAreaFieldType: () => isTextAreaFieldType,
183
205
  isTextFieldType: () => isTextFieldType,
184
206
  isUndeclaredDraft: () => isUndeclaredDraft,
207
+ isVerificationPage: () => isVerificationPage,
185
208
  mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
186
209
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
187
210
  mapFieldTypeToZod: () => mapFieldTypeToZod,
211
+ never: () => never,
188
212
  not: () => not,
213
+ omitHiddenFields: () => omitHiddenFields,
214
+ omitHiddenPaginatedFields: () => omitHiddenPaginatedFields,
189
215
  or: () => or,
190
- resolveLabelsFromKnownFields: () => resolveLabelsFromKnownFields,
191
- stripHiddenFields: () => stripHiddenFields,
192
216
  user: () => user,
193
217
  validate: () => validate,
194
218
  validateFieldInput: () => validateFieldInput,
@@ -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
+ )
657
707
  });
658
- var VerificationPageConfig = import_zod6.z.object({
708
+ var FormPageConfig = PageConfigBase.extend({
709
+ type: import_zod6.z.literal(PageTypes.enum.FORM).default(PageTypes.enum.FORM)
710
+ });
711
+ var VerificationActionConfig = import_zod6.z.object({
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)
790
- })
791
- );
792
- var CustomConfig = ActionConfigBase.merge(
793
- import_zod7.z.object({
794
- type: import_zod7.z.literal(ActionType.CUSTOM)
886
+ import_zod9.z.object({
887
+ type: import_zod9.z.literal(ActionType.APPROVE_CORRECTION)
795
888
  })
796
889
  );
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,19 @@ 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
+ modifiedAt: import_zod14.z.string().datetime(),
1062
+ assignedTo: import_zod14.z.string().nullish(),
1063
+ updatedBy: import_zod14.z.string(),
1064
+ trackingId: import_zod14.z.string(),
1065
+ registrationNumber: import_zod14.z.string().nullish()
966
1066
  });
967
1067
  var eventMetadataLabelMap = {
968
1068
  "event.assignedTo": {
@@ -1014,28 +1114,33 @@ var eventMetadataLabelMap = {
1014
1114
  id: "event.trackingId.label",
1015
1115
  defaultMessage: "Tracking ID",
1016
1116
  description: "Tracking ID"
1117
+ },
1118
+ "event.registrationNumber": {
1119
+ id: "event.registrationNumber.label",
1120
+ defaultMessage: "Registration Number",
1121
+ description: "Registration Number"
1017
1122
  }
1018
1123
  };
1019
1124
 
1020
1125
  // ../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.")
1126
+ var WorkqueueConfig = import_zod15.z.object({
1127
+ id: import_zod15.z.string().describe("Unique identifier for workqueue."),
1128
+ filters: import_zod15.z.array(
1129
+ import_zod15.z.object({
1130
+ status: import_zod15.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
1026
1131
  })
1027
1132
  ).describe("Filters to be applied to workqueue.")
1028
1133
  }).describe("Configuration for workqueue.");
1029
1134
 
1030
1135
  // ../commons/src/events/AdvancedSearchConfig.ts
1031
- var import_zod14 = require("zod");
1032
- var AdvancedSearchConfig = import_zod14.z.object({
1136
+ var import_zod16 = require("zod");
1137
+ var AdvancedSearchConfig = import_zod16.z.object({
1033
1138
  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")
1139
+ fields: import_zod16.z.array(
1140
+ import_zod16.z.object({
1141
+ fieldId: import_zod16.z.string(),
1142
+ config: import_zod16.z.object({
1143
+ type: import_zod16.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
1039
1144
  }).optional().describe("Configuration options for the field")
1040
1145
  })
1041
1146
  ).optional().default([]).describe("Advanced search fields.")
@@ -1045,12 +1150,12 @@ var AdvancedSearchConfig = import_zod14.z.object({
1045
1150
  var import_lodash = require("lodash");
1046
1151
 
1047
1152
  // ../commons/src/workqueues/WorkqueueConfig.ts
1048
- var import_zod16 = require("zod");
1153
+ var import_zod18 = require("zod");
1049
1154
 
1050
1155
  // ../commons/src/workqueues/defaultColumns.ts
1051
- var import_zod15 = require("zod");
1052
- var WorkQueueColumnConfig = import_zod15.z.object({
1053
- id: import_zod15.z.string(),
1156
+ var import_zod17 = require("zod");
1157
+ var WorkQueueColumnConfig = import_zod17.z.object({
1158
+ id: import_zod17.z.string(),
1054
1159
  label: TranslationConfig
1055
1160
  });
1056
1161
  var defaultColumns = {
@@ -1087,16 +1192,16 @@ var defaultColumns = {
1087
1192
  }
1088
1193
  }
1089
1194
  };
1090
- var DefaultColumnKeys = import_zod15.z.enum(
1195
+ var DefaultColumnKeys = import_zod17.z.enum(
1091
1196
  Object.keys(defaultColumns)
1092
1197
  );
1093
1198
 
1094
1199
  // ../commons/src/workqueues/WorkqueueConfig.ts
1095
- var rootWorkqueueConfig = import_zod16.z.object({
1096
- id: import_zod16.z.string(),
1200
+ var rootWorkqueueConfig = import_zod18.z.object({
1201
+ id: import_zod18.z.string(),
1097
1202
  title: TranslationConfig,
1098
- columns: import_zod16.z.array(WorkQueueColumnConfig),
1099
- defaultColumns: import_zod16.z.array(DefaultColumnKeys)
1203
+ columns: import_zod18.z.array(WorkQueueColumnConfig),
1204
+ defaultColumns: import_zod18.z.array(DefaultColumnKeys)
1100
1205
  });
1101
1206
  var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
1102
1207
 
@@ -1176,7 +1281,7 @@ var import_ajv_formats = __toESM(require("ajv-formats"));
1176
1281
  var import_date_fns = require("date-fns");
1177
1282
 
1178
1283
  // ../commons/src/events/FieldTypeMapping.ts
1179
- var import_zod17 = require("zod");
1284
+ var import_zod19 = require("zod");
1180
1285
  function mapFieldTypeToZod(type, required) {
1181
1286
  let schema;
1182
1287
  switch (type) {
@@ -1229,7 +1334,7 @@ function createValidationSchema(config) {
1229
1334
  for (const field2 of config) {
1230
1335
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1231
1336
  }
1232
- return import_zod17.z.object(shape);
1337
+ return import_zod19.z.object(shape);
1233
1338
  }
1234
1339
  function mapFieldTypeToMockValue(field2, i) {
1235
1340
  switch (field2.type) {
@@ -1396,7 +1501,8 @@ var isDataFieldType = (field2) => {
1396
1501
 
1397
1502
  // ../commons/src/conditionals/validate.ts
1398
1503
  var ajv = new import_ajv.default({
1399
- $data: true
1504
+ $data: true,
1505
+ allowUnionTypes: true
1400
1506
  });
1401
1507
  (0, import_ajv_formats.default)(ajv);
1402
1508
  function validate(schema, data) {
@@ -1429,6 +1535,9 @@ function isFieldVisible(field2, form) {
1429
1535
  function isFieldEnabled(field2, form) {
1430
1536
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1431
1537
  }
1538
+ function isFieldDisplayedOnReview(field2, form) {
1539
+ return isFieldVisible(field2, form) && isFieldConditionMet(field2, form, ConditionalType.DISPLAY_ON_REVIEW);
1540
+ }
1432
1541
  var errorMessages = {
1433
1542
  hiddenField: {
1434
1543
  id: "v2.error.hidden",
@@ -1456,12 +1565,14 @@ var errorMessages = {
1456
1565
  id: "v2.error.invalid"
1457
1566
  }
1458
1567
  };
1459
- var createIntlError = (message) => ({
1460
- message: {
1461
- message
1462
- }
1463
- });
1464
- var zodToIntlErrorMap = (issue, _ctx) => {
1568
+ function createIntlError(message) {
1569
+ return {
1570
+ message: {
1571
+ message
1572
+ }
1573
+ };
1574
+ }
1575
+ function zodToIntlErrorMap(issue, _ctx) {
1465
1576
  switch (issue.code) {
1466
1577
  case "invalid_string": {
1467
1578
  if (_ctx.data === "") {
@@ -1499,8 +1610,29 @@ var zodToIntlErrorMap = (issue, _ctx) => {
1499
1610
  }
1500
1611
  }
1501
1612
  return createIntlError(errorMessages.invalidInput);
1502
- };
1503
- function getFieldValidationErrors({
1613
+ }
1614
+ function runCustomFieldValidations({
1615
+ field: field2,
1616
+ conditionalParameters
1617
+ }) {
1618
+ return (field2.validation ?? []).filter((validation) => {
1619
+ return !validate(validation.validator, conditionalParameters);
1620
+ }).map((validation) => ({ message: validation.message }));
1621
+ }
1622
+ function validateFieldInput({
1623
+ field: field2,
1624
+ value
1625
+ }) {
1626
+ const rawError = mapFieldTypeToZod(field2.type, field2.required).safeParse(
1627
+ value,
1628
+ {
1629
+ // @ts-expect-error
1630
+ errorMap: zodToIntlErrorMap
1631
+ }
1632
+ );
1633
+ return rawError.error?.issues.map((issue) => issue.message) ?? [];
1634
+ }
1635
+ function runFieldValidations({
1504
1636
  field: field2,
1505
1637
  values
1506
1638
  }) {
@@ -1508,6 +1640,23 @@ function getFieldValidationErrors({
1508
1640
  $form: values,
1509
1641
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1510
1642
  };
1643
+ const fieldValidationResult = validateFieldInput({
1644
+ field: field2,
1645
+ value: values[field2.id]
1646
+ });
1647
+ const customValidationResults = runCustomFieldValidations({
1648
+ field: field2,
1649
+ conditionalParameters
1650
+ });
1651
+ return {
1652
+ // Assumes that custom validation errors are based on the field type, and extend the validation.
1653
+ errors: [...fieldValidationResult, ...customValidationResults]
1654
+ };
1655
+ }
1656
+ function getFieldValidationErrors({
1657
+ field: field2,
1658
+ values
1659
+ }) {
1511
1660
  if (!isFieldVisible(field2, values) || !isFieldEnabled(field2, values)) {
1512
1661
  if (values[field2.id]) {
1513
1662
  return {
@@ -1522,41 +1671,21 @@ function getFieldValidationErrors({
1522
1671
  errors: []
1523
1672
  };
1524
1673
  }
1525
- const fieldValidationResult = validateFieldInput({
1674
+ return runFieldValidations({
1526
1675
  field: field2,
1527
- value: values[field2.id]
1528
- });
1529
- const customValidationResults = runCustomFieldValidations({
1530
- field: field2,
1531
- conditionalParameters
1676
+ values
1532
1677
  });
1533
- return {
1534
- // Assumes that custom validation errors are based on the field type, and extend the validation.
1535
- errors: [...fieldValidationResult, ...customValidationResults]
1536
- };
1537
1678
  }
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) ?? [];
1679
+
1680
+ // ../commons/src/uuid.ts
1681
+ var import_uuid = require("uuid");
1682
+ function getUUID() {
1683
+ return (0, import_uuid.v4)();
1558
1684
  }
1559
1685
 
1686
+ // ../commons/src/events/utils.ts
1687
+ var import_date_fns2 = require("date-fns");
1688
+
1560
1689
  // ../commons/src/utils.ts
1561
1690
  function getOrThrow(x, message) {
1562
1691
  if (x === void 0 || x === null) {
@@ -1565,73 +1694,64 @@ function getOrThrow(x, message) {
1565
1694
  return x;
1566
1695
  }
1567
1696
 
1568
- // ../commons/src/uuid.ts
1569
- var import_uuid = require("uuid");
1570
- function getUUID() {
1571
- return (0, import_uuid.v4)();
1572
- }
1573
-
1574
1697
  // ../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
- );
1588
- };
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
- );
1698
+ function isDeclarationActionConfig(action) {
1699
+ return DeclarationActions.safeParse(action.type).success;
1700
+ }
1701
+ function getDeclarationFields(configuration) {
1702
+ return configuration.declaration.pages.flatMap(({ fields }) => fields);
1703
+ }
1704
+ function getDeclarationPages(configuration) {
1705
+ return configuration.declaration.pages;
1706
+ }
1707
+ function getDeclaration(configuration) {
1708
+ return configuration.declaration;
1709
+ }
1710
+ var getActionAnnotationFields = (actionConfig) => {
1711
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1712
+ return [
1713
+ ...actionConfig.onboardingForm.flatMap(({ fields }) => fields),
1714
+ ...actionConfig.additionalDetailsForm.flatMap(({ fields }) => fields)
1715
+ ];
1716
+ }
1717
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1718
+ return actionConfig.printForm.pages.flatMap(({ fields }) => fields);
1719
+ }
1720
+ if (isDeclarationActionConfig(actionConfig)) {
1721
+ return actionConfig.review.fields;
1722
+ }
1723
+ return [];
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
- });
1725
+ var getAllAnnotationFields = (config) => {
1726
+ return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1626
1727
  };
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)
1728
+ var findAllFields = (config) => {
1729
+ return (0, import_lodash.flattenDeep)([
1730
+ ...getDeclarationFields(config),
1731
+ ...getAllAnnotationFields(config)
1631
1732
  ]);
1733
+ };
1734
+ var findRecordActionPages = (config, actionType) => {
1735
+ const action = config.actions.find((a) => a.type === actionType);
1736
+ if (action?.type === ActionType.REQUEST_CORRECTION) {
1737
+ return [...action.onboardingForm, ...action.additionalDetailsForm];
1738
+ }
1739
+ if (action?.type === ActionType.PRINT_CERTIFICATE) {
1740
+ return action.printForm.pages;
1741
+ }
1742
+ return [];
1743
+ };
1744
+ function getActionReview(configuration, actionType) {
1745
+ const [actionConfig] = configuration.actions.filter(
1746
+ (a) => a.type === actionType
1747
+ );
1748
+ return getOrThrow(
1749
+ actionConfig.review,
1750
+ `No review config found for ${actionType}`
1751
+ );
1632
1752
  }
1633
- function getAllPages(configuration) {
1634
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => form.pages);
1753
+ function getActionReviewFields(configuration, actionType) {
1754
+ return getActionReview(configuration, actionType).fields;
1635
1755
  }
1636
1756
  function validateWorkqueueConfig(workqueueConfigs) {
1637
1757
  workqueueConfigs.map((workqueue) => {
@@ -1645,71 +1765,30 @@ function validateWorkqueueConfig(workqueueConfigs) {
1645
1765
  }
1646
1766
  });
1647
1767
  }
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}`);
1690
- }
1691
- return config;
1692
- }
1693
- function isOptionalUncheckedCheckbox(field2, form) {
1694
- if (field2.type !== FieldType.CHECKBOX || field2.required) {
1695
- return false;
1768
+ function isPageVisible(page, formValues) {
1769
+ if (!page.conditional) {
1770
+ return true;
1696
1771
  }
1697
- return !form[field2.id];
1772
+ return validate(page.conditional, {
1773
+ $form: formValues,
1774
+ $now: (0, import_date_fns2.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1775
+ });
1698
1776
  }
1699
- function stripHiddenFields(fields, data) {
1700
- return (0, import_lodash.omitBy)(data, (_2, fieldId) => {
1777
+ function omitHiddenFields(fields, values) {
1778
+ return (0, import_lodash.omitBy)(values, (_, fieldId) => {
1701
1779
  const field2 = fields.find((f) => f.id === fieldId);
1702
1780
  if (!field2) {
1703
1781
  return true;
1704
1782
  }
1705
- if (isOptionalUncheckedCheckbox(field2, data)) {
1706
- return true;
1707
- }
1708
- return !isFieldVisible(field2, data);
1783
+ return !isFieldVisible(field2, values);
1709
1784
  });
1710
1785
  }
1786
+ function omitHiddenPaginatedFields(formConfig, declaration) {
1787
+ const visiblePagesFormFields = formConfig.pages.filter((p) => isPageVisible(p, declaration)).flatMap((p) => p.fields);
1788
+ return omitHiddenFields(visiblePagesFormFields, declaration);
1789
+ }
1711
1790
  function findActiveDrafts(event2, drafts) {
1712
- const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1791
+ const actions = event2.actions.slice().filter(({ type }) => type !== ActionType.READ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1713
1792
  const lastAction = actions[actions.length - 1];
1714
1793
  return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
1715
1794
  }
@@ -1721,35 +1800,50 @@ function createEmptyDraft(eventId, draftId, actionType) {
1721
1800
  transactionId: getUUID(),
1722
1801
  action: {
1723
1802
  type: actionType,
1724
- data: {},
1725
- metadata: {},
1803
+ declaration: {},
1804
+ annotation: {},
1726
1805
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1727
1806
  createdBy: "@todo",
1728
1807
  createdAtLocation: "@todo"
1729
1808
  }
1730
1809
  };
1731
1810
  }
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);
1811
+ function isVerificationPage(page) {
1812
+ return page.type === PageTypes.enum.VERIFICATION;
1813
+ }
1814
+ function deepMerge(currentDocument, actionDocument) {
1815
+ return (0, import_lodash.mergeWith)(
1816
+ currentDocument,
1817
+ actionDocument,
1818
+ (previousValue, incomingValue) => {
1819
+ if (incomingValue === void 0) {
1820
+ return previousValue;
1821
+ }
1822
+ if ((0, import_lodash.isArray)(incomingValue)) {
1823
+ return incomingValue;
1824
+ }
1825
+ if ((0, import_lodash.isObject)(previousValue) && (0, import_lodash.isObject)(incomingValue)) {
1826
+ return void 0;
1827
+ }
1828
+ return incomingValue;
1829
+ }
1830
+ );
1738
1831
  }
1739
1832
 
1740
1833
  // ../commons/src/events/EventConfig.ts
1741
- var EventConfig = import_zod18.z.object({
1742
- id: import_zod18.z.string().describe(
1834
+ var EventConfig = import_zod20.z.object({
1835
+ id: import_zod20.z.string().describe(
1743
1836
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1744
1837
  ),
1745
1838
  summary: SummaryConfig,
1746
1839
  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([])
1840
+ actions: import_zod20.z.array(ActionConfig),
1841
+ declaration: DeclarationFormConfig,
1842
+ workqueues: import_zod20.z.array(WorkqueueConfig),
1843
+ deduplication: import_zod20.z.array(DeduplicationConfig).optional().default([]),
1844
+ advancedSearch: import_zod20.z.array(AdvancedSearchConfig).optional().default([])
1751
1845
  }).superRefine((event2, ctx) => {
1752
- const allFields = findPageFields(event2);
1846
+ const allFields = findAllFields(event2);
1753
1847
  const fieldIds = allFields.map((field2) => field2.id);
1754
1848
  const advancedSearchFields = event2.advancedSearch.flatMap(
1755
1849
  (section) => section.fields.flatMap((field2) => field2.fieldId)
@@ -1776,106 +1870,117 @@ var EventConfig = import_zod18.z.object({
1776
1870
  });
1777
1871
 
1778
1872
  // ../commons/src/events/EventConfigInput.ts
1779
- var defineForm = (form) => FormConfig.parse(form);
1873
+ var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
1874
+ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1875
+ var definePage = (page) => PageConfig.parse(page);
1780
1876
  var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1781
1877
 
1782
1878
  // ../commons/src/events/Draft.ts
1783
- var import_zod21 = require("zod");
1879
+ var import_zod23 = require("zod");
1784
1880
 
1785
1881
  // ../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()
1882
+ var import_zod21 = require("zod");
1883
+ var ActionUpdate = import_zod21.z.record(import_zod21.z.string(), FieldUpdateValue);
1884
+ var ActionStatus = {
1885
+ Requested: "Requested",
1886
+ Accepted: "Accepted",
1887
+ Rejected: "Rejected"
1888
+ };
1889
+ var ActionBase = import_zod21.z.object({
1890
+ id: import_zod21.z.string(),
1891
+ createdAt: import_zod21.z.string().datetime(),
1892
+ createdBy: import_zod21.z.string(),
1893
+ declaration: ActionUpdate,
1894
+ annotation: ActionUpdate.optional(),
1895
+ createdAtLocation: import_zod21.z.string(),
1896
+ status: import_zod21.z.enum([
1897
+ ActionStatus.Requested,
1898
+ ActionStatus.Accepted,
1899
+ ActionStatus.Rejected
1900
+ ]),
1901
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1902
+ originalActionId: import_zod21.z.string().optional()
1795
1903
  });
1796
1904
  var AssignedAction = ActionBase.merge(
1797
- import_zod19.z.object({
1798
- type: import_zod19.z.literal(ActionType.ASSIGN),
1799
- assignedTo: import_zod19.z.string()
1905
+ import_zod21.z.object({
1906
+ type: import_zod21.z.literal(ActionType.ASSIGN),
1907
+ assignedTo: import_zod21.z.string()
1800
1908
  })
1801
1909
  );
1802
1910
  var UnassignedAction = ActionBase.merge(
1803
- import_zod19.z.object({
1804
- type: import_zod19.z.literal(ActionType.UNASSIGN)
1911
+ import_zod21.z.object({
1912
+ type: import_zod21.z.literal(ActionType.UNASSIGN)
1805
1913
  })
1806
1914
  );
1807
1915
  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
- })
1916
+ import_zod21.z.object({
1917
+ type: import_zod21.z.literal(ActionType.REGISTER),
1918
+ registrationNumber: import_zod21.z.string().optional()
1814
1919
  })
1815
1920
  );
1816
1921
  var DeclareAction = ActionBase.merge(
1817
- import_zod19.z.object({
1818
- type: import_zod19.z.literal(ActionType.DECLARE)
1922
+ import_zod21.z.object({
1923
+ type: import_zod21.z.literal(ActionType.DECLARE)
1819
1924
  })
1820
1925
  );
1821
1926
  var ValidateAction = ActionBase.merge(
1822
- import_zod19.z.object({
1823
- type: import_zod19.z.literal(ActionType.VALIDATE)
1927
+ import_zod21.z.object({
1928
+ type: import_zod21.z.literal(ActionType.VALIDATE)
1824
1929
  })
1825
1930
  );
1826
1931
  var RejectAction = ActionBase.merge(
1827
- import_zod19.z.object({
1828
- type: import_zod19.z.literal(ActionType.REJECT)
1932
+ import_zod21.z.object({
1933
+ type: import_zod21.z.literal(ActionType.REJECT)
1829
1934
  })
1830
1935
  );
1831
1936
  var MarkAsDuplicateAction = ActionBase.merge(
1832
- import_zod19.z.object({
1833
- type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1937
+ import_zod21.z.object({
1938
+ type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE)
1834
1939
  })
1835
1940
  );
1836
1941
  var ArchiveAction = ActionBase.merge(
1837
- import_zod19.z.object({
1838
- type: import_zod19.z.literal(ActionType.ARCHIVE)
1942
+ import_zod21.z.object({
1943
+ type: import_zod21.z.literal(ActionType.ARCHIVE)
1839
1944
  })
1840
1945
  );
1841
1946
  var CreatedAction = ActionBase.merge(
1842
- import_zod19.z.object({
1843
- type: import_zod19.z.literal(ActionType.CREATE)
1947
+ import_zod21.z.object({
1948
+ type: import_zod21.z.literal(ActionType.CREATE)
1844
1949
  })
1845
1950
  );
1846
1951
  var NotifiedAction = ActionBase.merge(
1847
- import_zod19.z.object({
1848
- type: import_zod19.z.literal(ActionType.NOTIFY)
1952
+ import_zod21.z.object({
1953
+ type: import_zod21.z.literal(ActionType.NOTIFY)
1849
1954
  })
1850
1955
  );
1851
1956
  var PrintCertificateAction = ActionBase.merge(
1852
- import_zod19.z.object({
1853
- type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE)
1957
+ import_zod21.z.object({
1958
+ type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE)
1854
1959
  })
1855
1960
  );
1856
1961
  var RequestedCorrectionAction = ActionBase.merge(
1857
- import_zod19.z.object({
1858
- type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION)
1962
+ import_zod21.z.object({
1963
+ type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION)
1859
1964
  })
1860
1965
  );
1861
1966
  var ApprovedCorrectionAction = ActionBase.merge(
1862
- import_zod19.z.object({
1863
- type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION),
1864
- requestId: import_zod19.z.string()
1967
+ import_zod21.z.object({
1968
+ type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION),
1969
+ requestId: import_zod21.z.string()
1865
1970
  })
1866
1971
  );
1867
1972
  var RejectedCorrectionAction = ActionBase.merge(
1868
- import_zod19.z.object({
1869
- type: import_zod19.z.literal(ActionType.REJECT_CORRECTION),
1870
- requestId: import_zod19.z.string()
1973
+ import_zod21.z.object({
1974
+ type: import_zod21.z.literal(ActionType.REJECT_CORRECTION),
1975
+ requestId: import_zod21.z.string()
1871
1976
  })
1872
1977
  );
1873
- var CustomAction = ActionBase.merge(
1874
- import_zod19.z.object({
1875
- type: import_zod19.z.literal(ActionType.CUSTOM)
1978
+ var ReadAction = ActionBase.merge(
1979
+ import_zod21.z.object({
1980
+ type: import_zod21.z.literal(ActionType.READ)
1876
1981
  })
1877
1982
  );
1878
- var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1983
+ var ActionDocument = import_zod21.z.discriminatedUnion("type", [
1879
1984
  CreatedAction,
1880
1985
  ValidateAction,
1881
1986
  RejectAction,
@@ -1890,108 +1995,124 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1890
1995
  RejectedCorrectionAction,
1891
1996
  UnassignedAction,
1892
1997
  PrintCertificateAction,
1893
- CustomAction
1998
+ ReadAction
1894
1999
  ]);
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()
2000
+ var AsyncRejectActionDocument = ActionBase.omit({
2001
+ declaration: true,
2002
+ annotation: true,
2003
+ createdBy: true,
2004
+ createdAtLocation: true
2005
+ }).merge(
2006
+ import_zod21.z.object({
2007
+ type: import_zod21.z.enum(ConfirmableActions),
2008
+ status: import_zod21.z.literal(ActionStatus.Rejected)
2009
+ })
2010
+ );
2011
+ var Action = import_zod21.z.union([ActionDocument, AsyncRejectActionDocument]);
2012
+ var ResolvedUser = import_zod21.z.object({
2013
+ id: import_zod21.z.string(),
2014
+ role: import_zod21.z.string(),
2015
+ name: import_zod21.z.array(
2016
+ import_zod21.z.object({
2017
+ use: import_zod21.z.string(),
2018
+ given: import_zod21.z.array(import_zod21.z.string()),
2019
+ family: import_zod21.z.string()
1903
2020
  })
1904
2021
  )
1905
2022
  });
1906
2023
 
1907
2024
  // ../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()
2025
+ var import_zod22 = require("zod");
2026
+ var BaseActionInput = import_zod22.z.object({
2027
+ eventId: import_zod22.z.string(),
2028
+ transactionId: import_zod22.z.string(),
2029
+ declaration: ActionUpdate.default({}),
2030
+ annotation: ActionUpdate.optional(),
2031
+ originalActionId: import_zod22.z.string().optional()
1914
2032
  });
1915
2033
  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()
2034
+ import_zod22.z.object({
2035
+ type: import_zod22.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2036
+ createdAtLocation: import_zod22.z.string()
1919
2037
  })
1920
2038
  );
1921
2039
  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
- })
2040
+ import_zod22.z.object({
2041
+ type: import_zod22.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2042
+ registrationNumber: import_zod22.z.string().optional()
1928
2043
  })
1929
2044
  );
1930
2045
  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())
2046
+ import_zod22.z.object({
2047
+ type: import_zod22.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2048
+ duplicates: import_zod22.z.array(import_zod22.z.string())
1934
2049
  })
1935
2050
  );
1936
2051
  var NotifyActionInput = BaseActionInput.merge(
1937
- import_zod20.z.object({
1938
- type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2052
+ import_zod22.z.object({
2053
+ type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1939
2054
  })
1940
2055
  );
1941
2056
  var DeclareActionInput = BaseActionInput.merge(
1942
- import_zod20.z.object({
1943
- type: import_zod20.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2057
+ import_zod22.z.object({
2058
+ type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1944
2059
  })
1945
2060
  );
1946
2061
  var PrintCertificateActionInput = BaseActionInput.merge(
1947
- import_zod20.z.object({
1948
- type: import_zod20.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2062
+ import_zod22.z.object({
2063
+ type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1949
2064
  })
1950
2065
  );
1951
2066
  var RejectDeclarationActionInput = BaseActionInput.merge(
1952
- import_zod20.z.object({
1953
- type: import_zod20.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2067
+ import_zod22.z.object({
2068
+ type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1954
2069
  })
1955
2070
  );
1956
2071
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1957
- import_zod20.z.object({
1958
- type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2072
+ import_zod22.z.object({
2073
+ type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1959
2074
  })
1960
2075
  );
1961
2076
  var ArchiveActionInput = BaseActionInput.merge(
1962
- import_zod20.z.object({
1963
- type: import_zod20.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2077
+ import_zod22.z.object({
2078
+ type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1964
2079
  })
1965
2080
  );
1966
2081
  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()
2082
+ import_zod22.z.object({
2083
+ type: import_zod22.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2084
+ assignedTo: import_zod22.z.string()
1970
2085
  })
1971
2086
  );
1972
2087
  var UnassignActionInput = BaseActionInput.merge(
1973
- import_zod20.z.object({
1974
- type: import_zod20.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN)
2088
+ import_zod22.z.object({
2089
+ type: import_zod22.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2090
+ assignedTo: import_zod22.z.literal(null).default(null)
1975
2091
  })
1976
2092
  );
1977
2093
  var RequestCorrectionActionInput = BaseActionInput.merge(
1978
- import_zod20.z.object({
1979
- type: import_zod20.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2094
+ import_zod22.z.object({
2095
+ type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
1980
2096
  })
1981
2097
  );
1982
2098
  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)
2099
+ import_zod22.z.object({
2100
+ requestId: import_zod22.z.string(),
2101
+ type: import_zod22.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
1986
2102
  })
1987
2103
  );
1988
2104
  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)
2105
+ import_zod22.z.object({
2106
+ requestId: import_zod22.z.string(),
2107
+ type: import_zod22.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
1992
2108
  })
1993
2109
  );
1994
- var ActionInput = import_zod20.z.discriminatedUnion("type", [
2110
+ var ReadActionInput = BaseActionInput.merge(
2111
+ import_zod22.z.object({
2112
+ type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
2113
+ })
2114
+ );
2115
+ var ActionInput = import_zod22.z.discriminatedUnion("type", [
1995
2116
  CreateActionInput,
1996
2117
  ValidateActionInput,
1997
2118
  RegisterActionInput,
@@ -2005,56 +2126,62 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
2005
2126
  PrintCertificateActionInput,
2006
2127
  RequestCorrectionActionInput,
2007
2128
  RejectCorrectionActionInput,
2008
- ApproveCorrectionActionInput
2129
+ ApproveCorrectionActionInput,
2130
+ ReadActionInput
2009
2131
  ]);
2010
2132
 
2011
2133
  // ../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(),
2134
+ var Draft = import_zod23.z.object({
2135
+ id: import_zod23.z.string(),
2136
+ eventId: import_zod23.z.string(),
2137
+ transactionId: import_zod23.z.string(),
2138
+ createdAt: import_zod23.z.string().datetime(),
2017
2139
  action: ActionBase.extend({
2018
- type: import_zod21.z.enum(Object.values(ActionType))
2140
+ type: ActionTypes
2019
2141
  }).omit({ id: true })
2020
2142
  });
2021
2143
  var DraftInput = BaseActionInput.extend({
2022
- type: import_zod21.z.enum(Object.values(ActionType))
2144
+ type: ActionTypes
2023
2145
  });
2024
2146
 
2025
2147
  // ../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()
2148
+ var import_zod24 = require("zod");
2149
+ var EventInput = import_zod24.z.object({
2150
+ transactionId: import_zod24.z.string(),
2151
+ type: import_zod24.z.string()
2030
2152
  });
2031
2153
 
2032
2154
  // ../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()
2155
+ var import_zod25 = require("zod");
2156
+ var EventDocument = import_zod25.z.object({
2157
+ id: import_zod25.z.string(),
2158
+ type: import_zod25.z.string(),
2159
+ createdAt: import_zod25.z.string().datetime(),
2160
+ updatedAt: import_zod25.z.string().datetime(),
2161
+ actions: import_zod25.z.array(Action),
2162
+ trackingId: import_zod25.z.string()
2041
2163
  });
2042
2164
 
2043
2165
  // ../commons/src/events/EventIndex.ts
2044
- var import_zod24 = require("zod");
2166
+ var import_zod26 = require("zod");
2045
2167
  var EventIndex = EventMetadata.extend({
2046
- data: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any())
2168
+ declaration: import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any())
2047
2169
  });
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()
2170
+ var EventSearchIndex = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any()).and(
2171
+ import_zod26.z.object({
2172
+ type: import_zod26.z.string()
2051
2173
  // Ensures "type" (event-id) exists and is a string
2052
2174
  })
2053
2175
  );
2054
2176
 
2055
2177
  // ../commons/src/events/state/index.ts
2056
- var _ = __toESM(require("lodash"));
2057
2178
  function getStatusFromActions(actions) {
2179
+ const hasRejectedAction = actions.some(
2180
+ (a) => a.status === ActionStatus.Rejected
2181
+ );
2182
+ if (hasRejectedAction) {
2183
+ return EventStatus.REJECTED;
2184
+ }
2058
2185
  return actions.reduce((status, action) => {
2059
2186
  if (action.type === ActionType.CREATE) {
2060
2187
  return EventStatus.CREATED;
@@ -2091,7 +2218,7 @@ function getAssignedUserFromActions(actions) {
2091
2218
  return user2;
2092
2219
  }, null);
2093
2220
  }
2094
- function getData(actions) {
2221
+ function aggregateActionDeclarations(actions) {
2095
2222
  const excludedActions = [
2096
2223
  ActionType.REQUEST_CORRECTION,
2097
2224
  ActionType.PRINT_CERTIFICATE
@@ -2105,47 +2232,35 @@ function getData(actions) {
2105
2232
  if (!requestAction) {
2106
2233
  return status;
2107
2234
  }
2108
- return deepMerge(status, requestAction.data);
2109
- }
2110
- return deepMerge(status, action.data);
2111
- }, {});
2112
- }
2113
- 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
- };
2235
+ return deepMerge(status, requestAction.declaration);
2124
2236
  }
2125
- return acc;
2237
+ return deepMerge(status, action.declaration);
2126
2238
  }, {});
2127
2239
  }
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;
2240
+ function deepDropNulls(obj) {
2241
+ if (Array.isArray(obj)) {
2242
+ return obj.map(deepDropNulls);
2243
+ }
2244
+ if (obj !== null && typeof obj === "object") {
2245
+ return Object.entries(obj).reduce((acc, [key, value]) => {
2246
+ const cleanedValue = deepDropNulls(value);
2247
+ if (cleanedValue !== null) {
2248
+ ;
2249
+ acc[key] = cleanedValue;
2141
2250
  }
2142
- return incomingValue;
2143
- }
2144
- );
2251
+ return acc;
2252
+ }, {});
2253
+ }
2254
+ return obj;
2145
2255
  }
2146
2256
  function isUndeclaredDraft(status) {
2147
2257
  return status === EventStatus.CREATED;
2148
2258
  }
2259
+ function getAcceptedActions(event2) {
2260
+ return event2.actions.filter(
2261
+ (a) => a.status === ActionStatus.Accepted
2262
+ );
2263
+ }
2149
2264
  function getCurrentEventState(event2) {
2150
2265
  const creationAction = event2.actions.find(
2151
2266
  (action) => action.type === ActionType.CREATE
@@ -2153,7 +2268,12 @@ function getCurrentEventState(event2) {
2153
2268
  if (!creationAction) {
2154
2269
  throw new Error(`Event ${event2.id} has no creation action`);
2155
2270
  }
2156
- const latestAction = event2.actions[event2.actions.length - 1];
2271
+ const activeActions = getAcceptedActions(event2);
2272
+ const latestAction = activeActions[activeActions.length - 1];
2273
+ const registrationAction = activeActions.find(
2274
+ (a) => a.type === ActionType.REGISTER && a.status === ActionStatus.Accepted
2275
+ );
2276
+ const registrationNumber = registrationAction?.registrationNumber ?? null;
2157
2277
  return deepDropNulls({
2158
2278
  id: event2.id,
2159
2279
  type: event2.type,
@@ -2162,10 +2282,11 @@ function getCurrentEventState(event2) {
2162
2282
  createdBy: creationAction.createdBy,
2163
2283
  createdAtLocation: creationAction.createdAtLocation,
2164
2284
  modifiedAt: latestAction.createdAt,
2165
- assignedTo: getAssignedUserFromActions(event2.actions),
2285
+ assignedTo: getAssignedUserFromActions(activeActions),
2166
2286
  updatedBy: latestAction.createdBy,
2167
- data: getData(event2.actions),
2168
- trackingId: event2.trackingId
2287
+ declaration: aggregateActionDeclarations(activeActions),
2288
+ trackingId: event2.trackingId,
2289
+ registrationNumber
2169
2290
  });
2170
2291
  }
2171
2292
  function getCurrentEventStateWithDrafts(event2, drafts) {
@@ -2197,38 +2318,44 @@ function applyDraftsToEventIndex(eventIndex, drafts) {
2197
2318
  }
2198
2319
  return {
2199
2320
  ...eventIndex,
2200
- data: {
2201
- ...eventIndex.data,
2202
- ...activeDrafts[activeDrafts.length - 1].data
2321
+ declaration: {
2322
+ ...eventIndex.declaration,
2323
+ ...activeDrafts[activeDrafts.length - 1].declaration
2203
2324
  }
2204
2325
  };
2205
2326
  }
2206
- function getMetadataForAction({
2327
+ function getAnnotationFromDrafts(drafts) {
2328
+ const actions = drafts.map((draft) => draft.action);
2329
+ const annotation = actions.reduce((ann, action) => {
2330
+ return deepMerge(ann, action.annotation ?? {});
2331
+ }, {});
2332
+ return deepDropNulls(annotation);
2333
+ }
2334
+ function getActionAnnotation({
2207
2335
  event: event2,
2208
2336
  actionType,
2209
2337
  drafts
2210
2338
  }) {
2211
- const action = event2.actions.find((action2) => actionType === action2.type);
2339
+ const activeActions = getAcceptedActions(event2);
2340
+ const action = activeActions.find(
2341
+ (activeAction) => actionType === activeAction.type
2342
+ );
2212
2343
  const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
2213
2344
  const sorted = [
2214
2345
  ...action ? [action] : [],
2215
2346
  ...eventDrafts.map((draft) => draft.action)
2216
2347
  ].sort();
2217
- const metadata = sorted.reduce((metadata2, action2) => {
2218
- return deepMerge(metadata2, action2.metadata ?? {});
2348
+ const annotation = sorted.reduce((ann, sortedAction) => {
2349
+ return deepMerge(ann, sortedAction.annotation ?? {});
2219
2350
  }, {});
2220
- return deepDropNulls(metadata);
2351
+ return deepDropNulls(annotation);
2221
2352
  }
2222
2353
 
2223
2354
  // ../commons/src/events/defineConfig.ts
2224
2355
  var defineConfig = (config) => {
2225
2356
  validateWorkqueueConfig(config.workqueues);
2226
2357
  const input = EventConfig.parse(config);
2227
- const pageFields = findInputPageFields(input);
2228
- return EventConfig.parse({
2229
- ...input,
2230
- pageFields
2231
- });
2358
+ return input;
2232
2359
  };
2233
2360
 
2234
2361
  // ../commons/src/events/transactions.ts
@@ -2243,6 +2370,16 @@ var import_lodash2 = require("lodash");
2243
2370
  function defineConditional(schema) {
2244
2371
  return schema;
2245
2372
  }
2373
+ function defineFormConditional(schema) {
2374
+ const schemaWithForm = {
2375
+ type: "object",
2376
+ properties: {
2377
+ $form: schema
2378
+ },
2379
+ required: ["$form"]
2380
+ };
2381
+ return defineConditional(schemaWithForm);
2382
+ }
2246
2383
  function alwaysTrue() {
2247
2384
  return {};
2248
2385
  }
@@ -2267,6 +2404,9 @@ function not(condition) {
2267
2404
  required: []
2268
2405
  });
2269
2406
  }
2407
+ function never() {
2408
+ return not(alwaysTrue());
2409
+ }
2270
2410
  var user = {
2271
2411
  hasScope: (scope) => defineConditional({
2272
2412
  type: "object",
@@ -2314,69 +2454,120 @@ var event = {
2314
2454
  required: ["$event"]
2315
2455
  })
2316
2456
  };
2457
+ function getDateFromNow(days) {
2458
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2459
+ }
2460
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2461
+ return {
2462
+ type: "object",
2463
+ properties: {
2464
+ [fieldId]: {
2465
+ type: "string",
2466
+ format: "date",
2467
+ [clause]: { $data: `1/${comparedFieldId}` }
2468
+ },
2469
+ [comparedFieldId]: { type: "string", format: "date" }
2470
+ },
2471
+ required: [fieldId]
2472
+ };
2473
+ }
2474
+ function isFieldReference(value) {
2475
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2476
+ }
2317
2477
  function field(fieldId) {
2318
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2319
2478
  const getDateRange = (date, clause) => ({
2320
2479
  type: "object",
2321
2480
  properties: {
2322
- $form: {
2323
- type: "object",
2324
- properties: {
2325
- [fieldId]: {
2326
- type: "string",
2327
- format: "date",
2328
- [clause]: date
2329
- }
2330
- },
2331
- required: [fieldId]
2481
+ [fieldId]: {
2482
+ type: "string",
2483
+ format: "date",
2484
+ [clause]: date
2332
2485
  }
2333
2486
  },
2334
- required: ["$form"]
2487
+ required: [fieldId]
2335
2488
  });
2336
2489
  return {
2490
+ /**
2491
+ * @private Internal property used for field reference tracking.
2492
+ */
2493
+ _fieldId: fieldId,
2337
2494
  isAfter: () => ({
2338
2495
  days: (days) => ({
2339
- inPast: () => defineConditional(
2496
+ inPast: () => defineFormConditional(
2340
2497
  getDateRange(getDateFromNow(days), "formatMinimum")
2341
2498
  ),
2342
- inFuture: () => defineConditional(
2499
+ inFuture: () => defineFormConditional(
2343
2500
  getDateRange(getDateFromNow(-days), "formatMinimum")
2344
2501
  )
2345
2502
  }),
2346
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
2347
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2503
+ date: (date) => {
2504
+ if (isFieldReference(date)) {
2505
+ const comparedFieldId = date._fieldId;
2506
+ return defineFormConditional(
2507
+ getDateRangeToFieldReference(
2508
+ fieldId,
2509
+ comparedFieldId,
2510
+ "formatMinimum"
2511
+ )
2512
+ );
2513
+ }
2514
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2515
+ },
2516
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2348
2517
  }),
2349
2518
  isBefore: () => ({
2350
2519
  days: (days) => ({
2351
- inPast: () => defineConditional(
2520
+ inPast: () => defineFormConditional(
2352
2521
  getDateRange(getDateFromNow(days), "formatMaximum")
2353
2522
  ),
2354
- inFuture: () => defineConditional(
2523
+ inFuture: () => defineFormConditional(
2355
2524
  getDateRange(getDateFromNow(-days), "formatMaximum")
2356
2525
  )
2357
2526
  }),
2358
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
2359
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2527
+ date: (date) => {
2528
+ if (isFieldReference(date)) {
2529
+ const comparedFieldId = date._fieldId;
2530
+ return defineFormConditional(
2531
+ getDateRangeToFieldReference(
2532
+ fieldId,
2533
+ comparedFieldId,
2534
+ "formatMaximum"
2535
+ )
2536
+ );
2537
+ }
2538
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2539
+ },
2540
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2360
2541
  }),
2361
- isEqualTo: (value) => defineConditional({
2362
- type: "object",
2363
- properties: {
2364
- $form: {
2542
+ isEqualTo: (value) => {
2543
+ if (isFieldReference(value)) {
2544
+ const comparedFieldId = value._fieldId;
2545
+ return defineFormConditional({
2365
2546
  type: "object",
2366
2547
  properties: {
2367
2548
  [fieldId]: {
2368
- oneOf: [
2369
- { type: "string", const: value },
2370
- { type: "boolean", const: value }
2371
- ],
2372
- const: value
2373
- }
2549
+ type: ["string", "boolean"],
2550
+ const: { $data: `1/${comparedFieldId}` }
2551
+ },
2552
+ [comparedFieldId]: { type: ["string", "boolean"] }
2374
2553
  },
2375
- required: [fieldId]
2376
- }
2377
- },
2378
- required: ["$form"]
2379
- }),
2554
+ required: [fieldId, comparedFieldId]
2555
+ });
2556
+ }
2557
+ return defineFormConditional({
2558
+ type: "object",
2559
+ properties: {
2560
+ [fieldId]: {
2561
+ oneOf: [
2562
+ { type: "string", const: value },
2563
+ { type: "boolean", const: value }
2564
+ ],
2565
+ const: value
2566
+ }
2567
+ },
2568
+ required: [fieldId]
2569
+ });
2570
+ },
2380
2571
  /**
2381
2572
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
2382
2573
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -2385,108 +2576,102 @@ function field(fieldId) {
2385
2576
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2386
2577
  *
2387
2578
  */
2388
- isFalsy: () => defineConditional({
2579
+ isFalsy: () => defineFormConditional({
2389
2580
  type: "object",
2390
2581
  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
- },
2582
+ [fieldId]: {
2403
2583
  anyOf: [
2404
- {
2405
- required: [fieldId]
2406
- },
2407
- {
2408
- not: {
2409
- required: [fieldId]
2410
- }
2411
- }
2584
+ { const: "undefined" },
2585
+ { const: false },
2586
+ { const: null },
2587
+ { const: "" }
2412
2588
  ]
2413
2589
  }
2414
2590
  },
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
- },
2591
+ anyOf: [
2592
+ {
2593
+ required: [fieldId]
2594
+ },
2595
+ {
2428
2596
  not: {
2429
2597
  required: [fieldId]
2430
2598
  }
2431
2599
  }
2600
+ ]
2601
+ }),
2602
+ isUndefined: () => defineFormConditional({
2603
+ type: "object",
2604
+ properties: {
2605
+ [fieldId]: {
2606
+ type: "string",
2607
+ enum: ["undefined"]
2608
+ }
2432
2609
  },
2433
- required: ["$form"]
2610
+ not: {
2611
+ required: [fieldId]
2612
+ }
2434
2613
  }),
2435
- inArray: (values) => defineConditional({
2614
+ inArray: (values) => defineFormConditional({
2436
2615
  type: "object",
2437
2616
  properties: {
2438
- $form: {
2439
- type: "object",
2440
- properties: {
2441
- [fieldId]: {
2442
- type: "string",
2443
- enum: values
2444
- }
2445
- },
2446
- required: [fieldId]
2617
+ [fieldId]: {
2618
+ type: "string",
2619
+ enum: values
2447
2620
  }
2448
2621
  },
2449
- required: ["$form"]
2622
+ required: [fieldId]
2450
2623
  }),
2451
- isValidEnglishName: () => defineConditional({
2624
+ isValidEnglishName: () => defineFormConditional({
2452
2625
  type: "object",
2453
2626
  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]
2627
+ [fieldId]: {
2628
+ type: "string",
2629
+ pattern: "^[\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*( [\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*)*$",
2630
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2631
+ }
2632
+ },
2633
+ required: [fieldId]
2634
+ }),
2635
+ /**
2636
+ * Checks if the field value matches a given regular expression pattern.
2637
+ * @param pattern - The regular expression pattern to match the field value against.
2638
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2639
+ */
2640
+ matches: (pattern) => defineFormConditional({
2641
+ type: "object",
2642
+ properties: {
2643
+ [fieldId]: {
2644
+ type: "string",
2645
+ pattern
2464
2646
  }
2465
2647
  },
2466
- required: ["$form"]
2648
+ required: [fieldId]
2649
+ }),
2650
+ isBetween: (min, max) => defineFormConditional({
2651
+ type: "object",
2652
+ properties: {
2653
+ [fieldId]: {
2654
+ type: "number",
2655
+ minimum: min,
2656
+ maximum: max
2657
+ }
2658
+ },
2659
+ required: [fieldId]
2467
2660
  })
2468
2661
  };
2469
2662
  }
2470
2663
 
2471
2664
  // ../commons/src/fixtures/tennis-club-membership-event.ts
2472
- var PRINT_CERTIFICATE_FORM = defineForm({
2665
+ var PRINT_CERTIFICATE_FORM = defineActionForm({
2473
2666
  label: {
2474
2667
  id: "v2.event.tennis-club-membership.action.certificate.form.label",
2475
2668
  defaultMessage: "Tennis club membership certificate collector",
2476
2669
  description: "This is what this form is referred as in the system"
2477
2670
  },
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
2671
  pages: [
2488
2672
  {
2489
2673
  id: "collector",
2674
+ type: PageTypes.enum.FORM,
2490
2675
  title: {
2491
2676
  id: "v2.event.tennis-club-membership.action.certificate.form.section.who.title",
2492
2677
  defaultMessage: "Print certified copy",
@@ -2501,7 +2686,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2501
2686
  defaultMessage: "Requester",
2502
2687
  description: "This is the label for the field"
2503
2688
  },
2504
- type: "SELECT",
2689
+ type: FieldType.SELECT,
2505
2690
  options: [
2506
2691
  {
2507
2692
  value: "INFORMANT",
@@ -2578,7 +2763,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2578
2763
  defaultMessage: "Select Type of ID",
2579
2764
  description: "This is the label for selecting the type of ID"
2580
2765
  },
2581
- type: "SELECT",
2766
+ type: FieldType.SELECT,
2582
2767
  options: [
2583
2768
  {
2584
2769
  value: "PASSPORT",
@@ -2679,7 +2864,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2679
2864
  defaultMessage: "Passport Details",
2680
2865
  description: "Field for entering Passport details"
2681
2866
  },
2682
- type: "TEXT"
2867
+ type: FieldType.TEXT
2683
2868
  },
2684
2869
  {
2685
2870
  id: "collector.DRIVING_LICENSE.details",
@@ -2730,7 +2915,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2730
2915
  defaultMessage: "Driving License Details",
2731
2916
  description: "Field for entering Driving License details"
2732
2917
  },
2733
- type: "TEXT"
2918
+ type: FieldType.TEXT
2734
2919
  },
2735
2920
  {
2736
2921
  id: "collector.REFUGEE_NUMBER.details",
@@ -2781,7 +2966,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2781
2966
  defaultMessage: "Refugee Number Details",
2782
2967
  description: "Field for entering Refugee Number details"
2783
2968
  },
2784
- type: "TEXT"
2969
+ type: FieldType.TEXT
2785
2970
  },
2786
2971
  {
2787
2972
  id: "collector.ALIEN_NUMBER.details",
@@ -2832,7 +3017,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2832
3017
  defaultMessage: "Alien Number Details",
2833
3018
  description: "Field for entering Alien Number details"
2834
3019
  },
2835
- type: "TEXT"
3020
+ type: FieldType.TEXT
2836
3021
  },
2837
3022
  {
2838
3023
  id: "collector.OTHER.idTypeOther",
@@ -2883,7 +3068,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2883
3068
  defaultMessage: "Other ID Type (if applicable)",
2884
3069
  description: 'Field for entering ID type if "Other" is selected'
2885
3070
  },
2886
- type: "TEXT"
3071
+ type: FieldType.TEXT
2887
3072
  },
2888
3073
  {
2889
3074
  id: "collector.OTHER.firstName",
@@ -2934,7 +3119,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2934
3119
  defaultMessage: "First Name",
2935
3120
  description: "This is the label for the first name field"
2936
3121
  },
2937
- type: "TEXT"
3122
+ type: FieldType.TEXT
2938
3123
  },
2939
3124
  {
2940
3125
  id: "collector.OTHER.lastName",
@@ -2985,7 +3170,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2985
3170
  defaultMessage: "Last Name",
2986
3171
  description: "This is the label for the last name field"
2987
3172
  },
2988
- type: "TEXT"
3173
+ type: FieldType.TEXT
2989
3174
  },
2990
3175
  {
2991
3176
  id: "collector.OTHER.relationshipToMember",
@@ -3036,7 +3221,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
3036
3221
  defaultMessage: "Relationship to Member",
3037
3222
  description: "This is the label for the relationship to member field"
3038
3223
  },
3039
- type: "TEXT"
3224
+ type: FieldType.TEXT
3040
3225
  },
3041
3226
  {
3042
3227
  id: "collector.OTHER.signedAffidavit",
@@ -3087,13 +3272,14 @@ var PRINT_CERTIFICATE_FORM = defineForm({
3087
3272
  defaultMessage: "Signed Affidavit (Optional)",
3088
3273
  description: "This is the label for uploading a signed affidavit"
3089
3274
  },
3090
- type: "FILE"
3275
+ type: FieldType.FILE
3091
3276
  }
3092
3277
  ]
3093
3278
  },
3094
3279
  {
3095
3280
  id: "collector.identity.verify",
3096
- type: FormPageType.VERIFICATION,
3281
+ type: PageTypes.enum.VERIFICATION,
3282
+ conditional: field("collector.requesterId").isEqualTo("INFORMANT"),
3097
3283
  title: {
3098
3284
  id: "event.tennis-club-membership.action.print.verifyIdentity",
3099
3285
  defaultMessage: "Verify their identity",
@@ -3129,62 +3315,45 @@ var PRINT_CERTIFICATE_FORM = defineForm({
3129
3315
  }
3130
3316
  }
3131
3317
  }
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
- }
3318
+ ]
3141
3319
  });
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
- }
3320
+ var TENNIS_CLUB_DECLARATION_REVIEW = {
3321
+ title: {
3322
+ id: "v2.event.tennis-club-membership.action.declare.form.review.title",
3323
+ defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
3324
+ description: "Title of the review page"
3156
3325
  },
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"
3326
+ fields: [
3327
+ {
3328
+ id: "review.comment",
3329
+ type: FieldType.TEXTAREA,
3330
+ label: {
3331
+ defaultMessage: "Comment",
3332
+ id: "v2.event.birth.action.declare.form.review.comment.label",
3333
+ description: "Label for the comment field in the review section"
3334
+ }
3162
3335
  },
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
- }
3336
+ {
3337
+ type: FieldType.SIGNATURE,
3338
+ id: "review.signature",
3339
+ label: {
3340
+ defaultMessage: "Signature of informant",
3341
+ id: "v2.event.birth.action.declare.form.review.signature.label",
3342
+ description: "Label for the signature field in the review section"
3172
3343
  },
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
- }
3344
+ signaturePromptLabel: {
3345
+ id: "v2.signature.upload.modal.title",
3346
+ defaultMessage: "Draw signature",
3347
+ description: "Title for the modal to draw signature"
3186
3348
  }
3187
- ]
3349
+ }
3350
+ ]
3351
+ };
3352
+ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3353
+ label: {
3354
+ id: "v2.event.tennis-club-membership.action.declare.form.label",
3355
+ defaultMessage: "Tennis club membership application",
3356
+ description: "This is what this form is referred as in the system"
3188
3357
  },
3189
3358
  pages: [
3190
3359
  {
@@ -3197,7 +3366,7 @@ var TENNIS_CLUB_FORM = defineForm({
3197
3366
  fields: [
3198
3367
  {
3199
3368
  id: "applicant.firstname",
3200
- type: "TEXT",
3369
+ type: FieldType.TEXT,
3201
3370
  required: true,
3202
3371
  conditionals: [],
3203
3372
  label: {
@@ -3208,7 +3377,7 @@ var TENNIS_CLUB_FORM = defineForm({
3208
3377
  },
3209
3378
  {
3210
3379
  id: "applicant.surname",
3211
- type: "TEXT",
3380
+ type: FieldType.TEXT,
3212
3381
  required: true,
3213
3382
  conditionals: [],
3214
3383
  label: {
@@ -3230,9 +3399,8 @@ var TENNIS_CLUB_FORM = defineForm({
3230
3399
  },
3231
3400
  {
3232
3401
  id: "applicant.dob",
3233
- type: "DATE",
3402
+ type: FieldType.DATE,
3234
3403
  required: true,
3235
- conditionals: [],
3236
3404
  validation: [
3237
3405
  {
3238
3406
  message: {
@@ -3243,15 +3411,53 @@ var TENNIS_CLUB_FORM = defineForm({
3243
3411
  validator: field("applicant.dob").isBefore().now()
3244
3412
  }
3245
3413
  ],
3414
+ conditionals: [
3415
+ {
3416
+ type: ConditionalType.SHOW,
3417
+ conditional: field("applicant.dobUnknown").isFalsy()
3418
+ }
3419
+ ],
3246
3420
  label: {
3247
3421
  defaultMessage: "Applicant's date of birth",
3248
3422
  description: "This is the label for the field",
3249
3423
  id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dob.label"
3250
3424
  }
3251
3425
  },
3426
+ {
3427
+ id: "applicant.dobUnknown",
3428
+ type: FieldType.CHECKBOX,
3429
+ required: false,
3430
+ label: {
3431
+ defaultMessage: "Exact date of birth unknown",
3432
+ description: "This is the label for the field",
3433
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dobUnknown.label"
3434
+ },
3435
+ conditionals: [
3436
+ {
3437
+ type: ConditionalType.DISPLAY_ON_REVIEW,
3438
+ conditional: never()
3439
+ }
3440
+ ]
3441
+ },
3442
+ {
3443
+ id: "applicant.age",
3444
+ type: FieldType.NUMBER,
3445
+ required: true,
3446
+ label: {
3447
+ defaultMessage: "Age of tennis-member",
3448
+ description: "This is the label for the field",
3449
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.age.label"
3450
+ },
3451
+ conditionals: [
3452
+ {
3453
+ type: ConditionalType.SHOW,
3454
+ conditional: field("applicant.dobUnknown").isEqualTo(true)
3455
+ }
3456
+ ]
3457
+ },
3252
3458
  {
3253
3459
  id: "applicant.image",
3254
- type: "FILE",
3460
+ type: FieldType.FILE,
3255
3461
  required: false,
3256
3462
  label: {
3257
3463
  defaultMessage: "Applicant's profile picture",
@@ -3272,6 +3478,27 @@ var TENNIS_CLUB_FORM = defineForm({
3272
3478
  }
3273
3479
  ]
3274
3480
  },
3481
+ {
3482
+ id: "senior-pass",
3483
+ conditional: field("applicant.dob").isBefore().date("1950-01-01"),
3484
+ title: {
3485
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.title",
3486
+ defaultMessage: "Assign senior pass for applicant",
3487
+ description: "This is the title of the section"
3488
+ },
3489
+ fields: [
3490
+ {
3491
+ id: "senior-pass.id",
3492
+ type: FieldType.TEXT,
3493
+ required: true,
3494
+ label: {
3495
+ defaultMessage: "Senior pass ID",
3496
+ description: "This is the label for the field",
3497
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.field.id.label"
3498
+ }
3499
+ }
3500
+ ]
3501
+ },
3275
3502
  {
3276
3503
  id: "recommender",
3277
3504
  title: {
@@ -3293,7 +3520,7 @@ var TENNIS_CLUB_FORM = defineForm({
3293
3520
  },
3294
3521
  {
3295
3522
  id: "recommender.firstname",
3296
- type: "TEXT",
3523
+ type: FieldType.TEXT,
3297
3524
  required: true,
3298
3525
  conditionals: [
3299
3526
  {
@@ -3309,7 +3536,7 @@ var TENNIS_CLUB_FORM = defineForm({
3309
3536
  },
3310
3537
  {
3311
3538
  id: "recommender.surname",
3312
- type: "TEXT",
3539
+ type: FieldType.TEXT,
3313
3540
  required: true,
3314
3541
  conditionals: [
3315
3542
  {
@@ -3325,7 +3552,7 @@ var TENNIS_CLUB_FORM = defineForm({
3325
3552
  },
3326
3553
  {
3327
3554
  id: "recommender.id",
3328
- type: "TEXT",
3555
+ type: FieldType.TEXT,
3329
3556
  required: true,
3330
3557
  conditionals: [
3331
3558
  {
@@ -3433,7 +3660,7 @@ var tennisClubMembershipEvent = defineConfig({
3433
3660
  description: "This is shown as the action name anywhere the user can trigger the action from",
3434
3661
  id: "event.tennis-club-membership.action.declare.label"
3435
3662
  },
3436
- forms: [TENNIS_CLUB_FORM]
3663
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3437
3664
  },
3438
3665
  {
3439
3666
  type: ActionType.VALIDATE,
@@ -3442,7 +3669,7 @@ var tennisClubMembershipEvent = defineConfig({
3442
3669
  description: "This is shown as the action name anywhere the user can trigger the action from",
3443
3670
  id: "event.tennis-club-membership.action.validate.label"
3444
3671
  },
3445
- forms: [TENNIS_CLUB_FORM]
3672
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3446
3673
  },
3447
3674
  {
3448
3675
  type: ActionType.REGISTER,
@@ -3451,7 +3678,7 @@ var tennisClubMembershipEvent = defineConfig({
3451
3678
  description: "This is shown as the action name anywhere the user can trigger the action from",
3452
3679
  id: "event.tennis-club-membership.action.register.label"
3453
3680
  },
3454
- forms: [TENNIS_CLUB_FORM]
3681
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3455
3682
  },
3456
3683
  {
3457
3684
  type: ActionType.REQUEST_CORRECTION,
@@ -3460,10 +3687,10 @@ var tennisClubMembershipEvent = defineConfig({
3460
3687
  description: "This is shown as the action name anywhere the user can trigger the action from",
3461
3688
  id: "event.tennis-club-membership.action.correction.request.label"
3462
3689
  },
3463
- forms: [TENNIS_CLUB_FORM],
3464
3690
  onboardingForm: [
3465
3691
  {
3466
3692
  id: "correction-requester",
3693
+ type: PageTypes.enum.FORM,
3467
3694
  title: {
3468
3695
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3469
3696
  defaultMessage: "Correction requester",
@@ -3527,6 +3754,7 @@ var tennisClubMembershipEvent = defineConfig({
3527
3754
  },
3528
3755
  {
3529
3756
  id: "identity-check",
3757
+ type: PageTypes.enum.FORM,
3530
3758
  title: {
3531
3759
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3532
3760
  defaultMessage: "Verify their identity",
@@ -3569,6 +3797,7 @@ var tennisClubMembershipEvent = defineConfig({
3569
3797
  additionalDetailsForm: [
3570
3798
  {
3571
3799
  id: "correction-request.supporting-documents",
3800
+ type: PageTypes.enum.FORM,
3572
3801
  title: {
3573
3802
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3574
3803
  defaultMessage: "Upload supporting documents",
@@ -3586,7 +3815,7 @@ var tennisClubMembershipEvent = defineConfig({
3586
3815
  },
3587
3816
  {
3588
3817
  id: "correction.supportingDocs",
3589
- type: "FILE",
3818
+ type: FieldType.FILE,
3590
3819
  label: {
3591
3820
  id: "correction.corrector.title",
3592
3821
  defaultMessage: "Upload supporting documents",
@@ -3630,6 +3859,7 @@ var tennisClubMembershipEvent = defineConfig({
3630
3859
  },
3631
3860
  {
3632
3861
  id: "correction-request.additional-details",
3862
+ type: PageTypes.enum.FORM,
3633
3863
  title: {
3634
3864
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3635
3865
  defaultMessage: "Reason for correction",
@@ -3638,7 +3868,7 @@ var tennisClubMembershipEvent = defineConfig({
3638
3868
  fields: [
3639
3869
  {
3640
3870
  id: "correction.request.reason",
3641
- type: "TEXT",
3871
+ type: FieldType.TEXT,
3642
3872
  label: {
3643
3873
  id: "correction.reason.title",
3644
3874
  defaultMessage: "Reason for correction?",
@@ -3651,7 +3881,6 @@ var tennisClubMembershipEvent = defineConfig({
3651
3881
  },
3652
3882
  {
3653
3883
  type: ActionType.APPROVE_CORRECTION,
3654
- forms: [TENNIS_CLUB_FORM],
3655
3884
  label: {
3656
3885
  defaultMessage: "Approve correction",
3657
3886
  description: "This is shown as the action name anywhere the user can trigger the action from",
@@ -3665,7 +3894,7 @@ var tennisClubMembershipEvent = defineConfig({
3665
3894
  defaultMessage: "Print certificate",
3666
3895
  description: "This is shown as the action name anywhere the user can trigger the action from"
3667
3896
  },
3668
- forms: [PRINT_CERTIFICATE_FORM],
3897
+ printForm: PRINT_CERTIFICATE_FORM,
3669
3898
  conditionals: [
3670
3899
  {
3671
3900
  type: "SHOW",
@@ -3712,8 +3941,7 @@ var tennisClubMembershipEvent = defineConfig({
3712
3941
  id: "v2.event.tennis-club-membership.action.archive.label",
3713
3942
  defaultMessage: "Archive",
3714
3943
  description: "This is shown as the action name anywhere the user can trigger the action from"
3715
- },
3716
- forms: [TENNIS_CLUB_FORM]
3944
+ }
3717
3945
  },
3718
3946
  {
3719
3947
  type: ActionType.REJECT,
@@ -3721,8 +3949,7 @@ var tennisClubMembershipEvent = defineConfig({
3721
3949
  id: "v2.event.tennis-club-membership.action.reject.label",
3722
3950
  defaultMessage: "Reject",
3723
3951
  description: "This is shown as the action name anywhere the user can trigger the action from"
3724
- },
3725
- forms: [TENNIS_CLUB_FORM]
3952
+ }
3726
3953
  }
3727
3954
  ],
3728
3955
  advancedSearch: [
@@ -3738,33 +3965,53 @@ var tennisClubMembershipEvent = defineConfig({
3738
3965
  }
3739
3966
  ]
3740
3967
  }
3741
- ]
3968
+ ],
3969
+ declaration: TENNIS_CLUB_DECLARATION_FORM
3742
3970
  });
3743
3971
 
3744
3972
  // ../commons/src/events/test.utils.ts
3745
- function generateActionInput(configuration, action) {
3746
- const fields = findActiveActionFormFields(configuration, action) ?? [];
3747
- const data = fields.reduce(
3973
+ function fieldConfigsToActionPayload(fields) {
3974
+ return fields.reduce(
3748
3975
  (acc, field2, i) => ({
3749
3976
  ...acc,
3750
3977
  [field2.id]: mapFieldTypeToMockValue(field2, i)
3751
3978
  }),
3752
3979
  {}
3753
3980
  );
3754
- return stripHiddenFields(fields, data);
3755
3981
  }
3756
- function generateActionMetadataInput(configuration, action) {
3757
- const verificationPageIds = findActiveActionVerificationPageIds(
3982
+ function generateActionDeclarationInput(configuration, action) {
3983
+ const parsed = DeclarationUpdateActions.safeParse(action);
3984
+ if (parsed.success) {
3985
+ const fields = getDeclarationFields(configuration);
3986
+ const declarationConfig = getDeclaration(configuration);
3987
+ const declaration = fieldConfigsToActionPayload(fields);
3988
+ return omitHiddenPaginatedFields(declarationConfig, declaration);
3989
+ }
3990
+ console.warn(`${action} is not a declaration action. Setting data as {}.`);
3991
+ return {};
3992
+ }
3993
+ function generateActionAnnotationInput(configuration, action) {
3994
+ const actionConfig = configuration.actions.find(
3995
+ (ac) => ac.type === action
3996
+ );
3997
+ const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
3998
+ const annotation = fieldConfigsToActionPayload(annotationFields);
3999
+ const visibleVerificationPageIds = findRecordActionPages(
3758
4000
  configuration,
3759
4001
  action
3760
- );
3761
- return verificationPageIds.reduce(
4002
+ ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
4003
+ const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
3762
4004
  (acc, pageId) => ({
3763
4005
  ...acc,
3764
4006
  [pageId]: true
3765
4007
  }),
3766
4008
  {}
3767
4009
  );
4010
+ const fieldBasedPayload = omitHiddenFields(annotationFields, annotation);
4011
+ return {
4012
+ ...fieldBasedPayload,
4013
+ ...visiblePageVerificationMap
4014
+ };
3768
4015
  }
3769
4016
  var eventPayloadGenerator = {
3770
4017
  create: (input = {}) => ({
@@ -3776,21 +4023,22 @@ var eventPayloadGenerator = {
3776
4023
  type: input.type ?? "TENNIS_CLUB_MEMBERSHIP",
3777
4024
  id
3778
4025
  }),
3779
- draft: (eventId, input = {}) => (0, import_lodash2.merge)(
4026
+ draft: ({ eventId, actionType }, input = {}) => (0, import_lodash2.merge)(
3780
4027
  {
3781
4028
  id: getUUID(),
3782
4029
  eventId,
3783
4030
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3784
4031
  transactionId: getUUID(),
3785
4032
  action: {
3786
- type: ActionType.REQUEST_CORRECTION,
3787
- data: {
4033
+ type: actionType,
4034
+ status: ActionStatus.Accepted,
4035
+ declaration: {
3788
4036
  "applicant.firstname": "Max",
3789
4037
  "applicant.surname": "McLaren",
3790
4038
  "applicant.dob": "2020-01-02",
3791
4039
  "recommender.none": true
3792
4040
  },
3793
- metadata: {
4041
+ annotation: {
3794
4042
  "correction.requester.relationship": "ANOTHER_AGENT",
3795
4043
  "correction.request.reason": "Child's name was incorrect"
3796
4044
  },
@@ -3805,45 +4053,104 @@ var eventPayloadGenerator = {
3805
4053
  declare: (eventId, input = {}) => ({
3806
4054
  type: ActionType.DECLARE,
3807
4055
  transactionId: input.transactionId ?? getUUID(),
3808
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4056
+ declaration: input.declaration ?? generateActionDeclarationInput(
4057
+ tennisClubMembershipEvent,
4058
+ ActionType.DECLARE
4059
+ ),
4060
+ annotation: input.annotation ?? generateActionAnnotationInput(
4061
+ tennisClubMembershipEvent,
4062
+ ActionType.DECLARE
4063
+ ),
3809
4064
  eventId
3810
4065
  }),
4066
+ /**
4067
+ * Notify allows sending incomplete data. Think it as 'partial declare' for now.
4068
+ */
4069
+ notify: (eventId, input = {}) => {
4070
+ let declaration = input.declaration;
4071
+ if (!declaration) {
4072
+ const partialDeclaration = (0, import_lodash2.omitBy)(
4073
+ generateActionDeclarationInput(
4074
+ tennisClubMembershipEvent,
4075
+ ActionType.DECLARE
4076
+ ),
4077
+ import_lodash2.isString
4078
+ );
4079
+ declaration = partialDeclaration;
4080
+ }
4081
+ return {
4082
+ type: ActionType.NOTIFY,
4083
+ transactionId: input.transactionId ?? getUUID(),
4084
+ declaration,
4085
+ eventId
4086
+ };
4087
+ },
3811
4088
  validate: (eventId, input = {}) => ({
3812
4089
  type: ActionType.VALIDATE,
3813
4090
  transactionId: input.transactionId ?? getUUID(),
3814
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4091
+ declaration: input.declaration ?? generateActionDeclarationInput(
4092
+ tennisClubMembershipEvent,
4093
+ ActionType.VALIDATE
4094
+ ),
4095
+ annotation: input.annotation ?? generateActionAnnotationInput(
4096
+ tennisClubMembershipEvent,
4097
+ ActionType.VALIDATE
4098
+ ),
3815
4099
  duplicates: [],
3816
4100
  eventId
3817
4101
  }),
4102
+ assign: (eventId, input = {}) => ({
4103
+ type: ActionType.ASSIGN,
4104
+ transactionId: input.transactionId ?? getUUID(),
4105
+ declaration: {},
4106
+ assignedTo: input.assignedTo ?? getUUID(),
4107
+ eventId
4108
+ }),
4109
+ unassign: (eventId, input = {}) => ({
4110
+ type: ActionType.UNASSIGN,
4111
+ transactionId: input.transactionId ?? getUUID(),
4112
+ declaration: {},
4113
+ assignedTo: null,
4114
+ eventId
4115
+ }),
3818
4116
  archive: (eventId, input = {}, isDuplicate) => ({
3819
4117
  type: ActionType.ARCHIVE,
3820
4118
  transactionId: input.transactionId ?? getUUID(),
3821
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.ARCHIVE),
3822
- metadata: { isDuplicate: isDuplicate ?? false },
4119
+ declaration: {},
4120
+ // @TODO: Check whether generator is needed?
4121
+ annotation: { isDuplicate: isDuplicate ?? false },
3823
4122
  duplicates: [],
3824
4123
  eventId
3825
4124
  }),
3826
4125
  reject: (eventId, input = {}) => ({
3827
4126
  type: ActionType.REJECT,
3828
4127
  transactionId: input.transactionId ?? getUUID(),
3829
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REJECT),
4128
+ declaration: {},
4129
+ annotation: input.annotation ?? generateActionAnnotationInput(
4130
+ tennisClubMembershipEvent,
4131
+ ActionType.REJECT
4132
+ ),
3830
4133
  duplicates: [],
3831
4134
  eventId
3832
4135
  }),
3833
4136
  register: (eventId, input = {}) => ({
3834
4137
  type: ActionType.REGISTER,
3835
4138
  transactionId: input.transactionId ?? getUUID(),
3836
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4139
+ declaration: input.declaration ?? generateActionDeclarationInput(
4140
+ tennisClubMembershipEvent,
4141
+ ActionType.REGISTER
4142
+ ),
4143
+ annotation: input.annotation ?? generateActionAnnotationInput(
4144
+ tennisClubMembershipEvent,
4145
+ ActionType.REGISTER
4146
+ ),
3837
4147
  eventId
3838
4148
  }),
3839
4149
  printCertificate: (eventId, input = {}) => ({
3840
4150
  type: ActionType.PRINT_CERTIFICATE,
3841
4151
  transactionId: input.transactionId ?? getUUID(),
3842
- data: input.data ?? generateActionInput(
3843
- tennisClubMembershipEvent,
3844
- ActionType.PRINT_CERTIFICATE
3845
- ),
3846
- metadata: input.metadata ?? generateActionMetadataInput(
4152
+ declaration: {},
4153
+ annotation: input.annotation ?? generateActionAnnotationInput(
3847
4154
  tennisClubMembershipEvent,
3848
4155
  ActionType.PRINT_CERTIFICATE
3849
4156
  ),
@@ -3853,17 +4160,21 @@ var eventPayloadGenerator = {
3853
4160
  request: (eventId, input = {}) => ({
3854
4161
  type: ActionType.REQUEST_CORRECTION,
3855
4162
  transactionId: input.transactionId ?? getUUID(),
3856
- data: input.data ?? generateActionInput(
4163
+ declaration: input.declaration ?? generateActionDeclarationInput(
4164
+ tennisClubMembershipEvent,
4165
+ ActionType.REQUEST_CORRECTION
4166
+ ),
4167
+ annotation: input.annotation ?? generateActionAnnotationInput(
3857
4168
  tennisClubMembershipEvent,
3858
4169
  ActionType.REQUEST_CORRECTION
3859
4170
  ),
3860
- metadata: {},
3861
4171
  eventId
3862
4172
  }),
3863
4173
  approve: (eventId, requestId, input = {}) => ({
3864
4174
  type: ActionType.APPROVE_CORRECTION,
3865
4175
  transactionId: input.transactionId ?? getUUID(),
3866
- data: input.data ?? generateActionInput(
4176
+ declaration: {},
4177
+ annotation: input.annotation ?? generateActionAnnotationInput(
3867
4178
  tennisClubMembershipEvent,
3868
4179
  ActionType.APPROVE_CORRECTION
3869
4180
  ),
@@ -3873,7 +4184,8 @@ var eventPayloadGenerator = {
3873
4184
  reject: (eventId, requestId, input = {}) => ({
3874
4185
  type: ActionType.REJECT_CORRECTION,
3875
4186
  transactionId: input.transactionId ?? getUUID(),
3876
- data: input.data ?? generateActionInput(
4187
+ declaration: {},
4188
+ annotation: input.annotation ?? generateActionAnnotationInput(
3877
4189
  tennisClubMembershipEvent,
3878
4190
  ActionType.REJECT_CORRECTION
3879
4191
  ),
@@ -3895,11 +4207,16 @@ function generateActionDocument({
3895
4207
  createdBy: getUUID(),
3896
4208
  id: getUUID(),
3897
4209
  createdAtLocation: "TODO",
3898
- data: generateActionInput(configuration, action),
3899
- metadata: {},
3900
- ...defaults
4210
+ declaration: generateActionDeclarationInput(configuration, action),
4211
+ annotation: {},
4212
+ ...defaults,
4213
+ status: ActionStatus.Accepted
3901
4214
  };
3902
4215
  switch (action) {
4216
+ case ActionType.READ:
4217
+ return { ...actionBase, type: action };
4218
+ case ActionType.MARKED_AS_DUPLICATE:
4219
+ return { ...actionBase, type: action };
3903
4220
  case ActionType.DECLARE:
3904
4221
  return { ...actionBase, type: action };
3905
4222
  case ActionType.UNASSIGN:
@@ -3924,14 +4241,13 @@ function generateActionDocument({
3924
4241
  return { ...actionBase, requestId: getUUID(), type: action };
3925
4242
  case ActionType.REJECT_CORRECTION:
3926
4243
  return { ...actionBase, requestId: getUUID(), type: action };
3927
- case ActionType.CUSTOM:
3928
- return { ...actionBase, type: action };
3929
4244
  case ActionType.REGISTER:
3930
4245
  return {
3931
4246
  ...actionBase,
3932
- type: action,
3933
- identifiers: { trackingId: getUUID(), registrationNumber: getUUID() }
4247
+ type: action
3934
4248
  };
4249
+ case ActionType.DELETE:
4250
+ case ActionType.DETECT_DUPLICATE:
3935
4251
  default:
3936
4252
  throw new Error(`Unsupported action type: ${action}`);
3937
4253
  }
@@ -3955,7 +4271,7 @@ function generateEventDocument({
3955
4271
  updatedAt: new Date(Date.now() - 1e3).toISOString()
3956
4272
  };
3957
4273
  }
3958
- function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, data = {}) {
4274
+ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
3959
4275
  const action = generateActionDocument({
3960
4276
  configuration: tennisClubMembershipEvent,
3961
4277
  action: actionType
@@ -3965,9 +4281,9 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, da
3965
4281
  transactionId: getUUID(),
3966
4282
  action: {
3967
4283
  ...action,
3968
- data: {
3969
- ...action.data,
3970
- ...data
4284
+ declaration: {
4285
+ ...action.declaration,
4286
+ ...declaration
3971
4287
  }
3972
4288
  },
3973
4289
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3984,7 +4300,7 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3984
4300
  modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3985
4301
  assignedTo: overrides.assignedTo ?? null,
3986
4302
  updatedBy: overrides.updatedBy ?? getUUID(),
3987
- data: overrides.data ?? {
4303
+ declaration: overrides.declaration ?? {
3988
4304
  "recommender.none": true,
3989
4305
  "applicant.firstname": "Danny",
3990
4306
  "applicant.surname": "Doe",
@@ -4015,7 +4331,9 @@ function isFieldValueWithoutTemplates(value) {
4015
4331
  return true;
4016
4332
  }
4017
4333
  function isFieldConfigDefaultValue(value) {
4018
- if (!value) return false;
4334
+ if (!value) {
4335
+ return false;
4336
+ }
4019
4337
  if (isFieldValue(value)) {
4020
4338
  return true;
4021
4339
  }