@wandelbots/nova-js 1.17.1-pr.feat-added-v2-client.64.9ac2247
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.
- package/LICENSE +201 -0
- package/README.md +202 -0
- package/dist/LoginWithAuth0.d.ts +7 -0
- package/dist/LoginWithAuth0.d.ts.map +1 -0
- package/dist/chunk-V3NJLR6P.js +336 -0
- package/dist/chunk-V3NJLR6P.js.map +1 -0
- package/dist/index.cjs +390 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/AutoReconnectingWebsocket.d.ts +43 -0
- package/dist/lib/AutoReconnectingWebsocket.d.ts.map +1 -0
- package/dist/lib/availableStorage.d.ts +15 -0
- package/dist/lib/availableStorage.d.ts.map +1 -0
- package/dist/lib/converters.d.ts +26 -0
- package/dist/lib/converters.d.ts.map +1 -0
- package/dist/lib/errorHandling.d.ts +4 -0
- package/dist/lib/errorHandling.d.ts.map +1 -0
- package/dist/lib/v1/ConnectedMotionGroup.d.ts +77 -0
- package/dist/lib/v1/ConnectedMotionGroup.d.ts.map +1 -0
- package/dist/lib/v1/JoggerConnection.d.ts +94 -0
- package/dist/lib/v1/JoggerConnection.d.ts.map +1 -0
- package/dist/lib/v1/MotionStreamConnection.d.ts +25 -0
- package/dist/lib/v1/MotionStreamConnection.d.ts.map +1 -0
- package/dist/lib/v1/NovaCellAPIClient.d.ts +66 -0
- package/dist/lib/v1/NovaCellAPIClient.d.ts.map +1 -0
- package/dist/lib/v1/NovaClient.d.ts +67 -0
- package/dist/lib/v1/NovaClient.d.ts.map +1 -0
- package/dist/lib/v1/ProgramStateConnection.d.ts +53 -0
- package/dist/lib/v1/ProgramStateConnection.d.ts.map +1 -0
- package/dist/lib/v1/getLatestTrajectories.d.ts +4 -0
- package/dist/lib/v1/getLatestTrajectories.d.ts.map +1 -0
- package/dist/lib/v1/index.cjs +3957 -0
- package/dist/lib/v1/index.cjs.map +1 -0
- package/dist/lib/v1/index.d.ts +9 -0
- package/dist/lib/v1/index.d.ts.map +1 -0
- package/dist/lib/v1/index.js +3662 -0
- package/dist/lib/v1/index.js.map +1 -0
- package/dist/lib/v1/mock/MockNovaInstance.d.ts +13 -0
- package/dist/lib/v1/mock/MockNovaInstance.d.ts.map +1 -0
- package/dist/lib/v1/motionStateUpdate.d.ts +4 -0
- package/dist/lib/v1/motionStateUpdate.d.ts.map +1 -0
- package/dist/lib/v2/ConnectedMotionGroup.d.ts +41 -0
- package/dist/lib/v2/ConnectedMotionGroup.d.ts.map +1 -0
- package/dist/lib/v2/JoggerConnection.d.ts +53 -0
- package/dist/lib/v2/JoggerConnection.d.ts.map +1 -0
- package/dist/lib/v2/MotionStreamConnection.d.ts +25 -0
- package/dist/lib/v2/MotionStreamConnection.d.ts.map +1 -0
- package/dist/lib/v2/NovaCellAPIClient.d.ts +64 -0
- package/dist/lib/v2/NovaCellAPIClient.d.ts.map +1 -0
- package/dist/lib/v2/NovaClient.d.ts +67 -0
- package/dist/lib/v2/NovaClient.d.ts.map +1 -0
- package/dist/lib/v2/ProgramStateConnection.d.ts +53 -0
- package/dist/lib/v2/ProgramStateConnection.d.ts.map +1 -0
- package/dist/lib/v2/index.cjs +2239 -0
- package/dist/lib/v2/index.cjs.map +1 -0
- package/dist/lib/v2/index.d.ts +8 -0
- package/dist/lib/v2/index.d.ts.map +1 -0
- package/dist/lib/v2/index.js +1947 -0
- package/dist/lib/v2/index.js.map +1 -0
- package/dist/lib/v2/mock/MockNovaInstance.d.ts +13 -0
- package/dist/lib/v2/mock/MockNovaInstance.d.ts.map +1 -0
- package/dist/lib/v2/motionStateUpdate.d.ts +4 -0
- package/dist/lib/v2/motionStateUpdate.d.ts.map +1 -0
- package/dist/lib/v2/vectorUtils.d.ts +7 -0
- package/dist/lib/v2/vectorUtils.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/LoginWithAuth0.ts +90 -0
- package/src/index.ts +5 -0
- package/src/lib/AutoReconnectingWebsocket.ts +163 -0
- package/src/lib/availableStorage.ts +46 -0
- package/src/lib/converters.ts +74 -0
- package/src/lib/errorHandling.ts +26 -0
- package/src/lib/v1/ConnectedMotionGroup.ts +419 -0
- package/src/lib/v1/JoggerConnection.ts +480 -0
- package/src/lib/v1/MotionStreamConnection.ts +202 -0
- package/src/lib/v1/NovaCellAPIClient.ts +180 -0
- package/src/lib/v1/NovaClient.ts +232 -0
- package/src/lib/v1/ProgramStateConnection.ts +267 -0
- package/src/lib/v1/getLatestTrajectories.ts +36 -0
- package/src/lib/v1/index.ts +8 -0
- package/src/lib/v1/mock/MockNovaInstance.ts +1302 -0
- package/src/lib/v1/motionStateUpdate.ts +55 -0
- package/src/lib/v2/ConnectedMotionGroup.ts +216 -0
- package/src/lib/v2/JoggerConnection.ts +207 -0
- package/src/lib/v2/MotionStreamConnection.ts +201 -0
- package/src/lib/v2/NovaCellAPIClient.ts +174 -0
- package/src/lib/v2/NovaClient.ts +230 -0
- package/src/lib/v2/ProgramStateConnection.ts +255 -0
- package/src/lib/v2/index.ts +7 -0
- package/src/lib/v2/mock/MockNovaInstance.ts +982 -0
- package/src/lib/v2/motionStateUpdate.ts +55 -0
- package/src/lib/v2/vectorUtils.ts +36 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var __async = (__this, __arguments, generator) => {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
var fulfilled = (value) => {
|
|
32
|
+
try {
|
|
33
|
+
step(generator.next(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var rejected = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.throw(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
46
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/index.ts
|
|
51
|
+
var index_exports = {};
|
|
52
|
+
__export(index_exports, {
|
|
53
|
+
AutoReconnectingWebsocket: () => AutoReconnectingWebsocket,
|
|
54
|
+
availableStorage: () => availableStorage,
|
|
55
|
+
degreesToRadians: () => degreesToRadians,
|
|
56
|
+
delay: () => delay,
|
|
57
|
+
isSameCoordinateSystem: () => isSameCoordinateSystem,
|
|
58
|
+
loginWithAuth0: () => loginWithAuth0,
|
|
59
|
+
makeErrorMessage: () => makeErrorMessage,
|
|
60
|
+
makeShortErrorMessage: () => makeShortErrorMessage,
|
|
61
|
+
makeUrlQueryString: () => makeUrlQueryString,
|
|
62
|
+
poseToWandelscriptString: () => poseToWandelscriptString,
|
|
63
|
+
radiansToDegrees: () => radiansToDegrees,
|
|
64
|
+
tryParseJson: () => tryParseJson,
|
|
65
|
+
tryStringifyJson: () => tryStringifyJson
|
|
66
|
+
});
|
|
67
|
+
module.exports = __toCommonJS(index_exports);
|
|
68
|
+
|
|
69
|
+
// src/lib/AutoReconnectingWebsocket.ts
|
|
70
|
+
var import_reconnecting_websocket = __toESM(require("reconnecting-websocket"), 1);
|
|
71
|
+
var AutoReconnectingWebsocket = class extends import_reconnecting_websocket.default {
|
|
72
|
+
constructor(targetUrl, opts = {}) {
|
|
73
|
+
console.log("Opening websocket to", targetUrl);
|
|
74
|
+
super(() => this.targetUrl || targetUrl, void 0, {
|
|
75
|
+
startClosed: true
|
|
76
|
+
});
|
|
77
|
+
this.opts = opts;
|
|
78
|
+
this.disposed = false;
|
|
79
|
+
Object.defineProperty(this, "url", {
|
|
80
|
+
get() {
|
|
81
|
+
return this.targetUrl;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
this.targetUrl = targetUrl;
|
|
85
|
+
this.addEventListener("open", () => {
|
|
86
|
+
console.log(`Websocket to ${this.url} opened`);
|
|
87
|
+
});
|
|
88
|
+
this.addEventListener("message", (ev) => {
|
|
89
|
+
if (!this.receivedFirstMessage) {
|
|
90
|
+
this.receivedFirstMessage = ev;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
this.addEventListener("close", () => {
|
|
94
|
+
console.log(`Websocket to ${this.url} closed`);
|
|
95
|
+
});
|
|
96
|
+
const origReconnect = this.reconnect;
|
|
97
|
+
this.reconnect = () => {
|
|
98
|
+
if (this.opts.mock) {
|
|
99
|
+
this.opts.mock.handleWebsocketConnection(this);
|
|
100
|
+
} else {
|
|
101
|
+
origReconnect.apply(this);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
this.reconnect();
|
|
105
|
+
}
|
|
106
|
+
changeUrl(targetUrl) {
|
|
107
|
+
this.receivedFirstMessage = void 0;
|
|
108
|
+
this.targetUrl = targetUrl;
|
|
109
|
+
this.reconnect();
|
|
110
|
+
}
|
|
111
|
+
sendJson(data) {
|
|
112
|
+
if (this.opts.mock) {
|
|
113
|
+
this.opts.mock.handleWebsocketMessage(this, JSON.stringify(data));
|
|
114
|
+
} else {
|
|
115
|
+
this.send(JSON.stringify(data));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Permanently close this websocket and indicate that
|
|
120
|
+
* this object should not be used again.
|
|
121
|
+
**/
|
|
122
|
+
dispose() {
|
|
123
|
+
this.close();
|
|
124
|
+
this.disposed = true;
|
|
125
|
+
if (this.opts.onDispose) {
|
|
126
|
+
this.opts.onDispose();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns a promise that resolves once the websocket
|
|
131
|
+
* is in the OPEN state. */
|
|
132
|
+
opened() {
|
|
133
|
+
return __async(this, null, function* () {
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
if (this.readyState === WebSocket.OPEN) {
|
|
136
|
+
resolve();
|
|
137
|
+
} else {
|
|
138
|
+
this.addEventListener("open", () => resolve());
|
|
139
|
+
this.addEventListener("error", reject);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns a promise that resolves once the websocket
|
|
146
|
+
* is in the CLOSED state. */
|
|
147
|
+
closed() {
|
|
148
|
+
return __async(this, null, function* () {
|
|
149
|
+
return new Promise((resolve, reject) => {
|
|
150
|
+
if (this.readyState === WebSocket.CLOSED) {
|
|
151
|
+
resolve();
|
|
152
|
+
} else {
|
|
153
|
+
this.addEventListener("close", () => resolve());
|
|
154
|
+
this.addEventListener("error", reject);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Returns a promise that resolves when the first message
|
|
161
|
+
* is received from the websocket. Resolves immediately if
|
|
162
|
+
* the first message has already been received.
|
|
163
|
+
*/
|
|
164
|
+
firstMessage() {
|
|
165
|
+
return __async(this, null, function* () {
|
|
166
|
+
if (this.receivedFirstMessage) {
|
|
167
|
+
return this.receivedFirstMessage;
|
|
168
|
+
}
|
|
169
|
+
return new Promise((resolve, reject) => {
|
|
170
|
+
const onMessage = (ev) => {
|
|
171
|
+
this.receivedFirstMessage = ev;
|
|
172
|
+
this.removeEventListener("message", onMessage);
|
|
173
|
+
this.removeEventListener("error", onError);
|
|
174
|
+
resolve(ev);
|
|
175
|
+
};
|
|
176
|
+
const onError = (ev) => {
|
|
177
|
+
this.removeEventListener("message", onMessage);
|
|
178
|
+
this.removeEventListener("error", onError);
|
|
179
|
+
reject(ev);
|
|
180
|
+
};
|
|
181
|
+
this.addEventListener("message", onMessage);
|
|
182
|
+
this.addEventListener("error", onError);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Returns a promise that resolves when the next message
|
|
188
|
+
* is received from the websocket.
|
|
189
|
+
*/
|
|
190
|
+
nextMessage() {
|
|
191
|
+
return __async(this, null, function* () {
|
|
192
|
+
return new Promise((resolve, reject) => {
|
|
193
|
+
const onMessage = (ev) => {
|
|
194
|
+
this.removeEventListener("message", onMessage);
|
|
195
|
+
this.removeEventListener("error", onError);
|
|
196
|
+
resolve(ev);
|
|
197
|
+
};
|
|
198
|
+
const onError = (ev) => {
|
|
199
|
+
this.removeEventListener("message", onMessage);
|
|
200
|
+
this.removeEventListener("error", onError);
|
|
201
|
+
reject(ev);
|
|
202
|
+
};
|
|
203
|
+
this.addEventListener("message", onMessage);
|
|
204
|
+
this.addEventListener("error", onError);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// src/lib/availableStorage.ts
|
|
211
|
+
var AvailableStorage = class {
|
|
212
|
+
constructor() {
|
|
213
|
+
this.available = typeof window !== "undefined" && !!window.localStorage;
|
|
214
|
+
}
|
|
215
|
+
getJSON(key) {
|
|
216
|
+
if (!this.available) return null;
|
|
217
|
+
const result = window.localStorage.getItem(key);
|
|
218
|
+
if (result === null) return null;
|
|
219
|
+
try {
|
|
220
|
+
return JSON.parse(result);
|
|
221
|
+
} catch (err) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
setJSON(key, obj) {
|
|
226
|
+
if (!this.available) return null;
|
|
227
|
+
window.localStorage.setItem(key, JSON.stringify(obj));
|
|
228
|
+
}
|
|
229
|
+
delete(key) {
|
|
230
|
+
if (!this.available) return null;
|
|
231
|
+
window.localStorage.removeItem(key);
|
|
232
|
+
}
|
|
233
|
+
setString(key, value) {
|
|
234
|
+
if (!this.available) return null;
|
|
235
|
+
window.localStorage.setItem(key, value);
|
|
236
|
+
}
|
|
237
|
+
getString(key) {
|
|
238
|
+
if (!this.available) return null;
|
|
239
|
+
return window.localStorage.getItem(key);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
var availableStorage = new AvailableStorage();
|
|
243
|
+
|
|
244
|
+
// src/lib/converters.ts
|
|
245
|
+
function tryParseJson(json) {
|
|
246
|
+
try {
|
|
247
|
+
return JSON.parse(json);
|
|
248
|
+
} catch (e) {
|
|
249
|
+
return void 0;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function tryStringifyJson(json) {
|
|
253
|
+
try {
|
|
254
|
+
return JSON.stringify(json);
|
|
255
|
+
} catch (e) {
|
|
256
|
+
return void 0;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function makeUrlQueryString(obj) {
|
|
260
|
+
const str = new URLSearchParams(obj).toString();
|
|
261
|
+
return str ? `?${str}` : "";
|
|
262
|
+
}
|
|
263
|
+
function radiansToDegrees(radians) {
|
|
264
|
+
return radians * (180 / Math.PI);
|
|
265
|
+
}
|
|
266
|
+
function degreesToRadians(degrees) {
|
|
267
|
+
return degrees * (Math.PI / 180);
|
|
268
|
+
}
|
|
269
|
+
function poseToWandelscriptString(pose) {
|
|
270
|
+
var _a, _b, _c, _d, _e, _f;
|
|
271
|
+
const position = [pose.position.x, pose.position.y, pose.position.z];
|
|
272
|
+
const orientation = [
|
|
273
|
+
(_b = (_a = pose.orientation) == null ? void 0 : _a.x) != null ? _b : 0,
|
|
274
|
+
(_d = (_c = pose.orientation) == null ? void 0 : _c.y) != null ? _d : 0,
|
|
275
|
+
(_f = (_e = pose.orientation) == null ? void 0 : _e.z) != null ? _f : 0
|
|
276
|
+
];
|
|
277
|
+
const positionValues = position.map((v) => v.toFixed(1));
|
|
278
|
+
const rotationValues = orientation.map((v) => v.toFixed(4));
|
|
279
|
+
return `(${positionValues.concat(rotationValues).join(", ")})`;
|
|
280
|
+
}
|
|
281
|
+
function isSameCoordinateSystem(firstCoordSystem, secondCoordSystem) {
|
|
282
|
+
if (!firstCoordSystem) firstCoordSystem = "world";
|
|
283
|
+
if (!secondCoordSystem) secondCoordSystem = "world";
|
|
284
|
+
return firstCoordSystem === secondCoordSystem;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/lib/errorHandling.ts
|
|
288
|
+
var import_axios = require("axios");
|
|
289
|
+
function delay(ms) {
|
|
290
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
291
|
+
}
|
|
292
|
+
function makeShortErrorMessage(err) {
|
|
293
|
+
var _a, _b, _c;
|
|
294
|
+
if (err instanceof import_axios.AxiosError && err.response) {
|
|
295
|
+
return `${(_a = err.response) == null ? void 0 : _a.status} ${(_b = err.response) == null ? void 0 : _b.statusText}: ${JSON.stringify((_c = err.response) == null ? void 0 : _c.data)}`;
|
|
296
|
+
} else if (err instanceof Error) {
|
|
297
|
+
return err.message;
|
|
298
|
+
} else {
|
|
299
|
+
return `Unexpected error: ${err}`;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function makeErrorMessage(err) {
|
|
303
|
+
var _a, _b, _c, _d;
|
|
304
|
+
if (err instanceof import_axios.AxiosError && err.response) {
|
|
305
|
+
return `${(_a = err.response) == null ? void 0 : _a.status} ${(_b = err.response) == null ? void 0 : _b.statusText} from ${(_c = err.response) == null ? void 0 : _c.config.url}: ${JSON.stringify((_d = err.response) == null ? void 0 : _d.data)}`;
|
|
306
|
+
} else if (err instanceof Error) {
|
|
307
|
+
return err.message;
|
|
308
|
+
} else {
|
|
309
|
+
return `Unexpected error: ${tryStringifyJson(err) || err}`;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/LoginWithAuth0.ts
|
|
314
|
+
var DOMAIN_SUFFIX = "wandelbots.io";
|
|
315
|
+
var auth0ConfigMap = {
|
|
316
|
+
dev: {
|
|
317
|
+
domain: `https://auth.portal.dev.${DOMAIN_SUFFIX}`,
|
|
318
|
+
clientId: "fLbJD0RLp5r2Dpucm5j8BjwMR6Hunfha"
|
|
319
|
+
},
|
|
320
|
+
stg: {
|
|
321
|
+
domain: `https://auth.portal.stg.${DOMAIN_SUFFIX}`,
|
|
322
|
+
clientId: "joVDeD9e786WzFNSGCqoVq7HNkWt5j6s"
|
|
323
|
+
},
|
|
324
|
+
prod: {
|
|
325
|
+
domain: `https://auth.portal.${DOMAIN_SUFFIX}`,
|
|
326
|
+
clientId: "J7WJUi38xVQdJAEBNRT9Xw1b0fXDb4J2"
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
var getAuth0Config = (instanceUrl) => {
|
|
330
|
+
if (instanceUrl.includes(`dev.${DOMAIN_SUFFIX}`)) return auth0ConfigMap.dev;
|
|
331
|
+
if (instanceUrl.includes(`stg.${DOMAIN_SUFFIX}`)) return auth0ConfigMap.stg;
|
|
332
|
+
if (instanceUrl.includes(DOMAIN_SUFFIX)) return auth0ConfigMap.prod;
|
|
333
|
+
throw new Error(
|
|
334
|
+
"Unsupported instance URL. Cannot determine Auth0 configuration."
|
|
335
|
+
);
|
|
336
|
+
};
|
|
337
|
+
var loginWithAuth0 = (instanceUrl) => __async(void 0, null, function* () {
|
|
338
|
+
var _a;
|
|
339
|
+
if (typeof window === "undefined") {
|
|
340
|
+
throw new Error(
|
|
341
|
+
`Access token must be set to use NovaClient when not in a browser environment.`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
const auth0Config = getAuth0Config(instanceUrl);
|
|
345
|
+
if (new URL(instanceUrl).origin === window.location.origin) {
|
|
346
|
+
window.location.reload();
|
|
347
|
+
throw new Error(
|
|
348
|
+
"Failed to reload page to get auth details, please refresh manually"
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
const { Auth0Client } = yield import("@auth0/auth0-spa-js");
|
|
352
|
+
const auth0Client = new Auth0Client({
|
|
353
|
+
domain: auth0Config.domain,
|
|
354
|
+
clientId: (_a = auth0Config.clientId) != null ? _a : "",
|
|
355
|
+
useRefreshTokens: false,
|
|
356
|
+
authorizationParams: {
|
|
357
|
+
audience: "nova-api",
|
|
358
|
+
redirect_uri: window.location.origin
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
if (window.location.search.includes("code=") && window.location.search.includes("state=")) {
|
|
362
|
+
const { appState } = yield auth0Client.handleRedirectCallback();
|
|
363
|
+
window.history.replaceState(
|
|
364
|
+
{},
|
|
365
|
+
document.title,
|
|
366
|
+
(appState == null ? void 0 : appState.returnTo) || window.location.pathname
|
|
367
|
+
);
|
|
368
|
+
} else {
|
|
369
|
+
yield auth0Client.loginWithRedirect();
|
|
370
|
+
}
|
|
371
|
+
const accessToken = yield auth0Client.getTokenSilently();
|
|
372
|
+
return accessToken;
|
|
373
|
+
});
|
|
374
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
375
|
+
0 && (module.exports = {
|
|
376
|
+
AutoReconnectingWebsocket,
|
|
377
|
+
availableStorage,
|
|
378
|
+
degreesToRadians,
|
|
379
|
+
delay,
|
|
380
|
+
isSameCoordinateSystem,
|
|
381
|
+
loginWithAuth0,
|
|
382
|
+
makeErrorMessage,
|
|
383
|
+
makeShortErrorMessage,
|
|
384
|
+
makeUrlQueryString,
|
|
385
|
+
poseToWandelscriptString,
|
|
386
|
+
radiansToDegrees,
|
|
387
|
+
tryParseJson,
|
|
388
|
+
tryStringifyJson
|
|
389
|
+
});
|
|
390
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/AutoReconnectingWebsocket.ts","../src/lib/availableStorage.ts","../src/lib/converters.ts","../src/lib/errorHandling.ts","../src/LoginWithAuth0.ts"],"sourcesContent":["export * from \"./lib/AutoReconnectingWebsocket\"\nexport * from \"./lib/availableStorage\"\nexport * from \"./lib/converters\"\nexport * from \"./lib/errorHandling\"\nexport * from \"./LoginWithAuth0\"\n","import ReconnectingWebSocket, { type ErrorEvent } from \"reconnecting-websocket\"\nimport * as v2 from \"./v2/mock/MockNovaInstance\"\nimport * as v1 from \"./v1/mock/MockNovaInstance\"\n\nexport class AutoReconnectingWebsocket extends ReconnectingWebSocket {\n receivedFirstMessage?: MessageEvent\n targetUrl: string\n disposed = false\n\n constructor(\n targetUrl: string,\n readonly opts: {\n mock?: v1.MockNovaInstance | v2.MockNovaInstance\n onDispose?: () => void\n } = {},\n ) {\n console.log(\"Opening websocket to\", targetUrl)\n\n super(() => this.targetUrl || targetUrl, undefined, {\n startClosed: true,\n })\n\n // Reconnecting websocket doesn't set this properly with startClosed\n Object.defineProperty(this, \"url\", {\n get() {\n return this.targetUrl\n },\n })\n\n this.targetUrl = targetUrl\n\n this.addEventListener(\"open\", () => {\n console.log(`Websocket to ${this.url} opened`)\n })\n\n this.addEventListener(\"message\", (ev) => {\n if (!this.receivedFirstMessage) {\n this.receivedFirstMessage = ev\n }\n })\n\n this.addEventListener(\"close\", () => {\n console.log(`Websocket to ${this.url} closed`)\n })\n\n const origReconnect = this.reconnect\n this.reconnect = () => {\n if (this.opts.mock) {\n this.opts.mock.handleWebsocketConnection(this)\n } else {\n origReconnect.apply(this)\n }\n }\n\n this.reconnect()\n }\n\n changeUrl(targetUrl: string) {\n this.receivedFirstMessage = undefined\n this.targetUrl = targetUrl\n this.reconnect()\n }\n\n sendJson(data: unknown) {\n if (this.opts.mock) {\n this.opts.mock.handleWebsocketMessage(this, JSON.stringify(data))\n } else {\n this.send(JSON.stringify(data))\n }\n }\n\n /**\n * Permanently close this websocket and indicate that\n * this object should not be used again.\n **/\n dispose() {\n this.close()\n this.disposed = true\n if (this.opts.onDispose) {\n this.opts.onDispose()\n }\n }\n\n /**\n * Returns a promise that resolves once the websocket\n * is in the OPEN state. */\n async opened() {\n return new Promise<void>((resolve, reject) => {\n if (this.readyState === WebSocket.OPEN) {\n resolve()\n } else {\n this.addEventListener(\"open\", () => resolve())\n this.addEventListener(\"error\", reject)\n }\n })\n }\n\n /**\n * Returns a promise that resolves once the websocket\n * is in the CLOSED state. */\n async closed() {\n return new Promise<void>((resolve, reject) => {\n if (this.readyState === WebSocket.CLOSED) {\n resolve()\n } else {\n this.addEventListener(\"close\", () => resolve())\n this.addEventListener(\"error\", reject)\n }\n })\n }\n\n /**\n * Returns a promise that resolves when the first message\n * is received from the websocket. Resolves immediately if\n * the first message has already been received.\n */\n async firstMessage() {\n if (this.receivedFirstMessage) {\n return this.receivedFirstMessage\n }\n\n return new Promise<MessageEvent>((resolve, reject) => {\n const onMessage = (ev: MessageEvent) => {\n this.receivedFirstMessage = ev\n this.removeEventListener(\"message\", onMessage)\n this.removeEventListener(\"error\", onError)\n resolve(ev)\n }\n\n const onError = (ev: ErrorEvent) => {\n this.removeEventListener(\"message\", onMessage)\n this.removeEventListener(\"error\", onError)\n reject(ev)\n }\n\n this.addEventListener(\"message\", onMessage)\n this.addEventListener(\"error\", onError)\n })\n }\n\n /**\n * Returns a promise that resolves when the next message\n * is received from the websocket.\n */\n async nextMessage() {\n return new Promise<MessageEvent>((resolve, reject) => {\n const onMessage = (ev: MessageEvent) => {\n this.removeEventListener(\"message\", onMessage)\n this.removeEventListener(\"error\", onError)\n resolve(ev)\n }\n\n const onError = (ev: ErrorEvent) => {\n this.removeEventListener(\"message\", onMessage)\n this.removeEventListener(\"error\", onError)\n reject(ev)\n }\n\n this.addEventListener(\"message\", onMessage)\n this.addEventListener(\"error\", onError)\n })\n }\n}\n","/**\n * Safety wrapper around browser localStorage providing context availability\n * checks and JSON parsing\n */\nclass AvailableStorage {\n available = typeof window !== \"undefined\" && !!window.localStorage\n\n getJSON<T>(key: string): Partial<T> | null {\n if (!this.available) return null\n\n const result = window.localStorage.getItem(key)\n if (result === null) return null\n\n try {\n return JSON.parse(result)\n } catch (err) {\n return null\n }\n }\n\n setJSON(key: string, obj: any) {\n if (!this.available) return null\n\n window.localStorage.setItem(key, JSON.stringify(obj))\n }\n\n delete(key: string) {\n if (!this.available) return null\n\n window.localStorage.removeItem(key)\n }\n\n setString(key: string, value: string) {\n if (!this.available) return null\n\n window.localStorage.setItem(key, value)\n }\n\n getString(key: string): string | null {\n if (!this.available) return null\n\n return window.localStorage.getItem(key)\n }\n}\n\nexport const availableStorage = new AvailableStorage()\n","import type { Pose } from \"@wandelbots/nova-api/v1\"\n\n/** Try to parse something as JSON; return undefined if we can't */\nexport function tryParseJson(json: unknown): any {\n try {\n return JSON.parse(json as string)\n } catch {\n return undefined\n }\n}\n\n/** Try to turn something into JSON; return undefined if we can't */\nexport function tryStringifyJson(json: unknown): string | undefined {\n try {\n return JSON.stringify(json)\n } catch {\n return undefined\n }\n}\n\n/**\n * Converts object parameters to query string.\n * e.g. { a: \"1\", b: \"2\" } => \"?a=1&b=2\"\n * {} => \"\"\n */\nexport function makeUrlQueryString(obj: Record<string, string>): string {\n const str = new URLSearchParams(obj).toString()\n return str ? `?${str}` : \"\"\n}\n\n/** Convert radians to degrees */\nexport function radiansToDegrees(radians: number): number {\n return radians * (180 / Math.PI)\n}\n\n/** Convert degrees to radians */\nexport function degreesToRadians(degrees: number): number {\n return degrees * (Math.PI / 180)\n}\n\n/**\n * Convert a Pose object representing a motion group position\n * into a string which represents that pose in Wandelscript.\n */\nexport function poseToWandelscriptString(\n pose: Pick<Pose, \"position\" | \"orientation\">,\n) {\n const position = [pose.position.x, pose.position.y, pose.position.z]\n const orientation = [\n pose.orientation?.x ?? 0,\n pose.orientation?.y ?? 0,\n pose.orientation?.z ?? 0,\n ]\n\n const positionValues = position.map((v) => v.toFixed(1))\n // Rotation needs more precision since it's in radians\n const rotationValues = orientation.map((v) => v.toFixed(4))\n\n return `(${positionValues.concat(rotationValues).join(\", \")})`\n}\n\n/**\n * Check for coordinate system id equivalence, accounting for the \"world\" default\n * on empty/undefined values.\n */\nexport function isSameCoordinateSystem(\n firstCoordSystem: string | undefined,\n secondCoordSystem: string | undefined,\n) {\n if (!firstCoordSystem) firstCoordSystem = \"world\"\n if (!secondCoordSystem) secondCoordSystem = \"world\"\n\n return firstCoordSystem === secondCoordSystem\n}\n","import { AxiosError } from \"axios\"\nimport { tryStringifyJson } from \"./converters\"\n\nexport function delay(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nexport function makeShortErrorMessage(err: unknown) {\n if (err instanceof AxiosError && err.response) {\n return `${err.response?.status} ${err.response?.statusText}: ${JSON.stringify(err.response?.data)}`\n } else if (err instanceof Error) {\n return err.message\n } else {\n return `Unexpected error: ${err}`\n }\n}\n\nexport function makeErrorMessage(err: unknown) {\n if (err instanceof AxiosError && err.response) {\n return `${err.response?.status} ${err.response?.statusText} from ${err.response?.config.url}: ${JSON.stringify(err.response?.data)}`\n } else if (err instanceof Error) {\n return err.message\n } else {\n return `Unexpected error: ${tryStringifyJson(err) || err}`\n }\n}\n","const DOMAIN_SUFFIX = \"wandelbots.io\"\n\n/** Mapping of stages to Auth0 configurations */\nconst auth0ConfigMap = {\n dev: {\n domain: `https://auth.portal.dev.${DOMAIN_SUFFIX}`,\n clientId: process.env.NOVA_AUTH0_DEV_CLIENT_ID,\n },\n stg: {\n domain: `https://auth.portal.stg.${DOMAIN_SUFFIX}`,\n clientId: process.env.NOVA_AUTH0_STG_CLIENT_ID,\n },\n prod: {\n domain: `https://auth.portal.${DOMAIN_SUFFIX}`,\n clientId: process.env.NOVA_AUTH0_PROD_CLIENT_ID,\n },\n}\n\n/** Determine which Auth0 configuration to use based on instance URL */\nconst getAuth0Config = (instanceUrl: string) => {\n if (instanceUrl.includes(`dev.${DOMAIN_SUFFIX}`)) return auth0ConfigMap.dev\n if (instanceUrl.includes(`stg.${DOMAIN_SUFFIX}`)) return auth0ConfigMap.stg\n if (instanceUrl.includes(DOMAIN_SUFFIX)) return auth0ConfigMap.prod\n throw new Error(\n \"Unsupported instance URL. Cannot determine Auth0 configuration.\",\n )\n}\n\n/**\n * Initializes Auth0 login process using redirect if necessary and retrieves an access token.\n * Returns null when an access token should not be needed to authenticate (i.e. cookie auth\n * when deployed on the instance domain)\n */\nexport const loginWithAuth0 = async (\n instanceUrl: string,\n): Promise<string | null> => {\n if (typeof window === \"undefined\") {\n throw new Error(\n `Access token must be set to use NovaClient when not in a browser environment.`,\n )\n }\n\n const auth0Config = getAuth0Config(instanceUrl)\n\n if (new URL(instanceUrl).origin === window.location.origin) {\n // When deployed on the instance itself, our auth is handled by cookies\n // and no access token is needed-- just need to reload the page and it'll\n // login again / set cookie as needed\n window.location.reload()\n throw new Error(\n \"Failed to reload page to get auth details, please refresh manually\",\n )\n }\n\n // If we're on localhost or another domain, we need to do the full oauth flow\n // Note this will ONLY work for origins which are whitelisted as a redirect_uri\n // in the auth0 config, currently\n const { Auth0Client } = await import(\"@auth0/auth0-spa-js\")\n\n const auth0Client = new Auth0Client({\n domain: auth0Config.domain,\n clientId: auth0Config.clientId ?? \"\",\n useRefreshTokens: false,\n authorizationParams: {\n audience: \"nova-api\",\n redirect_uri: window.location.origin,\n },\n })\n\n // If the URL includes a redirect result, handle it\n if (\n window.location.search.includes(\"code=\") &&\n window.location.search.includes(\"state=\")\n ) {\n const { appState } = await auth0Client.handleRedirectCallback()\n // Return to the URL the user was originally on before the redirect\n window.history.replaceState(\n {},\n document.title,\n appState?.returnTo || window.location.pathname,\n )\n } else {\n // Initiate login with redirect\n await auth0Client.loginWithRedirect()\n }\n\n // Once logged in, retrieve the access token silently\n const accessToken = await auth0Client.getTokenSilently()\n return accessToken\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oCAAuD;AAIhD,IAAM,4BAAN,cAAwC,8BAAAA,QAAsB;AAAA,EAKnE,YACE,WACS,OAGL,CAAC,GACL;AACA,YAAQ,IAAI,wBAAwB,SAAS;AAE7C,UAAM,MAAM,KAAK,aAAa,WAAW,QAAW;AAAA,MAClD,aAAa;AAAA,IACf,CAAC;AATQ;AAJX,oBAAW;AAgBT,WAAO,eAAe,MAAM,OAAO;AAAA,MACjC,MAAM;AACJ,eAAO,KAAK;AAAA,MACd;AAAA,IACF,CAAC;AAED,SAAK,YAAY;AAEjB,SAAK,iBAAiB,QAAQ,MAAM;AAClC,cAAQ,IAAI,gBAAgB,KAAK,GAAG,SAAS;AAAA,IAC/C,CAAC;AAED,SAAK,iBAAiB,WAAW,CAAC,OAAO;AACvC,UAAI,CAAC,KAAK,sBAAsB;AAC9B,aAAK,uBAAuB;AAAA,MAC9B;AAAA,IACF,CAAC;AAED,SAAK,iBAAiB,SAAS,MAAM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,KACvC,OAAO,SAAS,OAAO,SAAS,QAAQ,GACxC;AACA,UAAM,EAAE,SAAS,IAAI,MAAM,YAAY,uBAAuB;AAE9D,WAAO,QAAQ;AAAA,MACb,CAAC;AAAA,MACD,SAAS;AAAA,OACT,qCAAU,aAAY,OAAO,SAAS;AAAA,IACxC;AAAA,EACF,OAAO;AAEL,UAAM,YAAY,kBAAkB;AAAA,EACtC;AAGA,QAAM,cAAc,MAAM,YAAY,iBAAiB;AACvD,SAAO;AACT;","names":["ReconnectingWebSocket"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AutoReconnectingWebsocket,
|
|
3
|
+
availableStorage,
|
|
4
|
+
degreesToRadians,
|
|
5
|
+
isSameCoordinateSystem,
|
|
6
|
+
loginWithAuth0,
|
|
7
|
+
makeUrlQueryString,
|
|
8
|
+
poseToWandelscriptString,
|
|
9
|
+
radiansToDegrees,
|
|
10
|
+
tryParseJson,
|
|
11
|
+
tryStringifyJson
|
|
12
|
+
} from "./chunk-V3NJLR6P.js";
|
|
13
|
+
|
|
14
|
+
// src/lib/errorHandling.ts
|
|
15
|
+
import { AxiosError } from "axios";
|
|
16
|
+
function delay(ms) {
|
|
17
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
|
+
}
|
|
19
|
+
function makeShortErrorMessage(err) {
|
|
20
|
+
var _a, _b, _c;
|
|
21
|
+
if (err instanceof AxiosError && err.response) {
|
|
22
|
+
return `${(_a = err.response) == null ? void 0 : _a.status} ${(_b = err.response) == null ? void 0 : _b.statusText}: ${JSON.stringify((_c = err.response) == null ? void 0 : _c.data)}`;
|
|
23
|
+
} else if (err instanceof Error) {
|
|
24
|
+
return err.message;
|
|
25
|
+
} else {
|
|
26
|
+
return `Unexpected error: ${err}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function makeErrorMessage(err) {
|
|
30
|
+
var _a, _b, _c, _d;
|
|
31
|
+
if (err instanceof AxiosError && err.response) {
|
|
32
|
+
return `${(_a = err.response) == null ? void 0 : _a.status} ${(_b = err.response) == null ? void 0 : _b.statusText} from ${(_c = err.response) == null ? void 0 : _c.config.url}: ${JSON.stringify((_d = err.response) == null ? void 0 : _d.data)}`;
|
|
33
|
+
} else if (err instanceof Error) {
|
|
34
|
+
return err.message;
|
|
35
|
+
} else {
|
|
36
|
+
return `Unexpected error: ${tryStringifyJson(err) || err}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
AutoReconnectingWebsocket,
|
|
41
|
+
availableStorage,
|
|
42
|
+
degreesToRadians,
|
|
43
|
+
delay,
|
|
44
|
+
isSameCoordinateSystem,
|
|
45
|
+
loginWithAuth0,
|
|
46
|
+
makeErrorMessage,
|
|
47
|
+
makeShortErrorMessage,
|
|
48
|
+
makeUrlQueryString,
|
|
49
|
+
poseToWandelscriptString,
|
|
50
|
+
radiansToDegrees,
|
|
51
|
+
tryParseJson,
|
|
52
|
+
tryStringifyJson
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/errorHandling.ts"],"sourcesContent":["import { AxiosError } from \"axios\"\nimport { tryStringifyJson } from \"./converters\"\n\nexport function delay(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nexport function makeShortErrorMessage(err: unknown) {\n if (err instanceof AxiosError && err.response) {\n return `${err.response?.status} ${err.response?.statusText}: ${JSON.stringify(err.response?.data)}`\n } else if (err instanceof Error) {\n return err.message\n } else {\n return `Unexpected error: ${err}`\n }\n}\n\nexport function makeErrorMessage(err: unknown) {\n if (err instanceof AxiosError && err.response) {\n return `${err.response?.status} ${err.response?.statusText} from ${err.response?.config.url}: ${JSON.stringify(err.response?.data)}`\n } else if (err instanceof Error) {\n return err.message\n } else {\n return `Unexpected error: ${tryStringifyJson(err) || err}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAGpB,SAAS,MAAM,IAAY;AAChC,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AACzD;AAEO,SAAS,sBAAsB,KAAc;AAPpD;AAQE,MAAI,eAAe,cAAc,IAAI,UAAU;AAC7C,WAAO,IAAG,SAAI,aAAJ,mBAAc,MAAM,KAAI,SAAI,aAAJ,mBAAc,UAAU,KAAK,KAAK,WAAU,SAAI,aAAJ,mBAAc,IAAI,CAAC;AAAA,EACnG,WAAW,eAAe,OAAO;AAC/B,WAAO,IAAI;AAAA,EACb,OAAO;AACL,WAAO,qBAAqB,GAAG;AAAA,EACjC;AACF;AAEO,SAAS,iBAAiB,KAAc;AAjB/C;AAkBE,MAAI,eAAe,cAAc,IAAI,UAAU;AAC7C,WAAO,IAAG,SAAI,aAAJ,mBAAc,MAAM,KAAI,SAAI,aAAJ,mBAAc,UAAU,UAAS,SAAI,aAAJ,mBAAc,OAAO,GAAG,KAAK,KAAK,WAAU,SAAI,aAAJ,mBAAc,IAAI,CAAC;AAAA,EACpI,WAAW,eAAe,OAAO;AAC/B,WAAO,IAAI;AAAA,EACb,OAAO;AACL,WAAO,qBAAqB,iBAAiB,GAAG,KAAK,GAAG;AAAA,EAC1D;AACF;","names":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import ReconnectingWebSocket from "reconnecting-websocket";
|
|
2
|
+
import * as v2 from "./v2/mock/MockNovaInstance";
|
|
3
|
+
import * as v1 from "./v1/mock/MockNovaInstance";
|
|
4
|
+
export declare class AutoReconnectingWebsocket extends ReconnectingWebSocket {
|
|
5
|
+
readonly opts: {
|
|
6
|
+
mock?: v1.MockNovaInstance | v2.MockNovaInstance;
|
|
7
|
+
onDispose?: () => void;
|
|
8
|
+
};
|
|
9
|
+
receivedFirstMessage?: MessageEvent;
|
|
10
|
+
targetUrl: string;
|
|
11
|
+
disposed: boolean;
|
|
12
|
+
constructor(targetUrl: string, opts?: {
|
|
13
|
+
mock?: v1.MockNovaInstance | v2.MockNovaInstance;
|
|
14
|
+
onDispose?: () => void;
|
|
15
|
+
});
|
|
16
|
+
changeUrl(targetUrl: string): void;
|
|
17
|
+
sendJson(data: unknown): void;
|
|
18
|
+
/**
|
|
19
|
+
* Permanently close this websocket and indicate that
|
|
20
|
+
* this object should not be used again.
|
|
21
|
+
**/
|
|
22
|
+
dispose(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Returns a promise that resolves once the websocket
|
|
25
|
+
* is in the OPEN state. */
|
|
26
|
+
opened(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a promise that resolves once the websocket
|
|
29
|
+
* is in the CLOSED state. */
|
|
30
|
+
closed(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a promise that resolves when the first message
|
|
33
|
+
* is received from the websocket. Resolves immediately if
|
|
34
|
+
* the first message has already been received.
|
|
35
|
+
*/
|
|
36
|
+
firstMessage(): Promise<MessageEvent<any>>;
|
|
37
|
+
/**
|
|
38
|
+
* Returns a promise that resolves when the next message
|
|
39
|
+
* is received from the websocket.
|
|
40
|
+
*/
|
|
41
|
+
nextMessage(): Promise<MessageEvent<any>>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=AutoReconnectingWebsocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoReconnectingWebsocket.d.ts","sourceRoot":"","sources":["../../src/lib/AutoReconnectingWebsocket.ts"],"names":[],"mappings":"AAAA,OAAO,qBAA0C,MAAM,wBAAwB,CAAA;AAC/E,OAAO,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAChD,OAAO,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAEhD,qBAAa,yBAA0B,SAAQ,qBAAqB;IAOhE,QAAQ,CAAC,IAAI,EAAE;QACb,IAAI,CAAC,EAAE,EAAE,CAAC,gBAAgB,GAAG,EAAE,CAAC,gBAAgB,CAAA;QAChD,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;KACvB;IATH,oBAAoB,CAAC,EAAE,YAAY,CAAA;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,UAAQ;gBAGd,SAAS,EAAE,MAAM,EACR,IAAI,GAAE;QACb,IAAI,CAAC,EAAE,EAAE,CAAC,gBAAgB,GAAG,EAAE,CAAC,gBAAgB,CAAA;QAChD,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;KAClB;IA2CR,SAAS,CAAC,SAAS,EAAE,MAAM;IAM3B,QAAQ,CAAC,IAAI,EAAE,OAAO;IAQtB;;;QAGI;IACJ,OAAO;IAQP;;+BAE2B;IACrB,MAAM;IAWZ;;iCAE6B;IACvB,MAAM;IAWZ;;;;OAIG;IACG,YAAY;IAwBlB;;;OAGG;IACG,WAAW;CAkBlB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safety wrapper around browser localStorage providing context availability
|
|
3
|
+
* checks and JSON parsing
|
|
4
|
+
*/
|
|
5
|
+
declare class AvailableStorage {
|
|
6
|
+
available: boolean;
|
|
7
|
+
getJSON<T>(key: string): Partial<T> | null;
|
|
8
|
+
setJSON(key: string, obj: any): null | undefined;
|
|
9
|
+
delete(key: string): null | undefined;
|
|
10
|
+
setString(key: string, value: string): null | undefined;
|
|
11
|
+
getString(key: string): string | null;
|
|
12
|
+
}
|
|
13
|
+
export declare const availableStorage: AvailableStorage;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=availableStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"availableStorage.d.ts","sourceRoot":"","sources":["../../src/lib/availableStorage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAM,gBAAgB;IACpB,SAAS,UAAyD;IAElE,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI;IAa1C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;IAM7B,MAAM,CAAC,GAAG,EAAE,MAAM;IAMlB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAMpC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAKtC;AAED,eAAO,MAAM,gBAAgB,kBAAyB,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Pose } from "@wandelbots/nova-api/v1";
|
|
2
|
+
/** Try to parse something as JSON; return undefined if we can't */
|
|
3
|
+
export declare function tryParseJson(json: unknown): any;
|
|
4
|
+
/** Try to turn something into JSON; return undefined if we can't */
|
|
5
|
+
export declare function tryStringifyJson(json: unknown): string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Converts object parameters to query string.
|
|
8
|
+
* e.g. { a: "1", b: "2" } => "?a=1&b=2"
|
|
9
|
+
* {} => ""
|
|
10
|
+
*/
|
|
11
|
+
export declare function makeUrlQueryString(obj: Record<string, string>): string;
|
|
12
|
+
/** Convert radians to degrees */
|
|
13
|
+
export declare function radiansToDegrees(radians: number): number;
|
|
14
|
+
/** Convert degrees to radians */
|
|
15
|
+
export declare function degreesToRadians(degrees: number): number;
|
|
16
|
+
/**
|
|
17
|
+
* Convert a Pose object representing a motion group position
|
|
18
|
+
* into a string which represents that pose in Wandelscript.
|
|
19
|
+
*/
|
|
20
|
+
export declare function poseToWandelscriptString(pose: Pick<Pose, "position" | "orientation">): string;
|
|
21
|
+
/**
|
|
22
|
+
* Check for coordinate system id equivalence, accounting for the "world" default
|
|
23
|
+
* on empty/undefined values.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isSameCoordinateSystem(firstCoordSystem: string | undefined, secondCoordSystem: string | undefined): boolean;
|
|
26
|
+
//# sourceMappingURL=converters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../src/lib/converters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAEnD,mEAAmE;AACnE,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG,CAM/C;AAED,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMlE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAGtE;AAED,iCAAiC;AACjC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,iCAAiC;AACjC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,aAAa,CAAC,UAc7C;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,iBAAiB,EAAE,MAAM,GAAG,SAAS,WAMtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorHandling.d.ts","sourceRoot":"","sources":["../../src/lib/errorHandling.ts"],"names":[],"mappings":"AAGA,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAE/B;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,UAQjD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,UAQ5C"}
|