@umituz/react-native-subscription 2.37.13 → 2.37.15
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 -1
- package/src/domains/credits/application/PurchaseMetadataGenerator.ts +1 -1
- package/src/domains/credits/application/credit-strategies/CreditAllocationOrchestrator.ts +1 -1
- package/src/domains/credits/application/creditDocumentHelpers.ts +0 -14
- package/src/domains/credits/presentation/deduct-credit/index.ts +0 -1
- package/src/domains/credits/presentation/useCredits.ts +1 -6
- package/src/domains/credits/utils/creditValidation.ts +3 -3
- package/src/domains/paywall/components/PaywallFeatures.tsx +1 -1
- package/src/domains/paywall/hooks/usePaywallActions.ts +1 -1
- package/src/domains/revenuecat/core/errors/RevenueCatError.ts +1 -14
- package/src/domains/revenuecat/core/errors/RevenueCatErrorHandler.ts +1 -1
- package/src/domains/revenuecat/core/types/RevenueCatTypes.ts +3 -3
- package/src/domains/revenuecat/infrastructure/services/ConfigurationStateManager.ts +8 -2
- package/src/domains/revenuecat/infrastructure/services/RevenueCatInitializer.ts +0 -2
- package/src/domains/subscription/application/initializer/BackgroundInitializer.ts +45 -16
- package/src/domains/subscription/application/initializer/index.ts +1 -1
- package/src/domains/subscription/core/SubscriptionStatus.ts +4 -10
- package/src/domains/subscription/core/SubscriptionStatusHandlers.ts +1 -1
- package/src/domains/subscription/infrastructure/handlers/PackageHandler.ts +0 -2
- package/src/domains/subscription/infrastructure/hooks/usePurchasePackage.ts +1 -1
- package/src/domains/subscription/infrastructure/hooks/useRevenueCatTrialEligibility.ts +1 -2
- package/src/domains/subscription/infrastructure/hooks/useSubscriptionQueries.ts +0 -4
- package/src/domains/subscription/infrastructure/services/OfferingsFetcher.ts +50 -22
- package/src/domains/subscription/infrastructure/services/RestoreHandler.ts +1 -1
- package/src/domains/subscription/infrastructure/services/RevenueCatService.ts +1 -2
- package/src/domains/subscription/infrastructure/services/revenueCatServiceInstance.ts +0 -4
- package/src/domains/subscription/infrastructure/utils/renewal/index.ts +1 -1
- package/src/domains/subscription/presentation/components/details/CreditRow.tsx +1 -1
- package/src/domains/subscription/presentation/components/details/DetailRow.tsx +1 -1
- package/src/domains/subscription/presentation/components/feedback/FeedbackOption.tsx +0 -2
- package/src/domains/subscription/presentation/components/feedback/FeedbackTextInput.tsx +1 -1
- package/src/domains/subscription/presentation/featureGateRefs.ts +1 -1
- package/src/domains/subscription/presentation/screens/components/CreditsList.tsx +2 -2
- package/src/domains/subscription/presentation/screens/components/SubscriptionHeader.tsx +0 -2
- package/src/domains/subscription/presentation/stores/index.ts +0 -5
- package/src/domains/subscription/presentation/stores/purchaseLoadingStore.ts +3 -7
- package/src/domains/subscription/presentation/useAuthAwarePurchase.ts +2 -8
- package/src/domains/subscription/presentation/useFeatureGate.ts +0 -2
- package/src/domains/subscription/presentation/usePaywallVisibility.ts +1 -1
- package/src/domains/subscription/utils/authGuards.ts +0 -23
- package/src/domains/subscription/utils/syncStatus.ts +1 -1
- package/src/domains/wallet/index.ts +0 -112
- package/src/domains/wallet/infrastructure/config/walletConfig.ts +1 -23
- package/src/domains/wallet/infrastructure/repositories/transaction/CollectionBuilder.ts +1 -1
- package/src/domains/wallet/infrastructure/repositories/transaction/index.ts +0 -9
- package/src/domains/wallet/presentation/components/BalanceCard.tsx +1 -1
- package/src/domains/wallet/presentation/components/TransactionItem.tsx +0 -2
- package/src/domains/wallet/presentation/components/TransactionList.tsx +3 -2
- package/src/domains/wallet/presentation/hooks/useTransactionHistory.ts +2 -2
- package/src/domains/wallet/presentation/hooks/useWallet.ts +2 -2
- package/src/shared/application/FeedbackService.ts +2 -2
- package/src/shared/infrastructure/SubscriptionEventBus.ts +1 -1
- package/src/shared/infrastructure/firestore/collectionUtils.ts +0 -7
- package/src/shared/infrastructure/firestore/resultUtils.ts +3 -39
- package/src/shared/presentation/layouts/ScreenLayout.tsx +1 -1
- package/src/shared/utils/numberUtils.core.ts +0 -27
- package/src/shared/utils/numberUtils.ts +1 -9
- package/src/shared/utils/validators.ts +0 -58
- package/src/domains/config/domain/entities/Plan.ts +0 -44
- package/src/domains/config/domain/index.ts +0 -2
- package/src/domains/config/domain/value-objects/Config.ts +0 -49
- package/src/domains/config/index.ts +0 -6
- package/src/domains/config/utils/planSelectors.ts +0 -56
- package/src/domains/paywall/components/FeatureItem.tsx +0 -50
- package/src/domains/paywall/components/FeatureList.tsx +0 -34
- package/src/domains/paywall/components/PaywallHeader.tsx +0 -112
- package/src/domains/paywall/hooks/usePaywallTranslations.ts +0 -78
- package/src/domains/paywall/hooks/useSubscriptionModal.ts +0 -45
- package/src/domains/paywall/index.ts +0 -13
- package/src/domains/revenuecat/core/constants/RevenueCatConstants.ts +0 -201
- package/src/domains/revenuecat/core/constants/index.ts +0 -5
- package/src/domains/revenuecat/core/customerInfoHelpers.ts +0 -21
- package/src/domains/revenuecat/core/index.ts +0 -7
- package/src/domains/revenuecat/index.ts +0 -7
- package/src/domains/revenuecat/infrastructure/index.ts +0 -5
- package/src/domains/revenuecat/infrastructure/services/index.ts +0 -7
- package/src/domains/subscription/infrastructure/hooks/customer-info/index.ts +0 -2
- package/src/domains/subscription/infrastructure/hooks/customer-info/types.ts +0 -9
- package/src/domains/subscription/infrastructure/hooks/customer-info/useCustomerInfo.ts +0 -52
- package/src/domains/subscription/infrastructure/hooks/useInitializeSubscription.ts +0 -30
- package/src/domains/subscription/infrastructure/hooks/usePaywallFlow.ts +0 -78
- package/src/domains/subscription/infrastructure/hooks/useRevenueCat.ts +0 -119
- package/src/domains/subscription/presentation/components/feedback/FeedbackConstants.ts +0 -6
- package/src/domains/subscription/presentation/screens/components/SubscriptionActions.tsx +0 -56
- package/src/domains/subscription/utils/dateFormatters.ts +0 -28
- package/src/domains/wallet/domain/entities/CreditCost.ts +0 -45
- package/src/domains/wallet/domain/entities/README.md +0 -41
- package/src/domains/wallet/domain/errors/README.md +0 -40
- package/src/domains/wallet/domain/errors/WalletError.ts +0 -17
- package/src/domains/wallet/domain/errors/WalletError.types.ts +0 -30
- package/src/domains/wallet/domain/errors/WalletErrorClasses.ts +0 -82
- package/src/domains/wallet/domain/errors/WalletErrorFactory.ts +0 -24
- package/src/domains/wallet/domain/errors/WalletErrorMessages.ts +0 -17
- package/src/domains/wallet/domain/types/credit-cost.types.ts +0 -86
- package/src/domains/wallet/domain/types/index.ts +0 -33
- package/src/domains/wallet/domain/types/wallet.types.ts +0 -50
- package/src/domains/wallet/infrastructure/services/product-metadata/CacheManager.ts +0 -30
- package/src/domains/wallet/infrastructure/services/product-metadata/FirebaseFetcher.ts +0 -17
- package/src/domains/wallet/infrastructure/services/product-metadata/ProductMetadataService.ts +0 -57
- package/src/domains/wallet/infrastructure/services/product-metadata/ServiceManager.ts +0 -29
- package/src/domains/wallet/infrastructure/services/product-metadata/index.ts +0 -7
- package/src/domains/wallet/presentation/hooks/index.ts +0 -8
- package/src/domains/wallet/presentation/hooks/useProductMetadata.ts +0 -72
- package/src/domains/wallet/utils/index.ts +0 -1
- package/src/shared/application/ActivationHandler.ts +0 -108
- package/src/shared/application/ports/ISubscriptionService.ts +0 -27
- package/src/shared/infrastructure/index.ts +0 -6
- package/src/shared/infrastructure/react-query/queryInvalidation.ts +0 -46
- package/src/shared/presentation/hooks/index.ts +0 -6
- package/src/shared/presentation/hooks/useAsyncState.ts +0 -72
- package/src/shared/presentation/hooks/useServiceCall.ts +0 -77
- package/src/shared/types/ReactTypes.ts +0 -80
- package/src/shared/utils/InsufficientCreditsError.ts +0 -32
- package/src/shared/utils/Logger.ts +0 -81
- package/src/shared/utils/SubscriptionConfig.ts +0 -15
- package/src/shared/utils/SubscriptionError.ts +0 -47
- package/src/shared/utils/appValidators.ts +0 -38
- package/src/shared/utils/arrayUtils.core.ts +0 -81
- package/src/shared/utils/arrayUtils.query.ts +0 -118
- package/src/shared/utils/arrayUtils.transforms.ts +0 -116
- package/src/shared/utils/arrayUtils.ts +0 -19
- package/src/shared/utils/errorUtils.ts +0 -32
- package/src/shared/utils/index.ts +0 -14
- package/src/shared/utils/numberUtils.aggregate.ts +0 -35
- package/src/shared/utils/numberUtils.format.ts +0 -42
- package/src/shared/utils/numberUtils.math.ts +0 -48
- package/src/shared/utils/queryKeyFactory.ts +0 -9
- package/src/shared/utils/stringUtils.case.ts +0 -64
- package/src/shared/utils/stringUtils.check.ts +0 -65
- package/src/shared/utils/stringUtils.format.ts +0 -84
- package/src/shared/utils/stringUtils.generate.ts +0 -47
- package/src/shared/utils/stringUtils.modify.ts +0 -67
- package/src/shared/utils/stringUtils.ts +0 -10
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.15",
|
|
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",
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
import { detectPackageType } from "../../../utils/packageTypeDetector";
|
|
9
9
|
import { PACKAGE_TYPE, PURCHASE_TYPE, type Platform } from "../../subscription/core/SubscriptionConstants";
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
interface MetadataGeneratorConfig {
|
|
12
12
|
productId: string;
|
|
13
13
|
source: PurchaseSource;
|
|
14
14
|
type: PurchaseType;
|
|
@@ -6,7 +6,7 @@ import { StandardPurchaseCreditStrategy } from "./StandardPurchaseCreditStrategy
|
|
|
6
6
|
/**
|
|
7
7
|
* Orchestrator to coordinate credit allocation logic using the Strategy Pattern.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
class CreditAllocationOrchestrator {
|
|
10
10
|
private strategies: ICreditStrategy[] = [
|
|
11
11
|
new SyncCreditStrategy(),
|
|
12
12
|
new TrialCreditStrategy(),
|
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
import type { UserCreditsDocumentRead } from "../core/UserCreditsDocument";
|
|
7
7
|
import { serverTimestamp, type DocumentSnapshot } from "@umituz/react-native-firebase";
|
|
8
8
|
import { SUBSCRIPTION_STATUS, type Platform } from "../../subscription/core/SubscriptionConstants";
|
|
9
|
-
import { PROCESSED_PURCHASES_WINDOW } from "../core/CreditsConstants";
|
|
10
|
-
|
|
11
9
|
/**
|
|
12
10
|
* Get existing credit document or create default
|
|
13
11
|
*/
|
|
@@ -54,15 +52,3 @@ export function getCreditDocumentOrDefault(
|
|
|
54
52
|
|
|
55
53
|
return defaultDocument;
|
|
56
54
|
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Add purchase ID to processed purchases list
|
|
60
|
-
* Maintains last N purchases (default: PROCESSED_PURCHASES_WINDOW)
|
|
61
|
-
*/
|
|
62
|
-
export function addProcessedPurchase(
|
|
63
|
-
existing: string[],
|
|
64
|
-
purchaseId: string,
|
|
65
|
-
limit: number = PROCESSED_PURCHASES_WINDOW
|
|
66
|
-
): string[] {
|
|
67
|
-
return [...existing, purchaseId].slice(-limit);
|
|
68
|
-
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { isValidNumber, isNonNegativeNumber } from "../../../shared/utils/validators";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const isValidBalance = (balance: number | null | undefined): balance is number => {
|
|
4
4
|
return isValidNumber(balance) && isNonNegativeNumber(balance);
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const isValidCost = (cost: number): boolean => {
|
|
8
8
|
return isValidNumber(cost) && isNonNegativeNumber(cost);
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const isValidMaxCredits = (max: number): boolean => {
|
|
12
12
|
return isValidNumber(max) && max > 0;
|
|
13
13
|
};
|
|
14
14
|
|
|
@@ -11,7 +11,7 @@ export const PaywallFeatures: React.FC<{ features: SubscriptionFeature[] }> = ({
|
|
|
11
11
|
return (
|
|
12
12
|
<View style={[styles.features, { backgroundColor: tokens.colors.surfaceSecondary }]}>
|
|
13
13
|
{features.map((feature, idx) => (
|
|
14
|
-
<View key={
|
|
14
|
+
<View key={`${feature.icon}-${feature.text}`} style={styles.featureRow}>
|
|
15
15
|
<View style={[styles.featureIcon, { backgroundColor: tokens.colors.primaryLight }]}>
|
|
16
16
|
<AtomicIcon name={feature.icon} customSize={16} customColor={tokens.colors.primary} />
|
|
17
17
|
</View>
|
|
@@ -7,7 +7,7 @@ import type { PurchasesPackage } from "react-native-purchases";
|
|
|
7
7
|
import { usePurchaseLoadingStore } from "../../subscription/presentation/stores";
|
|
8
8
|
import type { PurchaseSource } from "../../subscription/core/SubscriptionConstants";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface UsePaywallActionsParams {
|
|
11
11
|
packages?: PurchasesPackage[];
|
|
12
12
|
onPurchase?: (pkg: PurchasesPackage) => Promise<void | boolean>;
|
|
13
13
|
onRestore?: () => Promise<void | boolean>;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { BaseError } from "../../../../shared/utils/BaseError";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
class RevenueCatError extends BaseError {
|
|
9
9
|
constructor(message: string, code: string = 'REVENUE_CAT_ERROR', cause?: Error) {
|
|
10
10
|
super(message, code, cause);
|
|
11
11
|
this.name = "RevenueCatError";
|
|
@@ -19,13 +19,6 @@ export class RevenueCatInitializationError extends RevenueCatError {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export class RevenueCatConfigurationError extends RevenueCatError {
|
|
23
|
-
constructor(message = "RevenueCat configuration is invalid", cause?: Error) {
|
|
24
|
-
super(message, 'REVENUE_CAT_CONFIGURATION_ERROR', cause);
|
|
25
|
-
this.name = "RevenueCatConfigurationError";
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
22
|
export class RevenueCatPurchaseError extends RevenueCatError {
|
|
30
23
|
public readonly productId: string | undefined;
|
|
31
24
|
|
|
@@ -57,9 +50,3 @@ export class RevenueCatNetworkError extends RevenueCatError {
|
|
|
57
50
|
}
|
|
58
51
|
}
|
|
59
52
|
|
|
60
|
-
export class RevenueCatExpoGoError extends RevenueCatError {
|
|
61
|
-
constructor(message = "RevenueCat is not available in Expo Go. Use a development build or test store.", cause?: Error) {
|
|
62
|
-
super(message, 'REVENUE_CAT_EXPO_GO_ERROR', cause);
|
|
63
|
-
this.name = "RevenueCatExpoGoError";
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -54,7 +54,7 @@ const ERROR_CODE_MAP = new Map<string, PurchasesErrorCode>([
|
|
|
54
54
|
* @param errorCode - Error code string from RevenueCat error
|
|
55
55
|
* @returns ErrorMessage configuration
|
|
56
56
|
*/
|
|
57
|
-
|
|
57
|
+
function getErrorMessageForCode(errorCode: string | null | undefined): ErrorMessage {
|
|
58
58
|
if (!errorCode) {
|
|
59
59
|
return DEFAULT_ERROR_MESSAGE;
|
|
60
60
|
}
|
|
@@ -9,7 +9,7 @@ import type { CustomerInfo, PurchasesEntitlementInfo, PurchasesPackage } from "r
|
|
|
9
9
|
* Default entitlement identifier
|
|
10
10
|
* Can be overridden in RevenueCatConfig
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
const DEFAULT_ENTITLEMENT_ID = "premium";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Store type - Directly from RevenueCat SDK
|
|
@@ -34,7 +34,7 @@ export type PackageType = PurchasesPackage['packageType'];
|
|
|
34
34
|
* RevenueCat Entitlement Info
|
|
35
35
|
* Represents active entitlement data from CustomerInfo
|
|
36
36
|
*/
|
|
37
|
-
|
|
37
|
+
interface RevenueCatEntitlement {
|
|
38
38
|
identifier: string;
|
|
39
39
|
productIdentifier: string;
|
|
40
40
|
isSandbox: boolean;
|
|
@@ -50,7 +50,7 @@ export interface RevenueCatEntitlement {
|
|
|
50
50
|
/**
|
|
51
51
|
* RevenueCat Purchase Error with userCancelled flag
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
interface RevenueCatPurchaseErrorInfo extends Error {
|
|
54
54
|
userCancelled?: boolean;
|
|
55
55
|
code?: string;
|
|
56
56
|
readableErrorCode?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { InitializeResult } from "../../../../shared/application/ports/IRevenueCatService";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
class ConfigurationStateManager {
|
|
4
4
|
private _isPurchasesConfigured = false;
|
|
5
5
|
private _configurationPromise: Promise<InitializeResult> | null = null;
|
|
6
6
|
private _resolveConfiguration: ((value: InitializeResult) => void) | null = null;
|
|
@@ -19,7 +19,13 @@ export class ConfigurationStateManager {
|
|
|
19
19
|
|
|
20
20
|
startConfiguration(): (value: InitializeResult) => void {
|
|
21
21
|
if (this._configurationPromise) {
|
|
22
|
-
|
|
22
|
+
// Resolve previous pending configuration as failed to prevent dangling promises
|
|
23
|
+
if (this._resolveConfiguration) {
|
|
24
|
+
const prevResolve = this._resolveConfiguration;
|
|
25
|
+
this._resolveConfiguration = null;
|
|
26
|
+
prevResolve({ success: false, offering: null, isPremium: false });
|
|
27
|
+
}
|
|
28
|
+
this._configurationPromise = null;
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
// Create promise and store resolve function atomically
|
|
@@ -5,8 +5,6 @@ import { FAILED_INITIALIZATION_RESULT, CONFIGURATION_RETRY_DELAY_MS, MAX_INIT_RE
|
|
|
5
5
|
import { configState } from "./ConfigurationStateManager";
|
|
6
6
|
import { handleUserSwitch, handleInitialConfiguration, fetchCurrentUserData } from "./userSwitchHandler";
|
|
7
7
|
|
|
8
|
-
export type { InitializerDeps } from "./RevenueCatInitializer.types";
|
|
9
|
-
|
|
10
8
|
const MAX_CONFIG_START_RETRIES = 3;
|
|
11
9
|
|
|
12
10
|
export async function initializeSDK(
|
|
@@ -3,10 +3,14 @@ import { getCurrentUserId, setupAuthStateListener } from "../SubscriptionAuthLis
|
|
|
3
3
|
import type { SubscriptionInitConfig } from "../SubscriptionInitializerTypes";
|
|
4
4
|
|
|
5
5
|
const AUTH_STATE_DEBOUNCE_MS = 500; // Wait 500ms before processing auth state changes
|
|
6
|
+
const MAX_RETRY_ATTEMPTS = 3;
|
|
7
|
+
const RETRY_DELAY_MS = 2000;
|
|
6
8
|
|
|
7
9
|
export async function startBackgroundInitialization(config: SubscriptionInitConfig): Promise<() => void> {
|
|
8
10
|
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
11
|
+
let retryTimer: ReturnType<typeof setTimeout> | null = null;
|
|
9
12
|
let lastUserId: string | undefined = undefined;
|
|
13
|
+
let lastInitSucceeded = false;
|
|
10
14
|
|
|
11
15
|
const initializeInBackground = async (revenueCatUserId?: string): Promise<void> => {
|
|
12
16
|
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
@@ -15,16 +19,49 @@ export async function startBackgroundInitialization(config: SubscriptionInitConf
|
|
|
15
19
|
await SubscriptionManager.initialize(revenueCatUserId);
|
|
16
20
|
};
|
|
17
21
|
|
|
22
|
+
const attemptInitWithRetry = async (revenueCatUserId?: string, attempt = 0): Promise<void> => {
|
|
23
|
+
try {
|
|
24
|
+
await initializeInBackground(revenueCatUserId);
|
|
25
|
+
lastUserId = revenueCatUserId;
|
|
26
|
+
lastInitSucceeded = true;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
lastInitSucceeded = false;
|
|
29
|
+
console.error('[BackgroundInitializer] Initialization failed:', {
|
|
30
|
+
userId: revenueCatUserId,
|
|
31
|
+
attempt: attempt + 1,
|
|
32
|
+
maxAttempts: MAX_RETRY_ATTEMPTS,
|
|
33
|
+
error: error instanceof Error ? error.message : String(error)
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (attempt < MAX_RETRY_ATTEMPTS - 1) {
|
|
37
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
38
|
+
console.log('[BackgroundInitializer] Scheduling retry', { attempt: attempt + 2 });
|
|
39
|
+
}
|
|
40
|
+
retryTimer = setTimeout(() => {
|
|
41
|
+
void attemptInitWithRetry(revenueCatUserId, attempt + 1);
|
|
42
|
+
}, RETRY_DELAY_MS * (attempt + 1));
|
|
43
|
+
} else {
|
|
44
|
+
// After all retries failed, set lastUserId so we don't block
|
|
45
|
+
// but mark as failed so next auth change can retry
|
|
46
|
+
lastUserId = revenueCatUserId;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
18
51
|
const debouncedInitialize = (revenueCatUserId?: string): void => {
|
|
19
|
-
// Clear any pending initialization
|
|
52
|
+
// Clear any pending initialization or retry
|
|
20
53
|
if (debounceTimer) {
|
|
21
54
|
clearTimeout(debounceTimer);
|
|
22
55
|
}
|
|
56
|
+
if (retryTimer) {
|
|
57
|
+
clearTimeout(retryTimer);
|
|
58
|
+
retryTimer = null;
|
|
59
|
+
}
|
|
23
60
|
|
|
24
|
-
// If userId hasn't changed, skip
|
|
25
|
-
if (lastUserId === revenueCatUserId) {
|
|
61
|
+
// If userId hasn't changed AND last init succeeded, skip
|
|
62
|
+
if (lastUserId === revenueCatUserId && lastInitSucceeded) {
|
|
26
63
|
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
27
|
-
console.log('[BackgroundInitializer] UserId unchanged, skipping
|
|
64
|
+
console.log('[BackgroundInitializer] UserId unchanged and init succeeded, skipping');
|
|
28
65
|
}
|
|
29
66
|
return;
|
|
30
67
|
}
|
|
@@ -33,18 +70,7 @@ export async function startBackgroundInitialization(config: SubscriptionInitConf
|
|
|
33
70
|
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
34
71
|
console.log('[BackgroundInitializer] Auth state listener triggered, reinitializing with userId:', revenueCatUserId || '(undefined - anonymous)');
|
|
35
72
|
}
|
|
36
|
-
|
|
37
|
-
await initializeInBackground(revenueCatUserId);
|
|
38
|
-
lastUserId = revenueCatUserId;
|
|
39
|
-
} catch (error) {
|
|
40
|
-
// Don't update lastUserId on failure — allow retry on next auth state change
|
|
41
|
-
// with the same userId (e.g., network blip recovers)
|
|
42
|
-
lastUserId = undefined;
|
|
43
|
-
console.error('[BackgroundInitializer] Reinitialization failed:', {
|
|
44
|
-
userId: revenueCatUserId,
|
|
45
|
-
error: error instanceof Error ? error.message : String(error)
|
|
46
|
-
});
|
|
47
|
-
}
|
|
73
|
+
void attemptInitWithRetry(revenueCatUserId);
|
|
48
74
|
}, AUTH_STATE_DEBOUNCE_MS);
|
|
49
75
|
};
|
|
50
76
|
|
|
@@ -75,6 +101,9 @@ export async function startBackgroundInitialization(config: SubscriptionInitConf
|
|
|
75
101
|
if (debounceTimer) {
|
|
76
102
|
clearTimeout(debounceTimer);
|
|
77
103
|
}
|
|
104
|
+
if (retryTimer) {
|
|
105
|
+
clearTimeout(retryTimer);
|
|
106
|
+
}
|
|
78
107
|
if (unsubscribe) {
|
|
79
108
|
unsubscribe();
|
|
80
109
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { initializeSubscription } from "./SubscriptionInitializer";
|
|
2
|
-
export type {
|
|
2
|
+
export type { CreditPackageConfig, SubscriptionInitConfig } from "../SubscriptionInitializerTypes";
|
|
@@ -11,11 +11,10 @@ import {
|
|
|
11
11
|
ActiveStatusHandler
|
|
12
12
|
} from "./SubscriptionStatusHandlers";
|
|
13
13
|
|
|
14
|
-
export {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type
|
|
18
|
-
type SubscriptionStatusType
|
|
14
|
+
export {
|
|
15
|
+
PERIOD_TYPE,
|
|
16
|
+
type PeriodType,
|
|
17
|
+
type SubscriptionStatusType
|
|
19
18
|
};
|
|
20
19
|
|
|
21
20
|
export interface SubscriptionStatus {
|
|
@@ -46,11 +45,6 @@ export const isSubscriptionValid = (status: SubscriptionStatus | null): boolean
|
|
|
46
45
|
return timezoneService.isFuture(new Date(status.expiresAt));
|
|
47
46
|
};
|
|
48
47
|
|
|
49
|
-
export const calculateDaysRemaining = (expiresAt: string | null): number | null => {
|
|
50
|
-
if (!expiresAt) return null;
|
|
51
|
-
return timezoneService.getDaysUntil(new Date(expiresAt));
|
|
52
|
-
};
|
|
53
|
-
|
|
54
48
|
export interface StatusResolverInput {
|
|
55
49
|
isPremium: boolean;
|
|
56
50
|
willRenew?: boolean;
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "./SubscriptionConstants";
|
|
6
6
|
import type { StatusResolverInput } from "./SubscriptionStatus";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
abstract class BaseStatusHandler {
|
|
9
9
|
protected next?: BaseStatusHandler;
|
|
10
10
|
|
|
11
11
|
setNext(handler: BaseStatusHandler): BaseStatusHandler {
|
|
@@ -20,7 +20,7 @@ import { creditsQueryKeys } from "../../../credits/presentation/creditsQueryKeys
|
|
|
20
20
|
import { getErrorMessage } from "../../../revenuecat/core/errors";
|
|
21
21
|
|
|
22
22
|
/** Purchase mutation result - simplified for presentation layer */
|
|
23
|
-
|
|
23
|
+
interface PurchaseMutationResult {
|
|
24
24
|
success: boolean;
|
|
25
25
|
productId: string;
|
|
26
26
|
}
|
|
@@ -14,9 +14,8 @@ import {
|
|
|
14
14
|
type TrialEligibilityMap,
|
|
15
15
|
} from "../utils/trialEligibilityUtils";
|
|
16
16
|
|
|
17
|
-
export type { ProductTrialEligibility, TrialEligibilityMap };
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
interface UseRevenueCatTrialEligibilityResult {
|
|
20
19
|
/** Map of product IDs to their trial eligibility */
|
|
21
20
|
eligibilityMap: TrialEligibilityMap;
|
|
22
21
|
/** Whether eligibility check is in progress */
|
|
@@ -4,10 +4,6 @@
|
|
|
4
4
|
* Generic hooks for 100+ apps
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
export {
|
|
8
|
-
SUBSCRIPTION_QUERY_KEYS,
|
|
9
|
-
} from "./subscriptionQueryKeys";
|
|
10
|
-
export { useInitializeSubscription } from "./useInitializeSubscription";
|
|
11
7
|
export { useSubscriptionPackages } from "./useSubscriptionPackages";
|
|
12
8
|
export { usePurchasePackage } from "./usePurchasePackage";
|
|
13
9
|
export { useRestorePurchase } from "./useRestorePurchase";
|
|
@@ -1,34 +1,62 @@
|
|
|
1
1
|
import Purchases, { type PurchasesOffering } from "react-native-purchases";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface OfferingsFetcherDeps {
|
|
4
4
|
isInitialized: () => boolean;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
const MAX_FETCH_RETRIES = 2;
|
|
8
|
+
const FETCH_RETRY_DELAY_MS = 1500;
|
|
9
|
+
|
|
7
10
|
export async function fetchOfferings(deps: OfferingsFetcherDeps): Promise<PurchasesOffering | null> {
|
|
8
11
|
if (!deps.isInitialized()) return null;
|
|
9
|
-
try {
|
|
10
|
-
const offerings = await Purchases.getOfferings();
|
|
11
|
-
|
|
12
|
-
if (__DEV__) {
|
|
13
|
-
console.log('[OfferingsFetcher] Offerings received:', {
|
|
14
|
-
hasCurrent: !!offerings.current,
|
|
15
|
-
currentId: offerings.current?.identifier,
|
|
16
|
-
allOfferingsCount: Object.keys(offerings.all).length,
|
|
17
|
-
allOfferingIds: Object.keys(offerings.all),
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
for (let attempt = 0; attempt <= MAX_FETCH_RETRIES; attempt++) {
|
|
14
|
+
try {
|
|
15
|
+
const offerings = await Purchases.getOfferings();
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
18
|
+
console.log('[OfferingsFetcher] Offerings received:', {
|
|
19
|
+
attempt,
|
|
20
|
+
hasCurrent: !!offerings.current,
|
|
21
|
+
currentId: offerings.current?.identifier,
|
|
22
|
+
allOfferingsCount: Object.keys(offerings.all).length,
|
|
23
|
+
allOfferingIds: Object.keys(offerings.all),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (offerings.current) {
|
|
28
|
+
return offerings.current;
|
|
29
|
+
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const allOfferings = Object.values(offerings.all);
|
|
32
|
+
if (allOfferings.length > 0) {
|
|
33
|
+
return allOfferings[0];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// No offerings found - retry after delay (RevenueCat may still be syncing)
|
|
37
|
+
if (attempt < MAX_FETCH_RETRIES) {
|
|
38
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
39
|
+
console.log('[OfferingsFetcher] No offerings found, retrying...', { attempt: attempt + 1 });
|
|
40
|
+
}
|
|
41
|
+
await new Promise<void>(resolve => setTimeout(resolve, FETCH_RETRY_DELAY_MS));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
46
|
+
console.warn('[OfferingsFetcher] No offerings found after all retries');
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (attempt < MAX_FETCH_RETRIES) {
|
|
51
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
52
|
+
console.warn('[OfferingsFetcher] Fetch failed, retrying...', { attempt: attempt + 1, error });
|
|
53
|
+
}
|
|
54
|
+
await new Promise<void>(resolve => setTimeout(resolve, FETCH_RETRY_DELAY_MS));
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
throw new Error(`Failed to fetch offerings: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
58
|
+
}
|
|
33
59
|
}
|
|
60
|
+
|
|
61
|
+
return null;
|
|
34
62
|
}
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "../../../revenuecat/core/types";
|
|
15
15
|
import { notifyRestoreCompleted } from "../utils/PremiumStatusSyncer";
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
interface RestoreHandlerDeps {
|
|
18
18
|
config: RevenueCatConfig;
|
|
19
19
|
isInitialized: () => boolean;
|
|
20
20
|
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { initializeRevenueCatService, getRevenueCatService, resetRevenueCatService } from "./revenueCatServiceInstance";
|
|
1
|
+
export { initializeRevenueCatService, getRevenueCatService } from "./revenueCatServiceInstance";
|
|
@@ -11,7 +11,3 @@ export const initializeRevenueCatService = (config: RevenueCatConfig): RevenueCa
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export const getRevenueCatService = (): RevenueCatService | null => revenueCatServiceInstance;
|
|
14
|
-
|
|
15
|
-
export const resetRevenueCatService = (): void => {
|
|
16
|
-
revenueCatServiceInstance = null;
|
|
17
|
-
};
|
|
@@ -2,7 +2,7 @@ import React, { useMemo } from "react";
|
|
|
2
2
|
import { View, StyleSheet } from "react-native";
|
|
3
3
|
import { useAppDesignTokens, AtomicText } from "@umituz/react-native-design-system";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interface CreditRowProps {
|
|
6
6
|
label: string;
|
|
7
7
|
current: number;
|
|
8
8
|
total: number;
|
|
@@ -7,7 +7,7 @@ import React from "react";
|
|
|
7
7
|
import { View, StyleSheet, type ViewStyle, type TextStyle } from "react-native";
|
|
8
8
|
import { useAppDesignTokens, AtomicText } from "@umituz/react-native-design-system";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface DetailRowProps {
|
|
11
11
|
label: string;
|
|
12
12
|
value: string;
|
|
13
13
|
highlight?: boolean;
|
|
@@ -7,8 +7,6 @@ import { FEEDBACK_OPTION_OPACITY } from "./feedbackOptionConstants";
|
|
|
7
7
|
import { FeedbackRadioButton } from "./FeedbackRadioButton";
|
|
8
8
|
import { FeedbackTextInput } from "./FeedbackTextInput";
|
|
9
9
|
|
|
10
|
-
export type { FeedbackOptionProps } from "./FeedbackOption.types";
|
|
11
|
-
|
|
12
10
|
export const FeedbackOption: React.FC<FeedbackOptionProps> = React.memo(({
|
|
13
11
|
isSelected,
|
|
14
12
|
text,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRef, useEffect, type MutableRefObject } from "react";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface FeatureGateRefs {
|
|
4
4
|
creditBalanceRef: MutableRefObject<number>;
|
|
5
5
|
hasSubscriptionRef: MutableRefObject<boolean>;
|
|
6
6
|
onShowPaywallRef: MutableRefObject<(requiredCredits?: number) => void>;
|
|
@@ -8,14 +8,14 @@ import { View, StyleSheet } from "react-native";
|
|
|
8
8
|
import { useAppDesignTokens, AtomicText } from "@umituz/react-native-design-system";
|
|
9
9
|
import { CreditRow } from "../../components/details/CreditRow";
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
interface CreditItem {
|
|
12
12
|
id: string;
|
|
13
13
|
label: string;
|
|
14
14
|
current: number;
|
|
15
15
|
total: number;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
interface CreditsListProps {
|
|
19
19
|
credits: readonly CreditItem[];
|
|
20
20
|
title?: string;
|
|
21
21
|
description?: string;
|
|
@@ -7,8 +7,6 @@ import { createSubscriptionHeaderStyles } from "./SubscriptionHeader.styles";
|
|
|
7
7
|
import { EXPIRATION_WARNING_THRESHOLD_DAYS as EXPIRING_SOON_THRESHOLD_DAYS } from "../../../constants/thresholds";
|
|
8
8
|
import { SubscriptionHeaderContent } from "./SubscriptionHeaderContent";
|
|
9
9
|
|
|
10
|
-
export type { SubscriptionHeaderProps } from "./SubscriptionHeader.types";
|
|
11
|
-
|
|
12
10
|
export const SubscriptionHeader: React.FC<SubscriptionHeaderProps> = ({
|
|
13
11
|
statusType,
|
|
14
12
|
showExpirationDate,
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
import { create } from "zustand";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface PurchaseLoadingState {
|
|
11
11
|
/** Map of product IDs to purchase sources (supports concurrent purchases) */
|
|
12
12
|
activePurchases: Map<string, "manual" | "auto-execution">;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
interface PurchaseLoadingActions {
|
|
16
16
|
/** Start purchase loading state for a product */
|
|
17
17
|
startPurchase: (productId: string, source: "manual" | "auto-execution") => void;
|
|
18
18
|
/** End purchase loading state for a product */
|
|
@@ -23,7 +23,7 @@ export interface PurchaseLoadingActions {
|
|
|
23
23
|
reset: () => void;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
type PurchaseLoadingStore = PurchaseLoadingState & PurchaseLoadingActions;
|
|
27
27
|
|
|
28
28
|
const createInitialState = (): PurchaseLoadingState => ({
|
|
29
29
|
activePurchases: new Map(),
|
|
@@ -61,7 +61,3 @@ export const usePurchaseLoadingStore = create<PurchaseLoadingStore>((set, get) =
|
|
|
61
61
|
|
|
62
62
|
// Selectors for optimized re-renders
|
|
63
63
|
export const selectIsPurchasing = (state: PurchaseLoadingStore) => state.activePurchases.size > 0;
|
|
64
|
-
export const selectIsProductPurchasing = (productId: string) =>
|
|
65
|
-
(state: PurchaseLoadingStore) => state.activePurchases.has(productId);
|
|
66
|
-
export const selectPurchaseSource = (productId: string) =>
|
|
67
|
-
(state: PurchaseLoadingStore) => state.activePurchases.get(productId) ?? null;
|