@wandelbots/nova-js 3.1.0 → 3.2.0-pr.ci-simplify-build.137.87eeb8d

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 (79) hide show
  1. package/dist/AutoReconnectingWebsocket-BI1ckzP8.d.ts +71 -0
  2. package/dist/AutoReconnectingWebsocket-BI1ckzP8.d.ts.map +1 -0
  3. package/dist/AutoReconnectingWebsocket-Cr7f9016.d.cts +71 -0
  4. package/dist/AutoReconnectingWebsocket-Cr7f9016.d.cts.map +1 -0
  5. package/dist/LoginWithAuth0-0g0wWRUC.js +217 -0
  6. package/dist/LoginWithAuth0-0g0wWRUC.js.map +1 -0
  7. package/dist/LoginWithAuth0-C82OCyDy.cjs +264 -0
  8. package/dist/LoginWithAuth0-C82OCyDy.cjs.map +1 -0
  9. package/dist/converters-DP2EIVv6.cjs +108 -0
  10. package/dist/converters-DP2EIVv6.cjs.map +1 -0
  11. package/dist/converters-DY6Lf7mb.js +66 -0
  12. package/dist/converters-DY6Lf7mb.js.map +1 -0
  13. package/dist/index.cjs +41 -386
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +70 -0
  16. package/dist/index.d.cts.map +1 -0
  17. package/dist/index.d.ts +69 -5
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +28 -52
  20. package/dist/index.js.map +1 -1
  21. package/dist/lib/v1/index.cjs +2146 -2917
  22. package/dist/lib/v1/index.cjs.map +1 -1
  23. package/dist/lib/v1/index.d.cts +397 -0
  24. package/dist/lib/v1/index.d.cts.map +1 -0
  25. package/dist/lib/v1/index.d.ts +395 -7
  26. package/dist/lib/v1/index.d.ts.map +1 -1
  27. package/dist/lib/v1/index.js +2127 -2623
  28. package/dist/lib/v1/index.js.map +1 -1
  29. package/dist/lib/v2/index.cjs +1356 -1472
  30. package/dist/lib/v2/index.cjs.map +1 -1
  31. package/dist/lib/v2/index.d.cts +115 -0
  32. package/dist/lib/v2/index.d.cts.map +1 -0
  33. package/dist/lib/v2/index.d.ts +113 -2
  34. package/dist/lib/v2/index.d.ts.map +1 -1
  35. package/dist/lib/v2/index.js +1346 -1189
  36. package/dist/lib/v2/index.js.map +1 -1
  37. package/package.json +14 -16
  38. package/src/LoginWithAuth0.ts +9 -9
  39. package/src/lib/v1/NovaCellAPIClient.ts +4 -2
  40. package/src/lib/v2/NovaCellAPIClient.ts +4 -2
  41. package/src/lib/v2/mock/MockNovaInstance.ts +9 -13
  42. package/dist/LoginWithAuth0.d.ts +0 -7
  43. package/dist/LoginWithAuth0.d.ts.map +0 -1
  44. package/dist/chunk-B2C22PTK.js +0 -53
  45. package/dist/chunk-B2C22PTK.js.map +0 -1
  46. package/dist/chunk-I3PUV6ZD.js +0 -286
  47. package/dist/chunk-I3PUV6ZD.js.map +0 -1
  48. package/dist/lib/AutoReconnectingWebsocket.d.ts +0 -43
  49. package/dist/lib/AutoReconnectingWebsocket.d.ts.map +0 -1
  50. package/dist/lib/availableStorage.d.ts +0 -15
  51. package/dist/lib/availableStorage.d.ts.map +0 -1
  52. package/dist/lib/converters.d.ts +0 -26
  53. package/dist/lib/converters.d.ts.map +0 -1
  54. package/dist/lib/errorHandling.d.ts +0 -15
  55. package/dist/lib/errorHandling.d.ts.map +0 -1
  56. package/dist/lib/v1/ConnectedMotionGroup.d.ts +0 -77
  57. package/dist/lib/v1/ConnectedMotionGroup.d.ts.map +0 -1
  58. package/dist/lib/v1/JoggerConnection.d.ts +0 -94
  59. package/dist/lib/v1/JoggerConnection.d.ts.map +0 -1
  60. package/dist/lib/v1/MotionStreamConnection.d.ts +0 -26
  61. package/dist/lib/v1/MotionStreamConnection.d.ts.map +0 -1
  62. package/dist/lib/v1/NovaCellAPIClient.d.ts +0 -68
  63. package/dist/lib/v1/NovaCellAPIClient.d.ts.map +0 -1
  64. package/dist/lib/v1/NovaClient.d.ts +0 -67
  65. package/dist/lib/v1/NovaClient.d.ts.map +0 -1
  66. package/dist/lib/v1/ProgramStateConnection.d.ts +0 -57
  67. package/dist/lib/v1/ProgramStateConnection.d.ts.map +0 -1
  68. package/dist/lib/v1/getLatestTrajectories.d.ts +0 -4
  69. package/dist/lib/v1/getLatestTrajectories.d.ts.map +0 -1
  70. package/dist/lib/v1/mock/MockNovaInstance.d.ts +0 -13
  71. package/dist/lib/v1/mock/MockNovaInstance.d.ts.map +0 -1
  72. package/dist/lib/v1/motionStateUpdate.d.ts +0 -4
  73. package/dist/lib/v1/motionStateUpdate.d.ts.map +0 -1
  74. package/dist/lib/v2/NovaCellAPIClient.d.ts +0 -62
  75. package/dist/lib/v2/NovaCellAPIClient.d.ts.map +0 -1
  76. package/dist/lib/v2/NovaClient.d.ts +0 -60
  77. package/dist/lib/v2/NovaClient.d.ts.map +0 -1
  78. package/dist/lib/v2/mock/MockNovaInstance.d.ts +0 -13
  79. package/dist/lib/v2/mock/MockNovaInstance.d.ts.map +0 -1
@@ -1,1200 +1,1357 @@
1
- import {
2
- AutoReconnectingWebsocket,
3
- __async,
4
- __spreadProps,
5
- __spreadValues,
6
- availableStorage,
7
- loginWithAuth0
8
- } from "../../chunk-I3PUV6ZD.js";
1
+ import { AutoReconnectingWebsocket, availableStorage, loginWithAuth0 } from "../../LoginWithAuth0-0g0wWRUC.js";
2
+ import axios, { AxiosError, isAxiosError } from "axios";
3
+ import urlJoin from "url-join";
4
+ import * as pathToRegexp from "path-to-regexp";
5
+ import { ApplicationApi, BUSInputsOutputsApi, CellApi, ControllerApi, ControllerInputsOutputsApi, JoggingApi, KinematicsApi, MotionGroupApi, MotionGroupModelsApi, StoreCollisionComponentsApi, StoreCollisionSetupsApi, StoreObjectApi, SystemApi, TrajectoryCachingApi, TrajectoryExecutionApi, TrajectoryPlanningApi, VirtualControllerApi, VirtualControllerBehaviorApi, VirtualControllerInputsOutputsApi } from "@wandelbots/nova-api/v2";
9
6
 
10
- // src/lib/v2/index.ts
11
- export * from "@wandelbots/nova-api/v2";
7
+ export * from "@wandelbots/nova-api/v2"
12
8
 
