@ecrvs/opencrvs-toolkit 1.8.1-rc.a7ee8fb
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.
- package/README.md +70 -0
- package/build.sh +56 -0
- package/dist/api/index.d.ts +11 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +52 -0
- package/dist/commons/api/router.d.ts +14568 -0
- package/dist/commons/conditionals/conditionals.d.ts +194 -0
- package/dist/commons/conditionals/index.d.ts +2 -0
- package/dist/commons/conditionals/validate.d.ts +129 -0
- package/dist/commons/events/ActionConfig.d.ts +2034 -0
- package/dist/commons/events/ActionDocument.d.ts +14400 -0
- package/dist/commons/events/ActionInput.d.ts +11157 -0
- package/dist/commons/events/ActionType.d.ts +52 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +1175 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +181 -0
- package/dist/commons/events/Conditional.d.ts +55 -0
- package/dist/commons/events/Constants.d.ts +3 -0
- package/dist/commons/events/CountryConfigQueryInput.d.ts +4494 -0
- package/dist/commons/events/CreatedAtLocation.d.ts +2 -0
- package/dist/commons/events/DeduplicationConfig.d.ts +209 -0
- package/dist/commons/events/Draft.d.ts +814 -0
- package/dist/commons/events/EventConfig.d.ts +2237 -0
- package/dist/commons/events/EventConfigInput.d.ts +10 -0
- package/dist/commons/events/EventDocument.d.ts +8505 -0
- package/dist/commons/events/EventIndex.d.ts +3858 -0
- package/dist/commons/events/EventInput.d.ts +13 -0
- package/dist/commons/events/EventMetadata.d.ts +408 -0
- package/dist/commons/events/FieldConfig.d.ts +7125 -0
- package/dist/commons/events/FieldType.d.ts +46 -0
- package/dist/commons/events/FieldTypeMapping.d.ts +537 -0
- package/dist/commons/events/FieldValue.d.ts +250 -0
- package/dist/commons/events/FileUtils.d.ts +4 -0
- package/dist/commons/events/FormConfig.d.ts +725 -0
- package/dist/commons/events/PageConfig.d.ts +336 -0
- package/dist/commons/events/SummaryConfig.d.ts +170 -0
- package/dist/commons/events/TemplateConfig.d.ts +38 -0
- package/dist/commons/events/TranslationConfig.d.ts +15 -0
- package/dist/commons/events/User.d.ts +45 -0
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +53 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +8997 -0
- package/dist/commons/events/deduplication.d.ts +32 -0
- package/dist/commons/events/defineConfig.d.ts +309 -0
- package/dist/commons/events/event.d.ts +109 -0
- package/dist/commons/events/field.d.ts +151 -0
- package/dist/commons/events/index.d.ts +46 -0
- package/dist/commons/events/locations.d.ts +24 -0
- package/dist/commons/events/scopes.d.ts +55 -0
- package/dist/commons/events/serializer.d.ts +2 -0
- package/dist/commons/events/state/availableActions.d.ts +6 -0
- package/dist/commons/events/state/flags.d.ts +4 -0
- package/dist/commons/events/state/index.d.ts +146 -0
- package/dist/commons/events/state/utils.d.ts +1263 -0
- package/dist/commons/events/test.utils.d.ts +473 -0
- package/dist/commons/events/transactions.d.ts +2 -0
- package/dist/commons/events/utils.d.ts +501 -0
- package/dist/commons/events/workqueueDefaultColumns.d.ts +3 -0
- package/dist/commons/notification/UserNotifications.d.ts +632 -0
- package/dist/commons/notification/index.d.ts +2 -0
- package/dist/conditionals/index.d.ts +2 -0
- package/dist/conditionals/index.d.ts.map +1 -0
- package/dist/conditionals/index.js +491 -0
- package/dist/events/deduplication.d.ts +32 -0
- package/dist/events/deduplication.d.ts.map +1 -0
- package/dist/events/deduplication.js +67 -0
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +8383 -0
- package/dist/notification/index.d.ts +2 -0
- package/dist/notification/index.d.ts.map +1 -0
- package/dist/notification/index.js +5928 -0
- package/dist/scopes/index.d.ts +335 -0
- package/dist/scopes/index.d.ts.map +1 -0
- package/dist/scopes/index.js +379 -0
- package/package.json +40 -0
- package/tsconfig.json +27 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { EventDocument } from '../events/EventDocument';
|
|
2
|
+
import { EventState } from '../events/ActionDocument';
|
|
3
|
+
import { ITokenPayload as TokenPayload, Scope } from '../authentication';
|
|
4
|
+
import { PartialSchema as AjvJSONSchemaType } from 'ajv/dist/types/json-schema';
|
|
5
|
+
import { userSerializer } from '../events/serializers/user/serializer';
|
|
6
|
+
import { UUID } from '../uuid';
|
|
7
|
+
/** @knipignore */
|
|
8
|
+
export type JSONSchema = {
|
|
9
|
+
$id: string;
|
|
10
|
+
readonly __nominal__type: 'JSONSchema';
|
|
11
|
+
};
|
|
12
|
+
export declare function defineConditional(schema: any): JSONSchema;
|
|
13
|
+
export declare function defineFormConditional(schema: Record<string, unknown>): JSONSchema;
|
|
14
|
+
export type UserConditionalParameters = {
|
|
15
|
+
$now: string;
|
|
16
|
+
$online: boolean;
|
|
17
|
+
$user: TokenPayload;
|
|
18
|
+
};
|
|
19
|
+
export type EventConditionalParameters = {
|
|
20
|
+
$now: string;
|
|
21
|
+
$online: boolean;
|
|
22
|
+
$event: EventDocument;
|
|
23
|
+
};
|
|
24
|
+
export type FormConditionalParameters = {
|
|
25
|
+
$now: string;
|
|
26
|
+
$online: boolean;
|
|
27
|
+
$form: EventState | Record<string, any>;
|
|
28
|
+
$locations?: Array<{
|
|
29
|
+
id: UUID;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
export type ConditionalParameters = UserConditionalParameters | EventConditionalParameters | FormConditionalParameters;
|
|
33
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
34
|
+
type AjvJSONSchema = AjvJSONSchemaType<UnionToIntersection<ConditionalParameters>>;
|
|
35
|
+
/**
|
|
36
|
+
* Returns an empty JSON Schema object, which is treated as always valid.
|
|
37
|
+
*
|
|
38
|
+
* @returns {AjvJSONSchema} An empty schema object `{}` that always evaluates to true.
|
|
39
|
+
*/
|
|
40
|
+
export declare function alwaysTrue(): AjvJSONSchema;
|
|
41
|
+
/**
|
|
42
|
+
* Universal boolean connector to be used with any type of conditional. (user, event, field)
|
|
43
|
+
*
|
|
44
|
+
* @example and(field('foo').isEqualTo('bar'), field('baz').isUndefined())
|
|
45
|
+
*/
|
|
46
|
+
export declare function and(...conditions: AjvJSONSchema[]): JSONSchema;
|
|
47
|
+
/**
|
|
48
|
+
* Universal boolean connector to be used with any type of conditional. (user, event, field)
|
|
49
|
+
*
|
|
50
|
+
* @example or(field('foo').isEqualTo('bar'), field('baz').isUndefined())
|
|
51
|
+
*/
|
|
52
|
+
export declare function or(...conditions: AjvJSONSchema[]): JSONSchema;
|
|
53
|
+
/**
|
|
54
|
+
* Universal boolean connector to be used with any type of conditional. (user, event, field)
|
|
55
|
+
*
|
|
56
|
+
* @example not(field('foo').isEqualTo('bar'))
|
|
57
|
+
*/
|
|
58
|
+
export declare function not(condition: AjvJSONSchema): JSONSchema;
|
|
59
|
+
/**
|
|
60
|
+
* Returns an JSON Schema object, which is treated as always invalid.
|
|
61
|
+
*
|
|
62
|
+
* @returns {JSONSchema} An schema object that always evaluates to false.
|
|
63
|
+
*/
|
|
64
|
+
export declare function never(): JSONSchema;
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* Generate conditional rules for user.
|
|
68
|
+
*/
|
|
69
|
+
export declare const user: typeof userSerializer & {
|
|
70
|
+
hasScope: (scope: Scope) => JSONSchema;
|
|
71
|
+
isOnline: () => JSONSchema;
|
|
72
|
+
locationLevel: (adminLevelId: string) => {
|
|
73
|
+
$user: {
|
|
74
|
+
$location: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
type FieldReference = {
|
|
79
|
+
$$field: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Generate conditional rules for a form field.
|
|
83
|
+
*
|
|
84
|
+
* @param fieldId - The field ID condition is applied to.
|
|
85
|
+
* @example to combine multiple conditions, utilise connectors like `and`, `or`, `not`:
|
|
86
|
+
* and(field('foo').isEqualTo('bar'), field('baz').isUndefined())
|
|
87
|
+
*
|
|
88
|
+
*/
|
|
89
|
+
export declare function createFieldConditionals(fieldId: string): {
|
|
90
|
+
/**
|
|
91
|
+
* @private Internal property used for field reference tracking.
|
|
92
|
+
*/
|
|
93
|
+
$$field: string;
|
|
94
|
+
/**
|
|
95
|
+
* @private Internal property used for solving a object path within field's value
|
|
96
|
+
*/
|
|
97
|
+
$$subfield: string[];
|
|
98
|
+
get(fieldPath: string): {
|
|
99
|
+
$$subfield: string[];
|
|
100
|
+
/**
|
|
101
|
+
* @private Internal property used for field reference tracking.
|
|
102
|
+
*/
|
|
103
|
+
$$field: string;
|
|
104
|
+
get(fieldPath: string): any;
|
|
105
|
+
isAfter: () => {
|
|
106
|
+
days: (days: number) => {
|
|
107
|
+
inPast: () => JSONSchema;
|
|
108
|
+
inFuture: () => JSONSchema;
|
|
109
|
+
};
|
|
110
|
+
date: (date: string | FieldReference) => JSONSchema;
|
|
111
|
+
now: () => JSONSchema;
|
|
112
|
+
};
|
|
113
|
+
isBefore: () => {
|
|
114
|
+
days: (days: number) => {
|
|
115
|
+
inPast: () => JSONSchema;
|
|
116
|
+
inFuture: () => JSONSchema;
|
|
117
|
+
};
|
|
118
|
+
date: (date: `${string}-${string}-${string}` | FieldReference) => JSONSchema;
|
|
119
|
+
now: () => JSONSchema;
|
|
120
|
+
};
|
|
121
|
+
isGreaterThan: (value: number | FieldReference) => JSONSchema;
|
|
122
|
+
isLessThan: (value: number | FieldReference) => JSONSchema;
|
|
123
|
+
isEqualTo(value: string | boolean | FieldReference): JSONSchema;
|
|
124
|
+
/**
|
|
125
|
+
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
|
126
|
+
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|
|
127
|
+
* @returns whether the field is falsy (undefined, false, null, empty string)
|
|
128
|
+
*
|
|
129
|
+
* NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
isFalsy(): JSONSchema;
|
|
133
|
+
isUndefined(): JSONSchema;
|
|
134
|
+
inArray: (values: string[]) => JSONSchema;
|
|
135
|
+
isValidEnglishName: () => JSONSchema;
|
|
136
|
+
isValidAdministrativeLeafLevel: () => JSONSchema;
|
|
137
|
+
/**
|
|
138
|
+
* Checks if the field value matches a given regular expression pattern.
|
|
139
|
+
* @param pattern - The regular expression pattern to match the field value against.
|
|
140
|
+
* @returns A JSONSchema conditional that validates the field value against the pattern.
|
|
141
|
+
*/
|
|
142
|
+
matches: (pattern: string) => JSONSchema;
|
|
143
|
+
isBetween: (min: number, max: number) => JSONSchema;
|
|
144
|
+
getId: () => {
|
|
145
|
+
fieldId: string;
|
|
146
|
+
};
|
|
147
|
+
object: (options: Record<string, any>) => JSONSchema;
|
|
148
|
+
};
|
|
149
|
+
isAfter: () => {
|
|
150
|
+
days: (days: number) => {
|
|
151
|
+
inPast: () => JSONSchema;
|
|
152
|
+
inFuture: () => JSONSchema;
|
|
153
|
+
};
|
|
154
|
+
date: (date: string | FieldReference) => JSONSchema;
|
|
155
|
+
now: () => JSONSchema;
|
|
156
|
+
};
|
|
157
|
+
isBefore: () => {
|
|
158
|
+
days: (days: number) => {
|
|
159
|
+
inPast: () => JSONSchema;
|
|
160
|
+
inFuture: () => JSONSchema;
|
|
161
|
+
};
|
|
162
|
+
date: (date: `${string}-${string}-${string}` | FieldReference) => JSONSchema;
|
|
163
|
+
now: () => JSONSchema;
|
|
164
|
+
};
|
|
165
|
+
isGreaterThan: (value: number | FieldReference) => JSONSchema;
|
|
166
|
+
isLessThan: (value: number | FieldReference) => JSONSchema;
|
|
167
|
+
isEqualTo(value: string | boolean | FieldReference): JSONSchema;
|
|
168
|
+
/**
|
|
169
|
+
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
|
170
|
+
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|
|
171
|
+
* @returns whether the field is falsy (undefined, false, null, empty string)
|
|
172
|
+
*
|
|
173
|
+
* NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
|
|
174
|
+
*
|
|
175
|
+
*/
|
|
176
|
+
isFalsy(): JSONSchema;
|
|
177
|
+
isUndefined(): JSONSchema;
|
|
178
|
+
inArray: (values: string[]) => JSONSchema;
|
|
179
|
+
isValidEnglishName: () => JSONSchema;
|
|
180
|
+
isValidAdministrativeLeafLevel: () => JSONSchema;
|
|
181
|
+
/**
|
|
182
|
+
* Checks if the field value matches a given regular expression pattern.
|
|
183
|
+
* @param pattern - The regular expression pattern to match the field value against.
|
|
184
|
+
* @returns A JSONSchema conditional that validates the field value against the pattern.
|
|
185
|
+
*/
|
|
186
|
+
matches: (pattern: string) => JSONSchema;
|
|
187
|
+
isBetween: (min: number, max: number) => JSONSchema;
|
|
188
|
+
getId: () => {
|
|
189
|
+
fieldId: string;
|
|
190
|
+
};
|
|
191
|
+
object: (options: Record<string, any>) => JSONSchema;
|
|
192
|
+
};
|
|
193
|
+
export {};
|
|
194
|
+
//# sourceMappingURL=conditionals.d.ts.map
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ConditionalParameters, JSONSchema } from './conditionals';
|
|
2
|
+
import { ActionUpdate, EventState } from '../events/ActionDocument';
|
|
3
|
+
import { FieldConditional } from '../events/Conditional';
|
|
4
|
+
import { FieldConfig } from '../events/FieldConfig';
|
|
5
|
+
import { FieldUpdateValue } from '../events/FieldValue';
|
|
6
|
+
import { TranslationConfig } from '../events/TranslationConfig';
|
|
7
|
+
import { UUID } from '../uuid';
|
|
8
|
+
export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean;
|
|
9
|
+
export declare function isOnline(): boolean;
|
|
10
|
+
export declare function isConditionMet(conditional: JSONSchema, values: Record<string, unknown>): boolean;
|
|
11
|
+
export declare function areConditionsMet(conditions: FieldConditional[], values: Record<string, unknown>): boolean;
|
|
12
|
+
export declare function isFieldVisible(field: FieldConfig, form: ActionUpdate | EventState): boolean;
|
|
13
|
+
export declare function getOnlyVisibleFormValues(field: FieldConfig[], form: EventState): Record<string, string | number | boolean | {
|
|
14
|
+
type: string;
|
|
15
|
+
path: string;
|
|
16
|
+
originalFilename: string;
|
|
17
|
+
} | {
|
|
18
|
+
firstname: string;
|
|
19
|
+
surname: string;
|
|
20
|
+
middlename?: string | undefined;
|
|
21
|
+
} | {
|
|
22
|
+
firstname: string;
|
|
23
|
+
surname: string;
|
|
24
|
+
middlename?: string | null | undefined;
|
|
25
|
+
} | Record<string, string> | {
|
|
26
|
+
country: string;
|
|
27
|
+
addressType: "DOMESTIC" | "INTERNATIONAL";
|
|
28
|
+
administrativeArea?: string | undefined;
|
|
29
|
+
streetLevelDetails?: Record<string, string> | undefined;
|
|
30
|
+
} | {
|
|
31
|
+
type: string;
|
|
32
|
+
option: string;
|
|
33
|
+
path: string;
|
|
34
|
+
originalFilename: string;
|
|
35
|
+
}[] | {
|
|
36
|
+
loading: boolean;
|
|
37
|
+
data?: any;
|
|
38
|
+
error?: {
|
|
39
|
+
message: string;
|
|
40
|
+
statusCode: number;
|
|
41
|
+
} | null | undefined;
|
|
42
|
+
} | {
|
|
43
|
+
start: string;
|
|
44
|
+
end: string;
|
|
45
|
+
} | null | undefined>;
|
|
46
|
+
export declare function isFieldEnabled(field: FieldConfig, form: ActionUpdate | EventState): boolean;
|
|
47
|
+
export declare function isFieldDisplayedOnReview(field: FieldConfig, form: ActionUpdate | EventState): boolean;
|
|
48
|
+
export declare const errorMessages: {
|
|
49
|
+
hiddenField: {
|
|
50
|
+
id: string;
|
|
51
|
+
defaultMessage: string;
|
|
52
|
+
description: string;
|
|
53
|
+
};
|
|
54
|
+
invalidDate: {
|
|
55
|
+
defaultMessage: string;
|
|
56
|
+
description: string;
|
|
57
|
+
id: string;
|
|
58
|
+
};
|
|
59
|
+
invalidEmail: {
|
|
60
|
+
defaultMessage: string;
|
|
61
|
+
description: string;
|
|
62
|
+
id: string;
|
|
63
|
+
};
|
|
64
|
+
requiredField: {
|
|
65
|
+
defaultMessage: string;
|
|
66
|
+
description: string;
|
|
67
|
+
id: string;
|
|
68
|
+
};
|
|
69
|
+
invalidInput: {
|
|
70
|
+
defaultMessage: string;
|
|
71
|
+
description: string;
|
|
72
|
+
id: string;
|
|
73
|
+
};
|
|
74
|
+
unexpectedField: {
|
|
75
|
+
defaultMessage: string;
|
|
76
|
+
description: string;
|
|
77
|
+
id: string;
|
|
78
|
+
};
|
|
79
|
+
correctionNotAllowed: {
|
|
80
|
+
defaultMessage: string;
|
|
81
|
+
description: string;
|
|
82
|
+
id: string;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Custom error map for Zod to override the default error messages in intl-formik format.
|
|
87
|
+
*/
|
|
88
|
+
export type CustomZodToIntlErrorMap = {
|
|
89
|
+
/** Zod by default expects { message: string } */
|
|
90
|
+
message: {
|
|
91
|
+
/** Override it to match current intl-formik model */
|
|
92
|
+
message: TranslationConfig;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Validates primitive fields defined by the FieldConfig type.
|
|
97
|
+
* e.g. email is proper format, date is a valid date, etc.
|
|
98
|
+
* for custom validations @see runCustomFieldValidations
|
|
99
|
+
*/
|
|
100
|
+
export declare function validateFieldInput({ field, value }: {
|
|
101
|
+
field: FieldConfig;
|
|
102
|
+
value: FieldUpdateValue;
|
|
103
|
+
}): {
|
|
104
|
+
message: TranslationConfig;
|
|
105
|
+
}[];
|
|
106
|
+
export declare function runStructuralValidations({ field, values }: {
|
|
107
|
+
field: FieldConfig;
|
|
108
|
+
values: ActionUpdate;
|
|
109
|
+
}): {
|
|
110
|
+
errors: {
|
|
111
|
+
message: TranslationConfig;
|
|
112
|
+
}[];
|
|
113
|
+
};
|
|
114
|
+
export declare function runFieldValidations({ field, values, context }: {
|
|
115
|
+
field: FieldConfig;
|
|
116
|
+
values: ActionUpdate;
|
|
117
|
+
context?: {
|
|
118
|
+
leafAdminStructureLocationIds: Array<{
|
|
119
|
+
id: UUID;
|
|
120
|
+
}>;
|
|
121
|
+
};
|
|
122
|
+
}): {
|
|
123
|
+
errors: {
|
|
124
|
+
message: TranslationConfig;
|
|
125
|
+
}[];
|
|
126
|
+
};
|
|
127
|
+
export declare function getValidatorsForField(fieldId: FieldConfig['id'], validations: NonNullable<FieldConfig['validation']>): NonNullable<FieldConfig['validation']>;
|
|
128
|
+
export declare function areCertificateConditionsMet(conditions: FieldConditional[], values: Record<string, unknown>): boolean;
|
|
129
|
+
//# sourceMappingURL=validate.d.ts.map
|