@umituz/react-native-subscription 2.14.97 → 2.14.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +461 -0
  3. package/package.json +1 -3
  4. package/src/application/README.md +229 -0
  5. package/src/application/ports/README.md +103 -0
  6. package/src/domain/README.md +402 -0
  7. package/src/domain/constants/README.md +80 -0
  8. package/src/domain/entities/README.md +176 -0
  9. package/src/domain/errors/README.md +307 -0
  10. package/src/domain/value-objects/README.md +186 -0
  11. package/src/domains/README.md +240 -0
  12. package/src/domains/config/README.md +390 -0
  13. package/src/domains/config/domain/README.md +390 -0
  14. package/src/domains/config/domain/entities/README.md +350 -0
  15. package/src/domains/paywall/README.md +371 -0
  16. package/src/domains/paywall/components/PaywallHeader.tsx +8 -11
  17. package/src/domains/paywall/components/README.md +185 -0
  18. package/src/domains/paywall/entities/README.md +199 -0
  19. package/src/domains/paywall/hooks/README.md +129 -0
  20. package/src/domains/wallet/README.md +292 -0
  21. package/src/domains/wallet/domain/README.md +108 -0
  22. package/src/domains/wallet/domain/entities/README.md +122 -0
  23. package/src/domains/wallet/domain/errors/README.md +157 -0
  24. package/src/domains/wallet/infrastructure/README.md +96 -0
  25. package/src/domains/wallet/presentation/components/BalanceCard.tsx +6 -12
  26. package/src/domains/wallet/presentation/components/README.md +231 -0
  27. package/src/domains/wallet/presentation/hooks/README.md +255 -0
  28. package/src/infrastructure/README.md +514 -0
  29. package/src/infrastructure/mappers/README.md +34 -0
  30. package/src/infrastructure/models/README.md +26 -0
  31. package/src/infrastructure/repositories/README.md +385 -0
  32. package/src/infrastructure/services/README.md +374 -0
  33. package/src/presentation/README.md +410 -0
  34. package/src/presentation/components/README.md +183 -0
  35. package/src/presentation/components/details/CreditRow.md +337 -0
  36. package/src/presentation/components/details/DetailRow.md +283 -0
  37. package/src/presentation/components/details/PremiumDetailsCard.md +266 -0
  38. package/src/presentation/components/details/PremiumStatusBadge.md +266 -0
  39. package/src/presentation/components/details/README.md +449 -0
  40. package/src/presentation/components/feedback/PaywallFeedbackModal.md +314 -0
  41. package/src/presentation/components/feedback/README.md +447 -0
  42. package/src/presentation/components/paywall/PaywallModal.md +444 -0
  43. package/src/presentation/components/paywall/README.md +190 -0
  44. package/src/presentation/components/sections/README.md +468 -0
  45. package/src/presentation/components/sections/SubscriptionSection.md +246 -0
  46. package/src/presentation/hooks/README.md +743 -0
  47. package/src/presentation/hooks/useAuthAwarePurchase.md +359 -0
  48. package/src/presentation/hooks/useAuthGate.md +403 -0
  49. package/src/presentation/hooks/useAuthSubscriptionSync.md +398 -0
  50. package/src/presentation/hooks/useCreditChecker.md +407 -0
  51. package/src/presentation/hooks/useCredits.md +342 -0
  52. package/src/presentation/hooks/useCreditsGate.md +346 -0
  53. package/src/presentation/hooks/useDeductCredit.md +176 -0
  54. package/src/presentation/hooks/useDevTestCallbacks.md +422 -0
  55. package/src/presentation/hooks/useFeatureGate.md +157 -0
  56. package/src/presentation/hooks/useInitializeCredits.md +458 -0
  57. package/src/presentation/hooks/usePaywall.md +334 -0
  58. package/src/presentation/hooks/usePaywallOperations.md +486 -0
  59. package/src/presentation/hooks/usePaywallVisibility.md +344 -0
  60. package/src/presentation/hooks/usePremium.md +230 -0
  61. package/src/presentation/hooks/usePremiumGate.md +423 -0
  62. package/src/presentation/hooks/usePremiumWithCredits.md +429 -0
  63. package/src/presentation/hooks/useSubscription.md +450 -0
  64. package/src/presentation/hooks/useSubscriptionDetails.md +438 -0
  65. package/src/presentation/hooks/useSubscriptionGate.md +168 -0
  66. package/src/presentation/hooks/useSubscriptionSettingsConfig.md +374 -0
  67. package/src/presentation/hooks/useSubscriptionStatus.md +424 -0
  68. package/src/presentation/hooks/useUserTier.md +356 -0
  69. package/src/presentation/hooks/useUserTierWithRepository.md +452 -0
  70. package/src/presentation/screens/README.md +194 -0
  71. package/src/presentation/types/README.md +38 -0
  72. package/src/presentation/utils/README.md +52 -0
  73. package/src/revenuecat/README.md +523 -0
  74. package/src/revenuecat/application/README.md +158 -0
  75. package/src/revenuecat/application/ports/README.md +169 -0
  76. package/src/revenuecat/domain/README.md +147 -0
  77. package/src/revenuecat/domain/constants/README.md +183 -0
  78. package/src/revenuecat/domain/entities/README.md +382 -0
  79. package/src/revenuecat/domain/errors/README.md +197 -0
  80. package/src/revenuecat/domain/types/README.md +373 -0
  81. package/src/revenuecat/domain/value-objects/README.md +441 -0
  82. package/src/revenuecat/infrastructure/README.md +50 -0
  83. package/src/revenuecat/infrastructure/config/README.md +40 -0
  84. package/src/revenuecat/infrastructure/handlers/README.md +218 -0
  85. package/src/revenuecat/infrastructure/managers/README.md +49 -0
  86. package/src/revenuecat/infrastructure/services/README.md +325 -0
  87. package/src/revenuecat/infrastructure/utils/README.md +382 -0
  88. package/src/revenuecat/presentation/README.md +184 -0
  89. package/src/revenuecat/presentation/hooks/README.md +56 -0
  90. package/src/utils/README.md +529 -0
@@ -0,0 +1,169 @@
1
+ # RevenueCat Application Ports
2
+
3
+ Interface definitions for RevenueCat service layer.
4
+
5
+ ## Overview
6
+
7
+ This directory defines the ports (interfaces) that the RevenueCat infrastructure must implement. Following Dependency Inversion Principle, the application layer depends on these abstractions rather than concrete implementations.
8
+
9
+ ## Ports
10
+
11
+ ### IRevenueCatService
12
+
13
+ Core service interface for RevenueCat operations.
14
+
15
+ ```typescript
16
+ interface IRevenueCatService {
17
+ // Configuration
18
+ configure(params: {
19
+ apiKey: string;
20
+ userId?: string;
21
+ observerMode?: boolean;
22
+ }): Promise<void>;
23
+
24
+ // Purchasing Operations
25
+ purchasePackage(pkg: PurchasesPackage): Promise<PurchaseResult>;
26
+ purchaseProduct(productId: string): Promise<PurchaseResult>;
27
+ restorePurchases(): Promise<RestoreResult>;
28
+
29
+ // Customer Information
30
+ getCustomerInfo(): Promise<CustomerInfo>;
31
+ getCustomerInfoUserId(): string | null;
32
+
33
+ // Offerings
34
+ getOfferings(): Promise<Offerings>;
35
+ getCurrentOffering(): Promise<Offering | null>;
36
+
37
+ // Entitlements
38
+ checkEntitlement(entitlementId: string): Promise<boolean>;
39
+ checkEntitlementInfo(entitlementId: string): Promise<EntitlementInfo | null>;
40
+
41
+ // Subscriber Attributes
42
+ setAttributes(attributes: SubscriberAttributes): Promise<void>;
43
+ setEmail(email: string): Promise<void>;
44
+ setPhoneNumber(phoneNumber: string): Promise<void>;
45
+
46
+ // Log Out
47
+ logOut(): Promise<void>;
48
+ }
49
+ ```
50
+
51
+ ### IRevenueCatPurchaseHandler
52
+
53
+ Handles purchase callbacks and results.
54
+
55
+ ```typescript
56
+ interface IRevenueCatPurchaseHandler {
57
+ onPurchaseStarted?(package: PurchasesPackage): void;
58
+ onPurchaseSuccess?(result: PurchaseResult): void;
59
+ onPurchaseError?(error: PurchaseError): void;
60
+ onPurchaseCancelled?(result: PurchaseResult): void;
61
+ onRestoreStarted?(): void;
62
+ onRestoreSuccess?(result: RestoreResult): void;
63
+ onRestoreError?(error: Error): void;
64
+ }
65
+ ```
66
+
67
+ ### IRevenueCatCustomerInfoListener
68
+
69
+ Listens to customer info changes.
70
+
71
+ ```typescript
72
+ interface IRevenueCatCustomerInfoListener {
73
+ onCustomerInfoChanged(customerInfo: CustomerInfo): void;
74
+ onEntitlementsChanged(entitlements: EntitlementInfos): void;
75
+ }
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ ### Injecting Dependencies
81
+
82
+ ```typescript
83
+ import type { IRevenueCatService } from './ports/IRevenueCatService';
84
+
85
+ class PurchaseManager {
86
+ constructor(
87
+ private revenueCatService: IRevenueCatService
88
+ ) {}
89
+
90
+ async purchasePremium() {
91
+ const offerings = await this.revenueCatService.getOfferings();
92
+ const package = offerings.current?.monthly;
93
+
94
+ if (!package) {
95
+ throw new Error('No package available');
96
+ }
97
+
98
+ return await this.revenueCatService.purchasePackage(package);
99
+ }
100
+ }
101
+ ```
102
+
103
+ ### Implementing Ports
104
+
105
+ ```typescript
106
+ import type { IRevenueCatService } from './ports/IRevenueCatService';
107
+ import { Purchases } from '@revenuecat/purchases-capacitor';
108
+
109
+ class RevenueCatServiceImpl implements IRevenueCatService {
110
+ async configure(params: {
111
+ apiKey: string;
112
+ userId?: string;
113
+ observerMode?: boolean;
114
+ }): Promise<void> {
115
+ await Purchases.configure({
116
+ apiKey: params.apiKey,
117
+ appUserID: params.userId,
118
+ observerMode: params.observerMode ?? false,
119
+ });
120
+ }
121
+
122
+ async purchasePackage(pkg: PurchasesPackage): Promise<PurchaseResult> {
123
+ return await Purchases.purchasePackage({
124
+ aPackage: pkg,
125
+ });
126
+ }
127
+
128
+ // ... other implementations
129
+ }
130
+
131
+ // Provide implementation
132
+ const revenueCatService: IRevenueCatService = new RevenueCatServiceImpl();
133
+ ```
134
+
135
+ ## Benefits of Ports
136
+
137
+ 1. **Testability**: Easy to mock for testing
138
+ 2. **Flexibility**: Can swap implementations
139
+ 3. **Decoupling**: Application layer doesn't depend on concrete implementations
140
+ 4. **Maintainability**: Clear contracts between layers
141
+
142
+ ## Testing with Mocks
143
+
144
+ ```typescript
145
+ import type { IRevenueCatService } from './ports/IRevenueCatService';
146
+
147
+ const mockRevenueCatService: IRevenueCatService = {
148
+ configure: vi.fn().mockResolvedValue(undefined),
149
+ purchasePackage: vi.fn().mockResolvedValue({
150
+ customerInfo: mockCustomerInfo,
151
+ }),
152
+ restorePurchases: vi.fn().mockResolvedValue({
153
+ customerInfo: mockCustomerInfo,
154
+ }),
155
+ getCustomerInfo: vi.fn().mockResolvedValue(mockCustomerInfo),
156
+ getOfferings: vi.fn().mockResolvedValue(mockOfferings),
157
+ checkEntitlement: vi.fn().mockResolvedValue(true),
158
+ // ... other methods
159
+ };
160
+
161
+ // Use in tests
162
+ const manager = new PurchaseManager(mockRevenueCatService);
163
+ ```
164
+
165
+ ## Related
166
+
167
+ - [RevenueCat Application Layer](../README.md)
168
+ - [RevenueCat Infrastructure](../infrastructure/README.md)
169
+ - [RevenueCat Domain](../domain/README.md)
@@ -0,0 +1,147 @@
1
+ # RevenueCat Domain
2
+
3
+ Domain entities and types for RevenueCat integration.
4
+
5
+ ## Overview
6
+
7
+ This directory contains domain-specific entities representing RevenueCat concepts like entitlements, offerings, and packages.
8
+
9
+ ## Entities
10
+
11
+ ### EntitlementInfo
12
+ Represents a RevenueCat entitlement.
13
+
14
+ ```typescript
15
+ interface EntitlementInfo {
16
+ identifier: string;
17
+ isActive: boolean;
18
+ willRenew: boolean;
19
+ expirationDate?: Date;
20
+ productIdentifier?: string;
21
+ period?: PackagePeriod;
22
+ }
23
+ ```
24
+
25
+ **Usage:**
26
+ ```typescript
27
+ const entitlement: EntitlementInfo = {
28
+ identifier: 'premium',
29
+ isActive: true,
30
+ willRenew: true,
31
+ expirationDate: new Date('2024-12-31'),
32
+ productIdentifier: 'com.app.premium.annual',
33
+ period: 'annual',
34
+ };
35
+ ```
36
+
37
+ ### OfferingInfo
38
+ Represents a RevenueCat offering containing packages.
39
+
40
+ ```typescript
41
+ interface OfferingInfo {
42
+ identifier: string;
43
+ packages: PackageInfo[];
44
+ lifetime?: PackageInfo;
45
+ monthly?: PackageInfo;
46
+ annual?: PackageInfo;
47
+ }
48
+ ```
49
+
50
+ ### PackageInfo
51
+ Represents a purchasable package.
52
+
53
+ ```typescript
54
+ interface PackageInfo {
55
+ identifier: string;
56
+ packageType: PackageType;
57
+ product: ProductInfo;
58
+ offeringIdentifier: string;
59
+ }
60
+
61
+ interface ProductInfo {
62
+ identifier: string;
63
+ title: string;
64
+ description: string;
65
+ price: number;
66
+ pricePerMonth?: number;
67
+ currencyCode: string;
68
+ }
69
+
70
+ type PackageType = 'WEEKLY' | 'MONTHLY' | 'THREE_MONTHLY' | 'SIX_MONTHLY' | 'ANNUAL' | 'LIFETIME';
71
+ ```
72
+
73
+ ## Constants
74
+
75
+ ### Entitlement Identifiers
76
+
77
+ ```typescript
78
+ export const ENTITLEMENT_IDS = {
79
+ PREMIUM: 'premium',
80
+ PRO: 'pro',
81
+ BASIC: 'basic',
82
+ } as const;
83
+ ```
84
+
85
+ ### Package Periods
86
+
87
+ ```typescript
88
+ export const PACKAGE_PERIODS = {
89
+ WEEKLY: 'weekly',
90
+ MONTHLY: 'monthly',
91
+ ANNUAL: 'annual',
92
+ LIFETIME: 'lifetime',
93
+ } as const;
94
+ ```
95
+
96
+ ## Helper Functions
97
+
98
+ ### Get Package Period
99
+
100
+ ```typescript
101
+ function getPackagePeriod(packageType: PackageType): PackagePeriod {
102
+ const periodMap: Record<PackageType, PackagePeriod> = {
103
+ WEEKLY: 'monthly',
104
+ MONTHLY: 'monthly',
105
+ THREE_MONTHLY: 'monthly',
106
+ SIX_MONTHLY: 'monthly',
107
+ ANNUAL: 'annual',
108
+ LIFETIME: 'lifetime',
109
+ };
110
+ return periodMap[packageType];
111
+ }
112
+ ```
113
+
114
+ ### Calculate Price Per Month
115
+
116
+ ```typescript
117
+ function calculatePricePerMonth(packageInfo: PackageInfo): number | null {
118
+ if (!packageInfo.product.pricePerMonth) {
119
+ return packageInfo.product.price;
120
+ }
121
+ return packageInfo.product.pricePerMonth;
122
+ }
123
+ ```
124
+
125
+ ### Format Price
126
+
127
+ ```typescript
128
+ function formatPrice(price: number, currencyCode: string): string {
129
+ return new Intl.NumberFormat('en-US', {
130
+ style: 'currency',
131
+ currency: currencyCode,
132
+ }).format(price);
133
+ }
134
+ ```
135
+
136
+ ## Best Practices
137
+
138
+ 1. **Type Mapping**: Map RevenueCat types to domain types
139
+ 2. **Null Safety**: Handle optional properties safely
140
+ 3. **Validation**: Validate RevenueCat data
141
+ 4. **Formatting**: Format prices and dates consistently
142
+ 5. **Constants**: Use constants for identifiers
143
+
144
+ ## Related
145
+
146
+ - [RevenueCat README](../README.md)
147
+ - [Subscription Manager](../infrastructure/managers/README.md)
@@ -0,0 +1,183 @@
1
+ # RevenueCat Domain Constants
2
+
3
+ Constants used throughout the RevenueCat integration.
4
+
5
+ ## Overview
6
+
7
+ This directory contains constant definitions for RevenueCat-specific values including entitlement IDs, error codes, and configuration defaults.
8
+
9
+ ## Constants
10
+
11
+ ### Entitlement IDs
12
+
13
+ ```typescript
14
+ export const ENTITLEMENT_IDS = {
15
+ PREMIUM: 'premium',
16
+ PRO: 'pro',
17
+ LIFETIME: 'lifetime',
18
+ } as const;
19
+
20
+ export type EntitlementId = typeof ENTITLEMENT_IDS[keyof typeof ENTITLEMENT_IDS];
21
+ ```
22
+
23
+ ### Offering Identifiers
24
+
25
+ ```typescript
26
+ export const OFFERING_IDS = {
27
+ DEFAULT: 'default',
28
+ ANNUAL_OFFER: 'annual_offer',
29
+ LIFETIME_OFFER: 'lifetime_offer',
30
+ } as const;
31
+
32
+ export type OfferingId = typeof OFFERING_IDS[keyof typeof OFFERING_IDS];
33
+ ```
34
+
35
+ ### Package Periods
36
+
37
+ ```typescript
38
+ export const PACKAGE_PERIODS = {
39
+ MONTHLY: 'monthly',
40
+ ANNUAL: 'annual',
41
+ LIFETIME: 'lifetime',
42
+ WEEKLY: 'weekly',
43
+ } as const;
44
+
45
+ export type PackagePeriod = typeof PACKAGE_PERIODS[keyof typeof PACKAGE_PERIODS];
46
+ ```
47
+
48
+ ### Product Categories
49
+
50
+ ```typescript
51
+ export const PRODUCT_CATEGORIES = {
52
+ SUBSCRIPTION: 'subscription',
53
+ ONE_TIME_PURCHASE: 'non_subscription',
54
+ CONSUMABLE: 'consumable',
55
+ } as const;
56
+
57
+ export type ProductCategory = typeof PRODUCT_CATEGORIES[keyof typeof PRODUCT_CATEGORIES];
58
+ ```
59
+
60
+ ### Error Codes
61
+
62
+ ```typescript
63
+ export const ERROR_CODES = {
64
+ // Configuration Errors
65
+ CONFIGURATION_ERROR: 'CONFIGURATION_ERROR',
66
+ API_KEY_NOT_SET: 'API_KEY_NOT_SET',
67
+ INVALID_API_KEY: 'INVALID_API_KEY',
68
+
69
+ // Purchase Errors
70
+ PURCHASE_ERROR: 'PURCHASE_ERROR',
71
+ PURCHASE_CANCELLED: 'PURCHASE_CANCELLED',
72
+ PURCHASE_INVALID: 'PURCHASE_INVALID',
73
+ PRODUCT_NOT_AVAILABLE: 'PRODUCT_NOT_AVAILABLE',
74
+
75
+ // Network Errors
76
+ NETWORK_ERROR: 'NETWORK_ERROR',
77
+ CONNECTION_TIMEOUT: 'CONNECTION_TIMEOUT',
78
+ SERVER_ERROR: 'SERVER_ERROR',
79
+
80
+ // Customer Info Errors
81
+ CUSTOMER_INFO_ERROR: 'CUSTOMER_INFO_ERROR',
82
+ ENTITLEMENT_NOT_FOUND: 'ENTITLEMENT_NOT_FOUND',
83
+ OFFERING_NOT_FOUND: 'OFFERING_NOT_FOUND',
84
+
85
+ // Receipt Errors
86
+ RECEIPT_ERROR: 'RECEIPT_ERROR',
87
+ RECEIPT_INVALID: 'RECEIPT_INVALID',
88
+ RECEIPT_ALREADY_USED: 'RECEIPT_ALREADY_USES',
89
+
90
+ // User Errors
91
+ USER_NOT_AUTHENTICATED: 'USER_NOT_AUTHENTICATED',
92
+ USER_ID_NOT_SET: 'USER_ID_NOT_SET',
93
+ } as const;
94
+ ```
95
+
96
+ ### Configuration Defaults
97
+
98
+ ```typescript
99
+ export const CONFIG_DEFAULTS = {
100
+ // Timeout Settings
101
+ NETWORK_TIMEOUT_MS: 10000,
102
+ PURCHASE_TIMEOUT_MS: 30000,
103
+
104
+ // Retry Settings
105
+ MAX_RETRIES: 3,
106
+ RETRY_DELAY_MS: 1000,
107
+
108
+ // Cache Settings
109
+ CUSTOMER_INFO_CACHE_TTL_MS: 60000, // 1 minute
110
+ OFFERINGS_CACHE_TTL_MS: 300000, // 5 minutes
111
+
112
+ // Debug Settings
113
+ ENABLE_DEBUG_LOGS: __DEV__,
114
+ LOG_LEVEL: 'info' as const,
115
+ } as const;
116
+ ```
117
+
118
+ ### Entitlement Verification
119
+
120
+ ```typescript
121
+ export const ENTITLEMENT_VERIFICATION = {
122
+ // Verification Modes
123
+ MODE_STRICT: 'strict',
124
+ MODE_LOOSE: 'loose',
125
+
126
+ // Grace Periods (milliseconds)
127
+ GRACE_PERIOD_MS: 3 * 24 * 60 * 60 * 1000, // 3 days
128
+ REFUND_GRACE_PERIOD_MS: 7 * 24 * 60 * 60 * 1000, // 7 days
129
+ } as const;
130
+ ```
131
+
132
+ ## Usage Examples
133
+
134
+ ### Checking Entitlements
135
+
136
+ ```typescript
137
+ import { ENTITLEMENT_IDS } from './constants';
138
+
139
+ const hasPremium = await checkEntitlement(ENTITLEMENT_IDS.PREMIUM);
140
+ ```
141
+
142
+ ### Filtering Offerings
143
+
144
+ ```typescript
145
+ import { OFFERING_IDS } from './constants';
146
+
147
+ const defaultOffering = offerings[OFFERING_IDS.DEFAULT];
148
+ const annualOffering = offerings[OFFERING_IDS.ANNUAL_OFFER];
149
+ ```
150
+
151
+ ### Handling Errors
152
+
153
+ ```typescript
154
+ import { ERROR_CODES } from './constants';
155
+
156
+ try {
157
+ await purchasePackage(pkg);
158
+ } catch (error) {
159
+ if (error.code === ERROR_CODES.PURCHASE_CANCELLED) {
160
+ // Handle cancellation
161
+ } else if (error.code === ERROR_CODES.NETWORK_ERROR) {
162
+ // Handle network error
163
+ }
164
+ }
165
+ ```
166
+
167
+ ### Configuration
168
+
169
+ ```typescript
170
+ import { CONFIG_DEFAULTS } from './constants';
171
+
172
+ const config = {
173
+ apiKey: 'your_api_key',
174
+ timeout: CONFIG_DEFAULTS.NETWORK_TIMEOUT_MS,
175
+ enableDebugLogs: CONFIG_DEFAULTS.ENABLE_DEBUG_LOGS,
176
+ };
177
+ ```
178
+
179
+ ## Related
180
+
181
+ - [RevenueCat Domain](../README.md)
182
+ - [RevenueCat Errors](../errors/README.md)
183
+ - [RevenueCat Entities](../entities/README.md)