react-native-adapty
Version:
Adapty React Native SDK
100 lines (91 loc) • 2.44 kB
text/typescript
import type { EmitterSubscription } from 'react-native';
import type { AdaptyProfile, AdaptyInstallationDetails } from '@/types';
import type { AdaptyError } from '@/adapty-error';
/**
* Valid list of callable bridge handlers
* Must be the same as
* - iOS RNAConstants.MethodName
* @internal
*/
export const MethodNames = [
'activate',
'adapty_ui_activate',
'adapty_ui_create_paywall_view',
'adapty_ui_dismiss_paywall_view',
'adapty_ui_present_paywall_view',
'adapty_ui_show_dialog',
'adapty_ui_create_onboarding_view',
'adapty_ui_dismiss_onboarding_view',
'adapty_ui_present_onboarding_view',
'create_web_paywall_url',
'get_current_installation_status',
'is_activated',
'get_paywall',
'get_paywall_for_default_audience',
'get_paywall_products',
'get_onboarding',
'get_onboarding_for_default_audience',
'get_profile',
'identify',
'log_show_paywall',
'logout',
'make_purchase',
'open_web_paywall',
'present_code_redemption_sheet',
'report_transaction',
'restore_purchases',
'set_fallback',
'set_integration_identifiers',
'set_log_level',
'update_attribution_data',
'update_collecting_refund_data_consent',
'update_profile',
'update_refund_preference',
] as const;
export type MethodName = (typeof MethodNames)[number];
/**
* Types of values that can be passed
* to the bridge without corruption
*/
export type Serializable =
| string
| number
| boolean
| string[]
| null
| undefined;
/**
* Interface of error that emit from native SDK
*/
export interface AdaptyNativeError {
adaptyCode: number;
message: string;
detail?: string | undefined;
}
/**
* Interface of error that was raised by native bridge
*/
export interface AdaptyBridgeError {
errorType: string;
name?: string;
type?: string;
underlyingError?: string;
description?: string;
}
interface EventMap {
onLatestProfileLoad: string;
onInstallationDetailsSuccess: string;
onInstallationDetailsFail: string;
}
export type UserEventName = keyof EventMap;
export type AddListenerGeneric<E extends UserEventName, Data> = (
event: E,
callback: (data: Data) => void | Promise<void>,
) => EmitterSubscription;
export type AddListenerFn =
| AddListenerGeneric<'onLatestProfileLoad', AdaptyProfile>
| AddListenerGeneric<
'onInstallationDetailsSuccess',
AdaptyInstallationDetails
>
| AddListenerGeneric<'onInstallationDetailsFail', AdaptyError>;