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

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,21 +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,
94
108
  ReadActionInput: () => ReadActionInput,
109
+ RegisterAction: () => RegisterAction,
95
110
  RegisterActionInput: () => RegisterActionInput,
96
111
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
97
112
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
@@ -104,23 +119,29 @@ __export(events_exports, {
104
119
  SummaryConfig: () => SummaryConfig,
105
120
  TextValue: () => TextValue,
106
121
  TranslationConfig: () => TranslationConfig,
122
+ UnassignActionInput: () => UnassignActionInput,
107
123
  UrbanAddressUpdateValue: () => UrbanAddressUpdateValue,
108
124
  UrbanAddressValue: () => UrbanAddressValue,
109
125
  ValidateActionInput: () => ValidateActionInput,
110
- VerificationPage: () => VerificationPage,
126
+ VerificationActionConfig: () => VerificationActionConfig,
111
127
  VerificationPageConfig: () => VerificationPageConfig,
112
128
  WorkqueueConfig: () => WorkqueueConfig,
113
129
  alwaysTrue: () => alwaysTrue,
114
130
  and: () => and,
131
+ annotationActions: () => annotationActions,
115
132
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
116
133
  compositeFieldTypes: () => compositeFieldTypes,
117
134
  createEmptyDraft: () => createEmptyDraft,
118
135
  createValidationSchema: () => createValidationSchema,
119
136
  deepDropNulls: () => deepDropNulls,
137
+ deepMerge: () => deepMerge,
138
+ defineActionForm: () => defineActionForm,
120
139
  defineConditional: () => defineConditional,
121
140
  defineConfig: () => defineConfig,
122
- defineForm: () => defineForm,
141
+ defineDeclarationForm: () => defineDeclarationForm,
142
+ defineFormConditional: () => defineFormConditional,
123
143
  defineFormPage: () => defineFormPage,
144
+ definePage: () => definePage,
124
145
  errorMessages: () => errorMessages,
125
146
  event: () => event,
126
147
  eventMetadataLabelMap: () => eventMetadataLabelMap,
@@ -129,13 +150,9 @@ __export(events_exports, {
129
150
  eventStatuses: () => eventStatuses,
130
151
  field: () => field,
131
152
  fieldTypes: () => fieldTypes,
132
- findActiveActionFields: () => findActiveActionFields,
133
- findActiveActionForm: () => findActiveActionForm,
134
- findActiveActionFormFields: () => findActiveActionFormFields,
135
- findActiveActionFormPages: () => findActiveActionFormPages,
136
153
  findActiveDrafts: () => findActiveDrafts,
137
- findInputPageFields: () => findInputPageFields,
138
- findPageFields: () => findPageFields,
154
+ findAllFields: () => findAllFields,
155
+ findRecordActionPages: () => findRecordActionPages,
139
156
  generateActionDocument: () => generateActionDocument,
140
157
  generateActionInput: () => generateActionInput,
141
158
  generateActionMetadataInput: () => generateActionMetadataInput,
@@ -143,16 +160,19 @@ __export(events_exports, {
143
160
  generateEventDraftDocument: () => generateEventDraftDocument,
144
161
  generateTransactionId: () => generateTransactionId,
145
162
  generateTranslationConfig: () => generateTranslationConfig,
146
- getActiveActionFields: () => getActiveActionFields,
147
- getActiveActionFormPages: () => getActiveActionFormPages,
148
- getAllFields: () => getAllFields,
149
- getAllPages: () => getAllPages,
163
+ getAcceptedActions: () => getAcceptedActions,
164
+ getActionAnnotation: () => getActionAnnotation,
165
+ getActionAnnotationFields: () => getActionAnnotationFields,
166
+ getActionReview: () => getActionReview,
167
+ getActionReviewFields: () => getActionReviewFields,
168
+ getAllAnnotationFields: () => getAllAnnotationFields,
169
+ getAnnotationFromDrafts: () => getAnnotationFromDrafts,
150
170
  getCurrentEventState: () => getCurrentEventState,
151
171
  getCurrentEventStateWithDrafts: () => getCurrentEventStateWithDrafts,
152
- getEventConfiguration: () => getEventConfiguration,
172
+ getDeclaration: () => getDeclaration,
173
+ getDeclarationFields: () => getDeclarationFields,
174
+ getDeclarationPages: () => getDeclarationPages,
153
175
  getFieldValidationErrors: () => getFieldValidationErrors,
154
- getFormFields: () => getFormFields,
155
- getMetadataForAction: () => getMetadataForAction,
156
176
  getVisiblePagesFormFields: () => getVisiblePagesFormFields,
157
177
  isAddressFieldType: () => isAddressFieldType,
158
178
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
@@ -165,6 +185,7 @@ __export(events_exports, {
165
185
  isEmailFieldType: () => isEmailFieldType,
166
186
  isFacilityFieldType: () => isFacilityFieldType,
167
187
  isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
188
+ isFieldDisplayedOnReview: () => isFieldDisplayedOnReview,
168
189
  isFieldEnabled: () => isFieldEnabled,
169
190
  isFieldValue: () => isFieldValue,
170
191
  isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
@@ -188,9 +209,9 @@ __export(events_exports, {
188
209
  mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
189
210
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
190
211
  mapFieldTypeToZod: () => mapFieldTypeToZod,
212
+ never: () => never,
191
213
  not: () => not,
192
214
  or: () => or,
193
- resolveLabelsFromKnownFields: () => resolveLabelsFromKnownFields,
194
215
  stripHiddenFields: () => stripHiddenFields,
195
216
  user: () => user,
196
217
  validate: () => validate,
@@ -200,35 +221,52 @@ __export(events_exports, {
200
221
  module.exports = __toCommonJS(events_exports);
201
222
 
202
223
  // ../commons/src/events/ActionConfig.ts
203
- var import_zod7 = require("zod");
224
+ var import_zod9 = require("zod");
204
225
 
205
226
  // ../commons/src/events/Conditional.ts
206
227
  var import_zod = require("zod");
207
- function Conditional() {
208
- return import_zod.z.custom((val) => typeof val === "object" && val !== null);
209
- }
228
+ var Conditional = import_zod.z.custom(
229
+ (val) => typeof val === "object" && val !== null
230
+ );
210
231
  var ConditionalType = {
211
- /** When 'SHOW' conditional is defined, the action is shown to the user only if the condition is met */
212
232
  SHOW: "SHOW",
213
- /** If 'ENABLE' conditional is defined, the action is enabled only if the condition is met */
214
- ENABLE: "ENABLE"
233
+ ENABLE: "ENABLE",
234
+ DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
215
235
  };
216
236
  var ShowConditional = import_zod.z.object({
217
237
  type: import_zod.z.literal(ConditionalType.SHOW),
218
- conditional: Conditional()
219
- });
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
+ );
220
242
  var EnableConditional = import_zod.z.object({
221
243
  type: import_zod.z.literal(ConditionalType.ENABLE),
222
- conditional: Conditional()
223
- });
244
+ conditional: Conditional
245
+ }).describe(
246
+ "If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
247
+ );
224
248
  var ActionConditional = import_zod.z.discriminatedUnion("type", [
225
249
  // Action can be shown / hidden
226
250
  ShowConditional,
227
251
  // Action can be shown to the user in the list but as disabled
228
252
  EnableConditional
229
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
+ ]);
230
268
 
231
- // ../commons/src/events/FormConfig.ts
269
+ // ../commons/src/events/PageConfig.ts
232
270
  var import_zod6 = require("zod");
233
271
 
234
272
  // ../commons/src/events/FieldConfig.ts
@@ -414,14 +452,14 @@ var BaseField = import_zod5.z.object({
414
452
  ]),
415
453
  DependencyExpression
416
454
  ]).optional(),
417
- conditionals: import_zod5.z.array(ActionConditional).default([]).optional(),
455
+ conditionals: import_zod5.z.array(FieldConditional).default([]).optional(),
418
456
  required: import_zod5.z.boolean().default(false).optional(),
419
457
  disabled: import_zod5.z.boolean().default(false).optional(),
420
458
  hidden: import_zod5.z.boolean().default(false).optional(),
421
459
  placeholder: TranslationConfig.optional(),
422
460
  validation: import_zod5.z.array(
423
461
  import_zod5.z.object({
424
- validator: Conditional(),
462
+ validator: Conditional,
425
463
  message: TranslationConfig
426
464
  })
427
465
  ).default([]).optional(),
@@ -580,7 +618,7 @@ var AdministrativeAreas = import_zod5.z.enum([
580
618
  ]);
581
619
  var AdministrativeAreaConfiguration = import_zod5.z.object({
582
620
  partOf: import_zod5.z.object({
583
- $data: import_zod5.z.string()
621
+ $declaration: import_zod5.z.string()
584
622
  }).optional().describe("Parent location"),
585
623
  type: AdministrativeAreas
586
624
  }).describe("Administrative area options");
@@ -615,11 +653,20 @@ var Address = BaseField.extend({
615
653
  type: import_zod5.z.literal(FieldType.ADDRESS),
616
654
  defaultValue: AddressFieldValue.optional()
617
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
+ ]);
618
665
  var DataField = BaseField.extend({
619
666
  type: import_zod5.z.literal(FieldType.DATA),
620
667
  configuration: import_zod5.z.object({
621
668
  subtitle: TranslationConfig.optional(),
622
- data: import_zod5.z.array(import_zod5.z.object({ fieldId: import_zod5.z.string() }))
669
+ data: import_zod5.z.array(DataEntry)
623
670
  })
624
671
  }).describe("Data field for displaying read-only data");
625
672
  var FieldConfig = import_zod5.z.discriminatedUnion("type", [
@@ -645,23 +692,23 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
645
692
  EmailField,
646
693
  FileUploadWithOptions,
647
694
  DataField
695
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
648
696
  ]);
649
697
 
650
- // ../commons/src/events/FormConfig.ts
651
- var FormPageType = {
652
- FORM: "FORM",
653
- VERIFICATION: "VERIFICATION"
654
- };
655
- 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({
656
701
  id: import_zod6.z.string().describe("Unique identifier for the page"),
657
- type: import_zod6.z.literal(FormPageType.FORM).default(FormPageType.FORM),
658
702
  title: TranslationConfig.describe("Header title of the page"),
659
703
  fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page"),
660
- conditional: Conditional().optional().describe(
704
+ conditional: Conditional.optional().describe(
661
705
  "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
662
706
  )
663
707
  });
664
- 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({
665
712
  verify: import_zod6.z.object({ label: TranslationConfig }),
666
713
  cancel: import_zod6.z.object({
667
714
  label: TranslationConfig,
@@ -671,137 +718,176 @@ var VerificationPageConfig = import_zod6.z.object({
671
718
  })
672
719
  })
673
720
  }).describe("Actions available on the verification page");
674
- var VerificationPage = FormPage.extend({
675
- type: import_zod6.z.literal(FormPageType.VERIFICATION),
676
- actions: VerificationPageConfig
677
- });
678
- var FormPageConfig = import_zod6.z.preprocess(
679
- (pageConfig) => ({
680
- ...pageConfig,
681
- type: pageConfig.type ?? FormPageType.FORM
682
- // Default type to "FORM" if not provided
683
- }),
684
- import_zod6.z.discriminatedUnion("type", [FormPage, VerificationPage])
685
- );
686
- var FormConfig = import_zod6.z.object({
687
- label: TranslationConfig.describe("Human readable description of the form"),
688
- version: import_zod6.z.object({
689
- id: import_zod6.z.string().describe(
690
- "Form version. Semantic versioning recommended. Example: 0.0.1"
691
- ),
692
- label: TranslationConfig.describe(
693
- "Human readable description of the version"
694
- )
695
- }),
696
- active: import_zod6.z.boolean().default(false).describe("Whether the form is active"),
697
- pages: import_zod6.z.array(FormPageConfig),
698
- review: import_zod6.z.object({
699
- title: TranslationConfig.describe(
700
- "Title of the form to show in review page"
701
- ),
702
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the review page for metadata")
703
- })
721
+ var VerificationPageConfig = FormPageConfig.extend({
722
+ type: import_zod6.z.literal(PageTypes.enum.VERIFICATION),
723
+ actions: VerificationActionConfig
704
724
  });
725
+ var PageConfig = import_zod6.z.discriminatedUnion("type", [
726
+ FormPageConfig,
727
+ VerificationPageConfig
728
+ ]);
705
729
 
706
730
  // ../commons/src/events/ActionType.ts
731
+ var import_zod7 = require("zod");
707
732
  var ActionType = {
733
+ // Pre-declaration actions
734
+ DELETE: "DELETE",
708
735
  CREATE: "CREATE",
709
- ASSIGN: "ASSIGN",
710
- UNASSIGN: "UNASSIGN",
711
- REGISTER: "REGISTER",
712
- VALIDATE: "VALIDATE",
713
- REQUEST_CORRECTION: "REQUEST_CORRECTION",
714
- REJECT_CORRECTION: "REJECT_CORRECTION",
715
- APPROVE_CORRECTION: "APPROVE_CORRECTION",
716
- DETECT_DUPLICATE: "DETECT_DUPLICATE",
717
736
  NOTIFY: "NOTIFY",
737
+ // Declaration actions
718
738
  DECLARE: "DECLARE",
719
- DELETE: "DELETE",
720
- PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
721
- CUSTOM: "CUSTOM",
739
+ VALIDATE: "VALIDATE",
740
+ REGISTER: "REGISTER",
741
+ // Declaration system actions. Non-configurable.
742
+ DETECT_DUPLICATE: "DETECT_DUPLICATE",
722
743
  REJECT: "REJECT",
744
+ // REJECT_DECLARATION
723
745
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
746
+ // MARK_AS_DUPLICATE
724
747
  ARCHIVE: "ARCHIVE",
725
- READ: "READ"
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"
726
757
  };
727
- 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]);
728
812
 
729
813
  // ../commons/src/events/ActionConfig.ts
730
- var ActionConditional2 = import_zod7.z.discriminatedUnion("type", [
814
+ var ActionConditional2 = import_zod9.z.discriminatedUnion("type", [
731
815
  /** If conditional is defined, the action is shown to the user only if the condition is met */
732
816
  ShowConditional,
733
817
  /** If conditional is defined, the action is enabled only if the condition is met */
734
818
  EnableConditional
735
819
  ]);
736
- 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({
737
825
  label: TranslationConfig,
738
- conditionals: import_zod7.z.array(ActionConditional2).optional().default([]),
739
- draft: import_zod7.z.boolean().optional(),
740
- forms: import_zod7.z.array(FormConfig)
826
+ conditionals: import_zod9.z.array(ActionConditional2).optional().default([]),
827
+ draft: import_zod9.z.boolean().optional()
741
828
  });
742
829
  var DeclareConfig = ActionConfigBase.merge(
743
- import_zod7.z.object({
744
- type: import_zod7.z.literal(ActionType.DECLARE)
830
+ import_zod9.z.object({
831
+ type: import_zod9.z.literal(ActionType.DECLARE),
832
+ review: DeclarationReviewConfig
745
833
  })
746
834
  );
747
835
  var ValidateConfig = ActionConfigBase.merge(
748
- import_zod7.z.object({
749
- 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
750
845
  })
751
846
  );
752
847
  var RejectDeclarationConfig = ActionConfigBase.merge(
753
- import_zod7.z.object({
754
- type: import_zod7.z.literal(ActionType.REJECT)
848
+ import_zod9.z.object({
849
+ type: import_zod9.z.literal(ActionType.REJECT)
755
850
  })
756
851
  );
757
852
  var MarkedAsDuplicateConfig = ActionConfigBase.merge(
758
- import_zod7.z.object({
759
- type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE)
853
+ import_zod9.z.object({
854
+ type: import_zod9.z.literal(ActionType.MARKED_AS_DUPLICATE)
760
855
  })
761
856
  );
762
857
  var ArchiveConfig = ActionConfigBase.merge(
763
- import_zod7.z.object({
764
- type: import_zod7.z.literal(ActionType.ARCHIVE)
765
- })
766
- );
767
- var RegisterConfig = ActionConfigBase.merge(
768
- import_zod7.z.object({
769
- type: import_zod7.z.literal(ActionType.REGISTER)
858
+ import_zod9.z.object({
859
+ type: import_zod9.z.literal(ActionType.ARCHIVE)
770
860
  })
771
861
  );
772
862
  var DeleteConfig = ActionConfigBase.merge(
773
- import_zod7.z.object({
774
- type: import_zod7.z.literal(ActionType.DELETE)
863
+ import_zod9.z.object({
864
+ type: import_zod9.z.literal(ActionType.DELETE)
775
865
  })
776
866
  );
777
867
  var PrintCertificateActionConfig = ActionConfigBase.merge(
778
- import_zod7.z.object({
779
- 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
780
871
  })
781
872
  );
782
873
  var RequestCorrectionConfig = ActionConfigBase.merge(
783
- import_zod7.z.object({
784
- type: import_zod7.z.literal(ActionType.REQUEST_CORRECTION),
785
- onboardingForm: import_zod7.z.array(FormPageConfig),
786
- 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)
787
878
  })
788
879
  );
789
880
  var RejectCorrectionConfig = ActionConfigBase.merge(
790
- import_zod7.z.object({
791
- type: import_zod7.z.literal(ActionType.REJECT_CORRECTION)
881
+ import_zod9.z.object({
882
+ type: import_zod9.z.literal(ActionType.REJECT_CORRECTION)
792
883
  })
793
884
  );
794
885
  var ApproveCorrectionConfig = ActionConfigBase.merge(
795
- import_zod7.z.object({
796
- type: import_zod7.z.literal(ActionType.APPROVE_CORRECTION)
797
- })
798
- );
799
- var CustomConfig = ActionConfigBase.merge(
800
- import_zod7.z.object({
801
- type: import_zod7.z.literal(ActionType.CUSTOM)
886
+ import_zod9.z.object({
887
+ type: import_zod9.z.literal(ActionType.APPROVE_CORRECTION)
802
888
  })
803
889
  );
804
- var ActionConfig = import_zod7.z.discriminatedUnion("type", [
890
+ var ActionConfig = import_zod9.z.discriminatedUnion("type", [
805
891
  DeclareConfig,
806
892
  ValidateConfig,
807
893
  RejectDeclarationConfig,
@@ -812,102 +898,108 @@ var ActionConfig = import_zod7.z.discriminatedUnion("type", [
812
898
  PrintCertificateActionConfig,
813
899
  RequestCorrectionConfig,
814
900
  RejectCorrectionConfig,
815
- ApproveCorrectionConfig,
816
- CustomConfig
901
+ ApproveCorrectionConfig
902
+ ]);
903
+ var DeclarationActionConfig = import_zod9.z.discriminatedUnion("type", [
904
+ DeclareConfig,
905
+ ValidateConfig,
906
+ RegisterConfig
817
907
  ]);
818
908
 
819
909
  // ../commons/src/events/offline/CertificateConfig.ts
820
- var import_zod8 = require("zod");
821
- var FontFamily = import_zod8.z.object({
822
- normal: import_zod8.z.string(),
823
- bold: import_zod8.z.string(),
824
- italics: import_zod8.z.string(),
825
- 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()
826
916
  });
827
- var CertificateConfig = import_zod8.z.object({
828
- id: import_zod8.z.string(),
829
- event: import_zod8.z.string(),
917
+ var CertificateConfig = import_zod10.z.object({
918
+ id: import_zod10.z.string(),
919
+ event: import_zod10.z.string(),
830
920
  label: TranslationConfig,
831
- isDefault: import_zod8.z.boolean(),
832
- fee: import_zod8.z.object({
833
- onTime: import_zod8.z.number(),
834
- late: import_zod8.z.number(),
835
- 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()
836
926
  }),
837
- svgUrl: import_zod8.z.string(),
838
- fonts: import_zod8.z.record(FontFamily).optional()
927
+ svgUrl: import_zod10.z.string(),
928
+ fonts: import_zod10.z.record(FontFamily).optional()
839
929
  });
840
930
  var CertificateTemplateConfig = CertificateConfig.extend({
841
- hash: import_zod8.z.string().optional(),
842
- svg: import_zod8.z.string()
931
+ hash: import_zod10.z.string().optional(),
932
+ svg: import_zod10.z.string()
843
933
  });
844
934
 
845
935
  // ../commons/src/events/offline/LanguageConfig.ts
846
- var import_zod9 = require("zod");
847
- var LanguageConfig = import_zod9.z.object({
848
- lang: import_zod9.z.string(),
936
+ var import_zod11 = require("zod");
937
+ var LanguageConfig = import_zod11.z.object({
938
+ lang: import_zod11.z.string(),
849
939
  /**
850
940
  * client.csv contents
851
941
  */
852
- messages: import_zod9.z.record(import_zod9.z.string())
942
+ messages: import_zod11.z.record(import_zod11.z.string())
853
943
  });
854
944
 
855
945
  // ../commons/src/events/EventConfig.ts
856
- var import_zod18 = require("zod");
946
+ var import_zod20 = require("zod");
857
947
 
858
948
  // ../commons/src/events/DeduplicationConfig.ts
859
- var import_zod10 = require("zod");
860
- var FieldReference = import_zod10.z.string();
861
- var Matcher = import_zod10.z.object({
862
- fieldId: import_zod10.z.string(),
863
- options: import_zod10.z.object({
864
- 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()
865
955
  }).optional().default({})
866
956
  });
867
957
  var FuzzyMatcher = Matcher.extend({
868
- type: import_zod10.z.literal("fuzzy"),
869
- options: import_zod10.z.object({
958
+ type: import_zod12.z.literal("fuzzy"),
959
+ options: import_zod12.z.object({
870
960
  /**
871
961
  * Names of length 3 or less characters = 0 edits allowed
872
962
  * Names of length 4 - 6 characters = 1 edit allowed
873
963
  * Names of length >7 characters = 2 edits allowed
874
964
  */
875
- fuzziness: import_zod10.z.union([import_zod10.z.string(), import_zod10.z.number()]).optional().default("AUTO:4,7"),
876
- 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)
877
967
  }).optional().default({})
878
968
  });
879
969
  var StrictMatcher = Matcher.extend({
880
- type: import_zod10.z.literal("strict"),
881
- options: import_zod10.z.object({
882
- 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)
883
973
  }).optional().default({})
884
974
  });
885
975
  var DateRangeMatcher = Matcher.extend({
886
- type: import_zod10.z.literal("dateRange"),
887
- options: import_zod10.z.object({
888
- days: import_zod10.z.number(),
976
+ type: import_zod12.z.literal("dateRange"),
977
+ options: import_zod12.z.object({
978
+ days: import_zod12.z.number(),
889
979
  origin: FieldReference,
890
- boost: import_zod10.z.number().optional().default(1)
980
+ boost: import_zod12.z.number().optional().default(1)
891
981
  })
892
982
  });
893
983
  var DateDistanceMatcher = Matcher.extend({
894
- type: import_zod10.z.literal("dateDistance"),
895
- options: import_zod10.z.object({
896
- days: import_zod10.z.number(),
984
+ type: import_zod12.z.literal("dateDistance"),
985
+ options: import_zod12.z.object({
986
+ days: import_zod12.z.number(),
897
987
  origin: FieldReference,
898
- boost: import_zod10.z.number().optional().default(1)
988
+ boost: import_zod12.z.number().optional().default(1)
899
989
  })
900
990
  });
901
- var And = import_zod10.z.object({
902
- type: import_zod10.z.literal("and"),
903
- 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())
904
995
  });
905
- var Or = import_zod10.z.object({
906
- type: import_zod10.z.literal("or"),
907
- 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())
908
1000
  });
909
- var Clause = import_zod10.z.lazy(
910
- () => import_zod10.z.discriminatedUnion("type", [
1001
+ var Clause = import_zod12.z.lazy(
1002
+ () => import_zod12.z.discriminatedUnion("type", [
911
1003
  And,
912
1004
  Or,
913
1005
  FuzzyMatcher,
@@ -916,37 +1008,37 @@ var Clause = import_zod10.z.lazy(
916
1008
  DateDistanceMatcher
917
1009
  ])
918
1010
  );
919
- var DeduplicationConfig = import_zod10.z.object({
920
- id: import_zod10.z.string(),
1011
+ var DeduplicationConfig = import_zod12.z.object({
1012
+ id: import_zod12.z.string(),
921
1013
  label: TranslationConfig,
922
1014
  query: Clause
923
1015
  });
924
1016
 
925
1017
  // ../commons/src/events/SummaryConfig.ts
926
- var import_zod11 = require("zod");
927
- var Field = import_zod11.z.object({
928
- 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"),
929
1021
  value: TranslationConfig.describe(
930
1022
  "Summary field value. Can utilise values defined in configuration and EventMetadata"
931
1023
  ),
932
1024
  label: TranslationConfig,
933
1025
  emptyValueMessage: TranslationConfig.optional()
934
1026
  });
935
- var Title = import_zod11.z.object({
936
- id: import_zod11.z.string(),
1027
+ var Title = import_zod13.z.object({
1028
+ id: import_zod13.z.string(),
937
1029
  label: TranslationConfig.describe("Title content"),
938
1030
  emptyValueMessage: TranslationConfig.optional()
939
1031
  });
940
- var SummaryConfig = import_zod11.z.object({
1032
+ var SummaryConfig = import_zod13.z.object({
941
1033
  title: Title.describe("Title of summary view."),
942
- 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.")
943
1035
  }).describe("Configuration for summary in event.");
944
1036
 
945
1037
  // ../commons/src/events/WorkqueueConfig.ts
946
- var import_zod13 = require("zod");
1038
+ var import_zod15 = require("zod");
947
1039
 
948
1040
  // ../commons/src/events/EventMetadata.ts
949
- var import_zod12 = require("zod");
1041
+ var import_zod14 = require("zod");
950
1042
  var EventStatus = {
951
1043
  CREATED: "CREATED",
952
1044
  NOTIFIED: "NOTIFIED",
@@ -958,18 +1050,19 @@ var EventStatus = {
958
1050
  ARCHIVED: "ARCHIVED"
959
1051
  };
960
1052
  var eventStatuses = Object.values(EventStatus);
961
- var EventStatuses = import_zod12.z.nativeEnum(EventStatus);
962
- var EventMetadata = import_zod12.z.object({
963
- id: import_zod12.z.string(),
964
- 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(),
965
1057
  status: EventStatuses,
966
- createdAt: import_zod12.z.string().datetime(),
967
- createdBy: import_zod12.z.string(),
968
- createdAtLocation: import_zod12.z.string(),
969
- modifiedAt: import_zod12.z.string().datetime(),
970
- assignedTo: import_zod12.z.string().nullish(),
971
- updatedBy: import_zod12.z.string(),
972
- 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()
973
1066
  });
974
1067
  var eventMetadataLabelMap = {
975
1068
  "event.assignedTo": {
@@ -1021,28 +1114,33 @@ var eventMetadataLabelMap = {
1021
1114
  id: "event.trackingId.label",
1022
1115
  defaultMessage: "Tracking ID",
1023
1116
  description: "Tracking ID"
1117
+ },
1118
+ "event.registrationNumber": {
1119
+ id: "event.registrationNumber.label",
1120
+ defaultMessage: "Registration Number",
1121
+ description: "Registration Number"
1024
1122
  }
1025
1123
  };
1026
1124
 
1027
1125
  // ../commons/src/events/WorkqueueConfig.ts
1028
- var WorkqueueConfig = import_zod13.z.object({
1029
- id: import_zod13.z.string().describe("Unique identifier for workqueue."),
1030
- filters: import_zod13.z.array(
1031
- import_zod13.z.object({
1032
- 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.")
1033
1131
  })
1034
1132
  ).describe("Filters to be applied to workqueue.")
1035
1133
  }).describe("Configuration for workqueue.");
1036
1134
 
1037
1135
  // ../commons/src/events/AdvancedSearchConfig.ts
1038
- var import_zod14 = require("zod");
1039
- var AdvancedSearchConfig = import_zod14.z.object({
1136
+ var import_zod16 = require("zod");
1137
+ var AdvancedSearchConfig = import_zod16.z.object({
1040
1138
  title: TranslationConfig.describe("Advanced search tab title"),
1041
- fields: import_zod14.z.array(
1042
- import_zod14.z.object({
1043
- fieldId: import_zod14.z.string(),
1044
- config: import_zod14.z.object({
1045
- 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")
1046
1144
  }).optional().describe("Configuration options for the field")
1047
1145
  })
1048
1146
  ).optional().default([]).describe("Advanced search fields.")
@@ -1052,12 +1150,12 @@ var AdvancedSearchConfig = import_zod14.z.object({
1052
1150
  var import_lodash = require("lodash");
1053
1151
 
1054
1152
  // ../commons/src/workqueues/WorkqueueConfig.ts
1055
- var import_zod16 = require("zod");
1153
+ var import_zod18 = require("zod");
1056
1154
 
1057
1155
  // ../commons/src/workqueues/defaultColumns.ts
1058
- var import_zod15 = require("zod");
1059
- var WorkQueueColumnConfig = import_zod15.z.object({
1060
- id: import_zod15.z.string(),
1156
+ var import_zod17 = require("zod");
1157
+ var WorkQueueColumnConfig = import_zod17.z.object({
1158
+ id: import_zod17.z.string(),
1061
1159
  label: TranslationConfig
1062
1160
  });
1063
1161
  var defaultColumns = {
@@ -1094,16 +1192,16 @@ var defaultColumns = {
1094
1192
  }
1095
1193
  }
1096
1194
  };
1097
- var DefaultColumnKeys = import_zod15.z.enum(
1195
+ var DefaultColumnKeys = import_zod17.z.enum(
1098
1196
  Object.keys(defaultColumns)
1099
1197
  );
1100
1198
 
1101
1199
  // ../commons/src/workqueues/WorkqueueConfig.ts
1102
- var rootWorkqueueConfig = import_zod16.z.object({
1103
- id: import_zod16.z.string(),
1200
+ var rootWorkqueueConfig = import_zod18.z.object({
1201
+ id: import_zod18.z.string(),
1104
1202
  title: TranslationConfig,
1105
- columns: import_zod16.z.array(WorkQueueColumnConfig),
1106
- defaultColumns: import_zod16.z.array(DefaultColumnKeys)
1203
+ columns: import_zod18.z.array(WorkQueueColumnConfig),
1204
+ defaultColumns: import_zod18.z.array(DefaultColumnKeys)
1107
1205
  });
1108
1206
  var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
1109
1207
 
@@ -1183,7 +1281,7 @@ var import_ajv_formats = __toESM(require("ajv-formats"));
1183
1281
  var import_date_fns = require("date-fns");
1184
1282
 
1185
1283
  // ../commons/src/events/FieldTypeMapping.ts
1186
- var import_zod17 = require("zod");
1284
+ var import_zod19 = require("zod");
1187
1285
  function mapFieldTypeToZod(type, required) {
1188
1286
  let schema;
1189
1287
  switch (type) {
@@ -1236,7 +1334,7 @@ function createValidationSchema(config) {
1236
1334
  for (const field2 of config) {
1237
1335
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1238
1336
  }
1239
- return import_zod17.z.object(shape);
1337
+ return import_zod19.z.object(shape);
1240
1338
  }
1241
1339
  function mapFieldTypeToMockValue(field2, i) {
1242
1340
  switch (field2.type) {
@@ -1403,7 +1501,8 @@ var isDataFieldType = (field2) => {
1403
1501
 
1404
1502
  // ../commons/src/conditionals/validate.ts
1405
1503
  var ajv = new import_ajv.default({
1406
- $data: true
1504
+ $data: true,
1505
+ allowUnionTypes: true
1407
1506
  });
1408
1507
  (0, import_ajv_formats.default)(ajv);
1409
1508
  function validate(schema, data) {
@@ -1436,6 +1535,9 @@ function isFieldVisible(field2, form) {
1436
1535
  function isFieldEnabled(field2, form) {
1437
1536
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1438
1537
  }
1538
+ function isFieldDisplayedOnReview(field2, form) {
1539
+ return isFieldVisible(field2, form) && isFieldConditionMet(field2, form, ConditionalType.DISPLAY_ON_REVIEW);
1540
+ }
1439
1541
  var errorMessages = {
1440
1542
  hiddenField: {
1441
1543
  id: "v2.error.hidden",
@@ -1463,12 +1565,14 @@ var errorMessages = {
1463
1565
  id: "v2.error.invalid"
1464
1566
  }
1465
1567
  };
1466
- var createIntlError = (message) => ({
1467
- message: {
1468
- message
1469
- }
1470
- });
1471
- var zodToIntlErrorMap = (issue, _ctx) => {
1568
+ function createIntlError(message) {
1569
+ return {
1570
+ message: {
1571
+ message
1572
+ }
1573
+ };
1574
+ }
1575
+ function zodToIntlErrorMap(issue, _ctx) {
1472
1576
  switch (issue.code) {
1473
1577
  case "invalid_string": {
1474
1578
  if (_ctx.data === "") {
@@ -1506,7 +1610,28 @@ var zodToIntlErrorMap = (issue, _ctx) => {
1506
1610
  }
1507
1611
  }
1508
1612
  return createIntlError(errorMessages.invalidInput);
1509
- };
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
+ }
1510
1635
  function getFieldValidationErrors({
1511
1636
  field: field2,
1512
1637
  values
@@ -1542,28 +1667,16 @@ function getFieldValidationErrors({
1542
1667
  errors: [...fieldValidationResult, ...customValidationResults]
1543
1668
  };
1544
1669
  }
1545
- function runCustomFieldValidations({
1546
- field: field2,
1547
- conditionalParameters
1548
- }) {
1549
- return (field2.validation ?? []).filter((validation) => {
1550
- return !validate(validation.validator, conditionalParameters);
1551
- }).map((validation) => ({ message: validation.message }));
1552
- }
1553
- function validateFieldInput({
1554
- field: field2,
1555
- value
1556
- }) {
1557
- const rawError = mapFieldTypeToZod(field2.type, field2.required).safeParse(
1558
- value,
1559
- {
1560
- // @ts-expect-error
1561
- errorMap: zodToIntlErrorMap
1562
- }
1563
- );
1564
- return rawError.error?.issues.map((issue) => issue.message) ?? [];
1670
+
1671
+ // ../commons/src/uuid.ts
1672
+ var import_uuid = require("uuid");
1673
+ function getUUID() {
1674
+ return (0, import_uuid.v4)();
1565
1675
  }
1566
1676
 
1677
+ // ../commons/src/events/utils.ts
1678
+ var import_date_fns2 = require("date-fns");
1679
+
1567
1680
  // ../commons/src/utils.ts
1568
1681
  function getOrThrow(x, message) {
1569
1682
  if (x === void 0 || x === null) {
@@ -1572,74 +1685,64 @@ function getOrThrow(x, message) {
1572
1685
  return x;
1573
1686
  }
1574
1687
 
1575
- // ../commons/src/uuid.ts
1576
- var import_uuid = require("uuid");
1577
- function getUUID() {
1578
- return (0, import_uuid.v4)();
1579
- }
1580
-
1581
1688
  // ../commons/src/events/utils.ts
1582
- var import_date_fns2 = require("date-fns");
1583
- function isMetadataField(field2) {
1584
- return field2 in eventMetadataLabelMap;
1585
- }
1586
- var findInputPageFields = (config) => {
1587
- return (0, import_lodash.flattenDeep)(
1588
- config.actions.map(
1589
- ({ forms }) => forms.map(
1590
- ({ pages }) => pages.map(
1591
- ({ fields }) => fields.map(({ id, label }) => ({ id, label }))
1592
- )
1593
- )
1594
- )
1595
- );
1596
- };
1597
- var findPageFields = (config) => {
1598
- return (0, import_lodash.flattenDeep)(
1599
- config.actions.map((action) => {
1600
- if (action.type === ActionType.REQUEST_CORRECTION) {
1601
- return [
1602
- ...action.forms.map(({ pages }) => pages.map(({ fields }) => fields)),
1603
- ...action.onboardingForm.flatMap(({ fields }) => fields),
1604
- ...action.additionalDetailsForm.flatMap(({ fields }) => fields)
1605
- ];
1606
- }
1607
- return action.forms.map(({ pages }) => pages.map(({ fields }) => fields));
1608
- })
1609
- );
1689
+ function isDeclarationActionConfig(action) {
1690
+ return DeclarationActions.safeParse(action.type).success;
1691
+ }
1692
+ function getDeclarationFields(configuration) {
1693
+ return configuration.declaration.pages.flatMap(({ fields }) => fields);
1694
+ }
1695
+ function getDeclarationPages(configuration) {
1696
+ return configuration.declaration.pages;
1697
+ }
1698
+ function getDeclaration(configuration) {
1699
+ return configuration.declaration;
1700
+ }
1701
+ var getActionAnnotationFields = (actionConfig) => {
1702
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1703
+ return [
1704
+ ...actionConfig.onboardingForm.flatMap(({ fields }) => fields),
1705
+ ...actionConfig.additionalDetailsForm.flatMap(({ fields }) => fields)
1706
+ ];
1707
+ }
1708
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1709
+ return actionConfig.printForm.pages.flatMap(({ fields }) => fields);
1710
+ }
1711
+ if (isDeclarationActionConfig(actionConfig)) {
1712
+ return actionConfig.review.fields;
1713
+ }
1714
+ return [];
1610
1715
  };
1611
- var resolveLabelsFromKnownFields = ({
1612
- pageFields,
1613
- refFields
1614
- }) => {
1615
- return refFields.map((field2) => {
1616
- if (field2.label) {
1617
- return field2;
1618
- }
1619
- if (isMetadataField(field2.id)) {
1620
- return {
1621
- ...field2,
1622
- label: eventMetadataLabelMap[field2.id]
1623
- };
1624
- }
1625
- const pageLabel = pageFields.find((pageField) => pageField.id === field2.id);
1626
- if (!pageLabel) {
1627
- throw new Error(`Referenced field ${field2.id} does not have a label`);
1628
- }
1629
- return {
1630
- ...field2,
1631
- label: pageLabel.label
1632
- };
1633
- });
1716
+ var getAllAnnotationFields = (config) => {
1717
+ return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1634
1718
  };
1635
- function getAllFields(configuration) {
1636
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => [
1637
- ...form.review.fields,
1638
- ...form.pages.flatMap((page) => page.fields)
1719
+ var findAllFields = (config) => {
1720
+ return (0, import_lodash.flattenDeep)([
1721
+ ...getDeclarationFields(config),
1722
+ ...getAllAnnotationFields(config)
1639
1723
  ]);
1724
+ };
1725
+ var findRecordActionPages = (config, actionType) => {
1726
+ const action = config.actions.find((a) => a.type === actionType);
1727
+ if (action?.type === ActionType.REQUEST_CORRECTION) {
1728
+ return [...action.onboardingForm, ...action.additionalDetailsForm];
1729
+ }
1730
+ if (action?.type === ActionType.PRINT_CERTIFICATE) {
1731
+ return action.printForm.pages;
1732
+ }
1733
+ return [];
1734
+ };
1735
+ function getActionReview(configuration, actionType) {
1736
+ const [actionConfig] = configuration.actions.filter(
1737
+ (a) => a.type === actionType
1738
+ );
1739
+ return getOrThrow(
1740
+ actionConfig.review,
1741
+ `No review config found for ${actionType}`
1742
+ );
1640
1743
  }
1641
- function getAllPages(configuration) {
1642
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => form.pages);
1744
+ function getActionReviewFields(configuration, actionType) {
1745
+ return getActionReview(configuration, actionType).fields;
1643
1746
  }
1644
1747
  function validateWorkqueueConfig(workqueueConfigs) {
1645
1748
  workqueueConfigs.map((workqueue) => {
@@ -1653,17 +1756,6 @@ function validateWorkqueueConfig(workqueueConfigs) {
1653
1756
  }
1654
1757
  });
1655
1758
  }
1656
- var findActiveActionForm = (configuration, action) => {
1657
- const actionConfig = configuration.actions.find((a) => a.type === action);
1658
- const form = actionConfig?.forms.find((f) => f.active);
1659
- return form;
1660
- };
1661
- var findActiveActionFormPages = (configuration, action) => {
1662
- return findActiveActionForm(configuration, action)?.pages;
1663
- };
1664
- var getFormFields = (formConfig) => {
1665
- return formConfig.pages.flatMap((p) => p.fields);
1666
- };
1667
1759
  function isPageVisible(page, formValues) {
1668
1760
  if (!page.conditional) {
1669
1761
  return true;
@@ -1676,59 +1768,22 @@ function isPageVisible(page, formValues) {
1676
1768
  var getVisiblePagesFormFields = (formConfig, formData) => {
1677
1769
  return formConfig.pages.filter((p) => isPageVisible(p, formData)).flatMap((p) => p.fields);
1678
1770
  };
1679
- var findActiveActionFormFields = (configuration, action) => {
1680
- const form = findActiveActionForm(configuration, action);
1681
- return form ? getFormFields(form) : void 0;
1682
- };
1683
- var findActiveActionFields = (configuration, action, formData) => {
1684
- const form = findActiveActionForm(configuration, action);
1685
- const reviewFields = form?.review.fields;
1686
- let formFields = void 0;
1687
- if (form) {
1688
- formFields = formData ? getVisiblePagesFormFields(form, formData) : getFormFields(form);
1689
- }
1690
- const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1691
- return allFields;
1692
- };
1693
- var getActiveActionFormPages = (configuration, action) => {
1694
- return getOrThrow(
1695
- findActiveActionForm(configuration, action)?.pages,
1696
- "Form configuration not found for type: " + configuration.id
1697
- );
1698
- };
1699
- function getActiveActionFields(configuration, action) {
1700
- if (LatentActions.some((latentAction) => latentAction === action)) {
1701
- return getActiveActionFields(configuration, ActionType.DECLARE);
1702
- }
1703
- const fields = findActiveActionFields(configuration, action);
1704
- if (!fields) {
1705
- throw new Error(`No active field config found for action type ${action}`);
1706
- }
1707
- return fields;
1708
- }
1709
- function getEventConfiguration(eventConfigurations, type) {
1710
- const config = eventConfigurations.find((config2) => config2.id === type);
1711
- if (!config) {
1712
- throw new Error(`Event configuration not found for type: ${type}`);
1713
- }
1714
- return config;
1715
- }
1716
1771
  function isOptionalUncheckedCheckbox(field2, form) {
1717
1772
  if (field2.type !== FieldType.CHECKBOX || field2.required) {
1718
1773
  return false;
1719
1774
  }
1720
1775
  return !form[field2.id];
1721
1776
  }
1722
- function stripHiddenFields(fields, data) {
1723
- return (0, import_lodash.omitBy)(data, (_2, fieldId) => {
1777
+ function stripHiddenFields(fields, declaration) {
1778
+ return (0, import_lodash.omitBy)(declaration, (_, fieldId) => {
1724
1779
  const field2 = fields.find((f) => f.id === fieldId);
1725
1780
  if (!field2) {
1726
1781
  return true;
1727
1782
  }
1728
- if (isOptionalUncheckedCheckbox(field2, data)) {
1783
+ if (isOptionalUncheckedCheckbox(field2, declaration)) {
1729
1784
  return true;
1730
1785
  }
1731
- return !isFieldVisible(field2, data);
1786
+ return !isFieldVisible(field2, declaration);
1732
1787
  });
1733
1788
  }
1734
1789
  function findActiveDrafts(event2, drafts) {
@@ -1744,8 +1799,8 @@ function createEmptyDraft(eventId, draftId, actionType) {
1744
1799
  transactionId: getUUID(),
1745
1800
  action: {
1746
1801
  type: actionType,
1747
- data: {},
1748
- metadata: {},
1802
+ declaration: {},
1803
+ annotation: {},
1749
1804
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1750
1805
  createdBy: "@todo",
1751
1806
  createdAtLocation: "@todo"
@@ -1753,22 +1808,41 @@ function createEmptyDraft(eventId, draftId, actionType) {
1753
1808
  };
1754
1809
  }
1755
1810
  function isVerificationPage(page) {
1756
- return page.type === FormPageType.VERIFICATION;
1811
+ return page.type === PageTypes.enum.VERIFICATION;
1812
+ }
1813
+ function deepMerge(currentDocument, actionDocument) {
1814
+ return (0, import_lodash.mergeWith)(
1815
+ currentDocument,
1816
+ actionDocument,
1817
+ (previousValue, incomingValue) => {
1818
+ if (incomingValue === void 0) {
1819
+ return previousValue;
1820
+ }
1821
+ if ((0, import_lodash.isArray)(incomingValue)) {
1822
+ return incomingValue;
1823
+ }
1824
+ if ((0, import_lodash.isObject)(previousValue) && (0, import_lodash.isObject)(incomingValue)) {
1825
+ return void 0;
1826
+ }
1827
+ return incomingValue;
1828
+ }
1829
+ );
1757
1830
  }
1758
1831
 
1759
1832
  // ../commons/src/events/EventConfig.ts
1760
- var EventConfig = import_zod18.z.object({
1761
- id: import_zod18.z.string().describe(
1833
+ var EventConfig = import_zod20.z.object({
1834
+ id: import_zod20.z.string().describe(
1762
1835
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1763
1836
  ),
1764
1837
  summary: SummaryConfig,
1765
1838
  label: TranslationConfig,
1766
- actions: import_zod18.z.array(ActionConfig),
1767
- workqueues: import_zod18.z.array(WorkqueueConfig),
1768
- deduplication: import_zod18.z.array(DeduplicationConfig).optional().default([]),
1769
- advancedSearch: import_zod18.z.array(AdvancedSearchConfig).optional().default([])
1839
+ actions: import_zod20.z.array(ActionConfig),
1840
+ declaration: DeclarationFormConfig,
1841
+ workqueues: import_zod20.z.array(WorkqueueConfig),
1842
+ deduplication: import_zod20.z.array(DeduplicationConfig).optional().default([]),
1843
+ advancedSearch: import_zod20.z.array(AdvancedSearchConfig).optional().default([])
1770
1844
  }).superRefine((event2, ctx) => {
1771
- const allFields = findPageFields(event2);
1845
+ const allFields = findAllFields(event2);
1772
1846
  const fieldIds = allFields.map((field2) => field2.id);
1773
1847
  const advancedSearchFields = event2.advancedSearch.flatMap(
1774
1848
  (section) => section.fields.flatMap((field2) => field2.fieldId)
@@ -1795,111 +1869,117 @@ var EventConfig = import_zod18.z.object({
1795
1869
  });
1796
1870
 
1797
1871
  // ../commons/src/events/EventConfigInput.ts
1798
- var defineForm = (form) => FormConfig.parse(form);
1872
+ var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
1873
+ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1874
+ var definePage = (page) => PageConfig.parse(page);
1799
1875
  var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1800
1876
 
1801
1877
  // ../commons/src/events/Draft.ts
1802
- var import_zod21 = require("zod");
1878
+ var import_zod23 = require("zod");
1803
1879
 
1804
1880
  // ../commons/src/events/ActionDocument.ts
1805
- var import_zod19 = require("zod");
1806
- var ActionUpdate = import_zod19.z.record(import_zod19.z.string(), FieldUpdateValue);
1807
- var ActionBase = import_zod19.z.object({
1808
- id: import_zod19.z.string(),
1809
- createdAt: import_zod19.z.string().datetime(),
1810
- createdBy: import_zod19.z.string(),
1811
- data: ActionUpdate,
1812
- metadata: ActionUpdate.optional(),
1813
- createdAtLocation: import_zod19.z.string()
1881
+ var import_zod21 = require("zod");
1882
+ var ActionUpdate = import_zod21.z.record(import_zod21.z.string(), FieldUpdateValue);
1883
+ var ActionStatus = {
1884
+ Requested: "Requested",
1885
+ Accepted: "Accepted",
1886
+ Rejected: "Rejected"
1887
+ };
1888
+ var ActionBase = import_zod21.z.object({
1889
+ id: import_zod21.z.string(),
1890
+ createdAt: import_zod21.z.string().datetime(),
1891
+ createdBy: import_zod21.z.string(),
1892
+ declaration: ActionUpdate,
1893
+ annotation: ActionUpdate.optional(),
1894
+ createdAtLocation: import_zod21.z.string(),
1895
+ status: import_zod21.z.enum([
1896
+ ActionStatus.Requested,
1897
+ ActionStatus.Accepted,
1898
+ ActionStatus.Rejected
1899
+ ]),
1900
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1901
+ originalActionId: import_zod21.z.string().optional()
1814
1902
  });
1815
1903
  var AssignedAction = ActionBase.merge(
1816
- import_zod19.z.object({
1817
- type: import_zod19.z.literal(ActionType.ASSIGN),
1818
- assignedTo: import_zod19.z.string()
1904
+ import_zod21.z.object({
1905
+ type: import_zod21.z.literal(ActionType.ASSIGN),
1906
+ assignedTo: import_zod21.z.string()
1819
1907
  })
1820
1908
  );
1821
1909
  var UnassignedAction = ActionBase.merge(
1822
- import_zod19.z.object({
1823
- type: import_zod19.z.literal(ActionType.UNASSIGN)
1910
+ import_zod21.z.object({
1911
+ type: import_zod21.z.literal(ActionType.UNASSIGN)
1824
1912
  })
1825
1913
  );
1826
1914
  var RegisterAction = ActionBase.merge(
1827
- import_zod19.z.object({
1828
- type: import_zod19.z.literal(ActionType.REGISTER),
1829
- identifiers: import_zod19.z.object({
1830
- trackingId: import_zod19.z.string(),
1831
- registrationNumber: import_zod19.z.string()
1832
- })
1915
+ import_zod21.z.object({
1916
+ type: import_zod21.z.literal(ActionType.REGISTER),
1917
+ registrationNumber: import_zod21.z.string().optional()
1833
1918
  })
1834
1919
  );
1835
1920
  var DeclareAction = ActionBase.merge(
1836
- import_zod19.z.object({
1837
- type: import_zod19.z.literal(ActionType.DECLARE)
1921
+ import_zod21.z.object({
1922
+ type: import_zod21.z.literal(ActionType.DECLARE)
1838
1923
  })
1839
1924
  );
1840
1925
  var ValidateAction = ActionBase.merge(
1841
- import_zod19.z.object({
1842
- type: import_zod19.z.literal(ActionType.VALIDATE)
1926
+ import_zod21.z.object({
1927
+ type: import_zod21.z.literal(ActionType.VALIDATE)
1843
1928
  })
1844
1929
  );
1845
1930
  var RejectAction = ActionBase.merge(
1846
- import_zod19.z.object({
1847
- type: import_zod19.z.literal(ActionType.REJECT)
1931
+ import_zod21.z.object({
1932
+ type: import_zod21.z.literal(ActionType.REJECT)
1848
1933
  })
1849
1934
  );
1850
1935
  var MarkAsDuplicateAction = ActionBase.merge(
1851
- import_zod19.z.object({
1852
- type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1936
+ import_zod21.z.object({
1937
+ type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE)
1853
1938
  })
1854
1939
  );
1855
1940
  var ArchiveAction = ActionBase.merge(
1856
- import_zod19.z.object({
1857
- type: import_zod19.z.literal(ActionType.ARCHIVE)
1941
+ import_zod21.z.object({
1942
+ type: import_zod21.z.literal(ActionType.ARCHIVE)
1858
1943
  })
1859
1944
  );
1860
1945
  var CreatedAction = ActionBase.merge(
1861
- import_zod19.z.object({
1862
- type: import_zod19.z.literal(ActionType.CREATE)
1946
+ import_zod21.z.object({
1947
+ type: import_zod21.z.literal(ActionType.CREATE)
1863
1948
  })
1864
1949
  );
1865
1950
  var NotifiedAction = ActionBase.merge(
1866
- import_zod19.z.object({
1867
- type: import_zod19.z.literal(ActionType.NOTIFY)
1951
+ import_zod21.z.object({
1952
+ type: import_zod21.z.literal(ActionType.NOTIFY)
1868
1953
  })
1869
1954
  );
1870
1955
  var PrintCertificateAction = ActionBase.merge(
1871
- import_zod19.z.object({
1872
- type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE)
1956
+ import_zod21.z.object({
1957
+ type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE)
1873
1958
  })
1874
1959
  );
1875
1960
  var RequestedCorrectionAction = ActionBase.merge(
1876
- import_zod19.z.object({
1877
- type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION)
1961
+ import_zod21.z.object({
1962
+ type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION)
1878
1963
  })
1879
1964
  );
1880
1965
  var ApprovedCorrectionAction = ActionBase.merge(
1881
- import_zod19.z.object({
1882
- type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION),
1883
- requestId: import_zod19.z.string()
1966
+ import_zod21.z.object({
1967
+ type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION),
1968
+ requestId: import_zod21.z.string()
1884
1969
  })
1885
1970
  );
1886
1971
  var RejectedCorrectionAction = ActionBase.merge(
1887
- import_zod19.z.object({
1888
- type: import_zod19.z.literal(ActionType.REJECT_CORRECTION),
1889
- requestId: import_zod19.z.string()
1972
+ import_zod21.z.object({
1973
+ type: import_zod21.z.literal(ActionType.REJECT_CORRECTION),
1974
+ requestId: import_zod21.z.string()
1890
1975
  })
1891
1976
  );
1892
1977
  var ReadAction = ActionBase.merge(
1893
- import_zod19.z.object({
1894
- type: import_zod19.z.literal(ActionType.READ)
1895
- })
1896
- );
1897
- var CustomAction = ActionBase.merge(
1898
- import_zod19.z.object({
1899
- type: import_zod19.z.literal(ActionType.CUSTOM)
1978
+ import_zod21.z.object({
1979
+ type: import_zod21.z.literal(ActionType.READ)
1900
1980
  })
1901
1981
  );
1902
- var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1982
+ var ActionDocument = import_zod21.z.discriminatedUnion("type", [
1903
1983
  CreatedAction,
1904
1984
  ValidateAction,
1905
1985
  RejectAction,
@@ -1914,114 +1994,124 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1914
1994
  RejectedCorrectionAction,
1915
1995
  UnassignedAction,
1916
1996
  PrintCertificateAction,
1917
- ReadAction,
1918
- CustomAction
1997
+ ReadAction
1919
1998
  ]);
1920
- var ResolvedUser = import_zod19.z.object({
1921
- id: import_zod19.z.string(),
1922
- role: import_zod19.z.string(),
1923
- name: import_zod19.z.array(
1924
- import_zod19.z.object({
1925
- use: import_zod19.z.string(),
1926
- given: import_zod19.z.array(import_zod19.z.string()),
1927
- family: import_zod19.z.string()
1999
+ var AsyncRejectActionDocument = ActionBase.omit({
2000
+ declaration: true,
2001
+ annotation: true,
2002
+ createdBy: true,
2003
+ createdAtLocation: true
2004
+ }).merge(
2005
+ import_zod21.z.object({
2006
+ type: import_zod21.z.enum(ConfirmableActions),
2007
+ status: import_zod21.z.literal(ActionStatus.Rejected)
2008
+ })
2009
+ );
2010
+ var Action = import_zod21.z.union([ActionDocument, AsyncRejectActionDocument]);
2011
+ var ResolvedUser = import_zod21.z.object({
2012
+ id: import_zod21.z.string(),
2013
+ role: import_zod21.z.string(),
2014
+ name: import_zod21.z.array(
2015
+ import_zod21.z.object({
2016
+ use: import_zod21.z.string(),
2017
+ given: import_zod21.z.array(import_zod21.z.string()),
2018
+ family: import_zod21.z.string()
1928
2019
  })
1929
2020
  )
1930
2021
  });
1931
2022
 
1932
2023
  // ../commons/src/events/ActionInput.ts
1933
- var import_zod20 = require("zod");
1934
- var BaseActionInput = import_zod20.z.object({
1935
- eventId: import_zod20.z.string(),
1936
- transactionId: import_zod20.z.string(),
1937
- data: ActionUpdate,
1938
- metadata: ActionUpdate.optional()
2024
+ var import_zod22 = require("zod");
2025
+ var BaseActionInput = import_zod22.z.object({
2026
+ eventId: import_zod22.z.string(),
2027
+ transactionId: import_zod22.z.string(),
2028
+ declaration: ActionUpdate.default({}),
2029
+ annotation: ActionUpdate.optional(),
2030
+ originalActionId: import_zod22.z.string().optional()
1939
2031
  });
1940
2032
  var CreateActionInput = BaseActionInput.merge(
1941
- import_zod20.z.object({
1942
- type: import_zod20.z.literal(ActionType.CREATE).default(ActionType.CREATE),
1943
- createdAtLocation: import_zod20.z.string()
2033
+ import_zod22.z.object({
2034
+ type: import_zod22.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2035
+ createdAtLocation: import_zod22.z.string()
1944
2036
  })
1945
2037
  );
1946
2038
  var RegisterActionInput = BaseActionInput.merge(
1947
- import_zod20.z.object({
1948
- type: import_zod20.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
1949
- identifiers: import_zod20.z.object({
1950
- trackingId: import_zod20.z.string(),
1951
- registrationNumber: import_zod20.z.string()
1952
- })
2039
+ import_zod22.z.object({
2040
+ type: import_zod22.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2041
+ registrationNumber: import_zod22.z.string().optional()
1953
2042
  })
1954
2043
  );
1955
2044
  var ValidateActionInput = BaseActionInput.merge(
1956
- import_zod20.z.object({
1957
- type: import_zod20.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
1958
- duplicates: import_zod20.z.array(import_zod20.z.string())
2045
+ import_zod22.z.object({
2046
+ type: import_zod22.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2047
+ duplicates: import_zod22.z.array(import_zod22.z.string())
1959
2048
  })
1960
2049
  );
1961
2050
  var NotifyActionInput = BaseActionInput.merge(
1962
- import_zod20.z.object({
1963
- type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2051
+ import_zod22.z.object({
2052
+ type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1964
2053
  })
1965
2054
  );
1966
2055
  var DeclareActionInput = BaseActionInput.merge(
1967
- import_zod20.z.object({
1968
- type: import_zod20.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2056
+ import_zod22.z.object({
2057
+ type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1969
2058
  })
1970
2059
  );
1971
2060
  var PrintCertificateActionInput = BaseActionInput.merge(
1972
- import_zod20.z.object({
1973
- type: import_zod20.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2061
+ import_zod22.z.object({
2062
+ type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1974
2063
  })
1975
2064
  );
1976
2065
  var RejectDeclarationActionInput = BaseActionInput.merge(
1977
- import_zod20.z.object({
1978
- type: import_zod20.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2066
+ import_zod22.z.object({
2067
+ type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1979
2068
  })
1980
2069
  );
1981
2070
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1982
- import_zod20.z.object({
1983
- type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2071
+ import_zod22.z.object({
2072
+ type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1984
2073
  })
1985
2074
  );
1986
2075
  var ArchiveActionInput = BaseActionInput.merge(
1987
- import_zod20.z.object({
1988
- type: import_zod20.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2076
+ import_zod22.z.object({
2077
+ type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1989
2078
  })
1990
2079
  );
1991
2080
  var AssignActionInput = BaseActionInput.merge(
1992
- import_zod20.z.object({
1993
- type: import_zod20.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
1994
- assignedTo: import_zod20.z.string()
2081
+ import_zod22.z.object({
2082
+ type: import_zod22.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2083
+ assignedTo: import_zod22.z.string()
1995
2084
  })
1996
2085
  );
1997
2086
  var UnassignActionInput = BaseActionInput.merge(
1998
- import_zod20.z.object({
1999
- type: import_zod20.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN)
2087
+ import_zod22.z.object({
2088
+ type: import_zod22.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2089
+ assignedTo: import_zod22.z.literal(null).default(null)
2000
2090
  })
2001
2091
  );
2002
2092
  var RequestCorrectionActionInput = BaseActionInput.merge(
2003
- import_zod20.z.object({
2004
- type: import_zod20.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2093
+ import_zod22.z.object({
2094
+ type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2005
2095
  })
2006
2096
  );
2007
2097
  var RejectCorrectionActionInput = BaseActionInput.merge(
2008
- import_zod20.z.object({
2009
- requestId: import_zod20.z.string(),
2010
- type: import_zod20.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2098
+ import_zod22.z.object({
2099
+ requestId: import_zod22.z.string(),
2100
+ type: import_zod22.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2011
2101
  })
2012
2102
  );
2013
2103
  var ApproveCorrectionActionInput = BaseActionInput.merge(
2014
- import_zod20.z.object({
2015
- requestId: import_zod20.z.string(),
2016
- type: import_zod20.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2104
+ import_zod22.z.object({
2105
+ requestId: import_zod22.z.string(),
2106
+ type: import_zod22.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2017
2107
  })
2018
2108
  );
2019
2109
  var ReadActionInput = BaseActionInput.merge(
2020
- import_zod20.z.object({
2021
- type: import_zod20.z.literal(ActionType.READ).default(ActionType.READ)
2110
+ import_zod22.z.object({
2111
+ type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
2022
2112
  })
2023
2113
  );
2024
- var ActionInput = import_zod20.z.discriminatedUnion("type", [
2114
+ var ActionInput = import_zod22.z.discriminatedUnion("type", [
2025
2115
  CreateActionInput,
2026
2116
  ValidateActionInput,
2027
2117
  RegisterActionInput,
@@ -2040,52 +2130,57 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
2040
2130
  ]);
2041
2131
 
2042
2132
  // ../commons/src/events/Draft.ts
2043
- var Draft = import_zod21.z.object({
2044
- id: import_zod21.z.string(),
2045
- eventId: import_zod21.z.string(),
2046
- transactionId: import_zod21.z.string(),
2047
- createdAt: import_zod21.z.string().datetime(),
2133
+ var Draft = import_zod23.z.object({
2134
+ id: import_zod23.z.string(),
2135
+ eventId: import_zod23.z.string(),
2136
+ transactionId: import_zod23.z.string(),
2137
+ createdAt: import_zod23.z.string().datetime(),
2048
2138
  action: ActionBase.extend({
2049
- type: import_zod21.z.enum(Object.values(ActionType))
2139
+ type: ActionTypes
2050
2140
  }).omit({ id: true })
2051
2141
  });
2052
2142
  var DraftInput = BaseActionInput.extend({
2053
- type: import_zod21.z.enum(Object.values(ActionType))
2143
+ type: ActionTypes
2054
2144
  });
2055
2145
 
2056
2146
  // ../commons/src/events/EventInput.ts
2057
- var import_zod22 = require("zod");
2058
- var EventInput = import_zod22.z.object({
2059
- transactionId: import_zod22.z.string(),
2060
- type: import_zod22.z.string()
2147
+ var import_zod24 = require("zod");
2148
+ var EventInput = import_zod24.z.object({
2149
+ transactionId: import_zod24.z.string(),
2150
+ type: import_zod24.z.string()
2061
2151
  });
2062
2152
 
2063
2153
  // ../commons/src/events/EventDocument.ts
2064
- var import_zod23 = require("zod");
2065
- var EventDocument = import_zod23.z.object({
2066
- id: import_zod23.z.string(),
2067
- type: import_zod23.z.string(),
2068
- createdAt: import_zod23.z.string().datetime(),
2069
- updatedAt: import_zod23.z.string().datetime(),
2070
- actions: import_zod23.z.array(ActionDocument),
2071
- trackingId: import_zod23.z.string()
2154
+ var import_zod25 = require("zod");
2155
+ var EventDocument = import_zod25.z.object({
2156
+ id: import_zod25.z.string(),
2157
+ type: import_zod25.z.string(),
2158
+ createdAt: import_zod25.z.string().datetime(),
2159
+ updatedAt: import_zod25.z.string().datetime(),
2160
+ actions: import_zod25.z.array(Action),
2161
+ trackingId: import_zod25.z.string()
2072
2162
  });
2073
2163
 
2074
2164
  // ../commons/src/events/EventIndex.ts
2075
- var import_zod24 = require("zod");
2165
+ var import_zod26 = require("zod");
2076
2166
  var EventIndex = EventMetadata.extend({
2077
- data: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any())
2167
+ declaration: import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any())
2078
2168
  });
2079
- var EventSearchIndex = import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any()).and(
2080
- import_zod24.z.object({
2081
- type: import_zod24.z.string()
2169
+ var EventSearchIndex = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any()).and(
2170
+ import_zod26.z.object({
2171
+ type: import_zod26.z.string()
2082
2172
  // Ensures "type" (event-id) exists and is a string
2083
2173
  })
2084
2174
  );
2085
2175
 
2086
2176
  // ../commons/src/events/state/index.ts
2087
- var _ = __toESM(require("lodash"));
2088
2177
  function getStatusFromActions(actions) {
2178
+ const hasRejectedAction = actions.some(
2179
+ (a) => a.status === ActionStatus.Rejected
2180
+ );
2181
+ if (hasRejectedAction) {
2182
+ return EventStatus.REJECTED;
2183
+ }
2089
2184
  return actions.reduce((status, action) => {
2090
2185
  if (action.type === ActionType.CREATE) {
2091
2186
  return EventStatus.CREATED;
@@ -2122,7 +2217,7 @@ function getAssignedUserFromActions(actions) {
2122
2217
  return user2;
2123
2218
  }, null);
2124
2219
  }
2125
- function getData(actions) {
2220
+ function aggregateActionDeclarations(actions) {
2126
2221
  const excludedActions = [
2127
2222
  ActionType.REQUEST_CORRECTION,
2128
2223
  ActionType.PRINT_CERTIFICATE
@@ -2136,47 +2231,35 @@ function getData(actions) {
2136
2231
  if (!requestAction) {
2137
2232
  return status;
2138
2233
  }
2139
- return deepMerge(status, requestAction.data);
2234
+ return deepMerge(status, requestAction.declaration);
2140
2235
  }
2141
- return deepMerge(status, action.data);
2236
+ return deepMerge(status, action.declaration);
2142
2237
  }, {});
2143
2238
  }
2144
2239
  function deepDropNulls(obj) {
2145
- if (!_.isObject(obj)) return obj;
2146
- return Object.entries(obj).reduce((acc, [key, value]) => {
2147
- if (_.isObject(value)) {
2148
- value = deepDropNulls(value);
2149
- }
2150
- if (value !== null) {
2151
- return {
2152
- ...acc,
2153
- [key]: value
2154
- };
2155
- }
2156
- return acc;
2157
- }, {});
2158
- }
2159
- function deepMerge(currentDocument, actionDocument) {
2160
- return _.mergeWith(
2161
- currentDocument,
2162
- actionDocument,
2163
- (previousValue, incomingValue) => {
2164
- if (incomingValue === void 0) {
2165
- return previousValue;
2166
- }
2167
- if (_.isArray(incomingValue)) {
2168
- return incomingValue;
2169
- }
2170
- if (_.isObject(previousValue) && _.isObject(incomingValue)) {
2171
- return void 0;
2240
+ if (Array.isArray(obj)) {
2241
+ return obj;
2242
+ }
2243
+ if (obj !== null && typeof obj === "object") {
2244
+ return Object.entries(obj).reduce((acc, [key, value]) => {
2245
+ const cleanedValue = deepDropNulls(value);
2246
+ if (cleanedValue !== null) {
2247
+ ;
2248
+ acc[key] = cleanedValue;
2172
2249
  }
2173
- return incomingValue;
2174
- }
2175
- );
2250
+ return acc;
2251
+ }, {});
2252
+ }
2253
+ return obj;
2176
2254
  }
2177
2255
  function isUndeclaredDraft(status) {
2178
2256
  return status === EventStatus.CREATED;
2179
2257
  }
2258
+ function getAcceptedActions(event2) {
2259
+ return event2.actions.filter(
2260
+ (a) => a.status === ActionStatus.Accepted
2261
+ );
2262
+ }
2180
2263
  function getCurrentEventState(event2) {
2181
2264
  const creationAction = event2.actions.find(
2182
2265
  (action) => action.type === ActionType.CREATE
@@ -2184,7 +2267,12 @@ function getCurrentEventState(event2) {
2184
2267
  if (!creationAction) {
2185
2268
  throw new Error(`Event ${event2.id} has no creation action`);
2186
2269
  }
2187
- const latestAction = event2.actions[event2.actions.length - 1];
2270
+ const activeActions = getAcceptedActions(event2);
2271
+ const latestAction = activeActions[activeActions.length - 1];
2272
+ const registrationAction = activeActions.find(
2273
+ (a) => a.type === ActionType.REGISTER && a.status === ActionStatus.Accepted
2274
+ );
2275
+ const registrationNumber = registrationAction?.registrationNumber ?? null;
2188
2276
  return deepDropNulls({
2189
2277
  id: event2.id,
2190
2278
  type: event2.type,
@@ -2193,10 +2281,11 @@ function getCurrentEventState(event2) {
2193
2281
  createdBy: creationAction.createdBy,
2194
2282
  createdAtLocation: creationAction.createdAtLocation,
2195
2283
  modifiedAt: latestAction.createdAt,
2196
- assignedTo: getAssignedUserFromActions(event2.actions),
2284
+ assignedTo: getAssignedUserFromActions(activeActions),
2197
2285
  updatedBy: latestAction.createdBy,
2198
- data: getData(event2.actions),
2199
- trackingId: event2.trackingId
2286
+ declaration: aggregateActionDeclarations(activeActions),
2287
+ trackingId: event2.trackingId,
2288
+ registrationNumber
2200
2289
  });
2201
2290
  }
2202
2291
  function getCurrentEventStateWithDrafts(event2, drafts) {
@@ -2228,38 +2317,44 @@ function applyDraftsToEventIndex(eventIndex, drafts) {
2228
2317
  }
2229
2318
  return {
2230
2319
  ...eventIndex,
2231
- data: {
2232
- ...eventIndex.data,
2233
- ...activeDrafts[activeDrafts.length - 1].data
2320
+ declaration: {
2321
+ ...eventIndex.declaration,
2322
+ ...activeDrafts[activeDrafts.length - 1].declaration
2234
2323
  }
2235
2324
  };
2236
2325
  }
2237
- function getMetadataForAction({
2326
+ function getAnnotationFromDrafts(drafts) {
2327
+ const actions = drafts.map((draft) => draft.action);
2328
+ const annotation = actions.reduce((ann, action) => {
2329
+ return deepMerge(ann, action.annotation ?? {});
2330
+ }, {});
2331
+ return deepDropNulls(annotation);
2332
+ }
2333
+ function getActionAnnotation({
2238
2334
  event: event2,
2239
2335
  actionType,
2240
2336
  drafts
2241
2337
  }) {
2242
- const action = event2.actions.find((action2) => actionType === action2.type);
2338
+ const activeActions = getAcceptedActions(event2);
2339
+ const action = activeActions.find(
2340
+ (activeAction) => actionType === activeAction.type
2341
+ );
2243
2342
  const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
2244
2343
  const sorted = [
2245
2344
  ...action ? [action] : [],
2246
2345
  ...eventDrafts.map((draft) => draft.action)
2247
2346
  ].sort();
2248
- const metadata = sorted.reduce((metadata2, action2) => {
2249
- return deepMerge(metadata2, action2.metadata ?? {});
2347
+ const annotation = sorted.reduce((ann, sortedAction) => {
2348
+ return deepMerge(ann, sortedAction.annotation ?? {});
2250
2349
  }, {});
2251
- return deepDropNulls(metadata);
2350
+ return deepDropNulls(annotation);
2252
2351
  }
2253
2352
 
2254
2353
  // ../commons/src/events/defineConfig.ts
2255
2354
  var defineConfig = (config) => {
2256
2355
  validateWorkqueueConfig(config.workqueues);
2257
2356
  const input = EventConfig.parse(config);
2258
- const pageFields = findInputPageFields(input);
2259
- return EventConfig.parse({
2260
- ...input,
2261
- pageFields
2262
- });
2357
+ return input;
2263
2358
  };
2264
2359
 
2265
2360
  // ../commons/src/events/transactions.ts
@@ -2274,6 +2369,16 @@ var import_lodash2 = require("lodash");
2274
2369
  function defineConditional(schema) {
2275
2370
  return schema;
2276
2371
  }
2372
+ function defineFormConditional(schema) {
2373
+ const schemaWithForm = {
2374
+ type: "object",
2375
+ properties: {
2376
+ $form: schema
2377
+ },
2378
+ required: ["$form"]
2379
+ };
2380
+ return defineConditional(schemaWithForm);
2381
+ }
2277
2382
  function alwaysTrue() {
2278
2383
  return {};
2279
2384
  }
@@ -2298,6 +2403,9 @@ function not(condition) {
2298
2403
  required: []
2299
2404
  });
2300
2405
  }
2406
+ function never() {
2407
+ return not(alwaysTrue());
2408
+ }
2301
2409
  var user = {
2302
2410
  hasScope: (scope) => defineConditional({
2303
2411
  type: "object",
@@ -2345,69 +2453,120 @@ var event = {
2345
2453
  required: ["$event"]
2346
2454
  })
2347
2455
  };
2456
+ function getDateFromNow(days) {
2457
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2458
+ }
2459
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2460
+ return {
2461
+ type: "object",
2462
+ properties: {
2463
+ [fieldId]: {
2464
+ type: "string",
2465
+ format: "date",
2466
+ [clause]: { $data: `1/${comparedFieldId}` }
2467
+ },
2468
+ [comparedFieldId]: { type: "string", format: "date" }
2469
+ },
2470
+ required: [fieldId]
2471
+ };
2472
+ }
2473
+ function isFieldReference(value) {
2474
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2475
+ }
2348
2476
  function field(fieldId) {
2349
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2350
2477
  const getDateRange = (date, clause) => ({
2351
2478
  type: "object",
2352
2479
  properties: {
2353
- $form: {
2354
- type: "object",
2355
- properties: {
2356
- [fieldId]: {
2357
- type: "string",
2358
- format: "date",
2359
- [clause]: date
2360
- }
2361
- },
2362
- required: [fieldId]
2480
+ [fieldId]: {
2481
+ type: "string",
2482
+ format: "date",
2483
+ [clause]: date
2363
2484
  }
2364
2485
  },
2365
- required: ["$form"]
2486
+ required: [fieldId]
2366
2487
  });
2367
2488
  return {
2489
+ /**
2490
+ * @private Internal property used for field reference tracking.
2491
+ */
2492
+ _fieldId: fieldId,
2368
2493
  isAfter: () => ({
2369
2494
  days: (days) => ({
2370
- inPast: () => defineConditional(
2495
+ inPast: () => defineFormConditional(
2371
2496
  getDateRange(getDateFromNow(days), "formatMinimum")
2372
2497
  ),
2373
- inFuture: () => defineConditional(
2498
+ inFuture: () => defineFormConditional(
2374
2499
  getDateRange(getDateFromNow(-days), "formatMinimum")
2375
2500
  )
2376
2501
  }),
2377
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
2378
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2502
+ date: (date) => {
2503
+ if (isFieldReference(date)) {
2504
+ const comparedFieldId = date._fieldId;
2505
+ return defineFormConditional(
2506
+ getDateRangeToFieldReference(
2507
+ fieldId,
2508
+ comparedFieldId,
2509
+ "formatMinimum"
2510
+ )
2511
+ );
2512
+ }
2513
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2514
+ },
2515
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2379
2516
  }),
2380
2517
  isBefore: () => ({
2381
2518
  days: (days) => ({
2382
- inPast: () => defineConditional(
2519
+ inPast: () => defineFormConditional(
2383
2520
  getDateRange(getDateFromNow(days), "formatMaximum")
2384
2521
  ),
2385
- inFuture: () => defineConditional(
2522
+ inFuture: () => defineFormConditional(
2386
2523
  getDateRange(getDateFromNow(-days), "formatMaximum")
2387
2524
  )
2388
2525
  }),
2389
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
2390
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2526
+ date: (date) => {
2527
+ if (isFieldReference(date)) {
2528
+ const comparedFieldId = date._fieldId;
2529
+ return defineFormConditional(
2530
+ getDateRangeToFieldReference(
2531
+ fieldId,
2532
+ comparedFieldId,
2533
+ "formatMaximum"
2534
+ )
2535
+ );
2536
+ }
2537
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2538
+ },
2539
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2391
2540
  }),
2392
- isEqualTo: (value) => defineConditional({
2393
- type: "object",
2394
- properties: {
2395
- $form: {
2541
+ isEqualTo: (value) => {
2542
+ if (isFieldReference(value)) {
2543
+ const comparedFieldId = value._fieldId;
2544
+ return defineFormConditional({
2396
2545
  type: "object",
2397
2546
  properties: {
2398
2547
  [fieldId]: {
2399
- oneOf: [
2400
- { type: "string", const: value },
2401
- { type: "boolean", const: value }
2402
- ],
2403
- const: value
2404
- }
2548
+ type: ["string", "boolean"],
2549
+ const: { $data: `1/${comparedFieldId}` }
2550
+ },
2551
+ [comparedFieldId]: { type: ["string", "boolean"] }
2405
2552
  },
2406
- required: [fieldId]
2407
- }
2408
- },
2409
- required: ["$form"]
2410
- }),
2553
+ required: [fieldId, comparedFieldId]
2554
+ });
2555
+ }
2556
+ return defineFormConditional({
2557
+ type: "object",
2558
+ properties: {
2559
+ [fieldId]: {
2560
+ oneOf: [
2561
+ { type: "string", const: value },
2562
+ { type: "boolean", const: value }
2563
+ ],
2564
+ const: value
2565
+ }
2566
+ },
2567
+ required: [fieldId]
2568
+ });
2569
+ },
2411
2570
  /**
2412
2571
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
2413
2572
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -2416,108 +2575,102 @@ function field(fieldId) {
2416
2575
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2417
2576
  *
2418
2577
  */
2419
- isFalsy: () => defineConditional({
2578
+ isFalsy: () => defineFormConditional({
2420
2579
  type: "object",
2421
2580
  properties: {
2422
- $form: {
2423
- type: "object",
2424
- properties: {
2425
- [fieldId]: {
2426
- anyOf: [
2427
- { const: "undefined" },
2428
- { const: false },
2429
- { const: null },
2430
- { const: "" }
2431
- ]
2432
- }
2433
- },
2581
+ [fieldId]: {
2434
2582
  anyOf: [
2435
- {
2436
- required: [fieldId]
2437
- },
2438
- {
2439
- not: {
2440
- required: [fieldId]
2441
- }
2442
- }
2583
+ { const: "undefined" },
2584
+ { const: false },
2585
+ { const: null },
2586
+ { const: "" }
2443
2587
  ]
2444
2588
  }
2445
2589
  },
2446
- required: ["$form"]
2447
- }),
2448
- isUndefined: () => defineConditional({
2449
- type: "object",
2450
- properties: {
2451
- $form: {
2452
- type: "object",
2453
- properties: {
2454
- [fieldId]: {
2455
- type: "string",
2456
- enum: ["undefined"]
2457
- }
2458
- },
2590
+ anyOf: [
2591
+ {
2592
+ required: [fieldId]
2593
+ },
2594
+ {
2459
2595
  not: {
2460
2596
  required: [fieldId]
2461
2597
  }
2462
2598
  }
2599
+ ]
2600
+ }),
2601
+ isUndefined: () => defineFormConditional({
2602
+ type: "object",
2603
+ properties: {
2604
+ [fieldId]: {
2605
+ type: "string",
2606
+ enum: ["undefined"]
2607
+ }
2463
2608
  },
2464
- required: ["$form"]
2609
+ not: {
2610
+ required: [fieldId]
2611
+ }
2465
2612
  }),
2466
- inArray: (values) => defineConditional({
2613
+ inArray: (values) => defineFormConditional({
2467
2614
  type: "object",
2468
2615
  properties: {
2469
- $form: {
2470
- type: "object",
2471
- properties: {
2472
- [fieldId]: {
2473
- type: "string",
2474
- enum: values
2475
- }
2476
- },
2477
- required: [fieldId]
2616
+ [fieldId]: {
2617
+ type: "string",
2618
+ enum: values
2478
2619
  }
2479
2620
  },
2480
- required: ["$form"]
2621
+ required: [fieldId]
2481
2622
  }),
2482
- isValidEnglishName: () => defineConditional({
2623
+ isValidEnglishName: () => defineFormConditional({
2483
2624
  type: "object",
2484
2625
  properties: {
2485
- $form: {
2486
- type: "object",
2487
- properties: {
2488
- [fieldId]: {
2489
- type: "string",
2490
- pattern: "^[\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*( [\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*)*$",
2491
- description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2492
- }
2493
- },
2494
- required: [fieldId]
2626
+ [fieldId]: {
2627
+ type: "string",
2628
+ 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'._-]*)*$",
2629
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2630
+ }
2631
+ },
2632
+ required: [fieldId]
2633
+ }),
2634
+ /**
2635
+ * Checks if the field value matches a given regular expression pattern.
2636
+ * @param pattern - The regular expression pattern to match the field value against.
2637
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2638
+ */
2639
+ matches: (pattern) => defineFormConditional({
2640
+ type: "object",
2641
+ properties: {
2642
+ [fieldId]: {
2643
+ type: "string",
2644
+ pattern
2645
+ }
2646
+ },
2647
+ required: [fieldId]
2648
+ }),
2649
+ isBetween: (min, max) => defineFormConditional({
2650
+ type: "object",
2651
+ properties: {
2652
+ [fieldId]: {
2653
+ type: "number",
2654
+ minimum: min,
2655
+ maximum: max
2495
2656
  }
2496
2657
  },
2497
- required: ["$form"]
2658
+ required: [fieldId]
2498
2659
  })
2499
2660
  };
2500
2661
  }
2501
2662
 
2502
2663
  // ../commons/src/fixtures/tennis-club-membership-event.ts
2503
- var PRINT_CERTIFICATE_FORM = defineForm({
2664
+ var PRINT_CERTIFICATE_FORM = defineActionForm({
2504
2665
  label: {
2505
2666
  id: "v2.event.tennis-club-membership.action.certificate.form.label",
2506
2667
  defaultMessage: "Tennis club membership certificate collector",
2507
2668
  description: "This is what this form is referred as in the system"
2508
2669
  },
2509
- version: {
2510
- id: "1.0.0",
2511
- label: {
2512
- id: "v2.event.tennis-club-membership.action.certificate.form.version.1",
2513
- defaultMessage: "Version 1",
2514
- description: "This is the first version of the form"
2515
- }
2516
- },
2517
- active: true,
2518
2670
  pages: [
2519
2671
  {
2520
2672
  id: "collector",
2673
+ type: PageTypes.enum.FORM,
2521
2674
  title: {
2522
2675
  id: "v2.event.tennis-club-membership.action.certificate.form.section.who.title",
2523
2676
  defaultMessage: "Print certified copy",
@@ -2532,7 +2685,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2532
2685
  defaultMessage: "Requester",
2533
2686
  description: "This is the label for the field"
2534
2687
  },
2535
- type: "SELECT",
2688
+ type: FieldType.SELECT,
2536
2689
  options: [
2537
2690
  {
2538
2691
  value: "INFORMANT",
@@ -2609,7 +2762,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2609
2762
  defaultMessage: "Select Type of ID",
2610
2763
  description: "This is the label for selecting the type of ID"
2611
2764
  },
2612
- type: "SELECT",
2765
+ type: FieldType.SELECT,
2613
2766
  options: [
2614
2767
  {
2615
2768
  value: "PASSPORT",
@@ -2710,7 +2863,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2710
2863
  defaultMessage: "Passport Details",
2711
2864
  description: "Field for entering Passport details"
2712
2865
  },
2713
- type: "TEXT"
2866
+ type: FieldType.TEXT
2714
2867
  },
2715
2868
  {
2716
2869
  id: "collector.DRIVING_LICENSE.details",
@@ -2761,7 +2914,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2761
2914
  defaultMessage: "Driving License Details",
2762
2915
  description: "Field for entering Driving License details"
2763
2916
  },
2764
- type: "TEXT"
2917
+ type: FieldType.TEXT
2765
2918
  },
2766
2919
  {
2767
2920
  id: "collector.REFUGEE_NUMBER.details",
@@ -2812,7 +2965,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2812
2965
  defaultMessage: "Refugee Number Details",
2813
2966
  description: "Field for entering Refugee Number details"
2814
2967
  },
2815
- type: "TEXT"
2968
+ type: FieldType.TEXT
2816
2969
  },
2817
2970
  {
2818
2971
  id: "collector.ALIEN_NUMBER.details",
@@ -2863,7 +3016,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2863
3016
  defaultMessage: "Alien Number Details",
2864
3017
  description: "Field for entering Alien Number details"
2865
3018
  },
2866
- type: "TEXT"
3019
+ type: FieldType.TEXT
2867
3020
  },
2868
3021
  {
2869
3022
  id: "collector.OTHER.idTypeOther",
@@ -2914,7 +3067,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2914
3067
  defaultMessage: "Other ID Type (if applicable)",
2915
3068
  description: 'Field for entering ID type if "Other" is selected'
2916
3069
  },
2917
- type: "TEXT"
3070
+ type: FieldType.TEXT
2918
3071
  },
2919
3072
  {
2920
3073
  id: "collector.OTHER.firstName",
@@ -2965,7 +3118,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2965
3118
  defaultMessage: "First Name",
2966
3119
  description: "This is the label for the first name field"
2967
3120
  },
2968
- type: "TEXT"
3121
+ type: FieldType.TEXT
2969
3122
  },
2970
3123
  {
2971
3124
  id: "collector.OTHER.lastName",
@@ -3016,7 +3169,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
3016
3169
  defaultMessage: "Last Name",
3017
3170
  description: "This is the label for the last name field"
3018
3171
  },
3019
- type: "TEXT"
3172
+ type: FieldType.TEXT
3020
3173
  },
3021
3174
  {
3022
3175
  id: "collector.OTHER.relationshipToMember",
@@ -3067,7 +3220,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
3067
3220
  defaultMessage: "Relationship to Member",
3068
3221
  description: "This is the label for the relationship to member field"
3069
3222
  },
3070
- type: "TEXT"
3223
+ type: FieldType.TEXT
3071
3224
  },
3072
3225
  {
3073
3226
  id: "collector.OTHER.signedAffidavit",
@@ -3118,13 +3271,13 @@ var PRINT_CERTIFICATE_FORM = defineForm({
3118
3271
  defaultMessage: "Signed Affidavit (Optional)",
3119
3272
  description: "This is the label for uploading a signed affidavit"
3120
3273
  },
3121
- type: "FILE"
3274
+ type: FieldType.FILE
3122
3275
  }
3123
3276
  ]
3124
3277
  },
3125
3278
  {
3126
3279
  id: "collector.identity.verify",
3127
- type: FormPageType.VERIFICATION,
3280
+ type: PageTypes.enum.VERIFICATION,
3128
3281
  conditional: field("collector.requesterId").isEqualTo("INFORMANT"),
3129
3282
  title: {
3130
3283
  id: "event.tennis-club-membership.action.print.verifyIdentity",
@@ -3161,62 +3314,45 @@ var PRINT_CERTIFICATE_FORM = defineForm({
3161
3314
  }
3162
3315
  }
3163
3316
  }
3164
- ],
3165
- review: {
3166
- title: {
3167
- id: "v2.event.tennis-club-membership.action.certificate.form.review.title",
3168
- defaultMessage: "Member certificate collector for {firstname} {surname}",
3169
- description: "Title of the form to show in review page"
3170
- },
3171
- fields: []
3172
- }
3317
+ ]
3173
3318
  });
3174
- var TENNIS_CLUB_FORM = defineForm({
3175
- label: {
3176
- id: "v2.event.tennis-club-membership.action.declare.form.label",
3177
- defaultMessage: "Tennis club membership application",
3178
- description: "This is what this form is referred as in the system"
3179
- },
3180
- active: true,
3181
- version: {
3182
- id: "1.0.0",
3183
- label: {
3184
- id: "v2.event.tennis-club-membership.action.declare.form.version.1",
3185
- defaultMessage: "Version 1",
3186
- description: "This is the first version of the form"
3187
- }
3319
+ var TENNIS_CLUB_DECLARATION_REVIEW = {
3320
+ title: {
3321
+ id: "v2.event.tennis-club-membership.action.declare.form.review.title",
3322
+ defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
3323
+ description: "Title of the review page"
3188
3324
  },
3189
- review: {
3190
- title: {
3191
- id: "v2.event.tennis-club-membership.action.declare.form.review.title",
3192
- defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
3193
- description: "Title of the form to show in review page"
3325
+ fields: [
3326
+ {
3327
+ id: "review.comment",
3328
+ type: FieldType.TEXTAREA,
3329
+ label: {
3330
+ defaultMessage: "Comment",
3331
+ id: "v2.event.birth.action.declare.form.review.comment.label",
3332
+ description: "Label for the comment field in the review section"
3333
+ }
3194
3334
  },
3195
- fields: [
3196
- {
3197
- id: "review.comment",
3198
- type: "TEXTAREA",
3199
- label: {
3200
- defaultMessage: "Comment",
3201
- id: "v2.event.birth.action.declare.form.review.comment.label",
3202
- description: "Label for the comment field in the review section"
3203
- }
3335
+ {
3336
+ type: FieldType.SIGNATURE,
3337
+ id: "review.signature",
3338
+ label: {
3339
+ defaultMessage: "Signature of informant",
3340
+ id: "v2.event.birth.action.declare.form.review.signature.label",
3341
+ description: "Label for the signature field in the review section"
3204
3342
  },
3205
- {
3206
- type: "SIGNATURE",
3207
- id: "review.signature",
3208
- label: {
3209
- defaultMessage: "Signature of informant",
3210
- id: "v2.event.birth.action.declare.form.review.signature.label",
3211
- description: "Label for the signature field in the review section"
3212
- },
3213
- signaturePromptLabel: {
3214
- id: "v2.signature.upload.modal.title",
3215
- defaultMessage: "Draw signature",
3216
- description: "Title for the modal to draw signature"
3217
- }
3343
+ signaturePromptLabel: {
3344
+ id: "v2.signature.upload.modal.title",
3345
+ defaultMessage: "Draw signature",
3346
+ description: "Title for the modal to draw signature"
3218
3347
  }
3219
- ]
3348
+ }
3349
+ ]
3350
+ };
3351
+ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3352
+ label: {
3353
+ id: "v2.event.tennis-club-membership.action.declare.form.label",
3354
+ defaultMessage: "Tennis club membership application",
3355
+ description: "This is what this form is referred as in the system"
3220
3356
  },
3221
3357
  pages: [
3222
3358
  {
@@ -3229,7 +3365,7 @@ var TENNIS_CLUB_FORM = defineForm({
3229
3365
  fields: [
3230
3366
  {
3231
3367
  id: "applicant.firstname",
3232
- type: "TEXT",
3368
+ type: FieldType.TEXT,
3233
3369
  required: true,
3234
3370
  conditionals: [],
3235
3371
  label: {
@@ -3240,7 +3376,7 @@ var TENNIS_CLUB_FORM = defineForm({
3240
3376
  },
3241
3377
  {
3242
3378
  id: "applicant.surname",
3243
- type: "TEXT",
3379
+ type: FieldType.TEXT,
3244
3380
  required: true,
3245
3381
  conditionals: [],
3246
3382
  label: {
@@ -3283,7 +3419,7 @@ var TENNIS_CLUB_FORM = defineForm({
3283
3419
  },
3284
3420
  {
3285
3421
  id: "applicant.image",
3286
- type: "FILE",
3422
+ type: FieldType.FILE,
3287
3423
  required: false,
3288
3424
  label: {
3289
3425
  defaultMessage: "Applicant's profile picture",
@@ -3315,7 +3451,7 @@ var TENNIS_CLUB_FORM = defineForm({
3315
3451
  fields: [
3316
3452
  {
3317
3453
  id: "senior-pass.id",
3318
- type: "TEXT",
3454
+ type: FieldType.TEXT,
3319
3455
  required: true,
3320
3456
  label: {
3321
3457
  defaultMessage: "Senior pass ID",
@@ -3346,7 +3482,7 @@ var TENNIS_CLUB_FORM = defineForm({
3346
3482
  },
3347
3483
  {
3348
3484
  id: "recommender.firstname",
3349
- type: "TEXT",
3485
+ type: FieldType.TEXT,
3350
3486
  required: true,
3351
3487
  conditionals: [
3352
3488
  {
@@ -3362,7 +3498,7 @@ var TENNIS_CLUB_FORM = defineForm({
3362
3498
  },
3363
3499
  {
3364
3500
  id: "recommender.surname",
3365
- type: "TEXT",
3501
+ type: FieldType.TEXT,
3366
3502
  required: true,
3367
3503
  conditionals: [
3368
3504
  {
@@ -3378,7 +3514,7 @@ var TENNIS_CLUB_FORM = defineForm({
3378
3514
  },
3379
3515
  {
3380
3516
  id: "recommender.id",
3381
- type: "TEXT",
3517
+ type: FieldType.TEXT,
3382
3518
  required: true,
3383
3519
  conditionals: [
3384
3520
  {
@@ -3486,7 +3622,7 @@ var tennisClubMembershipEvent = defineConfig({
3486
3622
  description: "This is shown as the action name anywhere the user can trigger the action from",
3487
3623
  id: "event.tennis-club-membership.action.declare.label"
3488
3624
  },
3489
- forms: [TENNIS_CLUB_FORM]
3625
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3490
3626
  },
3491
3627
  {
3492
3628
  type: ActionType.VALIDATE,
@@ -3495,7 +3631,7 @@ var tennisClubMembershipEvent = defineConfig({
3495
3631
  description: "This is shown as the action name anywhere the user can trigger the action from",
3496
3632
  id: "event.tennis-club-membership.action.validate.label"
3497
3633
  },
3498
- forms: [TENNIS_CLUB_FORM]
3634
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3499
3635
  },
3500
3636
  {
3501
3637
  type: ActionType.REGISTER,
@@ -3504,7 +3640,7 @@ var tennisClubMembershipEvent = defineConfig({
3504
3640
  description: "This is shown as the action name anywhere the user can trigger the action from",
3505
3641
  id: "event.tennis-club-membership.action.register.label"
3506
3642
  },
3507
- forms: [TENNIS_CLUB_FORM]
3643
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3508
3644
  },
3509
3645
  {
3510
3646
  type: ActionType.REQUEST_CORRECTION,
@@ -3513,10 +3649,10 @@ var tennisClubMembershipEvent = defineConfig({
3513
3649
  description: "This is shown as the action name anywhere the user can trigger the action from",
3514
3650
  id: "event.tennis-club-membership.action.correction.request.label"
3515
3651
  },
3516
- forms: [TENNIS_CLUB_FORM],
3517
3652
  onboardingForm: [
3518
3653
  {
3519
3654
  id: "correction-requester",
3655
+ type: PageTypes.enum.FORM,
3520
3656
  title: {
3521
3657
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3522
3658
  defaultMessage: "Correction requester",
@@ -3580,6 +3716,7 @@ var tennisClubMembershipEvent = defineConfig({
3580
3716
  },
3581
3717
  {
3582
3718
  id: "identity-check",
3719
+ type: PageTypes.enum.FORM,
3583
3720
  title: {
3584
3721
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3585
3722
  defaultMessage: "Verify their identity",
@@ -3622,6 +3759,7 @@ var tennisClubMembershipEvent = defineConfig({
3622
3759
  additionalDetailsForm: [
3623
3760
  {
3624
3761
  id: "correction-request.supporting-documents",
3762
+ type: PageTypes.enum.FORM,
3625
3763
  title: {
3626
3764
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3627
3765
  defaultMessage: "Upload supporting documents",
@@ -3639,7 +3777,7 @@ var tennisClubMembershipEvent = defineConfig({
3639
3777
  },
3640
3778
  {
3641
3779
  id: "correction.supportingDocs",
3642
- type: "FILE",
3780
+ type: FieldType.FILE,
3643
3781
  label: {
3644
3782
  id: "correction.corrector.title",
3645
3783
  defaultMessage: "Upload supporting documents",
@@ -3683,6 +3821,7 @@ var tennisClubMembershipEvent = defineConfig({
3683
3821
  },
3684
3822
  {
3685
3823
  id: "correction-request.additional-details",
3824
+ type: PageTypes.enum.FORM,
3686
3825
  title: {
3687
3826
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3688
3827
  defaultMessage: "Reason for correction",
@@ -3691,7 +3830,7 @@ var tennisClubMembershipEvent = defineConfig({
3691
3830
  fields: [
3692
3831
  {
3693
3832
  id: "correction.request.reason",
3694
- type: "TEXT",
3833
+ type: FieldType.TEXT,
3695
3834
  label: {
3696
3835
  id: "correction.reason.title",
3697
3836
  defaultMessage: "Reason for correction?",
@@ -3704,7 +3843,6 @@ var tennisClubMembershipEvent = defineConfig({
3704
3843
  },
3705
3844
  {
3706
3845
  type: ActionType.APPROVE_CORRECTION,
3707
- forms: [TENNIS_CLUB_FORM],
3708
3846
  label: {
3709
3847
  defaultMessage: "Approve correction",
3710
3848
  description: "This is shown as the action name anywhere the user can trigger the action from",
@@ -3718,7 +3856,7 @@ var tennisClubMembershipEvent = defineConfig({
3718
3856
  defaultMessage: "Print certificate",
3719
3857
  description: "This is shown as the action name anywhere the user can trigger the action from"
3720
3858
  },
3721
- forms: [PRINT_CERTIFICATE_FORM],
3859
+ printForm: PRINT_CERTIFICATE_FORM,
3722
3860
  conditionals: [
3723
3861
  {
3724
3862
  type: "SHOW",
@@ -3765,8 +3903,7 @@ var tennisClubMembershipEvent = defineConfig({
3765
3903
  id: "v2.event.tennis-club-membership.action.archive.label",
3766
3904
  defaultMessage: "Archive",
3767
3905
  description: "This is shown as the action name anywhere the user can trigger the action from"
3768
- },
3769
- forms: [TENNIS_CLUB_FORM]
3906
+ }
3770
3907
  },
3771
3908
  {
3772
3909
  type: ActionType.REJECT,
@@ -3774,8 +3911,7 @@ var tennisClubMembershipEvent = defineConfig({
3774
3911
  id: "v2.event.tennis-club-membership.action.reject.label",
3775
3912
  defaultMessage: "Reject",
3776
3913
  description: "This is shown as the action name anywhere the user can trigger the action from"
3777
- },
3778
- forms: [TENNIS_CLUB_FORM]
3914
+ }
3779
3915
  }
3780
3916
  ],
3781
3917
  advancedSearch: [
@@ -3791,33 +3927,52 @@ var tennisClubMembershipEvent = defineConfig({
3791
3927
  }
3792
3928
  ]
3793
3929
  }
3794
- ]
3930
+ ],
3931
+ declaration: TENNIS_CLUB_DECLARATION_FORM
3795
3932
  });
3796
3933
 
3797
3934
  // ../commons/src/events/test.utils.ts
3798
- function generateActionInput(configuration, action) {
3799
- const fields = findActiveActionFormFields(configuration, action) ?? [];
3800
- const data = fields.reduce(
3935
+ function fieldConfigsToActionAnnotation(fields) {
3936
+ return fields.reduce(
3801
3937
  (acc, field2, i) => ({
3802
3938
  ...acc,
3803
3939
  [field2.id]: mapFieldTypeToMockValue(field2, i)
3804
3940
  }),
3805
3941
  {}
3806
3942
  );
3807
- return stripHiddenFields(fields, data);
3943
+ }
3944
+ function generateActionInput(configuration, action) {
3945
+ const parsed = DeclarationUpdateActions.safeParse(action);
3946
+ if (parsed.success) {
3947
+ const fields = getDeclarationFields(configuration);
3948
+ const annotation = fieldConfigsToActionAnnotation(fields);
3949
+ return stripHiddenFields(fields, annotation);
3950
+ }
3951
+ console.warn(`${action} is not a declaration action. Setting data as {}.`);
3952
+ return {};
3808
3953
  }
3809
3954
  function generateActionMetadataInput(configuration, action) {
3810
- const visibleVerificationPageIds = getActiveActionFormPages(
3955
+ const actionConfig = configuration.actions.find(
3956
+ (ac) => ac.type === action
3957
+ );
3958
+ const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
3959
+ const annotation = fieldConfigsToActionAnnotation(annotationFields);
3960
+ const visibleVerificationPageIds = findRecordActionPages(
3811
3961
  configuration,
3812
3962
  action
3813
- ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, {})).map((page) => page.id);
3814
- return visibleVerificationPageIds.reduce(
3963
+ ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
3964
+ const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
3815
3965
  (acc, pageId) => ({
3816
3966
  ...acc,
3817
3967
  [pageId]: true
3818
3968
  }),
3819
3969
  {}
3820
3970
  );
3971
+ const fieldBasedPayload = stripHiddenFields(annotationFields, annotation);
3972
+ return {
3973
+ ...fieldBasedPayload,
3974
+ ...visiblePageVerificationMap
3975
+ };
3821
3976
  }
3822
3977
  var eventPayloadGenerator = {
3823
3978
  create: (input = {}) => ({
@@ -3829,21 +3984,22 @@ var eventPayloadGenerator = {
3829
3984
  type: input.type ?? "TENNIS_CLUB_MEMBERSHIP",
3830
3985
  id
3831
3986
  }),
3832
- draft: (eventId, input = {}) => (0, import_lodash2.merge)(
3987
+ draft: ({ eventId, actionType }, input = {}) => (0, import_lodash2.merge)(
3833
3988
  {
3834
3989
  id: getUUID(),
3835
3990
  eventId,
3836
3991
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3837
3992
  transactionId: getUUID(),
3838
3993
  action: {
3839
- type: ActionType.REQUEST_CORRECTION,
3840
- data: {
3994
+ type: actionType,
3995
+ status: ActionStatus.Accepted,
3996
+ declaration: {
3841
3997
  "applicant.firstname": "Max",
3842
3998
  "applicant.surname": "McLaren",
3843
3999
  "applicant.dob": "2020-01-02",
3844
4000
  "recommender.none": true
3845
4001
  },
3846
- metadata: {
4002
+ annotation: {
3847
4003
  "correction.requester.relationship": "ANOTHER_AGENT",
3848
4004
  "correction.request.reason": "Child's name was incorrect"
3849
4005
  },
@@ -3858,45 +4014,92 @@ var eventPayloadGenerator = {
3858
4014
  declare: (eventId, input = {}) => ({
3859
4015
  type: ActionType.DECLARE,
3860
4016
  transactionId: input.transactionId ?? getUUID(),
3861
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4017
+ declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4018
+ annotation: input.annotation ?? generateActionMetadataInput(
4019
+ tennisClubMembershipEvent,
4020
+ ActionType.DECLARE
4021
+ ),
3862
4022
  eventId
3863
4023
  }),
4024
+ /**
4025
+ * Notify allows sending incomplete data. Think it as 'partial declare' for now.
4026
+ */
4027
+ notify: (eventId, input = {}) => {
4028
+ let declaration = input.declaration;
4029
+ if (!declaration) {
4030
+ const partialDeclaration = (0, import_lodash2.omitBy)(
4031
+ generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4032
+ import_lodash2.isString
4033
+ );
4034
+ declaration = partialDeclaration;
4035
+ }
4036
+ return {
4037
+ type: ActionType.NOTIFY,
4038
+ transactionId: input.transactionId ?? getUUID(),
4039
+ declaration,
4040
+ eventId
4041
+ };
4042
+ },
3864
4043
  validate: (eventId, input = {}) => ({
3865
4044
  type: ActionType.VALIDATE,
3866
4045
  transactionId: input.transactionId ?? getUUID(),
3867
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4046
+ declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4047
+ annotation: input.annotation ?? generateActionMetadataInput(
4048
+ tennisClubMembershipEvent,
4049
+ ActionType.VALIDATE
4050
+ ),
3868
4051
  duplicates: [],
3869
4052
  eventId
3870
4053
  }),
4054
+ assign: (eventId, input = {}) => ({
4055
+ type: ActionType.ASSIGN,
4056
+ transactionId: input.transactionId ?? getUUID(),
4057
+ declaration: {},
4058
+ assignedTo: input.assignedTo ?? getUUID(),
4059
+ eventId
4060
+ }),
4061
+ unassign: (eventId, input = {}) => ({
4062
+ type: ActionType.UNASSIGN,
4063
+ transactionId: input.transactionId ?? getUUID(),
4064
+ declaration: {},
4065
+ assignedTo: null,
4066
+ eventId
4067
+ }),
3871
4068
  archive: (eventId, input = {}, isDuplicate) => ({
3872
4069
  type: ActionType.ARCHIVE,
3873
4070
  transactionId: input.transactionId ?? getUUID(),
3874
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.ARCHIVE),
3875
- metadata: { isDuplicate: isDuplicate ?? false },
4071
+ declaration: {},
4072
+ // @TODO: Check whether generator is needed?
4073
+ annotation: { isDuplicate: isDuplicate ?? false },
3876
4074
  duplicates: [],
3877
4075
  eventId
3878
4076
  }),
3879
4077
  reject: (eventId, input = {}) => ({
3880
4078
  type: ActionType.REJECT,
3881
4079
  transactionId: input.transactionId ?? getUUID(),
3882
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REJECT),
4080
+ declaration: {},
4081
+ annotation: input.annotation ?? generateActionMetadataInput(
4082
+ tennisClubMembershipEvent,
4083
+ ActionType.REJECT
4084
+ ),
3883
4085
  duplicates: [],
3884
4086
  eventId
3885
4087
  }),
3886
4088
  register: (eventId, input = {}) => ({
3887
4089
  type: ActionType.REGISTER,
3888
4090
  transactionId: input.transactionId ?? getUUID(),
3889
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4091
+ declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4092
+ annotation: input.annotation ?? generateActionMetadataInput(
4093
+ tennisClubMembershipEvent,
4094
+ ActionType.REGISTER
4095
+ ),
3890
4096
  eventId
3891
4097
  }),
3892
4098
  printCertificate: (eventId, input = {}) => ({
3893
4099
  type: ActionType.PRINT_CERTIFICATE,
3894
4100
  transactionId: input.transactionId ?? getUUID(),
3895
- data: input.data ?? generateActionInput(
3896
- tennisClubMembershipEvent,
3897
- ActionType.PRINT_CERTIFICATE
3898
- ),
3899
- metadata: input.metadata ?? generateActionMetadataInput(
4101
+ declaration: {},
4102
+ annotation: input.annotation ?? generateActionMetadataInput(
3900
4103
  tennisClubMembershipEvent,
3901
4104
  ActionType.PRINT_CERTIFICATE
3902
4105
  ),
@@ -3906,17 +4109,21 @@ var eventPayloadGenerator = {
3906
4109
  request: (eventId, input = {}) => ({
3907
4110
  type: ActionType.REQUEST_CORRECTION,
3908
4111
  transactionId: input.transactionId ?? getUUID(),
3909
- data: input.data ?? generateActionInput(
4112
+ declaration: input.declaration ?? generateActionInput(
4113
+ tennisClubMembershipEvent,
4114
+ ActionType.REQUEST_CORRECTION
4115
+ ),
4116
+ annotation: input.annotation ?? generateActionMetadataInput(
3910
4117
  tennisClubMembershipEvent,
3911
4118
  ActionType.REQUEST_CORRECTION
3912
4119
  ),
3913
- metadata: {},
3914
4120
  eventId
3915
4121
  }),
3916
4122
  approve: (eventId, requestId, input = {}) => ({
3917
4123
  type: ActionType.APPROVE_CORRECTION,
3918
4124
  transactionId: input.transactionId ?? getUUID(),
3919
- data: input.data ?? generateActionInput(
4125
+ declaration: {},
4126
+ annotation: input.annotation ?? generateActionMetadataInput(
3920
4127
  tennisClubMembershipEvent,
3921
4128
  ActionType.APPROVE_CORRECTION
3922
4129
  ),
@@ -3926,7 +4133,8 @@ var eventPayloadGenerator = {
3926
4133
  reject: (eventId, requestId, input = {}) => ({
3927
4134
  type: ActionType.REJECT_CORRECTION,
3928
4135
  transactionId: input.transactionId ?? getUUID(),
3929
- data: input.data ?? generateActionInput(
4136
+ declaration: {},
4137
+ annotation: input.annotation ?? generateActionMetadataInput(
3930
4138
  tennisClubMembershipEvent,
3931
4139
  ActionType.REJECT_CORRECTION
3932
4140
  ),
@@ -3948,11 +4156,16 @@ function generateActionDocument({
3948
4156
  createdBy: getUUID(),
3949
4157
  id: getUUID(),
3950
4158
  createdAtLocation: "TODO",
3951
- data: generateActionInput(configuration, action),
3952
- metadata: {},
3953
- ...defaults
4159
+ declaration: generateActionInput(configuration, action),
4160
+ annotation: {},
4161
+ ...defaults,
4162
+ status: ActionStatus.Accepted
3954
4163
  };
3955
4164
  switch (action) {
4165
+ case ActionType.READ:
4166
+ return { ...actionBase, type: action };
4167
+ case ActionType.MARKED_AS_DUPLICATE:
4168
+ return { ...actionBase, type: action };
3956
4169
  case ActionType.DECLARE:
3957
4170
  return { ...actionBase, type: action };
3958
4171
  case ActionType.UNASSIGN:
@@ -3977,14 +4190,13 @@ function generateActionDocument({
3977
4190
  return { ...actionBase, requestId: getUUID(), type: action };
3978
4191
  case ActionType.REJECT_CORRECTION:
3979
4192
  return { ...actionBase, requestId: getUUID(), type: action };
3980
- case ActionType.CUSTOM:
3981
- return { ...actionBase, type: action };
3982
4193
  case ActionType.REGISTER:
3983
4194
  return {
3984
4195
  ...actionBase,
3985
- type: action,
3986
- identifiers: { trackingId: getUUID(), registrationNumber: getUUID() }
4196
+ type: action
3987
4197
  };
4198
+ case ActionType.DELETE:
4199
+ case ActionType.DETECT_DUPLICATE:
3988
4200
  default:
3989
4201
  throw new Error(`Unsupported action type: ${action}`);
3990
4202
  }
@@ -4008,7 +4220,7 @@ function generateEventDocument({
4008
4220
  updatedAt: new Date(Date.now() - 1e3).toISOString()
4009
4221
  };
4010
4222
  }
4011
- function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, data = {}) {
4223
+ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
4012
4224
  const action = generateActionDocument({
4013
4225
  configuration: tennisClubMembershipEvent,
4014
4226
  action: actionType
@@ -4018,9 +4230,9 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, da
4018
4230
  transactionId: getUUID(),
4019
4231
  action: {
4020
4232
  ...action,
4021
- data: {
4022
- ...action.data,
4023
- ...data
4233
+ declaration: {
4234
+ ...action.declaration,
4235
+ ...declaration
4024
4236
  }
4025
4237
  },
4026
4238
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -4037,7 +4249,7 @@ var eventQueryDataGenerator = (overrides = {}) => ({
4037
4249
  modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4038
4250
  assignedTo: overrides.assignedTo ?? null,
4039
4251
  updatedBy: overrides.updatedBy ?? getUUID(),
4040
- data: overrides.data ?? {
4252
+ declaration: overrides.declaration ?? {
4041
4253
  "recommender.none": true,
4042
4254
  "applicant.firstname": "Danny",
4043
4255
  "applicant.surname": "Doe",
@@ -4068,7 +4280,9 @@ function isFieldValueWithoutTemplates(value) {
4068
4280
  return true;
4069
4281
  }
4070
4282
  function isFieldConfigDefaultValue(value) {
4071
- if (!value) return false;
4283
+ if (!value) {
4284
+ return false;
4285
+ }
4072
4286
  if (isFieldValue(value)) {
4073
4287
  return true;
4074
4288
  }