@umituz/react-native-subscription 2.14.99 → 2.14.101

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 (98) hide show
  1. package/README.md +211 -394
  2. package/package.json +3 -3
  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/entities/SubscriptionStatus.ts +1 -1
  9. package/src/domain/errors/README.md +33 -287
  10. package/src/domain/value-objects/README.md +43 -179
  11. package/src/domains/README.md +50 -238
  12. package/src/domains/README.md.bak +274 -0
  13. package/src/domains/config/README.md +93 -383
  14. package/src/domains/config/domain/README.md +23 -376
  15. package/src/domains/config/domain/entities/README.md +34 -343
  16. package/src/domains/paywall/README.md +99 -369
  17. package/src/domains/paywall/components/README.md +34 -178
  18. package/src/domains/paywall/entities/README.md +34 -193
  19. package/src/domains/paywall/hooks/README.md +34 -122
  20. package/src/domains/wallet/README.md +34 -275
  21. package/src/domains/wallet/README.md.bak +209 -0
  22. package/src/domains/wallet/domain/README.md +34 -101
  23. package/src/domains/wallet/domain/entities/README.md +34 -115
  24. package/src/domains/wallet/domain/errors/README.md +34 -151
  25. package/src/domains/wallet/infrastructure/README.md +34 -89
  26. package/src/domains/wallet/presentation/components/README.md +34 -224
  27. package/src/domains/wallet/presentation/components/TransactionItem.tsx +1 -1
  28. package/src/domains/wallet/presentation/hooks/README.md +34 -248
  29. package/src/infrastructure/README.md +37 -496
  30. package/src/infrastructure/mappers/README.md +0 -13
  31. package/src/infrastructure/repositories/README.md +74 -360
  32. package/src/infrastructure/services/ActivationHandler.ts +1 -1
  33. package/src/infrastructure/services/README.md +95 -370
  34. package/src/infrastructure/services/SubscriptionService.ts +1 -1
  35. package/src/presentation/README.md +123 -408
  36. package/src/presentation/README.md.bak +172 -0
  37. package/src/presentation/components/README.md +151 -179
  38. package/src/presentation/components/README.md.bak +217 -0
  39. package/src/presentation/components/details/CreditRow.md +65 -310
  40. package/src/presentation/components/details/DetailRow.md +63 -255
  41. package/src/presentation/components/details/PremiumDetailsCard.md +65 -238
  42. package/src/presentation/components/details/PremiumStatusBadge.md +64 -239
  43. package/src/presentation/components/details/README.md +97 -447
  44. package/src/presentation/components/feedback/PaywallFeedbackModal.md +63 -287
  45. package/src/presentation/components/feedback/README.md +97 -445
  46. package/src/presentation/components/paywall/PaywallModal.md +66 -416
  47. package/src/presentation/components/paywall/README.md +50 -186
  48. package/src/presentation/components/sections/README.md +97 -466
  49. package/src/presentation/components/sections/SubscriptionSection.md +92 -244
  50. package/src/presentation/hooks/README.md +154 -741
  51. package/src/presentation/hooks/useAuthAwarePurchase.md +58 -325
  52. package/src/presentation/hooks/useAuthGate.md +61 -375
  53. package/src/presentation/hooks/useAuthSubscriptionSync.md +66 -370
  54. package/src/presentation/hooks/useCreditChecker.md +73 -378
  55. package/src/presentation/hooks/useCredits.md +74 -313
  56. package/src/presentation/hooks/useCredits.md.bak +231 -0
  57. package/src/presentation/hooks/useCreditsGate.md +66 -318
  58. package/src/presentation/hooks/useDeductCredit.md +0 -76
  59. package/src/presentation/hooks/useDeductCredit.ts +1 -1
  60. package/src/presentation/hooks/useDevTestCallbacks.md +63 -394
  61. package/src/presentation/hooks/useFeatureGate.md +105 -150
  62. package/src/presentation/hooks/useFeatureGate.md.bak +284 -0
  63. package/src/presentation/hooks/useInitializeCredits.md +64 -430
  64. package/src/presentation/hooks/usePaywall.md +61 -306
  65. package/src/presentation/hooks/usePaywallOperations.md +64 -458
  66. package/src/presentation/hooks/usePaywallVisibility.md +67 -316
  67. package/src/presentation/hooks/usePremium.md +84 -226
  68. package/src/presentation/hooks/usePremiumGate.md +60 -395
  69. package/src/presentation/hooks/usePremiumWithCredits.md +64 -401
  70. package/src/presentation/hooks/useSubscription.md +66 -422
  71. package/src/presentation/hooks/useSubscriptionDetails.md +65 -410
  72. package/src/presentation/hooks/useSubscriptionGate.md +80 -164
  73. package/src/presentation/hooks/useSubscriptionSettingsConfig.md +66 -346
  74. package/src/presentation/hooks/useSubscriptionStatus.md +66 -396
  75. package/src/presentation/hooks/useUserTier.md +63 -328
  76. package/src/presentation/hooks/useUserTierWithRepository.md +64 -424
  77. package/src/presentation/screens/README.md +48 -190
  78. package/src/presentation/types/README.md +0 -16
  79. package/src/presentation/utils/README.md +0 -21
  80. package/src/presentation/utils/subscriptionDateUtils.ts +1 -1
  81. package/src/revenuecat/README.md +99 -518
  82. package/src/revenuecat/application/README.md +35 -150
  83. package/src/revenuecat/application/ports/README.md +34 -162
  84. package/src/revenuecat/domain/README.md +42 -141
  85. package/src/revenuecat/domain/constants/README.md +34 -176
  86. package/src/revenuecat/domain/entities/README.md +34 -374
  87. package/src/revenuecat/domain/errors/README.md +47 -191
  88. package/src/revenuecat/domain/types/README.md +34 -366
  89. package/src/revenuecat/domain/value-objects/README.md +34 -434
  90. package/src/revenuecat/infrastructure/README.md +34 -43
  91. package/src/revenuecat/infrastructure/config/README.md +32 -23
  92. package/src/revenuecat/infrastructure/handlers/README.md +34 -211
  93. package/src/revenuecat/infrastructure/managers/README.md +34 -42
  94. package/src/revenuecat/infrastructure/services/README.md +35 -318
  95. package/src/revenuecat/infrastructure/utils/README.md +34 -375
  96. package/src/revenuecat/presentation/README.md +34 -176
  97. package/src/revenuecat/presentation/hooks/README.md +29 -35
  98. package/src/utils/README.md +38 -525