13
- // src/lib/v2/NovaCellAPIClient.ts
14
- import {
15
- ApplicationApi,
16
- BUSInputsOutputsApi,
17
- CellApi,
18
- ControllerApi,
19
- ControllerInputsOutputsApi,
20
- JoggingApi,
21
- KinematicsApi,
22
- MotionGroupApi,
23
- MotionGroupModelsApi,
24
- StoreCollisionComponentsApi,
25
- StoreCollisionSetupsApi,
26
- StoreObjectApi,
27
- SystemApi,
28
- TrajectoryCachingApi,
29
- TrajectoryExecutionApi,
30
- TrajectoryPlanningApi,
31
- VirtualControllerApi,
32
- VirtualControllerBehaviorApi,
33
- VirtualControllerInputsOutputsApi
34
- } from "@wandelbots/nova-api/v2";
35
- import axios from "axios";
9
+ //#region src/lib/v2/NovaCellAPIClient.ts
10
+ /**
11
+ * API client providing type-safe access to all the Nova API REST endpoints
12
+ * associated with a specific cell id.
13
+ */
36
14
  var NovaCellAPIClient = class {
37
- constructor(cellId, opts) {
38
- this.cellId = cellId;
39
- this.opts = opts;
40
- this.system = this.withUnwrappedResponsesOnly(SystemApi);
41
- this.cell = this.withUnwrappedResponsesOnly(CellApi);
42
- this.motionGroup = this.withCellId(MotionGroupApi);
43
- this.motionGroupModels = this.withCellId(MotionGroupModelsApi);
44
- this.controller = this.withCellId(ControllerApi);
45
- this.controllerIOs = this.withCellId(ControllerInputsOutputsApi);
46
- this.trajectoryPlanning = this.withCellId(TrajectoryPlanningApi);
47
- this.trajectoryExecution = this.withCellId(TrajectoryExecutionApi);
48
- this.trajectoryCaching = this.withCellId(TrajectoryCachingApi);
49
- this.application = this.withCellId(ApplicationApi);
50
- this.applicationGlobal = this.withUnwrappedResponsesOnly(ApplicationApi);
51
- this.jogging = this.withCellId(JoggingApi);
52
- this.kinematics = this.withCellId(KinematicsApi);
53
- this.busInputsOutputs = this.withCellId(BUSInputsOutputsApi);
54
- this.virtualController = this.withCellId(VirtualControllerApi);
55
- this.virtualControllerBehavior = this.withCellId(
56
- VirtualControllerBehaviorApi
57
- );
58
- this.virtualControllerIOs = this.withCellId(
59
- VirtualControllerInputsOutputsApi
60
- );
61
- this.storeObject = this.withCellId(StoreObjectApi);
62
- this.storeCollisionComponents = this.withCellId(
63
- StoreCollisionComponentsApi
64
- );
65
- this.storeCollisionSetups = this.withCellId(StoreCollisionSetupsApi);
66
- }
67
- /**
68
- * Some TypeScript sorcery which alters the API class methods so you don't
69
- * have to pass the cell id to every single one, and de-encapsulates the
70
- * response data
71
- */
72
- withCellId(ApiConstructor) {
73
- var _a, _b;
74
- const apiClient = new ApiConstructor(
75
- __spreadProps(__spreadValues({}, this.opts), {
76
- isJsonMime: (mime) => {
77
- return mime === "application/json";
78
- }
79
- }),
80
- (_a = this.opts.basePath) != null ? _a : "",
81
- (_b = this.opts.axiosInstance) != null ? _b : axios.create()
82
- );
83
- for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) {
84
- if (key !== "constructor" && typeof apiClient[key] === "function") {
85
- const originalFunction = apiClient[key];
86
- apiClient[key] = (...args) => {
87
- return originalFunction.apply(apiClient, [this.cellId, ...args]).then((res) => res.data);
88
- };
89
- }
90
- }
91
- return apiClient;
92
- }
93
- /**
94
- * As withCellId, but only does the response unwrapping
95
- */
96
- withUnwrappedResponsesOnly(ApiConstructor) {
97
- var _a, _b;
98
- const apiClient = new ApiConstructor(
99
- __spreadProps(__spreadValues({}, this.opts), {
100
- isJsonMime: (mime) => {
101
- return mime === "application/json";
102
- }
103
- }),
104
- (_a = this.opts.basePath) != null ? _a : "",
105
- (_b = this.opts.axiosInstance) != null ? _b : axios.create()
106
- );
107
- for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) {
108
- if (key !== "constructor" && typeof apiClient[key] === "function") {
109
- const originalFunction = apiClient[key];
110
- apiClient[key] = (...args) => {
111
- return originalFunction.apply(apiClient, args).then((res) => res.data);
112
- };
113
- }
114
- }
115
- return apiClient;
116
- }
15
+ constructor(cellId, opts) {
16
+ this.cellId = cellId;
17
+ this.opts = opts;
18
+ this.system = this.withUnwrappedResponsesOnly(SystemApi);
19
+ this.cell = this.withUnwrappedResponsesOnly(CellApi);
20
+ this.motionGroup = this.withCellId(MotionGroupApi);
21
+ this.motionGroupModels = this.withCellId(MotionGroupModelsApi);
22
+ this.controller = this.withCellId(ControllerApi);
23
+ this.controllerIOs = this.withCellId(ControllerInputsOutputsApi);
24
+ this.trajectoryPlanning = this.withCellId(TrajectoryPlanningApi);
25
+ this.trajectoryExecution = this.withCellId(TrajectoryExecutionApi);
26
+ this.trajectoryCaching = this.withCellId(TrajectoryCachingApi);
27
+ this.application = this.withCellId(ApplicationApi);
28
+ this.applicationGlobal = this.withUnwrappedResponsesOnly(ApplicationApi);
29
+ this.jogging = this.withCellId(JoggingApi);
30
+ this.kinematics = this.withCellId(KinematicsApi);
31
+ this.busInputsOutputs = this.withCellId(BUSInputsOutputsApi);
32
+ this.virtualController = this.withCellId(VirtualControllerApi);
33
+ this.virtualControllerBehavior = this.withCellId(VirtualControllerBehaviorApi);
34
+ this.virtualControllerIOs = this.withCellId(VirtualControllerInputsOutputsApi);
35
+ this.storeObject = this.withCellId(StoreObjectApi);
36
+ this.storeCollisionComponents = this.withCellId(StoreCollisionComponentsApi);
37
+ this.storeCollisionSetups = this.withCellId(StoreCollisionSetupsApi);
38
+ }
39
+ /**
40
+ * Some TypeScript sorcery which alters the API class methods so you don't
41
+ * have to pass the cell id to every single one, and de-encapsulates the
42
+ * response data
43
+ */
44
+ withCellId(ApiConstructor) {
45
+ const apiClient = new ApiConstructor({
46
+ ...this.opts,
47
+ isJsonMime: (mime) => {
48
+ return mime === "application/json";
49
+ }
50
+ }, this.opts.basePath ?? "", this.opts.axiosInstance ?? axios.create());
51
+ for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) if (key !== "constructor" && typeof apiClient[key] === "function") {
52
+ const originalFunction = apiClient[key];
53
+ apiClient[key] = (...args) => {
54
+ return originalFunction.apply(apiClient, [this.cellId, ...args]).then((res) => res.data);
55
+ };
56
+ }
57
+ return apiClient;
58
+ }
59
+ /**
60
+ * As withCellId, but only does the response unwrapping
61
+ */
62
+ withUnwrappedResponsesOnly(ApiConstructor) {
63
+ const apiClient = new ApiConstructor({
64
+ ...this.opts,
65
+ isJsonMime: (mime) => {
66
+ return mime === "application/json";
67
+ }
68
+ }, this.opts.basePath ?? "", this.opts.axiosInstance ?? axios.create());
69
+ for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) if (key !== "constructor" && typeof apiClient[key] === "function") {
70
+ const originalFunction = apiClient[key];
71
+ apiClient[key] = (...args) => {
72
+ return originalFunction.apply(apiClient, args).then((res) => res.data);
73
+ };
74
+ }
75
+ return apiClient;
76
+ }
117
77
  };
118
78
 
