@opencrvs/toolkit 1.8.0-rc.faacbde → 1.8.0-rc.fb0e687

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.
@@ -6,12 +6,12 @@ import { FieldValue } from './FieldValue';
6
6
  /**
7
7
  * Available system variables for configuration.
8
8
  */
9
- export interface MetaFields {
9
+ export type MetaFields = {
10
10
  $user: {
11
11
  province: string;
12
12
  district: string;
13
13
  };
14
- }
14
+ };
15
15
  /**
16
16
  * Recursively flatten the keys of an object. Used to limit types when configuring default values in country config.
17
17
  * @example
@@ -1,5 +1,5 @@
1
1
  import { ActionDocument, ActionUpdate } from './ActionDocument';
2
- import { ArchiveActionInput, DeclareActionInput, RegisterActionInput, RejectDeclarationActionInput, RequestCorrectionActionInput, ValidateActionInput } from './ActionInput';
2
+ import { ArchiveActionInput, AssignActionInput, DeclareActionInput, RegisterActionInput, RejectDeclarationActionInput, RequestCorrectionActionInput, UnassignActionInput, ValidateActionInput } from './ActionInput';
3
3
  import { ActionType } from './ActionType';
4
4
  import { Draft } from './Draft';
5
5
  import { EventConfig } from './EventConfig';
@@ -57,115 +57,10 @@ export declare const eventPayloadGenerator: {
57
57
  type: string;
58
58
  id: string;
59
59
  };
60
- draft: (eventId: string, input?: Partial<Draft>) => {
61
- id: import("../uuid").UUID;
60
+ draft: ({ eventId, actionType }: {
62
61
  eventId: string;
63
- createdAt: string;
64
- transactionId: import("../uuid").UUID;
65
- action: {
66
- type: "REQUEST_CORRECTION";
67
- declaration: {
68
- 'applicant.firstname': string;
69
- 'applicant.surname': string;
70
- 'applicant.dob': string;
71
- 'recommender.none': boolean;
72
- };
73
- annotation: {
74
- 'correction.requester.relationship': string;
75
- 'correction.request.reason': string;
76
- };
77
- createdAt: string;
78
- createdBy: string;
79
- createdAtLocation: string;
80
- };
81
- } & Partial<{
82
- id: string;
83
- createdAt: string;
84
- eventId: string;
85
- transactionId: string;
86
- action: {
87
- 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";
88
- createdAt: string;
89
- createdBy: string;
90
- declaration: Record<string, string | number | boolean | {
91
- type: string;
92
- filename: string;
93
- originalFilename: string;
94
- } | {
95
- country: string;
96
- district: string;
97
- addressType: "DOMESTIC";
98
- province: string;
99
- urbanOrRural: "URBAN";
100
- number?: string | null | undefined;
101
- town?: string | null | undefined;
102
- residentialArea?: string | null | undefined;
103
- street?: string | null | undefined;
104
- zipCode?: string | null | undefined;
105
- } | {
106
- country: string;
107
- district: string;
108
- addressType: "DOMESTIC";
109
- province: string;
110
- urbanOrRural: "RURAL";
111
- village?: string | null | undefined;
112
- } | {
113
- country: string;
114
- state: string;
115
- addressType: "INTERNATIONAL";
116
- district2: string;
117
- cityOrTown?: string | null | undefined;
118
- addressLine1?: string | null | undefined;
119
- addressLine2?: string | null | undefined;
120
- addressLine3?: string | null | undefined;
121
- postcodeOrZip?: string | null | undefined;
122
- } | {
123
- type: string;
124
- option: string;
125
- filename: string;
126
- originalFilename: string;
127
- }[] | undefined>;
128
- createdAtLocation: string;
129
- annotation?: Record<string, string | number | boolean | {
130
- type: string;
131
- filename: string;
132
- originalFilename: string;
133
- } | {
134
- country: string;
135
- district: string;
136
- addressType: "DOMESTIC";
137
- province: string;
138
- urbanOrRural: "URBAN";
139
- number?: string | null | undefined;
140
- town?: string | null | undefined;
141
- residentialArea?: string | null | undefined;
142
- street?: string | null | undefined;
143
- zipCode?: string | null | undefined;
144
- } | {
145
- country: string;
146
- district: string;
147
- addressType: "DOMESTIC";
148
- province: string;
149
- urbanOrRural: "RURAL";
150
- village?: string | null | undefined;
151
- } | {
152
- country: string;
153
- state: string;
154
- addressType: "INTERNATIONAL";
155
- district2: string;
156
- cityOrTown?: string | null | undefined;
157
- addressLine1?: string | null | undefined;
158
- addressLine2?: string | null | undefined;
159
- addressLine3?: string | null | undefined;
160
- postcodeOrZip?: string | null | undefined;
161
- } | {
162
- type: string;
163
- option: string;
164
- filename: string;
165
- originalFilename: string;
166
- }[] | undefined> | undefined;
167
- };
168
- }>;
62
+ actionType: ActionType;
63
+ }, input?: Partial<Draft>) => Draft;
169
64
  actions: {
170
65
  declare: (eventId: string, input?: Partial<Pick<DeclareActionInput, "transactionId" | "declaration" | "annotation">>) => {
171
66
  type: "DECLARE";
@@ -305,6 +200,20 @@ export declare const eventPayloadGenerator: {
305
200
  duplicates: never[];
306
201
  eventId: string;
307
202
  };
203
+ assign: (eventId: string, input?: Partial<Pick<AssignActionInput, "transactionId" | "assignedTo">>) => {
204
+ type: "ASSIGN";
205
+ transactionId: string;
206
+ declaration: {};
207
+ assignedTo: string;
208
+ eventId: string;
209
+ };
210
+ unassign: (eventId: string, input?: Partial<Pick<UnassignActionInput, "transactionId">>) => {
211
+ type: "UNASSIGN";
212
+ transactionId: string;
213
+ declaration: {};
214
+ assignedTo: null;
215
+ eventId: string;
216
+ };
308
217
  archive: (eventId: string, input?: Partial<Pick<ArchiveActionInput, "transactionId" | "declaration">>, isDuplicate?: boolean) => {
309
218
  type: "ARCHIVE";
310
219
  transactionId: string;
@@ -1,4 +1,4 @@
1
- import { ActionType, DeclarationAction } from './ActionType';
1
+ import { ActionType, DeclarationActionType } from './ActionType';
2
2
  import { EventConfig } from './EventConfig';
3
3
  import { FieldConfig } from './FieldConfig';
4
4
  import { WorkqueueConfig } from './WorkqueueConfig';
@@ -8,16 +8,6 @@ import { Draft } from './Draft';
8
8
  import { EventDocument } from './EventDocument';
9
9
  import { ActionConfig } from './ActionConfig';
10
10
  import { FormConfig } from './FormConfig';
11
- /**
12
- * @returns All the fields in the event configuration.
13
- */
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[];
17
- /**
18
- * @TODO: Request correction should have same format as print certificate
19
- */
20
- export declare const findRecordActionPages: (config: EventConfig, actionType: ActionType) => PageConfig[];
21
11
  export declare function getDeclarationFields(configuration: EventConfig): FieldConfig[];
