@umituz/react-native-subscription 2.14.59 → 2.14.61

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.14.59",
3
+ "version": "2.14.61",
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",
@@ -20,6 +20,8 @@ export interface CreditsConfig {
20
20
  imageCreditLimit: number;
21
21
  /** When true, stores credits at users/{userId}/credits instead of {collectionName}/{userId} */
22
22
  useUserSubcollection?: boolean;
23
+ /** Credit amounts per product ID for consumable credit packages */
24
+ creditPackageAmounts?: Record<string, number>;
23
25
  }
24
26
 
25
27
  export interface CreditsResult<T = UserCredits> {
package/src/index.ts CHANGED
@@ -324,6 +324,7 @@ export {
324
324
 
325
325
  export {
326
326
  usePaywallVisibility,
327
+ paywallControl,
327
328
  type UsePaywallVisibilityResult,
328
329
  } from "./presentation/hooks/usePaywallVisibility";
329
330
 
@@ -25,6 +25,8 @@ import { initializeCreditsTransaction } from "../services/CreditsInitializer";
25
25
  import { detectPackageType } from "../../utils/packageTypeDetector";
26
26
  import { getCreditAllocation } from "../../utils/creditMapper";
27
27
 
28
+ declare const __DEV__: boolean;
29
+
28
30
  export class CreditsRepository extends BaseRepository {
29
31
  private config: CreditsConfig;
30
32
 
@@ -98,15 +100,31 @@ export class CreditsRepository extends BaseRepository {
98
100
  let configToUse = this.config;
99
101
 
100
102
  if (productId) {
101
- const packageType = detectPackageType(productId);
102
- const allocation = getCreditAllocation(packageType);
103
-
104
- if (allocation) {
103
+ // First check credit package amounts (for consumable credit packages)
104
+ const creditPackageAmount = this.config.creditPackageAmounts?.[productId];
105
+
106
+ if (creditPackageAmount) {
107
+ // Credit package: use the configured amount
108
+ if (__DEV__) {
109
+ console.log("[CreditsRepository] Credit package detected:", { productId, amount: creditPackageAmount });
110
+ }
105
111
  configToUse = {
106
112
  ...this.config,
107
- imageCreditLimit: allocation.imageCredits,
108
- textCreditLimit: allocation.textCredits,
113
+ imageCreditLimit: creditPackageAmount,
114
+ textCreditLimit: creditPackageAmount,
109
115
  };
116
+ } else {
117
+ // Subscription package: use package type detection
118
+ const packageType = detectPackageType(productId);
119
+ const allocation = getCreditAllocation(packageType);
120
+
121
+ if (allocation) {
122
+ configToUse = {
123
+ ...this.config,
124
+ imageCreditLimit: allocation.imageCredits,
125
+ textCreditLimit: allocation.textCredits,
126
+ };
127
+ }
110
128
  }
111
129
  }
112
130
 
@@ -99,7 +99,12 @@ export const initializeSubscription = async (
99
99
  throw new Error("RevenueCat API key is required");
100
100
  }
101
101
 
102
- configureCreditsRepository(credits);
102
+ // Merge credit package amounts into credits config
103
+ const creditsConfigWithPackages = {
104
+ ...credits,
105
+ creditPackageAmounts: creditPackages?.amounts,
106
+ };
107
+ configureCreditsRepository(creditsConfigWithPackages);
103
108
 
104
109
  // Build consumable product identifiers from credit package pattern
105
110
  const consumableIdentifiers: string[] = [];
@@ -23,6 +23,15 @@ const setPaywallVisible = (visible: boolean): void => {
23
23
  listeners.forEach((listener) => listener());
24
24
  };
25
25
 
26
+ /**
27
+ * Direct paywall control for non-React contexts (e.g., appInitializer)
28
+ */
29
+ export const paywallControl = {
30
+ open: () => setPaywallVisible(true),
31
+ close: () => setPaywallVisible(false),
32
+ isOpen: () => paywallVisible,
33
+ };
34
+
26
35
  export interface UsePaywallVisibilityResult {
27
36
  showPaywall: boolean;
28
37
  setShowPaywall: (visible: boolean) => void;