@sanity/client 7.1.0 → 7.2.1-agent-actions.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.cjs CHANGED
@@ -19,7 +19,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
19
19
  mod
20
20
  ));
21
21
  Object.defineProperty(exports, "__esModule", { value: !0 });
22
- var getIt = require("get-it"), middleware$1 = require("get-it/middleware"), rxjs = require("rxjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"), operators = require("rxjs/operators"), config = require("./_chunks-cjs/config.cjs");
22
+ var getIt = require("get-it"), middleware$1 = require("get-it/middleware"), rxjs = require("rxjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"), operators = require("rxjs/operators"), csm = require("@sanity/client/csm"), nanoid = require("nanoid"), config = require("./_chunks-cjs/config.cjs");
23
23
  class ClientError extends Error {
24
24
  response;
25
25
  statusCode = 400;
@@ -636,8 +636,24 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
636
636
  ) : $request.pipe(operators.map(mapResponse));
637
637
  }
638
638
  function _getDocument(client, httpRequest, id, opts = {}) {
639
- const options = {
640
- uri: _getDataUrl(client, "doc", id),
639
+ const docId = (() => {
640
+ if (!opts.releaseId)
641
+ return id;
642
+ const versionId = csm.getVersionFromId(id);
643
+ if (!versionId) {
644
+ if (csm.isDraftId(id))
645
+ throw new Error(
646
+ `The document ID (\`${id}\`) is a draft, but \`options.releaseId\` is set as \`${opts.releaseId}\``
647
+ );
648
+ return csm.getVersionId(id, opts.releaseId);
649
+ }
650
+ if (versionId !== opts.releaseId)
651
+ throw new Error(
652
+ `The document ID (\`${id}\`) is already a version of \`${versionId}\` release, but this does not match the provided \`options.releaseId\` (\`${opts.releaseId}\`)`
653
+ );
654
+ return id;
655
+ })(), options = {
656
+ uri: _getDataUrl(client, "doc", docId),
641
657
  json: !0,
642
658
  tag: opts.tag,
643
659
  signal: opts.signal
@@ -662,12 +678,33 @@ function _getDocuments(client, httpRequest, ids, opts = {}) {
662
678
  })
663
679
  );
664
680
  }
681
+ function _getReleaseDocuments(client, httpRequest, releaseId, opts = {}) {
682
+ return _dataRequest(
683
+ client,
684
+ httpRequest,
685
+ "query",
686
+ {
687
+ query: "*[sanity::partOfRelease($releaseId)]",
688
+ params: {
689
+ releaseId
690
+ }
691
+ },
692
+ opts
693
+ );
694
+ }
665
695
  function _createIfNotExists(client, httpRequest, doc, options) {
666
696
  return config.requireDocumentId("createIfNotExists", doc), _create(client, httpRequest, doc, "createIfNotExists", options);
667
697
  }
668
698
  function _createOrReplace(client, httpRequest, doc, options) {
669
699
  return config.requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
670
700
  }
701
+ function _createVersion(client, httpRequest, doc, publishedId, options) {
702
+ return config.requireDocumentId("createVersion", doc), config.requireDocumentType("createVersion", doc), _action(client, httpRequest, {
703
+ actionType: "sanity.action.document.version.create",
704
+ publishedId,
705
+ document: doc
706
+ }, options);
707
+ }
671
708
  function _delete(client, httpRequest, selection, options) {
672
709
  return _dataRequest(
673
710
  client,
@@ -677,6 +714,26 @@ function _delete(client, httpRequest, selection, options) {
677
714
  options
678
715
  );
679
716
  }
717
+ function _discardVersion(client, httpRequest, versionId, purge = !1, options) {
718
+ return _action(client, httpRequest, {
719
+ actionType: "sanity.action.document.version.discard",
720
+ versionId,
721
+ purge
722
+ }, options);
723
+ }
724
+ function _replaceVersion(client, httpRequest, doc, options) {
725
+ return config.requireDocumentId("replaceVersion", doc), config.requireDocumentType("replaceVersion", doc), _action(client, httpRequest, {
726
+ actionType: "sanity.action.document.version.replace",
727
+ document: doc
728
+ }, options);
729
+ }
730
+ function _unpublishVersion(client, httpRequest, versionId, publishedId, options) {
731
+ return _action(client, httpRequest, {
732
+ actionType: "sanity.action.document.version.unpublish",
733
+ versionId,
734
+ publishedId
735
+ }, options);
736
+ }
680
737
  function _mutate(client, httpRequest, mutations, options) {
681
738
  let mut;
682
739
  mutations instanceof Patch || mutations instanceof ObservablePatch ? mut = { patch: mutations.serialize() } : mutations instanceof Transaction || mutations instanceof ObservableTransaction ? mut = mutations.serialize() : mut = mutations;
@@ -831,6 +888,14 @@ function _generate(client, httpRequest, request) {
831
888
  body: request
832
889
  });
833
890
  }
