@wandelbots/nova-js 3.2.0 → 3.3.0-pr.fix-mock-v2.176.43cb4cc

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 (104) hide show
  1. package/README.md +32 -136
  2. package/dist/AutoReconnectingWebsocket-Qcrbm3Kb.d.cts +69 -0
  3. package/dist/AutoReconnectingWebsocket-Qcrbm3Kb.d.cts.map +1 -0
  4. package/dist/AutoReconnectingWebsocket-dHe-kceU.d.mts +69 -0
  5. package/dist/AutoReconnectingWebsocket-dHe-kceU.d.mts.map +1 -0
  6. package/dist/LoginWithAuth0-CBD9BXXz.cjs +264 -0
  7. package/dist/LoginWithAuth0-CBD9BXXz.cjs.map +1 -0
  8. package/dist/LoginWithAuth0-wQB-Sol1.mjs +217 -0
  9. package/dist/LoginWithAuth0-wQB-Sol1.mjs.map +1 -0
  10. package/dist/NovaClient-B8XM3OPO.mjs +2057 -0
  11. package/dist/NovaClient-B8XM3OPO.mjs.map +1 -0
  12. package/dist/NovaClient-CV7ooIkD.d.cts +349 -0
  13. package/dist/NovaClient-CV7ooIkD.d.cts.map +1 -0
  14. package/dist/NovaClient-D2EItmiH.cjs +2137 -0
  15. package/dist/NovaClient-D2EItmiH.cjs.map +1 -0
  16. package/dist/NovaClient-qJnHcx2s.d.mts +349 -0
  17. package/dist/NovaClient-qJnHcx2s.d.mts.map +1 -0
  18. package/dist/index.cjs +42 -386
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +73 -0
  21. package/dist/index.d.cts.map +1 -0
  22. package/dist/index.d.mts +73 -0
  23. package/dist/index.d.mts.map +1 -0
  24. package/dist/index.mjs +36 -0
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/lib/v1/index.cjs +190 -2940
  27. package/dist/lib/v1/index.cjs.map +1 -1
  28. package/dist/lib/v1/index.d.cts +62 -0
  29. package/dist/lib/v1/index.d.cts.map +1 -0
  30. package/dist/lib/v1/index.d.mts +62 -0
  31. package/dist/lib/v1/index.d.mts.map +1 -0
  32. package/dist/lib/v1/index.mjs +182 -0
  33. package/dist/lib/v1/index.mjs.map +1 -0
  34. package/dist/lib/v2/index.cjs +737 -1468
  35. package/dist/lib/v2/index.cjs.map +1 -1
  36. package/dist/lib/v2/index.d.cts +118 -0
  37. package/dist/lib/v2/index.d.cts.map +1 -0
  38. package/dist/lib/v2/index.d.mts +118 -0
  39. package/dist/lib/v2/index.d.mts.map +1 -0
  40. package/dist/lib/v2/index.mjs +738 -0
  41. package/dist/lib/v2/index.mjs.map +1 -0
  42. package/package.json +21 -19
  43. package/src/LoginWithAuth0.ts +12 -12
  44. package/src/index.ts +2 -0
  45. package/src/lib/converters.ts +5 -23
  46. package/src/lib/v1/MotionStreamConnection.ts +0 -1
  47. package/src/lib/v1/NovaClient.ts +18 -0
  48. package/src/lib/v1/index.ts +6 -0
  49. package/src/lib/v1/mock/MockNovaInstance.ts +0 -1
  50. package/src/lib/v1/wandelscriptUtils.ts +22 -0
  51. package/src/lib/v2/NovaClient.ts +14 -7
  52. package/src/lib/v2/index.ts +1 -0
  53. package/src/lib/v2/mock/MockNovaInstance.ts +324 -747
  54. package/src/lib/v2/wandelscriptUtils.ts +27 -0
  55. package/dist/LoginWithAuth0.d.ts +0 -7
  56. package/dist/LoginWithAuth0.d.ts.map +0 -1
  57. package/dist/chunk-B2C22PTK.js +0 -53
  58. package/dist/chunk-B2C22PTK.js.map +0 -1
  59. package/dist/chunk-I3PUV6ZD.js +0 -286
  60. package/dist/chunk-I3PUV6ZD.js.map +0 -1
  61. package/dist/index.d.ts +0 -6
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/index.js +0 -60
  64. package/dist/index.js.map +0 -1
  65. package/dist/lib/AutoReconnectingWebsocket.d.ts +0 -43
  66. package/dist/lib/AutoReconnectingWebsocket.d.ts.map +0 -1
  67. package/dist/lib/availableStorage.d.ts +0 -15
  68. package/dist/lib/availableStorage.d.ts.map +0 -1
  69. package/dist/lib/converters.d.ts +0 -26
  70. package/dist/lib/converters.d.ts.map +0 -1
  71. package/dist/lib/errorHandling.d.ts +0 -15
  72. package/dist/lib/errorHandling.d.ts.map +0 -1
  73. package/dist/lib/v1/ConnectedMotionGroup.d.ts +0 -77
  74. package/dist/lib/v1/ConnectedMotionGroup.d.ts.map +0 -1
  75. package/dist/lib/v1/JoggerConnection.d.ts +0 -94
  76. package/dist/lib/v1/JoggerConnection.d.ts.map +0 -1
  77. package/dist/lib/v1/MotionStreamConnection.d.ts +0 -26
  78. package/dist/lib/v1/MotionStreamConnection.d.ts.map +0 -1
  79. package/dist/lib/v1/NovaCellAPIClient.d.ts +0 -68
  80. package/dist/lib/v1/NovaCellAPIClient.d.ts.map +0 -1
  81. package/dist/lib/v1/NovaClient.d.ts +0 -67
  82. package/dist/lib/v1/NovaClient.d.ts.map +0 -1
  83. package/dist/lib/v1/ProgramStateConnection.d.ts +0 -57
  84. package/dist/lib/v1/ProgramStateConnection.d.ts.map +0 -1
  85. package/dist/lib/v1/getLatestTrajectories.d.ts +0 -4
  86. package/dist/lib/v1/getLatestTrajectories.d.ts.map +0 -1
  87. package/dist/lib/v1/index.d.ts +0 -9
  88. package/dist/lib/v1/index.d.ts.map +0 -1
  89. package/dist/lib/v1/index.js +0 -2653
  90. package/dist/lib/v1/index.js.map +0 -1
  91. package/dist/lib/v1/mock/MockNovaInstance.d.ts +0 -13
  92. package/dist/lib/v1/mock/MockNovaInstance.d.ts.map +0 -1
  93. package/dist/lib/v1/motionStateUpdate.d.ts +0 -4
  94. package/dist/lib/v1/motionStateUpdate.d.ts.map +0 -1
  95. package/dist/lib/v2/NovaCellAPIClient.d.ts +0 -62
  96. package/dist/lib/v2/NovaCellAPIClient.d.ts.map +0 -1
  97. package/dist/lib/v2/NovaClient.d.ts +0 -60
  98. package/dist/lib/v2/NovaClient.d.ts.map +0 -1
  99. package/dist/lib/v2/index.d.ts +0 -4
  100. package/dist/lib/v2/index.d.ts.map +0 -1
  101. package/dist/lib/v2/index.js +0 -1196
  102. package/dist/lib/v2/index.js.map +0 -1
  103. package/dist/lib/v2/mock/MockNovaInstance.d.ts +0 -13
  104. package/dist/lib/v2/mock/MockNovaInstance.d.ts.map +0 -1