22
12
  export declare function getDeclarationPages(configuration: EventConfig): {
23
13
  type: "FORM";
@@ -36,11 +26,21 @@ export declare function getDeclaration(configuration: EventConfig): {
36
26
  conditional?: import(".").JSONSchema | undefined;
37
27
  }[];
38
28
  };
39
- export declare function getActionReviewFields(configuration: EventConfig, actionType: DeclarationAction): import("./FieldConfig").Inferred[];
29
+ export declare const getActionAnnotationFields: (actionConfig: ActionConfig) => import("./FieldConfig").Inferred[];
30
+ export declare const getAllAnnotationFields: (config: EventConfig) => FieldConfig[];
31
+ /**
32
+ * @returns All the fields in the event configuration.
33
+ */
34
+ export declare const findAllFields: (config: EventConfig) => FieldConfig[];
35
+ /**
36
+ * @TODO: Request correction should have same format as print certificate
37
+ */
38
+ export declare const findRecordActionPages: (config: EventConfig, actionType: ActionType) => PageConfig[];
40
39
  export declare function getActionReview(configuration: EventConfig, actionType: ActionType): {
41
40
  title: import("./TranslationConfig").TranslationConfig;
42
41
  fields: import("./FieldConfig").Inferred[];
43
42
  };
43
+ export declare function getActionReviewFields(configuration: EventConfig, actionType: DeclarationActionType): import("./FieldConfig").Inferred[];
44
44
  export declare function validateWorkqueueConfig(workqueueConfigs: WorkqueueConfig[]): void;
