@umituz/react-native-subscription 2.27.11 → 2.27.12
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/index.ts +6 -0
- package/src/init/createSubscriptionInitModule.ts +121 -0
- package/src/init/index.ts +10 -0
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.12",
|
|
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",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription Init Module Factory
|
|
3
|
+
* Creates a ready-to-use InitModule for app initialization
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { initializeSubscription, type SubscriptionInitConfig } from '../infrastructure/services/SubscriptionInitializer';
|
|
7
|
+
|
|
8
|
+
declare const __DEV__: boolean;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* InitModule interface (from @umituz/react-native-design-system)
|
|
12
|
+
*/
|
|
13
|
+
export interface InitModule {
|
|
14
|
+
name: string;
|
|
15
|
+
init: () => Promise<boolean>;
|
|
16
|
+
critical?: boolean;
|
|
17
|
+
dependsOn?: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SubscriptionInitModuleConfig extends Omit<SubscriptionInitConfig, 'apiKey'> {
|
|
21
|
+
/**
|
|
22
|
+
* RevenueCat API key getter function
|
|
23
|
+
* Returns the API key or undefined if not available
|
|
24
|
+
*/
|
|
25
|
+
getApiKey: () => string | undefined;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Optional RevenueCat test store key getter
|
|
29
|
+
*/
|
|
30
|
+
getTestStoreKey?: () => string | undefined;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Whether this module is critical for app startup
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
critical?: boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Module dependencies
|
|
40
|
+
* @default ["auth"]
|
|
41
|
+
*/
|
|
42
|
+
dependsOn?: string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates a Subscription initialization module for use with createAppInitializer
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { createAppInitializer } from "@umituz/react-native-design-system";
|
|
51
|
+
* import { createFirebaseInitModule } from "@umituz/react-native-firebase";
|
|
52
|
+
* import { createAuthInitModule } from "@umituz/react-native-auth";
|
|
53
|
+
* import { createSubscriptionInitModule } from "@umituz/react-native-subscription";
|
|
54
|
+
*
|
|
55
|
+
* export const initializeApp = createAppInitializer({
|
|
56
|
+
* modules: [
|
|
57
|
+
* createFirebaseInitModule(),
|
|
58
|
+
* createAuthInitModule({ userCollection: "users" }),
|
|
59
|
+
* createSubscriptionInitModule({
|
|
60
|
+
* getApiKey: () => getRevenueCatApiKey(),
|
|
61
|
+
* entitlementId: "premium",
|
|
62
|
+
* credits: {
|
|
63
|
+
* collectionName: "credits",
|
|
64
|
+
* creditLimit: 500,
|
|
65
|
+
* enableFreeCredits: true,
|
|
66
|
+
* freeCredits: 1,
|
|
67
|
+
* },
|
|
68
|
+
* }),
|
|
69
|
+
* ],
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function createSubscriptionInitModule(
|
|
74
|
+
config: SubscriptionInitModuleConfig
|
|
75
|
+
): InitModule {
|
|
76
|
+
const {
|
|
77
|
+
getApiKey,
|
|
78
|
+
getTestStoreKey,
|
|
79
|
+
critical = true,
|
|
80
|
+
dependsOn = ['auth'],
|
|
81
|
+
...subscriptionConfig
|
|
82
|
+
} = config;
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
name: 'subscription',
|
|
86
|
+
critical,
|
|
87
|
+
dependsOn,
|
|
88
|
+
init: async () => {
|
|
89
|
+
try {
|
|
90
|
+
const apiKey = getApiKey();
|
|
91
|
+
|
|
92
|
+
if (!apiKey) {
|
|
93
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
94
|
+
console.log('[createSubscriptionInitModule] No API key - skipping');
|
|
95
|
+
}
|
|
96
|
+
return true; // Not an error, just skip
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const testStoreKey = getTestStoreKey?.();
|
|
100
|
+
|
|
101
|
+
await initializeSubscription({
|
|
102
|
+
apiKey,
|
|
103
|
+
testStoreKey,
|
|
104
|
+
...subscriptionConfig,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
108
|
+
console.log('[createSubscriptionInitModule] Subscription initialized');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return true;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
114
|
+
console.error('[createSubscriptionInitModule] Error:', error);
|
|
115
|
+
}
|
|
116
|
+
// Continue on error - subscription is not critical for app launch
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|