@sanity/client 6.22.1 → 6.22.2-canary.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.
@@ -945,27 +945,33 @@ class LiveClient {
945
945
  * Requires `apiVersion` to be `2021-03-26` or later.
946
946
  */
947
947
  events({
948
- includeDrafts = !1
948
+ includeDrafts = !1,
949
+ tag: _tag
949
950
  } = {}) {
950
- const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
951
+ const {
952
+ apiVersion: _apiVersion,
953
+ token,
954
+ withCredentials,
955
+ requestTagPrefix
956
+ } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
951
957
  if (apiVersion !== "X" && apiVersion < requiredApiVersion)
952
958
  throw new Error(
953
959
  `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
960
  );
955
- if (includeDrafts && !token)
961
+ if (includeDrafts && !token && !withCredentials)
956
962
  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."
963
+ "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
964
  );
959
965
  if (includeDrafts && apiVersion !== "X")
960
966
  throw new Error(
961
967
  "The live events API requires API version X when 'includeDrafts: true'. This API is experimental and may change or even be removed."
962
968
  );
963
- const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1));
964
- includeDrafts && url.searchParams.set("includeDrafts", "true");
965
- const listenFor = ["restart", "message"], esOptions = {};
969
+ const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
970
+ tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
971
+ const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {};
966
972
  return includeDrafts && token && (esOptions.headers = {
967
973
  Authorization: `Bearer ${token}`
968
- }), new rxjs.Observable((observer) => {
974
+ }), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new rxjs.Observable((observer) => {
969
975
  let es, reconnectTimer, stopped = !1, unsubscribed = !1;
970
976
  open();
971
977
  function onError(evt) {
@@ -990,7 +996,7 @@ class LiveClient {
990
996
  }
991
997
  }
992
998
  async function getEventSource() {
993
- const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
999
+ const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
994
1000
  if (unsubscribed)
995
1001
  return;
996
1002
  const evs = new EventSourceImplementation(url.toString(), esOptions);