@opencrvs/toolkit 1.8.0-rc.f7e8fb5 → 1.8.0-rc.f872339

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 (36) hide show
  1. package/README.md +1 -1
  2. package/dist/commons/api/router.d.ts +6700 -9337
  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 -17
  6. package/dist/commons/conditionals/validate.test.d.ts +2 -0
  7. package/dist/commons/events/ActionConfig.d.ts +1123 -2056
  8. package/dist/commons/events/ActionDocument.d.ts +9488 -312
  9. package/dist/commons/events/ActionInput.d.ts +5329 -472
  10. package/dist/commons/events/ActionType.d.ts +26 -11
  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 +351 -48
  14. package/dist/commons/events/EventConfig.d.ts +709 -1226
  15. package/dist/commons/events/EventConfigInput.d.ts +6 -3
  16. package/dist/commons/events/EventDocument.d.ts +3343 -424
  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 +567 -74
  20. package/dist/commons/events/FieldType.d.ts +2 -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/SummaryConfig.d.ts +93 -7
  26. package/dist/commons/events/TemplateConfig.d.ts +5 -5
  27. package/dist/commons/events/User.d.ts +5 -0
  28. package/dist/commons/events/defineConfig.d.ts +104 -218
  29. package/dist/commons/events/index.d.ts +3 -1
  30. package/dist/commons/events/scopes.d.ts +25 -0
  31. package/dist/commons/events/test.utils.d.ts +140 -213
  32. package/dist/commons/events/utils.d.ts +125 -83
  33. package/dist/commons/events/utils.test.d.ts +2 -0
  34. package/dist/conditionals/index.js +166 -81
  35. package/dist/events/index.js +1644 -832
  36. package/package.json +1 -1
@@ -30,30 +30,48 @@ 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_ALLOWED_SCOPES: () => ACTION_ALLOWED_SCOPES,
34
+ Action: () => Action,
33
35
  ActionBase: () => ActionBase,
34
36
  ActionConditional: () => ActionConditional,
35
37
  ActionConfig: () => ActionConfig,
36
38
  ActionConfigBase: () => ActionConfigBase,
37
39
  ActionDocument: () => ActionDocument,
40
+ ActionFormConfig: () => ActionFormConfig,
38
41
  ActionInput: () => ActionInput,
42
+ ActionStatus: () => ActionStatus,
39
43
  ActionType: () => ActionType,
44
+ ActionTypes: () => ActionTypes,
40
45
  ActionUpdate: () => ActionUpdate,
41
46
  AddressFieldUpdateValue: () => AddressFieldUpdateValue,
42
47
  AddressFieldValue: () => AddressFieldValue,
48
+ AddressType: () => AddressType,
43
49
  AdministrativeAreas: () => AdministrativeAreas,
44
50
  AdvancedSearchConfig: () => AdvancedSearchConfig,
45
51
  ApproveCorrectionActionInput: () => ApproveCorrectionActionInput,
46
52
  ArchiveActionInput: () => ArchiveActionInput,
53
+ AssignActionInput: () => AssignActionInput,
54
+ AsyncRejectActionDocument: () => AsyncRejectActionDocument,
47
55
  BaseActionInput: () => BaseActionInput,
56
+ CONFIG_GET_ALLOWED_SCOPES: () => CONFIG_GET_ALLOWED_SCOPES,
48
57
  CertificateConfig: () => CertificateConfig,
49
58
  CertificateTemplateConfig: () => CertificateTemplateConfig,
50
59
  CheckboxFieldValue: () => CheckboxFieldValue,
51
60
  Clause: () => Clause,
52
61
  Conditional: () => Conditional,
53
62
  ConditionalType: () => ConditionalType,
63
+ ConfirmableActions: () => ConfirmableActions,
64
+ DataEntry: () => DataEntry,
65
+ DataFieldValue: () => DataFieldValue,
54
66
  DateValue: () => DateValue,
67
+ DeclarationActionConfig: () => DeclarationActionConfig,
68
+ DeclarationActions: () => DeclarationActions,
69
+ DeclarationFormConfig: () => DeclarationFormConfig,
70
+ DeclarationReviewConfig: () => DeclarationReviewConfig,
71
+ DeclarationUpdateActions: () => DeclarationUpdateActions,
55
72
  DeclareActionInput: () => DeclareActionInput,
56
73
  DeduplicationConfig: () => DeduplicationConfig,
74
+ DisplayOnReviewConditional: () => DisplayOnReviewConditional,
57
75
  Draft: () => Draft,
58
76
  DraftInput: () => DraftInput,
59
77
  EmailField: () => EmailField,
@@ -67,6 +85,7 @@ __export(events_exports, {
67
85
  EventSearchIndex: () => EventSearchIndex,
68
86
  EventStatus: () => EventStatus,
69
87
  EventStatuses: () => EventStatuses,
88
+ FieldConditional: () => FieldConditional,
70
89
  FieldConfig: () => FieldConfig,
71
90
  FieldType: () => FieldType,
72
91
  FieldUpdateValue: () => FieldUpdateValue,
@@ -75,13 +94,21 @@ __export(events_exports, {
75
94
  FileFieldValueWithOption: () => FileFieldValueWithOption,
76
95
  FileFieldWithOptionValue: () => FileFieldWithOptionValue,
77
96
  FormConfig: () => FormConfig,
78
- FormPage: () => FormPage,
97
+ FormPageConfig: () => FormPageConfig,
98
+ GenericAddressUpdateValue: () => GenericAddressUpdateValue,
99
+ GenericAddressValue: () => GenericAddressValue,
79
100
  GeographicalArea: () => GeographicalArea,
101
+ ImageMimeType: () => ImageMimeType,
80
102
  LanguageConfig: () => LanguageConfig,
81
103
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
104
+ MimeType: () => MimeType,
82
105
  NotifyActionInput: () => NotifyActionInput,
83
106
  NumberFieldValue: () => NumberFieldValue,
107
+ PageConfig: () => PageConfig,
108
+ PageTypes: () => PageTypes,
84
109
  PrintCertificateActionInput: () => PrintCertificateActionInput,
110
+ ReadActionInput: () => ReadActionInput,
111
+ RegisterAction: () => RegisterAction,
85
112
  RegisterActionInput: () => RegisterActionInput,
86
113
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
87
114
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
@@ -94,21 +121,31 @@ __export(events_exports, {
94
121
  SummaryConfig: () => SummaryConfig,
95
122
  TextValue: () => TextValue,
96
123
  TranslationConfig: () => TranslationConfig,
124
+ UnassignActionInput: () => UnassignActionInput,
97
125
  UrbanAddressUpdateValue: () => UrbanAddressUpdateValue,
98
126
  UrbanAddressValue: () => UrbanAddressValue,
99
127
  ValidateActionInput: () => ValidateActionInput,
128
+ VerificationActionConfig: () => VerificationActionConfig,
129
+ VerificationPageConfig: () => VerificationPageConfig,
100
130
  WorkqueueConfig: () => WorkqueueConfig,
101
131
  alwaysTrue: () => alwaysTrue,
102
132
  and: () => and,
133
+ annotationActions: () => annotationActions,
103
134
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
135
+ areConditionsMet: () => areConditionsMet,
104
136
  compositeFieldTypes: () => compositeFieldTypes,
105
137
  createEmptyDraft: () => createEmptyDraft,
106
138
  createValidationSchema: () => createValidationSchema,
107
139
  deepDropNulls: () => deepDropNulls,
140
+ deepMerge: () => deepMerge,
141
+ defineActionForm: () => defineActionForm,
108
142
  defineConditional: () => defineConditional,
109
143
  defineConfig: () => defineConfig,
110
- defineForm: () => defineForm,
144
+ defineDeclarationForm: () => defineDeclarationForm,
145
+ defineFormConditional: () => defineFormConditional,
111
146
  defineFormPage: () => defineFormPage,
147
+ definePage: () => definePage,
148
+ errorMessages: () => errorMessages,
112
149
  event: () => event,
113
150
  eventMetadataLabelMap: () => eventMetadataLabelMap,
114
151
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -116,38 +153,44 @@ __export(events_exports, {
116
153
  eventStatuses: () => eventStatuses,
117
154
  field: () => field,
118
155
  fieldTypes: () => fieldTypes,
119
- findActiveActionFields: () => findActiveActionFields,
120
- findActiveActionForm: () => findActiveActionForm,
121
- findActiveActionFormFields: () => findActiveActionFormFields,
122
- findActiveActionFormPages: () => findActiveActionFormPages,
156
+ filterUnallowedActions: () => filterUnallowedActions,
123
157
  findActiveDrafts: () => findActiveDrafts,
124
- findInputPageFields: () => findInputPageFields,
125
- findPageFields: () => findPageFields,
158
+ findAllFields: () => findAllFields,
159
+ findLastAssignmentAction: () => findLastAssignmentAction,
160
+ findRecordActionPages: () => findRecordActionPages,
161
+ generateActionAnnotationInput: () => generateActionAnnotationInput,
162
+ generateActionDeclarationInput: () => generateActionDeclarationInput,
126
163
  generateActionDocument: () => generateActionDocument,
127
- generateActionInput: () => generateActionInput,
128
164
  generateEventDocument: () => generateEventDocument,
129
165
  generateEventDraftDocument: () => generateEventDraftDocument,
130
166
  generateTransactionId: () => generateTransactionId,
131
- getActiveActionFields: () => getActiveActionFields,
132
- getActiveActionFormPages: () => getActiveActionFormPages,
133
- getAllFields: () => getAllFields,
134
- getAllPages: () => getAllPages,
167
+ generateTranslationConfig: () => generateTranslationConfig,
168
+ getAcceptedActions: () => getAcceptedActions,
169
+ getActionAnnotation: () => getActionAnnotation,
170
+ getActionAnnotationFields: () => getActionAnnotationFields,
171
+ getActionReview: () => getActionReview,
172
+ getActionReviewFields: () => getActionReviewFields,
173
+ getAllAnnotationFields: () => getAllAnnotationFields,
174
+ getAnnotationFromDrafts: () => getAnnotationFromDrafts,
135
175
  getCurrentEventState: () => getCurrentEventState,
136
176
  getCurrentEventStateWithDrafts: () => getCurrentEventStateWithDrafts,
137
- getEventConfiguration: () => getEventConfiguration,
138
- getFieldValidationErrors: () => getFieldValidationErrors,
139
- getFormFields: () => getFormFields,
140
- getMetadataForAction: () => getMetadataForAction,
177
+ getDeclaration: () => getDeclaration,
178
+ getDeclarationFields: () => getDeclarationFields,
179
+ getDeclarationPages: () => getDeclarationPages,
180
+ hasAnyOfScopes: () => hasAnyOfScopes,
141
181
  isAddressFieldType: () => isAddressFieldType,
142
182
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
143
183
  isBulletListFieldType: () => isBulletListFieldType,
144
184
  isCheckboxFieldType: () => isCheckboxFieldType,
185
+ isConditionMet: () => isConditionMet,
145
186
  isCountryFieldType: () => isCountryFieldType,
187
+ isDataFieldType: () => isDataFieldType,
146
188
  isDateFieldType: () => isDateFieldType,
147
189
  isDividerFieldType: () => isDividerFieldType,
148
190
  isEmailFieldType: () => isEmailFieldType,
149
191
  isFacilityFieldType: () => isFacilityFieldType,
150
192
  isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
193
+ isFieldDisplayedOnReview: () => isFieldDisplayedOnReview,
151
194
  isFieldEnabled: () => isFieldEnabled,
152
195
  isFieldValue: () => isFieldValue,
153
196
  isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
@@ -158,6 +201,7 @@ __export(events_exports, {
158
201
  isNumberFieldType: () => isNumberFieldType,
159
202
  isOfficeFieldType: () => isOfficeFieldType,
160
203
  isPageHeaderFieldType: () => isPageHeaderFieldType,
204
+ isPageVisible: () => isPageVisible,
161
205
  isParagraphFieldType: () => isParagraphFieldType,
162
206
  isRadioGroupFieldType: () => isRadioGroupFieldType,
163
207
  isSelectFieldType: () => isSelectFieldType,
@@ -166,49 +210,72 @@ __export(events_exports, {
166
210
  isTextAreaFieldType: () => isTextAreaFieldType,
167
211
  isTextFieldType: () => isTextFieldType,
168
212
  isUndeclaredDraft: () => isUndeclaredDraft,
213
+ isVerificationPage: () => isVerificationPage,
214
+ isWriteAction: () => isWriteAction,
215
+ mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
169
216
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
170
217
  mapFieldTypeToZod: () => mapFieldTypeToZod,
218
+ never: () => never,
171
219
  not: () => not,
220
+ omitHiddenFields: () => omitHiddenFields,
221
+ omitHiddenPaginatedFields: () => omitHiddenPaginatedFields,
172
222
  or: () => or,
173
- resolveLabelsFromKnownFields: () => resolveLabelsFromKnownFields,
174
- stripHiddenFields: () => stripHiddenFields,
223
+ runFieldValidations: () => runFieldValidations,
175
224
  user: () => user,
176
225
  validate: () => validate,
177
226
  validateFieldInput: () => validateFieldInput,
178
- validateWorkqueueConfig: () => validateWorkqueueConfig
227
+ validateWorkqueueConfig: () => validateWorkqueueConfig,
228
+ writeActions: () => writeActions
179
229
  });
180
230
  module.exports = __toCommonJS(events_exports);
181
231
 
182
232
  // ../commons/src/events/ActionConfig.ts
183
- var import_zod7 = require("zod");
233
+ var import_zod9 = require("zod");
184
234
 
185
235
  // ../commons/src/events/Conditional.ts
186
236
  var import_zod = require("zod");
187
- function Conditional() {
188
- return import_zod.z.custom((val) => typeof val === "object" && val !== null);
189
- }
237
+ var Conditional = import_zod.z.custom(
238
+ (val) => typeof val === "object" && val !== null
239
+ );
190
240
  var ConditionalType = {
191
- /** When 'SHOW' conditional is defined, the action is shown to the user only if the condition is met */
192
241
  SHOW: "SHOW",
193
- /** If 'ENABLE' conditional is defined, the action is enabled only if the condition is met */
194
- ENABLE: "ENABLE"
242
+ ENABLE: "ENABLE",
243
+ DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
195
244
  };
196
245
  var ShowConditional = import_zod.z.object({
197
246
  type: import_zod.z.literal(ConditionalType.SHOW),
198
- conditional: Conditional()
199
- });
247
+ conditional: Conditional
248
+ }).describe(
249
+ "If 'SHOW' conditional is defined, the component is shown to the user only if the condition is met"
250
+ );
200
251
  var EnableConditional = import_zod.z.object({
201
252
  type: import_zod.z.literal(ConditionalType.ENABLE),
202
- conditional: Conditional()
203
- });
253
+ conditional: Conditional
254
+ }).describe(
255
+ "If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
256
+ );
204
257
  var ActionConditional = import_zod.z.discriminatedUnion("type", [
205
258
  // Action can be shown / hidden
206
259
  ShowConditional,
207
260
  // Action can be shown to the user in the list but as disabled
208
261
  EnableConditional
209
262
  ]);
263
+ var DisplayOnReviewConditional = import_zod.z.object({
264
+ type: import_zod.z.literal(ConditionalType.DISPLAY_ON_REVIEW),
265
+ conditional: Conditional
266
+ }).describe(
267
+ "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."
268
+ );
269
+ var FieldConditional = import_zod.z.discriminatedUnion("type", [
270
+ // Field input can be shown / hidden
271
+ ShowConditional,
272
+ // Field input can be shown to the user but as disabled
273
+ EnableConditional,
274
+ // Field output can be shown / hidden on the review page
275
+ DisplayOnReviewConditional
276
+ ]);
210
277
 
211
- // ../commons/src/events/FormConfig.ts
278
+ // ../commons/src/events/PageConfig.ts
212
279
  var import_zod6 = require("zod");
213
280
 
214
281
  // ../commons/src/events/FieldConfig.ts
@@ -249,7 +316,8 @@ var FieldType = {
249
316
  ADMINISTRATIVE_AREA: "ADMINISTRATIVE_AREA",
250
317
  FACILITY: "FACILITY",
251
318
  OFFICE: "OFFICE",
252
- SIGNATURE: "SIGNATURE"
319
+ SIGNATURE: "SIGNATURE",
320
+ DATA: "DATA"
253
321
  };
254
322
  var fieldTypes = Object.values(FieldType);
255
323
  var compositeFieldTypes = [
@@ -267,6 +335,10 @@ var GeographicalArea = {
267
335
  URBAN: "URBAN",
268
336
  RURAL: "RURAL"
269
337
  };
338
+ var AddressType = {
339
+ DOMESTIC: "DOMESTIC",
340
+ INTERNATIONAL: "INTERNATIONAL"
341
+ };
270
342
  var FileFieldValue = import_zod3.z.object({
271
343
  filename: import_zod3.z.string(),
272
344
  originalFilename: import_zod3.z.string(),
@@ -274,6 +346,7 @@ var FileFieldValue = import_zod3.z.object({
274
346
  });
275
347
  var AdminStructure = import_zod3.z.object({
276
348
  country: import_zod3.z.string(),
349
+ addressType: import_zod3.z.literal(AddressType.DOMESTIC),
277
350
  province: import_zod3.z.string(),
278
351
  district: import_zod3.z.string()
279
352
  });
@@ -301,14 +374,33 @@ var RuralAddressUpdateValue = AdminStructure.extend({
301
374
  urbanOrRural: import_zod3.z.literal(GeographicalArea.RURAL),
302
375
  village: import_zod3.z.string().nullish()
303
376
  });
304
- var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
305
- UrbanAddressValue,
306
- RuralAddressValue
307
- ]);
377
+ var GenericAddressValue = import_zod3.z.object({
378
+ country: import_zod3.z.string(),
379
+ addressType: import_zod3.z.literal(AddressType.INTERNATIONAL),
380
+ state: import_zod3.z.string(),
381
+ district2: import_zod3.z.string(),
382
+ cityOrTown: import_zod3.z.string().optional(),
383
+ addressLine1: import_zod3.z.string().optional(),
384
+ addressLine2: import_zod3.z.string().optional(),
385
+ addressLine3: import_zod3.z.string().optional(),
386
+ postcodeOrZip: import_zod3.z.string().optional()
387
+ });
388
+ var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [UrbanAddressValue, RuralAddressValue]).or(GenericAddressValue);
389
+ var GenericAddressUpdateValue = import_zod3.z.object({
390
+ country: import_zod3.z.string(),
391
+ addressType: import_zod3.z.literal(AddressType.INTERNATIONAL),
392
+ state: import_zod3.z.string(),
393
+ district2: import_zod3.z.string(),
394
+ cityOrTown: import_zod3.z.string().nullish(),
395
+ addressLine1: import_zod3.z.string().nullish(),
396
+ addressLine2: import_zod3.z.string().nullish(),
397
+ addressLine3: import_zod3.z.string().nullish(),
398
+ postcodeOrZip: import_zod3.z.string().nullish()
399
+ });
308
400
  var AddressFieldUpdateValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
309
401
  UrbanAddressUpdateValue,
310
402
  RuralAddressUpdateValue
311
- ]);
403
+ ]).or(GenericAddressUpdateValue);
312
404
  var FileFieldValueWithOption = import_zod3.z.object({
313
405
  filename: import_zod3.z.string(),
314
406
  originalFilename: import_zod3.z.string(),
@@ -324,6 +416,7 @@ var DateValue = import_zod4.z.string().date().describe("Date in the format YYYY-
324
416
  var EmailValue = import_zod4.z.string().email();
325
417
  var CheckboxFieldValue = import_zod4.z.boolean();
326
418
  var NumberFieldValue = import_zod4.z.number();
419
+ var DataFieldValue = import_zod4.z.undefined();
327
420
  var FieldValue = import_zod4.z.union([
328
421
  TextValue,
329
422
  DateValue,
@@ -332,7 +425,9 @@ var FieldValue = import_zod4.z.union([
332
425
  FileFieldValue,
333
426
  FileFieldWithOptionValue,
334
427
  UrbanAddressValue,
335
- RuralAddressValue
428
+ RuralAddressValue,
429
+ DataFieldValue,
430
+ GenericAddressValue
336
431
  ]);
337
432
  var FieldUpdateValue = import_zod4.z.union([
338
433
  TextValue,
@@ -342,7 +437,9 @@ var FieldUpdateValue = import_zod4.z.union([
342
437
  FileFieldValue,
343
438
  FileFieldWithOptionValue,
344
439
  UrbanAddressUpdateValue,
345
- RuralAddressUpdateValue
440
+ RuralAddressUpdateValue,
441
+ DataFieldValue,
442
+ GenericAddressUpdateValue
346
443
  ]);
347
444
 
348
445
  // ../commons/src/events/FieldConfig.ts
@@ -364,14 +461,14 @@ var BaseField = import_zod5.z.object({
364
461
  ]),
365
462
  DependencyExpression
366
463
  ]).optional(),
367
- conditionals: import_zod5.z.array(ActionConditional).default([]).optional(),
464
+ conditionals: import_zod5.z.array(FieldConditional).default([]).optional(),
368
465
  required: import_zod5.z.boolean().default(false).optional(),
369
466
  disabled: import_zod5.z.boolean().default(false).optional(),
370
467
  hidden: import_zod5.z.boolean().default(false).optional(),
371
468
  placeholder: TranslationConfig.optional(),
372
469
  validation: import_zod5.z.array(
373
470
  import_zod5.z.object({
374
- validator: Conditional(),
471
+ validator: Conditional,
375
472
  message: TranslationConfig
376
473
  })
377
474
  ).default([]).optional(),
@@ -413,15 +510,25 @@ var TextAreaField = BaseField.extend({
413
510
  postfix: TranslationConfig.optional()
414
511
  }).default({ rows: 4 }).optional()
415
512
  }).describe("Multiline text input");
513
+ var ImageMimeType = import_zod5.z.enum([
514
+ "image/png",
515
+ "image/jpg",
516
+ "image/jpeg",
517
+ "image/svg+xml"
518
+ ]);
519
+ var MimeType = ImageMimeType;
520
+ var DEFAULT_MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
416
521
  var SignatureField = BaseField.extend({
417
522
  type: import_zod5.z.literal(FieldType.SIGNATURE),
418
523
  signaturePromptLabel: TranslationConfig.describe(
419
524
  "Title of the signature modal"
420
525
  ),
421
526
  configuration: import_zod5.z.object({
422
- maxSizeMb: import_zod5.z.number().optional().describe("Maximum file size in MB"),
423
- allowedFileFormats: import_zod5.z.array(import_zod5.z.string()).optional().describe("List of allowed file formats for the signature")
424
- }).default({}).optional()
527
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
528
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
529
+ }).default({
530
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
531
+ })
425
532
  }).describe("Signature input field");
426
533
  var EmailField = BaseField.extend({
427
534
  type: import_zod5.z.literal(FieldType.EMAIL),
@@ -464,13 +571,18 @@ var PageHeader = BaseField.extend({
464
571
  }).describe("A read-only header component for form pages");
465
572
  var File = BaseField.extend({
466
573
  type: import_zod5.z.literal(FieldType.FILE),
467
- options: import_zod5.z.object({
574
+ configuration: import_zod5.z.object({
575
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
576
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
468
577
  style: import_zod5.z.object({
469
- fullWidth: import_zod5.z.boolean().describe(
578
+ width: import_zod5.z.enum(["full", "auto"]).optional().describe(
470
579
  "Whether the file upload button should take the full width of the container or not"
471
580
  )
472
- })
473
- }).optional()
581
+ }).optional(),
582
+ fileName: TranslationConfig.optional()
583
+ }).default({
584
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
585
+ })
474
586
  }).describe("File upload");
475
587
  var SelectOption = import_zod5.z.object({
476
588
  value: import_zod5.z.string().describe("The value of the option"),
@@ -516,7 +628,7 @@ var AdministrativeAreas = import_zod5.z.enum([
516
628
  ]);
517
629
  var AdministrativeAreaConfiguration = import_zod5.z.object({
518
630
  partOf: import_zod5.z.object({
519
- $data: import_zod5.z.string()
631
+ $declaration: import_zod5.z.string()
520
632
  }).optional().describe("Parent location"),
521
633
  type: AdministrativeAreas
522
634
  }).describe("Administrative area options");
@@ -531,8 +643,14 @@ var Location = BaseField.extend({
531
643
  }).describe("Input field for a location");
532
644
  var FileUploadWithOptions = BaseField.extend({
533
645
  type: import_zod5.z.literal(FieldType.FILE_WITH_OPTIONS),
534
- options: import_zod5.z.array(SelectOption).describe("A list of options")
535
- }).describe("Select input");
646
+ options: import_zod5.z.array(SelectOption).describe("A list of options"),
647
+ configuration: import_zod5.z.object({
648
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
649
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
650
+ }).default({
651
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
652
+ })
653
+ });
536
654
  var Facility = BaseField.extend({
537
655
  type: import_zod5.z.literal(FieldType.FACILITY),
538
656
  defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
@@ -545,6 +663,22 @@ var Address = BaseField.extend({
545
663
  type: import_zod5.z.literal(FieldType.ADDRESS),
546
664
  defaultValue: AddressFieldValue.optional()
547
665
  }).describe("Address input field \u2013 a combination of location and text fields");
666
+ var DataEntry = import_zod5.z.union([
667
+ import_zod5.z.object({
668
+ label: TranslationConfig,
669
+ value: TranslationConfig.or(import_zod5.z.string())
670
+ }),
671
+ import_zod5.z.object({
672
+ fieldId: import_zod5.z.string()
673
+ })
674
+ ]);
675
+ var DataField = BaseField.extend({
676
+ type: import_zod5.z.literal(FieldType.DATA),
677
+ configuration: import_zod5.z.object({
678
+ subtitle: TranslationConfig.optional(),
679
+ data: import_zod5.z.array(DataEntry)
680
+ })
681
+ }).describe("Data field for displaying read-only data");
548
682
  var FieldConfig = import_zod5.z.discriminatedUnion("type", [
549
683
  Address,
550
684
  TextField,
@@ -566,132 +700,210 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
566
700
  Office,
567
701
  SignatureField,
568
702
  EmailField,
569
- FileUploadWithOptions
703
+ FileUploadWithOptions,
704
+ DataField
705
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
570
706
  ]);
571
707
 
572
- // ../commons/src/events/FormConfig.ts
573
- var FormPage = import_zod6.z.object({
708
+ // ../commons/src/events/PageConfig.ts
709
+ var PageTypes = import_zod6.z.enum(["FORM", "VERIFICATION"]);
710
+ var PageConfigBase = import_zod6.z.object({
574
711
  id: import_zod6.z.string().describe("Unique identifier for the page"),
575
712
  title: TranslationConfig.describe("Header title of the page"),
576
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page")
713
+ fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page"),
714
+ conditional: Conditional.optional().describe(
715
+ "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
716
+ )
577
717
  });
578
- var FormConfig = import_zod6.z.object({
579
- label: TranslationConfig.describe("Human readable description of the form"),
580
- version: import_zod6.z.object({
581
- id: import_zod6.z.string().describe(
582
- "Form version. Semantic versioning recommended. Example: 0.0.1"
583
- ),
584
- label: TranslationConfig.describe(
585
- "Human readable description of the version"
586
- )
587
- }),
588
- active: import_zod6.z.boolean().default(false).describe("Whether the form is active"),
589
- pages: import_zod6.z.array(FormPage),
590
- review: import_zod6.z.object({
591
- title: TranslationConfig.describe(
592
- "Title of the form to show in review page"
593
- ),
594
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the review page for metadata")
718
+ var FormPageConfig = PageConfigBase.extend({
719
+ type: import_zod6.z.literal(PageTypes.enum.FORM).default(PageTypes.enum.FORM)
720
+ });
721
+ var VerificationActionConfig = import_zod6.z.object({
722
+ verify: import_zod6.z.object({ label: TranslationConfig }),
723
+ cancel: import_zod6.z.object({
724
+ label: TranslationConfig,
725
+ confirmation: import_zod6.z.object({
726
+ title: TranslationConfig,
727
+ body: TranslationConfig
728
+ })
595
729
  })
730
+ }).describe("Actions available on the verification page");
731
+ var VerificationPageConfig = FormPageConfig.extend({
732
+ type: import_zod6.z.literal(PageTypes.enum.VERIFICATION),
733
+ actions: VerificationActionConfig
596
734
  });
735
+ var PageConfig = import_zod6.z.discriminatedUnion("type", [
736
+ FormPageConfig,
737
+ VerificationPageConfig
738
+ ]);
597
739
 
598
740
  // ../commons/src/events/ActionType.ts
741
+ var import_zod7 = require("zod");
599
742
  var ActionType = {
743
+ // Pre-declaration actions
744
+ DELETE: "DELETE",
600
745
  CREATE: "CREATE",
601
- ASSIGN: "ASSIGN",
602
- UNASSIGN: "UNASSIGN",
603
- REGISTER: "REGISTER",
604
- VALIDATE: "VALIDATE",
605
- REQUEST_CORRECTION: "REQUEST_CORRECTION",
606
- REJECT_CORRECTION: "REJECT_CORRECTION",
607
- APPROVE_CORRECTION: "APPROVE_CORRECTION",
608
- DETECT_DUPLICATE: "DETECT_DUPLICATE",
609
746
  NOTIFY: "NOTIFY",
747
+ // Declaration actions
610
748
  DECLARE: "DECLARE",
611
- DELETE: "DELETE",
612
- PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
613
- CUSTOM: "CUSTOM",
749
+ VALIDATE: "VALIDATE",
750
+ REGISTER: "REGISTER",
751
+ // Declaration system actions. Non-configurable.
752
+ DETECT_DUPLICATE: "DETECT_DUPLICATE",
614
753
  REJECT: "REJECT",
754
+ // REJECT_DECLARATION
615
755
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
616
- ARCHIVE: "ARCHIVE"
756
+ // MARK_AS_DUPLICATE
757
+ ARCHIVE: "ARCHIVE",
758
+ // Record actions
759
+ PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
760
+ REQUEST_CORRECTION: "REQUEST_CORRECTION",
761
+ REJECT_CORRECTION: "REJECT_CORRECTION",
762
+ APPROVE_CORRECTION: "APPROVE_CORRECTION",
763
+ // General actions
764
+ READ: "READ",
765
+ ASSIGN: "ASSIGN",
766
+ UNASSIGN: "UNASSIGN"
617
767
  };
768
+ var ConfirmableActions = [
769
+ ActionType.NOTIFY,
770
+ ActionType.DECLARE,
771
+ ActionType.VALIDATE,
772
+ ActionType.REGISTER,
773
+ ActionType.REJECT,
774
+ ActionType.ARCHIVE,
775
+ ActionType.PRINT_CERTIFICATE
776
+ ];
777
+ var ActionTypes = import_zod7.z.enum([
778
+ "DELETE",
779
+ "CREATE",
780
+ "NOTIFY",
781
+ "DECLARE",
782
+ "VALIDATE",
783
+ "REGISTER",
784
+ "DETECT_DUPLICATE",
785
+ "REJECT",
786
+ "MARKED_AS_DUPLICATE",
787
+ "ARCHIVE",
788
+ "PRINT_CERTIFICATE",
789
+ "REQUEST_CORRECTION",
790
+ "REJECT_CORRECTION",
791
+ "APPROVE_CORRECTION",
792
+ "READ",
793
+ "ASSIGN",
794
+ "UNASSIGN"
795
+ ]);
796
+ var declarationActionValues = [
797
+ ActionTypes.enum.DECLARE,
798
+ ActionTypes.enum.VALIDATE,
799
+ ActionTypes.enum.REGISTER
800
+ ];
801
+ var DeclarationActions = ActionTypes.extract(declarationActionValues);
802
+ var declarationUpdateActionValues = [
803
+ ...declarationActionValues,
804
+ ActionTypes.enum.REQUEST_CORRECTION
805
+ ];
806
+ var DeclarationUpdateActions = ActionTypes.extract(
807
+ declarationUpdateActionValues
808
+ );
809
+ var annotationActions = ActionTypes.exclude(declarationActionValues);
810
+ var writeActions = ActionTypes.exclude([
811
+ ActionType.CREATE,
812
+ ActionType.READ,
813
+ ActionType.ASSIGN,
814
+ ActionType.UNASSIGN
815
+ ]);
816
+
817
+ // ../commons/src/events/FormConfig.ts
818
+ var import_zod8 = require("zod");
819
+ var DeclarationFormConfig = import_zod8.z.object({
820
+ label: TranslationConfig.describe("Human readable description of the form"),
821
+ pages: import_zod8.z.array(FormPageConfig)
822
+ }).describe("Configuration for a declaration form");
823
+ var ActionFormConfig = import_zod8.z.object({
824
+ label: TranslationConfig.describe("Human readable description of the form"),
825
+ pages: import_zod8.z.array(PageConfig)
826
+ });
827
+ var FormConfig = import_zod8.z.union([DeclarationFormConfig, ActionFormConfig]);
618
828
 
619
829
  // ../commons/src/events/ActionConfig.ts
620
- var ActionConditional2 = import_zod7.z.discriminatedUnion("type", [
830
+ var ActionConditional2 = import_zod9.z.discriminatedUnion("type", [
621
831
  /** If conditional is defined, the action is shown to the user only if the condition is met */
622
832
  ShowConditional,
623
833
  /** If conditional is defined, the action is enabled only if the condition is met */
624
834
  EnableConditional
625
835
  ]);
626
- var ActionConfigBase = import_zod7.z.object({
836
+ var DeclarationReviewConfig = import_zod9.z.object({
837
+ title: TranslationConfig.describe("Title of the review page"),
838
+ fields: import_zod9.z.array(FieldConfig).describe("Fields to be rendered on the review page for annotations.")
839
+ }).describe("Configuration for **declaration** review page.");
840
+ var ActionConfigBase = import_zod9.z.object({
627
841
  label: TranslationConfig,
628
- conditionals: import_zod7.z.array(ActionConditional2).optional().default([]),
629
- draft: import_zod7.z.boolean().optional(),
630
- forms: import_zod7.z.array(FormConfig)
842
+ conditionals: import_zod9.z.array(ActionConditional2).optional().default([]),
843
+ draft: import_zod9.z.boolean().optional()
631
844
  });
632
845
  var DeclareConfig = ActionConfigBase.merge(
633
- import_zod7.z.object({
634
- type: import_zod7.z.literal(ActionType.DECLARE)
846
+ import_zod9.z.object({
847
+ type: import_zod9.z.literal(ActionType.DECLARE),
848
+ review: DeclarationReviewConfig
635
849
  })
636
850
  );
637
851
  var ValidateConfig = ActionConfigBase.merge(
638
- import_zod7.z.object({
639
- type: import_zod7.z.literal(ActionType.VALIDATE)
852
+ import_zod9.z.object({
853
+ type: import_zod9.z.literal(ActionType.VALIDATE),
854
+ review: DeclarationReviewConfig
855
+ })
856
+ );
857
+ var RegisterConfig = ActionConfigBase.merge(
858
+ import_zod9.z.object({
859
+ type: import_zod9.z.literal(ActionType.REGISTER),
860
+ review: DeclarationReviewConfig
640
861
  })
641
862
  );
642
863
  var RejectDeclarationConfig = ActionConfigBase.merge(
643
- import_zod7.z.object({
644
- type: import_zod7.z.literal(ActionType.REJECT)
864
+ import_zod9.z.object({
865
+ type: import_zod9.z.literal(ActionType.REJECT)
645
866
  })
646
867
  );
647
868
  var MarkedAsDuplicateConfig = ActionConfigBase.merge(
648
- import_zod7.z.object({
649
- type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE)
869
+ import_zod9.z.object({
870
+ type: import_zod9.z.literal(ActionType.MARKED_AS_DUPLICATE)
650
871
  })
651
872
  );
652
873
  var ArchiveConfig = ActionConfigBase.merge(
653
- import_zod7.z.object({
654
- type: import_zod7.z.literal(ActionType.ARCHIVE)
655
- })
656
- );
657
- var RegisterConfig = ActionConfigBase.merge(
658
- import_zod7.z.object({
659
- type: import_zod7.z.literal(ActionType.REGISTER)
874
+ import_zod9.z.object({
875
+ type: import_zod9.z.literal(ActionType.ARCHIVE)
660
876
  })
661
877
  );
662
878
  var DeleteConfig = ActionConfigBase.merge(
663
- import_zod7.z.object({
664
- type: import_zod7.z.literal(ActionType.DELETE)
879
+ import_zod9.z.object({
880
+ type: import_zod9.z.literal(ActionType.DELETE)
665
881
  })
666
882
  );
667
883
  var PrintCertificateActionConfig = ActionConfigBase.merge(
668
- import_zod7.z.object({
669
- type: import_zod7.z.literal(ActionType.PRINT_CERTIFICATE)
884
+ import_zod9.z.object({
885
+ type: import_zod9.z.literal(ActionType.PRINT_CERTIFICATE),
886
+ printForm: ActionFormConfig
670
887
  })
671
888
  );
672
889
  var RequestCorrectionConfig = ActionConfigBase.merge(
673
- import_zod7.z.object({
674
- type: import_zod7.z.literal(ActionType.REQUEST_CORRECTION),
675
- onboardingForm: import_zod7.z.array(FormPage),
676
- additionalDetailsForm: import_zod7.z.array(FormPage)
890
+ import_zod9.z.object({
891
+ type: import_zod9.z.literal(ActionType.REQUEST_CORRECTION),
892
+ onboardingForm: import_zod9.z.array(PageConfig),
893
+ additionalDetailsForm: import_zod9.z.array(PageConfig)
677
894
  })
678
895
  );
679
896
  var RejectCorrectionConfig = ActionConfigBase.merge(
680
- import_zod7.z.object({
681
- type: import_zod7.z.literal(ActionType.REJECT_CORRECTION)
897
+ import_zod9.z.object({
898
+ type: import_zod9.z.literal(ActionType.REJECT_CORRECTION)
682
899
  })
683
900
  );
684
901
  var ApproveCorrectionConfig = ActionConfigBase.merge(
685
- import_zod7.z.object({
686
- type: import_zod7.z.literal(ActionType.APPROVE_CORRECTION)
902
+ import_zod9.z.object({
903
+ type: import_zod9.z.literal(ActionType.APPROVE_CORRECTION)
687
904
  })
688
905
  );
689
- var CustomConfig = ActionConfigBase.merge(
690
- import_zod7.z.object({
691
- type: import_zod7.z.literal(ActionType.CUSTOM)
692
- })
693
- );
694
- var ActionConfig = import_zod7.z.discriminatedUnion("type", [
906
+ var ActionConfig = import_zod9.z.discriminatedUnion("type", [
695
907
  DeclareConfig,
696
908
  ValidateConfig,
697
909
  RejectDeclarationConfig,
@@ -702,102 +914,108 @@ var ActionConfig = import_zod7.z.discriminatedUnion("type", [
702
914
  PrintCertificateActionConfig,
703
915
  RequestCorrectionConfig,
704
916
  RejectCorrectionConfig,
705
- ApproveCorrectionConfig,
706
- CustomConfig
917
+ ApproveCorrectionConfig
918
+ ]);
919
+ var DeclarationActionConfig = import_zod9.z.discriminatedUnion("type", [
920
+ DeclareConfig,
921
+ ValidateConfig,
922
+ RegisterConfig
707
923
  ]);
708
924
 
709
925
  // ../commons/src/events/offline/CertificateConfig.ts
710
- var import_zod8 = require("zod");
711
- var FontFamily = import_zod8.z.object({
712
- normal: import_zod8.z.string(),
713
- bold: import_zod8.z.string(),
714
- italics: import_zod8.z.string(),
715
- bolditalics: import_zod8.z.string()
926
+ var import_zod10 = require("zod");
927
+ var FontFamily = import_zod10.z.object({
928
+ normal: import_zod10.z.string(),
929
+ bold: import_zod10.z.string(),
930
+ italics: import_zod10.z.string(),
931
+ bolditalics: import_zod10.z.string()
716
932
  });
717
- var CertificateConfig = import_zod8.z.object({
718
- id: import_zod8.z.string(),
719
- event: import_zod8.z.string(),
933
+ var CertificateConfig = import_zod10.z.object({
934
+ id: import_zod10.z.string(),
935
+ event: import_zod10.z.string(),
720
936
  label: TranslationConfig,
721
- isDefault: import_zod8.z.boolean(),
722
- fee: import_zod8.z.object({
723
- onTime: import_zod8.z.number(),
724
- late: import_zod8.z.number(),
725
- delayed: import_zod8.z.number()
937
+ isDefault: import_zod10.z.boolean(),
938
+ fee: import_zod10.z.object({
939
+ onTime: import_zod10.z.number(),
940
+ late: import_zod10.z.number(),
941
+ delayed: import_zod10.z.number()
726
942
  }),
727
- svgUrl: import_zod8.z.string(),
728
- fonts: import_zod8.z.record(FontFamily).optional()
943
+ svgUrl: import_zod10.z.string(),
944
+ fonts: import_zod10.z.record(FontFamily).optional()
729
945
  });
730
946
  var CertificateTemplateConfig = CertificateConfig.extend({
731
- hash: import_zod8.z.string().optional(),
732
- svg: import_zod8.z.string()
947
+ hash: import_zod10.z.string().optional(),
948
+ svg: import_zod10.z.string()
733
949
  });
734
950
 
735
951
  // ../commons/src/events/offline/LanguageConfig.ts
736
- var import_zod9 = require("zod");
737
- var LanguageConfig = import_zod9.z.object({
738
- lang: import_zod9.z.string(),
952
+ var import_zod11 = require("zod");
953
+ var LanguageConfig = import_zod11.z.object({
954
+ lang: import_zod11.z.string(),
739
955
  /**
740
956
  * client.csv contents
741
957
  */
742
- messages: import_zod9.z.record(import_zod9.z.string())
958
+ messages: import_zod11.z.record(import_zod11.z.string())
743
959
  });
744
960
 
745
961
  // ../commons/src/events/EventConfig.ts
746
- var import_zod18 = require("zod");
962
+ var import_zod20 = require("zod");
747
963
 
748
964
  // ../commons/src/events/DeduplicationConfig.ts
749
- var import_zod10 = require("zod");
750
- var FieldReference = import_zod10.z.string();
751
- var Matcher = import_zod10.z.object({
752
- fieldId: import_zod10.z.string(),
753
- options: import_zod10.z.object({
754
- boost: import_zod10.z.number().optional()
965
+ var import_zod12 = require("zod");
966
+ var FieldReference = import_zod12.z.string();
967
+ var Matcher = import_zod12.z.object({
968
+ fieldId: import_zod12.z.string(),
969
+ options: import_zod12.z.object({
970
+ boost: import_zod12.z.number().optional()
755
971
  }).optional().default({})
756
972
  });
757
973
  var FuzzyMatcher = Matcher.extend({
758
- type: import_zod10.z.literal("fuzzy"),
759
- options: import_zod10.z.object({
974
+ type: import_zod12.z.literal("fuzzy"),
975
+ options: import_zod12.z.object({
760
976
  /**
761
977
  * Names of length 3 or less characters = 0 edits allowed
762
978
  * Names of length 4 - 6 characters = 1 edit allowed
763
979
  * Names of length >7 characters = 2 edits allowed
764
980
  */
765
- fuzziness: import_zod10.z.union([import_zod10.z.string(), import_zod10.z.number()]).optional().default("AUTO:4,7"),
766
- boost: import_zod10.z.number().optional().default(1)
981
+ fuzziness: import_zod12.z.union([import_zod12.z.string(), import_zod12.z.number()]).optional().default("AUTO:4,7"),
982
+ boost: import_zod12.z.number().optional().default(1)
767
983
  }).optional().default({})
768
984
  });
769
985
  var StrictMatcher = Matcher.extend({
770
- type: import_zod10.z.literal("strict"),
771
- options: import_zod10.z.object({
772
- boost: import_zod10.z.number().optional().default(1)
986
+ type: import_zod12.z.literal("strict"),
987
+ options: import_zod12.z.object({
988
+ boost: import_zod12.z.number().optional().default(1)
773
989
  }).optional().default({})
774
990
  });
775
991
  var DateRangeMatcher = Matcher.extend({
776
- type: import_zod10.z.literal("dateRange"),
777
- options: import_zod10.z.object({
778
- days: import_zod10.z.number(),
992
+ type: import_zod12.z.literal("dateRange"),
993
+ options: import_zod12.z.object({
994
+ days: import_zod12.z.number(),
779
995
  origin: FieldReference,
780
- boost: import_zod10.z.number().optional().default(1)
996
+ boost: import_zod12.z.number().optional().default(1)
781
997
  })
782
998
  });
783
999
  var DateDistanceMatcher = Matcher.extend({
784
- type: import_zod10.z.literal("dateDistance"),
785
- options: import_zod10.z.object({
786
- days: import_zod10.z.number(),
1000
+ type: import_zod12.z.literal("dateDistance"),
1001
+ options: import_zod12.z.object({
1002
+ days: import_zod12.z.number(),
787
1003
  origin: FieldReference,
788
- boost: import_zod10.z.number().optional().default(1)
1004
+ boost: import_zod12.z.number().optional().default(1)
789
1005
  })
790
1006
  });
791
- var And = import_zod10.z.object({
792
- type: import_zod10.z.literal("and"),
793
- clauses: import_zod10.z.lazy(() => Clause.array())
1007
+ var And = import_zod12.z.object({
1008
+ type: import_zod12.z.literal("and"),
1009
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
1010
+ clauses: import_zod12.z.lazy(() => Clause.array())
794
1011
  });
795
- var Or = import_zod10.z.object({
796
- type: import_zod10.z.literal("or"),
797
- clauses: import_zod10.z.lazy(() => Clause.array())
1012
+ var Or = import_zod12.z.object({
1013
+ type: import_zod12.z.literal("or"),
1014
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
1015
+ clauses: import_zod12.z.lazy(() => Clause.array())
798
1016
  });
799
- var Clause = import_zod10.z.lazy(
800
- () => import_zod10.z.discriminatedUnion("type", [
1017
+ var Clause = import_zod12.z.lazy(
1018
+ () => import_zod12.z.discriminatedUnion("type", [
801
1019
  And,
802
1020
  Or,
803
1021
  FuzzyMatcher,
@@ -806,37 +1024,44 @@ var Clause = import_zod10.z.lazy(
806
1024
  DateDistanceMatcher
807
1025
  ])
808
1026
  );
809
- var DeduplicationConfig = import_zod10.z.object({
810
- id: import_zod10.z.string(),
1027
+ var DeduplicationConfig = import_zod12.z.object({
1028
+ id: import_zod12.z.string(),
811
1029
  label: TranslationConfig,
812
1030
  query: Clause
813
1031
  });
814
1032
 
815
1033
  // ../commons/src/events/SummaryConfig.ts
816
- var import_zod11 = require("zod");
817
- var Field = import_zod11.z.object({
818
- id: import_zod11.z.string().describe("Id of summary field"),
1034
+ var import_zod13 = require("zod");
1035
+ var BaseField2 = import_zod13.z.object({
1036
+ emptyValueMessage: TranslationConfig.optional(),
1037
+ conditionals: import_zod13.z.array(ShowConditional).default([]).optional()
1038
+ });
1039
+ var ReferenceField = BaseField2.extend({
1040
+ fieldId: import_zod13.z.string()
1041
+ }).describe("Field directly referencing event data with field id");
1042
+ var Field = BaseField2.extend({
1043
+ id: import_zod13.z.string().describe("Id of summary field"),
819
1044
  value: TranslationConfig.describe(
820
1045
  "Summary field value. Can utilise values defined in configuration and EventMetadata"
821
1046
  ),
822
1047
  label: TranslationConfig,
823
1048
  emptyValueMessage: TranslationConfig.optional()
824
- });
825
- var Title = import_zod11.z.object({
826
- id: import_zod11.z.string(),
1049
+ }).describe("Custom configured field");
1050
+ var Title = import_zod13.z.object({
1051
+ id: import_zod13.z.string(),
827
1052
  label: TranslationConfig.describe("Title content"),
828
1053
  emptyValueMessage: TranslationConfig.optional()
829
1054
  });
830
- var SummaryConfig = import_zod11.z.object({
1055
+ var SummaryConfig = import_zod13.z.object({
831
1056
  title: Title.describe("Title of summary view."),
832
- fields: import_zod11.z.array(Field).describe("Fields rendered in summary view.")
1057
+ fields: import_zod13.z.array(import_zod13.z.union([Field, ReferenceField])).describe("Fields rendered in summary view.")
833
1058
  }).describe("Configuration for summary in event.");
834
1059
 
835
1060
  // ../commons/src/events/WorkqueueConfig.ts
836
- var import_zod13 = require("zod");
1061
+ var import_zod15 = require("zod");
837
1062
 
838
1063
  // ../commons/src/events/EventMetadata.ts
839
- var import_zod12 = require("zod");
1064
+ var import_zod14 = require("zod");
840
1065
  var EventStatus = {
841
1066
  CREATED: "CREATED",
842
1067
  NOTIFIED: "NOTIFIED",
@@ -848,18 +1073,20 @@ var EventStatus = {
848
1073
  ARCHIVED: "ARCHIVED"
849
1074
  };
850
1075
  var eventStatuses = Object.values(EventStatus);
851
- var EventStatuses = import_zod12.z.nativeEnum(EventStatus);
852
- var EventMetadata = import_zod12.z.object({
853
- id: import_zod12.z.string(),
854
- type: import_zod12.z.string(),
1076
+ var EventStatuses = import_zod14.z.nativeEnum(EventStatus);
1077
+ var EventMetadata = import_zod14.z.object({
1078
+ id: import_zod14.z.string(),
1079
+ type: import_zod14.z.string(),
855
1080
  status: EventStatuses,
856
- createdAt: import_zod12.z.string().datetime(),
857
- createdBy: import_zod12.z.string(),
858
- createdAtLocation: import_zod12.z.string(),
859
- modifiedAt: import_zod12.z.string().datetime(),
860
- assignedTo: import_zod12.z.string().nullish(),
861
- updatedBy: import_zod12.z.string(),
862
- trackingId: import_zod12.z.string()
1081
+ createdAt: import_zod14.z.string().datetime(),
1082
+ createdBy: import_zod14.z.string(),
1083
+ createdAtLocation: import_zod14.z.string(),
1084
+ updatedAtLocation: import_zod14.z.string(),
1085
+ modifiedAt: import_zod14.z.string().datetime(),
1086
+ assignedTo: import_zod14.z.string().nullish(),
1087
+ updatedBy: import_zod14.z.string(),
1088
+ trackingId: import_zod14.z.string(),
1089
+ registrationNumber: import_zod14.z.string().nullish()
863
1090
  });
864
1091
  var eventMetadataLabelMap = {
865
1092
  "event.assignedTo": {
@@ -877,6 +1104,11 @@ var eventMetadataLabelMap = {
877
1104
  defaultMessage: "Location",
878
1105
  description: "Created At Location"
879
1106
  },
1107
+ "event.updatedAtLocation": {
1108
+ id: "event.updatedAtLocation.label",
1109
+ defaultMessage: "Location",
1110
+ description: "Updated At Location"
1111
+ },
880
1112
  "event.createdBy": {
881
1113
  id: "event.createdBy.label",
882
1114
  defaultMessage: "Created By",
@@ -911,28 +1143,33 @@ var eventMetadataLabelMap = {
911
1143
  id: "event.trackingId.label",
912
1144
  defaultMessage: "Tracking ID",
913
1145
  description: "Tracking ID"
1146
+ },
1147
+ "event.registrationNumber": {
1148
+ id: "event.registrationNumber.label",
1149
+ defaultMessage: "Registration Number",
1150
+ description: "Registration Number"
914
1151
  }
915
1152
  };
916
1153
 
917
1154
  // ../commons/src/events/WorkqueueConfig.ts
918
- var WorkqueueConfig = import_zod13.z.object({
919
- id: import_zod13.z.string().describe("Unique identifier for workqueue."),
920
- filters: import_zod13.z.array(
921
- import_zod13.z.object({
922
- status: import_zod13.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
1155
+ var WorkqueueConfig = import_zod15.z.object({
1156
+ id: import_zod15.z.string().describe("Unique identifier for workqueue."),
1157
+ filters: import_zod15.z.array(
1158
+ import_zod15.z.object({
1159
+ status: import_zod15.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
923
1160
  })
924
1161
  ).describe("Filters to be applied to workqueue.")
925
1162
  }).describe("Configuration for workqueue.");
926
1163
 
927
1164
  // ../commons/src/events/AdvancedSearchConfig.ts
928
- var import_zod14 = require("zod");
929
- var AdvancedSearchConfig = import_zod14.z.object({
1165
+ var import_zod16 = require("zod");
1166
+ var AdvancedSearchConfig = import_zod16.z.object({
930
1167
  title: TranslationConfig.describe("Advanced search tab title"),
931
- fields: import_zod14.z.array(
932
- import_zod14.z.object({
933
- fieldId: import_zod14.z.string(),
934
- config: import_zod14.z.object({
935
- type: import_zod14.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
1168
+ fields: import_zod16.z.array(
1169
+ import_zod16.z.object({
1170
+ fieldId: import_zod16.z.string(),
1171
+ config: import_zod16.z.object({
1172
+ type: import_zod16.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
936
1173
  }).optional().describe("Configuration options for the field")
937
1174
  })
938
1175
  ).optional().default([]).describe("Advanced search fields.")
@@ -942,12 +1179,12 @@ var AdvancedSearchConfig = import_zod14.z.object({
942
1179
  var import_lodash = require("lodash");
943
1180
 
944
1181
  // ../commons/src/workqueues/WorkqueueConfig.ts
945
- var import_zod16 = require("zod");
1182
+ var import_zod18 = require("zod");
946
1183
 
947
1184
  // ../commons/src/workqueues/defaultColumns.ts
948
- var import_zod15 = require("zod");
949
- var WorkQueueColumnConfig = import_zod15.z.object({
950
- id: import_zod15.z.string(),
1185
+ var import_zod17 = require("zod");
1186
+ var WorkQueueColumnConfig = import_zod17.z.object({
1187
+ id: import_zod17.z.string(),
951
1188
  label: TranslationConfig
952
1189
  });
953
1190
  var defaultColumns = {
@@ -984,16 +1221,16 @@ var defaultColumns = {
984
1221
  }
985
1222
  }
986
1223
  };
987
- var DefaultColumnKeys = import_zod15.z.enum(
1224
+ var DefaultColumnKeys = import_zod17.z.enum(
988
1225
  Object.keys(defaultColumns)
989
1226
  );
990
1227
 
991
1228
  // ../commons/src/workqueues/WorkqueueConfig.ts
992
- var rootWorkqueueConfig = import_zod16.z.object({
993
- id: import_zod16.z.string(),
1229
+ var rootWorkqueueConfig = import_zod18.z.object({
1230
+ id: import_zod18.z.string(),
994
1231
  title: TranslationConfig,
995
- columns: import_zod16.z.array(WorkQueueColumnConfig),
996
- defaultColumns: import_zod16.z.array(DefaultColumnKeys)
1232
+ columns: import_zod18.z.array(WorkQueueColumnConfig),
1233
+ defaultColumns: import_zod18.z.array(DefaultColumnKeys)
997
1234
  });
998
1235
  var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
999
1236
 
@@ -1073,7 +1310,7 @@ var import_ajv_formats = __toESM(require("ajv-formats"));
1073
1310
  var import_date_fns = require("date-fns");
1074
1311
 
1075
1312
  // ../commons/src/events/FieldTypeMapping.ts
1076
- var import_zod17 = require("zod");
1313
+ var import_zod19 = require("zod");
1077
1314
  function mapFieldTypeToZod(type, required) {
1078
1315
  let schema;
1079
1316
  switch (type) {
@@ -1115,6 +1352,9 @@ function mapFieldTypeToZod(type, required) {
1115
1352
  case FieldType.ADDRESS:
1116
1353
  schema = AddressFieldUpdateValue;
1117
1354
  break;
1355
+ case FieldType.DATA:
1356
+ schema = DataFieldValue;
1357
+ break;
1118
1358
  }
1119
1359
  return required ? schema : schema.nullish();
1120
1360
  }
@@ -1123,7 +1363,7 @@ function createValidationSchema(config) {
1123
1363
  for (const field2 of config) {
1124
1364
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1125
1365
  }
1126
- return import_zod17.z.object(shape);
1366
+ return import_zod19.z.object(shape);
1127
1367
  }
1128
1368
  function mapFieldTypeToMockValue(field2, i) {
1129
1369
  switch (field2.type) {
@@ -1149,6 +1389,7 @@ function mapFieldTypeToMockValue(field2, i) {
1149
1389
  case FieldType.ADDRESS:
1150
1390
  return {
1151
1391
  country: "FAR",
1392
+ addressType: AddressType.DOMESTIC,
1152
1393
  province: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
1153
1394
  district: "5ef450bc-712d-48ad-93f3-8da0fa453baa",
1154
1395
  urbanOrRural: "URBAN",
@@ -1170,6 +1411,54 @@ function mapFieldTypeToMockValue(field2, i) {
1170
1411
  };
1171
1412
  case FieldType.FILE_WITH_OPTIONS:
1172
1413
  return null;
1414
+ case FieldType.DATA:
1415
+ return {};
1416
+ }
1417
+ }
1418
+ function mapFieldTypeToEmptyValue(field2) {
1419
+ switch (field2.type) {
1420
+ case FieldType.DIVIDER:
1421
+ case FieldType.TEXT:
1422
+ case FieldType.TEXTAREA:
1423
+ case FieldType.BULLET_LIST:
1424
+ case FieldType.PAGE_HEADER:
1425
+ case FieldType.LOCATION:
1426
+ case FieldType.SELECT:
1427
+ case FieldType.COUNTRY:
1428
+ case FieldType.RADIO_GROUP:
1429
+ case FieldType.SIGNATURE:
1430
+ case FieldType.PARAGRAPH:
1431
+ case FieldType.ADMINISTRATIVE_AREA:
1432
+ case FieldType.FACILITY:
1433
+ case FieldType.OFFICE:
1434
+ case FieldType.NUMBER:
1435
+ case FieldType.EMAIL:
1436
+ case FieldType.DATE:
1437
+ case FieldType.CHECKBOX:
1438
+ case FieldType.DATA:
1439
+ return null;
1440
+ case FieldType.ADDRESS:
1441
+ return {
1442
+ country: null,
1443
+ addressType: AddressType.DOMESTIC,
1444
+ province: null,
1445
+ district: null,
1446
+ urbanOrRural: "URBAN",
1447
+ // Default to urban needed for validation
1448
+ town: null,
1449
+ residentialArea: null,
1450
+ street: null,
1451
+ number: null,
1452
+ zipCode: null
1453
+ };
1454
+ case FieldType.FILE:
1455
+ return {
1456
+ filename: "",
1457
+ originalFilename: "",
1458
+ type: ""
1459
+ };
1460
+ case FieldType.FILE_WITH_OPTIONS:
1461
+ return [];
1173
1462
  }
1174
1463
  }
1175
1464
  var isParagraphFieldType = (field2) => {
@@ -1235,21 +1524,36 @@ var isFacilityFieldType = (field2) => {
1235
1524
  var isOfficeFieldType = (field2) => {
1236
1525
  return field2.config.type === FieldType.OFFICE;
1237
1526
  };
1527
+ var isDataFieldType = (field2) => {
1528
+ return field2.config.type === FieldType.DATA;
1529
+ };
1238
1530
 
1239
1531
  // ../commons/src/conditionals/validate.ts
1240
1532
  var ajv = new import_ajv.default({
1241
- $data: true
1533
+ $data: true,
1534
+ allowUnionTypes: true
1242
1535
  });
1243
1536
  (0, import_ajv_formats.default)(ajv);
1244
1537
  function validate(schema, data) {
1245
1538
  return ajv.validate(schema, data);
1246
1539
  }
1540
+ function isConditionMet(conditional, values) {
1541
+ return validate(conditional, {
1542
+ $form: values,
1543
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1544
+ });
1545
+ }
1247
1546
  function getConditionalActionsForField(field2, values) {
1248
1547
  if (!field2.conditionals) {
1249
1548
  return [];
1250
1549
  }
1251
1550
  return field2.conditionals.filter((conditional) => validate(conditional.conditional, values)).map((conditional) => conditional.type);
1252
1551
  }
1552
+ function areConditionsMet(conditions, values) {
1553
+ return conditions.every(
1554
+ (condition) => isConditionMet(condition.conditional, values)
1555
+ );
1556
+ }
1253
1557
  function isFieldConditionMet(field2, form, conditionalType) {
1254
1558
  const hasRule = (field2.conditionals ?? []).some(
1255
1559
  (conditional) => conditional.type === conditionalType
@@ -1271,88 +1575,81 @@ function isFieldVisible(field2, form) {
1271
1575
  function isFieldEnabled(field2, form) {
1272
1576
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1273
1577
  }
1274
- var zodToIntlErrorMap = (issue, _ctx) => {
1275
- if (issue.code === "invalid_string" && issue.validation === "date") {
1276
- return {
1277
- message: {
1278
- message: {
1279
- defaultMessage: "Invalid date. Please use the format YYYY-MM-DD",
1280
- description: "This is the error message for invalid date fields",
1281
- id: "v2.error.invalidDate"
1282
- }
1283
- }
1284
- };
1285
- }
1286
- if (issue.code === "invalid_string" && issue.validation === "email") {
1287
- return {
1288
- message: {
1289
- message: {
1290
- defaultMessage: "Invalid email address",
1291
- description: "This is the error message for invalid email fields",
1292
- id: "v2.error.invalidEmail"
1293
- }
1294
- }
1295
- };
1296
- }
1297
- if (issue.code === "invalid_type" && issue.expected !== issue.received && issue.received === "undefined" || issue.code === "too_small" && issue.message === void 0) {
1298
- return {
1299
- message: {
1300
- message: {
1301
- defaultMessage: "Required for registration",
1302
- description: "This is the error message for required fields",
1303
- id: "v2.error.required"
1304
- }
1305
- }
1306
- };
1578
+ function isFieldDisplayedOnReview(field2, form) {
1579
+ return isFieldVisible(field2, form) && isFieldConditionMet(field2, form, ConditionalType.DISPLAY_ON_REVIEW);
1580
+ }
1581
+ var errorMessages = {
1582
+ hiddenField: {
1583
+ id: "v2.error.hidden",
1584
+ defaultMessage: "Hidden or disabled field should not receive a value",
1585
+ description: "Error message when field is hidden or disabled, but a value was received"
1586
+ },
1587
+ invalidDate: {
1588
+ defaultMessage: "Invalid date field",
1589
+ description: "Error message when date field is invalid",
1590
+ id: "v2.error.invalidDate"
1591
+ },
1592
+ invalidEmail: {
1593
+ defaultMessage: "Invalid email address",
1594
+ description: "Error message when email address is invalid",
1595
+ id: "v2.error.invalidEmail"
1596
+ },
1597
+ requiredField: {
1598
+ defaultMessage: "Required for registration",
1599
+ description: "Error message when required field is missing",
1600
+ id: "v2.error.required"
1601
+ },
1602
+ invalidInput: {
1603
+ defaultMessage: "Invalid input",
1604
+ description: "Error message when generic field is invalid",
1605
+ id: "v2.error.invalid"
1307
1606
  }
1607
+ };
1608
+ function createIntlError(message) {
1308
1609
  return {
1309
1610
  message: {
1310
- message: {
1311
- defaultMessage: "Invalid input",
1312
- description: "This is the error message for invalid field value",
1313
- id: "v2.error.invalid"
1314
- }
1611
+ message
1315
1612
  }
1316
1613
  };
1317
- };
1318
- function getFieldValidationErrors({
1319
- field: field2,
1320
- values
1321
- }) {
1322
- const conditionalParameters = {
1323
- $form: values,
1324
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1325
- };
1326
- if (!isFieldVisible(field2, values) || !isFieldEnabled(field2, values)) {
1327
- if (values[field2.id]) {
1328
- return {
1329
- errors: [
1330
- {
1331
- message: {
1332
- id: "v2.error.hidden",
1333
- defaultMessage: "Hidden or disabled field should not receive a value",
1334
- description: "Error message when field is hidden or disabled, but a value was received"
1335
- }
1614
+ }
1615
+ function zodToIntlErrorMap(issue, _ctx) {
1616
+ switch (issue.code) {
1617
+ case "invalid_string": {
1618
+ if (_ctx.data === "") {
1619
+ return createIntlError(errorMessages.requiredField);
1620
+ }
1621
+ if (issue.validation === "date") {
1622
+ return createIntlError(errorMessages.invalidDate);
1623
+ }
1624
+ if (issue.validation === "email") {
1625
+ return createIntlError(errorMessages.invalidEmail);
1626
+ }
1627
+ break;
1628
+ }
1629
+ case "invalid_type": {
1630
+ if (issue.expected !== issue.received && issue.received === "undefined") {
1631
+ return createIntlError(errorMessages.requiredField);
1632
+ }
1633
+ break;
1634
+ }
1635
+ case "too_small": {
1636
+ if (issue.message === void 0) {
1637
+ return createIntlError(errorMessages.requiredField);
1638
+ }
1639
+ break;
1640
+ }
1641
+ case "invalid_union": {
1642
+ for (const { issues } of issue.unionErrors) {
1643
+ for (const e of issues) {
1644
+ if (zodToIntlErrorMap(e, _ctx).message.message.id !== "v2.error.required") {
1645
+ return createIntlError(errorMessages.invalidInput);
1336
1646
  }
1337
- ]
1338
- };
1647
+ }
1648
+ }
1649
+ return createIntlError(errorMessages.requiredField);
1339
1650
  }
1340
- return {
1341
- errors: []
1342
- };
1343
1651
  }
1344
- const fieldValidationResult = validateFieldInput({
1345
- field: field2,
1346
- value: values[field2.id]
1347
- });
1348
- const customValidationResults = runCustomFieldValidations({
1349
- field: field2,
1350
- conditionalParameters
1351
- });
1352
- return {
1353
- // Assumes that custom validation errors are more important than field validation errors
1354
- errors: [...customValidationResults, ...fieldValidationResult]
1355
- };
1652
+ return createIntlError(errorMessages.invalidInput);
1356
1653
  }
1357
1654
  function runCustomFieldValidations({
1358
1655
  field: field2,
@@ -1375,13 +1672,31 @@ function validateFieldInput({
1375
1672
  );
1376
1673
  return rawError.error?.issues.map((issue) => issue.message) ?? [];
1377
1674
  }
1378
-
1379
- // ../commons/src/utils.ts
1380
- function getOrThrow(x, message) {
1381
- if (x === void 0 || x === null) {
1382
- throw new Error(message);
1675
+ function runFieldValidations({
1676
+ field: field2,
1677
+ values
1678
+ }) {
1679
+ if (!isFieldVisible(field2, values)) {
1680
+ return {
1681
+ errors: []
1682
+ };
1383
1683
  }
1384
- return x;
1684
+ const conditionalParameters = {
1685
+ $form: values,
1686
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1687
+ };
1688
+ const fieldValidationResult = validateFieldInput({
1689
+ field: field2,
1690
+ value: values[field2.id]
1691
+ });
1692
+ const customValidationResults = runCustomFieldValidations({
1693
+ field: field2,
1694
+ conditionalParameters
1695
+ });
1696
+ return {
1697
+ // Assumes that custom validation errors are based on the field type, and extend the validation.
1698
+ errors: [...fieldValidationResult, ...customValidationResults]
1699
+ };
1385
1700
  }
1386
1701
 
1387
1702
  // ../commons/src/uuid.ts
@@ -1390,67 +1705,72 @@ function getUUID() {
1390
1705
  return (0, import_uuid.v4)();
1391
1706
  }
1392
1707
 
1708
+ // ../commons/src/utils.ts
1709
+ function getOrThrow(x, message) {
1710
+ if (x === void 0 || x === null) {
1711
+ throw new Error(message);
1712
+ }
1713
+ return x;
1714
+ }
1715
+
1393
1716
  // ../commons/src/events/utils.ts
1394
- function isMetadataField(field2) {
1395
- return field2 in eventMetadataLabelMap;
1396
- }
1397
- var findInputPageFields = (config) => {
1398
- return (0, import_lodash.flattenDeep)(
1399
- config.actions.map(
1400
- ({ forms }) => forms.map(
1401
- ({ pages }) => pages.map(
1402
- ({ fields }) => fields.map(({ id, label }) => ({ id, label }))
1403
- )
1404
- )
1405
- )
1406
- );
1407
- };
1408
- var findPageFields = (config) => {
1409
- return (0, import_lodash.flattenDeep)(
1410
- config.actions.map((action) => {
1411
- if (action.type === ActionType.REQUEST_CORRECTION) {
1412
- return [
1413
- ...action.forms.map(({ pages }) => pages.map(({ fields }) => fields)),
1414
- ...action.onboardingForm.flatMap(({ fields }) => fields),
1415
- ...action.additionalDetailsForm.flatMap(({ fields }) => fields)
1416
- ];
1417
- }
1418
- return action.forms.map(({ pages }) => pages.map(({ fields }) => fields));
1419
- })
1420
- );
1717
+ function isDeclarationActionConfig(action) {
1718
+ return DeclarationActions.safeParse(action.type).success;
1719
+ }
1720
+ function getDeclarationFields(configuration) {
1721
+ return configuration.declaration.pages.flatMap(({ fields }) => fields);
1722
+ }
1723
+ function getDeclarationPages(configuration) {
1724
+ return configuration.declaration.pages;
1725
+ }
1726
+ function getDeclaration(configuration) {
1727
+ return configuration.declaration;
1728
+ }
1729
+ var getActionAnnotationFields = (actionConfig) => {
1730
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1731
+ return [
1732
+ ...actionConfig.onboardingForm.flatMap(({ fields }) => fields),
1733
+ ...actionConfig.additionalDetailsForm.flatMap(({ fields }) => fields)
1734
+ ];
1735
+ }
1736
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1737
+ return actionConfig.printForm.pages.flatMap(({ fields }) => fields);
1738
+ }
1739
+ if (isDeclarationActionConfig(actionConfig)) {
1740
+ return actionConfig.review.fields;
1741
+ }
1742
+ return [];
1421
1743
  };
1422
- var resolveLabelsFromKnownFields = ({
1423
- pageFields,
1424
- refFields
1425
- }) => {
1426
- return refFields.map((field2) => {
1427
- if (field2.label) {
1428
- return field2;
1429
- }
1430
- if (isMetadataField(field2.id)) {
1431
- return {
1432
- ...field2,
1433
- label: eventMetadataLabelMap[field2.id]
1434
- };
1435
- }
1436
- const pageLabel = pageFields.find((pageField) => pageField.id === field2.id);
1437
- if (!pageLabel) {
1438
- throw new Error(`Referenced field ${field2.id} does not have a label`);
1439
- }
1440
- return {
1441
- ...field2,
1442
- label: pageLabel.label
1443
- };
1444
- });
1744
+ var getAllAnnotationFields = (config) => {
1745
+ return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1445
1746
  };
1446
- function getAllFields(configuration) {
1447
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => [
1448
- ...form.review.fields,
1449
- ...form.pages.flatMap((page) => page.fields)
1747
+ var findAllFields = (config) => {
1748
+ return (0, import_lodash.flattenDeep)([
1749
+ ...getDeclarationFields(config),
1750
+ ...getAllAnnotationFields(config)
1450
1751
  ]);
1752
+ };
1753
+ var findRecordActionPages = (config, actionType) => {
1754
+ const action = config.actions.find((a) => a.type === actionType);
1755
+ if (action?.type === ActionType.REQUEST_CORRECTION) {
1756
+ return [...action.onboardingForm, ...action.additionalDetailsForm];
1757
+ }
1758
+ if (action?.type === ActionType.PRINT_CERTIFICATE) {
1759
+ return action.printForm.pages;
1760
+ }
1761
+ return [];
1762
+ };
1763
+ function getActionReview(configuration, actionType) {
1764
+ const [actionConfig] = configuration.actions.filter(
1765
+ (a) => a.type === actionType
1766
+ );
1767
+ return getOrThrow(
1768
+ actionConfig.review,
1769
+ `No review config found for ${actionType}`
1770
+ );
1451
1771
  }
1452
- function getAllPages(configuration) {
1453
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => form.pages);
1772
+ function getActionReviewFields(configuration, actionType) {
1773
+ return getActionReview(configuration, actionType).fields;
1454
1774
  }
1455
1775
  function validateWorkqueueConfig(workqueueConfigs) {
1456
1776
  workqueueConfigs.map((workqueue) => {
@@ -1459,73 +1779,32 @@ function validateWorkqueueConfig(workqueueConfigs) {
1459
1779
  );
1460
1780
  if (!rootWorkqueue) {
1461
1781
  throw new Error(
1462
- `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1782
+ `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1463
1783
  );
1464
1784
  }
1465
1785
  });
1466
1786
  }
1467
- var findActiveActionForm = (configuration, action) => {
1468
- const actionConfig = configuration.actions.find((a) => a.type === action);
1469
- const form = actionConfig?.forms.find((f) => f.active);
1470
- return form;
1471
- };
1472
- var findActiveActionFormPages = (configuration, action) => {
1473
- return findActiveActionForm(configuration, action)?.pages;
1474
- };
1475
- var getFormFields = (formConfig) => {
1476
- return formConfig.pages.flatMap((p) => p.fields);
1477
- };
1478
- var findActiveActionFormFields = (configuration, action) => {
1479
- const form = findActiveActionForm(configuration, action);
1480
- return form ? getFormFields(form) : void 0;
1481
- };
1482
- var findActiveActionFields = (configuration, action) => {
1483
- const form = findActiveActionForm(configuration, action);
1484
- const reviewFields = form?.review.fields;
1485
- const formFields = form ? getFormFields(form) : void 0;
1486
- const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1487
- return allFields;
1488
- };
1489
- var getActiveActionFormPages = (configuration, action) => {
1490
- return getOrThrow(
1491
- findActiveActionForm(configuration, action)?.pages,
1492
- "Form configuration not found for type: " + configuration.id
1493
- );
1494
- };
1495
- function getActiveActionFields(configuration, action) {
1496
- const fields = findActiveActionFields(configuration, action);
1497
- if (!fields) {
1498
- throw new Error(`No active field config found for action type ${action}`);
1499
- }
1500
- return fields;
1501
- }
1502
- function getEventConfiguration(eventConfigurations, type) {
1503
- const config = eventConfigurations.find((config2) => config2.id === type);
1504
- if (!config) {
1505
- throw new Error(`Event configuration not found for type: ${type}`);
1506
- }
1507
- return config;
1508
- }
1509
- function isOptionalUncheckedCheckbox(field2, form) {
1510
- if (field2.type !== FieldType.CHECKBOX || field2.required) {
1511
- return false;
1787
+ function isPageVisible(page, formValues) {
1788
+ if (!page.conditional) {
1789
+ return true;
1512
1790
  }
1513
- return !form[field2.id];
1791
+ return isConditionMet(page.conditional, formValues);
1514
1792
  }
1515
- function stripHiddenFields(fields, data) {
1516
- return (0, import_lodash.omitBy)(data, (_2, fieldId) => {
1793
+ function omitHiddenFields(fields, values) {
1794
+ return (0, import_lodash.omitBy)(values, (_, fieldId) => {
1517
1795
  const field2 = fields.find((f) => f.id === fieldId);
1518
1796
  if (!field2) {
1519
1797
  return true;
1520
1798
  }
1521
- if (isOptionalUncheckedCheckbox(field2, data)) {
1522
- return true;
1523
- }
1524
- return !isFieldVisible(field2, data);
1799
+ return !isFieldVisible(field2, values);
1525
1800
  });
1526
1801
  }
1802
+ function omitHiddenPaginatedFields(formConfig, declaration) {
1803
+ const visiblePagesFormFields = formConfig.pages.filter((p) => isPageVisible(p, declaration)).flatMap((p) => p.fields);
1804
+ return omitHiddenFields(visiblePagesFormFields, declaration);
1805
+ }
1527
1806
  function findActiveDrafts(event2, drafts) {
1528
- const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1807
+ const actions = event2.actions.slice().filter(({ type }) => type !== ActionType.READ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1529
1808
  const lastAction = actions[actions.length - 1];
1530
1809
  return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
1531
1810
  }
@@ -1537,28 +1816,58 @@ function createEmptyDraft(eventId, draftId, actionType) {
1537
1816
  transactionId: getUUID(),
1538
1817
  action: {
1539
1818
  type: actionType,
1540
- data: {},
1541
- metadata: {},
1819
+ declaration: {},
1820
+ annotation: {},
1542
1821
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1543
1822
  createdBy: "@todo",
1544
1823
  createdAtLocation: "@todo"
1545
1824
  }
1546
1825
  };
1547
1826
  }
1827
+ function isVerificationPage(page) {
1828
+ return page.type === PageTypes.enum.VERIFICATION;
1829
+ }
1830
+ function deepMerge(currentDocument, actionDocument) {
1831
+ return (0, import_lodash.mergeWith)(
1832
+ currentDocument,
1833
+ actionDocument,
1834
+ (previousValue, incomingValue) => {
1835
+ if (incomingValue === void 0) {
1836
+ return previousValue;
1837
+ }
1838
+ if ((0, import_lodash.isArray)(incomingValue)) {
1839
+ return incomingValue;
1840
+ }
1841
+ if ((0, import_lodash.isObject)(previousValue) && (0, import_lodash.isObject)(incomingValue)) {
1842
+ return void 0;
1843
+ }
1844
+ return incomingValue;
1845
+ }
1846
+ );
1847
+ }
1848
+ function findLastAssignmentAction(actions) {
1849
+ return actions.filter(
1850
+ ({ type }) => type === ActionType.ASSIGN || type === ActionType.UNASSIGN
1851
+ ).reduce((latestAction, action) => !latestAction || action.createdAt > latestAction.createdAt ? action : latestAction, void 0);
1852
+ }
1853
+ function isWriteAction(actionType) {
1854
+ return writeActions.safeParse(actionType).success;
1855
+ }
1548
1856
 
1549
1857
  // ../commons/src/events/EventConfig.ts
1550
- var EventConfig = import_zod18.z.object({
1551
- id: import_zod18.z.string().describe(
1858
+ var EventConfig = import_zod20.z.object({
1859
+ id: import_zod20.z.string().describe(
1552
1860
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1553
1861
  ),
1554
1862
  summary: SummaryConfig,
1555
1863
  label: TranslationConfig,
1556
- actions: import_zod18.z.array(ActionConfig),
1557
- workqueues: import_zod18.z.array(WorkqueueConfig),
1558
- deduplication: import_zod18.z.array(DeduplicationConfig).optional().default([]),
1559
- advancedSearch: import_zod18.z.array(AdvancedSearchConfig).optional().default([])
1864
+ actions: import_zod20.z.array(ActionConfig),
1865
+ declaration: DeclarationFormConfig,
1866
+ workqueues: import_zod20.z.array(WorkqueueConfig),
1867
+ deduplication: import_zod20.z.array(DeduplicationConfig).optional().default([]),
1868
+ advancedSearch: import_zod20.z.array(AdvancedSearchConfig).optional().default([])
1560
1869
  }).superRefine((event2, ctx) => {
1561
- const allFields = findPageFields(event2);
1870
+ const allFields = findAllFields(event2);
1562
1871
  const fieldIds = allFields.map((field2) => field2.id);
1563
1872
  const advancedSearchFields = event2.advancedSearch.flatMap(
1564
1873
  (section) => section.fields.flatMap((field2) => field2.fieldId)
@@ -1585,106 +1894,118 @@ var EventConfig = import_zod18.z.object({
1585
1894
  });
1586
1895
 
1587
1896
  // ../commons/src/events/EventConfigInput.ts
1588
- var defineForm = (form) => FormConfig.parse(form);
1589
- var defineFormPage = (formPage) => FormPage.parse(formPage);
1897
+ var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
1898
+ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1899
+ var definePage = (page) => PageConfig.parse(page);
1900
+ var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1590
1901
 
1591
1902
  // ../commons/src/events/Draft.ts
1592
- var import_zod21 = require("zod");
1903
+ var import_zod23 = require("zod");
1593
1904
 
1594
1905
  // ../commons/src/events/ActionDocument.ts
1595
- var import_zod19 = require("zod");
1596
- var ActionUpdate = import_zod19.z.record(import_zod19.z.string(), FieldUpdateValue);
1597
- var ActionBase = import_zod19.z.object({
1598
- id: import_zod19.z.string(),
1599
- createdAt: import_zod19.z.string().datetime(),
1600
- createdBy: import_zod19.z.string(),
1601
- data: ActionUpdate,
1602
- metadata: ActionUpdate.optional(),
1603
- createdAtLocation: import_zod19.z.string()
1906
+ var import_zod21 = require("zod");
1907
+ var ActionUpdate = import_zod21.z.record(import_zod21.z.string(), FieldUpdateValue);
1908
+ var ActionStatus = {
1909
+ Requested: "Requested",
1910
+ Accepted: "Accepted",
1911
+ Rejected: "Rejected"
1912
+ };
1913
+ var ActionBase = import_zod21.z.object({
1914
+ id: import_zod21.z.string(),
1915
+ createdAt: import_zod21.z.string().datetime(),
1916
+ createdBy: import_zod21.z.string(),
1917
+ declaration: ActionUpdate,
1918
+ annotation: ActionUpdate.optional(),
1919
+ createdAtLocation: import_zod21.z.string(),
1920
+ status: import_zod21.z.enum([
1921
+ ActionStatus.Requested,
1922
+ ActionStatus.Accepted,
1923
+ ActionStatus.Rejected
1924
+ ]),
1925
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1926
+ originalActionId: import_zod21.z.string().optional()
1604
1927
  });
1605
1928
  var AssignedAction = ActionBase.merge(
1606
- import_zod19.z.object({
1607
- type: import_zod19.z.literal(ActionType.ASSIGN),
1608
- assignedTo: import_zod19.z.string()
1929
+ import_zod21.z.object({
1930
+ type: import_zod21.z.literal(ActionType.ASSIGN),
1931
+ assignedTo: import_zod21.z.string()
1609
1932
  })
1610
1933
  );
1611
1934
  var UnassignedAction = ActionBase.merge(
1612
- import_zod19.z.object({
1613
- type: import_zod19.z.literal(ActionType.UNASSIGN)
1935
+ import_zod21.z.object({
1936
+ type: import_zod21.z.literal(ActionType.UNASSIGN),
1937
+ assignedTo: import_zod21.z.literal(null).default(null)
1614
1938
  })
1615
1939
  );
1616
1940
  var RegisterAction = ActionBase.merge(
1617
- import_zod19.z.object({
1618
- type: import_zod19.z.literal(ActionType.REGISTER),
1619
- identifiers: import_zod19.z.object({
1620
- trackingId: import_zod19.z.string(),
1621
- registrationNumber: import_zod19.z.string()
1622
- })
1941
+ import_zod21.z.object({
1942
+ type: import_zod21.z.literal(ActionType.REGISTER),
1943
+ registrationNumber: import_zod21.z.string().optional()
1623
1944
  })
1624
1945
  );
1625
1946
  var DeclareAction = ActionBase.merge(
1626
- import_zod19.z.object({
1627
- type: import_zod19.z.literal(ActionType.DECLARE)
1947
+ import_zod21.z.object({
1948
+ type: import_zod21.z.literal(ActionType.DECLARE)
1628
1949
  })
1629
1950
  );
1630
1951
  var ValidateAction = ActionBase.merge(
1631
- import_zod19.z.object({
1632
- type: import_zod19.z.literal(ActionType.VALIDATE)
1952
+ import_zod21.z.object({
1953
+ type: import_zod21.z.literal(ActionType.VALIDATE)
1633
1954
  })
1634
1955
  );
1635
1956
  var RejectAction = ActionBase.merge(
1636
- import_zod19.z.object({
1637
- type: import_zod19.z.literal(ActionType.REJECT)
1957
+ import_zod21.z.object({
1958
+ type: import_zod21.z.literal(ActionType.REJECT)
1638
1959
  })
1639
1960
  );
1640
1961
  var MarkAsDuplicateAction = ActionBase.merge(
1641
- import_zod19.z.object({
1642
- type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1962
+ import_zod21.z.object({
1963
+ type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE)
1643
1964
  })
1644
1965
  );
1645
1966
  var ArchiveAction = ActionBase.merge(
1646
- import_zod19.z.object({
1647
- type: import_zod19.z.literal(ActionType.ARCHIVE)
1967
+ import_zod21.z.object({
1968
+ type: import_zod21.z.literal(ActionType.ARCHIVE)
1648
1969
  })
1649
1970
  );
1650
1971
  var CreatedAction = ActionBase.merge(
1651
- import_zod19.z.object({
1652
- type: import_zod19.z.literal(ActionType.CREATE)
1972
+ import_zod21.z.object({
1973
+ type: import_zod21.z.literal(ActionType.CREATE)
1653
1974
  })
1654
1975
  );
1655
1976
  var NotifiedAction = ActionBase.merge(
1656
- import_zod19.z.object({
1657
- type: import_zod19.z.literal(ActionType.NOTIFY)
1977
+ import_zod21.z.object({
1978
+ type: import_zod21.z.literal(ActionType.NOTIFY)
1658
1979
  })
1659
1980
  );
1660
1981
  var PrintCertificateAction = ActionBase.merge(
1661
- import_zod19.z.object({
1662
- type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE)
1982
+ import_zod21.z.object({
1983
+ type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE)
1663
1984
  })
1664
1985
  );
1665
1986
  var RequestedCorrectionAction = ActionBase.merge(
1666
- import_zod19.z.object({
1667
- type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION)
1987
+ import_zod21.z.object({
1988
+ type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION)
1668
1989
  })
1669
1990
  );
1670
1991
  var ApprovedCorrectionAction = ActionBase.merge(
1671
- import_zod19.z.object({
1672
- type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION),
1673
- requestId: import_zod19.z.string()
1992
+ import_zod21.z.object({
1993
+ type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION),
1994
+ requestId: import_zod21.z.string()
1674
1995
  })
1675
1996
  );
1676
1997
  var RejectedCorrectionAction = ActionBase.merge(
1677
- import_zod19.z.object({
1678
- type: import_zod19.z.literal(ActionType.REJECT_CORRECTION),
1679
- requestId: import_zod19.z.string()
1998
+ import_zod21.z.object({
1999
+ type: import_zod21.z.literal(ActionType.REJECT_CORRECTION),
2000
+ requestId: import_zod21.z.string()
1680
2001
  })
1681
2002
  );
1682
- var CustomAction = ActionBase.merge(
1683
- import_zod19.z.object({
1684
- type: import_zod19.z.literal(ActionType.CUSTOM)
2003
+ var ReadAction = ActionBase.merge(
2004
+ import_zod21.z.object({
2005
+ type: import_zod21.z.literal(ActionType.READ)
1685
2006
  })
1686
2007
  );
1687
- var ActionDocument = import_zod19.z.discriminatedUnion("type", [
2008
+ var ActionDocument = import_zod21.z.discriminatedUnion("type", [
1688
2009
  CreatedAction,
1689
2010
  ValidateAction,
1690
2011
  RejectAction,
@@ -1699,108 +2020,125 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1699
2020
  RejectedCorrectionAction,
1700
2021
  UnassignedAction,
1701
2022
  PrintCertificateAction,
1702
- CustomAction
2023
+ ReadAction
1703
2024
  ]);
1704
- var ResolvedUser = import_zod19.z.object({
1705
- id: import_zod19.z.string(),
1706
- role: import_zod19.z.string(),
1707
- name: import_zod19.z.array(
1708
- import_zod19.z.object({
1709
- use: import_zod19.z.string(),
1710
- given: import_zod19.z.array(import_zod19.z.string()),
1711
- family: import_zod19.z.string()
2025
+ var AsyncRejectActionDocument = ActionBase.omit({
2026
+ declaration: true,
2027
+ annotation: true,
2028
+ createdBy: true,
2029
+ createdAtLocation: true
2030
+ }).merge(
2031
+ import_zod21.z.object({
2032
+ type: import_zod21.z.enum(ConfirmableActions),
2033
+ status: import_zod21.z.literal(ActionStatus.Rejected)
2034
+ })
2035
+ );
2036
+ var Action = import_zod21.z.union([ActionDocument, AsyncRejectActionDocument]);
2037
+ var ResolvedUser = import_zod21.z.object({
2038
+ id: import_zod21.z.string(),
2039
+ role: import_zod21.z.string(),
2040
+ name: import_zod21.z.array(
2041
+ import_zod21.z.object({
2042
+ use: import_zod21.z.string(),
2043
+ given: import_zod21.z.array(import_zod21.z.string()),
2044
+ family: import_zod21.z.string()
1712
2045
  })
1713
2046
  )
1714
2047
  });
1715
2048
 
1716
2049
  // ../commons/src/events/ActionInput.ts
1717
- var import_zod20 = require("zod");
1718
- var BaseActionInput = import_zod20.z.object({
1719
- eventId: import_zod20.z.string(),
1720
- transactionId: import_zod20.z.string(),
1721
- data: ActionUpdate,
1722
- metadata: ActionUpdate.optional()
2050
+ var import_zod22 = require("zod");
2051
+ var BaseActionInput = import_zod22.z.object({
2052
+ eventId: import_zod22.z.string(),
2053
+ transactionId: import_zod22.z.string(),
2054
+ declaration: ActionUpdate.default({}),
2055
+ annotation: ActionUpdate.optional(),
2056
+ originalActionId: import_zod22.z.string().optional(),
2057
+ keepAssignment: import_zod22.z.boolean().optional()
1723
2058
  });
1724
2059
  var CreateActionInput = BaseActionInput.merge(
1725
- import_zod20.z.object({
1726
- type: import_zod20.z.literal(ActionType.CREATE).default(ActionType.CREATE),
1727
- createdAtLocation: import_zod20.z.string()
2060
+ import_zod22.z.object({
2061
+ type: import_zod22.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2062
+ createdAtLocation: import_zod22.z.string()
1728
2063
  })
1729
2064
  );
1730
2065
  var RegisterActionInput = BaseActionInput.merge(
1731
- import_zod20.z.object({
1732
- type: import_zod20.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
1733
- identifiers: import_zod20.z.object({
1734
- trackingId: import_zod20.z.string(),
1735
- registrationNumber: import_zod20.z.string()
1736
- })
2066
+ import_zod22.z.object({
2067
+ type: import_zod22.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2068
+ registrationNumber: import_zod22.z.string().optional()
1737
2069
  })
1738
2070
  );
1739
2071
  var ValidateActionInput = BaseActionInput.merge(
1740
- import_zod20.z.object({
1741
- type: import_zod20.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
1742
- duplicates: import_zod20.z.array(import_zod20.z.string())
2072
+ import_zod22.z.object({
2073
+ type: import_zod22.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2074
+ duplicates: import_zod22.z.array(import_zod22.z.string())
1743
2075
  })
1744
2076
  );
1745
2077
  var NotifyActionInput = BaseActionInput.merge(
1746
- import_zod20.z.object({
1747
- type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2078
+ import_zod22.z.object({
2079
+ type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1748
2080
  })
1749
2081
  );
1750
2082
  var DeclareActionInput = BaseActionInput.merge(
1751
- import_zod20.z.object({
1752
- type: import_zod20.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2083
+ import_zod22.z.object({
2084
+ type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1753
2085
  })
1754
2086
  );
1755
2087
  var PrintCertificateActionInput = BaseActionInput.merge(
1756
- import_zod20.z.object({
1757
- type: import_zod20.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2088
+ import_zod22.z.object({
2089
+ type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1758
2090
  })
1759
2091
  );
1760
2092
  var RejectDeclarationActionInput = BaseActionInput.merge(
1761
- import_zod20.z.object({
1762
- type: import_zod20.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2093
+ import_zod22.z.object({
2094
+ type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1763
2095
  })
1764
2096
  );
1765
2097
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1766
- import_zod20.z.object({
1767
- type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2098
+ import_zod22.z.object({
2099
+ type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1768
2100
  })
1769
2101
  );
1770
2102
  var ArchiveActionInput = BaseActionInput.merge(
1771
- import_zod20.z.object({
1772
- type: import_zod20.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2103
+ import_zod22.z.object({
2104
+ type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1773
2105
  })
1774
2106
  );
1775
2107
  var AssignActionInput = BaseActionInput.merge(
1776
- import_zod20.z.object({
1777
- type: import_zod20.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
1778
- assignedTo: import_zod20.z.string()
2108
+ import_zod22.z.object({
2109
+ type: import_zod22.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2110
+ assignedTo: import_zod22.z.string()
1779
2111
  })
1780
2112
  );
1781
2113
  var UnassignActionInput = BaseActionInput.merge(
1782
- import_zod20.z.object({
1783
- type: import_zod20.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN)
2114
+ import_zod22.z.object({
2115
+ type: import_zod22.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2116
+ assignedTo: import_zod22.z.literal(null).default(null)
1784
2117
  })
1785
2118
  );
1786
2119
  var RequestCorrectionActionInput = BaseActionInput.merge(
1787
- import_zod20.z.object({
1788
- type: import_zod20.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2120
+ import_zod22.z.object({
2121
+ type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
1789
2122
  })
1790
2123
  );
1791
2124
  var RejectCorrectionActionInput = BaseActionInput.merge(
1792
- import_zod20.z.object({
1793
- requestId: import_zod20.z.string(),
1794
- type: import_zod20.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2125
+ import_zod22.z.object({
2126
+ requestId: import_zod22.z.string(),
2127
+ type: import_zod22.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
1795
2128
  })
1796
2129
  );
1797
2130
  var ApproveCorrectionActionInput = BaseActionInput.merge(
1798
- import_zod20.z.object({
1799
- requestId: import_zod20.z.string(),
1800
- type: import_zod20.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2131
+ import_zod22.z.object({
2132
+ requestId: import_zod22.z.string(),
2133
+ type: import_zod22.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2134
+ })
2135
+ );
2136
+ var ReadActionInput = BaseActionInput.merge(
2137
+ import_zod22.z.object({
2138
+ type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
1801
2139
  })
1802
2140
  );
1803
- var ActionInput = import_zod20.z.discriminatedUnion("type", [
2141
+ var ActionInput = import_zod22.z.discriminatedUnion("type", [
1804
2142
  CreateActionInput,
1805
2143
  ValidateActionInput,
1806
2144
  RegisterActionInput,
@@ -1814,79 +2152,90 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
1814
2152
  PrintCertificateActionInput,
1815
2153
  RequestCorrectionActionInput,
1816
2154
  RejectCorrectionActionInput,
1817
- ApproveCorrectionActionInput
2155
+ ApproveCorrectionActionInput,
2156
+ ReadActionInput
1818
2157
  ]);
1819
2158
 
1820
2159
  // ../commons/src/events/Draft.ts
1821
- var Draft = import_zod21.z.object({
1822
- id: import_zod21.z.string(),
1823
- eventId: import_zod21.z.string(),
1824
- transactionId: import_zod21.z.string(),
1825
- createdAt: import_zod21.z.string().datetime(),
2160
+ var Draft = import_zod23.z.object({
2161
+ id: import_zod23.z.string(),
2162
+ eventId: import_zod23.z.string(),
2163
+ transactionId: import_zod23.z.string(),
2164
+ createdAt: import_zod23.z.string().datetime(),
1826
2165
  action: ActionBase.extend({
1827
- type: import_zod21.z.enum(Object.values(ActionType))
2166
+ type: ActionTypes
1828
2167
  }).omit({ id: true })
1829
2168
  });
1830
2169
  var DraftInput = BaseActionInput.extend({
1831
- type: import_zod21.z.enum(Object.values(ActionType))
2170
+ type: ActionTypes
1832
2171
  });
1833
2172
 
1834
2173
  // ../commons/src/events/EventInput.ts
1835
- var import_zod22 = require("zod");
1836
- var EventInput = import_zod22.z.object({
1837
- transactionId: import_zod22.z.string(),
1838
- type: import_zod22.z.string()
2174
+ var import_zod24 = require("zod");
2175
+ var EventInput = import_zod24.z.object({
2176
+ transactionId: import_zod24.z.string(),
2177
+ type: import_zod24.z.string()
1839
2178
  });
1840
2179
 
1841
2180
  // ../commons/src/events/EventDocument.ts
1842
- var import_zod23 = require("zod");
1843
- var EventDocument = import_zod23.z.object({
1844
- id: import_zod23.z.string(),
1845
- type: import_zod23.z.string(),
1846
- createdAt: import_zod23.z.string().datetime(),
1847
- updatedAt: import_zod23.z.string().datetime(),
1848
- actions: import_zod23.z.array(ActionDocument),
1849
- trackingId: import_zod23.z.string()
2181
+ var import_zod25 = require("zod");
2182
+ var EventDocument = import_zod25.z.object({
2183
+ id: import_zod25.z.string(),
2184
+ type: import_zod25.z.string(),
2185
+ createdAt: import_zod25.z.string().datetime(),
2186
+ updatedAt: import_zod25.z.string().datetime(),
2187
+ updatedAtLocation: import_zod25.z.string(),
2188
+ actions: import_zod25.z.array(Action),
2189
+ trackingId: import_zod25.z.string()
1850
2190
  });
1851
2191
 
1852
2192
  // ../commons/src/events/EventIndex.ts
1853
- var import_zod24 = require("zod");
2193
+ var import_zod26 = require("zod");
1854
2194
  var EventIndex = EventMetadata.extend({
1855
- data: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any())
2195
+ declaration: import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any())
1856
2196
  });
1857
- var EventSearchIndex = import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any()).and(
1858
- import_zod24.z.object({
1859
- type: import_zod24.z.string()
2197
+ var EventSearchIndex = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any()).and(
2198
+ import_zod26.z.object({
2199
+ type: import_zod26.z.string()
1860
2200
  // Ensures "type" (event-id) exists and is a string
1861
2201
  })
1862
2202
  );
1863
2203
 
1864
2204
  // ../commons/src/events/state/index.ts
1865
- var _ = __toESM(require("lodash"));
1866
2205
  function getStatusFromActions(actions) {
2206
+ const hasRejectedAction = actions.some(
2207
+ (a) => a.status === ActionStatus.Rejected
2208
+ );
2209
+ if (hasRejectedAction) {
2210
+ return EventStatus.REJECTED;
2211
+ }
1867
2212
  return actions.reduce((status, action) => {
1868
- if (action.type === ActionType.CREATE) {
1869
- return EventStatus.CREATED;
1870
- }
1871
- if (action.type === ActionType.DECLARE) {
1872
- return EventStatus.DECLARED;
1873
- }
1874
- if (action.type === ActionType.VALIDATE) {
1875
- return EventStatus.VALIDATED;
1876
- }
1877
- if (action.type === ActionType.REGISTER) {
1878
- return EventStatus.REGISTERED;
1879
- }
1880
- if (action.type === ActionType.REJECT) {
1881
- return EventStatus.REJECTED;
1882
- }
1883
- if (action.type === ActionType.ARCHIVE) {
1884
- return EventStatus.ARCHIVED;
1885
- }
1886
- if (action.type === ActionType.NOTIFY) {
1887
- return EventStatus.NOTIFIED;
2213
+ switch (action.type) {
2214
+ case ActionType.CREATE:
2215
+ return EventStatus.CREATED;
2216
+ case ActionType.DECLARE:
2217
+ return EventStatus.DECLARED;
2218
+ case ActionType.VALIDATE:
2219
+ return EventStatus.VALIDATED;
2220
+ case ActionType.REGISTER:
2221
+ return EventStatus.REGISTERED;
2222
+ case ActionType.REJECT:
2223
+ return EventStatus.REJECTED;
2224
+ case ActionType.ARCHIVE:
2225
+ return EventStatus.ARCHIVED;
2226
+ case ActionType.NOTIFY:
2227
+ return EventStatus.NOTIFIED;
2228
+ case ActionType.PRINT_CERTIFICATE:
2229
+ case ActionType.ASSIGN:
2230
+ case ActionType.UNASSIGN:
2231
+ case ActionType.REQUEST_CORRECTION:
2232
+ case ActionType.APPROVE_CORRECTION:
2233
+ case ActionType.MARKED_AS_DUPLICATE:
2234
+ case ActionType.REJECT_CORRECTION:
2235
+ case ActionType.READ:
2236
+ default:
2237
+ return status;
1888
2238
  }
1889
- return status;
1890
2239
  }, EventStatus.CREATED);
1891
2240
  }
1892
2241
  function getAssignedUserFromActions(actions) {
@@ -1900,7 +2249,7 @@ function getAssignedUserFromActions(actions) {
1900
2249
  return user2;
1901
2250
  }, null);
1902
2251
  }
1903
- function getData(actions) {
2252
+ function aggregateActionDeclarations(actions) {
1904
2253
  const excludedActions = [
1905
2254
  ActionType.REQUEST_CORRECTION,
1906
2255
  ActionType.PRINT_CERTIFICATE
@@ -1914,47 +2263,35 @@ function getData(actions) {
1914
2263
  if (!requestAction) {
1915
2264
  return status;
1916
2265
  }
1917
- return deepMerge(status, requestAction.data);
2266
+ return deepMerge(status, requestAction.declaration);
1918
2267
  }
1919
- return deepMerge(status, action.data);
2268
+ return deepMerge(status, action.declaration);
1920
2269
  }, {});
1921
2270
  }
1922
2271
  function deepDropNulls(obj) {
1923
- if (!_.isObject(obj)) return obj;
1924
- return Object.entries(obj).reduce((acc, [key, value]) => {
1925
- if (_.isObject(value)) {
1926
- value = deepDropNulls(value);
1927
- }
1928
- if (value !== null) {
1929
- return {
1930
- ...acc,
1931
- [key]: value
1932
- };
1933
- }
1934
- return acc;
1935
- }, {});
1936
- }
1937
- function deepMerge(currentDocument, actionDocument) {
1938
- return _.mergeWith(
1939
- currentDocument,
1940
- actionDocument,
1941
- (previousValue, incomingValue) => {
1942
- if (incomingValue === void 0) {
1943
- return previousValue;
1944
- }
1945
- if (_.isArray(incomingValue)) {
1946
- return incomingValue;
1947
- }
1948
- if (_.isObject(previousValue) && _.isObject(incomingValue)) {
1949
- return void 0;
2272
+ if (Array.isArray(obj)) {
2273
+ return obj.map(deepDropNulls);
2274
+ }
2275
+ if (obj !== null && typeof obj === "object") {
2276
+ return Object.entries(obj).reduce((acc, [key, value]) => {
2277
+ const cleanedValue = deepDropNulls(value);
2278
+ if (cleanedValue !== null) {
2279
+ ;
2280
+ acc[key] = cleanedValue;
1950
2281
  }
1951
- return incomingValue;
1952
- }
1953
- );
2282
+ return acc;
2283
+ }, {});
2284
+ }
2285
+ return obj;
1954
2286
  }
1955
2287
  function isUndeclaredDraft(status) {
1956
2288
  return status === EventStatus.CREATED;
1957
2289
  }
2290
+ function getAcceptedActions(event2) {
2291
+ return event2.actions.filter(
2292
+ (a) => a.status === ActionStatus.Accepted
2293
+ );
2294
+ }
1958
2295
  function getCurrentEventState(event2) {
1959
2296
  const creationAction = event2.actions.find(
1960
2297
  (action) => action.type === ActionType.CREATE
@@ -1962,7 +2299,12 @@ function getCurrentEventState(event2) {
1962
2299
  if (!creationAction) {
1963
2300
  throw new Error(`Event ${event2.id} has no creation action`);
1964
2301
  }
1965
- const latestAction = event2.actions[event2.actions.length - 1];
2302
+ const activeActions = getAcceptedActions(event2);
2303
+ const latestAction = activeActions[activeActions.length - 1];
2304
+ const registrationAction = activeActions.find(
2305
+ (a) => a.type === ActionType.REGISTER && a.status === ActionStatus.Accepted
2306
+ );
2307
+ const registrationNumber = registrationAction?.registrationNumber ?? null;
1966
2308
  return deepDropNulls({
1967
2309
  id: event2.id,
1968
2310
  type: event2.type,
@@ -1971,10 +2313,12 @@ function getCurrentEventState(event2) {
1971
2313
  createdBy: creationAction.createdBy,
1972
2314
  createdAtLocation: creationAction.createdAtLocation,
1973
2315
  modifiedAt: latestAction.createdAt,
1974
- assignedTo: getAssignedUserFromActions(event2.actions),
2316
+ assignedTo: getAssignedUserFromActions(activeActions),
1975
2317
  updatedBy: latestAction.createdBy,
1976
- data: getData(event2.actions),
1977
- trackingId: event2.trackingId
2318
+ updatedAtLocation: event2.updatedAtLocation,
2319
+ declaration: aggregateActionDeclarations(activeActions),
2320
+ trackingId: event2.trackingId,
2321
+ registrationNumber
1978
2322
  });
1979
2323
  }
1980
2324
  function getCurrentEventStateWithDrafts(event2, drafts) {
@@ -2006,38 +2350,44 @@ function applyDraftsToEventIndex(eventIndex, drafts) {
2006
2350
  }
2007
2351
  return {
2008
2352
  ...eventIndex,
2009
- data: {
2010
- ...eventIndex.data,
2011
- ...activeDrafts[activeDrafts.length - 1].data
2353
+ declaration: {
2354
+ ...eventIndex.declaration,
2355
+ ...activeDrafts[activeDrafts.length - 1].declaration
2012
2356
  }
2013
2357
  };
2014
2358
  }
2015
- function getMetadataForAction({
2359
+ function getAnnotationFromDrafts(drafts) {
2360
+ const actions = drafts.map((draft) => draft.action);
2361
+ const annotation = actions.reduce((ann, action) => {
2362
+ return deepMerge(ann, action.annotation ?? {});
2363
+ }, {});
2364
+ return deepDropNulls(annotation);
2365
+ }
2366
+ function getActionAnnotation({
2016
2367
  event: event2,
2017
2368
  actionType,
2018
2369
  drafts
2019
2370
  }) {
2020
- const action = event2.actions.find((action2) => actionType === action2.type);
2371
+ const activeActions = getAcceptedActions(event2);
2372
+ const action = activeActions.find(
2373
+ (activeAction) => actionType === activeAction.type
2374
+ );
2021
2375
  const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
2022
2376
  const sorted = [
2023
2377
  ...action ? [action] : [],
2024
2378
  ...eventDrafts.map((draft) => draft.action)
2025
2379
  ].sort();
2026
- const metadata = sorted.reduce((metadata2, action2) => {
2027
- return deepMerge(metadata2, action2.metadata ?? {});
2380
+ const annotation = sorted.reduce((ann, sortedAction) => {
2381
+ return deepMerge(ann, sortedAction.annotation ?? {});
2028
2382
  }, {});
2029
- return deepDropNulls(metadata);
2383
+ return deepDropNulls(annotation);
2030
2384
  }
2031
2385
 
2032
2386
  // ../commons/src/events/defineConfig.ts
2033
2387
  var defineConfig = (config) => {
2034
2388
  validateWorkqueueConfig(config.workqueues);
2035
2389
  const input = EventConfig.parse(config);
2036
- const pageFields = findInputPageFields(input);
2037
- return EventConfig.parse({
2038
- ...input,
2039
- pageFields
2040
- });
2390
+ return input;
2041
2391
  };
2042
2392
 
2043
2393
  // ../commons/src/events/transactions.ts
@@ -2052,6 +2402,16 @@ var import_lodash2 = require("lodash");
2052
2402
  function defineConditional(schema) {
2053
2403
  return schema;
2054
2404
  }
2405
+ function defineFormConditional(schema) {
2406
+ const schemaWithForm = {
2407
+ type: "object",
2408
+ properties: {
2409
+ $form: schema
2410
+ },
2411
+ required: ["$form"]
2412
+ };
2413
+ return defineConditional(schemaWithForm);
2414
+ }
2055
2415
  function alwaysTrue() {
2056
2416
  return {};
2057
2417
  }
@@ -2076,6 +2436,9 @@ function not(condition) {
2076
2436
  required: []
2077
2437
  });
2078
2438
  }
2439
+ function never() {
2440
+ return not(alwaysTrue());
2441
+ }
2079
2442
  var user = {
2080
2443
  hasScope: (scope) => defineConditional({
2081
2444
  type: "object",
@@ -2123,69 +2486,120 @@ var event = {
2123
2486
  required: ["$event"]
2124
2487
  })
2125
2488
  };
2489
+ function getDateFromNow(days) {
2490
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2491
+ }
2492
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2493
+ return {
2494
+ type: "object",
2495
+ properties: {
2496
+ [fieldId]: {
2497
+ type: "string",
2498
+ format: "date",
2499
+ [clause]: { $data: `1/${comparedFieldId}` }
2500
+ },
2501
+ [comparedFieldId]: { type: "string", format: "date" }
2502
+ },
2503
+ required: [fieldId]
2504
+ };
2505
+ }
2506
+ function isFieldReference(value) {
2507
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2508
+ }
2126
2509
  function field(fieldId) {
2127
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2128
2510
  const getDateRange = (date, clause) => ({
2129
2511
  type: "object",
2130
2512
  properties: {
2131
- $form: {
2132
- type: "object",
2133
- properties: {
2134
- [fieldId]: {
2135
- type: "string",
2136
- format: "date",
2137
- [clause]: date
2138
- }
2139
- },
2140
- required: [fieldId]
2513
+ [fieldId]: {
2514
+ type: "string",
2515
+ format: "date",
2516
+ [clause]: date
2141
2517
  }
2142
2518
  },
2143
- required: ["$form"]
2519
+ required: [fieldId]
2144
2520
  });
2145
2521
  return {
2522
+ /**
2523
+ * @private Internal property used for field reference tracking.
2524
+ */
2525
+ _fieldId: fieldId,
2146
2526
  isAfter: () => ({
2147
2527
  days: (days) => ({
2148
- inPast: () => defineConditional(
2528
+ inPast: () => defineFormConditional(
2149
2529
  getDateRange(getDateFromNow(days), "formatMinimum")
2150
2530
  ),
2151
- inFuture: () => defineConditional(
2531
+ inFuture: () => defineFormConditional(
2152
2532
  getDateRange(getDateFromNow(-days), "formatMinimum")
2153
2533
  )
2154
2534
  }),
2155
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
2156
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2535
+ date: (date) => {
2536
+ if (isFieldReference(date)) {
2537
+ const comparedFieldId = date._fieldId;
2538
+ return defineFormConditional(
2539
+ getDateRangeToFieldReference(
2540
+ fieldId,
2541
+ comparedFieldId,
2542
+ "formatMinimum"
2543
+ )
2544
+ );
2545
+ }
2546
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2547
+ },
2548
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2157
2549
  }),
2158
2550
  isBefore: () => ({
2159
2551
  days: (days) => ({
2160
- inPast: () => defineConditional(
2552
+ inPast: () => defineFormConditional(
2161
2553
  getDateRange(getDateFromNow(days), "formatMaximum")
2162
2554
  ),
2163
- inFuture: () => defineConditional(
2555
+ inFuture: () => defineFormConditional(
2164
2556
  getDateRange(getDateFromNow(-days), "formatMaximum")
2165
2557
  )
2166
2558
  }),
2167
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
2168
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2559
+ date: (date) => {
2560
+ if (isFieldReference(date)) {
2561
+ const comparedFieldId = date._fieldId;
2562
+ return defineFormConditional(
2563
+ getDateRangeToFieldReference(
2564
+ fieldId,
2565
+ comparedFieldId,
2566
+ "formatMaximum"
2567
+ )
2568
+ );
2569
+ }
2570
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2571
+ },
2572
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2169
2573
  }),
2170
- isEqualTo: (value) => defineConditional({
2171
- type: "object",
2172
- properties: {
2173
- $form: {
2574
+ isEqualTo: (value) => {
2575
+ if (isFieldReference(value)) {
2576
+ const comparedFieldId = value._fieldId;
2577
+ return defineFormConditional({
2174
2578
  type: "object",
2175
2579
  properties: {
2176
2580
  [fieldId]: {
2177
- oneOf: [
2178
- { type: "string", const: value },
2179
- { type: "boolean", const: value }
2180
- ],
2181
- const: value
2182
- }
2581
+ type: ["string", "boolean"],
2582
+ const: { $data: `1/${comparedFieldId}` }
2583
+ },
2584
+ [comparedFieldId]: { type: ["string", "boolean"] }
2183
2585
  },
2184
- required: [fieldId]
2185
- }
2186
- },
2187
- required: ["$form"]
2188
- }),
2586
+ required: [fieldId, comparedFieldId]
2587
+ });
2588
+ }
2589
+ return defineFormConditional({
2590
+ type: "object",
2591
+ properties: {
2592
+ [fieldId]: {
2593
+ oneOf: [
2594
+ { type: "string", const: value },
2595
+ { type: "boolean", const: value }
2596
+ ],
2597
+ const: value
2598
+ }
2599
+ },
2600
+ required: [fieldId]
2601
+ });
2602
+ },
2189
2603
  /**
2190
2604
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
2191
2605
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -2194,91 +2608,102 @@ function field(fieldId) {
2194
2608
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2195
2609
  *
2196
2610
  */
2197
- isFalsy: () => defineConditional({
2611
+ isFalsy: () => defineFormConditional({
2198
2612
  type: "object",
2199
2613
  properties: {
2200
- $form: {
2201
- type: "object",
2202
- properties: {
2203
- [fieldId]: {
2204
- anyOf: [
2205
- { const: "undefined" },
2206
- { const: false },
2207
- { const: null },
2208
- { const: "" }
2209
- ]
2210
- }
2211
- },
2614
+ [fieldId]: {
2212
2615
  anyOf: [
2213
- {
2214
- required: [fieldId]
2215
- },
2216
- {
2217
- not: {
2218
- required: [fieldId]
2219
- }
2220
- }
2616
+ { const: "undefined" },
2617
+ { const: false },
2618
+ { const: null },
2619
+ { const: "" }
2221
2620
  ]
2222
2621
  }
2223
2622
  },
2224
- required: ["$form"]
2225
- }),
2226
- isUndefined: () => defineConditional({
2227
- type: "object",
2228
- properties: {
2229
- $form: {
2230
- type: "object",
2231
- properties: {
2232
- [fieldId]: {
2233
- type: "string",
2234
- enum: ["undefined"]
2235
- }
2236
- },
2623
+ anyOf: [
2624
+ {
2625
+ required: [fieldId]
2626
+ },
2627
+ {
2237
2628
  not: {
2238
2629
  required: [fieldId]
2239
2630
  }
2240
2631
  }
2632
+ ]
2633
+ }),
2634
+ isUndefined: () => defineFormConditional({
2635
+ type: "object",
2636
+ properties: {
2637
+ [fieldId]: {
2638
+ type: "string",
2639
+ enum: ["undefined"]
2640
+ }
2241
2641
  },
2242
- required: ["$form"]
2642
+ not: {
2643
+ required: [fieldId]
2644
+ }
2243
2645
  }),
2244
- inArray: (values) => defineConditional({
2646
+ inArray: (values) => defineFormConditional({
2245
2647
  type: "object",
2246
2648
  properties: {
2247
- $form: {
2248
- type: "object",
2249
- properties: {
2250
- [fieldId]: {
2251
- type: "string",
2252
- enum: values
2253
- }
2254
- },
2255
- required: [fieldId]
2649
+ [fieldId]: {
2650
+ type: "string",
2651
+ enum: values
2652
+ }
2653
+ },
2654
+ required: [fieldId]
2655
+ }),
2656
+ isValidEnglishName: () => defineFormConditional({
2657
+ type: "object",
2658
+ properties: {
2659
+ [fieldId]: {
2660
+ type: "string",
2661
+ 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'._-]*)*$",
2662
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2663
+ }
2664
+ },
2665
+ required: [fieldId]
2666
+ }),
2667
+ /**
2668
+ * Checks if the field value matches a given regular expression pattern.
2669
+ * @param pattern - The regular expression pattern to match the field value against.
2670
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2671
+ */
2672
+ matches: (pattern) => defineFormConditional({
2673
+ type: "object",
2674
+ properties: {
2675
+ [fieldId]: {
2676
+ type: "string",
2677
+ pattern
2256
2678
  }
2257
2679
  },
2258
- required: ["$form"]
2680
+ required: [fieldId]
2681
+ }),
2682
+ isBetween: (min, max) => defineFormConditional({
2683
+ type: "object",
2684
+ properties: {
2685
+ [fieldId]: {
2686
+ type: "number",
2687
+ minimum: min,
2688
+ maximum: max
2689
+ }
2690
+ },
2691
+ required: [fieldId]
2259
2692
  })
2260
2693
  };
2261
2694
  }
2262
2695
 
2263
2696
  // ../commons/src/fixtures/tennis-club-membership-event.ts
2264
- var PRINT_CERTIFICATE_FORM = defineForm({
2697
+ var PRINT_CERTIFICATE_FORM = defineActionForm({
2265
2698
  label: {
2266
2699
  id: "v2.event.tennis-club-membership.action.certificate.form.label",
2267
2700
  defaultMessage: "Tennis club membership certificate collector",
2268
2701
  description: "This is what this form is referred as in the system"
2269
2702
  },
2270
- version: {
2271
- id: "1.0.0",
2272
- label: {
2273
- id: "v2.event.tennis-club-membership.action.certificate.form.version.1",
2274
- defaultMessage: "Version 1",
2275
- description: "This is the first version of the form"
2276
- }
2277
- },
2278
- active: true,
2279
2703
  pages: [
2280
2704
  {
2281
2705
  id: "collector",
2706
+ type: PageTypes.enum.FORM,
2282
2707
  title: {
2283
2708
  id: "v2.event.tennis-club-membership.action.certificate.form.section.who.title",
2284
2709
  defaultMessage: "Print certified copy",
@@ -2293,7 +2718,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2293
2718
  defaultMessage: "Requester",
2294
2719
  description: "This is the label for the field"
2295
2720
  },
2296
- type: "SELECT",
2721
+ type: FieldType.SELECT,
2297
2722
  options: [
2298
2723
  {
2299
2724
  value: "INFORMANT",
@@ -2370,7 +2795,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2370
2795
  defaultMessage: "Select Type of ID",
2371
2796
  description: "This is the label for selecting the type of ID"
2372
2797
  },
2373
- type: "SELECT",
2798
+ type: FieldType.SELECT,
2374
2799
  options: [
2375
2800
  {
2376
2801
  value: "PASSPORT",
@@ -2471,7 +2896,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2471
2896
  defaultMessage: "Passport Details",
2472
2897
  description: "Field for entering Passport details"
2473
2898
  },
2474
- type: "TEXT"
2899
+ type: FieldType.TEXT
2475
2900
  },
2476
2901
  {
2477
2902
  id: "collector.DRIVING_LICENSE.details",
@@ -2522,7 +2947,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2522
2947
  defaultMessage: "Driving License Details",
2523
2948
  description: "Field for entering Driving License details"
2524
2949
  },
2525
- type: "TEXT"
2950
+ type: FieldType.TEXT
2526
2951
  },
2527
2952
  {
2528
2953
  id: "collector.REFUGEE_NUMBER.details",
@@ -2573,7 +2998,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2573
2998
  defaultMessage: "Refugee Number Details",
2574
2999
  description: "Field for entering Refugee Number details"
2575
3000
  },
2576
- type: "TEXT"
3001
+ type: FieldType.TEXT
2577
3002
  },
2578
3003
  {
2579
3004
  id: "collector.ALIEN_NUMBER.details",
@@ -2624,7 +3049,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2624
3049
  defaultMessage: "Alien Number Details",
2625
3050
  description: "Field for entering Alien Number details"
2626
3051
  },
2627
- type: "TEXT"
3052
+ type: FieldType.TEXT
2628
3053
  },
2629
3054
  {
2630
3055
  id: "collector.OTHER.idTypeOther",
@@ -2675,7 +3100,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2675
3100
  defaultMessage: "Other ID Type (if applicable)",
2676
3101
  description: 'Field for entering ID type if "Other" is selected'
2677
3102
  },
2678
- type: "TEXT"
3103
+ type: FieldType.TEXT
2679
3104
  },
2680
3105
  {
2681
3106
  id: "collector.OTHER.firstName",
@@ -2726,7 +3151,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2726
3151
  defaultMessage: "First Name",
2727
3152
  description: "This is the label for the first name field"
2728
3153
  },
2729
- type: "TEXT"
3154
+ type: FieldType.TEXT
2730
3155
  },
2731
3156
  {
2732
3157
  id: "collector.OTHER.lastName",
@@ -2777,7 +3202,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2777
3202
  defaultMessage: "Last Name",
2778
3203
  description: "This is the label for the last name field"
2779
3204
  },
2780
- type: "TEXT"
3205
+ type: FieldType.TEXT
2781
3206
  },
2782
3207
  {
2783
3208
  id: "collector.OTHER.relationshipToMember",
@@ -2828,7 +3253,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2828
3253
  defaultMessage: "Relationship to Member",
2829
3254
  description: "This is the label for the relationship to member field"
2830
3255
  },
2831
- type: "TEXT"
3256
+ type: FieldType.TEXT
2832
3257
  },
2833
3258
  {
2834
3259
  id: "collector.OTHER.signedAffidavit",
@@ -2879,66 +3304,88 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2879
3304
  defaultMessage: "Signed Affidavit (Optional)",
2880
3305
  description: "This is the label for uploading a signed affidavit"
2881
3306
  },
2882
- type: "FILE"
3307
+ type: FieldType.FILE
2883
3308
  }
2884
3309
  ]
2885
- }
2886
- ],
2887
- review: {
2888
- title: {
2889
- id: "v2.event.tennis-club-membership.action.certificate.form.review.title",
2890
- defaultMessage: "Member certificate collector for {firstname} {surname}",
2891
- description: "Title of the form to show in review page"
2892
3310
  },
2893
- fields: []
2894
- }
2895
- });
2896
- var TENNIS_CLUB_FORM = defineForm({
2897
- label: {
2898
- id: "v2.event.tennis-club-membership.action.declare.form.label",
2899
- defaultMessage: "Tennis club membership application",
2900
- description: "This is what this form is referred as in the system"
2901
- },
2902
- active: true,
2903
- version: {
2904
- id: "1.0.0",
2905
- label: {
2906
- id: "v2.event.tennis-club-membership.action.declare.form.version.1",
2907
- defaultMessage: "Version 1",
2908
- description: "This is the first version of the form"
3311
+ {
3312
+ id: "collector.identity.verify",
3313
+ type: PageTypes.enum.VERIFICATION,
3314
+ conditional: field("collector.requesterId").isEqualTo("INFORMANT"),
3315
+ title: {
3316
+ id: "event.tennis-club-membership.action.print.verifyIdentity",
3317
+ defaultMessage: "Verify their identity",
3318
+ description: "This is the title of the section"
3319
+ },
3320
+ fields: [],
3321
+ actions: {
3322
+ verify: {
3323
+ label: {
3324
+ defaultMessage: "Verified",
3325
+ description: "This is the label for the verification button",
3326
+ id: "v2.event.tennis-club-membership.action.certificate.form.verify"
3327
+ }
3328
+ },
3329
+ cancel: {
3330
+ label: {
3331
+ defaultMessage: "Identity does not match",
3332
+ description: "This is the label for the verification cancellation button",
3333
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel"
3334
+ },
3335
+ confirmation: {
3336
+ title: {
3337
+ defaultMessage: "Print without proof of ID?",
3338
+ description: "This is the title for the verification cancellation modal",
3339
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel.confirmation.title"
3340
+ },
3341
+ body: {
3342
+ 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",
3343
+ description: "This is the body for the verification cancellation modal",
3344
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel.confirmation.body"
3345
+ }
3346
+ }
3347
+ }
3348
+ }
2909
3349
  }
3350
+ ]
3351
+ });
3352
+ var TENNIS_CLUB_DECLARATION_REVIEW = {
3353
+ title: {
3354
+ id: "v2.event.tennis-club-membership.action.declare.form.review.title",
3355
+ defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
3356
+ description: "Title of the review page"
2910
3357
  },
2911
- review: {
2912
- title: {
2913
- id: "v2.event.tennis-club-membership.action.declare.form.review.title",
2914
- defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
2915
- description: "Title of the form to show in review page"
3358
+ fields: [
3359
+ {
3360
+ id: "review.comment",
3361
+ type: FieldType.TEXTAREA,
3362
+ label: {
3363
+ defaultMessage: "Comment",
3364
+ id: "v2.event.birth.action.declare.form.review.comment.label",
3365
+ description: "Label for the comment field in the review section"
3366
+ }
2916
3367
  },
2917
- fields: [
2918
- {
2919
- id: "review.comment",
2920
- type: "TEXTAREA",
2921
- label: {
2922
- defaultMessage: "Comment",
2923
- id: "v2.event.birth.action.declare.form.review.comment.label",
2924
- description: "Label for the comment field in the review section"
2925
- }
3368
+ {
3369
+ type: FieldType.SIGNATURE,
3370
+ id: "review.signature",
3371
+ label: {
3372
+ defaultMessage: "Signature of informant",
3373
+ id: "v2.event.birth.action.declare.form.review.signature.label",
3374
+ description: "Label for the signature field in the review section"
2926
3375
  },
2927
- {
2928
- type: "SIGNATURE",
2929
- id: "review.signature",
2930
- label: {
2931
- defaultMessage: "Signature of informant",
2932
- id: "v2.event.birth.action.declare.form.review.signature.label",
2933
- description: "Label for the signature field in the review section"
2934
- },
2935
- signaturePromptLabel: {
2936
- id: "v2.signature.upload.modal.title",
2937
- defaultMessage: "Draw signature",
2938
- description: "Title for the modal to draw signature"
2939
- }
3376
+ signaturePromptLabel: {
3377
+ id: "v2.signature.upload.modal.title",
3378
+ defaultMessage: "Draw signature",
3379
+ description: "Title for the modal to draw signature"
2940
3380
  }
2941
- ]
3381
+ }
3382
+ ]
3383
+ };
3384
+ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3385
+ label: {
3386
+ id: "v2.event.tennis-club-membership.action.declare.form.label",
3387
+ defaultMessage: "Tennis club membership application",
3388
+ description: "This is what this form is referred as in the system"
2942
3389
  },
2943
3390
  pages: [
2944
3391
  {
@@ -2951,7 +3398,7 @@ var TENNIS_CLUB_FORM = defineForm({
2951
3398
  fields: [
2952
3399
  {
2953
3400
  id: "applicant.firstname",
2954
- type: "TEXT",
3401
+ type: FieldType.TEXT,
2955
3402
  required: true,
2956
3403
  conditionals: [],
2957
3404
  label: {
@@ -2962,7 +3409,7 @@ var TENNIS_CLUB_FORM = defineForm({
2962
3409
  },
2963
3410
  {
2964
3411
  id: "applicant.surname",
2965
- type: "TEXT",
3412
+ type: FieldType.TEXT,
2966
3413
  required: true,
2967
3414
  conditionals: [],
2968
3415
  label: {
@@ -2984,9 +3431,8 @@ var TENNIS_CLUB_FORM = defineForm({
2984
3431
  },
2985
3432
  {
2986
3433
  id: "applicant.dob",
2987
- type: "DATE",
3434
+ type: FieldType.DATE,
2988
3435
  required: true,
2989
- conditionals: [],
2990
3436
  validation: [
2991
3437
  {
2992
3438
  message: {
@@ -2997,15 +3443,53 @@ var TENNIS_CLUB_FORM = defineForm({
2997
3443
  validator: field("applicant.dob").isBefore().now()
2998
3444
  }
2999
3445
  ],
3446
+ conditionals: [
3447
+ {
3448
+ type: ConditionalType.SHOW,
3449
+ conditional: field("applicant.dobUnknown").isFalsy()
3450
+ }
3451
+ ],
3000
3452
  label: {
3001
3453
  defaultMessage: "Applicant's date of birth",
3002
3454
  description: "This is the label for the field",
3003
3455
  id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dob.label"
3004
3456
  }
3005
3457
  },
3458
+ {
3459
+ id: "applicant.dobUnknown",
3460
+ type: FieldType.CHECKBOX,
3461
+ required: false,
3462
+ label: {
3463
+ defaultMessage: "Exact date of birth unknown",
3464
+ description: "This is the label for the field",
3465
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dobUnknown.label"
3466
+ },
3467
+ conditionals: [
3468
+ {
3469
+ type: ConditionalType.DISPLAY_ON_REVIEW,
3470
+ conditional: never()
3471
+ }
3472
+ ]
3473
+ },
3474
+ {
3475
+ id: "applicant.age",
3476
+ type: FieldType.NUMBER,
3477
+ required: true,
3478
+ label: {
3479
+ defaultMessage: "Age of tennis-member",
3480
+ description: "This is the label for the field",
3481
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.age.label"
3482
+ },
3483
+ conditionals: [
3484
+ {
3485
+ type: ConditionalType.SHOW,
3486
+ conditional: field("applicant.dobUnknown").isEqualTo(true)
3487
+ }
3488
+ ]
3489
+ },
3006
3490
  {
3007
3491
  id: "applicant.image",
3008
- type: "FILE",
3492
+ type: FieldType.FILE,
3009
3493
  required: false,
3010
3494
  label: {
3011
3495
  defaultMessage: "Applicant's profile picture",
@@ -3026,6 +3510,27 @@ var TENNIS_CLUB_FORM = defineForm({
3026
3510
  }
3027
3511
  ]
3028
3512
  },
3513
+ {
3514
+ id: "senior-pass",
3515
+ conditional: field("applicant.dob").isBefore().date("1950-01-01"),
3516
+ title: {
3517
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.title",
3518
+ defaultMessage: "Assign senior pass for applicant",
3519
+ description: "This is the title of the section"
3520
+ },
3521
+ fields: [
3522
+ {
3523
+ id: "senior-pass.id",
3524
+ type: FieldType.TEXT,
3525
+ required: true,
3526
+ label: {
3527
+ defaultMessage: "Senior pass ID",
3528
+ description: "This is the label for the field",
3529
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.field.id.label"
3530
+ }
3531
+ }
3532
+ ]
3533
+ },
3029
3534
  {
3030
3535
  id: "recommender",
3031
3536
  title: {
@@ -3047,7 +3552,7 @@ var TENNIS_CLUB_FORM = defineForm({
3047
3552
  },
3048
3553
  {
3049
3554
  id: "recommender.firstname",
3050
- type: "TEXT",
3555
+ type: FieldType.TEXT,
3051
3556
  required: true,
3052
3557
  conditionals: [
3053
3558
  {
@@ -3063,7 +3568,7 @@ var TENNIS_CLUB_FORM = defineForm({
3063
3568
  },
3064
3569
  {
3065
3570
  id: "recommender.surname",
3066
- type: "TEXT",
3571
+ type: FieldType.TEXT,
3067
3572
  required: true,
3068
3573
  conditionals: [
3069
3574
  {
@@ -3079,7 +3584,7 @@ var TENNIS_CLUB_FORM = defineForm({
3079
3584
  },
3080
3585
  {
3081
3586
  id: "recommender.id",
3082
- type: "TEXT",
3587
+ type: FieldType.TEXT,
3083
3588
  required: true,
3084
3589
  conditionals: [
3085
3590
  {
@@ -3187,7 +3692,7 @@ var tennisClubMembershipEvent = defineConfig({
3187
3692
  description: "This is shown as the action name anywhere the user can trigger the action from",
3188
3693
  id: "event.tennis-club-membership.action.declare.label"
3189
3694
  },
3190
- forms: [TENNIS_CLUB_FORM]
3695
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3191
3696
  },
3192
3697
  {
3193
3698
  type: ActionType.VALIDATE,
@@ -3196,7 +3701,7 @@ var tennisClubMembershipEvent = defineConfig({
3196
3701
  description: "This is shown as the action name anywhere the user can trigger the action from",
3197
3702
  id: "event.tennis-club-membership.action.validate.label"
3198
3703
  },
3199
- forms: [TENNIS_CLUB_FORM]
3704
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3200
3705
  },
3201
3706
  {
3202
3707
  type: ActionType.REGISTER,
@@ -3205,7 +3710,7 @@ var tennisClubMembershipEvent = defineConfig({
3205
3710
  description: "This is shown as the action name anywhere the user can trigger the action from",
3206
3711
  id: "event.tennis-club-membership.action.register.label"
3207
3712
  },
3208
- forms: [TENNIS_CLUB_FORM]
3713
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3209
3714
  },
3210
3715
  {
3211
3716
  type: ActionType.REQUEST_CORRECTION,
@@ -3214,10 +3719,10 @@ var tennisClubMembershipEvent = defineConfig({
3214
3719
  description: "This is shown as the action name anywhere the user can trigger the action from",
3215
3720
  id: "event.tennis-club-membership.action.correction.request.label"
3216
3721
  },
3217
- forms: [TENNIS_CLUB_FORM],
3218
3722
  onboardingForm: [
3219
3723
  {
3220
3724
  id: "correction-requester",
3725
+ type: PageTypes.enum.FORM,
3221
3726
  title: {
3222
3727
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3223
3728
  defaultMessage: "Correction requester",
@@ -3281,6 +3786,7 @@ var tennisClubMembershipEvent = defineConfig({
3281
3786
  },
3282
3787
  {
3283
3788
  id: "identity-check",
3789
+ type: PageTypes.enum.FORM,
3284
3790
  title: {
3285
3791
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3286
3792
  defaultMessage: "Verify their identity",
@@ -3323,6 +3829,7 @@ var tennisClubMembershipEvent = defineConfig({
3323
3829
  additionalDetailsForm: [
3324
3830
  {
3325
3831
  id: "correction-request.supporting-documents",
3832
+ type: PageTypes.enum.FORM,
3326
3833
  title: {
3327
3834
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3328
3835
  defaultMessage: "Upload supporting documents",
@@ -3340,7 +3847,7 @@ var tennisClubMembershipEvent = defineConfig({
3340
3847
  },
3341
3848
  {
3342
3849
  id: "correction.supportingDocs",
3343
- type: "FILE",
3850
+ type: FieldType.FILE,
3344
3851
  label: {
3345
3852
  id: "correction.corrector.title",
3346
3853
  defaultMessage: "Upload supporting documents",
@@ -3384,6 +3891,7 @@ var tennisClubMembershipEvent = defineConfig({
3384
3891
  },
3385
3892
  {
3386
3893
  id: "correction-request.additional-details",
3894
+ type: PageTypes.enum.FORM,
3387
3895
  title: {
3388
3896
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3389
3897
  defaultMessage: "Reason for correction",
@@ -3392,7 +3900,7 @@ var tennisClubMembershipEvent = defineConfig({
3392
3900
  fields: [
3393
3901
  {
3394
3902
  id: "correction.request.reason",
3395
- type: "TEXT",
3903
+ type: FieldType.TEXT,
3396
3904
  label: {
3397
3905
  id: "correction.reason.title",
3398
3906
  defaultMessage: "Reason for correction?",
@@ -3405,7 +3913,6 @@ var tennisClubMembershipEvent = defineConfig({
3405
3913
  },
3406
3914
  {
3407
3915
  type: ActionType.APPROVE_CORRECTION,
3408
- forms: [TENNIS_CLUB_FORM],
3409
3916
  label: {
3410
3917
  defaultMessage: "Approve correction",
3411
3918
  description: "This is shown as the action name anywhere the user can trigger the action from",
@@ -3419,7 +3926,7 @@ var tennisClubMembershipEvent = defineConfig({
3419
3926
  defaultMessage: "Print certificate",
3420
3927
  description: "This is shown as the action name anywhere the user can trigger the action from"
3421
3928
  },
3422
- forms: [PRINT_CERTIFICATE_FORM],
3929
+ printForm: PRINT_CERTIFICATE_FORM,
3423
3930
  conditionals: [
3424
3931
  {
3425
3932
  type: "SHOW",
@@ -3466,8 +3973,7 @@ var tennisClubMembershipEvent = defineConfig({
3466
3973
  id: "v2.event.tennis-club-membership.action.archive.label",
3467
3974
  defaultMessage: "Archive",
3468
3975
  description: "This is shown as the action name anywhere the user can trigger the action from"
3469
- },
3470
- forms: [TENNIS_CLUB_FORM]
3976
+ }
3471
3977
  },
3472
3978
  {
3473
3979
  type: ActionType.REJECT,
@@ -3475,8 +3981,7 @@ var tennisClubMembershipEvent = defineConfig({
3475
3981
  id: "v2.event.tennis-club-membership.action.reject.label",
3476
3982
  defaultMessage: "Reject",
3477
3983
  description: "This is shown as the action name anywhere the user can trigger the action from"
3478
- },
3479
- forms: [TENNIS_CLUB_FORM]
3984
+ }
3480
3985
  }
3481
3986
  ],
3482
3987
  advancedSearch: [
@@ -3492,20 +3997,53 @@ var tennisClubMembershipEvent = defineConfig({
3492
3997
  }
3493
3998
  ]
3494
3999
  }
3495
- ]
4000
+ ],
4001
+ declaration: TENNIS_CLUB_DECLARATION_FORM
3496
4002
  });
3497
4003
 
3498
4004
  // ../commons/src/events/test.utils.ts
3499
- function generateActionInput(configuration, action) {
3500
- const fields = findActiveActionFormFields(configuration, action) ?? [];
3501
- const data = fields.reduce(
4005
+ function fieldConfigsToActionPayload(fields) {
4006
+ return fields.reduce(
3502
4007
  (acc, field2, i) => ({
3503
4008
  ...acc,
3504
4009
  [field2.id]: mapFieldTypeToMockValue(field2, i)
3505
4010
  }),
3506
4011
  {}
3507
4012
  );
3508
- return stripHiddenFields(fields, data);
4013
+ }
4014
+ function generateActionDeclarationInput(configuration, action) {
4015
+ const parsed = DeclarationUpdateActions.safeParse(action);
4016
+ if (parsed.success) {
4017
+ const fields = getDeclarationFields(configuration);
4018
+ const declarationConfig = getDeclaration(configuration);
4019
+ const declaration = fieldConfigsToActionPayload(fields);
4020
+ return omitHiddenPaginatedFields(declarationConfig, declaration);
4021
+ }
4022
+ console.warn(`${action} is not a declaration action. Setting data as {}.`);
4023
+ return {};
4024
+ }
4025
+ function generateActionAnnotationInput(configuration, action) {
4026
+ const actionConfig = configuration.actions.find(
4027
+ (ac) => ac.type === action
4028
+ );
4029
+ const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
4030
+ const annotation = fieldConfigsToActionPayload(annotationFields);
4031
+ const visibleVerificationPageIds = findRecordActionPages(
4032
+ configuration,
4033
+ action
4034
+ ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
4035
+ const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
4036
+ (acc, pageId) => ({
4037
+ ...acc,
4038
+ [pageId]: true
4039
+ }),
4040
+ {}
4041
+ );
4042
+ const fieldBasedPayload = omitHiddenFields(annotationFields, annotation);
4043
+ return {
4044
+ ...fieldBasedPayload,
4045
+ ...visiblePageVerificationMap
4046
+ };
3509
4047
  }
3510
4048
  var eventPayloadGenerator = {
3511
4049
  create: (input = {}) => ({
@@ -3517,21 +4055,22 @@ var eventPayloadGenerator = {
3517
4055
  type: input.type ?? "TENNIS_CLUB_MEMBERSHIP",
3518
4056
  id
3519
4057
  }),
3520
- draft: (eventId, input = {}) => (0, import_lodash2.merge)(
4058
+ draft: ({ eventId, actionType }, input = {}) => (0, import_lodash2.merge)(
3521
4059
  {
3522
4060
  id: getUUID(),
3523
4061
  eventId,
3524
4062
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3525
4063
  transactionId: getUUID(),
3526
4064
  action: {
3527
- type: ActionType.REQUEST_CORRECTION,
3528
- data: {
4065
+ type: actionType,
4066
+ status: ActionStatus.Accepted,
4067
+ declaration: {
3529
4068
  "applicant.firstname": "Max",
3530
4069
  "applicant.surname": "McLaren",
3531
4070
  "applicant.dob": "2020-01-02",
3532
4071
  "recommender.none": true
3533
4072
  },
3534
- metadata: {
4073
+ annotation: {
3535
4074
  "correction.requester.relationship": "ANOTHER_AGENT",
3536
4075
  "correction.request.reason": "Child's name was incorrect"
3537
4076
  },
@@ -3546,41 +4085,104 @@ var eventPayloadGenerator = {
3546
4085
  declare: (eventId, input = {}) => ({
3547
4086
  type: ActionType.DECLARE,
3548
4087
  transactionId: input.transactionId ?? getUUID(),
3549
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4088
+ declaration: input.declaration ?? generateActionDeclarationInput(
4089
+ tennisClubMembershipEvent,
4090
+ ActionType.DECLARE
4091
+ ),
4092
+ annotation: input.annotation ?? generateActionAnnotationInput(
4093
+ tennisClubMembershipEvent,
4094
+ ActionType.DECLARE
4095
+ ),
3550
4096
  eventId
3551
4097
  }),
4098
+ /**
4099
+ * Notify allows sending incomplete data. Think it as 'partial declare' for now.
4100
+ */
4101
+ notify: (eventId, input = {}) => {
4102
+ let declaration = input.declaration;
4103
+ if (!declaration) {
4104
+ const partialDeclaration = (0, import_lodash2.omitBy)(
4105
+ generateActionDeclarationInput(
4106
+ tennisClubMembershipEvent,
4107
+ ActionType.DECLARE
4108
+ ),
4109
+ import_lodash2.isString
4110
+ );
4111
+ declaration = partialDeclaration;
4112
+ }
4113
+ return {
4114
+ type: ActionType.NOTIFY,
4115
+ transactionId: input.transactionId ?? getUUID(),
4116
+ declaration,
4117
+ eventId
4118
+ };
4119
+ },
3552
4120
  validate: (eventId, input = {}) => ({
3553
4121
  type: ActionType.VALIDATE,
3554
4122
  transactionId: input.transactionId ?? getUUID(),
3555
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4123
+ declaration: input.declaration ?? generateActionDeclarationInput(
4124
+ tennisClubMembershipEvent,
4125
+ ActionType.VALIDATE
4126
+ ),
4127
+ annotation: input.annotation ?? generateActionAnnotationInput(
4128
+ tennisClubMembershipEvent,
4129
+ ActionType.VALIDATE
4130
+ ),
3556
4131
  duplicates: [],
3557
4132
  eventId
3558
4133
  }),
4134
+ assign: (eventId, input = {}) => ({
4135
+ type: ActionType.ASSIGN,
4136
+ transactionId: input.transactionId ?? getUUID(),
4137
+ declaration: {},
4138
+ assignedTo: input.assignedTo ?? getUUID(),
4139
+ eventId
4140
+ }),
4141
+ unassign: (eventId, input = {}) => ({
4142
+ type: ActionType.UNASSIGN,
4143
+ transactionId: input.transactionId ?? getUUID(),
4144
+ declaration: {},
4145
+ assignedTo: null,
4146
+ eventId
4147
+ }),
3559
4148
  archive: (eventId, input = {}, isDuplicate) => ({
3560
4149
  type: ActionType.ARCHIVE,
3561
4150
  transactionId: input.transactionId ?? getUUID(),
3562
- data: input.data ?? {},
3563
- metadata: { isDuplicate: isDuplicate ?? false },
4151
+ declaration: {},
4152
+ // @TODO: Check whether generator is needed?
4153
+ annotation: { isDuplicate: isDuplicate ?? false },
3564
4154
  duplicates: [],
3565
4155
  eventId
3566
4156
  }),
3567
4157
  reject: (eventId, input = {}) => ({
3568
4158
  type: ActionType.REJECT,
3569
4159
  transactionId: input.transactionId ?? getUUID(),
3570
- data: input.data ?? {},
4160
+ declaration: {},
4161
+ annotation: input.annotation ?? generateActionAnnotationInput(
4162
+ tennisClubMembershipEvent,
4163
+ ActionType.REJECT
4164
+ ),
3571
4165
  duplicates: [],
3572
4166
  eventId
3573
4167
  }),
3574
4168
  register: (eventId, input = {}) => ({
3575
4169
  type: ActionType.REGISTER,
3576
4170
  transactionId: input.transactionId ?? getUUID(),
3577
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4171
+ declaration: input.declaration ?? generateActionDeclarationInput(
4172
+ tennisClubMembershipEvent,
4173
+ ActionType.REGISTER
4174
+ ),
4175
+ annotation: input.annotation ?? generateActionAnnotationInput(
4176
+ tennisClubMembershipEvent,
4177
+ ActionType.REGISTER
4178
+ ),
3578
4179
  eventId
3579
4180
  }),
3580
4181
  printCertificate: (eventId, input = {}) => ({
3581
4182
  type: ActionType.PRINT_CERTIFICATE,
3582
4183
  transactionId: input.transactionId ?? getUUID(),
3583
- data: input.data ?? generateActionInput(
4184
+ declaration: {},
4185
+ annotation: input.annotation ?? generateActionAnnotationInput(
3584
4186
  tennisClubMembershipEvent,
3585
4187
  ActionType.PRINT_CERTIFICATE
3586
4188
  ),
@@ -3590,17 +4192,21 @@ var eventPayloadGenerator = {
3590
4192
  request: (eventId, input = {}) => ({
3591
4193
  type: ActionType.REQUEST_CORRECTION,
3592
4194
  transactionId: input.transactionId ?? getUUID(),
3593
- data: input.data ?? generateActionInput(
4195
+ declaration: input.declaration ?? generateActionDeclarationInput(
4196
+ tennisClubMembershipEvent,
4197
+ ActionType.REQUEST_CORRECTION
4198
+ ),
4199
+ annotation: input.annotation ?? generateActionAnnotationInput(
3594
4200
  tennisClubMembershipEvent,
3595
4201
  ActionType.REQUEST_CORRECTION
3596
4202
  ),
3597
- metadata: {},
3598
4203
  eventId
3599
4204
  }),
3600
4205
  approve: (eventId, requestId, input = {}) => ({
3601
4206
  type: ActionType.APPROVE_CORRECTION,
3602
4207
  transactionId: input.transactionId ?? getUUID(),
3603
- data: input.data ?? generateActionInput(
4208
+ declaration: {},
4209
+ annotation: input.annotation ?? generateActionAnnotationInput(
3604
4210
  tennisClubMembershipEvent,
3605
4211
  ActionType.APPROVE_CORRECTION
3606
4212
  ),
@@ -3610,7 +4216,8 @@ var eventPayloadGenerator = {
3610
4216
  reject: (eventId, requestId, input = {}) => ({
3611
4217
  type: ActionType.REJECT_CORRECTION,
3612
4218
  transactionId: input.transactionId ?? getUUID(),
3613
- data: input.data ?? generateActionInput(
4219
+ declaration: {},
4220
+ annotation: input.annotation ?? generateActionAnnotationInput(
3614
4221
  tennisClubMembershipEvent,
3615
4222
  ActionType.REJECT_CORRECTION
3616
4223
  ),
@@ -3626,19 +4233,26 @@ function generateActionDocument({
3626
4233
  defaults = {}
3627
4234
  }) {
3628
4235
  const actionBase = {
4236
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4237
+ // @TODO: This should be fixed in the future.
3629
4238
  createdAt: new Date(Date.now() - 500).toISOString(),
3630
4239
  createdBy: getUUID(),
3631
4240
  id: getUUID(),
3632
4241
  createdAtLocation: "TODO",
3633
- data: generateActionInput(configuration, action),
3634
- metadata: {},
3635
- ...defaults
4242
+ declaration: generateActionDeclarationInput(configuration, action),
4243
+ annotation: {},
4244
+ ...defaults,
4245
+ status: ActionStatus.Accepted
3636
4246
  };
3637
4247
  switch (action) {
4248
+ case ActionType.READ:
4249
+ return { ...actionBase, type: action };
4250
+ case ActionType.MARKED_AS_DUPLICATE:
4251
+ return { ...actionBase, type: action };
3638
4252
  case ActionType.DECLARE:
3639
4253
  return { ...actionBase, type: action };
3640
4254
  case ActionType.UNASSIGN:
3641
- return { ...actionBase, type: action };
4255
+ return { ...actionBase, type: action, assignedTo: null };
3642
4256
  case ActionType.ASSIGN:
3643
4257
  return { ...actionBase, assignedTo: getUUID(), type: action };
3644
4258
  case ActionType.VALIDATE:
@@ -3659,14 +4273,13 @@ function generateActionDocument({
3659
4273
  return { ...actionBase, requestId: getUUID(), type: action };
3660
4274
  case ActionType.REJECT_CORRECTION:
3661
4275
  return { ...actionBase, requestId: getUUID(), type: action };
3662
- case ActionType.CUSTOM:
3663
- return { ...actionBase, type: action };
3664
4276
  case ActionType.REGISTER:
3665
4277
  return {
3666
4278
  ...actionBase,
3667
- type: action,
3668
- identifiers: { trackingId: getUUID(), registrationNumber: getUUID() }
4279
+ type: action
3669
4280
  };
4281
+ case ActionType.DELETE:
4282
+ case ActionType.DETECT_DUPLICATE:
3670
4283
  default:
3671
4284
  throw new Error(`Unsupported action type: ${action}`);
3672
4285
  }
@@ -3681,12 +4294,17 @@ function generateEventDocument({
3681
4294
  actions: actions.map(
3682
4295
  (action) => generateActionDocument({ configuration, action })
3683
4296
  ),
4297
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4298
+ // @TODO: This should be fixed in the future.
3684
4299
  createdAt: new Date(Date.now() - 1e3).toISOString(),
3685
4300
  id: getUUID(),
3686
- updatedAt: new Date(Date.now() - 1e3).toISOString()
4301
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4302
+ // @TODO: This should be fixed in the future.
4303
+ updatedAt: new Date(Date.now() - 1e3).toISOString(),
4304
+ updatedAtLocation: "TODO"
3687
4305
  };
3688
4306
  }
3689
- function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, data = {}) {
4307
+ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
3690
4308
  const action = generateActionDocument({
3691
4309
  configuration: tennisClubMembershipEvent,
3692
4310
  action: actionType
@@ -3696,9 +4314,9 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, da
3696
4314
  transactionId: getUUID(),
3697
4315
  action: {
3698
4316
  ...action,
3699
- data: {
3700
- ...action.data,
3701
- ...data
4317
+ declaration: {
4318
+ ...action.declaration,
4319
+ ...declaration
3702
4320
  }
3703
4321
  },
3704
4322
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3712,10 +4330,11 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3712
4330
  createdAt: overrides.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3713
4331
  createdBy: overrides.createdBy ?? getUUID(),
3714
4332
  createdAtLocation: overrides.createdAtLocation ?? getUUID(),
4333
+ updatedAtLocation: overrides.updatedAtLocation ?? getUUID(),
3715
4334
  modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3716
4335
  assignedTo: overrides.assignedTo ?? null,
3717
4336
  updatedBy: overrides.updatedBy ?? getUUID(),
3718
- data: overrides.data ?? {
4337
+ declaration: overrides.declaration ?? {
3719
4338
  "recommender.none": true,
3720
4339
  "applicant.firstname": "Danny",
3721
4340
  "applicant.surname": "Doe",
@@ -3723,6 +4342,11 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3723
4342
  },
3724
4343
  trackingId: overrides.trackingId ?? "M3F8YQ"
3725
4344
  });
4345
+ var generateTranslationConfig = (message) => ({
4346
+ defaultMessage: message,
4347
+ description: "Description for ${message}",
4348
+ id: message
4349
+ });
3726
4350
 
3727
4351
  // ../commons/src/events/TemplateConfig.ts
3728
4352
  function isTemplateVariable(value) {
@@ -3741,7 +4365,9 @@ function isFieldValueWithoutTemplates(value) {
3741
4365
  return true;
3742
4366
  }
3743
4367
  function isFieldConfigDefaultValue(value) {
3744
- if (!value) return false;
4368
+ if (!value) {
4369
+ return false;
4370
+ }
3745
4371
  if (isFieldValue(value)) {
3746
4372
  return true;
3747
4373
  }
@@ -3753,3 +4379,189 @@ function isFieldConfigDefaultValue(value) {
3753
4379
  }
3754
4380
  return false;
3755
4381
  }
4382
+
4383
+ // ../commons/src/events/scopes.ts
4384
+ var import_lodash3 = require("lodash");
4385
+
4386
+ // ../commons/src/scopes.ts
4387
+ var SCOPES = {
4388
+ // TODO v1.8 legacy scopes
4389
+ NATLSYSADMIN: "natlsysadmin",
4390
+ BYPASSRATELIMIT: "bypassratelimit",
4391
+ DECLARE: "declare",
4392
+ REGISTER: "register",
4393
+ VALIDATE: "validate",
4394
+ DEMO: "demo",
4395
+ CERTIFY: "certify",
4396
+ PERFORMANCE: "performance",
4397
+ SYSADMIN: "sysadmin",
4398
+ TEAMS: "teams",
4399
+ CONFIG: "config",
4400
+ // systems / integrations
4401
+ WEBHOOK: "webhook",
4402
+ NATIONALID: "nationalId",
4403
+ NOTIFICATION_API: "notification-api",
4404
+ RECORDSEARCH: "recordsearch",
4405
+ /**
4406
+ * @TODO This is a temporary scope to be used for V2 Events custom events declaration
4407
+ */
4408
+ RECORD_DECLARE: "record.declare-birth",
4409
+ // declare
4410
+ RECORD_DECLARE_BIRTH: "record.declare-birth",
4411
+ RECORD_DECLARE_BIRTH_MY_JURISDICTION: "record.declare-birth:my-jurisdiction",
4412
+ RECORD_DECLARE_DEATH: "record.declare-death",
4413
+ RECORD_DECLARE_DEATH_MY_JURISDICTION: "record.declare-death:my-jurisdiction",
4414
+ RECORD_DECLARE_MARRIAGE: "record.declare-marriage",
4415
+ RECORD_DECLARE_MARRIAGE_MY_JURISDICTION: "record.declare-marriage:my-jurisdiction",
4416
+ RECORD_SUBMIT_INCOMPLETE: "record.declaration-submit-incomplete",
4417
+ RECORD_SUBMIT_FOR_REVIEW: "record.declaration-submit-for-review",
4418
+ RECORD_UNASSIGN_OTHERS: "record.unassign-others",
4419
+ // validate
4420
+ RECORD_SUBMIT_FOR_APPROVAL: "record.declaration-submit-for-approval",
4421
+ RECORD_SUBMIT_FOR_UPDATES: "record.declaration-submit-for-updates",
4422
+ RECORD_DECLARATION_EDIT: "record.declaration-edit",
4423
+ RECORD_REVIEW_DUPLICATES: "record.review-duplicates",
4424
+ RECORD_DECLARATION_ARCHIVE: "record.declaration-archive",
4425
+ RECORD_DECLARATION_REINSTATE: "record.declaration-reinstate",
4426
+ // register
4427
+ RECORD_REGISTER: "record.register",
4428
+ // certify
4429
+ RECORD_EXPORT_RECORDS: "record.export-records",
4430
+ RECORD_DECLARATION_PRINT: "record.declaration-print",
4431
+ RECORD_PRINT_RECORDS_SUPPORTING_DOCUMENTS: "record.declaration-print-supporting-documents",
4432
+ RECORD_REGISTRATION_PRINT: "record.registration-print",
4433
+ // v1.8
4434
+ /**
4435
+ * This scope is used to **print and **issue certified copies of a record
4436
+ * after it has been registered. Previously Registrars had this permission.
4437
+ */
4438
+ RECORD_PRINT_ISSUE_CERTIFIED_COPIES: "record.registration-print&issue-certified-copies",
4439
+ RECORD_PRINT_CERTIFIED_COPIES: "record.registration-print-certified-copies",
4440
+ // v1.8
4441
+ RECORD_BULK_PRINT_CERTIFIED_COPIES: "record.registration-bulk-print-certified-copies",
4442
+ // v1.8
4443
+ RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES: "record.registration-verify-certified-copies",
4444
+ // v1.8
4445
+ // correct
4446
+ RECORD_REGISTRATION_REQUEST_CORRECTION: "record.registration-request-correction",
4447
+ RECORD_REGISTRATION_CORRECT: "record.registration-correct",
4448
+ RECORD_REGISTRATION_REQUEST_REVOCATION: "record.registration-request-revocation",
4449
+ // v1.8
4450
+ RECORD_REGISTRATION_REVOKE: "record.registration-revoke",
4451
+ // v1.8
4452
+ RECORD_REGISTRATION_REQUEST_REINSTATEMENT: "record.registration-request-reinstatement",
4453
+ // v1.8
4454
+ RECORD_REGISTRATION_REINSTATE: "record.registration-reinstate",
4455
+ // v1.8
4456
+ RECORD_CONFIRM_REGISTRATION: "record.confirm-registration",
4457
+ RECORD_REJECT_REGISTRATION: "record.reject-registration",
4458
+ // search
4459
+ SEARCH_BIRTH_MY_JURISDICTION: "search.birth:my-jurisdiction",
4460
+ SEARCH_BIRTH: "search.birth",
4461
+ SEARCH_DEATH_MY_JURISDICTION: "search.death:my-jurisdiction",
4462
+ SEARCH_DEATH: "search.death",
4463
+ SEARCH_MARRIAGE_MY_JURISDICTION: "search.marriage:my-jurisdiction",
4464
+ SEARCH_MARRIAGE: "search.marriage",
4465
+ // audit v1.8
4466
+ RECORD_READ: "record.read",
4467
+ RECORD_READ_AUDIT: "record.read-audit",
4468
+ RECORD_READ_COMMENTS: "record.read-comments",
4469
+ RECORD_CREATE_COMMENTS: "record.create-comments",
4470
+ // profile
4471
+ PROFILE_UPDATE: "profile.update",
4472
+ //v1.8
4473
+ PROFILE_ELECTRONIC_SIGNATURE: "profile.electronic-signature",
4474
+ // performance
4475
+ PERFORMANCE_READ: "performance.read",
4476
+ PERFORMANCE_READ_DASHBOARDS: "performance.read-dashboards",
4477
+ PERFORMANCE_EXPORT_VITAL_STATISTICS: "performance.vital-statistics-export",
4478
+ // organisation
4479
+ ORGANISATION_READ_LOCATIONS: "organisation.read-locations:all",
4480
+ ORGANISATION_READ_LOCATIONS_MY_OFFICE: "organisation.read-locations:my-office",
4481
+ ORGANISATION_READ_LOCATIONS_MY_JURISDICTION: "organisation.read-locations:my-jurisdiction",
4482
+ // user
4483
+ USER_READ: "user.read:all",
4484
+ USER_READ_MY_OFFICE: "user.read:my-office",
4485
+ USER_READ_MY_JURISDICTION: "user.read:my-jurisdiction",
4486
+ USER_READ_ONLY_MY_AUDIT: "user.read:only-my-audit",
4487
+ //v1.8
4488
+ USER_CREATE: "user.create:all",
4489
+ USER_CREATE_MY_JURISDICTION: "user.create:my-jurisdiction",
4490
+ USER_UPDATE: "user.update:all",
4491
+ USER_UPDATE_MY_JURISDICTION: "user.update:my-jurisdiction",
4492
+ // config
4493
+ CONFIG_UPDATE_ALL: "config.update:all",
4494
+ // data seeding
4495
+ USER_DATA_SEEDING: "user.data-seeding"
4496
+ };
4497
+ var scopes = Object.values(SCOPES);
4498
+
4499
+ // ../commons/src/events/scopes.ts
4500
+ function hasAnyOfScopes(a, b) {
4501
+ return (0, import_lodash3.intersection)(a, b).length > 0;
4502
+ }
4503
+ var CONFIG_GET_ALLOWED_SCOPES = [
4504
+ SCOPES.RECORD_DECLARE,
4505
+ SCOPES.RECORD_READ,
4506
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4507
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
4508
+ SCOPES.RECORD_REGISTER,
4509
+ SCOPES.RECORD_EXPORT_RECORDS,
4510
+ SCOPES.CONFIG,
4511
+ SCOPES.CONFIG_UPDATE_ALL
4512
+ ];
4513
+ var ACTION_ALLOWED_SCOPES = {
4514
+ [ActionType.READ]: [
4515
+ SCOPES.RECORD_DECLARE,
4516
+ SCOPES.RECORD_READ,
4517
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4518
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
4519
+ SCOPES.RECORD_REGISTER,
4520
+ SCOPES.RECORD_EXPORT_RECORDS
4521
+ ],
4522
+ [ActionType.CREATE]: [
4523
+ SCOPES.RECORD_DECLARE,
4524
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4525
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW
4526
+ ],
4527
+ [ActionType.NOTIFY]: [SCOPES.RECORD_SUBMIT_INCOMPLETE],
4528
+ [ActionType.DECLARE]: [
4529
+ SCOPES.RECORD_DECLARE,
4530
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
4531
+ SCOPES.RECORD_REGISTER
4532
+ ],
4533
+ [ActionType.DELETE]: [SCOPES.RECORD_DECLARE],
4534
+ [ActionType.VALIDATE]: [
4535
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
4536
+ SCOPES.RECORD_REGISTER
4537
+ ],
4538
+ [ActionType.REGISTER]: [SCOPES.RECORD_REGISTER],
4539
+ [ActionType.PRINT_CERTIFICATE]: [SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES],
4540
+ [ActionType.REQUEST_CORRECTION]: [
4541
+ SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION
4542
+ ],
4543
+ [ActionType.REJECT_CORRECTION]: [SCOPES.RECORD_REGISTRATION_CORRECT],
4544
+ [ActionType.APPROVE_CORRECTION]: [SCOPES.RECORD_REGISTRATION_CORRECT],
4545
+ [ActionType.MARKED_AS_DUPLICATE]: [SCOPES.RECORD_DECLARATION_ARCHIVE],
4546
+ [ActionType.ARCHIVE]: [SCOPES.RECORD_DECLARATION_ARCHIVE],
4547
+ [ActionType.REJECT]: [SCOPES.RECORD_SUBMIT_FOR_UPDATES],
4548
+ [ActionType.ASSIGN]: null,
4549
+ [ActionType.UNASSIGN]: null,
4550
+ [ActionType.DETECT_DUPLICATE]: []
4551
+ };
4552
+ function filterUnallowedActions(actions, userScopes) {
4553
+ const allowedActions = actions.filter((action) => {
4554
+ const requiredScopes = ACTION_ALLOWED_SCOPES[action];
4555
+ if (requiredScopes === null) {
4556
+ return true;
4557
+ }
4558
+ return hasAnyOfScopes(userScopes, requiredScopes);
4559
+ });
4560
+ const hasOtherAllowedActions = allowedActions.some(
4561
+ (action) => action !== ActionType.READ && action !== ActionType.ASSIGN && action !== ActionType.UNASSIGN
4562
+ );
4563
+ if (hasOtherAllowedActions) {
4564
+ return allowedActions;
4565
+ }
4566
+ return [ActionType.READ];
4567
+ }