119
- // src/lib/v2/NovaClient.ts
120
- import axios2, { isAxiosError } from "axios";
121
- import urlJoin from "url-join";
122
-
123
- // src/lib/v2/mock/MockNovaInstance.ts
124
- import { AxiosError } from "axios";
125
- import * as pathToRegexp from "path-to-regexp";
79
+ //#endregion
80
+ //#region src/lib/v2/mock/MockNovaInstance.ts
81
+ /**
82
+ * EXPERIMENTAL
83
+ * Ultra-simplified mock Nova server for testing stuff
84
+ */
126
85
  var MockNovaInstance = class {
127
- constructor() {
128
- this.connections = [];
129
- }
130
- handleAPIRequest(config) {
131
- return __async(this, null, function* () {
132
- var _a, _b, _c;
133
- const apiHandlers = [
134
- {
135
- method: "GET",
136
- path: "/cells/:cellId/controllers",
137
- handle() {
138
- return {
139
- controllers: [
140
- {
141
- controller: "mock-ur5e",
142
- model_name: "UniversalRobots::Controller",
143
- host: "mock-ur5e",
144
- allow_software_install_on_controller: true,
145
- motion_groups: [
146
- {
147
- motion_group: "0@mock-ur5e",
148
- name_from_controller: "UR5e",
149
- active: false,
150
- model_from_controller: "UniversalRobots_UR5e"
151
- }
152
- ],
153
- has_error: false,
154
- error_details: ""
155
- }
156
- ]
157
- };
158
- }
159
- },
160
- {
161
- method: "GET",
162
- path: "/cells/:cellId/controllers/:controllerId",
163
- handle() {
164
- return {
165
- configuration: {
166
- kind: "VirtualController",
167
- manufacturer: "universalrobots",
168
- type: "universalrobots-ur5e"
169
- },
170
- name: "mock-ur5"
171
- };
172
- }
173
- },
174
- {
175
- method: "GET",
176
- path: "/cells/:cellId/motion-groups/:motionGroupId/specification",
177
- handle() {
178
- return {
179
- dh_parameters: [
180
- {
181
- alpha: 1.5707963267948966,
182
- theta: 0,
183
- a: 0,
184
- d: 162.25,
185
- reverse_rotation_direction: false
186
- },
187
- {
188
- alpha: 0,
189
- theta: 0,
190
- a: -425,
191
- d: 0,
192
- reverse_rotation_direction: false
193
- },
194
- {
195
- alpha: 0,
196
- theta: 0,
197
- a: -392.2,
198
- d: 0,
199
- reverse_rotation_direction: false
200
- },
201
- {
202
- alpha: 1.5707963267948966,
203
- theta: 0,
204
- a: 0,
205
- d: 133.3,
206
- reverse_rotation_direction: false
207
- },
208
- {
209
- alpha: -1.5707963267948966,
210
- theta: 0,
211
- a: 0,
212
- d: 99.7,
213
- reverse_rotation_direction: false
214
- },
215
- {
216
- alpha: 0,
217
- theta: 0,
218
- a: 0,
219
- d: 99.6,
220
- reverse_rotation_direction: false
221
- }
222
- ],
223
- mechanical_joint_limits: [
224
- {
225
- joint: "JOINTNAME_AXIS_1",
226
- lower_limit: -6.335545063018799,
227
- upper_limit: 6.335545063018799,
228
- unlimited: false
229
- },
230
- {
231
- joint: "JOINTNAME_AXIS_2",
232
- lower_limit: -6.335545063018799,
233
- upper_limit: 6.335545063018799,
234
- unlimited: false
235
- },
236
- {
237
- joint: "JOINTNAME_AXIS_3",
238
- lower_limit: -6.335545063018799,
239
- upper_limit: 6.335545063018799,
240
- unlimited: false
241
- },
242
- {
243
- joint: "JOINTNAME_AXIS_4",
244
- lower_limit: -6.335545063018799,
245
- upper_limit: 6.335545063018799,
246
- unlimited: false
247
- },
248
- {
249
- joint: "JOINTNAME_AXIS_5",
250
- lower_limit: -6.335545063018799,
251
- upper_limit: 6.335545063018799,
252
- unlimited: false
253
- },
254
- {
255
- joint: "JOINTNAME_AXIS_6",
256
- lower_limit: -6.335545063018799,
257
- upper_limit: 6.335545063018799,
258
- unlimited: false
259
- }
260
- ]
261
- };
262
- }
263
- },
264
- {
265
- method: "GET",
266
- path: "/cells/:cellId/motion-groups/:motionGroupId/safety-setup",
267
- handle() {
268
- return {
269
- safety_settings: [
270
- {
271
- safety_state: "SAFETY_NORMAL",
272
- settings: {
273
- joint_position_limits: [
274
- {
275
- joint: "JOINTNAME_AXIS_1",
276
- lower_limit: -2.96705961227417,
277
- upper_limit: 2.96705961227417,
278
- unlimited: false
279
- },
280
- {
281
- joint: "JOINTNAME_AXIS_2",
282
- lower_limit: -1.7453292608261108,
283
- upper_limit: 2.7925267219543457,
284
- unlimited: false
285
- },
286
- {
287
- joint: "JOINTNAME_AXIS_3",
288
- lower_limit: -3.3161256313323975,
289
- upper_limit: 0.40142571926116943,
290
- unlimited: false
291
- },
292
- {
293
- joint: "JOINTNAME_AXIS_4",
294
- lower_limit: -3.4906585216522217,
295
- upper_limit: 3.4906585216522217,
296
- unlimited: false
297
- },
298
- {
299
- joint: "JOINTNAME_AXIS_5",
300
- lower_limit: -2.4434609413146973,
301
- upper_limit: 2.4434609413146973,
302
- unlimited: false
303
- },
304
- {
305
- joint: "JOINTNAME_AXIS_6",
306
- lower_limit: -4.71238899230957,
307
- upper_limit: 4.71238899230957,
308
- unlimited: false
309
- }
310
- ],
311
- joint_velocity_limits: [
312
- {
313
- joint: "JOINTNAME_AXIS_1",
314
- limit: 3.1415927410125732
315
- },
316
- {
317
- joint: "JOINTNAME_AXIS_2",
318
- limit: 3.1415927410125732
319
- },
320
- {
321
- joint: "JOINTNAME_AXIS_3",
322
- limit: 3.4906585216522217
323
- },
324
- {
325
- joint: "JOINTNAME_AXIS_4",
326
- limit: 6.108652591705322
327
- },
328
- {
329
- joint: "JOINTNAME_AXIS_5",
330
- limit: 6.108652591705322
331
- },
332
- {
333
- joint: "JOINTNAME_AXIS_6",
334
- limit: 6.981317043304443
335
- }
336
- ],
337
- joint_acceleration_limits: [],
338
- joint_torque_limits: [],
339
- tcp_velocity_limit: 1800
340
- }
341
- }
342
- ],
343
- safety_zones: [
344
- {
345
- id: 1,
346
- priority: 0,
347
- geometry: {
348
- compound: {
349
- child_geometries: [
350
- {
351
- convex_hull: {
352
- vertices: [
353
- { vertex: [-800, -1330, -1820] },
354
- { vertex: [1650, -1330, -1820] },
355
- { vertex: [1650, 1330, -1820] },
356
- { vertex: [-800, 1330, -1820] }
357
- ]
358
- },
359
- init_pose: {
360
- position: [0, 0, 0],
361
- orientation: [0, 0, 0, 1]
362
- },
363
- id: "box"
364
- },
365
- {
366
- convex_hull: {
367
- vertices: [
368
- {
369
- vertex: [-800, -1330, -1820]
370
- },
371
- {
372
- vertex: [1650, -1330, -1820]
373
- },
374
- {
375
- vertex: [1650, -1330, 1500]
376
- },
377
- {
378
- vertex: [-800, -1330, 1500]
379
- }
380
- ]
381
- },
382
- init_pose: {
383
- position: [0, 0, 0],
384
- orientation: [0, 0, 0, 1]
385
- },
386
- id: "box"
387
- },
388
- {
389
- convex_hull: {
390
- vertices: [
391
- {
392
- vertex: [-800, -1330, -1820]
393
- },
394
- {
395
- vertex: [-800, 1330, -1820]
396
- },
397
- {
398
- vertex: [-800, 1330, 1500]
399
- },
400
- {
401
- vertex: [-800, -1330, 1500]
402
- }
403
- ]
404
- },
405
- init_pose: {
406
- position: [0, 0, 0],
407
- orientation: [0, 0, 0, 1]
408
- },
409
- id: "box"
410
- },
411
- {
412
- convex_hull: {
413
- vertices: [
414
- {
415
- vertex: [1650, 1330, 1500]
416
- },
417
- {
418
- vertex: [-800, 1330, 1500]
419
- },
420
- {
421
- vertex: [-800, -1330, 1500]
422
- },
423
- {
424
- vertex: [1650, -1330, 1500]
425
- }
426
- ]
427
- },
428
- init_pose: {
429
- position: [0, 0, 0],
430
- orientation: [0, 0, 0, 1]
431
- },
432
- id: "box"
433
- },
434
- {
435
- convex_hull: {
436
- vertices: [
437
- {
438
- vertex: [1650, 1330, 1500]
439
- },
440
- {
441
- vertex: [-800, 1330, 1500]
442
- },
443
- {
444
- vertex: [-800, 1330, -1820]
445
- },
446
- {
447
- vertex: [1650, 1330, -1820]
448
- }
449
- ]
450
- },
451
- init_pose: {
452
- position: [0, 0, 0],
453
- orientation: [0, 0, 0, 1]
454
- },
455
- id: "box"
456
- },
457
- {
458
- convex_hull: {
459
- vertices: [
460
- {
461
- vertex: [1650, 1330, 1500]
462
- },
463
- {
464
- vertex: [1650, -1330, 1500]
465
- },
466
- {
467
- vertex: [1650, -1330, -1820]
468
- },
469
- {
470
- vertex: [1650, 1330, -1820]
471
- }
472
- ]
473
- },
474
- init_pose: {
475
- position: [0, 0, 0],
476
- orientation: [0, 0, 0, 1]
477
- },
478
- id: "box"
479
- }
480
- ]
481
- },
482
- init_pose: {
483
- position: [0, 0, 0],
484
- orientation: [0, 0, 0, 1]
485
- },
486
- id: "Cell workzone"
487
- },
488
- motion_group_uid: 1
489
- },
490
- {
491
- id: 2,
492
- priority: 0,
493
- geometry: {
494
- convex_hull: {
495
- vertices: [
496
- {
497
- vertex: [1650, 1330, -1850]
498
- },
499
- {
500
- vertex: [865, 1330, -1850]
501
- },
502
- {
503
- vertex: [865, -720, -1850]
504
- },
505
- {
506
- vertex: [1650, -720, -1850]
507
- },
508
- {
509
- vertex: [1650, 1330, -920]
510
- },
511
- {
512
- vertex: [865, 1330, -920]
513
- },
514
- {
515
- vertex: [865, -720, -920]
516
- },
517
- {
518
- vertex: [1650, -720, -920]
519
- }
520
- ]
521
- },
522
- init_pose: {
523
- position: [0, 0, 0],
524
- orientation: [0, 0, 0, 1]
525
- },
526
- id: "Transport"
527
- },
528
- motion_group_uid: 1
529
- },
530
- {
531
- id: 3,
532
- priority: 0,
533
- geometry: {
534
- convex_hull: {
535
- vertices: [
536
- {
537
- vertex: [1650, 1330, -600]
538
- },
539
- {
540
- vertex: [865, 1330, -600]
541
- },
542
- {
543
- vertex: [865, 430, -600]
544
- },
545
- {
546
- vertex: [1650, 430, -600]
547
- },
548
- {
549
- vertex: [1650, 1330, -1250]
550
- },
551
- {
552
- vertex: [865, 1330, -1250]
553
- },
554
- {
555
- vertex: [865, 430, -1250]
556
- },
557
- {
558
- vertex: [1650, 430, -1250]
559
- }
560
- ]
561
- },
562
- init_pose: {
563
- position: [0, 0, 0],
564
- orientation: [0, 0, 0, 1]
565
- },
566
- id: "Tunel"
567
- },
568
- motion_group_uid: 1
569
- },
570
- {
571
- id: 4,
572
- priority: 0,
573
- geometry: {
574
- convex_hull: {
575
- vertices: [
576
- {
577
- vertex: [1650, -760, -440]
578
- },
579
- {
580
- vertex: [900, -760, -440]
581
- },
582
- {
583
- vertex: [900, -1330, -440]
584
- },
585
- {
586
- vertex: [1650, -1330, -440]
587
- },
588
- {
589
- vertex: [1650, -760, -1800]
590
- },
591
- {
592
- vertex: [900, -760, -1800]
593
- },
594
- {
595
- vertex: [900, -1330, -1800]
596
- },
597
- {
598
- vertex: [1650, -1330, -1800]
599
- }
600
- ]
601
- },
602
- init_pose: {
603
- position: [0, 0, 0],
604
- orientation: [0, 0, 0, 1]
605
- },
606
- id: "Fanuc controller"
607
- },
608
- motion_group_uid: 1
609
- },
610
- {
611
- id: 6,
612
- priority: 0,
613
- geometry: {
614
- convex_hull: {
615
- vertices: [
616
- {
617
- vertex: [-200, -200, -1900]
618
- },
619
- {
620
- vertex: [200, -200, -1900]
621
- },
622
- {
623
- vertex: [200, 200, -1900]
624
- },
625
- {
626
- vertex: [-200, 200, -1900]
627
- },
628
- {
629
- vertex: [-200, -200, -350]
630
- },
631
- {
632
- vertex: [200, -200, -350]
633
- },
634
- {
635
- vertex: [200, 200, -350]
636
- },
637
- {
638
- vertex: [-200, 200, -350]
639
- }
640
- ]
641
- },
642
- init_pose: {
643
- position: [0, 0, 0],
644
- orientation: [0, 0, 0, 1]
645
- },
646
- id: "Robot base"
647
- },
648
- motion_group_uid: 1
649
- }
650
- ],
651
- robot_model_geometries: [
652
- {
653
- link_index: 1,
654
- geometry: {
655
- sphere: {
656
- radius: 270
657
- },
658
- init_pose: {
659
- position: [-70, -70, -50],
660
- orientation: [0, 0, 0, 1]
661
- },
662
- id: "link1_sphere"
663
- }
664
- },
665
- {
666
- link_index: 2,
667
- geometry: {
668
- capsule: {
669
- radius: 160,
670
- cylinder_height: 800
671
- },
672
- init_pose: {
673
- position: [-450, 40, 170],
674
- orientation: [0, -Math.SQRT1_2, 0, Math.SQRT1_2]
675
- },
676
- id: "link2_capsule"
677
- }
678
- },
679
- {
680
- link_index: 3,
681
- geometry: {
682
- sphere: {
683
- radius: 270
684
- },
685
- init_pose: {
686
- position: [-110, 10, -100],
687
- orientation: [0, 0, 0, 1]
688
- },
689
- id: "link3_sphere"
690
- }
691
- },
692
- {
693
- link_index: 4,
694
- geometry: {
695
- capsule: {
696
- radius: 110,
697
- cylinder_height: 600
698
- },
699
- init_pose: {
700
- position: [0, 300, 40],
701
- orientation: [-Math.SQRT1_2, 0, 0, Math.SQRT1_2]
702
- },
703
- id: "link4_capsule"
704
- }
705
- },
706
- {
707
- link_index: 5,
708
- geometry: {
709
- sphere: {
710
- radius: 75
711
- },
712
- init_pose: {
713
- position: [0, 0, -50],
714
- orientation: [0, 0, 0, 1]
715
- },
716
- id: "link5_sphere"
717
- }
718
- }
719
- ],
720
- tool_geometries: []
721
- };
722
- }
723
- },
724
- {
725
- method: "GET",
726
- path: "/cells/:cellId/coordinate-systems",
727
- handle() {
728
- return {
729
- coordinatesystems: [
730
- {
731
- coordinate_system: "",
732
- name: "world",
733
- reference_uid: "",
734
- position: [0, 0, 0],
735
- rotation: {
736
- angles: [0, 0, 0],
737
- type: "ROTATION_VECTOR"
738
- }
739
- }
740
- ]
741
- };
742
- }
743
- },
744
- {
745
- method: "GET",
746
- path: "/cells/:cellId/motion-groups/:motionGroupId/tcps",
747
- handle() {
748
- return {
749
- tcps: [
750
- {
751
- id: "Flange",
752
- readable_name: "Default-Flange",
753
- position: [0, 0, 0],
754
- rotation: {
755
- angles: [0, 0, 0, 0],
756
- type: "ROTATION_VECTOR"
757
- }
758
- },
759
- {
760
- id: "complex-tcp-position",
761
- readable_name: "Complex TCP Position",
762
- position: [-200, 300, 150],
763
- rotation: {
764
- angles: [
765
- -0.12139440409113832,
766
- -0.06356210998212003,
767
- -0.2023240068185639,
768
- 0
769
- ],
770
- type: "ROTATION_VECTOR"
771
- }
772
- }
773
- ]
774
- };
775
- }
776
- }
777
- ];
778
- const method = ((_a = config.method) == null ? void 0 : _a.toUpperCase()) || "GET";
779
- const path = `/cells${(_c = (_b = config.url) == null ? void 0 : _b.split("/cells")[1]) == null ? void 0 : _c.split("?")[0]}`;
780
- for (const handler of apiHandlers) {
781
- const match2 = pathToRegexp.match(handler.path)(path || "");
782
- if (method === handler.method && match2) {
783
- const json = handler.handle();
784
- return {
785
- status: 200,
786
- statusText: "Success",
787
- data: JSON.stringify(json),
788
- headers: {},
789
- config,
790
- request: {
791
- responseURL: config.url
792
- }
793
- };
794
- }
795
- }
796
- throw new AxiosError(
797
- `No mock handler matched this request: ${method} ${path}`,
798
- "404",
799
- config
800
- );
801
- });
802
- }
803
- handleWebsocketConnection(socket) {
804
- this.connections.push(socket);
805
- setTimeout(() => {
806
- socket.dispatchEvent(new Event("open"));
807
- console.log("Websocket connection opened from", socket.url);
808
- if (socket.url.includes("/state-stream")) {
809
- socket.dispatchEvent(
810
- new MessageEvent("message", {
811
- data: JSON.stringify(defaultMotionState)
812
- })
813
- );
814
- }
815
- if (socket.url.includes("/move-joint")) {
816
- socket.dispatchEvent(
817
- new MessageEvent("message", {
818
- data: JSON.stringify({
819
- result: {
820
- motion_group: "0@ur",
821
- state: {
822
- controller: "ur",
823
- operation_mode: "OPERATION_MODE_AUTO",
824
- safety_state: "SAFETY_STATE_NORMAL",
825
- timestamp: "2024-09-18T12:48:26.096266444Z",
826
- velocity_override: 100,
827
- motion_groups: [
828
- {
829
- motion_group: "0@ur",
830
- controller: "ur",
831
- joint_position: {
832
- joints: [
833
- 1.3492152690887451,
834
- -1.5659207105636597,
835
- 1.6653711795806885,
836
- -1.0991662740707397,
837
- -1.829018235206604,
838
- 1.264623761177063
839
- ]
840
- },
841
- joint_velocity: {
842
- joints: [0, 0, 0, 0, 0, 0]
843
- },
844
- flange_pose: {
845
- position: [
846
- 6.437331889439328,
847
- -628.4123774830913,
848
- 577.0569957147832
849
- ],
850
- orientation: {
851
- x: -1.683333649797158,
852
- y: -1.9783363827298732,
853
- z: -0.4928031860165713
854
- },
855
- coordinate_system: ""
856
- },
857
- tcp_pose: {
858
- position: [
859
- 6.437331889439328,
860
- -628.4123774830913,
861
- 577.0569957147832
862
- ],
863
- orientation: {
864
- x: -1.683333649797158,
865
- y: -1.9783363827298732,
866
- z: -0.4928031860165713
867
- },
868
- coordinate_system: "",
869
- tcp: "Flange"
870
- },
871
- velocity: {
872
- linear: {
873
- x: 0,
874
- y: 0,
875
- z: 0
876
- },
877
- angular: {
878
- x: -0,
879
- y: 0,
880
- z: 0
881
- },
882
- coordinate_system: ""
883
- },
884
- force: {
885
- force: {
886
- x: 0,
887
- y: 0,
888
- z: 0
889
- },
890
- moment: {
891
- x: 0,
892
- y: 0,
893
- z: 0
894
- },
895
- coordinate_system: ""
896
- },
897
- joint_limit_reached: {
898
- limit_reached: [
899
- false,
900
- false,
901
- false,
902
- false,
903
- false,
904
- false
905
- ]
906
- },
907
- joint_current: {
908
- joints: [0, 0, 0, 0, 0, 0]
909
- },
910
- sequence_number: "671259"
911
- }
912
- ],
913
- sequence_number: "671259"
914
- },
915
- movement_state: "MOVEMENT_STATE_MOVING"
916
- }
917
- })
918
- })
919
- );
920
- }
921
- if (socket.url.includes("/move-tcp")) {
922
- socket.dispatchEvent(
923
- new MessageEvent("message", {
924
- data: JSON.stringify({
925
- result: {
926
- motion_group: "0@ur",
927
- state: {
928
- controller: "ur",
929
- operation_mode: "OPERATION_MODE_AUTO",
930
- safety_state: "SAFETY_STATE_NORMAL",
931
- timestamp: "2024-09-18T12:43:12.188335774Z",
932
- velocity_override: 100,
933
- motion_groups: [
934
- {
935
- motion_group: "0@ur",
936
- controller: "ur",
937
- joint_position: {
938
- joints: [
939
- 1.3352527618408203,
940
- -1.5659207105636597,
941
- 1.6653711795806885,
942
- -1.110615611076355,
943
- -1.829018235206604,
944
- 1.264623761177063
945
- ]
946
- },
947
- joint_velocity: {
948
- joints: [0, 0, 0, 0, 0, 0]
949
- },
950
- flange_pose: {
951
- position: [
952
- -2.763015284002938,
953
- -630.2151479701106,
954
- 577.524509114342
955
- ],
956
- orientation: {
957
- x: -1.704794877102097,
958
- y: -1.9722372952861567,
959
- z: -0.4852079204210754
960
- },
961
- coordinate_system: ""
962
- },
963
- tcp_pose: {
964
- position: [
965
- -2.763015284002938,
966
- -630.2151479701106,
967
- 577.524509114342
968
- ],
969
- orientation: {
970
- x: -1.704794877102097,
971
- y: -1.9722372952861567,
972
- z: -0.4852079204210754
973
- },
974
- coordinate_system: "",
975
- tcp: "Flange"
976
- },
977
- velocity: {
978
- linear: {
979
- x: 0,
980
- y: 0,
981
- z: 0
982
- },
983
- angular: {
984
- x: -0,
985
- y: 0,
986
- z: 0
987
- },
988
- coordinate_system: ""
989
- },
990
- force: {
991
- force: {
992
- x: 0,
993
- y: 0,
994
- z: 0
995
- },
996
- moment: {
997
- x: 0,
998
- y: 0,
999
- z: 0
1000
- },
1001
- coordinate_system: ""
1002
- },
1003
- joint_limit_reached: {
1004
- limit_reached: [
1005
- false,
1006
- false,
1007
- false,
1008
- false,
1009
- false,
1010
- false
1011
- ]
1012
- },
1013
- joint_current: {
1014
- joints: [0, 0, 0, 0, 0, 0]
1015
- },
1016
- sequence_number: "627897"
1017
- }
1018
- ],
1019
- sequence_number: "627897"
1020
- },
1021
- movement_state: "MOVEMENT_STATE_MOVING"
1022
- }
1023
- })
1024
- })
1025
- );
1026
- }
1027
- }, 10);
1028
- }
1029
- handleWebsocketMessage(socket, message) {
1030
- console.log(`Received message on ${socket.url}`, message);
1031
- }
1032
- };
1033
- var defaultMotionState = {
1034
- result: {
1035
- motion_group: "0@universalrobots-ur5e",
1036
- controller: "universalrobots-ur5e",
1037
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1038
- sequence_number: 1,
1039
- joint_position: {
1040
- joints: [
1041
- 1.1699999570846558,
1042
- -1.5700000524520874,
1043
- 1.3600000143051147,
1044
- 1.0299999713897705,
1045
- 1.2899999618530273,
1046
- 1.2799999713897705
1047
- ]
1048
- },
1049
- joint_limit_reached: {
1050
- limit_reached: [false, false, false, false, false, false]
1051
- },
1052
- standstill: false,
1053
- flange_pose: {
1054
- position: [1.3300010259703043, -409.2680714682808, 531.0203477065281],
1055
- orientation: [
1056
- 1.7564919306270736,
1057
- -1.7542521568325058,
1058
- 0.7326972590614671
1059
- ]
1060
- },
1061
- tcp_pose: {
1062
- position: [1.3300010259703043, -409.2680714682808, 531.0203477065281],
1063
- orientation: [
1064
- 1.7564919306270736,
1065
- -1.7542521568325058,
1066
- 0.7326972590614671
1067
- ]
1068
- }
1069
- }
86
+ constructor() {
87
+ this.connections = [];
88
+ }
89
+ async handleAPIRequest(config) {
90
+ const apiHandlers = [
91
+ {
92
+ method: "GET",
93
+ path: "/cells/:cellId/controllers",
94
+ handle() {
95
+ return { controllers: [{
96
+ controller: "mock-ur5e",
97
+ model_name: "UniversalRobots::Controller",
98
+ host: "mock-ur5e",
99
+ allow_software_install_on_controller: true,
100
+ motion_groups: [{
101
+ motion_group: "0@mock-ur5e",
102
+ name_from_controller: "UR5e",
103
+ active: false,
104
+ model_from_controller: "UniversalRobots_UR5e"
105
+ }],
106
+ has_error: false,
107
+ error_details: ""
108
+ }] };
109
+ }
110
+ },
111
+ {
112
+ method: "GET",
113
+ path: "/cells/:cellId/controllers/:controllerId",
114
+ handle() {
115
+ return {
116
+ configuration: {
117
+ kind: "VirtualController",
118
+ manufacturer: "universalrobots",
119
+ type: "universalrobots-ur5e"
120
+ },
121
+ name: "mock-ur5"
122
+ };
123
+ }
124
+ },
125
+ {
126
+ method: "GET",
127
+ path: "/cells/:cellId/motion-groups/:motionGroupId/specification",
128
+ handle() {
129
+ return {
130
+ dh_parameters: [
131
+ {
132
+ alpha: 1.5707963267948966,
133
+ theta: 0,
134
+ a: 0,
135
+ d: 162.25,
136
+ reverse_rotation_direction: false
137
+ },
138
+ {
139
+ alpha: 0,
140
+ theta: 0,
141
+ a: -425,
142
+ d: 0,
143
+ reverse_rotation_direction: false
144
+ },
145
+ {
146
+ alpha: 0,
147
+ theta: 0,
148
+ a: -392.2,
149
+ d: 0,
150
+ reverse_rotation_direction: false
151
+ },
152
+ {
153
+ alpha: 1.5707963267948966,
154
+ theta: 0,
155
+ a: 0,
156
+ d: 133.3,
157
+ reverse_rotation_direction: false
158
+ },
159
+ {
160
+ alpha: -1.5707963267948966,
161
+ theta: 0,
162
+ a: 0,
163
+ d: 99.7,
164
+ reverse_rotation_direction: false
165
+ },
166
+ {
167
+ alpha: 0,
168
+ theta: 0,
169
+ a: 0,
170
+ d: 99.6,
171
+ reverse_rotation_direction: false
172
+ }
173
+ ],
174
+ mechanical_joint_limits: [
175
+ {
176
+ joint: "JOINTNAME_AXIS_1",
177
+ lower_limit: -6.335545063018799,
178
+ upper_limit: 6.335545063018799,
179
+ unlimited: false
180
+ },
181
+ {
182
+ joint: "JOINTNAME_AXIS_2",
183
+ lower_limit: -6.335545063018799,
184
+ upper_limit: 6.335545063018799,
185
+ unlimited: false
186
+ },
187
+ {
188
+ joint: "JOINTNAME_AXIS_3",
189
+ lower_limit: -6.335545063018799,
190
+ upper_limit: 6.335545063018799,
191
+ unlimited: false
192
+ },
193
+ {
194
+ joint: "JOINTNAME_AXIS_4",
195
+ lower_limit: -6.335545063018799,
196
+ upper_limit: 6.335545063018799,
197
+ unlimited: false
198
+ },
199
+ {
200
+ joint: "JOINTNAME_AXIS_5",
201
+ lower_limit: -6.335545063018799,
202
+ upper_limit: 6.335545063018799,
203
+ unlimited: false
204
+ },
205
+ {
206
+ joint: "JOINTNAME_AXIS_6",
207
+ lower_limit: -6.335545063018799,
208
+ upper_limit: 6.335545063018799,
209
+ unlimited: false
210
+ }
211
+ ]
212
+ };
213
+ }
214
+ },
215
+ {
216
+ method: "GET",
217
+ path: "/cells/:cellId/motion-groups/:motionGroupId/safety-setup",
218
+ handle() {
219
+ return {
220
+ safety_settings: [{
221
+ safety_state: "SAFETY_NORMAL",
222
+ settings: {
223
+ joint_position_limits: [
224
+ {
225
+ joint: "JOINTNAME_AXIS_1",
226
+ lower_limit: -2.96705961227417,
227
+ upper_limit: 2.96705961227417,
228
+ unlimited: false
229
+ },
230
+ {
231
+ joint: "JOINTNAME_AXIS_2",
232
+ lower_limit: -1.7453292608261108,
233
+ upper_limit: 2.7925267219543457,
234
+ unlimited: false
235
+ },
236
+ {
237
+ joint: "JOINTNAME_AXIS_3",
238
+ lower_limit: -3.3161256313323975,
239
+ upper_limit: .40142571926116943,
240
+ unlimited: false
241
+ },
242
+ {
243
+ joint: "JOINTNAME_AXIS_4",
244
+ lower_limit: -3.4906585216522217,
245
+ upper_limit: 3.4906585216522217,
246
+ unlimited: false
247
+ },
248
+ {
249
+ joint: "JOINTNAME_AXIS_5",
250
+ lower_limit: -2.4434609413146973,
251
+ upper_limit: 2.4434609413146973,
252
+ unlimited: false
253
+ },
254
+ {
255
+ joint: "JOINTNAME_AXIS_6",
256
+ lower_limit: -4.71238899230957,
257
+ upper_limit: 4.71238899230957,
258
+ unlimited: false
259
+ }
260
+ ],
261
+ joint_velocity_limits: [
262
+ {
263
+ joint: "JOINTNAME_AXIS_1",
264
+ limit: 3.1415927410125732
265
+ },
266
+ {
267
+ joint: "JOINTNAME_AXIS_2",
268
+ limit: 3.1415927410125732
269
+ },
270
+ {
271
+ joint: "JOINTNAME_AXIS_3",
272
+ limit: 3.4906585216522217
273
+ },
274
+ {
275
+ joint: "JOINTNAME_AXIS_4",
276
+ limit: 6.108652591705322
277
+ },
278
+ {
279
+ joint: "JOINTNAME_AXIS_5",
280
+ limit: 6.108652591705322
281
+ },
282
+ {
283
+ joint: "JOINTNAME_AXIS_6",
284
+ limit: 6.981317043304443
285
+ }
286
+ ],
287
+ joint_acceleration_limits: [],
288
+ joint_torque_limits: [],
289
+ tcp_velocity_limit: 1800
290
+ }
291
+ }],
292
+ safety_zones: [
293
+ {
294
+ id: 1,
295
+ priority: 0,
296
+ geometry: {
297
+ compound: { child_geometries: [
298
+ {
299
+ convex_hull: { vertices: [
300
+ { vertex: [
301
+ -800,
302
+ -1330,
303
+ -1820
304
+ ] },
305
+ { vertex: [
306
+ 1650,
307
+ -1330,
308
+ -1820
309
+ ] },
310
+ { vertex: [
311
+ 1650,
312
+ 1330,
313
+ -1820
314
+ ] },
315
+ { vertex: [
316
+ -800,
317
+ 1330,
318
+ -1820
319
+ ] }
320
+ ] },
321
+ init_pose: {
322
+ position: [
323
+ 0,
324
+ 0,
325
+ 0
326
+ ],
327
+ orientation: [
328
+ 0,
329
+ 0,
330
+ 0,
331
+ 1
332
+ ]
333
+ },
334
+ id: "box"
335
+ },
336
+ {
337
+ convex_hull: { vertices: [
338
+ { vertex: [
339
+ -800,
340
+ -1330,
341
+ -1820
342
+ ] },
343
+ { vertex: [
344
+ 1650,
345
+ -1330,
346
+ -1820
347
+ ] },
348
+ { vertex: [
349
+ 1650,
350
+ -1330,
351
+ 1500
352
+ ] },
353
+ { vertex: [
354
+ -800,
355
+ -1330,
356
+ 1500
357
+ ] }
358
+ ] },
359
+ init_pose: {
360
+ position: [
361
+ 0,
362
+ 0,
363
+ 0
364
+ ],
365
+ orientation: [
366
+ 0,
367
+ 0,
368
+ 0,
369
+ 1
370
+ ]
371
+ },
372
+ id: "box"
373
+ },
374
+ {
375
+ convex_hull: { vertices: [
376
+ { vertex: [
377
+ -800,
378
+ -1330,
379
+ -1820
380
+ ] },
381
+ { vertex: [
382
+ -800,
383
+ 1330,
384
+ -1820
385
+ ] },
386
+ { vertex: [
387
+ -800,
388
+ 1330,
389
+ 1500
390
+ ] },
391
+ { vertex: [
392
+ -800,
393
+ -1330,
394
+ 1500
395
+ ] }
396
+ ] },
397
+ init_pose: {
398
+ position: [
399
+ 0,
400
+ 0,
401
+ 0
402
+ ],
403
+ orientation: [
404
+ 0,
405
+ 0,
406
+ 0,
407
+ 1
408
+ ]
409
+ },
410
+ id: "box"
411
+ },
412
+ {
413
+ convex_hull: { vertices: [
414
+ { vertex: [
415
+ 1650,
416
+ 1330,
417
+ 1500
418
+ ] },
419
+ { vertex: [
420
+ -800,
421
+ 1330,
422
+ 1500
423
+ ] },
424
+ { vertex: [
425
+ -800,
426
+ -1330,
427
+ 1500
428
+ ] },
429
+ { vertex: [
430
+ 1650,
431
+ -1330,
432
+ 1500
433
+ ] }
434
+ ] },
435
+ init_pose: {
436
+ position: [
437
+ 0,
438
+ 0,
439
+ 0
440
+ ],
441
+ orientation: [
442
+ 0,
443
+ 0,
444
+ 0,
445
+ 1
446
+ ]
447
+ },
448
+ id: "box"
449
+ },
450
+ {
451
+ convex_hull: { vertices: [
452
+ { vertex: [
453
+ 1650,
454
+ 1330,
455
+ 1500
456
+ ] },
457
+ { vertex: [
458
+ -800,
459
+ 1330,
460
+ 1500
461
+ ] },
462
+ { vertex: [
463
+ -800,
464
+ 1330,
465
+ -1820
466
+ ] },
467
+ { vertex: [
468
+ 1650,
469
+ 1330,
470
+ -1820
471
+ ] }
472
+ ] },
473
+ init_pose: {
474
+ position: [
475
+ 0,
476
+ 0,
477
+ 0
478
+ ],
479
+ orientation: [
480
+ 0,
481
+ 0,
482
+ 0,
483
+ 1
484
+ ]
485
+ },
486
+ id: "box"
487
+ },
488
+ {
489
+ convex_hull: { vertices: [
490
+ { vertex: [
491
+ 1650,
492
+ 1330,
493
+ 1500
494
+ ] },
495
+ { vertex: [
496
+ 1650,
497
+ -1330,
498
+ 1500
499
+ ] },
500
+ { vertex: [
501
+ 1650,
502
+ -1330,
503
+ -1820
504
+ ] },
505
+ { vertex: [
506
+ 1650,
507
+ 1330,
508
+ -1820
509
+ ] }
510
+ ] },
511
+ init_pose: {
512
+ position: [
513
+ 0,
514
+ 0,
515
+ 0
516
+ ],
517
+ orientation: [
518
+ 0,
519
+ 0,
520
+ 0,
521
+ 1
522
+ ]
523
+ },
524
+ id: "box"
525
+ }
526
+ ] },
527
+ init_pose: {
528
+ position: [
529
+ 0,
530
+ 0,
531
+ 0
532
+ ],
533
+ orientation: [
534
+ 0,
535
+ 0,
536
+ 0,
537
+ 1
538
+ ]
539
+ },
540
+ id: "Cell workzone"
541
+ },
542
+ motion_group_uid: 1
543
+ },
544
+ {
545
+ id: 2,
546
+ priority: 0,
547
+ geometry: {
548
+ convex_hull: { vertices: [
549
+ { vertex: [
550
+ 1650,
551
+ 1330,
552
+ -1850
553
+ ] },
554
+ { vertex: [
555
+ 865,
556
+ 1330,
557
+ -1850
558
+ ] },
559
+ { vertex: [
560
+ 865,
561
+ -720,
562
+ -1850
563
+ ] },
564
+ { vertex: [
565
+ 1650,
566
+ -720,
567
+ -1850
568
+ ] },
569
+ { vertex: [
570
+ 1650,
571
+ 1330,
572
+ -920
573
+ ] },
574
+ { vertex: [
575
+ 865,
576
+ 1330,
577
+ -920
578
+ ] },
579
+ { vertex: [
580
+ 865,
581
+ -720,
582
+ -920
583
+ ] },
584
+ { vertex: [
585
+ 1650,
586
+ -720,
587
+ -920
588
+ ] }
589
+ ] },
590
+ init_pose: {
591
+ position: [
592
+ 0,
593
+ 0,
594
+ 0
595
+ ],
596
+ orientation: [
597
+ 0,
598
+ 0,
599
+ 0,
600
+ 1
601
+ ]
602
+ },
603
+ id: "Transport"
604
+ },
605
+ motion_group_uid: 1
606
+ },
607
+ {
608
+ id: 3,
609
+ priority: 0,
610
+ geometry: {
611
+ convex_hull: { vertices: [
612
+ { vertex: [
613
+ 1650,
614
+ 1330,
615
+ -600
616
+ ] },
617
+ { vertex: [
618
+ 865,
619
+ 1330,
620
+ -600
621
+ ] },
622
+ { vertex: [
623
+ 865,
624
+ 430,
625
+ -600
626
+ ] },
627
+ { vertex: [
628
+ 1650,
629
+ 430,
630
+ -600
631
+ ] },
632
+ { vertex: [
633
+ 1650,
634
+ 1330,
635
+ -1250
636
+ ] },
637
+ { vertex: [
638
+ 865,
639
+ 1330,
640
+ -1250
641
+ ] },
642
+ { vertex: [
643
+ 865,
644
+ 430,
645
+ -1250
646
+ ] },
647
+ { vertex: [
648
+ 1650,
649
+ 430,
650
+ -1250
651
+ ] }
652
+ ] },
653
+ init_pose: {
654
+ position: [
655
+ 0,
656
+ 0,
657
+ 0
658
+ ],
659
+ orientation: [
660
+ 0,
661
+ 0,
662
+ 0,
663
+ 1
664
+ ]
665
+ },
666
+ id: "Tunel"
667
+ },
668
+ motion_group_uid: 1
669
+ },
670
+ {
671
+ id: 4,
672
+ priority: 0,
673
+ geometry: {
674
+ convex_hull: { vertices: [
675
+ { vertex: [
676
+ 1650,
677
+ -760,
678
+ -440
679
+ ] },
680
+ { vertex: [
681
+ 900,
682
+ -760,
683
+ -440
684
+ ] },
685
+ { vertex: [
686
+ 900,
687
+ -1330,
688
+ -440
689
+ ] },
690
+ { vertex: [
691
+ 1650,
692
+ -1330,
693
+ -440
694
+ ] },
695
+ { vertex: [
696
+ 1650,
697
+ -760,
698
+ -1800
699
+ ] },
700
+ { vertex: [
701
+ 900,
702
+ -760,
703
+ -1800
704
+ ] },
705
+ { vertex: [
706
+ 900,
707
+ -1330,
708
+ -1800
709
+ ] },
710
+ { vertex: [
711
+ 1650,
712
+ -1330,
713
+ -1800
714
+ ] }
715
+ ] },
716
+ init_pose: {
717
+ position: [
718
+ 0,
719
+ 0,
720
+ 0
721
+ ],
722
+ orientation: [
723
+ 0,
724
+ 0,
725
+ 0,
726
+ 1
727
+ ]
728
+ },
729
+ id: "Fanuc controller"
730
+ },
731
+ motion_group_uid: 1
732
+ },
733
+ {
734
+ id: 6,
735
+ priority: 0,
736
+ geometry: {
737
+ convex_hull: { vertices: [
738
+ { vertex: [
739
+ -200,
740
+ -200,
741
+ -1900
742
+ ] },
743
+ { vertex: [
744
+ 200,
745
+ -200,
746
+ -1900
747
+ ] },
748
+ { vertex: [
749
+ 200,
750
+ 200,
751
+ -1900
752
+ ] },
753
+ { vertex: [
754
+ -200,
755
+ 200,
756
+ -1900
757
+ ] },
758
+ { vertex: [
759
+ -200,
760
+ -200,
761
+ -350
762
+ ] },
763
+ { vertex: [
764
+ 200,
765
+ -200,
766
+ -350
767
+ ] },
768
+ { vertex: [
769
+ 200,
770
+ 200,
771
+ -350
772
+ ] },
773
+ { vertex: [
774
+ -200,
775
+ 200,
776
+ -350
777
+ ] }
778
+ ] },
779
+ init_pose: {
780
+ position: [
781
+ 0,
782
+ 0,
783
+ 0
784
+ ],
785
+ orientation: [
786
+ 0,
787
+ 0,
788
+ 0,
789
+ 1
790
+ ]
791
+ },
792
+ id: "Robot base"
793
+ },
794
+ motion_group_uid: 1
795
+ }
796
+ ],
797
+ robot_model_geometries: [
798
+ {
799
+ link_index: 1,
800
+ geometry: {
801
+ sphere: { radius: 270 },
802
+ init_pose: {
803
+ position: [
804
+ -70,
805
+ -70,
806
+ -50
807
+ ],
808
+ orientation: [
809
+ 0,
810
+ 0,
811
+ 0,
812
+ 1
813
+ ]
814
+ },
815
+ id: "link1_sphere"
816
+ }
817
+ },
818
+ {
819
+ link_index: 2,
820
+ geometry: {
821
+ capsule: {
822
+ radius: 160,
823
+ cylinder_height: 800
824
+ },
825
+ init_pose: {
826
+ position: [
827
+ -450,
828
+ 40,
829
+ 170
830
+ ],
831
+ orientation: [
832
+ 0,
833
+ -Math.SQRT1_2,
834
+ 0,
835
+ Math.SQRT1_2
836
+ ]
837
+ },
838
+ id: "link2_capsule"
839
+ }
840
+ },
841
+ {
842
+ link_index: 3,
843
+ geometry: {
844
+ sphere: { radius: 270 },
845
+ init_pose: {
846
+ position: [
847
+ -110,
848
+ 10,
849
+ -100
850
+ ],
851
+ orientation: [
852
+ 0,
853
+ 0,
854
+ 0,
855
+ 1
856
+ ]
857
+ },
858
+ id: "link3_sphere"
859
+ }
860
+ },
861
+ {
862
+ link_index: 4,
863
+ geometry: {
864
+ capsule: {
865
+ radius: 110,
866
+ cylinder_height: 600
867
+ },
868
+ init_pose: {
869
+ position: [
870
+ 0,
871
+ 300,
872
+ 40
873
+ ],
874
+ orientation: [
875
+ -Math.SQRT1_2,
876
+ 0,
877
+ 0,
878
+ Math.SQRT1_2
879
+ ]
880
+ },
881
+ id: "link4_capsule"
882
+ }
883
+ },
884
+ {
885
+ link_index: 5,
886
+ geometry: {
887
+ sphere: { radius: 75 },
888
+ init_pose: {
889
+ position: [
890
+ 0,
891
+ 0,
892
+ -50
893
+ ],
894
+ orientation: [
895
+ 0,
896
+ 0,
897
+ 0,
898
+ 1
899
+ ]
900
+ },
901
+ id: "link5_sphere"
902
+ }
903
+ }
904
+ ],
905
+ tool_geometries: []
906
+ };
907
+ }
908
+ },
909
+ {
910
+ method: "GET",
911
+ path: "/cells/:cellId/coordinate-systems",
912
+ handle() {
913
+ return { coordinatesystems: [{
914
+ coordinate_system: "",
915
+ name: "world",
916
+ reference_uid: "",
917
+ position: [
918
+ 0,
919
+ 0,
920
+ 0
921
+ ],
922
+ rotation: {
923
+ angles: [
924
+ 0,
925
+ 0,
926
+ 0
927
+ ],
928
+ type: "ROTATION_VECTOR"
929
+ }
930
+ }] };
931
+ }
932
+ },
933
+ {
934
+ method: "GET",
935
+ path: "/cells/:cellId/motion-groups/:motionGroupId/tcps",
936
+ handle() {
937
+ return { tcps: [{
938
+ id: "Flange",
939
+ readable_name: "Default-Flange",
940
+ position: [
941
+ 0,
942
+ 0,
943
+ 0
944
+ ],
945
+ rotation: {
946
+ angles: [
947
+ 0,
948
+ 0,
949
+ 0,
950
+ 0
951
+ ],
952
+ type: "ROTATION_VECTOR"
953
+ }
954
+ }, {
955
+ id: "complex-tcp-position",
956
+ readable_name: "Complex TCP Position",
957
+ position: [
958
+ -200,
959
+ 300,
960
+ 150
961
+ ],
962
+ rotation: {
963
+ angles: [
964
+ -.12139440409113832,
965
+ -.06356210998212003,
966
+ -.2023240068185639,
967
+ 0
968
+ ],
969
+ type: "ROTATION_VECTOR"
970
+ }
971
+ }] };
972
+ }
973
+ }
974
+ ];
975
+ const method = config.method?.toUpperCase() || "GET";
976
+ const path = `/cells${config.url?.split("/cells")[1]?.split("?")[0]}`;
977
+ for (const handler of apiHandlers) {
978
+ const match = pathToRegexp.match(handler.path)(path || "");
979
+ if (method === handler.method && match) {
980
+ const json = handler.handle();
981
+ return {
982
+ status: 200,
983
+ statusText: "Success",
984
+ data: JSON.stringify(json),
985
+ headers: {},
986
+ config,
987
+ request: { responseURL: config.url }
988
+ };
989
+ }
990
+ }
991
+ throw new AxiosError(`No mock handler matched this request: ${method} ${path}`, "404", config);
992
+ }
993
+ handleWebsocketConnection(socket) {
994
+ this.connections.push(socket);
995
+ setTimeout(() => {
996
+ socket.dispatchEvent(new Event("open"));
997
+ console.log("Websocket connection opened from", socket.url);
998
+ if (socket.url.includes("/state-stream")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify(defaultMotionState) }));
999
+ if (socket.url.includes("/move-joint")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify({ result: {
1000
+ motion_group: "0@ur",
1001
+ state: {
1002
+ controller: "ur",
1003
+ operation_mode: "OPERATION_MODE_AUTO",
1004
+ safety_state: "SAFETY_STATE_NORMAL",
1005
+ timestamp: "2024-09-18T12:48:26.096266444Z",
1006
+ velocity_override: 100,
1007
+ motion_groups: [{
1008
+ motion_group: "0@ur",
1009
+ controller: "ur",
1010
+ joint_position: [
1011
+ 1.3492152690887451,
1012
+ -1.5659207105636597,
1013
+ 1.6653711795806885,
1014
+ -1.0991662740707397,
1015
+ -1.829018235206604,
1016
+ 1.264623761177063
1017
+ ],
1018
+ joint_velocity: { joints: [
1019
+ 0,
1020
+ 0,
1021
+ 0,
1022
+ 0,
1023
+ 0,
1024
+ 0
1025
+ ] },
1026
+ flange_pose: {
1027
+ position: [
1028
+ 6.437331889439328,
1029
+ -628.4123774830913,
1030
+ 577.0569957147832
1031
+ ],
1032
+ orientation: {
1033
+ x: -1.683333649797158,
1034
+ y: -1.9783363827298732,
1035
+ z: -.4928031860165713
1036
+ },
1037
+ coordinate_system: ""
1038
+ },
1039
+ tcp_pose: {
1040
+ position: [
1041
+ 6.437331889439328,
1042
+ -628.4123774830913,
1043
+ 577.0569957147832
1044
+ ],
1045
+ orientation: {
1046
+ x: -1.683333649797158,
1047
+ y: -1.9783363827298732,
1048
+ z: -.4928031860165713
1049
+ },
1050
+ coordinate_system: "",
1051
+ tcp: "Flange"
1052
+ },
1053
+ velocity: {
1054
+ linear: {
1055
+ x: 0,
1056
+ y: 0,
1057
+ z: 0
1058
+ },
1059
+ angular: {
1060
+ x: -0,
1061
+ y: 0,
1062
+ z: 0
1063
+ },
1064
+ coordinate_system: ""
1065
+ },
1066
+ force: {
1067
+ force: {
1068
+ x: 0,
1069
+ y: 0,
1070
+ z: 0
1071
+ },
1072
+ moment: {
1073
+ x: 0,
1074
+ y: 0,
1075
+ z: 0
1076
+ },
1077
+ coordinate_system: ""
1078
+ },
1079
+ joint_limit_reached: { limit_reached: [
1080
+ false,
1081
+ false,
1082
+ false,
1083
+ false,
1084
+ false,
1085
+ false
1086
+ ] },
1087
+ joint_current: { joints: [
1088
+ 0,
1089
+ 0,
1090
+ 0,
1091
+ 0,
1092
+ 0,
1093
+ 0
1094
+ ] },
1095
+ sequence_number: "671259"
1096
+ }],
1097
+ sequence_number: "671259"
1098
+ },
1099
+ movement_state: "MOVEMENT_STATE_MOVING"
1100
+ } }) }));
1101
+ if (socket.url.includes("/move-tcp")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify({ result: {
1102
+ motion_group: "0@ur",
1103
+ state: {
1104
+ controller: "ur",
1105
+ operation_mode: "OPERATION_MODE_AUTO",
1106
+ safety_state: "SAFETY_STATE_NORMAL",
1107
+ timestamp: "2024-09-18T12:43:12.188335774Z",
1108
+ velocity_override: 100,
1109
+ motion_groups: [{
1110
+ motion_group: "0@ur",
1111
+ controller: "ur",
1112
+ joint_position: { joints: [
1113
+ 1.3352527618408203,
1114
+ -1.5659207105636597,
1115
+ 1.6653711795806885,
1116
+ -1.110615611076355,
1117
+ -1.829018235206604,
1118
+ 1.264623761177063
1119
+ ] },
1120
+ joint_velocity: { joints: [
1121
+ 0,
1122
+ 0,
1123
+ 0,
1124
+ 0,
1125
+ 0,
1126
+ 0
1127
+ ] },
1128
+ flange_pose: {
1129
+ position: [
1130
+ -2.763015284002938,
1131
+ -630.2151479701106,
1132
+ 577.524509114342
1133
+ ],
1134
+ orientation: {
1135
+ x: -1.704794877102097,
1136
+ y: -1.9722372952861567,
1137
+ z: -.4852079204210754
1138
+ },
1139
+ coordinate_system: ""
1140
+ },
1141
+ tcp_pose: {
1142
+ position: [
1143
+ -2.763015284002938,
1144
+ -630.2151479701106,
1145
+ 577.524509114342
1146
+ ],
1147
+ orientation: {
1148
+ x: -1.704794877102097,
1149
+ y: -1.9722372952861567,
1150
+ z: -.4852079204210754
1151
+ },
1152
+ coordinate_system: "",
1153
+ tcp: "Flange"
1154
+ },
1155
+ velocity: {
1156
+ linear: {
1157
+ x: 0,
1158
+ y: 0,
1159
+ z: 0
1160
+ },
1161
+ angular: {
1162
+ x: -0,
1163
+ y: 0,
1164
+ z: 0
1165
+ },
1166
+ coordinate_system: ""
1167
+ },
1168
+ force: {
1169
+ force: {
1170
+ x: 0,
1171
+ y: 0,
1172
+ z: 0
1173
+ },
1174
+ moment: {
1175
+ x: 0,
1176
+ y: 0,
1177
+ z: 0
1178
+ },
1179
+ coordinate_system: ""
1180
+ },
1181
+ joint_limit_reached: { limit_reached: [
1182
+ false,
1183
+ false,
1184
+ false,
1185
+ false,
1186
+ false,
1187
+ false
1188
+ ] },
1189
+ joint_current: { joints: [
1190
+ 0,
1191
+ 0,
1192
+ 0,
1193
+ 0,
1194
+ 0,
1195
+ 0
1196
+ ] },
1197
+ sequence_number: "627897"
1198
+ }],
1199
+ sequence_number: "627897"
1200
+ },
1201
+ movement_state: "MOVEMENT_STATE_MOVING"
1202
+ } }) }));
1203
+ }, 10);
1204
+ }
1205
+ handleWebsocketMessage(socket, message) {
1206
+ console.log(`Received message on ${socket.url}`, message);
1207
+ }
1070
1208
  };
