@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.
@@ -922,7 +922,7 @@ export declare class LiveClient {
922
922
  }?: {
923
923
  /** @alpha this API is experimental and may change or even be removed */
924
924
  includeDrafts?: boolean
925
- }): Observable<LiveEventMessage | LiveEventRestart>
925
+ }): Observable<LiveEventMessage | LiveEventRestart | LiveEventReconnect | LiveEventWelcome>
926
926
  }
927
927
 
928
928
  /** @public */
@@ -932,9 +932,20 @@ export declare interface LiveEventMessage {
932
932
  tags: SyncTag[]
933
933
  }
934
934
 
935
+ /** @public */
936
+ export declare interface LiveEventReconnect {
937
+ type: 'reconnect'
938
+ }
939
+
935
940
  /** @public */
936
941
  export declare interface LiveEventRestart {
937
942
  type: 'restart'
943
+ id: string
944
+ }
945
+
946
+ /** @public */
947
+ export declare interface LiveEventWelcome {
948
+ type: 'welcome'
938
949
  }
939
950
 
940
951
  /** @public */
@@ -922,7 +922,7 @@ export declare class LiveClient {
922
922
  }?: {
923
923
  /** @alpha this API is experimental and may change or even be removed */
924
924
  includeDrafts?: boolean
925
- }): Observable<LiveEventMessage | LiveEventRestart>
925
+ }): Observable<LiveEventMessage | LiveEventRestart | LiveEventReconnect | LiveEventWelcome>
926
926
  }
927
927
 
928
928
  /** @public */
@@ -932,9 +932,20 @@ export declare interface LiveEventMessage {
932
932
  tags: SyncTag[]
933
933
  }
934
934
 
935
+ /** @public */
936
+ export declare interface LiveEventReconnect {
937
+ type: 'reconnect'
938
+ }
939
+
935
940
  /** @public */
936
941
  export declare interface LiveEventRestart {
937
942
  type: 'restart'
943
+ id: string
944
+ }
945
+
946
+ /** @public */
947
+ export declare interface LiveEventWelcome {
948
+ type: 'welcome'
938
949
  }
939
950
 
940
951
  /** @public */
@@ -929,14 +929,14 @@ class LiveClient {
929
929
  events({
930
930
  includeDrafts = !1
931
931
  } = {}) {
932
- const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
932
+ const { apiVersion: _apiVersion, token, withCredentials } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
933
933
  if (apiVersion !== "X" && apiVersion < requiredApiVersion)
934
934
  throw new Error(
935
935
  `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.`
936
936
  );
937
- if (includeDrafts && !token)
937
+ if (includeDrafts && !token && !withCredentials)
938
938
  throw new Error(
939
- "The live events API requires a token when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role."
939
+ "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."
940
940
  );
941
941
  if (includeDrafts && apiVersion !== "X")
942
942
  throw new Error(
@@ -944,10 +944,10 @@ class LiveClient {
944
944
  );
945
945
  const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1));
946
946
  includeDrafts && url.searchParams.set("includeDrafts", "true");
947
- const listenFor = ["restart", "message"], esOptions = {};
947
+ const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {};
948
948
  return includeDrafts && token && (esOptions.headers = {
949
949
  Authorization: `Bearer ${token}`
950
- }), new Observable((observer) => {
950
+ }), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new Observable((observer) => {
951
951
  let es, reconnectTimer, stopped = !1, unsubscribed = !1;
952
952
  open();
953
953
  function onError(evt) {
@@ -972,7 +972,7 @@ class LiveClient {
972
972
  }
973
973
  }
974
974
  async function getEventSource() {
975
- const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
975
+ const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
976
976
  if (unsubscribed)
977
977
  return;
978
978
  const evs = new EventSourceImplementation(url.toString(), esOptions);