@opencrvs/toolkit 1.8.0-rc.fef85f2 → 1.8.0-rc.ff0b26c

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 (32) hide show
  1. package/dist/commons/api/router.d.ts +10585 -4200
  2. package/dist/commons/conditionals/conditionals.d.ts +9 -6
  3. package/dist/commons/events/ActionConfig.d.ts +97080 -1720
  4. package/dist/commons/events/ActionDocument.d.ts +542 -211
  5. package/dist/commons/events/ActionInput.d.ts +248 -240
  6. package/dist/commons/events/AdvancedSearchConfig.d.ts +957 -22
  7. package/dist/commons/events/Draft.d.ts +33 -20
  8. package/dist/commons/events/EventConfig.d.ts +46237 -1398
  9. package/dist/commons/events/EventDocument.d.ts +337 -159
  10. package/dist/commons/events/EventIndex.d.ts +1735 -16
  11. package/dist/commons/events/EventInput.d.ts +13 -0
  12. package/dist/commons/events/EventMetadata.d.ts +274 -14
  13. package/dist/commons/events/FieldConfig.d.ts +4229 -744
  14. package/dist/commons/events/FieldType.d.ts +3 -3
  15. package/dist/commons/events/FieldTypeMapping.d.ts +11 -4
  16. package/dist/commons/events/FieldValue.d.ts +7 -4
  17. package/dist/commons/events/FormConfig.d.ts +43591 -439
  18. package/dist/commons/events/PageConfig.d.ts +10860 -204
  19. package/dist/commons/events/SummaryConfig.d.ts +17 -47
  20. package/dist/commons/events/WorkqueueConfig.d.ts +1549 -19
  21. package/dist/commons/events/defineConfig.d.ts +7199 -27
  22. package/dist/commons/events/event.d.ts +54 -0
  23. package/dist/commons/events/field.d.ts +82 -0
  24. package/dist/commons/events/index.d.ts +2 -0
  25. package/dist/commons/events/scopes.d.ts +21 -1
  26. package/dist/commons/events/test.utils.d.ts +10 -47
  27. package/dist/commons/events/utils.d.ts +3665 -67
  28. package/dist/conditionals/index.js +36 -33
  29. package/dist/events/index.js +1771 -966
  30. package/dist/scopes/index.d.ts +158 -1
  31. package/dist/scopes/index.js +152 -1
  32. package/package.json +3 -2
@@ -30,12 +30,14 @@ 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_CONFIGURABLE_SCOPES: () => ACTION_ALLOWED_CONFIGURABLE_SCOPES,
33
34
  ACTION_ALLOWED_SCOPES: () => ACTION_ALLOWED_SCOPES,
34
35
  Action: () => Action,
35
36
  ActionBase: () => ActionBase,
36
37
  ActionConditional: () => ActionConditional,
37
38
  ActionConfig: () => ActionConfig,
38
39
  ActionConfigBase: () => ActionConfigBase,
40
+ ActionCreationMetadata: () => ActionCreationMetadata,
39
41
  ActionDocument: () => ActionDocument,
40
42
  ActionFormConfig: () => ActionFormConfig,
41
43
  ActionInput: () => ActionInput,
@@ -54,6 +56,7 @@ __export(events_exports, {
54
56
  AsyncRejectActionDocument: () => AsyncRejectActionDocument,
55
57
  BaseActionInput: () => BaseActionInput,
56
58
  CONFIG_GET_ALLOWED_SCOPES: () => CONFIG_GET_ALLOWED_SCOPES,
59
+ CONFIG_SEARCH_ALLOWED_SCOPES: () => CONFIG_SEARCH_ALLOWED_SCOPES,
57
60
  CertificateConfig: () => CertificateConfig,
58
61
  CertificateTemplateConfig: () => CertificateTemplateConfig,
59
62
  CheckboxFieldValue: () => CheckboxFieldValue,
@@ -61,9 +64,13 @@ __export(events_exports, {
61
64
  Conditional: () => Conditional,
62
65
  ConditionalType: () => ConditionalType,
63
66
  ConfirmableActions: () => ConfirmableActions,
67
+ CustomFlags: () => CustomFlags,
68
+ DEFAULT_DATE_OF_EVENT_PROPERTY: () => DEFAULT_DATE_OF_EVENT_PROPERTY,
64
69
  DataEntry: () => DataEntry,
65
70
  DataFieldValue: () => DataFieldValue,
71
+ DateRangeFieldValue: () => DateRangeFieldValue,
66
72
  DateValue: () => DateValue,
73
+ DatetimeValue: () => DatetimeValue,
67
74
  DeclarationActionConfig: () => DeclarationActionConfig,
68
75
  DeclarationActions: () => DeclarationActions,
69
76
  DeclarationFormConfig: () => DeclarationFormConfig,
@@ -71,6 +78,7 @@ __export(events_exports, {
71
78
  DeclarationUpdateActions: () => DeclarationUpdateActions,
72
79
  DeclareActionInput: () => DeclareActionInput,
73
80
  DeduplicationConfig: () => DeduplicationConfig,
81
+ DeleteActionInput: () => DeleteActionInput,
74
82
  DisplayOnReviewConditional: () => DisplayOnReviewConditional,
75
83
  Draft: () => Draft,
76
84
  DraftInput: () => DraftInput,
@@ -79,20 +87,28 @@ __export(events_exports, {
79
87
  EnableConditional: () => EnableConditional,
80
88
  EventConfig: () => EventConfig,
81
89
  EventDocument: () => EventDocument,
90
+ EventFieldConfigSchema: () => EventFieldConfigSchema,
91
+ EventFieldId: () => EventFieldId,
82
92
  EventIndex: () => EventIndex,
83
93
  EventInput: () => EventInput,
84
94
  EventMetadata: () => EventMetadata,
95
+ EventMetadataKeys: () => EventMetadataKeys,
96
+ EventMetadataParameter: () => EventMetadataParameter,
85
97
  EventSearchIndex: () => EventSearchIndex,
98
+ EventState: () => EventState,
86
99
  EventStatus: () => EventStatus,
100
+ EventStatusEnum: () => EventStatusEnum,
87
101
  EventStatuses: () => EventStatuses,
88
102
  FieldConditional: () => FieldConditional,
89
103
  FieldConfig: () => FieldConfig,
104
+ FieldConfigSchema: () => FieldConfigSchema,
90
105
  FieldType: () => FieldType,
91
106
  FieldUpdateValue: () => FieldUpdateValue,
92
107
  FieldValue: () => FieldValue,
93
108
  FileFieldValue: () => FileFieldValue,
94
109
  FileFieldValueWithOption: () => FileFieldValueWithOption,
95
110
  FileFieldWithOptionValue: () => FileFieldWithOptionValue,
111
+ Flag: () => Flag,
96
112
  FormConfig: () => FormConfig,
97
113
  FormPageConfig: () => FormPageConfig,
98
114
  GenericAddressUpdateValue: () => GenericAddressUpdateValue,
@@ -100,23 +116,30 @@ __export(events_exports, {
100
116
  GeographicalArea: () => GeographicalArea,
101
117
  ImageMimeType: () => ImageMimeType,
102
118
  LanguageConfig: () => LanguageConfig,
119
+ LegalStatuses: () => LegalStatuses,
103
120
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
104
121
  MimeType: () => MimeType,
122
+ NonEmptyTextValue: () => NonEmptyTextValue,
105
123
  NotifyActionInput: () => NotifyActionInput,
106
124
  NumberFieldValue: () => NumberFieldValue,
107
125
  PageConfig: () => PageConfig,
108
126
  PageTypes: () => PageTypes,
109
127
  PrintCertificateActionInput: () => PrintCertificateActionInput,
128
+ QueryInput: () => QueryInput,
129
+ QueryType: () => QueryType,
110
130
  ReadActionInput: () => ReadActionInput,
111
131
  RegisterAction: () => RegisterAction,
112
132
  RegisterActionInput: () => RegisterActionInput,
133
+ RegistrationCreationMetadata: () => RegistrationCreationMetadata,
113
134
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
114
135
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
115
136
  RequestCorrectionActionInput: () => RequestCorrectionActionInput,
116
- RequiredTextValue: () => RequiredTextValue,
117
137
  ResolvedUser: () => ResolvedUser,
118
138
  RuralAddressUpdateValue: () => RuralAddressUpdateValue,
119
139
  RuralAddressValue: () => RuralAddressValue,
140
+ SearchField: () => SearchField,
141
+ SearchQueryParams: () => SearchQueryParams,
142
+ SelectOption: () => SelectOption,
120
143
  ShowConditional: () => ShowConditional,
121
144
  SummaryConfig: () => SummaryConfig,
122
145
  TextValue: () => TextValue,
@@ -128,6 +151,7 @@ __export(events_exports, {
128
151
  VerificationActionConfig: () => VerificationActionConfig,
129
152
  VerificationPageConfig: () => VerificationPageConfig,
130
153
  WorkqueueConfig: () => WorkqueueConfig,
154
+ ZodDate: () => ZodDate,
131
155
  alwaysTrue: () => alwaysTrue,
132
156
  and: () => and,
133
157
  annotationActions: () => annotationActions,
@@ -135,6 +159,8 @@ __export(events_exports, {
135
159
  areConditionsMet: () => areConditionsMet,
136
160
  compositeFieldTypes: () => compositeFieldTypes,
137
161
  createEmptyDraft: () => createEmptyDraft,
162
+ createEventConditionals: () => createEventConditionals,
163
+ createFieldConditionals: () => createFieldConditionals,
138
164
  createValidationSchema: () => createValidationSchema,
139
165
  deepDropNulls: () => deepDropNulls,
140
166
  deepMerge: () => deepMerge,
@@ -145,6 +171,7 @@ __export(events_exports, {
145
171
  defineFormConditional: () => defineFormConditional,
146
172
  defineFormPage: () => defineFormPage,
147
173
  definePage: () => definePage,
174
+ defineWorkqueue: () => defineWorkqueue,
148
175
  errorMessages: () => errorMessages,
149
176
  event: () => event,
150
177
  eventMetadataLabelMap: () => eventMetadataLabelMap,
@@ -170,13 +197,17 @@ __export(events_exports, {
170
197
  getActionAnnotationFields: () => getActionAnnotationFields,
171
198
  getActionReview: () => getActionReview,
172
199
  getActionReviewFields: () => getActionReviewFields,
173
- getAllAnnotationFields: () => getAllAnnotationFields,
200
+ getActionVerificationPageIds: () => getActionVerificationPageIds,
174
201
  getAnnotationFromDrafts: () => getAnnotationFromDrafts,
202
+ getAssignedUserFromActions: () => getAssignedUserFromActions,
175
203
  getCurrentEventState: () => getCurrentEventState,
176
204
  getCurrentEventStateWithDrafts: () => getCurrentEventStateWithDrafts,
177
205
  getDeclaration: () => getDeclaration,
178
206
  getDeclarationFields: () => getDeclarationFields,
179
207
  getDeclarationPages: () => getDeclarationPages,
208
+ getMixedPath: () => getMixedPath,
209
+ getRandomDatetime: () => getRandomDatetime,
210
+ getVisibleVerificationPageIds: () => getVisibleVerificationPageIds,
180
211
  hasAnyOfScopes: () => hasAnyOfScopes,
181
212
  isAddressFieldType: () => isAddressFieldType,
182
213
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
@@ -186,6 +217,7 @@ __export(events_exports, {
186
217
  isCountryFieldType: () => isCountryFieldType,
187
218
  isDataFieldType: () => isDataFieldType,
188
219
  isDateFieldType: () => isDateFieldType,
220
+ isDateRangeFieldType: () => isDateRangeFieldType,
189
221
  isDividerFieldType: () => isDividerFieldType,
190
222
  isEmailFieldType: () => isEmailFieldType,
191
223
  isFacilityFieldType: () => isFacilityFieldType,
@@ -217,6 +249,7 @@ __export(events_exports, {
217
249
  mapFieldTypeToZod: () => mapFieldTypeToZod,
218
250
  never: () => never,
219
251
  not: () => not,
252
+ omitHiddenAnnotationFields: () => omitHiddenAnnotationFields,
220
253
  omitHiddenFields: () => omitHiddenFields,
221
254
  omitHiddenPaginatedFields: () => omitHiddenPaginatedFields,
222
255
  or: () => or,
@@ -224,7 +257,6 @@ __export(events_exports, {
224
257
  user: () => user,
225
258
  validate: () => validate,
226
259
  validateFieldInput: () => validateFieldInput,
227
- validateWorkqueueConfig: () => validateWorkqueueConfig,
228
260
  writeActions: () => writeActions
229
261
  });
230
262
  module.exports = __toCommonJS(events_exports);
@@ -234,9 +266,12 @@ var import_zod9 = require("zod");
234
266
 
235
267
  // ../commons/src/events/Conditional.ts
236
268
  var import_zod = require("zod");
237
- var Conditional = import_zod.z.custom(
238
- (val) => typeof val === "object" && val !== null
239
- );
269
+ var import_zod_openapi = require("zod-openapi");
270
+ (0, import_zod_openapi.extendZodWithOpenApi)(import_zod.z);
271
+ var Conditional = import_zod.z.custom((val) => typeof val === "object" && val !== null).openapi({
272
+ description: "JSON schema conditional configuration",
273
+ ref: "Conditional"
274
+ });
240
275
  var ConditionalType = {
241
276
  SHOW: "SHOW",
242
277
  ENABLE: "ENABLE",
@@ -273,7 +308,10 @@ var FieldConditional = import_zod.z.discriminatedUnion("type", [
273
308
  EnableConditional,
274
309
  // Field output can be shown / hidden on the review page
275
310
  DisplayOnReviewConditional
276
- ]);
311
+ ]).openapi({
312
+ description: "Field conditional configuration",
313
+ ref: "FieldConditional"
314
+ });
277
315
 
278
316
  // ../commons/src/events/PageConfig.ts
279
317
  var import_zod6 = require("zod");
@@ -283,6 +321,8 @@ var import_zod5 = require("zod");
283
321
 
284
322
  // ../commons/src/events/TranslationConfig.ts
285
323
  var import_zod2 = require("zod");
324
+ var import_zod_openapi2 = require("zod-openapi");
325
+ (0, import_zod_openapi2.extendZodWithOpenApi)(import_zod2.z);
286
326
  var TranslationConfig = import_zod2.z.object({
287
327
  id: import_zod2.z.string().describe(
288
328
  "The identifier of the translation referred in translation CSV files"
@@ -291,6 +331,9 @@ var TranslationConfig = import_zod2.z.object({
291
331
  description: import_zod2.z.string().describe(
292
332
  "Describe the translation for a translator to be able to identify it."
293
333
  )
334
+ }).openapi({
335
+ description: "Translation configuration",
336
+ ref: "TranslationConfig"
294
337
  });
295
338
 
296
339
  // ../commons/src/events/FieldType.ts
@@ -301,12 +344,12 @@ var FieldType = {
301
344
  TEXTAREA: "TEXTAREA",
302
345
  EMAIL: "EMAIL",
303
346
  DATE: "DATE",
347
+ DATE_RANGE: "DATE_RANGE",
304
348
  PARAGRAPH: "PARAGRAPH",
305
349
  PAGE_HEADER: "PAGE_HEADER",
306
350
  RADIO_GROUP: "RADIO_GROUP",
307
351
  FILE: "FILE",
308
352
  FILE_WITH_OPTIONS: "FILE_WITH_OPTIONS",
309
- HIDDEN: "HIDDEN",
310
353
  BULLET_LIST: "BULLET_LIST",
311
354
  CHECKBOX: "CHECKBOX",
312
355
  SELECT: "SELECT",
@@ -321,6 +364,7 @@ var FieldType = {
321
364
  };
322
365
  var fieldTypes = Object.values(FieldType);
323
366
  var compositeFieldTypes = [
367
+ FieldType.DATE_RANGE,
324
368
  FieldType.ADDRESS,
325
369
  FieldType.FILE_WITH_OPTIONS,
326
370
  FieldType.FILE
@@ -411,8 +455,10 @@ var FileFieldWithOptionValue = import_zod3.z.array(FileFieldValueWithOption);
411
455
 
412
456
  // ../commons/src/events/FieldValue.ts
413
457
  var TextValue = import_zod4.z.string();
414
- var RequiredTextValue = TextValue.min(1);
458
+ var NonEmptyTextValue = TextValue.min(1);
415
459
  var DateValue = import_zod4.z.string().date().describe("Date in the format YYYY-MM-DD");
460
+ var DatetimeValue = import_zod4.z.string().datetime();
461
+ var DateRangeFieldValue = DateValue.or(import_zod4.z.tuple([DateValue, DateValue]));
416
462
  var EmailValue = import_zod4.z.string().email();
417
463
  var CheckboxFieldValue = import_zod4.z.boolean();
418
464
  var NumberFieldValue = import_zod4.z.number();
@@ -420,6 +466,7 @@ var DataFieldValue = import_zod4.z.undefined();
420
466
  var FieldValue = import_zod4.z.union([
421
467
  TextValue,
422
468
  DateValue,
469
+ DateRangeFieldValue,
423
470
  CheckboxFieldValue,
424
471
  NumberFieldValue,
425
472
  FileFieldValue,
@@ -432,6 +479,7 @@ var FieldValue = import_zod4.z.union([
432
479
  var FieldUpdateValue = import_zod4.z.union([
433
480
  TextValue,
434
481
  DateValue,
482
+ DateRangeFieldValue,
435
483
  CheckboxFieldValue,
436
484
  NumberFieldValue,
437
485
  FileFieldValue,
@@ -443,28 +491,24 @@ var FieldUpdateValue = import_zod4.z.union([
443
491
  ]);
444
492
 
445
493
  // ../commons/src/events/FieldConfig.ts
494
+ var import_zod_openapi3 = require("zod-openapi");
495
+ (0, import_zod_openapi3.extendZodWithOpenApi)(import_zod5.z);
446
496
  var FieldId = import_zod5.z.string();
447
- var DependencyExpression = import_zod5.z.object({
448
- dependsOn: import_zod5.z.array(FieldId).default([]),
449
- expression: import_zod5.z.string()
450
- });
497
+ var ParentReference = import_zod5.z.object({
498
+ _fieldId: FieldId.optional()
499
+ }).optional();
451
500
  var BaseField = import_zod5.z.object({
452
501
  id: FieldId,
453
502
  defaultValue: import_zod5.z.union([
454
- // These are the currently supported default values types
455
- import_zod5.z.union([
456
- TextValue,
457
- RequiredTextValue,
458
- DateValue,
459
- NumberFieldValue,
460
- CheckboxFieldValue
461
- ]),
462
- DependencyExpression
503
+ TextValue,
504
+ NonEmptyTextValue,
505
+ DateValue,
506
+ NumberFieldValue,
507
+ CheckboxFieldValue
463
508
  ]).optional(),
509
+ parent: ParentReference,
464
510
  conditionals: import_zod5.z.array(FieldConditional).default([]).optional(),
465
511
  required: import_zod5.z.boolean().default(false).optional(),
466
- disabled: import_zod5.z.boolean().default(false).optional(),
467
- hidden: import_zod5.z.boolean().default(false).optional(),
468
512
  placeholder: TranslationConfig.optional(),
469
513
  validation: import_zod5.z.array(
470
514
  import_zod5.z.object({
@@ -472,8 +516,8 @@ var BaseField = import_zod5.z.object({
472
516
  message: TranslationConfig
473
517
  })
474
518
  ).default([]).optional(),
475
- dependsOn: import_zod5.z.array(FieldId).default([]).optional(),
476
519
  label: TranslationConfig,
520
+ helperText: TranslationConfig.optional(),
477
521
  hideLabel: import_zod5.z.boolean().default(false).optional()
478
522
  });
479
523
  var Divider = BaseField.extend({
@@ -481,7 +525,7 @@ var Divider = BaseField.extend({
481
525
  });
482
526
  var TextField = BaseField.extend({
483
527
  type: import_zod5.z.literal(FieldType.TEXT),
484
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
528
+ defaultValue: NonEmptyTextValue.optional(),
485
529
  configuration: import_zod5.z.object({
486
530
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text"),
487
531
  type: import_zod5.z.enum(["text", "password"]).optional(),
@@ -491,7 +535,7 @@ var TextField = BaseField.extend({
491
535
  }).describe("Text input");
492
536
  var NumberField = BaseField.extend({
493
537
  type: import_zod5.z.literal(FieldType.NUMBER),
494
- defaultValue: import_zod5.z.union([NumberFieldValue, DependencyExpression]).optional(),
538
+ defaultValue: NumberFieldValue.optional(),
495
539
  configuration: import_zod5.z.object({
496
540
  min: import_zod5.z.number().optional().describe("Minimum value"),
497
541
  max: import_zod5.z.number().optional().describe("Maximum value"),
@@ -501,7 +545,7 @@ var NumberField = BaseField.extend({
501
545
  }).describe("Number input");
502
546
  var TextAreaField = BaseField.extend({
503
547
  type: import_zod5.z.literal(FieldType.TEXTAREA),
504
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
548
+ defaultValue: NonEmptyTextValue.optional(),
505
549
  configuration: import_zod5.z.object({
506
550
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text"),
507
551
  rows: import_zod5.z.number().optional().describe("Number of visible text lines"),
@@ -535,17 +579,28 @@ var EmailField = BaseField.extend({
535
579
  configuration: import_zod5.z.object({
536
580
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text")
537
581
  }).default({ maxLength: 10 }).optional(),
538
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
582
+ defaultValue: NonEmptyTextValue.optional()
539
583
  });
540
584
  var DateField = BaseField.extend({
541
585
  type: import_zod5.z.literal(FieldType.DATE),
542
- defaultValue: import_zod5.z.union([DateValue, DependencyExpression]).optional(),
586
+ defaultValue: DateValue.optional(),
543
587
  configuration: import_zod5.z.object({
544
588
  notice: TranslationConfig.describe(
545
589
  "Text to display above the date input"
546
590
  ).optional()
547
591
  }).optional()
548
592
  }).describe("A single date input (dd-mm-YYYY)");
593
+ var DateRangeField = BaseField.extend({
594
+ type: import_zod5.z.literal(FieldType.DATE_RANGE),
595
+ defaultValue: DateRangeFieldValue.optional(),
596
+ configuration: import_zod5.z.object({
597
+ notice: TranslationConfig.describe(
598
+ "Text to display above the date input"
599
+ ).optional()
600
+ }).optional()
601
+ }).describe(
602
+ "A date range input ({ rangeStart: dd-mm-YYYY, rangeEnd: dd-mm-YYYY })"
603
+ );
549
604
  var HtmlFontVariant = import_zod5.z.enum([
550
605
  "reg12",
551
606
  "reg14",
@@ -558,7 +613,7 @@ var HtmlFontVariant = import_zod5.z.enum([
558
613
  ]);
559
614
  var Paragraph = BaseField.extend({
560
615
  type: import_zod5.z.literal(FieldType.PARAGRAPH),
561
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
616
+ defaultValue: NonEmptyTextValue.optional(),
562
617
  configuration: import_zod5.z.object({
563
618
  styles: import_zod5.z.object({
564
619
  fontVariant: HtmlFontVariant.optional()
@@ -567,7 +622,7 @@ var Paragraph = BaseField.extend({
567
622
  }).describe("A read-only HTML <p> paragraph");
568
623
  var PageHeader = BaseField.extend({
569
624
  type: import_zod5.z.literal(FieldType.PAGE_HEADER),
570
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
625
+ defaultValue: NonEmptyTextValue.optional()
571
626
  }).describe("A read-only header component for form pages");
572
627
  var File = BaseField.extend({
573
628
  type: import_zod5.z.literal(FieldType.FILE),
@@ -590,7 +645,7 @@ var SelectOption = import_zod5.z.object({
590
645
  });
591
646
  var RadioGroup = BaseField.extend({
592
647
  type: import_zod5.z.literal(FieldType.RADIO_GROUP),
593
- defaultValue: import_zod5.z.union([TextValue, DependencyExpression]).optional(),
648
+ defaultValue: TextValue.optional(),
594
649
  options: import_zod5.z.array(SelectOption).describe("A list of options"),
595
650
  configuration: import_zod5.z.object({
596
651
  styles: import_zod5.z.object({
@@ -600,7 +655,7 @@ var RadioGroup = BaseField.extend({
600
655
  }).describe("Grouped radio options");
601
656
  var BulletList = BaseField.extend({
602
657
  type: import_zod5.z.literal(FieldType.BULLET_LIST),
603
- defaultValue: import_zod5.z.string().optional(),
658
+ defaultValue: TextValue.optional(),
604
659
  items: import_zod5.z.array(TranslationConfig).describe("A list of items"),
605
660
  configuration: import_zod5.z.object({
606
661
  styles: import_zod5.z.object({
@@ -610,16 +665,16 @@ var BulletList = BaseField.extend({
610
665
  }).describe("A list of bullet points");
611
666
  var Select = BaseField.extend({
612
667
  type: import_zod5.z.literal(FieldType.SELECT),
613
- defaultValue: import_zod5.z.union([TextValue, DependencyExpression]).optional(),
668
+ defaultValue: TextValue.optional(),
614
669
  options: import_zod5.z.array(SelectOption).describe("A list of options")
615
670
  }).describe("Select input");
616
671
  var Checkbox = BaseField.extend({
617
672
  type: import_zod5.z.literal(FieldType.CHECKBOX),
618
- defaultValue: import_zod5.z.union([CheckboxFieldValue, DependencyExpression]).optional()
673
+ defaultValue: CheckboxFieldValue.optional()
619
674
  }).describe("Boolean checkbox field");
620
675
  var Country = BaseField.extend({
621
676
  type: import_zod5.z.literal(FieldType.COUNTRY),
622
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
677
+ defaultValue: NonEmptyTextValue.optional()
623
678
  }).describe("Country select field");
624
679
  var AdministrativeAreas = import_zod5.z.enum([
625
680
  "ADMIN_STRUCTURE",
@@ -634,12 +689,12 @@ var AdministrativeAreaConfiguration = import_zod5.z.object({
634
689
  }).describe("Administrative area options");
635
690
  var AdministrativeArea = BaseField.extend({
636
691
  type: import_zod5.z.literal(FieldType.ADMINISTRATIVE_AREA),
637
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
692
+ defaultValue: NonEmptyTextValue.optional(),
638
693
  configuration: AdministrativeAreaConfiguration
639
694
  }).describe("Administrative area input field e.g. facility, office");
640
695
  var Location = BaseField.extend({
641
696
  type: import_zod5.z.literal(FieldType.LOCATION),
642
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
697
+ defaultValue: NonEmptyTextValue.optional()
643
698
  }).describe("Input field for a location");
644
699
  var FileUploadWithOptions = BaseField.extend({
645
700
  type: import_zod5.z.literal(FieldType.FILE_WITH_OPTIONS),
@@ -653,11 +708,11 @@ var FileUploadWithOptions = BaseField.extend({
653
708
  });
654
709
  var Facility = BaseField.extend({
655
710
  type: import_zod5.z.literal(FieldType.FACILITY),
656
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
711
+ defaultValue: NonEmptyTextValue.optional()
657
712
  }).describe("Input field for a facility");
658
713
  var Office = BaseField.extend({
659
714
  type: import_zod5.z.literal(FieldType.OFFICE),
660
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
715
+ defaultValue: NonEmptyTextValue.optional()
661
716
  }).describe("Input field for an office");
662
717
  var Address = BaseField.extend({
663
718
  type: import_zod5.z.literal(FieldType.ADDRESS),
@@ -685,6 +740,7 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
685
740
  NumberField,
686
741
  TextAreaField,
687
742
  DateField,
743
+ DateRangeField,
688
744
  Paragraph,
689
745
  RadioGroup,
690
746
  BulletList,
@@ -702,10 +758,14 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
702
758
  EmailField,
703
759
  FileUploadWithOptions,
704
760
  DataField
705
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
706
- ]);
761
+ ]).openapi({
762
+ description: "Form field configuration",
763
+ ref: "FieldConfig"
764
+ });
707
765
 
708
766
  // ../commons/src/events/PageConfig.ts
767
+ var import_zod_openapi4 = require("zod-openapi");
768
+ (0, import_zod_openapi4.extendZodWithOpenApi)(import_zod6.z);
709
769
  var PageTypes = import_zod6.z.enum(["FORM", "VERIFICATION"]);
710
770
  var PageConfigBase = import_zod6.z.object({
711
771
  id: import_zod6.z.string().describe("Unique identifier for the page"),
@@ -714,6 +774,9 @@ var PageConfigBase = import_zod6.z.object({
714
774
  conditional: Conditional.optional().describe(
715
775
  "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
716
776
  )
777
+ }).openapi({
778
+ description: "Form page configuration",
779
+ ref: "FormPageConfig"
717
780
  });
718
781
  var FormPageConfig = PageConfigBase.extend({
719
782
  type: import_zod6.z.literal(PageTypes.enum.FORM).default(PageTypes.enum.FORM)
@@ -727,7 +790,10 @@ var VerificationActionConfig = import_zod6.z.object({
727
790
  body: TranslationConfig
728
791
  })
729
792
  })
730
- }).describe("Actions available on the verification page");
793
+ }).describe("Actions available on the verification page").openapi({
794
+ description: "Verification action configuration",
795
+ ref: "VerificationActionConfig"
796
+ });
731
797
  var VerificationPageConfig = FormPageConfig.extend({
732
798
  type: import_zod6.z.literal(PageTypes.enum.VERIFICATION),
733
799
  actions: VerificationActionConfig
@@ -827,6 +893,8 @@ var ActionFormConfig = import_zod8.z.object({
827
893
  var FormConfig = import_zod8.z.union([DeclarationFormConfig, ActionFormConfig]);
828
894
 
829
895
  // ../commons/src/events/ActionConfig.ts
896
+ var import_zod_openapi5 = require("zod-openapi");
897
+ (0, import_zod_openapi5.extendZodWithOpenApi)(import_zod9.z);
830
898
  var ActionConditional2 = import_zod9.z.discriminatedUnion("type", [
831
899
  /** If conditional is defined, the action is shown to the user only if the condition is met */
832
900
  ShowConditional,
@@ -904,18 +972,24 @@ var ApproveCorrectionConfig = ActionConfigBase.merge(
904
972
  })
905
973
  );
906
974
  var ActionConfig = import_zod9.z.discriminatedUnion("type", [
907
- DeclareConfig,
908
- ValidateConfig,
909
- RejectDeclarationConfig,
910
- MarkedAsDuplicateConfig,
911
- ArchiveConfig,
912
- RegisterConfig,
913
- DeleteConfig,
914
- PrintCertificateActionConfig,
915
- RequestCorrectionConfig,
916
- RejectCorrectionConfig,
917
- ApproveCorrectionConfig
918
- ]);
975
+ /*
976
+ * OpenAPI references are defined here so our generated OpenAPI spec knows to reuse the models
977
+ * and treat them as "models" instead of duplicating the data structure in each endpoint.
978
+ */
979
+ DeclareConfig.openapi({ ref: "DeclareActionConfig" }),
980
+ ValidateConfig.openapi({ ref: "ValidateActionConfig" }),
981
+ RejectDeclarationConfig.openapi({ ref: "RejectDeclarationActionConfig" }),
982
+ MarkedAsDuplicateConfig.openapi({ ref: "MarkedAsDuplicateActionConfig" }),
983
+ ArchiveConfig.openapi({ ref: "ArchiveActionConfig" }),
984
+ RegisterConfig.openapi({ ref: "RegisterActionConfig" }),
985
+ DeleteConfig.openapi({ ref: "DeleteActionConfig" }),
986
+ PrintCertificateActionConfig.openapi({
987
+ ref: "PrintCertificateActionConfig"
988
+ }),
989
+ RequestCorrectionConfig.openapi({ ref: "RequestCorrectionActionConfig" }),
990
+ RejectCorrectionConfig.openapi({ ref: "RejectCorrectionActionConfig" }),
991
+ ApproveCorrectionConfig.openapi({ ref: "ApproveCorrectionActionConfig" })
992
+ ]).openapi({ ref: "ActionConfig" });
919
993
  var DeclarationActionConfig = import_zod9.z.discriminatedUnion("type", [
920
994
  DeclareConfig,
921
995
  ValidateConfig,
@@ -959,10 +1033,12 @@ var LanguageConfig = import_zod11.z.object({
959
1033
  });
960
1034
 
961
1035
  // ../commons/src/events/EventConfig.ts
962
- var import_zod20 = require("zod");
1036
+ var import_zod17 = require("zod");
963
1037
 
964
1038
  // ../commons/src/events/DeduplicationConfig.ts
965
1039
  var import_zod12 = require("zod");
1040
+ var import_zod_openapi6 = require("zod-openapi");
1041
+ (0, import_zod_openapi6.extendZodWithOpenApi)(import_zod12.z);
966
1042
  var FieldReference = import_zod12.z.string();
967
1043
  var Matcher = import_zod12.z.object({
968
1044
  fieldId: import_zod12.z.string(),
@@ -1023,7 +1099,9 @@ var Clause = import_zod12.z.lazy(
1023
1099
  DateRangeMatcher,
1024
1100
  DateDistanceMatcher
1025
1101
  ])
1026
- );
1102
+ ).openapi({
1103
+ ref: "Clause"
1104
+ });
1027
1105
  var DeduplicationConfig = import_zod12.z.object({
1028
1106
  id: import_zod12.z.string(),
1029
1107
  label: TranslationConfig,
@@ -1037,7 +1115,10 @@ var BaseField2 = import_zod13.z.object({
1037
1115
  conditionals: import_zod13.z.array(ShowConditional).default([]).optional()
1038
1116
  });
1039
1117
  var ReferenceField = BaseField2.extend({
1040
- fieldId: import_zod13.z.string()
1118
+ fieldId: import_zod13.z.string(),
1119
+ label: TranslationConfig.optional().describe(
1120
+ "By default, the configured field's label is used. This can be overridden by providing a custom label."
1121
+ )
1041
1122
  }).describe("Field directly referencing event data with field id");
1042
1123
  var Field = BaseField2.extend({
1043
1124
  id: import_zod13.z.string().describe("Id of summary field"),
@@ -1047,262 +1128,233 @@ var Field = BaseField2.extend({
1047
1128
  label: TranslationConfig,
1048
1129
  emptyValueMessage: TranslationConfig.optional()
1049
1130
  }).describe("Custom configured field");
1050
- var Title = import_zod13.z.object({
1051
- id: import_zod13.z.string(),
1052
- label: TranslationConfig.describe("Title content"),
1053
- emptyValueMessage: TranslationConfig.optional()
1054
- });
1055
1131
  var SummaryConfig = import_zod13.z.object({
1056
- title: Title.describe("Title of summary view."),
1057
1132
  fields: import_zod13.z.array(import_zod13.z.union([Field, ReferenceField])).describe("Fields rendered in summary view.")
1058
1133
  }).describe("Configuration for summary in event.");
1059
1134
 
1060
- // ../commons/src/events/WorkqueueConfig.ts
1061
- var import_zod15 = require("zod");
1062
-
1063
- // ../commons/src/events/EventMetadata.ts
1135
+ // ../commons/src/events/AdvancedSearchConfig.ts
1064
1136
  var import_zod14 = require("zod");
1065
- var EventStatus = {
1066
- CREATED: "CREATED",
1067
- NOTIFIED: "NOTIFIED",
1068
- DECLARED: "DECLARED",
1069
- VALIDATED: "VALIDATED",
1070
- REGISTERED: "REGISTERED",
1071
- CERTIFIED: "CERTIFIED",
1072
- REJECTED: "REJECTED",
1073
- ARCHIVED: "ARCHIVED"
1074
- };
1075
- var eventStatuses = Object.values(EventStatus);
1076
- var EventStatuses = import_zod14.z.nativeEnum(EventStatus);
1077
- var EventMetadata = import_zod14.z.object({
1078
- id: import_zod14.z.string(),
1079
- type: import_zod14.z.string(),
1080
- status: EventStatuses,
1081
- createdAt: import_zod14.z.string().datetime(),
1082
- createdBy: import_zod14.z.string(),
1083
- createdAtLocation: import_zod14.z.string(),
1084
- updatedAtLocation: import_zod14.z.string(),
1085
- modifiedAt: import_zod14.z.string().datetime(),
1086
- assignedTo: import_zod14.z.string().nullish(),
1087
- updatedBy: import_zod14.z.string(),
1088
- trackingId: import_zod14.z.string(),
1089
- registrationNumber: import_zod14.z.string().nullish()
1090
- });
1091
- var eventMetadataLabelMap = {
1092
- "event.assignedTo": {
1093
- id: "event.assignedTo.label",
1094
- defaultMessage: "Assigned To",
1095
- description: "Assigned To"
1096
- },
1097
- "event.createdAt": {
1098
- id: "event.createdAt.label",
1099
- defaultMessage: "Created",
1100
- description: "Created At"
1101
- },
1102
- "event.createdAtLocation": {
1103
- id: "event.createdAtLocation.label",
1104
- defaultMessage: "Location",
1105
- description: "Created At Location"
1106
- },
1107
- "event.updatedAtLocation": {
1108
- id: "event.updatedAtLocation.label",
1109
- defaultMessage: "Location",
1110
- description: "Updated At Location"
1111
- },
1112
- "event.createdBy": {
1113
- id: "event.createdBy.label",
1114
- defaultMessage: "Created By",
1115
- description: "Created By"
1116
- },
1117
- "event.id": {
1118
- id: "event.id.label",
1119
- defaultMessage: "ID",
1120
- description: "ID"
1121
- },
1122
- "event.modifiedAt": {
1123
- id: "event.modifiedAt.label",
1124
- defaultMessage: "Updated",
1125
- description: "Modified At"
1126
- },
1127
- "event.status": {
1128
- id: "event.status.label",
1129
- defaultMessage: "Status",
1130
- description: "Status"
1131
- },
1132
- "event.type": {
1133
- id: "event.type.label",
1134
- defaultMessage: "Type",
1135
- description: "Type"
1136
- },
1137
- "event.updatedBy": {
1138
- id: "event.updatedBy.label",
1139
- defaultMessage: "Updated By",
1140
- description: "Updated By"
1141
- },
1142
- "event.trackingId": {
1143
- id: "event.trackingId.label",
1144
- defaultMessage: "Tracking ID",
1145
- description: "Tracking ID"
1146
- },
1147
- "event.registrationNumber": {
1148
- id: "event.registrationNumber.label",
1149
- defaultMessage: "Registration Number",
1150
- description: "Registration Number"
1151
- }
1152
- };
1137
+ var MatchType = import_zod14.z.enum(["fuzzy", "exact", "range"]);
1138
+ var BaseField3 = import_zod14.z.object({
1139
+ config: import_zod14.z.object({
1140
+ type: MatchType.describe("Determines the type of field")
1141
+ }),
1142
+ options: import_zod14.z.array(SelectOption).optional(),
1143
+ searchCriteriaLabelPrefix: TranslationConfig.optional().describe(
1144
+ `
1145
+ This property determines whether to add a prefix (such as "Child" or "Applicant") before the field label
1146
+ when rendering search parameter labels \u2014 for example, in the search results page to indicate which fields were used in the search.
1153
1147
 
1154
- // ../commons/src/events/WorkqueueConfig.ts
1155
- var WorkqueueConfig = import_zod15.z.object({
1156
- id: import_zod15.z.string().describe("Unique identifier for workqueue."),
1157
- filters: import_zod15.z.array(
1158
- import_zod15.z.object({
1159
- status: import_zod15.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
1160
- })
1161
- ).describe("Filters to be applied to workqueue.")
1162
- }).describe("Configuration for workqueue.");
1148
+ For example, a field config like { id: "child.firstname", label: { defaultMessage: "First Name(s)" } } would render as "First Name(s)" by default.
1163
1149
 
1164
- // ../commons/src/events/AdvancedSearchConfig.ts
1165
- var import_zod16 = require("zod");
1166
- var AdvancedSearchConfig = import_zod16.z.object({
1167
- title: TranslationConfig.describe("Advanced search tab title"),
1168
- fields: import_zod16.z.array(
1169
- import_zod16.z.object({
1170
- fieldId: import_zod16.z.string(),
1171
- config: import_zod16.z.object({
1172
- type: import_zod16.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
1173
- }).optional().describe("Configuration options for the field")
1174
- })
1175
- ).optional().default([]).describe("Advanced search fields.")
1176
- });
1150
+ A field config like { id: "mother.firstname", label: { defaultMessage: "First Name(s)" } } would also render as "First Name(s)" by default.
1177
1151
 
1178
- // ../commons/src/events/utils.ts
1179
- var import_lodash = require("lodash");
1152
+ So, if both child.firstname and mother.firstname are used in a search, the resulting search criteria labels would be "First Name(s)", "First Name(s)",
1153
+ which is ambiguous.
1180
1154
 
1181
- // ../commons/src/workqueues/WorkqueueConfig.ts
1182
- var import_zod18 = require("zod");
1155
+ Now, if we treat the field ID prefix as a label (e.g., "applicant.firstname" \u2192 "Applicant"), and the field label is already
1156
+ descriptive \u2014 like { id: "applicant.firstname", label: { defaultMessage: "Applicant's First Name" } } \u2014 then the resulting
1157
+ label would be "Applicant Applicant's First Name", which is redundant and awkward.
1183
1158
 
1184
- // ../commons/src/workqueues/defaultColumns.ts
1185
- var import_zod17 = require("zod");
1186
- var WorkQueueColumnConfig = import_zod17.z.object({
1187
- id: import_zod17.z.string(),
1188
- label: TranslationConfig
1159
+ By setting searchCriteriaLabelPrefix to a translation config object, we can explicitly define the desired prefix
1160
+ in the country-config > event.advancedSearch configuration. For example: field("child.dob", { searchCriteriaLabelPrefix: TranslationConfig }).
1161
+ `
1162
+ ),
1163
+ conditionals: import_zod14.z.array(FieldConditional).default([]).optional().describe(
1164
+ `
1165
+ In advanced search, we sometimes need to override the default field visibility conditionals.
1166
+
1167
+ For example, Informant fields in the declaration form may have conditional logic
1168
+ that hides them based on other field values. Since the advanced search form reuses
1169
+ the declaration form config, those same conditionals would apply by default.
1170
+
1171
+ However, in advanced search we often want to make all Informant fields searchable,
1172
+ regardless of their original visibility logic. To do this, we explicitly set their
1173
+ 'conditionals' to an empty array ('[]') in the search config. This ensures they
1174
+ are always rendered in the advanced search form.
1175
+ `
1176
+ )
1189
1177
  });
1190
- var defaultColumns = {
1191
- event: {
1192
- id: "event",
1193
- label: {
1194
- defaultMessage: "Event",
1195
- description: "This is the label for the workqueue column",
1196
- id: "workqueue.default.column.event"
1197
- }
1198
- },
1199
- status: {
1200
- id: "status",
1201
- label: {
1202
- defaultMessage: "Status",
1203
- description: "This is the label for the workqueue column",
1204
- id: "workqueue.default.column.status"
1205
- }
1206
- },
1207
- createdAt: {
1208
- id: "createdAt",
1209
- label: {
1210
- defaultMessage: "Created",
1211
- description: "This is the label for the workqueue column",
1212
- id: "workqueue.default.column.createdAt"
1213
- }
1214
- },
1215
- modifiedAt: {
1216
- id: "modifiedAt",
1217
- label: {
1218
- defaultMessage: "Modified",
1219
- description: "This is the label for the workqueue column",
1220
- id: "workqueue.default.column.modifiedAt"
1221
- }
1222
- }
1223
- };
1224
- var DefaultColumnKeys = import_zod17.z.enum(
1225
- Object.keys(defaultColumns)
1226
- );
1227
-
1228
- // ../commons/src/workqueues/WorkqueueConfig.ts
1229
- var rootWorkqueueConfig = import_zod18.z.object({
1230
- id: import_zod18.z.string(),
1231
- title: TranslationConfig,
1232
- columns: import_zod18.z.array(WorkQueueColumnConfig),
1233
- defaultColumns: import_zod18.z.array(DefaultColumnKeys)
1178
+ var SearchQueryParams = import_zod14.z.object({
1179
+ eventType: import_zod14.z.string().optional().describe(
1180
+ "Defines type of event so that when redirecting to Advanced Search page, appropriate tab can be selected"
1181
+ )
1182
+ }).catchall(FieldValue);
1183
+ var FieldConfigSchema = BaseField3.extend({
1184
+ fieldId: import_zod14.z.string(),
1185
+ fieldType: import_zod14.z.literal("field")
1234
1186
  });
1235
- var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
1236
-
1237
- // ../commons/src/workqueues/all.ts
1238
- var allWorkqueue = defineWorkqueue({
1239
- id: "all",
1240
- title: {
1241
- defaultMessage: "All events",
1242
- description: "This is the label for the workqueue",
1243
- id: "workqueue.all.label"
1244
- },
1245
- columns: [
1246
- {
1247
- id: "title",
1248
- label: {
1249
- defaultMessage: "Title",
1250
- description: "This is the label for the workqueue column",
1251
- id: "workqueue.all.column.title"
1252
- }
1253
- }
1254
- ],
1255
- defaultColumns: ["event", "status", "createdAt", "modifiedAt"]
1187
+ var EventFieldId = import_zod14.z.enum([
1188
+ "trackingId",
1189
+ "status",
1190
+ "legalStatus.REGISTERED.createdAt",
1191
+ "legalStatus.REGISTERED.createdAtLocation",
1192
+ "updatedAt"
1193
+ ]);
1194
+ var EventFieldConfigSchema = BaseField3.extend({
1195
+ fieldId: EventFieldId,
1196
+ fieldType: import_zod14.z.literal("event")
1256
1197
  });
1257
-
1258
- // ../commons/src/workqueues/readyForReview.ts
1259
- var inReviewWorkqueue = defineWorkqueue({
1260
- id: "ready-for-review",
1261
- title: {
1262
- defaultMessage: "Ready for review",
1263
- description: "Label for in review workqueue",
1264
- id: "event.workqueue.in-review.label"
1265
- },
1266
- columns: [
1267
- {
1268
- id: "title",
1269
- label: {
1270
- defaultMessage: "Title",
1271
- description: "This is the label for the workqueue column",
1272
- id: "workqueue.in-reveiw.column.title"
1273
- }
1274
- }
1275
- ],
1276
- defaultColumns: ["event", "createdAt", "modifiedAt"]
1198
+ var SearchField = import_zod14.z.discriminatedUnion("fieldType", [
1199
+ FieldConfigSchema,
1200
+ EventFieldConfigSchema
1201
+ ]);
1202
+ var AdvancedSearchConfig = import_zod14.z.object({
1203
+ title: TranslationConfig.describe("Advanced search tab title"),
1204
+ fields: import_zod14.z.array(SearchField).describe("Advanced search fields.")
1277
1205
  });
1278
1206
 
1279
- // ../commons/src/workqueues/readyToPrint.ts
1280
- var registeredWorkqueue = defineWorkqueue({
1281
- id: "registered",
1282
- title: {
1283
- defaultMessage: "Ready to print",
1284
- description: "Label for registered workqueue",
1285
- id: "event.workqueue.registered.label"
1286
- },
1287
- columns: [
1288
- {
1289
- id: "title",
1290
- label: {
1291
- defaultMessage: "Title",
1292
- description: "This is the label for the workqueue column",
1293
- id: "workqueue.registered.column.title"
1294
- }
1295
- }
1296
- ],
1297
- defaultColumns: ["event", "createdAt", "modifiedAt"]
1298
- });
1207
+ // ../commons/src/events/utils.ts
1208
+ var import_lodash = require("lodash");
1299
1209
 
1300
- // ../commons/src/workqueues/index.ts
1301
- var workqueues = {
1302
- all: allWorkqueue,
1303
- registered: registeredWorkqueue,
1304
- inReview: inReviewWorkqueue
1210
+ // ../commons/src/events/ActionDocument.ts
1211
+ var import_zod15 = require("zod");
1212
+ var import_zod_openapi7 = require("zod-openapi");
1213
+ (0, import_zod_openapi7.extendZodWithOpenApi)(import_zod15.z);
1214
+ var ActionUpdate = import_zod15.z.record(import_zod15.z.string(), FieldUpdateValue);
1215
+ var EventState = import_zod15.z.record(import_zod15.z.string(), FieldValue);
1216
+ var ActionStatus = {
1217
+ Requested: "Requested",
1218
+ Accepted: "Accepted",
1219
+ Rejected: "Rejected"
1305
1220
  };
1221
+ var ActionBase = import_zod15.z.object({
1222
+ id: import_zod15.z.string(),
1223
+ transactionId: import_zod15.z.string(),
1224
+ createdAt: import_zod15.z.string().datetime(),
1225
+ createdBy: import_zod15.z.string(),
1226
+ createdByRole: import_zod15.z.string(),
1227
+ declaration: ActionUpdate,
1228
+ annotation: ActionUpdate.optional(),
1229
+ createdAtLocation: import_zod15.z.string(),
1230
+ status: import_zod15.z.enum([
1231
+ ActionStatus.Requested,
1232
+ ActionStatus.Accepted,
1233
+ ActionStatus.Rejected
1234
+ ]),
1235
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1236
+ originalActionId: import_zod15.z.string().optional()
1237
+ });
1238
+ var AssignedAction = ActionBase.merge(
1239
+ import_zod15.z.object({
1240
+ type: import_zod15.z.literal(ActionType.ASSIGN),
1241
+ assignedTo: import_zod15.z.string()
1242
+ })
1243
+ );
1244
+ var UnassignedAction = ActionBase.merge(
1245
+ import_zod15.z.object({
1246
+ type: import_zod15.z.literal(ActionType.UNASSIGN),
1247
+ assignedTo: import_zod15.z.literal(null)
1248
+ })
1249
+ );
1250
+ var RegisterAction = ActionBase.merge(
1251
+ import_zod15.z.object({
1252
+ type: import_zod15.z.literal(ActionType.REGISTER),
1253
+ registrationNumber: import_zod15.z.string().optional()
1254
+ })
1255
+ );
1256
+ var DeclareAction = ActionBase.merge(
1257
+ import_zod15.z.object({
1258
+ type: import_zod15.z.literal(ActionType.DECLARE)
1259
+ })
1260
+ );
1261
+ var ValidateAction = ActionBase.merge(
1262
+ import_zod15.z.object({
1263
+ type: import_zod15.z.literal(ActionType.VALIDATE)
1264
+ })
1265
+ );
1266
+ var RejectAction = ActionBase.merge(
1267
+ import_zod15.z.object({
1268
+ type: import_zod15.z.literal(ActionType.REJECT)
1269
+ })
1270
+ );
1271
+ var MarkAsDuplicateAction = ActionBase.merge(
1272
+ import_zod15.z.object({
1273
+ type: import_zod15.z.literal(ActionType.MARKED_AS_DUPLICATE)
1274
+ })
1275
+ );
1276
+ var ArchiveAction = ActionBase.merge(
1277
+ import_zod15.z.object({
1278
+ type: import_zod15.z.literal(ActionType.ARCHIVE)
1279
+ })
1280
+ );
1281
+ var CreatedAction = ActionBase.merge(
1282
+ import_zod15.z.object({
1283
+ type: import_zod15.z.literal(ActionType.CREATE)
1284
+ })
1285
+ );
1286
+ var NotifiedAction = ActionBase.merge(
1287
+ import_zod15.z.object({
1288
+ type: import_zod15.z.literal(ActionType.NOTIFY)
1289
+ })
1290
+ );
1291
+ var PrintCertificateAction = ActionBase.merge(
1292
+ import_zod15.z.object({
1293
+ type: import_zod15.z.literal(ActionType.PRINT_CERTIFICATE)
1294
+ })
1295
+ );
1296
+ var RequestedCorrectionAction = ActionBase.merge(
1297
+ import_zod15.z.object({
1298
+ type: import_zod15.z.literal(ActionType.REQUEST_CORRECTION)
1299
+ })
1300
+ );
1301
+ var ApprovedCorrectionAction = ActionBase.merge(
1302
+ import_zod15.z.object({
1303
+ type: import_zod15.z.literal(ActionType.APPROVE_CORRECTION),
1304
+ requestId: import_zod15.z.string()
1305
+ })
1306
+ );
1307
+ var RejectedCorrectionAction = ActionBase.merge(
1308
+ import_zod15.z.object({
1309
+ type: import_zod15.z.literal(ActionType.REJECT_CORRECTION),
1310
+ requestId: import_zod15.z.string()
1311
+ })
1312
+ );
1313
+ var ReadAction = ActionBase.merge(
1314
+ import_zod15.z.object({
1315
+ type: import_zod15.z.literal(ActionType.READ)
1316
+ })
1317
+ );
1318
+ var ActionDocument = import_zod15.z.discriminatedUnion("type", [
1319
+ CreatedAction.openapi({ ref: "CreatedAction" }),
1320
+ ValidateAction.openapi({ ref: "ValidateAction" }),
1321
+ RejectAction.openapi({ ref: "RejectAction" }),
1322
+ MarkAsDuplicateAction.openapi({ ref: "MarkAsDuplicateAction" }),
1323
+ ArchiveAction.openapi({ ref: "ArchiveAction" }),
1324
+ NotifiedAction.openapi({ ref: "NotifiedAction" }),
1325
+ RegisterAction.openapi({ ref: "RegisterAction" }),
1326
+ DeclareAction.openapi({ ref: "DeclareAction" }),
1327
+ AssignedAction.openapi({ ref: "AssignedAction" }),
1328
+ RequestedCorrectionAction.openapi({ ref: "RequestedCorrectionAction" }),
1329
+ ApprovedCorrectionAction.openapi({ ref: "ApprovedCorrectionAction" }),
1330
+ RejectedCorrectionAction.openapi({ ref: "RejectedCorrectionAction" }),
1331
+ UnassignedAction.openapi({ ref: "UnassignedAction" }),
1332
+ PrintCertificateAction.openapi({ ref: "PrintCertificateAction" }),
1333
+ ReadAction.openapi({ ref: "ReadAction" })
1334
+ ]).openapi({
1335
+ ref: "ActionDocument"
1336
+ });
1337
+ var AsyncRejectActionDocument = ActionBase.omit({
1338
+ declaration: true,
1339
+ annotation: true
1340
+ }).merge(
1341
+ import_zod15.z.object({
1342
+ type: import_zod15.z.enum(ConfirmableActions),
1343
+ status: import_zod15.z.literal(ActionStatus.Rejected)
1344
+ })
1345
+ );
1346
+ var Action = import_zod15.z.union([ActionDocument, AsyncRejectActionDocument]);
1347
+ var ResolvedUser = import_zod15.z.object({
1348
+ id: import_zod15.z.string(),
1349
+ role: import_zod15.z.string(),
1350
+ name: import_zod15.z.array(
1351
+ import_zod15.z.object({
1352
+ use: import_zod15.z.string(),
1353
+ given: import_zod15.z.array(import_zod15.z.string()),
1354
+ family: import_zod15.z.string()
1355
+ })
1356
+ )
1357
+ });
1306
1358
 
1307
1359
  // ../commons/src/conditionals/validate.ts
1308
1360
  var import_ajv = __toESM(require("ajv"));
@@ -1310,7 +1362,7 @@ var import_ajv_formats = __toESM(require("ajv-formats"));
1310
1362
  var import_date_fns = require("date-fns");
1311
1363
 
1312
1364
  // ../commons/src/events/FieldTypeMapping.ts
1313
- var import_zod19 = require("zod");
1365
+ var import_zod16 = require("zod");
1314
1366
  function mapFieldTypeToZod(type, required) {
1315
1367
  let schema;
1316
1368
  switch (type) {
@@ -1320,6 +1372,9 @@ function mapFieldTypeToZod(type, required) {
1320
1372
  case FieldType.EMAIL:
1321
1373
  schema = EmailValue;
1322
1374
  break;
1375
+ case FieldType.DATE_RANGE:
1376
+ schema = DateRangeFieldValue;
1377
+ break;
1323
1378
  case FieldType.TEXT:
1324
1379
  case FieldType.TEXTAREA:
1325
1380
  case FieldType.DIVIDER:
@@ -1334,8 +1389,7 @@ function mapFieldTypeToZod(type, required) {
1334
1389
  case FieldType.FACILITY:
1335
1390
  case FieldType.OFFICE:
1336
1391
  case FieldType.SIGNATURE:
1337
- case FieldType.HIDDEN:
1338
- schema = required ? RequiredTextValue : TextValue;
1392
+ schema = required ? NonEmptyTextValue : TextValue;
1339
1393
  break;
1340
1394
  case FieldType.NUMBER:
1341
1395
  schema = NumberFieldValue;
@@ -1363,7 +1417,7 @@ function createValidationSchema(config) {
1363
1417
  for (const field2 of config) {
1364
1418
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1365
1419
  }
1366
- return import_zod19.z.object(shape);
1420
+ return import_zod16.z.object(shape);
1367
1421
  }
1368
1422
  function mapFieldTypeToMockValue(field2, i) {
1369
1423
  switch (field2.type) {
@@ -1401,6 +1455,8 @@ function mapFieldTypeToMockValue(field2, i) {
1401
1455
  };
1402
1456
  case FieldType.DATE:
1403
1457
  return "2021-01-01";
1458
+ case FieldType.DATE_RANGE:
1459
+ return ["2021-01-01", "2021-01-02"];
1404
1460
  case FieldType.CHECKBOX:
1405
1461
  return true;
1406
1462
  case FieldType.FILE:
@@ -1435,6 +1491,7 @@ function mapFieldTypeToEmptyValue(field2) {
1435
1491
  case FieldType.EMAIL:
1436
1492
  case FieldType.DATE:
1437
1493
  case FieldType.CHECKBOX:
1494
+ case FieldType.DATE_RANGE:
1438
1495
  case FieldType.DATA:
1439
1496
  return null;
1440
1497
  case FieldType.ADDRESS:
@@ -1467,6 +1524,9 @@ var isParagraphFieldType = (field2) => {
1467
1524
  var isDateFieldType = (field2) => {
1468
1525
  return field2.config.type === FieldType.DATE;
1469
1526
  };
1527
+ var isDateRangeFieldType = (field2) => {
1528
+ return field2.config.type === FieldType.DATE_RANGE;
1529
+ };
1470
1530
  var isPageHeaderFieldType = (field2) => {
1471
1531
  return field2.config.type === FieldType.PAGE_HEADER;
1472
1532
  };
@@ -1572,6 +1632,10 @@ function isFieldConditionMet(field2, form, conditionalType) {
1572
1632
  function isFieldVisible(field2, form) {
1573
1633
  return isFieldConditionMet(field2, form, ConditionalType.SHOW);
1574
1634
  }
1635
+ function isFieldEmptyAndNotRequired(field2, form) {
1636
+ const fieldValue = form[field2.id];
1637
+ return !field2.required && (fieldValue === void 0 || fieldValue === "");
1638
+ }
1575
1639
  function isFieldEnabled(field2, form) {
1576
1640
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1577
1641
  }
@@ -1676,7 +1740,7 @@ function runFieldValidations({
1676
1740
  field: field2,
1677
1741
  values
1678
1742
  }) {
1679
- if (!isFieldVisible(field2, values)) {
1743
+ if (!isFieldVisible(field2, values) || isFieldEmptyAndNotRequired(field2, values)) {
1680
1744
  return {
1681
1745
  errors: []
1682
1746
  };
@@ -1741,15 +1805,9 @@ var getActionAnnotationFields = (actionConfig) => {
1741
1805
  }
1742
1806
  return [];
1743
1807
  };
1744
- var getAllAnnotationFields = (config) => {
1808
+ function getAllAnnotationFields(config) {
1745
1809
  return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1746
- };
1747
- var findAllFields = (config) => {
1748
- return (0, import_lodash.flattenDeep)([
1749
- ...getDeclarationFields(config),
1750
- ...getAllAnnotationFields(config)
1751
- ]);
1752
- };
1810
+ }
1753
1811
  var findRecordActionPages = (config, actionType) => {
1754
1812
  const action = config.actions.find((a) => a.type === actionType);
1755
1813
  if (action?.type === ActionType.REQUEST_CORRECTION) {
@@ -1772,31 +1830,22 @@ function getActionReview(configuration, actionType) {
1772
1830
  function getActionReviewFields(configuration, actionType) {
1773
1831
  return getActionReview(configuration, actionType).fields;
1774
1832
  }
1775
- function validateWorkqueueConfig(workqueueConfigs) {
1776
- workqueueConfigs.map((workqueue) => {
1777
- const rootWorkqueue = Object.values(workqueues).find(
1778
- (wq) => wq.id === workqueue.id
1779
- );
1780
- if (!rootWorkqueue) {
1781
- throw new Error(
1782
- `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1783
- );
1784
- }
1785
- });
1786
- }
1787
1833
  function isPageVisible(page, formValues) {
1788
1834
  if (!page.conditional) {
1789
1835
  return true;
1790
1836
  }
1791
1837
  return isConditionMet(page.conditional, formValues);
1792
1838
  }
1793
- function omitHiddenFields(fields, values) {
1839
+ function omitHiddenFields(fields, values, visibleVerificationPageIds = []) {
1794
1840
  return (0, import_lodash.omitBy)(values, (_, fieldId) => {
1795
- const field2 = fields.find((f) => f.id === fieldId);
1796
- if (!field2) {
1841
+ if (visibleVerificationPageIds.includes(fieldId)) {
1842
+ return false;
1843
+ }
1844
+ const fieldConfigs = fields.filter((f) => f.id === fieldId);
1845
+ if (!fieldConfigs.length) {
1797
1846
  return true;
1798
1847
  }
1799
- return !isFieldVisible(field2, values);
1848
+ return fieldConfigs.every((f) => !isFieldVisible(f, values));
1800
1849
  });
1801
1850
  }
1802
1851
  function omitHiddenPaginatedFields(formConfig, declaration) {
@@ -1820,17 +1869,53 @@ function createEmptyDraft(eventId, draftId, actionType) {
1820
1869
  annotation: {},
1821
1870
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1822
1871
  createdBy: "@todo",
1823
- createdAtLocation: "@todo"
1872
+ createdAtLocation: "@todo",
1873
+ status: ActionStatus.Accepted,
1874
+ transactionId: "@todo",
1875
+ createdByRole: "@todo"
1824
1876
  }
1825
1877
  };
1826
1878
  }
1827
1879
  function isVerificationPage(page) {
1828
1880
  return page.type === PageTypes.enum.VERIFICATION;
1829
1881
  }
1830
- function deepMerge(currentDocument, actionDocument) {
1831
- return (0, import_lodash.mergeWith)(
1832
- currentDocument,
1833
- actionDocument,
1882
+ function getVisibleVerificationPageIds(pages, annotation) {
1883
+ return pages.filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
1884
+ }
1885
+ function getActionVerificationPageIds(actionConfig, annotation) {
1886
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1887
+ return [
1888
+ ...getVisibleVerificationPageIds(actionConfig.onboardingForm, annotation),
1889
+ ...getVisibleVerificationPageIds(
1890
+ actionConfig.additionalDetailsForm,
1891
+ annotation
1892
+ )
1893
+ ];
1894
+ }
1895
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1896
+ return getVisibleVerificationPageIds(
1897
+ actionConfig.printForm.pages,
1898
+ annotation
1899
+ );
1900
+ }
1901
+ return [];
1902
+ }
1903
+ function omitHiddenAnnotationFields(actionConfig, declaration, annotation) {
1904
+ const annotationFields = getActionAnnotationFields(actionConfig);
1905
+ const visibleVerificationPageIds = getActionVerificationPageIds(
1906
+ actionConfig,
1907
+ annotation
1908
+ );
1909
+ return omitHiddenFields(
1910
+ annotationFields,
1911
+ { ...declaration, ...annotation },
1912
+ visibleVerificationPageIds
1913
+ );
1914
+ }
1915
+ function deepMerge(currentDocument, actionDocument) {
1916
+ return (0, import_lodash.mergeWith)(
1917
+ currentDocument,
1918
+ actionDocument,
1834
1919
  (previousValue, incomingValue) => {
1835
1920
  if (incomingValue === void 0) {
1836
1921
  return previousValue;
@@ -1853,19 +1938,49 @@ function findLastAssignmentAction(actions) {
1853
1938
  function isWriteAction(actionType) {
1854
1939
  return writeActions.safeParse(actionType).success;
1855
1940
  }
1941
+ var findAllFields = (config) => {
1942
+ return (0, import_lodash.flattenDeep)([
1943
+ ...getDeclarationFields(config),
1944
+ ...getAllAnnotationFields(config)
1945
+ ]);
1946
+ };
1947
+ function getMixedPath(obj, path, defaultValue) {
1948
+ const parts = path.split(".");
1949
+ const resolve = (current, segments) => {
1950
+ if (current == null || segments.length === 0) {
1951
+ return current;
1952
+ }
1953
+ for (let i = segments.length; i > 0; i--) {
1954
+ const compoundKey = segments.slice(0, i).join(".");
1955
+ if ((0, import_lodash.has)(current, compoundKey)) {
1956
+ const next = (0, import_lodash.get)(current, compoundKey);
1957
+ return resolve(next, segments.slice(i));
1958
+ }
1959
+ }
1960
+ return void 0;
1961
+ };
1962
+ const result = resolve(obj, parts);
1963
+ return (0, import_lodash.isNil)(result) ? defaultValue : result;
1964
+ }
1856
1965
 
1857
1966
  // ../commons/src/events/EventConfig.ts
1858
- var EventConfig = import_zod20.z.object({
1859
- id: import_zod20.z.string().describe(
1967
+ var import_zod_openapi8 = require("zod-openapi");
1968
+ (0, import_zod_openapi8.extendZodWithOpenApi)(import_zod17.z);
1969
+ var EventConfig = import_zod17.z.object({
1970
+ id: import_zod17.z.string().describe(
1860
1971
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1861
1972
  ),
1973
+ dateOfEvent: import_zod17.z.object({ fieldId: import_zod17.z.string() }).optional(),
1974
+ title: TranslationConfig,
1975
+ fallbackTitle: TranslationConfig.optional().describe(
1976
+ "This is a fallback title if actual title resolves to empty string"
1977
+ ),
1862
1978
  summary: SummaryConfig,
1863
1979
  label: TranslationConfig,
1864
- actions: import_zod20.z.array(ActionConfig),
1980
+ actions: import_zod17.z.array(ActionConfig),
1865
1981
  declaration: DeclarationFormConfig,
1866
- workqueues: import_zod20.z.array(WorkqueueConfig),
1867
- deduplication: import_zod20.z.array(DeduplicationConfig).optional().default([]),
1868
- advancedSearch: import_zod20.z.array(AdvancedSearchConfig).optional().default([])
1982
+ deduplication: import_zod17.z.array(DeduplicationConfig).optional().default([]),
1983
+ advancedSearch: import_zod17.z.array(AdvancedSearchConfig).optional().default([])
1869
1984
  }).superRefine((event2, ctx) => {
1870
1985
  const allFields = findAllFields(event2);
1871
1986
  const fieldIds = allFields.map((field2) => field2.id);
@@ -1881,16 +1996,43 @@ var EventConfig = import_zod20.z.object({
1881
1996
  });
1882
1997
  }
1883
1998
  const invalidFields = event2.advancedSearch.flatMap(
1884
- (section) => section.fields.filter((field2) => !fieldIds.includes(field2.fieldId))
1999
+ (section) => (
2000
+ // Check if the fieldId is not in the fieldIds array
2001
+ // and also not in the metadataFields array
2002
+ section.fields.filter(
2003
+ (field2) => !(fieldIds.includes(field2.fieldId) || EventFieldId.options.includes(field2.fieldId))
2004
+ )
2005
+ )
1885
2006
  );
1886
2007
  if (invalidFields.length > 0) {
1887
2008
  ctx.addIssue({
1888
2009
  code: "custom",
1889
- message: `Advanced search id must match a field id in fields array.
2010
+ message: `Advanced search id must match a field id of form fields or pre-defined metadata fields.
1890
2011
  Invalid AdvancedSearch field IDs for event ${event2.id}: ${invalidFields.map((f) => f.fieldId).join(", ")}`,
1891
2012
  path: ["advancedSearch"]
1892
2013
  });
1893
2014
  }
2015
+ if (event2.dateOfEvent) {
2016
+ const eventDateFieldId = getDeclarationFields(event2).find(
2017
+ ({ id }) => id === event2.dateOfEvent?.fieldId
2018
+ );
2019
+ if (!eventDateFieldId) {
2020
+ ctx.addIssue({
2021
+ code: "custom",
2022
+ message: `Date of event field id must match a field id in fields array.
2023
+ Invalid date of event field ID for event ${event2.id}: ${event2.dateOfEvent.fieldId}`,
2024
+ path: ["dateOfEvent"]
2025
+ });
2026
+ } else if (eventDateFieldId.type !== FieldType.DATE) {
2027
+ ctx.addIssue({
2028
+ code: "custom",
2029
+ message: `Field specified for date of event is of type: ${eventDateFieldId.type}, but it needs to be of type: ${FieldType.DATE}`,
2030
+ path: ["dateOfEvent.fieldType"]
2031
+ });
2032
+ }
2033
+ }
2034
+ }).openapi({
2035
+ ref: "EventConfig"
1894
2036
  });
1895
2037
 
1896
2038
  // ../commons/src/events/EventConfigInput.ts
@@ -1899,504 +2041,242 @@ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1899
2041
  var definePage = (page) => PageConfig.parse(page);
1900
2042
  var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1901
2043
 
1902
- // ../commons/src/events/Draft.ts
1903
- var import_zod23 = require("zod");
2044
+ // ../commons/src/events/WorkqueueConfig.ts
2045
+ var import_zod20 = require("zod");
1904
2046
 
1905
- // ../commons/src/events/ActionDocument.ts
1906
- var import_zod21 = require("zod");
1907
- var ActionUpdate = import_zod21.z.record(import_zod21.z.string(), FieldUpdateValue);
1908
- var ActionStatus = {
1909
- Requested: "Requested",
1910
- Accepted: "Accepted",
1911
- Rejected: "Rejected"
2047
+ // ../commons/src/events/EventIndex.ts
2048
+ var import_zod19 = require("zod");
2049
+
2050
+ // ../commons/src/events/EventMetadata.ts
2051
+ var import_zod18 = require("zod");
2052
+ var EventStatus = {
2053
+ CREATED: "CREATED",
2054
+ NOTIFIED: "NOTIFIED",
2055
+ DECLARED: "DECLARED",
2056
+ VALIDATED: "VALIDATED",
2057
+ REGISTERED: "REGISTERED",
2058
+ CERTIFIED: "CERTIFIED",
2059
+ REJECTED: "REJECTED",
2060
+ ARCHIVED: "ARCHIVED"
1912
2061
  };
1913
- var ActionBase = import_zod21.z.object({
1914
- id: import_zod21.z.string(),
1915
- createdAt: import_zod21.z.string().datetime(),
1916
- createdBy: import_zod21.z.string(),
1917
- declaration: ActionUpdate,
1918
- annotation: ActionUpdate.optional(),
1919
- createdAtLocation: import_zod21.z.string(),
1920
- status: import_zod21.z.enum([
1921
- ActionStatus.Requested,
1922
- ActionStatus.Accepted,
1923
- ActionStatus.Rejected
1924
- ]),
1925
- // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1926
- originalActionId: import_zod21.z.string().optional()
2062
+ var eventStatusValues = [
2063
+ EventStatus.CREATED,
2064
+ EventStatus.NOTIFIED,
2065
+ EventStatus.DECLARED,
2066
+ EventStatus.VALIDATED,
2067
+ EventStatus.REGISTERED,
2068
+ EventStatus.CERTIFIED,
2069
+ EventStatus.REJECTED,
2070
+ EventStatus.ARCHIVED
2071
+ ];
2072
+ var EventStatusEnum = import_zod18.z.enum(eventStatusValues);
2073
+ var CustomFlags = {
2074
+ CERTIFICATE_PRINTED: "certificate-printed"
2075
+ };
2076
+ var Flag = import_zod18.z.string().regex(
2077
+ new RegExp(
2078
+ `^(${Object.values(ActionType).join("|").toLowerCase()}):(${Object.values(ActionStatus).join("|").toLowerCase()})$`
2079
+ ),
2080
+ "Flag must be in the format ActionType:ActionStatus (lowerCase)"
2081
+ ).or(import_zod18.z.nativeEnum(CustomFlags));
2082
+ var eventStatuses = Object.values(EventStatus);
2083
+ var EventStatuses = import_zod18.z.nativeEnum(EventStatus);
2084
+ var ZodDate = import_zod18.z.string().date();
2085
+ var ActionCreationMetadata = import_zod18.z.object({
2086
+ createdAt: import_zod18.z.string().datetime().describe("The timestamp when the action request was created."),
2087
+ createdBy: import_zod18.z.string().describe("ID of the user who created the action request."),
2088
+ createdAtLocation: import_zod18.z.string().describe("Location of the user who created the action request."),
2089
+ acceptedAt: import_zod18.z.string().datetime().describe("Timestamp when the action request was accepted."),
2090
+ createdByRole: import_zod18.z.string().describe("Role of the user at the time of action request creation.")
1927
2091
  });
1928
- var AssignedAction = ActionBase.merge(
1929
- import_zod21.z.object({
1930
- type: import_zod21.z.literal(ActionType.ASSIGN),
1931
- assignedTo: import_zod21.z.string()
1932
- })
1933
- );
1934
- var UnassignedAction = ActionBase.merge(
1935
- import_zod21.z.object({
1936
- type: import_zod21.z.literal(ActionType.UNASSIGN),
1937
- assignedTo: import_zod21.z.literal(null).default(null)
1938
- })
1939
- );
1940
- var RegisterAction = ActionBase.merge(
1941
- import_zod21.z.object({
1942
- type: import_zod21.z.literal(ActionType.REGISTER),
1943
- registrationNumber: import_zod21.z.string().optional()
1944
- })
1945
- );
1946
- var DeclareAction = ActionBase.merge(
1947
- import_zod21.z.object({
1948
- type: import_zod21.z.literal(ActionType.DECLARE)
1949
- })
1950
- );
1951
- var ValidateAction = ActionBase.merge(
1952
- import_zod21.z.object({
1953
- type: import_zod21.z.literal(ActionType.VALIDATE)
1954
- })
1955
- );
1956
- var RejectAction = ActionBase.merge(
1957
- import_zod21.z.object({
1958
- type: import_zod21.z.literal(ActionType.REJECT)
1959
- })
1960
- );
1961
- var MarkAsDuplicateAction = ActionBase.merge(
1962
- import_zod21.z.object({
1963
- type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE)
1964
- })
1965
- );
1966
- var ArchiveAction = ActionBase.merge(
1967
- import_zod21.z.object({
1968
- type: import_zod21.z.literal(ActionType.ARCHIVE)
1969
- })
1970
- );
1971
- var CreatedAction = ActionBase.merge(
1972
- import_zod21.z.object({
1973
- type: import_zod21.z.literal(ActionType.CREATE)
1974
- })
1975
- );
1976
- var NotifiedAction = ActionBase.merge(
1977
- import_zod21.z.object({
1978
- type: import_zod21.z.literal(ActionType.NOTIFY)
1979
- })
1980
- );
1981
- var PrintCertificateAction = ActionBase.merge(
1982
- import_zod21.z.object({
1983
- type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE)
1984
- })
1985
- );
1986
- var RequestedCorrectionAction = ActionBase.merge(
1987
- import_zod21.z.object({
1988
- type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION)
1989
- })
1990
- );
1991
- var ApprovedCorrectionAction = ActionBase.merge(
1992
- import_zod21.z.object({
1993
- type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION),
1994
- requestId: import_zod21.z.string()
1995
- })
1996
- );
1997
- var RejectedCorrectionAction = ActionBase.merge(
1998
- import_zod21.z.object({
1999
- type: import_zod21.z.literal(ActionType.REJECT_CORRECTION),
2000
- requestId: import_zod21.z.string()
2001
- })
2002
- );
2003
- var ReadAction = ActionBase.merge(
2004
- import_zod21.z.object({
2005
- type: import_zod21.z.literal(ActionType.READ)
2006
- })
2007
- );
2008
- var ActionDocument = import_zod21.z.discriminatedUnion("type", [
2009
- CreatedAction,
2010
- ValidateAction,
2011
- RejectAction,
2012
- MarkAsDuplicateAction,
2013
- ArchiveAction,
2014
- NotifiedAction,
2015
- RegisterAction,
2016
- DeclareAction,
2017
- AssignedAction,
2018
- RequestedCorrectionAction,
2019
- ApprovedCorrectionAction,
2020
- RejectedCorrectionAction,
2021
- UnassignedAction,
2022
- PrintCertificateAction,
2023
- ReadAction
2024
- ]);
2025
- var AsyncRejectActionDocument = ActionBase.omit({
2026
- declaration: true,
2027
- annotation: true,
2028
- createdBy: true,
2029
- createdAtLocation: true
2030
- }).merge(
2031
- import_zod21.z.object({
2032
- type: import_zod21.z.enum(ConfirmableActions),
2033
- status: import_zod21.z.literal(ActionStatus.Rejected)
2034
- })
2035
- );
2036
- var Action = import_zod21.z.union([ActionDocument, AsyncRejectActionDocument]);
2037
- var ResolvedUser = import_zod21.z.object({
2038
- id: import_zod21.z.string(),
2039
- role: import_zod21.z.string(),
2040
- name: import_zod21.z.array(
2041
- import_zod21.z.object({
2042
- use: import_zod21.z.string(),
2043
- given: import_zod21.z.array(import_zod21.z.string()),
2044
- family: import_zod21.z.string()
2045
- })
2092
+ var RegistrationCreationMetadata = ActionCreationMetadata.extend({
2093
+ registrationNumber: import_zod18.z.string().describe(
2094
+ "Registration number of the event. Always present for accepted registrations."
2046
2095
  )
2047
2096
  });
2097
+ var LegalStatuses = import_zod18.z.object({
2098
+ [EventStatus.DECLARED]: ActionCreationMetadata.nullish(),
2099
+ [EventStatus.REGISTERED]: RegistrationCreationMetadata.nullish()
2100
+ });
2101
+ var EventMetadata = import_zod18.z.object({
2102
+ id: import_zod18.z.string(),
2103
+ type: import_zod18.z.string().describe("The type of event, such as birth, death, or marriage."),
2104
+ status: EventStatuses,
2105
+ legalStatuses: LegalStatuses.describe(
2106
+ "Metadata related to the legal registration of the event, such as who registered it and when."
2107
+ ),
2108
+ createdAt: import_zod18.z.string().datetime().describe("The timestamp when the event was first created and saved."),
2109
+ dateOfEvent: ZodDate.nullish(),
2110
+ createdBy: import_zod18.z.string().describe("ID of the user who created the event."),
2111
+ updatedByUserRole: import_zod18.z.string().describe("Role of the user who last updated the declaration."),
2112
+ createdAtLocation: import_zod18.z.string().describe("Location of the user who created the event."),
2113
+ updatedAtLocation: import_zod18.z.string().nullish().describe("Location of the user who last updated the declaration."),
2114
+ updatedAt: import_zod18.z.string().datetime().describe("Timestamp of the most recent declaration update."),
2115
+ assignedTo: import_zod18.z.string().nullish().describe("ID of the user currently assigned to the event."),
2116
+ updatedBy: import_zod18.z.string().nullish().describe("ID of the user who last updated the declaration."),
2117
+ trackingId: import_zod18.z.string().describe(
2118
+ "System-generated tracking ID used by informants or registrars to look up the event."
2119
+ ),
2120
+ flags: import_zod18.z.array(Flag)
2121
+ });
2122
+ var EventMetadataKeys = import_zod18.z.enum([
2123
+ "id",
2124
+ "type",
2125
+ "status",
2126
+ "createdAt",
2127
+ "dateOfEvent",
2128
+ "createdBy",
2129
+ "updatedByUserRole",
2130
+ "createdAtLocation",
2131
+ "updatedAtLocation",
2132
+ "updatedAt",
2133
+ "assignedTo",
2134
+ "updatedBy",
2135
+ "trackingId",
2136
+ "legalStatuses",
2137
+ "flags"
2138
+ ]);
2139
+ var EventMetadataParameter = import_zod18.z.object({
2140
+ // @TODO: Reconcile with the event metadata definition. How could we derive one from the other?
2141
+ $event: EventMetadataKeys
2142
+ });
2143
+ var eventMetadataLabelMap = {
2144
+ "event.assignedTo": {
2145
+ id: "event.assignedTo.label",
2146
+ defaultMessage: "Assigned To",
2147
+ description: "Assigned To"
2148
+ },
2149
+ "event.createdAt": {
2150
+ id: "event.createdAt.label",
2151
+ defaultMessage: "Created",
2152
+ description: "Created At"
2153
+ },
2154
+ "event.dateOfEvent": {
2155
+ id: "event.dateOfEvent.label",
2156
+ defaultMessage: "Date of Event",
2157
+ description: "Date of Event"
2158
+ },
2159
+ "event.createdAtLocation": {
2160
+ id: "event.createdAtLocation.label",
2161
+ defaultMessage: "Location",
2162
+ description: "Created At Location"
2163
+ },
2164
+ "event.updatedAtLocation": {
2165
+ id: "event.updatedAtLocation.label",
2166
+ defaultMessage: "Location",
2167
+ description: "Updated At Location"
2168
+ },
2169
+ "event.createdBy": {
2170
+ id: "event.createdBy.label",
2171
+ defaultMessage: "Created By",
2172
+ description: "Created By"
2173
+ },
2174
+ "event.updatedByUserRole": {
2175
+ id: "event.updatedByUserRole.label",
2176
+ defaultMessage: "Updated By Role",
2177
+ description: "Updated By Role"
2178
+ },
2179
+ "event.id": {
2180
+ id: "event.id.label",
2181
+ defaultMessage: "ID",
2182
+ description: "ID"
2183
+ },
2184
+ "event.updatedAt": {
2185
+ id: "event.modifiedAt.label",
2186
+ defaultMessage: "Updated",
2187
+ description: "Modified At"
2188
+ },
2189
+ "event.status": {
2190
+ id: "event.status.label",
2191
+ defaultMessage: "Status",
2192
+ description: "Status"
2193
+ },
2194
+ "event.type": {
2195
+ id: "event.type.label",
2196
+ defaultMessage: "Type",
2197
+ description: "Type"
2198
+ },
2199
+ "event.updatedBy": {
2200
+ id: "event.updatedBy.label",
2201
+ defaultMessage: "Updated By",
2202
+ description: "Updated By"
2203
+ },
2204
+ "event.trackingId": {
2205
+ id: "event.trackingId.label",
2206
+ defaultMessage: "Tracking ID",
2207
+ description: "Tracking ID"
2208
+ },
2209
+ "event.flags": {
2210
+ id: "event.flags.label",
2211
+ defaultMessage: "Flags",
2212
+ description: "Flags"
2213
+ }
2214
+ };
2048
2215
 
2049
- // ../commons/src/events/ActionInput.ts
2050
- var import_zod22 = require("zod");
2051
- var BaseActionInput = import_zod22.z.object({
2052
- eventId: import_zod22.z.string(),
2053
- transactionId: import_zod22.z.string(),
2054
- declaration: ActionUpdate.default({}),
2055
- annotation: ActionUpdate.optional(),
2056
- originalActionId: import_zod22.z.string().optional(),
2057
- keepAssignment: import_zod22.z.boolean().optional()
2216
+ // ../commons/src/events/EventIndex.ts
2217
+ var EventIndex = EventMetadata.extend({
2218
+ declaration: EventState
2058
2219
  });
2059
- var CreateActionInput = BaseActionInput.merge(
2060
- import_zod22.z.object({
2061
- type: import_zod22.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2062
- createdAtLocation: import_zod22.z.string()
2063
- })
2064
- );
2065
- var RegisterActionInput = BaseActionInput.merge(
2066
- import_zod22.z.object({
2067
- type: import_zod22.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2068
- registrationNumber: import_zod22.z.string().optional()
2069
- })
2070
- );
2071
- var ValidateActionInput = BaseActionInput.merge(
2072
- import_zod22.z.object({
2073
- type: import_zod22.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2074
- duplicates: import_zod22.z.array(import_zod22.z.string())
2075
- })
2076
- );
2077
- var NotifyActionInput = BaseActionInput.merge(
2078
- import_zod22.z.object({
2079
- type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2080
- })
2081
- );
2082
- var DeclareActionInput = BaseActionInput.merge(
2083
- import_zod22.z.object({
2084
- type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2085
- })
2086
- );
2087
- var PrintCertificateActionInput = BaseActionInput.merge(
2088
- import_zod22.z.object({
2089
- type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2090
- })
2091
- );
2092
- var RejectDeclarationActionInput = BaseActionInput.merge(
2093
- import_zod22.z.object({
2094
- type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2095
- })
2096
- );
2097
- var MarkedAsDuplicateActionInput = BaseActionInput.merge(
2098
- import_zod22.z.object({
2099
- type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2100
- })
2101
- );
2102
- var ArchiveActionInput = BaseActionInput.merge(
2103
- import_zod22.z.object({
2104
- type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2105
- })
2106
- );
2107
- var AssignActionInput = BaseActionInput.merge(
2108
- import_zod22.z.object({
2109
- type: import_zod22.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2110
- assignedTo: import_zod22.z.string()
2220
+ var EventSearchIndex = import_zod19.z.record(import_zod19.z.string(), import_zod19.z.any()).and(
2221
+ import_zod19.z.object({
2222
+ type: import_zod19.z.string()
2223
+ // Ensures "type" (event-id) exists and is a string
2111
2224
  })
2112
2225
  );
2113
- var UnassignActionInput = BaseActionInput.merge(
2114
- import_zod22.z.object({
2115
- type: import_zod22.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2116
- assignedTo: import_zod22.z.literal(null).default(null)
2117
- })
2226
+ var Fuzzy = import_zod19.z.object({ type: import_zod19.z.literal("fuzzy"), term: import_zod19.z.string() });
2227
+ var Exact = import_zod19.z.object({ type: import_zod19.z.literal("exact"), term: import_zod19.z.string() });
2228
+ var AnyOf = import_zod19.z.object({
2229
+ type: import_zod19.z.literal("anyOf"),
2230
+ terms: import_zod19.z.array(import_zod19.z.string())
2231
+ });
2232
+ var ExactStatus = import_zod19.z.object({
2233
+ type: import_zod19.z.literal("exact"),
2234
+ term: EventStatusEnum
2235
+ });
2236
+ var AnyOfStatus = import_zod19.z.object({
2237
+ type: import_zod19.z.literal("anyOf"),
2238
+ terms: import_zod19.z.array(EventStatusEnum)
2239
+ });
2240
+ var Range = import_zod19.z.object({
2241
+ type: import_zod19.z.literal("range"),
2242
+ gte: import_zod19.z.string(),
2243
+ lte: import_zod19.z.string()
2244
+ });
2245
+ var Not = import_zod19.z.object({ type: import_zod19.z.literal("not"), term: import_zod19.z.string() });
2246
+ var Within = import_zod19.z.object({ type: import_zod19.z.literal("within"), location: import_zod19.z.string() });
2247
+ var DateCondition = import_zod19.z.union([Exact, Range]);
2248
+ var QueryInput = import_zod19.z.lazy(
2249
+ () => import_zod19.z.union([
2250
+ import_zod19.z.discriminatedUnion("type", [Fuzzy, Exact, Range, Within, AnyOf, Not]),
2251
+ import_zod19.z.record(import_zod19.z.string(), QueryInput)
2252
+ ])
2118
2253
  );
2119
- var RequestCorrectionActionInput = BaseActionInput.merge(
2120
- import_zod22.z.object({
2121
- type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2122
- })
2123
- );
2124
- var RejectCorrectionActionInput = BaseActionInput.merge(
2125
- import_zod22.z.object({
2126
- requestId: import_zod22.z.string(),
2127
- type: import_zod22.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2128
- })
2129
- );
2130
- var ApproveCorrectionActionInput = BaseActionInput.merge(
2131
- import_zod22.z.object({
2132
- requestId: import_zod22.z.string(),
2133
- type: import_zod22.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2134
- })
2135
- );
2136
- var ReadActionInput = BaseActionInput.merge(
2137
- import_zod22.z.object({
2138
- type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
2139
- })
2140
- );
2141
- var ActionInput = import_zod22.z.discriminatedUnion("type", [
2142
- CreateActionInput,
2143
- ValidateActionInput,
2144
- RegisterActionInput,
2145
- NotifyActionInput,
2146
- DeclareActionInput,
2147
- RejectDeclarationActionInput,
2148
- MarkedAsDuplicateActionInput,
2149
- ArchiveActionInput,
2150
- AssignActionInput,
2151
- UnassignActionInput,
2152
- PrintCertificateActionInput,
2153
- RequestCorrectionActionInput,
2154
- RejectCorrectionActionInput,
2155
- ApproveCorrectionActionInput,
2156
- ReadActionInput
2157
- ]);
2158
-
2159
- // ../commons/src/events/Draft.ts
2160
- var Draft = import_zod23.z.object({
2161
- id: import_zod23.z.string(),
2162
- eventId: import_zod23.z.string(),
2163
- transactionId: import_zod23.z.string(),
2164
- createdAt: import_zod23.z.string().datetime(),
2165
- action: ActionBase.extend({
2166
- type: ActionTypes
2167
- }).omit({ id: true })
2168
- });
2169
- var DraftInput = BaseActionInput.extend({
2170
- type: ActionTypes
2171
- });
2172
-
2173
- // ../commons/src/events/EventInput.ts
2174
- var import_zod24 = require("zod");
2175
- var EventInput = import_zod24.z.object({
2176
- transactionId: import_zod24.z.string(),
2177
- type: import_zod24.z.string()
2178
- });
2179
-
2180
- // ../commons/src/events/EventDocument.ts
2181
- var import_zod25 = require("zod");
2182
- var EventDocument = import_zod25.z.object({
2183
- id: import_zod25.z.string(),
2184
- type: import_zod25.z.string(),
2185
- createdAt: import_zod25.z.string().datetime(),
2186
- updatedAt: import_zod25.z.string().datetime(),
2187
- updatedAtLocation: import_zod25.z.string(),
2188
- actions: import_zod25.z.array(Action),
2189
- trackingId: import_zod25.z.string()
2254
+ var QueryExpression = import_zod19.z.object({
2255
+ eventType: import_zod19.z.string(),
2256
+ status: import_zod19.z.optional(import_zod19.z.union([AnyOfStatus, ExactStatus])),
2257
+ createdAt: import_zod19.z.optional(DateCondition),
2258
+ updatedAt: import_zod19.z.optional(DateCondition),
2259
+ "legalStatus.REGISTERED.createdAt": import_zod19.z.optional(DateCondition),
2260
+ "legalStatus.REGISTERED.createdAtLocation": import_zod19.z.optional(
2261
+ import_zod19.z.union([Within, Exact])
2262
+ ),
2263
+ createAtLocation: import_zod19.z.optional(import_zod19.z.union([Within, Exact])),
2264
+ updatedAtLocation: import_zod19.z.optional(import_zod19.z.union([Within, Exact])),
2265
+ createdBy: import_zod19.z.optional(Exact),
2266
+ updatedBy: import_zod19.z.optional(Exact),
2267
+ trackingId: import_zod19.z.optional(Exact),
2268
+ flags: import_zod19.z.optional(import_zod19.z.array(import_zod19.z.union([AnyOf, Not]))),
2269
+ data: QueryInput
2270
+ }).partial();
2271
+ var Or2 = import_zod19.z.object({
2272
+ type: import_zod19.z.literal("or"),
2273
+ clauses: import_zod19.z.array(QueryExpression)
2190
2274
  });
2191
-
2192
- // ../commons/src/events/EventIndex.ts
2193
- var import_zod26 = require("zod");
2194
- var EventIndex = EventMetadata.extend({
2195
- declaration: import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any())
2275
+ var And2 = import_zod19.z.object({
2276
+ type: import_zod19.z.literal("and"),
2277
+ clauses: import_zod19.z.array(QueryExpression)
2196
2278
  });
2197
- var EventSearchIndex = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any()).and(
2198
- import_zod26.z.object({
2199
- type: import_zod26.z.string()
2200
- // Ensures "type" (event-id) exists and is a string
2201
- })
2202
- );
2203
-
2204
- // ../commons/src/events/state/index.ts
2205
- function getStatusFromActions(actions) {
2206
- const hasRejectedAction = actions.some(
2207
- (a) => a.status === ActionStatus.Rejected
2208
- );
2209
- if (hasRejectedAction) {
2210
- return EventStatus.REJECTED;
2211
- }
2212
- return actions.reduce((status, action) => {
2213
- switch (action.type) {
2214
- case ActionType.CREATE:
2215
- return EventStatus.CREATED;
2216
- case ActionType.DECLARE:
2217
- return EventStatus.DECLARED;
2218
- case ActionType.VALIDATE:
2219
- return EventStatus.VALIDATED;
2220
- case ActionType.REGISTER:
2221
- return EventStatus.REGISTERED;
2222
- case ActionType.REJECT:
2223
- return EventStatus.REJECTED;
2224
- case ActionType.ARCHIVE:
2225
- return EventStatus.ARCHIVED;
2226
- case ActionType.NOTIFY:
2227
- return EventStatus.NOTIFIED;
2228
- case ActionType.PRINT_CERTIFICATE:
2229
- case ActionType.ASSIGN:
2230
- case ActionType.UNASSIGN:
2231
- case ActionType.REQUEST_CORRECTION:
2232
- case ActionType.APPROVE_CORRECTION:
2233
- case ActionType.MARKED_AS_DUPLICATE:
2234
- case ActionType.REJECT_CORRECTION:
2235
- case ActionType.READ:
2236
- default:
2237
- return status;
2238
- }
2239
- }, EventStatus.CREATED);
2240
- }
2241
- function getAssignedUserFromActions(actions) {
2242
- return actions.reduce((user2, action) => {
2243
- if (action.type === ActionType.ASSIGN) {
2244
- return action.assignedTo;
2245
- }
2246
- if (action.type === ActionType.UNASSIGN) {
2247
- return null;
2248
- }
2249
- return user2;
2250
- }, null);
2251
- }
2252
- function aggregateActionDeclarations(actions) {
2253
- const excludedActions = [
2254
- ActionType.REQUEST_CORRECTION,
2255
- ActionType.PRINT_CERTIFICATE
2256
- ];
2257
- return actions.reduce((status, action) => {
2258
- if (excludedActions.some((excludedAction) => excludedAction === action.type)) {
2259
- return status;
2260
- }
2261
- if (action.type === ActionType.APPROVE_CORRECTION) {
2262
- const requestAction = actions.find(({ id }) => id === action.requestId);
2263
- if (!requestAction) {
2264
- return status;
2265
- }
2266
- return deepMerge(status, requestAction.declaration);
2267
- }
2268
- return deepMerge(status, action.declaration);
2269
- }, {});
2270
- }
2271
- function deepDropNulls(obj) {
2272
- if (Array.isArray(obj)) {
2273
- return obj.map(deepDropNulls);
2274
- }
2275
- if (obj !== null && typeof obj === "object") {
2276
- return Object.entries(obj).reduce((acc, [key, value]) => {
2277
- const cleanedValue = deepDropNulls(value);
2278
- if (cleanedValue !== null) {
2279
- ;
2280
- acc[key] = cleanedValue;
2281
- }
2282
- return acc;
2283
- }, {});
2284
- }
2285
- return obj;
2286
- }
2287
- function isUndeclaredDraft(status) {
2288
- return status === EventStatus.CREATED;
2289
- }
2290
- function getAcceptedActions(event2) {
2291
- return event2.actions.filter(
2292
- (a) => a.status === ActionStatus.Accepted
2293
- );
2294
- }
2295
- function getCurrentEventState(event2) {
2296
- const creationAction = event2.actions.find(
2297
- (action) => action.type === ActionType.CREATE
2298
- );
2299
- if (!creationAction) {
2300
- throw new Error(`Event ${event2.id} has no creation action`);
2301
- }
2302
- const activeActions = getAcceptedActions(event2);
2303
- const latestAction = activeActions[activeActions.length - 1];
2304
- const registrationAction = activeActions.find(
2305
- (a) => a.type === ActionType.REGISTER && a.status === ActionStatus.Accepted
2306
- );
2307
- const registrationNumber = registrationAction?.registrationNumber ?? null;
2308
- return deepDropNulls({
2309
- id: event2.id,
2310
- type: event2.type,
2311
- status: getStatusFromActions(event2.actions),
2312
- createdAt: event2.createdAt,
2313
- createdBy: creationAction.createdBy,
2314
- createdAtLocation: creationAction.createdAtLocation,
2315
- modifiedAt: latestAction.createdAt,
2316
- assignedTo: getAssignedUserFromActions(activeActions),
2317
- updatedBy: latestAction.createdBy,
2318
- updatedAtLocation: event2.updatedAtLocation,
2319
- declaration: aggregateActionDeclarations(activeActions),
2320
- trackingId: event2.trackingId,
2321
- registrationNumber
2322
- });
2323
- }
2324
- function getCurrentEventStateWithDrafts(event2, drafts) {
2325
- const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2326
- const activeDrafts = findActiveDrafts(event2, drafts).map((draft) => draft.action).flatMap((action) => {
2327
- if (action.type === ActionType.REQUEST_CORRECTION) {
2328
- return [
2329
- action,
2330
- {
2331
- ...action,
2332
- type: ActionType.APPROVE_CORRECTION
2333
- }
2334
- ];
2335
- }
2336
- return [action];
2337
- });
2338
- const actionWithDrafts = [...actions, ...activeDrafts].sort();
2339
- const withDrafts = {
2340
- ...event2,
2341
- actions: actionWithDrafts
2342
- };
2343
- return getCurrentEventState(withDrafts);
2344
- }
2345
- function applyDraftsToEventIndex(eventIndex, drafts) {
2346
- const indexedAt = eventIndex.modifiedAt;
2347
- const activeDrafts = drafts.filter(({ createdAt }) => new Date(createdAt) > new Date(indexedAt)).map((draft) => draft.action).sort();
2348
- if (activeDrafts.length === 0) {
2349
- return eventIndex;
2350
- }
2351
- return {
2352
- ...eventIndex,
2353
- declaration: {
2354
- ...eventIndex.declaration,
2355
- ...activeDrafts[activeDrafts.length - 1].declaration
2356
- }
2357
- };
2358
- }
2359
- function getAnnotationFromDrafts(drafts) {
2360
- const actions = drafts.map((draft) => draft.action);
2361
- const annotation = actions.reduce((ann, action) => {
2362
- return deepMerge(ann, action.annotation ?? {});
2363
- }, {});
2364
- return deepDropNulls(annotation);
2365
- }
2366
- function getActionAnnotation({
2367
- event: event2,
2368
- actionType,
2369
- drafts
2370
- }) {
2371
- const activeActions = getAcceptedActions(event2);
2372
- const action = activeActions.find(
2373
- (activeAction) => actionType === activeAction.type
2374
- );
2375
- const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
2376
- const sorted = [
2377
- ...action ? [action] : [],
2378
- ...eventDrafts.map((draft) => draft.action)
2379
- ].sort();
2380
- const annotation = sorted.reduce((ann, sortedAction) => {
2381
- return deepMerge(ann, sortedAction.annotation ?? {});
2382
- }, {});
2383
- return deepDropNulls(annotation);
2384
- }
2385
-
2386
- // ../commons/src/events/defineConfig.ts
2387
- var defineConfig = (config) => {
2388
- validateWorkqueueConfig(config.workqueues);
2389
- const input = EventConfig.parse(config);
2390
- return input;
2391
- };
2392
-
2393
- // ../commons/src/events/transactions.ts
2394
- function generateTransactionId() {
2395
- return getUUID();
2396
- }
2397
-
2398
- // ../commons/src/events/test.utils.ts
2399
- var import_lodash2 = require("lodash");
2279
+ var QueryType = import_zod19.z.discriminatedUnion("type", [Or2, And2]);
2400
2280
 
2401
2281
  // ../commons/src/conditionals/conditionals.ts
2402
2282
  function defineConditional(schema) {
@@ -2460,32 +2340,38 @@ var user = {
2460
2340
  required: ["$user"]
2461
2341
  })
2462
2342
  };
2463
- var event = {
2464
- hasAction: (action) => defineConditional({
2465
- type: "object",
2466
- properties: {
2467
- $event: {
2468
- type: "object",
2469
- properties: {
2470
- actions: {
2471
- type: "array",
2472
- contains: {
2473
- type: "object",
2474
- properties: {
2475
- type: {
2476
- const: action
2477
- }
2478
- },
2479
- required: ["type"]
2343
+ function createEventConditionals() {
2344
+ return {
2345
+ /**
2346
+ * Checks if the event contains a specific action type.
2347
+ * @param action - The action type to check for.
2348
+ */
2349
+ hasAction: (action) => defineConditional({
2350
+ type: "object",
2351
+ properties: {
2352
+ $event: {
2353
+ type: "object",
2354
+ properties: {
2355
+ actions: {
2356
+ type: "array",
2357
+ contains: {
2358
+ type: "object",
2359
+ properties: {
2360
+ type: {
2361
+ const: action
2362
+ }
2363
+ },
2364
+ required: ["type"]
2365
+ }
2480
2366
  }
2481
- }
2482
- },
2483
- required: ["actions"]
2484
- }
2485
- },
2486
- required: ["$event"]
2487
- })
2488
- };
2367
+ },
2368
+ required: ["actions"]
2369
+ }
2370
+ },
2371
+ required: ["$event"]
2372
+ })
2373
+ };
2374
+ }
2489
2375
  function getDateFromNow(days) {
2490
2376
  return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2491
2377
  }
@@ -2506,7 +2392,7 @@ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2506
2392
  function isFieldReference(value) {
2507
2393
  return typeof value === "object" && value !== null && "_fieldId" in value;
2508
2394
  }
2509
- function field(fieldId) {
2395
+ function createFieldConditionals(fieldId) {
2510
2396
  const getDateRange = (date, clause) => ({
2511
2397
  type: "object",
2512
2398
  properties: {
@@ -2519,10 +2405,6 @@ function field(fieldId) {
2519
2405
  required: [fieldId]
2520
2406
  });
2521
2407
  return {
2522
- /**
2523
- * @private Internal property used for field reference tracking.
2524
- */
2525
- _fieldId: fieldId,
2526
2408
  isAfter: () => ({
2527
2409
  days: (days) => ({
2528
2410
  inPast: () => defineFormConditional(
@@ -2661,39 +2543,650 @@ function field(fieldId) {
2661
2543
  pattern: "^[\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*( [\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*)*$",
2662
2544
  description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2663
2545
  }
2664
- },
2665
- required: [fieldId]
2666
- }),
2546
+ },
2547
+ required: [fieldId]
2548
+ }),
2549
+ /**
2550
+ * Checks if the field value matches a given regular expression pattern.
2551
+ * @param pattern - The regular expression pattern to match the field value against.
2552
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2553
+ */
2554
+ matches: (pattern) => defineFormConditional({
2555
+ type: "object",
2556
+ properties: {
2557
+ [fieldId]: {
2558
+ type: "string",
2559
+ pattern
2560
+ }
2561
+ },
2562
+ required: [fieldId]
2563
+ }),
2564
+ isBetween: (min, max) => defineFormConditional({
2565
+ type: "object",
2566
+ properties: {
2567
+ [fieldId]: {
2568
+ type: "number",
2569
+ minimum: min,
2570
+ maximum: max
2571
+ }
2572
+ },
2573
+ required: [fieldId]
2574
+ }),
2575
+ getId: () => ({ fieldId })
2576
+ };
2577
+ }
2578
+
2579
+ // ../commons/src/searchConfigs.ts
2580
+ function createSearchConfig(baseField) {
2581
+ return {
2582
+ /**
2583
+ * Creates a range configuration for the specified field.
2584
+ *
2585
+ * @returns An object containing the field ID and a configuration object with a type of 'range'.
2586
+ *
2587
+ * @example event('legalStatus.REGISTERED.createdAt').range()
2588
+ * // {
2589
+ * // ...
2590
+ * // config: { type: 'range' }
2591
+ * // }
2592
+ */
2593
+ range: () => ({
2594
+ ...baseField,
2595
+ config: { type: "range" }
2596
+ }),
2597
+ /**
2598
+ * Creates a configuration for exact matching of the specified field.
2599
+ * @returns An object containing the field ID and a configuration object with a type of 'exact'.
2600
+ * @example field('dob').exact()
2601
+ * // {
2602
+ * // ...
2603
+ * // config: { type: 'exact' }
2604
+ * // }
2605
+ */
2606
+ exact: () => ({
2607
+ ...baseField,
2608
+ config: { type: "exact" }
2609
+ }),
2610
+ /**
2611
+ * Creates a configuration for fuzzy matching of the specified field.
2612
+ * @returns An object containing the field ID and a configuration object with a type of 'exact'.
2613
+ * @example field('name').fuzzy()
2614
+ * // {
2615
+ * // ...
2616
+ * // config: { type: 'fuzzy' }
2617
+ * // }
2618
+ */
2619
+ fuzzy: () => ({
2620
+ ...baseField,
2621
+ config: { type: "fuzzy" }
2622
+ })
2623
+ };
2624
+ }
2625
+
2626
+ // ../commons/src/event-config/event-configuration.ts
2627
+ function createEventFieldConfig(fieldId, options) {
2628
+ const baseField = {
2629
+ fieldId,
2630
+ options,
2631
+ fieldType: "event"
2632
+ };
2633
+ return createSearchConfig(baseField);
2634
+ }
2635
+
2636
+ // ../commons/src/events/event.ts
2637
+ function eventFn(fieldId, options) {
2638
+ return createEventFieldConfig(fieldId, options);
2639
+ }
2640
+ var event = Object.assign(eventFn, {
2641
+ ...createEventConditionals(),
2642
+ field(field2) {
2643
+ return {
2644
+ $event: field2
2645
+ };
2646
+ }
2647
+ });
2648
+
2649
+ // ../commons/src/events/WorkqueueConfig.ts
2650
+ var WorkqueueConfig = import_zod20.z.object({
2651
+ slug: import_zod20.z.string().describe("Determines the url of the workqueue."),
2652
+ name: TranslationConfig.describe(
2653
+ "Title of the workflow (both in navigation and on the page)"
2654
+ ),
2655
+ query: QueryType,
2656
+ actions: import_zod20.z.array(
2657
+ import_zod20.z.object({
2658
+ type: import_zod20.z.string(),
2659
+ conditionals: import_zod20.z.array(Conditional).optional()
2660
+ })
2661
+ ),
2662
+ columns: import_zod20.z.array(
2663
+ import_zod20.z.object({ label: TranslationConfig, value: EventMetadataParameter })
2664
+ ).default([
2665
+ {
2666
+ label: {
2667
+ id: "workqueues.dateOfEvent",
2668
+ defaultMessage: "Date of Event",
2669
+ description: "Label for workqueue column: dateOfEvent"
2670
+ },
2671
+ value: event.field("dateOfEvent")
2672
+ }
2673
+ ])
2674
+ }).describe("Configuration for workqueue.");
2675
+ function defineWorkqueue(workqueues) {
2676
+ return workqueues.map((workqueue) => WorkqueueConfig.parse(workqueue));
2677
+ }
2678
+
2679
+ // ../commons/src/events/Draft.ts
2680
+ var import_zod22 = require("zod");
2681
+
2682
+ // ../commons/src/events/ActionInput.ts
2683
+ var import_zod21 = require("zod");
2684
+ var import_zod_openapi9 = require("zod-openapi");
2685
+ var import_uuid3 = require("uuid");
2686
+ (0, import_zod_openapi9.extendZodWithOpenApi)(import_zod21.z);
2687
+ var BaseActionInput = import_zod21.z.object({
2688
+ eventId: import_zod21.z.string(),
2689
+ transactionId: import_zod21.z.string(),
2690
+ declaration: ActionUpdate.default({}),
2691
+ annotation: ActionUpdate.optional(),
2692
+ originalActionId: import_zod21.z.string().optional(),
2693
+ keepAssignment: import_zod21.z.boolean().optional()
2694
+ });
2695
+ var CreateActionInput = BaseActionInput.merge(
2696
+ import_zod21.z.object({
2697
+ type: import_zod21.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2698
+ createdAtLocation: import_zod21.z.string()
2699
+ })
2700
+ );
2701
+ var RegisterActionInput = BaseActionInput.merge(
2702
+ import_zod21.z.object({
2703
+ type: import_zod21.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2704
+ registrationNumber: import_zod21.z.string().optional()
2705
+ })
2706
+ );
2707
+ var ValidateActionInput = BaseActionInput.merge(
2708
+ import_zod21.z.object({
2709
+ type: import_zod21.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2710
+ duplicates: import_zod21.z.array(import_zod21.z.string())
2711
+ })
2712
+ );
2713
+ var NotifyActionInput = BaseActionInput.merge(
2714
+ import_zod21.z.object({
2715
+ type: import_zod21.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2716
+ })
2717
+ ).openapi({
2718
+ default: {
2719
+ eventId: "<event-id-here>",
2720
+ transactionId: (0, import_uuid3.v4)(),
2721
+ declaration: {},
2722
+ annotation: {},
2723
+ type: ActionType.NOTIFY
2724
+ }
2725
+ });
2726
+ var DeclareActionInput = BaseActionInput.merge(
2727
+ import_zod21.z.object({
2728
+ type: import_zod21.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2729
+ })
2730
+ );
2731
+ var PrintCertificateActionInput = BaseActionInput.merge(
2732
+ import_zod21.z.object({
2733
+ type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2734
+ })
2735
+ );
2736
+ var RejectDeclarationActionInput = BaseActionInput.merge(
2737
+ import_zod21.z.object({
2738
+ type: import_zod21.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2739
+ })
2740
+ );
2741
+ var MarkedAsDuplicateActionInput = BaseActionInput.merge(
2742
+ import_zod21.z.object({
2743
+ type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2744
+ })
2745
+ );
2746
+ var ArchiveActionInput = BaseActionInput.merge(
2747
+ import_zod21.z.object({
2748
+ type: import_zod21.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2749
+ })
2750
+ );
2751
+ var AssignActionInput = BaseActionInput.merge(
2752
+ import_zod21.z.object({
2753
+ type: import_zod21.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2754
+ assignedTo: import_zod21.z.string()
2755
+ })
2756
+ );
2757
+ var UnassignActionInput = BaseActionInput.merge(
2758
+ import_zod21.z.object({
2759
+ type: import_zod21.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2760
+ assignedTo: import_zod21.z.literal(null).default(null)
2761
+ })
2762
+ );
2763
+ var RequestCorrectionActionInput = BaseActionInput.merge(
2764
+ import_zod21.z.object({
2765
+ type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2766
+ })
2767
+ );
2768
+ var RejectCorrectionActionInput = BaseActionInput.merge(
2769
+ import_zod21.z.object({
2770
+ requestId: import_zod21.z.string(),
2771
+ type: import_zod21.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2772
+ })
2773
+ );
2774
+ var ApproveCorrectionActionInput = BaseActionInput.merge(
2775
+ import_zod21.z.object({
2776
+ requestId: import_zod21.z.string(),
2777
+ type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2778
+ })
2779
+ );
2780
+ var ReadActionInput = BaseActionInput.merge(
2781
+ import_zod21.z.object({
2782
+ type: import_zod21.z.literal(ActionType.READ).default(ActionType.READ)
2783
+ })
2784
+ );
2785
+ var DeleteActionInput = import_zod21.z.object({ eventId: import_zod21.z.string() });
2786
+ var ActionInput = import_zod21.z.discriminatedUnion("type", [
2787
+ CreateActionInput.openapi({ ref: "CreateActionInput" }),
2788
+ ValidateActionInput.openapi({ ref: "ValidateActionInput" }),
2789
+ RegisterActionInput.openapi({ ref: "RegisterActionInput" }),
2790
+ NotifyActionInput.openapi({ ref: "NotifyActionInput" }),
2791
+ DeclareActionInput.openapi({ ref: "DeclareActionInput" }),
2792
+ RejectDeclarationActionInput.openapi({
2793
+ ref: "RejectDeclarationActionInput"
2794
+ }),
2795
+ MarkedAsDuplicateActionInput.openapi({
2796
+ ref: "MarkedAsDuplicateActionInput"
2797
+ }),
2798
+ ArchiveActionInput.openapi({ ref: "ArchiveActionInput" }),
2799
+ AssignActionInput.openapi({ ref: "AssignActionInput" }),
2800
+ UnassignActionInput.openapi({ ref: "UnassignActionInput" }),
2801
+ PrintCertificateActionInput.openapi({ ref: "PrintCertificateActionInput" }),
2802
+ RequestCorrectionActionInput.openapi({
2803
+ ref: "RequestCorrectionActionInput"
2804
+ }),
2805
+ RejectCorrectionActionInput.openapi({ ref: "RejectCorrectionActionInput" }),
2806
+ ApproveCorrectionActionInput.openapi({
2807
+ ref: "ApproveCorrectionActionInput"
2808
+ }),
2809
+ ReadActionInput.openapi({ ref: "ReadActionInput" })
2810
+ ]).openapi({
2811
+ ref: "ActionInput"
2812
+ });
2813
+
2814
+ // ../commons/src/events/Draft.ts
2815
+ var Draft = import_zod22.z.object({
2816
+ id: import_zod22.z.string(),
2817
+ eventId: import_zod22.z.string(),
2818
+ transactionId: import_zod22.z.string(),
2819
+ createdAt: import_zod22.z.string().datetime(),
2820
+ action: ActionBase.extend({
2821
+ type: ActionTypes
2822
+ }).omit({ id: true })
2823
+ });
2824
+ var DraftInput = BaseActionInput.extend({
2825
+ type: ActionTypes,
2826
+ status: import_zod22.z.enum([
2827
+ ActionStatus.Requested,
2828
+ ActionStatus.Accepted,
2829
+ ActionStatus.Rejected
2830
+ ])
2831
+ });
2832
+
2833
+ // ../commons/src/events/EventInput.ts
2834
+ var import_zod23 = require("zod");
2835
+ var import_uuid4 = require("uuid");
2836
+ var EventInput = import_zod23.z.object({
2837
+ transactionId: import_zod23.z.string(),
2838
+ type: import_zod23.z.string(),
2839
+ dateOfEvent: import_zod23.z.object({ fieldId: import_zod23.z.string() }).optional()
2840
+ }).openapi({ default: { transactionId: (0, import_uuid4.v4)(), type: "v2.birth" } });
2841
+
2842
+ // ../commons/src/events/EventDocument.ts
2843
+ var import_zod24 = require("zod");
2844
+ var import_zod_openapi10 = require("zod-openapi");
2845
+ (0, import_zod_openapi10.extendZodWithOpenApi)(import_zod24.z);
2846
+ var EventDocument = import_zod24.z.object({
2847
+ id: import_zod24.z.string(),
2848
+ type: import_zod24.z.string(),
2849
+ dateOfEvent: import_zod24.z.object({ fieldId: import_zod24.z.string() }).optional(),
2850
+ createdAt: import_zod24.z.string().datetime(),
2851
+ updatedAt: import_zod24.z.string().datetime(),
2852
+ actions: import_zod24.z.array(Action),
2853
+ trackingId: import_zod24.z.string()
2854
+ }).openapi({ ref: "EventDocument" });
2855
+
2856
+ // ../commons/src/events/state/utils.ts
2857
+ function getActionRequests(actionType, actions) {
2858
+ const filtered = actions.filter((action) => action.type === actionType);
2859
+ const accept = filtered.find(
2860
+ (action) => action.status === ActionStatus.Accepted
2861
+ );
2862
+ const request = filtered.find(
2863
+ (action) => action.status === ActionStatus.Requested
2864
+ );
2865
+ const reject = filtered.find(
2866
+ (action) => action.status === ActionStatus.Rejected
2867
+ );
2868
+ return {
2869
+ reject,
2870
+ accept,
2871
+ request
2872
+ };
2873
+ }
2874
+ function getDeclarationActionCreationMetadata(actionType, actions) {
2875
+ const { accept: acceptAction, request: requestAction } = getActionRequests(
2876
+ actionType,
2877
+ actions
2878
+ );
2879
+ if (!acceptAction) {
2880
+ return null;
2881
+ }
2882
+ const registrationNumber = acceptAction.type === ActionType.REGISTER ? acceptAction.registrationNumber : null;
2883
+ return {
2884
+ // When 3rd party API returns 200 OK, we assume that the request was accepted, and persist single 'accepted' action.
2885
+ createdAt: requestAction?.createdAt ?? acceptAction.createdAt,
2886
+ createdBy: requestAction?.createdBy ?? acceptAction.createdBy,
2887
+ createdAtLocation: requestAction?.createdAtLocation ?? acceptAction.createdAtLocation,
2888
+ acceptedAt: acceptAction.createdAt,
2889
+ createdByRole: requestAction?.createdByRole ?? acceptAction.createdByRole,
2890
+ registrationNumber
2891
+ };
2892
+ }
2893
+ function getDeclarationActionUpdateMetadata(actions) {
2894
+ const createAction = getOrThrow(
2895
+ actions.find((action) => action.type === ActionType.CREATE),
2896
+ `Event has no ${ActionType.CREATE} action`
2897
+ );
2898
+ return [ActionType.DECLARE, ActionType.VALIDATE, ActionType.REGISTER].reduce(
2899
+ (metadata, actionType) => {
2900
+ const { accept, request } = getActionRequests(actionType, actions);
2901
+ return {
2902
+ createdAt: request?.createdAt ?? accept?.createdAt ?? metadata.createdAt,
2903
+ createdBy: request?.createdBy ?? accept?.createdBy ?? metadata.createdBy,
2904
+ createdAtLocation: request?.createdAtLocation ?? accept?.createdAtLocation ?? metadata.createdAtLocation,
2905
+ createdByRole: request?.createdByRole ?? accept?.createdByRole ?? metadata.createdByRole
2906
+ };
2907
+ },
2908
+ {
2909
+ createdAt: createAction.createdAt,
2910
+ createdBy: createAction.createdBy,
2911
+ createdAtLocation: createAction.createdAtLocation,
2912
+ createdByRole: createAction.createdByRole
2913
+ }
2914
+ );
2915
+ }
2916
+ function getLegalStatuses(actions) {
2917
+ return {
2918
+ [EventStatus.DECLARED]: getDeclarationActionCreationMetadata(
2919
+ ActionType.DECLARE,
2920
+ actions
2921
+ ),
2922
+ [EventStatus.REGISTERED]: getDeclarationActionCreationMetadata(
2923
+ ActionType.REGISTER,
2924
+ actions
2925
+ )
2926
+ };
2927
+ }
2928
+
2929
+ // ../commons/src/events/state/index.ts
2930
+ function getStatusFromActions(actions) {
2931
+ const hasRejectedAction = actions.some(
2932
+ (a) => a.status === ActionStatus.Rejected
2933
+ );
2934
+ if (hasRejectedAction) {
2935
+ return EventStatus.REJECTED;
2936
+ }
2937
+ return actions.reduce((status, action) => {
2938
+ switch (action.type) {
2939
+ case ActionType.CREATE:
2940
+ return EventStatus.CREATED;
2941
+ case ActionType.DECLARE:
2942
+ return EventStatus.DECLARED;
2943
+ case ActionType.VALIDATE:
2944
+ return EventStatus.VALIDATED;
2945
+ case ActionType.REGISTER:
2946
+ return EventStatus.REGISTERED;
2947
+ case ActionType.REJECT:
2948
+ return EventStatus.REJECTED;
2949
+ case ActionType.ARCHIVE:
2950
+ return EventStatus.ARCHIVED;
2951
+ case ActionType.NOTIFY:
2952
+ return EventStatus.NOTIFIED;
2953
+ case ActionType.PRINT_CERTIFICATE:
2954
+ return EventStatus.CERTIFIED;
2955
+ case ActionType.ASSIGN:
2956
+ case ActionType.UNASSIGN:
2957
+ case ActionType.REQUEST_CORRECTION:
2958
+ case ActionType.APPROVE_CORRECTION:
2959
+ case ActionType.MARKED_AS_DUPLICATE:
2960
+ case ActionType.REJECT_CORRECTION:
2961
+ case ActionType.READ:
2962
+ default:
2963
+ return status;
2964
+ }
2965
+ }, EventStatus.CREATED);
2966
+ }
2967
+ function getFlagsFromActions(actions) {
2968
+ const sortedactions = actions.sort(
2969
+ (a, b) => a.createdAt.localeCompare(b.createdAt)
2970
+ );
2971
+ const actionStatus = sortedactions.reduce(
2972
+ (actionStatuses, { type, status }) => ({
2973
+ ...actionStatuses,
2974
+ [type]: status
2975
+ }),
2976
+ {}
2977
+ );
2978
+ const flags = Object.entries(actionStatus).filter(([, status]) => status !== ActionStatus.Accepted).map(([type, status]) => {
2979
+ const flag = `${type.toLowerCase()}:${status.toLowerCase()}`;
2980
+ return flag;
2981
+ });
2982
+ const isCertificatePrinted = sortedactions.reduce(
2983
+ (prev, { type }) => {
2984
+ if (type === ActionType.PRINT_CERTIFICATE) {
2985
+ return true;
2986
+ }
2987
+ if (type === ActionType.APPROVE_CORRECTION) {
2988
+ return false;
2989
+ }
2990
+ return prev;
2991
+ },
2992
+ false
2993
+ );
2994
+ if (isCertificatePrinted) {
2995
+ flags.push(CustomFlags.CERTIFICATE_PRINTED);
2996
+ }
2997
+ return flags;
2998
+ }
2999
+ function getAssignedUserFromActions(actions) {
3000
+ return actions.reduce((user2, action) => {
3001
+ if (action.type === ActionType.ASSIGN) {
3002
+ return action.assignedTo;
3003
+ }
3004
+ if (action.type === ActionType.UNASSIGN) {
3005
+ return null;
3006
+ }
3007
+ return user2;
3008
+ }, null);
3009
+ }
3010
+ function aggregateActionDeclarations(actions) {
3011
+ const excludedActions = [
3012
+ ActionType.REQUEST_CORRECTION,
3013
+ ActionType.PRINT_CERTIFICATE
3014
+ ];
3015
+ return actions.reduce((status, action) => {
3016
+ if (excludedActions.some((excludedAction) => excludedAction === action.type)) {
3017
+ return status;
3018
+ }
3019
+ if (action.type === ActionType.APPROVE_CORRECTION) {
3020
+ const requestAction = actions.find(({ id }) => id === action.requestId);
3021
+ if (!requestAction) {
3022
+ return status;
3023
+ }
3024
+ return deepMerge(status, requestAction.declaration);
3025
+ }
3026
+ return deepMerge(status, action.declaration);
3027
+ }, {});
3028
+ }
3029
+ function deepDropNulls(obj) {
3030
+ if (Array.isArray(obj)) {
3031
+ return obj.map(deepDropNulls);
3032
+ }
3033
+ if (obj !== null && typeof obj === "object") {
3034
+ return Object.entries(obj).reduce((acc, [key, value]) => {
3035
+ const cleanedValue = deepDropNulls(value);
3036
+ if (cleanedValue !== null) {
3037
+ ;
3038
+ acc[key] = cleanedValue;
3039
+ }
3040
+ return acc;
3041
+ }, {});
3042
+ }
3043
+ return obj;
3044
+ }
3045
+ function isUndeclaredDraft(status) {
3046
+ return status === EventStatus.CREATED;
3047
+ }
3048
+ function getAcceptedActions(event2) {
3049
+ return event2.actions.filter(
3050
+ (a) => a.status === ActionStatus.Accepted
3051
+ );
3052
+ }
3053
+ var DEFAULT_DATE_OF_EVENT_PROPERTY = "createdAt";
3054
+ function getCurrentEventState(event2) {
3055
+ const creationAction = event2.actions.find(
3056
+ (action) => action.type === ActionType.CREATE
3057
+ );
3058
+ if (!creationAction) {
3059
+ throw new Error(`Event ${event2.id} has no creation action`);
3060
+ }
3061
+ const acceptedActions = getAcceptedActions(event2);
3062
+ const declarationUpdateMetadata = getDeclarationActionUpdateMetadata(
3063
+ event2.actions
3064
+ );
3065
+ const declaration = aggregateActionDeclarations(acceptedActions);
3066
+ const dateOfEvent = ZodDate.safeParse(
3067
+ event2.dateOfEvent?.fieldId ? declaration[event2.dateOfEvent.fieldId] : event2[DEFAULT_DATE_OF_EVENT_PROPERTY]
3068
+ ).data ?? null;
3069
+ return deepDropNulls({
3070
+ id: event2.id,
3071
+ type: event2.type,
3072
+ status: getStatusFromActions(event2.actions),
3073
+ legalStatuses: getLegalStatuses(event2.actions),
3074
+ createdAt: creationAction.createdAt,
3075
+ createdBy: creationAction.createdBy,
3076
+ createdAtLocation: creationAction.createdAtLocation,
3077
+ updatedAt: declarationUpdateMetadata.createdAt,
3078
+ assignedTo: getAssignedUserFromActions(acceptedActions),
3079
+ updatedBy: declarationUpdateMetadata.createdBy,
3080
+ updatedAtLocation: declarationUpdateMetadata.createdAtLocation,
3081
+ declaration,
3082
+ trackingId: event2.trackingId,
3083
+ // @TODO: unify this with rest of the code. It will trip us if updatedBy has different rules than updatedByUserRole
3084
+ updatedByUserRole: declarationUpdateMetadata.createdByRole,
3085
+ dateOfEvent,
3086
+ flags: getFlagsFromActions(event2.actions)
3087
+ });
3088
+ }
3089
+ function getCurrentEventStateWithDrafts(event2, drafts) {
3090
+ const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
3091
+ const activeDrafts = findActiveDrafts(event2, drafts).map((draft) => draft.action).flatMap((action) => {
3092
+ if (action.type === ActionType.REQUEST_CORRECTION) {
3093
+ return [
3094
+ action,
3095
+ {
3096
+ ...action,
3097
+ type: ActionType.APPROVE_CORRECTION
3098
+ }
3099
+ ];
3100
+ }
3101
+ return [action];
3102
+ });
3103
+ const actionWithDrafts = [...actions, ...activeDrafts].sort();
3104
+ const withDrafts = {
3105
+ ...event2,
3106
+ actions: actionWithDrafts
3107
+ };
3108
+ return getCurrentEventState(withDrafts);
3109
+ }
3110
+ function applyDraftsToEventIndex(eventIndex, drafts) {
3111
+ const indexedAt = eventIndex.updatedAt;
3112
+ const activeDrafts = drafts.filter(({ createdAt }) => new Date(createdAt) > new Date(indexedAt)).map((draft) => draft.action).sort();
3113
+ if (activeDrafts.length === 0) {
3114
+ return eventIndex;
3115
+ }
3116
+ return {
3117
+ ...eventIndex,
3118
+ declaration: {
3119
+ ...eventIndex.declaration,
3120
+ ...activeDrafts[activeDrafts.length - 1].declaration
3121
+ }
3122
+ };
3123
+ }
3124
+ function getAnnotationFromDrafts(drafts) {
3125
+ const actions = drafts.map((draft) => draft.action);
3126
+ const annotation = actions.reduce((ann, action) => {
3127
+ return deepMerge(ann, action.annotation ?? {});
3128
+ }, {});
3129
+ return deepDropNulls(annotation);
3130
+ }
3131
+ function getActionAnnotation({
3132
+ event: event2,
3133
+ actionType,
3134
+ drafts = []
3135
+ }) {
3136
+ const activeActions = getAcceptedActions(event2);
3137
+ const action = activeActions.find(
3138
+ (activeAction) => actionType === activeAction.type
3139
+ );
3140
+ const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
3141
+ const sorted = [
3142
+ ...action ? [action] : [],
3143
+ ...eventDrafts.map((draft) => draft.action)
3144
+ ].sort();
3145
+ const annotation = sorted.reduce((ann, sortedAction) => {
3146
+ return deepMerge(ann, sortedAction.annotation ?? {});
3147
+ }, {});
3148
+ return deepDropNulls(annotation);
3149
+ }
3150
+
3151
+ // ../commons/src/events/defineConfig.ts
3152
+ var defineConfig = (config) => {
3153
+ const input = EventConfig.parse(config);
3154
+ return input;
3155
+ };
3156
+
3157
+ // ../commons/src/events/transactions.ts
3158
+ function generateTransactionId() {
3159
+ return getUUID();
3160
+ }
3161
+
3162
+ // ../commons/src/events/test.utils.ts
3163
+ var import_lodash2 = require("lodash");
3164
+ var import_addDays = __toESM(require("date-fns/addDays"));
3165
+
3166
+ // ../commons/src/field-config/field-configuration.ts
3167
+ function createFieldConfig(fieldId, options) {
3168
+ const baseField = {
3169
+ fieldId,
3170
+ fieldType: "field",
3171
+ ...options
3172
+ };
3173
+ return createSearchConfig(baseField);
3174
+ }
3175
+
3176
+ // ../commons/src/events/field.ts
3177
+ function field(fieldId, options = {}) {
3178
+ return {
2667
3179
  /**
2668
- * Checks if the field value matches a given regular expression pattern.
2669
- * @param pattern - The regular expression pattern to match the field value against.
2670
- * @returns A JSONSchema conditional that validates the field value against the pattern.
3180
+ * @private Internal property used for field reference tracking.
2671
3181
  */
2672
- matches: (pattern) => defineFormConditional({
2673
- type: "object",
2674
- properties: {
2675
- [fieldId]: {
2676
- type: "string",
2677
- pattern
2678
- }
2679
- },
2680
- required: [fieldId]
2681
- }),
2682
- isBetween: (min, max) => defineFormConditional({
2683
- type: "object",
2684
- properties: {
2685
- [fieldId]: {
2686
- type: "number",
2687
- minimum: min,
2688
- maximum: max
2689
- }
2690
- },
2691
- required: [fieldId]
2692
- })
3182
+ _fieldId: fieldId,
3183
+ ...createFieldConditionals(fieldId),
3184
+ ...createFieldConfig(fieldId, options)
2693
3185
  };
2694
3186
  }
2695
3187
 
2696
3188
  // ../commons/src/fixtures/tennis-club-membership-event.ts
3189
+ var import_date_fns2 = require("date-fns");
2697
3190
  var PRINT_CERTIFICATE_FORM = defineActionForm({
2698
3191
  label: {
2699
3192
  id: "v2.event.tennis-club-membership.action.certificate.form.label",
@@ -3602,6 +4095,114 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3602
4095
  }
3603
4096
  ]
3604
4097
  });
4098
+ var statusOptions = [
4099
+ {
4100
+ value: "ALL",
4101
+ label: {
4102
+ defaultMessage: "Any status",
4103
+ description: "Option for form field: status of record",
4104
+ id: "v2.advancedSearch.form.recordStatusAny"
4105
+ }
4106
+ },
4107
+ {
4108
+ value: EventStatus.CREATED,
4109
+ label: {
4110
+ defaultMessage: "Draft",
4111
+ description: "Option for form field: status of record",
4112
+ id: "v2.advancedSearch.form.recordStatusCreated"
4113
+ }
4114
+ },
4115
+ {
4116
+ value: EventStatus.NOTIFIED,
4117
+ label: {
4118
+ defaultMessage: "Notified",
4119
+ description: "Option for form field: status of record",
4120
+ id: "v2.advancedSearch.form.recordStatusNotified"
4121
+ }
4122
+ },
4123
+ {
4124
+ value: EventStatus.DECLARED,
4125
+ label: {
4126
+ defaultMessage: "Declared",
4127
+ description: "Option for form field: status of record",
4128
+ id: "v2.advancedSearch.form.recordStatusDeclared"
4129
+ }
4130
+ },
4131
+ {
4132
+ value: EventStatus.VALIDATED,
4133
+ label: {
4134
+ defaultMessage: "Validated",
4135
+ description: "Option for form field: status of record",
4136
+ id: "v2.advancedSearch.form.recordStatusValidated"
4137
+ }
4138
+ },
4139
+ {
4140
+ value: EventStatus.REGISTERED,
4141
+ label: {
4142
+ defaultMessage: "Registered",
4143
+ description: "Option for form field: status of record",
4144
+ id: "v2.advancedSearch.form.recordStatusRegistered"
4145
+ }
4146
+ },
4147
+ {
4148
+ value: EventStatus.CERTIFIED,
4149
+ label: {
4150
+ defaultMessage: "Certified",
4151
+ description: "Option for form field: status of record",
4152
+ id: "v2.advancedSearch.form.recordStatusCertified"
4153
+ }
4154
+ },
4155
+ {
4156
+ value: EventStatus.REJECTED,
4157
+ label: {
4158
+ defaultMessage: "Rejected",
4159
+ description: "Option for form field: status of record",
4160
+ id: "v2.advancedSearch.form.recordStatusRejected"
4161
+ }
4162
+ },
4163
+ {
4164
+ value: EventStatus.ARCHIVED,
4165
+ label: {
4166
+ defaultMessage: "Archived",
4167
+ description: "Option for form field: status of record",
4168
+ id: "v2.advancedSearch.form.recordStatusArchived"
4169
+ }
4170
+ }
4171
+ ];
4172
+ var timePeriodOptions = [
4173
+ {
4174
+ label: {
4175
+ defaultMessage: "Last 7 days",
4176
+ description: "Label for option of time period select: last 7 days",
4177
+ id: "form.section.label.timePeriodLast7Days"
4178
+ },
4179
+ value: `${(0, import_date_fns2.format)((0, import_date_fns2.subDays)(/* @__PURE__ */ new Date(), 7), "yyyy-MM-dd")},${(0, import_date_fns2.format)(/* @__PURE__ */ new Date(), "yyyy-MM-dd")}`
4180
+ },
4181
+ {
4182
+ label: {
4183
+ defaultMessage: "Last 30 days",
4184
+ description: "Label for option of time period select: last 30 days",
4185
+ id: "form.section.label.timePeriodLast30Days"
4186
+ },
4187
+ value: `${(0, import_date_fns2.format)((0, import_date_fns2.subMonths)(/* @__PURE__ */ new Date(), 1), "yyyy-MM-dd")},${(0, import_date_fns2.format)(/* @__PURE__ */ new Date(), "yyyy-MM-dd")}`
4188
+ },
4189
+ {
4190
+ label: {
4191
+ defaultMessage: "Last 90 days",
4192
+ description: "Label for option of time period select: last 90 days",
4193
+ id: "form.section.label.timePeriodLast90Days"
4194
+ },
4195
+ value: `${(0, import_date_fns2.format)((0, import_date_fns2.subQuarters)(/* @__PURE__ */ new Date(), 1), "yyyy-MM-dd")},${(0, import_date_fns2.format)(/* @__PURE__ */ new Date(), "yyyy-MM-dd")}`
4196
+ },
4197
+ {
4198
+ label: {
4199
+ defaultMessage: "Last year",
4200
+ description: "Label for option of time period select: last year",
4201
+ id: "form.section.label.timePeriodLastYear"
4202
+ },
4203
+ value: `${(0, import_date_fns2.format)((0, import_date_fns2.subYears)(/* @__PURE__ */ new Date(), 1), "yyyy-MM-dd")},${(0, import_date_fns2.format)(/* @__PURE__ */ new Date(), "yyyy-MM-dd")}`
4204
+ }
4205
+ ];
3605
4206
  var tennisClubMembershipEvent = defineConfig({
3606
4207
  id: "TENNIS_CLUB_MEMBERSHIP",
3607
4208
  label: {
@@ -3609,20 +4210,12 @@ var tennisClubMembershipEvent = defineConfig({
3609
4210
  description: "This is what this event is referred as in the system",
3610
4211
  id: "event.tennis-club-membership.label"
3611
4212
  },
4213
+ title: {
4214
+ defaultMessage: "{applicant.firstname} {applicant.surname}",
4215
+ description: "This is the title of the summary",
4216
+ id: "v2.event.tennis-club-membership.title"
4217
+ },
3612
4218
  summary: {
3613
- title: {
3614
- id: "event.tennis-club-membership.summary.title",
3615
- label: {
3616
- defaultMessage: "{applicant.firstname} {applicant.surname}",
3617
- description: "This is the title of the summary",
3618
- id: "v2.event.tennis-club-membership.summary.title"
3619
- },
3620
- emptyValueMessage: {
3621
- defaultMessage: "Membership application",
3622
- description: "This is the message shown when the applicant name is missing",
3623
- id: "event.tennis-club-membership.summary.title.empty"
3624
- }
3625
- },
3626
4219
  fields: [
3627
4220
  {
3628
4221
  id: "applicant.firstname",
@@ -3643,47 +4236,18 @@ var tennisClubMembershipEvent = defineConfig({
3643
4236
  }
3644
4237
  },
3645
4238
  {
3646
- id: "applicant.surname",
4239
+ fieldId: "applicant.surname",
3647
4240
  label: {
3648
4241
  defaultMessage: "Applicant's last name",
3649
- description: "This is the label for the field",
3650
- id: "event.tennis-club-membership.summary.field.surname.label"
3651
- },
3652
- value: {
3653
- defaultMessage: "{applicant.surname}",
3654
- description: "This is the value to show in the summary",
3655
- id: "event.tennis-club-membership.summary.field.surname"
3656
- },
3657
- emptyValueMessage: {
3658
- defaultMessage: "Last name is not provided",
3659
- description: "This is the message to show when the field is empty",
3660
- id: "event.tennis-club-membership.summary.field.surname.empty"
4242
+ description: "Label for surname",
4243
+ id: "v2.event.tennis-club-membership.summary.field.surname.label"
3661
4244
  }
4245
+ },
4246
+ {
4247
+ fieldId: "applicant.email"
3662
4248
  }
3663
4249
  ]
3664
4250
  },
3665
- workqueues: [
3666
- {
3667
- id: "all",
3668
- filters: []
3669
- },
3670
- {
3671
- id: "ready-for-review",
3672
- filters: [
3673
- {
3674
- status: ["DECLARED"]
3675
- }
3676
- ]
3677
- },
3678
- {
3679
- id: "registered",
3680
- filters: [
3681
- {
3682
- status: ["REGISTERED"]
3683
- }
3684
- ]
3685
- }
3686
- ],
3687
4251
  actions: [
3688
4252
  {
3689
4253
  type: ActionType.DECLARE,
@@ -3987,14 +4551,39 @@ var tennisClubMembershipEvent = defineConfig({
3987
4551
  advancedSearch: [
3988
4552
  {
3989
4553
  title: {
3990
- defaultMessage: "Tennis club registration search",
3991
- description: "This is what this event is referred as in the system",
3992
- id: "v2.event.tennis-club-membership.search"
4554
+ defaultMessage: "Registration details",
4555
+ description: "The title of Registration details accordion",
4556
+ id: "v2.advancedSearch.form.registrationDetails"
3993
4557
  },
3994
4558
  fields: [
3995
- {
3996
- fieldId: "applicant.dob"
3997
- }
4559
+ event("legalStatus.REGISTERED.createdAtLocation").exact(),
4560
+ event("legalStatus.REGISTERED.createdAt").range(),
4561
+ event("status", statusOptions).exact(),
4562
+ event("updatedAt", timePeriodOptions).range()
4563
+ ]
4564
+ },
4565
+ {
4566
+ title: {
4567
+ defaultMessage: "Applicant's details",
4568
+ description: "Applicant details search field section title",
4569
+ id: "v2.event.tennis-club-membership.search.applicants"
4570
+ },
4571
+ fields: [
4572
+ field("applicant.firstname").fuzzy(),
4573
+ field("applicant.surname").fuzzy(),
4574
+ field("applicant.dob").range(),
4575
+ field("applicant.email").exact()
4576
+ ]
4577
+ },
4578
+ {
4579
+ title: {
4580
+ defaultMessage: "Recommender's details",
4581
+ description: "Recommender details search field section title",
4582
+ id: "v2.event.tennis-club-membership.search.recommender"
4583
+ },
4584
+ fields: [
4585
+ field("recommender.firstname").fuzzy(),
4586
+ field("recommender.surname").fuzzy()
3998
4587
  ]
3999
4588
  }
4000
4589
  ],
@@ -4028,10 +4617,10 @@ function generateActionAnnotationInput(configuration, action) {
4028
4617
  );
4029
4618
  const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
4030
4619
  const annotation = fieldConfigsToActionPayload(annotationFields);
4031
- const visibleVerificationPageIds = findRecordActionPages(
4032
- configuration,
4033
- action
4034
- ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
4620
+ const visibleVerificationPageIds = getVisibleVerificationPageIds(
4621
+ findRecordActionPages(configuration, action),
4622
+ annotation
4623
+ );
4035
4624
  const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
4036
4625
  (acc, pageId) => ({
4037
4626
  ...acc,
@@ -4062,6 +4651,7 @@ var eventPayloadGenerator = {
4062
4651
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4063
4652
  transactionId: getUUID(),
4064
4653
  action: {
4654
+ transactionId: getUUID(),
4065
4655
  type: actionType,
4066
4656
  status: ActionStatus.Accepted,
4067
4657
  declaration: {
@@ -4076,6 +4666,7 @@ var eventPayloadGenerator = {
4076
4666
  },
4077
4667
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4078
4668
  createdBy: "@todo",
4669
+ createdByRole: "@todo",
4079
4670
  createdAtLocation: "@todo"
4080
4671
  }
4081
4672
  },
@@ -4237,12 +4828,14 @@ function generateActionDocument({
4237
4828
  // @TODO: This should be fixed in the future.
4238
4829
  createdAt: new Date(Date.now() - 500).toISOString(),
4239
4830
  createdBy: getUUID(),
4831
+ createdByRole: "FIELD_AGENT",
4240
4832
  id: getUUID(),
4241
- createdAtLocation: "TODO",
4833
+ createdAtLocation: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
4242
4834
  declaration: generateActionDeclarationInput(configuration, action),
4243
4835
  annotation: {},
4244
- ...defaults,
4245
- status: ActionStatus.Accepted
4836
+ status: ActionStatus.Accepted,
4837
+ transactionId: getUUID(),
4838
+ ...defaults
4246
4839
  };
4247
4840
  switch (action) {
4248
4841
  case ActionType.READ:
@@ -4301,7 +4894,7 @@ function generateEventDocument({
4301
4894
  // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4302
4895
  // @TODO: This should be fixed in the future.
4303
4896
  updatedAt: new Date(Date.now() - 1e3).toISOString(),
4304
- updatedAtLocation: "TODO"
4897
+ dateOfEvent: configuration.dateOfEvent
4305
4898
  };
4306
4899
  }
4307
4900
  function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
@@ -4323,25 +4916,97 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, de
4323
4916
  eventId
4324
4917
  };
4325
4918
  }
4326
- var eventQueryDataGenerator = (overrides = {}) => ({
4327
- id: overrides.id ?? getUUID(),
4328
- type: overrides.type ?? "tennis-club-membership",
4329
- status: overrides.status ?? "REGISTERED",
4330
- createdAt: overrides.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4331
- createdBy: overrides.createdBy ?? getUUID(),
4332
- createdAtLocation: overrides.createdAtLocation ?? getUUID(),
4333
- updatedAtLocation: overrides.updatedAtLocation ?? getUUID(),
4334
- modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4335
- assignedTo: overrides.assignedTo ?? null,
4336
- updatedBy: overrides.updatedBy ?? getUUID(),
4337
- declaration: overrides.declaration ?? {
4919
+ function pickRandom(rng, items) {
4920
+ return items[Math.floor(rng() * items.length)];
4921
+ }
4922
+ function getRandomDatetime(rng, start, end) {
4923
+ const range = end.getTime() - start.getTime();
4924
+ const offset = Math.floor(rng() * range);
4925
+ const randomDate = new Date(start.getTime() + offset);
4926
+ return randomDate.toISOString();
4927
+ }
4928
+ function generateRandomApplicant(rng) {
4929
+ const firstNames = [
4930
+ "Danny",
4931
+ "John",
4932
+ "Jane",
4933
+ "Emily",
4934
+ "Michael",
4935
+ "Sarah",
4936
+ "Chris",
4937
+ "Jessica"
4938
+ ];
4939
+ const surnames = [
4940
+ "Doe",
4941
+ "Smith",
4942
+ "Johnson",
4943
+ "Brown",
4944
+ "Williams",
4945
+ "Jones",
4946
+ "Garcia",
4947
+ "Miller"
4948
+ ];
4949
+ const randomFirstName = pickRandom(rng, firstNames);
4950
+ const randomSurname = pickRandom(rng, surnames);
4951
+ const randomDob = getRandomDatetime(
4952
+ rng,
4953
+ /* @__PURE__ */ new Date("1990-01-01"),
4954
+ /* @__PURE__ */ new Date("2010-12-31")
4955
+ ).split("T")[0];
4956
+ return {
4338
4957
  "recommender.none": true,
4339
- "applicant.firstname": "Danny",
4340
- "applicant.surname": "Doe",
4341
- "applicant.dob": "1999-11-11"
4342
- },
4343
- trackingId: overrides.trackingId ?? "M3F8YQ"
4344
- });
4958
+ "applicant.firstname": randomFirstName,
4959
+ "applicant.surname": randomSurname,
4960
+ "applicant.dob": randomDob
4961
+ };
4962
+ }
4963
+ function createPseudoRandomNumberGenerator(seed) {
4964
+ const MODULUS = 2 ** 32;
4965
+ const MULTIPLIER = 1664525;
4966
+ const INCREMENT = 1013904223;
4967
+ let state = seed >>> 0;
4968
+ return () => {
4969
+ state = (MULTIPLIER * state + INCREMENT) % MODULUS;
4970
+ return state / MODULUS;
4971
+ };
4972
+ }
4973
+ function generateUuid(rng) {
4974
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
4975
+ const r = Math.floor(rng() * 16);
4976
+ const v = c === "x" ? r : r & 3 | 8;
4977
+ return v.toString(16);
4978
+ });
4979
+ }
4980
+ function generateTrackingId(rng) {
4981
+ const uuid = generateUuid(rng).replace(/-/g, "");
4982
+ const trackingId = uuid.slice(0, 6).toUpperCase();
4983
+ return trackingId;
4984
+ }
4985
+ var eventQueryDataGenerator = (overrides = {}, seed = 1) => {
4986
+ const rng = createPseudoRandomNumberGenerator(seed);
4987
+ const createdAt = getRandomDatetime(
4988
+ rng,
4989
+ /* @__PURE__ */ new Date("2024-01-01"),
4990
+ /* @__PURE__ */ new Date("2024-12-31")
4991
+ );
4992
+ return {
4993
+ id: overrides.id ?? generateUuid(rng),
4994
+ type: overrides.type ?? "TENNIS_CLUB_MEMBERSHIP",
4995
+ status: overrides.status ?? pickRandom(rng, eventStatuses),
4996
+ createdAt: overrides.createdAt ?? createdAt,
4997
+ createdBy: overrides.createdBy ?? generateUuid(rng),
4998
+ createdAtLocation: overrides.createdAtLocation ?? generateUuid(rng),
4999
+ updatedAtLocation: overrides.updatedAtLocation ?? generateUuid(rng),
5000
+ updatedAt: overrides.updatedAt ?? (0, import_addDays.default)(new Date(createdAt), 1).toISOString(),
5001
+ assignedTo: overrides.assignedTo ?? null,
5002
+ updatedBy: overrides.updatedBy ?? generateUuid(rng),
5003
+ updatedByUserRole: overrides.updatedByUserRole ?? "FIELD_AGENT",
5004
+ flags: [],
5005
+ legalStatuses: overrides.legalStatuses ?? {},
5006
+ declaration: overrides.declaration ?? generateRandomApplicant(rng),
5007
+ trackingId: overrides.trackingId ?? generateTrackingId(rng)
5008
+ };
5009
+ };
4345
5010
  var generateTranslationConfig = (message) => ({
4346
5011
  defaultMessage: message,
4347
5012
  description: "Description for ${message}",
@@ -4384,6 +5049,7 @@ function isFieldConfigDefaultValue(value) {
4384
5049
  var import_lodash3 = require("lodash");
4385
5050
 
4386
5051
  // ../commons/src/scopes.ts
5052
+ var import_zod25 = require("zod");
4387
5053
  var SCOPES = {
4388
5054
  // TODO v1.8 legacy scopes
4389
5055
  NATLSYSADMIN: "natlsysadmin",
@@ -4407,6 +5073,8 @@ var SCOPES = {
4407
5073
  */
4408
5074
  RECORD_DECLARE: "record.declare-birth",
4409
5075
  // declare
5076
+ RECORD_IMPORT: "record.import",
5077
+ // declare
4410
5078
  RECORD_DECLARE_BIRTH: "record.declare-birth",
4411
5079
  RECORD_DECLARE_BIRTH_MY_JURISDICTION: "record.declare-birth:my-jurisdiction",
4412
5080
  RECORD_DECLARE_DEATH: "record.declare-death",
@@ -4494,12 +5162,119 @@ var SCOPES = {
4494
5162
  // data seeding
4495
5163
  USER_DATA_SEEDING: "user.data-seeding"
4496
5164
  };
5165
+ var LiteralScopes = import_zod25.z.union([
5166
+ import_zod25.z.literal(SCOPES.NATLSYSADMIN),
5167
+ import_zod25.z.literal(SCOPES.BYPASSRATELIMIT),
5168
+ import_zod25.z.literal(SCOPES.DECLARE),
5169
+ import_zod25.z.literal(SCOPES.REGISTER),
5170
+ import_zod25.z.literal(SCOPES.VALIDATE),
5171
+ import_zod25.z.literal(SCOPES.DEMO),
5172
+ import_zod25.z.literal(SCOPES.CERTIFY),
5173
+ import_zod25.z.literal(SCOPES.PERFORMANCE),
5174
+ import_zod25.z.literal(SCOPES.SYSADMIN),
5175
+ import_zod25.z.literal(SCOPES.TEAMS),
5176
+ import_zod25.z.literal(SCOPES.CONFIG),
5177
+ import_zod25.z.literal(SCOPES.WEBHOOK),
5178
+ import_zod25.z.literal(SCOPES.NATIONALID),
5179
+ import_zod25.z.literal(SCOPES.NOTIFICATION_API),
5180
+ import_zod25.z.literal(SCOPES.RECORDSEARCH),
5181
+ import_zod25.z.literal(SCOPES.RECORD_IMPORT),
5182
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_BIRTH),
5183
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_BIRTH_MY_JURISDICTION),
5184
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_DEATH),
5185
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_DEATH_MY_JURISDICTION),
5186
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE),
5187
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE_MY_JURISDICTION),
5188
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_INCOMPLETE),
5189
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_FOR_REVIEW),
5190
+ import_zod25.z.literal(SCOPES.RECORD_UNASSIGN_OTHERS),
5191
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_FOR_APPROVAL),
5192
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_FOR_UPDATES),
5193
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_EDIT),
5194
+ import_zod25.z.literal(SCOPES.RECORD_REVIEW_DUPLICATES),
5195
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_ARCHIVE),
5196
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_REINSTATE),
5197
+ import_zod25.z.literal(SCOPES.RECORD_REGISTER),
5198
+ import_zod25.z.literal(SCOPES.RECORD_EXPORT_RECORDS),
5199
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_PRINT),
5200
+ import_zod25.z.literal(SCOPES.RECORD_PRINT_RECORDS_SUPPORTING_DOCUMENTS),
5201
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_PRINT),
5202
+ import_zod25.z.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
5203
+ import_zod25.z.literal(SCOPES.RECORD_PRINT_CERTIFIED_COPIES),
5204
+ import_zod25.z.literal(SCOPES.RECORD_BULK_PRINT_CERTIFIED_COPIES),
5205
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES),
5206
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION),
5207
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_CORRECT),
5208
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_REVOCATION),
5209
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REVOKE),
5210
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_REINSTATEMENT),
5211
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REINSTATE),
5212
+ import_zod25.z.literal(SCOPES.RECORD_CONFIRM_REGISTRATION),
5213
+ import_zod25.z.literal(SCOPES.RECORD_REJECT_REGISTRATION),
5214
+ import_zod25.z.literal(SCOPES.SEARCH_BIRTH_MY_JURISDICTION),
5215
+ import_zod25.z.literal(SCOPES.SEARCH_BIRTH),
5216
+ import_zod25.z.literal(SCOPES.SEARCH_DEATH_MY_JURISDICTION),
5217
+ import_zod25.z.literal(SCOPES.SEARCH_DEATH),
5218
+ import_zod25.z.literal(SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION),
5219
+ import_zod25.z.literal(SCOPES.SEARCH_MARRIAGE),
5220
+ import_zod25.z.literal(SCOPES.RECORD_READ),
5221
+ import_zod25.z.literal(SCOPES.RECORD_READ_AUDIT),
5222
+ import_zod25.z.literal(SCOPES.RECORD_READ_COMMENTS),
5223
+ import_zod25.z.literal(SCOPES.RECORD_CREATE_COMMENTS),
5224
+ import_zod25.z.literal(SCOPES.PROFILE_UPDATE),
5225
+ import_zod25.z.literal(SCOPES.PROFILE_ELECTRONIC_SIGNATURE),
5226
+ import_zod25.z.literal(SCOPES.PERFORMANCE_READ),
5227
+ import_zod25.z.literal(SCOPES.PERFORMANCE_READ_DASHBOARDS),
5228
+ import_zod25.z.literal(SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS),
5229
+ import_zod25.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS),
5230
+ import_zod25.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE),
5231
+ import_zod25.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_JURISDICTION),
5232
+ import_zod25.z.literal(SCOPES.USER_READ),
5233
+ import_zod25.z.literal(SCOPES.USER_READ_MY_OFFICE),
5234
+ import_zod25.z.literal(SCOPES.USER_READ_MY_JURISDICTION),
5235
+ import_zod25.z.literal(SCOPES.USER_READ_ONLY_MY_AUDIT),
5236
+ import_zod25.z.literal(SCOPES.USER_CREATE),
5237
+ import_zod25.z.literal(SCOPES.USER_CREATE_MY_JURISDICTION),
5238
+ import_zod25.z.literal(SCOPES.USER_UPDATE),
5239
+ import_zod25.z.literal(SCOPES.USER_UPDATE_MY_JURISDICTION),
5240
+ import_zod25.z.literal(SCOPES.CONFIG_UPDATE_ALL),
5241
+ import_zod25.z.literal(SCOPES.USER_DATA_SEEDING)
5242
+ ]);
5243
+ var rawConfigurableScopeRegex = /^([a-zA-Z\.]+)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
5244
+ var rawConfigurableScope = import_zod25.z.string().regex(rawConfigurableScopeRegex);
5245
+ var CreateUserScope = import_zod25.z.object({
5246
+ type: import_zod25.z.literal("user.create"),
5247
+ options: import_zod25.z.object({
5248
+ role: import_zod25.z.array(import_zod25.z.string())
5249
+ })
5250
+ });
5251
+ var EditUserScope = import_zod25.z.object({
5252
+ type: import_zod25.z.literal("user.edit"),
5253
+ options: import_zod25.z.object({
5254
+ role: import_zod25.z.array(import_zod25.z.string())
5255
+ })
5256
+ });
5257
+ var WorkqueueScope = import_zod25.z.object({
5258
+ type: import_zod25.z.literal("workqueue"),
5259
+ options: import_zod25.z.object({
5260
+ id: import_zod25.z.array(import_zod25.z.string())
5261
+ })
5262
+ });
5263
+ var NotifyRecordScope = import_zod25.z.object({
5264
+ type: import_zod25.z.literal("record.notify"),
5265
+ options: import_zod25.z.object({
5266
+ event: import_zod25.z.array(import_zod25.z.string())
5267
+ })
5268
+ });
5269
+ var ConfigurableScopes = import_zod25.z.discriminatedUnion("type", [
5270
+ CreateUserScope,
5271
+ EditUserScope,
5272
+ WorkqueueScope,
5273
+ NotifyRecordScope
5274
+ ]);
4497
5275
  var scopes = Object.values(SCOPES);
4498
5276
 
4499
5277
  // ../commons/src/events/scopes.ts
4500
- function hasAnyOfScopes(a, b) {
4501
- return (0, import_lodash3.intersection)(a, b).length > 0;
4502
- }
4503
5278
  var CONFIG_GET_ALLOWED_SCOPES = [
4504
5279
  SCOPES.RECORD_DECLARE,
4505
5280
  SCOPES.RECORD_READ,
@@ -4510,6 +5285,14 @@ var CONFIG_GET_ALLOWED_SCOPES = [
4510
5285
  SCOPES.CONFIG,
4511
5286
  SCOPES.CONFIG_UPDATE_ALL
4512
5287
  ];
5288
+ var CONFIG_SEARCH_ALLOWED_SCOPES = [
5289
+ SCOPES.SEARCH_BIRTH,
5290
+ SCOPES.SEARCH_DEATH,
5291
+ SCOPES.SEARCH_MARRIAGE,
5292
+ SCOPES.SEARCH_BIRTH_MY_JURISDICTION,
5293
+ SCOPES.SEARCH_DEATH_MY_JURISDICTION,
5294
+ SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION
5295
+ ];
4513
5296
  var ACTION_ALLOWED_SCOPES = {
4514
5297
  [ActionType.READ]: [
4515
5298
  SCOPES.RECORD_DECLARE,
@@ -4549,6 +5332,28 @@ var ACTION_ALLOWED_SCOPES = {
4549
5332
  [ActionType.UNASSIGN]: null,
4550
5333
  [ActionType.DETECT_DUPLICATE]: []
4551
5334
  };
5335
+ var ACTION_ALLOWED_CONFIGURABLE_SCOPES = {
5336
+ [ActionType.READ]: [],
5337
+ [ActionType.CREATE]: ["record.notify"],
5338
+ [ActionType.NOTIFY]: ["record.notify"],
5339
+ [ActionType.DECLARE]: [],
5340
+ [ActionType.DELETE]: [],
5341
+ [ActionType.VALIDATE]: [],
5342
+ [ActionType.REGISTER]: [],
5343
+ [ActionType.PRINT_CERTIFICATE]: [],
5344
+ [ActionType.REQUEST_CORRECTION]: [],
5345
+ [ActionType.REJECT_CORRECTION]: [],
5346
+ [ActionType.APPROVE_CORRECTION]: [],
5347
+ [ActionType.MARKED_AS_DUPLICATE]: [],
5348
+ [ActionType.ARCHIVE]: [],
5349
+ [ActionType.REJECT]: [],
5350
+ [ActionType.ASSIGN]: [],
5351
+ [ActionType.UNASSIGN]: [],
5352
+ [ActionType.DETECT_DUPLICATE]: []
5353
+ };
5354
+ function hasAnyOfScopes(a, b) {
5355
+ return (0, import_lodash3.intersection)(a, b).length > 0;
5356
+ }
4552
5357
  function filterUnallowedActions(actions, userScopes) {
4553
5358
  const allowedActions = actions.filter((action) => {
4554
5359
  const requiredScopes = ACTION_ALLOWED_SCOPES[action];