@monkvision/network 5.1.7 → 5.2.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 +84 -1
- package/lib/package.json +9 -9
- package/lib/src/api/api.d.ts +2 -1
- package/lib/src/api/api.js +1 -0
- package/lib/src/api/image/requests.d.ts +23 -1
- package/lib/src/api/image/requests.js +51 -1
- package/lib/src/api/index.d.ts +1 -1
- package/lib/src/api/inspection/mappers.d.ts +1 -0
- package/lib/src/api/inspection/mappers.js +8 -1
- package/lib/src/api/inspection/requests.d.ts +7 -0
- package/lib/src/api/inspection/requests.js +7 -6
- package/lib/src/api/react.d.ts +6 -0
- package/lib/src/api/react.js +6 -0
- package/lib/src/auth/authProvider.d.ts +15 -0
- package/lib/src/auth/authProvider.js +43 -0
- package/lib/src/auth/authProvider.types.d.ts +31 -0
- package/lib/src/auth/authProvider.types.js +2 -0
- package/lib/src/auth/index.d.ts +2 -0
- package/lib/src/auth/index.js +2 -0
- package/lib/src/auth/token.d.ts +10 -0
- package/lib/src/auth/token.js +28 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -70,6 +70,21 @@ been created in the API.
|
|
|
70
70
|
|-----------|-----------------|----------------------------------------------------------|----------|
|
|
71
71
|
| options | AddImageOptions | The options used to specify how to upload the image. | ✔️ |
|
|
72
72
|
|
|
73
|
+
### deleteImage
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { MonkApi } from '@monkvision/network';
|
|
77
|
+
|
|
78
|
+
MonkApi.deleteImage(options,apiConfig, dispatch);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Delete an image from an inspection. The resulting action of this request will contain the ID of the image that has
|
|
82
|
+
been deleted in the API.
|
|
83
|
+
|
|
84
|
+
| Parameter | Type | Description | Required |
|
|
85
|
+
| ----------|--------------------|----------------------------------------------------|----------|
|
|
86
|
+
| options | DeleteImageOptions | The options used to specify which image to delete. | ✔️ |
|
|
87
|
+
|
|
73
88
|
### updateTaskStatus
|
|
74
89
|
```typescript
|
|
75
90
|
import { MonkApi } from '@monkvision/network';
|
|
@@ -334,6 +349,39 @@ function MyAuthComponent() {
|
|
|
334
349
|
}
|
|
335
350
|
```
|
|
336
351
|
|
|
352
|
+
## AuthProvider
|
|
353
|
+
|
|
354
|
+
### Description
|
|
355
|
+
This component is a Authentication provider that selects the appropriate Auth0 configuration based on URL parameters (MonkSearchParam.CLIENT_ID).
|
|
356
|
+
|
|
357
|
+
### Example
|
|
358
|
+
|
|
359
|
+
```tsx
|
|
360
|
+
import { AuthProvider } from '@monkvision/network';
|
|
361
|
+
|
|
362
|
+
const configs = [
|
|
363
|
+
{
|
|
364
|
+
clientId: 'CID_EU',
|
|
365
|
+
domain: 'eu.auth0.com',
|
|
366
|
+
authorizationParams: { redirect_uri: 'https://eu.monk.ai' },
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
clientId: 'CID_US',
|
|
370
|
+
domain: 'us.auth0.com',
|
|
371
|
+
authorizationParams: { redirect_uri: 'https://us.monk.ai' },
|
|
372
|
+
},
|
|
373
|
+
];
|
|
374
|
+
|
|
375
|
+
function App() {
|
|
376
|
+
return (
|
|
377
|
+
<AuthProvider configs={configs} >
|
|
378
|
+
...
|
|
379
|
+
</AuthProvider>
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
|
|
337
385
|
## JWT Utils
|
|
338
386
|
### Token decoding
|
|
339
387
|
You can decode Monk JWT token issued by Auth0 using the `decodeMonkJwt` util function provided by this package :
|
|
@@ -359,7 +407,6 @@ console.log(isUserAuthorized(value, requiredPermissions));
|
|
|
359
407
|
// value can either be an auth token as a string or a decoded JWT payload
|
|
360
408
|
```
|
|
361
409
|
|
|
362
|
-
|
|
363
410
|
### isTokenExpired
|
|
364
411
|
This utility function checks if an authorization token is expired or not. You can either pass an auth token to be
|
|
365
412
|
decoded or the JWT payload directly.
|
|
@@ -370,3 +417,39 @@ import { isTokenExpired } from '@monkvision/network';
|
|
|
370
417
|
console.log(isTokenExpired(value));
|
|
371
418
|
// value can either be an auth token as a string or a decoded JWT payload
|
|
372
419
|
```
|
|
420
|
+
|
|
421
|
+
### isTokenValid
|
|
422
|
+
This utility function checks if the stored auth token is valid for the given Auth0 Client ID.
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
import { isTokenValid } from '@monkvision/network';
|
|
426
|
+
|
|
427
|
+
console.log(isTokenValid(clientId));
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### getAuthConfig
|
|
431
|
+
This utility function that retrieves the appropriate AuthConfig based on the URL search params.
|
|
432
|
+
Priority: TOKEN parameter (decoded azp claim) > CLIENT_ID parameter > first config (default)
|
|
433
|
+
|
|
434
|
+
```typescript
|
|
435
|
+
import { getAuthConfig } from '@monkvision/network';
|
|
436
|
+
import { MonkSearchParam } from '@monkvision/common';
|
|
437
|
+
|
|
438
|
+
const configs = [
|
|
439
|
+
{
|
|
440
|
+
clientId: 'CID_EU',
|
|
441
|
+
domain: 'eu.auth0.com',
|
|
442
|
+
authorizationParams: { redirect_uri: 'https://eu.monk.ai' },
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
clientId: 'CID_US',
|
|
446
|
+
domain: 'us.auth0.com',
|
|
447
|
+
authorizationParams: { redirect_uri: 'https://us.monk.ai' },
|
|
448
|
+
},
|
|
449
|
+
];
|
|
450
|
+
|
|
451
|
+
// Suppose the URL includes ?c=CID_US
|
|
452
|
+
const config = getAuthConfig(configs);
|
|
453
|
+
console.log(config);
|
|
454
|
+
// → returns the "us" configuration
|
|
455
|
+
```
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkvision/network",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.8",
|
|
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": "5.1.
|
|
32
|
-
"@monkvision/sights": "5.1.
|
|
31
|
+
"@monkvision/common": "5.1.8",
|
|
32
|
+
"@monkvision/sights": "5.1.8",
|
|
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": "5.1.
|
|
46
|
-
"@monkvision/eslint-config-typescript": "5.1.
|
|
47
|
-
"@monkvision/jest-config": "5.1.
|
|
48
|
-
"@monkvision/prettier-config": "5.1.
|
|
49
|
-
"@monkvision/types": "5.1.
|
|
50
|
-
"@monkvision/typescript-config": "5.1.
|
|
45
|
+
"@monkvision/eslint-config-base": "5.1.8",
|
|
46
|
+
"@monkvision/eslint-config-typescript": "5.1.8",
|
|
47
|
+
"@monkvision/jest-config": "5.1.8",
|
|
48
|
+
"@monkvision/prettier-config": "5.1.8",
|
|
49
|
+
"@monkvision/types": "5.1.8",
|
|
50
|
+
"@monkvision/typescript-config": "5.1.8",
|
|
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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getInspection, createInspection, updateAdditionalData, getAllInspections, getAllInspectionsCount } from './inspection';
|
|
2
|
-
import { addImage } from './image';
|
|
2
|
+
import { addImage, deleteImage } from './image';
|
|
3
3
|
import { startInspectionTasks, updateTaskStatus } from './task';
|
|
4
4
|
import { getLiveConfig } from './liveConfigs';
|
|
5
5
|
import { updateInspectionVehicle } from './vehicle';
|
|
@@ -16,6 +16,7 @@ export declare const MonkApi: {
|
|
|
16
16
|
getAllInspectionsCount: typeof getAllInspectionsCount;
|
|
17
17
|
createInspection: typeof createInspection;
|
|
18
18
|
addImage: typeof addImage;
|
|
19
|
+
deleteImage: typeof deleteImage;
|
|
19
20
|
updateTaskStatus: typeof updateTaskStatus;
|
|
20
21
|
startInspectionTasks: typeof startInspectionTasks;
|
|
21
22
|
getLiveConfig: typeof getLiveConfig;
|
package/lib/src/api/api.js
CHANGED
|
@@ -19,6 +19,7 @@ exports.MonkApi = {
|
|
|
19
19
|
getAllInspectionsCount: inspection_1.getAllInspectionsCount,
|
|
20
20
|
createInspection: inspection_1.createInspection,
|
|
21
21
|
addImage: image_1.addImage,
|
|
22
|
+
deleteImage: image_1.deleteImage,
|
|
22
23
|
updateTaskStatus: task_1.updateTaskStatus,
|
|
23
24
|
startInspectionTasks: task_1.startInspectionTasks,
|
|
24
25
|
getLiveConfig: liveConfigs_1.getLiveConfig,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch } from 'react';
|
|
2
|
-
import { MonkCreatedOneImageAction } from '@monkvision/common';
|
|
2
|
+
import { MonkCreatedOneImageAction, MonkDeletedOneImageAction } from '@monkvision/common';
|
|
3
3
|
import { ComplianceOptions, Image, MonkPicture, TaskName, VehiclePart } from '@monkvision/types';
|
|
4
4
|
import { MonkApiConfig } from '../config';
|
|
5
5
|
import { ApiImage } from '../models';
|
|
@@ -195,3 +195,25 @@ export interface AddImageResponse {
|
|
|
195
195
|
* state management for you.
|
|
196
196
|
*/
|
|
197
197
|
export declare function addImage(options: AddImageOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkCreatedOneImageAction>): Promise<MonkApiResponse<AddImageResponse, ApiImage>>;
|
|
198
|
+
/**
|
|
199
|
+
* Options specified when deleting an image from an inspection.
|
|
200
|
+
*/
|
|
201
|
+
export interface DeleteImageOptions {
|
|
202
|
+
/**
|
|
203
|
+
* The ID of the inspection to update via the API.
|
|
204
|
+
*/
|
|
205
|
+
id: string;
|
|
206
|
+
/**
|
|
207
|
+
* Image ID that will be deleted.
|
|
208
|
+
*/
|
|
209
|
+
imageId: string;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Delete an image from an inspection.
|
|
213
|
+
*
|
|
214
|
+
* @param options Deletion options for the image.
|
|
215
|
+
* @param config The API config.
|
|
216
|
+
* @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
|
|
217
|
+
* state management for you.
|
|
218
|
+
*/
|
|
219
|
+
export declare function deleteImage(options: DeleteImageOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkDeletedOneImageAction>): Promise<MonkApiResponse>;
|
|
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.addImage = exports.ImageUploadType = void 0;
|
|
53
|
+
exports.deleteImage = exports.addImage = exports.ImageUploadType = void 0;
|
|
54
54
|
var ky_1 = __importDefault(require("ky"));
|
|
55
55
|
var common_1 = require("@monkvision/common");
|
|
56
56
|
var types_1 = require("@monkvision/types");
|
|
@@ -102,6 +102,7 @@ function getImageLabel(options) {
|
|
|
102
102
|
fr: "Trame Vid\u00E9o ".concat(options.frameIndex),
|
|
103
103
|
de: "Videobild ".concat(options.frameIndex),
|
|
104
104
|
nl: "Videoframe ".concat(options.frameIndex),
|
|
105
|
+
it: "Frame Video ".concat(options.frameIndex),
|
|
105
106
|
};
|
|
106
107
|
}
|
|
107
108
|
if (options.uploadType === ImageUploadType.VIDEO_MANUAL_PHOTO) {
|
|
@@ -110,6 +111,7 @@ function getImageLabel(options) {
|
|
|
110
111
|
fr: "Photo Manuelle Vid\u00E9o",
|
|
111
112
|
de: "Foto Manuell Video",
|
|
112
113
|
nl: "Foto-handleiding Video",
|
|
114
|
+
it: "Foto Manuale Video",
|
|
113
115
|
};
|
|
114
116
|
}
|
|
115
117
|
if (options.uploadType === ImageUploadType.PART_SELECT_SHOT) {
|
|
@@ -119,6 +121,7 @@ function getImageLabel(options) {
|
|
|
119
121
|
fr: "Photo Zoom\u00E9e sur ".concat(partsTranslation.map(function (part) { return part.en; }).join(', ')),
|
|
120
122
|
de: "Gezoomtes an ".concat(partsTranslation.map(function (part) { return part.en; }).join(', ')),
|
|
121
123
|
nl: "Nabij aan ".concat(partsTranslation.map(function (part) { return part.en; }).join(', ')),
|
|
124
|
+
it: "Close Up su ".concat(partsTranslation.map(function (part) { return part.en; }).join(', ')),
|
|
122
125
|
};
|
|
123
126
|
}
|
|
124
127
|
return {
|
|
@@ -126,6 +129,7 @@ function getImageLabel(options) {
|
|
|
126
129
|
fr: options.firstShot ? 'Photo Zoomée (partie)' : 'Photo Zoomée (dégât)',
|
|
127
130
|
de: options.firstShot ? 'Gezoomtes Foto (Teil)' : 'Close Up (Schaden)',
|
|
128
131
|
nl: options.firstShot ? 'Nabij (onderdeel)' : 'Nabij (schade)',
|
|
132
|
+
it: options.firstShot ? 'Close Up (parte)' : 'Close Up (danno)',
|
|
129
133
|
};
|
|
130
134
|
}
|
|
131
135
|
function getAdditionalData(options) {
|
|
@@ -417,3 +421,49 @@ function addImage(options, config, dispatch) {
|
|
|
417
421
|
});
|
|
418
422
|
}
|
|
419
423
|
exports.addImage = addImage;
|
|
424
|
+
/**
|
|
425
|
+
* Delete an image from an inspection.
|
|
426
|
+
*
|
|
427
|
+
* @param options Deletion options for the image.
|
|
428
|
+
* @param config The API config.
|
|
429
|
+
* @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
|
|
430
|
+
* state management for you.
|
|
431
|
+
*/
|
|
432
|
+
function deleteImage(options, config, dispatch) {
|
|
433
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
434
|
+
var kyOptions, response, body, err_2;
|
|
435
|
+
return __generator(this, function (_a) {
|
|
436
|
+
switch (_a.label) {
|
|
437
|
+
case 0:
|
|
438
|
+
kyOptions = (0, config_1.getDefaultOptions)(config);
|
|
439
|
+
_a.label = 1;
|
|
440
|
+
case 1:
|
|
441
|
+
_a.trys.push([1, 4, , 5]);
|
|
442
|
+
return [4 /*yield*/, ky_1.default.delete("inspections/".concat(options.id, "/images/").concat(options.imageId), __assign(__assign({}, kyOptions), { json: { authorized_tasks_statuses: [types_1.ProgressStatus.NOT_STARTED] } }))];
|
|
443
|
+
case 2:
|
|
444
|
+
response = _a.sent();
|
|
445
|
+
return [4 /*yield*/, response.json()];
|
|
446
|
+
case 3:
|
|
447
|
+
body = _a.sent();
|
|
448
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
449
|
+
type: common_1.MonkActionType.DELETED_ONE_IMAGE,
|
|
450
|
+
payload: {
|
|
451
|
+
inspectionId: options.id,
|
|
452
|
+
imageId: body.id,
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
return [2 /*return*/, {
|
|
456
|
+
id: body.id,
|
|
457
|
+
response: response,
|
|
458
|
+
body: body,
|
|
459
|
+
}];
|
|
460
|
+
case 4:
|
|
461
|
+
err_2 = _a.sent();
|
|
462
|
+
console.error("Failed to delete image: ".concat(err_2.message));
|
|
463
|
+
throw err_2;
|
|
464
|
+
case 5: return [2 /*return*/];
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
exports.deleteImage = deleteImage;
|
package/lib/src/api/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export { MonkNetworkError, type MonkHTTPError } from './error';
|
|
|
5
5
|
export { MonkApi } from './api';
|
|
6
6
|
export * from './hooks';
|
|
7
7
|
export { type GetInspectionOptions, type GetInspectionResponse, type GetAllInspectionsCountResponse, type UpdateAdditionalDataOptions, type GetAllInspectionsResponse, type GetAllInspectionsOptions, } from './inspection';
|
|
8
|
-
export { type AddImageResponse, type AddBeautyShotImageOptions, type Add2ShotCloseUpImageOptions, type AddImageOptions, type AddVideoFrameOptions, ImageUploadType, } from './image';
|
|
8
|
+
export { type AddImageResponse, type AddBeautyShotImageOptions, type Add2ShotCloseUpImageOptions, type AddImageOptions, type DeleteImageOptions, type AddVideoFrameOptions, ImageUploadType, } from './image';
|
|
9
9
|
export { type UpdateProgressStatus, type UpdateTaskStatusOptions, type StartInspectionTasksOptions, } from './task';
|
|
10
10
|
export { type UpdateInspectionVehicleOptions } from './vehicle';
|
|
@@ -56,3 +56,4 @@ export interface GetAllInspectionsOptions {
|
|
|
56
56
|
sort?: SortRequestParams;
|
|
57
57
|
}
|
|
58
58
|
export declare function mapApiAllInspectionsUrlParamsGet(options: GetAllInspectionsOptions, verbose: boolean | null, showDeleted: boolean): string;
|
|
59
|
+
export declare function mapApiInspectionUrlParamsGet(light: boolean): string;
|
|
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.mapApiAllInspectionsUrlParamsGet = exports.mapApiInspectionPost = exports.mapApiInspectionGet = exports.mapApiAllInspectionsVerboseGet = void 0;
|
|
14
|
+
exports.mapApiInspectionUrlParamsGet = exports.mapApiAllInspectionsUrlParamsGet = exports.mapApiInspectionPost = exports.mapApiInspectionGet = exports.mapApiAllInspectionsVerboseGet = void 0;
|
|
15
15
|
var types_1 = require("@monkvision/types");
|
|
16
16
|
var mappers_1 = require("../image/mappers");
|
|
17
17
|
var config_1 = require("../config");
|
|
@@ -552,3 +552,10 @@ function mapApiAllInspectionsUrlParamsGet(options, verbose, showDeleted) {
|
|
|
552
552
|
return "".concat(paramsStr.length > 0 ? '?' : '').concat(paramsStr);
|
|
553
553
|
}
|
|
554
554
|
exports.mapApiAllInspectionsUrlParamsGet = mapApiAllInspectionsUrlParamsGet;
|
|
555
|
+
function mapApiInspectionUrlParamsGet(light) {
|
|
556
|
+
if (!light) {
|
|
557
|
+
return '';
|
|
558
|
+
}
|
|
559
|
+
return '?verbose=light';
|
|
560
|
+
}
|
|
561
|
+
exports.mapApiInspectionUrlParamsGet = mapApiInspectionUrlParamsGet;
|
|
@@ -17,6 +17,13 @@ export interface GetInspectionOptions {
|
|
|
17
17
|
* Additional options used to configure the compliance locally.
|
|
18
18
|
*/
|
|
19
19
|
compliance?: ComplianceOptions;
|
|
20
|
+
/**
|
|
21
|
+
* If true, polygons are excluded from the inspection response,
|
|
22
|
+
* reducing payload size and improving request speed.
|
|
23
|
+
*
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
light?: boolean;
|
|
20
27
|
}
|
|
21
28
|
/**
|
|
22
29
|
* Type definition for the result of the `getInspection` API request.
|
|
@@ -65,17 +65,18 @@ var mappers_1 = require("./mappers");
|
|
|
65
65
|
*/
|
|
66
66
|
function getInspection(options, config, dispatch) {
|
|
67
67
|
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
-
var kyOptions, response, body, entities;
|
|
69
|
-
return __generator(this, function (
|
|
70
|
-
switch (
|
|
68
|
+
var _a, light, kyOptions, response, body, entities;
|
|
69
|
+
return __generator(this, function (_b) {
|
|
70
|
+
switch (_b.label) {
|
|
71
71
|
case 0:
|
|
72
|
+
_a = options.light, light = _a === void 0 ? true : _a;
|
|
72
73
|
kyOptions = (0, config_1.getDefaultOptions)(config);
|
|
73
|
-
return [4 /*yield*/, ky_1.default.get("inspections/".concat(options.id), kyOptions)];
|
|
74
|
+
return [4 /*yield*/, ky_1.default.get("inspections/".concat(options.id).concat((0, mappers_1.mapApiInspectionUrlParamsGet)(light)), kyOptions)];
|
|
74
75
|
case 1:
|
|
75
|
-
response =
|
|
76
|
+
response = _b.sent();
|
|
76
77
|
return [4 /*yield*/, response.json()];
|
|
77
78
|
case 2:
|
|
78
|
-
body =
|
|
79
|
+
body = _b.sent();
|
|
79
80
|
entities = (0, mappers_1.mapApiInspectionGet)(body, config.thumbnailDomain, options.compliance);
|
|
80
81
|
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
81
82
|
type: common_1.MonkActionType.GOT_ONE_INSPECTION,
|
package/lib/src/api/react.d.ts
CHANGED
|
@@ -40,6 +40,12 @@ export declare function useMonkApi(config: MonkApiConfig): {
|
|
|
40
40
|
* @param options Upload options for the image.
|
|
41
41
|
*/
|
|
42
42
|
addImage: (options: import("./image").AddImageOptions) => Promise<import("./types").MonkApiResponse<import("./image").AddImageResponse, import("./models").ApiImage>>;
|
|
43
|
+
/**
|
|
44
|
+
* Delete an image from an inspection.
|
|
45
|
+
*
|
|
46
|
+
* @param options The options of the request.
|
|
47
|
+
*/
|
|
48
|
+
deleteImage: (options: import("./image").DeleteImageOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn>>;
|
|
43
49
|
/**
|
|
44
50
|
* Update the progress status of an inspection task.
|
|
45
51
|
*
|
package/lib/src/api/react.js
CHANGED
|
@@ -77,6 +77,12 @@ function useMonkApi(config) {
|
|
|
77
77
|
* @param options Upload options for the image.
|
|
78
78
|
*/
|
|
79
79
|
addImage: reactify(api_1.MonkApi.addImage, config, dispatch, handleError),
|
|
80
|
+
/**
|
|
81
|
+
* Delete an image from an inspection.
|
|
82
|
+
*
|
|
83
|
+
* @param options The options of the request.
|
|
84
|
+
*/
|
|
85
|
+
deleteImage: reactify(api_1.MonkApi.deleteImage, config, dispatch, handleError),
|
|
80
86
|
/**
|
|
81
87
|
* Update the progress status of an inspection task.
|
|
82
88
|
*
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { AuthConfig } from './authProvider.types';
|
|
3
|
+
/**
|
|
4
|
+
* Props accepted by the AuthProvider component.
|
|
5
|
+
*/
|
|
6
|
+
export interface AuthProviderProps {
|
|
7
|
+
/**
|
|
8
|
+
* List of Auth0 configurations to choose from based on URL parameters.
|
|
9
|
+
*/
|
|
10
|
+
configs: AuthConfig[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Authentication provider that selects the appropriate Auth0 configuration based on URL parameters.
|
|
14
|
+
*/
|
|
15
|
+
export declare function AuthProvider({ configs, children }: PropsWithChildren<AuthProviderProps>): JSX.Element;
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.AuthProvider = void 0;
|
|
15
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
+
var react_1 = require("react");
|
|
17
|
+
var auth0_react_1 = require("@auth0/auth0-react");
|
|
18
|
+
var common_1 = require("@monkvision/common");
|
|
19
|
+
var token_1 = require("./token");
|
|
20
|
+
function AuthValidator(_a) {
|
|
21
|
+
var clientId = _a.clientId;
|
|
22
|
+
var logout = (0, auth0_react_1.useAuth0)().logout;
|
|
23
|
+
(0, react_1.useEffect)(function () {
|
|
24
|
+
var storedToken = localStorage.getItem(common_1.STORAGE_KEY_AUTH_TOKEN);
|
|
25
|
+
if (!(0, token_1.isTokenValid)(clientId) && storedToken) {
|
|
26
|
+
localStorage.removeItem(common_1.STORAGE_KEY_AUTH_TOKEN);
|
|
27
|
+
logout({ logoutParams: { returnTo: window.location.href } });
|
|
28
|
+
}
|
|
29
|
+
}, [clientId, logout]);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Authentication provider that selects the appropriate Auth0 configuration based on URL parameters.
|
|
34
|
+
*/
|
|
35
|
+
function AuthProvider(_a) {
|
|
36
|
+
var configs = _a.configs, children = _a.children;
|
|
37
|
+
var config = (0, token_1.getAuthConfig)(configs);
|
|
38
|
+
if (!config) {
|
|
39
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
40
|
+
}
|
|
41
|
+
return ((0, jsx_runtime_1.jsxs)(auth0_react_1.Auth0Provider, __assign({ domain: config.domain, clientId: config.clientId, authorizationParams: config.authorizationParams, context: config.context }, { children: [(0, jsx_runtime_1.jsx)(AuthValidator, { clientId: config.clientId }), children] })));
|
|
42
|
+
}
|
|
43
|
+
exports.AuthProvider = AuthProvider;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Context } from 'react';
|
|
2
|
+
import { Auth0ContextInterface, AuthorizationParams } from '@auth0/auth0-react';
|
|
3
|
+
/**
|
|
4
|
+
* Auth0 authentication configuration.
|
|
5
|
+
*/
|
|
6
|
+
export interface AuthConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Auth0 domain (e.g., "idp.monk.ai").
|
|
9
|
+
*/
|
|
10
|
+
domain: string;
|
|
11
|
+
/**
|
|
12
|
+
* Auth0 client ID.
|
|
13
|
+
*/
|
|
14
|
+
clientId: string;
|
|
15
|
+
/**
|
|
16
|
+
* Authorization parameters for Auth0.
|
|
17
|
+
*/
|
|
18
|
+
authorizationParams: AuthorizationParams;
|
|
19
|
+
/**
|
|
20
|
+
* Base domain for API requests.
|
|
21
|
+
*/
|
|
22
|
+
apiDomain?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Domain for thumbnail images (image_resize microservice).
|
|
25
|
+
*/
|
|
26
|
+
thumbnailDomain?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Custom Auth0 context (optional).
|
|
29
|
+
*/
|
|
30
|
+
context?: Context<Auth0ContextInterface>;
|
|
31
|
+
}
|
package/lib/src/auth/index.d.ts
CHANGED
package/lib/src/auth/index.js
CHANGED
|
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./token"), exports);
|
|
18
18
|
__exportStar(require("./hooks"), exports);
|
|
19
|
+
__exportStar(require("./authProvider"), exports);
|
|
20
|
+
__exportStar(require("./authProvider.types"), exports);
|
package/lib/src/auth/token.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JwtPayload } from 'jsonwebtoken';
|
|
2
2
|
import { MonkApiPermission } from '@monkvision/types';
|
|
3
|
+
import { AuthConfig } from './authProvider.types';
|
|
3
4
|
/**
|
|
4
5
|
* The payload of the authentication token used with the Monk API.
|
|
5
6
|
*/
|
|
@@ -27,3 +28,12 @@ export declare function isUserAuthorized(tokenOrPayload: MonkJwtPayload | string
|
|
|
27
28
|
* decoded or the JWT payload directly.
|
|
28
29
|
*/
|
|
29
30
|
export declare function isTokenExpired(tokenOrPayload: MonkJwtPayload | string | null): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Utility function that checks if the stored auth token is valid for the given Auth0 Client ID.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isTokenValid(clientID: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Utility function that retrieves the appropriate AuthConfig based on the URL search params.
|
|
37
|
+
* Priority: TOKEN parameter (decoded azp claim) > CLIENT_ID parameter > first config (default)
|
|
38
|
+
*/
|
|
39
|
+
export declare function getAuthConfig(configs: AuthConfig[]): AuthConfig | undefined;
|
package/lib/src/auth/token.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isTokenExpired = exports.isUserAuthorized = exports.decodeMonkJwt = void 0;
|
|
3
|
+
exports.getAuthConfig = exports.isTokenValid = exports.isTokenExpired = exports.isUserAuthorized = exports.decodeMonkJwt = void 0;
|
|
4
4
|
var jwt_decode_1 = require("jwt-decode");
|
|
5
|
+
var common_1 = require("@monkvision/common");
|
|
5
6
|
/**
|
|
6
7
|
* Decode the given Monk auth token and returns the MonkJwtPayload.
|
|
7
8
|
*/
|
|
@@ -33,3 +34,29 @@ function isTokenExpired(tokenOrPayload) {
|
|
|
33
34
|
return !payload.exp || Math.round(Date.now() / 1000) >= payload.exp;
|
|
34
35
|
}
|
|
35
36
|
exports.isTokenExpired = isTokenExpired;
|
|
37
|
+
/**
|
|
38
|
+
* Utility function that checks if the stored auth token is valid for the given Auth0 Client ID.
|
|
39
|
+
*/
|
|
40
|
+
function isTokenValid(clientID) {
|
|
41
|
+
var fetchedToken = localStorage.getItem(common_1.STORAGE_KEY_AUTH_TOKEN);
|
|
42
|
+
var fetchedClientId = fetchedToken ? decodeMonkJwt(fetchedToken).azp : null;
|
|
43
|
+
return fetchedClientId === clientID;
|
|
44
|
+
}
|
|
45
|
+
exports.isTokenValid = isTokenValid;
|
|
46
|
+
/**
|
|
47
|
+
* Utility function that retrieves the appropriate AuthConfig based on the URL search params.
|
|
48
|
+
* Priority: TOKEN parameter (decoded azp claim) > CLIENT_ID parameter > first config (default)
|
|
49
|
+
*/
|
|
50
|
+
function getAuthConfig(configs) {
|
|
51
|
+
if (!configs.length) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
var searchParams = new URL(window.location.href).searchParams;
|
|
55
|
+
var tokenParam = searchParams.get(common_1.MonkSearchParam.TOKEN);
|
|
56
|
+
var clientIdParam = searchParams.get(common_1.MonkSearchParam.CLIENT_ID);
|
|
57
|
+
var tokenClientId = tokenParam ? decodeMonkJwt((0, common_1.zlibDecompress)(tokenParam)).azp : null;
|
|
58
|
+
var targetClientId = tokenClientId || clientIdParam;
|
|
59
|
+
var matchingConfig = configs.find(function (config) { return config.clientId === targetClientId; });
|
|
60
|
+
return matchingConfig !== null && matchingConfig !== void 0 ? matchingConfig : configs[0];
|
|
61
|
+
}
|
|
62
|
+
exports.getAuthConfig = getAuthConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkvision/network",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
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": "5.
|
|
32
|
-
"@monkvision/sights": "5.
|
|
31
|
+
"@monkvision/common": "5.2.0",
|
|
32
|
+
"@monkvision/sights": "5.2.0",
|
|
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": "5.
|
|
46
|
-
"@monkvision/eslint-config-typescript": "5.
|
|
47
|
-
"@monkvision/jest-config": "5.
|
|
48
|
-
"@monkvision/prettier-config": "5.
|
|
49
|
-
"@monkvision/types": "5.
|
|
50
|
-
"@monkvision/typescript-config": "5.
|
|
45
|
+
"@monkvision/eslint-config-base": "5.2.0",
|
|
46
|
+
"@monkvision/eslint-config-typescript": "5.2.0",
|
|
47
|
+
"@monkvision/jest-config": "5.2.0",
|
|
48
|
+
"@monkvision/prettier-config": "5.2.0",
|
|
49
|
+
"@monkvision/types": "5.2.0",
|
|
50
|
+
"@monkvision/typescript-config": "5.2.0",
|
|
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": "5380665942c8c075485142183e431996657e70d1"
|
|
88
88
|
}
|