@basis-theory/basis-theory-reactor-formulas-sdk-js 1.0.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.0.0",
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",
@@ -15,7 +15,7 @@
15
15
  "scripts": {
16
16
  "lint": "eslint . --quiet --ignore-path .gitignore",
17
17
  "release": "semantic-release",
18
- "postinstall": "husky install"
18
+ "test": "jest --coverage --passWithNoTests"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@commitlint/cli": "^12.1.1",
@@ -29,11 +29,13 @@
29
29
  "eslint": "^7.32.0",
30
30
  "eslint-config-standard": "^16.0.3",
31
31
  "eslint-plugin-import": "^2.23.4",
32
+ "eslint-plugin-jest": "^24.4.0",
32
33
  "eslint-plugin-node": "^11.1.0",
33
34
  "eslint-plugin-promise": "^5.1.0",
34
35
  "eslint-config-prettier": "^8.3.0",
35
36
  "eslint-plugin-prettier": "^3.4.0",
36
37
  "husky": "^5.1.1",
38
+ "jest": "^27.1.0",
37
39
  "prettier": "^2.3.2",
38
40
  "pretty-quick": "^3.1.0",
39
41
  "semantic-release": "^17.3.9"
@@ -2,7 +2,11 @@ const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class AuthenticationError extends BasisTheoryReactorError {
4
4
  constructor(data) {
5
- super('Authentication Failed', 401, data);
5
+ super({
6
+ message: 'Authentication Failed',
7
+ status: 401,
8
+ data,
9
+ });
6
10
  }
7
11
  }
8
12
 
@@ -2,7 +2,7 @@ const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class BadRequestError extends BasisTheoryReactorError {
4
4
  constructor(data) {
5
- super('Bad Request', 400, data);
5
+ super({ message: 'Bad Request', status: 400, data });
6
6
  }
7
7
  }
8
8
 
@@ -1,16 +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.validationErrors = sanitizeErrors(validationErrors);
6
7
  }
7
8
 
8
9
  toRFC7807() {
9
10
  return {
10
- title: this.message,
11
+ detail: this.message,
11
12
  status: this.status,
13
+ errors: this.validationErrors,
12
14
  };
13
15
  }
14
16
  }
15
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
+
16
34
  module.exports = BasisTheoryReactorError;
@@ -0,0 +1,9 @@
1
+ const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
+
3
+ class InvalidPaymentMethodError extends BasisTheoryReactorError {
4
+ constructor(data) {
5
+ super({ message: 'Invalid Payment Method', status: 402, data });
6
+ }
7
+ }
8
+
9
+ module.exports = InvalidPaymentMethodError;
@@ -0,0 +1,13 @@
1
+ const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
+
3
+ class InvalidReactorConfigurationError extends BasisTheoryReactorError {
4
+ constructor(validationErrors) {
5
+ super({
6
+ message: 'Invalid Reactor Configuration',
7
+ status: 400,
8
+ validationErrors,
9
+ });
10
+ }
11
+ }
12
+
13
+ module.exports = InvalidReactorConfigurationError;
@@ -1,8 +1,8 @@
1
1
  const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class InvalidReactorFormulaError extends BasisTheoryReactorError {
4
- constructor(title) {
5
- super(title, 422);
4
+ constructor(message) {
5
+ super({ message, status: 422 });
6
6
  }
7
7
  }
8
8
 
@@ -2,7 +2,7 @@ const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class RateLimitError extends BasisTheoryReactorError {
4
4
  constructor(data) {
5
- super('Rate Limit Exceeded', 429, data);
5
+ super({ message: 'Rate Limit Exceeded', status: 429, data });
6
6
  }
7
7
  }
8
8
 
@@ -2,7 +2,7 @@ const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class ReactorRuntimeError extends BasisTheoryReactorError {
4
4
  constructor(error) {
5
- super('Reactor Runtime Error', 500, error);
5
+ super({ message: 'Reactor Runtime Error', status: 500, data: error });
6
6
  }
7
7
  }
8
8
 
@@ -1,13 +1,15 @@
1
1
  const AuthenticationError = require('./AuthenticationError');
2
2
  const BadRequestError = require('./BadRequestError');
3
- const InvalidCardError = require('./InvalidCardError');
3
+ const InvalidPaymentMethodError = require('./InvalidPaymentMethodError');
4
+ const InvalidReactorConfigurationError = require('./InvalidReactorConfigurationError');
4
5
  const RateLimitError = require('./RateLimitError');
5
6
  const ReactorRuntimeError = require('./ReactorRuntimeError');
6
7
 
7
8
  module.exports = {
8
9
  AuthenticationError,
9
10
  BadRequestError,
10
- InvalidCardError,
11
+ InvalidPaymentMethodError,
12
+ InvalidReactorConfigurationError,
11
13
  RateLimitError,
12
14
  ReactorRuntimeError,
13
15
  };
@@ -1,9 +0,0 @@
1
- const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
-
3
- class InvalidCardError extends BasisTheoryReactorError {
4
- constructor(data) {
5
- super('Invalid Card', 402, data);
6
- }
7
- }
8
-
9
- module.exports = InvalidCardError;