@sudobility/subscription_lib 0.0.7 → 0.0.8
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revenuecat-web.d.ts","sourceRoot":"","sources":["../../src/adapters/revenuecat-web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAKV,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"revenuecat-web.d.ts","sourceRoot":"","sources":["../../src/adapters/revenuecat-web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAKV,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAY1B;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAEzE;AA0BD;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CA6Cf;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAM1C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,mBAAmB,CAyM7D"}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
let purchasesInstance = null;
|
|
9
9
|
let currentUserId = null;
|
|
10
10
|
let apiKey = null;
|
|
11
|
+
let pendingUserSetup = null; // Track in-flight user setup
|
|
11
12
|
/**
|
|
12
13
|
* Configure the RevenueCat adapter with API key.
|
|
13
14
|
* Call this before initializing subscription_lib.
|
|
@@ -45,30 +46,40 @@ export async function setRevenueCatUser(userId, email) {
|
|
|
45
46
|
console.warn('[subscription] RevenueCat not configured');
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
|
-
// Skip if same user
|
|
49
|
+
// Skip if same user already set up
|
|
49
50
|
if (currentUserId === userId && purchasesInstance) {
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (purchasesInstance) {
|
|
56
|
-
purchasesInstance.close();
|
|
53
|
+
// Skip if already setting up this user (prevent concurrent calls)
|
|
54
|
+
if (pendingUserSetup === userId) {
|
|
55
|
+
return;
|
|
57
56
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (email) {
|
|
65
|
-
try {
|
|
66
|
-
await purchasesInstance.setAttributes({ email });
|
|
57
|
+
pendingUserSetup = userId;
|
|
58
|
+
try {
|
|
59
|
+
const SDK = await import('@revenuecat/purchases-js');
|
|
60
|
+
// Close existing instance
|
|
61
|
+
if (purchasesInstance) {
|
|
62
|
+
purchasesInstance.close();
|
|
67
63
|
}
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
// Configure new instance with user
|
|
65
|
+
purchasesInstance = SDK.Purchases.configure({
|
|
66
|
+
apiKey,
|
|
67
|
+
appUserId: userId,
|
|
68
|
+
});
|
|
69
|
+
currentUserId = userId;
|
|
70
|
+
// Set email attribute
|
|
71
|
+
if (email) {
|
|
72
|
+
try {
|
|
73
|
+
await purchasesInstance.setAttributes({ email });
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Ignore attribute errors
|
|
77
|
+
}
|
|
70
78
|
}
|
|
71
79
|
}
|
|
80
|
+
finally {
|
|
81
|
+
pendingUserSetup = null;
|
|
82
|
+
}
|
|
72
83
|
}
|
|
73
84
|
/**
|
|
74
85
|
* Clear the current user (on logout).
|