@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/README.md CHANGED
@@ -48,7 +48,7 @@ export async function updateDocumentTitle(_id, title) {
48
48
  }
49
49
  ```
50
50
 
51
- # Table of contents<!-- omit in toc -->
51
+ # Table of contents
52
52
 
53
53
  - [QuickStart](#quickstart)
54
54
  - [Requirements](#requirements)
@@ -88,6 +88,7 @@ export async function updateDocumentTitle(_id, title) {
88
88
  - [Examples: Specify image metadata to extract](#examples-specify-image-metadata-to-extract)
89
89
  - [Deleting an asset](#deleting-an-asset)
90
90
  - [Mutation options](#mutation-options)
91
+ - [Aborting a request](#aborting-a-request)
91
92
  - [Get client configuration](#get-client-configuration)
92
93
  - [Set client configuration](#set-client-configuration)
93
94
  - [Release new version](#release-new-version)
@@ -925,15 +926,15 @@ MIT © [Sanity.io](https://www.sanity.io/)
925
926
 
926
927
  ## From `v4`
927
928
 
928
- ### No longer shipping `ES5`<!-- omit in toc -->
929
+ ### No longer shipping `ES5`
929
930
 
930
931
  The target is changed to [modern browsers] that supports `ES6` `class`, `{...rest}` syntax and more. You may need to update your bundler to a recent major version. Or you could configure your bundler to transpile `@sanity/client`, and `get-it`, which is the engine that powers `@sanity/client` and uses the same output target.
931
932
 
932
- ### Node.js `v12` no longer supported<!-- omit in toc -->
933
+ ### Node.js `v12` no longer supported
933
934
 
934
935
  Upgrade to the [LTS release, or one of the Maintenance releases](https://github.com/nodejs/release#release-schedule).
935
936
 
936
- ### The `default` export is replaced with the named export `createClient`<!-- omit in toc -->
937
+ ### The `default` export is replaced with the named export `createClient`
937
938
 
938
939
  Before:
939
940
 
@@ -954,7 +955,7 @@ import {createClient} from '@sanity/client'
954
955
  const client = createClient()
955
956
  ```
956
957
 
957
- ### `client.assets.delete` is removed<!-- omit in toc -->
958
+ ### `client.assets.delete` is removed
958
959
 
959
960
  Before:
960
961
 
@@ -970,7 +971,7 @@ After:
970
971
  client.delete('image-abc123_foobar-123x123-png')
971
972
  ```
972
973
 
973
- ### `client.assets.getImageUrl` is removed, replace with [`@sanity/image-url`](https://github.com/sanity-io/image-url)<!-- omit in toc -->
974
+ ### `client.assets.getImageUrl` is removed, replace with [`@sanity/image-url`](https://github.com/sanity-io/image-url)
974
975
 
975
976
  Before:
976
977
 
@@ -1001,7 +1002,7 @@ urlFor({_ref: 'image-abc123_foobar-123x123-png'}).url()
1001
1002
  urlFor({_ref: 'image-abc123_foobar-123x123-png'}).auto('format').url()
1002
1003
  ```
1003
1004
 
1004
- ### `SanityClient` static properties moved to named exports<!-- omit in toc -->
1005
+ ### `SanityClient` static properties moved to named exports
1005
1006
 
1006
1007
  Before:
1007
1008
 
@@ -1017,7 +1018,7 @@ After:
1017
1018
  import {Patch, Transaction, ClientError, ServerError, requester} from '@sanity/client'
1018
1019
  ```
1019
1020
 
1020
- ### `client.clientConfig` is removed, replace with `client.config()`<!-- omit in toc -->
1021
+ ### `client.clientConfig` is removed, replace with `client.config()`
1021
1022
 
1022
1023
  Before:
1023
1024
 
@@ -1037,64 +1038,7 @@ const client = createClient()
1037
1038
  console.log(client.config().projectId)
1038
1039
  ```
1039
1040
 
