@monkvision/network 4.3.2 → 4.3.3

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 CHANGED
@@ -210,6 +210,20 @@ Delete a damage of an inspection.
210
210
  |-----------|---------------------|-----------------------------|----------|
211
211
  | options | DeleteDamageOptions | The options of the request. | ✔️ |
212
212
 
213
+ ### getInspections
214
+ ```typescript
215
+ import { MonkApi } from '@monkvision/network';
216
+
217
+ MonkApi.getInspections(options, apiConfig, dispatch);
218
+ ```
219
+
220
+ Fetch the details of multiple inspections using the provided filters. The resulting action of this request will contain
221
+ a list of all entities that match the specified criteria.
222
+
223
+ | Parameter | Type | Description | Required |
224
+ |-----------|-----------------------|-----------------------------|----------|
225
+ | options | getInspectionsOptions | The options of the request. | ✔️ |
226
+
213
227
  # React Tools
214
228
  In order to simply integrate the Monk Api requests into your React app, you can make use of the `useMonkApi` hook. This
215
229
  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.3.1",
3
+ "version": "4.3.2",
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.3.1",
32
- "@monkvision/sights": "4.3.1",
31
+ "@monkvision/common": "4.3.2",
32
+ "@monkvision/sights": "4.3.2",
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.3.1",
46
- "@monkvision/eslint-config-typescript": "4.3.1",
47
- "@monkvision/jest-config": "4.3.1",
48
- "@monkvision/prettier-config": "4.3.1",
49
- "@monkvision/types": "4.3.1",
50
- "@monkvision/typescript-config": "4.3.1",
45
+ "@monkvision/eslint-config-base": "4.3.2",
46
+ "@monkvision/eslint-config-typescript": "4.3.2",
47
+ "@monkvision/jest-config": "4.3.2",
48
+ "@monkvision/prettier-config": "4.3.2",
49
+ "@monkvision/types": "4.3.2",
50
+ "@monkvision/typescript-config": "4.3.2",
51
51
  "@types/jest": "^29.2.2",
52
52
  "@types/jsonwebtoken": "^9.0.5",
53
53
  "@types/node": "^18.11.9",
@@ -1,4 +1,4 @@
1
- import { getInspection, createInspection, updateAdditionalData } from './inspection';
1
+ import { getInspection, createInspection, updateAdditionalData, getInspections } from './inspection';
2
2
  import { addImage } from './image';
3
3
  import { startInspectionTasks, updateTaskStatus } from './task';
4
4
  import { getLiveConfig } from './liveConfigs';
@@ -11,6 +11,7 @@ import { createDamage, deleteDamage } from './damage';
11
11
  */
