@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/dist/index.browser.js
CHANGED
|
@@ -180,6 +180,9 @@ const createWarningPrinter = (message) => (
|
|
|
180
180
|
`See ${generateHelpUrl(
|
|
181
181
|
"js-client-browser-token"
|
|
182
182
|
)} for more information and how to hide this warning.`
|
|
183
|
+
]), printCredentialedTokenWarning = createWarningPrinter([
|
|
184
|
+
"You have configured Sanity client to use a token, but also provided `withCredentials: true`.",
|
|
185
|
+
"This is no longer supported - only token will be used - remove `withCredentials: true`."
|
|
183
186
|
]), printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
184
187
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
185
188
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
@@ -250,8 +253,9 @@ const initConfig = (config, prevConfig) => {
|
|
|
250
253
|
throw new Error(
|
|
251
254
|
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
252
255
|
);
|
|
253
|
-
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
254
|
-
|
|
256
|
+
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname), hasToken = !!newConfig.token;
|
|
257
|
+
let withCredentials = !!newConfig.withCredentials;
|
|
258
|
+
withCredentials && hasToken && (printCredentialedTokenWarning(), withCredentials = !1), isBrowser && isLocalhost && hasToken && newConfig.ignoreBrowserTokenWarning !== !0 ? 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 === !0 && withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== !1 && !withCredentials, validateApiVersion(newConfig.apiVersion);
|
|
255
259
|
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
256
260
|
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;
|
|
257
261
|
};
|
|
@@ -699,7 +703,7 @@ const projectHeader = "X-Sanity-Project-ID";
|
|
|
699
703
|
function requestOptions(config, overrides = {}) {
|
|
700
704
|
const headers = {}, token = overrides.token || config.token;
|
|
701
705
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
|
|
702
|
-
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.
|
|
706
|
+
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
|
|
703
707
|
return Object.assign({}, overrides, {
|
|
704
708
|
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
705
709
|
timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
|
|
@@ -1009,7 +1013,7 @@ function _listen(query, params, opts = {}) {
|
|
|
1009
1013
|
if (uri.length > MAX_URL_LENGTH)
|
|
1010
1014
|
return throwError(() => new Error("Query too large for listener"));
|
|
1011
1015
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
1012
|
-
return
|
|
1016
|
+
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
1013
1017
|
Authorization: `Bearer ${token}`
|
|
1014
1018
|
}), connectEventSource(() => (
|
|
1015
1019
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
@@ -1042,7 +1046,10 @@ function _shareReplayLatest(config) {
|
|
|
1042
1046
|
}),
|
|
1043
1047
|
share(shareConfig)
|
|
1044
1048
|
), emitLatest = new Observable((subscriber) => {
|
|
1045
|
-
emitted && subscriber.next(
|
|
1049
|
+
emitted && subscriber.next(
|
|
1050
|
+
// this cast is safe because of the emitted check which asserts that we got T from the source
|
|
1051
|
+
latest
|
|
1052
|
+
), subscriber.complete();
|
|
1046
1053
|
});
|
|
1047
1054
|
return merge(wrapped, emitLatest);
|
|
1048
1055
|
};
|