@umituz/react-native-subscription 2.37.88 → 2.37.90
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.37.
|
|
3
|
+
"version": "2.37.90",
|
|
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",
|
|
@@ -1,24 +1,27 @@
|
|
|
1
|
+
import type { DocumentReference, Transaction } from "@umituz/react-native-firebase";
|
|
2
|
+
import { runTransaction, serverTimestamp } from "@umituz/react-native-firebase";
|
|
1
3
|
import { getDoc, setDoc } from "firebase/firestore";
|
|
2
|
-
import type { DocumentReference } from "@umituz/react-native-firebase";
|
|
3
|
-
import { serverTimestamp } from "@umituz/react-native-firebase";
|
|
4
4
|
import { SUBSCRIPTION_STATUS } from "../../../subscription/core/SubscriptionConstants";
|
|
5
5
|
import { resolveSubscriptionStatus } from "../../../subscription/core/SubscriptionStatus";
|
|
6
6
|
import { toTimestamp } from "../../../../shared/utils/dateConverter";
|
|
7
7
|
import { isPast } from "../../../../utils/dateUtils";
|
|
8
8
|
import { getAppVersion, validatePlatform } from "../../../../utils/appUtils";
|
|
9
9
|
|
|
10
|
+
// Fix: was getDoc+setDoc (non-atomic) — now uses runTransaction so concurrent
|
|
11
|
+
// initializeCreditsTransaction and deductCreditsOperation no longer see stale
|
|
12
|
+
// updateTime preconditions that produce failed-precondition errors.
|
|
10
13
|
export async function syncExpiredStatus(ref: DocumentReference): Promise<void> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
14
|
+
await runTransaction(async (tx: Transaction) => {
|
|
15
|
+
const doc = await tx.get(ref);
|
|
16
|
+
if (!doc.exists()) return;
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
tx.update(ref, {
|
|
19
|
+
isPremium: false,
|
|
20
|
+
status: SUBSCRIPTION_STATUS.EXPIRED,
|
|
21
|
+
willRenew: false,
|
|
22
|
+
lastUpdatedAt: serverTimestamp(),
|
|
23
|
+
});
|
|
24
|
+
});
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
export interface PremiumMetadata {
|
|
@@ -33,39 +36,40 @@ export interface PremiumMetadata {
|
|
|
33
36
|
ownershipType: string | null;
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
// Fix: was getDoc+setDoc (non-atomic) — now uses runTransaction.
|
|
36
40
|
export async function syncPremiumMetadata(
|
|
37
41
|
ref: DocumentReference,
|
|
38
42
|
metadata: PremiumMetadata
|
|
39
43
|
): Promise<void> {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
+
await runTransaction(async (tx: Transaction) => {
|
|
45
|
+
const doc = await tx.get(ref);
|
|
46
|
+
if (!doc.exists()) return;
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const isExpired = metadata.expirationDate ? isPast(metadata.expirationDate) : false;
|
|
49
|
+
const status = resolveSubscriptionStatus({
|
|
50
|
+
isPremium: metadata.isPremium,
|
|
51
|
+
willRenew: metadata.willRenew,
|
|
52
|
+
isExpired,
|
|
53
|
+
periodType: metadata.periodType ?? undefined,
|
|
54
|
+
});
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
const expirationTimestamp = metadata.expirationDate ? toTimestamp(metadata.expirationDate) : null;
|
|
57
|
+
const canceledAtTimestamp = metadata.unsubscribeDetectedAt ? toTimestamp(metadata.unsubscribeDetectedAt) : null;
|
|
58
|
+
const billingIssueTimestamp = metadata.billingIssueDetectedAt ? toTimestamp(metadata.billingIssueDetectedAt) : null;
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
tx.set(ref, {
|
|
61
|
+
isPremium: metadata.isPremium,
|
|
62
|
+
status,
|
|
63
|
+
willRenew: metadata.willRenew,
|
|
64
|
+
productId: metadata.productId,
|
|
65
|
+
lastUpdatedAt: serverTimestamp(),
|
|
66
|
+
...(expirationTimestamp && { expirationDate: expirationTimestamp }),
|
|
67
|
+
...(canceledAtTimestamp && { canceledAt: canceledAtTimestamp }),
|
|
68
|
+
...(billingIssueTimestamp && { billingIssueDetectedAt: billingIssueTimestamp }),
|
|
69
|
+
...(metadata.store && { store: metadata.store }),
|
|
70
|
+
...(metadata.ownershipType && { ownershipType: metadata.ownershipType }),
|
|
71
|
+
}, { merge: true });
|
|
72
|
+
});
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/**
|
|
@@ -199,8 +199,11 @@ export async function handleInitialConfiguration(
|
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
// Sync premium status via callback (if configured)
|
|
203
|
-
|
|
202
|
+
// Sync premium status via callback (if configured).
|
|
203
|
+
// Only when we have a real Firebase UID — skip for pre-auth anonymous state
|
|
204
|
+
// to avoid writing to Firestore with a RevenueCat-generated ID that doesn't
|
|
205
|
+
// match request.auth.uid.
|
|
206
|
+
if (deps.config.onPremiumStatusChanged && normalizedUserId) {
|
|
204
207
|
try {
|
|
205
208
|
const premiumEntitlement = getPremiumEntitlement(
|
|
206
209
|
customerInfo,
|
|
@@ -209,7 +212,7 @@ export async function handleInitialConfiguration(
|
|
|
209
212
|
|
|
210
213
|
if (premiumEntitlement) {
|
|
211
214
|
await deps.config.onPremiumStatusChanged(
|
|
212
|
-
|
|
215
|
+
normalizedUserId,
|
|
213
216
|
true,
|
|
214
217
|
premiumEntitlement.productIdentifier,
|
|
215
218
|
premiumEntitlement.expirationDate ?? undefined,
|
|
@@ -218,7 +221,7 @@ export async function handleInitialConfiguration(
|
|
|
218
221
|
);
|
|
219
222
|
} else {
|
|
220
223
|
await deps.config.onPremiumStatusChanged(
|
|
221
|
-
|
|
224
|
+
normalizedUserId,
|
|
222
225
|
false,
|
|
223
226
|
undefined,
|
|
224
227
|
undefined,
|