@@ -0,0 +1,738 @@
1
+ import { n as availableStorage, r as AutoReconnectingWebsocket, t as loginWithAuth0 } from "../../LoginWithAuth0-wQB-Sol1.mjs";
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";
6
+
7
+ export * from "@wandelbots/nova-api/v2"
8
+
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
+ */
14
+ var NovaCellAPIClient = class {
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
+ }
77
+ };
78
+
79
+ //#endregion
80
+ //#region src/lib/v2/mock/MockNovaInstance.ts
81
+ /**
82
+ * Ultra-simplified mock Nova server for testing stuff
83
+ */
84
+ var MockNovaInstance = class {
85
+ constructor() {
86
+ this.connections = [];
87
+ }
88
+ async handleAPIRequest(config) {
89
+ const apiHandlers = [
90
+ {
91
+ method: "GET",
92
+ path: "/cells/:cellId/controllers",
93
+ handle() {
94
+ return ["mock-ur5e"];
95
+ }
96
+ },
97
+ {
98
+ method: "GET",
99
+ path: "/cells/:cellId/controllers/:controllerId",
100
+ handle() {
101
+ return {
102
+ configuration: {
103
+ initial_joint_position: "[0,-1.571,-1.571,-1.571,1.571,-1.571,0]",
104
+ kind: "VirtualController",
105
+ manufacturer: "universalrobots",
106
+ type: "universalrobots-ur5e"
107
+ },
108
+ name: "mock-ur5"
109
+ };
110
+ }
111
+ },
112
+ {
113
+ method: "GET",
114
+ path: "/cells/:cellId/controllers/:controllerId/state",
115
+ handle() {
116
+ return {
117
+ mode: "MODE_CONTROL",
118
+ last_error: [],
119
+ timestamp: "2025-10-16T09:19:26.634534092Z",
120
+ sequence_number: 1054764,
121
+ controller: "mock-ur5e",
122
+ operation_mode: "OPERATION_MODE_AUTO",
123
+ safety_state: "SAFETY_STATE_NORMAL",
124
+ velocity_override: 100,
125
+ motion_groups: [{
126
+ timestamp: "2025-10-16T09:19:26.634534092Z",
127
+ sequence_number: 1054764,
128
+ motion_group: "0@mock-ur5e",
129
+ controller: "mock-ur5e",
130
+ joint_position: [
131
+ 1.487959623336792,
132
+ -1.8501918315887451,
133
+ 1.8003005981445312,
134
+ 6.034560203552246,
135
+ 1.4921919107437134,
136
+ 1.593459963798523
137
+ ],
138
+ joint_limit_reached: { limit_reached: [
139
+ false,
140
+ false,
141
+ false,
142
+ false,
143
+ false,
144
+ false
145
+ ] },
146
+ joint_torque: [],
147
+ joint_current: [
148
+ 0,
149
+ 0,
150
+ 0,
151
+ 0,
152
+ 0,
153
+ 0
154
+ ],
155
+ flange_pose: {
156
+ position: [
157
+ 107.6452433732927,
158
+ -409.0402987746852,
159
+ 524.2402132330305
160
+ ],
161
+ orientation: [
162
+ .9874434028353319,
163
+ -.986571714997442,
164
+ 1.3336589451098142
165
+ ]
166
+ },
167
+ tcp: "Flange",
168
+ tcp_pose: {
169
+ position: [
170
+ 107.6452433732927,
171
+ -409.0402987746852,
172
+ 524.2402132330305
173
+ ],
174
+ orientation: [
175
+ .9874434028353319,
176
+ -.986571714997442,
177
+ 1.3336589451098142
178
+ ]
179
+ },
180
+ payload: "",
181
+ coordinate_system: "",
182
+ standstill: true
183
+ }]
184
+ };
185
+ }
186
+ },
187
+ {
188
+ method: "GET",
189
+ path: "/cells/:cellId/controllers/:controllerId/motion-groups/:motionGroupId/description",
190
+ handle() {
191
+ return {
192
+ motion_group_model: "UniversalRobots_UR5e",
193
+ mounting: {
194
+ position: [
195
+ 0,
196
+ 0,
197
+ 0
198
+ ],
199
+ orientation: [
200
+ 0,
201
+ 0,
202
+ 0
203
+ ]
204
+ },
205
+ tcps: { Flange: {
206
+ name: "Default-Flange",
207
+ pose: {
208
+ position: [
209
+ 0,
210
+ 0,
211
+ 0
212
+ ],
213
+ orientation: [
214
+ 0,
215
+ 0,
216
+ 0
217
+ ]
218
+ }
219
+ } },
220
+ payloads: { "FPay-0": {
221
+ name: "FPay-0",
222
+ payload: 0,
223
+ center_of_mass: [
224
+ 0,
225
+ 0,
226
+ 0
227
+ ],
228
+ moment_of_inertia: [
229
+ 0,
230
+ 0,
231
+ 0
232
+ ]
233
+ } },
234
+ cycle_time: 8,
235
+ dh_parameters: [
236
+ {
237
+ alpha: 1.5707963267948966,
238
+ d: 162.25
239
+ },
240
+ { a: -425 },
241
+ { a: -392.2 },
242
+ {
243
+ alpha: 1.5707963267948966,
244
+ d: 133.3
245
+ },
246
+ {
247
+ alpha: -1.5707963267948966,
248
+ d: 99.7
249
+ },
250
+ { d: 99.6 }
251
+ ],
252
+ operation_limits: {
253
+ auto_limits: {
254
+ joints: [
255
+ {
256
+ position: {
257
+ lower_limit: -6.283185307179586,
258
+ upper_limit: 6.283185307179586
259
+ },
260
+ velocity: 3.34159255027771,
261
+ acceleration: 40,
262
+ torque: 150
263
+ },
264
+ {
265
+ position: {
266
+ lower_limit: -6.283185307179586,
267
+ upper_limit: 6.283185307179586
268
+ },
269
+ velocity: 3.34159255027771,
270
+ acceleration: 40,
271
+ torque: 150
272
+ },
273
+ {
274
+ position: {
275
+ lower_limit: -6.283185307179586,
276
+ upper_limit: 6.283185307179586
277
+ },
278
+ velocity: 3.34159255027771,
279
+ acceleration: 40,
280
+ torque: 150
281
+ },
282
+ {
283
+ position: {
284
+ lower_limit: -6.283185307179586,
285
+ upper_limit: 6.283185307179586
286
+ },
287
+ velocity: 3.34159255027771,
288
+ acceleration: 40,
289
+ torque: 28
290
+ },
291
+ {
292
+ position: {
293
+ lower_limit: -6.283185307179586,
294
+ upper_limit: 6.283185307179586
295
+ },
296
+ velocity: 3.34159255027771,
297
+ acceleration: 40,
298
+ torque: 28
299
+ },
300
+ {
301
+ position: {
302
+ lower_limit: -6.283185307179586,
303
+ upper_limit: 6.283185307179586
304
+ },
305
+ velocity: 3.34159255027771,
306
+ acceleration: 40,
307
+ torque: 28
308
+ }
309
+ ],
310
+ tcp: { velocity: 5e3 },
311
+ elbow: { velocity: 5e3 },
312
+ flange: { velocity: 5e3 }
313
+ },
314
+ manual_limits: {
315
+ joints: [
316
+ {
317
+ position: {
318
+ lower_limit: -6.283185307179586,
319
+ upper_limit: 6.283185307179586
320
+ },
321
+ velocity: 3.34159255027771,
322
+ acceleration: 40,
323
+ torque: 150
324
+ },
325
+ {
326
+ position: {
327
+ lower_limit: -6.283185307179586,
328
+ upper_limit: 6.283185307179586
329
+ },
330
+ velocity: 3.34159255027771,
331
+ acceleration: 40,
332
+ torque: 150
333
+ },
334
+ {
335
+ position: {
336
+ lower_limit: -6.283185307179586,
337
+ upper_limit: 6.283185307179586
338
+ },
339
+ velocity: 3.34159255027771,
340
+ acceleration: 40,
341
+ torque: 150
342
+ },
343
+ {
344
+ position: {
345
+ lower_limit: -6.283185307179586,
346
+ upper_limit: 6.283185307179586
347
+ },
348
+ velocity: 3.34159255027771,
349
+ acceleration: 40,
350
+ torque: 28
351
+ },
352
+ {
353
+ position: {
354
+ lower_limit: -6.283185307179586,
355
+ upper_limit: 6.283185307179586
356
+ },
357
+ velocity: 3.34159255027771,
358
+ acceleration: 40,
359
+ torque: 28
360
+ },
361
+ {
362
+ position: {
363
+ lower_limit: -6.283185307179586,
364
+ upper_limit: 6.283185307179586
365
+ },
366
+ velocity: 3.34159255027771,
367
+ acceleration: 40,
368
+ torque: 28
369
+ }
370
+ ],
371
+ tcp: { velocity: 5e3 }
372
+ },
373
+ manual_t1_limits: {
374
+ joints: [
375
+ {
376
+ position: {
377
+ lower_limit: -6.283185307179586,
378
+ upper_limit: 6.283185307179586
379
+ },
380
+ velocity: 3.34159255027771,
381
+ acceleration: 40,
382
+ torque: 150
383
+ },
384
+ {
385
+ position: {
386
+ lower_limit: -6.283185307179586,
387
+ upper_limit: 6.283185307179586
388
+ },
389
+ velocity: 3.34159255027771,
390
+ acceleration: 40,
391
+ torque: 150
392
+ },
393
+ {
394
+ position: {
395
+ lower_limit: -6.283185307179586,
396
+ upper_limit: 6.283185307179586
397
+ },
398
+ velocity: 3.34159255027771,
399
+ acceleration: 40,
400
+ torque: 150
401
+ },
402
+ {
403
+ position: {
404
+ lower_limit: -6.283185307179586,
405
+ upper_limit: 6.283185307179586
406
+ },
407
+ velocity: 3.34159255027771,
408
+ acceleration: 40,
409
+ torque: 28
410
+ },
411
+ {
412
+ position: {
413
+ lower_limit: -6.283185307179586,
414
+ upper_limit: 6.283185307179586
415
+ },
416
+ velocity: 3.34159255027771,
417
+ acceleration: 40,
418
+ torque: 28
419
+ },
420
+ {
421
+ position: {
422
+ lower_limit: -6.283185307179586,
423
+ upper_limit: 6.283185307179586
424
+ },
425
+ velocity: 3.34159255027771,
426
+ acceleration: 40,
427
+ torque: 28
428
+ }
429
+ ],
430
+ tcp: { velocity: 5e3 }
431
+ },
432
+ manual_t2_limits: {
433
+ joints: [
434
+ {
435
+ position: {
436
+ lower_limit: -6.283185307179586,
437
+ upper_limit: 6.283185307179586
438
+ },
439
+ velocity: 3.34159255027771,
440
+ acceleration: 40,
441
+ torque: 150
442
+ },
443
+ {
444
+ position: {
445
+ lower_limit: -6.283185307179586,
446
+ upper_limit: 6.283185307179586
447
+ },
448
+ velocity: 3.34159255027771,
449
+ acceleration: 40,
450
+ torque: 150
451
+ },
452
+ {
453
+ position: {
454
+ lower_limit: -6.283185307179586,
455
+ upper_limit: 6.283185307179586
456
+ },
457
+ velocity: 3.34159255027771,
458
+ acceleration: 40,
459
+ torque: 150
460
+ },
461
+ {
462
+ position: {
463
+ lower_limit: -6.283185307179586,
464
+ upper_limit: 6.283185307179586
465
+ },
466
+ velocity: 3.34159255027771,
467
+ acceleration: 40,
468
+ torque: 28
469
+ },
470
+ {
471
+ position: {
472
+ lower_limit: -6.283185307179586,
473
+ upper_limit: 6.283185307179586
474
+ },
475
+ velocity: 3.34159255027771,
476
+ acceleration: 40,
477
+ torque: 28
478
+ },
479
+ {
480
+ position: {
481
+ lower_limit: -6.283185307179586,
482
+ upper_limit: 6.283185307179586
483
+ },
484
+ velocity: 3.34159255027771,
485
+ acceleration: 40,
486
+ torque: 28
487
+ }
488
+ ],
489
+ tcp: { velocity: 5e3 }
490
+ }
491
+ },
492
+ serial_number: "WBVirtualRobot"
493
+ };
494
+ }
495
+ },
496
+ {
497
+ method: "GET",
498
+ path: "/cells/:cellId/controllers/:controllerId/coordinate-systems",
499
+ handle() {
500
+ return [{
501
+ coordinate_system: "",
502
+ name: "world",
503
+ reference_coordinate_system: "",
504
+ position: [
505
+ 0,
506
+ 0,
507
+ 0
508
+ ],
509
+ orientation: [
510
+ 0,
511
+ 0,
512
+ 0
513
+ ],
514
+ orientation_type: "ROTATION_VECTOR"
515
+ }, {
516
+ coordinate_system: "CS-0",
517
+ name: "Default-CS",
518
+ reference_coordinate_system: "",
519
+ position: [
520
+ 0,
521
+ 0,
522
+ 0
523
+ ],
524
+ orientation: [
525
+ 0,
526
+ 0,
527
+ 0
528
+ ],
529
+ orientation_type: "ROTATION_VECTOR"
530
+ }];
531
+ }
532
+ }
533
+ ];
534
+ const method = config.method?.toUpperCase() || "GET";
535
+ const path = `/cells${config.url?.split("/cells")[1]?.split("?")[0]}`;
536
+ for (const handler of apiHandlers) {
537
+ const match = pathToRegexp.match(handler.path)(path || "");
538
+ if (method === handler.method && match) {
539
+ const json = handler.handle();
540
+ return {
541
+ status: 200,
542
+ statusText: "Success",
543
+ data: JSON.stringify(json),
544
+ headers: {},
545
+ config,
546
+ request: { responseURL: config.url }
547
+ };
548
+ }
549
+ }
550
+ throw new AxiosError(`No mock handler matched this request: ${method} ${path}`, "404", config);
551
+ }
552
+ handleWebsocketConnection(socket) {
553
+ this.connections.push(socket);
554
+ setTimeout(() => {
555
+ socket.dispatchEvent(new Event("open"));
556
+ console.log("Websocket connection opened from", socket.url);
557
+ if (socket.url.includes("/state-stream")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify(defaultMotionState) }));
558
+ if (socket.url.includes("/execution/jogging")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify({ result: {
559
+ message: "string",
560
+ kind: "INITIALIZE_RECEIVED"
561
+ } }) }));
562
+ }, 10);
563
+ }
564
+ handleWebsocketMessage(socket, message) {
565
+ console.log(`Received message on ${socket.url}`, message);
566
+ }
567
+ };
568
+ const defaultMotionState = { result: {
569
+ motion_group: "0@universalrobots-ur5e",
570
+ controller: "universalrobots-ur5e",
571
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
572
+ sequence_number: 1,
573
+ joint_position: [
574
+ 1.1699999570846558,
575
+ -1.5700000524520874,
576
+ 1.3600000143051147,
577
+ 1.0299999713897705,
578
+ 1.2899999618530273,
579
+ 1.2799999713897705
580
+ ],
581
+ joint_limit_reached: { limit_reached: [
582
+ false,
583
+ false,
584
+ false,
585
+ false,
586
+ false,
587
+ false
588
+ ] },
589
+ standstill: false,
590
+ flange_pose: {
591
+ position: [
592
+ 1.3300010259703043,
593
+ -409.2680714682808,
594
+ 531.0203477065281
595
+ ],
596
+ orientation: [
597
+ 1.7564919306270736,
598
+ -1.7542521568325058,
599
+ .7326972590614671
600
+ ]
601
+ },
602
+ tcp_pose: {
603
+ position: [
604
+ 1.3300010259703043,
605
+ -409.2680714682808,
606
+ 531.0203477065281
607
+ ],
608
+ orientation: [
609
+ 1.7564919306270736,
610
+ -1.7542521568325058,
611
+ .7326972590614671
612
+ ]
613
+ }
614
+ } };
615
+
616
+ //#endregion
617
+ //#region src/lib/v2/NovaClient.ts
618
+ function permissiveInstanceUrlParse(url) {
619
+ if (!url.startsWith("http")) url = `http://${url}`;
620
+ return new URL(url).toString();
621
+ }
622
+ /**
623
+ *
624
+ * Client for connecting to a Nova instance and controlling robots.
625
+ */
626
+ var NovaClient = class {
627
+ constructor(config) {
628
+ this.authPromise = null;
629
+ this.accessToken = null;
630
+ const cellId = config.cellId ?? "cell";
631
+ this.config = {
632
+ cellId,
633
+ ...config
634
+ };
635
+ this.accessToken = config.accessToken || availableStorage.getString("wbjs.access_token") || null;
636
+ if (this.config.instanceUrl === "https://mock.example.com") this.mock = new MockNovaInstance();
637
+ else this.config.instanceUrl = permissiveInstanceUrlParse(this.config.instanceUrl);
638
+ const axiosInstance = axios.create({
639
+ baseURL: urlJoin(this.config.instanceUrl, "/api/v2"),
640
+ headers: typeof window !== "undefined" && window.location.origin.includes("localhost") ? {} : { "X-Wandelbots-Client": "Wandelbots-Nova-JS-SDK" }
641
+ });
642
+ axiosInstance.interceptors.request.use(async (request) => {
643
+ if (!request.headers.Authorization) {
644
+ if (this.accessToken) request.headers.Authorization = `Bearer ${this.accessToken}`;
645
+ else if (this.config.username && this.config.password) request.headers.Authorization = `Basic ${btoa(`${config.username}:${config.password}`)}`;
646
+ }
647
+ return request;
648
+ });
649
+ if (typeof window !== "undefined") axiosInstance.interceptors.response.use((r) => r, async (error) => {
650
+ if (isAxiosError(error)) {
651
+ if (error.response?.status === 401) try {
652
+ await this.renewAuthentication();
653
+ if (error.config) {
654
+ if (this.accessToken) error.config.headers.Authorization = `Bearer ${this.accessToken}`;
655
+ else delete error.config.headers.Authorization;
656
+ return axiosInstance.request(error.config);
657
+ }
658
+ } catch (err) {
659
+ return Promise.reject(err);
660
+ }
661
+ else if (error.response?.status === 503) {
662
+ if ((await fetch(window.location.href)).status === 503) window.location.reload();
663
+ }
664
+ }
665
+ return Promise.reject(error);
666
+ });
667
+ this.api = new NovaCellAPIClient(cellId, {
668
+ ...config,
669
+ basePath: urlJoin(this.config.instanceUrl, "/api/v2"),
670
+ isJsonMime: (mime) => {
671
+ return mime === "application/json";
672
+ },
673
+ baseOptions: {
674
+ ...this.mock ? { adapter: (config$1) => {
675
+ return this.mock.handleAPIRequest(config$1);
676
+ } } : {},
677
+ ...config.baseOptions
678
+ },
679
+ axiosInstance
680
+ });
681
+ }
682
+ async renewAuthentication() {
683
+ if (this.authPromise) return;
684
+ this.authPromise = loginWithAuth0(this.config.instanceUrl);
685
+ try {
686
+ this.accessToken = await this.authPromise;
687
+ if (this.accessToken) availableStorage.setString("wbjs.access_token", this.accessToken);
688
+ else availableStorage.delete("wbjs.access_token");
689
+ } finally {
690
+ this.authPromise = null;
691
+ }
692
+ }
693
+ makeWebsocketURL(path) {
694
+ const url = new URL(urlJoin(this.config.instanceUrl, `/api/v2/cells/${this.config.cellId}`, path));
695
+ url.protocol = url.protocol.replace("http", "ws");
696
+ url.protocol = url.protocol.replace("https", "wss");
697
+ if (this.accessToken) url.searchParams.append("token", this.accessToken);
698
+ else if (this.config.username && this.config.password) {
699
+ url.username = this.config.username;
700
+ url.password = this.config.password;
701
+ }
702
+ return url.toString();
703
+ }
704
+ /**
705
+ * Retrieve an AutoReconnectingWebsocket to the given path on the Nova instance.
706
+ * If you explicitly want to reconnect an existing websocket, call `reconnect`
707
+ * on the returned object.
708
+ */
709
+ openReconnectingWebsocket(path) {
710
+ return new AutoReconnectingWebsocket(this.makeWebsocketURL(path), { mock: this.mock });
711
+ }
712
+ };
713
+
714
+ //#endregion
715
+ //#region src/lib/v2/wandelscriptUtils.ts
716
+ /**
717
+ * Convert a Pose object representing a motion group position
718
+ * into a string which represents that pose in Wandelscript.
719
+ */
720
+ function poseToWandelscriptString(pose) {
721
+ const position = [
722
+ pose.position?.[0] ?? 0,
723
+ pose.position?.[1] ?? 0,
724
+ pose.position?.[2] ?? 0
725
+ ];
726
+ const orientation = [
727
+ pose.orientation?.[0] ?? 0,
728
+ pose.orientation?.[1] ?? 0,
729
+ pose.orientation?.[2] ?? 0
730
+ ];
731
+ const positionValues = position.map((v) => v.toFixed(1));
732
+ const rotationValues = orientation.map((v) => v.toFixed(4));
733
+ return `(${positionValues.concat(rotationValues).join(", ")})`;
734
+ }
735
+
736
+ //#endregion
737
+ export { NovaCellAPIClient, NovaClient, poseToWandelscriptString };
738
+ //# sourceMappingURL=index.mjs.map