@umituz/react-native-subscription 2.14.96 → 2.14.98
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.
- package/LICENSE +21 -0
- package/README.md +462 -0
- package/package.json +3 -3
- package/src/application/README.md +229 -0
- package/src/application/ports/README.md +103 -0
- package/src/domain/README.md +402 -0
- package/src/domain/constants/README.md +80 -0
- package/src/domain/entities/README.md +176 -0
- package/src/domain/errors/README.md +307 -0
- package/src/domain/value-objects/README.md +186 -0
- package/src/domains/config/README.md +390 -0
- package/src/domains/paywall/README.md +371 -0
- package/src/domains/paywall/components/PaywallHeader.tsx +8 -11
- package/src/domains/paywall/components/README.md +185 -0
- package/src/domains/paywall/entities/README.md +199 -0
- package/src/domains/paywall/hooks/README.md +129 -0
- package/src/domains/wallet/README.md +292 -0
- package/src/domains/wallet/domain/README.md +108 -0
- package/src/domains/wallet/domain/entities/README.md +122 -0
- package/src/domains/wallet/domain/errors/README.md +157 -0
- package/src/domains/wallet/infrastructure/README.md +96 -0
- package/src/domains/wallet/presentation/components/BalanceCard.tsx +6 -12
- package/src/domains/wallet/presentation/components/README.md +231 -0
- package/src/domains/wallet/presentation/hooks/README.md +255 -0
- package/src/infrastructure/README.md +514 -0
- package/src/infrastructure/mappers/README.md +34 -0
- package/src/infrastructure/models/README.md +26 -0
- package/src/infrastructure/repositories/README.md +385 -0
- package/src/infrastructure/services/README.md +374 -0
- package/src/presentation/README.md +410 -0
- package/src/presentation/components/README.md +183 -0
- package/src/presentation/components/details/CreditRow.md +337 -0
- package/src/presentation/components/details/DetailRow.md +283 -0
- package/src/presentation/components/details/PremiumDetailsCard.md +266 -0
- package/src/presentation/components/details/PremiumStatusBadge.md +266 -0
- package/src/presentation/components/details/README.md +449 -0
- package/src/presentation/components/feedback/PaywallFeedbackModal.md +314 -0
- package/src/presentation/components/feedback/README.md +447 -0
- package/src/presentation/components/paywall/PaywallModal.md +444 -0
- package/src/presentation/components/paywall/README.md +190 -0
- package/src/presentation/components/sections/README.md +468 -0
- package/src/presentation/components/sections/SubscriptionSection.md +246 -0
- package/src/presentation/hooks/README.md +743 -0
- package/src/presentation/hooks/useAuthAwarePurchase.md +359 -0
- package/src/presentation/hooks/useAuthGate.md +403 -0
- package/src/presentation/hooks/useAuthSubscriptionSync.md +398 -0
- package/src/presentation/hooks/useCreditChecker.md +407 -0
- package/src/presentation/hooks/useCredits.md +342 -0
- package/src/presentation/hooks/useCreditsGate.md +346 -0
- package/src/presentation/hooks/useDeductCredit.md +160 -0
- package/src/presentation/hooks/useDevTestCallbacks.md +422 -0
- package/src/presentation/hooks/useFeatureGate.md +157 -0
- package/src/presentation/hooks/useInitializeCredits.md +458 -0
- package/src/presentation/hooks/usePaywall.md +334 -0
- package/src/presentation/hooks/usePaywallOperations.md +486 -0
- package/src/presentation/hooks/usePaywallVisibility.md +344 -0
- package/src/presentation/hooks/usePremium.md +230 -0
- package/src/presentation/hooks/usePremiumGate.md +423 -0
- package/src/presentation/hooks/usePremiumWithCredits.md +429 -0
- package/src/presentation/hooks/useSubscription.md +450 -0
- package/src/presentation/hooks/useSubscriptionDetails.md +438 -0
- package/src/presentation/hooks/useSubscriptionGate.md +168 -0
- package/src/presentation/hooks/useSubscriptionSettingsConfig.md +374 -0
- package/src/presentation/hooks/useSubscriptionStatus.md +424 -0
- package/src/presentation/hooks/useUserTier.md +356 -0
- package/src/presentation/hooks/useUserTierWithRepository.md +452 -0
- package/src/presentation/screens/README.md +194 -0
- package/src/presentation/types/README.md +38 -0
- package/src/presentation/utils/README.md +52 -0
- package/src/revenuecat/README.md +523 -0
- package/src/revenuecat/domain/README.md +147 -0
- package/src/revenuecat/domain/errors/README.md +197 -0
- package/src/revenuecat/infrastructure/config/README.md +40 -0
- package/src/revenuecat/infrastructure/managers/README.md +49 -0
- package/src/revenuecat/presentation/hooks/README.md +56 -0
- package/src/revenuecat/presentation/hooks/usePurchasePackage.ts +1 -1
- package/src/utils/README.md +529 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# RevenueCat Domain Errors
|
|
2
|
+
|
|
3
|
+
Domain-specific errors for RevenueCat operations.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This directory contains custom error classes for RevenueCat-specific error conditions.
|
|
8
|
+
|
|
9
|
+
## Error Types
|
|
10
|
+
|
|
11
|
+
### PurchaseError
|
|
12
|
+
Base error for purchase failures.
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
class PurchaseError extends Error {
|
|
16
|
+
constructor(
|
|
17
|
+
message: string,
|
|
18
|
+
public code: string,
|
|
19
|
+
public underlyingError?: Error
|
|
20
|
+
) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = 'PurchaseError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Common Codes:**
|
|
28
|
+
- `PURCHASE_CANCELLED`: User cancelled purchase
|
|
29
|
+
- `PURCHASE_INVALID`: Invalid purchase data
|
|
30
|
+
- `NETWORK_ERROR`: Network connectivity issue
|
|
31
|
+
- `STORE_PROBLEM`: App store issue
|
|
32
|
+
|
|
33
|
+
### EntitlementNotFoundError
|
|
34
|
+
Thrown when expected entitlement is not found.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
class EntitlementNotFoundError extends Error {
|
|
38
|
+
constructor(public entitlementId: string) {
|
|
39
|
+
super(
|
|
40
|
+
`Entitlement not found: ${entitlementId}`,
|
|
41
|
+
'ENTITLEMENT_NOT_FOUND'
|
|
42
|
+
);
|
|
43
|
+
this.name = 'EntitlementNotFoundError';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Usage:**
|
|
49
|
+
```typescript
|
|
50
|
+
import { EntitlementNotFoundError } from './errors/EntitlementNotFoundError';
|
|
51
|
+
|
|
52
|
+
function getEntitlement(customerInfo: CustomerInfo, id: string): Entitlement {
|
|
53
|
+
const entitlement = customerInfo.entitlements.active[id];
|
|
54
|
+
if (!entitlement) {
|
|
55
|
+
throw new EntitlementNotFoundError(id);
|
|
56
|
+
}
|
|
57
|
+
return entitlement;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### ConfigurationError
|
|
62
|
+
Thrown when RevenueCat configuration is invalid.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
class ConfigurationError extends Error {
|
|
66
|
+
constructor(missingConfig: string[]) {
|
|
67
|
+
super(
|
|
68
|
+
`RevenueCat not configured: ${missingConfig.join(', ')}`,
|
|
69
|
+
'CONFIGURATION_ERROR'
|
|
70
|
+
);
|
|
71
|
+
this.name = 'ConfigurationError';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Usage:**
|
|
77
|
+
```typescript
|
|
78
|
+
function validateRevenueCatConfig(config: any) {
|
|
79
|
+
const required = ['apiKey'];
|
|
80
|
+
const missing = required.filter(key => !config[key]);
|
|
81
|
+
|
|
82
|
+
if (missing.length > 0) {
|
|
83
|
+
throw new ConfigurationError(missing);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### OfferingNotFoundError
|
|
89
|
+
Thrown when requested offering is not available.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
class OfferingNotFoundError extends Error {
|
|
93
|
+
constructor(public offeringId: string) {
|
|
94
|
+
super(
|
|
95
|
+
`Offering not found: ${offeringId}`,
|
|
96
|
+
'OFFERING_NOT_FOUND'
|
|
97
|
+
);
|
|
98
|
+
this.name = 'OfferingNotFoundError';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Error Handling Pattern
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import {
|
|
107
|
+
PurchaseError,
|
|
108
|
+
EntitlementNotFoundError,
|
|
109
|
+
ConfigurationError
|
|
110
|
+
} from './errors';
|
|
111
|
+
|
|
112
|
+
async function handlePurchase(package: Package) {
|
|
113
|
+
try {
|
|
114
|
+
const result = await Purchases.purchasePackage(package);
|
|
115
|
+
return { success: true, result };
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (error instanceof UserCancelledError) {
|
|
118
|
+
// User cancelled - not really an error
|
|
119
|
+
return { success: false, cancelled: true };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (error instanceof PurchaseError) {
|
|
123
|
+
switch (error.code) {
|
|
124
|
+
case 'PURCHASE_CANCELLED':
|
|
125
|
+
analytics.track('purchase_cancelled');
|
|
126
|
+
break;
|
|
127
|
+
case 'NETWORK_ERROR':
|
|
128
|
+
showRetryDialog();
|
|
129
|
+
break;
|
|
130
|
+
case 'STORE_PROBLEM':
|
|
131
|
+
showStoreProblemDialog();
|
|
132
|
+
break;
|
|
133
|
+
default:
|
|
134
|
+
showErrorDialog(error.message);
|
|
135
|
+
}
|
|
136
|
+
return { success: false, error };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Unexpected error
|
|
140
|
+
console.error('Unexpected purchase error:', error);
|
|
141
|
+
return { success: false, error };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Error Recovery
|
|
147
|
+
|
|
148
|
+
### Retry Logic
|
|
149
|
+
```typescript
|
|
150
|
+
async function purchaseWithRetry(pkg: Package, maxRetries = 3) {
|
|
151
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
152
|
+
try {
|
|
153
|
+
const result = await Purchases.purchasePackage(pkg);
|
|
154
|
+
return result;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error instanceof PurchaseError) {
|
|
157
|
+
if (error.code === 'NETWORK_ERROR' && i < maxRetries - 1) {
|
|
158
|
+
await delay(1000 * (i + 1)); // Exponential backoff
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### User-Friendly Messages
|
|
169
|
+
```typescript
|
|
170
|
+
function getUserFriendlyMessage(error: Error): string {
|
|
171
|
+
if (error instanceof PurchaseError) {
|
|
172
|
+
const messages: Record<string, string> = {
|
|
173
|
+
PURCHASE_CANCELLED: 'Purchase was cancelled',
|
|
174
|
+
NETWORK_ERROR: 'Network error. Please check your connection.',
|
|
175
|
+
STORE_PROBLEM: 'There was an issue with the app store.',
|
|
176
|
+
PURCHASE_INVALID: 'Purchase data is invalid.',
|
|
177
|
+
};
|
|
178
|
+
return messages[error.code] || 'An error occurred';
|
|
179
|
+
}
|
|
180
|
+
return error.message;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Best Practices
|
|
185
|
+
|
|
186
|
+
1. **Specific Errors**: Use specific error types
|
|
187
|
+
2. **Error Codes**: Include machine-readable codes
|
|
188
|
+
3. **Context**: Include relevant data in error
|
|
189
|
+
4. **Recovery**: Implement recovery strategies
|
|
190
|
+
5. **User Feedback**: Convert errors to user-friendly messages
|
|
191
|
+
6. **Logging**: Log errors for debugging
|
|
192
|
+
7. **Analytics**: Track errors for monitoring
|
|
193
|
+
|
|
194
|
+
## Related
|
|
195
|
+
|
|
196
|
+
- [RevenueCat Domain](../README.md)
|
|
197
|
+
- [RevenueCat Services](../infrastructure/services/README.md)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# RevenueCat Infrastructure Config
|
|
2
|
+
|
|
3
|
+
RevenueCat SDK configuration and initialization.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This directory contains configuration utilities and setup for the RevenueCat SDK.
|
|
8
|
+
|
|
9
|
+
## Contents
|
|
10
|
+
|
|
11
|
+
- **revenueCatConfig.ts** - RevenueCat configuration object and setup
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
interface RevenueCatConfig {
|
|
17
|
+
apiKey: string;
|
|
18
|
+
entitlementId: string;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Configure RevenueCat at app startup:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { revenueCatConfig } from './config/revenueCatConfig';
|
|
29
|
+
|
|
30
|
+
// In your app initializer
|
|
31
|
+
await Purchases.configure({
|
|
32
|
+
apiKey: revenueCatConfig.apiKey,
|
|
33
|
+
appUserID: userId,
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Related
|
|
38
|
+
|
|
39
|
+
- [Managers](../managers/README.md)
|
|
40
|
+
- [Services](../services/README.md)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# RevenueCat Infrastructure Managers
|
|
2
|
+
|
|
3
|
+
Manager classes for coordinating RevenueCat operations.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This directory contains high-level manager classes that coordinate between different RevenueCat services and handle complex operations.
|
|
8
|
+
|
|
9
|
+
## Contents
|
|
10
|
+
|
|
11
|
+
- **SubscriptionManager.ts** - Manages RevenueCat configuration and entitlement access
|
|
12
|
+
|
|
13
|
+
## SubscriptionManager
|
|
14
|
+
|
|
15
|
+
Manages RevenueCat SDK configuration and provides access to entitlement IDs.
|
|
16
|
+
|
|
17
|
+
### Key Methods
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
class SubscriptionManager {
|
|
21
|
+
static configure(config: RevenueCatConfig): void;
|
|
22
|
+
static getEntitlementId(): string | null;
|
|
23
|
+
static getOfferings(): Promise<Offerings>;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Usage
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { SubscriptionManager } from './managers/SubscriptionManager';
|
|
31
|
+
|
|
32
|
+
// Configure at app startup
|
|
33
|
+
SubscriptionManager.configure({
|
|
34
|
+
apiKey: 'your_api_key',
|
|
35
|
+
entitlementId: 'premium',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Get entitlement ID
|
|
39
|
+
const entitlementId = SubscriptionManager.getEntitlementId();
|
|
40
|
+
|
|
41
|
+
// Get offerings
|
|
42
|
+
const offerings = await SubscriptionManager.getOfferings();
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Related
|
|
46
|
+
|
|
47
|
+
- [Services](../services/README.md)
|
|
48
|
+
- [Config](../config/README.md)
|
|
49
|
+
- [Domain](../../domain/README.md)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# RevenueCat Presentation Hooks
|
|
2
|
+
|
|
3
|
+
React hooks for accessing RevenueCat data and operations.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This directory contains React hooks that expose RevenueCat functionality to the presentation layer.
|
|
8
|
+
|
|
9
|
+
## Contents
|
|
10
|
+
|
|
11
|
+
- **useCustomerInfo.ts** - Hook for accessing RevenueCat customer info
|
|
12
|
+
- **useSubscriptionPackages.ts** - Hook for accessing subscription packages/offering
|
|
13
|
+
|
|
14
|
+
## Key Hooks
|
|
15
|
+
|
|
16
|
+
### useCustomerInfo
|
|
17
|
+
|
|
18
|
+
Access RevenueCat customer information including entitlements.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
function useCustomerInfo() {
|
|
22
|
+
const { customerInfo, isLoading } = useCustomerInfo();
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<View>
|
|
26
|
+
<Text>Entitlements: {Object.keys(customerInfo.entitlements.active).join(', ')}</Text>
|
|
27
|
+
</View>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### useSubscriptionPackages
|
|
33
|
+
|
|
34
|
+
Access available subscription packages from current offering.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
function PackageList() {
|
|
38
|
+
const { packages, isLoading } = useSubscriptionPackages();
|
|
39
|
+
|
|
40
|
+
if (isLoading) return <Loading />;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<View>
|
|
44
|
+
{packages.map(pkg => (
|
|
45
|
+
<PackageCard key={pkg.identifier} package={pkg} />
|
|
46
|
+
))}
|
|
47
|
+
</View>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Related
|
|
53
|
+
|
|
54
|
+
- [Main Hooks](../../../presentation/hooks/README.md)
|
|
55
|
+
- [Domain](../../domain/README.md)
|
|
56
|
+
- [Services](../infrastructure/services/README.md)
|
|
@@ -10,7 +10,7 @@ import { SubscriptionManager } from "../../infrastructure/managers/SubscriptionM
|
|
|
10
10
|
import { SUBSCRIPTION_QUERY_KEYS } from "./subscriptionQueryKeys";
|
|
11
11
|
import { creditsQueryKeys } from "../../../presentation/hooks/useCredits";
|
|
12
12
|
|
|
13
|
-
interface PurchaseResult {
|
|
13
|
+
export interface PurchaseResult {
|
|
14
14
|
success: boolean;
|
|
15
15
|
productId: string;
|
|
16
16
|
}
|