@opencrvs/toolkit 1.8.0-rc.fe799b0 → 1.8.0-rc.ff2e7b6

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.
@@ -1282,9 +1282,9 @@ export declare const EventDocument: z.ZodObject<{
1282
1282
  }>]>>>;
1283
1283
  createdAtLocation: z.ZodString;
1284
1284
  }, {
1285
- type: z.ZodLiteral<"ARCHIVED">;
1285
+ type: z.ZodLiteral<"ARCHIVE">;
1286
1286
  }>, "strip", z.ZodTypeAny, {
1287
- type: "ARCHIVED";
1287
+ type: "ARCHIVE";
1288
1288
  id: string;
1289
1289
  data: Record<string, string | number | boolean | {
1290
1290
  type: string;
@@ -1342,7 +1342,7 @@ export declare const EventDocument: z.ZodObject<{
1342
1342
  originalFilename: string;
1343
1343
  }[]> | undefined;
1344
1344
  }, {
1345
- type: "ARCHIVED";
1345
+ type: "ARCHIVE";
1346
1346
  id: string;
1347
1347
  data: Record<string, string | number | boolean | {
1348
1348
  type: string;
@@ -4636,7 +4636,7 @@ export declare const EventDocument: z.ZodObject<{
4636
4636
  originalFilename: string;
4637
4637
  }[]> | undefined;
4638
4638
  } | {
4639
- type: "ARCHIVED";
4639
+ type: "ARCHIVE";
4640
4640
  id: string;
4641
4641
  data: Record<string, string | number | boolean | {
4642
4642
  type: string;
@@ -5520,7 +5520,7 @@ export declare const EventDocument: z.ZodObject<{
5520
5520
  originalFilename: string;
5521
5521
  }[]> | undefined;
5522
5522
  } | {
5523
- type: "ARCHIVED";
5523
+ type: "ARCHIVE";
5524
5524
  id: string;
5525
5525
  data: Record<string, string | number | boolean | {
5526
5526
  type: string;
@@ -2319,6 +2319,7 @@ declare const Country: z.ZodObject<z.objectUtil.extendShape<{
2319
2319
  hideLabel?: boolean | undefined;
2320
2320
  }>;
2321
2321
  export type Country = z.infer<typeof Country>;
2322
+ export declare const AdministrativeAreas: z.ZodEnum<["ADMIN_STRUCTURE", "HEALTH_FACILITY", "CRVS_OFFICE"]>;
2322
2323
  declare const AdministrativeAreaConfiguration: z.ZodObject<{
2323
2324
  partOf: z.ZodOptional<z.ZodObject<{
2324
2325
  $data: z.ZodString;
@@ -24,4 +24,8 @@ export declare const FieldType: {
24
24
  };
25
25
  export declare const fieldTypes: ("ADDRESS" | "TEXT" | "NUMBER" | "TEXTAREA" | "EMAIL" | "DATE" | "PARAGRAPH" | "PAGE_HEADER" | "RADIO_GROUP" | "FILE" | "FILE_WITH_OPTIONS" | "HIDDEN" | "BULLET_LIST" | "CHECKBOX" | "SELECT" | "COUNTRY" | "LOCATION" | "DIVIDER" | "ADMINISTRATIVE_AREA" | "FACILITY" | "OFFICE" | "SIGNATURE")[];
26
26
  export type FieldType = (typeof fieldTypes)[number];
27
+ /**
28
+ * Composite field types are field types that consist of multiple field values.
29
+ */
30
+ export declare const compositeFieldTypes: ("ADDRESS" | "FILE" | "FILE_WITH_OPTIONS")[];
27
31
  //# sourceMappingURL=FieldType.d.ts.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * TemplateConfig defines configuration rules for system-based variables (e.g. $user.province).
3
+ * They are currently used for providing default values in FieldConfig.
4
+ */
5
+ import { FieldValue } from './FieldValue';
6
+ /**
7
+ * Available system variables for configuration.
8
+ */
9
+ export interface MetaFields {
10
+ $user: {
11
+ province: string;
12
+ district: string;
13
+ };
14
+ }
15
+ /**
16
+ * Recursively flatten the keys of an object. Used to limit types when configuring default values in country config.
17
+ * @example
18
+ * type Test = FlattenedKeyStrings<{ a: { b: string, c: { d: string } } }>
19
+ * // 'a.b' | 'a.c.d' but not 'a' or 'a.c'
20
+ */
21
+ type FlattenedKeyStrings<T, Prefix extends string = ''> = {
22
+ [K in keyof T]: T[K] extends Record<string, any> ? FlattenedKeyStrings<T[K], `${Prefix}${K & string}.`> : `${Prefix}${K & string}`;
23
+ }[keyof T];
24
+ export type FlattenedMetaFields = FlattenedKeyStrings<MetaFields>;
25
+ /**
26
+ * Default value for a field when configuring a form.
27
+ */
28
+ export type FieldConfigDefaultValue = FieldValue | FlattenedMetaFields | Record<string, FlattenedMetaFields | FieldValue>;
29
+ export declare function isTemplateVariable(value: FieldConfigDefaultValue): value is FlattenedMetaFields;
30
+ export declare function isFieldValue(value: FieldConfigDefaultValue): value is FieldValue;
31
+ /**
32
+ * Checks if given value is valid for a field, and known template variables are already resolved.
33
+ * @todo: Extend functionality to arbitrary depth objects. Currently only checks first level since our compoosite fields are only 1 level deep.
34
+ */
35
+ export declare function isFieldValueWithoutTemplates(value: FieldConfigDefaultValue): value is FieldValue;
36
+ export declare function isFieldConfigDefaultValue(value: any): value is FieldConfigDefaultValue;
37
+ export {};
38
+ //# sourceMappingURL=TemplateConfig.d.ts.map
@@ -122,7 +122,7 @@ export declare const defineConfig: (config: EventConfigInput) => {
122
122
  duplicates: string[];
123
123
  draft?: boolean | undefined;
124
124
  } | {
125
- type: "ARCHIVED";
125
+ type: "ARCHIVE";
126
126
  comment: string;
127
127
  conditionals: ({
128
128
  type: "SHOW";
@@ -28,6 +28,7 @@ export * from './FieldTypeMapping';
28
28
  export * from './Conditional';
29
29
  export * from './AdvancedSearchConfig';
30
30
  export * from './test.utils';
31
+ export * from './TemplateConfig';
31
32
  export * from '../conditionals/conditionals';
32
33
  export * from '../conditionals/validate';
33
34
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { ActionDocument } from './ActionDocument';
2
- import { ArchivedActionInput, DeclareActionInput, RegisterActionInput, RejectDeclarationActionInput, RequestCorrectionActionInput, ValidateActionInput } from './ActionInput';
2
+ import { ArchiveActionInput, DeclareActionInput, RegisterActionInput, RejectDeclarationActionInput, RequestCorrectionActionInput, ValidateActionInput } from './ActionInput';
3
3
  import { ActionType } from './ActionType';
4
4
  import { Draft } from './Draft';
5
5
  import { EventConfig } from './EventConfig';
@@ -192,8 +192,8 @@ export declare const eventPayloadGenerator: {
192
192
  duplicates: never[];
193
193
  eventId: string;
194
194
  };
195
- archive: (eventId: string, input?: Partial<Pick<ArchivedActionInput, "transactionId" | "data">>, isDuplicate?: boolean) => {
196
- type: "ARCHIVED";
195
+ archive: (eventId: string, input?: Partial<Pick<ArchiveActionInput, "transactionId" | "data">>, isDuplicate?: boolean) => {
196
+ type: "ARCHIVE";
197
197
  transactionId: string;
198
198
  data: Record<string, string | number | boolean | {
199
199
  type: string;
@@ -75,6 +75,11 @@ export declare const findActiveActionFormFields: (configuration: EventConfig, ac
75
75
  * Returns all fields for the action type, including review fields, if any.
76
76
  */
77
77
  export declare const findActiveActionFields: (configuration: EventConfig, action: ActionType) => FieldConfig[] | undefined;
78
+ export declare const getActiveActionFormPages: (configuration: EventConfig, action: ActionType) => {
79
+ id: string;
80
+ title: TranslationConfig;
81
+ fields: import("./FieldConfig").Inferred[];
82
+ }[];
78
83
  /**
79
84
  * Returns all fields for the action type, including review fields, or throws
80
85
  */
@@ -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,6 +101,7 @@ __export(events_exports, {
100
101
  alwaysTrue: () => alwaysTrue,
101
102
  and: () => and,
102
103
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
104
+ compositeFieldTypes: () => compositeFieldTypes,
103
105
  createValidationSchema: () => createValidationSchema,
104
106
  deepDropNulls: () => deepDropNulls,
105
107
  defineConditional: () => defineConditional,
@@ -125,6 +127,7 @@ __export(events_exports, {
125
127
  generateEventDraftDocument: () => generateEventDraftDocument,
126
128
  generateTransactionId: () => generateTransactionId,
127
129
  getActiveActionFields: () => getActiveActionFields,
130
+ getActiveActionFormPages: () => getActiveActionFormPages,
128
131
  getAllFields: () => getAllFields,
129
132
  getAllPages: () => getAllPages,
130
133
  getCurrentEventState: () => getCurrentEventState,
@@ -142,7 +145,10 @@ __export(events_exports, {
142
145
  isDividerFieldType: () => isDividerFieldType,
143
146
  isEmailFieldType: () => isEmailFieldType,
144
147
  isFacilityFieldType: () => isFacilityFieldType,
148
+ isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
145
149
  isFieldEnabled: () => isFieldEnabled,
150
+ isFieldValue: () => isFieldValue,
151
+ isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
146
152
  isFieldVisible: () => isFieldVisible,
147
153
  isFileFieldType: () => isFileFieldType,
148
154
  isFileFieldWithOptionType: () => isFileFieldWithOptionType,
@@ -154,6 +160,7 @@ __export(events_exports, {
154
160
  isRadioGroupFieldType: () => isRadioGroupFieldType,
155
161
  isSelectFieldType: () => isSelectFieldType,
156
162
  isSignatureFieldType: () => isSignatureFieldType,
163
+ isTemplateVariable: () => isTemplateVariable,
157
164
  isTextAreaFieldType: () => isTextAreaFieldType,
158
165
  isTextFieldType: () => isTextFieldType,
159
166
  isUndeclaredDraft: () => isUndeclaredDraft,
@@ -243,6 +250,11 @@ var FieldType = {
243
250
  SIGNATURE: "SIGNATURE"
244
251
  };
245
252
  var fieldTypes = Object.values(FieldType);
253
+ var compositeFieldTypes = [
254
+ FieldType.ADDRESS,
255
+ FieldType.FILE_WITH_OPTIONS,
256
+ FieldType.FILE
257
+ ];
246
258
 
247
259
  // ../commons/src/events/FieldValue.ts
248
260
  var import_zod4 = require("zod");
@@ -495,11 +507,16 @@ var Country = BaseField.extend({
495
507
  type: import_zod5.z.literal(FieldType.COUNTRY),
496
508
  defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
497
509
  }).describe("Country select field");
510
+ var AdministrativeAreas = import_zod5.z.enum([
511
+ "ADMIN_STRUCTURE",
512
+ "HEALTH_FACILITY",
513
+ "CRVS_OFFICE"
514
+ ]);
498
515
  var AdministrativeAreaConfiguration = import_zod5.z.object({
499
516
  partOf: import_zod5.z.object({
500
517
  $data: import_zod5.z.string()
501
518
  }).optional().describe("Parent location"),
502
- type: import_zod5.z.enum(["ADMIN_STRUCTURE", "HEALTH_FACILITY", "CRVS_OFFICE"])
519
+ type: AdministrativeAreas
503
520
  }).describe("Administrative area options");
504
521
  var AdministrativeArea = BaseField.extend({
505
522
  type: import_zod5.z.literal(FieldType.ADMINISTRATIVE_AREA),
@@ -594,7 +611,7 @@ var ActionType = {
594
611
  CUSTOM: "CUSTOM",
595
612
  REJECT: "REJECT",
596
613
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
597
- ARCHIVED: "ARCHIVED"
614
+ ARCHIVE: "ARCHIVE"
598
615
  };
599
616
 
600
617
  // ../commons/src/events/ActionConfig.ts
@@ -634,9 +651,9 @@ var MarkedAsDuplicateConfig = ActionConfigBase.merge(
634
651
  duplicates: import_zod7.z.array(import_zod7.z.string()).describe("UUIDs of duplicate records")
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),
656
+ type: import_zod7.z.literal(ActionType.ARCHIVE),
640
657
  comment: import_zod7.z.string(),
641
658
  isDuplicate: import_zod7.z.boolean()
642
659
  })
@@ -683,7 +700,7 @@ var ActionConfig = import_zod7.z.discriminatedUnion("type", [
683
700
  ValidateConfig,
684
701
  RejectDeclarationConfig,
685
702
  MarkedAsDuplicateConfig,
686
- ArchivedConfig,
703
+ ArchiveConfig,
687
704
  RegisterConfig,
688
705
  DeleteConfig,
689
706
  PrintCertificateActionConfig,
@@ -1363,6 +1380,14 @@ function validateFieldInput({
1363
1380
  return rawError.error?.issues.map((issue) => issue.message) ?? [];
1364
1381
  }
1365
1382
 
1383
+ // ../commons/src/utils.ts
1384
+ function getOrThrow(x, message) {
1385
+ if (x === void 0 || x === null) {
1386
+ throw new Error(message);
1387
+ }
1388
+ return x;
1389
+ }
1390
+
1366
1391
  // ../commons/src/events/utils.ts
1367
1392
  function isMetadataField(field2) {
1368
1393
  return field2 in eventMetadataLabelMap;
@@ -1459,6 +1484,12 @@ var findActiveActionFields = (configuration, action) => {
1459
1484
  const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1460
1485
  return allFields;
1461
1486
  };
1487
+ var getActiveActionFormPages = (configuration, action) => {
1488
+ return getOrThrow(
1489
+ findActiveActionForm(configuration, action)?.pages,
1490
+ "Form configuration not found for type: " + configuration.id
1491
+ );
1492
+ };
1462
1493
  function getActiveActionFields(configuration, action) {
1463
1494
  const fields = findActiveActionFields(configuration, action);
1464
1495
  if (!fields) {
@@ -1588,9 +1619,9 @@ var MarkAsDuplicateAction = ActionBase.merge(
1588
1619
  type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1589
1620
  })
1590
1621
  );
1591
- var ArchivedAction = ActionBase.merge(
1622
+ var ArchiveAction = ActionBase.merge(
1592
1623
  import_zod19.z.object({
1593
- type: import_zod19.z.literal(ActionType.ARCHIVED)
1624
+ type: import_zod19.z.literal(ActionType.ARCHIVE)
1594
1625
  })
1595
1626
  );
1596
1627
  var CreatedAction = ActionBase.merge(
@@ -1635,7 +1666,7 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1635
1666
  ValidateAction,
1636
1667
  RejectAction,
1637
1668
  MarkAsDuplicateAction,
1638
- ArchivedAction,
1669
+ ArchiveAction,
1639
1670
  NotifiedAction,
1640
1671
  RegisterAction,
1641
1672
  DeclareAction,
@@ -1664,7 +1695,6 @@ var import_zod20 = require("zod");
1664
1695
  var BaseActionInput = import_zod20.z.object({
1665
1696
  eventId: import_zod20.z.string(),
1666
1697
  transactionId: import_zod20.z.string(),
1667
- incomplete: import_zod20.z.boolean().optional().default(false).describe("Allows action with partial data to be saved"),
1668
1698
  data: ActionUpdate,
1669
1699
  metadata: ActionUpdate.optional()
1670
1700
  });
@@ -1691,8 +1721,7 @@ var ValidateActionInput = BaseActionInput.merge(
1691
1721
  );
1692
1722
  var NotifyActionInput = BaseActionInput.merge(
1693
1723
  import_zod20.z.object({
1694
- type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY),
1695
- createdAtLocation: import_zod20.z.string()
1724
+ type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1696
1725
  })
1697
1726
  );
1698
1727
  var DeclareActionInput = BaseActionInput.merge(
@@ -1715,9 +1744,9 @@ var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1715
1744
  type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1716
1745
  })
1717
1746
  );
1718
- var ArchivedActionInput = BaseActionInput.merge(
1747
+ var ArchiveActionInput = BaseActionInput.merge(
1719
1748
  import_zod20.z.object({
1720
- type: import_zod20.z.literal(ActionType.ARCHIVED).default(ActionType.ARCHIVED)
1749
+ type: import_zod20.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1721
1750
  })
1722
1751
  );
1723
1752
  var AssignActionInput = BaseActionInput.merge(
@@ -1756,7 +1785,7 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
1756
1785
  DeclareActionInput,
1757
1786
  RejectDeclarationActionInput,
1758
1787
  MarkedAsDuplicateActionInput,
1759
- ArchivedActionInput,
1788
+ ArchiveActionInput,
1760
1789
  AssignActionInput,
1761
1790
  UnassignActionInput,
1762
1791
  PrintCertificateActionInput,
@@ -1828,9 +1857,12 @@ function getStatusFromActions(actions) {
1828
1857
  if (action.type === ActionType.REJECT) {
1829
1858
  return EventStatus.REJECTED;
1830
1859
  }
1831
- if (action.type === ActionType.ARCHIVED) {
1860
+ if (action.type === ActionType.ARCHIVE) {
1832
1861
  return EventStatus.ARCHIVED;
1833
1862
  }
1863
+ if (action.type === ActionType.NOTIFY) {
1864
+ return EventStatus.NOTIFIED;
1865
+ }
1834
1866
  return status;
1835
1867
  }, EventStatus.CREATED);
1836
1868
  }
@@ -1897,8 +1929,8 @@ function deepMerge(currentDocument, actionDocument) {
1897
1929
  }
1898
1930
  );
1899
1931
  }
1900
- function isUndeclaredDraft(event2) {
1901
- return event2.actions.every(({ type }) => type === ActionType.CREATE);
1932
+ function isUndeclaredDraft(status) {
1933
+ return status === EventStatus.CREATED;
1902
1934
  }
1903
1935
  function getCurrentEventState(event2) {
1904
1936
  const creationAction = event2.actions.find(
@@ -3491,7 +3523,7 @@ var eventPayloadGenerator = {
3491
3523
  eventId
3492
3524
  }),
3493
3525
  archive: (eventId, input = {}, isDuplicate) => ({
3494
- type: ActionType.ARCHIVED,
3526
+ type: ActionType.ARCHIVE,
3495
3527
  transactionId: input.transactionId ?? getUUID(),
3496
3528
  data: input.data ?? {},
3497
3529
  metadata: { isDuplicate: isDuplicate ?? false },
@@ -3577,7 +3609,7 @@ function generateActionDocument({
3577
3609
  return { ...actionBase, assignedTo: getUUID(), type: action };
3578
3610
  case ActionType.VALIDATE:
3579
3611
  return { ...actionBase, type: action };
3580
- case ActionType.ARCHIVED:
3612
+ case ActionType.ARCHIVE:
3581
3613
  return { ...actionBase, type: action };
3582
3614
  case ActionType.REJECT:
3583
3615
  return { ...actionBase, type: action };
@@ -3657,3 +3689,33 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3657
3689
  },
3658
3690
  trackingId: overrides.trackingId ?? "M3F8YQ"
3659
3691
  });
3692
+
3693
+ // ../commons/src/events/TemplateConfig.ts
3694
+ function isTemplateVariable(value) {
3695
+ return typeof value === "string" && value.startsWith("$");
3696
+ }
3697
+ function isFieldValue(value) {
3698
+ return FieldValue.safeParse(value).success;
3699
+ }
3700
+ function isFieldValueWithoutTemplates(value) {
3701
+ if (isTemplateVariable(value)) {
3702
+ return false;
3703
+ }
3704
+ if (typeof value === "object" && Object.values(value).some((val) => isTemplateVariable(val))) {
3705
+ return false;
3706
+ }
3707
+ return true;
3708
+ }
3709
+ function isFieldConfigDefaultValue(value) {
3710
+ if (!value) return false;
3711
+ if (isFieldValue(value)) {
3712
+ return true;
3713
+ }
3714
+ if (isTemplateVariable(value)) {
3715
+ return true;
3716
+ }
3717
+ if (typeof value === "object" && Object.values(value).every((v) => typeof v === "object" && v !== null)) {
3718
+ return Object.values(value).every((v) => isFieldConfigDefaultValue(v));
3719
+ }
3720
+ return false;
3721
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.8.0-rc.fe799b0",
3
+ "version": "1.8.0-rc.ff2e7b6",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {