@tryheliumai/paywall-sdk-react-native 3.0.3 → 3.0.6
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/PaywallSdkReactNative.podspec +1 -1
- package/ios/HeliumSwiftInterface.swift +99 -4
- package/ios/RCTHeliumBridge.m +14 -0
- package/lib/commonjs/handlers/revenuecat.js +6 -2
- package/lib/commonjs/handlers/revenuecat.js.map +1 -1
- package/lib/commonjs/index.js +18 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/native-interface.js +85 -34
- package/lib/commonjs/native-interface.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/handlers/revenuecat.js +7 -2
- package/lib/module/handlers/revenuecat.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/native-interface.js +81 -33
- package/lib/module/native-interface.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/src/handlers/revenuecat.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +1 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/native-interface.d.ts +9 -0
- package/lib/typescript/commonjs/src/native-interface.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types.d.ts +5 -3
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
- package/lib/typescript/module/src/handlers/revenuecat.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +1 -1
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/native-interface.d.ts +9 -0
- package/lib/typescript/module/src/native-interface.d.ts.map +1 -1
- package/lib/typescript/module/src/types.d.ts +5 -3
- package/lib/typescript/module/src/types.d.ts.map +1 -1
- package/package.json +1 -9
- package/src/handlers/revenuecat.ts +7 -2
- package/src/index.ts +3 -0
- package/src/native-interface.tsx +106 -44
- package/src/types.ts +5 -4
package/src/native-interface.tsx
CHANGED
|
@@ -37,10 +37,12 @@ export const initialize = async (config: HeliumConfig) => {
|
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const purchaseHandler =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const purchaseHandler = config.purchaseConfig
|
|
41
|
+
? {
|
|
42
|
+
makePurchase: config.purchaseConfig.makePurchase,
|
|
43
|
+
restorePurchases: config.purchaseConfig.restorePurchases,
|
|
44
|
+
}
|
|
45
|
+
: null;
|
|
44
46
|
|
|
45
47
|
// Update download status to inProgress
|
|
46
48
|
updateDownloadStatus('inProgress');
|
|
@@ -62,6 +64,9 @@ export const initialize = async (config: HeliumConfig) => {
|
|
|
62
64
|
updateDownloadStatus('failed');
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
// Handle internal event logic first
|
|
68
|
+
handlePaywallEvent(event);
|
|
69
|
+
|
|
65
70
|
// Forward all events to the callback provided in config
|
|
66
71
|
config.onHeliumPaywallEvent(event);
|
|
67
72
|
}
|
|
@@ -75,30 +80,33 @@ export const initialize = async (config: HeliumConfig) => {
|
|
|
75
80
|
}
|
|
76
81
|
);
|
|
77
82
|
|
|
78
|
-
// Set up purchase event
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
// Set up purchase event listeners only if we have a purchase handler
|
|
84
|
+
if (purchaseHandler) {
|
|
85
|
+
// Set up purchase event listener using the determined handler
|
|
86
|
+
heliumEventEmitter.addListener(
|
|
87
|
+
'helium_make_purchase',
|
|
88
|
+
async (event: { productId: string; transactionId: string }) => {
|
|
89
|
+
const result = await purchaseHandler.makePurchase(event.productId);
|
|
90
|
+
HeliumBridge.handlePurchaseResponse({
|
|
91
|
+
transactionId: event.transactionId,
|
|
92
|
+
status: result.status,
|
|
93
|
+
error: result.error,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
);
|
|
90
97
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
// Set up restore purchases event listener using the determined handler
|
|
99
|
+
heliumEventEmitter.addListener(
|
|
100
|
+
'helium_restore_purchases',
|
|
101
|
+
async (event: { transactionId: string }) => {
|
|
102
|
+
const success = await purchaseHandler.restorePurchases();
|
|
103
|
+
HeliumBridge.handleRestoreResponse({
|
|
104
|
+
transactionId: event.transactionId,
|
|
105
|
+
status: success ? 'restored' : 'failed',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
}
|
|
102
110
|
|
|
103
111
|
let fallbackBundleUrlString;
|
|
104
112
|
let fallbackBundleString;
|
|
@@ -128,12 +136,16 @@ export const initialize = async (config: HeliumConfig) => {
|
|
|
128
136
|
apiKey: config.apiKey,
|
|
129
137
|
customUserId: config.customUserId || null,
|
|
130
138
|
customAPIEndpoint: config.customAPIEndpoint || null,
|
|
131
|
-
customUserTraits:
|
|
132
|
-
config.customUserTraits == null ? {} : config.customUserTraits
|
|
139
|
+
customUserTraits: convertBooleansToMarkers(
|
|
140
|
+
config.customUserTraits == null ? {} : config.customUserTraits
|
|
141
|
+
),
|
|
133
142
|
revenueCatAppUserId: config.revenueCatAppUserId,
|
|
134
143
|
fallbackBundleUrlString: fallbackBundleUrlString,
|
|
135
144
|
fallbackBundleString: fallbackBundleString,
|
|
136
|
-
paywallLoadingConfig:
|
|
145
|
+
paywallLoadingConfig: convertBooleansToMarkers(
|
|
146
|
+
config.paywallLoadingConfig
|
|
147
|
+
),
|
|
148
|
+
useDefaultDelegate: !config.purchaseConfig,
|
|
137
149
|
},
|
|
138
150
|
{}
|
|
139
151
|
);
|
|
@@ -165,7 +177,10 @@ export const presentUpsell = ({
|
|
|
165
177
|
try {
|
|
166
178
|
paywallEventHandlers = eventHandlers;
|
|
167
179
|
presentOnFallback = onFallback;
|
|
168
|
-
HeliumBridge.presentUpsell(
|
|
180
|
+
HeliumBridge.presentUpsell(
|
|
181
|
+
triggerName,
|
|
182
|
+
convertBooleansToMarkers(customPaywallTraits) || null
|
|
183
|
+
);
|
|
169
184
|
} catch (error) {
|
|
170
185
|
console.log('[Helium] Present error', error);
|
|
171
186
|
paywallEventHandlers = undefined;
|
|
@@ -196,10 +211,6 @@ function callPaywallEventHandlers(event: HeliumPaywallEvent) {
|
|
|
196
211
|
paywallName: event.paywallName ?? 'unknown',
|
|
197
212
|
isSecondTry: event.isSecondTry ?? false,
|
|
198
213
|
});
|
|
199
|
-
if (!event.isSecondTry) {
|
|
200
|
-
paywallEventHandlers = undefined;
|
|
201
|
-
}
|
|
202
|
-
presentOnFallback = undefined;
|
|
203
214
|
break;
|
|
204
215
|
case 'paywallDismissed':
|
|
205
216
|
paywallEventHandlers?.onDismissed?.({
|
|
@@ -218,19 +229,30 @@ function callPaywallEventHandlers(event: HeliumPaywallEvent) {
|
|
|
218
229
|
isSecondTry: event.isSecondTry ?? false,
|
|
219
230
|
});
|
|
220
231
|
break;
|
|
221
|
-
case 'paywallSkipped':
|
|
222
|
-
paywallEventHandlers = undefined;
|
|
223
|
-
presentOnFallback = undefined;
|
|
224
|
-
break;
|
|
225
|
-
case 'paywallOpenFailed':
|
|
226
|
-
paywallEventHandlers = undefined;
|
|
227
|
-
presentOnFallback?.();
|
|
228
|
-
presentOnFallback = undefined;
|
|
229
|
-
break;
|
|
230
232
|
}
|
|
231
233
|
}
|
|
232
234
|
}
|
|
233
235
|
|
|
236
|
+
function handlePaywallEvent(event: HeliumPaywallEvent) {
|
|
237
|
+
switch (event.type) {
|
|
238
|
+
case 'paywallClose':
|
|
239
|
+
if (!event.isSecondTry) {
|
|
240
|
+
paywallEventHandlers = undefined;
|
|
241
|
+
}
|
|
242
|
+
presentOnFallback = undefined;
|
|
243
|
+
break;
|
|
244
|
+
case 'paywallSkipped':
|
|
245
|
+
paywallEventHandlers = undefined;
|
|
246
|
+
presentOnFallback = undefined;
|
|
247
|
+
break;
|
|
248
|
+
case 'paywallOpenFailed':
|
|
249
|
+
paywallEventHandlers = undefined;
|
|
250
|
+
presentOnFallback?.();
|
|
251
|
+
presentOnFallback = undefined;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
234
256
|
export const hideUpsell = () => {
|
|
235
257
|
HeliumBridge.hideUpsell();
|
|
236
258
|
};
|
|
@@ -273,7 +295,47 @@ export const handleDeepLink = async (url: string | null): Promise<boolean> => {
|
|
|
273
295
|
});
|
|
274
296
|
};
|
|
275
297
|
|
|
298
|
+
export const setRevenueCatAppUserId = (rcAppUserId: string) => {
|
|
299
|
+
HeliumBridge.setRevenueCatAppUserId(rcAppUserId);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Checks if the user has any active subscription (including non-renewable)
|
|
304
|
+
*/
|
|
305
|
+
export const hasAnyActiveSubscription = async (): Promise<boolean> => {
|
|
306
|
+
return HeliumBridge.hasAnyActiveSubscription();
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Checks if the user has any entitlement
|
|
311
|
+
*/
|
|
312
|
+
export const hasAnyEntitlement = async (): Promise<boolean> => {
|
|
313
|
+
return HeliumBridge.hasAnyEntitlement();
|
|
314
|
+
};
|
|
315
|
+
|
|
276
316
|
export const HELIUM_CTA_NAMES = {
|
|
277
317
|
SCHEDULE_CALL: 'schedule_call',
|
|
278
318
|
SUBSCRIBE_BUTTON: 'subscribe_button',
|
|
279
319
|
};
|
|
320
|
+
|
|
321
|
+
function convertBooleansToMarkers(
|
|
322
|
+
input: Record<string, any> | undefined
|
|
323
|
+
): Record<string, any> | undefined {
|
|
324
|
+
if (!input) return undefined;
|
|
325
|
+
|
|
326
|
+
const result: Record<string, any> = {};
|
|
327
|
+
for (const [key, value] of Object.entries(input)) {
|
|
328
|
+
result[key] = convertValueBooleansToMarkers(value);
|
|
329
|
+
}
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
function convertValueBooleansToMarkers(value: any): any {
|
|
333
|
+
if (typeof value === 'boolean') {
|
|
334
|
+
return value ? '__helium_rn_bool_true__' : '__helium_rn_bool_false__';
|
|
335
|
+
} else if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
336
|
+
return convertBooleansToMarkers(value);
|
|
337
|
+
} else if (value && Array.isArray(value)) {
|
|
338
|
+
return value.map(convertValueBooleansToMarkers);
|
|
339
|
+
}
|
|
340
|
+
return value;
|
|
341
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -21,9 +21,6 @@ export type HeliumDownloadStatus =
|
|
|
21
21
|
export interface HeliumPurchaseConfig {
|
|
22
22
|
makePurchase: (productId: string) => Promise<HeliumPurchaseResult>;
|
|
23
23
|
restorePurchases: () => Promise<boolean>;
|
|
24
|
-
|
|
25
|
-
/** Optional RevenueCat API Key. If not provided, RevenueCat must be configured elsewhere. */
|
|
26
|
-
apiKey?: string;
|
|
27
24
|
}
|
|
28
25
|
|
|
29
26
|
// Helper function for creating Custom Purchase Config
|
|
@@ -136,6 +133,10 @@ export type HeliumPaywallEvent = {
|
|
|
136
133
|
* @deprecated Use `productId` instead.
|
|
137
134
|
*/
|
|
138
135
|
productKey?: string;
|
|
136
|
+
buttonName?: string;
|
|
137
|
+
/**
|
|
138
|
+
* @deprecated Use `buttonName` instead.
|
|
139
|
+
*/
|
|
139
140
|
ctaName?: string;
|
|
140
141
|
paywallDownloadTimeTakenMS?: number;
|
|
141
142
|
templateDownloadTimeTakenMS?: number;
|
|
@@ -169,7 +170,7 @@ export interface HeliumConfig {
|
|
|
169
170
|
/** Your Helium API Key */
|
|
170
171
|
apiKey: string;
|
|
171
172
|
/** Configuration for handling purchases. Can be custom functions or a pre-built handler config. */
|
|
172
|
-
purchaseConfig
|
|
173
|
+
purchaseConfig?: HeliumPurchaseConfig;
|
|
173
174
|
/** Callback for receiving all Helium paywall events. */
|
|
174
175
|
onHeliumPaywallEvent: (event: HeliumPaywallEvent) => void;
|
|
175
176
|
|