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

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.
@@ -1,23 +1,12 @@
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
- import { WorkqueueConfig } from './WorkqueueConfig';
5
- import { ActionUpdate, EventState } from './ActionDocument';
4
+ import { Action, ActionUpdate, EventState } from './ActionDocument';
6
5
  import { PageConfig, VerificationPageConfig } from './PageConfig';
7
6
  import { Draft } from './Draft';
8
7
  import { EventDocument } from './EventDocument';
9
8
  import { ActionConfig } from './ActionConfig';
10
9
  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
10
  export declare function getDeclarationFields(configuration: EventConfig): FieldConfig[];
22
11
  export declare function getDeclarationPages(configuration: EventConfig): {
23
12
  type: "FORM";
@@ -36,15 +25,61 @@ export declare function getDeclaration(configuration: EventConfig): {
36
25
  conditional?: import(".").JSONSchema | undefined;
37
26
  }[];
38
27
  };
39
- export declare function getActionReviewFields(configuration: EventConfig, actionType: DeclarationAction): import("./FieldConfig").Inferred[];
28
+ export declare const getActionAnnotationFields: (actionConfig: ActionConfig) => import("./FieldConfig").Inferred[];
29
+ export declare const getAllAnnotationFields: (config: EventConfig) => FieldConfig[];
30
+ /**
31
+ * @returns All the fields in the event configuration.
32
+ */
33
+ export declare const findAllFields: (config: EventConfig) => FieldConfig[];
34
+ /**
35
+ * @TODO: Request correction should have same format as print certificate
36
+ */
37
+ export declare const findRecordActionPages: (config: EventConfig, actionType: ActionType) => PageConfig[];
40
38
  export declare function getActionReview(configuration: EventConfig, actionType: ActionType): {
41
39
  title: import("./TranslationConfig").TranslationConfig;
42
40
  fields: import("./FieldConfig").Inferred[];
43
41
  };
