import React from 'react'; import type { OneSubConfig, SubscriptionInfo, PurchaseInfo, EntitlementStatus } from '@onesub/shared'; export interface OneSubContextValue { isActive: boolean; isLoading: boolean; /** True until the active store mutation, including transaction cleanup, is complete. */ isBusy: boolean; subscription: SubscriptionInfo | null; subscribe: () => Promise; /** * Starts a subscription and returns only when this exact in-flight purchase * has passed server validation. Store cleanup may still be running; use * `isBusy` to keep every other purchase / restore action disabled. * Returns null when the user cancels or another IAP mutation is already busy. */ subscribeWithResult: () => Promise; restore: () => Promise; purchaseProduct: (productId: string, type: 'consumable' | 'non_consumable') => Promise<(PurchaseInfo & { action?: 'new' | 'restored'; }) | null>; /** * Restore a one-time purchase (non-consumable) from the store's history. * - Queries the native store for existing purchases * - If found, sends the receipt to the server for validation * - Server inserts into onesub_purchases if not already recorded * Returns the recorded PurchaseInfo on success, or null if the store has no * record of the product (i.e. the user never purchased). */ restoreProduct: (productId: string, type: 'consumable' | 'non_consumable') => Promise<(PurchaseInfo & { action?: 'new' | 'restored'; }) | null>; /** * Map of entitlement id → evaluation status, populated from the server. * Empty when the server has no entitlements configured. Auto-refreshed * after subscribe / restore / purchase / restoreProduct. */ entitlements: Record; /** Convenience: `entitlements[id]?.active === true`. */ hasEntitlement: (id: string) => boolean; /** Manually re-fetch the entitlements map. */ refreshEntitlements: () => Promise; } /** Server-validated result for the subscription request started by the caller. */ export interface SubscriptionPurchaseResult { subscription: SubscriptionInfo; } /** @internal */ export declare function useOneSubContext(): OneSubContextValue; export interface OneSubProviderProps { config: OneSubConfig; userId: string; /** * Stable account identity baked into each purchase (Apple `appAccountToken`, * Android `obfuscatedAccountId`). Bind this to an identity that survives * reinstall (e.g. a UUID derived from a hardware id hash) and is the SAME value * you pass as `userId`, so the server's validate route accepts the purchase. * Apple requires a UUID string. Omit to keep the previous unbound behavior. */ accountToken?: string; children: React.ReactNode; } export declare function OneSubProvider({ config, userId, accountToken, children }: OneSubProviderProps): React.JSX.Element; //# sourceMappingURL=OneSubProvider.d.ts.map