@opencrvs/toolkit 1.8.0-rc.f7e8fb5 → 1.8.0-rc.f876361

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.
Files changed (30) hide show
  1. package/README.md +1 -1
  2. package/dist/commons/api/router.d.ts +5260 -10679
  3. package/dist/commons/conditionals/conditionals.d.ts +17 -1
  4. package/dist/commons/conditionals/validate-address.test.d.ts +2 -0
  5. package/dist/commons/conditionals/validate.d.ts +27 -0
  6. package/dist/commons/conditionals/validate.test.d.ts +2 -0
  7. package/dist/commons/events/ActionConfig.d.ts +1123 -2056
  8. package/dist/commons/events/ActionDocument.d.ts +9482 -312
  9. package/dist/commons/events/ActionInput.d.ts +4321 -359
  10. package/dist/commons/events/ActionType.d.ts +24 -11
  11. package/dist/commons/events/CompositeFieldValue.d.ts +152 -2
  12. package/dist/commons/events/Draft.d.ts +342 -46
  13. package/dist/commons/events/EventConfig.d.ts +551 -1206
  14. package/dist/commons/events/EventConfigInput.d.ts +6 -3
  15. package/dist/commons/events/EventDocument.d.ts +3335 -424
  16. package/dist/commons/events/EventIndex.d.ts +6 -3
  17. package/dist/commons/events/EventMetadata.d.ts +3 -0
  18. package/dist/commons/events/FieldConfig.d.ts +366 -52
  19. package/dist/commons/events/FieldType.d.ts +2 -1
  20. package/dist/commons/events/FieldTypeMapping.d.ts +154 -3
  21. package/dist/commons/events/FieldValue.d.ts +76 -2
  22. package/dist/commons/events/FormConfig.d.ts +633 -48
  23. package/dist/commons/events/PageConfig.d.ts +359 -0
  24. package/dist/commons/events/defineConfig.d.ts +91 -216
  25. package/dist/commons/events/index.d.ts +2 -1
  26. package/dist/commons/events/test.utils.d.ts +159 -140
  27. package/dist/commons/events/utils.d.ts +115 -82
  28. package/dist/conditionals/index.js +120 -15
  29. package/dist/events/index.js +1166 -671
  30. package/package.json +1 -1
@@ -1,99 +1,57 @@
1
- import { TranslationConfig } from './TranslationConfig';
2
- import { ActionType } from './ActionType';
1
+ import { ActionType, DeclarationAction } from './ActionType';
3
2
  import { EventConfig } from './EventConfig';
4
- import { EventConfigInput } from './EventConfigInput';
5
- import { EventMetadataKeys } from './EventMetadata';
6
3
  import { FieldConfig } from './FieldConfig';
7
4
  import { WorkqueueConfig } from './WorkqueueConfig';
8
- import { EventState } from './ActionDocument';
9
- import { FormConfig } from './FormConfig';
5
+ import { ActionUpdate, EventState } from './ActionDocument';
6
+ import { PageConfig, VerificationPageConfig } from './PageConfig';
10
7
  import { Draft } from './Draft';
11
8
  import { EventDocument } from './EventDocument';
12
- /**
13
- * @returns All the fields in the event configuration input.
14
- */
15
- export declare const findInputPageFields: (config: EventConfigInput) => {
16
- id: string;
17
- label: TranslationConfig;
18
- }[];
9
+ import { ActionConfig } from './ActionConfig';
10
+ import { FormConfig } from './FormConfig';
19
11
  /**
20
12
  * @returns All the fields in the event configuration.
21
13
  */
22
- export declare const findPageFields: (config: EventConfig) => FieldConfig[];
14
+ export declare const findAllFields: (config: EventConfig) => FieldConfig[];
15
+ export declare const getAllAnnotationFields: (config: EventConfig) => FieldConfig[];
16
+ export declare const getActionAnnotationFields: (actionConfig: ActionConfig) => import("./FieldConfig").Inferred[];
23
17
  /**
24
- *
25
- * @param pageFields - All the fields in the event configuration
26
- * @param refFields - The fields referencing values within the event configuration (e.g. summary fields) or within system provided metadata fields (e.g. createdAt, updatedBy)
27
- * @returns referenced fields with populated labels
18
+ * @TODO: Request correction should have same format as print certificate
28
19
  */