891
+ function _prompt(client, httpRequest, request) {
892
+ const dataset = config.hasDataset(client.config());
893
+ return _request(client, httpRequest, {
894
+ method: "POST",
895
+ uri: `/agent/action/prompt/${dataset}`,
896
+ body: request
897
+ });
898
+ }
834
899
  function _transform(client, httpRequest, request) {
835
900
  const dataset = config.hasDataset(client.config());
836
901
  return _request(client, httpRequest, {
@@ -902,6 +967,13 @@ class AgentActionsClient {
902
967
  translate(request) {
903
968
  return rxjs.lastValueFrom(_translate(this.#client, this.#httpRequest, request));
904
969
  }
970
+ /**
971
+ * Run a raw instruction and return the result either as text or json
972
+ * @param request - prompt request
973
+ */
974
+ prompt(request) {
975
+ return rxjs.lastValueFrom(_prompt(this.#client, this.#httpRequest, request));
976
+ }
905
977
  }
906
978
  class ObservableAssetsClient {
907
979
  #client;
@@ -1279,6 +1351,498 @@ class ProjectsClient {
1279
1351
  );
1280
1352
  }
1281
1353
  }
1354
+ const generateReleaseId = nanoid.customAlphabet(
1355
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
1356
+ 8
1357
+ ), getDocumentVersionId = (publishedId, releaseId) => releaseId ? csm.getVersionId(publishedId, releaseId) : csm.getDraftId(publishedId);
1358
+ function deriveDocumentVersionId(op, {
1359
+ releaseId,
1360
+ publishedId,
1361
+ document
1362
+ }) {
1363
+ if (publishedId && document._id) {
1364
+ const versionId = getDocumentVersionId(publishedId, releaseId);
1365
+ return config.validateVersionIdMatch(versionId, document), versionId;
1366
+ }
1367
+ if (document._id) {
1368
+ const isDraft = csm.isDraftId(document._id), isVersion = csm.isVersionId(document._id);
1369
+ if (!isDraft && !isVersion)
1370
+ throw new Error(
1371
+ `\`${op}()\` requires a document with an \`_id\` that is a version or draft ID`
1372
+ );
1373
+ if (releaseId) {
1374
+ if (isDraft)
1375
+ throw new Error(
1376
+ `\`${op}()\` was called with a document ID (\`${document._id}\`) that is a draft ID, but a release ID (\`${releaseId}\`) was also provided.`
1377
+ );
1378
+ const builtVersionId = csm.getVersionFromId(document._id);
1379
+ if (builtVersionId !== releaseId)
1380
+ throw new Error(
1381
+ `\`${op}()\` was called with a document ID (\`${document._id}\`) that is a version ID, but the release ID (\`${releaseId}\`) does not match the document's version ID (\`${builtVersionId}\`).`
1382
+ );
1383
+ }
1384
+ return document._id;
1385
+ }
1386
+ if (publishedId)
1387
+ return getDocumentVersionId(publishedId, releaseId);
1388
+ throw new Error(`\`${op}()\` requires either a publishedId or a document with an \`_id\``);
1389
+ }
1390
+ const getArgs = (releaseOrOptions, maybeOptions) => {
1391
+ if (typeof releaseOrOptions == "object" && releaseOrOptions !== null && ("releaseId" in releaseOrOptions || "metadata" in releaseOrOptions)) {
1392
+ const { releaseId = generateReleaseId(), metadata = {} } = releaseOrOptions;
1393
+ return [releaseId, metadata, maybeOptions];
1394
+ }
1395
+ return [generateReleaseId(), {}, releaseOrOptions];
1396
+ }, createRelease = (releaseOrOptions, maybeOptions) => {
1397
+ const [releaseId, metadata, options] = getArgs(releaseOrOptions, maybeOptions), finalMetadata = {
1398
+ ...metadata,
1399
+ releaseType: metadata.releaseType || "undecided"
1400
+ };
1401
+ return { action: {
1402
+ actionType: "sanity.action.release.create",
1403
+ releaseId,
1404
+ metadata: finalMetadata
1405
+ }, options };
1406
+ };
1407
+ class ObservableReleasesClient {
1408
+ #client;
1409
+ #httpRequest;
1410
+ constructor(client, httpRequest) {
1411
+ this.#client = client, this.#httpRequest = httpRequest;
1412
+ }
1413
+ /**
1414
+ * @public
1415
+ *
1416
+ * Retrieve a release by id.
1417
+ *
1418
+ * @category Releases
1419
+ *
1420
+ * @param params - Release action parameters:
1421
+ * - `releaseId` - The id of the release to retrieve.
1422
+ * @param options - Additional query options including abort signal and query tag.
1423
+ * @returns An observable that resolves to the release document {@link ReleaseDocument}.
1424
+ *
1425
+ * @example Retrieving a release by id
1426
+ * ```ts
1427
+ * client.observable.releases.get({releaseId: 'my-release'}).pipe(
1428
+ * tap((release) => console.log(release)),
1429
+ * // {
1430
+ * // _id: '_.releases.my-release',
1431
+ * // name: 'my-release'
1432
+ * // _type: 'system.release',
1433
+ * // metadata: {releaseType: 'asap'},
1434
+ * // _createdAt: '2021-01-01T00:00:00.000Z',
1435
+ * // ...
1436
+ * // }
1437
+ * ).subscribe()
1438
+ * ```
1439
+ */
1440
+ get({ releaseId }, options) {
1441
+ return _getDocument(
1442
+ this.#client,
1443
+ this.#httpRequest,
1444
+ `_.releases.${releaseId}`,
1445
+ options
1446
+ );
1447
+ }
1448
+ create(releaseOrOptions, maybeOptions) {
1449
+ const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
1450
+ return _action(this.#client, this.#httpRequest, action, options).pipe(
1451
+ rxjs.map((actionResult) => ({
1452
+ ...actionResult,
1453
+ releaseId,
1454
+ metadata
1455
+ }))
1456
+ );
1457
+ }
1458
+ /**
1459
+ * @public
1460
+ *
1461
+ * Edits an existing release, updating the metadata.
1462
+ *
1463
+ * @category Releases
1464
+ *
1465
+ * @param params - Release action parameters:
1466
+ * - `releaseId` - The id of the release to edit.
1467
+ * - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
1468
+ * @param options - Additional action options.
1469
+ * @returns An observable that resolves to the `transactionId`.
1470
+ */
1471
+ edit({ releaseId, patch }, options) {
1472
+ const editAction = {
1473
+ actionType: "sanity.action.release.edit",
1474
+ releaseId,
1475
+ patch
1476
+ };
1477
+ return _action(this.#client, this.#httpRequest, editAction, options);
1478
+ }
1479
+ /**
1480
+ * @public
1481
+ *
1482
+ * Publishes all documents in a release at once. For larger releases the effect of the publish
1483
+ * will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
1484
+ * documents and creation of the corresponding published documents with the new content may
1485
+ * take some time.
1486
+ *
1487
+ * During this period both the source and target documents are locked and cannot be
1488
+ * modified through any other means.
1489
+ *
1490
+ * @category Releases
1491
+ *
1492
+ * @param params - Release action parameters:
1493
+ * - `releaseId` - The id of the release to publish.
1494
+ * @param options - Additional action options.
1495
+ * @returns An observable that resolves to the `transactionId`.
1496
+ */
1497
+ publish({ releaseId }, options) {
1498
+ const publishAction = {
1499
+ actionType: "sanity.action.release.publish",
1500
+ releaseId
1501
+ };
1502
+ return _action(this.#client, this.#httpRequest, publishAction, options);
1503
+ }
1504
+ /**
1505
+ * @public
1506
+ *
1507
+ * An archive action removes an active release. The documents that comprise the release
1508
+ * are deleted and therefore no longer queryable.
1509
+ *
1510
+ * While the documents remain in retention the last version can still be accessed using document history endpoint.
1511
+ *
1512
+ * @category Releases
1513
+ *
1514
+ * @param params - Release action parameters:
1515
+ * - `releaseId` - The id of the release to archive.
1516
+ * @param options - Additional action options.
1517
+ * @returns An observable that resolves to the `transactionId`.
1518
+ */
1519
+ archive({ releaseId }, options) {
1520
+ const archiveAction = {
1521
+ actionType: "sanity.action.release.archive",
1522
+ releaseId
1523
+ };
1524
+ return _action(this.#client, this.#httpRequest, archiveAction, options);
1525
+ }
1526
+ /**
1527
+ * @public
1528
+ *
1529
+ * An unarchive action restores an archived release and all documents
1530
+ * with the content they had just prior to archiving.
1531
+ *
1532
+ * @category Releases
1533
+ *
1534
+ * @param params - Release action parameters:
1535
+ * - `releaseId` - The id of the release to unarchive.
1536
+ * @param options - Additional action options.
1537
+ * @returns An observable that resolves to the `transactionId`.
1538
+ */
1539
+ unarchive({ releaseId }, options) {
1540
+ const unarchiveAction = {
1541
+ actionType: "sanity.action.release.unarchive",
1542
+ releaseId
1543
+ };
1544
+ return _action(this.#client, this.#httpRequest, unarchiveAction, options);
1545
+ }
1546
+ /**
1547
+ * @public
1548
+ *
1549
+ * A schedule action queues a release for publishing at the given future time.
1550
+ * The release is locked such that no documents in the release can be modified and
1551
+ * no documents that it references can be deleted as this would make the publish fail.
1552
+ * At the given time, the same logic as for the publish action is triggered.
1553
+ *
1554
+ * @category Releases
1555
+ *
1556
+ * @param params - Release action parameters:
1557
+ * - `releaseId` - The id of the release to schedule.
1558
+ * - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
1559
+ * @param options - Additional action options.
1560
+ * @returns An observable that resolves to the `transactionId`.
1561
+ */
1562
+ schedule({ releaseId, publishAt }, options) {
1563
+ const scheduleAction = {
1564
+ actionType: "sanity.action.release.schedule",
1565
+ releaseId,
1566
+ publishAt
1567
+ };
1568
+ return _action(this.#client, this.#httpRequest, scheduleAction, options);
1569
+ }
1570
+ /**
1571
+ * @public
1572
+ *
1573
+ * An unschedule action stops a release from being published.
1574
+ * The documents in the release are considered unlocked and can be edited again.
1575
+ * This may fail if another release is scheduled to be published after this one and
1576
+ * has a reference to a document created by this one.
1577
+ *
1578
+ * @category Releases
1579
+ *
1580
+ * @param params - Release action parameters:
1581
+ * - `releaseId` - The id of the release to unschedule.
1582
+ * @param options - Additional action options.
1583
+ * @returns An observable that resolves to the `transactionId`.
1584
+ */
1585
+ unschedule({ releaseId }, options) {
1586
+ const unscheduleAction = {
1587
+ actionType: "sanity.action.release.unschedule",
1588
+ releaseId
1589
+ };
1590
+ return _action(this.#client, this.#httpRequest, unscheduleAction, options);
1591
+ }
1592
+ /**
1593
+ * @public
1594
+ *
1595
+ * A delete action removes a published or archived release.
1596
+ * The backing system document will be removed from the dataset.
1597
+ *
1598
+ * @category Releases
1599
+ *
1600
+ * @param params - Release action parameters:
1601
+ * - `releaseId` - The id of the release to delete.
1602
+ * @param options - Additional action options.
1603
+ * @returns An observable that resolves to the `transactionId`.
1604
+ */
1605
+ delete({ releaseId }, options) {
1606
+ const deleteAction = {
1607
+ actionType: "sanity.action.release.delete",
1608
+ releaseId
1609
+ };
1610
+ return _action(this.#client, this.#httpRequest, deleteAction, options);
1611
+ }
1612
+ /**
1613
+ * @public
1614
+ *
1615
+ * Fetch the documents in a release by release id.
1616
+ *
1617
+ * @category Releases
1618
+ *
1619
+ * @param params - Release action parameters:
1620
+ * - `releaseId` - The id of the release to fetch documents for.
1621
+ * @param options - Additional mutation options {@link BaseMutationOptions}.
1622
+ * @returns An observable that resolves to the documents in the release.
1623
+ */
1624
+ fetchDocuments({ releaseId }, options) {
1625
+ return _getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options);
1626
+ }
1627
+ }
1628
+ class ReleasesClient {
1629
+ #client;
1630
+ #httpRequest;
1631
+ constructor(client, httpRequest) {
1632
+ this.#client = client, this.#httpRequest = httpRequest;
1633
+ }
1634
+ /**
1635
+ * @public
1636
+ *
1637
+ * Retrieve a release by id.
1638
+ *
1639
+ * @category Releases
1640
+ *
1641
+ * @param params - Release action parameters:
1642
+ * - `releaseId` - The id of the release to retrieve.
1643
+ * @param options - Additional query options including abort signal and query tag.
1644
+ * @returns A promise that resolves to the release document {@link ReleaseDocument}.
1645
+ *
1646
+ * @example Retrieving a release by id
1647
+ * ```ts
1648
+ * const release = await client.releases.get({releaseId: 'my-release'})
1649
+ * console.log(release)
1650
+ * // {
1651
+ * // _id: '_.releases.my-release',
1652
+ * // name: 'my-release'
1653
+ * // _type: 'system.release',
1654
+ * // metadata: {releaseType: 'asap'},
1655
+ * // _createdAt: '2021-01-01T00:00:00.000Z',
1656
+ * // ...
1657
+ * // }
1658
+ * ```
1659
+ */
1660
+ get({ releaseId }, options) {
1661
+ return rxjs.lastValueFrom(
1662
+ _getDocument(
1663
+ this.#client,
1664
+ this.#httpRequest,
1665
+ `_.releases.${releaseId}`,
1666
+ options
1667
+ )
1668
+ );
1669
+ }
1670
+ async create(releaseOrOptions, maybeOptions) {
1671
+ const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
1672
+ return { ...await rxjs.lastValueFrom(
1673
+ _action(this.#client, this.#httpRequest, action, options)
1674
+ ), releaseId, metadata };
1675
+ }
1676
+ /**
1677
+ * @public
1678
+ *
1679
+ * Edits an existing release, updating the metadata.
1680
+ *
1681
+ * @category Releases
1682
+ *
1683
+ * @param params - Release action parameters:
1684
+ * - `releaseId` - The id of the release to edit.
1685
+ * - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
1686
+ * @param options - Additional action options.
1687
+ * @returns A promise that resolves to the `transactionId`.
1688
+ */
1689
+ edit({ releaseId, patch }, options) {
1690
+ const editAction = {
1691
+ actionType: "sanity.action.release.edit",
1692
+ releaseId,
1693
+ patch
1694
+ };
1695
+ return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, editAction, options));
1696
+ }
1697
+ /**
1698
+ * @public
1699
+ *
1700
+ * Publishes all documents in a release at once. For larger releases the effect of the publish
1701
+ * will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
1702
+ * documents and creation of the corresponding published documents with the new content may
1703
+ * take some time.
1704
+ *
1705
+ * During this period both the source and target documents are locked and cannot be
1706
+ * modified through any other means.
1707
+ *
1708
+ * @category Releases
1709
+ *
1710
+ * @param params - Release action parameters:
1711
+ * - `releaseId` - The id of the release to publish.
1712
+ * @param options - Additional action options.
1713
+ * @returns A promise that resolves to the `transactionId`.
1714
+ */
1715
+ publish({ releaseId }, options) {
1716
+ const publishAction = {
1717
+ actionType: "sanity.action.release.publish",
1718
+ releaseId
1719
+ };
1720
+ return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, publishAction, options));
1721
+ }
1722
+ /**
1723
+ * @public
1724
+ *
1725
+ * An archive action removes an active release. The documents that comprise the release
1726
+ * are deleted and therefore no longer queryable.
1727
+ *
1728
+ * While the documents remain in retention the last version can still be accessed using document history endpoint.
1729
+ *
1730
+ * @category Releases
1731
+ *
1732
+ * @param params - Release action parameters:
1733
+ * - `releaseId` - The id of the release to archive.
1734
+ * @param options - Additional action options.
1735
+ * @returns A promise that resolves to the `transactionId`.
1736
+ */
1737
+ archive({ releaseId }, options) {
1738
+ const archiveAction = {
1739
+ actionType: "sanity.action.release.archive",
1740
+ releaseId
1741
+ };
1742
+ return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, archiveAction, options));
1743
+ }
1744
+ /**
1745
+ * @public
1746
+ *
1747
+ * An unarchive action restores an archived release and all documents
1748
+ * with the content they had just prior to archiving.
1749
+ *
1750
+ * @category Releases
1751
+ *
1752
+ * @param params - Release action parameters:
1753
+ * - `releaseId` - The id of the release to unarchive.
1754
+ * @param options - Additional action options.
1755
+ * @returns A promise that resolves to the `transactionId`.
1756
+ */
1757
+ unarchive({ releaseId }, options) {
1758
+ const unarchiveAction = {
1759
+ actionType: "sanity.action.release.unarchive",
1760
+ releaseId
1761
+ };
1762
+ return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, unarchiveAction, options));
1763
+ }
1764
+ /**
1765
+ * @public
1766
+ *
1767
+ * A schedule action queues a release for publishing at the given future time.
1768
+ * The release is locked such that no documents in the release can be modified and
1769
+ * no documents that it references can be deleted as this would make the publish fail.
1770
+ * At the given time, the same logic as for the publish action is triggered.
1771
+ *
1772
+ * @category Releases
1773
+ *
1774
+ * @param params - Release action parameters:
1775
+ * - `releaseId` - The id of the release to schedule.
1776
+ * - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
1777
+ * @param options - Additional action options.
1778
+ * @returns A promise that resolves to the `transactionId`.
1779
+ */
1780
+ schedule({ releaseId, publishAt }, options) {
1781
+ const scheduleAction = {
1782
+ actionType: "sanity.action.release.schedule",
1783
+ releaseId,
1784
+ publishAt
1785
+ };
1786
+ return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, scheduleAction, options));
1787
+ }
1788
+ /**
1789
+ * @public
1790
+ *
1791
+ * An unschedule action stops a release from being published.
1792
+ * The documents in the release are considered unlocked and can be edited again.
1793
+ * This may fail if another release is scheduled to be published after this one and
1794
+ * has a reference to a document created by this one.
1795
+ *
1796
+ * @category Releases
1797
+ *
1798
+ * @param params - Release action parameters:
1799
+ * - `releaseId` - The id of the release to unschedule.
1800
+ * @param options - Additional action options.
1801
+ * @returns A promise that resolves to the `transactionId`.
1802
+ */
1803
+ unschedule({ releaseId }, options) {
1804
+ const unscheduleAction = {
1805
+ actionType: "sanity.action.release.unschedule",
1806
+ releaseId
1807
+ };
1808
+ return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, unscheduleAction, options));
1809
+ }
1810
+ /**
1811
+ * @public
1812
+ *
1813
+ * A delete action removes a published or archived release.
1814
+ * The backing system document will be removed from the dataset.
1815
+ *
1816
+ * @category Releases
1817
+ *
1818
+ * @param params - Release action parameters:
1819
+ * - `releaseId` - The id of the release to delete.
1820
+ * @param options - Additional action options.
1821
+ * @returns A promise that resolves to the `transactionId`.
1822
+ */
1823
+ delete({ releaseId }, options) {
1824
+ const deleteAction = {
1825
+ actionType: "sanity.action.release.delete",
1826
+ releaseId
1827
+ };
1828
+ return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, deleteAction, options));
1829
+ }
1830
+ /**
1831
+ * @public
1832
+ *
1833
+ * Fetch the documents in a release by release id.
1834
+ *
1835
+ * @category Releases
1836
+ *
1837
+ * @param params - Release action parameters:
1838
+ * - `releaseId` - The id of the release to fetch documents for.
1839
+ * @param options - Additional mutation options {@link BaseMutationOptions}.
1840
+ * @returns A promise that resolves to the documents in the release.
1841
+ */
1842
+ fetchDocuments({ releaseId }, options) {
1843
+ return rxjs.lastValueFrom(_getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options));
1844
+ }
1845
+ }
1282
1846
  class ObservableUsersClient {
1283
1847
  #client;
1284
1848
  #httpRequest;
@@ -1324,6 +1888,7 @@ class ObservableSanityClient {
1324
1888
  projects;
1325
1889
  users;
1326
1890
  agent;
1891
+ releases;
1327
1892
  /**
1328
1893
  * Private properties
1329
1894
  */
@@ -1336,7 +1901,7 @@ class ObservableSanityClient {
1336
1901
  constructor(httpRequest, config$1 = config.defaultConfig) {
1337
1902
  this.config(config$1), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = {
1338
1903
  action: new ObservableAgentsActionClient(this, this.#httpRequest)
1339
- };
1904
+ }, this.releases = new ObservableReleasesClient(this, this.#httpRequest);
1340
1905
  }
1341
1906
  /**
1342
1907
  * Clone the client - returns a new instance
@@ -1409,9 +1974,96 @@ class ObservableSanityClient {
1409
1974
  createOrReplace(document, options) {
1410
1975
  return _createOrReplace(this, this.#httpRequest, document, options);
1411
1976
  }
1977
+ createVersion({
1978
+ document,
1979
+ publishedId,
1980
+ releaseId
1981
+ }, options) {
1982
+ const documentVersionId = deriveDocumentVersionId("createVersion", {
1983
+ document,
1984
+ publishedId,
1985
+ releaseId
1986
+ }), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || csm.getPublishedId(document._id);
1987
+ return _createVersion(
1988
+ this,
1989
+ this.#httpRequest,
1990
+ documentVersion,
1991
+ versionPublishedId,
1992
+ options
1993
+ );
1994
+ }
1412
1995
  delete(selection, options) {
1413
1996
  return _delete(this, this.#httpRequest, selection, options);
1414
1997
  }
1998
+ /**
1999
+ * @public
2000
+ *
2001
+ * Deletes the draft or release version of a document.
2002
+ *
2003
+ * @remarks
2004
+ * * Discarding a version with no `releaseId` will discard the draft version of the published document.
2005
+ * * If the draft or release version does not exist, any error will throw.
2006
+ *
2007
+ * @param params - Version action parameters:
2008
+ * - `releaseId` - The ID of the release to discard the document from.
2009
+ * - `publishedId` - The published ID of the document to discard.
2010
+ * @param purge - if `true` the document history is also discarded.
2011
+ * @param options - Additional action options.
2012
+ * @returns an observable that resolves to the `transactionId`.
2013
+ *
2014
+ * @example Discarding a release version of a document
2015
+ * ```ts
2016
+ * client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
2017
+ * // The document with the ID `versions.myRelease.myDocument` will be discarded.
2018
+ * ```
2019
+ *
2020
+ * @example Discarding a draft version of a document
2021
+ * ```ts
2022
+ * client.observable.discardVersion({publishedId: 'myDocument'})
2023
+ * // The document with the ID `drafts.myDocument` will be discarded.
2024
+ * ```
2025
+ */
2026
+ discardVersion({ releaseId, publishedId }, purge, options) {
2027
+ const documentVersionId = getDocumentVersionId(publishedId, releaseId);
2028
+ return _discardVersion(this, this.#httpRequest, documentVersionId, purge, options);
2029
+ }
2030
+ replaceVersion({
2031
+ document,
2032
+ publishedId,
2033
+ releaseId
2034
+ }, options) {
2035
+ const documentVersionId = deriveDocumentVersionId("replaceVersion", {
2036
+ document,
2037
+ publishedId,
2038
+ releaseId
2039
+ }), documentVersion = { ...document, _id: documentVersionId };
2040
+ return _replaceVersion(this, this.#httpRequest, documentVersion, options);
2041
+ }
2042
+ /**
2043
+ * @public
2044
+ *
2045
+ * Used to indicate when a document within a release should be unpublished when
2046
+ * the release is run.
2047
+ *
2048
+ * @remarks
2049
+ * * If the published document does not exist, an error will be thrown.
2050
+ *
2051
+ * @param params - Version action parameters:
2052
+ * - `releaseId` - The ID of the release to unpublish the document from.
2053
+ * - `publishedId` - The published ID of the document to unpublish.
2054
+ * @param options - Additional action options.
2055
+ * @returns an observable that resolves to the `transactionId`.
2056
+ *
2057
+ * @example Unpublishing a release version of a published document
2058
+ * ```ts
2059
+ * client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
2060
+ * // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
2061
+ * ```
2062
+ */
2063
+ unpublishVersion({ releaseId, publishedId }, options) {
2064
+ const versionId = csm.getVersionId(publishedId, releaseId);
2065
+ return _unpublishVersion(this, this.#httpRequest, versionId, publishedId, options);
2066
+ }
1415
2067
  mutate(operations, options) {
1416
2068
  return _mutate(this, this.#httpRequest, operations, options);
1417
2069
  }
@@ -1476,6 +2128,7 @@ class SanityClient {
1476
2128
  projects;
1477
2129
  users;
1478
2130
  agent;
2131
+ releases;
1479
2132
  /**
1480
2133
  * Observable version of the Sanity client, with the same configuration as the promise-based one
1481
2134
  */
@@ -1492,7 +2145,7 @@ class SanityClient {
1492
2145
  constructor(httpRequest, config$1 = config.defaultConfig) {
1493
2146
  this.config(config$1), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = {
1494
2147
  action: new AgentActionsClient(this, this.#httpRequest)
1495
- }, this.observable = new ObservableSanityClient(httpRequest, config$1);
2148
+ }, this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config$1);
1496
2149
  }
1497
2150
  /**
1498
2151
  * Clone the client - returns a new instance
@@ -1573,9 +2226,104 @@ class SanityClient {
1573
2226
  _createOrReplace(this, this.#httpRequest, document, options)
1574
2227
  );
1575
2228
  }
2229
+ createVersion({
2230
+ document,
2231
+ publishedId,
2232
+ releaseId
2233
+ }, options) {
2234
+ const documentVersionId = deriveDocumentVersionId("createVersion", {
2235
+ document,
2236
+ publishedId,
2237
+ releaseId
2238
+ }), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || csm.getPublishedId(document._id);
2239
+ return rxjs.firstValueFrom(
2240
+ _createVersion(
2241
+ this,
2242
+ this.#httpRequest,
2243
+ documentVersion,
2244
+ versionPublishedId,
2245
+ options
2246
+ )
2247
+ );
2248
+ }
1576
2249
  delete(selection, options) {
1577
2250
  return rxjs.lastValueFrom(_delete(this, this.#httpRequest, selection, options));
1578
2251
  }
2252
+ /**
2253
+ * @public
2254
+ *
2255
+ * Deletes the draft or release version of a document.
2256
+ *
2257
+ * @remarks
2258
+ * * Discarding a version with no `releaseId` will discard the draft version of the published document.
2259
+ * * If the draft or release version does not exist, any error will throw.
2260
+ *
2261
+ * @param params - Version action parameters:
2262
+ * - `releaseId` - The ID of the release to discard the document from.
2263
+ * - `publishedId` - The published ID of the document to discard.
2264
+ * @param purge - if `true` the document history is also discarded.
2265
+ * @param options - Additional action options.
2266
+ * @returns a promise that resolves to the `transactionId`.
2267
+ *
2268
+ * @example Discarding a release version of a document
2269
+ * ```ts
2270
+ * client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
2271
+ * // The document with the ID `versions.myRelease.myDocument` will be discarded.
2272
+ * ```
2273
+ *
2274
+ * @example Discarding a draft version of a document
2275
+ * ```ts
2276
+ * client.discardVersion({publishedId: 'myDocument'})
2277
+ * // The document with the ID `drafts.myDocument` will be discarded.
2278
+ * ```
2279
+ */
2280
+ discardVersion({ releaseId, publishedId }, purge, options) {
2281
+ const documentVersionId = getDocumentVersionId(publishedId, releaseId);
2282
+ return rxjs.lastValueFrom(
2283
+ _discardVersion(this, this.#httpRequest, documentVersionId, purge, options)
2284
+ );
2285
+ }
2286
+ replaceVersion({
2287
+ document,
2288
+ publishedId,
2289
+ releaseId
2290
+ }, options) {
2291
+ const documentVersionId = deriveDocumentVersionId("replaceVersion", {
2292
+ document,
2293
+ publishedId,
2294
+ releaseId
2295
+ }), documentVersion = { ...document, _id: documentVersionId };
2296
+ return rxjs.firstValueFrom(
2297
+ _replaceVersion(this, this.#httpRequest, documentVersion, options)
2298
+ );
2299
+ }
2300
+ /**
2301
+ * @public
2302
+ *
2303
+ * Used to indicate when a document within a release should be unpublished when
2304
+ * the release is run.
2305
+ *
2306
+ * @remarks
2307
+ * * If the published document does not exist, an error will be thrown.
2308
+ *
2309
+ * @param params - Version action parameters:
2310
+ * - `releaseId` - The ID of the release to unpublish the document from.
2311
+ * - `publishedId` - The published ID of the document to unpublish.
2312
+ * @param options - Additional action options.
2313
+ * @returns a promise that resolves to the `transactionId`.
2314
+ *
2315
+ * @example Unpublishing a release version of a published document
2316
+ * ```ts
2317
+ * await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
2318
+ * // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
2319
+ * ```
2320
+ */
2321
+ unpublishVersion({ releaseId, publishedId }, options) {
2322
+ const versionId = csm.getVersionId(publishedId, releaseId);
2323
+ return rxjs.lastValueFrom(
2324
+ _unpublishVersion(this, this.#httpRequest, versionId, publishedId, options)
2325
+ );
2326
+ }
1579
2327
  mutate(operations, options) {
1580
2328
  return rxjs.lastValueFrom(_mutate(this, this.#httpRequest, operations, options));
1581
2329
  }
@@ -1668,7 +2416,7 @@ function defineDeprecatedCreateClient(createClient2) {
1668
2416
  return config.printNoDefaultExport(), createClient2(config$1);
1669
2417
  };
1670
2418
  }
1671
- var name = "@sanity/client", version = "7.1.0";
2419
+ var name = "@sanity/client", version = "7.2.1-agent-actions.0";
1672
2420
  const middleware = [
1673
2421
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
1674
2422
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),