autoinspector 1.1.2 → 2.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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -3
- package/dist/package.json +1 -1
- package/dist/resources/Autoinspector.d.ts +4 -0
- package/dist/resources/Autoinspector.js +14 -9
- package/dist/resources/Car.d.ts +5 -2
- package/dist/resources/Car.js +62 -37
- package/dist/resources/Custom.d.ts +9 -0
- package/dist/resources/Custom.js +65 -0
- package/dist/resources/Goods.d.ts +4 -15
- package/dist/resources/Goods.js +40 -24
- package/dist/resources/HTTPClient.js +33 -20
- package/dist/resources/Helper.d.ts +10 -2
- package/dist/resources/Helper.js +77 -13
- package/dist/resources/Image.d.ts +4 -9
- package/dist/resources/Image.js +43 -28
- package/dist/resources/Inspections.d.ts +5 -2
- package/dist/resources/Inspections.js +44 -15
- package/dist/resources/Machinery.d.ts +4 -14
- package/dist/resources/Machinery.js +26 -23
- package/dist/resources/Memberships.js +8 -7
- package/dist/resources/Moto.d.ts +11 -0
- package/dist/resources/Moto.js +81 -0
- package/dist/resources/OAuth.js +22 -10
- package/dist/resources/People.d.ts +3 -13
- package/dist/resources/People.js +22 -24
- package/dist/resources/Products.d.ts +6 -2
- package/dist/resources/Products.js +13 -8
- package/dist/resources/Template.d.ts +2 -1
- package/dist/resources/Template.js +57 -10
- package/dist/resources/User.js +33 -14
- package/dist/resources/Webhooks.d.ts +4 -0
- package/dist/resources/Webhooks.js +41 -0
- package/dist/types/car.d.ts +9 -0
- package/dist/types/goods.d.ts +2 -12
- package/dist/types/helper.d.ts +5 -0
- package/dist/types/{vehicle.js → helper.js} +0 -0
- package/dist/types/inspection.d.ts +38 -26
- package/dist/types/machinery.d.ts +2 -9
- package/dist/types/moto.d.ts +6 -0
- package/dist/types/moto.js +2 -0
- package/dist/types/pagination.d.ts +0 -1
- package/dist/types/people.d.ts +2 -4
- package/dist/types/productMethods.d.ts +4 -3
- package/dist/types/template.d.ts +3 -2
- package/dist/types/webhooks.d.ts +63 -0
- package/dist/types/webhooks.js +2 -0
- package/index.ts +1 -1
- package/package.json +1 -1
- package/dist/resources/Vehicle.d.ts +0 -33
- package/dist/resources/Vehicle.js +0 -47
- package/dist/types/vehicle.d.ts +0 -116
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Autoinspector } from './resources/Autoinspector';
|
|
2
|
-
export
|
|
2
|
+
export = Autoinspector;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.default = Autoinspector_1.Autoinspector;
|
|
2
|
+
var Autoinspector_1 = require("./resources/Autoinspector");
|
|
3
|
+
module.exports = Autoinspector_1.Autoinspector;
|
package/dist/package.json
CHANGED
|
@@ -2,6 +2,8 @@ import { IAutoinspector } from '../types/autoinspector';
|
|
|
2
2
|
import { Image } from './Image';
|
|
3
3
|
import { Inspections } from './Inspections';
|
|
4
4
|
import { OAuth } from './OAuth';
|
|
5
|
+
import { Template } from './Template';
|
|
6
|
+
import { Webhooks } from './Webhooks';
|
|
5
7
|
/**
|
|
6
8
|
* @classdesc Represents the Autoinspector SDK. It allows the user to make every call to the API with a single function.
|
|
7
9
|
* @class
|
|
@@ -10,6 +12,8 @@ export declare class Autoinspector {
|
|
|
10
12
|
oauth: OAuth;
|
|
11
13
|
images: Image;
|
|
12
14
|
inspections: Inspections;
|
|
15
|
+
webhooks: Webhooks;
|
|
16
|
+
templates: Template;
|
|
13
17
|
/**
|
|
14
18
|
* Create Autoinspector SDK.
|
|
15
19
|
* @constructor
|
|
@@ -4,27 +4,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Autoinspector = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
var package_json_1 = __importDefault(require("../package.json"));
|
|
8
|
+
var HTTPClient_1 = require("./HTTPClient");
|
|
9
|
+
var Image_1 = require("./Image");
|
|
10
|
+
var Inspections_1 = require("./Inspections");
|
|
11
|
+
var OAuth_1 = require("./OAuth");
|
|
12
|
+
var Template_1 = require("./Template");
|
|
13
|
+
var Webhooks_1 = require("./Webhooks");
|
|
12
14
|
/**
|
|
13
15
|
* @classdesc Represents the Autoinspector SDK. It allows the user to make every call to the API with a single function.
|
|
14
16
|
* @class
|
|
15
17
|
*/
|
|
16
|
-
|
|
18
|
+
var Autoinspector = /** @class */ (function () {
|
|
17
19
|
/**
|
|
18
20
|
* Create Autoinspector SDK.
|
|
19
21
|
* @constructor
|
|
20
22
|
* @see {@link https://autoinspector.com.ar/docs/api/start}
|
|
21
23
|
* @param input - An object with credentials and configuration.
|
|
22
24
|
*/
|
|
23
|
-
|
|
25
|
+
function Autoinspector(input) {
|
|
24
26
|
if (typeof input.apikey !== 'string') {
|
|
25
27
|
throw new Error('apikey should be a string.');
|
|
26
28
|
}
|
|
27
|
-
|
|
29
|
+
var httpClient = new HTTPClient_1.HTTPClient({
|
|
28
30
|
baseURL: process.env.AUTOINSPECTOR_API_BASE_URL || 'https://api.autoinspector.com.ar',
|
|
29
31
|
headers: {
|
|
30
32
|
'x-api-key': input.apikey,
|
|
@@ -36,6 +38,9 @@ class Autoinspector {
|
|
|
36
38
|
this.oauth = new OAuth_1.OAuth(httpClient, input.oauthCredentials || {});
|
|
37
39
|
this.inspections = new Inspections_1.Inspections(httpClient);
|
|
38
40
|
this.images = new Image_1.Image(httpClient);
|
|
41
|
+
this.templates = new Template_1.Template(httpClient);
|
|
42
|
+
this.webhooks = new Webhooks_1.Webhooks();
|
|
39
43
|
}
|
|
40
|
-
|
|
44
|
+
return Autoinspector;
|
|
45
|
+
}());
|
|
41
46
|
exports.Autoinspector = Autoinspector;
|
package/dist/resources/Car.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IUpdateResourceResponse } from '../types/api';
|
|
2
|
+
import { ICar, ICreateCarInspection } from '../types/car';
|
|
2
3
|
import { ICreateInspectionOutput } from '../types/inspection';
|
|
4
|
+
import { IProductMethods } from '../types/productMethods';
|
|
3
5
|
import { HTTPClient } from './HTTPClient';
|
|
4
|
-
export declare class Car {
|
|
6
|
+
export declare class Car implements IProductMethods<ICreateCarInspection, Partial<ICar>> {
|
|
5
7
|
private readonly httpClient;
|
|
6
8
|
constructor(httpClient: HTTPClient);
|
|
7
9
|
create(input: ICreateCarInspection): Promise<ICreateInspectionOutput>;
|
|
10
|
+
update(productId: string, car: Partial<ICar>): Promise<IUpdateResourceResponse>;
|
|
8
11
|
}
|
package/dist/resources/Car.js
CHANGED
|
@@ -8,49 +8,74 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
24
37
|
};
|
|
25
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
39
|
exports.Car = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
constructor(httpClient) {
|
|
40
|
+
var Helper_1 = require("./Helper");
|
|
41
|
+
var Car = /** @class */ (function () {
|
|
42
|
+
function Car(httpClient) {
|
|
31
43
|
this.httpClient = httpClient;
|
|
32
44
|
}
|
|
33
|
-
create(input) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
Car.prototype.create = function (input) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
var form;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
form = Helper_1.Helper.buildFormData(input).form;
|
|
52
|
+
return [4 /*yield*/, this.httpClient.makeRequest({
|
|
53
|
+
method: 'POST',
|
|
54
|
+
path: "/inspection/car",
|
|
55
|
+
body: form,
|
|
56
|
+
headers: form.getHeaders(),
|
|
57
|
+
})];
|
|
58
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
43
59
|
}
|
|
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
60
|
});
|
|
53
61
|
});
|
|
54
|
-
}
|
|
55
|
-
|
|
62
|
+
};
|
|
63
|
+
Car.prototype.update = function (productId, car) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
switch (_a.label) {
|
|
67
|
+
case 0: return [4 /*yield*/, this.httpClient.makeRequest({
|
|
68
|
+
method: 'PUT',
|
|
69
|
+
path: "/inspection/car/".concat(productId),
|
|
70
|
+
body: {
|
|
71
|
+
car: car,
|
|
72
|
+
},
|
|
73
|
+
})];
|
|
74
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
return Car;
|
|
80
|
+
}());
|
|
56
81
|
exports.Car = Car;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ICreateInspectionOutput } from '../types/inspection';
|
|
2
|
+
import { ICreatePeopleInspection } from '../types/people';
|
|
3
|
+
import { IProductMethods } from '../types/productMethods';
|
|
4
|
+
import { HTTPClient } from './HTTPClient';
|
|
5
|
+
export declare class Custom implements IProductMethods<ICreatePeopleInspection> {
|
|
6
|
+
private readonly httpClient;
|
|
7
|
+
constructor(httpClient: HTTPClient);
|
|
8
|
+
create(input: ICreatePeopleInspection): Promise<ICreateInspectionOutput>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Custom = void 0;
|
|
40
|
+
var Helper_1 = require("./Helper");
|
|
41
|
+
var Custom = /** @class */ (function () {
|
|
42
|
+
function Custom(httpClient) {
|
|
43
|
+
this.httpClient = httpClient;
|
|
44
|
+
}
|
|
45
|
+
Custom.prototype.create = function (input) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
var form;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
form = Helper_1.Helper.buildFormData(input).form;
|
|
52
|
+
return [4 /*yield*/, this.httpClient.makeRequest({
|
|
53
|
+
method: 'POST',
|
|
54
|
+
path: "/inspection/custom",
|
|
55
|
+
body: form,
|
|
56
|
+
headers: form.getHeaders(),
|
|
57
|
+
})];
|
|
58
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
return Custom;
|
|
64
|
+
}());
|
|
65
|
+
exports.Custom = Custom;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ICreateGoodsInspection, IUpdateGoodsInspection } from '../types/goods';
|
|
1
|
+
import { ICreateGoodsInspection, IGood } from '../types/goods';
|
|
3
2
|
import { ICreateInspectionGoodsOutput } from '../types/inspection';
|
|
4
|
-
import { IProductService } from '../types/productMethods';
|
|
5
3
|
import { HTTPClient } from './HTTPClient';
|
|
6
|
-
export declare class Goods
|
|
4
|
+
export declare class Goods {
|
|
7
5
|
private readonly httpClient;
|
|
8
6
|
constructor(httpClient: HTTPClient);
|
|
9
7
|
/**
|
|
@@ -20,15 +18,6 @@ export declare class Goods implements IProductService {
|
|
|
20
18
|
* data or an Error with the problem.
|
|
21
19
|
*/
|
|
22
20
|
create(input: ICreateGoodsInspection): Promise<ICreateInspectionGoodsOutput>;
|
|
23
|
-
|
|
24
|
-
|
|
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>;
|
|
21
|
+
push(inspectionId: string, goods: IGood[]): Promise<ICreateInspectionGoodsOutput>;
|
|
22
|
+
update(productId: string, good: Partial<Omit<IGood, 'type' | 'category'>>): Promise<ICreateInspectionGoodsOutput>;
|
|
34
23
|
}
|
package/dist/resources/Goods.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.Goods = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
15
|
+
var Helper_1 = require("./Helper");
|
|
16
|
+
var Goods = /** @class */ (function () {
|
|
17
|
+
function Goods(httpClient) {
|
|
7
18
|
this.httpClient = httpClient;
|
|
8
19
|
}
|
|
9
20
|
/**
|
|
@@ -19,30 +30,35 @@ class Goods {
|
|
|
19
30
|
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
20
31
|
* data or an Error with the problem.
|
|
21
32
|
*/
|
|
22
|
-
create(input) {
|
|
33
|
+
Goods.prototype.create = function (input) {
|
|
34
|
+
var form = Helper_1.Helper.buildFormData(input).form;
|
|
23
35
|
return this.httpClient.makeRequest({
|
|
24
36
|
method: 'POST',
|
|
25
|
-
path:
|
|
26
|
-
body:
|
|
27
|
-
headers: Helper_1.Helper.buildOptionalHeaders(input.access_token),
|
|
37
|
+
path: "/inspection/goods",
|
|
38
|
+
body: form,
|
|
39
|
+
headers: __assign(__assign({}, Helper_1.Helper.buildOptionalHeaders(input.access_token)), form.getHeaders()),
|
|
28
40
|
});
|
|
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
|
+
};
|
|
42
|
+
Goods.prototype.push = function (inspectionId, goods) {
|
|
41
43
|
return this.httpClient.makeRequest({
|
|
42
|
-
method: '
|
|
43
|
-
path:
|
|
44
|
-
body:
|
|
44
|
+
method: 'POST',
|
|
45
|
+
path: "/inspection/goods/".concat(inspectionId),
|
|
46
|
+
body: {
|
|
47
|
+
goods: goods,
|
|
48
|
+
},
|
|
49
|
+
headers: __assign({}, Helper_1.Helper.buildOptionalHeaders()),
|
|
45
50
|
});
|
|
46
|
-
}
|
|
47
|
-
|
|
51
|
+
};
|
|
52
|
+
Goods.prototype.update = function (productId, good) {
|
|
53
|
+
return this.httpClient.makeRequest({
|
|
54
|
+
method: 'POST',
|
|
55
|
+
path: "/inspection/goods/".concat(productId),
|
|
56
|
+
body: {
|
|
57
|
+
good: good,
|
|
58
|
+
},
|
|
59
|
+
headers: __assign({}, Helper_1.Helper.buildOptionalHeaders()),
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return Goods;
|
|
63
|
+
}());
|
|
48
64
|
exports.Goods = Goods;
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
17
|
exports.HTTPClient = void 0;
|
|
7
|
-
|
|
18
|
+
var axios_1 = __importDefault(require("axios"));
|
|
8
19
|
/**
|
|
9
20
|
* @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
21
|
* @class
|
|
11
22
|
*/
|
|
12
|
-
|
|
23
|
+
var HTTPClient = /** @class */ (function () {
|
|
13
24
|
/**
|
|
14
25
|
* Create HTTPClient instance to start making request in another class.
|
|
15
26
|
* @constructor
|
|
@@ -18,7 +29,7 @@ class HTTPClient {
|
|
|
18
29
|
* @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
30
|
* @param {Object} input.baseURL - The baseURL to make the requests.
|
|
20
31
|
*/
|
|
21
|
-
|
|
32
|
+
function HTTPClient(input) {
|
|
22
33
|
this.headers = {};
|
|
23
34
|
this.headers = input.headers;
|
|
24
35
|
this.timeout = input.timeout;
|
|
@@ -35,10 +46,11 @@ class HTTPClient {
|
|
|
35
46
|
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
36
47
|
* data or an Error with the problem.
|
|
37
48
|
*/
|
|
38
|
-
makeRequest(input) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
HTTPClient.prototype.makeRequest = function (input) {
|
|
50
|
+
var _this = this;
|
|
51
|
+
var path = "".concat(this.baseURL).concat(this.pathPrefix).concat(input.path);
|
|
52
|
+
var options = {
|
|
53
|
+
headers: __assign(__assign({}, input.headers), (!input.withoutPredefinedHeaders ? this.headers : {})),
|
|
42
54
|
params: input.params,
|
|
43
55
|
timeout: this.timeout,
|
|
44
56
|
};
|
|
@@ -46,42 +58,43 @@ class HTTPClient {
|
|
|
46
58
|
case 'GET':
|
|
47
59
|
return axios_1.default
|
|
48
60
|
.get(path, options)
|
|
49
|
-
.then((res)
|
|
61
|
+
.then(function (res) {
|
|
50
62
|
return res.data;
|
|
51
63
|
})
|
|
52
|
-
.catch((err)
|
|
64
|
+
.catch(function (err) { return _this.handleError(err); });
|
|
53
65
|
case 'PUT':
|
|
54
66
|
return axios_1.default
|
|
55
67
|
.put(path, input.body, options)
|
|
56
|
-
.then((res)
|
|
68
|
+
.then(function (res) {
|
|
57
69
|
return res.data;
|
|
58
70
|
})
|
|
59
|
-
.catch((err)
|
|
71
|
+
.catch(function (err) { return _this.handleError(err); });
|
|
60
72
|
case 'POST':
|
|
61
73
|
return axios_1.default
|
|
62
74
|
.post(path, input.body, options)
|
|
63
|
-
.then((res)
|
|
75
|
+
.then(function (res) {
|
|
64
76
|
return res.data;
|
|
65
77
|
})
|
|
66
|
-
.catch((err)
|
|
78
|
+
.catch(function (err) { return _this.handleError(err); });
|
|
67
79
|
case 'DELETE':
|
|
68
80
|
return axios_1.default
|
|
69
81
|
.post(path, input.body, options)
|
|
70
|
-
.then((res)
|
|
82
|
+
.then(function (res) {
|
|
71
83
|
return res.data;
|
|
72
84
|
})
|
|
73
|
-
.catch((err)
|
|
85
|
+
.catch(function (err) { return _this.handleError(err); });
|
|
74
86
|
}
|
|
75
|
-
}
|
|
76
|
-
handleError(err) {
|
|
87
|
+
};
|
|
88
|
+
HTTPClient.prototype.handleError = function (err) {
|
|
77
89
|
var _a;
|
|
78
|
-
|
|
90
|
+
var isAxiosError = axios_1.default.isAxiosError(err);
|
|
79
91
|
if (isAxiosError) {
|
|
80
92
|
return Promise.reject((_a = err.response) === null || _a === void 0 ? void 0 : _a.data);
|
|
81
93
|
}
|
|
82
94
|
if (!isAxiosError) {
|
|
83
95
|
return Promise.reject(err);
|
|
84
96
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
97
|
+
};
|
|
98
|
+
return HTTPClient;
|
|
99
|
+
}());
|
|
87
100
|
exports.HTTPClient = HTTPClient;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import FormData from 'form-data';
|
|
2
|
+
import { IFilterInputValuesOutput } from '../types/helper';
|
|
2
3
|
import { IHeaders } from '../types/http';
|
|
4
|
+
import { IInputValue } from '../types/inspection';
|
|
3
5
|
export declare class Helper {
|
|
4
6
|
static buildOptionalHeaders(access_token?: string): IHeaders | undefined;
|
|
5
7
|
static isNode(): boolean;
|
|
6
8
|
static isFile(path: string): boolean;
|
|
7
|
-
static
|
|
9
|
+
static filterInputs(inputs: IInputValue[]): IFilterInputValuesOutput;
|
|
10
|
+
static buildFormData(input: {
|
|
11
|
+
inputs?: IInputValue[];
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}): {
|
|
14
|
+
form: FormData;
|
|
15
|
+
};
|
|
8
16
|
}
|
package/dist/resources/Helper.js
CHANGED
|
@@ -1,20 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
2
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
28
|
exports.Helper = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
29
|
+
var form_data_1 = __importDefault(require("form-data"));
|
|
30
|
+
var fs_1 = require("fs");
|
|
31
|
+
var Helper = /** @class */ (function () {
|
|
32
|
+
function Helper() {
|
|
33
|
+
}
|
|
34
|
+
Helper.buildOptionalHeaders = function (access_token) {
|
|
7
35
|
if (access_token) {
|
|
8
36
|
return {
|
|
9
|
-
Authorization:
|
|
37
|
+
Authorization: "Bearer ".concat(access_token),
|
|
10
38
|
};
|
|
11
39
|
}
|
|
12
40
|
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
41
|
+
};
|
|
42
|
+
Helper.isNode = function () {
|
|
15
43
|
return typeof window === 'undefined';
|
|
16
|
-
}
|
|
17
|
-
|
|
44
|
+
};
|
|
45
|
+
Helper.isFile = function (path) {
|
|
18
46
|
try {
|
|
19
47
|
var stat = (0, fs_1.lstatSync)(path);
|
|
20
48
|
return stat.isFile();
|
|
@@ -22,9 +50,45 @@ class Helper {
|
|
|
22
50
|
catch (e) {
|
|
23
51
|
return false;
|
|
24
52
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
53
|
+
};
|
|
54
|
+
Helper.filterInputs = function (inputs) {
|
|
55
|
+
var inputValuesNonFiles = [];
|
|
56
|
+
var inputValuesFiles = [];
|
|
57
|
+
for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
|
|
58
|
+
var inputValue = inputs_1[_i];
|
|
59
|
+
if (inputValue.value instanceof Buffer) {
|
|
60
|
+
inputValuesFiles.push(inputValue);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
inputValuesNonFiles.push(inputValue);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
inputValuesFiles: inputValuesFiles,
|
|
67
|
+
inputValuesNonFiles: inputValuesNonFiles,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
Helper.buildFormData = function (input) {
|
|
71
|
+
var form = new form_data_1.default();
|
|
72
|
+
if (!input.inputs) {
|
|
73
|
+
form.append('data', JSON.stringify(input));
|
|
74
|
+
return {
|
|
75
|
+
form: form,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
var inputs = input.inputs, rest = __rest(input, ["inputs"]);
|
|
79
|
+
var _a = this.filterInputs(inputs), inputValuesFiles = _a.inputValuesFiles, inputValuesNonFiles = _a.inputValuesNonFiles;
|
|
80
|
+
for (var _i = 0, inputValuesFiles_1 = inputValuesFiles; _i < inputValuesFiles_1.length; _i++) {
|
|
81
|
+
var inputFile = inputValuesFiles_1[_i];
|
|
82
|
+
form.append(inputFile.label, inputFile.value, {
|
|
83
|
+
contentType: inputFile.contentType,
|
|
84
|
+
filename: inputFile.filename,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
form.append('data', JSON.stringify(__assign(__assign({}, rest), { inputs: inputValuesNonFiles })));
|
|
88
|
+
return {
|
|
89
|
+
form: form,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
return Helper;
|
|
93
|
+
}());
|
|
30
94
|
exports.Helper = Helper;
|