autoinspector 1.0.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.
Files changed (96) hide show
  1. package/.eslintrc.json +22 -0
  2. package/.prettierrc.json +7 -0
  3. package/README.md +79 -0
  4. package/build-sdk.sh +4 -0
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.js +4 -0
  7. package/dist/package.json +44 -0
  8. package/dist/resources/Autoinspector.d.ts +18 -0
  9. package/dist/resources/Autoinspector.js +39 -0
  10. package/dist/resources/Goods.d.ts +33 -0
  11. package/dist/resources/Goods.js +49 -0
  12. package/dist/resources/HTTPClient.d.ts +32 -0
  13. package/dist/resources/HTTPClient.js +87 -0
  14. package/dist/resources/Helper.d.ts +4 -0
  15. package/dist/resources/Helper.js +14 -0
  16. package/dist/resources/Image.d.ts +19 -0
  17. package/dist/resources/Image.js +42 -0
  18. package/dist/resources/Inspections.d.ts +51 -0
  19. package/dist/resources/Inspections.js +69 -0
  20. package/dist/resources/Machinery.d.ts +37 -0
  21. package/dist/resources/Machinery.js +53 -0
  22. package/dist/resources/OAuth20.d.ts +37 -0
  23. package/dist/resources/OAuth20.js +52 -0
  24. package/dist/resources/OAuthUser.d.ts +36 -0
  25. package/dist/resources/OAuthUser.js +53 -0
  26. package/dist/resources/People.d.ts +31 -0
  27. package/dist/resources/People.js +47 -0
  28. package/dist/resources/Vehicle.d.ts +32 -0
  29. package/dist/resources/Vehicle.js +48 -0
  30. package/dist/test/autoinspector.spec.d.ts +0 -0
  31. package/dist/test/autoinspector.spec.js +1 -0
  32. package/dist/types/api.d.ts +12 -0
  33. package/dist/types/api.js +2 -0
  34. package/dist/types/authenticatedUser.d.ts +65 -0
  35. package/dist/types/authenticatedUser.js +2 -0
  36. package/dist/types/autoinspector.d.ts +6 -0
  37. package/dist/types/autoinspector.js +2 -0
  38. package/dist/types/colors.d.ts +1 -0
  39. package/dist/types/colors.js +2 -0
  40. package/dist/types/configuration.d.ts +27 -0
  41. package/dist/types/configuration.js +2 -0
  42. package/dist/types/consumer.d.ts +14 -0
  43. package/dist/types/consumer.js +2 -0
  44. package/dist/types/goods.d.ts +55 -0
  45. package/dist/types/goods.js +2 -0
  46. package/dist/types/http.d.ts +21 -0
  47. package/dist/types/http.js +2 -0
  48. package/dist/types/image.d.ts +14 -0
  49. package/dist/types/image.js +2 -0
  50. package/dist/types/inspection.d.ts +90 -0
  51. package/dist/types/inspection.js +2 -0
  52. package/dist/types/machinery.d.ts +64 -0
  53. package/dist/types/machinery.js +2 -0
  54. package/dist/types/oauth20.d.ts +19 -0
  55. package/dist/types/oauth20.js +2 -0
  56. package/dist/types/pagination.d.ts +20 -0
  57. package/dist/types/pagination.js +2 -0
  58. package/dist/types/people.d.ts +45 -0
  59. package/dist/types/people.js +2 -0
  60. package/dist/types/producer.d.ts +4 -0
  61. package/dist/types/producer.js +2 -0
  62. package/dist/types/productMethods.d.ts +5 -0
  63. package/dist/types/productMethods.js +2 -0
  64. package/dist/types/vehicle.d.ts +116 -0
  65. package/dist/types/vehicle.js +2 -0
  66. package/index.ts +3 -0
  67. package/package.json +44 -0
  68. package/resources/Autoinspector.ts +39 -0
  69. package/resources/Goods.ts +52 -0
  70. package/resources/HTTPClient.ts +97 -0
  71. package/resources/Helper.ts +13 -0
  72. package/resources/Image.ts +45 -0
  73. package/resources/Inspections.ts +77 -0
  74. package/resources/Machinery.ts +56 -0
  75. package/resources/OAuth20.ts +69 -0
  76. package/resources/OAuthUser.ts +62 -0
  77. package/resources/People.ts +49 -0
  78. package/resources/Vehicle.ts +51 -0
  79. package/tsconfig.json +13 -0
  80. package/types/api.ts +15 -0
  81. package/types/authenticatedUser.ts +71 -0
  82. package/types/autoinspector.ts +7 -0
  83. package/types/colors.ts +10 -0
  84. package/types/configuration.ts +28 -0
  85. package/types/consumer.ts +15 -0
  86. package/types/goods.ts +102 -0
  87. package/types/http.ts +24 -0
  88. package/types/image.ts +77 -0
  89. package/types/inspection.ts +190 -0
  90. package/types/machinery.ts +106 -0
  91. package/types/oauth20.ts +23 -0
  92. package/types/pagination.ts +22 -0
  93. package/types/people.ts +58 -0
  94. package/types/producer.ts +4 -0
  95. package/types/productMethods.ts +7 -0
  96. package/types/vehicle.ts +148 -0
