@tryheliumai/paywall-sdk-react-native 3.0.6 → 3.0.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/PaywallSdkReactNative.podspec +1 -1
- package/ios/HeliumSwiftInterface.swift +55 -40
- package/ios/RCTHeliumBridge.m +19 -5
- package/lib/commonjs/HeliumExperimentInfo.types.js +2 -0
- package/lib/commonjs/HeliumExperimentInfo.types.js.map +1 -0
- package/lib/commonjs/index.js +24 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/native-interface.js +82 -21
- package/lib/commonjs/native-interface.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/HeliumExperimentInfo.types.js +2 -0
- package/lib/module/HeliumExperimentInfo.types.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/native-interface.js +77 -20
- package/lib/module/native-interface.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/src/HeliumExperimentInfo.types.d.ts +92 -0
- package/lib/typescript/commonjs/src/HeliumExperimentInfo.types.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +3 -2
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/native-interface.d.ts +22 -0
- package/lib/typescript/commonjs/src/native-interface.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types.d.ts +26 -2
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
- package/lib/typescript/module/src/HeliumExperimentInfo.types.d.ts +92 -0
- package/lib/typescript/module/src/HeliumExperimentInfo.types.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +3 -2
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/native-interface.d.ts +22 -0
- package/lib/typescript/module/src/native-interface.d.ts.map +1 -1
- package/lib/typescript/module/src/types.d.ts +26 -2
- package/lib/typescript/module/src/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/HeliumExperimentInfo.types.ts +109 -0
- package/src/index.ts +12 -0
- package/src/native-interface.tsx +95 -29
- package/src/types.ts +30 -2
package/src/native-interface.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
PaywallEventHandlers,
|
|
13
13
|
HeliumPaywallEvent,
|
|
14
14
|
} from './types';
|
|
15
|
+
import type { ExperimentInfo } from './HeliumExperimentInfo.types';
|
|
15
16
|
|
|
16
17
|
const { HeliumBridge } = NativeModules;
|
|
17
18
|
const heliumEventEmitter = new NativeEventEmitter(HeliumBridge);
|
|
@@ -162,34 +163,20 @@ export const presentUpsell = ({
|
|
|
162
163
|
eventHandlers,
|
|
163
164
|
customPaywallTraits,
|
|
164
165
|
}: PresentUpsellParams) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
presentOnFallback = onFallback;
|
|
180
|
-
HeliumBridge.presentUpsell(
|
|
181
|
-
triggerName,
|
|
182
|
-
convertBooleansToMarkers(customPaywallTraits) || null
|
|
183
|
-
);
|
|
184
|
-
} catch (error) {
|
|
185
|
-
console.log('[Helium] Present error', error);
|
|
186
|
-
paywallEventHandlers = undefined;
|
|
187
|
-
presentOnFallback = undefined;
|
|
188
|
-
onFallback?.();
|
|
189
|
-
HeliumBridge.fallbackOpenOrCloseEvent(triggerName, true, 'presented');
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
);
|
|
166
|
+
try {
|
|
167
|
+
paywallEventHandlers = eventHandlers;
|
|
168
|
+
presentOnFallback = onFallback;
|
|
169
|
+
HeliumBridge.presentUpsell(
|
|
170
|
+
triggerName,
|
|
171
|
+
convertBooleansToMarkers(customPaywallTraits) || null
|
|
172
|
+
);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.log('[Helium] presentUpsell error', error);
|
|
175
|
+
paywallEventHandlers = undefined;
|
|
176
|
+
presentOnFallback = undefined;
|
|
177
|
+
onFallback?.();
|
|
178
|
+
HeliumBridge.fallbackOpenOrCloseEvent(triggerName, true, 'presented');
|
|
179
|
+
}
|
|
193
180
|
};
|
|
194
181
|
|
|
195
182
|
function callPaywallEventHandlers(event: HeliumPaywallEvent) {
|
|
@@ -229,6 +216,26 @@ function callPaywallEventHandlers(event: HeliumPaywallEvent) {
|
|
|
229
216
|
isSecondTry: event.isSecondTry ?? false,
|
|
230
217
|
});
|
|
231
218
|
break;
|
|
219
|
+
case 'paywallOpenFailed':
|
|
220
|
+
paywallEventHandlers?.onOpenFailed?.({
|
|
221
|
+
type: 'paywallOpenFailed',
|
|
222
|
+
triggerName: event.triggerName ?? 'unknown',
|
|
223
|
+
paywallName: event.paywallName ?? 'unknown',
|
|
224
|
+
error: event.error ?? 'Unknown error',
|
|
225
|
+
paywallUnavailableReason: event.paywallUnavailableReason,
|
|
226
|
+
isSecondTry: event.isSecondTry ?? false,
|
|
227
|
+
});
|
|
228
|
+
break;
|
|
229
|
+
case 'customPaywallAction':
|
|
230
|
+
paywallEventHandlers?.onCustomPaywallAction?.({
|
|
231
|
+
type: 'customPaywallAction',
|
|
232
|
+
triggerName: event.triggerName ?? 'unknown',
|
|
233
|
+
paywallName: event.paywallName ?? 'unknown',
|
|
234
|
+
actionName: event.customPaywallActionName ?? 'unknown',
|
|
235
|
+
params: event.customPaywallActionParams ?? {},
|
|
236
|
+
isSecondTry: event.isSecondTry ?? false,
|
|
237
|
+
});
|
|
238
|
+
break;
|
|
232
239
|
}
|
|
233
240
|
}
|
|
234
241
|
}
|
|
@@ -247,7 +254,15 @@ function handlePaywallEvent(event: HeliumPaywallEvent) {
|
|
|
247
254
|
break;
|
|
248
255
|
case 'paywallOpenFailed':
|
|
249
256
|
paywallEventHandlers = undefined;
|
|
250
|
-
|
|
257
|
+
const unavailableReason = event.paywallUnavailableReason;
|
|
258
|
+
if (
|
|
259
|
+
event.triggerName &&
|
|
260
|
+
unavailableReason !== 'alreadyPresented' &&
|
|
261
|
+
unavailableReason !== 'secondTryNoMatch'
|
|
262
|
+
) {
|
|
263
|
+
console.log('[Helium] paywall open failed', unavailableReason);
|
|
264
|
+
presentOnFallback?.();
|
|
265
|
+
}
|
|
251
266
|
presentOnFallback = undefined;
|
|
252
267
|
break;
|
|
253
268
|
}
|
|
@@ -313,6 +328,57 @@ export const hasAnyEntitlement = async (): Promise<boolean> => {
|
|
|
313
328
|
return HeliumBridge.hasAnyEntitlement();
|
|
314
329
|
};
|
|
315
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Get experiment allocation info for a specific trigger
|
|
333
|
+
*
|
|
334
|
+
* @param trigger The trigger name to get experiment info for
|
|
335
|
+
* @returns ExperimentInfo if the trigger has experiment data, undefined otherwise
|
|
336
|
+
*/
|
|
337
|
+
export const getExperimentInfoForTrigger = async (
|
|
338
|
+
trigger: string
|
|
339
|
+
): Promise<ExperimentInfo | undefined> => {
|
|
340
|
+
return new Promise((resolve) => {
|
|
341
|
+
HeliumBridge.getExperimentInfoForTrigger(trigger, (success: boolean, data: any) => {
|
|
342
|
+
if (!success) {
|
|
343
|
+
resolve(undefined);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
resolve(data as ExperimentInfo);
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Reset Helium entirely so you can call initialize again. Only for advanced use cases.
|
|
353
|
+
*/
|
|
354
|
+
export const resetHelium = () => {
|
|
355
|
+
HeliumBridge.resetHelium();
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Set custom strings to show in the dialog that Helium will display if a "Restore Purchases" action is not successful.
|
|
360
|
+
* Note that these strings will not be localized by Helium for you.
|
|
361
|
+
*/
|
|
362
|
+
export const setCustomRestoreFailedStrings = (
|
|
363
|
+
customTitle?: string,
|
|
364
|
+
customMessage?: string,
|
|
365
|
+
customCloseButtonText?: string
|
|
366
|
+
) => {
|
|
367
|
+
HeliumBridge.setCustomRestoreFailedStrings(
|
|
368
|
+
customTitle,
|
|
369
|
+
customMessage,
|
|
370
|
+
customCloseButtonText
|
|
371
|
+
);
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Disable the default dialog that Helium will display if a "Restore Purchases" action is not successful.
|
|
376
|
+
* You can handle this yourself if desired by listening for the PurchaseRestoreFailedEvent.
|
|
377
|
+
*/
|
|
378
|
+
export const disableRestoreFailedDialog = () => {
|
|
379
|
+
HeliumBridge.disableRestoreFailedDialog();
|
|
380
|
+
};
|
|
381
|
+
|
|
316
382
|
export const HELIUM_CTA_NAMES = {
|
|
317
383
|
SCHEDULE_CALL: 'schedule_call',
|
|
318
384
|
SUBSCRIBE_BUTTON: 'subscribe_button',
|
package/src/types.ts
CHANGED
|
@@ -69,6 +69,8 @@ export interface PaywallEventHandlers {
|
|
|
69
69
|
onClose?: (event: PaywallCloseEvent) => void;
|
|
70
70
|
onDismissed?: (event: PaywallDismissedEvent) => void;
|
|
71
71
|
onPurchaseSucceeded?: (event: PurchaseSucceededEvent) => void;
|
|
72
|
+
onOpenFailed?: (event: PaywallOpenFailedEvent) => void;
|
|
73
|
+
onCustomPaywallAction?: (event: CustomPaywallActionEvent) => void;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
// Typed event interfaces
|
|
@@ -102,6 +104,24 @@ export interface PurchaseSucceededEvent {
|
|
|
102
104
|
isSecondTry: boolean;
|
|
103
105
|
}
|
|
104
106
|
|
|
107
|
+
export interface PaywallOpenFailedEvent {
|
|
108
|
+
type: 'paywallOpenFailed';
|
|
109
|
+
triggerName: string;
|
|
110
|
+
paywallName: string;
|
|
111
|
+
error: string;
|
|
112
|
+
paywallUnavailableReason?: string;
|
|
113
|
+
isSecondTry: boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface CustomPaywallActionEvent {
|
|
117
|
+
type: 'customPaywallAction';
|
|
118
|
+
triggerName: string;
|
|
119
|
+
paywallName: string;
|
|
120
|
+
actionName: string;
|
|
121
|
+
params: Record<string, any>;
|
|
122
|
+
isSecondTry: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
105
125
|
export type HeliumPaywallEvent = {
|
|
106
126
|
type:
|
|
107
127
|
| 'paywallOpen'
|
|
@@ -121,7 +141,9 @@ export type HeliumPaywallEvent = {
|
|
|
121
141
|
| 'initializeStart'
|
|
122
142
|
| 'paywallsDownloadSuccess'
|
|
123
143
|
| 'paywallsDownloadError'
|
|
124
|
-
| 'paywallWebViewRendered'
|
|
144
|
+
| 'paywallWebViewRendered'
|
|
145
|
+
| 'customPaywallAction'
|
|
146
|
+
| 'userAllocated';
|
|
125
147
|
triggerName?: string;
|
|
126
148
|
paywallName?: string;
|
|
127
149
|
/**
|
|
@@ -155,6 +177,9 @@ export type HeliumPaywallEvent = {
|
|
|
155
177
|
* Unix timestamp in seconds
|
|
156
178
|
*/
|
|
157
179
|
timestamp?: number;
|
|
180
|
+
paywallUnavailableReason?: string;
|
|
181
|
+
customPaywallActionName?: string;
|
|
182
|
+
customPaywallActionParams?: Record<string, any>;
|
|
158
183
|
};
|
|
159
184
|
|
|
160
185
|
export type PresentUpsellParams = {
|
|
@@ -169,7 +194,10 @@ export type PresentUpsellParams = {
|
|
|
169
194
|
export interface HeliumConfig {
|
|
170
195
|
/** Your Helium API Key */
|
|
171
196
|
apiKey: string;
|
|
172
|
-
/**
|
|
197
|
+
/**
|
|
198
|
+
* Configuration for handling purchases. Can be custom functions or a pre-built handler config.
|
|
199
|
+
* If not provided, Helium will handle purchases for you.
|
|
200
|
+
*/
|
|
173
201
|
purchaseConfig?: HeliumPurchaseConfig;
|
|
174
202
|
/** Callback for receiving all Helium paywall events. */
|
|
175
203
|
onHeliumPaywallEvent: (event: HeliumPaywallEvent) => void;
|