@monkvision/network 4.4.2 → 4.4.4
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 +26 -0
- package/lib/package.json +9 -9
- package/lib/src/api/api.d.ts +3 -0
- package/lib/src/api/api.js +3 -0
- package/lib/src/api/damage/requests.d.ts +2 -2
- package/lib/src/api/damage/requests.js +2 -2
- package/lib/src/api/error.d.ts +5 -1
- package/lib/src/api/error.js +9 -0
- package/lib/src/api/inspection/mappers.js +1 -0
- package/lib/src/api/models/pdf.d.ts +7 -0
- package/lib/src/api/models/pdf.js +2 -0
- package/lib/src/api/pdf/index.d.ts +1 -0
- package/lib/src/api/pdf/index.js +17 -0
- package/lib/src/api/pdf/requests.d.ts +50 -0
- package/lib/src/api/pdf/requests.js +158 -0
- package/lib/src/api/react.d.ts +17 -0
- package/lib/src/api/react.js +14 -0
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -238,6 +238,32 @@ Gets the count of inspections that match the given filters.
|
|
|
238
238
|
|-----------|--------------------------|-----------------------------|----------|
|
|
239
239
|
| options | GetAllInspectionsOptions | The options of the request. | ✔️ |
|
|
240
240
|
|
|
241
|
+
### getPdf
|
|
242
|
+
```typescript
|
|
243
|
+
import { MonkApi } from '@monkvision/network';
|
|
244
|
+
|
|
245
|
+
MonkApi.getPdf(options, apiConfig, dispatch);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Gets the PDF url of an inspection.
|
|
249
|
+
|
|
250
|
+
| Parameter | Type | Description | Required |
|
|
251
|
+
|-----------|---------------|-----------------------------|----------|
|
|
252
|
+
| options | GetPdfOptions | The options of the request. | ✔️ |
|
|
253
|
+
|
|
254
|
+
### uploadPdf
|
|
255
|
+
```typescript
|
|
256
|
+
import { MonkApi } from '@monkvision/network';
|
|
257
|
+
|
|
258
|
+
MonkApi.uploadPdf(options, apiConfig, dispatch);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Upload a new PDF to an inspection.
|
|
262
|
+
|
|
263
|
+
| Parameter | Type | Description | Required |
|
|
264
|
+
|-----------|------------------|-----------------------------|----------|
|
|
265
|
+
| options | UploadPdfOptions | The options of the request. | ✔️ |
|
|
266
|
+
|
|
241
267
|
# React Tools
|
|
242
268
|
In order to simply integrate the Monk Api requests into your React app, you can make use of the `useMonkApi` hook. This
|
|
243
269
|
custom hook returns a custom version of the `MonkApi` object described in the section above, in which the requests do
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkvision/network",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.3",
|
|
4
4
|
"license": "BSD-3-Clause-Clear",
|
|
5
5
|
"packageManager": "yarn@3.2.4",
|
|
6
6
|
"description": "MonkJs core package used to communicate with the API",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"lint:fix": "yarn run prettier:fix && yarn run eslint:fix"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@monkvision/common": "4.4.
|
|
32
|
-
"@monkvision/sights": "4.4.
|
|
31
|
+
"@monkvision/common": "4.4.3",
|
|
32
|
+
"@monkvision/sights": "4.4.3",
|
|
33
33
|
"jsonwebtoken": "^9.0.2",
|
|
34
34
|
"jwt-decode": "^4.0.0",
|
|
35
35
|
"ky": "^1.2.0",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"react-router-dom": "^6.22.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@monkvision/eslint-config-base": "4.4.
|
|
46
|
-
"@monkvision/eslint-config-typescript": "4.4.
|
|
47
|
-
"@monkvision/jest-config": "4.4.
|
|
48
|
-
"@monkvision/prettier-config": "4.4.
|
|
49
|
-
"@monkvision/types": "4.4.
|
|
50
|
-
"@monkvision/typescript-config": "4.4.
|
|
45
|
+
"@monkvision/eslint-config-base": "4.4.3",
|
|
46
|
+
"@monkvision/eslint-config-typescript": "4.4.3",
|
|
47
|
+
"@monkvision/jest-config": "4.4.3",
|
|
48
|
+
"@monkvision/prettier-config": "4.4.3",
|
|
49
|
+
"@monkvision/types": "4.4.3",
|
|
50
|
+
"@monkvision/typescript-config": "4.4.3",
|
|
51
51
|
"@types/jest": "^29.2.2",
|
|
52
52
|
"@types/jsonwebtoken": "^9.0.5",
|
|
53
53
|
"@types/node": "^18.11.9",
|
package/lib/src/api/api.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { getLiveConfig } from './liveConfigs';
|
|
|
5
5
|
import { updateInspectionVehicle } from './vehicle';
|
|
6
6
|
import { createPricing, deletePricing, updatePricing } from './pricing';
|
|
7
7
|
import { createDamage, deleteDamage } from './damage';
|
|
8
|
+
import { getPdf, uploadPdf } from './pdf';
|
|
8
9
|
/**
|
|
9
10
|
* Object regrouping the different API requests available to communicate with the API using the `@monkvision/network`
|
|
10
11
|
* package.
|
|
@@ -25,4 +26,6 @@ export declare const MonkApi: {
|
|
|
25
26
|
updatePricing: typeof updatePricing;
|
|
26
27
|
createDamage: typeof createDamage;
|
|
27
28
|
deleteDamage: typeof deleteDamage;
|
|
29
|
+
uploadPdf: typeof uploadPdf;
|
|
30
|
+
getPdf: typeof getPdf;
|
|
28
31
|
};
|
package/lib/src/api/api.js
CHANGED
|
@@ -8,6 +8,7 @@ var liveConfigs_1 = require("./liveConfigs");
|
|
|
8
8
|
var vehicle_1 = require("./vehicle");
|
|
9
9
|
var pricing_1 = require("./pricing");
|
|
10
10
|
var damage_1 = require("./damage");
|
|
11
|
+
var pdf_1 = require("./pdf");
|
|
11
12
|
/**
|
|
12
13
|
* Object regrouping the different API requests available to communicate with the API using the `@monkvision/network`
|
|
13
14
|
* package.
|
|
@@ -28,4 +29,6 @@ exports.MonkApi = {
|
|
|
28
29
|
updatePricing: pricing_1.updatePricing,
|
|
29
30
|
createDamage: damage_1.createDamage,
|
|
30
31
|
deleteDamage: damage_1.deleteDamage,
|
|
32
|
+
uploadPdf: pdf_1.uploadPdf,
|
|
33
|
+
getPdf: pdf_1.getPdf,
|
|
31
34
|
};
|
|
@@ -23,7 +23,7 @@ export interface CreateDamageOptions {
|
|
|
23
23
|
/**
|
|
24
24
|
* Create a new damage with the given options. See the `CreateDamageOptions` interface for more details.
|
|
25
25
|
*
|
|
26
|
-
* @param options The options of the
|
|
26
|
+
* @param options The options of the request.
|
|
27
27
|
* @param config The API config.
|
|
28
28
|
* @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
|
|
29
29
|
* state management for you.
|
|
@@ -46,7 +46,7 @@ export interface DeleteDamageOptions {
|
|
|
46
46
|
/**
|
|
47
47
|
* Delete a damage with the given options. See the `DeleteDamageOptions` interface for more details.
|
|
48
48
|
*
|
|
49
|
-
* @param options The options of the
|
|
49
|
+
* @param options The options of the request.
|
|
50
50
|
* @param config The API config.
|
|
51
51
|
* @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
|
|
52
52
|
* state management for you.
|
|
@@ -60,7 +60,7 @@ var mappers_1 = require("./mappers");
|
|
|
60
60
|
/**
|
|
61
61
|
* Create a new damage with the given options. See the `CreateDamageOptions` interface for more details.
|
|
62
62
|
*
|
|
63
|
-
* @param options The options of the
|
|
63
|
+
* @param options The options of the request.
|
|
64
64
|
* @param config The API config.
|
|
65
65
|
* @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
|
|
66
66
|
* state management for you.
|
|
@@ -120,7 +120,7 @@ exports.createDamage = createDamage;
|
|
|
120
120
|
/**
|
|
121
121
|
* Delete a damage with the given options. See the `DeleteDamageOptions` interface for more details.
|
|
122
122
|
*
|
|
123
|
-
* @param options The options of the
|
|
123
|
+
* @param options The options of the request.
|
|
124
124
|
* @param config The API config.
|
|
125
125
|
* @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
|
|
126
126
|
* state management for you.
|
package/lib/src/api/error.d.ts
CHANGED
|
@@ -21,7 +21,11 @@ export declare enum MonkNetworkError {
|
|
|
21
21
|
* The user corresponding to the authentication token provided in the request does not have the sufficient
|
|
22
22
|
* authorization to perform the request.
|
|
23
23
|
*/
|
|
24
|
-
INSUFFICIENT_AUTHORIZATION = "InsufficientAuthorization"
|
|
24
|
+
INSUFFICIENT_AUTHORIZATION = "InsufficientAuthorization",
|
|
25
|
+
/**
|
|
26
|
+
* The PDF requested is not available.
|
|
27
|
+
*/
|
|
28
|
+
UNAVAILABLE_PDF = "UnavailablePdf"
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
31
|
* Type definition for a network error catched by the Monk SDK. Requests made by this package will usually process the
|
package/lib/src/api/error.js
CHANGED
|
@@ -59,6 +59,10 @@ var MonkNetworkError;
|
|
|
59
59
|
* authorization to perform the request.
|
|
60
60
|
*/
|
|
61
61
|
MonkNetworkError["INSUFFICIENT_AUTHORIZATION"] = "InsufficientAuthorization";
|
|
62
|
+
/**
|
|
63
|
+
* The PDF requested is not available.
|
|
64
|
+
*/
|
|
65
|
+
MonkNetworkError["UNAVAILABLE_PDF"] = "UnavailablePdf";
|
|
62
66
|
})(MonkNetworkError = exports.MonkNetworkError || (exports.MonkNetworkError = {}));
|
|
63
67
|
function getErrorMessage(name) {
|
|
64
68
|
switch (name) {
|
|
@@ -70,6 +74,8 @@ function getErrorMessage(name) {
|
|
|
70
74
|
return 'Authentication token is expired.';
|
|
71
75
|
case MonkNetworkError.INSUFFICIENT_AUTHORIZATION:
|
|
72
76
|
return 'User does not have the proper authorization grants to perform this request.';
|
|
77
|
+
case MonkNetworkError.UNAVAILABLE_PDF:
|
|
78
|
+
return 'The PDF requested is not available.';
|
|
73
79
|
default:
|
|
74
80
|
return null;
|
|
75
81
|
}
|
|
@@ -92,6 +98,9 @@ function getErrorName(status, message) {
|
|
|
92
98
|
if (status === 401 && message.includes('Token is expired')) {
|
|
93
99
|
return MonkNetworkError.EXPIRED_TOKEN;
|
|
94
100
|
}
|
|
101
|
+
if (status === 422 && message.includes('PDF has not been required to be generated')) {
|
|
102
|
+
return MonkNetworkError.UNAVAILABLE_PDF;
|
|
103
|
+
}
|
|
95
104
|
// TODO : Also check conditions for MonkNetworkError.INSUFFICIENT_AUTHORIZATION.
|
|
96
105
|
return null;
|
|
97
106
|
}
|
|
@@ -287,6 +287,7 @@ function mapInspection(response, ids) {
|
|
|
287
287
|
wheelAnalysis: mapWheelAnalysis(response),
|
|
288
288
|
severityResults: ids.severityResultIds,
|
|
289
289
|
pricings: ids.pricingIds,
|
|
290
|
+
pdfUrl: 'pdf_url' in response ? response.pdf_url : undefined,
|
|
290
291
|
additionalData: response.additional_data,
|
|
291
292
|
};
|
|
292
293
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './requests';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./requests"), exports);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MonkGotOneInspectionPdfAction } from '@monkvision/common';
|
|
2
|
+
import { Dispatch } from 'react';
|
|
3
|
+
import { MonkApiConfig } from '../config';
|
|
4
|
+
import { ApiPdf } from '../models/pdf';
|
|
5
|
+
import { MonkApiResponse } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Options passed to the `uploadPdf` API request.
|
|
8
|
+
*/
|
|
9
|
+
export interface UploadPdfOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The ID of the inspection to update via the API.
|
|
12
|
+
*/
|
|
13
|
+
id: string;
|
|
14
|
+
/**
|
|
15
|
+
* The PDF file to upload.
|
|
16
|
+
*/
|
|
17
|
+
pdf: Blob;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options passed to the `getPdf` API request.
|
|
21
|
+
*/
|
|
22
|
+
export interface GetPdfOptions {
|
|
23
|
+
/**
|
|
24
|
+
* The ID of the inspection to get the PDF from.
|
|
25
|
+
*/
|
|
26
|
+
id: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Upload a PDF file to an inspection. See the `UploadPdfOptions` interface for more details.
|
|
30
|
+
*
|
|
31
|
+
* @param options The options of the request.
|
|
32
|
+
* @param config The API config.
|
|
33
|
+
* @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
|
|
34
|
+
* state management for you.
|
|
35
|
+
* @see UploadPdfOptions
|
|
36
|
+
*/
|
|
37
|
+
export declare function uploadPdf(options: UploadPdfOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkGotOneInspectionPdfAction>): Promise<MonkApiResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Get a PDF file from an inspection. See the `GetPdfOptions` interface for more details.
|
|
40
|
+
*
|
|
41
|
+
* @param options The options of the request.
|
|
42
|
+
* @param config The API config.
|
|
43
|
+
* @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
|
|
44
|
+
* state management for you.
|
|
45
|
+
* @see GetPdfOptions
|
|
46
|
+
*/
|
|
47
|
+
export declare function getPdf(options: GetPdfOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkGotOneInspectionPdfAction>): Promise<{
|
|
48
|
+
response: import("ky").KyResponse;
|
|
49
|
+
body: ApiPdf;
|
|
50
|
+
}>;
|
|
@@ -0,0 +1,158 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.getPdf = exports.uploadPdf = void 0;
|
|
54
|
+
var common_1 = require("@monkvision/common");
|
|
55
|
+
var ky_1 = __importDefault(require("ky"));
|
|
56
|
+
var config_1 = require("../config");
|
|
57
|
+
function getPdfData(options, filetype) {
|
|
58
|
+
var filename = "".concat(options.id, "-").concat(Date.now(), ".").concat(filetype);
|
|
59
|
+
var body = { pdf_post_strategy: 'upload' };
|
|
60
|
+
return { filename: filename, body: body };
|
|
61
|
+
}
|
|
62
|
+
var MULTIPART_KEY_PDF_DATA = 'pdf_data';
|
|
63
|
+
var MULTIPART_KEY_JSON = 'json';
|
|
64
|
+
function createPdfData(options) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var extensions, filetype, _a, filename, body, file, data;
|
|
67
|
+
return __generator(this, function (_b) {
|
|
68
|
+
extensions = (0, common_1.getFileExtensions)(options.pdf.type);
|
|
69
|
+
if (!extensions) {
|
|
70
|
+
throw new Error("Unknown pdf mimetype : ".concat(options.pdf.type));
|
|
71
|
+
}
|
|
72
|
+
filetype = extensions[0];
|
|
73
|
+
_a = getPdfData(options, filetype), filename = _a.filename, body = _a.body;
|
|
74
|
+
file = new File([options.pdf], filename, { type: filetype });
|
|
75
|
+
data = new FormData();
|
|
76
|
+
data.append(MULTIPART_KEY_JSON, JSON.stringify(body));
|
|
77
|
+
data.append(MULTIPART_KEY_PDF_DATA, file);
|
|
78
|
+
return [2 /*return*/, data];
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Upload a PDF file to an inspection. See the `UploadPdfOptions` interface for more details.
|
|
84
|
+
*
|
|
85
|
+
* @param options The options of the request.
|
|
86
|
+
* @param config The API config.
|
|
87
|
+
* @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
|
|
88
|
+
* state management for you.
|
|
89
|
+
* @see UploadPdfOptions
|
|
90
|
+
*/
|
|
91
|
+
function uploadPdf(options, config, dispatch) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var kyOptions, formData, response, body;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
kyOptions = (0, config_1.getDefaultOptions)(config);
|
|
98
|
+
return [4 /*yield*/, createPdfData(options)];
|
|
99
|
+
case 1:
|
|
100
|
+
formData = _a.sent();
|
|
101
|
+
return [4 /*yield*/, ky_1.default.post("inspections/".concat(options.id, "/pdf"), __assign(__assign({}, kyOptions), { body: formData }))];
|
|
102
|
+
case 2:
|
|
103
|
+
_a.sent();
|
|
104
|
+
return [4 /*yield*/, ky_1.default.get("inspections/".concat(options.id, "/pdf"), __assign({}, kyOptions))];
|
|
105
|
+
case 3:
|
|
106
|
+
response = _a.sent();
|
|
107
|
+
return [4 /*yield*/, response.json()];
|
|
108
|
+
case 4:
|
|
109
|
+
body = _a.sent();
|
|
110
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
111
|
+
type: common_1.MonkActionType.GOT_ONE_INSPECTION_PDF,
|
|
112
|
+
payload: { inspectionId: options.id, pdfUrl: body.pdf_url },
|
|
113
|
+
});
|
|
114
|
+
return [2 /*return*/, {
|
|
115
|
+
id: body.id,
|
|
116
|
+
response: response,
|
|
117
|
+
body: body,
|
|
118
|
+
}];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
exports.uploadPdf = uploadPdf;
|
|
124
|
+
/**
|
|
125
|
+
* Get a PDF file from an inspection. See the `GetPdfOptions` interface for more details.
|
|
126
|
+
*
|
|
127
|
+
* @param options The options of the request.
|
|
128
|
+
* @param config The API config.
|
|
129
|
+
* @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
|
|
130
|
+
* state management for you.
|
|
131
|
+
* @see GetPdfOptions
|
|
132
|
+
*/
|
|
133
|
+
function getPdf(options, config, dispatch) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
var kyOptions, response, body;
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
kyOptions = (0, config_1.getDefaultOptions)(config);
|
|
140
|
+
return [4 /*yield*/, ky_1.default.get("inspections/".concat(options.id, "/pdf"), __assign({}, kyOptions))];
|
|
141
|
+
case 1:
|
|
142
|
+
response = _a.sent();
|
|
143
|
+
return [4 /*yield*/, response.json()];
|
|
144
|
+
case 2:
|
|
145
|
+
body = _a.sent();
|
|
146
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
147
|
+
type: common_1.MonkActionType.GOT_ONE_INSPECTION_PDF,
|
|
148
|
+
payload: { inspectionId: options.id, pdfUrl: body.pdf_url },
|
|
149
|
+
});
|
|
150
|
+
return [2 /*return*/, {
|
|
151
|
+
response: response,
|
|
152
|
+
body: body,
|
|
153
|
+
}];
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
exports.getPdf = getPdf;
|
package/lib/src/api/react.d.ts
CHANGED
|
@@ -119,4 +119,21 @@ export declare function useMonkApi(config: MonkApiConfig): {
|
|
|
119
119
|
* @see DeleteDamageOptions
|
|
120
120
|
*/
|
|
121
121
|
deleteDamage: (options: import("./damage").DeleteDamageOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn>>;
|
|
122
|
+
/**
|
|
123
|
+
* Upload a PDF file to the API. See the `UploadPdfOptions` interface for more details.
|
|
124
|
+
*
|
|
125
|
+
* @param options The options of the inspection.
|
|
126
|
+
* @see UploadPdfOptions
|
|
127
|
+
*/
|
|
128
|
+
uploadPdf: (options: import("./pdf").UploadPdfOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn>>;
|
|
129
|
+
/**
|
|
130
|
+
* Get a PDF file from an inspection. See the `GetPdfOptions` interface for more details.
|
|
131
|
+
*
|
|
132
|
+
* @param options The options of the inspection.
|
|
133
|
+
* @see GetPdfOptions
|
|
134
|
+
*/
|
|
135
|
+
getPdf: (options: import("./pdf").GetPdfOptions) => Promise<{
|
|
136
|
+
response: import("ky").KyResponse;
|
|
137
|
+
body: import("./models/pdf").ApiPdf;
|
|
138
|
+
}>;
|
|
122
139
|
};
|
package/lib/src/api/react.js
CHANGED
|
@@ -152,6 +152,20 @@ function useMonkApi(config) {
|
|
|
152
152
|
* @see DeleteDamageOptions
|
|
153
153
|
*/
|
|
154
154
|
deleteDamage: reactify(api_1.MonkApi.deleteDamage, config, dispatch, handleError),
|
|
155
|
+
/**
|
|
156
|
+
* Upload a PDF file to the API. See the `UploadPdfOptions` interface for more details.
|
|
157
|
+
*
|
|
158
|
+
* @param options The options of the inspection.
|
|
159
|
+
* @see UploadPdfOptions
|
|
160
|
+
*/
|
|
161
|
+
uploadPdf: reactify(api_1.MonkApi.uploadPdf, config, dispatch, handleError),
|
|
162
|
+
/**
|
|
163
|
+
* Get a PDF file from an inspection. See the `GetPdfOptions` interface for more details.
|
|
164
|
+
*
|
|
165
|
+
* @param options The options of the inspection.
|
|
166
|
+
* @see GetPdfOptions
|
|
167
|
+
*/
|
|
168
|
+
getPdf: reactify(api_1.MonkApi.getPdf, config, dispatch, handleError),
|
|
155
169
|
};
|
|
156
170
|
}
|
|
157
171
|
exports.useMonkApi = useMonkApi;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkvision/network",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.4",
|
|
4
4
|
"license": "BSD-3-Clause-Clear",
|
|
5
5
|
"packageManager": "yarn@3.2.4",
|
|
6
6
|
"description": "MonkJs core package used to communicate with the API",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"lint:fix": "yarn run prettier:fix && yarn run eslint:fix"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@monkvision/common": "4.4.
|
|
32
|
-
"@monkvision/sights": "4.4.
|
|
31
|
+
"@monkvision/common": "4.4.4",
|
|
32
|
+
"@monkvision/sights": "4.4.4",
|
|
33
33
|
"jsonwebtoken": "^9.0.2",
|
|
34
34
|
"jwt-decode": "^4.0.0",
|
|
35
35
|
"ky": "^1.2.0",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"react-router-dom": "^6.22.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@monkvision/eslint-config-base": "4.4.
|
|
46
|
-
"@monkvision/eslint-config-typescript": "4.4.
|
|
47
|
-
"@monkvision/jest-config": "4.4.
|
|
48
|
-
"@monkvision/prettier-config": "4.4.
|
|
49
|
-
"@monkvision/types": "4.4.
|
|
50
|
-
"@monkvision/typescript-config": "4.4.
|
|
45
|
+
"@monkvision/eslint-config-base": "4.4.4",
|
|
46
|
+
"@monkvision/eslint-config-typescript": "4.4.4",
|
|
47
|
+
"@monkvision/jest-config": "4.4.4",
|
|
48
|
+
"@monkvision/prettier-config": "4.4.4",
|
|
49
|
+
"@monkvision/types": "4.4.4",
|
|
50
|
+
"@monkvision/typescript-config": "4.4.4",
|
|
51
51
|
"@types/jest": "^29.2.2",
|
|
52
52
|
"@types/jsonwebtoken": "^9.0.5",
|
|
53
53
|
"@types/node": "^18.11.9",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"url": "https://github.com/monkvision/monkjs/issues"
|
|
85
85
|
},
|
|
86
86
|
"homepage": "https://github.com/monkvision/monkjs",
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "7abfa7fbb0b482a6dd916c92cfc994f2b4e74257"
|
|
88
88
|
}
|