package/.eslintrc.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "env": {
3
+ "es6": true,
4
+ "node": true
5
+ },
6
+ "extends": [
7
+ "airbnb-base",
8
+ "prettier/@typescript-eslint",
9
+ "plugin:prettier/recommended"
10
+ ],
11
+ "globals": {
12
+ "Atomics": "readonly",
13
+ "SharedArrayBuffer": "readonly"
14
+ },
15
+ "parser": "@typescript-eslint/parser",
16
+ "parserOptions": {
17
+ "ecmaVersion": 11,
18
+ "sourceType": "module"
19
+ },
20
+ "plugins": ["@typescript-eslint"],
21
+ "rules": {}
22
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "printWidth": 100,
3
+ "tabWidth": 2,
4
+ "singleQuote": true,
5
+ "jsxBracketSameLine": true,
6
+ "trailingComma": "es5"
7
+ }
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Autoinspector Node.js SDK
2
+
3
+ The Autoinspector Node library provides convenient access to the Autoinspector API from applications written in server-side JavaScript.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install autoinspector
9
+ #or
10
+ yarn add autoinspector
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ The package needs to be configured with your company api key, which is available in the [Autoinspector Dashboard](https://dashboard.autoinspector.com.ar/). Require it passing the token at the moment of instantiate Autoinspector class.
16
+
17
+ ```javascript
18
+ const Autoinspector = require('autoinspector').default
19
+
20
+ const autoinspector = new Autoinspector({
21
+ apikey:"YOUR_API_KEY"
22
+ })
23
+
24
+ autoinspector.createVehicleInspection({...})
25
+ .then((res) => {
26
+ console.log("inspection created!", res._id)
27
+ })
28
+ .catch((err) => console.error(err))
29
+ ```
30
+
31
+ Or using ES modules and async/await:
32
+
33
+ ```javascript
34
+ import Autoinspector from 'autoinspector'
35
+
36
+ const autoinspector = new Autoinspector({
37
+ apikey:"YOUR_API_KEY"
38
+ })
39
+
40
+ (async () => {
41
+
42
+ try {
43
+
44
+ const inspection = await autoinspector.createVehicleInspection({...})
45
+
46
+ console.log(inspection._id)
47
+
48
+ } catch (err) {
49
+
50
+ console.error(err)
51
+
52
+ }
53
+
54
+ })()
55
+ ```
56
+
57
+ ## Usage with Typescript
58
+
59
+ All the types are included in the module, so if you install it using typescript you automatically have access to all the interfaces used by Autoinspector SDK.
60
+
61
+ ## Configuration
62
+
63
+ Initialize with config object
64
+
65
+ The package can be initialized with two options:
66
+
67
+ ```javascript
68
+ import Autoinspector from 'autoinspector';
69
+
70
+ const autoinspector = new Autoinspector({
71
+ apikey: 'YOUR_API_KEY',
72
+ timeout: 1000,
73
+ });
74
+ ```
75
+
76
+ | Option | Default | Description |
77
+ | ------- | ------- | --------------------------------------------------------- |
78
+ | apikey | null | token for authentication that belongs to specific company |
79
+ | timeout | 80000 | Maximum time each request can take in ms. |
package/build-sdk.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ rm -rf ./dist
3
+ npm run build
4
+ npm link
@@ -0,0 +1,2 @@
1
+ import { Autoinspector } from './resources/Autoinspector';
2
+ export default Autoinspector;
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Autoinspector_1 = require("./resources/Autoinspector");
4
+ exports.default = Autoinspector_1.Autoinspector;
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "autoinspector",
3
+ "version": "1.0.0",
4
+ "description": "Autoinspector API wrapper",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "test": "test",
9
+ "build": "tsc"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/autoinspector-global/autoinspector-node.git"
14
+ },
15
+ "keywords": [
16
+ "inspections",
17
+ "machine",
18
+ "learning"
19
+ ],
20
+ "author": "Autoinspector <support@autoinspector.com.ar> (https://autoinspector.com.ar)",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/autoinspector-global/autoinspector-node/issues"
24
+ },
25
+ "homepage": "https://github.com/autoinspector-global/autoinspector-node#readme",
26
+ "dependencies": {
27
+ "axios": "^0.25.0",
28
+ "form-data": "^4.0.0",
29
+ "isomorphic-form-data": "^2.0.0",
30
+ "tsc": "^2.0.4",
31
+ "typescript": "^4.5.4"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^17.0.10",
35
+ "@typescript-eslint/eslint-plugin": "^5.10.0",
36
+ "@typescript-eslint/parser": "^5.10.0",
37
+ "eslint": "^8.7.0",
38
+ "eslint-config-airbnb-base": "^15.0.0",
39
+ "eslint-config-prettier": "^8.3.0",
40
+ "eslint-plugin-import": "^2.25.4",
41
+ "eslint-plugin-prettier": "^4.0.0",
42
+ "prettier": "^2.5.1"
43
+ }
44
+ }
@@ -0,0 +1,18 @@
1
+ import { IAutoinspector } from '../types/autoinspector';
2
+ import { OAuth20 } from './OAuth20';
3
+ import { Inspections } from './Inspections';
4
+ /**
5
+ * @classdesc Represents the Autoinspector SDK. It allows the user to make every call to the API with a single function.
6
+ * @class
7
+ */
8
+ export declare class Autoinspector {
9
+ oauth: OAuth20;
10
+ inspections: Inspections;
11
+ /**
12
+ * Create Autoinspector SDK.
13
+ * @constructor
14
+ * @see {@link https://autoinspector.com.ar/docs/api/start}
15
+ * @param {String} apikey - The apikey for authentication.
16
+ */
17
+ constructor(input: IAutoinspector);
18
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Autoinspector = void 0;
7
+ const HTTPClient_1 = require("./HTTPClient");
8
+ const OAuth20_1 = require("./OAuth20");
9
+ const package_json_1 = __importDefault(require("../package.json"));
10
+ const Inspections_1 = require("./Inspections");
11
+ /**
12
+ * @classdesc Represents the Autoinspector SDK. It allows the user to make every call to the API with a single function.
13
+ * @class
14
+ */
15
+ class Autoinspector {
16
+ /**
17
+ * Create Autoinspector SDK.
18
+ * @constructor
19
+ * @see {@link https://autoinspector.com.ar/docs/api/start}
20
+ * @param {String} apikey - The apikey for authentication.
21
+ */
22
+ constructor(input) {
23
+ if (typeof input.apikey !== 'string') {
24
+ throw new Error('apikey should be a string.');
25
+ }
26
+ const httpClient = new HTTPClient_1.HTTPClient({
27
+ baseURL: 'https://api.autoinspector.com.ar',
28
+ headers: {
29
+ 'x-api-key': input.apikey,
30
+ 'User-Agent': 'autoinspector-node-sdk/' + package_json_1.default.version,
31
+ },
32
+ timeout: input.timeout || 80000,
33
+ pathPrefix: '/v1',
34
+ });
35
+ this.oauth = new OAuth20_1.OAuth20(httpClient, input.oauthCredentials || {});
36
+ this.inspections = new Inspections_1.Inspections(httpClient);
37
+ }
38
+ }
39
+ exports.Autoinspector = Autoinspector;
@@ -0,0 +1,33 @@
1
+ import { IUpdateResourceResponse } from '../types/api';
2
+ import { ICreateGoodsInspection, IUpdateGoodsInspection } from '../types/goods';
3
+ import { ICreateInspectionGoodsOutput } from '../types/inspection';
4
+ import { IProductMethods } from '../types/productMethods';
5
+ import { HTTPClient } from './HTTPClient';
6
+ import { Image } from './Image';
7
+ export declare class Goods extends Image implements IProductMethods {
8
+ private readonly httpClient;
9
+ constructor(httpClient: HTTPClient);
10
+ /**
11
+ * Create an inspection that will contains goods.
12
+ * @param input - An object that contains the essential information for create an inspection.
13
+ * @param {Object} input.consumer - Represents the consumer who will do the inspection.
14
+ * @param {Object} input.goods - Represents the goods to be attached to the inspection.
15
+ * @param {String} input.mode - Represents the mode of the inspection. See more details: {@link https://www.autoinspector.com.ar/docs/api/start#inspection_mode}
16
+ * @param {String} input.kindOf - Represents the template that inspection will have. This only matters if the input.mode is normal.
17
+ * @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
18
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
19
+ * data or an Error with the problem.
20
+ */
21
+ create(input: ICreateGoodsInspection): Promise<ICreateInspectionGoodsOutput>;
22
+ /**
23
+ * Update a specific product.
24
+ * @param input - An object that contains information that .
25
+ * @param {String} input.productId - Represents the product unique identifier.
26
+ * @param {Object} input.consumer - Represents the consumer who will do the inspection.
27
+ * @param {Object} input.good - The information to update of the product.
28
+ * @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
29
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
30
+ * data or an Error with the problem.
31
+ */
32
+ update(input: IUpdateGoodsInspection): Promise<IUpdateResourceResponse>;
33
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Goods = void 0;
4
+ const Helper_1 = require("./Helper");
5
+ const Image_1 = require("./Image");
6
+ class Goods extends Image_1.Image {
7
+ constructor(httpClient) {
8
+ super(httpClient);
9
+ this.httpClient = httpClient;
10
+ }
11
+ /**
12
+ * Create an inspection that will contains goods.
13
+ * @param input - An object that contains the essential information for create an inspection.
14
+ * @param {Object} input.consumer - Represents the consumer who will do the inspection.
15
+ * @param {Object} input.goods - Represents the goods to be attached to the inspection.
16
+ * @param {String} input.mode - Represents the mode of the inspection. See more details: {@link https://www.autoinspector.com.ar/docs/api/start#inspection_mode}
17
+ * @param {String} input.kindOf - Represents the template that inspection will have. This only matters if the input.mode is normal.
18
+ * @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
19
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
20
+ * data or an Error with the problem.
21
+ */
22
+ create(input) {
23
+ return this.httpClient.makeRequest({
24
+ method: 'POST',
25
+ path: `/inspection/goods`,
26
+ body: input,
27
+ headers: Helper_1.Helper.buildOptionalHeaders(input.accessToken),
28
+ });
29
+ }
30
+ /**
31
+ * Update a specific product.
32
+ * @param input - An object that contains information that .
33
+ * @param {String} input.productId - Represents the product unique identifier.
34
+ * @param {Object} input.consumer - Represents the consumer who will do the inspection.
35
+ * @param {Object} input.good - The information to update of the product.
36
+ * @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
37
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
38
+ * data or an Error with the problem.
39
+ */
40
+ update(input) {
41
+ return this.httpClient.makeRequest({
42
+ method: 'PUT',
43
+ path: `/inspection/goods/${input.productId}`,
44
+ body: input,
45
+ headers: Helper_1.Helper.buildOptionalHeaders(input.accessToken),
46
+ });
47
+ }
48
+ }
49
+ exports.Goods = Goods;
@@ -0,0 +1,32 @@
1
+ import { IHTTPClient, IMakeRequest } from '../types/http';
2
+ /**
3
+ * @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.
4
+ * @class
5
+ */
6
+ export declare class HTTPClient {
7
+ private headers;
8
+ private timeout;
9
+ private baseURL;
10
+ private pathPrefix;
11
+ /**
12
+ * Create HTTPClient instance to start making request in another class.
13
+ * @constructor
14
+ * @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.timeout - The timeout that each request will have. That means, the time in milliseconds maximum that request will wait until cancel it.
17
+ * @param {Object} input.baseURL - The baseURL to make the requests.
18
+ */
19
+ constructor(input: IHTTPClient);
20
+ /**
21
+ * Make a request to a specific endpoint.
22
+ * @param input - An object that contains the essential information make the request.
23
+ * @param {Object} input.method - Represents the method of the http request.
24
+ * @param {Object} input.path - Represents the path where the request will take place.
25
+ * @param {String} input.body - Represents the body to send. It only will be sended if input.method is not `GET`.
26
+ * @param {String} input.params - Represents the query parameters to send in the request. It only will be sended if input.method is `GET`.
27
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
28
+ * data or an Error with the problem.
29
+ */
30
+ makeRequest(input: IMakeRequest): Promise<any>;
31
+ private handleError;
32
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HTTPClient = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ /**
9
+ * @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
+ * @class
11
+ */
12
+ class HTTPClient {
13
+ /**
14
+ * Create HTTPClient instance to start making request in another class.
15
+ * @constructor
16
+ * @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.
18
+ * @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
+ * @param {Object} input.baseURL - The baseURL to make the requests.
20
+ */
21
+ constructor(input) {
22
+ this.headers = {};
23
+ this.headers = input.headers;
24
+ this.timeout = input.timeout;
25
+ this.baseURL = input.baseURL;
26
+ this.pathPrefix = input.pathPrefix;
27
+ }
28
+ /**
29
+ * Make a request to a specific endpoint.
30
+ * @param input - An object that contains the essential information make the request.
31
+ * @param {Object} input.method - Represents the method of the http request.
32
+ * @param {Object} input.path - Represents the path where the request will take place.
33
+ * @param {String} input.body - Represents the body to send. It only will be sended if input.method is not `GET`.
34
+ * @param {String} input.params - Represents the query parameters to send in the request. It only will be sended if input.method is `GET`.
35
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
36
+ * data or an Error with the problem.
37
+ */
38
+ makeRequest(input) {
39
+ const path = `${this.baseURL}${this.pathPrefix}${input.path}`;
40
+ const options = {
41
+ headers: Object.assign(Object.assign({}, input.headers), this.headers),
42
+ params: input.params,
43
+ timeout: this.timeout,
44
+ };
45
+ switch (input.method) {
46
+ case 'GET':
47
+ return axios_1.default
48
+ .get(path, options)
49
+ .then((res) => {
50
+ return res.data;
51
+ })
52
+ .catch((err) => this.handleError(err));
53
+ case 'PUT':
54
+ return axios_1.default
55
+ .put(path, input.body, options)
56
+ .then((res) => {
57
+ return res.data;
58
+ })
59
+ .catch((err) => this.handleError(err));
60
+ case 'POST':
61
+ return axios_1.default
62
+ .post(path, input.body, options)
63
+ .then((res) => {
64
+ return res.data;
65
+ })
66
+ .catch((err) => this.handleError(err));
67
+ case 'DELETE':
68
+ return axios_1.default
69
+ .post(path, input.body, options)
70
+ .then((res) => {
71
+ return res.data;
72
+ })
73
+ .catch((err) => this.handleError(err));
74
+ }
75
+ }
76
+ handleError(err) {
77
+ var _a;
78
+ const isAxiosError = axios_1.default.isAxiosError(err);
79
+ if (isAxiosError) {
80
+ return Promise.reject((_a = err.response) === null || _a === void 0 ? void 0 : _a.data);
81
+ }
82
+ if (!isAxiosError) {
83
+ return Promise.reject(err);
84
+ }
85
+ }
86
+ }
87
+ exports.HTTPClient = HTTPClient;
@@ -0,0 +1,4 @@
1
+ import { IHeaders } from '../types/http';
2
+ export declare class Helper {
3
+ static buildOptionalHeaders(accessToken?: string): IHeaders | undefined;
4
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Helper = void 0;
4
+ class Helper {
5
+ static buildOptionalHeaders(accessToken) {
6
+ if (accessToken) {
7
+ return {
8
+ Authorization: `Bearer ${accessToken}`,
9
+ };
10
+ }
11
+ return;
12
+ }
13
+ }
14
+ exports.Helper = Helper;
@@ -0,0 +1,19 @@
1
+ import { IAPISucessResponse } from '../types/api';
2
+ import { IUploadImage } from '../types/image';
3
+ import { HTTPClient } from './HTTPClient';
4
+ export declare abstract class Image {
5
+ private readonly httpRef;
6
+ constructor(httpRef: HTTPClient);
7
+ /**
8
+ * Upload an image for specific product inspection item. For the moment, this method is only available for the inspection with mode full_control.
9
+ * @param input - An object that contains the essential information for upload the image.
10
+ * @param {String} input.productId - Represents the id of the product that you would like to attach a new photo.
11
+ * @param {Buffer} input.image - Represents the image to upload.
12
+ * @param {String} input.side - Represents the side of the image/photo to upload.
13
+ * @param {String} input.date - Represents the date when the photo was taken.
14
+ * @param {Object} input.coordinates - Represents the coordinates of the image/photo.
15
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
16
+ * data or an Error with the problem.
17
+ */
18
+ uploadImage(input: IUploadImage): Promise<IAPISucessResponse>;
19
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Image = void 0;
7
+ const form_data_1 = __importDefault(require("form-data"));
8
+ class Image {
9
+ constructor(httpRef) {
10
+ this.httpRef = httpRef;
11
+ }
12
+ /**
13
+ * Upload an image for specific product inspection item. For the moment, this method is only available for the inspection with mode full_control.
14
+ * @param input - An object that contains the essential information for upload the image.
15
+ * @param {String} input.productId - Represents the id of the product that you would like to attach a new photo.
16
+ * @param {Buffer} input.image - Represents the image to upload.
17
+ * @param {String} input.side - Represents the side of the image/photo to upload.
18
+ * @param {String} input.date - Represents the date when the photo was taken.
19
+ * @param {Object} input.coordinates - Represents the coordinates of the image/photo.
20
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
21
+ * data or an Error with the problem.
22
+ */
23
+ uploadImage(input) {
24
+ const form = new form_data_1.default();
25
+ form.append('side', input.side);
26
+ form.append('image', input.image);
27
+ if (input.coordinates) {
28
+ form.append('coordinates', JSON.stringify(input.coordinates));
29
+ }
30
+ if (input.date) {
31
+ form.append('date', input.date.toISOString());
32
+ }
33
+ console.log('FORM DATA!', form);
34
+ return this.httpRef.makeRequest({
35
+ method: 'POST',
36
+ path: `/inspection/image/${input.productId}`,
37
+ body: form,
38
+ headers: Object.assign({}, form.getHeaders()),
39
+ });
40
+ }
41
+ }
42
+ exports.Image = Image;
@@ -0,0 +1,51 @@
1
+ import { IAPISucessResponse } from '../types/api';
2
+ import { IFinishInspection, IGetInspection, IInspection } from '../types/inspection';
3
+ import { IPagination, IPaginationResponse } from '../types/pagination';
4
+ import { Goods } from './Goods';
5
+ import { HTTPClient } from './HTTPClient';
6
+ import { Machinery } from './Machinery';
7
+ import { People } from './People';
8
+ import { Vehicle } from './Vehicle';
9
+ /**
10
+ * @classdesc Represents the class that contains the methods or actions that somebody can do using apikey and access_token.
11
+ * @class
12
+ */
13
+ export declare class Inspections {
14
+ private readonly httpClient;
15
+ machinery: Machinery;
16
+ people: People;
17
+ goods: Goods;
18
+ vehicle: Vehicle;
19
+ constructor(httpClient: HTTPClient);
20
+ /**
21
+ * Finish the inspection to indicate that it will not receive more photos/images.
22
+ * @param input - An object that contains the essential information for upload the image.
23
+ * @param {String} input.inspectionId - Represents the id of the inspection.
24
+ * @param {Buffer} input.image - Represents the image to upload.
25
+ * @param {String} input.side - Represents the side of the image/photo to upload.
26
+ * @param {String} input.date - Represents the date when the photo was taken.
27
+ * @param {Object} input.coordinates - Represents the coordinates of the image/photo.
28
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
29
+ * data or an Error with the problem.
30
+ */
31
+ finishInspection(input: IFinishInspection): Promise<IAPISucessResponse>;
32
+ /**
33
+ * Get a specific inspection object.
34
+ * @param input - An object that contains the essential information for upload the image.
35
+ * @param {String} input.inspectionId - Represents the id of the inspection that you want to retrieve.
36
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
37
+ * data or an Error with the problem.
38
+ */
39
+ getInspection(input: IGetInspection): Promise<IInspection>;
40
+ /**
41
+ * Get a list of n inspections with pagination.
42
+ * @param input - An object that contains filters for list the inspections.
43
+ * @param {Number} input.page - Represents the specific page that you want to retrieve the inspections.
44
+ * @param {Number} input.limit - Represents the limit of the quantity of records that you want to retrieve for page.
45
+ * @param {String} input.status - Represents the status that inspections retrieved should have.
46
+ * @param {String} input.type - Represents the type that inspections retrieved should have.
47
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
48
+ * data or an Error with the problem.
49
+ */
50
+ listInspections(input?: Partial<IPagination>): Promise<IPaginationResponse<IInspection[]>>;
51
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Inspections = void 0;
4
+ const Goods_1 = require("./Goods");
5
+ const Machinery_1 = require("./Machinery");
6
+ const People_1 = require("./People");
7
+ const Vehicle_1 = require("./Vehicle");
8
+ /**
9
+ * @classdesc Represents the class that contains the methods or actions that somebody can do using apikey and access_token.
10
+ * @class
11
+ */
12
+ class Inspections {
13
+ constructor(httpClient) {
14
+ this.httpClient = httpClient;
15
+ this.machinery = new Machinery_1.Machinery(httpClient);
16
+ this.people = new People_1.People(httpClient);
17
+ this.goods = new Goods_1.Goods(httpClient);
18
+ this.vehicle = new Vehicle_1.Vehicle(httpClient);
19
+ }
20
+ /**
21
+ * Finish the inspection to indicate that it will not receive more photos/images.
22
+ * @param input - An object that contains the essential information for upload the image.
23
+ * @param {String} input.inspectionId - Represents the id of the inspection.
24
+ * @param {Buffer} input.image - Represents the image to upload.
25
+ * @param {String} input.side - Represents the side of the image/photo to upload.
26
+ * @param {String} input.date - Represents the date when the photo was taken.
27
+ * @param {Object} input.coordinates - Represents the coordinates of the image/photo.
28
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
29
+ * data or an Error with the problem.
30
+ */
31
+ finishInspection(input) {
32
+ return this.httpClient.makeRequest({
33
+ method: 'POST',
34
+ path: `/inspection/finish/${input.inspectionId}`,
35
+ body: {},
36
+ });
37
+ }
38
+ /**
39
+ * Get a specific inspection object.
40
+ * @param input - An object that contains the essential information for upload the image.
41
+ * @param {String} input.inspectionId - Represents the id of the inspection that you want to retrieve.
42
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
43
+ * data or an Error with the problem.
44
+ */
45
+ getInspection(input) {
46
+ return this.httpClient.makeRequest({
47
+ method: 'GET',
48
+ path: `/inspection/${input.inspectionId}`,
49
+ });
50
+ }
51
+ /**
52
+ * Get a list of n inspections with pagination.
53
+ * @param input - An object that contains filters for list the inspections.
54
+ * @param {Number} input.page - Represents the specific page that you want to retrieve the inspections.
55
+ * @param {Number} input.limit - Represents the limit of the quantity of records that you want to retrieve for page.
56
+ * @param {String} input.status - Represents the status that inspections retrieved should have.
57
+ * @param {String} input.type - Represents the type that inspections retrieved should have.
58
+ * @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
59
+ * data or an Error with the problem.
60
+ */
61
+ listInspections(input = {}) {
62
+ return this.httpClient.makeRequest({
63
+ method: 'GET',
64
+ path: `/inspection`,
65
+ params: input,
66
+ });
67
+ }
68
+ }
69
+ exports.Inspections = Inspections;