29
- export declare const resolveLabelsFromKnownFields: ({ pageFields, refFields }: {
30
- pageFields: {
31
- id: string;
32
- label: TranslationConfig;
33
- }[];
34
- refFields: {
35
- id: EventMetadataKeys | string;
36
- label?: TranslationConfig;
37
- }[];
38
- }) => {
39
- id: EventMetadataKeys | string;
40
- label?: TranslationConfig;
41
- }[];
42
- export declare function getAllFields(configuration: EventConfig): import("./FieldConfig").Inferred[];
43
- export declare function getAllPages(configuration: EventConfig): {
20
+ export declare const findRecordActionPages: (config: EventConfig, actionType: ActionType) => PageConfig[];
21
+ export declare function getDeclarationFields(configuration: EventConfig): FieldConfig[];
22
+ export declare function getDeclarationPages(configuration: EventConfig): {
23
+ type: "FORM";
44
24
  id: string;
45
- title: TranslationConfig;
25
+ title: import("./TranslationConfig").TranslationConfig;
46
26
  fields: import("./FieldConfig").Inferred[];
27
+ conditional?: import(".").JSONSchema | undefined;
47
28
  }[];
48
- export declare function validateWorkqueueConfig(workqueueConfigs: WorkqueueConfig[]): void;
49
- export declare const findActiveActionForm: (configuration: EventConfig, action: ActionType) => {
50
- active: boolean;
51
- version: {
52
- id: string;
53
- label: TranslationConfig;
54
- };
55
- label: TranslationConfig;
29
+ export declare function getDeclaration(configuration: EventConfig): {
30
+ label: import("./TranslationConfig").TranslationConfig;
56
31
  pages: {
32
+ type: "FORM";
57
33
  id: string;
58
- title: TranslationConfig;
34
+ title: import("./TranslationConfig").TranslationConfig;
59
35
  fields: import("./FieldConfig").Inferred[];
36
+ conditional?: import(".").JSONSchema | undefined;
60
37
  }[];
61
- review: {
62
- title: TranslationConfig;
63
- fields: import("./FieldConfig").Inferred[];
64
- };
65
- } | undefined;
66
- export declare const findActiveActionFormPages: (configuration: EventConfig, action: ActionType) => {
67
- id: string;
68
- title: TranslationConfig;
69
- fields: import("./FieldConfig").Inferred[];
70
- }[] | undefined;
71
- export declare const getFormFields: (formConfig: FormConfig) => import("./FieldConfig").Inferred[];
72
- /**
73
- * Returns only form fields for the action type, if any, excluding review fields.
74
- */
75
- export declare const findActiveActionFormFields: (configuration: EventConfig, action: ActionType) => FieldConfig[] | undefined;
76
- /**
77
- * Returns all fields for the action type, including review fields, if any.
78
- */
79
- export declare const findActiveActionFields: (configuration: EventConfig, action: ActionType) => FieldConfig[] | undefined;
80
- export declare const getActiveActionFormPages: (configuration: EventConfig, action: ActionType) => {
81
- id: string;
82
- title: TranslationConfig;
38
+ };
39
+ export declare function getActionReviewFields(configuration: EventConfig, actionType: DeclarationAction): import("./FieldConfig").Inferred[];
40
+ export declare function getActionReview(configuration: EventConfig, actionType: ActionType): {
41
+ title: import("./TranslationConfig").TranslationConfig;
83
42
  fields: import("./FieldConfig").Inferred[];
84
- }[];
85
- /**
86
- * Returns all fields for the action type, including review fields, or throws
87
- */
88
- export declare function getActiveActionFields(configuration: EventConfig, action: ActionType): FieldConfig[];
89
- export declare function getEventConfiguration(eventConfigurations: EventConfig[], type: string): EventConfig;
90
- export declare function stripHiddenFields(fields: FieldConfig[], data: EventState): import("lodash").Dictionary<string | number | boolean | {
43
+ };
44
+ export declare function validateWorkqueueConfig(workqueueConfigs: WorkqueueConfig[]): void;
45
+ export declare function isPageVisible(page: PageConfig, formValues: ActionUpdate): boolean;
46
+ export declare const getVisiblePagesFormFields: (formConfig: FormConfig, formData: ActionUpdate) => import("./FieldConfig").Inferred[];
47
+ export declare function stripHiddenFields(fields: FieldConfig[], declaration: EventState): import("lodash").Dictionary<string | number | boolean | {
91
48
  type: string;
92
49
  filename: string;
93
50
  originalFilename: string;
94
51
  } | {
95
52
  country: string;
96
53
  district: string;
54
+ addressType: "DOMESTIC";
97
55
  province: string;
98
56
  urbanOrRural: "URBAN";
99
57
  number?: string | undefined;
@@ -104,29 +62,43 @@ export declare function stripHiddenFields(fields: FieldConfig[], data: EventStat
104
62
  } | {
105
63
  country: string;
106
64
  district: string;
65
+ addressType: "DOMESTIC";
107
66
  province: string;
108
67
  urbanOrRural: "RURAL";
109
68
  village?: string | undefined;
69
+ } | {
70
+ country: string;
71
+ state: string;
72
+ addressType: "INTERNATIONAL";
73
+ district2: string;
74
+ cityOrTown?: string | undefined;
75
+ addressLine1?: string | undefined;
76
+ addressLine2?: string | undefined;
77
+ addressLine3?: string | undefined;
78
+ postcodeOrZip?: string | undefined;
110
79
  } | {
111
80
  type: string;
112
81
  option: string;
113
82
  filename: string;
114
83
  originalFilename: string;
115
- }[]>;
84
+ }[] | undefined>;
116
85
  export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]): {
117
86
  id: string;
118
87
  createdAt: string;
119
88
  eventId: string;
120
89
  transactionId: string;
121
90
  action: {
122
- type: ActionType;
123
- data: Record<string, string | number | boolean | {
91
+ type: "DECLARE" | "REGISTER" | "VALIDATE" | "DELETE" | "CREATE" | "NOTIFY" | "DETECT_DUPLICATE" | "REJECT" | "MARKED_AS_DUPLICATE" | "ARCHIVE" | "PRINT_CERTIFICATE" | "REQUEST_CORRECTION" | "REJECT_CORRECTION" | "APPROVE_CORRECTION" | "READ" | "ASSIGN" | "UNASSIGN";
92
+ createdAt: string;
93
+ createdBy: string;
94
+ declaration: Record<string, string | number | boolean | {
124
95
  type: string;
125
96
  filename: string;
126
97
  originalFilename: string;
127
98
  } | {
128
99
  country: string;
129
100
  district: string;
101
+ addressType: "DOMESTIC";
130
102
  province: string;
131
103
  urbanOrRural: "URBAN";
132
104
  number?: string | null | undefined;
@@ -137,25 +109,35 @@ export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]):
137
109
  } | {
138
110
  country: string;
139
111
  district: string;
112
+ addressType: "DOMESTIC";
140
113
  province: string;
141
114
  urbanOrRural: "RURAL";
142
115
  village?: string | null | undefined;
116
+ } | {
117
+ country: string;
118
+ state: string;
119
+ addressType: "INTERNATIONAL";
120
+ district2: string;
121
+ cityOrTown?: string | null | undefined;
122
+ addressLine1?: string | null | undefined;
123
+ addressLine2?: string | null | undefined;
124
+ addressLine3?: string | null | undefined;
125
+ postcodeOrZip?: string | null | undefined;
143
126
  } | {
144
127
  type: string;
145
128
  option: string;
146
129
  filename: string;
147
130
  originalFilename: string;
148
- }[]>;
149
- createdAt: string;
150
- createdBy: string;
131
+ }[] | undefined>;
151
132
  createdAtLocation: string;
