@bikefinder/sdk 0.32.0 → 0.33.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 +9 -0
- package/dist/{chunk-3EMQWFLN.js → chunk-IYM3P32E.js} +60 -11
- package/dist/index.d.ts +6533 -943
- package/dist/index.js +81 -27
- package/dist/schemas.d.ts +6466 -881
- package/dist/schemas.js +11 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -47,6 +47,10 @@ import {
|
|
|
47
47
|
photoUploadInput,
|
|
48
48
|
photoUploadSession,
|
|
49
49
|
photoUploadStartInput,
|
|
50
|
+
positionMethod,
|
|
51
|
+
positionRequest,
|
|
52
|
+
positionRequestInput,
|
|
53
|
+
positionRequestsContract,
|
|
50
54
|
pushContract,
|
|
51
55
|
pushRegistrationInput,
|
|
52
56
|
pushRemovalInput,
|
|
@@ -55,6 +59,7 @@ import {
|
|
|
55
59
|
realtimeTicket,
|
|
56
60
|
staffRealtimeFeed,
|
|
57
61
|
startFirmwareUpdate,
|
|
62
|
+
submitPositionRequestInput,
|
|
58
63
|
subscription,
|
|
59
64
|
subscriptionAllocationContract,
|
|
60
65
|
subscriptionAllocationInput,
|
|
@@ -77,10 +82,14 @@ import {
|
|
|
77
82
|
trackerMemberInput,
|
|
78
83
|
trackerMovementAlertsInput,
|
|
79
84
|
trackerPhotoContract
|
|
80
|
-
} from "./chunk-
|
|
85
|
+
} from "./chunk-IYM3P32E.js";
|
|
81
86
|
|
|
82
87
|
// ../../src/client/client.ts
|
|
83
|
-
import {
|
|
88
|
+
import {
|
|
89
|
+
createORPCClient,
|
|
90
|
+
DynamicLink,
|
|
91
|
+
ORPCError
|
|
92
|
+
} from "@orpc/client";
|
|
84
93
|
import { RPCLink as HttpLink } from "@orpc/client/fetch";
|
|
85
94
|
import { RPCLink as WebSocketLink } from "@orpc/client/websocket";
|
|
86
95
|
import {
|
|
@@ -94,7 +103,17 @@ import {
|
|
|
94
103
|
} from "@orpc/contract/plugins";
|
|
95
104
|
import ReconnectingWebSocket from "partysocket/ws";
|
|
96
105
|
import { pEvent } from "p-event";
|
|
106
|
+
import pTimeout from "p-timeout";
|
|
97
107
|
import { z } from "zod";
|
|
108
|
+
var RealtimeDisconnectedError = class extends ORPCError {
|
|
109
|
+
constructor() {
|
|
110
|
+
super("stream_unavailable", {
|
|
111
|
+
status: 503,
|
|
112
|
+
message: "The realtime socket closed. Subscribe again after reconnecting."
|
|
113
|
+
});
|
|
114
|
+
this.name = "RealtimeDisconnectedError";
|
|
115
|
+
}
|
|
116
|
+
};
|
|
98
117
|
var gatewayError = z.object({ message: z.string() });
|
|
99
118
|
function endpoint(value, transport) {
|
|
100
119
|
const url = new URL(value);
|
|
@@ -110,6 +129,7 @@ function createApiClient(contract, audience, options, createNegotiatedRealtime)
|
|
|
110
129
|
const base = endpoint(options.baseUrl, "http");
|
|
111
130
|
base.pathname = `${base.pathname.replace(/\/+$/, "")}/rpc`;
|
|
112
131
|
const lifetime = new AbortController();
|
|
132
|
+
const timeoutMs = options.realtimeConnectTimeoutMs ?? 3e4;
|
|
113
133
|
let disposed = false;
|
|
114
134
|
const root = { [audience]: contract };
|
|
115
135
|
function linkOptions() {
|
|
@@ -132,12 +152,15 @@ function createApiClient(contract, audience, options, createNegotiatedRealtime)
|
|
|
132
152
|
const http = new HttpLink({
|
|
133
153
|
...linkOptions(),
|
|
134
154
|
url: base,
|
|
135
|
-
fetch: (request, init) =>
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
155
|
+
fetch: (request, init) => {
|
|
156
|
+
request.signal.throwIfAborted();
|
|
157
|
+
return (options.fetch ?? globalThis.fetch)(request, {
|
|
158
|
+
...init,
|
|
159
|
+
credentials: "omit",
|
|
160
|
+
redirect: "error",
|
|
161
|
+
cache: "no-store"
|
|
162
|
+
});
|
|
163
|
+
},
|
|
141
164
|
async headers() {
|
|
142
165
|
const token = await options.accessToken();
|
|
143
166
|
lifetime.signal.throwIfAborted();
|
|
@@ -150,27 +173,41 @@ function createApiClient(contract, audience, options, createNegotiatedRealtime)
|
|
|
150
173
|
let ticketError;
|
|
151
174
|
let staffFeeds = [];
|
|
152
175
|
let negotiated;
|
|
176
|
+
async function ticketUrl() {
|
|
177
|
+
lifetime.signal.throwIfAborted();
|
|
178
|
+
ticketError = void 0;
|
|
179
|
+
const attempt = new AbortController();
|
|
180
|
+
try {
|
|
181
|
+
const result = await pTimeout(
|
|
182
|
+
tickets.ticket(void 0, { signal: attempt.signal }),
|
|
183
|
+
{
|
|
184
|
+
milliseconds: timeoutMs,
|
|
185
|
+
signal: lifetime.signal,
|
|
186
|
+
message: "Realtime ticket request timed out."
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
lifetime.signal.throwIfAborted();
|
|
190
|
+
const url = endpoint(result.webSocketUrl, "websocket");
|
|
191
|
+
url.searchParams.set("ticket", result.ticket);
|
|
192
|
+
staffFeeds = result.staffFeeds ?? [];
|
|
193
|
+
return url.href;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
attempt.abort(error);
|
|
196
|
+
if (error instanceof Error && !disposed) {
|
|
197
|
+
ticketError = error;
|
|
198
|
+
options.onConnectionError?.(error);
|
|
199
|
+
}
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
153
203
|
function websocket() {
|
|
154
204
|
if (realtime) return realtime;
|
|
155
205
|
options.onConnectionStateChange?.("connecting");
|
|
156
206
|
lifetime.signal.throwIfAborted();
|
|
157
207
|
let opened = false;
|
|
208
|
+
let connected = false;
|
|
158
209
|
socket = new ReconnectingWebSocket(
|
|
159
|
-
|
|
160
|
-
ticketError = void 0;
|
|
161
|
-
const result = await tickets.ticket().catch((error) => {
|
|
162
|
-
if (error instanceof Error && !disposed) {
|
|
163
|
-
ticketError = error;
|
|
164
|
-
options.onConnectionError?.(error);
|
|
165
|
-
}
|
|
166
|
-
throw error;
|
|
167
|
-
});
|
|
168
|
-
lifetime.signal.throwIfAborted();
|
|
169
|
-
staffFeeds = result.staffFeeds ?? [];
|
|
170
|
-
const url = endpoint(result.webSocketUrl, "websocket");
|
|
171
|
-
url.searchParams.set("ticket", result.ticket);
|
|
172
|
-
return url.href;
|
|
173
|
-
},
|
|
210
|
+
ticketUrl,
|
|
174
211
|
[],
|
|
175
212
|
{ maxEnqueuedMessages: 0, WebSocket: options.webSocket }
|
|
176
213
|
);
|
|
@@ -179,18 +216,27 @@ function createApiClient(contract, audience, options, createNegotiatedRealtime)
|
|
|
179
216
|
connection,
|
|
180
217
|
http,
|
|
181
218
|
lifetime.signal,
|
|
182
|
-
|
|
219
|
+
timeoutMs
|
|
183
220
|
);
|
|
184
221
|
connection.addEventListener("open", () => {
|
|
185
222
|
if (disposed) return;
|
|
223
|
+
connected = true;
|
|
186
224
|
options.onConnectionStateChange?.("connected");
|
|
187
225
|
if (opened && !disposed) options.onReconnect?.();
|
|
188
226
|
opened = true;
|
|
189
227
|
});
|
|
190
228
|
connection.addEventListener("close", () => {
|
|
191
229
|
negotiated?.disconnect();
|
|
230
|
+
if (!connected) return;
|
|
231
|
+
connected = false;
|
|
192
232
|
if (!disposed) options.onConnectionStateChange?.("reconnecting");
|
|
193
233
|
});
|
|
234
|
+
connection.addEventListener("error", () => {
|
|
235
|
+
if (!disposed && !ticketError)
|
|
236
|
+
options.onConnectionError?.(
|
|
237
|
+
new Error("Realtime WebSocket connection failed.")
|
|
238
|
+
);
|
|
239
|
+
});
|
|
194
240
|
connection.addEventListener("message", (event) => {
|
|
195
241
|
let decoded;
|
|
196
242
|
try {
|
|
@@ -226,12 +272,14 @@ function createApiClient(contract, audience, options, createNegotiatedRealtime)
|
|
|
226
272
|
await pEvent(connection, "open", {
|
|
227
273
|
rejectionEvents: ["close", "error"],
|
|
228
274
|
signal: request.signal ? AbortSignal.any([lifetime.signal, request.signal]) : lifetime.signal,
|
|
229
|
-
timeout:
|
|
275
|
+
timeout: timeoutMs
|
|
230
276
|
});
|
|
231
277
|
} catch (error) {
|
|
232
278
|
lifetime.signal.throwIfAborted();
|
|
233
279
|
request.signal?.throwIfAborted();
|
|
234
280
|
if (ticketError) throw ticketError;
|
|
281
|
+
if (error instanceof Event && error.type === "close")
|
|
282
|
+
throw new RealtimeDisconnectedError();
|
|
235
283
|
if (error && typeof error === "object" && "error" in error && error.error instanceof Error)
|
|
236
284
|
throw error.error;
|
|
237
285
|
throw error instanceof Error ? error : new Error("Realtime connection failed.", { cause: error });
|
|
@@ -258,7 +306,7 @@ function createApiClient(contract, audience, options, createNegotiatedRealtime)
|
|
|
258
306
|
}
|
|
259
307
|
|
|
260
308
|
// src/index.ts
|
|
261
|
-
import { ORPCError } from "@orpc/client";
|
|
309
|
+
import { ORPCError as ORPCError2 } from "@orpc/client";
|
|
262
310
|
|
|
263
311
|
// src/photo-upload.ts
|
|
264
312
|
async function uploadPhoto(uploads, input, fetch = globalThis.fetch) {
|
|
@@ -336,7 +384,8 @@ function createBikeFinderClient(options) {
|
|
|
336
384
|
};
|
|
337
385
|
}
|
|
338
386
|
export {
|
|
339
|
-
ORPCError,
|
|
387
|
+
ORPCError2 as ORPCError,
|
|
388
|
+
RealtimeDisconnectedError,
|
|
340
389
|
account,
|
|
341
390
|
accountPreferencePatch,
|
|
342
391
|
accountPreferences,
|
|
@@ -386,6 +435,10 @@ export {
|
|
|
386
435
|
photoUploadInput,
|
|
387
436
|
photoUploadSession,
|
|
388
437
|
photoUploadStartInput,
|
|
438
|
+
positionMethod,
|
|
439
|
+
positionRequest,
|
|
440
|
+
positionRequestInput,
|
|
441
|
+
positionRequestsContract,
|
|
389
442
|
pushContract,
|
|
390
443
|
pushRegistrationInput,
|
|
391
444
|
pushRemovalInput,
|
|
@@ -394,6 +447,7 @@ export {
|
|
|
394
447
|
realtimeTicket,
|
|
395
448
|
staffRealtimeFeed,
|
|
396
449
|
startFirmwareUpdate,
|
|
450
|
+
submitPositionRequestInput,
|
|
397
451
|
subscription,
|
|
398
452
|
subscriptionAllocationContract,
|
|
399
453
|
subscriptionAllocationInput,
|