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

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 (97) hide show
  1. package/README.md +73 -34
  2. package/dist/_chunks-es/context.js +8 -0
  3. package/dist/_chunks-es/context.js.map +1 -0
  4. package/dist/_chunks-es/useLogOut.js +44 -0
  5. package/dist/_chunks-es/useLogOut.js.map +1 -0
  6. package/dist/components.d.ts +83 -0
  7. package/dist/components.js +132 -0
  8. package/dist/components.js.map +1 -0
  9. package/dist/context.d.ts +39 -0
  10. package/dist/context.js +5 -0
  11. package/dist/context.js.map +1 -0
  12. package/dist/hooks.d.ts +277 -0
  13. package/dist/hooks.js +153 -0
  14. package/dist/hooks.js.map +1 -0
  15. package/dist/index.d.ts +2 -4742
  16. package/dist/index.js +2 -1054
  17. package/dist/index.js.map +1 -1
  18. package/package.json +43 -22
  19. package/src/_exports/components.ts +2 -0
  20. package/src/_exports/context.ts +2 -0
  21. package/src/_exports/hooks.ts +21 -0
  22. package/src/_exports/index.ts +10 -66
  23. package/src/components/Login/LoginLinks.test.tsx +3 -2
  24. package/src/components/SanityApp.test.tsx +2 -104
  25. package/src/components/SanityApp.tsx +16 -80
  26. package/src/components/auth/AuthBoundary.test.tsx +10 -4
  27. package/src/components/auth/AuthBoundary.tsx +2 -18
  28. package/src/components/auth/Login.test.tsx +9 -2
  29. package/src/components/auth/Login.tsx +0 -1
  30. package/src/components/auth/LoginCallback.test.tsx +9 -2
  31. package/src/components/auth/LoginError.test.tsx +10 -2
  32. package/src/components/auth/LoginFooter.test.tsx +9 -2
  33. package/src/components/auth/LoginLayout.test.tsx +9 -2
  34. package/src/context/SanityProvider.test.tsx +1 -1
  35. package/src/context/SanityProvider.tsx +13 -21
  36. package/src/hooks/auth/useAuthState.tsx +5 -4
  37. package/src/hooks/auth/useAuthToken.tsx +1 -1
  38. package/src/hooks/auth/useCurrentUser.tsx +4 -27
  39. package/src/hooks/auth/useHandleCallback.tsx +0 -1
  40. package/src/hooks/auth/useLogOut.tsx +1 -1
  41. package/src/hooks/auth/useLoginUrls.tsx +0 -1
  42. package/src/hooks/client/useClient.test.tsx +130 -0
  43. package/src/hooks/client/useClient.ts +30 -8
  44. package/src/hooks/comlink/useFrameConnection.test.tsx +10 -55
  45. package/src/hooks/comlink/useFrameConnection.ts +47 -43
  46. package/src/hooks/comlink/useWindowConnection.test.ts +12 -53
  47. package/src/hooks/comlink/useWindowConnection.ts +33 -73
  48. package/src/hooks/context/useSanityInstance.test.tsx +1 -1
  49. package/src/hooks/context/useSanityInstance.ts +7 -23
  50. package/src/hooks/documentCollection/useDocuments.test.ts +130 -0
  51. package/src/hooks/documentCollection/useDocuments.ts +87 -0
  52. package/src/hooks/helpers/createCallbackHook.tsx +2 -3
  53. package/src/hooks/helpers/createStateSourceHook.test.tsx +0 -66
  54. package/src/hooks/helpers/createStateSourceHook.tsx +10 -29
  55. package/src/hooks/preview/usePreview.test.tsx +10 -19
  56. package/src/hooks/preview/usePreview.tsx +12 -66
  57. package/src/components/SDKProvider.test.tsx +0 -79
  58. package/src/components/SDKProvider.tsx +0 -42
  59. package/src/components/auth/authTestHelpers.tsx +0 -11
  60. package/src/components/utils.ts +0 -22
  61. package/src/context/SanityInstanceContext.ts +0 -4
  62. package/src/hooks/_synchronous-groq-js.mjs +0 -4
  63. package/src/hooks/auth/useDashboardOrganizationId.test.tsx +0 -42
  64. package/src/hooks/auth/useDashboardOrganizationId.tsx +0 -29
  65. package/src/hooks/comlink/useManageFavorite.test.ts +0 -106
  66. package/src/hooks/comlink/useManageFavorite.ts +0 -101
  67. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +0 -77
  68. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +0 -79
  69. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +0 -97
  70. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +0 -274
  71. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +0 -91
  72. package/src/hooks/datasets/useDatasets.ts +0 -37
  73. package/src/hooks/document/useApplyActions.test.ts +0 -25
  74. package/src/hooks/document/useApplyActions.ts +0 -74
  75. package/src/hooks/document/useDocument.test.ts +0 -81
  76. package/src/hooks/document/useDocument.ts +0 -107
  77. package/src/hooks/document/useDocumentEvent.test.ts +0 -63
  78. package/src/hooks/document/useDocumentEvent.ts +0 -54
  79. package/src/hooks/document/useDocumentSyncStatus.test.ts +0 -16
  80. package/src/hooks/document/useDocumentSyncStatus.ts +0 -30
  81. package/src/hooks/document/useEditDocument.test.ts +0 -179
  82. package/src/hooks/document/useEditDocument.ts +0 -195
  83. package/src/hooks/document/usePermissions.ts +0 -82
  84. package/src/hooks/infiniteList/useInfiniteList.test.tsx +0 -152
  85. package/src/hooks/infiniteList/useInfiniteList.ts +0 -174
  86. package/src/hooks/paginatedList/usePaginatedList.test.tsx +0 -259
  87. package/src/hooks/paginatedList/usePaginatedList.ts +0 -290
  88. package/src/hooks/projection/useProjection.test.tsx +0 -218
  89. package/src/hooks/projection/useProjection.ts +0 -147
  90. package/src/hooks/projects/useProject.ts +0 -45
  91. package/src/hooks/projects/useProjects.ts +0 -41
  92. package/src/hooks/query/useQuery.test.tsx +0 -188
  93. package/src/hooks/query/useQuery.ts +0 -103
  94. package/src/hooks/users/useUsers.test.ts +0 -163
  95. package/src/hooks/users/useUsers.ts +0 -107
  96. package/src/utils/getEnv.ts +0 -21
  97. package/src/version.ts +0 -8
