@monkvision/network 4.0.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.
Files changed (124) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +225 -0
  3. package/lib/package.json +84 -0
  4. package/lib/src/api/api.d.ts +18 -0
  5. package/lib/src/api/api.js +22 -0
  6. package/lib/src/api/api.js.map +1 -0
  7. package/lib/src/api/config.d.ts +20 -0
  8. package/lib/src/api/config.js +41 -0
  9. package/lib/src/api/config.js.map +1 -0
  10. package/lib/src/api/error.d.ts +34 -0
  11. package/lib/src/api/error.js +118 -0
  12. package/lib/src/api/error.js.map +1 -0
  13. package/lib/src/api/hooks/index.d.ts +1 -0
  14. package/lib/src/api/hooks/index.js +18 -0
  15. package/lib/src/api/hooks/index.js.map +1 -0
  16. package/lib/src/api/hooks/useInspectionPoll.d.ts +34 -0
  17. package/lib/src/api/hooks/useInspectionPoll.js +21 -0
  18. package/lib/src/api/hooks/useInspectionPoll.js.map +1 -0
  19. package/lib/src/api/image/index.d.ts +1 -0
  20. package/lib/src/api/image/index.js +18 -0
  21. package/lib/src/api/image/index.js.map +1 -0
  22. package/lib/src/api/image/mappers.d.ts +3 -0
  23. package/lib/src/api/image/mappers.js +166 -0
  24. package/lib/src/api/image/mappers.js.map +1 -0
  25. package/lib/src/api/image/requests.d.ts +141 -0
  26. package/lib/src/api/image/requests.js +312 -0
  27. package/lib/src/api/image/requests.js.map +1 -0
  28. package/lib/src/api/index.d.ts +10 -0
  29. package/lib/src/api/index.js +27 -0
  30. package/lib/src/api/index.js.map +1 -0
  31. package/lib/src/api/inspection/index.d.ts +1 -0
  32. package/lib/src/api/inspection/index.js +18 -0
  33. package/lib/src/api/inspection/index.js.map +1 -0
  34. package/lib/src/api/inspection/mappers.d.ts +5 -0
  35. package/lib/src/api/inspection/mappers.js +392 -0
  36. package/lib/src/api/inspection/mappers.js.map +1 -0
  37. package/lib/src/api/inspection/requests.d.ts +47 -0
  38. package/lib/src/api/inspection/requests.js +122 -0
  39. package/lib/src/api/inspection/requests.js.map +1 -0
  40. package/lib/src/api/liveConfigs/index.d.ts +1 -0
  41. package/lib/src/api/liveConfigs/index.js +18 -0
  42. package/lib/src/api/liveConfigs/index.js.map +1 -0
  43. package/lib/src/api/liveConfigs/requests.d.ts +7 -0
  44. package/lib/src/api/liveConfigs/requests.js +66 -0
  45. package/lib/src/api/liveConfigs/requests.js.map +1 -0
  46. package/lib/src/api/models/common.d.ts +13 -0
  47. package/lib/src/api/models/common.js +3 -0
  48. package/lib/src/api/models/common.js.map +1 -0
  49. package/lib/src/api/models/compliance.d.ts +58 -0
  50. package/lib/src/api/models/compliance.js +3 -0
  51. package/lib/src/api/models/compliance.js.map +1 -0
  52. package/lib/src/api/models/damage.d.ts +11 -0
  53. package/lib/src/api/models/damage.js +3 -0
  54. package/lib/src/api/models/damage.js.map +1 -0
  55. package/lib/src/api/models/image.d.ts +76 -0
  56. package/lib/src/api/models/image.js +3 -0
  57. package/lib/src/api/models/image.js.map +1 -0
  58. package/lib/src/api/models/index.d.ts +13 -0
  59. package/lib/src/api/models/index.js +30 -0
  60. package/lib/src/api/models/index.js.map +1 -0
  61. package/lib/src/api/models/inspection.d.ts +40 -0
  62. package/lib/src/api/models/inspection.js +3 -0
  63. package/lib/src/api/models/inspection.js.map +1 -0
  64. package/lib/src/api/models/part.d.ts +10 -0
  65. package/lib/src/api/models/part.js +3 -0
  66. package/lib/src/api/models/part.js.map +1 -0
  67. package/lib/src/api/models/pricingV2.d.ts +15 -0
  68. package/lib/src/api/models/pricingV2.js +3 -0
  69. package/lib/src/api/models/pricingV2.js.map +1 -0
  70. package/lib/src/api/models/renderedOutput.d.ts +8 -0
  71. package/lib/src/api/models/renderedOutput.js +3 -0
  72. package/lib/src/api/models/renderedOutput.js.map +1 -0
  73. package/lib/src/api/models/severityResult.d.ts +37 -0
  74. package/lib/src/api/models/severityResult.js +3 -0
  75. package/lib/src/api/models/severityResult.js.map +1 -0
  76. package/lib/src/api/models/task.d.ts +76 -0
  77. package/lib/src/api/models/task.js +3 -0
  78. package/lib/src/api/models/task.js.map +1 -0
  79. package/lib/src/api/models/vehicle.d.ts +58 -0
  80. package/lib/src/api/models/vehicle.js +3 -0
  81. package/lib/src/api/models/vehicle.js.map +1 -0
  82. package/lib/src/api/models/view.d.ts +24 -0
  83. package/lib/src/api/models/view.js +3 -0
  84. package/lib/src/api/models/view.js.map +1 -0
  85. package/lib/src/api/models/wheelAnalysis.d.ts +13 -0
  86. package/lib/src/api/models/wheelAnalysis.js +3 -0
  87. package/lib/src/api/models/wheelAnalysis.js.map +1 -0
  88. package/lib/src/api/react.d.ts +69 -0
  89. package/lib/src/api/react.js +105 -0
  90. package/lib/src/api/react.js.map +1 -0
  91. package/lib/src/api/task/index.d.ts +1 -0
  92. package/lib/src/api/task/index.js +18 -0
  93. package/lib/src/api/task/index.js.map +1 -0
  94. package/lib/src/api/task/requests.d.ts +67 -0
  95. package/lib/src/api/task/requests.js +135 -0
  96. package/lib/src/api/task/requests.js.map +1 -0
  97. package/lib/src/api/types.d.ts +24 -0
  98. package/lib/src/api/types.js +3 -0
  99. package/lib/src/api/types.js.map +1 -0
  100. package/lib/src/api/utils.d.ts +9 -0
  101. package/lib/src/api/utils.js +22 -0
  102. package/lib/src/api/utils.js.map +1 -0
  103. package/lib/src/api/vehicle/index.d.ts +1 -0
  104. package/lib/src/api/vehicle/index.js +18 -0
  105. package/lib/src/api/vehicle/index.js.map +1 -0
  106. package/lib/src/api/vehicle/mappers.d.ts +3 -0
  107. package/lib/src/api/vehicle/mappers.js +33 -0
  108. package/lib/src/api/vehicle/mappers.js.map +1 -0
  109. package/lib/src/api/vehicle/requests.d.ts +31 -0
  110. package/lib/src/api/vehicle/requests.js +88 -0
  111. package/lib/src/api/vehicle/requests.js.map +1 -0
  112. package/lib/src/auth/hooks.d.ts +34 -0
  113. package/lib/src/auth/hooks.js +112 -0
  114. package/lib/src/auth/hooks.js.map +1 -0
  115. package/lib/src/auth/index.d.ts +2 -0
  116. package/lib/src/auth/index.js +19 -0
  117. package/lib/src/auth/index.js.map +1 -0
  118. package/lib/src/auth/token.d.ts +25 -0
  119. package/lib/src/auth/token.js +36 -0
  120. package/lib/src/auth/token.js.map +1 -0
  121. package/lib/src/index.d.ts +2 -0
  122. package/lib/src/index.js +19 -0
  123. package/lib/src/index.js.map +1 -0
  124. package/package.json +85 -0
