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

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 (37) hide show
  1. package/dist/commons/api/router.d.ts +7703 -4200
  2. package/dist/commons/conditionals/conditionals.d.ts +9 -6
  3. package/dist/commons/conditionals/validate.d.ts +4 -6
  4. package/dist/commons/events/ActionConfig.d.ts +90025 -1680
  5. package/dist/commons/events/ActionDocument.d.ts +544 -207
  6. package/dist/commons/events/ActionInput.d.ts +338 -240
  7. package/dist/commons/events/ActionType.d.ts +2 -0
  8. package/dist/commons/events/AdvancedSearchConfig.d.ts +369 -25
  9. package/dist/commons/events/CompositeFieldValue.d.ts +3 -0
  10. package/dist/commons/events/Draft.d.ts +36 -20
  11. package/dist/commons/events/EventConfig.d.ts +42812 -1344
  12. package/dist/commons/events/EventDocument.d.ts +339 -153
  13. package/dist/commons/events/EventIndex.d.ts +1346 -13
  14. package/dist/commons/events/EventInput.d.ts +13 -0
  15. package/dist/commons/events/EventMetadata.d.ts +273 -11
  16. package/dist/commons/events/FieldConfig.d.ts +3733 -724
  17. package/dist/commons/events/FieldType.d.ts +3 -3
  18. package/dist/commons/events/FieldTypeMapping.d.ts +11 -4
  19. package/dist/commons/events/FieldValue.d.ts +7 -4
  20. package/dist/commons/events/FormConfig.d.ts +40417 -439
  21. package/dist/commons/events/PageConfig.d.ts +10077 -203
  22. package/dist/commons/events/SummaryConfig.d.ts +95 -39
  23. package/dist/commons/events/User.d.ts +5 -0
  24. package/dist/commons/events/WorkqueueConfig.d.ts +1135 -19
  25. package/dist/commons/events/defineConfig.d.ts +6971 -40
  26. package/dist/commons/events/event.d.ts +27 -0
  27. package/dist/commons/events/field.d.ts +68 -0
  28. package/dist/commons/events/index.d.ts +3 -0
  29. package/dist/commons/events/scopes.d.ts +26 -0
  30. package/dist/commons/events/test.utils.d.ts +7 -44
  31. package/dist/commons/events/utils.d.ts +3553 -68
  32. package/dist/commons/events/utils.test.d.ts +2 -0
  33. package/dist/conditionals/index.js +36 -33
  34. package/dist/events/index.js +1690 -976
  35. package/dist/scopes/index.d.ts +70 -1
  36. package/dist/scopes/index.js +130 -0
  37. package/package.json +3 -2
@@ -30,11 +30,13 @@ 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,
33
34
  Action: () => Action,
34
35
  ActionBase: () => ActionBase,
35
36
  ActionConditional: () => ActionConditional,
36
37
  ActionConfig: () => ActionConfig,
37
38
  ActionConfigBase: () => ActionConfigBase,
39
+ ActionCreationMetadata: () => ActionCreationMetadata,
38
40
  ActionDocument: () => ActionDocument,
39
41
  ActionFormConfig: () => ActionFormConfig,
40
42
  ActionInput: () => ActionInput,
