@opencrvs/toolkit 1.8.0-rc.f876361 → 1.8.0-rc.f8a9481

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.
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/events/index.ts
31
31
  var events_exports = {};
32
32
  __export(events_exports, {
33
+ ACTION_ALLOWED_SCOPES: () => ACTION_ALLOWED_SCOPES,
33
34
  Action: () => Action,
34
35
  ActionBase: () => ActionBase,
35
36
  ActionConditional: () => ActionConditional,
@@ -49,8 +50,10 @@ __export(events_exports, {
49
50
  AdvancedSearchConfig: () => AdvancedSearchConfig,
50
51
  ApproveCorrectionActionInput: () => ApproveCorrectionActionInput,
51
52
  ArchiveActionInput: () => ArchiveActionInput,
53
+ AssignActionInput: () => AssignActionInput,
52
54
  AsyncRejectActionDocument: () => AsyncRejectActionDocument,
53
55
  BaseActionInput: () => BaseActionInput,
56
+ CONFIG_GET_ALLOWED_SCOPES: () => CONFIG_GET_ALLOWED_SCOPES,
54
57
  CertificateConfig: () => CertificateConfig,
55
58
  CertificateTemplateConfig: () => CertificateTemplateConfig,
56
59
  CheckboxFieldValue: () => CheckboxFieldValue,
@@ -68,6 +71,8 @@ __export(events_exports, {
68
71
  DeclarationUpdateActions: () => DeclarationUpdateActions,
69
72
  DeclareActionInput: () => DeclareActionInput,
70
73
  DeduplicationConfig: () => DeduplicationConfig,
74
+ DeleteActionInput: () => DeleteActionInput,
75
+ DisplayOnReviewConditional: () => DisplayOnReviewConditional,
71
76
  Draft: () => Draft,
72
77
  DraftInput: () => DraftInput,
73
78
  EmailField: () => EmailField,
@@ -81,6 +86,7 @@ __export(events_exports, {
81
86
  EventSearchIndex: () => EventSearchIndex,
82
87
  EventStatus: () => EventStatus,
83
88
  EventStatuses: () => EventStatuses,
89
+ FieldConditional: () => FieldConditional,
84
90
  FieldConfig: () => FieldConfig,
85
91
  FieldType: () => FieldType,
86
92
  FieldUpdateValue: () => FieldUpdateValue,
@@ -100,7 +106,6 @@ __export(events_exports, {
100
106
  NotifyActionInput: () => NotifyActionInput,
101
107
  NumberFieldValue: () => NumberFieldValue,
102
108
  PageConfig: () => PageConfig,
103
- PageConfigBase: () => PageConfigBase,
104
109
  PageTypes: () => PageTypes,
105
110
  PrintCertificateActionInput: () => PrintCertificateActionInput,
106
111
  ReadActionInput: () => ReadActionInput,
@@ -117,6 +122,7 @@ __export(events_exports, {
117
122
  SummaryConfig: () => SummaryConfig,
118
123
  TextValue: () => TextValue,
119
124
  TranslationConfig: () => TranslationConfig,
125
+ UnassignActionInput: () => UnassignActionInput,
120
126
  UrbanAddressUpdateValue: () => UrbanAddressUpdateValue,
121
127
  UrbanAddressValue: () => UrbanAddressValue,
122
128
  ValidateActionInput: () => ValidateActionInput,
@@ -127,6 +133,7 @@ __export(events_exports, {
127
133
  and: () => and,
128
134
  annotationActions: () => annotationActions,
129
135
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
136
+ areConditionsMet: () => areConditionsMet,
130
137
  compositeFieldTypes: () => compositeFieldTypes,
131
138
  createEmptyDraft: () => createEmptyDraft,
132
139
  createValidationSchema: () => createValidationSchema,
@@ -136,8 +143,10 @@ __export(events_exports, {
136
143
  defineConditional: () => defineConditional,
137
144
  defineConfig: () => defineConfig,
138
145
  defineDeclarationForm: () => defineDeclarationForm,
146
+ defineFormConditional: () => defineFormConditional,
139
147
  defineFormPage: () => defineFormPage,
140
148
  definePage: () => definePage,
149
+ defineWorkqueue: () => defineWorkqueue,
141
150
  errorMessages: () => errorMessages,
142
151
  event: () => event,
143
152
  eventMetadataLabelMap: () => eventMetadataLabelMap,
@@ -146,12 +155,14 @@ __export(events_exports, {
146
155
  eventStatuses: () => eventStatuses,
147
156
  field: () => field,
148
157
  fieldTypes: () => fieldTypes,
158
+ filterUnallowedActions: () => filterUnallowedActions,
149
159
  findActiveDrafts: () => findActiveDrafts,
150
160
  findAllFields: () => findAllFields,
161
+ findLastAssignmentAction: () => findLastAssignmentAction,
151
162
  findRecordActionPages: () => findRecordActionPages,
163
+ generateActionAnnotationInput: () => generateActionAnnotationInput,
164
+ generateActionDeclarationInput: () => generateActionDeclarationInput,
152
165
  generateActionDocument: () => generateActionDocument,
153
- generateActionInput: () => generateActionInput,
154
- generateActionMetadataInput: () => generateActionMetadataInput,
155
166
  generateEventDocument: () => generateEventDocument,
156
167
  generateEventDraftDocument: () => generateEventDraftDocument,
157
168
  generateTransactionId: () => generateTransactionId,
@@ -162,17 +173,19 @@ __export(events_exports, {
162
173
  getActionReview: () => getActionReview,
163
174
  getActionReviewFields: () => getActionReviewFields,
164
175
  getAllAnnotationFields: () => getAllAnnotationFields,
176
+ getAnnotationFromDrafts: () => getAnnotationFromDrafts,
177
+ getAssignedUserFromActions: () => getAssignedUserFromActions,
165
178
  getCurrentEventState: () => getCurrentEventState,
166
179
  getCurrentEventStateWithDrafts: () => getCurrentEventStateWithDrafts,
167
180
  getDeclaration: () => getDeclaration,
168
181
  getDeclarationFields: () => getDeclarationFields,
169
182
  getDeclarationPages: () => getDeclarationPages,
170
- getFieldValidationErrors: () => getFieldValidationErrors,
171
- getVisiblePagesFormFields: () => getVisiblePagesFormFields,
183
+ hasAnyOfScopes: () => hasAnyOfScopes,
172
184
  isAddressFieldType: () => isAddressFieldType,
173
185
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
174
186
  isBulletListFieldType: () => isBulletListFieldType,
175
187
  isCheckboxFieldType: () => isCheckboxFieldType,
188
+ isConditionMet: () => isConditionMet,
176
189
  isCountryFieldType: () => isCountryFieldType,
177
190
  isDataFieldType: () => isDataFieldType,
178
191
  isDateFieldType: () => isDateFieldType,
@@ -180,6 +193,7 @@ __export(events_exports, {
180
193
  isEmailFieldType: () => isEmailFieldType,
181
194
  isFacilityFieldType: () => isFacilityFieldType,
182
195
  isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
196
+ isFieldDisplayedOnReview: () => isFieldDisplayedOnReview,
183
197
  isFieldEnabled: () => isFieldEnabled,
184
198
  isFieldValue: () => isFieldValue,
185
199
  isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
@@ -200,16 +214,20 @@ __export(events_exports, {
200
214
  isTextFieldType: () => isTextFieldType,
201
215
  isUndeclaredDraft: () => isUndeclaredDraft,
202
216
  isVerificationPage: () => isVerificationPage,
217
+ isWriteAction: () => isWriteAction,
203
218
  mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
204
219
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
205
220
  mapFieldTypeToZod: () => mapFieldTypeToZod,
221
+ never: () => never,
206
222
  not: () => not,
223
+ omitHiddenFields: () => omitHiddenFields,
224
+ omitHiddenPaginatedFields: () => omitHiddenPaginatedFields,
207
225
  or: () => or,
208
- stripHiddenFields: () => stripHiddenFields,
226
+ runFieldValidations: () => runFieldValidations,
209
227
  user: () => user,
210
228
  validate: () => validate,
211
229
  validateFieldInput: () => validateFieldInput,
212
- validateWorkqueueConfig: () => validateWorkqueueConfig
230
+ writeActions: () => writeActions
213
231
  });
214
232
  module.exports = __toCommonJS(events_exports);
215
233
 
@@ -218,29 +236,52 @@ var import_zod9 = require("zod");
218
236
 
219
237
  // ../commons/src/events/Conditional.ts
220
238
  var import_zod = require("zod");
221
- function Conditional() {
222
- return import_zod.z.custom((val) => typeof val === "object" && val !== null);
223
- }
239
+ var import_zod_openapi = require("zod-openapi");
240
+ (0, import_zod_openapi.extendZodWithOpenApi)(import_zod.z);
241
+ var Conditional = import_zod.z.custom((val) => typeof val === "object" && val !== null).openapi({
242
+ description: "JSON schema conditional configuration",
243
+ ref: "Conditional"
244
+ });
224
245
  var ConditionalType = {
225
- /** When 'SHOW' conditional is defined, the action is shown to the user only if the condition is met */
226
246
  SHOW: "SHOW",
227
- /** If 'ENABLE' conditional is defined, the action is enabled only if the condition is met */
228
- ENABLE: "ENABLE"
247
+ ENABLE: "ENABLE",
248
+ DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
229
249
  };
230
250
  var ShowConditional = import_zod.z.object({
231
251
  type: import_zod.z.literal(ConditionalType.SHOW),
232
- conditional: Conditional()
233
- });
252
+ conditional: Conditional
253
+ }).describe(
254
+ "If 'SHOW' conditional is defined, the component is shown to the user only if the condition is met"
255
+ );
234
256
  var EnableConditional = import_zod.z.object({
235
257
  type: import_zod.z.literal(ConditionalType.ENABLE),
236
- conditional: Conditional()
237
- });
258
+ conditional: Conditional
259
+ }).describe(
260
+ "If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
261
+ );
238
262
  var ActionConditional = import_zod.z.discriminatedUnion("type", [
239
263
  // Action can be shown / hidden
240
264
  ShowConditional,
241
265
  // Action can be shown to the user in the list but as disabled
242
266
  EnableConditional
243
267
  ]);
268
+ var DisplayOnReviewConditional = import_zod.z.object({
269
+ type: import_zod.z.literal(ConditionalType.DISPLAY_ON_REVIEW),
270
+ conditional: Conditional
271
+ }).describe(
272
+ "If 'DISPLAY_ON_REVIEW' conditional is defined, the component is shown on the review page only if both the 'DISPLAY_ON_REVIEW' and 'SHOW' conditions are met. This should only be used for fields within declaration forms, as they are the only ones with review pages."
273
+ );
274
+ var FieldConditional = import_zod.z.discriminatedUnion("type", [
275
+ // Field input can be shown / hidden
276
+ ShowConditional,
277
+ // Field input can be shown to the user but as disabled
278
+ EnableConditional,
279
+ // Field output can be shown / hidden on the review page
280
+ DisplayOnReviewConditional
281
+ ]).openapi({
282
+ description: "Field conditional configuration",
283
+ ref: "FieldConditional"
284
+ });
244
285
 
245
286
  // ../commons/src/events/PageConfig.ts
246
287
  var import_zod6 = require("zod");
@@ -250,6 +291,8 @@ var import_zod5 = require("zod");
250
291
 
251
292
  // ../commons/src/events/TranslationConfig.ts
252
293
  var import_zod2 = require("zod");
294
+ var import_zod_openapi2 = require("zod-openapi");
295
+ (0, import_zod_openapi2.extendZodWithOpenApi)(import_zod2.z);
253
296
  var TranslationConfig = import_zod2.z.object({
254
297
  id: import_zod2.z.string().describe(
255
298
  "The identifier of the translation referred in translation CSV files"
@@ -258,8 +301,14 @@ var TranslationConfig = import_zod2.z.object({
258
301
  description: import_zod2.z.string().describe(
259
302
  "Describe the translation for a translator to be able to identify it."
260
303
  )
304
+ }).openapi({
305
+ description: "Translation configuration",
306
+ ref: "TranslationConfig"
261
307
  });
262
308
 
309
+ // ../commons/src/events/FieldConfig.ts
310
+ var import_zod_openapi3 = require("zod-openapi");
311
+
263
312
  // ../commons/src/events/FieldType.ts
264
313
  var FieldType = {
265
314
  ADDRESS: "ADDRESS",
@@ -410,6 +459,7 @@ var FieldUpdateValue = import_zod4.z.union([
410
459
  ]);
411
460
 
412
461
  // ../commons/src/events/FieldConfig.ts
462
+ (0, import_zod_openapi3.extendZodWithOpenApi)(import_zod5.z);
413
463
  var FieldId = import_zod5.z.string();
414
464
  var DependencyExpression = import_zod5.z.object({
415
465
  dependsOn: import_zod5.z.array(FieldId).default([]),
@@ -428,14 +478,14 @@ var BaseField = import_zod5.z.object({
428
478
  ]),
429
479
  DependencyExpression
430
480
  ]).optional(),
431
- conditionals: import_zod5.z.array(ActionConditional).default([]).optional(),
481
+ conditionals: import_zod5.z.array(FieldConditional).default([]).optional(),
432
482
  required: import_zod5.z.boolean().default(false).optional(),
433
483
  disabled: import_zod5.z.boolean().default(false).optional(),
434
484
  hidden: import_zod5.z.boolean().default(false).optional(),
435
485
  placeholder: TranslationConfig.optional(),
436
486
  validation: import_zod5.z.array(
437
487
  import_zod5.z.object({
438
- validator: Conditional(),
488
+ validator: Conditional,
439
489
  message: TranslationConfig
440
490
  })
441
491
  ).default([]).optional(),
@@ -545,7 +595,8 @@ var File = BaseField.extend({
545
595
  width: import_zod5.z.enum(["full", "auto"]).optional().describe(
546
596
  "Whether the file upload button should take the full width of the container or not"
547
597
  )
548
- }).optional()
598
+ }).optional(),
599
+ fileName: TranslationConfig.optional()
549
600
  }).default({
550
601
  maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
551
602
  })
@@ -632,7 +683,7 @@ var Address = BaseField.extend({
632
683
  var DataEntry = import_zod5.z.union([
633
684
  import_zod5.z.object({
634
685
  label: TranslationConfig,
635
- value: import_zod5.z.string()
686
+ value: TranslationConfig.or(import_zod5.z.string())
636
687
  }),
637
688
  import_zod5.z.object({
638
689
  fieldId: import_zod5.z.string()
@@ -668,20 +719,28 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
668
719
  EmailField,
669
720
  FileUploadWithOptions,
670
721
  DataField
671
- ]);
722
+ ]).openapi({
723
+ description: "Form field configuration",
724
+ ref: "FieldConfig"
725
+ });
672
726
 
673
727
  // ../commons/src/events/PageConfig.ts
728
+ var import_zod_openapi4 = require("zod-openapi");
729
+ (0, import_zod_openapi4.extendZodWithOpenApi)(import_zod6.z);
674
730
  var PageTypes = import_zod6.z.enum(["FORM", "VERIFICATION"]);
675
731
  var PageConfigBase = import_zod6.z.object({
676
732
  id: import_zod6.z.string().describe("Unique identifier for the page"),
677
733
  title: TranslationConfig.describe("Header title of the page"),
678
734
  fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page"),
679
- conditional: Conditional().optional().describe(
735
+ conditional: Conditional.optional().describe(
680
736
  "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
681
737
  )
682
738
  });
683
739
  var FormPageConfig = PageConfigBase.extend({
684
740
  type: import_zod6.z.literal(PageTypes.enum.FORM).default(PageTypes.enum.FORM)
741
+ }).openapi({
742
+ description: "Form page configuration",
743
+ ref: "FormPageConfig"
685
744
  });
686
745
  var VerificationActionConfig = import_zod6.z.object({
687
746
  verify: import_zod6.z.object({ label: TranslationConfig }),
@@ -692,7 +751,10 @@ var VerificationActionConfig = import_zod6.z.object({
692
751
  body: TranslationConfig
693
752
  })
694
753
  })
695
- }).describe("Actions available on the verification page");
754
+ }).describe("Actions available on the verification page").openapi({
755
+ description: "Verification action configuration",
756
+ ref: "VerificationActionConfig"
757
+ });
696
758
  var VerificationPageConfig = FormPageConfig.extend({
697
759
  type: import_zod6.z.literal(PageTypes.enum.VERIFICATION),
698
760
  actions: VerificationActionConfig
@@ -772,6 +834,12 @@ var DeclarationUpdateActions = ActionTypes.extract(
772
834
  declarationUpdateActionValues
773
835
  );
774
836
  var annotationActions = ActionTypes.exclude(declarationActionValues);
837
+ var writeActions = ActionTypes.exclude([
838
+ ActionType.CREATE,
839
+ ActionType.READ,
840
+ ActionType.ASSIGN,
841
+ ActionType.UNASSIGN
842
+ ]);
775
843
 
776
844
  // ../commons/src/events/FormConfig.ts
777
845
  var import_zod8 = require("zod");
@@ -786,6 +854,8 @@ var ActionFormConfig = import_zod8.z.object({
786
854
  var FormConfig = import_zod8.z.union([DeclarationFormConfig, ActionFormConfig]);
787
855
 
788
856
  // ../commons/src/events/ActionConfig.ts
857
+ var import_zod_openapi5 = require("zod-openapi");
858
+ (0, import_zod_openapi5.extendZodWithOpenApi)(import_zod9.z);
789
859
  var ActionConditional2 = import_zod9.z.discriminatedUnion("type", [
790
860
  /** If conditional is defined, the action is shown to the user only if the condition is met */
791
861
  ShowConditional,
@@ -863,18 +933,24 @@ var ApproveCorrectionConfig = ActionConfigBase.merge(
863
933
  })
864
934
  );
865
935
  var ActionConfig = import_zod9.z.discriminatedUnion("type", [
866
- DeclareConfig,
867
- ValidateConfig,
868
- RejectDeclarationConfig,
869
- MarkedAsDuplicateConfig,
870
- ArchiveConfig,
871
- RegisterConfig,
872
- DeleteConfig,
873
- PrintCertificateActionConfig,
874
- RequestCorrectionConfig,
875
- RejectCorrectionConfig,
876
- ApproveCorrectionConfig
877
- ]);
936
+ /*
937
+ * OpenAPI references are defined here so our generated OpenAPI spec knows to reuse the models
938
+ * and treat them as "models" instead of duplicating the data structure in each endpoint.
939
+ */
940
+ DeclareConfig.openapi({ ref: "DeclareActionConfig" }),
941
+ ValidateConfig.openapi({ ref: "ValidateActionConfig" }),
942
+ RejectDeclarationConfig.openapi({ ref: "RejectDeclarationActionConfig" }),
943
+ MarkedAsDuplicateConfig.openapi({ ref: "MarkedAsDuplicateActionConfig" }),
944
+ ArchiveConfig.openapi({ ref: "ArchiveActionConfig" }),
945
+ RegisterConfig.openapi({ ref: "RegisterActionConfig" }),
946
+ DeleteConfig.openapi({ ref: "DeleteActionConfig" }),
947
+ PrintCertificateActionConfig.openapi({
948
+ ref: "PrintCertificateActionConfig"
949
+ }),
950
+ RequestCorrectionConfig.openapi({ ref: "RequestCorrectionActionConfig" }),
951
+ RejectCorrectionConfig.openapi({ ref: "RejectCorrectionActionConfig" }),
952
+ ApproveCorrectionConfig.openapi({ ref: "ApproveCorrectionActionConfig" })
953
+ ]).openapi({ ref: "ActionConfig" });
878
954
  var DeclarationActionConfig = import_zod9.z.discriminatedUnion("type", [
879
955
  DeclareConfig,
880
956
  ValidateConfig,
@@ -918,10 +994,12 @@ var LanguageConfig = import_zod11.z.object({
918
994
  });
919
995
 
920
996
  // ../commons/src/events/EventConfig.ts
921
- var import_zod20 = require("zod");
997
+ var import_zod16 = require("zod");
922
998
 
923
999
  // ../commons/src/events/DeduplicationConfig.ts
924
1000
  var import_zod12 = require("zod");
1001
+ var import_zod_openapi6 = require("zod-openapi");
1002
+ (0, import_zod_openapi6.extendZodWithOpenApi)(import_zod12.z);
925
1003
  var FieldReference = import_zod12.z.string();
926
1004
  var Matcher = import_zod12.z.object({
927
1005
  fieldId: import_zod12.z.string(),
@@ -965,10 +1043,12 @@ var DateDistanceMatcher = Matcher.extend({
965
1043
  });
966
1044
  var And = import_zod12.z.object({
967
1045
  type: import_zod12.z.literal("and"),
1046
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
968
1047
  clauses: import_zod12.z.lazy(() => Clause.array())
969
1048
  });
970
1049
  var Or = import_zod12.z.object({
971
1050
  type: import_zod12.z.literal("or"),
1051
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
972
1052
  clauses: import_zod12.z.lazy(() => Clause.array())
973
1053
  });
974
1054
  var Clause = import_zod12.z.lazy(
@@ -980,7 +1060,9 @@ var Clause = import_zod12.z.lazy(
980
1060
  DateRangeMatcher,
981
1061
  DateDistanceMatcher
982
1062
  ])
983
- );
1063
+ ).openapi({
1064
+ ref: "Clause"
1065
+ });
984
1066
  var DeduplicationConfig = import_zod12.z.object({
985
1067
  id: import_zod12.z.string(),
986
1068
  label: TranslationConfig,
@@ -989,14 +1071,21 @@ var DeduplicationConfig = import_zod12.z.object({
989
1071
 
990
1072
  // ../commons/src/events/SummaryConfig.ts
991
1073
  var import_zod13 = require("zod");
992
- var Field = import_zod13.z.object({
1074
+ var BaseField2 = import_zod13.z.object({
1075
+ emptyValueMessage: TranslationConfig.optional(),
1076
+ conditionals: import_zod13.z.array(ShowConditional).default([]).optional()
1077
+ });
1078
+ var ReferenceField = BaseField2.extend({
1079
+ fieldId: import_zod13.z.string()
1080
+ }).describe("Field directly referencing event data with field id");
1081
+ var Field = BaseField2.extend({
993
1082
  id: import_zod13.z.string().describe("Id of summary field"),
994
1083
  value: TranslationConfig.describe(
995
1084
  "Summary field value. Can utilise values defined in configuration and EventMetadata"
996
1085
  ),
997
1086
  label: TranslationConfig,
998
1087
  emptyValueMessage: TranslationConfig.optional()
999
- });
1088
+ }).describe("Custom configured field");
1000
1089
  var Title = import_zod13.z.object({
1001
1090
  id: import_zod13.z.string(),
1002
1091
  label: TranslationConfig.describe("Title content"),
@@ -1004,116 +1093,18 @@ var Title = import_zod13.z.object({
1004
1093
  });
1005
1094
  var SummaryConfig = import_zod13.z.object({
1006
1095
  title: Title.describe("Title of summary view."),
1007
- fields: import_zod13.z.array(Field).describe("Fields rendered in summary view.")
1096
+ fields: import_zod13.z.array(import_zod13.z.union([Field, ReferenceField])).describe("Fields rendered in summary view.")
1008
1097
  }).describe("Configuration for summary in event.");
1009
1098
 
1010
- // ../commons/src/events/WorkqueueConfig.ts
1011
- var import_zod15 = require("zod");
1012
-
1013
- // ../commons/src/events/EventMetadata.ts
1014
- var import_zod14 = require("zod");
1015
- var EventStatus = {
1016
- CREATED: "CREATED",
1017
- NOTIFIED: "NOTIFIED",
1018
- DECLARED: "DECLARED",
1019
- VALIDATED: "VALIDATED",
1020
- REGISTERED: "REGISTERED",
1021
- CERTIFIED: "CERTIFIED",
1022
- REJECTED: "REJECTED",
1023
- ARCHIVED: "ARCHIVED"
1024
- };
1025
- var eventStatuses = Object.values(EventStatus);
1026
- var EventStatuses = import_zod14.z.nativeEnum(EventStatus);
1027
- var EventMetadata = import_zod14.z.object({
1028
- id: import_zod14.z.string(),
1029
- type: import_zod14.z.string(),
1030
- status: EventStatuses,
1031
- createdAt: import_zod14.z.string().datetime(),
1032
- createdBy: import_zod14.z.string(),
1033
- createdAtLocation: import_zod14.z.string(),
1034
- modifiedAt: import_zod14.z.string().datetime(),
1035
- assignedTo: import_zod14.z.string().nullish(),
1036
- updatedBy: import_zod14.z.string(),
1037
- trackingId: import_zod14.z.string(),
1038
- registrationNumber: import_zod14.z.string().nullish()
1039
- });
1040
- var eventMetadataLabelMap = {
1041
- "event.assignedTo": {
1042
- id: "event.assignedTo.label",
1043
- defaultMessage: "Assigned To",
1044
- description: "Assigned To"
1045
- },
1046
- "event.createdAt": {
1047
- id: "event.createdAt.label",
1048
- defaultMessage: "Created",
1049
- description: "Created At"
1050
- },
1051
- "event.createdAtLocation": {
1052
- id: "event.createdAtLocation.label",
1053
- defaultMessage: "Location",
1054
- description: "Created At Location"
1055
- },
1056
- "event.createdBy": {
1057
- id: "event.createdBy.label",
1058
- defaultMessage: "Created By",
1059
- description: "Created By"
1060
- },
1061
- "event.id": {
1062
- id: "event.id.label",
1063
- defaultMessage: "ID",
1064
- description: "ID"
1065
- },
1066
- "event.modifiedAt": {
1067
- id: "event.modifiedAt.label",
1068
- defaultMessage: "Updated",
1069
- description: "Modified At"
1070
- },
1071
- "event.status": {
1072
- id: "event.status.label",
1073
- defaultMessage: "Status",
1074
- description: "Status"
1075
- },
1076
- "event.type": {
1077
- id: "event.type.label",
1078
- defaultMessage: "Type",
1079
- description: "Type"
1080
- },
1081
- "event.updatedBy": {
1082
- id: "event.updatedBy.label",
1083
- defaultMessage: "Updated By",
1084
- description: "Updated By"
1085
- },
1086
- "event.trackingId": {
1087
- id: "event.trackingId.label",
1088
- defaultMessage: "Tracking ID",
1089
- description: "Tracking ID"
1090
- },
1091
- "event.registrationNumber": {
1092
- id: "event.registrationNumber.label",
1093
- defaultMessage: "Registration Number",
1094
- description: "Registration Number"
1095
- }
1096
- };
1097
-
1098
- // ../commons/src/events/WorkqueueConfig.ts
1099
- var WorkqueueConfig = import_zod15.z.object({
1100
- id: import_zod15.z.string().describe("Unique identifier for workqueue."),
1101
- filters: import_zod15.z.array(
1102
- import_zod15.z.object({
1103
- status: import_zod15.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
1104
- })
1105
- ).describe("Filters to be applied to workqueue.")
1106
- }).describe("Configuration for workqueue.");
1107
-
1108
1099
  // ../commons/src/events/AdvancedSearchConfig.ts
1109
- var import_zod16 = require("zod");
1110
- var AdvancedSearchConfig = import_zod16.z.object({
1100
+ var import_zod14 = require("zod");
1101
+ var AdvancedSearchConfig = import_zod14.z.object({
1111
1102
  title: TranslationConfig.describe("Advanced search tab title"),
1112
- fields: import_zod16.z.array(
1113
- import_zod16.z.object({
1114
- fieldId: import_zod16.z.string(),
1115
- config: import_zod16.z.object({
1116
- type: import_zod16.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
1103
+ fields: import_zod14.z.array(
1104
+ import_zod14.z.object({
1105
+ fieldId: import_zod14.z.string(),
1106
+ config: import_zod14.z.object({
1107
+ type: import_zod14.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
1117
1108
  }).optional().describe("Configuration options for the field")
1118
1109
  })
1119
1110
  ).optional().default([]).describe("Advanced search fields.")
@@ -1122,139 +1113,13 @@ var AdvancedSearchConfig = import_zod16.z.object({
1122
1113
  // ../commons/src/events/utils.ts
1123
1114
  var import_lodash = require("lodash");
1124
1115
 
1125
- // ../commons/src/workqueues/WorkqueueConfig.ts
1126
- var import_zod18 = require("zod");
1127
-
1128
- // ../commons/src/workqueues/defaultColumns.ts
1129
- var import_zod17 = require("zod");
1130
- var WorkQueueColumnConfig = import_zod17.z.object({
1131
- id: import_zod17.z.string(),
1132
- label: TranslationConfig
1133
- });
1134
- var defaultColumns = {
1135
- event: {
1136
- id: "event",
1137
- label: {
1138
- defaultMessage: "Event",
1139
- description: "This is the label for the workqueue column",
1140
- id: "workqueue.default.column.event"
1141
- }
1142
- },
1143
- status: {
1144
- id: "status",
1145
- label: {
1146
- defaultMessage: "Status",
1147
- description: "This is the label for the workqueue column",
1148
- id: "workqueue.default.column.status"
1149
- }
1150
- },
1151
- createdAt: {
1152
- id: "createdAt",
1153
- label: {
1154
- defaultMessage: "Created",
1155
- description: "This is the label for the workqueue column",
1156
- id: "workqueue.default.column.createdAt"
1157
- }
1158
- },
1159
- modifiedAt: {
1160
- id: "modifiedAt",
1161
- label: {
1162
- defaultMessage: "Modified",
1163
- description: "This is the label for the workqueue column",
1164
- id: "workqueue.default.column.modifiedAt"
1165
- }
1166
- }
1167
- };
1168
- var DefaultColumnKeys = import_zod17.z.enum(
1169
- Object.keys(defaultColumns)
1170
- );
1171
-
1172
- // ../commons/src/workqueues/WorkqueueConfig.ts
1173
- var rootWorkqueueConfig = import_zod18.z.object({
1174
- id: import_zod18.z.string(),
1175
- title: TranslationConfig,
1176
- columns: import_zod18.z.array(WorkQueueColumnConfig),
1177
- defaultColumns: import_zod18.z.array(DefaultColumnKeys)
1178
- });
1179
- var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
1180
-
1181
- // ../commons/src/workqueues/all.ts
1182
- var allWorkqueue = defineWorkqueue({
1183
- id: "all",
1184
- title: {
1185
- defaultMessage: "All events",
1186
- description: "This is the label for the workqueue",
1187
- id: "workqueue.all.label"
1188
- },
1189
- columns: [
1190
- {
1191
- id: "title",
1192
- label: {
1193
- defaultMessage: "Title",
1194
- description: "This is the label for the workqueue column",
1195
- id: "workqueue.all.column.title"
1196
- }
1197
- }
1198
- ],
1199
- defaultColumns: ["event", "status", "createdAt", "modifiedAt"]
1200
- });
1201
-
1202
- // ../commons/src/workqueues/readyForReview.ts
1203
- var inReviewWorkqueue = defineWorkqueue({
1204
- id: "ready-for-review",
1205
- title: {
1206
- defaultMessage: "Ready for review",
1207
- description: "Label for in review workqueue",
1208
- id: "event.workqueue.in-review.label"
1209
- },
1210
- columns: [
1211
- {
1212
- id: "title",
1213
- label: {
1214
- defaultMessage: "Title",
1215
- description: "This is the label for the workqueue column",
1216
- id: "workqueue.in-reveiw.column.title"
1217
- }
1218
- }
1219
- ],
1220
- defaultColumns: ["event", "createdAt", "modifiedAt"]
1221
- });
1222
-
1223
- // ../commons/src/workqueues/readyToPrint.ts
1224
- var registeredWorkqueue = defineWorkqueue({
1225
- id: "registered",
1226
- title: {
1227
- defaultMessage: "Ready to print",
1228
- description: "Label for registered workqueue",
1229
- id: "event.workqueue.registered.label"
1230
- },
1231
- columns: [
1232
- {
1233
- id: "title",
1234
- label: {
1235
- defaultMessage: "Title",
1236
- description: "This is the label for the workqueue column",
1237
- id: "workqueue.registered.column.title"
1238
- }
1239
- }
1240
- ],
1241
- defaultColumns: ["event", "createdAt", "modifiedAt"]
1242
- });
1243
-
1244
- // ../commons/src/workqueues/index.ts
1245
- var workqueues = {
1246
- all: allWorkqueue,
1247
- registered: registeredWorkqueue,
1248
- inReview: inReviewWorkqueue
1249
- };
1250
-
1251
1116
  // ../commons/src/conditionals/validate.ts
1252
1117
  var import_ajv = __toESM(require("ajv"));
1253
1118
  var import_ajv_formats = __toESM(require("ajv-formats"));
1254
1119
  var import_date_fns = require("date-fns");
1255
1120
 
1256
1121
  // ../commons/src/events/FieldTypeMapping.ts
1257
- var import_zod19 = require("zod");
1122
+ var import_zod15 = require("zod");
1258
1123
  function mapFieldTypeToZod(type, required) {
1259
1124
  let schema;
1260
1125
  switch (type) {
@@ -1307,7 +1172,7 @@ function createValidationSchema(config) {
1307
1172
  for (const field2 of config) {
1308
1173
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1309
1174
  }
1310
- return import_zod19.z.object(shape);
1175
+ return import_zod15.z.object(shape);
1311
1176
  }
1312
1177
  function mapFieldTypeToMockValue(field2, i) {
1313
1178
  switch (field2.type) {
@@ -1481,12 +1346,23 @@ var ajv = new import_ajv.default({
1481
1346
  function validate(schema, data) {
1482
1347
  return ajv.validate(schema, data);
1483
1348
  }
1349
+ function isConditionMet(conditional, values) {
1350
+ return validate(conditional, {
1351
+ $form: values,
1352
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1353
+ });
1354
+ }
1484
1355
  function getConditionalActionsForField(field2, values) {
1485
1356
  if (!field2.conditionals) {
1486
1357
  return [];
1487
1358
  }
1488
1359
  return field2.conditionals.filter((conditional) => validate(conditional.conditional, values)).map((conditional) => conditional.type);
1489
1360
  }
1361
+ function areConditionsMet(conditions, values) {
1362
+ return conditions.every(
1363
+ (condition) => isConditionMet(condition.conditional, values)
1364
+ );
1365
+ }
1490
1366
  function isFieldConditionMet(field2, form, conditionalType) {
1491
1367
  const hasRule = (field2.conditionals ?? []).some(
1492
1368
  (conditional) => conditional.type === conditionalType
@@ -1508,6 +1384,9 @@ function isFieldVisible(field2, form) {
1508
1384
  function isFieldEnabled(field2, form) {
1509
1385
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1510
1386
  }
1387
+ function isFieldDisplayedOnReview(field2, form) {
1388
+ return isFieldVisible(field2, form) && isFieldConditionMet(field2, form, ConditionalType.DISPLAY_ON_REVIEW);
1389
+ }
1511
1390
  var errorMessages = {
1512
1391
  hiddenField: {
1513
1392
  id: "v2.error.hidden",
@@ -1535,12 +1414,14 @@ var errorMessages = {
1535
1414
  id: "v2.error.invalid"
1536
1415
  }
1537
1416
  };
1538
- var createIntlError = (message) => ({
1539
- message: {
1540
- message
1541
- }
1542
- });
1543
- var zodToIntlErrorMap = (issue, _ctx) => {
1417
+ function createIntlError(message) {
1418
+ return {
1419
+ message: {
1420
+ message
1421
+ }
1422
+ };
1423
+ }
1424
+ function zodToIntlErrorMap(issue, _ctx) {
1544
1425
  switch (issue.code) {
1545
1426
  case "invalid_string": {
1546
1427
  if (_ctx.data === "") {
@@ -1578,41 +1459,6 @@ var zodToIntlErrorMap = (issue, _ctx) => {
1578
1459
  }
1579
1460
  }
1580
1461
  return createIntlError(errorMessages.invalidInput);
1581
- };
1582
- function getFieldValidationErrors({
1583
- field: field2,
1584
- values
1585
- }) {
1586
- const conditionalParameters = {
1587
- $form: values,
1588
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1589
- };
1590
- if (!isFieldVisible(field2, values) || !isFieldEnabled(field2, values)) {
1591
- if (values[field2.id]) {
1592
- return {
1593
- errors: [
1594
- {
1595
- message: errorMessages.hiddenField
1596
- }
1597
- ]
1598
- };
1599
- }
1600
- return {
1601
- errors: []
1602
- };
1603
- }
1604
- const fieldValidationResult = validateFieldInput({
1605
- field: field2,
1606
- value: values[field2.id]
1607
- });
1608
- const customValidationResults = runCustomFieldValidations({
1609
- field: field2,
1610
- conditionalParameters
1611
- });
1612
- return {
1613
- // Assumes that custom validation errors are based on the field type, and extend the validation.
1614
- errors: [...fieldValidationResult, ...customValidationResults]
1615
- };
1616
1462
  }
1617
1463
  function runCustomFieldValidations({
1618
1464
  field: field2,
@@ -1635,6 +1481,32 @@ function validateFieldInput({
1635
1481
  );
1636
1482
  return rawError.error?.issues.map((issue) => issue.message) ?? [];
1637
1483
  }
1484
+ function runFieldValidations({
1485
+ field: field2,
1486
+ values
1487
+ }) {
1488
+ if (!isFieldVisible(field2, values)) {
1489
+ return {
1490
+ errors: []
1491
+ };
1492
+ }
1493
+ const conditionalParameters = {
1494
+ $form: values,
1495
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1496
+ };
1497
+ const fieldValidationResult = validateFieldInput({
1498
+ field: field2,
1499
+ value: values[field2.id]
1500
+ });
1501
+ const customValidationResults = runCustomFieldValidations({
1502
+ field: field2,
1503
+ conditionalParameters
1504
+ });
1505
+ return {
1506
+ // Assumes that custom validation errors are based on the field type, and extend the validation.
1507
+ errors: [...fieldValidationResult, ...customValidationResults]
1508
+ };
1509
+ }
1638
1510
 
1639
1511
  // ../commons/src/uuid.ts
1640
1512
  var import_uuid = require("uuid");
@@ -1642,9 +1514,6 @@ function getUUID() {
1642
1514
  return (0, import_uuid.v4)();
1643
1515
  }
1644
1516
 
1645
- // ../commons/src/events/utils.ts
1646
- var import_date_fns2 = require("date-fns");
1647
-
1648
1517
  // ../commons/src/utils.ts
1649
1518
  function getOrThrow(x, message) {
1650
1519
  if (x === void 0 || x === null) {
@@ -1654,15 +1523,18 @@ function getOrThrow(x, message) {
1654
1523
  }
1655
1524
 
1656
1525
  // ../commons/src/events/utils.ts
1657
- var findAllFields = (config) => {
1658
- return (0, import_lodash.flattenDeep)([
1659
- ...getDeclarationFields(config),
1660
- ...getAllAnnotationFields(config)
1661
- ]);
1662
- };
1663
- var getAllAnnotationFields = (config) => {
1664
- return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1665
- };
1526
+ function isDeclarationActionConfig(action) {
1527
+ return DeclarationActions.safeParse(action.type).success;
1528
+ }
1529
+ function getDeclarationFields(configuration) {
1530
+ return configuration.declaration.pages.flatMap(({ fields }) => fields);
1531
+ }
1532
+ function getDeclarationPages(configuration) {
1533
+ return configuration.declaration.pages;
1534
+ }
1535
+ function getDeclaration(configuration) {
1536
+ return configuration.declaration;
1537
+ }
1666
1538
  var getActionAnnotationFields = (actionConfig) => {
1667
1539
  if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1668
1540
  return [
@@ -1671,13 +1543,22 @@ var getActionAnnotationFields = (actionConfig) => {
1671
1543
  ];
1672
1544
  }
1673
1545
  if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1674
- return actionConfig?.printForm.pages.flatMap(({ fields }) => fields) ?? [];
1546
+ return actionConfig.printForm.pages.flatMap(({ fields }) => fields);
1675
1547
  }
1676
1548
  if (isDeclarationActionConfig(actionConfig)) {
1677
- return actionConfig?.review.fields ?? [];
1549
+ return actionConfig.review.fields;
1678
1550
  }
1679
1551
  return [];
1680
1552
  };
1553
+ var getAllAnnotationFields = (config) => {
1554
+ return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1555
+ };
1556
+ var findAllFields = (config) => {
1557
+ return (0, import_lodash.flattenDeep)([
1558
+ ...getDeclarationFields(config),
1559
+ ...getAllAnnotationFields(config)
1560
+ ]);
1561
+ };
1681
1562
  var findRecordActionPages = (config, actionType) => {
1682
1563
  const action = config.actions.find((a) => a.type === actionType);
1683
1564
  if (action?.type === ActionType.REQUEST_CORRECTION) {
@@ -1688,72 +1569,37 @@ var findRecordActionPages = (config, actionType) => {
1688
1569
  }
1689
1570
  return [];
1690
1571
  };
1691
- function isDeclarationActionConfig(action) {
1692
- return DeclarationActions.safeParse(action.type).success;
1693
- }
1694
- function getDeclarationFields(configuration) {
1695
- return configuration.declaration.pages.flatMap(({ fields }) => fields);
1696
- }
1697
- function getDeclarationPages(configuration) {
1698
- return configuration.declaration.pages;
1699
- }
1700
- function getDeclaration(configuration) {
1701
- return configuration.declaration;
1702
- }
1703
- function getActionReviewFields(configuration, actionType) {
1704
- return getActionReview(configuration, actionType).fields;
1705
- }
1706
1572
  function getActionReview(configuration, actionType) {
1707
1573
  const [actionConfig] = configuration.actions.filter(
1708
1574
  (a) => a.type === actionType
1709
1575
  );
1710
1576
  return getOrThrow(
1711
- actionConfig?.review,
1577
+ actionConfig.review,
1712
1578
  `No review config found for ${actionType}`
1713
1579
  );
1714
1580
  }
1715
- function validateWorkqueueConfig(workqueueConfigs) {
1716
- workqueueConfigs.map((workqueue) => {
1717
- const rootWorkqueue = Object.values(workqueues).find(
1718
- (wq) => wq.id === workqueue.id
1719
- );
1720
- if (!rootWorkqueue) {
1721
- throw new Error(
1722
- `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1723
- );
1724
- }
1725
- });
1581
+ function getActionReviewFields(configuration, actionType) {
1582
+ return getActionReview(configuration, actionType).fields;
1726
1583
  }
1727
1584
  function isPageVisible(page, formValues) {
1728
1585
  if (!page.conditional) {
1729
1586
  return true;
1730
1587
  }
1731
- return validate(page.conditional, {
1732
- $form: formValues,
1733
- $now: (0, import_date_fns2.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1734
- });
1735
- }
1736
- var getVisiblePagesFormFields = (formConfig, formData) => {
1737
- return formConfig.pages.filter((p) => isPageVisible(p, formData)).flatMap((p) => p.fields);
1738
- };
1739
- function isOptionalUncheckedCheckbox(field2, form) {
1740
- if (field2.type !== FieldType.CHECKBOX || field2.required) {
1741
- return false;
1742
- }
1743
- return !form[field2.id];
1588
+ return isConditionMet(page.conditional, formValues);
1744
1589
  }
1745
- function stripHiddenFields(fields, declaration) {
1746
- return (0, import_lodash.omitBy)(declaration, (_2, fieldId) => {
1590
+ function omitHiddenFields(fields, values) {
1591
+ return (0, import_lodash.omitBy)(values, (_, fieldId) => {
1747
1592
  const field2 = fields.find((f) => f.id === fieldId);
1748
1593
  if (!field2) {
1749
1594
  return true;
1750
1595
  }
1751
- if (isOptionalUncheckedCheckbox(field2, declaration)) {
1752
- return true;
1753
- }
1754
- return !isFieldVisible(field2, declaration);
1596
+ return !isFieldVisible(field2, values);
1755
1597
  });
1756
1598
  }
1599
+ function omitHiddenPaginatedFields(formConfig, declaration) {
1600
+ const visiblePagesFormFields = formConfig.pages.filter((p) => isPageVisible(p, declaration)).flatMap((p) => p.fields);
1601
+ return omitHiddenFields(visiblePagesFormFields, declaration);
1602
+ }
1757
1603
  function findActiveDrafts(event2, drafts) {
1758
1604
  const actions = event2.actions.slice().filter(({ type }) => type !== ActionType.READ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1759
1605
  const lastAction = actions[actions.length - 1];
@@ -1796,19 +1642,28 @@ function deepMerge(currentDocument, actionDocument) {
1796
1642
  }
1797
1643
  );
1798
1644
  }
1645
+ function findLastAssignmentAction(actions) {
1646
+ return actions.filter(
1647
+ ({ type }) => type === ActionType.ASSIGN || type === ActionType.UNASSIGN
1648
+ ).reduce((latestAction, action) => !latestAction || action.createdAt > latestAction.createdAt ? action : latestAction, void 0);
1649
+ }
1650
+ function isWriteAction(actionType) {
1651
+ return writeActions.safeParse(actionType).success;
1652
+ }
1799
1653
 
1800
1654
  // ../commons/src/events/EventConfig.ts
1801
- var EventConfig = import_zod20.z.object({
1802
- id: import_zod20.z.string().describe(
1655
+ var import_zod_openapi7 = require("zod-openapi");
1656
+ (0, import_zod_openapi7.extendZodWithOpenApi)(import_zod16.z);
1657
+ var EventConfig = import_zod16.z.object({
1658
+ id: import_zod16.z.string().describe(
1803
1659
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1804
1660
  ),
1805
1661
  summary: SummaryConfig,
1806
1662
  label: TranslationConfig,
1807
- actions: import_zod20.z.array(ActionConfig),
1663
+ actions: import_zod16.z.array(ActionConfig),
1808
1664
  declaration: DeclarationFormConfig,
1809
- workqueues: import_zod20.z.array(WorkqueueConfig),
1810
- deduplication: import_zod20.z.array(DeduplicationConfig).optional().default([]),
1811
- advancedSearch: import_zod20.z.array(AdvancedSearchConfig).optional().default([])
1665
+ deduplication: import_zod16.z.array(DeduplicationConfig).optional().default([]),
1666
+ advancedSearch: import_zod16.z.array(AdvancedSearchConfig).optional().default([])
1812
1667
  }).superRefine((event2, ctx) => {
1813
1668
  const allFields = findAllFields(event2);
1814
1669
  const fieldIds = allFields.map((field2) => field2.id);
@@ -1834,6 +1689,8 @@ var EventConfig = import_zod20.z.object({
1834
1689
  path: ["advancedSearch"]
1835
1690
  });
1836
1691
  }
1692
+ }).openapi({
1693
+ ref: "EventConfig"
1837
1694
  });
1838
1695
 
1839
1696
  // ../commons/src/events/EventConfigInput.ts
@@ -1842,306 +1699,451 @@ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1842
1699
  var definePage = (page) => PageConfig.parse(page);
1843
1700
  var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1844
1701
 
1702
+ // ../commons/src/events/WorkqueueConfig.ts
1703
+ var import_zod17 = require("zod");
1704
+ var WorkqueueConfig = import_zod17.z.object({
1705
+ slug: import_zod17.z.string().describe("Determines the url of the workqueue."),
1706
+ name: TranslationConfig.describe(
1707
+ "Title of the workflow (both in navigation and on the page)"
1708
+ ),
1709
+ /**
1710
+ * Placeholder untill the following gets merged to develop
1711
+ * https://github.com/opencrvs/opencrvs-core/blob/5fbe9854a88504a7a13fcc856b3e82594b70c38c/packages/commons/src/events/EventIndex.ts#L92-L93
1712
+ */
1713
+ query: import_zod17.z.string(),
1714
+ actions: import_zod17.z.array(
1715
+ import_zod17.z.object({
1716
+ type: import_zod17.z.string(),
1717
+ conditionals: import_zod17.z.array(Conditional).optional()
1718
+ })
1719
+ )
1720
+ }).describe("Configuration for workqueue.");
1721
+ function defineWorkqueue(workqueues) {
1722
+ return workqueues.map((workqueue) => WorkqueueConfig.parse(workqueue));
1723
+ }
1724
+
1845
1725
  // ../commons/src/events/Draft.ts
1846
- var import_zod23 = require("zod");
1726
+ var import_zod20 = require("zod");
1847
1727
 
1848
1728
  // ../commons/src/events/ActionDocument.ts
1849
- var import_zod21 = require("zod");
1850
- var ActionUpdate = import_zod21.z.record(import_zod21.z.string(), FieldUpdateValue);
1729
+ var import_zod18 = require("zod");
1730
+ var import_zod_openapi8 = require("zod-openapi");
1731
+ (0, import_zod_openapi8.extendZodWithOpenApi)(import_zod18.z);
1732
+ var ActionUpdate = import_zod18.z.record(import_zod18.z.string(), FieldUpdateValue);
1851
1733
  var ActionStatus = {
1852
1734
  Requested: "Requested",
1853
1735
  Accepted: "Accepted",
1854
1736
  Rejected: "Rejected"
1855
1737
  };
1856
- var ActionBase = import_zod21.z.object({
1857
- id: import_zod21.z.string(),
1858
- createdAt: import_zod21.z.string().datetime(),
1859
- createdBy: import_zod21.z.string(),
1738
+ var ActionBase = import_zod18.z.object({
1739
+ id: import_zod18.z.string(),
1740
+ transactionId: import_zod18.z.string(),
1741
+ createdAt: import_zod18.z.string().datetime(),
1742
+ createdBy: import_zod18.z.string(),
1743
+ createdByRole: import_zod18.z.string(),
1860
1744
  declaration: ActionUpdate,
1861
1745
  annotation: ActionUpdate.optional(),
1862
- createdAtLocation: import_zod21.z.string(),
1863
- status: import_zod21.z.enum([
1746
+ createdAtLocation: import_zod18.z.string(),
1747
+ status: import_zod18.z.enum([
1864
1748
  ActionStatus.Requested,
1865
1749
  ActionStatus.Accepted,
1866
1750
  ActionStatus.Rejected
1867
1751
  ]),
1868
1752
  // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1869
- originalActionId: import_zod21.z.string().optional()
1753
+ originalActionId: import_zod18.z.string().optional()
1870
1754
  });
1871
1755
  var AssignedAction = ActionBase.merge(
1872
- import_zod21.z.object({
1873
- type: import_zod21.z.literal(ActionType.ASSIGN),
1874
- assignedTo: import_zod21.z.string()
1756
+ import_zod18.z.object({
1757
+ type: import_zod18.z.literal(ActionType.ASSIGN),
1758
+ assignedTo: import_zod18.z.string()
1875
1759
  })
1876
1760
  );
1877
1761
  var UnassignedAction = ActionBase.merge(
1878
- import_zod21.z.object({
1879
- type: import_zod21.z.literal(ActionType.UNASSIGN)
1762
+ import_zod18.z.object({
1763
+ type: import_zod18.z.literal(ActionType.UNASSIGN),
1764
+ assignedTo: import_zod18.z.literal(null)
1880
1765
  })
1881
1766
  );
1882
1767
  var RegisterAction = ActionBase.merge(
1883
- import_zod21.z.object({
1884
- type: import_zod21.z.literal(ActionType.REGISTER),
1885
- registrationNumber: import_zod21.z.string().optional()
1768
+ import_zod18.z.object({
1769
+ type: import_zod18.z.literal(ActionType.REGISTER),
1770
+ registrationNumber: import_zod18.z.string().optional()
1886
1771
  })
1887
1772
  );
1888
1773
  var DeclareAction = ActionBase.merge(
1889
- import_zod21.z.object({
1890
- type: import_zod21.z.literal(ActionType.DECLARE)
1774
+ import_zod18.z.object({
1775
+ type: import_zod18.z.literal(ActionType.DECLARE)
1891
1776
  })
1892
1777
  );
1893
1778
  var ValidateAction = ActionBase.merge(
1894
- import_zod21.z.object({
1895
- type: import_zod21.z.literal(ActionType.VALIDATE)
1779
+ import_zod18.z.object({
1780
+ type: import_zod18.z.literal(ActionType.VALIDATE)
1896
1781
  })
1897
1782
  );
1898
1783
  var RejectAction = ActionBase.merge(
1899
- import_zod21.z.object({
1900
- type: import_zod21.z.literal(ActionType.REJECT)
1784
+ import_zod18.z.object({
1785
+ type: import_zod18.z.literal(ActionType.REJECT)
1901
1786
  })
1902
1787
  );
1903
1788
  var MarkAsDuplicateAction = ActionBase.merge(
1904
- import_zod21.z.object({
1905
- type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE)
1789
+ import_zod18.z.object({
1790
+ type: import_zod18.z.literal(ActionType.MARKED_AS_DUPLICATE)
1906
1791
  })
1907
1792
  );
1908
1793
  var ArchiveAction = ActionBase.merge(
1909
- import_zod21.z.object({
1910
- type: import_zod21.z.literal(ActionType.ARCHIVE)
1794
+ import_zod18.z.object({
1795
+ type: import_zod18.z.literal(ActionType.ARCHIVE)
1911
1796
  })
1912
1797
  );
1913
1798
  var CreatedAction = ActionBase.merge(
1914
- import_zod21.z.object({
1915
- type: import_zod21.z.literal(ActionType.CREATE)
1799
+ import_zod18.z.object({
1800
+ type: import_zod18.z.literal(ActionType.CREATE)
1916
1801
  })
1917
1802
  );
1918
1803
  var NotifiedAction = ActionBase.merge(
1919
- import_zod21.z.object({
1920
- type: import_zod21.z.literal(ActionType.NOTIFY)
1804
+ import_zod18.z.object({
1805
+ type: import_zod18.z.literal(ActionType.NOTIFY)
1921
1806
  })
1922
1807
  );
1923
1808
  var PrintCertificateAction = ActionBase.merge(
1924
- import_zod21.z.object({
1925
- type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE)
1809
+ import_zod18.z.object({
1810
+ type: import_zod18.z.literal(ActionType.PRINT_CERTIFICATE)
1926
1811
  })
1927
1812
  );
1928
1813
  var RequestedCorrectionAction = ActionBase.merge(
1929
- import_zod21.z.object({
1930
- type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION)
1814
+ import_zod18.z.object({
1815
+ type: import_zod18.z.literal(ActionType.REQUEST_CORRECTION)
1931
1816
  })
1932
1817
  );
1933
1818
  var ApprovedCorrectionAction = ActionBase.merge(
1934
- import_zod21.z.object({
1935
- type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION),
1936
- requestId: import_zod21.z.string()
1819
+ import_zod18.z.object({
1820
+ type: import_zod18.z.literal(ActionType.APPROVE_CORRECTION),
1821
+ requestId: import_zod18.z.string()
1937
1822
  })
1938
1823
  );
1939
1824
  var RejectedCorrectionAction = ActionBase.merge(
1940
- import_zod21.z.object({
1941
- type: import_zod21.z.literal(ActionType.REJECT_CORRECTION),
1942
- requestId: import_zod21.z.string()
1825
+ import_zod18.z.object({
1826
+ type: import_zod18.z.literal(ActionType.REJECT_CORRECTION),
1827
+ requestId: import_zod18.z.string()
1943
1828
  })
1944
1829
  );
1945
1830
  var ReadAction = ActionBase.merge(
1946
- import_zod21.z.object({
1947
- type: import_zod21.z.literal(ActionType.READ)
1831
+ import_zod18.z.object({
1832
+ type: import_zod18.z.literal(ActionType.READ)
1948
1833
  })
1949
1834
  );
1950
- var ActionDocument = import_zod21.z.discriminatedUnion("type", [
1951
- CreatedAction,
1952
- ValidateAction,
1953
- RejectAction,
1954
- MarkAsDuplicateAction,
1955
- ArchiveAction,
1956
- NotifiedAction,
1957
- RegisterAction,
1958
- DeclareAction,
1959
- AssignedAction,
1960
- RequestedCorrectionAction,
1961
- ApprovedCorrectionAction,
1962
- RejectedCorrectionAction,
1963
- UnassignedAction,
1964
- PrintCertificateAction,
1965
- ReadAction
1966
- ]);
1835
+ var ActionDocument = import_zod18.z.discriminatedUnion("type", [
1836
+ CreatedAction.openapi({ ref: "CreatedAction" }),
1837
+ ValidateAction.openapi({ ref: "ValidateAction" }),
1838
+ RejectAction.openapi({ ref: "RejectAction" }),
1839
+ MarkAsDuplicateAction.openapi({ ref: "MarkAsDuplicateAction" }),
1840
+ ArchiveAction.openapi({ ref: "ArchiveAction" }),
1841
+ NotifiedAction.openapi({ ref: "NotifiedAction" }),
1842
+ RegisterAction.openapi({ ref: "RegisterAction" }),
1843
+ DeclareAction.openapi({ ref: "DeclareAction" }),
1844
+ AssignedAction.openapi({ ref: "AssignedAction" }),
1845
+ RequestedCorrectionAction.openapi({ ref: "RequestedCorrectionAction" }),
1846
+ ApprovedCorrectionAction.openapi({ ref: "ApprovedCorrectionAction" }),
1847
+ RejectedCorrectionAction.openapi({ ref: "RejectedCorrectionAction" }),
1848
+ UnassignedAction.openapi({ ref: "UnassignedAction" }),
1849
+ PrintCertificateAction.openapi({ ref: "PrintCertificateAction" }),
1850
+ ReadAction.openapi({ ref: "ReadAction" })
1851
+ ]).openapi({
1852
+ ref: "ActionDocument"
1853
+ });
1967
1854
  var AsyncRejectActionDocument = ActionBase.omit({
1968
1855
  declaration: true,
1969
1856
  annotation: true,
1970
1857
  createdBy: true,
1858
+ createdByRole: true,
1971
1859
  createdAtLocation: true
1972
1860
  }).merge(
1973
- import_zod21.z.object({
1974
- type: import_zod21.z.enum(ConfirmableActions),
1975
- status: import_zod21.z.literal(ActionStatus.Rejected)
1861
+ import_zod18.z.object({
1862
+ type: import_zod18.z.enum(ConfirmableActions),
1863
+ status: import_zod18.z.literal(ActionStatus.Rejected)
1976
1864
  })
1977
1865
  );
1978
- var Action = import_zod21.z.union([ActionDocument, AsyncRejectActionDocument]);
1979
- var ResolvedUser = import_zod21.z.object({
1980
- id: import_zod21.z.string(),
1981
- role: import_zod21.z.string(),
1982
- name: import_zod21.z.array(
1983
- import_zod21.z.object({
1984
- use: import_zod21.z.string(),
1985
- given: import_zod21.z.array(import_zod21.z.string()),
1986
- family: import_zod21.z.string()
1866
+ var Action = import_zod18.z.union([ActionDocument, AsyncRejectActionDocument]);
1867
+ var ResolvedUser = import_zod18.z.object({
1868
+ id: import_zod18.z.string(),
1869
+ role: import_zod18.z.string(),
1870
+ name: import_zod18.z.array(
1871
+ import_zod18.z.object({
1872
+ use: import_zod18.z.string(),
1873
+ given: import_zod18.z.array(import_zod18.z.string()),
1874
+ family: import_zod18.z.string()
1987
1875
  })
1988
1876
  )
1989
1877
  });
1990
1878
 
1991
1879
  // ../commons/src/events/ActionInput.ts
1992
- var import_zod22 = require("zod");
1993
- var BaseActionInput = import_zod22.z.object({
1994
- eventId: import_zod22.z.string(),
1995
- transactionId: import_zod22.z.string(),
1996
- declaration: ActionUpdate,
1880
+ var import_zod19 = require("zod");
1881
+ var import_zod_openapi9 = require("zod-openapi");
1882
+ (0, import_zod_openapi9.extendZodWithOpenApi)(import_zod19.z);
1883
+ var BaseActionInput = import_zod19.z.object({
1884
+ eventId: import_zod19.z.string(),
1885
+ transactionId: import_zod19.z.string(),
1886
+ declaration: ActionUpdate.default({}),
1997
1887
  annotation: ActionUpdate.optional(),
1998
- originalActionId: import_zod22.z.string().optional()
1888
+ originalActionId: import_zod19.z.string().optional(),
1889
+ keepAssignment: import_zod19.z.boolean().optional()
1999
1890
  });
2000
1891
  var CreateActionInput = BaseActionInput.merge(
2001
- import_zod22.z.object({
2002
- type: import_zod22.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2003
- createdAtLocation: import_zod22.z.string()
1892
+ import_zod19.z.object({
1893
+ type: import_zod19.z.literal(ActionType.CREATE).default(ActionType.CREATE),
1894
+ createdAtLocation: import_zod19.z.string()
2004
1895
  })
2005
1896
  );
2006
1897
  var RegisterActionInput = BaseActionInput.merge(
2007
- import_zod22.z.object({
2008
- type: import_zod22.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2009
- registrationNumber: import_zod22.z.string().optional()
1898
+ import_zod19.z.object({
1899
+ type: import_zod19.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
1900
+ registrationNumber: import_zod19.z.string().optional()
2010
1901
  })
2011
1902
  );
2012
1903
  var ValidateActionInput = BaseActionInput.merge(
2013
- import_zod22.z.object({
2014
- type: import_zod22.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2015
- duplicates: import_zod22.z.array(import_zod22.z.string())
1904
+ import_zod19.z.object({
1905
+ type: import_zod19.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
1906
+ duplicates: import_zod19.z.array(import_zod19.z.string())
2016
1907
  })
2017
1908
  );
2018
1909
  var NotifyActionInput = BaseActionInput.merge(
2019
- import_zod22.z.object({
2020
- type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1910
+ import_zod19.z.object({
1911
+ type: import_zod19.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2021
1912
  })
2022
1913
  );
2023
1914
  var DeclareActionInput = BaseActionInput.merge(
2024
- import_zod22.z.object({
2025
- type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1915
+ import_zod19.z.object({
1916
+ type: import_zod19.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2026
1917
  })
2027
1918
  );
2028
1919
  var PrintCertificateActionInput = BaseActionInput.merge(
2029
- import_zod22.z.object({
2030
- type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1920
+ import_zod19.z.object({
1921
+ type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2031
1922
  })
2032
1923
  );
2033
1924
  var RejectDeclarationActionInput = BaseActionInput.merge(
2034
- import_zod22.z.object({
2035
- type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1925
+ import_zod19.z.object({
1926
+ type: import_zod19.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2036
1927
  })
2037
1928
  );
2038
1929
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
2039
- import_zod22.z.object({
2040
- type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1930
+ import_zod19.z.object({
1931
+ type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2041
1932
  })
2042
1933
  );
2043
1934
  var ArchiveActionInput = BaseActionInput.merge(
2044
- import_zod22.z.object({
2045
- type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1935
+ import_zod19.z.object({
1936
+ type: import_zod19.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2046
1937
  })
2047
1938
  );
2048
1939
  var AssignActionInput = BaseActionInput.merge(
2049
- import_zod22.z.object({
2050
- type: import_zod22.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2051
- assignedTo: import_zod22.z.string()
1940
+ import_zod19.z.object({
1941
+ type: import_zod19.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
1942
+ assignedTo: import_zod19.z.string()
2052
1943
  })
2053
1944
  );
2054
1945
  var UnassignActionInput = BaseActionInput.merge(
2055
- import_zod22.z.object({
2056
- type: import_zod22.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN)
1946
+ import_zod19.z.object({
1947
+ type: import_zod19.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
1948
+ assignedTo: import_zod19.z.literal(null).default(null)
2057
1949
  })
2058
1950
  );
2059
1951
  var RequestCorrectionActionInput = BaseActionInput.merge(
2060
- import_zod22.z.object({
2061
- type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
1952
+ import_zod19.z.object({
1953
+ type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2062
1954
  })
2063
1955
  );
2064
1956
  var RejectCorrectionActionInput = BaseActionInput.merge(
2065
- import_zod22.z.object({
2066
- requestId: import_zod22.z.string(),
2067
- type: import_zod22.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
1957
+ import_zod19.z.object({
1958
+ requestId: import_zod19.z.string(),
1959
+ type: import_zod19.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2068
1960
  })
2069
1961
  );
2070
1962
  var ApproveCorrectionActionInput = BaseActionInput.merge(
2071
- import_zod22.z.object({
2072
- requestId: import_zod22.z.string(),
2073
- type: import_zod22.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
1963
+ import_zod19.z.object({
1964
+ requestId: import_zod19.z.string(),
1965
+ type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2074
1966
  })
2075
1967
  );
2076
1968
  var ReadActionInput = BaseActionInput.merge(
2077
- import_zod22.z.object({
2078
- type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
1969
+ import_zod19.z.object({
1970
+ type: import_zod19.z.literal(ActionType.READ).default(ActionType.READ)
2079
1971
  })
2080
1972
  );
2081
- var ActionInput = import_zod22.z.discriminatedUnion("type", [
2082
- CreateActionInput,
2083
- ValidateActionInput,
2084
- RegisterActionInput,
2085
- NotifyActionInput,
2086
- DeclareActionInput,
2087
- RejectDeclarationActionInput,
2088
- MarkedAsDuplicateActionInput,
2089
- ArchiveActionInput,
2090
- AssignActionInput,
2091
- UnassignActionInput,
2092
- PrintCertificateActionInput,
2093
- RequestCorrectionActionInput,
2094
- RejectCorrectionActionInput,
2095
- ApproveCorrectionActionInput,
2096
- ReadActionInput
2097
- ]);
1973
+ var DeleteActionInput = import_zod19.z.object({ eventId: import_zod19.z.string() });
1974
+ var ActionInput = import_zod19.z.discriminatedUnion("type", [
1975
+ CreateActionInput.openapi({ ref: "CreateActionInput" }),
1976
+ ValidateActionInput.openapi({ ref: "ValidateActionInput" }),
1977
+ RegisterActionInput.openapi({ ref: "RegisterActionInput" }),
1978
+ NotifyActionInput.openapi({ ref: "NotifyActionInput" }),
1979
+ DeclareActionInput.openapi({ ref: "DeclareActionInput" }),
1980
+ RejectDeclarationActionInput.openapi({
1981
+ ref: "RejectDeclarationActionInput"
1982
+ }),
1983
+ MarkedAsDuplicateActionInput.openapi({
1984
+ ref: "MarkedAsDuplicateActionInput"
1985
+ }),
1986
+ ArchiveActionInput.openapi({ ref: "ArchiveActionInput" }),
1987
+ AssignActionInput.openapi({ ref: "AssignActionInput" }),
1988
+ UnassignActionInput.openapi({ ref: "UnassignActionInput" }),
1989
+ PrintCertificateActionInput.openapi({ ref: "PrintCertificateActionInput" }),
1990
+ RequestCorrectionActionInput.openapi({
1991
+ ref: "RequestCorrectionActionInput"
1992
+ }),
1993
+ RejectCorrectionActionInput.openapi({ ref: "RejectCorrectionActionInput" }),
1994
+ ApproveCorrectionActionInput.openapi({
1995
+ ref: "ApproveCorrectionActionInput"
1996
+ }),
1997
+ ReadActionInput.openapi({ ref: "ReadActionInput" })
1998
+ ]).openapi({
1999
+ ref: "ActionInput"
2000
+ });
2098
2001
 
2099
2002
  // ../commons/src/events/Draft.ts
2100
- var Draft = import_zod23.z.object({
2101
- id: import_zod23.z.string(),
2102
- eventId: import_zod23.z.string(),
2103
- transactionId: import_zod23.z.string(),
2104
- createdAt: import_zod23.z.string().datetime(),
2003
+ var Draft = import_zod20.z.object({
2004
+ id: import_zod20.z.string(),
2005
+ eventId: import_zod20.z.string(),
2006
+ transactionId: import_zod20.z.string(),
2007
+ createdAt: import_zod20.z.string().datetime(),
2105
2008
  action: ActionBase.extend({
2106
2009
  type: ActionTypes
2107
- }).omit({ id: true, status: true })
2010
+ }).omit({ id: true })
2108
2011
  });
2109
2012
  var DraftInput = BaseActionInput.extend({
2110
2013
  type: ActionTypes
2111
2014
  });
2112
2015
 
2016
+ // ../commons/src/events/EventMetadata.ts
2017
+ var import_zod21 = require("zod");
2018
+ var EventStatus = {
2019
+ CREATED: "CREATED",
2020
+ NOTIFIED: "NOTIFIED",
2021
+ DECLARED: "DECLARED",
2022
+ VALIDATED: "VALIDATED",
2023
+ REGISTERED: "REGISTERED",
2024
+ CERTIFIED: "CERTIFIED",
2025
+ REJECTED: "REJECTED",
2026
+ ARCHIVED: "ARCHIVED"
2027
+ };
2028
+ var eventStatuses = Object.values(EventStatus);
2029
+ var EventStatuses = import_zod21.z.nativeEnum(EventStatus);
2030
+ var EventMetadata = import_zod21.z.object({
2031
+ id: import_zod21.z.string(),
2032
+ type: import_zod21.z.string(),
2033
+ status: EventStatuses,
2034
+ createdAt: import_zod21.z.string().datetime(),
2035
+ createdBy: import_zod21.z.string(),
2036
+ updatedByUserRole: import_zod21.z.string(),
2037
+ createdAtLocation: import_zod21.z.string(),
2038
+ updatedAtLocation: import_zod21.z.string(),
2039
+ modifiedAt: import_zod21.z.string().datetime(),
2040
+ assignedTo: import_zod21.z.string().nullish(),
2041
+ updatedBy: import_zod21.z.string(),
2042
+ trackingId: import_zod21.z.string(),
2043
+ registrationNumber: import_zod21.z.string().nullish()
2044
+ });
2045
+ var eventMetadataLabelMap = {
2046
+ "event.assignedTo": {
2047
+ id: "event.assignedTo.label",
2048
+ defaultMessage: "Assigned To",
2049
+ description: "Assigned To"
2050
+ },
2051
+ "event.createdAt": {
2052
+ id: "event.createdAt.label",
2053
+ defaultMessage: "Created",
2054
+ description: "Created At"
2055
+ },
2056
+ "event.createdAtLocation": {
2057
+ id: "event.createdAtLocation.label",
2058
+ defaultMessage: "Location",
2059
+ description: "Created At Location"
2060
+ },
2061
+ "event.updatedAtLocation": {
2062
+ id: "event.updatedAtLocation.label",
2063
+ defaultMessage: "Location",
2064
+ description: "Updated At Location"
2065
+ },
2066
+ "event.createdBy": {
2067
+ id: "event.createdBy.label",
2068
+ defaultMessage: "Created By",
2069
+ description: "Created By"
2070
+ },
2071
+ "event.updatedByUserRole": {
2072
+ id: "event.updatedByUserRole.label",
2073
+ defaultMessage: "Updated By Role",
2074
+ description: "Updated By Role"
2075
+ },
2076
+ "event.id": {
2077
+ id: "event.id.label",
2078
+ defaultMessage: "ID",
2079
+ description: "ID"
2080
+ },
2081
+ "event.modifiedAt": {
2082
+ id: "event.modifiedAt.label",
2083
+ defaultMessage: "Updated",
2084
+ description: "Modified At"
2085
+ },
2086
+ "event.status": {
2087
+ id: "event.status.label",
2088
+ defaultMessage: "Status",
2089
+ description: "Status"
2090
+ },
2091
+ "event.type": {
2092
+ id: "event.type.label",
2093
+ defaultMessage: "Type",
2094
+ description: "Type"
2095
+ },
2096
+ "event.updatedBy": {
2097
+ id: "event.updatedBy.label",
2098
+ defaultMessage: "Updated By",
2099
+ description: "Updated By"
2100
+ },
2101
+ "event.trackingId": {
2102
+ id: "event.trackingId.label",
2103
+ defaultMessage: "Tracking ID",
2104
+ description: "Tracking ID"
2105
+ },
2106
+ "event.registrationNumber": {
2107
+ id: "event.registrationNumber.label",
2108
+ defaultMessage: "Registration Number",
2109
+ description: "Registration Number"
2110
+ }
2111
+ };
2112
+
2113
2113
  // ../commons/src/events/EventInput.ts
2114
- var import_zod24 = require("zod");
2115
- var EventInput = import_zod24.z.object({
2116
- transactionId: import_zod24.z.string(),
2117
- type: import_zod24.z.string()
2114
+ var import_zod22 = require("zod");
2115
+ var EventInput = import_zod22.z.object({
2116
+ transactionId: import_zod22.z.string(),
2117
+ type: import_zod22.z.string()
2118
2118
  });
2119
2119
 
2120
2120
  // ../commons/src/events/EventDocument.ts
2121
- var import_zod25 = require("zod");
2122
- var EventDocument = import_zod25.z.object({
2123
- id: import_zod25.z.string(),
2124
- type: import_zod25.z.string(),
2125
- createdAt: import_zod25.z.string().datetime(),
2126
- updatedAt: import_zod25.z.string().datetime(),
2127
- actions: import_zod25.z.array(Action),
2128
- trackingId: import_zod25.z.string()
2129
- });
2121
+ var import_zod23 = require("zod");
2122
+ var import_zod_openapi10 = require("zod-openapi");
2123
+ (0, import_zod_openapi10.extendZodWithOpenApi)(import_zod23.z);
2124
+ var EventDocument = import_zod23.z.object({
2125
+ id: import_zod23.z.string(),
2126
+ type: import_zod23.z.string(),
2127
+ createdAt: import_zod23.z.string().datetime(),
2128
+ updatedAt: import_zod23.z.string().datetime(),
2129
+ updatedAtLocation: import_zod23.z.string(),
2130
+ actions: import_zod23.z.array(Action),
2131
+ trackingId: import_zod23.z.string()
2132
+ }).openapi({ ref: "EventDocument" });
2130
2133
 
2131
2134
  // ../commons/src/events/EventIndex.ts
2132
- var import_zod26 = require("zod");
2135
+ var import_zod24 = require("zod");
2133
2136
  var EventIndex = EventMetadata.extend({
2134
- declaration: import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any())
2137
+ declaration: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any())
2135
2138
  });
2136
- var EventSearchIndex = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any()).and(
2137
- import_zod26.z.object({
2138
- type: import_zod26.z.string()
2139
+ var EventSearchIndex = import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any()).and(
2140
+ import_zod24.z.object({
2141
+ type: import_zod24.z.string()
2139
2142
  // Ensures "type" (event-id) exists and is a string
2140
2143
  })
2141
2144
  );
2142
2145
 
2143
2146
  // ../commons/src/events/state/index.ts
2144
- var _ = __toESM(require("lodash"));
2145
2147
  function getStatusFromActions(actions) {
2146
2148
  const hasRejectedAction = actions.some(
2147
2149
  (a) => a.status === ActionStatus.Rejected
@@ -2150,30 +2152,46 @@ function getStatusFromActions(actions) {
2150
2152
  return EventStatus.REJECTED;
2151
2153
  }
2152
2154
  return actions.reduce((status, action) => {
2153
- if (action.type === ActionType.CREATE) {
2154
- return EventStatus.CREATED;
2155
- }
2156
- if (action.type === ActionType.DECLARE) {
2157
- return EventStatus.DECLARED;
2158
- }
2159
- if (action.type === ActionType.VALIDATE) {
2160
- return EventStatus.VALIDATED;
2161
- }
2162
- if (action.type === ActionType.REGISTER) {
2163
- return EventStatus.REGISTERED;
2164
- }
2165
- if (action.type === ActionType.REJECT) {
2166
- return EventStatus.REJECTED;
2167
- }
2168
- if (action.type === ActionType.ARCHIVE) {
2169
- return EventStatus.ARCHIVED;
2170
- }
2171
- if (action.type === ActionType.NOTIFY) {
2172
- return EventStatus.NOTIFIED;
2155
+ switch (action.type) {
2156
+ case ActionType.CREATE:
2157
+ return EventStatus.CREATED;
2158
+ case ActionType.DECLARE:
2159
+ return EventStatus.DECLARED;
2160
+ case ActionType.VALIDATE:
2161
+ return EventStatus.VALIDATED;
2162
+ case ActionType.REGISTER:
2163
+ return EventStatus.REGISTERED;
2164
+ case ActionType.REJECT:
2165
+ return EventStatus.REJECTED;
2166
+ case ActionType.ARCHIVE:
2167
+ return EventStatus.ARCHIVED;
2168
+ case ActionType.NOTIFY:
2169
+ return EventStatus.NOTIFIED;
2170
+ case ActionType.PRINT_CERTIFICATE:
2171
+ case ActionType.ASSIGN:
2172
+ case ActionType.UNASSIGN:
2173
+ case ActionType.REQUEST_CORRECTION:
2174
+ case ActionType.APPROVE_CORRECTION:
2175
+ case ActionType.MARKED_AS_DUPLICATE:
2176
+ case ActionType.REJECT_CORRECTION:
2177
+ case ActionType.READ:
2178
+ default:
2179
+ return status;
2173
2180
  }
2174
- return status;
2175
2181
  }, EventStatus.CREATED);
2176
2182
  }
2183
+ function getLastUpdatedByUserRoleFromActions(actions) {
2184
+ const actionsWithRoles = actions.filter(
2185
+ (action) => !isWriteAction(action.type) && action.status !== ActionStatus.Rejected
2186
+ ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2187
+ const lastAction = actionsWithRoles.at(-1);
2188
+ if (!lastAction) {
2189
+ throw new Error(
2190
+ "Should never happen, at least CREATE action should be present"
2191
+ );
2192
+ }
2193
+ return ActionDocument.parse(lastAction).createdByRole;
2194
+ }
2177
2195
  function getAssignedUserFromActions(actions) {
2178
2196
  return actions.reduce((user2, action) => {
2179
2197
  if (action.type === ActionType.ASSIGN) {
@@ -2205,26 +2223,27 @@ function aggregateActionDeclarations(actions) {
2205
2223
  }, {});
2206
2224
  }
2207
2225
  function deepDropNulls(obj) {
2208
- if (!_.isObject(obj)) return obj;
2209
- return Object.entries(obj).reduce((acc, [key, value]) => {
2210
- if (_.isObject(value)) {
2211
- value = deepDropNulls(value);
2212
- }
2213
- if (value !== null) {
2214
- return {
2215
- ...acc,
2216
- [key]: value
2217
- };
2218
- }
2219
- return acc;
2220
- }, {});
2226
+ if (Array.isArray(obj)) {
2227
+ return obj.map(deepDropNulls);
2228
+ }
2229
+ if (obj !== null && typeof obj === "object") {
2230
+ return Object.entries(obj).reduce((acc, [key, value]) => {
2231
+ const cleanedValue = deepDropNulls(value);
2232
+ if (cleanedValue !== null) {
2233
+ ;
2234
+ acc[key] = cleanedValue;
2235
+ }
2236
+ return acc;
2237
+ }, {});
2238
+ }
2239
+ return obj;
2221
2240
  }
2222
2241
  function isUndeclaredDraft(status) {
2223
2242
  return status === EventStatus.CREATED;
2224
2243
  }
2225
2244
  function getAcceptedActions(event2) {
2226
2245
  return event2.actions.filter(
2227
- (a) => !a.status || a.status === ActionStatus.Accepted
2246
+ (a) => a.status === ActionStatus.Accepted
2228
2247
  );
2229
2248
  }
2230
2249
  function getCurrentEventState(event2) {
@@ -2250,9 +2269,11 @@ function getCurrentEventState(event2) {
2250
2269
  modifiedAt: latestAction.createdAt,
2251
2270
  assignedTo: getAssignedUserFromActions(activeActions),
2252
2271
  updatedBy: latestAction.createdBy,
2272
+ updatedAtLocation: event2.updatedAtLocation,
2253
2273
  declaration: aggregateActionDeclarations(activeActions),
2254
2274
  trackingId: event2.trackingId,
2255
- registrationNumber
2275
+ registrationNumber,
2276
+ updatedByUserRole: getLastUpdatedByUserRoleFromActions(event2.actions)
2256
2277
  });
2257
2278
  }
2258
2279
  function getCurrentEventStateWithDrafts(event2, drafts) {
@@ -2290,27 +2311,35 @@ function applyDraftsToEventIndex(eventIndex, drafts) {
2290
2311
  }
2291
2312
  };
2292
2313
  }
2314
+ function getAnnotationFromDrafts(drafts) {
2315
+ const actions = drafts.map((draft) => draft.action);
2316
+ const annotation = actions.reduce((ann, action) => {
2317
+ return deepMerge(ann, action.annotation ?? {});
2318
+ }, {});
2319
+ return deepDropNulls(annotation);
2320
+ }
2293
2321
  function getActionAnnotation({
2294
2322
  event: event2,
2295
2323
  actionType,
2296
- drafts
2324
+ drafts = []
2297
2325
  }) {
2298
2326
  const activeActions = getAcceptedActions(event2);
2299
- const action = activeActions.find((action2) => actionType === action2.type);
2327
+ const action = activeActions.find(
2328
+ (activeAction) => actionType === activeAction.type
2329
+ );
2300
2330
  const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
2301
2331
  const sorted = [
2302
2332
  ...action ? [action] : [],
2303
2333
  ...eventDrafts.map((draft) => draft.action)
2304
2334
  ].sort();
2305
- const annotation = sorted.reduce((annotation2, action2) => {
2306
- return deepMerge(annotation2, action2.annotation ?? {});
2335
+ const annotation = sorted.reduce((ann, sortedAction) => {
2336
+ return deepMerge(ann, sortedAction.annotation ?? {});
2307
2337
  }, {});
2308
2338
  return deepDropNulls(annotation);
2309
2339
  }
2310
2340
 
2311
2341
  // ../commons/src/events/defineConfig.ts
2312
2342
  var defineConfig = (config) => {
2313
- validateWorkqueueConfig(config.workqueues);
2314
2343
  const input = EventConfig.parse(config);
2315
2344
  return input;
2316
2345
  };
@@ -2327,6 +2356,16 @@ var import_lodash2 = require("lodash");
2327
2356
  function defineConditional(schema) {
2328
2357
  return schema;
2329
2358
  }
2359
+ function defineFormConditional(schema) {
2360
+ const schemaWithForm = {
2361
+ type: "object",
2362
+ properties: {
2363
+ $form: schema
2364
+ },
2365
+ required: ["$form"]
2366
+ };
2367
+ return defineConditional(schemaWithForm);
2368
+ }
2330
2369
  function alwaysTrue() {
2331
2370
  return {};
2332
2371
  }
@@ -2351,6 +2390,9 @@ function not(condition) {
2351
2390
  required: []
2352
2391
  });
2353
2392
  }
2393
+ function never() {
2394
+ return not(alwaysTrue());
2395
+ }
2354
2396
  var user = {
2355
2397
  hasScope: (scope) => defineConditional({
2356
2398
  type: "object",
@@ -2398,100 +2440,118 @@ var event = {
2398
2440
  required: ["$event"]
2399
2441
  })
2400
2442
  };
2443
+ function getDateFromNow(days) {
2444
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2445
+ }
2446
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2447
+ return {
2448
+ type: "object",
2449
+ properties: {
2450
+ [fieldId]: {
2451
+ type: "string",
2452
+ format: "date",
2453
+ [clause]: { $data: `1/${comparedFieldId}` }
2454
+ },
2455
+ [comparedFieldId]: { type: "string", format: "date" }
2456
+ },
2457
+ required: [fieldId]
2458
+ };
2459
+ }
2460
+ function isFieldReference(value) {
2461
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2462
+ }
2401
2463
  function field(fieldId) {
2402
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2403
2464
  const getDateRange = (date, clause) => ({
2404
2465
  type: "object",
2405
2466
  properties: {
2406
- $form: {
2407
- type: "object",
2408
- properties: {
2409
- [fieldId]: {
2410
- type: "string",
2411
- format: "date",
2412
- [clause]: date
2413
- }
2414
- },
2415
- required: [fieldId]
2467
+ [fieldId]: {
2468
+ type: "string",
2469
+ format: "date",
2470
+ [clause]: date
2416
2471
  }
2417
2472
  },
2418
- required: ["$form"]
2473
+ required: [fieldId]
2419
2474
  });
2420
2475
  return {
2421
2476
  /**
2422
2477
  * @private Internal property used for field reference tracking.
2423
2478
  */
2424
- _returning: fieldId,
2479
+ _fieldId: fieldId,
2425
2480
  isAfter: () => ({
2426
2481
  days: (days) => ({
2427
- inPast: () => defineConditional(
2482
+ inPast: () => defineFormConditional(
2428
2483
  getDateRange(getDateFromNow(days), "formatMinimum")
2429
2484
  ),
2430
- inFuture: () => defineConditional(
2485
+ inFuture: () => defineFormConditional(
2431
2486
  getDateRange(getDateFromNow(-days), "formatMinimum")
2432
2487
  )
2433
2488
  }),
2434
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
2435
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2489
+ date: (date) => {
2490
+ if (isFieldReference(date)) {
2491
+ const comparedFieldId = date._fieldId;
2492
+ return defineFormConditional(
2493
+ getDateRangeToFieldReference(
2494
+ fieldId,
2495
+ comparedFieldId,
2496
+ "formatMinimum"
2497
+ )
2498
+ );
2499
+ }
2500
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2501
+ },
2502
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2436
2503
  }),
2437
2504
  isBefore: () => ({
2438
2505
  days: (days) => ({
2439
- inPast: () => defineConditional(
2506
+ inPast: () => defineFormConditional(
2440
2507
  getDateRange(getDateFromNow(days), "formatMaximum")
2441
2508
  ),
2442
- inFuture: () => defineConditional(
2509
+ inFuture: () => defineFormConditional(
2443
2510
  getDateRange(getDateFromNow(-days), "formatMaximum")
2444
2511
  )
2445
2512
  }),
2446
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
2447
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2513
+ date: (date) => {
2514
+ if (isFieldReference(date)) {
2515
+ const comparedFieldId = date._fieldId;
2516
+ return defineFormConditional(
2517
+ getDateRangeToFieldReference(
2518
+ fieldId,
2519
+ comparedFieldId,
2520
+ "formatMaximum"
2521
+ )
2522
+ );
2523
+ }
2524
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2525
+ },
2526
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2448
2527
  }),
2449
- // TODO CIHAN: typing
2450
2528
  isEqualTo: (value) => {
2451
- if (typeof value === "object" && value._returning) {
2452
- const comparedFieldId = value._returning;
2453
- return defineConditional({
2529
+ if (isFieldReference(value)) {
2530
+ const comparedFieldId = value._fieldId;
2531
+ return defineFormConditional({
2454
2532
  type: "object",
2455
2533
  properties: {
2456
- $form: {
2457
- type: "object",
2458
- properties: {
2459
- [fieldId]: { type: ["string", "boolean"] },
2460
- [comparedFieldId]: { type: ["string", "boolean"] }
2461
- },
2462
- required: [fieldId, comparedFieldId],
2463
- allOf: [
2464
- {
2465
- properties: {
2466
- [fieldId]: {
2467
- const: { $data: `1/${comparedFieldId}` }
2468
- }
2469
- }
2470
- }
2471
- ]
2472
- }
2534
+ [fieldId]: {
2535
+ type: ["string", "boolean"],
2536
+ const: { $data: `1/${comparedFieldId}` }
2537
+ },
2538
+ [comparedFieldId]: { type: ["string", "boolean"] }
2473
2539
  },
2474
- required: ["$form"]
2540
+ required: [fieldId, comparedFieldId]
2475
2541
  });
2476
2542
  }
2477
- return defineConditional({
2543
+ return defineFormConditional({
2478
2544
  type: "object",
2479
2545
  properties: {
2480
- $form: {
2481
- type: "object",
2482
- properties: {
2483
- [fieldId]: {
2484
- oneOf: [
2485
- { type: "string", const: value },
2486
- { type: "boolean", const: value }
2487
- ],
2488
- const: value
2489
- }
2490
- },
2491
- required: [fieldId]
2546
+ [fieldId]: {
2547
+ oneOf: [
2548
+ { type: "string", const: value },
2549
+ { type: "boolean", const: value }
2550
+ ],
2551
+ const: value
2492
2552
  }
2493
2553
  },
2494
- required: ["$form"]
2554
+ required: [fieldId]
2495
2555
  });
2496
2556
  },
2497
2557
  /**
@@ -2502,140 +2562,87 @@ function field(fieldId) {
2502
2562
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2503
2563
  *
2504
2564
  */
2505
- isFalsy: () => defineConditional({
2565
+ isFalsy: () => defineFormConditional({
2506
2566
  type: "object",
2507
2567
  properties: {
2508
- $form: {
2509
- type: "object",
2510
- properties: {
2511
- [fieldId]: {
2512
- anyOf: [
2513
- { const: "undefined" },
2514
- { const: false },
2515
- { const: null },
2516
- { const: "" }
2517
- ]
2518
- }
2519
- },
2568
+ [fieldId]: {
2520
2569
  anyOf: [
2521
- {
2522
- required: [fieldId]
2523
- },
2524
- {
2525
- not: {
2526
- required: [fieldId]
2527
- }
2528
- }
2570
+ { const: "undefined" },
2571
+ { const: false },
2572
+ { const: null },
2573
+ { const: "" }
2529
2574
  ]
2530
2575
  }
2531
2576
  },
2532
- required: ["$form"]
2533
- }),
2534
- isUndefined: () => defineConditional({
2535
- type: "object",
2536
- properties: {
2537
- $form: {
2538
- type: "object",
2539
- properties: {
2540
- [fieldId]: {
2541
- type: "string",
2542
- enum: ["undefined"]
2543
- }
2544
- },
2577
+ anyOf: [
2578
+ {
2579
+ required: [fieldId]
2580
+ },
2581
+ {
2545
2582
  not: {
2546
2583
  required: [fieldId]
2547
2584
  }
2548
2585
  }
2549
- },
2550
- required: ["$form"]
2586
+ ]
2551
2587
  }),
2552
- inArray: (values) => defineConditional({
2588
+ isUndefined: () => defineFormConditional({
2553
2589
  type: "object",
2554
2590
  properties: {
2555
- $form: {
2556
- type: "object",
2557
- properties: {
2558
- [fieldId]: {
2559
- type: "string",
2560
- enum: values
2561
- }
2562
- },
2563
- required: [fieldId]
2591
+ [fieldId]: {
2592
+ type: "string",
2593
+ enum: ["undefined"]
2564
2594
  }
2565
2595
  },
2566
- required: ["$form"]
2596
+ not: {
2597
+ required: [fieldId]
2598
+ }
2567
2599
  }),
2568
- isValidEnglishName: () => defineConditional({
2600
+ inArray: (values) => defineFormConditional({
2569
2601
  type: "object",
2570
2602
  properties: {
2571
- $form: {
2572
- type: "object",
2573
- properties: {
2574
- [fieldId]: {
2575
- type: "string",
2576
- 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'._-]*)*$",
2577
- description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2578
- }
2579
- },
2580
- required: [fieldId]
2603
+ [fieldId]: {
2604
+ type: "string",
2605
+ enum: values
2581
2606
  }
2582
2607
  },
2583
- required: ["$form"]
2608
+ required: [fieldId]
2584
2609
  }),
2585
- isValidNationalId: () => defineConditional({
2610
+ isValidEnglishName: () => defineFormConditional({
2586
2611
  type: "object",
2587
2612
  properties: {
2588
- $form: {
2589
- type: "object",
2590
- properties: {
2591
- [fieldId]: {
2592
- type: "string",
2593
- pattern: "^[0-9]{9}$",
2594
- description: "The National ID can only be numeric and must be 9 digits long."
2595
- }
2596
- },
2597
- required: [fieldId]
2613
+ [fieldId]: {
2614
+ type: "string",
2615
+ 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'._-]*)*$",
2616
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2598
2617
  }
2599
2618
  },
2600
- required: ["$form"]
2619
+ required: [fieldId]
2601
2620
  }),
2602
2621
  /**
2603
2622
  * Checks if the field value matches a given regular expression pattern.
2604
2623
  * @param pattern - The regular expression pattern to match the field value against.
2605
2624
  * @returns A JSONSchema conditional that validates the field value against the pattern.
2606
2625
  */
2607
- matches: (pattern) => defineConditional({
2626
+ matches: (pattern) => defineFormConditional({
2608
2627
  type: "object",
2609
2628
  properties: {
2610
- $form: {
2611
- type: "object",
2612
- properties: {
2613
- [fieldId]: {
2614
- type: "string",
2615
- pattern
2616
- }
2617
- },
2618
- required: [fieldId]
2629
+ [fieldId]: {
2630
+ type: "string",
2631
+ pattern
2619
2632
  }
2620
2633
  },
2621
- required: ["$form"]
2634
+ required: [fieldId]
2622
2635
  }),
2623
- isBetween: (min, max) => defineConditional({
2636
+ isBetween: (min, max) => defineFormConditional({
2624
2637
  type: "object",
2625
2638
  properties: {
2626
- $form: {
2627
- type: "object",
2628
- properties: {
2629
- [fieldId]: {
2630
- type: "number",
2631
- minimum: min,
2632
- maximum: max
2633
- }
2634
- },
2635
- required: [fieldId]
2639
+ [fieldId]: {
2640
+ type: "number",
2641
+ minimum: min,
2642
+ maximum: max
2636
2643
  }
2637
2644
  },
2638
- required: ["$form"]
2645
+ required: [fieldId]
2639
2646
  })
2640
2647
  };
2641
2648
  }
@@ -3378,9 +3385,8 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3378
3385
  },
3379
3386
  {
3380
3387
  id: "applicant.dob",
3381
- type: "DATE",
3388
+ type: FieldType.DATE,
3382
3389
  required: true,
3383
- conditionals: [],
3384
3390
  validation: [
3385
3391
  {
3386
3392
  message: {
@@ -3391,12 +3397,50 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3391
3397
  validator: field("applicant.dob").isBefore().now()
3392
3398
  }
3393
3399
  ],
3400
+ conditionals: [
3401
+ {
3402
+ type: ConditionalType.SHOW,
3403
+ conditional: field("applicant.dobUnknown").isFalsy()
3404
+ }
3405
+ ],
3394
3406
  label: {
3395
3407
  defaultMessage: "Applicant's date of birth",
3396
3408
  description: "This is the label for the field",
3397
3409
  id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dob.label"
3398
3410
  }
3399
3411
  },
3412
+ {
3413
+ id: "applicant.dobUnknown",
3414
+ type: FieldType.CHECKBOX,
3415
+ required: false,
3416
+ label: {
3417
+ defaultMessage: "Exact date of birth unknown",
3418
+ description: "This is the label for the field",
3419
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dobUnknown.label"
3420
+ },
3421
+ conditionals: [
3422
+ {
3423
+ type: ConditionalType.DISPLAY_ON_REVIEW,
3424
+ conditional: never()
3425
+ }
3426
+ ]
3427
+ },
3428
+ {
3429
+ id: "applicant.age",
3430
+ type: FieldType.NUMBER,
3431
+ required: true,
3432
+ label: {
3433
+ defaultMessage: "Age of tennis-member",
3434
+ description: "This is the label for the field",
3435
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.age.label"
3436
+ },
3437
+ conditionals: [
3438
+ {
3439
+ type: ConditionalType.SHOW,
3440
+ conditional: field("applicant.dobUnknown").isEqualTo(true)
3441
+ }
3442
+ ]
3443
+ },
3400
3444
  {
3401
3445
  id: "applicant.image",
3402
3446
  type: FieldType.FILE,
@@ -3572,28 +3616,6 @@ var tennisClubMembershipEvent = defineConfig({
3572
3616
  }
3573
3617
  ]
3574
3618
  },
3575
- workqueues: [
3576
- {
3577
- id: "all",
3578
- filters: []
3579
- },
3580
- {
3581
- id: "ready-for-review",
3582
- filters: [
3583
- {
3584
- status: ["DECLARED"]
3585
- }
3586
- ]
3587
- },
3588
- {
3589
- id: "registered",
3590
- filters: [
3591
- {
3592
- status: ["REGISTERED"]
3593
- }
3594
- ]
3595
- }
3596
- ],
3597
3619
  actions: [
3598
3620
  {
3599
3621
  type: ActionType.DECLARE,
@@ -3912,7 +3934,7 @@ var tennisClubMembershipEvent = defineConfig({
3912
3934
  });
3913
3935
 
3914
3936
  // ../commons/src/events/test.utils.ts
3915
- function fieldConfigsToActionAnnotation(fields) {
3937
+ function fieldConfigsToActionPayload(fields) {
3916
3938
  return fields.reduce(
3917
3939
  (acc, field2, i) => ({
3918
3940
  ...acc,
@@ -3921,23 +3943,27 @@ function fieldConfigsToActionAnnotation(fields) {
3921
3943
  {}
3922
3944
  );
3923
3945
  }
3924
- function generateActionInput(configuration, action) {
3946
+ function generateActionDeclarationInput(configuration, action) {
3925
3947
  const parsed = DeclarationUpdateActions.safeParse(action);
3926
3948
  if (parsed.success) {
3927
3949
  const fields = getDeclarationFields(configuration);
3928
- const annotation = fieldConfigsToActionAnnotation(fields);
3929
- return stripHiddenFields(fields, annotation);
3950
+ const declarationConfig = getDeclaration(configuration);
3951
+ const declaration = fieldConfigsToActionPayload(fields);
3952
+ return omitHiddenPaginatedFields(declarationConfig, declaration);
3930
3953
  }
3931
3954
  console.warn(`${action} is not a declaration action. Setting data as {}.`);
3932
3955
  return {};
3933
3956
  }
3934
- function generateActionMetadataInput(configuration, action) {
3957
+ function generateActionAnnotationInput(configuration, action) {
3935
3958
  const actionConfig = configuration.actions.find(
3936
- (actionConfig2) => actionConfig2.type === action
3959
+ (ac) => ac.type === action
3937
3960
  );
3938
3961
  const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
3939
- const annotation = fieldConfigsToActionAnnotation(annotationFields);
3940
- const visibleVerificationPageIds = (findRecordActionPages(configuration, action) ?? []).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id) ?? [];
3962
+ const annotation = fieldConfigsToActionPayload(annotationFields);
3963
+ const visibleVerificationPageIds = findRecordActionPages(
3964
+ configuration,
3965
+ action
3966
+ ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
3941
3967
  const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
3942
3968
  (acc, pageId) => ({
3943
3969
  ...acc,
@@ -3945,7 +3971,7 @@ function generateActionMetadataInput(configuration, action) {
3945
3971
  }),
3946
3972
  {}
3947
3973
  );
3948
- const fieldBasedPayload = stripHiddenFields(annotationFields, annotation);
3974
+ const fieldBasedPayload = omitHiddenFields(annotationFields, annotation);
3949
3975
  return {
3950
3976
  ...fieldBasedPayload,
3951
3977
  ...visiblePageVerificationMap
@@ -3961,14 +3987,16 @@ var eventPayloadGenerator = {
3961
3987
  type: input.type ?? "TENNIS_CLUB_MEMBERSHIP",
3962
3988
  id
3963
3989
  }),
3964
- draft: (eventId, input = {}) => (0, import_lodash2.merge)(
3990
+ draft: ({ eventId, actionType }, input = {}) => (0, import_lodash2.merge)(
3965
3991
  {
3966
3992
  id: getUUID(),
3967
3993
  eventId,
3968
3994
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3969
3995
  transactionId: getUUID(),
3970
3996
  action: {
3971
- type: ActionType.REQUEST_CORRECTION,
3997
+ transactionId: getUUID(),
3998
+ type: actionType,
3999
+ status: ActionStatus.Accepted,
3972
4000
  declaration: {
3973
4001
  "applicant.firstname": "Max",
3974
4002
  "applicant.surname": "McLaren",
@@ -3981,6 +4009,7 @@ var eventPayloadGenerator = {
3981
4009
  },
3982
4010
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3983
4011
  createdBy: "@todo",
4012
+ createdByRole: "@todo",
3984
4013
  createdAtLocation: "@todo"
3985
4014
  }
3986
4015
  },
@@ -3990,8 +4019,11 @@ var eventPayloadGenerator = {
3990
4019
  declare: (eventId, input = {}) => ({
3991
4020
  type: ActionType.DECLARE,
3992
4021
  transactionId: input.transactionId ?? getUUID(),
3993
- declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
3994
- annotation: input.annotation ?? generateActionMetadataInput(
4022
+ declaration: input.declaration ?? generateActionDeclarationInput(
4023
+ tennisClubMembershipEvent,
4024
+ ActionType.DECLARE
4025
+ ),
4026
+ annotation: input.annotation ?? generateActionAnnotationInput(
3995
4027
  tennisClubMembershipEvent,
3996
4028
  ActionType.DECLARE
3997
4029
  ),
@@ -4004,7 +4036,10 @@ var eventPayloadGenerator = {
4004
4036
  let declaration = input.declaration;
4005
4037
  if (!declaration) {
4006
4038
  const partialDeclaration = (0, import_lodash2.omitBy)(
4007
- generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4039
+ generateActionDeclarationInput(
4040
+ tennisClubMembershipEvent,
4041
+ ActionType.DECLARE
4042
+ ),
4008
4043
  import_lodash2.isString
4009
4044
  );
4010
4045
  declaration = partialDeclaration;
@@ -4019,14 +4054,31 @@ var eventPayloadGenerator = {
4019
4054
  validate: (eventId, input = {}) => ({
4020
4055
  type: ActionType.VALIDATE,
4021
4056
  transactionId: input.transactionId ?? getUUID(),
4022
- declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4023
- annotation: input.annotation ?? generateActionMetadataInput(
4057
+ declaration: input.declaration ?? generateActionDeclarationInput(
4058
+ tennisClubMembershipEvent,
4059
+ ActionType.VALIDATE
4060
+ ),
4061
+ annotation: input.annotation ?? generateActionAnnotationInput(
4024
4062
  tennisClubMembershipEvent,
4025
4063
  ActionType.VALIDATE
4026
4064
  ),
4027
4065
  duplicates: [],
4028
4066
  eventId
4029
4067
  }),
4068
+ assign: (eventId, input = {}) => ({
4069
+ type: ActionType.ASSIGN,
4070
+ transactionId: input.transactionId ?? getUUID(),
4071
+ declaration: {},
4072
+ assignedTo: input.assignedTo ?? getUUID(),
4073
+ eventId
4074
+ }),
4075
+ unassign: (eventId, input = {}) => ({
4076
+ type: ActionType.UNASSIGN,
4077
+ transactionId: input.transactionId ?? getUUID(),
4078
+ declaration: {},
4079
+ assignedTo: null,
4080
+ eventId
4081
+ }),
4030
4082
  archive: (eventId, input = {}, isDuplicate) => ({
4031
4083
  type: ActionType.ARCHIVE,
4032
4084
  transactionId: input.transactionId ?? getUUID(),
@@ -4040,7 +4092,7 @@ var eventPayloadGenerator = {
4040
4092
  type: ActionType.REJECT,
4041
4093
  transactionId: input.transactionId ?? getUUID(),
4042
4094
  declaration: {},
4043
- annotation: input.annotation ?? generateActionMetadataInput(
4095
+ annotation: input.annotation ?? generateActionAnnotationInput(
4044
4096
  tennisClubMembershipEvent,
4045
4097
  ActionType.REJECT
4046
4098
  ),
@@ -4050,8 +4102,11 @@ var eventPayloadGenerator = {
4050
4102
  register: (eventId, input = {}) => ({
4051
4103
  type: ActionType.REGISTER,
4052
4104
  transactionId: input.transactionId ?? getUUID(),
4053
- declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4054
- annotation: input.annotation ?? generateActionMetadataInput(
4105
+ declaration: input.declaration ?? generateActionDeclarationInput(
4106
+ tennisClubMembershipEvent,
4107
+ ActionType.REGISTER
4108
+ ),
4109
+ annotation: input.annotation ?? generateActionAnnotationInput(
4055
4110
  tennisClubMembershipEvent,
4056
4111
  ActionType.REGISTER
4057
4112
  ),
@@ -4061,7 +4116,7 @@ var eventPayloadGenerator = {
4061
4116
  type: ActionType.PRINT_CERTIFICATE,
4062
4117
  transactionId: input.transactionId ?? getUUID(),
4063
4118
  declaration: {},
4064
- annotation: input.annotation ?? generateActionMetadataInput(
4119
+ annotation: input.annotation ?? generateActionAnnotationInput(
4065
4120
  tennisClubMembershipEvent,
4066
4121
  ActionType.PRINT_CERTIFICATE
4067
4122
  ),
@@ -4071,11 +4126,11 @@ var eventPayloadGenerator = {
4071
4126
  request: (eventId, input = {}) => ({
4072
4127
  type: ActionType.REQUEST_CORRECTION,
4073
4128
  transactionId: input.transactionId ?? getUUID(),
4074
- declaration: input.declaration ?? generateActionInput(
4129
+ declaration: input.declaration ?? generateActionDeclarationInput(
4075
4130
  tennisClubMembershipEvent,
4076
4131
  ActionType.REQUEST_CORRECTION
4077
4132
  ),
4078
- annotation: input.annotation ?? generateActionMetadataInput(
4133
+ annotation: input.annotation ?? generateActionAnnotationInput(
4079
4134
  tennisClubMembershipEvent,
4080
4135
  ActionType.REQUEST_CORRECTION
4081
4136
  ),
@@ -4085,7 +4140,7 @@ var eventPayloadGenerator = {
4085
4140
  type: ActionType.APPROVE_CORRECTION,
4086
4141
  transactionId: input.transactionId ?? getUUID(),
4087
4142
  declaration: {},
4088
- annotation: input.annotation ?? generateActionMetadataInput(
4143
+ annotation: input.annotation ?? generateActionAnnotationInput(
4089
4144
  tennisClubMembershipEvent,
4090
4145
  ActionType.APPROVE_CORRECTION
4091
4146
  ),
@@ -4096,7 +4151,7 @@ var eventPayloadGenerator = {
4096
4151
  type: ActionType.REJECT_CORRECTION,
4097
4152
  transactionId: input.transactionId ?? getUUID(),
4098
4153
  declaration: {},
4099
- annotation: input.annotation ?? generateActionMetadataInput(
4154
+ annotation: input.annotation ?? generateActionAnnotationInput(
4100
4155
  tennisClubMembershipEvent,
4101
4156
  ActionType.REJECT_CORRECTION
4102
4157
  ),
@@ -4116,18 +4171,24 @@ function generateActionDocument({
4116
4171
  // @TODO: This should be fixed in the future.
4117
4172
  createdAt: new Date(Date.now() - 500).toISOString(),
4118
4173
  createdBy: getUUID(),
4174
+ createdByRole: "FIELD_AGENT",
4119
4175
  id: getUUID(),
4120
4176
  createdAtLocation: "TODO",
4121
- declaration: generateActionInput(configuration, action),
4177
+ declaration: generateActionDeclarationInput(configuration, action),
4122
4178
  annotation: {},
4123
4179
  ...defaults,
4124
- status: ActionStatus.Accepted
4180
+ status: ActionStatus.Accepted,
4181
+ transactionId: getUUID()
4125
4182
  };
4126
4183
  switch (action) {
4184
+ case ActionType.READ:
4185
+ return { ...actionBase, type: action };
4186
+ case ActionType.MARKED_AS_DUPLICATE:
4187
+ return { ...actionBase, type: action };
4127
4188
  case ActionType.DECLARE:
4128
4189
  return { ...actionBase, type: action };
4129
4190
  case ActionType.UNASSIGN:
4130
- return { ...actionBase, type: action };
4191
+ return { ...actionBase, type: action, assignedTo: null };
4131
4192
  case ActionType.ASSIGN:
4132
4193
  return { ...actionBase, assignedTo: getUUID(), type: action };
4133
4194
  case ActionType.VALIDATE:
@@ -4153,6 +4214,8 @@ function generateActionDocument({
4153
4214
  ...actionBase,
4154
4215
  type: action
4155
4216
  };
4217
+ case ActionType.DELETE:
4218
+ case ActionType.DETECT_DUPLICATE:
4156
4219
  default:
4157
4220
  throw new Error(`Unsupported action type: ${action}`);
4158
4221
  }
@@ -4173,7 +4236,8 @@ function generateEventDocument({
4173
4236
  id: getUUID(),
4174
4237
  // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4175
4238
  // @TODO: This should be fixed in the future.
4176
- updatedAt: new Date(Date.now() - 1e3).toISOString()
4239
+ updatedAt: new Date(Date.now() - 1e3).toISOString(),
4240
+ updatedAtLocation: "TODO"
4177
4241
  };
4178
4242
  }
4179
4243
  function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
@@ -4202,9 +4266,11 @@ var eventQueryDataGenerator = (overrides = {}) => ({
4202
4266
  createdAt: overrides.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4203
4267
  createdBy: overrides.createdBy ?? getUUID(),
4204
4268
  createdAtLocation: overrides.createdAtLocation ?? getUUID(),
4269
+ updatedAtLocation: overrides.updatedAtLocation ?? getUUID(),
4205
4270
  modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4206
4271
  assignedTo: overrides.assignedTo ?? null,
4207
4272
  updatedBy: overrides.updatedBy ?? getUUID(),
4273
+ updatedByUserRole: overrides.updatedByUserRole ?? "FIELD_AGENT",
4208
4274
  declaration: overrides.declaration ?? {
4209
4275
  "recommender.none": true,
4210
4276
  "applicant.firstname": "Danny",
@@ -4236,7 +4302,9 @@ function isFieldValueWithoutTemplates(value) {
4236
4302
  return true;
4237
4303
  }
4238
4304
  function isFieldConfigDefaultValue(value) {
4239
- if (!value) return false;
4305
+ if (!value) {
4306
+ return false;
4307
+ }
4240
4308
  if (isFieldValue(value)) {
4241
4309
  return true;
4242
4310
  }
@@ -4248,3 +4316,189 @@ function isFieldConfigDefaultValue(value) {
4248
4316
  }
4249
4317
  return false;
4250
4318
  }
4319
+
4320
+ // ../commons/src/events/scopes.ts
4321
+ var import_lodash3 = require("lodash");
4322
+
4323
+ // ../commons/src/scopes.ts
4324
+ var SCOPES = {
4325
+ // TODO v1.8 legacy scopes
4326
+ NATLSYSADMIN: "natlsysadmin",
4327
+ BYPASSRATELIMIT: "bypassratelimit",
4328
+ DECLARE: "declare",
4329
+ REGISTER: "register",
4330
+ VALIDATE: "validate",
4331
+ DEMO: "demo",
4332
+ CERTIFY: "certify",
4333
+ PERFORMANCE: "performance",
4334
+ SYSADMIN: "sysadmin",
4335
+ TEAMS: "teams",
4336
+ CONFIG: "config",
4337
+ // systems / integrations
4338
+ WEBHOOK: "webhook",
4339
+ NATIONALID: "nationalId",
4340
+ NOTIFICATION_API: "notification-api",
4341
+ RECORDSEARCH: "recordsearch",
4342
+ /**
4343
+ * @TODO This is a temporary scope to be used for V2 Events custom events declaration
4344
+ */
4345
+ RECORD_DECLARE: "record.declare-birth",
4346
+ // declare
4347
+ RECORD_DECLARE_BIRTH: "record.declare-birth",
4348
+ RECORD_DECLARE_BIRTH_MY_JURISDICTION: "record.declare-birth:my-jurisdiction",
4349
+ RECORD_DECLARE_DEATH: "record.declare-death",
4350
+ RECORD_DECLARE_DEATH_MY_JURISDICTION: "record.declare-death:my-jurisdiction",
4351
+ RECORD_DECLARE_MARRIAGE: "record.declare-marriage",
4352
+ RECORD_DECLARE_MARRIAGE_MY_JURISDICTION: "record.declare-marriage:my-jurisdiction",
4353
+ RECORD_SUBMIT_INCOMPLETE: "record.declaration-submit-incomplete",
4354
+ RECORD_SUBMIT_FOR_REVIEW: "record.declaration-submit-for-review",
4355
+ RECORD_UNASSIGN_OTHERS: "record.unassign-others",
4356
+ // validate
4357
+ RECORD_SUBMIT_FOR_APPROVAL: "record.declaration-submit-for-approval",
4358
+ RECORD_SUBMIT_FOR_UPDATES: "record.declaration-submit-for-updates",
4359
+ RECORD_DECLARATION_EDIT: "record.declaration-edit",
4360
+ RECORD_REVIEW_DUPLICATES: "record.review-duplicates",
4361
+ RECORD_DECLARATION_ARCHIVE: "record.declaration-archive",
4362
+ RECORD_DECLARATION_REINSTATE: "record.declaration-reinstate",
4363
+ // register
4364
+ RECORD_REGISTER: "record.register",
4365
+ // certify
4366
+ RECORD_EXPORT_RECORDS: "record.export-records",
4367
+ RECORD_DECLARATION_PRINT: "record.declaration-print",
4368
+ RECORD_PRINT_RECORDS_SUPPORTING_DOCUMENTS: "record.declaration-print-supporting-documents",
4369
+ RECORD_REGISTRATION_PRINT: "record.registration-print",
4370
+ // v1.8
4371
+ /**
4372
+ * This scope is used to **print and **issue certified copies of a record
4373
+ * after it has been registered. Previously Registrars had this permission.
4374
+ */
4375
+ RECORD_PRINT_ISSUE_CERTIFIED_COPIES: "record.registration-print&issue-certified-copies",
4376
+ RECORD_PRINT_CERTIFIED_COPIES: "record.registration-print-certified-copies",
4377
+ // v1.8
4378
+ RECORD_BULK_PRINT_CERTIFIED_COPIES: "record.registration-bulk-print-certified-copies",
4379
+ // v1.8
4380
+ RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES: "record.registration-verify-certified-copies",
4381
+ // v1.8
4382
+ // correct
4383
+ RECORD_REGISTRATION_REQUEST_CORRECTION: "record.registration-request-correction",
4384
+ RECORD_REGISTRATION_CORRECT: "record.registration-correct",
4385
+ RECORD_REGISTRATION_REQUEST_REVOCATION: "record.registration-request-revocation",
4386
+ // v1.8
4387
+ RECORD_REGISTRATION_REVOKE: "record.registration-revoke",
4388
+ // v1.8
4389
+ RECORD_REGISTRATION_REQUEST_REINSTATEMENT: "record.registration-request-reinstatement",
4390
+ // v1.8
4391
+ RECORD_REGISTRATION_REINSTATE: "record.registration-reinstate",
4392
+ // v1.8
4393
+ RECORD_CONFIRM_REGISTRATION: "record.confirm-registration",
4394
+ RECORD_REJECT_REGISTRATION: "record.reject-registration",
4395
+ // search
4396
+ SEARCH_BIRTH_MY_JURISDICTION: "search.birth:my-jurisdiction",
4397
+ SEARCH_BIRTH: "search.birth",
4398
+ SEARCH_DEATH_MY_JURISDICTION: "search.death:my-jurisdiction",
4399
+ SEARCH_DEATH: "search.death",
4400
+ SEARCH_MARRIAGE_MY_JURISDICTION: "search.marriage:my-jurisdiction",
4401
+ SEARCH_MARRIAGE: "search.marriage",
4402
+ // audit v1.8
4403
+ RECORD_READ: "record.read",
4404
+ RECORD_READ_AUDIT: "record.read-audit",
4405
+ RECORD_READ_COMMENTS: "record.read-comments",
4406
+ RECORD_CREATE_COMMENTS: "record.create-comments",
4407
+ // profile
4408
+ PROFILE_UPDATE: "profile.update",
4409
+ //v1.8
4410
+ PROFILE_ELECTRONIC_SIGNATURE: "profile.electronic-signature",
4411
+ // performance
4412
+ PERFORMANCE_READ: "performance.read",
4413
+ PERFORMANCE_READ_DASHBOARDS: "performance.read-dashboards",
4414
+ PERFORMANCE_EXPORT_VITAL_STATISTICS: "performance.vital-statistics-export",
4415
+ // organisation
4416
+ ORGANISATION_READ_LOCATIONS: "organisation.read-locations:all",
4417
+ ORGANISATION_READ_LOCATIONS_MY_OFFICE: "organisation.read-locations:my-office",
4418
+ ORGANISATION_READ_LOCATIONS_MY_JURISDICTION: "organisation.read-locations:my-jurisdiction",
4419
+ // user
4420
+ USER_READ: "user.read:all",
4421
+ USER_READ_MY_OFFICE: "user.read:my-office",
4422
+ USER_READ_MY_JURISDICTION: "user.read:my-jurisdiction",
4423
+ USER_READ_ONLY_MY_AUDIT: "user.read:only-my-audit",
4424
+ //v1.8
4425
+ USER_CREATE: "user.create:all",
4426
+ USER_CREATE_MY_JURISDICTION: "user.create:my-jurisdiction",
4427
+ USER_UPDATE: "user.update:all",
4428
+ USER_UPDATE_MY_JURISDICTION: "user.update:my-jurisdiction",
4429
+ // config
4430
+ CONFIG_UPDATE_ALL: "config.update:all",
4431
+ // data seeding
4432
+ USER_DATA_SEEDING: "user.data-seeding"
4433
+ };
4434
+ var scopes = Object.values(SCOPES);
4435
+
4436
+ // ../commons/src/events/scopes.ts
4437
+ function hasAnyOfScopes(a, b) {
4438
+ return (0, import_lodash3.intersection)(a, b).length > 0;
4439
+ }
4440
+ var CONFIG_GET_ALLOWED_SCOPES = [
4441
+ SCOPES.RECORD_DECLARE,
4442
+ SCOPES.RECORD_READ,
4443
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4444
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
4445
+ SCOPES.RECORD_REGISTER,
4446
+ SCOPES.RECORD_EXPORT_RECORDS,
4447
+ SCOPES.CONFIG,
4448
+ SCOPES.CONFIG_UPDATE_ALL
4449
+ ];
4450
+ var ACTION_ALLOWED_SCOPES = {
4451
+ [ActionType.READ]: [
4452
+ SCOPES.RECORD_DECLARE,
4453
+ SCOPES.RECORD_READ,
4454
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4455
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
4456
+ SCOPES.RECORD_REGISTER,
4457
+ SCOPES.RECORD_EXPORT_RECORDS
4458
+ ],
4459
+ [ActionType.CREATE]: [
4460
+ SCOPES.RECORD_DECLARE,
4461
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4462
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW
4463
+ ],
4464
+ [ActionType.NOTIFY]: [SCOPES.RECORD_SUBMIT_INCOMPLETE],
4465
+ [ActionType.DECLARE]: [
4466
+ SCOPES.RECORD_DECLARE,
4467
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
4468
+ SCOPES.RECORD_REGISTER
4469
+ ],
4470
+ [ActionType.DELETE]: [SCOPES.RECORD_DECLARE],
4471
+ [ActionType.VALIDATE]: [
4472
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
4473
+ SCOPES.RECORD_REGISTER
4474
+ ],
4475
+ [ActionType.REGISTER]: [SCOPES.RECORD_REGISTER],
4476
+ [ActionType.PRINT_CERTIFICATE]: [SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES],
4477
+ [ActionType.REQUEST_CORRECTION]: [
4478
+ SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION
4479
+ ],
4480
+ [ActionType.REJECT_CORRECTION]: [SCOPES.RECORD_REGISTRATION_CORRECT],
4481
+ [ActionType.APPROVE_CORRECTION]: [SCOPES.RECORD_REGISTRATION_CORRECT],
4482
+ [ActionType.MARKED_AS_DUPLICATE]: [SCOPES.RECORD_DECLARATION_ARCHIVE],
4483
+ [ActionType.ARCHIVE]: [SCOPES.RECORD_DECLARATION_ARCHIVE],
4484
+ [ActionType.REJECT]: [SCOPES.RECORD_SUBMIT_FOR_UPDATES],
4485
+ [ActionType.ASSIGN]: null,
4486
+ [ActionType.UNASSIGN]: null,
4487
+ [ActionType.DETECT_DUPLICATE]: []
4488
+ };
4489
+ function filterUnallowedActions(actions, userScopes) {
4490
+ const allowedActions = actions.filter((action) => {
4491
+ const requiredScopes = ACTION_ALLOWED_SCOPES[action];
4492
+ if (requiredScopes === null) {
4493
+ return true;
4494
+ }
4495
+ return hasAnyOfScopes(userScopes, requiredScopes);
4496
+ });
4497
+ const hasOtherAllowedActions = allowedActions.some(
4498
+ (action) => action !== ActionType.READ && action !== ActionType.ASSIGN && action !== ActionType.UNASSIGN
4499
+ );
4500
+ if (hasOtherAllowedActions) {
4501
+ return allowedActions;
4502
+ }
4503
+ return [ActionType.READ];
4504
+ }