@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 +16 -72
- package/dist/index.browser.cjs +49 -11
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +49 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +50 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +156 -128
- package/dist/index.js +50 -12
- package/dist/index.js.map +1 -1
- package/package.json +16 -16
- package/src/SanityClient.ts +120 -80
- package/src/assets/AssetsClient.ts +4 -4
- package/src/config.ts +1 -1
- package/src/data/dataMethods.ts +31 -31
- package/src/data/encodeQueryString.ts +3 -3
- package/src/data/listen.ts +11 -11
- package/src/data/patch.ts +18 -18
- package/src/data/transaction.ts +13 -15
- package/src/generateHelpUrl.ts +1 -1
- package/src/http/errors.ts +7 -7
- package/src/http/request.ts +4 -4
- package/src/http/requestOptions.ts +3 -3
- package/src/index.browser.ts +9 -1
- package/src/index.ts +9 -1
- package/src/types.ts +27 -28
- package/src/util/defaults.ts +3 -3
- package/src/util/getSelection.ts +1 -1
- package/src/util/once.ts +4 -4
- package/src/util/pick.ts +3 -3
- package/src/validators.ts +4 -4
- package/src/warnings.ts +8 -4
- package/umd/sanityClient.js +49 -11
- package/umd/sanityClient.min.js +3 -3
- package/src/migrationNotice.ts +0 -9
package/dist/index.browser.js
CHANGED
|
@@ -83,7 +83,7 @@ function defineHttpRequest(envMiddleware) {
|
|
|
83
83
|
return httpRequest;
|
|
84
84
|
}
|
|
85
85
|
const projectHeader = "X-Sanity-Project-ID";
|
|
86
|
-
|
|
86
|
+
function requestOptions(config) {
|
|
87
87
|
let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
88
88
|
const headers = {};
|
|
89
89
|
const token = overrides.token || config.token;
|
|
@@ -102,7 +102,7 @@ var getRequestOptions = function (config) {
|
|
|
102
102
|
json: true,
|
|
103
103
|
withCredentials
|
|
104
104
|
});
|
|
105
|
-
}
|
|
105
|
+
}
|
|
106
106
|
function getSelection(sel) {
|
|
107
107
|
if (typeof sel === "string" || Array.isArray(sel)) {
|
|
108
108
|
return {
|
|
@@ -178,7 +178,7 @@ const requestTag = tag => {
|
|
|
178
178
|
}
|
|
179
179
|
return tag;
|
|
180
180
|
};
|
|
181
|
-
|
|
181
|
+
const encodeQueryString = _ref => {
|
|
182
182
|
let {
|
|
183
183
|
query,
|
|
184
184
|
params = {},
|
|
@@ -783,7 +783,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
783
783
|
...options.query
|
|
784
784
|
};
|
|
785
785
|
}
|
|
786
|
-
const reqOptions =
|
|
786
|
+
const reqOptions = requestOptions(config, Object.assign({}, options, {
|
|
787
787
|
url: _getUrl(client, uri, useCdn)
|
|
788
788
|
}));
|
|
789
789
|
const request = new Observable(subscriber =>
|
|
@@ -939,7 +939,7 @@ const BASE_URL = "https://www.sanity.io/help/";
|
|
|
939
939
|
function generateHelpUrl(slug) {
|
|
940
940
|
return BASE_URL + slug;
|
|
941
941
|
}
|
|
942
|
-
|
|
942
|
+
function once(fn) {
|
|
943
943
|
let didCall = false;
|
|
944
944
|
let returnValue;
|
|
945
945
|
return function () {
|
|
@@ -950,7 +950,7 @@ var once = fn => {
|
|
|
950
950
|
didCall = true;
|
|
951
951
|
return returnValue;
|
|
952
952
|
};
|
|
953
|
-
}
|
|
953
|
+
}
|
|
954
954
|
const createWarningPrinter = message =>
|
|
955
955
|
// eslint-disable-next-line no-console
|
|
956
956
|
once(function () {
|
|
@@ -962,6 +962,7 @@ once(function () {
|
|
|
962
962
|
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."]);
|
|
963
963
|
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.")]);
|
|
964
964
|
const printNoApiVersionSpecifiedWarning = createWarningPrinter(["Using the Sanity client without specifying an API version is deprecated.", "See ".concat(generateHelpUrl("js-client-api-version"))]);
|
|
965
|
+
const printNoDefaultExport = createWarningPrinter(["The default export of @sanity/client has been deprecated. Use the named export `createClient` instead"]);
|
|
965
966
|
const defaultCdnHost = "apicdn.sanity.io";
|
|
966
967
|
const defaultConfig = {
|
|
967
968
|
apiHost: "https://api.sanity.io",
|
|
@@ -1031,7 +1032,7 @@ var defaults = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj))
|
|
|
1031
1032
|
target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
|
|
1032
1033
|
return target;
|
|
1033
1034
|
}, {});
|
|
1034
|
-
|
|
1035
|
+
const pick = (obj, props) => props.reduce((selection, prop) => {
|
|
1035
1036
|
if (typeof obj[prop] === "undefined") {
|
|
1036
1037
|
return selection;
|
|
1037
1038
|
}
|
|
@@ -1543,6 +1544,24 @@ const _ObservableSanityClient = class {
|
|
|
1543
1544
|
request(options) {
|
|
1544
1545
|
return _request(this, __privateGet(this, _httpRequest), options);
|
|
1545
1546
|
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Get a Sanity API URL for the URI provided
|
|
1549
|
+
*
|
|
1550
|
+
* @param uri - URI/path to build URL for
|
|
1551
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1552
|
+
*/
|
|
1553
|
+
getUrl(uri, canUseCdn) {
|
|
1554
|
+
return _getUrl(this, uri, canUseCdn);
|
|
1555
|
+
}
|
|
1556
|
+
/**
|
|
1557
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1558
|
+
*
|
|
1559
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1560
|
+
* @param path - Path to append after the operation
|
|
1561
|
+
*/
|
|
1562
|
+
getDataUrl(operation, path) {
|
|
1563
|
+
return _getDataUrl(this, operation, path);
|
|
1564
|
+
}
|
|
1546
1565
|
};
|
|
1547
1566
|
let ObservableSanityClient = _ObservableSanityClient;
|
|
1548
1567
|
_clientConfig = new WeakMap();
|
|
@@ -1676,15 +1695,34 @@ const _SanityClient = class {
|
|
|
1676
1695
|
dataRequest(endpoint, body, options) {
|
|
1677
1696
|
return lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
|
|
1678
1697
|
}
|
|
1698
|
+
/**
|
|
1699
|
+
* Get a Sanity API URL for the URI provided
|
|
1700
|
+
*
|
|
1701
|
+
* @param uri - URI/path to build URL for
|
|
1702
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1703
|
+
*/
|
|
1704
|
+
getUrl(uri, canUseCdn) {
|
|
1705
|
+
return _getUrl(this, uri, canUseCdn);
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1709
|
+
*
|
|
1710
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1711
|
+
* @param path - Path to append after the operation
|
|
1712
|
+
*/
|
|
1713
|
+
getDataUrl(operation, path) {
|
|
1714
|
+
return _getDataUrl(this, operation, path);
|
|
1715
|
+
}
|
|
1679
1716
|
};
|
|
1680
1717
|
let SanityClient = _SanityClient;
|
|
1681
1718
|
_clientConfig2 = new WeakMap();
|
|
1682
1719
|
_httpRequest2 = new WeakMap();
|
|
1683
|
-
function migrationNotice() {
|
|
1684
|
-
throw new TypeError("The default export of @sanity/client has been deprecated. Use the named export `createClient` instead");
|
|
1685
|
-
}
|
|
1686
1720
|
const httpRequest = defineHttpRequest(envMiddleware);
|
|
1687
1721
|
const requester = httpRequest.defaultRequester;
|
|
1688
1722
|
const createClient = config => new SanityClient(httpRequest, config);
|
|
1689
|
-
|
|
1723
|
+
function deprecatedCreateClient(config) {
|
|
1724
|
+
printNoDefaultExport();
|
|
1725
|
+
return new SanityClient(httpRequest, config);
|
|
1726
|
+
}
|
|
1727
|
+
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, deprecatedCreateClient as default, requester };
|
|
1690
1728
|
//# sourceMappingURL=index.browser.js.map
|