import {CheckScopesConsentResponse} from '@shopify/shop-minis-platform/actions' import {useShopActionQuery} from '../../internal/reactQuery' import {useShopActions} from '../../internal/useShopActions' export interface UseCheckScopesConsentReturns { /** * Required scopes declared by the mini, fetched fresh from the API. */ requiredScopes: string[] | undefined /** * Scopes already granted by the user. */ grantedScopes: string[] | undefined /** * Consent status derived from comparing required vs granted scopes. * * - `'granted'` — all required scopes are granted, or none declared * - `'partially_granted'` — at least one required scope is granted but not all * - `'not_granted'` — no required scopes are granted */ status: CheckScopesConsentResponse['status'] | undefined loading: boolean error: Error | null /** * Re-fetch scope consent status. Call this after `requestScopesConsent()` resolves * to get the updated status. */ refetch: () => Promise } export const useCheckScopesConsent = (): UseCheckScopesConsentReturns => { const {checkScopesConsent} = useShopActions() const {data, loading, error, refetch} = useShopActionQuery( ['scopesConsent'], checkScopesConsent, {} ) return { requiredScopes: data?.requiredScopes, grantedScopes: data?.grantedScopes, status: data?.status, loading, error, refetch, } } /** * Returns the current scope consent status for this mini, fetched fresh from the API on mount. * * Use `status` to branch UI on whether the user has granted all required scopes: * - `'granted'` — all required scopes are granted (or none declared) * - `'partially_granted'` — at least one required scope is granted but not all * - `'not_granted'` — no required scopes are granted * * Call `refetch()` after `requestScopesConsent()` resolves to get the updated status. * @publicDocs */ export type UseCheckScopesConsentGeneratedType = () => UseCheckScopesConsentReturns