autoinspector 2.0.1 → 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 (43) hide show
  1. package/constants/http.ts +6 -0
  2. package/dist/constants/http.d.ts +5 -0
  3. package/dist/constants/http.js +8 -0
  4. package/dist/package.json +7 -5
  5. package/dist/resources/Autoinspector.js +4 -1
  6. package/dist/resources/Bike.d.ts +1 -1
  7. package/dist/resources/Bike.js +4 -5
  8. package/dist/resources/Car.d.ts +1 -1
  9. package/dist/resources/Car.js +4 -5
  10. package/dist/resources/Custom.d.ts +1 -1
  11. package/dist/resources/Custom.js +4 -5
  12. package/dist/resources/Goods.d.ts +2 -2
  13. package/dist/resources/Goods.js +5 -5
  14. package/dist/resources/HTTPClient.d.ts +3 -2
  15. package/dist/resources/HTTPClient.js +21 -6
  16. package/dist/resources/Inspections.d.ts +2 -2
  17. package/dist/resources/Machinery.d.ts +1 -1
  18. package/dist/resources/Machinery.js +4 -5
  19. package/dist/resources/Moto.d.ts +1 -1
  20. package/dist/resources/Moto.js +4 -5
  21. package/dist/resources/People.d.ts +1 -1
  22. package/dist/resources/People.js +4 -5
  23. package/dist/types/autoinspector.d.ts +2 -1
  24. package/dist/types/bike.d.ts +2 -2
  25. package/dist/types/car.d.ts +4 -4
  26. package/dist/types/consumer.d.ts +1 -1
  27. package/dist/types/goods.d.ts +2 -2
  28. package/dist/types/http.d.ts +6 -2
  29. package/dist/types/inspection.d.ts +44 -13
  30. package/dist/types/machinery.d.ts +2 -2
  31. package/dist/types/people.d.ts +2 -2
  32. package/dist/types/productMethods.d.ts +2 -2
  33. package/dist/utils/backoff-delay.d.ts +2 -0
  34. package/dist/utils/backoff-delay.js +15 -0
  35. package/dist/utils/http-retry-handler.d.ts +2 -0
  36. package/dist/utils/http-retry-handler.js +18 -0
  37. package/dist/utils/idempotency.d.ts +3 -0
  38. package/dist/utils/idempotency.js +10 -0
  39. package/package.json +7 -5
  40. package/utils/backoff-delay.ts +18 -0
  41. package/utils/http-retry-handler.ts +21 -0
  42. package/utils/idempotency.ts +7 -0
  43. package/.env +0 -6
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoinspector",
3
- "version": "2.0.1",
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,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Autoinspector = void 0;
7
+ const http_1 = require("../constants/http");
7
8
  const package_json_1 = __importDefault(require("../package.json"));
8
9
  const HTTPClient_1 = require("./HTTPClient");
9
10
  const Image_1 = require("./Image");
@@ -32,7 +33,9 @@ class Autoinspector {
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 || {});
@@ -6,6 +6,6 @@ import { HTTPClient } from './HTTPClient';
6
6
  export declare class Bike implements IProductMethods<ICreateBikeInspection, Partial<IBike>> {
7
7
  private readonly httpClient;
8
8
  constructor(httpClient: HTTPClient);
9
- create(input: ICreateBikeInspection): Promise<ICreateInspectionOutput>;
9
+ create(body: ICreateBikeInspection): Promise<ICreateInspectionOutput>;
10
10
  update(productId: string, bike: Partial<IBike>): Promise<IUpdateResourceResponse>;
11
11
  }
@@ -10,19 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Bike = void 0;
13
- const Helper_1 = require("./Helper");
13
+ const idempotency_1 = require("../utils/idempotency");
14
14
  class Bike {
15
15
  constructor(httpClient) {
16
16
  this.httpClient = httpClient;
17
17
  }
18
- create(input) {
18
+ create(body) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- const { form } = Helper_1.Helper.buildFormData(input);
21
20
  return yield this.httpClient.makeRequest({
22
21
  method: 'POST',
23
22
  path: `/inspection/bike`,
24
- body: form,
25
- headers: form.getHeaders(),
23
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
24
+ body,
26
25
  });
27
26
  });
