@umituz/react-native-subscription 2.27.107 → 2.27.109

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.27.107",
3
+ "version": "2.27.109",
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",
@@ -33,11 +33,30 @@ export async function initializeCreditsTransaction(
33
33
  const now = serverTimestamp();
34
34
  const existingData = creditsDoc.exists()
35
35
  ? creditsDoc.data() as UserCreditsDocumentRead
36
- : null;
37
-
38
- if (!existingData) {
39
- throw new Error("Credits document does not exist");
40
- }
36
+ : {
37
+ credits: 0,
38
+ creditLimit: 0,
39
+ isPremium: false,
40
+ status: "none",
41
+ processedPurchases: [],
42
+ purchaseHistory: [],
43
+ platform: Platform.OS as any,
44
+ lastUpdatedAt: now,
45
+ purchasedAt: now,
46
+ expirationDate: null,
47
+ lastPurchaseAt: null,
48
+ willRenew: false,
49
+ productId: null,
50
+ packageType: null,
51
+ originalTransactionId: null,
52
+ appVersion: null,
53
+ periodType: null,
54
+ isTrialing: false,
55
+ trialStartDate: null,
56
+ trialEndDate: null,
57
+ trialCredits: 0,
58
+ convertedFromTrial: false,
59
+ } as any;
41
60
 
42
61
  if (existingData.processedPurchases.includes(purchaseId)) {
43
62
  return {
@@ -6,7 +6,14 @@ import type { UserCreditsDocumentRead } from "./UserCreditsDocument";
6
6
  /** Maps Firestore document to domain entity with expiration validation */
7
7
  export class CreditsMapper {
8
8
  static toEntity(doc: UserCreditsDocumentRead): UserCredits {
9
- const expirationDate = doc.expirationDate ? doc.expirationDate.toDate() : null;
9
+ const safeDate = (ts: any): Date | null => {
10
+ if (!ts) return null;
11
+ if (typeof ts.toDate === "function") return ts.toDate();
12
+ if (ts instanceof Date) return ts;
13
+ return null;
14
+ };
15
+
16
+ const expirationDate = safeDate(doc.expirationDate);
10
17
  const periodType = doc.periodType;
11
18
 
12
19
  // Validate isPremium against expirationDate (real-time check)
@@ -18,10 +25,10 @@ export class CreditsMapper {
18
25
  status,
19
26
 
20
27
  // Dates
21
- purchasedAt: doc.purchasedAt.toDate(),
28
+ purchasedAt: safeDate(doc.purchasedAt) ?? new Date(),
22
29
  expirationDate,
23
- lastUpdatedAt: doc.lastUpdatedAt.toDate(),
24
- lastPurchaseAt: doc.lastPurchaseAt ? doc.lastPurchaseAt.toDate() : null,
30
+ lastUpdatedAt: safeDate(doc.lastUpdatedAt) ?? new Date(),
31
+ lastPurchaseAt: safeDate(doc.lastPurchaseAt),
25
32
 
26
33
  // RevenueCat details
27
34
  willRenew: doc.willRenew,
@@ -32,8 +39,8 @@ export class CreditsMapper {
32
39
  // Trial fields
33
40
  periodType,
34
41
  isTrialing: doc.isTrialing,
35
- trialStartDate: doc.trialStartDate ? doc.trialStartDate.toDate() : null,
36
- trialEndDate: doc.trialEndDate ? doc.trialEndDate.toDate() : null,
42
+ trialStartDate: safeDate(doc.trialStartDate),
43
+ trialEndDate: safeDate(doc.trialEndDate),
37
44
  trialCredits: doc.trialCredits,
38
45
  convertedFromTrial: doc.convertedFromTrial,
39
46
 
@@ -13,7 +13,7 @@ import type { RevenueCatData } from "../../subscription/core/RevenueCatData";
13
13
  import { DeductCreditsCommand } from "../application/DeductCreditsCommand";
14
14
  import { CreditLimitCalculator } from "../application/CreditLimitCalculator";
15
15
  import { PURCHASE_TYPE, type PurchaseType } from "../../subscription/core/SubscriptionConstants";
16
- import { updateDoc } from "firebase/firestore";
16
+ import { setDoc } from "firebase/firestore";
17
17
 
18
18
  export class CreditsRepository extends BaseRepository {
19
19
  private deductCommand: DeductCreditsCommand;
@@ -102,12 +102,12 @@ export class CreditsRepository extends BaseRepository {
102
102
  if (!db) throw new Error("Firestore instance is not available");
103
103
 
104
104
  const ref = this.getRef(db, userId);
105
- await updateDoc(ref, {
105
+ await setDoc(ref, {
106
106
  isPremium: false,
107
107
  status: "expired",
108
108
  willRenew: false,
109
109
  expirationDate: new Date().toISOString()
110
- });
110
+ }, { merge: true });
111
111
  }
112
112
  }
113
113