@bikefinder/sdk 0.23.0 → 0.28.0
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/README.md +37 -9
- package/dist/chunk-2FP3HQAZ.js +903 -0
- package/dist/index.d.ts +68380 -16501
- package/dist/index.js +25 -12
- package/dist/schemas.d.ts +68700 -16739
- package/dist/schemas.js +9 -3
- package/package.json +3 -3
- package/dist/chunk-HTKUP56M.js +0 -786
package/dist/index.js
CHANGED
|
@@ -2,14 +2,15 @@ import {
|
|
|
2
2
|
account,
|
|
3
3
|
accountPreferencePatch,
|
|
4
4
|
accountPreferences,
|
|
5
|
+
apiContractVersion,
|
|
5
6
|
batteryObservation,
|
|
6
7
|
bikeChanges,
|
|
7
8
|
bikeEditInput,
|
|
8
9
|
bluetoothContract,
|
|
9
10
|
bluetoothCredentials,
|
|
10
11
|
bluetoothPin,
|
|
11
|
-
bluetoothPinChange,
|
|
12
12
|
customerContract,
|
|
13
|
+
defaultAccountPreferences,
|
|
13
14
|
directoryProfile,
|
|
14
15
|
downloadReference,
|
|
15
16
|
factoryResetReport,
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
historyInput,
|
|
28
29
|
historyPage,
|
|
29
30
|
inboxContract,
|
|
31
|
+
inboxCursor,
|
|
30
32
|
inboxPage,
|
|
31
33
|
inboxPageInput,
|
|
32
34
|
invitationInput,
|
|
@@ -56,6 +58,7 @@ import {
|
|
|
56
58
|
subscriptionAllocationContract,
|
|
57
59
|
subscriptionAllocationInput,
|
|
58
60
|
subscriptionContract,
|
|
61
|
+
subscriptionInput,
|
|
59
62
|
subscriptionPage,
|
|
60
63
|
theftContract,
|
|
61
64
|
theftSubmission,
|
|
@@ -73,9 +76,9 @@ import {
|
|
|
73
76
|
trackerMemberInput,
|
|
74
77
|
trackerMovementAlertsInput,
|
|
75
78
|
trackerPhotoContract
|
|
76
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-2FP3HQAZ.js";
|
|
77
80
|
|
|
78
|
-
// ../../src/
|
|
81
|
+
// ../../src/client/client.ts
|
|
79
82
|
import { createORPCClient, DynamicLink } from "@orpc/client";
|
|
80
83
|
import { RPCLink as HttpLink } from "@orpc/client/fetch";
|
|
81
84
|
import { RPCLink as WebSocketLink } from "@orpc/client/websocket";
|
|
@@ -106,6 +109,7 @@ function createApiClient(contract, audience, options) {
|
|
|
106
109
|
const base = endpoint(options.baseUrl, "http");
|
|
107
110
|
base.pathname = `${base.pathname.replace(/\/+$/, "")}/rpc`;
|
|
108
111
|
const lifetime = new AbortController();
|
|
112
|
+
let disposed = false;
|
|
109
113
|
const root = { [audience]: contract };
|
|
110
114
|
function linkOptions() {
|
|
111
115
|
return {
|
|
@@ -146,12 +150,13 @@ function createApiClient(contract, audience, options) {
|
|
|
146
150
|
function websocket() {
|
|
147
151
|
if (realtime) return realtime;
|
|
148
152
|
options.onConnectionStateChange?.("connecting");
|
|
153
|
+
lifetime.signal.throwIfAborted();
|
|
149
154
|
let opened = false;
|
|
150
155
|
socket = new ReconnectingWebSocket(
|
|
151
156
|
async () => {
|
|
152
157
|
ticketError = void 0;
|
|
153
158
|
const result = await tickets.ticket().catch((error) => {
|
|
154
|
-
if (error instanceof Error) {
|
|
159
|
+
if (error instanceof Error && !disposed) {
|
|
155
160
|
ticketError = error;
|
|
156
161
|
options.onConnectionError?.(error);
|
|
157
162
|
}
|
|
@@ -167,14 +172,13 @@ function createApiClient(contract, audience, options) {
|
|
|
167
172
|
);
|
|
168
173
|
const connection = socket;
|
|
169
174
|
connection.addEventListener("open", () => {
|
|
175
|
+
if (disposed) return;
|
|
170
176
|
options.onConnectionStateChange?.("connected");
|
|
171
|
-
if (opened) options.onReconnect?.();
|
|
177
|
+
if (opened && !disposed) options.onReconnect?.();
|
|
172
178
|
opened = true;
|
|
173
179
|
});
|
|
174
180
|
connection.addEventListener("close", () => {
|
|
175
|
-
options.onConnectionStateChange?.(
|
|
176
|
-
lifetime.signal.aborted ? "closed" : "reconnecting"
|
|
177
|
-
);
|
|
181
|
+
if (!disposed) options.onConnectionStateChange?.("reconnecting");
|
|
178
182
|
});
|
|
179
183
|
connection.addEventListener("message", (event) => {
|
|
180
184
|
let decoded;
|
|
@@ -228,6 +232,8 @@ function createApiClient(contract, audience, options) {
|
|
|
228
232
|
return {
|
|
229
233
|
api,
|
|
230
234
|
dispose() {
|
|
235
|
+
if (disposed) return;
|
|
236
|
+
disposed = true;
|
|
231
237
|
socket?.close(1e3, "Client disposed.");
|
|
232
238
|
lifetime.abort(new DOMException("Client disposed.", "AbortError"));
|
|
233
239
|
options.onConnectionStateChange?.("closed");
|
|
@@ -244,9 +250,13 @@ async function uploadPhoto(uploads, input, fetch = globalThis.fetch) {
|
|
|
244
250
|
if (input.body.size < 4 || input.body.size > 10 * 1024 * 1024 || input.body.type && input.body.type.toLowerCase() !== "image/jpeg")
|
|
245
251
|
throw new TypeError("Use an image/jpeg Blob of at most 10 MiB.");
|
|
246
252
|
const bytes = await input.body.arrayBuffer();
|
|
247
|
-
const hash = new Uint8Array(
|
|
253
|
+
const hash = new Uint8Array(
|
|
254
|
+
await (input.sha256 ? input.sha256(bytes) : crypto.subtle.digest("SHA-256", bytes))
|
|
255
|
+
);
|
|
256
|
+
if (hash.byteLength !== 32)
|
|
257
|
+
throw new TypeError("SHA-256 must return 32 digest bytes.");
|
|
248
258
|
input.signal?.throwIfAborted();
|
|
249
|
-
const operation = {
|
|
259
|
+
const operation = { deviceId: input.deviceId, requestId: input.requestId };
|
|
250
260
|
const session = await uploads.start(
|
|
251
261
|
{
|
|
252
262
|
...operation,
|
|
@@ -266,7 +276,7 @@ async function uploadPhoto(uploads, input, fetch = globalThis.fetch) {
|
|
|
266
276
|
);
|
|
267
277
|
const url = new URL(session.url);
|
|
268
278
|
if (url.protocol !== "https:" || url.username || url.password || url.hash || !url.hostname.endsWith(".s3.eu-north-1.amazonaws.com") || !decodeURIComponent(url.pathname).startsWith(
|
|
269
|
-
"/photo-uploads/" + input.
|
|
279
|
+
"/photo-uploads/" + input.deviceId + "/"
|
|
270
280
|
))
|
|
271
281
|
throw new TypeError(
|
|
272
282
|
"The photo upload session targets an unexpected storage endpoint."
|
|
@@ -314,15 +324,16 @@ export {
|
|
|
314
324
|
account,
|
|
315
325
|
accountPreferencePatch,
|
|
316
326
|
accountPreferences,
|
|
327
|
+
apiContractVersion,
|
|
317
328
|
batteryObservation,
|
|
318
329
|
bikeChanges,
|
|
319
330
|
bikeEditInput,
|
|
320
331
|
bluetoothContract,
|
|
321
332
|
bluetoothCredentials,
|
|
322
333
|
bluetoothPin,
|
|
323
|
-
bluetoothPinChange,
|
|
324
334
|
createBikeFinderClient,
|
|
325
335
|
customerContract,
|
|
336
|
+
defaultAccountPreferences,
|
|
326
337
|
directoryProfile,
|
|
327
338
|
downloadReference,
|
|
328
339
|
factoryResetReport,
|
|
@@ -340,6 +351,7 @@ export {
|
|
|
340
351
|
historyInput,
|
|
341
352
|
historyPage,
|
|
342
353
|
inboxContract,
|
|
354
|
+
inboxCursor,
|
|
343
355
|
inboxPage,
|
|
344
356
|
inboxPageInput,
|
|
345
357
|
invitationInput,
|
|
@@ -369,6 +381,7 @@ export {
|
|
|
369
381
|
subscriptionAllocationContract,
|
|
370
382
|
subscriptionAllocationInput,
|
|
371
383
|
subscriptionContract,
|
|
384
|
+
subscriptionInput,
|
|
372
385
|
subscriptionPage,
|
|
373
386
|
theftContract,
|
|
374
387
|
theftSubmission,
|