@umituz/react-native-subscription 2.14.99 → 2.14.101

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 (98) hide show
  1. package/README.md +211 -394
  2. package/package.json +3 -3
  3. package/src/application/README.md +46 -225
  4. package/src/application/ports/README.md +42 -97
  5. package/src/domain/README.md +36 -384
  6. package/src/domain/constants/README.md +0 -56
  7. package/src/domain/entities/README.md +43 -169
  8. package/src/domain/entities/SubscriptionStatus.ts +1 -1
  9. package/src/domain/errors/README.md +33 -287
  10. package/src/domain/value-objects/README.md +43 -179
  11. package/src/domains/README.md +50 -238
  12. package/src/domains/README.md.bak +274 -0
  13. package/src/domains/config/README.md +93 -383
  14. package/src/domains/config/domain/README.md +23 -376
  15. package/src/domains/config/domain/entities/README.md +34 -343
  16. package/src/domains/paywall/README.md +99 -369
  17. package/src/domains/paywall/components/README.md +34 -178
  18. package/src/domains/paywall/entities/README.md +34 -193
  19. package/src/domains/paywall/hooks/README.md +34 -122
  20. package/src/domains/wallet/README.md +34 -275
  21. package/src/domains/wallet/README.md.bak +209 -0
  22. package/src/domains/wallet/domain/README.md +34 -101
  23. package/src/domains/wallet/domain/entities/README.md +34 -115
  24. package/src/domains/wallet/domain/errors/README.md +34 -151
  25. package/src/domains/wallet/infrastructure/README.md +34 -89
  26. package/src/domains/wallet/presentation/components/README.md +34 -224
  27. package/src/domains/wallet/presentation/components/TransactionItem.tsx +1 -1
  28. package/src/domains/wallet/presentation/hooks/README.md +34 -248
  29. package/src/infrastructure/README.md +37 -496
  30. package/src/infrastructure/mappers/README.md +0 -13
  31. package/src/infrastructure/repositories/README.md +74 -360
  32. package/src/infrastructure/services/ActivationHandler.ts +1 -1
  33. package/src/infrastructure/services/README.md +95 -370
  34. package/src/infrastructure/services/SubscriptionService.ts +1 -1
  35. package/src/presentation/README.md +123 -408
  36. package/src/presentation/README.md.bak +172 -0
  37. package/src/presentation/components/README.md +151 -179
  38. package/src/presentation/components/README.md.bak +217 -0
  39. package/src/presentation/components/details/CreditRow.md +65 -310
  40. package/src/presentation/components/details/DetailRow.md +63 -255
  41. package/src/presentation/components/details/PremiumDetailsCard.md +65 -238
  42. package/src/presentation/components/details/PremiumStatusBadge.md +64 -239
  43. package/src/presentation/components/details/README.md +97 -447
  44. package/src/presentation/components/feedback/PaywallFeedbackModal.md +63 -287
  45. package/src/presentation/components/feedback/README.md +97 -445
  46. package/src/presentation/components/paywall/PaywallModal.md +66 -416
  47. package/src/presentation/components/paywall/README.md +50 -186
  48. package/src/presentation/components/sections/README.md +97 -466
  49. package/src/presentation/components/sections/SubscriptionSection.md +92 -244
  50. package/src/presentation/hooks/README.md +154 -741
  51. package/src/presentation/hooks/useAuthAwarePurchase.md +58 -325
  52. package/src/presentation/hooks/useAuthGate.md +61 -375
  53. package/src/presentation/hooks/useAuthSubscriptionSync.md +66 -370
  54. package/src/presentation/hooks/useCreditChecker.md +73 -378
  55. package/src/presentation/hooks/useCredits.md +74 -313
  56. package/src/presentation/hooks/useCredits.md.bak +231 -0
  57. package/src/presentation/hooks/useCreditsGate.md +66 -318
  58. package/src/presentation/hooks/useDeductCredit.md +0 -76
  59. package/src/presentation/hooks/useDeductCredit.ts +1 -1
  60. package/src/presentation/hooks/useDevTestCallbacks.md +63 -394
  61. package/src/presentation/hooks/useFeatureGate.md +105 -150
  62. package/src/presentation/hooks/useFeatureGate.md.bak +284 -0
  63. package/src/presentation/hooks/useInitializeCredits.md +64 -430
  64. package/src/presentation/hooks/usePaywall.md +61 -306
  65. package/src/presentation/hooks/usePaywallOperations.md +64 -458
  66. package/src/presentation/hooks/usePaywallVisibility.md +67 -316
  67. package/src/presentation/hooks/usePremium.md +84 -226
  68. package/src/presentation/hooks/usePremiumGate.md +60 -395
  69. package/src/presentation/hooks/usePremiumWithCredits.md +64 -401
  70. package/src/presentation/hooks/useSubscription.md +66 -422
  71. package/src/presentation/hooks/useSubscriptionDetails.md +65 -410
  72. package/src/presentation/hooks/useSubscriptionGate.md +80 -164
  73. package/src/presentation/hooks/useSubscriptionSettingsConfig.md +66 -346
  74. package/src/presentation/hooks/useSubscriptionStatus.md +66 -396
  75. package/src/presentation/hooks/useUserTier.md +63 -328
  76. package/src/presentation/hooks/useUserTierWithRepository.md +64 -424
  77. package/src/presentation/screens/README.md +48 -190
  78. package/src/presentation/types/README.md +0 -16
  79. package/src/presentation/utils/README.md +0 -21
  80. package/src/presentation/utils/subscriptionDateUtils.ts +1 -1
  81. package/src/revenuecat/README.md +99 -518
  82. package/src/revenuecat/application/README.md +35 -150
  83. package/src/revenuecat/application/ports/README.md +34 -162
  84. package/src/revenuecat/domain/README.md +42 -141
  85. package/src/revenuecat/domain/constants/README.md +34 -176
  86. package/src/revenuecat/domain/entities/README.md +34 -374
  87. package/src/revenuecat/domain/errors/README.md +47 -191
  88. package/src/revenuecat/domain/types/README.md +34 -366
  89. package/src/revenuecat/domain/value-objects/README.md +34 -434
  90. package/src/revenuecat/infrastructure/README.md +34 -43
  91. package/src/revenuecat/infrastructure/config/README.md +32 -23
  92. package/src/revenuecat/infrastructure/handlers/README.md +34 -211
  93. package/src/revenuecat/infrastructure/managers/README.md +34 -42
  94. package/src/revenuecat/infrastructure/services/README.md +35 -318
  95. package/src/revenuecat/infrastructure/utils/README.md +34 -375
  96. package/src/revenuecat/presentation/README.md +34 -176
  97. package/src/revenuecat/presentation/hooks/README.md +29 -35
  98. 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
