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

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 (35) hide show
  1. package/dist/commons/api/router.d.ts +7990 -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 +97080 -1720
  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 +535 -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 +46232 -1342
  12. package/dist/commons/events/EventDocument.d.ts +345 -153
  13. package/dist/commons/events/EventIndex.d.ts +1589 -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 +4280 -754
  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 +43591 -439
  21. package/dist/commons/events/PageConfig.d.ts +10860 -204
  22. package/dist/commons/events/SummaryConfig.d.ts +81 -42
  23. package/dist/commons/events/User.d.ts +5 -0
  24. package/dist/commons/events/WorkqueueConfig.d.ts +1397 -19
  25. package/dist/commons/events/defineConfig.d.ts +7220 -40
  26. package/dist/commons/events/event.d.ts +54 -0
  27. package/dist/commons/events/field.d.ts +77 -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 +3668 -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 +1617 -975
  35. 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,8 +499,8 @@ 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,
503
+ helperText: TranslationConfig.optional(),
468
504
  hideLabel: import_zod5.z.boolean().default(false).optional()
469
505
  });
470
506
  var Divider = BaseField.extend({
@@ -472,7 +508,7 @@ var Divider = BaseField.extend({
472
508
  });
473
509
  var TextField = BaseField.extend({
474
510
  type: import_zod5.z.literal(FieldType.TEXT),
475
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
511
+ defaultValue: NonEmptyTextValue.optional(),
476
512
  configuration: import_zod5.z.object({
477
513
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text"),
478
514
  type: import_zod5.z.enum(["text", "password"]).optional(),
@@ -482,7 +518,7 @@ var TextField = BaseField.extend({
482
518
  }).describe("Text input");
483
519
  var NumberField = BaseField.extend({
484
520
  type: import_zod5.z.literal(FieldType.NUMBER),
485
- defaultValue: import_zod5.z.union([NumberFieldValue, DependencyExpression]).optional(),
521
+ defaultValue: NumberFieldValue.optional(),
486
522
  configuration: import_zod5.z.object({
487
523
  min: import_zod5.z.number().optional().describe("Minimum value"),
488
524
  max: import_zod5.z.number().optional().describe("Maximum value"),
@@ -492,7 +528,7 @@ var NumberField = BaseField.extend({
492
528
  }).describe("Number input");
493
529
  var TextAreaField = BaseField.extend({
494
530
  type: import_zod5.z.literal(FieldType.TEXTAREA),
495
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
531
+ defaultValue: NonEmptyTextValue.optional(),
496
532
  configuration: import_zod5.z.object({
497
533
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text"),
498
534
  rows: import_zod5.z.number().optional().describe("Number of visible text lines"),
@@ -526,17 +562,28 @@ var EmailField = BaseField.extend({
526
562
  configuration: import_zod5.z.object({
527
563
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text")
528
564
  }).default({ maxLength: 10 }).optional(),
529
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
565
+ defaultValue: NonEmptyTextValue.optional()
530
566
  });
531
567
  var DateField = BaseField.extend({
532
568
  type: import_zod5.z.literal(FieldType.DATE),
533
- defaultValue: import_zod5.z.union([DateValue, DependencyExpression]).optional(),
569
+ defaultValue: DateValue.optional(),
534
570
  configuration: import_zod5.z.object({
535
571
  notice: TranslationConfig.describe(
536
572
  "Text to display above the date input"
537
573
  ).optional()
538
574
  }).optional()
539
575
  }).describe("A single date input (dd-mm-YYYY)");
576
+ var DateRangeField = BaseField.extend({
577
+ type: import_zod5.z.literal(FieldType.DATE_RANGE),
578
+ defaultValue: DateRangeFieldValue.optional(),
579
+ configuration: import_zod5.z.object({
580
+ notice: TranslationConfig.describe(
581
+ "Text to display above the date input"
582
+ ).optional()
583
+ }).optional()
584
+ }).describe(
585
+ "A date range input ({ rangeStart: dd-mm-YYYY, rangeEnd: dd-mm-YYYY })"
586
+ );
540
587
  var HtmlFontVariant = import_zod5.z.enum([
541
588
  "reg12",
542
589
  "reg14",
@@ -549,7 +596,7 @@ var HtmlFontVariant = import_zod5.z.enum([
549
596
  ]);
550
597
  var Paragraph = BaseField.extend({
551
598
  type: import_zod5.z.literal(FieldType.PARAGRAPH),
552
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
599
+ defaultValue: NonEmptyTextValue.optional(),
553
600
  configuration: import_zod5.z.object({
554
601
  styles: import_zod5.z.object({
555
602
  fontVariant: HtmlFontVariant.optional()
@@ -558,7 +605,7 @@ var Paragraph = BaseField.extend({
558
605
  }).describe("A read-only HTML <p> paragraph");
559
606
  var PageHeader = BaseField.extend({
560
607
  type: import_zod5.z.literal(FieldType.PAGE_HEADER),
561
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
608
+ defaultValue: NonEmptyTextValue.optional()
562
609
  }).describe("A read-only header component for form pages");
563
610
  var File = BaseField.extend({
564
611
  type: import_zod5.z.literal(FieldType.FILE),
@@ -569,7 +616,8 @@ var File = BaseField.extend({
569
616
  width: import_zod5.z.enum(["full", "auto"]).optional().describe(
570
617
  "Whether the file upload button should take the full width of the container or not"
571
618
  )
572
- }).optional()
619
+ }).optional(),
620
+ fileName: TranslationConfig.optional()
573
621
  }).default({
574
622
  maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
575
623
  })
@@ -580,7 +628,7 @@ var SelectOption = import_zod5.z.object({
580
628
  });
581
629
  var RadioGroup = BaseField.extend({
582
630
  type: import_zod5.z.literal(FieldType.RADIO_GROUP),
583
- defaultValue: import_zod5.z.union([TextValue, DependencyExpression]).optional(),
631
+ defaultValue: TextValue.optional(),
584
632
  options: import_zod5.z.array(SelectOption).describe("A list of options"),
585
633
  configuration: import_zod5.z.object({
586
634
  styles: import_zod5.z.object({
@@ -590,7 +638,7 @@ var RadioGroup = BaseField.extend({
590
638
  }).describe("Grouped radio options");
591
639
  var BulletList = BaseField.extend({
592
640
  type: import_zod5.z.literal(FieldType.BULLET_LIST),
593
- defaultValue: import_zod5.z.string().optional(),
641
+ defaultValue: TextValue.optional(),
594
642
  items: import_zod5.z.array(TranslationConfig).describe("A list of items"),
595
643
  configuration: import_zod5.z.object({
596
644
  styles: import_zod5.z.object({
@@ -600,16 +648,16 @@ var BulletList = BaseField.extend({
600
648
  }).describe("A list of bullet points");
601
649
  var Select = BaseField.extend({
602
650
  type: import_zod5.z.literal(FieldType.SELECT),
603
- defaultValue: import_zod5.z.union([TextValue, DependencyExpression]).optional(),
651
+ defaultValue: TextValue.optional(),
604
652
  options: import_zod5.z.array(SelectOption).describe("A list of options")
605
653
  }).describe("Select input");
606
654
  var Checkbox = BaseField.extend({
607
655
  type: import_zod5.z.literal(FieldType.CHECKBOX),
608
- defaultValue: import_zod5.z.union([CheckboxFieldValue, DependencyExpression]).optional()
656
+ defaultValue: CheckboxFieldValue.optional()
609
657
  }).describe("Boolean checkbox field");
610
658
  var Country = BaseField.extend({
611
659
  type: import_zod5.z.literal(FieldType.COUNTRY),
612
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
660
+ defaultValue: NonEmptyTextValue.optional()
613
661
  }).describe("Country select field");
614
662
  var AdministrativeAreas = import_zod5.z.enum([
615
663
  "ADMIN_STRUCTURE",
@@ -624,12 +672,12 @@ var AdministrativeAreaConfiguration = import_zod5.z.object({
624
672
  }).describe("Administrative area options");
625
673
  var AdministrativeArea = BaseField.extend({
626
674
  type: import_zod5.z.literal(FieldType.ADMINISTRATIVE_AREA),
627
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
675
+ defaultValue: NonEmptyTextValue.optional(),
628
676
  configuration: AdministrativeAreaConfiguration
629
677
  }).describe("Administrative area input field e.g. facility, office");
630
678
  var Location = BaseField.extend({
631
679
  type: import_zod5.z.literal(FieldType.LOCATION),
632
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
680
+ defaultValue: NonEmptyTextValue.optional()
633
681
  }).describe("Input field for a location");
634
682
  var FileUploadWithOptions = BaseField.extend({
635
683
  type: import_zod5.z.literal(FieldType.FILE_WITH_OPTIONS),
@@ -643,11 +691,11 @@ var FileUploadWithOptions = BaseField.extend({
643
691
  });
644
692
  var Facility = BaseField.extend({
645
693
  type: import_zod5.z.literal(FieldType.FACILITY),
646
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
694
+ defaultValue: NonEmptyTextValue.optional()
647
695
  }).describe("Input field for a facility");
648
696
  var Office = BaseField.extend({
649
697
  type: import_zod5.z.literal(FieldType.OFFICE),
650
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
698
+ defaultValue: NonEmptyTextValue.optional()
651
699
  }).describe("Input field for an office");
652
700
  var Address = BaseField.extend({
653
701
  type: import_zod5.z.literal(FieldType.ADDRESS),
@@ -656,7 +704,7 @@ var Address = BaseField.extend({
656
704
  var DataEntry = import_zod5.z.union([
657
705
  import_zod5.z.object({
658
706
  label: TranslationConfig,
659
- value: import_zod5.z.string()
707
+ value: TranslationConfig.or(import_zod5.z.string())
660
708
  }),
661
709
  import_zod5.z.object({
662
710
  fieldId: import_zod5.z.string()
@@ -675,6 +723,7 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
675
723
  NumberField,
676
724
  TextAreaField,
677
725
  DateField,
726
+ DateRangeField,
678
727
  Paragraph,
679
728
  RadioGroup,
680
729
  BulletList,
@@ -692,7 +741,6 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
692
741
  EmailField,
693
742
  FileUploadWithOptions,
694
743
  DataField
695
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
696
744
  ]);
697
745
 
698
746
  // ../commons/src/events/PageConfig.ts
@@ -797,6 +845,12 @@ var DeclarationUpdateActions = ActionTypes.extract(
797
845
  declarationUpdateActionValues
798
846
  );
799
847
  var annotationActions = ActionTypes.exclude(declarationActionValues);
848
+ var writeActions = ActionTypes.exclude([
849
+ ActionType.CREATE,
850
+ ActionType.READ,
851
+ ActionType.ASSIGN,
852
+ ActionType.UNASSIGN
853
+ ]);
800
854
 
801
855
  // ../commons/src/events/FormConfig.ts
802
856
  var import_zod8 = require("zod");
@@ -811,6 +865,8 @@ var ActionFormConfig = import_zod8.z.object({
811
865
  var FormConfig = import_zod8.z.union([DeclarationFormConfig, ActionFormConfig]);
812
866
 
813
867
  // ../commons/src/events/ActionConfig.ts
868
+ var import_zod_openapi = require("zod-openapi");
869
+ (0, import_zod_openapi.extendZodWithOpenApi)(import_zod9.z);
814
870
  var ActionConditional2 = import_zod9.z.discriminatedUnion("type", [
815
871
  /** If conditional is defined, the action is shown to the user only if the condition is met */
816
872
  ShowConditional,
@@ -888,18 +944,24 @@ var ApproveCorrectionConfig = ActionConfigBase.merge(
888
944
  })
889
945
  );
890
946
  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
- ]);
947
+ /*
948
+ * OpenAPI references are defined here so our generated OpenAPI spec knows to reuse the models
949
+ * and treat them as "models" instead of duplicating the data structure in each endpoint.
950
+ */
951
+ DeclareConfig.openapi({ ref: "DeclareActionConfig" }),
952
+ ValidateConfig.openapi({ ref: "ValidateActionConfig" }),
953
+ RejectDeclarationConfig.openapi({ ref: "RejectDeclarationActionConfig" }),
954
+ MarkedAsDuplicateConfig.openapi({ ref: "MarkedAsDuplicateActionConfig" }),
955
+ ArchiveConfig.openapi({ ref: "ArchiveActionConfig" }),
956
+ RegisterConfig.openapi({ ref: "RegisterActionConfig" }),
957
+ DeleteConfig.openapi({ ref: "DeleteActionConfig" }),
958
+ PrintCertificateActionConfig.openapi({
959
+ ref: "PrintCertificateActionConfig"
960
+ }),
961
+ RequestCorrectionConfig.openapi({ ref: "RequestCorrectionActionConfig" }),
962
+ RejectCorrectionConfig.openapi({ ref: "RejectCorrectionActionConfig" }),
963
+ ApproveCorrectionConfig.openapi({ ref: "ApproveCorrectionActionConfig" })
964
+ ]).openapi({ ref: "ActionConfig" });
903
965
  var DeclarationActionConfig = import_zod9.z.discriminatedUnion("type", [
904
966
  DeclareConfig,
905
967
  ValidateConfig,
@@ -943,10 +1005,12 @@ var LanguageConfig = import_zod11.z.object({
943
1005
  });
944
1006
 
945
1007
  // ../commons/src/events/EventConfig.ts
946
- var import_zod20 = require("zod");
1008
+ var import_zod17 = require("zod");
947
1009
 
948
1010
  // ../commons/src/events/DeduplicationConfig.ts
949
1011
  var import_zod12 = require("zod");
1012
+ var import_zod_openapi2 = require("zod-openapi");
1013
+ (0, import_zod_openapi2.extendZodWithOpenApi)(import_zod12.z);
950
1014
  var FieldReference = import_zod12.z.string();
951
1015
  var Matcher = import_zod12.z.object({
952
1016
  fieldId: import_zod12.z.string(),
@@ -1007,7 +1071,9 @@ var Clause = import_zod12.z.lazy(
1007
1071
  DateRangeMatcher,
1008
1072
  DateDistanceMatcher
1009
1073
  ])
1010
- );
1074
+ ).openapi({
1075
+ ref: "Clause"
1076
+ });
1011
1077
  var DeduplicationConfig = import_zod12.z.object({
1012
1078
  id: import_zod12.z.string(),
1013
1079
  label: TranslationConfig,
@@ -1016,272 +1082,219 @@ var DeduplicationConfig = import_zod12.z.object({
1016
1082
 
1017
1083
  // ../commons/src/events/SummaryConfig.ts
1018
1084
  var import_zod13 = require("zod");
1019
- var Field = import_zod13.z.object({
1085
+ var BaseField2 = import_zod13.z.object({
1086
+ emptyValueMessage: TranslationConfig.optional(),
1087
+ conditionals: import_zod13.z.array(ShowConditional).default([]).optional()
1088
+ });
1089
+ var ReferenceField = BaseField2.extend({
1090
+ fieldId: import_zod13.z.string()
1091
+ }).describe("Field directly referencing event data with field id");
1092
+ var Field = BaseField2.extend({
1020
1093
  id: import_zod13.z.string().describe("Id of summary field"),
1021
1094
  value: TranslationConfig.describe(
1022
1095
  "Summary field value. Can utilise values defined in configuration and EventMetadata"
1023
1096
  ),
1024
1097
  label: TranslationConfig,
1025
1098
  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
- });
1099
+ }).describe("Custom configured field");
1032
1100
  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.")
1101
+ fields: import_zod13.z.array(import_zod13.z.union([Field, ReferenceField])).describe("Fields rendered in summary view.")
1035
1102
  }).describe("Configuration for summary in event.");
1036
1103
 
1037
- // ../commons/src/events/WorkqueueConfig.ts
1038
- var import_zod15 = require("zod");
1039
-
1040
- // ../commons/src/events/EventMetadata.ts
1104
+ // ../commons/src/events/AdvancedSearchConfig.ts
1041
1105
  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()
1106
+ var MatchType = import_zod14.z.enum(["fuzzy", "exact", "range"]);
1107
+ var BaseField3 = import_zod14.z.object({
1108
+ config: import_zod14.z.object({
1109
+ type: MatchType.describe("Determines the type of field")
1110
+ }),
1111
+ options: import_zod14.z.array(SelectOption).optional(),
1112
+ // If we ever need to override default field conditionals in advanced search
1113
+ conditionals: import_zod14.z.array(FieldConditional).default([]).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([
1120
+ "trackingId",
1121
+ "status",
1122
+ "registeredAt",
1123
+ "registeredAtLocation",
1124
+ "updatedAt"
1125
+ ]);
1126
+ var EventFieldConfigSchema = BaseField3.extend({
1127
+ fieldId: EventFieldId,
1128
+ fieldType: import_zod14.z.literal("event")
1129
+ });
1130
+ var SearchField = import_zod14.z.discriminatedUnion("fieldType", [
1131
+ FieldConfigSchema,
1132
+ EventFieldConfigSchema
1133
+ ]);
1134
+ var AdvancedSearchConfig = import_zod14.z.object({
1138
1135
  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.")
1136
+ fields: import_zod14.z.array(SearchField).describe("Advanced search fields.")
1147
1137
  });
1148
1138
 
1149
1139
  // ../commons/src/events/utils.ts
1150
1140
  var import_lodash = require("lodash");
1151
1141
 
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
- }
1142
+ // ../commons/src/events/ActionDocument.ts
1143
+ var import_zod15 = require("zod");
1144
+ var import_zod_openapi3 = require("zod-openapi");
1145
+ (0, import_zod_openapi3.extendZodWithOpenApi)(import_zod15.z);
1146
+ var ActionUpdate = import_zod15.z.record(import_zod15.z.string(), FieldUpdateValue);
1147
+ var EventState = import_zod15.z.record(import_zod15.z.string(), FieldValue);
1148
+ var ActionStatus = {
1149
+ Requested: "Requested",
1150
+ Accepted: "Accepted",
1151
+ Rejected: "Rejected"
1194
1152
  };
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"]
1153
+ var ActionBase = import_zod15.z.object({
1154
+ id: import_zod15.z.string(),
1155
+ transactionId: import_zod15.z.string(),
1156
+ createdAt: import_zod15.z.string().datetime(),
1157
+ createdBy: import_zod15.z.string(),
1158
+ createdByRole: import_zod15.z.string(),
1159
+ declaration: ActionUpdate,
1160
+ annotation: ActionUpdate.optional(),
1161
+ createdAtLocation: import_zod15.z.string(),
1162
+ status: import_zod15.z.enum([
1163
+ ActionStatus.Requested,
1164
+ ActionStatus.Accepted,
1165
+ ActionStatus.Rejected
1166
+ ]),
1167
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1168
+ originalActionId: import_zod15.z.string().optional()
1227
1169
  });
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"]
1170
+ var AssignedAction = ActionBase.merge(
1171
+ import_zod15.z.object({
1172
+ type: import_zod15.z.literal(ActionType.ASSIGN),
1173
+ assignedTo: import_zod15.z.string()
1174
+ })
1175
+ );
1176
+ var UnassignedAction = ActionBase.merge(
1177
+ import_zod15.z.object({
1178
+ type: import_zod15.z.literal(ActionType.UNASSIGN),
1179
+ assignedTo: import_zod15.z.literal(null)
1180
+ })
1181
+ );
1182
+ var RegisterAction = ActionBase.merge(
1183
+ import_zod15.z.object({
1184
+ type: import_zod15.z.literal(ActionType.REGISTER),
1185
+ registrationNumber: import_zod15.z.string().optional()
1186
+ })
1187
+ );
1188
+ var DeclareAction = ActionBase.merge(
1189
+ import_zod15.z.object({
1190
+ type: import_zod15.z.literal(ActionType.DECLARE)
1191
+ })
1192
+ );
1193
+ var ValidateAction = ActionBase.merge(
1194
+ import_zod15.z.object({
1195
+ type: import_zod15.z.literal(ActionType.VALIDATE)
1196
+ })
1197
+ );
1198
+ var RejectAction = ActionBase.merge(
1199
+ import_zod15.z.object({
1200
+ type: import_zod15.z.literal(ActionType.REJECT)
1201
+ })
1202
+ );
1203
+ var MarkAsDuplicateAction = ActionBase.merge(
1204
+ import_zod15.z.object({
1205
+ type: import_zod15.z.literal(ActionType.MARKED_AS_DUPLICATE)
1206
+ })
1207
+ );
1208
+ var ArchiveAction = ActionBase.merge(
1209
+ import_zod15.z.object({
1210
+ type: import_zod15.z.literal(ActionType.ARCHIVE)
1211
+ })
1212
+ );
1213
+ var CreatedAction = ActionBase.merge(
1214
+ import_zod15.z.object({
1215
+ type: import_zod15.z.literal(ActionType.CREATE)
1216
+ })
1217
+ );
1218
+ var NotifiedAction = ActionBase.merge(
1219
+ import_zod15.z.object({
1220
+ type: import_zod15.z.literal(ActionType.NOTIFY)
1221
+ })
1222
+ );
1223
+ var PrintCertificateAction = ActionBase.merge(
1224
+ import_zod15.z.object({
1225
+ type: import_zod15.z.literal(ActionType.PRINT_CERTIFICATE)
1226
+ })
1227
+ );
1228
+ var RequestedCorrectionAction = ActionBase.merge(
1229
+ import_zod15.z.object({
1230
+ type: import_zod15.z.literal(ActionType.REQUEST_CORRECTION)
1231
+ })
1232
+ );
1233
+ var ApprovedCorrectionAction = ActionBase.merge(
1234
+ import_zod15.z.object({
1235
+ type: import_zod15.z.literal(ActionType.APPROVE_CORRECTION),
1236
+ requestId: import_zod15.z.string()
1237
+ })
1238
+ );
1239
+ var RejectedCorrectionAction = ActionBase.merge(
1240
+ import_zod15.z.object({
1241
+ type: import_zod15.z.literal(ActionType.REJECT_CORRECTION),
1242
+ requestId: import_zod15.z.string()
1243
+ })
1244
+ );
1245
+ var ReadAction = ActionBase.merge(
1246
+ import_zod15.z.object({
1247
+ type: import_zod15.z.literal(ActionType.READ)
1248
+ })
1249
+ );
1250
+ var ActionDocument = import_zod15.z.discriminatedUnion("type", [
1251
+ CreatedAction.openapi({ ref: "CreatedAction" }),
1252
+ ValidateAction.openapi({ ref: "ValidateAction" }),
1253
+ RejectAction.openapi({ ref: "RejectAction" }),
1254
+ MarkAsDuplicateAction.openapi({ ref: "MarkAsDuplicateAction" }),
1255
+ ArchiveAction.openapi({ ref: "ArchiveAction" }),
1256
+ NotifiedAction.openapi({ ref: "NotifiedAction" }),
1257
+ RegisterAction.openapi({ ref: "RegisterAction" }),
1258
+ DeclareAction.openapi({ ref: "DeclareAction" }),
1259
+ AssignedAction.openapi({ ref: "AssignedAction" }),
1260
+ RequestedCorrectionAction.openapi({ ref: "RequestedCorrectionAction" }),
1261
+ ApprovedCorrectionAction.openapi({ ref: "ApprovedCorrectionAction" }),
1262
+ RejectedCorrectionAction.openapi({ ref: "RejectedCorrectionAction" }),
1263
+ UnassignedAction.openapi({ ref: "UnassignedAction" }),
1264
+ PrintCertificateAction.openapi({ ref: "PrintCertificateAction" }),
1265
+ ReadAction.openapi({ ref: "ReadAction" })
1266
+ ]).openapi({
1267
+ ref: "ActionDocument"
1248
1268
  });
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"]
1269
+ var AsyncRejectActionDocument = ActionBase.omit({
1270
+ declaration: true,
1271
+ annotation: true
1272
+ }).merge(
1273
+ import_zod15.z.object({
1274
+ type: import_zod15.z.enum(ConfirmableActions),
1275
+ status: import_zod15.z.literal(ActionStatus.Rejected)
1276
+ })
1277
+ );
1278
+ var Action = import_zod15.z.union([ActionDocument, AsyncRejectActionDocument]);
1279
+ var ResolvedUser = import_zod15.z.object({
1280
+ id: import_zod15.z.string(),
1281
+ role: import_zod15.z.string(),
1282
+ name: import_zod15.z.array(
1283
+ import_zod15.z.object({
1284
+ use: import_zod15.z.string(),
1285
+ given: import_zod15.z.array(import_zod15.z.string()),
1286
+ family: import_zod15.z.string()
1287
+ })
1288
+ )
1269
1289
  });
1270
1290
 
1271
- // ../commons/src/workqueues/index.ts
1272
- var workqueues = {
1273
- all: allWorkqueue,
1274
- registered: registeredWorkqueue,
1275
- inReview: inReviewWorkqueue
1276
- };
1277
-
1278
1291
  // ../commons/src/conditionals/validate.ts
1279
1292
  var import_ajv = __toESM(require("ajv"));
1280
1293
  var import_ajv_formats = __toESM(require("ajv-formats"));
1281
1294
  var import_date_fns = require("date-fns");
1282
1295
 
1283
1296
  // ../commons/src/events/FieldTypeMapping.ts
1284
- var import_zod19 = require("zod");
1297
+ var import_zod16 = require("zod");
1285
1298
  function mapFieldTypeToZod(type, required) {
1286
1299
  let schema;
1287
1300
  switch (type) {
@@ -1291,6 +1304,9 @@ function mapFieldTypeToZod(type, required) {
1291
1304
  case FieldType.EMAIL:
1292
1305
  schema = EmailValue;
1293
1306
  break;
1307
+ case FieldType.DATE_RANGE:
1308
+ schema = DateRangeFieldValue;
1309
+ break;
1294
1310
  case FieldType.TEXT:
1295
1311
  case FieldType.TEXTAREA:
1296
1312
  case FieldType.DIVIDER:
@@ -1305,8 +1321,7 @@ function mapFieldTypeToZod(type, required) {
1305
1321
  case FieldType.FACILITY:
1306
1322
  case FieldType.OFFICE:
1307
1323
  case FieldType.SIGNATURE:
1308
- case FieldType.HIDDEN:
1309
- schema = required ? RequiredTextValue : TextValue;
1324
+ schema = required ? NonEmptyTextValue : TextValue;
1310
1325
  break;
1311
1326
  case FieldType.NUMBER:
1312
1327
  schema = NumberFieldValue;
@@ -1334,7 +1349,7 @@ function createValidationSchema(config) {
1334
1349
  for (const field2 of config) {
1335
1350
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1336
1351
  }
1337
- return import_zod19.z.object(shape);
1352
+ return import_zod16.z.object(shape);
1338
1353
  }
1339
1354
  function mapFieldTypeToMockValue(field2, i) {
1340
1355
  switch (field2.type) {
@@ -1372,6 +1387,8 @@ function mapFieldTypeToMockValue(field2, i) {
1372
1387
  };
1373
1388
  case FieldType.DATE:
1374
1389
  return "2021-01-01";
1390
+ case FieldType.DATE_RANGE:
1391
+ return ["2021-01-01", "2021-01-02"];
1375
1392
  case FieldType.CHECKBOX:
1376
1393
  return true;
1377
1394
  case FieldType.FILE:
@@ -1406,6 +1423,7 @@ function mapFieldTypeToEmptyValue(field2) {
1406
1423
  case FieldType.EMAIL:
1407
1424
  case FieldType.DATE:
1408
1425
  case FieldType.CHECKBOX:
1426
+ case FieldType.DATE_RANGE:
1409
1427
  case FieldType.DATA:
1410
1428
  return null;
1411
1429
  case FieldType.ADDRESS:
@@ -1438,6 +1456,9 @@ var isParagraphFieldType = (field2) => {
1438
1456
  var isDateFieldType = (field2) => {
1439
1457
  return field2.config.type === FieldType.DATE;
1440
1458
  };
1459
+ var isDateRangeFieldType = (field2) => {
1460
+ return field2.config.type === FieldType.DATE_RANGE;
1461
+ };
1441
1462
  var isPageHeaderFieldType = (field2) => {
1442
1463
  return field2.config.type === FieldType.PAGE_HEADER;
1443
1464
  };
@@ -1508,12 +1529,23 @@ var ajv = new import_ajv.default({
1508
1529
  function validate(schema, data) {
1509
1530
  return ajv.validate(schema, data);
1510
1531
  }
1532
+ function isConditionMet(conditional, values) {
1533
+ return validate(conditional, {
1534
+ $form: values,
1535
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1536
+ });
1537
+ }
1511
1538
  function getConditionalActionsForField(field2, values) {
1512
1539
  if (!field2.conditionals) {
1513
1540
  return [];
1514
1541
  }
1515
1542
  return field2.conditionals.filter((conditional) => validate(conditional.conditional, values)).map((conditional) => conditional.type);
1516
1543
  }
1544
+ function areConditionsMet(conditions, values) {
1545
+ return conditions.every(
1546
+ (condition) => isConditionMet(condition.conditional, values)
1547
+ );
1548
+ }
1517
1549
  function isFieldConditionMet(field2, form, conditionalType) {
1518
1550
  const hasRule = (field2.conditionals ?? []).some(
1519
1551
  (conditional) => conditional.type === conditionalType
@@ -1532,6 +1564,10 @@ function isFieldConditionMet(field2, form, conditionalType) {
1532
1564
  function isFieldVisible(field2, form) {
1533
1565
  return isFieldConditionMet(field2, form, ConditionalType.SHOW);
1534
1566
  }
1567
+ function isFieldEmptyAndNotRequired(field2, form) {
1568
+ const fieldValue = form[field2.id];
1569
+ return !field2.required && (fieldValue === void 0 || fieldValue === "");
1570
+ }
1535
1571
  function isFieldEnabled(field2, form) {
1536
1572
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1537
1573
  }
@@ -1636,6 +1672,11 @@ function runFieldValidations({
1636
1672
  field: field2,
1637
1673
  values
1638
1674
  }) {
1675
+ if (!isFieldVisible(field2, values) || isFieldEmptyAndNotRequired(field2, values)) {
1676
+ return {
1677
+ errors: []
1678
+ };
1679
+ }
1639
1680
  const conditionalParameters = {
1640
1681
  $form: values,
1641
1682
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
@@ -1653,29 +1694,6 @@ function runFieldValidations({
1653
1694
  errors: [...fieldValidationResult, ...customValidationResults]
1654
1695
  };
1655
1696
  }
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
1697
 
1680
1698
  // ../commons/src/uuid.ts
1681
1699
  var import_uuid = require("uuid");
@@ -1683,9 +1701,6 @@ function getUUID() {
1683
1701
  return (0, import_uuid.v4)();
1684
1702
  }
1685
1703
 
1686
- // ../commons/src/events/utils.ts
1687
- var import_date_fns2 = require("date-fns");
1688
-
1689
1704
  // ../commons/src/utils.ts
1690
1705
  function getOrThrow(x, message) {
1691
1706
  if (x === void 0 || x === null) {
@@ -1722,15 +1737,9 @@ var getActionAnnotationFields = (actionConfig) => {
1722
1737
  }
1723
1738
  return [];
1724
1739
  };
1725
- var getAllAnnotationFields = (config) => {
1740
+ function getAllAnnotationFields(config) {
1726
1741
  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
- };
1742
+ }
1734
1743
  var findRecordActionPages = (config, actionType) => {
1735
1744
  const action = config.actions.find((a) => a.type === actionType);
1736
1745
  if (action?.type === ActionType.REQUEST_CORRECTION) {
@@ -1753,34 +1762,22 @@ function getActionReview(configuration, actionType) {
1753
1762
  function getActionReviewFields(configuration, actionType) {
1754
1763
  return getActionReview(configuration, actionType).fields;
1755
1764
  }
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
1765
  function isPageVisible(page, formValues) {
1769
1766
  if (!page.conditional) {
1770
1767
  return true;
1771
1768
  }
1772
- return validate(page.conditional, {
1773
- $form: formValues,
1774
- $now: (0, import_date_fns2.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1775
- });
1769
+ return isConditionMet(page.conditional, formValues);
1776
1770
  }
1777
- function omitHiddenFields(fields, values) {
1771
+ function omitHiddenFields(fields, values, visibleVerificationPageIds = []) {
1778
1772
  return (0, import_lodash.omitBy)(values, (_, fieldId) => {
1779
- const field2 = fields.find((f) => f.id === fieldId);
1780
- if (!field2) {
1773
+ if (visibleVerificationPageIds.includes(fieldId)) {
1774
+ return false;
1775
+ }
1776
+ const fieldConfigs = fields.filter((f) => f.id === fieldId);
1777
+ if (!fieldConfigs.length) {
1781
1778
  return true;
1782
1779
  }
1783
- return !isFieldVisible(field2, values);
1780
+ return fieldConfigs.every((f) => !isFieldVisible(f, values));
1784
1781
  });
1785
1782
  }
1786
1783
  function omitHiddenPaginatedFields(formConfig, declaration) {
@@ -1804,13 +1801,49 @@ function createEmptyDraft(eventId, draftId, actionType) {
1804
1801
  annotation: {},
1805
1802
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1806
1803
  createdBy: "@todo",
1807
- createdAtLocation: "@todo"
1804
+ createdAtLocation: "@todo",
1805
+ status: ActionStatus.Accepted,
1806
+ transactionId: "@todo",
1807
+ createdByRole: "@todo"
1808
1808
  }
1809
1809
  };
1810
1810
  }
1811
1811
  function isVerificationPage(page) {
1812
1812
  return page.type === PageTypes.enum.VERIFICATION;
1813
1813
  }
1814
+ function getVisibleVerificationPageIds(pages, annotation) {
1815
+ return pages.filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
1816
+ }
1817
+ function getActionVerificationPageIds(actionConfig, annotation) {
1818
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1819
+ return [
1820
+ ...getVisibleVerificationPageIds(actionConfig.onboardingForm, annotation),
1821
+ ...getVisibleVerificationPageIds(
1822
+ actionConfig.additionalDetailsForm,
1823
+ annotation
1824
+ )
1825
+ ];
1826
+ }
1827
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1828
+ return getVisibleVerificationPageIds(
1829
+ actionConfig.printForm.pages,
1830
+ annotation
1831
+ );
1832
+ }
1833
+ return [];
1834
+ }
1835
+ function omitHiddenAnnotationFields(actionConfig, declaration, annotation) {
1836
+ const annotationFields = getActionAnnotationFields(actionConfig);
1837
+ const visibleVerificationPageIds = getActionVerificationPageIds(
1838
+ actionConfig,
1839
+ annotation
1840
+ );
1841
+ return omitHiddenFields(
1842
+ annotationFields,
1843
+ { ...declaration, ...annotation },
1844
+ visibleVerificationPageIds
1845
+ );
1846
+ }
1814
1847
  function deepMerge(currentDocument, actionDocument) {
1815
1848
  return (0, import_lodash.mergeWith)(
1816
1849
  currentDocument,
@@ -1829,19 +1862,57 @@ function deepMerge(currentDocument, actionDocument) {
1829
1862
  }
1830
1863
  );
1831
1864
  }
1865
+ function findLastAssignmentAction(actions) {
1866
+ return actions.filter(
1867
+ ({ type }) => type === ActionType.ASSIGN || type === ActionType.UNASSIGN
1868
+ ).reduce((latestAction, action) => !latestAction || action.createdAt > latestAction.createdAt ? action : latestAction, void 0);
1869
+ }
1870
+ function isWriteAction(actionType) {
1871
+ return writeActions.safeParse(actionType).success;
1872
+ }
1873
+ var findAllFields = (config) => {
1874
+ return (0, import_lodash.flattenDeep)([
1875
+ ...getDeclarationFields(config),
1876
+ ...getAllAnnotationFields(config)
1877
+ ]);
1878
+ };
1879
+ function getMixedPath(obj, path, defaultValue) {
1880
+ const parts = path.split(".");
1881
+ const resolve = (current, segments) => {
1882
+ if (current == null || segments.length === 0) {
1883
+ return current;
1884
+ }
1885
+ for (let i = segments.length; i > 0; i--) {
1886
+ const compoundKey = segments.slice(0, i).join(".");
1887
+ if ((0, import_lodash.has)(current, compoundKey)) {
1888
+ const next = (0, import_lodash.get)(current, compoundKey);
1889
+ return resolve(next, segments.slice(i));
1890
+ }
1891
+ }
1892
+ return void 0;
1893
+ };
1894
+ const result = resolve(obj, parts);
1895
+ return (0, import_lodash.isNil)(result) ? defaultValue : result;
1896
+ }
1832
1897
 
1833
1898
  // ../commons/src/events/EventConfig.ts
1834
- var EventConfig = import_zod20.z.object({
1835
- id: import_zod20.z.string().describe(
1899
+ var import_zod_openapi4 = require("zod-openapi");
1900
+ (0, import_zod_openapi4.extendZodWithOpenApi)(import_zod17.z);
1901
+ var EventConfig = import_zod17.z.object({
1902
+ id: import_zod17.z.string().describe(
1836
1903
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1837
1904
  ),
1905
+ dateOfEvent: import_zod17.z.object({ fieldId: import_zod17.z.string() }).optional(),
1906
+ title: TranslationConfig,
1907
+ fallbackTitle: TranslationConfig.optional().describe(
1908
+ "This is a fallback title if actual title resolves to empty string"
1909
+ ),
1838
1910
  summary: SummaryConfig,
1839
1911
  label: TranslationConfig,
1840
- actions: import_zod20.z.array(ActionConfig),
1912
+ actions: import_zod17.z.array(ActionConfig),
1841
1913
  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([])
1914
+ deduplication: import_zod17.z.array(DeduplicationConfig).optional().default([]),
1915
+ advancedSearch: import_zod17.z.array(AdvancedSearchConfig).optional().default([])
1845
1916
  }).superRefine((event2, ctx) => {
1846
1917
  const allFields = findAllFields(event2);
1847
1918
  const fieldIds = allFields.map((field2) => field2.id);
@@ -1857,16 +1928,43 @@ var EventConfig = import_zod20.z.object({
1857
1928
  });
1858
1929
  }
1859
1930
  const invalidFields = event2.advancedSearch.flatMap(
1860
- (section) => section.fields.filter((field2) => !fieldIds.includes(field2.fieldId))
1931
+ (section) => (
1932
+ // Check if the fieldId is not in the fieldIds array
1933
+ // and also not in the metadataFields array
1934
+ section.fields.filter(
1935
+ (field2) => !(fieldIds.includes(field2.fieldId) || EventFieldId.options.includes(field2.fieldId))
1936
+ )
1937
+ )
1861
1938
  );
1862
1939
  if (invalidFields.length > 0) {
1863
1940
  ctx.addIssue({
1864
1941
  code: "custom",
1865
- message: `Advanced search id must match a field id in fields array.
1942
+ message: `Advanced search id must match a field id of form fields or pre-defined metadata fields.
1866
1943
  Invalid AdvancedSearch field IDs for event ${event2.id}: ${invalidFields.map((f) => f.fieldId).join(", ")}`,
1867
1944
  path: ["advancedSearch"]
1868
1945
  });
1869
1946
  }
1947
+ if (event2.dateOfEvent) {
1948
+ const eventDateFieldId = getDeclarationFields(event2).find(
1949
+ ({ id }) => id === event2.dateOfEvent?.fieldId
1950
+ );
1951
+ if (!eventDateFieldId) {
1952
+ ctx.addIssue({
1953
+ code: "custom",
1954
+ message: `Date of event field id must match a field id in fields array.
1955
+ Invalid date of event field ID for event ${event2.id}: ${event2.dateOfEvent.fieldId}`,
1956
+ path: ["dateOfEvent"]
1957
+ });
1958
+ } else if (eventDateFieldId.type !== FieldType.DATE) {
1959
+ ctx.addIssue({
1960
+ code: "custom",
1961
+ message: `Field specified for date of event is of type: ${eventDateFieldId.type}, but it needs to be of type: ${FieldType.DATE}`,
1962
+ path: ["dateOfEvent.fieldType"]
1963
+ });
1964
+ }
1965
+ }
1966
+ }).openapi({
1967
+ ref: "EventConfig"
1870
1968
  });
1871
1969
 
1872
1970
  // ../commons/src/events/EventConfigInput.ts
@@ -1875,304 +1973,860 @@ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1875
1973
  var definePage = (page) => PageConfig.parse(page);
1876
1974
  var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1877
1975
 
1878
- // ../commons/src/events/Draft.ts
1879
- var import_zod23 = require("zod");
1976
+ // ../commons/src/events/WorkqueueConfig.ts
1977
+ var import_zod20 = require("zod");
1880
1978
 
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"
1979
+ // ../commons/src/events/EventIndex.ts
1980
+ var import_zod19 = require("zod");
1981
+
1982
+ // ../commons/src/events/EventMetadata.ts
1983
+ var import_zod18 = require("zod");
1984
+ var EventStatus = {
1985
+ CREATED: "CREATED",
1986
+ NOTIFIED: "NOTIFIED",
1987
+ DECLARED: "DECLARED",
1988
+ VALIDATED: "VALIDATED",
1989
+ REGISTERED: "REGISTERED",
1990
+ CERTIFIED: "CERTIFIED",
1991
+ REJECTED: "REJECTED",
1992
+ ARCHIVED: "ARCHIVED"
1888
1993
  };
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()
1994
+ var CustomFlags = {
1995
+ CERTIFICATE_PRINTED: "certificate-printed"
1996
+ };
1997
+ var Flag = import_zod18.z.string().regex(
1998
+ new RegExp(
1999
+ `^(${Object.values(ActionType).join("|").toLowerCase()}):(${Object.values(ActionStatus).join("|").toLowerCase()})$`
2000
+ ),
2001
+ "Flag must be in the format ActionType:ActionStatus (lowerCase)"
2002
+ ).or(import_zod18.z.nativeEnum(CustomFlags));
2003
+ var eventStatuses = Object.values(EventStatus);
2004
+ var EventStatuses = import_zod18.z.nativeEnum(EventStatus);
2005
+ var ZodDate = import_zod18.z.string().date();
2006
+ var ActionCreationMetadata = import_zod18.z.object({
2007
+ createdAt: import_zod18.z.string().datetime().describe("The timestamp when the action request was created."),
2008
+ createdBy: import_zod18.z.string().describe("ID of the user who created the action request."),
2009
+ createdAtLocation: import_zod18.z.string().describe("Location of the user who created the action request."),
2010
+ acceptedAt: import_zod18.z.string().datetime().describe("Timestamp when the action request was accepted."),
2011
+ createdByRole: import_zod18.z.string().describe("Role of the user at the time of action request creation.")
1903
2012
  });
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()
2013
+ var RegistrationCreationMetadata = ActionCreationMetadata.extend({
2014
+ registrationNumber: import_zod18.z.string().describe(
2015
+ "Registration number of the event. Always present for accepted registrations."
2016
+ )
2017
+ });
2018
+ var LegalStatuses = import_zod18.z.object({
2019
+ [EventStatus.DECLARED]: ActionCreationMetadata.nullish(),
2020
+ [EventStatus.REGISTERED]: RegistrationCreationMetadata.nullish()
2021
+ });
2022
+ var EventMetadata = import_zod18.z.object({
2023
+ id: import_zod18.z.string(),
2024
+ type: import_zod18.z.string().describe("The type of event, such as birth, death, or marriage."),
2025
+ status: EventStatuses,
2026
+ legalStatuses: LegalStatuses.describe(
2027
+ "Metadata related to the legal registration of the event, such as who registered it and when."
2028
+ ),
2029
+ createdAt: import_zod18.z.string().datetime().describe("The timestamp when the event was first created and saved."),
2030
+ dateOfEvent: ZodDate.nullish(),
2031
+ createdBy: import_zod18.z.string().describe("ID of the user who created the event."),
2032
+ updatedByUserRole: import_zod18.z.string().describe("Role of the user who last updated the declaration."),
2033
+ createdAtLocation: import_zod18.z.string().describe("Location of the user who created the event."),
2034
+ updatedAtLocation: import_zod18.z.string().nullish().describe("Location of the user who last updated the declaration."),
2035
+ updatedAt: import_zod18.z.string().datetime().describe("Timestamp of the most recent declaration update."),
2036
+ assignedTo: import_zod18.z.string().nullish().describe("ID of the user currently assigned to the event."),
2037
+ updatedBy: import_zod18.z.string().nullish().describe("ID of the user who last updated the declaration."),
2038
+ trackingId: import_zod18.z.string().describe(
2039
+ "System-generated tracking ID used by informants or registrars to look up the event."
2040
+ ),
2041
+ flags: import_zod18.z.array(Flag)
2042
+ });
2043
+ var EventMetadataKeys = import_zod18.z.enum([
2044
+ "id",
2045
+ "type",
2046
+ "status",
2047
+ "createdAt",
2048
+ "dateOfEvent",
2049
+ "createdBy",
2050
+ "updatedByUserRole",
2051
+ "createdAtLocation",
2052
+ "updatedAtLocation",
2053
+ "updatedAt",
2054
+ "assignedTo",
2055
+ "updatedBy",
2056
+ "trackingId",
2057
+ "legalStatuses",
2058
+ "flags"
2059
+ ]);
2060
+ var EventMetadataParameter = import_zod18.z.object({
2061
+ // @TODO: Reconcile with the event metadata definition. How could we derive one from the other?
2062
+ $event: EventMetadataKeys
2063
+ });
2064
+ var eventMetadataLabelMap = {
2065
+ "event.assignedTo": {
2066
+ id: "event.assignedTo.label",
2067
+ defaultMessage: "Assigned To",
2068
+ description: "Assigned To"
2069
+ },
2070
+ "event.createdAt": {
2071
+ id: "event.createdAt.label",
2072
+ defaultMessage: "Created",
2073
+ description: "Created At"
2074
+ },
2075
+ "event.dateOfEvent": {
2076
+ id: "event.dateOfEvent.label",
2077
+ defaultMessage: "Date of Event",
2078
+ description: "Date of Event"
2079
+ },
2080
+ "event.createdAtLocation": {
2081
+ id: "event.createdAtLocation.label",
2082
+ defaultMessage: "Location",
2083
+ description: "Created At Location"
2084
+ },
2085
+ "event.updatedAtLocation": {
2086
+ id: "event.updatedAtLocation.label",
2087
+ defaultMessage: "Location",
2088
+ description: "Updated At Location"
2089
+ },
2090
+ "event.createdBy": {
2091
+ id: "event.createdBy.label",
2092
+ defaultMessage: "Created By",
2093
+ description: "Created By"
2094
+ },
2095
+ "event.updatedByUserRole": {
2096
+ id: "event.updatedByUserRole.label",
2097
+ defaultMessage: "Updated By Role",
2098
+ description: "Updated By Role"
2099
+ },
2100
+ "event.id": {
2101
+ id: "event.id.label",
2102
+ defaultMessage: "ID",
2103
+ description: "ID"
2104
+ },
2105
+ "event.updatedAt": {
2106
+ id: "event.modifiedAt.label",
2107
+ defaultMessage: "Updated",
2108
+ description: "Modified At"
2109
+ },
2110
+ "event.status": {
2111
+ id: "event.status.label",
2112
+ defaultMessage: "Status",
2113
+ description: "Status"
2114
+ },
2115
+ "event.type": {
2116
+ id: "event.type.label",
2117
+ defaultMessage: "Type",
2118
+ description: "Type"
2119
+ },
2120
+ "event.updatedBy": {
2121
+ id: "event.updatedBy.label",
2122
+ defaultMessage: "Updated By",
2123
+ description: "Updated By"
2124
+ },
2125
+ "event.trackingId": {
2126
+ id: "event.trackingId.label",
2127
+ defaultMessage: "Tracking ID",
2128
+ description: "Tracking ID"
2129
+ },
2130
+ "event.flags": {
2131
+ id: "event.flags.label",
2132
+ defaultMessage: "Flags",
2133
+ description: "Flags"
2134
+ }
2135
+ };
2136
+
2137
+ // ../commons/src/events/EventIndex.ts
2138
+ var EventIndex = EventMetadata.extend({
2139
+ declaration: EventState
2140
+ });
2141
+ var EventSearchIndex = import_zod19.z.record(import_zod19.z.string(), import_zod19.z.any()).and(
2142
+ import_zod19.z.object({
2143
+ type: import_zod19.z.string()
2144
+ // Ensures "type" (event-id) exists and is a string
1976
2145
  })
1977
2146
  );
1978
- var ReadAction = ActionBase.merge(
1979
- import_zod21.z.object({
1980
- type: import_zod21.z.literal(ActionType.READ)
1981
- })
2147
+ var Fuzzy = import_zod19.z.object({ type: import_zod19.z.literal("fuzzy"), term: import_zod19.z.string() });
2148
+ var Exact = import_zod19.z.object({ type: import_zod19.z.literal("exact"), term: import_zod19.z.string() });
2149
+ var AnyOf = import_zod19.z.object({
2150
+ type: import_zod19.z.literal("anyOf"),
2151
+ terms: import_zod19.z.array(import_zod19.z.string())
2152
+ });
2153
+ var Range = import_zod19.z.object({
2154
+ type: import_zod19.z.literal("range"),
2155
+ gte: import_zod19.z.string(),
2156
+ lte: import_zod19.z.string()
2157
+ });
2158
+ var Not = import_zod19.z.object({ type: import_zod19.z.literal("not"), term: import_zod19.z.string() });
2159
+ var Within = import_zod19.z.object({ type: import_zod19.z.literal("within"), location: import_zod19.z.string() });
2160
+ var DateCondition = import_zod19.z.union([Exact, Range]);
2161
+ var QueryInput = import_zod19.z.lazy(
2162
+ () => import_zod19.z.union([
2163
+ import_zod19.z.discriminatedUnion("type", [Fuzzy, Exact, Range, Within, AnyOf, Not]),
2164
+ import_zod19.z.record(import_zod19.z.string(), QueryInput)
2165
+ ])
1982
2166
  );
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)
2167
+ var QueryExpression = import_zod19.z.object({
2168
+ type: import_zod19.z.literal("and"),
2169
+ eventType: import_zod19.z.string(),
2170
+ status: import_zod19.z.optional(import_zod19.z.union([AnyOf, Exact])),
2171
+ createdAt: import_zod19.z.optional(DateCondition),
2172
+ updatedAt: import_zod19.z.optional(DateCondition),
2173
+ registeredAt: import_zod19.z.optional(DateCondition),
2174
+ registeredAtLocation: import_zod19.z.optional(import_zod19.z.union([Within, Exact])),
2175
+ createAtLocation: import_zod19.z.optional(import_zod19.z.union([Within, Exact])),
2176
+ updatedAtLocation: import_zod19.z.optional(import_zod19.z.union([Within, Exact])),
2177
+ createdBy: import_zod19.z.optional(Exact),
2178
+ updatedBy: import_zod19.z.optional(Exact),
2179
+ trackingId: import_zod19.z.optional(Exact),
2180
+ flags: import_zod19.z.optional(import_zod19.z.array(import_zod19.z.union([AnyOf, Not]))),
2181
+ data: QueryInput
2182
+ }).partial();
2183
+ var Or2 = import_zod19.z.object({
2184
+ type: import_zod19.z.literal("or"),
2185
+ clauses: import_zod19.z.array(QueryExpression)
2186
+ });
2187
+ var QueryType = import_zod19.z.discriminatedUnion("type", [QueryExpression, Or2]);
2188
+
2189
+ // ../commons/src/conditionals/conditionals.ts
2190
+ function defineConditional(schema) {
2191
+ return schema;
2192
+ }
2193
+ function defineFormConditional(schema) {
2194
+ const schemaWithForm = {
2195
+ type: "object",
2196
+ properties: {
2197
+ $form: schema
2198
+ },
2199
+ required: ["$form"]
2200
+ };
2201
+ return defineConditional(schemaWithForm);
2202
+ }
2203
+ function alwaysTrue() {
2204
+ return {};
2205
+ }
2206
+ function and(...conditions) {
2207
+ return defineConditional({
2208
+ type: "object",
2209
+ allOf: conditions,
2210
+ required: []
2211
+ });
2212
+ }
2213
+ function or(...conditions) {
2214
+ return defineConditional({
2215
+ type: "object",
2216
+ anyOf: conditions,
2217
+ required: []
2218
+ });
2219
+ }
2220
+ function not(condition) {
2221
+ return defineConditional({
2222
+ type: "object",
2223
+ not: condition,
2224
+ required: []
2225
+ });
2226
+ }
2227
+ function never() {
2228
+ return not(alwaysTrue());
2229
+ }
2230
+ var user = {
2231
+ hasScope: (scope) => defineConditional({
2232
+ type: "object",
2233
+ properties: {
2234
+ $user: {
2235
+ type: "object",
2236
+ required: ["scope"],
2237
+ properties: {
2238
+ scope: {
2239
+ type: "array",
2240
+ contains: {
2241
+ type: "string",
2242
+ const: scope
2243
+ }
2244
+ }
2245
+ }
2246
+ }
2247
+ },
2248
+ required: ["$user"]
2009
2249
  })
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()
2250
+ };
2251
+ function createEventConditionals() {
2252
+ return {
2253
+ /**
2254
+ * Checks if the event contains a specific action type.
2255
+ * @param action - The action type to check for.
2256
+ */
2257
+ hasAction: (action) => defineConditional({
2258
+ type: "object",
2259
+ properties: {
2260
+ $event: {
2261
+ type: "object",
2262
+ properties: {
2263
+ actions: {
2264
+ type: "array",
2265
+ contains: {
2266
+ type: "object",
2267
+ properties: {
2268
+ type: {
2269
+ const: action
2270
+ }
2271
+ },
2272
+ required: ["type"]
2273
+ }
2274
+ }
2275
+ },
2276
+ required: ["actions"]
2277
+ }
2278
+ },
2279
+ required: ["$event"]
2280
+ })
2281
+ };
2282
+ }
2283
+ function getDateFromNow(days) {
2284
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2285
+ }
2286
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2287
+ return {
2288
+ type: "object",
2289
+ properties: {
2290
+ [fieldId]: {
2291
+ type: "string",
2292
+ format: "date",
2293
+ [clause]: { $data: `1/${comparedFieldId}` }
2294
+ },
2295
+ [comparedFieldId]: { type: "string", format: "date" }
2296
+ },
2297
+ required: [fieldId]
2298
+ };
2299
+ }
2300
+ function isFieldReference(value) {
2301
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2302
+ }
2303
+ function createFieldConditionals(fieldId) {
2304
+ const getDateRange = (date, clause) => ({
2305
+ type: "object",
2306
+ properties: {
2307
+ [fieldId]: {
2308
+ type: "string",
2309
+ format: "date",
2310
+ [clause]: date
2311
+ }
2312
+ },
2313
+ required: [fieldId]
2314
+ });
2315
+ return {
2316
+ isAfter: () => ({
2317
+ days: (days) => ({
2318
+ inPast: () => defineFormConditional(
2319
+ getDateRange(getDateFromNow(days), "formatMinimum")
2320
+ ),
2321
+ inFuture: () => defineFormConditional(
2322
+ getDateRange(getDateFromNow(-days), "formatMinimum")
2323
+ )
2324
+ }),
2325
+ date: (date) => {
2326
+ if (isFieldReference(date)) {
2327
+ const comparedFieldId = date._fieldId;
2328
+ return defineFormConditional(
2329
+ getDateRangeToFieldReference(
2330
+ fieldId,
2331
+ comparedFieldId,
2332
+ "formatMinimum"
2333
+ )
2334
+ );
2335
+ }
2336
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2337
+ },
2338
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2339
+ }),
2340
+ isBefore: () => ({
2341
+ days: (days) => ({
2342
+ inPast: () => defineFormConditional(
2343
+ getDateRange(getDateFromNow(days), "formatMaximum")
2344
+ ),
2345
+ inFuture: () => defineFormConditional(
2346
+ getDateRange(getDateFromNow(-days), "formatMaximum")
2347
+ )
2348
+ }),
2349
+ date: (date) => {
2350
+ if (isFieldReference(date)) {
2351
+ const comparedFieldId = date._fieldId;
2352
+ return defineFormConditional(
2353
+ getDateRangeToFieldReference(
2354
+ fieldId,
2355
+ comparedFieldId,
2356
+ "formatMaximum"
2357
+ )
2358
+ );
2359
+ }
2360
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2361
+ },
2362
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2363
+ }),
2364
+ isEqualTo: (value) => {
2365
+ if (isFieldReference(value)) {
2366
+ const comparedFieldId = value._fieldId;
2367
+ return defineFormConditional({
2368
+ type: "object",
2369
+ properties: {
2370
+ [fieldId]: {
2371
+ type: ["string", "boolean"],
2372
+ const: { $data: `1/${comparedFieldId}` }
2373
+ },
2374
+ [comparedFieldId]: { type: ["string", "boolean"] }
2375
+ },
2376
+ required: [fieldId, comparedFieldId]
2377
+ });
2378
+ }
2379
+ return defineFormConditional({
2380
+ type: "object",
2381
+ properties: {
2382
+ [fieldId]: {
2383
+ oneOf: [
2384
+ { type: "string", const: value },
2385
+ { type: "boolean", const: value }
2386
+ ],
2387
+ const: value
2388
+ }
2389
+ },
2390
+ required: [fieldId]
2391
+ });
2392
+ },
2393
+ /**
2394
+ * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
2395
+ * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
2396
+ * @returns whether the field is falsy (undefined, false, null, empty string)
2397
+ *
2398
+ * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2399
+ *
2400
+ */
2401
+ isFalsy: () => defineFormConditional({
2402
+ type: "object",
2403
+ properties: {
2404
+ [fieldId]: {
2405
+ anyOf: [
2406
+ { const: "undefined" },
2407
+ { const: false },
2408
+ { const: null },
2409
+ { const: "" }
2410
+ ]
2411
+ }
2412
+ },
2413
+ anyOf: [
2414
+ {
2415
+ required: [fieldId]
2416
+ },
2417
+ {
2418
+ not: {
2419
+ required: [fieldId]
2420
+ }
2421
+ }
2422
+ ]
2423
+ }),
2424
+ isUndefined: () => defineFormConditional({
2425
+ type: "object",
2426
+ properties: {
2427
+ [fieldId]: {
2428
+ type: "string",
2429
+ enum: ["undefined"]
2430
+ }
2431
+ },
2432
+ not: {
2433
+ required: [fieldId]
2434
+ }
2435
+ }),
2436
+ inArray: (values) => defineFormConditional({
2437
+ type: "object",
2438
+ properties: {
2439
+ [fieldId]: {
2440
+ type: "string",
2441
+ enum: values
2442
+ }
2443
+ },
2444
+ required: [fieldId]
2445
+ }),
2446
+ isValidEnglishName: () => defineFormConditional({
2447
+ type: "object",
2448
+ properties: {
2449
+ [fieldId]: {
2450
+ type: "string",
2451
+ 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'._-]*)*$",
2452
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2453
+ }
2454
+ },
2455
+ required: [fieldId]
2456
+ }),
2457
+ /**
2458
+ * Checks if the field value matches a given regular expression pattern.
2459
+ * @param pattern - The regular expression pattern to match the field value against.
2460
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2461
+ */
2462
+ matches: (pattern) => defineFormConditional({
2463
+ type: "object",
2464
+ properties: {
2465
+ [fieldId]: {
2466
+ type: "string",
2467
+ pattern
2468
+ }
2469
+ },
2470
+ required: [fieldId]
2471
+ }),
2472
+ isBetween: (min, max) => defineFormConditional({
2473
+ type: "object",
2474
+ properties: {
2475
+ [fieldId]: {
2476
+ type: "number",
2477
+ minimum: min,
2478
+ maximum: max
2479
+ }
2480
+ },
2481
+ required: [fieldId]
2482
+ }),
2483
+ getId: () => ({ fieldId })
2484
+ };
2485
+ }
2486
+
2487
+ // ../commons/src/searchConfigs.ts
2488
+ function createSearchConfigs(baseField) {
2489
+ return {
2490
+ /**
2491
+ * Creates a range configuration for the specified field.
2492
+ *
2493
+ * @returns An object containing the field ID and a configuration object with a type of 'range'.
2494
+ *
2495
+ * @example event('registeredAt').range()
2496
+ * // {
2497
+ * // ...
2498
+ * // config: { type: 'range' }
2499
+ * // }
2500
+ */
2501
+ range: () => ({
2502
+ ...baseField,
2503
+ config: { type: "range" }
2504
+ }),
2505
+ /**
2506
+ * Creates a configuration for exact matching of the specified field.
2507
+ * @returns An object containing the field ID and a configuration object with a type of 'exact'.
2508
+ * @example field('dob').exact()
2509
+ * // {
2510
+ * // ...
2511
+ * // config: { type: 'exact' }
2512
+ * // }
2513
+ */
2514
+ exact: () => ({
2515
+ ...baseField,
2516
+ config: { type: "exact" }
2517
+ }),
2518
+ /**
2519
+ * Creates a configuration for fuzzy matching of the specified field.
2520
+ * @returns An object containing the field ID and a configuration object with a type of 'exact'.
2521
+ * @example field('name').fuzzy()
2522
+ * // {
2523
+ * // ...
2524
+ * // config: { type: 'fuzzy' }
2525
+ * // }
2526
+ */
2527
+ fuzzy: () => ({
2528
+ ...baseField,
2529
+ config: { type: "fuzzy" }
2020
2530
  })
2021
- )
2531
+ };
2532
+ }
2533
+
2534
+ // ../commons/src/event-config/event-configuration.ts
2535
+ function createEventFieldConfig(fieldId, options) {
2536
+ const baseField = {
2537
+ fieldId,
2538
+ options,
2539
+ fieldType: "event"
2540
+ };
2541
+ return createSearchConfigs(baseField);
2542
+ }
2543
+
2544
+ // ../commons/src/events/event.ts
2545
+ function eventFn(fieldId, options) {
2546
+ return createEventFieldConfig(fieldId, options);
2547
+ }
2548
+ var event = Object.assign(eventFn, {
2549
+ ...createEventConditionals(),
2550
+ field(field2) {
2551
+ return {
2552
+ $event: field2
2553
+ };
2554
+ }
2022
2555
  });
2023
2556
 
2024
- // ../commons/src/events/ActionInput.ts
2557
+ // ../commons/src/events/WorkqueueConfig.ts
2558
+ var WorkqueueConfig = import_zod20.z.object({
2559
+ slug: import_zod20.z.string().describe("Determines the url of the workqueue."),
2560
+ name: TranslationConfig.describe(
2561
+ "Title of the workflow (both in navigation and on the page)"
2562
+ ),
2563
+ query: QueryType,
2564
+ actions: import_zod20.z.array(
2565
+ import_zod20.z.object({
2566
+ type: import_zod20.z.string(),
2567
+ conditionals: import_zod20.z.array(Conditional).optional()
2568
+ })
2569
+ ),
2570
+ columns: import_zod20.z.array(
2571
+ import_zod20.z.object({ label: TranslationConfig, value: EventMetadataParameter })
2572
+ ).default([
2573
+ {
2574
+ label: {
2575
+ id: "workqueues.dateOfEvent",
2576
+ defaultMessage: "Date of Event",
2577
+ description: "Label for workqueue column: dateOfEvent"
2578
+ },
2579
+ value: event.field("dateOfEvent")
2580
+ }
2581
+ ])
2582
+ }).describe("Configuration for workqueue.");
2583
+ function defineWorkqueue(workqueues) {
2584
+ return workqueues.map((workqueue) => WorkqueueConfig.parse(workqueue));
2585
+ }
2586
+
2587
+ // ../commons/src/events/Draft.ts
2025
2588
  var import_zod22 = require("zod");
2026
- var BaseActionInput = import_zod22.z.object({
2027
- eventId: import_zod22.z.string(),
2028
- transactionId: import_zod22.z.string(),
2589
+
2590
+ // ../commons/src/events/ActionInput.ts
2591
+ var import_zod21 = require("zod");
2592
+ var import_zod_openapi5 = require("zod-openapi");
2593
+ (0, import_zod_openapi5.extendZodWithOpenApi)(import_zod21.z);
2594
+ var BaseActionInput = import_zod21.z.object({
2595
+ eventId: import_zod21.z.string(),
2596
+ transactionId: import_zod21.z.string(),
2029
2597
  declaration: ActionUpdate.default({}),
2030
2598
  annotation: ActionUpdate.optional(),
2031
- originalActionId: import_zod22.z.string().optional()
2599
+ originalActionId: import_zod21.z.string().optional(),
2600
+ keepAssignment: import_zod21.z.boolean().optional()
2032
2601
  });
2033
2602
  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()
2603
+ import_zod21.z.object({
2604
+ type: import_zod21.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2605
+ createdAtLocation: import_zod21.z.string()
2037
2606
  })
2038
2607
  );
2039
2608
  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()
2609
+ import_zod21.z.object({
2610
+ type: import_zod21.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2611
+ registrationNumber: import_zod21.z.string().optional()
2043
2612
  })
2044
2613
  );
2045
2614
  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())
2615
+ import_zod21.z.object({
2616
+ type: import_zod21.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2617
+ duplicates: import_zod21.z.array(import_zod21.z.string())
2049
2618
  })
2050
2619
  );
2051
2620
  var NotifyActionInput = BaseActionInput.merge(
2052
- import_zod22.z.object({
2053
- type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2621
+ import_zod21.z.object({
2622
+ type: import_zod21.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2054
2623
  })
2055
2624
  );
2056
2625
  var DeclareActionInput = BaseActionInput.merge(
2057
- import_zod22.z.object({
2058
- type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2626
+ import_zod21.z.object({
2627
+ type: import_zod21.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2059
2628
  })
2060
2629
  );
2061
2630
  var PrintCertificateActionInput = BaseActionInput.merge(
2062
- import_zod22.z.object({
2063
- type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2631
+ import_zod21.z.object({
2632
+ type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2064
2633
  })
2065
2634
  );
2066
2635
  var RejectDeclarationActionInput = BaseActionInput.merge(
2067
- import_zod22.z.object({
2068
- type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2636
+ import_zod21.z.object({
2637
+ type: import_zod21.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2069
2638
  })
2070
2639
  );
2071
2640
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
2072
- import_zod22.z.object({
2073
- type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2641
+ import_zod21.z.object({
2642
+ type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2074
2643
  })
2075
2644
  );
2076
2645
  var ArchiveActionInput = BaseActionInput.merge(
2077
- import_zod22.z.object({
2078
- type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2646
+ import_zod21.z.object({
2647
+ type: import_zod21.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2079
2648
  })
2080
2649
  );
2081
2650
  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()
2651
+ import_zod21.z.object({
2652
+ type: import_zod21.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2653
+ assignedTo: import_zod21.z.string()
2085
2654
  })
2086
2655
  );
2087
2656
  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)
2657
+ import_zod21.z.object({
2658
+ type: import_zod21.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2659
+ assignedTo: import_zod21.z.literal(null).default(null)
2091
2660
  })
2092
2661
  );
2093
2662
  var RequestCorrectionActionInput = BaseActionInput.merge(
2094
- import_zod22.z.object({
2095
- type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2663
+ import_zod21.z.object({
2664
+ type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2096
2665
  })
2097
2666
  );
2098
2667
  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)
2668
+ import_zod21.z.object({
2669
+ requestId: import_zod21.z.string(),
2670
+ type: import_zod21.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2102
2671
  })
2103
2672
  );
2104
2673
  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)
2674
+ import_zod21.z.object({
2675
+ requestId: import_zod21.z.string(),
2676
+ type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2108
2677
  })
2109
2678
  );
2110
2679
  var ReadActionInput = BaseActionInput.merge(
2111
- import_zod22.z.object({
2112
- type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
2680
+ import_zod21.z.object({
2681
+ type: import_zod21.z.literal(ActionType.READ).default(ActionType.READ)
2113
2682
  })
2114
2683
  );
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
- ]);
2684
+ var DeleteActionInput = import_zod21.z.object({ eventId: import_zod21.z.string() });
2685
+ var ActionInput = import_zod21.z.discriminatedUnion("type", [
2686
+ CreateActionInput.openapi({ ref: "CreateActionInput" }),
2687
+ ValidateActionInput.openapi({ ref: "ValidateActionInput" }),
2688
+ RegisterActionInput.openapi({ ref: "RegisterActionInput" }),
2689
+ NotifyActionInput.openapi({ ref: "NotifyActionInput" }),
2690
+ DeclareActionInput.openapi({ ref: "DeclareActionInput" }),
2691
+ RejectDeclarationActionInput.openapi({
2692
+ ref: "RejectDeclarationActionInput"
2693
+ }),
2694
+ MarkedAsDuplicateActionInput.openapi({
2695
+ ref: "MarkedAsDuplicateActionInput"
2696
+ }),
2697
+ ArchiveActionInput.openapi({ ref: "ArchiveActionInput" }),
2698
+ AssignActionInput.openapi({ ref: "AssignActionInput" }),
2699
+ UnassignActionInput.openapi({ ref: "UnassignActionInput" }),
2700
+ PrintCertificateActionInput.openapi({ ref: "PrintCertificateActionInput" }),
2701
+ RequestCorrectionActionInput.openapi({
2702
+ ref: "RequestCorrectionActionInput"
2703
+ }),
2704
+ RejectCorrectionActionInput.openapi({ ref: "RejectCorrectionActionInput" }),
2705
+ ApproveCorrectionActionInput.openapi({
2706
+ ref: "ApproveCorrectionActionInput"
2707
+ }),
2708
+ ReadActionInput.openapi({ ref: "ReadActionInput" })
2709
+ ]).openapi({
2710
+ ref: "ActionInput"
2711
+ });
2132
2712
 
2133
2713
  // ../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(),
2714
+ var Draft = import_zod22.z.object({
2715
+ id: import_zod22.z.string(),
2716
+ eventId: import_zod22.z.string(),
2717
+ transactionId: import_zod22.z.string(),
2718
+ createdAt: import_zod22.z.string().datetime(),
2139
2719
  action: ActionBase.extend({
2140
2720
  type: ActionTypes
2141
2721
  }).omit({ id: true })
2142
2722
  });
2143
2723
  var DraftInput = BaseActionInput.extend({
2144
- type: ActionTypes
2724
+ type: ActionTypes,
2725
+ status: import_zod22.z.enum([
2726
+ ActionStatus.Requested,
2727
+ ActionStatus.Accepted,
2728
+ ActionStatus.Rejected
2729
+ ])
2145
2730
  });
2146
2731
 
2147
2732
  // ../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()
2733
+ var import_zod23 = require("zod");
2734
+ var EventInput = import_zod23.z.object({
2735
+ transactionId: import_zod23.z.string(),
2736
+ type: import_zod23.z.string(),
2737
+ dateOfEvent: import_zod23.z.object({ fieldId: import_zod23.z.string() }).optional()
2152
2738
  });
2153
2739
 
2154
2740
  // ../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
- });
2741
+ var import_zod24 = require("zod");
2742
+ var import_zod_openapi6 = require("zod-openapi");
2743
+ (0, import_zod_openapi6.extendZodWithOpenApi)(import_zod24.z);
2744
+ var EventDocument = import_zod24.z.object({
2745
+ id: import_zod24.z.string(),
2746
+ type: import_zod24.z.string(),
2747
+ dateOfEvent: import_zod24.z.object({ fieldId: import_zod24.z.string() }).optional(),
2748
+ createdAt: import_zod24.z.string().datetime(),
2749
+ updatedAt: import_zod24.z.string().datetime(),
2750
+ registeredAt: import_zod24.z.string().datetime().optional(),
2751
+ // search based on registeration date
2752
+ registeredAtLocation: import_zod24.z.string().optional(),
2753
+ // search based on registeration location
2754
+ actions: import_zod24.z.array(Action),
2755
+ trackingId: import_zod24.z.string()
2756
+ }).openapi({ ref: "EventDocument" });
2164
2757
 
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
- );
2758
+ // ../commons/src/events/state/utils.ts
2759
+ function getActionRequests(actionType, actions) {
2760
+ const filtered = actions.filter((action) => action.type === actionType);
2761
+ const accept = filtered.find(
2762
+ (action) => action.status === ActionStatus.Accepted
2763
+ );
2764
+ const request = filtered.find(
2765
+ (action) => action.status === ActionStatus.Requested
2766
+ );
2767
+ const reject = filtered.find(
2768
+ (action) => action.status === ActionStatus.Rejected
2769
+ );
2770
+ return {
2771
+ reject,
2772
+ accept,
2773
+ request
2774
+ };
2775
+ }
2776
+ function getDeclarationActionCreationMetadata(actionType, actions) {
2777
+ const { accept: acceptAction, request: requestAction } = getActionRequests(
2778
+ actionType,
2779
+ actions
2780
+ );
2781
+ if (!acceptAction) {
2782
+ return null;
2783
+ }
2784
+ const registrationNumber = acceptAction.type === ActionType.REGISTER ? acceptAction.registrationNumber : null;
2785
+ return {
2786
+ // When 3rd party API returns 200 OK, we assume that the request was accepted, and persist single 'accepted' action.
2787
+ createdAt: requestAction?.createdAt ?? acceptAction.createdAt,
2788
+ createdBy: requestAction?.createdBy ?? acceptAction.createdBy,
2789
+ createdAtLocation: requestAction?.createdAtLocation ?? acceptAction.createdAtLocation,
2790
+ acceptedAt: acceptAction.createdAt,
2791
+ createdByRole: requestAction?.createdByRole ?? acceptAction.createdByRole,
2792
+ registrationNumber
2793
+ };
2794
+ }
2795
+ function getDeclarationActionUpdateMetadata(actions) {
2796
+ const createAction = getOrThrow(
2797
+ actions.find((action) => action.type === ActionType.CREATE),
2798
+ `Event has no ${ActionType.CREATE} action`
2799
+ );
2800
+ return [ActionType.DECLARE, ActionType.VALIDATE, ActionType.REGISTER].reduce(
2801
+ (metadata, actionType) => {
2802
+ const { accept, request } = getActionRequests(actionType, actions);
2803
+ return {
2804
+ createdAt: request?.createdAt ?? accept?.createdAt ?? metadata.createdAt,
2805
+ createdBy: request?.createdBy ?? accept?.createdBy ?? metadata.createdBy,
2806
+ createdAtLocation: request?.createdAtLocation ?? accept?.createdAtLocation ?? metadata.createdAtLocation,
2807
+ createdByRole: request?.createdByRole ?? accept?.createdByRole ?? metadata.createdByRole
2808
+ };
2809
+ },
2810
+ {
2811
+ createdAt: createAction.createdAt,
2812
+ createdBy: createAction.createdBy,
2813
+ createdAtLocation: createAction.createdAtLocation,
2814
+ createdByRole: createAction.createdByRole
2815
+ }
2816
+ );
2817
+ }
2818
+ function getLegalStatuses(actions) {
2819
+ return {
2820
+ [EventStatus.DECLARED]: getDeclarationActionCreationMetadata(
2821
+ ActionType.DECLARE,
2822
+ actions
2823
+ ),
2824
+ [EventStatus.REGISTERED]: getDeclarationActionCreationMetadata(
2825
+ ActionType.REGISTER,
2826
+ actions
2827
+ )
2828
+ };
2829
+ }
2176
2830
 
2177
2831
  // ../commons/src/events/state/index.ts
2178
2832
  function getStatusFromActions(actions) {
@@ -2183,30 +2837,67 @@ function getStatusFromActions(actions) {
2183
2837
  return EventStatus.REJECTED;
2184
2838
  }
2185
2839
  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;
2840
+ switch (action.type) {
2841
+ case ActionType.CREATE:
2842
+ return EventStatus.CREATED;
2843
+ case ActionType.DECLARE:
2844
+ return EventStatus.DECLARED;
2845
+ case ActionType.VALIDATE:
2846
+ return EventStatus.VALIDATED;
2847
+ case ActionType.REGISTER:
2848
+ return EventStatus.REGISTERED;
2849
+ case ActionType.REJECT:
2850
+ return EventStatus.REJECTED;
2851
+ case ActionType.ARCHIVE:
2852
+ return EventStatus.ARCHIVED;
2853
+ case ActionType.NOTIFY:
2854
+ return EventStatus.NOTIFIED;
2855
+ case ActionType.PRINT_CERTIFICATE:
2856
+ return EventStatus.CERTIFIED;
2857
+ case ActionType.ASSIGN:
2858
+ case ActionType.UNASSIGN:
2859
+ case ActionType.REQUEST_CORRECTION:
2860
+ case ActionType.APPROVE_CORRECTION:
2861
+ case ActionType.MARKED_AS_DUPLICATE:
2862
+ case ActionType.REJECT_CORRECTION:
2863
+ case ActionType.READ:
2864
+ default:
2865
+ return status;
2206
2866
  }
2207
- return status;
2208
2867
  }, EventStatus.CREATED);
2209
2868
  }
2869
+ function getFlagsFromActions(actions) {
2870
+ const sortedactions = actions.sort(
2871
+ (a, b) => a.createdAt.localeCompare(b.createdAt)
2872
+ );
2873
+ const actionStatus = sortedactions.reduce(
2874
+ (actionStatuses, { type, status }) => ({
2875
+ ...actionStatuses,
2876
+ [type]: status
2877
+ }),
2878
+ {}
2879
+ );
2880
+ const flags = Object.entries(actionStatus).filter(([, status]) => status !== ActionStatus.Accepted).map(([type, status]) => {
2881
+ const flag = `${type.toLowerCase()}:${status.toLowerCase()}`;
2882
+ return flag;
2883
+ });
2884
+ const isCertificatePrinted = sortedactions.reduce(
2885
+ (prev, { type }) => {
2886
+ if (type === ActionType.PRINT_CERTIFICATE) {
2887
+ return true;
2888
+ }
2889
+ if (type === ActionType.APPROVE_CORRECTION) {
2890
+ return false;
2891
+ }
2892
+ return prev;
2893
+ },
2894
+ false
2895
+ );
2896
+ if (isCertificatePrinted) {
2897
+ flags.push(CustomFlags.CERTIFICATE_PRINTED);
2898
+ }
2899
+ return flags;
2900
+ }
2210
2901
  function getAssignedUserFromActions(actions) {
2211
2902
  return actions.reduce((user2, action) => {
2212
2903
  if (action.type === ActionType.ASSIGN) {
@@ -2261,6 +2952,7 @@ function getAcceptedActions(event2) {
2261
2952
  (a) => a.status === ActionStatus.Accepted
2262
2953
  );
2263
2954
  }
2955
+ var DEFAULT_DATE_OF_EVENT_PROPERTY = "createdAt";
2264
2956
  function getCurrentEventState(event2) {
2265
2957
  const creationAction = event2.actions.find(
2266
2958
  (action) => action.type === ActionType.CREATE
@@ -2268,25 +2960,31 @@ function getCurrentEventState(event2) {
2268
2960
  if (!creationAction) {
2269
2961
  throw new Error(`Event ${event2.id} has no creation action`);
2270
2962
  }
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
2963
+ const acceptedActions = getAcceptedActions(event2);
2964
+ const declarationUpdateMetadata = getDeclarationActionUpdateMetadata(
2965
+ event2.actions
2275
2966
  );
2276
- const registrationNumber = registrationAction?.registrationNumber ?? null;
2967
+ const declaration = aggregateActionDeclarations(acceptedActions);
2968
+ const dateOfEvent = ZodDate.safeParse(
2969
+ event2.dateOfEvent?.fieldId ? declaration[event2.dateOfEvent.fieldId] : event2[DEFAULT_DATE_OF_EVENT_PROPERTY]
2970
+ ).data ?? null;
2277
2971
  return deepDropNulls({
2278
2972
  id: event2.id,
2279
2973
  type: event2.type,
2280
2974
  status: getStatusFromActions(event2.actions),
2281
- createdAt: event2.createdAt,
2975
+ legalStatuses: getLegalStatuses(event2.actions),
2976
+ createdAt: creationAction.createdAt,
2282
2977
  createdBy: creationAction.createdBy,
2283
2978
  createdAtLocation: creationAction.createdAtLocation,
2284
- modifiedAt: latestAction.createdAt,
2285
- assignedTo: getAssignedUserFromActions(activeActions),
2286
- updatedBy: latestAction.createdBy,
2287
- declaration: aggregateActionDeclarations(activeActions),
2979
+ updatedAt: declarationUpdateMetadata.createdAt,
2980
+ assignedTo: getAssignedUserFromActions(acceptedActions),
2981
+ updatedBy: declarationUpdateMetadata.createdBy,
2982
+ declaration,
2288
2983
  trackingId: event2.trackingId,
2289
- registrationNumber
2984
+ // @TODO: unify this with rest of the code. It will trip us if updatedBy has different rules than updatedByUserRole
2985
+ updatedByUserRole: declarationUpdateMetadata.createdByRole,
2986
+ dateOfEvent,
2987
+ flags: getFlagsFromActions(event2.actions)
2290
2988
  });
2291
2989
  }
2292
2990
  function getCurrentEventStateWithDrafts(event2, drafts) {
@@ -2311,7 +3009,7 @@ function getCurrentEventStateWithDrafts(event2, drafts) {
2311
3009
  return getCurrentEventState(withDrafts);
2312
3010
  }
2313
3011
  function applyDraftsToEventIndex(eventIndex, drafts) {
2314
- const indexedAt = eventIndex.modifiedAt;
3012
+ const indexedAt = eventIndex.updatedAt;
2315
3013
  const activeDrafts = drafts.filter(({ createdAt }) => new Date(createdAt) > new Date(indexedAt)).map((draft) => draft.action).sort();
2316
3014
  if (activeDrafts.length === 0) {
2317
3015
  return eventIndex;
@@ -2334,7 +3032,7 @@ function getAnnotationFromDrafts(drafts) {
2334
3032
  function getActionAnnotation({
2335
3033
  event: event2,
2336
3034
  actionType,
2337
- drafts
3035
+ drafts = []
2338
3036
  }) {
2339
3037
  const activeActions = getAcceptedActions(event2);
2340
3038
  const action = activeActions.find(
@@ -2353,311 +3051,37 @@ function getActionAnnotation({
2353
3051
 
2354
3052
  // ../commons/src/events/defineConfig.ts
2355
3053
  var defineConfig = (config) => {
2356
- validateWorkqueueConfig(config.workqueues);
2357
- const input = EventConfig.parse(config);
2358
- return input;
2359
- };
2360
-
2361
- // ../commons/src/events/transactions.ts
2362
- function generateTransactionId() {
2363
- return getUUID();
2364
- }
2365
-
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
- };
3054
+ const input = EventConfig.parse(config);
3055
+ return input;
3056
+ };
3057
+
3058
+ // ../commons/src/events/transactions.ts
3059
+ function generateTransactionId() {
3060
+ return getUUID();
2473
3061
  }
2474
- function isFieldReference(value) {
2475
- return typeof value === "object" && value !== null && "_fieldId" in value;
3062
+
3063
+ // ../commons/src/events/test.utils.ts
3064
+ var import_lodash2 = require("lodash");
3065
+
3066
+ // ../commons/src/field-config/field-configuration.ts
3067
+ function createFieldConfigs(fieldId, options) {
3068
+ const baseField = {
3069
+ fieldId,
3070
+ fieldType: "field",
3071
+ ...options
3072
+ };
3073
+ return createSearchConfigs(baseField);
2476
3074
  }
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
- });
3075
+
3076
+ // ../commons/src/events/field.ts
3077
+ function field(fieldId, options = {}) {
2489
3078
  return {
2490
3079
  /**
2491
3080
  * @private Internal property used for field reference tracking.
2492
3081
  */
2493
3082
  _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)
2575
- *
2576
- * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2577
- *
2578
- */
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]
2634
- }),
2635
- /**
2636
- * Checks if the field value matches a given regular expression pattern.
2637
- * @param pattern - The regular expression pattern to match the field value against.
2638
- * @returns A JSONSchema conditional that validates the field value against the pattern.
2639
- */
2640
- matches: (pattern) => defineFormConditional({
2641
- type: "object",
2642
- properties: {
2643
- [fieldId]: {
2644
- type: "string",
2645
- pattern
2646
- }
2647
- },
2648
- required: [fieldId]
2649
- }),
2650
- isBetween: (min, max) => defineFormConditional({
2651
- type: "object",
2652
- properties: {
2653
- [fieldId]: {
2654
- type: "number",
2655
- minimum: min,
2656
- maximum: max
2657
- }
2658
- },
2659
- required: [fieldId]
2660
- })
3083
+ ...createFieldConditionals(fieldId),
3084
+ ...createFieldConfigs(fieldId, options)
2661
3085
  };
2662
3086
  }
2663
3087
 
@@ -3577,20 +4001,12 @@ var tennisClubMembershipEvent = defineConfig({
3577
4001
  description: "This is what this event is referred as in the system",
3578
4002
  id: "event.tennis-club-membership.label"
3579
4003
  },
4004
+ title: {
4005
+ defaultMessage: "{applicant.firstname} {applicant.surname}",
4006
+ description: "This is the title of the summary",
4007
+ id: "v2.event.tennis-club-membership.title"
4008
+ },
3580
4009
  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
4010
  fields: [
3595
4011
  {
3596
4012
  id: "applicant.firstname",
@@ -3630,28 +4046,6 @@ var tennisClubMembershipEvent = defineConfig({
3630
4046
  }
3631
4047
  ]
3632
4048
  },
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
4049
  actions: [
3656
4050
  {
3657
4051
  type: ActionType.DECLARE,
@@ -3959,11 +4353,7 @@ var tennisClubMembershipEvent = defineConfig({
3959
4353
  description: "This is what this event is referred as in the system",
3960
4354
  id: "v2.event.tennis-club-membership.search"
3961
4355
  },
3962
- fields: [
3963
- {
3964
- fieldId: "applicant.dob"
3965
- }
3966
- ]
4356
+ fields: [field("applicant.dob").exact(), event("registeredAt").exact()]
3967
4357
  }
3968
4358
  ],
3969
4359
  declaration: TENNIS_CLUB_DECLARATION_FORM
@@ -3996,10 +4386,10 @@ function generateActionAnnotationInput(configuration, action) {
3996
4386
  );
3997
4387
  const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
3998
4388
  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);
4389
+ const visibleVerificationPageIds = getVisibleVerificationPageIds(
4390
+ findRecordActionPages(configuration, action),
4391
+ annotation
4392
+ );
4003
4393
  const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
4004
4394
  (acc, pageId) => ({
4005
4395
  ...acc,
@@ -4030,6 +4420,7 @@ var eventPayloadGenerator = {
4030
4420
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4031
4421
  transactionId: getUUID(),
4032
4422
  action: {
4423
+ transactionId: getUUID(),
4033
4424
  type: actionType,
4034
4425
  status: ActionStatus.Accepted,
4035
4426
  declaration: {
@@ -4044,6 +4435,7 @@ var eventPayloadGenerator = {
4044
4435
  },
4045
4436
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4046
4437
  createdBy: "@todo",
4438
+ createdByRole: "@todo",
4047
4439
  createdAtLocation: "@todo"
4048
4440
  }
4049
4441
  },
@@ -4205,12 +4597,14 @@ function generateActionDocument({
4205
4597
  // @TODO: This should be fixed in the future.
4206
4598
  createdAt: new Date(Date.now() - 500).toISOString(),
4207
4599
  createdBy: getUUID(),
4600
+ createdByRole: "FIELD_AGENT",
4208
4601
  id: getUUID(),
4209
- createdAtLocation: "TODO",
4602
+ createdAtLocation: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
4210
4603
  declaration: generateActionDeclarationInput(configuration, action),
4211
4604
  annotation: {},
4212
- ...defaults,
4213
- status: ActionStatus.Accepted
4605
+ status: ActionStatus.Accepted,
4606
+ transactionId: getUUID(),
4607
+ ...defaults
4214
4608
  };
4215
4609
  switch (action) {
4216
4610
  case ActionType.READ:
@@ -4220,7 +4614,7 @@ function generateActionDocument({
4220
4614
  case ActionType.DECLARE:
4221
4615
  return { ...actionBase, type: action };
4222
4616
  case ActionType.UNASSIGN:
4223
- return { ...actionBase, type: action };
4617
+ return { ...actionBase, type: action, assignedTo: null };
4224
4618
  case ActionType.ASSIGN:
4225
4619
  return { ...actionBase, assignedTo: getUUID(), type: action };
4226
4620
  case ActionType.VALIDATE:
@@ -4268,7 +4662,8 @@ function generateEventDocument({
4268
4662
  id: getUUID(),
4269
4663
  // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4270
4664
  // @TODO: This should be fixed in the future.
4271
- updatedAt: new Date(Date.now() - 1e3).toISOString()
4665
+ updatedAt: new Date(Date.now() - 1e3).toISOString(),
4666
+ dateOfEvent: configuration.dateOfEvent
4272
4667
  };
4273
4668
  }
4274
4669
  function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
@@ -4290,23 +4685,76 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, de
4290
4685
  eventId
4291
4686
  };
4292
4687
  }
4688
+ function getEventStatus() {
4689
+ const statuses = [
4690
+ EventStatus.CREATED,
4691
+ EventStatus.REGISTERED,
4692
+ EventStatus.DECLARED
4693
+ ];
4694
+ const randomIndex = Math.floor(Math.random() * 3);
4695
+ return statuses[randomIndex];
4696
+ }
4697
+ function getTrackingId() {
4698
+ const uuid = getUUID().replace(/-/g, "");
4699
+ const trackingId = uuid.slice(0, 6).toUpperCase();
4700
+ return trackingId;
4701
+ }
4702
+ function getRandomApplicant() {
4703
+ const firstNames = [
4704
+ "Danny",
4705
+ "John",
4706
+ "Jane",
4707
+ "Emily",
4708
+ "Michael",
4709
+ "Sarah",
4710
+ "Chris",
4711
+ "Jessica"
4712
+ ];
4713
+ const surnames = [
4714
+ "Doe",
4715
+ "Smith",
4716
+ "Johnson",
4717
+ "Brown",
4718
+ "Williams",
4719
+ "Jones",
4720
+ "Garcia",
4721
+ "Miller"
4722
+ ];
4723
+ function getRandomDate(start, end) {
4724
+ const randomDate = new Date(
4725
+ start.getTime() + Math.random() * (end.getTime() - start.getTime())
4726
+ );
4727
+ return randomDate.toISOString().split("T")[0];
4728
+ }
4729
+ const randomFirstName = firstNames[Math.floor(Math.random() * firstNames.length)];
4730
+ const randomSurname = surnames[Math.floor(Math.random() * surnames.length)];
4731
+ const randomDob = getRandomDate(
4732
+ /* @__PURE__ */ new Date("1990-01-01"),
4733
+ /* @__PURE__ */ new Date("2010-12-31")
4734
+ );
4735
+ return {
4736
+ "recommender.none": true,
4737
+ "applicant.firstname": randomFirstName,
4738
+ "applicant.surname": randomSurname,
4739
+ "applicant.dob": randomDob
4740
+ };
4741
+ }
4293
4742
  var eventQueryDataGenerator = (overrides = {}) => ({
4294
4743
  id: overrides.id ?? getUUID(),
4295
- type: overrides.type ?? "tennis-club-membership",
4296
- status: overrides.status ?? "REGISTERED",
4744
+ type: overrides.type ?? "TENNIS_CLUB_MEMBERSHIP",
4745
+ status: overrides.status ?? getEventStatus(),
4297
4746
  createdAt: overrides.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4298
4747
  createdBy: overrides.createdBy ?? getUUID(),
4299
4748
  createdAtLocation: overrides.createdAtLocation ?? getUUID(),
4300
- modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4749
+ updatedAtLocation: overrides.updatedAtLocation ?? getUUID(),
4750
+ updatedAt: overrides.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4301
4751
  assignedTo: overrides.assignedTo ?? null,
4302
4752
  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"
4753
+ updatedByUserRole: overrides.updatedByUserRole ?? "FIELD_AGENT",
4754
+ flags: [],
4755
+ legalStatuses: overrides.legalStatuses ?? {},
4756
+ declaration: overrides.declaration ?? getRandomApplicant(),
4757
+ trackingId: overrides.trackingId ?? getTrackingId()
4310
4758
  });
4311
4759
  var generateTranslationConfig = (message) => ({
4312
4760
  defaultMessage: message,
@@ -4345,3 +4793,197 @@ function isFieldConfigDefaultValue(value) {
4345
4793
  }
4346
4794
  return false;
4347
4795
  }
4796
+
4797
+ // ../commons/src/events/scopes.ts
4798
+ var import_lodash3 = require("lodash");
4799
+
4800
+ // ../commons/src/scopes.ts
4801
+ var SCOPES = {
4802
+ // TODO v1.8 legacy scopes
4803
+ NATLSYSADMIN: "natlsysadmin",
4804
+ BYPASSRATELIMIT: "bypassratelimit",
4805
+ DECLARE: "declare",
4806
+ REGISTER: "register",
4807
+ VALIDATE: "validate",
4808
+ DEMO: "demo",
4809
+ CERTIFY: "certify",
4810
+ PERFORMANCE: "performance",
4811
+ SYSADMIN: "sysadmin",
4812
+ TEAMS: "teams",
4813
+ CONFIG: "config",
4814
+ // systems / integrations
4815
+ WEBHOOK: "webhook",
4816
+ NATIONALID: "nationalId",
4817
+ NOTIFICATION_API: "notification-api",
4818
+ RECORDSEARCH: "recordsearch",
4819
+ /**
4820
+ * @TODO This is a temporary scope to be used for V2 Events custom events declaration
4821
+ */
4822
+ RECORD_DECLARE: "record.declare-birth",
4823
+ // declare
4824
+ RECORD_DECLARE_BIRTH: "record.declare-birth",
4825
+ RECORD_DECLARE_BIRTH_MY_JURISDICTION: "record.declare-birth:my-jurisdiction",
4826
+ RECORD_DECLARE_DEATH: "record.declare-death",
4827
+ RECORD_DECLARE_DEATH_MY_JURISDICTION: "record.declare-death:my-jurisdiction",
4828
+ RECORD_DECLARE_MARRIAGE: "record.declare-marriage",
4829
+ RECORD_DECLARE_MARRIAGE_MY_JURISDICTION: "record.declare-marriage:my-jurisdiction",
4830
+ RECORD_SUBMIT_INCOMPLETE: "record.declaration-submit-incomplete",
4831
+ RECORD_SUBMIT_FOR_REVIEW: "record.declaration-submit-for-review",
4832
+ RECORD_UNASSIGN_OTHERS: "record.unassign-others",
4833
+ // validate
4834
+ RECORD_SUBMIT_FOR_APPROVAL: "record.declaration-submit-for-approval",
4835
+ RECORD_SUBMIT_FOR_UPDATES: "record.declaration-submit-for-updates",
4836
+ RECORD_DECLARATION_EDIT: "record.declaration-edit",
4837
+ RECORD_REVIEW_DUPLICATES: "record.review-duplicates",
4838
+ RECORD_DECLARATION_ARCHIVE: "record.declaration-archive",
4839
+ RECORD_DECLARATION_REINSTATE: "record.declaration-reinstate",
4840
+ // register
4841
+ RECORD_REGISTER: "record.register",
4842
+ // certify
4843
+ RECORD_EXPORT_RECORDS: "record.export-records",
4844
+ RECORD_DECLARATION_PRINT: "record.declaration-print",
4845
+ RECORD_PRINT_RECORDS_SUPPORTING_DOCUMENTS: "record.declaration-print-supporting-documents",
4846
+ RECORD_REGISTRATION_PRINT: "record.registration-print",
4847
+ // v1.8
4848
+ /**
4849
+ * This scope is used to **print and **issue certified copies of a record
4850
+ * after it has been registered. Previously Registrars had this permission.
4851
+ */
4852
+ RECORD_PRINT_ISSUE_CERTIFIED_COPIES: "record.registration-print&issue-certified-copies",
4853
+ RECORD_PRINT_CERTIFIED_COPIES: "record.registration-print-certified-copies",
4854
+ // v1.8
4855
+ RECORD_BULK_PRINT_CERTIFIED_COPIES: "record.registration-bulk-print-certified-copies",
4856
+ // v1.8
4857
+ RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES: "record.registration-verify-certified-copies",
4858
+ // v1.8
4859
+ // correct
4860
+ RECORD_REGISTRATION_REQUEST_CORRECTION: "record.registration-request-correction",
4861
+ RECORD_REGISTRATION_CORRECT: "record.registration-correct",
4862
+ RECORD_REGISTRATION_REQUEST_REVOCATION: "record.registration-request-revocation",
4863
+ // v1.8
4864
+ RECORD_REGISTRATION_REVOKE: "record.registration-revoke",
4865
+ // v1.8
4866
+ RECORD_REGISTRATION_REQUEST_REINSTATEMENT: "record.registration-request-reinstatement",
4867
+ // v1.8
4868
+ RECORD_REGISTRATION_REINSTATE: "record.registration-reinstate",
4869
+ // v1.8
4870
+ RECORD_CONFIRM_REGISTRATION: "record.confirm-registration",
4871
+ RECORD_REJECT_REGISTRATION: "record.reject-registration",
4872
+ // search
4873
+ SEARCH_BIRTH_MY_JURISDICTION: "search.birth:my-jurisdiction",
4874
+ SEARCH_BIRTH: "search.birth",
4875
+ SEARCH_DEATH_MY_JURISDICTION: "search.death:my-jurisdiction",
4876
+ SEARCH_DEATH: "search.death",
4877
+ SEARCH_MARRIAGE_MY_JURISDICTION: "search.marriage:my-jurisdiction",
4878
+ SEARCH_MARRIAGE: "search.marriage",
4879
+ // audit v1.8
4880
+ RECORD_READ: "record.read",
4881
+ RECORD_READ_AUDIT: "record.read-audit",
4882
+ RECORD_READ_COMMENTS: "record.read-comments",
4883
+ RECORD_CREATE_COMMENTS: "record.create-comments",
4884
+ // profile
4885
+ PROFILE_UPDATE: "profile.update",
4886
+ //v1.8
4887
+ PROFILE_ELECTRONIC_SIGNATURE: "profile.electronic-signature",
4888
+ // performance
4889
+ PERFORMANCE_READ: "performance.read",
4890
+ PERFORMANCE_READ_DASHBOARDS: "performance.read-dashboards",
4891
+ PERFORMANCE_EXPORT_VITAL_STATISTICS: "performance.vital-statistics-export",
4892
+ // organisation
4893
+ ORGANISATION_READ_LOCATIONS: "organisation.read-locations:all",
4894
+ ORGANISATION_READ_LOCATIONS_MY_OFFICE: "organisation.read-locations:my-office",
4895
+ ORGANISATION_READ_LOCATIONS_MY_JURISDICTION: "organisation.read-locations:my-jurisdiction",
4896
+ // user
4897
+ USER_READ: "user.read:all",
4898
+ USER_READ_MY_OFFICE: "user.read:my-office",
4899
+ USER_READ_MY_JURISDICTION: "user.read:my-jurisdiction",
4900
+ USER_READ_ONLY_MY_AUDIT: "user.read:only-my-audit",
4901
+ //v1.8
4902
+ USER_CREATE: "user.create:all",
4903
+ USER_CREATE_MY_JURISDICTION: "user.create:my-jurisdiction",
4904
+ USER_UPDATE: "user.update:all",
4905
+ USER_UPDATE_MY_JURISDICTION: "user.update:my-jurisdiction",
4906
+ // config
4907
+ CONFIG_UPDATE_ALL: "config.update:all",
4908
+ // data seeding
4909
+ USER_DATA_SEEDING: "user.data-seeding"
4910
+ };
4911
+ var scopes = Object.values(SCOPES);
4912
+
4913
+ // ../commons/src/events/scopes.ts
4914
+ function hasAnyOfScopes(a, b) {
4915
+ return (0, import_lodash3.intersection)(a, b).length > 0;
4916
+ }
4917
+ var CONFIG_GET_ALLOWED_SCOPES = [
4918
+ SCOPES.RECORD_DECLARE,
4919
+ SCOPES.RECORD_READ,
4920
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4921
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
4922
+ SCOPES.RECORD_REGISTER,
4923
+ SCOPES.RECORD_EXPORT_RECORDS,
4924
+ SCOPES.CONFIG,
4925
+ SCOPES.CONFIG_UPDATE_ALL
4926
+ ];
4927
+ var CONFIG_SEARCH_ALLOWED_SCOPES = [
4928
+ SCOPES.SEARCH_BIRTH,
4929
+ SCOPES.SEARCH_DEATH,
4930
+ SCOPES.SEARCH_MARRIAGE,
4931
+ SCOPES.SEARCH_BIRTH_MY_JURISDICTION,
4932
+ SCOPES.SEARCH_DEATH_MY_JURISDICTION,
4933
+ SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION
4934
+ ];
4935
+ var ACTION_ALLOWED_SCOPES = {
4936
+ [ActionType.READ]: [
4937
+ SCOPES.RECORD_DECLARE,
4938
+ SCOPES.RECORD_READ,
4939
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4940
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
4941
+ SCOPES.RECORD_REGISTER,
4942
+ SCOPES.RECORD_EXPORT_RECORDS
4943
+ ],
4944
+ [ActionType.CREATE]: [
4945
+ SCOPES.RECORD_DECLARE,
4946
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4947
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW
4948
+ ],
4949
+ [ActionType.NOTIFY]: [SCOPES.RECORD_SUBMIT_INCOMPLETE],
4950
+ [ActionType.DECLARE]: [
4951
+ SCOPES.RECORD_DECLARE,
4952
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
4953
+ SCOPES.RECORD_REGISTER
4954
+ ],
4955
+ [ActionType.DELETE]: [SCOPES.RECORD_DECLARE],
4956
+ [ActionType.VALIDATE]: [
4957
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
4958
+ SCOPES.RECORD_REGISTER
4959
+ ],
4960
+ [ActionType.REGISTER]: [SCOPES.RECORD_REGISTER],
4961
+ [ActionType.PRINT_CERTIFICATE]: [SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES],
4962
+ [ActionType.REQUEST_CORRECTION]: [
4963
+ SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION
4964
+ ],
4965
+ [ActionType.REJECT_CORRECTION]: [SCOPES.RECORD_REGISTRATION_CORRECT],
4966
+ [ActionType.APPROVE_CORRECTION]: [SCOPES.RECORD_REGISTRATION_CORRECT],
4967
+ [ActionType.MARKED_AS_DUPLICATE]: [SCOPES.RECORD_DECLARATION_ARCHIVE],
4968
+ [ActionType.ARCHIVE]: [SCOPES.RECORD_DECLARATION_ARCHIVE],
4969
+ [ActionType.REJECT]: [SCOPES.RECORD_SUBMIT_FOR_UPDATES],
4970
+ [ActionType.ASSIGN]: null,
4971
+ [ActionType.UNASSIGN]: null,
4972
+ [ActionType.DETECT_DUPLICATE]: []
4973
+ };
4974
+ function filterUnallowedActions(actions, userScopes) {
4975
+ const allowedActions = actions.filter((action) => {
4976
+ const requiredScopes = ACTION_ALLOWED_SCOPES[action];
4977
+ if (requiredScopes === null) {
4978
+ return true;
4979
+ }
4980
+ return hasAnyOfScopes(userScopes, requiredScopes);
4981
+ });
4982
+ const hasOtherAllowedActions = allowedActions.some(
4983
+ (action) => action !== ActionType.READ && action !== ActionType.ASSIGN && action !== ActionType.UNASSIGN
4984
+ );
4985
+ if (hasOtherAllowedActions) {
4986
+ return allowedActions;
4987
+ }
4988
+ return [ActionType.READ];
4989
+ }