package/LICENSE ADDED
@@ -0,0 +1,32 @@
1
+ The Clear BSD License
2
+
3
+ Copyright (c) [2022] [Monk](http://monk.ai)
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted (subject to the limitations in the disclaimer
8
+ below) provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice,
11
+ this list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright
14
+ notice, this list of conditions and the following disclaimer in the
15
+ documentation and/or other materials provided with the distribution.
16
+
17
+ * Neither the name of the copyright holder nor the names of its
18
+ contributors may be used to endorse or promote products derived from this
19
+ software without specific prior written permission.
20
+
21
+ NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
22
+ THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23
+ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,225 @@
1
+ # @monkvision/network
2
+ This package provides tools used by the MonkJs SDK to interact with the Network (authentication, API calls...).
3
+
4
+ # Installing
5
+ To install the package, you can run the following command :
6
+
7
+ ```shell
8
+ yarn add @monkvision/network
9
+ ```
10
+
11
+ If you are using TypeScript, this package comes with its type definitions integrated, so you don't need to install
12
+ anything else!
13
+
14
+ # API Requests
15
+ This package exports an object called `MonkApi` that regroups the different API requests available. The request
16
+ available in this pacakge all follow the same format :
17
+
18
+ - They can accept a certain amount of parameters
19
+ - The last parameters of the function will always be :
20
+ - The `apiConfig` object, that describes how to communicate with the
21
+ API (API domain and authentication token).
22
+ - An optional MonkState `dispatch` function that, if provided to the request function, will allow it to automatically
23
+ update the local React state. If not provided, the function will act as a simple TypeScript function with no React
24
+ functionality. To help you integrate Monk API requests more easily into your React apps, take a look at the
25
+ `useMonkApi` hook below.
26
+ - Their return type always contains at least the following properties:
27
+ - `body` : The API response body.
28
+ - `response` : The raw HTTP response object.
29
+
30
+ ### getInspection
31
+ ```typescript
32
+ import { MonkApi } from '@monkvision/network';
33
+
34
+ MonkApi.getInspection(options, apiConfig, dispatch);
35
+ ```
36
+
37
+ Fetch the details of an inspection using its ID. The resulting action of this request will contain the list of
38
+ every entity that has been fetched using this API call.
39
+
40
+ | Parameter | Type | Description | Required |
41
+ |-----------|----------------------|-----------------------------|----------|
42
+ | options | GetInspectionOptions | The options of the request. | ✔️ |
43
+
44
+ ### addImage
45
+ ```typescript
46
+ import { MonkApi } from '@monkvision/network';
47
+
48
+ MonkApi.addImage(options, apiConfig, dispatch);
49
+ ```
50
+
51
+ Add a new image to an inspection. The resulting action of this request will contain the details of the image that has
52
+ been created in the API.
53
+
54
+ | Parameter | Type | Description | Required |
55
+ |-----------|-----------------|----------------------------------------------------------|----------|
56
+ | options | AddImageOptions | The options used to specify how to upload the image. | ✔️ |
57
+
58
+ ### updateTaskStatus
59
+ ```typescript
60
+ import { MonkApi } from '@monkvision/network';
61
+ import { ProgressStatus, TaskName } from '@monkvision/types';
62
+
63
+ MonkApi.updateTaskStatus(options, apiConfig, dispatch);
64
+ ```
65
+
66
+ Update the progress status of an inspection task.
67
+
68
+ **Note : This API call is known to sometimes fail for unknown reasons. In order to fix this, we added a retry config
69
+ to this API request : when failing, this request will retry itself up to 4 times (5 API calls in total), with
70
+ exponentially increasing delay between each request (max delay : 1.5s).**
71
+
72
+ | Parameter | Type | Description | Required |
73
+ |-----------|-------------------------|----------------------------------------------------------|----------|
74
+ | options | UpdateTaskStatusOptions | The options of the request. | ✔️ |
75
+
76
+ ### startInspectionTasks
77
+ ```typescript
78
+ import { MonkApi } from '@monkvision/network';
79
+ import { TaskName } from '@monkvision/types';
80
+
81
+ MonkApi.startInspectionTasks(options, apiConfig, dispatch);
82
+ ```
83
+
84
+ Start some inspection tasks that were in the NOT_STARTED status. This function actually makes one API call for each
85
+ task provided using the `updateTaskStatus`.
86
+
87
+ **Note : This API call is known to sometimes fail for unknown reasons. Please take note of the details provided in
88
+ this documentation for the `updateTaskStatus` function.**
89
+
90
+ | Parameter | Type | Description | Required |
91
+ |-----------|-----------------------------|----------------------------------------------------------|----------|
92
+ | options | StartInspectionTasksOptions | The options of the request. | ✔️ |
93
+
94
+ ### getLiveConfig
95
+ ```typescript
96
+ import { MonkApi } from '@monkvision/network';https://acvauctions.fls.jetbrains.com
97
+
98
+ MonkApi.getLiveConfig(id);
99
+ ```
100
+
101
+ Fetch a webapp live configuration from the API.
102
+
103
+ | Parameter | Type | Description | Required |
104
+ |-----------|--------|-----------------------------------|----------|
105
+ | id | string | The ID of the live config to get. | ✔️ |
106
+
107
+ ### updateInspectionVehicle
108
+ ```typescript
109
+ import { MonkApi } from '@monkvision/network';
110
+
111
+ MonkApi.updateInspectionVehicule(options, apiConfig, dispatch);
112
+ ```
113
+
114
+ Update the vehicle of an inspection.
115
+
116
+ | Parameter | Type | Description | Required |
117
+ |-----------|--------------------------------|-----------------------------|----------|
118
+ | options | UpdateInspectionVehicleOptions | The options of the request. | ✔️ |
119
+
120
+ # React Tools
121
+ In order to simply integrate the Monk Api requests into your React app, you can make use of the `useMonkApi` hook. This
122
+ custom hook returns a custom version of the `MonkApi` object described in the section above, in which the requests do
123
+ not need to be passed the `apiConfig` parameter (since it is already provided to the `useMonkApi` hook) and the
124
+ MonkState `dispatch` function.
125
+
126
+ ```tsx
127
+ import { useEffect } from 'react';
128
+ import { MonkApi, useMonkApi } from '@monkvision/network';
129
+ import { TaskName } from '@monkvision/types';
130
+
131
+ function App() {
132
+ const { getInspection } = useMonkApi(apiConfig);
133
+
134
+ useEffect(() => {
135
+ // This call automatically syncs the local state with the distant state, which means that entities located in the
136
+ // MonkState (accessed using the `useMonkState` hook) are automatically updated after the response from the server.
137
+ getInspection(inspectionId);
138
+ }, []);
139
+ }
140
+ ```
141
+
142
+ ## Hooks
143
+ This package also exports useful Network hooks that you can use in your React apps.
144
+
145
+ ### useInspectionPoll
146
+ ```tsx
147
+ import { useInspectionPoll } from '@monkvision/network';
148
+
149
+ function TestComponent() {
150
+ useInspectionPoll({
151
+ id: myInspectionId,
152
+ delay: 2000,
153
+ apiConfig,
154
+ onSuccess: (entities) => console.log(entities.inspections.find((inspection) => inspection.id === myInspectionId)),
155
+ compliance,
156
+ });
157
+ }
158
+ ```
159
+ Custom hook used to fetch an inspection every `delay` milliseconds using the `getInspection` API request. To stop the
160
+ hook from making requests, simply pass a `null` vlaue for the `delay` param.
161
+
162
+ # Authentication
163
+ This package also exports tools for dealing with authentication within the Monk SDK :
164
+
165
+ ## useAuth hook
166
+ This package exports a custom hook called `useAuth` used to easily handle authentication in Monk applications. It stores
167
+ the current user's authentication token, and returns callbacks used to log in and out of the application using Auth0
168
+ pop-ups. It accepts a config option called `storeToken` that indicates if the token should be fetched and stored from
169
+ the browser local storage (default : `true`).
170
+
171
+ - For this hook to work properly, you must use it in a component that is a child of an `Auth0Provider` component.
172
+ - This hook automatically stores the token fetched in the `useMonkAppState` hook so that it can be accessed
173
+ anywhere in your app if you're using the `MonkAppStateProvider`.
174
+
175
+ ```tsx
176
+ function MyAuthComponent() {
177
+ const { login } = useAuth();
178
+ const navigate = useNavigate();
179
+
180
+ const handleLogIn = () => {
181
+ login().then(() => {
182
+ navigate('/home');
183
+ });
184
+ };
185
+
186
+ return <button onClick={handleLogIn}>Log In</button>;
187
+ }
188
+ ```
189
+
190
+ ## JWT Utils
191
+ ### Token decoding
192
+ You can decode Monk JWT token issued by Auth0 using the `decodeMonkJwt` util function provided by this package :
193
+
194
+ ```typescript
195
+ import { decodeMonkJwt, MonkJwtPayload } from '@monkvision/network';
196
+
197
+ const decodedToken: MonkJwtPayload = decodeMonkJwt(token);
198
+ ```
199
+
200
+ The available properties in the Monk JWT token payload are described in the `MonkJwtPayload` typescript interface.
201
+
202
+ ### isUserAuthorized
203
+ This utility function checks if the given user has all the required authroizations. You can either pass an auth token
204
+ to be decoded or the JWT payload directly.
205
+
206
+ ```typescript
207
+ import { MonkApiPermission } from '@monkvision/types';
208
+ import { isUserAuthorized } from '@monkvision/network';
209
+
210
+ const requiredPermissions = [MonkApiPermission.INSPECTION_CREATE, MonkApiPermission.INSPECTION_READ];
211
+ console.log(isUserAuthorized(value, requiredPermissions));
212
+ // value can either be an auth token as a string or a decoded JWT payload
213
+ ```
214
+
215
+
216
+ ### isTokenExpired
217
+ This utility function checks if an authorization token is expired or not. You can either pass an auth token to be
218
+ decoded or the JWT payload directly.
219
+
220
+ ```typescript
221
+ import { isTokenExpired } from '@monkvision/network';
222
+
223
+ console.log(isTokenExpired(value));
224
+ // value can either be an auth token as a string or a decoded JWT payload
225
+ ```
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@monkvision/network",
3
+ "version": "4.0.0",
4
+ "license": "BSD-3-Clause-Clear",
5
+ "packageManager": "yarn@3.2.4",
6
+ "description": "MonkJs core package used to communicate with the API",
7
+ "author": "monkvision",
8
+ "main": "lib/src/index.js",
9
+ "types": "lib/src/index.d.ts",
10
+ "files": [
11
+ "package.json",
12
+ "README.md",
13
+ "lib"
14
+ ],
15
+ "scripts": {
16
+ "clean": "rimraf lib && mkdirp lib",
17
+ "build": "yarn run clean && tsc -p tsconfig.build.json",
18
+ "test": "jest",
19
+ "test:coverage": "jest --coverage",
20
+ "prettier": "prettier --check ./src ./test",
21
+ "prettier:fix": "prettier --write ./src ./test",
22
+ "eslint": "eslint --format=pretty ./src ./test",
23
+ "eslint:fix": "eslint --fix --format=pretty ./src ./test",
24
+ "lint": "yarn run prettier && yarn run eslint",
25
+ "lint:fix": "yarn run prettier:fix && yarn run eslint:fix"
26
+ },
27
+ "dependencies": {
28
+ "@monkvision/common": "4.0.0",
29
+ "@monkvision/sights": "4.0.0",
30
+ "jsonwebtoken": "^9.0.2",
31
+ "jwt-decode": "^4.0.0",
32
+ "ky": "^1.2.0",
33
+ "uuid": "^9.0.1"
34
+ },
35
+ "peerDependencies": {
36
+ "@auth0/auth0-react": "^2.2.4",
37
+ "react": "^17.0.2",
38
+ "react-dom": "^17.0.2",
39
+ "react-router-dom": "^6.22.3"
40
+ },
41
+ "devDependencies": {
42
+ "@monkvision/eslint-config-base": "4.0.0",
43
+ "@monkvision/eslint-config-typescript": "4.0.0",
44
+ "@monkvision/jest-config": "4.0.0",
45
+ "@monkvision/prettier-config": "4.0.0",
46
+ "@monkvision/types": "4.0.0",
47
+ "@monkvision/typescript-config": "4.0.0",
48
+ "@types/jest": "^29.2.2",
49
+ "@types/jsonwebtoken": "^9.0.5",
50
+ "@types/node": "^18.11.9",
51
+ "@types/uuid": "^9",
52
+ "@typescript-eslint/eslint-plugin": "^5.43.0",
53
+ "@typescript-eslint/parser": "^5.43.0",
54
+ "eslint": "^8.29.0",
55
+ "eslint-config-airbnb-base": "^15.0.0",
56
+ "eslint-config-prettier": "^8.5.0",
57
+ "eslint-formatter-pretty": "^4.1.0",
58
+ "eslint-plugin-eslint-comments": "^3.2.0",
59
+ "eslint-plugin-import": "^2.26.0",
60
+ "eslint-plugin-jest": "^25.3.0",
61
+ "eslint-plugin-prettier": "^4.2.1",
62
+ "eslint-plugin-promise": "^6.1.1",
63
+ "eslint-utils": "^3.0.0",
64
+ "jest": "^29.3.1",
65
+ "mkdirp": "^1.0.4",
66
+ "prettier": "^2.7.1",
67
+ "regexpp": "^3.2.0",
68
+ "rimraf": "^3.0.2",
69
+ "ts-jest": "^29.0.3",
70
+ "typescript": "^4.8.4"
71
+ },
72
+ "prettier": "@monkvision/prettier-config",
73
+ "publishConfig": {
74
+ "access": "public"
75
+ },
76
+ "repository": {
77
+ "type": "git",
78
+ "url": "https://github.com/monkvision/monkjs.git"
79
+ },
80
+ "bugs": {
81
+ "url": "https://github.com/monkvision/monkjs/issues"
82
+ },
83
+ "homepage": "https://github.com/monkvision/monkjs"
84
+ }
@@ -0,0 +1,18 @@
1
+ import { getInspection, createInspection } from './inspection';
2
+ import { addImage } from './image';
3
+ import { startInspectionTasks, updateTaskStatus } from './task';
4
+ import { getLiveConfig } from './liveConfigs';
5
+ import { updateInspectionVehicle } from './vehicle';
6
+ /**
7
+ * Object regrouping the different API requests available to communicate with the API using the `@monkvision/network`
8
+ * package.
9
+ */
10
+ export declare const MonkApi: {
11
+ getInspection: typeof getInspection;
12
+ createInspection: typeof createInspection;
13
+ addImage: typeof addImage;
14
+ updateTaskStatus: typeof updateTaskStatus;
15
+ startInspectionTasks: typeof startInspectionTasks;
16
+ getLiveConfig: typeof getLiveConfig;
17
+ updateInspectionVehicle: typeof updateInspectionVehicle;
18
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MonkApi = void 0;
4
+ var inspection_1 = require("./inspection");
5
+ var image_1 = require("./image");
6
+ var task_1 = require("./task");
7
+ var liveConfigs_1 = require("./liveConfigs");
8
+ var vehicle_1 = require("./vehicle");
9
+ /**
10
+ * Object regrouping the different API requests available to communicate with the API using the `@monkvision/network`
11
+ * package.
12
+ */
13
+ exports.MonkApi = {
14
+ getInspection: inspection_1.getInspection,
15
+ createInspection: inspection_1.createInspection,
16
+ addImage: image_1.addImage,
17
+ updateTaskStatus: task_1.updateTaskStatus,
18
+ startInspectionTasks: task_1.startInspectionTasks,
19
+ getLiveConfig: liveConfigs_1.getLiveConfig,
20
+ updateInspectionVehicle: vehicle_1.updateInspectionVehicle,
21
+ };
22
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/api.ts"],"names":[],"mappings":";;;AAAA,2CAA+D;AAC/D,iCAAmC;AACnC,+BAAgE;AAChE,6CAA8C;AAC9C,qCAAoD;AAEpD;;;GAGG;AACU,QAAA,OAAO,GAAG;IACrB,aAAa,4BAAA;IACb,gBAAgB,+BAAA;IAChB,QAAQ,kBAAA;IACR,gBAAgB,yBAAA;IAChB,oBAAoB,6BAAA;IACpB,aAAa,6BAAA;IACb,uBAAuB,mCAAA;CACxB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { Options } from 'ky';
2
+ export declare const sdkVersion: string;
3
+ /**
4
+ * Required configuration properties used when interacting with the MonkJs API.
5
+ */
6
+ export interface MonkApiConfig {
7
+ /**
8
+ * The domain of the Monk API.
9
+ */
10
+ apiDomain: string;
11
+ /**
12
+ * The authentication token used to communicate with the API.
13
+ */
14
+ authToken: string;
15
+ /**
16
+ * The API domain used to communicate with the resize micro service.
17
+ */
18
+ thumbnailDomain: string;
19
+ }
20
+ export declare function getDefaultOptions(config?: MonkApiConfig): Options;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getDefaultOptions = exports.sdkVersion = void 0;
7
+ var package_json_1 = __importDefault(require("../../package.json"));
8
+ var error_1 = require("./error");
9
+ exports.sdkVersion = package_json_1.default.version;
10
+ function getPrefixUrl(config) {
11
+ if (!config) {
12
+ return undefined;
13
+ }
14
+ var apiDomain = config.apiDomain.endsWith('/')
15
+ ? config.apiDomain.substring(0, config.apiDomain.length - 1)
16
+ : config.apiDomain;
17
+ return "https://".concat(apiDomain);
18
+ }
19
+ function getAuthorizationHeader(config) {
20
+ if (!config) {
21
+ return undefined;
22
+ }
23
+ return config.authToken.startsWith('Bearer ') ? config.authToken : "Bearer ".concat(config.authToken);
24
+ }
25
+ function getDefaultOptions(config) {
26
+ return {
27
+ prefixUrl: getPrefixUrl(config),
28
+ headers: {
29
+ 'Accept': 'application/json, text/plain, */*',
30
+ 'Access-Control-Allow-Origin': '*',
31
+ 'Authorization': getAuthorizationHeader(config),
32
+ 'X-Monk-SDK-Version': exports.sdkVersion,
33
+ },
34
+ hooks: {
35
+ beforeError: [error_1.beforeError],
36
+ },
37
+ timeout: 30000,
38
+ };
39
+ }
40
+ exports.getDefaultOptions = getDefaultOptions;
41
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/api/config.ts"],"names":[],"mappings":";;;;;;AACA,oEAA6C;AAC7C,iCAAsC;AAEzB,QAAA,UAAU,GAAG,sBAAW,CAAC,OAAO,CAAC;AAoB9C,SAAS,YAAY,CAAC,MAAsB;IAC1C,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,SAAS,CAAC;KAClB;IACD,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC;QAC9C,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QAC5D,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;IACrB,OAAO,kBAAW,SAAS,CAAE,CAAC;AAChC,CAAC;AAED,SAAS,sBAAsB,CAAC,MAAsB;IACpD,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAU,MAAM,CAAC,SAAS,CAAE,CAAC;AAClG,CAAC;AAED,SAAgB,iBAAiB,CAAC,MAAsB;IACtD,OAAO;QACL,SAAS,EAAE,YAAY,CAAC,MAAM,CAAC;QAC/B,OAAO,EAAE;YACP,QAAQ,EAAE,mCAAmC;YAC7C,6BAA6B,EAAE,GAAG;YAClC,eAAe,EAAE,sBAAsB,CAAC,MAAM,CAAC;YAC/C,oBAAoB,EAAE,kBAAU;SACjC;QACD,KAAK,EAAE;YACL,WAAW,EAAE,CAAC,mBAAW,CAAC;SAC3B;QACD,OAAO,EAAE,KAAK;KACf,CAAC;AACJ,CAAC;AAdD,8CAcC"}
@@ -0,0 +1,34 @@
1
+ import { HTTPError } from 'ky';
2
+ import { BeforeErrorHook } from 'ky/distribution/types/hooks';
3
+ import { ApiError } from './models';
4
+ /**
5
+ * Enumeration of names of known error that can occur when making Monk api requests.
6
+ */
7
+ export declare enum MonkNetworkError {
8
+ /**
9
+ * The authentication token was not provided.
10
+ */
11
+ MISSING_TOKEN = "MissingToken",
12
+ /**
13
+ * The authentication token provided in the request is invalid (badly formatted etc.).
14
+ */
15
+ INVALID_TOKEN = "InvalidToken",
16
+ /**
17
+ * The authentication token provided in the request is expired.
18
+ */
19
+ EXPIRED_TOKEN = "TokenExpired",
20
+ /**
21
+ * The user corresponding to the authentication token provided in the request does not have the sufficient
22
+ * authorization to perform the request.
23
+ */
24
+ INSUFFICIENT_AUTHORIZATION = "InsufficientAuthorization"
25
+ }
26
+ /**
27
+ * Type definition for a network error catched by the Monk SDK. Requests made by this package will usually process the
28
+ * error returned by the API and will include the request body (containing the error message) with the Error object
29
+ * itself.
30
+ */
31
+ export interface MonkHTTPError extends HTTPError {
32
+ body?: ApiError;
33
+ }
34
+ export declare const beforeError: BeforeErrorHook;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.beforeError = exports.MonkNetworkError = void 0;
40
+ /**
41
+ * Enumeration of names of known error that can occur when making Monk api requests.
42
+ */
43
+ var MonkNetworkError;
44
+ (function (MonkNetworkError) {
45
+ /**
46
+ * The authentication token was not provided.
47
+ */
48
+ MonkNetworkError["MISSING_TOKEN"] = "MissingToken";
49
+ /**
50
+ * The authentication token provided in the request is invalid (badly formatted etc.).
51
+ */
52
+ MonkNetworkError["INVALID_TOKEN"] = "InvalidToken";
53
+ /**
54
+ * The authentication token provided in the request is expired.
55
+ */
56
+ MonkNetworkError["EXPIRED_TOKEN"] = "TokenExpired";
57
+ /**
58
+ * The user corresponding to the authentication token provided in the request does not have the sufficient
59
+ * authorization to perform the request.
60
+ */
61
+ MonkNetworkError["INSUFFICIENT_AUTHORIZATION"] = "InsufficientAuthorization";
62
+ })(MonkNetworkError = exports.MonkNetworkError || (exports.MonkNetworkError = {}));
63
+ function getErrorMessage(name) {
64
+ switch (name) {
65
+ case MonkNetworkError.MISSING_TOKEN:
66
+ return 'Missing authentication token in request headers.';
67
+ case MonkNetworkError.INVALID_TOKEN:
68
+ return 'Invalid authentication token in request.';
69
+ case MonkNetworkError.EXPIRED_TOKEN:
70
+ return 'Authentication token is expired.';
71
+ case MonkNetworkError.INSUFFICIENT_AUTHORIZATION:
72
+ return 'User does not have the proper authorization grants to perform this request.';
73
+ default:
74
+ return null;
75
+ }
76
+ }
77
+ function getErrorName(status, message) {
78
+ if (status === 401 && message.includes('Authorization header is required')) {
79
+ return MonkNetworkError.MISSING_TOKEN;
80
+ }
81
+ if (status === 401 &&
82
+ [
83
+ 'Token payload schema unknown',
84
+ 'Token decode failed',
85
+ 'Token audience invalid, please check audience',
86
+ 'Token issuer invalid, please check issuer',
87
+ 'Wrong authorization header format, should be in the format : Bearer TOKEN',
88
+ 'Invalid authentication token in request.',
89
+ ].some(function (str) { return message.includes(str); })) {
90
+ return MonkNetworkError.INVALID_TOKEN;
91
+ }
92
+ if (status === 401 && message.includes('Token is expired')) {
93
+ return MonkNetworkError.EXPIRED_TOKEN;
94
+ }
95
+ // TODO : Also check conditions for MonkNetworkError.INSUFFICIENT_AUTHORIZATION.
96
+ return null;
97
+ }
98
+ /* eslint-disable no-param-reassign */
99
+ var beforeError = function (error) { return __awaiter(void 0, void 0, void 0, function () {
100
+ var response, clone, body;
101
+ var _a, _b;
102
+ return __generator(this, function (_c) {
103
+ switch (_c.label) {
104
+ case 0:
105
+ response = error.response;
106
+ clone = response.clone();
107
+ return [4 /*yield*/, clone.json()];
108
+ case 1:
109
+ body = (_c.sent());
110
+ error.name = (_a = getErrorName(clone.status, body.message)) !== null && _a !== void 0 ? _a : error.name;
111
+ error.message = (_b = getErrorMessage(error.name)) !== null && _b !== void 0 ? _b : error.message;
112
+ Object.assign(error, { body: body });
113
+ return [2 /*return*/, error];
114
+ }
115
+ });
116
+ }); };
117
+ exports.beforeError = beforeError;
118
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/api/error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;GAEG;AACH,IAAY,gBAkBX;AAlBD,WAAY,gBAAgB;IAC1B;;OAEG;IACH,kDAA8B,CAAA;IAC9B;;OAEG;IACH,kDAA8B,CAAA;IAC9B;;OAEG;IACH,kDAA8B,CAAA;IAC9B;;;OAGG;IACH,4EAAwD,CAAA;AAC1D,CAAC,EAlBW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAkB3B;AAED,SAAS,eAAe,CAAC,IAAY;IACnC,QAAQ,IAAI,EAAE;QACZ,KAAK,gBAAgB,CAAC,aAAa;YACjC,OAAO,kDAAkD,CAAC;QAC5D,KAAK,gBAAgB,CAAC,aAAa;YACjC,OAAO,0CAA0C,CAAC;QACpD,KAAK,gBAAgB,CAAC,aAAa;YACjC,OAAO,kCAAkC,CAAC;QAC5C,KAAK,gBAAgB,CAAC,0BAA0B;YAC9C,OAAO,6EAA6E,CAAC;QACvF;YACE,OAAO,IAAI,CAAC;KACf;AACH,CAAC;AAED,SAAS,YAAY,CAAC,MAAc,EAAE,OAAe;IACnD,IAAI,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,kCAAkC,CAAC,EAAE;QAC1E,OAAO,gBAAgB,CAAC,aAAa,CAAC;KACvC;IACD,IACE,MAAM,KAAK,GAAG;QACd;YACE,8BAA8B;YAC9B,qBAAqB;YACrB,+CAA+C;YAC/C,2CAA2C;YAC3C,2EAA2E;YAC3E,0CAA0C;SAC3C,CAAC,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAArB,CAAqB,CAAC,EACtC;QACA,OAAO,gBAAgB,CAAC,aAAa,CAAC;KACvC;IACD,IAAI,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE;QAC1D,OAAO,gBAAgB,CAAC,aAAa,CAAC;KACvC;IACD,gFAAgF;IAChF,OAAO,IAAI,CAAC;AACd,CAAC;AAWD,sCAAsC;AAC/B,IAAM,WAAW,GAAoB,UAAO,KAAgB;;;;;;gBACzD,QAAQ,GAAK,KAAK,SAAV,CAAW;gBACrB,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;gBACjB,qBAAM,KAAK,CAAC,IAAI,EAAE,EAAA;;gBAA1B,IAAI,GAAG,CAAC,SAAkB,CAAa;gBAC7C,KAAK,CAAC,IAAI,GAAG,MAAA,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,mCAAI,KAAK,CAAC,IAAI,CAAC;gBACpE,KAAK,CAAC,OAAO,GAAG,MAAA,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,mCAAI,KAAK,CAAC,OAAO,CAAC;gBAC7D,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;gBAC/B,sBAAO,KAAK,EAAC;;;KACd,CAAC;AARW,QAAA,WAAW,eAQtB"}
@@ -0,0 +1 @@
1
+ export * from './useInspectionPoll';
@@ -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("./useInspectionPoll"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/api/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}