@sanity/client 6.28.3 → 6.28.4-beta.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.
@@ -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,8 @@ 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
- isBrowser && isLocalhost && newConfig.token && 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 && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== !1 && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
256
+ const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname), hasToken = !!newConfig.token;
257
+ newConfig.withCredentials && hasToken && (printCredentialedTokenWarning(), newConfig.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 && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== !1 && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
255
258
  const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
256
259
  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
260
  };
@@ -699,7 +702,7 @@ const projectHeader = "X-Sanity-Project-ID";
699
702
  function requestOptions(config, overrides = {}) {
700
703
  const headers = {}, token = overrides.token || config.token;
701
704
  token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
702
- const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.token || config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
705
+ const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
703
706
  return Object.assign({}, overrides, {
704
707
  headers: Object.assign({}, headers, overrides.headers || {}),
705
708
  timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
@@ -1009,7 +1012,7 @@ function _listen(query, params, opts = {}) {
1009
1012
  if (uri.length > MAX_URL_LENGTH)
1010
1013
  return throwError(() => new Error("Query too large for listener"));
1011
1014
  const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
1012
- return (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.headers = {
1015
+ return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
1013
1016
  Authorization: `Bearer ${token}`
1014
1017
  }), connectEventSource(() => (
1015
1018
  // use polyfill if there is no global EventSource or if we need to set headers
@@ -1042,7 +1045,10 @@ function _shareReplayLatest(config) {
1042
1045
  }),
1043
1046
  share(shareConfig)
1044
1047
  ), emitLatest = new Observable((subscriber) => {
1045
- emitted && subscriber.next(latest), subscriber.complete();
1048
+ emitted && subscriber.next(
1049
+ // this cast is safe because of the emitted check which asserts that we got T from the source
1050
+ latest
1051
+ ), subscriber.complete();
1046
1052
  });
1047
1053
  return merge(wrapped, emitLatest);
1048
1054
  };