@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "6.28.3",
3
+ "version": "6.28.4-beta.1",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
package/src/config.ts CHANGED
@@ -122,7 +122,13 @@ 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
- if (isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== true) {
125
+ const hasToken = Boolean(newConfig.token)
126
+ if (newConfig.withCredentials && hasToken) {
127
+ warnings.printCredentialedTokenWarning()
128
+ newConfig.withCredentials = false
129
+ }
130
+
131
+ if (isBrowser && isLocalhost && hasToken && newConfig.ignoreBrowserTokenWarning !== true) {
126
132
  warnings.printBrowserTokenWarning()
127
133
  } else if (typeof newConfig.useCdn === 'undefined') {
128
134
  warnings.printCdnWarning()
@@ -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 (token || withCredentials) {
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.token || config.withCredentials
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(latest)
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')}`,
@@ -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) { return function EmptyErrorImpl() {
1469
- _super(this);
1470
- this.name = 'EmptyError';
1471
- this.message = 'no elements in sequence';
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,8 @@
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
- isBrowser && isLocalhost && newConfig.token && 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 && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== false && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
2164
+ const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname), hasToken = !!newConfig.token;
2165
+ newConfig.withCredentials && hasToken && (printCredentialedTokenWarning(), newConfig.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 && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== false && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
2161
2166
  const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
2162
2167
  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
2168
  };
@@ -2605,7 +2610,7 @@ ${selectionOpts}`);
2605
2610
  function requestOptions(config, overrides = {}) {
2606
2611
  const headers = {}, token = overrides.token || config.token;
2607
2612
  token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
2608
- const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.token || config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
2613
+ const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
2609
2614
  return Object.assign({}, overrides, {
2610
2615
  headers: Object.assign({}, headers, overrides.headers || {}),
2611
2616
  timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
@@ -2915,7 +2920,7 @@ ${selectionOpts}`);
2915
2920
  if (uri.length > MAX_URL_LENGTH)
2916
2921
  return throwError(() => new Error("Query too large for listener"));
2917
2922
  const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
2918
- return (token || withCredentials) && (esOptions.withCredentials = true), token && (esOptions.headers = {
2923
+ return withCredentials && (esOptions.withCredentials = true), token && (esOptions.headers = {
2919
2924
  Authorization: `Bearer ${token}`
2920
2925
  }), connectEventSource(() => (
2921
2926
  // use polyfill if there is no global EventSource or if we need to set headers
@@ -2948,7 +2953,10 @@ ${selectionOpts}`);
2948
2953
  }),
2949
2954
  share(shareConfig)
2950
2955
  ), emitLatest = new Observable((subscriber) => {
2951
- emitted && subscriber.next(latest), subscriber.complete();
2956
+ emitted && subscriber.next(
2957
+ // this cast is safe because of the emitted check which asserts that we got T from the source
2958
+ latest
2959
+ ), subscriber.complete();
2952
2960
  });
2953
2961
  return merge(wrapped, emitLatest);
2954
2962
  };