@monkvision/network 4.0.24 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -117,6 +117,59 @@ Update the vehicle of an inspection.
117
117
  |-----------|--------------------------------|-----------------------------|----------|
118
118
  | options | UpdateInspectionVehicleOptions | The options of the request. | ✔️ |
119
119
 
120
+ ### createPricing
121
+ ```typescript
122
+ import { MonkApi } from '@monkvision/network';
123
+
124
+ MonkApi.createPricing(options, apiConfig, dispatch);
125
+ ```
126
+
127
+ Create a new pricing of an inspection.
128
+
129
+ | Parameter | Type | Description | Required |
130
+ |-----------|----------------------|-----------------------------|----------|
131
+ | options | CreatePricingOptions | The options of the request. | ✔️ |
132
+
133
+ ### updatePricing
134
+ ```typescript
135
+ import { MonkApi } from '@monkvision/network';
136
+
137
+ MonkApi.updatePricing(options, apiConfig, dispatch);
138
+ ```
139
+
140
+ Update a pricing of an inspection.
141
+
142
+ | Parameter | Type | Description | Required |
143
+ |-----------|----------------------|-----------------------------|----------|
144
+ | options | UpdatePricingOptions | The options of the request. | ✔️ |
145
+
146
+ ### deletePricing
147
+ ```typescript
148
+ import { MonkApi } from '@monkvision/network';
149
+
150
+ MonkApi.deletePricing(options, apiConfig, dispatch);
151
+ ```
152
+
153
+ Update a pricing of an inspection.
154
+
155
+ | Parameter | Type | Description | Required |
156
+ |-----------|----------------------|-----------------------------|----------|
157
+ | options | DeletePricingOptions | The options of the request. | ✔️ |
158
+
159
+ ### updateAdditionalData
160
+ ```typescript
161
+ import { MonkApi } from '@monkvision/network';
162
+
163
+ MonkApi.updateAdditionalData(options, apiConfig, dispatch);
164
+ ```
165
+
166
+ Update the additional data of an inspection.
167
+
168
+ | Parameter | Type | Description | Required |
169
+ |-----------|-----------------------------|-----------------------------|----------|
170
+ | options | UpdateAdditionalDataOptions | The options of the request. | ✔️ |
171
+
172
+
120
173
  # React Tools
121
174
  In order to simply integrate the Monk Api requests into your React app, you can make use of the `useMonkApi` hook. This
122
175
  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.0.23",
3
+ "version": "4.0.24",
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.0.23",
32
- "@monkvision/sights": "4.0.23",
31
+ "@monkvision/common": "4.0.24",
32
+ "@monkvision/sights": "4.0.24",
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.0.23",
46
- "@monkvision/eslint-config-typescript": "4.0.23",
47
- "@monkvision/jest-config": "4.0.23",
48
- "@monkvision/prettier-config": "4.0.23",
49
- "@monkvision/types": "4.0.23",
50
- "@monkvision/typescript-config": "4.0.23",
45
+ "@monkvision/eslint-config-base": "4.0.24",
46
+ "@monkvision/eslint-config-typescript": "4.0.24",
47
+ "@monkvision/jest-config": "4.0.24",
48
+ "@monkvision/prettier-config": "4.0.24",
49
+ "@monkvision/types": "4.0.24",
50
+ "@monkvision/typescript-config": "4.0.24",
51
51
  "@types/jest": "^29.2.2",
52
52
  "@types/jsonwebtoken": "^9.0.5",
53
53
  "@types/node": "^18.11.9",
@@ -1,8 +1,9 @@
1
- import { getInspection, createInspection } from './inspection';
1
+ import { getInspection, createInspection, updateAdditionalData } from './inspection';
2
2
  import { addImage } from './image';
3
3
  import { startInspectionTasks, updateTaskStatus } from './task';
4
4
  import { getLiveConfig } from './liveConfigs';
5
5
  import { updateInspectionVehicle } from './vehicle';
6
+ import { createPricing, deletePricing, updatePricing } from './pricing';
6
7
  /**
7
8
  * Object regrouping the different API requests available to communicate with the API using the `@monkvision/network`
8
9
  * package.
@@ -15,4 +16,8 @@ export declare const MonkApi: {
15
16
  startInspectionTasks: typeof startInspectionTasks;
16
17
  getLiveConfig: typeof getLiveConfig;
17
18
  updateInspectionVehicle: typeof updateInspectionVehicle;
19
+ updateAdditionalData: typeof updateAdditionalData;
20
+ createPricing: typeof createPricing;
21
+ deletePricing: typeof deletePricing;
22
+ updatePricing: typeof updatePricing;
18
23
  };
@@ -6,6 +6,7 @@ var image_1 = require("./image");
6
6
  var task_1 = require("./task");
7
7
  var liveConfigs_1 = require("./liveConfigs");
8
8
  var vehicle_1 = require("./vehicle");
9
+ var pricing_1 = require("./pricing");
9
10
  /**
10
11
  * Object regrouping the different API requests available to communicate with the API using the `@monkvision/network`
11
12
  * package.
@@ -18,4 +19,8 @@ exports.MonkApi = {
18
19
  startInspectionTasks: task_1.startInspectionTasks,
19
20
  getLiveConfig: liveConfigs_1.getLiveConfig,
20
21
  updateInspectionVehicle: vehicle_1.updateInspectionVehicle,
22
+ updateAdditionalData: inspection_1.updateAdditionalData,
23
+ createPricing: pricing_1.createPricing,
24
+ deletePricing: pricing_1.deletePricing,
25
+ updatePricing: pricing_1.updatePricing,
21
26
  };
@@ -137,6 +137,8 @@ function mapPricingV2Details(apiPricingV2Details, inspectionId) {
137
137
  var details = apiPricingV2Details;
138
138
  return {
139
139
  inspectionId: inspectionId,
140
+ id: details.id,
141
+ entityType: types_1.MonkEntityType.PRICING,
140
142
  relatedItemType: details.related_item_type,
141
143
  relatedItemId: details.related_item_id,
142
144
  pricing: details.pricing,
@@ -145,19 +147,16 @@ function mapPricingV2Details(apiPricingV2Details, inspectionId) {
145
147
  };
146
148
  }
147
149
  function mapPricingV2(response) {
150
+ var pricings = [];
151
+ var pricingIds = [];
148
152
  if (!response.pricing) {
149
- return undefined;
153
+ return { pricings: pricings, pricingIds: pricingIds };
150
154
  }
151
- return {
152
- details: (response === null || response === void 0 ? void 0 : response.pricing.details)
153
- ? Object.keys(response.pricing.details).reduce(function (prev, curr) {
154
- var _a;
155
- var _b;
156
- return (__assign(__assign({}, prev), (_a = {}, _a[curr] = mapPricingV2Details((_b = response.pricing) === null || _b === void 0 ? void 0 : _b.details[curr], response.id), _a)));
157
- }, {})
158
- : {},
159
- totalPrice: response.pricing.total_price,
160
- };
155
+ Object.values(response.pricing.details).forEach(function (details) {
156
+ pricingIds.push(details.id);
157
+ pricings.push(mapPricingV2Details(details, response.id));
158
+ });
159
+ return { pricings: pricings, pricingIds: pricingIds };
161
160
  }
162
161
  function mapSeverityResultRepairOperation(severityResult) {
163
162
  var partSeverity = severityResult;
@@ -275,7 +274,7 @@ function mapInspection(response, ids) {
275
274
  vehicle: ids.vehicleId,
276
275
  wheelAnalysis: mapWheelAnalysis(response),
277
276
  severityResults: ids.severityResultIds,
278
- pricing: mapPricingV2(response),
277
+ pricings: ids.pricingIds,
279
278
  additionalData: response.additional_data,
280
279
  };
281
280
  }
@@ -285,6 +284,7 @@ function mapApiInspectionGet(response, thumbnailDomain, complianceOptions) {
285
284
  var _c = mapParts(response), parts = _c.parts, partIds = _c.partIds;
286
285
  var _d = mapSeverityResults(response), severityResults = _d.severityResults, severityResultIds = _d.severityResultIds;
287
286
  var _e = mapTasks(response), tasks = _e.tasks, taskIds = _e.taskIds;
287
+ var _f = mapPricingV2(response), pricings = _f.pricings, pricingIds = _f.pricingIds;
288
288
  var vehicle = mapVehicle(response);
289
289
  var inspection = mapInspection(response, {
290
290
  imageIds: imageIds,
@@ -294,6 +294,7 @@ function mapApiInspectionGet(response, thumbnailDomain, complianceOptions) {
294
294
  partIds: partIds,
295
295
  severityResultIds: severityResultIds,
296
296
  taskIds: taskIds,
297
+ pricingIds: pricingIds,
297
298
  });
298
299
  return {
299
300
  damages: damages,
@@ -305,6 +306,7 @@ function mapApiInspectionGet(response, thumbnailDomain, complianceOptions) {
305
306
  tasks: tasks,
306
307
  vehicles: vehicle ? [vehicle] : [],
307
308
  views: views,
309
+ pricings: pricings,
308
310
  partOperations: [],
309
311
  };
310
312
  }
@@ -1,5 +1,5 @@
1
- import { MonkAction, MonkGotOneInspectionAction, MonkState } from '@monkvision/common';
2
- import { ComplianceOptions, CreateInspectionOptions } from '@monkvision/types';
1
+ import { MonkAction, MonkGotOneInspectionAction, MonkState, MonkUpdatedOneInspectionAdditionalDataAction } from '@monkvision/common';
2
+ import { AdditionalData, ComplianceOptions, CreateInspectionOptions } from '@monkvision/types';
3
3
  import { Dispatch } from 'react';
4
4
  import { MonkApiConfig } from '../config';
5
5
  import { ApiInspectionGet } from '../models';
@@ -45,3 +45,27 @@ export declare function getInspection(options: GetInspectionOptions, config: Mon
45
45
  * @see CreateInspectionOptions
46
46
  */
47
47
  export declare function createInspection(options: CreateInspectionOptions, config: MonkApiConfig, _dispatch?: Dispatch<MonkAction>): Promise<MonkApiResponse>;
48
+ /**
49
+ * Options passed to the `updateAdditionalData` API request.
50
+ */
51
+ export interface UpdateAdditionalDataOptions {
52
+ /**
53
+ * The ID of the inspection to update via the API.
54
+ */
55
+ id: string;
56
+ /**
57
+ * Callback function that takes optional additional data and returns the updated additional data.
58
+ */
59
+ callback: (additionalData?: AdditionalData) => AdditionalData;
60
+ }
61
+ /**
62
+ * Update the additional data of inspection with the given options.
63
+ * See the `UpdateAdditionalDataOptions` interface for more details.
64
+ *
65
+ * @param options The options of the request.
66
+ * @param config The API config.
67
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
68
+ * state management for you.
69
+ * @see UpdateAdditionalDataOptions
70
+ */
71
+ export declare function updateAdditionalData(options: UpdateAdditionalDataOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkUpdatedOneInspectionAdditionalDataAction>): 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.createInspection = exports.getInspection = void 0;
53
+ 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");
@@ -119,3 +119,50 @@ function createInspection(options, config, _dispatch) {
119
119
  });
120
120
  }
121
121
  exports.createInspection = createInspection;
