@basis-theory/basis-theory-reactor-formulas-sdk-js 1.1.0 → 1.3.0

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.0",
3
+ "version": "1.3.0",
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,9 +14,12 @@
14
14
  ],
15
15
  "scripts": {
16
16
  "lint": "eslint . --quiet --ignore-path .gitignore",
17
- "release": "semantic-release"
17
+ "lint:fix": "eslint . --quiet --fix --ignore-path .gitignore",
18
+ "release": "semantic-release",
19
+ "test": "jest --coverage --passWithNoTests"
18
20
  },
19
21
  "devDependencies": {
22
+ "@basis-theory/eslint-config": "^1.0.5",
20
23
  "@commitlint/cli": "^12.1.1",
21
24
  "@commitlint/config-conventional": "^12.1.1",
22
25
  "@semantic-release/changelog": "^5.0.1",
@@ -25,18 +28,18 @@
25
28
  "@semantic-release/github": "^7.2.0",
26
29
  "@semantic-release/npm": "^7.0.10",
27
30
  "@semantic-release/release-notes-generator": "^9.0.1",
31
+ "chance": "^1.1.8",
28
32
  "eslint": "^7.32.0",
29
- "eslint-config-standard": "^16.0.3",
30
- "eslint-plugin-import": "^2.23.4",
31
- "eslint-plugin-node": "^11.1.0",
32
- "eslint-plugin-promise": "^5.1.0",
33
- "eslint-config-prettier": "^8.3.0",
34
- "eslint-plugin-prettier": "^3.4.0",
35
33
  "husky": "^5.1.1",
34
+ "jest": "^27.1.0",
36
35
  "prettier": "^2.3.2",
37
36
  "pretty-quick": "^3.1.0",
38
37
  "semantic-release": "^17.3.9"
39
38
  },
39
+ "resolutions": {
40
+ "eslint-plugin-import": "2.24.2",
41
+ "eslint-plugin-react": "7.25.1"
42
+ },
40
43
  "engines": {
41
44
  "node": ">=14"
42
45
  },
