@sanity/client 8.0.0 → 8.2.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.
Files changed (58) hide show
  1. package/README.md +265 -0
  2. package/dist/{browserUpload-CQgx9YYo.js → browserUpload-2tz6Sdqp.js} +4 -3
  3. package/dist/browserUpload-2tz6Sdqp.js.map +1 -0
  4. package/dist/{browserUpload-icWlVP15.js → browserUpload-CwpNx7Vl.js} +4 -3
  5. package/dist/browserUpload-CwpNx7Vl.js.map +1 -0
  6. package/dist/{config-a8VajuEY.js → config-3wiPP-sZ.js} +2 -2
  7. package/dist/config-3wiPP-sZ.js.map +1 -0
  8. package/dist/csm.js +2 -2
  9. package/dist/csm.js.map +1 -1
  10. package/dist/index.d.ts +17 -11
  11. package/dist/index.js +610 -136
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.node.d.ts +918 -26
  14. package/dist/index.node.js +559 -66
  15. package/dist/index.node.js.map +1 -1
  16. package/dist/media-library.d.ts +1 -1
  17. package/dist/{request-CJxcN16k.js → request-BhMuKj0D.js} +10 -9
  18. package/dist/request-BhMuKj0D.js.map +1 -0
  19. package/dist/{request-k7VS_NnC.js → request-SnMg7nUX.js} +10 -9
  20. package/dist/request-SnMg7nUX.js.map +1 -0
  21. package/dist/{resolveEditInfo-sq7yF78q.js → resolveEditInfo-Cz-smq3a.js} +17 -3
  22. package/dist/resolveEditInfo-Cz-smq3a.js.map +1 -0
  23. package/dist/stega.js +1 -1
  24. package/dist/{stegaEncodeSourceMap-DkoIlutY.js → stegaEncodeSourceMap-DbM2fTN4.js} +8 -2
  25. package/dist/stegaEncodeSourceMap-DbM2fTN4.js.map +1 -0
  26. package/dist/{stegaEncodeSourceMap-B2fGArSf.js → stegaEncodeSourceMap-YR3NQ3iz.js} +2 -2
  27. package/dist/{stegaEncodeSourceMap-B2fGArSf.js.map → stegaEncodeSourceMap-YR3NQ3iz.js.map} +1 -1
  28. package/dist/{types-CUxZSgB2.d.ts → types-nJhm5Nyq.d.ts} +910 -24
  29. package/package.json +26 -11
  30. package/src/SanityClient.ts +39 -20
  31. package/src/assets/AssetsClient.ts +54 -5
  32. package/src/collaboration/CollaborationCommentsClient.ts +387 -0
  33. package/src/collaboration/comments.ts +313 -0
  34. package/src/collaboration/types.ts +252 -0
  35. package/src/csm/applySourceDocuments.ts +2 -4
  36. package/src/csm/draftUtils.ts +23 -4
  37. package/src/data/dataMethods.ts +9 -20
  38. package/src/data/eventsource.ts +71 -41
  39. package/src/data/listen.ts +20 -5
  40. package/src/data/live.ts +17 -9
  41. package/src/data/resolveEventSourceFetch.ts +9 -1
  42. package/src/defineCreateClient.ts +5 -1
  43. package/src/functions/FunctionsClient.ts +66 -0
  44. package/src/functions/invoke.ts +176 -0
  45. package/src/http/browserUpload.ts +1 -0
  46. package/src/http/errors.ts +2 -1
  47. package/src/http/request.ts +8 -14
  48. package/src/mediaLibrary/MediaLibraryVideoClient.ts +1 -1
  49. package/src/types.ts +420 -4
  50. package/src/validators.ts +1 -1
  51. package/src/warnings.ts +7 -1
  52. package/dist/browserUpload-CQgx9YYo.js.map +0 -1
  53. package/dist/browserUpload-icWlVP15.js.map +0 -1
  54. package/dist/config-a8VajuEY.js.map +0 -1
  55. package/dist/request-CJxcN16k.js.map +0 -1
  56. package/dist/request-k7VS_NnC.js.map +0 -1
  57. package/dist/resolveEditInfo-sq7yF78q.js.map +0 -1
  58. package/dist/stegaEncodeSourceMap-DkoIlutY.js.map +0 -1
@@ -1,6 +1,7 @@
1
- import { FetchFunction } from "get-it";
1
+ import { FetchFunction, RequestOptions as RequestOptions$1, TimeoutErrorLike, isTimeoutError } from "get-it";
2
2
  import { Observable } from "rxjs";
3
3
  import { ContentSourceMapDocuments as ContentSourceMapDocuments$1, ContentSourceMapParsedPath, ContentSourceMapParsedPath as ContentSourceMapParsedPath$1, ContentSourceMapParsedPathKeyedSegment, ResolveStudioUrl, StudioBaseRoute, StudioBaseUrl, StudioUrl, StudioUrl as StudioUrl$1 } from "@sanity/client/csm";
4
+ import { EventSourceConstructor } from "eventsource";
4
5
  import { ClientPerspective as ClientPerspective$1 } from "@sanity/client";
5
6
  /** @public */
