@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.cjs
CHANGED
|
@@ -15,7 +15,7 @@ function _interopDefaultCompat(e) {
|
|
|
15
15
|
}
|
|
16
16
|
var polyfilledEventSource__default = /*#__PURE__*/_interopDefaultCompat(polyfilledEventSource);
|
|
17
17
|
var name = "@sanity/client";
|
|
18
|
-
var version = "5.1
|
|
18
|
+
var version = "5.2.1";
|
|
19
19
|
const middleware = [middleware$1.debug({
|
|
20
20
|
verbose: true,
|
|
21
21
|
namespace: "sanity:client"
|
|
@@ -103,7 +103,7 @@ function defineHttpRequest(envMiddleware) {
|
|
|
103
103
|
return httpRequest;
|
|
104
104
|
}
|
|
105
105
|
const projectHeader = "X-Sanity-Project-ID";
|
|
106
|
-
|
|
106
|
+
function requestOptions(config) {
|
|
107
107
|
let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
108
108
|
const headers = {};
|
|
109
109
|
const token = overrides.token || config.token;
|
|
@@ -122,7 +122,7 @@ var getRequestOptions = function (config) {
|
|
|
122
122
|
json: true,
|
|
123
123
|
withCredentials
|
|
124
124
|
});
|
|
125
|
-
}
|
|
125
|
+
}
|
|
126
126
|
function getSelection(sel) {
|
|
127
127
|
if (typeof sel === "string" || Array.isArray(sel)) {
|
|
128
128
|
return {
|
|
@@ -198,7 +198,7 @@ const requestTag = tag => {
|
|
|
198
198
|
}
|
|
199
199
|
return tag;
|
|
200
200
|
};
|
|
201
|
-
|
|
201
|
+
const encodeQueryString = _ref => {
|
|
202
202
|
let {
|
|
203
203
|
query,
|
|
204
204
|
params = {},
|
|
@@ -803,7 +803,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
803
803
|
...options.query
|
|
804
804
|
};
|
|
805
805
|
}
|
|
806
|
-
const reqOptions =
|
|
806
|
+
const reqOptions = requestOptions(config, Object.assign({}, options, {
|
|
807
807
|
url: _getUrl(client, uri, useCdn)
|
|
808
808
|
}));
|
|
809
809
|
const request = new rxjs.Observable(subscriber =>
|
|
@@ -959,7 +959,7 @@ const BASE_URL = "https://www.sanity.io/help/";
|
|
|
959
959
|
function generateHelpUrl(slug) {
|
|
960
960
|
return BASE_URL + slug;
|
|
961
961
|
}
|
|
962
|
-
|
|
962
|
+
function once(fn) {
|
|
963
963
|
let didCall = false;
|
|
964
964
|
let returnValue;
|
|
965
965
|
return function () {
|
|
@@ -970,7 +970,7 @@ var once = fn => {
|
|
|
970
970
|
didCall = true;
|
|
971
971
|
return returnValue;
|
|
972
972
|
};
|
|
973
|
-
}
|
|
973
|
+
}
|
|
974
974
|
const createWarningPrinter = message =>
|
|
975
975
|
// eslint-disable-next-line no-console
|
|
976
976
|
once(function () {
|
|
@@ -982,6 +982,7 @@ once(function () {
|
|
|
982
982
|
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."]);
|
|
983
983
|
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.")]);
|
|
984
984
|
const printNoApiVersionSpecifiedWarning = createWarningPrinter(["Using the Sanity client without specifying an API version is deprecated.", "See ".concat(generateHelpUrl("js-client-api-version"))]);
|
|
985
|
+
const printNoDefaultExport = createWarningPrinter(["The default export of @sanity/client has been deprecated. Use the named export `createClient` instead"]);
|
|
985
986
|
const defaultCdnHost = "apicdn.sanity.io";
|
|
986
987
|
const defaultConfig = {
|
|
987
988
|
apiHost: "https://api.sanity.io",
|
|
@@ -1051,7 +1052,7 @@ var defaults = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj))
|
|
|
1051
1052
|
target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
|
|
1052
1053
|
return target;
|
|
1053
1054
|
}, {});
|
|
1054
|
-
|
|
1055
|
+
const pick = (obj, props) => props.reduce((selection, prop) => {
|
|
1055
1056
|
if (typeof obj[prop] === "undefined") {
|
|
1056
1057
|
return selection;
|
|
1057
1058
|
}
|
|
@@ -1563,6 +1564,24 @@ const _ObservableSanityClient = class {
|
|
|
1563
1564
|
request(options) {
|
|
1564
1565
|
return _request(this, __privateGet(this, _httpRequest), options);
|
|
1565
1566
|
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Get a Sanity API URL for the URI provided
|
|
1569
|
+
*
|
|
1570
|
+
* @param uri - URI/path to build URL for
|
|
1571
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1572
|
+
*/
|
|
1573
|
+
getUrl(uri, canUseCdn) {
|
|
1574
|
+
return _getUrl(this, uri, canUseCdn);
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1578
|
+
*
|
|
1579
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1580
|
+
* @param path - Path to append after the operation
|
|
1581
|
+
*/
|
|
1582
|
+
getDataUrl(operation, path) {
|
|
1583
|
+
return _getDataUrl(this, operation, path);
|
|
1584
|
+
}
|
|
1566
1585
|
};
|
|
1567
1586
|
let ObservableSanityClient = _ObservableSanityClient;
|
|
1568
1587
|
_clientConfig = new WeakMap();
|
|
@@ -1696,16 +1715,35 @@ const _SanityClient = class {
|
|
|
1696
1715
|
dataRequest(endpoint, body, options) {
|
|
1697
1716
|
return rxjs.lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
|
|
1698
1717
|
}
|
|
1718
|
+
/**
|
|
1719
|
+
* Get a Sanity API URL for the URI provided
|
|
1720
|
+
*
|
|
1721
|
+
* @param uri - URI/path to build URL for
|
|
1722
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1723
|
+
*/
|
|
1724
|
+
getUrl(uri, canUseCdn) {
|
|
1725
|
+
return _getUrl(this, uri, canUseCdn);
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1729
|
+
*
|
|
1730
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1731
|
+
* @param path - Path to append after the operation
|
|
1732
|
+
*/
|
|
1733
|
+
getDataUrl(operation, path) {
|
|
1734
|
+
return _getDataUrl(this, operation, path);
|
|
1735
|
+
}
|
|
1699
1736
|
};
|
|
1700
1737
|
let SanityClient = _SanityClient;
|
|
1701
1738
|
_clientConfig2 = new WeakMap();
|
|
1702
1739
|
_httpRequest2 = new WeakMap();
|
|
1703
|
-
function migrationNotice() {
|
|
1704
|
-
throw new TypeError("The default export of @sanity/client has been deprecated. Use the named export `createClient` instead");
|
|
1705
|
-
}
|
|
1706
1740
|
const httpRequest = defineHttpRequest(middleware);
|
|
1707
1741
|
const requester = httpRequest.defaultRequester;
|
|
1708
1742
|
const createClient = config => new SanityClient(httpRequest, config);
|
|
1743
|
+
function deprecatedCreateClient(config) {
|
|
1744
|
+
printNoDefaultExport();
|
|
1745
|
+
return new SanityClient(httpRequest, config);
|
|
1746
|
+
}
|
|
1709
1747
|
exports.BasePatch = BasePatch;
|
|
1710
1748
|
exports.BaseTransaction = BaseTransaction;
|
|
1711
1749
|
exports.ClientError = ClientError;
|
|
@@ -1717,6 +1755,6 @@ exports.SanityClient = SanityClient;
|
|
|
1717
1755
|
exports.ServerError = ServerError;
|
|
1718
1756
|
exports.Transaction = Transaction;
|
|
1719
1757
|
exports.createClient = createClient;
|
|
1720
|
-
exports.default =
|
|
1758
|
+
exports.default = deprecatedCreateClient;
|
|
1721
1759
|
exports.requester = requester;
|
|
1722
1760
|
//# sourceMappingURL=index.cjs.map
|