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

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 (40) hide show
  1. package/dist/index.d.ts +276 -207
  2. package/dist/index.js +90 -75
  3. package/dist/index.js.map +1 -1
  4. package/package.json +4 -4
  5. package/src/_exports/index.ts +11 -11
  6. package/src/components/Login/LoginLinks.test.tsx +2 -2
  7. package/src/components/Login/LoginLinks.tsx +2 -2
  8. package/src/components/auth/AuthBoundary.test.tsx +2 -2
  9. package/src/components/auth/LoginCallback.test.tsx +3 -3
  10. package/src/components/auth/LoginCallback.tsx +4 -4
  11. package/src/hooks/auth/useCurrentUser.tsx +1 -0
  12. package/src/hooks/auth/useHandleAuthCallback.test.tsx +16 -0
  13. package/src/hooks/auth/{useHandleCallback.tsx → useHandleAuthCallback.tsx} +6 -6
  14. package/src/hooks/auth/useLogOut.test.tsx +2 -2
  15. package/src/hooks/client/useClient.ts +1 -0
  16. package/src/hooks/comlink/useManageFavorite.test.ts +9 -4
  17. package/src/hooks/comlink/useManageFavorite.ts +42 -13
  18. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +7 -3
  19. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +39 -12
  20. package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +178 -0
  21. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +31 -5
  22. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +5 -1
  23. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +4 -3
  24. package/src/hooks/datasets/useDatasets.ts +6 -3
  25. package/src/hooks/document/useApplyDocumentActions.test.ts +25 -0
  26. package/src/hooks/document/{useApplyActions.ts → useApplyDocumentActions.ts} +13 -12
  27. package/src/hooks/document/{usePermissions.ts → useDocumentPermissions.ts} +8 -6
  28. package/src/hooks/document/useDocumentSyncStatus.ts +4 -1
  29. package/src/hooks/document/useEditDocument.test.ts +8 -8
  30. package/src/hooks/document/useEditDocument.ts +2 -2
  31. package/src/hooks/{infiniteList/useInfiniteList.test.tsx → documents/useDocuments.test.tsx} +9 -9
  32. package/src/hooks/{infiniteList/useInfiniteList.ts → documents/useDocuments.ts} +10 -10
  33. package/src/hooks/{paginatedList/usePaginatedList.test.tsx → paginatedDocuments/usePaginatedDocuments.test.tsx} +14 -14
  34. package/src/hooks/{paginatedList/usePaginatedList.ts → paginatedDocuments/usePaginatedDocuments.ts} +7 -7
  35. package/src/hooks/preview/usePreview.tsx +2 -2
  36. package/src/hooks/projection/useProjection.ts +2 -2
  37. package/src/hooks/projects/useProject.ts +4 -1
  38. package/src/hooks/projects/useProjects.ts +7 -3
  39. package/src/hooks/auth/useHandleCallback.test.tsx +0 -16
  40. package/src/hooks/document/useApplyActions.test.ts +0 -25
package/dist/index.d.ts CHANGED
@@ -1,18 +1,20 @@
1
1
  import {ActionsResult} from '@sanity/sdk'
2
- import {ApplyActionsOptions} from '@sanity/sdk'
2
+ import {ApplyDocumentActionsOptions} from '@sanity/sdk'
3
3
  import {AuthProvider} from '@sanity/sdk'
4
4
  import {AuthState} from '@sanity/sdk'
5
+ import {CanvasResource} from '@sanity/message-protocol'
5
6
  import {ClientOptions} from '@sanity/sdk'
6
7
  import {CurrentUser} from '@sanity/sdk'
7
8
  import {DocumentAction} from '@sanity/sdk'
8
9
  import {DocumentEvent} from '@sanity/sdk'
9
10
  import {DocumentHandle} from '@sanity/sdk'
11
+ import {DocumentPermissionsResult} from '@sanity/sdk'
10
12
  import {FallbackProps} from 'react-error-boundary'
11
13
  import {FrameMessage} from '@sanity/sdk'
12
14
  import {JsonMatch} from '@sanity/sdk'
13
15
  import {JsonMatchPath} from '@sanity/sdk'
16
+ import {MediaResource} from '@sanity/message-protocol'
14
17
  import {Observable} from 'rxjs'
15
- import {PermissionsResult} from '@sanity/sdk'
16
18
  import {PreviewValue} from '@sanity/sdk'
17
19
  import {QueryOptions} from '@sanity/sdk'
18
20
  import {ReactElement} from 'react'
@@ -26,6 +28,7 @@ import {SanityInstance} from '@sanity/sdk'
26
28
  import {SanityProject as SanityProject_2} from '@sanity/sdk'
27
29
  import {SanityUser as SanityUser_2} from '@sanity/sdk'
28
30
  import {SortOrderingItem} from '@sanity/types'
31
+ import {StudioResource} from '@sanity/message-protocol'
29
32
  import {ValidProjection} from '@sanity/sdk'
30
33
  import {WindowMessage} from '@sanity/sdk'
31
34
 
@@ -720,6 +723,60 @@ declare interface DocumentInteractionHistory {
720
723
  isConnected: boolean
721
724
  }
722
725
 
726
+ /**
727
+ * Configuration options for the useDocuments hook
728
+ *
729
+ * @beta
730
+ * @category Types
731
+ */
732
+ export declare interface DocumentsOptions extends QueryOptions {
733
+ /**
734
+ * GROQ filter expression to apply to the query
735
+ */
736
+ filter?: string
737
+ /**
738
+ * Number of items to load per batch (defaults to 25)
739
+ */
740
+ batchSize?: number
741
+ /**
742
+ * Sorting configuration for the results
743
+ */
744
+ orderings?: SortOrderingItem[]
745
+ /**
746
+ * Text search query to filter results
747
+ */
748
+ search?: string
749
+ }
750
+
751
+ /**
752
+ * Return value from the useDocuments hook
753
+ *
754
+ * @beta
755
+ * @category Types
756
+ */
757
+ export declare interface DocumentsResponse {
758
+ /**
759
+ * Array of document handles for the current batch
760
+ */
761
+ data: DocumentHandle[]
762
+ /**
763
+ * Whether there are more items available to load
764
+ */
765
+ hasMore: boolean
766
+ /**
767
+ * Total count of items matching the query
768
+ */
769
+ count: number
770
+ /**
771
+ * Whether a query is currently in progress
772
+ */
773
+ isPending: boolean
774
+ /**
775
+ * Function to load the next batch of results
776
+ */
777
+ loadMore: () => void
778
+ }
779
+
723
780
  /**
724
781
  * Modifies an existing draft document.
725
782
  * It applies the given patch to the document referenced by draftId.
@@ -849,60 +906,6 @@ declare type IdentifiedSanityDocumentStub<T extends Record<string, Any> = Record
849
906
  _id: string
850
907
  } & SanityDocumentStub
851
908
 
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
909
  /** @public */
