@sanity/client 6.18.3 → 6.19.0
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 +34 -2
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +224 -0
- package/dist/index.browser.d.ts +224 -0
- package/dist/index.browser.js +34 -2
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +35 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +224 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.js +35 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/SanityClient.ts +31 -0
- package/src/data/dataMethods.ts +31 -2
- package/src/http/errors.ts +11 -2
- package/src/types.ts +223 -0
- package/umd/sanityClient.js +34 -2
- package/umd/sanityClient.min.js +2 -2
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ function extractErrorProps(res) {
|
|
|
42
42
|
};
|
|
43
43
|
if (body.error && body.message)
|
|
44
44
|
return props.message = `${body.error} - ${body.message}`, props;
|
|
45
|
-
if (isMutationError(body)) {
|
|
45
|
+
if (isMutationError(body) || isActionError(body)) {
|
|
46
46
|
const allItems = body.error.items || [], items = allItems.slice(0, 5).map((item) => {
|
|
47
47
|
var _a;
|
|
48
48
|
return (_a = item.error) == null ? void 0 : _a.description;
|
|
@@ -58,6 +58,9 @@ function extractErrorProps(res) {
|
|
|
58
58
|
function isMutationError(body) {
|
|
59
59
|
return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "mutationError" && typeof body.error.description == "string";
|
|
60
60
|
}
|
|
61
|
+
function isActionError(body) {
|
|
62
|
+
return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "actionError" && typeof body.error.description == "string";
|
|
63
|
+
}
|
|
61
64
|
function isPlainObject(obj) {
|
|
62
65
|
return typeof obj == "object" && obj !== null && !Array.isArray(obj);
|
|
63
66
|
}
|
|
@@ -691,8 +694,18 @@ function _mutate(client, httpRequest, mutations, options) {
|
|
|
691
694
|
const muts = Array.isArray(mut) ? mut : [mut], transactionId = options && options.transactionId || void 0;
|
|
692
695
|
return _dataRequest(client, httpRequest, "mutate", { mutations: muts, transactionId }, options);
|
|
693
696
|
}
|
|
697
|
+
function _action(client, httpRequest, actions, options) {
|
|
698
|
+
const acts = Array.isArray(actions) ? actions : [actions], transactionId = options && options.transactionId || void 0, skipCrossDatasetReferenceValidation = options && options.skipCrossDatasetReferenceValidation || void 0, dryRun = options && options.dryRun || void 0;
|
|
699
|
+
return _dataRequest(
|
|
700
|
+
client,
|
|
701
|
+
httpRequest,
|
|
702
|
+
"actions",
|
|
703
|
+
{ actions: acts, transactionId, skipCrossDatasetReferenceValidation, dryRun },
|
|
704
|
+
options
|
|
705
|
+
);
|
|
706
|
+
}
|
|
694
707
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
695
|
-
const isMutation = endpoint === "mutate", isQuery = endpoint === "query", strQuery = isMutation ? "" : encodeQueryString(body), useGet = !isMutation && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
|
|
708
|
+
const isMutation = endpoint === "mutate", isAction = endpoint === "actions", isQuery = endpoint === "query", strQuery = isMutation || isAction ? "" : encodeQueryString(body), useGet = !isMutation && !isAction && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
|
|
696
709
|
method: useGet ? "GET" : "POST",
|
|
697
710
|
uri,
|
|
698
711
|
json: !0,
|
|
@@ -1304,6 +1317,15 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1304
1317
|
transaction(operations) {
|
|
1305
1318
|
return new ObservableTransaction(operations, this);
|
|
1306
1319
|
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Perform action operations against the configured dataset
|
|
1322
|
+
*
|
|
1323
|
+
* @param operations - Action operation(s) to execute
|
|
1324
|
+
* @param options - Action options
|
|
1325
|
+
*/
|
|
1326
|
+
action(operations, options) {
|
|
1327
|
+
return _action(this, __privateGet(this, _httpRequest), operations, options);
|
|
1328
|
+
}
|
|
1307
1329
|
/**
|
|
1308
1330
|
* Perform an HTTP request against the Sanity API
|
|
1309
1331
|
*
|
|
@@ -1441,6 +1463,16 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1441
1463
|
transaction(operations) {
|
|
1442
1464
|
return new Transaction(operations, this);
|
|
1443
1465
|
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Perform action operations against the configured dataset
|
|
1468
|
+
* Returns a promise that resolves to the transaction result
|
|
1469
|
+
*
|
|
1470
|
+
* @param operations - Action operation(s) to execute
|
|
1471
|
+
* @param options - Action options
|
|
1472
|
+
*/
|
|
1473
|
+
action(operations, options) {
|
|
1474
|
+
return rxjs.lastValueFrom(_action(this, __privateGet(this, _httpRequest2), operations, options));
|
|
1475
|
+
}
|
|
1444
1476
|
/**
|
|
1445
1477
|
* Perform a request against the Sanity API
|
|
1446
1478
|
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
@@ -1502,7 +1534,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1502
1534
|
return printNoDefaultExport(), createClient2(config);
|
|
1503
1535
|
};
|
|
1504
1536
|
}
|
|
1505
|
-
var name = "@sanity/client", version = "6.
|
|
1537
|
+
var name = "@sanity/client", version = "6.19.0";
|
|
1506
1538
|
const middleware = [
|
|
1507
1539
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1508
1540
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|