122
+ /**
123
+ * Update the additional data of inspection with the given options.
124
+ * See the `UpdateAdditionalDataOptions` interface for more details.
125
+ *
126
+ * @param options The options of the request.
127
+ * @param config The API config.
128
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
129
+ * state management for you.
130
+ * @see UpdateAdditionalDataOptions
131
+ */
132
+ function updateAdditionalData(options, config, dispatch) {
133
+ return __awaiter(this, void 0, void 0, function () {
134
+ var entities, inspection, newAdditionalData, kyOptions, response, body;
135
+ return __generator(this, function (_a) {
136
+ switch (_a.label) {
137
+ case 0: return [4 /*yield*/, getInspection({ id: options.id }, config)];
138
+ case 1:
139
+ entities = (_a.sent()).entities;
140
+ inspection = entities.inspections.find(function (i) { return i.id === options.id; });
141
+ if (!inspection) {
142
+ throw new Error('Inspection does not exist');
143
+ }
144
+ newAdditionalData = options.callback(inspection.additionalData);
145
+ kyOptions = (0, config_1.getDefaultOptions)(config);
146
+ return [4 /*yield*/, ky_1.default.patch("inspections/".concat(options.id), __assign(__assign({}, kyOptions), { json: { additional_data: newAdditionalData } }))];
147
+ case 2:
148
+ response = _a.sent();
149
+ return [4 /*yield*/, response.json()];
150
+ case 3:
151
+ body = _a.sent();
152
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({
153
+ type: common_1.MonkActionType.UPDATED_ONE_INSPECTION_ADDITIONAL_DATA,
154
+ payload: {
155
+ inspectionId: options.id,
156
+ additionalData: newAdditionalData,
157
+ },
158
+ });
159
+ return [2 /*return*/, {
160
+ id: body.id,
161
+ response: response,
162
+ body: body,
163
+ }];
164
+ }
165
+ });
166
+ });
167
+ }
168
+ exports.updateAdditionalData = updateAdditionalData;
@@ -1,7 +1,9 @@
1
+ import { PricingV2RelatedItemType, VehiclePart } from '@monkvision/types';
1
2
  export type ApiRelatedItemType = 'part' | 'vehicle';
2
3
  export type ApiRepairOperationsTypes = 'polishing' | 'sanding' | 'painting' | 'replacing' | 'paintless_dent_repair' | 'dent_repair' | 'refinishing' | 'removing' | 'painting_hard' | 'paint_preparation';
3
4
  export type ApiHours = Record<string, number>;
