@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.cjs
CHANGED
|
@@ -944,14 +944,24 @@ class LiveClient {
|
|
|
944
944
|
/**
|
|
945
945
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
946
946
|
*/
|
|
947
|
-
events(
|
|
948
|
-
|
|
947
|
+
events({
|
|
948
|
+
includeDrafts = !1
|
|
949
|
+
} = {}) {
|
|
950
|
+
const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
949
951
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
950
952
|
throw new Error(
|
|
951
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.`
|
|
952
954
|
);
|
|
953
|
-
|
|
954
|
-
|
|
955
|
+
if (includeDrafts && !token)
|
|
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."
|
|
958
|
+
);
|
|
959
|
+
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1));
|
|
960
|
+
includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
961
|
+
const listenFor = ["restart", "message"], esOptions = {};
|
|
962
|
+
return includeDrafts && token && (esOptions.headers = {
|
|
963
|
+
Authorization: `Bearer ${token}`
|
|
964
|
+
}), new rxjs.Observable((observer) => {
|
|
955
965
|
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
956
966
|
open();
|
|
957
967
|
function onError(evt) {
|
|
@@ -976,10 +986,10 @@ class LiveClient {
|
|
|
976
986
|
}
|
|
977
987
|
}
|
|
978
988
|
async function getEventSource() {
|
|
979
|
-
const EventSourceImplementation = typeof EventSource > "u" ? (await import("@sanity/eventsource")).default : EventSource;
|
|
989
|
+
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
|
|
980
990
|
if (unsubscribed)
|
|
981
991
|
return;
|
|
982
|
-
const evs = new EventSourceImplementation(url.toString());
|
|
992
|
+
const evs = new EventSourceImplementation(url.toString(), esOptions);
|
|
983
993
|
evs.addEventListener("error", onError);
|
|
984
994
|
for (const type of listenFor)
|
|
985
995
|
evs.addEventListener(type, onMessage);
|