@sanity/client 6.28.3 → 6.28.4-beta.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/_chunks-cjs/config.cjs +6 -2
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +6 -2
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +12 -5
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +12 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +7 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +11 -3
- package/src/data/listen.ts +1 -1
- package/src/http/requestOptions.ts +1 -1
- package/src/util/shareReplayLatest.ts +4 -1
- package/src/warnings.ts +5 -0
- package/umd/sanityClient.js +19 -10
- package/umd/sanityClient.min.js +2 -2
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -122,7 +122,15 @@ export const initConfig = (
|
|
|
122
122
|
const isBrowser = typeof window !== 'undefined' && window.location && window.location.hostname
|
|
123
123
|
const isLocalhost = isBrowser && isLocal(window.location.hostname)
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
const hasToken = Boolean(newConfig.token)
|
|
126
|
+
let withCredentials = Boolean(newConfig.withCredentials)
|
|
127
|
+
|
|
128
|
+
if (withCredentials && hasToken) {
|
|
129
|
+
warnings.printCredentialedTokenWarning()
|
|
130
|
+
withCredentials = false
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (isBrowser && isLocalhost && hasToken && newConfig.ignoreBrowserTokenWarning !== true) {
|
|
126
134
|
warnings.printBrowserTokenWarning()
|
|
127
135
|
} else if (typeof newConfig.useCdn === 'undefined') {
|
|
128
136
|
warnings.printCdnWarning()
|
|
@@ -146,12 +154,12 @@ export const initConfig = (
|
|
|
146
154
|
newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, '')
|
|
147
155
|
newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost
|
|
148
156
|
|
|
149
|
-
if (newConfig.useCdn === true &&
|
|
157
|
+
if (newConfig.useCdn === true && withCredentials) {
|
|
150
158
|
warnings.printCdnAndWithCredentialsWarning()
|
|
151
159
|
}
|
|
152
160
|
|
|
153
161
|
// If `useCdn` is undefined, we treat it as `true`
|
|
154
|
-
newConfig.useCdn = newConfig.useCdn !== false && !
|
|
162
|
+
newConfig.useCdn = newConfig.useCdn !== false && !withCredentials
|
|
155
163
|
|
|
156
164
|
validateApiVersion(newConfig.apiVersion)
|
|
157
165
|
|
package/src/data/listen.ts
CHANGED
|
@@ -84,7 +84,7 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
|
84
84
|
const listenFor = options.events ? options.events : ['mutation']
|
|
85
85
|
|
|
86
86
|
const esOptions: EventSourceInit & {headers?: Record<string, string>} = {}
|
|
87
|
-
if (
|
|
87
|
+
if (withCredentials) {
|
|
88
88
|
esOptions.withCredentials = true
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -18,7 +18,7 @@ export function requestOptions(config: Any, overrides: Any = {}): Omit<RequestOp
|
|
|
18
18
|
|
|
19
19
|
const withCredentials = Boolean(
|
|
20
20
|
typeof overrides.withCredentials === 'undefined'
|
|
21
|
-
? config.
|
|
21
|
+
? config.withCredentials
|
|
22
22
|
: overrides.withCredentials,
|
|
23
23
|
)
|
|
24
24
|
|
|
@@ -62,7 +62,10 @@ function _shareReplayLatest<T>(config: ShareReplayLatestConfig<T>): MonoTypeOper
|
|
|
62
62
|
)
|
|
63
63
|
const emitLatest = new Observable<T>((subscriber) => {
|
|
64
64
|
if (emitted) {
|
|
65
|
-
subscriber.next(
|
|
65
|
+
subscriber.next(
|
|
66
|
+
// this cast is safe because of the emitted check which asserts that we got T from the source
|
|
67
|
+
latest as T,
|
|
68
|
+
)
|
|
66
69
|
}
|
|
67
70
|
subscriber.complete()
|
|
68
71
|
})
|
package/src/warnings.ts
CHANGED
|
@@ -33,6 +33,11 @@ export const printBrowserTokenWarning = createWarningPrinter([
|
|
|
33
33
|
)} for more information and how to hide this warning.`,
|
|
34
34
|
])
|
|
35
35
|
|
|
36
|
+
export const printCredentialedTokenWarning = createWarningPrinter([
|
|
37
|
+
'You have configured Sanity client to use a token, but also provided `withCredentials: true`.',
|
|
38
|
+
'This is no longer supported - only token will be used - remove `withCredentials: true`.',
|
|
39
|
+
])
|
|
40
|
+
|
|
36
41
|
export const printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
37
42
|
'Using the Sanity client without specifying an API version is deprecated.',
|
|
38
43
|
`See ${generateHelpUrl('js-client-api-version')}`,
|
package/umd/sanityClient.js
CHANGED
|
@@ -1465,11 +1465,13 @@
|
|
|
1465
1465
|
return !!obj && (obj instanceof Observable || (isFunction(obj.lift) && isFunction(obj.subscribe)));
|
|
1466
1466
|
}
|
|
1467
1467
|
|
|
1468
|
-
var EmptyError = createErrorClass(function (_super) {
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1468
|
+
var EmptyError = createErrorClass(function (_super) {
|
|
1469
|
+
return function EmptyErrorImpl() {
|
|
1470
|
+
_super(this);
|
|
1471
|
+
this.name = 'EmptyError';
|
|
1472
|
+
this.message = 'no elements in sequence';
|
|
1473
|
+
};
|
|
1474
|
+
});
|
|
1473
1475
|
|
|
1474
1476
|
function lastValueFrom(source, config) {
|
|
1475
1477
|
return new Promise(function (resolve, reject) {
|
|
@@ -2086,6 +2088,9 @@
|
|
|
2086
2088
|
`See ${generateHelpUrl(
|
|
2087
2089
|
"js-client-browser-token"
|
|
2088
2090
|
)} for more information and how to hide this warning.`
|
|
2091
|
+
]), printCredentialedTokenWarning = createWarningPrinter([
|
|
2092
|
+
"You have configured Sanity client to use a token, but also provided `withCredentials: true`.",
|
|
2093
|
+
"This is no longer supported - only token will be used - remove `withCredentials: true`."
|
|
2089
2094
|
]), printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
2090
2095
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
2091
2096
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
@@ -2156,8 +2161,9 @@
|
|
|
2156
2161
|
throw new Error(
|
|
2157
2162
|
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
2158
2163
|
);
|
|
2159
|
-
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
2160
|
-
|
|
2164
|
+
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname), hasToken = !!newConfig.token;
|
|
2165
|
+
let withCredentials = !!newConfig.withCredentials;
|
|
2166
|
+
withCredentials && hasToken && (printCredentialedTokenWarning(), withCredentials = false), isBrowser && isLocalhost && hasToken && newConfig.ignoreBrowserTokenWarning !== true ? printBrowserTokenWarning() : typeof newConfig.useCdn > "u" && printCdnWarning(), projectBased && projectId(newConfig.projectId), newConfig.dataset && dataset(newConfig.dataset), "requestTagPrefix" in newConfig && (newConfig.requestTagPrefix = newConfig.requestTagPrefix ? requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0), newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, ""), newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost, newConfig.useCdn === true && withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== false && !withCredentials, validateApiVersion(newConfig.apiVersion);
|
|
2161
2167
|
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
2162
2168
|
return newConfig.useProjectHostname ? (newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`, newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`) : (newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`, newConfig.cdnUrl = newConfig.url), newConfig;
|
|
2163
2169
|
};
|
|
@@ -2605,7 +2611,7 @@ ${selectionOpts}`);
|
|
|
2605
2611
|
function requestOptions(config, overrides = {}) {
|
|
2606
2612
|
const headers = {}, token = overrides.token || config.token;
|
|
2607
2613
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
|
|
2608
|
-
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.
|
|
2614
|
+
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
|
|
2609
2615
|
return Object.assign({}, overrides, {
|
|
2610
2616
|
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
2611
2617
|
timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
|
|
@@ -2915,7 +2921,7 @@ ${selectionOpts}`);
|
|
|
2915
2921
|
if (uri.length > MAX_URL_LENGTH)
|
|
2916
2922
|
return throwError(() => new Error("Query too large for listener"));
|
|
2917
2923
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
2918
|
-
return
|
|
2924
|
+
return withCredentials && (esOptions.withCredentials = true), token && (esOptions.headers = {
|
|
2919
2925
|
Authorization: `Bearer ${token}`
|
|
2920
2926
|
}), connectEventSource(() => (
|
|
2921
2927
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
@@ -2948,7 +2954,10 @@ ${selectionOpts}`);
|
|
|
2948
2954
|
}),
|
|
2949
2955
|
share(shareConfig)
|
|
2950
2956
|
), emitLatest = new Observable((subscriber) => {
|
|
2951
|
-
emitted && subscriber.next(
|
|
2957
|
+
emitted && subscriber.next(
|
|
2958
|
+
// this cast is safe because of the emitted check which asserts that we got T from the source
|
|
2959
|
+
latest
|
|
2960
|
+
), subscriber.complete();
|
|
2952
2961
|
});
|
|
2953
2962
|
return merge(wrapped, emitLatest);
|
|
2954
2963
|
};
|