@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.
Files changed (92) hide show
  1. package/README.md +211 -395
  2. package/package.json +1 -1
  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/errors/README.md +33 -287
  9. package/src/domain/value-objects/README.md +43 -179
  10. package/src/domains/README.md +52 -0
  11. package/src/domains/README.md.bak +274 -0
  12. package/src/domains/config/README.md +93 -383
  13. package/src/domains/config/domain/README.md +37 -0
  14. package/src/domains/config/domain/entities/README.md +41 -0
  15. package/src/domains/paywall/README.md +99 -369
  16. package/src/domains/paywall/components/README.md +34 -178
  17. package/src/domains/paywall/entities/README.md +34 -193
  18. package/src/domains/paywall/hooks/README.md +34 -122
  19. package/src/domains/wallet/README.md +34 -275
  20. package/src/domains/wallet/README.md.bak +209 -0
  21. package/src/domains/wallet/domain/README.md +34 -101
  22. package/src/domains/wallet/domain/entities/README.md +34 -115
  23. package/src/domains/wallet/domain/errors/README.md +34 -151
  24. package/src/domains/wallet/infrastructure/README.md +34 -89
  25. package/src/domains/wallet/presentation/components/README.md +34 -224
  26. package/src/domains/wallet/presentation/hooks/README.md +34 -248
  27. package/src/infrastructure/README.md +37 -496
  28. package/src/infrastructure/mappers/README.md +0 -13
  29. package/src/infrastructure/repositories/README.md +74 -360
  30. package/src/infrastructure/services/README.md +95 -370
  31. package/src/presentation/README.md +123 -408
  32. package/src/presentation/README.md.bak +172 -0
  33. package/src/presentation/components/README.md +151 -179
  34. package/src/presentation/components/README.md.bak +217 -0
  35. package/src/presentation/components/details/CreditRow.md +65 -310
  36. package/src/presentation/components/details/DetailRow.md +63 -255
  37. package/src/presentation/components/details/PremiumDetailsCard.md +65 -238
  38. package/src/presentation/components/details/PremiumStatusBadge.md +64 -239
  39. package/src/presentation/components/details/README.md +97 -447
  40. package/src/presentation/components/feedback/PaywallFeedbackModal.md +63 -287
  41. package/src/presentation/components/feedback/README.md +97 -445
  42. package/src/presentation/components/paywall/PaywallModal.md +66 -416
  43. package/src/presentation/components/paywall/README.md +50 -186
  44. package/src/presentation/components/sections/README.md +97 -466
  45. package/src/presentation/components/sections/SubscriptionSection.md +92 -244
  46. package/src/presentation/hooks/README.md +154 -741
  47. package/src/presentation/hooks/useAuthAwarePurchase.md +58 -325
  48. package/src/presentation/hooks/useAuthGate.md +61 -375
  49. package/src/presentation/hooks/useAuthSubscriptionSync.md +66 -370
  50. package/src/presentation/hooks/useCreditChecker.md +73 -378
  51. package/src/presentation/hooks/useCredits.md +74 -313
  52. package/src/presentation/hooks/useCredits.md.bak +231 -0
  53. package/src/presentation/hooks/useCreditsGate.md +66 -318
  54. package/src/presentation/hooks/useDeductCredit.md +96 -156
  55. package/src/presentation/hooks/useDevTestCallbacks.md +63 -394
  56. package/src/presentation/hooks/useFeatureGate.md +105 -150
  57. package/src/presentation/hooks/useFeatureGate.md.bak +284 -0
  58. package/src/presentation/hooks/useInitializeCredits.md +64 -430
  59. package/src/presentation/hooks/usePaywall.md +61 -306
  60. package/src/presentation/hooks/usePaywallOperations.md +64 -458
  61. package/src/presentation/hooks/usePaywallVisibility.md +67 -316
  62. package/src/presentation/hooks/usePremium.md +84 -226
  63. package/src/presentation/hooks/usePremiumGate.md +60 -395
  64. package/src/presentation/hooks/usePremiumWithCredits.md +64 -401
  65. package/src/presentation/hooks/useSubscription.md +66 -422
  66. package/src/presentation/hooks/useSubscriptionDetails.md +65 -410
  67. package/src/presentation/hooks/useSubscriptionGate.md +80 -164
  68. package/src/presentation/hooks/useSubscriptionSettingsConfig.md +66 -346
  69. package/src/presentation/hooks/useSubscriptionStatus.md +66 -396
  70. package/src/presentation/hooks/useUserTier.md +63 -328
  71. package/src/presentation/hooks/useUserTierWithRepository.md +64 -424
  72. package/src/presentation/screens/README.md +48 -190
  73. package/src/presentation/types/README.md +0 -16
  74. package/src/presentation/utils/README.md +0 -21
  75. package/src/revenuecat/README.md +99 -518
  76. package/src/revenuecat/application/README.md +43 -0
  77. package/src/revenuecat/application/ports/README.md +41 -0
  78. package/src/revenuecat/domain/README.md +42 -141
  79. package/src/revenuecat/domain/constants/README.md +41 -0
  80. package/src/revenuecat/domain/entities/README.md +42 -0
  81. package/src/revenuecat/domain/errors/README.md +47 -191
  82. package/src/revenuecat/domain/types/README.md +41 -0
  83. package/src/revenuecat/domain/value-objects/README.md +41 -0
  84. package/src/revenuecat/infrastructure/README.md +41 -0
  85. package/src/revenuecat/infrastructure/config/README.md +32 -23
  86. package/src/revenuecat/infrastructure/handlers/README.md +41 -0
  87. package/src/revenuecat/infrastructure/managers/README.md +34 -42
  88. package/src/revenuecat/infrastructure/services/README.md +42 -0
  89. package/src/revenuecat/infrastructure/utils/README.md +41 -0
  90. package/src/revenuecat/presentation/README.md +42 -0
  91. package/src/revenuecat/presentation/hooks/README.md +29 -35
  92. package/src/utils/README.md +38 -525
@@ -2,358 +2,91 @@
2
2
 
3
3
  Security-focused purchase hook that requires authentication before any transaction.
4
4
 
5
- ## Import
5
+ ## Location
6
6
 
7
- ```typescript
8
- import {
9
- useAuthAwarePurchase,
10
- configureAuthProvider
11
- } from '@umituz/react-native-subscription';
12
- ```
7
+ **Import Path**: `@umituz/react-native-subscription`
13
8
 
14
- ## Configuration
9
+ **File**: `src/presentation/hooks/useAuthAwarePurchase.ts`
15
10
 
16
- **IMPORTANT**: You must configure the auth provider once at app initialization:
11
+ **Type**: Hook
17
12
 
18
- ```typescript
19
- import { configureAuthProvider } from '@umituz/react-native-subscription';
13
+ ## Strategy
20
14
 
21
- // Configure once at app startup
22
- configureAuthProvider({
23
- isAuthenticated: () => {
24
- // Return true if user is authenticated
25
- return auth.currentUser != null;
26
- },
27
- showAuthModal: () => {
28
- // Show your authentication modal/screen
29
- navigation.navigate('Auth');
30
- },
31
- });
32
- ```
15
+ ### Auth-Gated Purchase Flow
33
16
 
34
- ## Signature
17
+ 1. **Auth Provider Validation**: Verify auth provider is configured at app startup
18
+ 2. **Authentication Check**: Block purchases for unauthenticated users
19
+ 3. **Auth Flow Trigger**: Show auth modal when guest attempts purchase
20
+ 4. **Purchase Blocking**: Prevent all transactions without valid authentication
21
+ 5. **Post-Auth Purchase**: Allow purchase after user completes authentication
22
+ 6. **Security Enforcement**: Server-side validation required for final verification
35
23
 
36
- ```typescript
37
- function useAuthAwarePurchase(): {
38
- handlePurchase: (pkg: PurchasesPackage) => Promise<boolean>;
39
- handleRestore: () => Promise<boolean>;
40
- }
41
- ```
24
+ ### Integration Points
42
25
 
43
- ## Returns
26
+ - **Auth Provider Configuration**: Must be configured once at app initialization
27
+ - **Auth Context**: User authentication state
28
+ - **Paywall Domain**: For subscription upgrade flow
29
+ - **Auth UI**: For sign-in/sign-up flows
30
+ - **RevenueCat**: For purchase transactions
44
31
 
45
- | Property | Type | Description |
46
- |----------|------|-------------|
47
- | `handlePurchase` | `(pkg) => Promise<boolean>` | Purchase with auth check |
48
- | `handleRestore` | `() => Promise<boolean>` | Restore with auth check |
32
+ ## Restrictions
49
33
 
50
- ## Basic Usage
34
+ ### REQUIRED
51
35
 
52
- ```typescript
53
- function PaywallScreen() {
54
- const { handlePurchase, handleRestore } = useAuthAwarePurchase();
36
+ - **Auth Provider Configuration**: MUST call `configureAuthProvider()` once at app startup
37
+ - **isAuthenticated Function**: MUST provide function to check auth status
38
+ - **showAuthModal Function**: MUST provide function to show auth UI
39
+ - **Error Handling**: MUST handle purchase failures appropriately
55
40
 
56
- const onPurchasePress = async (package: PurchasesPackage) => {
57
- const success = await handlePurchase(package);
58
- if (success) {
59
- console.log('Purchase successful');
60
- }
61
- };
41
+ ### PROHIBITED
62
42
 
63
- const onRestorePress = async () => {
64
- const success = await handleRestore();
65
- if (success) {
66
- console.log('Restore successful');
67
- }
68
- };
43
+ - **NEVER** use without configuring auth provider first
44
+ - **NEVER** bypass auth checks for convenience
45
+ - **NEVER** allow anonymous/guest purchases
46
+ - **DO NOT** call handlePurchase/handleRestore without auth provider setup
69
47
 
70
- return (
71
- <View>
72
- <PackageList onSelectPackage={onPurchasePress} />
73
- <Button onPress={onRestorePress} title="Restore Purchases" />
74
- </View>
75
- );
76
- }
77
- ```
48
+ ### CRITICAL SAFETY
78
49
 
79
- ## Advanced Usage
50
+ - **ALWAYS** configure auth provider at app initialization
51
+ - **NEVER** allow purchases for anonymous users
52
+ - **MUST** implement proper auth flow with pending purchase preservation
53
+ - **ALWAYS** verify auth status in production
80
54
 
81
- ### With Auth Provider Setup
55
+ ## AI Agent Guidelines
82
56
 
83
- ```typescript
84
- // App.tsx - Configure at app start
85
- import { configureAuthProvider } from '@umituz/react-native-subscription';
86
- import { auth } from './firebase/config';
57
+ ### When Implementing Auth-Gated Purchases
87
58
 
88
- export default function App() {
89
- useEffect(() => {
90
- configureAuthProvider({
91
- isAuthenticated: () => {
92
- return auth.currentUser !== null;
93
- },
94
- showAuthModal: () => {
95
- // Navigate to auth screen or show modal
96
- navigationRef.current?.navigate('AuthModal', {
97
- onAuthSuccess: () => {
98
- // Paywall will be shown again after auth
99
- },
100
- });
101
- },
102
- });
103
- }, []);
59
+ 1. **Always** configure auth provider at app startup
60
+ 2. **Always** implement isAuthenticated function
61
+ 3. **Always** implement showAuthModal function
62
+ 4. **Never** bypass auth checks
63
+ 5. **Always** test purchase flow with authenticated and unauthenticated users
104
64
 
105
- return <YourAppNavigation />;
106
- }
107
- ```
108
-
109
- ### With Custom Auth Logic
110
-
111
- ```typescript
112
- // With your auth library
113
- import { configureAuthProvider } from '@umituz/react-native-subscription';
114
- import { useAuth } from '@umituz/react-native-auth';
115
-
116
- export default function App() {
117
- const { user, showAuthModal } = useAuth();
118
-
119
- useEffect(() => {
120
- configureAuthProvider({
121
- isAuthenticated: () => !!user,
122
- showAuthModal: () => {
123
- showAuthModal({
124
- purpose: 'purchase',
125
- message: 'Sign in to complete your purchase',
126
- });
127
- },
128
- });
129
- }, [user, showAuthModal]);
130
-
131
- return <YourApp />;
132
- }
133
- ```
134
-
135
- ### With Pending Purchase After Auth
136
-
137
- ```typescript
138
- function PaywallWithPendingPurchase() {
139
- const { handlePurchase } = useAuthAwarePurchase();
140
- const [pendingPackage, setPendingPackage] = useState<PurchasesPackage | null>(null);
141
-
142
- useEffect(() => {
143
- // If user was not authenticated, purchase is intercepted
144
- // After authentication, you can retry the purchase
145
- if (user && pendingPackage) {
146
- handlePurchase(pendingPackage).then((success) => {
147
- if (success) {
148
- setPendingPackage(null);
149
- }
150
- });
151
- }
152
- }, [user, pendingPackage]);
153
-
154
- const onPurchasePress = async (pkg: PurchasesPackage) => {
155
- const success = await handlePurchase(pkg);
156
- if (!success && !user) {
157
- // User needs to authenticate first
158
- setPendingPackage(pkg);
159
- }
160
- };
161
-
162
- return <PackageList onSelectPackage={onPurchasePress} />;
163
- }
164
- ```
165
-
166
- ### With Error Handling
167
-
168
- ```typescript
169
- function SecurePaywall() {
170
- const { handlePurchase, handleRestore } = useAuthAwarePurchase();
171
-
172
- const onPurchasePress = async (pkg: PurchasesPackage) => {
173
- try {
174
- const success = await handlePurchase(pkg);
175
-
176
- if (!success) {
177
- // Check if auth was the issue
178
- if (!auth.currentUser) {
179
- console.log('Purchase blocked - user not authenticated');
180
- } else {
181
- console.log('Purchase failed for other reasons');
182
- }
183
- }
184
- } catch (error) {
185
- console.error('Purchase error:', error);
186
- Alert.alert('Error', 'Failed to complete purchase');
187
- }
188
- };
189
-
190
- return (
191
- <PaywallModal>
192
- <PackageList onSelectPackage={onPurchasePress} />
193
- </PaywallModal>
194
- );
195
- }
196
- ```
197
-
198
- ## Security Features
199
-
200
- ### Auth Provider Required
201
-
202
- The hook will **block all purchases** if auth provider is not configured:
203
-
204
- ```typescript
205
- // Development mode error
206
- [useAuthAwarePurchase] CRITICAL: Auth provider not configured.
207
- Call configureAuthProvider() at app start. Purchase blocked for security.
208
- ```
209
-
210
- ### Anonymous User Blocking
211
-
212
- Purchases are automatically blocked for anonymous/guest users:
213
-
214
- ```typescript
215
- // Development mode log
216
- [useAuthAwarePurchase] User not authenticated, opening auth modal
217
- ```
218
-
219
- ### Automatic Auth Flow
220
-
221
- When an unauthenticated user tries to purchase:
222
-
223
- 1. Purchase is blocked
224
- 2. Auth modal is shown
225
- 3. User can authenticate
226
- 4. After auth, purchase can be retried
227
-
228
- ## Examples
229
-
230
- ### Complete Paywall Implementation
231
-
232
- ```typescript
233
- function PaywallScreen() {
234
- const { handlePurchase, handleRestore } = useAuthAwarePurchase();
235
- const { packages } = useSubscriptionPackages();
236
-
237
- const [selectedPackage, setSelectedPackage] = useState<PurchasesPackage | null>(null);
238
- const [isPurchasing, setIsPurchasing] = useState(false);
239
-
240
- const handlePackageSelect = async (pkg: PurchasesPackage) => {
241
- setSelectedPackage(pkg);
242
- setIsPurchasing(true);
243
-
244
- try {
245
- const success = await handlePurchase(pkg);
246
-
247
- if (success) {
248
- Alert.alert('Success', 'You are now a Premium member!');
249
- }
250
- } catch (error) {
251
- Alert.alert('Error', 'Purchase failed. Please try again.');
252
- } finally {
253
- setIsPurchasing(false);
254
- setSelectedPackage(null);
255
- }
256
- };
257
-
258
- const handleRestorePress = async () => {
259
- const success = await handleRestore();
260
- Alert.alert(
261
- success ? 'Success' : 'Failed',
262
- success ? 'Purchases restored' : 'No purchases found'
263
- );
264
- };
265
-
266
- return (
267
- <ScrollView>
268
- <PaywallHeader />
269
-
270
- {packages.map((pkg) => (
271
- <PackageCard
272
- key={pkg.identifier}
273
- package={pkg}
274
- onSelect={handlePackageSelect}
275
- disabled={isPurchasing}
276
- selected={selectedPackage?.identifier === pkg.identifier}
277
- />
278
- ))}
279
-
280
- <Button onPress={handleRestorePress} title="Restore Purchases" />
281
-
282
- <TermsAndConditions />
283
- </ScrollView>
284
- );
285
- }
286
- ```
287
-
288
- ### In-App Purchase Button
289
-
290
- ```typescript
291
- function InAppPurchaseButton({ productIdentifier }) {
292
- const { handlePurchase } = useAuthAwarePurchase();
293
- const { packages } = useSubscriptionPackages();
294
-
295
- const pkg = packages.find((p) => p.identifier === productIdentifier);
296
-
297
- const onPress = async () => {
298
- if (!pkg) return;
299
-
300
- const success = await handlePurchase(pkg);
301
-
302
- if (success) {
303
- onPurchaseSuccess?.();
304
- }
305
- };
306
-
307
- return (
308
- <Button
309
- onPress={onPress}
310
- title="Get Premium"
311
- disabled={!pkg}
312
- />
313
- );
314
- }
315
- ```
316
-
317
- ## Best Practices
318
-
319
- 1. **Configure early** - Set up auth provider at app initialization
320
- 2. **Test auth flow** - Verify purchases work for authenticated users
321
- 3. **Test guest flow** - Verify guests are prompted to sign in
322
- 4. **Handle failures** - Show user-friendly error messages
323
- 5. **Clear pending** - Reset pending purchase state after completion
324
- 6. **Security first** - Never bypass auth checks
325
- 7. **Development testing** - Use dev logs to verify auth checks work
326
-
327
- ## Security Considerations
328
-
329
- ### Why Auth Provider is Required
330
-
331
- This hook implements a security-first approach to prevent:
332
-
333
- 1. **Anonymous purchases** - Guest users cannot make purchases
334
- 2. **Unauthorized transactions** - Only authenticated users can buy
335
- 3. **Payment fraud** - Reduces risk of fraudulent purchases
336
- 4. **Compliance** - Meets app store requirements for user identification
337
-
338
- ### Configuration Checklist
65
+ ### Integration Checklist
339
66
 
