Teardown

API Reference

Complete API reference for the Teardown React Native SDK.

TeardownCore

The main SDK class that orchestrates all clients.

Constructor

new TeardownCore(options: TeardownCoreOptions)

TeardownCoreOptions

PropertyTypeRequiredDescription
org_idstringYesOrganization ID from dashboard
project_idstringYesProject ID from dashboard
api_keystringYesAPI key from dashboard
environment_slugstringNoEnvironment slug (default: "production")
ingestUrlstringNoCustom ingest API URL for local/staging
storageAdapterStorageAdapterYesStorage adapter instance
deviceAdapterDeviceInfoAdapterYesDevice info adapter instance
notificationAdapterNotificationAdapterNoPush notification adapter instance
forceUpdateForceUpdateClientOptionsNoForce update configuration

Methods

MethodReturnsDescription
setLogLevel(level)voidSet logging verbosity
shutdown()voidCleanup SDK resources

Properties

PropertyTypeDescription
apiApiClientBackend API client
deviceDeviceClientDevice information client
eventsEventsClientEvent tracking client
identityIdentityClientIdentity management client
forceUpdateForceUpdateClientVersion checking client
notificationsNotificationsClient | undefinedPush notifications client (if adapter provided)

IdentityClient

Manages user and device identification.

Methods

MethodReturnsDescription
identify(persona?)AsyncResult<IdentityUser>Identify user/device
refresh()AsyncResult<IdentityUser>Re-identify current user
signOut(options?)AsyncResult<void>Sign out user, preserve device
signOutAll(options?)AsyncResult<void>Sign out and reset device
getIdentifyState()IdentifyStateGet current state
getSessionState()Session | nullGet current session
onIdentifyStateChange(listener)() => voidSubscribe to state changes
shutdown()voidCleanup listeners

Persona

interface Persona {
  user_id?: string;
  email?: string;
  name?: string;
}

Session

interface Session {
  session_id: string;
  device_id: string;
  user_id: string;
  token: string;
}

IdentifyState

type IdentifyState =
  | { type: 'unidentified' }
  | { type: 'identifying' }
  | { type: 'identified'; session: Session; version_info: VersionInfo };

SignOutOptions

interface SignOutOptions {
  // Additional properties to include in the sign out event
  properties?: Record<string, unknown>;
  // Wait for event to be sent before clearing state (default: true)
  waitForEvent?: boolean;
}

ForceUpdateClient

Manages version checking and force updates.

Methods

MethodReturnsDescription
getVersionStatus()VersionStatusGet current version status
onVersionStatusChange(listener)() => voidSubscribe to status changes
shutdown()voidCleanup listeners

ForceUpdateClientOptions

PropertyTypeDefaultDescription
checkIntervalMsnumber300000Min time between checks. 0 = every foreground, -1 = disabled
checkOnForegroundbooleantrueCheck when app foregrounds
identifyAnonymousDevicebooleanfalseCheck when not identified

VersionStatus

type VersionStatus =
  | { type: 'initializing' }
  | { type: 'checking' }
  | { type: 'up_to_date' }
  | { type: 'update_available'; releaseNotes?: string | null }
  | { type: 'update_recommended'; releaseNotes?: string | null }
  | { type: 'update_required'; releaseNotes?: string | null }
  | { type: 'disabled' };

EventsClient

Tracks events to the backend.

Methods

MethodReturnsDescription
track(event, sessionId?)AsyncResult<void>Track a single event
trackBatch(events, sessionId?)AsyncResult<void>Track multiple events

EventPayload

interface EventPayload {
  /** Name of the event (e.g., "button_clicked", "page_viewed") */
  event_name: string;
  /** Type of event */
  event_type?: "action" | "screen_view" | "custom";
  /** Additional properties to attach to the event */
  properties?: Record<string, unknown>;
  /** ISO timestamp. Defaults to current time if not provided */
  timestamp?: string;
}

Usage

const { core } = useTeardown();

// Track a single event
await core.events.track({
  event_name: 'button_clicked',
  event_type: 'action',
  properties: { button_id: 'submit-form' }
});