907
910
  declare interface InitializedClientConfig extends ClientConfig {
908
911
  apiHost: string
@@ -2063,12 +2066,37 @@ declare type OpenEvent = {
2063
2066
  }
2064
2067
 
2065
2068
  /**
2066
- * Return value from the usePaginatedList hook
2069
+ * Configuration options for the usePaginatedDocuments hook
2070
+ *
2071
+ * @beta
2072
+ * @category Types
2073
+ */
2074
+ export declare interface PaginatedDocumentsOptions extends QueryOptions {
2075
+ /**
2076
+ * GROQ filter expression to apply to the query
2077
+ */
2078
+ filter?: string
2079
+ /**
2080
+ * Number of items to display per page (defaults to 25)
2081
+ */
2082
+ pageSize?: number
2083
+ /**
2084
+ * Sorting configuration for the results
2085
+ */
2086
+ orderings?: SortOrderingItem[]
2087
+ /**
2088
+ * Text search query to filter results
2089
+ */
2090
+ search?: string
2091
+ }
2092
+
2093
+ /**
2094
+ * Return value from the usePaginatedDocuments hook
2067
2095
  *
2068
2096
  * @beta
2069
2097
  * @category Types
2070
2098
  */
2071
- export declare interface PaginatedList {
2099
+ export declare interface PaginatedDocumentsResponse {
2072
2100
  /**
2073
2101
  * Array of document handles for the current page
2074
2102
  */
@@ -2140,31 +2168,6 @@ export declare interface PaginatedList {
2140
2168
  goToPage: (pageNumber: number) => void
2141
2169
  }
2142
2170
 
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
2171
  /** @public */
2169
2172
  declare class Patch extends BasePatch {
2170
2173
  #private
@@ -2275,6 +2278,7 @@ declare class ProjectsClient {
2275
2278
  /**
2276
2279
  * @public
2277
2280
  * @category Types
2281
+ * @interface
2278
2282
  */
2279
2283
  export declare type ProjectWithoutMembers = Omit<SanityProject, 'members'>
2280
2284
 
@@ -3535,9 +3539,9 @@ declare interface UploadClientConfig {
3535
3539
  * @example Publish or unpublish a document
3536
3540
  * ```
3537
3541
  * import { publishDocument, unpublishDocument } from '@sanity/sdk'
3538
- * import { useApplyActions } from '@sanity/sdk-react'
3542
+ * import { useApplyDocumentActions } from '@sanity/sdk-react'
3539
3543
  *
3540
- * const apply = useApplyActions()
3544
+ * const apply = useApplyDocumentActions()
3541
3545
  * const myDocument = { _id: 'my-document-id', _type: 'my-document-type' }
3542
3546
  *
3543
3547
  * return (
@@ -3549,9 +3553,9 @@ declare interface UploadClientConfig {
3549
3553
  * @example Create and publish a new document
3550
3554
  * ```
3551
3555
  * import { createDocument, publishDocument } from '@sanity/sdk'
3552
- * import { useApplyActions } from '@sanity/sdk-react'
3556
+ * import { useApplyDocumentActions } from '@sanity/sdk-react'
3553
3557
  *
3554
- * const apply = useApplyActions()
3558
+ * const apply = useApplyDocumentActions()
3555
3559
  *
3556
3560
  * const handleCreateAndPublish = () => {
3557
3561
  * const handle = { _id: window.crypto.randomUUID(), _type: 'my-document-type' }
@@ -3568,11 +3572,11 @@ declare interface UploadClientConfig {
3568
3572
  * )
3569
3573
  * ```
3570
3574
  */
3571
- export declare function useApplyActions(
3575
+ export declare function useApplyDocumentActions(
3572
3576
  resourceId?: ResourceId,
3573
3577
  ): <TDocument extends SanityDocument>(
3574
3578
  action: DocumentAction<TDocument> | DocumentAction<TDocument>[],
3575
- options?: ApplyActionsOptions,
3579
+ options?: ApplyDocumentActionsOptions,
3576
3580
  ) => Promise<ActionsResult<TDocument>>
3577
3581
 
3578
3582
  /**
@@ -3630,6 +3634,7 @@ export declare const useAuthToken: () => string | null
3630
3634
  * ```
3631
3635
  *
3632
3636
  * @public
3637
+ * @function
3633
3638
  */
3634
3639
  export declare const useClient: (e: ClientOptions) => SanityClient
3635
3640
 
@@ -3659,6 +3664,7 @@ declare type UseCurrentUser = {
3659
3664
 
3660
3665
  /**
3661
3666
  * @public
3667
+ * @function
3662
3668
  * @TODO This should not return null — users of a custom app will always be authenticated via Core
3663
3669
  */
3664
3670
  export declare const useCurrentUser: UseCurrentUser
@@ -3686,10 +3692,10 @@ export declare function useDashboardOrganizationId(): string | undefined
3686
3692
  declare type UseDatasets = {
3687
3693
  /**
3688
3694
  *
3689
- * Returns metadata for each dataset in your organization.
3695
+ * Returns metadata for each dataset the current user has access to.
3690
3696
  *
3691
3697
  * @category Datasets
3692
- * @returns The metadata for your organization's datasets
3698
+ * @returns The metadata for your the datasets
3693
3699
  *
3694
3700
  * @example
3695
3701
  * ```tsx
@@ -3708,7 +3714,10 @@ declare type UseDatasets = {
3708
3714
  (): DatasetsResponse
3709
3715
  }
3710
3716
 
3711
- /** @public */
3717
+ /**
3718
+ * @public
3719
+ * @function
3720
+ */
3712
3721
  export declare const useDatasets: UseDatasets
3713
3722
 
3714
3723
  /**
@@ -3810,6 +3819,91 @@ export declare function useDocumentEvent(
3810
3819
  doc: DocumentHandle,
3811
3820
  ): void
3812
3821
 
3822
+ /**
3823
+ *
3824
+ * @beta
3825
+ *
3826
+ * Check if the current user has the specified permissions for the given document actions.
3827
+ *
3828
+ * @category Permissions
3829
+ * @param actions - One more more calls to a particular document action function for a given document
3830
+ * @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.
3831
+ *
3832
+ * @example Checking for permission to publish a document
3833
+ * ```ts
3834
+ * import {useDocumentPermissions, useApplyDocumentActions} from '@sanity/sdk-react'
3835
+ * import {publishDocument} from '@sanity/sdk'
3836
+ *
3837
+ * export function PublishButton({doc}: {doc: DocumentHandle}) {
3838
+ * const publishPermissions = useDocumentPermissions(publishDocument(doc))
3839
+ * const applyAction = useApplyDocumentActions()
3840
+ *
3841
+ * return (
3842
+ * <>
3843
+ * <button
3844
+ * disabled={!publishPermissions.allowed}
3845
+ * onClick={() => applyAction(publishDocument(doc))}
3846
+ * popoverTarget={`${publishPermissions.allowed ? undefined : 'publishButtonPopover'}`}
3847
+ * >
3848
+ * Publish
3849
+ * </button>
3850
+ * {!publishPermissions.allowed && (
3851
+ * <div popover id="publishButtonPopover">
3852
+ * {publishPermissions.message}
3853
+ * </div>
3854
+ * )}
3855
+ * </>
3856
+ * )
3857
+ * }
3858
+ * ```
3859
+ */
3860
+ export declare function useDocumentPermissions(
3861
+ actions: DocumentAction | DocumentAction[],
3862
+ ): DocumentPermissionsResult
3863
+
3864
+ /**
3865
+ * Retrieves batches of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,
3866
+ * with infinite scrolling support. The number of document handles returned per batch is customizable,
3867
+ * and additional batches can be loaded using the supplied `loadMore` function.
3868
+ *
3869
+ * @beta
3870
+ * @category Documents
3871
+ * @param options - Configuration options for the infinite list
3872
+ * @returns An object containing the list of document handles, the loading state, the total count of retrieved document handles, and a function to load more
3873
+ * @example
3874
+ * ```tsx
3875
+ * const {data, hasMore, isPending, loadMore} = useDocuments({
3876
+ * filter: '_type == "post"',
3877
+ * search: searchTerm,
3878
+ * batchSize: 10,
3879
+ * orderings: [{field: '_createdAt', direction: 'desc'}]
3880
+ * })
3881
+ *
3882
+ * return (
3883
+ * <div>
3884
+ * Total documents: {count}
3885
+ * <ol>
3886
+ * {data.map((doc) => (
3887
+ * <li key={doc._id}>
3888
+ * <MyDocumentComponent doc={doc} />
3889
+ * </li>
3890
+ * ))}
3891
+ * </ol>
3892
+ * {hasMore && <button onClick={loadMore}>Load More</button>}
3893
+ * </div>
3894
+ * )
3895
+ * ```
3896
+ *
3897
+ */
3898
+ export declare function useDocuments({
3899
+ batchSize,
3900
+ params,
3901
+ search,
3902
+ filter,
3903
+ orderings,
3904
+ ...options
3905
+ }: DocumentsOptions): DocumentsResponse
3906
+
3813
3907
  declare type UseDocumentSyncStatus = {
3814
3908
  /**
3815
3909
  * Exposes the document’s sync status between local and remote document states.
@@ -3833,7 +3927,10 @@ declare type UseDocumentSyncStatus = {
3833
3927
  (doc: DocumentHandle): boolean | undefined
3834
3928
  }
3835
3929
 
3836
- /** @beta */
3930
+ /**
3931
+ * @beta
3932
+ * @function
3933
+ */
3837
3934
  export declare const useDocumentSyncStatus: UseDocumentSyncStatus
3838
3935
 
3839
3936
  /**
@@ -3994,7 +4091,7 @@ export declare interface UseFrameConnectionOptions<TWindowMessage extends Window
3994
4091
  * This hook provides access to the authentication store's callback handler,
3995
4092
  * which processes auth redirects by extracting the session ID and fetching the
3996
4093
  * authentication token. If fetching the long-lived token is successful,
3997
- * `handleCallback` will return a Promise that resolves a new location that
4094
+ * `handleAuthCallback` will return a Promise that resolves a new location that
3998
4095
  * removes the short-lived token from the URL. Use this in combination with
3999
4096
  * `history.replaceState` or your own router's `replace` function to update the
4000
4097
  * current location without triggering a reload.
@@ -4002,13 +4099,13 @@ export declare interface UseFrameConnectionOptions<TWindowMessage extends Window
4002
4099
  * @example
4003
4100
  * ```tsx
4004
4101
  * function AuthCallback() {
4005
- * const handleCallback = useHandleCallback()
4102
+ * const handleAuthCallback = useHandleAuthCallback()
4006
4103
  * const router = useRouter() // Example router
4007
4104
  *
4008
4105
  * useEffect(() => {
4009
4106
  * async function processCallback() {
4010
4107
  * // Handle the callback and get the cleaned URL
4011
- * const newUrl = await handleCallback(window.location.href)
4108
+ * const newUrl = await handleAuthCallback(window.location.href)
4012
4109
  *
4013
4110
  * if (newUrl) {
4014
4111
  * // Replace URL without triggering navigation
@@ -4017,7 +4114,7 @@ export declare interface UseFrameConnectionOptions<TWindowMessage extends Window
4017
4114
  * }
4018
4115
  *
4019
4116
  * processCallback().catch(console.error)
4020
- * }, [handleCallback, router])
4117
+ * }, [handleAuthCallback, router])
4021
4118
  *
4022
4119
  * return <div>Completing login...</div>
4023
4120
  * }
@@ -4026,53 +4123,10 @@ export declare interface UseFrameConnectionOptions<TWindowMessage extends Window
4026
4123
  * @returns A callback handler function that processes OAuth redirects
4027
4124
  * @public
4028
4125
  */
4029
- export declare const useHandleCallback: () => (
4126
+ export declare const useHandleAuthCallback: () => (
4030
4127
  locationHref?: string | undefined,
4031
4128
  ) => Promise<string | false>
4032
4129
 
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
4130
  /**
4077
4131
  * @internal
4078
4132
  * A React hook that retrieves the available authentication provider URLs for login.
@@ -4127,21 +4181,21 @@ export declare const useLogOut: () => () => Promise<void>
4127
4181
  * ## useManageFavorite
4128
4182
  * This hook provides functionality to add and remove documents from favorites,
4129
4183
  * and tracks the current favorite status of the document.
4130
- * @category Core UI Communication
4184
+ * @category Dashboard Communication
4131
4185
  * @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
4132
4186
  * @returns An object containing:
4133
4187
  * - `favorite` - Function to add document to favorites
4134
4188
  * - `unfavorite` - Function to remove document from favorites
4135
4189
  * - `isFavorited` - Boolean indicating if document is currently favorited
4136
- * - `isConnected` - Boolean indicating if connection to Core UI is established
4190
+ * - `isConnected` - Boolean indicating if connection to Dashboard UI is established
4137
4191
  *
4138
4192
  * @example
4139
4193
  * ```tsx
4140
4194
  * function MyDocumentAction(props: DocumentActionProps) {
4141
- * const {_id, _type} = props
4195
+ * const {documentId, documentType} = props
4142
4196
  * const {favorite, unfavorite, isFavorited, isConnected} = useManageFavorite({
4143
- * _id,
4144
- * _type
4197
+ * documentId,
4198
+ * documentType
4145
4199
  * })
4146
4200
  *
4147
4201
  * return (
@@ -4154,15 +4208,52 @@ export declare const useLogOut: () => () => Promise<void>
4154
4208
  * }
4155
4209
  * ```
4156
4210
  */
4157
- export declare function useManageFavorite({_id, _type}: DocumentHandle): ManageFavorite
4211
+ export declare function useManageFavorite({
4212
+ documentId,
4213
+ documentType,
4214
+ resourceId,
4215
+ resourceType,
4216
+ }: UseManageFavoriteProps): ManageFavorite
4217
+
4218
+ declare interface UseManageFavoriteProps {
4219
+ documentId: string
4220
+ documentType: string
4221
+ resourceId?: string
4222
+ resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
4223
+ }
4158
4224
 
4159
4225
  /**
4160
4226
  * @public
4161
4227
  * Hook that provides a function to navigate to a studio document.
4228
+ * Currently, requires a document handle with a resourceId.
4229
+ * That resourceId is currently formatted like: `document:projectId.dataset:documentId`
4230
+ * If the hook you used to retrieve the document handle doesn't provide a resourceId like this,
4231
+ * you can construct it according to the above format with the document handle's _id.
4232
+ *
4233
+ * This will only work if you have deployed a studio with a workspace
4234
+ * with this projectId / dataset combination.
4235
+ * It may be able to take a custom URL in the future.
4236
+ *
4237
+ * This will likely change in the future.
4162
4238
  * @param documentHandle - The document handle containing document ID, type, and resource ID
4163
4239
  * @returns An object containing:
4164
4240
  * - navigateToStudioDocument - Function that when called will navigate to the studio document
4165
- * - isConnected - Boolean indicating if connection to Core UI is established
4241
+ * - isConnected - Boolean indicating if connection to Dashboard is established
4242
+ *
4243
+ * @example
4244
+ * ```ts
4245
+ * import {navigateToStudioDocument, type DocumentHandle} from '@sanity/sdk'
4246
+ *
4247
+ * function MyComponent({documentHandle}: {documentHandle: DocumentHandle}) {
4248
+ * const {navigateToStudioDocument, isConnected} = useNavigateToStudioDocument(documentHandle)
4249
+ *
4250
+ * return (
4251
+ * <button onClick={navigateToStudioDocument} disabled={!isConnected}>
4252
+ * Navigate to Studio Document
4253
+ * </button>
4254
+ * )
4255
+ * }
4256
+ * ```
4166
4257
  */
4167
4258
  export declare function useNavigateToStudioDocument(
4168
4259
  documentHandle: DocumentHandle,
@@ -4188,7 +4279,7 @@ export declare function useNavigateToStudioDocument(
4188
4279
  * previousPage,
4189
4280
  * hasNextPage,
4190
4281
  * hasPreviousPage
4191
- * } = usePaginatedList({
4282
+ * } = usePaginatedDocuments({
4192
4283
  * filter: '_type == "post"',
4193
4284
  * search: searchTerm,
4194
4285
  * pageSize: 10,
@@ -4212,56 +4303,14 @@ export declare function useNavigateToStudioDocument(
4212
4303
  * ```
4213
4304
  *
4214
4305
  */
4215
- export declare function usePaginatedList({
4306
+ export declare function usePaginatedDocuments({
4216
4307
  filter,
4217
4308
  pageSize,
4218
4309
  params,
4219
4310
  orderings,
4220
4311
  search,
4221
4312
  ...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
4313
+ }?: PaginatedDocumentsOptions): PaginatedDocumentsResponse
4265
4314
 
4266
4315
  /**
4267
4316
  * @beta
@@ -4290,12 +4339,12 @@ export declare function usePermissions(
4290
4339
  * }
4291
4340
  *
4292
4341
  * // DocumentList.jsx
4293
- * const { data, isPending } = useDocuments({ filter: '_type == "movie"' })
4342
+ * const { data } = useDocuments({ filter: '_type == "movie"' })
4294
4343
  * return (
4295
4344
  * <div>
4296
4345
  * <h1>Movies</h1>
4297
4346
  * <ul>
4298
- * {isPending ? 'Loading…' : data.map(movie => (
4347
+ * {data.map(movie => (
4299
4348
  * <li key={movie._id}>
4300
4349
  * <Suspense fallback='Loading…'>
4301
4350
  * <PreviewComponent document={movie} />
@@ -4356,7 +4405,10 @@ declare type UseProject = {
4356
4405
  (projectId: string): SanityProject_2
4357
4406
  }
4358
4407
 
4359
- /** @public */
4408
+ /**
4409
+ * @public
4410
+ * @function
4411
+ */
4360
4412
  export declare const useProject: UseProject
4361
4413
 
4362
4414
  /**
@@ -4396,10 +4448,10 @@ export declare const useProject: UseProject
4396
4448
  * }
4397
4449
  * ```
4398
4450
  *
4399
- * @example Combining with useInfiniteList to render a collection with specific fields
4451
+ * @example Combining with useDocuments to render a collection with specific fields
4400
4452
  * ```
4401
4453
  * // DocumentList.jsx
4402
- * const { data } = useInfiniteList({ filter: '_type == "article"' })
4454
+ * const { data } = useDocuments({ filter: '_type == "article"' })
4403
4455
  * return (
4404
4456
  * <div>
4405
4457
  * <h1>Books</h1>
@@ -4446,10 +4498,10 @@ export declare interface UseProjectionResults<TResult extends object> {
4446
4498
  declare type UseProjects = {
4447
4499
  /**
4448
4500
  *
4449
- * Returns metadata for each project in your organization.
4501
+ * Returns metadata for each project you have access to.
4450
4502
  *
4451
4503
  * @category Projects
4452
- * @returns An array of metadata (minus the projects’ members) for each project in your organization
4504
+ * @returns An array of metadata (minus the projects’ members) for each project
4453
4505
  * @example
4454
4506
  * ```tsx
4455
4507
  * const projects = useProjects()
@@ -4466,7 +4518,10 @@ declare type UseProjects = {
4466
4518
  (): ProjectWithoutMembers[]
4467
4519
  }
4468
4520
 
4469
- /** @public */
4521
+ /**
4522
+ * @public
4523
+ * @function
4524
+ */
4470
4525
  export declare const useProjects: UseProjects
4471
4526
 
4472
4527
  /**
@@ -4534,10 +4589,12 @@ export declare function useQuery<T>(
4534
4589
  * @example
4535
4590
  * ```tsx
4536
4591
  * function MyDocumentAction(props: DocumentActionProps) {
4537
- * const {_id, _type} = props
4592
+ * const {documentId, documentType, resourceType, resourceId} = props
4538
4593
  * const {recordEvent, isConnected} = useRecordDocumentHistoryEvent({
4539
- * _id,
4540
- * _type
4594
+ * documentId,
4595
+ * documentType,
4596
+ * resourceType,
4597
+ * resourceId,
4541
4598
  * })
4542
4599
  *
4543
4600
  * return (
@@ -4551,9 +4608,21 @@ export declare function useQuery<T>(
4551
4608
  * ```
4552
4609
  */
4553
4610
  export declare function useRecordDocumentHistoryEvent({
4554
- _id,
4555
- _type,
4556
- }: DocumentHandle): DocumentInteractionHistory
4611
+ documentId,
4612
+ documentType,
4613
+ resourceType,
4614
+ resourceId,
4615
+ }: UseRecordDocumentHistoryEventProps): DocumentInteractionHistory
4616
+
4617
+ /**
4618
+ * @public
4619
+ */
4620
+ declare interface UseRecordDocumentHistoryEventProps {
4621
+ documentId: string
4622
+ documentType: string
4623
+ resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
4624
+ resourceId?: string
4625
+ }
4557
4626
 
4558
4627
  /** @public */
4559
4628
  declare class UsersClient {