@sanity/sdk-react 0.0.0-alpha.2 → 0.0.0-alpha.20

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 (112) hide show
  1. package/README.md +38 -67
  2. package/dist/index.d.ts +4742 -2
  3. package/dist/index.js +1054 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +27 -58
  6. package/src/_exports/index.ts +66 -10
  7. package/src/components/Login/LoginLinks.test.tsx +2 -12
  8. package/src/components/Login/LoginLinks.tsx +14 -29
  9. package/src/components/SDKProvider.test.tsx +79 -0
  10. package/src/components/SDKProvider.tsx +42 -0
  11. package/src/components/SanityApp.test.tsx +156 -0
  12. package/src/components/SanityApp.tsx +90 -0
  13. package/src/components/auth/AuthBoundary.test.tsx +4 -17
  14. package/src/components/auth/AuthBoundary.tsx +20 -4
  15. package/src/components/auth/Login.test.tsx +2 -16
  16. package/src/components/auth/Login.tsx +11 -30
  17. package/src/components/auth/LoginCallback.test.tsx +2 -17
  18. package/src/components/auth/LoginCallback.tsx +5 -10
  19. package/src/components/auth/LoginError.test.tsx +2 -17
  20. package/src/components/auth/LoginError.tsx +11 -16
  21. package/src/components/auth/LoginFooter.test.tsx +2 -16
  22. package/src/components/auth/LoginFooter.tsx +8 -24
  23. package/src/components/auth/LoginLayout.test.tsx +2 -16
  24. package/src/components/auth/LoginLayout.tsx +8 -38
  25. package/src/components/auth/authTestHelpers.tsx +11 -0
  26. package/src/components/utils.ts +22 -0
  27. package/src/context/SanityInstanceContext.ts +4 -0
  28. package/src/{components/context → context}/SanityProvider.test.tsx +2 -2
  29. package/src/context/SanityProvider.tsx +50 -0
  30. package/src/hooks/_synchronous-groq-js.mjs +4 -0
  31. package/src/hooks/auth/useAuthState.tsx +4 -5
  32. package/src/hooks/auth/useAuthToken.tsx +1 -1
  33. package/src/hooks/auth/useCurrentUser.tsx +27 -4
  34. package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
  35. package/src/hooks/auth/useDashboardOrganizationId.tsx +29 -0
  36. package/src/hooks/auth/useHandleCallback.tsx +1 -0
  37. package/src/hooks/auth/useLogOut.tsx +1 -1
  38. package/src/hooks/auth/useLoginUrls.tsx +1 -0
  39. package/src/hooks/client/useClient.ts +8 -30
  40. package/src/hooks/comlink/useFrameConnection.test.tsx +167 -0
  41. package/src/hooks/comlink/useFrameConnection.ts +107 -0
  42. package/src/hooks/comlink/useManageFavorite.test.ts +106 -0
  43. package/src/hooks/comlink/useManageFavorite.ts +101 -0
  44. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +77 -0
  45. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +79 -0
  46. package/src/hooks/comlink/useWindowConnection.test.ts +135 -0
  47. package/src/hooks/comlink/useWindowConnection.ts +122 -0
  48. package/src/hooks/context/useSanityInstance.test.tsx +2 -2
  49. package/src/hooks/context/useSanityInstance.ts +24 -8
  50. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +97 -0
  51. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +274 -0
  52. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +91 -0
  53. package/src/hooks/datasets/useDatasets.ts +37 -0
  54. package/src/hooks/document/useApplyActions.test.ts +25 -0
  55. package/src/hooks/document/useApplyActions.ts +74 -0
  56. package/src/hooks/document/useDocument.test.ts +81 -0
  57. package/src/hooks/document/useDocument.ts +107 -0
  58. package/src/hooks/document/useDocumentEvent.test.ts +63 -0
  59. package/src/hooks/document/useDocumentEvent.ts +54 -0
  60. package/src/hooks/document/useDocumentSyncStatus.test.ts +16 -0
  61. package/src/hooks/document/useDocumentSyncStatus.ts +30 -0
  62. package/src/hooks/document/useEditDocument.test.ts +179 -0
  63. package/src/hooks/document/useEditDocument.ts +195 -0
  64. package/src/hooks/document/usePermissions.ts +82 -0
  65. package/src/hooks/helpers/createCallbackHook.tsx +3 -2
  66. package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
  67. package/src/hooks/helpers/createStateSourceHook.tsx +29 -10
  68. package/src/hooks/infiniteList/useInfiniteList.test.tsx +152 -0
  69. package/src/hooks/infiniteList/useInfiniteList.ts +174 -0
  70. package/src/hooks/paginatedList/usePaginatedList.test.tsx +259 -0
  71. package/src/hooks/paginatedList/usePaginatedList.ts +290 -0
  72. package/src/hooks/preview/usePreview.test.tsx +19 -10
  73. package/src/hooks/preview/usePreview.tsx +67 -13
  74. package/src/hooks/projection/useProjection.test.tsx +218 -0
  75. package/src/hooks/projection/useProjection.ts +147 -0
  76. package/src/hooks/projects/useProject.ts +45 -0
  77. package/src/hooks/projects/useProjects.ts +41 -0
  78. package/src/hooks/query/useQuery.test.tsx +188 -0
  79. package/src/hooks/query/useQuery.ts +103 -0
  80. package/src/hooks/users/useUsers.test.ts +163 -0
  81. package/src/hooks/users/useUsers.ts +107 -0
  82. package/src/utils/getEnv.ts +21 -0
  83. package/src/version.ts +8 -0
  84. package/src/vite-env.d.ts +10 -0
  85. package/dist/_chunks-es/useLogOut.js +0 -44
  86. package/dist/_chunks-es/useLogOut.js.map +0 -1
  87. package/dist/assets/bundle-CcAyERuZ.css +0 -11
  88. package/dist/components.d.ts +0 -257
  89. package/dist/components.js +0 -316
  90. package/dist/components.js.map +0 -1
  91. package/dist/hooks.d.ts +0 -187
  92. package/dist/hooks.js +0 -81
  93. package/dist/hooks.js.map +0 -1
  94. package/src/_exports/components.ts +0 -13
  95. package/src/_exports/hooks.ts +0 -9
  96. package/src/components/DocumentGridLayout/DocumentGridLayout.stories.tsx +0 -113
  97. package/src/components/DocumentGridLayout/DocumentGridLayout.test.tsx +0 -42
  98. package/src/components/DocumentGridLayout/DocumentGridLayout.tsx +0 -21
  99. package/src/components/DocumentListLayout/DocumentListLayout.stories.tsx +0 -105
  100. package/src/components/DocumentListLayout/DocumentListLayout.test.tsx +0 -42
  101. package/src/components/DocumentListLayout/DocumentListLayout.tsx +0 -12
  102. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.md +0 -49
  103. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.stories.tsx +0 -39
  104. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.test.tsx +0 -30
  105. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.tsx +0 -171
  106. package/src/components/context/SanityProvider.tsx +0 -42
  107. package/src/css/css.config.js +0 -220
  108. package/src/css/paramour.css +0 -2347
  109. package/src/css/styles.css +0 -11
  110. package/src/hooks/client/useClient.test.tsx +0 -130
  111. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  112. package/src/hooks/documentCollection/useDocuments.ts +0 -87
package/dist/index.d.ts CHANGED
@@ -1,7 +1,4747 @@
1
+ import {ActionsResult} from '@sanity/sdk'
2
+ import {ApplyActionsOptions} from '@sanity/sdk'
3
+ import {AuthProvider} from '@sanity/sdk'
4
+ import {AuthState} from '@sanity/sdk'
5
+ import {ClientOptions} from '@sanity/sdk'
6
+ import {CurrentUser} from '@sanity/sdk'
7
+ import {DocumentAction} from '@sanity/sdk'
8
+ import {DocumentEvent} from '@sanity/sdk'
9
+ import {DocumentHandle} from '@sanity/sdk'
10
+ import {FallbackProps} from 'react-error-boundary'
11
+ import {FrameMessage} from '@sanity/sdk'
12
+ import {JsonMatch} from '@sanity/sdk'
13
+ import {JsonMatchPath} from '@sanity/sdk'
14
+ import {Observable} from 'rxjs'
15
+ import {PermissionsResult} from '@sanity/sdk'
16
+ import {PreviewValue} from '@sanity/sdk'
17
+ import {QueryOptions} from '@sanity/sdk'
18
+ import {ReactElement} from 'react'
19
+ import {ReactNode} from 'react'
20
+ import {Requester} from 'get-it'
21
+ import {ResourceId} from '@sanity/sdk'
22
+ import {ResourceType} from '@sanity/sdk'
23
+ import {SanityConfig} from '@sanity/sdk'
24
+ import {SanityDocument} from '@sanity/types'
25
+ import {SanityInstance} from '@sanity/sdk'
26
+ import {SanityProject as SanityProject_2} from '@sanity/sdk'
27
+ import {SanityUser as SanityUser_2} from '@sanity/sdk'
28
+ import {SortOrderingItem} from '@sanity/types'
29
+ import {ValidProjection} from '@sanity/sdk'
30
+ import {WindowMessage} from '@sanity/sdk'
31
+
32
+ /** @public */
33
+ declare type Action =
34
+ | CreateAction
35
+ | ReplaceDraftAction
36
+ | EditAction
37
+ | DeleteAction
38
+ | DiscardAction
39
+ | PublishAction
40
+ | UnpublishAction
41
+
42
+ /** @internal */
43
+ declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
44
+ returnFirst: false
45
+ returnDocuments: false
46
+ }
47
+
48
+ /** @internal */
49
+ declare type AllDocumentsMutationOptions = BaseMutationOptions & {
50
+ returnFirst: false
51
+ returnDocuments?: true
52
+ }
53
+
54
+ /**
55
+ * Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
56
+ * @internal
57
+ */
58
+ declare type Any = any
59
+
60
+ /** @public */
61
+ declare type AssetMetadataType =
62
+ | 'location'
63
+ | 'exif'
64
+ | 'image'
65
+ | 'palette'
66
+ | 'lqip'
67
+ | 'blurhash'
68
+ | 'none'
69
+
70
+ /** @internal */
71
+ declare class AssetsClient {
72
+ #private
73
+ constructor(client: SanityClient, httpRequest: HttpRequest)
74
+ /**
75
+ * Uploads a file asset to the configured dataset
76
+ *
77
+ * @param assetType - Asset type (file)
78
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
79
+ * @param options - Options to use for the upload
80
+ */
81
+ upload(
82
+ assetType: 'file',
83
+ body: UploadBody,
84
+ options?: UploadClientConfig,
85
+ ): Promise<SanityAssetDocument>
86
+ /**
87
+ * Uploads an image asset to the configured dataset
88
+ *
89
+ * @param assetType - Asset type (image)
90
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
91
+ * @param options - Options to use for the upload
92
+ */
93
+ upload(
94
+ assetType: 'image',
95
+ body: UploadBody,
96
+ options?: UploadClientConfig,
97
+ ): Promise<SanityImageAssetDocument>
98
+ /**
99
+ * Uploads a file or an image asset to the configured dataset
100
+ *
101
+ * @param assetType - Asset type (file/image)
102
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
103
+ * @param options - Options to use for the upload
104
+ */
105
+ upload(
106
+ assetType: 'file' | 'image',
107
+ body: UploadBody,
108
+ options?: UploadClientConfig,
109
+ ): Promise<SanityAssetDocument | SanityImageAssetDocument>
110
+ }
111
+
112
+ /** @internal */
113
+ declare type AttributeSet = {
114
+ [key: string]: Any
115
+ }
116
+
117
+ /**
118
+ * A component that handles authentication flow and error boundaries for a
119
+ * protected section of the application.
120
+ *
121
+ * @remarks
122
+ * This component manages different authentication states and renders the
123
+ * appropriate components based on that state.
124
+ *
125
+ * @example
126
+ * ```tsx
127
+ * function App() {
128
+ * return (
129
+ * <AuthBoundary header={<MyLogo />}>
130
+ * <ProtectedContent />
131
+ * </AuthBoundary>
132
+ * )
133
+ * }
134
+ * ```
135
+ *
136
+ * @internal
137
+ */
138
+ export declare function AuthBoundary({
139
+ LoginErrorComponent,
140
+ ...props
141
+ }: AuthBoundaryProps): React.ReactNode
142
+
143
+ /**
144
+ * @internal
145
+ */
146
+ declare interface AuthBoundaryProps extends LoginLayoutProps {
147
+ /**
148
+ * Custom component to render the login screen.
149
+ * Receives all login layout props. Defaults to {@link Login}.
150
+ */
151
+ LoginComponent?: React.ComponentType<LoginLayoutProps>
152
+ /**
153
+ * Custom component to render during OAuth callback processing.
154
+ * Receives all login layout props. Defaults to {@link LoginCallback}.
155
+ */
156
+ CallbackComponent?: React.ComponentType<LoginLayoutProps>
157
+ /**
158
+ * Custom component to render when authentication errors occur.
159
+ * Receives login layout props and error boundary props. Defaults to
160
+ * {@link LoginError}
161
+ */
162
+ LoginErrorComponent?: React.ComponentType<LoginErrorProps>
163
+ }
164
+
165
+ /** @internal */
166
+ declare type BaseActionOptions = RequestOptions & {
167
+ transactionId?: string
168
+ skipCrossDatasetReferenceValidation?: boolean
169
+ dryRun?: boolean
170
+ }
171
+
172
+ /** @internal */
173
+ declare type BaseMutationOptions = RequestOptions & {
174
+ visibility?: 'sync' | 'async' | 'deferred'
175
+ returnDocuments?: boolean
176
+ returnFirst?: boolean
177
+ dryRun?: boolean
178
+ autoGenerateArrayKeys?: boolean
179
+ skipCrossDatasetReferenceValidation?: boolean
180
+ transactionId?: string
181
+ }
182
+
183
+ /** @internal */
184
+ declare class BasePatch {
185
+ protected selection: PatchSelection
186
+ protected operations: PatchOperations
187
+ constructor(selection: PatchSelection, operations?: PatchOperations)
188
+ /**
189
+ * Sets the given attributes to the document. Does NOT merge objects.
190
+ * The operation is added to the current patch, ready to be commited by `commit()`
191
+ *
192
+ * @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
193
+ */
194
+ set(attrs: AttributeSet): this
195
+ /**
196
+ * Sets the given attributes to the document if they are not currently set. Does NOT merge objects.
197
+ * The operation is added to the current patch, ready to be commited by `commit()`
198
+ *
199
+ * @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
200
+ */
201
+ setIfMissing(attrs: AttributeSet): this
202
+ /**
203
+ * Performs a "diff-match-patch" operation on the string attributes provided.
204
+ * The operation is added to the current patch, ready to be commited by `commit()`
205
+ *
206
+ * @param attrs - Attributes to perform operation on. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "dmp"\}
207
+ */
208
+ diffMatchPatch(attrs: AttributeSet): this
209
+ /**
210
+ * Unsets the attribute paths provided.
211
+ * The operation is added to the current patch, ready to be commited by `commit()`
212
+ *
213
+ * @param attrs - Attribute paths to unset.
214
+ */
215
+ unset(attrs: string[]): this
216
+ /**
217
+ * Increment a numeric value. Each entry in the argument is either an attribute or a JSON path. The value may be a positive or negative integer or floating-point value. The operation will fail if target value is not a numeric value, or doesn't exist.
218
+ *
219
+ * @param attrs - Object of attribute paths to increment, values representing the number to increment by.
220
+ */
221
+ inc(attrs: {[key: string]: number}): this
222
+ /**
223
+ * Decrement a numeric value. Each entry in the argument is either an attribute or a JSON path. The value may be a positive or negative integer or floating-point value. The operation will fail if target value is not a numeric value, or doesn't exist.
224
+ *
225
+ * @param attrs - Object of attribute paths to decrement, values representing the number to decrement by.
226
+ */
227
+ dec(attrs: {[key: string]: number}): this
228
+ /**
229
+ * Provides methods for modifying arrays, by inserting, appending and replacing elements via a JSONPath expression.
230
+ *
231
+ * @param at - Location to insert at, relative to the given selector, or 'replace' the matched path
232
+ * @param selector - JSONPath expression, eg `comments[-1]` or `blocks[_key=="abc123"]`
233
+ * @param items - Array of items to insert/replace
234
+ */
235
+ insert(at: 'before' | 'after' | 'replace', selector: string, items: Any[]): this
236
+ /**
237
+ * Append the given items to the array at the given JSONPath
238
+ *
239
+ * @param selector - Attribute/path to append to, eg `comments` or `person.hobbies`
240
+ * @param items - Array of items to append to the array
241
+ */
242
+ append(selector: string, items: Any[]): this
243
+ /**
244
+ * Prepend the given items to the array at the given JSONPath
245
+ *
246
+ * @param selector - Attribute/path to prepend to, eg `comments` or `person.hobbies`
247
+ * @param items - Array of items to prepend to the array
248
+ */
249
+ prepend(selector: string, items: Any[]): this
250
+ /**
251
+ * Change the contents of an array by removing existing elements and/or adding new elements.
252
+ *
253
+ * @param selector - Attribute or JSONPath expression for array
254
+ * @param start - Index at which to start changing the array (with origin 0). If greater than the length of the array, actual starting index will be set to the length of the array. If negative, will begin that many elements from the end of the array (with origin -1) and will be set to 0 if absolute value is greater than the length of the array.x
255
+ * @param deleteCount - An integer indicating the number of old array elements to remove.
256
+ * @param items - The elements to add to the array, beginning at the start index. If you don't specify any elements, splice() will only remove elements from the array.
257
+ */
258
+ splice(selector: string, start: number, deleteCount?: number, items?: Any[]): this
259
+ /**
260
+ * Adds a revision clause, preventing the document from being patched if the `_rev` property does not match the given value
261
+ *
262
+ * @param rev - Revision to lock the patch to
263
+ */
264
+ ifRevisionId(rev: string): this
265
+ /**
266
+ * Return a plain JSON representation of the patch
267
+ */
268
+ serialize(): PatchMutationOperation
269
+ /**
270
+ * Return a plain JSON representation of the patch
271
+ */
272
+ toJSON(): PatchMutationOperation
273
+ /**
274
+ * Clears the patch of all operations
275
+ */
276
+ reset(): this
277
+ protected _assign(op: keyof PatchOperations, props: Any, merge?: boolean): this
278
+ protected _set(op: keyof PatchOperations, props: Any): this
279
+ }
280
+
281
+ /** @internal */
282
+ declare class BaseTransaction {
283
+ protected operations: Mutation[]
284
+ protected trxId?: string
285
+ constructor(operations?: Mutation[], transactionId?: string)
286
+ /**
287
+ * Creates a new Sanity document. If `_id` is provided and already exists, the mutation will fail. If no `_id` is given, one will automatically be generated by the database.
288
+ * The operation is added to the current transaction, ready to be commited by `commit()`
289
+ *
290
+ * @param doc - Document to create. Requires a `_type` property.
291
+ */
292
+ create<R extends Record<string, Any> = Record<string, Any>>(doc: SanityDocumentStub<R>): this
293
+ /**
294
+ * Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
295
+ * The operation is added to the current transaction, ready to be commited by `commit()`
296
+ *
297
+ * @param doc - Document to create if it does not already exist. Requires `_id` and `_type` properties.
298
+ */
299
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
300
+ doc: IdentifiedSanityDocumentStub<R>,
301
+ ): this
302
+ /**
303
+ * Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
304
+ * The operation is added to the current transaction, ready to be commited by `commit()`
305
+ *
306
+ * @param doc - Document to create or replace. Requires `_id` and `_type` properties.
307
+ */
308
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
309
+ doc: IdentifiedSanityDocumentStub<R>,
310
+ ): this
311
+ /**
312
+ * Deletes the document with the given document ID
313
+ * The operation is added to the current transaction, ready to be commited by `commit()`
314
+ *
315
+ * @param documentId - Document ID to delete
316
+ */
317
+ delete(documentId: string): this
318
+ /**
319
+ * Gets the current transaction ID, if any
320
+ */
321
+ transactionId(): string | undefined
322
+ /**
323
+ * Set the ID of this transaction.
324
+ *
325
+ * @param id - Transaction ID
326
+ */
327
+ transactionId(id: string): this
328
+ /**
329
+ * Return a plain JSON representation of the transaction
330
+ */
331
+ serialize(): Mutation[]
332
+ /**
333
+ * Return a plain JSON representation of the transaction
334
+ */
335
+ toJSON(): Mutation[]
336
+ /**
337
+ * Clears the transaction of all operations
338
+ */
339
+ reset(): this
340
+ protected _add(mut: Mutation): this
341
+ }
342
+
343
+ /**
344
+ * An error occurred. This is different from a network-level error (which will be emitted as 'error').
345
+ * Possible causes are things such as malformed filters, non-existant datasets or similar.
346
+ *
347
+ * @public
348
+ */
349
+ declare type ChannelErrorEvent = {
350
+ type: 'channelError'
351
+ message: string
352
+ }
353
+
354
+ /** @public */
355
+ declare interface ClientConfig {
356
+ projectId?: string
357
+ dataset?: string
358
+ /** @defaultValue true */
359
+ useCdn?: boolean
360
+ token?: string
361
+ /**
362
+ * What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
363
+ * @remarks
364
+ * As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
365
+ * @defaultValue 'published'
366
+ */
367
+ perspective?: ClientPerspective
368
+ apiHost?: string
369
+ /**
370
+ @remarks
371
+ * As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
372
+ */
373
+ apiVersion?: string
374
+ proxy?: string
375
+ /**
376
+ * Optional request tag prefix for all request tags
377
+ */
378
+ requestTagPrefix?: string
379
+ ignoreBrowserTokenWarning?: boolean
380
+ withCredentials?: boolean
381
+ allowReconfigure?: boolean
382
+ timeout?: number
383
+ /** Number of retries for requests. Defaults to 5. */
384
+ maxRetries?: number
385
+ /**
386
+ * The amount of time, in milliseconds, to wait before retrying, given an attemptNumber (starting at 0).
387
+ *
388
+ * Defaults to exponential back-off, starting at 100ms, doubling for each attempt, together with random
389
+ * jitter between 0 and 100 milliseconds. More specifically the following algorithm is used:
390
+ *
391
+ * Delay = 100 * 2^attemptNumber + randomNumberBetween0and100
392
+ */
393
+ retryDelay?: (attemptNumber: number) => number
394
+ /**
395
+ * @deprecated Don't use
396
+ */
397
+ useProjectHostname?: boolean
398
+ /**
399
+ * @deprecated Don't use
400
+ */
401
+ requester?: Requester
402
+ /**
403
+ * Adds a `resultSourceMap` key to the API response, with the type `ContentSourceMap`
404
+ */
405
+ resultSourceMap?: boolean | 'withKeyArraySelector'
406
+ /**
407
+ *@deprecated set `cache` and `next` options on `client.fetch` instead
408
+ */
409
+ fetch?:
410
+ | {
411
+ cache?: ResponseQueryOptions['cache']
412
+ next?: ResponseQueryOptions['next']
413
+ }
414
+ | boolean
415
+ /**
416
+ * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
417
+ */
418
+ stega?: StegaConfig | boolean
419
+ }
420
+
421
+ /** @public */
422
+ declare type ClientPerspective =
423
+ | DeprecatedPreviewDrafts
424
+ | 'published'
425
+ | 'drafts'
426
+ | 'raw'
427
+ | StackablePerspective[]
428
+
429
+ /** @public */
430
+ declare type ClientReturn<
431
+ GroqString extends string,
432
+ Fallback = Any,
433
+ > = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
434
+
435
+ /**
436
+ * @public
437
+ */
438
+ export declare type ComlinkStatus = 'idle' | 'handshaking' | 'connected' | 'disconnected'
439
+
440
+ /** @public */
441
+ declare interface ContentSourceMap {
442
+ mappings: ContentSourceMapMappings
443
+ documents: ContentSourceMapDocuments_2
444
+ paths: ContentSourceMapPaths
445
+ }
446
+
447
+ /** @public */
448
+ declare interface ContentSourceMapDocument extends ContentSourceMapDocumentBase {
449
+ _projectId?: undefined
450
+ _dataset?: undefined
451
+ }
452
+
453
+ /** @public */
454
+ declare interface ContentSourceMapDocument_2 extends ContentSourceMapDocumentBase_2 {
455
+ _projectId?: undefined
456
+ _dataset?: undefined
457
+ }
458
+
459
+ /** @public */
460
+ declare interface ContentSourceMapDocumentBase {
461
+ _id: string
462
+ _type: string
463
+ }
464
+
465
+ /** @public */
466
+ declare interface ContentSourceMapDocumentBase_2 {
467
+ _id: string
468
+ _type: string
469
+ }
470
+
471
+ /** @public */
472
+ declare type ContentSourceMapDocuments = (
473
+ | ContentSourceMapDocument
474
+ | ContentSourceMapRemoteDocument
475
+ )[]
476
+
477
+ /** @public */
478
+ declare type ContentSourceMapDocuments_2 = (
479
+ | ContentSourceMapDocument_2
480
+ | ContentSourceMapRemoteDocument_2
481
+ )[]
482
+
483
+ /**
484
+ * DocumentValueSource is a path to a value within a document
485
+ * @public
486
+ */
487
+ declare interface ContentSourceMapDocumentValueSource {
488
+ type: 'documentValue'
489
+ document: number
490
+ path: number
491
+ }
492
+
493
+ /**
494
+ * When a value is not from a source, its a literal
495
+ * @public
496
+ */
497
+ declare interface ContentSourceMapLiteralSource {
498
+ type: 'literal'
499
+ }
500
+
501
+ /** @public */
502
+ declare type ContentSourceMapMapping = ContentSourceMapValueMapping
503
+
504
+ /** @public */
505
+ declare type ContentSourceMapMappings = Record<string, ContentSourceMapMapping>
506
+
507
+ /** @alpha */
508
+ declare type ContentSourceMapParsedPath = (
509
+ | string
510
+ | number
511
+ | ContentSourceMapParsedPathKeyedSegment
512
+ )[]
513
+
514
+ /** @alpha */
515
+ declare type ContentSourceMapParsedPathKeyedSegment = {
516
+ _key: string
517
+ _index: number
518
+ }
519
+
520
+ /** @public */
521
+ declare type ContentSourceMapPaths = string[]
522
+
523
+ /** @public */
524
+ declare interface ContentSourceMapRemoteDocument extends ContentSourceMapDocumentBase {
525
+ _projectId: string
526
+ _dataset: string
527
+ }
528
+
529
+ /** @public */
530
+ declare interface ContentSourceMapRemoteDocument_2 extends ContentSourceMapDocumentBase_2 {
531
+ _projectId: string
532
+ _dataset: string
533
+ }
534
+
535
+ /** @public */
536
+ declare type ContentSourceMapSource =
537
+ | ContentSourceMapDocumentValueSource
538
+ | ContentSourceMapLiteralSource
539
+ | ContentSourceMapUnknownSource
540
+
541
+ /**
542
+ * When a field source is unknown
543
+ * @public
544
+ */
545
+ declare interface ContentSourceMapUnknownSource {
546
+ type: 'unknown'
547
+ }
548
+
549
+ /**
550
+ * ValueMapping is a mapping when for value that is from a single source value
551
+ * It may refer to a field within a document or a literal value
552
+ * @public
553
+ */
554
+ declare interface ContentSourceMapValueMapping {
555
+ type: 'value'
556
+ source: ContentSourceMapSource
557
+ }
558
+
559
+ /**
560
+ * Creates a new draft document. The published version of the document must not already exist.
561
+ * If the draft version of the document already exists the action will fail by default, but
562
+ * this can be adjusted to instead leave the existing document in place.
563
+ *
564
+ * @public
565
+ */
566
+ declare type CreateAction = {
567
+ actionType: 'sanity.action.document.create'
568
+ /**
569
+ * ID of the published document to create a draft for.
570
+ */
571
+ publishedId: string
572
+ /**
573
+ * Document to create. Requires a `_type` property.
574
+ */
575
+ attributes: IdentifiedSanityDocumentStub
576
+ /**
577
+ * ifExists controls what to do if the draft already exists
578
+ */
579
+ ifExists: 'fail' | 'ignore'
580
+ }
581
+
582
+ /** @public */
583
+ declare interface CurrentSanityUser {
584
+ id: string
585
+ name: string
586
+ email: string
587
+ profileImage: string | null
588
+ role: string
589
+ }
590
+
591
+ export {CurrentUser}
592
+
593
+ /** @public */
594
+ declare type DatasetAclMode = 'public' | 'private' | 'custom'
595
+
596
+ /** @public */
597
+ declare type DatasetResponse = {
598
+ datasetName: string
599
+ aclMode: DatasetAclMode
600
+ }
601
+
602
+ /** @internal */
603
+ declare class DatasetsClient {
604
+ #private
605
+ constructor(client: SanityClient, httpRequest: HttpRequest)
606
+ /**
607
+ * Create a new dataset with the given name
608
+ *
609
+ * @param name - Name of the dataset to create
610
+ * @param options - Options for the dataset
611
+ */
612
+ create(
613
+ name: string,
614
+ options?: {
615
+ aclMode?: DatasetAclMode
616
+ },
617
+ ): Promise<DatasetResponse>
618
+ /**
619
+ * Edit a dataset with the given name
620
+ *
621
+ * @param name - Name of the dataset to edit
622
+ * @param options - New options for the dataset
623
+ */
624
+ edit(
625
+ name: string,
626
+ options?: {
627
+ aclMode?: DatasetAclMode
628
+ },
629
+ ): Promise<DatasetResponse>
630
+ /**
631
+ * Delete a dataset with the given name
632
+ *
633
+ * @param name - Name of the dataset to delete
634
+ */
635
+ delete(name: string): Promise<{
636
+ deleted: true
637
+ }>
638
+ /**
639
+ * Fetch a list of datasets for the configured project
640
+ */
641
+ list(): Promise<DatasetsResponse>
642
+ }
643
+
644
+ /** @public */
645
+ export declare type DatasetsResponse = {
646
+ name: string
647
+ aclMode: DatasetAclMode
648
+ createdAt: string
649
+ createdByUserId: string
650
+ addonFor: string | null
651
+ datasetProfile: string
652
+ features: string[]
653
+ tags: string[]
654
+ }[]
655
+
656
+ /**
657
+ * Deletes the published version of a document and optionally some (likely all known) draft versions.
658
+ * If any draft version exists that is not specified for deletion this is an error.
659
+ * If the purge flag is set then the document history is also deleted.
660
+ *
661
+ * @public
662
+ */
663
+ declare type DeleteAction = {
664
+ actionType: 'sanity.action.document.delete'
665
+ /**
666
+ * Published document ID to delete
667
+ */
668
+ publishedId: string
669
+ /**
670
+ * Draft document ID to delete
671
+ */
672
+ includeDrafts: string[]
673
+ /**
674
+ * Delete document history
675
+ */
676
+ purge?: boolean
677
+ }
678
+
679
+ /**
680
+ * @deprecated use 'drafts' instead
681
+ */
682
+ declare type DeprecatedPreviewDrafts = 'previewDrafts'
683
+
684
+ /**
685
+ * Delete the draft version of a document.
686
+ * It is an error if it does not exist. If the purge flag is set, the document history is also deleted.
687
+ *
688
+ * @public
689
+ */
690
+ declare type DiscardAction = {
691
+ actionType: 'sanity.action.document.discard'
692
+ /**
693
+ * Draft document ID to delete
694
+ */
695
+ draftId: string
696
+ /**
697
+ * Delete document history
698
+ */
699
+ purge?: boolean
700
+ }
701
+
702
+ /**
703
+ * The listener has been told to explicitly disconnect and not reconnect.
704
+ * This is a rare situation, but may occur if the API knows reconnect attempts will fail,
705
+ * eg in the case of a deleted dataset, a blocked project or similar events.
706
+ *
707
+ * Note that this is not treated as an error on the observable, but will complete the observable.
708
+ *
709
+ * @public
710
+ */
711
+ declare type DisconnectEvent = {
712
+ type: 'disconnect'
713
+ reason: string
714
+ }
715
+
716
+ export {DocumentHandle}
717
+
718
+ declare interface DocumentInteractionHistory {
719
+ recordEvent: (eventType: 'viewed' | 'edited' | 'created' | 'deleted') => void
720
+ isConnected: boolean
721
+ }
722
+
723
+ /**
724
+ * Modifies an existing draft document.
725
+ * It applies the given patch to the document referenced by draftId.
726
+ * If there is no such document then one is created using the current state of the published version and then that is updated accordingly.
727
+ *
728
+ * @public
729
+ */
730
+ declare type EditAction = {
731
+ actionType: 'sanity.action.document.edit'
732
+ /**
733
+ * Draft document ID to edit
734
+ */
735
+ draftId: string
736
+ /**
737
+ * Published document ID to create draft from, if draft does not exist
738
+ */
739
+ publishedId: string
740
+ /**
741
+ * Patch operations to apply
742
+ */
743
+ patch: PatchOperations
744
+ }
745
+
746
+ /** @public */
747
+ declare type FilterDefault = (props: {
748
+ /**
749
+ * The path to the value in the source document, for example if you queried for a document like this:
750
+ * `*[_type == "author"][0]{"slug": slug.current}`
751
+ * Then the `sourcePath` for `result.slug` would be `['slug', 'current']`.
752
+ *
753
+ */
754
+ sourcePath: ContentSourceMapParsedPath
755
+ /**
756
+ * If `sourcePath` alone isn't enough to tell you if it's safe to contain stega strings, then you can use `sourceDocument`
757
+ * for additional metadata.
758
+ * It'll always have a `_type` property, which can be used to trace it to the Studio Schema that were used initially.
759
+ * It also has `_id` to help you debug and look at the whole document when troubleshooting.
760
+ * Finally, if the document origins in a Cross Dataset Reference you'll also have `_projectId` and `_dataset` properties to help you trace it.
761
+ */
762
+ sourceDocument: ContentSourceMapDocuments[number]
763
+ /**
764
+ * If you don't colocate your Studio Schemas with your GROQ queries it might be hard to make sense of `sourcePath`,
765
+ * as it operates on the original shape of a document.
766
+ * In that case `resultPath` can be used, as it mirrors the path to the value in the result.
767
+ * For example in a query like this:
768
+ * `*[_type == "author"][0]{"slug": slug.current}`
769
+ * The `resultPath` for `result.slug` would be `['slug']`, while `sourcePath` will be `['slug', 'current']`.
770
+ */
771
+ resultPath: ContentSourceMapParsedPath
772
+ /**
773
+ * You can also use your own string validation logic to determine if it's safe.
774
+ */
775
+ value: string
776
+ /**
777
+ * If you want to keep the default filtering behavior, but only override it for a specific path, you can use `filterDefault` to do that.
778
+ * For example, here all "icon" documents in a Page Builder skips encoding:
779
+ * ```ts
780
+ {
781
+ filter: (props) => {
782
+ switch (props.sourceDocument._type) {
783
+ case 'icon':
784
+ return false
785
+ default:
786
+ return props.filterDefault(props)
787
+ }
788
+ }
789
+ }
790
+ * ```
791
+ */
792
+ filterDefault: FilterDefault
793
+ }) => boolean
794
+
795
+ /** @public */
796
+ declare interface FilteredResponseQueryOptions extends ResponseQueryOptions {
797
+ filterResponse?: true
798
+ }
799
+
800
+ /** @internal */
801
+ declare type FirstDocumentIdMutationOptions = BaseMutationOptions & {
802
+ returnFirst?: true
803
+ returnDocuments: false
804
+ }
805
+
806
+ /** @internal */
807
+ declare type FirstDocumentMutationOptions = BaseMutationOptions & {
808
+ returnFirst?: true
809
+ returnDocuments?: true
810
+ }
811
+
812
+ /**
813
+ * @internal
814
+ */
815
+ export declare interface FrameConnection<TFrameMessage extends FrameMessage> {
816
+ connect: (frameWindow: Window) => () => void
817
+ sendMessage: <T extends TFrameMessage['type']>(
818
+ ...params: Extract<
819
+ TFrameMessage,
820
+ {
821
+ type: T
822
+ }
823
+ >['data'] extends undefined
824
+ ? [type: T]
825
+ : [
826
+ type: T,
827
+ data: Extract<
828
+ TFrameMessage,
829
+ {
830
+ type: T
831
+ }
832
+ >['data'],
833
+ ]
834
+ ) => void
835
+ }
836
+
837
+ /** @public */
838
+ declare type HttpRequest = {
839
+ (options: RequestOptions, requester: Requester): ReturnType<Requester>
840
+ }
841
+
842
+ /** @public */
843
+ declare type HttpRequestEvent<T = unknown> = ResponseEvent<T> | ProgressEvent_2
844
+
845
+ /** @public */
846
+ declare type IdentifiedSanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
847
+ [P in keyof T]: T[P]
848
+ } & {
849
+ _id: string
850
+ } & SanityDocumentStub
851
+
852
+ /**
853
+ * Return value from the useInfiniteList hook
854
+ *
855
+ * @beta
856
+ * @category Types
857
+ */
858
+ export declare interface InfiniteList {
859
+ /**
860
+ * Array of document handles for the current batch
861
+ */
862
+ data: DocumentHandle[]
863
+ /**
864
+ * Whether there are more items available to load
865
+ */
866
+ hasMore: boolean
867
+ /**
868
+ * Total count of items matching the query
869
+ */
870
+ count: number
871
+ /**
872
+ * Whether a query is currently in progress
873
+ */
874
+ isPending: boolean
875
+ /**
876
+ * Function to load the next batch of results
877
+ */
878
+ loadMore: () => void
879
+ }
880
+
881
+ /**
882
+ * Configuration options for the useInfiniteList hook
883
+ *
884
+ * @beta
885
+ * @category Types
886
+ */
887
+ export declare interface InfiniteListOptions extends QueryOptions {
888
+ /**
889
+ * GROQ filter expression to apply to the query
890
+ */
891
+ filter?: string
892
+ /**
893
+ * Number of items to load per batch (defaults to 25)
894
+ */
895
+ batchSize?: number
896
+ /**
897
+ * Sorting configuration for the results
898
+ */
899
+ orderings?: SortOrderingItem[]
900
+ /**
901
+ * Text search query to filter results
902
+ */
903
+ search?: string
904
+ }
905
+
906
+ /** @public */
907
+ declare interface InitializedClientConfig extends ClientConfig {
908
+ apiHost: string
909
+ apiVersion: string
910
+ useProjectHostname: boolean
911
+ useCdn: boolean
912
+ /**
913
+ * @deprecated Internal, don't use
914
+ */
915
+ isDefaultApi: boolean
916
+ /**
917
+ * @deprecated Internal, don't use
918
+ */
919
+ url: string
920
+ /**
921
+ * @deprecated Internal, don't use
922
+ */
923
+ cdnUrl: string
924
+ /**
925
+ * The fully initialized stega config, can be used to check if stega is enabled
926
+ */
927
+ stega: InitializedStegaConfig
928
+ }
929
+
930
+ /** @public */
931
+ declare type InitializedStegaConfig = Omit<StegaConfig, StegaConfigRequiredKeys> &
932
+ Required<Pick<StegaConfig, StegaConfigRequiredKeys>>
933
+
934
+ /** @internal */
935
+ declare type InsertPatch =
936
+ | {
937
+ before: string
938
+ items: Any[]
939
+ }
940
+ | {
941
+ after: string
942
+ items: Any[]
943
+ }
944
+ | {
945
+ replace: string
946
+ items: Any[]
947
+ }
948
+
949
+ /**
950
+ * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
951
+ *
952
+ * @param query - GROQ-filter to listen to changes for
953
+ * @param params - Optional query parameters
954
+ * @param options - Optional listener options
955
+ * @public
956
+ */
957
+ declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
958
+ this: SanityClient | ObservableSanityClient,
959
+ query: string,
960
+ params?: ListenParams,
961
+ ): Observable<MutationEvent_2<R>>
962
+
963
+ /**
964
+ * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
965
+ *
966
+ * @param query - GROQ-filter to listen to changes for
967
+ * @param params - Optional query parameters
968
+ * @param options - Optional listener options
969
+ * @public
970
+ */
971
+ declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
972
+ this: SanityClient | ObservableSanityClient,
973
+ query: string,
974
+ params?: ListenParams,
975
+ options?: ListenOptions,
976
+ ): Observable<ListenEvent<R>>
977
+
978
+ /** @public */
979
+ declare type ListenEvent<R extends Record<string, Any>> =
980
+ | MutationEvent_2<R>
981
+ | ChannelErrorEvent
982
+ | DisconnectEvent
983
+ | ReconnectEvent
984
+ | WelcomeEvent
985
+ | OpenEvent
986
+
987
+ /** @public */
988
+ declare type ListenEventName =
989
+ /** A mutation was performed */
990
+ | 'mutation'
991
+ /** The listener has been (re)established */
992
+ | 'welcome'
993
+ /** The listener has been disconnected, and a reconnect attempt is scheduled */
994
+ | 'reconnect'
995
+
996
+ /** @public */
997
+ declare interface ListenOptions {
998
+ /**
999
+ * Whether or not to include the resulting document in addition to the mutations performed.
1000
+ * If you do not need the actual document, set this to `false` to reduce bandwidth usage.
1001
+ * The result will be available on the `.result` property of the events.
1002
+ * @defaultValue `true`
1003
+ */
1004
+ includeResult?: boolean
1005
+ /**
1006
+ * Whether or not to include the mutations that was performed.
1007
+ * If you do not need the mutations, set this to `false` to reduce bandwidth usage.
1008
+ * @defaultValue `true`
1009
+ */
1010
+ includeMutations?: boolean
1011
+ /**
1012
+ * Whether or not to include the document as it looked before the mutation event.
1013
+ * The previous revision will be available on the `.previous` property of the events,
1014
+ * and may be `null` in the case of a new document.
1015
+ * @defaultValue `false`
1016
+ */
1017
+ includePreviousRevision?: boolean
1018
+ /**
1019
+ * Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
1020
+ * for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
1021
+ * If you need events from drafts and versions, set this to `true`.
1022
+ * Note: Keep in mind that additional document variants may be introduced in the future, so it's
1023
+ * recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
1024
+ * explicitly checking whether the event is for a draft or a version.
1025
+ * @defaultValue `false`
1026
+ */
1027
+ includeAllVersions?: boolean
1028
+ /**
1029
+ * Whether events should be sent as soon as a transaction has been committed (`transaction`, default),
1030
+ * or only after they are available for queries (query). Note that this is on a best-effort basis,
1031
+ * and listeners with `query` may in certain cases (notably with deferred transactions) receive events
1032
+ * that are not yet visible to queries.
1033
+ *
1034
+ * @defaultValue `'transaction'`
1035
+ */
1036
+ visibility?: 'transaction' | 'query'
1037
+ /**
1038
+ * Array of event names to include in the observable. By default, only mutation events are included.
1039
+ *
1040
+ * @defaultValue `['mutation']`
1041
+ */
1042
+ events?: ListenEventName[]
1043
+ /**
1044
+ * Format of "effects", eg the resulting changes of a mutation.
1045
+ * Currently only `mendoza` is supported, and (if set) will include `apply` and `revert` arrays
1046
+ * in the mutation events under the `effects` property.
1047
+ *
1048
+ * See {@link https://github.com/sanity-io/mendoza | The mendoza docs} for more info
1049
+ *
1050
+ * @defaultValue `undefined`
1051
+ */
1052
+ effectFormat?: 'mendoza'
1053
+ /**
1054
+ * Optional request tag for the listener. Use to identify the request in logs.
1055
+ *
1056
+ * @defaultValue `undefined`
1057
+ */
1058
+ tag?: string
1059
+ }
1060
+
1061
+ /** @public */
1062
+ declare type ListenParams = {
1063
+ [key: string]: Any
1064
+ }
1065
+
1066
+ /**
1067
+ * @public
1068
+ */
1069
+ declare class LiveClient {
1070
+ #private
1071
+ constructor(client: SanityClient | ObservableSanityClient)
1072
+ /**
1073
+ * Requires `apiVersion` to be `2021-03-25` or later.
1074
+ */
1075
+ events({
1076
+ includeDrafts,
1077
+ tag: _tag,
1078
+ }?: {
1079
+ includeDrafts?: boolean
1080
+ /**
1081
+ * Optional request tag for the listener. Use to identify the request in logs.
1082
+ *
1083
+ * @defaultValue `undefined`
1084
+ */
1085
+ tag?: string
1086
+ }): Observable<LiveEvent>
1087
+ }
1088
+
1089
+ /** @public */
1090
+ declare type LiveEvent = LiveEventRestart | LiveEventReconnect | LiveEventMessage | LiveEventWelcome
1091
+
1092
+ /** @public */
1093
+ declare interface LiveEventMessage {
1094
+ type: 'message'
1095
+ id: string
1096
+ tags: SyncTag[]
1097
+ }
1098
+
1099
+ /** @public */
1100
+ declare interface LiveEventReconnect {
1101
+ type: 'reconnect'
1102
+ }
1103
+
1104
+ /** @public */
1105
+ declare interface LiveEventRestart {
1106
+ type: 'restart'
1107
+ id: string
1108
+ }
1109
+
1110
+ /** @public */
1111
+ declare interface LiveEventWelcome {
1112
+ type: 'welcome'
1113
+ }
1114
+
1115
+ /** @public */
1116
+ declare type Logger =
1117
+ | typeof console
1118
+ | Partial<
1119
+ Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
1120
+ >
1121
+
1122
+ /**
1123
+ * @alpha
1124
+ */
1125
+ declare type LoginErrorProps = FallbackProps & LoginLayoutProps
1126
+
1127
+ /**
1128
+ * @alpha
1129
+ */
1130
+ declare interface LoginLayoutProps {
1131
+ /** Optional header content rendered at top of card */
1132
+ header?: React.ReactNode
1133
+ /** Optional footer content rendered below card. Defaults to an internal login footer */
1134
+ footer?: React.ReactNode
1135
+ /** Main content rendered in card body */
1136
+ children?: React.ReactNode
1137
+ }
1138
+
1139
+ declare interface ManageFavorite {
1140
+ favorite: () => void
1141
+ unfavorite: () => void
1142
+ isFavorited: boolean
1143
+ isConnected: boolean
1144
+ }
1145
+
1146
+ /**
1147
+ * @public
1148
+ */
1149
+ declare type MessageData = Record<string, unknown> | undefined
1150
+
1151
+ /**
1152
+ * @internal
1153
+ */
1154
+ export declare type MessageHandler<TWindowMessage extends WindowMessage> = (
1155
+ event: TWindowMessage['data'],
1156
+ ) => TWindowMessage['response'] | Promise<TWindowMessage['response']>
1157
+
1158
+ /** @internal */
1159
+ declare interface MultipleActionResult {
1160
+ transactionId: string
1161
+ }
1162
+
1163
+ /** @internal */
1164
+ declare interface MultipleMutationResult {
1165
+ transactionId: string
1166
+ documentIds: string[]
1167
+ results: {
1168
+ id: string
1169
+ operation: MutationOperation
1170
+ }[]
1171
+ }
1172
+
1173
+ /** @public */
1174
+ declare type Mutation<R extends Record<string, Any> = Record<string, Any>> =
1175
+ | {
1176
+ create: SanityDocumentStub<R>
1177
+ }
1178
+ | {
1179
+ createOrReplace: IdentifiedSanityDocumentStub<R>
1180
+ }
1181
+ | {
1182
+ createIfNotExists: IdentifiedSanityDocumentStub<R>
1183
+ }
1184
+ | {
1185
+ delete: MutationSelection
1186
+ }
1187
+ | {
1188
+ patch: PatchMutationOperation
1189
+ }
1190
+
1191
+ /**
1192
+ * A mutation was performed. Note that when updating multiple documents in a transaction,
1193
+ * each document affected will get a separate mutation event.
1194
+ *
1195
+ * @public
1196
+ */
1197
+ declare type MutationEvent_2<R extends Record<string, Any> = Record<string, Any>> = {
1198
+ type: 'mutation'
1199
+ /**
1200
+ * The ID of the document that was affected
1201
+ */
1202
+ documentId: string
1203
+ /**
1204
+ * A unique ID for this event
1205
+ */
1206
+ eventId: string
1207
+ /**
1208
+ * The user ID of the user that performed the mutation
1209
+ */
1210
+ identity: string
1211
+ /**
1212
+ * An array of mutations that were performed. Note that this can differ slightly from the
1213
+ * mutations sent to the server, as the server may perform some mutations automatically.
1214
+ */
1215
+ mutations: Mutation[]
1216
+ /**
1217
+ * The revision ID of the document before the mutation was performed
1218
+ */
1219
+ previousRev?: string
1220
+ /**
1221
+ * The revision ID of the document after the mutation was performed
1222
+ */
1223
+ resultRev?: string
1224
+ /**
1225
+ * The document as it looked after the mutation was performed. This is only included if
1226
+ * the listener was configured with `includeResult: true`.
1227
+ */
1228
+ result?: SanityDocument_2<R>
1229
+ /**
1230
+ * The document as it looked before the mutation was performed. This is only included if
1231
+ * the listener was configured with `includePreviousRevision: true`.
1232
+ */
1233
+ previous?: SanityDocument_2<R> | null
1234
+ /**
1235
+ * The effects of the mutation, if the listener was configured with `effectFormat: 'mendoza'`.
1236
+ * Object with `apply` and `revert` arrays, see {@link https://github.com/sanity-io/mendoza}.
1237
+ */
1238
+ effects?: {
1239
+ apply: unknown[]
1240
+ revert: unknown[]
1241
+ }
1242
+ /**
1243
+ * A timestamp for when the mutation was performed
1244
+ */
1245
+ timestamp: string
1246
+ /**
1247
+ * The transaction ID for the mutation
1248
+ */
1249
+ transactionId: string
1250
+ /**
1251
+ * The type of transition the document went through.
1252
+ *
1253
+ * - `update` means the document was previously part of the subscribed set of documents,
1254
+ * and still is.
1255
+ * - `appear` means the document was not previously part of the subscribed set of documents,
1256
+ * but is now. This can happen both on create or if updating to a state where it now matches
1257
+ * the filter provided to the listener.
1258
+ * - `disappear` means the document was previously part of the subscribed set of documents,
1259
+ * but is no longer. This can happen both on delete or if updating to a state where it no
1260
+ * longer matches the filter provided to the listener.
1261
+ */
1262
+ transition: 'update' | 'appear' | 'disappear'
1263
+ /**
1264
+ * Whether the change that triggered this event is visible to queries (query) or only to
1265
+ * subsequent transactions (transaction). The listener client can specify a preferred visibility
1266
+ * through the `visibility` parameter on the listener, but this is only on a best-effort basis,
1267
+ * and may yet not be accurate.
1268
+ */
1269
+ visibility: 'query' | 'transaction'
1270
+ /**
1271
+ * The total number of events that will be sent for this transaction.
1272
+ * Note that this may differ from the amount of _documents_ affected by the transaction, as this
1273
+ * number only includes the documents that matches the given filter.
1274
+ *
1275
+ * This can be useful if you need to perform changes to all matched documents atomically,
1276
+ * eg you would wait for `transactionTotalEvents` events with the same `transactionId` before
1277
+ * applying the changes locally.
1278
+ */
1279
+ transactionTotalEvents: number
1280
+ /**
1281
+ * The index of this event within the transaction. Note that events may be delivered out of order,
1282
+ * and that the index is zero-based.
1283
+ */
1284
+ transactionCurrentEvent: number
1285
+ }
1286
+
1287
+ /** @internal */
1288
+ declare type MutationOperation = 'create' | 'delete' | 'update' | 'none'
1289
+
1290
+ /** @internal */
1291
+ declare type MutationSelection =
1292
+ | {
1293
+ query: string
1294
+ params?: MutationSelectionQueryParams
1295
+ }
1296
+ | {
1297
+ id: string | string[]
1298
+ }
1299
+
1300
+ /** @internal */
1301
+ declare type MutationSelectionQueryParams = {
1302
+ [key: string]: Any
1303
+ }
1304
+
1305
+ declare interface NavigateToStudioResult {
1306
+ navigateToStudioDocument: () => void
1307
+ isConnected: boolean
1308
+ }
1309
+
1310
+ /** @internal */
1311
+ declare class ObservableAssetsClient {
1312
+ #private
1313
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1314
+ /**
1315
+ * Uploads a file asset to the configured dataset
1316
+ *
1317
+ * @param assetType - Asset type (file)
1318
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1319
+ * @param options - Options to use for the upload
1320
+ */
1321
+ upload(
1322
+ assetType: 'file',
1323
+ body: UploadBody,
1324
+ options?: UploadClientConfig,
1325
+ ): Observable<
1326
+ HttpRequestEvent<{
1327
+ document: SanityAssetDocument
1328
+ }>
1329
+ >
1330
+ /**
1331
+ * Uploads an image asset to the configured dataset
1332
+ *
1333
+ * @param assetType - Asset type (image)
1334
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1335
+ * @param options - Options to use for the upload
1336
+ */
1337
+ upload(
1338
+ assetType: 'image',
1339
+ body: UploadBody,
1340
+ options?: UploadClientConfig,
1341
+ ): Observable<
1342
+ HttpRequestEvent<{
1343
+ document: SanityImageAssetDocument
1344
+ }>
1345
+ >
1346
+ /**
1347
+ * Uploads a file or an image asset to the configured dataset
1348
+ *
1349
+ * @param assetType - Asset type (file/image)
1350
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1351
+ * @param options - Options to use for the upload
1352
+ */
1353
+ upload(
1354
+ assetType: 'file' | 'image',
1355
+ body: UploadBody,
1356
+ options?: UploadClientConfig,
1357
+ ): Observable<
1358
+ HttpRequestEvent<{
1359
+ document: SanityAssetDocument | SanityImageAssetDocument
1360
+ }>
1361
+ >
1362
+ }
1363
+
1364
+ /** @internal */
1365
+ declare class ObservableDatasetsClient {
1366
+ #private
1367
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1368
+ /**
1369
+ * Create a new dataset with the given name
1370
+ *
1371
+ * @param name - Name of the dataset to create
1372
+ * @param options - Options for the dataset
1373
+ */
1374
+ create(
1375
+ name: string,
1376
+ options?: {
1377
+ aclMode?: DatasetAclMode
1378
+ },
1379
+ ): Observable<DatasetResponse>
1380
+ /**
1381
+ * Edit a dataset with the given name
1382
+ *
1383
+ * @param name - Name of the dataset to edit
1384
+ * @param options - New options for the dataset
1385
+ */
1386
+ edit(
1387
+ name: string,
1388
+ options?: {
1389
+ aclMode?: DatasetAclMode
1390
+ },
1391
+ ): Observable<DatasetResponse>
1392
+ /**
1393
+ * Delete a dataset with the given name
1394
+ *
1395
+ * @param name - Name of the dataset to delete
1396
+ */
1397
+ delete(name: string): Observable<{
1398
+ deleted: true
1399
+ }>
1400
+ /**
1401
+ * Fetch a list of datasets for the configured project
1402
+ */
1403
+ list(): Observable<DatasetsResponse>
1404
+ }
1405
+
1406
+ /** @public */
1407
+ declare class ObservablePatch extends BasePatch {
1408
+ #private
1409
+ constructor(
1410
+ selection: PatchSelection,
1411
+ operations?: PatchOperations,
1412
+ client?: ObservableSanityClient,
1413
+ )
1414
+ /**
1415
+ * Clones the patch
1416
+ */
1417
+ clone(): ObservablePatch
1418
+ /**
1419
+ * Commit the patch, returning an observable that produces the first patched document
1420
+ *
1421
+ * @param options - Options for the mutation operation
1422
+ */
1423
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1424
+ options: FirstDocumentMutationOptions,
1425
+ ): Observable<SanityDocument_2<R>>
1426
+ /**
1427
+ * Commit the patch, returning an observable that produces an array of the mutated documents
1428
+ *
1429
+ * @param options - Options for the mutation operation
1430
+ */
1431
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1432
+ options: AllDocumentsMutationOptions,
1433
+ ): Observable<SanityDocument_2<R>[]>
1434
+ /**
1435
+ * Commit the patch, returning an observable that produces a mutation result object
1436
+ *
1437
+ * @param options - Options for the mutation operation
1438
+ */
1439
+ commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
1440
+ /**
1441
+ * Commit the patch, returning an observable that produces a mutation result object
1442
+ *
1443
+ * @param options - Options for the mutation operation
1444
+ */
1445
+ commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
1446
+ /**
1447
+ * Commit the patch, returning an observable that produces the first patched document
1448
+ *
1449
+ * @param options - Options for the mutation operation
1450
+ */
1451
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1452
+ options?: BaseMutationOptions,
1453
+ ): Observable<SanityDocument_2<R>>
1454
+ }
1455
+
1456
+ /** @public */
1457
+ declare type ObservablePatchBuilder = (patch: ObservablePatch) => ObservablePatch
1458
+
1459
+ /** @internal */
1460
+ declare class ObservableProjectsClient {
1461
+ #private
1462
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1463
+ /**
1464
+ * Fetch a list of projects the authenticated user has access to.
1465
+ *
1466
+ * @param options - Options for the list request
1467
+ * @param options.includeMembers - Whether to include members in the response (default: true)
1468
+ */
1469
+ list(options?: {includeMembers?: true}): Observable<SanityProject[]>
1470
+ list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
1471
+ /**
1472
+ * Fetch a project by project ID
1473
+ *
1474
+ * @param projectId - ID of the project to fetch
1475
+ */
1476
+ getById(projectId: string): Observable<SanityProject>
1477
+ }
1478
+
1479
+ /** @public */
1480
+ declare class ObservableSanityClient {
1481
+ #private
1482
+ assets: ObservableAssetsClient
1483
+ datasets: ObservableDatasetsClient
1484
+ live: LiveClient
1485
+ projects: ObservableProjectsClient
1486
+ users: ObservableUsersClient
1487
+ /**
1488
+ * Instance properties
1489
+ */
1490
+ listen: typeof _listen
1491
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
1492
+ /**
1493
+ * Clone the client - returns a new instance
1494
+ */
1495
+ clone(): ObservableSanityClient
1496
+ /**
1497
+ * Returns the current client configuration
1498
+ */
1499
+ config(): InitializedClientConfig
1500
+ /**
1501
+ * Reconfigure the client. Note that this _mutates_ the current client.
1502
+ */
1503
+ config(newConfig?: Partial<ClientConfig>): this
1504
+ /**
1505
+ * Clone the client with a new (partial) configuration.
1506
+ *
1507
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
1508
+ */
1509
+ withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient
1510
+ /**
1511
+ * Perform a GROQ-query against the configured dataset.
1512
+ *
1513
+ * @param query - GROQ-query to perform
1514
+ */
1515
+ fetch<
1516
+ R = Any,
1517
+ Q extends QueryWithoutParams = QueryWithoutParams,
1518
+ const G extends string = string,
1519
+ >(query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>
1520
+ /**
1521
+ * Perform a GROQ-query against the configured dataset.
1522
+ *
1523
+ * @param query - GROQ-query to perform
1524
+ * @param params - Optional query parameters
1525
+ * @param options - Optional request options
1526
+ */
1527
+ fetch<
1528
+ R = Any,
1529
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1530
+ const G extends string = string,
1531
+ >(
1532
+ query: G,
1533
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1534
+ options?: FilteredResponseQueryOptions,
1535
+ ): Observable<ClientReturn<G, R>>
1536
+ /**
1537
+ * Perform a GROQ-query against the configured dataset.
1538
+ *
1539
+ * @param query - GROQ-query to perform
1540
+ * @param params - Optional query parameters
1541
+ * @param options - Request options
1542
+ */
1543
+ fetch<
1544
+ R = Any,
1545
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1546
+ const G extends string = string,
1547
+ >(
1548
+ query: string,
1549
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1550
+ options: UnfilteredResponseQueryOptions,
1551
+ ): Observable<RawQueryResponse<ClientReturn<G, R>>>
1552
+ /**
1553
+ * Perform a GROQ-query against the configured dataset.
1554
+ *
1555
+ * @param query - GROQ-query to perform
1556
+ * @param params - Optional query parameters
1557
+ * @param options - Request options
1558
+ */
1559
+ fetch<
1560
+ R = Any,
1561
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1562
+ const G extends string = string,
1563
+ >(
1564
+ query: G,
1565
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1566
+ options: UnfilteredResponseWithoutQuery,
1567
+ ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
1568
+ /**
1569
+ * Fetch a single document with the given ID.
1570
+ *
1571
+ * @param id - Document ID to fetch
1572
+ * @param options - Request options
1573
+ */
1574
+ getDocument<R extends Record<string, Any> = Record<string, Any>>(
1575
+ id: string,
1576
+ options?: {
1577
+ tag?: string
1578
+ },
1579
+ ): Observable<SanityDocument_2<R> | undefined>
1580
+ /**
1581
+ * Fetch multiple documents in one request.
1582
+ * Should be used sparingly - performing a query is usually a better option.
1583
+ * The order/position of documents is preserved based on the original array of IDs.
1584
+ * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
1585
+ *
1586
+ * @param ids - Document IDs to fetch
1587
+ * @param options - Request options
1588
+ */
1589
+ getDocuments<R extends Record<string, Any> = Record<string, Any>>(
1590
+ ids: string[],
1591
+ options?: {
1592
+ tag?: string
1593
+ },
1594
+ ): Observable<(SanityDocument_2<R> | null)[]>
1595
+ /**
1596
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1597
+ * Returns an observable that resolves to the created document.
1598
+ *
1599
+ * @param document - Document to create
1600
+ * @param options - Mutation options
1601
+ */
1602
+ create<R extends Record<string, Any> = Record<string, Any>>(
1603
+ document: SanityDocumentStub<R>,
1604
+ options: FirstDocumentMutationOptions,
1605
+ ): Observable<SanityDocument_2<R>>
1606
+ /**
1607
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1608
+ * Returns an observable that resolves to an array containing the created document.
1609
+ *
1610
+ * @param document - Document to create
1611
+ * @param options - Mutation options
1612
+ */
1613
+ create<R extends Record<string, Any> = Record<string, Any>>(
1614
+ document: SanityDocumentStub<R>,
1615
+ options: AllDocumentsMutationOptions,
1616
+ ): Observable<SanityDocument_2<R>[]>
1617
+ /**
1618
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1619
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
1620
+ *
1621
+ * @param document - Document to create
1622
+ * @param options - Mutation options
1623
+ */
1624
+ create<R extends Record<string, Any> = Record<string, Any>>(
1625
+ document: SanityDocumentStub<R>,
1626
+ options: FirstDocumentIdMutationOptions,
1627
+ ): Observable<SingleMutationResult>
1628
+ /**
1629
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1630
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
1631
+ *
1632
+ * @param document - Document to create
1633
+ * @param options - Mutation options
1634
+ */
1635
+ create<R extends Record<string, Any> = Record<string, Any>>(
1636
+ document: SanityDocumentStub<R>,
1637
+ options: AllDocumentIdsMutationOptions,
1638
+ ): Observable<MultipleMutationResult>
1639
+ /**
1640
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1641
+ * Returns an observable that resolves to the created document.
1642
+ *
1643
+ * @param document - Document to create
1644
+ * @param options - Mutation options
1645
+ */
1646
+ create<R extends Record<string, Any> = Record<string, Any>>(
1647
+ document: SanityDocumentStub<R>,
1648
+ options?: BaseMutationOptions,
1649
+ ): Observable<SanityDocument_2<R>>
1650
+ /**
1651
+ * Create a document if no document with the same ID already exists.
1652
+ * Returns an observable that resolves to the created document.
1653
+ *
1654
+ * @param document - Document to create
1655
+ * @param options - Mutation options
1656
+ */
1657
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1658
+ document: IdentifiedSanityDocumentStub<R>,
1659
+ options: FirstDocumentMutationOptions,
1660
+ ): Observable<SanityDocument_2<R>>
1661
+ /**
1662
+ * Create a document if no document with the same ID already exists.
1663
+ * Returns an observable that resolves to an array containing the created document.
1664
+ *
1665
+ * @param document - Document to create
1666
+ * @param options - Mutation options
1667
+ */
1668
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1669
+ document: IdentifiedSanityDocumentStub<R>,
1670
+ options: AllDocumentsMutationOptions,
1671
+ ): Observable<SanityDocument_2<R>[]>
1672
+ /**
1673
+ * Create a document if no document with the same ID already exists.
1674
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
1675
+ *
1676
+ * @param document - Document to create
1677
+ * @param options - Mutation options
1678
+ */
1679
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1680
+ document: IdentifiedSanityDocumentStub<R>,
1681
+ options: FirstDocumentIdMutationOptions,
1682
+ ): Observable<SingleMutationResult>
1683
+ /**
1684
+ * Create a document if no document with the same ID already exists.
1685
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
1686
+ *
1687
+ * @param document - Document to create
1688
+ * @param options - Mutation options
1689
+ */
1690
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1691
+ document: IdentifiedSanityDocumentStub<R>,
1692
+ options: AllDocumentIdsMutationOptions,
1693
+ ): Observable<MultipleMutationResult>
1694
+ /**
1695
+ * Create a document if no document with the same ID already exists.
1696
+ * Returns an observable that resolves to the created document.
1697
+ *
1698
+ * @param document - Document to create
1699
+ * @param options - Mutation options
1700
+ */
1701
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1702
+ document: IdentifiedSanityDocumentStub<R>,
1703
+ options?: BaseMutationOptions,
1704
+ ): Observable<SanityDocument_2<R>>
1705
+ /**
1706
+ * Create a document if it does not exist, or replace a document with the same document ID
1707
+ * Returns an observable that resolves to the created document.
1708
+ *
1709
+ * @param document - Document to either create or replace
1710
+ * @param options - Mutation options
1711
+ */
1712
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1713
+ document: IdentifiedSanityDocumentStub<R>,
1714
+ options: FirstDocumentMutationOptions,
1715
+ ): Observable<SanityDocument_2<R>>
1716
+ /**
1717
+ * Create a document if it does not exist, or replace a document with the same document ID
1718
+ * Returns an observable that resolves to an array containing the created document.
1719
+ *
1720
+ * @param document - Document to either create or replace
1721
+ * @param options - Mutation options
1722
+ */
1723
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1724
+ document: IdentifiedSanityDocumentStub<R>,
1725
+ options: AllDocumentsMutationOptions,
1726
+ ): Observable<SanityDocument_2<R>[]>
1727
+ /**
1728
+ * Create a document if it does not exist, or replace a document with the same document ID
1729
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
1730
+ *
1731
+ * @param document - Document to either create or replace
1732
+ * @param options - Mutation options
1733
+ */
1734
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1735
+ document: IdentifiedSanityDocumentStub<R>,
1736
+ options: FirstDocumentIdMutationOptions,
1737
+ ): Observable<SingleMutationResult>
1738
+ /**
1739
+ * Create a document if it does not exist, or replace a document with the same document ID
1740
+ * Returns an observable that resolves to a mutation result object containing the created document ID.
1741
+ *
1742
+ * @param document - Document to either create or replace
1743
+ * @param options - Mutation options
1744
+ */
1745
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1746
+ document: IdentifiedSanityDocumentStub<R>,
1747
+ options: AllDocumentIdsMutationOptions,
1748
+ ): Observable<MultipleMutationResult>
1749
+ /**
1750
+ * Create a document if it does not exist, or replace a document with the same document ID
1751
+ * Returns an observable that resolves to the created document.
1752
+ *
1753
+ * @param document - Document to either create or replace
1754
+ * @param options - Mutation options
1755
+ */
1756
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1757
+ document: IdentifiedSanityDocumentStub<R>,
1758
+ options?: BaseMutationOptions,
1759
+ ): Observable<SanityDocument_2<R>>
1760
+ /**
1761
+ * Deletes a document with the given document ID.
1762
+ * Returns an observable that resolves to the deleted document.
1763
+ *
1764
+ * @param id - Document ID to delete
1765
+ * @param options - Options for the mutation
1766
+ */
1767
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1768
+ id: string,
1769
+ options: FirstDocumentMutationOptions,
1770
+ ): Observable<SanityDocument_2<R>>
1771
+ /**
1772
+ * Deletes a document with the given document ID.
1773
+ * Returns an observable that resolves to an array containing the deleted document.
1774
+ *
1775
+ * @param id - Document ID to delete
1776
+ * @param options - Options for the mutation
1777
+ */
1778
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1779
+ id: string,
1780
+ options: AllDocumentsMutationOptions,
1781
+ ): Observable<SanityDocument_2<R>[]>
1782
+ /**
1783
+ * Deletes a document with the given document ID.
1784
+ * Returns an observable that resolves to a mutation result object containing the deleted document ID.
1785
+ *
1786
+ * @param id - Document ID to delete
1787
+ * @param options - Options for the mutation
1788
+ */
1789
+ delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
1790
+ /**
1791
+ * Deletes a document with the given document ID.
1792
+ * Returns an observable that resolves to a mutation result object containing the deleted document ID.
1793
+ *
1794
+ * @param id - Document ID to delete
1795
+ * @param options - Options for the mutation
1796
+ */
1797
+ delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
1798
+ /**
1799
+ * Deletes a document with the given document ID.
1800
+ * Returns an observable that resolves to the deleted document.
1801
+ *
1802
+ * @param id - Document ID to delete
1803
+ * @param options - Options for the mutation
1804
+ */
1805
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1806
+ id: string,
1807
+ options?: BaseMutationOptions,
1808
+ ): Observable<SanityDocument_2<R>>
1809
+ /**
1810
+ * Deletes one or more documents matching the given query or document ID.
1811
+ * Returns an observable that resolves to first deleted document.
1812
+ *
1813
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1814
+ * @param options - Options for the mutation
1815
+ */
1816
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1817
+ selection: MutationSelection,
1818
+ options: FirstDocumentMutationOptions,
1819
+ ): Observable<SanityDocument_2<R>>
1820
+ /**
1821
+ * Deletes one or more documents matching the given query or document ID.
1822
+ * Returns an observable that resolves to an array containing the deleted documents.
1823
+ *
1824
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1825
+ * @param options - Options for the mutation
1826
+ */
1827
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1828
+ selection: MutationSelection,
1829
+ options: AllDocumentsMutationOptions,
1830
+ ): Observable<SanityDocument_2<R>[]>
1831
+ /**
1832
+ * Deletes one or more documents matching the given query or document ID.
1833
+ * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
1834
+ *
1835
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1836
+ * @param options - Options for the mutation
1837
+ */
1838
+ delete(
1839
+ selection: MutationSelection,
1840
+ options: FirstDocumentIdMutationOptions,
1841
+ ): Observable<SingleMutationResult>
1842
+ /**
1843
+ * Deletes one or more documents matching the given query or document ID.
1844
+ * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
1845
+ *
1846
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1847
+ * @param options - Options for the mutation
1848
+ */
1849
+ delete(
1850
+ selection: MutationSelection,
1851
+ options: AllDocumentIdsMutationOptions,
1852
+ ): Observable<MultipleMutationResult>
1853
+ /**
1854
+ * Deletes one or more documents matching the given query or document ID.
1855
+ * Returns an observable that resolves to first deleted document.
1856
+ *
1857
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1858
+ * @param options - Options for the mutation
1859
+ */
1860
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1861
+ selection: MutationSelection,
1862
+ options?: BaseMutationOptions,
1863
+ ): Observable<SanityDocument_2<R>>
1864
+ /**
1865
+ * Perform mutation operations against the configured dataset
1866
+ * Returns an observable that resolves to the first mutated document.
1867
+ *
1868
+ * @param operations - Mutation operations to execute
1869
+ * @param options - Mutation options
1870
+ */
1871
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1872
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1873
+ options: FirstDocumentMutationOptions,
1874
+ ): Observable<SanityDocument_2<R>>
1875
+ /**
1876
+ * Perform mutation operations against the configured dataset.
1877
+ * Returns an observable that resolves to an array of the mutated documents.
1878
+ *
1879
+ * @param operations - Mutation operations to execute
1880
+ * @param options - Mutation options
1881
+ */
1882
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1883
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1884
+ options: AllDocumentsMutationOptions,
1885
+ ): Observable<SanityDocument_2<R>[]>
1886
+ /**
1887
+ * Perform mutation operations against the configured dataset
1888
+ * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
1889
+ *
1890
+ * @param operations - Mutation operations to execute
1891
+ * @param options - Mutation options
1892
+ */
1893
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1894
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1895
+ options: FirstDocumentIdMutationOptions,
1896
+ ): Observable<SingleMutationResult>
1897
+ /**
1898
+ * Perform mutation operations against the configured dataset
1899
+ * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
1900
+ *
1901
+ * @param operations - Mutation operations to execute
1902
+ * @param options - Mutation options
1903
+ */
1904
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1905
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1906
+ options: AllDocumentIdsMutationOptions,
1907
+ ): Observable<MultipleMutationResult>
1908
+ /**
1909
+ * Perform mutation operations against the configured dataset
1910
+ * Returns an observable that resolves to the first mutated document.
1911
+ *
1912
+ * @param operations - Mutation operations to execute
1913
+ * @param options - Mutation options
1914
+ */
1915
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1916
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1917
+ options?: BaseMutationOptions,
1918
+ ): Observable<SanityDocument_2<R>>
1919
+ /**
1920
+ * Create a new buildable patch of operations to perform
1921
+ *
1922
+ * @param documentId - Document ID to patch
1923
+ * @param operations - Optional object of patch operations to initialize the patch instance with
1924
+ * @returns Patch instance - call `.commit()` to perform the operations defined
1925
+ */
1926
+ patch(documentId: string, operations?: PatchOperations): ObservablePatch
1927
+ /**
1928
+ * Create a new buildable patch of operations to perform
1929
+ *
1930
+ * @param documentIds - Array of document IDs to patch
1931
+ * @param operations - Optional object of patch operations to initialize the patch instance with
1932
+ * @returns Patch instance - call `.commit()` to perform the operations defined
1933
+ */
1934
+ patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
1935
+ /**
1936
+ * Create a new buildable patch of operations to perform
1937
+ *
1938
+ * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
1939
+ * @param operations - Optional object of patch operations to initialize the patch instance with
1940
+ * @returns Patch instance - call `.commit()` to perform the operations defined
1941
+ */
1942
+ patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
1943
+ /**
1944
+ * Create a new transaction of mutations
1945
+ *
1946
+ * @param operations - Optional array of mutation operations to initialize the transaction instance with
1947
+ */
1948
+ transaction<R extends Record<string, Any> = Record<string, Any>>(
1949
+ operations?: Mutation<R>[],
1950
+ ): ObservableTransaction
1951
+ /**
1952
+ * Perform action operations against the configured dataset
1953
+ *
1954
+ * @param operations - Action operation(s) to execute
1955
+ * @param options - Action options
1956
+ */
1957
+ action(
1958
+ operations: Action | Action[],
1959
+ options?: BaseActionOptions,
1960
+ ): Observable<SingleActionResult | MultipleActionResult>
1961
+ /**
1962
+ * Perform an HTTP request against the Sanity API
1963
+ *
1964
+ * @param options - Request options
1965
+ */
1966
+ request<R = Any>(options: RawRequestOptions): Observable<R>
1967
+ /**
1968
+ * Get a Sanity API URL for the URI provided
1969
+ *
1970
+ * @param uri - URI/path to build URL for
1971
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
1972
+ */
1973
+ getUrl(uri: string, canUseCdn?: boolean): string
1974
+ /**
1975
+ * Get a Sanity API URL for the data operation and path provided
1976
+ *
1977
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
1978
+ * @param path - Path to append after the operation
1979
+ */
1980
+ getDataUrl(operation: string, path?: string): string
1981
+ }
1982
+
1983
+ /** @public */
1984
+ declare class ObservableTransaction extends BaseTransaction {
1985
+ #private
1986
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
1987
+ /**
1988
+ * Clones the transaction
1989
+ */
1990
+ clone(): ObservableTransaction
1991
+ /**
1992
+ * Commit the transaction, returning an observable that produces the first mutated document
1993
+ *
1994
+ * @param options - Options for the mutation operation
1995
+ */
1996
+ commit<R extends Record<string, Any>>(
1997
+ options: TransactionFirstDocumentMutationOptions,
1998
+ ): Observable<SanityDocument_2<R>>
1999
+ /**
2000
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
2001
+ *
2002
+ * @param options - Options for the mutation operation
2003
+ */
2004
+ commit<R extends Record<string, Any>>(
2005
+ options: TransactionAllDocumentsMutationOptions,
2006
+ ): Observable<SanityDocument_2<R>[]>
2007
+ /**
2008
+ * Commit the transaction, returning an observable that produces a mutation result object
2009
+ *
2010
+ * @param options - Options for the mutation operation
2011
+ */
2012
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2013
+ /**
2014
+ * Commit the transaction, returning an observable that produces a mutation result object
2015
+ *
2016
+ * @param options - Options for the mutation operation
2017
+ */
2018
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2019
+ /**
2020
+ * Commit the transaction, returning an observable that produces a mutation result object
2021
+ *
2022
+ * @param options - Options for the mutation operation
2023
+ */
2024
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2025
+ /**
2026
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2027
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2028
+ *
2029
+ * @param documentId - Document ID to perform the patch operation on
2030
+ * @param patchOps - Operations to perform, or a builder function
2031
+ */
2032
+ patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2033
+ /**
2034
+ * Adds the given patch instance to the transaction.
2035
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2036
+ *
2037
+ * @param patch - ObservablePatch to execute
2038
+ */
2039
+ patch(patch: ObservablePatch): this
2040
+ }
2041
+
2042
+ /** @public */
2043
+ declare class ObservableUsersClient {
2044
+ #private
2045
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2046
+ /**
2047
+ * Fetch a user by user ID
2048
+ *
2049
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2050
+ */
2051
+ getById<T extends 'me' | string>(
2052
+ id: T,
2053
+ ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2054
+ }
2055
+
2056
+ /**
2057
+ * The listener connection has been established
2058
+ * note: it's usually a better option to use the 'welcome' event
2059
+ * @public
2060
+ */
2061
+ declare type OpenEvent = {
2062
+ type: 'open'
2063
+ }
2064
+
2065
+ /**
2066
+ * Return value from the usePaginatedList hook
2067
+ *
2068
+ * @beta
2069
+ * @category Types
2070
+ */
2071
+ export declare interface PaginatedList {
2072
+ /**
2073
+ * Array of document handles for the current page
2074
+ */
2075
+ data: DocumentHandle[]
2076
+ /**
2077
+ * Whether a query is currently in progress
2078
+ */
2079
+ isPending: boolean
2080
+ /**
2081
+ * Number of items displayed per page
2082
+ */
2083
+ pageSize: number
2084
+ /**
2085
+ * Current page number (1-indexed)
2086
+ */
2087
+ currentPage: number
2088
+ /**
2089
+ * Total number of pages available
2090
+ */
2091
+ totalPages: number
2092
+ /**
2093
+ * Starting index of the current page (0-indexed)
2094
+ */
2095
+ startIndex: number
2096
+ /**
2097
+ * Ending index of the current page (exclusive, 0-indexed)
2098
+ */
2099
+ endIndex: number
2100
+ /**
2101
+ * Total count of items matching the query
2102
+ */
2103
+ count: number
2104
+ /**
2105
+ * Navigate to the first page
2106
+ */
2107
+ firstPage: () => void
2108
+ /**
2109
+ * Whether there is a first page available to navigate to
2110
+ */
2111
+ hasFirstPage: boolean
2112
+ /**
2113
+ * Navigate to the previous page
2114
+ */
2115
+ previousPage: () => void
2116
+ /**
2117
+ * Whether there is a previous page available to navigate to
2118
+ */
2119
+ hasPreviousPage: boolean
2120
+ /**
2121
+ * Navigate to the next page
2122
+ */
2123
+ nextPage: () => void
2124
+ /**
2125
+ * Whether there is a next page available to navigate to
2126
+ */
2127
+ hasNextPage: boolean
2128
+ /**
2129
+ * Navigate to the last page
2130
+ */
2131
+ lastPage: () => void
2132
+ /**
2133
+ * Whether there is a last page available to navigate to
2134
+ */
2135
+ hasLastPage: boolean
2136
+ /**
2137
+ * Navigate to a specific page number
2138
+ * @param pageNumber - The page number to navigate to (1-indexed)
2139
+ */
2140
+ goToPage: (pageNumber: number) => void
2141
+ }
2142
+
2143
+ /**
2144
+ * Configuration options for the usePaginatedList hook
2145
+ *
2146
+ * @beta
2147
+ * @category Types
2148
+ */
2149
+ export declare interface PaginatedListOptions extends QueryOptions {
2150
+ /**
2151
+ * GROQ filter expression to apply to the query
2152
+ */
2153
+ filter?: string
2154
+ /**
2155
+ * Number of items to display per page (defaults to 25)
2156
+ */
2157
+ pageSize?: number
2158
+ /**
2159
+ * Sorting configuration for the results
2160
+ */
2161
+ orderings?: SortOrderingItem[]
2162
+ /**
2163
+ * Text search query to filter results
2164
+ */
2165
+ search?: string
2166
+ }
2167
+
2168
+ /** @public */
2169
+ declare class Patch extends BasePatch {
2170
+ #private
2171
+ constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2172
+ /**
2173
+ * Clones the patch
2174
+ */
2175
+ clone(): Patch
2176
+ /**
2177
+ * Commit the patch, returning a promise that resolves to the first patched document
2178
+ *
2179
+ * @param options - Options for the mutation operation
2180
+ */
2181
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2182
+ options: FirstDocumentMutationOptions,
2183
+ ): Promise<SanityDocument_2<R>>
2184
+ /**
2185
+ * Commit the patch, returning a promise that resolves to an array of the mutated documents
2186
+ *
2187
+ * @param options - Options for the mutation operation
2188
+ */
2189
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2190
+ options: AllDocumentsMutationOptions,
2191
+ ): Promise<SanityDocument_2<R>[]>
2192
+ /**
2193
+ * Commit the patch, returning a promise that resolves to a mutation result object
2194
+ *
2195
+ * @param options - Options for the mutation operation
2196
+ */
2197
+ commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2198
+ /**
2199
+ * Commit the patch, returning a promise that resolves to a mutation result object
2200
+ *
2201
+ * @param options - Options for the mutation operation
2202
+ */
2203
+ commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2204
+ /**
2205
+ * Commit the patch, returning a promise that resolves to the first patched document
2206
+ *
2207
+ * @param options - Options for the mutation operation
2208
+ */
2209
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2210
+ options?: BaseMutationOptions,
2211
+ ): Promise<SanityDocument_2<R>>
2212
+ }
2213
+
2214
+ /** @public */
2215
+ declare type PatchBuilder = (patch: Patch) => Patch
2216
+
2217
+ /** @internal */
2218
+ declare type PatchMutationOperation = PatchOperations & MutationSelection
2219
+
2220
+ /** @internal */
2221
+ declare interface PatchOperations {
2222
+ set?: {
2223
+ [key: string]: Any
2224
+ }
2225
+ setIfMissing?: {
2226
+ [key: string]: Any
2227
+ }
2228
+ diffMatchPatch?: {
2229
+ [key: string]: Any
2230
+ }
2231
+ unset?: string[]
2232
+ inc?: {
2233
+ [key: string]: number
2234
+ }
2235
+ dec?: {
2236
+ [key: string]: number
2237
+ }
2238
+ insert?: InsertPatch
2239
+ ifRevisionID?: string
2240
+ }
2241
+
2242
+ /** @internal */
2243
+ declare type PatchSelection = string | string[] | MutationSelection
2244
+
2245
+ /** @public */
2246
+ declare interface ProgressEvent_2 {
2247
+ type: 'progress'
2248
+ stage: 'upload' | 'download'
2249
+ percent: number
2250
+ total?: number
2251
+ loaded?: number
2252
+ lengthComputable: boolean
2253
+ }
2254
+
2255
+ /** @internal */
2256
+ declare class ProjectsClient {
2257
+ #private
2258
+ constructor(client: SanityClient, httpRequest: HttpRequest)
2259
+ /**
2260
+ * Fetch a list of projects the authenticated user has access to.
2261
+ *
2262
+ * @param options - Options for the list request
2263
+ * @param options.includeMembers - Whether to include members in the response (default: true)
2264
+ */
2265
+ list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2266
+ list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
2267
+ /**
2268
+ * Fetch a project by project ID
2269
+ *
2270
+ * @param projectId - ID of the project to fetch
2271
+ */
2272
+ getById(projectId: string): Promise<SanityProject>
2273
+ }
2274
+
2275
+ /**
2276
+ * @public
2277
+ * @category Types
2278
+ */
2279
+ export declare type ProjectWithoutMembers = Omit<SanityProject, 'members'>
2280
+
2281
+ /**
2282
+ * Publishes a draft document.
2283
+ * If a published version of the document already exists this is replaced by the current draft document.
2284
+ * In either case the draft document is deleted.
2285
+ * The optional revision id parameters can be used for optimistic locking to ensure
2286
+ * that the draft and/or published versions of the document have not been changed by another client.
2287
+ *
2288
+ * @public
2289
+ */
2290
+ declare type PublishAction = {
2291
+ actionType: 'sanity.action.document.publish'
2292
+ /**
2293
+ * Draft document ID to publish
2294
+ */
2295
+ draftId: string
2296
+ /**
2297
+ * Draft revision ID to match
2298
+ */
2299
+ ifDraftRevisionId?: string
2300
+ /**
2301
+ * Published document ID to replace
2302
+ */
2303
+ publishedId: string
2304
+ /**
2305
+ * Published revision ID to match
2306
+ */
2307
+ ifPublishedRevisionId?: string
2308
+ }
2309
+
2310
+ /** @public */
2311
+ declare interface QueryParams {
2312
+ [key: string]: any
2313
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2314
+ body?: never
2315
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2316
+ cache?: 'next' extends keyof RequestInit ? never : any
2317
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2318
+ filterResponse?: never
2319
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2320
+ headers?: never
2321
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2322
+ method?: never
2323
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2324
+ next?: 'next' extends keyof RequestInit ? never : any
2325
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2326
+ perspective?: never
2327
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2328
+ query?: never
2329
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2330
+ resultSourceMap?: never
2331
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2332
+ returnQuery?: never
2333
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2334
+ signal?: never
2335
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2336
+ stega?: never
2337
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2338
+ tag?: never
2339
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2340
+ timeout?: never
2341
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2342
+ token?: never
2343
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2344
+ useCdn?: never
2345
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2346
+ lastLiveEventId?: never
2347
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2348
+ cacheMode?: never
2349
+ }
2350
+
2351
+ /**
2352
+ * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
2353
+ * @public
2354
+ */
2355
+ declare type QueryWithoutParams = Record<string, never> | undefined
2356
+
2357
+ /** @public */
2358
+ declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
2359
+
2360
+ /** @public */
2361
+ declare interface RawQueryResponse<R> {
2362
+ query: string
2363
+ ms: number
2364
+ result: R
2365
+ resultSourceMap?: ContentSourceMap
2366
+ /** Requires `apiVersion` to be `2021-03-25` or later. */
2367
+ syncTags?: SyncTag[]
2368
+ }
2369
+
2370
+ /** @internal */
2371
+ declare interface RawRequestOptions {
2372
+ url?: string
2373
+ uri?: string
2374
+ method?: string
2375
+ token?: string
2376
+ json?: boolean
2377
+ tag?: string
2378
+ useGlobalApi?: boolean
2379
+ withCredentials?: boolean
2380
+ query?: {
2381
+ [key: string]: string | string[]
2382
+ }
2383
+ headers?: {
2384
+ [key: string]: string
2385
+ }
2386
+ timeout?: number
2387
+ proxy?: string
2388
+ body?: Any
2389
+ maxRedirects?: number
2390
+ signal?: AbortSignal
2391
+ }
2392
+
2393
+ /**
2394
+ * This version is provided by pkg-utils at build time
2395
+ * @internal
2396
+ */
2397
+ export declare const REACT_SDK_VERSION: {}
2398
+
2399
+ /**
2400
+ * The listener has been disconnected, and a reconnect attempt is scheduled.
2401
+ *
2402
+ * @public
2403
+ */
2404
+ declare type ReconnectEvent = {
2405
+ type: 'reconnect'
2406
+ }
2407
+
2408
+ /**
2409
+ * Replaces an existing draft document.
2410
+ * At least one of the draft or published versions of the document must exist.
2411
+ *
2412
+ * @public
2413
+ */
2414
+ declare type ReplaceDraftAction = {
2415
+ actionType: 'sanity.action.document.replaceDraft'
2416
+ /**
2417
+ * Published document ID to create draft from, if draft does not exist
2418
+ */
2419
+ publishedId: string
2420
+ /**
2421
+ * Document to create if it does not already exist. Requires `_id` and `_type` properties.
2422
+ */
2423
+ attributes: IdentifiedSanityDocumentStub
2424
+ }
2425
+
2426
+ /** @public */
2427
+ declare interface RequestOptions {
2428
+ timeout?: number
2429
+ token?: string
2430
+ tag?: string
2431
+ headers?: Record<string, string>
2432
+ method?: string
2433
+ query?: Any
2434
+ body?: Any
2435
+ signal?: AbortSignal
2436
+ }
2437
+
2438
+ /** @alpha */
2439
+ declare type ResolveStudioUrl = (sourceDocument: ContentSourceMapDocuments[number]) => StudioUrl
2440
+
2441
+ /** @public */
2442
+ declare interface ResponseEvent<T = unknown> {
2443
+ type: 'response'
2444
+ body: T
2445
+ url: string
2446
+ method: string
2447
+ statusCode: number
2448
+ statusMessage?: string
2449
+ headers: Record<string, string>
2450
+ }
2451
+
2452
+ /** @public */
2453
+ declare interface ResponseQueryOptions extends RequestOptions {
2454
+ perspective?: ClientPerspective
2455
+ resultSourceMap?: boolean | 'withKeyArraySelector'
2456
+ returnQuery?: boolean
2457
+ useCdn?: boolean
2458
+ stega?: boolean | StegaConfig
2459
+ cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
2460
+ next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
2461
+ lastLiveEventId?: string | string[] | null
2462
+ /**
2463
+ * When set to `noStale`, APICDN will not return a cached response if the content is stale.
2464
+ * Tradeoff between latency and freshness of content.
2465
+ *
2466
+ * Only to be used with live content queries and when useCdn is true.
2467
+ */
2468
+ cacheMode?: 'noStale'
2469
+ }
2470
+
2471
+ /**
2472
+ * @public
2473
+ *
2474
+ * The SanityApp component provides your Sanity application with access to your Sanity configuration,
2475
+ * as well as application context and state which is used by the Sanity React hooks. Your application
2476
+ * must be wrapped with the SanityApp component to function properly.
2477
+ *
2478
+ * @param props - Your Sanity configuration and the React children to render
2479
+ * @returns Your Sanity application, integrated with your Sanity configuration and application context
2480
+ *
2481
+ * @example
2482
+ * ```tsx
2483
+ * import { SanityApp } from '@sanity/sdk-react'
2484
+ *
2485
+ * import MyAppRoot from './Root'
2486
+ *
2487
+ * // Single project configuration
2488
+ * const mySanityConfigs = [
2489
+ * {
2490
+ * projectId: 'my-project-id',
2491
+ * dataset: 'production',
2492
+ * },
2493
+ * ]
2494
+ *
2495
+ * // Or multiple project configurations
2496
+ * const multipleConfigs = [
2497
+ * // Configuration for your main project. This will be used as the default project for all hooks if no resource ID override is provided.
2498
+ * {
2499
+ * projectId: 'marketing-website-project',
2500
+ * dataset: 'production',
2501
+ * },
2502
+ * // Configuration for a separate blog project
2503
+ * {
2504
+ * projectId: 'blog-project',
2505
+ * dataset: 'production',
2506
+ * },
2507
+ * // Configuration for a separate ecommerce project
2508
+ * {
2509
+ * projectId: 'ecommerce-project',
2510
+ * dataset: 'production',
2511
+ * }
2512
+ * ]
2513
+ *
2514
+ * export default function MyApp() {
2515
+ * return (
2516
+ * <SanityApp sanityConfigs={mySanityConfigs}>
2517
+ * <MyAppRoot />
2518
+ * </SanityApp>
2519
+ * )
2520
+ * }
2521
+ * ```
2522
+ */
2523
+ export declare function SanityApp({sanityConfigs, children, fallback}: SanityAppProps): ReactElement
2524
+
2525
+ /**
2526
+ * @public
2527
+ */
2528
+ export declare interface SanityAppProps {
2529
+ sanityConfigs: SanityConfig[]
2530
+ children: React.ReactNode
2531
+ fallback: React.ReactNode
2532
+ }
2533
+
2534
+ /** @internal */
2535
+ declare interface SanityAssetDocument extends SanityDocument_2 {
2536
+ url: string
2537
+ path: string
2538
+ size: number
2539
+ assetId: string
2540
+ mimeType: string
2541
+ sha1hash: string
2542
+ extension: string
2543
+ uploadId?: string
2544
+ originalFilename?: string
2545
+ }
2546
+
2547
+ /** @public */
2548
+ declare class SanityClient {
2549
+ #private
2550
+ assets: AssetsClient
2551
+ datasets: DatasetsClient
2552
+ live: LiveClient
2553
+ projects: ProjectsClient
2554
+ users: UsersClient
2555
+ /**
2556
+ * Observable version of the Sanity client, with the same configuration as the promise-based one
2557
+ */
2558
+ observable: ObservableSanityClient
2559
+ /**
2560
+ * Instance properties
2561
+ */
2562
+ listen: typeof _listen
2563
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
2564
+ /**
2565
+ * Clone the client - returns a new instance
2566
+ */
2567
+ clone(): SanityClient
2568
+ /**
2569
+ * Returns the current client configuration
2570
+ */
2571
+ config(): InitializedClientConfig
2572
+ /**
2573
+ * Reconfigure the client. Note that this _mutates_ the current client.
2574
+ */
2575
+ config(newConfig?: Partial<ClientConfig>): this
2576
+ /**
2577
+ * Clone the client with a new (partial) configuration.
2578
+ *
2579
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
2580
+ */
2581
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClient
2582
+ /**
2583
+ * Perform a GROQ-query against the configured dataset.
2584
+ *
2585
+ * @param query - GROQ-query to perform
2586
+ */
2587
+ fetch<
2588
+ R = Any,
2589
+ Q extends QueryWithoutParams = QueryWithoutParams,
2590
+ const G extends string = string,
2591
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
2592
+ /**
2593
+ * Perform a GROQ-query against the configured dataset.
2594
+ *
2595
+ * @param query - GROQ-query to perform
2596
+ * @param params - Optional query parameters
2597
+ * @param options - Optional request options
2598
+ */
2599
+ fetch<
2600
+ R = Any,
2601
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2602
+ const G extends string = string,
2603
+ >(
2604
+ query: G,
2605
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2606
+ options?: FilteredResponseQueryOptions,
2607
+ ): Promise<ClientReturn<G, R>>
2608
+ /**
2609
+ * Perform a GROQ-query against the configured dataset.
2610
+ *
2611
+ * @param query - GROQ-query to perform
2612
+ * @param params - Optional query parameters
2613
+ * @param options - Request options
2614
+ */
2615
+ fetch<
2616
+ R = Any,
2617
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2618
+ const G extends string = string,
2619
+ >(
2620
+ query: G,
2621
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2622
+ options: UnfilteredResponseQueryOptions,
2623
+ ): Promise<RawQueryResponse<ClientReturn<G, R>>>
2624
+ /**
2625
+ * Perform a GROQ-query against the configured dataset.
2626
+ *
2627
+ * @param query - GROQ-query to perform
2628
+ * @param params - Optional query parameters
2629
+ * @param options - Request options
2630
+ */
2631
+ fetch<
2632
+ R = Any,
2633
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2634
+ const G extends string = string,
2635
+ >(
2636
+ query: G,
2637
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2638
+ options: UnfilteredResponseWithoutQuery,
2639
+ ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
2640
+ /**
2641
+ * Fetch a single document with the given ID.
2642
+ *
2643
+ * @param id - Document ID to fetch
2644
+ * @param options - Request options
2645
+ */
2646
+ getDocument<R extends Record<string, Any> = Record<string, Any>>(
2647
+ id: string,
2648
+ options?: {
2649
+ signal?: AbortSignal
2650
+ tag?: string
2651
+ },
2652
+ ): Promise<SanityDocument_2<R> | undefined>
2653
+ /**
2654
+ * Fetch multiple documents in one request.
2655
+ * Should be used sparingly - performing a query is usually a better option.
2656
+ * The order/position of documents is preserved based on the original array of IDs.
2657
+ * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
2658
+ *
2659
+ * @param ids - Document IDs to fetch
2660
+ * @param options - Request options
2661
+ */
2662
+ getDocuments<R extends Record<string, Any> = Record<string, Any>>(
2663
+ ids: string[],
2664
+ options?: {
2665
+ signal?: AbortSignal
2666
+ tag?: string
2667
+ },
2668
+ ): Promise<(SanityDocument_2<R> | null)[]>
2669
+ /**
2670
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2671
+ * Returns a promise that resolves to the created document.
2672
+ *
2673
+ * @param document - Document to create
2674
+ * @param options - Mutation options
2675
+ */
2676
+ create<R extends Record<string, Any> = Record<string, Any>>(
2677
+ document: SanityDocumentStub<R>,
2678
+ options: FirstDocumentMutationOptions,
2679
+ ): Promise<SanityDocument_2<R>>
2680
+ /**
2681
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2682
+ * Returns a promise that resolves to an array containing the created document.
2683
+ *
2684
+ * @param document - Document to create
2685
+ * @param options - Mutation options
2686
+ */
2687
+ create<R extends Record<string, Any> = Record<string, Any>>(
2688
+ document: SanityDocumentStub<R>,
2689
+ options: AllDocumentsMutationOptions,
2690
+ ): Promise<SanityDocument_2<R>[]>
2691
+ /**
2692
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2693
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
2694
+ *
2695
+ * @param document - Document to create
2696
+ * @param options - Mutation options
2697
+ */
2698
+ create<R extends Record<string, Any> = Record<string, Any>>(
2699
+ document: SanityDocumentStub<R>,
2700
+ options: FirstDocumentIdMutationOptions,
2701
+ ): Promise<SingleMutationResult>
2702
+ /**
2703
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2704
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
2705
+ *
2706
+ * @param document - Document to create
2707
+ * @param options - Mutation options
2708
+ */
2709
+ create<R extends Record<string, Any> = Record<string, Any>>(
2710
+ document: SanityDocumentStub<R>,
2711
+ options: AllDocumentIdsMutationOptions,
2712
+ ): Promise<MultipleMutationResult>
2713
+ /**
2714
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2715
+ * Returns a promise that resolves to the created document.
2716
+ *
2717
+ * @param document - Document to create
2718
+ * @param options - Mutation options
2719
+ */
2720
+ create<R extends Record<string, Any> = Record<string, Any>>(
2721
+ document: SanityDocumentStub<R>,
2722
+ options?: BaseMutationOptions,
2723
+ ): Promise<SanityDocument_2<R>>
2724
+ /**
2725
+ * Create a document if no document with the same ID already exists.
2726
+ * Returns a promise that resolves to the created document.
2727
+ *
2728
+ * @param document - Document to create
2729
+ * @param options - Mutation options
2730
+ */
2731
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2732
+ document: IdentifiedSanityDocumentStub<R>,
2733
+ options: FirstDocumentMutationOptions,
2734
+ ): Promise<SanityDocument_2<R>>
2735
+ /**
2736
+ * Create a document if no document with the same ID already exists.
2737
+ * Returns a promise that resolves to an array containing the created document.
2738
+ *
2739
+ * @param document - Document to create
2740
+ * @param options - Mutation options
2741
+ */
2742
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2743
+ document: IdentifiedSanityDocumentStub<R>,
2744
+ options: AllDocumentsMutationOptions,
2745
+ ): Promise<SanityDocument_2<R>[]>
2746
+ /**
2747
+ * Create a document if no document with the same ID already exists.
2748
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
2749
+ *
2750
+ * @param document - Document to create
2751
+ * @param options - Mutation options
2752
+ */
2753
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2754
+ document: IdentifiedSanityDocumentStub<R>,
2755
+ options: FirstDocumentIdMutationOptions,
2756
+ ): Promise<SingleMutationResult>
2757
+ /**
2758
+ * Create a document if no document with the same ID already exists.
2759
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
2760
+ *
2761
+ * @param document - Document to create
2762
+ * @param options - Mutation options
2763
+ */
2764
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2765
+ document: IdentifiedSanityDocumentStub<R>,
2766
+ options: AllDocumentIdsMutationOptions,
2767
+ ): Promise<MultipleMutationResult>
2768
+ /**
2769
+ * Create a document if no document with the same ID already exists.
2770
+ * Returns a promise that resolves to the created document.
2771
+ *
2772
+ * @param document - Document to create
2773
+ * @param options - Mutation options
2774
+ */
2775
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2776
+ document: IdentifiedSanityDocumentStub<R>,
2777
+ options?: BaseMutationOptions,
2778
+ ): Promise<SanityDocument_2<R>>
2779
+ /**
2780
+ * Create a document if it does not exist, or replace a document with the same document ID
2781
+ * Returns a promise that resolves to the created document.
2782
+ *
2783
+ * @param document - Document to either create or replace
2784
+ * @param options - Mutation options
2785
+ */
2786
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2787
+ document: IdentifiedSanityDocumentStub<R>,
2788
+ options: FirstDocumentMutationOptions,
2789
+ ): Promise<SanityDocument_2<R>>
2790
+ /**
2791
+ * Create a document if it does not exist, or replace a document with the same document ID
2792
+ * Returns a promise that resolves to an array containing the created document.
2793
+ *
2794
+ * @param document - Document to either create or replace
2795
+ * @param options - Mutation options
2796
+ */
2797
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2798
+ document: IdentifiedSanityDocumentStub<R>,
2799
+ options: AllDocumentsMutationOptions,
2800
+ ): Promise<SanityDocument_2<R>[]>
2801
+ /**
2802
+ * Create a document if it does not exist, or replace a document with the same document ID
2803
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
2804
+ *
2805
+ * @param document - Document to either create or replace
2806
+ * @param options - Mutation options
2807
+ */
2808
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2809
+ document: IdentifiedSanityDocumentStub<R>,
2810
+ options: FirstDocumentIdMutationOptions,
2811
+ ): Promise<SingleMutationResult>
2812
+ /**
2813
+ * Create a document if it does not exist, or replace a document with the same document ID
2814
+ * Returns a promise that resolves to a mutation result object containing the created document ID.
2815
+ *
2816
+ * @param document - Document to either create or replace
2817
+ * @param options - Mutation options
2818
+ */
2819
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2820
+ document: IdentifiedSanityDocumentStub<R>,
2821
+ options: AllDocumentIdsMutationOptions,
2822
+ ): Promise<MultipleMutationResult>
2823
+ /**
2824
+ * Create a document if it does not exist, or replace a document with the same document ID
2825
+ * Returns a promise that resolves to the created document.
2826
+ *
2827
+ * @param document - Document to either create or replace
2828
+ * @param options - Mutation options
2829
+ */
2830
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2831
+ document: IdentifiedSanityDocumentStub<R>,
2832
+ options?: BaseMutationOptions,
2833
+ ): Promise<SanityDocument_2<R>>
2834
+ /**
2835
+ * Deletes a document with the given document ID.
2836
+ * Returns a promise that resolves to the deleted document.
2837
+ *
2838
+ * @param id - Document ID to delete
2839
+ * @param options - Options for the mutation
2840
+ */
2841
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2842
+ id: string,
2843
+ options: FirstDocumentMutationOptions,
2844
+ ): Promise<SanityDocument_2<R>>
2845
+ /**
2846
+ * Deletes a document with the given document ID.
2847
+ * Returns a promise that resolves to an array containing the deleted document.
2848
+ *
2849
+ * @param id - Document ID to delete
2850
+ * @param options - Options for the mutation
2851
+ */
2852
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2853
+ id: string,
2854
+ options: AllDocumentsMutationOptions,
2855
+ ): Promise<SanityDocument_2<R>[]>
2856
+ /**
2857
+ * Deletes a document with the given document ID.
2858
+ * Returns a promise that resolves to a mutation result object containing the deleted document ID.
2859
+ *
2860
+ * @param id - Document ID to delete
2861
+ * @param options - Options for the mutation
2862
+ */
2863
+ delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2864
+ /**
2865
+ * Deletes a document with the given document ID.
2866
+ * Returns a promise that resolves to a mutation result object containing the deleted document ID.
2867
+ *
2868
+ * @param id - Document ID to delete
2869
+ * @param options - Options for the mutation
2870
+ */
2871
+ delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2872
+ /**
2873
+ * Deletes a document with the given document ID.
2874
+ * Returns a promise that resolves to the deleted document.
2875
+ *
2876
+ * @param id - Document ID to delete
2877
+ * @param options - Options for the mutation
2878
+ */
2879
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2880
+ id: string,
2881
+ options?: BaseMutationOptions,
2882
+ ): Promise<SanityDocument_2<R>>
2883
+ /**
2884
+ * Deletes one or more documents matching the given query or document ID.
2885
+ * Returns a promise that resolves to first deleted document.
2886
+ *
2887
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2888
+ * @param options - Options for the mutation
2889
+ */
2890
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2891
+ selection: MutationSelection,
2892
+ options: FirstDocumentMutationOptions,
2893
+ ): Promise<SanityDocument_2<R>>
2894
+ /**
2895
+ * Deletes one or more documents matching the given query or document ID.
2896
+ * Returns a promise that resolves to an array containing the deleted documents.
2897
+ *
2898
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2899
+ * @param options - Options for the mutation
2900
+ */
2901
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2902
+ selection: MutationSelection,
2903
+ options: AllDocumentsMutationOptions,
2904
+ ): Promise<SanityDocument_2<R>[]>
2905
+ /**
2906
+ * Deletes one or more documents matching the given query or document ID.
2907
+ * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
2908
+ *
2909
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2910
+ * @param options - Options for the mutation
2911
+ */
2912
+ delete(
2913
+ selection: MutationSelection,
2914
+ options: FirstDocumentIdMutationOptions,
2915
+ ): Promise<SingleMutationResult>
2916
+ /**
2917
+ * Deletes one or more documents matching the given query or document ID.
2918
+ * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
2919
+ *
2920
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2921
+ * @param options - Options for the mutation
2922
+ */
2923
+ delete(
2924
+ selection: MutationSelection,
2925
+ options: AllDocumentIdsMutationOptions,
2926
+ ): Promise<MultipleMutationResult>
2927
+ /**
2928
+ * Deletes one or more documents matching the given query or document ID.
2929
+ * Returns a promise that resolves to first deleted document.
2930
+ *
2931
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2932
+ * @param options - Options for the mutation
2933
+ */
2934
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2935
+ selection: MutationSelection,
2936
+ options?: BaseMutationOptions,
2937
+ ): Promise<SanityDocument_2<R>>
2938
+ /**
2939
+ * Perform mutation operations against the configured dataset
2940
+ * Returns a promise that resolves to the first mutated document.
2941
+ *
2942
+ * @param operations - Mutation operations to execute
2943
+ * @param options - Mutation options
2944
+ */
2945
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2946
+ operations: Mutation<R>[] | Patch | Transaction,
2947
+ options: FirstDocumentMutationOptions,
2948
+ ): Promise<SanityDocument_2<R>>
2949
+ /**
2950
+ * Perform mutation operations against the configured dataset.
2951
+ * Returns a promise that resolves to an array of the mutated documents.
2952
+ *
2953
+ * @param operations - Mutation operations to execute
2954
+ * @param options - Mutation options
2955
+ */
2956
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2957
+ operations: Mutation<R>[] | Patch | Transaction,
2958
+ options: AllDocumentsMutationOptions,
2959
+ ): Promise<SanityDocument_2<R>[]>
2960
+ /**
2961
+ * Perform mutation operations against the configured dataset
2962
+ * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
2963
+ *
2964
+ * @param operations - Mutation operations to execute
2965
+ * @param options - Mutation options
2966
+ */
2967
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2968
+ operations: Mutation<R>[] | Patch | Transaction,
2969
+ options: FirstDocumentIdMutationOptions,
2970
+ ): Promise<SingleMutationResult>
2971
+ /**
2972
+ * Perform mutation operations against the configured dataset
2973
+ * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
2974
+ *
2975
+ * @param operations - Mutation operations to execute
2976
+ * @param options - Mutation options
2977
+ */
2978
+ mutate<R extends Record<string, Any>>(
2979
+ operations: Mutation<R>[] | Patch | Transaction,
2980
+ options: AllDocumentIdsMutationOptions,
2981
+ ): Promise<MultipleMutationResult>
2982
+ /**
2983
+ * Perform mutation operations against the configured dataset
2984
+ * Returns a promise that resolves to the first mutated document.
2985
+ *
2986
+ * @param operations - Mutation operations to execute
2987
+ * @param options - Mutation options
2988
+ */
2989
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2990
+ operations: Mutation<R>[] | Patch | Transaction,
2991
+ options?: BaseMutationOptions,
2992
+ ): Promise<SanityDocument_2<R>>
2993
+ /**
2994
+ * Create a new buildable patch of operations to perform
2995
+ *
2996
+ * @param documentId - Document ID to patch
2997
+ * @param operations - Optional object of patch operations to initialize the patch instance with
2998
+ * @returns Patch instance - call `.commit()` to perform the operations defined
2999
+ */
3000
+ patch(documentId: string, operations?: PatchOperations): Patch
3001
+ /**
3002
+ * Create a new buildable patch of operations to perform
3003
+ *
3004
+ * @param documentIds - Array of document IDs to patch
3005
+ * @param operations - Optional object of patch operations to initialize the patch instance with
3006
+ * @returns Patch instance - call `.commit()` to perform the operations defined
3007
+ */
3008
+ patch(documentIds: string[], operations?: PatchOperations): Patch
3009
+ /**
3010
+ * Create a new buildable patch of operations to perform
3011
+ *
3012
+ * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
3013
+ * @param operations - Optional object of patch operations to initialize the patch instance with
3014
+ * @returns Patch instance - call `.commit()` to perform the operations defined
3015
+ */
3016
+ patch(selection: MutationSelection, operations?: PatchOperations): Patch
3017
+ /**
3018
+ * Create a new transaction of mutations
3019
+ *
3020
+ * @param operations - Optional array of mutation operations to initialize the transaction instance with
3021
+ */
3022
+ transaction<R extends Record<string, Any> = Record<string, Any>>(
3023
+ operations?: Mutation<R>[],
3024
+ ): Transaction
3025
+ /**
3026
+ * Perform action operations against the configured dataset
3027
+ * Returns a promise that resolves to the transaction result
3028
+ *
3029
+ * @param operations - Action operation(s) to execute
3030
+ * @param options - Action options
3031
+ */
3032
+ action(
3033
+ operations: Action | Action[],
3034
+ options?: BaseActionOptions,
3035
+ ): Promise<SingleActionResult | MultipleActionResult>
3036
+ /**
3037
+ * Perform a request against the Sanity API
3038
+ * NOTE: Only use this for Sanity API endpoints, not for your own APIs!
3039
+ *
3040
+ * @param options - Request options
3041
+ * @returns Promise resolving to the response body
3042
+ */
3043
+ request<R = Any>(options: RawRequestOptions): Promise<R>
3044
+ /**
3045
+ * Perform an HTTP request a `/data` sub-endpoint
3046
+ * NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
3047
+ *
3048
+ * @deprecated - Use `request()` or your own HTTP library instead
3049
+ * @param endpoint - Endpoint to hit (mutate, query etc)
3050
+ * @param body - Request body
3051
+ * @param options - Request options
3052
+ * @internal
3053
+ */
3054
+ dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
3055
+ /**
3056
+ * Get a Sanity API URL for the URI provided
3057
+ *
3058
+ * @param uri - URI/path to build URL for
3059
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
3060
+ */
3061
+ getUrl(uri: string, canUseCdn?: boolean): string
3062
+ /**
3063
+ * Get a Sanity API URL for the data operation and path provided
3064
+ *
3065
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3066
+ * @param path - Path to append after the operation
3067
+ */
3068
+ getDataUrl(operation: string, path?: string): string
3069
+ }
3070
+
3071
+ export {SanityDocument}
3072
+
3073
+ /** @internal */
3074
+ declare type SanityDocument_2<T extends Record<string, Any> = Record<string, Any>> = {
3075
+ [P in keyof T]: T[P]
3076
+ } & {
3077
+ _id: string
3078
+ _rev: string
3079
+ _type: string
3080
+ _createdAt: string
3081
+ _updatedAt: string
3082
+ /**
3083
+ * Present when `perspective` is set to `previewDrafts`
3084
+ */
3085
+ _originalId?: string
3086
+ }
3087
+
3088
+ /** @public */
3089
+ declare type SanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
3090
+ [P in keyof T]: T[P]
3091
+ } & {
3092
+ _type: string
3093
+ }
3094
+
3095
+ /** @internal */
3096
+ declare interface SanityImageAssetDocument extends SanityAssetDocument {
3097
+ metadata: {
3098
+ _type: 'sanity.imageMetadata'
3099
+ hasAlpha: boolean
3100
+ isOpaque: boolean
3101
+ lqip?: string
3102
+ blurHash?: string
3103
+ dimensions: {
3104
+ _type: 'sanity.imageDimensions'
3105
+ aspectRatio: number
3106
+ height: number
3107
+ width: number
3108
+ }
3109
+ palette?: {
3110
+ _type: 'sanity.imagePalette'
3111
+ darkMuted?: SanityImagePalette
3112
+ darkVibrant?: SanityImagePalette
3113
+ dominant?: SanityImagePalette
3114
+ lightMuted?: SanityImagePalette
3115
+ lightVibrant?: SanityImagePalette
3116
+ muted?: SanityImagePalette
3117
+ vibrant?: SanityImagePalette
3118
+ }
3119
+ image?: {
3120
+ _type: 'sanity.imageExifTags'
3121
+ [key: string]: Any
3122
+ }
3123
+ exif?: {
3124
+ _type: 'sanity.imageExifMetadata'
3125
+ [key: string]: Any
3126
+ }
3127
+ }
3128
+ }
3129
+
3130
+ /** @internal */
3131
+ declare interface SanityImagePalette {
3132
+ background: string
3133
+ foreground: string
3134
+ population: number
3135
+ title: string
3136
+ }
3137
+
3138
+ /** @public */
3139
+ export declare interface SanityProject {
3140
+ id: string
3141
+ displayName: string
3142
+ /**
3143
+ * @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
3144
+ * @see https://www.sanity.io/help/studio-host-user-applications
3145
+ */
3146
+ studioHost: string | null
3147
+ organizationId: string | null
3148
+ isBlocked: boolean
3149
+ isDisabled: boolean
3150
+ isDisabledByUser: boolean
3151
+ createdAt: string
3152
+ pendingInvites?: number
3153
+ maxRetentionDays?: number
3154
+ members: SanityProjectMember[]
3155
+ metadata: {
3156
+ cliInitializedAt?: string
3157
+ color?: string
3158
+ /**
3159
+ * @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
3160
+ * @see https://www.sanity.io/help/studio-host-user-applications
3161
+ */
3162
+ externalStudioHost?: string
3163
+ }
3164
+ }
3165
+
3166
+ /** @public */
3167
+ export declare interface SanityProjectMember {
3168
+ id: string
3169
+ role: string
3170
+ isRobot: boolean
3171
+ isCurrentUser: boolean
3172
+ }
3173
+
3174
+ /**
3175
+ * @internal
3176
+ *
3177
+ * Top-level context provider that provides access to the Sanity configuration instance.
3178
+ * This must wrap any components making use of the Sanity SDK React hooks.
3179
+ *
3180
+ * @remarks In most cases, SanityApp should be used rather than SanityProvider directly; SanityApp bundles both SanityProvider and an authentication layer.
3181
+ * @param props - Sanity project and dataset configuration
3182
+ * @returns Rendered component
3183
+ * @example
3184
+ * ```tsx
3185
+ * import {createSanityInstance} from '@sanity/sdk'
3186
+ * import {SanityProvider} from '@sanity/sdk-react'
3187
+ *
3188
+ * import MyAppRoot from './Root'
3189
+ *
3190
+ * const sanityInstance = createSanityInstance({
3191
+ * projectId: 'your-project-id',
3192
+ * dataset: 'production',
3193
+ * })
3194
+ *
3195
+ * export default function MyApp() {
3196
+ * return (
3197
+ * <SanityProvider sanityInstance={sanityInstance}>
3198
+ * <MyAppRoot />
3199
+ * </SanityProvider>
3200
+ * )
3201
+ * }
3202
+ * ```
3203
+ */
3204
+ export declare const SanityProvider: ({
3205
+ children,
3206
+ sanityInstances,
3207
+ }: SanityProviderProps) => ReactElement
3208
+
3209
+ /**
3210
+ * @internal
3211
+ */
3212
+ export declare interface SanityProviderProps {
3213
+ children: React.ReactNode
3214
+ sanityInstances: SanityInstance[]
3215
+ }
3216
+
3217
+ /** @public */
3218
+ declare interface SanityQueries {}
3219
+
3220
+ /** @public */
3221
+ declare interface SanityUser {
3222
+ id: string
3223
+ projectId: string
3224
+ displayName: string
3225
+ familyName: string | null
3226
+ givenName: string | null
3227
+ middleName: string | null
3228
+ imageUrl: string | null
3229
+ createdAt: string
3230
+ updatedAt: string
3231
+ isCurrentUser: boolean
3232
+ }
3233
+
3234
+ /**
3235
+ * @internal
3236
+ *
3237
+ * Top-level context provider that provides access to the Sanity SDK.
3238
+ */
3239
+ export declare function SDKProvider({
3240
+ children,
3241
+ sanityConfigs,
3242
+ fallback,
3243
+ }: SDKProviderProps): ReactElement
3244
+
3245
+ /**
3246
+ * @internal
3247
+ */
3248
+ export declare interface SDKProviderProps {
3249
+ children: ReactNode
3250
+ sanityConfigs: SanityConfig[]
3251
+ fallback: ReactNode
3252
+ }
3253
+
3254
+ /** @internal */
3255
+ declare interface SingleActionResult {
3256
+ transactionId: string
3257
+ }
3258
+
3259
+ /** @internal */
3260
+ declare interface SingleMutationResult {
3261
+ transactionId: string
3262
+ documentId: string
3263
+ results: {
3264
+ id: string
3265
+ operation: MutationOperation
3266
+ }[]
3267
+ }
3268
+
3269
+ export {SortOrderingItem}
3270
+
3271
+ /** @public */
3272
+ declare type StackablePerspective = ('published' | 'drafts' | string) & {}
3273
+
3274
+ /** @public */
3275
+ declare interface StegaConfig {
3276
+ /**
3277
+ * Enable or disable stega encoded strings in query results
3278
+ * ```ts
3279
+ {
3280
+ enabled: process.env.VERCEL_ENV !== 'production'
3281
+ }
3282
+ * ```
3283
+ * @defaultValue `false`
3284
+ */
3285
+ enabled?: boolean
3286
+ /**
3287
+ * Where the Studio is hosted.
3288
+ * If it's embedded in the app, use the base path for example `/studio`.
3289
+ * Otherwise provide the full URL to where the Studio is hosted, for example: `https://blog.sanity.studio`.
3290
+ *
3291
+ */
3292
+ studioUrl?: StudioUrl | ResolveStudioUrl
3293
+ filter?: FilterDefault
3294
+ /**
3295
+ * Specify a `console.log` compatible logger to see debug logs, which keys are encoded and which are not.
3296
+ */
3297
+ logger?: Logger
3298
+ /**
3299
+ * Set to `true` to omit cross dataset reference specific data from encoded strings
3300
+ */
3301
+ omitCrossDatasetReferenceData?: boolean
3302
+ }
3303
+
3304
+ /** @public */
3305
+ declare type StegaConfigRequiredKeys = Extract<keyof StegaConfig, 'enabled'>
3306
+
3307
+ /** @alpha */
3308
+ declare type StudioBaseRoute = {
3309
+ baseUrl: StudioBaseUrl
3310
+ workspace?: string
3311
+ tool?: string
3312
+ }
3313
+
3314
+ /** @alpha */
3315
+ declare type StudioBaseUrl = `/${string}` | `${string}.sanity.studio` | `https://${string}` | string
3316
+
3317
+ /** @alpha */
3318
+ declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
3319
+
3320
+ declare interface StudioWorkspacesResult {
3321
+ workspacesByResourceId: WorkspacesByResourceId
3322
+ error: string | null
3323
+ isConnected: boolean
3324
+ }
3325
+
3326
+ /** @public */
3327
+ declare type SyncTag = `s1:${string}`
3328
+
3329
+ /** @public */
3330
+ declare class Transaction extends BaseTransaction {
3331
+ #private
3332
+ constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
3333
+ /**
3334
+ * Clones the transaction
3335
+ */
3336
+ clone(): Transaction
3337
+ /**
3338
+ * Commit the transaction, returning a promise that resolves to the first mutated document
3339
+ *
3340
+ * @param options - Options for the mutation operation
3341
+ */
3342
+ commit<R extends Record<string, Any>>(
3343
+ options: TransactionFirstDocumentMutationOptions,
3344
+ ): Promise<SanityDocument_2<R>>
3345
+ /**
3346
+ * Commit the transaction, returning a promise that resolves to an array of the mutated documents
3347
+ *
3348
+ * @param options - Options for the mutation operation
3349
+ */
3350
+ commit<R extends Record<string, Any>>(
3351
+ options: TransactionAllDocumentsMutationOptions,
3352
+ ): Promise<SanityDocument_2<R>[]>
3353
+ /**
3354
+ * Commit the transaction, returning a promise that resolves to a mutation result object
3355
+ *
3356
+ * @param options - Options for the mutation operation
3357
+ */
3358
+ commit(options: TransactionFirstDocumentIdMutationOptions): Promise<SingleMutationResult>
3359
+ /**
3360
+ * Commit the transaction, returning a promise that resolves to a mutation result object
3361
+ *
3362
+ * @param options - Options for the mutation operation
3363
+ */
3364
+ commit(options: TransactionAllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
3365
+ /**
3366
+ * Commit the transaction, returning a promise that resolves to a mutation result object
3367
+ *
3368
+ * @param options - Options for the mutation operation
3369
+ */
3370
+ commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
3371
+ /**
3372
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
3373
+ * The operation is added to the current transaction, ready to be commited by `commit()`
3374
+ *
3375
+ * @param documentId - Document ID to perform the patch operation on
3376
+ * @param patchOps - Operations to perform, or a builder function
3377
+ */
3378
+ patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
3379
+ /**
3380
+ * Performs a patch on the given selection. Can either be a builder function or an object of patch operations.
3381
+ *
3382
+ * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
3383
+ * @param patchOps - Operations to perform, or a builder function
3384
+ */
3385
+ patch(patch: MutationSelection, patchOps?: PatchBuilder | PatchOperations): this
3386
+ /**
3387
+ * Adds the given patch instance to the transaction.
3388
+ * The operation is added to the current transaction, ready to be commited by `commit()`
3389
+ *
3390
+ * @param patch - Patch to execute
3391
+ */
3392
+ patch(patch: Patch): this
3393
+ }
3394
+
3395
+ /** @internal */
3396
+ declare type TransactionAllDocumentIdsMutationOptions = BaseMutationOptions & {
3397
+ returnFirst?: false
3398
+ returnDocuments?: false
3399
+ }
3400
+
3401
+ /** @internal */
3402
+ declare type TransactionAllDocumentsMutationOptions = BaseMutationOptions & {
3403
+ returnFirst?: false
3404
+ returnDocuments: true
3405
+ }
3406
+
3407
+ /** @internal */
3408
+ declare type TransactionFirstDocumentIdMutationOptions = BaseMutationOptions & {
3409
+ returnFirst: true
3410
+ returnDocuments?: false
3411
+ }
3412
+
3413
+ /** @internal */
3414
+ declare type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
3415
+ returnFirst: true
3416
+ returnDocuments: true
3417
+ }
3418
+
3419
+ /** @public */
3420
+ declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
3421
+ filterResponse: false
3422
+ /**
3423
+ * When `filterResponse` is `false`, `returnQuery` also defaults to `true` for
3424
+ * backwards compatibility (on the client side, not from the content lake API).
3425
+ * Can also explicitly be set to `true`.
3426
+ */
3427
+ returnQuery?: true
3428
+ }
3429
+
3430
+ /**
3431
+ * When using `filterResponse: false`, but you do not wish to receive back the query from
3432
+ * the content lake API.
3433
+ *
3434
+ * @public
3435
+ */
3436
+ declare interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions {
3437
+ filterResponse: false
3438
+ returnQuery: false
3439
+ }
3440
+
3441
+ /**
3442
+ * Retract a published document.
3443
+ * If there is no draft version then this is created from the published version.
3444
+ * In either case the published version is deleted.
3445
+ *
3446
+ * @public
3447
+ */
3448
+ declare type UnpublishAction = {
3449
+ actionType: 'sanity.action.document.unpublish'
3450
+ /**
3451
+ * Draft document ID to replace the published document with
3452
+ */
3453
+ draftId: string
3454
+ /**
3455
+ * Published document ID to delete
3456
+ */
3457
+ publishedId: string
3458
+ }
3459
+
3460
+ declare type Updater<TValue> = TValue | ((nextValue: TValue) => TValue)
3461
+
3462
+ /** @public */
3463
+ declare type UploadBody = File | Blob | Buffer | NodeJS.ReadableStream
3464
+
3465
+ /** @public */
3466
+ declare interface UploadClientConfig {
3467
+ /**
3468
+ * Optional request tag for the upload
3469
+ */
3470
+ tag?: string
3471
+ /**
3472
+ * Whether or not to preserve the original filename (default: true)
3473
+ */
3474
+ preserveFilename?: boolean
3475
+ /**
3476
+ * Filename for this file (optional)
3477
+ */
3478
+ filename?: string
3479
+ /**
3480
+ * Milliseconds to wait before timing the request out
3481
+ */
3482
+ timeout?: number
3483
+ /**
3484
+ * Mime type of the file
3485
+ */
3486
+ contentType?: string
3487
+ /**
3488
+ * Array of metadata parts to extract from asset
3489
+ */
3490
+ extract?: AssetMetadataType[]
3491
+ /**
3492
+ * Optional freeform label for the asset. Generally not used.
3493
+ */
3494
+ label?: string
3495
+ /**
3496
+ * Optional title for the asset
3497
+ */
3498
+ title?: string
3499
+ /**
3500
+ * Optional description for the asset
3501
+ */
3502
+ description?: string
3503
+ /**
3504
+ * The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published
3505
+ */
3506
+ creditLine?: string
3507
+ /**
3508
+ * Source data (when the asset is from an external service)
3509
+ */
3510
+ source?: {
3511
+ /**
3512
+ * The (u)id of the asset within the source, i.e. 'i-f323r1E'
3513
+ */
3514
+ id: string
3515
+ /**
3516
+ * The name of the source, i.e. 'unsplash'
3517
+ */
3518
+ name: string
3519
+ /**
3520
+ * A url to where to find the asset, or get more info about it in the source
3521
+ */
3522
+ url?: string
3523
+ }
3524
+ }
3525
+
3526
+ /**
3527
+ *
3528
+ * @beta
3529
+ *
3530
+ * Provides a callback for applying one or more actions to a document.
3531
+ *
3532
+ * @category Documents
3533
+ * @param resourceId - The resource ID of the document to apply actions to. If not provided, the document will use the default resource.
3534
+ * @returns A function that takes one more more {@link DocumentAction}s and returns a promise that resolves to an {@link ActionsResult}.
3535
+ * @example Publish or unpublish a document
3536
+ * ```
3537
+ * import { publishDocument, unpublishDocument } from '@sanity/sdk'
3538
+ * import { useApplyActions } from '@sanity/sdk-react'
3539
+ *
3540
+ * const apply = useApplyActions()
3541
+ * const myDocument = { _id: 'my-document-id', _type: 'my-document-type' }
3542
+ *
3543
+ * return (
3544
+ * <button onClick={() => apply(publishDocument(myDocument))}>Publish</button>
3545
+ * <button onClick={() => apply(unpublishDocument(myDocument))}>Unpublish</button>
3546
+ * )
3547
+ * ```
3548
+ *
3549
+ * @example Create and publish a new document
3550
+ * ```
3551
+ * import { createDocument, publishDocument } from '@sanity/sdk'
3552
+ * import { useApplyActions } from '@sanity/sdk-react'
3553
+ *
3554
+ * const apply = useApplyActions()
3555
+ *
3556
+ * const handleCreateAndPublish = () => {
3557
+ * const handle = { _id: window.crypto.randomUUID(), _type: 'my-document-type' }
3558
+ * apply([
3559
+ * createDocument(handle),
3560
+ * publishDocument(handle),
3561
+ * ])
3562
+ * }
3563
+ *
3564
+ * return (
3565
+ * <button onClick={handleCreateAndPublish}>
3566
+ * I’m feeling lucky
3567
+ * </button>
3568
+ * )
3569
+ * ```
3570
+ */
3571
+ export declare function useApplyActions(
3572
+ resourceId?: ResourceId,
3573
+ ): <TDocument extends SanityDocument>(
3574
+ action: DocumentAction<TDocument> | DocumentAction<TDocument>[],
3575
+ options?: ApplyActionsOptions,
3576
+ ) => Promise<ActionsResult<TDocument>>
3577
+
3578
+ /**
3579
+ * @internal
3580
+ * A React hook that subscribes to authentication state changes.
3581
+ *
3582
+ * This hook provides access to the current authentication state type from the Sanity auth store.
3583
+ * It automatically re-renders when the authentication state changes.
3584
+ *
3585
+ * @remarks
3586
+ * The hook uses `useSyncExternalStore` to safely subscribe to auth state changes
3587
+ * and ensure consistency between server and client rendering.
3588
+ *
3589
+ * @returns The current authentication state type
3590
+ *
3591
+ * @example
3592
+ * ```tsx
3593
+ * function AuthStatus() {
3594
+ * const authState = useAuthState()
3595
+ * return <div>Current auth state: {authState}</div>
3596
+ * }
3597
+ * ```
3598
+ */
3599
+ export declare const useAuthState: () => AuthState
3600
+
3601
+ /**
3602
+ * Hook to get the currently logged in user
3603
+ * @internal
3604
+ * @returns The current user or null if not authenticated
3605
+ */
3606
+ export declare const useAuthToken: () => string | null
3607
+
3608
+ /**
3609
+ * A React hook that provides a client that subscribes to changes in your application,
3610
+ * such as user authentication changes.
3611
+ *
3612
+ * @remarks
3613
+ * The hook uses `useSyncExternalStore` to safely subscribe to changes
3614
+ * and ensure consistency between server and client rendering.
3615
+ *
3616
+ * @category Platform
3617
+ * @returns A Sanity client
3618
+ *
3619
+ * @example
3620
+ * ```tsx
3621
+ * function MyComponent() {
3622
+ * const client = useClient({apiVersion: '2024-11-12'})
3623
+ * const [document, setDocument] = useState(null)
3624
+ * useEffect(async () => {
3625
+ * const doc = client.fetch('*[_id == "myDocumentId"]')
3626
+ * setDocument(doc)
3627
+ * }, [])
3628
+ * return <div>{JSON.stringify(document) ?? 'Loading...'}</div>
3629
+ * }
3630
+ * ```
3631
+ *
3632
+ * @public
3633
+ */
3634
+ export declare const useClient: (e: ClientOptions) => SanityClient
3635
+
3636
+ declare type UseCurrentUser = {
3637
+ /**
3638
+ * @public
3639
+ *
3640
+ * Provides the currently authenticated user’s profile information.
3641
+ *
3642
+ * @category Users
3643
+ * @returns The current user data
3644
+ *
3645
+ * @example Rendering a basic user profile
3646
+ * ```
3647
+ * const user = useCurrentUser()
3648
+ *
3649
+ * return (
3650
+ * <figure>
3651
+ * <img src={user?.profileImage} alt=`Profile image for ${user?.name}` />
3652
+ * <h2>{user?.name}</h2>
3653
+ * </figure>
3654
+ * )
3655
+ * ```
3656
+ */
3657
+ (): CurrentUser | null
3658
+ }
3659
+
3660
+ /**
3661
+ * @public
3662
+ * @TODO This should not return null — users of a custom app will always be authenticated via Core
3663
+ */
3664
+ export declare const useCurrentUser: UseCurrentUser
3665
+
3666
+ /**
3667
+ * @remarks
3668
+ * A React hook that retrieves the dashboard organization ID that is currently selected in the Sanity Dashboard.
3669
+ *
3670
+ * @example
3671
+ * ```tsx
3672
+ * function DashboardComponent() {
3673
+ * const orgId = useDashboardOrganizationId()
3674
+ *
3675
+ * if (!orgId) return null
3676
+ *
3677
+ * return <div>Organization ID: {String(orgId)}</div>
3678
+ * }
3679
+ * ```
3680
+ *
3681
+ * @returns The dashboard organization ID (string | undefined)
3682
+ * @public
3683
+ */
3684
+ export declare function useDashboardOrganizationId(): string | undefined
3685
+
3686
+ declare type UseDatasets = {
3687
+ /**
3688
+ *
3689
+ * Returns metadata for each dataset in your organization.
3690
+ *
3691
+ * @category Datasets
3692
+ * @returns The metadata for your organization's datasets
3693
+ *
3694
+ * @example
3695
+ * ```tsx
3696
+ * const datasets = useDatasets()
3697
+ *
3698
+ * return (
3699
+ * <select>
3700
+ * {datasets.map((dataset) => (
3701
+ * <option key={dataset.name}>{dataset.name}</option>
3702
+ * ))}
3703
+ * </select>
3704
+ * )
3705
+ * ```
3706
+ *
3707
+ */
3708
+ (): DatasetsResponse
3709
+ }
3710
+
3711
+ /** @public */
3712
+ export declare const useDatasets: UseDatasets
3713
+
3714
+ /**
3715
+ * @beta
3716
+ *
3717
+ * ## useDocument(doc, path)
3718
+ * Read and subscribe to nested values in a document
3719
+ * @category Documents
3720
+ * @param doc - The document to read state from. If you pass a `DocumentHandle` with a `resourceId` in the DocumentResourceId format (`document:projectId.dataset:documentId`)
3721
+ * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.
3722
+ * @param path - The path to the nested value to read from
3723
+ * @returns The value at the specified path
3724
+ * @example
3725
+ * ```tsx
3726
+ * import {type DocumentHandle, useDocument} from '@sanity/sdk-react'
3727
+ *
3728
+ * function OrderLink({documentHandle}: {documentHandle: DocumentHandle}) {
3729
+ * const title = useDocument(documentHandle, 'title')
3730
+ * const id = useDocument(documentHandle, '_id')
3731
+ *
3732
+ * return (
3733
+ * <a href=`/order/${id}`>Order {title} today!</a>
3734
+ * )
3735
+ * }
3736
+ * ```
3737
+ *
3738
+ */
3739
+ export declare function useDocument<
3740
+ TDocument extends SanityDocument,
3741
+ TPath extends JsonMatchPath<TDocument>,
3742
+ >(doc: DocumentHandle<TDocument>, path: TPath): JsonMatch<TDocument, TPath> | undefined
3743
+
3744
+ /**
3745
+ * @beta
3746
+ * ## useDocument(doc)
3747
+ * Read and subscribe to an entire document
3748
+ * @param doc - The document to read state from
3749
+ * @returns The document state as an object
3750
+ * @example
3751
+ * ```tsx
3752
+ * import {type SanityDocument, type DocumentHandle, useDocument} from '@sanity/sdk-react'
3753
+ *
3754
+ * interface Book extends SanityDocument {
3755
+ * title: string
3756
+ * author: string
3757
+ * summary: string
3758
+ * }
3759
+ *
3760
+ * function DocumentView({documentHandle}: {documentHandle: DocumentHandle}) {
3761
+ * const book = useDocument<Book>(documentHandle)
3762
+ *
3763
+ * return (
3764
+ * <article>
3765
+ * <h1>{book?.title}</h1>
3766
+ * <address>By {book?.author}</address>
3767
+ *
3768
+ * <h2>Summary</h2>
3769
+ * {book?.summary}
3770
+ *
3771
+ * <h2>Order</h2>
3772
+ * <a href=`/order/${book._id}`>Order {book?.title} today!</a>
3773
+ * </article>
3774
+ * )
3775
+ * }
3776
+ * ```
3777
+ *
3778
+ */
3779
+ export declare function useDocument<TDocument extends SanityDocument>(
3780
+ doc: DocumentHandle<TDocument>,
3781
+ ): TDocument | null
3782
+
3783
+ /**
3784
+ *
3785
+ * @beta
3786
+ *
3787
+ * Subscribes an event handler to events in your application’s document store, such as document
3788
+ * creation, deletion, and updates.
3789
+ *
3790
+ * @category Documents
3791
+ * @param handler - The event handler to register.
3792
+ * @param doc - The document to subscribe to events for. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)
3793
+ * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.
3794
+ * @example
3795
+ * ```
3796
+ * import {useDocumentEvent} from '@sanity/sdk-react'
3797
+ * import {type DocumentEvent} from '@sanity/sdk'
3798
+ *
3799
+ * useDocumentEvent((event) => {
3800
+ * if (event.type === DocumentEvent.DocumentDeletedEvent) {
3801
+ * alert(`Document with ID ${event.documentId} deleted!`)
3802
+ * } else {
3803
+ * console.log(event)
3804
+ * }
3805
+ * })
3806
+ * ```
3807
+ */
3808
+ export declare function useDocumentEvent(
3809
+ handler: (documentEvent: DocumentEvent) => void,
3810
+ doc: DocumentHandle,
3811
+ ): void
3812
+
3813
+ declare type UseDocumentSyncStatus = {
3814
+ /**
3815
+ * Exposes the document’s sync status between local and remote document states.
3816
+ *
3817
+ * @category Documents
3818
+ * @param doc - The document handle to get sync status for. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)
3819
+ * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.
3820
+ * @returns `true` if local changes are synced with remote, `false` if the changes are not synced, and `undefined` if the document is not found
3821
+ * @example Disable a Save button when there are no changes to sync
3822
+ * ```
3823
+ * const myDocumentHandle = { _id: 'documentId', _type: 'documentType', resourceId: 'document:projectId:dataset:documentId' }
3824
+ * const documentSynced = useDocumentSyncStatus(myDocumentHandle)
3825
+ *
3826
+ * return (
3827
+ * <button disabled={documentSynced}>
3828
+ * Save Changes
3829
+ * </button>
3830
+ * )
3831
+ * ```
3832
+ */
3833
+ (doc: DocumentHandle): boolean | undefined
3834
+ }
3835
+
3836
+ /** @beta */
3837
+ export declare const useDocumentSyncStatus: UseDocumentSyncStatus
3838
+
3839
+ /**
3840
+ *
3841
+ * @beta
3842
+ *
3843
+ * ## useEditDocument(doc, path)
3844
+ * Edit a nested value within a document
3845
+ *
3846
+ * @category Documents
3847
+ * @param doc - The document to be edited; either as a document handle or the document’s ID a string
3848
+ * @param path - The path to the nested value to be edited
3849
+ * @returns A function to update the nested value. Accepts either a new value, or an updater function that exposes the previous value and returns a new value.
3850
+ * @example Update a document’s name by providing the new value directly
3851
+ * ```
3852
+ * const handle = { _id: 'documentId', _type: 'documentType' }
3853
+ * const name = useDocument(handle, 'name')
3854
+ * const editName = useEditDocument(handle, 'name')
3855
+ *
3856
+ * function handleNameChange(event: React.ChangeEvent<HTMLInputElement>) {
3857
+ * editName(event.target.value)
3858
+ * }
3859
+ *
3860
+ * return (
3861
+ * <input type='text' value={name} onChange={handleNameChange} />
3862
+ * )
3863
+ * ```
3864
+ *
3865
+ * @example Update a count on a document by providing an updater function
3866
+ * ```
3867
+ * const handle = { _id: 'documentId', _type: 'documentType' }
3868
+ * const count = useDocument(handle, 'count')
3869
+ * const editCount = useEditDocument(handle, 'count')
3870
+ *
3871
+ * function incrementCount() {
3872
+ * editCount(previousCount => previousCount + 1)
3873
+ * }
3874
+ *
3875
+ * return (
3876
+ * <>
3877
+ * <button onClick={incrementCount}>
3878
+ * Increment
3879
+ * </button>
3880
+ * Current count: {count}
3881
+ * </>
3882
+ * )
3883
+ * ```
3884
+ */
3885
+ export declare function useEditDocument<
3886
+ TDocument extends SanityDocument,
3887
+ TPath extends JsonMatchPath<TDocument>,
3888
+ >(
3889
+ doc: DocumentHandle<TDocument>,
3890
+ path: TPath,
3891
+ ): (nextValue: Updater<JsonMatch<TDocument, TPath>>) => Promise<ActionsResult<TDocument>>
3892
+
3893
+ /**
3894
+ *
3895
+ * @beta
3896
+ *
3897
+ * ## useEditDocument(doc)
3898
+ * Edit an entire document
3899
+ * @param doc - The document to be edited; either as a document handle or the document’s ID a string. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)
3900
+ * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.
3901
+ * @returns A function to update the document state. Accepts either a new document state, or an updater function that exposes the previous document state and returns the new document state.
3902
+ * @example
3903
+ * ```
3904
+ * const myDocumentHandle = { _id: 'documentId', _type: 'documentType' }
3905
+ *
3906
+ * const myDocument = useDocument(myDocumentHandle)
3907
+ * const { title, price } = myDocument
3908
+ *
3909
+ * const editMyDocument = useEditDocument(myDocumentHandle)
3910
+ *
3911
+ * function handleFieldChange(e: React.ChangeEvent<HTMLInputElement>) {
3912
+ * const {name, value} = e.currentTarget
3913
+ * // Use an updater function to update the document state based on the previous state
3914
+ * editMyDocument(previousDocument => ({
3915
+ * ...previousDocument,
3916
+ * [name]: value
3917
+ * }))
3918
+ * }
3919
+ *
3920
+ * function handleSaleChange(e: React.ChangeEvent<HTMLInputElement>) {
3921
+ * const { checked } = e.currentTarget
3922
+ * if (checked) {
3923
+ * // Use an updater function to add a new salePrice field;
3924
+ * // set it at a 20% discount off the normal price
3925
+ * editMyDocument(previousDocument => ({
3926
+ * ...previousDocument,
3927
+ * salePrice: previousDocument.price * 0.8,
3928
+ * }))
3929
+ * } else {
3930
+ * // Get the document state without the salePrice field
3931
+ * const { salePrice, ...rest } = myDocument
3932
+ * // Update the document state to remove the salePrice field
3933
+ * editMyDocument(rest)
3934
+ * }
3935
+ * }
3936
+ *
3937
+ * return (
3938
+ * <>
3939
+ * <form onSubmit={e => e.preventDefault()}>
3940
+ * <input name='title' type='text' value={title} onChange={handleFieldChange} />
3941
+ * <input name='price' type='number' value={price} onChange={handleFieldChange} />
3942
+ * <input
3943
+ * name='salePrice'
3944
+ * type='checkbox'
3945
+ * checked={Object(myDocument).hasOwnProperty('salePrice')}
3946
+ * onChange={handleSaleChange}
3947
+ * />
3948
+ * </form>
3949
+ * <pre><code>
3950
+ * {JSON.stringify(myDocument, null, 2)}
3951
+ * </code></pre>
3952
+ * </>
3953
+ * )
3954
+ * ```
3955
+ */
3956
+ export declare function useEditDocument<TDocument extends SanityDocument>(
3957
+ doc: DocumentHandle<TDocument>,
3958
+ ): (nextValue: Updater<TDocument>) => Promise<ActionsResult<TDocument>>
3959
+
3960
+ /**
3961
+ * @internal
3962
+ */
3963
+ export declare function useFrameConnection<
3964
+ TFrameMessage extends FrameMessage,
3965
+ TWindowMessage extends WindowMessage,
3966
+ >(options: UseFrameConnectionOptions<TWindowMessage>): FrameConnection<TFrameMessage>
3967
+
3968
+ /**
3969
+ * @internal
3970
+ */
3971
+ export declare interface UseFrameConnectionOptions<TWindowMessage extends WindowMessage> {
3972
+ name: string
3973
+ connectTo: string
3974
+ targetOrigin: string
3975
+ onMessage?: {
3976
+ [K in TWindowMessage['type']]: (
3977
+ data: Extract<
3978
+ TWindowMessage,
3979
+ {
3980
+ type: K
3981
+ }
3982
+ >['data'],
3983
+ ) => void
3984
+ }
3985
+ heartbeat?: boolean
3986
+ onStatus?: (status: ComlinkStatus) => void
3987
+ }
3988
+
3989
+ /**
3990
+ * @internal
3991
+ * A React hook that returns a function for handling authentication callbacks.
3992
+ *
3993
+ * @remarks
3994
+ * This hook provides access to the authentication store's callback handler,
3995
+ * which processes auth redirects by extracting the session ID and fetching the
3996
+ * authentication token. If fetching the long-lived token is successful,
3997
+ * `handleCallback` will return a Promise that resolves a new location that
3998
+ * removes the short-lived token from the URL. Use this in combination with
3999
+ * `history.replaceState` or your own router's `replace` function to update the
4000
+ * current location without triggering a reload.
4001
+ *
4002
+ * @example
4003
+ * ```tsx
4004
+ * function AuthCallback() {
4005
+ * const handleCallback = useHandleCallback()
4006
+ * const router = useRouter() // Example router
4007
+ *
4008
+ * useEffect(() => {
4009
+ * async function processCallback() {
4010
+ * // Handle the callback and get the cleaned URL
4011
+ * const newUrl = await handleCallback(window.location.href)
4012
+ *
4013
+ * if (newUrl) {
4014
+ * // Replace URL without triggering navigation
4015
+ * router.replace(newUrl, {shallow: true})
4016
+ * }
4017
+ * }
4018
+ *
4019
+ * processCallback().catch(console.error)
4020
+ * }, [handleCallback, router])
4021
+ *
4022
+ * return <div>Completing login...</div>
4023
+ * }
4024
+ * ```
4025
+ *
4026
+ * @returns A callback handler function that processes OAuth redirects
4027
+ * @public
4028
+ */
4029
+ export declare const useHandleCallback: () => (
4030
+ locationHref?: string | undefined,
4031
+ ) => Promise<string | false>
4032
+
4033
+ /**
4034
+ * Retrieves batches of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,
4035
+ * with infinite scrolling support. The number of document handles returned per batch is customizable,
4036
+ * and additional batches can be loaded using the supplied `loadMore` function.
4037
+ *
4038
+ * @beta
4039
+ * @category Documents
4040
+ * @param options - Configuration options for the infinite list
4041
+ * @returns An object containing the list of document handles, the loading state, the total count of retrived document handles, and a function to load more
4042
+ * @example
4043
+ * ```tsx
4044
+ * const {data, hasMore, isPending, loadMore} = useInfiniteList({
4045
+ * filter: '_type == "post"',
4046
+ * search: searchTerm,
4047
+ * batchSize: 10,
4048
+ * orderings: [{field: '_createdAt', direction: 'desc'}]
4049
+ * })
4050
+ *
4051
+ * return (
4052
+ * <div>
4053
+ * Total documents: {count}
4054
+ * <ol>
4055
+ * {data.map((doc) => (
4056
+ * <li key={doc._id}>
4057
+ * <MyDocumentComponent doc={doc} />
4058
+ * </li>
4059
+ * ))}
4060
+ * </ol>
4061
+ * {hasMore && <button onClick={loadMore}>Load More</button>}
4062
+ * </div>
4063
+ * )
4064
+ * ```
4065
+ *
4066
+ */
4067
+ export declare function useInfiniteList({
4068
+ batchSize,
4069
+ params,
4070
+ search,
4071
+ filter,
4072
+ orderings,
4073
+ ...options
4074
+ }: InfiniteListOptions): InfiniteList
4075
+
4076
+ /**
4077
+ * @internal
4078
+ * A React hook that retrieves the available authentication provider URLs for login.
4079
+ *
4080
+ * @remarks
4081
+ * This hook fetches the login URLs from the Sanity auth store when the component mounts.
4082
+ * Each provider object contains information about an authentication method, including its URL.
4083
+ * The hook will suspend if the login URLs have not yet loaded.
4084
+ *
4085
+ * @example
4086
+ * ```tsx
4087
+ * // LoginProviders component that uses the hook
4088
+ * function LoginProviders() {
4089
+ * const providers = useLoginUrls()
4090
+ *
4091
+ * return (
4092
+ * <div>
4093
+ * {providers.map((provider) => (
4094
+ * <a key={provider.name} href={provider.url}>
4095
+ * Login with {provider.title}
4096
+ * </a>
4097
+ * ))}
4098
+ * </div>
4099
+ * )
4100
+ * }
4101
+ *
4102
+ * // Parent component with Suspense boundary
4103
+ * function LoginPage() {
4104
+ * return (
4105
+ * <Suspense fallback={<div>Loading authentication providers...</div>}>
4106
+ * <LoginProviders />
4107
+ * </Suspense>
4108
+ * )
4109
+ * }
4110
+ * ```
4111
+ *
4112
+ * @returns An array of {@link AuthProvider} objects containing login URLs and provider information
4113
+ * @public
4114
+ */
4115
+ export declare function useLoginUrls(): AuthProvider[]
4116
+
4117
+ /**
4118
+ * Hook to log out of the current session
4119
+ * @internal
4120
+ * @returns A function to log out of the current session
4121
+ */
4122
+ export declare const useLogOut: () => () => Promise<void>
4123
+
4124
+ /**
4125
+ * @beta
4126
+ *
4127
+ * ## useManageFavorite
4128
+ * This hook provides functionality to add and remove documents from favorites,
4129
+ * and tracks the current favorite status of the document.
4130
+ * @category Core UI Communication
4131
+ * @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
4132
+ * @returns An object containing:
4133
+ * - `favorite` - Function to add document to favorites
4134
+ * - `unfavorite` - Function to remove document from favorites
4135
+ * - `isFavorited` - Boolean indicating if document is currently favorited
4136
+ * - `isConnected` - Boolean indicating if connection to Core UI is established
4137
+ *
4138
+ * @example
4139
+ * ```tsx
4140
+ * function MyDocumentAction(props: DocumentActionProps) {
4141
+ * const {_id, _type} = props
4142
+ * const {favorite, unfavorite, isFavorited, isConnected} = useManageFavorite({
4143
+ * _id,
4144
+ * _type
4145
+ * })
4146
+ *
4147
+ * return (
4148
+ * <Button
4149
+ * disabled={!isConnected}
4150
+ * onClick={() => isFavorited ? unfavorite() : favorite()}
4151
+ * text={isFavorited ? 'Remove from favorites' : 'Add to favorites'}
4152
+ * />
4153
+ * )
4154
+ * }
4155
+ * ```
4156
+ */
4157
+ export declare function useManageFavorite({_id, _type}: DocumentHandle): ManageFavorite
4158
+
1
4159
  /**
2
- * An example function that will be removed.
3
4160
  * @public
4161
+ * Hook that provides a function to navigate to a studio document.
4162
+ * @param documentHandle - The document handle containing document ID, type, and resource ID
4163
+ * @returns An object containing:
4164
+ * - navigateToStudioDocument - Function that when called will navigate to the studio document
4165
+ * - isConnected - Boolean indicating if connection to Core UI is established
4166
+ */
4167
+ export declare function useNavigateToStudioDocument(
4168
+ documentHandle: DocumentHandle,
4169
+ ): NavigateToStudioResult
4170
+
4171
+ /**
4172
+ * Retrieves pages of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,
4173
+ * with support for traditional paginated interfaces. The number of document handles returned per page is customizable,
4174
+ * while page navigation is handled via the included navigation functions.
4175
+ *
4176
+ * @beta
4177
+ * @category Documents
4178
+ * @param options - Configuration options for the paginated list
4179
+ * @returns An object containing the current page of document handles, the loading and pagination state, and navigation functions
4180
+ * @example
4181
+ * ```tsx
4182
+ * const {
4183
+ * data,
4184
+ * isPending,
4185
+ * currentPage,
4186
+ * totalPages,
4187
+ * nextPage,
4188
+ * previousPage,
4189
+ * hasNextPage,
4190
+ * hasPreviousPage
4191
+ * } = usePaginatedList({
4192
+ * filter: '_type == "post"',
4193
+ * search: searchTerm,
4194
+ * pageSize: 10,
4195
+ * orderings: [{field: '_createdAt', direction: 'desc'}]
4196
+ * })
4197
+ *
4198
+ * return (
4199
+ * <>
4200
+ * <table>
4201
+ * {data.map(doc => (
4202
+ * <MyTableRowComponent key={doc._id} doc={doc} />
4203
+ * ))}
4204
+ * </table>
4205
+ * <>
4206
+ * {hasPreviousPage && <button onClick={previousPage}>Previous</button>}
4207
+ * {currentPage} / {totalPages}
4208
+ * {hasNextPage && <button onClick={nextPage}>Next</button>}
4209
+ * </>
4210
+ * </>
4211
+ * )
4212
+ * ```
4213
+ *
4214
+ */
4215
+ export declare function usePaginatedList({
4216
+ filter,
4217
+ pageSize,
4218
+ params,
4219
+ orderings,
4220
+ search,
4221
+ ...options
4222
+ }?: PaginatedListOptions): PaginatedList
4223
+
4224
+ /**
4225
+ *
4226
+ * @beta
4227
+ *
4228
+ * Check if the current user has the specified permissions for the given document actions.
4229
+ *
4230
+ * @category Permissions
4231
+ * @param actions - One more more calls to a particular document action function for a given document
4232
+ * @returns An object that specifies whether the action is allowed; if the action is not allowed, an explanatory message and list of reasons is also provided.
4233
+ *
4234
+ * @example Checking for permission to publish a document
4235
+ * ```ts
4236
+ * import {usePermissions, useApplyActions} from '@sanity/sdk-react'
4237
+ * import {publishDocument} from '@sanity/sdk'
4238
+ *
4239
+ * export function PublishButton({doc}: {doc: DocumentHandle}) {
4240
+ * const publishPermissions = usePermissions(publishDocument(doc))
4241
+ * const applyAction = useApplyActions()
4242
+ *
4243
+ * return (
4244
+ * <>
4245
+ * <button
4246
+ * disabled={!publishPermissions.allowed}
4247
+ * onClick={() => applyAction(publishDocument(doc))}
4248
+ * popoverTarget={`${publishPermissions.allowed ? undefined : 'publishButtonPopover'}`}
4249
+ * >
4250
+ * Publish
4251
+ * </button>
4252
+ * {!publishPermissions.allowed && (
4253
+ * <div popover id="publishButtonPopover">
4254
+ * {publishPermissions.message}
4255
+ * </div>
4256
+ * )}
4257
+ * </>
4258
+ * )
4259
+ * }
4260
+ * ```
4261
+ */
4262
+ export declare function usePermissions(
4263
+ actions: DocumentAction | DocumentAction[],
4264
+ ): PermissionsResult
4265
+
4266
+ /**
4267
+ * @beta
4268
+ *
4269
+ * Returns the preview values of a document (specified via a `DocumentHandle`),
4270
+ * including the document’s `title`, `subtitle`, `media`, and `status`. These values are live and will update in realtime.
4271
+ * To reduce unnecessary network requests for resolving the preview values, an optional `ref` can be passed to the hook so that preview
4272
+ * resolution will only occur if the `ref` is intersecting the current viewport.
4273
+ *
4274
+ * @category Documents
4275
+ * @param options - The document handle for the document you want to resolve preview values for, and an optional ref
4276
+ * @returns The preview values for the given document and a boolean to indicate whether the resolution is pending
4277
+ *
4278
+ * @example Combining with useDocuments to render a collection of document previews
4279
+ * ```
4280
+ * // PreviewComponent.jsx
4281
+ * export default function PreviewComponent({ document }) {
4282
+ * const { data: { title, subtitle, media }, isPending } = usePreview({ document })
4283
+ * return (
4284
+ * <article style={{ opacity: isPending ? 0.5 : 1}}>
4285
+ * {media?.type === 'image-asset' ? <img src={media.url} alt='' /> : ''}
4286
+ * <h2>{title}</h2>
4287
+ * <p>{subtitle}</p>
4288
+ * </article>
4289
+ * )
4290
+ * }
4291
+ *
4292
+ * // DocumentList.jsx
4293
+ * const { data, isPending } = useDocuments({ filter: '_type == "movie"' })
4294
+ * return (
4295
+ * <div>
4296
+ * <h1>Movies</h1>
4297
+ * <ul>
4298
+ * {isPending ? 'Loading…' : data.map(movie => (
4299
+ * <li key={movie._id}>
4300
+ * <Suspense fallback='Loading…'>
4301
+ * <PreviewComponent document={movie} />
4302
+ * </Suspense>
4303
+ * </li>
4304
+ * ))}
4305
+ * </ul>
4306
+ * </div>
4307
+ * )
4308
+ * ```
4309
+ */
4310
+ export declare function usePreview({
4311
+ document: {_id, _type},
4312
+ ref,
4313
+ }: UsePreviewOptions): UsePreviewResults
4314
+
4315
+ /**
4316
+ * @beta
4317
+ * @category Types
4
4318
  */
5
- export declare function main(): void
4319
+ export declare interface UsePreviewOptions {
4320
+ document: DocumentHandle
4321
+ ref?: React.RefObject<unknown>
4322
+ }
4323
+
4324
+ /**
4325
+ * @beta
4326
+ * @category Types
4327
+ */
4328
+ export declare interface UsePreviewResults {
4329
+ /** The results of resolving the document’s preview values */
4330
+ data: PreviewValue
4331
+ /** True when preview values are being refreshed */
4332
+ isPending: boolean
4333
+ }
4334
+
4335
+ declare type UseProject = {
4336
+ /**
4337
+ *
4338
+ * Returns metadata for a given project
4339
+ *
4340
+ * @category Projects
4341
+ * @param projectId - The ID of the project to retrieve metadata for
4342
+ * @returns The metadata for the project
4343
+ * @example
4344
+ * ```tsx
4345
+ * function ProjectMetadata({ projectId }: { projectId: string }) {
4346
+ * const project = useProject(projectId)
4347
+ *
4348
+ * return (
4349
+ * <figure style={{ backgroundColor: project.metadata.color || 'lavender'}}>
4350
+ * <h1>{project.displayName}</h1>
4351
+ * </figure>
4352
+ * )
4353
+ * }
4354
+ * ```
4355
+ */
4356
+ (projectId: string): SanityProject_2
4357
+ }
4358
+
4359
+ /** @public */
4360
+ export declare const useProject: UseProject
4361
+
4362
+ /**
4363
+ * @beta
4364
+ *
4365
+ * Returns the projection values of a document (specified via a `DocumentHandle`),
4366
+ * based on the provided projection string. These values are live and will update in realtime.
4367
+ * To reduce unnecessary network requests for resolving the projection values, an optional `ref` can be passed to the hook so that projection
4368
+ * resolution will only occur if the `ref` is intersecting the current viewport.
4369
+ *
4370
+ * @category Documents
4371
+ * @param options - The document handle for the document you want to project values from, the projection string, and an optional ref
4372
+ * @returns The projection values for the given document and a boolean to indicate whether the resolution is pending
4373
+ *
4374
+ * @example Using a projection to render a preview of document
4375
+ * ```
4376
+ * // ProjectionComponent.jsx
4377
+ * export default function ProjectionComponent({ document }) {
4378
+ * const ref = useRef(null)
4379
+ * const { results: { title, coverImage, authors }, isPending } = useProjection({
4380
+ * document,
4381
+ * ref,
4382
+ * projection: `{
4383
+ * title,
4384
+ * 'coverImage': cover.asset->url,
4385
+ * 'authors': array::join(authors[]->{'name': firstName + ' ' + lastName + ' '}.name, ', ')
4386
+ * }`,
4387
+ * })
4388
+ *
4389
+ * return (
4390
+ * <article ref={ref} style={{ opacity: isPending ? 0.5 : 1}}>
4391
+ * <h2>{title}</h2>
4392
+ * <img src={coverImage} alt={title} />
4393
+ * <p>{authors}</p>
4394
+ * </article>
4395
+ * )
4396
+ * }
4397
+ * ```
4398
+ *
4399
+ * @example Combining with useInfiniteList to render a collection with specific fields
4400
+ * ```
4401
+ * // DocumentList.jsx
4402
+ * const { data } = useInfiniteList({ filter: '_type == "article"' })
4403
+ * return (
4404
+ * <div>
4405
+ * <h1>Books</h1>
4406
+ * <ul>
4407
+ * {data.map(book => (
4408
+ * <li key={book._id}>
4409
+ * <Suspense fallback='Loading…'>
4410
+ * <ProjectionComponent
4411
+ * document={book}
4412
+ * />
4413
+ * </Suspense>
4414
+ * </li>
4415
+ * ))}
4416
+ * </ul>
4417
+ * </div>
4418
+ * )
4419
+ * ```
4420
+ */
4421
+ export declare function useProjection<TResult extends object>({
4422
+ document: {_id, _type},
4423
+ projection,
4424
+ ref,
4425
+ }: UseProjectionOptions): UseProjectionResults<TResult>
4426
+
4427
+ /**
4428
+ * @public
4429
+ * @category Types
4430
+ */
4431
+ export declare interface UseProjectionOptions {
4432
+ document: DocumentHandle
4433
+ projection: ValidProjection
4434
+ ref?: React.RefObject<unknown>
4435
+ }
4436
+
4437
+ /**
4438
+ * @public
4439
+ * @category Types
4440
+ */
4441
+ export declare interface UseProjectionResults<TResult extends object> {
4442
+ data: TResult
4443
+ isPending: boolean
4444
+ }
4445
+
4446
+ declare type UseProjects = {
4447
+ /**
4448
+ *
4449
+ * Returns metadata for each project in your organization.
4450
+ *
4451
+ * @category Projects
4452
+ * @returns An array of metadata (minus the projects’ members) for each project in your organization
4453
+ * @example
4454
+ * ```tsx
4455
+ * const projects = useProjects()
4456
+ *
4457
+ * return (
4458
+ * <select>
4459
+ * {projects.map((project) => (
4460
+ * <option key={project.id}>{project.displayName}</option>
4461
+ * ))}
4462
+ * </select>
4463
+ * )
4464
+ * ```
4465
+ */
4466
+ (): ProjectWithoutMembers[]
4467
+ }
4468
+
4469
+ /** @public */
4470
+ export declare const useProjects: UseProjects
4471
+
4472
+ /**
4473
+ * Executes GROQ queries against a Sanity dataset.
4474
+ *
4475
+ * This hook provides a convenient way to fetch and subscribe to real-time updates
4476
+ * for your Sanity content. Changes made to the dataset’s content will trigger
4477
+ * automatic updates.
4478
+ *
4479
+ * @remarks
4480
+ * The returned `isPending` flag indicates when a React transition is in progress,
4481
+ * which can be used to show loading states for query changes.
4482
+ *
4483
+ * @beta
4484
+ * @category GROQ
4485
+ * @param query - GROQ query string to execute
4486
+ * @param options - Optional configuration for the query
4487
+ * @returns Object containing the query result and a pending state flag
4488
+ *
4489
+ * @example Basic usage
4490
+ * ```tsx
4491
+ * const {data, isPending} = useQuery<Movie[]>('*[_type == "movie"]')
4492
+ * ```
4493
+ *
4494
+ * @example Using parameters
4495
+ * ```tsx
4496
+ * // With parameters
4497
+ * const {data} = useQuery<Movie>('*[_type == "movie" && _id == $id][0]', {
4498
+ * params: { id: 'movie-123' }
4499
+ * })
4500
+ * ```
4501
+ *
4502
+ * @example With a loading state for transitions
4503
+ * ```tsx
4504
+ * const {data, isPending} = useQuery<Movie[]>('*[_type == "movie"]')
4505
+ * return (
4506
+ * <div>
4507
+ * {isPending && <div>Updating...</div>}
4508
+ * <ul>
4509
+ * {data.map(movie => <li key={movie._id}>{movie.title}</li>)}
4510
+ * </ul>
4511
+ * </div>
4512
+ * )
4513
+ * ```
4514
+ *
4515
+ */
4516
+ export declare function useQuery<T>(
4517
+ query: string,
4518
+ options?: QueryOptions,
4519
+ ): {
4520
+ data: T
4521
+ isPending: boolean
4522
+ }
4523
+
4524
+ /**
4525
+ * @public
4526
+ * Hook for managing document interaction history in Sanity Studio.
4527
+ * This hook provides functionality to record document interactions.
4528
+ * @category History
4529
+ * @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
4530
+ * @returns An object containing:
4531
+ * - `recordEvent` - Function to record document interactions
4532
+ * - `isConnected` - Boolean indicating if connection to Studio is established
4533
+ *
4534
+ * @example
4535
+ * ```tsx
4536
+ * function MyDocumentAction(props: DocumentActionProps) {
4537
+ * const {_id, _type} = props
4538
+ * const {recordEvent, isConnected} = useRecordDocumentHistoryEvent({
4539
+ * _id,
4540
+ * _type
4541
+ * })
4542
+ *
4543
+ * return (
4544
+ * <Button
4545
+ * disabled={!isConnected}
4546
+ * onClick={() => recordEvent('viewed')}
4547
+ * text={'Viewed'}
4548
+ * />
4549
+ * )
4550
+ * }
4551
+ * ```
4552
+ */
4553
+ export declare function useRecordDocumentHistoryEvent({
4554
+ _id,
4555
+ _type,
4556
+ }: DocumentHandle): DocumentInteractionHistory
4557
+
4558
+ /** @public */
4559
+ declare class UsersClient {
4560
+ #private
4561
+ constructor(client: SanityClient, httpRequest: HttpRequest)
4562
+ /**
4563
+ * Fetch a user by user ID
4564
+ *
4565
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
4566
+ */
4567
+ getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
4568
+ }
4569
+
4570
+ /**
4571
+ * `useSanityInstance` returns the current Sanity instance from the application context.
4572
+ * This must be called from within a `SanityProvider` component.
4573
+ * @internal
4574
+ *
4575
+ * @param resourceId - The resourceId of the Sanity instance to return (optional)
4576
+ * @returns The current Sanity instance
4577
+ * @example
4578
+ * ```tsx
4579
+ * const instance = useSanityInstance('abc123.production')
4580
+ * ```
4581
+ */
4582
+ export declare const useSanityInstance: (resourceId?: string) => SanityInstance
4583
+
4584
+ /**
4585
+ * Hook that fetches studio workspaces and organizes them by projectId:dataset
4586
+ * @internal
4587
+ */
4588
+ export declare function useStudioWorkspacesByResourceId(): StudioWorkspacesResult
4589
+
4590
+ /**
4591
+ *
4592
+ * @public
4593
+ *
4594
+ * Retrieves the users for a given resource (either a project or an organization).
4595
+ *
4596
+ * @category Users
4597
+ * @param params - The resource type and its ID, and the limit of users to fetch
4598
+ * @returns A list of users, a boolean indicating whether there are more users to fetch, and a function to load more users
4599
+ *
4600
+ * @example
4601
+ * ```
4602
+ * const { users, hasMore, loadMore } = useUsers({
4603
+ * resourceType: 'organization',
4604
+ * resourceId: 'my-org-id',
4605
+ * limit: 10,
4606
+ * })
4607
+ *
4608
+ * return (
4609
+ * <div>
4610
+ * {users.map(user => (
4611
+ * <figure key={user.sanityUserId}>
4612
+ * <img src={user.profile.imageUrl} alt='' />
4613
+ * <figcaption>{user.profile.displayName}</figcaption>
4614
+ * <address>{user.profile.email}</address>
4615
+ * </figure>
4616
+ * ))}
4617
+ * {hasMore && <button onClick={loadMore}>Load More</button>}
4618
+ * </div>
4619
+ * )
4620
+ * ```
4621
+ */
4622
+ export declare function useUsers(params: UseUsersParams): UseUsersResult
4623
+
4624
+ /**
4625
+ * @public
4626
+ * @category Types
4627
+ */
4628
+ export declare interface UseUsersParams {
4629
+ /**
4630
+ * The type of resource to fetch users for.
4631
+ */
4632
+ resourceType: ResourceType
4633
+ /**
4634
+ * The ID of the resource to fetch users for.
4635
+ */
4636
+ resourceId: string
4637
+ /**
4638
+ * The limit of users to fetch.
4639
+ */
4640
+ limit?: number
4641
+ }
4642
+
4643
+ /**
4644
+ * @public
4645
+ * @category Types
4646
+ */
4647
+ export declare interface UseUsersResult {
4648
+ /**
4649
+ * The users fetched.
4650
+ */
4651
+ users: SanityUser_2[]
4652
+ /**
4653
+ * Whether there are more users to fetch.
4654
+ */
4655
+ hasMore: boolean
4656
+ /**
4657
+ * Load more users.
4658
+ */
4659
+ loadMore: () => void
4660
+ }
4661
+
4662
+ /**
4663
+ * @internal
4664
+ * Hook to wrap a Comlink node in a React hook.
4665
+ * Our store functionality takes care of the lifecycle of the node,
4666
+ * as well as sharing a single node between invocations if they share the same name.
4667
+ *
4668
+ * Generally not to be used directly, but to be used as a dependency of
4669
+ * Comlink-powered hooks like `useManageFavorite`.
4670
+ */
4671
+ export declare function useWindowConnection<
4672
+ TWindowMessage extends WindowMessage,
4673
+ TFrameMessage extends FrameMessage,
4674
+ >({
4675
+ name,
4676
+ connectTo,
4677
+ onMessage,
4678
+ onStatus,
4679
+ }: UseWindowConnectionOptions<TFrameMessage>): WindowConnection<TWindowMessage>
4680
+
4681
+ /**
4682
+ * @internal
4683
+ */
4684
+ export declare interface UseWindowConnectionOptions<TMessage extends FrameMessage> {
4685
+ name: string
4686
+ connectTo: string
4687
+ onMessage?: Record<TMessage['type'], WindowMessageHandler<TMessage>>
4688
+ onStatus?: (status: ComlinkStatus) => void
4689
+ }
4690
+
4691
+ /**
4692
+ * The listener has been established, and will start receiving events.
4693
+ * Note that this is also emitted upon _reconnection_.
4694
+ *
4695
+ * @public
4696
+ */
4697
+ declare type WelcomeEvent = {
4698
+ type: 'welcome'
4699
+ listenerName: string
4700
+ }
4701
+
4702
+ /**
4703
+ * @internal
4704
+ */
4705
+ export declare interface WindowConnection<TMessage extends WindowMessage> {
4706
+ sendMessage: <TType extends TMessage['type']>(
4707
+ type: TType,
4708
+ data?: Extract<
4709
+ TMessage,
4710
+ {
4711
+ type: TType
4712
+ }
4713
+ >['data'],
4714
+ ) => void
4715
+ fetch: <TResponse>(
4716
+ type: string,
4717
+ data?: MessageData,
4718
+ options?: {
4719
+ signal?: AbortSignal
4720
+ suppressWarnings?: boolean
4721
+ responseTimeout?: number
4722
+ },
4723
+ ) => Promise<TResponse>
4724
+ }
4725
+
4726
+ /**
4727
+ * @internal
4728
+ */
4729
+ export declare type WindowMessageHandler<TFrameMessage extends FrameMessage> = (
4730
+ event: TFrameMessage['data'],
4731
+ ) => TFrameMessage['response']
4732
+
4733
+ declare interface Workspace {
4734
+ name: string
4735
+ title: string
4736
+ basePath: string
4737
+ dataset: string
4738
+ userApplicationId: string
4739
+ url: string
4740
+ _ref: string
4741
+ }
4742
+
4743
+ declare interface WorkspacesByResourceId {
4744
+ [key: string]: Workspace[]
4745
+ }
6
4746
 
7
4747
  export {}