@bikefinder/sdk 0.33.1 → 0.33.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +3 -0
  2. package/dist/index.js +25 -24
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -78,6 +78,9 @@ Full reconnects end existing subscriptions. Use `onReconnect` to explicitly
78
78
  subscribe again. The SDK does not replay events or retry writes automatically.
79
79
  Each ticket attempt has its own deadline (`realtimeConnectTimeoutMs`, 30 seconds
80
80
  by default), so a stalled token provider or ticket request can time out and retry.
81
+ Pending subscriptions wait through transient connection failures within the same
82
+ connection-wait deadline. Ticket admission errors such as a denied sign-in or
83
+ rate limit are returned immediately.
81
84
  Retain the original request ID when explicitly retrying an uncertain mutation.
82
85
 
83
86
  Photo metadata supports HTTP `list` and WebSocket `watchPage`, with the same
package/dist/index.js CHANGED
@@ -170,12 +170,14 @@ function createApiClient(contract, audience, options, createNegotiatedRealtime)
170
170
  const tickets = createORPCClient(http, { path: [audience, "realtime"] });
171
171
  let socket;
172
172
  let realtime;
173
- let ticketError;
173
+ let ticketFailed = false;
174
+ let ticketRejection = new AbortController();
174
175
  let staffFeeds = [];
175
176
  let negotiated;
176
177
  async function ticketUrl() {
177
178
  lifetime.signal.throwIfAborted();
178
- ticketError = void 0;
179
+ ticketFailed = false;
180
+ let receivedTicket = false;
179
181
  const attempt = new AbortController();
180
182
  try {
181
183
  const result = await pTimeout(
@@ -187,17 +189,24 @@ function createApiClient(contract, audience, options, createNegotiatedRealtime)
187
189
  }
188
190
  );
189
191
  lifetime.signal.throwIfAborted();
192
+ receivedTicket = true;
190
193
  const url = endpoint(result.webSocketUrl, "websocket");
191
194
  url.searchParams.set("ticket", result.ticket);
192
195
  staffFeeds = result.staffFeeds ?? [];
193
196
  return url.href;
194
197
  } catch (error) {
195
- attempt.abort(error);
196
- if (error instanceof Error && !disposed) {
197
- ticketError = error;
198
- options.onConnectionError?.(error);
198
+ const failure = error instanceof Error ? error : new Error("Realtime ticket request failed.", { cause: error });
199
+ attempt.abort(failure);
200
+ ticketFailed = true;
201
+ if (!disposed) {
202
+ if (receivedTicket || failure instanceof ORPCError && failure.status >= 400 && failure.status < 500 && failure.status !== 408) {
203
+ const rejected = ticketRejection;
204
+ ticketRejection = new AbortController();
205
+ rejected.abort(failure);
206
+ }
207
+ options.onConnectionError?.(failure);
199
208
  }
200
- throw error;
209
+ throw failure;
201
210
  }
202
211
  }
203
212
  function websocket() {
@@ -232,7 +241,7 @@ function createApiClient(contract, audience, options, createNegotiatedRealtime)
232
241
  if (!disposed) options.onConnectionStateChange?.("reconnecting");
233
242
  });
234
243
  connection.addEventListener("error", () => {
235
- if (!disposed && !ticketError)
244
+ if (!disposed && !ticketFailed)
236
245
  options.onConnectionError?.(
237
246
  new Error("Realtime WebSocket connection failed.")
238
247
  );
@@ -262,28 +271,20 @@ function createApiClient(contract, audience, options, createNegotiatedRealtime)
262
271
  }
263
272
  const link = new DynamicLink(async (request, path) => {
264
273
  lifetime.signal.throwIfAborted();
274
+ request.signal?.throwIfAborted();
265
275
  const procedure = getContractRouter(root, path);
266
276
  if (!isContractProcedure(procedure) || !getEventIteratorSchemaDetails(procedure["~orpc"].outputSchema))
267
277
  return http;
268
278
  const link2 = websocket();
269
279
  const connection = socket;
270
280
  if (connection.readyState !== connection.OPEN) {
271
- try {
272
- await pEvent(connection, "open", {
273
- rejectionEvents: ["close", "error"],
274
- signal: request.signal ? AbortSignal.any([lifetime.signal, request.signal]) : lifetime.signal,
275
- timeout: timeoutMs
276
- });
277
- } catch (error) {
278
- lifetime.signal.throwIfAborted();
279
- request.signal?.throwIfAborted();
280
- if (ticketError) throw ticketError;
281
- if (error instanceof Event && error.type === "close")
282
- throw new RealtimeDisconnectedError();
283
- if (error && typeof error === "object" && "error" in error && error.error instanceof Error)
284
- throw error.error;
285
- throw error instanceof Error ? error : new Error("Realtime connection failed.", { cause: error });
286
- }
281
+ const signals = [lifetime.signal, ticketRejection.signal];
282
+ if (request.signal) signals.push(request.signal);
283
+ await pEvent(connection, "open", {
284
+ rejectionEvents: [],
285
+ signal: AbortSignal.any(signals),
286
+ timeout: timeoutMs
287
+ });
287
288
  }
288
289
  lifetime.signal.throwIfAborted();
289
290
  request.signal?.throwIfAborted();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikefinder/sdk",
3
- "version": "0.33.1",
3
+ "version": "0.33.2",
4
4
  "description": "Typed HTTP and WebSocket client for BikeFinder.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {