@wandelbots/nova-js 3.2.0 → 3.3.0-pr.fix-mock-v2.176.c5ea07d

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