@wandelbots/nova-js 3.3.2 → 3.3.3
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/dist/{LoginWithAuth0-wQB-Sol1.mjs → LoginWithAuth0-DBe9CXOr.mjs} +97 -13
- package/dist/LoginWithAuth0-DBe9CXOr.mjs.map +1 -0
- package/dist/{LoginWithAuth0-CBD9BXXz.cjs → LoginWithAuth0-iXpPiCcz.cjs} +162 -12
- package/dist/LoginWithAuth0-iXpPiCcz.cjs.map +1 -0
- package/dist/{NovaClient-qJnHcx2s.d.mts → NovaClient-C0GXOu4w.d.mts} +2 -1
- package/dist/{NovaClient-CV7ooIkD.d.cts.map → NovaClient-C0GXOu4w.d.mts.map} +1 -1
- package/dist/{NovaClient-B8XM3OPO.mjs → NovaClient-C27dk3Ql.mjs} +12 -64
- package/dist/NovaClient-C27dk3Ql.mjs.map +1 -0
- package/dist/{NovaClient-CV7ooIkD.d.cts → NovaClient-PNinV5c4.d.cts} +2 -1
- package/dist/{NovaClient-qJnHcx2s.d.mts.map → NovaClient-PNinV5c4.d.cts.map} +1 -1
- package/dist/{NovaClient-D2EItmiH.cjs → NovaClient-j40sHBBq.cjs} +20 -114
- package/dist/NovaClient-j40sHBBq.cjs.map +1 -0
- package/dist/index.cjs +14 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +34 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/lib/v1/index.cjs +3 -3
- package/dist/lib/v1/index.cjs.map +1 -1
- package/dist/lib/v1/index.d.cts +1 -1
- package/dist/lib/v1/index.d.mts +1 -1
- package/dist/lib/v1/index.mjs +2 -2
- package/dist/lib/v2/index.cjs +11 -10
- package/dist/lib/v2/index.cjs.map +1 -1
- package/dist/lib/v2/index.d.cts +1 -0
- package/dist/lib/v2/index.d.cts.map +1 -1
- package/dist/lib/v2/index.d.mts +1 -0
- package/dist/lib/v2/index.d.mts.map +1 -1
- package/dist/lib/v2/index.mjs +11 -10
- package/dist/lib/v2/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/LoginWithAuth0.ts +13 -15
- package/src/lib/converters.ts +61 -0
- package/src/lib/v1/NovaClient.ts +14 -15
- package/src/lib/v2/NovaClient.ts +15 -16
- package/dist/LoginWithAuth0-CBD9BXXz.cjs.map +0 -1
- package/dist/LoginWithAuth0-wQB-Sol1.mjs.map +0 -1
- package/dist/NovaClient-B8XM3OPO.mjs.map +0 -1
- package/dist/NovaClient-D2EItmiH.cjs.map +0 -1
|
@@ -153,9 +153,93 @@ var AvailableStorage = class {
|
|
|
153
153
|
};
|
|
154
154
|
const availableStorage = new AvailableStorage();
|
|
155
155
|
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/lib/converters.ts
|
|
158
|
+
/**
|
|
159
|
+
* Parse a string as a URL, with options to enforce or default the scheme.
|
|
160
|
+
*/
|
|
161
|
+
function parseUrl(url, options = {}) {
|
|
162
|
+
const { scheme, defaultScheme } = options;
|
|
163
|
+
const schemeRegex = /^[a-zA-Z]+:\/\//;
|
|
164
|
+
if (scheme) {
|
|
165
|
+
url = url.replace(schemeRegex, "");
|
|
166
|
+
url = `${scheme}://${url}`;
|
|
167
|
+
} else if (defaultScheme && !schemeRegex.test(url)) url = `${defaultScheme}://${url}`;
|
|
168
|
+
return new URL(url);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Attempt to parse a string as a URL; return undefined if we can't
|
|
172
|
+
*/
|
|
173
|
+
function tryParseUrl(url, options = {}) {
|
|
174
|
+
try {
|
|
175
|
+
return parseUrl(url, options);
|
|
176
|
+
} catch {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Permissively parse a NOVA instance URL from a config variable.
|
|
182
|
+
* If scheme is not specified, defaults to https for *.wandelbots.io hosts,
|
|
183
|
+
* and http otherwise.
|
|
184
|
+
* Throws an error if a valid URL could not be determined.
|
|
185
|
+
*/
|
|
186
|
+
function parseNovaInstanceUrl(url) {
|
|
187
|
+
if (tryParseUrl(url, { defaultScheme: "http" })?.host.endsWith(".wandelbots.io")) return parseUrl(url, { defaultScheme: "https" });
|
|
188
|
+
else return parseUrl(url, { defaultScheme: "http" });
|
|
189
|
+
}
|
|
190
|
+
/** Try to parse something as JSON; return undefined if we can't */
|
|
191
|
+
function tryParseJson(json) {
|
|
192
|
+
try {
|
|
193
|
+
return JSON.parse(json);
|
|
194
|
+
} catch {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/** Try to turn something into JSON; return undefined if we can't */
|
|
199
|
+
function tryStringifyJson(json) {
|
|
200
|
+
try {
|
|
201
|
+
return JSON.stringify(json);
|
|
202
|
+
} catch {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Converts object parameters to query string.
|
|
208
|
+
* e.g. { a: "1", b: "2" } => "?a=1&b=2"
|
|
209
|
+
* {} => ""
|
|
210
|
+
*/
|
|
211
|
+
function makeUrlQueryString(obj) {
|
|
212
|
+
const str = new URLSearchParams(obj).toString();
|
|
213
|
+
return str ? `?${str}` : "";
|
|
214
|
+
}
|
|
215
|
+
/** Convert radians to degrees */
|
|
216
|
+
function radiansToDegrees(radians) {
|
|
217
|
+
return radians * (180 / Math.PI);
|
|
218
|
+
}
|
|
219
|
+
/** Convert degrees to radians */
|
|
220
|
+
function degreesToRadians(degrees) {
|
|
221
|
+
return degrees * (Math.PI / 180);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Check for coordinate system id equivalence, accounting for the "world" default
|
|
225
|
+
* on empty/undefined values.
|
|
226
|
+
*/
|
|
227
|
+
function isSameCoordinateSystem(firstCoordSystem, secondCoordSystem) {
|
|
228
|
+
if (!firstCoordSystem) firstCoordSystem = "world";
|
|
229
|
+
if (!secondCoordSystem) secondCoordSystem = "world";
|
|
230
|
+
return firstCoordSystem === secondCoordSystem;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Helpful const for converting {x, y, z} to [x, y, z] and vice versa
|
|
234
|
+
*/
|
|
235
|
+
const XYZ_TO_VECTOR = {
|
|
236
|
+
x: 0,
|
|
237
|
+
y: 1,
|
|
238
|
+
z: 2
|
|
239
|
+
};
|
|
240
|
+
|
|
156
241
|
//#endregion
|
|
157
242
|
//#region src/LoginWithAuth0.ts
|
|
158
|
-
const DOMAIN_SUFFIX = "wandelbots.io";
|
|
159
243
|
/**
|
|
160
244
|
* Mapping of stages to Auth0 configurations.
|
|
161
245
|
* The client ids are public identifiers for a specific auth0 application
|
|
@@ -164,24 +248,24 @@ const DOMAIN_SUFFIX = "wandelbots.io";
|
|
|
164
248
|
*/
|
|
165
249
|
const auth0ConfigMap = {
|
|
166
250
|
dev: {
|
|
167
|
-
domain: `https://auth.portal.dev
|
|
251
|
+
domain: `https://auth.portal.dev.wandelbots.io`,
|
|
168
252
|
clientId: "fLbJD0RLp5r2Dpucm5j8BjwMR6Hunfha"
|
|
169
253
|
},
|
|
170
254
|
stg: {
|
|
171
|
-
domain: `https://auth.portal.stg
|
|
255
|
+
domain: `https://auth.portal.stg.wandelbots.io`,
|
|
172
256
|
clientId: "joVDeD9e786WzFNSGCqoVq7HNkWt5j6s"
|
|
173
257
|
},
|
|
174
258
|
prod: {
|
|
175
|
-
domain: `https://auth.portal
|
|
259
|
+
domain: `https://auth.portal.wandelbots.io`,
|
|
176
260
|
clientId: "J7WJUi38xVQdJAEBNRT9Xw1b0fXDb4J2"
|
|
177
261
|
}
|
|
178
262
|
};
|
|
179
|
-
/** Determine which Auth0 configuration to use based on instance URL
|
|
263
|
+
/** Determine which Auth0 configuration to use based on instance URL */
|
|
180
264
|
const getAuth0Config = (instanceUrl) => {
|
|
181
|
-
if (instanceUrl.endsWith(
|
|
182
|
-
if (instanceUrl.endsWith(
|
|
183
|
-
if (instanceUrl.endsWith(
|
|
184
|
-
throw new Error(
|
|
265
|
+
if (instanceUrl.host.endsWith(".dev.wandelbots.io")) return auth0ConfigMap.dev;
|
|
266
|
+
if (instanceUrl.host.endsWith(".stg.wandelbots.io")) return auth0ConfigMap.stg;
|
|
267
|
+
if (instanceUrl.host.endsWith(".wandelbots.io")) return auth0ConfigMap.prod;
|
|
268
|
+
throw new Error(`Unable to authenticate with NOVA instance "${instanceUrl}". Auth0 login is only supported for cloud instances with hosts of the form "**.wandelbots.io".`);
|
|
185
269
|
};
|
|
186
270
|
/**
|
|
187
271
|
* Initializes Auth0 login process using redirect if necessary and retrieves an access token.
|
|
@@ -190,12 +274,12 @@ const getAuth0Config = (instanceUrl) => {
|
|
|
190
274
|
*/
|
|
191
275
|
const loginWithAuth0 = async (instanceUrl) => {
|
|
192
276
|
if (typeof window === "undefined") throw new Error(`Access token must be set to use NovaClient when not in a browser environment.`);
|
|
193
|
-
|
|
194
|
-
if (new URL(instanceUrl).origin === window.location.origin) {
|
|
277
|
+
if (instanceUrl.origin === window.location.origin) {
|
|
195
278
|
window.location.reload();
|
|
196
279
|
throw new Error("Failed to reload page to get auth details, please refresh manually");
|
|
197
280
|
}
|
|
198
281
|
const { Auth0Client } = await import("@auth0/auth0-spa-js");
|
|
282
|
+
const auth0Config = getAuth0Config(instanceUrl);
|
|
199
283
|
const auth0Client = new Auth0Client({
|
|
200
284
|
domain: auth0Config.domain,
|
|
201
285
|
clientId: auth0Config.clientId ?? "",
|
|
@@ -213,5 +297,5 @@ const loginWithAuth0 = async (instanceUrl) => {
|
|
|
213
297
|
};
|
|
214
298
|
|
|
215
299
|
//#endregion
|
|
216
|
-
export {
|
|
217
|
-
//# sourceMappingURL=LoginWithAuth0-
|
|
300
|
+
export { isSameCoordinateSystem as a, parseUrl as c, tryParseUrl as d, tryStringifyJson as f, degreesToRadians as i, radiansToDegrees as l, AutoReconnectingWebsocket as m, loginWithAuth0 as n, makeUrlQueryString as o, availableStorage as p, XYZ_TO_VECTOR as r, parseNovaInstanceUrl as s, getAuth0Config as t, tryParseJson as u };
|
|
301
|
+
//# sourceMappingURL=LoginWithAuth0-DBe9CXOr.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoginWithAuth0-DBe9CXOr.mjs","names":["opts: {\n mock?: v1.MockNovaInstance | v2.MockNovaInstance\n onDispose?: () => void\n }"],"sources":["../src/lib/AutoReconnectingWebsocket.ts","../src/lib/availableStorage.ts","../src/lib/converters.ts","../src/LoginWithAuth0.ts"],"sourcesContent":["import ReconnectingWebSocket, { type ErrorEvent } from \"reconnecting-websocket\"\nimport type * as v1 from \"./v1/mock/MockNovaInstance\"\nimport type * as v2 from \"./v2/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: unknown) {\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","export type URLParseOptions = {\n /**\n * Ignore any scheme in the input string and force this scheme instead.\n */\n scheme?: \"http\" | \"https\"\n /**\n * If the input string does not include a scheme, use this as the default\n * scheme.\n */\n defaultScheme?: \"http\" | \"https\"\n}\n\n/**\n * Parse a string as a URL, with options to enforce or default the scheme.\n */\nexport function parseUrl(url: string, options: URLParseOptions = {}): URL {\n const { scheme, defaultScheme } = options\n\n const schemeRegex = /^[a-zA-Z]+:\\/\\//\n\n if (scheme) {\n // Force the scheme by removing any existing scheme and prepending the desired one\n url = url.replace(schemeRegex, \"\")\n url = `${scheme}://${url}`\n } else if (defaultScheme && !schemeRegex.test(url)) {\n // No scheme is present, add the default one\n url = `${defaultScheme}://${url}`\n }\n\n return new URL(url)\n}\n\n/**\n * Attempt to parse a string as a URL; return undefined if we can't\n */\nexport function tryParseUrl(\n url: string,\n options: URLParseOptions = {},\n): URL | undefined {\n try {\n return parseUrl(url, options)\n } catch {\n return undefined\n }\n}\n\n/**\n * Permissively parse a NOVA instance URL from a config variable.\n * If scheme is not specified, defaults to https for *.wandelbots.io hosts,\n * and http otherwise.\n * Throws an error if a valid URL could not be determined.\n */\nexport function parseNovaInstanceUrl(url: string): URL {\n const testUrl = tryParseUrl(url, { defaultScheme: \"http\" })\n if (testUrl?.host.endsWith(\".wandelbots.io\")) {\n return parseUrl(url, { defaultScheme: \"https\" })\n } else {\n return parseUrl(url, { defaultScheme: \"http\" })\n }\n}\n\n/** Try to parse something as JSON; return undefined if we can't */\n// biome-ignore lint/suspicious/noExplicitAny: it's json\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 * 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\n/**\n * Helpful const for converting {x, y, z} to [x, y, z] and vice versa\n */\nexport const XYZ_TO_VECTOR = { x: 0, y: 1, z: 2 }\n","/**\n * Mapping of stages to Auth0 configurations.\n * The client ids are public identifiers for a specific auth0 application\n * and are safe to include in client-side code.\n * https://auth0.com/docs/get-started/applications/application-settings\n */\nconst auth0ConfigMap = {\n dev: {\n domain: `https://auth.portal.dev.wandelbots.io`,\n clientId: \"fLbJD0RLp5r2Dpucm5j8BjwMR6Hunfha\",\n },\n stg: {\n domain: `https://auth.portal.stg.wandelbots.io`,\n clientId: \"joVDeD9e786WzFNSGCqoVq7HNkWt5j6s\",\n },\n prod: {\n domain: `https://auth.portal.wandelbots.io`,\n clientId: \"J7WJUi38xVQdJAEBNRT9Xw1b0fXDb4J2\",\n },\n}\n\n/** Determine which Auth0 configuration to use based on instance URL */\nexport const getAuth0Config = (instanceUrl: URL) => {\n if (instanceUrl.host.endsWith(\".dev.wandelbots.io\")) return auth0ConfigMap.dev\n if (instanceUrl.host.endsWith(\".stg.wandelbots.io\")) return auth0ConfigMap.stg\n if (instanceUrl.host.endsWith(\".wandelbots.io\")) return auth0ConfigMap.prod\n throw new Error(\n `Unable to authenticate with NOVA instance \"${instanceUrl}\". Auth0 login is only supported for cloud instances with hosts of the form \"**.wandelbots.io\".`,\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: URL,\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 if (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 auth0Config = getAuth0Config(instanceUrl)\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":";;;AAIA,IAAa,4BAAb,cAA+C,sBAAsB;CAKnE,YACE,WACA,AAASA,OAGL,EAAE,EACN;AACA,UAAQ,IAAI,wBAAwB,UAAU;AAE9C,cAAY,KAAK,aAAa,WAAW,QAAW,EAClD,aAAa,MACd,CAAC;EATO;kBAJA;AAgBT,SAAO,eAAe,MAAM,OAAO,EACjC,MAAM;AACJ,UAAO,KAAK;KAEf,CAAC;AAEF,OAAK,YAAY;AAEjB,OAAK,iBAAiB,cAAc;AAClC,WAAQ,IAAI,gBAAgB,KAAK,IAAI,SAAS;IAC9C;AAEF,OAAK,iBAAiB,YAAY,OAAO;AACvC,OAAI,CAAC,KAAK,qBACR,MAAK,uBAAuB;IAE9B;AAEF,OAAK,iBAAiB,eAAe;AACnC,WAAQ,IAAI,gBAAgB,KAAK,IAAI,SAAS;IAC9C;EAEF,MAAM,gBAAgB,KAAK;AAC3B,OAAK,kBAAkB;AACrB,OAAI,KAAK,KAAK,KACZ,MAAK,KAAK,KAAK,0BAA0B,KAAK;OAE9C,eAAc,MAAM,KAAK;;AAI7B,OAAK,WAAW;;CAGlB,UAAU,WAAmB;AAC3B,OAAK,uBAAuB;AAC5B,OAAK,YAAY;AACjB,OAAK,WAAW;;CAGlB,SAAS,MAAe;AACtB,MAAI,KAAK,KAAK,KACZ,MAAK,KAAK,KAAK,uBAAuB,MAAM,KAAK,UAAU,KAAK,CAAC;MAEjE,MAAK,KAAK,KAAK,UAAU,KAAK,CAAC;;;;;;CAQnC,UAAU;AACR,OAAK,OAAO;AACZ,OAAK,WAAW;A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,QAAQ;AAIjD,SAAO,SAAS,QAAQ;AACxB,QAAM,IAAI,MACR,qEACD;;CAMH,MAAM,EAAE,gBAAgB,MAAM,OAAO;CAErC,MAAM,cAAc,eAAe,YAAY;CAE/C,MAAM,cAAc,IAAI,YAAY;EAClC,QAAQ,YAAY;EACpB,UAAU,YAAY,YAAY;EAClC,kBAAkB;EAClB,qBAAqB;GACnB,UAAU;GACV,cAAc,OAAO,SAAS;GAC/B;EACF,CAAC;AAGF,KACE,OAAO,SAAS,OAAO,SAAS,QAAQ,IACxC,OAAO,SAAS,OAAO,SAAS,SAAS,EACzC;EACA,MAAM,EAAE,aAAa,MAAM,YAAY,wBAAwB;AAE/D,SAAO,QAAQ,aACb,EAAE,EACF,SAAS,OACT,UAAU,YAAY,OAAO,SAAS,SACvC;OAGD,OAAM,YAAY,mBAAmB;AAKvC,QADoB,MAAM,YAAY,kBAAkB"}
|
|
@@ -177,9 +177,93 @@ var AvailableStorage = class {
|
|
|
177
177
|
};
|
|
178
178
|
const availableStorage = new AvailableStorage();
|
|
179
179
|
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/lib/converters.ts
|
|
182
|
+
/**
|
|
183
|
+
* Parse a string as a URL, with options to enforce or default the scheme.
|
|
184
|
+
*/
|
|
185
|
+
function parseUrl(url, options = {}) {
|
|
186
|
+
const { scheme, defaultScheme } = options;
|
|
187
|
+
const schemeRegex = /^[a-zA-Z]+:\/\//;
|
|
188
|
+
if (scheme) {
|
|
189
|
+
url = url.replace(schemeRegex, "");
|
|
190
|
+
url = `${scheme}://${url}`;
|
|
191
|
+
} else if (defaultScheme && !schemeRegex.test(url)) url = `${defaultScheme}://${url}`;
|
|
192
|
+
return new URL(url);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Attempt to parse a string as a URL; return undefined if we can't
|
|
196
|
+
*/
|
|
197
|
+
function tryParseUrl(url, options = {}) {
|
|
198
|
+
try {
|
|
199
|
+
return parseUrl(url, options);
|
|
200
|
+
} catch {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Permissively parse a NOVA instance URL from a config variable.
|
|
206
|
+
* If scheme is not specified, defaults to https for *.wandelbots.io hosts,
|
|
207
|
+
* and http otherwise.
|
|
208
|
+
* Throws an error if a valid URL could not be determined.
|
|
209
|
+
*/
|
|
210
|
+
function parseNovaInstanceUrl(url) {
|
|
211
|
+
if (tryParseUrl(url, { defaultScheme: "http" })?.host.endsWith(".wandelbots.io")) return parseUrl(url, { defaultScheme: "https" });
|
|
212
|
+
else return parseUrl(url, { defaultScheme: "http" });
|
|
213
|
+
}
|
|
214
|
+
/** Try to parse something as JSON; return undefined if we can't */
|
|
215
|
+
function tryParseJson(json) {
|
|
216
|
+
try {
|
|
217
|
+
return JSON.parse(json);
|
|
218
|
+
} catch {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/** Try to turn something into JSON; return undefined if we can't */
|
|
223
|
+
function tryStringifyJson(json) {
|
|
224
|
+
try {
|
|
225
|
+
return JSON.stringify(json);
|
|
226
|
+
} catch {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Converts object parameters to query string.
|
|
232
|
+
* e.g. { a: "1", b: "2" } => "?a=1&b=2"
|
|
233
|
+
* {} => ""
|
|
234
|
+
*/
|
|
235
|
+
function makeUrlQueryString(obj) {
|
|
236
|
+
const str = new URLSearchParams(obj).toString();
|
|
237
|
+
return str ? `?${str}` : "";
|
|
238
|
+
}
|
|
239
|
+
/** Convert radians to degrees */
|
|
240
|
+
function radiansToDegrees(radians) {
|
|
241
|
+
return radians * (180 / Math.PI);
|
|
242
|
+
}
|
|
243
|
+
/** Convert degrees to radians */
|
|
244
|
+
function degreesToRadians(degrees) {
|
|
245
|
+
return degrees * (Math.PI / 180);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Check for coordinate system id equivalence, accounting for the "world" default
|
|
249
|
+
* on empty/undefined values.
|
|
250
|
+
*/
|
|
251
|
+
function isSameCoordinateSystem(firstCoordSystem, secondCoordSystem) {
|
|
252
|
+
if (!firstCoordSystem) firstCoordSystem = "world";
|
|
253
|
+
if (!secondCoordSystem) secondCoordSystem = "world";
|
|
254
|
+
return firstCoordSystem === secondCoordSystem;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Helpful const for converting {x, y, z} to [x, y, z] and vice versa
|
|
258
|
+
*/
|
|
259
|
+
const XYZ_TO_VECTOR = {
|
|
260
|
+
x: 0,
|
|
261
|
+
y: 1,
|
|
262
|
+
z: 2
|
|
263
|
+
};
|
|
264
|
+
|
|
180
265
|
//#endregion
|
|
181
266
|
//#region src/LoginWithAuth0.ts
|
|
182
|
-
const DOMAIN_SUFFIX = "wandelbots.io";
|
|
183
267
|
/**
|
|
184
268
|
* Mapping of stages to Auth0 configurations.
|
|
185
269
|
* The client ids are public identifiers for a specific auth0 application
|
|
@@ -188,24 +272,24 @@ const DOMAIN_SUFFIX = "wandelbots.io";
|
|
|
188
272
|
*/
|
|
189
273
|
const auth0ConfigMap = {
|
|
190
274
|
dev: {
|
|
191
|
-
domain: `https://auth.portal.dev
|
|
275
|
+
domain: `https://auth.portal.dev.wandelbots.io`,
|
|
192
276
|
clientId: "fLbJD0RLp5r2Dpucm5j8BjwMR6Hunfha"
|
|
193
277
|
},
|
|
194
278
|
stg: {
|
|
195
|
-
domain: `https://auth.portal.stg
|
|
279
|
+
domain: `https://auth.portal.stg.wandelbots.io`,
|
|
196
280
|
clientId: "joVDeD9e786WzFNSGCqoVq7HNkWt5j6s"
|
|
197
281
|
},
|
|
198
282
|
prod: {
|
|
199
|
-
domain: `https://auth.portal
|
|
283
|
+
domain: `https://auth.portal.wandelbots.io`,
|
|
200
284
|
clientId: "J7WJUi38xVQdJAEBNRT9Xw1b0fXDb4J2"
|
|
201
285
|
}
|
|
202
286
|
};
|
|
203
|
-
/** Determine which Auth0 configuration to use based on instance URL
|
|
287
|
+
/** Determine which Auth0 configuration to use based on instance URL */
|
|
204
288
|
const getAuth0Config = (instanceUrl) => {
|
|
205
|
-
if (instanceUrl.endsWith(
|
|
206
|
-
if (instanceUrl.endsWith(
|
|
207
|
-
if (instanceUrl.endsWith(
|
|
208
|
-
throw new Error(
|
|
289
|
+
if (instanceUrl.host.endsWith(".dev.wandelbots.io")) return auth0ConfigMap.dev;
|
|
290
|
+
if (instanceUrl.host.endsWith(".stg.wandelbots.io")) return auth0ConfigMap.stg;
|
|
291
|
+
if (instanceUrl.host.endsWith(".wandelbots.io")) return auth0ConfigMap.prod;
|
|
292
|
+
throw new Error(`Unable to authenticate with NOVA instance "${instanceUrl}". Auth0 login is only supported for cloud instances with hosts of the form "**.wandelbots.io".`);
|
|
209
293
|
};
|
|
210
294
|
/**
|
|
211
295
|
* Initializes Auth0 login process using redirect if necessary and retrieves an access token.
|
|
@@ -214,12 +298,12 @@ const getAuth0Config = (instanceUrl) => {
|
|
|
214
298
|
*/
|
|
215
299
|
const loginWithAuth0 = async (instanceUrl) => {
|
|
216
300
|
if (typeof window === "undefined") throw new Error(`Access token must be set to use NovaClient when not in a browser environment.`);
|
|
217
|
-
|
|
218
|
-
if (new URL(instanceUrl).origin === window.location.origin) {
|
|
301
|
+
if (instanceUrl.origin === window.location.origin) {
|
|
219
302
|
window.location.reload();
|
|
220
303
|
throw new Error("Failed to reload page to get auth details, please refresh manually");
|
|
221
304
|
}
|
|
222
305
|
const { Auth0Client } = await import("@auth0/auth0-spa-js");
|
|
306
|
+
const auth0Config = getAuth0Config(instanceUrl);
|
|
223
307
|
const auth0Client = new Auth0Client({
|
|
224
308
|
domain: auth0Config.domain,
|
|
225
309
|
clientId: auth0Config.clientId ?? "",
|
|
@@ -243,6 +327,12 @@ Object.defineProperty(exports, 'AutoReconnectingWebsocket', {
|
|
|
243
327
|
return AutoReconnectingWebsocket;
|
|
244
328
|
}
|
|
245
329
|
});
|
|
330
|
+
Object.defineProperty(exports, 'XYZ_TO_VECTOR', {
|
|
331
|
+
enumerable: true,
|
|
332
|
+
get: function () {
|
|
333
|
+
return XYZ_TO_VECTOR;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
246
336
|
Object.defineProperty(exports, '__toESM', {
|
|
247
337
|
enumerable: true,
|
|
248
338
|
get: function () {
|
|
@@ -255,10 +345,70 @@ Object.defineProperty(exports, 'availableStorage', {
|
|
|
255
345
|
return availableStorage;
|
|
256
346
|
}
|
|
257
347
|
});
|
|
348
|
+
Object.defineProperty(exports, 'degreesToRadians', {
|
|
349
|
+
enumerable: true,
|
|
350
|
+
get: function () {
|
|
351
|
+
return degreesToRadians;
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
Object.defineProperty(exports, 'getAuth0Config', {
|
|
355
|
+
enumerable: true,
|
|
356
|
+
get: function () {
|
|
357
|
+
return getAuth0Config;
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
Object.defineProperty(exports, 'isSameCoordinateSystem', {
|
|
361
|
+
enumerable: true,
|
|
362
|
+
get: function () {
|
|
363
|
+
return isSameCoordinateSystem;
|
|
364
|
+
}
|
|
365
|
+
});
|
|
258
366
|
Object.defineProperty(exports, 'loginWithAuth0', {
|
|
259
367
|
enumerable: true,
|
|
260
368
|
get: function () {
|
|
261
369
|
return loginWithAuth0;
|
|
262
370
|
}
|
|
263
371
|
});
|
|
264
|
-
|
|
372
|
+
Object.defineProperty(exports, 'makeUrlQueryString', {
|
|
373
|
+
enumerable: true,
|
|
374
|
+
get: function () {
|
|
375
|
+
return makeUrlQueryString;
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
Object.defineProperty(exports, 'parseNovaInstanceUrl', {
|
|
379
|
+
enumerable: true,
|
|
380
|
+
get: function () {
|
|
381
|
+
return parseNovaInstanceUrl;
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
Object.defineProperty(exports, 'parseUrl', {
|
|
385
|
+
enumerable: true,
|
|
386
|
+
get: function () {
|
|
387
|
+
return parseUrl;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
Object.defineProperty(exports, 'radiansToDegrees', {
|
|
391
|
+
enumerable: true,
|
|
392
|
+
get: function () {
|
|
393
|
+
return radiansToDegrees;
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
Object.defineProperty(exports, 'tryParseJson', {
|
|
397
|
+
enumerable: true,
|
|
398
|
+
get: function () {
|
|
399
|
+
return tryParseJson;
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
Object.defineProperty(exports, 'tryParseUrl', {
|
|
403
|
+
enumerable: true,
|
|
404
|
+
get: function () {
|
|
405
|
+
return tryParseUrl;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
Object.defineProperty(exports, 'tryStringifyJson', {
|
|
409
|
+
enumerable: true,
|
|
410
|
+
get: function () {
|
|
411
|
+
return tryStringifyJson;
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
//# sourceMappingURL=LoginWithAuth0-iXpPiCcz.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoginWithAuth0-iXpPiCcz.cjs","names":["ReconnectingWebSocket","opts: {\n mock?: v1.MockNovaInstance | v2.MockNovaInstance\n onDispose?: () => void\n }"],"sources":["../src/lib/AutoReconnectingWebsocket.ts","../src/lib/availableStorage.ts","../src/lib/converters.ts","../src/LoginWithAuth0.ts"],"sourcesContent":["import ReconnectingWebSocket, { type ErrorEvent } from \"reconnecting-websocket\"\nimport type * as v1 from \"./v1/mock/MockNovaInstance\"\nimport type * as v2 from \"./v2/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: unknown) {\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","export type URLParseOptions = {\n /**\n * Ignore any scheme in the input string and force this scheme instead.\n */\n scheme?: \"http\" | \"https\"\n /**\n * If the input string does not include a scheme, use this as the default\n * scheme.\n */\n defaultScheme?: \"http\" | \"https\"\n}\n\n/**\n * Parse a string as a URL, with options to enforce or default the scheme.\n */\nexport function parseUrl(url: string, options: URLParseOptions = {}): URL {\n const { scheme, defaultScheme } = options\n\n const schemeRegex = /^[a-zA-Z]+:\\/\\//\n\n if (scheme) {\n // Force the scheme by removing any existing scheme and prepending the desired one\n url = url.replace(schemeRegex, \"\")\n url = `${scheme}://${url}`\n } else if (defaultScheme && !schemeRegex.test(url)) {\n // No scheme is present, add the default one\n url = `${defaultScheme}://${url}`\n }\n\n return new URL(url)\n}\n\n/**\n * Attempt to parse a string as a URL; return undefined if we can't\n */\nexport function tryParseUrl(\n url: string,\n options: URLParseOptions = {},\n): URL | undefined {\n try {\n return parseUrl(url, options)\n } catch {\n return undefined\n }\n}\n\n/**\n * Permissively parse a NOVA instance URL from a config variable.\n * If scheme is not specified, defaults to https for *.wandelbots.io hosts,\n * and http otherwise.\n * Throws an error if a valid URL could not be determined.\n */\nexport function parseNovaInstanceUrl(url: string): URL {\n const testUrl = tryParseUrl(url, { defaultScheme: \"http\" })\n if (testUrl?.host.endsWith(\".wandelbots.io\")) {\n return parseUrl(url, { defaultScheme: \"https\" })\n } else {\n return parseUrl(url, { defaultScheme: \"http\" })\n }\n}\n\n/** Try to parse something as JSON; return undefined if we can't */\n// biome-ignore lint/suspicious/noExplicitAny: it's json\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 * 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\n/**\n * Helpful const for converting {x, y, z} to [x, y, z] and vice versa\n */\nexport const XYZ_TO_VECTOR = { x: 0, y: 1, z: 2 }\n","/**\n * Mapping of stages to Auth0 configurations.\n * The client ids are public identifiers for a specific auth0 application\n * and are safe to include in client-side code.\n * https://auth0.com/docs/get-started/applications/application-settings\n */\nconst auth0ConfigMap = {\n dev: {\n domain: `https://auth.portal.dev.wandelbots.io`,\n clientId: \"fLbJD0RLp5r2Dpucm5j8BjwMR6Hunfha\",\n },\n stg: {\n domain: `https://auth.portal.stg.wandelbots.io`,\n clientId: \"joVDeD9e786WzFNSGCqoVq7HNkWt5j6s\",\n },\n prod: {\n domain: `https://auth.portal.wandelbots.io`,\n clientId: \"J7WJUi38xVQdJAEBNRT9Xw1b0fXDb4J2\",\n },\n}\n\n/** Determine which Auth0 configuration to use based on instance URL */\nexport const getAuth0Config = (instanceUrl: URL) => {\n if (instanceUrl.host.endsWith(\".dev.wandelbots.io\")) return auth0ConfigMap.dev\n if (instanceUrl.host.endsWith(\".stg.wandelbots.io\")) return auth0ConfigMap.stg\n if (instanceUrl.host.endsWith(\".wandelbots.io\")) return auth0ConfigMap.prod\n throw new Error(\n `Unable to authenticate with NOVA instance \"${instanceUrl}\". Auth0 login is only supported for cloud instances with hosts of the form \"**.wandelbots.io\".`,\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: URL,\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 if (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 auth0Config = getAuth0Config(instanceUrl)\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAa,4BAAb,cAA+CA,+BAAsB;CAKnE,YACE,WACA,AAASC,OAGL,EAAE,EACN;AACA,UAAQ,IAAI,wBAAwB,UAAU;AAE9C,cAAY,KAAK,aAAa,WAAW,QAAW,EAClD,aAAa,MACd,CAAC;EATO;kBAJA;AAgBT,SAAO,eAAe,MAAM,OAAO,EACjC,MAAM;AACJ,UAAO,KAAK;KAEf,CAAC;AAEF,OAAK,YAAY;AAEjB,OAAK,iBAAiB,cAAc;AAClC,WAAQ,IAAI,gBAAgB,KAAK,IAAI,SAAS;IAC9C;AAEF,OAAK,iBAA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ly config: NovaClientConfigWithDefaults;
|
|
324
324
|
readonly mock?: MockNovaInstance;
|
|
325
|
+
readonly instanceUrl: URL;
|
|
325
326
|
authPromise: Promise<string | null> | null;
|
|
326
327
|
accessToken: string | null;
|
|
327
328
|
constructor(config: NovaClientConfig);
|
|
@@ -346,4 +347,4 @@ declare class NovaClient {
|
|
|
346
347
|
}
|
|
347
348
|
//#endregion
|
|
348
349
|
export { WithUnwrappedAxiosResponse as a, MotionStreamConnection as c, poseToWandelscriptString as d, WithCellId as i, ConnectedMotionGroup as l, NovaClientConfig as n, JoggerConnection as o, NovaCellAPIClient as r, JoggerConnectionOpts as s, NovaClient as t, MotionGroupOption as u };
|
|
349
|
-
//# sourceMappingURL=NovaClient-
|
|
350
|
+
//# sourceMappingURL=NovaClient-C0GXOu4w.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NovaClient-
|
|
1
|
+
{"version":3,"file":"NovaClient-C0GXOu4w.d.mts","names":[],"sources":["../src/lib/v1/wandelscriptUtils.ts","../src/lib/v1/ConnectedMotionGroup.ts","../src/lib/v1/MotionStreamConnection.ts","../src/lib/v1/JoggerConnection.ts","../src/lib/v1/NovaCellAPIClient.ts","../src/lib/v1/NovaClient.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;iBAMgB,wBAAA,OACR,KAAK;;;KCcD,iBAAA;;IAER;ADjBJ;;;cCsBa,oBAAA;EAPD,SAAA,IAAA,EA2IO,UA3IU;EAOhB,SAAA,UAAA,EAqIY,kBArIQ;EAoId,SAAA,WAAA,EAEO,mBAFP;EACM,SAAA,kBAAA,EAEQ,wBAFR;EACC,SAAA,iBAAA,EAEM,yBAFN;EACO,SAAA,SAAA,EAAA,OAAA;EACD,SAAA,IAAA,EAEb,QAFa,EAAA;EAEb,SAAA,wBAAA,EACoB,wBADpB;EACoB,SAAA,WAAA,EACb,WADa;EACb,SAAA,QAAA,EACH,QADG,GAAA,IAAA;EACH,SAAA,sBAAA,EACc,oBADd;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AA,WAAA,EI1TQ,GJ0TR;eIzTD;;sBAGO;EHNT,mBAAA,CAAA,CAAA,EGyGkB,OHzGI,CAAA,IAAA,CAAA;EAqDhB,gBAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EACM;;;;;EArDkC,yBAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EGiKnB,yBHjKmB;EAAA;;;EAqDlC,mBAAA,CAAA,aAAA,EAAA,MAAA,CAAA,EGqHwB,OHrHxB,CGqHwB,sBHrHxB,CAAA;EACC;;;EAE+B,aAAA,CAAA,aAAA,EAAA,MAAA,CAAA,EGyHd,OHzHc,CGyHd,gBHzHc,CAAA;iDG+HpD,QAAQ;6CAYR,QAAQ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as isSameCoordinateSystem, m as AutoReconnectingWebsocket, n as loginWithAuth0, p as availableStorage, s as parseNovaInstanceUrl, u as tryParseJson } from "./LoginWithAuth0-DBe9CXOr.mjs";
|
|
2
2
|
import axios, { AxiosError, isAxiosError } from "axios";
|
|
3
3
|
import urlJoin from "url-join";
|
|
4
4
|
import { makeAutoObservable, runInAction } from "mobx";
|
|
@@ -8,59 +8,6 @@ import { Vector3 as Vector3$1 } from "three/src/math/Vector3.js";
|
|
|
8
8
|
import { ApplicationApi, CellApi, ControllerApi, ControllerIOsApi, CoordinateSystemsApi, DeviceConfigurationApi, LibraryProgramApi, LibraryProgramMetadataApi, LibraryRecipeApi, LibraryRecipeMetadataApi, MotionApi, MotionGroupApi, MotionGroupInfosApi, MotionGroupJoggingApi, MotionGroupKinematicApi, ProgramApi, ProgramValuesApi, StoreCollisionComponentsApi, StoreCollisionScenesApi, StoreObjectApi, SystemApi, VirtualRobotApi, VirtualRobotBehaviorApi, VirtualRobotModeApi, VirtualRobotSetupApi } from "@wandelbots/nova-api/v1";
|
|
9
9
|
import * as pathToRegexp from "path-to-regexp";
|
|
10
10
|
|
|
11
|
-
//#region src/lib/converters.ts
|
|
12
|
-
/** Try to parse something as JSON; return undefined if we can't */
|
|
13
|
-
function tryParseJson(json) {
|
|
14
|
-
try {
|
|
15
|
-
return JSON.parse(json);
|
|
16
|
-
} catch {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/** Try to turn something into JSON; return undefined if we can't */
|
|
21
|
-
function tryStringifyJson(json) {
|
|
22
|
-
try {
|
|
23
|
-
return JSON.stringify(json);
|
|
24
|
-
} catch {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Converts object parameters to query string.
|
|
30
|
-
* e.g. { a: "1", b: "2" } => "?a=1&b=2"
|
|
31
|
-
* {} => ""
|
|
32
|
-
*/
|
|
33
|
-
function makeUrlQueryString(obj) {
|
|
34
|
-
const str = new URLSearchParams(obj).toString();
|
|
35
|
-
return str ? `?${str}` : "";
|
|
36
|
-
}
|
|
37
|
-
/** Convert radians to degrees */
|
|
38
|
-
function radiansToDegrees(radians) {
|
|
39
|
-
return radians * (180 / Math.PI);
|
|
40
|
-
}
|
|
41
|
-
/** Convert degrees to radians */
|
|
42
|
-
function degreesToRadians(degrees) {
|
|
43
|
-
return degrees * (Math.PI / 180);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Check for coordinate system id equivalence, accounting for the "world" default
|
|
47
|
-
* on empty/undefined values.
|
|
48
|
-
*/
|
|
49
|
-
function isSameCoordinateSystem(firstCoordSystem, secondCoordSystem) {
|
|
50
|
-
if (!firstCoordSystem) firstCoordSystem = "world";
|
|
51
|
-
if (!secondCoordSystem) secondCoordSystem = "world";
|
|
52
|
-
return firstCoordSystem === secondCoordSystem;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Helpful const for converting {x, y, z} to [x, y, z] and vice versa
|
|
56
|
-
*/
|
|
57
|
-
const XYZ_TO_VECTOR = {
|
|
58
|
-
x: 0,
|
|
59
|
-
y: 1,
|
|
60
|
-
z: 2
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
11
|
//#region src/lib/v1/wandelscriptUtils.ts
|
|
65
12
|
/**
|
|
66
13
|
* Convert a Pose object representing a motion group position
|
|
@@ -1937,10 +1884,6 @@ const defaultMotionState = { result: {
|
|
|
1937
1884
|
|
|
1938
1885
|
//#endregion
|
|
1939
1886
|
//#region src/lib/v1/NovaClient.ts
|
|
1940
|
-
function permissiveInstanceUrlParse(url) {
|
|
1941
|
-
if (!url.startsWith("http")) url = `http://${url}`;
|
|
1942
|
-
return new URL(url).toString();
|
|
1943
|
-
}
|
|
1944
1887
|
/**
|
|
1945
1888
|
* Client for connecting to a Nova instance and controlling robots.
|
|
1946
1889
|
* @deprecated The nova v1 client is deprecated. Please use the v2 client from `@wandelbots/nova-js/v2` instead.
|
|
@@ -1956,7 +1899,7 @@ var NovaClient = class {
|
|
|
1956
1899
|
};
|
|
1957
1900
|
this.accessToken = config.accessToken || availableStorage.getString("wbjs.access_token") || null;
|
|
1958
1901
|
if (this.config.instanceUrl === "https://mock.example.com") this.mock = new MockNovaInstance();
|
|
1959
|
-
|
|
1902
|
+
this.instanceUrl = parseNovaInstanceUrl(this.config.instanceUrl);
|
|
1960
1903
|
const axiosInstance = axios.create({
|
|
1961
1904
|
baseURL: urlJoin(this.config.instanceUrl, "/api/v1"),
|
|
1962
1905
|
headers: typeof window !== "undefined" && window.location.origin.includes("localhost") ? {} : { "X-Wandelbots-Client": "Wandelbots-Nova-JS-SDK" }
|
|
@@ -1988,7 +1931,7 @@ var NovaClient = class {
|
|
|
1988
1931
|
});
|
|
1989
1932
|
this.api = new NovaCellAPIClient(cellId, {
|
|
1990
1933
|
...config,
|
|
1991
|
-
basePath: urlJoin(this.
|
|
1934
|
+
basePath: urlJoin(this.instanceUrl.href, "/api/v1"),
|
|
1992
1935
|
isJsonMime: (mime) => {
|
|
1993
1936
|
return mime === "application/json";
|
|
1994
1937
|
},
|
|
@@ -2003,7 +1946,12 @@ var NovaClient = class {
|
|
|
2003
1946
|
}
|
|
2004
1947
|
async renewAuthentication() {
|
|
2005
1948
|
if (this.authPromise) return;
|
|
2006
|
-
|
|
1949
|
+
const storedToken = availableStorage.getString("wbjs.access_token");
|
|
1950
|
+
if (storedToken && this.accessToken !== storedToken) {
|
|
1951
|
+
this.accessToken = storedToken;
|
|
1952
|
+
return;
|
|
1953
|
+
}
|
|
1954
|
+
this.authPromise = loginWithAuth0(this.instanceUrl);
|
|
2007
1955
|
try {
|
|
2008
1956
|
this.accessToken = await this.authPromise;
|
|
2009
1957
|
if (this.accessToken) availableStorage.setString("wbjs.access_token", this.accessToken);
|
|
@@ -2013,7 +1961,7 @@ var NovaClient = class {
|
|
|
2013
1961
|
}
|
|
2014
1962
|
}
|
|
2015
1963
|
makeWebsocketURL(path) {
|
|
2016
|
-
const url = new URL(urlJoin(this.
|
|
1964
|
+
const url = new URL(urlJoin(this.instanceUrl.href, `/api/v1/cells/${this.config.cellId}`, path));
|
|
2017
1965
|
url.protocol = url.protocol.replace("http", "ws");
|
|
2018
1966
|
url.protocol = url.protocol.replace("https", "wss");
|
|
2019
1967
|
if (this.accessToken) url.searchParams.append("token", this.accessToken);
|
|
@@ -2053,5 +2001,5 @@ var NovaClient = class {
|
|
|
2053
2001
|
};
|
|
2054
2002
|
|
|
2055
2003
|
//#endregion
|
|
2056
|
-
export { ConnectedMotionGroup as a,
|
|
2057
|
-
//# sourceMappingURL=NovaClient-
|
|
2004
|
+
export { ConnectedMotionGroup as a, JoggerConnection as i, NovaCellAPIClient as n, poseToWandelscriptString as o, MotionStreamConnection as r, NovaClient as t };
|
|
2005
|
+
//# sourceMappingURL=NovaClient-C27dk3Ql.mjs.map
|