UNPKG

a0-purchases

Version:

Lightweight subscription management for AI apps with auto-detecting providers

87 lines 2.52 kB
import { PurchasesOfferings } from '../revenuecat-types'; import { CustomerInfo, PurchaseSuccessResult, PurchasesConfig } from '../types'; declare class PurchasesService { private adapter; private initializationPromise; private stripePresenter; private config; private logEvent; private createError; private selectAdapter; /** * Initialize the purchases service * This is idempotent - multiple calls are safe * @param config - Optional configuration object * @param config.debug - Enable debug logging (default: false) */ initialize(config?: PurchasesConfig): Promise<void>; private _doInitialize; private ensureInitialized; /** * Get current offerings */ getOfferings(): PurchasesOfferings; /** * Get current customer info */ getCustomerInfo(): CustomerInfo | null; /** * Check if user has premium access */ isPremium(): boolean; /** * Check if the current user is anonymous */ isAnonymous(): boolean; /** * Get current user ID */ getUserId(): string | null; /** * Subscribe to state changes */ subscribe(listener: (state: any) => void): () => void; /** * Refresh customer info from backend */ refreshCustomerInfo(): Promise<CustomerInfo | null>; /** * Purchase a package */ purchase(packageId: string): Promise<PurchaseSuccessResult>; /** * Restore purchases (native only) */ restore(): Promise<CustomerInfo | null>; /** * Get manage subscription URL */ getManageSubscriptionUrl(): Promise<string>; /** * Log in with a new user ID * If the current user is anonymous, this will alias (merge) them with the new user */ logIn(newUserId: string): Promise<CustomerInfo | null>; /** * Log out current user */ logOut(): Promise<void>; /** * Auto-sync receipts in the background (called during initialization) * This ensures the backend always has the latest purchase state */ private autoSyncReceipts; /** * Register a Stripe presenter component (for backward compatibility) */ registerStripePresenter(presenter: { requestPresentation: (request: any) => void; } | null): void; /** * Destroy the service and clean up resources */ destroy(): void; } export declare const purchasesService: PurchasesService; export {}; //# sourceMappingURL=PurchasesService.d.ts.map