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