6
7
  interface StegaConfig {
@@ -1149,6 +1150,16 @@ declare class AssetsClient {
1149
1150
  /**
1150
1151
  * Uploads a file asset to the configured dataset
1151
1152
  *
1153
+ * Note: when the client is configured against a Media Library
1154
+ * (`resource: {type: 'media-library', id}`), this resolves to a
1155
+ * {@link MediaLibraryAssetDocument} at runtime, not to a
1156
+ * {@link SanityAssetDocument}. The declared type cannot express that: the
1157
+ * shape depends on the client's configuration rather than on the arguments,
1158
+ * so an overload cannot discriminate it, and widening the return type into a
1159
+ * union would be a breaking change for every existing caller. Narrow the
1160
+ * result yourself (for example, check for `currentVersion`) if you upload to
1161
+ * a Media Library. Typing this honestly is deferred to the next major.
1162
+ *
1152
1163
  * @param assetType - Asset type (file)
1153
1164
  * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1154
1165
  * @param options - Options to use for the upload
@@ -1157,6 +1168,10 @@ declare class AssetsClient {
1157
1168
  /**
1158
1169
  * Uploads an image asset to the configured dataset
1159
1170
  *
1171
+ * Note: against a Media Library this resolves to a
1172
+ * {@link MediaLibraryAssetDocument} at runtime. See the `'file'` overload
1173
+ * above for why the declared type cannot say so.
1174
+ *
1160
1175
  * @param assetType - Asset type (image)
1161
1176
  * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1162
1177
  * @param options - Options to use for the upload
@@ -1209,6 +1224,462 @@ declare function _listen<R extends Record<string, Any> = Record<string, Any>>(th
1209
1224
  * @public
1210
1225
  */
1211
1226
  declare function _listen<R extends Record<string, Any> = Record<string, Any>, Opts extends ListenOptions | ResumableListenOptions = ListenOptions | ResumableListenOptions>(this: SanityClient | ObservableSanityClient, query: string, params?: ListenParams, options?: Opts): Observable<ListenEventFromOptions<R, Opts>>;
1227
+ /** @internal */
1228
+ declare const possibleRequestOptions: readonly ['headers', 'signal', 'tag', 'timeout', 'token'];
1229
+ /**
1230
+ * Request options honored by the collaboration comments methods.
1231
+ *
1232
+ * @alpha
1233
+ */
1234
+ type CollaborationCommentsRequestOptions = Pick<RequestOptions, (typeof possibleRequestOptions)[number]>;
1235
+ /**
1236
+ * Options for collaboration comments write methods.
1237
+ *
1238
+ * @alpha
1239
+ */
1240
+ type CollaborationCommentsWriteOptions = CollaborationCommentsRequestOptions & {
1241
+ /** Transaction ID to associate the write with */
1242
+ transactionId?: string;
1243
+ };
1244
+ /**
1245
+ * Listener options for `collaboration.comments.listen`.
1246
+ *
1247
+ * `includeAllVersions` is left out: comments are stored as `sanity.comment`
1248
+ * documents with no drafts or versions, so it would never make a difference.
1249
+ *
1250
+ * @alpha
1251
+ */
1252
+ type CollaborationCommentsListenOptions = Omit<ListenOptions, 'includeAllVersions'> | Omit<ResumableListenOptions, 'includeAllVersions'>;
1253
+ /**
1254
+ * Status of a comment thread. Replies always share the status of their parent comment.
1255
+ *
1256
+ * @alpha
1257
+ */
1258
+ type CollaborationCommentStatus = 'open' | 'resolved';
1259
+ /**
1260
+ * Emoji short names that can be used as comment reactions.
1261
+ *
1262
+ * @alpha
1263
+ */
1264
+ type CollaborationCommentReactionShortName = ':-1:' | ':+1:' | ':eyes:' | ':heart:' | ':heavy_plus_sign:' | ':rocket:';
1265
+ /**
1266
+ * A single Portable Text block, as used in comment messages and content snapshots.
1267
+ *
1268
+ * @alpha
1269
+ */
1270
+ interface CollaborationCommentPortableTextBlock {
1271
+ _type: string;
1272
+ children: Array<{
1273
+ _type: string;
1274
+ [key: string]: Any;
1275
+ }>;
1276
+ [key: string]: Any;
1277
+ }
1278
+ /**
1279
+ * Comment message, as an array of Portable Text blocks.
1280
+ *
1281
+ * @alpha
1282
+ */
1283
+ type CollaborationCommentMessage = CollaborationCommentPortableTextBlock[];
1284
+ /**
1285
+ * The text an inline comment was anchored to, resolved by the API when the
1286
+ * comment was created.
1287
+ *
1288
+ * Holds one entry per Portable Text block the selection spans, keyed by the
1289
+ * block it came from. `text` is the plain text of that block with the selected
1290
+ * part wrapped in the marker characters `\uF000` (start) and `\uF001` (end).
1291
+ *
1292
+ * @alpha
1293
+ */
1294
+ interface CollaborationCommentSelection {
1295
+ type: 'text';
1296
+ value: {
1297
+ _key: string;
1298
+ text: string;
1299
+ }[];
1300
+ }
1301
+ /**
1302
+ * A comment document, as stored by the Comments API.
1303
+ *
1304
+ * @alpha
1305
+ */
1306
+ interface CollaborationCommentDocument extends SanityDocument {
1307
+ _type: 'sanity.comment';
1308
+ _system?: {
1309
+ /** ID of the user that created the comment */
1310
+ createdBy?: string;
1311
+ };
1312
+ /** ID shared by a top-level comment and all of its replies */
1313
+ threadId?: string;
1314
+ /** Set on replies, pointing to the comment being replied to */
1315
+ parentCommentId?: string;
1316
+ message: CollaborationCommentMessage;
1317
+ reactions: {
1318
+ _key: string;
1319
+ shortName: CollaborationCommentReactionShortName;
1320
+ userId: string;
1321
+ addedAt: string;
1322
+ }[];
1323
+ /** Arbitrary metadata stored with the comment by the creating application */
1324
+ context?: Record<string, unknown>;
1325
+ target: {
1326
+ /** Global document reference (`resourceType:resourceId:documentId`, using the published document ID) */
1327
+ document: {
1328
+ _ref: `${string}:${string}:${string}`;
1329
+ _type: 'globalDocumentReference';
1330
+ _weak: true;
1331
+ };
1332
+ documentType: string;
1333
+ /** The exact document ID the comment was created against, e.g. a draft or version ID */
1334
+ sourceDocumentId: string;
1335
+ documentRevisionId?: string;
1336
+ /**
1337
+ * Set for field and inline comments. `field` is the `path` the comment was
1338
+ * created with; `selection` is set for inline comments only.
1339
+ */
1340
+ path?: {
1341
+ field: string;
1342
+ selection?: CollaborationCommentSelection;
1343
+ };
1344
+ };
1345
+ /**
1346
+ * Copy of the commented content, as it looked when the comment was created.
1347
+ * Set for inline comments only, and holds just the selected fragment of each
1348
+ * Portable Text block the selection spans.
1349
+ */
1350
+ contentSnapshot?: CollaborationCommentPortableTextBlock[];
1351
+ status: CollaborationCommentStatus;
1352
+ /** Set when the message has been updated after creation */
1353
+ lastEditedAt?: string;
1354
+ }
1355
+ /**
1356
+ * Inline text selection within a Portable Text field.
1357
+ * Each endpoint pairs the `_key` of a Portable Text block with a character
1358
+ * offset into that block's plain text.
1359
+ *
1360
+ * @alpha
1361
+ */
1362
+ interface CollaborationCommentRange {
1363
+ start: {
1364
+ _key: string;
1365
+ offset: number;
1366
+ };
1367
+ end: {
1368
+ _key: string;
1369
+ offset: number;
1370
+ };
1371
+ }
1372
+ /**
1373
+ * Target for a top-level comment. Inline selections require both `path` and
1374
+ * `range`; field-level comments may set `path` alone.
1375
+ *
1376
+ * The created comment stores this in a different shape: `path` becomes
1377
+ * `target.path.field`, and `range` is resolved against the document into
1378
+ * `target.path.selection` and `contentSnapshot` rather than being stored.
1379
+ *
1380
+ * @alpha
1381
+ */
1382
+ type CollaborationCommentTarget = {
1383
+ documentId: string;
1384
+ documentType: string;
1385
+ documentRevisionId?: string;
1386
+ } & ({
1387
+ /** Path to the field containing the inline comment selection */
1388
+ path: string;
1389
+ range: CollaborationCommentRange;
1390
+ } | {
1391
+ /** Path to the commented field */
1392
+ path?: string;
1393
+ range?: never;
1394
+ });
1395
+ /**
1396
+ * Comment to create with `collaboration.comments.create`.
1397
+ *
1398
+ * A top-level comment requires `target`; a reply requires `parentCommentId` (never both).
1399
+ * Replies inherit `target`, `status`, and `threadId` from the parent comment.
1400
+ *
1401
+ * ### Examples
1402
+ *
1403
+ * #### Top-level comment
1404
+ * ```ts
1405
+ * // `message` is an array of Portable Text blocks
1406
+ * await client.collaboration.comments.create({
1407
+ * message,
1408
+ * target: {documentId: 'doc-1', documentType: 'article'},
1409
+ * })
1410
+ * ```
1411
+ *
1412
+ * #### Reply
1413
+ * ```ts
1414
+ * await client.collaboration.comments.create({
1415
+ * message,
1416
+ * parentCommentId: 'comment-1',
1417
+ * })
1418
+ * ```
1419
+ *
1420
+ * @alpha
1421
+ */
1422
+ type CollaborationCommentCreate = {
1423
+ /** Provide to control the ID of the created comment document */
1424
+ _id?: string;
1425
+ message: CollaborationCommentMessage;
1426
+ context?: Record<string, unknown>;
1427
+ } & ({
1428
+ target: CollaborationCommentTarget;
1429
+ threadId?: string;
1430
+ parentCommentId?: never;
1431
+ } | {
1432
+ parentCommentId: string;
1433
+ target?: never;
1434
+ threadId?: never;
1435
+ });
1436
+ /**
1437
+ * Fields that can be updated on an existing comment.
1438
+ *
1439
+ * @alpha
1440
+ */
1441
+ interface CollaborationCommentUpdate {
1442
+ /** Replaces the current message */
1443
+ message?: CollaborationCommentMessage;
1444
+ /** Cascades to the comment's replies */
1445
+ status?: CollaborationCommentStatus;
1446
+ /**
1447
+ * Re-anchors the comment within the field and source document it already
1448
+ * targets. Pass `null` to remove the selection and leave a field-level
1449
+ * comment.
1450
+ */
1451
+ range?: CollaborationCommentRange | null;
1452
+ }
1453
+ /**
1454
+ * Comments on the configured organization resource.
1455
+ *
1456
+ * Requires `collaboration.organizationId`, plus either `resource` or `projectId` and `dataset`.
1457
+ *
1458
+ * @alpha
1459
+ */
1460
+ declare class ObservableCollaborationCommentsClient {
1461
+ #private;
1462
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest);
1463
+ /**
1464
+ * Create a comment or reply on the configured resource.
1465
+ *
1466
+ * A top-level comment requires `target`; a reply requires `parentCommentId` (never both).
1467
+ * Replies inherit `target`, `status`, and `threadId` from the parent comment.
1468
+ *
1469
+ * @param body - Comment to create
1470
+ * @param options - Optional request options
1471
+ * @returns The created comment
1472
+ */
1473
+ create(body: CollaborationCommentCreate, options?: CollaborationCommentsWriteOptions): Observable<CollaborationCommentDocument>;
1474
+ /**
1475
+ * Update an existing comment.
1476
+ *
1477
+ * Updating `status` cascades to the comment's replies.
1478
+ *
1479
+ * @param id - Comment document ID
1480
+ * @param body - Fields to update
1481
+ * @param options - Optional request options
1482
+ * @returns The updated comment
1483
+ */
1484
+ update(id: string, body: CollaborationCommentUpdate, options?: CollaborationCommentsWriteOptions): Observable<CollaborationCommentDocument>;
1485
+ /**
1486
+ * Delete a comment and its replies.
1487
+ *
1488
+ * @param id - Comment document ID
1489
+ * @param options - Optional request options
1490
+ * @returns Mutation result, where `documentIds` covers the comment and every deleted reply
1491
+ */
1492
+ delete(id: string, options?: CollaborationCommentsWriteOptions): Observable<MultipleMutationResult>;
1493
+ /**
1494
+ * Add the current user's reaction to a comment.
1495
+ *
1496
+ * @param id - Comment document ID
1497
+ * @param shortName - Emoji short name, for example `:+1:`
1498
+ * @param options - Optional request options
1499
+ * @returns The comment, with the reaction applied
1500
+ */
1501
+ addReaction(id: string, shortName: CollaborationCommentReactionShortName, options?: CollaborationCommentsWriteOptions): Observable<CollaborationCommentDocument>;
1502
+ /**
1503
+ * Remove the current user's reaction from a comment.
1504
+ *
1505
+ * @param id - Comment document ID
1506
+ * @param shortName - Emoji short name, for example `:+1:`
1507
+ * @param options - Optional request options
1508
+ * @returns The comment, with the reaction removed
1509
+ */
1510
+ removeReaction(id: string, shortName: CollaborationCommentReactionShortName, options?: CollaborationCommentsWriteOptions): Observable<CollaborationCommentDocument>;
1511
+ /**
1512
+ * Build the global document reference used by `target.document._ref`, for use in
1513
+ * queries and listeners.
1514
+ *
1515
+ * The reference is built from the configured `resource` and the published ID of
1516
+ * the given document ID, since comment references always use published IDs.
1517
+ *
1518
+ * @example
1519
+ * ```ts
1520
+ * client.collaboration.comments.listen(
1521
+ * '*[_type == "sanity.comment" && target.document._ref == $ref]',
1522
+ * {ref: client.collaboration.comments.getTargetDocumentRef('doc-1')},
1523
+ * )
1524
+ * ```
1525
+ *
1526
+ * @param documentId - Document ID, in published, draft or version form
1527
+ * @returns Global document reference, of the form `resourceType:resourceId:documentId`
1528
+ */
1529
+ getTargetDocumentRef(documentId: string): CollaborationCommentDocument['target']['document']['_ref'];
1530
+ /**
1531
+ * Fetch comments on the configured resource.
1532
+ *
1533
+ * Takes the same `query` and `params` as `client.fetch`, and switches from a
1534
+ * GET to a POST for queries too large for the request URL in the same way,
1535
+ * but queries the comments endpoint, which accepts none of the query options
1536
+ * `client.fetch` does (`perspective`, `useCdn`, `filterResponse`,
1537
+ * `resultSourceMap`, stega).
1538
+ *
1539
+ * The query runs against the organization store, which is not scoped to
1540
+ * comments, so filter on `_type == "sanity.comment"`.
1541
+ *
1542
+ * @param query - GROQ-query to perform
1543
+ * @param params - Optional query parameters
1544
+ * @param options - Optional request options
1545
+ */
1546
+ fetch<R = unknown>(query: string, params?: QueryParams, options?: CollaborationCommentsRequestOptions): Observable<R>;
1547
+ /**
1548
+ * Listen for changes to comments on the configured resource.
1549
+ *
1550
+ * Mirrors `client.listen(query, params)`, and emits mutation events.
1551
+ *
1552
+ * @param query - GROQ-filter to listen to changes for
1553
+ * @param params - Optional query parameters
1554
+ */
1555
+ listen(query: string, params?: QueryParams): Observable<MutationEvent<CollaborationCommentDocument>>;
1556
+ /**
1557
+ * Listen for changes to comments on the configured resource.
1558
+ *
1559
+ * Mirrors `client.listen(query, params, options)`.
1560
+ *
1561
+ * @param query - GROQ-filter to listen to changes for
1562
+ * @param params - Optional query parameters
1563
+ * @param options - The same listener options `client.listen` takes, forwarded
1564
+ * to the organization store's listener
1565
+ */
1566
+ listen<Opts extends CollaborationCommentsListenOptions>(query: string, params: QueryParams | undefined, options: Opts): Observable<ListenEventFromOptions<CollaborationCommentDocument, Opts>>;
1567
+ }
1568
+ /**
1569
+ * Comments on the configured organization resource.
1570
+ *
1571
+ * Requires `collaboration.organizationId`, plus either `resource` or `projectId` and `dataset`.
1572
+ *
1573
+ * @alpha
1574
+ */
1575
+ declare class CollaborationCommentsClient {
1576
+ #private;
1577
+ constructor(client: SanityClient, httpRequest: HttpRequest);
1578
+ /**
1579
+ * Create a comment or reply on the configured resource.
1580
+ *
1581
+ * A top-level comment requires `target`; a reply requires `parentCommentId` (never both).
1582
+ * Replies inherit `target`, `status`, and `threadId` from the parent comment.
1583
+ *
1584
+ * @param body - Comment to create
1585
+ * @param options - Optional request options
1586
+ * @returns The created comment
1587
+ */
1588
+ create(body: CollaborationCommentCreate, options?: CollaborationCommentsWriteOptions): Promise<CollaborationCommentDocument>;
1589
+ /**
1590
+ * Update an existing comment.
1591
+ *
1592
+ * Updating `status` cascades to the comment's replies.
1593
+ *
1594
+ * @param id - Comment document ID
1595
+ * @param body - Fields to update
1596
+ * @param options - Optional request options
1597
+ * @returns The updated comment
1598
+ */
1599
+ update(id: string, body: CollaborationCommentUpdate, options?: CollaborationCommentsWriteOptions): Promise<CollaborationCommentDocument>;
1600
+ /**
1601
+ * Delete a comment and its replies.
1602
+ *
1603
+ * @param id - Comment document ID
1604
+ * @param options - Optional request options
1605
+ * @returns Mutation result, where `documentIds` covers the comment and every deleted reply
1606
+ */
1607
+ delete(id: string, options?: CollaborationCommentsWriteOptions): Promise<MultipleMutationResult>;
1608
+ /**
1609
+ * Add the current user's reaction to a comment.
1610
+ *
1611
+ * @param id - Comment document ID
1612
+ * @param shortName - Emoji short name, for example `:+1:`
1613
+ * @param options - Optional request options
1614
+ * @returns The comment, with the reaction applied
1615
+ */
1616
+ addReaction(id: string, shortName: CollaborationCommentReactionShortName, options?: CollaborationCommentsWriteOptions): Promise<CollaborationCommentDocument>;
1617
+ /**
1618
+ * Remove the current user's reaction from a comment.
1619
+ *
1620
+ * @param id - Comment document ID
1621
+ * @param shortName - Emoji short name, for example `:+1:`
1622
+ * @param options - Optional request options
1623
+ * @returns The comment, with the reaction removed
1624
+ */
1625
+ removeReaction(id: string, shortName: CollaborationCommentReactionShortName, options?: CollaborationCommentsWriteOptions): Promise<CollaborationCommentDocument>;
1626
+ /**
1627
+ * Build the global document reference used by `target.document._ref`, for use in
1628
+ * queries and listeners.
1629
+ *
1630
+ * The reference is built from the configured `resource` and the published ID of
1631
+ * the given document ID, since comment references always use published IDs.
1632
+ *
1633
+ * @example
1634
+ * ```ts
1635
+ * const comments = await client.collaboration.comments.fetch(
1636
+ * '*[_type == "sanity.comment" && target.document._ref == $ref]',
1637
+ * {ref: client.collaboration.comments.getTargetDocumentRef('doc-1')},
1638
+ * )
1639
+ * ```
1640
+ *
1641
+ * @param documentId - Document ID, in published, draft or version form
1642
+ * @returns Global document reference, of the form `resourceType:resourceId:documentId`
1643
+ */
1644
+ getTargetDocumentRef(documentId: string): CollaborationCommentDocument['target']['document']['_ref'];
1645
+ /**
1646
+ * Fetch comments on the configured resource.
1647
+ *
1648
+ * Takes the same `query` and `params` as `client.fetch`, and switches from a
1649
+ * GET to a POST for queries too large for the request URL in the same way,
1650
+ * but queries the comments endpoint, which accepts none of the query options
1651
+ * `client.fetch` does (`perspective`, `useCdn`, `filterResponse`,
1652
+ * `resultSourceMap`, stega).
1653
+ *
1654
+ * The query runs against the organization store, which is not scoped to
1655
+ * comments, so filter on `_type == "sanity.comment"`.
1656
+ *
1657
+ * @param query - GROQ-query to perform
1658
+ * @param params - Optional query parameters
1659
+ * @param options - Optional request options
1660
+ */
1661
+ fetch<R = unknown>(query: string, params?: QueryParams, options?: CollaborationCommentsRequestOptions): Promise<R>;
1662
+ /**
1663
+ * Listen for changes to comments on the configured resource.
1664
+ *
1665
+ * Mirrors `client.listen(query, params)`, and emits mutation events.
1666
+ *
1667
+ * @param query - GROQ-filter to listen to changes for
1668
+ * @param params - Optional query parameters
1669
+ */
1670
+ listen(query: string, params?: QueryParams): Observable<MutationEvent<CollaborationCommentDocument>>;
1671
+ /**
1672
+ * Listen for changes to comments on the configured resource.
1673
+ *
1674
+ * Mirrors `client.listen(query, params, options)`.
1675
+ *
1676
+ * @param query - GROQ-filter to listen to changes for
1677
+ * @param params - Optional query parameters
1678
+ * @param options - The same listener options `client.listen` takes, forwarded
1679
+ * to the organization store's listener
1680
+ */
1681
+ listen<Opts extends CollaborationCommentsListenOptions>(query: string, params: QueryParams | undefined, options: Opts): Observable<ListenEventFromOptions<CollaborationCommentDocument, Opts>>;
1682
+ }
1212
1683
  /**
1213
1684
  * @public
1214
1685
  */
@@ -1676,6 +2147,72 @@ declare class DatasetsClient {
1676
2147
  */
1677
2148
  editEmbeddingsSettings(name: string, settings: EmbeddingsSettingsBody): Promise<void>;
1678
2149
  }
2150
+ /** @public */
2151
+ interface InvokeFunctionEvent {
2152
+ /**
2153
+ * Payload handed to the function.
2154
+ * The function receives it as `event.data`.
2155
+ */
2156
+ data?: unknown;
2157
+ }
2158
+ /** @public */
2159
+ interface InvokeFunctionRequest {
2160
+ event?: InvokeFunctionEvent;
2161
+ /**
2162
+ * Stack to resolve the function name against.
2163
+ * Overrides `stackId` from the client config.
2164
+ */
2165
+ stackId?: string;
2166
+ /**
2167
+ * Organization owning the stack.
2168
+ */
2169
+ organizationId?: string;
2170
+ /**
2171
+ * Milliseconds to wait for the function to return.
2172
+ */
2173
+ timeout?: number;
2174
+ /** Abort the invocation. */
2175
+ signal?: AbortSignal;
2176
+ }
2177
+ /** @public */
2178
+ declare class ObservableFunctionsClient {
2179
+ #private;
2180
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest);
2181
+ /**
2182
+ * Invoke a deployed function by its blueprint name.
2183
+ *
2184
+ * The name is resolved within the stack given by `stackId` on the request or
2185
+ * the client config. Passes the function's return value once it finishes.
2186
+ *
2187
+ * @param functionName - name of the function, as declared in the blueprint
2188
+ * @param request - payload and request options
2189
+ */
2190
+ invoke<R = unknown>(functionName: string, request?: InvokeFunctionRequest): Observable<R | undefined>;
2191
+ }
2192
+ /** @public */
2193
+ declare class FunctionsClient {
2194
+ #private;
2195
+ constructor(client: SanityClient, httpRequest: HttpRequest);
2196
+ /**
2197
+ * Invoke a deployed function by its blueprint name.
2198
+ *
2199
+ * The name is resolved within the stack given by `stackId` on the request or
2200
+ * the client config, which costs one extra request per call. Rejects if the
2201
+ * stack has no function by that name, or if the name resolves to anything
2202
+ * other than a `sanity.function.pubsub` function.
2203
+ *
2204
+ * The lookup is scoped to `projectId`, or to `organizationId` when one is set
2205
+ * for a stack deployed at organization scope.
2206
+ *
2207
+ * The request stays open until the function finishes, and resolves with its
2208
+ * return value, or `undefined` if it returns nothing. Long-running functions
2209
+ * may need an explicit `timeout`.
2210
+ *
2211
+ * @param functionName - name of the function, as declared in the blueprint
2212
+ * @param request - payload and request options
2213
+ */
2214
+ invoke<R = unknown>(functionName: string, request?: InvokeFunctionRequest): Promise<R | undefined>;
2215
+ }
1679
2216
  /** @internal */
1680
2217
  declare class ObservableMediaLibraryVideoClient {
1681
2218
  #private;
@@ -2270,6 +2807,11 @@ declare class ObservableSanityClient {
2270
2807
  agent: {
2271
2808
  action: ObservableAgentsActionClient;
2272
2809
  };
2810
+ collaboration: {
2811
+ /** @alpha */
2812
+ comments: ObservableCollaborationCommentsClient;
2813
+ };
2814
+ functions: ObservableFunctionsClient;
2273
2815
  releases: ObservableReleasesClient;
2274
2816
  /**
2275
2817
  * Instance properties
@@ -2609,12 +3151,12 @@ declare class ObservableSanityClient {
2609
3151
  delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>;
2610
3152
  /**
2611
3153
  * Deletes a document with the given document ID.
2612
- * Returns an observable that resolves to the deleted document.
3154
+ * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2613
3155
  *
2614
3156
  * @param id - Document ID to delete
2615
3157
  * @param options - Options for the mutation
2616
3158
  */
2617
- delete<R extends Record<string, Any> = Record<string, Any>>(id: string, options?: BaseMutationOptions): Observable<SanityDocument<R>>;
3159
+ delete(id: string, options?: BaseMutationOptions): Observable<MultipleMutationResult>;
2618
3160
  /**
2619
3161
  * Deletes one or more documents matching the given query or document ID.
2620
3162
  * Returns an observable that resolves to first deleted document.
@@ -2649,12 +3191,12 @@ declare class ObservableSanityClient {
2649
3191
  delete(selection: MutationSelection, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>;
2650
3192
  /**
2651
3193
  * Deletes one or more documents matching the given query or document ID.
2652
- * Returns an observable that resolves to first deleted document.
3194
+ * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
2653
3195
  *
2654
3196
  * @param selection - An object with either an `id` or `query` key defining what to delete
2655
3197
  * @param options - Options for the mutation
2656
3198
  */
2657
- delete<R extends Record<string, Any> = Record<string, Any>>(selection: MutationSelection, options?: BaseMutationOptions): Observable<SanityDocument<R>>;
3199
+ delete(selection: MutationSelection, options?: BaseMutationOptions): Observable<MultipleMutationResult>;
2658
3200
  /**
2659
3201
  * @public
2660
3202
  *
@@ -2821,12 +3363,12 @@ declare class ObservableSanityClient {
2821
3363
  mutate<R extends Record<string, Any> = Record<string, Any>>(operations: Mutation<R>[] | ObservablePatch | ObservableTransaction, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>;
2822
3364
  /**
2823
3365
  * Perform mutation operations against the configured dataset
2824
- * Returns an observable that resolves to the first mutated document.
3366
+ * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
2825
3367
  *
2826
3368
  * @param operations - Mutation operations to execute
2827
3369
  * @param options - Mutation options
2828
3370
  */
2829
- mutate<R extends Record<string, Any> = Record<string, Any>>(operations: Mutation<R>[] | ObservablePatch | ObservableTransaction, options?: BaseMutationOptions): Observable<SanityDocument<R>>;
3371
+ mutate<R extends Record<string, Any> = Record<string, Any>>(operations: Mutation<R>[] | ObservablePatch | ObservableTransaction, options?: BaseMutationOptions): Observable<MultipleMutationResult>;
2830
3372
  /**
2831
3373
  * Create a new buildable patch of operations to perform
2832
3374
  *
@@ -2899,6 +3441,11 @@ declare class SanityClient {
2899
3441
  agent: {
2900
3442
  action: AgentActionsClient;
2901
3443
  };
3444
+ collaboration: {
3445
+ /** @alpha */
3446
+ comments: CollaborationCommentsClient;
3447
+ };
3448
+ functions: FunctionsClient;
2902
3449
  releases: ReleasesClient;
2903
3450
  /**
2904
3451
  * Observable version of the Sanity client, with the same configuration as the promise-based one
@@ -3231,12 +3778,12 @@ declare class SanityClient {
3231
3778
  delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>;
3232
3779
  /**
3233
3780
  * Deletes a document with the given document ID.
3234
- * Returns a promise that resolves to the deleted document.
3781
+ * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3235
3782
  *
3236
3783
  * @param id - Document ID to delete
3237
3784
  * @param options - Options for the mutation
3238
3785
  */
3239
- delete<R extends Record<string, Any> = Record<string, Any>>(id: string, options?: BaseMutationOptions): Promise<SanityDocument<R>>;
3786
+ delete(id: string, options?: BaseMutationOptions): Promise<MultipleMutationResult>;
3240
3787
  /**
3241
3788
  * Deletes one or more documents matching the given query or document ID.
3242
3789
  * Returns a promise that resolves to first deleted document.
@@ -3271,12 +3818,12 @@ declare class SanityClient {
3271
3818
  delete(selection: MutationSelection, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>;
3272
3819
  /**
3273
3820
  * Deletes one or more documents matching the given query or document ID.
3274
- * Returns a promise that resolves to first deleted document.
3821
+ * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
3275
3822
  *
3276
3823
  * @param selection - An object with either an `id` or `query` key defining what to delete
3277
3824
  * @param options - Options for the mutation
3278
3825
  */
3279
- delete<R extends Record<string, Any> = Record<string, Any>>(selection: MutationSelection, options?: BaseMutationOptions): Promise<SanityDocument<R>>;
3826
+ delete(selection: MutationSelection, options?: BaseMutationOptions): Promise<MultipleMutationResult>;
3280
3827
  /**
3281
3828
  * @public
3282
3829
  *
@@ -3443,12 +3990,12 @@ declare class SanityClient {
3443
3990
  mutate<R extends Record<string, Any> = Record<string, Any>>(operations: Mutation<R>[] | Patch | Transaction, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>;
3444
3991
  /**
3445
3992
  * Perform mutation operations against the configured dataset
3446
- * Returns a promise that resolves to the first mutated document.
3993
+ * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
3447
3994
  *
3448
3995
  * @param operations - Mutation operations to execute
3449
3996
  * @param options - Mutation options
3450
3997
  */
3451
- mutate<R extends Record<string, Any> = Record<string, Any>>(operations: Mutation<R>[] | Patch | Transaction, options?: BaseMutationOptions): Promise<SanityDocument<R>>;
3998
+ mutate<R extends Record<string, Any> = Record<string, Any>>(operations: Mutation<R>[] | Patch | Transaction, options?: BaseMutationOptions): Promise<MultipleMutationResult>;
3452
3999
  /**
3453
4000
  * Create a new buildable patch of operations to perform
3454
4001
  *
@@ -3770,8 +4317,9 @@ type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any
3770
4317
  /** @beta */
3771
4318
  type GenerateInstruction<T extends Record<string, Any> = Record<string, Any>> = GenerateSyncInstruction<T> | GenerateAsyncInstruction<T>;
3772
4319
  /**
3773
- * Low-level requester returned by `defineHttpRequest`. Surfaces as
3774
- * `client.config().requester` and as the named `requester` export.
4320
+ * Low-level requester returned by `defineRequester(...).observable`.
4321
+ * Surfaces as `client.config().requester` and as the named `requester`
4322
+ * export.
3775
4323
  *
3776
4324
  * Defined locally rather than imported from `http/request` so api-extractor
3777
4325
  * inlines it into the bundled `.d.ts` instead of emitting a relative import
@@ -3803,6 +4351,25 @@ interface RequestOptions {
3803
4351
  body?: Any;
3804
4352
  signal?: AbortSignal;
3805
4353
  }
4354
+ /**
4355
+ * The fully resolved request passed to a {@link RequestHandler}.
4356
+ *
4357
+ * @public
4358
+ */
4359
+ type RequestHandlerOptions = RequestOptions$1;
4360
+ /**
4361
+ * Intercepts a client request around the normal HTTP pipeline.
4362
+ *
4363
+ * Call `next(request)` to execute the request. It resolves to the parsed
4364
+ * response body and rejects with the same errors the client normally exposes,
4365
+ * including {@link ClientError} and {@link ServerError}. A handler can modify
4366
+ * the request, retry it by calling `next` again, or return a synthetic body.
4367
+ *
4368
+ * Browser asset uploads and server-sent event connections do not use this handler.
4369
+ *
4370
+ * @public
4371
+ */
4372
+ type RequestHandler = (request: RequestHandlerOptions, next: (request: RequestHandlerOptions) => Promise<unknown>) => Promise<unknown>;
3806
4373
  /**
3807
4374
  * @public
3808
4375
  * @deprecated – The `r`-prefix is not required, use `string` instead
@@ -3895,6 +4462,19 @@ interface ClientConfig {
3895
4462
  * Optional request tag prefix for all request tags
3896
4463
  */
3897
4464
  requestTagPrefix?: string;
4465
+ /**
4466
+ * Intercepts requests after the client has resolved their URL, headers, and
4467
+ * transport options. The handler wraps the normal client pipeline, so errors
4468
+ * from `next` are already converted to {@link ClientError} or
4469
+ * {@link ServerError}.
4470
+ *
4471
+ * A handler supplied through `withConfig()` replaces the current handler.
4472
+ * To compose handlers, read the current handler from `client.config()` and
4473
+ * call it from the replacement.
4474
+ *
4475
+ * Browser asset uploads and server-sent event connections are not intercepted.
4476
+ */
4477
+ requestHandler?: RequestHandler;
3898
4478
  /**
3899
4479
  * Optional default headers to include with all requests
3900
4480
  *
@@ -3984,6 +4564,25 @@ interface ClientConfig {
3984
4564
  * Lineage token for recursion control
3985
4565
  */
3986
4566
  lineage?: string;
4567
+ /**
4568
+ * ID of the blueprints stack that `functions.invoke()` resolves function
4569
+ * names against. Function names are unique within a stack
4570
+ */
4571
+ stackId?: string;
4572
+ /**
4573
+ * ID of the organization owning the blueprints stack
4574
+ */
4575
+ organizationId?: string;
4576
+ /**
4577
+ * Organization-scoped configuration for collaboration APIs.
4578
+ *
4579
+ * Currently this is used by `collaboration.comments` methods.
4580
+ *
4581
+ * @alpha
4582
+ */
4583
+ collaboration?: {
4584
+ organizationId?: string;
4585
+ };
3987
4586
  }
