@umituz/react-native-subscription 2.37.50 → 2.37.51
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.51",
|
|
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",
|
|
@@ -58,8 +58,9 @@ class SubscriptionManagerImpl {
|
|
|
58
58
|
// Mark pending so React components know to wait
|
|
59
59
|
initializationState.markPending();
|
|
60
60
|
|
|
61
|
+
const realUserId = actualUserId || null;
|
|
61
62
|
const promise = this.performInitialization(actualUserId);
|
|
62
|
-
this.state.initCache.setPromise(promise, cacheKey);
|
|
63
|
+
this.state.initCache.setPromise(promise, cacheKey, realUserId);
|
|
63
64
|
return promise;
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
export class InitializationCache {
|
|
2
2
|
private initPromise: Promise<boolean> | null = null;
|
|
3
|
-
private
|
|
4
|
-
private
|
|
3
|
+
private cacheKey: string | null = null;
|
|
4
|
+
private promiseCacheKey: string | null = null;
|
|
5
|
+
private resolvedUserId: string | null = null;
|
|
5
6
|
private promiseCompleted = true;
|
|
6
7
|
private pendingQueue: Map<string, Promise<boolean>> = new Map();
|
|
7
8
|
|
|
8
|
-
tryAcquireInitialization(
|
|
9
|
-
const queuedPromise = this.pendingQueue.get(
|
|
9
|
+
tryAcquireInitialization(cacheKey: string): { shouldInit: boolean; existingPromise: Promise<boolean> | null } {
|
|
10
|
+
const queuedPromise = this.pendingQueue.get(cacheKey);
|
|
10
11
|
if (queuedPromise) {
|
|
11
12
|
return { shouldInit: false, existingPromise: queuedPromise };
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
if (
|
|
15
16
|
this.initPromise &&
|
|
16
|
-
this.
|
|
17
|
+
this.cacheKey === cacheKey &&
|
|
17
18
|
this.promiseCompleted &&
|
|
18
|
-
this.
|
|
19
|
+
this.promiseCacheKey === cacheKey
|
|
19
20
|
) {
|
|
20
21
|
return { shouldInit: false, existingPromise: this.initPromise };
|
|
21
22
|
}
|
|
@@ -23,44 +24,47 @@ export class InitializationCache {
|
|
|
23
24
|
return { shouldInit: true, existingPromise: null };
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
setPromise(promise: Promise<boolean>,
|
|
27
|
-
this.
|
|
27
|
+
setPromise(promise: Promise<boolean>, cacheKey: string, realUserId: string | null): void {
|
|
28
|
+
this.promiseCacheKey = cacheKey;
|
|
28
29
|
this.promiseCompleted = false;
|
|
29
30
|
|
|
30
31
|
const chain: Promise<boolean> = promise
|
|
31
32
|
.then((result) => {
|
|
32
|
-
if (result && this.
|
|
33
|
-
this.
|
|
33
|
+
if (result && this.promiseCacheKey === cacheKey) {
|
|
34
|
+
this.cacheKey = cacheKey;
|
|
35
|
+
this.resolvedUserId = realUserId;
|
|
34
36
|
}
|
|
35
37
|
this.promiseCompleted = true;
|
|
36
38
|
return result;
|
|
37
39
|
})
|
|
38
40
|
.catch((error) => {
|
|
39
|
-
if (this.
|
|
41
|
+
if (this.promiseCacheKey === cacheKey) {
|
|
40
42
|
this.initPromise = null;
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
43
|
+
this.promiseCacheKey = null;
|
|
44
|
+
this.cacheKey = null;
|
|
45
|
+
this.resolvedUserId = null;
|
|
43
46
|
}
|
|
44
47
|
this.promiseCompleted = true;
|
|
45
|
-
console.error('[InitializationCache] Initialization failed', {
|
|
48
|
+
console.error('[InitializationCache] Initialization failed', { cacheKey, error });
|
|
46
49
|
return false;
|
|
47
50
|
})
|
|
48
51
|
.finally(() => {
|
|
49
|
-
this.pendingQueue.delete(
|
|
52
|
+
this.pendingQueue.delete(cacheKey);
|
|
50
53
|
});
|
|
51
54
|
|
|
52
55
|
this.initPromise = chain;
|
|
53
|
-
this.pendingQueue.set(
|
|
56
|
+
this.pendingQueue.set(cacheKey, chain);
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
getCurrentUserId(): string | null {
|
|
57
|
-
return this.
|
|
60
|
+
return this.resolvedUserId;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
reset(): void {
|
|
61
64
|
this.initPromise = null;
|
|
62
|
-
this.
|
|
63
|
-
this.
|
|
65
|
+
this.cacheKey = null;
|
|
66
|
+
this.promiseCacheKey = null;
|
|
67
|
+
this.resolvedUserId = null;
|
|
64
68
|
this.promiseCompleted = true;
|
|
65
69
|
this.pendingQueue.clear();
|
|
66
70
|
}
|