package/README.md CHANGED
@@ -7,62 +7,101 @@
7
7
 
8
8
  React hooks for creating Sanity applications.
9
9
 
10
- ## 💻 Installation
10
+ ## Installation
11
11
 
12
12
  ```bash
13
13
  npm i @sanity/sdk-react @sanity/sdk
14
14
  ```
15
15
 
16
- > 💡 Looking to build a Sanity application? Check out the [Quick Start](#quick-start) section.
17
-
18
- ## 📚 SDK Documentation
16
+ ## SDK Documentation
19
17
 
20
18
  See the [SDK Documentation](https://sdk-docs.sanity.dev) for more information.
21
19
 
22
- ## 🚀 Quick Start
20
+ ## Quick Start
23
21
 
24
22
  Here's how to implement your Sanity application:
25
23
 
26
- 1. Create a new React TypeScript project using the Sanity template
27
-
28
24
  ```bash
29
- pnpx sanity@latest init --template app-quickstart
25
+ # Create a new Vite React TypeScript project
26
+ npm create vite@latest my-content-os-app -- --template react-ts -y
30
27
  cd my-content-os-app
28
+ # Install Sanity dependencies
29
+ npm i @sanity/sdk-react @sanity/sdk @sanity/ui
30
+ # Run the app
31
+ npm run dev
31
32
  ```
32
33
 
33
- 2. Install dependencies
34
-
35
- ```bash
36
- npm i
34
+ ```tsx
35
+ // src/App.tsx
36
+ import {createSanityInstance} from '@sanity/sdk'
37
+ import {SanityProvider} from '@sanity/sdk-react/context'
38
+ import {useCurrentUser, useLogOut} from '@sanity/sdk-react/hooks'
39
+ import {Button, Flex, Spinner, Text, ThemeProvider} from '@sanity/ui'
40
+ import {buildTheme} from '@sanity/ui/theme'
41
+ import {Suspense} from 'react'
42
+
43
+ const theme = buildTheme({})
44
+ const sanityInstance = createSanityInstance({
45
+ projectId: '<your-project-id>',
46
+ dataset: '<your-dataset>',
47
+ // optional auth config set projectId and dataset to '' and authScope to 'org' for a global token
48
+ // auth: {
49
+ // authScope: 'org',
50
+ // ...
51
+ // },
52
+ })
53
+
54
+ export function App(): JSX.Element {
55
+ return (
56
+ <ThemeProvider theme={theme}>
57
+ <Suspense fallback={<Spinner />}>
58
+ <SanityProvider sanityInstance={sanityInstance}>
59
+ {/* You will need to implement an auth boundary */}
60
+ <AuthBoundary header={<Text>My Sanity App</Text>}>
61
+ <Authenticated />
62
+ </AuthBoundary>
63
+ </SanityProvider>
64
+ </Suspense>
65
+ </ThemeProvider>
66
+ )
67
+ }
68
+
69
+ function Authenticated() {
70
+ const currentUser = useCurrentUser()
71
+ const logout = useLogOut()
72
+
73
+ return (
74
+ <Flex direction="column" gap={2}>
75
+ <Text>Hello, {currentUser?.name}!</Text>
76
+ <Button text="Logout" onClick={logout} mode="ghost" />
77
+ </Flex>
78
+ )
79
+ }
80
+
81
+ export default App
37
82
  ```
38
83
 
39
- 3. Run the app
40
-
41
- ```bash
42
- npm run dev
43
- ```
84
+ ## Available Hooks
44
85
 
45
- 4. Open the App in Sanity Dashboard with your organization ID
86
+ - `useAuthState` - Get current authentication state
87
+ - `useCurrentUser` - Access the currently authenticated user
88
+ - `useAuthToken` - Access the authentication token
89
+ - `useLoginUrls` - Get OAuth login URLs
90
+ - `useLogOut` - Handle user logout
91
+ - `useSanityInstance` - Access the Sanity client instance
92
+ - and more...
46
93
 
47
- ```
48
- https://core.sanity.io/<your-organization-id>?dev=http://localhost:3333
49
- ```
94
+ ## TypeScript Support
50
95
 
51
- 5. Update the `src/App.tsx` file with your Sanity project and dataset
96
+ This package includes TypeScript definitions. You can import types like:
52
97
 
53
98
  ```tsx
54
- // src/App.tsx
55
- import {createSanityInstance} from '@sanity/sdk'
56
- ...
57
-
58
- const sanityConfig: SanityConfigs = [
59
- {
60
- projectId: 'abc123',
61
- dataset: 'production',
62
- },
63
- ]
64
-
65
- ...
99
+ import type {
100
+ SanityProviderProps,
101
+ AuthBoundaryProps,
102
+ LoginLayoutProps,
103
+ LoginErrorProps,
104
+ } from '@sanity/react'
66
105
  ```
67
106
 
68
107
  ## License
@@ -0,0 +1,8 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext } from "react";
3
+ const SanityInstanceContext = createContext(null), SanityProvider = ({ children, sanityInstance }) => /* @__PURE__ */ jsx(SanityInstanceContext.Provider, { value: sanityInstance, children });
4
+ export {
5
+ SanityInstanceContext,
6
+ SanityProvider
7
+ };
8
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sources":["../../src/context/SanityProvider.tsx"],"sourcesContent":["import {type SanityInstance} from '@sanity/sdk'\nimport {createContext, type ReactElement} from 'react'\n\n/**\n * @public\n */\nexport interface SanityProviderProps {\n children: React.ReactNode\n sanityInstance: SanityInstance\n}\n\nexport const SanityInstanceContext = createContext<SanityInstance | null>(null)\n\n/**\n * Top-level context provider that provides a Sanity configuration instance.\n * This must wrap any Sanity SDK React component.\n * @public\n * @param props - Sanity project and dataset configuration\n * @returns Rendered component\n * @example\n * ```tsx\n * import {createSanityInstance} from '@sanity/sdk'\n * import {ExampleComponent, SanityProvider} from '@sanity/sdk-react'\n *\n * const sanityInstance = createSanityInstance({projectId: 'your-project-id', dataset: 'production'})\n *\n * export default function MyApp() {\n * return (\n * <SanityProvider sanityInstance={sanityInstance}>\n * <ExampleComponent />\n * </SanityProvider>\n * )\n * }\n * ```\n */\nexport const SanityProvider = ({children, sanityInstance}: SanityProviderProps): ReactElement => {\n return (\n <SanityInstanceContext.Provider value={sanityInstance}>\n {children}\n </SanityInstanceContext.Provider>\n )\n}\n"],"names":[],"mappings":";;AAWO,MAAM,wBAAwB,cAAqC,IAAI,GAwBjE,iBAAiB,CAAC,EAAC,UAAU,eAAc,0BAEnD,sBAAsB,UAAtB,EAA+B,OAAO,gBACpC,SACH,CAAA;"}
@@ -0,0 +1,44 @@
1
+ import { getAuthState, handleCallback, getLoginUrlsState, fetchLoginUrls, logout } from "@sanity/sdk";
2
+ import { useContext, useMemo, useSyncExternalStore, useCallback } from "react";
3
+ import { SanityInstanceContext } from "./context.js";
4
+ const useSanityInstance = () => {
5
+ const sanityInstance = useContext(SanityInstanceContext);
6
+ if (!sanityInstance)
7
+ throw new Error("useSanityInstance must be called from within the SanityProvider");
8
+ return sanityInstance;
9
+ };
10
+ function createStateSourceHook(stateSourceFactory) {
11
+ function useHook(...params) {
12
+ const instance = useSanityInstance(), { subscribe, getCurrent } = useMemo(
13
+ () => stateSourceFactory(instance, ...params),
14
+ // eslint-disable-next-line react-hooks/exhaustive-deps
15
+ [instance, ...params]
16
+ );
17
+ return useSyncExternalStore(subscribe, getCurrent);
18
+ }
19
+ return useHook;
20
+ }
21
+ const useAuthState = createStateSourceHook(getAuthState);
22
+ function createCallbackHook(callback) {
23
+ function useHook() {
24
+ const instance = useSanityInstance();
25
+ return useCallback((...params) => callback(instance, ...params), [instance]);
26
+ }
27
+ return useHook;
28
+ }
29
+ const useHandleCallback = createCallbackHook(handleCallback);
30
+ function useLoginUrls() {
31
+ const instance = useSanityInstance(), { subscribe, getCurrent } = useMemo(() => getLoginUrlsState(instance), [instance]);
32
+ if (!getCurrent()) throw fetchLoginUrls(instance);
33
+ return useSyncExternalStore(subscribe, getCurrent);
34
+ }
35
+ const useLogOut = createCallbackHook(logout);
36
+ export {
37
+ createStateSourceHook,
38
+ useAuthState,
39
+ useHandleCallback,
40
+ useLogOut,
41
+ useLoginUrls,
42
+ useSanityInstance
43
+ };
44
+ //# sourceMappingURL=useLogOut.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLogOut.js","sources":["../../src/hooks/context/useSanityInstance.ts","../../src/hooks/helpers/createStateSourceHook.tsx","../../src/hooks/auth/useAuthState.tsx","../../src/hooks/helpers/createCallbackHook.tsx","../../src/hooks/auth/useHandleCallback.tsx","../../src/hooks/auth/useLoginUrls.tsx","../../src/hooks/auth/useLogOut.tsx"],"sourcesContent":["import {type SanityInstance} from '@sanity/sdk'\nimport {useContext} from 'react'\n\nimport {SanityInstanceContext} from '../../context/SanityProvider'\n\n/**\n * Hook that provides the current Sanity instance from the context.\n * This must be called from within a `SanityProvider` component.\n * @public\n * @returns the current Sanity instance\n * @example\n * ```tsx\n * const instance = useSanityInstance()\n * ```\n */\nexport const useSanityInstance = (): SanityInstance => {\n const sanityInstance = useContext(SanityInstanceContext)\n if (!sanityInstance) {\n throw new Error('useSanityInstance must be called from within the SanityProvider')\n }\n\n return sanityInstance\n}\n","import {type SanityInstance, type StateSource} from '@sanity/sdk'\nimport {useMemo, useSyncExternalStore} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\nexport function createStateSourceHook<TParams extends unknown[], TState>(\n stateSourceFactory: (instance: SanityInstance, ...params: TParams) => StateSource<TState>,\n): (...params: TParams) => TState {\n function useHook(...params: TParams) {\n const instance = useSanityInstance()\n const {subscribe, getCurrent} = useMemo(\n () => stateSourceFactory(instance, ...params),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [instance, ...params],\n )\n\n return useSyncExternalStore(subscribe, getCurrent)\n }\n\n return useHook\n}\n","import {getAuthState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * A React hook that subscribes to authentication state changes.\n *\n * This hook provides access to the current authentication state type from the Sanity auth store.\n * It automatically re-renders the component when the authentication state changes.\n *\n * @remarks\n * The hook uses `useSyncExternalStore` to safely subscribe to auth state changes\n * and ensure consistency between server and client rendering.\n *\n * @returns The current authentication state type\n *\n * @example\n * ```tsx\n * function AuthStatus() {\n * const authState = useAuthState()\n * return <div>Current auth state: {authState}</div>\n * }\n * ```\n *\n * @public\n */\nexport const useAuthState = createStateSourceHook(getAuthState)\n","import {type SanityInstance} from '@sanity/sdk'\nimport {useCallback} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\nexport function createCallbackHook<TParams extends unknown[], TReturn>(\n callback: (instance: SanityInstance, ...params: TParams) => TReturn,\n): () => (...params: TParams) => TReturn {\n function useHook() {\n const instance = useSanityInstance()\n return useCallback((...params: TParams) => callback(instance, ...params), [instance])\n }\n\n return useHook\n}\n","import {handleCallback} from '@sanity/sdk'\n\nimport {createCallbackHook} from '../helpers/createCallbackHook'\n\n/**\n * A React hook that returns a function for handling authentication callbacks.\n *\n * @remarks\n * This hook provides access to the authentication store's callback handler,\n * which processes auth redirects by extracting the session ID and fetching the\n * authentication token. If fetching the long-lived token is successful,\n * `handleCallback` will return a Promise that resolves a new location that\n * removes the short-lived token from the URL. Use this in combination with\n * `history.replaceState` or your own router's `replace` function to update the\n * current location without triggering a reload.\n *\n * @example\n * ```tsx\n * function AuthCallback() {\n * const handleCallback = useHandleCallback()\n * const router = useRouter() // Example router\n *\n * useEffect(() => {\n * async function processCallback() {\n * // Handle the callback and get the cleaned URL\n * const newUrl = await handleCallback(window.location.href)\n *\n * if (newUrl) {\n * // Replace URL without triggering navigation\n * router.replace(newUrl, {shallow: true})\n * }\n * }\n *\n * processCallback().catch(console.error)\n * }, [handleCallback, router])\n *\n * return <div>Completing login...</div>\n * }\n * ```\n *\n * @returns A callback handler function that processes OAuth redirects\n * @public\n */\nexport const useHandleCallback = createCallbackHook(handleCallback)\n","import {type AuthProvider, fetchLoginUrls, getLoginUrlsState} from '@sanity/sdk'\nimport {useMemo, useSyncExternalStore} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * A React hook that retrieves the available authentication provider URLs for login.\n *\n * @remarks\n * This hook fetches the login URLs from the Sanity auth store when the component mounts.\n * Each provider object contains information about an authentication method, including its URL.\n * The hook will suspend if the login URLs have not yet loaded.\n *\n * @example\n * ```tsx\n * // LoginProviders component that uses the hook\n * function LoginProviders() {\n * const providers = useLoginUrls()\n *\n * return (\n * <div>\n * {providers.map((provider) => (\n * <a key={provider.name} href={provider.url}>\n * Login with {provider.title}\n * </a>\n * ))}\n * </div>\n * )\n * }\n *\n * // Parent component with Suspense boundary\n * function LoginPage() {\n * return (\n * <Suspense fallback={<div>Loading authentication providers...</div>}>\n * <LoginProviders />\n * </Suspense>\n * )\n * }\n * ```\n *\n * @returns An array of {@link AuthProvider} objects containing login URLs and provider information\n * @public\n */\nexport function useLoginUrls(): AuthProvider[] {\n const instance = useSanityInstance()\n const {subscribe, getCurrent} = useMemo(() => getLoginUrlsState(instance), [instance])\n\n if (!getCurrent()) throw fetchLoginUrls(instance)\n\n return useSyncExternalStore(subscribe, getCurrent as () => AuthProvider[])\n}\n","import {logout} from '@sanity/sdk'\n\nimport {createCallbackHook} from '../helpers/createCallbackHook'\n\n/**\n * Hook to log out of the current session\n * @public\n * @returns A function to log out of the current session\n */\nexport const useLogOut = createCallbackHook(logout)\n"],"names":[],"mappings":";;;AAeO,MAAM,oBAAoB,MAAsB;AAC/C,QAAA,iBAAiB,WAAW,qBAAqB;AACvD,MAAI,CAAC;AACG,UAAA,IAAI,MAAM,iEAAiE;AAG5E,SAAA;AACT;ACjBO,SAAS,sBACd,oBACgC;AAChC,WAAS,WAAW,QAAiB;AACnC,UAAM,WAAW,kBAAkB,GAC7B,EAAC,WAAW,WAAc,IAAA;AAAA,MAC9B,MAAM,mBAAmB,UAAU,GAAG,MAAM;AAAA;AAAA,MAE5C,CAAC,UAAU,GAAG,MAAM;AAAA,IACtB;AAEO,WAAA,qBAAqB,WAAW,UAAU;AAAA,EAAA;AAG5C,SAAA;AACT;ACMa,MAAA,eAAe,sBAAsB,YAAY;ACrBvD,SAAS,mBACd,UACuC;AACvC,WAAS,UAAU;AACjB,UAAM,WAAW,kBAAkB;AAC5B,WAAA,YAAY,IAAI,WAAoB,SAAS,UAAU,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC;AAAA,EAAA;AAG/E,SAAA;AACT;AC6Ba,MAAA,oBAAoB,mBAAmB,cAAc;ACA3D,SAAS,eAA+B;AAC7C,QAAM,WAAW,qBACX,EAAC,WAAW,WAAU,IAAI,QAAQ,MAAM,kBAAkB,QAAQ,GAAG,CAAC,QAAQ,CAAC;AAErF,MAAI,CAAC,WAAA,EAAc,OAAM,eAAe,QAAQ;AAEzC,SAAA,qBAAqB,WAAW,UAAkC;AAC3E;ACzCa,MAAA,YAAY,mBAAmB,MAAM;"}
@@ -0,0 +1,83 @@
1
+ import {FallbackProps} from 'react-error-boundary'
2
+ import {JSX} from 'react'
3
+ import {SanityConfig} from '@sanity/sdk'
4
+
5
+ /**
6
+ * A component that handles authentication flow and error boundaries for a
7
+ * protected section of the application.
8
+ *
9
+ * @remarks
10
+ * This component manages different authentication states and renders the
11
+ * appropriate components based on that state.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * function App() {
16
+ * return (
17
+ * <AuthBoundary header={<MyLogo />}>
18
+ * <ProtectedContent />
19
+ * </AuthBoundary>
20
+ * )
21
+ * }
22
+ * ```
23
+ *
24
+ * @alpha
25
+ */
26
+ export declare function AuthBoundary({
27
+ LoginErrorComponent,
28
+ ...props
29
+ }: AuthBoundaryProps): React.ReactNode
30
+
31
+ /**
32
+ * @alpha
33
+ */
34
+ declare interface AuthBoundaryProps extends LoginLayoutProps {
35
+ /**
36
+ * Custom component to render the login screen.
37
+ * Receives all login layout props. Defaults to {@link Login}.
38
+ */
39
+ LoginComponent?: React.ComponentType<LoginLayoutProps>
40
+ /**
41
+ * Custom component to render during OAuth callback processing.
42
+ * Receives all login layout props. Defaults to {@link LoginCallback}.
43
+ */
44
+ CallbackComponent?: React.ComponentType<LoginLayoutProps>
45
+ /**
46
+ * Custom component to render when authentication errors occur.
47
+ * Receives login layout props and error boundary props. Defaults to
48
+ * {@link LoginError}
49
+ */
50
+ LoginErrorComponent?: React.ComponentType<LoginErrorProps>
51
+ }
52
+
53
+ /**
54
+ * @alpha
55
+ */
56
+ declare type LoginErrorProps = FallbackProps & LoginLayoutProps
57
+
58
+ /**
59
+ * @alpha
60
+ */
61
+ declare interface LoginLayoutProps {
62
+ /** Optional header content rendered at top of card */
63
+ header?: React.ReactNode
64
+ /** Optional footer content rendered below card. Defaults to an internal login footer */
65
+ footer?: React.ReactNode
66
+ /** Main content rendered in card body */
67
+ children?: React.ReactNode
68
+ }
69
+
70
+ /**
71
+ * @public
72
+ *
73
+ * @returns Rendered child component wrapped in a SanityProvider and AuthBoundary
74
+ */
75
+ export declare function SanityApp({
76
+ sanityConfig,
77
+ children,
78
+ }: {
79
+ children: React.ReactNode
80
+ sanityConfig: SanityConfig
81
+ }): JSX.Element
82
+
83
+ export {}
@@ -0,0 +1,132 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { AuthStateType, createSanityInstance } from "@sanity/sdk";
3
+ import { Fragment, Suspense, useEffect, useCallback, useMemo } from "react";
4
+ import { ErrorBoundary } from "react-error-boundary";
5
+ import { useLoginUrls, useHandleCallback, useLogOut, useAuthState } from "./_chunks-es/useLogOut.js";
6
+ import { SanityLogo } from "@sanity/logos";
7
+ import { SanityProvider } from "./_chunks-es/context.js";
8
+ class AuthError extends Error {
9
+ constructor(error) {
10
+ typeof error == "object" && error && "message" in error && typeof error.message == "string" ? super(error.message) : super(), this.cause = error;
11
+ }
12
+ }
13
+ const LINKS = [
14
+ {
15
+ url: "https://slack.sanity.io/",
16
+ i18nKey: "workspaces.community-title",
17
+ title: "Community"
18
+ },
19
+ {
20
+ url: "https://www.sanity.io/docs",
21
+ i18nKey: "workspaces.docs-title",
22
+ title: "Docs"
23
+ },
24
+ {
25
+ url: "https://www.sanity.io/legal/privacy",
26
+ i18nKey: "workspaces.privacy-title",
27
+ title: "Privacy"
28
+ },
29
+ {
30
+ url: "https://www.sanity.io",
31
+ i18nKey: "workspaces.sanity-io-title",
32
+ title: "sanity.io"
33
+ }
34
+ ];
35
+ function LoginFooter() {
36
+ return /* @__PURE__ */ jsxs("div", { className: "sc-login-footer", children: [
37
+ /* @__PURE__ */ jsx(SanityLogo, { className: "sc-login-footer__logo" }),
38
+ /* @__PURE__ */ jsx("ul", { className: "sc-login-footer__links", children: LINKS.map((link) => /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("li", { className: "sc-login-footer__link", children: /* @__PURE__ */ jsx("a", { href: link.url, target: "_blank", rel: "noopener noreferrer", children: link.title }) }) }, link.title)) })
39
+ ] });
40
+ }
41
+ function LoginLayout({
42
+ children,
43
+ footer = /* @__PURE__ */ jsx(LoginFooter, {}),
44
+ header
45
+ }) {
46
+ return /* @__PURE__ */ jsx("div", { className: "sc-login-layout", children: /* @__PURE__ */ jsxs("div", { className: "sc-login-layout__container", children: [
47
+ /* @__PURE__ */ jsxs("div", { className: "sc-login-layout__card", children: [
48
+ header && /* @__PURE__ */ jsx("div", { className: "sc-login-layout__card-header", children: header }),
49
+ children && /* @__PURE__ */ jsx("div", { className: "sc-login-layout__card-body", children })
50
+ ] }),
51
+ footer
52
+ ] }) });
53
+ }
54
+ function Login({ header, footer }) {
55
+ return /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: /* @__PURE__ */ jsxs("div", { className: "sc-login", children: [
56
+ /* @__PURE__ */ jsx("h1", { className: "sc-login__title", children: "Choose login provider" }),
57
+ /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { className: "sc-login__loading", children: "Loading\u2026" }), children: /* @__PURE__ */ jsx(Providers, {}) })
58
+ ] }) });
59
+ }
60
+ function Providers() {
61
+ const loginUrls = useLoginUrls();
62
+ return /* @__PURE__ */ jsx("div", { className: "sc-login-providers", children: loginUrls.map(({ title, url }) => /* @__PURE__ */ jsx("a", { href: url, children: title }, url)) });
63
+ }
64
+ function LoginCallback({ header, footer }) {
65
+ const handleCallback = useHandleCallback();
66
+ return useEffect(() => {
67
+ const url = new URL(location.href);
68
+ handleCallback(url.toString()).then((replacementLocation) => {
69
+ replacementLocation && history.replaceState(null, "", replacementLocation);
70
+ });
71
+ }, [handleCallback]), /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: /* @__PURE__ */ jsxs("div", { className: "sc-login-callback", children: [
72
+ /* @__PURE__ */ jsx("h1", { className: "sc-login-callback__title", children: "Logging you in\u2026" }),
73
+ /* @__PURE__ */ jsx("div", { className: "sc-login-callback__loading", children: "Loading\u2026" })
74
+ ] }) });
75
+ }
76
+ function LoginError({
77
+ error,
78
+ resetErrorBoundary,
79
+ header,
80
+ footer
81
+ }) {
82
+ if (!(error instanceof AuthError)) throw error;
83
+ const logout = useLogOut(), handleRetry = useCallback(async () => {
84
+ await logout(), resetErrorBoundary();
85
+ }, [logout, resetErrorBoundary]);
86
+ return /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
87
+ /* @__PURE__ */ jsxs("div", { className: "sc-login-error__content", children: [
88
+ /* @__PURE__ */ jsx("h2", { className: "sc-login-error__title", children: "Authentication Error" }),
89
+ /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: "Please try again or contact support if the problem persists." })
90
+ ] }),
91
+ /* @__PURE__ */ jsx("button", { className: "sc-login-error__button", onClick: handleRetry, children: "Retry" })
92
+ ] }) });
93
+ }
94
+ function AuthBoundary({
95
+ LoginErrorComponent = LoginError,
96
+ ...props
97
+ }) {
98
+ const { header, footer } = props, FallbackComponent = useMemo(() => function(fallbackProps) {
99
+ return /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps, header, footer });
100
+ }, [header, footer, LoginErrorComponent]);
101
+ return /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: /* @__PURE__ */ jsx(AuthSwitch, { ...props }) });
102
+ }
103
+ function AuthSwitch({
104
+ LoginComponent = Login,
105
+ CallbackComponent = LoginCallback,
106
+ children,
107
+ ...props
108
+ }) {
109
+ const authState = useAuthState();
110
+ switch (authState.type) {
111
+ case AuthStateType.ERROR:
112
+ throw new AuthError(authState.error);
113
+ case AuthStateType.LOGGING_IN:
114
+ return /* @__PURE__ */ jsx(CallbackComponent, { ...props });
115
+ case AuthStateType.LOGGED_IN:
116
+ return children;
117
+ default:
118
+ return /* @__PURE__ */ jsx(LoginComponent, { ...props });
119
+ }
120
+ }
121
+ function SanityApp({
122
+ sanityConfig,
123
+ children
124
+ }) {
125
+ const sanityInstance = createSanityInstance(sanityConfig);
126
+ return /* @__PURE__ */ jsx(SanityProvider, { sanityInstance, children: /* @__PURE__ */ jsx(AuthBoundary, { children }) });
127
+ }
128
+ export {
129
+ AuthBoundary,
130
+ SanityApp
131
+ };
132
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.js","sources":["../src/components/auth/AuthError.ts","../src/components/auth/LoginFooter.tsx","../src/components/auth/LoginLayout.tsx","../src/components/auth/Login.tsx","../src/components/auth/LoginCallback.tsx","../src/components/auth/LoginError.tsx","../src/components/auth/AuthBoundary.tsx","../src/components/SanityApp.tsx"],"sourcesContent":["/**\n * Error class for authentication-related errors. Wraps errors thrown during the\n * authentication flow.\n *\n * @remarks\n * This class provides a consistent error type for authentication failures while\n * preserving the original error as the cause. If the original error has a\n * message property, it will be used as the error message.\n *\n * @alpha\n */\nexport class AuthError extends Error {\n constructor(error: unknown) {\n if (\n typeof error === 'object' &&\n !!error &&\n 'message' in error &&\n typeof error.message === 'string'\n ) {\n super(error.message)\n } else {\n super()\n }\n\n this.cause = error\n }\n}\n","import {SanityLogo} from '@sanity/logos'\nimport {Fragment} from 'react'\n\nconst LINKS = [\n {\n url: 'https://slack.sanity.io/',\n i18nKey: 'workspaces.community-title',\n title: 'Community',\n },\n {\n url: 'https://www.sanity.io/docs',\n i18nKey: 'workspaces.docs-title',\n title: 'Docs',\n },\n {\n url: 'https://www.sanity.io/legal/privacy',\n i18nKey: 'workspaces.privacy-title',\n title: 'Privacy',\n },\n {\n url: 'https://www.sanity.io',\n i18nKey: 'workspaces.sanity-io-title',\n title: 'sanity.io',\n },\n]\n\n/**\n * Default footer component for login screens showing Sanity branding and legal\n * links.\n *\n * @alpha\n */\nexport function LoginFooter(): React.ReactNode {\n return (\n <div className=\"sc-login-footer\">\n <SanityLogo className=\"sc-login-footer__logo\" />\n\n <ul className=\"sc-login-footer__links\">\n {LINKS.map((link) => (\n <Fragment key={link.title}>\n <li className=\"sc-login-footer__link\">\n <a href={link.url} target=\"_blank\" rel=\"noopener noreferrer\">\n {link.title}\n </a>\n </li>\n </Fragment>\n ))}\n </ul>\n </div>\n )\n}\n","import {LoginFooter} from './LoginFooter'\n\n/**\n * @alpha\n */\nexport interface LoginLayoutProps {\n /** Optional header content rendered at top of card */\n header?: React.ReactNode\n\n /** Optional footer content rendered below card. Defaults to an internal login footer */\n footer?: React.ReactNode\n\n /** Main content rendered in card body */\n children?: React.ReactNode\n}\n\n/**\n * Layout component for login-related screens providing consistent styling and structure.\n * Renders content in a centered card with optional header and footer sections.\n *\n * Can be used to build custom login screens for the AuthBoundary component, including:\n * - Login provider selection (LoginComponent)\n * - OAuth callback handling (CallbackComponent)\n * - Error states (LoginErrorComponent)\n *\n * @example\n * ```tsx\n * // Custom login screen using the layout\n * function CustomLogin({header, footer}: LoginLayoutProps) {\n * return (\n * <LoginLayout\n * header={header}\n * footer={footer}\n * >\n * <CustomLoginContent />\n * </LoginLayout>\n * )\n * }\n *\n * // Use with AuthBoundary\n * <AuthBoundary\n * LoginComponent={CustomLogin}\n * header={<Logo />}\n * >\n * <ProtectedContent />\n * </AuthBoundary>\n * ```\n *\n * @alpha\n */\nexport function LoginLayout({\n children,\n footer = <LoginFooter />,\n header,\n}: LoginLayoutProps): React.ReactNode {\n return (\n <div className=\"sc-login-layout\">\n <div className=\"sc-login-layout__container\">\n <div className=\"sc-login-layout__card\">\n {header && <div className=\"sc-login-layout__card-header\">{header}</div>}\n\n {children && <div className=\"sc-login-layout__card-body\">{children}</div>}\n </div>\n\n {footer}\n </div>\n </div>\n )\n}\n","import {type JSX, Suspense} from 'react'\n\nimport {useLoginUrls} from '../../hooks/auth/useLoginUrls'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n * Login component that displays available authentication providers.\n * Renders a list of login options with a loading fallback while providers load.\n *\n * @alpha\n */\nexport function Login({header, footer}: LoginLayoutProps): JSX.Element {\n return (\n <LoginLayout header={header} footer={footer}>\n <div className=\"sc-login\">\n <h1 className=\"sc-login__title\">Choose login provider</h1>\n\n <Suspense fallback={<div className=\"sc-login__loading\">Loading…</div>}>\n <Providers />\n </Suspense>\n </div>\n </LoginLayout>\n )\n}\n\nfunction Providers() {\n const loginUrls = useLoginUrls()\n\n return (\n <div className=\"sc-login-providers\">\n {loginUrls.map(({title, url}) => (\n <a key={url} href={url}>\n {title}\n </a>\n ))}\n </div>\n )\n}\n","import {useEffect} from 'react'\n\nimport {useHandleCallback} from '../../hooks/auth/useHandleCallback'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n/**\n * Component shown during auth callback processing that handles login completion.\n * Automatically processes the auth callback when mounted and updates the URL\n * to remove callback parameters without triggering a page reload.\n *\n * @alpha\n */\nexport function LoginCallback({header, footer}: LoginLayoutProps): React.ReactNode {\n const handleCallback = useHandleCallback()\n\n useEffect(() => {\n const url = new URL(location.href)\n handleCallback(url.toString()).then((replacementLocation) => {\n if (replacementLocation) {\n // history API with `replaceState` is used to prevent a reload but still\n // remove the short-lived token from the URL\n history.replaceState(null, '', replacementLocation)\n }\n })\n }, [handleCallback])\n\n return (\n <LoginLayout header={header} footer={footer}>\n <div className=\"sc-login-callback\">\n <h1 className=\"sc-login-callback__title\">Logging you in…</h1>\n <div className=\"sc-login-callback__loading\">Loading…</div>\n </div>\n </LoginLayout>\n )\n}\n","import {useCallback} from 'react'\nimport {type FallbackProps} from 'react-error-boundary'\n\nimport {useLogOut} from '../../hooks/auth/useLogOut'\nimport {AuthError} from './AuthError'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n * @alpha\n */\nexport type LoginErrorProps = FallbackProps & LoginLayoutProps\n\n/**\n * Displays authentication error details and provides retry functionality.\n * Only handles {@link AuthError} instances - rethrows other error types.\n *\n * @alpha\n */\nexport function LoginError({\n error,\n resetErrorBoundary,\n header,\n footer,\n}: LoginErrorProps): React.ReactNode {\n if (!(error instanceof AuthError)) throw error\n const logout = useLogOut()\n\n const handleRetry = useCallback(async () => {\n await logout()\n resetErrorBoundary()\n }, [logout, resetErrorBoundary])\n\n return (\n <LoginLayout header={header} footer={footer}>\n <div className=\"sc-login-error\">\n <div className=\"sc-login-error__content\">\n <h2 className=\"sc-login-error__title\">Authentication Error</h2>\n <p className=\"sc-login-error__description\">\n Please try again or contact support if the problem persists.\n </p>\n </div>\n\n <button className=\"sc-login-error__button\" onClick={handleRetry}>\n Retry\n </button>\n </div>\n </LoginLayout>\n )\n}\n","import {AuthStateType} from '@sanity/sdk'\nimport {useMemo} from 'react'\nimport {ErrorBoundary, type FallbackProps} from 'react-error-boundary'\n\nimport {useAuthState} from '../../hooks/auth/useAuthState'\nimport {AuthError} from './AuthError'\nimport {Login} from './Login'\nimport {LoginCallback} from './LoginCallback'\nimport {LoginError, type LoginErrorProps} from './LoginError'\nimport {type LoginLayoutProps} from './LoginLayout'\n\n/**\n * @alpha\n */\ninterface AuthBoundaryProps extends LoginLayoutProps {\n /**\n * Custom component to render the login screen.\n * Receives all login layout props. Defaults to {@link Login}.\n */\n LoginComponent?: React.ComponentType<LoginLayoutProps>\n\n /**\n * Custom component to render during OAuth callback processing.\n * Receives all login layout props. Defaults to {@link LoginCallback}.\n */\n CallbackComponent?: React.ComponentType<LoginLayoutProps>\n\n /**\n * Custom component to render when authentication errors occur.\n * Receives login layout props and error boundary props. Defaults to\n * {@link LoginError}\n */\n LoginErrorComponent?: React.ComponentType<LoginErrorProps>\n}\n\n/**\n * A component that handles authentication flow and error boundaries for a\n * protected section of the application.\n *\n * @remarks\n * This component manages different authentication states and renders the\n * appropriate components based on that state.\n *\n * @example\n * ```tsx\n * function App() {\n * return (\n * <AuthBoundary header={<MyLogo />}>\n * <ProtectedContent />\n * </AuthBoundary>\n * )\n * }\n * ```\n *\n * @alpha\n */\nexport function AuthBoundary({\n LoginErrorComponent = LoginError,\n ...props\n}: AuthBoundaryProps): React.ReactNode {\n const {header, footer} = props\n const FallbackComponent = useMemo(() => {\n return function LoginComponentWithLayoutProps(fallbackProps: FallbackProps) {\n return <LoginErrorComponent {...fallbackProps} header={header} footer={footer} />\n }\n }, [header, footer, LoginErrorComponent])\n\n return (\n <ErrorBoundary FallbackComponent={FallbackComponent}>\n <AuthSwitch {...props} />\n </ErrorBoundary>\n )\n}\n\ninterface AuthSwitchProps extends LoginLayoutProps {\n LoginComponent?: React.ComponentType<LoginLayoutProps>\n CallbackComponent?: React.ComponentType<LoginLayoutProps>\n}\n\nfunction AuthSwitch({\n LoginComponent = Login,\n CallbackComponent = LoginCallback,\n children,\n ...props\n}: AuthSwitchProps) {\n const authState = useAuthState()\n\n switch (authState.type) {\n case AuthStateType.ERROR: {\n throw new AuthError(authState.error)\n }\n case AuthStateType.LOGGING_IN: {\n return <CallbackComponent {...props} />\n }\n case AuthStateType.LOGGED_IN: {\n return children\n }\n default: {\n return <LoginComponent {...props} />\n }\n }\n}\n","import {createSanityInstance, type SanityConfig} from '@sanity/sdk'\nimport {type JSX} from 'react'\n\nimport {SanityProvider} from '../context/SanityProvider'\nimport {AuthBoundary} from './auth/AuthBoundary'\n\n/**\n * @public\n *\n * @returns Rendered child component wrapped in a SanityProvider and AuthBoundary\n */\nexport function SanityApp({\n sanityConfig,\n children,\n}: {\n children: React.ReactNode\n sanityConfig: SanityConfig\n}): JSX.Element {\n const sanityInstance = createSanityInstance(sanityConfig)\n\n return (\n <SanityProvider sanityInstance={sanityInstance}>\n <AuthBoundary>{children}</AuthBoundary>\n </SanityProvider>\n )\n}\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,39 @@
1
+ import {ReactElement} from 'react'
2
+ import {SanityInstance} from '@sanity/sdk'
3
+
4
+ /**
5
+ * Top-level context provider that provides a Sanity configuration instance.
6
+ * This must wrap any Sanity SDK React component.
7
+ * @public
8
+ * @param props - Sanity project and dataset configuration
9
+ * @returns Rendered component
10
+ * @example
11
+ * ```tsx
12
+ * import {createSanityInstance} from '@sanity/sdk'
13
+ * import {ExampleComponent, SanityProvider} from '@sanity/sdk-react'
14
+ *
15
+ * const sanityInstance = createSanityInstance({projectId: 'your-project-id', dataset: 'production'})
16
+ *
17
+ * export default function MyApp() {
18
+ * return (
19
+ * <SanityProvider sanityInstance={sanityInstance}>
20
+ * <ExampleComponent />
21
+ * </SanityProvider>
22
+ * )
23
+ * }
24
+ * ```
25
+ */
26
+ export declare const SanityProvider: ({
27
+ children,
28
+ sanityInstance,
29
+ }: SanityProviderProps) => ReactElement
30
+
31
+ /**
32
+ * @public
33
+ */
34
+ export declare interface SanityProviderProps {
35
+ children: React.ReactNode
36
+ sanityInstance: SanityInstance
37
+ }
38
+
39
+ export {}
@@ -0,0 +1,5 @@
1
+ import { SanityProvider } from "./_chunks-es/context.js";
2
+ export {
3
+ SanityProvider
4
+ };
5
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}