@umituz/react-native-subscription 2.37.87 → 2.37.89

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.87",
3
+ "version": "2.37.89",
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
- const doc = await getDoc(ref);
12
- if (!doc.exists()) {
13
- return;
14
- }
14
+ await runTransaction(async (tx: Transaction) => {
15
+ const doc = await tx.get(ref);
16
+ if (!doc.exists()) return;
15
17
 
16
- await setDoc(ref, {
17
- isPremium: false,
18
- status: SUBSCRIPTION_STATUS.EXPIRED,
19
- willRenew: false,
20
- lastUpdatedAt: serverTimestamp(),
21
- }, { merge: true });
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
- const doc = await getDoc(ref);
41
- if (!doc.exists()) {
42
- return;
43
- }
44
+ await runTransaction(async (tx: Transaction) => {
45
+ const doc = await tx.get(ref);
46
+ if (!doc.exists()) return;
44
47
 
45
- const isExpired = metadata.expirationDate ? isPast(metadata.expirationDate) : false;
46
- const status = resolveSubscriptionStatus({
47
- isPremium: metadata.isPremium,
48
- willRenew: metadata.willRenew,
49
- isExpired,
50
- periodType: metadata.periodType ?? undefined,
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
- const expirationTimestamp = metadata.expirationDate ? toTimestamp(metadata.expirationDate) : null;
54
- const canceledAtTimestamp = metadata.unsubscribeDetectedAt ? toTimestamp(metadata.unsubscribeDetectedAt) : null;
55
- const billingIssueTimestamp = metadata.billingIssueDetectedAt ? toTimestamp(metadata.billingIssueDetectedAt) : null;
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
- await setDoc(ref, {
58
- isPremium: metadata.isPremium,
59
- status,
60
- willRenew: metadata.willRenew,
61
- productId: metadata.productId,
62
- lastUpdatedAt: serverTimestamp(),
63
- ...(expirationTimestamp && { expirationDate: expirationTimestamp }),
64
- ...(canceledAtTimestamp && { canceledAt: canceledAtTimestamp }),
65
- ...(billingIssueTimestamp && { billingIssueDetectedAt: billingIssueTimestamp }),
66
- ...(metadata.store && { store: metadata.store }),
67
- ...(metadata.ownershipType && { ownershipType: metadata.ownershipType }),
68
- }, { merge: true });
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
  /**