@sanity/client 6.21.3 → 6.21.4-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.
- package/dist/index.browser.cjs +14 -6
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +5 -1
- package/dist/index.browser.d.ts +5 -1
- package/dist/index.browser.js +14 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +15 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +15 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data/live.ts +22 -5
- package/umd/sanityClient.js +14 -6
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.cjs
CHANGED
|
@@ -944,14 +944,22 @@ class LiveClient {
|
|
|
944
944
|
/**
|
|
945
945
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
946
946
|
*/
|
|
947
|
-
events() {
|
|
948
|
-
const apiVersion = this.#client.config()
|
|
947
|
+
events({ includeDrafts = !1 } = {}) {
|
|
948
|
+
const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
949
949
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
950
950
|
throw new Error(
|
|
951
951
|
`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
952
|
);
|
|
953
|
-
|
|
954
|
-
|
|
953
|
+
if (includeDrafts && !token)
|
|
954
|
+
throw new Error(
|
|
955
|
+
"The live events API requires a token when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role."
|
|
956
|
+
);
|
|
957
|
+
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1));
|
|
958
|
+
includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
959
|
+
const listenFor = ["restart", "message"], esOptions = {};
|
|
960
|
+
return token && (esOptions.headers = {
|
|
961
|
+
Authorization: `Bearer ${token}`
|
|
962
|
+
}), new rxjs.Observable((observer) => {
|
|
955
963
|
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
956
964
|
open();
|
|
957
965
|
function onError(evt) {
|
|
@@ -976,10 +984,10 @@ class LiveClient {
|
|
|
976
984
|
}
|
|
977
985
|
}
|
|
978
986
|
async function getEventSource() {
|
|
979
|
-
const EventSourceImplementation = typeof EventSource > "u" ? (await import("@sanity/eventsource")).default : EventSource;
|
|
987
|
+
const EventSourceImplementation = typeof EventSource > "u" || token ? (await import("@sanity/eventsource")).default : EventSource;
|
|
980
988
|
if (unsubscribed)
|
|
981
989
|
return;
|
|
982
|
-
const evs = new EventSourceImplementation(url.toString());
|
|
990
|
+
const evs = new EventSourceImplementation(url.toString(), esOptions);
|
|
983
991
|
evs.addEventListener("error", onError);
|
|
984
992
|
for (const type of listenFor)
|
|
985
993
|
evs.addEventListener(type, onMessage);
|