44
- export declare function validateWorkqueueConfig(workqueueConfigs: WorkqueueConfig[]): void;
42
+ export declare function getActionReviewFields(configuration: EventConfig, actionType: DeclarationActionType): import("./FieldConfig").Inferred[];
45
43
  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 | {
44
+ export declare function omitHiddenFields(fields: FieldConfig[], values: EventState): import("lodash").Dictionary<string | number | boolean | {
45
+ type: string;
46
+ filename: string;
47
+ originalFilename: string;
48
+ } | {
49
+ country: string;
50
+ district: string;
51
+ addressType: "DOMESTIC";
52
+ province: string;
53
+ urbanOrRural: "URBAN";
54
+ number?: string | undefined;
55
+ town?: string | undefined;
56
+ residentialArea?: string | undefined;
57
+ street?: string | undefined;
58
+ zipCode?: string | undefined;
59
+ } | {
60
+ country: string;
61
+ district: string;
62
+ addressType: "DOMESTIC";
63
+ province: string;
64
+ urbanOrRural: "RURAL";
65
+ village?: string | undefined;
66
+ } | {
67
+ country: string;
68
+ state: string;
69
+ addressType: "INTERNATIONAL";
70
+ district2: string;
71
+ cityOrTown?: string | undefined;
72
+ addressLine1?: string | undefined;
73
+ addressLine2?: string | undefined;
74
+ addressLine3?: string | undefined;
75
+ postcodeOrZip?: string | undefined;
76
+ } | {
77
+ type: string;
78
+ option: string;
79
+ filename: string;
80
+ originalFilename: string;
81
+ }[] | undefined>;
82
+ export declare function omitHiddenPaginatedFields(formConfig: FormConfig, declaration: EventState): import("lodash").Dictionary<string | number | boolean | {
48
83
  type: string;
49
84
  filename: string;
50
85
  originalFilename: string;
@@ -84,13 +119,16 @@ export declare function stripHiddenFields(fields: FieldConfig[], declaration: Ev
84
119
  }[] | undefined>;
85
120
  export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]): {
86
121
  id: string;
122
+ transactionId: string;
87
123
  createdAt: string;
88
124
  eventId: string;
89
- transactionId: string;
90
125
  action: {
91
126
  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";
127
+ status: "Rejected" | "Requested" | "Accepted";
128
+ transactionId: string;
92
129
  createdAt: string;
93
130
  createdBy: string;
131
+ createdByRole: string;
94
132
  declaration: Record<string, string | number | boolean | {
95
133
  type: string;
96
134
  filename: string;
@@ -186,42 +224,13 @@ export declare function createEmptyDraft(eventId: string, draftId: string, actio
186
224
  };
187
225
  };
188
226
  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>;
227
+ export declare function deepMerge<T extends Record<string, unknown>>(currentDocument: T, actionDocument: T): T;
228
+ export declare function findLastAssignmentAction(actions: Action[]): Action | undefined;
229
+ /** Tell compiler that accessing record with arbitrary key might result to undefined
230
+ * Use when you **cannot guarantee** that key exists in the record
231
+ */
232
+ export type IndexMap<T> = {
233
+ [id: string]: T | undefined;
234
+ };
235
+ export declare function isWriteAction(actionType: ActionType): boolean;
227
236
  //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utils.test.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,100 +121,118 @@ 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 {
129
157
  /**
130
158
  * @private Internal property used for field reference tracking.
131
159
  */
132
- _returning: fieldId,
160
+ _fieldId: fieldId,
133
161
  isAfter: () => ({
134
162
  days: (days) => ({
135
- inPast: () => defineConditional(
163
+ inPast: () => defineFormConditional(
136
164
  getDateRange(getDateFromNow(days), "formatMinimum")
137
165
  ),
138
- inFuture: () => defineConditional(
166
+ inFuture: () => defineFormConditional(
139
167
  getDateRange(getDateFromNow(-days), "formatMinimum")
140
168
  )
141
169
  }),
142
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
143
- 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"))
144
184
  }),
145
185
  isBefore: () => ({
146
186
  days: (days) => ({
147
- inPast: () => defineConditional(
187
+ inPast: () => defineFormConditional(
148
188
  getDateRange(getDateFromNow(days), "formatMaximum")
149
189
  ),
150
- inFuture: () => defineConditional(
190
+ inFuture: () => defineFormConditional(
151
191
  getDateRange(getDateFromNow(-days), "formatMaximum")
152
192
  )
153
193
  }),
154
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
155
- 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"))
156
208
  }),
157
- // TODO CIHAN: typing
158
209
  isEqualTo: (value) => {
159
- if (typeof value === "object" && value._returning) {
160
- const comparedFieldId = value._returning;
161
- return defineConditional({
210
+ if (isFieldReference(value)) {
211
+ const comparedFieldId = value._fieldId;
212
+ return defineFormConditional({
162
213
  type: "object",
163
214
  properties: {
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
- ]
180
- }
215
+ [fieldId]: {
216
+ type: ["string", "boolean"],
217
+ const: { $data: `1/${comparedFieldId}` }
218
+ },
219
+ [comparedFieldId]: { type: ["string", "boolean"] }
181
220
  },
182
- required: ["$form"]
221
+ required: [fieldId, comparedFieldId]
183
222
  });
184
223
  }
185
- return defineConditional({
224
+ return defineFormConditional({
186
225
  type: "object",
187
226
  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]
227
+ [fieldId]: {
228
+ oneOf: [
229
+ { type: "string", const: value },
230
+ { type: "boolean", const: value }
231
+ ],
232
+ const: value
200
233
  }
201
234
  },
202
- required: ["$form"]
235
+ required: [fieldId]
203
236
  });
204
237
  },
205
238
  /**
@@ -210,140 +243,87 @@ function field(fieldId) {
210
243
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
211
244
  *
212
245
  */
213
- isFalsy: () => defineConditional({
246
+ isFalsy: () => defineFormConditional({
214
247
  type: "object",
215
248
  properties: {
216
- $form: {
217
- type: "object",
218
- properties: {
219
- [fieldId]: {
220
- anyOf: [
221
- { const: "undefined" },
222
- { const: false },
223
- { const: null },
224
- { const: "" }
225
- ]
226
- }
227
- },
249
+ [fieldId]: {
228
250
  anyOf: [
229
- {
230
- required: [fieldId]
231
- },
232
- {
233
- not: {
234
- required: [fieldId]
235
- }
236
- }
251
+ { const: "undefined" },
252
+ { const: false },
253
+ { const: null },
254
+ { const: "" }
237
255
  ]
238
256
  }
239
257
  },
240
- required: ["$form"]
241
- }),
242
- isUndefined: () => defineConditional({
243
- type: "object",
244
- properties: {
245
- $form: {
246
- type: "object",
247
- properties: {
248
- [fieldId]: {
249
- type: "string",
250
- enum: ["undefined"]
251
- }
252
- },
258
+ anyOf: [
259
+ {
260
+ required: [fieldId]
261
+ },
262
+ {
253
263
  not: {
254
264
  required: [fieldId]
255
265
  }
256
266
  }
257
- },
258
- required: ["$form"]
267
+ ]
259
268
  }),
260
- inArray: (values) => defineConditional({
269
+ isUndefined: () => defineFormConditional({
261
270
  type: "object",
262
271
  properties: {
263
- $form: {
264
- type: "object",
265
- properties: {
266
- [fieldId]: {
267
- type: "string",
268
- enum: values
269
- }
270
- },
271
- required: [fieldId]
272
+ [fieldId]: {
273
+ type: "string",
274
+ enum: ["undefined"]
272
275
  }
273
276
  },
274
- required: ["$form"]
277
+ not: {
278
+ required: [fieldId]
279
+ }
275
280
  }),
276
- isValidEnglishName: () => defineConditional({
281
+ inArray: (values) => defineFormConditional({
277
282
  type: "object",
278
283
  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]
284
+ [fieldId]: {
285
+ type: "string",
286
+ enum: values
289
287
  }
290
288
  },
291
- required: ["$form"]
289
+ required: [fieldId]
292
290
  }),
293
- isValidNationalId: () => defineConditional({
291
+ isValidEnglishName: () => defineFormConditional({
294
292
  type: "object",
295
293
  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]
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."
306
298
  }
307
299
  },
308
- required: ["$form"]
300
+ required: [fieldId]
309
301
  }),
310
302
  /**
311
303
  * Checks if the field value matches a given regular expression pattern.
312
304
  * @param pattern - The regular expression pattern to match the field value against.
313
305
  * @returns A JSONSchema conditional that validates the field value against the pattern.
314
306
  */
315
- matches: (pattern) => defineConditional({
307
+ matches: (pattern) => defineFormConditional({
316
308
  type: "object",
317
309
  properties: {
318
- $form: {
319
- type: "object",
320
- properties: {
321
- [fieldId]: {
322
- type: "string",
323
- pattern
324
- }
325
- },
326
- required: [fieldId]
310
+ [fieldId]: {
311
+ type: "string",
312
+ pattern
327
313
  }
328
314
  },
329
- required: ["$form"]
315
+ required: [fieldId]
330
316
  }),
331
- isBetween: (min, max) => defineConditional({
317
+ isBetween: (min, max) => defineFormConditional({
332
318
  type: "object",
333
319
  properties: {
334
- $form: {
335
- type: "object",
336
- properties: {
337
- [fieldId]: {
338
- type: "number",
339
- minimum: min,
340
- maximum: max
341
- }
342
- },
343
- required: [fieldId]
320
+ [fieldId]: {
321
+ type: "number",
322
+ minimum: min,
323
+ maximum: max
344
324
  }
345
325
  },
346
- required: ["$form"]
326
+ required: [fieldId]
347
327
  })
348
328
  };
349
329
  }