@opencrvs/toolkit 1.8.0-rc.fb2e700 → 1.8.0-rc.fb4793a

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