@wandelbots/nova-js 3.13.0-pr.307.07b1ea2 → 3.13.0-pr.307.2abdb29
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/Nova--8gozkLR.d.mts +85 -0
- package/dist/Nova--8gozkLR.d.mts.map +1 -0
- package/dist/Nova-B1o5iTQ6.d.cts +85 -0
- package/dist/Nova-B1o5iTQ6.d.cts.map +1 -0
- package/dist/{context-Cu5mXcFZ.cjs → context-BZELA2eh.cjs} +3 -146
- package/dist/context-BZELA2eh.cjs.map +1 -0
- package/dist/{context-CmXqEEwW.mjs → context-ffr5Q2dc.mjs} +3 -86
- package/dist/context-ffr5Q2dc.mjs.map +1 -0
- package/dist/converters-DnG1fX23.mjs +87 -0
- package/dist/converters-DnG1fX23.mjs.map +1 -0
- package/dist/converters-EYS27XJE.cjs +146 -0
- package/dist/converters-EYS27XJE.cjs.map +1 -0
- package/dist/experimental/nats/index.cjs +37 -4
- package/dist/experimental/nats/index.cjs.map +1 -1
- package/dist/experimental/nats/index.d.cts +30 -7
- package/dist/experimental/nats/index.d.cts.map +1 -1
- package/dist/experimental/nats/index.d.mts +30 -7
- package/dist/experimental/nats/index.d.mts.map +1 -1
- package/dist/experimental/nats/index.mjs +37 -5
- package/dist/experimental/nats/index.mjs.map +1 -1
- package/dist/index.cjs +13 -12
- package/dist/index.mjs +3 -2
- package/dist/v1/index.cjs +3 -3
- package/dist/v1/index.cjs.map +1 -1
- package/dist/v1/index.mjs +2 -2
- package/dist/v2/index.cjs +4 -3
- package/dist/v2/index.cjs.map +1 -1
- package/dist/v2/index.d.cts +5 -83
- package/dist/v2/index.d.cts.map +1 -1
- package/dist/v2/index.d.mts +4 -82
- package/dist/v2/index.d.mts.map +1 -1
- package/dist/v2/index.mjs +2 -1
- package/dist/v2/index.mjs.map +1 -1
- package/dist/{wandelscriptUtils-CKhiZJsB.mjs → wandelscriptUtils-CpUXdLVc.mjs} +3 -2
- package/dist/{wandelscriptUtils-CKhiZJsB.mjs.map → wandelscriptUtils-CpUXdLVc.mjs.map} +1 -1
- package/dist/{wandelscriptUtils-BdqeVDCY.cjs → wandelscriptUtils-DcY1aLWu.cjs} +13 -12
- package/dist/{wandelscriptUtils-BdqeVDCY.cjs.map → wandelscriptUtils-DcY1aLWu.cjs.map} +1 -1
- package/package.json +1 -1
- package/src/experimental/nats/index.ts +1 -0
- package/src/lib/experimental/nats/NovaNatsClient.ts +41 -4
- package/src/lib/experimental/nats/buildNatsServerUrl.ts +15 -0
- package/src/lib/experimental/nats/buildSubject.ts +2 -1
- package/src/lib/experimental/nats/generated/operations.ts +4 -4
- package/dist/context-CmXqEEwW.mjs.map +0 -1
- package/dist/context-Cu5mXcFZ.cjs.map +0 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { n as MockNovaInstance, t as AutoReconnectingWebsocket } from "./AutoReconnectingWebsocket-1K2J1NA4.mjs";
|
|
2
|
+
import { AxiosInstance } from "axios";
|
|
3
|
+
import { ApplicationApi, BUSInputsOutputsApi, CellApi, Configuration, ControllerApi, ControllerInputsOutputsApi, JoggingApi, KinematicsApi, LicenseApi, MotionGroupApi, MotionGroupModelsApi, NOVACloudApi, ProgramApi, RobotConfigurationsApi, SessionApi, StoreCollisionComponentsApi, StoreCollisionSetupsApi, StoreObjectApi, SystemApi, TrajectoryCachingApi, TrajectoryExecutionApi, TrajectoryPlanningApi, VersionApi, VirtualControllerApi, VirtualControllerBehaviorApi, VirtualControllerInputsOutputsApi } from "@wandelbots/nova-api/v2";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/NovaAPIClient.d.ts
|
|
6
|
+
type UnwrapAxiosResponseReturn<T> = T extends ((...a: any[]) => any) ? (...a: Parameters<T>) => Promise<Awaited<ReturnType<T>> extends {
|
|
7
|
+
data: infer D;
|
|
8
|
+
} ? D : never> : never;
|
|
9
|
+
type WithUnwrappedAxiosResponse<T> = { [P in keyof T]: UnwrapAxiosResponseReturn<T[P]> };
|
|
10
|
+
type NovaAPIClientOpts = Configuration & {
|
|
11
|
+
axiosInstance?: AxiosInstance;
|
|
12
|
+
mock?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* API client providing type-safe access to all the endpoints of a NOVA
|
|
16
|
+
* instance.
|
|
17
|
+
*/
|
|
18
|
+
declare class NovaAPIClient {
|
|
19
|
+
readonly opts: NovaAPIClientOpts;
|
|
20
|
+
readonly application: WithUnwrappedAxiosResponse<ApplicationApi>;
|
|
21
|
+
readonly busIOs: WithUnwrappedAxiosResponse<BUSInputsOutputsApi>;
|
|
22
|
+
readonly cell: WithUnwrappedAxiosResponse<CellApi>;
|
|
23
|
+
readonly controller: WithUnwrappedAxiosResponse<ControllerApi>;
|
|
24
|
+
readonly controllerIOs: WithUnwrappedAxiosResponse<ControllerInputsOutputsApi>;
|
|
25
|
+
readonly jogging: WithUnwrappedAxiosResponse<JoggingApi>;
|
|
26
|
+
readonly kinematics: WithUnwrappedAxiosResponse<KinematicsApi>;
|
|
27
|
+
readonly license: WithUnwrappedAxiosResponse<LicenseApi>;
|
|
28
|
+
readonly motionGroup: WithUnwrappedAxiosResponse<MotionGroupApi>;
|
|
29
|
+
readonly motionGroupModels: WithUnwrappedAxiosResponse<MotionGroupModelsApi>;
|
|
30
|
+
readonly novaCloud: WithUnwrappedAxiosResponse<NOVACloudApi>;
|
|
31
|
+
readonly program: WithUnwrappedAxiosResponse<ProgramApi>;
|
|
32
|
+
readonly robotConfigurations: WithUnwrappedAxiosResponse<RobotConfigurationsApi>;
|
|
33
|
+
readonly session: WithUnwrappedAxiosResponse<SessionApi>;
|
|
34
|
+
readonly storeCollisionComponents: WithUnwrappedAxiosResponse<StoreCollisionComponentsApi>;
|
|
35
|
+
readonly storeCollisionSetups: WithUnwrappedAxiosResponse<StoreCollisionSetupsApi>;
|
|
36
|
+
readonly storeObject: WithUnwrappedAxiosResponse<StoreObjectApi>;
|
|
37
|
+
readonly system: WithUnwrappedAxiosResponse<SystemApi>;
|
|
38
|
+
readonly trajectoryCaching: WithUnwrappedAxiosResponse<TrajectoryCachingApi>;
|
|
39
|
+
readonly trajectoryExecution: WithUnwrappedAxiosResponse<TrajectoryExecutionApi>;
|
|
40
|
+
readonly trajectoryPlanning: WithUnwrappedAxiosResponse<TrajectoryPlanningApi>;
|
|
41
|
+
readonly version: WithUnwrappedAxiosResponse<VersionApi>;
|
|
42
|
+
readonly virtualController: WithUnwrappedAxiosResponse<VirtualControllerApi>;
|
|
43
|
+
readonly virtualControllerBehavior: WithUnwrappedAxiosResponse<VirtualControllerBehaviorApi>;
|
|
44
|
+
readonly virtualControllerIOs: WithUnwrappedAxiosResponse<VirtualControllerInputsOutputsApi>;
|
|
45
|
+
constructor(opts: NovaAPIClientOpts);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/lib/Nova.d.ts
|
|
49
|
+
type NovaConfig = {
|
|
50
|
+
/**
|
|
51
|
+
* Url of the deployed NOVA instance to connect to
|
|
52
|
+
* e.g. https://saeattii.instance.wandelbots.io
|
|
53
|
+
*/
|
|
54
|
+
instanceUrl: string;
|
|
55
|
+
/**
|
|
56
|
+
* Access token for Bearer authentication.
|
|
57
|
+
* If running on a NOVA instance, this can be automatically retrieved from
|
|
58
|
+
* the current session when omitted.
|
|
59
|
+
*/
|
|
60
|
+
accessToken?: string;
|
|
61
|
+
} & Omit<Configuration, "isJsonMime" | "basePath">;
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* Client for connecting to a NOVA instance and controlling robots.
|
|
65
|
+
*/
|
|
66
|
+
declare class Nova {
|
|
67
|
+
readonly api: NovaAPIClient;
|
|
68
|
+
readonly config: NovaConfig;
|
|
69
|
+
readonly mock?: MockNovaInstance;
|
|
70
|
+
readonly instanceUrl: URL;
|
|
71
|
+
authPromise: Promise<string | null> | null;
|
|
72
|
+
accessToken: string | null;
|
|
73
|
+
constructor(config: NovaConfig);
|
|
74
|
+
renewAuthentication(): Promise<void>;
|
|
75
|
+
makeWebsocketURL(path: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieve an AutoReconnectingWebsocket to the given path on the Nova instance.
|
|
78
|
+
* If you explicitly want to reconnect an existing websocket, call `reconnect`
|
|
79
|
+
* on the returned object.
|
|
80
|
+
*/
|
|
81
|
+
openReconnectingWebsocket(path: string): AutoReconnectingWebsocket;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { NovaConfig as n, NovaAPIClient as r, Nova as t };
|
|
85
|
+
//# sourceMappingURL=Nova--8gozkLR.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Nova--8gozkLR.d.mts","names":[],"sources":["../src/lib/NovaAPIClient.ts","../src/lib/Nova.ts"],"mappings":";;;;;KAmCK,yBAAA,MAA+B,CAAA,cAAc,CAAA,uBAEzC,CAAA,EAAG,UAAA,CAAW,CAAA,MACd,OAAA,CAAQ,OAAA,CAAQ,UAAA,CAAW,CAAA;EAAc,IAAA;AAAA,IAAkB,CAAA;AAAA,KAG/D,0BAAA,oBACS,CAAA,GAAI,yBAAA,CAA0B,CAAA,CAAE,CAAA;AAAA,KAGzC,iBAAA,GAAoB,aAAA;EACvB,aAAA,GAAgB,aAAa;EAC7B,IAAA;AAAA;;;;;cAuCW,aAAA;EAAA,SACF,IAAA,EAAM,iBAAA;EAAA,SAEN,WAAA,EAAa,0BAAA,CAA2B,cAAA;EAAA,SACxC,MAAA,EAAQ,0BAAA,CAA2B,mBAAA;EAAA,SACnC,IAAA,EAAM,0BAAA,CAA2B,OAAA;EAAA,SACjC,UAAA,EAAY,0BAAA,CAA2B,aAAA;EAAA,SACvC,aAAA,EAAe,0BAAA,CAA2B,0BAAA;EAAA,SAC1C,OAAA,EAAS,0BAAA,CAA2B,UAAA;EAAA,SACpC,UAAA,EAAY,0BAAA,CAA2B,aAAA;EAAA,SACvC,OAAA,EAAS,0BAAA,CAA2B,UAAA;EAAA,SACpC,WAAA,EAAa,0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1,85 @@
|
|
|
1
|
+
import { n as MockNovaInstance, t as AutoReconnectingWebsocket } from "./AutoReconnectingWebsocket-1K2J1NA4.cjs";
|
|
2
|
+
import { ApplicationApi, BUSInputsOutputsApi, CellApi, Configuration, ControllerApi, ControllerInputsOutputsApi, JoggingApi, KinematicsApi, LicenseApi, MotionGroupApi, MotionGroupModelsApi, NOVACloudApi, ProgramApi, RobotConfigurationsApi, SessionApi, StoreCollisionComponentsApi, StoreCollisionSetupsApi, StoreObjectApi, SystemApi, TrajectoryCachingApi, TrajectoryExecutionApi, TrajectoryPlanningApi, VersionApi, VirtualControllerApi, VirtualControllerBehaviorApi, VirtualControllerInputsOutputsApi } from "@wandelbots/nova-api/v2";
|
|
3
|
+
import { AxiosInstance } from "axios";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/NovaAPIClient.d.ts
|
|
6
|
+
type UnwrapAxiosResponseReturn<T> = T extends ((...a: any[]) => any) ? (...a: Parameters<T>) => Promise<Awaited<ReturnType<T>> extends {
|
|
7
|
+
data: infer D;
|
|
8
|
+
} ? D : never> : never;
|
|
9
|
+
type WithUnwrappedAxiosResponse<T> = { [P in keyof T]: UnwrapAxiosResponseReturn<T[P]> };
|
|
10
|
+
type NovaAPIClientOpts = Configuration & {
|
|
11
|
+
axiosInstance?: AxiosInstance;
|
|
12
|
+
mock?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* API client providing type-safe access to all the endpoints of a NOVA
|
|
16
|
+
* instance.
|
|
17
|
+
*/
|
|
18
|
+
declare class NovaAPIClient {
|
|
19
|
+
readonly opts: NovaAPIClientOpts;
|
|
20
|
+
readonly application: WithUnwrappedAxiosResponse<ApplicationApi>;
|
|
21
|
+
readonly busIOs: WithUnwrappedAxiosResponse<BUSInputsOutputsApi>;
|
|
22
|
+
readonly cell: WithUnwrappedAxiosResponse<CellApi>;
|
|
23
|
+
readonly controller: WithUnwrappedAxiosResponse<ControllerApi>;
|
|
24
|
+
readonly controllerIOs: WithUnwrappedAxiosResponse<ControllerInputsOutputsApi>;
|
|
25
|
+
readonly jogging: WithUnwrappedAxiosResponse<JoggingApi>;
|
|
26
|
+
readonly kinematics: WithUnwrappedAxiosResponse<KinematicsApi>;
|
|
27
|
+
readonly license: WithUnwrappedAxiosResponse<LicenseApi>;
|
|
28
|
+
readonly motionGroup: WithUnwrappedAxiosResponse<MotionGroupApi>;
|
|
29
|
+
readonly motionGroupModels: WithUnwrappedAxiosResponse<MotionGroupModelsApi>;
|
|
30
|
+
readonly novaCloud: WithUnwrappedAxiosResponse<NOVACloudApi>;
|
|
31
|
+
readonly program: WithUnwrappedAxiosResponse<ProgramApi>;
|
|
32
|
+
readonly robotConfigurations: WithUnwrappedAxiosResponse<RobotConfigurationsApi>;
|
|
33
|
+
readonly session: WithUnwrappedAxiosResponse<SessionApi>;
|
|
34
|
+
readonly storeCollisionComponents: WithUnwrappedAxiosResponse<StoreCollisionComponentsApi>;
|
|
35
|
+
readonly storeCollisionSetups: WithUnwrappedAxiosResponse<StoreCollisionSetupsApi>;
|
|
36
|
+
readonly storeObject: WithUnwrappedAxiosResponse<StoreObjectApi>;
|
|
37
|
+
readonly system: WithUnwrappedAxiosResponse<SystemApi>;
|
|
38
|
+
readonly trajectoryCaching: WithUnwrappedAxiosResponse<TrajectoryCachingApi>;
|
|
39
|
+
readonly trajectoryExecution: WithUnwrappedAxiosResponse<TrajectoryExecutionApi>;
|
|
40
|
+
readonly trajectoryPlanning: WithUnwrappedAxiosResponse<TrajectoryPlanningApi>;
|
|
41
|
+
readonly version: WithUnwrappedAxiosResponse<VersionApi>;
|
|
42
|
+
readonly virtualController: WithUnwrappedAxiosResponse<VirtualControllerApi>;
|
|
43
|
+
readonly virtualControllerBehavior: WithUnwrappedAxiosResponse<VirtualControllerBehaviorApi>;
|
|
44
|
+
readonly virtualControllerIOs: WithUnwrappedAxiosResponse<VirtualControllerInputsOutputsApi>;
|
|
45
|
+
constructor(opts: NovaAPIClientOpts);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/lib/Nova.d.ts
|
|
49
|
+
type NovaConfig = {
|
|
50
|
+
/**
|
|
51
|
+
* Url of the deployed NOVA instance to connect to
|
|
52
|
+
* e.g. https://saeattii.instance.wandelbots.io
|
|
53
|
+
*/
|
|
54
|
+
instanceUrl: string;
|
|
55
|
+
/**
|
|
56
|
+
* Access token for Bearer authentication.
|
|
57
|
+
* If running on a NOVA instance, this can be automatically retrieved from
|
|
58
|
+
* the current session when omitted.
|
|
59
|
+
*/
|
|
60
|
+
accessToken?: string;
|
|
61
|
+
} & Omit<Configuration, "isJsonMime" | "basePath">;
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* Client for connecting to a NOVA instance and controlling robots.
|
|
65
|
+
*/
|
|
66
|
+
declare class Nova {
|
|
67
|
+
readonly api: NovaAPIClient;
|
|
68
|
+
readonly config: NovaConfig;
|
|
69
|
+
readonly mock?: MockNovaInstance;
|
|
70
|
+
readonly instanceUrl: URL;
|
|
71
|
+
authPromise: Promise<string | null> | null;
|
|
72
|
+
accessToken: string | null;
|
|
73
|
+
constructor(config: NovaConfig);
|
|
74
|
+
renewAuthentication(): Promise<void>;
|
|
75
|
+
makeWebsocketURL(path: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieve an AutoReconnectingWebsocket to the given path on the Nova instance.
|
|
78
|
+
* If you explicitly want to reconnect an existing websocket, call `reconnect`
|
|
79
|
+
* on the returned object.
|
|
80
|
+
*/
|
|
81
|
+
openReconnectingWebsocket(path: string): AutoReconnectingWebsocket;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { NovaConfig as n, NovaAPIClient as r, Nova as t };
|
|
85
|
+
//# sourceMappingURL=Nova-B1o5iTQ6.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Nova-B1o5iTQ6.d.cts","names":[],"sources":["../src/lib/NovaAPIClient.ts","../src/lib/Nova.ts"],"mappings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A;EAAA,SAC9C,mBAAA,EAAqB,0BAAA,CAA2B,sBAAA;EAAA,SAChD,kBAAA,EAAoB,0BAAA,CAA2B,qBAAA;EAAA,SAC/C,OAAA,EAAS,0BAAA,CAA2B,UAAA;EAAA,SACpC,iBAAA,EAAmB,0BAAA,CAA2B,oBAAA;EAAA,SAC9C,yBAAA,EAA2B,0BAAA,CAA2B,4BAAA;EAAA,SACtD,oBAAA,EAAsB,0BAAA,CAA2B,iCAAA;cAE9C,IAAA,EAAM,iBAAA;AAAA;;;KCvGR,UAAA;EDuBP;;;;EClBH,WAAA;EDoBU;;;;;ECbV,WAAA;AAAA,IACE,IAAI,CAAC,aAAA;;;;;cAMI,IAAA;EAAA,SACF,GAAA,EAAK,aAAA;EAAA,SACL,MAAA,EAAQ,UAAA;EAAA,SACR,IAAA,GAAO,gBAAA;EAAA,SACP,WAAA,EAAa,GAAA;EACtB,WAAA,EAAa,OAAA;EACb,WAAA;cAEY,MAAA,EAAQ,UAAA;EAqId,mBAAA,IAAuB,OAAA;EA4B7B,gBAAA,CAAiB,IAAA;EDlKkD;AAAA;;;;ECmLnE,yBAAA,CAA0B,IAAA,WAAY,yBAAA;AAAA"}
|
|
@@ -20,6 +20,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
//#endregion
|
|
23
|
+
const require_converters = require("./converters-EYS27XJE.cjs");
|
|
23
24
|
let reconnecting_websocket = require("reconnecting-websocket");
|
|
24
25
|
reconnecting_websocket = __toESM(reconnecting_websocket, 1);
|
|
25
26
|
let axios = require("axios");
|
|
@@ -176,90 +177,6 @@ var AvailableStorage = class {
|
|
|
176
177
|
};
|
|
177
178
|
const availableStorage = new AvailableStorage();
|
|
178
179
|
//#endregion
|
|
179
|
-
//#region src/lib/converters.ts
|
|
180
|
-
/**
|
|
181
|
-
* Parse a string as a URL, with options to enforce or default the scheme.
|
|
182
|
-
*/
|
|
183
|
-
function parseUrl(url, options = {}) {
|
|
184
|
-
const { scheme, defaultScheme } = options;
|
|
185
|
-
const schemeRegex = /^[a-zA-Z]+:\/\//;
|
|
186
|
-
if (scheme) {
|
|
187
|
-
url = url.replace(schemeRegex, "");
|
|
188
|
-
url = `${scheme}://${url}`;
|
|
189
|
-
} else if (defaultScheme && !schemeRegex.test(url)) url = `${defaultScheme}://${url}`;
|
|
190
|
-
return new URL(url);
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Attempt to parse a string as a URL; return undefined if we can't
|
|
194
|
-
*/
|
|
195
|
-
function tryParseUrl(url, options = {}) {
|
|
196
|
-
try {
|
|
197
|
-
return parseUrl(url, options);
|
|
198
|
-
} catch {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Permissively parse a NOVA instance URL from a config variable.
|
|
204
|
-
* If scheme is not specified, defaults to https for *.wandelbots.io hosts,
|
|
205
|
-
* and http otherwise.
|
|
206
|
-
* Throws an error if a valid URL could not be determined.
|
|
207
|
-
*/
|
|
208
|
-
function parseNovaInstanceUrl(url) {
|
|
209
|
-
if (tryParseUrl(url, { defaultScheme: "http" })?.host.endsWith(".wandelbots.io")) return parseUrl(url, { defaultScheme: "https" });
|
|
210
|
-
else return parseUrl(url, { defaultScheme: "http" });
|
|
211
|
-
}
|
|
212
|
-
/** Try to parse something as JSON; return undefined if we can't */
|
|
213
|
-
function tryParseJson(json) {
|
|
214
|
-
try {
|
|
215
|
-
return JSON.parse(json);
|
|
216
|
-
} catch {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/** Try to turn something into JSON; return undefined if we can't */
|
|
221
|
-
function tryStringifyJson(json) {
|
|
222
|
-
try {
|
|
223
|
-
return JSON.stringify(json);
|
|
224
|
-
} catch {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Converts object parameters to query string.
|
|
230
|
-
* e.g. { a: "1", b: "2" } => "?a=1&b=2"
|
|
231
|
-
* {} => ""
|
|
232
|
-
*/
|
|
233
|
-
function makeUrlQueryString(obj) {
|
|
234
|
-
const str = new URLSearchParams(obj).toString();
|
|
235
|
-
return str ? `?${str}` : "";
|
|
236
|
-
}
|
|
237
|
-
/** Convert radians to degrees */
|
|
238
|
-
function radiansToDegrees(radians) {
|
|
239
|
-
return radians * (180 / Math.PI);
|
|
240
|
-
}
|
|
241
|
-
/** Convert degrees to radians */
|
|
242
|
-
function degreesToRadians(degrees) {
|
|
243
|
-
return degrees * (Math.PI / 180);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Check for coordinate system id equivalence, accounting for the "world" default
|
|
247
|
-
* on empty/undefined values.
|
|
248
|
-
*/
|
|
249
|
-
function isSameCoordinateSystem(firstCoordSystem, secondCoordSystem) {
|
|
250
|
-
if (!firstCoordSystem) firstCoordSystem = "world";
|
|
251
|
-
if (!secondCoordSystem) secondCoordSystem = "world";
|
|
252
|
-
return firstCoordSystem === secondCoordSystem;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Helpful const for converting {x, y, z} to [x, y, z] and vice versa
|
|
256
|
-
*/
|
|
257
|
-
const XYZ_TO_VECTOR = {
|
|
258
|
-
x: 0,
|
|
259
|
-
y: 1,
|
|
260
|
-
z: 2
|
|
261
|
-
};
|
|
262
|
-
//#endregion
|
|
263
180
|
//#region src/lib/errorHandling.ts
|
|
264
181
|
function delay(ms) {
|
|
265
182
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -285,7 +202,7 @@ function makeErrorMessage(err) {
|
|
|
285
202
|
else return `${err.message} from ${err.config.method?.toUpperCase() || "accessing"} ${err.config.url}`;
|
|
286
203
|
} else if (err instanceof Error) return err.message;
|
|
287
204
|
else if (typeof err === "string") return err;
|
|
288
|
-
else if (typeof err === "object") return tryStringifyJson(err) || `Unserializable object ${err}`;
|
|
205
|
+
else if (typeof err === "object") return require_converters.tryStringifyJson(err) || `Unserializable object ${err}`;
|
|
289
206
|
return `${err}`;
|
|
290
207
|
}
|
|
291
208
|
/**
|
|
@@ -367,12 +284,6 @@ Object.defineProperty(exports, "AutoReconnectingWebsocket", {
|
|
|
367
284
|
return AutoReconnectingWebsocket;
|
|
368
285
|
}
|
|
369
286
|
});
|
|
370
|
-
Object.defineProperty(exports, "XYZ_TO_VECTOR", {
|
|
371
|
-
enumerable: true,
|
|
372
|
-
get: function() {
|
|
373
|
-
return XYZ_TO_VECTOR;
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
287
|
Object.defineProperty(exports, "__toESM", {
|
|
377
288
|
enumerable: true,
|
|
378
289
|
get: function() {
|
|
@@ -385,12 +296,6 @@ Object.defineProperty(exports, "availableStorage", {
|
|
|
385
296
|
return availableStorage;
|
|
386
297
|
}
|
|
387
298
|
});
|
|
388
|
-
Object.defineProperty(exports, "degreesToRadians", {
|
|
389
|
-
enumerable: true,
|
|
390
|
-
get: function() {
|
|
391
|
-
return degreesToRadians;
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
299
|
Object.defineProperty(exports, "delay", {
|
|
395
300
|
enumerable: true,
|
|
396
301
|
get: function() {
|
|
@@ -421,12 +326,6 @@ Object.defineProperty(exports, "isLocalhostDev", {
|
|
|
421
326
|
return isLocalhostDev;
|
|
422
327
|
}
|
|
423
328
|
});
|
|
424
|
-
Object.defineProperty(exports, "isSameCoordinateSystem", {
|
|
425
|
-
enumerable: true,
|
|
426
|
-
get: function() {
|
|
427
|
-
return isSameCoordinateSystem;
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
329
|
Object.defineProperty(exports, "loginWithAuth0", {
|
|
431
330
|
enumerable: true,
|
|
432
331
|
get: function() {
|
|
@@ -445,47 +344,5 @@ Object.defineProperty(exports, "makeShortErrorMessage", {
|
|
|
445
344
|
return makeShortErrorMessage;
|
|
446
345
|
}
|
|
447
346
|
});
|
|
448
|
-
Object.defineProperty(exports, "makeUrlQueryString", {
|
|
449
|
-
enumerable: true,
|
|
450
|
-
get: function() {
|
|
451
|
-
return makeUrlQueryString;
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
Object.defineProperty(exports, "parseNovaInstanceUrl", {
|
|
455
|
-
enumerable: true,
|
|
456
|
-
get: function() {
|
|
457
|
-
return parseNovaInstanceUrl;
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
Object.defineProperty(exports, "parseUrl", {
|
|
461
|
-
enumerable: true,
|
|
462
|
-
get: function() {
|
|
463
|
-
return parseUrl;
|
|
464
|
-
}
|
|
465
|
-
});
|
|
466
|
-
Object.defineProperty(exports, "radiansToDegrees", {
|
|
467
|
-
enumerable: true,
|
|
468
|
-
get: function() {
|
|
469
|
-
return radiansToDegrees;
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
Object.defineProperty(exports, "tryParseJson", {
|
|
473
|
-
enumerable: true,
|
|
474
|
-
get: function() {
|
|
475
|
-
return tryParseJson;
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
|
-
Object.defineProperty(exports, "tryParseUrl", {
|
|
479
|
-
enumerable: true,
|
|
480
|
-
get: function() {
|
|
481
|
-
return tryParseUrl;
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
Object.defineProperty(exports, "tryStringifyJson", {
|
|
485
|
-
enumerable: true,
|
|
486
|
-
get: function() {
|
|
487
|
-
return tryStringifyJson;
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
347
|
|
|
491
|
-
//# sourceMappingURL=context-
|
|
348
|
+
//# sourceMappingURL=context-BZELA2eh.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-BZELA2eh.cjs","names":["ReconnectingWebSocket","tryStringifyJson"],"sources":["../src/lib/AutoReconnectingWebsocket.ts","../src/lib/availableStorage.ts","../src/lib/errorHandling.ts","../src/lib/LoginWithAuth0.ts","../src/lib/context.ts"],"sourcesContent":["import ReconnectingWebSocket, { type ErrorEvent } from \"reconnecting-websocket\"\nimport type * as v1 from \"./deprecated/v1/mock/MockNovaInstance.ts\"\nimport type * as v2 from \"./mock/MockNovaInstance.ts\"\n\nexport class AutoReconnectingWebsocket extends ReconnectingWebSocket {\n receivedFirstMessage?: MessageEvent\n targetUrl: string\n disposed = false\n readonly opts: {\n mock?: v1.MockNovaInstance | v2.MockNovaInstance\n onDispose?: () => void\n }\n\n constructor(\n targetUrl: string,\n 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 this.opts = opts\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","import { isAxiosError } from \"axios\"\nimport { tryStringifyJson } from \"./converters.ts\"\n\nexport function delay(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\n/**\n * @deprecated Use makeErrorMessage instead and truncate the error for display as needed, or make a situation-specific localized error message based on a response code\n */\nexport function makeShortErrorMessage(err: unknown) {\n return makeErrorMessage(err)\n}\n\n/**\n * Attempts to make a helpful error message from an unknown thrown error\n * or promise rejection.\n *\n * This function is mainly to aid debugging and good bug reports. For\n * expected errors encountered by end users, it's more ideal to catch\n * the specific error code and provide a localized app-specific error message.\n */\nexport function makeErrorMessage(err: unknown): string {\n if (isAxiosError(err)) {\n if (err.response) {\n return `${err.response?.status} ${err.response?.statusText} from ${err.response?.config.method?.toUpperCase() || \"accessing\"} ${err.response?.config.url}: ${JSON.stringify(err.response?.data)}`\n } else if (err.config) {\n if (err.code === \"ERR_NETWORK\") {\n return `${err.message} from ${err.config.method?.toUpperCase() || \"accessing\"} ${err.config.url}. This error can happen because of either connection issues or server CORS policy.`\n } else {\n return `${err.message} from ${err.config.method?.toUpperCase() || \"accessing\"} ${err.config.url}`\n }\n }\n } else if (err instanceof Error) {\n return err.message\n } else if (typeof err === \"string\") {\n return err\n } else if (typeof err === \"object\") {\n return tryStringifyJson(err) || `Unserializable object ${err}`\n }\n\n return `${err}`\n}\n\n/**\n * Reloads the page with protection against loops.\n * Allows at most one reload per 10 seconds; otherwise throws\n * an error.\n */\nexport function guardedPageReload(key: string): Promise<never> {\n const RELOAD_KEY = `novajs_reload_guard:${key}`\n const RELOAD_COOLDOWN_MS = 10_000\n const lastReloadAt = Number(window.sessionStorage.getItem(RELOAD_KEY) ?? \"0\")\n\n if (Date.now() - lastReloadAt < RELOAD_COOLDOWN_MS) {\n throw new Error(\n `Unhandled error caused a reload (${key}), but a reload was already attempted recently. Aborting to prevent reload loop.`,\n )\n }\n\n window.sessionStorage.setItem(RELOAD_KEY, String(Date.now()))\n window.location.reload()\n\n return new Promise(() => {}) // never settles, the page should be reloading\n}\n","import { guardedPageReload } from \"./errorHandling.ts\"\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.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 return guardedPageReload(\"cloud_instance_auth\")\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","// Some general checks about the context the nova-js code is running in\n\nexport const isBrowser = typeof window !== \"undefined\"\n\nexport const isLocalhostDev =\n isBrowser &&\n window.location.hostname === \"localhost\" &&\n process.env.NODE_ENV === \"development\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAa,4BAAb,cAA+CA,uBAAAA,QAAsB;CACnE;CACA;CACA,WAAW;CACX;CAKA,YACE,WACA,OAGI,CAAC,GACL;EACA,QAAQ,IAAI,wBAAwB,SAAS;EAE7C,YAAY,KAAK,aAAa,WAAW,KAAA,GAAW,EAClD,aAAa,KACf,CAAC;EAGD,OAAO,eAAe,MAAM,OAAO,EACjC,MAAM;GACJ,OAAO,KAAK;EACd,EACF,CAAC;EAED,KAAK,YAAY;EACjB,KAAK,OAAO;EAEZ,KAAK,iBA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ACF,OAEE,MAAM,YAAY,kBAAkB;CAKtC,OAAO,MADmB,YAAY,iBAAiB;AAEzD;;;ACzFA,MAAa,YAAY,OAAO,WAAW;AAE3C,MAAa,iBACX,aACA,OAAO,SAAS,aAAa,eAC7B,QAAQ,IAAI,aAAa"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { u as tryStringifyJson } from "./converters-DnG1fX23.mjs";
|
|
1
2
|
import ReconnectingWebSocket from "reconnecting-websocket";
|
|
2
3
|
import { isAxiosError } from "axios";
|
|
3
4
|
//#region src/lib/AutoReconnectingWebsocket.ts
|
|
@@ -153,90 +154,6 @@ var AvailableStorage = class {
|
|
|
153
154
|
};
|
|
154
155
|
const availableStorage = new AvailableStorage();
|
|
155
156
|
//#endregion
|
|
156
|
-
//#region src/lib/converters.ts
|
|
157
|
-
/**
|
|
158
|
-
* Parse a string as a URL, with options to enforce or default the scheme.
|
|
159
|
-
*/
|
|
160
|
-
function parseUrl(url, options = {}) {
|
|
161
|
-
const { scheme, defaultScheme } = options;
|
|
162
|
-
const schemeRegex = /^[a-zA-Z]+:\/\//;
|
|
163
|
-
if (scheme) {
|
|
164
|
-
url = url.replace(schemeRegex, "");
|
|
165
|
-
url = `${scheme}://${url}`;
|
|
166
|
-
} else if (defaultScheme && !schemeRegex.test(url)) url = `${defaultScheme}://${url}`;
|
|
167
|
-
return new URL(url);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Attempt to parse a string as a URL; return undefined if we can't
|
|
171
|
-
*/
|
|
172
|
-
function tryParseUrl(url, options = {}) {
|
|
173
|
-
try {
|
|
174
|
-
return parseUrl(url, options);
|
|
175
|
-
} catch {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Permissively parse a NOVA instance URL from a config variable.
|
|
181
|
-
* If scheme is not specified, defaults to https for *.wandelbots.io hosts,
|
|
182
|
-
* and http otherwise.
|
|
183
|
-
* Throws an error if a valid URL could not be determined.
|
|
184
|
-
*/
|
|
185
|
-
function parseNovaInstanceUrl(url) {
|
|
186
|
-
if (tryParseUrl(url, { defaultScheme: "http" })?.host.endsWith(".wandelbots.io")) return parseUrl(url, { defaultScheme: "https" });
|
|
187
|
-
else return parseUrl(url, { defaultScheme: "http" });
|
|
188
|
-
}
|
|
189
|
-
/** Try to parse something as JSON; return undefined if we can't */
|
|
190
|
-
function tryParseJson(json) {
|
|
191
|
-
try {
|
|
192
|
-
return JSON.parse(json);
|
|
193
|
-
} catch {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
/** Try to turn something into JSON; return undefined if we can't */
|
|
198
|
-
function tryStringifyJson(json) {
|
|
199
|
-
try {
|
|
200
|
-
return JSON.stringify(json);
|
|
201
|
-
} catch {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Converts object parameters to query string.
|
|
207
|
-
* e.g. { a: "1", b: "2" } => "?a=1&b=2"
|
|
208
|
-
* {} => ""
|
|
209
|
-
*/
|
|
210
|
-
function makeUrlQueryString(obj) {
|
|
211
|
-
const str = new URLSearchParams(obj).toString();
|
|
212
|
-
return str ? `?${str}` : "";
|
|
213
|
-
}
|
|
214
|
-
/** Convert radians to degrees */
|
|
215
|
-
function radiansToDegrees(radians) {
|
|
216
|
-
return radians * (180 / Math.PI);
|
|
217
|
-
}
|
|
218
|
-
/** Convert degrees to radians */
|
|
219
|
-
function degreesToRadians(degrees) {
|
|
220
|
-
return degrees * (Math.PI / 180);
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Check for coordinate system id equivalence, accounting for the "world" default
|
|
224
|
-
* on empty/undefined values.
|
|
225
|
-
*/
|
|
226
|
-
function isSameCoordinateSystem(firstCoordSystem, secondCoordSystem) {
|
|
227
|
-
if (!firstCoordSystem) firstCoordSystem = "world";
|
|
228
|
-
if (!secondCoordSystem) secondCoordSystem = "world";
|
|
229
|
-
return firstCoordSystem === secondCoordSystem;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Helpful const for converting {x, y, z} to [x, y, z] and vice versa
|
|
233
|
-
*/
|
|
234
|
-
const XYZ_TO_VECTOR = {
|
|
235
|
-
x: 0,
|
|
236
|
-
y: 1,
|
|
237
|
-
z: 2
|
|
238
|
-
};
|
|
239
|
-
//#endregion
|
|
240
157
|
//#region src/lib/errorHandling.ts
|
|
241
158
|
function delay(ms) {
|
|
242
159
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -338,6 +255,6 @@ const loginWithAuth0 = async (instanceUrl) => {
|
|
|
338
255
|
const isBrowser = typeof window !== "undefined";
|
|
339
256
|
const isLocalhostDev = isBrowser && window.location.hostname === "localhost" && process.env.NODE_ENV === "development";
|
|
340
257
|
//#endregion
|
|
341
|
-
export {
|
|
258
|
+
export { delay as a, makeShortErrorMessage as c, loginWithAuth0 as i, availableStorage as l, isLocalhostDev as n, guardedPageReload as o, getAuth0Config as r, makeErrorMessage as s, isBrowser as t, AutoReconnectingWebsocket as u };
|
|
342
259
|
|
|
343
|
-
//# sourceMappingURL=context-
|
|
260
|
+
//# sourceMappingURL=context-ffr5Q2dc.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-ffr5Q2dc.mjs","names":[],"sources":["../src/lib/AutoReconnectingWebsocket.ts","../src/lib/availableStorage.ts","../src/lib/errorHandling.ts","../src/lib/LoginWithAuth0.ts","../src/lib/context.ts"],"sourcesContent":["import ReconnectingWebSocket, { type ErrorEvent } from \"reconnecting-websocket\"\nimport type * as v1 from \"./deprecated/v1/mock/MockNovaInstance.ts\"\nimport type * as v2 from \"./mock/MockNovaInstance.ts\"\n\nexport class AutoReconnectingWebsocket extends ReconnectingWebSocket {\n receivedFirstMessage?: MessageEvent\n targetUrl: string\n disposed = false\n readonly opts: {\n mock?: v1.MockNovaInstance | v2.MockNovaInstance\n onDispose?: () => void\n }\n\n constructor(\n targetUrl: string,\n 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 this.opts = opts\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","import { isAxiosError } from \"axios\"\nimport { tryStringifyJson } from \"./converters.ts\"\n\nexport function delay(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\n/**\n * @deprecated Use makeErrorMessage instead and truncate the error for display as needed, or make a situation-specific localized error message based on a response code\n */\nexport function makeShortErrorMessage(err: unknown) {\n return makeErrorMessage(err)\n}\n\n/**\n * Attempts to make a helpful error message from an unknown thrown error\n * or promise rejection.\n *\n * This function is mainly to aid debugging and good bug reports. For\n * expected errors encountered by end users, it's more ideal to catch\n * the specific error code and provide a localized app-specific error message.\n */\nexport function makeErrorMessage(err: unknown): string {\n if (isAxiosError(err)) {\n if (err.response) {\n return `${err.response?.status} ${err.response?.statusText} from ${err.response?.config.method?.toUpperCase() || \"accessing\"} ${err.response?.config.url}: ${JSON.stringify(err.response?.data)}`\n } else if (err.config) {\n if (err.code === \"ERR_NETWORK\") {\n return `${err.message} from ${err.config.method?.toUpperCase() || \"accessing\"} ${err.config.url}. This error can happen because of either connection issues or server CORS policy.`\n } else {\n return `${err.message} from ${err.config.method?.toUpperCase() || \"accessing\"} ${err.config.url}`\n }\n }\n } else if (err instanceof Error) {\n return err.message\n } else if (typeof err === \"string\") {\n return err\n } else if (typeof err === \"object\") {\n return tryStringifyJson(err) || `Unserializable object ${err}`\n }\n\n return `${err}`\n}\n\n/**\n * Reloads the page with protection against loops.\n * Allows at most one reload per 10 seconds; otherwise throws\n * an error.\n */\nexport function guardedPageReload(key: string): Promise<never> {\n const RELOAD_KEY = `novajs_reload_guard:${key}`\n const RELOAD_COOLDOWN_MS = 10_000\n const lastReloadAt = Number(window.sessionStorage.getItem(RELOAD_KEY) ?? \"0\")\n\n if (Date.now() - lastReloadAt < RELOAD_COOLDOWN_MS) {\n throw new Error(\n `Unhandled error caused a reload (${key}), but a reload was already attempted recently. Aborting to prevent reload loop.`,\n )\n }\n\n window.sessionStorage.setItem(RELOAD_KEY, String(Date.now()))\n window.location.reload()\n\n return new Promise(() => {}) // never settles, the page should be reloading\n}\n","import { guardedPageReload } from \"./errorHandling.ts\"\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.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 return guardedPageReload(\"cloud_instance_auth\")\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","// Some general checks about the context the nova-js code is running in\n\nexport const isBrowser = typeof window !== \"undefined\"\n\nexport const isLocalhostDev =\n isBrowser &&\n window.location.hostname === \"localhost\" &&\n process.env.NODE_ENV === \"development\"\n"],"mappings":";;;;AAIA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE;CACA;CACA,WAAW;CACX;CAKA,YACE,WACA,OAGI,CAAC,GACL;EACA,QAAQ,IAAI,wBAAwB,SAAS;EAE7C,YAAY,KAAK,aAAa,WAAW,KAAA,GAAW,EAClD,aAAa,KACf,CAAC;EAGD,OAAO,eAAe,MAAM,OAAO,EACjC,MAAM;GACJ,OAAO,KAAK;EACd,EACF,CAAC;EAED,KAAK,YAAY;EACjB,KAAK,OAAO;EAEZ,KAAK,iBAAiB,cAAc;GAClC,QAAQ,IAAI,gBAAgB,KAAK,IAAI,QAAQ;EAC/C,CAAC;EAED,KAAK,iBAAiB,YAAY,OAAO;GACvC,IAAI,CAAC,KAAK,sBACR,KAAK,uBAAuB;EAEhC,CAAC;EAED,KAAK,iBAAiB,eAAe;GACnC,QAAQ,IAAI,gBAAgB,KAAK,IAAI,QAAQ;EAC/C,CAAC;EAED,MAAM,gBAAgB,KAAK;EAC3B,KAAK,kBAAkB;GACrB,IAAI,KAAK,KA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ACZ;CACA,MAAM;EACJ,QAAQ;EACR,UAAU;CACZ;AACF;;AAGA,MAAa,kBAAkB,gBAAqB;CAClD,IAAI,YAAY,KAAK,SAAS,oBAAoB,GAAG,OAAO,eAAe;CAC3E,IAAI,YAAY,KAAK,SAAS,oBAAoB,GAAG,OAAO,eAAe;CAC3E,IAAI,YAAY,KAAK,SAAS,gBAAgB,GAAG,OAAO,eAAe;CACvE,MAAM,IAAI,MACR,8CAA8C,YAAY,gGAC5D;AACF;;;;;;AAOA,MAAa,iBAAiB,OAC5B,gBAC2B;CAC3B,IAAI,OAAO,WAAW,aACpB,MAAM,IAAI,MACR,+EACF;CAGF,IAAI,YAAY,WAAW,OAAO,SAAS,QAIzC,OAAO,kBAAkB,qBAAqB;CAMhD,MAAM,EAAE,gBAAgB,MAAM,OAAO;CAErC,MAAM,cAAc,eAAe,WAAW;CAE9C,MAAM,cAAc,IAAI,YAAY;EAClC,QAAQ,YAAY;EACpB,UAAU,YAAY,YAAY;EAClC,kBAAkB;EAClB,qBAAqB;GACnB,UAAU;GACV,cAAc,OAAO,SAAS;EAChC;CACF,CAAC;CAGD,IACE,OAAO,SAAS,OAAO,SAAS,OAAO,KACvC,OAAO,SAAS,OAAO,SAAS,QAAQ,GACxC;EACA,MAAM,EAAE,aAAa,MAAM,YAAY,uBAAuB;EAE9D,OAAO,QAAQ,aACb,CAAC,GACD,SAAS,OACT,UAAU,YAAY,OAAO,SAAS,QACxC;CACF,OAEE,MAAM,YAAY,kBAAkB;CAKtC,OAAO,MADmB,YAAY,iBAAiB;AAEzD;;;ACzFA,MAAa,YAAY,OAAO,WAAW;AAE3C,MAAa,iBACX,aACA,OAAO,SAAS,aAAa,eAC7B,QAAQ,IAAI,aAAa"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
//#region src/lib/converters.ts
|
|
2
|
+
/**
|
|
3
|
+
* Parse a string as a URL, with options to enforce or default the scheme.
|
|
4
|
+
*/
|
|
5
|
+
function parseUrl(url, options = {}) {
|
|
6
|
+
const { scheme, defaultScheme } = options;
|
|
7
|
+
const schemeRegex = /^[a-zA-Z]+:\/\//;
|
|
8
|
+
if (scheme) {
|
|
9
|
+
url = url.replace(schemeRegex, "");
|
|
10
|
+
url = `${scheme}://${url}`;
|
|
11
|
+
} else if (defaultScheme && !schemeRegex.test(url)) url = `${defaultScheme}://${url}`;
|
|
12
|
+
return new URL(url);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Attempt to parse a string as a URL; return undefined if we can't
|
|
16
|
+
*/
|
|
17
|
+
function tryParseUrl(url, options = {}) {
|
|
18
|
+
try {
|
|
19
|
+
return parseUrl(url, options);
|
|
20
|
+
} catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Permissively parse a NOVA instance URL from a config variable.
|
|
26
|
+
* If scheme is not specified, defaults to https for *.wandelbots.io hosts,
|
|
27
|
+
* and http otherwise.
|
|
28
|
+
* Throws an error if a valid URL could not be determined.
|
|
29
|
+
*/
|
|
30
|
+
function parseNovaInstanceUrl(url) {
|
|
31
|
+
if (tryParseUrl(url, { defaultScheme: "http" })?.host.endsWith(".wandelbots.io")) return parseUrl(url, { defaultScheme: "https" });
|
|
32
|
+
else return parseUrl(url, { defaultScheme: "http" });
|
|
33
|
+
}
|
|
34
|
+
/** Try to parse something as JSON; return undefined if we can't */
|
|
35
|
+
function tryParseJson(json) {
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(json);
|
|
38
|
+
} catch {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Try to turn something into JSON; return undefined if we can't */
|
|
43
|
+
function tryStringifyJson(json) {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.stringify(json);
|
|
46
|
+
} catch {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Converts object parameters to query string.
|
|
52
|
+
* e.g. { a: "1", b: "2" } => "?a=1&b=2"
|
|
53
|
+
* {} => ""
|
|
54
|
+
*/
|
|
55
|
+
function makeUrlQueryString(obj) {
|
|
56
|
+
const str = new URLSearchParams(obj).toString();
|
|
57
|
+
return str ? `?${str}` : "";
|
|
58
|
+
}
|
|
59
|
+
/** Convert radians to degrees */
|
|
60
|
+
function radiansToDegrees(radians) {
|
|
61
|
+
return radians * (180 / Math.PI);
|
|
62
|
+
}
|
|
63
|
+
/** Convert degrees to radians */
|
|
64
|
+
function degreesToRadians(degrees) {
|
|
65
|
+
return degrees * (Math.PI / 180);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check for coordinate system id equivalence, accounting for the "world" default
|
|
69
|
+
* on empty/undefined values.
|
|
70
|
+
*/
|
|
71
|
+
function isSameCoordinateSystem(firstCoordSystem, secondCoordSystem) {
|
|
72
|
+
if (!firstCoordSystem) firstCoordSystem = "world";
|
|
73
|
+
if (!secondCoordSystem) secondCoordSystem = "world";
|
|
74
|
+
return firstCoordSystem === secondCoordSystem;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Helpful const for converting {x, y, z} to [x, y, z] and vice versa
|
|
78
|
+
*/
|
|
79
|
+
const XYZ_TO_VECTOR = {
|
|
80
|
+
x: 0,
|
|
81
|
+
y: 1,
|
|
82
|
+
z: 2
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { parseNovaInstanceUrl as a, tryParseJson as c, makeUrlQueryString as i, tryParseUrl as l, degreesToRadians as n, parseUrl as o, isSameCoordinateSystem as r, radiansToDegrees as s, XYZ_TO_VECTOR as t, tryStringifyJson as u };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=converters-DnG1fX23.mjs.map
|