@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
@@ -1,122 +1,41 @@
1
1
  # Wallet Domain Entities
2
2
 
3
+ ## Location
3
4
  Core entities for credits and transaction management.
4
5
 
5
- ## Overview
6
-
7
- This directory contains domain entities representing credits, transactions, and wallet-related business concepts.
8
-
9
- ## Entities
10
-
11
- ### UserCredits
12
- Represents user's credit balance and metadata.
13
-
14
- ```typescript
15
- interface UserCredits {
16
- credits: number; // Current credit balance
17
- purchasedAt: Date; // When credits were purchased
18
- lastUpdatedAt: Date; // Last update timestamp
19
- }
20
-
21
- interface CreditsResult {
22
- success: boolean;
23
- data?: UserCredits;
24
- error?: {
25
- code: string;
26
- message: string;
27
- };
28
- duplicate?: boolean; // If this was a duplicate operation
29
- }
30
- ```
31
-
32
- **Usage:**
33
- ```typescript
34
- const credits: UserCredits = {
35
- credits: 100,
36
- purchasedAt: new Date('2024-01-01'),
37
- lastUpdatedAt: new Date('2024-01-15'),
38
- };
39
- ```
40
-
41
- ### Transaction
42
- Represents a credit transaction record.
43
-
44
- ```typescript
45
- interface Transaction {
46
- id: string;
47
- amount: number; // Positive for additions, negative for deductions
48
- reason: string; // Description of transaction
49
- timestamp: Date; // When transaction occurred
50
- type: TransactionType; // Transaction category
51
- }
52
-
53
- type TransactionType =
54
- | 'purchase' // Initial purchase
55
- | 'deduction' // Feature usage
56
- | 'bonus' // Bonus credits
57
- | 'renewal' // Subscription renewal
58
- | 'adjustment'; // Manual adjustment
59
- ```
60
-
61
- **Usage:**
62
- ```typescript
63
- const transaction: Transaction = {
64
- id: 'tx_123',
65
- amount: -5,
66
- reason: 'ai_generation',
67
- timestamp: new Date(),
68
- type: 'deduction',
69
- };
70
- ```
71
-
72
- ### CreditPackage
73
- Represents a credit package for purchase.
74
-
75
- ```typescript
76
- interface CreditPackage {
77
- id: string;
78
- amount: number; // Number of credits
79
- price: number; // Price in currency units
80
- currency: string; // Currency code (USD, EUR, etc.)
81
- description?: string;
82
- }
83
- ```
84
-
85
- ## Key Operations
86
-
87
- ### Check Balance
88
- ```typescript
89
- function hasEnoughCredits(credits: UserCredits, required: number): boolean {
90
- return credits.credits >= required;
91
- }
92
- ```
93
-
94
- ### Calculate Remaining
95
- ```typescript
96
- function calculateRemaining(credits: UserCredits, spent: number): number {
97
- return Math.max(0, credits.credits - spent);
98
- }
99
- ```
100
-
101
- ### Validate Credits
102
- ```typescript
103
- function validateCredits(amount: number): void {
104
- if (amount < 0) {
105
- throw new Error('Credits cannot be negative');
106
- }
107
- }
108
- ```
109
-
110
- ## Best Practices
111
-
112
- 1. **Immutability**: Treat entities as immutable values
113
- 2. **Validation**: Validate in entity methods
114
- 3. **Type Safety**: Use strict TypeScript types
115
- 4. **Business Rules**: Keep business logic in entities
116
- 5. **Serialization**: Handle date serialization properly
117
-
118
- ## Related
119
-
6
+ ## Strategy
7
+ This directory contains domain entities representing credits, transactions, and wallet-related business concepts with strict immutability and validation.
8
+
9
+ ## Restrictions
10
+
11
+ ### REQUIRED
12
+ - Must treat entities as immutable values
13
+ - Must validate in entity methods
14
+ - Must use strict TypeScript types
15
+ - Must keep business logic in entities
16
+
17
+ ### PROHIBITED
18
+ - DO NOT mutate entities after creation
19
+ - DO NOT bypass validation methods
20
+ - DO NOT leak entity internals
21
+ - DO NOT allow invalid state
22
+
23
+ ### CRITICAL SAFETY
24
+ - All entities MUST be immutable
25
+ - Validation MUST be performed in entity methods
26
+ - Date serialization MUST be handled properly
27
+ - Business rules MUST be enforced in entities
28
+
29
+ ## AI Agent Guidelines
30
+ 1. Treat all entities as immutable values
31
+ 2. Perform validation within entity methods
32
+ 3. Use strict TypeScript types for all properties
33
+ 4. Keep business logic encapsulated in entities
34
+ 5. Handle date serialization properly for transactions
35
+ 6. Implement proper equality methods
36
+ 7. Provide clear validation error messages
37
+
38
+ ## Related Documentation
120
39
  - [Wallet Domain](../README.md)
