@opencrvs/toolkit 1.8.0-rc.feef45c → 1.8.0-rc.ff0a1b5

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.
@@ -36,6 +36,7 @@ __export(events_exports, {
36
36
  ActionConditional: () => ActionConditional,
37
37
  ActionConfig: () => ActionConfig,
38
38
  ActionConfigBase: () => ActionConfigBase,
39
+ ActionCreationMetadata: () => ActionCreationMetadata,
39
40
  ActionDocument: () => ActionDocument,
40
41
  ActionFormConfig: () => ActionFormConfig,
41
42
  ActionInput: () => ActionInput,
@@ -62,9 +63,13 @@ __export(events_exports, {
62
63
  Conditional: () => Conditional,
63
64
  ConditionalType: () => ConditionalType,
64
65
  ConfirmableActions: () => ConfirmableActions,
66
+ CustomFlags: () => CustomFlags,
67
+ DEFAULT_DATE_OF_EVENT_PROPERTY: () => DEFAULT_DATE_OF_EVENT_PROPERTY,
65
68
  DataEntry: () => DataEntry,
66
69
  DataFieldValue: () => DataFieldValue,
70
+ DateRangeFieldValue: () => DateRangeFieldValue,
67
71
  DateValue: () => DateValue,
72
+ DatetimeValue: () => DatetimeValue,
68
73
  DeclarationActionConfig: () => DeclarationActionConfig,
69
74
  DeclarationActions: () => DeclarationActions,
70
75
  DeclarationFormConfig: () => DeclarationFormConfig,
@@ -86,7 +91,10 @@ __export(events_exports, {
86
91
  EventIndex: () => EventIndex,
87
92
  EventInput: () => EventInput,
88
93
  EventMetadata: () => EventMetadata,
94
+ EventMetadataKeys: () => EventMetadataKeys,
95
+ EventMetadataParameter: () => EventMetadataParameter,
89
96
  EventSearchIndex: () => EventSearchIndex,
97
+ EventState: () => EventState,
90
98
  EventStatus: () => EventStatus,
91
99
  EventStatuses: () => EventStatuses,
92
100
  FieldConditional: () => FieldConditional,
@@ -98,6 +106,7 @@ __export(events_exports, {
98
106
  FileFieldValue: () => FileFieldValue,
99
107
  FileFieldValueWithOption: () => FileFieldValueWithOption,
100
108
  FileFieldWithOptionValue: () => FileFieldWithOptionValue,
109
+ Flag: () => Flag,
101
110
  FormConfig: () => FormConfig,
102
111
  FormPageConfig: () => FormPageConfig,
103
112
  GenericAddressUpdateValue: () => GenericAddressUpdateValue,
@@ -105,8 +114,8 @@ __export(events_exports, {
105
114
  GeographicalArea: () => GeographicalArea,
106
115
  ImageMimeType: () => ImageMimeType,
107
116
  LanguageConfig: () => LanguageConfig,
117
+ LegalStatuses: () => LegalStatuses,
108
118
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
109
- MatchType: () => MatchType,
110
119
  MimeType: () => MimeType,
111
120
  NonEmptyTextValue: () => NonEmptyTextValue,
112
121
  NotifyActionInput: () => NotifyActionInput,
@@ -119,6 +128,7 @@ __export(events_exports, {
119
128
  ReadActionInput: () => ReadActionInput,
120
129
  RegisterAction: () => RegisterAction,
121
130
  RegisterActionInput: () => RegisterActionInput,
131
+ RegistrationCreationMetadata: () => RegistrationCreationMetadata,
122
132
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
123
133
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
124
134
  RequestCorrectionActionInput: () => RequestCorrectionActionInput,
@@ -192,6 +202,7 @@ __export(events_exports, {
192
202
  getDeclaration: () => getDeclaration,
193
203
  getDeclarationFields: () => getDeclarationFields,
194
204
  getDeclarationPages: () => getDeclarationPages,
205
+ getMixedPath: () => getMixedPath,
195
206
  getVisibleVerificationPageIds: () => getVisibleVerificationPageIds,
196
207
  hasAnyOfScopes: () => hasAnyOfScopes,
197
208
  isAddressFieldType: () => isAddressFieldType,
@@ -202,6 +213,7 @@ __export(events_exports, {
202
213
  isCountryFieldType: () => isCountryFieldType,
203
214
  isDataFieldType: () => isDataFieldType,
204
215
  isDateFieldType: () => isDateFieldType,
216
+ isDateRangeFieldType: () => isDateRangeFieldType,
205
217
  isDividerFieldType: () => isDividerFieldType,
206
218
  isEmailFieldType: () => isEmailFieldType,
207
219
  isFacilityFieldType: () => isFacilityFieldType,
@@ -317,6 +329,7 @@ var FieldType = {
317
329
  TEXTAREA: "TEXTAREA",
318
330
  EMAIL: "EMAIL",
319
331
  DATE: "DATE",
332
+ DATE_RANGE: "DATE_RANGE",
320
333
  PARAGRAPH: "PARAGRAPH",
321
334
  PAGE_HEADER: "PAGE_HEADER",
322
335
  RADIO_GROUP: "RADIO_GROUP",
@@ -336,6 +349,7 @@ var FieldType = {
336
349
  };
337
350
  var fieldTypes = Object.values(FieldType);
338
351
  var compositeFieldTypes = [
352
+ FieldType.DATE_RANGE,
339
353
  FieldType.ADDRESS,
340
354
  FieldType.FILE_WITH_OPTIONS,
341
355
  FieldType.FILE
@@ -428,6 +442,8 @@ var FileFieldWithOptionValue = import_zod3.z.array(FileFieldValueWithOption);
428
442
  var TextValue = import_zod4.z.string();
429
443
  var NonEmptyTextValue = TextValue.min(1);
430
444
  var DateValue = import_zod4.z.string().date().describe("Date in the format YYYY-MM-DD");
445
+ var DatetimeValue = import_zod4.z.string().datetime();
446
+ var DateRangeFieldValue = DateValue.or(import_zod4.z.tuple([DateValue, DateValue]));
431
447
  var EmailValue = import_zod4.z.string().email();
432
448
  var CheckboxFieldValue = import_zod4.z.boolean();
433
449
  var NumberFieldValue = import_zod4.z.number();
@@ -435,6 +451,7 @@ var DataFieldValue = import_zod4.z.undefined();
435
451
  var FieldValue = import_zod4.z.union([
436
452
  TextValue,
437
453
  DateValue,
454
+ DateRangeFieldValue,
438
455
  CheckboxFieldValue,
439
456
  NumberFieldValue,
440
457
  FileFieldValue,
@@ -447,6 +464,7 @@ var FieldValue = import_zod4.z.union([
447
464
  var FieldUpdateValue = import_zod4.z.union([
448
465
  TextValue,
449
466
  DateValue,
467
+ DateRangeFieldValue,
450
468
  CheckboxFieldValue,
451
469
  NumberFieldValue,
452
470
  FileFieldValue,
@@ -554,6 +572,17 @@ var DateField = BaseField.extend({
554
572
  ).optional()
555
573
  }).optional()
556
574
  }).describe("A single date input (dd-mm-YYYY)");
575
+ var DateRangeField = BaseField.extend({
576
+ type: import_zod5.z.literal(FieldType.DATE_RANGE),
577
+ defaultValue: DateRangeFieldValue.optional(),
578
+ configuration: import_zod5.z.object({
579
+ notice: TranslationConfig.describe(
580
+ "Text to display above the date input"
581
+ ).optional()
582
+ }).optional()
583
+ }).describe(
584
+ "A date range input ({ rangeStart: dd-mm-YYYY, rangeEnd: dd-mm-YYYY })"
585
+ );
557
586
  var HtmlFontVariant = import_zod5.z.enum([
558
587
  "reg12",
559
588
  "reg14",
@@ -693,6 +722,7 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
693
722
  NumberField,
694
723
  TextAreaField,
695
724
  DateField,
725
+ DateRangeField,
696
726
  Paragraph,
697
727
  RadioGroup,
698
728
  BulletList,
@@ -974,7 +1004,7 @@ var LanguageConfig = import_zod11.z.object({
974
1004
  });
975
1005
 
976
1006
  // ../commons/src/events/EventConfig.ts
977
- var import_zod16 = require("zod");
1007
+ var import_zod17 = require("zod");
978
1008
 
979
1009
  // ../commons/src/events/DeduplicationConfig.ts
980
1010
  var import_zod12 = require("zod");
@@ -1056,7 +1086,10 @@ var BaseField2 = import_zod13.z.object({
1056
1086
  conditionals: import_zod13.z.array(ShowConditional).default([]).optional()
1057
1087
  });
1058
1088
  var ReferenceField = BaseField2.extend({
1059
- fieldId: import_zod13.z.string()
1089
+ fieldId: import_zod13.z.string(),
1090
+ label: TranslationConfig.optional().describe(
1091
+ "By default, the configured field's label is used. This can be overridden by providing a custom label."
1092
+ )
1060
1093
  }).describe("Field directly referencing event data with field id");
1061
1094
  var Field = BaseField2.extend({
1062
1095
  id: import_zod13.z.string().describe("Id of summary field"),
@@ -1072,7 +1105,7 @@ var SummaryConfig = import_zod13.z.object({
1072
1105
 
1073
1106
  // ../commons/src/events/AdvancedSearchConfig.ts
1074
1107
  var import_zod14 = require("zod");
1075
- var MatchType = import_zod14.z.enum(["FUZZY", "EXACT", "RANGE", "ANY_OF"]);
1108
+ var MatchType = import_zod14.z.enum(["fuzzy", "exact", "range"]);
1076
1109
  var BaseField3 = import_zod14.z.object({
1077
1110
  config: import_zod14.z.object({
1078
1111
  type: MatchType.describe("Determines the type of field")
@@ -1100,13 +1133,162 @@ var AdvancedSearchConfig = import_zod14.z.object({
1100
1133
  // ../commons/src/events/utils.ts
1101
1134
  var import_lodash = require("lodash");
1102
1135
 
1136
+ // ../commons/src/events/ActionDocument.ts
1137
+ var import_zod15 = require("zod");
1138
+ var import_zod_openapi3 = require("zod-openapi");
1139
+ (0, import_zod_openapi3.extendZodWithOpenApi)(import_zod15.z);
1140
+ var ActionUpdate = import_zod15.z.record(import_zod15.z.string(), FieldUpdateValue);
1141
+ var EventState = import_zod15.z.record(import_zod15.z.string(), FieldValue);
1142
+ var ActionStatus = {
1143
+ Requested: "Requested",
1144
+ Accepted: "Accepted",
1145
+ Rejected: "Rejected"
1146
+ };
1147
+ var ActionBase = import_zod15.z.object({
1148
+ id: import_zod15.z.string(),
1149
+ transactionId: import_zod15.z.string(),
1150
+ createdAt: import_zod15.z.string().datetime(),
1151
+ createdBy: import_zod15.z.string(),
1152
+ createdByRole: import_zod15.z.string(),
1153
+ declaration: ActionUpdate,
1154
+ annotation: ActionUpdate.optional(),
1155
+ createdAtLocation: import_zod15.z.string(),
1156
+ status: import_zod15.z.enum([
1157
+ ActionStatus.Requested,
1158
+ ActionStatus.Accepted,
1159
+ ActionStatus.Rejected
1160
+ ]),
1161
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1162
+ originalActionId: import_zod15.z.string().optional()
1163
+ });
1164
+ var AssignedAction = ActionBase.merge(
1165
+ import_zod15.z.object({
1166
+ type: import_zod15.z.literal(ActionType.ASSIGN),
1167
+ assignedTo: import_zod15.z.string()
1168
+ })
1169
+ );
1170
+ var UnassignedAction = ActionBase.merge(
1171
+ import_zod15.z.object({
1172
+ type: import_zod15.z.literal(ActionType.UNASSIGN),
1173
+ assignedTo: import_zod15.z.literal(null)
1174
+ })
1175
+ );
1176
+ var RegisterAction = ActionBase.merge(
1177
+ import_zod15.z.object({
1178
+ type: import_zod15.z.literal(ActionType.REGISTER),
1179
+ registrationNumber: import_zod15.z.string().optional()
1180
+ })
1181
+ );
1182
+ var DeclareAction = ActionBase.merge(
1183
+ import_zod15.z.object({
1184
+ type: import_zod15.z.literal(ActionType.DECLARE)
1185
+ })
1186
+ );
1187
+ var ValidateAction = ActionBase.merge(
1188
+ import_zod15.z.object({
1189
+ type: import_zod15.z.literal(ActionType.VALIDATE)
1190
+ })
1191
+ );
1192
+ var RejectAction = ActionBase.merge(
1193
+ import_zod15.z.object({
1194
+ type: import_zod15.z.literal(ActionType.REJECT)
1195
+ })
1196
+ );
1197
+ var MarkAsDuplicateAction = ActionBase.merge(
1198
+ import_zod15.z.object({
1199
+ type: import_zod15.z.literal(ActionType.MARKED_AS_DUPLICATE)
1200
+ })
1201
+ );
1202
+ var ArchiveAction = ActionBase.merge(
1203
+ import_zod15.z.object({
1204
+ type: import_zod15.z.literal(ActionType.ARCHIVE)
1205
+ })
1206
+ );
1207
+ var CreatedAction = ActionBase.merge(
1208
+ import_zod15.z.object({
1209
+ type: import_zod15.z.literal(ActionType.CREATE)
1210
+ })
1211
+ );
1212
+ var NotifiedAction = ActionBase.merge(
1213
+ import_zod15.z.object({
1214
+ type: import_zod15.z.literal(ActionType.NOTIFY)
1215
+ })
1216
+ );
1217
+ var PrintCertificateAction = ActionBase.merge(
1218
+ import_zod15.z.object({
1219
+ type: import_zod15.z.literal(ActionType.PRINT_CERTIFICATE)
1220
+ })
1221
+ );
1222
+ var RequestedCorrectionAction = ActionBase.merge(
1223
+ import_zod15.z.object({
1224
+ type: import_zod15.z.literal(ActionType.REQUEST_CORRECTION)
1225
+ })
1226
+ );
1227
+ var ApprovedCorrectionAction = ActionBase.merge(
1228
+ import_zod15.z.object({
1229
+ type: import_zod15.z.literal(ActionType.APPROVE_CORRECTION),
1230
+ requestId: import_zod15.z.string()
1231
+ })
1232
+ );
1233
+ var RejectedCorrectionAction = ActionBase.merge(
1234
+ import_zod15.z.object({
1235
+ type: import_zod15.z.literal(ActionType.REJECT_CORRECTION),
1236
+ requestId: import_zod15.z.string()
1237
+ })
1238
+ );
1239
+ var ReadAction = ActionBase.merge(
1240
+ import_zod15.z.object({
1241
+ type: import_zod15.z.literal(ActionType.READ)
1242
+ })
1243
+ );
1244
+ var ActionDocument = import_zod15.z.discriminatedUnion("type", [
1245
+ CreatedAction.openapi({ ref: "CreatedAction" }),
1246
+ ValidateAction.openapi({ ref: "ValidateAction" }),
1247
+ RejectAction.openapi({ ref: "RejectAction" }),
1248
+ MarkAsDuplicateAction.openapi({ ref: "MarkAsDuplicateAction" }),
1249
+ ArchiveAction.openapi({ ref: "ArchiveAction" }),
1250
+ NotifiedAction.openapi({ ref: "NotifiedAction" }),
1251
+ RegisterAction.openapi({ ref: "RegisterAction" }),
1252
+ DeclareAction.openapi({ ref: "DeclareAction" }),
1253
+ AssignedAction.openapi({ ref: "AssignedAction" }),
1254
+ RequestedCorrectionAction.openapi({ ref: "RequestedCorrectionAction" }),
1255
+ ApprovedCorrectionAction.openapi({ ref: "ApprovedCorrectionAction" }),
1256
+ RejectedCorrectionAction.openapi({ ref: "RejectedCorrectionAction" }),
1257
+ UnassignedAction.openapi({ ref: "UnassignedAction" }),
1258
+ PrintCertificateAction.openapi({ ref: "PrintCertificateAction" }),
1259
+ ReadAction.openapi({ ref: "ReadAction" })
1260
+ ]).openapi({
1261
+ ref: "ActionDocument"
1262
+ });
1263
+ var AsyncRejectActionDocument = ActionBase.omit({
1264
+ declaration: true,
1265
+ annotation: true
1266
+ }).merge(
1267
+ import_zod15.z.object({
1268
+ type: import_zod15.z.enum(ConfirmableActions),
1269
+ status: import_zod15.z.literal(ActionStatus.Rejected)
1270
+ })
1271
+ );
1272
+ var Action = import_zod15.z.union([ActionDocument, AsyncRejectActionDocument]);
1273
+ var ResolvedUser = import_zod15.z.object({
1274
+ id: import_zod15.z.string(),
1275
+ role: import_zod15.z.string(),
1276
+ name: import_zod15.z.array(
1277
+ import_zod15.z.object({
1278
+ use: import_zod15.z.string(),
1279
+ given: import_zod15.z.array(import_zod15.z.string()),
1280
+ family: import_zod15.z.string()
1281
+ })
1282
+ )
1283
+ });
1284
+
1103
1285
  // ../commons/src/conditionals/validate.ts
1104
1286
  var import_ajv = __toESM(require("ajv"));
1105
1287
  var import_ajv_formats = __toESM(require("ajv-formats"));
1106
1288
  var import_date_fns = require("date-fns");
1107
1289
 
1108
1290
  // ../commons/src/events/FieldTypeMapping.ts
1109
- var import_zod15 = require("zod");
1291
+ var import_zod16 = require("zod");
1110
1292
  function mapFieldTypeToZod(type, required) {
1111
1293
  let schema;
1112
1294
  switch (type) {
@@ -1116,6 +1298,9 @@ function mapFieldTypeToZod(type, required) {
1116
1298
  case FieldType.EMAIL:
1117
1299
  schema = EmailValue;
1118
1300
  break;
1301
+ case FieldType.DATE_RANGE:
1302
+ schema = DateRangeFieldValue;
1303
+ break;
1119
1304
  case FieldType.TEXT:
1120
1305
  case FieldType.TEXTAREA:
1121
1306
  case FieldType.DIVIDER:
@@ -1158,7 +1343,7 @@ function createValidationSchema(config) {
1158
1343
  for (const field2 of config) {
1159
1344
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1160
1345
  }
1161
- return import_zod15.z.object(shape);
1346
+ return import_zod16.z.object(shape);
1162
1347
  }
1163
1348
  function mapFieldTypeToMockValue(field2, i) {
1164
1349
  switch (field2.type) {
@@ -1196,6 +1381,8 @@ function mapFieldTypeToMockValue(field2, i) {
1196
1381
  };
1197
1382
  case FieldType.DATE:
1198
1383
  return "2021-01-01";
1384
+ case FieldType.DATE_RANGE:
1385
+ return ["2021-01-01", "2021-01-02"];
1199
1386
  case FieldType.CHECKBOX:
1200
1387
  return true;
1201
1388
  case FieldType.FILE:
@@ -1230,6 +1417,7 @@ function mapFieldTypeToEmptyValue(field2) {
1230
1417
  case FieldType.EMAIL:
1231
1418
  case FieldType.DATE:
1232
1419
  case FieldType.CHECKBOX:
1420
+ case FieldType.DATE_RANGE:
1233
1421
  case FieldType.DATA:
1234
1422
  return null;
1235
1423
  case FieldType.ADDRESS:
@@ -1262,6 +1450,9 @@ var isParagraphFieldType = (field2) => {
1262
1450
  var isDateFieldType = (field2) => {
1263
1451
  return field2.config.type === FieldType.DATE;
1264
1452
  };
1453
+ var isDateRangeFieldType = (field2) => {
1454
+ return field2.config.type === FieldType.DATE_RANGE;
1455
+ };
1265
1456
  var isPageHeaderFieldType = (field2) => {
1266
1457
  return field2.config.type === FieldType.PAGE_HEADER;
1267
1458
  };
@@ -1604,7 +1795,10 @@ function createEmptyDraft(eventId, draftId, actionType) {
1604
1795
  annotation: {},
1605
1796
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1606
1797
  createdBy: "@todo",
1607
- createdAtLocation: "@todo"
1798
+ createdAtLocation: "@todo",
1799
+ status: ActionStatus.Accepted,
1800
+ transactionId: "@todo",
1801
+ createdByRole: "@todo"
1608
1802
  }
1609
1803
  };
1610
1804
  }
@@ -1676,25 +1870,43 @@ var findAllFields = (config) => {
1676
1870
  ...getAllAnnotationFields(config)
1677
1871
  ]);
1678
1872
  };
1873
+ function getMixedPath(obj, path, defaultValue) {
1874
+ const parts = path.split(".");
1875
+ const resolve = (current, segments) => {
1876
+ if (current == null || segments.length === 0) {
1877
+ return current;
1878
+ }
1879
+ for (let i = segments.length; i > 0; i--) {
1880
+ const compoundKey = segments.slice(0, i).join(".");
1881
+ if ((0, import_lodash.has)(current, compoundKey)) {
1882
+ const next = (0, import_lodash.get)(current, compoundKey);
1883
+ return resolve(next, segments.slice(i));
1884
+ }
1885
+ }
1886
+ return void 0;
1887
+ };
1888
+ const result = resolve(obj, parts);
1889
+ return (0, import_lodash.isNil)(result) ? defaultValue : result;
1890
+ }
1679
1891
 
1680
1892
  // ../commons/src/events/EventConfig.ts
1681
- var import_zod_openapi3 = require("zod-openapi");
1682
- (0, import_zod_openapi3.extendZodWithOpenApi)(import_zod16.z);
1683
- var EventConfig = import_zod16.z.object({
1684
- id: import_zod16.z.string().describe(
1893
+ var import_zod_openapi4 = require("zod-openapi");
1894
+ (0, import_zod_openapi4.extendZodWithOpenApi)(import_zod17.z);
1895
+ var EventConfig = import_zod17.z.object({
1896
+ id: import_zod17.z.string().describe(
1685
1897
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1686
1898
  ),
1687
- dateOfEvent: import_zod16.z.object({ fieldId: import_zod16.z.string() }).optional(),
1899
+ dateOfEvent: import_zod17.z.object({ fieldId: import_zod17.z.string() }).optional(),
1688
1900
  title: TranslationConfig,
1689
1901
  fallbackTitle: TranslationConfig.optional().describe(
1690
1902
  "This is a fallback title if actual title resolves to empty string"
1691
1903
  ),
1692
1904
  summary: SummaryConfig,
1693
1905
  label: TranslationConfig,
1694
- actions: import_zod16.z.array(ActionConfig),
1906
+ actions: import_zod17.z.array(ActionConfig),
1695
1907
  declaration: DeclarationFormConfig,
1696
- deduplication: import_zod16.z.array(DeduplicationConfig).optional().default([]),
1697
- advancedSearch: import_zod16.z.array(AdvancedSearchConfig).optional().default([])
1908
+ deduplication: import_zod17.z.array(DeduplicationConfig).optional().default([]),
1909
+ advancedSearch: import_zod17.z.array(AdvancedSearchConfig).optional().default([])
1698
1910
  }).superRefine((event2, ctx) => {
1699
1911
  const allFields = findAllFields(event2);
1700
1912
  const fieldIds = allFields.map((field2) => field2.id);
@@ -1756,350 +1968,92 @@ var definePage = (page) => PageConfig.parse(page);
1756
1968
  var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1757
1969
 
1758
1970
  // ../commons/src/events/WorkqueueConfig.ts
1759
- var import_zod17 = require("zod");
1760
- var WorkqueueConfig = import_zod17.z.object({
1761
- slug: import_zod17.z.string().describe("Determines the url of the workqueue."),
1762
- name: TranslationConfig.describe(
1763
- "Title of the workflow (both in navigation and on the page)"
1764
- ),
1765
- /**
1766
- * Placeholder untill the following gets merged to develop
1767
- * https://github.com/opencrvs/opencrvs-core/blob/5fbe9854a88504a7a13fcc856b3e82594b70c38c/packages/commons/src/events/EventIndex.ts#L92-L93
1768
- */
1769
- query: import_zod17.z.string(),
1770
- actions: import_zod17.z.array(
1771
- import_zod17.z.object({
1772
- type: import_zod17.z.string(),
1773
- conditionals: import_zod17.z.array(Conditional).optional()
1774
- })
1775
- )
1776
- }).describe("Configuration for workqueue.");
1777
- function defineWorkqueue(workqueues) {
1778
- return workqueues.map((workqueue) => WorkqueueConfig.parse(workqueue));
1779
- }
1780
-
1781
- // ../commons/src/events/Draft.ts
1782
1971
  var import_zod20 = require("zod");
1783
1972
 
1784
- // ../commons/src/events/ActionDocument.ts
1973
+ // ../commons/src/events/EventIndex.ts
1974
+ var import_zod19 = require("zod");
1975
+
1976
+ // ../commons/src/events/EventMetadata.ts
1785
1977
  var import_zod18 = require("zod");
1786
- var import_zod_openapi4 = require("zod-openapi");
1787
- (0, import_zod_openapi4.extendZodWithOpenApi)(import_zod18.z);
1788
- var ActionUpdate = import_zod18.z.record(import_zod18.z.string(), FieldUpdateValue);
1789
- var ActionStatus = {
1790
- Requested: "Requested",
1791
- Accepted: "Accepted",
1792
- Rejected: "Rejected"
1978
+ var EventStatus = {
1979
+ CREATED: "CREATED",
1980
+ NOTIFIED: "NOTIFIED",
1981
+ DECLARED: "DECLARED",
1982
+ VALIDATED: "VALIDATED",
1983
+ REGISTERED: "REGISTERED",
1984
+ CERTIFIED: "CERTIFIED",
1985
+ REJECTED: "REJECTED",
1986
+ ARCHIVED: "ARCHIVED"
1793
1987
  };
1794
- var ActionBase = import_zod18.z.object({
1795
- id: import_zod18.z.string(),
1796
- transactionId: import_zod18.z.string(),
1797
- createdAt: import_zod18.z.string().datetime(),
1798
- createdBy: import_zod18.z.string(),
1799
- createdByRole: import_zod18.z.string(),
1800
- declaration: ActionUpdate,
1801
- annotation: ActionUpdate.optional(),
1802
- createdAtLocation: import_zod18.z.string().optional(),
1803
- updatedAtLocation: import_zod18.z.string().optional(),
1804
- status: import_zod18.z.enum([
1805
- ActionStatus.Requested,
1806
- ActionStatus.Accepted,
1807
- ActionStatus.Rejected
1808
- ]),
1809
- // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1810
- originalActionId: import_zod18.z.string().optional()
1988
+ var CustomFlags = {
1989
+ CERTIFICATE_PRINTED: "certificate-printed"
1990
+ };
1991
+ var Flag = import_zod18.z.string().regex(
1992
+ new RegExp(
1993
+ `^(${Object.values(ActionType).join("|").toLowerCase()}):(${Object.values(ActionStatus).join("|").toLowerCase()})$`
1994
+ ),
1995
+ "Flag must be in the format ActionType:ActionStatus (lowerCase)"
1996
+ ).or(import_zod18.z.nativeEnum(CustomFlags));
1997
+ var eventStatuses = Object.values(EventStatus);
1998
+ var EventStatuses = import_zod18.z.nativeEnum(EventStatus);
1999
+ var ZodDate = import_zod18.z.string().date();
2000
+ var ActionCreationMetadata = import_zod18.z.object({
2001
+ createdAt: import_zod18.z.string().datetime().describe("The timestamp when the action request was created."),
2002
+ createdBy: import_zod18.z.string().describe("ID of the user who created the action request."),
2003
+ createdAtLocation: import_zod18.z.string().describe("Location of the user who created the action request."),
2004
+ acceptedAt: import_zod18.z.string().datetime().describe("Timestamp when the action request was accepted."),
2005
+ createdByRole: import_zod18.z.string().describe("Role of the user at the time of action request creation.")
1811
2006
  });
1812
- var AssignedAction = ActionBase.merge(
1813
- import_zod18.z.object({
1814
- type: import_zod18.z.literal(ActionType.ASSIGN),
1815
- assignedTo: import_zod18.z.string()
1816
- })
1817
- );
1818
- var UnassignedAction = ActionBase.merge(
1819
- import_zod18.z.object({
1820
- type: import_zod18.z.literal(ActionType.UNASSIGN),
1821
- assignedTo: import_zod18.z.literal(null)
1822
- })
1823
- );
1824
- var RegisterAction = ActionBase.merge(
1825
- import_zod18.z.object({
1826
- type: import_zod18.z.literal(ActionType.REGISTER),
1827
- registrationNumber: import_zod18.z.string().optional()
1828
- })
1829
- );
1830
- var DeclareAction = ActionBase.merge(
1831
- import_zod18.z.object({
1832
- type: import_zod18.z.literal(ActionType.DECLARE)
1833
- })
1834
- );
1835
- var ValidateAction = ActionBase.merge(
1836
- import_zod18.z.object({
1837
- type: import_zod18.z.literal(ActionType.VALIDATE)
1838
- })
1839
- );
1840
- var RejectAction = ActionBase.merge(
1841
- import_zod18.z.object({
1842
- type: import_zod18.z.literal(ActionType.REJECT)
1843
- })
1844
- );
1845
- var MarkAsDuplicateAction = ActionBase.merge(
1846
- import_zod18.z.object({
1847
- type: import_zod18.z.literal(ActionType.MARKED_AS_DUPLICATE)
1848
- })
1849
- );
1850
- var ArchiveAction = ActionBase.merge(
1851
- import_zod18.z.object({
1852
- type: import_zod18.z.literal(ActionType.ARCHIVE)
1853
- })
1854
- );
1855
- var CreatedAction = ActionBase.merge(
1856
- import_zod18.z.object({
1857
- type: import_zod18.z.literal(ActionType.CREATE)
1858
- })
1859
- );
1860
- var NotifiedAction = ActionBase.merge(
1861
- import_zod18.z.object({
1862
- type: import_zod18.z.literal(ActionType.NOTIFY)
1863
- })
1864
- );
1865
- var PrintCertificateAction = ActionBase.merge(
1866
- import_zod18.z.object({
1867
- type: import_zod18.z.literal(ActionType.PRINT_CERTIFICATE)
1868
- })
1869
- );
1870
- var RequestedCorrectionAction = ActionBase.merge(
1871
- import_zod18.z.object({
1872
- type: import_zod18.z.literal(ActionType.REQUEST_CORRECTION)
1873
- })
1874
- );
1875
- var ApprovedCorrectionAction = ActionBase.merge(
1876
- import_zod18.z.object({
1877
- type: import_zod18.z.literal(ActionType.APPROVE_CORRECTION),
1878
- requestId: import_zod18.z.string()
1879
- })
1880
- );
1881
- var RejectedCorrectionAction = ActionBase.merge(
1882
- import_zod18.z.object({
1883
- type: import_zod18.z.literal(ActionType.REJECT_CORRECTION),
1884
- requestId: import_zod18.z.string()
1885
- })
1886
- );
1887
- var ReadAction = ActionBase.merge(
1888
- import_zod18.z.object({
1889
- type: import_zod18.z.literal(ActionType.READ)
1890
- })
1891
- );
1892
- var ActionDocument = import_zod18.z.discriminatedUnion("type", [
1893
- CreatedAction.openapi({ ref: "CreatedAction" }),
1894
- ValidateAction.openapi({ ref: "ValidateAction" }),
1895
- RejectAction.openapi({ ref: "RejectAction" }),
1896
- MarkAsDuplicateAction.openapi({ ref: "MarkAsDuplicateAction" }),
1897
- ArchiveAction.openapi({ ref: "ArchiveAction" }),
1898
- NotifiedAction.openapi({ ref: "NotifiedAction" }),
1899
- RegisterAction.openapi({ ref: "RegisterAction" }),
1900
- DeclareAction.openapi({ ref: "DeclareAction" }),
1901
- AssignedAction.openapi({ ref: "AssignedAction" }),
1902
- RequestedCorrectionAction.openapi({ ref: "RequestedCorrectionAction" }),
1903
- ApprovedCorrectionAction.openapi({ ref: "ApprovedCorrectionAction" }),
1904
- RejectedCorrectionAction.openapi({ ref: "RejectedCorrectionAction" }),
1905
- UnassignedAction.openapi({ ref: "UnassignedAction" }),
1906
- PrintCertificateAction.openapi({ ref: "PrintCertificateAction" }),
1907
- ReadAction.openapi({ ref: "ReadAction" })
1908
- ]).openapi({
1909
- ref: "ActionDocument"
2007
+ var RegistrationCreationMetadata = ActionCreationMetadata.extend({
2008
+ registrationNumber: import_zod18.z.string().describe(
2009
+ "Registration number of the event. Always present for accepted registrations."
2010
+ )
1910
2011
  });
1911
- var AsyncRejectActionDocument = ActionBase.omit({
1912
- declaration: true,
1913
- annotation: true,
1914
- createdBy: true,
1915
- createdByRole: true,
1916
- createdAtLocation: true
1917
- }).merge(
1918
- import_zod18.z.object({
1919
- type: import_zod18.z.enum(ConfirmableActions),
1920
- status: import_zod18.z.literal(ActionStatus.Rejected)
1921
- })
1922
- );
1923
- var Action = import_zod18.z.union([ActionDocument, AsyncRejectActionDocument]);
1924
- var ResolvedUser = import_zod18.z.object({
2012
+ var LegalStatuses = import_zod18.z.object({
2013
+ [EventStatus.DECLARED]: ActionCreationMetadata.nullish(),
2014
+ [EventStatus.REGISTERED]: RegistrationCreationMetadata.nullish()
2015
+ });
2016
+ var EventMetadata = import_zod18.z.object({
1925
2017
  id: import_zod18.z.string(),
1926
- role: import_zod18.z.string(),
1927
- name: import_zod18.z.array(
1928
- import_zod18.z.object({
1929
- use: import_zod18.z.string(),
1930
- given: import_zod18.z.array(import_zod18.z.string()),
1931
- family: import_zod18.z.string()
1932
- })
1933
- )
2018
+ type: import_zod18.z.string().describe("The type of event, such as birth, death, or marriage."),
2019
+ status: EventStatuses,
2020
+ legalStatuses: LegalStatuses.describe(
2021
+ "Metadata related to the legal registration of the event, such as who registered it and when."
2022
+ ),
2023
+ createdAt: import_zod18.z.string().datetime().describe("The timestamp when the event was first created and saved."),
2024
+ dateOfEvent: ZodDate.nullish(),
2025
+ createdBy: import_zod18.z.string().describe("ID of the user who created the event."),
2026
+ updatedByUserRole: import_zod18.z.string().describe("Role of the user who last updated the declaration."),
2027
+ createdAtLocation: import_zod18.z.string().describe("Location of the user who created the event."),
2028
+ updatedAtLocation: import_zod18.z.string().nullish().describe("Location of the user who last updated the declaration."),
2029
+ updatedAt: import_zod18.z.string().datetime().describe("Timestamp of the most recent declaration update."),
2030
+ assignedTo: import_zod18.z.string().nullish().describe("ID of the user currently assigned to the event."),
2031
+ updatedBy: import_zod18.z.string().nullish().describe("ID of the user who last updated the declaration."),
2032
+ trackingId: import_zod18.z.string().describe(
2033
+ "System-generated tracking ID used by informants or registrars to look up the event."
2034
+ ),
2035
+ flags: import_zod18.z.array(Flag)
1934
2036
  });
1935
-
1936
- // ../commons/src/events/ActionInput.ts
1937
- var import_zod19 = require("zod");
1938
- var import_zod_openapi5 = require("zod-openapi");
1939
- (0, import_zod_openapi5.extendZodWithOpenApi)(import_zod19.z);
1940
- var BaseActionInput = import_zod19.z.object({
1941
- eventId: import_zod19.z.string(),
1942
- transactionId: import_zod19.z.string(),
1943
- declaration: ActionUpdate.default({}),
1944
- annotation: ActionUpdate.optional(),
1945
- originalActionId: import_zod19.z.string().optional(),
1946
- keepAssignment: import_zod19.z.boolean().optional()
1947
- });
1948
- var CreateActionInput = BaseActionInput.merge(
1949
- import_zod19.z.object({
1950
- type: import_zod19.z.literal(ActionType.CREATE).default(ActionType.CREATE),
1951
- createdAtLocation: import_zod19.z.string()
1952
- })
1953
- );
1954
- var RegisterActionInput = BaseActionInput.merge(
1955
- import_zod19.z.object({
1956
- type: import_zod19.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
1957
- registrationNumber: import_zod19.z.string().optional()
1958
- })
1959
- );
1960
- var ValidateActionInput = BaseActionInput.merge(
1961
- import_zod19.z.object({
1962
- type: import_zod19.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
1963
- duplicates: import_zod19.z.array(import_zod19.z.string())
1964
- })
1965
- );
1966
- var NotifyActionInput = BaseActionInput.merge(
1967
- import_zod19.z.object({
1968
- type: import_zod19.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1969
- })
1970
- );
1971
- var DeclareActionInput = BaseActionInput.merge(
1972
- import_zod19.z.object({
1973
- type: import_zod19.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1974
- })
1975
- );
1976
- var PrintCertificateActionInput = BaseActionInput.merge(
1977
- import_zod19.z.object({
1978
- type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1979
- })
1980
- );
1981
- var RejectDeclarationActionInput = BaseActionInput.merge(
1982
- import_zod19.z.object({
1983
- type: import_zod19.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1984
- })
1985
- );
1986
- var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1987
- import_zod19.z.object({
1988
- type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1989
- })
1990
- );
1991
- var ArchiveActionInput = BaseActionInput.merge(
1992
- import_zod19.z.object({
1993
- type: import_zod19.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1994
- })
1995
- );
1996
- var AssignActionInput = BaseActionInput.merge(
1997
- import_zod19.z.object({
1998
- type: import_zod19.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
1999
- assignedTo: import_zod19.z.string()
2000
- })
2001
- );
2002
- var UnassignActionInput = BaseActionInput.merge(
2003
- import_zod19.z.object({
2004
- type: import_zod19.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2005
- assignedTo: import_zod19.z.literal(null).default(null)
2006
- })
2007
- );
2008
- var RequestCorrectionActionInput = BaseActionInput.merge(
2009
- import_zod19.z.object({
2010
- type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2011
- })
2012
- );
2013
- var RejectCorrectionActionInput = BaseActionInput.merge(
2014
- import_zod19.z.object({
2015
- requestId: import_zod19.z.string(),
2016
- type: import_zod19.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2017
- })
2018
- );
2019
- var ApproveCorrectionActionInput = BaseActionInput.merge(
2020
- import_zod19.z.object({
2021
- requestId: import_zod19.z.string(),
2022
- type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2023
- })
2024
- );
2025
- var ReadActionInput = BaseActionInput.merge(
2026
- import_zod19.z.object({
2027
- type: import_zod19.z.literal(ActionType.READ).default(ActionType.READ)
2028
- })
2029
- );
2030
- var DeleteActionInput = import_zod19.z.object({ eventId: import_zod19.z.string() });
2031
- var ActionInput = import_zod19.z.discriminatedUnion("type", [
2032
- CreateActionInput.openapi({ ref: "CreateActionInput" }),
2033
- ValidateActionInput.openapi({ ref: "ValidateActionInput" }),
2034
- RegisterActionInput.openapi({ ref: "RegisterActionInput" }),
2035
- NotifyActionInput.openapi({ ref: "NotifyActionInput" }),
2036
- DeclareActionInput.openapi({ ref: "DeclareActionInput" }),
2037
- RejectDeclarationActionInput.openapi({
2038
- ref: "RejectDeclarationActionInput"
2039
- }),
2040
- MarkedAsDuplicateActionInput.openapi({
2041
- ref: "MarkedAsDuplicateActionInput"
2042
- }),
2043
- ArchiveActionInput.openapi({ ref: "ArchiveActionInput" }),
2044
- AssignActionInput.openapi({ ref: "AssignActionInput" }),
2045
- UnassignActionInput.openapi({ ref: "UnassignActionInput" }),
2046
- PrintCertificateActionInput.openapi({ ref: "PrintCertificateActionInput" }),
2047
- RequestCorrectionActionInput.openapi({
2048
- ref: "RequestCorrectionActionInput"
2049
- }),
2050
- RejectCorrectionActionInput.openapi({ ref: "RejectCorrectionActionInput" }),
2051
- ApproveCorrectionActionInput.openapi({
2052
- ref: "ApproveCorrectionActionInput"
2053
- }),
2054
- ReadActionInput.openapi({ ref: "ReadActionInput" })
2055
- ]).openapi({
2056
- ref: "ActionInput"
2057
- });
2058
-
2059
- // ../commons/src/events/Draft.ts
2060
- var Draft = import_zod20.z.object({
2061
- id: import_zod20.z.string(),
2062
- eventId: import_zod20.z.string(),
2063
- transactionId: import_zod20.z.string(),
2064
- createdAt: import_zod20.z.string().datetime(),
2065
- action: ActionBase.extend({
2066
- type: ActionTypes
2067
- }).omit({ id: true })
2068
- });
2069
- var DraftInput = BaseActionInput.extend({
2070
- type: ActionTypes
2071
- });
2072
-
2073
- // ../commons/src/events/EventMetadata.ts
2074
- var import_zod21 = require("zod");
2075
- var EventStatus = {
2076
- CREATED: "CREATED",
2077
- NOTIFIED: "NOTIFIED",
2078
- DECLARED: "DECLARED",
2079
- VALIDATED: "VALIDATED",
2080
- REGISTERED: "REGISTERED",
2081
- CERTIFIED: "CERTIFIED",
2082
- REJECTED: "REJECTED",
2083
- ARCHIVED: "ARCHIVED"
2084
- };
2085
- var eventStatuses = Object.values(EventStatus);
2086
- var EventStatuses = import_zod21.z.nativeEnum(EventStatus);
2087
- var ZodDate = import_zod21.z.string().date();
2088
- var EventMetadata = import_zod21.z.object({
2089
- id: import_zod21.z.string(),
2090
- type: import_zod21.z.string(),
2091
- status: EventStatuses,
2092
- createdAt: import_zod21.z.string().datetime(),
2093
- dateOfEvent: ZodDate.nullish(),
2094
- createdBy: import_zod21.z.string(),
2095
- updatedByUserRole: import_zod21.z.string(),
2096
- createdAtLocation: import_zod21.z.string(),
2097
- updatedAtLocation: import_zod21.z.string(),
2098
- updatedAt: import_zod21.z.string().datetime(),
2099
- assignedTo: import_zod21.z.string().nullish(),
2100
- updatedBy: import_zod21.z.string(),
2101
- trackingId: import_zod21.z.string(),
2102
- registrationNumber: import_zod21.z.string().nullish()
2037
+ var EventMetadataKeys = import_zod18.z.enum([
2038
+ "id",
2039
+ "type",
2040
+ "status",
2041
+ "createdAt",
2042
+ "dateOfEvent",
2043
+ "createdBy",
2044
+ "updatedByUserRole",
2045
+ "createdAtLocation",
2046
+ "updatedAtLocation",
2047
+ "updatedAt",
2048
+ "assignedTo",
2049
+ "updatedBy",
2050
+ "trackingId",
2051
+ "legalStatuses",
2052
+ "flags"
2053
+ ]);
2054
+ var EventMetadataParameter = import_zod18.z.object({
2055
+ // @TODO: Reconcile with the event metadata definition. How could we derive one from the other?
2056
+ $event: EventMetadataKeys
2103
2057
  });
2104
2058
  var eventMetadataLabelMap = {
2105
2059
  "event.assignedTo": {
@@ -2167,339 +2121,102 @@ var eventMetadataLabelMap = {
2167
2121
  defaultMessage: "Tracking ID",
2168
2122
  description: "Tracking ID"
2169
2123
  },
2170
- "event.registrationNumber": {
2171
- id: "event.registrationNumber.label",
2172
- defaultMessage: "Registration Number",
2173
- description: "Registration Number"
2124
+ "event.flags": {
2125
+ id: "event.flags.label",
2126
+ defaultMessage: "Flags",
2127
+ description: "Flags"
2174
2128
  }
2175
2129
  };
2176
2130
 
2177
- // ../commons/src/events/EventInput.ts
2178
- var import_zod22 = require("zod");
2179
- var EventInput = import_zod22.z.object({
2180
- transactionId: import_zod22.z.string(),
2181
- type: import_zod22.z.string(),
2182
- dateOfEvent: import_zod22.z.object({ fieldId: import_zod22.z.string() }).optional()
2183
- });
2184
-
2185
- // ../commons/src/events/EventDocument.ts
2186
- var import_zod23 = require("zod");
2187
- var import_zod_openapi6 = require("zod-openapi");
2188
- (0, import_zod_openapi6.extendZodWithOpenApi)(import_zod23.z);
2189
- var EventDocument = import_zod23.z.object({
2190
- id: import_zod23.z.string(),
2191
- type: import_zod23.z.string(),
2192
- dateOfEvent: import_zod23.z.object({ fieldId: import_zod23.z.string() }).optional(),
2193
- createdAt: import_zod23.z.string().datetime(),
2194
- updatedAt: import_zod23.z.string().datetime(),
2195
- updatedAtLocation: import_zod23.z.string(),
2196
- actions: import_zod23.z.array(Action),
2197
- trackingId: import_zod23.z.string()
2198
- }).openapi({ ref: "EventDocument" });
2199
-
2200
2131
  // ../commons/src/events/EventIndex.ts
2201
- var import_zod24 = require("zod");
2202
2132
  var EventIndex = EventMetadata.extend({
2203
- declaration: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any())
2133
+ declaration: EventState
2204
2134
  });
2205
- var EventSearchIndex = import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any()).and(
2206
- import_zod24.z.object({
2207
- type: import_zod24.z.string()
2135
+ var EventSearchIndex = import_zod19.z.record(import_zod19.z.string(), import_zod19.z.any()).and(
2136
+ import_zod19.z.object({
2137
+ type: import_zod19.z.string()
2208
2138
  // Ensures "type" (event-id) exists and is a string
2209
2139
  })
2210
2140
  );
2211
- var Fuzzy = import_zod24.z.object({ type: import_zod24.z.literal("fuzzy"), term: import_zod24.z.string() });
2212
- var Exact = import_zod24.z.object({ type: import_zod24.z.literal("exact"), term: import_zod24.z.string() });
2213
- var AnyOf = import_zod24.z.object({
2214
- type: import_zod24.z.literal("anyOf"),
2215
- terms: import_zod24.z.array(import_zod24.z.string())
2141
+ var Fuzzy = import_zod19.z.object({ type: import_zod19.z.literal("fuzzy"), term: import_zod19.z.string() });
2142
+ var Exact = import_zod19.z.object({ type: import_zod19.z.literal("exact"), term: import_zod19.z.string() });
2143
+ var AnyOf = import_zod19.z.object({
2144
+ type: import_zod19.z.literal("anyOf"),
2145
+ terms: import_zod19.z.array(import_zod19.z.string())
2216
2146
  });
2217
- var Range = import_zod24.z.object({
2218
- type: import_zod24.z.literal("range"),
2219
- gte: import_zod24.z.string(),
2220
- lte: import_zod24.z.string()
2147
+ var Range = import_zod19.z.object({
2148
+ type: import_zod19.z.literal("range"),
2149
+ gte: import_zod19.z.string(),
2150
+ lte: import_zod19.z.string()
2221
2151
  });
2222
- var Within = import_zod24.z.object({ type: import_zod24.z.literal("within"), location: import_zod24.z.string() });
2223
- var DateCondition = import_zod24.z.union([Exact, Range]);
2224
- var QueryInput = import_zod24.z.lazy(
2225
- () => import_zod24.z.union([
2226
- import_zod24.z.discriminatedUnion("type", [Fuzzy, Exact, Range, Within, AnyOf]),
2227
- import_zod24.z.record(import_zod24.z.string(), QueryInput)
2152
+ var Not = import_zod19.z.object({ type: import_zod19.z.literal("not"), term: import_zod19.z.string() });
2153
+ var Within = import_zod19.z.object({ type: import_zod19.z.literal("within"), location: import_zod19.z.string() });
2154
+ var DateCondition = import_zod19.z.union([Exact, Range]);
2155
+ var QueryInput = import_zod19.z.lazy(
2156
+ () => import_zod19.z.union([
2157
+ import_zod19.z.discriminatedUnion("type", [Fuzzy, Exact, Range, Within, AnyOf, Not]),
2158
+ import_zod19.z.record(import_zod19.z.string(), QueryInput)
2228
2159
  ])
2229
2160
  );
2230
- var QueryExpression = import_zod24.z.object({
2231
- type: import_zod24.z.literal("and"),
2232
- eventType: import_zod24.z.string(),
2233
- status: import_zod24.z.optional(import_zod24.z.union([AnyOf, Exact])),
2234
- createdAt: import_zod24.z.optional(DateCondition),
2235
- updatedAt: import_zod24.z.optional(DateCondition),
2236
- createAtLocation: import_zod24.z.optional(import_zod24.z.union([Within, Exact])),
2237
- updatedAtLocation: import_zod24.z.optional(import_zod24.z.union([Within, Exact])),
2238
- createdBy: import_zod24.z.optional(Exact),
2239
- updatedBy: import_zod24.z.optional(Exact),
2240
- trackingId: import_zod24.z.optional(Exact),
2161
+ var QueryExpression = import_zod19.z.object({
2162
+ eventType: import_zod19.z.string(),
2163
+ status: import_zod19.z.optional(import_zod19.z.union([AnyOf, Exact])),
2164
+ createdAt: import_zod19.z.optional(DateCondition),
2165
+ updatedAt: import_zod19.z.optional(DateCondition),
2166
+ createAtLocation: import_zod19.z.optional(import_zod19.z.union([Within, Exact])),
2167
+ updatedAtLocation: import_zod19.z.optional(import_zod19.z.union([Within, Exact])),
2168
+ createdBy: import_zod19.z.optional(Exact),
2169
+ updatedBy: import_zod19.z.optional(Exact),
2170
+ trackingId: import_zod19.z.optional(Exact),
2171
+ flags: import_zod19.z.optional(import_zod19.z.array(import_zod19.z.union([AnyOf, Not]))),
2241
2172
  data: QueryInput
2242
2173
  }).partial();
2243
- var Or2 = import_zod24.z.object({
2244
- type: import_zod24.z.literal("or"),
2245
- clauses: import_zod24.z.array(QueryExpression)
2174
+ var Or2 = import_zod19.z.object({
2175
+ type: import_zod19.z.literal("or"),
2176
+ clauses: import_zod19.z.array(QueryExpression)
2177
+ });
2178
+ var And2 = import_zod19.z.object({
2179
+ type: import_zod19.z.literal("and"),
2180
+ clauses: import_zod19.z.array(QueryExpression)
2246
2181
  });
2247
- var QueryType = import_zod24.z.discriminatedUnion("type", [QueryExpression, Or2]);
2182
+ var QueryType = import_zod19.z.discriminatedUnion("type", [Or2, And2]);
2248
2183
 
2249
- // ../commons/src/events/state/index.ts
2250
- function getStatusFromActions(actions) {
2251
- const hasRejectedAction = actions.some(
2252
- (a) => a.status === ActionStatus.Rejected
2253
- );
2254
- if (hasRejectedAction) {
2255
- return EventStatus.REJECTED;
2256
- }
2257
- return actions.reduce((status, action) => {
2258
- switch (action.type) {
2259
- case ActionType.CREATE:
2260
- return EventStatus.CREATED;
2261
- case ActionType.DECLARE:
2262
- return EventStatus.DECLARED;
2263
- case ActionType.VALIDATE:
2264
- return EventStatus.VALIDATED;
2265
- case ActionType.REGISTER:
2266
- return EventStatus.REGISTERED;
2267
- case ActionType.REJECT:
2268
- return EventStatus.REJECTED;
2269
- case ActionType.ARCHIVE:
2270
- return EventStatus.ARCHIVED;
2271
- case ActionType.NOTIFY:
2272
- return EventStatus.NOTIFIED;
2273
- case ActionType.PRINT_CERTIFICATE:
2274
- return EventStatus.CERTIFIED;
2275
- case ActionType.ASSIGN:
2276
- case ActionType.UNASSIGN:
2277
- case ActionType.REQUEST_CORRECTION:
2278
- case ActionType.APPROVE_CORRECTION:
2279
- case ActionType.MARKED_AS_DUPLICATE:
2280
- case ActionType.REJECT_CORRECTION:
2281
- case ActionType.READ:
2282
- default:
2283
- return status;
2284
- }
2285
- }, EventStatus.CREATED);
2286
- }
2287
- function getLastUpdatedByUserRoleFromActions(actions) {
2288
- const actionsWithRoles = actions.filter(
2289
- (action) => !isWriteAction(action.type) && action.status !== ActionStatus.Rejected
2290
- ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2291
- const lastAction = actionsWithRoles.at(-1);
2292
- if (!lastAction) {
2293
- throw new Error(
2294
- "Should never happen, at least CREATE action should be present"
2295
- );
2296
- }
2297
- return ActionDocument.parse(lastAction).createdByRole;
2298
- }
2299
- function getAssignedUserFromActions(actions) {
2300
- return actions.reduce((user2, action) => {
2301
- if (action.type === ActionType.ASSIGN) {
2302
- return action.assignedTo;
2303
- }
2304
- if (action.type === ActionType.UNASSIGN) {
2305
- return null;
2306
- }
2307
- return user2;
2308
- }, null);
2309
- }
2310
- function aggregateActionDeclarations(actions) {
2311
- const excludedActions = [
2312
- ActionType.REQUEST_CORRECTION,
2313
- ActionType.PRINT_CERTIFICATE
2314
- ];
2315
- return actions.reduce((status, action) => {
2316
- if (excludedActions.some((excludedAction) => excludedAction === action.type)) {
2317
- return status;
2318
- }
2319
- if (action.type === ActionType.APPROVE_CORRECTION) {
2320
- const requestAction = actions.find(({ id }) => id === action.requestId);
2321
- if (!requestAction) {
2322
- return status;
2323
- }
2324
- return deepMerge(status, requestAction.declaration);
2325
- }
2326
- return deepMerge(status, action.declaration);
2327
- }, {});
2184
+ // ../commons/src/conditionals/conditionals.ts
2185
+ function defineConditional(schema) {
2186
+ return schema;
2328
2187
  }
2329
- function deepDropNulls(obj) {
2330
- if (Array.isArray(obj)) {
2331
- return obj.map(deepDropNulls);
2332
- }
2333
- if (obj !== null && typeof obj === "object") {
2334
- return Object.entries(obj).reduce((acc, [key, value]) => {
2335
- const cleanedValue = deepDropNulls(value);
2336
- if (cleanedValue !== null) {
2337
- ;
2338
- acc[key] = cleanedValue;
2339
- }
2340
- return acc;
2341
- }, {});
2342
- }
2343
- return obj;
2188
+ function defineFormConditional(schema) {
2189
+ const schemaWithForm = {
2190
+ type: "object",
2191
+ properties: {
2192
+ $form: schema
2193
+ },
2194
+ required: ["$form"]
2195
+ };
2196
+ return defineConditional(schemaWithForm);
2344
2197
  }
2345
- function isUndeclaredDraft(status) {
2346
- return status === EventStatus.CREATED;
2198
+ function alwaysTrue() {
2199
+ return {};
2347
2200
  }
2348
- function getAcceptedActions(event2) {
2349
- return event2.actions.filter(
2350
- (a) => a.status === ActionStatus.Accepted
2351
- );
2201
+ function and(...conditions) {
2202
+ return defineConditional({
2203
+ type: "object",
2204
+ allOf: conditions,
2205
+ required: []
2206
+ });
2352
2207
  }
2353
- function getCurrentEventState(event2) {
2354
- const creationAction = event2.actions.find(
2355
- (action) => action.type === ActionType.CREATE
2356
- );
2357
- if (!creationAction) {
2358
- throw new Error(`Event ${event2.id} has no creation action`);
2359
- }
2360
- const activeActions = getAcceptedActions(event2);
2361
- const latestAction = activeActions[activeActions.length - 1];
2362
- const registrationAction = activeActions.find(
2363
- (a) => a.type === ActionType.REGISTER && a.status === ActionStatus.Accepted
2364
- );
2365
- const registrationNumber = registrationAction?.registrationNumber ?? null;
2366
- const declaration = aggregateActionDeclarations(activeActions);
2367
- let dateOfEvent = event2.createdAt.split("T")[0];
2368
- if (event2.dateOfEvent) {
2369
- const parsedDate = ZodDate.safeParse(declaration[event2.dateOfEvent.fieldId]);
2370
- dateOfEvent = parsedDate.success ? parsedDate.data : null;
2371
- }
2372
- return deepDropNulls({
2373
- id: event2.id,
2374
- type: event2.type,
2375
- status: getStatusFromActions(event2.actions),
2376
- createdAt: event2.createdAt,
2377
- createdBy: creationAction.createdBy,
2378
- createdAtLocation: creationAction.createdAtLocation ?? "",
2379
- // @todo remove using empty string
2380
- updatedAt: latestAction.createdAt,
2381
- assignedTo: getAssignedUserFromActions(activeActions),
2382
- updatedBy: latestAction.createdBy,
2383
- updatedAtLocation: event2.updatedAtLocation,
2384
- declaration,
2385
- trackingId: event2.trackingId,
2386
- registrationNumber,
2387
- updatedByUserRole: getLastUpdatedByUserRoleFromActions(event2.actions),
2388
- dateOfEvent
2208
+ function or(...conditions) {
2209
+ return defineConditional({
2210
+ type: "object",
2211
+ anyOf: conditions,
2212
+ required: []
2389
2213
  });
2390
2214
  }
2391
- function getCurrentEventStateWithDrafts(event2, drafts) {
2392
- const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2393
- const activeDrafts = findActiveDrafts(event2, drafts).map((draft) => draft.action).flatMap((action) => {
2394
- if (action.type === ActionType.REQUEST_CORRECTION) {
2395
- return [
2396
- action,
2397
- {
2398
- ...action,
2399
- type: ActionType.APPROVE_CORRECTION
2400
- }
2401
- ];
2402
- }
2403
- return [action];
2404
- });
2405
- const actionWithDrafts = [...actions, ...activeDrafts].sort();
2406
- const withDrafts = {
2407
- ...event2,
2408
- actions: actionWithDrafts
2409
- };
2410
- return getCurrentEventState(withDrafts);
2411
- }
2412
- function applyDraftsToEventIndex(eventIndex, drafts) {
2413
- const indexedAt = eventIndex.updatedAt;
2414
- const activeDrafts = drafts.filter(({ createdAt }) => new Date(createdAt) > new Date(indexedAt)).map((draft) => draft.action).sort();
2415
- if (activeDrafts.length === 0) {
2416
- return eventIndex;
2417
- }
2418
- return {
2419
- ...eventIndex,
2420
- declaration: {
2421
- ...eventIndex.declaration,
2422
- ...activeDrafts[activeDrafts.length - 1].declaration
2423
- }
2424
- };
2425
- }
2426
- function getAnnotationFromDrafts(drafts) {
2427
- const actions = drafts.map((draft) => draft.action);
2428
- const annotation = actions.reduce((ann, action) => {
2429
- return deepMerge(ann, action.annotation ?? {});
2430
- }, {});
2431
- return deepDropNulls(annotation);
2432
- }
2433
- function getActionAnnotation({
2434
- event: event2,
2435
- actionType,
2436
- drafts = []
2437
- }) {
2438
- const activeActions = getAcceptedActions(event2);
2439
- const action = activeActions.find(
2440
- (activeAction) => actionType === activeAction.type
2441
- );
2442
- const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
2443
- const sorted = [
2444
- ...action ? [action] : [],
2445
- ...eventDrafts.map((draft) => draft.action)
2446
- ].sort();
2447
- const annotation = sorted.reduce((ann, sortedAction) => {
2448
- return deepMerge(ann, sortedAction.annotation ?? {});
2449
- }, {});
2450
- return deepDropNulls(annotation);
2451
- }
2452
-
2453
- // ../commons/src/events/defineConfig.ts
2454
- var defineConfig = (config) => {
2455
- const input = EventConfig.parse(config);
2456
- return input;
2457
- };
2458
-
2459
- // ../commons/src/events/transactions.ts
2460
- function generateTransactionId() {
2461
- return getUUID();
2462
- }
2463
-
2464
- // ../commons/src/events/test.utils.ts
2465
- var import_lodash2 = require("lodash");
2466
-
2467
- // ../commons/src/conditionals/conditionals.ts
2468
- function defineConditional(schema) {
2469
- return schema;
2470
- }
2471
- function defineFormConditional(schema) {
2472
- const schemaWithForm = {
2473
- type: "object",
2474
- properties: {
2475
- $form: schema
2476
- },
2477
- required: ["$form"]
2478
- };
2479
- return defineConditional(schemaWithForm);
2480
- }
2481
- function alwaysTrue() {
2482
- return {};
2483
- }
2484
- function and(...conditions) {
2485
- return defineConditional({
2486
- type: "object",
2487
- allOf: conditions,
2488
- required: []
2489
- });
2490
- }
2491
- function or(...conditions) {
2492
- return defineConditional({
2493
- type: "object",
2494
- anyOf: conditions,
2495
- required: []
2496
- });
2497
- }
2498
- function not(condition) {
2499
- return defineConditional({
2500
- type: "object",
2501
- not: condition,
2502
- required: []
2215
+ function not(condition) {
2216
+ return defineConditional({
2217
+ type: "object",
2218
+ not: condition,
2219
+ required: []
2503
2220
  });
2504
2221
  }
2505
2222
  function never() {
@@ -2699,68 +2416,597 @@ function createFieldConditionals(fieldId) {
2699
2416
  }
2700
2417
  ]
2701
2418
  }),
2702
- isUndefined: () => defineFormConditional({
2703
- type: "object",
2704
- properties: {
2705
- [fieldId]: {
2706
- type: "string",
2707
- enum: ["undefined"]
2708
- }
2709
- },
2710
- not: {
2711
- required: [fieldId]
2419
+ isUndefined: () => defineFormConditional({
2420
+ type: "object",
2421
+ properties: {
2422
+ [fieldId]: {
2423
+ type: "string",
2424
+ enum: ["undefined"]
2425
+ }
2426
+ },
2427
+ not: {
2428
+ required: [fieldId]
2429
+ }
2430
+ }),
2431
+ inArray: (values) => defineFormConditional({
2432
+ type: "object",
2433
+ properties: {
2434
+ [fieldId]: {
2435
+ type: "string",
2436
+ enum: values
2437
+ }
2438
+ },
2439
+ required: [fieldId]
2440
+ }),
2441
+ isValidEnglishName: () => defineFormConditional({
2442
+ type: "object",
2443
+ properties: {
2444
+ [fieldId]: {
2445
+ type: "string",
2446
+ 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'._-]*)*$",
2447
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2448
+ }
2449
+ },
2450
+ required: [fieldId]
2451
+ }),
2452
+ /**
2453
+ * Checks if the field value matches a given regular expression pattern.
2454
+ * @param pattern - The regular expression pattern to match the field value against.
2455
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2456
+ */
2457
+ matches: (pattern) => defineFormConditional({
2458
+ type: "object",
2459
+ properties: {
2460
+ [fieldId]: {
2461
+ type: "string",
2462
+ pattern
2463
+ }
2464
+ },
2465
+ required: [fieldId]
2466
+ }),
2467
+ isBetween: (min, max) => defineFormConditional({
2468
+ type: "object",
2469
+ properties: {
2470
+ [fieldId]: {
2471
+ type: "number",
2472
+ minimum: min,
2473
+ maximum: max
2474
+ }
2475
+ },
2476
+ required: [fieldId]
2477
+ }),
2478
+ getId: () => ({ fieldId })
2479
+ };
2480
+ }
2481
+
2482
+ // ../commons/src/event-config/event-configuration.ts
2483
+ function createEventFieldConfig(fieldId, options) {
2484
+ return {
2485
+ fieldId,
2486
+ options,
2487
+ config: { type: "exact" },
2488
+ fieldType: "event"
2489
+ };
2490
+ }
2491
+
2492
+ // ../commons/src/events/event.ts
2493
+ function eventFn(fieldId, options) {
2494
+ return createEventFieldConfig(fieldId, options);
2495
+ }
2496
+ var event = Object.assign(eventFn, {
2497
+ ...createEventConditionals(),
2498
+ field(field2) {
2499
+ return {
2500
+ $event: field2
2501
+ };
2502
+ }
2503
+ });
2504
+
2505
+ // ../commons/src/events/WorkqueueConfig.ts
2506
+ var WorkqueueConfig = import_zod20.z.object({
2507
+ slug: import_zod20.z.string().describe("Determines the url of the workqueue."),
2508
+ name: TranslationConfig.describe(
2509
+ "Title of the workflow (both in navigation and on the page)"
2510
+ ),
2511
+ query: QueryType,
2512
+ actions: import_zod20.z.array(
2513
+ import_zod20.z.object({
2514
+ type: import_zod20.z.string(),
2515
+ conditionals: import_zod20.z.array(Conditional).optional()
2516
+ })
2517
+ ),
2518
+ columns: import_zod20.z.array(
2519
+ import_zod20.z.object({ label: TranslationConfig, value: EventMetadataParameter })
2520
+ ).default([
2521
+ {
2522
+ label: {
2523
+ id: "workqueues.dateOfEvent",
2524
+ defaultMessage: "Date of Event",
2525
+ description: "Label for workqueue column: dateOfEvent"
2526
+ },
2527
+ value: event.field("dateOfEvent")
2528
+ }
2529
+ ])
2530
+ }).describe("Configuration for workqueue.");
2531
+ function defineWorkqueue(workqueues) {
2532
+ return workqueues.map((workqueue) => WorkqueueConfig.parse(workqueue));
2533
+ }
2534
+
2535
+ // ../commons/src/events/Draft.ts
2536
+ var import_zod22 = require("zod");
2537
+
2538
+ // ../commons/src/events/ActionInput.ts
2539
+ var import_zod21 = require("zod");
2540
+ var import_zod_openapi5 = require("zod-openapi");
2541
+ (0, import_zod_openapi5.extendZodWithOpenApi)(import_zod21.z);
2542
+ var BaseActionInput = import_zod21.z.object({
2543
+ eventId: import_zod21.z.string(),
2544
+ transactionId: import_zod21.z.string(),
2545
+ declaration: ActionUpdate.default({}),
2546
+ annotation: ActionUpdate.optional(),
2547
+ originalActionId: import_zod21.z.string().optional(),
2548
+ keepAssignment: import_zod21.z.boolean().optional()
2549
+ });
2550
+ var CreateActionInput = BaseActionInput.merge(
2551
+ import_zod21.z.object({
2552
+ type: import_zod21.z.literal(ActionType.CREATE).default(ActionType.CREATE),
2553
+ createdAtLocation: import_zod21.z.string()
2554
+ })
2555
+ );
2556
+ var RegisterActionInput = BaseActionInput.merge(
2557
+ import_zod21.z.object({
2558
+ type: import_zod21.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
2559
+ registrationNumber: import_zod21.z.string().optional()
2560
+ })
2561
+ );
2562
+ var ValidateActionInput = BaseActionInput.merge(
2563
+ import_zod21.z.object({
2564
+ type: import_zod21.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
2565
+ duplicates: import_zod21.z.array(import_zod21.z.string())
2566
+ })
2567
+ );
2568
+ var NotifyActionInput = BaseActionInput.merge(
2569
+ import_zod21.z.object({
2570
+ type: import_zod21.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
2571
+ })
2572
+ );
2573
+ var DeclareActionInput = BaseActionInput.merge(
2574
+ import_zod21.z.object({
2575
+ type: import_zod21.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
2576
+ })
2577
+ );
2578
+ var PrintCertificateActionInput = BaseActionInput.merge(
2579
+ import_zod21.z.object({
2580
+ type: import_zod21.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
2581
+ })
2582
+ );
2583
+ var RejectDeclarationActionInput = BaseActionInput.merge(
2584
+ import_zod21.z.object({
2585
+ type: import_zod21.z.literal(ActionType.REJECT).default(ActionType.REJECT)
2586
+ })
2587
+ );
2588
+ var MarkedAsDuplicateActionInput = BaseActionInput.merge(
2589
+ import_zod21.z.object({
2590
+ type: import_zod21.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
2591
+ })
2592
+ );
2593
+ var ArchiveActionInput = BaseActionInput.merge(
2594
+ import_zod21.z.object({
2595
+ type: import_zod21.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
2596
+ })
2597
+ );
2598
+ var AssignActionInput = BaseActionInput.merge(
2599
+ import_zod21.z.object({
2600
+ type: import_zod21.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
2601
+ assignedTo: import_zod21.z.string()
2602
+ })
2603
+ );
2604
+ var UnassignActionInput = BaseActionInput.merge(
2605
+ import_zod21.z.object({
2606
+ type: import_zod21.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2607
+ assignedTo: import_zod21.z.literal(null).default(null)
2608
+ })
2609
+ );
2610
+ var RequestCorrectionActionInput = BaseActionInput.merge(
2611
+ import_zod21.z.object({
2612
+ type: import_zod21.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2613
+ })
2614
+ );
2615
+ var RejectCorrectionActionInput = BaseActionInput.merge(
2616
+ import_zod21.z.object({
2617
+ requestId: import_zod21.z.string(),
2618
+ type: import_zod21.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2619
+ })
2620
+ );
2621
+ var ApproveCorrectionActionInput = BaseActionInput.merge(
2622
+ import_zod21.z.object({
2623
+ requestId: import_zod21.z.string(),
2624
+ type: import_zod21.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2625
+ })
2626
+ );
2627
+ var ReadActionInput = BaseActionInput.merge(
2628
+ import_zod21.z.object({
2629
+ type: import_zod21.z.literal(ActionType.READ).default(ActionType.READ)
2630
+ })
2631
+ );
2632
+ var DeleteActionInput = import_zod21.z.object({ eventId: import_zod21.z.string() });
2633
+ var ActionInput = import_zod21.z.discriminatedUnion("type", [
2634
+ CreateActionInput.openapi({ ref: "CreateActionInput" }),
2635
+ ValidateActionInput.openapi({ ref: "ValidateActionInput" }),
2636
+ RegisterActionInput.openapi({ ref: "RegisterActionInput" }),
2637
+ NotifyActionInput.openapi({ ref: "NotifyActionInput" }),
2638
+ DeclareActionInput.openapi({ ref: "DeclareActionInput" }),
2639
+ RejectDeclarationActionInput.openapi({
2640
+ ref: "RejectDeclarationActionInput"
2641
+ }),
2642
+ MarkedAsDuplicateActionInput.openapi({
2643
+ ref: "MarkedAsDuplicateActionInput"
2644
+ }),
2645
+ ArchiveActionInput.openapi({ ref: "ArchiveActionInput" }),
2646
+ AssignActionInput.openapi({ ref: "AssignActionInput" }),
2647
+ UnassignActionInput.openapi({ ref: "UnassignActionInput" }),
2648
+ PrintCertificateActionInput.openapi({ ref: "PrintCertificateActionInput" }),
2649
+ RequestCorrectionActionInput.openapi({
2650
+ ref: "RequestCorrectionActionInput"
2651
+ }),
2652
+ RejectCorrectionActionInput.openapi({ ref: "RejectCorrectionActionInput" }),
2653
+ ApproveCorrectionActionInput.openapi({
2654
+ ref: "ApproveCorrectionActionInput"
2655
+ }),
2656
+ ReadActionInput.openapi({ ref: "ReadActionInput" })
2657
+ ]).openapi({
2658
+ ref: "ActionInput"
2659
+ });
2660
+
2661
+ // ../commons/src/events/Draft.ts
2662
+ var Draft = import_zod22.z.object({
2663
+ id: import_zod22.z.string(),
2664
+ eventId: import_zod22.z.string(),
2665
+ transactionId: import_zod22.z.string(),
2666
+ createdAt: import_zod22.z.string().datetime(),
2667
+ action: ActionBase.extend({
2668
+ type: ActionTypes
2669
+ }).omit({ id: true })
2670
+ });
2671
+ var DraftInput = BaseActionInput.extend({
2672
+ type: ActionTypes,
2673
+ status: import_zod22.z.enum([
2674
+ ActionStatus.Requested,
2675
+ ActionStatus.Accepted,
2676
+ ActionStatus.Rejected
2677
+ ])
2678
+ });
2679
+
2680
+ // ../commons/src/events/EventInput.ts
2681
+ var import_zod23 = require("zod");
2682
+ var EventInput = import_zod23.z.object({
2683
+ transactionId: import_zod23.z.string(),
2684
+ type: import_zod23.z.string(),
2685
+ dateOfEvent: import_zod23.z.object({ fieldId: import_zod23.z.string() }).optional()
2686
+ });
2687
+
2688
+ // ../commons/src/events/EventDocument.ts
2689
+ var import_zod24 = require("zod");
2690
+ var import_zod_openapi6 = require("zod-openapi");
2691
+ (0, import_zod_openapi6.extendZodWithOpenApi)(import_zod24.z);
2692
+ var EventDocument = import_zod24.z.object({
2693
+ id: import_zod24.z.string(),
2694
+ type: import_zod24.z.string(),
2695
+ dateOfEvent: import_zod24.z.object({ fieldId: import_zod24.z.string() }).optional(),
2696
+ createdAt: import_zod24.z.string().datetime(),
2697
+ updatedAt: import_zod24.z.string().datetime(),
2698
+ actions: import_zod24.z.array(Action),
2699
+ trackingId: import_zod24.z.string()
2700
+ }).openapi({ ref: "EventDocument" });
2701
+
2702
+ // ../commons/src/events/state/utils.ts
2703
+ function getActionRequests(actionType, actions) {
2704
+ const filtered = actions.filter((action) => action.type === actionType);
2705
+ const accept = filtered.find(
2706
+ (action) => action.status === ActionStatus.Accepted
2707
+ );
2708
+ const request = filtered.find(
2709
+ (action) => action.status === ActionStatus.Requested
2710
+ );
2711
+ const reject = filtered.find(
2712
+ (action) => action.status === ActionStatus.Rejected
2713
+ );
2714
+ return {
2715
+ reject,
2716
+ accept,
2717
+ request
2718
+ };
2719
+ }
2720
+ function getDeclarationActionCreationMetadata(actionType, actions) {
2721
+ const { accept: acceptAction, request: requestAction } = getActionRequests(
2722
+ actionType,
2723
+ actions
2724
+ );
2725
+ if (!acceptAction) {
2726
+ return null;
2727
+ }
2728
+ const registrationNumber = acceptAction.type === ActionType.REGISTER ? acceptAction.registrationNumber : null;
2729
+ return {
2730
+ // When 3rd party API returns 200 OK, we assume that the request was accepted, and persist single 'accepted' action.
2731
+ createdAt: requestAction?.createdAt ?? acceptAction.createdAt,
2732
+ createdBy: requestAction?.createdBy ?? acceptAction.createdBy,
2733
+ createdAtLocation: requestAction?.createdAtLocation ?? acceptAction.createdAtLocation,
2734
+ acceptedAt: acceptAction.createdAt,
2735
+ createdByRole: requestAction?.createdByRole ?? acceptAction.createdByRole,
2736
+ registrationNumber
2737
+ };
2738
+ }
2739
+ function getDeclarationActionUpdateMetadata(actions) {
2740
+ const createAction = getOrThrow(
2741
+ actions.find((action) => action.type === ActionType.CREATE),
2742
+ `Event has no ${ActionType.CREATE} action`
2743
+ );
2744
+ return [ActionType.DECLARE, ActionType.VALIDATE, ActionType.REGISTER].reduce(
2745
+ (metadata, actionType) => {
2746
+ const { accept, request } = getActionRequests(actionType, actions);
2747
+ return {
2748
+ createdAt: request?.createdAt ?? accept?.createdAt ?? metadata.createdAt,
2749
+ createdBy: request?.createdBy ?? accept?.createdBy ?? metadata.createdBy,
2750
+ createdAtLocation: request?.createdAtLocation ?? accept?.createdAtLocation ?? metadata.createdAtLocation,
2751
+ createdByRole: request?.createdByRole ?? accept?.createdByRole ?? metadata.createdByRole
2752
+ };
2753
+ },
2754
+ {
2755
+ createdAt: createAction.createdAt,
2756
+ createdBy: createAction.createdBy,
2757
+ createdAtLocation: createAction.createdAtLocation,
2758
+ createdByRole: createAction.createdByRole
2759
+ }
2760
+ );
2761
+ }
2762
+ function getLegalStatuses(actions) {
2763
+ return {
2764
+ [EventStatus.DECLARED]: getDeclarationActionCreationMetadata(
2765
+ ActionType.DECLARE,
2766
+ actions
2767
+ ),
2768
+ [EventStatus.REGISTERED]: getDeclarationActionCreationMetadata(
2769
+ ActionType.REGISTER,
2770
+ actions
2771
+ )
2772
+ };
2773
+ }
2774
+
2775
+ // ../commons/src/events/state/index.ts
2776
+ function getStatusFromActions(actions) {
2777
+ const hasRejectedAction = actions.some(
2778
+ (a) => a.status === ActionStatus.Rejected
2779
+ );
2780
+ if (hasRejectedAction) {
2781
+ return EventStatus.REJECTED;
2782
+ }
2783
+ return actions.reduce((status, action) => {
2784
+ switch (action.type) {
2785
+ case ActionType.CREATE:
2786
+ return EventStatus.CREATED;
2787
+ case ActionType.DECLARE:
2788
+ return EventStatus.DECLARED;
2789
+ case ActionType.VALIDATE:
2790
+ return EventStatus.VALIDATED;
2791
+ case ActionType.REGISTER:
2792
+ return EventStatus.REGISTERED;
2793
+ case ActionType.REJECT:
2794
+ return EventStatus.REJECTED;
2795
+ case ActionType.ARCHIVE:
2796
+ return EventStatus.ARCHIVED;
2797
+ case ActionType.NOTIFY:
2798
+ return EventStatus.NOTIFIED;
2799
+ case ActionType.PRINT_CERTIFICATE:
2800
+ return EventStatus.CERTIFIED;
2801
+ case ActionType.ASSIGN:
2802
+ case ActionType.UNASSIGN:
2803
+ case ActionType.REQUEST_CORRECTION:
2804
+ case ActionType.APPROVE_CORRECTION:
2805
+ case ActionType.MARKED_AS_DUPLICATE:
2806
+ case ActionType.REJECT_CORRECTION:
2807
+ case ActionType.READ:
2808
+ default:
2809
+ return status;
2810
+ }
2811
+ }, EventStatus.CREATED);
2812
+ }
2813
+ function getFlagsFromActions(actions) {
2814
+ const sortedactions = actions.sort(
2815
+ (a, b) => a.createdAt.localeCompare(b.createdAt)
2816
+ );
2817
+ const actionStatus = sortedactions.reduce(
2818
+ (actionStatuses, { type, status }) => ({
2819
+ ...actionStatuses,
2820
+ [type]: status
2821
+ }),
2822
+ {}
2823
+ );
2824
+ const flags = Object.entries(actionStatus).filter(([, status]) => status !== ActionStatus.Accepted).map(([type, status]) => {
2825
+ const flag = `${type.toLowerCase()}:${status.toLowerCase()}`;
2826
+ return flag;
2827
+ });
2828
+ const isCertificatePrinted = sortedactions.reduce(
2829
+ (prev, { type }) => {
2830
+ if (type === ActionType.PRINT_CERTIFICATE) {
2831
+ return true;
2712
2832
  }
2713
- }),
2714
- inArray: (values) => defineFormConditional({
2715
- type: "object",
2716
- properties: {
2717
- [fieldId]: {
2718
- type: "string",
2719
- enum: values
2720
- }
2721
- },
2722
- required: [fieldId]
2723
- }),
2724
- isValidEnglishName: () => defineFormConditional({
2725
- type: "object",
2726
- properties: {
2727
- [fieldId]: {
2728
- type: "string",
2729
- 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'._-]*)*$",
2730
- description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2731
- }
2732
- },
2733
- required: [fieldId]
2734
- }),
2735
- /**
2736
- * Checks if the field value matches a given regular expression pattern.
2737
- * @param pattern - The regular expression pattern to match the field value against.
2738
- * @returns A JSONSchema conditional that validates the field value against the pattern.
2739
- */
2740
- matches: (pattern) => defineFormConditional({
2741
- type: "object",
2742
- properties: {
2743
- [fieldId]: {
2744
- type: "string",
2745
- pattern
2746
- }
2747
- },
2748
- required: [fieldId]
2749
- }),
2750
- isBetween: (min, max) => defineFormConditional({
2751
- type: "object",
2752
- properties: {
2753
- [fieldId]: {
2754
- type: "number",
2755
- minimum: min,
2756
- maximum: max
2833
+ if (type === ActionType.APPROVE_CORRECTION) {
2834
+ return false;
2835
+ }
2836
+ return prev;
2837
+ },
2838
+ false
2839
+ );
2840
+ if (isCertificatePrinted) {
2841
+ flags.push(CustomFlags.CERTIFICATE_PRINTED);
2842
+ }
2843
+ return flags;
2844
+ }
2845
+ function getAssignedUserFromActions(actions) {
2846
+ return actions.reduce((user2, action) => {
2847
+ if (action.type === ActionType.ASSIGN) {
2848
+ return action.assignedTo;
2849
+ }
2850
+ if (action.type === ActionType.UNASSIGN) {
2851
+ return null;
2852
+ }
2853
+ return user2;
2854
+ }, null);
2855
+ }
2856
+ function aggregateActionDeclarations(actions) {
2857
+ const excludedActions = [
2858
+ ActionType.REQUEST_CORRECTION,
2859
+ ActionType.PRINT_CERTIFICATE
2860
+ ];
2861
+ return actions.reduce((status, action) => {
2862
+ if (excludedActions.some((excludedAction) => excludedAction === action.type)) {
2863
+ return status;
2864
+ }
2865
+ if (action.type === ActionType.APPROVE_CORRECTION) {
2866
+ const requestAction = actions.find(({ id }) => id === action.requestId);
2867
+ if (!requestAction) {
2868
+ return status;
2869
+ }
2870
+ return deepMerge(status, requestAction.declaration);
2871
+ }
2872
+ return deepMerge(status, action.declaration);
2873
+ }, {});
2874
+ }
2875
+ function deepDropNulls(obj) {
2876
+ if (Array.isArray(obj)) {
2877
+ return obj.map(deepDropNulls);
2878
+ }
2879
+ if (obj !== null && typeof obj === "object") {
2880
+ return Object.entries(obj).reduce((acc, [key, value]) => {
2881
+ const cleanedValue = deepDropNulls(value);
2882
+ if (cleanedValue !== null) {
2883
+ ;
2884
+ acc[key] = cleanedValue;
2885
+ }
2886
+ return acc;
2887
+ }, {});
2888
+ }
2889
+ return obj;
2890
+ }
2891
+ function isUndeclaredDraft(status) {
2892
+ return status === EventStatus.CREATED;
2893
+ }
2894
+ function getAcceptedActions(event2) {
2895
+ return event2.actions.filter(
2896
+ (a) => a.status === ActionStatus.Accepted
2897
+ );
2898
+ }
2899
+ var DEFAULT_DATE_OF_EVENT_PROPERTY = "createdAt";
2900
+ function getCurrentEventState(event2) {
2901
+ const creationAction = event2.actions.find(
2902
+ (action) => action.type === ActionType.CREATE
2903
+ );
2904
+ if (!creationAction) {
2905
+ throw new Error(`Event ${event2.id} has no creation action`);
2906
+ }
2907
+ const acceptedActions = getAcceptedActions(event2);
2908
+ const declarationUpdateMetadata = getDeclarationActionUpdateMetadata(
2909
+ event2.actions
2910
+ );
2911
+ const declaration = aggregateActionDeclarations(acceptedActions);
2912
+ const dateOfEvent = ZodDate.safeParse(
2913
+ event2.dateOfEvent?.fieldId ? declaration[event2.dateOfEvent.fieldId] : event2[DEFAULT_DATE_OF_EVENT_PROPERTY]
2914
+ ).data ?? null;
2915
+ return deepDropNulls({
2916
+ id: event2.id,
2917
+ type: event2.type,
2918
+ status: getStatusFromActions(event2.actions),
2919
+ legalStatuses: getLegalStatuses(event2.actions),
2920
+ createdAt: creationAction.createdAt,
2921
+ createdBy: creationAction.createdBy,
2922
+ createdAtLocation: creationAction.createdAtLocation,
2923
+ updatedAt: declarationUpdateMetadata.createdAt,
2924
+ assignedTo: getAssignedUserFromActions(acceptedActions),
2925
+ updatedBy: declarationUpdateMetadata.createdBy,
2926
+ updatedAtLocation: declarationUpdateMetadata.createdAtLocation,
2927
+ declaration,
2928
+ trackingId: event2.trackingId,
2929
+ // @TODO: unify this with rest of the code. It will trip us if updatedBy has different rules than updatedByUserRole
2930
+ updatedByUserRole: declarationUpdateMetadata.createdByRole,
2931
+ dateOfEvent,
2932
+ flags: getFlagsFromActions(event2.actions)
2933
+ });
2934
+ }
2935
+ function getCurrentEventStateWithDrafts(event2, drafts) {
2936
+ const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2937
+ const activeDrafts = findActiveDrafts(event2, drafts).map((draft) => draft.action).flatMap((action) => {
2938
+ if (action.type === ActionType.REQUEST_CORRECTION) {
2939
+ return [
2940
+ action,
2941
+ {
2942
+ ...action,
2943
+ type: ActionType.APPROVE_CORRECTION
2757
2944
  }
2758
- },
2759
- required: [fieldId]
2760
- }),
2761
- getId: () => ({ fieldId })
2945
+ ];
2946
+ }
2947
+ return [action];
2948
+ });
2949
+ const actionWithDrafts = [...actions, ...activeDrafts].sort();
2950
+ const withDrafts = {
2951
+ ...event2,
2952
+ actions: actionWithDrafts
2953
+ };
2954
+ return getCurrentEventState(withDrafts);
2955
+ }
2956
+ function applyDraftsToEventIndex(eventIndex, drafts) {
2957
+ const indexedAt = eventIndex.updatedAt;
2958
+ const activeDrafts = drafts.filter(({ createdAt }) => new Date(createdAt) > new Date(indexedAt)).map((draft) => draft.action).sort();
2959
+ if (activeDrafts.length === 0) {
2960
+ return eventIndex;
2961
+ }
2962
+ return {
2963
+ ...eventIndex,
2964
+ declaration: {
2965
+ ...eventIndex.declaration,
2966
+ ...activeDrafts[activeDrafts.length - 1].declaration
2967
+ }
2762
2968
  };
2763
2969
  }
2970
+ function getAnnotationFromDrafts(drafts) {
2971
+ const actions = drafts.map((draft) => draft.action);
2972
+ const annotation = actions.reduce((ann, action) => {
2973
+ return deepMerge(ann, action.annotation ?? {});
2974
+ }, {});
2975
+ return deepDropNulls(annotation);
2976
+ }
2977
+ function getActionAnnotation({
2978
+ event: event2,
2979
+ actionType,
2980
+ drafts = []
2981
+ }) {
2982
+ const activeActions = getAcceptedActions(event2);
2983
+ const action = activeActions.find(
2984
+ (activeAction) => actionType === activeAction.type
2985
+ );
2986
+ const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
2987
+ const sorted = [
2988
+ ...action ? [action] : [],
2989
+ ...eventDrafts.map((draft) => draft.action)
2990
+ ].sort();
2991
+ const annotation = sorted.reduce((ann, sortedAction) => {
2992
+ return deepMerge(ann, sortedAction.annotation ?? {});
2993
+ }, {});
2994
+ return deepDropNulls(annotation);
2995
+ }
2996
+
2997
+ // ../commons/src/events/defineConfig.ts
2998
+ var defineConfig = (config) => {
2999
+ const input = EventConfig.parse(config);
3000
+ return input;
3001
+ };
3002
+
3003
+ // ../commons/src/events/transactions.ts
3004
+ function generateTransactionId() {
3005
+ return getUUID();
3006
+ }
3007
+
3008
+ // ../commons/src/events/test.utils.ts
3009
+ var import_lodash2 = require("lodash");
2764
3010
 
2765
3011
  // ../commons/src/field-config/field-configuration.ts
2766
3012
  function createFieldConfigs(fieldId) {
@@ -2772,43 +3018,43 @@ function createFieldConfigs(fieldId) {
2772
3018
  /**
2773
3019
  * Creates a range configuration for the specified field.
2774
3020
  *
2775
- * @returns An object containing the field ID and a configuration object with a type of 'RANGE'.
3021
+ * @returns An object containing the field ID and a configuration object with a type of 'range'.
2776
3022
  *
2777
3023
  * @example field('age').range()
2778
3024
  * // {
2779
3025
  * // fieldId: 'age',
2780
- * // config: { type: 'RANGE' }
3026
+ * // config: { type: 'range' }
2781
3027
  * // }
2782
3028
  */
2783
3029
  range: () => ({
2784
3030
  ...baseField,
2785
- config: { type: "RANGE" }
3031
+ config: { type: "range" }
2786
3032
  }),
2787
3033
  /**
2788
3034
  * Creates a configuration for exact matching of the specified field.
2789
- * @returns An object containing the field ID and a configuration object with a type of 'EXACT'.
3035
+ * @returns An object containing the field ID and a configuration object with a type of 'exact'.
2790
3036
  * @example field('dob').exact()
2791
3037
  * // {
2792
3038
  * // fieldId: 'dob',
2793
- * // config: { type: 'EXACT' }
3039
+ * // config: { type: 'exact' }
2794
3040
  * // }
2795
3041
  */
2796
3042
  exact: () => ({
2797
3043
  ...baseField,
2798
- config: { type: "EXACT" }
3044
+ config: { type: "exact" }
2799
3045
  }),
2800
3046
  /**
2801
3047
  * Creates a configuration for fuzzy matching of the specified field.
2802
- * @returns An object containing the field ID and a configuration object with a type of 'EXACT'.
3048
+ * @returns An object containing the field ID and a configuration object with a type of 'exact'.
2803
3049
  * @example field('name').fuzzy()
2804
3050
  * // {
2805
3051
  * // fieldId: 'name',
2806
- * // config: { type: 'FUZZY' }
3052
+ * // config: { type: 'fuzzy' }
2807
3053
  * // }
2808
3054
  */
2809
3055
  fuzzy: () => ({
2810
3056
  ...baseField,
2811
- config: { type: "FUZZY" }
3057
+ config: { type: "fuzzy" }
2812
3058
  })
2813
3059
  };
2814
3060
  }
@@ -3767,22 +4013,15 @@ var tennisClubMembershipEvent = defineConfig({
3767
4013
  }
3768
4014
  },
3769
4015
  {
3770
- id: "applicant.surname",
4016
+ fieldId: "applicant.surname",
3771
4017
  label: {
3772
4018
  defaultMessage: "Applicant's last name",
3773
- description: "This is the label for the field",
3774
- id: "event.tennis-club-membership.summary.field.surname.label"
3775
- },
3776
- value: {
3777
- defaultMessage: "{applicant.surname}",
3778
- description: "This is the value to show in the summary",
3779
- id: "event.tennis-club-membership.summary.field.surname"
3780
- },
3781
- emptyValueMessage: {
3782
- defaultMessage: "Last name is not provided",
3783
- description: "This is the message to show when the field is empty",
3784
- id: "event.tennis-club-membership.summary.field.surname.empty"
4019
+ description: "Label for surname",
4020
+ id: "v2.event.tennis-club-membership.summary.field.surname.label"
3785
4021
  }
4022
+ },
4023
+ {
4024
+ fieldId: "applicant.email"
3786
4025
  }
3787
4026
  ]
3788
4027
  },
@@ -4176,8 +4415,7 @@ var eventPayloadGenerator = {
4176
4415
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4177
4416
  createdBy: "@todo",
4178
4417
  createdByRole: "@todo",
4179
- createdAtLocation: "@todo",
4180
- updatedAtLocation: "@todo"
4418
+ createdAtLocation: "@todo"
4181
4419
  }
4182
4420
  },
4183
4421
  input
@@ -4340,13 +4578,12 @@ function generateActionDocument({
4340
4578
  createdBy: getUUID(),
4341
4579
  createdByRole: "FIELD_AGENT",
4342
4580
  id: getUUID(),
4343
- createdAtLocation: "TODO",
4344
- updatedAtLocation: "TODO",
4581
+ createdAtLocation: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
4345
4582
  declaration: generateActionDeclarationInput(configuration, action),
4346
4583
  annotation: {},
4347
- ...defaults,
4348
4584
  status: ActionStatus.Accepted,
4349
- transactionId: getUUID()
4585
+ transactionId: getUUID(),
4586
+ ...defaults
4350
4587
  };
4351
4588
  switch (action) {
4352
4589
  case ActionType.READ:
@@ -4405,8 +4642,7 @@ function generateEventDocument({
4405
4642
  // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4406
4643
  // @TODO: This should be fixed in the future.
4407
4644
  updatedAt: new Date(Date.now() - 1e3).toISOString(),
4408
- dateOfEvent: configuration.dateOfEvent,
4409
- updatedAtLocation: getUUID()
4645
+ dateOfEvent: configuration.dateOfEvent
4410
4646
  };
4411
4647
  }
4412
4648
  function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
@@ -4428,10 +4664,64 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, de
4428
4664
  eventId
4429
4665
  };
4430
4666
  }
4667
+ function getEventStatus() {
4668
+ const statuses = [
4669
+ EventStatus.CREATED,
4670
+ EventStatus.REGISTERED,
4671
+ EventStatus.DECLARED
4672
+ ];
4673
+ const randomIndex = Math.floor(Math.random() * 3);
4674
+ return statuses[randomIndex];
4675
+ }
4676
+ function getTrackingId() {
4677
+ const uuid = getUUID().replace(/-/g, "");
4678
+ const trackingId = uuid.slice(0, 6).toUpperCase();
4679
+ return trackingId;
4680
+ }
4681
+ function getRandomApplicant() {
4682
+ const firstNames = [
4683
+ "Danny",
4684
+ "John",
4685
+ "Jane",
4686
+ "Emily",
4687
+ "Michael",
4688
+ "Sarah",
4689
+ "Chris",
4690
+ "Jessica"
4691
+ ];
4692
+ const surnames = [
4693
+ "Doe",
4694
+ "Smith",
4695
+ "Johnson",
4696
+ "Brown",
4697
+ "Williams",
4698
+ "Jones",
4699
+ "Garcia",
4700
+ "Miller"
4701
+ ];
4702
+ function getRandomDate(start, end) {
4703
+ const randomDate = new Date(
4704
+ start.getTime() + Math.random() * (end.getTime() - start.getTime())
4705
+ );
4706
+ return randomDate.toISOString().split("T")[0];
4707
+ }
4708
+ const randomFirstName = firstNames[Math.floor(Math.random() * firstNames.length)];
4709
+ const randomSurname = surnames[Math.floor(Math.random() * surnames.length)];
4710
+ const randomDob = getRandomDate(
4711
+ /* @__PURE__ */ new Date("1990-01-01"),
4712
+ /* @__PURE__ */ new Date("2010-12-31")
4713
+ );
4714
+ return {
4715
+ "recommender.none": true,
4716
+ "applicant.firstname": randomFirstName,
4717
+ "applicant.surname": randomSurname,
4718
+ "applicant.dob": randomDob
4719
+ };
4720
+ }
4431
4721
  var eventQueryDataGenerator = (overrides = {}) => ({
4432
4722
  id: overrides.id ?? getUUID(),
4433
- type: overrides.type ?? "tennis-club-membership",
4434
- status: overrides.status ?? "REGISTERED",
4723
+ type: overrides.type ?? "TENNIS_CLUB_MEMBERSHIP",
4724
+ status: overrides.status ?? getEventStatus(),
4435
4725
  createdAt: overrides.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4436
4726
  createdBy: overrides.createdBy ?? getUUID(),
4437
4727
  createdAtLocation: overrides.createdAtLocation ?? getUUID(),
@@ -4440,13 +4730,10 @@ var eventQueryDataGenerator = (overrides = {}) => ({
4440
4730
  assignedTo: overrides.assignedTo ?? null,
4441
4731
  updatedBy: overrides.updatedBy ?? getUUID(),
4442
4732
  updatedByUserRole: overrides.updatedByUserRole ?? "FIELD_AGENT",
4443
- declaration: overrides.declaration ?? {
4444
- "recommender.none": true,
4445
- "applicant.firstname": "Danny",
4446
- "applicant.surname": "Doe",
4447
- "applicant.dob": "1999-11-11"
4448
- },
4449
- trackingId: overrides.trackingId ?? "M3F8YQ"
4733
+ flags: [],
4734
+ legalStatuses: overrides.legalStatuses ?? {},
4735
+ declaration: overrides.declaration ?? getRandomApplicant(),
4736
+ trackingId: overrides.trackingId ?? getTrackingId()
4450
4737
  });
4451
4738
  var generateTranslationConfig = (message) => ({
4452
4739
  defaultMessage: message,
@@ -4490,6 +4777,7 @@ function isFieldConfigDefaultValue(value) {
4490
4777
  var import_lodash3 = require("lodash");
4491
4778
 
4492
4779
  // ../commons/src/scopes.ts
4780
+ var import_zod25 = require("zod");
4493
4781
  var SCOPES = {
4494
4782
  // TODO v1.8 legacy scopes
4495
4783
  NATLSYSADMIN: "natlsysadmin",
@@ -4600,6 +4888,101 @@ var SCOPES = {
4600
4888
  // data seeding
4601
4889
  USER_DATA_SEEDING: "user.data-seeding"
4602
4890
  };
4891
+ var LiteralScopes = import_zod25.z.union([
4892
+ import_zod25.z.literal(SCOPES.NATLSYSADMIN),
4893
+ import_zod25.z.literal(SCOPES.BYPASSRATELIMIT),
4894
+ import_zod25.z.literal(SCOPES.DECLARE),
4895
+ import_zod25.z.literal(SCOPES.REGISTER),
4896
+ import_zod25.z.literal(SCOPES.VALIDATE),
4897
+ import_zod25.z.literal(SCOPES.DEMO),
4898
+ import_zod25.z.literal(SCOPES.CERTIFY),
4899
+ import_zod25.z.literal(SCOPES.PERFORMANCE),
4900
+ import_zod25.z.literal(SCOPES.SYSADMIN),
4901
+ import_zod25.z.literal(SCOPES.TEAMS),
4902
+ import_zod25.z.literal(SCOPES.CONFIG),
4903
+ import_zod25.z.literal(SCOPES.WEBHOOK),
4904
+ import_zod25.z.literal(SCOPES.NATIONALID),
4905
+ import_zod25.z.literal(SCOPES.NOTIFICATION_API),
4906
+ import_zod25.z.literal(SCOPES.RECORDSEARCH),
4907
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_BIRTH),
4908
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_BIRTH_MY_JURISDICTION),
4909
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_DEATH),
4910
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_DEATH_MY_JURISDICTION),
4911
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE),
4912
+ import_zod25.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE_MY_JURISDICTION),
4913
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_INCOMPLETE),
4914
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_FOR_REVIEW),
4915
+ import_zod25.z.literal(SCOPES.RECORD_UNASSIGN_OTHERS),
4916
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_FOR_APPROVAL),
4917
+ import_zod25.z.literal(SCOPES.RECORD_SUBMIT_FOR_UPDATES),
4918
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_EDIT),
4919
+ import_zod25.z.literal(SCOPES.RECORD_REVIEW_DUPLICATES),
4920
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_ARCHIVE),
4921
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_REINSTATE),
4922
+ import_zod25.z.literal(SCOPES.RECORD_REGISTER),
4923
+ import_zod25.z.literal(SCOPES.RECORD_EXPORT_RECORDS),
4924
+ import_zod25.z.literal(SCOPES.RECORD_DECLARATION_PRINT),
4925
+ import_zod25.z.literal(SCOPES.RECORD_PRINT_RECORDS_SUPPORTING_DOCUMENTS),
4926
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_PRINT),
4927
+ import_zod25.z.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
4928
+ import_zod25.z.literal(SCOPES.RECORD_PRINT_CERTIFIED_COPIES),
4929
+ import_zod25.z.literal(SCOPES.RECORD_BULK_PRINT_CERTIFIED_COPIES),
4930
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES),
4931
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION),
4932
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_CORRECT),
4933
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_REVOCATION),
4934
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REVOKE),
4935
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_REINSTATEMENT),
4936
+ import_zod25.z.literal(SCOPES.RECORD_REGISTRATION_REINSTATE),
4937
+ import_zod25.z.literal(SCOPES.RECORD_CONFIRM_REGISTRATION),
4938
+ import_zod25.z.literal(SCOPES.RECORD_REJECT_REGISTRATION),
4939
+ import_zod25.z.literal(SCOPES.SEARCH_BIRTH_MY_JURISDICTION),
4940
+ import_zod25.z.literal(SCOPES.SEARCH_BIRTH),
4941
+ import_zod25.z.literal(SCOPES.SEARCH_DEATH_MY_JURISDICTION),
4942
+ import_zod25.z.literal(SCOPES.SEARCH_DEATH),
4943
+ import_zod25.z.literal(SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION),
4944
+ import_zod25.z.literal(SCOPES.SEARCH_MARRIAGE),
4945
+ import_zod25.z.literal(SCOPES.RECORD_READ),
4946
+ import_zod25.z.literal(SCOPES.RECORD_READ_AUDIT),
4947
+ import_zod25.z.literal(SCOPES.RECORD_READ_COMMENTS),
4948
+ import_zod25.z.literal(SCOPES.RECORD_CREATE_COMMENTS),
4949
+ import_zod25.z.literal(SCOPES.PROFILE_UPDATE),
4950
+ import_zod25.z.literal(SCOPES.PROFILE_ELECTRONIC_SIGNATURE),
4951
+ import_zod25.z.literal(SCOPES.PERFORMANCE_READ),
4952
+ import_zod25.z.literal(SCOPES.PERFORMANCE_READ_DASHBOARDS),
4953
+ import_zod25.z.literal(SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS),
4954
+ import_zod25.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS),
4955
+ import_zod25.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE),
4956
+ import_zod25.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_JURISDICTION),
4957
+ import_zod25.z.literal(SCOPES.USER_READ),
4958
+ import_zod25.z.literal(SCOPES.USER_READ_MY_OFFICE),
4959
+ import_zod25.z.literal(SCOPES.USER_READ_MY_JURISDICTION),
4960
+ import_zod25.z.literal(SCOPES.USER_READ_ONLY_MY_AUDIT),
4961
+ import_zod25.z.literal(SCOPES.USER_CREATE),
4962
+ import_zod25.z.literal(SCOPES.USER_CREATE_MY_JURISDICTION),
4963
+ import_zod25.z.literal(SCOPES.USER_UPDATE),
4964
+ import_zod25.z.literal(SCOPES.USER_UPDATE_MY_JURISDICTION),
4965
+ import_zod25.z.literal(SCOPES.CONFIG_UPDATE_ALL),
4966
+ import_zod25.z.literal(SCOPES.USER_DATA_SEEDING)
4967
+ ]);
4968
+ var rawConfigurableScopeRegex = /^([a-zA-Z]+\.[a-zA-Z]+)\[((?:\w+=\w+(?:\|\w+)*)(:?,\w+=\w+(?:\|\w+)*)*)\]$/;
4969
+ var rawConfigurableScope = import_zod25.z.string().regex(rawConfigurableScopeRegex);
4970
+ var CreateUserScope = import_zod25.z.object({
4971
+ type: import_zod25.z.literal("user.create"),
4972
+ options: import_zod25.z.object({
4973
+ role: import_zod25.z.array(import_zod25.z.string())
4974
+ })
4975
+ });
4976
+ var EditUserScope = import_zod25.z.object({
4977
+ type: import_zod25.z.literal("user.edit"),
4978
+ options: import_zod25.z.object({
4979
+ role: import_zod25.z.array(import_zod25.z.string())
4980
+ })
4981
+ });
4982
+ var ConfigurableScopes = import_zod25.z.discriminatedUnion("type", [
4983
+ CreateUserScope,
4984
+ EditUserScope
4985
+ ]);
4603
4986
  var scopes = Object.values(SCOPES);
4604
4987
 
4605
4988
  // ../commons/src/events/scopes.ts
@@ -4679,19 +5062,3 @@ function filterUnallowedActions(actions, userScopes) {
4679
5062
  }
4680
5063
  return [ActionType.READ];
4681
5064
  }
4682
-
4683
- // ../commons/src/event-config/event-configuration.ts
4684
- function createEventFieldConfig(fieldId, options) {
4685
- return {
4686
- fieldId,
4687
- options,
4688
- config: { type: "EXACT" },
4689
- fieldType: "event"
4690
- };
4691
- }
4692
-
4693
- // ../commons/src/events/event.ts
4694
- function eventFn(fieldId, options) {
4695
- return createEventFieldConfig(fieldId, options);
4696
- }
4697
- var event = Object.assign(eventFn, createEventConditionals());