@umituz/react-native-subscription 2.27.30 → 2.27.32
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/presentation/components/feedback/PaywallFeedbackModal.tsx +23 -29
- package/src/revenuecat/infrastructure/managers/SubscriptionManager.ts +5 -3
- package/src/revenuecat/infrastructure/services/RevenueCatInitializer.ts +19 -0
- package/src/revenuecat/infrastructure/utils/InitializationCache.ts +59 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.27.
|
|
3
|
+
"version": "2.27.32",
|
|
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",
|
|
@@ -60,7 +60,6 @@
|
|
|
60
60
|
"@umituz/react-native-auth": "^3.6.14",
|
|
61
61
|
"@umituz/react-native-design-system": "^2.9.35",
|
|
62
62
|
"@umituz/react-native-firebase": "*",
|
|
63
|
-
"@umituz/react-native-localization": "^3.6.0",
|
|
64
63
|
"eslint": "^9.39.2",
|
|
65
64
|
"eslint-plugin-react": "^7.37.5",
|
|
66
65
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
@@ -85,9 +84,7 @@
|
|
|
85
84
|
"expo-video": "~3.0.15",
|
|
86
85
|
"expo-web-browser": "~15.0.10",
|
|
87
86
|
"firebase": "^11.0.0",
|
|
88
|
-
"i18next": "^25.7.3",
|
|
89
87
|
"react": "19.1.0",
|
|
90
|
-
"react-i18next": "^16.5.1",
|
|
91
88
|
"react-native": "0.81.5",
|
|
92
89
|
"react-native-gesture-handler": "^2.30.0",
|
|
93
90
|
"react-native-purchases": "^7.0.0",
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Paywall Feedback Modal
|
|
3
|
-
* Collects user feedback when declining paywall
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
1
|
import React, { useMemo } from "react";
|
|
7
2
|
import { View, TouchableOpacity, TextInput } from "react-native";
|
|
8
|
-
import { AtomicText, BaseModal } from "@umituz/react-native-design-system";
|
|
9
|
-
import { useAppDesignTokens } from "@umituz/react-native-design-system";
|
|
10
|
-
import { useLocalization } from "@umituz/react-native-localization";
|
|
3
|
+
import { AtomicText, BaseModal, useAppDesignTokens } from "@umituz/react-native-design-system";
|
|
11
4
|
import { usePaywallFeedback } from "../../hooks/feedback/usePaywallFeedback";
|
|
12
5
|
import { createPaywallFeedbackStyles } from "./paywallFeedbackStyles";
|
|
13
6
|
|
|
@@ -19,26 +12,33 @@ const FEEDBACK_OPTION_IDS = [
|
|
|
19
12
|
"other",
|
|
20
13
|
] as const;
|
|
21
14
|
|
|
15
|
+
export interface PaywallFeedbackTranslations {
|
|
16
|
+
title: string;
|
|
17
|
+
subtitle: string;
|
|
18
|
+
submit: string;
|
|
19
|
+
otherPlaceholder: string;
|
|
20
|
+
reasons: {
|
|
21
|
+
too_expensive: string;
|
|
22
|
+
no_need: string;
|
|
23
|
+
trying_out: string;
|
|
24
|
+
technical_issues: string;
|
|
25
|
+
other: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
export interface PaywallFeedbackModalProps {
|
|
30
|
+
translations: PaywallFeedbackTranslations;
|
|
23
31
|
visible: boolean;
|
|
24
32
|
onClose: () => void;
|
|
25
33
|
onSubmit: (reason: string) => void;
|
|
26
|
-
title?: string;
|
|
27
|
-
subtitle?: string;
|
|
28
|
-
submitText?: string;
|
|
29
|
-
otherPlaceholder?: string;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
export const PaywallFeedbackModal: React.FC<PaywallFeedbackModalProps> = React.memo(({
|
|
37
|
+
translations,
|
|
33
38
|
visible,
|
|
34
39
|
onClose,
|
|
35
40
|
onSubmit,
|
|
36
|
-
title,
|
|
37
|
-
subtitle,
|
|
38
|
-
submitText,
|
|
39
|
-
otherPlaceholder,
|
|
40
41
|
}) => {
|
|
41
|
-
const { t } = useLocalization();
|
|
42
42
|
const tokens = useAppDesignTokens();
|
|
43
43
|
|
|
44
44
|
const {
|
|
@@ -47,7 +47,7 @@ export const PaywallFeedbackModal: React.FC<PaywallFeedbackModalProps> = React.m
|
|
|
47
47
|
setOtherText,
|
|
48
48
|
selectReason,
|
|
49
49
|
handleSubmit,
|
|
50
|
-
handleSkip,
|
|
50
|
+
handleSkip,
|
|
51
51
|
canSubmit,
|
|
52
52
|
} = usePaywallFeedback({ onSubmit, onClose });
|
|
53
53
|
|
|
@@ -56,18 +56,12 @@ export const PaywallFeedbackModal: React.FC<PaywallFeedbackModalProps> = React.m
|
|
|
56
56
|
[tokens, canSubmit],
|
|
57
57
|
);
|
|
58
58
|
|
|
59
|
-
const displayTitle = title || t("paywall.feedback.title");
|
|
60
|
-
const displaySubtitle = subtitle || t("paywall.feedback.subtitle");
|
|
61
|
-
const displaySubmitText = submitText || t("paywall.feedback.submit");
|
|
62
|
-
const displayOtherPlaceholder = otherPlaceholder || t("paywall.feedback.otherPlaceholder");
|
|
63
|
-
|
|
64
|
-
// BaseModal from design system handles animations, safe areas, keyboard avoiding, and overlay backdrop
|
|
65
59
|
return (
|
|
66
60
|
<BaseModal
|
|
67
61
|
visible={visible}
|
|
68
62
|
onClose={handleSkip}
|
|
69
|
-
title={
|
|
70
|
-
subtitle={
|
|
63
|
+
title={translations.title}
|
|
64
|
+
subtitle={translations.subtitle}
|
|
71
65
|
>
|
|
72
66
|
<View style={{ paddingHorizontal: tokens.spacing.md, paddingBottom: tokens.spacing.lg }}>
|
|
73
67
|
<View style={[styles.optionsContainer, { backgroundColor: 'transparent', padding: 0 }]}>
|
|
@@ -75,7 +69,7 @@ export const PaywallFeedbackModal: React.FC<PaywallFeedbackModalProps> = React.m
|
|
|
75
69
|
const isSelected = selectedReason === optionId;
|
|
76
70
|
const isOther = optionId === "other";
|
|
77
71
|
const showInput = isSelected && isOther;
|
|
78
|
-
const displayText =
|
|
72
|
+
const displayText = translations.reasons[optionId];
|
|
79
73
|
|
|
80
74
|
// Dynamic styles for the container
|
|
81
75
|
const containerStyle = {
|
|
@@ -135,7 +129,7 @@ export const PaywallFeedbackModal: React.FC<PaywallFeedbackModalProps> = React.m
|
|
|
135
129
|
padding: tokens.spacing.sm,
|
|
136
130
|
}
|
|
137
131
|
]}
|
|
138
|
-
placeholder={
|
|
132
|
+
placeholder={translations.otherPlaceholder}
|
|
139
133
|
placeholderTextColor={tokens.colors.textTertiary}
|
|
140
134
|
multiline
|
|
141
135
|
maxLength={200}
|
|
@@ -157,7 +151,7 @@ export const PaywallFeedbackModal: React.FC<PaywallFeedbackModalProps> = React.m
|
|
|
157
151
|
activeOpacity={0.8}
|
|
158
152
|
>
|
|
159
153
|
<AtomicText type="labelLarge" style={styles.submitText}>
|
|
160
|
-
{
|
|
154
|
+
{translations.submit}
|
|
161
155
|
</AtomicText>
|
|
162
156
|
</TouchableOpacity>
|
|
163
157
|
</View>
|
|
@@ -64,9 +64,11 @@ class SubscriptionManagerImpl {
|
|
|
64
64
|
|
|
65
65
|
const effectiveUserId = userId || (await this.userIdProvider.getOrCreateAnonymousUserId());
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
// Atomic check-and-acquire to prevent race conditions
|
|
68
|
+
const { shouldInit, existingPromise } = this.initCache.tryAcquireInitialization(effectiveUserId);
|
|
69
|
+
|
|
70
|
+
if (!shouldInit && existingPromise) {
|
|
71
|
+
return existingPromise;
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
const promise = this.performInitialization(effectiveUserId);
|
|
@@ -20,6 +20,8 @@ export interface InitializerDeps {
|
|
|
20
20
|
|
|
21
21
|
let isPurchasesConfigured = false;
|
|
22
22
|
let isLogHandlerConfigured = false;
|
|
23
|
+
// Mutex to prevent concurrent configuration
|
|
24
|
+
let configurationInProgress = false;
|
|
23
25
|
|
|
24
26
|
function configureLogHandler(): void {
|
|
25
27
|
if (isLogHandlerConfigured) return;
|
|
@@ -97,12 +99,26 @@ export async function initializeSDK(
|
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
// Case 3: First time configuration
|
|
102
|
+
// Check mutex to prevent double configuration
|
|
103
|
+
if (configurationInProgress) {
|
|
104
|
+
// Wait a bit and retry - another thread is configuring
|
|
105
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
106
|
+
// After waiting, isPurchasesConfigured should be true
|
|
107
|
+
if (isPurchasesConfigured) {
|
|
108
|
+
return initializeSDK(deps, userId, apiKey);
|
|
109
|
+
}
|
|
110
|
+
return { success: false, offering: null, hasPremium: false };
|
|
111
|
+
}
|
|
112
|
+
|
|
100
113
|
const key = apiKey || resolveApiKey(deps.config);
|
|
101
114
|
|
|
102
115
|
if (!key) {
|
|
103
116
|
return { success: false, offering: null, hasPremium: false };
|
|
104
117
|
}
|
|
105
118
|
|
|
119
|
+
// Acquire mutex
|
|
120
|
+
configurationInProgress = true;
|
|
121
|
+
|
|
106
122
|
try {
|
|
107
123
|
configureLogHandler();
|
|
108
124
|
|
|
@@ -123,5 +139,8 @@ export async function initializeSDK(
|
|
|
123
139
|
} catch (error) {
|
|
124
140
|
getErrorMessage(error, "RevenueCat init failed");
|
|
125
141
|
return { success: false, offering: null, hasPremium: false };
|
|
142
|
+
} finally {
|
|
143
|
+
// Release mutex
|
|
144
|
+
configurationInProgress = false;
|
|
126
145
|
}
|
|
127
146
|
}
|
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Initialization Cache
|
|
3
3
|
* Manages promise caching and user state for initialization
|
|
4
|
+
* Thread-safe: Uses mutex pattern to prevent race conditions
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
export class InitializationCache {
|
|
7
8
|
private initPromise: Promise<boolean> | null = null;
|
|
8
9
|
private currentUserId: string | null = null;
|
|
10
|
+
// Mutex to prevent race condition during initialization
|
|
11
|
+
private initializationInProgress = false;
|
|
12
|
+
// Track which userId the promise is for (separate from currentUserId which is set after completion)
|
|
13
|
+
private promiseUserId: string | null = null;
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Atomically check if reinitialization is needed AND reserve the slot
|
|
17
|
+
* Returns: { shouldInit: boolean, existingPromise: Promise | null }
|
|
18
|
+
*/
|
|
19
|
+
tryAcquireInitialization(userId: string): { shouldInit: boolean; existingPromise: Promise<boolean> | null } {
|
|
20
|
+
// If initialization is in progress for the same user, return existing promise
|
|
21
|
+
if (this.initializationInProgress && this.promiseUserId === userId && this.initPromise) {
|
|
22
|
+
return { shouldInit: false, existingPromise: this.initPromise };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// If already initialized for this user and promise resolved successfully, return it
|
|
26
|
+
if (this.initPromise && this.currentUserId === userId && !this.initializationInProgress) {
|
|
27
|
+
return { shouldInit: false, existingPromise: this.initPromise };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Different user or no initialization - need to reinitialize
|
|
31
|
+
// Atomically set the flag
|
|
32
|
+
this.initializationInProgress = true;
|
|
33
|
+
this.promiseUserId = userId;
|
|
34
|
+
|
|
35
|
+
return { shouldInit: true, existingPromise: null };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use tryAcquireInitialization instead for atomic operations
|
|
40
|
+
*/
|
|
10
41
|
shouldReinitialize(userId: string): boolean {
|
|
11
42
|
if (!this.initPromise) {
|
|
12
43
|
return true;
|
|
@@ -19,13 +50,38 @@ export class InitializationCache {
|
|
|
19
50
|
return false;
|
|
20
51
|
}
|
|
21
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use tryAcquireInitialization instead for atomic operations
|
|
55
|
+
*/
|
|
22
56
|
getExistingPromise(): Promise<boolean> | null {
|
|
23
57
|
return this.initPromise;
|
|
24
58
|
}
|
|
25
59
|
|
|
26
60
|
setPromise(promise: Promise<boolean>, userId: string): void {
|
|
27
61
|
this.initPromise = promise;
|
|
28
|
-
this.
|
|
62
|
+
this.promiseUserId = userId;
|
|
63
|
+
|
|
64
|
+
// Chain to mark completion and set currentUserId only on success
|
|
65
|
+
promise
|
|
66
|
+
.then((result) => {
|
|
67
|
+
if (result && this.promiseUserId === userId) {
|
|
68
|
+
this.currentUserId = userId;
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
})
|
|
72
|
+
.catch(() => {
|
|
73
|
+
// On failure, clear the promise so retry is possible
|
|
74
|
+
if (this.promiseUserId === userId) {
|
|
75
|
+
this.initPromise = null;
|
|
76
|
+
this.promiseUserId = null;
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
.finally(() => {
|
|
80
|
+
// Always release the mutex
|
|
81
|
+
if (this.promiseUserId === userId) {
|
|
82
|
+
this.initializationInProgress = false;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
29
85
|
}
|
|
30
86
|
|
|
31
87
|
getCurrentUserId(): string | null {
|
|
@@ -35,5 +91,7 @@ export class InitializationCache {
|
|
|
35
91
|
reset(): void {
|
|
36
92
|
this.initPromise = null;
|
|
37
93
|
this.currentUserId = null;
|
|
94
|
+
this.initializationInProgress = false;
|
|
95
|
+
this.promiseUserId = null;
|
|
38
96
|
}
|
|
39
97
|
}
|