121
40
  - [Credits Repository](../../infrastructure/repositories/README.md)
122
41
  - [useCredits Hook](../../../../presentation/hooks/useCredits.md)
@@ -1,157 +1,40 @@
1
1
  # Wallet Domain Errors
2
2
 
3
+ ## Location
3
4
  Domain-specific errors for wallet and credit operations.
4
5
 
5
- ## Overview
6
-
7
- This directory contains custom error classes representing wallet-related error conditions.
8
-
9
- ## Error Types
10
-
11
- ### CreditsExhaustedError
12
- Thrown when user doesn't have enough credits for an operation.
13
-
14
- ```typescript
15
- class CreditsExhaustedError extends Error {
16
- constructor(
17
- public currentBalance: number,
18
- public required: number
19
- ) {
20
- super(
21
- `Insufficient credits: ${currentBalance}/${required} required`,
22
- 'CREDITS_EXHAUSTED'
23
- );
24
- this.name = 'CreditsExhaustedError';
25
- }
26
- }
27
- ```
28
-
29
- **Usage:**
30
- ```typescript
31
- import { CreditsExhaustedError } from './errors/CreditsExhaustedError';
32
-
33
- function deductCredits(credits: UserCredits, amount: number) {
34
- if (credits.credits < amount) {
35
- throw new CreditsExhaustedError(credits.credits, amount);
36
- }
37
- // Proceed with deduction
38
- }
39
- ```
40
-
41
- ### DuplicatePurchaseError
42
- Thrown when attempting to add credits for a duplicate purchase ID.
43
-
44
- ```typescript
45
- class DuplicatePurchaseError extends Error {
46
- constructor(
47
- public purchaseId: string,
48
- public existingCredits: UserCredits
49
- ) {
50
- super(
51
- `Duplicate purchase ID: ${purchaseId}`,
52
- 'DUPLICATE_PURCHASE'
53
- );
54
- this.name = 'DuplicatePurchaseError';
55
- }
56
- }
57
- ```
58
-
59
- **Usage:**
60
- ```typescript
61
- try {
62
- await repository.initializeCredits(userId, purchaseId);
63
- } catch (error) {
64
- if (error instanceof DuplicatePurchaseError) {
65
- console.log('Credits already added for this purchase');
66
- }
67
- }
68
- ```
69
-
70
- ### CreditsValidationError
71
- Thrown when credit validation fails.
72
-
73
- ```typescript
74
- class CreditsValidationError extends Error {
75
- constructor(
76
- message: string,
77
- public code: string
78
- ) {
79
- super(message, code);
80
- this.name = 'CreditsValidationError';
81
- }
82
- }
83
- ```
84
-
85
- **Usage:**
86
- ```typescript
87
- function validateCreditAmount(amount: number) {
88
- if (amount < 0) {
89
- throw new CreditsValidationError(
90
- 'Credit amount cannot be negative',
91
- 'INVALID_AMOUNT'
92
- );
93
- }
94
- if (amount > 10000) {
95
- throw new CreditsValidationError(
96
- 'Credit amount exceeds maximum',
97
- 'EXCEEDS_MAXIMUM'
98
- );
99
- }
100
- }
101
- ```
102
-
103
- ## Error Handling Pattern
104
-
105
- ```typescript
106
- import {
107
- CreditsExhaustedError,
108
- DuplicatePurchaseError,
109
- CreditsValidationError
110
- } from './errors';
111
-
112
- async function handleCreditOperation(userId: string, cost: number) {
113
- try {
114
- const result = await repository.deductCredit(userId, cost);
115
- return result;
116
- } catch (error) {
117
- if (error instanceof CreditsExhaustedError) {
118
- // Show paywall or upgrade prompt
119
- showPaywall({ required: cost, current: error.currentBalance });
120
- } else if (error instanceof DuplicatePurchaseError) {
121
- // Log and continue (not a critical error)
122
- console.warn('Duplicate purchase detected');
123
- } else if (error instanceof CreditsValidationError) {
124
- // Log validation error
125
- console.error('Validation failed:', error.message);
126
- } else {
127
- // Unexpected error
128
- console.error('Unexpected error:', error);
129
- }
130
- throw error;
131
- }
132
- }
133
- ```
134
-
135
- ## Error Codes Reference
136
-
137
- | Code | Description | Recovery |
138
- |------|-------------|----------|
139
- | `CREDITS_EXHAUSTED` | Not enough credits | Show paywall/upgrade |
140
- | `DUPLICATE_PURCHASE` | Duplicate purchase ID | Ignore (idempotent) |
141
- | `INVALID_AMOUNT` | Invalid credit amount | Validate input |
142
- | `EXCEEDS_MAXIMUM` | Amount too large | Cap at maximum |
143
- | `USER_NOT_FOUND` | User doesn't exist | Create user record |
144
- | `INITIALIZATION_FAILED` | Credit init failed | Retry operation |
145
-
146
- ## Best Practices
147
-
148
- 1. **Specific Errors**: Use specific error types for different scenarios
149
- 2. **Error Context**: Include relevant data in error properties
150
- 3. **Graceful Handling**: Handle errors appropriately at boundaries
151
- 4. **Logging**: Log errors for debugging
152
- 5. **User Feedback**: Convert errors to user-friendly messages
153
-
154
- ## Related
155
-
6
+ ## Strategy
7
+ This directory contains custom error classes representing wallet-related error conditions with specific error types and recovery strategies.
8
+
9
+ ## Restrictions
10
+
11
+ ### REQUIRED
12
+ - Must use specific error types for different scenarios
13
+ - Must include relevant context in error properties
14
+ - Must handle errors gracefully at boundaries
15
+ - Must log errors for debugging
16
+
17
+ ### PROHIBITED
18
+ - DO NOT use generic error types
19
+ - DO NOT throw errors without context
20
+ - DO NOT ignore error conditions
21
+ - DO NOT expose technical errors to users
22
+
23
+ ### CRITICAL SAFETY
24
+ - All errors MUST be handled appropriately
25
+ - Error context MUST be sufficient for recovery
26
+ - Technical errors MUST be converted to user-friendly messages
27
+ - Error codes MUST be actionable
28
+
29
+ ## AI Agent Guidelines
30
+ 1. Use specific error types for different scenarios (CreditsExhaustedError, DuplicatePurchaseError, etc.)
31
+ 2. Include relevant data in error properties for recovery
32
+ 3. Handle errors gracefully at layer boundaries
33
+ 4. Log all errors with sufficient context for debugging
34
+ 5. Convert technical errors to user-friendly messages
35
+ 6. Follow error code reference for recovery strategies
36
+ 7. Test error handling paths thoroughly
37
+
38
+ ## Related Documentation
156
39
  - [Wallet Entities](../entities/README.md)
157
40
  - [Credits Repository](../../infrastructure/repositories/README.md)
@@ -1,96 +1,41 @@
1
1
  # Wallet Infrastructure
2
2
 
3
+ ## Location
3
4
  Infrastructure layer for wallet and credits functionality.
4
5
 
5
- ## Overview
6
-
7
- This directory contains implementations for credit persistence, transactions, and credit operations.
8
-
9
- ## Structure
10
-
11
- ```
12
- infrastructure/
13
- ├── repositories/ # Data persistence implementations
14
- │ └── CreditsRepository.ts
15
- └── services/ # External service integrations
16
- └── CreditsService.ts
17
- ```
18
-
19
- ## Credits Repository
20
-
21
- Handles credit data persistence with duplicate protection.
22
-
23
- ### Key Features
24
-
25
- - **Duplicate Protection**: Prevents duplicate credit allocations
26
- - **Optimistic Updates**: Immediate UI updates with rollback
27
- - **Transactional**: Atomic credit operations
28
- - **ACCUMULATE Mode**: Adds credits on renewal
29
-
30
- ### Core Methods
31
-
32
- ```typescript
33
- class CreditsRepository implements ICreditsRepository {
34
- async getCredits(userId: string): Promise<UserCredits | null>;
35
- async initializeCredits(
36
- userId: string,
37
- purchaseId?: string,
38
- productId?: string
39
- ): Promise<CreditsResult>;
40
- async deductCredit(userId: string, amount: number): Promise<CreditsResult>;
41
- async addCredits(userId: string, amount: number): Promise<CreditsResult>;
42
- }
43
- ```
44
-
45
- ### Usage
46
-
47
- ```typescript
48
- import { CreditsRepository } from './repositories/CreditsRepository';
49
- import { getCreditsRepository } from './repositories/CreditsRepositoryProvider';
50
-
51
- const repository = getCreditsRepository();
52
-
53
- // Initialize credits
54
- const result = await repository.initializeCredits('user-123', 'purchase-456', 'premium_monthly');
55
- if (result.success) {
56
- console.log('Credits:', result.data.credits);
57
- }
58
-
59
- // Deduct credits
60
- const deductResult = await repository.deductCredit('user-123', 5);
61
- if (deductResult.success) {
62
- console.log('Credits deducted successfully');
63
- } else if (deductResult.error?.code === 'CREDITS_EXHAUSTED') {
64
- console.log('Not enough credits');
65
- }
66
- ```
67
-
68
- ## Duplicate Protection
69
-
70
- The repository prevents duplicate credit allocations based on `purchaseId`:
71
-
72
- ```typescript
73
- // First call
74
- await repository.initializeCredits(userId, 'renewal-123', 'premium');
75
- // Returns: { success: true, data: { credits: 100 } }
76
-
77
- // Second call with same purchaseId
78
- await repository.initializeCredits(userId, 'renewal-123', 'premium');
79
- // Returns: { success: true, duplicate: true, data: { credits: 100 } }
80
- // Credits not added again
81
- ```
82
-
83
- ## Best Practices
84
-
85
- 1. **Check Before Deduct**: Always verify credit balance
86
- 2. **Handle Errors**: Catch and handle credit errors appropriately
87
- 3. **Use Transactions**: Ensure data consistency
88
- 4. **Log Operations**: Track credit operations for debugging
89
- 5. **Test Edge Cases**: Zero credits, max credits, duplicates
90
- 6. **Validate Input**: Validate all input parameters
91
-
92
- ## Related
93
-
6
+ ## Strategy
7
+ This directory contains implementations for credit persistence, transactions, and credit operations with duplicate protection and optimistic updates.
8
+
9
+ ## Restrictions
10
+
11
+ ### REQUIRED
12
+ - Must check credit balance before deducting
13
+ - Must handle errors appropriately
14
+ - Must use transactions for data consistency
15
+ - Must log all credit operations
16
+
17
+ ### PROHIBITED
18
+ - DO NOT deduct credits without balance check
19
+ - DO NOT allow duplicate credit allocations
20
+ - DO NOT skip transaction boundaries
21
+ - DO NOT ignore credit operation errors
22
+
23
+ ### CRITICAL SAFETY
24
+ - Duplicate allocations MUST be prevented based on purchaseId
25
+ - Credit operations MUST be atomic
26
+ - All operations MUST be logged for debugging
27
+ - Input validation MUST be performed
28
+
29
+ ## AI Agent Guidelines
30
+ 1. Always verify credit balance before deduction operations
31
+ 2. Implement comprehensive error handling for credit operations
32
+ 3. Use transactions to ensure data consistency
33
+ 4. Track all credit operations with detailed logging
34
+ 5. Test edge cases: zero credits, max credits, duplicates
35
+ 6. Validate all input parameters before processing
36
+ 7. Implement duplicate protection based on purchaseId
37
+
38
+ ## Related Documentation
94
39
  - [Wallet Domain](../domain/README.md)
95
40
  - [Credits Entity](../domain/entities/README.md)
96
41
  - [useCredits Hook](../../presentation/hooks/useCredits.md)