@sanity/client 6.22.1 → 6.22.2-bundle-perspective-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 +28 -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 +28 -10
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +29 -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 +29 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +10 -0
- package/src/data/dataMethods.ts +12 -1
- package/src/data/live.ts +32 -7
- package/src/types.ts +15 -0
- package/umd/sanityClient.js +28 -10
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.d.cts
CHANGED
|
@@ -331,6 +331,8 @@ export declare interface ClientConfig {
|
|
|
331
331
|
token?: string
|
|
332
332
|
/** @defaultValue 'raw' */
|
|
333
333
|
perspective?: ClientPerspective
|
|
334
|
+
/** @defaultValue 'raw' */
|
|
335
|
+
bundlePerspective?: string[]
|
|
334
336
|
apiHost?: string
|
|
335
337
|
apiVersion?: string
|
|
336
338
|
proxy?: string
|
|
@@ -919,10 +921,17 @@ export declare class LiveClient {
|
|
|
919
921
|
*/
|
|
920
922
|
events({
|
|
921
923
|
includeDrafts,
|
|
924
|
+
tag: _tag,
|
|
922
925
|
}?: {
|
|
923
926
|
/** @alpha this API is experimental and may change or even be removed */
|
|
924
927
|
includeDrafts?: boolean
|
|
925
|
-
|
|
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>
|
|
926
935
|
}
|
|
927
936
|
|
|
928
937
|
/** @public */
|
|
@@ -932,9 +941,20 @@ export declare interface LiveEventMessage {
|
|
|
932
941
|
tags: SyncTag[]
|
|
933
942
|
}
|
|
934
943
|
|
|
944
|
+
/** @public */
|
|
945
|
+
export declare interface LiveEventReconnect {
|
|
946
|
+
type: 'reconnect'
|
|
947
|
+
}
|
|
948
|
+
|
|
935
949
|
/** @public */
|
|
936
950
|
export declare interface LiveEventRestart {
|
|
937
951
|
type: 'restart'
|
|
952
|
+
id: string
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/** @public */
|
|
956
|
+
export declare interface LiveEventWelcome {
|
|
957
|
+
type: 'welcome'
|
|
938
958
|
}
|
|
939
959
|
|
|
940
960
|
/** @public */
|
|
@@ -2017,6 +2037,8 @@ export declare interface QueryParams {
|
|
|
2017
2037
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2018
2038
|
perspective?: never
|
|
2019
2039
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2040
|
+
bundlePerspective?: never
|
|
2041
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2020
2042
|
query?: never
|
|
2021
2043
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2022
2044
|
resultSourceMap?: never
|
|
@@ -2119,6 +2141,7 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
2119
2141
|
returnQuery?: boolean
|
|
2120
2142
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
2121
2143
|
perspective?: ClientPerspective
|
|
2144
|
+
bundlePerspective?: string[]
|
|
2122
2145
|
lastLiveEventId?: string
|
|
2123
2146
|
}
|
|
2124
2147
|
|
|
@@ -2150,6 +2173,7 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
2150
2173
|
/** @public */
|
|
2151
2174
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
2152
2175
|
perspective?: ClientPerspective
|
|
2176
|
+
bundlePerspective?: string[]
|
|
2153
2177
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
2154
2178
|
returnQuery?: boolean
|
|
2155
2179
|
useCdn?: boolean
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -331,6 +331,8 @@ export declare interface ClientConfig {
|
|
|
331
331
|
token?: string
|
|
332
332
|
/** @defaultValue 'raw' */
|
|
333
333
|
perspective?: ClientPerspective
|
|
334
|
+
/** @defaultValue 'raw' */
|
|
335
|
+
bundlePerspective?: string[]
|
|
334
336
|
apiHost?: string
|
|
335
337
|
apiVersion?: string
|
|
336
338
|
proxy?: string
|
|
@@ -919,10 +921,17 @@ export declare class LiveClient {
|
|
|
919
921
|
*/
|
|
920
922
|
events({
|
|
921
923
|
includeDrafts,
|
|
924
|
+
tag: _tag,
|
|
922
925
|
}?: {
|
|
923
926
|
/** @alpha this API is experimental and may change or even be removed */
|
|
924
927
|
includeDrafts?: boolean
|
|
925
|
-
|
|
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>
|
|
926
935
|
}
|
|
927
936
|
|
|
928
937
|
/** @public */
|
|
@@ -932,9 +941,20 @@ export declare interface LiveEventMessage {
|
|
|
932
941
|
tags: SyncTag[]
|
|
933
942
|
}
|
|
934
943
|
|
|
944
|
+
/** @public */
|
|
945
|
+
export declare interface LiveEventReconnect {
|
|
946
|
+
type: 'reconnect'
|
|
947
|
+
}
|
|
948
|
+
|
|
935
949
|
/** @public */
|
|
936
950
|
export declare interface LiveEventRestart {
|
|
937
951
|
type: 'restart'
|
|
952
|
+
id: string
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/** @public */
|
|
956
|
+
export declare interface LiveEventWelcome {
|
|
957
|
+
type: 'welcome'
|
|
938
958
|
}
|
|
939
959
|
|
|
940
960
|
/** @public */
|
|
@@ -2017,6 +2037,8 @@ export declare interface QueryParams {
|
|
|
2017
2037
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2018
2038
|
perspective?: never
|
|
2019
2039
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2040
|
+
bundlePerspective?: never
|
|
2041
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2020
2042
|
query?: never
|
|
2021
2043
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2022
2044
|
resultSourceMap?: never
|
|
@@ -2119,6 +2141,7 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
2119
2141
|
returnQuery?: boolean
|
|
2120
2142
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
2121
2143
|
perspective?: ClientPerspective
|
|
2144
|
+
bundlePerspective?: string[]
|
|
2122
2145
|
lastLiveEventId?: string
|
|
2123
2146
|
}
|
|
2124
2147
|
|
|
@@ -2150,6 +2173,7 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
2150
2173
|
/** @public */
|
|
2151
2174
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
2152
2175
|
perspective?: ClientPerspective
|
|
2176
|
+
bundlePerspective?: string[]
|
|
2153
2177
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
2154
2178
|
returnQuery?: boolean
|
|
2155
2179
|
useCdn?: boolean
|
package/dist/index.browser.js
CHANGED
|
@@ -519,6 +519,11 @@ const validateApiPerspective = function(perspective) {
|
|
|
519
519
|
"Invalid API perspective string, expected `published`, `previewDrafts` or `raw`"
|
|
520
520
|
);
|
|
521
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
|
+
);
|
|
522
527
|
}, initConfig = (config, prevConfig) => {
|
|
523
528
|
const specifiedConfig = {
|
|
524
529
|
...prevConfig,
|
|
@@ -697,6 +702,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
697
702
|
tag,
|
|
698
703
|
returnQuery,
|
|
699
704
|
perspective: options.perspective,
|
|
705
|
+
bundlePerspective: options.bundlePerspective,
|
|
700
706
|
resultSourceMap: options.resultSourceMap,
|
|
701
707
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
702
708
|
canUseCdn: isQuery,
|
|
@@ -735,7 +741,13 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
735
741
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
736
742
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
737
743
|
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()))
|
|
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 = {
|
|
747
|
+
perspective: void 0,
|
|
748
|
+
bundlePerspective: bundlePerspective.join(","),
|
|
749
|
+
...options.query
|
|
750
|
+
}), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
|
|
739
751
|
}
|
|
740
752
|
const reqOptions = requestOptions(
|
|
741
753
|
config,
|
|
@@ -927,27 +939,33 @@ class LiveClient {
|
|
|
927
939
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
928
940
|
*/
|
|
929
941
|
events({
|
|
930
|
-
includeDrafts = !1
|
|
942
|
+
includeDrafts = !1,
|
|
943
|
+
tag: _tag
|
|
931
944
|
} = {}) {
|
|
932
|
-
const {
|
|
945
|
+
const {
|
|
946
|
+
apiVersion: _apiVersion,
|
|
947
|
+
token,
|
|
948
|
+
withCredentials,
|
|
949
|
+
requestTagPrefix
|
|
950
|
+
} = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
933
951
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
934
952
|
throw new Error(
|
|
935
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.`
|
|
936
954
|
);
|
|
937
|
-
if (includeDrafts && !token)
|
|
955
|
+
if (includeDrafts && !token && !withCredentials)
|
|
938
956
|
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."
|
|
957
|
+
"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
958
|
);
|
|
941
959
|
if (includeDrafts && apiVersion !== "X")
|
|
942
960
|
throw new Error(
|
|
943
961
|
"The live events API requires API version X when 'includeDrafts: true'. This API is experimental and may change or even be removed."
|
|
944
962
|
);
|
|
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 = {};
|
|
963
|
+
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
|
|
964
|
+
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
965
|
+
const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {};
|
|
948
966
|
return includeDrafts && token && (esOptions.headers = {
|
|
949
967
|
Authorization: `Bearer ${token}`
|
|
950
|
-
}), new Observable((observer) => {
|
|
968
|
+
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new Observable((observer) => {
|
|
951
969
|
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
952
970
|
open();
|
|
953
971
|
function onError(evt) {
|
|
@@ -972,7 +990,7 @@ class LiveClient {
|
|
|
972
990
|
}
|
|
973
991
|
}
|
|
974
992
|
async function getEventSource() {
|
|
975
|
-
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
|
|
993
|
+
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
|
|
976
994
|
if (unsubscribed)
|
|
977
995
|
return;
|
|
978
996
|
const evs = new EventSourceImplementation(url.toString(), esOptions);
|