67
+ - [ ] Import from correct path: `@umituz/react-native-subscription`
340
68
  - [ ] Call `configureAuthProvider()` once at app startup
341
69
  - [ ] Provide `isAuthenticated()` function
342
70
  - [ ] Provide `showAuthModal()` function
343
71
  - [ ] Test purchase flow with authenticated user
344
72
  - [ ] Test purchase flow with unauthenticated user
345
- - [ ] Verify development logs show auth checks
73
+ - [ ] Verify auth modal appears for guests
74
+ - [ ] Verify purchase proceeds after authentication
75
+ - [ ] Check development logs for auth verification
346
76
  - [ ] Verify purchases are blocked without auth provider
347
77
 
348
- ## Related Hooks
78
+ ### Common Patterns
349
79
 
350
- - **usePremium** - For purchase and restore operations
351
- - **usePaywallOperations** - For complete paywall purchase handling
352
- - **useAuthGate** - For authentication gating
353
- - **useAuthSubscriptionSync** - For syncing auth with subscription
80
+ 1. **App-Level Config**: Configure once in root App component
81
+ 2. **Pending Purchase**: Store package for post-auth completion
82
+ 3. **Auth Integration**: Use with Firebase, Auth0, or custom auth
83
+ 4. **Error Handling**: Handle auth failures and purchase failures
84
+ 5. **Development Testing**: Use dev logs to verify auth checks
354
85
 
355
- ## See Also
86
+ ## Related Documentation
356
87
 
357
- - [Auth Integration](../../hooks/useAuthSubscriptionSync.md)
358
- - [Paywall Screen](../screens/README.md)
359
- - [Security Best Practices](../../../docs/SECURITY.md)
88
+ - **usePremium**: For purchase and restore operations
89
+ - **usePaywallOperations**: For complete paywall purchase handling
90
+ - **useAuthGate**: For authentication gating
91
+ - **useAuthSubscriptionSync**: For syncing auth with subscription
92
+ - **Security Best Practices**: `src/docs/SECURITY.md`