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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +1 -1
  2. package/dist/commons/api/router.d.ts +7079 -9746
  3. package/dist/commons/conditionals/conditionals.d.ts +26 -3
  4. package/dist/commons/conditionals/validate-address.test.d.ts +2 -0
  5. package/dist/commons/conditionals/validate.d.ts +39 -11
  6. package/dist/commons/conditionals/validate.test.d.ts +2 -0
  7. package/dist/commons/events/ActionConfig.d.ts +1116 -2067
  8. package/dist/commons/events/ActionDocument.d.ts +9482 -312
  9. package/dist/commons/events/ActionInput.d.ts +5244 -477
  10. package/dist/commons/events/ActionType.d.ts +25 -12
  11. package/dist/commons/events/CompositeFieldValue.d.ts +155 -2
  12. package/dist/commons/events/Conditional.d.ts +21 -5
  13. package/dist/commons/events/Draft.d.ts +348 -48
  14. package/dist/commons/events/EventConfig.d.ts +559 -1238
  15. package/dist/commons/events/EventConfigInput.d.ts +6 -3
  16. package/dist/commons/events/EventDocument.d.ts +3343 -429
  17. package/dist/commons/events/EventIndex.d.ts +9 -3
  18. package/dist/commons/events/EventMetadata.d.ts +6 -0
  19. package/dist/commons/events/FieldConfig.d.ts +527 -74
  20. package/dist/commons/events/FieldType.d.ts +6 -1
  21. package/dist/commons/events/FieldTypeMapping.d.ts +154 -3
  22. package/dist/commons/events/FieldValue.d.ts +76 -2
  23. package/dist/commons/events/FormConfig.d.ts +633 -48
  24. package/dist/commons/events/PageConfig.d.ts +335 -0
  25. package/dist/commons/events/TemplateConfig.d.ts +38 -0
  26. package/dist/commons/events/User.d.ts +5 -0
  27. package/dist/commons/events/defineConfig.d.ts +91 -222
  28. package/dist/commons/events/index.d.ts +3 -1
  29. package/dist/commons/events/test.utils.d.ts +140 -213
  30. package/dist/commons/events/utils.d.ts +188 -69
  31. package/dist/conditionals/index.js +166 -81
  32. package/dist/events/index.js +1441 -795
  33. package/package.json +1 -1
@@ -30,19 +30,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/events/index.ts
31
31
  var events_exports = {};
