@monkvision/network 4.2.2 → 4.2.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 CHANGED
@@ -165,7 +165,7 @@ import { MonkApi } from '@monkvision/network';
165
165
  MonkApi.deletePricing(options, apiConfig, dispatch);
166
166
  ```
167
167
 
168
- Update a pricing of an inspection.
168
+ Delete a pricing of an inspection.
169
169
 
170
170
  | Parameter | Type | Description | Required |
171
171
  |-----------|----------------------|-----------------------------|----------|
@@ -184,6 +184,31 @@ Update the additional data of an inspection.
184
184
  |-----------|-----------------------------|-----------------------------|----------|
185
185
  | options | UpdateAdditionalDataOptions | The options of the request. | ✔️ |
186
186
 
187
+ ### createDamage
188
+ ```typescript
189
+ import { MonkApi } from '@monkvision/network';
190
+
191
+ MonkApi.createDamage(options, apiConfig, dispatch);
192
+ ```
193
+
194
+ Create a new damage of an inspection.
195
+
196
+ | Parameter | Type | Description | Required |
197
+ |-----------|---------------------|-----------------------------|----------|
198
+ | options | CreateDamageOptions | The options of the request. | ✔️ |
199
+
200
+ ### deleteDamage
201
+ ```typescript
202
+ import { MonkApi } from '@monkvision/network';
203
+
204
+ MonkApi.deleteDamage(options, apiConfig, dispatch);
205
+ ```
206
+
207
+ Delete a damage of an inspection.
208
+
209
+ | Parameter | Type | Description | Required |
210
+ |-----------|---------------------|-----------------------------|----------|
211
+ | options | DeleteDamageOptions | The options of the request. | ✔️ |
187
212
 
188
213
  # React Tools
189
214
  In order to simply integrate the Monk Api requests into your React app, you can make use of the `useMonkApi` hook. This
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkvision/network",
3
- "version": "4.2.1",
3
+ "version": "4.2.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.2.1",
32
- "@monkvision/sights": "4.2.1",
31
+ "@monkvision/common": "4.2.3",
32
+ "@monkvision/sights": "4.2.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.2.1",
46
- "@monkvision/eslint-config-typescript": "4.2.1",
47
- "@monkvision/jest-config": "4.2.1",
48
- "@monkvision/prettier-config": "4.2.1",
49
- "@monkvision/types": "4.2.1",
50
- "@monkvision/typescript-config": "4.2.1",
45
+ "@monkvision/eslint-config-base": "4.2.3",
46
+ "@monkvision/eslint-config-typescript": "4.2.3",
47
+ "@monkvision/jest-config": "4.2.3",
48
+ "@monkvision/prettier-config": "4.2.3",
49
+ "@monkvision/types": "4.2.3",
50
+ "@monkvision/typescript-config": "4.2.3",
51
51
  "@types/jest": "^29.2.2",
52
52
  "@types/jsonwebtoken": "^9.0.5",
53
53
  "@types/node": "^18.11.9",
@@ -4,6 +4,7 @@ import { startInspectionTasks, updateTaskStatus } from './task';
4
4
  import { getLiveConfig } from './liveConfigs';
5
5
  import { updateInspectionVehicle } from './vehicle';
6
6
  import { createPricing, deletePricing, updatePricing } from './pricing';
7
+ import { createDamage, deleteDamage } from './damage';
7
8
  /**
8
9
  * Object regrouping the different API requests available to communicate with the API using the `@monkvision/network`
9
10
  * package.
@@ -20,4 +21,6 @@ export declare const MonkApi: {
20
21
  createPricing: typeof createPricing;
21
22
  deletePricing: typeof deletePricing;
22
23
  updatePricing: typeof updatePricing;
24
+ createDamage: typeof createDamage;
25
+ deleteDamage: typeof deleteDamage;
23
26
  };
@@ -7,6 +7,7 @@ var task_1 = require("./task");
7
7
  var liveConfigs_1 = require("./liveConfigs");
8
8
  var vehicle_1 = require("./vehicle");
9
9
  var pricing_1 = require("./pricing");
10
+ var damage_1 = require("./damage");
10
11
  /**
11
12
  * Object regrouping the different API requests available to communicate with the API using the `@monkvision/network`
12
13
  * package.
@@ -23,4 +24,6 @@ exports.MonkApi = {
23
24
  createPricing: pricing_1.createPricing,
24
25
  deletePricing: pricing_1.deletePricing,
25
26
  updatePricing: pricing_1.updatePricing,
27
+ createDamage: damage_1.createDamage,
28
+ deleteDamage: damage_1.deleteDamage,
26
29
  };
@@ -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,3 @@
1
+ import { DamageType, VehiclePart } from '@monkvision/types';
2
+ import { ApiDamagePost } from '../models';
3
+ export declare function mapApiDamagePostRequest(damageType: DamageType, vehiclePart: VehiclePart): ApiDamagePost;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapApiDamagePostRequest = void 0;
4
+ function mapApiDamagePostRequest(damageType, vehiclePart) {
5
+ return {
6
+ damage_type: damageType,
7
+ part_type: vehiclePart,
8
+ };
9
+ }
10
+ exports.mapApiDamagePostRequest = mapApiDamagePostRequest;
@@ -0,0 +1,55 @@
1
+ import { MonkCreatedOneDamageAction, MonkDeletedOneDamageAction } from '@monkvision/common';
2
+ import { DamageType, VehiclePart } from '@monkvision/types';
3
+ import { Dispatch } from 'react';
4
+ import { MonkApiConfig } from '../config';
5
+ import { MonkApiResponse } from '../types';
6
+ /**
7
+ * Options passed to the `createDamage` API request.
8
+ */
9
+ export interface CreateDamageOptions {
10
+ /**
11
+ * The ID of the inspection to update via the API.
12
+ */
13
+ id: string;
14
+ /**
15
+ * Damage type used for the update operation.
16
+ */
17
+ damageType: DamageType;
18
+ /**
19
+ * Vehicle part used for the update operation.
20
+ */
21
+ vehiclePart: VehiclePart;
22
+ }
23
+ /**
24
+ * Create a new damage with the given options. See the `CreateDamageOptions` interface for more details.
25
+ *
26
+ * @param options The options of the inspection.
27
+ * @param config The API config.
28
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
29
+ * state management for you.
30
+ * @see CreateDamageOptions
31
+ */
32
+ export declare function createDamage(options: CreateDamageOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkCreatedOneDamageAction>): Promise<MonkApiResponse>;
33
+ /**
34
+ * Options passed to the `deleteDamage` API request.
35
+ */
36
+ export interface DeleteDamageOptions {
37
+ /**
38
+ * The ID of the inspection to update via the API.
39
+ */
40
+ id: string;
41
+ /**
42
+ * Damage ID that will be deleted.
43
+ */
44
+ damageId: string;
45
+ }
46
+ /**
47
+ * Delete a damage with the given options. See the `DeleteDamageOptions` interface for more details.
48
+ *
49
+ * @param options The options of the inspection.
50
+ * @param config The API config.
51
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
52
+ * state management for you.
53
+ * @see DeleteDamageOptions
54
+ */
55
+ export declare function deleteDamage(options: DeleteDamageOptions, config: MonkApiConfig, dispatch?: Dispatch<MonkDeletedOneDamageAction>): Promise<MonkApiResponse>;
@@ -0,0 +1,139 @@
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.deleteDamage = exports.createDamage = void 0;
54
+ var common_1 = require("@monkvision/common");
55
+ var types_1 = require("@monkvision/types");
56
+ var ky_1 = __importDefault(require("ky"));
57
+ var config_1 = require("../config");
58
+ var mappers_1 = require("./mappers");
59
+ /**
60
+ * Create a new damage with the given options. See the `CreateDamageOptions` interface for more details.
61
+ *
62
+ * @param options The options of the inspection.
63
+ * @param config The API config.
64
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
65
+ * state management for you.
66
+ * @see CreateDamageOptions
67
+ */
68
+ function createDamage(options, config, dispatch) {
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var kyOptions, response, body;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0:
74
+ kyOptions = (0, config_1.getDefaultOptions)(config);
75
+ return [4 /*yield*/, ky_1.default.post("inspections/".concat(options.id, "/damages"), __assign(__assign({}, kyOptions), { json: (0, mappers_1.mapApiDamagePostRequest)(options.damageType, options.vehiclePart) }))];
76
+ case 1:
77
+ response = _a.sent();
78
+ return [4 /*yield*/, response.json()];
79
+ case 2:
80
+ body = _a.sent();
81
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({
82
+ type: common_1.MonkActionType.CREATED_ONE_DAMAGE,
83
+ payload: {
84
+ damage: {
85
+ entityType: types_1.MonkEntityType.DAMAGE,
86
+ id: body.id,
87
+ inspectionId: options.id,
88
+ parts: [options.vehiclePart],
89
+ relatedImages: [],
90
+ type: options.damageType,
91
+ },
92
+ },
93
+ });
94
+ return [2 /*return*/, {
95
+ id: body.id,
96
+ response: response,
97
+ body: body,
98
+ }];
99
+ }
100
+ });
101
+ });
102
+ }
103
+ exports.createDamage = createDamage;
104
+ /**
105
+ * Delete a damage with the given options. See the `DeleteDamageOptions` interface for more details.
106
+ *
107
+ * @param options The options of the inspection.
108
+ * @param config The API config.
109
+ * @param [dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
110
+ * state management for you.
111
+ * @see DeleteDamageOptions
112
+ */
113
+ function deleteDamage(options, config, dispatch) {
114
+ return __awaiter(this, void 0, void 0, function () {
115
+ var kyOptions, response, body;
116
+ return __generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ case 0:
119
+ kyOptions = (0, config_1.getDefaultOptions)(config);
120
+ return [4 /*yield*/, ky_1.default.delete("inspections/".concat(options.id, "/damages/").concat(options.damageId), __assign({}, kyOptions))];
121
+ case 1:
122
+ response = _a.sent();
123
+ return [4 /*yield*/, response.json()];
124
+ case 2:
125
+ body = _a.sent();
126
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({
127
+ type: common_1.MonkActionType.DELETED_ONE_DAMAGE,
128
+ payload: { inspectionId: options.id, damageId: body.id },
129
+ });
130
+ return [2 /*return*/, {
131
+ id: body.id,
132
+ response: response,
133
+ body: body,
134
+ }];
135
+ }
136
+ });
137
+ });
138
+ }
139
+ exports.deleteDamage = deleteDamage;
@@ -1,3 +1,4 @@
1
+ import { DamageType, VehiclePart } from '@monkvision/types';
1
2
  import type { ApiRelatedImages } from './image';
2
3
  import type { ApiPartIds } from './part';
3
4
  export interface ApiDamage {
@@ -9,3 +10,7 @@ export interface ApiDamage {
9
10
  }
10
11
  export type ApiDamages = ApiDamage[];
11
12
  export type ApiDamageIds = string[];
13
+ export interface ApiDamagePost {
14
+ damage_type: DamageType;
15
+ part_type: VehiclePart;
16
+ }
@@ -15,7 +15,7 @@ export interface ApiPricingV2 {
15
15
  details: ApiDetails;
16
16
  total_price?: number;
17
17
  }
18
- export interface ApiPricingPost {
18
+ export interface ApiPricingPostPatch {
19
19
  pricing: number;
20
20
  related_item_type: PricingV2RelatedItemType;
21
21
  part_type: VehiclePart | undefined;
@@ -1,5 +1,5 @@
1
1
  import { PricingV2 } from '@monkvision/types';
2
- import { ApiPricingPost, ApiPricingV2Details } from '../models';
2
+ import { ApiPricingPostPatch, ApiPricingV2Details } from '../models';
3
3
  import { PricingOptions } from './types';
4
4
  export declare function mapApiPricingPost(inspectionId: string, response: ApiPricingV2Details): PricingV2;
5
- export declare function mapApiPricingPostRequest(options: PricingOptions): ApiPricingPost;
5
+ export declare function mapApiPricingPostRequest(options: PricingOptions): ApiPricingPostPatch;
@@ -93,4 +93,18 @@ export declare function useMonkApi(config: MonkApiConfig): {
93
93
  * @see UpdatePricingOptions
94
94
  */
95
95
  updatePricing: (options: import("./pricing").UpdatePricingOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn>>;
96
+ /**
97
+ * Create a new damage with the given options. See the `CreateDamageOptions` interface for more details.
98
+ *
99
+ * @param options The options of the inspection.
100
+ * @see CreateDamageOptions
101
+ */
102
+ createDamage: (options: import("./damage").CreateDamageOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn>>;
103
+ /**
104
+ * Delete a damage with the given options. See the `DeleteDamageOptions` interface for more details.
105
+ *
106
+ * @param options The options of the inspection.
107
+ * @see DeleteDamageOptions
108
+ */
109
+ deleteDamage: (options: import("./damage").DeleteDamageOptions) => Promise<import("./types").MonkApiResponse<import("./types").MonkId, import("./models").ApiIdColumn>>;
96
110
  };
@@ -126,6 +126,20 @@ function useMonkApi(config) {
126
126
  * @see UpdatePricingOptions
127
127
  */
128
128
  updatePricing: reactify(api_1.MonkApi.updatePricing, config, dispatch, handleError),
129
+ /**
130
+ * Create a new damage with the given options. See the `CreateDamageOptions` interface for more details.
131
+ *
132
+ * @param options The options of the inspection.
133
+ * @see CreateDamageOptions
134
+ */
135
+ createDamage: reactify(api_1.MonkApi.createDamage, config, dispatch, handleError),
136
+ /**
137
+ * Delete a damage with the given options. See the `DeleteDamageOptions` interface for more details.
138
+ *
139
+ * @param options The options of the inspection.
140
+ * @see DeleteDamageOptions
141
+ */
142
+ deleteDamage: reactify(api_1.MonkApi.deleteDamage, config, dispatch, handleError),
129
143
  };
130
144
  }
131
145
  exports.useMonkApi = useMonkApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkvision/network",
3
- "version": "4.2.2",
3
+ "version": "4.2.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.2.2",
32
- "@monkvision/sights": "4.2.2",
31
+ "@monkvision/common": "4.2.4",
32
+ "@monkvision/sights": "4.2.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.2.2",
46
- "@monkvision/eslint-config-typescript": "4.2.2",
47
- "@monkvision/jest-config": "4.2.2",
48
- "@monkvision/prettier-config": "4.2.2",
49
- "@monkvision/types": "4.2.2",
50
- "@monkvision/typescript-config": "4.2.2",
45
+ "@monkvision/eslint-config-base": "4.2.4",
46
+ "@monkvision/eslint-config-typescript": "4.2.4",
47
+ "@monkvision/jest-config": "4.2.4",
48
+ "@monkvision/prettier-config": "4.2.4",
49
+ "@monkvision/types": "4.2.4",
50
+ "@monkvision/typescript-config": "4.2.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": "6b099cf04f90c80e519fd0cc22ebe0cff740e4cb"
87
+ "gitHead": "f746a694b9c441a4b1d5f6868f503b3d1099fd81"
88
88
  }