@wandelbots/nova-js 3.13.0 → 4.0.0-pr.309.02b99fd
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/{AutoReconnectingWebsocket-1K2J1NA4.d.cts → AutoReconnectingWebsocket-BSt-vnzX.d.mts} +4 -16
- package/dist/AutoReconnectingWebsocket-BSt-vnzX.d.mts.map +1 -0
- package/dist/{context-ffr5Q2dc.mjs → LoginWithAuth0-D92HnzHq.mjs} +3 -13
- package/dist/LoginWithAuth0-D92HnzHq.mjs.map +1 -0
- package/dist/{Nova--8gozkLR.d.mts → Nova-C8nDNSCa.d.mts} +2 -2
- package/dist/{Nova--8gozkLR.d.mts.map → Nova-C8nDNSCa.d.mts.map} +1 -1
- package/dist/experimental/nats/index.d.mts +1 -1
- package/dist/index.d.mts +2 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -3
- package/dist/v2/index.d.mts +2 -130
- package/dist/v2/index.mjs +4 -231
- package/dist/v2/index.mjs.map +1 -1
- package/package.json +13 -17
- package/src/index.ts +0 -2
- package/src/lib/AutoReconnectingWebsocket.ts +3 -4
- package/src/lib/LoginWithAuth0.ts +1 -1
- package/src/lib/context.ts +1 -1
- package/src/lib/errorHandling.ts +0 -7
- package/src/v2/index.ts +0 -3
- package/dist/AutoReconnectingWebsocket-1K2J1NA4.d.cts.map +0 -1
- package/dist/AutoReconnectingWebsocket-1K2J1NA4.d.mts +0 -69
- package/dist/AutoReconnectingWebsocket-1K2J1NA4.d.mts.map +0 -1
- package/dist/Nova-B1o5iTQ6.d.cts +0 -85
- package/dist/Nova-B1o5iTQ6.d.cts.map +0 -1
- package/dist/context-BZELA2eh.cjs +0 -348
- package/dist/context-BZELA2eh.cjs.map +0 -1
- package/dist/context-ffr5Q2dc.mjs.map +0 -1
- package/dist/converters-EYS27XJE.cjs +0 -146
- package/dist/converters-EYS27XJE.cjs.map +0 -1
- package/dist/experimental/nats/index.cjs +0 -158
- package/dist/experimental/nats/index.cjs.map +0 -1
- package/dist/experimental/nats/index.d.cts +0 -3235
- package/dist/experimental/nats/index.d.cts.map +0 -1
- package/dist/index.cjs +0 -24
- package/dist/index.d.cts +0 -110
- package/dist/index.d.cts.map +0 -1
- package/dist/v1/index.cjs +0 -201
- package/dist/v1/index.cjs.map +0 -1
- package/dist/v1/index.d.cts +0 -67
- package/dist/v1/index.d.cts.map +0 -1
- package/dist/v1/index.d.mts +0 -67
- package/dist/v1/index.d.mts.map +0 -1
- package/dist/v1/index.mjs +0 -184
- package/dist/v1/index.mjs.map +0 -1
- package/dist/v2/index.cjs +0 -1038
- package/dist/v2/index.cjs.map +0 -1
- package/dist/v2/index.d.cts +0 -131
- package/dist/v2/index.d.cts.map +0 -1
- package/dist/v2/index.d.mts.map +0 -1
- package/dist/wandelscriptUtils-CpUXdLVc.mjs +0 -2062
- package/dist/wandelscriptUtils-CpUXdLVc.mjs.map +0 -1
- package/dist/wandelscriptUtils-DY3WsiuB.d.cts +0 -356
- package/dist/wandelscriptUtils-DY3WsiuB.d.cts.map +0 -1
- package/dist/wandelscriptUtils-DcY1aLWu.cjs +0 -2099
- package/dist/wandelscriptUtils-DcY1aLWu.cjs.map +0 -1
- package/dist/wandelscriptUtils-YHTxn_p9.d.mts +0 -356
- package/dist/wandelscriptUtils-YHTxn_p9.d.mts.map +0 -1
- package/src/lib/deprecated/v1/ConnectedMotionGroup.ts +0 -449
- package/src/lib/deprecated/v1/JoggerConnection.ts +0 -491
- package/src/lib/deprecated/v1/MotionStreamConnection.ts +0 -215
- package/src/lib/deprecated/v1/NovaCellAPIClient.ts +0 -208
- package/src/lib/deprecated/v1/NovaClient.ts +0 -260
- package/src/lib/deprecated/v1/ProgramStateConnection.ts +0 -277
- package/src/lib/deprecated/v1/getLatestTrajectories.ts +0 -37
- package/src/lib/deprecated/v1/mock/MockNovaInstance.ts +0 -1303
- package/src/lib/deprecated/v1/motionStateUpdate.ts +0 -58
- package/src/lib/deprecated/v1/wandelscriptUtils.ts +0 -23
- package/src/lib/deprecated/v2/NovaCellAPIClient.ts +0 -215
- package/src/lib/deprecated/v2/NovaClient.ts +0 -218
- package/src/lib/deprecated/v2/wandelscriptUtils.ts +0 -28
- package/src/v1/index.ts +0 -14
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { TcpPose } from "@wandelbots/nova-api/v1"
|
|
2
|
-
|
|
3
|
-
/** @deprecated */
|
|
4
|
-
export function jointValuesEqual(
|
|
5
|
-
oldJointValues: number[],
|
|
6
|
-
newJointValues: number[],
|
|
7
|
-
changeDeltaThreshold: number,
|
|
8
|
-
): boolean {
|
|
9
|
-
if (newJointValues.length !== oldJointValues.length) {
|
|
10
|
-
return true
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
for (let jointIndex = 0; jointIndex < newJointValues.length; jointIndex++) {
|
|
14
|
-
if (
|
|
15
|
-
// biome-ignore lint/style/noNonNullAssertion: legacy code
|
|
16
|
-
Math.abs(newJointValues[jointIndex]! - oldJointValues[jointIndex]!) >
|
|
17
|
-
changeDeltaThreshold
|
|
18
|
-
) {
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return true
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** @deprecated */
|
|
27
|
-
export function tcpPoseEqual(
|
|
28
|
-
oldTcp: TcpPose | undefined,
|
|
29
|
-
newTcp: TcpPose | undefined,
|
|
30
|
-
changeDeltaThreshold: number,
|
|
31
|
-
): boolean {
|
|
32
|
-
// undefined -> defined (+reverse) transition
|
|
33
|
-
if ((oldTcp === undefined && newTcp) || (oldTcp && newTcp === undefined)) {
|
|
34
|
-
return false
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// the typechecker cannot resolve states to "!= undefined" if "&&" is used
|
|
38
|
-
if (oldTcp === undefined || newTcp === undefined) {
|
|
39
|
-
return true
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let changedDelta = 0
|
|
43
|
-
changedDelta += Math.abs(oldTcp.orientation.x - newTcp.orientation.x)
|
|
44
|
-
changedDelta += Math.abs(oldTcp.orientation.y - newTcp.orientation.y)
|
|
45
|
-
changedDelta += Math.abs(oldTcp.orientation.z - newTcp.orientation.z)
|
|
46
|
-
changedDelta += Math.abs(oldTcp.position.x - newTcp.position.x)
|
|
47
|
-
changedDelta += Math.abs(oldTcp.position.y - newTcp.position.y)
|
|
48
|
-
changedDelta += Math.abs(oldTcp.position.z - newTcp.position.z)
|
|
49
|
-
|
|
50
|
-
if (changedDelta > changeDeltaThreshold) {
|
|
51
|
-
return false
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
oldTcp.coordinate_system === newTcp.coordinate_system &&
|
|
56
|
-
oldTcp.tcp === newTcp.tcp
|
|
57
|
-
)
|
|
58
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Pose } from "@wandelbots/nova-api/v1"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Convert a Pose object representing a motion group position
|
|
5
|
-
* into a string which represents that pose in Wandelscript.
|
|
6
|
-
* @deprecated
|
|
7
|
-
*/
|
|
8
|
-
export function poseToWandelscriptString(
|
|
9
|
-
pose: Pick<Pose, "position" | "orientation">,
|
|
10
|
-
) {
|
|
11
|
-
const position = [pose.position.x, pose.position.y, pose.position.z]
|
|
12
|
-
const orientation = [
|
|
13
|
-
pose.orientation?.x ?? 0,
|
|
14
|
-
pose.orientation?.y ?? 0,
|
|
15
|
-
pose.orientation?.z ?? 0,
|
|
16
|
-
]
|
|
17
|
-
|
|
18
|
-
const positionValues = position.map((v) => v.toFixed(1))
|
|
19
|
-
// Rotation needs more precision since it's in radians
|
|
20
|
-
const rotationValues = orientation.map((v) => v.toFixed(4))
|
|
21
|
-
|
|
22
|
-
return `(${positionValues.concat(rotationValues).join(", ")})`
|
|
23
|
-
}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/** biome-ignore-all lint/suspicious/noExplicitAny: legacy code */
|
|
2
|
-
/** biome-ignore-all lint/style/noNonNullAssertion: legacy code */
|
|
3
|
-
import type {
|
|
4
|
-
BaseAPI,
|
|
5
|
-
Configuration as BaseConfiguration,
|
|
6
|
-
} from "@wandelbots/nova-api/v2"
|
|
7
|
-
import {
|
|
8
|
-
ApplicationApi,
|
|
9
|
-
BUSInputsOutputsApi,
|
|
10
|
-
CellApi,
|
|
11
|
-
ControllerApi,
|
|
12
|
-
ControllerInputsOutputsApi,
|
|
13
|
-
JoggingApi,
|
|
14
|
-
KinematicsApi,
|
|
15
|
-
LicenseApi,
|
|
16
|
-
MotionGroupApi,
|
|
17
|
-
MotionGroupModelsApi,
|
|
18
|
-
NOVACloudApi,
|
|
19
|
-
ProgramApi,
|
|
20
|
-
RobotConfigurationsApi,
|
|
21
|
-
SessionApi,
|
|
22
|
-
StoreCollisionComponentsApi,
|
|
23
|
-
StoreCollisionSetupsApi,
|
|
24
|
-
StoreObjectApi,
|
|
25
|
-
SystemApi,
|
|
26
|
-
TrajectoryCachingApi,
|
|
27
|
-
TrajectoryExecutionApi,
|
|
28
|
-
TrajectoryPlanningApi,
|
|
29
|
-
VersionApi,
|
|
30
|
-
VirtualControllerApi,
|
|
31
|
-
VirtualControllerBehaviorApi,
|
|
32
|
-
VirtualControllerInputsOutputsApi,
|
|
33
|
-
} from "@wandelbots/nova-api/v2"
|
|
34
|
-
import type { AxiosInstance } from "axios"
|
|
35
|
-
import axios from "axios"
|
|
36
|
-
|
|
37
|
-
type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R
|
|
38
|
-
? (...args: P) => R
|
|
39
|
-
: never
|
|
40
|
-
|
|
41
|
-
type UnwrapAxiosResponseReturn<T> = T extends (...a: any) => any
|
|
42
|
-
? (
|
|
43
|
-
...a: Parameters<T>
|
|
44
|
-
) => Promise<Awaited<ReturnType<T>> extends { data: infer D } ? D : never>
|
|
45
|
-
: never
|
|
46
|
-
|
|
47
|
-
/** @deprecated Use `NovaAPIClient` instead. */
|
|
48
|
-
export type WithCellId<T> = {
|
|
49
|
-
[P in keyof T]: UnwrapAxiosResponseReturn<OmitFirstArg<T[P]>>
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** @deprecated Use `NovaAPIClient` instead. */
|
|
53
|
-
export type WithUnwrappedAxiosResponse<T> = {
|
|
54
|
-
[P in keyof T]: UnwrapAxiosResponseReturn<T[P]>
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* API client providing type-safe access to all the Nova API REST endpoints
|
|
59
|
-
* associated with a specific cell id.
|
|
60
|
-
* @deprecated Use `NovaAPIClient` from `@wandelbots/nova-js/v2` instead.
|
|
61
|
-
*/
|
|
62
|
-
export class NovaCellAPIClient {
|
|
63
|
-
readonly system: WithUnwrappedAxiosResponse<SystemApi>
|
|
64
|
-
readonly cell: WithUnwrappedAxiosResponse<CellApi>
|
|
65
|
-
readonly motionGroup: WithCellId<MotionGroupApi>
|
|
66
|
-
readonly motionGroupModels: WithUnwrappedAxiosResponse<MotionGroupModelsApi>
|
|
67
|
-
readonly controller: WithCellId<ControllerApi>
|
|
68
|
-
readonly controllerIOs: WithCellId<ControllerInputsOutputsApi>
|
|
69
|
-
readonly trajectoryPlanning: WithCellId<TrajectoryPlanningApi>
|
|
70
|
-
readonly trajectoryExecution: WithCellId<TrajectoryExecutionApi>
|
|
71
|
-
readonly trajectoryCaching: WithCellId<TrajectoryCachingApi>
|
|
72
|
-
readonly application: WithCellId<ApplicationApi>
|
|
73
|
-
readonly applicationGlobal: WithUnwrappedAxiosResponse<ApplicationApi>
|
|
74
|
-
readonly jogging: WithCellId<JoggingApi>
|
|
75
|
-
readonly kinematics: WithCellId<KinematicsApi>
|
|
76
|
-
readonly busInputsOutputs: WithCellId<BUSInputsOutputsApi>
|
|
77
|
-
readonly virtualController: WithCellId<VirtualControllerApi>
|
|
78
|
-
readonly virtualControllerBehavior: WithCellId<VirtualControllerBehaviorApi>
|
|
79
|
-
readonly virtualControllerIOs: WithCellId<VirtualControllerInputsOutputsApi>
|
|
80
|
-
readonly storeObject: WithCellId<StoreObjectApi>
|
|
81
|
-
readonly storeCollisionComponents: WithCellId<StoreCollisionComponentsApi>
|
|
82
|
-
readonly storeCollisionSetups: WithCellId<StoreCollisionSetupsApi>
|
|
83
|
-
readonly program: WithCellId<ProgramApi>
|
|
84
|
-
readonly license: WithUnwrappedAxiosResponse<LicenseApi>
|
|
85
|
-
readonly novaCloud: WithUnwrappedAxiosResponse<NOVACloudApi>
|
|
86
|
-
readonly robotConfigurations: WithUnwrappedAxiosResponse<RobotConfigurationsApi>
|
|
87
|
-
readonly version: WithUnwrappedAxiosResponse<VersionApi>
|
|
88
|
-
readonly session: WithUnwrappedAxiosResponse<SessionApi>
|
|
89
|
-
|
|
90
|
-
readonly cellId: string
|
|
91
|
-
readonly opts: BaseConfiguration & {
|
|
92
|
-
axiosInstance?: AxiosInstance
|
|
93
|
-
mock?: boolean
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
constructor(
|
|
97
|
-
cellId: string,
|
|
98
|
-
opts: BaseConfiguration & {
|
|
99
|
-
axiosInstance?: AxiosInstance
|
|
100
|
-
mock?: boolean
|
|
101
|
-
},
|
|
102
|
-
) {
|
|
103
|
-
this.cellId = cellId
|
|
104
|
-
this.opts = opts
|
|
105
|
-
this.system = this.withUnwrappedResponsesOnly(SystemApi)
|
|
106
|
-
this.cell = this.withUnwrappedResponsesOnly(CellApi)
|
|
107
|
-
this.motionGroup = this.withCellId(MotionGroupApi)
|
|
108
|
-
this.motionGroupModels =
|
|
109
|
-
this.withUnwrappedResponsesOnly(MotionGroupModelsApi)
|
|
110
|
-
this.controller = this.withCellId(ControllerApi)
|
|
111
|
-
this.controllerIOs = this.withCellId(ControllerInputsOutputsApi)
|
|
112
|
-
this.trajectoryPlanning = this.withCellId(TrajectoryPlanningApi)
|
|
113
|
-
this.trajectoryExecution = this.withCellId(TrajectoryExecutionApi)
|
|
114
|
-
this.trajectoryCaching = this.withCellId(TrajectoryCachingApi)
|
|
115
|
-
this.application = this.withCellId(ApplicationApi)
|
|
116
|
-
this.applicationGlobal = this.withUnwrappedResponsesOnly(ApplicationApi)
|
|
117
|
-
this.jogging = this.withCellId(JoggingApi)
|
|
118
|
-
this.kinematics = this.withCellId(KinematicsApi)
|
|
119
|
-
this.busInputsOutputs = this.withCellId(BUSInputsOutputsApi)
|
|
120
|
-
this.virtualController = this.withCellId(VirtualControllerApi)
|
|
121
|
-
this.virtualControllerBehavior = this.withCellId(
|
|
122
|
-
VirtualControllerBehaviorApi,
|
|
123
|
-
)
|
|
124
|
-
this.virtualControllerIOs = this.withCellId(
|
|
125
|
-
VirtualControllerInputsOutputsApi,
|
|
126
|
-
)
|
|
127
|
-
this.storeObject = this.withCellId(StoreObjectApi)
|
|
128
|
-
this.storeCollisionComponents = this.withCellId(StoreCollisionComponentsApi)
|
|
129
|
-
this.storeCollisionSetups = this.withCellId(StoreCollisionSetupsApi)
|
|
130
|
-
this.program = this.withCellId(ProgramApi)
|
|
131
|
-
this.license = this.withUnwrappedResponsesOnly(LicenseApi)
|
|
132
|
-
this.novaCloud = this.withUnwrappedResponsesOnly(NOVACloudApi)
|
|
133
|
-
this.robotConfigurations = this.withUnwrappedResponsesOnly(
|
|
134
|
-
RobotConfigurationsApi,
|
|
135
|
-
)
|
|
136
|
-
this.version = this.withUnwrappedResponsesOnly(VersionApi)
|
|
137
|
-
this.session = this.withUnwrappedResponsesOnly(SessionApi)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Some TypeScript sorcery which alters the API class methods so you don't
|
|
142
|
-
* have to pass the cell id to every single one, and de-encapsulates the
|
|
143
|
-
* response data
|
|
144
|
-
*/
|
|
145
|
-
private withCellId<T extends BaseAPI>(
|
|
146
|
-
ApiConstructor: new (
|
|
147
|
-
config: BaseConfiguration,
|
|
148
|
-
basePath: string,
|
|
149
|
-
axios: AxiosInstance,
|
|
150
|
-
) => T,
|
|
151
|
-
) {
|
|
152
|
-
const apiClient = new ApiConstructor(
|
|
153
|
-
{
|
|
154
|
-
...this.opts,
|
|
155
|
-
isJsonMime: (mime: string) => {
|
|
156
|
-
return mime === "application/json"
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
this.opts.basePath ?? "",
|
|
160
|
-
this.opts.axiosInstance ?? axios.create(),
|
|
161
|
-
) as {
|
|
162
|
-
[key: string | symbol]: any
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient)!)) {
|
|
166
|
-
if (key !== "constructor" && typeof apiClient[key] === "function") {
|
|
167
|
-
const originalFunction = apiClient[key]
|
|
168
|
-
apiClient[key] = (...args: any[]) => {
|
|
169
|
-
return originalFunction
|
|
170
|
-
.apply(apiClient, [this.cellId, ...args])
|
|
171
|
-
.then((res: any) => res.data)
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return apiClient as WithCellId<T>
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* As withCellId, but only does the response unwrapping
|
|
181
|
-
*/
|
|
182
|
-
private withUnwrappedResponsesOnly<T extends BaseAPI>(
|
|
183
|
-
ApiConstructor: new (
|
|
184
|
-
config: BaseConfiguration,
|
|
185
|
-
basePath: string,
|
|
186
|
-
axios: AxiosInstance,
|
|
187
|
-
) => T,
|
|
188
|
-
) {
|
|
189
|
-
const apiClient = new ApiConstructor(
|
|
190
|
-
{
|
|
191
|
-
...this.opts,
|
|
192
|
-
isJsonMime: (mime: string) => {
|
|
193
|
-
return mime === "application/json"
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
this.opts.basePath ?? "",
|
|
197
|
-
this.opts.axiosInstance ?? axios.create(),
|
|
198
|
-
) as {
|
|
199
|
-
[key: string | symbol]: any
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient)!)) {
|
|
203
|
-
if (key !== "constructor" && typeof apiClient[key] === "function") {
|
|
204
|
-
const originalFunction = apiClient[key]
|
|
205
|
-
apiClient[key] = (...args: any[]) => {
|
|
206
|
-
return originalFunction
|
|
207
|
-
.apply(apiClient, args)
|
|
208
|
-
.then((res: any) => res.data)
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return apiClient as WithUnwrappedAxiosResponse<T>
|
|
214
|
-
}
|
|
215
|
-
}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/** biome-ignore-all lint/style/noNonNullAssertion: legacy code */
|
|
2
|
-
import type { Configuration as BaseConfiguration } from "@wandelbots/nova-api/v2"
|
|
3
|
-
import type { AxiosRequestConfig } from "axios"
|
|
4
|
-
import axios, { isAxiosError } from "axios"
|
|
5
|
-
import { AutoReconnectingWebsocket } from "../../AutoReconnectingWebsocket.ts"
|
|
6
|
-
import { availableStorage } from "../../availableStorage.ts"
|
|
7
|
-
import { parseNovaInstanceUrl } from "../../converters.ts"
|
|
8
|
-
import { guardedPageReload } from "../../errorHandling.ts"
|
|
9
|
-
import { loginWithAuth0 } from "../../LoginWithAuth0.ts"
|
|
10
|
-
|
|
11
|
-
import { isLocalhostDev } from "../../context.ts"
|
|
12
|
-
import { MockNovaInstance } from "../../mock/MockNovaInstance.ts"
|
|
13
|
-
import { NovaCellAPIClient } from "./NovaCellAPIClient.ts"
|
|
14
|
-
|
|
15
|
-
/** @deprecated Use `NovaClientConfig` from `Nova` instead. */
|
|
16
|
-
export type NovaClientConfig = {
|
|
17
|
-
/**
|
|
18
|
-
* Url of the deployed Nova instance to connect to
|
|
19
|
-
* e.g. https://saeattii.instance.wandelbots.io
|
|
20
|
-
*/
|
|
21
|
-
instanceUrl: string | "https://mock.example.com"
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Identifier of the cell on the Nova instance to connect this client to.
|
|
25
|
-
* If omitted, the default identifier "cell" is used.
|
|
26
|
-
**/
|
|
27
|
-
cellId?: string
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Username for basic auth to the Nova instance.
|
|
31
|
-
* @deprecated use accessToken instead
|
|
32
|
-
*/
|
|
33
|
-
username?: string
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Password for basic auth to the Nova instance.
|
|
37
|
-
* @deprecated use accessToken instead
|
|
38
|
-
*/
|
|
39
|
-
password?: string
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Access token for Bearer authentication.
|
|
43
|
-
*/
|
|
44
|
-
accessToken?: string
|
|
45
|
-
} & Omit<BaseConfiguration, "isJsonMime" | "basePath">
|
|
46
|
-
|
|
47
|
-
type NovaClientConfigWithDefaults = NovaClientConfig & { cellId: string }
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Client for connecting to a Nova instance and controlling robots.
|
|
51
|
-
* @deprecated Use `Nova` from `@wandelbots/nova-js/v2` instead.
|
|
52
|
-
*/
|
|
53
|
-
export class NovaClient {
|
|
54
|
-
readonly api: NovaCellAPIClient
|
|
55
|
-
readonly config: NovaClientConfigWithDefaults
|
|
56
|
-
readonly mock?: MockNovaInstance
|
|
57
|
-
readonly instanceUrl: URL
|
|
58
|
-
authPromise: Promise<string | null> | null = null
|
|
59
|
-
accessToken: string | null = null
|
|
60
|
-
|
|
61
|
-
constructor(config: NovaClientConfig) {
|
|
62
|
-
const cellId = config.cellId ?? "cell"
|
|
63
|
-
this.config = {
|
|
64
|
-
cellId,
|
|
65
|
-
...config,
|
|
66
|
-
}
|
|
67
|
-
this.accessToken =
|
|
68
|
-
config.accessToken ||
|
|
69
|
-
availableStorage.getString("wbjs.access_token") ||
|
|
70
|
-
null
|
|
71
|
-
|
|
72
|
-
if (this.config.instanceUrl === "https://mock.example.com") {
|
|
73
|
-
this.mock = new MockNovaInstance()
|
|
74
|
-
}
|
|
75
|
-
this.instanceUrl = parseNovaInstanceUrl(this.config.instanceUrl)
|
|
76
|
-
|
|
77
|
-
// Set up Axios instance with interceptor for token fetching
|
|
78
|
-
const axiosInstance = axios.create({
|
|
79
|
-
baseURL: new URL("/api/v2", this.instanceUrl).href,
|
|
80
|
-
// TODO - backend needs to set proper CORS headers for this
|
|
81
|
-
headers: isLocalhostDev
|
|
82
|
-
? {}
|
|
83
|
-
: {
|
|
84
|
-
// Identify the client to the backend for logging purposes
|
|
85
|
-
"X-Wandelbots-Client": "Wandelbots-Nova-JS-SDK",
|
|
86
|
-
},
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
axiosInstance.interceptors.request.use(async (request) => {
|
|
90
|
-
if (!request.headers.Authorization) {
|
|
91
|
-
if (this.accessToken) {
|
|
92
|
-
request.headers.Authorization = `Bearer ${this.accessToken}`
|
|
93
|
-
} else if (this.config.username && this.config.password) {
|
|
94
|
-
request.headers.Authorization = `Basic ${btoa(`${config.username}:${config.password}`)}`
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return request
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
if (typeof window !== "undefined") {
|
|
101
|
-
axiosInstance.interceptors.response.use(
|
|
102
|
-
(r) => r,
|
|
103
|
-
async (error) => {
|
|
104
|
-
if (isAxiosError(error)) {
|
|
105
|
-
if (error.response?.status === 401) {
|
|
106
|
-
// If we hit a 401, attempt to login the user and retry with
|
|
107
|
-
// a new access token
|
|
108
|
-
try {
|
|
109
|
-
await this.renewAuthentication()
|
|
110
|
-
|
|
111
|
-
if (error.config) {
|
|
112
|
-
if (this.accessToken) {
|
|
113
|
-
error.config.headers.Authorization = `Bearer ${this.accessToken}`
|
|
114
|
-
} else {
|
|
115
|
-
delete error.config.headers.Authorization
|
|
116
|
-
}
|
|
117
|
-
return axiosInstance.request(error.config)
|
|
118
|
-
}
|
|
119
|
-
} catch (err) {
|
|
120
|
-
return Promise.reject(err)
|
|
121
|
-
}
|
|
122
|
-
} else if (error.response?.status === 503) {
|
|
123
|
-
// Check if the server as a whole is down
|
|
124
|
-
const res = await fetch(window.location.href)
|
|
125
|
-
if (res.status === 503) {
|
|
126
|
-
// Go to 503 page
|
|
127
|
-
return guardedPageReload("503_server_unavailable")
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return Promise.reject(error)
|
|
133
|
-
},
|
|
134
|
-
)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
this.api = new NovaCellAPIClient(cellId, {
|
|
138
|
-
...config,
|
|
139
|
-
basePath: new URL("/api/v2", this.instanceUrl).href,
|
|
140
|
-
isJsonMime: (mime: string) => {
|
|
141
|
-
return mime === "application/json"
|
|
142
|
-
},
|
|
143
|
-
baseOptions: {
|
|
144
|
-
...(this.mock
|
|
145
|
-
? ({
|
|
146
|
-
adapter: (config) => {
|
|
147
|
-
return this.mock!.handleAPIRequest(config)
|
|
148
|
-
},
|
|
149
|
-
} satisfies AxiosRequestConfig)
|
|
150
|
-
: {}),
|
|
151
|
-
...config.baseOptions,
|
|
152
|
-
},
|
|
153
|
-
axiosInstance,
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async renewAuthentication(): Promise<void> {
|
|
158
|
-
if (this.authPromise) {
|
|
159
|
-
// Don't double up
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const storedToken = availableStorage.getString("wbjs.access_token")
|
|
164
|
-
if (storedToken && this.accessToken !== storedToken) {
|
|
165
|
-
// Might be newer than the one we have
|
|
166
|
-
this.accessToken = storedToken
|
|
167
|
-
return
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Otherwise, perform login flow
|
|
171
|
-
this.authPromise = loginWithAuth0(this.instanceUrl)
|
|
172
|
-
try {
|
|
173
|
-
this.accessToken = await this.authPromise
|
|
174
|
-
if (this.accessToken) {
|
|
175
|
-
// Cache access token so we don't need to log in every refresh
|
|
176
|
-
availableStorage.setString("wbjs.access_token", this.accessToken)
|
|
177
|
-
} else {
|
|
178
|
-
availableStorage.delete("wbjs.access_token")
|
|
179
|
-
}
|
|
180
|
-
} finally {
|
|
181
|
-
this.authPromise = null
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
makeWebsocketURL(path: string): string {
|
|
186
|
-
const url = new URL(
|
|
187
|
-
new URL(
|
|
188
|
-
`/api/v2/cells/${this.config.cellId}/${path.replace(/^\/+/, "")}`,
|
|
189
|
-
this.instanceUrl,
|
|
190
|
-
).href,
|
|
191
|
-
)
|
|
192
|
-
url.protocol = url.protocol.replace("http", "ws")
|
|
193
|
-
url.protocol = url.protocol.replace("https", "wss")
|
|
194
|
-
|
|
195
|
-
// If provided, add basic auth credentials to the URL
|
|
196
|
-
// NOTE - basic auth is deprecated on websockets and doesn't work in Safari
|
|
197
|
-
// use tokens instead
|
|
198
|
-
if (this.accessToken) {
|
|
199
|
-
url.searchParams.append("token", this.accessToken)
|
|
200
|
-
} else if (this.config.username && this.config.password) {
|
|
201
|
-
url.username = this.config.username
|
|
202
|
-
url.password = this.config.password
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return url.toString()
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Retrieve an AutoReconnectingWebsocket to the given path on the Nova instance.
|
|
210
|
-
* If you explicitly want to reconnect an existing websocket, call `reconnect`
|
|
211
|
-
* on the returned object.
|
|
212
|
-
*/
|
|
213
|
-
openReconnectingWebsocket(path: string) {
|
|
214
|
-
return new AutoReconnectingWebsocket(this.makeWebsocketURL(path), {
|
|
215
|
-
mock: this.mock,
|
|
216
|
-
})
|
|
217
|
-
}
|
|
218
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Pose } from "@wandelbots/nova-api/v2"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Convert a Pose object representing a motion group position
|
|
5
|
-
* into a string which represents that pose in Wandelscript.
|
|
6
|
-
* @deprecated Wandelscript usage is deprecated; switching to Python is recommended.
|
|
7
|
-
*/
|
|
8
|
-
export function poseToWandelscriptString(
|
|
9
|
-
pose: Pick<Pose, "position" | "orientation">,
|
|
10
|
-
) {
|
|
11
|
-
const position = [
|
|
12
|
-
pose.position?.[0] ?? 0,
|
|
13
|
-
pose.position?.[1] ?? 0,
|
|
14
|
-
pose.position?.[2] ?? 0,
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
const orientation = [
|
|
18
|
-
pose.orientation?.[0] ?? 0,
|
|
19
|
-
pose.orientation?.[1] ?? 0,
|
|
20
|
-
pose.orientation?.[2] ?? 0,
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
const positionValues = position.map((v) => v.toFixed(1))
|
|
24
|
-
// Rotation needs more precision since it's in radians
|
|
25
|
-
const rotationValues = orientation.map((v) => v.toFixed(4))
|
|
26
|
-
|
|
27
|
-
return `(${positionValues.concat(rotationValues).join(", ")})`
|
|
28
|
-
}
|
package/src/v1/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview
|
|
3
|
-
* @deprecated The NOVA v1 client is deprecated. Please use the v2 client from `@wandelbots/nova-js/v2` instead.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export * from "@wandelbots/nova-api/v1"
|
|
7
|
-
export * from "../lib/deprecated/v1/ConnectedMotionGroup.ts"
|
|
8
|
-
export * from "../lib/deprecated/v1/getLatestTrajectories.ts"
|
|
9
|
-
export * from "../lib/deprecated/v1/JoggerConnection.ts"
|
|
10
|
-
export * from "../lib/deprecated/v1/MotionStreamConnection.ts"
|
|
11
|
-
export * from "../lib/deprecated/v1/NovaCellAPIClient.ts"
|
|
12
|
-
export * from "../lib/deprecated/v1/NovaClient.ts"
|
|
13
|
-
export * from "../lib/deprecated/v1/ProgramStateConnection.ts"
|
|
14
|
-
export * from "../lib/deprecated/v1/wandelscriptUtils.ts"
|