autoinspector 2.0.0 → 2.0.2

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.
Files changed (58) hide show
  1. package/README.md +2 -2
  2. package/constants/http.ts +6 -0
  3. package/dist/constants/http.d.ts +5 -0
  4. package/dist/constants/http.js +8 -0
  5. package/dist/index.js +1 -1
  6. package/dist/package.json +7 -5
  7. package/dist/resources/Autoinspector.js +15 -13
  8. package/dist/resources/Bike.d.ts +11 -0
  9. package/dist/resources/Bike.js +40 -0
  10. package/dist/resources/Car.d.ts +1 -1
  11. package/dist/resources/Car.js +21 -62
  12. package/dist/resources/Custom.d.ts +1 -1
  13. package/dist/resources/Custom.js +12 -48
  14. package/dist/resources/Goods.d.ts +2 -2
  15. package/dist/resources/Goods.js +20 -32
  16. package/dist/resources/HTTPClient.d.ts +3 -2
  17. package/dist/resources/HTTPClient.js +41 -39
  18. package/dist/resources/Helper.js +28 -44
  19. package/dist/resources/Image.js +14 -26
  20. package/dist/resources/Inspections.d.ts +2 -2
  21. package/dist/resources/Inspections.js +20 -39
  22. package/dist/resources/Machinery.d.ts +1 -1
  23. package/dist/resources/Machinery.js +12 -25
  24. package/dist/resources/Memberships.js +7 -8
  25. package/dist/resources/Moto.d.ts +1 -1
  26. package/dist/resources/Moto.js +21 -62
  27. package/dist/resources/OAuth.js +10 -22
  28. package/dist/resources/People.d.ts +1 -1
  29. package/dist/resources/People.js +9 -22
  30. package/dist/resources/Products.d.ts +2 -0
  31. package/dist/resources/Products.js +11 -10
  32. package/dist/resources/Template.js +16 -55
  33. package/dist/resources/User.js +14 -33
  34. package/dist/resources/Webhooks.js +11 -32
  35. package/dist/types/autoinspector.d.ts +2 -1
  36. package/dist/types/bike.d.ts +10 -0
  37. package/dist/types/bike.js +2 -0
  38. package/dist/types/car.d.ts +4 -4
  39. package/dist/types/consumer.d.ts +1 -1
  40. package/dist/types/goods.d.ts +3 -3
  41. package/dist/types/http.d.ts +6 -2
  42. package/dist/types/inspection.d.ts +47 -15
  43. package/dist/types/machinery.d.ts +3 -3
  44. package/dist/types/moto.d.ts +1 -1
  45. package/dist/types/people.d.ts +2 -2
  46. package/dist/types/productMethods.d.ts +2 -2
  47. package/dist/types/template.d.ts +6 -1
  48. package/dist/utils/backoff-delay.d.ts +2 -0
  49. package/dist/utils/backoff-delay.js +15 -0
  50. package/dist/utils/http-retry-handler.d.ts +2 -0
  51. package/dist/utils/http-retry-handler.js +18 -0
  52. package/dist/utils/idempotency.d.ts +3 -0
  53. package/dist/utils/idempotency.js +10 -0
  54. package/package.json +7 -5
  55. package/utils/backoff-delay.ts +18 -0
  56. package/utils/http-retry-handler.ts +21 -0
  57. package/utils/idempotency.ts +7 -0
  58. package/.env +0 -6
package/README.md CHANGED
@@ -21,7 +21,7 @@ const autoinspector = new Autoinspector({
21
21
  apikey:"YOUR_API_KEY"
22
22
  })
23
23
 
24
- autoinspector.inspections.vehicle.create({...})
24
+ autoinspector.inspections.car.create({...})
25
25
  .then((res) => {
26
26
  console.log("inspection created!", res.inspectionId)
27
27
  })
