@wandelbots/nova-js 3.1.0 → 3.2.0-pr.ci-simplify-build.137.87eeb8d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/AutoReconnectingWebsocket-BI1ckzP8.d.ts +71 -0
  2. package/dist/AutoReconnectingWebsocket-BI1ckzP8.d.ts.map +1 -0
  3. package/dist/AutoReconnectingWebsocket-Cr7f9016.d.cts +71 -0
  4. package/dist/AutoReconnectingWebsocket-Cr7f9016.d.cts.map +1 -0
  5. package/dist/LoginWithAuth0-0g0wWRUC.js +217 -0
  6. package/dist/LoginWithAuth0-0g0wWRUC.js.map +1 -0
  7. package/dist/LoginWithAuth0-C82OCyDy.cjs +264 -0
  8. package/dist/LoginWithAuth0-C82OCyDy.cjs.map +1 -0
  9. package/dist/converters-DP2EIVv6.cjs +108 -0
  10. package/dist/converters-DP2EIVv6.cjs.map +1 -0
  11. package/dist/converters-DY6Lf7mb.js +66 -0
  12. package/dist/converters-DY6Lf7mb.js.map +1 -0
  13. package/dist/index.cjs +41 -386
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +70 -0
  16. package/dist/index.d.cts.map +1 -0
  17. package/dist/index.d.ts +69 -5
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +28 -52
  20. package/dist/index.js.map +1 -1
  21. package/dist/lib/v1/index.cjs +2146 -2917
  22. package/dist/lib/v1/index.cjs.map +1 -1
  23. package/dist/lib/v1/index.d.cts +397 -0
  24. package/dist/lib/v1/index.d.cts.map +1 -0
  25. package/dist/lib/v1/index.d.ts +395 -7
  26. package/dist/lib/v1/index.d.ts.map +1 -1
  27. package/dist/lib/v1/index.js +2127 -2623
  28. package/dist/lib/v1/index.js.map +1 -1
  29. package/dist/lib/v2/index.cjs +1356 -1472
  30. package/dist/lib/v2/index.cjs.map +1 -1
  31. package/dist/lib/v2/index.d.cts +115 -0
  32. package/dist/lib/v2/index.d.cts.map +1 -0
  33. package/dist/lib/v2/index.d.ts +113 -2
  34. package/dist/lib/v2/index.d.ts.map +1 -1
  35. package/dist/lib/v2/index.js +1346 -1189
  36. package/dist/lib/v2/index.js.map +1 -1
  37. package/package.json +14 -16
  38. package/src/LoginWithAuth0.ts +9 -9
  39. package/src/lib/v1/NovaCellAPIClient.ts +4 -2
  40. package/src/lib/v2/NovaCellAPIClient.ts +4 -2
  41. package/src/lib/v2/mock/MockNovaInstance.ts +9 -13
  42. package/dist/LoginWithAuth0.d.ts +0 -7
  43. package/dist/LoginWithAuth0.d.ts.map +0 -1
  44. package/dist/chunk-B2C22PTK.js +0 -53
  45. package/dist/chunk-B2C22PTK.js.map +0 -1
  46. package/dist/chunk-I3PUV6ZD.js +0 -286
  47. package/dist/chunk-I3PUV6ZD.js.map +0 -1
  48. package/dist/lib/AutoReconnectingWebsocket.d.ts +0 -43
  49. package/dist/lib/AutoReconnectingWebsocket.d.ts.map +0 -1
  50. package/dist/lib/availableStorage.d.ts +0 -15
  51. package/dist/lib/availableStorage.d.ts.map +0 -1
  52. package/dist/lib/converters.d.ts +0 -26
  53. package/dist/lib/converters.d.ts.map +0 -1
  54. package/dist/lib/errorHandling.d.ts +0 -15
  55. package/dist/lib/errorHandling.d.ts.map +0 -1
  56. package/dist/lib/v1/ConnectedMotionGroup.d.ts +0 -77
  57. package/dist/lib/v1/ConnectedMotionGroup.d.ts.map +0 -1
  58. package/dist/lib/v1/JoggerConnection.d.ts +0 -94
  59. package/dist/lib/v1/JoggerConnection.d.ts.map +0 -1
  60. package/dist/lib/v1/MotionStreamConnection.d.ts +0 -26
  61. package/dist/lib/v1/MotionStreamConnection.d.ts.map +0 -1
  62. package/dist/lib/v1/NovaCellAPIClient.d.ts +0 -68
  63. package/dist/lib/v1/NovaCellAPIClient.d.ts.map +0 -1
  64. package/dist/lib/v1/NovaClient.d.ts +0 -67
  65. package/dist/lib/v1/NovaClient.d.ts.map +0 -1
  66. package/dist/lib/v1/ProgramStateConnection.d.ts +0 -57
  67. package/dist/lib/v1/ProgramStateConnection.d.ts.map +0 -1
  68. package/dist/lib/v1/getLatestTrajectories.d.ts +0 -4
  69. package/dist/lib/v1/getLatestTrajectories.d.ts.map +0 -1
  70. package/dist/lib/v1/mock/MockNovaInstance.d.ts +0 -13
  71. package/dist/lib/v1/mock/MockNovaInstance.d.ts.map +0 -1
  72. package/dist/lib/v1/motionStateUpdate.d.ts +0 -4
  73. package/dist/lib/v1/motionStateUpdate.d.ts.map +0 -1
  74. package/dist/lib/v2/NovaCellAPIClient.d.ts +0 -62
  75. package/dist/lib/v2/NovaCellAPIClient.d.ts.map +0 -1
  76. package/dist/lib/v2/NovaClient.d.ts +0 -60
  77. package/dist/lib/v2/NovaClient.d.ts.map +0 -1
  78. package/dist/lib/v2/mock/MockNovaInstance.d.ts +0 -13
  79. package/dist/lib/v2/mock/MockNovaInstance.d.ts.map +0 -1