152
- metadata?: Record<string, string | number | boolean | {
133
+ annotation?: Record<string, string | number | boolean | {
153
134
  type: string;
154
135
  filename: string;
155
136
  originalFilename: string;
156
137
  } | {
157
138
  country: string;
158
139
  district: string;
140
+ addressType: "DOMESTIC";
159
141
  province: string;
160
142
  urbanOrRural: "URBAN";
161
143
  number?: string | null | undefined;
@@ -166,15 +148,27 @@ export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]):
166
148
  } | {
167
149
  country: string;
168
150
  district: string;
151
+ addressType: "DOMESTIC";
169
152
  province: string;
170
153
  urbanOrRural: "RURAL";
171
154
  village?: string | null | undefined;
155
+ } | {
156
+ country: string;
157
+ state: string;
158
+ addressType: "INTERNATIONAL";
159
+ district2: string;
160
+ cityOrTown?: string | null | undefined;
161
+ addressLine1?: string | null | undefined;
162
+ addressLine2?: string | null | undefined;
163
+ addressLine3?: string | null | undefined;
164
+ postcodeOrZip?: string | null | undefined;
172
165
  } | {
173
166
  type: string;
174
167
  option: string;
175
168
  filename: string;
176
169
  originalFilename: string;
177
- }[]> | undefined;
170
+ }[] | undefined> | undefined;
171
+ originalActionId?: string | undefined;
178
172
  };