@@ -41,7 +41,7 @@ const autoinspector = new Autoinspector({
41
41
 
42
42
  try {
43
43
 
44
- const inspection = await autoinspector.inspections.vehicle.create({...})
44
+ const inspection = await autoinspector.inspections.car.create({...})
45
45
 
46
46
  console.log(inspection._id)
47
47
 
@@ -0,0 +1,6 @@
1
+ export const BASE_DELAY = 50; // 1 second
2
+ export const DEFAULT_MAX_BACKOFF_TIME = 3000; // 3 seconds
3
+ export const DEFAULT_MAX_RETRIES_DEFAULT = 3;
4
+ export const DEFAULT_TIMEOUT = 120000;
5
+
6
+ export const INTERNAL_SERVER_ERROR_STATUS = 500;
@@ -0,0 +1,5 @@
1
+ export declare const BASE_DELAY = 50;
2
+ export declare const DEFAULT_MAX_BACKOFF_TIME = 3000;
3
+ export declare const DEFAULT_MAX_RETRIES_DEFAULT = 3;
4
+ export declare const DEFAULT_TIMEOUT = 120000;
5
+ export declare const INTERNAL_SERVER_ERROR_STATUS = 500;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INTERNAL_SERVER_ERROR_STATUS = exports.DEFAULT_TIMEOUT = exports.DEFAULT_MAX_RETRIES_DEFAULT = exports.DEFAULT_MAX_BACKOFF_TIME = exports.BASE_DELAY = void 0;
4
+ exports.BASE_DELAY = 50; // 1 second
5
+ exports.DEFAULT_MAX_BACKOFF_TIME = 3000; // 3 seconds
6
+ exports.DEFAULT_MAX_RETRIES_DEFAULT = 3;
7
+ exports.DEFAULT_TIMEOUT = 120000;
8
+ exports.INTERNAL_SERVER_ERROR_STATUS = 500;
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
- var Autoinspector_1 = require("./resources/Autoinspector");
2
+ const Autoinspector_1 = require("./resources/Autoinspector");
3
3
  module.exports = Autoinspector_1.Autoinspector;
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoinspector",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Autoinspector API wrapper",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,8 @@
8
8
  "test": "jest --config ./jest.config.js",
9
9
  "build": "tsc",
10
10
  "semantic-release": "semantic-release",
11
- "commit": "git-cz"
11
+ "commit": "git-cz",
12
+ "link": "npm run build && npm link"
12
13
  },
13
14
  "repository": {
14
15
  "type": "git",
@@ -27,9 +28,11 @@
27
28
  "homepage": "https://github.com/autoinspector-global/autoinspector-node#readme",
28
29
  "dependencies": {
29
30
  "axios": "^0.25.0",
31
+ "axios-retry": "^3.3.1",
30
32
  "form-data": "^4.0.0",
31
33
  "isomorphic-form-data": "^2.0.0",
32
- "typescript": "^4.5.4"
34
+ "typescript": "^4.5.4",
35
+ "uuid": "^9.0.0"
33
36
  },
34
37
  "devDependencies": {
35
38
  "@types/jest": "^27.5.0",
@@ -44,8 +47,7 @@
44
47
  "eslint-plugin-prettier": "^4.0.0",
45
48
  "jest": "^27.5.1",
46
49
  "prettier": "^2.5.1",
47
- "semantic-release": "^19.0.2",
48
- "ts-jest": "^28.0.0"
50
+ "semantic-release": "^19.0.2"
49
51
  },
50
52
  "config": {
51
53
  "commitizen": {
@@ -4,35 +4,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Autoinspector = void 0;
7
- var package_json_1 = __importDefault(require("../package.json"));
8
- var HTTPClient_1 = require("./HTTPClient");
9
- var Image_1 = require("./Image");
10
- var Inspections_1 = require("./Inspections");
11
- var OAuth_1 = require("./OAuth");
12
- var Template_1 = require("./Template");
13
- var Webhooks_1 = require("./Webhooks");
7
+ const http_1 = require("../constants/http");
8
+ const package_json_1 = __importDefault(require("../package.json"));
9
+ const HTTPClient_1 = require("./HTTPClient");
10
+ const Image_1 = require("./Image");
11
+ const Inspections_1 = require("./Inspections");
12
+ const OAuth_1 = require("./OAuth");
13
+ const Template_1 = require("./Template");
14
+ const Webhooks_1 = require("./Webhooks");
14
15
  /**
15
16
  * @classdesc Represents the Autoinspector SDK. It allows the user to make every call to the API with a single function.
16
17
  * @class
17
18
  */
18
- var Autoinspector = /** @class */ (function () {
19
+ class Autoinspector {
19
20
  /**
20
21
  * Create Autoinspector SDK.
21
22
  * @constructor
22
23
  * @see {@link https://autoinspector.com.ar/docs/api/start}
23
24
  * @param input - An object with credentials and configuration.
24
25
  */
25
- function Autoinspector(input) {
26
+ constructor(input) {
26
27
  if (typeof input.apikey !== 'string') {
27
28
  throw new Error('apikey should be a string.');
28
29
  }
29
- var httpClient = new HTTPClient_1.HTTPClient({
30
+ const httpClient = new HTTPClient_1.HTTPClient({
30
31
  baseURL: process.env.AUTOINSPECTOR_API_BASE_URL || 'https://api.autoinspector.com.ar',
31
32
  headers: {
32
33
  'x-api-key': input.apikey,
33
34
  'User-Agent': 'autoinspector-node-sdk/' + package_json_1.default.version,
34
35
  },
35
- timeout: input.timeout || 80000,
36
+ maxRetries: input.maxRetries || http_1.DEFAULT_MAX_RETRIES_DEFAULT,
37
+ timeout: input.timeout,
38
+ maxBackoffTime: input.maxBackoffTime,
36
39
  pathPrefix: '/v1',
37
40
  });
38
41
  this.oauth = new OAuth_1.OAuth(httpClient, input.oauthCredentials || {});
@@ -41,6 +44,5 @@ var Autoinspector = /** @class */ (function () {
41
44
  this.templates = new Template_1.Template(httpClient);
42
45
  this.webhooks = new Webhooks_1.Webhooks();
43
46
  }
44
- return Autoinspector;
45
- }());
47
+ }
46
48
  exports.Autoinspector = Autoinspector;
@@ -0,0 +1,11 @@
1
+ import { IUpdateResourceResponse } from '../types/api';
2
+ import { IBike, ICreateBikeInspection } from '../types/bike';
3
+ import { ICreateInspectionOutput } from '../types/inspection';
4
+ import { IProductMethods } from '../types/productMethods';
5
+ import { HTTPClient } from './HTTPClient';
6
+ export declare class Bike implements IProductMethods<ICreateBikeInspection, Partial<IBike>> {
7
+ private readonly httpClient;
8
+ constructor(httpClient: HTTPClient);
9
+ create(body: ICreateBikeInspection): Promise<ICreateInspectionOutput>;
10
+ update(productId: string, bike: Partial<IBike>): Promise<IUpdateResourceResponse>;
11
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Bike = void 0;
13
+ const idempotency_1 = require("../utils/idempotency");
14
+ class Bike {
15
+ constructor(httpClient) {
16
+ this.httpClient = httpClient;
17
+ }
18
+ create(body) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ return yield this.httpClient.makeRequest({
21
+ method: 'POST',
22
+ path: `/inspection/bike`,
23
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
24
+ body,
25
+ });
26
+ });
27
+ }
28
+ update(productId, bike) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return yield this.httpClient.makeRequest({
31
+ method: 'PUT',
32
+ path: `/inspection/bike/${productId}`,
33
+ body: {
34
+ bike,
35
+ },
36
+ });
37
+ });
38
+ }
39
+ }
40
+ exports.Bike = Bike;
@@ -6,6 +6,6 @@ import { HTTPClient } from './HTTPClient';
6
6
  export declare class Car implements IProductMethods<ICreateCarInspection, Partial<ICar>> {
7
7
  private readonly httpClient;
8
8
  constructor(httpClient: HTTPClient);
9
- create(input: ICreateCarInspection): Promise<ICreateInspectionOutput>;
9
+ create(body: ICreateCarInspection): Promise<ICreateInspectionOutput>;
10
10
  update(productId: string, car: Partial<ICar>): Promise<IUpdateResourceResponse>;
11
11
  }
@@ -8,74 +8,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  Object.defineProperty(exports, "__esModule", { value: true });
39
12
  exports.Car = void 0;
40
- var Helper_1 = require("./Helper");
41
- var Car = /** @class */ (function () {
42
- function Car(httpClient) {
13
+ const idempotency_1 = require("../utils/idempotency");
14
+ class Car {
15
+ constructor(httpClient) {
43
16
  this.httpClient = httpClient;
44
17
  }
45
- Car.prototype.create = function (input) {
46
- return __awaiter(this, void 0, void 0, function () {
47
- var form;
48
- return __generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0:
51
- form = Helper_1.Helper.buildFormData(input).form;
52
- return [4 /*yield*/, this.httpClient.makeRequest({
53
- method: 'POST',
54
- path: "/inspection/car",
55
- body: form,
56
- headers: form.getHeaders(),
57
- })];
58
- case 1: return [2 /*return*/, _a.sent()];
59
- }
18
+ create(body) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ return yield this.httpClient.makeRequest({
21
+ method: 'POST',
22
+ path: `/inspection/car`,
23
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
24
+ body,
60
25
  });
61
26
  });
62
- };
63
- Car.prototype.update = function (productId, car) {
64
- return __awaiter(this, void 0, void 0, function () {
65
- return __generator(this, function (_a) {
66
- switch (_a.label) {
67
- case 0: return [4 /*yield*/, this.httpClient.makeRequest({
68
- method: 'PUT',
69
- path: "/inspection/car/".concat(productId),
70
- body: {
71
- car: car,
72
- },
73
- })];
74
- case 1: return [2 /*return*/, _a.sent()];
75
- }
27
+ }
28
+ update(productId, car) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return yield this.httpClient.makeRequest({
31
+ method: 'PUT',
32
+ path: `/inspection/car/${productId}`,
33
+ body: {
34
+ car,
35
+ },
76
36
  });
77
37
  });
78
- };
79
- return Car;
80
- }());
38
+ }
39
+ }
81
40
  exports.Car = Car;
@@ -5,5 +5,5 @@ import { HTTPClient } from './HTTPClient';
5
5
  export declare class Custom implements IProductMethods<ICreatePeopleInspection> {
6
6
  private readonly httpClient;
7
7
  constructor(httpClient: HTTPClient);
8
- create(input: ICreatePeopleInspection): Promise<ICreateInspectionOutput>;
8
+ create(body: ICreatePeopleInspection): Promise<ICreateInspectionOutput>;
9
9
  }
@@ -8,58 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  Object.defineProperty(exports, "__esModule", { value: true });
39
12
  exports.Custom = void 0;
40
- var Helper_1 = require("./Helper");
41
- var Custom = /** @class */ (function () {
42
- function Custom(httpClient) {
13
+ const idempotency_1 = require("../utils/idempotency");
14
+ class Custom {
15
+ constructor(httpClient) {
43
16
  this.httpClient = httpClient;
44
17
  }
45
- Custom.prototype.create = function (input) {
46
- return __awaiter(this, void 0, void 0, function () {
47
- var form;
48
- return __generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0:
51
- form = Helper_1.Helper.buildFormData(input).form;
52
- return [4 /*yield*/, this.httpClient.makeRequest({
53
- method: 'POST',
54
- path: "/inspection/custom",
55
- body: form,
56
- headers: form.getHeaders(),
57
- })];
58
- case 1: return [2 /*return*/, _a.sent()];
59
- }
18
+ create(body) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ return yield this.httpClient.makeRequest({
21
+ method: 'POST',
22
+ path: `/inspection/custom`,
23
+ body,
24
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
60
25
  });
61
26
  });
62
- };
63
- return Custom;
64
- }());
27
+ }
28
+ }
65
29
  exports.Custom = Custom;
@@ -17,7 +17,7 @@ export declare class Goods {
17
17
  * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
18
18
  * data or an Error with the problem.
19
19
  */
20
- create(input: ICreateGoodsInspection): Promise<ICreateInspectionGoodsOutput>;
21
- push(inspectionId: string, goods: IGood[]): Promise<ICreateInspectionGoodsOutput>;
20
+ create(body: ICreateGoodsInspection): Promise<ICreateInspectionGoodsOutput>;
21
+ addGoods(inspectionId: string, goods: IGood[]): Promise<ICreateInspectionGoodsOutput>;
22
22
  update(productId: string, good: Partial<Omit<IGood, 'type' | 'category'>>): Promise<ICreateInspectionGoodsOutput>;
23
23
  }
@@ -1,20 +1,10 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.Goods = void 0;
15
- var Helper_1 = require("./Helper");
16
- var Goods = /** @class */ (function () {
17
- function Goods(httpClient) {
4
+ const idempotency_1 = require("../utils/idempotency");
5
+ const Helper_1 = require("./Helper");
6
+ class Goods {
7
+ constructor(httpClient) {
18
8
  this.httpClient = httpClient;
19
9
  }
20
10
  /**
@@ -30,35 +20,33 @@ var Goods = /** @class */ (function () {
30
20
  * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
31
21
  * data or an Error with the problem.
32
22
  */
33
- Goods.prototype.create = function (input) {
34
- var form = Helper_1.Helper.buildFormData(input).form;
23
+ create(body) {
35
24
  return this.httpClient.makeRequest({
36
25
  method: 'POST',
37
- path: "/inspection/goods",
38
- body: form,
39
- headers: __assign(__assign({}, Helper_1.Helper.buildOptionalHeaders(input.access_token)), form.getHeaders()),
26
+ path: `/inspection/goods`,
27
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
28
+ body,
40
29
  });
41
- };
42
- Goods.prototype.push = function (inspectionId, goods) {
30
+ }
31
+ addGoods(inspectionId, goods) {
43
32
  return this.httpClient.makeRequest({
44
33
  method: 'POST',
45
- path: "/inspection/goods/".concat(inspectionId),
34
+ path: `/inspection/goods/${inspectionId}`,
46
35
  body: {
47
- goods: goods,
36
+ goods,
48
37
  },
49
- headers: __assign({}, Helper_1.Helper.buildOptionalHeaders()),
38
+ headers: Object.assign({}, Helper_1.Helper.buildOptionalHeaders()),
50
39
  });
51
- };
52
- Goods.prototype.update = function (productId, good) {
40
+ }
41
+ update(productId, good) {
53
42
  return this.httpClient.makeRequest({
54
43
  method: 'POST',
55
- path: "/inspection/goods/".concat(productId),
44
+ path: `/inspection/goods/${productId}`,
56
45
  body: {
57
- good: good,
46
+ good,
58
47
  },
59
- headers: __assign({}, Helper_1.Helper.buildOptionalHeaders()),
48
+ headers: Object.assign({}, Helper_1.Helper.buildOptionalHeaders()),
60
49
  });
61
- };
62
- return Goods;
63
- }());
50
+ }
51
+ }
64
52
  exports.Goods = Goods;
@@ -5,14 +5,15 @@ import { IHTTPClient, IMakeRequest } from '../types/http';
5
5
  */
6
6
  export declare class HTTPClient {
7
7
  private headers;
8
- private timeout;
9
8
  private baseURL;
10
9
  private pathPrefix;
10
+ private instance;
11
+ private timeout;
11
12
  /**
12
13
  * Create HTTPClient instance to start making request in another class.
13
14
  * @constructor
14
15
  * @param input - An object with common parameters that we need to set in the http client third party library.
15
- * @param {Object} input.headers - An object with the headers to send in each makeRequest() call.
16
+ * @param {Object} input'''.headers - An object with the headers to send in each makeRequest() call.
16
17
  * @param {Object} input.timeout - The timeout that each request will have. That means, the time in milliseconds maximum that request will wait until cancel it.
17
18
  * @param {Object} input.baseURL - The baseURL to make the requests.
18
19
  */
@@ -1,40 +1,44 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
6
  exports.HTTPClient = void 0;
18
- var axios_1 = __importDefault(require("axios"));
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const axios_retry_1 = __importDefault(require("axios-retry"));
9
+ const http_1 = require("../constants/http");
10
+ const http_retry_handler_1 = require("../utils/http-retry-handler");
19
11
  /**
20
12
  * @classdesc Represents the class that implements some HTTP client third library. It's an extra layer for in case if we need to change the implementation be one hundred percent sure we can do it without problems.
21
13
  * @class
22
14
  */
23
- var HTTPClient = /** @class */ (function () {
15
+ class HTTPClient {
24
16
  /**
25
17
  * Create HTTPClient instance to start making request in another class.
26
18
  * @constructor
27
19
  * @param input - An object with common parameters that we need to set in the http client third party library.
28
- * @param {Object} input.headers - An object with the headers to send in each makeRequest() call.
20
+ * @param {Object} input'''.headers - An object with the headers to send in each makeRequest() call.
29
21
  * @param {Object} input.timeout - The timeout that each request will have. That means, the time in milliseconds maximum that request will wait until cancel it.
30
22
  * @param {Object} input.baseURL - The baseURL to make the requests.
31
23
  */
32
- function HTTPClient(input) {
24
+ constructor(input) {
33
25
  this.headers = {};
34
26
  this.headers = input.headers;
35
- this.timeout = input.timeout;
36
27
  this.baseURL = input.baseURL;
28
+ this.timeout = input.timeout || http_1.DEFAULT_TIMEOUT;
37
29
  this.pathPrefix = input.pathPrefix;
30
+ const httpClient = axios_1.default.create();
31
+ (0, axios_retry_1.default)(httpClient, {
32
+ retryDelay: (0, http_retry_handler_1.httpRetryHandler)(input),
33
+ retries: input.maxRetries,
34
+ retryCondition: (error) => {
35
+ if (axios_1.default.isAxiosError(error)) {
36
+ return false;
37
+ }
38
+ return true;
39
+ },
40
+ });
41
+ this.instance = httpClient;
38
42
  }
39
43
  /**
40
44
  * Make a request to a specific endpoint.
@@ -46,55 +50,53 @@ var HTTPClient = /** @class */ (function () {
46
50
  * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
47
51
  * data or an Error with the problem.
48
52
  */
49
- HTTPClient.prototype.makeRequest = function (input) {
50
- var _this = this;
51
- var path = "".concat(this.baseURL).concat(this.pathPrefix).concat(input.path);
52
- var options = {
53
- headers: __assign(__assign({}, input.headers), (!input.withoutPredefinedHeaders ? this.headers : {})),
53
+ makeRequest(input) {
54
+ const path = `${this.baseURL}${this.pathPrefix}${input.path}`;
55
+ const options = {
56
+ headers: Object.assign(Object.assign({}, input.headers), (!input.withoutPredefinedHeaders ? this.headers : {})),
54
57
  params: input.params,
55
58
  timeout: this.timeout,
56
59
  };
57
60
  switch (input.method) {
58
61
  case 'GET':
59
- return axios_1.default
62
+ return this.instance
60
63
  .get(path, options)
61
- .then(function (res) {
64
+ .then((res) => {
62
65
  return res.data;
63
66
  })
64
- .catch(function (err) { return _this.handleError(err); });
67
+ .catch((err) => this.handleError(err));
65
68
  case 'PUT':
66
- return axios_1.default
69
+ return this.instance
67
70
  .put(path, input.body, options)
68
- .then(function (res) {
71
+ .then((res) => {
69
72
  return res.data;
70
73
  })
71
- .catch(function (err) { return _this.handleError(err); });
74
+ .catch((err) => this.handleError(err));
72
75
  case 'POST':
73
- return axios_1.default
76
+ return this.instance
74
77
  .post(path, input.body, options)
75
- .then(function (res) {
78
+ .then((res) => {
76
79
  return res.data;
77
80
  })
78
- .catch(function (err) { return _this.handleError(err); });
81
+ .catch((err) => this.handleError(err));
79
82
  case 'DELETE':
80
- return axios_1.default
83
+ return this.instance
81
84
  .post(path, input.body, options)
82
- .then(function (res) {
85
+ .then((res) => {
83
86
  return res.data;
84
87
  })
85
- .catch(function (err) { return _this.handleError(err); });
88
+ .catch((err) => this.handleError(err));
86
89
  }
87
- };
88
- HTTPClient.prototype.handleError = function (err) {
90
+ }
91
+ handleError(err) {
89
92
  var _a;
90
- var isAxiosError = axios_1.default.isAxiosError(err);
93
+ const isAxiosError = axios_1.default.isAxiosError(err);
91
94
  if (isAxiosError) {
92
95
  return Promise.reject((_a = err.response) === null || _a === void 0 ? void 0 : _a.data);
93
96
  }
94
97
  if (!isAxiosError) {
95
98
  return Promise.reject(err);
96
99
  }
97
- };
98
- return HTTPClient;
99
- }());
100
+ }
101
+ }
100
102
  exports.HTTPClient = HTTPClient;