@opencrvs/toolkit 1.8.0-rc.fbb7263 → 1.8.0-rc.fd16d13

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.
@@ -40,9 +40,10 @@ __export(events_exports, {
40
40
  ActionUpdate: () => ActionUpdate,
41
41
  AddressFieldUpdateValue: () => AddressFieldUpdateValue,
42
42
  AddressFieldValue: () => AddressFieldValue,
43
+ AdministrativeAreas: () => AdministrativeAreas,
43
44
  AdvancedSearchConfig: () => AdvancedSearchConfig,
44
45
  ApproveCorrectionActionInput: () => ApproveCorrectionActionInput,
45
- ArchivedActionInput: () => ArchivedActionInput,
46
+ ArchiveActionInput: () => ArchiveActionInput,
46
47
  BaseActionInput: () => BaseActionInput,
47
48
  CertificateConfig: () => CertificateConfig,
48
49
  CertificateTemplateConfig: () => CertificateTemplateConfig,
@@ -75,6 +76,8 @@ __export(events_exports, {
75
76
  FileFieldWithOptionValue: () => FileFieldWithOptionValue,
76
77
  FormConfig: () => FormConfig,
77
78
  FormPage: () => FormPage,
79
+ GenericAddressUpdateValue: () => GenericAddressUpdateValue,
80
+ GenericAddressValue: () => GenericAddressValue,
78
81
  GeographicalArea: () => GeographicalArea,
79
82
  LanguageConfig: () => LanguageConfig,
80
83
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
@@ -100,12 +103,15 @@ __export(events_exports, {
100
103
  alwaysTrue: () => alwaysTrue,
101
104
  and: () => and,
102
105
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
106
+ compositeFieldTypes: () => compositeFieldTypes,
107
+ createEmptyDraft: () => createEmptyDraft,
103
108
  createValidationSchema: () => createValidationSchema,
104
109
  deepDropNulls: () => deepDropNulls,
105
110
  defineConditional: () => defineConditional,
106
111
  defineConfig: () => defineConfig,
107
112
  defineForm: () => defineForm,
108
113
  defineFormPage: () => defineFormPage,
114
+ errorMessages: () => errorMessages,
109
115
  event: () => event,
110
116
  eventMetadataLabelMap: () => eventMetadataLabelMap,
111
117
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -117,6 +123,7 @@ __export(events_exports, {
117
123
  findActiveActionForm: () => findActiveActionForm,
118
124
  findActiveActionFormFields: () => findActiveActionFormFields,
119
125
  findActiveActionFormPages: () => findActiveActionFormPages,
126
+ findActiveDrafts: () => findActiveDrafts,
120
127
  findInputPageFields: () => findInputPageFields,
121
128
  findPageFields: () => findPageFields,
122
129
  generateActionDocument: () => generateActionDocument,
@@ -125,6 +132,7 @@ __export(events_exports, {
125
132
  generateEventDraftDocument: () => generateEventDraftDocument,
126
133
  generateTransactionId: () => generateTransactionId,
127
134
  getActiveActionFields: () => getActiveActionFields,
135
+ getActiveActionFormPages: () => getActiveActionFormPages,
128
136
  getAllFields: () => getAllFields,
129
137
  getAllPages: () => getAllPages,
130
138
  getCurrentEventState: () => getCurrentEventState,
@@ -142,7 +150,10 @@ __export(events_exports, {
142
150
  isDividerFieldType: () => isDividerFieldType,
143
151
  isEmailFieldType: () => isEmailFieldType,
144
152
  isFacilityFieldType: () => isFacilityFieldType,
153
+ isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
145
154
  isFieldEnabled: () => isFieldEnabled,
155
+ isFieldValue: () => isFieldValue,
156
+ isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
146
157
  isFieldVisible: () => isFieldVisible,
147
158
  isFileFieldType: () => isFileFieldType,
148
159
  isFileFieldWithOptionType: () => isFileFieldWithOptionType,
@@ -154,9 +165,11 @@ __export(events_exports, {
154
165
  isRadioGroupFieldType: () => isRadioGroupFieldType,
155
166
  isSelectFieldType: () => isSelectFieldType,
156
167
  isSignatureFieldType: () => isSignatureFieldType,
168
+ isTemplateVariable: () => isTemplateVariable,
157
169
  isTextAreaFieldType: () => isTextAreaFieldType,
158
170
  isTextFieldType: () => isTextFieldType,
159
171
  isUndeclaredDraft: () => isUndeclaredDraft,
172
+ mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
160
173
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
161
174
  mapFieldTypeToZod: () => mapFieldTypeToZod,
162
175
  not: () => not,
@@ -243,6 +256,11 @@ var FieldType = {
243
256
  SIGNATURE: "SIGNATURE"
244
257
  };
245
258
  var fieldTypes = Object.values(FieldType);
259
+ var compositeFieldTypes = [
260
+ FieldType.ADDRESS,
261
+ FieldType.FILE_WITH_OPTIONS,
262
+ FieldType.FILE
263
+ ];
246
264
 
247
265
  // ../commons/src/events/FieldValue.ts
248
266
  var import_zod4 = require("zod");
@@ -259,7 +277,7 @@ var FileFieldValue = import_zod3.z.object({
259
277
  type: import_zod3.z.string()
260
278
  });
261
279
  var AdminStructure = import_zod3.z.object({
262
- country: import_zod3.z.string(),
280
+ country: import_zod3.z.literal(process.env.country || "FAR"),
263
281
  province: import_zod3.z.string(),
264
282
  district: import_zod3.z.string()
265
283
  });
@@ -287,14 +305,31 @@ var RuralAddressUpdateValue = AdminStructure.extend({
287
305
  urbanOrRural: import_zod3.z.literal(GeographicalArea.RURAL),
288
306
  village: import_zod3.z.string().nullish()
289
307
  });
290
- var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
291
- UrbanAddressValue,
292
- RuralAddressValue
293
- ]);
308
+ var GenericAddressValue = import_zod3.z.object({
309
+ country: import_zod3.z.string().refine((value) => value !== process.env.country || "FAR"),
310
+ state: import_zod3.z.string(),
311
+ district2: import_zod3.z.string(),
312
+ cityOrTown: import_zod3.z.string().optional(),
313
+ addressLine1: import_zod3.z.string().optional(),
314
+ addressLine2: import_zod3.z.string().optional(),
315
+ addressLine3: import_zod3.z.string().optional(),
316
+ postcodeOrZip: import_zod3.z.string().optional()
317
+ });
318
+ var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [UrbanAddressValue, RuralAddressValue]).or(GenericAddressValue);
319
+ var GenericAddressUpdateValue = import_zod3.z.object({
320
+ country: import_zod3.z.string().refine((value) => value !== process.env.country || "FAR"),
321
+ state: import_zod3.z.string(),
322
+ district2: import_zod3.z.string(),
323
+ cityOrTown: import_zod3.z.string().nullish(),
324
+ addressLine1: import_zod3.z.string().nullish(),
325
+ addressLine2: import_zod3.z.string().nullish(),
326
+ addressLine3: import_zod3.z.string().nullish(),
327
+ postcodeOrZip: import_zod3.z.string().nullish()
328
+ });
294
329
  var AddressFieldUpdateValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
295
330
  UrbanAddressUpdateValue,
296
331
  RuralAddressUpdateValue
297
- ]);
332
+ ]).or(GenericAddressUpdateValue);
298
333
  var FileFieldValueWithOption = import_zod3.z.object({
299
334
  filename: import_zod3.z.string(),
300
335
  originalFilename: import_zod3.z.string(),
@@ -318,7 +353,8 @@ var FieldValue = import_zod4.z.union([
318
353
  FileFieldValue,
319
354
  FileFieldWithOptionValue,
320
355
  UrbanAddressValue,
321
- RuralAddressValue
356
+ RuralAddressValue,
357
+ GenericAddressValue
322
358
  ]);
323
359
  var FieldUpdateValue = import_zod4.z.union([
324
360
  TextValue,
@@ -328,7 +364,8 @@ var FieldUpdateValue = import_zod4.z.union([
328
364
  FileFieldValue,
329
365
  FileFieldWithOptionValue,
330
366
  UrbanAddressUpdateValue,
331
- RuralAddressUpdateValue
367
+ RuralAddressUpdateValue,
368
+ GenericAddressUpdateValue
332
369
  ]);
333
370
 
334
371
  // ../commons/src/events/FieldConfig.ts
@@ -495,11 +532,16 @@ var Country = BaseField.extend({
495
532
  type: import_zod5.z.literal(FieldType.COUNTRY),
496
533
  defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
497
534
  }).describe("Country select field");
535
+ var AdministrativeAreas = import_zod5.z.enum([
536
+ "ADMIN_STRUCTURE",
537
+ "HEALTH_FACILITY",
538
+ "CRVS_OFFICE"
539
+ ]);
498
540
  var AdministrativeAreaConfiguration = import_zod5.z.object({
499
541
  partOf: import_zod5.z.object({
500
542
  $data: import_zod5.z.string()
501
543
  }).optional().describe("Parent location"),
502
- type: import_zod5.z.enum(["ADMIN_STRUCTURE", "HEALTH_FACILITY", "CRVS_OFFICE"])
544
+ type: AdministrativeAreas
503
545
  }).describe("Administrative area options");
504
546
  var AdministrativeArea = BaseField.extend({
505
547
  type: import_zod5.z.literal(FieldType.ADMINISTRATIVE_AREA),
@@ -594,7 +636,7 @@ var ActionType = {
594
636
  CUSTOM: "CUSTOM",
595
637
  REJECT: "REJECT",
596
638
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
597
- ARCHIVED: "ARCHIVED"
639
+ ARCHIVE: "ARCHIVE"
598
640
  };
599
641
 
600
642
  // ../commons/src/events/ActionConfig.ts
@@ -622,23 +664,17 @@ var ValidateConfig = ActionConfigBase.merge(
622
664
  );
623
665
  var RejectDeclarationConfig = ActionConfigBase.merge(
624
666
  import_zod7.z.object({
625
- type: import_zod7.z.literal(ActionType.REJECT),
626
- comment: import_zod7.z.string(),
627
- isDuplicate: import_zod7.z.boolean()
667
+ type: import_zod7.z.literal(ActionType.REJECT)
628
668
  })
629
669
  );
630
670
  var MarkedAsDuplicateConfig = ActionConfigBase.merge(
631
671
  import_zod7.z.object({
632
- type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE),
633
- comment: import_zod7.z.string(),
634
- duplicates: import_zod7.z.array(import_zod7.z.string()).describe("UUIDs of duplicate records")
672
+ type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE)
635
673
  })
636
674
  );
637
- var ArchivedConfig = ActionConfigBase.merge(
675
+ var ArchiveConfig = ActionConfigBase.merge(
638
676
  import_zod7.z.object({
639
- type: import_zod7.z.literal(ActionType.ARCHIVED),
640
- comment: import_zod7.z.string(),
641
- isDuplicate: import_zod7.z.boolean()
677
+ type: import_zod7.z.literal(ActionType.ARCHIVE)
642
678
  })
643
679
  );
644
680
  var RegisterConfig = ActionConfigBase.merge(
@@ -683,7 +719,7 @@ var ActionConfig = import_zod7.z.discriminatedUnion("type", [
683
719
  ValidateConfig,
684
720
  RejectDeclarationConfig,
685
721
  MarkedAsDuplicateConfig,
686
- ArchivedConfig,
722
+ ArchiveConfig,
687
723
  RegisterConfig,
688
724
  DeleteConfig,
689
725
  PrintCertificateActionConfig,
@@ -1135,7 +1171,7 @@ function mapFieldTypeToMockValue(field2, i) {
1135
1171
  return "test@opencrvs.org";
1136
1172
  case FieldType.ADDRESS:
1137
1173
  return {
1138
- country: "FAR",
1174
+ country: process.env.COUNTRY || "FAR",
1139
1175
  province: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
1140
1176
  district: "5ef450bc-712d-48ad-93f3-8da0fa453baa",
1141
1177
  urbanOrRural: "URBAN",
@@ -1159,6 +1195,50 @@ function mapFieldTypeToMockValue(field2, i) {
1159
1195
  return null;
1160
1196
  }
1161
1197
  }
1198
+ function mapFieldTypeToEmptyValue(field2) {
1199
+ switch (field2.type) {
1200
+ case FieldType.DIVIDER:
1201
+ case FieldType.TEXT:
1202
+ case FieldType.TEXTAREA:
1203
+ case FieldType.BULLET_LIST:
1204
+ case FieldType.PAGE_HEADER:
1205
+ case FieldType.LOCATION:
1206
+ case FieldType.SELECT:
1207
+ case FieldType.COUNTRY:
1208
+ case FieldType.RADIO_GROUP:
1209
+ case FieldType.SIGNATURE:
1210
+ case FieldType.PARAGRAPH:
1211
+ case FieldType.ADMINISTRATIVE_AREA:
1212
+ case FieldType.FACILITY:
1213
+ case FieldType.OFFICE:
1214
+ case FieldType.NUMBER:
1215
+ case FieldType.EMAIL:
1216
+ case FieldType.DATE:
1217
+ case FieldType.CHECKBOX:
1218
+ return null;
1219
+ case FieldType.ADDRESS:
1220
+ return {
1221
+ country: null,
1222
+ province: null,
1223
+ district: null,
1224
+ urbanOrRural: "URBAN",
1225
+ // Default to urban needed for validation
1226
+ town: null,
1227
+ residentialArea: null,
1228
+ street: null,
1229
+ number: null,
1230
+ zipCode: null
1231
+ };
1232
+ case FieldType.FILE:
1233
+ return {
1234
+ filename: "",
1235
+ originalFilename: "",
1236
+ type: ""
1237
+ };
1238
+ case FieldType.FILE_WITH_OPTIONS:
1239
+ return [];
1240
+ }
1241
+ }
1162
1242
  var isParagraphFieldType = (field2) => {
1163
1243
  return field2.config.type === FieldType.PARAGRAPH;
1164
1244
  };
@@ -1258,49 +1338,76 @@ function isFieldVisible(field2, form) {
1258
1338
  function isFieldEnabled(field2, form) {
1259
1339
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1260
1340
  }
1341
+ var errorMessages = {
1342
+ hiddenField: {
1343
+ id: "v2.error.hidden",
1344
+ defaultMessage: "Hidden or disabled field should not receive a value",
1345
+ description: "Error message when field is hidden or disabled, but a value was received"
1346
+ },
1347
+ invalidDate: {
1348
+ defaultMessage: "Invalid date field",
1349
+ description: "Error message when date field is invalid",
1350
+ id: "v2.error.invalidDate"
1351
+ },
1352
+ invalidEmail: {
1353
+ defaultMessage: "Invalid email address",
1354
+ description: "Error message when email address is invalid",
1355
+ id: "v2.error.invalidEmail"
1356
+ },
1357
+ requiredField: {
1358
+ defaultMessage: "Required for registration",
1359
+ description: "Error message when required field is missing",
1360
+ id: "v2.error.required"
1361
+ },
1362
+ invalidInput: {
1363
+ defaultMessage: "Invalid input",
1364
+ description: "Error message when generic field is invalid",
1365
+ id: "v2.error.invalid"
1366
+ }
1367
+ };
1368
+ var createIntlError = (message) => ({
1369
+ message: {
1370
+ message
1371
+ }
1372
+ });
1261
1373
  var zodToIntlErrorMap = (issue, _ctx) => {
1262
- if (issue.code === "invalid_string" && issue.validation === "date") {
1263
- return {
1264
- message: {
1265
- message: {
1266
- defaultMessage: "Invalid date. Please use the format YYYY-MM-DD",
1267
- description: "This is the error message for invalid date fields",
1268
- id: "v2.error.invalidDate"
1269
- }
1374
+ switch (issue.code) {
1375
+ case "invalid_string": {
1376
+ if (_ctx.data === "") {
1377
+ return createIntlError(errorMessages.requiredField);
1270
1378
  }
1271
- };
1272
- }
1273
- if (issue.code === "invalid_string" && issue.validation === "email") {
1274
- return {
1275
- message: {
1276
- message: {
1277
- defaultMessage: "Invalid email address",
1278
- description: "This is the error message for invalid email fields",
1279
- id: "v2.error.invalidEmail"
1280
- }
1379
+ if (issue.validation === "date") {
1380
+ return createIntlError(errorMessages.invalidDate);
1281
1381
  }
1282
- };
1283
- }
1284
- if (issue.code === "invalid_type" && issue.expected !== issue.received && issue.received === "undefined" || issue.code === "too_small" && issue.message === void 0) {
1285
- return {
1286
- message: {
1287
- message: {
1288
- defaultMessage: "Required for registration",
1289
- description: "This is the error message for required fields",
1290
- id: "v2.error.required"
1291
- }
1382
+ if (issue.validation === "email") {
1383
+ return createIntlError(errorMessages.invalidEmail);
1292
1384
  }
1293
- };
1294
- }
1295
- return {
1296
- message: {
1297
- message: {
1298
- defaultMessage: "Invalid input",
1299
- description: "This is the error message for invalid field value",
1300
- id: "v2.error.invalid"
1385
+ break;
1386
+ }
1387
+ case "invalid_type": {
1388
+ if (issue.expected !== issue.received && issue.received === "undefined") {
1389
+ return createIntlError(errorMessages.requiredField);
1301
1390
  }
1391
+ break;
1302
1392
  }
1303
- };
1393
+ case "too_small": {
1394
+ if (issue.message === void 0) {
1395
+ return createIntlError(errorMessages.requiredField);
1396
+ }
1397
+ break;
1398
+ }
1399
+ case "invalid_union": {
1400
+ for (const { issues } of issue.unionErrors) {
1401
+ for (const e of issues) {
1402
+ if (zodToIntlErrorMap(e, _ctx).message.message.id !== "v2.error.required") {
1403
+ return createIntlError(errorMessages.invalidInput);
1404
+ }
1405
+ }
1406
+ }
1407
+ return createIntlError(errorMessages.requiredField);
1408
+ }
1409
+ }
1410
+ return createIntlError(errorMessages.invalidInput);
1304
1411
  };
1305
1412
  function getFieldValidationErrors({
1306
1413
  field: field2,
@@ -1315,11 +1422,7 @@ function getFieldValidationErrors({
1315
1422
  return {
1316
1423
  errors: [
1317
1424
  {
1318
- message: {
1319
- id: "v2.error.hidden",
1320
- defaultMessage: "Hidden or disabled field should not receive a value",
1321
- description: "Error message when field is hidden or disabled, but a value was received"
1322
- }
1425
+ message: errorMessages.hiddenField
1323
1426
  }
1324
1427
  ]
1325
1428
  };
@@ -1337,8 +1440,8 @@ function getFieldValidationErrors({
1337
1440
  conditionalParameters
1338
1441
  });
1339
1442
  return {
1340
- // Assumes that custom validation errors are more important than field validation errors
1341
- errors: [...customValidationResults, ...fieldValidationResult]
1443
+ // Assumes that custom validation errors are based on the field type, and extend the validation.
1444
+ errors: [...fieldValidationResult, ...customValidationResults]
1342
1445
  };
1343
1446
  }
1344
1447
  function runCustomFieldValidations({
@@ -1363,6 +1466,20 @@ function validateFieldInput({
1363
1466
  return rawError.error?.issues.map((issue) => issue.message) ?? [];
1364
1467
  }
1365
1468
 
1469
+ // ../commons/src/utils.ts
1470
+ function getOrThrow(x, message) {
1471
+ if (x === void 0 || x === null) {
1472
+ throw new Error(message);
1473
+ }
1474
+ return x;
1475
+ }
1476
+
1477
+ // ../commons/src/uuid.ts
1478
+ var import_uuid = require("uuid");
1479
+ function getUUID() {
1480
+ return (0, import_uuid.v4)();
1481
+ }
1482
+
1366
1483
  // ../commons/src/events/utils.ts
1367
1484
  function isMetadataField(field2) {
1368
1485
  return field2 in eventMetadataLabelMap;
@@ -1432,7 +1549,7 @@ function validateWorkqueueConfig(workqueueConfigs) {
1432
1549
  );
1433
1550
  if (!rootWorkqueue) {
1434
1551
  throw new Error(
1435
- `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1552
+ `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1436
1553
  );
1437
1554
  }
1438
1555
  });
@@ -1459,6 +1576,12 @@ var findActiveActionFields = (configuration, action) => {
1459
1576
  const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1460
1577
  return allFields;
1461
1578
  };
1579
+ var getActiveActionFormPages = (configuration, action) => {
1580
+ return getOrThrow(
1581
+ findActiveActionForm(configuration, action)?.pages,
1582
+ "Form configuration not found for type: " + configuration.id
1583
+ );
1584
+ };
1462
1585
  function getActiveActionFields(configuration, action) {
1463
1586
  const fields = findActiveActionFields(configuration, action);
1464
1587
  if (!fields) {
@@ -1491,6 +1614,27 @@ function stripHiddenFields(fields, data) {
1491
1614
  return !isFieldVisible(field2, data);
1492
1615
  });
1493
1616
  }
1617
+ function findActiveDrafts(event2, drafts) {
1618
+ const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1619
+ const lastAction = actions[actions.length - 1];
1620
+ return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
1621
+ }
1622
+ function createEmptyDraft(eventId, draftId, actionType) {
1623
+ return {
1624
+ id: draftId,
1625
+ eventId,
1626
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1627
+ transactionId: getUUID(),
1628
+ action: {
1629
+ type: actionType,
1630
+ data: {},
1631
+ metadata: {},
1632
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1633
+ createdBy: "@todo",
1634
+ createdAtLocation: "@todo"
1635
+ }
1636
+ };
1637
+ }
1494
1638
 
1495
1639
  // ../commons/src/events/EventConfig.ts
1496
1640
  var EventConfig = import_zod18.z.object({
@@ -1588,9 +1732,9 @@ var MarkAsDuplicateAction = ActionBase.merge(
1588
1732
  type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1589
1733
  })
1590
1734
  );
1591
- var ArchivedAction = ActionBase.merge(
1735
+ var ArchiveAction = ActionBase.merge(
1592
1736
  import_zod19.z.object({
1593
- type: import_zod19.z.literal(ActionType.ARCHIVED)
1737
+ type: import_zod19.z.literal(ActionType.ARCHIVE)
1594
1738
  })
1595
1739
  );
1596
1740
  var CreatedAction = ActionBase.merge(
@@ -1635,7 +1779,7 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1635
1779
  ValidateAction,
1636
1780
  RejectAction,
1637
1781
  MarkAsDuplicateAction,
1638
- ArchivedAction,
1782
+ ArchiveAction,
1639
1783
  NotifiedAction,
1640
1784
  RegisterAction,
1641
1785
  DeclareAction,
@@ -1713,9 +1857,9 @@ var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1713
1857
  type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1714
1858
  })
1715
1859
  );
1716
- var ArchivedActionInput = BaseActionInput.merge(
1860
+ var ArchiveActionInput = BaseActionInput.merge(
1717
1861
  import_zod20.z.object({
1718
- type: import_zod20.z.literal(ActionType.ARCHIVED).default(ActionType.ARCHIVED)
1862
+ type: import_zod20.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1719
1863
  })
1720
1864
  );
1721
1865
  var AssignActionInput = BaseActionInput.merge(
@@ -1754,7 +1898,7 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
1754
1898
  DeclareActionInput,
1755
1899
  RejectDeclarationActionInput,
1756
1900
  MarkedAsDuplicateActionInput,
1757
- ArchivedActionInput,
1901
+ ArchiveActionInput,
1758
1902
  AssignActionInput,
1759
1903
  UnassignActionInput,
1760
1904
  PrintCertificateActionInput,
@@ -1826,7 +1970,7 @@ function getStatusFromActions(actions) {
1826
1970
  if (action.type === ActionType.REJECT) {
1827
1971
  return EventStatus.REJECTED;
1828
1972
  }
1829
- if (action.type === ActionType.ARCHIVED) {
1973
+ if (action.type === ActionType.ARCHIVE) {
1830
1974
  return EventStatus.ARCHIVED;
1831
1975
  }
1832
1976
  if (action.type === ActionType.NOTIFY) {
@@ -1898,8 +2042,8 @@ function deepMerge(currentDocument, actionDocument) {
1898
2042
  }
1899
2043
  );
1900
2044
  }
1901
- function isUndeclaredDraft(event2) {
1902
- return event2.actions.every(({ type }) => type === ActionType.CREATE);
2045
+ function isUndeclaredDraft(status) {
2046
+ return status === EventStatus.CREATED;
1903
2047
  }
1904
2048
  function getCurrentEventState(event2) {
1905
2049
  const creationAction = event2.actions.find(
@@ -1924,9 +2068,8 @@ function getCurrentEventState(event2) {
1924
2068
  });
1925
2069
  }
1926
2070
  function getCurrentEventStateWithDrafts(event2, drafts) {
1927
- const actions = event2.actions.slice().sort();
1928
- const lastAction = actions[actions.length - 1];
1929
- const activeDrafts = drafts.filter(({ eventId }) => eventId === event2.id).filter(({ createdAt }) => createdAt > lastAction.createdAt).map((draft) => draft.action).flatMap((action) => {
2071
+ const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2072
+ const activeDrafts = findActiveDrafts(event2, drafts).map((draft) => draft.action).flatMap((action) => {
1930
2073
  if (action.type === ActionType.REQUEST_CORRECTION) {
1931
2074
  return [
1932
2075
  action,
@@ -1987,12 +2130,6 @@ var defineConfig = (config) => {
1987
2130
  });
1988
2131
  };
1989
2132
 
1990
- // ../commons/src/uuid.ts
1991
- var import_uuid = require("uuid");
1992
- function getUUID() {
1993
- return (0, import_uuid.v4)();
1994
- }
1995
-
1996
2133
  // ../commons/src/events/transactions.ts
1997
2134
  function generateTransactionId() {
1998
2135
  return getUUID();
@@ -3412,6 +3549,24 @@ var tennisClubMembershipEvent = defineConfig({
3412
3549
  })
3413
3550
  }
3414
3551
  ]
3552
+ },
3553
+ {
3554
+ type: ActionType.ARCHIVE,
3555
+ label: {
3556
+ id: "v2.event.tennis-club-membership.action.archive.label",
3557
+ defaultMessage: "Archive",
3558
+ description: "This is shown as the action name anywhere the user can trigger the action from"
3559
+ },
3560
+ forms: [TENNIS_CLUB_FORM]
3561
+ },
3562
+ {
3563
+ type: ActionType.REJECT,
3564
+ label: {
3565
+ id: "v2.event.tennis-club-membership.action.reject.label",
3566
+ defaultMessage: "Reject",
3567
+ description: "This is shown as the action name anywhere the user can trigger the action from"
3568
+ },
3569
+ forms: [TENNIS_CLUB_FORM]
3415
3570
  }
3416
3571
  ],
3417
3572
  advancedSearch: [
@@ -3492,9 +3647,9 @@ var eventPayloadGenerator = {
3492
3647
  eventId
3493
3648
  }),
3494
3649
  archive: (eventId, input = {}, isDuplicate) => ({
3495
- type: ActionType.ARCHIVED,
3650
+ type: ActionType.ARCHIVE,
3496
3651
  transactionId: input.transactionId ?? getUUID(),
3497
- data: input.data ?? {},
3652
+ data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.ARCHIVE),
3498
3653
  metadata: { isDuplicate: isDuplicate ?? false },
3499
3654
  duplicates: [],
3500
3655
  eventId
@@ -3502,7 +3657,7 @@ var eventPayloadGenerator = {
3502
3657
  reject: (eventId, input = {}) => ({
3503
3658
  type: ActionType.REJECT,
3504
3659
  transactionId: input.transactionId ?? getUUID(),
3505
- data: input.data ?? {},
3660
+ data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REJECT),
3506
3661
  duplicates: [],
3507
3662
  eventId
3508
3663
  }),
@@ -3561,7 +3716,9 @@ function generateActionDocument({
3561
3716
  defaults = {}
3562
3717
  }) {
3563
3718
  const actionBase = {
3564
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3719
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
3720
+ // @TODO: This should be fixed in the future.
3721
+ createdAt: new Date(Date.now() - 500).toISOString(),
3565
3722
  createdBy: getUUID(),
3566
3723
  id: getUUID(),
3567
3724
  createdAtLocation: "TODO",
@@ -3578,7 +3735,7 @@ function generateActionDocument({
3578
3735
  return { ...actionBase, assignedTo: getUUID(), type: action };
3579
3736
  case ActionType.VALIDATE:
3580
3737
  return { ...actionBase, type: action };
3581
- case ActionType.ARCHIVED:
3738
+ case ActionType.ARCHIVE:
3582
3739
  return { ...actionBase, type: action };
3583
3740
  case ActionType.REJECT:
3584
3741
  return { ...actionBase, type: action };
@@ -3616,9 +3773,13 @@ function generateEventDocument({
3616
3773
  actions: actions.map(
3617
3774
  (action) => generateActionDocument({ configuration, action })
3618
3775
  ),
3619
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3776
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
3777
+ // @TODO: This should be fixed in the future.
3778
+ createdAt: new Date(Date.now() - 1e3).toISOString(),
3620
3779
  id: getUUID(),
3621
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
3780
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
3781
+ // @TODO: This should be fixed in the future.
3782
+ updatedAt: new Date(Date.now() - 1e3).toISOString()
3622
3783
  };
3623
3784
  }
3624
3785
  function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, data = {}) {
@@ -3658,3 +3819,33 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3658
3819
  },
3659
3820
  trackingId: overrides.trackingId ?? "M3F8YQ"
3660
3821
  });
3822
+
3823
+ // ../commons/src/events/TemplateConfig.ts
3824
+ function isTemplateVariable(value) {
3825
+ return typeof value === "string" && value.startsWith("$");
3826
+ }
3827
+ function isFieldValue(value) {
3828
+ return FieldValue.safeParse(value).success;
3829
+ }
3830
+ function isFieldValueWithoutTemplates(value) {
3831
+ if (isTemplateVariable(value)) {
3832
+ return false;
3833
+ }
3834
+ if (typeof value === "object" && Object.values(value).some((val) => isTemplateVariable(val))) {
3835
+ return false;
3836
+ }
3837
+ return true;
3838
+ }
3839
+ function isFieldConfigDefaultValue(value) {
3840
+ if (!value) return false;
3841
+ if (isFieldValue(value)) {
3842
+ return true;
3843
+ }
3844
+ if (isTemplateVariable(value)) {
3845
+ return true;
3846
+ }
3847
+ if (typeof value === "object" && Object.values(value).every((v) => typeof v === "object" && v !== null)) {
3848
+ return Object.values(value).every((v) => isFieldConfigDefaultValue(v));
3849
+ }
3850
+ return false;
3851
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.8.0-rc.fbb7263",
3
+ "version": "1.8.0-rc.fd16d13",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {