@umituz/react-native-subscription 2.14.99 → 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 -394
  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 +50 -238
  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 +23 -376
  14. package/src/domains/config/domain/entities/README.md +34 -343
  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 +0 -76
  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 +35 -150
  77. package/src/revenuecat/application/ports/README.md +34 -162
  78. package/src/revenuecat/domain/README.md +42 -141
  79. package/src/revenuecat/domain/constants/README.md +34 -176
  80. package/src/revenuecat/domain/entities/README.md +34 -374
  81. package/src/revenuecat/domain/errors/README.md +47 -191
  82. package/src/revenuecat/domain/types/README.md +34 -366
  83. package/src/revenuecat/domain/value-objects/README.md +34 -434
  84. package/src/revenuecat/infrastructure/README.md +34 -43
  85. package/src/revenuecat/infrastructure/config/README.md +32 -23
  86. package/src/revenuecat/infrastructure/handlers/README.md +34 -211
  87. package/src/revenuecat/infrastructure/managers/README.md +34 -42
  88. package/src/revenuecat/infrastructure/services/README.md +35 -318
  89. package/src/revenuecat/infrastructure/utils/README.md +34 -375
  90. package/src/revenuecat/presentation/README.md +34 -176
  91. package/src/revenuecat/presentation/hooks/README.md +29 -35
  92. package/src/utils/README.md +38 -525
@@ -2,156 +2,111 @@
2
2
 
3
3
  Unified feature gate combining authentication, subscription, and credits checks.
4
4
 
5
- ## Import
6
-
7
- ```typescript
8
- import { useFeatureGate } from '@umituz/react-native-subscription';
9
- ```
10
-
11
- ## Signature
12
-
13
- ```typescript
14
- function useFeatureGate(params: {
15
- isAuthenticated: boolean;
16
- onShowAuthModal: (pendingCallback: () => void | Promise<void>) => void;
17
- hasSubscription?: boolean;
18
- hasCredits: boolean;
19
- creditBalance: number;
20
- requiredCredits?: number;
21
- onShowPaywall: (requiredCredits?: number) => void;
22
- }): {
23
- requireFeature: (action: () => void | Promise<void>) => void;
24
- isAuthenticated: boolean;
25
- hasSubscription: boolean;
26
- hasCredits: boolean;
27
- creditBalance: number;
28
- canAccess: boolean;
29
- }
30
- ```
31
-
32
- ## Parameters
33
-
34
- | Parameter | Type | Default | Description |
35
- |-----------|------|---------|-------------|
36
- | `isAuthenticated` | `boolean` | **Required** | Whether user is authenticated |
37
- | `onShowAuthModal` | `(callback) => void` | **Required** | Show auth modal with pending action |
38
- | `hasSubscription` | `boolean` | `false` | Whether user has subscription |
39
- | `hasCredits` | `boolean` | **Required** | Whether user has enough credits |
40
- | `creditBalance` | `number` | **Required** | Current credit balance |
41
- | `requiredCredits` | `number` | `undefined` | Credits required for action |
42
- | `onShowPaywall` | `(credits?) => void` | **Required** | Show paywall/upgrade prompt |
43
-
44
- ## Returns
45
-
46
- | Property | Type | Description |
47
- |----------|------|-------------|
48
- | `requireFeature` | `(action) => void` | Gate action behind auth, subscription, and credits |
49
- | `isAuthenticated` | `boolean` | User is authenticated |
50
- | `hasSubscription` | `boolean` | User has subscription |
51
- | `hasCredits` | `boolean` | User has enough credits |
52
- | `creditBalance` | `number` | Current credit balance |
53
- | `canAccess` | `boolean` | User can access the feature |
54
-
55
- ## Basic Usage
56
-
57
- ```typescript
58
- function PremiumFeature() {
59
- const { user } = useAuth();
60
- const { isPremium } = usePremium();
61
- const { credits } = useCredits();
62
-
63
- const { requireFeature, canAccess } = useFeatureGate({
64
- isAuthenticated: !!user,
65
- onShowAuthModal: (pendingAction) => {
66
- navigation.navigate('Auth', { pendingAction });
67
- },
68
- hasSubscription: isPremium,
69
- hasCredits: credits >= 5,
70
- creditBalance: credits,
71
- requiredCredits: 5,
72
- onShowPaywall: (required) => {
73
- if (isPremium) {
74
- showInsufficientCreditsModal(required);
75
- } else {
76
- showPaywall();
77
- }
78
- },
79
- });
80
-
81
- const handleGenerate = () => {
82
- requireFeature(async () => {
83
- await generateContent();
84
- });
85
- };
86
-
87
- return (
88
- <Button
89
- onPress={handleGenerate}
90
- title={!canAccess ? 'Unlock Feature' : 'Generate'}
91
- />
92
- );
93
- }
94
- ```
95
-
96
- ## Advanced Usage
5
+ ## Location
6
+
7
+ **Import Path**: `@umituz/react-native-subscription`
8
+
9
+ **File**: `src/presentation/hooks/useFeatureGate.ts`
10
+
11
+ **Type**: Hook
12
+
13
+ ## Strategy
97
14
 
98
15
  ### Progressive Access Control
99
16
 
100
- ```typescript
101
- function ProgressiveFeatureGate() {
102
- const { user } = useAuth();
103
- const { isPremium } = usePremium();
104
- const { credits } = useCredits();
105
-
106
- const { requireFeature, canAccess, isAuthenticated, hasSubscription, hasCredits } =
107
- useFeatureGate({
108
- isAuthenticated: !!user,
109
- onShowAuthModal: (pending) => showAuthModal({ pendingAction: pending }),
110
- hasSubscription: isPremium,
111
- hasCredits: credits >= 3,
112
- creditBalance: credits,
113
- requiredCredits: 3,
114
- onShowPaywall: (required) => showUpgradeModal({ requiredCredits: required }),
115
- });
116
-
117
- const getAccessMessage = () => {
118
- if (!isAuthenticated) return 'Sign in to access';
119
- if (!hasSubscription && !hasCredits) return 'Upgrade or purchase credits';
120
- if (!hasCredits) return 'Insufficient credits';
121
- return 'Full access';
122
- };
123
-
124
- return (
125
- <View>
126
- <Text>{getAccessMessage()}</Text>
127
- <Button
128
- onPress={() => requireFeature(() => executeAction())}
129
- disabled={!canAccess}
130
- title={canAccess ? 'Execute Action' : 'Unlock'}
131
- />
132
- </View>
133
- );
134
- }
135
- ```
136
-
137
- ## Best Practices
138
-
139
- 1. **Check in order** - Auth → Subscription → Credits
140
- 2. **Clear messaging** - Tell users exactly what's required
141
- 3. **Preserve intent** - Queue pending actions through auth/purchase
142
- 4. **Smart prompts** - Show relevant upgrade option
143
- 5. **Track events** - Monitor gate triggers for optimization
144
- 6. **Respect premium** - Bypass credits for subscribers
145
- 7. **Show alternatives** - Offer both subscription and credits options
146
-
147
- ## Related Hooks
148
-
149
- - **useAuthGate** - Auth gating only
150
- - **useSubscriptionGate** - Subscription gating only
151
- - **useCreditsGate** - Credits gating only
152
- - **usePremiumGate** - Premium feature gating
153
-
154
- ## See Also
155
-
156
- - [Feature Gating](../../../docs/FEATURE_GATING.md)
157
- - [Access Control Patterns](../../../docs/ACCESS_PATTERNS.md)
17
+ 1. **Authentication Check**
18
+ - Verify user is authenticated
19
+ - Show auth modal if not authenticated
20
+ - Queue pending action for post-auth execution
21
+
22
+ 2. **Subscription Check**
23
+ - Verify user has required subscription tier
24
+ - Show paywall if subscription insufficient
25
+ - Bypass credit check for premium users
26
+
27
+ 3. **Credit Check**
28
+ - Verify sufficient credit balance
29
+ - Show purchase prompt if insufficient
30
+ - Deduct credits only after all checks pass
31
+
32
+ 4. **Action Execution**
33
+ - Execute gated action only if all checks pass
34
+ - Handle failures gracefully
35
+ - Update UI state appropriately
36
+
37
+ ### Integration Points
38
+
39
+ - **useAuth**: For authentication state
40
+ - **usePremium**: For subscription status
41
+ - **useCredits**: For credit balance
42
+ - **useDeductCredit**: For credit deduction
43
+ - **Auth Modals**: Custom authentication UI
44
+ - **Paywall Components**: Upgrade prompts
45
+
46
+ ## Restrictions
47
+
48
+ ### REQUIRED
49
+
50
+ - **Authentication Check**: MUST implement `onShowAuthModal` callback
51
+ - **Paywall Handler**: MUST implement `onShowPaywall` callback
52
+ - **Credit Validation**: MUST check `hasCredits` before allowing actions
53
+ - **State Management**: MUST respect `canAccess` boolean
54
+
55
+ ### PROHIBITED
56
+
57
+ - **NEVER** bypass authentication check for sensitive features
58
+ - **NEVER** show feature gate if user has access (confusing UX)
59
+ - **NEVER** execute action without checking all gates first
60
+ - **DO NOT** hardcode gate logic (use hook parameters)
61
+ - **NEVER** deduct credits without checking subscription status first
62
+
63
+ ### CRITICAL SAFETY
64
+
65
+ - **ALWAYS** check gates in order: Auth → Subscription → Credits
66
+ - **ALWAYS** provide clear messaging about why access is denied
67
+ - **ALWAYS** preserve user intent through auth/purchase flows
68
+ - **NEVER** trust client-side gate for security (server-side validation required)
69
+ - **MUST** implement proper error boundaries around gated actions
70
+
71
+ ## AI Agent Guidelines
72
+
73
+ ### When Implementing Feature Gates
74
+
75
+ 1. **Always** check gates in order: Auth → Subscription → Credits
76
+ 2. **Always** provide clear, specific messaging for each gate
77
+ 3. **Always** preserve user intent through auth/purchase flows
78
+ 4. **Always** bypass credit check for premium users (if applicable)
79
+ 5. **Never** trust client-side gates for security (server validation required)
80
+
81
+ ### Integration Checklist
82
+
83
+ - [ ] Import from correct path: `@umituz/react-native-subscription`
84
+ - [ ] Implement `onShowAuthModal` with pending action preservation
85
+ - [ ] Implement `onShowPaywall` with context-aware messaging
86
+ - [ ] Check `canAccess` before showing feature
87
+ - [ ] Provide appropriate messaging for each gate state
88
+ - [ ] Respect premium status (bypass credit check if needed)
89
+ - [ ] Test all gate combinations (auth, subscription, credits)
90
+ - [ ] Test pending action execution after auth/purchase
91
+ - [ ] Implement error boundaries around gated actions
92
+
93
+ ### Common Patterns to Implement
94
+
95
+ 1. **Progressive Unlocking**: Show upgrade path for each gate
96
+ 2. **Smart Paywalls**: Show subscription OR credits based on user state
97
+ 3. **Intent Preservation**: Queue actions through auth/purchase flows
98
+ 4. **Clear Messaging**: Tell users exactly what's required
99
+ 5. **Premium Bypass**: Skip credit check for premium users
100
+ 6. **Access Indicators**: Show lock/unlock status in UI
101
+ 7. **Graceful Degradation**: Show limited version for free users
102
+ 8. **Analytics Tracking**: Monitor gate triggers and conversions
103
+
104
+ ## Related Documentation
105
+
106
+ - **useAuthGate**: Authentication gating only
107
+ - **useSubscriptionGate**: Subscription gating only
108
+ - **useCreditsGate**: Credits gating only
109
+ - **usePremiumGate**: Premium feature gating
110
+ - **useDeductCredit**: Credit deduction after gate passes
111
+ - **Feature Gating**: `../../../docs/FEATURE_GATING.md`
112
+ - **Access Control**: `../../../docs/ACCESS_PATTERNS.md`
@@ -0,0 +1,284 @@
1
+ # useFeatureGate Hook
2
+
3
+ Unified feature gate combining authentication, subscription, and credits checks.
4
+
5
+ ## Location
6
+
7
+ **Import Path**: `@umituz/react-native-subscription`
8
+
9
+ **File**: `src/presentation/hooks/useFeatureGate.ts`
10
+
11
+ **Type**: Hook
12
+
13
+ ## Strategy
14
+
15
+ ### Progressive Access Control
16
+
17
+ 1. **Authentication Check**
18
+ - Verify user is authenticated
19
+ - Show auth modal if not authenticated
20
+ - Queue pending action for post-auth execution
21
+
22
+ 2. **Subscription Check**
23
+ - Verify user has required subscription tier
24
+ - Show paywall if subscription insufficient
25
+ - Bypass credit check for premium users
26
+
27
+ 3. **Credit Check**
28
+ - Verify sufficient credit balance
29
+ - Show purchase prompt if insufficient
30
+ - Deduct credits only after all checks pass
31
+
32
+ 4. **Action Execution**
33
+ - Execute gated action only if all checks pass
34
+ - Handle failures gracefully
35
+ - Update UI state appropriately
36
+
37
+ ### Integration Points
38
+
39
+ - **useAuth**: For authentication state
40
+ - **usePremium**: For subscription status
41
+ - **useCredits**: For credit balance
42
+ - **useDeductCredit**: For credit deduction
43
+ - **Auth Modals**: Custom authentication UI
44
+ - **Paywall Components**: Upgrade prompts
45
+
46
+ ## Restrictions
47
+
48
+ ### REQUIRED
49
+
50
+ - **Authentication Check**: MUST implement `onShowAuthModal` callback
51
+ - **Paywall Handler**: MUST implement `onShowPaywall` callback
52
+ - **Credit Validation**: MUST check `hasCredits` before allowing actions
53
+ - **State Management**: MUST respect `canAccess` boolean
54
+
55
+ ### PROHIBITED
56
+
57
+ - **NEVER** bypass authentication check for sensitive features
58
+ - **NEVER** show feature gate if user has access (confusing UX)
59
+ - **NEVER** execute action without checking all gates first
60
+ - **DO NOT** hardcode gate logic (use hook parameters)
61
+ - **NEVER** deduct credits without checking subscription status first
62
+
63
+ ### CRITICAL SAFETY
64
+
65
+ - **ALWAYS** check gates in order: Auth → Subscription → Credits
66
+ - **ALWAYS** provide clear messaging about why access is denied
67
+ - **ALWAYS** preserve user intent through auth/purchase flows
68
+ - **NEVER** trust client-side gate for security (server-side validation required)
69
+ - **MUST** implement proper error boundaries around gated actions
70
+
71
+ ## Rules
72
+
73
+ ### Basic Feature Gating
74
+
75
+ ```typescript
76
+ // CORRECT - All gates with clear messaging
77
+ function PremiumFeature() {
78
+ const { requireFeature, canAccess, isAuthenticated, hasSubscription, hasCredits } =
79
+ useFeatureGate({
80
+ isAuthenticated: !!user,
81
+ onShowAuthModal: (pendingAction) => {
82
+ navigation.navigate('Auth', { pendingAction });
83
+ },
84
+ hasSubscription: isPremium,
85
+ hasCredits: credits >= 5,
86
+ creditBalance: credits,
87
+ requiredCredits: 5,
88
+ onShowPaywall: (required) => {
89
+ if (!isAuthenticated) return;
90
+ if (!hasSubscription) showPaywall();
91
+ else showCreditPurchase(required);
92
+ },
93
+ });
94
+
95
+ const handleAction = () => {
96
+ requireFeature(async () => {
97
+ await executeFeature();
98
+ });
99
+ };
100
+
101
+ return (
102
+ <Button
103
+ onPress={handleAction}
104
+ title={!canAccess ? 'Unlock Feature' : 'Execute'}
105
+ />
106
+ );
107
+ }
108
+
109
+ // INCORRECT - Missing auth callback
110
+ const { requireFeature } = useFeatureGate({
111
+ isAuthenticated: !!user,
112
+ // Missing onShowAuthModal
113
+ hasSubscription: isPremium,
114
+ hasCredits: credits >= 5,
115
+ creditBalance: credits,
116
+ onShowPaywall: showPaywall,
117
+ });
118
+
119
+ // INCORRECT - No access check
120
+ const handleAction = () => {
121
+ requireFeature(() => executeFeature());
122
+ };
123
+ // Always shows button, even if user can't access
124
+ ```
125
+
126
+ ### Progressive Access Control
127
+
128
+ ```typescript
129
+ // CORRECT - Show appropriate message for each gate
130
+ function ProgressiveGate() {
131
+ const { canAccess, isAuthenticated, hasSubscription, hasCredits } = useFeatureGate({
132
+ isAuthenticated: !!user,
133
+ onShowAuthModal: (pending) => showAuthModal({ pendingAction: pending }),
134
+ hasSubscription: isPremium,
135
+ hasCredits: credits >= 3,
136
+ creditBalance: credits,
137
+ requiredCredits: 3,
138
+ onShowPaywall: (required) => showUpgradeModal({ requiredCredits: required }),
139
+ });
140
+
141
+ const getAccessMessage = () => {
142
+ if (!isAuthenticated) return 'Sign in to access';
143
+ if (!hasSubscription && !hasCredits) return 'Upgrade or purchase credits';
144
+ if (!hasCredits) return `Need ${requiredCredits} credits`;
145
+ return 'Full access';
146
+ };
147
+
148
+ return (
149
+ <View>
150
+ <Text>{getAccessMessage()}</Text>
151
+ <Button
152
+ onPress={() => requireFeature(() => executeAction())}
153
+ disabled={!canAccess}
154
+ title={canAccess ? 'Execute' : 'Unlock'}
155
+ />
156
+ </View>
157
+ );
158
+ }
159
+
160
+ // INCORRECT - Generic message for all gates
161
+ if (!canAccess) {
162
+ return <Text>You cannot access this feature</Text>;
163
+ }
164
+ // Doesn't tell user what they need to do
165
+ ```
166
+
167
+ ### Premium Bypass Logic
168
+
169
+ ```typescript
170
+ // CORRECT - Premium users bypass credit check
171
+ function PremiumBypass() {
172
+ const { requireFeature } = useFeatureGate({
173
+ isAuthenticated: !!user,
174
+ onShowAuthModal: (pending) => showAuthModal({ pendingAction: pending }),
175
+ hasSubscription: isPremium,
176
+ hasCredits: isPremium ? true : credits >= 5,
177
+ creditBalance: credits,
178
+ requiredCredits: isPremium ? 0 : 5,
179
+ onShowPaywall: (required) => {
180
+ if (isPremium) {
181
+ showInsufficientCreditsModal(required);
182
+ } else {
183
+ showPaywall();
184
+ }
185
+ },
186
+ });
187
+
188
+ return <Button onPress={() => requireFeature(executeAction)} />;
189
+ }
190
+
191
+ // INCORRECT - Charges premium users for credits
192
+ hasCredits: credits >= 5, // Even if isPremium is true
193
+ requiredCredits: 5, // Charges premium users
194
+ ```
195
+
196
+ ### Callback Implementation
197
+
198
+ ```typescript
199
+ // CORRECT - Proper auth modal with pending action
200
+ onShowAuthModal: (pendingAction) => {
201
+ navigation.navigate('Auth', {
202
+ onAuthSuccess: pendingAction,
203
+ });
204
+ }
205
+
206
+ // CORRECT - Context-aware paywall
207
+ onShowPaywall: (requiredCredits) => {
208
+ if (isPremium) {
209
+ // Already premium, need credits
210
+ showCreditPurchaseModal({ requiredCredits });
211
+ } else {
212
+ // Not premium, show subscription
213
+ showSubscriptionPaywall();
214
+ }
215
+ }
216
+
217
+ // INCORRECT - No pending action preservation
218
+ onShowAuthModal: () => {
219
+ navigation.navigate('Auth');
220
+ // User's intent is lost
221
+ }
222
+ ```
223
+
224
+ ### Action Gating
225
+
226
+ ```typescript
227
+ // CORRECT - Gate action execution
228
+ const handleGenerate = () => {
229
+ requireFeature(async () => {
230
+ // Only runs if all gates pass
231
+ const result = await generateContent();
232
+ showResult(result);
233
+ });
234
+ };
235
+
236
+ // INCORRECT - Execute action before gating
237
+ const handleGenerate = async () => {
238
+ const result = await generateContent(); // Runs regardless!
239
+ requireFeature(() => showResult(result));
240
+ };
241
+ ```
242
+
243
+ ## AI Agent Guidelines
244
+
245
+ ### When Implementing Feature Gates
246
+
247
+ 1. **Always** check gates in order: Auth → Subscription → Credits
248
+ 2. **Always** provide clear, specific messaging for each gate
249
+ 3. **Always** preserve user intent through auth/purchase flows
250
+ 4. **Always** bypass credit check for premium users (if applicable)
251
+ 5. **Never** trust client-side gates for security (server validation required)
252
+
253
+ ### Integration Checklist
254
+
255
+ - [ ] Import from correct path: `@umituz/react-native-subscription`
256
+ - [ ] Implement `onShowAuthModal` with pending action preservation
257
+ - [ ] Implement `onShowPaywall` with context-aware messaging
258
+ - [ ] Check `canAccess` before showing feature
259
+ - [ ] Provide appropriate messaging for each gate state
260
+ - [ ] Respect premium status (bypass credit check if needed)
261
+ - [ ] Test all gate combinations (auth, subscription, credits)
262
+ - [ ] Test pending action execution after auth/purchase
263
+ - [ ] Implement error boundaries around gated actions
264
+
265
+ ### Common Patterns to Implement
266
+
267
+ 1. **Progressive Unlocking**: Show upgrade path for each gate
268
+ 2. **Smart Paywalls**: Show subscription OR credits based on user state
269
+ 3. **Intent Preservation**: Queue actions through auth/purchase flows
270
+ 4. **Clear Messaging**: Tell users exactly what's required
271
+ 5. **Premium Bypass**: Skip credit check for premium users
272
+ 6. **Access Indicators**: Show lock/unlock status in UI
273
+ 7. **Graceful Degradation**: Show limited version for free users
274
+ 8. **Analytics Tracking**: Monitor gate triggers and conversions
275
+
276
+ ## Related Documentation
277
+
278
+ - **useAuthGate**: Authentication gating only
279
+ - **useSubscriptionGate**: Subscription gating only
280
+ - **useCreditsGate**: Credits gating only
281
+ - **usePremiumGate**: Premium feature gating
282
+ - **useDeductCredit**: Credit deduction after gate passes
283
+ - **Feature Gating**: `../../../docs/FEATURE_GATING.md`
284
+ - **Access Control**: `../../../docs/ACCESS_PATTERNS.md`