1209
+ const defaultMotionState = { result: {
1210
+ motion_group: "0@universalrobots-ur5e",
1211
+ controller: "universalrobots-ur5e",
1212
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1213
+ sequence_number: 1,
1214
+ joint_position: [
1215
+ 1.1699999570846558,
1216
+ -1.5700000524520874,
1217
+ 1.3600000143051147,
1218
+ 1.0299999713897705,
1219
+ 1.2899999618530273,
1220
+ 1.2799999713897705
1221
+ ],
1222
+ joint_limit_reached: { limit_reached: [
1223
+ false,
1224
+ false,
1225
+ false,
1226
+ false,
1227
+ false,
1228
+ false
1229
+ ] },
1230
+ standstill: false,
1231
+ flange_pose: {
1232
+ position: [
1233
+ 1.3300010259703043,
1234
+ -409.2680714682808,
1235
+ 531.0203477065281
1236
+ ],
1237
+ orientation: [
1238
+ 1.7564919306270736,
1239
+ -1.7542521568325058,
1240
+ .7326972590614671
1241
+ ]
1242
+ },
1243
+ tcp_pose: {
1244
+ position: [
1245
+ 1.3300010259703043,
1246
+ -409.2680714682808,
1247
+ 531.0203477065281
1248
+ ],
1249
+ orientation: [
1250
+ 1.7564919306270736,
1251
+ -1.7542521568325058,
1252
+ .7326972590614671
1253
+ ]
1254
+ }
1255
+ } };
1071
1256
 
