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.
- package/.eslintrc.json +22 -0
- package/.prettierrc.json +7 -0
- package/README.md +79 -0
- package/build-sdk.sh +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/package.json +44 -0
- package/dist/resources/Autoinspector.d.ts +18 -0
- package/dist/resources/Autoinspector.js +39 -0
- package/dist/resources/Goods.d.ts +33 -0
- package/dist/resources/Goods.js +49 -0
- package/dist/resources/HTTPClient.d.ts +32 -0
- package/dist/resources/HTTPClient.js +87 -0
- package/dist/resources/Helper.d.ts +4 -0
- package/dist/resources/Helper.js +14 -0
- package/dist/resources/Image.d.ts +19 -0
- package/dist/resources/Image.js +42 -0
- package/dist/resources/Inspections.d.ts +51 -0
- package/dist/resources/Inspections.js +69 -0
- package/dist/resources/Machinery.d.ts +37 -0
- package/dist/resources/Machinery.js +53 -0
- package/dist/resources/OAuth20.d.ts +37 -0
- package/dist/resources/OAuth20.js +52 -0
- package/dist/resources/OAuthUser.d.ts +36 -0
- package/dist/resources/OAuthUser.js +53 -0
- package/dist/resources/People.d.ts +31 -0
- package/dist/resources/People.js +47 -0
- package/dist/resources/Vehicle.d.ts +32 -0
- package/dist/resources/Vehicle.js +48 -0
- package/dist/test/autoinspector.spec.d.ts +0 -0
- package/dist/test/autoinspector.spec.js +1 -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 +6 -0
- package/dist/types/autoinspector.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 +21 -0
- package/dist/types/http.js +2 -0
- package/dist/types/image.d.ts +14 -0
- package/dist/types/image.js +2 -0
- package/dist/types/inspection.d.ts +90 -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 +20 -0
- package/dist/types/pagination.js +2 -0
- package/dist/types/people.d.ts +45 -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 +5 -0
- package/dist/types/productMethods.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 +44 -0
- package/resources/Autoinspector.ts +39 -0
- package/resources/Goods.ts +52 -0
- package/resources/HTTPClient.ts +97 -0
- package/resources/Helper.ts +13 -0
- package/resources/Image.ts +45 -0
- package/resources/Inspections.ts +77 -0
- package/resources/Machinery.ts +56 -0
- package/resources/OAuth20.ts +69 -0
- package/resources/OAuthUser.ts +62 -0
- package/resources/People.ts +49 -0
- package/resources/Vehicle.ts +51 -0
- package/tsconfig.json +13 -0
- package/types/api.ts +15 -0
- package/types/authenticatedUser.ts +71 -0
- package/types/autoinspector.ts +7 -0
- package/types/colors.ts +10 -0
- package/types/configuration.ts +28 -0
- package/types/consumer.ts +15 -0
- package/types/goods.ts +102 -0
- package/types/http.ts +24 -0
- package/types/image.ts +77 -0
- package/types/inspection.ts +190 -0
- package/types/machinery.ts +106 -0
- package/types/oauth20.ts +23 -0
- package/types/pagination.ts +22 -0
- package/types/people.ts +58 -0
- package/types/producer.ts +4 -0
- package/types/productMethods.ts +7 -0
- package/types/vehicle.ts +148 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import axios, { AxiosResponse } from 'axios';
|
|
2
|
+
import { IHeaders, IHTTPClient, IMakeRequest } from '../types/http';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @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.
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
export class HTTPClient {
|
|
9
|
+
private headers: IHeaders = {};
|
|
10
|
+
private timeout: number;
|
|
11
|
+
private baseURL: string;
|
|
12
|
+
private pathPrefix: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create HTTPClient instance to start making request in another class.
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param input - An object with common parameters that we need to set in the http client third party library.
|
|
18
|
+
* @param {Object} input.headers - An object with the headers to send in each makeRequest() call.
|
|
19
|
+
* @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.
|
|
20
|
+
* @param {Object} input.baseURL - The baseURL to make the requests.
|
|
21
|
+
*/
|
|
22
|
+
constructor(input: IHTTPClient) {
|
|
23
|
+
this.headers = input.headers;
|
|
24
|
+
this.timeout = input.timeout;
|
|
25
|
+
this.baseURL = input.baseURL;
|
|
26
|
+
this.pathPrefix = input.pathPrefix;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Make a request to a specific endpoint.
|
|
31
|
+
* @param input - An object that contains the essential information make the request.
|
|
32
|
+
* @param {Object} input.method - Represents the method of the http request.
|
|
33
|
+
* @param {Object} input.path - Represents the path where the request will take place.
|
|
34
|
+
* @param {String} input.body - Represents the body to send. It only will be sended if input.method is not `GET`.
|
|
35
|
+
* @param {String} input.params - Represents the query parameters to send in the request. It only will be sended if input.method is `GET`.
|
|
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
|
+
public makeRequest(input: IMakeRequest): Promise<any> {
|
|
40
|
+
const path = `${this.baseURL}${this.pathPrefix}${input.path}`;
|
|
41
|
+
|
|
42
|
+
const options = {
|
|
43
|
+
headers: {
|
|
44
|
+
...input.headers,
|
|
45
|
+
...this.headers,
|
|
46
|
+
},
|
|
47
|
+
params: input.params,
|
|
48
|
+
timeout: this.timeout,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
switch (input.method) {
|
|
52
|
+
case 'GET':
|
|
53
|
+
return axios
|
|
54
|
+
.get(path, options)
|
|
55
|
+
.then((res: AxiosResponse<any>) => {
|
|
56
|
+
return res.data;
|
|
57
|
+
})
|
|
58
|
+
.catch((err) => this.handleError(err));
|
|
59
|
+
|
|
60
|
+
case 'PUT':
|
|
61
|
+
return axios
|
|
62
|
+
.put(path, input.body, options)
|
|
63
|
+
.then((res: AxiosResponse<any>) => {
|
|
64
|
+
return res.data;
|
|
65
|
+
})
|
|
66
|
+
.catch((err) => this.handleError(err));
|
|
67
|
+
|
|
68
|
+
case 'POST':
|
|
69
|
+
return axios
|
|
70
|
+
.post(path, input.body, options)
|
|
71
|
+
.then((res: AxiosResponse<any>) => {
|
|
72
|
+
return res.data;
|
|
73
|
+
})
|
|
74
|
+
.catch((err) => this.handleError(err));
|
|
75
|
+
|
|
76
|
+
case 'DELETE':
|
|
77
|
+
return axios
|
|
78
|
+
.post(path, input.body, options)
|
|
79
|
+
.then((res: AxiosResponse<any>) => {
|
|
80
|
+
return res.data;
|
|
81
|
+
})
|
|
82
|
+
.catch((err) => this.handleError(err));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private handleError(err: any) {
|
|
87
|
+
const isAxiosError = axios.isAxiosError(err);
|
|
88
|
+
|
|
89
|
+
if (isAxiosError) {
|
|
90
|
+
return Promise.reject(err.response?.data);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!isAxiosError) {
|
|
94
|
+
return Promise.reject(err);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IAPISucessResponse } from '../types/api';
|
|
2
|
+
import { IUploadImage } from '../types/image';
|
|
3
|
+
import { HTTPClient } from './HTTPClient';
|
|
4
|
+
import FormData from 'form-data';
|
|
5
|
+
|
|
6
|
+
export abstract class Image {
|
|
7
|
+
constructor(private readonly httpRef: HTTPClient) {}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Upload an image for specific product inspection item. For the moment, this method is only available for the inspection with mode full_control.
|
|
11
|
+
* @param input - An object that contains the essential information for upload the image.
|
|
12
|
+
* @param {String} input.productId - Represents the id of the product that you would like to attach a new photo.
|
|
13
|
+
* @param {Buffer} input.image - Represents the image to upload.
|
|
14
|
+
* @param {String} input.side - Represents the side of the image/photo to upload.
|
|
15
|
+
* @param {String} input.date - Represents the date when the photo was taken.
|
|
16
|
+
* @param {Object} input.coordinates - Represents the coordinates of the image/photo.
|
|
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
|
+
uploadImage(input: IUploadImage): Promise<IAPISucessResponse> {
|
|
21
|
+
const form = new FormData();
|
|
22
|
+
|
|
23
|
+
form.append('side', input.side);
|
|
24
|
+
form.append('image', input.image);
|
|
25
|
+
|
|
26
|
+
if (input.coordinates) {
|
|
27
|
+
form.append('coordinates', JSON.stringify(input.coordinates));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (input.date) {
|
|
31
|
+
form.append('date', input.date.toISOString());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
console.log('FORM DATA!', form);
|
|
35
|
+
|
|
36
|
+
return this.httpRef.makeRequest({
|
|
37
|
+
method: 'POST',
|
|
38
|
+
path: `/inspection/image/${input.productId}`,
|
|
39
|
+
body: form,
|
|
40
|
+
headers: {
|
|
41
|
+
...form.getHeaders(),
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* @classdesc Represents the class that contains the methods or actions that somebody can do using apikey and access_token.
|
|
12
|
+
* @class
|
|
13
|
+
*/
|
|
14
|
+
export class Inspections {
|
|
15
|
+
public machinery: Machinery;
|
|
16
|
+
public people: People;
|
|
17
|
+
public goods: Goods;
|
|
18
|
+
public vehicle: Vehicle;
|
|
19
|
+
|
|
20
|
+
constructor(private readonly httpClient: HTTPClient) {
|
|
21
|
+
this.machinery = new Machinery(httpClient);
|
|
22
|
+
this.people = new People(httpClient);
|
|
23
|
+
this.goods = new Goods(httpClient);
|
|
24
|
+
this.vehicle = new Vehicle(httpClient);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Finish the inspection to indicate that it will not receive more photos/images.
|
|
29
|
+
* @param input - An object that contains the essential information for upload the image.
|
|
30
|
+
* @param {String} input.inspectionId - Represents the id of the inspection.
|
|
31
|
+
* @param {Buffer} input.image - Represents the image to upload.
|
|
32
|
+
* @param {String} input.side - Represents the side of the image/photo to upload.
|
|
33
|
+
* @param {String} input.date - Represents the date when the photo was taken.
|
|
34
|
+
* @param {Object} input.coordinates - Represents the coordinates of the image/photo.
|
|
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
|
+
finishInspection(input: IFinishInspection): Promise<IAPISucessResponse> {
|
|
39
|
+
return this.httpClient.makeRequest({
|
|
40
|
+
method: 'POST',
|
|
41
|
+
path: `/inspection/finish/${input.inspectionId}`,
|
|
42
|
+
body: {},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get a specific inspection object.
|
|
48
|
+
* @param input - An object that contains the essential information for upload the image.
|
|
49
|
+
* @param {String} input.inspectionId - Represents the id of the inspection that you want to retrieve.
|
|
50
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
51
|
+
* data or an Error with the problem.
|
|
52
|
+
*/
|
|
53
|
+
getInspection(input: IGetInspection): Promise<IInspection> {
|
|
54
|
+
return this.httpClient.makeRequest({
|
|
55
|
+
method: 'GET',
|
|
56
|
+
path: `/inspection/${input.inspectionId}`,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get a list of n inspections with pagination.
|
|
62
|
+
* @param input - An object that contains filters for list the inspections.
|
|
63
|
+
* @param {Number} input.page - Represents the specific page that you want to retrieve the inspections.
|
|
64
|
+
* @param {Number} input.limit - Represents the limit of the quantity of records that you want to retrieve for page.
|
|
65
|
+
* @param {String} input.status - Represents the status that inspections retrieved should have.
|
|
66
|
+
* @param {String} input.type - Represents the type that inspections retrieved should have.
|
|
67
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
68
|
+
* data or an Error with the problem.
|
|
69
|
+
*/
|
|
70
|
+
listInspections(input: Partial<IPagination> = {}): Promise<IPaginationResponse<IInspection[]>> {
|
|
71
|
+
return this.httpClient.makeRequest({
|
|
72
|
+
method: 'GET',
|
|
73
|
+
path: `/inspection`,
|
|
74
|
+
params: input,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { IUpdateResourceResponse } from '../types/api';
|
|
2
|
+
import { ICreateInspectionOutput } from '../types/inspection';
|
|
3
|
+
import { ICreateMachineryInspection, IUpdateMachineryInspection } from '../types/machinery';
|
|
4
|
+
import { IProductMethods } from '../types/productMethods';
|
|
5
|
+
import { Helper } from './Helper';
|
|
6
|
+
import { HTTPClient } from './HTTPClient';
|
|
7
|
+
import { Image } from './Image';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @classdesc Represents the class that handle all the requests related to an inspection of type machinery.
|
|
11
|
+
* @class
|
|
12
|
+
*/
|
|
13
|
+
export class Machinery extends Image implements IProductMethods {
|
|
14
|
+
constructor(private readonly httpClient: HTTPClient) {
|
|
15
|
+
super(httpClient);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create an inspection of type machinery
|
|
20
|
+
* @param input - An object that contains the essential information for create an inspection.
|
|
21
|
+
* @param {Object} input.consumer - Represents the consumer who will do the inspection.
|
|
22
|
+
* @param {Object} input.machinery - Represents the machinery to be attached to the inspection.
|
|
23
|
+
* @param {String} input.mode - Represents the mode of the inspection. See more details: {@link https://www.autoinspector.com.ar/docs/api/start#inspection_mode}
|
|
24
|
+
* @param {String} input.kindOf - Represents the template that inspection will have. This only matters if the input.mode is normal.
|
|
25
|
+
* @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
|
|
26
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
27
|
+
* data or an Error with the problem.
|
|
28
|
+
*/
|
|
29
|
+
create(input: ICreateMachineryInspection): Promise<ICreateInspectionOutput> {
|
|
30
|
+
return this.httpClient.makeRequest({
|
|
31
|
+
method: 'POST',
|
|
32
|
+
path: `/inspection/machinery`,
|
|
33
|
+
body: input,
|
|
34
|
+
headers: Helper.buildOptionalHeaders(input.accessToken),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Update a machinery inspection.
|
|
40
|
+
* @param input - An object with the values to update.
|
|
41
|
+
* @param {Object} input.consumer - Represents the consumer who will do the inspection.
|
|
42
|
+
* @param {String} input.productId - Represents the unique identifier of the machinery.
|
|
43
|
+
* @param {Object} input.machinery - Represents the machinery to be attached to the inspection.
|
|
44
|
+
* @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
|
|
45
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
46
|
+
* data or an Error with the problem.
|
|
47
|
+
*/
|
|
48
|
+
update(input: IUpdateMachineryInspection): Promise<IUpdateResourceResponse> {
|
|
49
|
+
return this.httpClient.makeRequest({
|
|
50
|
+
method: 'PUT',
|
|
51
|
+
path: `/inspection/machinery/${input.productId}`,
|
|
52
|
+
body: input,
|
|
53
|
+
headers: Helper.buildOptionalHeaders(input.accessToken),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IExchangeCodeForAccessToken,
|
|
3
|
+
IExchangeCodeForAccessTokenOutput,
|
|
4
|
+
IOAuth20Credentials,
|
|
5
|
+
IRefreshAccessToken,
|
|
6
|
+
IRefreshAccessTokenOutput,
|
|
7
|
+
} from '../types/oauth20';
|
|
8
|
+
import { HTTPClient } from './HTTPClient';
|
|
9
|
+
import { OAuthUser } from './OAuthUser';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @classdesc Represents the class that has the responsability for make the request to every endpoint about oauth.
|
|
13
|
+
* @class
|
|
14
|
+
*/
|
|
15
|
+
export class OAuth20 {
|
|
16
|
+
private credentials: Partial<IOAuth20Credentials>;
|
|
17
|
+
public user: OAuthUser;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create OAuth20 instance to implement and execute methods in another class.
|
|
21
|
+
* @constructor
|
|
22
|
+
* @param httpClient - The httpClient that needs to be injected in the constructor. This is done by this way for inherit the http configuration from the Autoinspector constructor.
|
|
23
|
+
* @param credentials - An object with the neccessary credentials for interact with oauth endpoints.
|
|
24
|
+
* @param {String} credentials.clientappId - Represents the identification value that is generated when register an application into Autoinspector Dashboard.
|
|
25
|
+
* @param {String} credentials.clientSecret - Represents the token that is generated when register an application in Autoinspector Dashboard. It's an sensitive key. so it will only be exported/used in back channel.
|
|
26
|
+
*/
|
|
27
|
+
constructor(private readonly httpClient: HTTPClient, credentials: Partial<IOAuth20Credentials>) {
|
|
28
|
+
this.credentials = credentials;
|
|
29
|
+
this.user = new OAuthUser(httpClient);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Exchange some authorization code for a valid access_token.
|
|
34
|
+
* @param input - An object that contains the essential information for make the trade.
|
|
35
|
+
* @param {String} input.code - Represents the code received from Autoinspector in callbackURL.
|
|
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
|
+
exchangeCodeForAccessToken(
|
|
40
|
+
input: IExchangeCodeForAccessToken
|
|
41
|
+
): Promise<IExchangeCodeForAccessTokenOutput> {
|
|
42
|
+
return this.httpClient.makeRequest({
|
|
43
|
+
method: 'POST',
|
|
44
|
+
path: '/account/oauth/exchange_code',
|
|
45
|
+
body: {
|
|
46
|
+
...input,
|
|
47
|
+
...this.credentials,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Refresh some access_token for obtain a new one. This is useful for keep a long-term access_token.
|
|
54
|
+
* @param input - An object that contains the essential information refresh the token.
|
|
55
|
+
* @param {String} input.refreshToken - Represents the refresh token received when exchanged the code for an access_token.
|
|
56
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
57
|
+
* data or an Error with the problem.
|
|
58
|
+
*/
|
|
59
|
+
refreshAccessToken(input: IRefreshAccessToken): Promise<IRefreshAccessTokenOutput> {
|
|
60
|
+
return this.httpClient.makeRequest({
|
|
61
|
+
method: 'POST',
|
|
62
|
+
path: '/account/oauth/refresh_token',
|
|
63
|
+
body: {
|
|
64
|
+
...input,
|
|
65
|
+
...this.credentials,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IAuthenticatedUserListInspections,
|
|
3
|
+
IListAuthenticatedUserInspectionsOutput,
|
|
4
|
+
IListMemberships,
|
|
5
|
+
IListMembershipsOutput,
|
|
6
|
+
} from '../types/authenticatedUser';
|
|
7
|
+
import { Helper } from './Helper';
|
|
8
|
+
import { HTTPClient } from './HTTPClient';
|
|
9
|
+
import { Inspections } from './Inspections';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @classdesc Represents the class that contains the methods/actions availables that somebody can do using the access_token received in the oauth 2.0 authorization code flow.
|
|
13
|
+
* @class
|
|
14
|
+
*/
|
|
15
|
+
export class OAuthUser {
|
|
16
|
+
public inspections: Inspections;
|
|
17
|
+
|
|
18
|
+
constructor(private readonly httpClient: HTTPClient) {
|
|
19
|
+
this.inspections = new Inspections(httpClient);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* List all the inspections with a couple of filters.
|
|
24
|
+
* @param input - An object that contains the information for make the request.
|
|
25
|
+
* @param {String} input.scope - Indicates if the inspections to retrieve will be where the user authenticated is the producer or where the users created by the user authenticated invite before.
|
|
26
|
+
* @param {String} input.accessToken - Represents the token that belongs to the authenticated user.
|
|
27
|
+
* @param input.params - An object that contains the filters.
|
|
28
|
+
* @param {String} input.params.from - Represents the base date in ISO format of the inspections to retrieve.
|
|
29
|
+
* @param {String} input.params.to - Represents the limit date in ISO format of the inspections to retrieve.
|
|
30
|
+
* @param {String} input.params.result - Represents the result that inspections to retrieve should have.
|
|
31
|
+
* @param {String} input.params.search - Represents a general search that will match with the consumer: identification, firstName and email.
|
|
32
|
+
* @param {String} input.params.status - Represents the status that inspections to retrieve should have.
|
|
33
|
+
* @param {Number} input.params.page - Represents the specific page that you want to retrieve the inspections.
|
|
34
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
35
|
+
* data or an Error with the problem.
|
|
36
|
+
*/
|
|
37
|
+
listInspections(
|
|
38
|
+
input: IAuthenticatedUserListInspections
|
|
39
|
+
): Promise<IListAuthenticatedUserInspectionsOutput[]> {
|
|
40
|
+
return this.httpClient.makeRequest({
|
|
41
|
+
method: 'GET',
|
|
42
|
+
path: `/inspection/${input.scope}?membershipId=${input.membershipId}`,
|
|
43
|
+
params: input.params,
|
|
44
|
+
headers: Helper.buildOptionalHeaders(input.accessToken),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* List all the memberships accepted by the user authenticated related with companies.
|
|
50
|
+
* @param input - An object that contains the information for make the request.
|
|
51
|
+
* @param {String} input.accessToken - Represents the token that belongs to the authenticated user.
|
|
52
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
53
|
+
* data or an Error with the problem.
|
|
54
|
+
*/
|
|
55
|
+
listMemberships(input: IListMemberships): Promise<IListMembershipsOutput> {
|
|
56
|
+
return this.httpClient.makeRequest({
|
|
57
|
+
method: 'GET',
|
|
58
|
+
path: `/account/membership/authenticated`,
|
|
59
|
+
headers: Helper.buildOptionalHeaders(input.accessToken),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { IUpdateResourceResponse } from '../types/api';
|
|
2
|
+
import { ICreateInspectionOutput } from '../types/inspection';
|
|
3
|
+
import { ICreatePeopleInspection, IUpdatePeopleInspection } from '../types/people';
|
|
4
|
+
import { IProductMethods } from '../types/productMethods';
|
|
5
|
+
import { Helper } from './Helper';
|
|
6
|
+
import { HTTPClient } from './HTTPClient';
|
|
7
|
+
import { Image } from './Image';
|
|
8
|
+
|
|
9
|
+
export class People extends Image implements IProductMethods {
|
|
10
|
+
constructor(private readonly httpClient: HTTPClient) {
|
|
11
|
+
super(httpClient);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create an inspection of type people
|
|
15
|
+
* @param input - An object that contains the essential information for create an inspection.
|
|
16
|
+
* @param {Object} input.consumer - Represents the consumer who will do the inspection.
|
|
17
|
+
* @param {Object} input.people - Represents the people to be attached to the inspection.
|
|
18
|
+
* @param {String} input.mode - Represents the mode of the inspection. See more details: {@link https://www.autoinspector.com.ar/docs/api/start#inspection_mode}
|
|
19
|
+
* @param {String} input.kindOf - Represents the template that inspection will have. This only matters if the input.mode is normal.
|
|
20
|
+
* @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
|
|
21
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
22
|
+
* data or an Error with the problem.
|
|
23
|
+
*/
|
|
24
|
+
create(input: ICreatePeopleInspection): Promise<ICreateInspectionOutput> {
|
|
25
|
+
return this.httpClient.makeRequest({
|
|
26
|
+
method: 'POST',
|
|
27
|
+
path: `/inspection/people`,
|
|
28
|
+
body: input,
|
|
29
|
+
headers: Helper.buildOptionalHeaders(input.accessToken),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Update an inspection of type people
|
|
35
|
+
* @param input - An object that contains the essential information for create an inspection.
|
|
36
|
+
* @param {Object} input.consumer - Represents the user who do the inspection.
|
|
37
|
+
* @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
|
|
38
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
39
|
+
* data or an Error with the problem.
|
|
40
|
+
*/
|
|
41
|
+
update(input: IUpdatePeopleInspection): Promise<IUpdateResourceResponse> {
|
|
42
|
+
return this.httpClient.makeRequest({
|
|
43
|
+
method: 'PUT',
|
|
44
|
+
path: `/inspection/people/${input.productId}`,
|
|
45
|
+
body: input,
|
|
46
|
+
headers: Helper.buildOptionalHeaders(input.accessToken),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { IUpdateResourceResponse } from '../types/api';
|
|
2
|
+
import { ICreateInspectionOutput } from '../types/inspection';
|
|
3
|
+
import { IProductMethods } from '../types/productMethods';
|
|
4
|
+
import { ICreateVehicleInspection, IUpdateVehicleInspection } from '../types/vehicle';
|
|
5
|
+
import { Helper } from './Helper';
|
|
6
|
+
import { HTTPClient } from './HTTPClient';
|
|
7
|
+
import { Image } from './Image';
|
|
8
|
+
|
|
9
|
+
export class Vehicle extends Image implements IProductMethods {
|
|
10
|
+
constructor(private readonly httpClient: HTTPClient) {
|
|
11
|
+
super(httpClient);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create an inspection of type vehicle
|
|
16
|
+
* @param input - An object that contains the essential information for create an inspection.
|
|
17
|
+
* @param {Object} input.consumer - Represents the consumer who will do the inspection.
|
|
18
|
+
* @param {Object} input.vehicle - Represents the vehicle to be attached to the inspection.
|
|
19
|
+
* @param {String} input.mode - Represents the mode of the inspection. See more details: {@link https://www.autoinspector.com.ar/docs/api/start#inspection_mode}
|
|
20
|
+
* @param {String} input.kindOf - Represents the template that inspection will have. This only matters if the input.mode is normal.
|
|
21
|
+
* @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
|
|
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
|
+
create(input: ICreateVehicleInspection): Promise<ICreateInspectionOutput> {
|
|
26
|
+
return this.httpClient.makeRequest({
|
|
27
|
+
method: 'POST',
|
|
28
|
+
path: `/inspection/vehicle`,
|
|
29
|
+
body: input,
|
|
30
|
+
headers: Helper.buildOptionalHeaders(input.accessToken),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Update an inspection of type vehicle.
|
|
36
|
+
* @param input - An object that contains the essential information for create an inspection.
|
|
37
|
+
* @param {Object} input.consumer - Represents the consumer who will do the inspection.
|
|
38
|
+
* @param {Object} input.vehicle - Represents the vehicle to be attached to the inspection.
|
|
39
|
+
* @param {Object} input.metadata - Represents a dinamic object where you can store any key-value pairs.
|
|
40
|
+
* @return {Promise} - Returns a Promise that, when fulfilled, will either return an JSON Object with the requested
|
|
41
|
+
* data or an Error with the problem.
|
|
42
|
+
*/
|
|
43
|
+
update(input: IUpdateVehicleInspection): Promise<IUpdateResourceResponse> {
|
|
44
|
+
return this.httpClient.makeRequest({
|
|
45
|
+
method: 'PUT',
|
|
46
|
+
path: `/inspection/vehicle/${input.productId}`,
|
|
47
|
+
body: input,
|
|
48
|
+
headers: Helper.buildOptionalHeaders(input.accessToken),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
|
4
|
+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
|
5
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
6
|
+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
|
7
|
+
"skipLibCheck": true /* Skip type checking of declaration files. */,
|
|
8
|
+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"outDir": "./dist",
|
|
11
|
+
"resolveJsonModule": true
|
|
12
|
+
}
|
|
13
|
+
}
|
package/types/api.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface IAPISucessResponse {
|
|
2
|
+
message: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface IAutoinspectorError {
|
|
6
|
+
code: string;
|
|
7
|
+
status: number;
|
|
8
|
+
detail: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type APIMethods = 'POST' | 'GET' | 'PUT' | 'DELETE';
|
|
12
|
+
|
|
13
|
+
export interface IUpdateResourceResponse {
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { InspectionStatus, InspectionVeredict } from './inspection';
|
|
2
|
+
|
|
3
|
+
export interface IListInspections {
|
|
4
|
+
from: Date;
|
|
5
|
+
to: Date;
|
|
6
|
+
veredict: InspectionVeredict;
|
|
7
|
+
search: string;
|
|
8
|
+
status: InspectionStatus;
|
|
9
|
+
page: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IAuthenticatedUserCommonParams {
|
|
13
|
+
accessToken: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IAuthenticatedUserListInspections extends IAuthenticatedUserCommonParams {
|
|
17
|
+
scope: 'all' | 'mine';
|
|
18
|
+
params: IListInspections;
|
|
19
|
+
membershipId: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IPaginationOutput {
|
|
23
|
+
hasNextPage: boolean;
|
|
24
|
+
hasPrevPage: boolean;
|
|
25
|
+
limit: number;
|
|
26
|
+
nextPage?: number;
|
|
27
|
+
page: number;
|
|
28
|
+
pagingCounter: number;
|
|
29
|
+
prevPage?: number;
|
|
30
|
+
totalDocs: number;
|
|
31
|
+
totalPages: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface IInspectionItemOutput {
|
|
35
|
+
accessCode: string;
|
|
36
|
+
consumer: {
|
|
37
|
+
firstName: string;
|
|
38
|
+
identification: string;
|
|
39
|
+
lastName: string;
|
|
40
|
+
};
|
|
41
|
+
createdAt: string;
|
|
42
|
+
id: string;
|
|
43
|
+
producer: {
|
|
44
|
+
companyId: string;
|
|
45
|
+
user: { _id: string; username: string };
|
|
46
|
+
userId: string;
|
|
47
|
+
};
|
|
48
|
+
status: string;
|
|
49
|
+
type: string;
|
|
50
|
+
_id: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface IListAuthenticatedUserInspectionsOutput {
|
|
54
|
+
pagination: IPaginationOutput;
|
|
55
|
+
inspection: IInspectionItemOutput[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface IListMemberships extends IAuthenticatedUserCommonParams {}
|
|
59
|
+
|
|
60
|
+
export interface ICompany {
|
|
61
|
+
logo: string;
|
|
62
|
+
societyReason: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface IMembershipItem {
|
|
66
|
+
role: string;
|
|
67
|
+
company: ICompany;
|
|
68
|
+
_id: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type IListMembershipsOutput = IMembershipItem[];
|