autoinspector 1.1.1 → 1.1.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.
- package/.env +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/package.json +58 -0
- package/dist/resources/Autoinspector.d.ts +20 -0
- package/dist/resources/Autoinspector.js +41 -0
- package/dist/resources/Car.d.ts +8 -0
- package/dist/resources/Car.js +56 -0
- package/dist/resources/Goods.d.ts +34 -0
- package/dist/resources/Goods.js +48 -0
- package/dist/resources/HTTPClient.d.ts +32 -0
- package/dist/resources/HTTPClient.js +87 -0
- package/dist/resources/Helper.d.ts +8 -0
- package/dist/resources/Helper.js +30 -0
- package/dist/resources/Image.d.ts +26 -0
- package/dist/resources/Image.js +53 -0
- package/dist/resources/Inspections.d.ts +40 -0
- package/dist/resources/Inspections.js +59 -0
- package/dist/resources/Machinery.d.ts +38 -0
- package/dist/resources/Machinery.js +52 -0
- package/dist/resources/Memberships.d.ts +14 -0
- package/dist/resources/Memberships.js +24 -0
- package/dist/resources/OAuth.d.ts +37 -0
- package/dist/resources/OAuth.js +52 -0
- package/dist/resources/People.d.ts +32 -0
- package/dist/resources/People.js +46 -0
- package/dist/resources/Products.d.ts +12 -0
- package/dist/resources/Products.js +16 -0
- package/dist/resources/Template.d.ts +7 -0
- package/dist/resources/Template.js +27 -0
- package/dist/resources/User.d.ts +35 -0
- package/dist/resources/User.js +47 -0
- package/dist/resources/Vehicle.d.ts +33 -0
- package/dist/resources/Vehicle.js +47 -0
- package/dist/types/api.d.ts +12 -0
- package/dist/types/api.js +2 -0
- package/dist/types/authenticatedUser.d.ts +65 -0
- package/dist/types/authenticatedUser.js +2 -0
- package/dist/types/autoinspector.d.ts +15 -0
- package/dist/types/autoinspector.js +2 -0
- package/dist/types/car.d.ts +39 -0
- package/dist/types/car.js +2 -0
- package/dist/types/colors.d.ts +1 -0
- package/dist/types/colors.js +2 -0
- package/dist/types/configuration.d.ts +27 -0
- package/dist/types/configuration.js +2 -0
- package/dist/types/consumer.d.ts +14 -0
- package/dist/types/consumer.js +2 -0
- package/dist/types/goods.d.ts +55 -0
- package/dist/types/goods.js +2 -0
- package/dist/types/http.d.ts +22 -0
- package/dist/types/http.js +2 -0
- package/dist/types/image.d.ts +15 -0
- package/dist/types/image.js +2 -0
- package/dist/types/inspection.d.ts +112 -0
- package/dist/types/inspection.js +2 -0
- package/dist/types/machinery.d.ts +64 -0
- package/dist/types/machinery.js +2 -0
- package/dist/types/oauth20.d.ts +19 -0
- package/dist/types/oauth20.js +2 -0
- package/dist/types/pagination.d.ts +21 -0
- package/dist/types/pagination.js +2 -0
- package/dist/types/people.d.ts +46 -0
- package/dist/types/people.js +2 -0
- package/dist/types/producer.d.ts +4 -0
- package/dist/types/producer.js +2 -0
- package/dist/types/productMethods.d.ts +4 -0
- package/dist/types/productMethods.js +2 -0
- package/dist/types/template.d.ts +56 -0
- package/dist/types/template.js +2 -0
- package/dist/types/vehicle.d.ts +116 -0
- package/dist/types/vehicle.js +2 -0
- package/index.ts +3 -0
- package/package.json +1 -1
package/.env
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
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
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "autoinspector",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "Autoinspector API wrapper",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest --config ./jest.config.js",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"semantic-release": "semantic-release",
|
|
11
|
+
"commit": "git-cz"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/autoinspector-global/autoinspector-node.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"inspections",
|
|
19
|
+
"machine",
|
|
20
|
+
"learning"
|
|
21
|
+
],
|
|
22
|
+
"author": "Autoinspector <support@autoinspector.com.ar> (https://autoinspector.com.ar)",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/autoinspector-global/autoinspector-node/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/autoinspector-global/autoinspector-node#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"axios": "^0.25.0",
|
|
30
|
+
"form-data": "^4.0.0",
|
|
31
|
+
"isomorphic-form-data": "^2.0.0",
|
|
32
|
+
"typescript": "^4.5.4"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/jest": "^27.5.0",
|
|
36
|
+
"@types/node": "^17.0.10",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
|
38
|
+
"@typescript-eslint/parser": "^5.10.0",
|
|
39
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
40
|
+
"eslint": "^8.7.0",
|
|
41
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
42
|
+
"eslint-config-prettier": "^8.3.0",
|
|
43
|
+
"eslint-plugin-import": "^2.25.4",
|
|
44
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
45
|
+
"jest": "^27.5.1",
|
|
46
|
+
"prettier": "^2.5.1",
|
|
47
|
+
"semantic-release": "^19.0.2",
|
|
48
|
+
"ts-jest": "^28.0.0"
|
|
49
|
+
},
|
|
50
|
+
"config": {
|
|
51
|
+
"commitizen": {
|
|
52
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IAutoinspector } from '../types/autoinspector';
|
|
2
|
+
import { Image } from './Image';
|
|
3
|
+
import { Inspections } from './Inspections';
|
|
4
|
+
import { OAuth } from './OAuth';
|
|
5
|
+
/**
|
|
6
|
+
* @classdesc Represents the Autoinspector SDK. It allows the user to make every call to the API with a single function.
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
export declare class Autoinspector {
|
|
10
|
+
oauth: OAuth;
|
|
11
|
+
images: Image;
|
|
12
|
+
inspections: Inspections;
|
|
13
|
+
/**
|
|
14
|
+
* Create Autoinspector SDK.
|
|
15
|
+
* @constructor
|
|
16
|
+
* @see {@link https://autoinspector.com.ar/docs/api/start}
|
|
17
|
+
* @param input - An object with credentials and configuration.
|
|
18
|
+
*/
|
|
19
|
+
constructor(input: IAutoinspector);
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 package_json_1 = __importDefault(require("../package.json"));
|
|
8
|
+
const HTTPClient_1 = require("./HTTPClient");
|
|
9
|
+
const Image_1 = require("./Image");
|
|
10
|
+
const Inspections_1 = require("./Inspections");
|
|
11
|
+
const OAuth_1 = require("./OAuth");
|
|
12
|
+
/**
|
|
13
|
+
* @classdesc Represents the Autoinspector SDK. It allows the user to make every call to the API with a single function.
|
|
14
|
+
* @class
|
|
15
|
+
*/
|
|
16
|
+
class Autoinspector {
|
|
17
|
+
/**
|
|
18
|
+
* Create Autoinspector SDK.
|
|
19
|
+
* @constructor
|
|
20
|
+
* @see {@link https://autoinspector.com.ar/docs/api/start}
|
|
21
|
+
* @param input - An object with credentials and configuration.
|
|
22
|
+
*/
|
|
23
|
+
constructor(input) {
|
|
24
|
+
if (typeof input.apikey !== 'string') {
|
|
25
|
+
throw new Error('apikey should be a string.');
|
|
26
|
+
}
|
|
27
|
+
const httpClient = new HTTPClient_1.HTTPClient({
|
|
28
|
+
baseURL: process.env.AUTOINSPECTOR_API_BASE_URL || 'https://api.autoinspector.com.ar',
|
|
29
|
+
headers: {
|
|
30
|
+
'x-api-key': input.apikey,
|
|
31
|
+
'User-Agent': 'autoinspector-node-sdk/' + package_json_1.default.version,
|
|
32
|
+
},
|
|
33
|
+
timeout: input.timeout || 80000,
|
|
34
|
+
pathPrefix: '/v1',
|
|
35
|
+
});
|
|
36
|
+
this.oauth = new OAuth_1.OAuth(httpClient, input.oauthCredentials || {});
|
|
37
|
+
this.inspections = new Inspections_1.Inspections(httpClient);
|
|
38
|
+
this.images = new Image_1.Image(httpClient);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Autoinspector = Autoinspector;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ICreateCarInspection } from '../types/car';
|
|
2
|
+
import { ICreateInspectionOutput } from '../types/inspection';
|
|
3
|
+
import { HTTPClient } from './HTTPClient';
|
|
4
|
+
export declare class Car {
|
|
5
|
+
private readonly httpClient;
|
|
6
|
+
constructor(httpClient: HTTPClient);
|
|
7
|
+
create(input: ICreateCarInspection): Promise<ICreateInspectionOutput>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Car = void 0;
|
|
27
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
28
|
+
const Helper_1 = require("./Helper");
|
|
29
|
+
class Car {
|
|
30
|
+
constructor(httpClient) {
|
|
31
|
+
this.httpClient = httpClient;
|
|
32
|
+
}
|
|
33
|
+
create(input) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const form = new form_data_1.default();
|
|
36
|
+
const { inputValues } = input, rest = __rest(input, ["inputValues"]);
|
|
37
|
+
const inputValuesNonFiles = [];
|
|
38
|
+
for (const inputValue of inputValues) {
|
|
39
|
+
const isFile = inputValue.value instanceof Buffer || Helper_1.Helper.isFile(inputValue.value);
|
|
40
|
+
if (isFile) {
|
|
41
|
+
form.append(inputValue.label, inputValue.value instanceof Buffer ? inputValue.value : Helper_1.Helper.readFile(inputValue.value));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
inputValuesNonFiles.push(inputValue);
|
|
45
|
+
}
|
|
46
|
+
form.append('data', JSON.stringify(Object.assign(Object.assign({}, rest), { inputValues: inputValuesNonFiles })));
|
|
47
|
+
return yield this.httpClient.makeRequest({
|
|
48
|
+
method: 'POST',
|
|
49
|
+
path: `/inspection/car`,
|
|
50
|
+
body: input,
|
|
51
|
+
headers: form.getHeaders(),
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.Car = Car;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IUpdateResourceResponse } from '../types/api';
|
|
2
|
+
import { ICreateGoodsInspection, IUpdateGoodsInspection } from '../types/goods';
|
|
3
|
+
import { ICreateInspectionGoodsOutput } from '../types/inspection';
|
|
4
|
+
import { IProductService } from '../types/productMethods';
|
|
5
|
+
import { HTTPClient } from './HTTPClient';
|
|
6
|
+
export declare class Goods implements IProductService {
|
|
7
|
+
private readonly httpClient;
|
|
8
|
+
constructor(httpClient: HTTPClient);
|
|
9
|
+
/**
|
|
10
|
+
* Create an inspection that will contains goods.
|
|
11
|
+
* @param input - An object that contains the essential information for create an inspection.
|
|
12
|
+
* @param {Object} input.consumer - Represents the consumer who will do the inspection.
|
|
13
|
+
* @param {Object} input.goods - Represents the goods to be attached to the inspection.
|
|
14
|
+
* @param {String} input.mode - Represents the mode of the inspection. See more details: {@link https://www.autoinspector.com.ar/docs/api/start#inspection_mode}
|
|
15
|
+
* @param {String} input.kindOf - Represents the template that inspection will have. This only matters if the input.mode is normal.
|
|
16
|
+
* @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
|
|
17
|
+
* @param {Object} input.producer - Represents the entity that has the ownership of the inspection to be created.
|
|
18
|
+
* @param {Object} input.access_token - Represents the token that belongs to some user into Autoinspector and was generated thanks to OAuth 2.0. When pass this argument, the apikey will not being send.
|
|
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: ICreateGoodsInspection): Promise<ICreateInspectionGoodsOutput>;
|
|
23
|
+
/**
|
|
24
|
+
* Update a specific product.
|
|
25
|
+
* @param input - An object that contains information that .
|
|
26
|
+
* @param {String} input.productId - Represents the product unique identifier.
|
|
27
|
+
* @param {Object} input.consumer - Represents the consumer who will do the inspection.
|
|
28
|
+
* @param {Object} input.good - The information to update of the product.
|
|
29
|
+
* @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
|
|
30
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
31
|
+
* data or an Error with the problem.
|
|
32
|
+
*/
|
|
33
|
+
update(input: IUpdateGoodsInspection): Promise<IUpdateResourceResponse>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Goods = void 0;
|
|
4
|
+
const Helper_1 = require("./Helper");
|
|
5
|
+
class Goods {
|
|
6
|
+
constructor(httpClient) {
|
|
7
|
+
this.httpClient = httpClient;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create an inspection that will contains goods.
|
|
11
|
+
* @param input - An object that contains the essential information for create an inspection.
|
|
12
|
+
* @param {Object} input.consumer - Represents the consumer who will do the inspection.
|
|
13
|
+
* @param {Object} input.goods - Represents the goods to be attached to the inspection.
|
|
14
|
+
* @param {String} input.mode - Represents the mode of the inspection. See more details: {@link https://www.autoinspector.com.ar/docs/api/start#inspection_mode}
|
|
15
|
+
* @param {String} input.kindOf - Represents the template that inspection will have. This only matters if the input.mode is normal.
|
|
16
|
+
* @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
|
|
17
|
+
* @param {Object} input.producer - Represents the entity that has the ownership of the inspection to be created.
|
|
18
|
+
* @param {Object} input.access_token - Represents the token that belongs to some user into Autoinspector and was generated thanks to OAuth 2.0. When pass this argument, the apikey will not being send.
|
|
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.access_token),
|
|
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
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
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<F = any>(input: IMakeRequest): Promise<F>;
|
|
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), (!input.withoutPredefinedHeaders ? 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,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IHeaders } from '../types/http';
|
|
3
|
+
export declare class Helper {
|
|
4
|
+
static buildOptionalHeaders(access_token?: string): IHeaders | undefined;
|
|
5
|
+
static isNode(): boolean;
|
|
6
|
+
static isFile(path: string): boolean;
|
|
7
|
+
static readFile(path: string): Buffer;
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Helper = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
class Helper {
|
|
6
|
+
static buildOptionalHeaders(access_token) {
|
|
7
|
+
if (access_token) {
|
|
8
|
+
return {
|
|
9
|
+
Authorization: `Bearer ${access_token}`,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
static isNode() {
|
|
15
|
+
return typeof window === 'undefined';
|
|
16
|
+
}
|
|
17
|
+
static isFile(path) {
|
|
18
|
+
try {
|
|
19
|
+
var stat = (0, fs_1.lstatSync)(path);
|
|
20
|
+
return stat.isFile();
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
static readFile(path) {
|
|
27
|
+
return (0, fs_1.readFileSync)(path);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Helper = Helper;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IAPISucessResponse } from '../types/api';
|
|
2
|
+
import { IUploadImage } from '../types/image';
|
|
3
|
+
import { HTTPClient } from './HTTPClient';
|
|
4
|
+
import { IImageToken } from '../types/inspection';
|
|
5
|
+
export declare class Image {
|
|
6
|
+
private readonly httpRef;
|
|
7
|
+
constructor(httpRef: HTTPClient);
|
|
8
|
+
/**
|
|
9
|
+
* Generates an image token.
|
|
10
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
11
|
+
* data or an Error with the problem.
|
|
12
|
+
*/
|
|
13
|
+
generateToken(): Promise<IImageToken>;
|
|
14
|
+
/**
|
|
15
|
+
* Upload an image for specific product inspection item. For the moment, this method is only available for the inspection with mode full_control.
|
|
16
|
+
* @param input - An object that contains the essential information for upload the image.
|
|
17
|
+
* @param {String} input.productId - Represents the id of the product that you would like to attach a new photo.
|
|
18
|
+
* @param {ReadStream} input.image - Represents the image to upload.
|
|
19
|
+
* @param {String} input.side - Represents the side of the image/photo to upload.
|
|
20
|
+
* @param {String} input.date - Represents the date when the photo was taken. If you can extract this information from the EXIF data, it's better because it's more reliable.
|
|
21
|
+
* @param {Object} input.coordinates - Represents the coordinates of the image/photo.
|
|
22
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
23
|
+
* data or an Error with the problem.
|
|
24
|
+
*/
|
|
25
|
+
uploadImage(input: IUploadImage): Promise<IAPISucessResponse>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
* Generates an image token.
|
|
14
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
15
|
+
* data or an Error with the problem.
|
|
16
|
+
*/
|
|
17
|
+
generateToken() {
|
|
18
|
+
return this.httpRef.makeRequest({
|
|
19
|
+
method: 'POST',
|
|
20
|
+
path: `/inspection/image/token`,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Upload an image for specific product inspection item. For the moment, this method is only available for the inspection with mode full_control.
|
|
25
|
+
* @param input - An object that contains the essential information for upload the image.
|
|
26
|
+
* @param {String} input.productId - Represents the id of the product that you would like to attach a new photo.
|
|
27
|
+
* @param {ReadStream} input.image - Represents the image to upload.
|
|
28
|
+
* @param {String} input.side - Represents the side of the image/photo to upload.
|
|
29
|
+
* @param {String} input.date - Represents the date when the photo was taken. If you can extract this information from the EXIF data, it's better because it's more reliable.
|
|
30
|
+
* @param {Object} input.coordinates - Represents the coordinates of the image/photo.
|
|
31
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
32
|
+
* data or an Error with the problem.
|
|
33
|
+
*/
|
|
34
|
+
uploadImage(input) {
|
|
35
|
+
const form = new form_data_1.default();
|
|
36
|
+
form.append('side', input.side);
|
|
37
|
+
form.append('image', input.image);
|
|
38
|
+
if (input.coordinates) {
|
|
39
|
+
form.append('coordinates', JSON.stringify(input.coordinates));
|
|
40
|
+
}
|
|
41
|
+
if (input.date) {
|
|
42
|
+
form.append('date', input.date.toISOString());
|
|
43
|
+
}
|
|
44
|
+
return this.httpRef.makeRequest({
|
|
45
|
+
method: 'POST',
|
|
46
|
+
path: `/inspection/image/${input.productId}`,
|
|
47
|
+
body: form,
|
|
48
|
+
headers: Object.assign(Object.assign({}, form.getHeaders()), (input.imageToken ? { 'x-image-token': input.imageToken } : {})),
|
|
49
|
+
withoutPredefinedHeaders: !!input.imageToken,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.Image = Image;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IAPISucessResponse } from '../types/api';
|
|
2
|
+
import { IFinishInspection, IGetInspection, IInspection } from '../types/inspection';
|
|
3
|
+
import { IPagination, IPaginationResponse } from '../types/pagination';
|
|
4
|
+
import { HTTPClient } from './HTTPClient';
|
|
5
|
+
import { Products } from './Products';
|
|
6
|
+
/**
|
|
7
|
+
* @classdesc Represents the class that contains the methods or actions that somebody can do using apikey and access_token.
|
|
8
|
+
* @class
|
|
9
|
+
*/
|
|
10
|
+
export declare class Inspections extends Products {
|
|
11
|
+
private readonly httpClient;
|
|
12
|
+
constructor(httpClient: HTTPClient);
|
|
13
|
+
/**
|
|
14
|
+
* Finish the inspection to indicate that it will not receive more photos/images.
|
|
15
|
+
* @param input - An object that contains the essential information for upload the image.
|
|
16
|
+
* @param {String} input.inspectionId - Represents the id of the inspection.
|
|
17
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
18
|
+
* data or an Error with the problem.
|
|
19
|
+
*/
|
|
20
|
+
finish(input: IFinishInspection): Promise<IAPISucessResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Get a specific inspection object.
|
|
23
|
+
* @param input - An object that contains the essential information for upload the image.
|
|
24
|
+
* @param {String} input.inspectionId - Represents the id of the inspection that you want to retrieve.
|
|
25
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
26
|
+
* data or an Error with the problem.
|
|
27
|
+
*/
|
|
28
|
+
retrieve(input: IGetInspection): Promise<IInspection>;
|
|
29
|
+
/**
|
|
30
|
+
* Get a list of n inspections with pagination.
|
|
31
|
+
* @param input - An object that contains filters for list the inspections.
|
|
32
|
+
* @param {Number} input.page - Represents the specific page that you want to retrieve the inspections.
|
|
33
|
+
* @param {Number} input.limit - Represents the limit of the quantity of records that you want to retrieve for page.
|
|
34
|
+
* @param {String} input.status - Represents the status that inspections retrieved should have.
|
|
35
|
+
* @param {String} input.type - Represents the type of the inspection.
|
|
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
|
+
list(input?: Partial<IPagination>): Promise<IPaginationResponse<IInspection[]>>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Inspections = void 0;
|
|
4
|
+
const Products_1 = require("./Products");
|
|
5
|
+
/**
|
|
6
|
+
* @classdesc Represents the class that contains the methods or actions that somebody can do using apikey and access_token.
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class Inspections extends Products_1.Products {
|
|
10
|
+
constructor(httpClient) {
|
|
11
|
+
super(httpClient);
|
|
12
|
+
this.httpClient = httpClient;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Finish the inspection to indicate that it will not receive more photos/images.
|
|
16
|
+
* @param input - An object that contains the essential information for upload the image.
|
|
17
|
+
* @param {String} input.inspectionId - Represents the id of the inspection.
|
|
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
|
+
finish(input) {
|
|
22
|
+
return this.httpClient.makeRequest({
|
|
23
|
+
method: 'POST',
|
|
24
|
+
path: `/inspection/finish/${input.inspectionId}`,
|
|
25
|
+
body: {},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get a specific inspection object.
|
|
30
|
+
* @param input - An object that contains the essential information for upload the image.
|
|
31
|
+
* @param {String} input.inspectionId - Represents the id of the inspection that you want to retrieve.
|
|
32
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
33
|
+
* data or an Error with the problem.
|
|
34
|
+
*/
|
|
35
|
+
retrieve(input) {
|
|
36
|
+
return this.httpClient.makeRequest({
|
|
37
|
+
method: 'GET',
|
|
38
|
+
path: `/inspection/${input.inspectionId}`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get a list of n inspections with pagination.
|
|
43
|
+
* @param input - An object that contains filters for list the inspections.
|
|
44
|
+
* @param {Number} input.page - Represents the specific page that you want to retrieve the inspections.
|
|
45
|
+
* @param {Number} input.limit - Represents the limit of the quantity of records that you want to retrieve for page.
|
|
46
|
+
* @param {String} input.status - Represents the status that inspections retrieved should have.
|
|
47
|
+
* @param {String} input.type - Represents the type of the inspection.
|
|
48
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
49
|
+
* data or an Error with the problem.
|
|
50
|
+
*/
|
|
51
|
+
list(input = {}) {
|
|
52
|
+
return this.httpClient.makeRequest({
|
|
53
|
+
method: 'GET',
|
|
54
|
+
path: `/inspection`,
|
|
55
|
+
params: input,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Inspections = Inspections;
|