@sanity/sdk-react 2.9.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/index.d.ts +338 -215
  2. package/dist/index.js +564 -342
  3. package/dist/index.js.map +1 -1
  4. package/package.json +9 -14
  5. package/src/_exports/index.ts +2 -0
  6. package/src/_exports/sdk-react.ts +8 -0
  7. package/src/components/SDKProvider.test.tsx +5 -12
  8. package/src/components/SDKProvider.tsx +58 -28
  9. package/src/components/SanityApp.tsx +2 -2
  10. package/src/components/auth/AuthBoundary.tsx +8 -1
  11. package/src/components/auth/DashboardAccessRequest.tsx +37 -0
  12. package/src/components/auth/LoginError.test.tsx +191 -5
  13. package/src/components/auth/LoginError.tsx +100 -56
  14. package/src/components/errors/ChunkLoadError.test.tsx +59 -0
  15. package/src/components/errors/ChunkLoadError.tsx +56 -0
  16. package/src/components/errors/chunkReloadStorage.ts +57 -0
  17. package/src/config/handles.ts +55 -0
  18. package/src/constants.ts +5 -0
  19. package/src/context/DefaultResourceContext.ts +10 -0
  20. package/src/context/PerspectiveContext.ts +12 -0
  21. package/src/context/ResourceProvider.test.tsx +2 -2
  22. package/src/context/ResourceProvider.tsx +56 -51
  23. package/src/context/ResourcesContext.tsx +7 -0
  24. package/src/context/SanityInstanceProvider.test.tsx +100 -0
  25. package/src/context/SanityInstanceProvider.tsx +71 -0
  26. package/src/hooks/agent/agentActions.ts +55 -38
  27. package/src/hooks/auth/useVerifyOrgProjects.tsx +13 -6
  28. package/src/hooks/context/useResource.test.tsx +32 -0
  29. package/src/hooks/context/useResource.ts +24 -0
  30. package/src/hooks/context/useSanityInstance.test.tsx +42 -111
  31. package/src/hooks/context/useSanityInstance.ts +28 -50
  32. package/src/hooks/dashboard/useDispatchIntent.test.ts +11 -7
  33. package/src/hooks/dashboard/useDispatchIntent.ts +7 -7
  34. package/src/hooks/dashboard/useManageFavorite.test.tsx +16 -12
  35. package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.test.ts +15 -15
  36. package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.ts +13 -17
  37. package/src/hooks/document/{useApplyDocumentActions.test.ts → useApplyDocumentActions.test.tsx} +46 -81
  38. package/src/hooks/document/useApplyDocumentActions.ts +33 -67
  39. package/src/hooks/document/useDocument.ts +4 -6
  40. package/src/hooks/document/useDocumentEvent.ts +8 -7
  41. package/src/hooks/document/useDocumentPermissions.test.tsx +60 -152
  42. package/src/hooks/document/useDocumentPermissions.ts +78 -55
  43. package/src/hooks/document/useDocumentSyncStatus.ts +2 -2
  44. package/src/hooks/document/useEditDocument.test.tsx +25 -60
  45. package/src/hooks/document/useEditDocument.ts +3 -3
  46. package/src/hooks/documents/useDocuments.ts +19 -11
  47. package/src/hooks/helpers/createStateSourceHook.tsx +1 -2
  48. package/src/hooks/helpers/useNormalizedResourceOptions.test.tsx +253 -0
  49. package/src/hooks/helpers/useNormalizedResourceOptions.ts +169 -0
  50. package/src/hooks/helpers/useTrackHookUsage.ts +2 -2
  51. package/src/hooks/organizations/useOrganization.test-d.ts +53 -0
  52. package/src/hooks/organizations/useOrganization.test.ts +65 -0
  53. package/src/hooks/organizations/useOrganization.ts +40 -0
  54. package/src/hooks/organizations/useOrganizations.test-d.ts +55 -0
  55. package/src/hooks/organizations/useOrganizations.test.ts +85 -0
  56. package/src/hooks/organizations/useOrganizations.ts +45 -0
  57. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +29 -14
  58. package/src/hooks/presence/usePresence.test.tsx +56 -9
  59. package/src/hooks/presence/usePresence.ts +16 -4
  60. package/src/hooks/preview/useDocumentPreview.tsx +8 -10
  61. package/src/hooks/projection/useDocumentProjection.ts +7 -9
  62. package/src/hooks/projects/useProject.test-d.ts +49 -0
  63. package/src/hooks/projects/useProject.ts +33 -41
  64. package/src/hooks/projects/useProjects.test-d.ts +49 -0
  65. package/src/hooks/projects/useProjects.ts +17 -23
  66. package/src/hooks/query/useQuery.ts +11 -10
  67. package/src/hooks/releases/useActiveReleases.ts +14 -14
  68. package/src/hooks/releases/usePerspective.ts +11 -16
  69. package/src/hooks/users/useUser.ts +1 -1
  70. package/src/hooks/users/useUsers.ts +1 -1
  71. package/src/context/SourcesContext.tsx +0 -7
  72. package/src/hooks/helpers/useNormalizedSourceOptions.ts +0 -107
package/dist/index.d.ts CHANGED
@@ -6,7 +6,6 @@ import {AgentPromptOptions} from '@sanity/sdk'
6
6
  import {AgentPromptResult} from '@sanity/sdk'
7
7
  import {AgentTransformOptions} from '@sanity/sdk'
8
8
  import {AgentTranslateOptions} from '@sanity/sdk'
9
- import {ApplyDocumentActionsOptions} from '@sanity/sdk'
10
9
  import {AuthState} from '@sanity/sdk'
11
10
  import {CanvasResource} from '@sanity/message-protocol'
12
11
  import {ClientOptions} from '@sanity/sdk'
@@ -16,10 +15,11 @@ import {DatasetHandle} from '@sanity/sdk'
16
15
  import {DatasetsResponse} from '@sanity/client'
17
16
  import {DocumentAction} from '@sanity/sdk'
18
17
  import {DocumentEvent} from '@sanity/sdk'
19
- import {DocumentHandle} from '@sanity/sdk'
18
+ import {DocumentHandle as DocumentHandle_2} from '@sanity/sdk'
20
19
  import {DocumentOptions} from '@sanity/sdk'
21
20
  import {DocumentPermissionsResult} from '@sanity/sdk'
22
- import {DocumentSource} from '@sanity/sdk'
21
+ import {DocumentResource} from '@sanity/sdk'
22
+ import {DocumentTypeHandle as DocumentTypeHandle_2} from '@sanity/sdk'
23
23
  import {FallbackProps} from 'react-error-boundary'
24
24
  import {FavoriteStatusResponse} from '@sanity/sdk'
25
25
  import {FrameMessage} from '@sanity/sdk'
@@ -27,9 +27,15 @@ import {GetUserOptions} from '@sanity/sdk'
27
27
  import {GetUsersOptions} from '@sanity/sdk'
28
28
  import {JsonMatch} from '@sanity/sdk'
29
29
  import {MediaResource} from '@sanity/message-protocol'
30
+ import {Organization} from '@sanity/sdk'
31
+ import {OrganizationOptions} from '@sanity/sdk'
32
+ import {Organizations} from '@sanity/sdk'
33
+ import {OrganizationsOptions} from '@sanity/sdk'
30
34
  import {PathChangeMessage} from '@sanity/message-protocol'
31
35
  import {PreviewValue} from '@sanity/sdk'
32
- import {ProjectHandle} from '@sanity/sdk'
36
+ import {Project} from '@sanity/sdk'
37
+ import {ProjectOptions} from '@sanity/sdk'
38
+ import {ProjectsOptions} from '@sanity/sdk'
33
39
  import {PropsWithChildren} from 'react'
34
40
  import {QueryOptions} from '@sanity/sdk'
35
41
  import {default as React_2} from 'react'
@@ -41,8 +47,6 @@ import {SanityConfig} from '@sanity/sdk'
41
47
  import {SanityDocument} from '@sanity/types'
42
48
  import {SanityDocument as SanityDocument_2} from 'groq'
43
49
  import {SanityInstance} from '@sanity/sdk'
44
- import {SanityProject} from '@sanity/sdk'
45
- import {SanityProject as SanityProject_2} from '@sanity/client'
46
50
  import {SanityProjectionResult} from 'groq'
47
51
  import {SanityProjectMember} from '@sanity/client'
48
52
  import {SanityQueryResult} from 'groq'
@@ -177,6 +181,22 @@ declare interface DispatchIntent {
177
181
  dispatchIntent: () => void
178
182
  }
179
183
 
184
+ /**
185
+ * React SDK document handle. Adds `resourceName` to the core `DocumentHandle`.
186
+ *
187
+ * Import from `@sanity/sdk-react` (not `@sanity/sdk`) when writing option types
188
+ * for hooks — this version understands `resourceName` resolution.
189
+ *
190
+ * @public
191
+ */
192
+ export declare interface DocumentHandle<
193
+ TDocumentType extends string = string,
194
+ TDataset extends string = string,
195
+ TProjectId extends string = string,
196
+ > extends DocumentHandle_2<TDocumentType, TDataset, TProjectId> {
197
+ resourceName?: string
198
+ }
199
+
180
200
  declare interface DocumentInteractionHistory {
181
201
  recordEvent: (eventType: 'viewed' | 'edited' | 'created' | 'deleted') => void
182
202
  }
@@ -192,7 +212,7 @@ export declare interface DocumentsOptions<
192
212
  TDataset extends string = string,
193
213
  TProjectId extends string = string,
194
214
  >
195
- extends DatasetHandle<TDataset, TProjectId>, Pick<QueryOptions, 'perspective' | 'params'> {
215
+ extends ResourceHandle<TDataset, TProjectId>, Pick<QueryOptions, 'perspective' | 'params'> {
196
216
  /**
197
217
  * Filter documents by their `_type`. Can be a single type or an array of types.
198
218
  */
@@ -230,7 +250,7 @@ export declare interface DocumentsResponse<
230
250
  /**
231
251
  * Array of document handles for the current batch
232
252
  */
233
- data: DocumentHandle<TDocumentType, TDataset, TProjectId>[]
253
+ data: DocumentHandle_2<TDocumentType, TDataset, TProjectId>[]
234
254
  /**
235
255
  * Whether there are more items available to load
236
256
  */
@@ -249,6 +269,18 @@ export declare interface DocumentsResponse<
249
269
  loadMore: () => void
250
270
  }
251
271
 
272
+ /**
273
+ * React SDK document-type handle. Adds `resourceName` to the core `DocumentTypeHandle`.
274
+ * @public
275
+ */
276
+ export declare interface DocumentTypeHandle<
277
+ TDocumentType extends string = string,
278
+ TDataset extends string = string,
279
+ TProjectId extends string = string,
280
+ > extends DocumentTypeHandle_2<TDocumentType, TDataset, TProjectId> {
281
+ resourceName?: string
282
+ }
283
+
252
284
  /**
253
285
  * @internal
254
286
  */
@@ -328,7 +360,9 @@ export declare interface PaginatedDocumentsOptions<
328
360
  TDocumentType extends string = string,
329
361
  TDataset extends string = string,
330
362
  TProjectId extends string = string,
331
- > extends Omit<QueryOptions<TDocumentType, TDataset, TProjectId>, 'query'> {
363
+ > extends WithResourceNameSupport<
364
+ Omit<QueryOptions<TDocumentType, TDataset, TProjectId>, 'query'>
365
+ > {
332
366
  documentType?: TDocumentType | TDocumentType[]
333
367
  /**
334
368
  * GROQ filter expression to apply to the query
@@ -363,7 +397,7 @@ export declare interface PaginatedDocumentsResponse<
363
397
  /**
364
398
  * Array of document handles for the current page
365
399
  */
366
- data: DocumentHandle<TDocumentType, TDataset, TProjectId>[]
400
+ data: DocumentHandle_2<TDocumentType, TDataset, TProjectId>[]
367
401
  /**
368
402
  * Whether a query is currently in progress
369
403
  */
@@ -435,8 +469,9 @@ export declare interface PaginatedDocumentsResponse<
435
469
  * @public
436
470
  * @category Types
437
471
  * @interface
472
+ * @deprecated use the Project type directly.
438
473
  */
439
- export declare type ProjectWithoutMembers = Omit<SanityProject_2, 'members'>
474
+ export declare type ProjectWithoutMembers = Project
440
475
 
441
476
  /**
442
477
  * This version is provided by pkg-utils at build time
@@ -457,53 +492,46 @@ declare interface RenderSanitySDKAppOptions {
457
492
  }
458
493
 
459
494
  /**
460
- * Provides a Sanity instance to child components through React Context
495
+ * React SDK resource handle extends the core DatasetHandle with `resourceName`
496
+ * for context-based resource resolution.
461
497
  *
462
- * @internal
498
+ * Use this (or its subtypes) as the options type for custom hooks that need to
499
+ * accept a resource. It accepts a `resource` object, a `resourceName` registered
500
+ * via the `resources` prop on `<SanityApp>`, or a bare `projectId`/`dataset` pair
501
+ * for backward compatibility.
463
502
  *
464
- * @remarks
465
- * The ResourceProvider creates a hierarchical structure of Sanity instances:
466
- * - When used as a root provider, it creates a new Sanity instance with the given config
467
- * - When nested inside another ResourceProvider, it creates a child instance that
468
- * inherits and extends the parent's configuration
469
- *
470
- * Features:
471
- * - Automatically manages the lifecycle of Sanity instances
472
- * - Disposes instances when the component unmounts
473
- * - Includes a Suspense boundary for data loading
474
- * - Enables hierarchical configuration inheritance
503
+ * @public
504
+ */
505
+ export declare interface ResourceHandle<
506
+ TDataset extends string = string,
507
+ TProjectId extends string = string,
508
+ > extends DatasetHandle<TDataset, TProjectId> {
509
+ /**
510
+ * Name of a resource registered via the `resources` prop on `<SanityApp>`.
511
+ * Resolved to a `DocumentResource` at the React layer.
512
+ */
513
+ resourceName?: string
514
+ }
515
+
516
+ /**
517
+ * Provides Sanity configuration to child components through React Context.
475
518
  *
476
- * Use this component to:
477
- * - Set up project/dataset configuration for an application
478
- * - Override specific configuration values in a section of your app
479
- * - Create isolated instance hierarchies for different features
519
+ * @internal
480
520
  *
481
- * @example Creating a root provider
521
+ * @example
482
522
  * ```tsx
483
523
  * <ResourceProvider
484
- * projectId="your-project-id"
485
- * dataset="production"
524
+ * resource={{ projectId: 'your-project-id', dataset: 'production' }}
486
525
  * fallback={<LoadingSpinner />}
487
526
  * >
488
527
  * <YourApp />
489
528
  * </ResourceProvider>
490
529
  * ```
491
- *
492
- * @example Creating nested providers with configuration inheritance
493
- * ```tsx
494
- * // Root provider with production config with nested provider for preview features with custom dataset
495
- * <ResourceProvider projectId="abc123" dataset="production" fallback={<Loading />}>
496
- * <div>...Main app content</div>
497
- * <Dashboard />
498
- * <ResourceProvider dataset="preview" fallback={<Loading />}>
499
- * <PreviewFeatures />
500
- * </ResourceProvider>
501
- * </ResourceProvider>
502
- * ```
503
530
  */
504
531
  export declare function ResourceProvider({
505
532
  children,
506
533
  fallback,
534
+ resource,
507
535
  ...config
508
536
  }: ResourceProviderProps): React.ReactNode
509
537
 
@@ -513,8 +541,14 @@ export declare function ResourceProvider({
513
541
  */
514
542
  export declare interface ResourceProviderProps extends SanityConfig {
515
543
  /**
516
- * React node to show while content is loading
517
- * Used as the fallback for the internal Suspense boundary
544
+ * The document resource (project/dataset, media library, or canvas)
545
+ * for this subtree. Hooks that don't specify an explicit resource will
546
+ * use this value.
547
+ */
548
+ resource?: DocumentResource
549
+ /**
550
+ * React node to show while content is loading.
551
+ * Used as the fallback for the internal Suspense boundary.
518
552
  */
519
553
  fallback: React.ReactNode
520
554
  children: React.ReactNode
@@ -605,21 +639,80 @@ export declare interface SanityAppProps {
605
639
  config?: SanityConfig | SanityConfig[]
606
640
  /** @deprecated use the `config` prop instead. */
607
641
  sanityConfigs?: SanityConfig[]
608
- sources?: Record<string, DocumentSource>
642
+ resources?: Record<string, DocumentResource>
609
643
  children: React.ReactNode
610
644
  fallback: React.ReactNode
611
645
  }
612
646
 
613
647
  export {SanityDocument}
614
648
 
649
+ /**
650
+ * Provides an externally-created Sanity instance to child components through React Context.
651
+ *
652
+ * @internal
653
+ *
654
+ * @remarks
655
+ * Unlike {@link ResourceProvider}, this component does not create or dispose a SanityInstance.
656
+ * The caller is responsible for creating the instance via `createSanityInstance` and disposing
657
+ * it when appropriate. This is useful when a non-React system layer (e.g. a state machine)
658
+ * owns the instance and the React tree should consume it without managing its lifecycle.
659
+ *
660
+ * All SDK hooks (`useSanityInstance`, `useDocuments`, etc.) will read from the provided instance.
661
+ *
662
+ * @example Providing a pre-created instance
663
+ * ```tsx
664
+ * import { createSanityInstance, type SanityConfig } from '@sanity/sdk'
665
+ * import { SanityInstanceProvider } from '@sanity/sdk-react'
666
+ *
667
+ * const config: SanityConfig = {
668
+ * projectId: 'my-project-id',
669
+ * dataset: 'production',
670
+ * }
671
+ *
672
+ * const instance = createSanityInstance(config)
673
+ *
674
+ * function App() {
675
+ * return (
676
+ * <SanityInstanceProvider instance={instance} fallback={<div>Loading...</div>}>
677
+ * <MyApp />
678
+ * </SanityInstanceProvider>
679
+ * )
680
+ * }
681
+ * ```
682
+ *
683
+ * @category Components
684
+ */
685
+ export declare function SanityInstanceProvider({
686
+ instance,
687
+ fallback,
688
+ children,
689
+ }: SanityInstanceProviderProps): React.ReactNode
690
+
691
+ /**
692
+ * Props for the SanityInstanceProvider component
693
+ * @public
694
+ */
695
+ export declare interface SanityInstanceProviderProps {
696
+ /**
697
+ * A pre-created SanityInstance to provide to child components.
698
+ * The caller owns the instance lifecycle — SanityInstanceProvider
699
+ * will not dispose it on unmount.
700
+ */
701
+ instance: SanityInstance
702
+ /**
703
+ * React node to show while content is loading.
704
+ * Used as the fallback for the internal Suspense boundary.
705
+ */
706
+ fallback: React.ReactNode
707
+ children: React.ReactNode
708
+ }
709
+
615
710
  export {SanityProjectMember}
616
711
 
617
712
  /**
618
713
  * @internal
619
714
  *
620
715
  * Top-level context provider that provides access to the Sanity SDK.
621
- * Creates a hierarchy of ResourceProviders, each providing a SanityInstance that can be
622
- * accessed by hooks. The first configuration in the array becomes the default instance.
623
716
  */
624
717
  export declare function SDKProvider({
625
718
  children,
@@ -635,7 +728,7 @@ export declare interface SDKProviderProps extends AuthBoundaryProps {
635
728
  children: ReactNode
636
729
  config: SanityConfig | SanityConfig[]
637
730
  fallback: ReactNode
638
- sources?: Record<string, DocumentSource>
731
+ resources?: Record<string, DocumentResource>
639
732
  }
640
733
 
641
734
  /**
@@ -728,30 +821,13 @@ declare interface Subscription {
728
821
 
729
822
  declare type Updater<TValue> = TValue | ((currentValue: TValue) => TValue)
730
823
 
731
- /**
732
- * @public
733
-
734
- * Returns the active releases for the current project,
735
- * represented as a list of release documents.
736
- *
737
- * @returns The active releases for the current project.
738
- * @category Projects
739
- * @example
740
- * ```tsx
741
- * import {useActiveReleases} from '@sanity/sdk-react'
742
- *
743
- * const activeReleases = useActiveReleases()
744
- * ```
745
- */
746
- declare type UseActiveReleases = {
747
- (options?: WithSourceNameSupport<SanityConfig> | undefined): ReleaseDocument[]
748
- }
749
-
750
824
  /**
751
825
  * @public
752
826
  * @function
753
827
  */
754
- export declare const useActiveReleases: UseActiveReleases
828
+ export declare function useActiveReleases(
829
+ options?: WithResourceNameSupport<SanityConfig> | undefined,
830
+ ): ReleaseDocument[]
755
831
 
756
832
  /**
757
833
  * @alpha
@@ -820,9 +896,9 @@ export declare const useActiveReleases: UseActiveReleases
820
896
  *
821
897
  * @category Agent Actions
822
898
  */
823
- export declare const useAgentGenerate: () => (
824
- options: AgentGenerateOptions,
825
- ) => Subscribable<unknown>
899
+ export declare function useAgentGenerate(
900
+ resourceHandle?: ResourceHandle,
901
+ ): (options: AgentGenerateOptions) => Subscribable<unknown>
826
902
 
827
903
  /**
828
904
  * @alpha
@@ -973,7 +1049,9 @@ export declare const useAgentGenerate: () => (
973
1049
  *
974
1050
  * @category Agent Actions
975
1051
  */
976
- export declare const useAgentPatch: () => (options: AgentPatchOptions) => Promise<AgentPatchResult>
1052
+ export declare function useAgentPatch(
1053
+ resourceHandle?: ResourceHandle,
1054
+ ): (options: AgentPatchOptions) => Promise<AgentPatchResult>
977
1055
 
978
1056
  /**
979
1057
  * @alpha
@@ -1069,9 +1147,9 @@ export declare const useAgentPatch: () => (options: AgentPatchOptions) => Promis
1069
1147
  *
1070
1148
  * @category Agent Actions
1071
1149
  */
1072
- export declare const useAgentPrompt: () => (
1073
- options: AgentPromptOptions,
1074
- ) => Promise<AgentPromptResult>
1150
+ export declare function useAgentPrompt(
1151
+ resourceHandle?: ResourceHandle,
1152
+ ): (options: AgentPromptOptions) => Promise<AgentPromptResult>
1075
1153
 
1076
1154
  /**
1077
1155
  * @public
@@ -1176,9 +1254,9 @@ export declare function useAgentResourceContext(options: AgentResourceContextOpt
1176
1254
  *
1177
1255
  * @category Agent Actions
1178
1256
  */
1179
- export declare const useAgentTransform: () => (
1180
- options: AgentTransformOptions,
1181
- ) => Subscribable<unknown>
1257
+ export declare function useAgentTransform(
1258
+ resourceHandle?: ResourceHandle,
1259
+ ): (options: AgentTransformOptions) => Subscribable<unknown>
1182
1260
 
1183
1261
  /**
1184
1262
  * @alpha
@@ -1270,9 +1348,9 @@ export declare const useAgentTransform: () => (
1270
1348
  *
1271
1349
  * @category Agent Actions
1272
1350
  */
1273
- export declare const useAgentTranslate: () => (
1274
- options: AgentTranslateOptions,
1275
- ) => Subscribable<unknown>
1351
+ export declare function useAgentTranslate(
1352
+ resourceHandle?: ResourceHandle,
1353
+ ): (options: AgentTranslateOptions) => Subscribable<unknown>
1276
1354
 
1277
1355
  /**
1278
1356
  * @public
@@ -1286,7 +1364,7 @@ declare interface UseApplyDocumentActions {
1286
1364
  action:
1287
1365
  | DocumentAction<TDocumentType, TDataset, TProjectId>
1288
1366
  | DocumentAction<TDocumentType, TDataset, TProjectId>[],
1289
- options?: WithSourceNameSupport<ApplyDocumentActionsOptions>,
1367
+ options?: ResourceHandle,
1290
1368
  ) => Promise<ActionsResult<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>>>
1291
1369
  }
1292
1370
 
@@ -1674,8 +1752,8 @@ export declare const useDatasets: UseDatasets
1674
1752
  * - `action` - Action to perform (currently only 'edit' is supported). Will prompt a picker if multiple handlers are available.
1675
1753
  * - `intentId` - Specific ID of the intent to dispatch. Either `action` or `intentId` is required.
1676
1754
  * - `documentHandle` - The document handle containing document ID, type, and either:
1677
- * - `projectId` and `dataset` for traditional dataset sources, like `{documentId: '123', documentType: 'book', projectId: 'abc123', dataset: 'production'}`
1678
- * - `source` for media library, canvas, or dataset sources, like `{documentId: '123', documentType: 'sanity.asset', source: mediaLibrarySource('ml123')}` or `{documentId: '123', documentType: 'sanity.canvas.document', source: canvasSource('canvas123')}`
1755
+ * - `projectId` and `dataset` for traditional dataset resources, like `{documentId: '123', documentType: 'book', projectId: 'abc123', dataset: 'production'}`
1756
+ * - `resource` for media library, canvas, or dataset resources, like `{documentId: '123', documentType: 'sanity.asset', resource: mediaLibrarySource('ml123')}` or `{documentId: '123', documentType: 'sanity.canvas.document', resource: canvasSource('canvas123')}`
1679
1757
  * - `paremeters` - Optional parameters to include in the dispatch; will be passed to the resolved intent handler
1680
1758
  * @returns An object containing:
1681
1759
  * - `dispatchIntent` - Function to dispatch the intent message
@@ -1724,7 +1802,7 @@ export declare function useDispatchIntent(params: UseDispatchIntentParams): Disp
1724
1802
  declare interface UseDispatchIntentParams {
1725
1803
  action?: 'edit'
1726
1804
  intentId?: string
1727
- documentHandle: WithSourceNameSupport<DocumentHandle>
1805
+ documentHandle: DocumentHandle
1728
1806
  parameters?: Record<string, unknown>
1729
1807
  }
1730
1808
 
@@ -2000,7 +2078,7 @@ export declare function useDocumentEvent<
2000
2078
  declare interface UseDocumentEventOptions<
2001
2079
  TDataset extends string = string,
2002
2080
  TProjectId extends string = string,
2003
- > extends DatasetHandle<TDataset, TProjectId> {
2081
+ > extends ResourceHandle<TDataset, TProjectId> {
2004
2082
  onEvent: (documentEvent: DocumentEvent) => void
2005
2083
  }
2006
2084
 
@@ -2009,7 +2087,9 @@ declare type UseDocumentOptions<
2009
2087
  TDocumentType extends string = string,
2010
2088
  TDataset extends string = string,
2011
2089
  TProjectId extends string = string,
2012
- > = WithSourceNameSupport<DocumentOptions<TPath, TDocumentType, TDataset, TProjectId>>
2090
+ > = DocumentHandle<TDocumentType, TDataset, TProjectId> & {
2091
+ path?: TPath
2092
+ }
2013
2093
 
2014
2094
  /**
2015
2095
  *
@@ -2089,7 +2169,9 @@ declare type UseDocumentOptions<
2089
2169
  * ```
2090
2170
  */
2091
2171
  export declare function useDocumentPermissions(
2092
- actionOrActions: DocumentAction | DocumentAction[],
2172
+ actionOrActions:
2173
+ | WithResourceNameSupport<DocumentAction>
2174
+ | WithResourceNameSupport<DocumentAction>[],
2093
2175
  ): DocumentPermissionsResult
2094
2176
 
2095
2177
  /**
@@ -2157,7 +2239,7 @@ export declare function useDocumentPreview({
2157
2239
  * @public
2158
2240
  * @category Types
2159
2241
  */
2160
- export declare interface useDocumentPreviewOptions extends WithSourceNameSupport<DocumentHandle> {
2242
+ export declare interface useDocumentPreviewOptions extends DocumentHandle {
2161
2243
  /**
2162
2244
  * Optional ref object to track visibility. When provided, preview resolution
2163
2245
  * only occurs when the referenced element is visible in the viewport.
@@ -2318,7 +2400,7 @@ export declare interface useDocumentProjectionOptions<
2318
2400
  TDocumentType extends string = string,
2319
2401
  TDataset extends string = string,
2320
2402
  TProjectId extends string = string,
2321
- > extends WithSourceNameSupport<DocumentHandle<TDocumentType, TDataset, TProjectId>> {
2403
+ > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
2322
2404
  /** The GROQ projection string */
2323
2405
  projection: TProjection
2324
2406
  /** Optional parameters for the projection query */
@@ -2458,7 +2540,7 @@ export declare function useDocuments<
2458
2540
  filter,
2459
2541
  orderings,
2460
2542
  documentType,
2461
- ...options
2543
+ ...rawOptions
2462
2544
  }: DocumentsOptions<TDocumentType, TDataset, TProjectId>): DocumentsResponse<
2463
2545
  TDocumentType,
2464
2546
  TDataset,
@@ -2498,7 +2580,7 @@ declare type UseDocumentSyncStatus = {
2498
2580
  * // <SyncIndicator doc={doc} />
2499
2581
  * ```
2500
2582
  */
2501
- (doc: DocumentHandle): boolean
2583
+ (doc: DocumentHandle_2): boolean
2502
2584
  }
2503
2585
 
2504
2586
  /**
@@ -2710,7 +2792,7 @@ export declare function useManageFavorite({
2710
2792
  schemaName,
2711
2793
  }: UseManageFavoriteProps): ManageFavorite
2712
2794
 
2713
- declare interface UseManageFavoriteProps extends DocumentHandle {
2795
+ declare interface UseManageFavoriteProps extends DocumentHandle_2 {
2714
2796
  resourceId?: string
2715
2797
  resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
2716
2798
  /**
@@ -2765,10 +2847,75 @@ declare interface UseManageFavoriteProps extends DocumentHandle {
2765
2847
  * ```
2766
2848
  */
2767
2849
  export declare function useNavigateToStudioDocument(
2768
- documentHandle: DocumentHandle,
2850
+ documentHandle: DocumentHandle_2,
2769
2851
  preferredStudioUrl?: string,
2770
2852
  ): NavigateToStudioResult
2771
2853
 
2854
+ /**
2855
+ * Returns metadata for a given organisation.
2856
+ *
2857
+ * @category Organizations
2858
+ * @param options - Configuration options
2859
+ * @returns The metadata for the organisation. `members` is included only when
2860
+ * `includeMembers: true`; `features` is included only when `includeFeatures: true`.
2861
+ * @example
2862
+ * ```tsx
2863
+ * function OrganizationName({organizationId}: {organizationId: string}) {
2864
+ * const organization = useOrganization({organizationId})
2865
+ *
2866
+ * return <h1>{organization.name}</h1>
2867
+ * }
2868
+ * ```
2869
+ * @example
2870
+ * ```tsx
2871
+ * const organizationWithMembers = useOrganization({organizationId, includeMembers: true})
2872
+ * const organizationWithFeatures = useOrganization({organizationId, includeFeatures: true})
2873
+ * ```
2874
+ * @public
2875
+ * @function
2876
+ */
2877
+ export declare const useOrganization: <
2878
+ IncludeMembers extends boolean = false,
2879
+ IncludeFeatures extends boolean = false,
2880
+ >(
2881
+ options: OrganizationOptions<IncludeMembers, IncludeFeatures>,
2882
+ ) => Organization<IncludeMembers, IncludeFeatures>
2883
+
2884
+ /**
2885
+ * Returns metadata for each organisation the current user has access to.
2886
+ *
2887
+ * @category Organizations
2888
+ * @param options - Configuration options
2889
+ * @returns An array of organisation metadata. `members` is included only when
2890
+ * `includeMembers: true`; `features` is included only when `includeFeatures: true`.
2891
+ * @example
2892
+ * ```tsx
2893
+ * const organizations = useOrganizations()
2894
+ *
2895
+ * return (
2896
+ * <select>
2897
+ * {organizations.map((organization) => (
2898
+ * <option key={organization.id}>{organization.name}</option>
2899
+ * ))}
2900
+ * </select>
2901
+ * )
2902
+ * ```
2903
+ * @example
2904
+ * ```tsx
2905
+ * const organizationsWithMembers = useOrganizations({includeMembers: true})
2906
+ * const organizationsWithFeatures = useOrganizations({includeFeatures: true})
2907
+ * const organizationsIncludingImplicit = useOrganizations({includeImplicitMemberships: true})
2908
+ * ```
2909
+ * @public
2910
+ * @function
2911
+ */
2912
+ export declare const useOrganizations: <
2913
+ IncludeMembers extends boolean = false,
2914
+ IncludeFeatures extends boolean = false,
2915
+ >(
2916
+ options?: OrganizationsOptions<IncludeMembers, IncludeFeatures>,
2917
+ ) => Organizations<IncludeMembers, IncludeFeatures>
2918
+
2772
2919
  /**
2773
2920
  * Retrieves pages of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,
2774
2921
  * with support for traditional paginated interfaces. The number of document handles returned per page is customizable,
@@ -2875,7 +3022,7 @@ export declare function usePaginatedDocuments<
2875
3022
  params,
2876
3023
  orderings,
2877
3024
  search,
2878
- ...options
3025
+ ...rawOptions
2879
3026
  }: PaginatedDocumentsOptions<TDocumentType, TDataset, TProjectId>): PaginatedDocumentsResponse<
2880
3027
  TDocumentType,
2881
3028
  TDataset,
@@ -2885,88 +3032,60 @@ export declare function usePaginatedDocuments<
2885
3032
  /**
2886
3033
  * @public
2887
3034
  * @function
2888
- *
2889
- * Returns a single or stack of perspectives for the given perspective handle,
2890
- * which can then be used to correctly query the documents
2891
- * via the `perspective` parameter in the client.
2892
- *
2893
- * @param perspectiveHandle - The perspective handle to get the perspective for.
2894
- * @category Documents
2895
- * @example
2896
- * ```tsx
2897
- * import {usePerspective, useQuery} from '@sanity/sdk-react'
2898
-
2899
- * const perspective = usePerspective({perspective: 'rxg1346', projectId: 'abc123', dataset: 'production'})
2900
- * const {data} = useQuery<Movie[]>('*[_type == "movie"]', {
2901
- * perspective: perspective,
2902
- * })
2903
- * ```
2904
- *
2905
- * @returns The perspective for the given perspective handle.
2906
3035
  */
2907
- declare type UsePerspective = {
2908
- (perspectiveHandle: DatasetHandle): string | string[]
2909
- }
3036
+ export declare function usePerspective(perspectiveHandle?: ResourceHandle): string | string[]
2910
3037
 
2911
3038
  /**
3039
+ * A hook for subscribing to presence information for the current project or Canvas.
2912
3040
  * @public
2913
- * @function
2914
3041
  */
2915
- export declare const usePerspective: UsePerspective
2916
-
2917
- /**
2918
- * A hook for subscribing to presence information for the current project.
2919
- * @public
2920
- */
2921
- export declare function usePresence(): {
3042
+ export declare function usePresence(options?: ResourceHandle): {
2922
3043
  locations: UserPresence[]
2923
3044
  }
2924
3045
 
2925
- declare type UseProject = {
2926
- /**
2927
- *
2928
- * Returns metadata for a given project
2929
- *
2930
- * @category Projects
2931
- * @param projectId - The ID of the project to retrieve metadata for
2932
- * @returns The metadata for the project
2933
- * @example
2934
- * ```tsx
2935
- * function ProjectMetadata({ projectId }: { projectId: string }) {
2936
- * const project = useProject(projectId)
2937
- *
2938
- * return (
2939
- * <figure style={{ backgroundColor: project.metadata.color || 'lavender'}}>
2940
- * <h1>{project.displayName}</h1>
2941
- * </figure>
2942
- * )
2943
- * }
2944
- * ```
2945
- */
2946
- (projectHandle?: ProjectHandle): SanityProject
2947
- }
2948
-
2949
3046
  /**
3047
+ * Returns metadata for a given project.
3048
+ *
3049
+ * @category Projects
3050
+ * @param options - Configuration options
3051
+ * @returns The metadata for the project. `members` is included only when
3052
+ * `includeMembers: true`; `features` is included unless `includeFeatures: false`.
3053
+ * @example
3054
+ * ```tsx
3055
+ * function ProjectMetadata({projectId}: {projectId: string}) {
3056
+ * const project = useProject({projectId})
3057
+ *
3058
+ * return (
3059
+ * <figure style={{backgroundColor: project.metadata.color || 'lavender'}}>
3060
+ * <h1>{project.displayName}</h1>
3061
+ * </figure>
3062
+ * )
3063
+ * }
3064
+ * ```
3065
+ * @example
3066
+ * ```tsx
3067
+ * const projectWithMembersAndFeatures = useProject({projectId})
3068
+ * const projectWithMembers = useProject({projectId, includeMembers: true})
3069
+ * const projectWithoutMembers = useProject({projectId, includeMembers: false})
3070
+ * const projectWithoutFeatures = useProject({projectId, includeFeatures: false})
3071
+ * ```
2950
3072
  * @public
2951
3073
  * @function
2952
3074
  */
2953
- export declare const useProject: UseProject
2954
-
2955
- /**
2956
- * @public
2957
- * @category Types
2958
- */
2959
- declare type UseProjects = <TIncludeMembers extends boolean = false>(options?: {
2960
- organizationId?: string
2961
- includeMembers?: TIncludeMembers
2962
- }) => TIncludeMembers extends true ? SanityProject_2[] : ProjectWithoutMembers[]
3075
+ export declare const useProject: <
3076
+ IncludeMembers extends boolean = true,
3077
+ IncludeFeatures extends boolean = true,
3078
+ >(
3079
+ options?: ProjectOptions<IncludeMembers, IncludeFeatures>,
3080
+ ) => Project<IncludeMembers, IncludeFeatures>
2963
3081
 
2964
3082
  /**
2965
3083
  * Returns metadata for each project you have access to.
2966
3084
  *
2967
3085
  * @category Projects
2968
3086
  * @param options - Configuration options
2969
- * @returns An array of project metadata. If includeMembers is true, returns full SanityProject objects. Otherwise, returns ProjectWithoutMembers objects.
3087
+ * @returns An array of project metadata. `members` is included only when
3088
+ * `includeMembers: true`; `features` is included unless `includeFeatures: false`.
2970
3089
  * @example
2971
3090
  * ```tsx
2972
3091
  * const projects = useProjects()
@@ -2981,13 +3100,21 @@ declare type UseProjects = <TIncludeMembers extends boolean = false>(options?: {
2981
3100
  * ```
2982
3101
  * @example
2983
3102
  * ```tsx
2984
- * const projectsWithMembers = useProjects({ includeMembers: true })
2985
- * const projectsWithoutMembers = useProjects({ includeMembers: false })
3103
+ * const projects = useProjects()
3104
+ * const projectsWithFeatures = useProjects()
3105
+ * const projectsWithMembers = useProjects({includeMembers: true})
3106
+ * const projectsWithoutMembers = useProjects({includeMembers: false})
3107
+ * const projectsWithoutFeatures = useProjects({includeFeatures: false})
2986
3108
  * ```
2987
3109
  * @public
2988
3110
  * @function
2989
3111
  */
2990
- export declare const useProjects: UseProjects
3112
+ export declare const useProjects: <
3113
+ IncludeMembers extends boolean = false,
3114
+ IncludeFeatures extends boolean = true,
3115
+ >(
3116
+ options?: ProjectsOptions<IncludeMembers, IncludeFeatures>,
3117
+ ) => Project<IncludeMembers, IncludeFeatures>[]
2991
3118
 
2992
3119
  /**
2993
3120
  * @public
@@ -3085,7 +3212,7 @@ export declare function useQuery<
3085
3212
  * }
3086
3213
  * ```
3087
3214
  */
3088
- export declare function useQuery<TData>(options: WithSourceNameSupport<QueryOptions>): {
3215
+ export declare function useQuery<TData>(options: WithResourceNameSupport<QueryOptions>): {
3089
3216
  /** The query result, cast to the provided type TData */
3090
3217
  data: TData
3091
3218
  /** True if another query is resolving in the background (suspense handles the initial loading state) */
@@ -3093,14 +3220,14 @@ export declare function useQuery<TData>(options: WithSourceNameSupport<QueryOpti
3093
3220
  }
3094
3221
 
3095
3222
  /**
3096
- * Hook options for useQuery, supporting both direct source and sourceName.
3223
+ * Hook options for useQuery, supporting both direct resource and resourceName.
3097
3224
  * @beta
3098
3225
  */
3099
3226
  declare type UseQueryOptions<
3100
3227
  TQuery extends string = string,
3101
3228
  TDataset extends string = string,
3102
3229
  TProjectId extends string = string,
3103
- > = WithSourceNameSupport<QueryOptions<TQuery, TDataset, TProjectId>>
3230
+ > = WithResourceNameSupport<QueryOptions<TQuery, TDataset, TProjectId>>
3104
3231
 
3105
3232
  /**
3106
3233
  * @internal
@@ -3154,7 +3281,7 @@ export declare function useRecordDocumentHistoryEvent({
3154
3281
  /**
3155
3282
  * @internal
3156
3283
  */
3157
- declare interface UseRecordDocumentHistoryEventProps extends DocumentHandle {
3284
+ declare interface UseRecordDocumentHistoryEventProps extends DocumentHandle_2 {
3158
3285
  resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
3159
3286
  resourceId?: string
3160
3287
  /**
@@ -3164,6 +3291,25 @@ declare interface UseRecordDocumentHistoryEventProps extends DocumentHandle {
3164
3291
  schemaName?: string
3165
3292
  }
3166
3293
 
3294
+ /**
3295
+ * Returns the currently active `DocumentResource` for the nearest resource context.
3296
+ *
3297
+ * Resolves in priority order:
3298
+ * 1. A `resource` prop on the nearest `<ResourceProvider>`
3299
+ * 2. The `projectId`/`dataset` from the current `SanityInstance` config
3300
+ * 3. `undefined` when neither is available
3301
+ *
3302
+ * @public
3303
+ * @category Platform
3304
+ *
3305
+ * @example
3306
+ * ```tsx
3307
+ * const resource = useResource()
3308
+ * console.log(resource?.projectId, resource?.dataset)
3309
+ * ```
3310
+ */
3311
+ export declare function useResource(): DocumentResource | undefined
3312
+
3167
3313
  /**
3168
3314
  * @public
3169
3315
  * @category Types
@@ -3203,60 +3349,33 @@ export declare interface UsersResult {
3203
3349
  }
3204
3350
 
3205
3351
  /**
3206
- * Retrieves the current Sanity instance or finds a matching instance from the hierarchy
3352
+ * Retrieves the current Sanity instance from context
3207
3353
  *
3208
3354
  * @public
3209
3355
  *
3210
3356
  * @category Platform
3211
- * @param config - Optional configuration to match against when finding an instance
3212
- * @returns The current or matching Sanity instance
3357
+ * @param config - Deprecated. Formerly used to match against the instance hierarchy.
3358
+ * @returns The current Sanity instance
3213
3359
  *
3214
3360
  * @remarks
3215
- * This hook accesses the nearest Sanity instance from the React context. When provided with
3216
- * a configuration object, it traverses up the instance hierarchy to find the closest instance
3217
- * that matches the specified configuration using shallow comparison of properties.
3218
- *
3361
+ * This hook accesses the nearest Sanity instance from the React context.
3219
3362
  * The hook must be used within a component wrapped by a `ResourceProvider` or `SanityApp`.
3220
3363
  *
3221
- * Use this hook when you need to:
3222
- * - Access the current SanityInstance from context
3223
- * - Find a specific instance with matching project/dataset configuration
3224
- * - Access a parent instance with specific configuration values
3225
- *
3226
3364
  * @example Get the current instance
3227
3365
  * ```tsx
3228
- * // Get the current instance from context
3229
3366
  * const instance = useSanityInstance()
3230
3367
  * console.log(instance.config.projectId)
3231
3368
  * ```
3232
3369
  *
3233
- * @example Find an instance with specific configuration
3234
- * ```tsx
3235
- * // Find an instance matching the given project and dataset
3236
- * const instance = useSanityInstance({
3237
- * projectId: 'abc123',
3238
- * dataset: 'production'
3239
- * })
3240
- *
3241
- * // Use instance for API calls
3242
- * const fetchDocument = (docId) => {
3243
- * // Instance is guaranteed to have the matching config
3244
- * return client.fetch(`*[_id == $id][0]`, { id: docId })
3245
- * }
3246
- * ```
3247
- *
3248
- * @example Match partial configuration
3249
- * ```tsx
3250
- * // Find an instance with specific auth configuration
3251
- * const instance = useSanityInstance({
3252
- * auth: { requireLogin: true }
3253
- * })
3254
- * ```
3255
- *
3256
3370
  * @throws Error if no SanityInstance is found in context
3257
- * @throws Error if no matching instance is found for the provided config
3258
3371
  */
3259
- export declare const useSanityInstance: (config?: SanityConfig) => SanityInstance
3372
+ export declare const useSanityInstance: (
3373
+ /**
3374
+ * @deprecated Passing a config to match against the instance hierarchy is deprecated.
3375
+ * Use `useSanityInstance()` without arguments instead.
3376
+ */
3377
+ config?: SanityConfig,
3378
+ ) => SanityInstance
3260
3379
 
3261
3380
  /**
3262
3381
  * Hook that fetches studio workspaces and organizes them by projectId:dataset
@@ -3487,23 +3606,27 @@ export declare type WindowMessageHandler<TFrameMessage extends FrameMessage> = (
3487
3606
  ) => TFrameMessage['response']
3488
3607
 
3489
3608
  /**
3490
- * Adds React hook support (sourceName resolution) to core types.
3491
- * This wrapper allows hooks to accept `sourceName` as a convenience,
3492
- * which is then resolved to a `DocumentSource` at the React layer.
3493
- * For now, we are trying to avoid source name resolution in core --
3494
- * functions having sources explicitly passed will reduce complexity.
3609
+ * Adds React hook support (resourceName resolution) to core types.
3610
+ * Prefer using the React-layer handle types (ResourceHandle, DocumentHandle)
3611
+ * from `@sanity/sdk-react` this wrapper is kept for cases where overloads
3612
+ * don't fit (e.g. non-handle options objects).
3495
3613
  *
3496
- * @typeParam T - The core type to extend (must have optional `source` field)
3614
+ * @typeParam T - The core type to extend (must have optional `resource` field)
3497
3615
  * @beta
3498
3616
  */
3499
- declare type WithSourceNameSupport<
3617
+ declare type WithResourceNameSupport<
3500
3618
  T extends {
3501
- source?: DocumentSource
3619
+ resource?: DocumentResource
3502
3620
  },
3503
3621
  > = T & {
3504
3622
  /**
3505
- * Optional name of a source to resolve from context.
3506
- * If provided, will be resolved to a `DocumentSource` via `SourcesContext`.
3623
+ * Optional name of a resource to resolve from context.
3624
+ * If provided, will be resolved to a `DocumentResource` via `ResourcesContext`.
3625
+ * @beta
3626
+ */
3627
+ resourceName?: string
3628
+ /**
3629
+ * @deprecated Use `resourceName` instead.
3507
3630
  * @beta
3508
3631
  */
3509
3632
  sourceName?: string