@sanity/client 6.22.4 → 6.22.5-beta.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.js CHANGED
@@ -100,8 +100,7 @@ function defineHttpRequest(envMiddleware) {
100
100
  ]);
101
101
  }
102
102
  function shouldRetry(err, attempt, options) {
103
- if (options.maxRetries === 0)
104
- return !1;
103
+ if (options.maxRetries === 0) return !1;
105
104
  const isSafe = options.method === "GET" || options.method === "HEAD", isQuery = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
106
105
  return (isSafe || isQuery) && isRetriableResponse ? !0 : retry.shouldRetry(err, attempt, options);
107
106
  }
@@ -868,10 +867,13 @@ function _listen(query, params, opts = {}) {
868
867
  const { url, token, withCredentials, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = { ...defaults(opts, defaultOptions), tag }, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } }), uri = `${url}${_getDataUrl(this, "listen", qs)}`;
869
868
  if (uri.length > MAX_URL_LENGTH)
870
869
  return new Observable((observer) => observer.error(new Error("Query too large for listener")));
871
- const listenFor = options.events ? options.events : ["mutation"], shouldEmitReconnect = listenFor.indexOf("reconnect") !== -1, esOptions = {};
872
- return (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.headers = {
873
- Authorization: `Bearer ${token}`
874
- }), new Observable((observer) => {
870
+ const listenFor = options.events ? options.events : ["mutation"], shouldEmitReconnect = listenFor.indexOf("reconnect") !== -1;
871
+ return new Observable((observer) => {
872
+ const esOptions = {};
873
+ (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.fetch = (esUrl, esInit) => globalThis.fetch(esUrl, {
874
+ ...esInit,
875
+ headers: { ...esInit?.headers, Authorization: `Bearer ${token}` }
876
+ }));
875
877
  let es, reconnectTimer, stopped = !1, unsubscribed = !1;
876
878
  open();
877
879
  function onError() {
@@ -894,7 +896,7 @@ function _listen(query, params, opts = {}) {
894
896
  shouldEmitReconnect && observer.next({ type: "reconnect" });
895
897
  }
896
898
  async function getEventSource() {
897
- const { default: EventSource2 } = await import("@sanity/eventsource");
899
+ const { EventSource: EventSource2 } = await import("eventsource");
898
900
  if (unsubscribed)
899
901
  return;
900
902
  const evs = new EventSource2(uri, esOptions);
@@ -992,7 +994,7 @@ class LiveClient {
992
994
  }
993
995
  }
994
996
  async function getEventSource() {
995
- const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
997
+ const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("eventsource")).EventSource : EventSource;
996
998
  if (unsubscribed)
997
999
  return;
998
1000
  try {
@@ -1550,7 +1552,7 @@ function defineDeprecatedCreateClient(createClient2) {
1550
1552
  return printNoDefaultExport(), createClient2(config);
1551
1553
  };
1552
1554
  }
1553
- var name = "@sanity/client", version = "6.22.4";
1555
+ var name = "@sanity/client", version = "6.22.5-beta.1";
1554
1556
  const middleware = [
1555
1557
  debug({ verbose: !0, namespace: "sanity:client" }),
1556
1558
  headers({ "User-Agent": `${name} ${version}` }),