@@ -2,384 +2,98 @@
2
2
 
3
3
  Repository implementations for data persistence.
4
4
 
5
- ## Purpose
5
+ ## Location
6
6
 
7
- Repositories handle data access and persistence, abstracting away the details of storage mechanisms.
7
+ - **Base Path**: `/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-subscription/src/infrastructure/repositories/`
8
+ - **Repositories**: `src/infrastructure/repositories/`
8
9
 
9
- ## Available Repositories
10
+ ## Strategy
10
11
 
11
- ### CreditsRepository
12
+ ### Repository Pattern
12
13
 
13
- Manages credits data in Firestore.
14
+ Data access abstraction layer.
14
15
 
15
- ```typescript
16
- import {
17
- configureCreditsRepository,
18
- getCreditsRepository,
19
- type CreditsRepository,
20
- } from '@umituz/react-native-subscription/infrastructure';
16
+ - **CreditsRepository**: Credits data management
17
+ - **TransactionRepository**: Transaction history
18
+ - **SubscriptionRepository**: Subscription status management
19
+ - **Custom Repositories**: Extensible repository architecture
21
20
 
22
- // Configure
23
- configureCreditsRepository({
24
- firebase: { firestore: db },
25
- config: creditsConfig,
26
- });
21
+ ### Data Access Patterns
27
22
 
28
- // Get instance
29
- const repository = getCreditsRepository();
23
+ Structured data access implementations.
30
24
 
31
- // Use
32
- const credits = await repository.getCredits('user-123');
33
- ```
25
+ - **Active Record**: Entity-based data management
26
+ - **Data Mapper**: Separation of entities and data
27
+ - **Repository with Caching**: Performance optimization
28
+ - **Transaction Support**: Atomic operations
34
29
 
35
- ### TransactionRepository
30
+ ### Storage Implementations
36
31
 
37
- Manages transaction history.
32
+ Multiple storage backend support.
38
33
 
39
- ```typescript
40
- import {
41
- createTransactionRepository,
42
- type TransactionRepository,
43
- } from '@umituz/react-native-subscription/wallet';
34
+ - **Firestore**: Cloud Firestore implementation
35
+ - **In-Memory**: Testing and development
36
+ - **HTTP**: REST API integration
37
+ - **Redis**: Redis cache implementation
44
38
 
45
- const repository = createTransactionRepository({
46
- firebase: { firestore: db },
47
- userId: 'user-123',
48
- });
39
+ ### Advanced Features
49
40
 
50
- const transactions = await repository.getTransactions({ limit: 20 });
51
- ```
41
+ Enterprise-level repository capabilities.
52
42
 
