@opencrvs/toolkit 1.8.0-rc.feaeeb7 → 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
@@ -1,18 +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
+ */
1
5
  import { FieldValue } from './FieldValue';
2
- export type DefaultValue = FieldValue | MetaFieldsDotted | Record<string, MetaFieldsDotted | FieldValue>;
3
- export declare function isTemplateVariable(value: DefaultValue): value is MetaFieldsDotted;
4
- export declare function isFieldValue(value: DefaultValue): value is FieldValue;
5
- export declare function isFieldValueWithoutTemplates(value: DefaultValue): value is FieldValue;
6
- export declare function isDefaultValue(value: any): value is DefaultValue;
6
+ /**
7
+ * Available system variables for configuration.
8
+ */
7
9
  export interface MetaFields {
8
10
  $user: {
9
11
  province: string;
10
12
  district: string;
11
13
  };
12
14
  }
13
- type DottedKeys<T, Prefix extends string = ''> = {
14
- [K in keyof T]: T[K] extends Record<string, string> ? DottedKeys<T[K], `${Prefix}${K & string}.`> : `${Prefix}${K & string}`;
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}`;
15
23
  }[keyof T];
16
- export type MetaFieldsDotted = DottedKeys<MetaFields>;
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;
17
37
  export {};
18
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";
@@ -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,
@@ -139,10 +142,10 @@ __export(events_exports, {
139
142
  isCheckboxFieldType: () => isCheckboxFieldType,
140
143
  isCountryFieldType: () => isCountryFieldType,
141
144
  isDateFieldType: () => isDateFieldType,
142
- isDefaultValue: () => isDefaultValue,
143
145
  isDividerFieldType: () => isDividerFieldType,
144
146
  isEmailFieldType: () => isEmailFieldType,
145
147
  isFacilityFieldType: () => isFacilityFieldType,
148
+ isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
146
149
  isFieldEnabled: () => isFieldEnabled,
147
150
  isFieldValue: () => isFieldValue,
148
151
  isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
@@ -247,6 +250,11 @@ var FieldType = {
247
250
  SIGNATURE: "SIGNATURE"
248
251
  };
249
252
  var fieldTypes = Object.values(FieldType);
253
+ var compositeFieldTypes = [
254
+ FieldType.ADDRESS,
255
+ FieldType.FILE_WITH_OPTIONS,
256
+ FieldType.FILE
257
+ ];
250
258
 
251
259
  // ../commons/src/events/FieldValue.ts
252
260
  var import_zod4 = require("zod");
@@ -499,11 +507,16 @@ var Country = BaseField.extend({
499
507
  type: import_zod5.z.literal(FieldType.COUNTRY),
500
508
  defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
501
509
  }).describe("Country select field");
510
+ var AdministrativeAreas = import_zod5.z.enum([
511
+ "ADMIN_STRUCTURE",
512
+ "HEALTH_FACILITY",
513
+ "CRVS_OFFICE"
514
+ ]);
502
515
  var AdministrativeAreaConfiguration = import_zod5.z.object({
503
516
  partOf: import_zod5.z.object({
504
517
  $data: import_zod5.z.string()
505
518
  }).optional().describe("Parent location"),
506
- type: import_zod5.z.enum(["ADMIN_STRUCTURE", "HEALTH_FACILITY", "CRVS_OFFICE"])
519
+ type: AdministrativeAreas
507
520
  }).describe("Administrative area options");
508
521
  var AdministrativeArea = BaseField.extend({
509
522
  type: import_zod5.z.literal(FieldType.ADMINISTRATIVE_AREA),
@@ -598,7 +611,7 @@ var ActionType = {
598
611
  CUSTOM: "CUSTOM",
599
612
  REJECT: "REJECT",
600
613
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
601
- ARCHIVED: "ARCHIVED"
614
+ ARCHIVE: "ARCHIVE"
602
615
  };
603
616
 
604
617
  // ../commons/src/events/ActionConfig.ts
@@ -638,9 +651,9 @@ var MarkedAsDuplicateConfig = ActionConfigBase.merge(
638
651
  duplicates: import_zod7.z.array(import_zod7.z.string()).describe("UUIDs of duplicate records")
639
652
  })
640
653
  );
641
- var ArchivedConfig = ActionConfigBase.merge(
654
+ var ArchiveConfig = ActionConfigBase.merge(
642
655
  import_zod7.z.object({
643
- type: import_zod7.z.literal(ActionType.ARCHIVED),
656
+ type: import_zod7.z.literal(ActionType.ARCHIVE),
644
657
  comment: import_zod7.z.string(),
645
658
  isDuplicate: import_zod7.z.boolean()
646
659
  })
@@ -687,7 +700,7 @@ var ActionConfig = import_zod7.z.discriminatedUnion("type", [
687
700
  ValidateConfig,
688
701
  RejectDeclarationConfig,
689
702
  MarkedAsDuplicateConfig,
690
- ArchivedConfig,
703
+ ArchiveConfig,
691
704
  RegisterConfig,
692
705
  DeleteConfig,
693
706
  PrintCertificateActionConfig,
@@ -1367,6 +1380,14 @@ function validateFieldInput({
1367
1380
  return rawError.error?.issues.map((issue) => issue.message) ?? [];
1368
1381
  }
1369
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
+
1370
1391
  // ../commons/src/events/utils.ts
1371
1392
  function isMetadataField(field2) {
1372
1393
  return field2 in eventMetadataLabelMap;
@@ -1463,6 +1484,12 @@ var findActiveActionFields = (configuration, action) => {
1463
1484
  const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1464
1485
  return allFields;
1465
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
+ };
1466
1493
  function getActiveActionFields(configuration, action) {
1467
1494
  const fields = findActiveActionFields(configuration, action);
1468
1495
  if (!fields) {
@@ -1592,9 +1619,9 @@ var MarkAsDuplicateAction = ActionBase.merge(
1592
1619
  type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1593
1620
  })
1594
1621
  );
1595
- var ArchivedAction = ActionBase.merge(
1622
+ var ArchiveAction = ActionBase.merge(
1596
1623
  import_zod19.z.object({
1597
- type: import_zod19.z.literal(ActionType.ARCHIVED)
1624
+ type: import_zod19.z.literal(ActionType.ARCHIVE)
1598
1625
  })
1599
1626
  );
1600
1627
  var CreatedAction = ActionBase.merge(
@@ -1639,7 +1666,7 @@ var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1639
1666
  ValidateAction,
1640
1667
  RejectAction,
1641
1668
  MarkAsDuplicateAction,
1642
- ArchivedAction,
1669
+ ArchiveAction,
1643
1670
  NotifiedAction,
1644
1671
  RegisterAction,
1645
1672
  DeclareAction,
@@ -1668,7 +1695,6 @@ var import_zod20 = require("zod");
1668
1695
  var BaseActionInput = import_zod20.z.object({
1669
1696
  eventId: import_zod20.z.string(),
1670
1697
  transactionId: import_zod20.z.string(),
1671
- incomplete: import_zod20.z.boolean().optional().default(false).describe("Allows action with partial data to be saved"),
1672
1698
  data: ActionUpdate,
1673
1699
  metadata: ActionUpdate.optional()
1674
1700
  });
@@ -1695,8 +1721,7 @@ var ValidateActionInput = BaseActionInput.merge(
1695
1721
  );
1696
1722
  var NotifyActionInput = BaseActionInput.merge(
1697
1723
  import_zod20.z.object({
1698
- type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY),
1699
- createdAtLocation: import_zod20.z.string()
1724
+ type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1700
1725
  })
1701
1726
  );
1702
1727
  var DeclareActionInput = BaseActionInput.merge(
@@ -1719,9 +1744,9 @@ var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1719
1744
  type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1720
1745
  })
1721
1746
  );
1722
- var ArchivedActionInput = BaseActionInput.merge(
1747
+ var ArchiveActionInput = BaseActionInput.merge(
1723
1748
  import_zod20.z.object({
1724
- type: import_zod20.z.literal(ActionType.ARCHIVED).default(ActionType.ARCHIVED)
1749
+ type: import_zod20.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1725
1750
  })
1726
1751
  );
1727
1752
  var AssignActionInput = BaseActionInput.merge(
@@ -1760,7 +1785,7 @@ var ActionInput = import_zod20.z.discriminatedUnion("type", [
1760
1785
  DeclareActionInput,
1761
1786
  RejectDeclarationActionInput,
1762
1787
  MarkedAsDuplicateActionInput,
1763
- ArchivedActionInput,
1788
+ ArchiveActionInput,
1764
1789
  AssignActionInput,
1765
1790
  UnassignActionInput,
1766
1791
  PrintCertificateActionInput,
@@ -1832,9 +1857,12 @@ function getStatusFromActions(actions) {
1832
1857
  if (action.type === ActionType.REJECT) {
1833
1858
  return EventStatus.REJECTED;
1834
1859
  }
1835
- if (action.type === ActionType.ARCHIVED) {
1860
+ if (action.type === ActionType.ARCHIVE) {
1836
1861
  return EventStatus.ARCHIVED;
1837
1862
  }
1863
+ if (action.type === ActionType.NOTIFY) {
1864
+ return EventStatus.NOTIFIED;
1865
+ }
1838
1866
  return status;
1839
1867
  }, EventStatus.CREATED);
1840
1868
  }
@@ -1901,8 +1929,8 @@ function deepMerge(currentDocument, actionDocument) {
1901
1929
  }
1902
1930
  );
1903
1931
  }
1904
- function isUndeclaredDraft(event2) {
1905
- return event2.actions.every(({ type }) => type === ActionType.CREATE);
1932
+ function isUndeclaredDraft(status) {
1933
+ return status === EventStatus.CREATED;
1906
1934
  }
1907
1935
  function getCurrentEventState(event2) {
1908
1936
  const creationAction = event2.actions.find(
@@ -3495,7 +3523,7 @@ var eventPayloadGenerator = {
3495
3523
  eventId
3496
3524
  }),
3497
3525
  archive: (eventId, input = {}, isDuplicate) => ({
3498
- type: ActionType.ARCHIVED,
3526
+ type: ActionType.ARCHIVE,
3499
3527
  transactionId: input.transactionId ?? getUUID(),
3500
3528
  data: input.data ?? {},
3501
3529
  metadata: { isDuplicate: isDuplicate ?? false },
@@ -3581,7 +3609,7 @@ function generateActionDocument({
3581
3609
  return { ...actionBase, assignedTo: getUUID(), type: action };
3582
3610
  case ActionType.VALIDATE:
3583
3611
  return { ...actionBase, type: action };
3584
- case ActionType.ARCHIVED:
3612
+ case ActionType.ARCHIVE:
3585
3613
  return { ...actionBase, type: action };
3586
3614
  case ActionType.REJECT:
3587
3615
  return { ...actionBase, type: action };
@@ -3678,7 +3706,7 @@ function isFieldValueWithoutTemplates(value) {
3678
3706
  }
3679
3707
  return true;
3680
3708
  }
3681
- function isDefaultValue(value) {
3709
+ function isFieldConfigDefaultValue(value) {
3682
3710
  if (!value) return false;
3683
3711
  if (isFieldValue(value)) {
3684
3712
  return true;
@@ -3687,7 +3715,7 @@ function isDefaultValue(value) {
3687
3715
  return true;
3688
3716
  }
3689
3717
  if (typeof value === "object" && Object.values(value).every((v) => typeof v === "object" && v !== null)) {
3690
- return Object.values(value).every((v) => isDefaultValue(v));
3718
+ return Object.values(value).every((v) => isFieldConfigDefaultValue(v));
3691
3719
  }
3692
3720
  return false;
3693
3721
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.8.0-rc.feaeeb7",
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": {