@@ -52,6 +54,8 @@ __export(events_exports, {
52
54
  AssignActionInput: () => AssignActionInput,
53
55
  AsyncRejectActionDocument: () => AsyncRejectActionDocument,
54
56
  BaseActionInput: () => BaseActionInput,
57
+ CONFIG_GET_ALLOWED_SCOPES: () => CONFIG_GET_ALLOWED_SCOPES,
58
+ CONFIG_SEARCH_ALLOWED_SCOPES: () => CONFIG_SEARCH_ALLOWED_SCOPES,
55
59
  CertificateConfig: () => CertificateConfig,
56
60
  CertificateTemplateConfig: () => CertificateTemplateConfig,
57
61
  CheckboxFieldValue: () => CheckboxFieldValue,
@@ -59,9 +63,13 @@ __export(events_exports, {
59
63
  Conditional: () => Conditional,
60
64
  ConditionalType: () => ConditionalType,
61
65
  ConfirmableActions: () => ConfirmableActions,
66
+ CustomFlags: () => CustomFlags,
67
+ DEFAULT_DATE_OF_EVENT_PROPERTY: () => DEFAULT_DATE_OF_EVENT_PROPERTY,
62
68
  DataEntry: () => DataEntry,
63
69
  DataFieldValue: () => DataFieldValue,
70
+ DateRangeFieldValue: () => DateRangeFieldValue,
64
71
  DateValue: () => DateValue,
72
+ DatetimeValue: () => DatetimeValue,
65
73
  DeclarationActionConfig: () => DeclarationActionConfig,
66
74
  DeclarationActions: () => DeclarationActions,
67
75
  DeclarationFormConfig: () => DeclarationFormConfig,
@@ -69,6 +77,7 @@ __export(events_exports, {
69
77
  DeclarationUpdateActions: () => DeclarationUpdateActions,
70
78
  DeclareActionInput: () => DeclareActionInput,
71
79
  DeduplicationConfig: () => DeduplicationConfig,
80
+ DeleteActionInput: () => DeleteActionInput,
72
81
  DisplayOnReviewConditional: () => DisplayOnReviewConditional,
73
82
  Draft: () => Draft,
74
83
  DraftInput: () => DraftInput,
@@ -77,20 +86,27 @@ __export(events_exports, {
77
86
  EnableConditional: () => EnableConditional,
78
87
  EventConfig: () => EventConfig,
79
88
  EventDocument: () => EventDocument,
89
+ EventFieldConfigSchema: () => EventFieldConfigSchema,
90
+ EventFieldId: () => EventFieldId,
80
91
  EventIndex: () => EventIndex,
81
92
  EventInput: () => EventInput,
82
93
  EventMetadata: () => EventMetadata,
94
+ EventMetadataKeys: () => EventMetadataKeys,
95
+ EventMetadataParameter: () => EventMetadataParameter,
83
96
  EventSearchIndex: () => EventSearchIndex,
97
+ EventState: () => EventState,
84
98
  EventStatus: () => EventStatus,
85
99
  EventStatuses: () => EventStatuses,
86
100
  FieldConditional: () => FieldConditional,
87
101
  FieldConfig: () => FieldConfig,
102
+ FieldConfigSchema: () => FieldConfigSchema,
88
103
  FieldType: () => FieldType,
89
104
  FieldUpdateValue: () => FieldUpdateValue,
90
105
  FieldValue: () => FieldValue,
91
106
  FileFieldValue: () => FileFieldValue,
92
107
  FileFieldValueWithOption: () => FileFieldValueWithOption,
93
108
  FileFieldWithOptionValue: () => FileFieldWithOptionValue,
109
+ Flag: () => Flag,
94
110
  FormConfig: () => FormConfig,
95
111
  FormPageConfig: () => FormPageConfig,
96
112
  GenericAddressUpdateValue: () => GenericAddressUpdateValue,
@@ -98,23 +114,29 @@ __export(events_exports, {
98
114
  GeographicalArea: () => GeographicalArea,
99
115
  ImageMimeType: () => ImageMimeType,
100
116
  LanguageConfig: () => LanguageConfig,
117
+ LegalStatuses: () => LegalStatuses,
101
118
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
102
119
  MimeType: () => MimeType,
120
+ NonEmptyTextValue: () => NonEmptyTextValue,
103
121
  NotifyActionInput: () => NotifyActionInput,
104
122
  NumberFieldValue: () => NumberFieldValue,
105
123
  PageConfig: () => PageConfig,
106
124
  PageTypes: () => PageTypes,
107
125
  PrintCertificateActionInput: () => PrintCertificateActionInput,
126
+ QueryInput: () => QueryInput,
127
+ QueryType: () => QueryType,
108
128
  ReadActionInput: () => ReadActionInput,
109
129
  RegisterAction: () => RegisterAction,
110
130
  RegisterActionInput: () => RegisterActionInput,
131
+ RegistrationCreationMetadata: () => RegistrationCreationMetadata,
111
132
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
112
133
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
113
134
  RequestCorrectionActionInput: () => RequestCorrectionActionInput,
114
- RequiredTextValue: () => RequiredTextValue,
115
135
  ResolvedUser: () => ResolvedUser,
116
136
  RuralAddressUpdateValue: () => RuralAddressUpdateValue,
117
137
  RuralAddressValue: () => RuralAddressValue,
138
+ SearchField: () => SearchField,
139
+ SelectOption: () => SelectOption,
118
140
  ShowConditional: () => ShowConditional,
119
141
  SummaryConfig: () => SummaryConfig,
120
142
  TextValue: () => TextValue,
@@ -126,12 +148,16 @@ __export(events_exports, {
126
148
  VerificationActionConfig: () => VerificationActionConfig,
127
149
  VerificationPageConfig: () => VerificationPageConfig,
128
150
  WorkqueueConfig: () => WorkqueueConfig,
151
+ ZodDate: () => ZodDate,
129
152
  alwaysTrue: () => alwaysTrue,
130
153
  and: () => and,
131
154
  annotationActions: () => annotationActions,
132
155
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
156
+ areConditionsMet: () => areConditionsMet,
133
157
  compositeFieldTypes: () => compositeFieldTypes,
134
158
  createEmptyDraft: () => createEmptyDraft,
159
+ createEventConditionals: () => createEventConditionals,
160
+ createFieldConditionals: () => createFieldConditionals,
135
161
  createValidationSchema: () => createValidationSchema,
136
162
  deepDropNulls: () => deepDropNulls,
137
163
  deepMerge: () => deepMerge,
@@ -142,6 +168,7 @@ __export(events_exports, {
142
168
  defineFormConditional: () => defineFormConditional,
143
169
  defineFormPage: () => defineFormPage,
144
170
  definePage: () => definePage,
171
+ defineWorkqueue: () => defineWorkqueue,
145
172
  errorMessages: () => errorMessages,
146
173
  event: () => event,
147
174
  eventMetadataLabelMap: () => eventMetadataLabelMap,
@@ -150,8 +177,10 @@ __export(events_exports, {
150
177
  eventStatuses: () => eventStatuses,
151
178
  field: () => field,
152
179
  fieldTypes: () => fieldTypes,
180
+ filterUnallowedActions: () => filterUnallowedActions,
153
181
  findActiveDrafts: () => findActiveDrafts,
154
182
  findAllFields: () => findAllFields,
183
+ findLastAssignmentAction: () => findLastAssignmentAction,
155
184
  findRecordActionPages: () => findRecordActionPages,
156
185
  generateActionAnnotationInput: () => generateActionAnnotationInput,
157
186
  generateActionDeclarationInput: () => generateActionDeclarationInput,
@@ -165,21 +194,26 @@ __export(events_exports, {
165
194
  getActionAnnotationFields: () => getActionAnnotationFields,
166
195
  getActionReview: () => getActionReview,
167
196
  getActionReviewFields: () => getActionReviewFields,
168
- getAllAnnotationFields: () => getAllAnnotationFields,
197
+ getActionVerificationPageIds: () => getActionVerificationPageIds,
169
198
  getAnnotationFromDrafts: () => getAnnotationFromDrafts,
199
+ getAssignedUserFromActions: () => getAssignedUserFromActions,
170
200
  getCurrentEventState: () => getCurrentEventState,
171
201
  getCurrentEventStateWithDrafts: () => getCurrentEventStateWithDrafts,
172
202
  getDeclaration: () => getDeclaration,
173
203
  getDeclarationFields: () => getDeclarationFields,
174
204
  getDeclarationPages: () => getDeclarationPages,
175
- getFieldValidationErrors: () => getFieldValidationErrors,
205
+ getMixedPath: () => getMixedPath,
206
+ getVisibleVerificationPageIds: () => getVisibleVerificationPageIds,
207
+ hasAnyOfScopes: () => hasAnyOfScopes,
176
208
  isAddressFieldType: () => isAddressFieldType,
177
209
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
178
210
  isBulletListFieldType: () => isBulletListFieldType,
179
211
  isCheckboxFieldType: () => isCheckboxFieldType,
212
+ isConditionMet: () => isConditionMet,
180
213
  isCountryFieldType: () => isCountryFieldType,
181
214
  isDataFieldType: () => isDataFieldType,
182
215
  isDateFieldType: () => isDateFieldType,
216
+ isDateRangeFieldType: () => isDateRangeFieldType,
183
217
  isDividerFieldType: () => isDividerFieldType,
184
218
  isEmailFieldType: () => isEmailFieldType,
185
219
  isFacilityFieldType: () => isFacilityFieldType,
@@ -205,18 +239,21 @@ __export(events_exports, {
205
239
  isTextFieldType: () => isTextFieldType,
206
240
  isUndeclaredDraft: () => isUndeclaredDraft,
207
241
  isVerificationPage: () => isVerificationPage,
242
+ isWriteAction: () => isWriteAction,
208
243
  mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
209
244
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
210
245
  mapFieldTypeToZod: () => mapFieldTypeToZod,
211
246
  never: () => never,
212
247
  not: () => not,
248
+ omitHiddenAnnotationFields: () => omitHiddenAnnotationFields,
213
249
  omitHiddenFields: () => omitHiddenFields,
214
250
  omitHiddenPaginatedFields: () => omitHiddenPaginatedFields,
215
251
  or: () => or,
252
+ runFieldValidations: () => runFieldValidations,
216
253
  user: () => user,
217
254
  validate: () => validate,
218
255
  validateFieldInput: () => validateFieldInput,
219
- validateWorkqueueConfig: () => validateWorkqueueConfig
256
+ writeActions: () => writeActions
220
257
  });
221
258
  module.exports = __toCommonJS(events_exports);
222
259
 
@@ -292,12 +329,12 @@ var FieldType = {
292
329
  TEXTAREA: "TEXTAREA",
293
330
  EMAIL: "EMAIL",
294
331
  DATE: "DATE",
332
+ DATE_RANGE: "DATE_RANGE",
295
333
  PARAGRAPH: "PARAGRAPH",
296
334
  PAGE_HEADER: "PAGE_HEADER",
297
335
  RADIO_GROUP: "RADIO_GROUP",
298
336
  FILE: "FILE",
299
337
  FILE_WITH_OPTIONS: "FILE_WITH_OPTIONS",
300
- HIDDEN: "HIDDEN",
301
338
  BULLET_LIST: "BULLET_LIST",
302
339
  CHECKBOX: "CHECKBOX",
303
340
  SELECT: "SELECT",
@@ -312,6 +349,7 @@ var FieldType = {
312
349
  };
313
350
  var fieldTypes = Object.values(FieldType);
314
351
  var compositeFieldTypes = [
352
+ FieldType.DATE_RANGE,
315
353
  FieldType.ADDRESS,
316
354
  FieldType.FILE_WITH_OPTIONS,
317
355
  FieldType.FILE
@@ -402,8 +440,10 @@ var FileFieldWithOptionValue = import_zod3.z.array(FileFieldValueWithOption);
402
440
 
403
441
  // ../commons/src/events/FieldValue.ts
404
442
  var TextValue = import_zod4.z.string();
405
- var RequiredTextValue = TextValue.min(1);
443
+ var NonEmptyTextValue = TextValue.min(1);
406
444
  var DateValue = import_zod4.z.string().date().describe("Date in the format YYYY-MM-DD");
445
+ var DatetimeValue = import_zod4.z.string().datetime();
446
+ var DateRangeFieldValue = DateValue.or(import_zod4.z.tuple([DateValue, DateValue]));
407
447
  var EmailValue = import_zod4.z.string().email();
408
448
  var CheckboxFieldValue = import_zod4.z.boolean();
409
449
  var NumberFieldValue = import_zod4.z.number();
@@ -411,6 +451,7 @@ var DataFieldValue = import_zod4.z.undefined();
411
451
  var FieldValue = import_zod4.z.union([
412
452
  TextValue,
413
453
  DateValue,
454
+ DateRangeFieldValue,
414
455
  CheckboxFieldValue,
415
456
  NumberFieldValue,
416
457
  FileFieldValue,
@@ -423,6 +464,7 @@ var FieldValue = import_zod4.z.union([
423
464
  var FieldUpdateValue = import_zod4.z.union([
424
465
  TextValue,
425
466
  DateValue,
467
+ DateRangeFieldValue,
426
468
  CheckboxFieldValue,
427
469
  NumberFieldValue,
428
470
  FileFieldValue,
@@ -435,27 +477,21 @@ var FieldUpdateValue = import_zod4.z.union([
435
477
 
436
478
  // ../commons/src/events/FieldConfig.ts
437
479
  var FieldId = import_zod5.z.string();
438
- var DependencyExpression = import_zod5.z.object({
439
- dependsOn: import_zod5.z.array(FieldId).default([]),
440
- expression: import_zod5.z.string()
441
- });
480
+ var ParentReference = import_zod5.z.object({
481
+ _fieldId: FieldId.optional()
482
+ }).optional();
442
483
  var BaseField = import_zod5.z.object({
443
484
  id: FieldId,
444
485
  defaultValue: import_zod5.z.union([
445
- // These are the currently supported default values types
446
- import_zod5.z.union([
447
- TextValue,
448
- RequiredTextValue,
449
- DateValue,
450
- NumberFieldValue,
451
- CheckboxFieldValue
452
- ]),
453
- DependencyExpression
486
+ TextValue,
487
+ NonEmptyTextValue,
488
+ DateValue,
489
+ NumberFieldValue,
490
+ CheckboxFieldValue
454
491
  ]).optional(),
492
+ parent: ParentReference,
455
493
  conditionals: import_zod5.z.array(FieldConditional).default([]).optional(),
456
494
  required: import_zod5.z.boolean().default(false).optional(),
457
- disabled: import_zod5.z.boolean().default(false).optional(),
458
- hidden: import_zod5.z.boolean().default(false).optional(),
459
495
  placeholder: TranslationConfig.optional(),
460
496
  validation: import_zod5.z.array(
461
497
  import_zod5.z.object({
@@ -463,7 +499,6 @@ var BaseField = import_zod5.z.object({
463
499
  message: TranslationConfig
464
500
  })
465
501
  ).default([]).optional(),
466
- dependsOn: import_zod5.z.array(FieldId).default([]).optional(),
467
502
  label: TranslationConfig,
468
503
  hideLabel: import_zod5.z.boolean().default(false).optional()
469
504
  });
@@ -472,7 +507,7 @@ var Divider = BaseField.extend({
472
507
  });
473
508
  var TextField = BaseField.extend({
474
509
  type: import_zod5.z.literal(FieldType.TEXT),
475
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
510
+ defaultValue: NonEmptyTextValue.optional(),
476
511
  configuration: import_zod5.z.object({
477
512
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text"),
478
513
  type: import_zod5.z.enum(["text", "password"]).optional(),
@@ -482,7 +517,7 @@ var TextField = BaseField.extend({
482
517
  }).describe("Text input");
483
518
  var NumberField = BaseField.extend({
484
519
  type: import_zod5.z.literal(FieldType.NUMBER),
485
- defaultValue: import_zod5.z.union([NumberFieldValue, DependencyExpression]).optional(),
520
+ defaultValue: NumberFieldValue.optional(),
486
521
  configuration: import_zod5.z.object({
487
522
  min: import_zod5.z.number().optional().describe("Minimum value"),
488
523
  max: import_zod5.z.number().optional().describe("Maximum value"),
@@ -492,7 +527,7 @@ var NumberField = BaseField.extend({
492
527
  }).describe("Number input");
493
528
  var TextAreaField = BaseField.extend({
494
529
  type: import_zod5.z.literal(FieldType.TEXTAREA),
495
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
530
+ defaultValue: NonEmptyTextValue.optional(),
496
531
  configuration: import_zod5.z.object({
497
532
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text"),
498
533
  rows: import_zod5.z.number().optional().describe("Number of visible text lines"),
@@ -526,17 +561,28 @@ var EmailField = BaseField.extend({
526
561
  configuration: import_zod5.z.object({
527
562
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text")
528
563
  }).default({ maxLength: 10 }).optional(),
529
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
564
+ defaultValue: NonEmptyTextValue.optional()
530
565
  });
531
566
  var DateField = BaseField.extend({
532
567
  type: import_zod5.z.literal(FieldType.DATE),
533
- defaultValue: import_zod5.z.union([DateValue, DependencyExpression]).optional(),
568
+ defaultValue: DateValue.optional(),
534
569
  configuration: import_zod5.z.object({
535
570
  notice: TranslationConfig.describe(
536
571
  "Text to display above the date input"
537
572
  ).optional()
538
573
  }).optional()
539
574
  }).describe("A single date input (dd-mm-YYYY)");
575
+ var DateRangeField = BaseField.extend({
576
+ type: import_zod5.z.literal(FieldType.DATE_RANGE),
577
+ defaultValue: DateRangeFieldValue.optional(),
578
+ configuration: import_zod5.z.object({
579
+ notice: TranslationConfig.describe(
580
+ "Text to display above the date input"
581
+ ).optional()
582
+ }).optional()
583
+ }).describe(
584
+ "A date range input ({ rangeStart: dd-mm-YYYY, rangeEnd: dd-mm-YYYY })"
585
+ );
540
586
  var HtmlFontVariant = import_zod5.z.enum([
541
587
  "reg12",
542
588
  "reg14",
@@ -549,7 +595,7 @@ var HtmlFontVariant = import_zod5.z.enum([
549
595
  ]);
550
596
  var Paragraph = BaseField.extend({
551
597
  type: import_zod5.z.literal(FieldType.PARAGRAPH),
552
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
598
+ defaultValue: NonEmptyTextValue.optional(),
553
599
  configuration: import_zod5.z.object({
554
600
  styles: import_zod5.z.object({
555
601
  fontVariant: HtmlFontVariant.optional()
@@ -558,7 +604,7 @@ var Paragraph = BaseField.extend({
558
604
  }).describe("A read-only HTML <p> paragraph");
559
605
  var PageHeader = BaseField.extend({
560
606
  type: import_zod5.z.literal(FieldType.PAGE_HEADER),
561
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
607
+ defaultValue: NonEmptyTextValue.optional()
562
608
  }).describe("A read-only header component for form pages");
563
609
  var File = BaseField.extend({
564
610
  type: import_zod5.z.literal(FieldType.FILE),
@@ -569,7 +615,8 @@ var File = BaseField.extend({
569
615
  width: import_zod5.z.enum(["full", "auto"]).optional().describe(
570
616
  "Whether the file upload button should take the full width of the container or not"
571
617
  )
572
- }).optional()
618
+ }).optional(),
619
+ fileName: TranslationConfig.optional()
573
620
  }).default({
574
621
  maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
575
622
  })
@@ -580,7 +627,7 @@ var SelectOption = import_zod5.z.object({
580
627
  });
581
628
  var RadioGroup = BaseField.extend({
582
629
  type: import_zod5.z.literal(FieldType.RADIO_GROUP),
583
- defaultValue: import_zod5.z.union([TextValue, DependencyExpression]).optional(),
630
+ defaultValue: TextValue.optional(),
584
631
  options: import_zod5.z.array(SelectOption).describe("A list of options"),
585
632
  configuration: import_zod5.z.object({
586
633
  styles: import_zod5.z.object({
@@ -590,7 +637,7 @@ var RadioGroup = BaseField.extend({
590
637
  }).describe("Grouped radio options");
591
638
  var BulletList = BaseField.extend({
592
639
  type: import_zod5.z.literal(FieldType.BULLET_LIST),
593
- defaultValue: import_zod5.z.string().optional(),
640
+ defaultValue: TextValue.optional(),
594
641
  items: import_zod5.z.array(TranslationConfig).describe("A list of items"),
595
642
  configuration: import_zod5.z.object({
596
643
  styles: import_zod5.z.object({
@@ -600,16 +647,16 @@ var BulletList = BaseField.extend({
600
647
  }).describe("A list of bullet points");
601
648
  var Select = BaseField.extend({
602
649
  type: import_zod5.z.literal(FieldType.SELECT),
603
- defaultValue: import_zod5.z.union([TextValue, DependencyExpression]).optional(),
650
+ defaultValue: TextValue.optional(),
604
651
  options: import_zod5.z.array(SelectOption).describe("A list of options")
605
652
  }).describe("Select input");
606
653
  var Checkbox = BaseField.extend({
607
654
  type: import_zod5.z.literal(FieldType.CHECKBOX),
608
- defaultValue: import_zod5.z.union([CheckboxFieldValue, DependencyExpression]).optional()
655
+ defaultValue: CheckboxFieldValue.optional()
609
656
  }).describe("Boolean checkbox field");
610
657
  var Country = BaseField.extend({
611
658
  type: import_zod5.z.literal(FieldType.COUNTRY),
612
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
659
+ defaultValue: NonEmptyTextValue.optional()
613
660
  }).describe("Country select field");
614
661
  var AdministrativeAreas = import_zod5.z.enum([
615
662
  "ADMIN_STRUCTURE",
@@ -624,12 +671,12 @@ var AdministrativeAreaConfiguration = import_zod5.z.object({
624
671
  }).describe("Administrative area options");
625
672
  var AdministrativeArea = BaseField.extend({
626
673
  type: import_zod5.z.literal(FieldType.ADMINISTRATIVE_AREA),
627
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
674
+ defaultValue: NonEmptyTextValue.optional(),
628
675
  configuration: AdministrativeAreaConfiguration
629
676
  }).describe("Administrative area input field e.g. facility, office");
630
677
  var Location = BaseField.extend({
631
678
  type: import_zod5.z.literal(FieldType.LOCATION),
632
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
679
+ defaultValue: NonEmptyTextValue.optional()
633
680
  }).describe("Input field for a location");
634
681
  var FileUploadWithOptions = BaseField.extend({
635
682
  type: import_zod5.z.literal(FieldType.FILE_WITH_OPTIONS),
@@ -643,11 +690,11 @@ var FileUploadWithOptions = BaseField.extend({
643
690
  });
644
691
  var Facility = BaseField.extend({
645
692
  type: import_zod5.z.literal(FieldType.FACILITY),
646
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
693
+ defaultValue: NonEmptyTextValue.optional()
647
694
  }).describe("Input field for a facility");
648
695
  var Office = BaseField.extend({
649
696
  type: import_zod5.z.literal(FieldType.OFFICE),
650
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
697
+ defaultValue: NonEmptyTextValue.optional()
651
698
  }).describe("Input field for an office");
652
699
  var Address = BaseField.extend({
653
700
  type: import_zod5.z.literal(FieldType.ADDRESS),
@@ -656,7 +703,7 @@ var Address = BaseField.extend({
656
703
  var DataEntry = import_zod5.z.union([
657
704
  import_zod5.z.object({
658
705
  label: TranslationConfig,
659
- value: import_zod5.z.string()
706
+ value: TranslationConfig.or(import_zod5.z.string())
660
707
  }),
661
708
  import_zod5.z.object({
662
709
  fieldId: import_zod5.z.string()
@@ -675,6 +722,7 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
675
722
  NumberField,
676
723
  TextAreaField,
677
724
  DateField,
725
+ DateRangeField,
678
726
  Paragraph,
679
727
  RadioGroup,
680
728
  BulletList,
@@ -692,7 +740,6 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
692
740
  EmailField,
693
741
  FileUploadWithOptions,
694
742
  DataField
695
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
696
743
  ]);
697
744
 
698
745
  // ../commons/src/events/PageConfig.ts
@@ -797,6 +844,12 @@ var DeclarationUpdateActions = ActionTypes.extract(
797
844
  declarationUpdateActionValues
798
845
  );
799
846
  var annotationActions = ActionTypes.exclude(declarationActionValues);
847
+ var writeActions = ActionTypes.exclude([
848
+ ActionType.CREATE,
849
+ ActionType.READ,
850
+ ActionType.ASSIGN,
851
+ ActionType.UNASSIGN
852
+ ]);
800
853
 
801
854
  // ../commons/src/events/FormConfig.ts
802
855
  var import_zod8 = require("zod");
@@ -811,6 +864,8 @@ var ActionFormConfig = import_zod8.z.object({
811
864
  var FormConfig = import_zod8.z.union([DeclarationFormConfig, ActionFormConfig]);
812
865
 
813
866
  // ../commons/src/events/ActionConfig.ts
867
+ var import_zod_openapi = require("zod-openapi");
868
+ (0, import_zod_openapi.extendZodWithOpenApi)(import_zod9.z);
814
869
  var ActionConditional2 = import_zod9.z.discriminatedUnion("type", [
815
870
  /** If conditional is defined, the action is shown to the user only if the condition is met */
816
871
  ShowConditional,
@@ -888,18 +943,24 @@ var ApproveCorrectionConfig = ActionConfigBase.merge(
888
943
  })
889
944
  );
890
945
  var ActionConfig = import_zod9.z.discriminatedUnion("type", [
891
- DeclareConfig,
892
- ValidateConfig,
893
- RejectDeclarationConfig,
894
- MarkedAsDuplicateConfig,
895
- ArchiveConfig,
896
- RegisterConfig,
897
- DeleteConfig,
898
- PrintCertificateActionConfig,
899
- RequestCorrectionConfig,
900
- RejectCorrectionConfig,
901
- ApproveCorrectionConfig
902
- ]);
946
+ /*
947
+ * OpenAPI references are defined here so our generated OpenAPI spec knows to reuse the models
948
+ * and treat them as "models" instead of duplicating the data structure in each endpoint.
949
+ */
950
+ DeclareConfig.openapi({ ref: "DeclareActionConfig" }),
951
+ ValidateConfig.openapi({ ref: "ValidateActionConfig" }),
952
+ RejectDeclarationConfig.openapi({ ref: "RejectDeclarationActionConfig" }),
953
+ MarkedAsDuplicateConfig.openapi({ ref: "MarkedAsDuplicateActionConfig" }),
954
+ ArchiveConfig.openapi({ ref: "ArchiveActionConfig" }),
955
+ RegisterConfig.openapi({ ref: "RegisterActionConfig" }),
956
+ DeleteConfig.openapi({ ref: "DeleteActionConfig" }),
957
+ PrintCertificateActionConfig.openapi({
958
+ ref: "PrintCertificateActionConfig"
959
+ }),
960
+ RequestCorrectionConfig.openapi({ ref: "RequestCorrectionActionConfig" }),
961
+ RejectCorrectionConfig.openapi({ ref: "RejectCorrectionActionConfig" }),
962
+ ApproveCorrectionConfig.openapi({ ref: "ApproveCorrectionActionConfig" })
963
+ ]).openapi({ ref: "ActionConfig" });
903
964
  var DeclarationActionConfig = import_zod9.z.discriminatedUnion("type", [
904
965
  DeclareConfig,
905
966
  ValidateConfig,
@@ -943,10 +1004,12 @@ var LanguageConfig = import_zod11.z.object({
943
1004
  });
944
1005
 
945
1006
  // ../commons/src/events/EventConfig.ts
946
- var import_zod20 = require("zod");
1007
+ var import_zod17 = require("zod");
947
1008
 
948
1009
  // ../commons/src/events/DeduplicationConfig.ts
949
1010
  var import_zod12 = require("zod");
1011
+ var import_zod_openapi2 = require("zod-openapi");
1012
+ (0, import_zod_openapi2.extendZodWithOpenApi)(import_zod12.z);
950
1013
  var FieldReference = import_zod12.z.string();
951
1014
  var Matcher = import_zod12.z.object({
952
1015
  fieldId: import_zod12.z.string(),
@@ -1007,7 +1070,9 @@ var Clause = import_zod12.z.lazy(
1007
1070
  DateRangeMatcher,
1008
1071
  DateDistanceMatcher
1009
1072
  ])
1010
- );
1073
+ ).openapi({
1074
+ ref: "Clause"
1075
+ });
1011
1076
  var DeduplicationConfig = import_zod12.z.object({
1012
1077
  id: import_zod12.z.string(),
1013
1078
  label: TranslationConfig,
@@ -1016,272 +1081,214 @@ var DeduplicationConfig = import_zod12.z.object({
1016
1081
 
1017
1082
  // ../commons/src/events/SummaryConfig.ts
1018
1083
  var import_zod13 = require("zod");
1019
- var Field = import_zod13.z.object({
1084
+ var BaseField2 = import_zod13.z.object({
1085
+ emptyValueMessage: TranslationConfig.optional(),
1086
+ conditionals: import_zod13.z.array(ShowConditional).default([]).optional()
1087
+ });
1088
+ var ReferenceField = BaseField2.extend({
1089
+ fieldId: import_zod13.z.string(),
1090
+ label: TranslationConfig.optional().describe(
1091
+ "By default, the configured field's label is used. This can be overridden by providing a custom label."
1092
+ )
1093
+ }).describe("Field directly referencing event data with field id");
1094
+ var Field = BaseField2.extend({
1020
1095
  id: import_zod13.z.string().describe("Id of summary field"),
1021
1096
  value: TranslationConfig.describe(
1022
1097
  "Summary field value. Can utilise values defined in configuration and EventMetadata"
1023
1098
  ),
1024
1099
  label: TranslationConfig,
1025
1100
  emptyValueMessage: TranslationConfig.optional()
1026
- });
1027
- var Title = import_zod13.z.object({
1028
- id: import_zod13.z.string(),
1029
- label: TranslationConfig.describe("Title content"),
1030
- emptyValueMessage: TranslationConfig.optional()
1031
- });
1101
+ }).describe("Custom configured field");
1032
1102
  var SummaryConfig = import_zod13.z.object({
1033
- title: Title.describe("Title of summary view."),
1034
- fields: import_zod13.z.array(Field).describe("Fields rendered in summary view.")
1103
+ fields: import_zod13.z.array(import_zod13.z.union([Field, ReferenceField])).describe("Fields rendered in summary view.")
1035
1104
  }).describe("Configuration for summary in event.");
1036
1105
 
1037
- // ../commons/src/events/WorkqueueConfig.ts
1038
- var import_zod15 = require("zod");
1039
-
1040
- // ../commons/src/events/EventMetadata.ts
1106
+ // ../commons/src/events/AdvancedSearchConfig.ts
1041
1107
  var import_zod14 = require("zod");
1042
- var EventStatus = {
1043
- CREATED: "CREATED",
1044
- NOTIFIED: "NOTIFIED",
1045
- DECLARED: "DECLARED",
1046
- VALIDATED: "VALIDATED",
1047
- REGISTERED: "REGISTERED",
1048
- CERTIFIED: "CERTIFIED",
1049
- REJECTED: "REJECTED",
1050
- ARCHIVED: "ARCHIVED"
1051
- };
1052
- var eventStatuses = Object.values(EventStatus);
1053
- var EventStatuses = import_zod14.z.nativeEnum(EventStatus);
1054
- var EventMetadata = import_zod14.z.object({
1055
- id: import_zod14.z.string(),
1056
- type: import_zod14.z.string(),
1057
- status: EventStatuses,
1058
- createdAt: import_zod14.z.string().datetime(),
1059
- createdBy: import_zod14.z.string(),
1060
- createdAtLocation: import_zod14.z.string(),
1061
- modifiedAt: import_zod14.z.string().datetime(),
1062
- assignedTo: import_zod14.z.string().nullish(),
1063
- updatedBy: import_zod14.z.string(),
1064
- trackingId: import_zod14.z.string(),
1065
- registrationNumber: import_zod14.z.string().nullish()
1108
+ var MatchType = import_zod14.z.enum(["fuzzy", "exact", "range"]);
1109
+ var BaseField3 = import_zod14.z.object({
1110
+ config: import_zod14.z.object({
1111
+ type: MatchType.describe("Determines the type of field")
1112
+ }),
1113
+ options: import_zod14.z.array(SelectOption).optional()
1066
1114
  });
1067
- var eventMetadataLabelMap = {
1068
- "event.assignedTo": {
1069
- id: "event.assignedTo.label",
1070
- defaultMessage: "Assigned To",
1071
- description: "Assigned To"
1072
- },
1073
- "event.createdAt": {
1074
- id: "event.createdAt.label",
1075
- defaultMessage: "Created",
1076
- description: "Created At"
1077
- },
1078
- "event.createdAtLocation": {
1079
- id: "event.createdAtLocation.label",
1080
- defaultMessage: "Location",
1081
- description: "Created At Location"
1082
- },
1083
- "event.createdBy": {
1084
- id: "event.createdBy.label",
1085
- defaultMessage: "Created By",
1086
- description: "Created By"
1087
- },
1088
- "event.id": {
1089
- id: "event.id.label",
1090
- defaultMessage: "ID",
1091
- description: "ID"
1092
- },
1093
- "event.modifiedAt": {
1094
- id: "event.modifiedAt.label",
1095
- defaultMessage: "Updated",
1096
- description: "Modified At"
1097
- },
1098
- "event.status": {
1099
- id: "event.status.label",
1100
- defaultMessage: "Status",
1101
- description: "Status"
1102
- },
1103
- "event.type": {
1104
- id: "event.type.label",
1105
- defaultMessage: "Type",
1106
- description: "Type"
1107
- },
1108
- "event.updatedBy": {
1109
- id: "event.updatedBy.label",
1110
- defaultMessage: "Updated By",
1111
- description: "Updated By"
1112
- },
1113
- "event.trackingId": {
1114
- id: "event.trackingId.label",
1115
- defaultMessage: "Tracking ID",
1116
- description: "Tracking ID"
1117
- },
1118
- "event.registrationNumber": {
1119
- id: "event.registrationNumber.label",
1120
- defaultMessage: "Registration Number",
1121
- description: "Registration Number"
1122
- }
1123
- };
1124
-
1125
- // ../commons/src/events/WorkqueueConfig.ts
1126
- var WorkqueueConfig = import_zod15.z.object({
1127
- id: import_zod15.z.string().describe("Unique identifier for workqueue."),
1128
- filters: import_zod15.z.array(
1129
- import_zod15.z.object({
1130
- status: import_zod15.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
1131
- })
1132
- ).describe("Filters to be applied to workqueue.")
1133
- }).describe("Configuration for workqueue.");
1134
-
1135
- // ../commons/src/events/AdvancedSearchConfig.ts
1136
- var import_zod16 = require("zod");
1137
- var AdvancedSearchConfig = import_zod16.z.object({
1115
+ var FieldConfigSchema = BaseField3.extend({
1116
+ fieldId: import_zod14.z.string(),
1117
+ fieldType: import_zod14.z.literal("field")
1118
+ });
1119
+ var EventFieldId = import_zod14.z.enum(["trackingId", "status"]);
1120
+ var EventFieldConfigSchema = BaseField3.extend({
1121
+ fieldId: EventFieldId,
1122
+ fieldType: import_zod14.z.literal("event")
1123
+ });
1124
+ var SearchField = import_zod14.z.discriminatedUnion("fieldType", [
1125
+ FieldConfigSchema,
1126
+ EventFieldConfigSchema
1127
+ ]);
1128
+ var AdvancedSearchConfig = import_zod14.z.object({
1138
1129
  title: TranslationConfig.describe("Advanced search tab title"),
1139
- fields: import_zod16.z.array(
1140
- import_zod16.z.object({
1141
- fieldId: import_zod16.z.string(),
1142
- config: import_zod16.z.object({
1143
- type: import_zod16.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
1144
- }).optional().describe("Configuration options for the field")
1145
- })
1146
- ).optional().default([]).describe("Advanced search fields.")
1130
+ fields: import_zod14.z.array(SearchField).describe("Advanced search fields.")
1147
1131
  });
1148
1132
 
1149
1133
  // ../commons/src/events/utils.ts
1150
1134
  var import_lodash = require("lodash");
1151
1135
 
1152
- // ../commons/src/workqueues/WorkqueueConfig.ts
1153
- var import_zod18 = require("zod");
1154
-
1155
- // ../commons/src/workqueues/defaultColumns.ts
1156
- var import_zod17 = require("zod");
1157
- var WorkQueueColumnConfig = import_zod17.z.object({
1158
- id: import_zod17.z.string(),
1159
- label: TranslationConfig
1160
- });
1161
- var defaultColumns = {
1162
- event: {
1163
- id: "event",
1164
- label: {
1165
- defaultMessage: "Event",
1166
- description: "This is the label for the workqueue column",
1167
- id: "workqueue.default.column.event"
1168
- }
1169
- },
1170
- status: {
1171
- id: "status",
1172
- label: {
1173
- defaultMessage: "Status",
1174
- description: "This is the label for the workqueue column",
1175
- id: "workqueue.default.column.status"
1176
- }
1177
- },
1178
- createdAt: {
1179
- id: "createdAt",
1180
- label: {
1181
- defaultMessage: "Created",
1182
- description: "This is the label for the workqueue column",
1183
- id: "workqueue.default.column.createdAt"
1184
- }
1185
- },
1186
- modifiedAt: {
1187
- id: "modifiedAt",
1188
- label: {
1189
- defaultMessage: "Modified",
1190
- description: "This is the label for the workqueue column",
1191
- id: "workqueue.default.column.modifiedAt"
1192
- }
1193
- }
1136
+ // ../commons/src/events/ActionDocument.ts
1137
+ var import_zod15 = require("zod");
1138
+ var import_zod_openapi3 = require("zod-openapi");
1139
+ (0, import_zod_openapi3.extendZodWithOpenApi)(import_zod15.z);
1140
+ var ActionUpdate = import_zod15.z.record(import_zod15.z.string(), FieldUpdateValue);
1141
+ var EventState = import_zod15.z.record(import_zod15.z.string(), FieldValue);
1142
+ var ActionStatus = {
1143
+ Requested: "Requested",
1144
+ Accepted: "Accepted",
1145
+ Rejected: "Rejected"
1194
1146
  };
1195
- var DefaultColumnKeys = import_zod17.z.enum(
1196
- Object.keys(defaultColumns)
1197
- );
1198
-
1199
- // ../commons/src/workqueues/WorkqueueConfig.ts
1200
- var rootWorkqueueConfig = import_zod18.z.object({
1201
- id: import_zod18.z.string(),
1202
- title: TranslationConfig,
1203
- columns: import_zod18.z.array(WorkQueueColumnConfig),
1204
- defaultColumns: import_zod18.z.array(DefaultColumnKeys)
1205
- });
1206
- var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
1207
-
1208
- // ../commons/src/workqueues/all.ts
1209
- var allWorkqueue = defineWorkqueue({
1210
- id: "all",
1211
- title: {
1212
- defaultMessage: "All events",
1213
- description: "This is the label for the workqueue",
1214
- id: "workqueue.all.label"
1215
- },
1216
- columns: [
1217
- {
1218
- id: "title",
1219
- label: {
1220
- defaultMessage: "Title",
1221
- description: "This is the label for the workqueue column",
1222
- id: "workqueue.all.column.title"
1223
- }
1224
- }
1225
- ],
1226
- defaultColumns: ["event", "status", "createdAt", "modifiedAt"]
1147
+ var ActionBase = import_zod15.z.object({
1148
+ id: import_zod15.z.string(),
1149
+ transactionId: import_zod15.z.string(),
1150
+ createdAt: import_zod15.z.string().datetime(),
1151
+ createdBy: import_zod15.z.string(),
1152
+ createdByRole: import_zod15.z.string(),
1153
+ declaration: ActionUpdate,
1154
+ annotation: ActionUpdate.optional(),
1155
+ createdAtLocation: import_zod15.z.string(),
1156
+ status: import_zod15.z.enum([
1157
+ ActionStatus.Requested,
1158
+ ActionStatus.Accepted,
1159
+ ActionStatus.Rejected
1160
+ ]),
1161
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1162
+ originalActionId: import_zod15.z.string().optional()
1227
1163
  });
1228
-
1229
- // ../commons/src/workqueues/readyForReview.ts
1230
- var inReviewWorkqueue = defineWorkqueue({
1231
- id: "ready-for-review",
1232
- title: {
1233
- defaultMessage: "Ready for review",
1234
- description: "Label for in review workqueue",
1235
- id: "event.workqueue.in-review.label"
1236
- },
1237
- columns: [
1238
- {
1239
- id: "title",
1240
- label: {
1241
- defaultMessage: "Title",
1242
- description: "This is the label for the workqueue column",
1243
- id: "workqueue.in-reveiw.column.title"
1244
- }
1245
- }
1246
- ],
1247
- defaultColumns: ["event", "createdAt", "modifiedAt"]
1164
+ var AssignedAction = ActionBase.merge(
1165
+ import_zod15.z.object({
1166
+ type: import_zod15.z.literal(ActionType.ASSIGN),
1167
+ assignedTo: import_zod15.z.string()
1168
+ })
1169
+ );
1170
+ var UnassignedAction = ActionBase.merge(
1171
+ import_zod15.z.object({
1172
+ type: import_zod15.z.literal(ActionType.UNASSIGN),
1173
+ assignedTo: import_zod15.z.literal(null)
1174
+ })
1175
+ );
1176
+ var RegisterAction = ActionBase.merge(
1177
+ import_zod15.z.object({
1178
+ type: import_zod15.z.literal(ActionType.REGISTER),
1179
+ registrationNumber: import_zod15.z.string().optional()
1180
+ })
1181
+ );
1182
+ var DeclareAction = ActionBase.merge(
1183
+ import_zod15.z.object({
1184
+ type: import_zod15.z.literal(ActionType.DECLARE)
1185
+ })
1186
+ );
1187
+ var ValidateAction = ActionBase.merge(
1188
+ import_zod15.z.object({
1189
+ type: import_zod15.z.literal(ActionType.VALIDATE)
1190
+ })
1191
+ );
1192
+ var RejectAction = ActionBase.merge(
1193
+ import_zod15.z.object({
1194
+ type: import_zod15.z.literal(ActionType.REJECT)
1195
+ })
1196
+ );
1197
+ var MarkAsDuplicateAction = ActionBase.merge(
1198
+ import_zod15.z.object({
1199
+ type: import_zod15.z.literal(ActionType.MARKED_AS_DUPLICATE)
1200
+ })
1201
+ );
1202
+ var ArchiveAction = ActionBase.merge(
1203
+ import_zod15.z.object({
1204
+ type: import_zod15.z.literal(ActionType.ARCHIVE)
1205
+ })
1206
+ );
1207
+ var CreatedAction = ActionBase.merge(
1208
+ import_zod15.z.object({
1209
+ type: import_zod15.z.literal(ActionType.CREATE)
1210
+ })
1211
+ );
1212
+ var NotifiedAction = ActionBase.merge(
1213
+ import_zod15.z.object({
1214
+ type: import_zod15.z.literal(ActionType.NOTIFY)
1215
+ })
1216
+ );
1217
+ var PrintCertificateAction = ActionBase.merge(
1218
+ import_zod15.z.object({
1219
+ type: import_zod15.z.literal(ActionType.PRINT_CERTIFICATE)
1220
+ })
1221
+ );
1222
+ var RequestedCorrectionAction = ActionBase.merge(
1223
+ import_zod15.z.object({
1224
+ type: import_zod15.z.literal(ActionType.REQUEST_CORRECTION)
1225
+ })
1226
+ );
1227
+ var ApprovedCorrectionAction = ActionBase.merge(
1228
+ import_zod15.z.object({
1229
+ type: import_zod15.z.literal(ActionType.APPROVE_CORRECTION),
1230
+ requestId: import_zod15.z.string()
1231
+ })
1232
+ );
1233
+ var RejectedCorrectionAction = ActionBase.merge(
1234
+ import_zod15.z.object({
1235
+ type: import_zod15.z.literal(ActionType.REJECT_CORRECTION),
1236
+ requestId: import_zod15.z.string()
1237
+ })
1238
+ );
1239
+ var ReadAction = ActionBase.merge(
1240
+ import_zod15.z.object({
1241
+ type: import_zod15.z.literal(ActionType.READ)
1242
+ })
1243
+ );
1244
+ var ActionDocument = import_zod15.z.discriminatedUnion("type", [
1245
+ CreatedAction.openapi({ ref: "CreatedAction" }),
1246
+ ValidateAction.openapi({ ref: "ValidateAction" }),
1247
+ RejectAction.openapi({ ref: "RejectAction" }),
1248
+ MarkAsDuplicateAction.openapi({ ref: "MarkAsDuplicateAction" }),
1249
+ ArchiveAction.openapi({ ref: "ArchiveAction" }),
1250
+ NotifiedAction.openapi({ ref: "NotifiedAction" }),
1251
+ RegisterAction.openapi({ ref: "RegisterAction" }),
1252
+ DeclareAction.openapi({ ref: "DeclareAction" }),
1253
+ AssignedAction.openapi({ ref: "AssignedAction" }),
1254
+ RequestedCorrectionAction.openapi({ ref: "RequestedCorrectionAction" }),
1255
+ ApprovedCorrectionAction.openapi({ ref: "ApprovedCorrectionAction" }),
1256
+ RejectedCorrectionAction.openapi({ ref: "RejectedCorrectionAction" }),
1257
+ UnassignedAction.openapi({ ref: "UnassignedAction" }),
1258
+ PrintCertificateAction.openapi({ ref: "PrintCertificateAction" }),
1259
+ ReadAction.openapi({ ref: "ReadAction" })
1260
+ ]).openapi({
1261
+ ref: "ActionDocument"
1248
1262
  });
1249
-
1250
- // ../commons/src/workqueues/readyToPrint.ts
1251
- var registeredWorkqueue = defineWorkqueue({
1252
- id: "registered",
1253
- title: {
1254
- defaultMessage: "Ready to print",
1255
- description: "Label for registered workqueue",
1256
- id: "event.workqueue.registered.label"
1257
- },
1258
- columns: [
1259
- {
1260
- id: "title",
1261
- label: {
1262
- defaultMessage: "Title",
1263
- description: "This is the label for the workqueue column",
1264
- id: "workqueue.registered.column.title"
1265
- }
1266
- }
1267
- ],
1268
- defaultColumns: ["event", "createdAt", "modifiedAt"]
1263
+ var AsyncRejectActionDocument = ActionBase.omit({
1264
+ declaration: true,
1265
+ annotation: true
1266
+ }).merge(
1267
+ import_zod15.z.object({
1268
+ type: import_zod15.z.enum(ConfirmableActions),
1269
+ status: import_zod15.z.literal(ActionStatus.Rejected)
1270
+ })
1271
+ );
1272
+ var Action = import_zod15.z.union([ActionDocument, AsyncRejectActionDocument]);
1273
+ var ResolvedUser = import_zod15.z.object({
1274
+ id: import_zod15.z.string(),
1275
+ role: import_zod15.z.string(),
1276
+ name: import_zod15.z.array(
1277
+ import_zod15.z.object({
1278
+ use: import_zod15.z.string(),
1279
+ given: import_zod15.z.array(import_zod15.z.string()),
1280
+ family: import_zod15.z.string()
1281
+ })
1282
+ )
1269
1283
  });
1270
1284
 
1271
- // ../commons/src/workqueues/index.ts
1272
- var workqueues = {
1273
- all: allWorkqueue,
1274
- registered: registeredWorkqueue,
1275
- inReview: inReviewWorkqueue
1276
- };
1277
-
1278
1285
  // ../commons/src/conditionals/validate.ts
1279
1286
  var import_ajv = __toESM(require("ajv"));
1280
1287
  var import_ajv_formats = __toESM(require("ajv-formats"));
1281
1288
  var import_date_fns = require("date-fns");
1282
1289
 
1283
1290
  // ../commons/src/events/FieldTypeMapping.ts
1284
- var import_zod19 = require("zod");
1291
+ var import_zod16 = require("zod");
1285
1292
  function mapFieldTypeToZod(type, required) {
1286
1293
  let schema;
1287
1294
  switch (type) {
@@ -1291,6 +1298,9 @@ function mapFieldTypeToZod(type, required) {
1291
1298
  case FieldType.EMAIL:
1292
1299
  schema = EmailValue;
1293
1300
  break;
1301
+ case FieldType.DATE_RANGE:
1302
+ schema = DateRangeFieldValue;
1303
+ break;
1294
1304
  case FieldType.TEXT:
1295
1305
  case FieldType.TEXTAREA:
1296
1306
  case FieldType.DIVIDER:
@@ -1305,8 +1315,7 @@ function mapFieldTypeToZod(type, required) {
1305
1315
  case FieldType.FACILITY:
1306
1316
  case FieldType.OFFICE:
1307
1317
  case FieldType.SIGNATURE:
1308
- case FieldType.HIDDEN:
1309
- schema = required ? RequiredTextValue : TextValue;
1318
+ schema = required ? NonEmptyTextValue : TextValue;
1310
1319
  break;
1311
1320
  case FieldType.NUMBER:
1312
1321
  schema = NumberFieldValue;
@@ -1334,7 +1343,7 @@ function createValidationSchema(config) {
1334
1343
  for (const field2 of config) {
1335
1344
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1336
1345
  }
1337
- return import_zod19.z.object(shape);
1346
+ return import_zod16.z.object(shape);
1338
1347
  }
1339
1348
  function mapFieldTypeToMockValue(field2, i) {
1340
1349
  switch (field2.type) {
@@ -1372,6 +1381,8 @@ function mapFieldTypeToMockValue(field2, i) {
1372
1381
  };
1373
1382
  case FieldType.DATE:
1374
1383
  return "2021-01-01";
1384
+ case FieldType.DATE_RANGE:
1385
+ return ["2021-01-01", "2021-01-02"];
1375
1386
  case FieldType.CHECKBOX:
1376
1387
  return true;
1377
1388
  case FieldType.FILE:
@@ -1406,6 +1417,7 @@ function mapFieldTypeToEmptyValue(field2) {
1406
1417
  case FieldType.EMAIL:
1407
1418
  case FieldType.DATE:
1408
1419
  case FieldType.CHECKBOX:
1420
+ case FieldType.DATE_RANGE:
1409
1421
  case FieldType.DATA:
1410
1422
  return null;
1411
1423
  case FieldType.ADDRESS:
@@ -1438,6 +1450,9 @@ var isParagraphFieldType = (field2) => {
1438
1450
  var isDateFieldType = (field2) => {
1439
1451
  return field2.config.type === FieldType.DATE;
1440
1452
  };
1453
+ var isDateRangeFieldType = (field2) => {
1454
+ return field2.config.type === FieldType.DATE_RANGE;
1455
+ };
1441
1456
  var isPageHeaderFieldType = (field2) => {
1442
1457
  return field2.config.type === FieldType.PAGE_HEADER;
1443
1458
  };
@@ -1508,12 +1523,23 @@ var ajv = new import_ajv.default({
1508
1523
  function validate(schema, data) {
1509
1524
  return ajv.validate(schema, data);
1510
1525
  }
1526
+ function isConditionMet(conditional, values) {
1527
+ return validate(conditional, {
1528
+ $form: values,
1529
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1530
+ });
1531
+ }
1511
1532
  function getConditionalActionsForField(field2, values) {
1512
1533
  if (!field2.conditionals) {
1513
1534
  return [];
1514
1535
  }
1515
1536
  return field2.conditionals.filter((conditional) => validate(conditional.conditional, values)).map((conditional) => conditional.type);
1516
1537
  }
1538
+ function areConditionsMet(conditions, values) {
1539
+ return conditions.every(
1540
+ (condition) => isConditionMet(condition.conditional, values)
1541
+ );
1542
+ }
1517
1543
  function isFieldConditionMet(field2, form, conditionalType) {
1518
1544
  const hasRule = (field2.conditionals ?? []).some(
1519
1545
  (conditional) => conditional.type === conditionalType
@@ -1532,6 +1558,10 @@ function isFieldConditionMet(field2, form, conditionalType) {
1532
1558
  function isFieldVisible(field2, form) {
1533
1559
  return isFieldConditionMet(field2, form, ConditionalType.SHOW);
1534
1560
  }
1561
+ function isFieldEmptyAndNotRequired(field2, form) {
1562
+ const fieldValue = form[field2.id];
1563
+ return !field2.required && (fieldValue === void 0 || fieldValue === "");
1564
+ }
1535
1565
  function isFieldEnabled(field2, form) {
1536
1566
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1537
1567
  }
@@ -1636,6 +1666,11 @@ function runFieldValidations({
1636
1666
  field: field2,
1637
1667
  values
1638
1668
  }) {
1669
+ if (!isFieldVisible(field2, values) || isFieldEmptyAndNotRequired(field2, values)) {
1670
+ return {
1671
+ errors: []
1672
+ };
1673
+ }
1639
1674
  const conditionalParameters = {
1640
1675
  $form: values,
1641
1676
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
@@ -1653,29 +1688,6 @@ function runFieldValidations({
1653
1688
  errors: [...fieldValidationResult, ...customValidationResults]
1654
1689
  };
1655
1690
  }
1656
- function getFieldValidationErrors({
1657
- field: field2,
1658
- values
1659
- }) {
1660
- if (!isFieldVisible(field2, values) || !isFieldEnabled(field2, values)) {
1661
- if (values[field2.id]) {
1662
- return {
1663
- errors: [
1664
- {
1665
- message: errorMessages.hiddenField
1666
- }
1667
- ]
1668
- };
1669
- }
1670
- return {
1671
- errors: []
1672
- };
1673
- }
1674
- return runFieldValidations({
1675
- field: field2,
1676
- values
1677
- });
1678
- }
1679
1691
 
1680
1692
  // ../commons/src/uuid.ts
1681
1693
  var import_uuid = require("uuid");
@@ -1683,9 +1695,6 @@ function getUUID() {
1683
1695
  return (0, import_uuid.v4)();
1684
1696
  }
1685
1697
 
1686
- // ../commons/src/events/utils.ts
1687
- var import_date_fns2 = require("date-fns");
1688
-
1689
1698
  // ../commons/src/utils.ts
1690
1699
  function getOrThrow(x, message) {
1691
1700
  if (x === void 0 || x === null) {
@@ -1722,15 +1731,9 @@ var getActionAnnotationFields = (actionConfig) => {
1722
1731
  }
1723
1732
  return [];
1724
1733
  };
1725
- var getAllAnnotationFields = (config) => {
1734
+ function getAllAnnotationFields(config) {
1726
1735
  return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1727
- };
1728
- var findAllFields = (config) => {
1729
- return (0, import_lodash.flattenDeep)([
1730
- ...getDeclarationFields(config),
1731
- ...getAllAnnotationFields(config)
1732
- ]);
1733
- };
1736
+ }
1734
1737
  var findRecordActionPages = (config, actionType) => {
1735
1738
  const action = config.actions.find((a) => a.type === actionType);
1736
1739
  if (action?.type === ActionType.REQUEST_CORRECTION) {
@@ -1753,34 +1756,22 @@ function getActionReview(configuration, actionType) {
1753
1756
  function getActionReviewFields(configuration, actionType) {
1754
1757
  return getActionReview(configuration, actionType).fields;
1755
1758
  }
1756
- function validateWorkqueueConfig(workqueueConfigs) {
1757
- workqueueConfigs.map((workqueue) => {
1758
- const rootWorkqueue = Object.values(workqueues).find(
1759
- (wq) => wq.id === workqueue.id
1760
- );
1761
- if (!rootWorkqueue) {
1762
- throw new Error(
1763
- `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1764
- );
1765
- }
1766
- });
1767
- }
1768
1759
  function isPageVisible(page, formValues) {
1769
1760
  if (!page.conditional) {
1770
1761
  return true;
1771
1762
  }
1772
- return validate(page.conditional, {
1773
- $form: formValues,
1774
- $now: (0, import_date_fns2.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1775
- });
1763
+ return isConditionMet(page.conditional, formValues);
1776
1764
  }
1777
- function omitHiddenFields(fields, values) {
1765
+ function omitHiddenFields(fields, values, visibleVerificationPageIds = []) {
1778
1766
  return (0, import_lodash.omitBy)(values, (_, fieldId) => {
1779
- const field2 = fields.find((f) => f.id === fieldId);
1780
- if (!field2) {
1767
+ if (visibleVerificationPageIds.includes(fieldId)) {
1768
+ return false;
1769
+ }
1770
+ const fieldConfigs = fields.filter((f) => f.id === fieldId);
1771
+ if (!fieldConfigs.length) {
1781
1772
  return true;
1782
1773
  }
1783
- return !isFieldVisible(field2, values);
1774
+ return fieldConfigs.every((f) => !isFieldVisible(f, values));
1784
1775
  });
1785
1776
  }
1786
1777
  function omitHiddenPaginatedFields(formConfig, declaration) {
@@ -1804,13 +1795,49 @@ function createEmptyDraft(eventId, draftId, actionType) {
1804
1795
  annotation: {},
1805
1796
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1806
1797
  createdBy: "@todo",
1807
- createdAtLocation: "@todo"
1798
+ createdAtLocation: "@todo",
1799
+ status: ActionStatus.Accepted,
1800
+ transactionId: "@todo",
1801
+ createdByRole: "@todo"
1808
1802
  }
1809
1803
  };
1810
1804
  }
1811
1805
  function isVerificationPage(page) {
1812
1806
  return page.type === PageTypes.enum.VERIFICATION;
1813
1807
  }
1808
+ function getVisibleVerificationPageIds(pages, annotation) {
1809
+ return pages.filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
1810
+ }
1811
+ function getActionVerificationPageIds(actionConfig, annotation) {
1812
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1813
+ return [
1814
+ ...getVisibleVerificationPageIds(actionConfig.onboardingForm, annotation),
1815
+ ...getVisibleVerificationPageIds(
1816
+ actionConfig.additionalDetailsForm,
1817
+ annotation
1818
+ )
1819
+ ];
1820
+ }
1821
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1822
+ return getVisibleVerificationPageIds(
1823
+ actionConfig.printForm.pages,
1824
+ annotation
1825
+ );
1826
+ }
1827
+ return [];
1828
+ }
1829
+ function omitHiddenAnnotationFields(actionConfig, declaration, annotation) {
1830
+ const annotationFields = getActionAnnotationFields(actionConfig);
1831
+ const visibleVerificationPageIds = getActionVerificationPageIds(
1832
+ actionConfig,
1833
+ annotation
1834
+ );
1835
+ return omitHiddenFields(
1836
+ annotationFields,
1837
+ { ...declaration, ...annotation },
1838
+ visibleVerificationPageIds
1839
+ );
1840
+ }
1814
1841
  function deepMerge(currentDocument, actionDocument) {
1815
1842
  return (0, import_lodash.mergeWith)(
1816
1843
  currentDocument,
@@ -1829,19 +1856,57 @@ function deepMerge(currentDocument, actionDocument) {
1829
1856
  }
1830
1857
  );
1831
1858
  }
1859
+ function findLastAssignmentAction(actions) {
1860
+ return actions.filter(
1861
+ ({ type }) => type === ActionType.ASSIGN || type === ActionType.UNASSIGN
1862
+ ).reduce((latestAction, action) => !latestAction || action.createdAt > latestAction.createdAt ? action : latestAction, void 0);
1863
+ }
1864
+ function isWriteAction(actionType) {
1865
+ return writeActions.safeParse(actionType).success;
1866
+ }
1867
+ var findAllFields = (config) => {
1868
+ return (0, import_lodash.flattenDeep)([
1869
+ ...getDeclarationFields(config),
1870
+ ...getAllAnnotationFields(config)
1871
+ ]);
1872
+ };
1873
+ function getMixedPath(obj, path, defaultValue) {
1874
+ const parts = path.split(".");
1875
+ const resolve = (current, segments) => {
1876
+ if (current == null || segments.length === 0) {
1877
+ return current;
1878
+ }
1879
+ for (let i = segments.length; i > 0; i--) {
1880
+ const compoundKey = segments.slice(0, i).join(".");
1881
+ if ((0, import_lodash.has)(current, compoundKey)) {
1882
+ const next = (0, import_lodash.get)(current, compoundKey);
1883
+ return resolve(next, segments.slice(i));
1884
+ }
1885
+ }
1886
+ return void 0;
1887
+ };
1888
+ const result = resolve(obj, parts);
1889
+ return (0, import_lodash.isNil)(result) ? defaultValue : result;
1890
+ }
1832
1891
 
1833
1892
  // ../commons/src/events/EventConfig.ts
1834
- var EventConfig = import_zod20.z.object({
1835
- id: import_zod20.z.string().describe(
1893
+ var import_zod_openapi4 = require("zod-openapi");
1894
+ (0, import_zod_openapi4.extendZodWithOpenApi)(import_zod17.z);
1895
+ var EventConfig = import_zod17.z.object({
1896
+ id: import_zod17.z.string().describe(
1836
1897
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1837
1898
  ),
1899
+ dateOfEvent: import_zod17.z.object({ fieldId: import_zod17.z.string() }).optional(),
1900
+ title: TranslationConfig,
1901
+ fallbackTitle: TranslationConfig.optional().describe(
1902
+ "This is a fallback title if actual title resolves to empty string"
1903
+ ),
1838
1904
  summary: SummaryConfig,
1839
1905
  label: TranslationConfig,
1840
- actions: import_zod20.z.array(ActionConfig),
1906
+ actions: import_zod17.z.array(ActionConfig),
1841
1907
  declaration: DeclarationFormConfig,
1842
- workqueues: import_zod20.z.array(WorkqueueConfig),
1843
- deduplication: import_zod20.z.array(DeduplicationConfig).optional().default([]),
1844
- advancedSearch: import_zod20.z.array(AdvancedSearchConfig).optional().default([])
1908
+ deduplication: import_zod17.z.array(DeduplicationConfig).optional().default([]),
1909
+ advancedSearch: import_zod17.z.array(AdvancedSearchConfig).optional().default([])
1845
1910
  }).superRefine((event2, ctx) => {
1846
1911
  const allFields = findAllFields(event2);
1847
1912
  const fieldIds = allFields.map((field2) => field2.id);
@@ -1857,16 +1922,43 @@ var EventConfig = import_zod20.z.object({
1857
1922
  });
1858
1923
  }
1859
1924
  const invalidFields = event2.advancedSearch.flatMap(
1860
- (section) => section.fields.filter((field2) => !fieldIds.includes(field2.fieldId))
1925
+ (section) => (
1926
+ // Check if the fieldId is not in the fieldIds array
1927
+ // and also not in the metadataFields array
1928
+ section.fields.filter(
1929
+ (field2) => !(fieldIds.includes(field2.fieldId) || EventFieldId.options.includes(field2.fieldId))
1930
+ )
1931
+ )
1861
1932
  );
1862
1933
  if (invalidFields.length > 0) {
1863
1934
  ctx.addIssue({
1864
1935
  code: "custom",
1865
- message: `Advanced search id must match a field id in fields array.
1936
+ message: `Advanced search id must match a field id of form fields or pre-defined metadata fields.
1866
1937
  Invalid AdvancedSearch field IDs for event ${event2.id}: ${invalidFields.map((f) => f.fieldId).join(", ")}`,
1867
1938
  path: ["advancedSearch"]
1868
1939
  });
1869
1940
  }
1941
+ if (event2.dateOfEvent) {
1942
+ const eventDateFieldId = getDeclarationFields(event2).find(
1943
+ ({ id }) => id === event2.dateOfEvent?.fieldId
1944
+ );
1945
+ if (!eventDateFieldId) {
1946
+ ctx.addIssue({
1947
+ code: "custom",
1948
+ message: `Date of event field id must match a field id in fields array.
1949
+ Invalid date of event field ID for event ${event2.id}: ${event2.dateOfEvent.fieldId}`,
1950
+ path: ["dateOfEvent"]
1951
+ });
1952
+ } else if (eventDateFieldId.type !== FieldType.DATE) {
1953
+ ctx.addIssue({
1954
+ code: "custom",
1955
+ message: `Field specified for date of event is of type: ${eventDateFieldId.type}, but it needs to be of type: ${FieldType.DATE}`,
1956
+ path: ["dateOfEvent.fieldType"]
1957
+ });
1958
+ }
1959
+ }
1960
+ }).openapi({
1961
+ ref: "EventConfig"
1870
1962
  });
1871
1963
 
1872
1964
  // ../commons/src/events/EventConfigInput.ts
@@ -1875,304 +1967,807 @@ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1875
1967
  var definePage = (page) => PageConfig.parse(page);
1876
1968
  var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1877
1969
 
1878
- // ../commons/src/events/Draft.ts
1879
- var import_zod23 = require("zod");
1970
+ // ../commons/src/events/WorkqueueConfig.ts
1971
+ var import_zod20 = require("zod");
1880
1972
 
1881
- // ../commons/src/events/ActionDocument.ts
1882
- var import_zod21 = require("zod");
1883
- var ActionUpdate = import_zod21.z.record(import_zod21.z.string(), FieldUpdateValue);
1884
- var ActionStatus = {
1885
- Requested: "Requested",
1886
- Accepted: "Accepted",
1887
- Rejected: "Rejected"
1973
+ // ../commons/src/events/EventIndex.ts
1974
+ var import_zod19 = require("zod");
1975
+
1976
+ // ../commons/src/events/EventMetadata.ts
1977
+ var import_zod18 = require("zod");
1978
+ var EventStatus = {
1979
+ CREATED: "CREATED",
1980
+ NOTIFIED: "NOTIFIED",
1981
+ DECLARED: "DECLARED",
1982
+ VALIDATED: "VALIDATED",
1983
+ REGISTERED: "REGISTERED",
1984
+ CERTIFIED: "CERTIFIED",
1985
+ REJECTED: "REJECTED",
1986
+ ARCHIVED: "ARCHIVED"
1888
1987
  };
1889
- var ActionBase = import_zod21.z.object({
1890
- id: import_zod21.z.string(),
1891
- createdAt: import_zod21.z.string().datetime(),
1892
- createdBy: import_zod21.z.string(),
1893
- declaration: ActionUpdate,
1894
- annotation: ActionUpdate.optional(),
1895
- createdAtLocation: import_zod21.z.string(),
1896
- status: import_zod21.z.enum([
1897
- ActionStatus.Requested,
1898
- ActionStatus.Accepted,
1899
- ActionStatus.Rejected
1900
- ]),
1901
- // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1902
- originalActionId: import_zod21.z.string().optional()
1988
+ var CustomFlags = {
1989
+ CERTIFICATE_PRINTED: "certificate-printed"
1990
+ };
1991
+ var Flag = import_zod18.z.string().regex(
1992
+ new RegExp(
1993
+ `^(${Object.values(ActionType).join("|").toLowerCase()}):(${Object.values(ActionStatus).join("|").toLowerCase()})$`
1994
+ ),
1995
+ "Flag must be in the format ActionType:ActionStatus (lowerCase)"
1996
+ ).or(import_zod18.z.nativeEnum(CustomFlags));
1997
+ var eventStatuses = Object.values(EventStatus);
1998
+ var EventStatuses = import_zod18.z.nativeEnum(EventStatus);
1999
+ var ZodDate = import_zod18.z.string().date();
2000
+ var ActionCreationMetadata = import_zod18.z.object({
2001
+ createdAt: import_zod18.z.string().datetime().describe("The timestamp when the action request was created."),
2002
+ createdBy: import_zod18.z.string().describe("ID of the user who created the action request."),
2003
+ createdAtLocation: import_zod18.z.string().describe("Location of the user who created the action request."),
2004
+ acceptedAt: import_zod18.z.string().datetime().describe("Timestamp when the action request was accepted."),
2005
+ createdByRole: import_zod18.z.string().describe("Role of the user at the time of action request creation.")
1903
2006
  });
1904
- var AssignedAction = ActionBase.merge(
1905
- import_zod21.z.object({
1906
- type: import_zod21.z.literal(ActionType.ASSIGN),
1907
- assignedTo: import_zod21.z.string()
1908
- })
1909
- );
1910
- var UnassignedAction = ActionBase.merge(
1911
- import_zod21.z.object({
1912
- type: import_zod21.z.literal(ActionType.UNASSIGN)
1913
- })
1914
- );
1915
- var RegisterAction = ActionBase.merge(
1916
- import_zod21.z.object({
1917
- type: import_zod21.z.literal(ActionType.REGISTER),
1918
- registrationNumber: import_zod21.z.string().optional()
1919
- })
1920
- );
1921
- var DeclareAction = ActionBase.merge(
1922
- import_zod21.z.object({
1923
- type: import_zod21.z.literal(ActionType.DECLARE)
1924
- })
1925
- );
1926
- var ValidateAction = ActionBase.merge(
1927
- import_zod21.z.object({
1928
- type: import_zod21.z.literal(ActionType.VALIDATE)
1929
- })
1930
- );
1931
- var RejectAction = ActionBase.merge(
1932
- import_zod21.z.object({
1933
- type: import_zod21.z.literal(ActionType.REJECT)
1934
- })
1935
- );
1936
- var MarkAsDuplicateAction = ActionBase.merge(
1937
- import_zod21.z.object({
1938
- type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE)
1939
- })
1940
- );
1941
- var ArchiveAction = ActionBase.merge(
1942
- import_zod21.z.object({
1943
- type: import_zod21.z.literal(ActionType.ARCHIVE)
1944
- })
1945
- );
1946
- var CreatedAction = ActionBase.merge(
1947
- import_zod21.z.object({
1948
- type: import_zod21.z.literal(ActionType.CREATE)
1949
- })
1950
- );
1951
- var NotifiedAction = ActionBase.merge(
1952
- import_zod21.z.object({
1953
- type: import_zod21.z.literal(ActionType.NOTIFY)
1954
- })
1955
- );
1956
- var PrintCertificateAction = ActionBase.merge(
1957
- import_zod21.z.object({
1958
- type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE)
1959
- })
1960
- );
1961
- var RequestedCorrectionAction = ActionBase.merge(
1962
- import_zod21.z.object({
1963
- type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION)
1964
- })
1965
- );
1966
- var ApprovedCorrectionAction = ActionBase.merge(
1967
- import_zod21.z.object({
1968
- type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION),
1969
- requestId: import_zod21.z.string()
1970
- })
1971
- );
1972
- var RejectedCorrectionAction = ActionBase.merge(
1973
- import_zod21.z.object({
1974
- type: import_zod21.z.literal(ActionType.REJECT_CORRECTION),
1975
- requestId: import_zod21.z.string()
2007
+ var RegistrationCreationMetadata = ActionCreationMetadata.extend({
2008
+ registrationNumber: import_zod18.z.string().describe(
2009
+ "Registration number of the event. Always present for accepted registrations."
2010
+ )
2011
+ });
2012
+ var LegalStatuses = import_zod18.z.object({
2013
+ [EventStatus.DECLARED]: ActionCreationMetadata.nullish(),
2014
+ [EventStatus.REGISTERED]: RegistrationCreationMetadata.nullish()
2015
+ });
2016
+ var EventMetadata = import_zod18.z.object({
2017
+ id: import_zod18.z.string(),
2018
+ type: import_zod18.z.string().describe("The type of event, such as birth, death, or marriage."),
2019
+ status: EventStatuses,
2020
+ legalStatuses: LegalStatuses.describe(
2021
+ "Metadata related to the legal registration of the event, such as who registered it and when."
2022
+ ),
2023
+ createdAt: import_zod18.z.string().datetime().describe("The timestamp when the event was first created and saved."),
2024
+ dateOfEvent: ZodDate.nullish(),
2025
+ createdBy: import_zod18.z.string().describe("ID of the user who created the event."),
2026
+ updatedByUserRole: import_zod18.z.string().describe("Role of the user who last updated the declaration."),
2027
+ createdAtLocation: import_zod18.z.string().describe("Location of the user who created the event."),
2028
+ updatedAtLocation: import_zod18.z.string().nullish().describe("Location of the user who last updated the declaration."),
2029
+ updatedAt: import_zod18.z.string().datetime().describe("Timestamp of the most recent declaration update."),
2030
+ assignedTo: import_zod18.z.string().nullish().describe("ID of the user currently assigned to the event."),
2031
+ updatedBy: import_zod18.z.string().nullish().describe("ID of the user who last updated the declaration."),
2032
+ trackingId: import_zod18.z.string().describe(
2033
+ "System-generated tracking ID used by informants or registrars to look up the event."
2034
+ ),
2035
+ flags: import_zod18.z.array(Flag)
2036
+ });
2037
+ var EventMetadataKeys = import_zod18.z.enum([
2038
+ "id",
2039
+ "type",
2040
+ "status",
2041
+ "createdAt",
2042
+ "dateOfEvent",
2043
+ "createdBy",
2044
+ "updatedByUserRole",
2045
+ "createdAtLocation",
2046
+ "updatedAtLocation",
2047
+ "updatedAt",
2048
+ "assignedTo",
2049
+ "updatedBy",
2050
+ "trackingId",
2051
+ "legalStatuses",
2052
+ "flags"
2053
+ ]);
2054
+ var EventMetadataParameter = import_zod18.z.object({
2055
+ // @TODO: Reconcile with the event metadata definition. How could we derive one from the other?
2056
+ $event: EventMetadataKeys
2057
+ });
2058
+ var eventMetadataLabelMap = {
2059
+ "event.assignedTo": {
2060
+ id: "event.assignedTo.label",
2061
+ defaultMessage: "Assigned To",
2062
+ description: "Assigned To"
2063
+ },
2064
+ "event.createdAt": {
2065
+ id: "event.createdAt.label",
2066
+ defaultMessage: "Created",
2067
+ description: "Created At"
2068
+ },
2069
+ "event.dateOfEvent": {
2070
+ id: "event.dateOfEvent.label",
2071
+ defaultMessage: "Date of Event",
2072
+ description: "Date of Event"
2073
+ },
2074
+ "event.createdAtLocation": {
2075
+ id: "event.createdAtLocation.label",
2076
+ defaultMessage: "Location",
2077
+ description: "Created At Location"
2078
+ },
2079
+ "event.updatedAtLocation": {
2080
+ id: "event.updatedAtLocation.label",
2081
+ defaultMessage: "Location",
2082
+ description: "Updated At Location"
2083
+ },
2084
+ "event.createdBy": {
2085
+ id: "event.createdBy.label",
2086
+ defaultMessage: "Created By",
2087
+ description: "Created By"
2088
+ },
2089
+ "event.updatedByUserRole": {
2090
+ id: "event.updatedByUserRole.label",
2091
+ defaultMessage: "Updated By Role",
2092
+ description: "Updated By Role"
2093
+ },
2094
+ "event.id": {
2095
+ id: "event.id.label",
2096
+ defaultMessage: "ID",
2097
+ description: "ID"
2098
+ },
2099
+ "event.updatedAt": {
2100
+ id: "event.modifiedAt.label",
2101
+ defaultMessage: "Updated",
2102
+ description: "Modified At"
2103
+ },
2104
+ "event.status": {
2105
+ id: "event.status.label",
2106
+ defaultMessage: "Status",
2107
+ description: "Status"
2108
+ },
2109
+ "event.type": {
2110
+ id: "event.type.label",
2111
+ defaultMessage: "Type",
2112
+ description: "Type"
2113
+ },
2114
+ "event.updatedBy": {
2115
+ id: "event.updatedBy.label",
2116
+ defaultMessage: "Updated By",
2117
+ description: "Updated By"
2118
+ },
2119
+ "event.trackingId": {
2120
+ id: "event.trackingId.label",
2121
+ defaultMessage: "Tracking ID",
2122
+ description: "Tracking ID"
2123
+ },
2124
+ "event.flags": {
2125
+ id: "event.flags.label",
2126
+ defaultMessage: "Flags",
2127
+ description: "Flags"
2128
+ }
2129
+ };
2130
+
2131
+ // ../commons/src/events/EventIndex.ts
2132
+ var EventIndex = EventMetadata.extend({
2133
+ declaration: EventState
2134
+ });
2135
+ var EventSearchIndex = import_zod19.z.record(import_zod19.z.string(), import_zod19.z.any()).and(
2136
+ import_zod19.z.object({
2137
+ type: import_zod19.z.string()
2138
+ // Ensures "type" (event-id) exists and is a string
1976
2139
  })
1977
2140
  );
1978
- var ReadAction = ActionBase.merge(
1979
- import_zod21.z.object({
1980
- type: import_zod21.z.literal(ActionType.READ)
1981
- })
2141
+ var Fuzzy = import_zod19.z.object({ type: import_zod19.z.literal("fuzzy"), term: import_zod19.z.string() });
2142
+ var Exact = import_zod19.z.object({ type: import_zod19.z.literal("exact"), term: import_zod19.z.string() });
2143
+ var AnyOf = import_zod19.z.object({
2144
+ type: import_zod19.z.literal("anyOf"),
2145
+ terms: import_zod19.z.array(import_zod19.z.string())
2146
+ });
2147
+ var Range = import_zod19.z.object({
2148
+ type: import_zod19.z.literal("range"),
2149
+ gte: import_zod19.z.string(),
2150
+ lte: import_zod19.z.string()
2151
+ });
2152
+ var Not = import_zod19.z.object({ type: import_zod19.z.literal("not"), term: import_zod19.z.string() });
2153
+ var Within = import_zod19.z.object({ type: import_zod19.z.literal("within"), location: import_zod19.z.string() });
2154
+ var DateCondition = import_zod19.z.union([Exact, Range]);
2155
+ var QueryInput = import_zod19.z.lazy(
2156
+ () => import_zod19.z.union([
2157
+ import_zod19.z.discriminatedUnion("type", [Fuzzy, Exact, Range, Within, AnyOf, Not]),
2158
+ import_zod19.z.record(import_zod19.z.string(), QueryInput)
2159
+ ])
1982
2160
  );
1983
- var ActionDocument = import_zod21.z.discriminatedUnion("type", [
1984
- CreatedAction,
1985
- ValidateAction,
1986
- RejectAction,
1987
- MarkAsDuplicateAction,
1988
- ArchiveAction,
1989
- NotifiedAction,
1990
- RegisterAction,
1991
- DeclareAction,
1992
- AssignedAction,
1993
- RequestedCorrectionAction,
1994
- ApprovedCorrectionAction,
1995
- RejectedCorrectionAction,
1996
- UnassignedAction,
1997
- PrintCertificateAction,
1998
- ReadAction
1999
- ]);
2000
- var AsyncRejectActionDocument = ActionBase.omit({
2001
- declaration: true,
2002
- annotation: true,
2003
- createdBy: true,
2004
- createdAtLocation: true
2005
- }).merge(
2006
- import_zod21.z.object({
2007
- type: import_zod21.z.enum(ConfirmableActions),
2008
- status: import_zod21.z.literal(ActionStatus.Rejected)
2161
+ var QueryExpression = import_zod19.z.object({
2162
+ type: import_zod19.z.literal("and"),
2163
+ eventType: import_zod19.z.string(),
2164
+ status: import_zod19.z.optional(import_zod19.z.union([AnyOf, Exact])),
2165
+ createdAt: import_zod19.z.optional(DateCondition),
2166
+ updatedAt: import_zod19.z.optional(DateCondition),
2167
+ createAtLocation: import_zod19.z.optional(import_zod19.z.union([Within, Exact])),
2168
+ updatedAtLocation: import_zod19.z.optional(import_zod19.z.union([Within, Exact])),
2169
+ createdBy: import_zod19.z.optional(Exact),
2170
+ updatedBy: import_zod19.z.optional(Exact),
2171
+ trackingId: import_zod19.z.optional(Exact),
2172
+ flags: import_zod19.z.optional(import_zod19.z.array(import_zod19.z.union([AnyOf, Not]))),
2173
+ data: QueryInput
2174
+ }).partial();
2175
+ var Or2 = import_zod19.z.object({
2176
+ type: import_zod19.z.literal("or"),
2177
+ clauses: import_zod19.z.array(QueryExpression)
2178
+ });
2179
+ var QueryType = import_zod19.z.discriminatedUnion("type", [QueryExpression, Or2]);
2180
+
2181
+ // ../commons/src/conditionals/conditionals.ts
2182
+ function defineConditional(schema) {
2183
+ return schema;
2184
+ }
2185
+ function defineFormConditional(schema) {
2186
+ const schemaWithForm = {
2187
+ type: "object",
2188
+ properties: {
2189
+ $form: schema
2190
+ },
2191
+ required: ["$form"]
2192
+ };
2193
+ return defineConditional(schemaWithForm);
2194
+ }
2195
+ function alwaysTrue() {
2196
+ return {};
2197
+ }
2198
+ function and(...conditions) {
2199
+ return defineConditional({
2200
+ type: "object",
2201
+ allOf: conditions,
2202
+ required: []
2203
+ });
2204
+ }
2205
+ function or(...conditions) {
2206
+ return defineConditional({
2207
+ type: "object",
2208
+ anyOf: conditions,
2209
+ required: []
2210
+ });
2211
+ }
2212
+ function not(condition) {
2213
+ return defineConditional({
2214
+ type: "object",
2215
+ not: condition,
2216
+ required: []
2217
+ });
2218
+ }
2219
+ function never() {
2220
+ return not(alwaysTrue());
2221
+ }
2222
+ var user = {
2223
+ hasScope: (scope) => defineConditional({
2224
+ type: "object",
2225
+ properties: {
2226
+ $user: {
2227
+ type: "object",
2228
+ required: ["scope"],
2229
+ properties: {
2230
+ scope: {
2231
+ type: "array",
2232
+ contains: {
2233
+ type: "string",
2234
+ const: scope
2235
+ }
2236
+ }
2237
+ }
2238
+ }
2239
+ },
2240
+ required: ["$user"]
2009
2241
  })
2010
- );
2011
- var Action = import_zod21.z.union([ActionDocument, AsyncRejectActionDocument]);
2012
- var ResolvedUser = import_zod21.z.object({
2013
- id: import_zod21.z.string(),
2014
- role: import_zod21.z.string(),
2015
- name: import_zod21.z.array(
2016
- import_zod21.z.object({
2017
- use: import_zod21.z.string(),
2018
- given: import_zod21.z.array(import_zod21.z.string()),
2019
- family: import_zod21.z.string()
2242
+ };
2243
+ function createEventConditionals() {
2244
+ return {
2245
+ /**
2246
+ * Checks if the event contains a specific action type.
2247
+ * @param action - The action type to check for.
2248
+ */
2249
+ hasAction: (action) => defineConditional({
2250
+ type: "object",
2251
+ properties: {
2252
+ $event: {
2253
+ type: "object",
2254
+ properties: {
2255
+ actions: {
2256
+ type: "array",
2257
+ contains: {
2258
+ type: "object",
2259
+ properties: {
2260
+ type: {
2261
+ const: action
2262
+ }
2263
+ },
2264
+ required: ["type"]
2265
+ }
2266
+ }
2267
+ },
2268
+ required: ["actions"]
2269
+ }
2270
+ },
2271
+ required: ["$event"]
2020
2272
  })
2021
- )
2273
+ };
2274
+ }
2275
+ function getDateFromNow(days) {
2276
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2277
+ }
2278
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2279
+ return {
2280
+ type: "object",
2281
+ properties: {
2282
+ [fieldId]: {
2283
+ type: "string",
2284
+ format: "date",
2285
+ [clause]: { $data: `1/${comparedFieldId}` }
2286
+ },
2287
+ [comparedFieldId]: { type: "string", format: "date" }
2288
+ },
2289
+ required: [fieldId]
2290
+ };
2291
+ }
2292
+ function isFieldReference(value) {
2293
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2294
+ }
2295
+ function createFieldConditionals(fieldId) {
2296
+ const getDateRange = (date, clause) => ({
2297
+ type: "object",
2298
+ properties: {
2299
+ [fieldId]: {
2300
+ type: "string",
2301
+ format: "date",
2302
+ [clause]: date
2303
+ }
2304
+ },
2305
+ required: [fieldId]
2306
+ });
2307
+ return {
2308
+ isAfter: () => ({
2309
+ days: (days) => ({
2310
+ inPast: () => defineFormConditional(
2311
+ getDateRange(getDateFromNow(days), "formatMinimum")
2312
+ ),
2313
+ inFuture: () => defineFormConditional(
2314
+ getDateRange(getDateFromNow(-days), "formatMinimum")
2315
+ )
2316
+ }),
2317
+ date: (date) => {
2318
+ if (isFieldReference(date)) {
2319
+ const comparedFieldId = date._fieldId;
2320
+ return defineFormConditional(
2321
+ getDateRangeToFieldReference(
2322
+ fieldId,
2323
+ comparedFieldId,
2324
+ "formatMinimum"
2325
+ )
2326
+ );
2327
+ }
2328
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2329
+ },
2330
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2331
+ }),
2332
+ isBefore: () => ({
2333
+ days: (days) => ({
2334
+ inPast: () => defineFormConditional(
2335
+ getDateRange(getDateFromNow(days), "formatMaximum")
2336
+ ),
2337
+ inFuture: () => defineFormConditional(
2338
+ getDateRange(getDateFromNow(-days), "formatMaximum")
2339
+ )
2340
+ }),
2341
+ date: (date) => {
2342
+ if (isFieldReference(date)) {
2343
+ const comparedFieldId = date._fieldId;
2344
+ return defineFormConditional(
2345
+ getDateRangeToFieldReference(
2346
+ fieldId,
2347
+ comparedFieldId,
2348
+ "formatMaximum"
2349
+ )
2350
+ );
2351
+ }
2352
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2353
+ },
2354
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2355
+ }),
2356
+ isEqualTo: (value) => {
2357
+ if (isFieldReference(value)) {
2358
+ const comparedFieldId = value._fieldId;
2359
+ return defineFormConditional({
2360
+ type: "object",
2361
+ properties: {
2362
+ [fieldId]: {
2363
+ type: ["string", "boolean"],
2364
+ const: { $data: `1/${comparedFieldId}` }
2365
+ },
2366
+ [comparedFieldId]: { type: ["string", "boolean"] }
2367
+ },
2368
+ required: [fieldId, comparedFieldId]
2369
+ });
2370
+ }
2371
+ return defineFormConditional({
2372
+ type: "object",
2373
+ properties: {
2374
+ [fieldId]: {
2375
+ oneOf: [
2376
+ { type: "string", const: value },
2377
+ { type: "boolean", const: value }
2378
+ ],
2379
+ const: value
2380
+ }
2381
+ },
2382
+ required: [fieldId]
2383
+ });
2384
+ },
2385
+ /**
2386
+ * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
2387
+ * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
2388
+ * @returns whether the field is falsy (undefined, false, null, empty string)
2389
+ *
2390
+ * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2391
+ *
2392
+ */
2393
+ isFalsy: () => defineFormConditional({
2394
+ type: "object",
2395
+ properties: {
2396
+ [fieldId]: {
2397
+ anyOf: [
2398
+ { const: "undefined" },
2399
+ { const: false },
2400
+ { const: null },
2401
+ { const: "" }
2402
+ ]
2403
+ }
2404
+ },
2405
+ anyOf: [
2406
+ {
2407
+ required: [fieldId]
2408
+ },
2409
+ {
2410
+ not: {
2411
+ required: [fieldId]
2412
+ }
2413
+ }
2414
+ ]
2415
+ }),
2416
+ isUndefined: () => defineFormConditional({
2417
+ type: "object",
2418
+ properties: {
2419
+ [fieldId]: {
2420
+ type: "string",
2421
+ enum: ["undefined"]
2422
+ }
2423
+ },
2424
+ not: {
2425
+ required: [fieldId]
2426
+ }
2427
+ }),
2428
+ inArray: (values) => defineFormConditional({
2429
+ type: "object",
2430
+ properties: {
2431
+ [fieldId]: {
2432
+ type: "string",
2433
+ enum: values
2434
+ }
2435
+ },
2436
+ required: [fieldId]
2437
+ }),
2438
+ isValidEnglishName: () => defineFormConditional({
2439
+ type: "object",
2440
+ properties: {
2441
+ [fieldId]: {
2442
+ type: "string",
2443
+ 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'._-]*)*$",
2444
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2445
+ }
2446
+ },
2447
+ required: [fieldId]
2448
+ }),
2449
+ /**
2450
+ * Checks if the field value matches a given regular expression pattern.
2451
+ * @param pattern - The regular expression pattern to match the field value against.
2452
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2453
+ */
2454
+ matches: (pattern) => defineFormConditional({
2455
+ type: "object",
2456
+ properties: {
2457
+ [fieldId]: {
2458
+ type: "string",
2459
+ pattern
2460
+ }
2461
+ },
2462
+ required: [fieldId]
2463
+ }),
2464
+ isBetween: (min, max) => defineFormConditional({
2465
+ type: "object",
2466
+ properties: {
2467
+ [fieldId]: {
2468
+ type: "number",
2469
+ minimum: min,
2470
+ maximum: max
2471
+ }
2472
+ },
2473
+ required: [fieldId]
2474
+ }),
2475
+ getId: () => ({ fieldId })
2476
+ };
2477
+ }
2478
+
2479
+ // ../commons/src/event-config/event-configuration.ts
2480
+ function createEventFieldConfig(fieldId, options) {
2481
+ return {
2482
+ fieldId,
2483
+ options,
2484
+ config: { type: "exact" },
2485
+ fieldType: "event"
2486
+ };
2487
+ }
2488
+
2489
+ // ../commons/src/events/event.ts
2490
+ function eventFn(fieldId, options) {
2491
+ return createEventFieldConfig(fieldId, options);
2492
+ }
2493
+ var event = Object.assign(eventFn, {
2494
+ ...createEventConditionals(),
2495
+ field(field2) {
2496
+ return {
2497
+ $event: field2
2498
+ };
2499
+ }
2022
2500
  });
2023
2501
 
2024
- // ../commons/src/events/ActionInput.ts
2502
+ // ../commons/src/events/WorkqueueConfig.ts
2503
+ var WorkqueueConfig = import_zod20.z.object({
2504
+ slug: import_zod20.z.string().describe("Determines the url of the workqueue."),
2505
+ name: TranslationConfig.describe(
2506
+ "Title of the workflow (both in navigation and on the page)"
2507
+ ),
2508
+ query: QueryType,
2509
+ actions: import_zod20.z.array(
2510
+ import_zod20.z.object({
2511
+ type: import_zod20.z.string(),
2512
+ conditionals: import_zod20.z.array(Conditional).optional()
2513
+ })
2514
+ ),
2515
+ columns: import_zod20.z.array(
2516
+ import_zod20.z.object({ label: TranslationConfig, value: EventMetadataParameter })
2517
+ ).default([
2518
+ {
2519
+ label: {
2520
+ id: "workqueues.dateOfEvent",
2521
+ defaultMessage: "Date of Event",
2522
+ description: "Label for workqueue column: dateOfEvent"
2523
+ },
2524
+ value: event.field("dateOfEvent")
2525
+ }
2526
+ ])
2527
+ }).describe("Configuration for workqueue.");
2528
+ function defineWorkqueue(workqueues) {
2529
+ return workqueues.map((workqueue) => WorkqueueConfig.parse(workqueue));
2530
+ }
2531
+
2532
+ // ../commons/src/events/Draft.ts
2025
2533
  var import_zod22 = require("zod");
2026
- var BaseActionInput = import_zod22.z.object({
2027
- eventId: import_zod22.z.string(),
2028
- transactionId: import_zod22.z.string(),
2534
+
2535
+ // ../commons/src/events/ActionInput.ts
2536
+ var import_zod21 = require("zod");
2537
+ var import_zod_openapi5 = require("zod-openapi");
2538
+ (0, import_zod_openapi5.extendZodWithOpenApi)(import_zod21.z);
2539
+ var BaseActionInput = import_zod21.z.object({
2540
+ eventId: import_zod21.z.string(),
2541
+ transactionId: import_zod21.z.string(),
2029
2542
  declaration: ActionUpdate.default({}),
2030
2543
  annotation: ActionUpdate.optional(),
2031
- originalActionId: import_zod22.z.string().optional()
2544
+ originalActionId: import_zod21.z.string().optional(),
2545
+ keepAssignment: import_zod21.z.boolean().optional()
2032
2546
  });
2033
2547
  var CreateActionInput = BaseActionInput.merge(
2034
- import_zod22.z.object({
2035
- type: import_zod22.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2036
- createdAtLocation: import_zod22.z.string()
2548
+ import_zod21.z.object({
2549
+ type: import_zod21.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2550
+ createdAtLocation: import_zod21.z.string()
2037
2551
  })
2038
2552
  );
2039
2553
  var RegisterActionInput = BaseActionInput.merge(
2040
- import_zod22.z.object({
2041
- type: import_zod22.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2042
- registrationNumber: import_zod22.z.string().optional()
2554
+ import_zod21.z.object({
2555
+ type: import_zod21.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2556
+ registrationNumber: import_zod21.z.string().optional()
2043
2557
  })
2044
2558
  );
2045
2559
  var ValidateActionInput = BaseActionInput.merge(
2046
- import_zod22.z.object({
2047
- type: import_zod22.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2048
- duplicates: import_zod22.z.array(import_zod22.z.string())
2560
+ import_zod21.z.object({
2561
+ type: import_zod21.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2562
+ duplicates: import_zod21.z.array(import_zod21.z.string())
2049
2563
  })
2050
2564
  );
2051
2565
  var NotifyActionInput = BaseActionInput.merge(
2052
- import_zod22.z.object({
2053
- type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2566
+ import_zod21.z.object({
2567
+ type: import_zod21.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2054
2568
  })
2055
2569
  );
2056
2570
  var DeclareActionInput = BaseActionInput.merge(
2057
- import_zod22.z.object({
2058
- type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2571
+ import_zod21.z.object({
2572
+ type: import_zod21.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2059
2573
  })
2060
2574
  );
2061
2575
  var PrintCertificateActionInput = BaseActionInput.merge(
2062
- import_zod22.z.object({
2063
- type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2576
+ import_zod21.z.object({
2577
+ type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2064
2578
  })
2065
2579
  );
2066
2580
  var RejectDeclarationActionInput = BaseActionInput.merge(
2067
- import_zod22.z.object({
2068
- type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2581
+ import_zod21.z.object({
2582
+ type: import_zod21.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2069
2583
  })
2070
2584
  );
2071
2585
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
2072
- import_zod22.z.object({
2073
- type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2586
+ import_zod21.z.object({
2587
+ type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2074
2588
  })
2075
2589
  );
2076
2590
  var ArchiveActionInput = BaseActionInput.merge(
2077
- import_zod22.z.object({
2078
- type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2591
+ import_zod21.z.object({
2592
+ type: import_zod21.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2079
2593
  })
2080
2594
  );
2081
2595
  var AssignActionInput = BaseActionInput.merge(
2082
- import_zod22.z.object({
2083
- type: import_zod22.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2084
- assignedTo: import_zod22.z.string()
2596
+ import_zod21.z.object({
2597
+ type: import_zod21.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2598
+ assignedTo: import_zod21.z.string()
2085
2599
  })
2086
2600
  );
2087
2601
  var UnassignActionInput = BaseActionInput.merge(
2088
- import_zod22.z.object({
2089
- type: import_zod22.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2090
- assignedTo: import_zod22.z.literal(null).default(null)
2602
+ import_zod21.z.object({
2603
+ type: import_zod21.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2604
+ assignedTo: import_zod21.z.literal(null).default(null)
2091
2605
  })
2092
2606
  );
2093
2607
  var RequestCorrectionActionInput = BaseActionInput.merge(
2094
- import_zod22.z.object({
2095
- type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2608
+ import_zod21.z.object({
2609
+ type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2096
2610
  })
2097
2611
  );
2098
2612
  var RejectCorrectionActionInput = BaseActionInput.merge(
2099
- import_zod22.z.object({
2100
- requestId: import_zod22.z.string(),
2101
- type: import_zod22.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2613
+ import_zod21.z.object({
2614
+ requestId: import_zod21.z.string(),
2615
+ type: import_zod21.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2102
2616
  })
2103
2617
  );
2104
2618
  var ApproveCorrectionActionInput = BaseActionInput.merge(
2105
- import_zod22.z.object({
2106
- requestId: import_zod22.z.string(),
2107
- type: import_zod22.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2619
+ import_zod21.z.object({
2620
+ requestId: import_zod21.z.string(),
2621
+ type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2108
2622
  })
2109
2623
  );
2110
2624
  var ReadActionInput = BaseActionInput.merge(
2111
- import_zod22.z.object({
2112
- type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
2625
+ import_zod21.z.object({
2626
+ type: import_zod21.z.literal(ActionType.READ).default(ActionType.READ)
2113
2627
  })
2114
2628
  );
2115
- var ActionInput = import_zod22.z.discriminatedUnion("type", [
2116
- CreateActionInput,
2117
- ValidateActionInput,
2118
- RegisterActionInput,
2119
- NotifyActionInput,
2120
- DeclareActionInput,
2121
- RejectDeclarationActionInput,
2122
- MarkedAsDuplicateActionInput,
2123
- ArchiveActionInput,
2124
- AssignActionInput,
2125
- UnassignActionInput,
2126
- PrintCertificateActionInput,
2127
- RequestCorrectionActionInput,
2128
- RejectCorrectionActionInput,
2129
- ApproveCorrectionActionInput,
2130
- ReadActionInput
2131
- ]);
2629
+ var DeleteActionInput = import_zod21.z.object({ eventId: import_zod21.z.string() });
2630
+ var ActionInput = import_zod21.z.discriminatedUnion("type", [
2631
+ CreateActionInput.openapi({ ref: "CreateActionInput" }),
2632
+ ValidateActionInput.openapi({ ref: "ValidateActionInput" }),
2633
+ RegisterActionInput.openapi({ ref: "RegisterActionInput" }),
2634
+ NotifyActionInput.openapi({ ref: "NotifyActionInput" }),
2635
+ DeclareActionInput.openapi({ ref: "DeclareActionInput" }),
2636
+ RejectDeclarationActionInput.openapi({
2637
+ ref: "RejectDeclarationActionInput"
2638
+ }),
2639
+ MarkedAsDuplicateActionInput.openapi({
2640
+ ref: "MarkedAsDuplicateActionInput"
2641
+ }),
2642
+ ArchiveActionInput.openapi({ ref: "ArchiveActionInput" }),
2643
+ AssignActionInput.openapi({ ref: "AssignActionInput" }),
2644
+ UnassignActionInput.openapi({ ref: "UnassignActionInput" }),
2645
+ PrintCertificateActionInput.openapi({ ref: "PrintCertificateActionInput" }),
2646
+ RequestCorrectionActionInput.openapi({
2647
+ ref: "RequestCorrectionActionInput"
2648
+ }),
2649
+ RejectCorrectionActionInput.openapi({ ref: "RejectCorrectionActionInput" }),
2650
+ ApproveCorrectionActionInput.openapi({
2651
+ ref: "ApproveCorrectionActionInput"
2652
+ }),
2653
+ ReadActionInput.openapi({ ref: "ReadActionInput" })
2654
+ ]).openapi({
2655
+ ref: "ActionInput"
2656
+ });
2132
2657
 
2133
2658
  // ../commons/src/events/Draft.ts
2134
- var Draft = import_zod23.z.object({
2135
- id: import_zod23.z.string(),
2136
- eventId: import_zod23.z.string(),
2137
- transactionId: import_zod23.z.string(),
2138
- createdAt: import_zod23.z.string().datetime(),
2659
+ var Draft = import_zod22.z.object({
2660
+ id: import_zod22.z.string(),
2661
+ eventId: import_zod22.z.string(),
2662
+ transactionId: import_zod22.z.string(),
2663
+ createdAt: import_zod22.z.string().datetime(),
2139
2664
  action: ActionBase.extend({
2140
2665
  type: ActionTypes
2141
2666
  }).omit({ id: true })
2142
2667
  });
2143
2668
  var DraftInput = BaseActionInput.extend({
2144
- type: ActionTypes
2669
+ type: ActionTypes,
2670
+ status: import_zod22.z.enum([
2671
+ ActionStatus.Requested,
2672
+ ActionStatus.Accepted,
2673
+ ActionStatus.Rejected
2674
+ ])
2145
2675
  });
2146
2676
 
2147
2677
  // ../commons/src/events/EventInput.ts
2148
- var import_zod24 = require("zod");
2149
- var EventInput = import_zod24.z.object({
2150
- transactionId: import_zod24.z.string(),
2151
- type: import_zod24.z.string()
2678
+ var import_zod23 = require("zod");
2679
+ var EventInput = import_zod23.z.object({
2680
+ transactionId: import_zod23.z.string(),
2681
+ type: import_zod23.z.string(),
2682
+ dateOfEvent: import_zod23.z.object({ fieldId: import_zod23.z.string() }).optional()
2152
2683
  });
2153
2684
 
2154
2685
  // ../commons/src/events/EventDocument.ts
2155
- var import_zod25 = require("zod");
2156
- var EventDocument = import_zod25.z.object({
2157
- id: import_zod25.z.string(),
2158
- type: import_zod25.z.string(),
2159
- createdAt: import_zod25.z.string().datetime(),
2160
- updatedAt: import_zod25.z.string().datetime(),
2161
- actions: import_zod25.z.array(Action),
2162
- trackingId: import_zod25.z.string()
2163
- });
2686
+ var import_zod24 = require("zod");
2687
+ var import_zod_openapi6 = require("zod-openapi");
2688
+ (0, import_zod_openapi6.extendZodWithOpenApi)(import_zod24.z);
2689
+ var EventDocument = import_zod24.z.object({
2690
+ id: import_zod24.z.string(),
2691
+ type: import_zod24.z.string(),
2692
+ dateOfEvent: import_zod24.z.object({ fieldId: import_zod24.z.string() }).optional(),
2693
+ createdAt: import_zod24.z.string().datetime(),
2694
+ updatedAt: import_zod24.z.string().datetime(),
2695
+ actions: import_zod24.z.array(Action),
2696
+ trackingId: import_zod24.z.string()
2697
+ }).openapi({ ref: "EventDocument" });
2164
2698
 
2165
- // ../commons/src/events/EventIndex.ts
2166
- var import_zod26 = require("zod");
2167
- var EventIndex = EventMetadata.extend({
2168
- declaration: import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any())
2169
- });
2170
- var EventSearchIndex = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any()).and(
2171
- import_zod26.z.object({
2172
- type: import_zod26.z.string()
2173
- // Ensures "type" (event-id) exists and is a string
2174
- })
2175
- );
2699
+ // ../commons/src/events/state/utils.ts
2700
+ function getActionRequests(actionType, actions) {
2701
+ const filtered = actions.filter((action) => action.type === actionType);
2702
+ const accept = filtered.find(
2703
+ (action) => action.status === ActionStatus.Accepted
2704
+ );
2705
+ const request = filtered.find(
2706
+ (action) => action.status === ActionStatus.Requested
2707
+ );
2708
+ const reject = filtered.find(
2709
+ (action) => action.status === ActionStatus.Rejected
2710
+ );
2711
+ return {
2712
+ reject,
2713
+ accept,
2714
+ request
2715
+ };
2716
+ }
2717
+ function getDeclarationActionCreationMetadata(actionType, actions) {
2718
+ const { accept: acceptAction, request: requestAction } = getActionRequests(
2719
+ actionType,
2720
+ actions
2721
+ );
2722
+ if (!acceptAction) {
2723
+ return null;
2724
+ }
2725
+ const registrationNumber = acceptAction.type === ActionType.REGISTER ? acceptAction.registrationNumber : null;
2726
+ return {
2727
+ // When 3rd party API returns 200 OK, we assume that the request was accepted, and persist single 'accepted' action.
2728
+ createdAt: requestAction?.createdAt ?? acceptAction.createdAt,
2729
+ createdBy: requestAction?.createdBy ?? acceptAction.createdBy,
2730
+ createdAtLocation: requestAction?.createdAtLocation ?? acceptAction.createdAtLocation,
2731
+ acceptedAt: acceptAction.createdAt,
2732
+ createdByRole: requestAction?.createdByRole ?? acceptAction.createdByRole,
2733
+ registrationNumber
2734
+ };
2735
+ }
2736
+ function getDeclarationActionUpdateMetadata(actions) {
2737
+ const createAction = getOrThrow(
2738
+ actions.find((action) => action.type === ActionType.CREATE),
2739
+ `Event has no ${ActionType.CREATE} action`
2740
+ );
2741
+ return [ActionType.DECLARE, ActionType.VALIDATE, ActionType.REGISTER].reduce(
2742
+ (metadata, actionType) => {
2743
+ const { accept, request } = getActionRequests(actionType, actions);
2744
+ return {
2745
+ createdAt: request?.createdAt ?? accept?.createdAt ?? metadata.createdAt,
2746
+ createdBy: request?.createdBy ?? accept?.createdBy ?? metadata.createdBy,
2747
+ createdAtLocation: request?.createdAtLocation ?? accept?.createdAtLocation ?? metadata.createdAtLocation,
2748
+ createdByRole: request?.createdByRole ?? accept?.createdByRole ?? metadata.createdByRole
2749
+ };
2750
+ },
2751
+ {
2752
+ createdAt: createAction.createdAt,
2753
+ createdBy: createAction.createdBy,
2754
+ createdAtLocation: createAction.createdAtLocation,
2755
+ createdByRole: createAction.createdByRole
2756
+ }
2757
+ );
2758
+ }
2759
+ function getLegalStatuses(actions) {
2760
+ return {
2761
+ [EventStatus.DECLARED]: getDeclarationActionCreationMetadata(
2762
+ ActionType.DECLARE,
2763
+ actions
2764
+ ),
2765
+ [EventStatus.REGISTERED]: getDeclarationActionCreationMetadata(
2766
+ ActionType.REGISTER,
2767
+ actions
2768
+ )
2769
+ };
2770
+ }
2176
2771
 
2177
2772
  // ../commons/src/events/state/index.ts
2178
2773
  function getStatusFromActions(actions) {
@@ -2183,30 +2778,67 @@ function getStatusFromActions(actions) {
2183
2778
  return EventStatus.REJECTED;
2184
2779
  }
2185
2780
  return actions.reduce((status, action) => {
2186
- if (action.type === ActionType.CREATE) {
2187
- return EventStatus.CREATED;
2188
- }
2189
- if (action.type === ActionType.DECLARE) {
2190
- return EventStatus.DECLARED;
2191
- }
2192
- if (action.type === ActionType.VALIDATE) {
2193
- return EventStatus.VALIDATED;
2194
- }
2195
- if (action.type === ActionType.REGISTER) {
2196
- return EventStatus.REGISTERED;
2197
- }
2198
- if (action.type === ActionType.REJECT) {
2199
- return EventStatus.REJECTED;
2200
- }
2201
- if (action.type === ActionType.ARCHIVE) {
2202
- return EventStatus.ARCHIVED;
2203
- }
2204
- if (action.type === ActionType.NOTIFY) {
2205
- return EventStatus.NOTIFIED;
2781
+ switch (action.type) {
2782
+ case ActionType.CREATE:
2783
+ return EventStatus.CREATED;
2784
+ case ActionType.DECLARE:
2785
+ return EventStatus.DECLARED;
2786
+ case ActionType.VALIDATE:
2787
+ return EventStatus.VALIDATED;
2788
+ case ActionType.REGISTER:
2789
+ return EventStatus.REGISTERED;
2790
+ case ActionType.REJECT:
2791
+ return EventStatus.REJECTED;
2792
+ case ActionType.ARCHIVE:
2793
+ return EventStatus.ARCHIVED;
2794
+ case ActionType.NOTIFY:
2795
+ return EventStatus.NOTIFIED;
2796
+ case ActionType.PRINT_CERTIFICATE:
2797
+ return EventStatus.CERTIFIED;
2798
+ case ActionType.ASSIGN:
2799
+ case ActionType.UNASSIGN:
2800
+ case ActionType.REQUEST_CORRECTION:
2801
+ case ActionType.APPROVE_CORRECTION:
2802
+ case ActionType.MARKED_AS_DUPLICATE:
2803
+ case ActionType.REJECT_CORRECTION:
2804
+ case ActionType.READ:
2805
+ default:
2806
+ return status;
2206
2807
  }
2207
- return status;
2208
2808
  }, EventStatus.CREATED);
2209
2809
  }
2810
+ function getFlagsFromActions(actions) {
2811
+ const sortedactions = actions.sort(
2812
+ (a, b) => a.createdAt.localeCompare(b.createdAt)
2813
+ );
2814
+ const actionStatus = sortedactions.reduce(
2815
+ (actionStatuses, { type, status }) => ({
2816
+ ...actionStatuses,
2817
+ [type]: status
2818
+ }),
2819
+ {}
2820
+ );
2821
+ const flags = Object.entries(actionStatus).filter(([, status]) => status !== ActionStatus.Accepted).map(([type, status]) => {
2822
+ const flag = `${type.toLowerCase()}:${status.toLowerCase()}`;
2823
+ return flag;
2824
+ });
2825
+ const isCertificatePrinted = sortedactions.reduce(
2826
+ (prev, { type }) => {
2827
+ if (type === ActionType.PRINT_CERTIFICATE) {
2828
+ return true;
2829
+ }
2830
+ if (type === ActionType.APPROVE_CORRECTION) {
2831
+ return false;
2832
+ }
2833
+ return prev;
2834
+ },
2835
+ false
2836
+ );
2837
+ if (isCertificatePrinted) {
2838
+ flags.push(CustomFlags.CERTIFICATE_PRINTED);
2839
+ }
2840
+ return flags;
2841
+ }
2210
2842
  function getAssignedUserFromActions(actions) {
2211
2843
  return actions.reduce((user2, action) => {
2212
2844
  if (action.type === ActionType.ASSIGN) {
@@ -2261,6 +2893,7 @@ function getAcceptedActions(event2) {
2261
2893
  (a) => a.status === ActionStatus.Accepted
2262
2894
  );
2263
2895
  }
2896
+ var DEFAULT_DATE_OF_EVENT_PROPERTY = "createdAt";
2264
2897
  function getCurrentEventState(event2) {
2265
2898
  const creationAction = event2.actions.find(
2266
2899
  (action) => action.type === ActionType.CREATE
@@ -2268,25 +2901,32 @@ function getCurrentEventState(event2) {
2268
2901
  if (!creationAction) {
2269
2902
  throw new Error(`Event ${event2.id} has no creation action`);
2270
2903
  }
2271
- const activeActions = getAcceptedActions(event2);
2272
- const latestAction = activeActions[activeActions.length - 1];
2273
- const registrationAction = activeActions.find(
2274
- (a) => a.type === ActionType.REGISTER && a.status === ActionStatus.Accepted
2904
+ const acceptedActions = getAcceptedActions(event2);
2905
+ const declarationUpdateMetadata = getDeclarationActionUpdateMetadata(
2906
+ event2.actions
2275
2907
  );
2276
- const registrationNumber = registrationAction?.registrationNumber ?? null;
2908
+ const declaration = aggregateActionDeclarations(acceptedActions);
2909
+ const dateOfEvent = ZodDate.safeParse(
2910
+ event2.dateOfEvent?.fieldId ? declaration[event2.dateOfEvent.fieldId] : event2[DEFAULT_DATE_OF_EVENT_PROPERTY]
2911
+ ).data ?? null;
2277
2912
  return deepDropNulls({
2278
2913
  id: event2.id,
2279
2914
  type: event2.type,
2280
2915
  status: getStatusFromActions(event2.actions),
2281
- createdAt: event2.createdAt,
2916
+ legalStatuses: getLegalStatuses(event2.actions),
2917
+ createdAt: creationAction.createdAt,
2282
2918
  createdBy: creationAction.createdBy,
2283
2919
  createdAtLocation: creationAction.createdAtLocation,
2284
- modifiedAt: latestAction.createdAt,
2285
- assignedTo: getAssignedUserFromActions(activeActions),
2286
- updatedBy: latestAction.createdBy,
2287
- declaration: aggregateActionDeclarations(activeActions),
2920
+ updatedAt: declarationUpdateMetadata.createdAt,
2921
+ assignedTo: getAssignedUserFromActions(acceptedActions),
2922
+ updatedBy: declarationUpdateMetadata.createdBy,
2923
+ updatedAtLocation: declarationUpdateMetadata.createdAtLocation,
2924
+ declaration,
2288
2925
  trackingId: event2.trackingId,
2289
- registrationNumber
2926
+ // @TODO: unify this with rest of the code. It will trip us if updatedBy has different rules than updatedByUserRole
2927
+ updatedByUserRole: declarationUpdateMetadata.createdByRole,
2928
+ dateOfEvent,
2929
+ flags: getFlagsFromActions(event2.actions)
2290
2930
  });
2291
2931
  }
2292
2932
  function getCurrentEventStateWithDrafts(event2, drafts) {
@@ -2311,7 +2951,7 @@ function getCurrentEventStateWithDrafts(event2, drafts) {
2311
2951
  return getCurrentEventState(withDrafts);
2312
2952
  }
2313
2953
  function applyDraftsToEventIndex(eventIndex, drafts) {
2314
- const indexedAt = eventIndex.modifiedAt;
2954
+ const indexedAt = eventIndex.updatedAt;
2315
2955
  const activeDrafts = drafts.filter(({ createdAt }) => new Date(createdAt) > new Date(indexedAt)).map((draft) => draft.action).sort();
2316
2956
  if (activeDrafts.length === 0) {
2317
2957
  return eventIndex;
@@ -2334,7 +2974,7 @@ function getAnnotationFromDrafts(drafts) {
2334
2974
  function getActionAnnotation({
2335
2975
  event: event2,
2336
2976
  actionType,
2337
- drafts
2977
+ drafts = []
2338
2978
  }) {
2339
2979
  const activeActions = getAcceptedActions(event2);
2340
2980
  const action = activeActions.find(
@@ -2353,7 +2993,6 @@ function getActionAnnotation({
2353
2993
 
2354
2994
  // ../commons/src/events/defineConfig.ts
2355
2995
  var defineConfig = (config) => {
2356
- validateWorkqueueConfig(config.workqueues);
2357
2996
  const input = EventConfig.parse(config);
2358
2997
  return input;
2359
2998
  };
@@ -2363,304 +3002,72 @@ function generateTransactionId() {
2363
3002
  return getUUID();
2364
3003
  }
2365
3004
 
2366
- // ../commons/src/events/test.utils.ts
2367
- var import_lodash2 = require("lodash");
2368
-
2369
- // ../commons/src/conditionals/conditionals.ts
2370
- function defineConditional(schema) {
2371
- return schema;
2372
- }
2373
- function defineFormConditional(schema) {
2374
- const schemaWithForm = {
2375
- type: "object",
2376
- properties: {
2377
- $form: schema
2378
- },
2379
- required: ["$form"]
2380
- };
2381
- return defineConditional(schemaWithForm);
2382
- }
2383
- function alwaysTrue() {
2384
- return {};
2385
- }
2386
- function and(...conditions) {
2387
- return defineConditional({
2388
- type: "object",
2389
- allOf: conditions,
2390
- required: []
2391
- });
2392
- }
2393
- function or(...conditions) {
2394
- return defineConditional({
2395
- type: "object",
2396
- anyOf: conditions,
2397
- required: []
2398
- });
2399
- }
2400
- function not(condition) {
2401
- return defineConditional({
2402
- type: "object",
2403
- not: condition,
2404
- required: []
2405
- });
2406
- }
2407
- function never() {
2408
- return not(alwaysTrue());
2409
- }
2410
- var user = {
2411
- hasScope: (scope) => defineConditional({
2412
- type: "object",
2413
- properties: {
2414
- $user: {
2415
- type: "object",
2416
- required: ["scope"],
2417
- properties: {
2418
- scope: {
2419
- type: "array",
2420
- contains: {
2421
- type: "string",
2422
- const: scope
2423
- }
2424
- }
2425
- }
2426
- }
2427
- },
2428
- required: ["$user"]
2429
- })
2430
- };
2431
- var event = {
2432
- hasAction: (action) => defineConditional({
2433
- type: "object",
2434
- properties: {
2435
- $event: {
2436
- type: "object",
2437
- properties: {
2438
- actions: {
2439
- type: "array",
2440
- contains: {
2441
- type: "object",
2442
- properties: {
2443
- type: {
2444
- const: action
2445
- }
2446
- },
2447
- required: ["type"]
2448
- }
2449
- }
2450
- },
2451
- required: ["actions"]
2452
- }
2453
- },
2454
- required: ["$event"]
2455
- })
2456
- };
2457
- function getDateFromNow(days) {
2458
- return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2459
- }
2460
- function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2461
- return {
2462
- type: "object",
2463
- properties: {
2464
- [fieldId]: {
2465
- type: "string",
2466
- format: "date",
2467
- [clause]: { $data: `1/${comparedFieldId}` }
2468
- },
2469
- [comparedFieldId]: { type: "string", format: "date" }
2470
- },
2471
- required: [fieldId]
2472
- };
2473
- }
2474
- function isFieldReference(value) {
2475
- return typeof value === "object" && value !== null && "_fieldId" in value;
2476
- }
2477
- function field(fieldId) {
2478
- const getDateRange = (date, clause) => ({
2479
- type: "object",
2480
- properties: {
2481
- [fieldId]: {
2482
- type: "string",
2483
- format: "date",
2484
- [clause]: date
2485
- }
2486
- },
2487
- required: [fieldId]
2488
- });
3005
+ // ../commons/src/events/test.utils.ts
3006
+ var import_lodash2 = require("lodash");
3007
+
3008
+ // ../commons/src/field-config/field-configuration.ts
3009
+ function createFieldConfigs(fieldId) {
3010
+ const baseField = {
3011
+ fieldId,
3012
+ fieldType: "field"
3013
+ };
2489
3014
  return {
2490
3015
  /**
2491
- * @private Internal property used for field reference tracking.
2492
- */
2493
- _fieldId: fieldId,
2494
- isAfter: () => ({
2495
- days: (days) => ({
2496
- inPast: () => defineFormConditional(
2497
- getDateRange(getDateFromNow(days), "formatMinimum")
2498
- ),
2499
- inFuture: () => defineFormConditional(
2500
- getDateRange(getDateFromNow(-days), "formatMinimum")
2501
- )
2502
- }),
2503
- date: (date) => {
2504
- if (isFieldReference(date)) {
2505
- const comparedFieldId = date._fieldId;
2506
- return defineFormConditional(
2507
- getDateRangeToFieldReference(
2508
- fieldId,
2509
- comparedFieldId,
2510
- "formatMinimum"
2511
- )
2512
- );
2513
- }
2514
- return defineFormConditional(getDateRange(date, "formatMinimum"));
2515
- },
2516
- now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2517
- }),
2518
- isBefore: () => ({
2519
- days: (days) => ({
2520
- inPast: () => defineFormConditional(
2521
- getDateRange(getDateFromNow(days), "formatMaximum")
2522
- ),
2523
- inFuture: () => defineFormConditional(
2524
- getDateRange(getDateFromNow(-days), "formatMaximum")
2525
- )
2526
- }),
2527
- date: (date) => {
2528
- if (isFieldReference(date)) {
2529
- const comparedFieldId = date._fieldId;
2530
- return defineFormConditional(
2531
- getDateRangeToFieldReference(
2532
- fieldId,
2533
- comparedFieldId,
2534
- "formatMaximum"
2535
- )
2536
- );
2537
- }
2538
- return defineFormConditional(getDateRange(date, "formatMaximum"));
2539
- },
2540
- now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2541
- }),
2542
- isEqualTo: (value) => {
2543
- if (isFieldReference(value)) {
2544
- const comparedFieldId = value._fieldId;
2545
- return defineFormConditional({
2546
- type: "object",
2547
- properties: {
2548
- [fieldId]: {
2549
- type: ["string", "boolean"],
2550
- const: { $data: `1/${comparedFieldId}` }
2551
- },
2552
- [comparedFieldId]: { type: ["string", "boolean"] }
2553
- },
2554
- required: [fieldId, comparedFieldId]
2555
- });
2556
- }
2557
- return defineFormConditional({
2558
- type: "object",
2559
- properties: {
2560
- [fieldId]: {
2561
- oneOf: [
2562
- { type: "string", const: value },
2563
- { type: "boolean", const: value }
2564
- ],
2565
- const: value
2566
- }
2567
- },
2568
- required: [fieldId]
2569
- });
2570
- },
2571
- /**
2572
- * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
2573
- * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
2574
- * @returns whether the field is falsy (undefined, false, null, empty string)
3016
+ * Creates a range configuration for the specified field.
2575
3017
  *
2576
- * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
3018
+ * @returns An object containing the field ID and a configuration object with a type of 'range'.
2577
3019
  *
3020
+ * @example field('age').range()
3021
+ * // {
3022
+ * // fieldId: 'age',
3023
+ * // config: { type: 'range' }
3024
+ * // }
2578
3025
  */
2579
- isFalsy: () => defineFormConditional({
2580
- type: "object",
2581
- properties: {
2582
- [fieldId]: {
2583
- anyOf: [
2584
- { const: "undefined" },
2585
- { const: false },
2586
- { const: null },
2587
- { const: "" }
2588
- ]
2589
- }
2590
- },
2591
- anyOf: [
2592
- {
2593
- required: [fieldId]
2594
- },
2595
- {
2596
- not: {
2597
- required: [fieldId]
2598
- }
2599
- }
2600
- ]
2601
- }),
2602
- isUndefined: () => defineFormConditional({
2603
- type: "object",
2604
- properties: {
2605
- [fieldId]: {
2606
- type: "string",
2607
- enum: ["undefined"]
2608
- }
2609
- },
2610
- not: {
2611
- required: [fieldId]
2612
- }
2613
- }),
2614
- inArray: (values) => defineFormConditional({
2615
- type: "object",
2616
- properties: {
2617
- [fieldId]: {
2618
- type: "string",
2619
- enum: values
2620
- }
2621
- },
2622
- required: [fieldId]
2623
- }),
2624
- isValidEnglishName: () => defineFormConditional({
2625
- type: "object",
2626
- properties: {
2627
- [fieldId]: {
2628
- type: "string",
2629
- pattern: "^[\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*( [\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*)*$",
2630
- description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2631
- }
2632
- },
2633
- required: [fieldId]
3026
+ range: () => ({
3027
+ ...baseField,
3028
+ config: { type: "range" }
2634
3029
  }),
2635
3030
  /**
2636
- * Checks if the field value matches a given regular expression pattern.
2637
- * @param pattern - The regular expression pattern to match the field value against.
2638
- * @returns A JSONSchema conditional that validates the field value against the pattern.
3031
+ * Creates a configuration for exact matching of the specified field.
3032
+ * @returns An object containing the field ID and a configuration object with a type of 'exact'.
3033
+ * @example field('dob').exact()
3034
+ * // {
3035
+ * // fieldId: 'dob',
3036
+ * // config: { type: 'exact' }
3037
+ * // }
2639
3038
  */
2640
- matches: (pattern) => defineFormConditional({
2641
- type: "object",
2642
- properties: {
2643
- [fieldId]: {
2644
- type: "string",
2645
- pattern
2646
- }
2647
- },
2648
- required: [fieldId]
3039
+ exact: () => ({
3040
+ ...baseField,
3041
+ config: { type: "exact" }
2649
3042
  }),
2650
- isBetween: (min, max) => defineFormConditional({
2651
- type: "object",
2652
- properties: {
2653
- [fieldId]: {
2654
- type: "number",
2655
- minimum: min,
2656
- maximum: max
2657
- }
2658
- },
2659
- required: [fieldId]
3043
+ /**
3044
+ * Creates a configuration for fuzzy matching of the specified field.
3045
+ * @returns An object containing the field ID and a configuration object with a type of 'exact'.
3046
+ * @example field('name').fuzzy()
3047
+ * // {
3048
+ * // fieldId: 'name',
3049
+ * // config: { type: 'fuzzy' }
3050
+ * // }
3051
+ */
3052
+ fuzzy: () => ({
3053
+ ...baseField,
3054
+ config: { type: "fuzzy" }
2660
3055
  })
2661
3056
  };
2662
3057
  }
2663
3058
 
3059
+ // ../commons/src/events/field.ts
3060
+ function field(fieldId) {
3061
+ return {
3062
+ /**
3063
+ * @private Internal property used for field reference tracking.
3064
+ */
3065
+ _fieldId: fieldId,
3066
+ ...createFieldConditionals(fieldId),
3067
+ ...createFieldConfigs(fieldId)
3068
+ };
3069
+ }
3070
+
2664
3071
  // ../commons/src/fixtures/tennis-club-membership-event.ts
2665
3072
  var PRINT_CERTIFICATE_FORM = defineActionForm({
2666
3073
  label: {
@@ -3577,20 +3984,12 @@ var tennisClubMembershipEvent = defineConfig({
3577
3984
  description: "This is what this event is referred as in the system",
3578
3985
  id: "event.tennis-club-membership.label"
3579
3986
  },
3987
+ title: {
3988
+ defaultMessage: "{applicant.firstname} {applicant.surname}",
3989
+ description: "This is the title of the summary",
3990
+ id: "v2.event.tennis-club-membership.title"
3991
+ },
3580
3992
  summary: {
3581
- title: {
3582
- id: "event.tennis-club-membership.summary.title",
3583
- label: {
3584
- defaultMessage: "{applicant.firstname} {applicant.surname}",
3585
- description: "This is the title of the summary",
3586
- id: "v2.event.tennis-club-membership.summary.title"
3587
- },
3588
- emptyValueMessage: {
3589
- defaultMessage: "Membership application",
3590
- description: "This is the message shown when the applicant name is missing",
3591
- id: "event.tennis-club-membership.summary.title.empty"
3592
- }
3593
- },
3594
3993
  fields: [
3595
3994
  {
3596
3995
  id: "applicant.firstname",
@@ -3611,47 +4010,18 @@ var tennisClubMembershipEvent = defineConfig({
3611
4010
  }
3612
4011
  },
3613
4012
  {
3614
- id: "applicant.surname",
4013
+ fieldId: "applicant.surname",
3615
4014
  label: {
3616
4015
  defaultMessage: "Applicant's last name",
3617
- description: "This is the label for the field",
3618
- id: "event.tennis-club-membership.summary.field.surname.label"
3619
- },
3620
- value: {
3621
- defaultMessage: "{applicant.surname}",
3622
- description: "This is the value to show in the summary",
3623
- id: "event.tennis-club-membership.summary.field.surname"
3624
- },
3625
- emptyValueMessage: {
3626
- defaultMessage: "Last name is not provided",
3627
- description: "This is the message to show when the field is empty",
3628
- id: "event.tennis-club-membership.summary.field.surname.empty"
4016
+ description: "Label for surname",
4017
+ id: "v2.event.tennis-club-membership.summary.field.surname.label"
3629
4018
  }
4019
+ },
4020
+ {
4021
+ fieldId: "applicant.email"
3630
4022
  }
3631
4023
  ]
3632
4024
  },
3633
- workqueues: [
3634
- {
3635
- id: "all",
3636
- filters: []
3637
- },
3638
- {
3639
- id: "ready-for-review",
3640
- filters: [
3641
- {
3642
- status: ["DECLARED"]
3643
- }
3644
- ]
3645
- },
3646
- {
3647
- id: "registered",
3648
- filters: [
3649
- {
3650
- status: ["REGISTERED"]
3651
- }
3652
- ]
3653
- }
3654
- ],
3655
4025
  actions: [
3656
4026
  {
3657
4027
  type: ActionType.DECLARE,
@@ -3959,11 +4329,7 @@ var tennisClubMembershipEvent = defineConfig({
3959
4329
  description: "This is what this event is referred as in the system",
3960
4330
  id: "v2.event.tennis-club-membership.search"
3961
4331
  },
3962
- fields: [
3963
- {
3964
- fieldId: "applicant.dob"
3965
- }
3966
- ]
4332
+ fields: [field("applicant.dob").exact()]
3967
4333
  }
3968
4334
  ],
3969
4335
  declaration: TENNIS_CLUB_DECLARATION_FORM
@@ -3996,10 +4362,10 @@ function generateActionAnnotationInput(configuration, action) {
3996
4362
  );
3997
4363
  const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
3998
4364
  const annotation = fieldConfigsToActionPayload(annotationFields);
3999
- const visibleVerificationPageIds = findRecordActionPages(
4000
- configuration,
4001
- action
4002
- ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
4365
+ const visibleVerificationPageIds = getVisibleVerificationPageIds(
4366
+ findRecordActionPages(configuration, action),
4367
+ annotation
4368
+ );
4003
4369
  const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
4004
4370
  (acc, pageId) => ({
4005
4371
  ...acc,
@@ -4030,6 +4396,7 @@ var eventPayloadGenerator = {
4030
4396
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4031
4397
  transactionId: getUUID(),
4032
4398
  action: {
4399
+ transactionId: getUUID(),
4033
4400
  type: actionType,
4034
4401
  status: ActionStatus.Accepted,
4035
4402
  declaration: {
@@ -4044,6 +4411,7 @@ var eventPayloadGenerator = {
4044
4411
  },
4045
4412
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4046
4413
  createdBy: "@todo",
4414
+ createdByRole: "@todo",
4047
4415
  createdAtLocation: "@todo"
4048
4416
  }
4049
4417
  },
@@ -4205,12 +4573,14 @@ function generateActionDocument({
4205
4573
  // @TODO: This should be fixed in the future.
4206
4574
  createdAt: new Date(Date.now() - 500).toISOString(),
4207
4575
  createdBy: getUUID(),
4576
+ createdByRole: "FIELD_AGENT",
4208
4577
  id: getUUID(),
4209
- createdAtLocation: "TODO",
4578
+ createdAtLocation: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
4210
4579
  declaration: generateActionDeclarationInput(configuration, action),
4211
4580
  annotation: {},
4212
- ...defaults,
4213
- status: ActionStatus.Accepted
4581
+ status: ActionStatus.Accepted,
4582
+ transactionId: getUUID(),
4583
+ ...defaults
4214
4584
  };
4215
4585
  switch (action) {
4216
4586
  case ActionType.READ:
@@ -4220,7 +4590,7 @@ function generateActionDocument({
4220
4590
  case ActionType.DECLARE:
4221
4591
  return { ...actionBase, type: action };
4222
4592
  case ActionType.UNASSIGN:
4223
- return { ...actionBase, type: action };
4593
+ return { ...actionBase, type: action, assignedTo: null };
4224
4594
  case ActionType.ASSIGN:
4225
4595
  return { ...actionBase, assignedTo: getUUID(), type: action };
4226
4596
  case ActionType.VALIDATE:
@@ -4268,7 +4638,8 @@ function generateEventDocument({
4268
4638
  id: getUUID(),
4269
4639
  // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4270
4640
  // @TODO: This should be fixed in the future.
4271
- updatedAt: new Date(Date.now() - 1e3).toISOString()
4641
+ updatedAt: new Date(Date.now() - 1e3).toISOString(),
4642
+ dateOfEvent: configuration.dateOfEvent
4272
4643
  };
4273
4644
  }
4274
4645
  function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
@@ -4290,23 +4661,76 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, de
4290
4661
  eventId
4291
4662
  };
4292
4663
  }
4664
+ function getEventStatus() {
4665
+ const statuses = [
4666
+ EventStatus.CREATED,
4667
+ EventStatus.REGISTERED,
4668
+ EventStatus.DECLARED
4669
+ ];
4670
+ const randomIndex = Math.floor(Math.random() * 3);
4671
+ return statuses[randomIndex];
4672
+ }
4673
+ function getTrackingId() {
4674
+ const uuid = getUUID().replace(/-/g, "");
4675
+ const trackingId = uuid.slice(0, 6).toUpperCase();
4676
+ return trackingId;
4677
+ }
4678
+ function getRandomApplicant() {
4679
+ const firstNames = [
4680
+ "Danny",
4681
+ "John",
4682
+ "Jane",
4683
+ "Emily",
4684
+ "Michael",
4685
+ "Sarah",
4686
+ "Chris",
4687
+ "Jessica"
4688
+ ];
4689
+ const surnames = [
4690
+ "Doe",
4691
+ "Smith",
4692
+ "Johnson",
4693
+ "Brown",
4694
+ "Williams",
4695
+ "Jones",
4696
+ "Garcia",
4697
+ "Miller"
4698
+ ];
4699
+ function getRandomDate(start, end) {
4700
+ const randomDate = new Date(
4701
+ start.getTime() + Math.random() * (end.getTime() - start.getTime())
4702
+ );
4703
+ return randomDate.toISOString().split("T")[0];
4704
+ }
4705
+ const randomFirstName = firstNames[Math.floor(Math.random() * firstNames.length)];
4706
+ const randomSurname = surnames[Math.floor(Math.random() * surnames.length)];
4707
+ const randomDob = getRandomDate(
4708
+ /* @__PURE__ */ new Date("1990-01-01"),
4709
+ /* @__PURE__ */ new Date("2010-12-31")
4710
+ );
4711
+ return {
4712
+ "recommender.none": true,
4713
+ "applicant.firstname": randomFirstName,
4714
+ "applicant.surname": randomSurname,
4715
+ "applicant.dob": randomDob
4716
+ };
4717
+ }
4293
4718
  var eventQueryDataGenerator = (overrides = {}) => ({
4294
4719
  id: overrides.id ?? getUUID(),
4295
- type: overrides.type ?? "tennis-club-membership",
4296
- status: overrides.status ?? "REGISTERED",
4720
+ type: overrides.type ?? "TENNIS_CLUB_MEMBERSHIP",
4721
+ status: overrides.status ?? getEventStatus(),
4297
4722
  createdAt: overrides.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4298
4723
  createdBy: overrides.createdBy ?? getUUID(),
4299
4724
  createdAtLocation: overrides.createdAtLocation ?? getUUID(),
4300
- modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4725
+ updatedAtLocation: overrides.updatedAtLocation ?? getUUID(),
4726
+ updatedAt: overrides.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4301
4727
  assignedTo: overrides.assignedTo ?? null,
4302
4728
  updatedBy: overrides.updatedBy ?? getUUID(),
4303
- declaration: overrides.declaration ?? {
4304
- "recommender.none": true,
4305
- "applicant.firstname": "Danny",
4306
- "applicant.surname": "Doe",
4307
- "applicant.dob": "1999-11-11"
4308
- },
4309
- trackingId: overrides.trackingId ?? "M3F8YQ"
4729
+ updatedByUserRole: overrides.updatedByUserRole ?? "FIELD_AGENT",
4730
+ flags: [],
4731
+ legalStatuses: overrides.legalStatuses ?? {},
4732
+ declaration: overrides.declaration ?? getRandomApplicant(),
4733
+ trackingId: overrides.trackingId ?? getTrackingId()
4310
4734
  });
4311
4735
  var generateTranslationConfig = (message) => ({
4312
4736
  defaultMessage: message,
@@ -4345,3 +4769,293 @@ function isFieldConfigDefaultValue(value) {
4345
4769
  }
4346
4770
  return false;
4347
4771
  }
4772
+
4773
+ // ../commons/src/events/scopes.ts
4774
+ var import_lodash3 = require("lodash");
4775
+
4776
+ // ../commons/src/scopes.ts
4777
+ var import_zod25 = require("zod");
4778
+ var SCOPES = {
4779
+ // TODO v1.8 legacy scopes
4780
+ NATLSYSADMIN: "natlsysadmin",
4781
+ BYPASSRATELIMIT: "bypassratelimit",
4782
+ DECLARE: "declare",
4783
+ REGISTER: "register",
4784
+ VALIDATE: "validate",
4785
+ DEMO: "demo",
4786
+ CERTIFY: "certify",
4787
+ PERFORMANCE: "performance",
4788
+ SYSADMIN: "sysadmin",
4789
+ TEAMS: "teams",
4790
+ CONFIG: "config",
4791
+ // systems / integrations
4792
+ WEBHOOK: "webhook",
4793
+ NATIONALID: "nationalId",
4794
+ NOTIFICATION_API: "notification-api",
4795
+ RECORDSEARCH: "recordsearch",
4796
+ /**
4797
+ * @TODO This is a temporary scope to be used for V2 Events custom events declaration
4798
+ */
4799
+ RECORD_DECLARE: "record.declare-birth",
4800
+ // declare
4801
+ RECORD_DECLARE_BIRTH: "record.declare-birth",
4802
+ RECORD_DECLARE_BIRTH_MY_JURISDICTION: "record.declare-birth:my-jurisdiction",
4803
+ RECORD_DECLARE_DEATH: "record.declare-death",
4804
+ RECORD_DECLARE_DEATH_MY_JURISDICTION: "record.declare-death:my-jurisdiction",
4805
+ RECORD_DECLARE_MARRIAGE: "record.declare-marriage",
4806
+ RECORD_DECLARE_MARRIAGE_MY_JURISDICTION: "record.declare-marriage:my-jurisdiction",
4807
+ RECORD_SUBMIT_INCOMPLETE: "record.declaration-submit-incomplete",
4808
+ RECORD_SUBMIT_FOR_REVIEW: "record.declaration-submit-for-review",
4809
+ RECORD_UNASSIGN_OTHERS: "record.unassign-others",
4810
+ // validate
4811
+ RECORD_SUBMIT_FOR_APPROVAL: "record.declaration-submit-for-approval",
4812
+ RECORD_SUBMIT_FOR_UPDATES: "record.declaration-submit-for-updates",
4813
+ RECORD_DECLARATION_EDIT: "record.declaration-edit",
4814
+ RECORD_REVIEW_DUPLICATES: "record.review-duplicates",
4815
+ RECORD_DECLARATION_ARCHIVE: "record.declaration-archive",
4816
+ RECORD_DECLARATION_REINSTATE: "record.declaration-reinstate",
4817
+ // register
4818
+ RECORD_REGISTER: "record.register",
4819
+ // certify
4820
+ RECORD_EXPORT_RECORDS: "record.export-records",
4821
+ RECORD_DECLARATION_PRINT: "record.declaration-print",
4822
+ RECORD_PRINT_RECORDS_SUPPORTING_DOCUMENTS: "record.declaration-print-supporting-documents",
4823
+ RECORD_REGISTRATION_PRINT: "record.registration-print",
4824
+ // v1.8
4825
+ /**
4826
+ * This scope is used to **print and **issue certified copies of a record
4827
+ * after it has been registered. Previously Registrars had this permission.
4828
+ */
4829
+ RECORD_PRINT_ISSUE_CERTIFIED_COPIES: "record.registration-print&issue-certified-copies",
4830
+ RECORD_PRINT_CERTIFIED_COPIES: "record.registration-print-certified-copies",
4831
+ // v1.8
4832
+ RECORD_BULK_PRINT_CERTIFIED_COPIES: "record.registration-bulk-print-certified-copies",
4833
+ // v1.8
4834
+ RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES: "record.registration-verify-certified-copies",
4835
+ // v1.8
4836
+ // correct
4837
+ RECORD_REGISTRATION_REQUEST_CORRECTION: "record.registration-request-correction",
4838
+ RECORD_REGISTRATION_CORRECT: "record.registration-correct",
4839
+ RECORD_REGISTRATION_REQUEST_REVOCATION: "record.registration-request-revocation",
4840
+ // v1.8
4841
+ RECORD_REGISTRATION_REVOKE: "record.registration-revoke",
4842
+ // v1.8
4843
+ RECORD_REGISTRATION_REQUEST_REINSTATEMENT: "record.registration-request-reinstatement",
4844
+ // v1.8
4845
+ RECORD_REGISTRATION_REINSTATE: "record.registration-reinstate",
4846
+ // v1.8
4847
+ RECORD_CONFIRM_REGISTRATION: "record.confirm-registration",
4848
+ RECORD_REJECT_REGISTRATION: "record.reject-registration",
4849
+ // search
4850
+ SEARCH_BIRTH_MY_JURISDICTION: "search.birth:my-jurisdiction",
4851
+ SEARCH_BIRTH: "search.birth",
4852
+ SEARCH_DEATH_MY_JURISDICTION: "search.death:my-jurisdiction",
4853
+ SEARCH_DEATH: "search.death",
4854
+ SEARCH_MARRIAGE_MY_JURISDICTION: "search.marriage:my-jurisdiction",
4855
+ SEARCH_MARRIAGE: "search.marriage",
4856
+ // audit v1.8
4857
+ RECORD_READ: "record.read",
4858
+ RECORD_READ_AUDIT: "record.read-audit",
4859
+ RECORD_READ_COMMENTS: "record.read-comments",
4860
+ RECORD_CREATE_COMMENTS: "record.create-comments",
4861
+ // profile
4862
+ PROFILE_UPDATE: "profile.update",
4863
+ //v1.8
4864
+ PROFILE_ELECTRONIC_SIGNATURE: "profile.electronic-signature",
4865
+ // performance
4866
+ PERFORMANCE_READ: "performance.read",
4867
+ PERFORMANCE_READ_DASHBOARDS: "performance.read-dashboards",
4868
+ PERFORMANCE_EXPORT_VITAL_STATISTICS: "performance.vital-statistics-export",
4869
+ // organisation
4870
+ ORGANISATION_READ_LOCATIONS: "organisation.read-locations:all",
4871
+ ORGANISATION_READ_LOCATIONS_MY_OFFICE: "organisation.read-locations:my-office",
4872
+ ORGANISATION_READ_LOCATIONS_MY_JURISDICTION: "organisation.read-locations:my-jurisdiction",
4873
+ // user
4874
+ USER_READ: "user.read:all",
4875
+ USER_READ_MY_OFFICE: "user.read:my-office",
4876
+ USER_READ_MY_JURISDICTION: "user.read:my-jurisdiction",
4877
+ USER_READ_ONLY_MY_AUDIT: "user.read:only-my-audit",
4878
+ //v1.8
4879
+ USER_CREATE: "user.create:all",
4880
+ USER_CREATE_MY_JURISDICTION: "user.create:my-jurisdiction",
4881
+ USER_UPDATE: "user.update:all",
4882
+ USER_UPDATE_MY_JURISDICTION: "user.update:my-jurisdiction",
4883
+ // config
4884
+ CONFIG_UPDATE_ALL: "config.update:all",
4885
+ // data seeding
4886
+ USER_DATA_SEEDING: "user.data-seeding"
4887
+ };
4888
+ var LiteralScopes = import_zod25.z.union([
4889
+ import_zod25.z.literal(SCOPES.NATLSYSADMIN),
4890
+ import_zod25.z.literal(SCOPES.BYPASSRATELIMIT),
4891
+ import_zod25.z.literal(SCOPES.DECLARE),
4892
+ import_zod25.z.literal(SCOPES.REGISTER),
4893
+ import_zod25.z.literal(SCOPES.VALIDATE),
4894
+ import_zod25.z.literal(SCOPES.DEMO),
4895
+ import_zod25.z.literal(SCOPES.CERTIFY),
4896
+ import_zod25.z.literal(SCOPES.PERFORMANCE),
4897
+ import_zod25.z.literal(SCOPES.SYSADMIN),
4898
+ import_zod25.z.literal(SCOPES.TEAMS),
4899
+ import_zod25.z.literal(SCOPES.CONFIG),
4900
+ import_zod25.z.literal(SCOPES.WEBHOOK),
4901
+ import_zod25.z.literal(SCOPES.NATIONALID),
4902
+ import_zod25.z.literal(SCOPES.NOTIFICATION_API),
4903
+ import_zod25.z.literal(SCOPES.RECORDSEARCH),
4904
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_BIRTH),
4905
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_BIRTH_MY_JURISDICTION),
4906
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_DEATH),
4907
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_DEATH_MY_JURISDICTION),
4908
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE),
4909
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE_MY_JURISDICTION),
4910
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_INCOMPLETE),
4911
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_FOR_REVIEW),
4912
+ import_zod25.z.literal(SCOPES.RECORD_UNASSIGN_OTHERS),
4913
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_FOR_APPROVAL),
4914
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_FOR_UPDATES),
4915
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_EDIT),
4916
+ import_zod25.z.literal(SCOPES.RECORD_REVIEW_DUPLICATES),
4917
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_ARCHIVE),
4918
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_REINSTATE),
4919
+ import_zod25.z.literal(SCOPES.RECORD_REGISTER),
4920
+ import_zod25.z.literal(SCOPES.RECORD_EXPORT_RECORDS),
4921
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_PRINT),
4922
+ import_zod25.z.literal(SCOPES.RECORD_PRINT_RECORDS_SUPPORTING_DOCUMENTS),
4923
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_PRINT),
4924
+ import_zod25.z.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
4925
+ import_zod25.z.literal(SCOPES.RECORD_PRINT_CERTIFIED_COPIES),
4926
+ import_zod25.z.literal(SCOPES.RECORD_BULK_PRINT_CERTIFIED_COPIES),
4927
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES),
4928
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION),
4929
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_CORRECT),
4930
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_REVOCATION),
4931
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REVOKE),
4932
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_REINSTATEMENT),
4933
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REINSTATE),
4934
+ import_zod25.z.literal(SCOPES.RECORD_CONFIRM_REGISTRATION),
4935
+ import_zod25.z.literal(SCOPES.RECORD_REJECT_REGISTRATION),
4936
+ import_zod25.z.literal(SCOPES.SEARCH_BIRTH_MY_JURISDICTION),
4937
+ import_zod25.z.literal(SCOPES.SEARCH_BIRTH),
4938
+ import_zod25.z.literal(SCOPES.SEARCH_DEATH_MY_JURISDICTION),
4939
+ import_zod25.z.literal(SCOPES.SEARCH_DEATH),
4940
+ import_zod25.z.literal(SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION),
4941
+ import_zod25.z.literal(SCOPES.SEARCH_MARRIAGE),
4942
+ import_zod25.z.literal(SCOPES.RECORD_READ),
4943
+ import_zod25.z.literal(SCOPES.RECORD_READ_AUDIT),
4944
+ import_zod25.z.literal(SCOPES.RECORD_READ_COMMENTS),
4945
+ import_zod25.z.literal(SCOPES.RECORD_CREATE_COMMENTS),
4946
+ import_zod25.z.literal(SCOPES.PROFILE_UPDATE),
4947
+ import_zod25.z.literal(SCOPES.PROFILE_ELECTRONIC_SIGNATURE),
4948
+ import_zod25.z.literal(SCOPES.PERFORMANCE_READ),
4949
+ import_zod25.z.literal(SCOPES.PERFORMANCE_READ_DASHBOARDS),
4950
+ import_zod25.z.literal(SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS),
4951
+ import_zod25.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS),
4952
+ import_zod25.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE),
4953
+ import_zod25.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_JURISDICTION),
4954
+ import_zod25.z.literal(SCOPES.USER_READ),
4955
+ import_zod25.z.literal(SCOPES.USER_READ_MY_OFFICE),
4956
+ import_zod25.z.literal(SCOPES.USER_READ_MY_JURISDICTION),
4957
+ import_zod25.z.literal(SCOPES.USER_READ_ONLY_MY_AUDIT),
4958
+ import_zod25.z.literal(SCOPES.USER_CREATE),
4959
+ import_zod25.z.literal(SCOPES.USER_CREATE_MY_JURISDICTION),
4960
+ import_zod25.z.literal(SCOPES.USER_UPDATE),
4961
+ import_zod25.z.literal(SCOPES.USER_UPDATE_MY_JURISDICTION),
4962
+ import_zod25.z.literal(SCOPES.CONFIG_UPDATE_ALL),
4963
+ import_zod25.z.literal(SCOPES.USER_DATA_SEEDING)
4964
+ ]);
4965
+ var rawConfigurableScopeRegex = /^([a-zA-Z]+\.[a-zA-Z]+)\[((?:\w+=\w+(?:\|\w+)*)(:?,\w+=\w+(?:\|\w+)*)*)\]$/;
4966
+ var rawConfigurableScope = import_zod25.z.string().regex(rawConfigurableScopeRegex);
4967
+ var CreateUserScope = import_zod25.z.object({
4968
+ type: import_zod25.z.literal("user.create"),
4969
+ options: import_zod25.z.object({
4970
+ role: import_zod25.z.array(import_zod25.z.string())
4971
+ })
4972
+ });
4973
+ var EditUserScope = import_zod25.z.object({
4974
+ type: import_zod25.z.literal("user.edit"),
4975
+ options: import_zod25.z.object({
4976
+ role: import_zod25.z.array(import_zod25.z.string())
4977
+ })
4978
+ });
4979
+ var ConfigurableScopes = import_zod25.z.discriminatedUnion("type", [
4980
+ CreateUserScope,
4981
+ EditUserScope
4982
+ ]);
4983
+ var scopes = Object.values(SCOPES);
4984
+
4985
+ // ../commons/src/events/scopes.ts
4986
+ function hasAnyOfScopes(a, b) {
4987
+ return (0, import_lodash3.intersection)(a, b).length > 0;
4988
+ }
4989
+ var CONFIG_GET_ALLOWED_SCOPES = [
4990
+ SCOPES.RECORD_DECLARE,
4991
+ SCOPES.RECORD_READ,
4992
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4993
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
4994
+ SCOPES.RECORD_REGISTER,
4995
+ SCOPES.RECORD_EXPORT_RECORDS,
4996
+ SCOPES.CONFIG,
4997
+ SCOPES.CONFIG_UPDATE_ALL
4998
+ ];
4999
+ var CONFIG_SEARCH_ALLOWED_SCOPES = [
5000
+ SCOPES.SEARCH_BIRTH,
5001
+ SCOPES.SEARCH_DEATH,
5002
+ SCOPES.SEARCH_MARRIAGE,
5003
+ SCOPES.SEARCH_BIRTH_MY_JURISDICTION,
5004
+ SCOPES.SEARCH_DEATH_MY_JURISDICTION,
5005
+ SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION
5006
+ ];
5007
+ var ACTION_ALLOWED_SCOPES = {
5008
+ [ActionType.READ]: [
5009
+ SCOPES.RECORD_DECLARE,
5010
+ SCOPES.RECORD_READ,
5011
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
5012
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
5013
+ SCOPES.RECORD_REGISTER,
5014
+ SCOPES.RECORD_EXPORT_RECORDS
5015
+ ],
5016
+ [ActionType.CREATE]: [
5017
+ SCOPES.RECORD_DECLARE,
5018
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
5019
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW
5020
+ ],
5021
+ [ActionType.NOTIFY]: [SCOPES.RECORD_SUBMIT_INCOMPLETE],
5022
+ [ActionType.DECLARE]: [
5023
+ SCOPES.RECORD_DECLARE,
5024
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
5025
+ SCOPES.RECORD_REGISTER
5026
+ ],
5027
+ [ActionType.DELETE]: [SCOPES.RECORD_DECLARE],
5028
+ [ActionType.VALIDATE]: [
5029
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
5030
+ SCOPES.RECORD_REGISTER
5031
+ ],
5032
+ [ActionType.REGISTER]: [SCOPES.RECORD_REGISTER],
5033
+ [ActionType.PRINT_CERTIFICATE]: [SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES],
5034
+ [ActionType.REQUEST_CORRECTION]: [
5035
+ SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION
5036
+ ],
5037
+ [ActionType.REJECT_CORRECTION]: [SCOPES.RECORD_REGISTRATION_CORRECT],
5038
+ [ActionType.APPROVE_CORRECTION]: [SCOPES.RECORD_REGISTRATION_CORRECT],
5039
+ [ActionType.MARKED_AS_DUPLICATE]: [SCOPES.RECORD_DECLARATION_ARCHIVE],
5040
+ [ActionType.ARCHIVE]: [SCOPES.RECORD_DECLARATION_ARCHIVE],
5041
+ [ActionType.REJECT]: [SCOPES.RECORD_SUBMIT_FOR_UPDATES],
5042
+ [ActionType.ASSIGN]: null,
5043
+ [ActionType.UNASSIGN]: null,
5044
+ [ActionType.DETECT_DUPLICATE]: []
5045
+ };
5046
+ function filterUnallowedActions(actions, userScopes) {
5047
+ const allowedActions = actions.filter((action) => {
5048
+ const requiredScopes = ACTION_ALLOWED_SCOPES[action];
5049
+ if (requiredScopes === null) {
5050
+ return true;
5051
+ }
5052
+ return hasAnyOfScopes(userScopes, requiredScopes);
5053
+ });
5054
+ const hasOtherAllowedActions = allowedActions.some(
5055
+ (action) => action !== ActionType.READ && action !== ActionType.ASSIGN && action !== ActionType.UNASSIGN
5056
+ );
5057
+ if (hasOtherAllowedActions) {
5058
+ return allowedActions;
5059
+ }
5060
+ return [ActionType.READ];
5061
+ }