@sanity/client 6.22.1 → 6.22.2-bundle-perspective
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 +24 -10
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +25 -1
- package/dist/index.browser.d.ts +25 -1
- package/dist/index.browser.js +24 -10
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +25 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +25 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +10 -0
- package/src/data/dataMethods.ts +8 -1
- package/src/data/live.ts +32 -7
- package/src/types.ts +15 -0
- package/umd/sanityClient.js +24 -10
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.cjs
CHANGED
|
@@ -535,6 +535,11 @@ const validateApiPerspective = function(perspective) {
|
|
|
535
535
|
"Invalid API perspective string, expected `published`, `previewDrafts` or `raw`"
|
|
536
536
|
);
|
|
537
537
|
}
|
|
538
|
+
}, validateApiBundlePerspective = function(perspective, bundlePerspective) {
|
|
539
|
+
if (perspective !== "raw" && bundlePerspective)
|
|
540
|
+
throw new TypeError(
|
|
541
|
+
"Invalid, perspective and bundlePerspective parameters are mutually exclusive"
|
|
542
|
+
);
|
|
538
543
|
}, initConfig = (config, prevConfig) => {
|
|
539
544
|
const specifiedConfig = {
|
|
540
545
|
...prevConfig,
|
|
@@ -715,6 +720,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
715
720
|
tag,
|
|
716
721
|
returnQuery,
|
|
717
722
|
perspective: options.perspective,
|
|
723
|
+
bundlePerspective: options.bundlePerspective,
|
|
718
724
|
resultSourceMap: options.resultSourceMap,
|
|
719
725
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
720
726
|
canUseCdn: isQuery,
|
|
@@ -753,7 +759,9 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
753
759
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
754
760
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
755
761
|
const perspective = options.perspective || config.perspective;
|
|
756
|
-
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()))
|
|
762
|
+
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
|
|
763
|
+
const bundlePerspective = options.bundlePerspective || config.bundlePerspective;
|
|
764
|
+
Array.isArray(bundlePerspective) && bundlePerspective.length > 0 && (validateApiBundlePerspective(perspective, bundlePerspective), options.query = { perspective: void 0, bundlePerspective, ...options.query }), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
|
|
757
765
|
}
|
|
758
766
|
const reqOptions = requestOptions(
|
|
759
767
|
config,
|
|
@@ -945,27 +953,33 @@ class LiveClient {
|
|
|
945
953
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
946
954
|
*/
|
|
947
955
|
events({
|
|
948
|
-
includeDrafts = !1
|
|
956
|
+
includeDrafts = !1,
|
|
957
|
+
tag: _tag
|
|
949
958
|
} = {}) {
|
|
950
|
-
const {
|
|
959
|
+
const {
|
|
960
|
+
apiVersion: _apiVersion,
|
|
961
|
+
token,
|
|
962
|
+
withCredentials,
|
|
963
|
+
requestTagPrefix
|
|
964
|
+
} = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
951
965
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
952
966
|
throw new Error(
|
|
953
967
|
`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.`
|
|
954
968
|
);
|
|
955
|
-
if (includeDrafts && !token)
|
|
969
|
+
if (includeDrafts && !token && !withCredentials)
|
|
956
970
|
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."
|
|
971
|
+
"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."
|
|
958
972
|
);
|
|
959
973
|
if (includeDrafts && apiVersion !== "X")
|
|
960
974
|
throw new Error(
|
|
961
975
|
"The live events API requires API version X when 'includeDrafts: true'. This API is experimental and may change or even be removed."
|
|
962
976
|
);
|
|
963
|
-
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1));
|
|
964
|
-
includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
965
|
-
const listenFor = ["restart", "message"], esOptions = {};
|
|
977
|
+
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
|
|
978
|
+
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
979
|
+
const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {};
|
|
966
980
|
return includeDrafts && token && (esOptions.headers = {
|
|
967
981
|
Authorization: `Bearer ${token}`
|
|
968
|
-
}), new rxjs.Observable((observer) => {
|
|
982
|
+
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new rxjs.Observable((observer) => {
|
|
969
983
|
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
970
984
|
open();
|
|
971
985
|
function onError(evt) {
|
|
@@ -990,7 +1004,7 @@ class LiveClient {
|
|
|
990
1004
|
}
|
|
991
1005
|
}
|
|
992
1006
|
async function getEventSource() {
|
|
993
|
-
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
|
|
1007
|
+
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
|
|
994
1008
|
if (unsubscribed)
|
|
995
1009
|
return;
|
|
996
1010
|
const evs = new EventSourceImplementation(url.toString(), esOptions);
|