4
5
  export interface ApiPricingV2Details {
6
+ id: string;
5
7
  hours?: ApiHours;
6
8
  operations?: ApiRepairOperationsTypes[];
7
9
  pricing?: number;
@@ -13,3 +15,8 @@ export interface ApiPricingV2 {
13
15
  details: ApiDetails;
14
16
  total_price?: number;
15
17
  }
18
+ export interface ApiPricingPost {
19
+ pricing: number;
20
+ related_item_type: PricingV2RelatedItemType;
21
+ part_type: VehiclePart | undefined;
22
+ }
@@ -0,0 +1,2 @@
1
+ export * from './requests';
2
+ export * from './types';
@@ -0,0 +1,18 @@
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);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,5 @@
1
+ import { PricingV2 } from '@monkvision/types';
2
+ import { ApiPricingPost, ApiPricingV2Details } from '../models';
3
+ import { PricingOptions } from './types';
4
+ export declare function mapApiPricingPost(inspectionId: string, response: ApiPricingV2Details): PricingV2;
5
+ export declare function mapApiPricingPostRequest(options: PricingOptions): ApiPricingPost;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapApiPricingPostRequest = exports.mapApiPricingPost = void 0;
4
+ var types_1 = require("@monkvision/types");
5
+ function mapApiPricingPost(inspectionId, response) {
6
+ return {
7
+ inspectionId: inspectionId,
8
+ id: response.id,
9
+ entityType: types_1.MonkEntityType.PRICING,
10
+ relatedItemType: response.related_item_type,
11
+ relatedItemId: response.related_item_id,
12
+ pricing: response.pricing,
13
+ operations: response.operations,
14
+ hours: response.hours,
15
+ };
16
+ }
17
+ exports.mapApiPricingPost = mapApiPricingPost;
18
+ function mapApiPricingPostRequest(options) {
19
+ return {
20
+ pricing: options.pricing >= 0 ? options.pricing : 0,
21
+ related_item_type: options.type,
22
+ part_type: options.type === types_1.PricingV2RelatedItemType.PART ? options.vehiclePart : types_1.VehiclePart.IGNORE,
23
+ };
24
+ }
25
+ exports.mapApiPricingPostRequest = mapApiPricingPostRequest;
@@ -0,0 +1,78 @@
1
+ import { Dispatch } from 'react';
2
+ import { MonkCreatedOnePricingAction, MonkDeletedOnePricingAction, MonkUpdatedOnePricingAction } from '@monkvision/common';
3
+ import { MonkApiConfig } from '../config';
4
+ import { MonkApiResponse } from '../types';
5
+ import { PricingOptions } from './types';
6
+ /**
7
+ * Options passed to the `createPricing` API request.
8
+ */
9
+ export interface CreatePricingOptions {
10
+ /**
11
+ * The ID of the inspection to update via the API.
12
+ */
13
+ id: string;
14
+ /**
15
+ * Pricing used for the update operation.
16
+ */
17
+ pricing: PricingOptions;
18
+ }
19
+ /**
20
+ * Create a new pricing with the given options. See the `CreatePricingOptions` interface for more details.
21
+ *
22
+ * @param options The options of the inspection.
23
+ * @param config The API config.
24
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
25
+ * state management for you.
26
+ * @see CreatePricingOptions
27
+ */
28
+ export declare function createPricing(options: CreatePricingOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkCreatedOnePricingAction>): Promise<MonkApiResponse>;
29
+ /**
30
+ * Options passed to the `deletePricing` API request.
31
+ */
32
+ export interface DeletePricingOptions {
33
+ /**
34
+ * The ID of the inspection to update via the API.
35
+ */
36
+ id: string;
37
+ /**
38
+ * Pricing ID that will be deleted.
39
+ */
40
+ pricingId: string;
41
+ }
42
+ /**
43
+ * Delete a pricing with the given options. See the `DeletePricingOptions` interface for more details.
44
+ *
45
+ * @param options The options of the inspection.
46
+ * @param config The API config.
47
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
48
+ * state management for you.
49
+ * @see DeletePricingOptions
50
+ */
51
+ export declare function deletePricing(options: DeletePricingOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkDeletedOnePricingAction>): Promise<MonkApiResponse>;
52
+ /**
53
+ * Options passed to the `updatePricing` API request.
54
+ */
55
+ export interface UpdatePricingOptions {
56
+ /**
57
+ * The ID of the inspection to update via the API.
58
+ */
59
+ id: string;
60
+ /**
61
+ * Pricing ID that will be update.
62
+ */
63
+ pricingId: string;
64
+ /**
65
+ * The new price value.
66
+ */
67
+ price: number;
68
+ }
69
+ /**
70
+ * Update a pricing with the given options. See the `UpdatePricingOptions` interface for more details.
71
+ *
72
+ * @param options The options of the inspection.
73
+ * @param config The API config.
74
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
75
+ * state management for you.
76
+ * @see UpdatePricingOptions
77
+ */
78
+ export declare function updatePricing(options: UpdatePricingOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkUpdatedOnePricingAction>): Promise<MonkApiResponse>;
@@ -0,0 +1,167 @@
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.updatePricing = exports.deletePricing = exports.createPricing = void 0;
54
+ var common_1 = require("@monkvision/common");
55
+ var ky_1 = __importDefault(require("ky"));
56
+ var config_1 = require("../config");
57
+ var mappers_1 = require("./mappers");
58
+ /**
59
+ * Create a new pricing with the given options. See the `CreatePricingOptions` interface for more details.
60
+ *
61
+ * @param options The options of the inspection.
62
+ * @param config The API config.
63
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
64
+ * state management for you.
65
+ * @see CreatePricingOptions
66
+ */
67
+ function createPricing(options, config, dispatch) {
68
+ return __awaiter(this, void 0, void 0, function () {
69
+ var kyOptions, response, body, pricing;
70
+ return __generator(this, function (_a) {
71
+ switch (_a.label) {
72
+ case 0:
73
+ kyOptions = (0, config_1.getDefaultOptions)(config);
74
+ return [4 /*yield*/, ky_1.default.post("inspections/".concat(options.id, "/pricing"), __assign(__assign({}, kyOptions), { json: (0, mappers_1.mapApiPricingPostRequest)(options.pricing) }))];
75
+ case 1:
76
+ response = _a.sent();
77
+ return [4 /*yield*/, response.json()];
78
+ case 2:
79
+ body = _a.sent();
80
+ pricing = (0, mappers_1.mapApiPricingPost)(options.id, body);
81
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({
82
+ type: common_1.MonkActionType.CREATED_ONE_PRICING,
83
+ payload: { pricing: pricing },
84
+ });
85
+ return [2 /*return*/, {
86
+ id: body.id,
87
+ response: response,
88
+ body: body,
89
+ }];
90
+ }
91
+ });
92
+ });
93
+ }
94
+ exports.createPricing = createPricing;
95
+ /**
96
+ * Delete a pricing with the given options. See the `DeletePricingOptions` interface for more details.
97
+ *
98
+ * @param options The options of the inspection.
99
+ * @param config The API config.
100
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
101
+ * state management for you.
102
+ * @see DeletePricingOptions
103
+ */
104
+ function deletePricing(options, config, dispatch) {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ var kyOptions, response, body;
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0:
110
+ kyOptions = (0, config_1.getDefaultOptions)(config);
111
+ return [4 /*yield*/, ky_1.default.delete("inspections/".concat(options.id, "/pricing/").concat(options.pricingId), __assign({}, kyOptions))];
112
+ case 1:
113
+ response = _a.sent();
114
+ return [4 /*yield*/, response.json()];
115
+ case 2:
116
+ body = _a.sent();
117
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({
118
+ type: common_1.MonkActionType.DELETED_ONE_PRICING,
119
+ payload: { inspectionId: options.id, pricingId: body.id },
120
+ });
121
+ return [2 /*return*/, {
122
+ id: body.id,
123
+ response: response,
124
+ body: body,
125
+ }];
126
+ }
127
+ });
128
+ });
129
+ }
130
+ exports.deletePricing = deletePricing;
131
+ /**
132
+ * Update a pricing with the given options. See the `UpdatePricingOptions` interface for more details.
133
+ *
134
+ * @param options The options of the inspection.
135
+ * @param config The API config.
136
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
137
+ * state management for you.
138
+ * @see UpdatePricingOptions
139
+ */
140
+ function updatePricing(options, config, dispatch) {
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ var kyOptions, response, body, pricing;
143
+ return __generator(this, function (_a) {
144
+ switch (_a.label) {
145
+ case 0:
146
+ kyOptions = (0, config_1.getDefaultOptions)(config);
147
+ return [4 /*yield*/, ky_1.default.patch("inspections/".concat(options.id, "/pricing/").concat(options.pricingId), __assign(__assign({}, kyOptions), { json: { pricing: options.price } }))];
148
+ case 1:
149
+ response = _a.sent();
150
+ return [4 /*yield*/, response.json()];
151
+ case 2:
152
+ body = _a.sent();
153
+ pricing = (0, mappers_1.mapApiPricingPost)(options.id, body);
154
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({
155
+ type: common_1.MonkActionType.UPDATED_ONE_PRICING,
156
+ payload: { pricing: pricing },
157
+ });
158
+ return [2 /*return*/, {
159
+ id: body.id,
160
+ response: response,
161
+ body: body,
162
+ }];
163
+ }
164
+ });
165
+ });
166
+ }
167
+ exports.updatePricing = updatePricing;
@@ -0,0 +1,35 @@
1
+ import { PricingV2RelatedItemType, VehiclePart } from '@monkvision/types';
2
+ /**
3
+ * Options for part-specific pricing.
4
+ */
5
+ export interface PricingPartOptions {
6
+ /**
7
+ * The type of pricing, in this case for a part.
8
+ */
9
+ type: PricingV2RelatedItemType.PART;
10
+ /**
11
+ * The pricing value for the part. Must be a non-negative float.
12
+ */
13
+ pricing: number;
14
+ /**
15
+ * The specific vehicle part this pricing applies to.
16
+ */
17
+ vehiclePart: VehiclePart;
18
+ }
19
+ /**
20
+ * Options for car-wide pricing.
21
+ */
22
+ export interface PricingVehicleOptions {
23
+ /**
24
+ * The type of pricing, in this case for the whole car.
25
+ */
26
+ type: PricingV2RelatedItemType.VEHICLE;
27
+ /**
28
+ * The pricing value for the entire car.
29
+ */
30
+ pricing: number;
31
+ }
32
+ /**
33
+ * Union type representing pricing options for either a car or a part.
34
+ */
35
+ export type PricingOptions = PricingVehicleOptions | PricingPartOptions;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -66,4 +66,31 @@ export declare function useMonkApi(config: MonkApiConfig): {
66
66
  response: import("ky").KyResponse;
67
67
  body: import("./models").ApiIdColumn;
68
68
  }>;
