@apify/input_schema 2.0.0 → 2.0.4
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/input_schema.js +5 -5
- package/package.json +3 -3
- package/utilities.js +15 -15
package/input_schema.js
CHANGED
|
@@ -32,19 +32,19 @@ function parseAjvError(error, rootName, properties = {}, input = {}) {
|
|
|
32
32
|
if (properties[fieldKey] && properties[fieldKey].nullable && input[fieldKey] === null) {
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
|
-
message = intl_1.m('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });
|
|
35
|
+
message = (0, intl_1.m)('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });
|
|
36
36
|
}
|
|
37
37
|
else if (error.keyword === 'required') {
|
|
38
38
|
fieldKey = error.params.missingProperty;
|
|
39
|
-
message = intl_1.m('inputSchema.validation.required', { rootName, fieldKey });
|
|
39
|
+
message = (0, intl_1.m)('inputSchema.validation.required', { rootName, fieldKey });
|
|
40
40
|
}
|
|
41
41
|
else if (error.keyword === 'additionalProperties') {
|
|
42
42
|
fieldKey = error.params.additionalProperty;
|
|
43
|
-
message = intl_1.m('inputSchema.validation.additionalProperty', { rootName, fieldKey });
|
|
43
|
+
message = (0, intl_1.m)('inputSchema.validation.additionalProperty', { rootName, fieldKey });
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
46
|
fieldKey = error.instancePath.split('/').pop();
|
|
47
|
-
message = intl_1.m('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });
|
|
47
|
+
message = (0, intl_1.m)('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });
|
|
48
48
|
}
|
|
49
49
|
return { fieldKey, message };
|
|
50
50
|
}
|
|
@@ -83,7 +83,7 @@ const validateField = (validator, fieldSchema, fieldKey) => {
|
|
|
83
83
|
});
|
|
84
84
|
// There is not matching definition.
|
|
85
85
|
if (matchingDefinitions.length === 0) {
|
|
86
|
-
const errorMessage = intl_1.m('inputSchema.validation.noMatchingDefinition', { fieldKey });
|
|
86
|
+
const errorMessage = (0, intl_1.m)('inputSchema.validation.noMatchingDefinition', { fieldKey });
|
|
87
87
|
throw new Error(`Input schema is not valid (${errorMessage})`);
|
|
88
88
|
}
|
|
89
89
|
// If there is only one matching then we are done and simply compare it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/input_schema",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Tools and constants shared across Apify projects.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@apify/consts": "^1.2
|
|
38
|
+
"@apify/consts": "^1.4.2",
|
|
39
39
|
"countries-list": "^2.6.1",
|
|
40
40
|
"escaya": "^0.0.61"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"ajv": "^8.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "22d8e8ca5786dcf5d783e7863b4cb5f414be01e6"
|
|
46
46
|
}
|
package/utilities.js
CHANGED
|
@@ -23,13 +23,13 @@ function validateProxyField(fieldKey, value, isRequired = false, options = null)
|
|
|
23
23
|
if (value === null)
|
|
24
24
|
return fieldErrors;
|
|
25
25
|
if (!value) {
|
|
26
|
-
const message = intl_1.m('inputSchema.validation.required', { rootName: 'input', fieldKey });
|
|
26
|
+
const message = (0, intl_1.m)('inputSchema.validation.required', { rootName: 'input', fieldKey });
|
|
27
27
|
fieldErrors.push(message);
|
|
28
28
|
return fieldErrors;
|
|
29
29
|
}
|
|
30
30
|
const { useApifyProxy, proxyUrls } = value;
|
|
31
31
|
if (!useApifyProxy && (!Array.isArray(proxyUrls) || proxyUrls.length === 0)) {
|
|
32
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.proxyRequired', { rootName: 'input', fieldKey }));
|
|
32
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.proxyRequired', { rootName: 'input', fieldKey }));
|
|
33
33
|
return fieldErrors;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -44,19 +44,19 @@ function validateProxyField(fieldKey, value, isRequired = false, options = null)
|
|
|
44
44
|
invalidUrl = url.trim();
|
|
45
45
|
});
|
|
46
46
|
if (invalidUrl) {
|
|
47
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.customProxyInvalid', { invalidUrl }));
|
|
47
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.customProxyInvalid', { invalidUrl }));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
// Apify proxy country can be set only when using Apify proxy
|
|
51
51
|
if (!useApifyProxy && apifyProxyCountry) {
|
|
52
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden'));
|
|
52
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden'));
|
|
53
53
|
}
|
|
54
54
|
// If Apify proxy is not used skip additional checks
|
|
55
55
|
if (!useApifyProxy)
|
|
56
56
|
return fieldErrors;
|
|
57
57
|
// If Apify proxy is used, check if there is a selected country and if so, check that it's valid (empty or a valid country code)
|
|
58
58
|
if (apifyProxyCountry && !countries_list_1.countries[apifyProxyCountry]) {
|
|
59
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.apifyProxyCountryInvalid', { invalidCountry: apifyProxyCountry }));
|
|
59
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.apifyProxyCountryInvalid', { invalidCountry: apifyProxyCountry }));
|
|
60
60
|
}
|
|
61
61
|
// If options are not provided skip additional checks
|
|
62
62
|
if (!options)
|
|
@@ -64,7 +64,7 @@ function validateProxyField(fieldKey, value, isRequired = false, options = null)
|
|
|
64
64
|
const selectedProxyGroups = (apifyProxyGroups || []);
|
|
65
65
|
// Auto mode, check that user has access to alteast one proxy group usable in this mode
|
|
66
66
|
if (!selectedProxyGroups.length && !options.hasAutoProxyGroups) {
|
|
67
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.noAvailableAutoProxy'));
|
|
67
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.noAvailableAutoProxy'));
|
|
68
68
|
return fieldErrors;
|
|
69
69
|
}
|
|
70
70
|
// Check if proxy groups selected by user are available to him
|
|
@@ -72,7 +72,7 @@ function validateProxyField(fieldKey, value, isRequired = false, options = null)
|
|
|
72
72
|
(options.availableProxyGroups || []).forEach((group) => { availableProxyGroupsById[group] = true; });
|
|
73
73
|
const unavailableProxyGroups = selectedProxyGroups.filter((group) => !availableProxyGroupsById[group]);
|
|
74
74
|
if (unavailableProxyGroups.length) {
|
|
75
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.proxyGroupsNotAvailable', {
|
|
75
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.proxyGroupsNotAvailable', {
|
|
76
76
|
rootName: 'input',
|
|
77
77
|
fieldKey,
|
|
78
78
|
groups: unavailableProxyGroups.join(', '),
|
|
@@ -103,7 +103,7 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
|
|
|
103
103
|
// Process AJV validation errors
|
|
104
104
|
if (!isValid) {
|
|
105
105
|
errors = validator.errors
|
|
106
|
-
.map((error) => input_schema_1.parseAjvError(error, 'input', properties, input))
|
|
106
|
+
.map((error) => (0, input_schema_1.parseAjvError)(error, 'input', properties, input))
|
|
107
107
|
.filter((error) => !!error);
|
|
108
108
|
}
|
|
109
109
|
Object.keys(properties).forEach((property) => {
|
|
@@ -132,7 +132,7 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
|
|
|
132
132
|
invalidIndexes.push(index);
|
|
133
133
|
});
|
|
134
134
|
if (invalidIndexes.length) {
|
|
135
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.requestListSourcesInvalid', {
|
|
135
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.requestListSourcesInvalid', {
|
|
136
136
|
rootName: 'input',
|
|
137
137
|
fieldKey: property,
|
|
138
138
|
invalidIndexes: invalidIndexes.join(','),
|
|
@@ -148,7 +148,7 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
|
|
|
148
148
|
invalidIndexes.push(index);
|
|
149
149
|
});
|
|
150
150
|
if (invalidIndexes.length) {
|
|
151
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.arrayKeysInvalid', {
|
|
151
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.arrayKeysInvalid', {
|
|
152
152
|
rootName: 'input',
|
|
153
153
|
fieldKey: property,
|
|
154
154
|
invalidIndexes: invalidIndexes.join(','),
|
|
@@ -165,7 +165,7 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
|
|
|
165
165
|
invalidIndexes.push(index);
|
|
166
166
|
});
|
|
167
167
|
if (invalidIndexes.length) {
|
|
168
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.arrayValuesInvalid', {
|
|
168
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.arrayValuesInvalid', {
|
|
169
169
|
rootName: 'input',
|
|
170
170
|
fieldKey: property,
|
|
171
171
|
invalidIndexes: invalidIndexes.join(','),
|
|
@@ -182,7 +182,7 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
|
|
|
182
182
|
invalidIndexes.push(index);
|
|
183
183
|
});
|
|
184
184
|
if (invalidIndexes.length) {
|
|
185
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.arrayValuesInvalid', {
|
|
185
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.arrayValuesInvalid', {
|
|
186
186
|
rootName: 'input',
|
|
187
187
|
fieldKey: property,
|
|
188
188
|
invalidIndexes: invalidIndexes.join(','),
|
|
@@ -201,7 +201,7 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
|
|
|
201
201
|
invalidKeys.push(key);
|
|
202
202
|
});
|
|
203
203
|
if (invalidKeys.length) {
|
|
204
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.objectKeysInvalid', {
|
|
204
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.objectKeysInvalid', {
|
|
205
205
|
rootName: 'input',
|
|
206
206
|
fieldKey: property,
|
|
207
207
|
invalidKeys: invalidKeys.join(','),
|
|
@@ -218,7 +218,7 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
|
|
|
218
218
|
invalidKeys.push(key);
|
|
219
219
|
});
|
|
220
220
|
if (invalidKeys.length) {
|
|
221
|
-
fieldErrors.push(intl_1.m('inputSchema.validation.objectValuesInvalid', {
|
|
221
|
+
fieldErrors.push((0, intl_1.m)('inputSchema.validation.objectValuesInvalid', {
|
|
222
222
|
rootName: 'input',
|
|
223
223
|
fieldKey: property,
|
|
224
224
|
invalidKeys: invalidKeys.join(','),
|
|
@@ -252,7 +252,7 @@ function makeInputJsFieldsReadable(json, jsFields, jsonSpacing = 4, globalSpacin
|
|
|
252
252
|
return;
|
|
253
253
|
let ast;
|
|
254
254
|
try {
|
|
255
|
-
ast = escaya_1.parseScript(maybeFunction, { cst: true });
|
|
255
|
+
ast = (0, escaya_1.parseScript)(maybeFunction, { cst: true });
|
|
256
256
|
}
|
|
257
257
|
catch (err) {
|
|
258
258
|
// Don't do anything in a case of invalid JS code.
|