@umituz/react-native-subscription 1.10.0 → 1.10.1

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": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "Subscription management, paywall UI and credits system for React Native apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -26,12 +26,13 @@ interface FirestoreTimestamp {
26
26
  toDate: () => Date;
27
27
  }
28
28
 
29
- interface UserCreditsDocument {
29
+ // Document structure when READING from Firestore
30
+ interface UserCreditsDocumentRead {
30
31
  textCredits: number;
31
32
  imageCredits: number;
32
- purchasedAt: FirestoreTimestamp | FieldValue;
33
- lastUpdatedAt: FirestoreTimestamp | FieldValue;
34
- lastPurchaseAt?: FirestoreTimestamp | FieldValue;
33
+ purchasedAt?: FirestoreTimestamp;
34
+ lastUpdatedAt?: FirestoreTimestamp;
35
+ lastPurchaseAt?: FirestoreTimestamp;
35
36
  processedPurchases?: string[];
36
37
  }
37
38
 
@@ -60,7 +61,7 @@ export class CreditsRepository extends BaseRepository {
60
61
  return { success: true, data: undefined };
61
62
  }
62
63
 
63
- const data = snapshot.data() as UserCreditsDocument;
64
+ const data = snapshot.data() as UserCreditsDocumentRead;
64
65
  return {
65
66
  success: true,
66
67
  data: {
@@ -107,7 +108,7 @@ export class CreditsRepository extends BaseRepository {
107
108
  let processedPurchases: string[] = [];
108
109
 
109
110
  if (creditsDoc.exists()) {
110
- const existing = creditsDoc.data() as UserCreditsDocument;
111
+ const existing = creditsDoc.data() as UserCreditsDocumentRead;
111
112
  processedPurchases = existing.processedPurchases || [];
112
113
 
113
114
  if (purchaseId && processedPurchases.includes(purchaseId)) {
@@ -122,7 +123,10 @@ export class CreditsRepository extends BaseRepository {
122
123
  (existing.textCredits || 0) + this.config.textCreditLimit;
123
124
  newImageCredits =
124
125
  (existing.imageCredits || 0) + this.config.imageCreditLimit;
125
- purchasedAt = existing.purchasedAt || now;
126
+ // Keep existing purchasedAt if available, otherwise use server timestamp
127
+ if (existing.purchasedAt) {
128
+ purchasedAt = existing.purchasedAt as unknown as FieldValue;
129
+ }
126
130
  }
127
131
 
128
132
  if (purchaseId) {