@umituz/react-native-subscription 2.13.1 → 2.13.3

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.13.1",
3
+ "version": "2.13.3",
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",
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Plan Entity
3
+ * Represents a subscription plan with credits and pricing
4
+ */
5
+
6
+ export type PlanType = "weekly" | "monthly" | "yearly" | "lifetime" | "custom";
7
+
8
+ export interface Plan {
9
+ readonly id: string;
10
+ readonly type: PlanType;
11
+ readonly credits: number;
12
+ readonly price: number;
13
+ readonly currency: string;
14
+ readonly labelKey: string;
15
+ readonly descriptionKey?: string;
16
+ readonly isBestValue?: boolean;
17
+ readonly isPopular?: boolean;
18
+ }
19
+
20
+ export interface PlanMetadata {
21
+ readonly cost: number;
22
+ readonly profit: number;
23
+ readonly profitMargin: number;
24
+ readonly pricePerCredit: number;
25
+ }
26
+
27
+ export const calculatePlanMetadata = (
28
+ plan: Plan,
29
+ costPerCredit: number,
30
+ commissionRate: number = 0.30
31
+ ): PlanMetadata => {
32
+ const totalCost = plan.credits * costPerCredit;
33
+ const netRevenue = plan.price * (1 - commissionRate);
34
+ const profit = netRevenue - totalCost;
35
+ const profitMargin = (profit / plan.price) * 100;
36
+ const pricePerCredit = plan.price / plan.credits;
37
+
38
+ return {
39
+ cost: totalCost,
40
+ profit,
41
+ profitMargin,
42
+ pricePerCredit,
43
+ };
44
+ };
@@ -0,0 +1 @@
1
+ export * from "./Plan";
@@ -0,0 +1,2 @@
1
+ export * from "./entities";
2
+ export * from "./value-objects";
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Subscription Configuration Value Object
3
+ * Defines app-specific subscription plans and settings
4
+ */
5
+
6
+ import type { Plan } from "../entities";
7
+
8
+ export interface ConfigTranslations {
9
+ readonly title: string;
10
+ readonly subtitle?: string;
11
+ readonly creditsLabel: string;
12
+ readonly creditsRemaining: string;
13
+ readonly creditsTotal: string;
14
+ readonly upgradeButton: string;
15
+ readonly manageButton: string;
16
+ readonly restoreButton: string;
17
+ }
18
+
19
+ export interface Config {
20
+ readonly plans: readonly Plan[];
21
+ readonly collectionName: string;
22
+ readonly entitlementId: string;
23
+ readonly translations: ConfigTranslations;
24
+ readonly showCreditDetails?: boolean;
25
+ readonly allowRestore?: boolean;
26
+ readonly costPerCredit?: number;
27
+ readonly commissionRate?: number;
28
+ }
29
+
30
+ export const DEFAULT_TRANSLATIONS: ConfigTranslations = {
31
+ title: "subscription.title",
32
+ subtitle: "subscription.subtitle",
33
+ creditsLabel: "subscription.credits",
34
+ creditsRemaining: "subscription.creditsRemaining",
35
+ creditsTotal: "subscription.creditsTotal",
36
+ upgradeButton: "subscription.upgrade",
37
+ manageButton: "subscription.manage",
38
+ restoreButton: "subscription.restore",
39
+ };
40
+
41
+ export const DEFAULT_CONFIG: Partial<Config> = {
42
+ collectionName: "credits",
43
+ entitlementId: "premium",
44
+ translations: DEFAULT_TRANSLATIONS,
45
+ showCreditDetails: true,
46
+ allowRestore: true,
47
+ costPerCredit: 0.04,
48
+ commissionRate: 0.30,
49
+ };
@@ -0,0 +1 @@
1
+ export * from "./Config";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Subscription Config Domain
3
+ * Configuration-driven subscription management
4
+ */
5
+
6
+ export * from "./domain";
7
+ export * from "./utils";
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Subscription Config Utilities
3
+ * Helper functions for working with subscription configurations
4
+ */
5
+
6
+ import type { Plan, Config } from "../domain";
7
+
8
+ export const getPlanByType = (
9
+ config: Config,
10
+ type: string
11
+ ): Plan | undefined => {
12
+ return config.plans.find((plan) => plan.type === type);
13
+ };
14
+
15
+ export const getPlanById = (
16
+ config: Config,
17
+ id: string
18
+ ): Plan | undefined => {
19
+ return config.plans.find((plan) => plan.id === id);
20
+ };
21
+
22
+ export const getBestValuePlan = (config: Config): Plan | undefined => {
23
+ return config.plans.find((plan) => plan.isBestValue);
24
+ };
25
+
26
+ export const getPopularPlan = (config: Config): Plan | undefined => {
27
+ return config.plans.find((plan) => plan.isPopular);
28
+ };
29
+
30
+ export const getCreditLimitForPlan = (
31
+ config: Config,
32
+ planId: string
33
+ ): number => {
34
+ const plan = getPlanById(config, planId);
35
+ return plan?.credits ?? 0;
36
+ };
37
+
38
+ export const determinePlanFromCredits = (
39
+ config: Config,
40
+ currentCredits: number
41
+ ): Plan | undefined => {
42
+ const sortedPlans = [...config.plans].sort((a, b) => b.credits - a.credits);
43
+
44
+ for (const plan of sortedPlans) {
45
+ const threshold = plan.credits * 0.5;
46
+ if (currentCredits >= threshold) {
47
+ return plan;
48
+ }
49
+ }
50
+
51
+ return sortedPlans[sortedPlans.length - 1];
52
+ };
@@ -0,0 +1 @@
1
+ export * from "./helpers";
@@ -3,3 +3,4 @@
3
3
  */
4
4
 
5
5
  export * from "./paywall";
6
+ export * from "./config";
package/src/index.ts CHANGED
@@ -83,6 +83,29 @@ export {
83
83
  type PaywallLegalUrls,
84
84
  } from "./domains/paywall";
85
85
 
86
+ // =============================================================================
87
+ // CONFIG DOMAIN
88
+ // =============================================================================
89
+
90
+ export type {
91
+ Plan,
92
+ PlanType,
93
+ PlanMetadata,
94
+ Config,
95
+ ConfigTranslations,
96
+ } from "./domains/config";
97
+
98
+ export { calculatePlanMetadata } from "./domains/config";
99
+
100
+ export {
101
+ getPlanByType,
102
+ getPlanById,
103
+ getBestValuePlan,
104
+ getPopularPlan,
105
+ getCreditLimitForPlan,
106
+ determinePlanFromCredits,
107
+ } from "./domains/config";
108
+
86
109
  // =============================================================================
87
110
  // PRESENTATION LAYER - Premium Details Components
88
111
  // =============================================================================