@sanity/sdk-react 0.0.0-alpha.12 → 0.0.0-alpha.14
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.
- package/dist/_chunks-es/useLogOut.js +8 -4
- package/dist/_chunks-es/useLogOut.js.map +1 -1
- package/dist/components.d.ts +16 -0
- package/dist/components.js +11 -5
- package/dist/components.js.map +1 -1
- package/dist/hooks.d.ts +203 -31
- package/dist/hooks.js +65 -28
- package/dist/hooks.js.map +1 -1
- package/package.json +14 -15
- package/src/_exports/components.ts +1 -0
- package/src/_exports/hooks.ts +7 -1
- package/src/components/SDKProvider.test.tsx +79 -0
- package/src/components/SDKProvider.tsx +29 -0
- package/src/components/SanityApp.tsx +3 -9
- package/src/components/auth/AuthBoundary.tsx +10 -1
- package/src/hooks/auth/useCurrentUser.tsx +26 -21
- package/src/hooks/client/useClient.ts +4 -30
- package/src/hooks/datasets/useDatasets.ts +12 -0
- package/src/hooks/document/useDocument.ts +9 -16
- package/src/hooks/document/usePermissions.ts +38 -1
- package/src/hooks/documentCollection/types.ts +19 -0
- package/src/hooks/documentCollection/useDocuments.ts +2 -19
- package/src/hooks/documentCollection/useSearch.test.ts +100 -0
- package/src/hooks/documentCollection/useSearch.ts +75 -0
- package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
- package/src/hooks/helpers/createStateSourceHook.tsx +22 -5
- package/src/hooks/projects/useProject.ts +21 -0
- package/src/hooks/projects/useProjects.ts +19 -0
- package/src/hooks/users/useUsers.test.ts +163 -0
- package/src/hooks/users/useUsers.ts +107 -0
- package/src/hooks/client/useClient.test.tsx +0 -130
|
@@ -7,14 +7,18 @@ const useSanityInstance = () => {
|
|
|
7
7
|
throw new Error("useSanityInstance must be called from within the SanityProvider");
|
|
8
8
|
return sanityInstance;
|
|
9
9
|
};
|
|
10
|
-
function createStateSourceHook(
|
|
10
|
+
function createStateSourceHook(options) {
|
|
11
|
+
const getState = typeof options == "function" ? options : options.getState, suspense = "shouldSuspend" in options && "suspender" in options ? options : void 0;
|
|
11
12
|
function useHook(...params) {
|
|
12
|
-
const instance = useSanityInstance()
|
|
13
|
-
|
|
13
|
+
const instance = useSanityInstance();
|
|
14
|
+
if (suspense?.shouldSuspend(instance, ...params))
|
|
15
|
+
throw suspense.suspender(instance, ...params);
|
|
16
|
+
const state = useMemo(
|
|
17
|
+
() => getState(instance, ...params),
|
|
14
18
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
15
19
|
[instance, ...params]
|
|
16
20
|
);
|
|
17
|
-
return useSyncExternalStore(subscribe, getCurrent);
|
|
21
|
+
return useSyncExternalStore(state.subscribe, state.getCurrent);
|
|
18
22
|
}
|
|
19
23
|
return useHook;
|
|
20
24
|
}
|
|
@@ -1 +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 * `useSanityInstance` returns the current Sanity instance from the application context.\n * This must be called from within a `SanityProvider` component.\n * @internal\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\
|
|
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 * `useSanityInstance` returns the current Sanity instance from the application context.\n * This must be called from within a `SanityProvider` component.\n * @internal\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\ntype StateSourceFactory<TParams extends unknown[], TState> = (\n instance: SanityInstance,\n ...params: TParams\n) => StateSource<TState>\n\ninterface CreateStateSourceHookOptions<TParams extends unknown[], TState> {\n getState: StateSourceFactory<TParams, TState>\n shouldSuspend: (instance: SanityInstance, ...params: TParams) => boolean\n suspender: (instance: SanityInstance, ...params: TParams) => Promise<unknown>\n}\n\nexport function createStateSourceHook<TParams extends unknown[], TState>(\n options: StateSourceFactory<TParams, TState> | CreateStateSourceHookOptions<TParams, TState>,\n): (...params: TParams) => TState {\n const getState = typeof options === 'function' ? options : options.getState\n const suspense = 'shouldSuspend' in options && 'suspender' in options ? options : undefined\n\n function useHook(...params: TParams) {\n const instance = useSanityInstance()\n if (suspense?.shouldSuspend(instance, ...params)) {\n throw suspense.suspender(instance, ...params)\n }\n\n const state = useMemo(\n () => getState(instance, ...params),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [instance, ...params],\n )\n return useSyncExternalStore(state.subscribe, state.getCurrent)\n }\n\n return useHook\n}\n","import {type AuthState, getAuthState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * @internal\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 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 */\nexport const useAuthState: () => AuthState = 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 * @internal\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 * @internal\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 * @internal\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;ACNO,SAAS,sBACd,SACgC;AAChC,QAAM,WAAW,OAAO,WAAY,aAAa,UAAU,QAAQ,UAC7D,WAAW,mBAAmB,WAAW,eAAe,UAAU,UAAU;AAElF,WAAS,WAAW,QAAiB;AACnC,UAAM,WAAW,kBAAkB;AACnC,QAAI,UAAU,cAAc,UAAU,GAAG,MAAM;AAC7C,YAAM,SAAS,UAAU,UAAU,GAAG,MAAM;AAG9C,UAAM,QAAQ;AAAA,MACZ,MAAM,SAAS,UAAU,GAAG,MAAM;AAAA;AAAA,MAElC,CAAC,UAAU,GAAG,MAAM;AAAA,IACtB;AACA,WAAO,qBAAqB,MAAM,WAAW,MAAM,UAAU;AAAA,EAAA;AAGxD,SAAA;AACT;ACZa,MAAA,eAAgC,sBAAsB,YAAY;ACpBxE,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;AC8Ba,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;AC1Ca,MAAA,YAAY,mBAAmB,MAAM;"}
|
package/dist/components.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {FallbackProps} from 'react-error-boundary'
|
|
2
2
|
import {ReactElement} from 'react'
|
|
3
|
+
import {ReactNode} from 'react'
|
|
3
4
|
import {SanityConfig} from '@sanity/sdk'
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -107,4 +108,19 @@ export declare interface SanityAppProps {
|
|
|
107
108
|
children: React.ReactNode
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
/**
|
|
112
|
+
* @internal
|
|
113
|
+
*
|
|
114
|
+
* Top-level context provider that provides access to the Sanity SDK.
|
|
115
|
+
*/
|
|
116
|
+
export declare function SDKProvider({children, sanityConfig}: SDKProviderProps): ReactElement
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
export declare interface SDKProviderProps {
|
|
122
|
+
children: ReactNode
|
|
123
|
+
sanityConfig: SanityConfig
|
|
124
|
+
}
|
|
125
|
+
|
|
110
126
|
export {}
|
package/dist/components.js
CHANGED
|
@@ -94,7 +94,10 @@ function LoginError({
|
|
|
94
94
|
/* @__PURE__ */ jsx("button", { className: "sc-login-error__button", onClick: handleRetry, children: "Retry" })
|
|
95
95
|
] }) });
|
|
96
96
|
}
|
|
97
|
-
isInIframe()
|
|
97
|
+
if (isInIframe()) {
|
|
98
|
+
const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
|
|
99
|
+
script.src = mode === "core-ui--staging" ? "https://core.sanity-cdn.work/bridge.js" : "https://core.sanity-cdn.com/bridge.js", script.type = "module", script.async = !0, document.head.appendChild(script);
|
|
100
|
+
}
|
|
98
101
|
function AuthBoundary({
|
|
99
102
|
LoginErrorComponent = LoginError,
|
|
100
103
|
...props
|
|
@@ -122,16 +125,19 @@ function AuthSwitch({
|
|
|
122
125
|
return /* @__PURE__ */ jsx(LoginComponent, { ...props });
|
|
123
126
|
}
|
|
124
127
|
}
|
|
128
|
+
function SDKProvider({ children, sanityConfig }) {
|
|
129
|
+
const sanityInstance = createSanityInstance(sanityConfig);
|
|
130
|
+
return /* @__PURE__ */ jsx(SanityProvider, { sanityInstance, children: /* @__PURE__ */ jsx(AuthBoundary, { children }) });
|
|
131
|
+
}
|
|
125
132
|
function SanityApp({ sanityConfig, children }) {
|
|
126
|
-
isInIframe() && (sanityConfig.auth = {
|
|
133
|
+
return isInIframe() && (sanityConfig.auth = {
|
|
127
134
|
...sanityConfig.auth,
|
|
128
135
|
storageArea: void 0
|
|
129
|
-
});
|
|
130
|
-
const sanityInstance = createSanityInstance(sanityConfig);
|
|
131
|
-
return /* @__PURE__ */ jsx(SanityProvider, { sanityInstance, children: /* @__PURE__ */ jsx(AuthBoundary, { children }) });
|
|
136
|
+
}), /* @__PURE__ */ jsx(SDKProvider, { sanityConfig, children });
|
|
132
137
|
}
|
|
133
138
|
export {
|
|
134
139
|
AuthBoundary,
|
|
140
|
+
SDKProvider,
|
|
135
141
|
SanityApp
|
|
136
142
|
};
|
|
137
143
|
//# sourceMappingURL=components.js.map
|
package/dist/components.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../src/components/utils.ts","../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":["export function isInIframe(): boolean {\n return typeof window !== 'undefined' && window.self !== window.top\n}\n","/**\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 * @internal\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 {isInIframe} from '../utils'\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// Only import bridge if we're in an iframe. This assumes that the app is\n// running within SanityOS if it is in an iframe.\nif (isInIframe()) {\n import('@sanity/os/bridge')\n}\n\n/**\n * @internal\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 * @internal\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 ReactElement} from 'react'\n\nimport {SanityProvider} from '../context/SanityProvider'\nimport {AuthBoundary} from './auth/AuthBoundary'\nimport {isInIframe} from './utils'\n\n/**\n * @public\n */\nexport interface SanityAppProps {\n sanityConfig: SanityConfig\n children: React.ReactNode\n}\n\n/**\n * @public\n *\n * The SanityApp component provides your Sanity application with access to your Sanity configuration,\n * as well as application context and state which is used by the Sanity React hooks. Your application\n * must be wrapped with the SanityApp component to function properly.\n *\n * @param props - Your Sanity configuration and the React children to render\n * @returns Your Sanity application, integrated with your Sanity configuration and application context\n *\n * @example\n * ```\n * import { SanityApp } from '@sanity/sdk-react\n *\n * import MyAppRoot from './Root'\n *\n * const mySanityConfig = {\n * procectId: 'my-project-id',\n * dataset: 'production',\n * }\n *\n * export default function MyApp() {\n * return (\n * <SanityApp sanityConfig={mySanityConfig}>\n * <MyAppRoot />\n * </SanityApp>\n * )\n * }\n * ```\n */\nexport function SanityApp({sanityConfig, children}: SanityAppProps): ReactElement {\n if (isInIframe()) {\n // When running in an iframe Content OS, we don't want to store tokens\n sanityConfig.auth = {\n ...sanityConfig.auth,\n storageArea: undefined,\n }\n }\n const sanityInstance = createSanityInstance(sanityConfig)\n\n return (\n <SanityProvider sanityInstance={sanityInstance}>\n <AuthBoundary>{children}</AuthBoundary>\n </SanityProvider>\n )\n}\n"],"names":[],"mappings":";;;;;;;AAAO,SAAS,aAAsB;AACpC,SAAO,OAAO,SAAW,OAAe,OAAO,SAAS,OAAO;AACjE;ACSO,MAAM,kBAAkB,MAAM;AAAA,EACnC,YAAY,OAAgB;AAExB,WAAO,SAAU,YACf,SACF,aAAa,SACb,OAAO,MAAM,WAAY,WAEzB,MAAM,MAAM,OAAO,IAEnB,MAAM,GAGR,KAAK,QAAQ;AAAA,EAAA;AAEjB;ACvBA,MAAM,QAAQ;AAAA,EACZ;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EAAA;AAEX;AAQO,SAAS,cAA+B;AAE3C,SAAA,qBAAC,OAAI,EAAA,WAAU,mBACb,UAAA;AAAA,IAAC,oBAAA,Y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AAW,KACb,OAAO,mBAAmB;AAgDrB,SAAS,aAAa;AAAA,EAC3B,sBAAsB;AAAA,EACtB,GAAG;AACL,GAAuC;AAC/B,QAAA,EAAC,QAAQ,WAAU,OACnB,oBAAoB,QAAQ,MACzB,SAAuC,eAA8B;AAC1E,WAAQ,oBAAA,qBAAA,EAAqB,GAAG,eAAe,QAAgB,QAAgB;AAAA,EAEhF,GAAA,CAAC,QAAQ,QAAQ,mBAAmB,CAAC;AAExC,6BACG,eAAc,EAAA,mBACb,8BAAC,YAAY,EAAA,GAAG,MAAO,CAAA,GACzB;AAEJ;AAOA,SAAS,WAAW;AAAA,EAClB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB;AAAA,EACA,GAAG;AACL,GAAoB;AAClB,QAAM,YAAY,aAAa;AAE/B,UAAQ,UAAU,MAAM;AAAA,IACtB,KAAK,cAAc;AACX,YAAA,IAAI,UAAU,UAAU,KAAK;AAAA,IAErC,KAAK,cAAc;AACV,aAAA,oBAAC,mBAAmB,EAAA,GAAG,MAAO,CAAA;AAAA,IAEvC,KAAK,cAAc;AACV,aAAA;AAAA,IAET;AACS,aAAA,oBAAC,gBAAgB,EAAA,GAAG,MAAO,CAAA;AAAA,EAAA;AAGxC;AC/DO,SAAS,UAAU,EAAC,cAAc,YAAyC;AAC5E,aAEF,MAAA,aAAa,OAAO;AAAA,IAClB,GAAG,aAAa;AAAA,IAChB,aAAa;AAAA,EAAA;AAGX,QAAA,iBAAiB,qBAAqB,YAAY;AAExD,6BACG,gBAAe,EAAA,gBACd,UAAC,oBAAA,cAAA,EAAc,SAAS,CAAA,GAC1B;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../src/components/utils.ts","../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/SDKProvider.tsx","../src/components/SanityApp.tsx"],"sourcesContent":["export function isInIframe(): boolean {\n return typeof window !== 'undefined' && window.self !== window.top\n}\n","/**\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 * @internal\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 {isInIframe} from '../utils'\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// Only import bridge if we're in an iframe. This assumes that the app is\n// running within SanityOS if it is in an iframe.\nif (isInIframe()) {\n const parsedUrl = new URL(window.location.href)\n const mode = new URLSearchParams(parsedUrl.hash.slice(1)).get('mode')\n const script = document.createElement('script')\n script.src =\n mode === 'core-ui--staging'\n ? 'https://core.sanity-cdn.work/bridge.js'\n : 'https://core.sanity-cdn.com/bridge.js'\n script.type = 'module'\n script.async = true\n document.head.appendChild(script)\n}\n\n/**\n * @internal\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 * @internal\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 ReactElement, type ReactNode} from 'react'\n\nimport {SanityProvider} from '../context/SanityProvider'\nimport {AuthBoundary} from './auth/AuthBoundary'\n\n/**\n * @internal\n */\nexport interface SDKProviderProps {\n children: ReactNode\n sanityConfig: SanityConfig\n}\n\n// Marking this as internal since this should not be used directly by consumers\n/**\n * @internal\n *\n * Top-level context provider that provides access to the Sanity SDK.\n */\nexport function SDKProvider({children, sanityConfig}: SDKProviderProps): ReactElement {\n const sanityInstance = createSanityInstance(sanityConfig)\n\n return (\n <SanityProvider sanityInstance={sanityInstance}>\n <AuthBoundary>{children}</AuthBoundary>\n </SanityProvider>\n )\n}\n","import {type SanityConfig} from '@sanity/sdk'\nimport {type ReactElement} from 'react'\n\nimport {SDKProvider} from './SDKProvider'\nimport {isInIframe} from './utils'\n\n/**\n * @public\n */\nexport interface SanityAppProps {\n sanityConfig: SanityConfig\n children: React.ReactNode\n}\n\n/**\n * @public\n *\n * The SanityApp component provides your Sanity application with access to your Sanity configuration,\n * as well as application context and state which is used by the Sanity React hooks. Your application\n * must be wrapped with the SanityApp component to function properly.\n *\n * @param props - Your Sanity configuration and the React children to render\n * @returns Your Sanity application, integrated with your Sanity configuration and application context\n *\n * @example\n * ```\n * import { SanityApp } from '@sanity/sdk-react\n *\n * import MyAppRoot from './Root'\n *\n * const mySanityConfig = {\n * procectId: 'my-project-id',\n * dataset: 'production',\n * }\n *\n * export default function MyApp() {\n * return (\n * <SanityApp sanityConfig={mySanityConfig}>\n * <MyAppRoot />\n * </SanityApp>\n * )\n * }\n * ```\n */\nexport function SanityApp({sanityConfig, children}: SanityAppProps): ReactElement {\n if (isInIframe()) {\n // When running in an iframe Content OS, we don't want to store tokens\n sanityConfig.auth = {\n ...sanityConfig.auth,\n storageArea: undefined,\n }\n }\n\n return <SDKProvider sanityConfig={sanityConfig}>{children}</SDKProvider>\n}\n"],"names":[],"mappings":";;;;;;;AAAO,SAAS,aAAsB;AACpC,SAAO,OAAO,SAAW,OAAe,OAAO,SAAS,OAAO;AACjE;ACSO,MAAM,kBAAkB,MAAM;AAAA,EACnC,YAAY,OAAgB;AAExB,WAAO,SAAU,YACf,SACF,aAAa,SACb,OAAO,MAAM,WAAY,WAEzB,MAAM,MAAM,OAAO,IAEnB,MAAM,GAGR,KAAK,QAAQ;AAAA,EAAA;AAEjB;ACvBA,MAAM,QAAQ;AAAA,EACZ;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EAAA;AAEX;AAQO,SAAS,cAA+B;AAE3C,SAAA,qBAAC,OAAI,EAAA,WAAU,mBACb,UAAA;AAAA,IAAC,oBAAA,YAAA,EAAW,WAAU,wBAAwB,CAAA;AAAA,IAE7C,oBAAA,MAAA,EAAG,WAAU,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V,IAAA,oBAAC,aAAY,EAAA,cAA6B,SAAS,CAAA;AAC5D;"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -15,8 +15,10 @@ import {Observable} from 'rxjs'
|
|
|
15
15
|
import {PermissionsResult} from '@sanity/sdk'
|
|
16
16
|
import {PreviewValue} from '@sanity/sdk'
|
|
17
17
|
import {Requester} from 'get-it'
|
|
18
|
+
import {ResourceType} from '@sanity/sdk'
|
|
18
19
|
import {SanityDocument} from '@sanity/types'
|
|
19
20
|
import {SanityInstance} from '@sanity/sdk'
|
|
21
|
+
import {SanityUser as SanityUser_2} from '@sanity/sdk'
|
|
20
22
|
import {WindowMessage} from '@sanity/sdk'
|
|
21
23
|
|
|
22
24
|
/** @public */
|
|
@@ -516,7 +518,7 @@ declare type CreateAction = {
|
|
|
516
518
|
ifExists: 'fail' | 'ignore'
|
|
517
519
|
}
|
|
518
520
|
|
|
519
|
-
/** @
|
|
521
|
+
/** @public */
|
|
520
522
|
declare interface CurrentSanityUser {
|
|
521
523
|
id: string
|
|
522
524
|
name: string
|
|
@@ -527,10 +529,10 @@ declare interface CurrentSanityUser {
|
|
|
527
529
|
|
|
528
530
|
export {CurrentUser}
|
|
529
531
|
|
|
530
|
-
/** @
|
|
532
|
+
/** @public */
|
|
531
533
|
declare type DatasetAclMode = 'public' | 'private' | 'custom'
|
|
532
534
|
|
|
533
|
-
/** @
|
|
535
|
+
/** @public */
|
|
534
536
|
declare type DatasetResponse = {
|
|
535
537
|
datasetName: string
|
|
536
538
|
aclMode: DatasetAclMode
|
|
@@ -578,7 +580,7 @@ declare class DatasetsClient {
|
|
|
578
580
|
list(): Promise<DatasetsResponse>
|
|
579
581
|
}
|
|
580
582
|
|
|
581
|
-
/** @
|
|
583
|
+
/** @public */
|
|
582
584
|
declare type DatasetsResponse = {
|
|
583
585
|
name: string
|
|
584
586
|
aclMode: DatasetAclMode
|
|
@@ -2820,7 +2822,7 @@ declare interface SanityImagePalette {
|
|
|
2820
2822
|
title: string
|
|
2821
2823
|
}
|
|
2822
2824
|
|
|
2823
|
-
/** @
|
|
2825
|
+
/** @public */
|
|
2824
2826
|
declare interface SanityProject {
|
|
2825
2827
|
id: string
|
|
2826
2828
|
displayName: string
|
|
@@ -2848,7 +2850,7 @@ declare interface SanityProject {
|
|
|
2848
2850
|
}
|
|
2849
2851
|
}
|
|
2850
2852
|
|
|
2851
|
-
/** @
|
|
2853
|
+
/** @public */
|
|
2852
2854
|
declare interface SanityProjectMember {
|
|
2853
2855
|
id: string
|
|
2854
2856
|
role: string
|
|
@@ -2859,7 +2861,7 @@ declare interface SanityProjectMember {
|
|
|
2859
2861
|
/** @public */
|
|
2860
2862
|
declare interface SanityQueries {}
|
|
2861
2863
|
|
|
2862
|
-
/** @
|
|
2864
|
+
/** @public */
|
|
2863
2865
|
declare interface SanityUser {
|
|
2864
2866
|
id: string
|
|
2865
2867
|
projectId: string
|
|
@@ -2873,6 +2875,10 @@ declare interface SanityUser {
|
|
|
2873
2875
|
isCurrentUser: boolean
|
|
2874
2876
|
}
|
|
2875
2877
|
|
|
2878
|
+
declare interface SearchOptions extends DocumentListOptions {
|
|
2879
|
+
query?: string
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2876
2882
|
/** @internal */
|
|
2877
2883
|
declare interface SingleActionResult {
|
|
2878
2884
|
transactionId: string
|
|
@@ -3235,7 +3241,7 @@ export declare const useAuthToken: () => string | null
|
|
|
3235
3241
|
* @example
|
|
3236
3242
|
* ```tsx
|
|
3237
3243
|
* function MyComponent() {
|
|
3238
|
-
* const client = useClient()
|
|
3244
|
+
* const client = useClient({apiVersion: '2024-11-12'})
|
|
3239
3245
|
* const [document, setDocument] = useState(null)
|
|
3240
3246
|
* useEffect(async () => {
|
|
3241
3247
|
* const doc = client.fetch('*[_id == "myDocumentId"]')
|
|
@@ -3247,32 +3253,40 @@ export declare const useAuthToken: () => string | null
|
|
|
3247
3253
|
*
|
|
3248
3254
|
* @public
|
|
3249
3255
|
*/
|
|
3250
|
-
export declare
|
|
3256
|
+
export declare const useClient: (options: ClientOptions) => SanityClient
|
|
3257
|
+
|
|
3258
|
+
declare type UseCurrentUser = {
|
|
3259
|
+
/**
|
|
3260
|
+
* @public
|
|
3261
|
+
*
|
|
3262
|
+
* Provides the currently authenticated user’s profile information.
|
|
3263
|
+
*
|
|
3264
|
+
* @category Users
|
|
3265
|
+
* @returns The current user data
|
|
3266
|
+
*
|
|
3267
|
+
* @example Rendering a basic user profile
|
|
3268
|
+
* ```
|
|
3269
|
+
* const user = useCurrentUser()
|
|
3270
|
+
*
|
|
3271
|
+
* return (
|
|
3272
|
+
* <figure>
|
|
3273
|
+
* <img src={user?.profileImage} alt=`Profile image for ${user?.name}` />
|
|
3274
|
+
* <h2>{user?.name}</h2>
|
|
3275
|
+
* </figure>
|
|
3276
|
+
* )
|
|
3277
|
+
* ```
|
|
3278
|
+
*/
|
|
3279
|
+
(): CurrentUser | null
|
|
3280
|
+
}
|
|
3251
3281
|
|
|
3252
3282
|
/**
|
|
3253
|
-
* @TODO This should suspend! And possibly not return `null`?
|
|
3254
|
-
*
|
|
3255
3283
|
* @public
|
|
3256
|
-
*
|
|
3257
|
-
* Provides the currently authenticated user’s profile information (their name, email, roles, etc).
|
|
3258
|
-
* If no users are currently logged in, the hook returns null.
|
|
3259
|
-
*
|
|
3260
|
-
* @category Authentication
|
|
3261
|
-
* @returns The current user data, or `null` if not authenticated
|
|
3262
|
-
*
|
|
3263
|
-
* @example Rendering a basic user profile
|
|
3264
|
-
* ```
|
|
3265
|
-
* const user = useCurrentUser()
|
|
3266
|
-
*
|
|
3267
|
-
* return (
|
|
3268
|
-
* <figure>
|
|
3269
|
-
* <img src={user?.profileImage} alt=`Profile image for ${user?.name}` />
|
|
3270
|
-
* <h2>{user?.name}</h2>
|
|
3271
|
-
* </figure>
|
|
3272
|
-
* )
|
|
3273
|
-
* ```
|
|
3284
|
+
* @TODO This should not return null — users of a custom app will always be authenticated via Core
|
|
3274
3285
|
*/
|
|
3275
|
-
export declare const useCurrentUser:
|
|
3286
|
+
export declare const useCurrentUser: UseCurrentUser
|
|
3287
|
+
|
|
3288
|
+
/** @public */
|
|
3289
|
+
export declare const useDatasets: () => DatasetsResponse
|
|
3276
3290
|
|
|
3277
3291
|
/**
|
|
3278
3292
|
* @beta
|
|
@@ -3691,7 +3705,44 @@ export declare function useLoginUrls(): AuthProvider[]
|
|
|
3691
3705
|
*/
|
|
3692
3706
|
export declare const useLogOut: () => () => Promise<void>
|
|
3693
3707
|
|
|
3694
|
-
/**
|
|
3708
|
+
/**
|
|
3709
|
+
*
|
|
3710
|
+
* @beta
|
|
3711
|
+
*
|
|
3712
|
+
* Check if the current user has the specified permissions for the given document actions.
|
|
3713
|
+
*
|
|
3714
|
+
* @category Permissions
|
|
3715
|
+
* @param actions - One more more calls to a particular document action function for a given document
|
|
3716
|
+
* @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.
|
|
3717
|
+
*
|
|
3718
|
+
* @example Checking for permission to publish a document
|
|
3719
|
+
* ```ts
|
|
3720
|
+
* import {usePermissions, useApplyActions} from '@sanity/sdk-react'
|
|
3721
|
+
* import {publishDocument} from '@sanity/sdk'
|
|
3722
|
+
*
|
|
3723
|
+
* export function PublishButton({doc}: {doc: DocumentHandle}) {
|
|
3724
|
+
* const canPublish = usePermissions(publishDocument(doc))
|
|
3725
|
+
* const applyAction = useApplyActions()
|
|
3726
|
+
*
|
|
3727
|
+
* return (
|
|
3728
|
+
* <>
|
|
3729
|
+
* <button
|
|
3730
|
+
* disabled={!canPublish.allowed}
|
|
3731
|
+
* onClick={() => applyAction(publishDocument(doc))}
|
|
3732
|
+
* popoverTarget={`${canPublish.allowed ? undefined : 'publishButtonPopover'}`}
|
|
3733
|
+
* >
|
|
3734
|
+
* Publish
|
|
3735
|
+
* </button>
|
|
3736
|
+
* {!canPublish.allowed && (
|
|
3737
|
+
* <div popover id="publishButtonPopover">
|
|
3738
|
+
* {canPublish.message}
|
|
3739
|
+
* </div>
|
|
3740
|
+
* )}
|
|
3741
|
+
* </>
|
|
3742
|
+
* )
|
|
3743
|
+
* }
|
|
3744
|
+
* ```
|
|
3745
|
+
*/
|
|
3695
3746
|
export declare function usePermissions(
|
|
3696
3747
|
actions: DocumentAction | DocumentAction[],
|
|
3697
3748
|
): PermissionsResult
|
|
@@ -3765,6 +3816,12 @@ export declare interface UsePreviewResults {
|
|
|
3765
3816
|
isPending: boolean
|
|
3766
3817
|
}
|
|
3767
3818
|
|
|
3819
|
+
/** @public */
|
|
3820
|
+
export declare const useProject: (projectId: string) => SanityProject
|
|
3821
|
+
|
|
3822
|
+
/** @public */
|
|
3823
|
+
export declare const useProjects: () => Omit<SanityProject, 'members'>[]
|
|
3824
|
+
|
|
3768
3825
|
/** @public */
|
|
3769
3826
|
declare class UsersClient {
|
|
3770
3827
|
#private
|
|
@@ -3789,6 +3846,121 @@ declare class UsersClient {
|
|
|
3789
3846
|
*/
|
|
3790
3847
|
export declare const useSanityInstance: () => SanityInstance
|
|
3791
3848
|
|
|
3849
|
+
/**
|
|
3850
|
+
* @public
|
|
3851
|
+
* Hook for searching documents using full-text search.
|
|
3852
|
+
*
|
|
3853
|
+
* @param options - The options for the search.
|
|
3854
|
+
* @example
|
|
3855
|
+
* ```tsx
|
|
3856
|
+
* function SearchResults() {
|
|
3857
|
+
* const [query, setQuery] = useState('')
|
|
3858
|
+
* const {results, isPending} = useSearch({
|
|
3859
|
+
* filter: '_type == "book"',
|
|
3860
|
+
* query,
|
|
3861
|
+
* sort: [{field: '_createdAt', direction: 'desc'}]
|
|
3862
|
+
* })
|
|
3863
|
+
*
|
|
3864
|
+
* return (
|
|
3865
|
+
* <div>
|
|
3866
|
+
* <input
|
|
3867
|
+
* type="search"
|
|
3868
|
+
* value={query}
|
|
3869
|
+
* onChange={(e) => setQuery(e.target.value)}
|
|
3870
|
+
* placeholder="Search books..."
|
|
3871
|
+
* />
|
|
3872
|
+
* {isPending ? (
|
|
3873
|
+
* <div>Searching...</div>
|
|
3874
|
+
* ) : (
|
|
3875
|
+
* <ul>
|
|
3876
|
+
* {results.map((doc) => (
|
|
3877
|
+
* <li key={doc._id}>{doc._id}</li>
|
|
3878
|
+
* ))}
|
|
3879
|
+
* </ul>
|
|
3880
|
+
* )}
|
|
3881
|
+
* </div>
|
|
3882
|
+
* )
|
|
3883
|
+
* }
|
|
3884
|
+
* ```
|
|
3885
|
+
*/
|
|
3886
|
+
export declare function useSearch({
|
|
3887
|
+
query,
|
|
3888
|
+
filter: additionalFilter,
|
|
3889
|
+
...options
|
|
3890
|
+
}?: SearchOptions): DocumentHandleCollection
|
|
3891
|
+
|
|
3892
|
+
/**
|
|
3893
|
+
*
|
|
3894
|
+
* @public
|
|
3895
|
+
*
|
|
3896
|
+
* Retrieves the users for a given resource (either a project or an organization).
|
|
3897
|
+
*
|
|
3898
|
+
* @category Users
|
|
3899
|
+
* @param params - The resource type and its ID, and the limit of users to fetch
|
|
3900
|
+
* @returns A list of users, a boolean indicating whether there are more users to fetch, and a function to load more users
|
|
3901
|
+
*
|
|
3902
|
+
* @example
|
|
3903
|
+
* ```
|
|
3904
|
+
* const { users, hasMore, loadMore } = useUsers({
|
|
3905
|
+
* resourceType: 'organization',
|
|
3906
|
+
* resourceId: 'my-org-id',
|
|
3907
|
+
* limit: 10,
|
|
3908
|
+
* })
|
|
3909
|
+
*
|
|
3910
|
+
* return (
|
|
3911
|
+
* <div>
|
|
3912
|
+
* {users.map(user => (
|
|
3913
|
+
* <figure key={user.sanityUserId}>
|
|
3914
|
+
* <img src={user.profile.imageUrl} alt='' />
|
|
3915
|
+
* <figcaption>{user.profile.displayName}</figcaption>
|
|
3916
|
+
* <address>{user.profile.email}</address>
|
|
3917
|
+
* </figure>
|
|
3918
|
+
* ))}
|
|
3919
|
+
* {hasMore && <button onClick={loadMore}>Load More</button>}
|
|
3920
|
+
* </div>
|
|
3921
|
+
* )
|
|
3922
|
+
* ```
|
|
3923
|
+
*/
|
|
3924
|
+
export declare function useUsers(params: UseUsersParams): UseUsersResult
|
|
3925
|
+
|
|
3926
|
+
/**
|
|
3927
|
+
* @public
|
|
3928
|
+
* @category Users
|
|
3929
|
+
*/
|
|
3930
|
+
export declare interface UseUsersParams {
|
|
3931
|
+
/**
|
|
3932
|
+
* The type of resource to fetch users for.
|
|
3933
|
+
*/
|
|
3934
|
+
resourceType: ResourceType
|
|
3935
|
+
/**
|
|
3936
|
+
* The ID of the resource to fetch users for.
|
|
3937
|
+
*/
|
|
3938
|
+
resourceId: string
|
|
3939
|
+
/**
|
|
3940
|
+
* The limit of users to fetch.
|
|
3941
|
+
*/
|
|
3942
|
+
limit?: number
|
|
3943
|
+
}
|
|
3944
|
+
|
|
3945
|
+
/**
|
|
3946
|
+
* @public
|
|
3947
|
+
* @category Users
|
|
3948
|
+
*/
|
|
3949
|
+
export declare interface UseUsersResult {
|
|
3950
|
+
/**
|
|
3951
|
+
* The users fetched.
|
|
3952
|
+
*/
|
|
3953
|
+
users: SanityUser_2[]
|
|
3954
|
+
/**
|
|
3955
|
+
* Whether there are more users to fetch.
|
|
3956
|
+
*/
|
|
3957
|
+
hasMore: boolean
|
|
3958
|
+
/**
|
|
3959
|
+
* Load more users.
|
|
3960
|
+
*/
|
|
3961
|
+
loadMore: () => void
|
|
3962
|
+
}
|
|
3963
|
+
|
|
3792
3964
|
/**
|
|
3793
3965
|
* @internal
|
|
3794
3966
|
*/
|