@umituz/react-native-subscription 2.27.14 → 2.27.16

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-subscription",
3
- "version": "2.27.14",
3
+ "version": "2.27.16",
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",
@@ -4,6 +4,14 @@
4
4
  * Public API for wallet functionality.
5
5
  */
6
6
 
7
+ // Config
8
+ export {
9
+ configureWallet,
10
+ getWalletConfig,
11
+ resetWalletConfig,
12
+ type WalletConfiguration,
13
+ } from "./infrastructure/config/walletConfig";
14
+
7
15
  // Types
8
16
  export type {
9
17
  TransactionReason,
@@ -114,3 +122,8 @@ export {
114
122
  type WalletScreenConfig,
115
123
  type WalletScreenTranslations,
116
124
  } from "./presentation/screens/WalletScreen";
125
+
126
+ export {
127
+ WalletScreenContainer,
128
+ type WalletScreenContainerProps,
129
+ } from "./presentation/screens/WalletScreenContainer";
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Wallet Configuration
3
+ *
4
+ * Global configuration for wallet feature.
5
+ * Set once at app init, used by WalletScreen automatically.
6
+ */
7
+
8
+ import type { WalletScreenTranslations } from "../../presentation/screens/WalletScreen";
9
+
10
+ export interface WalletConfiguration {
11
+ translations: WalletScreenTranslations;
12
+ transactionCollection: string;
13
+ useUserSubcollection: boolean;
14
+ transactionLimit: number;
15
+ balanceIconName: string;
16
+ }
17
+
18
+ const DEFAULT_CONFIG: WalletConfiguration = {
19
+ translations: {
20
+ screenTitle: "Wallet",
21
+ balanceLabel: "Your Balance",
22
+ availableCredits: "Available Credits",
23
+ title: "Transaction History",
24
+ empty: "No transactions yet",
25
+ loading: "Loading...",
26
+ purchase: "Purchase",
27
+ usage: "Usage",
28
+ refund: "Refund",
29
+ bonus: "Bonus",
30
+ subscription: "Subscription",
31
+ admin: "Admin",
32
+ reward: "Reward",
33
+ expired: "Expired",
34
+ },
35
+ transactionCollection: "credit_logs",
36
+ useUserSubcollection: true,
37
+ transactionLimit: 50,
38
+ balanceIconName: "wallet",
39
+ };
40
+
41
+ let walletConfig: WalletConfiguration = { ...DEFAULT_CONFIG };
42
+
43
+ /**
44
+ * Configure wallet settings globally
45
+ * Call this once during app initialization
46
+ */
47
+ export function configureWallet(config: Partial<WalletConfiguration>): void {
48
+ walletConfig = {
49
+ ...DEFAULT_CONFIG,
50
+ ...config,
51
+ translations: {
52
+ ...DEFAULT_CONFIG.translations,
53
+ ...config.translations,
54
+ },
55
+ };
56
+ }
57
+
58
+ /**
59
+ * Get current wallet configuration
60
+ */
61
+ export function getWalletConfig(): WalletConfiguration {
62
+ return walletConfig;
63
+ }
64
+
65
+ /**
66
+ * Reset wallet configuration to defaults
67
+ */
68
+ export function resetWalletConfig(): void {
69
+ walletConfig = { ...DEFAULT_CONFIG };
70
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Wallet Screen Container
3
+ *
4
+ * Self-contained wallet screen.
5
+ * Uses global config from configureWallet() - no props needed!
6
+ *
7
+ * Usage:
8
+ * 1. Call configureWallet() during app init
9
+ * 2. Use WalletScreenContainer directly in navigation
10
+ *
11
+ * ```tsx
12
+ * // In init
13
+ * configureWallet({ translations: myTranslations });
14
+ *
15
+ * // In navigation
16
+ * <Stack.Screen name="Wallet" component={WalletScreenContainer} />
17
+ * ```
18
+ */
19
+
20
+ import React, { useMemo } from "react";
21
+ import { useNavigation } from "@react-navigation/native";
22
+ import { WalletScreen, type WalletScreenTranslations } from "./WalletScreen";
23
+ import { useWallet } from "../hooks/useWallet";
24
+ import { getWalletConfig } from "../../infrastructure/config/walletConfig";
25
+
26
+ export interface WalletScreenContainerProps {
27
+ /** Translations (overrides global config) */
28
+ translations?: WalletScreenTranslations;
29
+ /** Override onBack handler (default: navigation.goBack) */
30
+ onBack?: () => void;
31
+ /** Custom date formatter */
32
+ dateFormatter?: (timestamp: number) => string;
33
+ /** Footer component */
34
+ footer?: React.ReactNode;
35
+ }
36
+
37
+ export const WalletScreenContainer: React.FC<WalletScreenContainerProps> = ({
38
+ translations,
39
+ onBack,
40
+ dateFormatter,
41
+ footer,
42
+ }) => {
43
+ const navigation = useNavigation();
44
+ const config = getWalletConfig();
45
+
46
+ const {
47
+ balance,
48
+ balanceLoading,
49
+ transactions,
50
+ transactionsLoading,
51
+ } = useWallet({
52
+ transactionConfig: {
53
+ collectionName: config.transactionCollection,
54
+ useUserSubcollection: config.useUserSubcollection,
55
+ },
56
+ transactionLimit: config.transactionLimit,
57
+ });
58
+
59
+ const screenConfig = useMemo(
60
+ () => ({
61
+ balance,
62
+ balanceLoading,
63
+ transactions,
64
+ transactionsLoading,
65
+ translations: translations ?? config.translations,
66
+ onBack: onBack ?? (() => navigation.goBack()),
67
+ dateFormatter,
68
+ balanceIconName: config.balanceIconName,
69
+ footer,
70
+ }),
71
+ [
72
+ balance,
73
+ balanceLoading,
74
+ transactions,
75
+ transactionsLoading,
76
+ translations,
77
+ config,
78
+ onBack,
79
+ navigation,
80
+ dateFormatter,
81
+ footer,
82
+ ],
83
+ );
84
+
85
+ return <WalletScreen config={screenConfig} />;
86
+ };
87
+
88
+ export default WalletScreenContainer;
@@ -5,8 +5,6 @@
5
5
 
6
6
  import type { PurchasesPackage } from "react-native-purchases";
7
7
 
8
- declare const __DEV__: boolean;
9
-
10
8
  export type PackageCategory = "credits" | "subscription";
11
9
 
12
10
  export interface PackageFilterConfig {
@@ -30,17 +28,7 @@ export function getPackageCategory(
30
28
  config.creditIdentifierPattern?.test(identifier) ||
31
29
  config.creditIdentifierPattern?.test(productIdentifier);
32
30
 
33
- if (isCreditPackage) {
34
- if (__DEV__) {
35
- console.log("[PackageFilter] Credit package:", identifier);
36
- }
37
- return "credits";
38
- }
39
-
40
- if (__DEV__) {
41
- console.log("[PackageFilter] Subscription package:", identifier);
42
- }
43
- return "subscription";
31
+ return isCreditPackage ? "credits" : "subscription";
44
32
  }
45
33
 
46
34
  export function filterPackagesByMode(
@@ -49,22 +37,10 @@ export function filterPackagesByMode(
49
37
  config: PackageFilterConfig = DEFAULT_CONFIG
50
38
  ): PurchasesPackage[] {
51
39
  if (mode === "hybrid") {
52
- if (__DEV__) {
53
- console.log("[PackageFilter] Hybrid mode - returning all packages:", packages.length);
54
- }
55
40
  return packages;
56
41
  }
57
42
 
58
- const filtered = packages.filter((pkg) => {
59
- const category = getPackageCategory(pkg, config);
60
- return category === mode;
61
- });
62
-
63
- if (__DEV__) {
64
- console.log(`[PackageFilter] Mode: ${mode}, Filtered: ${filtered.length}/${packages.length}`);
65
- }
66
-
67
- return filtered;
43
+ return packages.filter((pkg) => getPackageCategory(pkg, config) === mode);
68
44
  }
69
45
 
70
46
  export function separatePackages(
@@ -75,20 +51,12 @@ export function separatePackages(
75
51
  const subscriptionPackages: PurchasesPackage[] = [];
76
52
 
77
53
  for (const pkg of packages) {
78
- const category = getPackageCategory(pkg, config);
79
- if (category === "credits") {
54
+ if (getPackageCategory(pkg, config) === "credits") {
80
55
  creditPackages.push(pkg);
81
56
  } else {
82
57
  subscriptionPackages.push(pkg);
83
58
  }
84
59
  }
85
60
 
86
- if (__DEV__) {
87
- console.log("[PackageFilter] Separated:", {
88
- credits: creditPackages.length,
89
- subscriptions: subscriptionPackages.length,
90
- });
91
- }
92
-
93
61
  return { creditPackages, subscriptionPackages };
94
62
  }
@@ -5,6 +5,14 @@
5
5
 
6
6
  export type SubscriptionPackageType = "weekly" | "monthly" | "yearly" | "unknown";
7
7
 
8
+ /**
9
+ * Check if identifier is a credit package (consumable purchase)
10
+ * Credit packages use a different system and don't need type detection
11
+ */
12
+ function isCreditPackage(identifier: string): boolean {
13
+ return identifier.includes("credit");
14
+ }
15
+
8
16
  /**
9
17
  * Detect package type from product identifier
10
18
  * Supports common RevenueCat naming patterns:
@@ -12,19 +20,19 @@ export type SubscriptionPackageType = "weekly" | "monthly" | "yearly" | "unknown
12
20
  * - premium_monthly, monthly_premium, premium-monthly
13
21
  * - premium_yearly, yearly_premium, premium-yearly, premium_annual, annual_premium
14
22
  * - preview-product-id (Preview API mode in Expo Go)
23
+ *
24
+ * Note: Credit packages (consumable purchases) are skipped silently
15
25
  */
16
26
  export function detectPackageType(productIdentifier: string): SubscriptionPackageType {
17
27
  if (!productIdentifier) {
18
- if (__DEV__) {
19
- console.log("[PackageTypeDetector] No product identifier provided");
20
- }
21
28
  return "unknown";
22
29
  }
23
30
 
24
31
  const normalized = productIdentifier.toLowerCase();
25
32
 
26
- if (__DEV__) {
27
- console.log("[PackageTypeDetector] Detecting package type for:", normalized);
33
+ // Skip credit packages silently - they use creditPackageConfig instead
34
+ if (isCreditPackage(normalized)) {
35
+ return "unknown";
28
36
  }
29
37
 
30
38
  // Preview API mode (Expo Go testing)