@umituz/react-native-subscription 2.14.97 → 2.14.99

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 (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +461 -0
  3. package/package.json +1 -3
  4. package/src/application/README.md +229 -0
  5. package/src/application/ports/README.md +103 -0
  6. package/src/domain/README.md +402 -0
  7. package/src/domain/constants/README.md +80 -0
  8. package/src/domain/entities/README.md +176 -0
  9. package/src/domain/errors/README.md +307 -0
  10. package/src/domain/value-objects/README.md +186 -0
  11. package/src/domains/README.md +240 -0
  12. package/src/domains/config/README.md +390 -0
  13. package/src/domains/config/domain/README.md +390 -0
  14. package/src/domains/config/domain/entities/README.md +350 -0
  15. package/src/domains/paywall/README.md +371 -0
  16. package/src/domains/paywall/components/PaywallHeader.tsx +8 -11
  17. package/src/domains/paywall/components/README.md +185 -0
  18. package/src/domains/paywall/entities/README.md +199 -0
  19. package/src/domains/paywall/hooks/README.md +129 -0
  20. package/src/domains/wallet/README.md +292 -0
  21. package/src/domains/wallet/domain/README.md +108 -0
  22. package/src/domains/wallet/domain/entities/README.md +122 -0
  23. package/src/domains/wallet/domain/errors/README.md +157 -0
  24. package/src/domains/wallet/infrastructure/README.md +96 -0
  25. package/src/domains/wallet/presentation/components/BalanceCard.tsx +6 -12
  26. package/src/domains/wallet/presentation/components/README.md +231 -0
  27. package/src/domains/wallet/presentation/hooks/README.md +255 -0
  28. package/src/infrastructure/README.md +514 -0
  29. package/src/infrastructure/mappers/README.md +34 -0
  30. package/src/infrastructure/models/README.md +26 -0
  31. package/src/infrastructure/repositories/README.md +385 -0
  32. package/src/infrastructure/services/README.md +374 -0
  33. package/src/presentation/README.md +410 -0
  34. package/src/presentation/components/README.md +183 -0
  35. package/src/presentation/components/details/CreditRow.md +337 -0
  36. package/src/presentation/components/details/DetailRow.md +283 -0
  37. package/src/presentation/components/details/PremiumDetailsCard.md +266 -0
  38. package/src/presentation/components/details/PremiumStatusBadge.md +266 -0
  39. package/src/presentation/components/details/README.md +449 -0
  40. package/src/presentation/components/feedback/PaywallFeedbackModal.md +314 -0
  41. package/src/presentation/components/feedback/README.md +447 -0
  42. package/src/presentation/components/paywall/PaywallModal.md +444 -0
  43. package/src/presentation/components/paywall/README.md +190 -0
  44. package/src/presentation/components/sections/README.md +468 -0
  45. package/src/presentation/components/sections/SubscriptionSection.md +246 -0
  46. package/src/presentation/hooks/README.md +743 -0
  47. package/src/presentation/hooks/useAuthAwarePurchase.md +359 -0
  48. package/src/presentation/hooks/useAuthGate.md +403 -0
  49. package/src/presentation/hooks/useAuthSubscriptionSync.md +398 -0
  50. package/src/presentation/hooks/useCreditChecker.md +407 -0
  51. package/src/presentation/hooks/useCredits.md +342 -0
  52. package/src/presentation/hooks/useCreditsGate.md +346 -0
  53. package/src/presentation/hooks/useDeductCredit.md +176 -0
  54. package/src/presentation/hooks/useDevTestCallbacks.md +422 -0
  55. package/src/presentation/hooks/useFeatureGate.md +157 -0
  56. package/src/presentation/hooks/useInitializeCredits.md +458 -0
  57. package/src/presentation/hooks/usePaywall.md +334 -0
  58. package/src/presentation/hooks/usePaywallOperations.md +486 -0
  59. package/src/presentation/hooks/usePaywallVisibility.md +344 -0
  60. package/src/presentation/hooks/usePremium.md +230 -0
  61. package/src/presentation/hooks/usePremiumGate.md +423 -0
  62. package/src/presentation/hooks/usePremiumWithCredits.md +429 -0
  63. package/src/presentation/hooks/useSubscription.md +450 -0
  64. package/src/presentation/hooks/useSubscriptionDetails.md +438 -0
  65. package/src/presentation/hooks/useSubscriptionGate.md +168 -0
  66. package/src/presentation/hooks/useSubscriptionSettingsConfig.md +374 -0
  67. package/src/presentation/hooks/useSubscriptionStatus.md +424 -0
  68. package/src/presentation/hooks/useUserTier.md +356 -0
  69. package/src/presentation/hooks/useUserTierWithRepository.md +452 -0
  70. package/src/presentation/screens/README.md +194 -0
  71. package/src/presentation/types/README.md +38 -0
  72. package/src/presentation/utils/README.md +52 -0
  73. package/src/revenuecat/README.md +523 -0
  74. package/src/revenuecat/application/README.md +158 -0
  75. package/src/revenuecat/application/ports/README.md +169 -0
  76. package/src/revenuecat/domain/README.md +147 -0
  77. package/src/revenuecat/domain/constants/README.md +183 -0
  78. package/src/revenuecat/domain/entities/README.md +382 -0
  79. package/src/revenuecat/domain/errors/README.md +197 -0
  80. package/src/revenuecat/domain/types/README.md +373 -0
  81. package/src/revenuecat/domain/value-objects/README.md +441 -0
  82. package/src/revenuecat/infrastructure/README.md +50 -0
  83. package/src/revenuecat/infrastructure/config/README.md +40 -0
  84. package/src/revenuecat/infrastructure/handlers/README.md +218 -0
  85. package/src/revenuecat/infrastructure/managers/README.md +49 -0
  86. package/src/revenuecat/infrastructure/services/README.md +325 -0
  87. package/src/revenuecat/infrastructure/utils/README.md +382 -0
  88. package/src/revenuecat/presentation/README.md +184 -0
  89. package/src/revenuecat/presentation/hooks/README.md +56 -0
  90. package/src/utils/README.md +529 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ümit UZ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,461 @@
1
+ # @umituz/react-native-subscription
2
+
3
+ Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps.
4
+
5
+ ## Features
6
+
7
+ - 🚀 **RevenueCat Integration** - Full RevenueCat SDK integration with auto-initialization
8
+ - 💳 **Subscription Management** - Handle monthly, annual, and lifetime subscriptions
9
+ - 💰 **Credits System** - Built-in credits system with transaction tracking
10
+ - 🎨 **Paywall Components** - Beautiful, customizable paywall UI components
11
+ - 🔐 **Gate System** - Premium, auth, and credit gates for feature access control
12
+ - 🌍 **Multi-language Support** - Built-in i18n support
13
+ - 📊 **Analytics Ready** - Track subscription events and user behavior
14
+ - 🏗️ **DDD Architecture** - Domain-driven design with clean architecture
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @umituz/react-native-subscription
20
+ # or
21
+ yarn add @umituz/react-native-subscription
22
+ ```
23
+
24
+ ## Peer Dependencies
25
+
26
+ ```json
27
+ {
28
+ "@tanstack/react-query": ">=5.0.0",
29
+ "expo-constants": ">=16.0.0",
30
+ "expo-image": ">=2.0.0",
31
+ "firebase": ">=10.0.0",
32
+ "react": ">=18.2.0",
33
+ "react-native": ">=0.74.0",
34
+ "react-native-purchases": ">=7.0.0",
35
+ "react-native-safe-area-context": ">=5.0.0"
36
+ }
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ### 1. Initialize Subscription
42
+
43
+ ```typescript
44
+ import { initializeSubscription, SubscriptionProvider } from '@umituz/react-native-subscription';
45
+
46
+ // Wrap your app with provider
47
+ function App() {
48
+ return (
49
+ <SubscriptionProvider
50
+ config={{
51
+ revenueCatApiKey: 'your_api_key',
52
+ revenueCatEntitlementId: 'premium',
53
+ }}
54
+ >
55
+ <YourApp />
56
+ </SubscriptionProvider>
57
+ );
58
+ }
59
+
60
+ // Or initialize manually
61
+ await initializeSubscription({
62
+ revenueCatApiKey: process.env.REVENUECAT_API_KEY,
63
+ revenueCatEntitlementId: 'premium',
64
+ });
65
+ ```
66
+
67
+ ### 2. Check Subscription Status
68
+
69
+ ```typescript
70
+ import { usePremium } from '@umituz/react-native-subscription';
71
+
72
+ function PremiumFeature() {
73
+ const { isPremium, isLoading } = usePremium();
74
+
75
+ if (isLoading) return <ActivityIndicator />;
76
+
77
+ if (!isPremium) {
78
+ return <UpgradePrompt />;
79
+ }
80
+
81
+ return <PremiumContent />;
82
+ }
83
+ ```
84
+
85
+ ### 3. Show Paywall
86
+
87
+ ```typescript
88
+ import { PaywallModal } from '@umituz/react-native-subscription';
89
+
90
+ function MyComponent() {
91
+ const [isVisible, setIsVisible] = useState(false);
92
+
93
+ return (
94
+ <>
95
+ <Button onPress={() => setIsVisible(true)} title="Upgrade" />
96
+
97
+ <PaywallModal
98
+ isVisible={isVisible}
99
+ onClose={() => setIsVisible(false)}
100
+ config={{
101
+ title: 'Unlock Premium',
102
+ description: 'Get unlimited access',
103
+ features: [
104
+ { icon: 'star', text: 'Unlimited credits' },
105
+ { icon: 'zap', text: 'AI-powered tools' },
106
+ ],
107
+ }}
108
+ />
109
+ </>
110
+ );
111
+ }
112
+ ```
113
+
114
+ ### 4. Use Credits
115
+
116
+ ```typescript
117
+ import { useCreditsGate } from '@umituz/react-native-subscription';
118
+
119
+ function FeatureWithCredits() {
120
+ const { hasCredits, consumeCredit } = useCreditsGate({
121
+ creditCost: 5,
122
+ featureId: 'ai_generation',
123
+ });
124
+
125
+ const handleAction = async () => {
126
+ if (!hasCredits) {
127
+ showPaywall();
128
+ return;
129
+ }
130
+
131
+ const result = await consumeCredit();
132
+ if (result.success) {
133
+ await performAction();
134
+ }
135
+ };
136
+
137
+ return <Button onPress={handleAction} title="Use Feature (5 credits)" />;
138
+ }
139
+ ```
140
+
141
+ ## Documentation
142
+
143
+ ### Domain Architecture
144
+
145
+ The package follows Domain-Driven Design (DDD) principles:
146
+
147
+ - **[Wallet Domain](./src/domains/wallet/README.md)** - Credits, transactions, and wallet management
148
+ - **[Paywall Domain](./src/domains/paywall/README.md)** - Paywall components and flows
149
+ - **[Config Domain](./src/domains/config/README.md)** - Plan configuration and metadata
150
+
151
+ ### Layer Architecture
152
+
153
+ - **[Application Layer](./src/application/README.md)** - Service contracts and ports
154
+ - **[Domain Layer](./src/domain/README.md)** - Entities, value objects, and domain logic
155
+ - **[Infrastructure Layer](./src/infrastructure/README.md)** - Repository implementations
156
+ - **[Presentation Layer](./src/presentation/README.md)** - React hooks and UI components
157
+
158
+ ### Key Features
159
+
160
+ - **[RevenueCat Integration](./src/revenuecat/README.md)** - RevenueCat SDK wrapper
161
+ - **[Subscription Hooks](./src/presentation/hooks/README.md)** - React hooks for subscription management
162
+ - **[Premium Components](./src/presentation/components/details/README.md)** - Premium UI components
163
+ - **[Utils](./src/utils/README.md)** - Helper functions for subscriptions and credits
164
+
165
+ ## API Reference
166
+
167
+ ### Hooks
168
+
169
+ ```typescript
170
+ // Subscription
171
+ import {
172
+ useSubscription,
173
+ useSubscriptionStatus,
174
+ usePremium,
175
+ usePremiumGate,
176
+ } from '@umituz/react-native-subscription';
177
+
178
+ // Credits
179
+ import {
180
+ useCredits,
181
+ useCreditsGate,
182
+ useDeductCredit,
183
+ } from '@umituz/react-native-subscription';
184
+
185
+ // Paywall
186
+ import {
187
+ usePaywall,
188
+ usePaywallActions,
189
+ usePaywallVisibility,
190
+ } from '@umituz/react-native-subscription';
191
+
192
+ // User Tier
193
+ import {
194
+ useUserTier,
195
+ useAuthGate,
196
+ useFeatureGate,
197
+ } from '@umituz/react-native-subscription';
198
+ ```
199
+
200
+ ### Components
201
+
202
+ ```typescript
203
+ import {
204
+ // Premium components
205
+ PremiumDetailsCard,
206
+ PremiumStatusBadge,
207
+ DetailRow,
208
+ CreditRow,
209
+
210
+ // Paywall components
211
+ PaywallModal,
212
+ PaywallScreen,
213
+ SubscriptionSection,
214
+
215
+ // Feedback
216
+ PaywallFeedbackModal,
217
+ } from '@umituz/react-native-subscription';
218
+ ```
219
+
220
+ ### Services
221
+
222
+ ```typescript
223
+ import {
224
+ // Initialization
225
+ initializeSubscription,
226
+ SubscriptionService,
227
+
228
+ // Credits
229
+ configureCreditsRepository,
230
+ getCreditsRepository,
231
+
232
+ // RevenueCat
233
+ useRevenueCat,
234
+ useCustomerInfo,
235
+ useRestorePurchase,
236
+ } from '@umituz/react-native-subscription';
237
+ ```
238
+
239
+ ## Examples
240
+
241
+ ### Complete Premium Feature Example
242
+
243
+ ```typescript
244
+ import React from 'react';
245
+ import { View, Text, Button, ActivityIndicator } from 'react-native';
246
+ import {
247
+ usePremiumGate,
248
+ useCreditsGate,
249
+ useUserTier,
250
+ PaywallModal,
251
+ } from '@umituz/react-native-subscription';
252
+
253
+ function PremiumFeature() {
254
+ const { tier, isPremium } = useUserTier();
255
+ const { canAccess, showPaywall } = usePremiumGate({
256
+ featureId: 'ai_tools',
257
+ });
258
+
259
+ const { hasCredits, credits, consumeCredit } = useCreditsGate({
260
+ creditCost: 5,
261
+ featureId: 'ai_generation',
262
+ });
263
+
264
+ const handleGenerate = async () => {
265
+ if (!canAccess) {
266
+ showPaywall();
267
+ return;
268
+ }
269
+
270
+ if (isPremium) {
271
+ // Premium: unlimited access
272
+ await generateContent();
273
+ } else if (hasCredits) {
274
+ // Free: use credits
275
+ const result = await consumeCredit();
276
+ if (result.success) {
277
+ await generateContent();
278
+ }
279
+ } else {
280
+ // No access: show upgrade
281
+ showPaywall();
282
+ }
283
+ };
284
+
285
+ return (
286
+ <View>
287
+ <Text>Tier: {tier}</Text>
288
+ {!isPremium && <Text>Credits: {credits}</Text>}
289
+
290
+ <Button
291
+ onPress={handleGenerate}
292
+ title={
293
+ isPremium
294
+ ? 'Generate (Unlimited)'
295
+ : 'Generate (5 credits)'
296
+ }
297
+ />
298
+ </View>
299
+ );
300
+ }
301
+ ```
302
+
303
+ ### Complete Settings Screen Example
304
+
305
+ ```typescript
306
+ import React from 'react';
307
+ import { ScrollView, RefreshControl } from 'react-native';
308
+ import {
309
+ PremiumDetailsCard,
310
+ SubscriptionSection,
311
+ useSubscription,
312
+ } from '@umituz/react-native-subscription';
313
+
314
+ function SettingsScreen() {
315
+ const { subscription, isLoading, refetch } = useSubscription();
316
+ const [refreshing, setRefreshing] = React.useState(false);
317
+
318
+ const handleRefresh = async () => {
319
+ setRefreshing(true);
320
+ await refetch();
321
+ setRefreshing(false);
322
+ };
323
+
324
+ return (
325
+ <ScrollView
326
+ refreshControl={
327
+ <RefreshControl refreshing={refreshing} onRefresh={handleRefresh} />
328
+ }
329
+ >
330
+ <SubscriptionSection
331
+ subscription={subscription}
332
+ onPress={() => navigation.navigate('SubscriptionDetail')}
333
+ />
334
+
335
+ {subscription?.isPremium && (
336
+ <PremiumDetailsCard
337
+ status={subscription}
338
+ onManagePress={handleManageSubscription}
339
+ />
340
+ )}
341
+ </ScrollView>
342
+ );
343
+ }
344
+ ```
345
+
346
+ ## Configuration
347
+
348
+ ### Subscription Config
349
+
350
+ ```typescript
351
+ import type { SubscriptionConfig } from '@umituz/react-native-subscription';
352
+
353
+ const config: SubscriptionConfig = {
354
+ revenueCatApiKey: 'your_api_key',
355
+ revenueCatEntitlementId: 'premium',
356
+
357
+ plans: {
358
+ monthly: monthlyPlan,
359
+ annual: annualPlan,
360
+ lifetime: lifetimePlan,
361
+ },
362
+
363
+ defaultPlan: 'monthly',
364
+
365
+ features: {
366
+ requireAuth: true,
367
+ allowRestore: true,
368
+ syncWithFirebase: true,
369
+ },
370
+
371
+ ui: {
372
+ showAnnualDiscount: true,
373
+ highlightPopularPlan: true,
374
+ showPerks: true,
375
+ },
376
+ };
377
+ ```
378
+
379
+ ### Credits Config
380
+
381
+ ```typescript
382
+ import type { CreditsConfig } from '@umituz/react-native-subscription';
383
+
384
+ const creditsConfig: CreditsConfig = {
385
+ initialCredits: 100,
386
+
387
+ creditPackages: [
388
+ {
389
+ id: 'credits_small',
390
+ productId: 'com.app.credits.small',
391
+ amount: 100,
392
+ price: 0.99,
393
+ currency: 'USD',
394
+ },
395
+ {
396
+ id: 'credits_medium',
397
+ productId: 'com.app.credits.medium',
398
+ amount: 500,
399
+ price: 3.99,
400
+ currency: 'USD',
401
+ },
402
+ ],
403
+
404
+ creditCosts: {
405
+ ai_generation: 1,
406
+ ai_analysis: 2,
407
+ premium_feature: 5,
408
+ },
409
+ };
410
+ ```
411
+
412
+ ## Architecture
413
+
414
+ The package follows Clean Architecture and Domain-Driven Design principles:
415
+
416
+ ```
417
+ ┌─────────────────────────────────────────┐
418
+ │ Presentation Layer │
419
+ │ (React Hooks & Components) │
420
+ ├─────────────────────────────────────────┤
421
+ │ Application Layer │
422
+ │ (Use Cases & Service Contracts) │
423
+ ├─────────────────────────────────────────┤
424
+ │ Domain Layer │
425
+ │ (Entities & Business Logic) │
426
+ ├─────────────────────────────────────────┤
427
+ │ Infrastructure Layer │
428
+ │ (External Services & Repositories) │
429
+ └─────────────────────────────────────────┘
430
+ ```
431
+
432
+ ## Best Practices
433
+
434
+ 1. **Always check loading states** before rendering subscription-dependent UI
435
+ 2. **Use gate hooks** (`usePremiumGate`, `useCreditsGate`) for feature access control
436
+ 3. **Handle errors gracefully** and show user-friendly messages
437
+ 4. **Provide restore purchase** option for iOS and Android
438
+ 5. **Track subscription events** with analytics
439
+ 6. **Use translations** for multi-language support
440
+ 7. **Test different subscription states** (guest, free, premium, expired)
441
+
442
+ ## Contributing
443
+
444
+ Contributions are welcome! Please feel free to submit a Pull Request.
445
+
446
+ ## License
447
+
448
+ MIT License - see LICENSE file for details
449
+
450
+ ## Author
451
+
452
+ Ümit UZ <umit@umituz.com>
453
+
454
+ ## Links
455
+
456
+ - [GitHub](https://github.com/umituz/react-native-subscription)
457
+ - [NPM](https://www.npmjs.com/package/@umituz/react-native-subscription)
458
+
459
+ ## Support
460
+
461
+ For issues and questions, please use the [GitHub Issues](https://github.com/umituz/react-native-subscription/issues).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-subscription",
3
- "version": "2.14.97",
3
+ "version": "2.14.99",
4
4
  "description": "Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -40,7 +40,6 @@
40
40
  "@tanstack/react-query": ">=5.0.0",
41
41
  "expo-constants": ">=16.0.0",
42
42
  "expo-image": ">=2.0.0",
43
- "expo-linear-gradient": ">=14.0.0",
44
43
  "firebase": ">=10.0.0",
45
44
  "react": ">=18.2.0",
46
45
  "react-native": ">=0.74.0",
@@ -80,7 +79,6 @@
80
79
  "expo-file-system": "^19.0.21",
81
80
  "expo-haptics": "^15.0.8",
82
81
  "expo-image": "~3.0.0",
83
- "expo-linear-gradient": "~15.0.0",
84
82
  "expo-localization": "^17.0.8",
85
83
  "expo-sharing": "^14.0.8",
86
84
  "expo-web-browser": "^12.0.0",