3988
4587
  /** @public */
3989
4588
  interface InitializedClientConfig extends ClientConfig {
@@ -4178,7 +4777,7 @@ interface ErrorProps {
4178
4777
  * @internal
4179
4778
  */
4180
4779
  type HttpRequest = {
4181
- (options: Any): Promise<unknown>;
4780
+ (options: Any, requestHandler?: RequestHandler): Promise<unknown>;
4182
4781
  };
4183
4782
  /**
4184
4783
  * Target URL for a request. Exactly one of `url` or the deprecated `uri` alias
@@ -4458,10 +5057,20 @@ type Mutation<R extends Record<string, Any> = Record<string, Any>> = {
4458
5057
  };
4459
5058
  /** @public */
4460
5059
  type ReleaseAction = CreateReleaseAction | EditReleaseAction | PublishReleaseAction | ArchiveReleaseAction | UnarchiveReleaseAction | ScheduleReleaseAction | UnscheduleReleaseAction | DeleteReleaseAction | ImportReleaseAction;
5060
+ /**
5061
+ * @public
5062
+ * @beta
5063
+ */
5064
+ type VariantDefinitionAction = CreateVariantDefinitionAction | EditVariantDefinitionAction | DeleteVariantDefinitionAction;
4461
5065
  /** @public */
4462
5066
  type VersionAction = CreateVersionAction | DiscardVersionAction | ReplaceVersionAction | UnpublishVersionAction;
5067
+ /**
5068
+ * @public
5069
+ * @beta
5070
+ */
5071
+ type VariantAction = CreateVariantAction | EditVariantAction | DeleteVariantAction | PublishVariantAction | UnpublishVariantAction;
4463
5072
  /** @public */
4464
- type Action = CreateAction | ReplaceDraftAction | EditAction | DeleteAction | DiscardAction | PublishAction | UnpublishAction | VersionAction | ReleaseAction;
5073
+ type Action = CreateAction | ReplaceDraftAction | EditAction | DeleteAction | DiscardAction | PublishAction | UnpublishAction | VersionAction | VariantAction | ReleaseAction | VariantDefinitionAction;
4465
5074
  /** @public */
4466
5075
  type ImportReleaseAction = {
4467
5076
  actionType: 'sanity.action.release.import';
@@ -4600,6 +5209,245 @@ interface UnpublishVersionAction {
4600
5209
  versionId: string;
4601
5210
  publishedId: string;
4602
5211
  }
5212
+ /**
5213
+ * Creates a variant of a document, either by supplying the full document
5214
+ * content, or the base ID of a document to copy.
5215
+ *
5216
+ * @public
5217
+ * @beta
5218
+ */
5219
+ type CreateVariantAction = {
5220
+ actionType: 'sanity.action.document.variant.create';
5221
+ /**
5222
+ * ID of the document group to create a variant in. Must be a published
5223
+ * document ID, without a `drafts.` or `versions.` prefix.
5224
+ */
5225
+ publishedId: string;
5226
+ /**
5227
+ * Name of the variant definition this document belongs to, as in
5228
+ * `_.variants.{variantName}`. Must be a bare name, not a full document ID.
5229
+ */
5230
+ variantId: string;
5231
+ /**
5232
+ * Source bundle: `'drafts'`, or a release id.
5233
+ *
5234
+ * Defaults to the published bundle.
5235
+ */
5236
+ bundleId?: 'drafts' | (string & {});
5237
+ } & ({
5238
+ /**
5239
+ * The full document content. Requires a `_type` property.
5240
+ */
5241
+ document: SanityDocumentStub;
5242
+ baseId?: never;
5243
+ ifBaseRevisionId?: never;
5244
+ } | {
5245
+ /**
5246
+ * ID of an existing document to copy the content from.
5247
+ */
5248
+ baseId: string;
5249
+ /**
5250
+ * When set, the action fails unless the current revision of the base
5251
+ * document matches this value.
5252
+ */
5253
+ ifBaseRevisionId?: string;
5254
+ document?: never;
5255
+ });
5256
+ /**
5257
+ * Modifies a variant version of a document by applying a patch.
5258
+ *
5259
+ * If no such variant document exists it is first created, by copying the
5260
+ * variant's published sibling, or the published document if the variant was
5261
+ * never published.
5262
+ *
5263
+ * @public
5264
+ * @beta
5265
+ */
5266
+ interface EditVariantAction {
5267
+ actionType: 'sanity.action.document.variant.edit';
5268
+ /**
5269
+ * ID of the document group the variant belongs to. Must be a published
5270
+ * document ID, without a `drafts.` or `versions.` prefix.
5271
+ */
5272
+ publishedId: string;
5273
+ /**
5274
+ * Name of the variant definition this document belongs to, as in
5275
+ * `_.variants.{variantName}`. Must be a bare name, not a full document ID.
5276
+ */
5277
+ variantId: string;
5278
+ /**
5279
+ * Source bundle: `'drafts'`, or a release id.
5280
+ *
5281
+ * Defaults to the published bundle.
5282
+ */
5283
+ bundleId?: 'drafts' | (string & {});
5284
+ /**
5285
+ * Patch operations to apply.
5286
+ */
5287
+ patch: PatchOperations;
5288
+ }
5289
+ /**
5290
+ * Deletes a variant of a document.
5291
+ *
5292
+ * @public
5293
+ * @beta
5294
+ */
5295
+ interface DeleteVariantAction {
5296
+ actionType: 'sanity.action.document.variant.delete';
5297
+ /**
5298
+ * ID of the document group the variant belongs to. Must be a published
5299
+ * document ID, without a `drafts.` or `versions.` prefix.
5300
+ */
5301
+ publishedId: string;
5302
+ /**
5303
+ * Name of the variant definition this document belongs to, as in
5304
+ * `_.variants.{variantName}`. Must be a bare name, not a full document ID.
5305
+ */
5306
+ variantId: string;
5307
+ /**
5308
+ * Source bundle: `'drafts'`, or a release id.
5309
+ *
5310
+ * Defaults to the published bundle.
5311
+ */
5312
+ bundleId?: 'drafts' | (string & {});
5313
+ /**
5314
+ * Delete document history.
5315
+ */
5316
+ purge?: boolean;
5317
+ }
5318
+ /**
5319
+ * Publishes a variant version of a document, replacing the published variant
5320
+ * and removing the source variant document.
5321
+ *
5322
+ * @public
5323
+ * @beta
5324
+ */
5325
+ interface PublishVariantAction {
5326
+ actionType: 'sanity.action.document.variant.publish';
5327
+ /**
5328
+ * ID of the document group the variant belongs to. Must be a published
5329
+ * document ID, without a `drafts.` or `versions.` prefix.
5330
+ */
5331
+ publishedId: string;
5332
+ /**
5333
+ * Name of the variant definition this document belongs to, as in
5334
+ * `_.variants.{variantName}`. Must be a bare name, not a full document ID.
5335
+ */
5336
+ variantId: string;
5337
+ /**
5338
+ * Bundle to publish from: `'drafts'`, or a release id.
5339
+ */
5340
+ bundleId: 'drafts' | (string & {});
5341
+ /**
5342
+ * When set, publishing fails unless the current revision of the source
5343
+ * variant document matches this value.
5344
+ */
5345
+ ifVersionRevisionId?: string;
5346
+ /**
5347
+ * When set, publishing fails unless the current revision of the published
5348
+ * variant document matches this value.
5349
+ */
5350
+ ifPublishedVariantRevisionId?: string;
5351
+ }
5352
+ /**
5353
+ * Unpublishes a variant version of a document.
5354
+ *
5355
+ * By default the published variant is removed and preserved as a draft
5356
+ * variant. When a release id is given as the `bundleId`, the deletion is
5357
+ * instead staged in that release, and takes effect when it is published.
5358
+ *
5359
+ * @public
5360
+ * @beta
5361
+ */
5362
+ interface UnpublishVariantAction {
5363
+ actionType: 'sanity.action.document.variant.unpublish';
5364
+ /**
5365
+ * ID of the document group the variant belongs to. Must be a published
5366
+ * document ID, without a `drafts.` or `versions.` prefix.
5367
+ */
5368
+ publishedId: string;
5369
+ /**
5370
+ * Name of the variant definition this document belongs to, as in
5371
+ * `_.variants.{variantName}`. Must be a bare name, not a full document ID.
5372
+ */
5373
+ variantId: string;
5374
+ /**
5375
+ * The content release in which to stage the unpublish.
5376
+ *
5377
+ * By default, the currently published document is unpublished immediately.
5378
+ */
5379
+ bundleId?: string;
5380
+ }
5381
+ /**
5382
+ * Creates a new `system.variant` definition document.
5383
+ *
5384
+ * @public
5385
+ * @beta
5386
+ */
5387
+ interface CreateVariantDefinitionAction {
5388
+ actionType: 'sanity.action.variant.definition.create';
5389
+ /**
5390
+ * Name of the variant definition to create, as in
5391
+ * `_.variants.{variantName}`. Must be a bare name, not a full document ID.
5392
+ */
5393
+ variantId: string;
5394
+ /**
5395
+ * Conditions used to select this variant.
5396
+ */
5397
+ conditions?: ClientVariantConditions;
5398
+ /**
5399
+ * Selection priority. Higher values are preferred when multiple variants
5400
+ * match.
5401
+ *
5402
+ * Defaults to `0`.
5403
+ */
5404
+ priority?: number;
5405
+ metadata?: Record<string, Any>;
5406
+ }
5407
+ /**
5408
+ * Edits an existing variant definition.
5409
+ *
5410
+ * @public
5411
+ * @beta
5412
+ */
5413
+ interface EditVariantDefinitionAction {
5414
+ actionType: 'sanity.action.variant.definition.edit';
5415
+ /**
5416
+ * Name of the variant definition to edit, as in `_.variants.{variantName}`.
5417
+ * Must be a bare name, not a full document ID.
5418
+ */
5419
+ variantId: string;
5420
+ /**
5421
+ * Patch operations to apply.
5422
+ */
5423
+ patch: PatchOperations;
5424
+ /**
5425
+ * When set, the action fails unless the current revision of the variant
5426
+ * definition matches this value.
5427
+ */
5428
+ ifRevisionId?: string;
5429
+ }
5430
+ /**
5431
+ * Deletes a variant definition.
5432
+ *
5433
+ * Deletion fails if any document holds a strong reference to this variant.
5434
+ *
5435
+ * @public
5436
+ * @beta
5437
+ */
5438
+ interface DeleteVariantDefinitionAction {
5439
+ actionType: 'sanity.action.variant.definition.delete';
5440
+ /**
5441
+ * Name of the variant definition to delete, as in
5442
+ * `_.variants.{variantName}`. Must be a bare name, not a full document ID.
5443
+ */
5444
+ variantId: string;
5445
+ /**
5446
+ * When set, the action fails unless the current revision of the variant
5447
+ * definition matches this value.
5448
+ */
5449
+ ifRevisionId?: string;
5450
+ }
4603
5451
  /**
4604
5452
  * Creates a new draft document. The published version of the document must not already exist.
4605
5453
  * If the draft version of the document already exists the action will fail by default, but
@@ -5581,16 +6429,56 @@ interface VideoPlaybackTokens {
5581
6429
  }
5582
6430
  /** @public */
5583
6431
  type MediaLibraryAssetInstanceIdentifier = string | SanityReference;
6432
+ /**
6433
+ * A single tracked version of a Media Library asset - one uploaded instance,
6434
+ * referencing the underlying (Content Lake shaped) asset document it wraps.
6435
+ *
6436
+ * @public
6437
+ */
6438
+ interface MediaLibraryAssetVersion {
6439
+ _key: string;
6440
+ _type: 'sanity.asset.version';
6441
+ title?: string;
6442
+ instance: SanityReference;
6443
+ }
6444
+ /**
6445
+ * The document returned by the Media Library upload endpoint
6446
+ * (`POST /media-libraries/:id/upload`).
6447
+ *
6448
+ * This is _not_ the same shape as {@link SanityAssetDocument} /
6449
+ * {@link SanityImageAssetDocument}: a Media Library asset is a `sanity.asset`
6450
+ * document that tracks one or more uploaded versions, each pointing at its
6451
+ * own underlying Content Lake asset document via `currentVersion`/`versions`.
6452
+ *
6453
+ * Modelled directly on an observed API response. Fields whose full shape has
6454
+ * not been confirmed (`parent`, `rootDirectory`, `aspects`) are typed loosely
6455
+ * on purpose - widen them once their shape is confirmed.
6456
+ *
6457
+ * @public
6458
+ */
6459
+ interface MediaLibraryAssetDocument {
6460
+ _id: string;
6461
+ _type: 'sanity.asset';
6462
+ assetType: string;
6463
+ title?: string;
6464
+ cdnAccessPolicy?: string;
6465
+ currentVersion: SanityReference;
6466
+ versions: MediaLibraryAssetVersion[];
6467
+ aspects?: Record<string, Any>;
6468
+ parent?: SanityReference | null;
6469
+ rootDirectory?: Any;
6470
+ }
5584
6471
  /**
5585
6472
  * @internal - it may have breaking changes in any release
5586
6473
  */
5587
6474
  declare function validateApiPerspective(perspective: unknown): asserts perspective is ClientPerspective;
5588
6475
  /**
5589
- * @public
5590
6476
  * Thrown when the EventSource connection could not be established, or was rejected by the server.
5591
6477
  * Transient failures (network drops, 5xx, 408, 429) are reconnected internally and emitted as
5592
6478
  * `reconnect` events; a permanent rejection (any other 4xx, eg an expired token) errors the
5593
6479
  * stream with this class so consumers can react — check `status` for the rejection code.
6480
+ *
6481
+ * @public
5594
6482
  */
5595
6483
  declare class ConnectionFailedError extends Error {
5596
6484
  readonly name = "ConnectionFailedError";
@@ -5607,8 +6495,9 @@ declare class ConnectionFailedError extends Error {
5607
6495
  }
5608
6496
  /**
5609
6497
  * The listener has been told to explicitly disconnect.
5610
- * This is a rare situation, but may occur if the API knows reconnect attempts will fail,
5611
- * eg in the case of a deleted dataset, a blocked project or similar events.
6498
+ * This is a rare situation, but may occur if the API knows reconnect attempts will fail,
6499
+ * eg in the case of a deleted dataset, a blocked project or similar events.
6500
+ *
5612
6501
  * @public
5613
6502
  */
5614
6503
  declare class DisconnectError extends Error {
@@ -5617,8 +6506,9 @@ declare class DisconnectError extends Error {
5617
6506
  constructor(message: string, reason?: string, options?: ErrorOptions);
5618
6507
  }
5619
6508
  /**
5620
- * @public
5621
6509
  * The server sent a `channelError` message. Usually indicative of a bad or malformed request
6510
+ *
6511
+ * @public
5622
6512
  */
5623
6513
  declare class ChannelError extends Error {
5624
6514
  readonly name = "ChannelError";
@@ -5626,8 +6516,9 @@ declare class ChannelError extends Error {
5626
6516
  constructor(message: string, data: unknown);
5627
6517
  }
5628
6518
  /**
5629
- * @public
5630
6519
  * The server sent an `error`-event to tell the client that an unexpected error has happened.
6520
+ *
6521
+ * @public
5631
6522
  */
5632
6523
  declare class MessageError extends Error {
5633
6524
  readonly name = "MessageError";
@@ -5635,8 +6526,9 @@ declare class MessageError extends Error {
5635
6526
  constructor(message: string, data: unknown, options?: ErrorOptions);
5636
6527
  }
5637
6528
  /**
5638
- * @public
5639
6529
  * An error occurred while parsing the message sent by the server as JSON. Should normally not happen.
6530
+ *
6531
+ * @public
5640
6532
  */
5641
6533
  declare class MessageParseError extends Error {
5642
6534
  readonly name = "MessageParseError";
@@ -5656,7 +6548,7 @@ type EventSourceEvent<Name extends string> = ServerSentEvent<Name>;
5656
6548
  /**
5657
6549
  * @internal
5658
6550
  */
5659
- type EventSourceInstance = InstanceType<typeof globalThis.EventSource>;
6551
+ type EventSourceInstance = InstanceType<EventSourceConstructor>;
5660
6552
  /**
5661
6553
  * Sanity API specific EventSource handler shared between the listen and live APIs
5662
6554
  *
@@ -5676,7 +6568,7 @@ type EventSourceInstance = InstanceType<typeof globalThis.EventSource>;
5676
6568
  *
5677
6569
  * @internal
5678
6570
  */
5679
- declare function connectEventSource<EventName extends string>(initEventSource: () => EventSourceInstance | Observable<EventSourceInstance>, events: EventName[]): Observable<ServerSentEvent<EventName>>;
6571
+ declare function connectEventSource<EventName extends string>(initEventSource: () => EventSourceInstance | Observable<EventSourceInstance>, events: EventName[]): Observable<EventSourceEvent<EventName>>;
5680
6572
  /**
5681
6573
  * Shared properties for HTTP errors (eg both ClientError and ServerError)
5682
6574
  * Use `isHttpError` for type narrowing and accessing response properties.
@@ -5754,5 +6646,5 @@ declare const createClient: (config: ClientConfig) => SanityClient;
5754
6646
  * @deprecated Use the named export `createClient` instead of the `default` export
5755
6647
  */
5756
6648
  declare const deprecatedCreateClient: (config: ClientConfig) => SanityClient;
5757
- export { Action, ActionError, ActionErrorItem, type AgentActionParam, type AgentActionParams, type AgentActionPath, type AgentActionPathSegment, type AgentActionTarget, AllDocumentIdsMutationOptions, AllDocumentsMutationOptions, AnimatedImageFormat, AnimatedTransformOptions, Any, ApiError, ArchiveReleaseAction, AssetMetadataType, type AssetsClient, AttributeSet, AuthProvider, AuthProviderResponse, BaseActionOptions, BaseMutationOptions, BasePatch, BaseTransaction, ChannelError, ChannelErrorEvent, ClientConfig, ClientError, ClientPerspective, ClientReturn, ClientVariant, ClientVariantConditions, ConnectionFailedError, type ConstantAgentActionParam, ContentSourceMap, ContentSourceMapDocument, ContentSourceMapDocumentBase, ContentSourceMapDocumentValueSource, ContentSourceMapDocuments, ContentSourceMapLiteralSource, ContentSourceMapMapping, ContentSourceMapMappings, type ContentSourceMapParsedPath, type ContentSourceMapParsedPathKeyedSegment, ContentSourceMapPaths, ContentSourceMapRemoteDocument, ContentSourceMapSource, ContentSourceMapUnknownSource, ContentSourceMapValueMapping, CorsOriginError, CreateAction, CreateReleaseAction, CreateVersionAction, CurrentSanityUser, DatasetAclMode, DatasetCreateOptions, DatasetEditOptions, DatasetResponse, type DatasetsClient, DatasetsResponse, DeleteAction, DeleteReleaseAction, DiscardAction, DiscardVersionAction, DisconnectError, DisconnectEvent, type DocumentAgentActionParam, EXPERIMENTAL_API_WARNING, EditAction, EditReleaseAction, EditableReleaseDocument, EmbeddingsSettings, EmbeddingsSettingsBody, ErrorProps, type EventSourceEvent, type EventSourceInstance, type FieldAgentActionParam, type FilterDefault, FilteredResponseQueryOptions, FirstDocumentIdMutationOptions, FirstDocumentMutationOptions, FitMode, type GenerateInstruction, type GenerateOperation, type GenerateTarget, type GenerateTargetDocument, type GenerateTargetInclude, type GroqAgentActionParam, type HttpError, HttpRequest, IdentifiedSanityDocumentStub, type ImageDescriptionOperation, ImportReleaseAction, InitializedClientConfig, type InitializedStegaConfig, InsertPatch, ListenEvent, ListenEventName, ListenOptions, ListenParams, type LiveClient, LiveEvent, LiveEventGoAway, LiveEventMessage, LiveEventReconnect, LiveEventRestart, LiveEventWelcome, type Logger, MediaLibraryAssetInstanceIdentifier, MediaLibraryPlaybackInfoOptions, type MediaLibraryVideoClient, MediaLibraryVideoPlaybackTransformations, MessageError, MessageParseError, MultipleActionResult, MultipleMutationResult, Mutation, MutationError, MutationErrorItem, MutationEvent, MutationOperation, MutationSelection, MutationSelectionQueryParams, type ObservableAssetsClient, type ObservableDatasetsClient, type ObservableMediaLibraryVideoClient, ObservablePatch, ObservablePatchBuilder, type ObservableProjectsClient, ObservableSanityClient, ObservableTransaction, type ObservableUsersClient, OpenEvent, PartialExcept, Patch, PatchBuilder, type PatchDocument, PatchMutationOperation, type PatchOperation, PatchOperations, PatchSelection, type PatchTarget, type ProjectsClient, type PromptRequest, PublishAction, PublishReleaseAction, QueryOptions, QueryParams, QueryParseError, QueryWithoutParams, RawQueryResponse, RawQuerylessQueryResponse, RawRequestOptions, ReconnectEvent, ReleaseAction, ReleaseCardinality, ReleaseDocument, ReleaseId, ReleaseState, ReleaseType, ReplaceDraftAction, ReplaceVersionAction, RequestObservableOptions, RequestOptions, RequestUrlOptions, Requester, ResetEvent, type ResolveStudioUrl, ResponseQueryOptions, ResumableListenEventNames, ResumableListenOptions, SanityAssetDocument, SanityClient, SanityDocument, SanityDocumentStub, SanityImageAssetDocument, SanityImagePalette, SanityProject, SanityProjectMember, SanityQueries, SanityReference, SanityUser, ScheduleReleaseAction, ServerError, type ServerSentEvent, SingleActionResult, SingleMutationResult, StackablePerspective, type StegaConfig, type StegaConfigRequiredKeys, StillImageFormat, StoryboardTransformOptions, type StudioBaseRoute, type StudioBaseUrl, type StudioUrl, SyncTag, ThumbnailTransformOptions, Transaction, TransactionAllDocumentIdsMutationOptions, TransactionAllDocumentsMutationOptions, TransactionFirstDocumentIdMutationOptions, TransactionFirstDocumentMutationOptions, TransactionMutationOptions, type TransformDocument, type TransformOperation, type TransformTarget, type TransformTargetDocument, type TransformTargetInclude, type TranslateDocument, type TranslateTarget, type TranslateTargetInclude, UnarchiveReleaseAction, UnfilteredResponseQueryOptions, UnfilteredResponseWithoutQuery, UnpublishAction, UnpublishVersionAction, UnscheduleReleaseAction, UploadBody, UploadClientConfig, UploadEvent, UploadProgressEvent, UploadResponseEvent, type UsersClient, VersionAction, VideoPlaybackInfo, VideoPlaybackInfoItem, VideoPlaybackInfoItemPublic, VideoPlaybackInfoItemSigned, VideoPlaybackInfoPublic, VideoPlaybackInfoSigned, VideoPlaybackTokens, VideoRenditionInfo, VideoRenditionInfoPublic, VideoRenditionInfoSigned, VideoSubtitleInfo, VideoSubtitleInfoPublic, VideoSubtitleInfoSigned, WelcomeBackEvent, WelcomeEvent, type _listen, connectEventSource, createClient, deprecatedCreateClient as default, formatQueryParseError, isHttpError, isQueryParseError, requester, validateApiPerspective };
6649
+ export { Action, ActionError, ActionErrorItem, type AgentActionParam, type AgentActionParams, type AgentActionPath, type AgentActionPathSegment, type AgentActionTarget, AllDocumentIdsMutationOptions, AllDocumentsMutationOptions, AnimatedImageFormat, AnimatedTransformOptions, Any, ApiError, ArchiveReleaseAction, AssetMetadataType, type AssetsClient, AttributeSet, AuthProvider, AuthProviderResponse, BaseActionOptions, BaseMutationOptions, BasePatch, BaseTransaction, ChannelError, ChannelErrorEvent, ClientConfig, ClientError, ClientPerspective, ClientReturn, ClientVariant, ClientVariantConditions, type CollaborationCommentCreate, type CollaborationCommentDocument, type CollaborationCommentMessage, type CollaborationCommentPortableTextBlock, type CollaborationCommentRange, type CollaborationCommentReactionShortName, type CollaborationCommentSelection, type CollaborationCommentStatus, type CollaborationCommentTarget, type CollaborationCommentUpdate, type CollaborationCommentsClient, type CollaborationCommentsListenOptions, type CollaborationCommentsRequestOptions, type CollaborationCommentsWriteOptions, ConnectionFailedError, type ConstantAgentActionParam, ContentSourceMap, ContentSourceMapDocument, ContentSourceMapDocumentBase, ContentSourceMapDocumentValueSource, ContentSourceMapDocuments, ContentSourceMapLiteralSource, ContentSourceMapMapping, ContentSourceMapMappings, type ContentSourceMapParsedPath, type ContentSourceMapParsedPathKeyedSegment, ContentSourceMapPaths, ContentSourceMapRemoteDocument, ContentSourceMapSource, ContentSourceMapUnknownSource, ContentSourceMapValueMapping, CorsOriginError, CreateAction, CreateReleaseAction, CreateVariantAction, CreateVariantDefinitionAction, CreateVersionAction, CurrentSanityUser, DatasetAclMode, DatasetCreateOptions, DatasetEditOptions, DatasetResponse, type DatasetsClient, DatasetsResponse, DeleteAction, DeleteReleaseAction, DeleteVariantAction, DeleteVariantDefinitionAction, DiscardAction, DiscardVersionAction, DisconnectError, DisconnectEvent, type DocumentAgentActionParam, EXPERIMENTAL_API_WARNING, EditAction, EditReleaseAction, EditVariantAction, EditVariantDefinitionAction, EditableReleaseDocument, EmbeddingsSettings, EmbeddingsSettingsBody, ErrorProps, type EventSourceEvent, type EventSourceInstance, type FieldAgentActionParam, type FilterDefault, FilteredResponseQueryOptions, FirstDocumentIdMutationOptions, FirstDocumentMutationOptions, FitMode, type GenerateInstruction, type GenerateOperation, type GenerateTarget, type GenerateTargetDocument, type GenerateTargetInclude, type GroqAgentActionParam, type HttpError, HttpRequest, IdentifiedSanityDocumentStub, type ImageDescriptionOperation, ImportReleaseAction, InitializedClientConfig, type InitializedStegaConfig, InsertPatch, type InvokeFunctionEvent, type InvokeFunctionRequest, ListenEvent, ListenEventName, ListenOptions, ListenParams, type LiveClient, LiveEvent, LiveEventGoAway, LiveEventMessage, LiveEventReconnect, LiveEventRestart, LiveEventWelcome, type Logger, MediaLibraryAssetDocument, MediaLibraryAssetInstanceIdentifier, MediaLibraryAssetVersion, MediaLibraryPlaybackInfoOptions, type MediaLibraryVideoClient, MediaLibraryVideoPlaybackTransformations, MessageError, MessageParseError, MultipleActionResult, MultipleMutationResult, Mutation, MutationError, MutationErrorItem, MutationEvent, MutationOperation, MutationSelection, MutationSelectionQueryParams, type ObservableAssetsClient, type ObservableCollaborationCommentsClient, type ObservableDatasetsClient, type ObservableMediaLibraryVideoClient, ObservablePatch, ObservablePatchBuilder, type ObservableProjectsClient, ObservableSanityClient, ObservableTransaction, type ObservableUsersClient, OpenEvent, PartialExcept, Patch, PatchBuilder, type PatchDocument, PatchMutationOperation, type PatchOperation, PatchOperations, PatchSelection, type PatchTarget, type ProjectsClient, type PromptRequest, PublishAction, PublishReleaseAction, PublishVariantAction, QueryOptions, QueryParams, QueryParseError, QueryWithoutParams, RawQueryResponse, RawQuerylessQueryResponse, RawRequestOptions, ReconnectEvent, ReleaseAction, ReleaseCardinality, ReleaseDocument, ReleaseId, ReleaseState, ReleaseType, ReplaceDraftAction, ReplaceVersionAction, RequestHandler, RequestHandlerOptions, RequestObservableOptions, RequestOptions, RequestUrlOptions, Requester, ResetEvent, type ResolveStudioUrl, ResponseQueryOptions, ResumableListenEventNames, ResumableListenOptions, SanityAssetDocument, SanityClient, SanityDocument, SanityDocumentStub, SanityImageAssetDocument, SanityImagePalette, SanityProject, SanityProjectMember, SanityQueries, SanityReference, SanityUser, ScheduleReleaseAction, ServerError, type ServerSentEvent, SingleActionResult, SingleMutationResult, StackablePerspective, type StegaConfig, type StegaConfigRequiredKeys, StillImageFormat, StoryboardTransformOptions, type StudioBaseRoute, type StudioBaseUrl, type StudioUrl, SyncTag, ThumbnailTransformOptions, type TimeoutErrorLike, Transaction, TransactionAllDocumentIdsMutationOptions, TransactionAllDocumentsMutationOptions, TransactionFirstDocumentIdMutationOptions, TransactionFirstDocumentMutationOptions, TransactionMutationOptions, type TransformDocument, type TransformOperation, type TransformTarget, type TransformTargetDocument, type TransformTargetInclude, type TranslateDocument, type TranslateTarget, type TranslateTargetInclude, UnarchiveReleaseAction, UnfilteredResponseQueryOptions, UnfilteredResponseWithoutQuery, UnpublishAction, UnpublishVariantAction, UnpublishVersionAction, UnscheduleReleaseAction, UploadBody, UploadClientConfig, UploadEvent, UploadProgressEvent, UploadResponseEvent, type UsersClient, VariantAction, VariantDefinitionAction, VersionAction, VideoPlaybackInfo, VideoPlaybackInfoItem, VideoPlaybackInfoItemPublic, VideoPlaybackInfoItemSigned, VideoPlaybackInfoPublic, VideoPlaybackInfoSigned, VideoPlaybackTokens, VideoRenditionInfo, VideoRenditionInfoPublic, VideoRenditionInfoSigned, VideoSubtitleInfo, VideoSubtitleInfoPublic, VideoSubtitleInfoSigned, WelcomeBackEvent, WelcomeEvent, type _listen, connectEventSource, createClient, deprecatedCreateClient as default, formatQueryParseError, isHttpError, isQueryParseError, isTimeoutError, requester, validateApiPerspective };
5758
6650
  //# sourceMappingURL=index.node.d.ts.map