@sanity/client 7.23.0 → 7.23.1

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/index.cjs CHANGED
@@ -235,6 +235,17 @@ function shouldRetry(err, attempt, options) {
235
235
  const EXPERIMENTAL_API_WARNING = "This is an experimental API version";
236
236
  class ConnectionFailedError extends Error {
237
237
  name = "ConnectionFailedError";
238
+ /**
239
+ * HTTP status code of the rejected connection attempt, if known.
240
+ * Only set when the EventSource implementation exposes it — the polyfill used in
241
+ * Node.js and when custom headers (eg authorization) are required does, while
242
+ * native EventSource implementations (browser and Node.js) do not.
243
+ */
244
+ status;
245
+ constructor(message, options = {}) {
246
+ const { status, ...errorOptions } = options;
247
+ super(message, errorOptions), this.status = status;
248
+ }
238
249
  }
239
250
  class DisconnectError extends Error {
240
251
  name = "DisconnectError";
@@ -278,6 +289,11 @@ function connectWithESInstance(es, events) {
278
289
  );
279
290
  return;
280
291
  }
292
+ const rawStatus = evt.status, status = typeof rawStatus == "number" ? rawStatus : void 0;
293
+ if (status !== void 0) {
294
+ observer.error(new ConnectionFailedError("EventSource connection failed", { status }));
295
+ return;
296
+ }
281
297
  es.readyState === es.CLOSED ? observer.error(new ConnectionFailedError("EventSource connection failed")) : emitReconnect && observer.next({ type: "reconnect" });
282
298
  }
283
299
  function onOpen() {
@@ -1249,11 +1265,11 @@ var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj
1249
1265
  const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = rxjs.defer(() => import("@sanity/eventsource")).pipe(
1250
1266
  operators.map(({ default: EventSource2 }) => EventSource2),
1251
1267
  rxjs.shareReplay(1)
1252
- );
1268
+ ), RETRYABLE_STATUSES = /* @__PURE__ */ new Set([408, 429]);
1253
1269
  function reconnectOnConnectionFailure() {
1254
1270
  return function(source) {
1255
1271
  return source.pipe(
1256
- rxjs.catchError((err, caught) => err instanceof ConnectionFailedError ? rxjs.concat(rxjs.of({ type: "reconnect" }), rxjs.timer(1e3).pipe(rxjs.mergeMap(() => caught))) : rxjs.throwError(() => err))
1272
+ rxjs.catchError((err, caught) => err instanceof ConnectionFailedError && (typeof err.status != "number" || err.status < 400 || err.status >= 500 || RETRYABLE_STATUSES.has(err.status)) ? rxjs.concat(rxjs.of({ type: "reconnect" }), rxjs.timer(1e3).pipe(rxjs.mergeMap(() => caught))) : rxjs.throwError(() => err))
1257
1273
  );
1258
1274
  };
1259
1275
  }
@@ -2852,7 +2868,7 @@ function defineDeprecatedCreateClient(createClient2) {
2852
2868
  return config.printNoDefaultExport(), createClient2(config$1);
2853
2869
  };
2854
2870
  }
2855
- var name = "@sanity/client", version = "7.23.0";
2871
+ var name = "@sanity/client", version = "7.23.1";
2856
2872
  const middleware = [
2857
2873
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
2858
2874
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),