45
45
  export declare function isPageVisible(page: PageConfig, formValues: ActionUpdate): boolean;
46
46
  export declare const getVisiblePagesFormFields: (formConfig: FormConfig, formData: ActionUpdate) => import("./FieldConfig").Inferred[];
@@ -89,6 +89,7 @@ export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]):
89
89
  transactionId: string;
90
90
  action: {
91
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
+ status: "Rejected" | "Requested" | "Accepted";
92
93
  createdAt: string;
93
94
  createdBy: string;
94
95
  declaration: Record<string, string | number | boolean | {
@@ -168,6 +169,7 @@ export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]):
168
169
  filename: string;
169
170
  originalFilename: string;
170
171
  }[] | undefined> | undefined;
172
+ originalActionId?: string | undefined;
171
173
  };
172
174
  }[];
173
175
  export declare function createEmptyDraft(eventId: string, draftId: string, actionType: ActionType): {
@@ -185,4 +187,42 @@ export declare function createEmptyDraft(eventId: string, draftId: string, actio
185
187
  };
186
188
  };
187
189
  export declare function isVerificationPage(page: PageConfig): page is VerificationPageConfig;
190
+ export declare function deepMerge(currentDocument: ActionUpdate, actionDocument: ActionUpdate): Record<string, string | number | boolean | {
191
+ type: string;
192
+ filename: string;
193
+ originalFilename: string;
194
+ } | {
195
+ country: string;
196
+ district: string;
197
+ addressType: "DOMESTIC";
198
+ province: string;
199
+ urbanOrRural: "URBAN";
200
+ number?: string | null | undefined;
201
+ town?: string | null | undefined;
202
+ residentialArea?: string | null | undefined;
203
+ street?: string | null | undefined;
204
+ zipCode?: string | null | undefined;
205
+ } | {
206
+ country: string;
207
+ district: string;
208
+ addressType: "DOMESTIC";
209
+ province: string;
210
+ urbanOrRural: "RURAL";
211
+ village?: string | null | undefined;
212
+ } | {
213
+ country: string;
214
+ state: string;
215
+ addressType: "INTERNATIONAL";
216
+ district2: string;
217
+ cityOrTown?: string | null | undefined;
218
+ addressLine1?: string | null | undefined;
219
+ addressLine2?: string | null | undefined;
220
+ addressLine3?: string | null | undefined;
221
+ postcodeOrZip?: string | null | undefined;
222
+ } | {
223
+ type: string;
224
+ option: string;
225
+ filename: string;
226
+ originalFilename: string;
227
+ }[] | undefined>;
188
228
  //# sourceMappingURL=utils.d.ts.map
@@ -23,8 +23,10 @@ __export(conditionals_exports, {
23
23
  alwaysTrue: () => alwaysTrue,
24
24
  and: () => and,
25
25
  defineConditional: () => defineConditional,
26
+ defineFormConditional: () => defineFormConditional,
26
27
  event: () => event,
27
28
  field: () => field,
29
+ never: () => never,
28
30
  not: () => not,
29
31
  or: () => or,
30
32
  user: () => user
@@ -35,6 +37,16 @@ module.exports = __toCommonJS(conditionals_exports);
35
37
  function defineConditional(schema) {
36
38
  return schema;
37
39
  }
40
+ function defineFormConditional(schema) {
41
+ const schemaWithForm = {
42
+ type: "object",
43
+ properties: {
44
+ $form: schema
45
+ },
46
+ required: ["$form"]
47
+ };
48
+ return defineConditional(schemaWithForm);
49
+ }
38
50
  function alwaysTrue() {
39
51
  return {};
40
52
  }
@@ -59,6 +71,9 @@ function not(condition) {
59
71
  required: []
60
72
  });
61
73
  }
74
+ function never() {
75
+ return not(alwaysTrue());
76
+ }
62
77
  var user = {
63
78
  hasScope: (scope) => defineConditional({
64
79
  type: "object",
@@ -106,69 +121,120 @@ var event = {
106
121
  required: ["$event"]
107
122
  })
108
123
  };
124
+ function getDateFromNow(days) {
125
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
126
+ }
127
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
128
+ return {
129
+ type: "object",
130
+ properties: {
131
+ [fieldId]: {
132
+ type: "string",
133
+ format: "date",
134
+ [clause]: { $data: `1/${comparedFieldId}` }
135
+ },
136
+ [comparedFieldId]: { type: "string", format: "date" }
137
+ },
138
+ required: [fieldId]
139
+ };
140
+ }
141
+ function isFieldReference(value) {
142
+ return typeof value === "object" && value !== null && "_fieldId" in value;
143
+ }
109
144
  function field(fieldId) {
110
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
111
145
  const getDateRange = (date, clause) => ({
112
146
  type: "object",
113
147
  properties: {
114
- $form: {
115
- type: "object",
116
- properties: {
117
- [fieldId]: {
118
- type: "string",
119
- format: "date",
120
- [clause]: date
121
- }
122
- },
123
- required: [fieldId]
148
+ [fieldId]: {
149
+ type: "string",
150
+ format: "date",
151
+ [clause]: date
124
152
  }
125
153
  },
126
- required: ["$form"]
154
+ required: [fieldId]
127
155
  });
128
156
  return {
157
+ /**
158
+ * @private Internal property used for field reference tracking.
159
+ */
160
+ _fieldId: fieldId,
129
161
  isAfter: () => ({
130
162
  days: (days) => ({
131
- inPast: () => defineConditional(
163
+ inPast: () => defineFormConditional(
132
164
  getDateRange(getDateFromNow(days), "formatMinimum")
133
165
  ),
134
- inFuture: () => defineConditional(
166
+ inFuture: () => defineFormConditional(
135
167
  getDateRange(getDateFromNow(-days), "formatMinimum")
136
168
  )
137
169
  }),
138
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
139
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
170
+ date: (date) => {
171
+ if (isFieldReference(date)) {
172
+ const comparedFieldId = date._fieldId;
173
+ return defineFormConditional(
174
+ getDateRangeToFieldReference(
175
+ fieldId,
176
+ comparedFieldId,
177
+ "formatMinimum"
178
+ )
179
+ );
180
+ }
181
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
182
+ },
183
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
140
184
  }),
141
185
  isBefore: () => ({
142
186
  days: (days) => ({
143
- inPast: () => defineConditional(
187
+ inPast: () => defineFormConditional(
144
188
  getDateRange(getDateFromNow(days), "formatMaximum")
145
189
  ),
146
- inFuture: () => defineConditional(
190
+ inFuture: () => defineFormConditional(
147
191
  getDateRange(getDateFromNow(-days), "formatMaximum")
148
192
  )
149
193
  }),
150
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
151
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
194
+ date: (date) => {
195
+ if (isFieldReference(date)) {
196
+ const comparedFieldId = date._fieldId;
197
+ return defineFormConditional(
198
+ getDateRangeToFieldReference(
199
+ fieldId,
200
+ comparedFieldId,
201
+ "formatMaximum"
202
+ )
203
+ );
204
+ }
205
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
206
+ },
207
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
152
208
  }),
153
- isEqualTo: (value) => defineConditional({
154
- type: "object",
155
- properties: {
156
- $form: {
209
+ isEqualTo: (value) => {
210
+ if (isFieldReference(value)) {
211
+ const comparedFieldId = value._fieldId;
212
+ return defineFormConditional({
157
213
  type: "object",
158
214
  properties: {
159
215
  [fieldId]: {
160
- oneOf: [
161
- { type: "string", const: value },
162
- { type: "boolean", const: value }
163
- ],
164
- const: value
165
- }
216
+ type: ["string", "boolean"],
217
+ const: { $data: `1/${comparedFieldId}` }
218
+ },
219
+ [comparedFieldId]: { type: ["string", "boolean"] }
166
220
  },
167
- required: [fieldId]
168
- }
169
- },
170
- required: ["$form"]
171
- }),
221
+ required: [fieldId, comparedFieldId]
222
+ });
223
+ }
224
+ return defineFormConditional({
225
+ type: "object",
226
+ properties: {
227
+ [fieldId]: {
228
+ oneOf: [
229
+ { type: "string", const: value },
230
+ { type: "boolean", const: value }
231
+ ],
232
+ const: value
233
+ }
234
+ },
235
+ required: [fieldId]
236
+ });
237
+ },
172
238
  /**
173
239
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
174
240
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -177,123 +243,87 @@ function field(fieldId) {
177
243
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
178
244
  *
179
245
  */
180
- isFalsy: () => defineConditional({
246
+ isFalsy: () => defineFormConditional({
181
247
  type: "object",
182
248
  properties: {
183
- $form: {
184
- type: "object",
185
- properties: {
186
- [fieldId]: {
187
- anyOf: [
188
- { const: "undefined" },
189
- { const: false },
190
- { const: null },
191
- { const: "" }
192
- ]
193
- }
194
- },
249
+ [fieldId]: {
195
250
  anyOf: [
196
- {
197
- required: [fieldId]
198
- },
199
- {
200
- not: {
201
- required: [fieldId]
202
- }
203
- }
251
+ { const: "undefined" },
252
+ { const: false },
253
+ { const: null },
254
+ { const: "" }
204
255
  ]
205
256
  }
206
257
  },
207
- required: ["$form"]
208
- }),
209
- isUndefined: () => defineConditional({
210
- type: "object",
211
- properties: {
212
- $form: {
213
- type: "object",
214
- properties: {
215
- [fieldId]: {
216
- type: "string",
217
- enum: ["undefined"]
218
- }
219
- },
258
+ anyOf: [
259
+ {
260
+ required: [fieldId]
261
+ },
262
+ {
220
263
  not: {
221
264
  required: [fieldId]
222
265
  }
223
266
  }
267
+ ]
268
+ }),
269
+ isUndefined: () => defineFormConditional({
270
+ type: "object",
271
+ properties: {
272
+ [fieldId]: {
273
+ type: "string",
274
+ enum: ["undefined"]
275
+ }
224
276
  },
225
- required: ["$form"]
277
+ not: {
278
+ required: [fieldId]
279
+ }
226
280
  }),
227
- inArray: (values) => defineConditional({
281
+ inArray: (values) => defineFormConditional({
228
282
  type: "object",
229
283
  properties: {
230
- $form: {
231
- type: "object",
232
- properties: {
233
- [fieldId]: {
234
- type: "string",
235
- enum: values
236
- }
237
- },
238
- required: [fieldId]
284
+ [fieldId]: {
285
+ type: "string",
286
+ enum: values
239
287
  }
240
288
  },
241
- required: ["$form"]
289
+ required: [fieldId]
242
290
  }),
243
- isValidEnglishName: () => defineConditional({
291
+ isValidEnglishName: () => defineFormConditional({
244
292
  type: "object",
245
293
  properties: {
246
- $form: {
247
- type: "object",
248
- properties: {
249
- [fieldId]: {
250
- type: "string",
251
- 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'._-]*)*$",
252
- description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
253
- }
254
- },
255
- required: [fieldId]
294
+ [fieldId]: {
295
+ type: "string",
296
+ 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'._-]*)*$",
297
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
256
298
  }
257
299
  },
258
- required: ["$form"]
300
+ required: [fieldId]
259
301
  }),
260
302
  /**
261
303
  * Checks if the field value matches a given regular expression pattern.
262
304
  * @param pattern - The regular expression pattern to match the field value against.
263
305
  * @returns A JSONSchema conditional that validates the field value against the pattern.
264
306
  */
265
- matches: (pattern) => defineConditional({
307
+ matches: (pattern) => defineFormConditional({
266
308
  type: "object",
267
309
  properties: {
268
- $form: {
269
- type: "object",
270
- properties: {
271
- [fieldId]: {
272
- type: "string",
273
- pattern
274
- }
275
- },
276
- required: [fieldId]
310
+ [fieldId]: {
311
+ type: "string",
312
+ pattern
277
313
  }
278
314
  },
279
- required: ["$form"]
315
+ required: [fieldId]
280
316
  }),
281
- isBetween: (min, max) => defineConditional({
317
+ isBetween: (min, max) => defineFormConditional({
282
318
  type: "object",
283
319
  properties: {
284
- $form: {
285
- type: "object",
286
- properties: {
287
- [fieldId]: {
288
- type: "number",
289
- minimum: min,
290
- maximum: max
291
- }
292
- },
293
- required: [fieldId]
320
+ [fieldId]: {
321
+ type: "number",
322
+ minimum: min,
323
+ maximum: max
294
324
  }
295
325
  },
296
- required: ["$form"]
326
+ required: [fieldId]
297
327
  })
298
328
  };
299
329
  }