@sanity/client 6.22.1 → 6.22.2-canary.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.
@@ -947,14 +947,14 @@ class LiveClient {
947
947
  events({
948
948
  includeDrafts = !1
949
949
  } = {}) {
950
- const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
950
+ const { apiVersion: _apiVersion, token, withCredentials } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
951
951
  if (apiVersion !== "X" && apiVersion < requiredApiVersion)
952
952
  throw new Error(
953
953
  `The live events API requires API version ${requiredApiVersion} or later. The current API version is ${apiVersion}. Please update your API version to use this feature.`
954
954
  );
955
- if (includeDrafts && !token)
955
+ if (includeDrafts && !token && !withCredentials)
956
956
  throw new Error(
957
- "The live events API requires a token when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role."
957
+ "The live events API requires a token or withCredentials when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role."
958
958
  );
959
959
  if (includeDrafts && apiVersion !== "X")
960
960
  throw new Error(
@@ -962,10 +962,10 @@ class LiveClient {
962
962
  );
963
963
  const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1));
964
964
  includeDrafts && url.searchParams.set("includeDrafts", "true");
965
- const listenFor = ["restart", "message"], esOptions = {};
965
+ const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {};
966
966
  return includeDrafts && token && (esOptions.headers = {
967
967
  Authorization: `Bearer ${token}`
968
- }), new rxjs.Observable((observer) => {
968
+ }), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new rxjs.Observable((observer) => {
969
969
  let es, reconnectTimer, stopped = !1, unsubscribed = !1;
970
970
  open();
971
971
  function onError(evt) {
@@ -990,7 +990,7 @@ class LiveClient {
990
990
  }
991
991
  }
992
992
  async function getEventSource() {
993
- const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
993
+ const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
994
994
  if (unsubscribed)
995
995
  return;
996
996
  const evs = new EventSourceImplementation(url.toString(), esOptions);