1040
- ### `client.getUrl()` is removed<!-- omit in toc -->
1041
-
1042
- Before:
1043
-
1044
- ```ts
1045
- import createClient from '@sanity/client'
1046
- const client = createClient({projectId: 'abc123'})
1047
-
1048
- console.log(client.getUrl('/foo/bar') === 'https://abc123.api.sanity.io/v1/foo/bar')
1049
- console.log(client.getUrl('/foo/bar', true) === 'https://abc123.apicdn.sanity.io/v1/foo/bar')
1050
- ```
1051
-
1052
- After:
1053
-
1054
- ```ts
1055
- import {createClient} from '@sanity/client'
1056
- const client = createClient({projectId: 'abc123'})
1057
-
1058
- const getUrl = (uri: string, useCdn = false) => {
1059
- const config = client.config()
1060
- const base = useCdn ? config.cdnUrl : config.url
1061
- return `${base}/${uri.replace(/^\//, '')}`
1062
- }
1063
-
1064
- console.log(getUrl('/foo/bar') === 'https://abc123.api.sanity.io/v1/foo/bar')
1065
- console.log(getUrl('/foo/bar', true) === 'https://abc123.apicdn.sanity.io/v1/foo/bar')
1066
- ```
1067
-
1068
- ### `client.getDataUrl()` is removed<!-- omit in toc -->
1069
-
1070
- Before:
1071
-
1072
- ```ts
1073
- import createClient from '@sanity/client'
1074
- const client = createClient({dataset: 'bikeshop'})
1075
-
1076
- console.log(client.getDataUrl('doc') === '/data/doc/bikeshop')
1077
- console.log(client.getDataUrl('doc', 'bike-123') === '/data/doc/bikeshop/bike-123')
1078
- ```
1079
-
1080
- After:
1081
-
1082
- ```ts
1083
- import {createClient} from '@sanity/client'
1084
- const client = createClient({dataset: 'bikeshop'})
1085
-
1086
- const getDataUrl = (operation: string, path?: string) => {
1087
- const {dataset} = client.config()
1088
- const baseUri = `/${operation}/${dataset}`
1089
- const uri = path ? `${baseUri}/${path}` : baseUri
1090
- return `/data${uri}`.replace(/\/($|\?)/, '$1')
1091
- }
1092
-
1093
- console.log(getDataUrl('doc') === '/data/doc/bikeshop')
1094
- console.log(getDataUrl('doc', 'bike-123') === '/data/doc/bikeshop/bike-123')
1095
- ```
1096
-
1097
- ### `client.isPromiseAPI()` is removed, replace with an `instanceof` check<!-- omit in toc -->
1041
+ ### `client.isPromiseAPI()` is removed, replace with an `instanceof` check
1098
1042
 
1099
1043
  Before:
1100
1044
 
@@ -1116,7 +1060,7 @@ const client = createClient()
1116
1060
  console.log(client instanceof SanityClient)
1117
1061
  ```
1118
1062
 
1119
- ### `client.observable.isObservableAPI()` is removed, replace with an `instanceof` check<!-- omit in toc -->
1063
+ ### `client.observable.isObservableAPI()` is removed, replace with an `instanceof` check
1120
1064
 
1121
1065
  Before:
1122
1066
 
@@ -1136,7 +1080,7 @@ const client = createClient()
1136
1080
  console.log(client.observable instanceof ObservableSanityClient)
1137
1081
  ```
1138
1082
 
1139
- ### `client._requestObservable` is removed, replace with `client.observable.request`<!-- omit in toc -->
1083
+ ### `client._requestObservable` is removed, replace with `client.observable.request`
1140
1084
 
1141
1085
  Before:
1142
1086
 
@@ -1156,7 +1100,7 @@ const client = createClient()
1156
1100
  client.observable.request({uri: '/ping'}).subscribe()
1157
1101
  ```
1158
1102
 
1159
- ### `client._dataRequest` is removed, replace with `client.dataRequest`<!-- omit in toc -->
1103
+ ### `client._dataRequest` is removed, replace with `client.dataRequest`
1160
1104
 
1161
1105
  Before:
1162
1106
 
@@ -1176,7 +1120,7 @@ const client = createClient()
1176
1120
  client.dataRequest(endpoint, body, options)
1177
1121
  ```
1178
1122
 
1179
- ### `client._create_` is removed, replace with one of `client.create`, `client.createIfNotExists` or `client.createOrReplace`<!-- omit in toc -->
1123
+ ### `client._create_` is removed, replace with one of `client.create`, `client.createIfNotExists` or `client.createOrReplace`
1180
1124
 
1181
1125
  Before:
1182
1126
 
@@ -1200,7 +1144,7 @@ client.createIfNotExists(doc, options)
1200
1144
  client.createOrReplace(doc, options)
1201
1145
  ```
1202
1146
 
1203
- ### `client.patch.replace` is removed, replace with `client.createOrReplace`<!-- omit in toc -->
1147
+ ### `client.patch.replace` is removed, replace with `client.createOrReplace`
1204
1148
 
1205
1149
  Before:
1206
1150
 
@@ -1225,7 +1169,7 @@ client.createOrReplace({
1225
1169
  })
1226
1170
  ```
1227
1171
 
1228
- ### `client.auth` is removed, replace with `client.request`<!-- omit in toc -->
1172
+ ### `client.auth` is removed, replace with `client.request`
1229
1173
 
1230
1174
  Before:
1231
1175
 
@@ -94,7 +94,7 @@ function defineHttpRequest(envMiddleware) {
94
94
  return httpRequest;
95
95
  }
96
96
  const projectHeader = "X-Sanity-Project-ID";
97
- var getRequestOptions = function (config) {
97
+ function requestOptions(config) {
98
98
  let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
99
99
  const headers = {};
100
100
  const token = overrides.token || config.token;
@@ -113,7 +113,7 @@ var getRequestOptions = function (config) {
113
113
  json: true,
114
114
  withCredentials
115
115
  });
116
- };
116
+ }
117
117
  function getSelection(sel) {
118
118
  if (typeof sel === "string" || Array.isArray(sel)) {
119
119
  return {
@@ -189,7 +189,7 @@ const requestTag = tag => {
189
189
  }
190
190
  return tag;
191
191
  };
192
- var encodeQueryString = _ref => {
192
+ const encodeQueryString = _ref => {
193
193
  let {
194
194
  query,
195
195
  params = {},
@@ -794,7 +794,7 @@ function _requestObservable(client, httpRequest, options) {
794
794
  ...options.query
795
795
  };
796
796
  }
797
- const reqOptions = getRequestOptions(config, Object.assign({}, options, {
797
+ const reqOptions = requestOptions(config, Object.assign({}, options, {
798
798
  url: _getUrl(client, uri, useCdn)
799
799
  }));
800
800
  const request = new rxjs.Observable(subscriber =>
@@ -950,7 +950,7 @@ const BASE_URL = "https://www.sanity.io/help/";
950
950
  function generateHelpUrl(slug) {
951
951
  return BASE_URL + slug;
952
952
  }
953
- var once = fn => {
953
+ function once(fn) {
954
954
  let didCall = false;
955
955
  let returnValue;
956
956
  return function () {
@@ -961,7 +961,7 @@ var once = fn => {
961
961
  didCall = true;
962
962
  return returnValue;
963
963
  };
964
- };
964
+ }
965
965
  const createWarningPrinter = message =>
966
966
  // eslint-disable-next-line no-console
967
967
  once(function () {
@@ -973,6 +973,7 @@ once(function () {
973
973
  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."]);
974
974
  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.")]);
975
975
  const printNoApiVersionSpecifiedWarning = createWarningPrinter(["Using the Sanity client without specifying an API version is deprecated.", "See ".concat(generateHelpUrl("js-client-api-version"))]);
976
+ const printNoDefaultExport = createWarningPrinter(["The default export of @sanity/client has been deprecated. Use the named export `createClient` instead"]);
976
977
  const defaultCdnHost = "apicdn.sanity.io";
977
978
  const defaultConfig = {
978
979
  apiHost: "https://api.sanity.io",
@@ -1042,7 +1043,7 @@ var defaults = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj))
1042
1043
  target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
1043
1044
  return target;
1044
1045
  }, {});
1045
- var pick = (obj, props) => props.reduce((selection, prop) => {
1046
+ const pick = (obj, props) => props.reduce((selection, prop) => {
1046
1047
  if (typeof obj[prop] === "undefined") {
1047
1048
  return selection;
1048
1049
  }
@@ -1554,6 +1555,24 @@ const _ObservableSanityClient = class {
1554
1555
  request(options) {
1555
1556
  return _request(this, __privateGet(this, _httpRequest), options);
1556
1557
  }
1558
+ /**
1559
+ * Get a Sanity API URL for the URI provided
1560
+ *
1561
+ * @param uri - URI/path to build URL for
1562
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
1563
+ */
1564
+ getUrl(uri, canUseCdn) {
1565
+ return _getUrl(this, uri, canUseCdn);
1566
+ }
1567
+ /**
1568
+ * Get a Sanity API URL for the data operation and path provided
1569
+ *
1570
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
1571
+ * @param path - Path to append after the operation
1572
+ */
1573
+ getDataUrl(operation, path) {
1574
+ return _getDataUrl(this, operation, path);
1575
+ }
1557
1576
  };
1558
1577
  let ObservableSanityClient = _ObservableSanityClient;
1559
1578
  _clientConfig = new WeakMap();
@@ -1687,16 +1706,35 @@ const _SanityClient = class {
1687
1706
  dataRequest(endpoint, body, options) {
1688
1707
  return rxjs.lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
1689
1708
  }
1709
+ /**
1710
+ * Get a Sanity API URL for the URI provided
1711
+ *
1712
+ * @param uri - URI/path to build URL for
1713
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
1714
+ */
1715
+ getUrl(uri, canUseCdn) {
1716
+ return _getUrl(this, uri, canUseCdn);
1717
+ }
1718
+ /**
1719
+ * Get a Sanity API URL for the data operation and path provided
1720
+ *
1721
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
1722
+ * @param path - Path to append after the operation
1723
+ */
1724
+ getDataUrl(operation, path) {
1725
+ return _getDataUrl(this, operation, path);
1726
+ }
1690
1727
  };
1691
1728
  let SanityClient = _SanityClient;
1692
1729
  _clientConfig2 = new WeakMap();
1693
1730
  _httpRequest2 = new WeakMap();
1694
- function migrationNotice() {
1695
- throw new TypeError("The default export of @sanity/client has been deprecated. Use the named export `createClient` instead");
1696
- }
1697
1731
  const httpRequest = defineHttpRequest(envMiddleware);
1698
1732
  const requester = httpRequest.defaultRequester;
1699
1733
  const createClient = config => new SanityClient(httpRequest, config);
1734
+ function deprecatedCreateClient(config) {
1735
+ printNoDefaultExport();
1736
+ return new SanityClient(httpRequest, config);
1737
+ }
1700
1738
  exports.BasePatch = BasePatch;
1701
1739
  exports.BaseTransaction = BaseTransaction;
1702
1740
  exports.ClientError = ClientError;
@@ -1708,6 +1746,6 @@ exports.SanityClient = SanityClient;
1708
1746
  exports.ServerError = ServerError;
1709
1747
  exports.Transaction = Transaction;
1710
1748
  exports.createClient = createClient;
1711
- exports.default = migrationNotice;
1749
+ exports.default = deprecatedCreateClient;
1712
1750
  exports.requester = requester;
1713
1751
  //# sourceMappingURL=index.browser.cjs.map