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

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.
@@ -49,6 +49,7 @@ __export(events_exports, {
49
49
  AdvancedSearchConfig: () => AdvancedSearchConfig,
50
50
  ApproveCorrectionActionInput: () => ApproveCorrectionActionInput,
51
51
  ArchiveActionInput: () => ArchiveActionInput,
52
+ AssignActionInput: () => AssignActionInput,
52
53
  AsyncRejectActionDocument: () => AsyncRejectActionDocument,
53
54
  BaseActionInput: () => BaseActionInput,
54
55
  CertificateConfig: () => CertificateConfig,
@@ -68,12 +69,13 @@ __export(events_exports, {
68
69
  DeclarationUpdateActions: () => DeclarationUpdateActions,
69
70
  DeclareActionInput: () => DeclareActionInput,
70
71
  DeduplicationConfig: () => DeduplicationConfig,
72
+ DisplayOnReviewConditional: () => DisplayOnReviewConditional,
71
73
  Draft: () => Draft,
72
74
  DraftInput: () => DraftInput,
73
75
  EmailField: () => EmailField,
74
76
  EmailValue: () => EmailValue,
75
77
  EnableConditional: () => EnableConditional,
76
- EventConfig: () => EventConfig,
78
+ EventConfig: () => EventConfig2,
77
79
  EventDocument: () => EventDocument,
78
80
  EventIndex: () => EventIndex,
79
81
  EventInput: () => EventInput,
@@ -81,7 +83,9 @@ __export(events_exports, {
81
83
  EventSearchIndex: () => EventSearchIndex,
82
84
  EventStatus: () => EventStatus,
83
85
  EventStatuses: () => EventStatuses,
86
+ FieldConditional: () => FieldConditional,
84
87
  FieldConfig: () => FieldConfig,
88
+ FieldConfigSchema: () => FieldConfigSchema,
85
89
  FieldType: () => FieldType,
86
90
  FieldUpdateValue: () => FieldUpdateValue,
87
91
  FieldValue: () => FieldValue,
@@ -100,9 +104,10 @@ __export(events_exports, {
100
104
  NotifyActionInput: () => NotifyActionInput,
101
105
  NumberFieldValue: () => NumberFieldValue,
102
106
  PageConfig: () => PageConfig,
103
- PageConfigBase: () => PageConfigBase,
104
107
  PageTypes: () => PageTypes,
105
108
  PrintCertificateActionInput: () => PrintCertificateActionInput,
109
+ QueryInput: () => QueryInput,
110
+ QueryType: () => QueryType,
106
111
  ReadActionInput: () => ReadActionInput,
107
112
  RegisterAction: () => RegisterAction,
108
113
  RegisterActionInput: () => RegisterActionInput,
@@ -113,10 +118,12 @@ __export(events_exports, {
113
118
  ResolvedUser: () => ResolvedUser,
114
119
  RuralAddressUpdateValue: () => RuralAddressUpdateValue,
115
120
  RuralAddressValue: () => RuralAddressValue,
121
+ SelectOption: () => SelectOption,
116
122
  ShowConditional: () => ShowConditional,
117
123
  SummaryConfig: () => SummaryConfig,
118
124
  TextValue: () => TextValue,
119
125
  TranslationConfig: () => TranslationConfig,
126
+ UnassignActionInput: () => UnassignActionInput,
120
127
  UrbanAddressUpdateValue: () => UrbanAddressUpdateValue,
121
128
  UrbanAddressValue: () => UrbanAddressValue,
122
129
  ValidateActionInput: () => ValidateActionInput,
@@ -136,10 +143,12 @@ __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,
141
149
  errorMessages: () => errorMessages,
142
150
  event: () => event,
151
+ eventField: () => eventField,
143
152
  eventMetadataLabelMap: () => eventMetadataLabelMap,
144
153
  eventPayloadGenerator: () => eventPayloadGenerator,
145
154
  eventQueryDataGenerator: () => eventQueryDataGenerator,
@@ -147,11 +156,11 @@ __export(events_exports, {
147
156
  field: () => field,
148
157
  fieldTypes: () => fieldTypes,
149
158
  findActiveDrafts: () => findActiveDrafts,
150
- findAllFields: () => findAllFields,
159
+ findLastAssignmentAction: () => findLastAssignmentAction,
151
160
  findRecordActionPages: () => findRecordActionPages,
161
+ generateActionAnnotationInput: () => generateActionAnnotationInput,
162
+ generateActionDeclarationInput: () => generateActionDeclarationInput,
152
163
  generateActionDocument: () => generateActionDocument,
153
- generateActionInput: () => generateActionInput,
154
- generateActionMetadataInput: () => generateActionMetadataInput,
155
164
  generateEventDocument: () => generateEventDocument,
156
165
  generateEventDraftDocument: () => generateEventDraftDocument,
157
166
  generateTransactionId: () => generateTransactionId,
@@ -162,13 +171,13 @@ __export(events_exports, {
162
171
  getActionReview: () => getActionReview,
163
172
  getActionReviewFields: () => getActionReviewFields,
164
173
  getAllAnnotationFields: () => getAllAnnotationFields,
174
+ getAnnotationFromDrafts: () => getAnnotationFromDrafts,
165
175
  getCurrentEventState: () => getCurrentEventState,
166
176
  getCurrentEventStateWithDrafts: () => getCurrentEventStateWithDrafts,
167
177
  getDeclaration: () => getDeclaration,
168
178
  getDeclarationFields: () => getDeclarationFields,
169
179
  getDeclarationPages: () => getDeclarationPages,
170
180
  getFieldValidationErrors: () => getFieldValidationErrors,
171
- getVisiblePagesFormFields: () => getVisiblePagesFormFields,
172
181
  isAddressFieldType: () => isAddressFieldType,
173
182
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
174
183
  isBulletListFieldType: () => isBulletListFieldType,
@@ -180,6 +189,7 @@ __export(events_exports, {
180
189
  isEmailFieldType: () => isEmailFieldType,
181
190
  isFacilityFieldType: () => isFacilityFieldType,
182
191
  isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
192
+ isFieldDisplayedOnReview: () => isFieldDisplayedOnReview,
183
193
  isFieldEnabled: () => isFieldEnabled,
184
194
  isFieldValue: () => isFieldValue,
185
195
  isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
@@ -200,16 +210,20 @@ __export(events_exports, {
200
210
  isTextFieldType: () => isTextFieldType,
201
211
  isUndeclaredDraft: () => isUndeclaredDraft,
202
212
  isVerificationPage: () => isVerificationPage,
213
+ isWriteAction: () => isWriteAction,
203
214
  mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
204
215
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
205
216
  mapFieldTypeToZod: () => mapFieldTypeToZod,
217
+ never: () => never,
206
218
  not: () => not,
219
+ omitHiddenFields: () => omitHiddenFields,
220
+ omitHiddenPaginatedFields: () => omitHiddenPaginatedFields,
207
221
  or: () => or,
208
- stripHiddenFields: () => stripHiddenFields,
209
222
  user: () => user,
210
223
  validate: () => validate,
211
224
  validateFieldInput: () => validateFieldInput,
212
- validateWorkqueueConfig: () => validateWorkqueueConfig
225
+ validateWorkqueueConfig: () => validateWorkqueueConfig,
226
+ writeActions: () => writeActions
213
227
  });
214
228
  module.exports = __toCommonJS(events_exports);
215
229
 
@@ -218,29 +232,46 @@ var import_zod9 = require("zod");
218
232
 
219
233
  // ../commons/src/events/Conditional.ts
220
234
  var import_zod = require("zod");
221
- function Conditional() {
222
- return import_zod.z.custom((val) => typeof val === "object" && val !== null);
223
- }
235
+ var Conditional = import_zod.z.custom(
236
+ (val) => typeof val === "object" && val !== null
237
+ );
224
238
  var ConditionalType = {
225
- /** When 'SHOW' conditional is defined, the action is shown to the user only if the condition is met */
226
239
  SHOW: "SHOW",
227
- /** If 'ENABLE' conditional is defined, the action is enabled only if the condition is met */
228
- ENABLE: "ENABLE"
240
+ ENABLE: "ENABLE",
241
+ DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
229
242
  };
230
243
  var ShowConditional = import_zod.z.object({
231
244
  type: import_zod.z.literal(ConditionalType.SHOW),
232
- conditional: Conditional()
233
- });
245
+ conditional: Conditional
246
+ }).describe(
247
+ "If 'SHOW' conditional is defined, the component is shown to the user only if the condition is met"
248
+ );
234
249
  var EnableConditional = import_zod.z.object({
235
250
  type: import_zod.z.literal(ConditionalType.ENABLE),
236
- conditional: Conditional()
237
- });
251
+ conditional: Conditional
252
+ }).describe(
253
+ "If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
254
+ );
238
255
  var ActionConditional = import_zod.z.discriminatedUnion("type", [
239
256
  // Action can be shown / hidden
240
257
  ShowConditional,
241
258
  // Action can be shown to the user in the list but as disabled
242
259
  EnableConditional
243
260
  ]);
261
+ var DisplayOnReviewConditional = import_zod.z.object({
262
+ type: import_zod.z.literal(ConditionalType.DISPLAY_ON_REVIEW),
263
+ conditional: Conditional
264
+ }).describe(
265
+ "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."
266
+ );
267
+ var FieldConditional = import_zod.z.discriminatedUnion("type", [
268
+ // Field input can be shown / hidden
269
+ ShowConditional,
270
+ // Field input can be shown to the user but as disabled
271
+ EnableConditional,
272
+ // Field output can be shown / hidden on the review page
273
+ DisplayOnReviewConditional
274
+ ]);
244
275
 
245
276
  // ../commons/src/events/PageConfig.ts
246
277
  var import_zod6 = require("zod");
@@ -428,14 +459,14 @@ var BaseField = import_zod5.z.object({
428
459
  ]),
429
460
  DependencyExpression
430
461
  ]).optional(),
431
- conditionals: import_zod5.z.array(ActionConditional).default([]).optional(),
462
+ conditionals: import_zod5.z.array(FieldConditional).default([]).optional(),
432
463
  required: import_zod5.z.boolean().default(false).optional(),
433
464
  disabled: import_zod5.z.boolean().default(false).optional(),
434
465
  hidden: import_zod5.z.boolean().default(false).optional(),
435
466
  placeholder: TranslationConfig.optional(),
436
467
  validation: import_zod5.z.array(
437
468
  import_zod5.z.object({
438
- validator: Conditional(),
469
+ validator: Conditional,
439
470
  message: TranslationConfig
440
471
  })
441
472
  ).default([]).optional(),
@@ -668,6 +699,7 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
668
699
  EmailField,
669
700
  FileUploadWithOptions,
670
701
  DataField
702
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
671
703
  ]);
672
704
 
673
705
  // ../commons/src/events/PageConfig.ts
@@ -676,7 +708,7 @@ var PageConfigBase = import_zod6.z.object({
676
708
  id: import_zod6.z.string().describe("Unique identifier for the page"),
677
709
  title: TranslationConfig.describe("Header title of the page"),
678
710
  fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page"),
679
- conditional: Conditional().optional().describe(
711
+ conditional: Conditional.optional().describe(
680
712
  "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
681
713
  )
682
714
  });
@@ -772,6 +804,12 @@ var DeclarationUpdateActions = ActionTypes.extract(
772
804
  declarationUpdateActionValues
773
805
  );
774
806
  var annotationActions = ActionTypes.exclude(declarationActionValues);
807
+ var writeActions = ActionTypes.exclude([
808
+ ActionType.CREATE,
809
+ ActionType.READ,
810
+ ActionType.ASSIGN,
811
+ ActionType.UNASSIGN
812
+ ]);
775
813
 
776
814
  // ../commons/src/events/FormConfig.ts
777
815
  var import_zod8 = require("zod");
@@ -918,7 +956,7 @@ var LanguageConfig = import_zod11.z.object({
918
956
  });
919
957
 
920
958
  // ../commons/src/events/EventConfig.ts
921
- var import_zod20 = require("zod");
959
+ var import_zod17 = require("zod");
922
960
 
923
961
  // ../commons/src/events/DeduplicationConfig.ts
924
962
  var import_zod12 = require("zod");
@@ -965,10 +1003,12 @@ var DateDistanceMatcher = Matcher.extend({
965
1003
  });
966
1004
  var And = import_zod12.z.object({
967
1005
  type: import_zod12.z.literal("and"),
1006
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
968
1007
  clauses: import_zod12.z.lazy(() => Clause.array())
969
1008
  });
970
1009
  var Or = import_zod12.z.object({
971
1010
  type: import_zod12.z.literal("or"),
1011
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
972
1012
  clauses: import_zod12.z.lazy(() => Clause.array())
973
1013
  });
974
1014
  var Clause = import_zod12.z.lazy(
@@ -1031,7 +1071,8 @@ var EventMetadata = import_zod14.z.object({
1031
1071
  createdAt: import_zod14.z.string().datetime(),
1032
1072
  createdBy: import_zod14.z.string(),
1033
1073
  createdAtLocation: import_zod14.z.string(),
1034
- modifiedAt: import_zod14.z.string().datetime(),
1074
+ updatedAtLocation: import_zod14.z.string(),
1075
+ updatedAt: import_zod14.z.string().datetime(),
1035
1076
  assignedTo: import_zod14.z.string().nullish(),
1036
1077
  updatedBy: import_zod14.z.string(),
1037
1078
  trackingId: import_zod14.z.string(),
@@ -1053,6 +1094,11 @@ var eventMetadataLabelMap = {
1053
1094
  defaultMessage: "Location",
1054
1095
  description: "Created At Location"
1055
1096
  },
1097
+ "event.updatedAtLocation": {
1098
+ id: "event.updatedAtLocation.label",
1099
+ defaultMessage: "Location",
1100
+ description: "Updated At"
1101
+ },
1056
1102
  "event.createdBy": {
1057
1103
  id: "event.createdBy.label",
1058
1104
  defaultMessage: "Created By",
@@ -1063,7 +1109,7 @@ var eventMetadataLabelMap = {
1063
1109
  defaultMessage: "ID",
1064
1110
  description: "ID"
1065
1111
  },
1066
- "event.modifiedAt": {
1112
+ "event.updatedAt": {
1067
1113
  id: "event.modifiedAt.label",
1068
1114
  defaultMessage: "Updated",
1069
1115
  description: "Modified At"
@@ -1107,847 +1153,194 @@ var WorkqueueConfig = import_zod15.z.object({
1107
1153
 
1108
1154
  // ../commons/src/events/AdvancedSearchConfig.ts
1109
1155
  var import_zod16 = require("zod");
1156
+ var FieldType2 = import_zod16.z.enum(["FUZZY", "EXACT", "RANGE"]);
1157
+ var FieldConfigSchema = import_zod16.z.object({
1158
+ fieldId: import_zod16.z.string(),
1159
+ config: import_zod16.z.object({
1160
+ type: FieldType2.describe("Determines the type of field")
1161
+ }),
1162
+ options: import_zod16.z.array(SelectOption).optional()
1163
+ });
1110
1164
  var AdvancedSearchConfig = import_zod16.z.object({
1111
1165
  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")
1117
- }).optional().describe("Configuration options for the field")
1118
- })
1119
- ).optional().default([]).describe("Advanced search fields.")
1166
+ fields: import_zod16.z.array(FieldConfigSchema).optional().default([]).describe("Advanced search fields.")
1120
1167
  });
1121
1168
 
1122
- // ../commons/src/events/utils.ts
1169
+ // ../commons/src/utils.ts
1123
1170
  var import_lodash = require("lodash");
1124
-
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
- }
1171
+ function getOrThrow(x, message) {
1172
+ if (x === void 0 || x === null) {
1173
+ throw new Error(message);
1166
1174
  }
1175
+ return x;
1176
+ }
1177
+ var findAllFields = (config) => {
1178
+ return (0, import_lodash.flattenDeep)([
1179
+ ...getDeclarationFields(config),
1180
+ ...getAllAnnotationFields(config)
1181
+ ]);
1167
1182
  };
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);
1183
+ var metadataFields = ["trackingId", "status"];
1180
1184
 
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"]
1185
+ // ../commons/src/events/EventConfig.ts
1186
+ var EventConfig2 = import_zod17.z.object({
1187
+ id: import_zod17.z.string().describe(
1188
+ 'A machine-readable identifier for the event, e.g. "birth" or "death"'
1189
+ ),
1190
+ summary: SummaryConfig,
1191
+ label: TranslationConfig,
1192
+ actions: import_zod17.z.array(ActionConfig),
1193
+ declaration: DeclarationFormConfig,
1194
+ workqueues: import_zod17.z.array(WorkqueueConfig),
1195
+ deduplication: import_zod17.z.array(DeduplicationConfig).optional().default([]),
1196
+ advancedSearch: import_zod17.z.array(AdvancedSearchConfig).optional().default([])
1197
+ }).superRefine((event2, ctx) => {
1198
+ const allFields = findAllFields(event2);
1199
+ const fieldIds = allFields.map((field2) => field2.id);
1200
+ const advancedSearchFields = event2.advancedSearch.flatMap(
1201
+ (section) => section.fields.flatMap((field2) => field2.fieldId)
1202
+ );
1203
+ const advancedSearchFieldsSet = new Set(advancedSearchFields);
1204
+ if (advancedSearchFieldsSet.size !== advancedSearchFields.length) {
1205
+ ctx.addIssue({
1206
+ code: "custom",
1207
+ message: "Advanced search field ids must be unique",
1208
+ path: ["advancedSearch"]
1209
+ });
1210
+ }
1211
+ const invalidFields = event2.advancedSearch.flatMap(
1212
+ (section) => (
1213
+ // Check if the fieldId is not in the fieldIds array
1214
+ // and also not in the metadataFields array
1215
+ section.fields.filter(
1216
+ (field2) => !(fieldIds.includes(field2.fieldId) || Boolean(metadataFields.find((f) => f === field2.fieldId)))
1217
+ )
1218
+ )
1219
+ );
1220
+ if (invalidFields.length > 0) {
1221
+ ctx.addIssue({
1222
+ code: "custom",
1223
+ message: `Advanced search id must match a field id of form fields or pre-defined metadata fields.
1224
+ Invalid AdvancedSearch field IDs for event ${event2.id}: ${invalidFields.map((f) => f.fieldId).join(", ")}`,
1225
+ path: ["advancedSearch"]
1226
+ });
1227
+ }
1200
1228
  });
1201
1229
 
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
- });
1230
+ // ../commons/src/events/EventConfigInput.ts
1231
+ var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
1232
+ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1233
+ var definePage = (page) => PageConfig.parse(page);
1234
+ var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1222
1235
 
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
- });
1236
+ // ../commons/src/events/Draft.ts
1237
+ var import_zod20 = require("zod");
1243
1238
 
1244
- // ../commons/src/workqueues/index.ts
1245
- var workqueues = {
1246
- all: allWorkqueue,
1247
- registered: registeredWorkqueue,
1248
- inReview: inReviewWorkqueue
1239
+ // ../commons/src/events/ActionDocument.ts
1240
+ var import_zod18 = require("zod");
1241
+ var ActionUpdate = import_zod18.z.record(import_zod18.z.string(), FieldUpdateValue);
1242
+ var ActionStatus = {
1243
+ Requested: "Requested",
1244
+ Accepted: "Accepted",
1245
+ Rejected: "Rejected"
1249
1246
  };
1250
-
1251
- // ../commons/src/conditionals/validate.ts
1252
- var import_ajv = __toESM(require("ajv"));
1253
- var import_ajv_formats = __toESM(require("ajv-formats"));
1254
- var import_date_fns = require("date-fns");
1255
-
1256
- // ../commons/src/events/FieldTypeMapping.ts
1257
- var import_zod19 = require("zod");
1258
- function mapFieldTypeToZod(type, required) {
1259
- let schema;
1260
- switch (type) {
1261
- case FieldType.DATE:
1262
- schema = DateValue;
1263
- break;
1264
- case FieldType.EMAIL:
1265
- schema = EmailValue;
1266
- break;
1267
- case FieldType.TEXT:
1268
- case FieldType.TEXTAREA:
1269
- case FieldType.DIVIDER:
1270
- case FieldType.BULLET_LIST:
1271
- case FieldType.PAGE_HEADER:
1272
- case FieldType.LOCATION:
1273
- case FieldType.SELECT:
1274
- case FieldType.COUNTRY:
1275
- case FieldType.RADIO_GROUP:
1276
- case FieldType.PARAGRAPH:
1277
- case FieldType.ADMINISTRATIVE_AREA:
1278
- case FieldType.FACILITY:
1279
- case FieldType.OFFICE:
1280
- case FieldType.SIGNATURE:
1281
- case FieldType.HIDDEN:
1282
- schema = required ? RequiredTextValue : TextValue;
1283
- break;
1284
- case FieldType.NUMBER:
1285
- schema = NumberFieldValue;
1286
- break;
1287
- case FieldType.CHECKBOX:
1288
- schema = CheckboxFieldValue;
1289
- break;
1290
- case FieldType.FILE:
1291
- schema = FileFieldValue;
1292
- break;
1293
- case FieldType.FILE_WITH_OPTIONS:
1294
- schema = FileFieldWithOptionValue;
1295
- break;
1296
- case FieldType.ADDRESS:
1297
- schema = AddressFieldUpdateValue;
1298
- break;
1299
- case FieldType.DATA:
1300
- schema = DataFieldValue;
1301
- break;
1302
- }
1303
- return required ? schema : schema.nullish();
1304
- }
1305
- function createValidationSchema(config) {
1306
- const shape = {};
1307
- for (const field2 of config) {
1308
- shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1309
- }
1310
- return import_zod19.z.object(shape);
1311
- }
1312
- function mapFieldTypeToMockValue(field2, i) {
1313
- switch (field2.type) {
1314
- case FieldType.DIVIDER:
1315
- case FieldType.TEXT:
1316
- case FieldType.TEXTAREA:
1317
- case FieldType.BULLET_LIST:
1318
- case FieldType.PAGE_HEADER:
1319
- case FieldType.LOCATION:
1320
- case FieldType.SELECT:
1321
- case FieldType.COUNTRY:
1322
- case FieldType.RADIO_GROUP:
1323
- case FieldType.SIGNATURE:
1324
- case FieldType.PARAGRAPH:
1325
- case FieldType.ADMINISTRATIVE_AREA:
1326
- case FieldType.FACILITY:
1327
- case FieldType.OFFICE:
1328
- return `${field2.id}-${field2.type}-${i}`;
1329
- case FieldType.NUMBER:
1330
- return 19;
1331
- case FieldType.EMAIL:
1332
- return "test@opencrvs.org";
1333
- case FieldType.ADDRESS:
1334
- return {
1335
- country: "FAR",
1336
- addressType: AddressType.DOMESTIC,
1337
- province: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
1338
- district: "5ef450bc-712d-48ad-93f3-8da0fa453baa",
1339
- urbanOrRural: "URBAN",
1340
- town: "Example Town",
1341
- residentialArea: "Example Residential Area",
1342
- street: "Example Street",
1343
- number: "55",
1344
- zipCode: "123456"
1345
- };
1346
- case FieldType.DATE:
1347
- return "2021-01-01";
1348
- case FieldType.CHECKBOX:
1349
- return true;
1350
- case FieldType.FILE:
1351
- return {
1352
- filename: "4f095fc4-4312-4de2-aa38-86dcc0f71044.png",
1353
- originalFilename: "abcd.png",
1354
- type: "image/png"
1355
- };
1356
- case FieldType.FILE_WITH_OPTIONS:
1357
- return null;
1358
- case FieldType.DATA:
1359
- return {};
1360
- }
1361
- }
1362
- function mapFieldTypeToEmptyValue(field2) {
1363
- switch (field2.type) {
1364
- case FieldType.DIVIDER:
1365
- case FieldType.TEXT:
1366
- case FieldType.TEXTAREA:
1367
- case FieldType.BULLET_LIST:
1368
- case FieldType.PAGE_HEADER:
1369
- case FieldType.LOCATION:
1370
- case FieldType.SELECT:
1371
- case FieldType.COUNTRY:
1372
- case FieldType.RADIO_GROUP:
1373
- case FieldType.SIGNATURE:
1374
- case FieldType.PARAGRAPH:
1375
- case FieldType.ADMINISTRATIVE_AREA:
1376
- case FieldType.FACILITY:
1377
- case FieldType.OFFICE:
1378
- case FieldType.NUMBER:
1379
- case FieldType.EMAIL:
1380
- case FieldType.DATE:
1381
- case FieldType.CHECKBOX:
1382
- case FieldType.DATA:
1383
- return null;
1384
- case FieldType.ADDRESS:
1385
- return {
1386
- country: null,
1387
- addressType: AddressType.DOMESTIC,
1388
- province: null,
1389
- district: null,
1390
- urbanOrRural: "URBAN",
1391
- // Default to urban needed for validation
1392
- town: null,
1393
- residentialArea: null,
1394
- street: null,
1395
- number: null,
1396
- zipCode: null
1397
- };
1398
- case FieldType.FILE:
1399
- return {
1400
- filename: "",
1401
- originalFilename: "",
1402
- type: ""
1403
- };
1404
- case FieldType.FILE_WITH_OPTIONS:
1405
- return [];
1406
- }
1407
- }
1408
- var isParagraphFieldType = (field2) => {
1409
- return field2.config.type === FieldType.PARAGRAPH;
1410
- };
1411
- var isDateFieldType = (field2) => {
1412
- return field2.config.type === FieldType.DATE;
1413
- };
1414
- var isPageHeaderFieldType = (field2) => {
1415
- return field2.config.type === FieldType.PAGE_HEADER;
1416
- };
1417
- var isTextFieldType = (field2) => {
1418
- return field2.config.type === FieldType.TEXT;
1419
- };
1420
- var isNumberFieldType = (field2) => {
1421
- return field2.config.type === FieldType.NUMBER;
1422
- };
1423
- var isTextAreaFieldType = (field2) => {
1424
- return field2.config.type === FieldType.TEXTAREA;
1425
- };
1426
- var isSignatureFieldType = (field2) => {
1427
- return field2.config.type === FieldType.SIGNATURE;
1428
- };
1429
- var isEmailFieldType = (field2) => {
1430
- return field2.config.type === FieldType.EMAIL;
1431
- };
1432
- var isFileFieldType = (field2) => {
1433
- return field2.config.type === FieldType.FILE;
1434
- };
1435
- var isFileFieldWithOptionType = (field2) => {
1436
- return field2.config.type === FieldType.FILE_WITH_OPTIONS;
1437
- };
1438
- var isBulletListFieldType = (field2) => {
1439
- return field2.config.type === FieldType.BULLET_LIST;
1440
- };
1441
- var isSelectFieldType = (field2) => {
1442
- return field2.config.type === FieldType.SELECT;
1443
- };
1444
- var isAddressFieldType = (field2) => {
1445
- return field2.config.type === FieldType.ADDRESS;
1446
- };
1447
- var isCountryFieldType = (field2) => {
1448
- return field2.config.type === FieldType.COUNTRY;
1449
- };
1450
- var isCheckboxFieldType = (field2) => {
1451
- return field2.config.type === FieldType.CHECKBOX;
1452
- };
1453
- var isRadioGroupFieldType = (field2) => {
1454
- return field2.config.type === FieldType.RADIO_GROUP;
1455
- };
1456
- var isLocationFieldType = (field2) => {
1457
- return field2.config.type === FieldType.LOCATION;
1458
- };
1459
- var isDividerFieldType = (field2) => {
1460
- return field2.config.type === FieldType.DIVIDER;
1461
- };
1462
- var isAdministrativeAreaFieldType = (field2) => {
1463
- return field2.config.type === FieldType.ADMINISTRATIVE_AREA;
1464
- };
1465
- var isFacilityFieldType = (field2) => {
1466
- return field2.config.type === FieldType.FACILITY;
1467
- };
1468
- var isOfficeFieldType = (field2) => {
1469
- return field2.config.type === FieldType.OFFICE;
1470
- };
1471
- var isDataFieldType = (field2) => {
1472
- return field2.config.type === FieldType.DATA;
1473
- };
1474
-
1475
- // ../commons/src/conditionals/validate.ts
1476
- var ajv = new import_ajv.default({
1477
- $data: true,
1478
- allowUnionTypes: true
1479
- });
1480
- (0, import_ajv_formats.default)(ajv);
1481
- function validate(schema, data) {
1482
- return ajv.validate(schema, data);
1483
- }
1484
- function getConditionalActionsForField(field2, values) {
1485
- if (!field2.conditionals) {
1486
- return [];
1487
- }
1488
- return field2.conditionals.filter((conditional) => validate(conditional.conditional, values)).map((conditional) => conditional.type);
1489
- }
1490
- function isFieldConditionMet(field2, form, conditionalType) {
1491
- const hasRule = (field2.conditionals ?? []).some(
1492
- (conditional) => conditional.type === conditionalType
1493
- );
1494
- if (!hasRule) {
1495
- return true;
1496
- }
1497
- const validConditionals = getConditionalActionsForField(field2, {
1498
- $form: form,
1499
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), {
1500
- representation: "date"
1501
- })
1502
- });
1503
- return validConditionals.includes(conditionalType);
1504
- }
1505
- function isFieldVisible(field2, form) {
1506
- return isFieldConditionMet(field2, form, ConditionalType.SHOW);
1507
- }
1508
- function isFieldEnabled(field2, form) {
1509
- return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1510
- }
1511
- var errorMessages = {
1512
- hiddenField: {
1513
- id: "v2.error.hidden",
1514
- defaultMessage: "Hidden or disabled field should not receive a value",
1515
- description: "Error message when field is hidden or disabled, but a value was received"
1516
- },
1517
- invalidDate: {
1518
- defaultMessage: "Invalid date field",
1519
- description: "Error message when date field is invalid",
1520
- id: "v2.error.invalidDate"
1521
- },
1522
- invalidEmail: {
1523
- defaultMessage: "Invalid email address",
1524
- description: "Error message when email address is invalid",
1525
- id: "v2.error.invalidEmail"
1526
- },
1527
- requiredField: {
1528
- defaultMessage: "Required for registration",
1529
- description: "Error message when required field is missing",
1530
- id: "v2.error.required"
1531
- },
1532
- invalidInput: {
1533
- defaultMessage: "Invalid input",
1534
- description: "Error message when generic field is invalid",
1535
- id: "v2.error.invalid"
1536
- }
1537
- };
1538
- var createIntlError = (message) => ({
1539
- message: {
1540
- message
1541
- }
1542
- });
1543
- var zodToIntlErrorMap = (issue, _ctx) => {
1544
- switch (issue.code) {
1545
- case "invalid_string": {
1546
- if (_ctx.data === "") {
1547
- return createIntlError(errorMessages.requiredField);
1548
- }
1549
- if (issue.validation === "date") {
1550
- return createIntlError(errorMessages.invalidDate);
1551
- }
1552
- if (issue.validation === "email") {
1553
- return createIntlError(errorMessages.invalidEmail);
1554
- }
1555
- break;
1556
- }
1557
- case "invalid_type": {
1558
- if (issue.expected !== issue.received && issue.received === "undefined") {
1559
- return createIntlError(errorMessages.requiredField);
1560
- }
1561
- break;
1562
- }
1563
- case "too_small": {
1564
- if (issue.message === void 0) {
1565
- return createIntlError(errorMessages.requiredField);
1566
- }
1567
- break;
1568
- }
1569
- case "invalid_union": {
1570
- for (const { issues } of issue.unionErrors) {
1571
- for (const e of issues) {
1572
- if (zodToIntlErrorMap(e, _ctx).message.message.id !== "v2.error.required") {
1573
- return createIntlError(errorMessages.invalidInput);
1574
- }
1575
- }
1576
- }
1577
- return createIntlError(errorMessages.requiredField);
1578
- }
1579
- }
1580
- 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
- }
1617
- function runCustomFieldValidations({
1618
- field: field2,
1619
- conditionalParameters
1620
- }) {
1621
- return (field2.validation ?? []).filter((validation) => {
1622
- return !validate(validation.validator, conditionalParameters);
1623
- }).map((validation) => ({ message: validation.message }));
1624
- }
1625
- function validateFieldInput({
1626
- field: field2,
1627
- value
1628
- }) {
1629
- const rawError = mapFieldTypeToZod(field2.type, field2.required).safeParse(
1630
- value,
1631
- {
1632
- // @ts-expect-error
1633
- errorMap: zodToIntlErrorMap
1634
- }
1635
- );
1636
- return rawError.error?.issues.map((issue) => issue.message) ?? [];
1637
- }
1638
-
1639
- // ../commons/src/uuid.ts
1640
- var import_uuid = require("uuid");
1641
- function getUUID() {
1642
- return (0, import_uuid.v4)();
1643
- }
1644
-
1645
- // ../commons/src/events/utils.ts
1646
- var import_date_fns2 = require("date-fns");
1647
-
1648
- // ../commons/src/utils.ts
1649
- function getOrThrow(x, message) {
1650
- if (x === void 0 || x === null) {
1651
- throw new Error(message);
1652
- }
1653
- return x;
1654
- }
1655
-
1656
- // ../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
- };
1666
- var getActionAnnotationFields = (actionConfig) => {
1667
- if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1668
- return [
1669
- ...actionConfig.onboardingForm.flatMap(({ fields }) => fields),
1670
- ...actionConfig.additionalDetailsForm.flatMap(({ fields }) => fields)
1671
- ];
1672
- }
1673
- if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1674
- return actionConfig?.printForm.pages.flatMap(({ fields }) => fields) ?? [];
1675
- }
1676
- if (isDeclarationActionConfig(actionConfig)) {
1677
- return actionConfig?.review.fields ?? [];
1678
- }
1679
- return [];
1680
- };
1681
- var findRecordActionPages = (config, actionType) => {
1682
- const action = config.actions.find((a) => a.type === actionType);
1683
- if (action?.type === ActionType.REQUEST_CORRECTION) {
1684
- return [...action.onboardingForm, ...action.additionalDetailsForm];
1685
- }
1686
- if (action?.type === ActionType.PRINT_CERTIFICATE) {
1687
- return action.printForm.pages;
1688
- }
1689
- return [];
1690
- };
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
- function getActionReview(configuration, actionType) {
1707
- const [actionConfig] = configuration.actions.filter(
1708
- (a) => a.type === actionType
1709
- );
1710
- return getOrThrow(
1711
- actionConfig?.review,
1712
- `No review config found for ${actionType}`
1713
- );
1714
- }
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
- });
1726
- }
1727
- function isPageVisible(page, formValues) {
1728
- if (!page.conditional) {
1729
- return true;
1730
- }
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];
1744
- }
1745
- function stripHiddenFields(fields, declaration) {
1746
- return (0, import_lodash.omitBy)(declaration, (_2, fieldId) => {
1747
- const field2 = fields.find((f) => f.id === fieldId);
1748
- if (!field2) {
1749
- return true;
1750
- }
1751
- if (isOptionalUncheckedCheckbox(field2, declaration)) {
1752
- return true;
1753
- }
1754
- return !isFieldVisible(field2, declaration);
1755
- });
1756
- }
1757
- function findActiveDrafts(event2, drafts) {
1758
- const actions = event2.actions.slice().filter(({ type }) => type !== ActionType.READ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1759
- const lastAction = actions[actions.length - 1];
1760
- return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
1761
- }
1762
- function createEmptyDraft(eventId, draftId, actionType) {
1763
- return {
1764
- id: draftId,
1765
- eventId,
1766
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1767
- transactionId: getUUID(),
1768
- action: {
1769
- type: actionType,
1770
- declaration: {},
1771
- annotation: {},
1772
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1773
- createdBy: "@todo",
1774
- createdAtLocation: "@todo"
1775
- }
1776
- };
1777
- }
1778
- function isVerificationPage(page) {
1779
- return page.type === PageTypes.enum.VERIFICATION;
1780
- }
1781
- function deepMerge(currentDocument, actionDocument) {
1782
- return (0, import_lodash.mergeWith)(
1783
- currentDocument,
1784
- actionDocument,
1785
- (previousValue, incomingValue) => {
1786
- if (incomingValue === void 0) {
1787
- return previousValue;
1788
- }
1789
- if ((0, import_lodash.isArray)(incomingValue)) {
1790
- return incomingValue;
1791
- }
1792
- if ((0, import_lodash.isObject)(previousValue) && (0, import_lodash.isObject)(incomingValue)) {
1793
- return void 0;
1794
- }
1795
- return incomingValue;
1796
- }
1797
- );
1798
- }
1799
-
1800
- // ../commons/src/events/EventConfig.ts
1801
- var EventConfig = import_zod20.z.object({
1802
- id: import_zod20.z.string().describe(
1803
- 'A machine-readable identifier for the event, e.g. "birth" or "death"'
1804
- ),
1805
- summary: SummaryConfig,
1806
- label: TranslationConfig,
1807
- actions: import_zod20.z.array(ActionConfig),
1808
- 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([])
1812
- }).superRefine((event2, ctx) => {
1813
- const allFields = findAllFields(event2);
1814
- const fieldIds = allFields.map((field2) => field2.id);
1815
- const advancedSearchFields = event2.advancedSearch.flatMap(
1816
- (section) => section.fields.flatMap((field2) => field2.fieldId)
1817
- );
1818
- const advancedSearchFieldsSet = new Set(advancedSearchFields);
1819
- if (advancedSearchFieldsSet.size !== advancedSearchFields.length) {
1820
- ctx.addIssue({
1821
- code: "custom",
1822
- message: "Advanced search field ids must be unique",
1823
- path: ["advancedSearch"]
1824
- });
1825
- }
1826
- const invalidFields = event2.advancedSearch.flatMap(
1827
- (section) => section.fields.filter((field2) => !fieldIds.includes(field2.fieldId))
1828
- );
1829
- if (invalidFields.length > 0) {
1830
- ctx.addIssue({
1831
- code: "custom",
1832
- message: `Advanced search id must match a field id in fields array.
1833
- Invalid AdvancedSearch field IDs for event ${event2.id}: ${invalidFields.map((f) => f.fieldId).join(", ")}`,
1834
- path: ["advancedSearch"]
1835
- });
1836
- }
1837
- });
1838
-
1839
- // ../commons/src/events/EventConfigInput.ts
1840
- var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
1841
- var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1842
- var definePage = (page) => PageConfig.parse(page);
1843
- var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1844
-
1845
- // ../commons/src/events/Draft.ts
1846
- var import_zod23 = require("zod");
1847
-
1848
- // ../commons/src/events/ActionDocument.ts
1849
- var import_zod21 = require("zod");
1850
- var ActionUpdate = import_zod21.z.record(import_zod21.z.string(), FieldUpdateValue);
1851
- var ActionStatus = {
1852
- Requested: "Requested",
1853
- Accepted: "Accepted",
1854
- Rejected: "Rejected"
1855
- };
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(),
1247
+ var ActionBase = import_zod18.z.object({
1248
+ id: import_zod18.z.string(),
1249
+ createdAt: import_zod18.z.string().datetime(),
1250
+ createdBy: import_zod18.z.string(),
1860
1251
  declaration: ActionUpdate,
1861
1252
  annotation: ActionUpdate.optional(),
1862
- createdAtLocation: import_zod21.z.string(),
1863
- status: import_zod21.z.enum([
1253
+ createdAtLocation: import_zod18.z.string().optional(),
1254
+ updatedAtLocation: import_zod18.z.string().optional(),
1255
+ status: import_zod18.z.enum([
1864
1256
  ActionStatus.Requested,
1865
1257
  ActionStatus.Accepted,
1866
1258
  ActionStatus.Rejected
1867
1259
  ]),
1868
1260
  // 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()
1261
+ originalActionId: import_zod18.z.string().optional()
1870
1262
  });
1871
1263
  var AssignedAction = ActionBase.merge(
1872
- import_zod21.z.object({
1873
- type: import_zod21.z.literal(ActionType.ASSIGN),
1874
- assignedTo: import_zod21.z.string()
1264
+ import_zod18.z.object({
1265
+ type: import_zod18.z.literal(ActionType.ASSIGN),
1266
+ assignedTo: import_zod18.z.string()
1875
1267
  })
1876
1268
  );
1877
1269
  var UnassignedAction = ActionBase.merge(
1878
- import_zod21.z.object({
1879
- type: import_zod21.z.literal(ActionType.UNASSIGN)
1270
+ import_zod18.z.object({
1271
+ type: import_zod18.z.literal(ActionType.UNASSIGN),
1272
+ assignedTo: import_zod18.z.literal(null).default(null)
1880
1273
  })
1881
1274
  );
1882
1275
  var RegisterAction = ActionBase.merge(
1883
- import_zod21.z.object({
1884
- type: import_zod21.z.literal(ActionType.REGISTER),
1885
- registrationNumber: import_zod21.z.string().optional()
1276
+ import_zod18.z.object({
1277
+ type: import_zod18.z.literal(ActionType.REGISTER),
1278
+ registrationNumber: import_zod18.z.string().optional()
1886
1279
  })
1887
1280
  );
1888
1281
  var DeclareAction = ActionBase.merge(
1889
- import_zod21.z.object({
1890
- type: import_zod21.z.literal(ActionType.DECLARE)
1282
+ import_zod18.z.object({
1283
+ type: import_zod18.z.literal(ActionType.DECLARE)
1891
1284
  })
1892
1285
  );
1893
1286
  var ValidateAction = ActionBase.merge(
1894
- import_zod21.z.object({
1895
- type: import_zod21.z.literal(ActionType.VALIDATE)
1287
+ import_zod18.z.object({
1288
+ type: import_zod18.z.literal(ActionType.VALIDATE)
1896
1289
  })
1897
1290
  );
1898
1291
  var RejectAction = ActionBase.merge(
1899
- import_zod21.z.object({
1900
- type: import_zod21.z.literal(ActionType.REJECT)
1292
+ import_zod18.z.object({
1293
+ type: import_zod18.z.literal(ActionType.REJECT)
1901
1294
  })
1902
1295
  );
1903
1296
  var MarkAsDuplicateAction = ActionBase.merge(
1904
- import_zod21.z.object({
1905
- type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE)
1297
+ import_zod18.z.object({
1298
+ type: import_zod18.z.literal(ActionType.MARKED_AS_DUPLICATE)
1906
1299
  })
1907
1300
  );
1908
1301
  var ArchiveAction = ActionBase.merge(
1909
- import_zod21.z.object({
1910
- type: import_zod21.z.literal(ActionType.ARCHIVE)
1302
+ import_zod18.z.object({
1303
+ type: import_zod18.z.literal(ActionType.ARCHIVE)
1911
1304
  })
1912
1305
  );
1913
1306
  var CreatedAction = ActionBase.merge(
1914
- import_zod21.z.object({
1915
- type: import_zod21.z.literal(ActionType.CREATE)
1307
+ import_zod18.z.object({
1308
+ type: import_zod18.z.literal(ActionType.CREATE)
1916
1309
  })
1917
1310
  );
1918
1311
  var NotifiedAction = ActionBase.merge(
1919
- import_zod21.z.object({
1920
- type: import_zod21.z.literal(ActionType.NOTIFY)
1312
+ import_zod18.z.object({
1313
+ type: import_zod18.z.literal(ActionType.NOTIFY)
1921
1314
  })
1922
1315
  );
1923
1316
  var PrintCertificateAction = ActionBase.merge(
1924
- import_zod21.z.object({
1925
- type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE)
1317
+ import_zod18.z.object({
1318
+ type: import_zod18.z.literal(ActionType.PRINT_CERTIFICATE)
1926
1319
  })
1927
1320
  );
1928
1321
  var RequestedCorrectionAction = ActionBase.merge(
1929
- import_zod21.z.object({
1930
- type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION)
1322
+ import_zod18.z.object({
1323
+ type: import_zod18.z.literal(ActionType.REQUEST_CORRECTION)
1931
1324
  })
1932
1325
  );
1933
1326
  var ApprovedCorrectionAction = ActionBase.merge(
1934
- import_zod21.z.object({
1935
- type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION),
1936
- requestId: import_zod21.z.string()
1327
+ import_zod18.z.object({
1328
+ type: import_zod18.z.literal(ActionType.APPROVE_CORRECTION),
1329
+ requestId: import_zod18.z.string()
1937
1330
  })
1938
1331
  );
1939
1332
  var RejectedCorrectionAction = ActionBase.merge(
1940
- import_zod21.z.object({
1941
- type: import_zod21.z.literal(ActionType.REJECT_CORRECTION),
1942
- requestId: import_zod21.z.string()
1333
+ import_zod18.z.object({
1334
+ type: import_zod18.z.literal(ActionType.REJECT_CORRECTION),
1335
+ requestId: import_zod18.z.string()
1943
1336
  })
1944
1337
  );
1945
1338
  var ReadAction = ActionBase.merge(
1946
- import_zod21.z.object({
1947
- type: import_zod21.z.literal(ActionType.READ)
1339
+ import_zod18.z.object({
1340
+ type: import_zod18.z.literal(ActionType.READ)
1948
1341
  })
1949
1342
  );
1950
- var ActionDocument = import_zod21.z.discriminatedUnion("type", [
1343
+ var ActionDocument = import_zod18.z.discriminatedUnion("type", [
1951
1344
  CreatedAction,
1952
1345
  ValidateAction,
1953
1346
  RejectAction,
@@ -1970,115 +1363,117 @@ var AsyncRejectActionDocument = ActionBase.omit({
1970
1363
  createdBy: true,
1971
1364
  createdAtLocation: true
1972
1365
  }).merge(
1973
- import_zod21.z.object({
1974
- type: import_zod21.z.enum(ConfirmableActions),
1975
- status: import_zod21.z.literal(ActionStatus.Rejected)
1366
+ import_zod18.z.object({
1367
+ type: import_zod18.z.enum(ConfirmableActions),
1368
+ status: import_zod18.z.literal(ActionStatus.Rejected)
1976
1369
  })
1977
1370
  );
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()
1371
+ var Action = import_zod18.z.union([ActionDocument, AsyncRejectActionDocument]);
1372
+ var ResolvedUser = import_zod18.z.object({
1373
+ id: import_zod18.z.string(),
1374
+ role: import_zod18.z.string(),
1375
+ name: import_zod18.z.array(
1376
+ import_zod18.z.object({
1377
+ use: import_zod18.z.string(),
1378
+ given: import_zod18.z.array(import_zod18.z.string()),
1379
+ family: import_zod18.z.string()
1987
1380
  })
1988
1381
  )
1989
1382
  });
1990
1383
 
1991
1384
  // ../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,
1385
+ var import_zod19 = require("zod");
1386
+ var BaseActionInput = import_zod19.z.object({
1387
+ eventId: import_zod19.z.string(),
1388
+ transactionId: import_zod19.z.string(),
1389
+ declaration: ActionUpdate.default({}),
1997
1390
  annotation: ActionUpdate.optional(),
1998
- originalActionId: import_zod22.z.string().optional()
1391
+ originalActionId: import_zod19.z.string().optional(),
1392
+ keepAssignment: import_zod19.z.boolean().optional()
1999
1393
  });
2000
1394
  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()
1395
+ import_zod19.z.object({
1396
+ type: import_zod19.z.literal(ActionType.CREATE).default(ActionType.CREATE),
1397
+ createdAtLocation: import_zod19.z.string()
2004
1398
  })
2005
1399
  );
2006
1400
  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()
1401
+ import_zod19.z.object({
1402
+ type: import_zod19.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
1403
+ registrationNumber: import_zod19.z.string().optional()
2010
1404
  })
2011
1405
  );
2012
1406
  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())
1407
+ import_zod19.z.object({
1408
+ type: import_zod19.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
1409
+ duplicates: import_zod19.z.array(import_zod19.z.string())
2016
1410
  })
2017
1411
  );
2018
1412
  var NotifyActionInput = BaseActionInput.merge(
2019
- import_zod22.z.object({
2020
- type: import_zod22.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1413
+ import_zod19.z.object({
1414
+ type: import_zod19.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2021
1415
  })
2022
1416
  );
2023
1417
  var DeclareActionInput = BaseActionInput.merge(
2024
- import_zod22.z.object({
2025
- type: import_zod22.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1418
+ import_zod19.z.object({
1419
+ type: import_zod19.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2026
1420
  })
2027
1421
  );
2028
1422
  var PrintCertificateActionInput = BaseActionInput.merge(
2029
- import_zod22.z.object({
2030
- type: import_zod22.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1423
+ import_zod19.z.object({
1424
+ type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2031
1425
  })
2032
1426
  );
2033
1427
  var RejectDeclarationActionInput = BaseActionInput.merge(
2034
- import_zod22.z.object({
2035
- type: import_zod22.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1428
+ import_zod19.z.object({
1429
+ type: import_zod19.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2036
1430
  })
2037
1431
  );
2038
1432
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
2039
- import_zod22.z.object({
2040
- type: import_zod22.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1433
+ import_zod19.z.object({
1434
+ type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2041
1435
  })
2042
1436
  );
2043
1437
  var ArchiveActionInput = BaseActionInput.merge(
2044
- import_zod22.z.object({
2045
- type: import_zod22.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1438
+ import_zod19.z.object({
1439
+ type: import_zod19.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2046
1440
  })
2047
1441
  );
2048
1442
  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()
1443
+ import_zod19.z.object({
1444
+ type: import_zod19.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
1445
+ assignedTo: import_zod19.z.string()
2052
1446
  })
2053
1447
  );
2054
1448
  var UnassignActionInput = BaseActionInput.merge(
2055
- import_zod22.z.object({
2056
- type: import_zod22.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN)
1449
+ import_zod19.z.object({
1450
+ type: import_zod19.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
1451
+ assignedTo: import_zod19.z.literal(null).default(null)
2057
1452
  })
2058
1453
  );
2059
1454
  var RequestCorrectionActionInput = BaseActionInput.merge(
2060
- import_zod22.z.object({
2061
- type: import_zod22.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
1455
+ import_zod19.z.object({
1456
+ type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2062
1457
  })
2063
1458
  );
2064
1459
  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)
1460
+ import_zod19.z.object({
1461
+ requestId: import_zod19.z.string(),
1462
+ type: import_zod19.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2068
1463
  })
2069
1464
  );
2070
1465
  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)
1466
+ import_zod19.z.object({
1467
+ requestId: import_zod19.z.string(),
1468
+ type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2074
1469
  })
2075
1470
  );
2076
1471
  var ReadActionInput = BaseActionInput.merge(
2077
- import_zod22.z.object({
2078
- type: import_zod22.z.literal(ActionType.READ).default(ActionType.READ)
1472
+ import_zod19.z.object({
1473
+ type: import_zod19.z.literal(ActionType.READ).default(ActionType.READ)
2079
1474
  })
2080
1475
  );
2081
- var ActionInput = import_zod22.z.discriminatedUnion("type", [
1476
+ var ActionInput = import_zod19.z.discriminatedUnion("type", [
2082
1477
  CreateActionInput,
2083
1478
  ValidateActionInput,
2084
1479
  RegisterActionInput,
@@ -2096,52 +1491,765 @@ var ActionInput = import_zod22.z.discriminatedUnion("type", [
2096
1491
  ReadActionInput
2097
1492
  ]);
2098
1493
 
2099
- // ../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(),
2105
- action: ActionBase.extend({
2106
- type: ActionTypes
2107
- }).omit({ id: true, status: true })
1494
+ // ../commons/src/events/Draft.ts
1495
+ var Draft = import_zod20.z.object({
1496
+ id: import_zod20.z.string(),
1497
+ eventId: import_zod20.z.string(),
1498
+ transactionId: import_zod20.z.string(),
1499
+ createdAt: import_zod20.z.string().datetime(),
1500
+ action: ActionBase.extend({
1501
+ type: ActionTypes
1502
+ }).omit({ id: true })
1503
+ });
1504
+ var DraftInput = BaseActionInput.extend({
1505
+ type: ActionTypes
1506
+ });
1507
+
1508
+ // ../commons/src/events/EventInput.ts
1509
+ var import_zod21 = require("zod");
1510
+ var EventInput = import_zod21.z.object({
1511
+ transactionId: import_zod21.z.string(),
1512
+ type: import_zod21.z.string()
1513
+ });
1514
+
1515
+ // ../commons/src/events/EventDocument.ts
1516
+ var import_zod22 = require("zod");
1517
+ var EventDocument = import_zod22.z.object({
1518
+ id: import_zod22.z.string(),
1519
+ type: import_zod22.z.string(),
1520
+ createdAt: import_zod22.z.string().datetime(),
1521
+ updatedAt: import_zod22.z.string().datetime(),
1522
+ actions: import_zod22.z.array(Action),
1523
+ trackingId: import_zod22.z.string()
1524
+ });
1525
+
1526
+ // ../commons/src/events/EventIndex.ts
1527
+ var import_zod23 = require("zod");
1528
+ var EventIndex = EventMetadata.extend({
1529
+ declaration: import_zod23.z.record(import_zod23.z.string(), import_zod23.z.any())
1530
+ });
1531
+ var EventSearchIndex = import_zod23.z.record(import_zod23.z.string(), import_zod23.z.any()).and(
1532
+ import_zod23.z.object({
1533
+ type: import_zod23.z.string()
1534
+ // Ensures "type" (event-id) exists and is a string
1535
+ })
1536
+ );
1537
+ var Fuzzy = import_zod23.z.object({ type: import_zod23.z.literal("fuzzy"), term: import_zod23.z.string() });
1538
+ var Exact = import_zod23.z.object({ type: import_zod23.z.literal("exact"), term: import_zod23.z.string() });
1539
+ var AnyOf = import_zod23.z.object({
1540
+ type: import_zod23.z.literal("anyOf"),
1541
+ terms: import_zod23.z.array(import_zod23.z.string())
1542
+ });
1543
+ var Range = import_zod23.z.object({
1544
+ type: import_zod23.z.literal("range"),
1545
+ gte: import_zod23.z.string(),
1546
+ lte: import_zod23.z.string()
1547
+ });
1548
+ var Within = import_zod23.z.object({ type: import_zod23.z.literal("within"), location: import_zod23.z.string() });
1549
+ var DateCondition = import_zod23.z.union([Exact, Range]);
1550
+ var QueryInput = import_zod23.z.lazy(
1551
+ () => import_zod23.z.union([
1552
+ import_zod23.z.discriminatedUnion("type", [Fuzzy, Exact, Range, Within, AnyOf]),
1553
+ import_zod23.z.record(import_zod23.z.string(), QueryInput)
1554
+ ])
1555
+ );
1556
+ var QueryExpression = import_zod23.z.object({
1557
+ type: import_zod23.z.literal("and"),
1558
+ eventType: import_zod23.z.string(),
1559
+ searchType: import_zod23.z.optional(import_zod23.z.union([AnyOf, Exact])),
1560
+ status: import_zod23.z.optional(import_zod23.z.union([AnyOf, Exact])),
1561
+ createdAt: import_zod23.z.optional(DateCondition),
1562
+ updatedAt: import_zod23.z.optional(DateCondition),
1563
+ createAtLocation: import_zod23.z.optional(import_zod23.z.union([Within, Exact])),
1564
+ updatedAtLocation: import_zod23.z.optional(import_zod23.z.union([Within, Exact])),
1565
+ createdBy: import_zod23.z.optional(Exact),
1566
+ updatedBy: import_zod23.z.optional(Exact),
1567
+ trackingId: import_zod23.z.optional(Exact),
1568
+ data: QueryInput
1569
+ }).partial();
1570
+ var Or2 = import_zod23.z.object({
1571
+ type: import_zod23.z.literal("or"),
1572
+ clauses: import_zod23.z.array(QueryExpression)
1573
+ });
1574
+ var QueryType = import_zod23.z.discriminatedUnion("type", [QueryExpression, Or2]);
1575
+
1576
+ // ../commons/src/events/utils.ts
1577
+ var import_lodash2 = require("lodash");
1578
+
1579
+ // ../commons/src/workqueues/WorkqueueConfig.ts
1580
+ var import_zod25 = require("zod");
1581
+
1582
+ // ../commons/src/workqueues/defaultColumns.ts
1583
+ var import_zod24 = require("zod");
1584
+ var WorkQueueColumnConfig = import_zod24.z.object({
1585
+ id: import_zod24.z.string(),
1586
+ label: TranslationConfig
1587
+ });
1588
+ var defaultColumns = {
1589
+ event: {
1590
+ id: "event",
1591
+ label: {
1592
+ defaultMessage: "Event",
1593
+ description: "This is the label for the workqueue column",
1594
+ id: "workqueue.default.column.event"
1595
+ }
1596
+ },
1597
+ status: {
1598
+ id: "status",
1599
+ label: {
1600
+ defaultMessage: "Status",
1601
+ description: "This is the label for the workqueue column",
1602
+ id: "workqueue.default.column.status"
1603
+ }
1604
+ },
1605
+ createdAt: {
1606
+ id: "createdAt",
1607
+ label: {
1608
+ defaultMessage: "Created",
1609
+ description: "This is the label for the workqueue column",
1610
+ id: "workqueue.default.column.createdAt"
1611
+ }
1612
+ },
1613
+ modifiedAt: {
1614
+ id: "modifiedAt",
1615
+ label: {
1616
+ defaultMessage: "Modified",
1617
+ description: "This is the label for the workqueue column",
1618
+ id: "workqueue.default.column.modifiedAt"
1619
+ }
1620
+ }
1621
+ };
1622
+ var DefaultColumnKeys = import_zod24.z.enum(
1623
+ Object.keys(defaultColumns)
1624
+ );
1625
+
1626
+ // ../commons/src/workqueues/WorkqueueConfig.ts
1627
+ var rootWorkqueueConfig = import_zod25.z.object({
1628
+ id: import_zod25.z.string(),
1629
+ title: TranslationConfig,
1630
+ columns: import_zod25.z.array(WorkQueueColumnConfig),
1631
+ defaultColumns: import_zod25.z.array(DefaultColumnKeys)
1632
+ });
1633
+ var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
1634
+
1635
+ // ../commons/src/workqueues/all.ts
1636
+ var allWorkqueue = defineWorkqueue({
1637
+ id: "all",
1638
+ title: {
1639
+ defaultMessage: "All events",
1640
+ description: "This is the label for the workqueue",
1641
+ id: "workqueue.all.label"
1642
+ },
1643
+ columns: [
1644
+ {
1645
+ id: "title",
1646
+ label: {
1647
+ defaultMessage: "Title",
1648
+ description: "This is the label for the workqueue column",
1649
+ id: "workqueue.all.column.title"
1650
+ }
1651
+ }
1652
+ ],
1653
+ defaultColumns: ["event", "status", "createdAt", "modifiedAt"]
1654
+ });
1655
+
1656
+ // ../commons/src/workqueues/readyForReview.ts
1657
+ var inReviewWorkqueue = defineWorkqueue({
1658
+ id: "ready-for-review",
1659
+ title: {
1660
+ defaultMessage: "Ready for review",
1661
+ description: "Label for in review workqueue",
1662
+ id: "event.workqueue.in-review.label"
1663
+ },
1664
+ columns: [
1665
+ {
1666
+ id: "title",
1667
+ label: {
1668
+ defaultMessage: "Title",
1669
+ description: "This is the label for the workqueue column",
1670
+ id: "workqueue.in-reveiw.column.title"
1671
+ }
1672
+ }
1673
+ ],
1674
+ defaultColumns: ["event", "createdAt", "modifiedAt"]
2108
1675
  });
2109
- var DraftInput = BaseActionInput.extend({
2110
- type: ActionTypes
1676
+
1677
+ // ../commons/src/workqueues/readyToPrint.ts
1678
+ var registeredWorkqueue = defineWorkqueue({
1679
+ id: "registered",
1680
+ title: {
1681
+ defaultMessage: "Ready to print",
1682
+ description: "Label for registered workqueue",
1683
+ id: "event.workqueue.registered.label"
1684
+ },
1685
+ columns: [
1686
+ {
1687
+ id: "title",
1688
+ label: {
1689
+ defaultMessage: "Title",
1690
+ description: "This is the label for the workqueue column",
1691
+ id: "workqueue.registered.column.title"
1692
+ }
1693
+ }
1694
+ ],
1695
+ defaultColumns: ["event", "createdAt", "modifiedAt"]
2111
1696
  });
2112
1697
 
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()
1698
+ // ../commons/src/workqueues/index.ts
1699
+ var workqueues = {
1700
+ all: allWorkqueue,
1701
+ registered: registeredWorkqueue,
1702
+ inReview: inReviewWorkqueue
1703
+ };
1704
+
1705
+ // ../commons/src/conditionals/validate.ts
1706
+ var import_ajv = __toESM(require("ajv"));
1707
+ var import_ajv_formats = __toESM(require("ajv-formats"));
1708
+ var import_date_fns = require("date-fns");
1709
+
1710
+ // ../commons/src/events/FieldTypeMapping.ts
1711
+ var import_zod26 = require("zod");
1712
+ function mapFieldTypeToZod(type, required) {
1713
+ let schema;
1714
+ switch (type) {
1715
+ case FieldType.DATE:
1716
+ schema = DateValue;
1717
+ break;
1718
+ case FieldType.EMAIL:
1719
+ schema = EmailValue;
1720
+ break;
1721
+ case FieldType.TEXT:
1722
+ case FieldType.TEXTAREA:
1723
+ case FieldType.DIVIDER:
1724
+ case FieldType.BULLET_LIST:
1725
+ case FieldType.PAGE_HEADER:
1726
+ case FieldType.LOCATION:
1727
+ case FieldType.SELECT:
1728
+ case FieldType.COUNTRY:
1729
+ case FieldType.RADIO_GROUP:
1730
+ case FieldType.PARAGRAPH:
1731
+ case FieldType.ADMINISTRATIVE_AREA:
1732
+ case FieldType.FACILITY:
1733
+ case FieldType.OFFICE:
1734
+ case FieldType.SIGNATURE:
1735
+ case FieldType.HIDDEN:
1736
+ schema = required ? RequiredTextValue : TextValue;
1737
+ break;
1738
+ case FieldType.NUMBER:
1739
+ schema = NumberFieldValue;
1740
+ break;
1741
+ case FieldType.CHECKBOX:
1742
+ schema = CheckboxFieldValue;
1743
+ break;
1744
+ case FieldType.FILE:
1745
+ schema = FileFieldValue;
1746
+ break;
1747
+ case FieldType.FILE_WITH_OPTIONS:
1748
+ schema = FileFieldWithOptionValue;
1749
+ break;
1750
+ case FieldType.ADDRESS:
1751
+ schema = AddressFieldUpdateValue;
1752
+ break;
1753
+ case FieldType.DATA:
1754
+ schema = DataFieldValue;
1755
+ break;
1756
+ }
1757
+ return required ? schema : schema.nullish();
1758
+ }
1759
+ function createValidationSchema(config) {
1760
+ const shape = {};
1761
+ for (const field2 of config) {
1762
+ shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1763
+ }
1764
+ return import_zod26.z.object(shape);
1765
+ }
1766
+ function mapFieldTypeToMockValue(field2, i) {
1767
+ switch (field2.type) {
1768
+ case FieldType.DIVIDER:
1769
+ case FieldType.TEXT:
1770
+ case FieldType.TEXTAREA:
1771
+ case FieldType.BULLET_LIST:
1772
+ case FieldType.PAGE_HEADER:
1773
+ case FieldType.LOCATION:
1774
+ case FieldType.SELECT:
1775
+ case FieldType.COUNTRY:
1776
+ case FieldType.RADIO_GROUP:
1777
+ case FieldType.SIGNATURE:
1778
+ case FieldType.PARAGRAPH:
1779
+ case FieldType.ADMINISTRATIVE_AREA:
1780
+ case FieldType.FACILITY:
1781
+ case FieldType.OFFICE:
1782
+ return `${field2.id}-${field2.type}-${i}`;
1783
+ case FieldType.NUMBER:
1784
+ return 19;
1785
+ case FieldType.EMAIL:
1786
+ return "test@opencrvs.org";
1787
+ case FieldType.ADDRESS:
1788
+ return {
1789
+ country: "FAR",
1790
+ addressType: AddressType.DOMESTIC,
1791
+ province: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
1792
+ district: "5ef450bc-712d-48ad-93f3-8da0fa453baa",
1793
+ urbanOrRural: "URBAN",
1794
+ town: "Example Town",
1795
+ residentialArea: "Example Residential Area",
1796
+ street: "Example Street",
1797
+ number: "55",
1798
+ zipCode: "123456"
1799
+ };
1800
+ case FieldType.DATE:
1801
+ return "2021-01-01";
1802
+ case FieldType.CHECKBOX:
1803
+ return true;
1804
+ case FieldType.FILE:
1805
+ return {
1806
+ filename: "4f095fc4-4312-4de2-aa38-86dcc0f71044.png",
1807
+ originalFilename: "abcd.png",
1808
+ type: "image/png"
1809
+ };
1810
+ case FieldType.FILE_WITH_OPTIONS:
1811
+ return null;
1812
+ case FieldType.DATA:
1813
+ return {};
1814
+ }
1815
+ }
1816
+ function mapFieldTypeToEmptyValue(field2) {
1817
+ switch (field2.type) {
1818
+ case FieldType.DIVIDER:
1819
+ case FieldType.TEXT:
1820
+ case FieldType.TEXTAREA:
1821
+ case FieldType.BULLET_LIST:
1822
+ case FieldType.PAGE_HEADER:
1823
+ case FieldType.LOCATION:
1824
+ case FieldType.SELECT:
1825
+ case FieldType.COUNTRY:
1826
+ case FieldType.RADIO_GROUP:
1827
+ case FieldType.SIGNATURE:
1828
+ case FieldType.PARAGRAPH:
1829
+ case FieldType.ADMINISTRATIVE_AREA:
1830
+ case FieldType.FACILITY:
1831
+ case FieldType.OFFICE:
1832
+ case FieldType.NUMBER:
1833
+ case FieldType.EMAIL:
1834
+ case FieldType.DATE:
1835
+ case FieldType.CHECKBOX:
1836
+ case FieldType.DATA:
1837
+ return null;
1838
+ case FieldType.ADDRESS:
1839
+ return {
1840
+ country: null,
1841
+ addressType: AddressType.DOMESTIC,
1842
+ province: null,
1843
+ district: null,
1844
+ urbanOrRural: "URBAN",
1845
+ // Default to urban needed for validation
1846
+ town: null,
1847
+ residentialArea: null,
1848
+ street: null,
1849
+ number: null,
1850
+ zipCode: null
1851
+ };
1852
+ case FieldType.FILE:
1853
+ return {
1854
+ filename: "",
1855
+ originalFilename: "",
1856
+ type: ""
1857
+ };
1858
+ case FieldType.FILE_WITH_OPTIONS:
1859
+ return [];
1860
+ }
1861
+ }
1862
+ var isParagraphFieldType = (field2) => {
1863
+ return field2.config.type === FieldType.PARAGRAPH;
1864
+ };
1865
+ var isDateFieldType = (field2) => {
1866
+ return field2.config.type === FieldType.DATE;
1867
+ };
1868
+ var isPageHeaderFieldType = (field2) => {
1869
+ return field2.config.type === FieldType.PAGE_HEADER;
1870
+ };
1871
+ var isTextFieldType = (field2) => {
1872
+ return field2.config.type === FieldType.TEXT;
1873
+ };
1874
+ var isNumberFieldType = (field2) => {
1875
+ return field2.config.type === FieldType.NUMBER;
1876
+ };
1877
+ var isTextAreaFieldType = (field2) => {
1878
+ return field2.config.type === FieldType.TEXTAREA;
1879
+ };
1880
+ var isSignatureFieldType = (field2) => {
1881
+ return field2.config.type === FieldType.SIGNATURE;
1882
+ };
1883
+ var isEmailFieldType = (field2) => {
1884
+ return field2.config.type === FieldType.EMAIL;
1885
+ };
1886
+ var isFileFieldType = (field2) => {
1887
+ return field2.config.type === FieldType.FILE;
1888
+ };
1889
+ var isFileFieldWithOptionType = (field2) => {
1890
+ return field2.config.type === FieldType.FILE_WITH_OPTIONS;
1891
+ };
1892
+ var isBulletListFieldType = (field2) => {
1893
+ return field2.config.type === FieldType.BULLET_LIST;
1894
+ };
1895
+ var isSelectFieldType = (field2) => {
1896
+ return field2.config.type === FieldType.SELECT;
1897
+ };
1898
+ var isAddressFieldType = (field2) => {
1899
+ return field2.config.type === FieldType.ADDRESS;
1900
+ };
1901
+ var isCountryFieldType = (field2) => {
1902
+ return field2.config.type === FieldType.COUNTRY;
1903
+ };
1904
+ var isCheckboxFieldType = (field2) => {
1905
+ return field2.config.type === FieldType.CHECKBOX;
1906
+ };
1907
+ var isRadioGroupFieldType = (field2) => {
1908
+ return field2.config.type === FieldType.RADIO_GROUP;
1909
+ };
1910
+ var isLocationFieldType = (field2) => {
1911
+ return field2.config.type === FieldType.LOCATION;
1912
+ };
1913
+ var isDividerFieldType = (field2) => {
1914
+ return field2.config.type === FieldType.DIVIDER;
1915
+ };
1916
+ var isAdministrativeAreaFieldType = (field2) => {
1917
+ return field2.config.type === FieldType.ADMINISTRATIVE_AREA;
1918
+ };
1919
+ var isFacilityFieldType = (field2) => {
1920
+ return field2.config.type === FieldType.FACILITY;
1921
+ };
1922
+ var isOfficeFieldType = (field2) => {
1923
+ return field2.config.type === FieldType.OFFICE;
1924
+ };
1925
+ var isDataFieldType = (field2) => {
1926
+ return field2.config.type === FieldType.DATA;
1927
+ };
1928
+
1929
+ // ../commons/src/conditionals/validate.ts
1930
+ var ajv = new import_ajv.default({
1931
+ $data: true,
1932
+ allowUnionTypes: true
2118
1933
  });
1934
+ (0, import_ajv_formats.default)(ajv);
1935
+ function validate(schema, data) {
1936
+ return ajv.validate(schema, data);
1937
+ }
1938
+ function getConditionalActionsForField(field2, values) {
1939
+ if (!field2.conditionals) {
1940
+ return [];
1941
+ }
1942
+ return field2.conditionals.filter((conditional) => validate(conditional.conditional, values)).map((conditional) => conditional.type);
1943
+ }
1944
+ function isFieldConditionMet(field2, form, conditionalType) {
1945
+ const hasRule = (field2.conditionals ?? []).some(
1946
+ (conditional) => conditional.type === conditionalType
1947
+ );
1948
+ if (!hasRule) {
1949
+ return true;
1950
+ }
1951
+ const validConditionals = getConditionalActionsForField(field2, {
1952
+ $form: form,
1953
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), {
1954
+ representation: "date"
1955
+ })
1956
+ });
1957
+ return validConditionals.includes(conditionalType);
1958
+ }
1959
+ function isFieldVisible(field2, form) {
1960
+ return isFieldConditionMet(field2, form, ConditionalType.SHOW);
1961
+ }
1962
+ function isFieldEnabled(field2, form) {
1963
+ return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1964
+ }
1965
+ function isFieldDisplayedOnReview(field2, form) {
1966
+ return isFieldVisible(field2, form) && isFieldConditionMet(field2, form, ConditionalType.DISPLAY_ON_REVIEW);
1967
+ }
1968
+ var errorMessages = {
1969
+ hiddenField: {
1970
+ id: "v2.error.hidden",
1971
+ defaultMessage: "Hidden or disabled field should not receive a value",
1972
+ description: "Error message when field is hidden or disabled, but a value was received"
1973
+ },
1974
+ invalidDate: {
1975
+ defaultMessage: "Invalid date field",
1976
+ description: "Error message when date field is invalid",
1977
+ id: "v2.error.invalidDate"
1978
+ },
1979
+ invalidEmail: {
1980
+ defaultMessage: "Invalid email address",
1981
+ description: "Error message when email address is invalid",
1982
+ id: "v2.error.invalidEmail"
1983
+ },
1984
+ requiredField: {
1985
+ defaultMessage: "Required for registration",
1986
+ description: "Error message when required field is missing",
1987
+ id: "v2.error.required"
1988
+ },
1989
+ invalidInput: {
1990
+ defaultMessage: "Invalid input",
1991
+ description: "Error message when generic field is invalid",
1992
+ id: "v2.error.invalid"
1993
+ }
1994
+ };
1995
+ function createIntlError(message) {
1996
+ return {
1997
+ message: {
1998
+ message
1999
+ }
2000
+ };
2001
+ }
2002
+ function zodToIntlErrorMap(issue, _ctx) {
2003
+ switch (issue.code) {
2004
+ case "invalid_string": {
2005
+ if (_ctx.data === "") {
2006
+ return createIntlError(errorMessages.requiredField);
2007
+ }
2008
+ if (issue.validation === "date") {
2009
+ return createIntlError(errorMessages.invalidDate);
2010
+ }
2011
+ if (issue.validation === "email") {
2012
+ return createIntlError(errorMessages.invalidEmail);
2013
+ }
2014
+ break;
2015
+ }
2016
+ case "invalid_type": {
2017
+ if (issue.expected !== issue.received && issue.received === "undefined") {
2018
+ return createIntlError(errorMessages.requiredField);
2019
+ }
2020
+ break;
2021
+ }
2022
+ case "too_small": {
2023
+ if (issue.message === void 0) {
2024
+ return createIntlError(errorMessages.requiredField);
2025
+ }
2026
+ break;
2027
+ }
2028
+ case "invalid_union": {
2029
+ for (const { issues } of issue.unionErrors) {
2030
+ for (const e of issues) {
2031
+ if (zodToIntlErrorMap(e, _ctx).message.message.id !== "v2.error.required") {
2032
+ return createIntlError(errorMessages.invalidInput);
2033
+ }
2034
+ }
2035
+ }
2036
+ return createIntlError(errorMessages.requiredField);
2037
+ }
2038
+ }
2039
+ return createIntlError(errorMessages.invalidInput);
2040
+ }
2041
+ function runCustomFieldValidations({
2042
+ field: field2,
2043
+ conditionalParameters
2044
+ }) {
2045
+ return (field2.validation ?? []).filter((validation) => {
2046
+ return !validate(validation.validator, conditionalParameters);
2047
+ }).map((validation) => ({ message: validation.message }));
2048
+ }
2049
+ function validateFieldInput({
2050
+ field: field2,
2051
+ value
2052
+ }) {
2053
+ const rawError = mapFieldTypeToZod(field2.type, field2.required).safeParse(
2054
+ value,
2055
+ {
2056
+ // @ts-expect-error
2057
+ errorMap: zodToIntlErrorMap
2058
+ }
2059
+ );
2060
+ return rawError.error?.issues.map((issue) => issue.message) ?? [];
2061
+ }
2062
+ function runFieldValidations({
2063
+ field: field2,
2064
+ values
2065
+ }) {
2066
+ const conditionalParameters = {
2067
+ $form: values,
2068
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
2069
+ };
2070
+ const fieldValidationResult = validateFieldInput({
2071
+ field: field2,
2072
+ value: values[field2.id]
2073
+ });
2074
+ const customValidationResults = runCustomFieldValidations({
2075
+ field: field2,
2076
+ conditionalParameters
2077
+ });
2078
+ return {
2079
+ // Assumes that custom validation errors are based on the field type, and extend the validation.
2080
+ errors: [...fieldValidationResult, ...customValidationResults]
2081
+ };
2082
+ }
2083
+ function getFieldValidationErrors({
2084
+ field: field2,
2085
+ values
2086
+ }) {
2087
+ if (!isFieldVisible(field2, values) || !isFieldEnabled(field2, values)) {
2088
+ if (values[field2.id]) {
2089
+ return {
2090
+ errors: [
2091
+ {
2092
+ message: errorMessages.hiddenField
2093
+ }
2094
+ ]
2095
+ };
2096
+ }
2097
+ return {
2098
+ errors: []
2099
+ };
2100
+ }
2101
+ return runFieldValidations({
2102
+ field: field2,
2103
+ values
2104
+ });
2105
+ }
2119
2106
 
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
- });
2107
+ // ../commons/src/uuid.ts
2108
+ var import_uuid = require("uuid");
2109
+ function getUUID() {
2110
+ return (0, import_uuid.v4)();
2111
+ }
2130
2112
 
2131
- // ../commons/src/events/EventIndex.ts
2132
- var import_zod26 = require("zod");
2133
- var EventIndex = EventMetadata.extend({
2134
- declaration: import_zod26.z.record(import_zod26.z.string(), import_zod26.z.any())
2135
- });
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
- // Ensures "type" (event-id) exists and is a string
2140
- })
2141
- );
2113
+ // ../commons/src/events/utils.ts
2114
+ var import_date_fns2 = require("date-fns");
2115
+ function isDeclarationActionConfig(action) {
2116
+ return DeclarationActions.safeParse(action.type).success;
2117
+ }
2118
+ function getDeclarationFields(configuration) {
2119
+ return configuration.declaration.pages.flatMap(({ fields }) => fields);
2120
+ }
2121
+ function getDeclarationPages(configuration) {
2122
+ return configuration.declaration.pages;
2123
+ }
2124
+ function getDeclaration(configuration) {
2125
+ return configuration.declaration;
2126
+ }
2127
+ var getActionAnnotationFields = (actionConfig) => {
2128
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
2129
+ return [
2130
+ ...actionConfig.onboardingForm.flatMap(({ fields }) => fields),
2131
+ ...actionConfig.additionalDetailsForm.flatMap(({ fields }) => fields)
2132
+ ];
2133
+ }
2134
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
2135
+ return actionConfig.printForm.pages.flatMap(({ fields }) => fields);
2136
+ }
2137
+ if (isDeclarationActionConfig(actionConfig)) {
2138
+ return actionConfig.review.fields;
2139
+ }
2140
+ return [];
2141
+ };
2142
+ var getAllAnnotationFields = (config) => {
2143
+ return (0, import_lodash2.flattenDeep)(config.actions.map(getActionAnnotationFields));
2144
+ };
2145
+ var findRecordActionPages = (config, actionType) => {
2146
+ const action = config.actions.find((a) => a.type === actionType);
2147
+ if (action?.type === ActionType.REQUEST_CORRECTION) {
2148
+ return [...action.onboardingForm, ...action.additionalDetailsForm];
2149
+ }
2150
+ if (action?.type === ActionType.PRINT_CERTIFICATE) {
2151
+ return action.printForm.pages;
2152
+ }
2153
+ return [];
2154
+ };
2155
+ function getActionReview(configuration, actionType) {
2156
+ const [actionConfig] = configuration.actions.filter(
2157
+ (a) => a.type === actionType
2158
+ );
2159
+ return getOrThrow(
2160
+ actionConfig.review,
2161
+ `No review config found for ${actionType}`
2162
+ );
2163
+ }
2164
+ function getActionReviewFields(configuration, actionType) {
2165
+ return getActionReview(configuration, actionType).fields;
2166
+ }
2167
+ function validateWorkqueueConfig(workqueueConfigs) {
2168
+ workqueueConfigs.map((workqueue) => {
2169
+ const rootWorkqueue = Object.values(workqueues).find(
2170
+ (wq) => wq.id === workqueue.id
2171
+ );
2172
+ if (!rootWorkqueue) {
2173
+ throw new Error(
2174
+ `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
2175
+ );
2176
+ }
2177
+ });
2178
+ }
2179
+ function isPageVisible(page, formValues) {
2180
+ if (!page.conditional) {
2181
+ return true;
2182
+ }
2183
+ return validate(page.conditional, {
2184
+ $form: formValues,
2185
+ $now: (0, import_date_fns2.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
2186
+ });
2187
+ }
2188
+ function omitHiddenFields(fields, values) {
2189
+ return (0, import_lodash2.omitBy)(values, (_, fieldId) => {
2190
+ const field2 = fields.find((f) => f.id === fieldId);
2191
+ if (!field2) {
2192
+ return true;
2193
+ }
2194
+ return !isFieldVisible(field2, values);
2195
+ });
2196
+ }
2197
+ function omitHiddenPaginatedFields(formConfig, declaration) {
2198
+ const visiblePagesFormFields = formConfig.pages.filter((p) => isPageVisible(p, declaration)).flatMap((p) => p.fields);
2199
+ return omitHiddenFields(visiblePagesFormFields, declaration);
2200
+ }
2201
+ function findActiveDrafts(event2, drafts) {
2202
+ const actions = event2.actions.slice().filter(({ type }) => type !== ActionType.READ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2203
+ const lastAction = actions[actions.length - 1];
2204
+ return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
2205
+ }
2206
+ function createEmptyDraft(eventId, draftId, actionType) {
2207
+ return {
2208
+ id: draftId,
2209
+ eventId,
2210
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2211
+ transactionId: getUUID(),
2212
+ action: {
2213
+ type: actionType,
2214
+ declaration: {},
2215
+ annotation: {},
2216
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2217
+ createdBy: "@todo",
2218
+ createdAtLocation: "@todo"
2219
+ }
2220
+ };
2221
+ }
2222
+ function isVerificationPage(page) {
2223
+ return page.type === PageTypes.enum.VERIFICATION;
2224
+ }
2225
+ function deepMerge(currentDocument, actionDocument) {
2226
+ return (0, import_lodash2.mergeWith)(
2227
+ currentDocument,
2228
+ actionDocument,
2229
+ (previousValue, incomingValue) => {
2230
+ if (incomingValue === void 0) {
2231
+ return previousValue;
2232
+ }
2233
+ if ((0, import_lodash2.isArray)(incomingValue)) {
2234
+ return incomingValue;
2235
+ }
2236
+ if ((0, import_lodash2.isObject)(previousValue) && (0, import_lodash2.isObject)(incomingValue)) {
2237
+ return void 0;
2238
+ }
2239
+ return incomingValue;
2240
+ }
2241
+ );
2242
+ }
2243
+ function findLastAssignmentAction(actions) {
2244
+ return actions.filter(
2245
+ ({ type }) => type === ActionType.ASSIGN || type === ActionType.UNASSIGN
2246
+ ).reduce((latestAction, action) => !latestAction || action.createdAt > latestAction.createdAt ? action : latestAction, void 0);
2247
+ }
2248
+ function isWriteAction(actionType) {
2249
+ return writeActions.safeParse(actionType).success;
2250
+ }
2142
2251
 
2143
2252
  // ../commons/src/events/state/index.ts
2144
- var _ = __toESM(require("lodash"));
2145
2253
  function getStatusFromActions(actions) {
2146
2254
  const hasRejectedAction = actions.some(
2147
2255
  (a) => a.status === ActionStatus.Rejected
@@ -2205,26 +2313,27 @@ function aggregateActionDeclarations(actions) {
2205
2313
  }, {});
2206
2314
  }
2207
2315
  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
- }, {});
2316
+ if (Array.isArray(obj)) {
2317
+ return obj.map(deepDropNulls);
2318
+ }
2319
+ if (obj !== null && typeof obj === "object") {
2320
+ return Object.entries(obj).reduce((acc, [key, value]) => {
2321
+ const cleanedValue = deepDropNulls(value);
2322
+ if (cleanedValue !== null) {
2323
+ ;
2324
+ acc[key] = cleanedValue;
2325
+ }
2326
+ return acc;
2327
+ }, {});
2328
+ }
2329
+ return obj;
2221
2330
  }
2222
2331
  function isUndeclaredDraft(status) {
2223
2332
  return status === EventStatus.CREATED;
2224
2333
  }
2225
2334
  function getAcceptedActions(event2) {
2226
2335
  return event2.actions.filter(
2227
- (a) => !a.status || a.status === ActionStatus.Accepted
2336
+ (a) => a.status === ActionStatus.Accepted
2228
2337
  );
2229
2338
  }
2230
2339
  function getCurrentEventState(event2) {
@@ -2246,8 +2355,11 @@ function getCurrentEventState(event2) {
2246
2355
  status: getStatusFromActions(event2.actions),
2247
2356
  createdAt: event2.createdAt,
2248
2357
  createdBy: creationAction.createdBy,
2249
- createdAtLocation: creationAction.createdAtLocation,
2250
- modifiedAt: latestAction.createdAt,
2358
+ createdAtLocation: creationAction.createdAtLocation ?? "",
2359
+ // @todo remove using empty string
2360
+ updatedAtLocation: creationAction.updatedAtLocation ?? "",
2361
+ // @todo remove using empty string
2362
+ updatedAt: latestAction.createdAt,
2251
2363
  assignedTo: getAssignedUserFromActions(activeActions),
2252
2364
  updatedBy: latestAction.createdBy,
2253
2365
  declaration: aggregateActionDeclarations(activeActions),
@@ -2277,7 +2389,7 @@ function getCurrentEventStateWithDrafts(event2, drafts) {
2277
2389
  return getCurrentEventState(withDrafts);
2278
2390
  }
2279
2391
  function applyDraftsToEventIndex(eventIndex, drafts) {
2280
- const indexedAt = eventIndex.modifiedAt;
2392
+ const indexedAt = eventIndex.updatedAt;
2281
2393
  const activeDrafts = drafts.filter(({ createdAt }) => new Date(createdAt) > new Date(indexedAt)).map((draft) => draft.action).sort();
2282
2394
  if (activeDrafts.length === 0) {
2283
2395
  return eventIndex;
@@ -2290,20 +2402,29 @@ function applyDraftsToEventIndex(eventIndex, drafts) {
2290
2402
  }
2291
2403
  };
2292
2404
  }
2405
+ function getAnnotationFromDrafts(drafts) {
2406
+ const actions = drafts.map((draft) => draft.action);
2407
+ const annotation = actions.reduce((ann, action) => {
2408
+ return deepMerge(ann, action.annotation ?? {});
2409
+ }, {});
2410
+ return deepDropNulls(annotation);
2411
+ }
2293
2412
  function getActionAnnotation({
2294
2413
  event: event2,
2295
2414
  actionType,
2296
2415
  drafts
2297
2416
  }) {
2298
2417
  const activeActions = getAcceptedActions(event2);
2299
- const action = activeActions.find((action2) => actionType === action2.type);
2418
+ const action = activeActions.find(
2419
+ (activeAction) => actionType === activeAction.type
2420
+ );
2300
2421
  const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
2301
2422
  const sorted = [
2302
2423
  ...action ? [action] : [],
2303
2424
  ...eventDrafts.map((draft) => draft.action)
2304
2425
  ].sort();
2305
- const annotation = sorted.reduce((annotation2, action2) => {
2306
- return deepMerge(annotation2, action2.annotation ?? {});
2426
+ const annotation = sorted.reduce((ann, sortedAction) => {
2427
+ return deepMerge(ann, sortedAction.annotation ?? {});
2307
2428
  }, {});
2308
2429
  return deepDropNulls(annotation);
2309
2430
  }
@@ -2311,7 +2432,7 @@ function getActionAnnotation({
2311
2432
  // ../commons/src/events/defineConfig.ts
2312
2433
  var defineConfig = (config) => {
2313
2434
  validateWorkqueueConfig(config.workqueues);
2314
- const input = EventConfig.parse(config);
2435
+ const input = EventConfig2.parse(config);
2315
2436
  return input;
2316
2437
  };
2317
2438
 
@@ -2321,12 +2442,22 @@ function generateTransactionId() {
2321
2442
  }
2322
2443
 
2323
2444
  // ../commons/src/events/test.utils.ts
2324
- var import_lodash2 = require("lodash");
2445
+ var import_lodash3 = require("lodash");
2325
2446
 
2326
2447
  // ../commons/src/conditionals/conditionals.ts
2327
2448
  function defineConditional(schema) {
2328
2449
  return schema;
2329
2450
  }
2451
+ function defineFormConditional(schema) {
2452
+ const schemaWithForm = {
2453
+ type: "object",
2454
+ properties: {
2455
+ $form: schema
2456
+ },
2457
+ required: ["$form"]
2458
+ };
2459
+ return defineConditional(schemaWithForm);
2460
+ }
2330
2461
  function alwaysTrue() {
2331
2462
  return {};
2332
2463
  }
@@ -2351,6 +2482,9 @@ function not(condition) {
2351
2482
  required: []
2352
2483
  });
2353
2484
  }
2485
+ function never() {
2486
+ return not(alwaysTrue());
2487
+ }
2354
2488
  var user = {
2355
2489
  hasScope: (scope) => defineConditional({
2356
2490
  type: "object",
@@ -2398,100 +2532,118 @@ var event = {
2398
2532
  required: ["$event"]
2399
2533
  })
2400
2534
  };
2535
+ function getDateFromNow(days) {
2536
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2537
+ }
2538
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2539
+ return {
2540
+ type: "object",
2541
+ properties: {
2542
+ [fieldId]: {
2543
+ type: "string",
2544
+ format: "date",
2545
+ [clause]: { $data: `1/${comparedFieldId}` }
2546
+ },
2547
+ [comparedFieldId]: { type: "string", format: "date" }
2548
+ },
2549
+ required: [fieldId]
2550
+ };
2551
+ }
2552
+ function isFieldReference(value) {
2553
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2554
+ }
2401
2555
  function field(fieldId) {
2402
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2403
2556
  const getDateRange = (date, clause) => ({
2404
2557
  type: "object",
2405
2558
  properties: {
2406
- $form: {
2407
- type: "object",
2408
- properties: {
2409
- [fieldId]: {
2410
- type: "string",
2411
- format: "date",
2412
- [clause]: date
2413
- }
2414
- },
2415
- required: [fieldId]
2559
+ [fieldId]: {
2560
+ type: "string",
2561
+ format: "date",
2562
+ [clause]: date
2416
2563
  }
2417
2564
  },
2418
- required: ["$form"]
2565
+ required: [fieldId]
2419
2566
  });
2420
2567
  return {
2421
2568
  /**
2422
2569
  * @private Internal property used for field reference tracking.
2423
2570
  */
2424
- _returning: fieldId,
2571
+ _fieldId: fieldId,
2425
2572
  isAfter: () => ({
2426
2573
  days: (days) => ({
2427
- inPast: () => defineConditional(
2574
+ inPast: () => defineFormConditional(
2428
2575
  getDateRange(getDateFromNow(days), "formatMinimum")
2429
2576
  ),
2430
- inFuture: () => defineConditional(
2577
+ inFuture: () => defineFormConditional(
2431
2578
  getDateRange(getDateFromNow(-days), "formatMinimum")
2432
2579
  )
2433
2580
  }),
2434
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
2435
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2581
+ date: (date) => {
2582
+ if (isFieldReference(date)) {
2583
+ const comparedFieldId = date._fieldId;
2584
+ return defineFormConditional(
2585
+ getDateRangeToFieldReference(
2586
+ fieldId,
2587
+ comparedFieldId,
2588
+ "formatMinimum"
2589
+ )
2590
+ );
2591
+ }
2592
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2593
+ },
2594
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2436
2595
  }),
2437
2596
  isBefore: () => ({
2438
2597
  days: (days) => ({
2439
- inPast: () => defineConditional(
2598
+ inPast: () => defineFormConditional(
2440
2599
  getDateRange(getDateFromNow(days), "formatMaximum")
2441
2600
  ),
2442
- inFuture: () => defineConditional(
2601
+ inFuture: () => defineFormConditional(
2443
2602
  getDateRange(getDateFromNow(-days), "formatMaximum")
2444
2603
  )
2445
2604
  }),
2446
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
2447
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2605
+ date: (date) => {
2606
+ if (isFieldReference(date)) {
2607
+ const comparedFieldId = date._fieldId;
2608
+ return defineFormConditional(
2609
+ getDateRangeToFieldReference(
2610
+ fieldId,
2611
+ comparedFieldId,
2612
+ "formatMaximum"
2613
+ )
2614
+ );
2615
+ }
2616
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2617
+ },
2618
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2448
2619
  }),
2449
- // TODO CIHAN: typing
2450
2620
  isEqualTo: (value) => {
2451
- if (typeof value === "object" && value._returning) {
2452
- const comparedFieldId = value._returning;
2453
- return defineConditional({
2621
+ if (isFieldReference(value)) {
2622
+ const comparedFieldId = value._fieldId;
2623
+ return defineFormConditional({
2454
2624
  type: "object",
2455
2625
  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
- }
2626
+ [fieldId]: {
2627
+ type: ["string", "boolean"],
2628
+ const: { $data: `1/${comparedFieldId}` }
2629
+ },
2630
+ [comparedFieldId]: { type: ["string", "boolean"] }
2473
2631
  },
2474
- required: ["$form"]
2632
+ required: [fieldId, comparedFieldId]
2475
2633
  });
2476
2634
  }
2477
- return defineConditional({
2635
+ return defineFormConditional({
2478
2636
  type: "object",
2479
2637
  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]
2638
+ [fieldId]: {
2639
+ oneOf: [
2640
+ { type: "string", const: value },
2641
+ { type: "boolean", const: value }
2642
+ ],
2643
+ const: value
2492
2644
  }
2493
2645
  },
2494
- required: ["$form"]
2646
+ required: [fieldId]
2495
2647
  });
2496
2648
  },
2497
2649
  /**
@@ -2502,143 +2654,138 @@ function field(fieldId) {
2502
2654
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2503
2655
  *
2504
2656
  */
2505
- isFalsy: () => defineConditional({
2657
+ isFalsy: () => defineFormConditional({
2506
2658
  type: "object",
2507
2659
  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
- },
2660
+ [fieldId]: {
2520
2661
  anyOf: [
2521
- {
2522
- required: [fieldId]
2523
- },
2524
- {
2525
- not: {
2526
- required: [fieldId]
2527
- }
2528
- }
2662
+ { const: "undefined" },
2663
+ { const: false },
2664
+ { const: null },
2665
+ { const: "" }
2529
2666
  ]
2530
2667
  }
2531
2668
  },
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
- },
2669
+ anyOf: [
2670
+ {
2671
+ required: [fieldId]
2672
+ },
2673
+ {
2545
2674
  not: {
2546
2675
  required: [fieldId]
2547
2676
  }
2548
2677
  }
2549
- },
2550
- required: ["$form"]
2678
+ ]
2551
2679
  }),
2552
- inArray: (values) => defineConditional({
2680
+ isUndefined: () => defineFormConditional({
2553
2681
  type: "object",
2554
2682
  properties: {
2555
- $form: {
2556
- type: "object",
2557
- properties: {
2558
- [fieldId]: {
2559
- type: "string",
2560
- enum: values
2561
- }
2562
- },
2563
- required: [fieldId]
2683
+ [fieldId]: {
2684
+ type: "string",
2685
+ enum: ["undefined"]
2564
2686
  }
2565
2687
  },
2566
- required: ["$form"]
2688
+ not: {
2689
+ required: [fieldId]
2690
+ }
2567
2691
  }),
2568
- isValidEnglishName: () => defineConditional({
2692
+ inArray: (values) => defineFormConditional({
2569
2693
  type: "object",
2570
2694
  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]
2695
+ [fieldId]: {
2696
+ type: "string",
2697
+ enum: values
2581
2698
  }
2582
2699
  },
2583
- required: ["$form"]
2700
+ required: [fieldId]
2584
2701
  }),
2585
- isValidNationalId: () => defineConditional({
2702
+ isValidEnglishName: () => defineFormConditional({
2586
2703
  type: "object",
2587
2704
  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]
2705
+ [fieldId]: {
2706
+ type: "string",
2707
+ 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'._-]*)*$",
2708
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2598
2709
  }
2599
2710
  },
2600
- required: ["$form"]
2711
+ required: [fieldId]
2601
2712
  }),
2602
2713
  /**
2603
2714
  * Checks if the field value matches a given regular expression pattern.
2604
2715
  * @param pattern - The regular expression pattern to match the field value against.
2605
2716
  * @returns A JSONSchema conditional that validates the field value against the pattern.
2606
2717
  */
2607
- matches: (pattern) => defineConditional({
2718
+ matches: (pattern) => defineFormConditional({
2608
2719
  type: "object",
2609
2720
  properties: {
2610
- $form: {
2611
- type: "object",
2612
- properties: {
2613
- [fieldId]: {
2614
- type: "string",
2615
- pattern
2616
- }
2617
- },
2618
- required: [fieldId]
2721
+ [fieldId]: {
2722
+ type: "string",
2723
+ pattern
2619
2724
  }
2620
2725
  },
2621
- required: ["$form"]
2726
+ required: [fieldId]
2622
2727
  }),
2623
- isBetween: (min, max) => defineConditional({
2728
+ isBetween: (min, max) => defineFormConditional({
2624
2729
  type: "object",
2625
2730
  properties: {
2626
- $form: {
2627
- type: "object",
2628
- properties: {
2629
- [fieldId]: {
2630
- type: "number",
2631
- minimum: min,
2632
- maximum: max
2633
- }
2634
- },
2635
- required: [fieldId]
2731
+ [fieldId]: {
2732
+ type: "number",
2733
+ minimum: min,
2734
+ maximum: max
2636
2735
  }
2637
2736
  },
2638
- required: ["$form"]
2737
+ required: [fieldId]
2738
+ }),
2739
+ /**
2740
+ * Creates a range configuration for the specified field.
2741
+ *
2742
+ * @returns An object containing the field ID and a configuration object with a type of 'RANGE'.
2743
+ *
2744
+ * @example field('age').range()
2745
+ * // {
2746
+ * // fieldId: 'age',
2747
+ * // config: { type: 'RANGE' }
2748
+ * // }
2749
+ */
2750
+ range: () => ({
2751
+ fieldId,
2752
+ config: { type: "RANGE" }
2753
+ }),
2754
+ /**
2755
+ * Creates a configuration for exact matching of the specified field.
2756
+ * @returns An object containing the field ID and a configuration object with a type of 'EXACT'.
2757
+ * @example field('dob').exact()
2758
+ * // {
2759
+ * // fieldId: 'dob',
2760
+ * // config: { type: 'EXACT' }
2761
+ * // }
2762
+ */
2763
+ exact: () => ({
2764
+ fieldId,
2765
+ config: { type: "EXACT" }
2766
+ }),
2767
+ /**
2768
+ * Creates a configuration for fuzzy matching of the specified field.
2769
+ * @returns An object containing the field ID and a configuration object with a type of 'EXACT'.
2770
+ * @example field('name').fuzzy()
2771
+ * // {
2772
+ * // fieldId: 'name',
2773
+ * // config: { type: 'FUZZY' }
2774
+ * // }
2775
+ */
2776
+ fuzzy: () => ({
2777
+ fieldId,
2778
+ config: { type: "FUZZY" }
2639
2779
  })
2640
2780
  };
2641
2781
  }
2782
+ function eventField(fieldId, options) {
2783
+ return {
2784
+ fieldId,
2785
+ options,
2786
+ config: { type: "EXACT" }
2787
+ };
2788
+ }
2642
2789
 
2643
2790
  // ../commons/src/fixtures/tennis-club-membership-event.ts
2644
2791
  var PRINT_CERTIFICATE_FORM = defineActionForm({
@@ -3378,9 +3525,8 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3378
3525
  },
3379
3526
  {
3380
3527
  id: "applicant.dob",
3381
- type: "DATE",
3528
+ type: FieldType.DATE,
3382
3529
  required: true,
3383
- conditionals: [],
3384
3530
  validation: [
3385
3531
  {
3386
3532
  message: {
@@ -3391,12 +3537,50 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3391
3537
  validator: field("applicant.dob").isBefore().now()
3392
3538
  }
3393
3539
  ],
3540
+ conditionals: [
3541
+ {
3542
+ type: ConditionalType.SHOW,
3543
+ conditional: field("applicant.dobUnknown").isFalsy()
3544
+ }
3545
+ ],
3394
3546
  label: {
3395
3547
  defaultMessage: "Applicant's date of birth",
3396
3548
  description: "This is the label for the field",
3397
3549
  id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dob.label"
3398
3550
  }
3399
3551
  },
3552
+ {
3553
+ id: "applicant.dobUnknown",
3554
+ type: FieldType.CHECKBOX,
3555
+ required: false,
3556
+ label: {
3557
+ defaultMessage: "Exact date of birth unknown",
3558
+ description: "This is the label for the field",
3559
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dobUnknown.label"
3560
+ },
3561
+ conditionals: [
3562
+ {
3563
+ type: ConditionalType.DISPLAY_ON_REVIEW,
3564
+ conditional: never()
3565
+ }
3566
+ ]
3567
+ },
3568
+ {
3569
+ id: "applicant.age",
3570
+ type: FieldType.NUMBER,
3571
+ required: true,
3572
+ label: {
3573
+ defaultMessage: "Age of tennis-member",
3574
+ description: "This is the label for the field",
3575
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.age.label"
3576
+ },
3577
+ conditionals: [
3578
+ {
3579
+ type: ConditionalType.SHOW,
3580
+ conditional: field("applicant.dobUnknown").isEqualTo(true)
3581
+ }
3582
+ ]
3583
+ },
3400
3584
  {
3401
3585
  id: "applicant.image",
3402
3586
  type: FieldType.FILE,
@@ -3901,18 +4085,14 @@ var tennisClubMembershipEvent = defineConfig({
3901
4085
  description: "This is what this event is referred as in the system",
3902
4086
  id: "v2.event.tennis-club-membership.search"
3903
4087
  },
3904
- fields: [
3905
- {
3906
- fieldId: "applicant.dob"
3907
- }
3908
- ]
4088
+ fields: [field("applicant.dob").exact()]
3909
4089
  }
3910
4090
  ],
3911
4091
  declaration: TENNIS_CLUB_DECLARATION_FORM
3912
4092
  });
3913
4093
 
3914
4094
  // ../commons/src/events/test.utils.ts
3915
- function fieldConfigsToActionAnnotation(fields) {
4095
+ function fieldConfigsToActionPayload(fields) {
3916
4096
  return fields.reduce(
3917
4097
  (acc, field2, i) => ({
3918
4098
  ...acc,
@@ -3921,23 +4101,27 @@ function fieldConfigsToActionAnnotation(fields) {
3921
4101
  {}
3922
4102
  );
3923
4103
  }
3924
- function generateActionInput(configuration, action) {
4104
+ function generateActionDeclarationInput(configuration, action) {
3925
4105
  const parsed = DeclarationUpdateActions.safeParse(action);
3926
4106
  if (parsed.success) {
3927
4107
  const fields = getDeclarationFields(configuration);
3928
- const annotation = fieldConfigsToActionAnnotation(fields);
3929
- return stripHiddenFields(fields, annotation);
4108
+ const declarationConfig = getDeclaration(configuration);
4109
+ const declaration = fieldConfigsToActionPayload(fields);
4110
+ return omitHiddenPaginatedFields(declarationConfig, declaration);
3930
4111
  }
3931
4112
  console.warn(`${action} is not a declaration action. Setting data as {}.`);
3932
4113
  return {};
3933
4114
  }
3934
- function generateActionMetadataInput(configuration, action) {
4115
+ function generateActionAnnotationInput(configuration, action) {
3935
4116
  const actionConfig = configuration.actions.find(
3936
- (actionConfig2) => actionConfig2.type === action
4117
+ (ac) => ac.type === action
3937
4118
  );
3938
4119
  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) ?? [];
4120
+ const annotation = fieldConfigsToActionPayload(annotationFields);
4121
+ const visibleVerificationPageIds = findRecordActionPages(
4122
+ configuration,
4123
+ action
4124
+ ).filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
3941
4125
  const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
3942
4126
  (acc, pageId) => ({
3943
4127
  ...acc,
@@ -3945,7 +4129,7 @@ function generateActionMetadataInput(configuration, action) {
3945
4129
  }),
3946
4130
  {}
3947
4131
  );
3948
- const fieldBasedPayload = stripHiddenFields(annotationFields, annotation);
4132
+ const fieldBasedPayload = omitHiddenFields(annotationFields, annotation);
3949
4133
  return {
3950
4134
  ...fieldBasedPayload,
3951
4135
  ...visiblePageVerificationMap
@@ -3961,14 +4145,15 @@ var eventPayloadGenerator = {
3961
4145
  type: input.type ?? "TENNIS_CLUB_MEMBERSHIP",
3962
4146
  id
3963
4147
  }),
3964
- draft: (eventId, input = {}) => (0, import_lodash2.merge)(
4148
+ draft: ({ eventId, actionType }, input = {}) => (0, import_lodash3.merge)(
3965
4149
  {
3966
4150
  id: getUUID(),
3967
4151
  eventId,
3968
4152
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3969
4153
  transactionId: getUUID(),
3970
4154
  action: {
3971
- type: ActionType.REQUEST_CORRECTION,
4155
+ type: actionType,
4156
+ status: ActionStatus.Accepted,
3972
4157
  declaration: {
3973
4158
  "applicant.firstname": "Max",
3974
4159
  "applicant.surname": "McLaren",
@@ -3981,7 +4166,8 @@ var eventPayloadGenerator = {
3981
4166
  },
3982
4167
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3983
4168
  createdBy: "@todo",
3984
- createdAtLocation: "@todo"
4169
+ createdAtLocation: "@todo",
4170
+ updatedAtLocation: "@todo"
3985
4171
  }
3986
4172
  },
3987
4173
  input
@@ -3990,8 +4176,11 @@ var eventPayloadGenerator = {
3990
4176
  declare: (eventId, input = {}) => ({
3991
4177
  type: ActionType.DECLARE,
3992
4178
  transactionId: input.transactionId ?? getUUID(),
3993
- declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
3994
- annotation: input.annotation ?? generateActionMetadataInput(
4179
+ declaration: input.declaration ?? generateActionDeclarationInput(
4180
+ tennisClubMembershipEvent,
4181
+ ActionType.DECLARE
4182
+ ),
4183
+ annotation: input.annotation ?? generateActionAnnotationInput(
3995
4184
  tennisClubMembershipEvent,
3996
4185
  ActionType.DECLARE
3997
4186
  ),
@@ -4003,9 +4192,12 @@ var eventPayloadGenerator = {
4003
4192
  notify: (eventId, input = {}) => {
4004
4193
  let declaration = input.declaration;
4005
4194
  if (!declaration) {
4006
- const partialDeclaration = (0, import_lodash2.omitBy)(
4007
- generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4008
- import_lodash2.isString
4195
+ const partialDeclaration = (0, import_lodash3.omitBy)(
4196
+ generateActionDeclarationInput(
4197
+ tennisClubMembershipEvent,
4198
+ ActionType.DECLARE
4199
+ ),
4200
+ import_lodash3.isString
4009
4201
  );
4010
4202
  declaration = partialDeclaration;
4011
4203
  }
@@ -4019,14 +4211,31 @@ var eventPayloadGenerator = {
4019
4211
  validate: (eventId, input = {}) => ({
4020
4212
  type: ActionType.VALIDATE,
4021
4213
  transactionId: input.transactionId ?? getUUID(),
4022
- declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4023
- annotation: input.annotation ?? generateActionMetadataInput(
4214
+ declaration: input.declaration ?? generateActionDeclarationInput(
4215
+ tennisClubMembershipEvent,
4216
+ ActionType.VALIDATE
4217
+ ),
4218
+ annotation: input.annotation ?? generateActionAnnotationInput(
4024
4219
  tennisClubMembershipEvent,
4025
4220
  ActionType.VALIDATE
4026
4221
  ),
4027
4222
  duplicates: [],
4028
4223
  eventId
4029
4224
  }),
4225
+ assign: (eventId, input = {}) => ({
4226
+ type: ActionType.ASSIGN,
4227
+ transactionId: input.transactionId ?? getUUID(),
4228
+ declaration: {},
4229
+ assignedTo: input.assignedTo ?? getUUID(),
4230
+ eventId
4231
+ }),
4232
+ unassign: (eventId, input = {}) => ({
4233
+ type: ActionType.UNASSIGN,
4234
+ transactionId: input.transactionId ?? getUUID(),
4235
+ declaration: {},
4236
+ assignedTo: null,
4237
+ eventId
4238
+ }),
4030
4239
  archive: (eventId, input = {}, isDuplicate) => ({
4031
4240
  type: ActionType.ARCHIVE,
4032
4241
  transactionId: input.transactionId ?? getUUID(),
@@ -4040,7 +4249,7 @@ var eventPayloadGenerator = {
4040
4249
  type: ActionType.REJECT,
4041
4250
  transactionId: input.transactionId ?? getUUID(),
4042
4251
  declaration: {},
4043
- annotation: input.annotation ?? generateActionMetadataInput(
4252
+ annotation: input.annotation ?? generateActionAnnotationInput(
4044
4253
  tennisClubMembershipEvent,
4045
4254
  ActionType.REJECT
4046
4255
  ),
@@ -4050,8 +4259,11 @@ var eventPayloadGenerator = {
4050
4259
  register: (eventId, input = {}) => ({
4051
4260
  type: ActionType.REGISTER,
4052
4261
  transactionId: input.transactionId ?? getUUID(),
4053
- declaration: input.declaration ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4054
- annotation: input.annotation ?? generateActionMetadataInput(
4262
+ declaration: input.declaration ?? generateActionDeclarationInput(
4263
+ tennisClubMembershipEvent,
4264
+ ActionType.REGISTER
4265
+ ),
4266
+ annotation: input.annotation ?? generateActionAnnotationInput(
4055
4267
  tennisClubMembershipEvent,
4056
4268
  ActionType.REGISTER
4057
4269
  ),
@@ -4061,7 +4273,7 @@ var eventPayloadGenerator = {
4061
4273
  type: ActionType.PRINT_CERTIFICATE,
4062
4274
  transactionId: input.transactionId ?? getUUID(),
4063
4275
  declaration: {},
4064
- annotation: input.annotation ?? generateActionMetadataInput(
4276
+ annotation: input.annotation ?? generateActionAnnotationInput(
4065
4277
  tennisClubMembershipEvent,
4066
4278
  ActionType.PRINT_CERTIFICATE
4067
4279
  ),
@@ -4071,11 +4283,11 @@ var eventPayloadGenerator = {
4071
4283
  request: (eventId, input = {}) => ({
4072
4284
  type: ActionType.REQUEST_CORRECTION,
4073
4285
  transactionId: input.transactionId ?? getUUID(),
4074
- declaration: input.declaration ?? generateActionInput(
4286
+ declaration: input.declaration ?? generateActionDeclarationInput(
4075
4287
  tennisClubMembershipEvent,
4076
4288
  ActionType.REQUEST_CORRECTION
4077
4289
  ),
4078
- annotation: input.annotation ?? generateActionMetadataInput(
4290
+ annotation: input.annotation ?? generateActionAnnotationInput(
4079
4291
  tennisClubMembershipEvent,
4080
4292
  ActionType.REQUEST_CORRECTION
4081
4293
  ),
@@ -4085,7 +4297,7 @@ var eventPayloadGenerator = {
4085
4297
  type: ActionType.APPROVE_CORRECTION,
4086
4298
  transactionId: input.transactionId ?? getUUID(),
4087
4299
  declaration: {},
4088
- annotation: input.annotation ?? generateActionMetadataInput(
4300
+ annotation: input.annotation ?? generateActionAnnotationInput(
4089
4301
  tennisClubMembershipEvent,
4090
4302
  ActionType.APPROVE_CORRECTION
4091
4303
  ),
@@ -4096,7 +4308,7 @@ var eventPayloadGenerator = {
4096
4308
  type: ActionType.REJECT_CORRECTION,
4097
4309
  transactionId: input.transactionId ?? getUUID(),
4098
4310
  declaration: {},
4099
- annotation: input.annotation ?? generateActionMetadataInput(
4311
+ annotation: input.annotation ?? generateActionAnnotationInput(
4100
4312
  tennisClubMembershipEvent,
4101
4313
  ActionType.REJECT_CORRECTION
4102
4314
  ),
@@ -4118,16 +4330,21 @@ function generateActionDocument({
4118
4330
  createdBy: getUUID(),
4119
4331
  id: getUUID(),
4120
4332
  createdAtLocation: "TODO",
4121
- declaration: generateActionInput(configuration, action),
4333
+ updatedAtLocation: "TODO",
4334
+ declaration: generateActionDeclarationInput(configuration, action),
4122
4335
  annotation: {},
4123
4336
  ...defaults,
4124
4337
  status: ActionStatus.Accepted
4125
4338
  };
4126
4339
  switch (action) {
4340
+ case ActionType.READ:
4341
+ return { ...actionBase, type: action };
4342
+ case ActionType.MARKED_AS_DUPLICATE:
4343
+ return { ...actionBase, type: action };
4127
4344
  case ActionType.DECLARE:
4128
4345
  return { ...actionBase, type: action };
4129
4346
  case ActionType.UNASSIGN:
4130
- return { ...actionBase, type: action };
4347
+ return { ...actionBase, type: action, assignedTo: null };
4131
4348
  case ActionType.ASSIGN:
4132
4349
  return { ...actionBase, assignedTo: getUUID(), type: action };
4133
4350
  case ActionType.VALIDATE:
@@ -4153,6 +4370,8 @@ function generateActionDocument({
4153
4370
  ...actionBase,
4154
4371
  type: action
4155
4372
  };
4373
+ case ActionType.DELETE:
4374
+ case ActionType.DETECT_DUPLICATE:
4156
4375
  default:
4157
4376
  throw new Error(`Unsupported action type: ${action}`);
4158
4377
  }
@@ -4202,7 +4421,8 @@ var eventQueryDataGenerator = (overrides = {}) => ({
4202
4421
  createdAt: overrides.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4203
4422
  createdBy: overrides.createdBy ?? getUUID(),
4204
4423
  createdAtLocation: overrides.createdAtLocation ?? getUUID(),
4205
- modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4424
+ updatedAtLocation: overrides.updatedAtLocation ?? getUUID(),
4425
+ updatedAt: overrides.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4206
4426
  assignedTo: overrides.assignedTo ?? null,
4207
4427
  updatedBy: overrides.updatedBy ?? getUUID(),
4208
4428
  declaration: overrides.declaration ?? {
@@ -4236,7 +4456,9 @@ function isFieldValueWithoutTemplates(value) {
4236
4456
  return true;
4237
4457
  }
4238
4458
  function isFieldConfigDefaultValue(value) {
4239
- if (!value) return false;
4459
+ if (!value) {
4460
+ return false;
4461
+ }
4240
4462
  if (isFieldValue(value)) {
4241
4463
  return true;
4242
4464
  }