@@ -0,0 +1,71 @@
1
+ import ReconnectingWebSocket from "reconnecting-websocket";
2
+ import { AxiosResponse, InternalAxiosRequestConfig } from "axios";
3
+
4
+ //#region src/lib/v1/mock/MockNovaInstance.d.ts
5
+
6
+ /**
7
+ * EXPERIMENTAL
8
+ * Ultra-simplified mock Nova server for testing stuff
9
+ */
10
+ declare class MockNovaInstance$1 {
11
+ readonly connections: AutoReconnectingWebsocket[];
12
+ handleAPIRequest(config: InternalAxiosRequestConfig): Promise<AxiosResponse>;
13
+ handleWebsocketConnection(socket: AutoReconnectingWebsocket): void;
14
+ handleWebsocketMessage(socket: AutoReconnectingWebsocket, message: string): void;
15
+ }
16
+ //#endregion
17
+ //#region src/lib/v2/mock/MockNovaInstance.d.ts
18
+ /**
19
+ * EXPERIMENTAL
20
+ * Ultra-simplified mock Nova server for testing stuff
21
+ */
22
+ declare class MockNovaInstance {
23
+ readonly connections: AutoReconnectingWebsocket[];
24
+ handleAPIRequest(config: InternalAxiosRequestConfig): Promise<AxiosResponse>;
25
+ handleWebsocketConnection(socket: AutoReconnectingWebsocket): void;
26
+ handleWebsocketMessage(socket: AutoReconnectingWebsocket, message: string): void;
27
+ }
28
+ //#endregion
29
+ //#region src/lib/AutoReconnectingWebsocket.d.ts
30
+ declare class AutoReconnectingWebsocket extends ReconnectingWebSocket {
31
+ readonly opts: {
32
+ mock?: MockNovaInstance$1 | MockNovaInstance;
33
+ onDispose?: () => void;
34
+ };
35
+ receivedFirstMessage?: MessageEvent;
36
+ targetUrl: string;
37
+ disposed: boolean;
38
+ constructor(targetUrl: string, opts?: {
39
+ mock?: MockNovaInstance$1 | MockNovaInstance;
40
+ onDispose?: () => void;
41
+ });
42
+ changeUrl(targetUrl: string): void;
43
+ sendJson(data: unknown): void;
44
+ /**
45
+ * Permanently close this websocket and indicate that
46
+ * this object should not be used again.
47
+ **/
48
+ dispose(): void;
49
+ /**
50
+ * Returns a promise that resolves once the websocket
51
+ * is in the OPEN state. */
52
+ opened(): Promise<void>;
53
+ /**
54
+ * Returns a promise that resolves once the websocket
55
+ * is in the CLOSED state. */
56
+ closed(): Promise<void>;
57
+ /**
58
+ * Returns a promise that resolves when the first message
59
+ * is received from the websocket. Resolves immediately if
60
+ * the first message has already been received.
61
+ */
62
+ firstMessage(): Promise<MessageEvent<any>>;
63
+ /**
64
+ * Returns a promise that resolves when the next message
65
+ * is received from the websocket.
66
+ */
67
+ nextMessage(): Promise<MessageEvent<any>>;
68
+ }
69
+ //#endregion
70
+ export { AutoReconnectingWebsocket, MockNovaInstance, MockNovaInstance$1 };
71
+ //# sourceMappingURL=AutoReconnectingWebsocket-BI1ckzP8.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AutoReconnectingWebsocket-BI1ckzP8.d.ts","names":[],"sources":["../src/lib/v1/mock/MockNovaInstance.ts","../src/lib/v2/mock/MockNovaInstance.ts","../src/lib/AutoReconnectingWebsocket.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;AACwB,cADX,kBAAA,CACW;WAGZ,WAAA,EAHY,yBAGZ,EAAA;kBACC,CAA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"axios";
3
+
4
+ //#region src/lib/v1/mock/MockNovaInstance.d.ts
5
+
6
+ /**
7
+ * EXPERIMENTAL
8
+ * Ultra-simplified mock Nova server for testing stuff
9
+ */
10
+ declare class MockNovaInstance$1 {
11
+ readonly connections: AutoReconnectingWebsocket[];
12
+ handleAPIRequest(config: InternalAxiosRequestConfig): Promise<AxiosResponse>;
13
+ handleWebsocketConnection(socket: AutoReconnectingWebsocket): void;
14
+ handleWebsocketMessage(socket: AutoReconnectingWebsocket, message: string): void;
15
+ }
16
+ //#endregion
17
+ //#region src/lib/v2/mock/MockNovaInstance.d.ts
18
+ /**
19
+ * EXPERIMENTAL
20
+ * Ultra-simplified mock Nova server for testing stuff
21
+ */
22
+ declare class MockNovaInstance {
23
+ readonly connections: AutoReconnectingWebsocket[];
24
+ handleAPIRequest(config: InternalAxiosRequestConfig): Promise<AxiosResponse>;
25
+ handleWebsocketConnection(socket: AutoReconnectingWebsocket): void;
26
+ handleWebsocketMessage(socket: AutoReconnectingWebsocket, message: string): void;
27
+ }
28
+ //#endregion
29
+ //#region src/lib/AutoReconnectingWebsocket.d.ts
30
+ declare class AutoReconnectingWebsocket extends ReconnectingWebSocket {
31
+ readonly opts: {
32
+ mock?: MockNovaInstance$1 | MockNovaInstance;
33
+ onDispose?: () => void;
34
+ };
35
+ receivedFirstMessage?: MessageEvent;
36
+ targetUrl: string;
37
+ disposed: boolean;
38
+ constructor(targetUrl: string, opts?: {
39
+ mock?: MockNovaInstance$1 | MockNovaInstance;
40
+ onDispose?: () => void;
41
+ });
42
+ changeUrl(targetUrl: string): void;
43
+ sendJson(data: unknown): void;
44
+ /**
45
+ * Permanently close this websocket and indicate that
46
+ * this object should not be used again.
47
+ **/
48
+ dispose(): void;
49
+ /**
50
+ * Returns a promise that resolves once the websocket
51
+ * is in the OPEN state. */
52
+ opened(): Promise<void>;
53
+ /**
54
+ * Returns a promise that resolves once the websocket
55
+ * is in the CLOSED state. */
56
+ closed(): Promise<void>;
57
+ /**
58
+ * Returns a promise that resolves when the first message
59
+ * is received from the websocket. Resolves immediately if
60
+ * the first message has already been received.
61
+ */
62
+ firstMessage(): Promise<MessageEvent<any>>;
63
+ /**
64
+ * Returns a promise that resolves when the next message
65
+ * is received from the websocket.
66
+ */
67
+ nextMessage(): Promise<MessageEvent<any>>;
68
+ }
69
+ //#endregion
70
+ export { AutoReconnectingWebsocket, MockNovaInstance, MockNovaInstance$1 };
71
+ //# sourceMappingURL=AutoReconnectingWebsocket-Cr7f9016.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AutoReconnectingWebsocket-Cr7f9016.d.cts","names":[],"sources":["../src/lib/v1/mock/MockNovaInstance.ts","../src/lib/v2/mock/MockNovaInstance.ts","../src/lib/AutoReconnectingWebsocket.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;AACwB,cADX,kBAAA,CACW;WAGZ,WAAA,EAHY,yBAGZ,EAAA;kBACC,CAAA,MAAA,EADD,0BACC,CAAA,EAAR,OAAQ,CAAA,aAAA,CAAA;2BAAR,CAAA,MAAA,EAg8B+B,yBAh8B/B,CAAA,EAAA,IAAA;wBAg8B+B,CAAA,MAAA,EAkOH,yBAlOG,EAAA,OAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;;;;;AAr8BpC;;AACwB,cCPX,gBAAA,CDOW;WAGZ,WAAA,ECTY,yBDSZ,EAAA;kBACC,CAAA,MAAA,ECPD,0BDOC,CAAA,ECNR,ODMQ,CCNA,aDMA,CAAA;2BAAR,CAAA,MAAA,ECqqB+B,yBDrqB/B,CAAA,EAAA,IAAA;wBAg8B+B,CAAA,MAAA,EC/DH,yBD+DG,EAAA,OAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;;;cEj9BvB,yBAAA,SAAkC,qBAAA;EFYlC,SAAA,IAAA,EAAA;IAAgB,IAAA,CAAA,EEJhB,kBFIgB,GEJM,gBFIN;IACL,SAAA,CAAA,EAAA,GAAA,GAAA,IAAA;;sBAIX,CAAA,EEhBY,YFgBZ;WAAR,EAAA,MAAA;UAg8B+B,EAAA,OAAA;aAkOH,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,EAAA;IAAyB,IAAA,CAAA,EE3qC7C,kBF2qC6C,GE3qCvB,gBF2qCuB;;;;EC7qC7C,QAAA,CAAA,IAAA,EAAA,OAAgB,CAAA,EAAA,IAAA;EAAA;;;;SAKxB,CAAA,CAAA,EAAA,IAAA;;;;YCuES;;;AAlFd;EAAuC,MAAA,CAAA,CAAA,EAgGzB,OAhGyB,CAAA,IAAA,CAAA;;;;;;cAkFzB,CAAA,CAAA,EA8BM,OA9BN,CA8BM,YA9BN,CAAA,GAAA,CAAA,CAAA;;;;;aA0DK,CAAA,CAAA,EAAA,OAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA"}
@@ -0,0 +1,217 @@
1
+ import ReconnectingWebSocket from "reconnecting-websocket";
2
+
3
+ //#region src/lib/AutoReconnectingWebsocket.ts
4
+ var AutoReconnectingWebsocket = class extends ReconnectingWebSocket {
5
+ constructor(targetUrl, opts = {}) {
6
+ console.log("Opening websocket to", targetUrl);
7
+ super(() => this.targetUrl || targetUrl, void 0, { startClosed: true });
8
+ this.opts = opts;
9
+ this.disposed = false;
10
+ Object.defineProperty(this, "url", { get() {
11
+ return this.targetUrl;
12
+ } });
13
+ this.targetUrl = targetUrl;
14
+ this.addEventListener("open", () => {
15
+ console.log(`Websocket to ${this.url} opened`);
16
+ });
17
+ this.addEventListener("message", (ev) => {
18
+ if (!this.receivedFirstMessage) this.receivedFirstMessage = ev;
19
+ });
20
+ this.addEventListener("close", () => {
21
+ console.log(`Websocket to ${this.url} closed`);
22
+ });
23
+ const origReconnect = this.reconnect;
24
+ this.reconnect = () => {
25
+ if (this.opts.mock) this.opts.mock.handleWebsocketConnection(this);
26
+ else origReconnect.apply(this);
27
+ };
28
+ this.reconnect();
29
+ }
30
+ changeUrl(targetUrl) {
31
+ this.receivedFirstMessage = void 0;
32
+ this.targetUrl = targetUrl;
33
+ this.reconnect();
34
+ }
35
+ sendJson(data) {
36
+ if (this.opts.mock) this.opts.mock.handleWebsocketMessage(this, JSON.stringify(data));
37
+ else this.send(JSON.stringify(data));
38
+ }
39
+ /**
40
+ * Permanently close this websocket and indicate that
41
+ * this object should not be used again.
42
+ **/
43
+ dispose() {
44
+ this.close();
45
+ this.disposed = true;
46
+ if (this.opts.onDispose) this.opts.onDispose();
47
+ }
48
+ /**
49
+ * Returns a promise that resolves once the websocket
50
+ * is in the OPEN state. */
51
+ async opened() {
52
+ return new Promise((resolve, reject) => {
53
+ if (this.readyState === WebSocket.OPEN) resolve();
54
+ else {
55
+ this.addEventListener("open", () => resolve());
56
+ this.addEventListener("error", reject);
57
+ }
58
+ });
59
+ }
60
+ /**
61
+ * Returns a promise that resolves once the websocket
62
+ * is in the CLOSED state. */
63
+ async closed() {
64
+ return new Promise((resolve, reject) => {
65
+ if (this.readyState === WebSocket.CLOSED) resolve();
66
+ else {
67
+ this.addEventListener("close", () => resolve());
68
+ this.addEventListener("error", reject);
69
+ }
70
+ });
71
+ }
72
+ /**
73
+ * Returns a promise that resolves when the first message
74
+ * is received from the websocket. Resolves immediately if
75
+ * the first message has already been received.
76
+ */
77
+ async firstMessage() {
78
+ if (this.receivedFirstMessage) return this.receivedFirstMessage;
79
+ return new Promise((resolve, reject) => {
80
+ const onMessage = (ev) => {
81
+ this.receivedFirstMessage = ev;
82
+ this.removeEventListener("message", onMessage);
83
+ this.removeEventListener("error", onError);
84
+ resolve(ev);
85
+ };
86
+ const onError = (ev) => {
87
+ this.removeEventListener("message", onMessage);
88
+ this.removeEventListener("error", onError);
89
+ reject(ev);
90
+ };
91
+ this.addEventListener("message", onMessage);
92
+ this.addEventListener("error", onError);
93
+ });
94
+ }
95
+ /**
96
+ * Returns a promise that resolves when the next message
97
+ * is received from the websocket.
98
+ */
99
+ async nextMessage() {
100
+ return new Promise((resolve, reject) => {
101
+ const onMessage = (ev) => {
102
+ this.removeEventListener("message", onMessage);
103
+ this.removeEventListener("error", onError);
104
+ resolve(ev);
105
+ };
106
+ const onError = (ev) => {
107
+ this.removeEventListener("message", onMessage);
108
+ this.removeEventListener("error", onError);
109
+ reject(ev);
110
+ };
111
+ this.addEventListener("message", onMessage);
112
+ this.addEventListener("error", onError);
113
+ });
114
+ }
115
+ };
116
+
117
+ //#endregion
118
+ //#region src/lib/availableStorage.ts
119
+ /**
120
+ * Safety wrapper around browser localStorage providing context availability
121
+ * checks and JSON parsing
122
+ */
123
+ var AvailableStorage = class {
124
+ constructor() {
125
+ this.available = typeof window !== "undefined" && !!window.localStorage;
126
+ }
127
+ getJSON(key) {
128
+ if (!this.available) return null;
129
+ const result = window.localStorage.getItem(key);
130
+ if (result === null) return null;
131
+ try {
132
+ return JSON.parse(result);
133
+ } catch (err) {
134
+ return null;
135
+ }
136
+ }
137
+ setJSON(key, obj) {
138
+ if (!this.available) return null;
139
+ window.localStorage.setItem(key, JSON.stringify(obj));
140
+ }
141
+ delete(key) {
142
+ if (!this.available) return null;
143
+ window.localStorage.removeItem(key);
144
+ }
145
+ setString(key, value) {
146
+ if (!this.available) return null;
147
+ window.localStorage.setItem(key, value);
148
+ }
149
+ getString(key) {
150
+ if (!this.available) return null;
151
+ return window.localStorage.getItem(key);
152
+ }
153
+ };
154
+ const availableStorage = new AvailableStorage();
155
+
156
+ //#endregion
157
+ //#region src/LoginWithAuth0.ts
158
+ const DOMAIN_SUFFIX = "wandelbots.io";
159
+ /**
160
+ * Mapping of stages to Auth0 configurations.
161
+ * The client ids are public identifiers for a specific auth0 application
162
+ * and are safe to include in client-side code.
163
+ * https://auth0.com/docs/get-started/applications/application-settings
164
+ */
165
+ const auth0ConfigMap = {
166
+ dev: {
167
+ domain: `https://auth.portal.dev.${DOMAIN_SUFFIX}`,
168
+ clientId: "fLbJD0RLp5r2Dpucm5j8BjwMR6Hunfha"
169
+ },
170
+ stg: {
171
+ domain: `https://auth.portal.stg.${DOMAIN_SUFFIX}`,
172
+ clientId: "joVDeD9e786WzFNSGCqoVq7HNkWt5j6s"
173
+ },
174
+ prod: {
175
+ domain: `https://auth.portal.${DOMAIN_SUFFIX}`,
176
+ clientId: "J7WJUi38xVQdJAEBNRT9Xw1b0fXDb4J2"
177
+ }
178
+ };
179
+ /** Determine which Auth0 configuration to use based on instance URL */
180
+ const getAuth0Config = (instanceUrl) => {
181
+ if (instanceUrl.includes(`dev.${DOMAIN_SUFFIX}`)) return auth0ConfigMap.dev;
182
+ if (instanceUrl.includes(`stg.${DOMAIN_SUFFIX}`)) return auth0ConfigMap.stg;
183
+ if (instanceUrl.includes(DOMAIN_SUFFIX)) return auth0ConfigMap.prod;
184
+ throw new Error("Unsupported instance URL. Cannot determine Auth0 configuration.");
185
+ };
186
+ /**
187
+ * Initializes Auth0 login process using redirect if necessary and retrieves an access token.
188
+ * Returns null when an access token should not be needed to authenticate (i.e. cookie auth
189
+ * when deployed on the instance domain)
190
+ */
191
+ const loginWithAuth0 = async (instanceUrl) => {
192
+ if (typeof window === "undefined") throw new Error(`Access token must be set to use NovaClient when not in a browser environment.`);
193
+ const auth0Config = getAuth0Config(instanceUrl);
194
+ if (new URL(instanceUrl).origin === window.location.origin) {
195
+ window.location.reload();
196
+ throw new Error("Failed to reload page to get auth details, please refresh manually");
197
+ }
198
+ const { Auth0Client } = await import("@auth0/auth0-spa-js");
199
+ const auth0Client = new Auth0Client({
200
+ domain: auth0Config.domain,
201
+ clientId: auth0Config.clientId ?? "",
202
+ useRefreshTokens: false,
203
+ authorizationParams: {
204
+ audience: "nova-api",
205
+ redirect_uri: window.location.origin
206
+ }
207
+ });
208
+ if (window.location.search.includes("code=") && window.location.search.includes("state=")) {
209
+ const { appState } = await auth0Client.handleRedirectCallback();
210
+ window.history.replaceState({}, document.title, appState?.returnTo || window.location.pathname);
211
+ } else await auth0Client.loginWithRedirect();
212
+ return await auth0Client.getTokenSilently();
213
+ };
214
+
215
+ //#endregion
216
+ export { AutoReconnectingWebsocket, availableStorage, loginWithAuth0 };
217
+ //# sourceMappingURL=LoginWithAuth0-0g0wWRUC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoginWithAuth0-0g0wWRUC.js","names":["opts: {\n mock?: v1.MockNovaInstance | v2.MockNovaInstance\n onDispose?: () => void\n }"],"sources":["../src/lib/AutoReconnectingWebsocket.ts","../src/lib/availableStorage.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","const DOMAIN_SUFFIX = \"wandelbots.io\"\n\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.${DOMAIN_SUFFIX}`,\n clientId: \"fLbJD0RLp5r2Dpucm5j8BjwMR6Hunfha\",\n },\n stg: {\n domain: `https://auth.portal.stg.${DOMAIN_SUFFIX}`,\n clientId: \"joVDeD9e786WzFNSGCqoVq7HNkWt5j6s\",\n },\n prod: {\n domain: `https://auth.portal.${DOMAIN_SUFFIX}`,\n clientId: \"J7WJUi38xVQdJAEBNRT9Xw1b0fXDb4J2\",\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":";;;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,gBA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,kBAAkB"}
@@ -0,0 +1,264 @@
1
+ //#region rolldown:runtime
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 __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ let reconnecting_websocket = require("reconnecting-websocket");
25
+ reconnecting_websocket = __toESM(reconnecting_websocket);
26
+
27
+ //#region src/lib/AutoReconnectingWebsocket.ts
28
+ var AutoReconnectingWebsocket = class extends reconnecting_websocket.default {
29
+ constructor(targetUrl, opts = {}) {
30
+ console.log("Opening websocket to", targetUrl);
31
+ super(() => this.targetUrl || targetUrl, void 0, { startClosed: true });
32
+ this.opts = opts;
33
+ this.disposed = false;
34
+ Object.defineProperty(this, "url", { get() {
35
+ return this.targetUrl;
36
+ } });
37
+ this.targetUrl = targetUrl;
38
+ this.addEventListener("open", () => {
39
+ console.log(`Websocket to ${this.url} opened`);
40
+ });
41
+ this.addEventListener("message", (ev) => {
42
+ if (!this.receivedFirstMessage) this.receivedFirstMessage = ev;
43
+ });
44
+ this.addEventListener("close", () => {
45
+ console.log(`Websocket to ${this.url} closed`);
46
+ });
47
+ const origReconnect = this.reconnect;
48
+ this.reconnect = () => {
49
+ if (this.opts.mock) this.opts.mock.handleWebsocketConnection(this);
50
+ else origReconnect.apply(this);
51
+ };
52
+ this.reconnect();
53
+ }
54
+ changeUrl(targetUrl) {
55
+ this.receivedFirstMessage = void 0;
56
+ this.targetUrl = targetUrl;
57
+ this.reconnect();
58
+ }
59
+ sendJson(data) {
60
+ if (this.opts.mock) this.opts.mock.handleWebsocketMessage(this, JSON.stringify(data));
61
+ else this.send(JSON.stringify(data));
62
+ }
63
+ /**
64
+ * Permanently close this websocket and indicate that
65
+ * this object should not be used again.
66
+ **/
67
+ dispose() {
68
+ this.close();
69
+ this.disposed = true;
70
+ if (this.opts.onDispose) this.opts.onDispose();
71
+ }
72
+ /**
73
+ * Returns a promise that resolves once the websocket
74
+ * is in the OPEN state. */
75
+ async opened() {
76
+ return new Promise((resolve, reject) => {
77
+ if (this.readyState === WebSocket.OPEN) resolve();
78
+ else {
79
+ this.addEventListener("open", () => resolve());
80
+ this.addEventListener("error", reject);
81
+ }
82
+ });
83
+ }
84
+ /**
85
+ * Returns a promise that resolves once the websocket
86
+ * is in the CLOSED state. */
87
+ async closed() {
88
+ return new Promise((resolve, reject) => {
89
+ if (this.readyState === WebSocket.CLOSED) resolve();
90
+ else {
91
+ this.addEventListener("close", () => resolve());
92
+ this.addEventListener("error", reject);
93
+ }
94
+ });
95
+ }
96
+ /**
97
+ * Returns a promise that resolves when the first message
98
+ * is received from the websocket. Resolves immediately if
99
+ * the first message has already been received.
100
+ */
101
+ async firstMessage() {
102
+ if (this.receivedFirstMessage) return this.receivedFirstMessage;
103
+ return new Promise((resolve, reject) => {
104
+ const onMessage = (ev) => {
105
+ this.receivedFirstMessage = ev;
106
+ this.removeEventListener("message", onMessage);
107
+ this.removeEventListener("error", onError);
108
+ resolve(ev);
109
+ };
110
+ const onError = (ev) => {
111
+ this.removeEventListener("message", onMessage);
112
+ this.removeEventListener("error", onError);
113
+ reject(ev);
114
+ };
115
+ this.addEventListener("message", onMessage);
116
+ this.addEventListener("error", onError);
117
+ });
118
+ }
119
+ /**
120
+ * Returns a promise that resolves when the next message
121
+ * is received from the websocket.
122
+ */
123
+ async nextMessage() {
124
+ return new Promise((resolve, reject) => {
125
+ const onMessage = (ev) => {
126
+ this.removeEventListener("message", onMessage);
127
+ this.removeEventListener("error", onError);
128
+ resolve(ev);
129
+ };
130
+ const onError = (ev) => {
131
+ this.removeEventListener("message", onMessage);
132
+ this.removeEventListener("error", onError);
133
+ reject(ev);
134
+ };
135
+ this.addEventListener("message", onMessage);
136
+ this.addEventListener("error", onError);
137
+ });
138
+ }
139
+ };
140
+
141
+ //#endregion
142
+ //#region src/lib/availableStorage.ts
143
+ /**
144
+ * Safety wrapper around browser localStorage providing context availability
145
+ * checks and JSON parsing
146
+ */
147
+ var AvailableStorage = class {
148
+ constructor() {
149
+ this.available = typeof window !== "undefined" && !!window.localStorage;
150
+ }
151
+ getJSON(key) {
152
+ if (!this.available) return null;
153
+ const result = window.localStorage.getItem(key);
154
+ if (result === null) return null;
155
+ try {
156
+ return JSON.parse(result);
157
+ } catch (err) {
158
+ return null;
159
+ }
160
+ }
161
+ setJSON(key, obj) {
162
+ if (!this.available) return null;
163
+ window.localStorage.setItem(key, JSON.stringify(obj));
164
+ }
165
+ delete(key) {
166
+ if (!this.available) return null;
167
+ window.localStorage.removeItem(key);
168
+ }
169
+ setString(key, value) {
170
+ if (!this.available) return null;
171
+ window.localStorage.setItem(key, value);
172
+ }
173
+ getString(key) {
174
+ if (!this.available) return null;
175
+ return window.localStorage.getItem(key);
176
+ }
177
+ };
178
+ const availableStorage = new AvailableStorage();
179
+
180
+ //#endregion
181
+ //#region src/LoginWithAuth0.ts
182
+ const DOMAIN_SUFFIX = "wandelbots.io";
183
+ /**
184
+ * Mapping of stages to Auth0 configurations.
185
+ * The client ids are public identifiers for a specific auth0 application
186
+ * and are safe to include in client-side code.
187
+ * https://auth0.com/docs/get-started/applications/application-settings
188
+ */
189
+ const auth0ConfigMap = {
190
+ dev: {
191
+ domain: `https://auth.portal.dev.${DOMAIN_SUFFIX}`,
192
+ clientId: "fLbJD0RLp5r2Dpucm5j8BjwMR6Hunfha"
193
+ },
194
+ stg: {
195
+ domain: `https://auth.portal.stg.${DOMAIN_SUFFIX}`,
196
+ clientId: "joVDeD9e786WzFNSGCqoVq7HNkWt5j6s"
197
+ },
198
+ prod: {
199
+ domain: `https://auth.portal.${DOMAIN_SUFFIX}`,
200
+ clientId: "J7WJUi38xVQdJAEBNRT9Xw1b0fXDb4J2"
201
+ }
202
+ };
203
+ /** Determine which Auth0 configuration to use based on instance URL */
204
+ const getAuth0Config = (instanceUrl) => {
205
+ if (instanceUrl.includes(`dev.${DOMAIN_SUFFIX}`)) return auth0ConfigMap.dev;
206
+ if (instanceUrl.includes(`stg.${DOMAIN_SUFFIX}`)) return auth0ConfigMap.stg;
207
+ if (instanceUrl.includes(DOMAIN_SUFFIX)) return auth0ConfigMap.prod;
208
+ throw new Error("Unsupported instance URL. Cannot determine Auth0 configuration.");
209
+ };
210
+ /**
211
+ * Initializes Auth0 login process using redirect if necessary and retrieves an access token.
212
+ * Returns null when an access token should not be needed to authenticate (i.e. cookie auth
213
+ * when deployed on the instance domain)
214
+ */
215
+ const loginWithAuth0 = async (instanceUrl) => {
216
+ if (typeof window === "undefined") throw new Error(`Access token must be set to use NovaClient when not in a browser environment.`);
217
+ const auth0Config = getAuth0Config(instanceUrl);
218
+ if (new URL(instanceUrl).origin === window.location.origin) {
219
+ window.location.reload();
220
+ throw new Error("Failed to reload page to get auth details, please refresh manually");
221
+ }
222
+ const { Auth0Client } = await import("@auth0/auth0-spa-js");
223
+ const auth0Client = new Auth0Client({
224
+ domain: auth0Config.domain,
225
+ clientId: auth0Config.clientId ?? "",
226
+ useRefreshTokens: false,
227
+ authorizationParams: {
228
+ audience: "nova-api",
229
+ redirect_uri: window.location.origin
230
+ }
231
+ });
232
+ if (window.location.search.includes("code=") && window.location.search.includes("state=")) {
233
+ const { appState } = await auth0Client.handleRedirectCallback();
234
+ window.history.replaceState({}, document.title, appState?.returnTo || window.location.pathname);
235
+ } else await auth0Client.loginWithRedirect();
236
+ return await auth0Client.getTokenSilently();
237
+ };
238
+
239
+ //#endregion
240
+ Object.defineProperty(exports, 'AutoReconnectingWebsocket', {
241
+ enumerable: true,
242
+ get: function () {
243
+ return AutoReconnectingWebsocket;
244
+ }
245
+ });
246
+ Object.defineProperty(exports, '__toESM', {
247
+ enumerable: true,
248
+ get: function () {
249
+ return __toESM;
250
+ }
251
+ });
252
+ Object.defineProperty(exports, 'availableStorage', {
253
+ enumerable: true,
254
+ get: function () {
255
+ return availableStorage;
256
+ }
257
+ });
258
+ Object.defineProperty(exports, 'loginWithAuth0', {
259
+ enumerable: true,
260
+ get: function () {
261
+ return loginWithAuth0;
262
+ }
263
+ });
264
+ //# sourceMappingURL=LoginWithAuth0-C82OCyDy.cjs.map