@sanity/client 8.1.0 → 8.3.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 +171 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +438 -101
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +734 -10
- package/dist/index.node.js +409 -59
- package/dist/index.node.js.map +1 -1
- package/dist/media-library.d.ts +1 -1
- package/dist/{types-BODIEY7F.d.ts → types-0x2hPfhJ.d.ts} +735 -11
- package/package.json +1 -2
- package/src/SanityClient.ts +20 -0
- package/src/collaboration/CollaborationCommentsClient.ts +387 -0
- package/src/collaboration/comments.ts +313 -0
- package/src/collaboration/types.ts +303 -0
- package/src/data/dataMethods.ts +7 -1
- package/src/data/listen.ts +20 -5
- package/src/functions/FunctionsClient.ts +52 -9
- package/src/functions/invoke.ts +47 -6
- package/src/types.ts +240 -1
- package/src/util/createVersionId.ts +15 -5
package/dist/index.node.js
CHANGED
|
@@ -7,7 +7,6 @@ import { Observable, catchError, concat, defer, finalize, isObservable, lastValu
|
|
|
7
7
|
import { getDraftId, getPublishedId, getVersionFromId, getVersionId, isDraftId, isVersionId } from "@sanity/client/csm";
|
|
8
8
|
import { filter, finalize as finalize$1, map as map$1, mergeAll } from "rxjs/operators";
|
|
9
9
|
import { EventSource } from "eventsource";
|
|
10
|
-
import { customAlphabet } from "nanoid";
|
|
11
10
|
import { Readable } from "node:stream";
|
|
12
11
|
import { createNodeFetch } from "get-it/node";
|
|
13
12
|
import { createDebug } from "obug";
|
|
@@ -726,7 +725,7 @@ function _fetchRequest(_stega, _params, options) {
|
|
|
726
725
|
}
|
|
727
726
|
/** @internal */
|
|
728
727
|
function _fetchObservable(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
729
|
-
return _observe(options.signal, (signal) => _fetch(client, httpRequest, _stega, query, _params, {
|
|
728
|
+
return _observe(options.signal, (signal) => _fetch$1(client, httpRequest, _stega, query, _params, {
|
|
730
729
|
...options,
|
|
731
730
|
signal
|
|
732
731
|
}));
|
|
@@ -736,7 +735,7 @@ function _fetchObservable(client, httpRequest, _stega, query, _params = {}, opti
|
|
|
736
735
|
*
|
|
737
736
|
* @internal
|
|
738
737
|
*/
|
|
739
|
-
function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
738
|
+
function _fetch$1(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
740
739
|
let { stega, params, mapResponse, reqOpts } = _fetchRequest(_stega, _params, options), request = _dataRequest(client, httpRequest, "query", {
|
|
741
740
|
query,
|
|
742
741
|
params
|
|
@@ -889,7 +888,7 @@ function _createVersionFromBaseObservable(client, httpRequest, publishedId, base
|
|
|
889
888
|
}
|
|
890
889
|
/** @internal */
|
|
891
890
|
function _deleteObservable(client, httpRequest, selection, options) {
|
|
892
|
-
return _observe(options?.signal, (signal) => _delete(client, httpRequest, selection, {
|
|
891
|
+
return _observe(options?.signal, (signal) => _delete$1(client, httpRequest, selection, {
|
|
893
892
|
...options,
|
|
894
893
|
signal
|
|
895
894
|
}));
|
|
@@ -994,7 +993,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
994
993
|
* @internal
|
|
995
994
|
*/
|
|
996
995
|
function _createObservable(client, httpRequest, doc, op, options = {}) {
|
|
997
|
-
return _observe(options.signal, (signal) => _create(client, httpRequest, doc, op, {
|
|
996
|
+
return _observe(options.signal, (signal) => _create$1(client, httpRequest, doc, op, {
|
|
998
997
|
...options,
|
|
999
998
|
signal
|
|
1000
999
|
}));
|
|
@@ -1004,7 +1003,7 @@ function _createObservable(client, httpRequest, doc, op, options = {}) {
|
|
|
1004
1003
|
*
|
|
1005
1004
|
* @internal
|
|
1006
1005
|
*/
|
|
1007
|
-
function _create(client, httpRequest, doc, op, options = {}) {
|
|
1006
|
+
function _create$1(client, httpRequest, doc, op, options = {}) {
|
|
1008
1007
|
let mutation = { [op]: doc }, opts = Object.assign({
|
|
1009
1008
|
returnFirst: !0,
|
|
1010
1009
|
returnDocuments: !0
|
|
@@ -1041,7 +1040,7 @@ function _mutate(client, httpRequest, mutations, options) {
|
|
|
1041
1040
|
*
|
|
1042
1041
|
* @internal
|
|
1043
1042
|
*/
|
|
1044
|
-
function _delete(client, httpRequest, selection, options) {
|
|
1043
|
+
function _delete$1(client, httpRequest, selection, options) {
|
|
1045
1044
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [{ delete: getSelection(selection) }] }, options);
|
|
1046
1045
|
}
|
|
1047
1046
|
/**
|
|
@@ -1050,7 +1049,7 @@ function _delete(client, httpRequest, selection, options) {
|
|
|
1050
1049
|
* @internal
|
|
1051
1050
|
*/
|
|
1052
1051
|
function _createIfNotExists(client, httpRequest, doc, options) {
|
|
1053
|
-
return requireDocumentId("createIfNotExists", doc), _create(client, httpRequest, doc, "createIfNotExists", options);
|
|
1052
|
+
return requireDocumentId("createIfNotExists", doc), _create$1(client, httpRequest, doc, "createIfNotExists", options);
|
|
1054
1053
|
}
|
|
1055
1054
|
/**
|
|
1056
1055
|
* Promise-based sibling of {@link _createOrReplaceObservable}.
|
|
@@ -1058,7 +1057,7 @@ function _createIfNotExists(client, httpRequest, doc, options) {
|
|
|
1058
1057
|
* @internal
|
|
1059
1058
|
*/
|
|
1060
1059
|
function _createOrReplace(client, httpRequest, doc, options) {
|
|
1061
|
-
return requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
|
|
1060
|
+
return requireDocumentId("createOrReplace", doc), _create$1(client, httpRequest, doc, "createOrReplace", options);
|
|
1062
1061
|
}
|
|
1063
1062
|
/**
|
|
1064
1063
|
* Promise-based sibling of {@link _createVersionObservable}.
|
|
@@ -1589,6 +1588,7 @@ function resolveEventSourceFetch(config, options = {}) {
|
|
|
1589
1588
|
function pickBaseFetch(config) {
|
|
1590
1589
|
return config.resolveFetch ? config.resolveFetch(typeof config.proxy == "string" ? config.proxy : void 0) : globalThis.fetch.bind(globalThis);
|
|
1591
1590
|
}
|
|
1591
|
+
/** @internal */
|
|
1592
1592
|
const possibleOptions = [
|
|
1593
1593
|
"includePreviousRevision",
|
|
1594
1594
|
"includeResult",
|
|
@@ -1600,8 +1600,8 @@ const possibleOptions = [
|
|
|
1600
1600
|
"tag"
|
|
1601
1601
|
], defaultOptions = { includeResult: !0 };
|
|
1602
1602
|
/** @public */
|
|
1603
|
-
function _listen(query, params, opts = {}) {
|
|
1604
|
-
let
|
|
1603
|
+
function _listen$1(query, params, opts = {}) {
|
|
1604
|
+
let { url, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = {
|
|
1605
1605
|
...defaults_default(opts, defaultOptions),
|
|
1606
1606
|
tag
|
|
1607
1607
|
}, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({
|
|
@@ -1613,7 +1613,12 @@ function _listen(query, params, opts = {}) {
|
|
|
1613
1613
|
}
|
|
1614
1614
|
}), uri = `${url}${_getDataUrl(this, "listen", qs)}`;
|
|
1615
1615
|
if (uri.length > 14800) return throwError(() => /* @__PURE__ */ Error("Query too large for listener"));
|
|
1616
|
-
let listenFor = options.events ? options.events : ["mutation"]
|
|
1616
|
+
let listenFor = options.events ? options.events : ["mutation"];
|
|
1617
|
+
return _connectListenEventSource(this, uri, listenFor);
|
|
1618
|
+
}
|
|
1619
|
+
/** @internal */
|
|
1620
|
+
function _connectListenEventSource(client, uri, listenFor) {
|
|
1621
|
+
let config = client.config(), { token, withCredentials, headers: configHeaders } = config, headers = {};
|
|
1617
1622
|
token && (headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(headers, configHeaders);
|
|
1618
1623
|
let initEventSource = () => new EventSource(uri, { fetch: resolveEventSourceFetch(config, {
|
|
1619
1624
|
headers: Object.keys(headers).length ? headers : void 0,
|
|
@@ -1624,6 +1629,358 @@ function _listen(query, params, opts = {}) {
|
|
|
1624
1629
|
..."data" in event ? event.data : {}
|
|
1625
1630
|
})));
|
|
1626
1631
|
}
|
|
1632
|
+
/** @internal */
|
|
1633
|
+
const possibleRequestOptions = [
|
|
1634
|
+
"headers",
|
|
1635
|
+
"signal",
|
|
1636
|
+
"tag",
|
|
1637
|
+
"timeout",
|
|
1638
|
+
"token"
|
|
1639
|
+
];
|
|
1640
|
+
function commentUrl(id) {
|
|
1641
|
+
if (!id) throw Error("Comment ID must be provided");
|
|
1642
|
+
return `/collaboration/comments/${encodeURIComponent(id)}`;
|
|
1643
|
+
}
|
|
1644
|
+
function resolveCommentResource(client) {
|
|
1645
|
+
let { resource, projectId, dataset } = client.config();
|
|
1646
|
+
if (resource) return resource;
|
|
1647
|
+
if (projectId && dataset) return {
|
|
1648
|
+
type: "dataset",
|
|
1649
|
+
id: `${projectId}.${dataset}`
|
|
1650
|
+
};
|
|
1651
|
+
throw Error("`resource` or `projectId` and `dataset` must be configured to use collaboration comments");
|
|
1652
|
+
}
|
|
1653
|
+
function resourceQuery(client) {
|
|
1654
|
+
let { collaboration } = client.config(), organizationId = collaboration?.organizationId;
|
|
1655
|
+
if (!organizationId) throw Error("`collaboration.organizationId` must be configured to use collaboration comments");
|
|
1656
|
+
let resource = resolveCommentResource(client);
|
|
1657
|
+
return {
|
|
1658
|
+
organizationId,
|
|
1659
|
+
resourceId: resource.id,
|
|
1660
|
+
resourceType: resource.type
|
|
1661
|
+
};
|
|
1662
|
+
}
|
|
1663
|
+
/** @internal */
|
|
1664
|
+
function _getTargetDocumentRef(client, documentId) {
|
|
1665
|
+
if (!documentId) throw Error("Document ID must be provided");
|
|
1666
|
+
let resource = resolveCommentResource(client);
|
|
1667
|
+
return `${resource.type}:${resource.id}:${getPublishedId(documentId)}`;
|
|
1668
|
+
}
|
|
1669
|
+
function write(client, httpRequest, method, url, body, options = {}) {
|
|
1670
|
+
return _requestObservable(client, httpRequest, {
|
|
1671
|
+
method,
|
|
1672
|
+
url,
|
|
1673
|
+
body,
|
|
1674
|
+
query: {
|
|
1675
|
+
...resourceQuery(client),
|
|
1676
|
+
...options.transactionId ? { transactionId: options.transactionId } : {}
|
|
1677
|
+
},
|
|
1678
|
+
...pick(options, possibleRequestOptions)
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
/**
|
|
1682
|
+
* `commentId` picks the written comment out of the results: a status update
|
|
1683
|
+
* cascades to the comment's replies, and the API leaves the results unordered.
|
|
1684
|
+
* Creates pass the requested `_id`, which is undefined when the API assigns
|
|
1685
|
+
* one, and always come back with a single result.
|
|
1686
|
+
*/
|
|
1687
|
+
function writeDocument(commentId, ...args) {
|
|
1688
|
+
return write(...args).pipe(map$1(({ results }) => {
|
|
1689
|
+
let result = commentId ? results.find(({ id }) => id === commentId) : results[0];
|
|
1690
|
+
if (!result?.document) throw Error("Comment write did not return a comment document");
|
|
1691
|
+
return result.document;
|
|
1692
|
+
}));
|
|
1693
|
+
}
|
|
1694
|
+
function writeMutationResult(...args) {
|
|
1695
|
+
return write(...args).pipe(map$1(({ transactionId, results }) => ({
|
|
1696
|
+
transactionId,
|
|
1697
|
+
documentIds: results.map((result) => result.id),
|
|
1698
|
+
results
|
|
1699
|
+
})));
|
|
1700
|
+
}
|
|
1701
|
+
/** @internal */
|
|
1702
|
+
function _create(client, httpRequest, body, options) {
|
|
1703
|
+
return writeDocument(body._id, client, httpRequest, "POST", "/collaboration/comments", body, options);
|
|
1704
|
+
}
|
|
1705
|
+
/** @internal */
|
|
1706
|
+
function _update(client, httpRequest, id, body, options) {
|
|
1707
|
+
return writeDocument(id, client, httpRequest, "PATCH", commentUrl(id), body, options);
|
|
1708
|
+
}
|
|
1709
|
+
/** @internal */
|
|
1710
|
+
function _delete(client, httpRequest, id, options) {
|
|
1711
|
+
return writeMutationResult(client, httpRequest, "DELETE", commentUrl(id), void 0, options);
|
|
1712
|
+
}
|
|
1713
|
+
/** @internal */
|
|
1714
|
+
function _addReaction(client, httpRequest, id, shortName, options) {
|
|
1715
|
+
return writeDocument(id, client, httpRequest, "POST", `${commentUrl(id)}/reactions`, { shortName }, options);
|
|
1716
|
+
}
|
|
1717
|
+
/** @internal */
|
|
1718
|
+
function _removeReaction(client, httpRequest, id, shortName, options) {
|
|
1719
|
+
return writeDocument(id, client, httpRequest, "DELETE", `${commentUrl(id)}/reactions/${encodeURIComponent(shortName)}`, void 0, options);
|
|
1720
|
+
}
|
|
1721
|
+
/** @internal */
|
|
1722
|
+
function _fetch(client, httpRequest, query, params, options) {
|
|
1723
|
+
let search = resourceQuery(client);
|
|
1724
|
+
return _requestObservable(client, httpRequest, {
|
|
1725
|
+
...encodeQueryString({
|
|
1726
|
+
query,
|
|
1727
|
+
params
|
|
1728
|
+
}).length < 11264 ? {
|
|
1729
|
+
method: "GET",
|
|
1730
|
+
url: `/collaboration/comments/query${encodeQueryString({
|
|
1731
|
+
query,
|
|
1732
|
+
params,
|
|
1733
|
+
options: search
|
|
1734
|
+
})}`
|
|
1735
|
+
} : {
|
|
1736
|
+
method: "POST",
|
|
1737
|
+
url: "/collaboration/comments/query",
|
|
1738
|
+
query: search,
|
|
1739
|
+
body: {
|
|
1740
|
+
query,
|
|
1741
|
+
params: params ?? {}
|
|
1742
|
+
}
|
|
1743
|
+
},
|
|
1744
|
+
...pick(options || {}, possibleRequestOptions)
|
|
1745
|
+
}).pipe(map$1((response) => response.result));
|
|
1746
|
+
}
|
|
1747
|
+
/** @internal */
|
|
1748
|
+
function _listen(client, query, params, options) {
|
|
1749
|
+
let opts = options ?? {}, { requestTagPrefix } = client.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, listenOpts = pick({
|
|
1750
|
+
...defaults_default(opts, defaultOptions),
|
|
1751
|
+
tag
|
|
1752
|
+
}, possibleOptions), qs = encodeQueryString({
|
|
1753
|
+
query,
|
|
1754
|
+
params,
|
|
1755
|
+
options: {
|
|
1756
|
+
...listenOpts,
|
|
1757
|
+
...resourceQuery(client)
|
|
1758
|
+
}
|
|
1759
|
+
}), uri = `${client.getUrl("/collaboration/comments/listen")}${qs}`;
|
|
1760
|
+
return uri.length > 14800 ? throwError(() => /* @__PURE__ */ Error("Query too large for listener")) : _connectListenEventSource(client, uri, opts.events ? opts.events : ["mutation"]);
|
|
1761
|
+
}
|
|
1762
|
+
/**
|
|
1763
|
+
* Comments on the configured organization resource.
|
|
1764
|
+
*
|
|
1765
|
+
* Requires `collaboration.organizationId`, plus either `resource` or `projectId` and `dataset`.
|
|
1766
|
+
*
|
|
1767
|
+
* @alpha
|
|
1768
|
+
*/
|
|
1769
|
+
var ObservableCollaborationCommentsClient = class {
|
|
1770
|
+
#client;
|
|
1771
|
+
#httpRequest;
|
|
1772
|
+
constructor(client, httpRequest) {
|
|
1773
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Create a comment or reply on the configured resource.
|
|
1777
|
+
*
|
|
1778
|
+
* A top-level comment requires `target`; a reply requires `parentCommentId` (never both).
|
|
1779
|
+
* Replies inherit `target`, `status`, and `threadId` from the parent comment.
|
|
1780
|
+
*
|
|
1781
|
+
* @param body - Comment to create
|
|
1782
|
+
* @param options - Optional request options
|
|
1783
|
+
* @returns The created comment
|
|
1784
|
+
*/
|
|
1785
|
+
create(body, options) {
|
|
1786
|
+
return _create(this.#client, this.#httpRequest, body, options);
|
|
1787
|
+
}
|
|
1788
|
+
/**
|
|
1789
|
+
* Update an existing comment.
|
|
1790
|
+
*
|
|
1791
|
+
* Updating `status` cascades to the comment's replies.
|
|
1792
|
+
*
|
|
1793
|
+
* @param id - Comment document ID
|
|
1794
|
+
* @param body - Fields to update
|
|
1795
|
+
* @param options - Optional request options
|
|
1796
|
+
* @returns The updated comment
|
|
1797
|
+
*/
|
|
1798
|
+
update(id, body, options) {
|
|
1799
|
+
return _update(this.#client, this.#httpRequest, id, body, options);
|
|
1800
|
+
}
|
|
1801
|
+
/**
|
|
1802
|
+
* Delete a comment and its replies.
|
|
1803
|
+
*
|
|
1804
|
+
* @param id - Comment document ID
|
|
1805
|
+
* @param options - Optional request options
|
|
1806
|
+
* @returns Mutation result, where `documentIds` covers the comment and every deleted reply
|
|
1807
|
+
*/
|
|
1808
|
+
delete(id, options) {
|
|
1809
|
+
return _delete(this.#client, this.#httpRequest, id, options);
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Add the current user's reaction to a comment.
|
|
1813
|
+
*
|
|
1814
|
+
* @param id - Comment document ID
|
|
1815
|
+
* @param shortName - Emoji short name, for example `:+1:`
|
|
1816
|
+
* @param options - Optional request options
|
|
1817
|
+
* @returns The comment, with the reaction applied
|
|
1818
|
+
*/
|
|
1819
|
+
addReaction(id, shortName, options) {
|
|
1820
|
+
return _addReaction(this.#client, this.#httpRequest, id, shortName, options);
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Remove the current user's reaction from a comment.
|
|
1824
|
+
*
|
|
1825
|
+
* @param id - Comment document ID
|
|
1826
|
+
* @param shortName - Emoji short name, for example `:+1:`
|
|
1827
|
+
* @param options - Optional request options
|
|
1828
|
+
* @returns The comment, with the reaction removed
|
|
1829
|
+
*/
|
|
1830
|
+
removeReaction(id, shortName, options) {
|
|
1831
|
+
return _removeReaction(this.#client, this.#httpRequest, id, shortName, options);
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Build the global document reference used by `target.document._ref`, for use in
|
|
1835
|
+
* queries and listeners.
|
|
1836
|
+
*
|
|
1837
|
+
* The reference is built from the configured `resource` and the published ID of
|
|
1838
|
+
* the given document ID, since comment references always use published IDs.
|
|
1839
|
+
*
|
|
1840
|
+
* @example
|
|
1841
|
+
* ```ts
|
|
1842
|
+
* client.collaboration.comments.listen(
|
|
1843
|
+
* '*[_type == "sanity.comment" && target.document._ref == $ref]',
|
|
1844
|
+
* {ref: client.collaboration.comments.getTargetDocumentRef('doc-1')},
|
|
1845
|
+
* )
|
|
1846
|
+
* ```
|
|
1847
|
+
*
|
|
1848
|
+
* @param documentId - Document ID, in published, draft or version form
|
|
1849
|
+
* @returns Global document reference, of the form `resourceType:resourceId:documentId`
|
|
1850
|
+
*/
|
|
1851
|
+
getTargetDocumentRef(documentId) {
|
|
1852
|
+
return _getTargetDocumentRef(this.#client, documentId);
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Fetch comments on the configured resource.
|
|
1856
|
+
*
|
|
1857
|
+
* Takes the same `query` and `params` as `client.fetch`, and switches from a
|
|
1858
|
+
* GET to a POST for queries too large for the request URL in the same way,
|
|
1859
|
+
* but queries the comments endpoint, which accepts none of the query options
|
|
1860
|
+
* `client.fetch` does (`perspective`, `useCdn`, `filterResponse`,
|
|
1861
|
+
* `resultSourceMap`, stega).
|
|
1862
|
+
*
|
|
1863
|
+
* The query runs against the organization store, which is not scoped to
|
|
1864
|
+
* comments, so filter on `_type == "sanity.comment"`.
|
|
1865
|
+
*
|
|
1866
|
+
* @param query - GROQ-query to perform
|
|
1867
|
+
* @param params - Optional query parameters
|
|
1868
|
+
* @param options - Optional request options
|
|
1869
|
+
*/
|
|
1870
|
+
fetch(query, params, options) {
|
|
1871
|
+
return _fetch(this.#client, this.#httpRequest, query, params, options);
|
|
1872
|
+
}
|
|
1873
|
+
listen(query, params, options) {
|
|
1874
|
+
return _listen(this.#client, query, params, options);
|
|
1875
|
+
}
|
|
1876
|
+
}, CollaborationCommentsClient = class {
|
|
1877
|
+
#client;
|
|
1878
|
+
#httpRequest;
|
|
1879
|
+
constructor(client, httpRequest) {
|
|
1880
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* Create a comment or reply on the configured resource.
|
|
1884
|
+
*
|
|
1885
|
+
* A top-level comment requires `target`; a reply requires `parentCommentId` (never both).
|
|
1886
|
+
* Replies inherit `target`, `status`, and `threadId` from the parent comment.
|
|
1887
|
+
*
|
|
1888
|
+
* @param body - Comment to create
|
|
1889
|
+
* @param options - Optional request options
|
|
1890
|
+
* @returns The created comment
|
|
1891
|
+
*/
|
|
1892
|
+
create(body, options) {
|
|
1893
|
+
return lastValueFrom(_create(this.#client, this.#httpRequest, body, options));
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Update an existing comment.
|
|
1897
|
+
*
|
|
1898
|
+
* Updating `status` cascades to the comment's replies.
|
|
1899
|
+
*
|
|
1900
|
+
* @param id - Comment document ID
|
|
1901
|
+
* @param body - Fields to update
|
|
1902
|
+
* @param options - Optional request options
|
|
1903
|
+
* @returns The updated comment
|
|
1904
|
+
*/
|
|
1905
|
+
update(id, body, options) {
|
|
1906
|
+
return lastValueFrom(_update(this.#client, this.#httpRequest, id, body, options));
|
|
1907
|
+
}
|
|
1908
|
+
/**
|
|
1909
|
+
* Delete a comment and its replies.
|
|
1910
|
+
*
|
|
1911
|
+
* @param id - Comment document ID
|
|
1912
|
+
* @param options - Optional request options
|
|
1913
|
+
* @returns Mutation result, where `documentIds` covers the comment and every deleted reply
|
|
1914
|
+
*/
|
|
1915
|
+
delete(id, options) {
|
|
1916
|
+
return lastValueFrom(_delete(this.#client, this.#httpRequest, id, options));
|
|
1917
|
+
}
|
|
1918
|
+
/**
|
|
1919
|
+
* Add the current user's reaction to a comment.
|
|
1920
|
+
*
|
|
1921
|
+
* @param id - Comment document ID
|
|
1922
|
+
* @param shortName - Emoji short name, for example `:+1:`
|
|
1923
|
+
* @param options - Optional request options
|
|
1924
|
+
* @returns The comment, with the reaction applied
|
|
1925
|
+
*/
|
|
1926
|
+
addReaction(id, shortName, options) {
|
|
1927
|
+
return lastValueFrom(_addReaction(this.#client, this.#httpRequest, id, shortName, options));
|
|
1928
|
+
}
|
|
1929
|
+
/**
|
|
1930
|
+
* Remove the current user's reaction from a comment.
|
|
1931
|
+
*
|
|
1932
|
+
* @param id - Comment document ID
|
|
1933
|
+
* @param shortName - Emoji short name, for example `:+1:`
|
|
1934
|
+
* @param options - Optional request options
|
|
1935
|
+
* @returns The comment, with the reaction removed
|
|
1936
|
+
*/
|
|
1937
|
+
removeReaction(id, shortName, options) {
|
|
1938
|
+
return lastValueFrom(_removeReaction(this.#client, this.#httpRequest, id, shortName, options));
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Build the global document reference used by `target.document._ref`, for use in
|
|
1942
|
+
* queries and listeners.
|
|
1943
|
+
*
|
|
1944
|
+
* The reference is built from the configured `resource` and the published ID of
|
|
1945
|
+
* the given document ID, since comment references always use published IDs.
|
|
1946
|
+
*
|
|
1947
|
+
* @example
|
|
1948
|
+
* ```ts
|
|
1949
|
+
* const comments = await client.collaboration.comments.fetch(
|
|
1950
|
+
* '*[_type == "sanity.comment" && target.document._ref == $ref]',
|
|
1951
|
+
* {ref: client.collaboration.comments.getTargetDocumentRef('doc-1')},
|
|
1952
|
+
* )
|
|
1953
|
+
* ```
|
|
1954
|
+
*
|
|
1955
|
+
* @param documentId - Document ID, in published, draft or version form
|
|
1956
|
+
* @returns Global document reference, of the form `resourceType:resourceId:documentId`
|
|
1957
|
+
*/
|
|
1958
|
+
getTargetDocumentRef(documentId) {
|
|
1959
|
+
return _getTargetDocumentRef(this.#client, documentId);
|
|
1960
|
+
}
|
|
1961
|
+
/**
|
|
1962
|
+
* Fetch comments on the configured resource.
|
|
1963
|
+
*
|
|
1964
|
+
* Takes the same `query` and `params` as `client.fetch`, and switches from a
|
|
1965
|
+
* GET to a POST for queries too large for the request URL in the same way,
|
|
1966
|
+
* but queries the comments endpoint, which accepts none of the query options
|
|
1967
|
+
* `client.fetch` does (`perspective`, `useCdn`, `filterResponse`,
|
|
1968
|
+
* `resultSourceMap`, stega).
|
|
1969
|
+
*
|
|
1970
|
+
* The query runs against the organization store, which is not scoped to
|
|
1971
|
+
* comments, so filter on `_type == "sanity.comment"`.
|
|
1972
|
+
*
|
|
1973
|
+
* @param query - GROQ-query to perform
|
|
1974
|
+
* @param params - Optional query parameters
|
|
1975
|
+
* @param options - Optional request options
|
|
1976
|
+
*/
|
|
1977
|
+
fetch(query, params, options) {
|
|
1978
|
+
return lastValueFrom(_fetch(this.#client, this.#httpRequest, query, params, options));
|
|
1979
|
+
}
|
|
1980
|
+
listen(query, params, options) {
|
|
1981
|
+
return _listen(this.#client, query, params, options);
|
|
1982
|
+
}
|
|
1983
|
+
};
|
|
1627
1984
|
/**
|
|
1628
1985
|
* A variant of share that takes a predicate function to determine which value to replay to new subscribers
|
|
1629
1986
|
* @param configOrPredicate - Predicate function to determine which value to replay
|
|
@@ -1935,7 +2292,11 @@ function _modify(client, httpRequest, method, name, options) {
|
|
|
1935
2292
|
});
|
|
1936
2293
|
}
|
|
1937
2294
|
/** Function resource types in a blueprint are namespaced under this prefix. */
|
|
1938
|
-
const
|
|
2295
|
+
const SYNC_INVOCABLE_FUNCTION_TYPES = ["sanity.function.pubsub"], ASYNC_INVOCABLE_FUNCTION_TYPES = [
|
|
2296
|
+
"sanity.function.durable",
|
|
2297
|
+
"sanity.function.pubsub",
|
|
2298
|
+
"sanity.function.queue"
|
|
2299
|
+
], INVOCABLE_FUNCTION_TYPES = [.../* @__PURE__ */ new Set([...SYNC_INVOCABLE_FUNCTION_TYPES, ...ASYNC_INVOCABLE_FUNCTION_TYPES])], scopeHeaders = (config, request) => {
|
|
1939
2300
|
let organizationId = request?.organizationId || config.organizationId;
|
|
1940
2301
|
if (organizationId) return {
|
|
1941
2302
|
"X-Sanity-Scope-Type": "organization",
|
|
@@ -1959,7 +2320,7 @@ const scopeHeaders = (config, request) => {
|
|
|
1959
2320
|
*
|
|
1960
2321
|
* @internal
|
|
1961
2322
|
*/
|
|
1962
|
-
function _resolveFunctionId(client, httpRequest, functionName, stackId, headers, request) {
|
|
2323
|
+
function _resolveFunctionId(client, httpRequest, functionName, stackId, headers, request, sync) {
|
|
1963
2324
|
return _requestObservable(client, httpRequest, {
|
|
1964
2325
|
method: "GET",
|
|
1965
2326
|
url: `/blueprints/stacks/${stackId}`,
|
|
@@ -1969,17 +2330,19 @@ function _resolveFunctionId(client, httpRequest, functionName, stackId, headers,
|
|
|
1969
2330
|
let match = (stack?.resources || []).find((resource) => resource.type?.startsWith("sanity.function.") && resource.name === functionName);
|
|
1970
2331
|
if (!match) throw Error(`Function "${functionName}" not found in stack "${stackId}"`);
|
|
1971
2332
|
if (!match.externalId) throw Error(`Function "${functionName}" is declared in stack "${stackId}" but is not deployed`);
|
|
1972
|
-
if (match.type
|
|
2333
|
+
if (!INVOCABLE_FUNCTION_TYPES.includes(match.type)) throw Error(`Function invocation is not supported for ${match.type}`);
|
|
2334
|
+
if (sync && !SYNC_INVOCABLE_FUNCTION_TYPES.includes(match.type)) throw Error(`Synchronous function invocation is not supported for ${match.type}`);
|
|
2335
|
+
if (!sync && !ASYNC_INVOCABLE_FUNCTION_TYPES.includes(match.type)) throw Error(`Asynchronous function invocation is not supported for ${match.type}`);
|
|
1973
2336
|
return match.externalId;
|
|
1974
2337
|
}));
|
|
1975
2338
|
}
|
|
1976
2339
|
/** @internal */
|
|
1977
|
-
function _invoke(client, httpRequest, functionName, request) {
|
|
2340
|
+
function _invoke(client, httpRequest, functionName, request, options) {
|
|
1978
2341
|
return defer(() => {
|
|
1979
|
-
let config = client.config(), headers = scopeHeaders(config, request);
|
|
1980
|
-
return _resolveFunctionId(client, httpRequest, functionName,
|
|
2342
|
+
let config = client.config(), headers = scopeHeaders(config, request), stackId = resolveStackId(config, request), sync = options?.sync ?? !1;
|
|
2343
|
+
return _resolveFunctionId(client, httpRequest, functionName, stackId, headers, request, sync).pipe(mergeMap((functionId) => _requestObservable(client, httpRequest, {
|
|
1981
2344
|
method: "POST",
|
|
1982
|
-
url: `/functions/${functionId}/invoke`,
|
|
2345
|
+
url: `/functions/${functionId}/invoke${sync ? "?sync=true" : ""}`,
|
|
1983
2346
|
headers,
|
|
1984
2347
|
body: { event: { data: request?.event?.data ?? {} } },
|
|
1985
2348
|
timeout: request?.timeout,
|
|
@@ -1994,17 +2357,8 @@ var ObservableFunctionsClient = class {
|
|
|
1994
2357
|
constructor(client, httpRequest) {
|
|
1995
2358
|
this.#client = client, this.#httpRequest = httpRequest;
|
|
1996
2359
|
}
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
*
|
|
2000
|
-
* The name is resolved within the stack given by `stackId` on the request or
|
|
2001
|
-
* the client config. Passes the function's return value once it finishes.
|
|
2002
|
-
*
|
|
2003
|
-
* @param functionName - name of the function, as declared in the blueprint
|
|
2004
|
-
* @param request - payload and request options
|
|
2005
|
-
*/
|
|
2006
|
-
invoke(functionName, request) {
|
|
2007
|
-
return _invoke(this.#client, this.#httpRequest, functionName, request);
|
|
2360
|
+
invoke(functionName, request, options) {
|
|
2361
|
+
return _invoke(this.#client, this.#httpRequest, functionName, request, options);
|
|
2008
2362
|
}
|
|
2009
2363
|
}, FunctionsClient = class {
|
|
2010
2364
|
#client;
|
|
@@ -2012,26 +2366,8 @@ var ObservableFunctionsClient = class {
|
|
|
2012
2366
|
constructor(client, httpRequest) {
|
|
2013
2367
|
this.#client = client, this.#httpRequest = httpRequest;
|
|
2014
2368
|
}
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
*
|
|
2018
|
-
* The name is resolved within the stack given by `stackId` on the request or
|
|
2019
|
-
* the client config, which costs one extra request per call. Rejects if the
|
|
2020
|
-
* stack has no function by that name, or if the name resolves to anything
|
|
2021
|
-
* other than a `sanity.function.pubsub` function.
|
|
2022
|
-
*
|
|
2023
|
-
* The lookup is scoped to `projectId`, or to `organizationId` when one is set
|
|
2024
|
-
* for a stack deployed at organization scope.
|
|
2025
|
-
*
|
|
2026
|
-
* The request stays open until the function finishes, and resolves with its
|
|
2027
|
-
* return value, or `undefined` if it returns nothing. Long-running functions
|
|
2028
|
-
* may need an explicit `timeout`.
|
|
2029
|
-
*
|
|
2030
|
-
* @param functionName - name of the function, as declared in the blueprint
|
|
2031
|
-
* @param request - payload and request options
|
|
2032
|
-
*/
|
|
2033
|
-
invoke(functionName, request) {
|
|
2034
|
-
return lastValueFrom(_invoke(this.#client, this.#httpRequest, functionName, request));
|
|
2369
|
+
invoke(functionName, request, options) {
|
|
2370
|
+
return lastValueFrom(_invoke(this.#client, this.#httpRequest, functionName, request, options));
|
|
2035
2371
|
}
|
|
2036
2372
|
}, ObservableMediaLibraryVideoClient = class {
|
|
2037
2373
|
#client;
|
|
@@ -2179,7 +2515,19 @@ var ObservableProjectsClient = class {
|
|
|
2179
2515
|
*
|
|
2180
2516
|
* ~24 years (or 7.54e+8 seconds) needed, in order to have a 1% probability of at least one collision if 10 ID's are generated every hour.
|
|
2181
2517
|
*/
|
|
2182
|
-
|
|
2518
|
+
function generateReleaseId() {
|
|
2519
|
+
let id = "";
|
|
2520
|
+
for (; id.length < 8;) {
|
|
2521
|
+
let bytes = crypto.getRandomValues(new Uint8Array(8 - id.length));
|
|
2522
|
+
for (let byte of bytes) {
|
|
2523
|
+
let index = byte & 63;
|
|
2524
|
+
index < 62 && (id += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[index]);
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
return id;
|
|
2528
|
+
}
|
|
2529
|
+
/** @internal */
|
|
2530
|
+
const getDocumentVersionId = (publishedId, releaseId) => releaseId ? getVersionId(publishedId, releaseId) : getDraftId(publishedId);
|
|
2183
2531
|
/** @internal */
|
|
2184
2532
|
function deriveDocumentVersionId(op, { releaseId, publishedId, document }) {
|
|
2185
2533
|
if (publishedId && document._id) {
|
|
@@ -2689,6 +3037,7 @@ var ObservableReleasesClient = class {
|
|
|
2689
3037
|
projects;
|
|
2690
3038
|
users;
|
|
2691
3039
|
agent;
|
|
3040
|
+
collaboration;
|
|
2692
3041
|
functions;
|
|
2693
3042
|
releases;
|
|
2694
3043
|
/**
|
|
@@ -2699,9 +3048,9 @@ var ObservableReleasesClient = class {
|
|
|
2699
3048
|
/**
|
|
2700
3049
|
* Instance properties
|
|
2701
3050
|
*/
|
|
2702
|
-
listen = _listen;
|
|
3051
|
+
listen = _listen$1;
|
|
2703
3052
|
constructor(httpRequest, config = defaultConfig) {
|
|
2704
|
-
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.mediaLibrary = { video: new ObservableMediaLibraryVideoClient(this, this.#httpRequest) }, this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = { action: new ObservableAgentsActionClient(this, this.#httpRequest) }, this.functions = new ObservableFunctionsClient(this, this.#httpRequest), this.releases = new ObservableReleasesClient(this, this.#httpRequest);
|
|
3053
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.mediaLibrary = { video: new ObservableMediaLibraryVideoClient(this, this.#httpRequest) }, this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = { action: new ObservableAgentsActionClient(this, this.#httpRequest) }, this.collaboration = { comments: new ObservableCollaborationCommentsClient(this, this.#httpRequest) }, this.functions = new ObservableFunctionsClient(this, this.#httpRequest), this.releases = new ObservableReleasesClient(this, this.#httpRequest);
|
|
2705
3054
|
}
|
|
2706
3055
|
/**
|
|
2707
3056
|
* Clone the client - returns a new instance
|
|
@@ -2924,6 +3273,7 @@ var ObservableReleasesClient = class {
|
|
|
2924
3273
|
projects;
|
|
2925
3274
|
users;
|
|
2926
3275
|
agent;
|
|
3276
|
+
collaboration;
|
|
2927
3277
|
functions;
|
|
2928
3278
|
releases;
|
|
2929
3279
|
/**
|
|
@@ -2938,9 +3288,9 @@ var ObservableReleasesClient = class {
|
|
|
2938
3288
|
/**
|
|
2939
3289
|
* Instance properties
|
|
2940
3290
|
*/
|
|
2941
|
-
listen = _listen;
|
|
3291
|
+
listen = _listen$1;
|
|
2942
3292
|
constructor(httpRequest, config = defaultConfig) {
|
|
2943
|
-
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.mediaLibrary = { video: new MediaLibraryVideoClient(this, this.#httpRequest) }, this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = { action: new AgentActionsClient(this, this.#httpRequest) }, this.functions = new FunctionsClient(this, this.#httpRequest), this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
3293
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.mediaLibrary = { video: new MediaLibraryVideoClient(this, this.#httpRequest) }, this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = { action: new AgentActionsClient(this, this.#httpRequest) }, this.collaboration = { comments: new CollaborationCommentsClient(this, this.#httpRequest) }, this.functions = new FunctionsClient(this, this.#httpRequest), this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
2944
3294
|
}
|
|
2945
3295
|
/**
|
|
2946
3296
|
* Clone the client - returns a new instance
|
|
@@ -2970,7 +3320,7 @@ var ObservableReleasesClient = class {
|
|
|
2970
3320
|
});
|
|
2971
3321
|
}
|
|
2972
3322
|
fetch(query, params, options) {
|
|
2973
|
-
return _fetch(this, this.#httpRequest, this.#clientConfig.stega, query, params, options);
|
|
3323
|
+
return _fetch$1(this, this.#httpRequest, this.#clientConfig.stega, query, params, options);
|
|
2974
3324
|
}
|
|
2975
3325
|
getDocument(id, options) {
|
|
2976
3326
|
if (options?.includeAllVersions === !0) return _getDocument(this, this.#httpRequest, id, {
|
|
@@ -3008,7 +3358,7 @@ var ObservableReleasesClient = class {
|
|
|
3008
3358
|
return _documentsExists(this, this.#httpRequest, ids, options);
|
|
3009
3359
|
}
|
|
3010
3360
|
create(document, options) {
|
|
3011
|
-
return _create(this, this.#httpRequest, document, "create", options);
|
|
3361
|
+
return _create$1(this, this.#httpRequest, document, "create", options);
|
|
3012
3362
|
}
|
|
3013
3363
|
createIfNotExists(document, options) {
|
|
3014
3364
|
return _createIfNotExists(this, this.#httpRequest, document, options);
|
|
@@ -3029,7 +3379,7 @@ var ObservableReleasesClient = class {
|
|
|
3029
3379
|
return _createVersion(this, this.#httpRequest, documentVersion, versionPublishedId, options);
|
|
3030
3380
|
}
|
|
3031
3381
|
delete(selection, options) {
|
|
3032
|
-
return _delete(this, this.#httpRequest, selection, options);
|
|
3382
|
+
return _delete$1(this, this.#httpRequest, selection, options);
|
|
3033
3383
|
}
|
|
3034
3384
|
/**
|
|
3035
3385
|
* @public
|
|
@@ -3202,7 +3552,7 @@ function defineDeprecatedCreateClient(createClient) {
|
|
|
3202
3552
|
return printNoDefaultExport(), createClient(config);
|
|
3203
3553
|
};
|
|
3204
3554
|
}
|
|
3205
|
-
var name = "@sanity/client", version = "8.
|
|
3555
|
+
var name = "@sanity/client", version = "8.3.0";
|
|
3206
3556
|
const log = createDebug("sanity:client");
|
|
3207
3557
|
function isNodeReadableStream(value) {
|
|
3208
3558
|
return typeof value != "object" || !value || !("pipe" in value) ? !1 : typeof value.pipe == "function";
|