UNPKG

a0-purchases

Version:

Lightweight subscription management for AI apps with auto-detecting providers

113 lines (101 loc) 4.54 kB
/** * A0 Purchases - Unified In-App Purchase Library * * New Architecture: Single API, Cross-Platform, No Fragmentation */ // ============================================================================ // MAIN API - Single entry point for all purchases functionality // ============================================================================ export { purchasesService as Purchases } from './core/PurchasesService'; // ============================================================================ // REACT COMPONENTS // ============================================================================ export { A0PaymentProvider } from './A0PaymentProvider'; // React hooks and provider (for apps that need React integration) export { A0PurchaseProvider, useA0Purchases } from './react-hooks'; // ============================================================================ // UTILITIES & CONSTANTS // ============================================================================ export * from './constants'; // State management for advanced users export { commerceState } from './core/commerceState'; // Backend client for direct API access (advanced) export { backendClient } from './api/backendClient'; // User ID utilities export { isAnonymousUserId, ANONYMOUS_USER_PREFIX } from './storage'; // ============================================================================ // USAGE EXAMPLES // ============================================================================ /* // SIMPLE USAGE (React Native + Web) import { Purchases } from 'a0-purchases'; // Initialize once in your app await Purchases.initialize(); // Default: anonymous user, no debug logs // Or with custom user ID from your auth system: await Purchases.initialize({ appUserId: 'user123', // Your custom user ID debug: true // Enable debug logging }); // Check if user is anonymous const isAnonymous = Purchases.isAnonymous(); // Check premium status const isPremium = Purchases.isPremium(); // Purchase a package await Purchases.purchase('premium_monthly'); // Switch from anonymous to identified user (aliases/merges) if (Purchases.isAnonymous()) { await Purchases.logIn('user123'); // This merges the anonymous user } // Listen to state changes const unsubscribe = Purchases.subscribe((state) => { console.log('Premium status:', state.isPremium()); console.log('Customer info:', state.getCustomerInfo()); }); // REACT INTEGRATION import { A0PaymentProvider } from 'a0-purchases'; function App() { return ( <A0PaymentProvider> <MyComponent /> </A0PaymentProvider> ); } // API METHODS AVAILABLE: // - Purchases.initialize(config?) // One-time setup (config.debug = true for logs) // - Purchases.getCustomerInfo() // Current user info // - Purchases.getOfferings() // Available packages // - Purchases.isPremium() // Quick premium check // - Purchases.isAnonymous() // Check if user is anonymous // - Purchases.getUserId() // Get current user ID // - Purchases.purchase(packageId) // Buy a package // - Purchases.restore() // Restore purchases // - Purchases.refreshCustomerInfo() // Sync with backend // - Purchases.logIn(userId) // Sign in user (aliases if anonymous) // - Purchases.logOut() // Sign out // - Purchases.getManageSubscriptionUrl() // Manage subs // - Purchases.subscribe(listener) // State updates // - Purchases.destroy() // Cleanup // USER ID PATTERNS: // 1. Anonymous by default: // await Purchases.initialize(); // // User ID: "$AnonymousUser:abc123..." // // 2. Custom user ID from start: // await Purchases.initialize({ appUserId: 'user123' }); // // User ID: "user123" // // 3. Switch from anonymous to identified: // await Purchases.initialize(); // Start anonymous // // Later, after user signs up/in: // await Purchases.logIn('user123'); // Aliases anonymous->identified // MIGRATION FROM OLD SYSTEM: // OLD: import { initialize, getCustomerInfo, purchasePackage } from 'a0-purchases'; // NEW: import { Purchases } from 'a0-purchases'; // Purchases.initialize(), Purchases.getCustomerInfo(), Purchases.purchase() */ // ============================================================================ // DEFAULT EXPORT // ============================================================================ // Default export for: import Purchases from 'a0-purchases' export { purchasesService as default } from './core/PurchasesService'; //# sourceMappingURL=index.js.map