28
27
  }
@@ -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
  }
@@ -10,19 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Car = void 0;
13
- const Helper_1 = require("./Helper");
13
+ const idempotency_1 = require("../utils/idempotency");
14
14
  class Car {
15
15
  constructor(httpClient) {
16
16
  this.httpClient = httpClient;
17
17
  }
18
- create(input) {
18
+ create(body) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- const { form } = Helper_1.Helper.buildFormData(input);
21
20
  return yield this.httpClient.makeRequest({
22
21
  method: 'POST',
23
22
  path: `/inspection/car`,
24
- body: form,
25
- headers: form.getHeaders(),
23
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
24
+ body,
26
25
  });
27
26
  });
28
27
  }
@@ -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
  }
@@ -10,19 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Custom = void 0;
13
- const Helper_1 = require("./Helper");
13
+ const idempotency_1 = require("../utils/idempotency");
14
14
  class Custom {
15
15
  constructor(httpClient) {
16
16
  this.httpClient = httpClient;
17
17
  }
18
- create(input) {
18
+ create(body) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- const { form } = Helper_1.Helper.buildFormData(input);
21
20
  return yield this.httpClient.makeRequest({
22
21
  method: 'POST',
23
22
  path: `/inspection/custom`,
24
- body: form,
25
- headers: form.getHeaders(),
23
+ body,
24
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
26
25
  });
27
26
  });
28
27
  }
@@ -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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Goods = void 0;
4
+ const idempotency_1 = require("../utils/idempotency");
4
5
  const Helper_1 = require("./Helper");