53
- ## Custom Repositories
43
+ - **Real-Time Updates**: Firestore real-time listeners
44
+ - **Transaction Support**: Multi-document transactions
45
+ - **Caching**: Performance optimization
46
+ - **Mocking**: Testing support
54
47
 
55
- ### Creating a Custom Repository
48
+ ## Restrictions
56
49
 
57
- ```typescript
58
- import type { ISubscriptionRepository } from '@umituz/react-native-subscription/application';
50
+ ### REQUIRED
59
51
 
60
- class HttpSubscriptionRepository implements ISubscriptionRepository {
61
- private baseUrl: string;
52
+ - **Interface Implementation**: Implement required interfaces
53
+ - **Error Handling**: Transform storage errors to domain errors
54
+ - **Validation**: Validate data before saving
55
+ - **Logging**: Log repository operations
62
56
 
63
- constructor(baseUrl: string) {
64
- this.baseUrl = baseUrl;
65
- }
57
+ ### PROHIBITED
66
58
 
67
- async getSubscriptionStatus(userId: string): Promise<SubscriptionStatus | null> {
68
- const response = await fetch(`${this.baseUrl}/subscriptions/${userId}`);
59
+ - **Business Logic**: Keep business logic in services
60
+ - **Direct Exposure**: Never expose storage-specific types
61
+ - **Missing Validation**: Never save invalid data
62
+ - **Swallowed Errors**: Always handle or propagate errors
69
63
 
70
- if (!response.ok) {
71
- throw new SubscriptionRepositoryError('Failed to fetch subscription');
72
- }
64
+ ### CRITICAL
73
65
 
74
- return await response.json();
75
- }
76
-
77
- async saveSubscriptionStatus(
78
- userId: string,
79
- status: SubscriptionStatus
80
- ): Promise<void> {
81
- const response = await fetch(`${this.baseUrl}/subscriptions/${userId}`, {
82
- method: 'PUT',
83
- headers: { 'Content-Type': 'application/json' },
84
- body: JSON.stringify(status),
85
- });
86
-
87
- if (!response.ok) {
88
- throw new SubscriptionRepositoryError('Failed to save subscription');
89
- }
90
- }
91
-
92
- async deleteSubscriptionStatus(userId: string): Promise<void> {
93
- const response = await fetch(`${this.baseUrl}/subscriptions/${userId}`, {
94
- method: 'DELETE',
95
- });
96
-
97
- if (!response.ok) {
98
- throw new SubscriptionRepositoryError('Failed to delete subscription');
99
- }
100
- }
101
-
102
- isSubscriptionValid(status: SubscriptionStatus): boolean {
103
- return status.isActive && !isExpired(status.expirationDate);
104
- }
105
- }
106
- ```
107
-
108
- ### In-Memory Repository (for testing)
109
-
110
- ```typescript
111
- class InMemorySubscriptionRepository implements ISubscriptionRepository {
112
- private storage = new Map<string, SubscriptionStatus>();
113
-
114
- async getSubscriptionStatus(userId: string): Promise<SubscriptionStatus | null> {
115
- return this.storage.get(userId) || null;
116
- }
117
-
118
- async saveSubscriptionStatus(
119
- userId: string,
120
- status: SubscriptionStatus
121
- ): Promise<void> {
122
- this.storage.set(userId, status);
123
- }
124
-
125
- async deleteSubscriptionStatus(userId: string): Promise<void> {
126
- this.storage.delete(userId);
127
- }
128
-
129
- isSubscriptionValid(status: SubscriptionStatus): boolean {
130
- return status.isActive && !isExpired(status.expirationDate);
131
- }
132
-
133
- // Test helpers
134
- __reset() {
135
- this.storage.clear();
136
- }
137
- }
138
- ```
139
-
140
- ### Redis Repository
141
-
142
- ```typescript
143
- import Redis from 'ioredis';
144
-
145
- class RedisCreditsRepository {
146
- private redis: Redis;
147
- private prefix = 'credits:';
148
-
149
- constructor(redis: Redis) {
150
- this.redis = redis;
151
- }
152
-
153
- async getCredits(userId: string): Promise<UserCredits> {
154
- const key = `${this.prefix}${userId}`;
155
- const data = await this.redis.get(key);
156
-
157
- if (!data) {
158
- return {
159
- balance: 0,
160
- lastUpdated: new Date().toISOString(),
161
- };
162
- }
163
-
164
- return JSON.parse(data);
165
- }
166
-
167
- async setCredits(userId: string, credits: UserCredits): Promise<void> {
168
- const key = `${this.prefix}${userId}`;
169
- await this.redis.set(key, JSON.stringify(credits));
170
- }
171
-
172
- async addCredits(
173
- userId: string,
174
- amount: number
175
- ): Promise<UserCredits> {
176
- const current = await this.getCredits(userId);
177
- const updated = {
178
- ...current,
179
- balance: current.balance + amount,
180
- lastUpdated: new Date().toISOString(),
181
- };
182
-
183
- await this.setCredits(userId, updated);
184
- return updated;
185
- }
186
- }
187
- ```
188
-
189
- ## Repository Patterns
190
-
191
- ### 1. Active Record Pattern
192
-
193
- ```typescript
194
- class Subscription {
195
- constructor(private data: SubscriptionData) {}
196
-
197
- async save(): Promise<void> {
198
- await db.collection('subscriptions').doc(this.data.id).set(this.data);
199
- }
200
-
201
- async delete(): Promise<void> {
202
- await db.collection('subscriptions').doc(this.data.id).delete();
203
- }
204
-
205
- static async find(id: string): Promise<Subscription | null> {
206
- const doc = await db.collection('subscriptions').doc(id).get();
207
- if (!doc.exists) return null;
208
- return new Subscription(doc.data());
209
- }
210
- }
211
- ```
212
-
213
- ### 2. Data Mapper Pattern
214
-
215
- ```typescript
216
- class SubscriptionMapper {
217
- toEntity(doc: FirebaseFirestore.DocumentSnapshot): Subscription {
218
- const data = doc.data();
219
- return Subscription.create({
220
- id: doc.id,
221
- ...data,
222
- });
223
- }
224
-
225
- toData(entity: Subscription): Record<string, any> {
226
- return {
227
- type: entity.type,
228
- isActive: entity.isActive,
229
- isPremium: entity.isPremium,
230
- expirationDate: entity.expirationDate,
231
- willRenew: entity.willRenew,
232
- };
233
- }
234
- }
235
- ```
236
-
237
- ### 3. Repository with Caching
238
-
239
- ```typescript
240
- class CachedSubscriptionRepository {
241
- private cache = new Map<string, { data: SubscriptionStatus; expiry: number }>();
242
- private ttl = 5 * 60 * 1000; // 5 minutes
243
-
244
- constructor(private repository: ISubscriptionRepository) {}
245
-
246
- async getSubscriptionStatus(userId: string): Promise<SubscriptionStatus | null> {
247
- // Check cache
248
- const cached = this.cache.get(userId);
249
- if (cached && cached.expiry > Date.now()) {
250
- return cached.data;
251
- }
252
-
253
- // Fetch from source
254
- const status = await this.repository.getSubscriptionStatus(userId);
255
-
256
- // Update cache
257
- if (status) {
258
- this.cache.set(userId, {
259
- data: status,
260
- expiry: Date.now() + this.ttl,
261
- });
262
- }
263
-
264
- return status;
265
- }
266
-
267
- invalidate(userId: string): void {
268
- this.cache.delete(userId);
269
- }
270
-
271
- invalidateAll(): void {
272
- this.cache.clear();
273
- }
274
- }
275
- ```
276
-
277
- ## Transaction Support
278
-
279
- ### Firestore Transactions
280
-
281
- ```typescript
282
- class TransactionalCreditsRepository {
283
- async transferCredits(
284
- fromUserId: string,
285
- toUserId: string,
286
- amount: number
287
- ): Promise<void> {
288
- await db.runTransaction(async (transaction) => {
289
- const fromRef = db.collection('credits').doc(fromUserId);
290
- const toRef = db.collection('credits').doc(toUserId);
291
-
292
- const fromDoc = await transaction.get(fromRef);
293
- const toDoc = await transaction.get(toRef);
294
-
295
- const fromBalance = fromDoc.data()?.balance || 0;
296
- const toBalance = toDoc.data()?.balance || 0;
297
-
298
- if (fromBalance < amount) {
299
- throw new InsufficientCreditsError('Insufficient credits');
300
- }
301
-
302
- transaction.update(fromRef, { balance: fromBalance - amount });
303
- transaction.update(toRef, { balance: toBalance + amount });
304
- });
305
- }
306
- }
307
- ```
308
-
309
- ## Real-Time Updates
310
-
311
- ### Firestore Realtime Listener
312
-
313
- ```typescript
314
- class RealtimeSubscriptionRepository {
315
- subscribeToStatus(
316
- userId: string,
317
- callback: (status: SubscriptionStatus) => void
318
- ): () => void {
319
- const unsubscribe = db
320
- .collection('subscriptions')
321
- .doc(userId)
322
- .onSnapshot((doc) => {
323
- if (doc.exists) {
324
- callback(doc.data() as SubscriptionStatus);
325
- }
326
- });
327
-
328
- return unsubscribe;
329
- }
330
- }
331
- ```
332
-
333
- ## Testing Repositories
334
-
335
- ### Mock Repository Factory
336
-
337
- ```typescript
338
- function createMockRepository(options?: {
339
- initialData?: Map<string, SubscriptionStatus>;
340
- latency?: number;
341
- }): ISubscriptionRepository {
342
- const data = options?.initialData || new Map();
343
- const latency = options?.latency || 0;
344
-
345
- return {
346
- async getSubscriptionStatus(userId: string) {
347
- if (latency > 0) {
348
- await sleep(latency);
349
- }
350
- return data.get(userId) || null;
351
- },
352
-
353
- async saveSubscriptionStatus(userId: string, status: SubscriptionStatus) {
354
- if (latency > 0) {
355
- await sleep(latency);
356
- }
357
- data.set(userId, status);
358
- },
359
-
360
- async deleteSubscriptionStatus(userId: string) {
361
- data.delete(userId);
362
- },
363
-
364
- isSubscriptionValid(status: SubscriptionStatus) {
365
- return status.isActive && !isExpired(status.expirationDate);
366
- },
367
- };
368
- }
369
- ```
370
-
371
- ## Best Practices
372
-
373
- 1. **Interface Segregation** - Keep interfaces focused
374
- 2. **Error Handling** - Transform storage errors to domain errors
375
- 3. **Logging** - Log repository operations
376
- 4. **Validation** - Validate data before saving
377
- 5. **Performance** - Use caching and batching
378
- 6. **Testing** - Mock repositories for unit tests
379
- 7. **Transactions** - Use transactions for multi-document updates
380
-
381
- ## Related
382
-
383
- - [Infrastructure Layer](../../README.md)
384
- - [Infrastructure Services](../services/README.md)
385
- - [Application Ports](../../application/ports/README.md)
66
+ - **Error Transformation**: Transform storage errors appropriately
67
+ - **Data Integrity**: Maintain data integrity
68
+ - **Performance**: Optimize with caching and batching
69
+ - **Testing**: Support mock implementations
70
+
71
+ ## AI Agent Guidelines
72
+
73
+ ### When Modifying Repositories
74
+
75
+ 1. **Interface Compliance**: Maintain interface contracts
76
+ 2. **Error Handling**: Transform errors appropriately
77
+ 3. **Validation**: Validate all data
78
+ 4. **Logging**: Log operations for debugging
79
+
80
+ ### When Creating Custom Repositories
81
+
82
+ 1. **Interface Implementation**: Implement required interfaces
83
+ 2. **Error Transformation**: Transform storage errors
84
+ 3. **Validation**: Add data validation
85
+ 4. **Testing**: Create mock implementations
86
+
87
+ ### When Fixing Repository Bugs
88
+
89
+ 1. **Data Access**: Check data access logic
90
+ 2. **Error Handling**: Verify error transformation
91
+ 3. **Validation**: Check validation rules
92
+ 4. **Edge Cases**: Test with null/undefined values
93
+
94
+ ## Related Documentation
95
+
96
+ - [Infrastructure Services](/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-subscription/src/infrastructure/services/README.md)
97
+ - [Infrastructure Layer](/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-subscription/src/infrastructure/README.md)
98
+ - [Application Ports](/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-subscription/src/application/ports/README.md)
99
+ - [Domain Layer](/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-subscription/src/domain/README.md)
@@ -1,4 +1,4 @@
1
- import { timezoneService } from "@umituz/react-native-timezone";
1
+ import { timezoneService } from "@umituz/react-native-design-system";
2
2
  import type { ISubscriptionRepository } from "../../application/ports/ISubscriptionRepository";
3
3
  import type { SubscriptionStatus } from "../../domain/entities/SubscriptionStatus";
4
4
  import { SubscriptionRepositoryError } from "../../domain/errors/SubscriptionError";