@sanity/client 8.6.2 → 8.8.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/README.md +24 -6
- package/dist/collaboration.d.ts +33 -0
- package/dist/collaboration.js +2 -0
- package/dist/getCommentTargetDocumentRef-B8NuiBjG.js +31 -0
- package/dist/getCommentTargetDocumentRef-B8NuiBjG.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +28 -5
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +450 -110
- package/dist/index.node.js +54 -6
- package/dist/index.node.js.map +1 -1
- package/dist/media-library.d.ts +1 -1
- package/dist/{types-B1XLvey7.d.ts → types-Cov8gzNZ.d.ts} +451 -111
- package/package.json +4 -3
- package/src/collaboration/comments.ts +30 -7
- package/src/collaboration/getCommentTargetDocumentRef.ts +45 -0
- package/src/collaboration/index.ts +1 -0
- package/src/collaboration/types.ts +105 -13
- package/src/context/openapi.json +1011 -698
- package/src/context/types.gen.ts +324 -182
- package/src/types.ts +70 -0
package/dist/index.node.js
CHANGED
|
@@ -1544,7 +1544,7 @@ function optionsFromFile(opts, file) {
|
|
|
1544
1544
|
contentType: file.type
|
|
1545
1545
|
}, opts);
|
|
1546
1546
|
}
|
|
1547
|
-
var defaults_default = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj)).reduce((target, prop) => (target[prop] = obj[prop] === void 0 ? defaults[prop] : obj[prop], target), {});
|
|
1547
|
+
var name = "@sanity/client", version = "8.8.0", defaults_default = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj)).reduce((target, prop) => (target[prop] = obj[prop] === void 0 ? defaults[prop] : obj[prop], target), {});
|
|
1548
1548
|
const pick = (obj, props) => props.reduce((selection, prop) => (obj[prop] === void 0 || (selection[prop] = obj[prop]), selection), {}), RETRYABLE_STATUSES = /* @__PURE__ */ new Set([408, 429]);
|
|
1549
1549
|
/**
|
|
1550
1550
|
* Note: connection failure is not the same as network disconnect which may happen more frequent.
|
|
@@ -1646,6 +1646,33 @@ function _connectListenEventSource(client, uri, listenFor) {
|
|
|
1646
1646
|
..."data" in event ? event.data : {}
|
|
1647
1647
|
})));
|
|
1648
1648
|
}
|
|
1649
|
+
/**
|
|
1650
|
+
* Build the global document reference a comment stores in `target.document._ref`,
|
|
1651
|
+
* without a client.
|
|
1652
|
+
*
|
|
1653
|
+
* `client.collaboration.comments.getTargetDocumentRef` reads the resource off the
|
|
1654
|
+
* client's configuration and calls this. Use this directly when the resource is
|
|
1655
|
+
* already at hand and no client should be involved, for example inside a state
|
|
1656
|
+
* selector that has to stay free of side effects.
|
|
1657
|
+
*
|
|
1658
|
+
* The reference always names the published document: a draft or version ID is
|
|
1659
|
+
* reduced to its published form first.
|
|
1660
|
+
*
|
|
1661
|
+
* @example
|
|
1662
|
+
* ```ts
|
|
1663
|
+
* getCommentTargetDocumentRef({type: 'dataset', id: 'abc123.production'}, 'drafts.doc-1')
|
|
1664
|
+
* // 'dataset:abc123.production:doc-1'
|
|
1665
|
+
* ```
|
|
1666
|
+
*
|
|
1667
|
+
* @param resource - The resource the comments are stored against, as `ClientConfig['resource']` takes it
|
|
1668
|
+
* @param documentId - Document ID, in published, draft or version form
|
|
1669
|
+
* @returns Global document reference, of the form `resourceType:resourceId:documentId`
|
|
1670
|
+
* @alpha
|
|
1671
|
+
*/
|
|
1672
|
+
function getCommentTargetDocumentRef(resource, documentId) {
|
|
1673
|
+
if (!documentId) throw Error("Document ID must be provided");
|
|
1674
|
+
return `${resource.type}:${resource.id}:${getPublishedId(documentId)}`;
|
|
1675
|
+
}
|
|
1649
1676
|
/** @internal */
|
|
1650
1677
|
const possibleRequestOptions = [
|
|
1651
1678
|
"headers",
|
|
@@ -1680,8 +1707,7 @@ function resourceQuery(client) {
|
|
|
1680
1707
|
/** @internal */
|
|
1681
1708
|
function _getTargetDocumentRef(client, documentId) {
|
|
1682
1709
|
if (!documentId) throw Error("Document ID must be provided");
|
|
1683
|
-
|
|
1684
|
-
return `${resource.type}:${resource.id}:${getPublishedId(documentId)}`;
|
|
1710
|
+
return getCommentTargetDocumentRef(resolveCommentResource(client), documentId);
|
|
1685
1711
|
}
|
|
1686
1712
|
function write(client, httpRequest, method, url, body, options = {}) {
|
|
1687
1713
|
return _requestObservable(client, httpRequest, {
|
|
@@ -1690,6 +1716,7 @@ function write(client, httpRequest, method, url, body, options = {}) {
|
|
|
1690
1716
|
body,
|
|
1691
1717
|
query: {
|
|
1692
1718
|
...resourceQuery(client),
|
|
1719
|
+
clientVersion: version,
|
|
1693
1720
|
...options.transactionId ? { transactionId: options.transactionId } : {}
|
|
1694
1721
|
},
|
|
1695
1722
|
...pick(options, possibleRequestOptions)
|
|
@@ -1715,13 +1742,35 @@ function writeMutationResult(...args) {
|
|
|
1715
1742
|
results
|
|
1716
1743
|
})));
|
|
1717
1744
|
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Moves the deprecated `range` + `fieldValue` onto a `portable-text` `anchor`.
|
|
1747
|
+
* Anything else passes through unchanged, and invalid combinations are left
|
|
1748
|
+
* for the API to reject.
|
|
1749
|
+
*/
|
|
1750
|
+
function withAnchor(input) {
|
|
1751
|
+
let { range, fieldValue, ...rest } = input;
|
|
1752
|
+
return range === void 0 || input.anchor !== void 0 ? input : range === null ? fieldValue ? input : {
|
|
1753
|
+
...rest,
|
|
1754
|
+
anchor: null
|
|
1755
|
+
} : {
|
|
1756
|
+
...rest,
|
|
1757
|
+
anchor: {
|
|
1758
|
+
type: "portable-text",
|
|
1759
|
+
...range,
|
|
1760
|
+
...fieldValue && { fieldValue }
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1718
1764
|
/** @internal */
|
|
1719
1765
|
function _create(client, httpRequest, body, options) {
|
|
1720
|
-
return writeDocument(body._id, client, httpRequest, "POST", "/collaboration/comments", body
|
|
1766
|
+
return writeDocument(body._id, client, httpRequest, "POST", "/collaboration/comments", body.target ? {
|
|
1767
|
+
...body,
|
|
1768
|
+
target: withAnchor(body.target)
|
|
1769
|
+
} : body, options);
|
|
1721
1770
|
}
|
|
1722
1771
|
/** @internal */
|
|
1723
1772
|
function _update(client, httpRequest, id, body, options) {
|
|
1724
|
-
return writeDocument(id, client, httpRequest, "PATCH", commentUrl(id), body, options);
|
|
1773
|
+
return writeDocument(id, client, httpRequest, "PATCH", commentUrl(id), withAnchor(body), options);
|
|
1725
1774
|
}
|
|
1726
1775
|
/** @internal */
|
|
1727
1776
|
function _delete(client, httpRequest, id, options) {
|
|
@@ -4506,7 +4555,6 @@ function defineDeprecatedCreateClient(createClient) {
|
|
|
4506
4555
|
return printNoDefaultExport(), createClient(config);
|
|
4507
4556
|
};
|
|
4508
4557
|
}
|
|
4509
|
-
var name = "@sanity/client", version = "8.6.2";
|
|
4510
4558
|
const log = createDebug("sanity:client");
|
|
4511
4559
|
function isNodeReadableStream(value) {
|
|
4512
4560
|
return typeof value != "object" || !value || !("pipe" in value) ? !1 : typeof value.pipe == "function";
|