@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.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { getIt } from "get-it";
2
2
  import { adapter, environment } from "get-it";
3
3
  import { retry, jsonRequest, jsonResponse, progress, observable, debug, headers, agent } from "get-it/middleware";
4
- import { Observable, defer, of, isObservable, mergeMap, from, lastValueFrom, shareReplay, catchError, concat, throwError, timer, tap, finalize, share, merge, EMPTY } from "rxjs";
4
+ import { Observable, defer, of, isObservable, mergeMap, from, lastValueFrom, shareReplay, catchError, concat, throwError, timer, tap, finalize, share, merge, EMPTY, map as map$1, firstValueFrom } from "rxjs";
5
5
  import { stegaClean } from "./_chunks-es/stegaClean.js";
6
6
  import { combineLatestWith, map, filter, finalize as finalize$1 } from "rxjs/operators";
7
- import { validateObject, validateInsert, requireDocumentId, validateDocumentId, resourceConfig, hasDataset, requestTag, printPreviewDraftsDeprecationWarning, validateApiPerspective, printCdnPreviewDraftsWarning, validateAssetType, resourceGuard, dataset, defaultConfig, initConfig, printNoDefaultExport } from "./_chunks-es/config.js";
7
+ import { getVersionFromId, isDraftId, getVersionId, getDraftId, isVersionId, getPublishedId } from "@sanity/client/csm";
8
+ import { customAlphabet } from "nanoid";
9
+ import { validateObject, validateInsert, requireDocumentId, validateDocumentId, requireDocumentType, resourceConfig, hasDataset, requestTag, printPreviewDraftsDeprecationWarning, validateApiPerspective, printCdnPreviewDraftsWarning, validateAssetType, resourceGuard, dataset, validateVersionIdMatch, defaultConfig, initConfig, printNoDefaultExport } from "./_chunks-es/config.js";
8
10
  class ClientError extends Error {
9
11
  response;
10
12
  statusCode = 400;
@@ -619,8 +621,24 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
619
621
  ) : $request.pipe(map(mapResponse));
620
622
  }
621
623
  function _getDocument(client, httpRequest, id, opts = {}) {
622
- const options = {
623
- uri: _getDataUrl(client, "doc", id),
624
+ const docId = (() => {
625
+ if (!opts.releaseId)
626
+ return id;
627
+ const versionId = getVersionFromId(id);
628
+ if (!versionId) {
629
+ if (isDraftId(id))
630
+ throw new Error(
631
+ `The document ID (\`${id}\`) is a draft, but \`options.releaseId\` is set as \`${opts.releaseId}\``
632
+ );
633
+ return getVersionId(id, opts.releaseId);
634
+ }
635
+ if (versionId !== opts.releaseId)
636
+ throw new Error(
637
+ `The document ID (\`${id}\`) is already a version of \`${versionId}\` release, but this does not match the provided \`options.releaseId\` (\`${opts.releaseId}\`)`
638
+ );
639
+ return id;
640
+ })(), options = {
641
+ uri: _getDataUrl(client, "doc", docId),
624
642
  json: !0,
625
643
  tag: opts.tag,
626
644
  signal: opts.signal
@@ -645,12 +663,33 @@ function _getDocuments(client, httpRequest, ids, opts = {}) {
645
663
  })
646
664
  );
647
665
  }
666
+ function _getReleaseDocuments(client, httpRequest, releaseId, opts = {}) {
667
+ return _dataRequest(
668
+ client,
669
+ httpRequest,
670
+ "query",
671
+ {
672
+ query: "*[sanity::partOfRelease($releaseId)]",
673
+ params: {
674
+ releaseId
675
+ }
676
+ },
677
+ opts
678
+ );
679
+ }
648
680
  function _createIfNotExists(client, httpRequest, doc, options) {
649
681
  return requireDocumentId("createIfNotExists", doc), _create(client, httpRequest, doc, "createIfNotExists", options);
650
682
  }
651
683
  function _createOrReplace(client, httpRequest, doc, options) {
652
684
  return requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
653
685
  }
686
+ function _createVersion(client, httpRequest, doc, publishedId, options) {
687
+ return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), _action(client, httpRequest, {
688
+ actionType: "sanity.action.document.version.create",
689
+ publishedId,
690
+ document: doc
691
+ }, options);
692
+ }
654
693
  function _delete(client, httpRequest, selection, options) {
655
694
  return _dataRequest(
656
695
  client,
@@ -660,6 +699,26 @@ function _delete(client, httpRequest, selection, options) {
660
699
  options
661
700
  );
662
701
  }
702
+ function _discardVersion(client, httpRequest, versionId, purge = !1, options) {
703
+ return _action(client, httpRequest, {
704
+ actionType: "sanity.action.document.version.discard",
705
+ versionId,
706
+ purge
707
+ }, options);
708
+ }
709
+ function _replaceVersion(client, httpRequest, doc, options) {
710
+ return requireDocumentId("replaceVersion", doc), requireDocumentType("replaceVersion", doc), _action(client, httpRequest, {
711
+ actionType: "sanity.action.document.version.replace",
712
+ document: doc
713
+ }, options);
714
+ }
715
+ function _unpublishVersion(client, httpRequest, versionId, publishedId, options) {
716
+ return _action(client, httpRequest, {
717
+ actionType: "sanity.action.document.version.unpublish",
718
+ versionId,
719
+ publishedId
720
+ }, options);
721
+ }
663
722
  function _mutate(client, httpRequest, mutations, options) {
664
723
  let mut;
665
724
  mutations instanceof Patch || mutations instanceof ObservablePatch ? mut = { patch: mutations.serialize() } : mutations instanceof Transaction || mutations instanceof ObservableTransaction ? mut = mutations.serialize() : mut = mutations;
@@ -814,6 +873,14 @@ function _generate(client, httpRequest, request) {
814
873
  body: request
815
874
  });
816
875
  }
