@umituz/react-native-subscription 3.1.7 → 3.1.9
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 -4
- package/src/domains/credits/application/CreditsInitializer.ts +3 -2
- package/src/domains/credits/application/DeductCreditsCommand.ts +4 -3
- package/src/domains/credits/application/PurchaseMetadataGenerator.ts +1 -1
- package/src/domains/credits/application/RefundCreditsCommand.ts +4 -3
- package/src/domains/credits/application/creditDocumentHelpers.ts +2 -1
- package/src/domains/credits/infrastructure/CreditsRepository.ts +4 -3
- package/src/domains/credits/infrastructure/operations/CreditsFetcher.ts +1 -2
- package/src/domains/credits/infrastructure/operations/CreditsInitializer.ts +2 -1
- package/src/domains/credits/infrastructure/operations/CreditsWriter.ts +6 -5
- package/src/domains/credits/presentation/useCreditsRealTime.ts +4 -4
- package/src/shared/infrastructure/firestore/collectionUtils.ts +2 -7
- package/src/shared/utils/dateConverter.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.9",
|
|
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",
|
|
@@ -61,9 +61,6 @@
|
|
|
61
61
|
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
62
62
|
"@react-native-community/datetimepicker": "^8.6.0",
|
|
63
63
|
"@react-native-community/slider": "^4.5.2",
|
|
64
|
-
"@react-navigation/bottom-tabs": "^7.9.0",
|
|
65
|
-
"@react-navigation/native": "^7.1.26",
|
|
66
|
-
"@react-navigation/stack": "^7.6.13",
|
|
67
64
|
"@tanstack/query-async-storage-persister": "^5.66.7",
|
|
68
65
|
"@tanstack/react-query": "^5.0.0",
|
|
69
66
|
"@tanstack/react-query-persist-client": "^5.66.7",
|
|
@@ -2,7 +2,8 @@ import type { CreditsConfig } from "../core/Credits";
|
|
|
2
2
|
import { getAppVersion, validatePlatform } from "../../../utils/appUtils";
|
|
3
3
|
|
|
4
4
|
import type { InitializeCreditsMetadata, InitializationResult } from "../../subscription/application/SubscriptionInitializerTypes";
|
|
5
|
-
import { runTransaction, type
|
|
5
|
+
import { runTransaction, type DocumentReference } from "firebase/firestore";
|
|
6
|
+
import type { Firestore } from "@umituz/react-native-firebase";
|
|
6
7
|
import { getCreditDocumentOrDefault } from "./creditDocumentHelpers";
|
|
7
8
|
import { calculateNewCredits, buildCreditsData } from "./creditOperationUtils";
|
|
8
9
|
import { CreditLimitService } from "../domain/services/CreditLimitService";
|
|
@@ -39,7 +40,7 @@ export async function initializeCreditsTransaction(
|
|
|
39
40
|
const platform = validatePlatform();
|
|
40
41
|
const appVersion = getAppVersion();
|
|
41
42
|
|
|
42
|
-
return runTransaction(async (transaction
|
|
43
|
+
return runTransaction(_db, async (transaction) => {
|
|
43
44
|
const creditsDoc = await transaction.get(creditsRef);
|
|
44
45
|
|
|
45
46
|
const existingData = getCreditDocumentOrDefault(creditsDoc, platform);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { runTransaction, serverTimestamp, type
|
|
1
|
+
import { runTransaction, serverTimestamp, type DocumentReference } from "firebase/firestore";
|
|
2
|
+
import type { Firestore } from "@umituz/react-native-firebase";
|
|
2
3
|
import type { DeductCreditsResult } from "../core/Credits";
|
|
3
4
|
import { CREDIT_ERROR_CODES, MAX_SINGLE_DEDUCTION } from "../core/CreditsConstants";
|
|
4
5
|
|
|
@@ -33,7 +34,7 @@ export async function deductCreditsOperation(
|
|
|
33
34
|
try {
|
|
34
35
|
if (__DEV__) console.log('[DeductCreditsCommand] >>> starting transaction', { userId, cost, creditsRefPath: creditsRef.path });
|
|
35
36
|
|
|
36
|
-
const remaining = await runTransaction(async (tx
|
|
37
|
+
const remaining = await runTransaction(_db, async (tx) => {
|
|
37
38
|
const docSnap = await tx.get(creditsRef);
|
|
38
39
|
|
|
39
40
|
if (__DEV__) console.log('[DeductCreditsCommand] doc exists:', docSnap.exists());
|
|
@@ -66,7 +67,7 @@ export async function deductCreditsOperation(
|
|
|
66
67
|
|
|
67
68
|
return {
|
|
68
69
|
success: true,
|
|
69
|
-
remainingCredits: remaining,
|
|
70
|
+
remainingCredits: remaining as number,
|
|
70
71
|
error: null
|
|
71
72
|
};
|
|
72
73
|
} catch (e: unknown) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { runTransaction, serverTimestamp, type
|
|
1
|
+
import { runTransaction, serverTimestamp, type DocumentReference } from "firebase/firestore";
|
|
2
|
+
import type { Firestore } from "@umituz/react-native-firebase";
|
|
2
3
|
import type { DeductCreditsResult } from "../core/Credits";
|
|
3
4
|
import { CREDIT_ERROR_CODES } from "../core/CreditsConstants";
|
|
4
5
|
|
|
@@ -31,7 +32,7 @@ export async function refundCreditsOperation(
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
try {
|
|
34
|
-
const remaining = await runTransaction(async (tx
|
|
35
|
+
const remaining = await runTransaction(_db, async (tx) => {
|
|
35
36
|
const docSnap = await tx.get(creditsRef);
|
|
36
37
|
|
|
37
38
|
if (!docSnap.exists()) {
|
|
@@ -54,7 +55,7 @@ export async function refundCreditsOperation(
|
|
|
54
55
|
|
|
55
56
|
return {
|
|
56
57
|
success: true,
|
|
57
|
-
remainingCredits: remaining,
|
|
58
|
+
remainingCredits: remaining as number,
|
|
58
59
|
error: null
|
|
59
60
|
};
|
|
60
61
|
} catch (e: unknown) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { UserCreditsDocumentRead, FirestoreTimestamp } from "../core/UserCreditsDocument";
|
|
2
|
-
import { serverTimestamp
|
|
2
|
+
import { serverTimestamp } from "firebase/firestore";
|
|
3
|
+
import type { DocumentSnapshot } from "firebase/firestore";
|
|
3
4
|
import { SUBSCRIPTION_STATUS, type Platform } from "../../subscription/core/SubscriptionConstants";
|
|
4
5
|
|
|
5
6
|
export function getCreditDocumentOrDefault(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DocumentReference } from "firebase/firestore";
|
|
2
|
+
import type { Firestore } from "@umituz/react-native-firebase";
|
|
2
3
|
import { BaseRepository } from "@umituz/react-native-firebase";
|
|
3
4
|
import type { CreditsConfig, CreditsResult, DeductCreditsResult } from "../core/Credits";
|
|
4
5
|
import type { PurchaseSource } from "../core/UserCreditsDocument";
|
|
@@ -86,12 +87,12 @@ export class CreditsRepository extends BaseRepository {
|
|
|
86
87
|
|
|
87
88
|
async syncExpiredStatus(userId: string): Promise<void> {
|
|
88
89
|
const db = requireFirestore();
|
|
89
|
-
await syncExpiredStatus(this.getRef(db, userId));
|
|
90
|
+
await syncExpiredStatus(db, this.getRef(db, userId));
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
async syncPremiumMetadata(userId: string, metadata: SubscriptionMetadata): Promise<void> {
|
|
93
94
|
const db = requireFirestore();
|
|
94
|
-
await syncPremiumMetadata(this.getRef(db, userId), metadata);
|
|
95
|
+
await syncPremiumMetadata(db, this.getRef(db, userId), metadata);
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
async ensurePremiumCreditsExist(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { getDoc } from "firebase/firestore";
|
|
2
|
-
import type { DocumentReference } from "@umituz/react-native-firebase";
|
|
1
|
+
import { getDoc, type DocumentReference } from "firebase/firestore";
|
|
3
2
|
import type { CreditsResult } from "../../core/Credits";
|
|
4
3
|
import type { UserCreditsDocumentRead } from "../../core/UserCreditsDocument";
|
|
5
4
|
import { mapCreditsDocumentToEntity } from "../../core/CreditsMapper";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DocumentReference } from "firebase/firestore";
|
|
2
|
+
import type { Firestore } from "@umituz/react-native-firebase";
|
|
2
3
|
import type { CreditsConfig, CreditsResult } from "../../core/Credits";
|
|
3
4
|
import type { PurchaseSource } from "../../core/UserCreditsDocument";
|
|
4
5
|
import { initializeCreditsTransaction } from "../../application/CreditsInitializer";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { runTransaction, serverTimestamp, type DocumentReference } from "firebase/firestore";
|
|
2
|
+
import type { Firestore } from "@umituz/react-native-firebase";
|
|
3
3
|
import { getDoc, setDoc } from "firebase/firestore";
|
|
4
4
|
import { SUBSCRIPTION_STATUS } from "../../../subscription/core/SubscriptionConstants";
|
|
5
5
|
import { resolveSubscriptionStatus } from "../../../subscription/core/SubscriptionStatus";
|
|
@@ -11,8 +11,8 @@ import { getAppVersion, validatePlatform } from "../../../../utils/appUtils";
|
|
|
11
11
|
// Fix: was getDoc+setDoc (non-atomic) — now uses runTransaction so concurrent
|
|
12
12
|
// initializeCreditsTransaction and deductCreditsOperation no longer see stale
|
|
13
13
|
// updateTime preconditions that produce failed-precondition errors.
|
|
14
|
-
export async function syncExpiredStatus(ref: DocumentReference): Promise<void> {
|
|
15
|
-
await runTransaction(async (tx
|
|
14
|
+
export async function syncExpiredStatus(db: Firestore, ref: DocumentReference): Promise<void> {
|
|
15
|
+
await runTransaction(db, async (tx) => {
|
|
16
16
|
const doc = await tx.get(ref);
|
|
17
17
|
if (!doc.exists()) return;
|
|
18
18
|
|
|
@@ -27,10 +27,11 @@ export async function syncExpiredStatus(ref: DocumentReference): Promise<void> {
|
|
|
27
27
|
|
|
28
28
|
// Fix: was getDoc+setDoc (non-atomic) — now uses runTransaction.
|
|
29
29
|
export async function syncPremiumMetadata(
|
|
30
|
+
db: Firestore,
|
|
30
31
|
ref: DocumentReference,
|
|
31
32
|
metadata: SubscriptionMetadata
|
|
32
33
|
): Promise<void> {
|
|
33
|
-
await runTransaction(async (tx
|
|
34
|
+
await runTransaction(db, async (tx) => {
|
|
34
35
|
const doc = await tx.get(ref);
|
|
35
36
|
if (!doc.exists()) return;
|
|
36
37
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState, useCallback } from "react";
|
|
2
|
-
import { onSnapshot } from "firebase/firestore";
|
|
2
|
+
import { onSnapshot, type DocumentSnapshot } from "firebase/firestore";
|
|
3
3
|
import type { UserCredits } from "../core/Credits";
|
|
4
4
|
import { getCreditsConfig } from "../infrastructure/CreditsRepositoryManager";
|
|
5
5
|
import { mapCreditsDocumentToEntity } from "../core/CreditsMapper";
|
|
@@ -50,7 +50,7 @@ export function useCreditsRealTime(userId: string | null | undefined) {
|
|
|
50
50
|
// Real-time listener
|
|
51
51
|
const unsubscribe = onSnapshot(
|
|
52
52
|
docRef,
|
|
53
|
-
(snapshot) => {
|
|
53
|
+
(snapshot: DocumentSnapshot) => {
|
|
54
54
|
if (snapshot.exists()) {
|
|
55
55
|
const entity = mapCreditsDocumentToEntity(snapshot.data() as UserCreditsDocumentRead);
|
|
56
56
|
setCredits(entity);
|
|
@@ -59,9 +59,9 @@ export function useCreditsRealTime(userId: string | null | undefined) {
|
|
|
59
59
|
}
|
|
60
60
|
setIsLoading(false);
|
|
61
61
|
},
|
|
62
|
-
(err) => {
|
|
62
|
+
(err: Error) => {
|
|
63
63
|
console.error("[useCreditsRealTime] Snapshot error:", err);
|
|
64
|
-
setError(err
|
|
64
|
+
setError(err);
|
|
65
65
|
setIsLoading(false);
|
|
66
66
|
}
|
|
67
67
|
);
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { collection, doc } from "firebase/firestore";
|
|
2
|
-
import {
|
|
3
|
-
getFirestore,
|
|
4
|
-
type CollectionReference,
|
|
5
|
-
type DocumentReference,
|
|
6
|
-
type Firestore,
|
|
7
|
-
} from "@umituz/react-native-firebase";
|
|
1
|
+
import { collection, doc, type CollectionReference, type DocumentReference } from "firebase/firestore";
|
|
2
|
+
import { getFirestore, type Firestore } from "@umituz/react-native-firebase";
|
|
8
3
|
|
|
9
4
|
export interface CollectionConfig {
|
|
10
5
|
collectionName: string;
|