@umituz/react-native-subscription 2.14.96 → 2.14.98

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