876
+ function _prompt(client, httpRequest, request) {
877
+ const dataset2 = hasDataset(client.config());
878
+ return _request(client, httpRequest, {
879
+ method: "POST",
880
+ uri: `/agent/action/prompt/${dataset2}`,
881
+ body: request
882
+ });
883
+ }
817
884
  function _transform(client, httpRequest, request) {
818
885
  const dataset2 = hasDataset(client.config());
819
886
  return _request(client, httpRequest, {
@@ -885,6 +952,13 @@ class AgentActionsClient {
885
952
  translate(request) {
886
953
  return lastValueFrom(_translate(this.#client, this.#httpRequest, request));
887
954
  }
955
+ /**
956
+ * Run a raw instruction and return the result either as text or json
957
+ * @param request - prompt request
958
+ */
959
+ prompt(request) {
960
+ return lastValueFrom(_prompt(this.#client, this.#httpRequest, request));
961
+ }
888
962
  }
889
963
  class ObservableAssetsClient {
890
964
  #client;
@@ -1262,6 +1336,498 @@ class ProjectsClient {
1262
1336
  );
1263
1337
  }
1264
1338
  }
1339
+ const generateReleaseId = customAlphabet(
1340
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
1341
+ 8
1342
+ ), getDocumentVersionId = (publishedId, releaseId) => releaseId ? getVersionId(publishedId, releaseId) : getDraftId(publishedId);
1343
+ function deriveDocumentVersionId(op, {
1344
+ releaseId,
1345
+ publishedId,
1346
+ document
1347
+ }) {
1348
+ if (publishedId && document._id) {
1349
+ const versionId = getDocumentVersionId(publishedId, releaseId);
1350
+ return validateVersionIdMatch(versionId, document), versionId;
1351
+ }
1352
+ if (document._id) {
1353
+ const isDraft = isDraftId(document._id), isVersion = isVersionId(document._id);
1354
+ if (!isDraft && !isVersion)
1355
+ throw new Error(
1356
+ `\`${op}()\` requires a document with an \`_id\` that is a version or draft ID`
1357
+ );
1358
+ if (releaseId) {
1359
+ if (isDraft)
1360
+ throw new Error(
1361
+ `\`${op}()\` was called with a document ID (\`${document._id}\`) that is a draft ID, but a release ID (\`${releaseId}\`) was also provided.`
1362
+ );
1363
+ const builtVersionId = getVersionFromId(document._id);
1364
+ if (builtVersionId !== releaseId)
1365
+ throw new Error(
1366
+ `\`${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}\`).`
1367
+ );
1368
+ }
1369
+ return document._id;
1370
+ }
1371
+ if (publishedId)
1372
+ return getDocumentVersionId(publishedId, releaseId);
1373
+ throw new Error(`\`${op}()\` requires either a publishedId or a document with an \`_id\``);
1374
+ }
1375
+ const getArgs = (releaseOrOptions, maybeOptions) => {
1376
+ if (typeof releaseOrOptions == "object" && releaseOrOptions !== null && ("releaseId" in releaseOrOptions || "metadata" in releaseOrOptions)) {
1377
+ const { releaseId = generateReleaseId(), metadata = {} } = releaseOrOptions;
1378
+ return [releaseId, metadata, maybeOptions];
1379
+ }
1380
+ return [generateReleaseId(), {}, releaseOrOptions];
1381
+ }, createRelease = (releaseOrOptions, maybeOptions) => {
1382
+ const [releaseId, metadata, options] = getArgs(releaseOrOptions, maybeOptions), finalMetadata = {
1383
+ ...metadata,
1384
+ releaseType: metadata.releaseType || "undecided"
1385
+ };
1386
+ return { action: {
1387
+ actionType: "sanity.action.release.create",
1388
+ releaseId,
1389
+ metadata: finalMetadata
1390
+ }, options };
1391
+ };
1392
+ class ObservableReleasesClient {
1393
+ #client;
1394
+ #httpRequest;
1395
+ constructor(client, httpRequest) {
1396
+ this.#client = client, this.#httpRequest = httpRequest;
1397
+ }
1398
+ /**
1399
+ * @public
1400
+ *
1401
+ * Retrieve a release by id.
1402
+ *
1403
+ * @category Releases
1404
+ *
1405
+ * @param params - Release action parameters:
1406
+ * - `releaseId` - The id of the release to retrieve.
1407
+ * @param options - Additional query options including abort signal and query tag.
1408
+ * @returns An observable that resolves to the release document {@link ReleaseDocument}.
1409
+ *
1410
+ * @example Retrieving a release by id
1411
+ * ```ts
1412
+ * client.observable.releases.get({releaseId: 'my-release'}).pipe(
1413
+ * tap((release) => console.log(release)),
1414
+ * // {
1415
+ * // _id: '_.releases.my-release',
1416
+ * // name: 'my-release'
1417
+ * // _type: 'system.release',
1418
+ * // metadata: {releaseType: 'asap'},
1419
+ * // _createdAt: '2021-01-01T00:00:00.000Z',
1420
+ * // ...
1421
+ * // }
1422
+ * ).subscribe()
1423
+ * ```
1424
+ */
1425
+ get({ releaseId }, options) {
1426
+ return _getDocument(
1427
+ this.#client,
1428
+ this.#httpRequest,
1429
+ `_.releases.${releaseId}`,
1430
+ options
1431
+ );
1432
+ }
1433
+ create(releaseOrOptions, maybeOptions) {
1434
+ const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
1435
+ return _action(this.#client, this.#httpRequest, action, options).pipe(
1436
+ map$1((actionResult) => ({
1437
+ ...actionResult,
1438
+ releaseId,
1439
+ metadata
1440
+ }))
1441
+ );
1442
+ }
1443
+ /**
1444
+ * @public
1445
+ *
1446
+ * Edits an existing release, updating the metadata.
1447
+ *
1448
+ * @category Releases
1449
+ *
1450
+ * @param params - Release action parameters:
1451
+ * - `releaseId` - The id of the release to edit.
1452
+ * - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
1453
+ * @param options - Additional action options.
1454
+ * @returns An observable that resolves to the `transactionId`.
1455
+ */
1456
+ edit({ releaseId, patch }, options) {
1457
+ const editAction = {
1458
+ actionType: "sanity.action.release.edit",
1459
+ releaseId,
1460
+ patch
1461
+ };
1462
+ return _action(this.#client, this.#httpRequest, editAction, options);
1463
+ }
1464
+ /**
1465
+ * @public
1466
+ *
1467
+ * Publishes all documents in a release at once. For larger releases the effect of the publish
1468
+ * will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
1469
+ * documents and creation of the corresponding published documents with the new content may
1470
+ * take some time.
1471
+ *
1472
+ * During this period both the source and target documents are locked and cannot be
1473
+ * modified through any other means.
1474
+ *
1475
+ * @category Releases
1476
+ *
1477
+ * @param params - Release action parameters:
1478
+ * - `releaseId` - The id of the release to publish.
1479
+ * @param options - Additional action options.
1480
+ * @returns An observable that resolves to the `transactionId`.
1481
+ */
1482
+ publish({ releaseId }, options) {
1483
+ const publishAction = {
1484
+ actionType: "sanity.action.release.publish",
1485
+ releaseId
1486
+ };
1487
+ return _action(this.#client, this.#httpRequest, publishAction, options);
1488
+ }
1489
+ /**
1490
+ * @public
1491
+ *
1492
+ * An archive action removes an active release. The documents that comprise the release
1493
+ * are deleted and therefore no longer queryable.
1494
+ *
1495
+ * While the documents remain in retention the last version can still be accessed using document history endpoint.
1496
+ *
1497
+ * @category Releases
1498
+ *
1499
+ * @param params - Release action parameters:
1500
+ * - `releaseId` - The id of the release to archive.
1501
+ * @param options - Additional action options.
1502
+ * @returns An observable that resolves to the `transactionId`.
1503
+ */
1504
+ archive({ releaseId }, options) {
1505
+ const archiveAction = {
1506
+ actionType: "sanity.action.release.archive",
1507
+ releaseId
1508
+ };
1509
+ return _action(this.#client, this.#httpRequest, archiveAction, options);
1510
+ }
1511
+ /**
1512
+ * @public
1513
+ *
1514
+ * An unarchive action restores an archived release and all documents
1515
+ * with the content they had just prior to archiving.
1516
+ *
1517
+ * @category Releases
1518
+ *
1519
+ * @param params - Release action parameters:
1520
+ * - `releaseId` - The id of the release to unarchive.
1521
+ * @param options - Additional action options.
1522
+ * @returns An observable that resolves to the `transactionId`.
1523
+ */
1524
+ unarchive({ releaseId }, options) {
1525
+ const unarchiveAction = {
1526
+ actionType: "sanity.action.release.unarchive",
1527
+ releaseId
1528
+ };
1529
+ return _action(this.#client, this.#httpRequest, unarchiveAction, options);
1530
+ }
1531
+ /**
1532
+ * @public
1533
+ *
1534
+ * A schedule action queues a release for publishing at the given future time.
1535
+ * The release is locked such that no documents in the release can be modified and
1536
+ * no documents that it references can be deleted as this would make the publish fail.
1537
+ * At the given time, the same logic as for the publish action is triggered.
1538
+ *
1539
+ * @category Releases
1540
+ *
1541
+ * @param params - Release action parameters:
1542
+ * - `releaseId` - The id of the release to schedule.
1543
+ * - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
1544
+ * @param options - Additional action options.
1545
+ * @returns An observable that resolves to the `transactionId`.
1546
+ */
1547
+ schedule({ releaseId, publishAt }, options) {
1548
+ const scheduleAction = {
1549
+ actionType: "sanity.action.release.schedule",
1550
+ releaseId,
1551
+ publishAt
1552
+ };
1553
+ return _action(this.#client, this.#httpRequest, scheduleAction, options);
1554
+ }
1555
+ /**
1556
+ * @public
1557
+ *
1558
+ * An unschedule action stops a release from being published.
1559
+ * The documents in the release are considered unlocked and can be edited again.
1560
+ * This may fail if another release is scheduled to be published after this one and
1561
+ * has a reference to a document created by this one.
1562
+ *
1563
+ * @category Releases
1564
+ *
1565
+ * @param params - Release action parameters:
1566
+ * - `releaseId` - The id of the release to unschedule.
1567
+ * @param options - Additional action options.
1568
+ * @returns An observable that resolves to the `transactionId`.
1569
+ */
1570
+ unschedule({ releaseId }, options) {
1571
+ const unscheduleAction = {
1572
+ actionType: "sanity.action.release.unschedule",
1573
+ releaseId
1574
+ };
1575
+ return _action(this.#client, this.#httpRequest, unscheduleAction, options);
1576
+ }
1577
+ /**
1578
+ * @public
1579
+ *
1580
+ * A delete action removes a published or archived release.
1581
+ * The backing system document will be removed from the dataset.
1582
+ *
1583
+ * @category Releases
1584
+ *
1585
+ * @param params - Release action parameters:
1586
+ * - `releaseId` - The id of the release to delete.
1587
+ * @param options - Additional action options.
1588
+ * @returns An observable that resolves to the `transactionId`.
1589
+ */
1590
+ delete({ releaseId }, options) {
1591
+ const deleteAction = {
1592
+ actionType: "sanity.action.release.delete",
1593
+ releaseId
1594
+ };
1595
+ return _action(this.#client, this.#httpRequest, deleteAction, options);
1596
+ }
1597
+ /**
1598
+ * @public
1599
+ *
1600
+ * Fetch the documents in a release by release id.
1601
+ *
1602
+ * @category Releases
1603
+ *
1604
+ * @param params - Release action parameters:
1605
+ * - `releaseId` - The id of the release to fetch documents for.
1606
+ * @param options - Additional mutation options {@link BaseMutationOptions}.
1607
+ * @returns An observable that resolves to the documents in the release.
1608
+ */
1609
+ fetchDocuments({ releaseId }, options) {
1610
+ return _getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options);
1611
+ }
1612
+ }
1613
+ class ReleasesClient {
1614
+ #client;
1615
+ #httpRequest;
1616
+ constructor(client, httpRequest) {
1617
+ this.#client = client, this.#httpRequest = httpRequest;
1618
+ }
1619
+ /**
1620
+ * @public
1621
+ *
1622
+ * Retrieve a release by id.
1623
+ *
1624
+ * @category Releases
1625
+ *
1626
+ * @param params - Release action parameters:
1627
+ * - `releaseId` - The id of the release to retrieve.
1628
+ * @param options - Additional query options including abort signal and query tag.
1629
+ * @returns A promise that resolves to the release document {@link ReleaseDocument}.
1630
+ *
1631
+ * @example Retrieving a release by id
1632
+ * ```ts
1633
+ * const release = await client.releases.get({releaseId: 'my-release'})
1634
+ * console.log(release)
1635
+ * // {
1636
+ * // _id: '_.releases.my-release',
1637
+ * // name: 'my-release'
1638
+ * // _type: 'system.release',
1639
+ * // metadata: {releaseType: 'asap'},
1640
+ * // _createdAt: '2021-01-01T00:00:00.000Z',
1641
+ * // ...
1642
+ * // }
1643
+ * ```
1644
+ */
1645
+ get({ releaseId }, options) {
1646
+ return lastValueFrom(
1647
+ _getDocument(
1648
+ this.#client,
1649
+ this.#httpRequest,
1650
+ `_.releases.${releaseId}`,
1651
+ options
1652
+ )
1653
+ );
1654
+ }
1655
+ async create(releaseOrOptions, maybeOptions) {
1656
+ const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
1657
+ return { ...await lastValueFrom(
1658
+ _action(this.#client, this.#httpRequest, action, options)
1659
+ ), releaseId, metadata };
1660
+ }
1661
+ /**
1662
+ * @public
1663
+ *
1664
+ * Edits an existing release, updating the metadata.
1665
+ *
1666
+ * @category Releases
1667
+ *
1668
+ * @param params - Release action parameters:
1669
+ * - `releaseId` - The id of the release to edit.
1670
+ * - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
1671
+ * @param options - Additional action options.
1672
+ * @returns A promise that resolves to the `transactionId`.
1673
+ */
1674
+ edit({ releaseId, patch }, options) {
1675
+ const editAction = {
1676
+ actionType: "sanity.action.release.edit",
1677
+ releaseId,
1678
+ patch
1679
+ };
1680
+ return lastValueFrom(_action(this.#client, this.#httpRequest, editAction, options));
1681
+ }
1682
+ /**
1683
+ * @public
1684
+ *
1685
+ * Publishes all documents in a release at once. For larger releases the effect of the publish
1686
+ * will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
1687
+ * documents and creation of the corresponding published documents with the new content may
1688
+ * take some time.
1689
+ *
1690
+ * During this period both the source and target documents are locked and cannot be
1691
+ * modified through any other means.
1692
+ *
1693
+ * @category Releases
1694
+ *
1695
+ * @param params - Release action parameters:
1696
+ * - `releaseId` - The id of the release to publish.
1697
+ * @param options - Additional action options.
1698
+ * @returns A promise that resolves to the `transactionId`.
1699
+ */
1700
+ publish({ releaseId }, options) {
1701
+ const publishAction = {
1702
+ actionType: "sanity.action.release.publish",
1703
+ releaseId
1704
+ };
1705
+ return lastValueFrom(_action(this.#client, this.#httpRequest, publishAction, options));
1706
+ }
1707
+ /**
1708
+ * @public
1709
+ *
1710
+ * An archive action removes an active release. The documents that comprise the release
1711
+ * are deleted and therefore no longer queryable.
1712
+ *
1713
+ * While the documents remain in retention the last version can still be accessed using document history endpoint.
1714
+ *
1715
+ * @category Releases
1716
+ *
1717
+ * @param params - Release action parameters:
1718
+ * - `releaseId` - The id of the release to archive.
1719
+ * @param options - Additional action options.
1720
+ * @returns A promise that resolves to the `transactionId`.
1721
+ */
1722
+ archive({ releaseId }, options) {
1723
+ const archiveAction = {
1724
+ actionType: "sanity.action.release.archive",
1725
+ releaseId
1726
+ };
1727
+ return lastValueFrom(_action(this.#client, this.#httpRequest, archiveAction, options));
1728
+ }
1729
+ /**
1730
+ * @public
1731
+ *
1732
+ * An unarchive action restores an archived release and all documents
1733
+ * with the content they had just prior to archiving.
1734
+ *
1735
+ * @category Releases
1736
+ *
1737
+ * @param params - Release action parameters:
1738
+ * - `releaseId` - The id of the release to unarchive.
1739
+ * @param options - Additional action options.
1740
+ * @returns A promise that resolves to the `transactionId`.
1741
+ */
1742
+ unarchive({ releaseId }, options) {
1743
+ const unarchiveAction = {
1744
+ actionType: "sanity.action.release.unarchive",
1745
+ releaseId
1746
+ };
1747
+ return lastValueFrom(_action(this.#client, this.#httpRequest, unarchiveAction, options));
1748
+ }
1749
+ /**
1750
+ * @public
1751
+ *
1752
+ * A schedule action queues a release for publishing at the given future time.
1753
+ * The release is locked such that no documents in the release can be modified and
1754
+ * no documents that it references can be deleted as this would make the publish fail.
1755
+ * At the given time, the same logic as for the publish action is triggered.
1756
+ *
1757
+ * @category Releases
1758
+ *
1759
+ * @param params - Release action parameters:
1760
+ * - `releaseId` - The id of the release to schedule.
1761
+ * - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
1762
+ * @param options - Additional action options.
1763
+ * @returns A promise that resolves to the `transactionId`.
1764
+ */
1765
+ schedule({ releaseId, publishAt }, options) {
1766
+ const scheduleAction = {
1767
+ actionType: "sanity.action.release.schedule",
1768
+ releaseId,
1769
+ publishAt
1770
+ };
1771
+ return lastValueFrom(_action(this.#client, this.#httpRequest, scheduleAction, options));
1772
+ }
1773
+ /**
1774
+ * @public
1775
+ *
1776
+ * An unschedule action stops a release from being published.
1777
+ * The documents in the release are considered unlocked and can be edited again.
1778
+ * This may fail if another release is scheduled to be published after this one and
1779
+ * has a reference to a document created by this one.
1780
+ *
1781
+ * @category Releases
1782
+ *
1783
+ * @param params - Release action parameters:
1784
+ * - `releaseId` - The id of the release to unschedule.
1785
+ * @param options - Additional action options.
1786
+ * @returns A promise that resolves to the `transactionId`.
1787
+ */
1788
+ unschedule({ releaseId }, options) {
1789
+ const unscheduleAction = {
1790
+ actionType: "sanity.action.release.unschedule",
1791
+ releaseId
1792
+ };
1793
+ return lastValueFrom(_action(this.#client, this.#httpRequest, unscheduleAction, options));
1794
+ }
1795
+ /**
1796
+ * @public
1797
+ *
1798
+ * A delete action removes a published or archived release.
1799
+ * The backing system document will be removed from the dataset.
1800
+ *
1801
+ * @category Releases
1802
+ *
1803
+ * @param params - Release action parameters:
1804
+ * - `releaseId` - The id of the release to delete.
1805
+ * @param options - Additional action options.
1806
+ * @returns A promise that resolves to the `transactionId`.
1807
+ */
1808
+ delete({ releaseId }, options) {
1809
+ const deleteAction = {
1810
+ actionType: "sanity.action.release.delete",
1811
+ releaseId
1812
+ };
1813
+ return lastValueFrom(_action(this.#client, this.#httpRequest, deleteAction, options));
1814
+ }
1815
+ /**
1816
+ * @public
1817
+ *
1818
+ * Fetch the documents in a release by release id.
1819
+ *
1820
+ * @category Releases
1821
+ *
1822
+ * @param params - Release action parameters:
1823
+ * - `releaseId` - The id of the release to fetch documents for.
1824
+ * @param options - Additional mutation options {@link BaseMutationOptions}.
1825
+ * @returns A promise that resolves to the documents in the release.
1826
+ */
1827
+ fetchDocuments({ releaseId }, options) {
1828
+ return lastValueFrom(_getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options));
1829
+ }
1830
+ }
1265
1831
  class ObservableUsersClient {
1266
1832
  #client;
1267
1833
  #httpRequest;
@@ -1307,6 +1873,7 @@ class ObservableSanityClient {
1307
1873
  projects;
1308
1874
  users;
1309
1875
  agent;
1876
+ releases;
1310
1877
  /**
1311
1878
  * Private properties
1312
1879
  */
@@ -1319,7 +1886,7 @@ class ObservableSanityClient {
1319
1886
  constructor(httpRequest, config = defaultConfig) {
1320
1887
  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.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = {
1321
1888
  action: new ObservableAgentsActionClient(this, this.#httpRequest)
1322
- };
1889
+ }, this.releases = new ObservableReleasesClient(this, this.#httpRequest);
1323
1890
  }
1324
1891
  /**
1325
1892
  * Clone the client - returns a new instance
@@ -1392,9 +1959,96 @@ class ObservableSanityClient {
1392
1959
  createOrReplace(document, options) {
1393
1960
  return _createOrReplace(this, this.#httpRequest, document, options);
1394
1961
  }
1962
+ createVersion({
1963
+ document,
1964
+ publishedId,
1965
+ releaseId
1966
+ }, options) {
1967
+ const documentVersionId = deriveDocumentVersionId("createVersion", {
1968
+ document,
1969
+ publishedId,
1970
+ releaseId
1971
+ }), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || getPublishedId(document._id);
1972
+ return _createVersion(
1973
+ this,
1974
+ this.#httpRequest,
1975
+ documentVersion,
1976
+ versionPublishedId,
1977
+ options
1978
+ );
1979
+ }
1395
1980
  delete(selection, options) {
1396
1981
  return _delete(this, this.#httpRequest, selection, options);
1397
1982
  }
1983
+ /**
1984
+ * @public
1985
+ *
1986
+ * Deletes the draft or release version of a document.
1987
+ *
1988
+ * @remarks
1989
+ * * Discarding a version with no `releaseId` will discard the draft version of the published document.
1990
+ * * If the draft or release version does not exist, any error will throw.
1991
+ *
1992
+ * @param params - Version action parameters:
1993
+ * - `releaseId` - The ID of the release to discard the document from.
1994
+ * - `publishedId` - The published ID of the document to discard.
1995
+ * @param purge - if `true` the document history is also discarded.
1996
+ * @param options - Additional action options.
1997
+ * @returns an observable that resolves to the `transactionId`.
1998
+ *
1999
+ * @example Discarding a release version of a document
2000
+ * ```ts
2001
+ * client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
2002
+ * // The document with the ID `versions.myRelease.myDocument` will be discarded.
2003
+ * ```
2004
+ *
2005
+ * @example Discarding a draft version of a document
2006
+ * ```ts
2007
+ * client.observable.discardVersion({publishedId: 'myDocument'})
2008
+ * // The document with the ID `drafts.myDocument` will be discarded.
2009
+ * ```
2010
+ */
2011
+ discardVersion({ releaseId, publishedId }, purge, options) {
2012
+ const documentVersionId = getDocumentVersionId(publishedId, releaseId);
2013
+ return _discardVersion(this, this.#httpRequest, documentVersionId, purge, options);
2014
+ }
2015
+ replaceVersion({
2016
+ document,
2017
+ publishedId,
2018
+ releaseId
2019
+ }, options) {
2020
+ const documentVersionId = deriveDocumentVersionId("replaceVersion", {
2021
+ document,
2022
+ publishedId,
2023
+ releaseId
2024
+ }), documentVersion = { ...document, _id: documentVersionId };
2025
+ return _replaceVersion(this, this.#httpRequest, documentVersion, options);
2026
+ }
2027
+ /**
2028
+ * @public
2029
+ *
2030
+ * Used to indicate when a document within a release should be unpublished when
2031
+ * the release is run.
2032
+ *
2033
+ * @remarks
2034
+ * * If the published document does not exist, an error will be thrown.
2035
+ *
2036
+ * @param params - Version action parameters:
2037
+ * - `releaseId` - The ID of the release to unpublish the document from.
2038
+ * - `publishedId` - The published ID of the document to unpublish.
2039
+ * @param options - Additional action options.
2040
+ * @returns an observable that resolves to the `transactionId`.
2041
+ *
2042
+ * @example Unpublishing a release version of a published document
2043
+ * ```ts
2044
+ * client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
2045
+ * // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
2046
+ * ```
2047
+ */
2048
+ unpublishVersion({ releaseId, publishedId }, options) {
2049
+ const versionId = getVersionId(publishedId, releaseId);
2050
+ return _unpublishVersion(this, this.#httpRequest, versionId, publishedId, options);
2051
+ }
1398
2052
  mutate(operations, options) {
1399
2053
  return _mutate(this, this.#httpRequest, operations, options);
1400
2054
  }
@@ -1459,6 +2113,7 @@ class SanityClient {
1459
2113
  projects;
1460
2114
  users;
1461
2115
  agent;
2116
+ releases;
1462
2117
  /**
1463
2118
  * Observable version of the Sanity client, with the same configuration as the promise-based one
1464
2119
  */
@@ -1475,7 +2130,7 @@ class SanityClient {
1475
2130
  constructor(httpRequest, config = defaultConfig) {
1476
2131
  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.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = {
1477
2132
  action: new AgentActionsClient(this, this.#httpRequest)
1478
- }, this.observable = new ObservableSanityClient(httpRequest, config);
2133
+ }, this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
1479
2134
  }
1480
2135
  /**
1481
2136
  * Clone the client - returns a new instance
@@ -1556,9 +2211,104 @@ class SanityClient {
1556
2211
  _createOrReplace(this, this.#httpRequest, document, options)
1557
2212
  );
1558
2213
  }
2214
+ createVersion({
2215
+ document,
2216
+ publishedId,
2217
+ releaseId
2218
+ }, options) {
2219
+ const documentVersionId = deriveDocumentVersionId("createVersion", {
2220
+ document,
2221
+ publishedId,
2222
+ releaseId
2223
+ }), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || getPublishedId(document._id);
2224
+ return firstValueFrom(
2225
+ _createVersion(
2226
+ this,
2227
+ this.#httpRequest,
2228
+ documentVersion,
2229
+ versionPublishedId,
2230
+ options
2231
+ )
2232
+ );
2233
+ }
1559
2234
  delete(selection, options) {
1560
2235
  return lastValueFrom(_delete(this, this.#httpRequest, selection, options));
1561
2236
  }
2237
+ /**
2238
+ * @public
2239
+ *
2240
+ * Deletes the draft or release version of a document.
2241
+ *
2242
+ * @remarks
2243
+ * * Discarding a version with no `releaseId` will discard the draft version of the published document.
2244
+ * * If the draft or release version does not exist, any error will throw.
2245
+ *
2246
+ * @param params - Version action parameters:
2247
+ * - `releaseId` - The ID of the release to discard the document from.
2248
+ * - `publishedId` - The published ID of the document to discard.
2249
+ * @param purge - if `true` the document history is also discarded.
2250
+ * @param options - Additional action options.
2251
+ * @returns a promise that resolves to the `transactionId`.
2252
+ *
2253
+ * @example Discarding a release version of a document
2254
+ * ```ts
2255
+ * client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
2256
+ * // The document with the ID `versions.myRelease.myDocument` will be discarded.
2257
+ * ```
2258
+ *
2259
+ * @example Discarding a draft version of a document
2260
+ * ```ts
2261
+ * client.discardVersion({publishedId: 'myDocument'})
2262
+ * // The document with the ID `drafts.myDocument` will be discarded.
2263
+ * ```
2264
+ */
2265
+ discardVersion({ releaseId, publishedId }, purge, options) {
2266
+ const documentVersionId = getDocumentVersionId(publishedId, releaseId);
2267
+ return lastValueFrom(
2268
+ _discardVersion(this, this.#httpRequest, documentVersionId, purge, options)
2269
+ );
2270
+ }
2271
+ replaceVersion({
2272
+ document,
2273
+ publishedId,
2274
+ releaseId
2275
+ }, options) {
2276
+ const documentVersionId = deriveDocumentVersionId("replaceVersion", {
2277
+ document,
2278
+ publishedId,
2279
+ releaseId
2280
+ }), documentVersion = { ...document, _id: documentVersionId };
2281
+ return firstValueFrom(
2282
+ _replaceVersion(this, this.#httpRequest, documentVersion, options)
2283
+ );
2284
+ }
2285
+ /**
2286
+ * @public
2287
+ *
2288
+ * Used to indicate when a document within a release should be unpublished when
2289
+ * the release is run.
2290
+ *
2291
+ * @remarks
2292
+ * * If the published document does not exist, an error will be thrown.
2293
+ *
2294
+ * @param params - Version action parameters:
2295
+ * - `releaseId` - The ID of the release to unpublish the document from.
2296
+ * - `publishedId` - The published ID of the document to unpublish.
2297
+ * @param options - Additional action options.
2298
+ * @returns a promise that resolves to the `transactionId`.
2299
+ *
2300
+ * @example Unpublishing a release version of a published document
2301
+ * ```ts
2302
+ * await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
2303
+ * // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
2304
+ * ```
2305
+ */
2306
+ unpublishVersion({ releaseId, publishedId }, options) {
2307
+ const versionId = getVersionId(publishedId, releaseId);
2308
+ return lastValueFrom(
2309
+ _unpublishVersion(this, this.#httpRequest, versionId, publishedId, options)
2310
+ );
2311
+ }
1562
2312
  mutate(operations, options) {
1563
2313
  return lastValueFrom(_mutate(this, this.#httpRequest, operations, options));
1564
2314
  }
@@ -1651,7 +2401,7 @@ function defineDeprecatedCreateClient(createClient2) {
1651
2401
  return printNoDefaultExport(), createClient2(config);
1652
2402
  };
1653
2403
  }
1654
- var name = "@sanity/client", version = "7.1.0";
2404
+ var name = "@sanity/client", version = "7.2.1-agent-actions.0";
1655
2405
  const middleware = [
1656
2406
  debug({ verbose: !0, namespace: "sanity:client" }),
1657
2407
  headers({ "User-Agent": `${name} ${version}` }),