12
12
  export declare const MonkApi: {
13
13
  getInspection: typeof getInspection;
14
+ getInspections: typeof getInspections;
14
15
  createInspection: typeof createInspection;
15
16
  addImage: typeof addImage;
16
17
  updateTaskStatus: typeof updateTaskStatus;
@@ -14,6 +14,7 @@ var damage_1 = require("./damage");
14
14
  */
15
15
  exports.MonkApi = {
16
16
  getInspection: inspection_1.getInspection,
17
+ getInspections: inspection_1.getInspections,
17
18
  createInspection: inspection_1.createInspection,
18
19
  addImage: image_1.addImage,
19
20
  updateTaskStatus: task_1.updateTaskStatus,
@@ -1,5 +1,64 @@
1
1
  import { MonkState } from '@monkvision/common';
2
- import { ComplianceOptions, CreateInspectionOptions } from '@monkvision/types';
3
- import { ApiInspectionGet, ApiInspectionPost } from '../models';
2
+ import { ComplianceOptions, CreateInspectionOptions, SortOrder } from '@monkvision/types';
3
+ import { ApiInspectionGet, ApiInspectionPost, ApiInspectionsGet } from '../models';
4
+ export declare function mapApiInspectionsGet(response: ApiInspectionsGet, thumbnailDomain: string): MonkState;
4
5
  export declare function mapApiInspectionGet(response: ApiInspectionGet, thumbnailDomain: string, complianceOptions?: ComplianceOptions): MonkState;
5
6
  export declare function mapApiInspectionPost(options: CreateInspectionOptions): ApiInspectionPost;
7
+ /**
8
+ * Parameters for pagination requests.
9
+ */
10
+ export interface PaginationRequestParams {
11
+ /**
12
+ * The number of inspections fetched.
13
+ *
14
+ * @default 100
15
+ */
16
+ limit?: number;
17
+ /**
18
+ * The inspection ID to filter that occurred before this ID.
19
+ */
20
+ before?: string;
21
+ /**
22
+ * The inspection ID to filter that occurred after this date.
23
+ */
24
+ after?: string;
25
+ }
26
+ /**
27
+ * Parameters for sorting requests.
28
+ */
29
+ export interface SortRequestParams {
30
+ /**
31
+ * The property to sort by.
32
+ */
33
+ sortByProperty: string;
34
+ /**
35
+ * The order of the pagination.
36
+ *
37
+ * @default SortOrder.DESC
38
+ */
39
+ sortOrder?: SortOrder;
40
+ }
41
+ /**
42
+ * Options passed to the `getInspections` API request.
43
+ */
44
+ export interface GetInspectionsOptions {
45
+ /**
46
+ * If true, only the total count of inspections will be returned.
47
+ *
48
+ * @default false
49
+ */
50
+ count?: boolean;
51
+ /**
52
+ * The filter request parameters.
53
+ */
54
+ filters?: Record<string, string | number>;
55
+ /**
56
+ * The pagination request parameters.
57
+ */
58
+ pagination?: PaginationRequestParams;
59
+ /**
60
+ * The sort request parameters.
61
+ */
62
+ sort?: SortRequestParams;
63
+ }
64
+ export declare function mapApiInspectionsUrlParamsGet(options: GetInspectionsOptions): 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.mapApiInspectionPost = exports.mapApiInspectionGet = void 0;
14
+ exports.mapApiInspectionsUrlParamsGet = exports.mapApiInspectionPost = exports.mapApiInspectionGet = exports.mapApiInspectionsGet = 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");
@@ -279,6 +279,54 @@ function mapInspection(response, ids) {
279
279
  additionalData: response.additional_data,
280
280
  };
281
281
  }
282
+ function mapApiInspectionsGet(response, thumbnailDomain) {
283
+ var state = {
284
+ damages: [],
285
+ images: [],
286
+ inspections: [],
287
+ parts: [],
288
+ renderedOutputs: [],
289
+ severityResults: [],
290
+ tasks: [],
291
+ vehicles: [],
292
+ views: [],
293
+ pricings: [],
294
+ partOperations: [],
295
+ };
296
+ if (!response.data) {
297
+ return state;
298
+ }
299
+ return response.data.reduce(function (acc, inspection) {
300
+ var _a, _b, _c, _d, _e;
301
+ var _f = mapImages(inspection, thumbnailDomain), images = _f.images, renderedOutputs = _f.renderedOutputs, imageIds = _f.imageIds, renderedOutputIds = _f.renderedOutputIds, viewIds = _f.viewIds;
302
+ var _g = mapDamages(inspection), damages = _g.damages, damageIds = _g.damageIds;
303
+ var _h = mapParts(inspection), parts = _h.parts, partIds = _h.partIds;
304
+ var _j = mapPricingV2(inspection), pricings = _j.pricings, pricingIds = _j.pricingIds;
305
+ var vehicle = mapVehicle(inspection);
306
+ var mappedInspection = mapInspection(inspection, {
307
+ imageIds: imageIds,
308
+ renderedOutputIds: renderedOutputIds,
309
+ viewIds: viewIds,
310
+ damageIds: damageIds,
311
+ partIds: partIds,
312
+ severityResultIds: [],
313
+ taskIds: [],
314
+ pricingIds: pricingIds,
315
+ vehicleId: vehicle === null || vehicle === void 0 ? void 0 : vehicle.id,
316
+ });
317
+ (_a = acc.damages).push.apply(_a, damages);
318
+ (_b = acc.images).push.apply(_b, images);
319
+ acc.inspections.push(mappedInspection);
320
+ (_c = acc.parts).push.apply(_c, parts);
321
+ (_d = acc.renderedOutputs).push.apply(_d, renderedOutputs);
322
+ if (vehicle) {
323
+ acc.vehicles.push(vehicle);
324
+ }
325
+ (_e = acc.pricings).push.apply(_e, pricings);
326
+ return acc;
327
+ }, state);
328
+ }
329
+ exports.mapApiInspectionsGet = mapApiInspectionsGet;
282
330
  function mapApiInspectionGet(response, thumbnailDomain, complianceOptions) {
283
331
  var _a = mapImages(response, thumbnailDomain, complianceOptions), images = _a.images, renderedOutputs = _a.renderedOutputs, views = _a.views, imageIds = _a.imageIds, renderedOutputIds = _a.renderedOutputIds, viewIds = _a.viewIds;
284
332
  var _b = mapDamages(response), damages = _b.damages, damageIds = _b.damageIds;
@@ -435,3 +483,28 @@ function mapApiInspectionPost(options) {
435
483
  };
436
484
  }
437
485
  exports.mapApiInspectionPost = mapApiInspectionPost;
486
+ function mapApiInspectionsUrlParamsGet(options) {
487
+ var params = new URLSearchParams();
488
+ var url = options.count ? '/count' : '';
489
+ url = options.filters || options.pagination ? "".concat(url, "?") : url;
490
+ if (options.filters) {
491
+ Object.entries(options.filters).forEach(function (_a) {
492
+ var key = _a[0], value = _a[1];
493
+ params.append(key, value.toString());
494
+ });
495
+ }
496
+ if (options.pagination) {
497
+ Object.entries(options.pagination).forEach(function (_a) {
498
+ var key = _a[0], value = _a[1];
499
+ params.append(key, value.toString());
500
+ });
501
+ }
502
+ if (options.sort) {
503
+ Object.entries(options.sort).forEach(function (_a) {
504
+ var key = _a[0], value = _a[1];
505
+ params.append(key, value.toString());
506
+ });
507
+ }
508
+ return "".concat(url).concat(params.toString());
509
+ }
510
+ exports.mapApiInspectionsUrlParamsGet = mapApiInspectionsUrlParamsGet;
@@ -2,7 +2,8 @@ import { MonkAction, MonkGotOneInspectionAction, MonkState, MonkUpdatedOneInspec
2
2
  import { AdditionalData, ComplianceOptions, CreateInspectionOptions } from '@monkvision/types';
3
3
  import { Dispatch } from 'react';
4
4
  import { MonkApiConfig } from '../config';
5
- import { ApiInspectionGet } from '../models';
5
+ import { ApiInspectionGet, ApiInspectionsGet } from '../models';
6
+ import { GetInspectionsOptions } from './mappers';
6
7
  import { MonkApiResponse } from '../types';
7
8
  /**
8
9
  * Options passed to the `getInspection` API request.
@@ -69,3 +70,12 @@ export interface UpdateAdditionalDataOptions {
69
70
  * @see UpdateAdditionalDataOptions
70
71
  */
71
72
  export declare function updateAdditionalData(options: UpdateAdditionalDataOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkUpdatedOneInspectionAdditionalDataAction>): Promise<MonkApiResponse>;
73
+ /**
74
+ * Fetch the details of multiple inspections.
75
+ *
76
+ * @param options The options of the request.
77
+ * @param config The API config.
78
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
79
+ * state management for you.
80
+ */
81
+ export declare function getInspections(options: GetInspectionsOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkGotOneInspectionAction>): Promise<MonkApiResponse | MonkApiResponse<GetInspectionResponse, ApiInspectionsGet>>;
@@ -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.updateAdditionalData = exports.createInspection = exports.getInspection = void 0;
53
+ exports.getInspections = exports.updateAdditionalData = exports.createInspection = exports.getInspection = void 0;
54
54
  var ky_1 = __importDefault(require("ky"));
55
55
  var common_1 = require("@monkvision/common");
56
56
  var config_1 = require("../config");
@@ -166,3 +166,35 @@ function updateAdditionalData(options, config, dispatch) {
166
166
  });
167
167
  }
