@umituz/react-native-subscription 2.27.65 → 2.27.66
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.27.
|
|
3
|
+
"version": "2.27.66",
|
|
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",
|
|
@@ -55,7 +55,9 @@
|
|
|
55
55
|
"@tanstack/query-async-storage-persister": "^5.66.7",
|
|
56
56
|
"@tanstack/react-query": "^5.0.0",
|
|
57
57
|
"@tanstack/react-query-persist-client": "^5.66.7",
|
|
58
|
+
"@types/jest": "^30.0.0",
|
|
58
59
|
"@types/react": "~19.1.10",
|
|
60
|
+
"@types/react-native": "^0.72.8",
|
|
59
61
|
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
60
62
|
"@typescript-eslint/parser": "^8.50.1",
|
|
61
63
|
"@umituz/react-native-auth": "^3.6.14",
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SUBSCRIPTION_STATUS,
|
|
3
|
+
} from './SubscriptionConstants';
|
|
1
4
|
import {
|
|
2
5
|
createDefaultSubscriptionStatus,
|
|
3
6
|
isSubscriptionValid,
|
|
4
7
|
calculateDaysRemaining,
|
|
8
|
+
resolveSubscriptionStatus,
|
|
5
9
|
} from './SubscriptionStatus';
|
|
6
10
|
|
|
7
11
|
describe('SubscriptionStatus', () => {
|
|
@@ -16,7 +20,7 @@ describe('SubscriptionStatus', () => {
|
|
|
16
20
|
purchasedAt: null,
|
|
17
21
|
customerId: null,
|
|
18
22
|
syncedAt: null,
|
|
19
|
-
status:
|
|
23
|
+
status: SUBSCRIPTION_STATUS.NONE,
|
|
20
24
|
});
|
|
21
25
|
});
|
|
22
26
|
});
|
|
@@ -102,4 +106,44 @@ describe('SubscriptionStatus', () => {
|
|
|
102
106
|
expect(calculateDaysRemaining(pastDate.toISOString())).toBe(0);
|
|
103
107
|
});
|
|
104
108
|
});
|
|
109
|
+
|
|
110
|
+
describe('resolveSubscriptionStatus', () => {
|
|
111
|
+
it('should return NONE when not premium', () => {
|
|
112
|
+
expect(resolveSubscriptionStatus({ isPremium: false })).toBe(SUBSCRIPTION_STATUS.NONE);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should return EXPIRED when expired', () => {
|
|
116
|
+
expect(resolveSubscriptionStatus({ isPremium: true, isExpired: true })).toBe(SUBSCRIPTION_STATUS.EXPIRED);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should return TRIAL when trialing and set to renew', () => {
|
|
120
|
+
expect(resolveSubscriptionStatus({
|
|
121
|
+
isPremium: true,
|
|
122
|
+
periodType: 'TRIAL',
|
|
123
|
+
willRenew: true
|
|
124
|
+
})).toBe(SUBSCRIPTION_STATUS.TRIAL);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should return TRIAL_CANCELED when trialing and will not renew', () => {
|
|
128
|
+
expect(resolveSubscriptionStatus({
|
|
129
|
+
isPremium: true,
|
|
130
|
+
periodType: 'TRIAL',
|
|
131
|
+
willRenew: false
|
|
132
|
+
})).toBe(SUBSCRIPTION_STATUS.TRIAL_CANCELED);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should return ACTIVE when premium, not expired, not trial, and set to renew', () => {
|
|
136
|
+
expect(resolveSubscriptionStatus({
|
|
137
|
+
isPremium: true,
|
|
138
|
+
willRenew: true
|
|
139
|
+
})).toBe(SUBSCRIPTION_STATUS.ACTIVE);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should return CANCELED when premium, not expired, not trial, and will not renew', () => {
|
|
143
|
+
expect(resolveSubscriptionStatus({
|
|
144
|
+
isPremium: true,
|
|
145
|
+
willRenew: false
|
|
146
|
+
})).toBe(SUBSCRIPTION_STATUS.CANCELED);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
105
149
|
});
|
|
@@ -13,7 +13,7 @@ import { configureCreditsRepository, getCreditsRepository } from "../repositorie
|
|
|
13
13
|
import { SubscriptionManager } from "../../revenuecat/infrastructure/managers/SubscriptionManager";
|
|
14
14
|
import { configureAuthProvider } from "../../presentation/hooks/useAuthAwarePurchase";
|
|
15
15
|
import type { RevenueCatData } from "../../domain/types/RevenueCatData";
|
|
16
|
-
import {
|
|
16
|
+
import { type PeriodType, type PurchaseSource } from "../../domain/entities/SubscriptionConstants";
|
|
17
17
|
import type { SubscriptionInitConfig, FirebaseAuthLike } from "./SubscriptionInitializerTypes";
|
|
18
18
|
|
|
19
19
|
export type { FirebaseAuthLike, CreditPackageConfig, SubscriptionInitConfig } from "./SubscriptionInitializerTypes";
|
|
@@ -33,14 +33,14 @@ export const PremiumStatusBadge: React.FC<PremiumStatusBadgeProps> = ({
|
|
|
33
33
|
}) => {
|
|
34
34
|
const tokens = useAppDesignTokens();
|
|
35
35
|
|
|
36
|
-
const labels: Record<SubscriptionStatusType, string> = {
|
|
36
|
+
const labels: Record<SubscriptionStatusType, string> = useMemo(() => ({
|
|
37
37
|
[SUBSCRIPTION_STATUS.ACTIVE]: activeLabel,
|
|
38
38
|
[SUBSCRIPTION_STATUS.TRIAL]: activeLabel,
|
|
39
39
|
[SUBSCRIPTION_STATUS.TRIAL_CANCELED]: trialCanceledLabel ?? canceledLabel,
|
|
40
40
|
[SUBSCRIPTION_STATUS.EXPIRED]: expiredLabel,
|
|
41
41
|
[SUBSCRIPTION_STATUS.NONE]: noneLabel,
|
|
42
42
|
[SUBSCRIPTION_STATUS.CANCELED]: canceledLabel,
|
|
43
|
-
};
|
|
43
|
+
}), [activeLabel, trialCanceledLabel, canceledLabel, expiredLabel, noneLabel]);
|
|
44
44
|
|
|
45
45
|
const backgroundColor = useMemo(() => {
|
|
46
46
|
const colors: Record<SubscriptionStatusType, string> = {
|
|
@@ -7,23 +7,22 @@ import { PACKAGE_TYPE, type PackageType } from "../domain/entities/SubscriptionC
|
|
|
7
7
|
|
|
8
8
|
export type SubscriptionPackageType = PackageType;
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Check if identifier is a credit package (consumable purchase)
|
|
12
|
+
* Credit packages use a different system and don't need type detection
|
|
13
|
+
*/
|
|
10
14
|
/**
|
|
11
15
|
* Check if identifier is a credit package (consumable purchase)
|
|
12
16
|
* Credit packages use a different system and don't need type detection
|
|
13
17
|
*/
|
|
14
18
|
function isCreditPackage(identifier: string): boolean {
|
|
15
|
-
|
|
19
|
+
// Matches "credit" as a word or part of a common naming pattern
|
|
20
|
+
return /\bcredit\b|_credit_|-credit-/i.test(identifier) || identifier.toLowerCase().includes("credit");
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
/**
|
|
19
24
|
* Detect package type from product identifier
|
|
20
|
-
* Supports common RevenueCat naming patterns
|
|
21
|
-
* - premium_weekly, weekly_premium, premium-weekly
|
|
22
|
-
* - premium_monthly, monthly_premium, premium-monthly
|
|
23
|
-
* - premium_yearly, yearly_premium, premium-yearly, premium_annual, annual_premium
|
|
24
|
-
* - preview-product-id (Preview API mode in Expo Go)
|
|
25
|
-
*
|
|
26
|
-
* Note: Credit packages (consumable purchases) are skipped silently
|
|
25
|
+
* Supports common RevenueCat naming patterns with regex for better accuracy
|
|
27
26
|
*/
|
|
28
27
|
export function detectPackageType(productIdentifier: string): SubscriptionPackageType {
|
|
29
28
|
if (!productIdentifier) {
|
|
@@ -45,28 +44,24 @@ export function detectPackageType(productIdentifier: string): SubscriptionPackag
|
|
|
45
44
|
return PACKAGE_TYPE.MONTHLY;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
// Weekly detection
|
|
49
|
-
if (
|
|
47
|
+
// Weekly detection: matches "weekly" or "week" as distinct parts of the ID
|
|
48
|
+
if (/\bweekly?\b|_week_|-week-|\.week\./i.test(normalized)) {
|
|
50
49
|
if (__DEV__) {
|
|
51
50
|
console.log("[PackageTypeDetector] Detected: WEEKLY");
|
|
52
51
|
}
|
|
53
52
|
return PACKAGE_TYPE.WEEKLY;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
// Monthly detection
|
|
57
|
-
if (
|
|
55
|
+
// Monthly detection: matches "monthly" or "month"
|
|
56
|
+
if (/\bmonthly?\b|_month_|-month-|\.month\./i.test(normalized)) {
|
|
58
57
|
if (__DEV__) {
|
|
59
58
|
console.log("[PackageTypeDetector] Detected: MONTHLY");
|
|
60
59
|
}
|
|
61
60
|
return PACKAGE_TYPE.MONTHLY;
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
// Yearly detection
|
|
65
|
-
if (
|
|
66
|
-
normalized.includes("yearly") ||
|
|
67
|
-
normalized.includes("year") ||
|
|
68
|
-
normalized.includes("annual")
|
|
69
|
-
) {
|
|
63
|
+
// Yearly detection: matches "yearly", "year", or "annual"
|
|
64
|
+
if (/\byearly?\b|_year_|-year-|\.year\.|annual/i.test(normalized)) {
|
|
70
65
|
if (__DEV__) {
|
|
71
66
|
console.log("[PackageTypeDetector] Detected: YEARLY");
|
|
72
67
|
}
|