179
173
  }[];
180
174
  export declare function createEmptyDraft(eventId: string, draftId: string, actionType: ActionType): {
@@ -184,11 +178,50 @@ export declare function createEmptyDraft(eventId: string, draftId: string, actio
184
178
  transactionId: import("../uuid").UUID;
185
179
  action: {
186
180
  type: ActionType;
187
- data: {};
188
- metadata: {};
181
+ declaration: {};
182
+ annotation: {};
189
183
  createdAt: string;
190
184
  createdBy: string;
191
185
  createdAtLocation: string;
192
186
  };
193
187
  };
188
+ export declare function isVerificationPage(page: PageConfig): page is VerificationPageConfig;
189
+ export declare function deepMerge(currentDocument: ActionUpdate, actionDocument: ActionUpdate): Record<string, string | number | boolean | {
190
+ type: string;
191
+ filename: string;
192
+ originalFilename: string;
193
+ } | {
194
+ country: string;
195
+ district: string;
196
+ addressType: "DOMESTIC";
197
+ province: string;
198
+ urbanOrRural: "URBAN";
199
+ number?: string | null | undefined;
200
+ town?: string | null | undefined;
201
+ residentialArea?: string | null | undefined;
202
+ street?: string | null | undefined;
203
+ zipCode?: string | null | undefined;
204
+ } | {
205
+ country: string;
206
+ district: string;
207
+ addressType: "DOMESTIC";
208
+ province: string;
209
+ urbanOrRural: "RURAL";
210
+ village?: string | null | undefined;
211
+ } | {
212
+ country: string;
213
+ state: string;
214
+ addressType: "INTERNATIONAL";
215
+ district2: string;
216
+ cityOrTown?: string | null | undefined;
217
+ addressLine1?: string | null | undefined;
218
+ addressLine2?: string | null | undefined;
219
+ addressLine3?: string | null | undefined;
220
+ postcodeOrZip?: string | null | undefined;
221
+ } | {
222
+ type: string;
223
+ option: string;
224
+ filename: string;
225
+ originalFilename: string;
226
+ }[] | undefined>;
194
227
  //# sourceMappingURL=utils.d.ts.map
@@ -126,6 +126,10 @@ function field(fieldId) {
126
126
  required: ["$form"]
127
127
  });
