@sanity/client 6.22.1-bundle-perspective → 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/_chunks-cjs/resolveEditInfo.cjs +2 -1
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaClean.cjs +2 -1
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +2 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/resolveEditInfo.js +2 -1
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaClean.js +2 -1
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +2 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/csm.cjs +2 -1
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.js +2 -1
- package/dist/csm.js.map +1 -1
- package/dist/index.browser.cjs +26 -12
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +24 -5
- package/dist/index.browser.d.ts +24 -5
- package/dist/index.browser.js +26 -12
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +27 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -5
- package/dist/index.d.ts +24 -5
- package/dist/index.js +27 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +10 -0
- package/src/data/dataMethods.ts +4 -6
- package/src/data/live.ts +32 -7
- package/src/types.ts +14 -4
- package/umd/sanityClient.js +32 -17
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.d.cts
CHANGED
|
@@ -331,7 +331,8 @@ export declare interface ClientConfig {
|
|
|
331
331
|
token?: string
|
|
332
332
|
/** @defaultValue 'raw' */
|
|
333
333
|
perspective?: ClientPerspective
|
|
334
|
-
|
|
334
|
+
/** @defaultValue 'raw' */
|
|
335
|
+
bundlePerspective?: string[]
|
|
335
336
|
apiHost?: string
|
|
336
337
|
apiVersion?: string
|
|
337
338
|
proxy?: string
|
|
@@ -920,10 +921,17 @@ export declare class LiveClient {
|
|
|
920
921
|
*/
|
|
921
922
|
events({
|
|
922
923
|
includeDrafts,
|
|
924
|
+
tag: _tag,
|
|
923
925
|
}?: {
|
|
924
926
|
/** @alpha this API is experimental and may change or even be removed */
|
|
925
927
|
includeDrafts?: boolean
|
|
926
|
-
|
|
928
|
+
/**
|
|
929
|
+
* Optional request tag for the listener. Use to identify the request in logs.
|
|
930
|
+
*
|
|
931
|
+
* @defaultValue `undefined`
|
|
932
|
+
*/
|
|
933
|
+
tag?: string
|
|
934
|
+
}): Observable<LiveEventMessage | LiveEventRestart | LiveEventReconnect | LiveEventWelcome>
|
|
927
935
|
}
|
|
928
936
|
|
|
929
937
|
/** @public */
|
|
@@ -933,9 +941,20 @@ export declare interface LiveEventMessage {
|
|
|
933
941
|
tags: SyncTag[]
|
|
934
942
|
}
|
|
935
943
|
|
|
944
|
+
/** @public */
|
|
945
|
+
export declare interface LiveEventReconnect {
|
|
946
|
+
type: 'reconnect'
|
|
947
|
+
}
|
|
948
|
+
|
|
936
949
|
/** @public */
|
|
937
950
|
export declare interface LiveEventRestart {
|
|
938
951
|
type: 'restart'
|
|
952
|
+
id: string
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/** @public */
|
|
956
|
+
export declare interface LiveEventWelcome {
|
|
957
|
+
type: 'welcome'
|
|
939
958
|
}
|
|
940
959
|
|
|
941
960
|
/** @public */
|
|
@@ -2122,7 +2141,7 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
2122
2141
|
returnQuery?: boolean
|
|
2123
2142
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
2124
2143
|
perspective?: ClientPerspective
|
|
2125
|
-
bundlePerspective?: string
|
|
2144
|
+
bundlePerspective?: string[]
|
|
2126
2145
|
lastLiveEventId?: string
|
|
2127
2146
|
}
|
|
2128
2147
|
|
|
@@ -2154,7 +2173,7 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
2154
2173
|
/** @public */
|
|
2155
2174
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
2156
2175
|
perspective?: ClientPerspective
|
|
2157
|
-
bundlePerspective?: string
|
|
2176
|
+
bundlePerspective?: string[]
|
|
2158
2177
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
2159
2178
|
returnQuery?: boolean
|
|
2160
2179
|
useCdn?: boolean
|
|
@@ -2711,7 +2730,7 @@ export declare type SanityDocument<T extends Record<string, Any> = Record<string
|
|
|
2711
2730
|
_createdAt: string
|
|
2712
2731
|
_updatedAt: string
|
|
2713
2732
|
/**
|
|
2714
|
-
* Present when `perspective` is set to `previewDrafts`
|
|
2733
|
+
* Present when `perspective` is set to `previewDrafts`
|
|
2715
2734
|
*/
|
|
2716
2735
|
_originalId?: string
|
|
2717
2736
|
}
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -331,7 +331,8 @@ export declare interface ClientConfig {
|
|
|
331
331
|
token?: string
|
|
332
332
|
/** @defaultValue 'raw' */
|
|
333
333
|
perspective?: ClientPerspective
|
|
334
|
-
|
|
334
|
+
/** @defaultValue 'raw' */
|
|
335
|
+
bundlePerspective?: string[]
|
|
335
336
|
apiHost?: string
|
|
336
337
|
apiVersion?: string
|
|
337
338
|
proxy?: string
|
|
@@ -920,10 +921,17 @@ export declare class LiveClient {
|
|
|
920
921
|
*/
|
|
921
922
|
events({
|
|
922
923
|
includeDrafts,
|
|
924
|
+
tag: _tag,
|
|
923
925
|
}?: {
|
|
924
926
|
/** @alpha this API is experimental and may change or even be removed */
|
|
925
927
|
includeDrafts?: boolean
|
|
926
|
-
|
|
928
|
+
/**
|
|
929
|
+
* Optional request tag for the listener. Use to identify the request in logs.
|
|
930
|
+
*
|
|
931
|
+
* @defaultValue `undefined`
|
|
932
|
+
*/
|
|
933
|
+
tag?: string
|
|
934
|
+
}): Observable<LiveEventMessage | LiveEventRestart | LiveEventReconnect | LiveEventWelcome>
|
|
927
935
|
}
|
|
928
936
|
|
|
929
937
|
/** @public */
|
|
@@ -933,9 +941,20 @@ export declare interface LiveEventMessage {
|
|
|
933
941
|
tags: SyncTag[]
|
|
934
942
|
}
|
|
935
943
|
|
|
944
|
+
/** @public */
|
|
945
|
+
export declare interface LiveEventReconnect {
|
|
946
|
+
type: 'reconnect'
|
|
947
|
+
}
|
|
948
|
+
|
|
936
949
|
/** @public */
|
|
937
950
|
export declare interface LiveEventRestart {
|
|
938
951
|
type: 'restart'
|
|
952
|
+
id: string
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/** @public */
|
|
956
|
+
export declare interface LiveEventWelcome {
|
|
957
|
+
type: 'welcome'
|
|
939
958
|
}
|
|
940
959
|
|
|
941
960
|
/** @public */
|
|
@@ -2122,7 +2141,7 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
2122
2141
|
returnQuery?: boolean
|
|
2123
2142
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
2124
2143
|
perspective?: ClientPerspective
|
|
2125
|
-
bundlePerspective?: string
|
|
2144
|
+
bundlePerspective?: string[]
|
|
2126
2145
|
lastLiveEventId?: string
|
|
2127
2146
|
}
|
|
2128
2147
|
|
|
@@ -2154,7 +2173,7 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
2154
2173
|
/** @public */
|
|
2155
2174
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
2156
2175
|
perspective?: ClientPerspective
|
|
2157
|
-
bundlePerspective?: string
|
|
2176
|
+
bundlePerspective?: string[]
|
|
2158
2177
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
2159
2178
|
returnQuery?: boolean
|
|
2160
2179
|
useCdn?: boolean
|
|
@@ -2711,7 +2730,7 @@ export declare type SanityDocument<T extends Record<string, Any> = Record<string
|
|
|
2711
2730
|
_createdAt: string
|
|
2712
2731
|
_updatedAt: string
|
|
2713
2732
|
/**
|
|
2714
|
-
* Present when `perspective` is set to `previewDrafts`
|
|
2733
|
+
* Present when `perspective` is set to `previewDrafts`
|
|
2715
2734
|
*/
|
|
2716
2735
|
_originalId?: string
|
|
2717
2736
|
}
|
package/dist/index.browser.js
CHANGED
|
@@ -87,7 +87,8 @@ function defineHttpRequest(envMiddleware2) {
|
|
|
87
87
|
]);
|
|
88
88
|
}
|
|
89
89
|
function shouldRetry(err, attempt, options) {
|
|
90
|
-
if (options.maxRetries === 0)
|
|
90
|
+
if (options.maxRetries === 0)
|
|
91
|
+
return !1;
|
|
91
92
|
const isSafe = options.method === "GET" || options.method === "HEAD", isQuery = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
92
93
|
return (isSafe || isQuery) && isRetriableResponse ? !0 : retry.shouldRetry(err, attempt, options);
|
|
93
94
|
}
|
|
@@ -518,6 +519,11 @@ const validateApiPerspective = function(perspective) {
|
|
|
518
519
|
"Invalid API perspective string, expected `published`, `previewDrafts` or `raw`"
|
|
519
520
|
);
|
|
520
521
|
}
|
|
522
|
+
}, validateApiBundlePerspective = function(perspective, bundlePerspective) {
|
|
523
|
+
if (perspective !== "raw" && bundlePerspective)
|
|
524
|
+
throw new TypeError(
|
|
525
|
+
"Invalid, perspective and bundlePerspective parameters are mutually exclusive"
|
|
526
|
+
);
|
|
521
527
|
}, initConfig = (config, prevConfig) => {
|
|
522
528
|
const specifiedConfig = {
|
|
523
529
|
...prevConfig,
|
|
@@ -734,8 +740,10 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
734
740
|
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
735
741
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
736
742
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
737
|
-
const perspective = options.perspective || config.perspective
|
|
738
|
-
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()))
|
|
743
|
+
const perspective = options.perspective || config.perspective;
|
|
744
|
+
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
|
|
745
|
+
const bundlePerspective = options.bundlePerspective || config.bundlePerspective;
|
|
746
|
+
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 });
|
|
739
747
|
}
|
|
740
748
|
const reqOptions = requestOptions(
|
|
741
749
|
config,
|
|
@@ -927,27 +935,33 @@ class LiveClient {
|
|
|
927
935
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
928
936
|
*/
|
|
929
937
|
events({
|
|
930
|
-
includeDrafts = !1
|
|
938
|
+
includeDrafts = !1,
|
|
939
|
+
tag: _tag
|
|
931
940
|
} = {}) {
|
|
932
|
-
const {
|
|
941
|
+
const {
|
|
942
|
+
apiVersion: _apiVersion,
|
|
943
|
+
token,
|
|
944
|
+
withCredentials,
|
|
945
|
+
requestTagPrefix
|
|
946
|
+
} = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
933
947
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
934
948
|
throw new Error(
|
|
935
949
|
`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
950
|
);
|
|
937
|
-
if (includeDrafts && !token)
|
|
951
|
+
if (includeDrafts && !token && !withCredentials)
|
|
938
952
|
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."
|
|
953
|
+
"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
954
|
);
|
|
941
955
|
if (includeDrafts && apiVersion !== "X")
|
|
942
956
|
throw new Error(
|
|
943
957
|
"The live events API requires API version X when 'includeDrafts: true'. This API is experimental and may change or even be removed."
|
|
944
958
|
);
|
|
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 = {};
|
|
959
|
+
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
|
|
960
|
+
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
961
|
+
const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {};
|
|
948
962
|
return includeDrafts && token && (esOptions.headers = {
|
|
949
963
|
Authorization: `Bearer ${token}`
|
|
950
|
-
}), new Observable((observer) => {
|
|
964
|
+
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new Observable((observer) => {
|
|
951
965
|
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
952
966
|
open();
|
|
953
967
|
function onError(evt) {
|
|
@@ -972,7 +986,7 @@ class LiveClient {
|
|
|
972
986
|
}
|
|
973
987
|
}
|
|
974
988
|
async function getEventSource() {
|
|
975
|
-
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
|
|
989
|
+
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
|
|
976
990
|
if (unsubscribed)
|
|
977
991
|
return;
|
|
978
992
|
const evs = new EventSourceImplementation(url.toString(), esOptions);
|