// Track multiple events
await core.events.trackBatch([
  { event_name: 'page_viewed', event_type: 'screen_view', properties: { page: 'home' } },
  { event_name: 'cta_shown', event_type: 'action' }
]);

NotificationsClient

Manages push notifications across different providers. Only available if notificationAdapter is provided in TeardownCore options.

Methods

MethodReturnsDescription
requestPermissions()Promise<PermissionStatus>Request notification permissions
getToken()Promise<string | null>Get push notification token
onTokenChange(listener)UnsubscribeSubscribe to token changes
onNotificationReceived(listener)UnsubscribeSubscribe to foreground notifications
onNotificationOpened(listener)UnsubscribeSubscribe to notification taps
onDataMessage(listener)UnsubscribeSubscribe to silent/data messages
destroy()voidCleanup resources

Properties

PropertyTypeDescription
platformNotificationPlatformEnumNotification platform (APNS, FCM, EXPO)

PermissionStatus

interface PermissionStatus {
  granted: boolean;
  canAskAgain: boolean;
}

PushNotification

interface PushNotification {
  title?: string;
  body?: string;
  data?: Record<string, unknown>;
}

DataMessage

interface DataMessage {
  data: Record<string, unknown>;
}

NotificationPlatformEnum

enum NotificationPlatformEnum {
  APNS = "APNS",  // Apple Push Notification Service
  FCM = "FCM",    // Firebase Cloud Messaging
  EXPO = "EXPO",  // Expo Push Notifications
}

Usage

const { core } = useTeardown();

if (core.notifications) {
  // Request permissions
  const status = await core.notifications.requestPermissions();

  // Get token for backend
  const token = await core.notifications.getToken();

  // Listen for foreground notifications
  const unsub = core.notifications.onNotificationReceived((notification) => {
    console.log('Notification:', notification.title);
  });

  // Cleanup
  unsub();
}

DeviceClient

Collects device information.

Methods

MethodReturnsDescription
getDeviceId()Promise<string>Get stable device UUID
getDeviceInfo()Promise<DeviceInfo>Get full device info
reset()voidClear stored deviceId (new ID on next call)

DeviceInfo

interface DeviceInfo {
  timestamp?: Date;
  os: OSInfo;
  hardware: HardwareInfo;
  application: ApplicationInfo;
  update: DeviceUpdateInfo | null;
  notifications?: NotificationsInfo;
}

StorageAdapter

Abstract class for storage implementations.

Methods

MethodReturnsDescription
createStorage(key)SupportedStorageCreate namespaced storage

SupportedStorage

interface SupportedStorage {
  preload(): void;
  getItem(key: string): string | null;
  setItem(key: string, value: string): void;
  removeItem(key: string): void;
  clear(): void;
  keys(): string[];
}

DeviceInfoAdapter

Interface for device information adapters.

Properties

PropertyTypeDescription
applicationInfoApplicationInfoApp version info
hardwareInfoHardwareInfoDevice hardware info
osInfoOSInfoOperating system info

ApplicationInfo

interface ApplicationInfo {
  version: string;
  build_number: number;
}

HardwareInfo

interface HardwareInfo {
  device_name: string;
  device_brand: string;
  device_type: string;
}

OSInfo

interface OSInfo {
  platform: DevicePlatformEnum;
  name: string;
  version: string;
}

DevicePlatformEnum

enum DevicePlatformEnum {
  IOS = "IOS",
  ANDROID = "ANDROID",
  WEB = "WEB",
  WINDOWS = "WINDOWS",
  MACOS = "MACOS",
  LINUX = "LINUX",
  UNKNOWN = "UNKNOWN",
  // ... and more
}

AsyncResult

Type-safe result type for async operations.

type AsyncResult<T> =
  | { success: true; data: T }
  | { success: false; error: string };

Usage

const result = await core.identity.identify({ user_id: '123' });

if (result.success) {
  console.log(result.data.session_id);
} else {
  console.error(result.error);
}