@@ -1,12 +1,13 @@
1
1
  const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class AuthenticationError extends BasisTheoryReactorError {
4
- constructor(data) {
4
+ constructor(errors) {
5
5
  super({
6
6
  message: 'Authentication Failed',
7
7
  status: 401,
8
- data,
8
+ errors,
9
9
  });
10
+ this.name = 'AuthenticationError';
10
11
  }
11
12
  }
12
13
 
@@ -0,0 +1,14 @@
1
+ const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
+
3
+ class AuthorizationError extends BasisTheoryReactorError {
4
+ constructor(errors) {
5
+ super({
6
+ message: 'Forbidden',
7
+ status: 403,
8
+ errors,
9
+ });
10
+ this.name = 'AuthorizationError';
11
+ }
12
+ }
13
+
14
+ module.exports = AuthorizationError;
@@ -1,8 +1,13 @@
1
1
  const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class BadRequestError extends BasisTheoryReactorError {
4
- constructor(data) {
5
- super({ message: 'Bad Request', status: 400, data });
4
+ constructor(errors) {
5
+ super({
6
+ message: 'Bad Request',
7
+ status: 400,
8
+ errors,
9
+ });
10
+ this.name = 'BadRequestError';
6
11
  }
7
12
  }
8
13
 
@@ -1,16 +1,42 @@
1
+ const sanitizeErrors = (errors) => {
2
+ const sanitizedErrors = {};
3
+
4
+ if (Array.isArray(errors)) {
5
+ sanitizedErrors['error'] = errors;
6
+ } else if (typeof errors === 'object') {
7
+ for (const property in errors) {
8
+ if (Array.isArray(errors[property])) {
9
+ sanitizedErrors[property] = errors[property].map((e) =>
10
+ e === 'object' ? JSON.stringify(e) : e.toString()
11
+ );
12
+ } else if (typeof errors[property] === 'object') {
13
+ sanitizedErrors[property] = [JSON.stringify(errors[property])];
14
+ } else {
15
+ sanitizedErrors[property] = [errors[property].toString()];
16
+ }
17
+ }
18
+ } else if (typeof errors === 'string') {
19
+ sanitizedErrors['error'] = [errors];
20
+ } else if (errors) {
21
+ sanitizedErrors['error'] = [errors.toString()];
22
+ }
23
+
24
+ return sanitizedErrors;
25
+ };
26
+
1
27
  class BasisTheoryReactorError extends Error {
2
- constructor({ message, status, data, propertyValidationErrors }) {
28
+ constructor({ message, status, errors }) {
3
29
  super(message);
30
+ this.name = 'BasisTheoryReactorError';
4
31
  this.status = status;
5
- this.data = data;
6
- this.propertyValidationErrors = propertyValidationErrors;
32
+ this.errors = sanitizeErrors(errors);
7
33
  }
8
34
 
9
35
  toRFC7807() {
10
36
  return {
11
- title: this.message,
37
+ detail: this.message,
12
38
  status: this.status,
13
- errors: this.propertyValidationErrors,
39
+ errors: this.errors,
14
40
  };
15
41
  }
16
42
  }
@@ -1,8 +1,13 @@
1
1
  const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class InvalidPaymentMethodError extends BasisTheoryReactorError {
4
- constructor(data) {
5
- super({ message: 'Invalid Payment Method', status: 402, data });
4
+ constructor(errors) {
5
+ super({
6
+ message: 'Invalid Payment Method',
7
+ status: 402,
8
+ errors,
9
+ });
10
+ this.name = 'InvalidPaymentMethodError';
6
11
  }
7
12
  }
8
13
 
@@ -2,21 +2,12 @@ const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class InvalidReactorConfigurationError extends BasisTheoryReactorError {
4
4
  constructor(errors) {
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
- }
15
5
  super({
16
6
  message: 'Invalid Reactor Configuration',
17
7
  status: 400,
18
- propertyValidationErrors: validationErrors,
8
+ errors,
19
9
  });
10
+ this.name = 'InvalidReactorConfigurationError';
20
11
  }
21
12
  }
22
13
 
@@ -2,7 +2,11 @@ const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class InvalidReactorFormulaError extends BasisTheoryReactorError {
4
4
  constructor(message) {
5
- super({ message, status: 422 });
5
+ super({
6
+ message,
7
+ status: 422,
8
+ });
9
+ this.name = 'InvalidReactorFormulaError';
6
10
  }
7
11
  }
8
12
 
@@ -1,8 +1,13 @@
1
1
  const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class RateLimitError extends BasisTheoryReactorError {
4
- constructor(data) {
5
- super({ message: 'Rate Limit Exceeded', status: 429, data });
4
+ constructor(errors) {
5
+ super({
6
+ message: 'Rate Limit Exceeded',
7
+ status: 429,
8
+ errors,
9
+ });
10
+ this.name = 'RateLimitError';
6
11
  }
7
12
  }
8
13
 
@@ -1,8 +1,13 @@
1
1
  const BasisTheoryReactorError = require('./BasisTheoryReactorError');
2
2
 
3
3
  class ReactorRuntimeError extends BasisTheoryReactorError {
4
- constructor(error) {
5
- super({ message: 'Reactor Runtime Error', status: 500, data: error });
4
+ constructor(errors) {
5
+ super({
6
+ message: 'Reactor Runtime Error',
7
+ status: 500,
8
+ errors,
9
+ });
10
+ this.name = 'ReactorRuntimeError';
6
11
  }
7
12
  }
8
13
 
@@ -1,4 +1,5 @@
1
1
  const AuthenticationError = require('./AuthenticationError');
2
+ const AuthorizationError = require('./AuthorizationError');
2
3
  const BadRequestError = require('./BadRequestError');
3
4
  const InvalidPaymentMethodError = require('./InvalidPaymentMethodError');
4
5
  const InvalidReactorConfigurationError = require('./InvalidReactorConfigurationError');
@@ -7,6 +8,7 @@ const ReactorRuntimeError = require('./ReactorRuntimeError');
7
8
 
8
9
  module.exports = {
9
10
  AuthenticationError,
11
+ AuthorizationError,
10
12
  BadRequestError,
11
13
  InvalidPaymentMethodError,
12
14
  InvalidReactorConfigurationError,