@basis-theory/basis-theory-reactor-formulas-sdk-js 1.1.0 → 1.1.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basis-theory/basis-theory-reactor-formulas-sdk-js",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Javascript SDK for building Basis Theory reactor formulas",
|
|
5
5
|
"repository": "https://github.com/Basis-Theory/basistheory-reactor-formulas-sdk-js",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
16
|
"lint": "eslint . --quiet --ignore-path .gitignore",
|
|
17
|
-
"release": "semantic-release"
|
|
17
|
+
"release": "semantic-release",
|
|
18
|
+
"test": "jest --coverage --passWithNoTests"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@commitlint/cli": "^12.1.1",
|
|
@@ -28,11 +29,13 @@
|
|
|
28
29
|
"eslint": "^7.32.0",
|
|
29
30
|
"eslint-config-standard": "^16.0.3",
|
|
30
31
|
"eslint-plugin-import": "^2.23.4",
|
|
32
|
+
"eslint-plugin-jest": "^24.4.0",
|
|
31
33
|
"eslint-plugin-node": "^11.1.0",
|
|
32
34
|
"eslint-plugin-promise": "^5.1.0",
|
|
33
35
|
"eslint-config-prettier": "^8.3.0",
|
|
34
36
|
"eslint-plugin-prettier": "^3.4.0",
|
|
35
37
|
"husky": "^5.1.1",
|
|
38
|
+
"jest": "^27.1.0",
|
|
36
39
|
"prettier": "^2.3.2",
|
|
37
40
|
"pretty-quick": "^3.1.0",
|
|
38
41
|
"semantic-release": "^17.3.9"
|
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
class BasisTheoryReactorError extends Error {
|
|
2
|
-
constructor({ message, status, data,
|
|
2
|
+
constructor({ message, status, data, validationErrors }) {
|
|
3
3
|
super(message);
|
|
4
4
|
this.status = status;
|
|
5
5
|
this.data = data;
|
|
6
|
-
this.
|
|
6
|
+
this.validationErrors = sanitizeErrors(validationErrors);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
toRFC7807() {
|
|
10
10
|
return {
|
|
11
|
-
|
|
11
|
+
detail: this.message,
|
|
12
12
|
status: this.status,
|
|
13
|
-
errors: this.
|
|
13
|
+
errors: this.validationErrors,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const sanitizeErrors = (errors) => {
|
|
19
|
+
const sanitizedErrors = {};
|
|
20
|
+
|
|
21
|
+
if (typeof errors === 'object') {
|
|
22
|
+
for (const property in errors) {
|
|
23
|
+
sanitizedErrors[property] = Array.isArray(errors[property])
|
|
24
|
+
? errors[property].map((e) => e.toString())
|
|
25
|
+
: [errors[property].toString()];
|
|
26
|
+
}
|
|
27
|
+
} else if (typeof errors === 'string') {
|
|
28
|
+
sanitizedErrors[errors] = [`${errors} is invalid`];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return sanitizedErrors;
|
|
32
|
+
};
|
|
33
|
+
|
|
18
34
|
module.exports = BasisTheoryReactorError;
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
const BasisTheoryReactorError = require('./BasisTheoryReactorError');
|
|
2
2
|
|
|
3
3
|
class InvalidReactorConfigurationError extends BasisTheoryReactorError {
|
|
4
|
-
constructor(
|
|
5
|
-
const validationErrors = {};
|
|
6
|
-
if (typeof errors === 'object') {
|
|
7
|
-
for (const property in errors) {
|
|
8
|
-
validationErrors[property] = Array.isArray(errors[property])
|
|
9
|
-
? errors[property].map((e) => e.toString())
|
|
10
|
-
: [errors[property].toString()];
|
|
11
|
-
}
|
|
12
|
-
} else if (typeof errors === 'string') {
|
|
13
|
-
validationErrors[errors] = [`${errors} is invalid`];
|
|
14
|
-
}
|
|
4
|
+
constructor(validationErrors) {
|
|
15
5
|
super({
|
|
16
6
|
message: 'Invalid Reactor Configuration',
|
|
17
7
|
status: 400,
|
|
18
|
-
|
|
8
|
+
validationErrors,
|
|
19
9
|
});
|
|
20
10
|
}
|
|
21
11
|
}
|