@umituz/react-native-subscription 2.9.3 → 2.9.4
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.9.
|
|
3
|
+
"version": "2.9.4",
|
|
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",
|
|
@@ -46,12 +46,14 @@ export async function handlePurchase(
|
|
|
46
46
|
pkg: PurchasesPackage,
|
|
47
47
|
userId: string
|
|
48
48
|
): Promise<PurchaseResult> {
|
|
49
|
+
if (__DEV__) console.log("[RevenueCat] Purchase started. Product:", pkg.product.identifier, "User:", userId);
|
|
49
50
|
addPackageBreadcrumb("subscription", "Purchase started", {
|
|
50
51
|
productId: pkg.product.identifier,
|
|
51
52
|
userId,
|
|
52
53
|
});
|
|
53
54
|
|
|
54
55
|
if (!deps.isInitialized()) {
|
|
56
|
+
if (__DEV__) console.error("[RevenueCat] Purchase failed - Not initialized");
|
|
55
57
|
const error = new RevenueCatInitializationError();
|
|
56
58
|
trackPackageError(error, {
|
|
57
59
|
packageName: "subscription",
|
|
@@ -62,17 +64,16 @@ export async function handlePurchase(
|
|
|
62
64
|
throw error;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
67
|
const consumableIds = deps.config.consumableProductIdentifiers || [];
|
|
68
68
|
const isConsumable = isConsumableProduct(pkg, consumableIds);
|
|
69
|
+
if (__DEV__) console.log("[RevenueCat] Product type:", isConsumable ? "consumable" : "subscription");
|
|
69
70
|
|
|
70
71
|
try {
|
|
71
72
|
const purchaseResult = await Purchases.purchasePackage(pkg);
|
|
72
73
|
const customerInfo = purchaseResult.customerInfo;
|
|
73
74
|
|
|
74
|
-
// For consumable products (credits), purchase success is enough
|
|
75
75
|
if (isConsumable) {
|
|
76
|
+
if (__DEV__) console.log("[RevenueCat] Consumable purchase successful:", pkg.product.identifier);
|
|
76
77
|
return {
|
|
77
78
|
success: true,
|
|
78
79
|
isPremium: false,
|
|
@@ -82,11 +83,11 @@ export async function handlePurchase(
|
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
// For subscriptions, check premium entitlement
|
|
86
86
|
const entitlementIdentifier = deps.config.entitlementIdentifier;
|
|
87
87
|
const isPremium = !!customerInfo.entitlements.active[entitlementIdentifier];
|
|
88
88
|
|
|
89
89
|
if (isPremium) {
|
|
90
|
+
if (__DEV__) console.log("[RevenueCat] Subscription purchase successful. Premium active:", isPremium);
|
|
90
91
|
await syncPremiumStatus(deps.config, userId, customerInfo);
|
|
91
92
|
await notifyPurchaseCompleted(
|
|
92
93
|
deps.config,
|
|
@@ -97,6 +98,7 @@ export async function handlePurchase(
|
|
|
97
98
|
return { success: true, isPremium: true, customerInfo };
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
if (__DEV__) console.warn("[RevenueCat] Purchase completed but entitlement not active");
|
|
100
102
|
const entitlementError = new RevenueCatPurchaseError(
|
|
101
103
|
"Purchase completed but premium entitlement not active",
|
|
102
104
|
pkg.product.identifier
|
|
@@ -111,12 +113,14 @@ export async function handlePurchase(
|
|
|
111
113
|
throw entitlementError;
|
|
112
114
|
} catch (error) {
|
|
113
115
|
if (isUserCancelledError(error)) {
|
|
116
|
+
if (__DEV__) console.log("[RevenueCat] Purchase cancelled by user");
|
|
114
117
|
addPackageBreadcrumb("subscription", "Purchase cancelled by user", {
|
|
115
118
|
productId: pkg.product.identifier,
|
|
116
119
|
userId,
|
|
117
120
|
});
|
|
118
121
|
return { success: false, isPremium: false };
|
|
119
122
|
}
|
|
123
|
+
if (__DEV__) console.error("[RevenueCat] Purchase error:", error);
|
|
120
124
|
const errorMessage = getErrorMessage(error, "Purchase failed");
|
|
121
125
|
const purchaseError = new RevenueCatPurchaseError(errorMessage, pkg.product.identifier);
|
|
122
126
|
trackPackageError(purchaseError, {
|
|
@@ -33,9 +33,11 @@ export async function handleRestore(
|
|
|
33
33
|
deps: RestoreHandlerDeps,
|
|
34
34
|
userId: string
|
|
35
35
|
): Promise<RestoreResult> {
|
|
36
|
+
if (__DEV__) console.log("[RevenueCat] Restore started for user:", userId);
|
|
36
37
|
addPackageBreadcrumb("subscription", "Restore started", { userId });
|
|
37
38
|
|
|
38
39
|
if (!deps.isInitialized()) {
|
|
40
|
+
if (__DEV__) console.error("[RevenueCat] Restore failed - Not initialized");
|
|
39
41
|
const error = new RevenueCatInitializationError();
|
|
40
42
|
trackPackageError(error, {
|
|
41
43
|
packageName: "subscription",
|
|
@@ -51,12 +53,14 @@ export async function handleRestore(
|
|
|
51
53
|
const isPremium = !!customerInfo.entitlements.active[entitlementIdentifier];
|
|
52
54
|
|
|
53
55
|
if (isPremium) {
|
|
56
|
+
if (__DEV__) console.log("[RevenueCat] Restore successful - Premium active");
|
|
54
57
|
await syncPremiumStatus(deps.config, userId, customerInfo);
|
|
55
58
|
addPackageBreadcrumb("subscription", "Restore successful - premium active", {
|
|
56
59
|
userId,
|
|
57
60
|
entitlementId: entitlementIdentifier,
|
|
58
61
|
});
|
|
59
62
|
} else {
|
|
63
|
+
if (__DEV__) console.log("[RevenueCat] Restore completed - No premium found");
|
|
60
64
|
addPackageBreadcrumb("subscription", "Restore completed - no premium found", {
|
|
61
65
|
userId,
|
|
62
66
|
});
|
|
@@ -66,6 +70,7 @@ export async function handleRestore(
|
|
|
66
70
|
|
|
67
71
|
return { success: isPremium, isPremium, customerInfo };
|
|
68
72
|
} catch (error) {
|
|
73
|
+
if (__DEV__) console.error("[RevenueCat] Restore error:", error);
|
|
69
74
|
const errorMessage = getErrorMessage(error, "Restore failed");
|
|
70
75
|
const restoreError = new RevenueCatRestoreError(errorMessage);
|
|
71
76
|
trackPackageError(restoreError, {
|
|
@@ -53,12 +53,13 @@ export class RevenueCatService implements IRevenueCatService {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
async initialize(userId: string, apiKey?: string): Promise<InitializeResult> {
|
|
56
|
-
// If already initialized for this user, return success immediately
|
|
57
56
|
if (this.isInitialized() && this.getCurrentUserId() === userId) {
|
|
57
|
+
if (__DEV__) console.log("[RevenueCat] Already initialized for user:", userId);
|
|
58
58
|
addPackageBreadcrumb("subscription", "Already initialized", { userId });
|
|
59
59
|
return { success: true, offering: (await this.fetchOfferings()), hasPremium: false };
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
if (__DEV__) console.log("[RevenueCat] Initializing for user:", userId, "API Key:", apiKey ? "provided" : "from config");
|
|
62
63
|
addPackageBreadcrumb("subscription", "Initialization started", { userId });
|
|
63
64
|
|
|
64
65
|
try {
|
|
@@ -76,10 +77,12 @@ export class RevenueCatService implements IRevenueCatService {
|
|
|
76
77
|
);
|
|
77
78
|
|
|
78
79
|
if (result.success) {
|
|
80
|
+
if (__DEV__) console.log("[RevenueCat] Initialization successful. Offering:", result.offering?.identifier, "Packages:", result.offering?.availablePackages.length);
|
|
79
81
|
this.listenerManager.setUserId(userId);
|
|
80
82
|
this.listenerManager.setupListener(this.stateManager.getConfig());
|
|
81
83
|
addPackageBreadcrumb("subscription", "Initialization successful", { userId });
|
|
82
84
|
} else {
|
|
85
|
+
if (__DEV__) console.warn("[RevenueCat] Initialization failed for user:", userId);
|
|
83
86
|
trackPackageWarning("subscription", "Initialization failed", {
|
|
84
87
|
userId,
|
|
85
88
|
hasOffering: !!result.offering,
|
|
@@ -88,6 +91,7 @@ export class RevenueCatService implements IRevenueCatService {
|
|
|
88
91
|
|
|
89
92
|
return result;
|
|
90
93
|
} catch (error) {
|
|
94
|
+
if (__DEV__) console.error("[RevenueCat] Initialization error:", error);
|
|
91
95
|
trackPackageError(error instanceof Error ? error : new Error(String(error)), {
|
|
92
96
|
packageName: "subscription",
|
|
93
97
|
operation: "initialize",
|
|
@@ -131,8 +135,12 @@ export class RevenueCatService implements IRevenueCatService {
|
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
async reset(): Promise<void> {
|
|
134
|
-
if (!this.isInitialized())
|
|
138
|
+
if (!this.isInitialized()) {
|
|
139
|
+
if (__DEV__) console.log("[RevenueCat] Reset called but not initialized");
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
135
142
|
|
|
143
|
+
if (__DEV__) console.log("[RevenueCat] Resetting for user:", this.getCurrentUserId());
|
|
136
144
|
addPackageBreadcrumb("subscription", "Reset started", {
|
|
137
145
|
userId: this.getCurrentUserId(),
|
|
138
146
|
});
|
|
@@ -142,8 +150,10 @@ export class RevenueCatService implements IRevenueCatService {
|
|
|
142
150
|
try {
|
|
143
151
|
await Purchases.logOut();
|
|
144
152
|
this.stateManager.setInitialized(false);
|
|
153
|
+
if (__DEV__) console.log("[RevenueCat] Reset successful");
|
|
145
154
|
addPackageBreadcrumb("subscription", "Reset successful", {});
|
|
146
155
|
} catch (error) {
|
|
156
|
+
if (__DEV__) console.warn("[RevenueCat] Reset failed (non-critical):", error);
|
|
147
157
|
trackPackageWarning("subscription", "Reset failed (non-critical)", {
|
|
148
158
|
error: error instanceof Error ? error.message : String(error),
|
|
149
159
|
});
|