UNPKG

@subscribe.dev/react

Version:

React hooks and components for SubscribeDev - provides context and hooks for managing AI predictions with billing and rate limiting

133 lines (117 loc) 4.07 kB
import { default as default_2 } from 'react'; import { JSX as JSX_2 } from 'react/jsx-runtime'; import { QueryClient } from '@tanstack/react-query'; import { SubscribeDevClient } from '@subscribe.dev/client'; declare interface AuthActions { initializeAuth: (props: { projectToken?: string; baseUrl?: string; authorizationUrl?: string; accessToken?: string; autoSignIn?: boolean; userToken?: string; getUserToken?: () => Promise<string>; }) => void; signIn: () => void; signOut: () => void; setSubscriptionModalUrl: (url: string | null) => void; handleAuthCallback: (accessToken: string) => void; _setPersistedToken: (token: string | null) => void; _setHasSignedOut: (hasSignedOut: boolean) => void; } declare interface AuthState { isReady: boolean; isSignedIn: boolean; token: string | null; user: UserObject_2 | null; client: SubscribeDevClient | null; hasSignedOut: boolean; subscriptionModalUrl: string | null; deferredAccessToken?: string; originalInitParams: { projectToken?: string; baseUrl?: string; authorizationUrl?: string; accessToken?: string; autoSignIn?: boolean; userToken?: string; getUserToken?: () => Promise<string>; } | null; canFetchUsage: boolean; canUseStorage: boolean; } /** * Check if we're running in a sandbox environment by looking at the URL */ export declare const isInSandbox: () => boolean; /** * Preload Subscribe.dev endpoints after user signs in * Only runs in sandbox environments (when URL contains "sandbox") */ export declare const preloadSubscribeDevPermissions: () => Promise<void>; declare interface SubscribeDevContextValue { client: SubscribeDevClient | null; token: string | null; user: UserObject | null; isSignedIn: boolean; queryClient: QueryClient; subscriptionModalUrl: string | null; setSubscriptionModalUrl: (url: string | null) => void; projectToken: string | undefined; effectiveApiKey: string | undefined; signIn: () => void; signOut: () => void; store: SubscribeDevStore; isDemoMode: boolean; } export declare function SubscribeDevProvider({ children, projectToken, project, baseUrl, authorizationUrl, accessToken, autoSignIn, getUserToken, onPublish, showDemoPublishBanner, }: SubscribeDevProviderProps): JSX_2.Element; declare interface SubscribeDevProviderProps { children: default_2.ReactNode; projectToken?: string; project?: string; baseUrl?: string; authorizationUrl?: string; accessToken?: string; autoSignIn?: boolean; getUserToken?: () => Promise<string>; onPublish?: () => void; showDemoPublishBanner?: boolean; } declare type SubscribeDevStore = AuthState & AuthActions; declare type SyncStatus = "local" | "syncing" | "synced" | "error"; export declare type UsageInfo = { allocatedCredits: number; usedCredits: number; remainingCredits: number; loading: boolean; error: string | null; refreshUsage: () => Promise<void>; }; export declare type UserObject = { userId: string; email: string; avatarUrl?: string; }; declare interface UserObject_2 { userId: string; email: string; avatarUrl?: string; } export declare function useSubscribeDev(): { client: SubscribeDevClient | null; token: string | null; user: UserObject | null; isSignedIn: boolean; signIn: () => void; signOut: () => void; subscribe: () => void; isSubscribed: boolean; subscriptionStatus: any; subscriptionLoading: boolean; refreshSubscriptionStatus: () => Promise<void>; useStorage: <T>(key: string, initialValue: T) => [T, (value: T) => void, SyncStatus]; usage: UsageInfo; canUseStorage: boolean; }; export declare function useSubscribeDevProvider(): SubscribeDevContextValue; export { }