@umituz/react-native-subscription 2.37.31 → 2.37.33
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 +1 -1
- package/src/domains/revenuecat/infrastructure/services/userSwitchHandler.ts +1 -1
- package/src/domains/subscription/application/SubscriptionAuthListener.ts +3 -4
- package/src/domains/subscription/infrastructure/hooks/usePurchasePackage.ts +3 -2
- package/src/domains/subscription/infrastructure/hooks/useRestorePurchase.ts +2 -7
- package/src/domains/subscription/infrastructure/managers/SubscriptionManager.ts +13 -5
- package/src/domains/subscription/infrastructure/managers/managerOperations.ts +3 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.37.
|
|
3
|
+
"version": "2.37.33",
|
|
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",
|
|
@@ -29,7 +29,7 @@ async function fetchOfferingsSafe(): Promise<any> {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function normalizeUserId(userId: string): string | null {
|
|
32
|
-
return (userId && userId.length > 0) ? userId : null;
|
|
32
|
+
return (userId && userId.length > 0 && userId !== "__anonymous__") ? userId : null;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function isAnonymousId(userId: string): boolean {
|
|
@@ -17,9 +17,8 @@ export const getCurrentUserId = (getAuth: () => FirebaseAuthLike | null): string
|
|
|
17
17
|
|
|
18
18
|
if (user.isAnonymous) {
|
|
19
19
|
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
20
|
-
console.log(
|
|
20
|
+
console.log(`[SubscriptionAuthListener] Anonymous user - using Firebase anonymous UID: ${user.uid}`);
|
|
21
21
|
}
|
|
22
|
-
return undefined;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
return user.uid;
|
|
@@ -40,13 +39,13 @@ export const setupAuthStateListener = (
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
return auth.onAuthStateChanged((user) => {
|
|
43
|
-
const userId =
|
|
42
|
+
const userId = user ? user.uid : undefined;
|
|
44
43
|
|
|
45
44
|
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
46
45
|
console.log('[SubscriptionAuthListener] 🔔 Auth state changed:', {
|
|
47
46
|
hasUser: !!user,
|
|
48
47
|
isAnonymous: user?.isAnonymous,
|
|
49
|
-
userId: userId || '(undefined -
|
|
48
|
+
userId: userId || '(undefined - no user)',
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
|
|
@@ -48,10 +48,11 @@ export const usePurchasePackage = () => {
|
|
|
48
48
|
|
|
49
49
|
const productId = pkg.product.identifier;
|
|
50
50
|
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
51
|
-
console.log(
|
|
51
|
+
console.log(`[Purchase] Initializing and purchasing. User: ${userId}`);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
await SubscriptionManager.initialize(userId);
|
|
55
|
+
const success = await SubscriptionManager.purchasePackage(pkg, userId);
|
|
55
56
|
|
|
56
57
|
return { success, productId };
|
|
57
58
|
},
|
|
@@ -10,7 +10,6 @@ import { useAlert } from "@umituz/react-native-design-system";
|
|
|
10
10
|
import {
|
|
11
11
|
useAuthStore,
|
|
12
12
|
selectUserId,
|
|
13
|
-
selectIsAnonymous,
|
|
14
13
|
} from "@umituz/react-native-auth";
|
|
15
14
|
import { SubscriptionManager } from "../../infrastructure/managers/SubscriptionManager";
|
|
16
15
|
import { SUBSCRIPTION_QUERY_KEYS } from "./subscriptionQueryKeys";
|
|
@@ -30,7 +29,6 @@ interface RestoreResult {
|
|
|
30
29
|
*/
|
|
31
30
|
export const useRestorePurchase = () => {
|
|
32
31
|
const userId = useAuthStore(selectUserId);
|
|
33
|
-
const isAnonymous = useAuthStore(selectIsAnonymous);
|
|
34
32
|
const queryClient = useQueryClient();
|
|
35
33
|
const { showSuccess, showInfo, showError } = useAlert();
|
|
36
34
|
|
|
@@ -40,11 +38,8 @@ export const useRestorePurchase = () => {
|
|
|
40
38
|
throw new Error("User not authenticated");
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const result = await SubscriptionManager.restore();
|
|
41
|
+
await SubscriptionManager.initialize(userId);
|
|
42
|
+
const result = await SubscriptionManager.restore(userId);
|
|
48
43
|
return result;
|
|
49
44
|
},
|
|
50
45
|
onSuccess: (result) => {
|
|
@@ -2,7 +2,7 @@ import type { PurchasesPackage } from "react-native-purchases";
|
|
|
2
2
|
import type { IRevenueCatService } from "../../../../shared/application/ports/IRevenueCatService";
|
|
3
3
|
import type { PackageHandler } from "../handlers/PackageHandler";
|
|
4
4
|
import { SubscriptionInternalState } from "./SubscriptionInternalState";
|
|
5
|
-
import { ensureServiceAvailable } from "./subscriptionManagerUtils";
|
|
5
|
+
import { ensureServiceAvailable, getCurrentUserIdOrThrow } from "./subscriptionManagerUtils";
|
|
6
6
|
import type { SubscriptionManagerConfig, PremiumStatus, RestoreResultInfo } from "./SubscriptionManager.types";
|
|
7
7
|
import { createPackageHandler } from "./packageHandlerFactory";
|
|
8
8
|
import { checkPremiumStatusFromService } from "./premiumStatusChecker";
|
|
@@ -100,17 +100,25 @@ class SubscriptionManagerImpl {
|
|
|
100
100
|
return getPackagesOperation(this.managerConfig, this.serviceInstance, this.packageHandler!);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
async purchasePackage(pkg: PurchasesPackage): Promise<boolean> {
|
|
103
|
+
async purchasePackage(pkg: PurchasesPackage, explicitUserId?: string): Promise<boolean> {
|
|
104
104
|
this.ensureConfigured();
|
|
105
|
+
if (explicitUserId) {
|
|
106
|
+
await this.initialize(explicitUserId);
|
|
107
|
+
}
|
|
105
108
|
this.ensurePackageHandlerInitialized();
|
|
106
|
-
const
|
|
109
|
+
const resolvedUserId = explicitUserId || getCurrentUserIdOrThrow(this.state);
|
|
110
|
+
const result = await purchasePackageOperation(pkg, this.managerConfig, resolvedUserId, this.packageHandler!);
|
|
107
111
|
return result;
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
async restore(): Promise<RestoreResultInfo> {
|
|
114
|
+
async restore(explicitUserId?: string): Promise<RestoreResultInfo> {
|
|
111
115
|
this.ensureConfigured();
|
|
116
|
+
if (explicitUserId) {
|
|
117
|
+
await this.initialize(explicitUserId);
|
|
118
|
+
}
|
|
112
119
|
this.ensurePackageHandlerInitialized();
|
|
113
|
-
|
|
120
|
+
const resolvedUserId = explicitUserId || getCurrentUserIdOrThrow(this.state);
|
|
121
|
+
return restoreOperation(this.managerConfig, resolvedUserId, this.packageHandler!);
|
|
114
122
|
}
|
|
115
123
|
|
|
116
124
|
async checkPremiumStatus(): Promise<PremiumStatus> {
|
|
@@ -2,8 +2,7 @@ import type { PurchasesPackage } from "react-native-purchases";
|
|
|
2
2
|
import type { IRevenueCatService } from "../../../../shared/application/ports/IRevenueCatService";
|
|
3
3
|
import type { PackageHandler } from "../handlers/PackageHandler";
|
|
4
4
|
import type { RestoreResultInfo } from "./SubscriptionManager.types";
|
|
5
|
-
import {
|
|
6
|
-
import { ensureConfigured, getCurrentUserIdOrThrow, getOrCreateService } from "./subscriptionManagerUtils";
|
|
5
|
+
import { ensureConfigured, getOrCreateService } from "./subscriptionManagerUtils";
|
|
7
6
|
import type { SubscriptionManagerConfig } from "./SubscriptionManager.types";
|
|
8
7
|
|
|
9
8
|
export const getPackagesOperation = async (
|
|
@@ -19,21 +18,19 @@ export const getPackagesOperation = async (
|
|
|
19
18
|
export const purchasePackageOperation = async (
|
|
20
19
|
pkg: PurchasesPackage,
|
|
21
20
|
managerConfig: SubscriptionManagerConfig | null,
|
|
22
|
-
|
|
21
|
+
userId: string,
|
|
23
22
|
packageHandler: PackageHandler
|
|
24
23
|
): Promise<boolean> => {
|
|
25
24
|
ensureConfigured(managerConfig);
|
|
26
|
-
const userId = getCurrentUserIdOrThrow(state);
|
|
27
25
|
const result = await packageHandler.purchase(pkg, userId);
|
|
28
26
|
return result;
|
|
29
27
|
};
|
|
30
28
|
|
|
31
29
|
export const restoreOperation = async (
|
|
32
30
|
managerConfig: SubscriptionManagerConfig | null,
|
|
33
|
-
|
|
31
|
+
userId: string,
|
|
34
32
|
packageHandler: PackageHandler
|
|
35
33
|
): Promise<RestoreResultInfo> => {
|
|
36
34
|
ensureConfigured(managerConfig);
|
|
37
|
-
const userId = getCurrentUserIdOrThrow(state);
|
|
38
35
|
return packageHandler.restore(userId);
|
|
39
36
|
};
|