5
6
  class Goods {
6
7
  constructor(httpClient) {
@@ -19,16 +20,15 @@ class Goods {
19
20
  * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
20
21
  * data or an Error with the problem.
21
22
  */
22
- create(input) {
23
- const { form } = Helper_1.Helper.buildFormData(input);
23
+ create(body) {
24
24
  return this.httpClient.makeRequest({
25
25
  method: 'POST',
26
26
  path: `/inspection/goods`,
27
- body: form,
28
- headers: Object.assign(Object.assign({}, Helper_1.Helper.buildOptionalHeaders(input.access_token)), form.getHeaders()),
27
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
28
+ body,
29
29
  });
30
30
  }
31
- push(inspectionId, goods) {
31
+ addGoods(inspectionId, goods) {
32
32
  return this.httpClient.makeRequest({
33
33
  method: 'POST',
34
34
  path: `/inspection/goods/${inspectionId}`,
@@ -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
  */
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.HTTPClient = void 0;
7
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");
8
11
  /**
9
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.
10
13
  * @class
@@ -14,16 +17,28 @@ class HTTPClient {
14
17
  * Create HTTPClient instance to start making request in another class.
15
18
  * @constructor
16
19
  * @param input - An object with common parameters that we need to set in the http client third party library.
17
- * @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.
18
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.
19
22
  * @param {Object} input.baseURL - The baseURL to make the requests.
20
23
  */
21
24
  constructor(input) {
22
25
  this.headers = {};
23
26
  this.headers = input.headers;
24
- this.timeout = input.timeout;
25
27
  this.baseURL = input.baseURL;
28
+ this.timeout = input.timeout || http_1.DEFAULT_TIMEOUT;
26
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;
27
42
  }
28
43
  /**
29
44
  * Make a request to a specific endpoint.
@@ -44,28 +59,28 @@ class HTTPClient {
44
59
  };
45
60
  switch (input.method) {
46
61
  case 'GET':
47
- return axios_1.default
62
+ return this.instance
48
63
  .get(path, options)
49
64
  .then((res) => {
50
65
  return res.data;
51
66
  })
52
67
  .catch((err) => this.handleError(err));
53
68
  case 'PUT':
54
- return axios_1.default
69
+ return this.instance
55
70
  .put(path, input.body, options)
56
71
  .then((res) => {
57
72
  return res.data;
58
73
  })
59
74
  .catch((err) => this.handleError(err));
60
75
  case 'POST':
61
- return axios_1.default
76
+ return this.instance
62
77
  .post(path, input.body, options)
63
78
  .then((res) => {
64
79
  return res.data;
65
80
  })
66
81
  .catch((err) => this.handleError(err));
67
82
  case 'DELETE':
68
- return axios_1.default
83
+ return this.instance
69
84
  .post(path, input.body, options)
70
85
  .then((res) => {
71
86
  return res.data;
@@ -1,6 +1,6 @@
1
1
  import { IAPISucessResponse } from '../types/api';
2
2
  import { IConsumer } from '../types/consumer';
3
- import { IFinishInspection, IIInspectionCommonParamsV2, IInspection } from '../types/inspection';
3
+ import { IFinishInspection, IInspection, IInspectionCommonParamsV2 } from '../types/inspection';
4
4
  import { IPagination, IPaginationResponse } from '../types/pagination';
5
5
  import { IProducer } from '../types/producer';
6
6
  import { HTTPClient } from './HTTPClient';
@@ -28,7 +28,7 @@ export declare class Inspections extends Products {
28
28
  * data or an Error with the problem.
29
29
  */
30
30
  retrieve(inspectionId: string): Promise<IInspection>;
31
- update(inspectionId: string, inspection: Partial<Pick<IIInspectionCommonParamsV2<IProducer, Partial<IConsumer>>, 'inputs' | 'consumer' | 'metadata'>>): Promise<IAPISucessResponse>;
31
+ update(inspectionId: string, inspection: Partial<Pick<IInspectionCommonParamsV2<IProducer, Partial<IConsumer>>, 'inputs' | 'consumer' | 'metadata'>>): Promise<IAPISucessResponse>;
32
32
  /**
33
33
  * Get a list of n inspections with pagination.
34
34
  * @param input - An object that contains filters for list the inspections.
@@ -23,6 +23,6 @@ export declare class Machinery implements IProductMethods<ICreateMachineryInspec
23
23
  * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
24
24
  * data or an Error with the problem.
25
25
  */
26
- create(input: ICreateMachineryInspection): Promise<ICreateInspectionOutput>;
26
+ create(body: ICreateMachineryInspection): Promise<ICreateInspectionOutput>;
27
27
  update(productId: string, machinery: Partial<Omit<IMachinery, 'type'>>): Promise<IUpdateResourceResponse>;
28
28
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Machinery = void 0;
4
- const Helper_1 = require("./Helper");
4
+ const idempotency_1 = require("../utils/idempotency");
5
5
  /**
6
6
  * @classdesc Represents the class that handle all the requests related to an inspection of type machinery.
7
7
  * @class
@@ -23,13 +23,12 @@ class Machinery {
23
23
  * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
24
24
  * data or an Error with the problem.
25
25
  */
26
- create(input) {
27
- const { form } = Helper_1.Helper.buildFormData(input);
26
+ create(body) {
28
27
  return this.httpClient.makeRequest({
29
28
  method: 'POST',
30
29
  path: `/inspection/machinery`,
31
- body: form,
32
- headers: Object.assign(Object.assign({}, Helper_1.Helper.buildOptionalHeaders(input === null || input === void 0 ? void 0 : input.access_token)), form.getHeaders()),
30
+ body,
31
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
33
32
  });
34
33
  }
35
34
  update(productId, machinery) {
@@ -6,6 +6,6 @@ import { HTTPClient } from './HTTPClient';
6
6
  export declare class Moto implements IProductMethods<ICreateMotoInspection, Partial<IMoto>> {
7
7
  private readonly httpClient;
8
8
  constructor(httpClient: HTTPClient);
9
- create(input: ICreateMotoInspection): Promise<ICreateInspectionOutput>;
9
+ create(body: ICreateMotoInspection): Promise<ICreateInspectionOutput>;
10
10
  update(productId: string, moto: Partial<IMoto>): Promise<IUpdateResourceResponse>;
11
11
  }
@@ -10,19 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Moto = void 0;
13
- const Helper_1 = require("./Helper");
13
+ const idempotency_1 = require("../utils/idempotency");
14
14
  class Moto {
15
15
  constructor(httpClient) {
16
16
  this.httpClient = httpClient;
17
17
  }
18
- create(input) {
18
+ create(body) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- const { form } = Helper_1.Helper.buildFormData(input);
21
20
  return yield this.httpClient.makeRequest({
22
21
  method: 'POST',
23
22
  path: `/inspection/moto`,
24
- body: form,
25
- headers: form.getHeaders(),
23
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
24
+ body,
26
25
  });
27
26
  });
28
27
  }
@@ -18,5 +18,5 @@ export declare class People implements IProductMethods<ICreatePeopleInspection>
18
18
  * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
19
19
  * data or an Error with the problem.
20
20
  */
21
- create(input: ICreatePeopleInspection): Promise<ICreateInspectionOutput>;
21
+ create(body: ICreatePeopleInspection): Promise<ICreateInspectionOutput>;
22
22
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.People = void 0;
4
- const Helper_1 = require("./Helper");
4
+ const idempotency_1 = require("../utils/idempotency");
5
5
  class People {
6
6
  constructor(httpClient) {
7
7
  this.httpClient = httpClient;
@@ -19,13 +19,12 @@ class People {
19
19
  * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
20
20
  * data or an Error with the problem.
21
21
  */
22
- create(input) {
23
- const { form } = Helper_1.Helper.buildFormData(input);
22
+ create(body) {
24
23
  return this.httpClient.makeRequest({
25
24
  method: 'POST',
26
25
  path: `/inspection/people`,
27
- body: form,
28
- headers: Object.assign(Object.assign({}, Helper_1.Helper.buildOptionalHeaders(input.access_token)), form.getHeaders()),
26
+ headers: (0, idempotency_1.generateIdempotencyHeader)(),
27
+ body,
29
28
  });
30
29
  }
31
30
  }
@@ -1,5 +1,6 @@
1
+ import { IHttpClientOpts } from './http';
1
2
  import { IOAuth20Credentials } from './oauth20';
2
- export interface IAutoinspector {
3
+ export interface IAutoinspector extends Partial<IHttpClientOpts> {
3
4
  /**
4
5
  * The apikey for authenticate to Autoinspector API.
5
6
  */
@@ -1,10 +1,10 @@
1
- import { ICreateInspectionProducer, IIInspectionCommonParamsV2 } from './inspection';
1
+ import { ICreateInspectionProducer, IInspectionCommonParamsV2 } from './inspection';
2
2
  export interface IBike {
3
3
  make: string;
4
4
  model: string;
5
5
  price: number;
6
6
  serialNumber: string;
7
7
  }
8
- export interface ICreateBikeInspection extends IIInspectionCommonParamsV2<ICreateInspectionProducer> {
8
+ export interface ICreateBikeInspection extends IInspectionCommonParamsV2<ICreateInspectionProducer> {
9
9
  bike?: Partial<IBike>;
10
10
  }
@@ -1,5 +1,5 @@
1
1
  import { Colors } from './colors';
2
- import { ICreateInspectionProducer, IIInspectionCommonParamsV2 } from './inspection';
2
+ import { ICreateInspectionProducer, IInspectionCommonParamsV2 } from './inspection';
3
3
  export interface ICar {
4
4
  /**
5
5
  * Plate: The plate of the vehicle.
@@ -34,8 +34,8 @@ export interface ICar {
34
34
  */
35
35
  chassis?: string;
36
36
  }
37
- export interface ICreateCarInspection extends IIInspectionCommonParamsV2<ICreateInspectionProducer> {
38
- car?: ICar;
37
+ export interface ICreateCarInspection extends IInspectionCommonParamsV2<ICreateInspectionProducer> {
38
+ car?: Partial<ICar>;
39
39
  }
40
40
  export declare type InspectionCompletedBy = 'client' | 'expiration';
41
41
  export interface IValidation {
@@ -45,4 +45,4 @@ export interface IValidation {
45
45
  type: string;
46
46
  }
47
47
  export declare type InspectionType = 'goods' | 'people' | 'vehicle' | 'machinery' | 'car' | 'moto';
48
- export declare type ICreateInspectionParamsV2 = IIInspectionCommonParamsV2<ICreateInspectionProducer>;
48
+ export declare type ICreateInspectionParamsV2 = IInspectionCommonParamsV2<ICreateInspectionProducer>;
@@ -1,4 +1,4 @@
1
- export declare type Sex = 0 | 1 | 2 | 9;
1
+ export declare type Sex = 'male' | 'female' | 'not_applicable';
2
2
  export interface IConsumer {
3
3
  firstName: string;
4
4
  lastName: string;
@@ -1,5 +1,5 @@
1
1
  import { IConfiguration, IConfigurationCommonValidations } from './configuration';
2
- import { ICreateInspectionProducer, IIInspectionCommonParamsV2 } from './inspection';
2
+ import { ICreateInspectionProducer, IInspectionCommonParamsV2 } from './inspection';
3
3
  export interface IGoodConfiguration extends IConfigurationCommonValidations {
4
4
  /**
5
5
  * object: `Validation that verifies the serial number that appears in the serialNumber photo is the same as declared.`
@@ -40,6 +40,6 @@ export interface IGood {
40
40
  /**
41
41
  * Represents the object to be sended when create an inspection of type vehicle.
42
42
  */
43
- export interface ICreateGoodsInspection extends IIInspectionCommonParamsV2<ICreateInspectionProducer> {
43
+ export interface ICreateGoodsInspection extends IInspectionCommonParamsV2<ICreateInspectionProducer> {
44
44
  goods?: Partial<IGood>[];
45
45
  }
@@ -14,9 +14,13 @@ export interface IMakeRequest {
14
14
  headers?: IHeaders;
15
15
  withoutPredefinedHeaders?: boolean;
16
16
  }
17
- export interface IHTTPClient {
18
- headers: IHeaders;
17
+ export interface IHttpClientOpts {
18
+ maxBackoffTime: number;
19
19
  timeout: number;
20
+ maxRetries: number;
21
+ }
22
+ export interface IHTTPClient extends Partial<IHttpClientOpts> {
23
+ headers: IHeaders;
20
24
  baseURL: string;
21
25
  pathPrefix: string;
22
26
  }
@@ -1,4 +1,5 @@
1
1
  import { IConsumer } from './consumer';
2
+ import { ITemplateInputTypes } from './template';
2
3
  export declare type InspectionCompletedBy = 'client' | 'expiration';
3
4
  export interface IValidation {
4
5
  confidence: number;
@@ -6,7 +7,7 @@ export interface IValidation {
6
7
  _id: string;
7
8
  type: string;
8
9
  }
9
- export declare type InspectionType = 'goods' | 'people' | 'machinery' | 'car' | 'moto' | 'custom';
10
+ export declare type InspectionType = 'goods' | 'people' | 'machinery' | 'car' | 'moto' | 'custom' | 'bike';
10
11
  export declare type InspectionVeredict = 'approved' | 'disapproved' | 'not_defined' | 'not_provided';
11
12
  export declare type ImageGeneratedBy = 'configuration' | 'damage_declaration' | 'full_control';
12
13
  export declare type InspectionStatus = 'created' | 'started' | 'completed' | 'blocked' | 'processing';
@@ -41,17 +42,15 @@ export declare type IInputFile = {
41
42
  filename: string;
42
43
  identifier: string;
43
44
  };
44
- export declare type IInputValue = {
45
- value: any;
45
+ export interface IInputValue {
46
46
  identifier: string;
47
- contentType?: string;
48
- filename?: string;
49
- };
47
+ value: any;
48
+ }
50
49
  export declare type DeliveryChannels = 'email' | 'wsp';
51
50
  export declare type Delivery = {
52
51
  disabled: true;
53
52
  } | {
54
- channel: 'wsp';
53
+ channel: 'wsp' | 'sms';
55
54
  destination: string;
56
55
  countryISO: string;
57
56
  disabled: false;
@@ -60,19 +59,19 @@ export declare type Delivery = {
60
59
  destination: string;
61
60
  disabled: false;
62
61
  };
63
- export interface IUpdateInspection extends Pick<IIInspectionCommonParamsV2, 'inputs' | 'consumer'> {
62
+ export interface IUpdateInspection extends Pick<IInspectionCommonParamsV2, 'inputs' | 'consumer'> {
64
63
  inspectionId: string;
65
64
  }
66
65
  export interface IInspectionMetadata {
67
66
  [key: string]: string;
68
67
  }
69
- export interface IIInspectionCommonParamsV2<P = IProducer, C = IConsumer> {
68
+ export interface IInspectionCommonParamsV2<P = IProducer, C = IConsumer> {
70
69
  callbackURL?: string;
71
70
  delivery: Delivery;
72
71
  locale: 'es_AR' | 'es_MX' | 'es_CL' | 'es_UY' | 'es_PE' | string;
73
72
  inputs?: IInputValue[];
74
- consumer?: C;
75
- producer: P;
73
+ consumer?: Partial<C>;
74
+ producer?: P;
76
75
  templateId: string;
77
76
  initialStatus?: 'created' | 'started';
78
77
  metadata?: IInspectionMetadata;
@@ -94,9 +93,25 @@ export interface ICreateInspectionOutputCommon {
94
93
  export interface IGetInspection {
95
94
  inspectionId: string;
96
95
  }
97
- export interface IProduct {
96
+ export declare type InspectionTargets = 'product' | 'identity' | 'custom';
97
+ export interface IInspectionSection {
98
98
  images: IImage[];
99
- extraImages: string[];
99
+ extraImages: {
100
+ target: InspectionTargets;
101
+ uploadedAt: string;
102
+ side: string;
103
+ _id: string;
104
+ src: string;
105
+ }[];
106
+ inputs: {
107
+ value?: any;
108
+ label: string;
109
+ type: ITemplateInputTypes;
110
+ identifier: string;
111
+ }[];
112
+ }
113
+ export interface IProduct extends IInspectionSection {
114
+ type: InspectionType;
100
115
  _id: string;
101
116
  }
102
117
  export interface ICreateInspectionProducer {
@@ -111,7 +126,21 @@ export interface IProducer {
111
126
  export interface IImageToken {
112
127
  token: string;
113
128
  }
129
+ export interface IInspectionIdentity extends IInspectionSection {
130
+ address: string;
131
+ city: string;
132
+ country: string;
133
+ state: string;
134
+ phone: string;
135
+ sex: string;
136
+ birthdate: string;
137
+ email: string;
138
+ identification: string;
139
+ lastName: string;
140
+ firstName: string;
141
+ }
114
142
  export interface IInspection {
143
+ testing: boolean;
115
144
  veredict: InspectionVeredict;
116
145
  type: InspectionType;
117
146
  status: InspectionStatus;
@@ -119,7 +148,9 @@ export interface IInspection {
119
148
  products: IProduct[];
120
149
  _id: string;
121
150
  producer: IProducer;
151
+ custom: IInspectionSection;
122
152
  metadata: IInspectionMetadata;
153
+ identity: IInspectionIdentity;
123
154
  }
124
155
  export interface IInspectionHandler {
125
156
  }
@@ -1,6 +1,6 @@
1
1
  import { Colors } from './colors';
2
2
  import { IConfiguration, IConfigurationCommonValidations } from './configuration';
3
- import { ICreateInspectionProducer, IIInspectionCommonParamsV2 } from './inspection';
3
+ import { ICreateInspectionProducer, IInspectionCommonParamsV2 } from './inspection';
4
4
  export declare type MachineryPurpose = 'Agrícola' | 'Vial' | 'Industrial';
5
5
  export declare type MachineryUse = 'OFICIAL' | 'PRIVADO' | 'PÚBLICO';
6
6
  export declare type MachineryType = 'tractor' | 'combine_harvester' | 'sprayer' | 'seeder' | 'fumigator' | 'baler' | 'round_baler' | 'paver' | 'leveler' | 'crane' | 'excavator' | 'carts' | 'grader' | 'loader' | 'scrapers' | 'compacting_machine' | 'machine_soil_treatment' | 'forklift' | 'motor_vehicle_with_coupling_device' | 'fertilizer' | 'backhoe' | 'bulldozer' | 'compactor' | 'hidrogua' | 'trencher' | 'mixer' | 'hopper' | 'mechanical_shovel';
@@ -52,6 +52,6 @@ export interface IMachinery {
52
52
  */
53
53
  type: MachineryType;
54
54
  }
55
- export interface ICreateMachineryInspection extends IIInspectionCommonParamsV2<ICreateInspectionProducer> {
55
+ export interface ICreateMachineryInspection extends IInspectionCommonParamsV2<ICreateInspectionProducer> {
56
56
  machinery?: Partial<IMachinery>;
57
57
  }
@@ -1,5 +1,5 @@
1
1
  import { IConfiguration, IConfigurationCommonValidations } from './configuration';
2
- import { ICreateInspectionProducer, IIInspectionCommonParamsV2 } from './inspection';
2
+ import { ICreateInspectionProducer, IInspectionCommonParamsV2 } from './inspection';
3
3
  export declare type PeopleType = 'person';
4
4
  export interface IPeopleConfiguration extends IConfigurationCommonValidations {
5
5
  /**
@@ -39,6 +39,6 @@ export interface IPeople {
39
39
  /**
40
40
  * Represents the object to be sended when create an inspection of type vehicle.
41
41
  */
42
- export interface ICreatePeopleInspection extends IIInspectionCommonParamsV2<ICreateInspectionProducer> {
42
+ export interface ICreatePeopleInspection extends IInspectionCommonParamsV2<ICreateInspectionProducer> {
43
43
  people: IPeople;
44
44
  }
@@ -1,5 +1,5 @@
1
- import { ICreateInspectionProducer, IIInspectionCommonParamsV2 } from './inspection';
2
- export interface IProductMethods<C extends IIInspectionCommonParamsV2<ICreateInspectionProducer>, U extends object = any> {
1
+ import { ICreateInspectionProducer, IInspectionCommonParamsV2 } from './inspection';
2
+ export interface IProductMethods<C extends IInspectionCommonParamsV2<ICreateInspectionProducer>, U extends object = any> {
3
3
  create(input: C): Promise<any>;
4
4
  update?(productId: string, update: U): Promise<any>;
5
5
  }
@@ -0,0 +1,2 @@
1
+ import { IHttpClientOpts } from '../types/http';
2
+ export declare const calculateBackoffDelay: (retryCount: number, opts: IHttpClientOpts) => number;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateBackoffDelay = void 0;
4
+ const http_1 = require("../constants/http");
5
+ const getRandomInt = (max) => Math.floor(Math.random() * Math.floor(max));
6
+ const calculateBackoffDelay = (retryCount, opts) => {
7
+ let baseDelay = 325;
8
+ if (retryCount < 1) {
9
+ baseDelay = http_1.BASE_DELAY;
10
+ }
11
+ const retries = Math.min(retryCount, opts.maxRetries);
12
+ const ceil = Math.min((1 << retries) * baseDelay, opts.maxBackoffTime);
13
+ return ceil / 2 + getRandomInt(ceil / 2 + 1);
14
+ };
15
+ exports.calculateBackoffDelay = calculateBackoffDelay;
@@ -0,0 +1,2 @@
1
+ import { IHttpClientOpts } from '../types/http';
2
+ export declare const httpRetryHandler: (opts: Partial<IHttpClientOpts>) => (retryCount: number, error: Error) => number;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.httpRetryHandler = void 0;
4
+ const http_1 = require("../constants/http");
5
+ const backoff_delay_1 = require("./backoff-delay");
6
+ const httpRetryHandler = (opts) => {
7
+ return (retryCount, error) => {
8
+ if (error) {
9
+ console.log('[AUTOINSPECTOR SDK] An error occurred:', error);
10
+ }
11
+ return (0, backoff_delay_1.calculateBackoffDelay)(retryCount, {
12
+ maxBackoffTime: opts.maxBackoffTime || http_1.DEFAULT_MAX_BACKOFF_TIME,
13
+ maxRetries: opts.maxRetries || http_1.DEFAULT_MAX_RETRIES_DEFAULT,
14
+ timeout: opts.timeout || http_1.DEFAULT_TIMEOUT,
15
+ });
16
+ };
17
+ };
18
+ exports.httpRetryHandler = httpRetryHandler;
@@ -0,0 +1,3 @@
1
+ export declare const generateIdempotencyHeader: () => {
2
+ 'Idempotency-Key': any;
3
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateIdempotencyHeader = void 0;
4
+ const { v4: uuidv4 } = require('uuid');
5
+ const generateIdempotencyHeader = () => {
6
+ return {
7
+ 'Idempotency-Key': uuidv4(),
8
+ };
9
+ };
10
+ exports.generateIdempotencyHeader = generateIdempotencyHeader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoinspector",
3
- "version": "2.0.1",
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": {
@@ -0,0 +1,18 @@
1
+ import { BASE_DELAY } from '../constants/http';
2
+ import { IHttpClientOpts } from '../types/http';
3
+
4
+ const getRandomInt = (max: number) => Math.floor(Math.random() * Math.floor(max));
5
+
6
+ export const calculateBackoffDelay = (retryCount: number, opts: IHttpClientOpts) => {
7
+ let baseDelay = 325;
8
+
9
+ if (retryCount < 1) {
10
+ baseDelay = BASE_DELAY;
11
+ }
12
+
13
+ const retries: number = Math.min(retryCount, opts.maxRetries);
14
+
15
+ const ceil = Math.min((1 << retries) * baseDelay, opts.maxBackoffTime);
16
+
17
+ return ceil / 2 + getRandomInt(ceil / 2 + 1);
18
+ };
@@ -0,0 +1,21 @@
1
+ import {
2
+ DEFAULT_MAX_BACKOFF_TIME,
3
+ DEFAULT_MAX_RETRIES_DEFAULT,
4
+ DEFAULT_TIMEOUT,
5
+ } from '../constants/http';
6
+ import { IHttpClientOpts } from '../types/http';
7
+ import { calculateBackoffDelay } from './backoff-delay';
8
+
9
+ export const httpRetryHandler = (opts: Partial<IHttpClientOpts>) => {
10
+ return (retryCount: number, error: Error): number => {
11
+ if (error) {
12
+ console.log('[AUTOINSPECTOR SDK] An error occurred:', error);
13
+ }
14
+
15
+ return calculateBackoffDelay(retryCount, {
16
+ maxBackoffTime: opts.maxBackoffTime || DEFAULT_MAX_BACKOFF_TIME,
17
+ maxRetries: opts.maxRetries || DEFAULT_MAX_RETRIES_DEFAULT,
18
+ timeout: opts.timeout || DEFAULT_TIMEOUT,
19
+ });
20
+ };
21
+ };
@@ -0,0 +1,7 @@
1
+ const { v4: uuidv4 } = require('uuid');
2
+
3
+ export const generateIdempotencyHeader = () => {
4
+ return {
5
+ 'Idempotency-Key': uuidv4(),
6
+ };
7
+ };
package/.env DELETED
@@ -1,6 +0,0 @@
1
- AUTOINSPECTOR_API_BASE_URL=http://localhost:9001/api
2
- AUTOINSPECTOR_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2MTQ3ODQzYmI5YTcwODAwNTUxODc4YmQiLCJpYXQiOjE2NDAyODI5NjcsImV4cCI6MzMxNjYzMjUzNjd9.Ikc2kIZRja8WBQ3QzWo7ztMAgFk-EFNyifjw_58sg3g
3
- CI_CAR_TEMPLATE_ID=627157f565b79931f3d1dbac
4
- CI_MACHINERY_TEMPLATE_ID=6274475b1996d60ec2803218
5
- CI_PEOPLE_TEMPLATE_ID=6274475b1996d60ec2803218
6
- CI_MOTO_TEMPLATE_ID=6274475b1996d60ec2803218