69
+ /**
70
+ * Update the additional data of an inspection.
71
+ *
72
+ * @param options The options of the request.
73
+ */
74
+ updateAdditionalData: (options: import("./inspection").UpdateAdditionalDataOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn>>;
75
+ /**
76
+ * Create a new pricing with the given options. See the `CreatePricingOptions` interface for more details.
77
+ *
78
+ * @param options The options of the inspection.
79
+ * @see CreatePricingOptions
80
+ */
81
+ createPricing: (options: import("./pricing").CreatePricingOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn>>;
82
+ /**
83
+ * Delete a pricing with the given options. See the `DeletePricingOptions` interface for more details.
84
+ *
85
+ * @param options The options of the inspection.
86
+ * @see DeletePricingOptions
87
+ */
88
+ deletePricing: (options: import("./pricing").DeletePricingOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn>>;
89
+ /**
90
+ * Update a pricing with the given options. See the `UpdatePricingOptions` interface for more details.
91
+ *
92
+ * @param options The options of the inspection.
93
+ * @see UpdatePricingOptions
94
+ */
95
+ updatePricing: (options: import("./pricing").UpdatePricingOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn>>;
69
96
  };
@@ -99,6 +99,33 @@ function useMonkApi(config) {
99
99
  * @param options The options of the request.
100
100
  */
101
101
  updateInspectionVehicle: reactify(api_1.MonkApi.updateInspectionVehicle, config, dispatch, handleError),
102
+ /**
103
+ * Update the additional data of an inspection.
104
+ *
105
+ * @param options The options of the request.
106
+ */
107
+ updateAdditionalData: reactify(api_1.MonkApi.updateAdditionalData, config, dispatch, handleError),
108
+ /**
109
+ * Create a new pricing with the given options. See the `CreatePricingOptions` interface for more details.
110
+ *
111
+ * @param options The options of the inspection.
112
+ * @see CreatePricingOptions
113
+ */
114
+ createPricing: reactify(api_1.MonkApi.createPricing, config, dispatch, handleError),
115
+ /**
116
+ * Delete a pricing with the given options. See the `DeletePricingOptions` interface for more details.
117
+ *
118
+ * @param options The options of the inspection.
119
+ * @see DeletePricingOptions
120
+ */
121
+ deletePricing: reactify(api_1.MonkApi.deletePricing, config, dispatch, handleError),
122
+ /**
123
+ * Update a pricing with the given options. See the `UpdatePricingOptions` interface for more details.
124
+ *
125
+ * @param options The options of the inspection.
126
+ * @see UpdatePricingOptions
127
+ */
128
+ updatePricing: reactify(api_1.MonkApi.updatePricing, config, dispatch, handleError),
102
129
  };
103
130
  }
104
131
  exports.useMonkApi = useMonkApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkvision/network",
3
- "version": "4.0.24",
3
+ "version": "4.1.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": "4.0.24",
32
- "@monkvision/sights": "4.0.24",
31
+ "@monkvision/common": "4.1.0",
32
+ "@monkvision/sights": "4.1.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": "4.0.24",
46
- "@monkvision/eslint-config-typescript": "4.0.24",
47
- "@monkvision/jest-config": "4.0.24",
48
- "@monkvision/prettier-config": "4.0.24",
49
- "@monkvision/types": "4.0.24",
50
- "@monkvision/typescript-config": "4.0.24",
45
+ "@monkvision/eslint-config-base": "4.1.0",
46
+ "@monkvision/eslint-config-typescript": "4.1.0",
47
+ "@monkvision/jest-config": "4.1.0",
48
+ "@monkvision/prettier-config": "4.1.0",
49
+ "@monkvision/types": "4.1.0",
50
+ "@monkvision/typescript-config": "4.1.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": "56cd03cfdc927dca6b56688da8c984a49784763b"
87
+ "gitHead": "609b0e8613f5ceaa946b8b626ba4fd3936d25067"
88
88
  }