@opencrvs/toolkit 1.8.0-rc.f8f3eb3 → 1.8.0-rc.fa72fdf

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,
@@ -100,12 +101,15 @@ __export(events_exports, {
100
101
  alwaysTrue: () => alwaysTrue,
101
102
  and: () => and,
102
103
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
104
+ compositeFieldTypes: () => compositeFieldTypes,
105
+ createEmptyDraft: () => createEmptyDraft,
103
106
  createValidationSchema: () => createValidationSchema,
104
107
  deepDropNulls: () => deepDropNulls,
105
108
  defineConditional: () => defineConditional,
106
109
  defineConfig: () => defineConfig,
107
110
  defineForm: () => defineForm,
108
111
  defineFormPage: () => defineFormPage,
112
+ errorMessages: () => errorMessages,
109
113
  event: () => event,
110
114
  eventMetadataLabelMap: () => eventMetadataLabelMap,
111
115
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -117,6 +121,7 @@ __export(events_exports, {
117
121
  findActiveActionForm: () => findActiveActionForm,
118
122
  findActiveActionFormFields: () => findActiveActionFormFields,
119
123
  findActiveActionFormPages: () => findActiveActionFormPages,
124
+ findActiveDrafts: () => findActiveDrafts,
120
125
  findInputPageFields: () => findInputPageFields,
121
126
  findPageFields: () => findPageFields,
122
127
  generateActionDocument: () => generateActionDocument,
@@ -125,6 +130,7 @@ __export(events_exports, {
125
130
  generateEventDraftDocument: () => generateEventDraftDocument,
126
131
  generateTransactionId: () => generateTransactionId,
127
132
  getActiveActionFields: () => getActiveActionFields,
133
+ getActiveActionFormPages: () => getActiveActionFormPages,
128
134
  getAllFields: () => getAllFields,
129
135
  getAllPages: () => getAllPages,
130
136
  getCurrentEventState: () => getCurrentEventState,
@@ -142,7 +148,10 @@ __export(events_exports, {
142
148
  isDividerFieldType: () => isDividerFieldType,
143
149
  isEmailFieldType: () => isEmailFieldType,
144
150
  isFacilityFieldType: () => isFacilityFieldType,
151
+ isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
145
152
  isFieldEnabled: () => isFieldEnabled,
153
+ isFieldValue: () => isFieldValue,
154
+ isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
146
155
  isFieldVisible: () => isFieldVisible,
147
156
  isFileFieldType: () => isFileFieldType,
148
157
  isFileFieldWithOptionType: () => isFileFieldWithOptionType,
@@ -154,9 +163,11 @@ __export(events_exports, {
154
163
  isRadioGroupFieldType: () => isRadioGroupFieldType,
155
164
  isSelectFieldType: () => isSelectFieldType,
156
165
  isSignatureFieldType: () => isSignatureFieldType,
166
+ isTemplateVariable: () => isTemplateVariable,
157
167
  isTextAreaFieldType: () => isTextAreaFieldType,
158
168
  isTextFieldType: () => isTextFieldType,
159
169
  isUndeclaredDraft: () => isUndeclaredDraft,
170
+ mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
160
171
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
161
172
  mapFieldTypeToZod: () => mapFieldTypeToZod,
162
173
  not: () => not,
@@ -243,6 +254,11 @@ var FieldType = {
243
254
  SIGNATURE: "SIGNATURE"
244
255
  };
245
256
  var fieldTypes = Object.values(FieldType);
257
+ var compositeFieldTypes = [
258
+ FieldType.ADDRESS,
259
+ FieldType.FILE_WITH_OPTIONS,
260
+ FieldType.FILE
261
+ ];
246
262
 
247
263
  // ../commons/src/events/FieldValue.ts
248
264
  var import_zod4 = require("zod");
@@ -495,11 +511,16 @@ var Country = BaseField.extend({
495
511
  type: import_zod5.z.literal(FieldType.COUNTRY),
496
512
  defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
497
513
  }).describe("Country select field");
514
+ var AdministrativeAreas = import_zod5.z.enum([
515
+ "ADMIN_STRUCTURE",
516
+ "HEALTH_FACILITY",
517
+ "CRVS_OFFICE"
518
+ ]);
498
519
  var AdministrativeAreaConfiguration = import_zod5.z.object({
499
520
  partOf: import_zod5.z.object({
500
521
  $data: import_zod5.z.string()
501
522
  }).optional().describe("Parent location"),
502
- type: import_zod5.z.enum(["ADMIN_STRUCTURE", "HEALTH_FACILITY", "CRVS_OFFICE"])
523
+ type: AdministrativeAreas
503
524
  }).describe("Administrative area options");
504
525
  var AdministrativeArea = BaseField.extend({
505
526
  type: import_zod5.z.literal(FieldType.ADMINISTRATIVE_AREA),
@@ -594,7 +615,7 @@ var ActionType = {
594
615
  CUSTOM: "CUSTOM",
595
616
  REJECT: "REJECT",
596
617
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
597
- ARCHIVED: "ARCHIVED"
618
+ ARCHIVE: "ARCHIVE"
598
619
  };
599
620
 
600
621
  // ../commons/src/events/ActionConfig.ts
@@ -622,23 +643,17 @@ var ValidateConfig = ActionConfigBase.merge(
622
643
  );
623
644
  var RejectDeclarationConfig = ActionConfigBase.merge(
624
645
  import_zod7.z.object({
625
- type: import_zod7.z.literal(ActionType.REJECT),
626
- comment: import_zod7.z.string(),
627
- isDuplicate: import_zod7.z.boolean()
646
+ type: import_zod7.z.literal(ActionType.REJECT)
628
647
  })
629
648
  );
630
649
  var MarkedAsDuplicateConfig = ActionConfigBase.merge(
631
650
  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")
651
+ type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE)
635
652
  })
636
653
  );
637
- var ArchivedConfig = ActionConfigBase.merge(
654
+ var ArchiveConfig = ActionConfigBase.merge(
638
655
  import_zod7.z.object({
639
- type: import_zod7.z.literal(ActionType.ARCHIVED),
640
- comment: import_zod7.z.string(),
641
- isDuplicate: import_zod7.z.boolean()
656
+ type: import_zod7.z.literal(ActionType.ARCHIVE)
642
657
  })
643
658
  );
644
659
  var RegisterConfig = ActionConfigBase.merge(
@@ -683,7 +698,7 @@ var ActionConfig = import_zod7.z.discriminatedUnion("type", [
683
698
  ValidateConfig,
684
699
  RejectDeclarationConfig,
685
700
  MarkedAsDuplicateConfig,
686
- ArchivedConfig,
701
+ ArchiveConfig,
687
702
  RegisterConfig,
688
703
  DeleteConfig,
689
704
  PrintCertificateActionConfig,
@@ -1159,6 +1174,50 @@ function mapFieldTypeToMockValue(field2, i) {
1159
1174
  return null;
1160
1175
  }
1161
1176
  }
1177
+ function mapFieldTypeToEmptyValue(field2) {
1178
+ switch (field2.type) {
1179
+ case FieldType.DIVIDER:
1180
+ case FieldType.TEXT:
1181
+ case FieldType.TEXTAREA:
1182
+ case FieldType.BULLET_LIST:
1183
+ case FieldType.PAGE_HEADER:
1184
+ case FieldType.LOCATION:
1185
+ case FieldType.SELECT:
1186
+ case FieldType.COUNTRY:
1187
+ case FieldType.RADIO_GROUP:
1188
+ case FieldType.SIGNATURE:
1189
+ case FieldType.PARAGRAPH:
1190
+ case FieldType.ADMINISTRATIVE_AREA:
1191
+ case FieldType.FACILITY:
1192
+ case FieldType.OFFICE:
1193
+ case FieldType.NUMBER:
1194
+ case FieldType.EMAIL:
1195
+ case FieldType.DATE:
1196
+ case FieldType.CHECKBOX:
1197
+ return null;
1198
+ case FieldType.ADDRESS:
1199
+ return {
1200
+ country: null,
1201
+ province: null,
1202
+ district: null,
1203
+ urbanOrRural: "URBAN",
1204
+ // Default to urban needed for validation
1205
+ town: null,
1206
+ residentialArea: null,
1207
+ street: null,
1208
+ number: null,
1209
+ zipCode: null
1210
+ };
1211
+ case FieldType.FILE:
1212
+ return {
1213
+ filename: "",
1214
+ originalFilename: "",
1215
+ type: ""
1216
+ };
1217
+ case FieldType.FILE_WITH_OPTIONS:
1218
+ return [];
1219
+ }
1220
+ }
1162
1221
  var isParagraphFieldType = (field2) => {
1163
1222
  return field2.config.type === FieldType.PARAGRAPH;
1164
1223
  };
@@ -1258,49 +1317,66 @@ function isFieldVisible(field2, form) {
1258
1317
  function isFieldEnabled(field2, form) {
1259
1318
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1260
1319
  }
1320
+ var errorMessages = {
1321
+ hiddenField: {
1322
+ id: "v2.error.hidden",
1323
+ defaultMessage: "Hidden or disabled field should not receive a value",
1324
+ description: "Error message when field is hidden or disabled, but a value was received"
1325
+ },
1326
+ invalidDate: {
1327
+ defaultMessage: "Invalid date field",
1328
+ description: "Error message when date field is invalid",
1329
+ id: "v2.error.invalidDate"
1330
+ },
1331
+ invalidEmail: {
1332
+ defaultMessage: "Invalid email address",
1333
+ description: "Error message when email address is invalid",
1334
+ id: "v2.error.invalidEmail"
1335
+ },
1336
+ requiredField: {
1337
+ defaultMessage: "Required for registration",
1338
+ description: "Error message when required field is missing",
1339
+ id: "v2.error.required"
1340
+ },
1341
+ invalidInput: {
1342
+ defaultMessage: "Invalid input",
1343
+ description: "Error message when generic field is invalid",
1344
+ id: "v2.error.invalid"
1345
+ }
1346
+ };
1347
+ var createIntlError = (message) => ({
1348
+ message: {
1349
+ message
1350
+ }
1351
+ });
1261
1352
  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
- }
1353
+ switch (issue.code) {
1354
+ case "invalid_string": {
1355
+ if (_ctx.data === "") {
1356
+ return createIntlError(errorMessages.requiredField);
1270
1357
  }
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
- }
1358
+ if (issue.validation === "date") {
1359
+ return createIntlError(errorMessages.invalidDate);
1281
1360
  }
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
- }
1361
+ if (issue.validation === "email") {
1362
+ return createIntlError(errorMessages.invalidEmail);
1292
1363
  }
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"
1364
+ break;
1365
+ }
1366
+ case "invalid_type": {
1367
+ if (issue.expected !== issue.received && issue.received === "undefined") {
1368
+ return createIntlError(errorMessages.requiredField);
1301
1369
  }
1370
+ break;
1302
1371
  }
1303
- };
1372
+ case "too_small": {
1373
+ if (issue.message === void 0) {
1374
+ return createIntlError(errorMessages.requiredField);
1375
+ }
1376
+ break;
1377
+ }
1378
+ }
1379
+ return createIntlError(errorMessages.invalidInput);
1304
1380
  };
1305
1381
  function getFieldValidationErrors({
1306
1382
  field: field2,
@@ -1315,11 +1391,7 @@ function getFieldValidationErrors({
1315
1391
  return {
1316
1392
  errors: [
1317
1393
  {
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
- }
1394
+ message: errorMessages.hiddenField
1323
1395
  }
1324
1396
  ]
1325
1397
  };
@@ -1337,8 +1409,8 @@ function getFieldValidationErrors({
1337
1409
  conditionalParameters
1338
1410
  });
1339
1411
  return {
1340
- // Assumes that custom validation errors are more important than field validation errors
1341
- errors: [...customValidationResults, ...fieldValidationResult]
1412
+ // Assumes that custom validation errors are based on the field type, and extend the validation.
1413
+ errors: [...fieldValidationResult, ...customValidationResults]
1342
1414
  };
1343
1415
  }
1344
1416
  function runCustomFieldValidations({
@@ -1363,6 +1435,20 @@ function validateFieldInput({
1363
1435
  return rawError.error?.issues.map((issue) => issue.message) ?? [];
1364
1436
  }
1365
1437
 
1438
+ // ../commons/src/utils.ts
1439
+ function getOrThrow(x, message) {
1440
+ if (x === void 0 || x === null) {
1441
+ throw new Error(message);
1442
+ }
1443
+ return x;
1444
+ }
1445
+
1446
+ // ../commons/src/uuid.ts
1447
+ var import_uuid = require("uuid");
1448
+ function getUUID() {
1449
+ return (0, import_uuid.v4)();
1450
+ }
1451
+
1366
1452
  // ../commons/src/events/utils.ts
1367
1453
  function isMetadataField(field2) {
1368
1454
  return field2 in eventMetadataLabelMap;
@@ -1432,7 +1518,7 @@ function validateWorkqueueConfig(workqueueConfigs) {
1432
1518
  );
1433
1519
  if (!rootWorkqueue) {
1434
1520
  throw new Error(
1435
- `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1521
+ `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1436
1522
  );
1437
1523
  }
1438
1524
  });
@@ -1459,6 +1545,12 @@ var findActiveActionFields = (configuration, action) => {
1459
1545
  const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1460
1546
  return allFields;
1461
1547
  };
1548
+ var getActiveActionFormPages = (configuration, action) => {
1549
+ return getOrThrow(
1550
+ findActiveActionForm(configuration, action)?.pages,
1551
+ "Form configuration not found for type: " + configuration.id
1552
+ );
1553
+ };
1462
1554
  function getActiveActionFields(configuration, action) {
1463
1555
  const fields = findActiveActionFields(configuration, action);
1464
1556
  if (!fields) {
@@ -1491,6 +1583,27 @@ function stripHiddenFields(fields, data) {
1491
1583
  return !isFieldVisible(field2, data);
1492
1584
  });
1493
1585
  }
1586
+ function findActiveDrafts(event2, drafts) {
1587
+ const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1588
+ const lastAction = actions[actions.length - 1];
1589
+ return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
1590
+ }
1591
+ function createEmptyDraft(eventId, draftId, actionType) {
1592
+ return {
1593
+ id: draftId,
1594
+ eventId,
1595
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1596
+ transactionId: getUUID(),
1597
+ action: {
1598
+ type: actionType,
1599
+ data: {},
1600
+ metadata: {},
1601
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1602
+ createdBy: "@todo",
1603
+ createdAtLocation: "@todo"
1604
+ }
1605
+ };
1606
+ }
1494
1607
 
1495
1608
  // ../commons/src/events/EventConfig.ts
1496
1609
  var EventConfig = import_zod18.z.object({
@@ -1588,9 +1701,9 @@ var MarkAsDuplicateAction = ActionBase.merge(
1588
1701
  type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1589
1702
  })
1590
1703
  );
1591
- var ArchivedAction = ActionBase.merge(
1704
+ var ArchiveAction = ActionBase.merge(
1592
1705
  import_zod19.z.object({
1593
- type: import_zod19.z.literal(ActionType.ARCHIVED)
1706
+ type: import_zod19.z.literal(ActionType.ARCHIVE)
1594
1707
  })
1595
1708
  );
1596
1709
  var CreatedAction = ActionBase.merge(
@@ -1635,7 +1748,7 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1635
1748
  ValidateAction,
1636
1749
  RejectAction,
1637
1750
  MarkAsDuplicateAction,
1638
- ArchivedAction,
1751
+ ArchiveAction,
1639
1752
  NotifiedAction,
1640
1753
  RegisterAction,
1641
1754
  DeclareAction,
@@ -1664,7 +1777,6 @@ var import_zod20 = require("zod");
1664
1777
  var BaseActionInput = import_zod20.z.object({
1665
1778
  eventId: import_zod20.z.string(),
1666
1779
  transactionId: import_zod20.z.string(),
1667
- incomplete: import_zod20.z.boolean().optional().default(false).describe("Allows action with partial data to be saved"),
1668
1780
  data: ActionUpdate,
1669
1781
  metadata: ActionUpdate.optional()
1670
1782
  });
@@ -1691,8 +1803,7 @@ var ValidateActionInput = BaseActionInput.merge(
1691
1803
  );
1692
1804
  var NotifyActionInput = BaseActionInput.merge(
1693
1805
  import_zod20.z.object({
1694
- type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY),
1695
- createdAtLocation: import_zod20.z.string()
1806
+ type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1696
1807
  })
1697
1808
  );
1698
1809
  var DeclareActionInput = BaseActionInput.merge(
@@ -1715,9 +1826,9 @@ var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1715
1826
  type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1716
1827
  })
1717
1828
  );
1718
- var ArchivedActionInput = BaseActionInput.merge(
1829
+ var ArchiveActionInput = BaseActionInput.merge(
1719
1830
  import_zod20.z.object({
1720
- type: import_zod20.z.literal(ActionType.ARCHIVED).default(ActionType.ARCHIVED)
1831
+ type: import_zod20.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1721
1832
  })
1722
1833
  );
1723
1834
  var AssignActionInput = BaseActionInput.merge(
@@ -1756,7 +1867,7 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
1756
1867
  DeclareActionInput,
1757
1868
  RejectDeclarationActionInput,
1758
1869
  MarkedAsDuplicateActionInput,
1759
- ArchivedActionInput,
1870
+ ArchiveActionInput,
1760
1871
  AssignActionInput,
1761
1872
  UnassignActionInput,
1762
1873
  PrintCertificateActionInput,
@@ -1828,9 +1939,12 @@ function getStatusFromActions(actions) {
1828
1939
  if (action.type === ActionType.REJECT) {
1829
1940
  return EventStatus.REJECTED;
1830
1941
  }
1831
- if (action.type === ActionType.ARCHIVED) {
1942
+ if (action.type === ActionType.ARCHIVE) {
1832
1943
  return EventStatus.ARCHIVED;
1833
1944
  }
1945
+ if (action.type === ActionType.NOTIFY) {
1946
+ return EventStatus.NOTIFIED;
1947
+ }
1834
1948
  return status;
1835
1949
  }, EventStatus.CREATED);
1836
1950
  }
@@ -1897,8 +2011,8 @@ function deepMerge(currentDocument, actionDocument) {
1897
2011
  }
1898
2012
  );
1899
2013
  }
1900
- function isUndeclaredDraft(event2) {
1901
- return event2.actions.every(({ type }) => type === ActionType.CREATE);
2014
+ function isUndeclaredDraft(status) {
2015
+ return status === EventStatus.CREATED;
1902
2016
  }
1903
2017
  function getCurrentEventState(event2) {
1904
2018
  const creationAction = event2.actions.find(
@@ -1923,9 +2037,8 @@ function getCurrentEventState(event2) {
1923
2037
  });
1924
2038
  }
1925
2039
  function getCurrentEventStateWithDrafts(event2, drafts) {
1926
- const actions = event2.actions.slice().sort();
1927
- const lastAction = actions[actions.length - 1];
1928
- const activeDrafts = drafts.filter(({ eventId }) => eventId === event2.id).filter(({ createdAt }) => createdAt > lastAction.createdAt).map((draft) => draft.action).flatMap((action) => {
2040
+ const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2041
+ const activeDrafts = findActiveDrafts(event2, drafts).map((draft) => draft.action).flatMap((action) => {
1929
2042
  if (action.type === ActionType.REQUEST_CORRECTION) {
1930
2043
  return [
1931
2044
  action,
@@ -1986,12 +2099,6 @@ var defineConfig = (config) => {
1986
2099
  });
1987
2100
  };
1988
2101
 
1989
- // ../commons/src/uuid.ts
1990
- var import_uuid = require("uuid");
1991
- function getUUID() {
1992
- return (0, import_uuid.v4)();
1993
- }
1994
-
1995
2102
  // ../commons/src/events/transactions.ts
1996
2103
  function generateTransactionId() {
1997
2104
  return getUUID();
@@ -3411,6 +3518,24 @@ var tennisClubMembershipEvent = defineConfig({
3411
3518
  })
3412
3519
  }
3413
3520
  ]
3521
+ },
3522
+ {
3523
+ type: ActionType.ARCHIVE,
3524
+ label: {
3525
+ id: "v2.event.tennis-club-membership.action.archive.label",
3526
+ defaultMessage: "Archive",
3527
+ description: "This is shown as the action name anywhere the user can trigger the action from"
3528
+ },
3529
+ forms: [TENNIS_CLUB_FORM]
3530
+ },
3531
+ {
3532
+ type: ActionType.REJECT,
3533
+ label: {
3534
+ id: "v2.event.tennis-club-membership.action.reject.label",
3535
+ defaultMessage: "Reject",
3536
+ description: "This is shown as the action name anywhere the user can trigger the action from"
3537
+ },
3538
+ forms: [TENNIS_CLUB_FORM]
3414
3539
  }
3415
3540
  ],
3416
3541
  advancedSearch: [
@@ -3491,9 +3616,9 @@ var eventPayloadGenerator = {
3491
3616
  eventId
3492
3617
  }),
3493
3618
  archive: (eventId, input = {}, isDuplicate) => ({
3494
- type: ActionType.ARCHIVED,
3619
+ type: ActionType.ARCHIVE,
3495
3620
  transactionId: input.transactionId ?? getUUID(),
3496
- data: input.data ?? {},
3621
+ data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.ARCHIVE),
3497
3622
  metadata: { isDuplicate: isDuplicate ?? false },
3498
3623
  duplicates: [],
3499
3624
  eventId
@@ -3501,7 +3626,7 @@ var eventPayloadGenerator = {
3501
3626
  reject: (eventId, input = {}) => ({
3502
3627
  type: ActionType.REJECT,
3503
3628
  transactionId: input.transactionId ?? getUUID(),
3504
- data: input.data ?? {},
3629
+ data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REJECT),
3505
3630
  duplicates: [],
3506
3631
  eventId
3507
3632
  }),
@@ -3560,7 +3685,9 @@ function generateActionDocument({
3560
3685
  defaults = {}
3561
3686
  }) {
3562
3687
  const actionBase = {
3563
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3688
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
3689
+ // @TODO: This should be fixed in the future.
3690
+ createdAt: new Date(Date.now() - 500).toISOString(),
3564
3691
  createdBy: getUUID(),
3565
3692
  id: getUUID(),
3566
3693
  createdAtLocation: "TODO",
@@ -3577,7 +3704,7 @@ function generateActionDocument({
3577
3704
  return { ...actionBase, assignedTo: getUUID(), type: action };
3578
3705
  case ActionType.VALIDATE:
3579
3706
  return { ...actionBase, type: action };
3580
- case ActionType.ARCHIVED:
3707
+ case ActionType.ARCHIVE:
3581
3708
  return { ...actionBase, type: action };
3582
3709
  case ActionType.REJECT:
3583
3710
  return { ...actionBase, type: action };
@@ -3615,9 +3742,13 @@ function generateEventDocument({
3615
3742
  actions: actions.map(
3616
3743
  (action) => generateActionDocument({ configuration, action })
3617
3744
  ),
3618
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3745
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
3746
+ // @TODO: This should be fixed in the future.
3747
+ createdAt: new Date(Date.now() - 1e3).toISOString(),
3619
3748
  id: getUUID(),
3620
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
3749
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
3750
+ // @TODO: This should be fixed in the future.
3751
+ updatedAt: new Date(Date.now() - 1e3).toISOString()
3621
3752
  };
3622
3753
  }
3623
3754
  function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, data = {}) {
@@ -3657,3 +3788,33 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3657
3788
  },
3658
3789
  trackingId: overrides.trackingId ?? "M3F8YQ"
3659
3790
  });
3791
+
3792
+ // ../commons/src/events/TemplateConfig.ts
3793
+ function isTemplateVariable(value) {
3794
+ return typeof value === "string" && value.startsWith("$");
3795
+ }
3796
+ function isFieldValue(value) {
3797
+ return FieldValue.safeParse(value).success;
3798
+ }
3799
+ function isFieldValueWithoutTemplates(value) {
3800
+ if (isTemplateVariable(value)) {
3801
+ return false;
3802
+ }
3803
+ if (typeof value === "object" && Object.values(value).some((val) => isTemplateVariable(val))) {
3804
+ return false;
3805
+ }
3806
+ return true;
3807
+ }
3808
+ function isFieldConfigDefaultValue(value) {
3809
+ if (!value) return false;
3810
+ if (isFieldValue(value)) {
3811
+ return true;
3812
+ }
3813
+ if (isTemplateVariable(value)) {
3814
+ return true;
3815
+ }
3816
+ if (typeof value === "object" && Object.values(value).every((v) => typeof v === "object" && v !== null)) {
3817
+ return Object.values(value).every((v) => isFieldConfigDefaultValue(v));
3818
+ }
3819
+ return false;
3820
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.8.0-rc.f8f3eb3",
3
+ "version": "1.8.0-rc.fa72fdf",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {