@sanity/sdk-react 2.10.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 (54) hide show
  1. package/dist/index.d.ts +257 -200
  2. package/dist/index.js +364 -253
  3. package/dist/index.js.map +1 -1
  4. package/package.json +6 -9
  5. package/src/_exports/index.ts +2 -0
  6. package/src/_exports/sdk-react.ts +4 -0
  7. package/src/components/SDKProvider.test.tsx +5 -12
  8. package/src/components/SDKProvider.tsx +26 -24
  9. package/src/config/handles.ts +55 -0
  10. package/src/constants.ts +5 -0
  11. package/src/context/DefaultResourceContext.ts +10 -0
  12. package/src/context/PerspectiveContext.ts +12 -0
  13. package/src/context/ResourceProvider.test.tsx +2 -2
  14. package/src/context/ResourceProvider.tsx +53 -49
  15. package/src/hooks/agent/agentActions.ts +55 -38
  16. package/src/hooks/context/useResource.test.tsx +32 -0
  17. package/src/hooks/context/useResource.ts +24 -0
  18. package/src/hooks/context/useSanityInstance.test.tsx +42 -111
  19. package/src/hooks/context/useSanityInstance.ts +28 -50
  20. package/src/hooks/dashboard/useDispatchIntent.test.ts +5 -1
  21. package/src/hooks/dashboard/useDispatchIntent.ts +3 -3
  22. package/src/hooks/dashboard/useManageFavorite.test.tsx +16 -12
  23. package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.ts +1 -5
  24. package/src/hooks/document/{useApplyDocumentActions.test.ts → useApplyDocumentActions.test.tsx} +42 -77
  25. package/src/hooks/document/useApplyDocumentActions.ts +28 -62
  26. package/src/hooks/document/useDocument.ts +3 -5
  27. package/src/hooks/document/useDocumentEvent.ts +4 -3
  28. package/src/hooks/document/useDocumentPermissions.test.tsx +58 -150
  29. package/src/hooks/document/useDocumentPermissions.ts +78 -55
  30. package/src/hooks/document/useEditDocument.test.tsx +25 -60
  31. package/src/hooks/document/useEditDocument.ts +1 -1
  32. package/src/hooks/documents/useDocuments.ts +13 -8
  33. package/src/hooks/helpers/createStateSourceHook.tsx +1 -2
  34. package/src/hooks/helpers/useNormalizedResourceOptions.test.tsx +253 -0
  35. package/src/hooks/helpers/useNormalizedResourceOptions.ts +85 -47
  36. package/src/hooks/organizations/useOrganization.test-d.ts +53 -0
  37. package/src/hooks/organizations/useOrganization.test.ts +65 -0
  38. package/src/hooks/organizations/useOrganization.ts +40 -0
  39. package/src/hooks/organizations/useOrganizations.test-d.ts +55 -0
  40. package/src/hooks/organizations/useOrganizations.test.ts +85 -0
  41. package/src/hooks/organizations/useOrganizations.ts +45 -0
  42. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +23 -9
  43. package/src/hooks/presence/usePresence.ts +4 -11
  44. package/src/hooks/preview/useDocumentPreview.tsx +4 -7
  45. package/src/hooks/projection/useDocumentProjection.ts +5 -7
  46. package/src/hooks/projects/useProject.test-d.ts +49 -0
  47. package/src/hooks/projects/useProject.ts +33 -41
  48. package/src/hooks/projects/useProjects.test-d.ts +49 -0
  49. package/src/hooks/projects/useProjects.ts +17 -23
  50. package/src/hooks/query/useQuery.ts +1 -1
  51. package/src/hooks/releases/useActiveReleases.ts +6 -6
  52. package/src/hooks/releases/usePerspective.ts +7 -12
  53. package/src/hooks/users/useUser.ts +1 -1
  54. package/src/hooks/users/useUsers.ts +1 -1
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
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
463
- *
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
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.
469
502
  *
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
@@ -679,8 +713,6 @@ export {SanityProjectMember}
679
713
  * @internal
680
714
  *
681
715
  * Top-level context provider that provides access to the Sanity SDK.
682
- * Creates a hierarchy of ResourceProviders, each providing a SanityInstance that can be
683
- * accessed by hooks. The first configuration in the array becomes the default instance.
684
716
  */