- ## Import
5
+ ## Location
6
6
 
7
- ```typescript
8
- import { useUserTier } from '@umituz/react-native-subscription';
9
- ```
7
+ **Import Path**: `@umituz/react-native-subscription`
10
8
 
11
- ## Signature
9
+ **File**: `src/presentation/hooks/useUserTier.ts`
12
10
 
13
- ```typescript
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
- ## Returns
13
+ ## Strategy
25
14
 
26
- | Property | Type | Description |
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
- ## User Tiers
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
- ### Guest
38
- - User is not authenticated
39
- - No access to personalized features
40
- - Limited functionality
24
+ ### Integration Points
41
25
 
42
- ### Free
43
- - User is authenticated
44
- - Has basic access
45
- - Can upgrade to premium
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
- ### Premium
48
- - User has active subscription
49
- - Full access to all features
50
- - Priority support
31
+ ## Restrictions
51
32
 
52
- ## Basic Usage
33
+ ### REQUIRED
53
34
 
54
- ```typescript
55
- function UserDisplay() {
56
- const { tier, isGuest, isFree, isPremium } = useUserTier();
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
- return (
59
- <View>
60
- <Badge>{tier.toUpperCase()}</Badge>
40
+ ### PROHIBITED
61
41
 
62
- {isGuest && <Text>Please sign in to save your progress</Text>}
63
- {isFree && <Text>Upgrade to Premium for full access</Text>}
64
- {isPremium && <Text>Welcome, Premium member!</Text>}
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
- ## Advanced Usage
46
+ ### CRITICAL SAFETY
71
47
 
72
- ### Tier-Based UI
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
- ```typescript
75
- function TierBasedFeatures() {
76
- const { tier } = useUserTier();
53
+ ## AI Agent Guidelines
77
54
 
78
- return (
79
- <View>
80
- {/* Available to everyone */}
81
- <BasicFeature />
55
+ ### When Implementing Tier-Based Features
82
56
 
83
- {/* Free and Premium only */}
84
- {(tier === 'free' || tier === 'premium') && (
85
- <FreeFeature />
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
- {/* Premium only */}
89
- {tier === 'premium' && (
90
- <PremiumFeature />
91
- )}
92
- </View>
93
- );
94
- }
95
- ```
63
+ ### Integration Checklist
96
64
 
97
- ### With Navigation Guard
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
- ```typescript
100
- function ProtectedScreen() {
101
- const { tier, isLoading } = useUserTier();
76
+ ### Common Patterns
102
77
 
103
- useEffect(() => {
104
- if (!isLoading && tier !== 'premium') {
105
- navigation.replace('Paywall');
106
- }
107
- }, [tier, isLoading]);
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
- if (isLoading) return <LoadingScreen />;
84
+ ## Related Documentation
110
85
 
111
- return tier === 'premium' ? <PremiumContent /> : null;
112
- }
113
- ```
114
-
115
- ### With Progress Tracking
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`