@sanity/client 6.4.8 → 6.4.10-canary.2

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.
@@ -4,13 +4,13 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SanityClient = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- const isReactNative = typeof navigator === "undefined" ? false : navigator.product === "ReactNative";
8
- const defaultOptions$1 = {
9
- timeout: isReactNative ? 6e4 : 12e4
7
+ const isReactNative$1 = typeof navigator === "undefined" ? false : navigator.product === "ReactNative";
8
+ const defaultOptions$2 = {
9
+ timeout: isReactNative$1 ? 6e4 : 12e4
10
10
  };
11
- const processOptions = function processOptions2(opts) {
11
+ const processOptions$1 = function processOptions2(opts) {
12
12
  const options = {
13
- ...defaultOptions$1,
13
+ ...defaultOptions$2,
14
14
  ...(typeof opts === "string" ? {
15
15
  url: opts
16
16
  } : opts)
@@ -18,7 +18,7 @@
18
18
  const {
19
19
  searchParams
20
20
  } = new URL(options.url, "http://localhost");
21
- options.timeout = normalizeTimeout(options.timeout);
21
+ options.timeout = normalizeTimeout$1(options.timeout);
22
22
  if (options.query) {
23
23
  for (const [key, value] of Object.entries(options.query)) {
24
24
  if (value !== void 0) {
@@ -40,7 +40,7 @@
40
40
  options.method = options.body && !options.method ? "POST" : (options.method || "GET").toUpperCase();
41
41
  return options;
42
42
  };
43
- function normalizeTimeout(time) {
43
+ function normalizeTimeout$1(time) {
44
44
  if (time === false || time === 0) {
45
45
  return false;
46
46
  }
@@ -49,16 +49,16 @@
49
49
  }
50
50
  const delay = Number(time);
51
51
  if (isNaN(delay)) {
52
- return normalizeTimeout(defaultOptions$1.timeout);
52
+ return normalizeTimeout$1(defaultOptions$2.timeout);
53
53
  }
54
54
  return {
55
55
  connect: delay,
56
56
  socket: delay
57
57
  };
58
58
  }
59
- const validUrl = /^https?:\/\//i;
60
- const validateOptions = function validateOptions2(options) {
61
- if (!validUrl.test(options.url)) {
59
+ const validUrl$1 = /^https?:\/\//i;
60
+ const validateOptions$1 = function validateOptions2(options) {
61
+ if (!validUrl$1.test(options.url)) {
62
62
  throw new Error('"'.concat(options.url, '" is not a valid URL'));
63
63
  }
64
64
  };
@@ -147,8 +147,8 @@
147
147
  ware[name] = ware[name] || [];
148
148
  return ware;
149
149
  }, {
150
- processOptions: [processOptions],
151
- validateOptions: [validateOptions]
150
+ processOptions: [processOptions$1],
151
+ validateOptions: [validateOptions$1]
152
152
  });
153
153
  function request(opts) {
154
154
  const onResponse = (reqErr, res, ctx) => {
@@ -498,6 +498,8 @@
498
498
  };
499
499
  const environment = "browser";
500
500
 
501
+ var middleware_browser = {};
502
+
501
503
  var browser$3 = {exports: {}};
502
504
 
503
505
  /**
@@ -1217,6 +1219,75 @@
1217
1219
  };
1218
1220
  } (browser$3, browser$3.exports));
1219
1221
 
1222
+ var browserExports = browser$3.exports;
1223
+
1224
+ var defaultOptionsValidator41aa9136 = {};
1225
+
1226
+ const isReactNative = typeof navigator === "undefined" ? false : navigator.product === "ReactNative";
1227
+ const defaultOptions$1 = {
1228
+ timeout: isReactNative ? 6e4 : 12e4
1229
+ };
1230
+ const processOptions = function processOptions2(opts) {
1231
+ const options = {
1232
+ ...defaultOptions$1,
1233
+ ...(typeof opts === "string" ? {
1234
+ url: opts
1235
+ } : opts)
1236
+ };
1237
+ const {
1238
+ searchParams
1239
+ } = new URL(options.url, "http://localhost");
1240
+ options.timeout = normalizeTimeout(options.timeout);
1241
+ if (options.query) {
1242
+ for (const [key, value] of Object.entries(options.query)) {
1243
+ if (value !== void 0) {
1244
+ if (Array.isArray(value)) {
1245
+ for (const v of value) {
1246
+ searchParams.append(key, v);
1247
+ }
1248
+ } else {
1249
+ searchParams.append(key, value);
1250
+ }
1251
+ }
1252
+ }
1253
+ }
1254
+ const [url] = options.url.split("?");
1255
+ const search = searchParams.toString();
1256
+ if (search) {
1257
+ options.url = "".concat(url, "?").concat(search);
1258
+ }
1259
+ options.method = options.body && !options.method ? "POST" : (options.method || "GET").toUpperCase();
1260
+ return options;
1261
+ };
1262
+ function normalizeTimeout(time) {
1263
+ if (time === false || time === 0) {
1264
+ return false;
1265
+ }
1266
+ if (time.connect || time.socket) {
1267
+ return time;
1268
+ }
1269
+ const delay = Number(time);
1270
+ if (isNaN(delay)) {
1271
+ return normalizeTimeout(defaultOptions$1.timeout);
1272
+ }
1273
+ return {
1274
+ connect: delay,
1275
+ socket: delay
1276
+ };
1277
+ }
1278
+ const validUrl = /^https?:\/\//i;
1279
+ const validateOptions = function validateOptions2(options) {
1280
+ if (!validUrl.test(options.url)) {
1281
+ throw new Error('"'.concat(options.url, '" is not a valid URL'));
1282
+ }
1283
+ };
1284
+ defaultOptionsValidator41aa9136.processOptions = processOptions;
1285
+ defaultOptionsValidator41aa9136.validateOptions = validateOptions;
1286
+
1287
+ var isPlainObject$3 = {};
1288
+
1289
+ Object.defineProperty(isPlainObject$3, '__esModule', { value: true });
1290
+
1220
1291
  /*!
1221
1292
  * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
1222
1293
  *
@@ -1228,7 +1299,7 @@
1228
1299
  return Object.prototype.toString.call(o) === '[object Object]';
1229
1300
  }
1230
1301
 
1231
- function isPlainObject$1(o) {
1302
+ function isPlainObject$2(o) {
1232
1303
  var ctor,prot;
1233
1304
 
1234
1305
  if (isObject(o) === false) return false;
@@ -1250,6 +1321,184 @@
1250
1321
  return true;
1251
1322
  }
1252
1323
 
1324
+ isPlainObject$3.isPlainObject = isPlainObject$2;
1325
+
1326
+ Object.defineProperty(middleware_browser, '__esModule', {
1327
+ value: true
1328
+ });
1329
+ var debugIt = browserExports;
1330
+ var defaultOptionsValidator = defaultOptionsValidator41aa9136;
1331
+ var isPlainObject$1 = isPlainObject$3;
1332
+ function _interopDefaultCompat$1(e) {
1333
+ return e && typeof e === 'object' && 'default' in e ? e : {
1334
+ default: e
1335
+ };
1336
+ }
1337
+ var debugIt__default = /*#__PURE__*/_interopDefaultCompat$1(debugIt);
1338
+ function agent(opts) {
1339
+ return {};
1340
+ }
1341
+ const leadingSlash = /^\//;
1342
+ const trailingSlash = /\/$/;
1343
+ function base(baseUrl) {
1344
+ const baseUri = baseUrl.replace(trailingSlash, "");
1345
+ return {
1346
+ processOptions: options => {
1347
+ if (/^https?:\/\//i.test(options.url)) {
1348
+ return options;
1349
+ }
1350
+ const url = [baseUri, options.url.replace(leadingSlash, "")].join("/");
1351
+ return Object.assign({}, options, {
1352
+ url
1353
+ });
1354
+ }
1355
+ };
1356
+ }
1357
+ const SENSITIVE_HEADERS = ["cookie", "authorization"];
1358
+ const hasOwn = Object.prototype.hasOwnProperty;
1359
+ const redactKeys = (source, redacted) => {
1360
+ const target = {};
1361
+ for (const key in source) {
1362
+ if (hasOwn.call(source, key)) {
1363
+ target[key] = redacted.indexOf(key.toLowerCase()) > -1 ? "<redacted>" : source[key];
1364
+ }
1365
+ }
1366
+ return target;
1367
+ };
1368
+ function debug() {
1369
+ let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1370
+ const verbose = opts.verbose;
1371
+ const namespace = opts.namespace || "get-it";
1372
+ const defaultLogger = debugIt__default.default(namespace);
1373
+ const log = opts.log || defaultLogger;
1374
+ const shortCircuit = log === defaultLogger && !debugIt__default.default.enabled(namespace);
1375
+ let requestId = 0;
1376
+ return {
1377
+ processOptions: options => {
1378
+ options.debug = log;
1379
+ options.requestId = options.requestId || ++requestId;
1380
+ return options;
1381
+ },
1382
+ onRequest: event => {
1383
+ if (shortCircuit || !event) {
1384
+ return event;
1385
+ }
1386
+ const options = event.options;
1387
+ log("[%s] HTTP %s %s", options.requestId, options.method, options.url);
1388
+ if (verbose && options.body && typeof options.body === "string") {
1389
+ log("[%s] Request body: %s", options.requestId, options.body);
1390
+ }
1391
+ if (verbose && options.headers) {
1392
+ const headers = opts.redactSensitiveHeaders === false ? options.headers : redactKeys(options.headers, SENSITIVE_HEADERS);
1393
+ log("[%s] Request headers: %s", options.requestId, JSON.stringify(headers, null, 2));
1394
+ }
1395
+ return event;
1396
+ },
1397
+ onResponse: (res, context) => {
1398
+ if (shortCircuit || !res) {
1399
+ return res;
1400
+ }
1401
+ const reqId = context.options.requestId;
1402
+ log("[%s] Response code: %s %s", reqId, res.statusCode, res.statusMessage);
1403
+ if (verbose && res.body) {
1404
+ log("[%s] Response body: %s", reqId, stringifyBody$1(res));
1405
+ }
1406
+ return res;
1407
+ },
1408
+ onError: (err, context) => {
1409
+ const reqId = context.options.requestId;
1410
+ if (!err) {
1411
+ log("[%s] Error encountered, but handled by an earlier middleware", reqId);
1412
+ return err;
1413
+ }
1414
+ log("[%s] ERROR: %s", reqId, err.message);
1415
+ return err;
1416
+ }
1417
+ };
1418
+ }
1419
+ function stringifyBody$1(res) {
1420
+ const contentType = (res.headers["content-type"] || "").toLowerCase();
1421
+ const isJson = contentType.indexOf("application/json") !== -1;
1422
+ return isJson ? tryFormat(res.body) : res.body;
1423
+ }
1424
+ function tryFormat(body) {
1425
+ try {
1426
+ const parsed = typeof body === "string" ? JSON.parse(body) : body;
1427
+ return JSON.stringify(parsed, null, 2);
1428
+ } catch (err) {
1429
+ return body;
1430
+ }
1431
+ }
1432
+ function headers(_headers) {
1433
+ let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1434
+ return {
1435
+ processOptions: options => {
1436
+ const existing = options.headers || {};
1437
+ options.headers = opts.override ? Object.assign({}, existing, _headers) : Object.assign({}, _headers, existing);
1438
+ return options;
1439
+ }
1440
+ };
1441
+ }
1442
+ var __defProp$1$1 = Object.defineProperty;
1443
+ var __defNormalProp$1$1 = (obj, key, value) => key in obj ? __defProp$1$1(obj, key, {
1444
+ enumerable: true,
1445
+ configurable: true,
1446
+ writable: true,
1447
+ value
1448
+ }) : obj[key] = value;
1449
+ var __publicField$1$1 = (obj, key, value) => {
1450
+ __defNormalProp$1$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1451
+ return value;
1452
+ };
1453
+ class HttpError extends Error {
1454
+ constructor(res, ctx) {
1455
+ super();
1456
+ __publicField$1$1(this, "response");
1457
+ __publicField$1$1(this, "request");
1458
+ const truncatedUrl = res.url.length > 400 ? "".concat(res.url.slice(0, 399), "\u2026") : res.url;
1459
+ let msg = "".concat(res.method, "-request to ").concat(truncatedUrl, " resulted in ");
1460
+ msg += "HTTP ".concat(res.statusCode, " ").concat(res.statusMessage);
1461
+ this.message = msg.trim();
1462
+ this.response = res;
1463
+ this.request = ctx.options;
1464
+ }
1465
+ }
1466
+ function httpErrors() {
1467
+ return {
1468
+ onResponse: (res, ctx) => {
1469
+ const isHttpError = res.statusCode >= 400;
1470
+ if (!isHttpError) {
1471
+ return res;
1472
+ }
1473
+ throw new HttpError(res, ctx);
1474
+ }
1475
+ };
1476
+ }
1477
+ function injectResponse() {
1478
+ let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1479
+ if (typeof opts.inject !== "function") {
1480
+ throw new Error("`injectResponse` middleware requires a `inject` function");
1481
+ }
1482
+ const inject = function inject2(prevValue, event) {
1483
+ const response = opts.inject(event, prevValue);
1484
+ if (!response) {
1485
+ return prevValue;
1486
+ }
1487
+ const options = event.context.options;
1488
+ return {
1489
+ body: "",
1490
+ url: options.url,
1491
+ method: options.method,
1492
+ headers: {},
1493
+ statusCode: 200,
1494
+ statusMessage: "OK",
1495
+ ...response
1496
+ };
1497
+ };
1498
+ return {
1499
+ interceptRequest: inject
1500
+ };
1501
+ }
1253
1502
  const isBuffer = typeof Buffer === "undefined" ? () => false : obj => Buffer.isBuffer(obj);
1254
1503
  const serializeTypes = ["boolean", "string", "number"];
1255
1504
  function jsonRequest() {
@@ -1260,7 +1509,7 @@
1260
1509
  return options;
1261
1510
  }
1262
1511
  const isStream = typeof body.pipe === "function";
1263
- const shouldSerialize = !isStream && !isBuffer(body) && (serializeTypes.indexOf(typeof body) !== -1 || Array.isArray(body) || isPlainObject$1(body));
1512
+ const shouldSerialize = !isStream && !isBuffer(body) && (serializeTypes.indexOf(typeof body) !== -1 || Array.isArray(body) || isPlainObject$1.isPlainObject(body));
1264
1513
  if (!shouldSerialize) {
1265
1514
  return options;
1266
1515
  }
@@ -1300,13 +1549,41 @@
1300
1549
  }
1301
1550
  }
1302
1551
  }
1552
+ function isBrowserOptions(options) {
1553
+ return typeof options === "object" && options !== null && !("protocol" in options);
1554
+ }
1555
+ function mtls() {
1556
+ let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1557
+ if (!config.ca) {
1558
+ throw new Error('Required mtls option "ca" is missing');
1559
+ }
1560
+ if (!config.cert) {
1561
+ throw new Error('Required mtls option "cert" is missing');
1562
+ }
1563
+ if (!config.key) {
1564
+ throw new Error('Required mtls option "key" is missing');
1565
+ }
1566
+ return {
1567
+ finalizeOptions: options => {
1568
+ if (isBrowserOptions(options)) {
1569
+ return options;
1570
+ }
1571
+ const mtlsOpts = {
1572
+ cert: config.cert,
1573
+ key: config.key,
1574
+ ca: config.ca
1575
+ };
1576
+ return Object.assign({}, options, mtlsOpts);
1577
+ }
1578
+ };
1579
+ }
1303
1580
  let actualGlobal = {};
1304
1581
  if (typeof globalThis !== "undefined") {
1305
1582
  actualGlobal = globalThis;
1306
1583
  } else if (typeof window !== "undefined") {
1307
1584
  actualGlobal = window;
1308
- } else if (typeof global !== "undefined") {
1309
- actualGlobal = global;
1585
+ } else if (typeof commonjsGlobal !== "undefined") {
1586
+ actualGlobal = commonjsGlobal;
1310
1587
  } else if (typeof self !== "undefined") {
1311
1588
  actualGlobal = self;
1312
1589
  }
@@ -1376,6 +1653,35 @@
1376
1653
  __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1377
1654
  return value;
1378
1655
  };
1656
+ const promise = function () {
1657
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1658
+ const PromiseImplementation = options.implementation || Promise;
1659
+ if (!PromiseImplementation) {
1660
+ throw new Error("`Promise` is not available in global scope, and no implementation was passed");
1661
+ }
1662
+ return {
1663
+ onReturn: (channels, context) => new PromiseImplementation((resolve, reject) => {
1664
+ const cancel = context.options.cancelToken;
1665
+ if (cancel) {
1666
+ cancel.promise.then(reason => {
1667
+ channels.abort.publish(reason);
1668
+ reject(reason);
1669
+ });
1670
+ }
1671
+ channels.error.subscribe(reject);
1672
+ channels.response.subscribe(response => {
1673
+ resolve(options.onlyBody ? response.body : response);
1674
+ });
1675
+ setTimeout(() => {
1676
+ try {
1677
+ channels.request.publish(context);
1678
+ } catch (err) {
1679
+ reject(err);
1680
+ }
1681
+ }, 0);
1682
+ })
1683
+ };
1684
+ };
1379
1685
  class Cancel {
1380
1686
  constructor(message) {
1381
1687
  __publicField$4(this, "__CANCEL__", true);
@@ -1416,6 +1722,21 @@
1416
1722
  cancel
1417
1723
  };
1418
1724
  });
1725
+ let CancelToken = _CancelToken;
1726
+ const isCancel = value => !!(value && (value == null ? void 0 : value.__CANCEL__));
1727
+ promise.Cancel = Cancel;
1728
+ promise.CancelToken = CancelToken;
1729
+ promise.isCancel = isCancel;
1730
+ function proxy(_proxy) {
1731
+ if (_proxy !== false && (!_proxy || !_proxy.host)) {
1732
+ throw new Error("Proxy middleware takes an object of host, port and auth properties");
1733
+ }
1734
+ return {
1735
+ processOptions: options => Object.assign({
1736
+ proxy: _proxy
1737
+ }, options)
1738
+ };
1739
+ }
1419
1740
  var defaultShouldRetry = (err, attempt, options) => {
1420
1741
  if (options.method !== "GET" && options.method !== "HEAD") {
1421
1742
  return false;
@@ -1460,6 +1781,88 @@
1460
1781
  });
1461
1782
  };
1462
1783
  retry.shouldRetry = defaultShouldRetry;
1784
+ function encode(data) {
1785
+ const query = new URLSearchParams();
1786
+ const nest = (name, _value) => {
1787
+ const value = _value instanceof Set ? Array.from(_value) : _value;
1788
+ if (Array.isArray(value)) {
1789
+ if (value.length) {
1790
+ for (const index in value) {
1791
+ nest("".concat(name, "[").concat(index, "]"), value[index]);
1792
+ }
1793
+ } else {
1794
+ query.append("".concat(name, "[]"), "");
1795
+ }
1796
+ } else if (typeof value === "object" && value !== null) {
1797
+ for (const [key, obj] of Object.entries(value)) {
1798
+ nest("".concat(name, "[").concat(key, "]"), obj);
1799
+ }
1800
+ } else {
1801
+ query.append(name, value);
1802
+ }
1803
+ };
1804
+ for (const [key, value] of Object.entries(data)) {
1805
+ nest(key, value);
1806
+ }
1807
+ return query.toString();
1808
+ }
1809
+ function urlEncoded() {
1810
+ return {
1811
+ processOptions: options => {
1812
+ const body = options.body;
1813
+ if (!body) {
1814
+ return options;
1815
+ }
1816
+ const isStream = typeof body.pipe === "function";
1817
+ const shouldSerialize = !isStream && !isBuffer(body) && isPlainObject$1.isPlainObject(body);
1818
+ if (!shouldSerialize) {
1819
+ return options;
1820
+ }
1821
+ return {
1822
+ ...options,
1823
+ body: encode(options.body),
1824
+ headers: {
1825
+ ...options.headers,
1826
+ "Content-Type": "application/x-www-form-urlencoded"
1827
+ }
1828
+ };
1829
+ }
1830
+ };
1831
+ }
1832
+ function buildKeepAlive(agent) {
1833
+ return function keepAlive() {
1834
+ let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1835
+ const ms = config.ms || 1e3;
1836
+ const maxFree = config.maxFree || 256;
1837
+ const agentOptions = {
1838
+ keepAlive: true,
1839
+ keepAliveMsecs: ms,
1840
+ maxFreeSockets: maxFree
1841
+ };
1842
+ return agent(agentOptions);
1843
+ };
1844
+ }
1845
+ const keepAlive = buildKeepAlive(agent);
1846
+ middleware_browser.processOptions = defaultOptionsValidator.processOptions;
1847
+ middleware_browser.validateOptions = defaultOptionsValidator.validateOptions;
1848
+ middleware_browser.Cancel = Cancel;
1849
+ middleware_browser.CancelToken = CancelToken;
1850
+ middleware_browser.agent = agent;
1851
+ middleware_browser.base = base;
1852
+ middleware_browser.debug = debug;
1853
+ middleware_browser.headers = headers;
1854
+ middleware_browser.httpErrors = httpErrors;
1855
+ middleware_browser.injectResponse = injectResponse;
1856
+ var jsonRequest_1 = middleware_browser.jsonRequest = jsonRequest;
1857
+ var jsonResponse_1 = middleware_browser.jsonResponse = jsonResponse;
1858
+ middleware_browser.keepAlive = keepAlive;
1859
+ middleware_browser.mtls = mtls;
1860
+ var observable_1 = middleware_browser.observable = observable$1;
1861
+ var progress_1 = middleware_browser.progress = progress;
1862
+ middleware_browser.promise = promise;
1863
+ middleware_browser.proxy = proxy;
1864
+ var retry_1 = middleware_browser.retry = retry;
1865
+ middleware_browser.urlEncoded = urlEncoded;
1463
1866
 
1464
1867
  /******************************************************************************
1465
1868
  Copyright (c) Microsoft Corporation.
@@ -2255,13 +2658,13 @@
2255
2658
  maxRetries = 5,
2256
2659
  retryDelay
2257
2660
  } = _ref;
2258
- const request = getIt([maxRetries > 0 ? retry({
2661
+ const request = getIt([maxRetries > 0 ? retry_1({
2259
2662
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2260
2663
  retryDelay,
2261
2664
  // This option is typed incorrectly in get-it.
2262
2665
  maxRetries,
2263
2666
  shouldRetry
2264
- }) : {}, ...envMiddleware, printWarnings, jsonRequest(), jsonResponse(), progress(), httpError, observable$1({
2667
+ }) : {}, ...envMiddleware, printWarnings, jsonRequest_1(), jsonResponse_1(), progress_1(), httpError, observable_1({
2265
2668
  implementation: Observable
2266
2669
  })]);
2267
2670
  function httpRequest(options) {
@@ -2280,7 +2683,7 @@
2280
2683
  const isQuery = uri.startsWith("/data/query");
2281
2684
  const isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
2282
2685
  if ((isSafe || isQuery) && isRetriableResponse) return true;
2283
- return retry.shouldRetry(err, attempt, options);
2686
+ return retry_1.shouldRetry(err, attempt, options);
2284
2687
  }
2285
2688
  const BASE_URL = "https://www.sanity.io/help/";
2286
2689
  function generateHelpUrl(slug) {
@@ -2365,6 +2768,7 @@
2365
2768
  return console.warn(message.join(" "), ...args);
2366
2769
  });
2367
2770
  const printCdnWarning = createWarningPrinter(["Since you haven't set a value for `useCdn`, we will deliver content using our", "global, edge-cached API-CDN. If you wish to have content delivered faster, set", "`useCdn: false` to use the Live API. Note: You may incur higher costs using the live API."]);
2771
+ const printCdnPreviewDraftsWarning = createWarningPrinter(["The Sanity client is configured with the `perspective` set to `previewDrafts`, which doesn't support the API-CDN.", "The Live API will be used instead. Set `useCdn: false` in your configuration to hide this warning."]);
2368
2772
  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.")]);
2369
2773
  const printNoApiVersionSpecifiedWarning = createWarningPrinter(["Using the Sanity client without specifying an API version is deprecated.", "See ".concat(generateHelpUrl("js-client-api-version"))]);
2370
2774
  const printNoDefaultExport = createWarningPrinter(["The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."]);
@@ -3145,7 +3549,7 @@
3145
3549
  const uri = options.url || options.uri;
3146
3550
  const config = client.config();
3147
3551
  const canUseCdn = typeof options.canUseCdn === "undefined" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn;
3148
- const useCdn = config.useCdn && canUseCdn;
3552
+ let useCdn = config.useCdn && canUseCdn;
3149
3553
  const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
3150
3554
  if (tag) {
3151
3555
  options.query = {
@@ -3167,6 +3571,10 @@
3167
3571
  perspective,
3168
3572
  ...options.query
3169
3573
  };
3574
+ if (perspective === "previewDrafts" && useCdn) {
3575
+ useCdn = false;
3576
+ printCdnPreviewDraftsWarning();
3577
+ }
3170
3578
  }
3171
3579
  }
3172
3580
  const reqOptions = requestOptions(config, Object.assign({}, options, {