@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.
@@ -19,6 +19,8 @@ export declare type Action =
19
19
  | DiscardAction
20
20
  | PublishAction
21
21
  | UnpublishAction
22
+ | VersionAction
23
+ | ReleaseAction
22
24
 
23
25
  /** @internal */
24
26
  export declare interface ActionError {
@@ -53,15 +55,27 @@ declare interface AgentActionAsync {
53
55
  }
54
56
 
55
57
  /** @beta */
56
- export declare type AgentActionParam =
58
+ export declare type AgentActionParam<
59
+ TParamConfig extends {
60
+ docIdRequired: boolean
61
+ } = {
62
+ docIdRequired: false
63
+ },
64
+ > =
57
65
  | string
58
66
  | ConstantAgentActionParam
59
- | FieldAgentActionParam
60
- | DocumentAgentActionParam
67
+ | FieldAgentActionParam<TParamConfig>
68
+ | DocumentAgentActionParam<TParamConfig>
61
69
  | GroqAgentActionParam
62
70
 
63
71
  /** @beta */
64
- export declare type AgentActionParams = Record<string, AgentActionParam>
72
+ export declare type AgentActionParams<
73
+ TParamConfig extends {
74
+ docIdRequired: boolean
75
+ } = {
76
+ docIdRequired: false
77
+ },
78
+ > = Record<string, AgentActionParam<TParamConfig>>
65
79
 
66
80
  /** @beta */
67
81
  export declare type AgentActionPath = AgentActionPathSegment[]
@@ -190,6 +204,13 @@ declare class AgentActionsClient {
190
204
  }
191
205
  : IdentifiedSanityDocumentStub & DocumentShape
192
206
  >
207
+ /**
208
+ * Run a raw instruction and return the result either as text or json
209
+ * @param request - prompt request
210
+ */
211
+ prompt<DocumentShape extends Record<string, Any>>(
212
+ request: PromptRequest<DocumentShape>,
213
+ ): Promise<(typeof request)['json'] extends true ? DocumentShape : string>
193
214
  }
194
215
 
195
216
  /** @beta */
@@ -320,6 +341,16 @@ export declare interface ApiError {
320
341
  statusCode: number
321
342
  }
322
343
 
344
+ /**
345
+ * Archives an `active` release, and deletes all the release documents.
346
+ *
347
+ * @public
348
+ */
349
+ export declare interface ArchiveReleaseAction {
350
+ actionType: 'sanity.action.release.archive'
351
+ releaseId: string
352
+ }
353
+
323
354
  /** @public */
324
355
  export declare type AssetMetadataType =
325
356
  | 'location'
@@ -887,6 +918,29 @@ export declare type CreateAction = {
887
918
  /** @public */
888
919
  export declare const createClient: (config: ClientConfig) => SanityClient
889
920
 
921
+ /**
922
+ * Creates a new release under the given id, with metadata.
923
+ *
924
+ * @public
925
+ */
926
+ export declare interface CreateReleaseAction {
927
+ actionType: 'sanity.action.release.create'
928
+ releaseId: string
929
+ metadata?: Partial<ReleaseDocument['metadata']>
930
+ }
931
+
932
+ /**
933
+ * Creates a new version of an existing document, attached to the release as given
934
+ * by `document._id`
935
+ *
936
+ * @public
937
+ */
938
+ export declare interface CreateVersionAction {
939
+ actionType: 'sanity.action.document.version.create'
940
+ publishedId: string
941
+ document: IdentifiedSanityDocumentStub
942
+ }
943
+
890
944
  /** @public */
891
945
  export declare interface CurrentSanityUser {
892
946
  id: string
@@ -982,6 +1036,16 @@ export declare type DeleteAction = {
982
1036
  purge?: boolean
983
1037
  }
984
1038
 
1039
+ /**
1040
+ * Deletes a `archived` or `published` release, and all the release documents versions.
1041
+ *
1042
+ * @public
1043
+ */
1044
+ export declare interface DeleteReleaseAction {
1045
+ actionType: 'sanity.action.release.delete'
1046
+ releaseId: string
1047
+ }
1048
+
985
1049
  /**
986
1050
  * @public
987
1051
  * @deprecated Use the named export `createClient` instead of the `default` export
@@ -999,6 +1063,7 @@ declare type DeprecatedPreviewDrafts = 'previewDrafts'
999
1063
  * It is an error if it does not exist. If the purge flag is set, the document history is also deleted.
1000
1064
  *
1001
1065
  * @public
1066
+ * @deprecated Use {@link DiscardVersionAction} instead
1002
1067
  */
1003
1068
  export declare type DiscardAction = {
1004
1069
  actionType: 'sanity.action.document.discard'
@@ -1012,6 +1077,17 @@ export declare type DiscardAction = {
1012
1077
  purge?: boolean
1013
1078
  }
1014
1079
 
1080
+ /**
1081
+ * Delete a version of a document.
1082
+ *
1083
+ * @public
1084
+ */
1085
+ export declare interface DiscardVersionAction {
1086
+ actionType: 'sanity.action.document.version.discard'
1087
+ versionId: string
1088
+ purge?: boolean
1089
+ }
1090
+
1015
1091
  /**
1016
1092
  * The listener has been told to explicitly disconnect.
1017
1093
  * This is a rare situation, but may occur if the API knows reconnect attempts will fail,
@@ -1038,6 +1114,23 @@ export declare type DisconnectEvent = {
1038
1114
  reason: string
1039
1115
  }
1040
1116
 
1117
+ declare type DocIdParam<
1118
+ TParamConfig extends {
1119
+ docIdRequired: boolean
1120
+ } = {
1121
+ docIdRequired: false
1122
+ },
1123
+ > = TParamConfig['docIdRequired'] extends true
1124
+ ? {
1125
+ documentId: string
1126
+ }
1127
+ : {
1128
+ /**
1129
+ * If omitted, implicitly uses the documentId of the instruction target
1130
+ */
1131
+ documentId?: string
1132
+ }
1133
+
1041
1134
  /**
1042
1135
  *
1043
1136
  * Includes a LLM-friendly version of the document in the instruction
@@ -1058,12 +1151,23 @@ export declare type DisconnectEvent = {
1058
1151
  *
1059
1152
  * @beta
1060
1153
  * */
1061
- export declare interface DocumentAgentActionParam {
1154
+ export declare type DocumentAgentActionParam<
1155
+ TParamConfig extends {
1156
+ docIdRequired: boolean
1157
+ } = {
1158
+ docIdRequired: false
1159
+ },
1160
+ > = {
1062
1161
  type: 'document'
1063
- /**
1064
- * If omitted, implicitly uses the documentId of the instruction target
1065
- */
1066
- documentId?: string
1162
+ } & DocIdParam<TParamConfig>
1163
+
1164
+ /** @internal */
1165
+ export declare type EditableReleaseDocument = Omit<
1166
+ PartialExcept<ReleaseDocument, '_id'>,
1167
+ 'metadata' | '_type'
1168
+ > & {
1169
+ _id: string
1170
+ metadata: Partial<ReleaseDocument['metadata']>
1067
1171
  }
1068
1172
 
1069
1173
  /**
@@ -1089,6 +1193,17 @@ export declare type EditAction = {
1089
1193
  patch: PatchOperations
1090
1194
  }
1091
1195
 
1196
+ /**
1197
+ * Edits an existing release, updating the metadata.
1198
+ *
1199
+ * @public
1200
+ */
1201
+ export declare interface EditReleaseAction {
1202
+ actionType: 'sanity.action.release.edit'
1203
+ releaseId: string
1204
+ patch: PatchOperations
1205
+ }
1206
+
1092
1207
  /** @public */
1093
1208
  export declare interface ErrorProps {
1094
1209
  message: string
@@ -1131,17 +1246,19 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
1131
1246
  *
1132
1247
  * @beta
1133
1248
  * */
1134
- export declare interface FieldAgentActionParam {
1249
+ export declare type FieldAgentActionParam<
1250
+ TParamConfig extends {
1251
+ docIdRequired: boolean
1252
+ } = {
1253
+ docIdRequired: false
1254
+ },
1255
+ > = {
1135
1256
  type: 'field'
1136
1257
  /**
1137
1258
  * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1138
1259
  */
1139
1260
  path: AgentActionPathSegment | AgentActionPath
1140
- /**
1141
- * If omitted, implicitly uses the documentId of the instruction target
1142
- */
1143
- documentId?: string
1144
- }
1261
+ } & DocIdParam<TParamConfig>
1145
1262
 
1146
1263
  /** @public */
1147
1264
  export declare type FilterDefault = (props: {
@@ -2114,6 +2231,306 @@ export declare class ObservableProjectsClient {
2114
2231
  getById(projectId: string): Observable<SanityProject>
2115
2232
  }
2116
2233
 
2234
+ /** @public */
2235
+ declare class ObservableReleasesClient {
2236
+ #private
2237
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2238
+ /**
2239
+ * @public
2240
+ *
2241
+ * Retrieve a release by id.
2242
+ *
2243
+ * @category Releases
2244
+ *
2245
+ * @param params - Release action parameters:
2246
+ * - `releaseId` - The id of the release to retrieve.
2247
+ * @param options - Additional query options including abort signal and query tag.
2248
+ * @returns An observable that resolves to the release document {@link ReleaseDocument}.
2249
+ *
2250
+ * @example Retrieving a release by id
2251
+ * ```ts
2252
+ * client.observable.releases.get({releaseId: 'my-release'}).pipe(
2253
+ * tap((release) => console.log(release)),
2254
+ * // {
2255
+ * // _id: '_.releases.my-release',
2256
+ * // name: 'my-release'
2257
+ * // _type: 'system.release',
2258
+ * // metadata: {releaseType: 'asap'},
2259
+ * // _createdAt: '2021-01-01T00:00:00.000Z',
2260
+ * // ...
2261
+ * // }
2262
+ * ).subscribe()
2263
+ * ```
2264
+ */
2265
+ get(
2266
+ {
2267
+ releaseId,
2268
+ }: {
2269
+ releaseId: string
2270
+ },
2271
+ options?: {
2272
+ signal?: AbortSignal
2273
+ tag?: string
2274
+ },
2275
+ ): Observable<ReleaseDocument | undefined>
2276
+ /**
2277
+ * @public
2278
+ *
2279
+ * Creates a new release under the given id, with metadata.
2280
+ *
2281
+ * @remarks
2282
+ * * If no releaseId is provided, a release id will be generated.
2283
+ * * If no metadata is provided, then an `undecided` releaseType will be used.
2284
+ *
2285
+ * @category Releases
2286
+ *
2287
+ * @param params - Release action parameters:
2288
+ * - `releaseId` - The id of the release to create.
2289
+ * - `metadata` - The metadata to associate with the release {@link ReleaseDocument}.
2290
+ * @param options - Additional action options.
2291
+ * @returns An observable that resolves to the `transactionId` and the release id and metadata.
2292
+ *
2293
+ * @example Creating a release with a custom id and metadata
2294
+ * ```ts
2295
+ * const releaseId = 'my-release'
2296
+ * const metadata: ReleaseDocument['metadata'] = {
2297
+ * releaseType: 'asap',
2298
+ * }
2299
+ *
2300
+ * client.observable.releases.create({releaseId, metadata}).pipe(
2301
+ * tap(({transactionId, releaseId, metadata}) => console.log(transactionId, releaseId, metadata)),
2302
+ * // {
2303
+ * // transactionId: 'transaction-id',
2304
+ * // releaseId: 'my-release',
2305
+ * // metadata: {releaseType: 'asap'},
2306
+ * // }
2307
+ * ).subscribe()
2308
+ * ```
2309
+ *
2310
+ * @example Creating a release with generated id and metadata
2311
+ * ```ts
2312
+ * client.observable.releases.create().pipe(
2313
+ * tap(({metadata}) => console.log(metadata)),
2314
+ * // {
2315
+ * // metadata: {releaseType: 'undecided'},
2316
+ * // }
2317
+ * ).subscribe()
2318
+ * ```
2319
+ *
2320
+ * @example Creating a release using a custom transaction id
2321
+ * ```ts
2322
+ * client.observable.releases.create({transactionId: 'my-transaction-id'}).pipe(
2323
+ * tap(({transactionId, metadata}) => console.log(transactionId, metadata)),
2324
+ * // {
2325
+ * // transactionId: 'my-transaction-id',
2326
+ * // metadata: {releaseType: 'undecided'},
2327
+ * // }
2328
+ * ).subscribe()
2329
+ * ```
2330
+ */
2331
+ create(options: BaseActionOptions): Observable<
2332
+ SingleActionResult & {
2333
+ releaseId: string
2334
+ metadata: ReleaseDocument['metadata']
2335
+ }
2336
+ >
2337
+ create(
2338
+ release: {
2339
+ releaseId?: string
2340
+ metadata?: Partial<ReleaseDocument['metadata']>
2341
+ },
2342
+ options?: BaseActionOptions,
2343
+ ): Observable<
2344
+ SingleActionResult & {
2345
+ releaseId: string
2346
+ metadata: ReleaseDocument['metadata']
2347
+ }
2348
+ >
2349
+ /**
2350
+ * @public
2351
+ *
2352
+ * Edits an existing release, updating the metadata.
2353
+ *
2354
+ * @category Releases
2355
+ *
2356
+ * @param params - Release action parameters:
2357
+ * - `releaseId` - The id of the release to edit.
2358
+ * - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
2359
+ * @param options - Additional action options.
2360
+ * @returns An observable that resolves to the `transactionId`.
2361
+ */
2362
+ edit(
2363
+ {
2364
+ releaseId,
2365
+ patch,
2366
+ }: {
2367
+ releaseId: string
2368
+ patch: PatchOperations
2369
+ },
2370
+ options?: BaseActionOptions,
2371
+ ): Observable<SingleActionResult>
2372
+ /**
2373
+ * @public
2374
+ *
2375
+ * Publishes all documents in a release at once. For larger releases the effect of the publish
2376
+ * will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
2377
+ * documents and creation of the corresponding published documents with the new content may
2378
+ * take some time.
2379
+ *
2380
+ * During this period both the source and target documents are locked and cannot be
2381
+ * modified through any other means.
2382
+ *
2383
+ * @category Releases
2384
+ *
2385
+ * @param params - Release action parameters:
2386
+ * - `releaseId` - The id of the release to publish.
2387
+ * @param options - Additional action options.
2388
+ * @returns An observable that resolves to the `transactionId`.
2389
+ */
2390
+ publish(
2391
+ {
2392
+ releaseId,
2393
+ }: {
2394
+ releaseId: string
2395
+ },
2396
+ options?: BaseActionOptions,
2397
+ ): Observable<SingleActionResult>
2398
+ /**
2399
+ * @public
2400
+ *
2401
+ * An archive action removes an active release. The documents that comprise the release
2402
+ * are deleted and therefore no longer queryable.
2403
+ *
2404
+ * While the documents remain in retention the last version can still be accessed using document history endpoint.
2405
+ *
2406
+ * @category Releases
2407
+ *
2408
+ * @param params - Release action parameters:
2409
+ * - `releaseId` - The id of the release to archive.
2410
+ * @param options - Additional action options.
2411
+ * @returns An observable that resolves to the `transactionId`.
2412
+ */
2413
+ archive(
2414
+ {
2415
+ releaseId,
2416
+ }: {
2417
+ releaseId: string
2418
+ },
2419
+ options?: BaseActionOptions,
2420
+ ): Observable<SingleActionResult>
2421
+ /**
2422
+ * @public
2423
+ *
2424
+ * An unarchive action restores an archived release and all documents
2425
+ * with the content they had just prior to archiving.
2426
+ *
2427
+ * @category Releases
2428
+ *
2429
+ * @param params - Release action parameters:
2430
+ * - `releaseId` - The id of the release to unarchive.
2431
+ * @param options - Additional action options.
2432
+ * @returns An observable that resolves to the `transactionId`.
2433
+ */
2434
+ unarchive(
2435
+ {
2436
+ releaseId,
2437
+ }: {
2438
+ releaseId: string
2439
+ },
2440
+ options?: BaseActionOptions,
2441
+ ): Observable<SingleActionResult>
2442
+ /**
2443
+ * @public
2444
+ *
2445
+ * A schedule action queues a release for publishing at the given future time.
2446
+ * The release is locked such that no documents in the release can be modified and
2447
+ * no documents that it references can be deleted as this would make the publish fail.
2448
+ * At the given time, the same logic as for the publish action is triggered.
2449
+ *
2450
+ * @category Releases
2451
+ *
2452
+ * @param params - Release action parameters:
2453
+ * - `releaseId` - The id of the release to schedule.
2454
+ * - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
2455
+ * @param options - Additional action options.
2456
+ * @returns An observable that resolves to the `transactionId`.
2457
+ */
2458
+ schedule(
2459
+ {
2460
+ releaseId,
2461
+ publishAt,
2462
+ }: {
2463
+ releaseId: string
2464
+ publishAt: string
2465
+ },
2466
+ options?: BaseActionOptions,
2467
+ ): Observable<SingleActionResult>
2468
+ /**
2469
+ * @public
2470
+ *
2471
+ * An unschedule action stops a release from being published.
2472
+ * The documents in the release are considered unlocked and can be edited again.
2473
+ * This may fail if another release is scheduled to be published after this one and
2474
+ * has a reference to a document created by this one.
2475
+ *
2476
+ * @category Releases
2477
+ *
2478
+ * @param params - Release action parameters:
2479
+ * - `releaseId` - The id of the release to unschedule.
2480
+ * @param options - Additional action options.
2481
+ * @returns An observable that resolves to the `transactionId`.
2482
+ */
2483
+ unschedule(
2484
+ {
2485
+ releaseId,
2486
+ }: {
2487
+ releaseId: string
2488
+ },
2489
+ options?: BaseActionOptions,
2490
+ ): Observable<SingleActionResult>
2491
+ /**
2492
+ * @public
2493
+ *
2494
+ * A delete action removes a published or archived release.
2495
+ * The backing system document will be removed from the dataset.
2496
+ *
2497
+ * @category Releases
2498
+ *
2499
+ * @param params - Release action parameters:
2500
+ * - `releaseId` - The id of the release to delete.
2501
+ * @param options - Additional action options.
2502
+ * @returns An observable that resolves to the `transactionId`.
2503
+ */
2504
+ delete(
2505
+ {
2506
+ releaseId,
2507
+ }: {
2508
+ releaseId: string
2509
+ },
2510
+ options?: BaseActionOptions,
2511
+ ): Observable<SingleActionResult>
2512
+ /**
2513
+ * @public
2514
+ *
2515
+ * Fetch the documents in a release by release id.
2516
+ *
2517
+ * @category Releases
2518
+ *
2519
+ * @param params - Release action parameters:
2520
+ * - `releaseId` - The id of the release to fetch documents for.
2521
+ * @param options - Additional mutation options {@link BaseMutationOptions}.
2522
+ * @returns An observable that resolves to the documents in the release.
2523
+ */
2524
+ fetchDocuments(
2525
+ {
2526
+ releaseId,
2527
+ }: {
2528
+ releaseId: string
2529
+ },
2530
+ options?: BaseMutationOptions,
2531
+ ): Observable<RawQueryResponse<SanityDocument[]>>
2532
+ }
2533
+
2117
2534
  /** @public */
2118
2535
  export declare class ObservableSanityClient {
2119
2536
  #private
@@ -2125,6 +2542,7 @@ export declare class ObservableSanityClient {
2125
2542
  agent: {
2126
2543
  action: ObservableAgentsActionClient
2127
2544
  }
2545
+ releases: ObservableReleasesClient
2128
2546
  /**
2129
2547
  * Instance properties
2130
2548
  */
@@ -2215,7 +2633,9 @@ export declare class ObservableSanityClient {
2215
2633
  getDocument<R extends Record<string, Any> = Record<string, Any>>(
2216
2634
  id: string,
2217
2635
  options?: {
2636
+ signal?: AbortSignal
2218
2637
  tag?: string
2638
+ releaseId?: string
2219
2639
  },
2220
2640
  ): Observable<SanityDocument<R> | undefined>
2221
2641
  /**
@@ -2398,6 +2818,90 @@ export declare class ObservableSanityClient {
2398
2818
  document: IdentifiedSanityDocumentStub<R>,
2399
2819
  options?: BaseMutationOptions,
2400
2820
  ): Observable<SanityDocument<R>>
2821
+ /**
2822
+ * @public
2823
+ *
2824
+ * Creates a new version of a published document.
2825
+ *
2826
+ * @remarks
2827
+ * * Requires a document with a `_type` property.
2828
+ * * Creating a version with no `releaseId` will create a new draft version of the published document.
2829
+ * * If the `document._id` is defined, it should be a draft or release version ID that matches the version ID generated from `publishedId` and `releaseId`.
2830
+ * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
2831
+ * * To create a version of an unpublished document, use the `client.create` method.
2832
+ *
2833
+ * @category Versions
2834
+ *
2835
+ * @param params - Version action parameters:
2836
+ * - `document` - The document to create as a new version (must include `_type`).
2837
+ * - `publishedId` - The ID of the published document being versioned.
2838
+ * - `releaseId` - The ID of the release to create the version for.
2839
+ * @param options - Additional action options.
2840
+ * @returns an observable that resolves to the `transactionId`.
2841
+ *
2842
+ * @example Creating a new version of a published document with a generated version ID
2843
+ * ```ts
2844
+ * client.observable.createVersion({
2845
+ * // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
2846
+ * document: {_type: 'myDocument', title: 'My Document'},
2847
+ * publishedId: 'myDocument',
2848
+ * releaseId: 'myRelease',
2849
+ * })
2850
+ *
2851
+ * // The following document will be created:
2852
+ * // {
2853
+ * // _id: 'versions.myRelease.myDocument',
2854
+ * // _type: 'myDocument',
2855
+ * // title: 'My Document',
2856
+ * // }
2857
+ * ```
2858
+ *
2859
+ * @example Creating a new version of a published document with a specified version ID
2860
+ * ```ts
2861
+ * client.observable.createVersion({
2862
+ * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
2863
+ * // `publishedId` and `releaseId` are not required since `document._id` has been specified
2864
+ * })
2865
+ *
2866
+ * // The following document will be created:
2867
+ * // {
2868
+ * // _id: 'versions.myRelease.myDocument',
2869
+ * // _type: 'myDocument',
2870
+ * // title: 'My Document',
2871
+ * // }
2872
+ * ```
2873
+ *
2874
+ * @example Creating a new draft version of a published document
2875
+ * ```ts
2876
+ * client.observable.createVersion({
2877
+ * document: {_type: 'myDocument', title: 'My Document'},
2878
+ * publishedId: 'myDocument',
2879
+ * })
2880
+ *
2881
+ * // The following document will be created:
2882
+ * // {
2883
+ * // _id: 'drafts.myDocument',
2884
+ * // _type: 'myDocument',
2885
+ * // title: 'My Document',
2886
+ * // }
2887
+ * ```
2888
+ */
2889
+ createVersion<R extends Record<string, Any>>(
2890
+ args: {
2891
+ document: SanityDocumentStub<R>
2892
+ publishedId: string
2893
+ releaseId?: string
2894
+ },
2895
+ options?: BaseActionOptions,
2896
+ ): Observable<SingleActionResult | MultipleActionResult>
2897
+ createVersion<R extends Record<string, Any>>(
2898
+ args: {
2899
+ document: IdentifiedSanityDocumentStub<R>
2900
+ publishedId?: string
2901
+ releaseId?: string
2902
+ },
2903
+ options?: BaseActionOptions,
2904
+ ): Observable<SingleActionResult | MultipleActionResult>
2401
2905
  /**
2402
2906
  * Deletes a document with the given document ID.
2403
2907
  * Returns an observable that resolves to the deleted document.
@@ -2502,6 +3006,157 @@ export declare class ObservableSanityClient {
2502
3006
  selection: MutationSelection,
2503
3007
  options?: BaseMutationOptions,
2504
3008
  ): Observable<SanityDocument<R>>
3009
+ /**
3010
+ * @public
3011
+ *
3012
+ * Deletes the draft or release version of a document.
3013
+ *
3014
+ * @remarks
3015
+ * * Discarding a version with no `releaseId` will discard the draft version of the published document.
3016
+ * * If the draft or release version does not exist, any error will throw.
3017
+ *
3018
+ * @param params - Version action parameters:
3019
+ * - `releaseId` - The ID of the release to discard the document from.
3020
+ * - `publishedId` - The published ID of the document to discard.
3021
+ * @param purge - if `true` the document history is also discarded.
3022
+ * @param options - Additional action options.
3023
+ * @returns an observable that resolves to the `transactionId`.
3024
+ *
3025
+ * @example Discarding a release version of a document
3026
+ * ```ts
3027
+ * client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
3028
+ * // The document with the ID `versions.myRelease.myDocument` will be discarded.
3029
+ * ```
3030
+ *
3031
+ * @example Discarding a draft version of a document
3032
+ * ```ts
3033
+ * client.observable.discardVersion({publishedId: 'myDocument'})
3034
+ * // The document with the ID `drafts.myDocument` will be discarded.
3035
+ * ```
3036
+ */
3037
+ discardVersion(
3038
+ {
3039
+ releaseId,
3040
+ publishedId,
3041
+ }: {
3042
+ releaseId?: string
3043
+ publishedId: string
3044
+ },
3045
+ purge?: boolean,
3046
+ options?: BaseActionOptions,
3047
+ ): Observable<SingleActionResult | MultipleActionResult>
3048
+ /**
3049
+ * @public
3050
+ *
3051
+ * Replaces an existing version document.
3052
+ *
3053
+ * @remarks
3054
+ * * Requires a document with a `_type` property.
3055
+ * * If the `document._id` is defined, it should be a draft or release version ID that matches the version ID generated from `publishedId` and `releaseId`.
3056
+ * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
3057
+ * * Replacing a version with no `releaseId` will replace the draft version of the published document.
3058
+ * * At least one of the **version** or **published** documents must exist.
3059
+ *
3060
+ * @param params - Version action parameters:
3061
+ * - `document` - The new document to replace the version with.
3062
+ * - `releaseId` - The ID of the release where the document version is replaced.
3063
+ * - `publishedId` - The ID of the published document to replace.
3064
+ * @param options - Additional action options.
3065
+ * @returns an observable that resolves to the `transactionId`.
3066
+ *
3067
+ * @example Replacing a release version of a published document with a generated version ID
3068
+ * ```ts
3069
+ * client.observable.replaceVersion({
3070
+ * document: {_type: 'myDocument', title: 'My Document'},
3071
+ * publishedId: 'myDocument',
3072
+ * releaseId: 'myRelease',
3073
+ * })
3074
+ *
3075
+ * // The following document will be patched:
3076
+ * // {
3077
+ * // _id: 'versions.myRelease.myDocument',
3078
+ * // _type: 'myDocument',
3079
+ * // title: 'My Document',
3080
+ * // }
3081
+ * ```
3082
+ *
3083
+ * @example Replacing a release version of a published document with a specified version ID
3084
+ * ```ts
3085
+ * client.observable.replaceVersion({
3086
+ * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
3087
+ * // `publishedId` and `releaseId` are not required since `document._id` has been specified
3088
+ * })
3089
+ *
3090
+ * // The following document will be patched:
3091
+ * // {
3092
+ * // _id: 'versions.myRelease.myDocument',
3093
+ * // _type: 'myDocument',
3094
+ * // title: 'My Document',
3095
+ * // }
3096
+ * ```
3097
+ *
3098
+ * @example Replacing a draft version of a published document
3099
+ * ```ts
3100
+ * client.observable.replaceVersion({
3101
+ * document: {_type: 'myDocument', title: 'My Document'},
3102
+ * publishedId: 'myDocument',
3103
+ * })
3104
+ *
3105
+ * // The following document will be patched:
3106
+ * // {
3107
+ * // _id: 'drafts.myDocument',
3108
+ * // _type: 'myDocument',
3109
+ * // title: 'My Document',
3110
+ * // }
3111
+ * ```
3112
+ */
3113
+ replaceVersion<R extends Record<string, Any>>(
3114
+ args: {
3115
+ document: SanityDocumentStub<R>
3116
+ publishedId: string
3117
+ releaseId?: string
3118
+ },
3119
+ options?: BaseActionOptions,
3120
+ ): Observable<SingleActionResult | MultipleActionResult>
3121
+ replaceVersion<R extends Record<string, Any>>(
3122
+ args: {
3123
+ document: IdentifiedSanityDocumentStub<R>
3124
+ publishedId?: string
3125
+ releaseId?: string
3126
+ },
3127
+ options?: BaseActionOptions,
3128
+ ): Observable<SingleActionResult | MultipleActionResult>
3129
+ /**
3130
+ * @public
3131
+ *
3132
+ * Used to indicate when a document within a release should be unpublished when
3133
+ * the release is run.
3134
+ *
3135
+ * @remarks
3136
+ * * If the published document does not exist, an error will be thrown.
3137
+ *
3138
+ * @param params - Version action parameters:
3139
+ * - `releaseId` - The ID of the release to unpublish the document from.
3140
+ * - `publishedId` - The published ID of the document to unpublish.
3141
+ * @param options - Additional action options.
3142
+ * @returns an observable that resolves to the `transactionId`.
3143
+ *
3144
+ * @example Unpublishing a release version of a published document
3145
+ * ```ts
3146
+ * client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
3147
+ * // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
3148
+ * ```
3149
+ */
3150
+ unpublishVersion(
3151
+ {
3152
+ releaseId,
3153
+ publishedId,
3154
+ }: {
3155
+ releaseId: string
3156
+ publishedId: string
3157
+ },
3158
+ options?: BaseActionOptions,
3159
+ ): Observable<SingleActionResult | MultipleActionResult>
2505
3160
  /**
2506
3161
  * Perform mutation operations against the configured dataset
2507
3162
  * Returns an observable that resolves to the first mutated document.
@@ -2703,6 +3358,9 @@ export declare type OpenEvent = {
2703
3358
  type: 'open'
2704
3359
  }
2705
3360
 
3361
+ /** @internal */
3362
+ export declare type PartialExcept<T, K extends keyof T> = Pick<T, K> & Partial<Omit<T, K>>
3363
+
2706
3364
  /** @public */
2707
3365
  export declare class Patch extends BasePatch {
2708
3366
  #private
@@ -2812,26 +3470,156 @@ export declare class ProjectsClient {
2812
3470
  }
2813
3471
 
2814
3472
  /**
2815
- * Publishes a draft document.
2816
- * If a published version of the document already exists this is replaced by the current draft document.
2817
- * In either case the draft document is deleted.
2818
- * The optional revision id parameters can be used for optimistic locking to ensure
2819
- * that the draft and/or published versions of the document have not been changed by another client.
2820
- *
2821
- * @public
3473
+ * @beta
2822
3474
  */
2823
- export declare type PublishAction = {
2824
- actionType: 'sanity.action.document.publish'
2825
- /**
2826
- * Draft document ID to publish
2827
- */
2828
- draftId: string
3475
+ declare interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
2829
3476
  /**
2830
- * Draft revision ID to match
3477
+ *
3478
+ * When true, the response body will be json according to the instruction.
3479
+ * When false, the response is the raw text response to the instruction.
3480
+ *
3481
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
2831
3482
  */
2832
- ifDraftRevisionId?: string
3483
+ json: true
3484
+ }
3485
+
3486
+ /** @beta */
3487
+ export declare type PromptRequest<T extends Record<string, Any> = Record<string, Any>> = (
3488
+ | PromptTextResponse
3489
+ | PromptJsonResponse<T>
3490
+ ) &
3491
+ PromptRequestBase
3492
+
3493
+ /** @beta */
3494
+ declare interface PromptRequestBase {
2833
3495
  /**
2834
- * Published document ID to replace
3496
+ * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
3497
+ *
3498
+ * The LLM only has access to information in the instruction, plus the target schema.
3499
+ *
3500
+ * string template using $variable
3501
+ * */
3502
+ instruction: string
3503
+ /**
3504
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
3505
+ *
3506
+ * ### Examples
3507
+ *
3508
+ * #### Constant
3509
+ *
3510
+ * ##### Shorthand
3511
+ * ```ts
3512
+ * client.agent.action.generate({
3513
+ * schemaId,
3514
+ * documentId,
3515
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it',
3516
+ * instructionParams: {
3517
+ * topic: 'Grapefruit'
3518
+ * },
3519
+ * })
3520
+ * ```
3521
+ * ##### Object-form
3522
+ *
3523
+ * ```ts
3524
+ * client.agent.action.prompt({
3525
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it.',
3526
+ * instructionParams: {
3527
+ * topic: {
3528
+ * type: 'constant',
3529
+ * value: 'Grapefruit'
3530
+ * },
3531
+ * },
3532
+ * })
3533
+ * ```
3534
+ * #### Field
3535
+ * ```ts
3536
+ * client.agent.action.prompt({
3537
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
3538
+ * instructionParams: {
3539
+ * pte: {
3540
+ * type: 'field',
3541
+ * path: ['pteField'],
3542
+ * documentId: 'someSanityDocId'
3543
+ * },
3544
+ * },
3545
+ * })
3546
+ * ```
3547
+ * #### Document
3548
+ * ```ts
3549
+ * client.agent.action.prompt({
3550
+ * json: true,
3551
+ * instruction: 'Given the following document:$document\nCreate a JSON string[] array with keywords describing it.',
3552
+ * instructionParams: {
3553
+ * document: {
3554
+ * type: 'document',
3555
+ * documentId: 'someSanityDocId'
3556
+ * },
3557
+ * },
3558
+ * })
3559
+ * ```
3560
+ *
3561
+ * #### GROQ
3562
+ * ```ts
3563
+ * client.agent.action.prompt({
3564
+ * instruction: 'Return the best title amongst these: $titles.',
3565
+ * instructionParams: {
3566
+ * titles: {
3567
+ * type: 'groq',
3568
+ * query: '* [_type==$type].title',
3569
+ * params: {type: 'article'}
3570
+ * },
3571
+ * },
3572
+ * })
3573
+ * ```
3574
+ * */
3575
+ instructionParams?: AgentActionParams<{
3576
+ docIdRequired: true
3577
+ }>
3578
+ /**
3579
+ * Controls how much variance the instructions will run with.
3580
+ *
3581
+ * Value must be in the range [0, 1] (inclusive).
3582
+ *
3583
+ * Defaults:
3584
+ * - generate: 0.3
3585
+ * - translate: 0
3586
+ * - transform: 0
3587
+ */
3588
+ temperature?: number
3589
+ }
3590
+
3591
+ declare interface PromptTextResponse {
3592
+ /**
3593
+ *
3594
+ * When true, the response body will be json according to the instruction.
3595
+ * When false, the response is the raw text response to the instruction.
3596
+ *
3597
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3598
+ */
3599
+ json?: false
3600
+ }
3601
+
3602
+ /**
3603
+ * Publishes a draft document.
3604
+ * If a published version of the document already exists this is replaced by the current draft document.
3605
+ * In either case the draft document is deleted.
3606
+ * The optional revision id parameters can be used for optimistic locking to ensure
3607
+ * that the draft and/or published versions of the document have not been changed by another client.
3608
+ *
3609
+ * @public
3610
+ */
3611
+ export declare type PublishAction = {
3612
+ actionType: 'sanity.action.document.publish'
3613
+ /**
3614
+ * Draft document ID to publish
3615
+ */
3616
+ draftId: string
3617
+ /**
3618
+ * Draft revision ID to match
3619
+ */
3620
+ ifDraftRevisionId?: string
3621
+ /**
3622
+ * Published document ID to replace
2835
3623
  */
2836
3624
  publishedId: string
2837
3625
  /**
@@ -2840,6 +3628,16 @@ export declare type PublishAction = {
2840
3628
  ifPublishedRevisionId?: string
2841
3629
  }
2842
3630
 
3631
+ /**
3632
+ * Publishes all documents in a release at once.
3633
+ *
3634
+ * @public
3635
+ */
3636
+ export declare interface PublishReleaseAction {
3637
+ actionType: 'sanity.action.release.publish'
3638
+ releaseId: string
3639
+ }
3640
+
2843
3641
  /** @public */
2844
3642
  export declare type QueryOptions =
2845
3643
  | FilteredResponseQueryOptions
@@ -2938,17 +3736,373 @@ export declare type ReconnectEvent = {
2938
3736
  type: 'reconnect'
2939
3737
  }
2940
3738
 
3739
+ /** @public */
3740
+ export declare type ReleaseAction =
3741
+ | CreateReleaseAction
3742
+ | EditReleaseAction
3743
+ | PublishReleaseAction
3744
+ | ArchiveReleaseAction
3745
+ | UnarchiveReleaseAction
3746
+ | ScheduleReleaseAction
3747
+ | UnscheduleReleaseAction
3748
+ | DeleteReleaseAction
3749
+
3750
+ /** @internal */
3751
+ export declare interface ReleaseDocument extends SanityDocument {
3752
+ /**
3753
+ * typically
3754
+ * `_.releases.<name>`
3755
+ */
3756
+ _id: string
3757
+ /**
3758
+ * where a release has _id `_.releases.foo`, the name is `foo`
3759
+ */
3760
+ name: string
3761
+ _type: 'system.release'
3762
+ _createdAt: string
3763
+ _updatedAt: string
3764
+ _rev: string
3765
+ state: ReleaseState
3766
+ error?: {
3767
+ message: string
3768
+ }
3769
+ finalDocumentStates?: {
3770
+ /** Document ID */
3771
+ id: string
3772
+ }[]
3773
+ /**
3774
+ * If defined, it takes precedence over the intendedPublishAt, the state should be 'scheduled'
3775
+ */
3776
+ publishAt?: string
3777
+ /**
3778
+ * If defined, it provides the time the release was actually published
3779
+ */
3780
+ publishedAt?: string
3781
+ metadata: {
3782
+ title?: string
3783
+ description?: string
3784
+ intendedPublishAt?: string
3785
+ releaseType: ReleaseType
3786
+ }
3787
+ }
3788
+
2941
3789
  /**
2942
3790
  * @public
2943
3791
  * @deprecated – The `r`-prefix is not required, use `string` instead
2944
3792
  */
2945
3793
  export declare type ReleaseId = `r${string}`
2946
3794
 
3795
+ /** @public */
3796
+ declare class ReleasesClient {
3797
+ #private
3798
+ constructor(client: SanityClient, httpRequest: HttpRequest)
3799
+ /**
3800
+ * @public
3801
+ *
3802
+ * Retrieve a release by id.
3803
+ *
3804
+ * @category Releases
3805
+ *
3806
+ * @param params - Release action parameters:
3807
+ * - `releaseId` - The id of the release to retrieve.
3808
+ * @param options - Additional query options including abort signal and query tag.
3809
+ * @returns A promise that resolves to the release document {@link ReleaseDocument}.
3810
+ *
3811
+ * @example Retrieving a release by id
3812
+ * ```ts
3813
+ * const release = await client.releases.get({releaseId: 'my-release'})
3814
+ * console.log(release)
3815
+ * // {
3816
+ * // _id: '_.releases.my-release',
3817
+ * // name: 'my-release'
3818
+ * // _type: 'system.release',
3819
+ * // metadata: {releaseType: 'asap'},
3820
+ * // _createdAt: '2021-01-01T00:00:00.000Z',
3821
+ * // ...
3822
+ * // }
3823
+ * ```
3824
+ */
3825
+ get(
3826
+ {
3827
+ releaseId,
3828
+ }: {
3829
+ releaseId: string
3830
+ },
3831
+ options?: {
3832
+ signal?: AbortSignal
3833
+ tag?: string
3834
+ },
3835
+ ): Promise<ReleaseDocument | undefined>
3836
+ /**
3837
+ * @public
3838
+ *
3839
+ * Creates a new release under the given id, with metadata.
3840
+ *
3841
+ * @remarks
3842
+ * * If no releaseId is provided, a release id will be generated.
3843
+ * * If no metadata is provided, then an `undecided` releaseType will be used.
3844
+ *
3845
+ * @category Releases
3846
+ *
3847
+ * @param params - Release action parameters:
3848
+ * - `releaseId` - The id of the release to create.
3849
+ * - `metadata` - The metadata to associate with the release {@link ReleaseDocument}.
3850
+ * @param options - Additional action options.
3851
+ * @returns A promise that resolves to the `transactionId` and the release id and metadata.
3852
+ *
3853
+ * @example Creating a release with a custom id and metadata
3854
+ * ```ts
3855
+ * const releaseId = 'my-release'
3856
+ * const releaseMetadata: ReleaseDocument['metadata'] = {
3857
+ * releaseType: 'asap',
3858
+ * }
3859
+ *
3860
+ * const result =
3861
+ * await client.releases.create({releaseId, metadata: releaseMetadata})
3862
+ * console.log(result)
3863
+ * // {
3864
+ * // transactionId: 'transaction-id',
3865
+ * // releaseId: 'my-release',
3866
+ * // metadata: {releaseType: 'asap'},
3867
+ * // }
3868
+ * ```
3869
+ *
3870
+ * @example Creating a release with generated id and metadata
3871
+ * ```ts
3872
+ * const {metadata} = await client.releases.create()
3873
+ * console.log(metadata.releaseType) // 'undecided'
3874
+ * ```
3875
+ *
3876
+ * @example Creating a release with a custom transaction id
3877
+ * ```ts
3878
+ * const {transactionId, metadata} = await client.releases.create({transactionId: 'my-transaction-id'})
3879
+ * console.log(metadata.releaseType) // 'undecided'
3880
+ * console.log(transactionId) // 'my-transaction-id'
3881
+ * ```
3882
+ */
3883
+ create(options: BaseActionOptions): Promise<
3884
+ SingleActionResult & {
3885
+ releaseId: string
3886
+ metadata: ReleaseDocument['metadata']
3887
+ }
3888
+ >
3889
+ create(
3890
+ release: {
3891
+ releaseId?: string
3892
+ metadata?: Partial<ReleaseDocument['metadata']>
3893
+ },
3894
+ options?: BaseActionOptions,
3895
+ ): Promise<
3896
+ SingleActionResult & {
3897
+ releaseId: string
3898
+ metadata: ReleaseDocument['metadata']
3899
+ }
3900
+ >
3901
+ /**
3902
+ * @public
3903
+ *
3904
+ * Edits an existing release, updating the metadata.
3905
+ *
3906
+ * @category Releases
3907
+ *
3908
+ * @param params - Release action parameters:
3909
+ * - `releaseId` - The id of the release to edit.
3910
+ * - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
3911
+ * @param options - Additional action options.
3912
+ * @returns A promise that resolves to the `transactionId`.
3913
+ */
3914
+ edit(
3915
+ {
3916
+ releaseId,
3917
+ patch,
3918
+ }: {
3919
+ releaseId: string
3920
+ patch: PatchOperations
3921
+ },
3922
+ options?: BaseActionOptions,
3923
+ ): Promise<SingleActionResult>
3924
+ /**
3925
+ * @public
3926
+ *
3927
+ * Publishes all documents in a release at once. For larger releases the effect of the publish
3928
+ * will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
3929
+ * documents and creation of the corresponding published documents with the new content may
3930
+ * take some time.
3931
+ *
3932
+ * During this period both the source and target documents are locked and cannot be
3933
+ * modified through any other means.
3934
+ *
3935
+ * @category Releases
3936
+ *
3937
+ * @param params - Release action parameters:
3938
+ * - `releaseId` - The id of the release to publish.
3939
+ * @param options - Additional action options.
3940
+ * @returns A promise that resolves to the `transactionId`.
3941
+ */
3942
+ publish(
3943
+ {
3944
+ releaseId,
3945
+ }: {
3946
+ releaseId: string
3947
+ },
3948
+ options?: BaseActionOptions,
3949
+ ): Promise<SingleActionResult>
3950
+ /**
3951
+ * @public
3952
+ *
3953
+ * An archive action removes an active release. The documents that comprise the release
3954
+ * are deleted and therefore no longer queryable.
3955
+ *
3956
+ * While the documents remain in retention the last version can still be accessed using document history endpoint.
3957
+ *
3958
+ * @category Releases
3959
+ *
3960
+ * @param params - Release action parameters:
3961
+ * - `releaseId` - The id of the release to archive.
3962
+ * @param options - Additional action options.
3963
+ * @returns A promise that resolves to the `transactionId`.
3964
+ */
3965
+ archive(
3966
+ {
3967
+ releaseId,
3968
+ }: {
3969
+ releaseId: string
3970
+ },
3971
+ options?: BaseActionOptions,
3972
+ ): Promise<SingleActionResult>
3973
+ /**
3974
+ * @public
3975
+ *
3976
+ * An unarchive action restores an archived release and all documents
3977
+ * with the content they had just prior to archiving.
3978
+ *
3979
+ * @category Releases
3980
+ *
3981
+ * @param params - Release action parameters:
3982
+ * - `releaseId` - The id of the release to unarchive.
3983
+ * @param options - Additional action options.
3984
+ * @returns A promise that resolves to the `transactionId`.
3985
+ */
3986
+ unarchive(
3987
+ {
3988
+ releaseId,
3989
+ }: {
3990
+ releaseId: string
3991
+ },
3992
+ options?: BaseActionOptions,
3993
+ ): Promise<SingleActionResult>
3994
+ /**
3995
+ * @public
3996
+ *
3997
+ * A schedule action queues a release for publishing at the given future time.
3998
+ * The release is locked such that no documents in the release can be modified and
3999
+ * no documents that it references can be deleted as this would make the publish fail.
4000
+ * At the given time, the same logic as for the publish action is triggered.
4001
+ *
4002
+ * @category Releases
4003
+ *
4004
+ * @param params - Release action parameters:
4005
+ * - `releaseId` - The id of the release to schedule.
4006
+ * - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
4007
+ * @param options - Additional action options.
4008
+ * @returns A promise that resolves to the `transactionId`.
4009
+ */
4010
+ schedule(
4011
+ {
4012
+ releaseId,
4013
+ publishAt,
4014
+ }: {
4015
+ releaseId: string
4016
+ publishAt: string
4017
+ },
4018
+ options?: BaseActionOptions,
4019
+ ): Promise<SingleActionResult>
4020
+ /**
4021
+ * @public
4022
+ *
4023
+ * An unschedule action stops a release from being published.
4024
+ * The documents in the release are considered unlocked and can be edited again.
4025
+ * This may fail if another release is scheduled to be published after this one and
4026
+ * has a reference to a document created by this one.
4027
+ *
4028
+ * @category Releases
4029
+ *
4030
+ * @param params - Release action parameters:
4031
+ * - `releaseId` - The id of the release to unschedule.
4032
+ * @param options - Additional action options.
4033
+ * @returns A promise that resolves to the `transactionId`.
4034
+ */
4035
+ unschedule(
4036
+ {
4037
+ releaseId,
4038
+ }: {
4039
+ releaseId: string
4040
+ },
4041
+ options?: BaseActionOptions,
4042
+ ): Promise<SingleActionResult>
4043
+ /**
4044
+ * @public
4045
+ *
4046
+ * A delete action removes a published or archived release.
4047
+ * The backing system document will be removed from the dataset.
4048
+ *
4049
+ * @category Releases
4050
+ *
4051
+ * @param params - Release action parameters:
4052
+ * - `releaseId` - The id of the release to delete.
4053
+ * @param options - Additional action options.
4054
+ * @returns A promise that resolves to the `transactionId`.
4055
+ */
4056
+ delete(
4057
+ {
4058
+ releaseId,
4059
+ }: {
4060
+ releaseId: string
4061
+ },
4062
+ options?: BaseActionOptions,
4063
+ ): Promise<SingleActionResult>
4064
+ /**
4065
+ * @public
4066
+ *
4067
+ * Fetch the documents in a release by release id.
4068
+ *
4069
+ * @category Releases
4070
+ *
4071
+ * @param params - Release action parameters:
4072
+ * - `releaseId` - The id of the release to fetch documents for.
4073
+ * @param options - Additional mutation options {@link BaseMutationOptions}.
4074
+ * @returns A promise that resolves to the documents in the release.
4075
+ */
4076
+ fetchDocuments(
4077
+ {
4078
+ releaseId,
4079
+ }: {
4080
+ releaseId: string
4081
+ },
4082
+ options?: BaseMutationOptions,
4083
+ ): Promise<RawQueryResponse<SanityDocument[]>>
4084
+ }
4085
+
4086
+ /** @beta */
4087
+ export declare type ReleaseState =
4088
+ | 'active'
4089
+ | 'archiving'
4090
+ | 'unarchiving'
4091
+ | 'archived'
4092
+ | 'published'
4093
+ | 'publishing'
4094
+ | 'scheduled'
4095
+ | 'scheduling'
4096
+
4097
+ /** @internal */
4098
+ export declare type ReleaseType = 'asap' | 'scheduled' | 'undecided'
4099
+
2947
4100
  /**
2948
4101
  * Replaces an existing draft document.
2949
4102
  * At least one of the draft or published versions of the document must exist.
2950
4103
  *
2951
4104
  * @public
4105
+ * @deprecated Use {@link ReplaceVersionAction} instead
2952
4106
  */
2953
4107
  export declare type ReplaceDraftAction = {
2954
4108
  actionType: 'sanity.action.document.replaceDraft'
@@ -2962,6 +4116,16 @@ export declare type ReplaceDraftAction = {
2962
4116
  attributes: IdentifiedSanityDocumentStub
2963
4117
  }
2964
4118
 
4119
+ /**
4120
+ * Replace an existing version of a document.
4121
+ *
4122
+ * @public
4123
+ */
4124
+ export declare interface ReplaceVersionAction {
4125
+ actionType: 'sanity.action.document.version.replace'
4126
+ document: IdentifiedSanityDocumentStub
4127
+ }
4128
+
2965
4129
  /** @public */
2966
4130
  export declare const requester: Requester
2967
4131
 
@@ -3047,6 +4211,7 @@ export declare class SanityClient {
3047
4211
  agent: {
3048
4212
  action: AgentActionsClient
3049
4213
  }
4214
+ releases: ReleasesClient
3050
4215
  /**
3051
4216
  * Observable version of the Sanity client, with the same configuration as the promise-based one
3052
4217
  */
@@ -3143,6 +4308,7 @@ export declare class SanityClient {
3143
4308
  options?: {
3144
4309
  signal?: AbortSignal
3145
4310
  tag?: string
4311
+ releaseId?: string
3146
4312
  },
3147
4313
  ): Promise<SanityDocument<R> | undefined>
3148
4314
  /**
@@ -3326,6 +4492,90 @@ export declare class SanityClient {
3326
4492
  document: IdentifiedSanityDocumentStub<R>,
3327
4493
  options?: BaseMutationOptions,
3328
4494
  ): Promise<SanityDocument<R>>
4495
+ /**
4496
+ * @public
4497
+ *
4498
+ * Creates a new version of a published document.
4499
+ *
4500
+ * @remarks
4501
+ * * Requires a document with a `_type` property.
4502
+ * * Creating a version with no `releaseId` will create a new draft version of the published document.
4503
+ * * If the `document._id` is defined, it should be a draft or release version ID that matches the version ID generated from `publishedId` and `releaseId`.
4504
+ * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
4505
+ * * To create a version of an unpublished document, use the `client.create` method.
4506
+ *
4507
+ * @category Versions
4508
+ *
4509
+ * @param params - Version action parameters:
4510
+ * - `document` - The document to create as a new version (must include `_type`).
4511
+ * - `publishedId` - The ID of the published document being versioned.
4512
+ * - `releaseId` - The ID of the release to create the version for.
4513
+ * @param options - Additional action options.
4514
+ * @returns A promise that resolves to the `transactionId`.
4515
+ *
4516
+ * @example Creating a new version of a published document with a generated version ID
4517
+ * ```ts
4518
+ * const transactionId = await client.createVersion({
4519
+ * // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
4520
+ * document: {_type: 'myDocument', title: 'My Document'},
4521
+ * publishedId: 'myDocument',
4522
+ * releaseId: 'myRelease',
4523
+ * })
4524
+ *
4525
+ * // The following document will be created:
4526
+ * // {
4527
+ * // _id: 'versions.myRelease.myDocument',
4528
+ * // _type: 'myDocument',
4529
+ * // title: 'My Document',
4530
+ * // }
4531
+ * ```
4532
+ *
4533
+ * @example Creating a new version of a published document with a specified version ID
4534
+ * ```ts
4535
+ * const transactionId = await client.createVersion({
4536
+ * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
4537
+ * // `publishedId` and `releaseId` are not required since `document._id` has been specified
4538
+ * })
4539
+ *
4540
+ * // The following document will be created:
4541
+ * // {
4542
+ * // _id: 'versions.myRelease.myDocument',
4543
+ * // _type: 'myDocument',
4544
+ * // title: 'My Document',
4545
+ * // }
4546
+ * ```
4547
+ *
4548
+ * @example Creating a new draft version of a published document
4549
+ * ```ts
4550
+ * const transactionId = await client.createVersion({
4551
+ * document: {_type: 'myDocument', title: 'My Document'},
4552
+ * publishedId: 'myDocument',
4553
+ * })
4554
+ *
4555
+ * // The following document will be created:
4556
+ * // {
4557
+ * // _id: 'drafts.myDocument',
4558
+ * // _type: 'myDocument',
4559
+ * // title: 'My Document',
4560
+ * // }
4561
+ * ```
4562
+ */
4563
+ createVersion<R extends Record<string, Any>>(
4564
+ args: {
4565
+ document: SanityDocumentStub<R>
4566
+ publishedId: string
4567
+ releaseId?: string
4568
+ },
4569
+ options?: BaseActionOptions,
4570
+ ): Promise<SingleActionResult | MultipleActionResult>
4571
+ createVersion<R extends Record<string, Any>>(
4572
+ args: {
4573
+ document: IdentifiedSanityDocumentStub<R>
4574
+ publishedId?: string
4575
+ releaseId?: string
4576
+ },
4577
+ options?: BaseActionOptions,
4578
+ ): Promise<SingleActionResult | MultipleActionResult>
3329
4579
  /**
3330
4580
  * Deletes a document with the given document ID.
3331
4581
  * Returns a promise that resolves to the deleted document.
@@ -3430,6 +4680,157 @@ export declare class SanityClient {
3430
4680
  selection: MutationSelection,
3431
4681
  options?: BaseMutationOptions,
3432
4682
  ): Promise<SanityDocument<R>>
4683
+ /**
4684
+ * @public
4685
+ *
4686
+ * Deletes the draft or release version of a document.
4687
+ *
4688
+ * @remarks
4689
+ * * Discarding a version with no `releaseId` will discard the draft version of the published document.
4690
+ * * If the draft or release version does not exist, any error will throw.
4691
+ *
4692
+ * @param params - Version action parameters:
4693
+ * - `releaseId` - The ID of the release to discard the document from.
4694
+ * - `publishedId` - The published ID of the document to discard.
4695
+ * @param purge - if `true` the document history is also discarded.
4696
+ * @param options - Additional action options.
4697
+ * @returns a promise that resolves to the `transactionId`.
4698
+ *
4699
+ * @example Discarding a release version of a document
4700
+ * ```ts
4701
+ * client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
4702
+ * // The document with the ID `versions.myRelease.myDocument` will be discarded.
4703
+ * ```
4704
+ *
4705
+ * @example Discarding a draft version of a document
4706
+ * ```ts
4707
+ * client.discardVersion({publishedId: 'myDocument'})
4708
+ * // The document with the ID `drafts.myDocument` will be discarded.
4709
+ * ```
4710
+ */
4711
+ discardVersion(
4712
+ {
4713
+ releaseId,
4714
+ publishedId,
4715
+ }: {
4716
+ releaseId?: string
4717
+ publishedId: string
4718
+ },
4719
+ purge?: boolean,
4720
+ options?: BaseActionOptions,
4721
+ ): Promise<SingleActionResult | MultipleActionResult>
4722
+ /**
4723
+ * @public
4724
+ *
4725
+ * Replaces an existing version document.
4726
+ *
4727
+ * @remarks
4728
+ * * Requires a document with a `_type` property.
4729
+ * * If the `document._id` is defined, it should be a draft or release version ID that matches the version ID generated from `publishedId` and `releaseId`.
4730
+ * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
4731
+ * * Replacing a version with no `releaseId` will replace the draft version of the published document.
4732
+ * * At least one of the **version** or **published** documents must exist.
4733
+ *
4734
+ * @param params - Version action parameters:
4735
+ * - `document` - The new document to replace the version with.
4736
+ * - `releaseId` - The ID of the release where the document version is replaced.
4737
+ * - `publishedId` - The ID of the published document to replace.
4738
+ * @param options - Additional action options.
4739
+ * @returns a promise that resolves to the `transactionId`.
4740
+ *
4741
+ * @example Replacing a release version of a published document with a generated version ID
4742
+ * ```ts
4743
+ * await client.replaceVersion({
4744
+ * document: {_type: 'myDocument', title: 'My Document'},
4745
+ * publishedId: 'myDocument',
4746
+ * releaseId: 'myRelease',
4747
+ * })
4748
+ *
4749
+ * // The following document will be patched:
4750
+ * // {
4751
+ * // _id: 'versions.myRelease.myDocument',
4752
+ * // _type: 'myDocument',
4753
+ * // title: 'My Document',
4754
+ * // }
4755
+ * ```
4756
+ *
4757
+ * @example Replacing a release version of a published document with a specified version ID
4758
+ * ```ts
4759
+ * await client.replaceVersion({
4760
+ * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
4761
+ * // `publishedId` and `releaseId` are not required since `document._id` has been specified
4762
+ * })
4763
+ *
4764
+ * // The following document will be patched:
4765
+ * // {
4766
+ * // _id: 'versions.myRelease.myDocument',
4767
+ * // _type: 'myDocument',
4768
+ * // title: 'My Document',
4769
+ * // }
4770
+ * ```
4771
+ *
4772
+ * @example Replacing a draft version of a published document
4773
+ * ```ts
4774
+ * await client.replaceVersion({
4775
+ * document: {_type: 'myDocument', title: 'My Document'},
4776
+ * publishedId: 'myDocument',
4777
+ * })
4778
+ *
4779
+ * // The following document will be patched:
4780
+ * // {
4781
+ * // _id: 'drafts.myDocument',
4782
+ * // _type: 'myDocument',
4783
+ * // title: 'My Document',
4784
+ * // }
4785
+ * ```
4786
+ */
4787
+ replaceVersion<R extends Record<string, Any>>(
4788
+ args: {
4789
+ document: SanityDocumentStub<R>
4790
+ publishedId: string
4791
+ releaseId?: string
4792
+ },
4793
+ options?: BaseActionOptions,
4794
+ ): Promise<SingleActionResult | MultipleActionResult>
4795
+ replaceVersion<R extends Record<string, Any>>(
4796
+ args: {
4797
+ document: IdentifiedSanityDocumentStub<R>
4798
+ publishedId?: string
4799
+ releaseId?: string
4800
+ },
4801
+ options?: BaseActionOptions,
4802
+ ): Promise<SingleActionResult | MultipleActionResult>
4803
+ /**
4804
+ * @public
4805
+ *
4806
+ * Used to indicate when a document within a release should be unpublished when
4807
+ * the release is run.
4808
+ *
4809
+ * @remarks
4810
+ * * If the published document does not exist, an error will be thrown.
4811
+ *
4812
+ * @param params - Version action parameters:
4813
+ * - `releaseId` - The ID of the release to unpublish the document from.
4814
+ * - `publishedId` - The published ID of the document to unpublish.
4815
+ * @param options - Additional action options.
4816
+ * @returns a promise that resolves to the `transactionId`.
4817
+ *
4818
+ * @example Unpublishing a release version of a published document
4819
+ * ```ts
4820
+ * await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
4821
+ * // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
4822
+ * ```
4823
+ */
4824
+ unpublishVersion(
4825
+ {
4826
+ releaseId,
4827
+ publishedId,
4828
+ }: {
4829
+ releaseId: string
4830
+ publishedId: string
4831
+ },
4832
+ options?: BaseActionOptions,
4833
+ ): Promise<SingleActionResult | MultipleActionResult>
3433
4834
  /**
3434
4835
  * Perform mutation operations against the configured dataset
3435
4836
  * Returns a promise that resolves to the first mutated document.
@@ -3470,7 +4871,7 @@ export declare class SanityClient {
3470
4871
  * @param operations - Mutation operations to execute
3471
4872
  * @param options - Mutation options
3472
4873
  */
3473
- mutate<R extends Record<string, Any>>(
4874
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
3474
4875
  operations: Mutation<R>[] | Patch | Transaction,
3475
4876
  options: AllDocumentIdsMutationOptions,
3476
4877
  ): Promise<MultipleMutationResult>
@@ -3686,6 +5087,17 @@ export declare interface SanityUser {
3686
5087
  isCurrentUser: boolean
3687
5088
  }
3688
5089
 
5090
+ /**
5091
+ * Queues release for publishing at the given future time.
5092
+ *
5093
+ * @public
5094
+ */
5095
+ export declare interface ScheduleReleaseAction {
5096
+ actionType: 'sanity.action.release.schedule'
5097
+ releaseId: string
5098
+ publishAt: string
5099
+ }
5100
+
3689
5101
  /** @public */
3690
5102
  export declare class ServerError extends Error {
3691
5103
  response: ErrorProps['response']
@@ -4164,6 +5576,16 @@ export declare interface TranslateTargetInclude extends AgentActionTargetInclude
4164
5576
  include?: (AgentActionPathSegment | TranslateTargetInclude)[]
4165
5577
  }
4166
5578
 
5579
+ /**
5580
+ * Unarchived an `archived` release, and restores all the release documents.
5581
+ *
5582
+ * @public
5583
+ */
5584
+ export declare interface UnarchiveReleaseAction {
5585
+ actionType: 'sanity.action.release.unarchive'
5586
+ releaseId: string
5587
+ }
5588
+
4167
5589
  /** @public */
4168
5590
  export declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
4169
5591
  filterResponse: false
@@ -4205,6 +5627,28 @@ export declare type UnpublishAction = {
4205
5627
  publishedId: string
4206
5628
  }
4207
5629
 
5630
+ /**
5631
+ * Identify that a version of a document should be unpublished when
5632
+ * the release that version is contained within is published.
5633
+ *
5634
+ * @public
5635
+ */
5636
+ export declare interface UnpublishVersionAction {
5637
+ actionType: 'sanity.action.document.version.unpublish'
5638
+ versionId: string
5639
+ publishedId: string
5640
+ }
5641
+
5642
+ /**
5643
+ * Unschedules a `scheduled` release, stopping it from being published.
5644
+ *
5645
+ * @public
5646
+ */
5647
+ export declare interface UnscheduleReleaseAction {
5648
+ actionType: 'sanity.action.release.unschedule'
5649
+ releaseId: string
5650
+ }
5651
+
4208
5652
  export {unstable__adapter}
4209
5653
 
4210
5654
  export {unstable__environment}
@@ -4292,6 +5736,13 @@ export declare function validateApiPerspective(
4292
5736
  perspective: unknown,
4293
5737
  ): asserts perspective is ClientPerspective
4294
5738
 
5739
+ /** @public */
5740
+ export declare type VersionAction =
5741
+ | CreateVersionAction
5742
+ | DiscardVersionAction
5743
+ | ReplaceVersionAction
5744
+ | UnpublishVersionAction
5745
+
4295
5746
  /**
4296
5747
  * The listener has been established, and will start receiving events.
4297
5748
  * Note that this is also emitted upon _reconnection_.