168
168
  exports.updateAdditionalData = updateAdditionalData;
169
+ /**
170
+ * Fetch the details of multiple inspections.
171
+ *
172
+ * @param options The options of the request.
173
+ * @param config The API config.
174
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
175
+ * state management for you.
176
+ */
177
+ function getInspections(options, config, dispatch) {
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ var kyOptions, response, body, entities;
180
+ return __generator(this, function (_a) {
181
+ switch (_a.label) {
182
+ case 0:
183
+ kyOptions = (0, config_1.getDefaultOptions)(config);
184
+ return [4 /*yield*/, ky_1.default.get("inspections".concat((0, mappers_1.mapApiInspectionsUrlParamsGet)(options)), kyOptions)];
185
+ case 1:
186
+ response = _a.sent();
187
+ return [4 /*yield*/, response.json()];
188
+ case 2:
189
+ body = _a.sent();
190
+ entities = (0, mappers_1.mapApiInspectionsGet)(body, config.thumbnailDomain);
191
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({
192
+ type: common_1.MonkActionType.GOT_ONE_INSPECTION,
193
+ payload: entities,
194
+ });
195
+ return [2 /*return*/, { entities: entities, response: response, body: body }];
196
+ }
197
+ });
198
+ });
199
+ }
200
+ exports.getInspections = getInspections;
@@ -1,3 +1,4 @@
1
+ import { SortOrder } from '@monkvision/types';
1
2
  import type { ApiAdditionalData } from './common';