1072
- // src/lib/v2/NovaClient.ts
1257
+ //#endregion
1258
+ //#region src/lib/v2/NovaClient.ts
1259
+ /**
1260
+ * EXPERIMENTAL
1261
+ *
1262
+ * This client provides a starting point to migrate NOVA api v2.
1263
+ * As v2 is still in development, this client has to be considered unstable
1264
+ *
1265
+ * Client for connecting to a Nova instance and controlling robots.
1266
+ */
1073
1267
  var NovaClient = class {
1074
- constructor(config) {
1075
- this.authPromise = null;
1076
- this.accessToken = null;
1077
- var _a;
1078
- console.warn("Using experimental NOVA v2 client");
1079
- const cellId = (_a = config.cellId) != null ? _a : "cell";
1080
- this.config = __spreadValues({
1081
- cellId
1082
- }, config);
1083
- this.accessToken = config.accessToken || availableStorage.getString("wbjs.access_token") || null;
1084
- if (this.config.instanceUrl === "https://mock.example.com") {
1085
- this.mock = new MockNovaInstance();
1086
- }
1087
- const axiosInstance = axios2.create({
1088
- baseURL: urlJoin(this.config.instanceUrl, "/api/v2"),
1089
- // TODO - backend needs to set proper CORS headers for this
1090
- headers: typeof window !== "undefined" && window.location.origin.includes("localhost") ? {} : {
1091
- // Identify the client to the backend for logging purposes
1092
- "X-Wandelbots-Client": "Wandelbots-Nova-JS-SDK"
1093
- }
1094
- });
1095
- axiosInstance.interceptors.request.use((request) => __async(this, null, function* () {
1096
- if (!request.headers.Authorization) {
1097
- if (this.accessToken) {
1098
- request.headers.Authorization = `Bearer ${this.accessToken}`;
1099
- } else if (this.config.username && this.config.password) {
1100
- request.headers.Authorization = `Basic ${btoa(`${config.username}:${config.password}`)}`;
1101
- }
1102
- }
1103
- return request;
1104
- }));
1105
- if (typeof window !== "undefined") {
1106
- axiosInstance.interceptors.response.use(
1107
- (r) => r,
1108
- (error) => __async(this, null, function* () {
1109
- var _a2, _b;
1110
- if (isAxiosError(error)) {
1111
- if (((_a2 = error.response) == null ? void 0 : _a2.status) === 401) {
1112
- try {
1113
- yield this.renewAuthentication();
1114
- if (error.config) {
1115
- if (this.accessToken) {
1116
- error.config.headers.Authorization = `Bearer ${this.accessToken}`;
1117
- } else {
1118
- delete error.config.headers.Authorization;
1119
- }
1120
- return axiosInstance.request(error.config);
1121
- }
1122
- } catch (err) {
1123
- return Promise.reject(err);
1124
- }
1125
- } else if (((_b = error.response) == null ? void 0 : _b.status) === 503) {
1126
- const res = yield fetch(window.location.href);
1127
- if (res.status === 503) {
1128
- window.location.reload();
1129
- }
1130
- }
1131
- }
1132
- return Promise.reject(error);
1133
- })
1134
- );
1135
- }
1136
- this.api = new NovaCellAPIClient(cellId, __spreadProps(__spreadValues({}, config), {
1137
- basePath: urlJoin(this.config.instanceUrl, "/api/v1"),
1138
- isJsonMime: (mime) => {
1139
- return mime === "application/json";
1140
- },
1141
- baseOptions: __spreadValues(__spreadValues({}, this.mock ? {
1142
- adapter: (config2) => {
1143
- return this.mock.handleAPIRequest(config2);
1144
- }
1145
- } : {}), config.baseOptions),
1146
- axiosInstance
1147
- }));
1148
- }
1149
- renewAuthentication() {
1150
- return __async(this, null, function* () {
1151
- if (this.authPromise) {
1152
- return;
1153
- }
1154
- this.authPromise = loginWithAuth0(this.config.instanceUrl);
1155
- try {
1156
- this.accessToken = yield this.authPromise;
1157
- if (this.accessToken) {
1158
- availableStorage.setString("wbjs.access_token", this.accessToken);
1159
- } else {
1160
- availableStorage.delete("wbjs.access_token");
1161
- }
1162
- } finally {
1163
- this.authPromise = null;
1164
- }
1165
- });
1166
- }
1167
- makeWebsocketURL(path) {
1168
- const url = new URL(
1169
- urlJoin(
1170
- this.config.instanceUrl,
1171
- `/api/v1/cells/${this.config.cellId}`,
1172
- path
1173
- )
1174
- );
1175
- url.protocol = url.protocol.replace("http", "ws");
1176
- url.protocol = url.protocol.replace("https", "wss");
1177
- if (this.accessToken) {
1178
- url.searchParams.append("token", this.accessToken);
1179
- } else if (this.config.username && this.config.password) {
1180
- url.username = this.config.username;
1181
- url.password = this.config.password;
1182
- }
1183
- return url.toString();
1184
- }
1185
- /**
1186
- * Retrieve an AutoReconnectingWebsocket to the given path on the Nova instance.
1187
- * If you explicitly want to reconnect an existing websocket, call `reconnect`
1188
- * on the returned object.
1189
- */
1190
- openReconnectingWebsocket(path) {
1191
- return new AutoReconnectingWebsocket(this.makeWebsocketURL(path), {
1192
- mock: this.mock
1193
- });
1194
- }
1195
- };
1196
- export {
1197
- NovaCellAPIClient,
1198
- NovaClient
1268
+ constructor(config) {
1269
+ this.authPromise = null;
1270
+ this.accessToken = null;
1271
+ console.warn("Using experimental NOVA v2 client");
1272
+ const cellId = config.cellId ?? "cell";
1273
+ this.config = {
1274
+ cellId,
1275
+ ...config
1276
+ };
1277
+ this.accessToken = config.accessToken || availableStorage.getString("wbjs.access_token") || null;
1278
+ if (this.config.instanceUrl === "https://mock.example.com") this.mock = new MockNovaInstance();
1279
+ const axiosInstance = axios.create({
1280
+ baseURL: urlJoin(this.config.instanceUrl, "/api/v2"),
1281
+ headers: typeof window !== "undefined" && window.location.origin.includes("localhost") ? {} : { "X-Wandelbots-Client": "Wandelbots-Nova-JS-SDK" }
1282
+ });
1283
+ axiosInstance.interceptors.request.use(async (request) => {
1284
+ if (!request.headers.Authorization) {
1285
+ if (this.accessToken) request.headers.Authorization = `Bearer ${this.accessToken}`;
1286
+ else if (this.config.username && this.config.password) request.headers.Authorization = `Basic ${btoa(`${config.username}:${config.password}`)}`;
1287
+ }
1288
+ return request;
1289
+ });
1290
+ if (typeof window !== "undefined") axiosInstance.interceptors.response.use((r) => r, async (error) => {
1291
+ if (isAxiosError(error)) {
1292
+ if (error.response?.status === 401) try {
1293
+ await this.renewAuthentication();
1294
+ if (error.config) {
1295
+ if (this.accessToken) error.config.headers.Authorization = `Bearer ${this.accessToken}`;
1296
+ else delete error.config.headers.Authorization;
1297
+ return axiosInstance.request(error.config);
1298
+ }
1299
+ } catch (err) {
1300
+ return Promise.reject(err);
1301
+ }
1302
+ else if (error.response?.status === 503) {
1303
+ if ((await fetch(window.location.href)).status === 503) window.location.reload();
1304
+ }
1305
+ }
1306
+ return Promise.reject(error);
1307
+ });
1308
+ this.api = new NovaCellAPIClient(cellId, {
1309
+ ...config,
1310
+ basePath: urlJoin(this.config.instanceUrl, "/api/v1"),
1311
+ isJsonMime: (mime) => {
1312
+ return mime === "application/json";
1313
+ },
1314
+ baseOptions: {
1315
+ ...this.mock ? { adapter: (config$1) => {
1316
+ return this.mock.handleAPIRequest(config$1);
1317
+ } } : {},
1318
+ ...config.baseOptions
1319
+ },
1320
+ axiosInstance
1321
+ });
1322
+ }
1323
+ async renewAuthentication() {
1324
+ if (this.authPromise) return;
1325
+ this.authPromise = loginWithAuth0(this.config.instanceUrl);
1326
+ try {
1327
+ this.accessToken = await this.authPromise;
1328
+ if (this.accessToken) availableStorage.setString("wbjs.access_token", this.accessToken);
1329
+ else availableStorage.delete("wbjs.access_token");
1330
+ } finally {
1331
+ this.authPromise = null;
1332
+ }
1333
+ }
1334
+ makeWebsocketURL(path) {
1335
+ const url = new URL(urlJoin(this.config.instanceUrl, `/api/v1/cells/${this.config.cellId}`, path));
1336
+ url.protocol = url.protocol.replace("http", "ws");
1337
+ url.protocol = url.protocol.replace("https", "wss");
1338
+ if (this.accessToken) url.searchParams.append("token", this.accessToken);
1339
+ else if (this.config.username && this.config.password) {
1340
+ url.username = this.config.username;
1341
+ url.password = this.config.password;
1342
+ }
1343
+ return url.toString();
1344
+ }
1345
+ /**
1346
+ * Retrieve an AutoReconnectingWebsocket to the given path on the Nova instance.
1347
+ * If you explicitly want to reconnect an existing websocket, call `reconnect`
1348
+ * on the returned object.
1349
+ */
1350
+ openReconnectingWebsocket(path) {
1351
+ return new AutoReconnectingWebsocket(this.makeWebsocketURL(path), { mock: this.mock });
1352
+ }
1199
1353
  };
1354
+
1355
+ //#endregion
1356
+ export { NovaCellAPIClient, NovaClient };
1200
1357
  //# sourceMappingURL=index.js.map