128
128
  return {
129
+ /**
130
+ * @private Internal property used for field reference tracking.
131
+ */
132
+ _returning: fieldId,
129
133
  isAfter: () => ({
130
134
  days: (days) => ({
131
135
  inPast: () => defineConditional(
@@ -150,25 +154,54 @@ function field(fieldId) {
150
154
  date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
151
155
  now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
152
156
  }),
153
- isEqualTo: (value) => defineConditional({
154
- type: "object",
155
- properties: {
156
- $form: {
157
+ // TODO CIHAN: typing
158
+ isEqualTo: (value) => {
159
+ if (typeof value === "object" && value._returning) {
160
+ const comparedFieldId = value._returning;
161
+ return defineConditional({
157
162
  type: "object",
158
163
  properties: {
159
- [fieldId]: {
160
- oneOf: [
161
- { type: "string", const: value },
162
- { type: "boolean", const: value }
163
- ],
164
- const: value
164
+ $form: {
165
+ type: "object",
166
+ properties: {
167
+ [fieldId]: { type: ["string", "boolean"] },
168
+ [comparedFieldId]: { type: ["string", "boolean"] }
169
+ },
170
+ required: [fieldId, comparedFieldId],
171
+ allOf: [
172
+ {
173
+ properties: {
174
+ [fieldId]: {
175
+ const: { $data: `1/${comparedFieldId}` }
176
+ }
177
+ }
178
+ }
179
+ ]
165
180
  }
166
181
  },
167
- required: [fieldId]
168
- }
169
- },
170
- required: ["$form"]
171
- }),
182
+ required: ["$form"]
183
+ });
184
+ }
185
+ return defineConditional({
186
+ type: "object",
187
+ properties: {
188
+ $form: {
189
+ type: "object",
190
+ properties: {
191
+ [fieldId]: {
192
+ oneOf: [
193
+ { type: "string", const: value },
194
+ { type: "boolean", const: value }
195
+ ],
196
+ const: value
197
+ }
198
+ },
199
+ required: [fieldId]
200
+ }
201
+ },
202
+ required: ["$form"]
203
+ });
204
+ },
172
205
  /**
173
206
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
174
207
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -239,6 +272,78 @@ function field(fieldId) {
239
272
  }
240
273
  },
241
274
  required: ["$form"]
275
+ }),
276
+ isValidEnglishName: () => defineConditional({
277
+ type: "object",
278
+ properties: {
279
+ $form: {
280
+ type: "object",
281
+ properties: {
282
+ [fieldId]: {
283
+ type: "string",
284
+ pattern: "^[\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*( [\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*)*$",
285
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
286
+ }
287
+ },
288
+ required: [fieldId]
289
+ }
290
+ },
291
+ required: ["$form"]
292
+ }),
293
+ isValidNationalId: () => defineConditional({
294
+ type: "object",
295
+ properties: {
296
+ $form: {
297
+ type: "object",
298
+ properties: {
299
+ [fieldId]: {
300
+ type: "string",
301
+ pattern: "^[0-9]{9}$",
302
+ description: "The National ID can only be numeric and must be 9 digits long."
303
+ }
304
+ },
305
+ required: [fieldId]
306
+ }
307
+ },
308
+ required: ["$form"]
309
+ }),
310
+ /**
311
+ * Checks if the field value matches a given regular expression pattern.
312
+ * @param pattern - The regular expression pattern to match the field value against.
313
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
314
+ */
315
+ matches: (pattern) => defineConditional({
316
+ type: "object",
317
+ properties: {
318
+ $form: {
319
+ type: "object",
320
+ properties: {
321
+ [fieldId]: {
322
+ type: "string",
323
+ pattern
324
+ }
325
+ },
326
+ required: [fieldId]
327
+ }
328
+ },
329
+ required: ["$form"]
330
+ }),
331
+ isBetween: (min, max) => defineConditional({
332
+ type: "object",
333
+ properties: {
334
+ $form: {
335
+ type: "object",
336
+ properties: {
337
+ [fieldId]: {
338
+ type: "number",
339
+ minimum: min,
340
+ maximum: max
341
+ }
342
+ },
343
+ required: [fieldId]
344
+ }
345
+ },
346
+ required: ["$form"]
242
347
  })
243
348
  };
244
349
  }