2
3
  import type { ApiDamages } from './damage';
3
4
  import type { ApiImagePost, ApiImages } from './image';
@@ -26,6 +27,28 @@ export interface ApiInspectionGet {
26
27
  vehicle?: ApiVehicleComponent;
27
28
  wheel_analysis?: ApiWheelAnalysis;
28
29
  }
30
+ interface ApiData extends Pick<ApiInspectionGet, 'id' | 'additional_data' | 'images' | 'damages' | 'pricing' | 'parts' | 'vehicle'> {
31
+ pdf_url?: string;
32
+ }
33
+ interface ApiPaginationParams {
34
+ limit?: number;
35
+ before?: string;
36
+ after?: string;
37
+ pagination_order?: SortOrder;
38
+ }
39
+ interface ApiCursors {
40
+ before?: Pick<ApiPaginationParams, 'before'>;
41
+ after?: Pick<ApiPaginationParams, 'after'>;
42
+ next?: ApiPaginationParams;
43
+ previous?: ApiPaginationParams;
44
+ }
45
+ interface ApiPagination {
46
+ cursors: ApiCursors;
47
+ }
48
+ export interface ApiInspectionsGet {
49
+ data: ApiData[];
50
+ paging: ApiPagination;
51
+ }
29
52
  export interface ApiDamageSeverity {
30
53
  output_format: ApiBusinessClients;
31
54
  }
@@ -36,3 +59,4 @@ export interface ApiInspectionPost {
36
59
  vehicle?: ApiVehiclePostPatch;
37
60
  damage_severity?: ApiDamageSeverity;
38
61
  }
62
+ export {};
@@ -15,6 +15,12 @@ export declare function useMonkApi(config: MonkApiConfig): {
15
15
  * @param options The options of the request.
16
16
  */
17
17
  getInspection: (options: import("./inspection").GetInspectionOptions) => Promise<import("./types").MonkApiResponse<import("./inspection").GetInspectionResponse, import("./models").ApiInspectionGet>>;
18
+ /**
19
+ * Fetch multiple inspection.
20
+ *
21
+ * @param options The options of the request.
22
+ */
23
+ getInspections: (options: import("./inspection/mappers").GetInspectionsOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn> | import("./types").MonkApiResponse<import("./inspection").GetInspectionResponse, import("./models").ApiInspectionsGet>>;
18
24
  /**
19
25
  * Create a new inspection with the given options. See the `CreateInspectionOptions` interface for more details.
20
26
  *
@@ -52,6 +52,12 @@ function useMonkApi(config) {
52
52
  * @param options The options of the request.
53
53
  */
54
54
  getInspection: reactify(api_1.MonkApi.getInspection, config, dispatch, handleError),
55
+ /**
56
+ * Fetch multiple inspection.
57
+ *
58
+ * @param options The options of the request.
59
+ */
60
+ getInspections: reactify(api_1.MonkApi.getInspections, config, dispatch, handleError),
55
61
  /**
56
62
  * Create a new inspection with the given options. See the `CreateInspectionOptions` interface for more details.
57
63
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkvision/network",
3
- "version": "4.3.2",
3
+ "version": "4.3.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.3.2",
32
- "@monkvision/sights": "4.3.2",
31
+ "@monkvision/common": "4.3.3",
32
+ "@monkvision/sights": "4.3.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.3.2",
46
- "@monkvision/eslint-config-typescript": "4.3.2",
47
- "@monkvision/jest-config": "4.3.2",
48
- "@monkvision/prettier-config": "4.3.2",
49
- "@monkvision/types": "4.3.2",
50
- "@monkvision/typescript-config": "4.3.2",
45
+ "@monkvision/eslint-config-base": "4.3.3",
46
+ "@monkvision/eslint-config-typescript": "4.3.3",
47
+ "@monkvision/jest-config": "4.3.3",
48
+ "@monkvision/prettier-config": "4.3.3",
49
+ "@monkvision/types": "4.3.3",
50
+ "@monkvision/typescript-config": "4.3.3",
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": "79cad6f0e22de9347582794b822d7843847e0d82"
87
+ "gitHead": "333b427e8497da0654c4ac6e4c72f81a8c89d93b"
88
88
  }