@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,185 +2,49 @@
2
2
 
3
3
  Value objects for the subscription domain.
4
4
 
5
- ## Purpose
6
-
7
- Value objects are immutable objects that represent concepts by their attributes rather than identity. They are used to ensure validity and prevent primitive obsession.
8
-
9
- ## Value Objects
10
-
11
- ### SubscriptionConfig
12
-
13
- Configuration object for subscription system.
14
-
15
- ```typescript
16
- interface SubscriptionConfig {
17
- revenueCatApiKey: string;
18
- revenueCatEntitlementId: string;
19
- plans: Record<string, Plan>;
20
- defaultPlan: string;
21
- features: ConfigFeatures;
22
- ui?: ConfigUI;
23
- onStatusChanged?: (userId: string, status: SubscriptionStatus) => void;
24
- onError?: (error: Error) => void;
25
- }
26
- ```
27
-
28
- **Usage:**
29
- ```typescript
30
- import { SubscriptionConfig } from '@umituz/react-native-subscription/domain';
31
-
32
- const config: SubscriptionConfig = {
33
- revenueCatApiKey: 'your_key',
34
- revenueCatEntitlementId: 'premium',
35
- plans: {
36
- monthly: monthlyPlan,
37
- annual: annualPlan,
38
- },
39
- defaultPlan: 'monthly',
40
- features: {
41
- requireAuth: true,
42
- allowRestore: true,
43
- },
44
- };
45
- ```
46
-
47
- ## Characteristics
48
-
49
- ### 1. Immutable
50
-
51
- ```typescript
52
- const config = SubscriptionConfig.create({...});
53
- // config.apiKey = 'new_key'; // Error: Cannot assign
54
- ```
55
-
56
- ### 2. Value-Based Equality
57
-
58
- ```typescript
59
- const config1 = SubscriptionConfig.create({...});
60
- const config2 = SubscriptionConfig.create({...});
61
-
62
- config1.equals(config2); // true (if same values)
63
- ```
64
-
65
- ### 3. Self-Validating
66
-
67
- ```typescript
68
- const config = SubscriptionConfig.create({
69
- apiKey: '', // Invalid!
70
- entitlementId: 'premium',
71
- });
72
- // Throws ValidationError
73
- ```
74
-
75
- ## Creating Value Objects
76
-
77
- ### Factory Method
78
-
79
- ```typescript
80
- const config = SubscriptionConfig.create({
81
- apiKey: 'your_key',
82
- entitlementId: 'premium',
83
- });
84
- ```
85
-
86
- ### Builder Pattern
87
-
88
- ```typescript
89
- const config = SubscriptionConfig.builder()
90
- .apiKey('your_key')
91
- .entitlementId('premium')
92
- .addPlan('monthly', monthlyPlan)
93
- .addPlan('annual', annualPlan)
94
- .build();
95
- ```
96
-
97
- ## Common Value Objects
98
-
99
- ### Money
100
-
101
- ```typescript
102
- class Money {
103
- private constructor(
104
- private amount: number,
105
- private currency: string
106
- ) {}
107
-
108
- static create(amount: number, currency: string): Money {
109
- if (amount < 0) throw new Error('Amount cannot be negative');
110
- return new Money(amount, currency);
111
- }
112
-
113
- format(): string {
114
- return new Intl.NumberFormat('en-US', {
115
- style: 'currency',
116
- currency: this.currency,
117
- }).format(this.amount);
118
- }
119
-
120
- add(other: Money): Money {
121
- if (this.currency !== other.currency) {
122
- throw new Error('Cannot add different currencies');
123
- }
124
- return new Money(this.amount + other.amount, this.currency);
125
- }
126
- }
127
- ```
128
-
129
- ### DateRange
130
-
131
- ```typescript
132
- class DateRange {
133
- constructor(
134
- private start: Date,
135
- private end: Date
136
- ) {}
137
-
138
- includes(date: Date): boolean {
139
- return date >= this.start && date <= this.end;
140
- }
141
-
142
- durationInDays(): number {
143
- return Math.ceil(
144
- (this.end.getTime() - this.start.getTime()) / (1000 * 60 * 60 * 24)
145
- );
146
- }
147
- }
148
- ```
149
-
150
- ## Best Practices
151
-
152
- 1. **Make immutable** - All properties readonly
153
- 2. **Validate on creation** - Fail fast
154
- 3. **Override equality** - Compare by value, not reference
155
- 4. **Use for complex attributes** - Don't use for simple primitives
156
- 5. **Keep small** - Value objects should be focused
157
-
158
- ## Testing
159
-
160
- ```typescript
161
- describe('SubscriptionConfig', () => {
162
- it('should create valid config', () => {
163
- const config = SubscriptionConfig.create({
164
- apiKey: 'test_key',
165
- entitlementId: 'premium',
166
- });
167
-
168
- expect(config.apiKey).toBe('test_key');
169
- });
170
-
171
- it('should reject invalid config', () => {
172
- expect(() => {
173
- SubscriptionConfig.create({
174
- apiKey: '',
175
- entitlementId: 'premium',
176
- });
177
- }).toThrow();
178
- });
179
- });
180
- ```
181
-
182
- ## Related
5
+ ## Location
6
+
7
+ `src/domain/value-objects/`
8
+
9
+ ## Strategy
10
+
11
+ Value objects are immutable objects that represent concepts by their attributes rather than identity. They ensure validity and prevent primitive obsession by providing type-safe, validated representations.
12
+
13
+ ## Restrictions
14
+
15
+ ### REQUIRED
16
+
17
+ - MUST be immutable (all properties readonly)
18
+ - MUST validate on creation (fail fast)
19
+ - MUST override equality (compare by value, not reference)
20
+ - MUST use for complex attributes (not simple primitives)
21
+ - MUST be small and focused
22
+
23
+ ### PROHIBITED
24
+
25
+ - MUST NOT allow mutation after creation
26
+ - MUST NOT use reference equality for comparison
27
+ - MUST NOT contain invalid states
28
+ - MUST NOT have identity-based equality
29
+
30
+ ### CRITICAL
31
+
32
+ - Always validate on creation
33
+ - Implement value-based equality comparison
34
+ - Keep value objects small and focused
35
+ - Use only for complex attributes, not simple primitives
36
+
37
+ ## AI Agent Guidelines
38
+
39
+ When working with value objects:
40
+ 1. Make immutable - all properties readonly
41
+ 2. Validate on creation - fail fast
42
+ 3. Override equality - compare by value, not reference
43
+ 4. Use for complex attributes - don't use for simple primitives
44
+ 5. Keep small - value objects should be focused
45
+
46
+ ## Related Documentation
183
47
 
184
48
  - [Domain Entities](../entities/README.md)
185
49
  - [Domain Errors](../errors/README.md)
186
- - [Domain Layer](../../README.md)
50
+ - [Domain Layer](../README.md)
@@ -1,240 +1,52 @@
1
1
  # Domains
2
2
 
3
- This directory contains specialized domain modules that implement specific business logic and features.
4
-
5
- ## Overview
6
-
7
- The `domains` directory organizes business logic into focused, self-contained modules. Each domain follows Domain-Driven Design (DDD) principles and Clean Architecture patterns.
8
-
9
- ## Domain Modules
10
-
11
- ### Wallet Domain (`wallet/`)
12
-
13
- Manages credits, transactions, and wallet operations.
14
-
15
- **Key Features:**
16
- - Credit balance tracking
17
- - Transaction history
18
- - Credit deduction and allocation
19
- - Purchase initialization
20
- - Duplicate protection
21
-
22
- **Structure:**
23
- ```
24
- wallet/
25
- ├── domain/ # Business logic and entities
26
- │ ├── entities/ # UserCredits, Transaction, CreditPackage
27
- │ ├── types/ # Type definitions
28
- │ └── mappers/ # Data transformation
29
- ├── infrastructure/ # External integrations
30
- │ ├── repositories/ # Data persistence
31
- │ └── services/ # External services
32
- └── presentation/ # UI layer
33
- ├── hooks/ # React hooks
34
- ├── components/ # React components
35
- └── screens/ # Screen components
36
- ```
37
-
38
- **Key Entities:**
39
- - `UserCredits`: Credit balance and allocations
40
- - `Transaction`: Credit transaction records
41
- - `CreditPackage`: Purchasable credit packages
42
-
43
- **Allocation Modes:**
44
- - **ACCUMULATE**: Add credits on renewal (default)
45
- - **REPLACE**: Replace existing credits with new allocation
46
-
47
- **Related:**
48
- - [Wallet Domain README](./wallet/README.md)
49
- - [Wallet Entities](./wallet/domain/entities/README.md)
50
- - [Wallet Hooks](./wallet/presentation/hooks/README.md)
51
-
52
- ### Paywall Domain (`paywall/`)
53
-
54
- Manages paywall display, triggers, and purchase flows.
55
-
56
- **Key Features:**
57
- - Paywall visibility management
58
- - Trigger-based paywall display
59
- - Package selection and comparison
60
- - Purchase operations
61
- - Feedback collection
62
-
63
- **Structure:**
64
- ```
65
- paywall/
66
- ├── domain/ # Business logic
67
- │ └── entities/ # PaywallTrigger, PaywallConfig, PaywallState
68
- ├── components/ # UI components
69
- │ ├── PaywallScreen/
70
- │ ├── PackageCard/
71
- │ └── FeatureComparison/
72
- └── hooks/ # React hooks
73
- └── usePaywallOperations/
74
- ```
75
-
76
- **Triggers:**
77
- - `premium_feature`: User attempts premium feature
78
- - `credit_gate`: Insufficient credits
79
- - `manual`: Manually triggered
80
- - `onboarding_complete`: After onboarding
81
- - `usage_limit`: Reached usage limit
82
-
83
- **Related:**
84
- - [Paywall Domain README](./paywall/README.md)
85
- - [Paywall Entities](./paywall/entities/README.md)
86
- - [Paywall Components](./paywall/components/README.md)
87
-
88
- ### Config Domain (`config/`)
89
-
90
- Manages subscription and feature configuration.
91
-
92
- **Key Features:**
93
- - Package configuration
94
- - Feature flags
95
- - Subscription settings
96
- - Paywall customization
97
-
98
- **Structure:**
99
- ```
100
- config/
101
- ├── domain/ # Configuration entities
102
- │ ├── entities/ # Config entities
103
- │ └── value-objects/ # Configuration value objects
104
- └── utils/ # Configuration utilities
105
- ```
106
-
107
- **Related:**
108
- - [Config Domain README](./config/README.md)
109
-
110
- ## Architecture Principles
111
-
112
- ### 1. Domain-Driven Design (DDD)
113
- Each domain represents a distinct business capability with:
114
- - Clear boundaries
115
- - Ubiquitous language
116
- - Domain entities
117
- - Business rules
118
-
119
- ### 2. Clean Architecture
120
- Each domain follows layered architecture:
121
- - **Domain Layer**: Business logic, entities (pure)
122
- - **Application Layer**: Use cases, orchestration
123
- - **Infrastructure Layer**: External integrations (persistence, APIs)
124
- - **Presentation Layer**: UI components, hooks
125
-
126
- ### 3. Independence
127
- Domains are independent and can:
128
- - Be developed in isolation
129
- - Have their own data stores
130
- - Be tested independently
131
- - Scale independently
132
-
133
- ### 4. Communication
134
- Domains communicate through:
135
- - Well-defined interfaces
136
- - Events (when needed)
137
- - Shared kernels (when necessary)
138
-
139
- ## Usage Patterns
140
-
141
- ### Using Wallet Domain
142
-
143
- ```typescript
144
- import { useCredits } from './wallet/presentation/hooks';
145
- import { CreditBalanceCard } from './wallet/presentation/components';
146
-
147
- function MyComponent() {
148
- const { credits, transactions } = useCredits({ userId: user?.uid });
149
-
150
- return (
151
- <CreditBalanceCard
152
- credits={credits}
153
- balance={calculateBalance(credits)}
154
- />
155
- );
156
- }
157
- ```
158
-
159
- ### Using Paywall Domain
160
-
161
- ```typescript
162
- import { usePaywallOperations } from './paywall/hooks';
163
-
164
- function MyScreen() {
165
- const { handlePurchase } = usePaywallOperations({
166
- userId: user?.uid,
167
- isAnonymous: false,
168
- });
169
-
170
- const onBuyPress = () => {
171
- handlePurchase(selectedPackage);
172
- };
173
- }
174
- ```
175
-
176
- ### Using Config Domain
177
-
178
- ```typescript
179
- import { getPackageConfiguration } from './config/utils';
180
-
181
- const packages = getPackageConfiguration('premium');
182
- ```
183
-
184
- ## Adding New Domains
185
-
186
- When adding a new domain:
187
-
188
- 1. **Create Domain Structure**
189
- ```bash
190
- src/domains/your-domain/
191
- ├── domain/
192
- │ ├── entities/
193
- │ ├── value-objects/
194
- │ └── types/
195
- ├── infrastructure/
196
- │ ├── repositories/
197
- │ └── services/
198
- └── presentation/
199
- ├── hooks/
200
- ├── components/
201
- └── screens/
202
- ```
203
-
204
- 2. **Define Entities**
205
- - Create core business entities
206
- - Define business rules
207
- - Implement validations
208
-
209
- 3. **Implement Infrastructure**
210
- - Create repositories for data persistence
211
- - Implement external service integrations
212
- - Add mappers for data transformation
213
-
214
- 4. **Create Presentation Layer**
215
- - Implement React hooks
216
- - Create UI components
217
- - Build screens
218
-
219
- 5. **Add Documentation**
220
- - Create README for domain
221
- - Document entities
222
- - Provide usage examples
223
-
224
- ## Best Practices
225
-
226
- 1. **Encapsulation**: Keep domain logic isolated
227
- 2. **Purity**: Domain layer should have no external dependencies
228
- 3. **Interfaces**: Depend on abstractions, not concretions
229
- 4. **Testing**: Each domain should be independently testable
230
- 5. **Documentation**: Document business rules and entities
231
- 6. **Type Safety**: Use TypeScript for all domain models
232
- 7. **Validation**: Validate at domain boundaries
233
- 8. **Error Handling**: Use domain-specific errors
234
-
235
- ## Related
236
-
237
- - [Domain Layer README](../domain/README.md)
238
- - [Application Layer README](../application/README.md)
239
- - [Infrastructure Layer README](../infrastructure/README.md)
240
- - [RevenueCat Integration README](../revenuecat/README.md)
3
+ Specialized domain modules implementing specific business logic and features.
4
+
5
+ ## Location
6
+
7
+ `src/domains/`
8
+
9
+ ## Strategy
10
+
11
+ Implements Domain-Driven Design (DDD) principles with self-contained domains. Each domain includes domain layer (business logic, entities, value objects), infrastructure layer (external integrations, repositories), and presentation layer (domain-specific hooks and components).
12
+
13
+ ## Restrictions
14
+
15
+ ### REQUIRED
16
+
17
+ - Domains MUST NOT directly depend on each other
18
+ - MUST use well-defined interfaces between layers
19
+ - MUST depend on abstractions, not concretions (Dependency Inversion)
20
+ - All domains MUST be testable in isolation
21
+
22
+ ### PROHIBITED
23
+
24
+ - MUST NOT share domain logic between domains (use shared kernel if needed)
25
+ - MUST NOT create circular dependencies between domains
26
+ - MUST NOT bypass domain layer from presentation
27
+ - MUST NOT expose infrastructure details to other domains
28
+
29
+ ### CRITICAL
30
+
31
+ - Always validate invariants at domain boundaries
32
+ - Always implement domain errors for business rule violations
33
+ - Never allow inconsistent domain state
34
+ - Must implement proper transaction boundaries
35
+ - Always sanitize inputs from external sources
36
+
37
+ ## AI Agent Guidelines
38
+
39
+ When working with domains:
40
+ 1. Always respect domain boundaries
41
+ 2. Always use dependency inversion
42
+ 3. Always implement domain-specific errors
43
+ 4. Always validate invariants at boundaries
44
+ 5. Never create circular dependencies
45
+
46
+ ## Related Documentation
47
+
48
+ - [Wallet Domain](wallet/README.md)
49
+ - [Paywall Domain](paywall/README.md)
50
+ - [Config Domain](config/README.md)
51
+ - [Domain Layer](../domain/README.md)
52
+ - [Infrastructure](../infrastructure/README.md)