@umituz/react-native-subscription 2.27.92 → 2.27.93
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/package.json +1 -1
- package/src/domains/credits/application/CreditsInitializer.ts +91 -38
- package/src/domains/credits/core/UserCreditsDocument.ts +33 -33
- package/src/domains/credits/infrastructure/CreditsRepository.ts +44 -58
- package/src/domains/paywall/components/PaywallModal.tsx +1 -1
- package/src/domains/subscription/application/SubscriptionInitializer.ts +59 -18
- package/src/domains/subscription/infrastructure/handlers/PackageHandler.ts +46 -27
- package/src/domains/subscription/infrastructure/managers/SubscriptionManager.ts +106 -42
- package/src/domains/subscription/infrastructure/services/RestoreHandler.ts +4 -2
- package/src/domains/subscription/infrastructure/services/RevenueCatInitializer.ts +1 -2
- package/src/domains/subscription/infrastructure/utils/RenewalDetector.ts +1 -1
- package/src/domains/subscription/presentation/components/details/PremiumStatusBadge.tsx +6 -4
- package/src/domains/subscription/presentation/components/feedback/PaywallFeedbackModal.tsx +1 -1
- package/src/domains/subscription/presentation/types/SubscriptionDetailTypes.ts +4 -2
- package/src/domains/subscription/presentation/types/SubscriptionSettingsTypes.ts +1 -1
- package/src/domains/subscription/presentation/usePremiumGate.ts +1 -1
- package/src/domains/subscription/presentation/useSavedPurchaseAutoExecution.ts +1 -1
- package/src/domains/subscription/presentation/useSubscriptionSettingsConfig.ts +4 -3
- package/src/domains/subscription/presentation/useSubscriptionSettingsConfig.utils.ts +1 -1
- package/src/domains/trial/application/TrialEligibilityService.ts +1 -1
- package/src/domains/trial/infrastructure/DeviceTrialRepository.ts +2 -2
- package/src/shared/application/ports/IRevenueCatService.ts +2 -0
- package/src/shared/infrastructure/SubscriptionEventBus.ts +5 -2
- package/src/presentation/README.md +0 -125
- package/src/presentation/hooks/README.md +0 -156
- package/src/presentation/hooks/useAuthSubscriptionSync.md +0 -94
- package/src/presentation/hooks/useCredits.md +0 -103
- package/src/presentation/hooks/useDeductCredit.md +0 -100
- package/src/presentation/hooks/useFeatureGate.md +0 -112
- package/src/presentation/hooks/usePaywall.md +0 -89
- package/src/presentation/hooks/usePaywallOperations.md +0 -92
- package/src/presentation/hooks/usePaywallVisibility.md +0 -95
- package/src/presentation/hooks/usePremium.md +0 -88
- package/src/presentation/hooks/useSubscriptionSettingsConfig.md +0 -94
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
# usePaywallOperations Hook
|
|
2
|
-
|
|
3
|
-
Complete paywall purchase operations with authentication handling.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/usePaywallOperations.ts`
|
|
10
|
-
|
|
11
|
-
**Type**: Hook
|
|
12
|
-
|
|
13
|
-
## Strategy
|
|
14
|
-
|
|
15
|
-
### Paywall Purchase Flow with Auth
|
|
16
|
-
|
|
17
|
-
1. **Auth Check**: Verify if user is authenticated before purchase
|
|
18
|
-
2. **Pending Package Management**: Store package when auth is required
|
|
19
|
-
3. **Auth Flow Trigger**: Show auth modal for unauthenticated users
|
|
20
|
-
4. **Purchase Execution**: Complete purchase after authentication
|
|
21
|
-
5. **Restore Support**: Handle purchase restoration with auth check
|
|
22
|
-
6. **Callback Handling**: Execute appropriate callbacks at each stage
|
|
23
|
-
|
|
24
|
-
### Integration Points
|
|
25
|
-
|
|
26
|
-
- **usePremium**: For purchase and restore operations
|
|
27
|
-
- **Auth Context**: User authentication state
|
|
28
|
-
- **Paywall Domain**: For paywall display and management
|
|
29
|
-
- **Auth UI**: For authentication modal
|
|
30
|
-
- **RevenueCat**: For purchase transactions
|
|
31
|
-
|
|
32
|
-
## Restrictions
|
|
33
|
-
|
|
34
|
-
### REQUIRED
|
|
35
|
-
|
|
36
|
-
- **User ID**: MUST provide valid userId parameter
|
|
37
|
-
- **Anonymous Check**: MUST provide isAnonymous parameter
|
|
38
|
-
- **Auth Required Callback**: MUST implement onAuthRequired callback
|
|
39
|
-
- **Error Handling**: MUST handle purchase failures
|
|
40
|
-
|
|
41
|
-
### PROHIBITED
|
|
42
|
-
|
|
43
|
-
- **NEVER** call without valid userId
|
|
44
|
-
- **NEVER** call without isAnonymous parameter
|
|
45
|
-
- **DO NOT** proceed with purchase without auth check
|
|
46
|
-
- **DO NOT** ignore pending package state
|
|
47
|
-
|
|
48
|
-
### CRITICAL SAFETY
|
|
49
|
-
|
|
50
|
-
- **ALWAYS** check authentication status before purchase
|
|
51
|
-
- **MUST** handle pending package after auth
|
|
52
|
-
- **ALWAYS** provide clear auth flow for users
|
|
53
|
-
- **NEVER** allow anonymous purchases without auth
|
|
54
|
-
|
|
55
|
-
## AI Agent Guidelines
|
|
56
|
-
|
|
57
|
-
### When Implementing Paywall Operations
|
|
58
|
-
|
|
59
|
-
1. **Always** provide valid userId
|
|
60
|
-
2. **Always** provide isAnonymous status
|
|
61
|
-
3. **Always** implement onAuthRequired with pending package handling
|
|
62
|
-
4. **Always** implement onPurchaseSuccess callback
|
|
63
|
-
5. **Always** handle purchase and restore failures
|
|
64
|
-
|
|
65
|
-
### Integration Checklist
|
|
66
|
-
|
|
67
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
68
|
-
- [ ] Provide valid userId
|
|
69
|
-
- [ ] Provide isAnonymous status
|
|
70
|
-
- [ ] Implement onAuthRequired callback
|
|
71
|
-
- [ ] Implement onPurchaseSuccess callback
|
|
72
|
-
- [ ] Implement onPaywallClose callback
|
|
73
|
-
- [ ] Handle pending package state
|
|
74
|
-
- [ ] Test purchase with authenticated user
|
|
75
|
-
- [ ] Test purchase with anonymous user
|
|
76
|
-
- [ ] Test purchase flow after authentication
|
|
77
|
-
|
|
78
|
-
### Common Patterns
|
|
79
|
-
|
|
80
|
-
1. **Pending Purchase Flow**: Store package, show auth, complete purchase
|
|
81
|
-
2. **In-App Purchases**: Use handleInAppPurchase for modal paywalls
|
|
82
|
-
3. **Purchase Analytics**: Track purchase attempts and completions
|
|
83
|
-
4. **Error Recovery**: Handle failures and provide retry options
|
|
84
|
-
5. **Post-Onboarding**: Handle purchases after onboarding flow
|
|
85
|
-
|
|
86
|
-
## Related Documentation
|
|
87
|
-
|
|
88
|
-
- **usePremium**: For purchase and restore operations
|
|
89
|
-
- **useAuthAwarePurchase**: For auth-gated purchases
|
|
90
|
-
- **usePaywallVisibility**: For paywall visibility control
|
|
91
|
-
- **Paywall Screen**: `src/presentation/screens/README.md`
|
|
92
|
-
- **Purchase Flow**: `src/docs/PURCHASE_FLOW.md`
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# usePaywallVisibility Hook
|
|
2
|
-
|
|
3
|
-
Simple global state management for paywall visibility using external store.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/usePaywallVisibility.ts`
|
|
10
|
-
|
|
11
|
-
**Type**: Hook
|
|
12
|
-
|
|
13
|
-
## Strategy
|
|
14
|
-
|
|
15
|
-
### Global Paywall State Management
|
|
16
|
-
|
|
17
|
-
1. **External Store**: Use Zustand or similar for global state
|
|
18
|
-
2. **Visibility Control**: Simple boolean for show/hide
|
|
19
|
-
3. **Global Access**: Available from any component
|
|
20
|
-
4. **Direct Control**: Provide paywallControl for non-React contexts
|
|
21
|
-
5. **Single Instance**: One paywall modal at app root
|
|
22
|
-
6. **State Persistence**: Maintain visibility across component unmounts
|
|
23
|
-
|
|
24
|
-
### Integration Points
|
|
25
|
-
|
|
26
|
-
- **App Root**: Paywall modal should be placed at app root
|
|
27
|
-
- **Any Component**: Can trigger paywall from anywhere
|
|
28
|
-
- **Deep Links**: Can open paywall from URLs
|
|
29
|
-
- **Push Notifications**: Can open paywall from notifications
|
|
30
|
-
- **usePremium**: For conditional display based on status
|
|
31
|
-
|
|
32
|
-
## Restrictions
|
|
33
|
-
|
|
34
|
-
### REQUIRED
|
|
35
|
-
|
|
36
|
-
- **Single Modal**: MUST place paywall modal once at app root
|
|
37
|
-
- **Close Handler**: MUST provide close button in paywall
|
|
38
|
-
- **Premium Check**: SHOULD hide paywall when user becomes premium
|
|
39
|
-
- **Back Handler**: SHOULD handle Android back button
|
|
40
|
-
|
|
41
|
-
### PROHIBITED
|
|
42
|
-
|
|
43
|
-
- **NEVER** place multiple paywall modals in component tree
|
|
44
|
-
- **NEVER** manage visibility locally (use this hook instead)
|
|
45
|
-
- **DO NOT** show paywall too frequently
|
|
46
|
-
- **DO NOT** trap users without exit option
|
|
47
|
-
|
|
48
|
-
### CRITICAL SAFETY
|
|
49
|
-
|
|
50
|
-
- **ALWAYS** provide close button
|
|
51
|
-
- **NEVER** trap users in paywall
|
|
52
|
-
- **MUST** handle back button on Android
|
|
53
|
-
- **ALWAYS** hide paywall after successful purchase
|
|
54
|
-
|
|
55
|
-
## AI Agent Guidelines
|
|
56
|
-
|
|
57
|
-
### When Implementing Paywall Visibility
|
|
58
|
-
|
|
59
|
-
1. **Always** place paywall modal once at app root
|
|
60
|
-
2. **Always** provide close button
|
|
61
|
-
3. **Always** use openPaywall/closePaywall functions
|
|
62
|
-
4. **Always** hide paywall after successful purchase
|
|
63
|
-
5. **Never** manage visibility locally in components
|
|
64
|
-
|
|
65
|
-
### Integration Checklist
|
|
66
|
-
|
|
67
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
68
|
-
- [ ] Place paywall modal once at app root
|
|
69
|
-
- [ ] Use openPaywall to show paywall
|
|
70
|
-
- [ ] Use closePaywall to hide paywall
|
|
71
|
-
- [ ] Provide close button in paywall
|
|
72
|
-
- [ ] Handle Android back button
|
|
73
|
-
- [ ] Hide paywall when user becomes premium
|
|
74
|
-
- [ ] Test paywall opens from any component
|
|
75
|
-
- [ ] Test paywallControl for non-React contexts
|
|
76
|
-
- [ ] Test deep link integration
|
|
77
|
-
|
|
78
|
-
### Common Patterns
|
|
79
|
-
|
|
80
|
-
1. **App Root Setup**: Single modal instance at app root
|
|
81
|
-
2. **Trigger Button**: Any component can open paywall
|
|
82
|
-
3. **Direct Control**: Use paywallControl in non-React code
|
|
83
|
-
4. **Conditional Display**: Auto-show based on user status
|
|
84
|
-
5. **History/Navigation**: Handle navigation with paywall
|
|
85
|
-
6. **Timeout/Auto-Close**: Auto-close after timeout
|
|
86
|
-
7. **Deep Links**: Open from URL schemes
|
|
87
|
-
|
|
88
|
-
## Related Documentation
|
|
89
|
-
|
|
90
|
-
- **usePaywallOperations**: For paywall purchase operations
|
|
91
|
-
- **usePremium**: For subscription status
|
|
92
|
-
- **usePaywall**: For complete paywall management
|
|
93
|
-
- **Paywall Screen**: `src/presentation/screens/README.md`
|
|
94
|
-
- **Paywall Components**: `src/presentation/components/paywall/README.md`
|
|
95
|
-
- **Modal Integration**: `src/docs/MODAL_INTEGRATION.md`
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# usePremium Hook
|
|
2
|
-
|
|
3
|
-
Hook for checking and managing premium subscription status.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/usePremium.ts`
|
|
10
|
-
|
|
11
|
-
**Type**: Hook
|
|
12
|
-
|
|
13
|
-
## Strategy
|
|
14
|
-
|
|
15
|
-
### Premium Status Flow
|
|
16
|
-
|
|
17
|
-
1. **Initial Check**: Fetch current subscription status from repository
|
|
18
|
-
2. **Status Evaluation**: Determine if user has active premium subscription
|
|
19
|
-
3. **Real-time Updates**: Automatically update when user logs in/out or subscription changes
|
|
20
|
-
4. **Caching**: Cache status for 5 minutes (configurable) to reduce API calls
|
|
21
|
-
5. **Loading States**: Provide loading indicators during data fetch
|
|
22
|
-
6. **Error Handling**: Handle fetch errors gracefully
|
|
23
|
-
|
|
24
|
-
### Integration Points
|
|
25
|
-
|
|
26
|
-
- **Subscription Repository**: `src/infrastructure/repositories/SubscriptionRepository.ts`
|
|
27
|
-
- **TanStack Query**: For caching and real-time updates
|
|
28
|
-
- **Auth Context**: Sync with user authentication state
|
|
29
|
-
- **RevenueCat**: For subscription data source
|
|
30
|
-
|
|
31
|
-
## Restrictions
|
|
32
|
-
|
|
33
|
-
### REQUIRED
|
|
34
|
-
|
|
35
|
-
- **Loading State**: MUST handle loading state in UI
|
|
36
|
-
- **Error Handling**: MUST handle error state
|
|
37
|
-
- **Check Before Access**: MUST verify isPremium before showing premium features
|
|
38
|
-
|
|
39
|
-
### PROHIBITED
|
|
40
|
-
|
|
41
|
-
- **NEVER** use for security decisions (server-side validation required)
|
|
42
|
-
- **NEVER** assume instant data availability (always check loading state)
|
|
43
|
-
- **DO NOT** use for anonymous users without proper handling
|
|
44
|
-
|
|
45
|
-
### CRITICAL SAFETY
|
|
46
|
-
|
|
47
|
-
- **ALWAYS** handle loading state before rendering premium content
|
|
48
|
-
- **NEVER** trust client-side state for security enforcement
|
|
49
|
-
- **MUST** implement error boundaries when using this hook
|
|
50
|
-
|
|
51
|
-
## AI Agent Guidelines
|
|
52
|
-
|
|
53
|
-
### When Implementing Premium Features
|
|
54
|
-
|
|
55
|
-
1. **Always** check loading state first
|
|
56
|
-
2. **Always** handle error state
|
|
57
|
-
3. **Always** verify isPremium before showing premium content
|
|
58
|
-
4. **Never** use for security decisions without server validation
|
|
59
|
-
5. **Always** provide upgrade path for non-premium users
|
|
60
|
-
|
|
61
|
-
### Integration Checklist
|
|
62
|
-
|
|
63
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
64
|
-
- [ ] Handle loading state (show ActivityIndicator or skeleton)
|
|
65
|
-
- [ ] Handle error state (show error message)
|
|
66
|
-
- [ ] Check isPremium before rendering premium content
|
|
67
|
-
- [ ] Provide upgrade path for free users
|
|
68
|
-
- [ ] Test with premium user
|
|
69
|
-
- [ ] Test with free user
|
|
70
|
-
- [ ] Test with anonymous user
|
|
71
|
-
- [ ] Test offline scenario
|
|
72
|
-
|
|
73
|
-
### Common Patterns
|
|
74
|
-
|
|
75
|
-
1. **Conditional Rendering**: Show/hide features based on isPremium
|
|
76
|
-
2. **Premium Badge**: Display premium status badge
|
|
77
|
-
3. **Feature Gating**: Use usePremiumGate instead of manual checks
|
|
78
|
-
4. **Status Display**: Show subscription details with useSubscriptionDetails
|
|
79
|
-
5. **Upgrade Prompts**: Guide free users to paywall
|
|
80
|
-
|
|
81
|
-
## Related Documentation
|
|
82
|
-
|
|
83
|
-
- **usePremiumGate**: Gating premium features
|
|
84
|
-
- **useSubscription**: Detailed subscription status
|
|
85
|
-
- **useSubscriptionStatus**: Subscription status details
|
|
86
|
-
- **usePremiumWithCredits**: Hybrid premium/credits access
|
|
87
|
-
- **Subscription Repository**: `src/infrastructure/repositories/README.md`
|
|
88
|
-
- **Domain Layer**: `src/domain/README.md`
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# useSubscriptionSettingsConfig Hook
|
|
2
|
-
|
|
3
|
-
Returns ready-to-use configuration for subscription settings screens.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/useSubscriptionSettingsConfig.ts`
|
|
10
|
-
|
|
11
|
-
**Type**: Hook
|
|
12
|
-
|
|
13
|
-
## Strategy
|
|
14
|
-
|
|
15
|
-
### Settings Configuration Generation
|
|
16
|
-
|
|
17
|
-
1. **Data Aggregation**: Combine subscription, credits, and tier information
|
|
18
|
-
2. **Status Determination**: Calculate status type (active/expired/free/canceled)
|
|
19
|
-
3. **Date Formatting**: Format expiration and purchase dates
|
|
20
|
-
4. **Credit Items**: Generate credit item list with optional limit
|
|
21
|
-
5. **Translation Support**: Apply provided translations to all strings
|
|
22
|
-
6. **Upgrade Prompt**: Optional upgrade prompt configuration
|
|
23
|
-
|
|
24
|
-
### Integration Points
|
|
25
|
-
|
|
26
|
-
- **useSubscriptionStatus**: For subscription status details
|
|
27
|
-
- **useCredits**: For credits information
|
|
28
|
-
- **useUserTier**: For tier determination
|
|
29
|
-
- **Settings UI**: For settings screen integration
|
|
30
|
-
- **Translation System**: For localization support
|
|
31
|
-
|
|
32
|
-
## Restrictions
|
|
33
|
-
|
|
34
|
-
### REQUIRED
|
|
35
|
-
|
|
36
|
-
- **User ID**: MUST provide valid userId parameter
|
|
37
|
-
- **Translations**: MUST provide all translation strings
|
|
38
|
-
- **Null Handling**: MUST handle null dates and values
|
|
39
|
-
- **Enabled Check**: MUST check config.enabled before use
|
|
40
|
-
|
|
41
|
-
### PROHIBITED
|
|
42
|
-
|
|
43
|
-
- **NEVER** use without providing all translations
|
|
44
|
-
- **NEVER** assume config is enabled (check enabled flag)
|
|
45
|
-
- **DO NOT** hardcode translation strings
|
|
46
|
-
- **DO NOT** use without userId
|
|
47
|
-
|
|
48
|
-
### CRITICAL SAFETY
|
|
49
|
-
|
|
50
|
-
- **ALWAYS** check config.enabled before rendering
|
|
51
|
-
- **MUST** provide complete translation objects
|
|
52
|
-
- **ALWAYS** handle null dates gracefully
|
|
53
|
-
- **NEVER** trust client-side config for security
|
|
54
|
-
|
|
55
|
-
## AI Agent Guidelines
|
|
56
|
-
|
|
57
|
-
### When Implementing Settings Config
|
|
58
|
-
|
|
59
|
-
1. **Always** provide complete translations
|
|
60
|
-
2. **Always** check config.enabled
|
|
61
|
-
3. **Always** handle null dates
|
|
62
|
-
4. **Always** format dates appropriately
|
|
63
|
-
5. **Never** use for security decisions without server validation
|
|
64
|
-
|
|
65
|
-
### Integration Checklist
|
|
66
|
-
|
|
67
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
68
|
-
- [ ] Provide valid userId
|
|
69
|
-
- [ ] Provide complete translations
|
|
70
|
-
- [ ] Check config.enabled
|
|
71
|
-
- [ ] Handle null dates
|
|
72
|
-
- [ ] Format dates appropriately
|
|
73
|
-
- [ ] Apply credit limit if needed
|
|
74
|
-
- [ ] Configure upgrade prompt if needed
|
|
75
|
-
- [ ] Test with active subscription
|
|
76
|
-
- [ ] Test with expired subscription
|
|
77
|
-
- [ ] Test with free user
|
|
78
|
-
- [ ] Test with lifetime subscription
|
|
79
|
-
|
|
80
|
-
### Common Patterns
|
|
81
|
-
|
|
82
|
-
1. **Settings List Item**: Quick access item in settings
|
|
83
|
-
2. **Detailed Section**: Comprehensive subscription section
|
|
84
|
-
3. **Localized Settings**: Use with translation libraries
|
|
85
|
-
4. **Credit Limit**: Limit displayed credit items
|
|
86
|
-
5. **Upgrade Prompt**: Show upgrade prompt for free users
|
|
87
|
-
|
|
88
|
-
## Related Documentation
|
|
89
|
-
|
|
90
|
-
- **useSubscriptionStatus**: For subscription status details
|
|
91
|
-
- **useCredits**: For credits information
|
|
92
|
-
- **useSubscriptionDetails**: For package and pricing info
|
|
93
|
-
- **Settings Screen**: `src/presentation/screens/README.md`
|
|
94
|
-
- **Subscription Utilities**: `src/utils/subscriptionDateUtils.md`
|