@sanity/client 6.21.3 → 6.21.4-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 +16 -6
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +6 -1
- package/dist/index.browser.d.ts +6 -1
- package/dist/index.browser.js +16 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +17 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data/live.ts +25 -5
- package/umd/sanityClient.js +16 -6
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.d.cts
CHANGED
|
@@ -917,7 +917,12 @@ export declare class LiveClient {
|
|
|
917
917
|
/**
|
|
918
918
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
919
919
|
*/
|
|
920
|
-
events(
|
|
920
|
+
events({
|
|
921
|
+
includeDrafts,
|
|
922
|
+
}?: {
|
|
923
|
+
/** @alpha this API is experimental and may change or even be removed */
|
|
924
|
+
includeDrafts?: boolean
|
|
925
|
+
}): Observable<LiveEventMessage | LiveEventRestart>
|
|
921
926
|
}
|
|
922
927
|
|
|
923
928
|
/** @public */
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -917,7 +917,12 @@ export declare class LiveClient {
|
|
|
917
917
|
/**
|
|
918
918
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
919
919
|
*/
|
|
920
|
-
events(
|
|
920
|
+
events({
|
|
921
|
+
includeDrafts,
|
|
922
|
+
}?: {
|
|
923
|
+
/** @alpha this API is experimental and may change or even be removed */
|
|
924
|
+
includeDrafts?: boolean
|
|
925
|
+
}): Observable<LiveEventMessage | LiveEventRestart>
|
|
921
926
|
}
|
|
922
927
|
|
|
923
928
|
/** @public */
|
package/dist/index.browser.js
CHANGED
|
@@ -926,14 +926,24 @@ class LiveClient {
|
|
|
926
926
|
/**
|
|
927
927
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
928
928
|
*/
|
|
929
|
-
events(
|
|
930
|
-
|
|
929
|
+
events({
|
|
930
|
+
includeDrafts = !1
|
|
931
|
+
} = {}) {
|
|
932
|
+
const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
931
933
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
932
934
|
throw new Error(
|
|
933
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.`
|
|
934
936
|
);
|
|
935
|
-
|
|
936
|
-
|
|
937
|
+
if (includeDrafts && !token)
|
|
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."
|
|
940
|
+
);
|
|
941
|
+
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1));
|
|
942
|
+
includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
943
|
+
const listenFor = ["restart", "message"], esOptions = {};
|
|
944
|
+
return includeDrafts && token && (esOptions.headers = {
|
|
945
|
+
Authorization: `Bearer ${token}`
|
|
946
|
+
}), new Observable((observer) => {
|
|
937
947
|
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
938
948
|
open();
|
|
939
949
|
function onError(evt) {
|
|
@@ -958,10 +968,10 @@ class LiveClient {
|
|
|
958
968
|
}
|
|
959
969
|
}
|
|
960
970
|
async function getEventSource() {
|
|
961
|
-
const EventSourceImplementation = typeof EventSource > "u" ? (await import("@sanity/eventsource")).default : EventSource;
|
|
971
|
+
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
|
|
962
972
|
if (unsubscribed)
|
|
963
973
|
return;
|
|
964
|
-
const evs = new EventSourceImplementation(url.toString());
|
|
974
|
+
const evs = new EventSourceImplementation(url.toString(), esOptions);
|
|
965
975
|
evs.addEventListener("error", onError);
|
|
966
976
|
for (const type of listenFor)
|
|
967
977
|
evs.addEventListener(type, onMessage);
|