@sanity/client 5.1.0 → 5.2.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.js CHANGED
@@ -4,7 +4,7 @@ import { Observable, lastValueFrom } from 'rxjs';
4
4
  import { map, filter } from 'rxjs/operators';
5
5
  import polyfilledEventSource from '@sanity/eventsource';
6
6
  var name = "@sanity/client";
7
- var version = "5.1.0";
7
+ var version = "5.2.1";
8
8
  const middleware = [debug({
9
9
  verbose: true,
10
10
  namespace: "sanity:client"
@@ -92,7 +92,7 @@ function defineHttpRequest(envMiddleware) {
92
92
  return httpRequest;
93
93
  }
94
94
  const projectHeader = "X-Sanity-Project-ID";
95
- var getRequestOptions = function (config) {
95
+ function requestOptions(config) {
96
96
  let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
97
97
  const headers = {};
98
98
  const token = overrides.token || config.token;
@@ -111,7 +111,7 @@ var getRequestOptions = function (config) {
111
111
  json: true,
112
112
  withCredentials
113
113
  });
114
- };
114
+ }
115
115
  function getSelection(sel) {
116
116
  if (typeof sel === "string" || Array.isArray(sel)) {
117
117
  return {
@@ -187,7 +187,7 @@ const requestTag = tag => {
187
187
  }
188
188
  return tag;
189
189
  };
190
- var encodeQueryString = _ref => {
190
+ const encodeQueryString = _ref => {
191
191
  let {
192
192
  query,
193
193
  params = {},
@@ -792,7 +792,7 @@ function _requestObservable(client, httpRequest, options) {
792
792
  ...options.query
793
793
  };
794
794
  }
795
- const reqOptions = getRequestOptions(config, Object.assign({}, options, {
795
+ const reqOptions = requestOptions(config, Object.assign({}, options, {
796
796
  url: _getUrl(client, uri, useCdn)
797
797
  }));
798
798
  const request = new Observable(subscriber =>
@@ -948,7 +948,7 @@ const BASE_URL = "https://www.sanity.io/help/";
948
948
  function generateHelpUrl(slug) {
949
949
  return BASE_URL + slug;
950
950
  }
951
- var once = fn => {
951
+ function once(fn) {
952
952
  let didCall = false;
953
953
  let returnValue;
954
954
  return function () {
@@ -959,7 +959,7 @@ var once = fn => {
959
959
  didCall = true;
960
960
  return returnValue;
961
961
  };
962
- };
962
+ }
963
963
  const createWarningPrinter = message =>
964
964
  // eslint-disable-next-line no-console
965
965
  once(function () {
@@ -971,6 +971,7 @@ once(function () {
971
971
  const printCdnWarning = createWarningPrinter(["You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and", "cheaper. Think about it! For more info, see ".concat(generateHelpUrl("js-client-cdn-configuration"), " "), "To hide this warning, please set the `useCdn` option to either `true` or `false` when creating", "the client."]);
972
972
  const printBrowserTokenWarning = createWarningPrinter(["You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.", "See ".concat(generateHelpUrl("js-client-browser-token"), " for more information and how to hide this warning.")]);
973
973
  const printNoApiVersionSpecifiedWarning = createWarningPrinter(["Using the Sanity client without specifying an API version is deprecated.", "See ".concat(generateHelpUrl("js-client-api-version"))]);
974
+ const printNoDefaultExport = createWarningPrinter(["The default export of @sanity/client has been deprecated. Use the named export `createClient` instead"]);
974
975
  const defaultCdnHost = "apicdn.sanity.io";
975
976
  const defaultConfig = {
976
977
  apiHost: "https://api.sanity.io",
@@ -1040,7 +1041,7 @@ var defaults = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj))
1040
1041
  target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
1041
1042
  return target;
1042
1043
  }, {});
1043
- var pick = (obj, props) => props.reduce((selection, prop) => {
1044
+ const pick = (obj, props) => props.reduce((selection, prop) => {
1044
1045
  if (typeof obj[prop] === "undefined") {
1045
1046
  return selection;
1046
1047
  }
@@ -1552,6 +1553,24 @@ const _ObservableSanityClient = class {
1552
1553
  request(options) {
1553
1554
  return _request(this, __privateGet(this, _httpRequest), options);
1554
1555
  }
1556
+ /**
1557
+ * Get a Sanity API URL for the URI provided
1558
+ *
1559
+ * @param uri - URI/path to build URL for
1560
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
1561
+ */
1562
+ getUrl(uri, canUseCdn) {
1563
+ return _getUrl(this, uri, canUseCdn);
1564
+ }
1565
+ /**
1566
+ * Get a Sanity API URL for the data operation and path provided
1567
+ *
1568
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
1569
+ * @param path - Path to append after the operation
1570
+ */
1571
+ getDataUrl(operation, path) {
1572
+ return _getDataUrl(this, operation, path);
1573
+ }
1555
1574
  };
1556
1575
  let ObservableSanityClient = _ObservableSanityClient;
1557
1576
  _clientConfig = new WeakMap();
@@ -1685,15 +1704,34 @@ const _SanityClient = class {
1685
1704
  dataRequest(endpoint, body, options) {
1686
1705
  return lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
1687
1706
  }
1707
+ /**
1708
+ * Get a Sanity API URL for the URI provided
1709
+ *
1710
+ * @param uri - URI/path to build URL for
1711
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
1712
+ */
1713
+ getUrl(uri, canUseCdn) {
1714
+ return _getUrl(this, uri, canUseCdn);
1715
+ }
1716
+ /**
1717
+ * Get a Sanity API URL for the data operation and path provided
1718
+ *
1719
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
1720
+ * @param path - Path to append after the operation
1721
+ */
1722
+ getDataUrl(operation, path) {
1723
+ return _getDataUrl(this, operation, path);
1724
+ }
1688
1725
  };
1689
1726
  let SanityClient = _SanityClient;
1690
1727
  _clientConfig2 = new WeakMap();
1691
1728
  _httpRequest2 = new WeakMap();
1692
- function migrationNotice() {
1693
- throw new TypeError("The default export of @sanity/client has been deprecated. Use the named export `createClient` instead");
1694
- }
1695
1729
  const httpRequest = defineHttpRequest(middleware);
1696
1730
  const requester = httpRequest.defaultRequester;
1697
1731
  const createClient = config => new SanityClient(httpRequest, config);
1698
- export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, migrationNotice as default, requester };
1732
+ function deprecatedCreateClient(config) {
1733
+ printNoDefaultExport();
1734
+ return new SanityClient(httpRequest, config);
1735
+ }
1736
+ export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, deprecatedCreateClient as default, requester };
1699
1737
  //# sourceMappingURL=index.js.map