685
717
  export declare function SDKProvider({
686
718
  children,
@@ -789,30 +821,13 @@ declare interface Subscription {
789
821
 
790
822
  declare type Updater<TValue> = TValue | ((currentValue: TValue) => TValue)
791
823
 
792
- /**
793
- * @public
794
-
795
- * Returns the active releases for the current project,
796
- * represented as a list of release documents.
797
- *
798
- * @returns The active releases for the current project.
799
- * @category Projects
800
- * @example
801
- * ```tsx
802
- * import {useActiveReleases} from '@sanity/sdk-react'
803
- *
804
- * const activeReleases = useActiveReleases()
805
- * ```
806
- */
807
- declare type UseActiveReleases = {
808
- (options?: WithResourceNameSupport<SanityConfig> | undefined): ReleaseDocument[]
809
- }
810
-
811
824
  /**
812
825
  * @public
813
826
  * @function
814
827
  */
815
- export declare const useActiveReleases: UseActiveReleases
828
+ export declare function useActiveReleases(
829
+ options?: WithResourceNameSupport<SanityConfig> | undefined,
830
+ ): ReleaseDocument[]
816
831
 
817
832
  /**
818
833
  * @alpha
@@ -881,9 +896,9 @@ export declare const useActiveReleases: UseActiveReleases
881
896
  *
882
897
  * @category Agent Actions
883
898
  */
884
- export declare const useAgentGenerate: () => (
885
- options: AgentGenerateOptions,
886
- ) => Subscribable<unknown>
899
+ export declare function useAgentGenerate(
900
+ resourceHandle?: ResourceHandle,
901
+ ): (options: AgentGenerateOptions) => Subscribable<unknown>
887
902
 
888
903
  /**
889
904
  * @alpha
@@ -1034,7 +1049,9 @@ export declare const useAgentGenerate: () => (
1034
1049
  *
1035
1050
  * @category Agent Actions
1036
1051
  */
1037
- export declare const useAgentPatch: () => (options: AgentPatchOptions) => Promise<AgentPatchResult>
1052
+ export declare function useAgentPatch(
1053
+ resourceHandle?: ResourceHandle,
1054
+ ): (options: AgentPatchOptions) => Promise<AgentPatchResult>
1038
1055
 
1039
1056
  /**
1040
1057
  * @alpha
@@ -1130,9 +1147,9 @@ export declare const useAgentPatch: () => (options: AgentPatchOptions) => Promis
1130
1147
  *
1131
1148
  * @category Agent Actions
1132
1149
  */
1133
- export declare const useAgentPrompt: () => (
1134
- options: AgentPromptOptions,
1135
- ) => Promise<AgentPromptResult>
1150
+ export declare function useAgentPrompt(
1151
+ resourceHandle?: ResourceHandle,
1152
+ ): (options: AgentPromptOptions) => Promise<AgentPromptResult>
1136
1153
 
1137
1154
  /**
1138
1155
  * @public
@@ -1237,9 +1254,9 @@ export declare function useAgentResourceContext(options: AgentResourceContextOpt
1237
1254
  *
1238
1255
  * @category Agent Actions
1239
1256
  */
1240
- export declare const useAgentTransform: () => (
1241
- options: AgentTransformOptions,
1242
- ) => Subscribable<unknown>
1257
+ export declare function useAgentTransform(
1258
+ resourceHandle?: ResourceHandle,
1259
+ ): (options: AgentTransformOptions) => Subscribable<unknown>
1243
1260
 
1244
1261
  /**
1245
1262
  * @alpha
@@ -1331,9 +1348,9 @@ export declare const useAgentTransform: () => (
1331
1348
  *
1332
1349
  * @category Agent Actions
1333
1350
  */
1334
- export declare const useAgentTranslate: () => (
1335
- options: AgentTranslateOptions,
1336
- ) => Subscribable<unknown>
1351
+ export declare function useAgentTranslate(
1352
+ resourceHandle?: ResourceHandle,
1353
+ ): (options: AgentTranslateOptions) => Subscribable<unknown>
1337
1354
 
1338
1355
  /**
1339
1356
  * @public
@@ -1347,7 +1364,7 @@ declare interface UseApplyDocumentActions {
1347
1364
  action:
1348
1365
  | DocumentAction<TDocumentType, TDataset, TProjectId>
1349
1366
  | DocumentAction<TDocumentType, TDataset, TProjectId>[],
1350
- options?: WithResourceNameSupport<ApplyDocumentActionsOptions>,
1367
+ options?: ResourceHandle,
1351
1368
  ) => Promise<ActionsResult<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>>>
1352
1369
  }
1353
1370
 
@@ -1785,7 +1802,7 @@ export declare function useDispatchIntent(params: UseDispatchIntentParams): Disp
1785
1802
  declare interface UseDispatchIntentParams {
1786
1803
  action?: 'edit'
1787
1804
  intentId?: string
1788
- documentHandle: WithResourceNameSupport<DocumentHandle>
1805
+ documentHandle: DocumentHandle
1789
1806
  parameters?: Record<string, unknown>
1790
1807
  }
1791
1808
 
@@ -2061,7 +2078,7 @@ export declare function useDocumentEvent<
2061
2078
  declare interface UseDocumentEventOptions<
2062
2079
  TDataset extends string = string,
2063
2080
  TProjectId extends string = string,
2064
- > extends DatasetHandle<TDataset, TProjectId> {
2081
+ > extends ResourceHandle<TDataset, TProjectId> {
2065
2082
  onEvent: (documentEvent: DocumentEvent) => void
2066
2083
  }
2067
2084
 
@@ -2070,7 +2087,9 @@ declare type UseDocumentOptions<
2070
2087
  TDocumentType extends string = string,
2071
2088
  TDataset extends string = string,
2072
2089
  TProjectId extends string = string,
2073
- > = WithResourceNameSupport<DocumentOptions<TPath, TDocumentType, TDataset, TProjectId>>
2090
+ > = DocumentHandle<TDocumentType, TDataset, TProjectId> & {
2091
+ path?: TPath
2092
+ }
2074
2093
 
2075
2094
  /**
2076
2095
  *
@@ -2150,7 +2169,9 @@ declare type UseDocumentOptions<
2150
2169
  * ```
2151
2170
  */
2152
2171
  export declare function useDocumentPermissions(
2153
- actionOrActions: DocumentAction | DocumentAction[],
2172
+ actionOrActions:
2173
+ | WithResourceNameSupport<DocumentAction>
2174
+ | WithResourceNameSupport<DocumentAction>[],
2154
2175
  ): DocumentPermissionsResult
2155
2176
 
2156
2177
  /**
@@ -2218,7 +2239,7 @@ export declare function useDocumentPreview({
2218
2239
  * @public
2219
2240
  * @category Types
2220
2241
  */
2221
- export declare interface useDocumentPreviewOptions extends WithResourceNameSupport<DocumentHandle> {
2242
+ export declare interface useDocumentPreviewOptions extends DocumentHandle {
2222
2243
  /**
2223
2244
  * Optional ref object to track visibility. When provided, preview resolution
2224
2245
  * only occurs when the referenced element is visible in the viewport.
@@ -2379,7 +2400,7 @@ export declare interface useDocumentProjectionOptions<
2379
2400
  TDocumentType extends string = string,
2380
2401
  TDataset extends string = string,
2381
2402
  TProjectId extends string = string,
2382
- > extends WithResourceNameSupport<DocumentHandle<TDocumentType, TDataset, TProjectId>> {
2403
+ > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
2383
2404
  /** The GROQ projection string */
2384
2405
  projection: TProjection
2385
2406
  /** Optional parameters for the projection query */
@@ -2519,7 +2540,7 @@ export declare function useDocuments<
2519
2540
  filter,
2520
2541
  orderings,
2521
2542
  documentType,
2522
- ...options
2543
+ ...rawOptions
2523
2544
  }: DocumentsOptions<TDocumentType, TDataset, TProjectId>): DocumentsResponse<
2524
2545
  TDocumentType,
2525
2546
  TDataset,
@@ -2559,7 +2580,7 @@ declare type UseDocumentSyncStatus = {
2559
2580
  * // <SyncIndicator doc={doc} />
2560
2581
  * ```
2561
2582
  */
2562
- (doc: DocumentHandle): boolean
2583
+ (doc: DocumentHandle_2): boolean
2563
2584
  }
2564
2585
 
2565
2586
  /**
@@ -2771,7 +2792,7 @@ export declare function useManageFavorite({
2771
2792
  schemaName,
2772
2793
  }: UseManageFavoriteProps): ManageFavorite
2773
2794
 
2774
- declare interface UseManageFavoriteProps extends DocumentHandle {
2795
+ declare interface UseManageFavoriteProps extends DocumentHandle_2 {
2775
2796
  resourceId?: string
2776
2797
  resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
2777
2798
  /**
@@ -2826,10 +2847,75 @@ declare interface UseManageFavoriteProps extends DocumentHandle {
2826
2847
  * ```
2827
2848
  */
2828
2849
  export declare function useNavigateToStudioDocument(
2829
- documentHandle: DocumentHandle,
2850
+ documentHandle: DocumentHandle_2,
2830
2851
  preferredStudioUrl?: string,
2831
2852
  ): NavigateToStudioResult
2832
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
+
2833
2919
  /**
2834
2920
  * Retrieves pages of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,
2835
2921
  * with support for traditional paginated interfaces. The number of document handles returned per page is customizable,
@@ -2936,98 +3022,70 @@ export declare function usePaginatedDocuments<
2936
3022
  params,
2937
3023
  orderings,
2938
3024
  search,
2939
- ...options
3025
+ ...rawOptions
2940
3026
  }: PaginatedDocumentsOptions<TDocumentType, TDataset, TProjectId>): PaginatedDocumentsResponse<
2941
3027
  TDocumentType,
2942
3028
  TDataset,
2943
3029
  TProjectId
2944
3030
  >
2945
3031
 
2946
- /**
2947
- * @public
2948
- * @function
2949
- *
2950
- * Returns a single or stack of perspectives for the given perspective handle,
2951
- * which can then be used to correctly query the documents
2952
- * via the `perspective` parameter in the client.
2953
- *
2954
- * @param perspectiveHandle - The perspective handle to get the perspective for.
2955
- * @category Documents
2956
- * @example
2957
- * ```tsx
2958
- * import {usePerspective, useQuery} from '@sanity/sdk-react'
2959
-
2960
- * const perspective = usePerspective({perspective: 'rxg1346', projectId: 'abc123', dataset: 'production'})
2961
- * const {data} = useQuery<Movie[]>('*[_type == "movie"]', {
2962
- * perspective: perspective,
2963
- * })
2964
- * ```
2965
- *
2966
- * @returns The perspective for the given perspective handle.
2967
- */
2968
- declare type UsePerspective = {
2969
- (perspectiveHandle: DatasetHandle): string | string[]
2970
- }
2971
-
2972
3032
  /**
2973
3033
  * @public
2974
3034
  * @function
2975
3035
  */
2976
- export declare const usePerspective: UsePerspective
3036
+ export declare function usePerspective(perspectiveHandle?: ResourceHandle): string | string[]
2977
3037
 
2978
3038
  /**
2979
3039
  * A hook for subscribing to presence information for the current project or Canvas.
2980
3040
  * @public
2981
3041
  */
2982
- export declare function usePresence(options?: WithResourceNameSupport<DatasetHandle>): {
3042
+ export declare function usePresence(options?: ResourceHandle): {
2983
3043
  locations: UserPresence[]
2984
3044
  }
2985
3045
 
2986
- declare type UseProject = {
2987
- /**
2988
- *
2989
- * Returns metadata for a given project
2990
- *
2991
- * @category Projects
2992
- * @param projectId - The ID of the project to retrieve metadata for
2993
- * @returns The metadata for the project
2994
- * @example
2995
- * ```tsx
2996
- * function ProjectMetadata({ projectId }: { projectId: string }) {
2997
- * const project = useProject(projectId)
2998
- *
2999
- * return (
3000
- * <figure style={{ backgroundColor: project.metadata.color || 'lavender'}}>
3001
- * <h1>{project.displayName}</h1>
3002
- * </figure>
3003
- * )
3004
- * }
3005
- * ```
3006
- */
3007
- (projectHandle?: ProjectHandle): SanityProject
3008
- }
3009
-
3010
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
+ * ```
3011
3072
  * @public
3012
3073
  * @function
3013
3074
  */
3014
- export declare const useProject: UseProject
3015
-
3016
- /**
3017
- * @public
3018
- * @category Types
3019
- */
3020
- declare type UseProjects = <TIncludeMembers extends boolean = false>(options?: {
3021
- organizationId?: string
3022
- includeMembers?: TIncludeMembers
3023
- }) => 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>
3024
3081
 
3025
3082
  /**
3026
3083
  * Returns metadata for each project you have access to.
3027
3084
  *
3028
3085
  * @category Projects
3029
3086
  * @param options - Configuration options
3030
- * @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`.
3031
3089
  * @example
3032
3090
  * ```tsx
3033
3091
  * const projects = useProjects()
@@ -3042,13 +3100,21 @@ declare type UseProjects = <TIncludeMembers extends boolean = false>(options?: {
3042
3100
  * ```
3043
3101
  * @example
3044
3102
  * ```tsx
3045
- * const projectsWithMembers = useProjects({ includeMembers: true })
3046
- * 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})
3047
3108
  * ```
3048
3109
  * @public
3049
3110
  * @function
3050
3111
  */
3051
- 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>[]
3052
3118
 
3053
3119
  /**
3054
3120
  * @public
@@ -3215,7 +3281,7 @@ export declare function useRecordDocumentHistoryEvent({
3215
3281
  /**
3216
3282
  * @internal
3217
3283
  */
3218
- declare interface UseRecordDocumentHistoryEventProps extends DocumentHandle {
3284
+ declare interface UseRecordDocumentHistoryEventProps extends DocumentHandle_2 {
3219
3285
  resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
3220
3286
  resourceId?: string
3221
3287
  /**
@@ -3225,6 +3291,25 @@ declare interface UseRecordDocumentHistoryEventProps extends DocumentHandle {
3225
3291
  schemaName?: string
3226
3292
  }
3227
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
+
3228
3313
  /**
3229
3314
  * @public
3230
3315
  * @category Types
@@ -3264,60 +3349,33 @@ export declare interface UsersResult {
3264
3349
  }
3265
3350
 
3266
3351
  /**
3267
- * Retrieves the current Sanity instance or finds a matching instance from the hierarchy
3352
+ * Retrieves the current Sanity instance from context
3268
3353
  *
3269
3354
  * @public
3270
3355
  *
3271
3356
  * @category Platform
3272
- * @param config - Optional configuration to match against when finding an instance
3273
- * @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
3274
3359
  *
3275
3360
  * @remarks
3276
- * This hook accesses the nearest Sanity instance from the React context. When provided with
3277
- * a configuration object, it traverses up the instance hierarchy to find the closest instance
3278
- * that matches the specified configuration using shallow comparison of properties.
3279
- *
3361
+ * This hook accesses the nearest Sanity instance from the React context.
3280
3362
  * The hook must be used within a component wrapped by a `ResourceProvider` or `SanityApp`.
3281
3363
  *
3282
- * Use this hook when you need to:
3283
- * - Access the current SanityInstance from context
3284
- * - Find a specific instance with matching project/dataset configuration
3285
- * - Access a parent instance with specific configuration values
3286
- *
3287
3364
  * @example Get the current instance
3288
3365
  * ```tsx
3289
- * // Get the current instance from context
3290
3366
  * const instance = useSanityInstance()
3291
3367
  * console.log(instance.config.projectId)
3292
3368
  * ```
3293
3369
  *
3294
- * @example Find an instance with specific configuration
3295
- * ```tsx
3296
- * // Find an instance matching the given project and dataset
3297
- * const instance = useSanityInstance({
3298
- * projectId: 'abc123',
3299
- * dataset: 'production'
3300
- * })
3301
- *
3302
- * // Use instance for API calls
3303
- * const fetchDocument = (docId) => {
3304
- * // Instance is guaranteed to have the matching config
3305
- * return client.fetch(`*[_id == $id][0]`, { id: docId })
3306
- * }
3307
- * ```
3308
- *
3309
- * @example Match partial configuration
3310
- * ```tsx
3311
- * // Find an instance with specific auth configuration
3312
- * const instance = useSanityInstance({
3313
- * auth: { requireLogin: true }
3314
- * })
3315
- * ```
3316
- *
3317
3370
  * @throws Error if no SanityInstance is found in context
3318
- * @throws Error if no matching instance is found for the provided config
3319
3371
  */
3320
- 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
3321
3379
 
3322
3380
  /**
3323
3381
  * Hook that fetches studio workspaces and organizes them by projectId:dataset
@@ -3549,10 +3607,9 @@ export declare type WindowMessageHandler<TFrameMessage extends FrameMessage> = (
3549
3607
 
3550
3608
  /**
3551
3609
  * Adds React hook support (resourceName resolution) to core types.
3552
- * This wrapper allows hooks to accept `resourceName` as a convenience,
3553
- * which is then resolved to a `DocumentResource` at the React layer.
3554
- * For now, we are trying to avoid resource name resolution in core --
3555
- * functions having resources explicitly passed will reduce complexity.
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).
3556
3613
  *
3557
3614
  * @typeParam T - The core type to extend (must have optional `resource` field)
3558
3615
  * @beta