@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.
- package/dist/index.browser.cjs +15 -9
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +19 -1
- package/dist/index.browser.d.ts +19 -1
- package/dist/index.browser.js +15 -9
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +16 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +16 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data/live.ts +32 -7
- package/src/types.ts +9 -0
- package/umd/sanityClient.js +15 -9
- package/umd/sanityClient.min.js +1 -1
package/dist/index.browser.d.cts
CHANGED
|
@@ -919,10 +919,17 @@ export declare class LiveClient {
|
|
|
919
919
|
*/
|
|
920
920
|
events({
|
|
921
921
|
includeDrafts,
|
|
922
|
+
tag: _tag,
|
|
922
923
|
}?: {
|
|
923
924
|
/** @alpha this API is experimental and may change or even be removed */
|
|
924
925
|
includeDrafts?: boolean
|
|
925
|
-
|
|
926
|
+
/**
|
|
927
|
+
* Optional request tag for the listener. Use to identify the request in logs.
|
|
928
|
+
*
|
|
929
|
+
* @defaultValue `undefined`
|
|
930
|
+
*/
|
|
931
|
+
tag?: string
|
|
932
|
+
}): Observable<LiveEventMessage | LiveEventRestart | LiveEventReconnect | LiveEventWelcome>
|
|
926
933
|
}
|
|
927
934
|
|
|
928
935
|
/** @public */
|
|
@@ -932,9 +939,20 @@ export declare interface LiveEventMessage {
|
|
|
932
939
|
tags: SyncTag[]
|
|
933
940
|
}
|
|
934
941
|
|
|
942
|
+
/** @public */
|
|
943
|
+
export declare interface LiveEventReconnect {
|
|
944
|
+
type: 'reconnect'
|
|
945
|
+
}
|
|
946
|
+
|
|
935
947
|
/** @public */
|
|
936
948
|
export declare interface LiveEventRestart {
|
|
937
949
|
type: 'restart'
|
|
950
|
+
id: string
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
/** @public */
|
|
954
|
+
export declare interface LiveEventWelcome {
|
|
955
|
+
type: 'welcome'
|
|
938
956
|
}
|
|
939
957
|
|
|
940
958
|
/** @public */
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -919,10 +919,17 @@ export declare class LiveClient {
|
|
|
919
919
|
*/
|
|
920
920
|
events({
|
|
921
921
|
includeDrafts,
|
|
922
|
+
tag: _tag,
|
|
922
923
|
}?: {
|
|
923
924
|
/** @alpha this API is experimental and may change or even be removed */
|
|
924
925
|
includeDrafts?: boolean
|
|
925
|
-
|
|
926
|
+
/**
|
|
927
|
+
* Optional request tag for the listener. Use to identify the request in logs.
|
|
928
|
+
*
|
|
929
|
+
* @defaultValue `undefined`
|
|
930
|
+
*/
|
|
931
|
+
tag?: string
|
|
932
|
+
}): Observable<LiveEventMessage | LiveEventRestart | LiveEventReconnect | LiveEventWelcome>
|
|
926
933
|
}
|
|
927
934
|
|
|
928
935
|
/** @public */
|
|
@@ -932,9 +939,20 @@ export declare interface LiveEventMessage {
|
|
|
932
939
|
tags: SyncTag[]
|
|
933
940
|
}
|
|
934
941
|
|
|
942
|
+
/** @public */
|
|
943
|
+
export declare interface LiveEventReconnect {
|
|
944
|
+
type: 'reconnect'
|
|
945
|
+
}
|
|
946
|
+
|
|
935
947
|
/** @public */
|
|
936
948
|
export declare interface LiveEventRestart {
|
|
937
949
|
type: 'restart'
|
|
950
|
+
id: string
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
/** @public */
|
|
954
|
+
export declare interface LiveEventWelcome {
|
|
955
|
+
type: 'welcome'
|
|
938
956
|
}
|
|
939
957
|
|
|
940
958
|
/** @public */
|
package/dist/index.browser.js
CHANGED
|
@@ -927,27 +927,33 @@ class LiveClient {
|
|
|
927
927
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
928
928
|
*/
|
|
929
929
|
events({
|
|
930
|
-
includeDrafts = !1
|
|
930
|
+
includeDrafts = !1,
|
|
931
|
+
tag: _tag
|
|
931
932
|
} = {}) {
|
|
932
|
-
const {
|
|
933
|
+
const {
|
|
934
|
+
apiVersion: _apiVersion,
|
|
935
|
+
token,
|
|
936
|
+
withCredentials,
|
|
937
|
+
requestTagPrefix
|
|
938
|
+
} = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
933
939
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
934
940
|
throw new Error(
|
|
935
941
|
`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
942
|
);
|
|
937
|
-
if (includeDrafts && !token)
|
|
943
|
+
if (includeDrafts && !token && !withCredentials)
|
|
938
944
|
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."
|
|
945
|
+
"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
946
|
);
|
|
941
947
|
if (includeDrafts && apiVersion !== "X")
|
|
942
948
|
throw new Error(
|
|
943
949
|
"The live events API requires API version X when 'includeDrafts: true'. This API is experimental and may change or even be removed."
|
|
944
950
|
);
|
|
945
|
-
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1));
|
|
946
|
-
includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
947
|
-
const listenFor = ["restart", "message"], esOptions = {};
|
|
951
|
+
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
|
|
952
|
+
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
953
|
+
const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {};
|
|
948
954
|
return includeDrafts && token && (esOptions.headers = {
|
|
949
955
|
Authorization: `Bearer ${token}`
|
|
950
|
-
}), new Observable((observer) => {
|
|
956
|
+
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new Observable((observer) => {
|
|
951
957
|
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
952
958
|
open();
|
|
953
959
|
function onError(evt) {
|
|
@@ -972,7 +978,7 @@ class LiveClient {
|
|
|
972
978
|
}
|
|
973
979
|
}
|
|
974
980
|
async function getEventSource() {
|
|
975
|
-
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
|
|
981
|
+
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
|
|
976
982
|
if (unsubscribed)
|
|
977
983
|
return;
|
|
978
984
|
const evs = new EventSourceImplementation(url.toString(), esOptions);
|