@wandelbots/nova-js 3.7.0-pr.267.ffc5d9d → 3.7.0-pr.276.de5eb8e

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