32
32
  __export(events_exports, {
33
+ Action: () => Action,
33
34
  ActionBase: () => ActionBase,
34
35
  ActionConditional: () => ActionConditional,
35
36
  ActionConfig: () => ActionConfig,
36
37
  ActionConfigBase: () => ActionConfigBase,
37
38
  ActionDocument: () => ActionDocument,
39
+ ActionFormConfig: () => ActionFormConfig,
38
40
  ActionInput: () => ActionInput,
41
+ ActionStatus: () => ActionStatus,
39
42
  ActionType: () => ActionType,
43
+ ActionTypes: () => ActionTypes,
40
44
  ActionUpdate: () => ActionUpdate,
41
45
  AddressFieldUpdateValue: () => AddressFieldUpdateValue,
42
46
  AddressFieldValue: () => AddressFieldValue,
47
+ AddressType: () => AddressType,
48
+ AdministrativeAreas: () => AdministrativeAreas,
43
49
  AdvancedSearchConfig: () => AdvancedSearchConfig,
44
50
  ApproveCorrectionActionInput: () => ApproveCorrectionActionInput,
45
- ArchivedActionInput: () => ArchivedActionInput,
51
+ ArchiveActionInput: () => ArchiveActionInput,
52
+ AssignActionInput: () => AssignActionInput,
53
+ AsyncRejectActionDocument: () => AsyncRejectActionDocument,
46
54
  BaseActionInput: () => BaseActionInput,
47
55
  CertificateConfig: () => CertificateConfig,
48
56
  CertificateTemplateConfig: () => CertificateTemplateConfig,
@@ -50,9 +58,18 @@ __export(events_exports, {
50
58
  Clause: () => Clause,
51
59
  Conditional: () => Conditional,
52
60
  ConditionalType: () => ConditionalType,
61
+ ConfirmableActions: () => ConfirmableActions,
62
+ DataEntry: () => DataEntry,
63
+ DataFieldValue: () => DataFieldValue,
53
64
  DateValue: () => DateValue,
65
+ DeclarationActionConfig: () => DeclarationActionConfig,
66
+ DeclarationActions: () => DeclarationActions,
67
+ DeclarationFormConfig: () => DeclarationFormConfig,
68
+ DeclarationReviewConfig: () => DeclarationReviewConfig,
69
+ DeclarationUpdateActions: () => DeclarationUpdateActions,
54
70
  DeclareActionInput: () => DeclareActionInput,
55
71
  DeduplicationConfig: () => DeduplicationConfig,
72
+ DisplayOnReviewConditional: () => DisplayOnReviewConditional,
56
73
  Draft: () => Draft,
57
74
  DraftInput: () => DraftInput,
58
75
  EmailField: () => EmailField,
@@ -66,6 +83,7 @@ __export(events_exports, {
66
83
  EventSearchIndex: () => EventSearchIndex,
67
84
  EventStatus: () => EventStatus,
68
85
  EventStatuses: () => EventStatuses,
86
+ FieldConditional: () => FieldConditional,
69
87
  FieldConfig: () => FieldConfig,
70
88
  FieldType: () => FieldType,
71
89
  FieldUpdateValue: () => FieldUpdateValue,
@@ -74,13 +92,21 @@ __export(events_exports, {
74
92
  FileFieldValueWithOption: () => FileFieldValueWithOption,
75
93
  FileFieldWithOptionValue: () => FileFieldWithOptionValue,
76
94
  FormConfig: () => FormConfig,
77
- FormPage: () => FormPage,
95
+ FormPageConfig: () => FormPageConfig,
96
+ GenericAddressUpdateValue: () => GenericAddressUpdateValue,
97
+ GenericAddressValue: () => GenericAddressValue,
78
98
  GeographicalArea: () => GeographicalArea,
99
+ ImageMimeType: () => ImageMimeType,
79
100
  LanguageConfig: () => LanguageConfig,
80
101
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
102
+ MimeType: () => MimeType,
81
103
  NotifyActionInput: () => NotifyActionInput,
82
104
  NumberFieldValue: () => NumberFieldValue,
105
+ PageConfig: () => PageConfig,
106
+ PageTypes: () => PageTypes,
83
107
  PrintCertificateActionInput: () => PrintCertificateActionInput,
108
+ ReadActionInput: () => ReadActionInput,
109
+ RegisterAction: () => RegisterAction,
84
110
  RegisterActionInput: () => RegisterActionInput,
85
111
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
86
112
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
@@ -93,19 +119,30 @@ __export(events_exports, {
93
119
  SummaryConfig: () => SummaryConfig,
94
120
  TextValue: () => TextValue,
95
121
  TranslationConfig: () => TranslationConfig,
122
+ UnassignActionInput: () => UnassignActionInput,
96
123
  UrbanAddressUpdateValue: () => UrbanAddressUpdateValue,
97
124
  UrbanAddressValue: () => UrbanAddressValue,
98
125
  ValidateActionInput: () => ValidateActionInput,
126
+ VerificationActionConfig: () => VerificationActionConfig,
127
+ VerificationPageConfig: () => VerificationPageConfig,
99
128
  WorkqueueConfig: () => WorkqueueConfig,
100
129
  alwaysTrue: () => alwaysTrue,
101
130
  and: () => and,
131
+ annotationActions: () => annotationActions,
102
132
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
133
+ compositeFieldTypes: () => compositeFieldTypes,
134
+ createEmptyDraft: () => createEmptyDraft,
103
135
  createValidationSchema: () => createValidationSchema,
104
136
  deepDropNulls: () => deepDropNulls,
137
+ deepMerge: () => deepMerge,
138
+ defineActionForm: () => defineActionForm,
105
139
  defineConditional: () => defineConditional,
106
140
  defineConfig: () => defineConfig,
107
- defineForm: () => defineForm,
141
+ defineDeclarationForm: () => defineDeclarationForm,
142
+ defineFormConditional: () => defineFormConditional,
108
143
  defineFormPage: () => defineFormPage,
144
+ definePage: () => definePage,
145
+ errorMessages: () => errorMessages,
109
146
  event: () => event,
110
147
  eventMetadataLabelMap: () => eventMetadataLabelMap,
111
148
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -113,36 +150,45 @@ __export(events_exports, {
113
150
  eventStatuses: () => eventStatuses,
114
151
  field: () => field,
115
152
  fieldTypes: () => fieldTypes,
116
- findActiveActionFields: () => findActiveActionFields,
117
- findActiveActionForm: () => findActiveActionForm,
118
- findActiveActionFormFields: () => findActiveActionFormFields,
119
- findActiveActionFormPages: () => findActiveActionFormPages,
120
- findInputPageFields: () => findInputPageFields,
121
- findPageFields: () => findPageFields,
153
+ findActiveDrafts: () => findActiveDrafts,
154
+ findAllFields: () => findAllFields,
155
+ findRecordActionPages: () => findRecordActionPages,
122
156
  generateActionDocument: () => generateActionDocument,
123
157
  generateActionInput: () => generateActionInput,
158
+ generateActionMetadataInput: () => generateActionMetadataInput,
124
159
  generateEventDocument: () => generateEventDocument,
125
160
  generateEventDraftDocument: () => generateEventDraftDocument,
126
161
  generateTransactionId: () => generateTransactionId,
127
- getActiveActionFields: () => getActiveActionFields,
128
- getAllFields: () => getAllFields,
129
- getAllPages: () => getAllPages,
162
+ generateTranslationConfig: () => generateTranslationConfig,
163
+ getAcceptedActions: () => getAcceptedActions,
164
+ getActionAnnotation: () => getActionAnnotation,
165
+ getActionAnnotationFields: () => getActionAnnotationFields,
166
+ getActionReview: () => getActionReview,
167
+ getActionReviewFields: () => getActionReviewFields,
168
+ getAllAnnotationFields: () => getAllAnnotationFields,
169
+ getAnnotationFromDrafts: () => getAnnotationFromDrafts,
130
170
  getCurrentEventState: () => getCurrentEventState,
131
171
  getCurrentEventStateWithDrafts: () => getCurrentEventStateWithDrafts,
132
- getEventConfiguration: () => getEventConfiguration,
172
+ getDeclaration: () => getDeclaration,
173
+ getDeclarationFields: () => getDeclarationFields,
174
+ getDeclarationPages: () => getDeclarationPages,
133
175
  getFieldValidationErrors: () => getFieldValidationErrors,
134
- getFormFields: () => getFormFields,
135
- getMetadataForAction: () => getMetadataForAction,
176
+ getVisiblePagesFormFields: () => getVisiblePagesFormFields,
136
177
  isAddressFieldType: () => isAddressFieldType,
137
178
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
138
179
  isBulletListFieldType: () => isBulletListFieldType,
139
180
  isCheckboxFieldType: () => isCheckboxFieldType,
140
181
  isCountryFieldType: () => isCountryFieldType,
182
+ isDataFieldType: () => isDataFieldType,
141
183
  isDateFieldType: () => isDateFieldType,
142
184
  isDividerFieldType: () => isDividerFieldType,
143
185
  isEmailFieldType: () => isEmailFieldType,
144
186
  isFacilityFieldType: () => isFacilityFieldType,
187
+ isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
188
+ isFieldDisplayedOnReview: () => isFieldDisplayedOnReview,
145
189
  isFieldEnabled: () => isFieldEnabled,
190
+ isFieldValue: () => isFieldValue,
191
+ isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
146
192
  isFieldVisible: () => isFieldVisible,
147
193
  isFileFieldType: () => isFileFieldType,
148
194
  isFileFieldWithOptionType: () => isFileFieldWithOptionType,
@@ -150,18 +196,22 @@ __export(events_exports, {
150
196
  isNumberFieldType: () => isNumberFieldType,
151
197
  isOfficeFieldType: () => isOfficeFieldType,
152
198
  isPageHeaderFieldType: () => isPageHeaderFieldType,
199
+ isPageVisible: () => isPageVisible,
153
200
  isParagraphFieldType: () => isParagraphFieldType,
154
201
  isRadioGroupFieldType: () => isRadioGroupFieldType,
155
202
  isSelectFieldType: () => isSelectFieldType,
156
203
  isSignatureFieldType: () => isSignatureFieldType,
204
+ isTemplateVariable: () => isTemplateVariable,
157
205
  isTextAreaFieldType: () => isTextAreaFieldType,
158
206
  isTextFieldType: () => isTextFieldType,
159
207
  isUndeclaredDraft: () => isUndeclaredDraft,
208
+ isVerificationPage: () => isVerificationPage,
209
+ mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
160
210
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
161
211
  mapFieldTypeToZod: () => mapFieldTypeToZod,
212
+ never: () => never,
162
213
  not: () => not,
163
214
  or: () => or,
164
- resolveLabelsFromKnownFields: () => resolveLabelsFromKnownFields,
165
215
  stripHiddenFields: () => stripHiddenFields,
166
216
  user: () => user,
167
217
  validate: () => validate,
@@ -171,35 +221,52 @@ __export(events_exports, {
171
221
  module.exports = __toCommonJS(events_exports);
172
222
 
173
223
  // ../commons/src/events/ActionConfig.ts
174
- var import_zod7 = require("zod");
224
+ var import_zod9 = require("zod");
175
225
 
176
226
  // ../commons/src/events/Conditional.ts
177
227
  var import_zod = require("zod");
178
- function Conditional() {
179
- return import_zod.z.custom((val) => typeof val === "object" && val !== null);
180
- }
228
+ var Conditional = import_zod.z.custom(
229
+ (val) => typeof val === "object" && val !== null
230
+ );
181
231
  var ConditionalType = {
182
- /** When 'SHOW' conditional is defined, the action is shown to the user only if the condition is met */
183
232
  SHOW: "SHOW",
184
- /** If 'ENABLE' conditional is defined, the action is enabled only if the condition is met */
185
- ENABLE: "ENABLE"
233
+ ENABLE: "ENABLE",
234
+ DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
186
235
  };
187
236
  var ShowConditional = import_zod.z.object({
188
237
  type: import_zod.z.literal(ConditionalType.SHOW),
189
- conditional: Conditional()
190
- });
238
+ conditional: Conditional
239
+ }).describe(
240
+ "If 'SHOW' conditional is defined, the component is shown to the user only if the condition is met"
241
+ );
191
242
  var EnableConditional = import_zod.z.object({
192
243
  type: import_zod.z.literal(ConditionalType.ENABLE),
193
- conditional: Conditional()
194
- });
244
+ conditional: Conditional
245
+ }).describe(
246
+ "If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
247
+ );
195
248
  var ActionConditional = import_zod.z.discriminatedUnion("type", [
196
249
  // Action can be shown / hidden
197
250
  ShowConditional,
198
251
  // Action can be shown to the user in the list but as disabled
199
252
  EnableConditional
200
253
  ]);
254
+ var DisplayOnReviewConditional = import_zod.z.object({
255
+ type: import_zod.z.literal(ConditionalType.DISPLAY_ON_REVIEW),
256
+ conditional: Conditional
257
+ }).describe(
258
+ "If 'DISPLAY_ON_REVIEW' conditional is defined, the component is shown on the review page only if both the 'DISPLAY_ON_REVIEW' and 'SHOW' conditions are met. This should only be used for fields within declaration forms, as they are the only ones with review pages."
259
+ );
260
+ var FieldConditional = import_zod.z.discriminatedUnion("type", [
261
+ // Field input can be shown / hidden
262
+ ShowConditional,
263
+ // Field input can be shown to the user but as disabled
264
+ EnableConditional,
265
+ // Field output can be shown / hidden on the review page
266
+ DisplayOnReviewConditional
267
+ ]);
201
268
 
202
- // ../commons/src/events/FormConfig.ts
269
+ // ../commons/src/events/PageConfig.ts
203
270
  var import_zod6 = require("zod");
204
271
 
205
272
  // ../commons/src/events/FieldConfig.ts
@@ -240,9 +307,15 @@ var FieldType = {
240
307
  ADMINISTRATIVE_AREA: "ADMINISTRATIVE_AREA",
241
308
  FACILITY: "FACILITY",
242
309
  OFFICE: "OFFICE",
243
- SIGNATURE: "SIGNATURE"
310
+ SIGNATURE: "SIGNATURE",
311
+ DATA: "DATA"
244
312
  };
245
313
  var fieldTypes = Object.values(FieldType);
314
+ var compositeFieldTypes = [
315
+ FieldType.ADDRESS,
316
+ FieldType.FILE_WITH_OPTIONS,
317
+ FieldType.FILE
318
+ ];
246
319
 
247
320
  // ../commons/src/events/FieldValue.ts
248
321
  var import_zod4 = require("zod");
@@ -253,6 +326,10 @@ var GeographicalArea = {
253
326
  URBAN: "URBAN",
254
327
  RURAL: "RURAL"
255
328
  };
329
+ var AddressType = {
330
+ DOMESTIC: "DOMESTIC",
331
+ INTERNATIONAL: "INTERNATIONAL"
332
+ };
256
333
  var FileFieldValue = import_zod3.z.object({
257
334
  filename: import_zod3.z.string(),
258
335
  originalFilename: import_zod3.z.string(),
@@ -260,6 +337,7 @@ var FileFieldValue = import_zod3.z.object({
260
337
  });
261
338
  var AdminStructure = import_zod3.z.object({
262
339
  country: import_zod3.z.string(),
340
+ addressType: import_zod3.z.literal(AddressType.DOMESTIC),
263
341
  province: import_zod3.z.string(),
264
342
  district: import_zod3.z.string()
265
343
  });
@@ -287,14 +365,33 @@ var RuralAddressUpdateValue = AdminStructure.extend({
287
365
  urbanOrRural: import_zod3.z.literal(GeographicalArea.RURAL),
288
366
  village: import_zod3.z.string().nullish()
289
367
  });
290
- var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
291
- UrbanAddressValue,
292
- RuralAddressValue
293
- ]);
368
+ var GenericAddressValue = import_zod3.z.object({
369
+ country: import_zod3.z.string(),
370
+ addressType: import_zod3.z.literal(AddressType.INTERNATIONAL),
371
+ state: import_zod3.z.string(),
372
+ district2: import_zod3.z.string(),
373
+ cityOrTown: import_zod3.z.string().optional(),
374
+ addressLine1: import_zod3.z.string().optional(),
375
+ addressLine2: import_zod3.z.string().optional(),
376
+ addressLine3: import_zod3.z.string().optional(),
377
+ postcodeOrZip: import_zod3.z.string().optional()
378
+ });
379
+ var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [UrbanAddressValue, RuralAddressValue]).or(GenericAddressValue);
380
+ var GenericAddressUpdateValue = import_zod3.z.object({
381
+ country: import_zod3.z.string(),
382
+ addressType: import_zod3.z.literal(AddressType.INTERNATIONAL),
383
+ state: import_zod3.z.string(),
384
+ district2: import_zod3.z.string(),
385
+ cityOrTown: import_zod3.z.string().nullish(),
386
+ addressLine1: import_zod3.z.string().nullish(),
387
+ addressLine2: import_zod3.z.string().nullish(),
388
+ addressLine3: import_zod3.z.string().nullish(),
389
+ postcodeOrZip: import_zod3.z.string().nullish()
390
+ });
294
391
  var AddressFieldUpdateValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
295
392
  UrbanAddressUpdateValue,
296
393
  RuralAddressUpdateValue
297
- ]);
394
+ ]).or(GenericAddressUpdateValue);
298
395
  var FileFieldValueWithOption = import_zod3.z.object({
299
396
  filename: import_zod3.z.string(),
300
397
  originalFilename: import_zod3.z.string(),
@@ -310,6 +407,7 @@ var DateValue = import_zod4.z.string().date().describe("Date in the format YYYY-
310
407
  var EmailValue = import_zod4.z.string().email();
311
408
  var CheckboxFieldValue = import_zod4.z.boolean();
312
409
  var NumberFieldValue = import_zod4.z.number();
410
+ var DataFieldValue = import_zod4.z.undefined();
313
411
  var FieldValue = import_zod4.z.union([
314
412
  TextValue,
315
413
  DateValue,
@@ -318,7 +416,9 @@ var FieldValue = import_zod4.z.union([
318
416
  FileFieldValue,
319
417
  FileFieldWithOptionValue,
320
418
  UrbanAddressValue,
321
- RuralAddressValue
419
+ RuralAddressValue,
420
+ DataFieldValue,
421
+ GenericAddressValue
322
422
  ]);
323
423
  var FieldUpdateValue = import_zod4.z.union([
324
424
  TextValue,
@@ -328,7 +428,9 @@ var FieldUpdateValue = import_zod4.z.union([
328
428
  FileFieldValue,
329
429
  FileFieldWithOptionValue,
330
430
  UrbanAddressUpdateValue,
331
- RuralAddressUpdateValue
431
+ RuralAddressUpdateValue,
432
+ DataFieldValue,
433
+ GenericAddressUpdateValue
332
434
  ]);
333
435
 
334
436
  // ../commons/src/events/FieldConfig.ts
@@ -350,14 +452,14 @@ var BaseField = import_zod5.z.object({
350
452
  ]),
351
453
  DependencyExpression
352
454
  ]).optional(),
353
- conditionals: import_zod5.z.array(ActionConditional).default([]).optional(),
455
+ conditionals: import_zod5.z.array(FieldConditional).default([]).optional(),
354
456
  required: import_zod5.z.boolean().default(false).optional(),
355
457
  disabled: import_zod5.z.boolean().default(false).optional(),
356
458
  hidden: import_zod5.z.boolean().default(false).optional(),
357
459
  placeholder: TranslationConfig.optional(),
358
460
  validation: import_zod5.z.array(
359
461
  import_zod5.z.object({
360
- validator: Conditional(),
462
+ validator: Conditional,
361
463
  message: TranslationConfig
362
464
  })
363
465
  ).default([]).optional(),
@@ -399,15 +501,25 @@ var TextAreaField = BaseField.extend({
399
501
  postfix: TranslationConfig.optional()
400
502
  }).default({ rows: 4 }).optional()
401
503
  }).describe("Multiline text input");
504
+ var ImageMimeType = import_zod5.z.enum([
505
+ "image/png",
506
+ "image/jpg",
507
+ "image/jpeg",
508
+ "image/svg+xml"
509
+ ]);
510
+ var MimeType = ImageMimeType;
511
+ var DEFAULT_MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
402
512
  var SignatureField = BaseField.extend({
403
513
  type: import_zod5.z.literal(FieldType.SIGNATURE),
404
514
  signaturePromptLabel: TranslationConfig.describe(
405
515
  "Title of the signature modal"
406
516
  ),
407
517
  configuration: import_zod5.z.object({
408
- maxSizeMb: import_zod5.z.number().optional().describe("Maximum file size in MB"),
409
- allowedFileFormats: import_zod5.z.array(import_zod5.z.string()).optional().describe("List of allowed file formats for the signature")
410
- }).default({}).optional()
518
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
519
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
520
+ }).default({
521
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
522
+ })
411
523
  }).describe("Signature input field");
412
524
  var EmailField = BaseField.extend({
413
525
  type: import_zod5.z.literal(FieldType.EMAIL),
@@ -450,13 +562,17 @@ var PageHeader = BaseField.extend({
450
562
  }).describe("A read-only header component for form pages");
451
563
  var File = BaseField.extend({
452
564
  type: import_zod5.z.literal(FieldType.FILE),
453
- options: import_zod5.z.object({
565
+ configuration: import_zod5.z.object({
566
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
567
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
454
568
  style: import_zod5.z.object({
455
- fullWidth: import_zod5.z.boolean().describe(
569
+ width: import_zod5.z.enum(["full", "auto"]).optional().describe(
456
570
  "Whether the file upload button should take the full width of the container or not"
457
571
  )
458
- })
459
- }).optional()
572
+ }).optional()
573
+ }).default({
574
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
575
+ })
460
576
  }).describe("File upload");
461
577
  var SelectOption = import_zod5.z.object({
462
578
  value: import_zod5.z.string().describe("The value of the option"),
@@ -495,11 +611,16 @@ var Country = BaseField.extend({
495
611
  type: import_zod5.z.literal(FieldType.COUNTRY),
496
612
  defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
497
613
  }).describe("Country select field");
614
+ var AdministrativeAreas = import_zod5.z.enum([
615
+ "ADMIN_STRUCTURE",
616
+ "HEALTH_FACILITY",
617
+ "CRVS_OFFICE"
618
+ ]);
498
619
  var AdministrativeAreaConfiguration = import_zod5.z.object({
499
620
  partOf: import_zod5.z.object({
500
- $data: import_zod5.z.string()
621
+ $declaration: import_zod5.z.string()
501
622
  }).optional().describe("Parent location"),
502
- type: import_zod5.z.enum(["ADMIN_STRUCTURE", "HEALTH_FACILITY", "CRVS_OFFICE"])
623
+ type: AdministrativeAreas
503
624
  }).describe("Administrative area options");
504
625
  var AdministrativeArea = BaseField.extend({
505
626
  type: import_zod5.z.literal(FieldType.ADMINISTRATIVE_AREA),
@@ -512,8 +633,14 @@ var Location = BaseField.extend({
512
633
  }).describe("Input field for a location");
513
634
  var FileUploadWithOptions = BaseField.extend({
514
635
  type: import_zod5.z.literal(FieldType.FILE_WITH_OPTIONS),
515
- options: import_zod5.z.array(SelectOption).describe("A list of options")
516
- }).describe("Select input");
636
+ options: import_zod5.z.array(SelectOption).describe("A list of options"),
637
+ configuration: import_zod5.z.object({
638
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
639
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
640
+ }).default({
641
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
642
+ })
643
+ });
517
644
  var Facility = BaseField.extend({
518
645
  type: import_zod5.z.literal(FieldType.FACILITY),
519
646
  defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
@@ -526,6 +653,22 @@ var Address = BaseField.extend({
526
653
  type: import_zod5.z.literal(FieldType.ADDRESS),
527
654
  defaultValue: AddressFieldValue.optional()
528
655
  }).describe("Address input field \u2013 a combination of location and text fields");
656
+ var DataEntry = import_zod5.z.union([
657
+ import_zod5.z.object({
658
+ label: TranslationConfig,
659
+ value: import_zod5.z.string()
660
+ }),
661
+ import_zod5.z.object({
662
+ fieldId: import_zod5.z.string()
663
+ })
664
+ ]);
665
+ var DataField = BaseField.extend({
666
+ type: import_zod5.z.literal(FieldType.DATA),
667
+ configuration: import_zod5.z.object({
668
+ subtitle: TranslationConfig.optional(),
669
+ data: import_zod5.z.array(DataEntry)
670
+ })
671
+ }).describe("Data field for displaying read-only data");
529
672
  var FieldConfig = import_zod5.z.discriminatedUnion("type", [
530
673
  Address,
531
674
  TextField,
@@ -547,244 +690,316 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
547
690
  Office,
548
691
  SignatureField,
549
692
  EmailField,
550
- FileUploadWithOptions
693
+ FileUploadWithOptions,
694
+ DataField
695
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
551
696
  ]);
552
697
 
553
- // ../commons/src/events/FormConfig.ts
554
- var FormPage = import_zod6.z.object({
698
+ // ../commons/src/events/PageConfig.ts
699
+ var PageTypes = import_zod6.z.enum(["FORM", "VERIFICATION"]);
700
+ var PageConfigBase = import_zod6.z.object({
555
701
  id: import_zod6.z.string().describe("Unique identifier for the page"),
556
702
  title: TranslationConfig.describe("Header title of the page"),
557
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page")
703
+ fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page"),
704
+ conditional: Conditional.optional().describe(
705
+ "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
706
+ )
558
707
  });
559
- var FormConfig = import_zod6.z.object({
560
- label: TranslationConfig.describe("Human readable description of the form"),
561
- version: import_zod6.z.object({
562
- id: import_zod6.z.string().describe(
563
- "Form version. Semantic versioning recommended. Example: 0.0.1"
564
- ),
565
- label: TranslationConfig.describe(
566
- "Human readable description of the version"
567
- )
568
- }),
569
- active: import_zod6.z.boolean().default(false).describe("Whether the form is active"),
570
- pages: import_zod6.z.array(FormPage),
571
- review: import_zod6.z.object({
572
- title: TranslationConfig.describe(
573
- "Title of the form to show in review page"
574
- ),
575
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the review page for metadata")
708
+ var FormPageConfig = PageConfigBase.extend({
709
+ type: import_zod6.z.literal(PageTypes.enum.FORM).default(PageTypes.enum.FORM)
710
+ });
711
+ var VerificationActionConfig = import_zod6.z.object({
712
+ verify: import_zod6.z.object({ label: TranslationConfig }),
713
+ cancel: import_zod6.z.object({
714
+ label: TranslationConfig,
715
+ confirmation: import_zod6.z.object({
716
+ title: TranslationConfig,
717
+ body: TranslationConfig
718
+ })
576
719
  })
720
+ }).describe("Actions available on the verification page");
721
+ var VerificationPageConfig = FormPageConfig.extend({
722
+ type: import_zod6.z.literal(PageTypes.enum.VERIFICATION),
723
+ actions: VerificationActionConfig
577
724
  });
725
+ var PageConfig = import_zod6.z.discriminatedUnion("type", [
726
+ FormPageConfig,
727
+ VerificationPageConfig
728
+ ]);
578
729
 
579
730
  // ../commons/src/events/ActionType.ts
731
+ var import_zod7 = require("zod");
580
732
  var ActionType = {
733
+ // Pre-declaration actions
734
+ DELETE: "DELETE",
581
735
  CREATE: "CREATE",
582
- ASSIGN: "ASSIGN",
583
- UNASSIGN: "UNASSIGN",
584
- REGISTER: "REGISTER",
585
- VALIDATE: "VALIDATE",
586
- REQUEST_CORRECTION: "REQUEST_CORRECTION",
587
- REJECT_CORRECTION: "REJECT_CORRECTION",
588
- APPROVE_CORRECTION: "APPROVE_CORRECTION",
589
- DETECT_DUPLICATE: "DETECT_DUPLICATE",
590
736
  NOTIFY: "NOTIFY",
737
+ // Declaration actions
591
738
  DECLARE: "DECLARE",
592
- DELETE: "DELETE",
593
- PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
594
- CUSTOM: "CUSTOM",
739
+ VALIDATE: "VALIDATE",
740
+ REGISTER: "REGISTER",
741
+ // Declaration system actions. Non-configurable.
742
+ DETECT_DUPLICATE: "DETECT_DUPLICATE",
595
743
  REJECT: "REJECT",
744
+ // REJECT_DECLARATION
596
745
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
597
- ARCHIVED: "ARCHIVED"
746
+ // MARK_AS_DUPLICATE
747
+ ARCHIVE: "ARCHIVE",
748
+ // Record actions
749
+ PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
750
+ REQUEST_CORRECTION: "REQUEST_CORRECTION",
751
+ REJECT_CORRECTION: "REJECT_CORRECTION",
752
+ APPROVE_CORRECTION: "APPROVE_CORRECTION",
753
+ // General actions
754
+ READ: "READ",
755
+ ASSIGN: "ASSIGN",
756
+ UNASSIGN: "UNASSIGN"
598
757
  };
758
+ var ConfirmableActions = [
759
+ ActionType.NOTIFY,
760
+ ActionType.DECLARE,
761
+ ActionType.VALIDATE,
762
+ ActionType.REGISTER,
763
+ ActionType.REJECT,
764
+ ActionType.ARCHIVE,
765
+ ActionType.PRINT_CERTIFICATE
766
+ ];
767
+ var ActionTypes = import_zod7.z.enum([
768
+ "DELETE",
769
+ "CREATE",
770
+ "NOTIFY",
771
+ "DECLARE",
772
+ "VALIDATE",
773
+ "REGISTER",
774
+ "DETECT_DUPLICATE",
775
+ "REJECT",
776
+ "MARKED_AS_DUPLICATE",
777
+ "ARCHIVE",
778
+ "PRINT_CERTIFICATE",
779
+ "REQUEST_CORRECTION",
780
+ "REJECT_CORRECTION",
781
+ "APPROVE_CORRECTION",
782
+ "READ",
783
+ "ASSIGN",
784
+ "UNASSIGN"
785
+ ]);
786
+ var declarationActionValues = [
787
+ ActionTypes.enum.DECLARE,
788
+ ActionTypes.enum.VALIDATE,
789
+ ActionTypes.enum.REGISTER
790
+ ];
791
+ var DeclarationActions = ActionTypes.extract(declarationActionValues);
792
+ var declarationUpdateActionValues = [
793
+ ...declarationActionValues,
794
+ ActionTypes.enum.REQUEST_CORRECTION
795
+ ];
796
+ var DeclarationUpdateActions = ActionTypes.extract(
797
+ declarationUpdateActionValues
798
+ );
799
+ var annotationActions = ActionTypes.exclude(declarationActionValues);
800
+
801
+ // ../commons/src/events/FormConfig.ts
802
+ var import_zod8 = require("zod");
803
+ var DeclarationFormConfig = import_zod8.z.object({
804
+ label: TranslationConfig.describe("Human readable description of the form"),
805
+ pages: import_zod8.z.array(FormPageConfig)
806
+ }).describe("Configuration for a declaration form");
807
+ var ActionFormConfig = import_zod8.z.object({
808
+ label: TranslationConfig.describe("Human readable description of the form"),
809
+ pages: import_zod8.z.array(PageConfig)
810
+ });
811
+ var FormConfig = import_zod8.z.union([DeclarationFormConfig, ActionFormConfig]);
599
812
 
600
813
  // ../commons/src/events/ActionConfig.ts
601
- var ActionConditional2 = import_zod7.z.discriminatedUnion("type", [
814
+ var ActionConditional2 = import_zod9.z.discriminatedUnion("type", [
602
815
  /** If conditional is defined, the action is shown to the user only if the condition is met */
603
816
  ShowConditional,
604
817
  /** If conditional is defined, the action is enabled only if the condition is met */
605
818
  EnableConditional
606
819
  ]);
607
- var ActionConfigBase = import_zod7.z.object({
820
+ var DeclarationReviewConfig = import_zod9.z.object({
821
+ title: TranslationConfig.describe("Title of the review page"),
822
+ fields: import_zod9.z.array(FieldConfig).describe("Fields to be rendered on the review page for annotations.")
823
+ }).describe("Configuration for **declaration** review page.");
824
+ var ActionConfigBase = import_zod9.z.object({
608
825
  label: TranslationConfig,
609
- conditionals: import_zod7.z.array(ActionConditional2).optional().default([]),
610
- draft: import_zod7.z.boolean().optional(),
611
- forms: import_zod7.z.array(FormConfig)
826
+ conditionals: import_zod9.z.array(ActionConditional2).optional().default([]),
827
+ draft: import_zod9.z.boolean().optional()
612
828
  });
613
829
  var DeclareConfig = ActionConfigBase.merge(
614
- import_zod7.z.object({
615
- type: import_zod7.z.literal(ActionType.DECLARE)
830
+ import_zod9.z.object({
831
+ type: import_zod9.z.literal(ActionType.DECLARE),
832
+ review: DeclarationReviewConfig
616
833
  })
617
834
  );
618
835
  var ValidateConfig = ActionConfigBase.merge(
619
- import_zod7.z.object({
620
- type: import_zod7.z.literal(ActionType.VALIDATE)
836
+ import_zod9.z.object({
837
+ type: import_zod9.z.literal(ActionType.VALIDATE),
838
+ review: DeclarationReviewConfig
621
839
  })
622
840
  );
623
- var RejectDeclarationConfig = ActionConfigBase.merge(
624
- import_zod7.z.object({
625
- type: import_zod7.z.literal(ActionType.REJECT),
626
- comment: import_zod7.z.string(),
627
- isDuplicate: import_zod7.z.boolean()
841
+ var RegisterConfig = ActionConfigBase.merge(
842
+ import_zod9.z.object({
843
+ type: import_zod9.z.literal(ActionType.REGISTER),
844
+ review: DeclarationReviewConfig
628
845
  })
629
846
  );
630
- var MarkedAsDuplicateConfig = ActionConfigBase.merge(
631
- import_zod7.z.object({
632
- type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE),
633
- comment: import_zod7.z.string(),
634
- duplicates: import_zod7.z.array(import_zod7.z.string()).describe("UUIDs of duplicate records")
847
+ var RejectDeclarationConfig = ActionConfigBase.merge(
848
+ import_zod9.z.object({
849
+ type: import_zod9.z.literal(ActionType.REJECT)
635
850
  })
636
851
  );
637
- var ArchivedConfig = ActionConfigBase.merge(
638
- import_zod7.z.object({
639
- type: import_zod7.z.literal(ActionType.ARCHIVED),
640
- comment: import_zod7.z.string(),
641
- isDuplicate: import_zod7.z.boolean()
852
+ var MarkedAsDuplicateConfig = ActionConfigBase.merge(
853
+ import_zod9.z.object({
854
+ type: import_zod9.z.literal(ActionType.MARKED_AS_DUPLICATE)
642
855
  })
643
856
  );
644
- var RegisterConfig = ActionConfigBase.merge(
645
- import_zod7.z.object({
646
- type: import_zod7.z.literal(ActionType.REGISTER)
857
+ var ArchiveConfig = ActionConfigBase.merge(
858
+ import_zod9.z.object({
859
+ type: import_zod9.z.literal(ActionType.ARCHIVE)
647
860
  })
648
861
  );
649
862
  var DeleteConfig = ActionConfigBase.merge(
650
- import_zod7.z.object({
651
- type: import_zod7.z.literal(ActionType.DELETE)
863
+ import_zod9.z.object({
864
+ type: import_zod9.z.literal(ActionType.DELETE)
652
865
  })
653
866
  );
654
867
  var PrintCertificateActionConfig = ActionConfigBase.merge(
655
- import_zod7.z.object({
656
- type: import_zod7.z.literal(ActionType.PRINT_CERTIFICATE)
868
+ import_zod9.z.object({
869
+ type: import_zod9.z.literal(ActionType.PRINT_CERTIFICATE),
870
+ printForm: ActionFormConfig
657
871
  })
658
872
  );
659
873
  var RequestCorrectionConfig = ActionConfigBase.merge(
660
- import_zod7.z.object({
661
- type: import_zod7.z.literal(ActionType.REQUEST_CORRECTION),
662
- onboardingForm: import_zod7.z.array(FormPage),
663
- additionalDetailsForm: import_zod7.z.array(FormPage)
874
+ import_zod9.z.object({
875
+ type: import_zod9.z.literal(ActionType.REQUEST_CORRECTION),
876
+ onboardingForm: import_zod9.z.array(PageConfig),
877
+ additionalDetailsForm: import_zod9.z.array(PageConfig)
664
878
  })
665
879
  );
666
880
  var RejectCorrectionConfig = ActionConfigBase.merge(
667
- import_zod7.z.object({
668
- type: import_zod7.z.literal(ActionType.REJECT_CORRECTION)
881
+ import_zod9.z.object({
882
+ type: import_zod9.z.literal(ActionType.REJECT_CORRECTION)
669
883
  })
670
884
  );
671
885
  var ApproveCorrectionConfig = ActionConfigBase.merge(
672
- import_zod7.z.object({
673
- type: import_zod7.z.literal(ActionType.APPROVE_CORRECTION)
886
+ import_zod9.z.object({
887
+ type: import_zod9.z.literal(ActionType.APPROVE_CORRECTION)
674
888
  })
675
889
  );
676
- var CustomConfig = ActionConfigBase.merge(
677
- import_zod7.z.object({
678
- type: import_zod7.z.literal(ActionType.CUSTOM)
679
- })
680
- );
681
- var ActionConfig = import_zod7.z.discriminatedUnion("type", [
890
+ var ActionConfig = import_zod9.z.discriminatedUnion("type", [
682
891
  DeclareConfig,
683
892
  ValidateConfig,
684
893
  RejectDeclarationConfig,
685
894
  MarkedAsDuplicateConfig,
686
- ArchivedConfig,
895
+ ArchiveConfig,
687
896
  RegisterConfig,
688
897
  DeleteConfig,
689
898
  PrintCertificateActionConfig,
690
899
  RequestCorrectionConfig,
691
900
  RejectCorrectionConfig,
692
- ApproveCorrectionConfig,
693
- CustomConfig
901
+ ApproveCorrectionConfig
902
+ ]);
903
+ var DeclarationActionConfig = import_zod9.z.discriminatedUnion("type", [
904
+ DeclareConfig,
905
+ ValidateConfig,
906
+ RegisterConfig
694
907
  ]);
695
908
 
696
909
  // ../commons/src/events/offline/CertificateConfig.ts
697
- var import_zod8 = require("zod");
698
- var FontFamily = import_zod8.z.object({
699
- normal: import_zod8.z.string(),
700
- bold: import_zod8.z.string(),
701
- italics: import_zod8.z.string(),
702
- bolditalics: import_zod8.z.string()
910
+ var import_zod10 = require("zod");
911
+ var FontFamily = import_zod10.z.object({
912
+ normal: import_zod10.z.string(),
913
+ bold: import_zod10.z.string(),
914
+ italics: import_zod10.z.string(),
915
+ bolditalics: import_zod10.z.string()
703
916
  });
704
- var CertificateConfig = import_zod8.z.object({
705
- id: import_zod8.z.string(),
706
- event: import_zod8.z.string(),
917
+ var CertificateConfig = import_zod10.z.object({
918
+ id: import_zod10.z.string(),
919
+ event: import_zod10.z.string(),
707
920
  label: TranslationConfig,
708
- isDefault: import_zod8.z.boolean(),
709
- fee: import_zod8.z.object({
710
- onTime: import_zod8.z.number(),
711
- late: import_zod8.z.number(),
712
- delayed: import_zod8.z.number()
921
+ isDefault: import_zod10.z.boolean(),
922
+ fee: import_zod10.z.object({
923
+ onTime: import_zod10.z.number(),
924
+ late: import_zod10.z.number(),
925
+ delayed: import_zod10.z.number()
713
926
  }),
714
- svgUrl: import_zod8.z.string(),
715
- fonts: import_zod8.z.record(FontFamily).optional()
927
+ svgUrl: import_zod10.z.string(),
928
+ fonts: import_zod10.z.record(FontFamily).optional()
716
929
  });
717
930
  var CertificateTemplateConfig = CertificateConfig.extend({
718
- hash: import_zod8.z.string().optional(),
719
- svg: import_zod8.z.string()
931
+ hash: import_zod10.z.string().optional(),
932
+ svg: import_zod10.z.string()
720
933
  });
721
934
 
722
935
  // ../commons/src/events/offline/LanguageConfig.ts
723
- var import_zod9 = require("zod");
724
- var LanguageConfig = import_zod9.z.object({
725
- lang: import_zod9.z.string(),
936
+ var import_zod11 = require("zod");
937
+ var LanguageConfig = import_zod11.z.object({
938
+ lang: import_zod11.z.string(),
726
939
  /**
727
940
  * client.csv contents
728
941
  */
729
- messages: import_zod9.z.record(import_zod9.z.string())
942
+ messages: import_zod11.z.record(import_zod11.z.string())
730
943
  });
731
944
 
732
945
  // ../commons/src/events/EventConfig.ts
733
- var import_zod18 = require("zod");
946
+ var import_zod20 = require("zod");
734
947
 
735
948
  // ../commons/src/events/DeduplicationConfig.ts
736
- var import_zod10 = require("zod");
737
- var FieldReference = import_zod10.z.string();
738
- var Matcher = import_zod10.z.object({
739
- fieldId: import_zod10.z.string(),
740
- options: import_zod10.z.object({
741
- boost: import_zod10.z.number().optional()
949
+ var import_zod12 = require("zod");
950
+ var FieldReference = import_zod12.z.string();
951
+ var Matcher = import_zod12.z.object({
952
+ fieldId: import_zod12.z.string(),
953
+ options: import_zod12.z.object({
954
+ boost: import_zod12.z.number().optional()
742
955
  }).optional().default({})
743
956
  });
744
957
  var FuzzyMatcher = Matcher.extend({
745
- type: import_zod10.z.literal("fuzzy"),
746
- options: import_zod10.z.object({
958
+ type: import_zod12.z.literal("fuzzy"),
959
+ options: import_zod12.z.object({
747
960
  /**
748
961
  * Names of length 3 or less characters = 0 edits allowed
749
962
  * Names of length 4 - 6 characters = 1 edit allowed
750
963
  * Names of length >7 characters = 2 edits allowed
751
964
  */
752
- fuzziness: import_zod10.z.union([import_zod10.z.string(), import_zod10.z.number()]).optional().default("AUTO:4,7"),
753
- boost: import_zod10.z.number().optional().default(1)
965
+ fuzziness: import_zod12.z.union([import_zod12.z.string(), import_zod12.z.number()]).optional().default("AUTO:4,7"),
966
+ boost: import_zod12.z.number().optional().default(1)
754
967
  }).optional().default({})
755
968
  });
756
969
  var StrictMatcher = Matcher.extend({
757
- type: import_zod10.z.literal("strict"),
758
- options: import_zod10.z.object({
759
- boost: import_zod10.z.number().optional().default(1)
970
+ type: import_zod12.z.literal("strict"),
971
+ options: import_zod12.z.object({
972
+ boost: import_zod12.z.number().optional().default(1)
760
973
  }).optional().default({})
761
974
  });
762
975
  var DateRangeMatcher = Matcher.extend({
763
- type: import_zod10.z.literal("dateRange"),
764
- options: import_zod10.z.object({
765
- days: import_zod10.z.number(),
976
+ type: import_zod12.z.literal("dateRange"),
977
+ options: import_zod12.z.object({
978
+ days: import_zod12.z.number(),
766
979
  origin: FieldReference,
767
- boost: import_zod10.z.number().optional().default(1)
980
+ boost: import_zod12.z.number().optional().default(1)
768
981
  })
769
982
  });
770
983
  var DateDistanceMatcher = Matcher.extend({
771
- type: import_zod10.z.literal("dateDistance"),
772
- options: import_zod10.z.object({
773
- days: import_zod10.z.number(),
984
+ type: import_zod12.z.literal("dateDistance"),
985
+ options: import_zod12.z.object({
986
+ days: import_zod12.z.number(),
774
987
  origin: FieldReference,
775
- boost: import_zod10.z.number().optional().default(1)
988
+ boost: import_zod12.z.number().optional().default(1)
776
989
  })
777
990
  });
778
- var And = import_zod10.z.object({
779
- type: import_zod10.z.literal("and"),
780
- clauses: import_zod10.z.lazy(() => Clause.array())
991
+ var And = import_zod12.z.object({
992
+ type: import_zod12.z.literal("and"),
993
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
994
+ clauses: import_zod12.z.lazy(() => Clause.array())
781
995
  });
782
- var Or = import_zod10.z.object({
783
- type: import_zod10.z.literal("or"),
784
- clauses: import_zod10.z.lazy(() => Clause.array())
996
+ var Or = import_zod12.z.object({
997
+ type: import_zod12.z.literal("or"),
998
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
999
+ clauses: import_zod12.z.lazy(() => Clause.array())
785
1000
  });
786
- var Clause = import_zod10.z.lazy(
787
- () => import_zod10.z.discriminatedUnion("type", [
1001
+ var Clause = import_zod12.z.lazy(
1002
+ () => import_zod12.z.discriminatedUnion("type", [
788
1003
  And,
789
1004
  Or,
790
1005
  FuzzyMatcher,
@@ -793,37 +1008,37 @@ var Clause = import_zod10.z.lazy(
793
1008
  DateDistanceMatcher
794
1009
  ])
795
1010
  );
796
- var DeduplicationConfig = import_zod10.z.object({
797
- id: import_zod10.z.string(),
1011
+ var DeduplicationConfig = import_zod12.z.object({
1012
+ id: import_zod12.z.string(),
798
1013
  label: TranslationConfig,
799
1014
  query: Clause
800
1015
  });
801
1016
 
802
1017
  // ../commons/src/events/SummaryConfig.ts
803
- var import_zod11 = require("zod");
804
- var Field = import_zod11.z.object({
805
- id: import_zod11.z.string().describe("Id of summary field"),
1018
+ var import_zod13 = require("zod");
1019
+ var Field = import_zod13.z.object({
1020
+ id: import_zod13.z.string().describe("Id of summary field"),
806
1021
  value: TranslationConfig.describe(
807
1022
  "Summary field value. Can utilise values defined in configuration and EventMetadata"
808
1023
  ),
809
1024
  label: TranslationConfig,
810
1025
  emptyValueMessage: TranslationConfig.optional()
811
1026
  });
812
- var Title = import_zod11.z.object({
813
- id: import_zod11.z.string(),
1027
+ var Title = import_zod13.z.object({
1028
+ id: import_zod13.z.string(),
814
1029
  label: TranslationConfig.describe("Title content"),
815
1030
  emptyValueMessage: TranslationConfig.optional()
816
1031
  });
817
- var SummaryConfig = import_zod11.z.object({
1032
+ var SummaryConfig = import_zod13.z.object({
818
1033
  title: Title.describe("Title of summary view."),
819
- fields: import_zod11.z.array(Field).describe("Fields rendered in summary view.")
1034
+ fields: import_zod13.z.array(Field).describe("Fields rendered in summary view.")
820
1035
  }).describe("Configuration for summary in event.");
821
1036
 
822
1037
  // ../commons/src/events/WorkqueueConfig.ts
823
- var import_zod13 = require("zod");
1038
+ var import_zod15 = require("zod");
824
1039
 
825
1040
  // ../commons/src/events/EventMetadata.ts
826
- var import_zod12 = require("zod");
1041
+ var import_zod14 = require("zod");
827
1042
  var EventStatus = {
828
1043
  CREATED: "CREATED",
829
1044
  NOTIFIED: "NOTIFIED",
@@ -835,18 +1050,20 @@ var EventStatus = {
835
1050
  ARCHIVED: "ARCHIVED"
836
1051
  };
837
1052
  var eventStatuses = Object.values(EventStatus);
838
- var EventStatuses = import_zod12.z.nativeEnum(EventStatus);
839
- var EventMetadata = import_zod12.z.object({
840
- id: import_zod12.z.string(),
841
- type: import_zod12.z.string(),
1053
+ var EventStatuses = import_zod14.z.nativeEnum(EventStatus);
1054
+ var EventMetadata = import_zod14.z.object({
1055
+ id: import_zod14.z.string(),
1056
+ type: import_zod14.z.string(),
842
1057
  status: EventStatuses,
843
- createdAt: import_zod12.z.string().datetime(),
844
- createdBy: import_zod12.z.string(),
845
- createdAtLocation: import_zod12.z.string(),
846
- modifiedAt: import_zod12.z.string().datetime(),
847
- assignedTo: import_zod12.z.string().nullish(),
848
- updatedBy: import_zod12.z.string(),
849
- trackingId: import_zod12.z.string()
1058
+ createdAt: import_zod14.z.string().datetime(),
1059
+ createdBy: import_zod14.z.string(),
1060
+ createdAtLocation: import_zod14.z.string(),
1061
+ updatedAtLocation: import_zod14.z.string(),
1062
+ modifiedAt: import_zod14.z.string().datetime(),
1063
+ assignedTo: import_zod14.z.string().nullish(),
1064
+ updatedBy: import_zod14.z.string(),
1065
+ trackingId: import_zod14.z.string(),
1066
+ registrationNumber: import_zod14.z.string().nullish()
850
1067
  });
851
1068
  var eventMetadataLabelMap = {
852
1069
  "event.assignedTo": {
@@ -864,6 +1081,11 @@ var eventMetadataLabelMap = {
864
1081
  defaultMessage: "Location",
865
1082
  description: "Created At Location"
866
1083
  },
1084
+ "event.updatedAtLocation": {
1085
+ id: "event.updatedAtLocation.label",
1086
+ defaultMessage: "Location",
1087
+ description: "Updated At Location"
1088
+ },
867
1089
  "event.createdBy": {
868
1090
  id: "event.createdBy.label",
869
1091
  defaultMessage: "Created By",
@@ -898,28 +1120,33 @@ var eventMetadataLabelMap = {
898
1120
  id: "event.trackingId.label",
899
1121
  defaultMessage: "Tracking ID",
900
1122
  description: "Tracking ID"
1123
+ },
1124
+ "event.registrationNumber": {
1125
+ id: "event.registrationNumber.label",
1126
+ defaultMessage: "Registration Number",
1127
+ description: "Registration Number"
901
1128
  }
902
1129
  };
903
1130
 
904
1131
  // ../commons/src/events/WorkqueueConfig.ts
905
- var WorkqueueConfig = import_zod13.z.object({
906
- id: import_zod13.z.string().describe("Unique identifier for workqueue."),
907
- filters: import_zod13.z.array(
908
- import_zod13.z.object({
909
- status: import_zod13.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
1132
+ var WorkqueueConfig = import_zod15.z.object({
1133
+ id: import_zod15.z.string().describe("Unique identifier for workqueue."),
1134
+ filters: import_zod15.z.array(
1135
+ import_zod15.z.object({
1136
+ status: import_zod15.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
910
1137
  })
911
1138
  ).describe("Filters to be applied to workqueue.")
912
1139
  }).describe("Configuration for workqueue.");
913
1140
 
914
1141
  // ../commons/src/events/AdvancedSearchConfig.ts
915
- var import_zod14 = require("zod");
916
- var AdvancedSearchConfig = import_zod14.z.object({
1142
+ var import_zod16 = require("zod");
1143
+ var AdvancedSearchConfig = import_zod16.z.object({
917
1144
  title: TranslationConfig.describe("Advanced search tab title"),
918
- fields: import_zod14.z.array(
919
- import_zod14.z.object({
920
- fieldId: import_zod14.z.string(),
921
- config: import_zod14.z.object({
922
- type: import_zod14.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
1145
+ fields: import_zod16.z.array(
1146
+ import_zod16.z.object({
1147
+ fieldId: import_zod16.z.string(),
1148
+ config: import_zod16.z.object({
1149
+ type: import_zod16.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
923
1150
  }).optional().describe("Configuration options for the field")
924
1151
  })
925
1152
  ).optional().default([]).describe("Advanced search fields.")
@@ -929,12 +1156,12 @@ var AdvancedSearchConfig = import_zod14.z.object({
929
1156
  var import_lodash = require("lodash");
930
1157
 
931
1158
  // ../commons/src/workqueues/WorkqueueConfig.ts
932
- var import_zod16 = require("zod");
1159
+ var import_zod18 = require("zod");
933
1160
 
934
1161
  // ../commons/src/workqueues/defaultColumns.ts
935
- var import_zod15 = require("zod");
936
- var WorkQueueColumnConfig = import_zod15.z.object({
937
- id: import_zod15.z.string(),
1162
+ var import_zod17 = require("zod");
1163
+ var WorkQueueColumnConfig = import_zod17.z.object({
1164
+ id: import_zod17.z.string(),
938
1165
  label: TranslationConfig
939
1166
  });
940
1167
  var defaultColumns = {
@@ -971,16 +1198,16 @@ var defaultColumns = {
971
1198
  }
972
1199
  }
973
1200
  };
974
- var DefaultColumnKeys = import_zod15.z.enum(
1201
+ var DefaultColumnKeys = import_zod17.z.enum(
975
1202
  Object.keys(defaultColumns)
976
1203
  );
977
1204
 
978
1205
  // ../commons/src/workqueues/WorkqueueConfig.ts
979
- var rootWorkqueueConfig = import_zod16.z.object({
980
- id: import_zod16.z.string(),
1206
+ var rootWorkqueueConfig = import_zod18.z.object({
1207
+ id: import_zod18.z.string(),
981
1208
  title: TranslationConfig,
982
- columns: import_zod16.z.array(WorkQueueColumnConfig),
983
- defaultColumns: import_zod16.z.array(DefaultColumnKeys)
1209
+ columns: import_zod18.z.array(WorkQueueColumnConfig),
1210
+ defaultColumns: import_zod18.z.array(DefaultColumnKeys)
984
1211
  });
985
1212
  var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
986
1213
 
@@ -1060,7 +1287,7 @@ var import_ajv_formats = __toESM(require("ajv-formats"));
1060
1287
  var import_date_fns = require("date-fns");
1061
1288
 
1062
1289
  // ../commons/src/events/FieldTypeMapping.ts
1063
- var import_zod17 = require("zod");
1290
+ var import_zod19 = require("zod");
1064
1291
  function mapFieldTypeToZod(type, required) {
1065
1292
  let schema;
1066
1293
  switch (type) {
@@ -1102,6 +1329,9 @@ function mapFieldTypeToZod(type, required) {
1102
1329
  case FieldType.ADDRESS:
1103
1330
  schema = AddressFieldUpdateValue;
1104
1331
  break;
1332
+ case FieldType.DATA:
1333
+ schema = DataFieldValue;
1334
+ break;
1105
1335
  }
1106
1336
  return required ? schema : schema.nullish();
1107
1337
  }
@@ -1110,7 +1340,7 @@ function createValidationSchema(config) {
1110
1340
  for (const field2 of config) {
1111
1341
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1112
1342
  }
1113
- return import_zod17.z.object(shape);
1343
+ return import_zod19.z.object(shape);
1114
1344
  }
1115
1345
  function mapFieldTypeToMockValue(field2, i) {
1116
1346
  switch (field2.type) {
@@ -1136,6 +1366,7 @@ function mapFieldTypeToMockValue(field2, i) {
1136
1366
  case FieldType.ADDRESS:
1137
1367
  return {
1138
1368
  country: "FAR",
1369
+ addressType: AddressType.DOMESTIC,
1139
1370
  province: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
1140
1371
  district: "5ef450bc-712d-48ad-93f3-8da0fa453baa",
1141
1372
  urbanOrRural: "URBAN",
@@ -1157,6 +1388,54 @@ function mapFieldTypeToMockValue(field2, i) {
1157
1388
  };
1158
1389
  case FieldType.FILE_WITH_OPTIONS:
1159
1390
  return null;
1391
+ case FieldType.DATA:
1392
+ return {};
1393
+ }
1394
+ }
1395
+ function mapFieldTypeToEmptyValue(field2) {
1396
+ switch (field2.type) {
1397
+ case FieldType.DIVIDER:
1398
+ case FieldType.TEXT:
1399
+ case FieldType.TEXTAREA:
1400
+ case FieldType.BULLET_LIST:
1401
+ case FieldType.PAGE_HEADER:
1402
+ case FieldType.LOCATION:
1403
+ case FieldType.SELECT:
1404
+ case FieldType.COUNTRY:
1405
+ case FieldType.RADIO_GROUP:
1406
+ case FieldType.SIGNATURE:
1407
+ case FieldType.PARAGRAPH:
1408
+ case FieldType.ADMINISTRATIVE_AREA:
1409
+ case FieldType.FACILITY:
1410
+ case FieldType.OFFICE:
1411
+ case FieldType.NUMBER:
1412
+ case FieldType.EMAIL:
1413
+ case FieldType.DATE:
1414
+ case FieldType.CHECKBOX:
1415
+ case FieldType.DATA:
1416
+ return null;
1417
+ case FieldType.ADDRESS:
1418
+ return {
1419
+ country: null,
1420
+ addressType: AddressType.DOMESTIC,
1421
+ province: null,
1422
+ district: null,
1423
+ urbanOrRural: "URBAN",
1424
+ // Default to urban needed for validation
1425
+ town: null,
1426
+ residentialArea: null,
1427
+ street: null,
1428
+ number: null,
1429
+ zipCode: null
1430
+ };
1431
+ case FieldType.FILE:
1432
+ return {
1433
+ filename: "",
1434
+ originalFilename: "",
1435
+ type: ""
1436
+ };
1437
+ case FieldType.FILE_WITH_OPTIONS:
1438
+ return [];
1160
1439
  }
1161
1440
  }
1162
1441
  var isParagraphFieldType = (field2) => {
@@ -1222,10 +1501,14 @@ var isFacilityFieldType = (field2) => {
1222
1501
  var isOfficeFieldType = (field2) => {
1223
1502
  return field2.config.type === FieldType.OFFICE;
1224
1503
  };
1504
+ var isDataFieldType = (field2) => {
1505
+ return field2.config.type === FieldType.DATA;
1506
+ };
1225
1507
 
1226
1508
  // ../commons/src/conditionals/validate.ts
1227
1509
  var ajv = new import_ajv.default({
1228
- $data: true
1510
+ $data: true,
1511
+ allowUnionTypes: true
1229
1512
  });
1230
1513
  (0, import_ajv_formats.default)(ajv);
1231
1514
  function validate(schema, data) {
@@ -1258,50 +1541,103 @@ function isFieldVisible(field2, form) {
1258
1541
  function isFieldEnabled(field2, form) {
1259
1542
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1260
1543
  }
1261
- var zodToIntlErrorMap = (issue, _ctx) => {
1262
- if (issue.code === "invalid_string" && issue.validation === "date") {
1263
- return {
1264
- message: {
1265
- message: {
1266
- defaultMessage: "Invalid date. Please use the format YYYY-MM-DD",
1267
- description: "This is the error message for invalid date fields",
1268
- id: "v2.error.invalidDate"
1269
- }
1270
- }
1271
- };
1544
+ function isFieldDisplayedOnReview(field2, form) {
1545
+ return isFieldVisible(field2, form) && isFieldConditionMet(field2, form, ConditionalType.DISPLAY_ON_REVIEW);
1546
+ }
1547
+ var errorMessages = {
1548
+ hiddenField: {
1549
+ id: "v2.error.hidden",
1550
+ defaultMessage: "Hidden or disabled field should not receive a value",
1551
+ description: "Error message when field is hidden or disabled, but a value was received"
1552
+ },
1553
+ invalidDate: {
1554
+ defaultMessage: "Invalid date field",
1555
+ description: "Error message when date field is invalid",
1556
+ id: "v2.error.invalidDate"
1557
+ },
1558
+ invalidEmail: {
1559
+ defaultMessage: "Invalid email address",
1560
+ description: "Error message when email address is invalid",
1561
+ id: "v2.error.invalidEmail"
1562
+ },
1563
+ requiredField: {
1564
+ defaultMessage: "Required for registration",
1565
+ description: "Error message when required field is missing",
1566
+ id: "v2.error.required"
1567
+ },
1568
+ invalidInput: {
1569
+ defaultMessage: "Invalid input",
1570
+ description: "Error message when generic field is invalid",
1571
+ id: "v2.error.invalid"
1272
1572
  }
1273
- if (issue.code === "invalid_string" && issue.validation === "email") {
1274
- return {
1275
- message: {
1276
- message: {
1277
- defaultMessage: "Invalid email address",
1278
- description: "This is the error message for invalid email fields",
1279
- id: "v2.error.invalidEmail"
1280
- }
1573
+ };
1574
+ function createIntlError(message) {
1575
+ return {
1576
+ message: {
1577
+ message
1578
+ }
1579
+ };
1580
+ }
1581
+ function zodToIntlErrorMap(issue, _ctx) {
1582
+ switch (issue.code) {
1583
+ case "invalid_string": {
1584
+ if (_ctx.data === "") {
1585
+ return createIntlError(errorMessages.requiredField);
1281
1586
  }
1282
- };
1283
- }
1284
- if (issue.code === "invalid_type" && issue.expected !== issue.received && issue.received === "undefined" || issue.code === "too_small" && issue.message === void 0) {
1285
- return {
1286
- message: {
1287
- message: {
1288
- defaultMessage: "Required for registration",
1289
- description: "This is the error message for required fields",
1290
- id: "v2.error.required"
1587
+ if (issue.validation === "date") {
1588
+ return createIntlError(errorMessages.invalidDate);
1589
+ }
1590
+ if (issue.validation === "email") {
1591
+ return createIntlError(errorMessages.invalidEmail);
1592
+ }
1593
+ break;
1594
+ }
1595
+ case "invalid_type": {
1596
+ if (issue.expected !== issue.received && issue.received === "undefined") {
1597
+ return createIntlError(errorMessages.requiredField);
1598
+ }
1599
+ break;
1600
+ }
1601
+ case "too_small": {
1602
+ if (issue.message === void 0) {
1603
+ return createIntlError(errorMessages.requiredField);
1604
+ }
1605
+ break;
1606
+ }
1607
+ case "invalid_union": {
1608
+ for (const { issues } of issue.unionErrors) {
1609
+ for (const e of issues) {
1610
+ if (zodToIntlErrorMap(e, _ctx).message.message.id !== "v2.error.required") {
1611
+ return createIntlError(errorMessages.invalidInput);
1612
+ }
1291
1613
  }
1292
1614
  }
1293
- };
1615
+ return createIntlError(errorMessages.requiredField);
1616
+ }
1294
1617
  }
1295
- return {
1296
- message: {
1297
- message: {
1298
- defaultMessage: "Invalid input",
1299
- description: "This is the error message for invalid field value",
1300
- id: "v2.error.invalid"
1301
- }
1618
+ return createIntlError(errorMessages.invalidInput);
1619
+ }
1620
+ function runCustomFieldValidations({
1621
+ field: field2,
1622
+ conditionalParameters
1623
+ }) {
1624
+ return (field2.validation ?? []).filter((validation) => {
1625
+ return !validate(validation.validator, conditionalParameters);
1626
+ }).map((validation) => ({ message: validation.message }));
1627
+ }
1628
+ function validateFieldInput({
1629
+ field: field2,
1630
+ value
1631
+ }) {
1632
+ const rawError = mapFieldTypeToZod(field2.type, field2.required).safeParse(
1633
+ value,
1634
+ {
1635
+ // @ts-expect-error
1636
+ errorMap: zodToIntlErrorMap
1302
1637
  }
1303
- };
1304
- };
1638
+ );
1639
+ return rawError.error?.issues.map((issue) => issue.message) ?? [];
1640
+ }
1305
1641
  function getFieldValidationErrors({
1306
1642
  field: field2,
1307
1643
  values
@@ -1315,11 +1651,7 @@ function getFieldValidationErrors({
1315
1651
  return {
1316
1652
  errors: [
1317
1653
  {
1318
- message: {
1319
- id: "v2.error.hidden",
1320
- defaultMessage: "Hidden or disabled field should not receive a value",
1321
- description: "Error message when field is hidden or disabled, but a value was received"
1322
- }
1654
+ message: errorMessages.hiddenField
1323
1655
  }
1324
1656
  ]
1325
1657
  };
@@ -1337,93 +1669,86 @@ function getFieldValidationErrors({
1337
1669
  conditionalParameters
1338
1670
  });
1339
1671
  return {
1340
- // Assumes that custom validation errors are more important than field validation errors
1341
- errors: [...customValidationResults, ...fieldValidationResult]
1672
+ // Assumes that custom validation errors are based on the field type, and extend the validation.
1673
+ errors: [...fieldValidationResult, ...customValidationResults]
1342
1674
  };
1343
1675
  }
1344
- function runCustomFieldValidations({
1345
- field: field2,
1346
- conditionalParameters
1347
- }) {
1348
- return (field2.validation ?? []).filter((validation) => {
1349
- return !validate(validation.validator, conditionalParameters);
1350
- }).map((validation) => ({ message: validation.message }));
1676
+
1677
+ // ../commons/src/uuid.ts
1678
+ var import_uuid = require("uuid");
1679
+ function getUUID() {
1680
+ return (0, import_uuid.v4)();
1351
1681
  }
1352
- function validateFieldInput({
1353
- field: field2,
1354
- value
1355
- }) {
1356
- const rawError = mapFieldTypeToZod(field2.type, field2.required).safeParse(
1357
- value,
1358
- {
1359
- // @ts-expect-error
1360
- errorMap: zodToIntlErrorMap
1361
- }
1362
- );
1363
- return rawError.error?.issues.map((issue) => issue.message) ?? [];
1682
+
1683
+ // ../commons/src/events/utils.ts
1684
+ var import_date_fns2 = require("date-fns");
1685
+
1686
+ // ../commons/src/utils.ts
1687
+ function getOrThrow(x, message) {
1688
+ if (x === void 0 || x === null) {
1689
+ throw new Error(message);
1690
+ }
1691
+ return x;
1364
1692
  }
1365
1693
 
1366
1694
  // ../commons/src/events/utils.ts
1367
- function isMetadataField(field2) {
1368
- return field2 in eventMetadataLabelMap;
1369
- }
1370
- var findInputPageFields = (config) => {
1371
- return (0, import_lodash.flattenDeep)(
1372
- config.actions.map(
1373
- ({ forms }) => forms.map(
1374
- ({ pages }) => pages.map(
1375
- ({ fields }) => fields.map(({ id, label }) => ({ id, label }))
1376
- )
1377
- )
1378
- )
1379
- );
1380
- };
1381
- var findPageFields = (config) => {
1382
- return (0, import_lodash.flattenDeep)(
1383
- config.actions.map((action) => {
1384
- if (action.type === ActionType.REQUEST_CORRECTION) {
1385
- return [
1386
- ...action.forms.map(({ pages }) => pages.map(({ fields }) => fields)),
1387
- ...action.onboardingForm.flatMap(({ fields }) => fields),
1388
- ...action.additionalDetailsForm.flatMap(({ fields }) => fields)
1389
- ];
1390
- }
1391
- return action.forms.map(({ pages }) => pages.map(({ fields }) => fields));
1392
- })
1393
- );
1695
+ function isDeclarationActionConfig(action) {
1696
+ return DeclarationActions.safeParse(action.type).success;
1697
+ }
1698
+ function getDeclarationFields(configuration) {
1699
+ return configuration.declaration.pages.flatMap(({ fields }) => fields);
1700
+ }
1701
+ function getDeclarationPages(configuration) {
1702
+ return configuration.declaration.pages;
1703
+ }
1704
+ function getDeclaration(configuration) {
1705
+ return configuration.declaration;
1706
+ }
1707
+ var getActionAnnotationFields = (actionConfig) => {
1708
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1709
+ return [
1710
+ ...actionConfig.onboardingForm.flatMap(({ fields }) => fields),
1711
+ ...actionConfig.additionalDetailsForm.flatMap(({ fields }) => fields)
1712
+ ];
1713
+ }
1714
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1715
+ return actionConfig.printForm.pages.flatMap(({ fields }) => fields);
1716
+ }
1717
+ if (isDeclarationActionConfig(actionConfig)) {
1718
+ return actionConfig.review.fields;
1719
+ }
1720
+ return [];
1394
1721
  };
1395
- var resolveLabelsFromKnownFields = ({
1396
- pageFields,
1397
- refFields
1398
- }) => {
1399
- return refFields.map((field2) => {
1400
- if (field2.label) {
1401
- return field2;
1402
- }
1403
- if (isMetadataField(field2.id)) {
1404
- return {
1405
- ...field2,
1406
- label: eventMetadataLabelMap[field2.id]
1407
- };
1408
- }
1409
- const pageLabel = pageFields.find((pageField) => pageField.id === field2.id);
1410
- if (!pageLabel) {
1411
- throw new Error(`Referenced field ${field2.id} does not have a label`);
1412
- }
1413
- return {
1414
- ...field2,
1415
- label: pageLabel.label
1416
- };
1417
- });
1722
+ var getAllAnnotationFields = (config) => {
1723
+ return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1418
1724
  };
1419
- function getAllFields(configuration) {
1420
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => [
1421
- ...form.review.fields,
1422
- ...form.pages.flatMap((page) => page.fields)
1725
+ var findAllFields = (config) => {
1726
+ return (0, import_lodash.flattenDeep)([
1727
+ ...getDeclarationFields(config),
1728
+ ...getAllAnnotationFields(config)
1423
1729
  ]);
1730
+ };
1731
+ var findRecordActionPages = (config, actionType) => {
1732
+ const action = config.actions.find((a) => a.type === actionType);
1733
+ if (action?.type === ActionType.REQUEST_CORRECTION) {
1734
+ return [...action.onboardingForm, ...action.additionalDetailsForm];
1735
+ }
1736
+ if (action?.type === ActionType.PRINT_CERTIFICATE) {
1737
+ return action.printForm.pages;
1738
+ }
1739
+ return [];
1740
+ };
1741
+ function getActionReview(configuration, actionType) {
1742
+ const [actionConfig] = configuration.actions.filter(
1743
+ (a) => a.type === actionType
1744
+ );
1745
+ return getOrThrow(
1746
+ actionConfig.review,
1747
+ `No review config found for ${actionType}`
1748
+ );
1424
1749
  }
1425
- function getAllPages(configuration) {
1426
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => form.pages);
1750
+ function getActionReviewFields(configuration, actionType) {
1751
+ return getActionReview(configuration, actionType).fields;
1427
1752
  }
1428
1753
  function validateWorkqueueConfig(workqueueConfigs) {
1429
1754
  workqueueConfigs.map((workqueue) => {
@@ -1432,79 +1757,98 @@ function validateWorkqueueConfig(workqueueConfigs) {
1432
1757
  );
1433
1758
  if (!rootWorkqueue) {
1434
1759
  throw new Error(
1435
- `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1760
+ `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1436
1761
  );
1437
1762
  }
1438
1763
  });
1439
1764
  }
1440
- var findActiveActionForm = (configuration, action) => {
1441
- const actionConfig = configuration.actions.find((a) => a.type === action);
1442
- const form = actionConfig?.forms.find((f) => f.active);
1443
- return form;
1444
- };
1445
- var findActiveActionFormPages = (configuration, action) => {
1446
- return findActiveActionForm(configuration, action)?.pages;
1447
- };
1448
- var getFormFields = (formConfig) => {
1449
- return formConfig.pages.flatMap((p) => p.fields);
1450
- };
1451
- var findActiveActionFormFields = (configuration, action) => {
1452
- const form = findActiveActionForm(configuration, action);
1453
- return form ? getFormFields(form) : void 0;
1454
- };
1455
- var findActiveActionFields = (configuration, action) => {
1456
- const form = findActiveActionForm(configuration, action);
1457
- const reviewFields = form?.review.fields;
1458
- const formFields = form ? getFormFields(form) : void 0;
1459
- const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1460
- return allFields;
1461
- };
1462
- function getActiveActionFields(configuration, action) {
1463
- const fields = findActiveActionFields(configuration, action);
1464
- if (!fields) {
1465
- throw new Error(`No active field config found for action type ${action}`);
1466
- }
1467
- return fields;
1468
- }
1469
- function getEventConfiguration(eventConfigurations, type) {
1470
- const config = eventConfigurations.find((config2) => config2.id === type);
1471
- if (!config) {
1472
- throw new Error(`Event configuration not found for type: ${type}`);
1765
+ function isPageVisible(page, formValues) {
1766
+ if (!page.conditional) {
1767
+ return true;
1473
1768
  }
1474
- return config;
1769
+ return validate(page.conditional, {
1770
+ $form: formValues,
1771
+ $now: (0, import_date_fns2.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1772
+ });
1475
1773
  }
1774
+ var getVisiblePagesFormFields = (formConfig, formData) => {
1775
+ return formConfig.pages.filter((p) => isPageVisible(p, formData)).flatMap((p) => p.fields);
1776
+ };
1476
1777
  function isOptionalUncheckedCheckbox(field2, form) {
1477
1778
  if (field2.type !== FieldType.CHECKBOX || field2.required) {
1478
1779
  return false;
1479
1780
  }
1480
1781
  return !form[field2.id];
1481
1782
  }
1482
- function stripHiddenFields(fields, data) {
1483
- return (0, import_lodash.omitBy)(data, (_2, fieldId) => {
1783
+ function stripHiddenFields(fields, declaration) {
1784
+ return (0, import_lodash.omitBy)(declaration, (_, fieldId) => {
1484
1785
  const field2 = fields.find((f) => f.id === fieldId);
1485
1786
  if (!field2) {
1486
1787
  return true;
1487
1788
  }
1488
- if (isOptionalUncheckedCheckbox(field2, data)) {
1789
+ if (isOptionalUncheckedCheckbox(field2, declaration)) {
1489
1790
  return true;
1490
1791
  }
1491
- return !isFieldVisible(field2, data);
1792
+ return !isFieldVisible(field2, declaration);
1492
1793
  });
1493
1794
  }
1795
+ function findActiveDrafts(event2, drafts) {
1796
+ const actions = event2.actions.slice().filter(({ type }) => type !== ActionType.READ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1797
+ const lastAction = actions[actions.length - 1];
1798
+ return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
1799
+ }
1800
+ function createEmptyDraft(eventId, draftId, actionType) {
1801
+ return {
1802
+ id: draftId,
1803
+ eventId,
1804
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1805
+ transactionId: getUUID(),
1806
+ action: {
1807
+ type: actionType,
1808
+ declaration: {},
1809
+ annotation: {},
1810
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1811
+ createdBy: "@todo",
1812
+ createdAtLocation: "@todo"
1813
+ }
1814
+ };
1815
+ }
1816
+ function isVerificationPage(page) {
1817
+ return page.type === PageTypes.enum.VERIFICATION;
1818
+ }
1819
+ function deepMerge(currentDocument, actionDocument) {
1820
+ return (0, import_lodash.mergeWith)(
1821
+ currentDocument,
1822
+ actionDocument,
1823
+ (previousValue, incomingValue) => {
1824
+ if (incomingValue === void 0) {
1825
+ return previousValue;
1826
+ }
1827
+ if ((0, import_lodash.isArray)(incomingValue)) {
1828
+ return incomingValue;
1829
+ }
1830
+ if ((0, import_lodash.isObject)(previousValue) && (0, import_lodash.isObject)(incomingValue)) {
1831
+ return void 0;
1832
+ }
1833
+ return incomingValue;
1834
+ }
1835
+ );
1836
+ }
1494
1837
 
1495
1838
  // ../commons/src/events/EventConfig.ts
1496
- var EventConfig = import_zod18.z.object({
1497
- id: import_zod18.z.string().describe(
1839
+ var EventConfig = import_zod20.z.object({
1840
+ id: import_zod20.z.string().describe(
1498
1841
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1499
1842
  ),
1500
1843
  summary: SummaryConfig,
1501
1844
  label: TranslationConfig,
1502
- actions: import_zod18.z.array(ActionConfig),
1503
- workqueues: import_zod18.z.array(WorkqueueConfig),
1504
- deduplication: import_zod18.z.array(DeduplicationConfig).optional().default([]),
1505
- advancedSearch: import_zod18.z.array(AdvancedSearchConfig).optional().default([])
1845
+ actions: import_zod20.z.array(ActionConfig),
1846
+ declaration: DeclarationFormConfig,
1847
+ workqueues: import_zod20.z.array(WorkqueueConfig),
1848
+ deduplication: import_zod20.z.array(DeduplicationConfig).optional().default([]),
1849
+ advancedSearch: import_zod20.z.array(AdvancedSearchConfig).optional().default([])
1506
1850
  }).superRefine((event2, ctx) => {
1507
- const allFields = findPageFields(event2);
1851
+ const allFields = findAllFields(event2);
1508
1852
  const fieldIds = allFields.map((field2) => field2.id);
1509
1853
  const advancedSearchFields = event2.advancedSearch.flatMap(
1510
1854
  (section) => section.fields.flatMap((field2) => field2.fieldId)
@@ -1531,111 +1875,122 @@ var EventConfig = import_zod18.z.object({
1531
1875
  });
1532
1876
 
1533
1877
  // ../commons/src/events/EventConfigInput.ts
1534
- var defineForm = (form) => FormConfig.parse(form);
1535
- var defineFormPage = (formPage) => FormPage.parse(formPage);
1878
+ var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
1879
+ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1880
+ var definePage = (page) => PageConfig.parse(page);
1881
+ var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1536
1882
 
1537
1883
  // ../commons/src/events/Draft.ts
1538
- var import_zod21 = require("zod");
1884
+ var import_zod23 = require("zod");
1539
1885
 
1540
1886
  // ../commons/src/events/ActionDocument.ts
1541
- var import_zod19 = require("zod");
1542
- var ActionUpdate = import_zod19.z.record(import_zod19.z.string(), FieldUpdateValue);
1543
- var ActionBase = import_zod19.z.object({
1544
- id: import_zod19.z.string(),
1545
- createdAt: import_zod19.z.string().datetime(),
1546
- createdBy: import_zod19.z.string(),
1547
- data: ActionUpdate,
1548
- metadata: ActionUpdate.optional(),
1549
- createdAtLocation: import_zod19.z.string()
1887
+ var import_zod21 = require("zod");
1888
+ var ActionUpdate = import_zod21.z.record(import_zod21.z.string(), FieldUpdateValue);
1889
+ var ActionStatus = {
1890
+ Requested: "Requested",
1891
+ Accepted: "Accepted",
1892
+ Rejected: "Rejected"
1893
+ };
1894
+ var ActionBase = import_zod21.z.object({
1895
+ id: import_zod21.z.string(),
1896
+ createdAt: import_zod21.z.string().datetime(),
1897
+ createdBy: import_zod21.z.string(),
1898
+ declaration: ActionUpdate,
1899
+ annotation: ActionUpdate.optional(),
1900
+ createdAtLocation: import_zod21.z.string(),
1901
+ status: import_zod21.z.enum([
1902
+ ActionStatus.Requested,
1903
+ ActionStatus.Accepted,
1904
+ ActionStatus.Rejected
1905
+ ]),
1906
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1907
+ originalActionId: import_zod21.z.string().optional()
1550
1908
  });
1551
1909
  var AssignedAction = ActionBase.merge(
1552
- import_zod19.z.object({
1553
- type: import_zod19.z.literal(ActionType.ASSIGN),
1554
- assignedTo: import_zod19.z.string()
1910
+ import_zod21.z.object({
1911
+ type: import_zod21.z.literal(ActionType.ASSIGN),
1912
+ assignedTo: import_zod21.z.string()
1555
1913
  })
1556
1914
  );
1557
1915
  var UnassignedAction = ActionBase.merge(
1558
- import_zod19.z.object({
1559
- type: import_zod19.z.literal(ActionType.UNASSIGN)
1916
+ import_zod21.z.object({
1917
+ type: import_zod21.z.literal(ActionType.UNASSIGN)
1560
1918
  })
1561
1919
  );
1562
1920
  var RegisterAction = ActionBase.merge(
1563
- import_zod19.z.object({
1564
- type: import_zod19.z.literal(ActionType.REGISTER),
1565
- identifiers: import_zod19.z.object({
1566
- trackingId: import_zod19.z.string(),
1567
- registrationNumber: import_zod19.z.string()
1568
- })
1921
+ import_zod21.z.object({
1922
+ type: import_zod21.z.literal(ActionType.REGISTER),
1923
+ registrationNumber: import_zod21.z.string().optional()
1569
1924
  })
1570
1925
  );
1571
1926
  var DeclareAction = ActionBase.merge(
1572
- import_zod19.z.object({
1573
- type: import_zod19.z.literal(ActionType.DECLARE)
1927
+ import_zod21.z.object({
1928
+ type: import_zod21.z.literal(ActionType.DECLARE)
1574
1929
  })
1575
1930
  );
1576
1931
  var ValidateAction = ActionBase.merge(
1577
- import_zod19.z.object({
1578
- type: import_zod19.z.literal(ActionType.VALIDATE)
1932
+ import_zod21.z.object({
1933
+ type: import_zod21.z.literal(ActionType.VALIDATE)
1579
1934
  })
1580
1935
  );
1581
1936
  var RejectAction = ActionBase.merge(
1582
- import_zod19.z.object({
1583
- type: import_zod19.z.literal(ActionType.REJECT)
1937
+ import_zod21.z.object({
1938
+ type: import_zod21.z.literal(ActionType.REJECT)
1584
1939
  })
1585
1940
  );
1586
1941
  var MarkAsDuplicateAction = ActionBase.merge(
1587
- import_zod19.z.object({
1588
- type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1942
+ import_zod21.z.object({
1943
+ type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE)
1589
1944
  })
1590
1945
  );
1591
- var ArchivedAction = ActionBase.merge(
1592
- import_zod19.z.object({
1593
- type: import_zod19.z.literal(ActionType.ARCHIVED)
1946
+ var ArchiveAction = ActionBase.merge(
1947
+ import_zod21.z.object({
1948
+ type: import_zod21.z.literal(ActionType.ARCHIVE)
1594
1949
  })
1595
1950
  );
1596
1951
  var CreatedAction = ActionBase.merge(
1597
- import_zod19.z.object({
1598
- type: import_zod19.z.literal(ActionType.CREATE)
1952
+ import_zod21.z.object({
1953
+ type: import_zod21.z.literal(ActionType.CREATE)
1599
1954
  })
1600
1955
  );
1601
1956
  var NotifiedAction = ActionBase.merge(
1602
- import_zod19.z.object({
1603
- type: import_zod19.z.literal(ActionType.NOTIFY)
1957
+ import_zod21.z.object({
1958
+ type: import_zod21.z.literal(ActionType.NOTIFY)
1604
1959
  })
1605
1960
  );
1606
1961
  var PrintCertificateAction = ActionBase.merge(
1607
- import_zod19.z.object({
1608
- type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE)
1962
+ import_zod21.z.object({
1963
+ type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE)
1609
1964
  })
1610
1965
  );
1611
1966
  var RequestedCorrectionAction = ActionBase.merge(
1612
- import_zod19.z.object({
1613
- type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION)
1967
+ import_zod21.z.object({
1968
+ type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION)
1614
1969
  })
1615
1970
  );
1616
1971
  var ApprovedCorrectionAction = ActionBase.merge(
1617
- import_zod19.z.object({
1618
- type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION),
1619
- requestId: import_zod19.z.string()
1972
+ import_zod21.z.object({
1973
+ type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION),
1974
+ requestId: import_zod21.z.string()
1620
1975
  })
1621
1976
  );
1622
1977
  var RejectedCorrectionAction = ActionBase.merge(
1623
- import_zod19.z.object({
1624
- type: import_zod19.z.literal(ActionType.REJECT_CORRECTION),
1625
- requestId: import_zod19.z.string()
1978
+ import_zod21.z.object({
1979
+ type: import_zod21.z.literal(ActionType.REJECT_CORRECTION),
1980
+ requestId: import_zod21.z.string()
1626
1981
  })
1627
1982
  );
1628
- var CustomAction = ActionBase.merge(
1629
- import_zod19.z.object({
1630
- type: import_zod19.z.literal(ActionType.CUSTOM)
1983
+ var ReadAction = ActionBase.merge(
1984
+ import_zod21.z.object({
1985
+ type: import_zod21.z.literal(ActionType.READ)
1631
1986
  })
1632
1987
  );
1633
- var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1988
+ var ActionDocument = import_zod21.z.discriminatedUnion("type", [
1634
1989
  CreatedAction,
1635
1990
  ValidateAction,
1636
1991
  RejectAction,
1637
1992
  MarkAsDuplicateAction,
1638
- ArchivedAction,
1993
+ ArchiveAction,
1639
1994
  NotifiedAction,
1640
1995
  RegisterAction,
1641
1996
  DeclareAction,
@@ -1645,108 +2000,124 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1645
2000
  RejectedCorrectionAction,
1646
2001
  UnassignedAction,
1647
2002
  PrintCertificateAction,
1648
- CustomAction
2003
+ ReadAction
1649
2004
  ]);
1650
- var ResolvedUser = import_zod19.z.object({
1651
- id: import_zod19.z.string(),
1652
- role: import_zod19.z.string(),
1653
- name: import_zod19.z.array(
1654
- import_zod19.z.object({
1655
- use: import_zod19.z.string(),
1656
- given: import_zod19.z.array(import_zod19.z.string()),
1657
- family: import_zod19.z.string()
2005
+ var AsyncRejectActionDocument = ActionBase.omit({
2006
+ declaration: true,
2007
+ annotation: true,
2008
+ createdBy: true,
2009
+ createdAtLocation: true
2010
+ }).merge(
2011
+ import_zod21.z.object({
2012
+ type: import_zod21.z.enum(ConfirmableActions),
2013
+ status: import_zod21.z.literal(ActionStatus.Rejected)
2014
+ })
2015
+ );
2016
+ var Action = import_zod21.z.union([ActionDocument, AsyncRejectActionDocument]);
2017
+ var ResolvedUser = import_zod21.z.object({
2018
+ id: import_zod21.z.string(),
2019
+ role: import_zod21.z.string(),
2020
+ name: import_zod21.z.array(
2021
+ import_zod21.z.object({
2022
+ use: import_zod21.z.string(),
2023
+ given: import_zod21.z.array(import_zod21.z.string()),
2024
+ family: import_zod21.z.string()
1658
2025
  })
1659
2026
  )
1660
2027
  });
1661
2028
 
1662
2029
  // ../commons/src/events/ActionInput.ts
1663
- var import_zod20 = require("zod");
1664
- var BaseActionInput = import_zod20.z.object({
1665
- eventId: import_zod20.z.string(),
1666
- transactionId: import_zod20.z.string(),
1667
- data: ActionUpdate,
1668
- metadata: ActionUpdate.optional()
2030
+ var import_zod22 = require("zod");
2031
+ var BaseActionInput = import_zod22.z.object({
2032
+ eventId: import_zod22.z.string(),
2033
+ transactionId: import_zod22.z.string(),
2034
+ declaration: ActionUpdate.default({}),
2035
+ annotation: ActionUpdate.optional(),
2036
+ originalActionId: import_zod22.z.string().optional()
1669
2037
  });
1670
2038
  var CreateActionInput = BaseActionInput.merge(
1671
- import_zod20.z.object({
1672
- type: import_zod20.z.literal(ActionType.CREATE).default(ActionType.CREATE),
1673
- createdAtLocation: import_zod20.z.string()
2039
+ import_zod22.z.object({
2040
+ type: import_zod22.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2041
+ createdAtLocation: import_zod22.z.string()
1674
2042
  })
1675
2043
  );
1676
2044
  var RegisterActionInput = BaseActionInput.merge(
1677
- import_zod20.z.object({
1678
- type: import_zod20.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
1679
- identifiers: import_zod20.z.object({
1680
- trackingId: import_zod20.z.string(),
1681
- registrationNumber: import_zod20.z.string()
1682
- })
2045
+ import_zod22.z.object({
2046
+ type: import_zod22.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2047
+ registrationNumber: import_zod22.z.string().optional()
1683
2048
  })
1684
2049
  );
1685
2050
  var ValidateActionInput = BaseActionInput.merge(
1686
- import_zod20.z.object({
1687
- type: import_zod20.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
1688
- duplicates: import_zod20.z.array(import_zod20.z.string())
2051
+ import_zod22.z.object({
2052
+ type: import_zod22.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2053
+ duplicates: import_zod22.z.array(import_zod22.z.string())
1689
2054
  })
1690
2055
  );
1691
2056
  var NotifyActionInput = BaseActionInput.merge(
1692
- import_zod20.z.object({
1693
- type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2057
+ import_zod22.z.object({
2058
+ type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1694
2059
  })
1695
2060
  );
1696
2061
  var DeclareActionInput = BaseActionInput.merge(
1697
- import_zod20.z.object({
1698
- type: import_zod20.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2062
+ import_zod22.z.object({
2063
+ type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1699
2064
  })
1700
2065
  );
1701
2066
  var PrintCertificateActionInput = BaseActionInput.merge(
1702
- import_zod20.z.object({
1703
- type: import_zod20.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2067
+ import_zod22.z.object({
2068
+ type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1704
2069
  })
1705
2070
  );
1706
2071
  var RejectDeclarationActionInput = BaseActionInput.merge(
1707
- import_zod20.z.object({
1708
- type: import_zod20.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2072
+ import_zod22.z.object({
2073
+ type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1709
2074
  })
1710
2075
  );
1711
2076
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1712
- import_zod20.z.object({
1713
- type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2077
+ import_zod22.z.object({
2078
+ type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1714
2079
  })
1715
2080
  );
1716
- var ArchivedActionInput = BaseActionInput.merge(
1717
- import_zod20.z.object({
1718
- type: import_zod20.z.literal(ActionType.ARCHIVED).default(ActionType.ARCHIVED)
2081
+ var ArchiveActionInput = BaseActionInput.merge(
2082
+ import_zod22.z.object({
2083
+ type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1719
2084
  })
1720
2085
  );
1721
2086
  var AssignActionInput = BaseActionInput.merge(
1722
- import_zod20.z.object({
1723
- type: import_zod20.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
1724
- assignedTo: import_zod20.z.string()
2087
+ import_zod22.z.object({
2088
+ type: import_zod22.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2089
+ assignedTo: import_zod22.z.string()
1725
2090
  })
1726
2091
  );
1727
2092
  var UnassignActionInput = BaseActionInput.merge(
1728
- import_zod20.z.object({
1729
- type: import_zod20.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN)
2093
+ import_zod22.z.object({
2094
+ type: import_zod22.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2095
+ assignedTo: import_zod22.z.literal(null).default(null)
1730
2096
  })
1731
2097
  );
1732
2098
  var RequestCorrectionActionInput = BaseActionInput.merge(
1733
- import_zod20.z.object({
1734
- type: import_zod20.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2099
+ import_zod22.z.object({
2100
+ type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
1735
2101
  })
1736
2102
  );
1737
2103
  var RejectCorrectionActionInput = BaseActionInput.merge(
1738
- import_zod20.z.object({
1739
- requestId: import_zod20.z.string(),
1740
- type: import_zod20.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2104
+ import_zod22.z.object({
2105
+ requestId: import_zod22.z.string(),
2106
+ type: import_zod22.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
1741
2107
  })
1742
2108
  );
1743
2109
  var ApproveCorrectionActionInput = BaseActionInput.merge(
1744
- import_zod20.z.object({
1745
- requestId: import_zod20.z.string(),
1746
- type: import_zod20.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2110
+ import_zod22.z.object({
2111
+ requestId: import_zod22.z.string(),
2112
+ type: import_zod22.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
1747
2113
  })
1748
2114
  );
1749
- var ActionInput = import_zod20.z.discriminatedUnion("type", [
2115
+ var ReadActionInput = BaseActionInput.merge(
2116
+ import_zod22.z.object({
2117
+ type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
2118
+ })
2119
+ );
2120
+ var ActionInput = import_zod22.z.discriminatedUnion("type", [
1750
2121
  CreateActionInput,
1751
2122
  ValidateActionInput,
1752
2123
  RegisterActionInput,
@@ -1754,62 +2125,69 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
1754
2125
  DeclareActionInput,
1755
2126
  RejectDeclarationActionInput,
1756
2127
  MarkedAsDuplicateActionInput,
1757
- ArchivedActionInput,
2128
+ ArchiveActionInput,
1758
2129
  AssignActionInput,
1759
2130
  UnassignActionInput,
1760
2131
  PrintCertificateActionInput,
1761
2132
  RequestCorrectionActionInput,
1762
2133
  RejectCorrectionActionInput,
1763
- ApproveCorrectionActionInput
2134
+ ApproveCorrectionActionInput,
2135
+ ReadActionInput
1764
2136
  ]);
1765
2137
 
1766
2138
  // ../commons/src/events/Draft.ts
1767
- var Draft = import_zod21.z.object({
1768
- id: import_zod21.z.string(),
1769
- eventId: import_zod21.z.string(),
1770
- transactionId: import_zod21.z.string(),
1771
- createdAt: import_zod21.z.string().datetime(),
2139
+ var Draft = import_zod23.z.object({
2140
+ id: import_zod23.z.string(),
2141
+ eventId: import_zod23.z.string(),
2142
+ transactionId: import_zod23.z.string(),
2143
+ createdAt: import_zod23.z.string().datetime(),
1772
2144
  action: ActionBase.extend({
1773
- type: import_zod21.z.enum(Object.values(ActionType))
2145
+ type: ActionTypes
1774
2146
  }).omit({ id: true })
1775
2147
  });
1776
2148
  var DraftInput = BaseActionInput.extend({
1777
- type: import_zod21.z.enum(Object.values(ActionType))
2149
+ type: ActionTypes
1778
2150
  });
1779
2151
 
1780
2152
  // ../commons/src/events/EventInput.ts
1781
- var import_zod22 = require("zod");
1782
- var EventInput = import_zod22.z.object({
1783
- transactionId: import_zod22.z.string(),
1784
- type: import_zod22.z.string()
2153
+ var import_zod24 = require("zod");
2154
+ var EventInput = import_zod24.z.object({
2155
+ transactionId: import_zod24.z.string(),
2156
+ type: import_zod24.z.string()
1785
2157
  });
1786
2158
 
1787
2159
  // ../commons/src/events/EventDocument.ts
1788
- var import_zod23 = require("zod");
1789
- var EventDocument = import_zod23.z.object({
1790
- id: import_zod23.z.string(),
1791
- type: import_zod23.z.string(),
1792
- createdAt: import_zod23.z.string().datetime(),
1793
- updatedAt: import_zod23.z.string().datetime(),
1794
- actions: import_zod23.z.array(ActionDocument),
1795
- trackingId: import_zod23.z.string()
2160
+ var import_zod25 = require("zod");
2161
+ var EventDocument = import_zod25.z.object({
2162
+ id: import_zod25.z.string(),
2163
+ type: import_zod25.z.string(),
2164
+ createdAt: import_zod25.z.string().datetime(),
2165
+ updatedAt: import_zod25.z.string().datetime(),
2166
+ updatedAtLocation: import_zod25.z.string(),
2167
+ actions: import_zod25.z.array(Action),
2168
+ trackingId: import_zod25.z.string()
1796
2169
  });
1797
2170
 
1798
2171
  // ../commons/src/events/EventIndex.ts
1799
- var import_zod24 = require("zod");
2172
+ var import_zod26 = require("zod");
1800
2173
  var EventIndex = EventMetadata.extend({
1801
- data: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any())
2174
+ declaration: import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any())
1802
2175
  });
1803
- var EventSearchIndex = import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any()).and(
1804
- import_zod24.z.object({
1805
- type: import_zod24.z.string()
2176
+ var EventSearchIndex = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any()).and(
2177
+ import_zod26.z.object({
2178
+ type: import_zod26.z.string()
1806
2179
  // Ensures "type" (event-id) exists and is a string
1807
2180
  })
1808
2181
  );
1809
2182
 
1810
2183
  // ../commons/src/events/state/index.ts
1811
- var _ = __toESM(require("lodash"));
1812
2184
  function getStatusFromActions(actions) {
2185
+ const hasRejectedAction = actions.some(
2186
+ (a) => a.status === ActionStatus.Rejected
2187
+ );
2188
+ if (hasRejectedAction) {
2189
+ return EventStatus.REJECTED;
2190
+ }
1813
2191
  return actions.reduce((status, action) => {
1814
2192
  if (action.type === ActionType.CREATE) {
1815
2193
  return EventStatus.CREATED;
@@ -1826,7 +2204,7 @@ function getStatusFromActions(actions) {
1826
2204
  if (action.type === ActionType.REJECT) {
1827
2205
  return EventStatus.REJECTED;
1828
2206
  }
1829
- if (action.type === ActionType.ARCHIVED) {
2207
+ if (action.type === ActionType.ARCHIVE) {
1830
2208
  return EventStatus.ARCHIVED;
1831
2209
  }
1832
2210
  if (action.type === ActionType.NOTIFY) {
@@ -1846,7 +2224,7 @@ function getAssignedUserFromActions(actions) {
1846
2224
  return user2;
1847
2225
  }, null);
1848
2226
  }
1849
- function getData(actions) {
2227
+ function aggregateActionDeclarations(actions) {
1850
2228
  const excludedActions = [
1851
2229
  ActionType.REQUEST_CORRECTION,
1852
2230
  ActionType.PRINT_CERTIFICATE
@@ -1860,46 +2238,34 @@ function getData(actions) {
1860
2238
  if (!requestAction) {
1861
2239
  return status;
1862
2240
  }
1863
- return deepMerge(status, requestAction.data);
2241
+ return deepMerge(status, requestAction.declaration);
1864
2242
  }
1865
- return deepMerge(status, action.data);
2243
+ return deepMerge(status, action.declaration);
1866
2244
  }, {});
1867
2245
  }
1868
2246
  function deepDropNulls(obj) {
1869
- if (!_.isObject(obj)) return obj;
1870
- return Object.entries(obj).reduce((acc, [key, value]) => {
1871
- if (_.isObject(value)) {
1872
- value = deepDropNulls(value);
1873
- }
1874
- if (value !== null) {
1875
- return {
1876
- ...acc,
1877
- [key]: value
1878
- };
1879
- }
1880
- return acc;
1881
- }, {});
1882
- }
1883
- function deepMerge(currentDocument, actionDocument) {
1884
- return _.mergeWith(
1885
- currentDocument,
1886
- actionDocument,
1887
- (previousValue, incomingValue) => {
1888
- if (incomingValue === void 0) {
1889
- return previousValue;
1890
- }
1891
- if (_.isArray(incomingValue)) {
1892
- return incomingValue;
1893
- }
1894
- if (_.isObject(previousValue) && _.isObject(incomingValue)) {
1895
- return void 0;
1896
- }
1897
- return incomingValue;
1898
- }
1899
- );
2247
+ if (Array.isArray(obj)) {
2248
+ return obj;
2249
+ }
2250
+ if (obj !== null && typeof obj === "object") {
2251
+ return Object.entries(obj).reduce((acc, [key, value]) => {
2252
+ const cleanedValue = deepDropNulls(value);
2253
+ if (cleanedValue !== null) {
2254
+ ;
2255
+ acc[key] = cleanedValue;
2256
+ }
2257
+ return acc;
2258
+ }, {});
2259
+ }
2260
+ return obj;
1900
2261
  }
1901
- function isUndeclaredDraft(event2) {
1902
- return event2.actions.every(({ type }) => type === ActionType.CREATE);
2262
+ function isUndeclaredDraft(status) {
2263
+ return status === EventStatus.CREATED;
2264
+ }
2265
+ function getAcceptedActions(event2) {
2266
+ return event2.actions.filter(
2267
+ (a) => a.status === ActionStatus.Accepted
2268
+ );
1903
2269
  }
1904
2270
  function getCurrentEventState(event2) {
1905
2271
  const creationAction = event2.actions.find(
@@ -1908,7 +2274,12 @@ function getCurrentEventState(event2) {
1908
2274
  if (!creationAction) {
1909
2275
  throw new Error(`Event ${event2.id} has no creation action`);
1910
2276
  }
1911
- const latestAction = event2.actions[event2.actions.length - 1];
2277
+ const activeActions = getAcceptedActions(event2);
2278
+ const latestAction = activeActions[activeActions.length - 1];
2279
+ const registrationAction = activeActions.find(
2280
+ (a) => a.type === ActionType.REGISTER && a.status === ActionStatus.Accepted
2281
+ );
2282
+ const registrationNumber = registrationAction?.registrationNumber ?? null;
1912
2283
  return deepDropNulls({
1913
2284
  id: event2.id,
1914
2285
  type: event2.type,
@@ -1917,16 +2288,17 @@ function getCurrentEventState(event2) {
1917
2288
  createdBy: creationAction.createdBy,
1918
2289
  createdAtLocation: creationAction.createdAtLocation,
1919
2290
  modifiedAt: latestAction.createdAt,
1920
- assignedTo: getAssignedUserFromActions(event2.actions),
2291
+ assignedTo: getAssignedUserFromActions(activeActions),
1921
2292
  updatedBy: latestAction.createdBy,
1922
- data: getData(event2.actions),
1923
- trackingId: event2.trackingId
2293
+ updatedAtLocation: event2.updatedAtLocation,
2294
+ declaration: aggregateActionDeclarations(activeActions),
2295
+ trackingId: event2.trackingId,
2296
+ registrationNumber
1924
2297
  });
1925
2298
  }
1926
2299
  function getCurrentEventStateWithDrafts(event2, drafts) {
1927
- const actions = event2.actions.slice().sort();
1928
- const lastAction = actions[actions.length - 1];
1929
- const activeDrafts = drafts.filter(({ eventId }) => eventId === event2.id).filter(({ createdAt }) => createdAt > lastAction.createdAt).map((draft) => draft.action).flatMap((action) => {
2300
+ const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2301
+ const activeDrafts = findActiveDrafts(event2, drafts).map((draft) => draft.action).flatMap((action) => {
1930
2302
  if (action.type === ActionType.REQUEST_CORRECTION) {
1931
2303
  return [
1932
2304
  action,
@@ -1953,46 +2325,46 @@ function applyDraftsToEventIndex(eventIndex, drafts) {
1953
2325
  }
1954
2326
  return {
1955
2327
  ...eventIndex,
1956
- data: {
1957
- ...eventIndex.data,
1958
- ...activeDrafts[activeDrafts.length - 1].data
2328
+ declaration: {
2329
+ ...eventIndex.declaration,
2330
+ ...activeDrafts[activeDrafts.length - 1].declaration
1959
2331
  }
1960
2332
  };
1961
2333
  }
1962
- function getMetadataForAction({
2334
+ function getAnnotationFromDrafts(drafts) {
2335
+ const actions = drafts.map((draft) => draft.action);
2336
+ const annotation = actions.reduce((ann, action) => {
2337
+ return deepMerge(ann, action.annotation ?? {});
2338
+ }, {});
2339
+ return deepDropNulls(annotation);
2340
+ }
2341
+ function getActionAnnotation({
1963
2342
  event: event2,
1964
2343
  actionType,
1965
2344
  drafts
1966
2345
  }) {
1967
- const action = event2.actions.find((action2) => actionType === action2.type);
2346
+ const activeActions = getAcceptedActions(event2);
2347
+ const action = activeActions.find(
2348
+ (activeAction) => actionType === activeAction.type
2349
+ );
1968
2350
  const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
1969
2351
  const sorted = [
1970
2352
  ...action ? [action] : [],
1971
2353
  ...eventDrafts.map((draft) => draft.action)
1972
2354
  ].sort();
1973
- const metadata = sorted.reduce((metadata2, action2) => {
1974
- return deepMerge(metadata2, action2.metadata ?? {});
2355
+ const annotation = sorted.reduce((ann, sortedAction) => {
2356
+ return deepMerge(ann, sortedAction.annotation ?? {});
1975
2357
  }, {});
1976
- return deepDropNulls(metadata);
2358
+ return deepDropNulls(annotation);
1977
2359
  }
1978
2360
 
1979
2361
  // ../commons/src/events/defineConfig.ts
1980
2362
  var defineConfig = (config) => {
1981
2363
  validateWorkqueueConfig(config.workqueues);
1982
2364
  const input = EventConfig.parse(config);
1983
- const pageFields = findInputPageFields(input);
1984
- return EventConfig.parse({
1985
- ...input,
1986
- pageFields
1987
- });
2365
+ return input;
1988
2366
  };
1989
2367
 
1990
- // ../commons/src/uuid.ts
1991
- var import_uuid = require("uuid");
1992
- function getUUID() {
1993
- return (0, import_uuid.v4)();
1994
- }
1995
-
1996
2368
  // ../commons/src/events/transactions.ts
1997
2369
  function generateTransactionId() {
1998
2370
  return getUUID();
@@ -2005,6 +2377,16 @@ var import_lodash2 = require("lodash");
2005
2377
  function defineConditional(schema) {
2006
2378
  return schema;
2007
2379
  }
2380
+ function defineFormConditional(schema) {
2381
+ const schemaWithForm = {
2382
+ type: "object",
2383
+ properties: {
2384
+ $form: schema
2385
+ },
2386
+ required: ["$form"]
2387
+ };
2388
+ return defineConditional(schemaWithForm);
2389
+ }
2008
2390
  function alwaysTrue() {
2009
2391
  return {};
2010
2392
  }
@@ -2029,6 +2411,9 @@ function not(condition) {
2029
2411
  required: []
2030
2412
  });
2031
2413
  }
2414
+ function never() {
2415
+ return not(alwaysTrue());
2416
+ }
2032
2417
  var user = {
2033
2418
  hasScope: (scope) => defineConditional({
2034
2419
  type: "object",
@@ -2076,69 +2461,120 @@ var event = {
2076
2461
  required: ["$event"]
2077
2462
  })
2078
2463
  };
2464
+ function getDateFromNow(days) {
2465
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2466
+ }
2467
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2468
+ return {
2469
+ type: "object",
2470
+ properties: {
2471
+ [fieldId]: {
2472
+ type: "string",
2473
+ format: "date",
2474
+ [clause]: { $data: `1/${comparedFieldId}` }
2475
+ },
2476
+ [comparedFieldId]: { type: "string", format: "date" }
2477
+ },
2478
+ required: [fieldId]
2479
+ };
2480
+ }
2481
+ function isFieldReference(value) {
2482
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2483
+ }
2079
2484
  function field(fieldId) {
2080
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2081
2485
  const getDateRange = (date, clause) => ({
2082
2486
  type: "object",
2083
2487
  properties: {
2084
- $form: {
2085
- type: "object",
2086
- properties: {
2087
- [fieldId]: {
2088
- type: "string",
2089
- format: "date",
2090
- [clause]: date
2091
- }
2092
- },
2093
- required: [fieldId]
2488
+ [fieldId]: {
2489
+ type: "string",
2490
+ format: "date",
2491
+ [clause]: date
2094
2492
  }
2095
2493
  },
2096
- required: ["$form"]
2494
+ required: [fieldId]
2097
2495
  });
2098
2496
  return {
2497
+ /**
2498
+ * @private Internal property used for field reference tracking.
2499
+ */
2500
+ _fieldId: fieldId,
2099
2501
  isAfter: () => ({
2100
2502
  days: (days) => ({
2101
- inPast: () => defineConditional(
2503
+ inPast: () => defineFormConditional(
2102
2504
  getDateRange(getDateFromNow(days), "formatMinimum")
2103
2505
  ),
2104
- inFuture: () => defineConditional(
2506
+ inFuture: () => defineFormConditional(
2105
2507
  getDateRange(getDateFromNow(-days), "formatMinimum")
2106
2508
  )
2107
2509
  }),
2108
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
2109
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2510
+ date: (date) => {
2511
+ if (isFieldReference(date)) {
2512
+ const comparedFieldId = date._fieldId;
2513
+ return defineFormConditional(
2514
+ getDateRangeToFieldReference(
2515
+ fieldId,
2516
+ comparedFieldId,
2517
+ "formatMinimum"
2518
+ )
2519
+ );
2520
+ }
2521
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2522
+ },
2523
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2110
2524
  }),
2111
2525
  isBefore: () => ({
2112
2526
  days: (days) => ({
2113
- inPast: () => defineConditional(
2527
+ inPast: () => defineFormConditional(
2114
2528
  getDateRange(getDateFromNow(days), "formatMaximum")
2115
2529
  ),
2116
- inFuture: () => defineConditional(
2530
+ inFuture: () => defineFormConditional(
2117
2531
  getDateRange(getDateFromNow(-days), "formatMaximum")
2118
2532
  )
2119
2533
  }),
2120
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
2121
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2534
+ date: (date) => {
2535
+ if (isFieldReference(date)) {
2536
+ const comparedFieldId = date._fieldId;
2537
+ return defineFormConditional(
2538
+ getDateRangeToFieldReference(
2539
+ fieldId,
2540
+ comparedFieldId,
2541
+ "formatMaximum"
2542
+ )
2543
+ );
2544
+ }
2545
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2546
+ },
2547
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2122
2548
  }),
2123
- isEqualTo: (value) => defineConditional({
2124
- type: "object",
2125
- properties: {
2126
- $form: {
2549
+ isEqualTo: (value) => {
2550
+ if (isFieldReference(value)) {
2551
+ const comparedFieldId = value._fieldId;
2552
+ return defineFormConditional({
2127
2553
  type: "object",
2128
2554
  properties: {
2129
2555
  [fieldId]: {
2130
- oneOf: [
2131
- { type: "string", const: value },
2132
- { type: "boolean", const: value }
2133
- ],
2134
- const: value
2135
- }
2556
+ type: ["string", "boolean"],
2557
+ const: { $data: `1/${comparedFieldId}` }
2558
+ },
2559
+ [comparedFieldId]: { type: ["string", "boolean"] }
2136
2560
  },
2137
- required: [fieldId]
2138
- }
2139
- },
2140
- required: ["$form"]
2141
- }),
2561
+ required: [fieldId, comparedFieldId]
2562
+ });
2563
+ }
2564
+ return defineFormConditional({
2565
+ type: "object",
2566
+ properties: {
2567
+ [fieldId]: {
2568
+ oneOf: [
2569
+ { type: "string", const: value },
2570
+ { type: "boolean", const: value }
2571
+ ],
2572
+ const: value
2573
+ }
2574
+ },
2575
+ required: [fieldId]
2576
+ });
2577
+ },
2142
2578
  /**
2143
2579
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
2144
2580
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -2147,91 +2583,102 @@ function field(fieldId) {
2147
2583
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2148
2584
  *
2149
2585
  */
2150
- isFalsy: () => defineConditional({
2586
+ isFalsy: () => defineFormConditional({
2151
2587
  type: "object",
2152
2588
  properties: {
2153
- $form: {
2154
- type: "object",
2155
- properties: {
2156
- [fieldId]: {
2157
- anyOf: [
2158
- { const: "undefined" },
2159
- { const: false },
2160
- { const: null },
2161
- { const: "" }
2162
- ]
2163
- }
2164
- },
2589
+ [fieldId]: {
2165
2590
  anyOf: [
2166
- {
2167
- required: [fieldId]
2168
- },
2169
- {
2170
- not: {
2171
- required: [fieldId]
2172
- }
2173
- }
2591
+ { const: "undefined" },
2592
+ { const: false },
2593
+ { const: null },
2594
+ { const: "" }
2174
2595
  ]
2175
2596
  }
2176
2597
  },
2177
- required: ["$form"]
2178
- }),
2179
- isUndefined: () => defineConditional({
2180
- type: "object",
2181
- properties: {
2182
- $form: {
2183
- type: "object",
2184
- properties: {
2185
- [fieldId]: {
2186
- type: "string",
2187
- enum: ["undefined"]
2188
- }
2189
- },
2598
+ anyOf: [
2599
+ {
2600
+ required: [fieldId]
2601
+ },
2602
+ {
2190
2603
  not: {
2191
2604
  required: [fieldId]
2192
2605
  }
2193
2606
  }
2607
+ ]
2608
+ }),
2609
+ isUndefined: () => defineFormConditional({
2610
+ type: "object",
2611
+ properties: {
2612
+ [fieldId]: {
2613
+ type: "string",
2614
+ enum: ["undefined"]
2615
+ }
2194
2616
  },
2195
- required: ["$form"]
2617
+ not: {
2618
+ required: [fieldId]
2619
+ }
2196
2620
  }),
2197
- inArray: (values) => defineConditional({
2621
+ inArray: (values) => defineFormConditional({
2198
2622
  type: "object",
2199
2623
  properties: {
2200
- $form: {
2201
- type: "object",
2202
- properties: {
2203
- [fieldId]: {
2204
- type: "string",
2205
- enum: values
2206
- }
2207
- },
2208
- required: [fieldId]
2624
+ [fieldId]: {
2625
+ type: "string",
2626
+ enum: values
2627
+ }
2628
+ },
2629
+ required: [fieldId]
2630
+ }),
2631
+ isValidEnglishName: () => defineFormConditional({
2632
+ type: "object",
2633
+ properties: {
2634
+ [fieldId]: {
2635
+ type: "string",
2636
+ pattern: "^[\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*( [\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*)*$",
2637
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2638
+ }
2639
+ },
2640
+ required: [fieldId]
2641
+ }),
2642
+ /**
2643
+ * Checks if the field value matches a given regular expression pattern.
2644
+ * @param pattern - The regular expression pattern to match the field value against.
2645
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2646
+ */
2647
+ matches: (pattern) => defineFormConditional({
2648
+ type: "object",
2649
+ properties: {
2650
+ [fieldId]: {
2651
+ type: "string",
2652
+ pattern
2653
+ }
2654
+ },
2655
+ required: [fieldId]
2656
+ }),
2657
+ isBetween: (min, max) => defineFormConditional({
2658
+ type: "object",
2659
+ properties: {
2660
+ [fieldId]: {
2661
+ type: "number",
2662
+ minimum: min,
2663
+ maximum: max
2209
2664
  }
2210
2665
  },
2211
- required: ["$form"]
2666
+ required: [fieldId]
2212
2667
  })
2213
2668
  };
2214
2669
  }
2215
2670
 
2216
2671
  // ../commons/src/fixtures/tennis-club-membership-event.ts
2217
- var PRINT_CERTIFICATE_FORM = defineForm({
2672
+ var PRINT_CERTIFICATE_FORM = defineActionForm({
2218
2673
  label: {
2219
2674
  id: "v2.event.tennis-club-membership.action.certificate.form.label",
2220
2675
  defaultMessage: "Tennis club membership certificate collector",
2221
2676
  description: "This is what this form is referred as in the system"
2222
2677
  },
2223
- version: {
2224
- id: "1.0.0",
2225
- label: {
2226
- id: "v2.event.tennis-club-membership.action.certificate.form.version.1",
2227
- defaultMessage: "Version 1",
2228
- description: "This is the first version of the form"
2229
- }
2230
- },
2231
- active: true,
2232
2678
  pages: [
2233
2679
  {
2234
2680
  id: "collector",
2681
+ type: PageTypes.enum.FORM,
2235
2682
  title: {
2236
2683
  id: "v2.event.tennis-club-membership.action.certificate.form.section.who.title",
2237
2684
  defaultMessage: "Print certified copy",
@@ -2246,7 +2693,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2246
2693
  defaultMessage: "Requester",
2247
2694
  description: "This is the label for the field"
2248
2695
  },
2249
- type: "SELECT",
2696
+ type: FieldType.SELECT,
2250
2697
  options: [
2251
2698
  {
2252
2699
  value: "INFORMANT",
@@ -2323,7 +2770,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2323
2770
  defaultMessage: "Select Type of ID",
2324
2771
  description: "This is the label for selecting the type of ID"
2325
2772
  },
2326
- type: "SELECT",
2773
+ type: FieldType.SELECT,
2327
2774
  options: [
2328
2775
  {
2329
2776
  value: "PASSPORT",
@@ -2424,7 +2871,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2424
2871
  defaultMessage: "Passport Details",
2425
2872
  description: "Field for entering Passport details"
2426
2873
  },
2427
- type: "TEXT"
2874
+ type: FieldType.TEXT
2428
2875
  },
2429
2876
  {
2430
2877
  id: "collector.DRIVING_LICENSE.details",
@@ -2475,7 +2922,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2475
2922
  defaultMessage: "Driving License Details",
2476
2923
  description: "Field for entering Driving License details"
2477
2924
  },
2478
- type: "TEXT"
2925
+ type: FieldType.TEXT
2479
2926
  },
2480
2927
  {
2481
2928
  id: "collector.REFUGEE_NUMBER.details",
@@ -2526,7 +2973,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2526
2973
  defaultMessage: "Refugee Number Details",
2527
2974
  description: "Field for entering Refugee Number details"
2528
2975
  },
2529
- type: "TEXT"
2976
+ type: FieldType.TEXT
2530
2977
  },
2531
2978
  {
2532
2979
  id: "collector.ALIEN_NUMBER.details",
@@ -2577,7 +3024,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2577
3024
  defaultMessage: "Alien Number Details",
2578
3025
  description: "Field for entering Alien Number details"
2579
3026
  },
2580
- type: "TEXT"
3027
+ type: FieldType.TEXT
2581
3028
  },
2582
3029
  {
2583
3030
  id: "collector.OTHER.idTypeOther",
@@ -2628,7 +3075,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2628
3075
  defaultMessage: "Other ID Type (if applicable)",
2629
3076
  description: 'Field for entering ID type if "Other" is selected'
2630
3077
  },
2631
- type: "TEXT"
3078
+ type: FieldType.TEXT
2632
3079
  },
2633
3080
  {
2634
3081
  id: "collector.OTHER.firstName",
@@ -2679,7 +3126,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2679
3126
  defaultMessage: "First Name",
2680
3127
  description: "This is the label for the first name field"
2681
3128
  },
2682
- type: "TEXT"
3129
+ type: FieldType.TEXT
2683
3130
  },
2684
3131
  {
2685
3132
  id: "collector.OTHER.lastName",
@@ -2730,7 +3177,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2730
3177
  defaultMessage: "Last Name",
2731
3178
  description: "This is the label for the last name field"
2732
3179
  },
2733
- type: "TEXT"
3180
+ type: FieldType.TEXT
2734
3181
  },
2735
3182
  {
2736
3183
  id: "collector.OTHER.relationshipToMember",
@@ -2781,7 +3228,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2781
3228
  defaultMessage: "Relationship to Member",
2782
3229
  description: "This is the label for the relationship to member field"
2783
3230
  },
2784
- type: "TEXT"
3231
+ type: FieldType.TEXT
2785
3232
  },
2786
3233
  {
2787
3234
  id: "collector.OTHER.signedAffidavit",
@@ -2832,66 +3279,88 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2832
3279
  defaultMessage: "Signed Affidavit (Optional)",
2833
3280
  description: "This is the label for uploading a signed affidavit"
2834
3281
  },
2835
- type: "FILE"
3282
+ type: FieldType.FILE
2836
3283
  }
2837
3284
  ]
2838
- }
2839
- ],
2840
- review: {
2841
- title: {
2842
- id: "v2.event.tennis-club-membership.action.certificate.form.review.title",
2843
- defaultMessage: "Member certificate collector for {firstname} {surname}",
2844
- description: "Title of the form to show in review page"
2845
3285
  },
2846
- fields: []
2847
- }
2848
- });
2849
- var TENNIS_CLUB_FORM = defineForm({
2850
- label: {
2851
- id: "v2.event.tennis-club-membership.action.declare.form.label",
2852
- defaultMessage: "Tennis club membership application",
2853
- description: "This is what this form is referred as in the system"
2854
- },
2855
- active: true,
2856
- version: {
2857
- id: "1.0.0",
2858
- label: {
2859
- id: "v2.event.tennis-club-membership.action.declare.form.version.1",
2860
- defaultMessage: "Version 1",
2861
- description: "This is the first version of the form"
3286
+ {
3287
+ id: "collector.identity.verify",
3288
+ type: PageTypes.enum.VERIFICATION,
3289
+ conditional: field("collector.requesterId").isEqualTo("INFORMANT"),
3290
+ title: {
3291
+ id: "event.tennis-club-membership.action.print.verifyIdentity",
3292
+ defaultMessage: "Verify their identity",
3293
+ description: "This is the title of the section"
3294
+ },
3295
+ fields: [],
3296
+ actions: {
3297
+ verify: {
3298
+ label: {
3299
+ defaultMessage: "Verified",
3300
+ description: "This is the label for the verification button",
3301
+ id: "v2.event.tennis-club-membership.action.certificate.form.verify"
3302
+ }
3303
+ },
3304
+ cancel: {
3305
+ label: {
3306
+ defaultMessage: "Identity does not match",
3307
+ description: "This is the label for the verification cancellation button",
3308
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel"
3309
+ },
3310
+ confirmation: {
3311
+ title: {
3312
+ defaultMessage: "Print without proof of ID?",
3313
+ description: "This is the title for the verification cancellation modal",
3314
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel.confirmation.title"
3315
+ },
3316
+ body: {
3317
+ defaultMessage: "Please be aware that if you proceed, you will be responsible for issuing a certificate without the necessary proof of ID from the collector",
3318
+ description: "This is the body for the verification cancellation modal",
3319
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel.confirmation.body"
3320
+ }
3321
+ }
3322
+ }
3323
+ }
2862
3324
  }
3325
+ ]
3326
+ });
3327
+ var TENNIS_CLUB_DECLARATION_REVIEW = {
3328
+ title: {
3329
+ id: "v2.event.tennis-club-membership.action.declare.form.review.title",
3330
+ defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
3331
+ description: "Title of the review page"
2863
3332
  },
2864
- review: {
2865
- title: {
2866
- id: "v2.event.tennis-club-membership.action.declare.form.review.title",
2867
- defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
2868
- description: "Title of the form to show in review page"
3333
+ fields: [
3334
+ {
3335
+ id: "review.comment",
3336
+ type: FieldType.TEXTAREA,
3337
+ label: {
3338
+ defaultMessage: "Comment",
3339
+ id: "v2.event.birth.action.declare.form.review.comment.label",
3340
+ description: "Label for the comment field in the review section"
3341
+ }
2869
3342
  },
2870
- fields: [
2871
- {
2872
- id: "review.comment",
2873
- type: "TEXTAREA",
2874
- label: {
2875
- defaultMessage: "Comment",
2876
- id: "v2.event.birth.action.declare.form.review.comment.label",
2877
- description: "Label for the comment field in the review section"
2878
- }
3343
+ {
3344
+ type: FieldType.SIGNATURE,
3345
+ id: "review.signature",
3346
+ label: {
3347
+ defaultMessage: "Signature of informant",
3348
+ id: "v2.event.birth.action.declare.form.review.signature.label",
3349
+ description: "Label for the signature field in the review section"
2879
3350
  },
2880
- {
2881
- type: "SIGNATURE",
2882
- id: "review.signature",
2883
- label: {
2884
- defaultMessage: "Signature of informant",
2885
- id: "v2.event.birth.action.declare.form.review.signature.label",
2886
- description: "Label for the signature field in the review section"
2887
- },
2888
- signaturePromptLabel: {
2889
- id: "v2.signature.upload.modal.title",
2890
- defaultMessage: "Draw signature",
2891
- description: "Title for the modal to draw signature"
2892
- }
3351
+ signaturePromptLabel: {
3352
+ id: "v2.signature.upload.modal.title",
3353
+ defaultMessage: "Draw signature",
3354
+ description: "Title for the modal to draw signature"
2893
3355
  }
2894
- ]
3356
+ }
3357
+ ]
3358
+ };
3359
+ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3360
+ label: {
3361
+ id: "v2.event.tennis-club-membership.action.declare.form.label",
3362
+ defaultMessage: "Tennis club membership application",
3363
+ description: "This is what this form is referred as in the system"
2895
3364
  },
2896
3365
  pages: [
2897
3366
  {
@@ -2904,7 +3373,7 @@ var TENNIS_CLUB_FORM = defineForm({
2904
3373
  fields: [
2905
3374
  {
2906
3375
  id: "applicant.firstname",
2907
- type: "TEXT",
3376
+ type: FieldType.TEXT,
2908
3377
  required: true,
2909
3378
  conditionals: [],
2910
3379
  label: {
@@ -2915,7 +3384,7 @@ var TENNIS_CLUB_FORM = defineForm({
2915
3384
  },
2916
3385
  {
2917
3386
  id: "applicant.surname",
2918
- type: "TEXT",
3387
+ type: FieldType.TEXT,
2919
3388
  required: true,
2920
3389
  conditionals: [],
2921
3390
  label: {
@@ -2958,7 +3427,7 @@ var TENNIS_CLUB_FORM = defineForm({
2958
3427
  },
2959
3428
  {
2960
3429
  id: "applicant.image",
2961
- type: "FILE",
3430
+ type: FieldType.FILE,
2962
3431
  required: false,
2963
3432
  label: {
2964
3433
  defaultMessage: "Applicant's profile picture",
@@ -2979,6 +3448,27 @@ var TENNIS_CLUB_FORM = defineForm({
2979
3448
  }
2980
3449
  ]
2981
3450
  },
3451
+ {
3452
+ id: "senior-pass",
3453
+ conditional: field("applicant.dob").isBefore().date("1950-01-01"),
3454
+ title: {
3455
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.title",
3456
+ defaultMessage: "Assign senior pass for applicant",
3457
+ description: "This is the title of the section"
3458
+ },
3459
+ fields: [
3460
+ {
3461
+ id: "senior-pass.id",
3462
+ type: FieldType.TEXT,
3463
+ required: true,
3464
+ label: {
3465
+ defaultMessage: "Senior pass ID",
3466
+ description: "This is the label for the field",
3467
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.field.id.label"
3468
+ }
3469
+ }
3470
+ ]
3471
+ },
2982
3472
  {
2983
3473
  id: "recommender",
2984
3474
  title: {
@@ -3000,7 +3490,7 @@ var TENNIS_CLUB_FORM = defineForm({
3000
3490
  },
3001
3491
  {
3002
3492
  id: "recommender.firstname",
3003
- type: "TEXT",
3493
+ type: FieldType.TEXT,
3004
3494
  required: true,
3005
3495
  conditionals: [
3006
3496
  {
@@ -3016,7 +3506,7 @@ var TENNIS_CLUB_FORM = defineForm({
3016
3506
  },
3017
3507
  {
3018
3508
  id: "recommender.surname",
3019
- type: "TEXT",
3509
+ type: FieldType.TEXT,
3020
3510
  required: true,
3021
3511
  conditionals: [
3022
3512
  {
@@ -3032,7 +3522,7 @@ var TENNIS_CLUB_FORM = defineForm({
3032
3522
  },
3033
3523
  {
3034
3524
  id: "recommender.id",
3035
- type: "TEXT",
3525
+ type: FieldType.TEXT,
3036
3526
  required: true,
3037
3527
  conditionals: [
3038
3528
  {
@@ -3140,7 +3630,7 @@ var tennisClubMembershipEvent = defineConfig({
3140
3630
  description: "This is shown as the action name anywhere the user can trigger the action from",
3141
3631
  id: "event.tennis-club-membership.action.declare.label"
3142
3632
  },
3143
- forms: [TENNIS_CLUB_FORM]
3633
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3144
3634
  },
3145
3635
  {
3146
3636
  type: ActionType.VALIDATE,
@@ -3149,7 +3639,7 @@ var tennisClubMembershipEvent = defineConfig({
3149
3639
  description: "This is shown as the action name anywhere the user can trigger the action from",
3150
3640
  id: "event.tennis-club-membership.action.validate.label"
3151
3641
  },
3152
- forms: [TENNIS_CLUB_FORM]
3642
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3153
3643
  },
3154
3644
  {
3155
3645
  type: ActionType.REGISTER,
@@ -3158,7 +3648,7 @@ var tennisClubMembershipEvent = defineConfig({
3158
3648
  description: "This is shown as the action name anywhere the user can trigger the action from",
3159
3649
  id: "event.tennis-club-membership.action.register.label"
3160
3650
  },
3161
- forms: [TENNIS_CLUB_FORM]
3651
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3162
3652
  },
3163
3653
  {
3164
3654
  type: ActionType.REQUEST_CORRECTION,
@@ -3167,10 +3657,10 @@ var tennisClubMembershipEvent = defineConfig({
3167
3657
  description: "This is shown as the action name anywhere the user can trigger the action from",
3168
3658
  id: "event.tennis-club-membership.action.correction.request.label"
3169
3659
  },
3170
- forms: [TENNIS_CLUB_FORM],
3171
3660
  onboardingForm: [
3172
3661
  {
3173
3662
  id: "correction-requester",
3663
+ type: PageTypes.enum.FORM,
3174
3664
  title: {
3175
3665
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3176
3666
  defaultMessage: "Correction requester",
@@ -3234,6 +3724,7 @@ var tennisClubMembershipEvent = defineConfig({
3234
3724
  },
3235
3725
  {
3236
3726
  id: "identity-check",
3727
+ type: PageTypes.enum.FORM,
3237
3728
  title: {
3238
3729
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3239
3730
  defaultMessage: "Verify their identity",
@@ -3276,6 +3767,7 @@ var tennisClubMembershipEvent = defineConfig({
3276
3767
  additionalDetailsForm: [
3277
3768
  {
3278
3769
  id: "correction-request.supporting-documents",
3770
+ type: PageTypes.enum.FORM,
3279
3771
  title: {
3280
3772
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3281
3773
  defaultMessage: "Upload supporting documents",
@@ -3293,7 +3785,7 @@ var tennisClubMembershipEvent = defineConfig({
3293
3785
  },
3294
3786
  {
3295
3787
  id: "correction.supportingDocs",
3296
- type: "FILE",
3788
+ type: FieldType.FILE,
3297
3789
  label: {
3298
3790
  id: "correction.corrector.title",
3299
3791
  defaultMessage: "Upload supporting documents",
@@ -3337,6 +3829,7 @@ var tennisClubMembershipEvent = defineConfig({
3337
3829
  },
3338
3830
  {
3339
3831
  id: "correction-request.additional-details",
3832
+ type: PageTypes.enum.FORM,
3340
3833
  title: {
3341
3834
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3342
3835
  defaultMessage: "Reason for correction",
@@ -3345,7 +3838,7 @@ var tennisClubMembershipEvent = defineConfig({
3345
3838
  fields: [
3346
3839
  {
3347
3840
  id: "correction.request.reason",
3348
- type: "TEXT",
3841
+ type: FieldType.TEXT,
3349
3842
  label: {
3350
3843
  id: "correction.reason.title",
3351
3844
  defaultMessage: "Reason for correction?",
@@ -3358,7 +3851,6 @@ var tennisClubMembershipEvent = defineConfig({
3358
3851
  },
3359
3852
  {
3360
3853
  type: ActionType.APPROVE_CORRECTION,
3361
- forms: [TENNIS_CLUB_FORM],
3362
3854
  label: {
3363
3855
  defaultMessage: "Approve correction",
3364
3856
  description: "This is shown as the action name anywhere the user can trigger the action from",
@@ -3372,7 +3864,7 @@ var tennisClubMembershipEvent = defineConfig({
3372
3864
  defaultMessage: "Print certificate",
3373
3865
  description: "This is shown as the action name anywhere the user can trigger the action from"
3374
3866
  },
3375
- forms: [PRINT_CERTIFICATE_FORM],
3867
+ printForm: PRINT_CERTIFICATE_FORM,
3376
3868
  conditionals: [
3377
3869
  {
3378
3870
  type: "SHOW",
@@ -3412,6 +3904,22 @@ var tennisClubMembershipEvent = defineConfig({
3412
3904
  })
3413
3905
  }
3414
3906
  ]
3907
+ },
3908
+ {
3909
+ type: ActionType.ARCHIVE,
3910
+ label: {
3911
+ id: "v2.event.tennis-club-membership.action.archive.label",
3912
+ defaultMessage: "Archive",
3913
+ description: "This is shown as the action name anywhere the user can trigger the action from"
3914
+ }
3915
+ },
3916
+ {
3917
+ type: ActionType.REJECT,
3918
+ label: {
3919
+ id: "v2.event.tennis-club-membership.action.reject.label",
3920
+ defaultMessage: "Reject",
3921
+ description: "This is shown as the action name anywhere the user can trigger the action from"
3922
+ }
3415
3923
  }
3416
3924
  ],
3417
3925
  advancedSearch: [
@@ -3427,20 +3935,52 @@ var tennisClubMembershipEvent = defineConfig({
3427
3935
  }
3428
3936
  ]
3429
3937
  }
3430
- ]
3938
+ ],
3939
+ declaration: TENNIS_CLUB_DECLARATION_FORM
3431
3940
  });
3432
3941
 
3433
3942
  // ../commons/src/events/test.utils.ts
3434
- function generateActionInput(configuration, action) {
3435
- const fields = findActiveActionFormFields(configuration, action) ?? [];
3436
- const data = fields.reduce(
3943
+ function fieldConfigsToActionAnnotation(fields) {
3944
+ return fields.reduce(
3437
3945
  (acc, field2, i) => ({
3438
3946
  ...acc,
3439
3947
  [field2.id]: mapFieldTypeToMockValue(field2, i)
3440
3948
  }),
3441
3949
  {}
3442
3950
  );
3443
- return stripHiddenFields(fields, data);
3951
+ }
3952
+ function generateActionInput(configuration, action) {
3953
+ const parsed = DeclarationUpdateActions.safeParse(action);
3954
+ if (parsed.success) {
3955
+ const fields = getDeclarationFields(configuration);
3956
+ const annotation = fieldConfigsToActionAnnotation(fields);
3957
+ return stripHiddenFields(fields, annotation);
3958
+ }
3959
+ console.warn(`${action} is not a declaration action. Setting data as {}.`);
3960
+ return {};
3961
+ }
3962
+ function generateActionMetadataInput(configuration, action) {
3963
+ const actionConfig = configuration.actions.find(
3964
+ (ac) => ac.type === action
3965
+ );
3966
+ const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
3967
+ const annotation = fieldConfigsToActionAnnotation(annotationFields);
3968
+ const visibleVerificationPageIds = findRecordActionPages(
3969
+ configuration,
3970
+ action
3971
+ ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
3972
+ const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
3973
+ (acc, pageId) => ({
3974
+ ...acc,
3975
+ [pageId]: true
3976
+ }),
3977
+ {}
3978
+ );
3979
+ const fieldBasedPayload = stripHiddenFields(annotationFields, annotation);
3980
+ return {
3981
+ ...fieldBasedPayload,
3982
+ ...visiblePageVerificationMap
3983
+ };
3444
3984
  }
3445
3985
  var eventPayloadGenerator = {
3446
3986
  create: (input = {}) => ({
@@ -3452,21 +3992,22 @@ var eventPayloadGenerator = {
3452
3992
  type: input.type ?? "TENNIS_CLUB_MEMBERSHIP",
3453
3993
  id
3454
3994
  }),
3455
- draft: (eventId, input = {}) => (0, import_lodash2.merge)(
3995
+ draft: ({ eventId, actionType }, input = {}) => (0, import_lodash2.merge)(
3456
3996
  {
3457
3997
  id: getUUID(),
3458
3998
  eventId,
3459
3999
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3460
4000
  transactionId: getUUID(),
3461
4001
  action: {
3462
- type: ActionType.REQUEST_CORRECTION,
3463
- data: {
4002
+ type: actionType,
4003
+ status: ActionStatus.Accepted,
4004
+ declaration: {
3464
4005
  "applicant.firstname": "Max",
3465
4006
  "applicant.surname": "McLaren",
3466
4007
  "applicant.dob": "2020-01-02",
3467
4008
  "recommender.none": true
3468
4009
  },
3469
- metadata: {
4010
+ annotation: {
3470
4011
  "correction.requester.relationship": "ANOTHER_AGENT",
3471
4012
  "correction.request.reason": "Child's name was incorrect"
3472
4013
  },
@@ -3481,41 +4022,92 @@ var eventPayloadGenerator = {
3481
4022
  declare: (eventId, input = {}) => ({
3482
4023
  type: ActionType.DECLARE,
3483
4024
  transactionId: input.transactionId ?? getUUID(),
3484
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4025
+ declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4026
+ annotation: input.annotation ?? generateActionMetadataInput(
4027
+ tennisClubMembershipEvent,
4028
+ ActionType.DECLARE
4029
+ ),
3485
4030
  eventId
3486
4031
  }),
4032
+ /**
4033
+ * Notify allows sending incomplete data. Think it as 'partial declare' for now.
4034
+ */
4035
+ notify: (eventId, input = {}) => {
4036
+ let declaration = input.declaration;
4037
+ if (!declaration) {
4038
+ const partialDeclaration = (0, import_lodash2.omitBy)(
4039
+ generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4040
+ import_lodash2.isString
4041
+ );
4042
+ declaration = partialDeclaration;
4043
+ }
4044
+ return {
4045
+ type: ActionType.NOTIFY,
4046
+ transactionId: input.transactionId ?? getUUID(),
4047
+ declaration,
4048
+ eventId
4049
+ };
4050
+ },
3487
4051
  validate: (eventId, input = {}) => ({
3488
4052
  type: ActionType.VALIDATE,
3489
4053
  transactionId: input.transactionId ?? getUUID(),
3490
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4054
+ declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4055
+ annotation: input.annotation ?? generateActionMetadataInput(
4056
+ tennisClubMembershipEvent,
4057
+ ActionType.VALIDATE
4058
+ ),
3491
4059
  duplicates: [],
3492
4060
  eventId
3493
4061
  }),
4062
+ assign: (eventId, input = {}) => ({
4063
+ type: ActionType.ASSIGN,
4064
+ transactionId: input.transactionId ?? getUUID(),
4065
+ declaration: {},
4066
+ assignedTo: input.assignedTo ?? getUUID(),
4067
+ eventId
4068
+ }),
4069
+ unassign: (eventId, input = {}) => ({
4070
+ type: ActionType.UNASSIGN,
4071
+ transactionId: input.transactionId ?? getUUID(),
4072
+ declaration: {},
4073
+ assignedTo: null,
4074
+ eventId
4075
+ }),
3494
4076
  archive: (eventId, input = {}, isDuplicate) => ({
3495
- type: ActionType.ARCHIVED,
4077
+ type: ActionType.ARCHIVE,
3496
4078
  transactionId: input.transactionId ?? getUUID(),
3497
- data: input.data ?? {},
3498
- metadata: { isDuplicate: isDuplicate ?? false },
4079
+ declaration: {},
4080
+ // @TODO: Check whether generator is needed?
4081
+ annotation: { isDuplicate: isDuplicate ?? false },
3499
4082
  duplicates: [],
3500
4083
  eventId
3501
4084
  }),
3502
4085
  reject: (eventId, input = {}) => ({
3503
4086
  type: ActionType.REJECT,
3504
4087
  transactionId: input.transactionId ?? getUUID(),
3505
- data: input.data ?? {},
4088
+ declaration: {},
4089
+ annotation: input.annotation ?? generateActionMetadataInput(
4090
+ tennisClubMembershipEvent,
4091
+ ActionType.REJECT
4092
+ ),
3506
4093
  duplicates: [],
3507
4094
  eventId
3508
4095
  }),
3509
4096
  register: (eventId, input = {}) => ({
3510
4097
  type: ActionType.REGISTER,
3511
4098
  transactionId: input.transactionId ?? getUUID(),
3512
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4099
+ declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4100
+ annotation: input.annotation ?? generateActionMetadataInput(
4101
+ tennisClubMembershipEvent,
4102
+ ActionType.REGISTER
4103
+ ),
3513
4104
  eventId
3514
4105
  }),
3515
4106
  printCertificate: (eventId, input = {}) => ({
3516
4107
  type: ActionType.PRINT_CERTIFICATE,
3517
4108
  transactionId: input.transactionId ?? getUUID(),
3518
- data: input.data ?? generateActionInput(
4109
+ declaration: {},
4110
+ annotation: input.annotation ?? generateActionMetadataInput(
3519
4111
  tennisClubMembershipEvent,
3520
4112
  ActionType.PRINT_CERTIFICATE
3521
4113
  ),
@@ -3525,17 +4117,21 @@ var eventPayloadGenerator = {
3525
4117
  request: (eventId, input = {}) => ({
3526
4118
  type: ActionType.REQUEST_CORRECTION,
3527
4119
  transactionId: input.transactionId ?? getUUID(),
3528
- data: input.data ?? generateActionInput(
4120
+ declaration: input.declaration ?? generateActionInput(
4121
+ tennisClubMembershipEvent,
4122
+ ActionType.REQUEST_CORRECTION
4123
+ ),
4124
+ annotation: input.annotation ?? generateActionMetadataInput(
3529
4125
  tennisClubMembershipEvent,
3530
4126
  ActionType.REQUEST_CORRECTION
3531
4127
  ),
3532
- metadata: {},
3533
4128
  eventId
3534
4129
  }),
3535
4130
  approve: (eventId, requestId, input = {}) => ({
3536
4131
  type: ActionType.APPROVE_CORRECTION,
3537
4132
  transactionId: input.transactionId ?? getUUID(),
3538
- data: input.data ?? generateActionInput(
4133
+ declaration: {},
4134
+ annotation: input.annotation ?? generateActionMetadataInput(
3539
4135
  tennisClubMembershipEvent,
3540
4136
  ActionType.APPROVE_CORRECTION
3541
4137
  ),
@@ -3545,7 +4141,8 @@ var eventPayloadGenerator = {
3545
4141
  reject: (eventId, requestId, input = {}) => ({
3546
4142
  type: ActionType.REJECT_CORRECTION,
3547
4143
  transactionId: input.transactionId ?? getUUID(),
3548
- data: input.data ?? generateActionInput(
4144
+ declaration: {},
4145
+ annotation: input.annotation ?? generateActionMetadataInput(
3549
4146
  tennisClubMembershipEvent,
3550
4147
  ActionType.REJECT_CORRECTION
3551
4148
  ),
@@ -3561,15 +4158,22 @@ function generateActionDocument({
3561
4158
  defaults = {}
3562
4159
  }) {
3563
4160
  const actionBase = {
3564
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4161
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4162
+ // @TODO: This should be fixed in the future.
4163
+ createdAt: new Date(Date.now() - 500).toISOString(),
3565
4164
  createdBy: getUUID(),
3566
4165
  id: getUUID(),
3567
4166
  createdAtLocation: "TODO",
3568
- data: generateActionInput(configuration, action),
3569
- metadata: {},
3570
- ...defaults
4167
+ declaration: generateActionInput(configuration, action),
4168
+ annotation: {},
4169
+ ...defaults,
4170
+ status: ActionStatus.Accepted
3571
4171
  };
3572
4172
  switch (action) {
4173
+ case ActionType.READ:
4174
+ return { ...actionBase, type: action };
4175
+ case ActionType.MARKED_AS_DUPLICATE:
4176
+ return { ...actionBase, type: action };
3573
4177
  case ActionType.DECLARE:
3574
4178
  return { ...actionBase, type: action };
3575
4179
  case ActionType.UNASSIGN:
@@ -3578,7 +4182,7 @@ function generateActionDocument({
3578
4182
  return { ...actionBase, assignedTo: getUUID(), type: action };
3579
4183
  case ActionType.VALIDATE:
3580
4184
  return { ...actionBase, type: action };
3581
- case ActionType.ARCHIVED:
4185
+ case ActionType.ARCHIVE:
3582
4186
  return { ...actionBase, type: action };
3583
4187
  case ActionType.REJECT:
3584
4188
  return { ...actionBase, type: action };
@@ -3594,14 +4198,13 @@ function generateActionDocument({
3594
4198
  return { ...actionBase, requestId: getUUID(), type: action };
3595
4199
  case ActionType.REJECT_CORRECTION:
3596
4200
  return { ...actionBase, requestId: getUUID(), type: action };
3597
- case ActionType.CUSTOM:
3598
- return { ...actionBase, type: action };
3599
4201
  case ActionType.REGISTER:
3600
4202
  return {
3601
4203
  ...actionBase,
3602
- type: action,
3603
- identifiers: { trackingId: getUUID(), registrationNumber: getUUID() }
4204
+ type: action
3604
4205
  };
4206
+ case ActionType.DELETE:
4207
+ case ActionType.DETECT_DUPLICATE:
3605
4208
  default:
3606
4209
  throw new Error(`Unsupported action type: ${action}`);
3607
4210
  }
@@ -3616,12 +4219,17 @@ function generateEventDocument({
3616
4219
  actions: actions.map(
3617
4220
  (action) => generateActionDocument({ configuration, action })
3618
4221
  ),
3619
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4222
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4223
+ // @TODO: This should be fixed in the future.
4224
+ createdAt: new Date(Date.now() - 1e3).toISOString(),
3620
4225
  id: getUUID(),
3621
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
4226
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4227
+ // @TODO: This should be fixed in the future.
4228
+ updatedAt: new Date(Date.now() - 1e3).toISOString(),
4229
+ updatedAtLocation: "TODO"
3622
4230
  };
3623
4231
  }
3624
- function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, data = {}) {
4232
+ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
3625
4233
  const action = generateActionDocument({
3626
4234
  configuration: tennisClubMembershipEvent,
3627
4235
  action: actionType
@@ -3631,9 +4239,9 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, da
3631
4239
  transactionId: getUUID(),
3632
4240
  action: {
3633
4241
  ...action,
3634
- data: {
3635
- ...action.data,
3636
- ...data
4242
+ declaration: {
4243
+ ...action.declaration,
4244
+ ...declaration
3637
4245
  }
3638
4246
  },
3639
4247
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3647,10 +4255,11 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3647
4255
  createdAt: overrides.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3648
4256
  createdBy: overrides.createdBy ?? getUUID(),
3649
4257
  createdAtLocation: overrides.createdAtLocation ?? getUUID(),
4258
+ updatedAtLocation: overrides.updatedAtLocation ?? getUUID(),
3650
4259
  modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3651
4260
  assignedTo: overrides.assignedTo ?? null,
3652
4261
  updatedBy: overrides.updatedBy ?? getUUID(),
3653
- data: overrides.data ?? {
4262
+ declaration: overrides.declaration ?? {
3654
4263
  "recommender.none": true,
3655
4264
  "applicant.firstname": "Danny",
3656
4265
  "applicant.surname": "Doe",
@@ -3658,3 +4267,40 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3658
4267
  },
3659
4268
  trackingId: overrides.trackingId ?? "M3F8YQ"
3660
4269
  });
4270
+ var generateTranslationConfig = (message) => ({
4271
+ defaultMessage: message,
4272
+ description: "Description for ${message}",
4273
+ id: message
4274
+ });
4275
+
4276
+ // ../commons/src/events/TemplateConfig.ts
4277
+ function isTemplateVariable(value) {
4278
+ return typeof value === "string" && value.startsWith("$");
4279
+ }
4280
+ function isFieldValue(value) {
4281
+ return FieldValue.safeParse(value).success;
4282
+ }
4283
+ function isFieldValueWithoutTemplates(value) {
4284
+ if (isTemplateVariable(value)) {
4285
+ return false;
4286
+ }
4287
+ if (typeof value === "object" && Object.values(value).some((val) => isTemplateVariable(val))) {
4288
+ return false;
4289
+ }
4290
+ return true;
4291
+ }
4292
+ function isFieldConfigDefaultValue(value) {
4293
+ if (!value) {
4294
+ return false;
4295
+ }
4296
+ if (isFieldValue(value)) {
4297
+ return true;
4298
+ }
4299
+ if (isTemplateVariable(value)) {
4300
+ return true;
4301
+ }
4302
+ if (typeof value === "object" && Object.values(value).every((v) => typeof v === "object" && v !== null)) {
4303
+ return Object.values(value).every((v) => isFieldConfigDefaultValue(v));
4304
+ }
4305
+ return false;
4306
+ }