@umituz/react-native-subscription 2.14.98 → 2.14.100
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/README.md +211 -395
- package/package.json +1 -1
- package/src/application/README.md +46 -225
- package/src/application/ports/README.md +42 -97
- package/src/domain/README.md +36 -384
- package/src/domain/constants/README.md +0 -56
- package/src/domain/entities/README.md +43 -169
- package/src/domain/errors/README.md +33 -287
- package/src/domain/value-objects/README.md +43 -179
- package/src/domains/README.md +52 -0
- package/src/domains/README.md.bak +274 -0
- package/src/domains/config/README.md +93 -383
- package/src/domains/config/domain/README.md +37 -0
- package/src/domains/config/domain/entities/README.md +41 -0
- package/src/domains/paywall/README.md +99 -369
- package/src/domains/paywall/components/README.md +34 -178
- package/src/domains/paywall/entities/README.md +34 -193
- package/src/domains/paywall/hooks/README.md +34 -122
- package/src/domains/wallet/README.md +34 -275
- package/src/domains/wallet/README.md.bak +209 -0
- package/src/domains/wallet/domain/README.md +34 -101
- package/src/domains/wallet/domain/entities/README.md +34 -115
- package/src/domains/wallet/domain/errors/README.md +34 -151
- package/src/domains/wallet/infrastructure/README.md +34 -89
- package/src/domains/wallet/presentation/components/README.md +34 -224
- package/src/domains/wallet/presentation/hooks/README.md +34 -248
- package/src/infrastructure/README.md +37 -496
- package/src/infrastructure/mappers/README.md +0 -13
- package/src/infrastructure/repositories/README.md +74 -360
- package/src/infrastructure/services/README.md +95 -370
- package/src/presentation/README.md +123 -408
- package/src/presentation/README.md.bak +172 -0
- package/src/presentation/components/README.md +151 -179
- package/src/presentation/components/README.md.bak +217 -0
- package/src/presentation/components/details/CreditRow.md +65 -310
- package/src/presentation/components/details/DetailRow.md +63 -255
- package/src/presentation/components/details/PremiumDetailsCard.md +65 -238
- package/src/presentation/components/details/PremiumStatusBadge.md +64 -239
- package/src/presentation/components/details/README.md +97 -447
- package/src/presentation/components/feedback/PaywallFeedbackModal.md +63 -287
- package/src/presentation/components/feedback/README.md +97 -445
- package/src/presentation/components/paywall/PaywallModal.md +66 -416
- package/src/presentation/components/paywall/README.md +50 -186
- package/src/presentation/components/sections/README.md +97 -466
- package/src/presentation/components/sections/SubscriptionSection.md +92 -244
- package/src/presentation/hooks/README.md +154 -741
- package/src/presentation/hooks/useAuthAwarePurchase.md +58 -325
- package/src/presentation/hooks/useAuthGate.md +61 -375
- package/src/presentation/hooks/useAuthSubscriptionSync.md +66 -370
- package/src/presentation/hooks/useCreditChecker.md +73 -378
- package/src/presentation/hooks/useCredits.md +74 -313
- package/src/presentation/hooks/useCredits.md.bak +231 -0
- package/src/presentation/hooks/useCreditsGate.md +66 -318
- package/src/presentation/hooks/useDeductCredit.md +96 -156
- package/src/presentation/hooks/useDevTestCallbacks.md +63 -394
- package/src/presentation/hooks/useFeatureGate.md +105 -150
- package/src/presentation/hooks/useFeatureGate.md.bak +284 -0
- package/src/presentation/hooks/useInitializeCredits.md +64 -430
- package/src/presentation/hooks/usePaywall.md +61 -306
- package/src/presentation/hooks/usePaywallOperations.md +64 -458
- package/src/presentation/hooks/usePaywallVisibility.md +67 -316
- package/src/presentation/hooks/usePremium.md +84 -226
- package/src/presentation/hooks/usePremiumGate.md +60 -395
- package/src/presentation/hooks/usePremiumWithCredits.md +64 -401
- package/src/presentation/hooks/useSubscription.md +66 -422
- package/src/presentation/hooks/useSubscriptionDetails.md +65 -410
- package/src/presentation/hooks/useSubscriptionGate.md +80 -164
- package/src/presentation/hooks/useSubscriptionSettingsConfig.md +66 -346
- package/src/presentation/hooks/useSubscriptionStatus.md +66 -396
- package/src/presentation/hooks/useUserTier.md +63 -328
- package/src/presentation/hooks/useUserTierWithRepository.md +64 -424
- package/src/presentation/screens/README.md +48 -190
- package/src/presentation/types/README.md +0 -16
- package/src/presentation/utils/README.md +0 -21
- package/src/revenuecat/README.md +99 -518
- package/src/revenuecat/application/README.md +43 -0
- package/src/revenuecat/application/ports/README.md +41 -0
- package/src/revenuecat/domain/README.md +42 -141
- package/src/revenuecat/domain/constants/README.md +41 -0
- package/src/revenuecat/domain/entities/README.md +42 -0
- package/src/revenuecat/domain/errors/README.md +47 -191
- package/src/revenuecat/domain/types/README.md +41 -0
- package/src/revenuecat/domain/value-objects/README.md +41 -0
- package/src/revenuecat/infrastructure/README.md +41 -0
- package/src/revenuecat/infrastructure/config/README.md +32 -23
- package/src/revenuecat/infrastructure/handlers/README.md +41 -0
- package/src/revenuecat/infrastructure/managers/README.md +34 -42
- package/src/revenuecat/infrastructure/services/README.md +42 -0
- package/src/revenuecat/infrastructure/utils/README.md +41 -0
- package/src/revenuecat/presentation/README.md +42 -0
- package/src/revenuecat/presentation/hooks/README.md +29 -35
- package/src/utils/README.md +38 -525
|
@@ -2,355 +2,90 @@
|
|
|
2
2
|
|
|
3
3
|
Hook for determining and tracking user tier (guest, free, premium).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Location
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import { useUserTier } from '@umituz/react-native-subscription';
|
|
9
|
-
```
|
|
7
|
+
**Import Path**: `@umituz/react-native-subscription`
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
**File**: `src/presentation/hooks/useUserTier.ts`
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
function useUserTier(): {
|
|
15
|
-
tier: UserTier;
|
|
16
|
-
isGuest: boolean;
|
|
17
|
-
isFree: boolean;
|
|
18
|
-
isPremium: boolean;
|
|
19
|
-
canUpgrade: boolean;
|
|
20
|
-
isLoading: boolean;
|
|
21
|
-
}
|
|
22
|
-
```
|
|
11
|
+
**Type**: Hook
|
|
23
12
|
|
|
24
|
-
##
|
|
13
|
+
## Strategy
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
|----------|------|-------------|
|
|
28
|
-
| `tier` | `'guest' \| 'free' \| 'premium'` | Current user tier |
|
|
29
|
-
| `isGuest` | `boolean` | User is not authenticated |
|
|
30
|
-
| `isFree` | `boolean` | User is authenticated but free |
|
|
31
|
-
| `isPremium` | `boolean` | User has premium subscription |
|
|
32
|
-
| `canUpgrade` | `boolean` | User can upgrade to premium |
|
|
33
|
-
| `isLoading` | `boolean` | Loading state |
|
|
15
|
+
### Tier Determination Flow
|
|
34
16
|
|
|
35
|
-
|
|
17
|
+
1. **Auth State Check**: Determine if user is authenticated
|
|
18
|
+
2. **Subscription Check**: Verify active subscription status
|
|
19
|
+
3. **Tier Assignment**: Assign tier based on auth + subscription
|
|
20
|
+
4. **Real-time Updates**: Update tier when auth or subscription changes
|
|
21
|
+
5. **Caching**: Cache tier status for performance
|
|
22
|
+
6. **Transition Tracking**: Monitor and track tier changes
|
|
36
23
|
|
|
37
|
-
###
|
|
38
|
-
- User is not authenticated
|
|
39
|
-
- No access to personalized features
|
|
40
|
-
- Limited functionality
|
|
24
|
+
### Integration Points
|
|
41
25
|
|
|
42
|
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
26
|
+
- **Auth Context**: User authentication state
|
|
27
|
+
- **Subscription Repository**: `src/infrastructure/repositories/SubscriptionRepository.ts`
|
|
28
|
+
- **Domain Layer**: `src/domain/entities/README.md`
|
|
29
|
+
- **TanStack Query**: For caching and real-time updates
|
|
46
30
|
|
|
47
|
-
|
|
48
|
-
- User has active subscription
|
|
49
|
-
- Full access to all features
|
|
50
|
-
- Priority support
|
|
31
|
+
## Restrictions
|
|
51
32
|
|
|
52
|
-
|
|
33
|
+
### REQUIRED
|
|
53
34
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
35
|
+
- **Tier Handling**: MUST handle all three tiers (guest, free, premium)
|
|
36
|
+
- **Loading State**: MUST handle loading state
|
|
37
|
+
- **Auth Integration**: MUST sync with authentication state
|
|
38
|
+
- **Guest Support**: MUST support unauthenticated users
|
|
57
39
|
|
|
58
|
-
|
|
59
|
-
<View>
|
|
60
|
-
<Badge>{tier.toUpperCase()}</Badge>
|
|
40
|
+
### PROHIBITED
|
|
61
41
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
</View>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
```
|
|
42
|
+
- **NEVER** assume user is authenticated (check isGuest)
|
|
43
|
+
- **NEVER** use for security decisions without server validation
|
|
44
|
+
- **DO NOT** hardcode tier values (use hook return values)
|
|
69
45
|
|
|
70
|
-
|
|
46
|
+
### CRITICAL SAFETY
|
|
71
47
|
|
|
72
|
-
|
|
48
|
+
- **ALWAYS** check loading state before using tier values
|
|
49
|
+
- **NEVER** trust client-side tier for security enforcement
|
|
50
|
+
- **MUST** handle tier transitions gracefully
|
|
51
|
+
- **ALWAYS** test with all three tier types
|
|
73
52
|
|
|
74
|
-
|
|
75
|
-
function TierBasedFeatures() {
|
|
76
|
-
const { tier } = useUserTier();
|
|
53
|
+
## AI Agent Guidelines
|
|
77
54
|
|
|
78
|
-
|
|
79
|
-
<View>
|
|
80
|
-
{/* Available to everyone */}
|
|
81
|
-
<BasicFeature />
|
|
55
|
+
### When Implementing Tier-Based Features
|
|
82
56
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
57
|
+
1. **Always** handle loading state before checking tier
|
|
58
|
+
2. **Always** handle all three tiers (guest, free, premium)
|
|
59
|
+
3. **Always** provide upgrade path for free users
|
|
60
|
+
4. **Never** show features to guests that require auth
|
|
61
|
+
5. **Always** track tier changes in analytics
|
|
87
62
|
|
|
88
|
-
|
|
89
|
-
{tier === 'premium' && (
|
|
90
|
-
<PremiumFeature />
|
|
91
|
-
)}
|
|
92
|
-
</View>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
```
|
|
63
|
+
### Integration Checklist
|
|
96
64
|
|
|
97
|
-
|
|
65
|
+
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
66
|
+
- [ ] Handle loading state
|
|
67
|
+
- [ ] Implement logic for guest users
|
|
68
|
+
- [ ] Implement logic for free users
|
|
69
|
+
- [ ] Implement logic for premium users
|
|
70
|
+
- [ ] Provide upgrade prompts for free users
|
|
71
|
+
- [ ] Provide auth prompts for guest users
|
|
72
|
+
- [ ] Test tier transitions (guest → free → premium)
|
|
73
|
+
- [ ] Test tier downgrade (premium → free)
|
|
74
|
+
- [ ] Track tier changes in analytics
|
|
98
75
|
|
|
99
|
-
|
|
100
|
-
function ProtectedScreen() {
|
|
101
|
-
const { tier, isLoading } = useUserTier();
|
|
76
|
+
### Common Patterns
|
|
102
77
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
78
|
+
1. **Conditional Rendering**: Show/hide features based on tier
|
|
79
|
+
2. **Navigation Guards**: Redirect based on tier requirements
|
|
80
|
+
3. **Feature Flags**: Enable features per tier
|
|
81
|
+
4. **Progress Indicators**: Show tier progression
|
|
82
|
+
5. **Upgrade Prompts**: Guide users to higher tiers
|
|
108
83
|
|
|
109
|
-
|
|
84
|
+
## Related Documentation
|
|
110
85
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
```typescript
|
|
118
|
-
function TierProgress() {
|
|
119
|
-
const { tier, canUpgrade } = useUserTier();
|
|
120
|
-
|
|
121
|
-
const tiers = ['guest', 'free', 'premium'];
|
|
122
|
-
const currentIndex = tiers.indexOf(tier);
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<View>
|
|
126
|
-
<Text>Current Tier: {tier}</Text>
|
|
127
|
-
|
|
128
|
-
<View style={styles.progress}>
|
|
129
|
-
{tiers.map((t, index) => (
|
|
130
|
-
<View
|
|
131
|
-
key={t}
|
|
132
|
-
style={[
|
|
133
|
-
styles.step,
|
|
134
|
-
index <= currentIndex && styles.activeStep,
|
|
135
|
-
]}
|
|
136
|
-
>
|
|
137
|
-
<Text>{t}</Text>
|
|
138
|
-
</View>
|
|
139
|
-
))}
|
|
140
|
-
</View>
|
|
141
|
-
|
|
142
|
-
{canUpgrade && (
|
|
143
|
-
<Button
|
|
144
|
-
onPress={() => navigation.navigate('Upgrade')}
|
|
145
|
-
title="Upgrade to Premium"
|
|
146
|
-
/>
|
|
147
|
-
)}
|
|
148
|
-
</View>
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## Examples
|
|
154
|
-
|
|
155
|
-
### Tier-Based Pricing
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
|
-
function PricingCards() {
|
|
159
|
-
const { tier } = useUserTier();
|
|
160
|
-
|
|
161
|
-
return (
|
|
162
|
-
<ScrollView horizontal>
|
|
163
|
-
<PricingCard
|
|
164
|
-
tier="free"
|
|
165
|
-
price="$0"
|
|
166
|
-
features={['Basic Access', 'Limited Storage']}
|
|
167
|
-
isCurrent={tier === 'free'}
|
|
168
|
-
/>
|
|
169
|
-
|
|
170
|
-
<PricingCard
|
|
171
|
-
tier="premium"
|
|
172
|
-
price="$9.99/mo"
|
|
173
|
-
features={[
|
|
174
|
-
'Full Access',
|
|
175
|
-
'Unlimited Storage',
|
|
176
|
-
'Priority Support',
|
|
177
|
-
'Ad-Free',
|
|
178
|
-
]}
|
|
179
|
-
isCurrent={tier === 'premium'}
|
|
180
|
-
popular
|
|
181
|
-
/>
|
|
182
|
-
</ScrollView>
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### Tier Indicator
|
|
188
|
-
|
|
189
|
-
```typescript
|
|
190
|
-
function TierIndicator() {
|
|
191
|
-
const { tier, isPremium } = useUserTier();
|
|
192
|
-
|
|
193
|
-
return (
|
|
194
|
-
<View style={[
|
|
195
|
-
styles.container,
|
|
196
|
-
isPremium && styles.premiumContainer,
|
|
197
|
-
]}>
|
|
198
|
-
{isPremium ? (
|
|
199
|
-
<>
|
|
200
|
-
<Icon name="crown" size={20} color="#FFD700" />
|
|
201
|
-
<Text style={styles.text}>PREMIUM</Text>
|
|
202
|
-
</>
|
|
203
|
-
) : (
|
|
204
|
-
<Text style={styles.text}>FREE</Text>
|
|
205
|
-
)}
|
|
206
|
-
</View>
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const styles = StyleSheet.create({
|
|
211
|
-
container: {
|
|
212
|
-
paddingHorizontal: 12,
|
|
213
|
-
paddingVertical: 6,
|
|
214
|
-
borderRadius: 16,
|
|
215
|
-
backgroundColor: '#E0E0E0',
|
|
216
|
-
},
|
|
217
|
-
premiumContainer: {
|
|
218
|
-
backgroundColor: '#FFD700',
|
|
219
|
-
},
|
|
220
|
-
text: {
|
|
221
|
-
fontWeight: 'bold',
|
|
222
|
-
fontSize: 12,
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
### Conditional Features
|
|
228
|
-
|
|
229
|
-
```typescript
|
|
230
|
-
function FeatureList() {
|
|
231
|
-
const { isGuest, isFree, isPremium } = useUserTier();
|
|
232
|
-
|
|
233
|
-
const features = [
|
|
234
|
-
{ name: 'Basic Search', available: true },
|
|
235
|
-
{ name: 'Save Favorites', available: !isGuest },
|
|
236
|
-
{ name: 'Advanced Filters', available: isFree || isPremium },
|
|
237
|
-
{ name: 'AI Recommendations', available: isPremium },
|
|
238
|
-
{ name: 'Priority Support', available: isPremium },
|
|
239
|
-
];
|
|
240
|
-
|
|
241
|
-
return (
|
|
242
|
-
<View>
|
|
243
|
-
{features.map((feature) => (
|
|
244
|
-
<FeatureItem
|
|
245
|
-
key={feature.name}
|
|
246
|
-
{...feature}
|
|
247
|
-
locked={!feature.available}
|
|
248
|
-
/>
|
|
249
|
-
))}
|
|
250
|
-
</View>
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
### Tier Transition Tracking
|
|
256
|
-
|
|
257
|
-
```typescript
|
|
258
|
-
function TierTransitionTracker() {
|
|
259
|
-
const { tier } = useUserTier();
|
|
260
|
-
const previousTier = useRef(tier);
|
|
261
|
-
|
|
262
|
-
useEffect(() => {
|
|
263
|
-
if (previousTier.current !== tier) {
|
|
264
|
-
analytics.track('tier_changed', {
|
|
265
|
-
from: previousTier.current,
|
|
266
|
-
to: tier,
|
|
267
|
-
timestamp: Date.now(),
|
|
268
|
-
});
|
|
269
|
-
previousTier.current = tier;
|
|
270
|
-
}
|
|
271
|
-
}, [tier]);
|
|
272
|
-
|
|
273
|
-
return <YourComponent />;
|
|
274
|
-
}
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
## Integration with Auth
|
|
278
|
-
|
|
279
|
-
```typescript
|
|
280
|
-
function TierWithAuth() {
|
|
281
|
-
const { user } = useAuth();
|
|
282
|
-
const { tier } = useUserTier();
|
|
283
|
-
|
|
284
|
-
// Tier updates automatically when auth state changes
|
|
285
|
-
useEffect(() => {
|
|
286
|
-
if (user) {
|
|
287
|
-
console.log(`Logged in as ${tier}`);
|
|
288
|
-
} else {
|
|
289
|
-
console.log('Logged out, now guest');
|
|
290
|
-
}
|
|
291
|
-
}, [user, tier]);
|
|
292
|
-
|
|
293
|
-
return (
|
|
294
|
-
<View>
|
|
295
|
-
<Text>Current tier: {tier}</Text>
|
|
296
|
-
<Text>User: {user?.email || 'Not logged in'}</Text>
|
|
297
|
-
</View>
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
## Testing
|
|
303
|
-
|
|
304
|
-
```typescript
|
|
305
|
-
describe('useUserTier', () => {
|
|
306
|
-
it('should return guest for unauthenticated user', () => {
|
|
307
|
-
const { result } = renderHook(() => useUserTier(), {
|
|
308
|
-
wrapper: ({ children }) => (
|
|
309
|
-
<AuthProvider value={{ user: null }}>{children}</AuthProvider>
|
|
310
|
-
),
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
expect(result.current.tier).toBe('guest');
|
|
314
|
-
expect(result.current.isGuest).toBe(true);
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it('should return premium for subscribed user', () => {
|
|
318
|
-
const { result } = renderHook(() => useUserTier(), {
|
|
319
|
-
wrapper: ({ children }) => (
|
|
320
|
-
<AuthProvider
|
|
321
|
-
value={{
|
|
322
|
-
user: { uid: '123' },
|
|
323
|
-
subscription: { type: 'premium', isActive: true },
|
|
324
|
-
}}
|
|
325
|
-
>
|
|
326
|
-
{children}
|
|
327
|
-
</AuthProvider>
|
|
328
|
-
),
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
expect(result.current.tier).toBe('premium');
|
|
332
|
-
expect(result.current.isPremium).toBe(true);
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
## Best Practices
|
|
338
|
-
|
|
339
|
-
1. **Handle all tiers** - Don't forget guest users
|
|
340
|
-
2. **Show upgrade prompts** - Guide free users to premium
|
|
341
|
-
3. **Track transitions** - Monitor tier changes
|
|
342
|
-
4. **Provide value** - Show benefits of upgrading
|
|
343
|
-
5. **Respect users** - Don't be too aggressive with upselling
|
|
344
|
-
6. **Test all tiers** - Ensure features work for each tier
|
|
345
|
-
|
|
346
|
-
## Related Hooks
|
|
347
|
-
|
|
348
|
-
- **useAuth** - Authentication state
|
|
349
|
-
- **usePremium** - Premium subscription check
|
|
350
|
-
- **useSubscription** - Subscription details
|
|
351
|
-
- **useAuthGate** - Auth + subscription gate
|
|
352
|
-
|
|
353
|
-
## See Also
|
|
354
|
-
|
|
355
|
-
- [User Tier Utils](../../../utils/README.md#user-tier-utilities)
|
|
356
|
-
- [Tier README](../../utils/README.md)
|
|
86
|
+
- **useAuth**: Authentication state
|
|
87
|
+
- **usePremium**: Premium subscription check
|
|
88
|
+
- **useSubscription**: Detailed subscription information
|
|
89
|
+
- **useAuthGate**: Authentication and subscription gating
|
|
90
|
+
- **Domain Entities**: `src/domain/entities/README.md`
|
|
91
|
+
- **User Tier Utils**: `src/utils/README.md`
|