@sanity/client 6.4.10-dev.0 → 6.4.11
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.browser.cjs +7 -6
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +7 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +8 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +192 -92
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/package.json +12 -14
- package/src/SanityClient.ts +61 -6
- package/src/data/listen.ts +5 -5
- package/src/types.ts +169 -80
- package/umd/sanityClient.js +27 -429
- package/umd/sanityClient.min.js +3 -3
package/umd/sanityClient.js
CHANGED
|
@@ -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
|
|
8
|
-
const defaultOptions$
|
|
9
|
-
timeout: isReactNative
|
|
7
|
+
const isReactNative = typeof navigator === "undefined" ? false : navigator.product === "ReactNative";
|
|
8
|
+
const defaultOptions$1 = {
|
|
9
|
+
timeout: isReactNative ? 6e4 : 12e4
|
|
10
10
|
};
|
|
11
|
-
const processOptions
|
|
11
|
+
const processOptions = function processOptions2(opts) {
|
|
12
12
|
const options = {
|
|
13
|
-
...defaultOptions$
|
|
13
|
+
...defaultOptions$1,
|
|
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
|
|
21
|
+
options.timeout = normalizeTimeout(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
|
|
43
|
+
function normalizeTimeout(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
|
|
52
|
+
return normalizeTimeout(defaultOptions$1.timeout);
|
|
53
53
|
}
|
|
54
54
|
return {
|
|
55
55
|
connect: delay,
|
|
56
56
|
socket: delay
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
const validUrl
|
|
60
|
-
const validateOptions
|
|
61
|
-
if (!validUrl
|
|
59
|
+
const validUrl = /^https?:\/\//i;
|
|
60
|
+
const validateOptions = function validateOptions2(options) {
|
|
61
|
+
if (!validUrl.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],
|
|
151
|
+
validateOptions: [validateOptions]
|
|
152
152
|
});
|
|
153
153
|
function request(opts) {
|
|
154
154
|
const onResponse = (reqErr, res, ctx) => {
|
|
@@ -498,8 +498,6 @@
|
|
|
498
498
|
};
|
|
499
499
|
const environment = "browser";
|
|
500
500
|
|
|
501
|
-
var middleware_browser = {};
|
|
502
|
-
|
|
503
501
|
var browser$3 = {exports: {}};
|
|
504
502
|
|
|
505
503
|
/**
|
|
@@ -1219,75 +1217,6 @@
|
|
|
1219
1217
|
};
|
|
1220
1218
|
} (browser$3, browser$3.exports));
|
|
1221
1219
|
|
|
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
|
-
|
|
1291
1220
|
/*!
|
|
1292
1221
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
1293
1222
|
*
|
|
@@ -1299,7 +1228,7 @@
|
|
|
1299
1228
|
return Object.prototype.toString.call(o) === '[object Object]';
|
|
1300
1229
|
}
|
|
1301
1230
|
|
|
1302
|
-
function isPlainObject$
|
|
1231
|
+
function isPlainObject$1(o) {
|
|
1303
1232
|
var ctor,prot;
|
|
1304
1233
|
|
|
1305
1234
|
if (isObject(o) === false) return false;
|
|
@@ -1321,184 +1250,6 @@
|
|
|
1321
1250
|
return true;
|
|
1322
1251
|
}
|
|
1323
1252
|
|
|
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
|
-
}
|
|
1502
1253
|
const isBuffer = typeof Buffer === "undefined" ? () => false : obj => Buffer.isBuffer(obj);
|
|
1503
1254
|
const serializeTypes = ["boolean", "string", "number"];
|
|
1504
1255
|
function jsonRequest() {
|
|
@@ -1509,7 +1260,7 @@
|
|
|
1509
1260
|
return options;
|
|
1510
1261
|
}
|
|
1511
1262
|
const isStream = typeof body.pipe === "function";
|
|
1512
|
-
const shouldSerialize = !isStream && !isBuffer(body) && (serializeTypes.indexOf(typeof body) !== -1 || Array.isArray(body) || isPlainObject$1
|
|
1263
|
+
const shouldSerialize = !isStream && !isBuffer(body) && (serializeTypes.indexOf(typeof body) !== -1 || Array.isArray(body) || isPlainObject$1(body));
|
|
1513
1264
|
if (!shouldSerialize) {
|
|
1514
1265
|
return options;
|
|
1515
1266
|
}
|
|
@@ -1549,41 +1300,13 @@
|
|
|
1549
1300
|
}
|
|
1550
1301
|
}
|
|
1551
1302
|
}
|
|
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
|
-
}
|
|
1580
1303
|
let actualGlobal = {};
|
|
1581
1304
|
if (typeof globalThis !== "undefined") {
|
|
1582
1305
|
actualGlobal = globalThis;
|
|
1583
1306
|
} else if (typeof window !== "undefined") {
|
|
1584
1307
|
actualGlobal = window;
|
|
1585
|
-
} else if (typeof
|
|
1586
|
-
actualGlobal =
|
|
1308
|
+
} else if (typeof global !== "undefined") {
|
|
1309
|
+
actualGlobal = global;
|
|
1587
1310
|
} else if (typeof self !== "undefined") {
|
|
1588
1311
|
actualGlobal = self;
|
|
1589
1312
|
}
|
|
@@ -1653,35 +1376,6 @@
|
|
|
1653
1376
|
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1654
1377
|
return value;
|
|
1655
1378
|
};
|
|
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
|
-
};
|
|
1685
1379
|
class Cancel {
|
|
1686
1380
|
constructor(message) {
|
|
1687
1381
|
__publicField$4(this, "__CANCEL__", true);
|
|
@@ -1722,21 +1416,6 @@
|
|
|
1722
1416
|
cancel
|
|
1723
1417
|
};
|
|
1724
1418
|
});
|
|
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
|
-
}
|
|
1740
1419
|
var defaultShouldRetry = (err, attempt, options) => {
|
|
1741
1420
|
if (options.method !== "GET" && options.method !== "HEAD") {
|
|
1742
1421
|
return false;
|
|
@@ -1781,88 +1460,6 @@
|
|
|
1781
1460
|
});
|
|
1782
1461
|
};
|
|
1783
1462
|
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;
|
|
1866
1463
|
|
|
1867
1464
|
/******************************************************************************
|
|
1868
1465
|
Copyright (c) Microsoft Corporation.
|
|
@@ -2658,13 +2255,13 @@
|
|
|
2658
2255
|
maxRetries = 5,
|
|
2659
2256
|
retryDelay
|
|
2660
2257
|
} = _ref;
|
|
2661
|
-
const request = getIt([maxRetries > 0 ?
|
|
2258
|
+
const request = getIt([maxRetries > 0 ? retry({
|
|
2662
2259
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2663
2260
|
retryDelay,
|
|
2664
2261
|
// This option is typed incorrectly in get-it.
|
|
2665
2262
|
maxRetries,
|
|
2666
2263
|
shouldRetry
|
|
2667
|
-
}) : {}, ...envMiddleware, printWarnings,
|
|
2264
|
+
}) : {}, ...envMiddleware, printWarnings, jsonRequest(), jsonResponse(), progress(), httpError, observable$1({
|
|
2668
2265
|
implementation: Observable
|
|
2669
2266
|
})]);
|
|
2670
2267
|
function httpRequest(options) {
|
|
@@ -2683,7 +2280,7 @@
|
|
|
2683
2280
|
const isQuery = uri.startsWith("/data/query");
|
|
2684
2281
|
const isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
2685
2282
|
if ((isSafe || isQuery) && isRetriableResponse) return true;
|
|
2686
|
-
return
|
|
2283
|
+
return retry.shouldRetry(err, attempt, options);
|
|
2687
2284
|
}
|
|
2688
2285
|
const BASE_URL = "https://www.sanity.io/help/";
|
|
2689
2286
|
function generateHelpUrl(slug) {
|
|
@@ -4245,11 +3842,12 @@
|
|
|
4245
3842
|
/**
|
|
4246
3843
|
* Create a new buildable patch of operations to perform
|
|
4247
3844
|
*
|
|
4248
|
-
* @param
|
|
3845
|
+
* @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
|
|
4249
3846
|
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
3847
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
4250
3848
|
*/
|
|
4251
|
-
patch(
|
|
4252
|
-
return new ObservablePatch(
|
|
3849
|
+
patch(selection, operations) {
|
|
3850
|
+
return new ObservablePatch(selection, operations, this);
|
|
4253
3851
|
}
|
|
4254
3852
|
/**
|
|
4255
3853
|
* Create a new transaction of mutations
|
|
@@ -4260,9 +3858,8 @@
|
|
|
4260
3858
|
return new ObservableTransaction(operations, this);
|
|
4261
3859
|
}
|
|
4262
3860
|
/**
|
|
4263
|
-
*
|
|
3861
|
+
* Perform an HTTP request against the Sanity API
|
|
4264
3862
|
*
|
|
4265
|
-
* @deprecated Use your own request library!
|
|
4266
3863
|
* @param options - Request options
|
|
4267
3864
|
*/
|
|
4268
3865
|
request(options) {
|
|
@@ -4393,8 +3990,9 @@
|
|
|
4393
3990
|
/**
|
|
4394
3991
|
* Create a new buildable patch of operations to perform
|
|
4395
3992
|
*
|
|
4396
|
-
* @param
|
|
3993
|
+
* @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
|
|
4397
3994
|
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
3995
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
4398
3996
|
*/
|
|
4399
3997
|
patch(documentId, operations) {
|
|
4400
3998
|
return new Patch(documentId, operations, this);
|