# React Native API Reference

## WarpLink

The main entry point. Exported from `@warplink/react-native`.

```typescript
import { WarpLink } from '@warplink/react-native';
```

### configure(options)

```typescript
configure(options: WarpLinkConfig): Promise<void>
```

Initialize the SDK. The key format is validated synchronously; the returned promise resolves after native configuration completes, including the automatic cold-start and deferred deep link dispatch.

| Parameter | Type | Description |
|-----------|------|-------------|
| `options` | `WarpLinkConfig` | Configuration with your SDK key, the `onLink` callback, and optional settings. |

When `onLink` is set, `configure()` wires `getInitialDeepLink` (cold start), `onDeepLink` (warm start), and `checkDeferredDeepLink` (deferred) into that single callback. Disambiguate the deferred case with `isDeferred`. Set `automaticDeepLinks` or `automaticDeferredDeepLinks` to `false` to disable either piece.

**Does not throw.** A malformed SDK key is reported through your `onLink` callback as an `{ error }` event with code `E_INVALID_API_KEY_FORMAT`, and always logs a warning. The SDK stays unconfigured. iOS and Android behave the same way.

Call it once at startup. A second call with the same key and options keeps the session and takes the new `onLink`. If no check is running and the check has no answer yet, it asks the native check once more, at most once a minute. The native SDK decides whether that sends a request, so a wait that is still running holds it back. A different key, different options, or adding or removing `onLink` start a new session.

### handleDeepLink(url)

```typescript
handleDeepLink(url: string): Promise<WarpLinkDeepLink | null>
```

Resolve a deep link URL to its link data.

**Errors:** `E_NOT_CONFIGURED`, `E_INVALID_URL`, `E_LINK_NOT_FOUND`, `E_PASSWORD_REQUIRED`, `E_NETWORK_ERROR`, `E_SERVER_ERROR`, `E_INVALID_API_KEY`, `E_DECODING_ERROR`

### checkDeferredDeepLink()

```typescript
checkDeferredDeepLink(): Promise<WarpLinkDeepLink | null>
```

Check for a deferred deep link on first launch. Returns `null` if no match found. On subsequent launches, returns the cached result.

"First launch" means the first launch of the current install. A reinstall is a new install and runs the check again, with `is_reinstall` set on the request. See [App Reinstall](https://warplink.app/docs/sdks/react-native/deferred#app-reinstall).

**Errors:** `E_NOT_CONFIGURED`, `E_NETWORK_ERROR`, `E_SERVER_ERROR`, `E_INVALID_API_KEY`, `E_KEY_APP_MISMATCH`, `E_DECODING_ERROR`

### getAttributionResult()

```typescript
getAttributionResult(): Promise<AttributionResult | null>
```

Get install attribution data. Returns `null` if no attribution match found.

### redeemInvitation(text)

```typescript
redeemInvitation(text: string): Promise<WarpLinkDeepLink | null>
```

Redeem a referral invitation the person pasted. This call reads nothing from the clipboard: the text reaches it only through this call.

Resolves with the matched link, also cached as the attribution result. Resolves with `null` when the text is not an invitation or matched nothing; nothing is confirmed then. An invitation that is invalid or expired rejects with a `WarpLinkError` whose message says how to open the link again. After a network failure the native SDK keeps the invitation and tries again on a later launch, a bounded number of times. That later result is delivered through `getAttributionResult()` and `claimReferral`, not through `onLink`.

**Errors:** `E_NOT_CONFIGURED`, `E_NETWORK_ERROR`, `E_SERVER_ERROR`

### claimReferral(installerId)

```typescript
claimReferral(installerId: string): Promise<ReferralClaimResult>
```

Credit the referral behind this install to the person who just signed up. `installerId` is your own stable id for them, 1 to 128 characters. The call is safe to repeat: the same id gets the same answer and is never credited twice. A status of `none` is an ordinary answer, not an error.

| Property | Type | Description |
|----------|------|-------------|
| `status` | `'claimed' \| 'flagged' \| 'ignored' \| 'none'` | The outcome of the claim. |
| `referralId` | `string \| null` | The referral's id. `null` for `none`. |
| `linkId`, `linkUrl` | `string \| null` | The link the referral came from. |
| `matchMethod` | `MatchMethod \| null` | How the referral was matched. |
| `isExact` | `boolean` | `true` when the match rests on exact evidence. |
| `matchConfidence` | `number \| null` | The confidence of an estimated match. |
| `flags` | `string[]` | Reasons for review, for example `outside_window`. |
| `duplicateOf` | `string \| null` | For `ignored`, the referral that holds the credit. |
| `updated` | `boolean` | `true` when this call replaced an estimate with an exact match. |
| `replayState` | `ReplayState \| null` | `original` or `replayed`. |

**Errors:** `E_NOT_CONFIGURED`, `E_NETWORK_ERROR`, `E_SERVER_ERROR`, `E_INVALID_API_KEY`, `E_KEY_APP_MISMATCH`. An empty or over-long `installerId` rejects with `E_SERVER_ERROR`.

### clearAttribution()

```typescript
clearAttribution(): Promise<void>
```

Forgets this install's attribution so you can test a first launch again without deleting the app: the cached match, the attempt and completed markers, and any held referral invitation. Only the device is cleared. Server records are not deleted.

Test only. With a `wl_live_` key this does nothing and resolves, so it never erases a live install's attribution. With a `wl_test_` key and `automaticDeferredDeepLinks` on, a check already in flight is discarded and a new check starts. A match from it reaches `onLink`.

**Errors:** `E_NOT_CONFIGURED` before `configure`. `E_STORAGE_ERROR` when a stored item could not be deleted and some state may remain. Calling again is safe.

### isConfigured()

```typescript
isConfigured(): Promise<boolean>
```

Check whether the SDK has been configured.

### sdkVersion()

```typescript
sdkVersion(): Promise<string>
```

Returns the version of the **native** WarpLink SDK the app is actually running, not the `@warplink/react-native` package version. This distinction matters because the package bundles the native WarpLink SDK. Calling `sdkVersion()` asks the native side directly, so you always see the version your app runs.

```typescript
console.log(await WarpLink.sdkVersion()); // "1.4.0"
```

### isAttributionComplete()

```typescript
isAttributionComplete(): Promise<boolean>
```

Whether the deferred attribution check has definitively completed for the current install. Scoped to one install: it reads `false` again after the app is deleted and reinstalled, or restored from a device backup, because a reinstall is attributed again from scratch. The automatic dispatch inside `configure()` already reads this before deciding whether to re-fire the deferred check, so a normal integration built on the opt-out model never has to call it directly. It is useful for diagnostics, or for a host that drives `checkDeferredDeepLink()` manually with `automaticDeferredDeepLinks: false`.

### getDeferredCheckStatus()

```typescript
getDeferredCheckStatus(): Promise<{
  state: 'notChecked' | 'checking' | 'matched' | 'noMatch' | 'waiting' | 'skippedOldInstall' | 'stopped';
  retryAt?: number;
}>
```

Where the deferred check stands for this install, read without sending a request. It tells a skipped check from no match. It comes from what the native SDK stored, so a relaunch keeps it. `retryAt` is set only when `state` is `'waiting'`, in epoch milliseconds.

| State | Meaning |
|-------|---------|
| `'notChecked'` | No check has finished for this install. A failed check whose wait has passed also reads `'notChecked'`. |
| `'checking'` | A check is running, or waiting for the app to come to the foreground. |
| `'matched'` | The check finished and found a link. |
| `'noMatch'` | The check finished and the server found no link. |
| `'waiting'` | An earlier check failed. The SDK sends nothing before `retryAt`. |
| `'skippedOldInstall'` | The install is older than 30 days by default, so no request is sent. |
| `'stopped'` | The SDK gave up 3 days after the first failure by default. No request is sent. |

A `wl_test_` key never reports `'waiting'`, `'skippedOldInstall'` or `'stopped'`. With `debugLogging` on, the native SDK prints `Deferred check request: attempt <n>, raw signals <yes|no>` for each request and `Deferred check: <state>` when a check ends. In Xcode the lines start with `[WarpLink]`. In Logcat, filter by the `WarpLink` tag. A waiting check prints `Deferred check: waiting, retry at <ISO 8601 time>`. See [If your test did not match](https://warplink.app/docs/sdks/react-native/deferred#if-your-test-did-not-match).

**Errors:** `E_DECODING_ERROR` when the native reply is malformed. Before `configure` it resolves `{ state: 'notChecked' }`.

### readTether()

```typescript
readTether(): Promise<TetherReadResult>
```

Reads the clipboard for a Tether code now, and sends the code to the server. It works in every `tetherReadMode`. On iOS the system may show its paste prompt. On Android nothing is read, and the result is `{ kind: 'noCode', reason: null }`. A match that replaces a link `onLink` already received also reaches `onLink` as an exact link. It rejects with a `WarpLinkError` when the SDK is not configured or the request failed. See [Tether](https://warplink.app/docs/tether/sdk-modes).

### lastTetherTestReceipt()

```typescript
lastTetherTestReceipt(): Promise<string | null>
```

The receipt the server returned for the last Tether test code (`wl1t_`), or `null`. It is kept in memory only: a restart or `clearAttribution()` clears it.

### onDeepLink(listener)

```typescript
onDeepLink(listener: DeepLinkListener): () => void
```

Register a listener for warm-start deep link events. Returns an unsubscribe function.

### getInitialDeepLink()

```typescript
getInitialDeepLink(): Promise<WarpLinkDeepLink | null>
```

Get the deep link that launched the app (cold start). Returns `null` if not launched via a link.

---

## Types

### WarpLinkConfig

```typescript
interface WarpLinkConfig {
  apiKey: string;
  apiEndpoint?: string;                  // Default: "https://api.warplink.app/v1"
  debugLogging?: boolean;                // Default: false
  onLink?: (event: { deepLink?: WarpLinkDeepLink; error?: WarpLinkError }) => void; // Cold/warm/deferred, or an error
  automaticDeepLinks?: boolean;          // Default: true
  automaticDeferredDeepLinks?: boolean;  // Default: true
  linkDomains?: string[];                // Default: [] (custom domains you serve links from)
  tetherReadMode?: TetherReadMode;       // Default: 'pasteButton'
  matchWindowHours?: number;             // @deprecated Server-side only, no effect
}
```

matchWindowHours is accepted for backward compatibility but has no effect: the match window is set per link in the dashboard.

#### tetherReadMode

How the SDK gets a Tether code from the clipboard. `'pasteButton'` is the default: the SDK never reads the clipboard by itself, and the person taps `WarpLinkPasteButton`. `'automatic'` reads once during the first-launch check, and iOS may show its paste prompt then. `'onCall'` reads only when you call `readTether()`. Android reads no clipboard in any mode. A value that is not one of these reads as `'pasteButton'`.

#### linkDomains

Hosts the SDK should treat as yours, in addition to `aplnk.to`. `configure()` forwards the list to the native SDKs, which own the domain set and the normalization (trimmed, lowercased, a full URL reduced to its host). Declaring a custom domain here is what lets a link on it resolve on the first launch, before the SDK has reached the server. The same domains can be declared natively instead: see [iOS](https://warplink.app/docs/sdks/ios#declare-your-link-domains) and [Android](https://warplink.app/docs/sdks/android#declare-your-link-domains).

### WarpLinkDeepLink

```typescript
interface WarpLinkDeepLink {
  linkId: string;
  destination: string;
  deepLinkUrl: string | null;
  customParams: Record<string, unknown>;
  isDeferred: boolean;
  matchType: 'deterministic' | 'probabilistic' | null;
  matchConfidence: number | null;
  matchGuaranteed: boolean;
  attributionId: string | null;
  matchMethod: MatchMethod | null;
  evidenceClass: EvidenceClass | null;
  replayState: ReplayState | null;
  capturedParams: Record<string, unknown>;
  tappedAt: string | null;
}
```

### AttributionResult

```typescript
interface AttributionResult {
  linkId: string;
  matchType: 'deterministic' | 'probabilistic';
  matchConfidence: number;
  matchGuaranteed: boolean;
  isDeferred: boolean;
  attributionId: string | null;
  matchMethod: MatchMethod | null;
  evidenceClass: EvidenceClass | null;
  replayState: ReplayState | null;
  capturedParams: Record<string, unknown>;
  tappedAt: string | null;
}
```

`MatchMethod` is `'install_token' | 'android_referrer' | 'referrer' | 'device_id' | 'link_open' | 'probabilistic'` (`android_referrer` is an invitation token from the Play install referrer and `referrer` is a plain link ID from it, so `referrer` comes with `evidenceClass` `legacy_link`), `EvidenceClass` is `'exact' | 'estimated' | 'legacy_link'` and `ReplayState` is `'original' | 'replayed'`. A value this SDK does not know reads as `null`, and `null` is never read as exact.

### DeepLinkEvent

Discriminated union: exactly one of `deepLink` or `error` is present.

```typescript
type DeepLinkEvent =
  | { deepLink: WarpLinkDeepLink; error?: undefined }
  | { deepLink?: undefined; error: WarpLinkError };
```

### DeepLinkListener

```typescript
type DeepLinkListener = (event: DeepLinkEvent) => void;
```

---

### TetherReadResult

```typescript
type TetherReadResult =
  | { kind: 'matched'; link: WarpLinkDeepLink }
  | { kind: 'noCode'; reason: TetherMissReason | null }
  | { kind: 'unusable' }
  | { kind: 'test'; receipt: string | null };
```

| Kind | Meaning |
|------|---------|
| `matched` | The code led to `link`. |
| `noCode` | No code was read and nothing was sent. `reason` says why, and is `null` on Android. |
| `unusable` | A code was sent and led nowhere. Let the person continue. |
| `test` | A test code reached the server and nothing was recorded. |

A failure is a rejected promise with a `WarpLinkError`, never one of these. `TetherMissReason` is one of `'paste_not_allowed'`, `'clipboard_empty'`, `'in_app_browser'`, `'expired'`, `'other_app'`, `'link_ended'` and `'older_sdk'`.

### WarpLinkPasteButton

The system paste button that reads a Tether code. In the default `'pasteButton'` mode it is the only way the SDK reads the clipboard, and iOS shows no paste prompt. It renders nothing on Android and on iOS below 16.

| Prop | Type | Description |
|------|------|-------------|
| `onResult` | `(result: TetherReadResult) => void` | Called with the outcome after the person taps the button. |
| `onError` | `(error: WarpLinkError) => void` | Called when the read or the request failed. |
| `style` | `StyleProp<ViewStyle>` | Layout. The default size is 160 by 44 points. |
| `baseBackgroundColor`, `baseForegroundColor` | `ColorValue` | The button colors. |
| `cornerStyle` | `PasteButtonCornerStyle` | `'dynamic'`, `'fixed'`, `'small'`, `'medium'`, `'large'` or `'capsule'`. |
| `displayMode` | `PasteButtonDisplayMode` | `'iconAndLabel'`, `'iconOnly'` or `'labelOnly'`. |

## Error Types

### WarpLinkError

```typescript
class WarpLinkError extends Error {
  readonly code: ErrorCode;
  constructor(code: ErrorCode, message: string);
}
```

### ErrorCodes

```typescript
const ErrorCodes = {
  E_NOT_CONFIGURED: 'E_NOT_CONFIGURED',
  E_INVALID_API_KEY_FORMAT: 'E_INVALID_API_KEY_FORMAT',
  E_INVALID_API_KEY: 'E_INVALID_API_KEY',
  E_KEY_APP_MISMATCH: 'E_KEY_APP_MISMATCH',
  E_NETWORK_ERROR: 'E_NETWORK_ERROR',
  E_SERVER_ERROR: 'E_SERVER_ERROR',
  E_INVALID_URL: 'E_INVALID_URL',
  E_LINK_NOT_FOUND: 'E_LINK_NOT_FOUND',
  E_PASSWORD_REQUIRED: 'E_PASSWORD_REQUIRED',
  E_DECODING_ERROR: 'E_DECODING_ERROR',
  E_STORAGE_ERROR: 'E_STORAGE_ERROR',
} as const;
```

| Code | Description |
|------|-------------|
| `E_NOT_CONFIGURED` | SDK not initialized. |
| `E_INVALID_API_KEY_FORMAT` | Key format invalid. |
| `E_INVALID_API_KEY` | Key rejected by server. |
| `E_KEY_APP_MISMATCH` | The key is valid but tied to a different app. Use the SDK key created for this app. |
| `E_NETWORK_ERROR` | Network unreachable or timeout. |
| `E_SERVER_ERROR` | Server returned 5xx. |
| `E_INVALID_URL` | Not a recognized WarpLink domain. |
| `E_LINK_NOT_FOUND` | Link not found or inactive. |
| `E_PASSWORD_REQUIRED` | Link is password protected, so it resolves to no destination and no platform URLs. |
| `E_DECODING_ERROR` | Malformed server response. |
| `E_STORAGE_ERROR` | `clearAttribution()` could not delete a stored item. Calling it again is safe. |

---

## Native Bridge

`@warplink/react-native` is a classic native-module bridge (`NativeModules` + a single `NativeEventEmitter` channel, `onWarpLinkDeepLink`), not a TurboModule authored from scratch. React Native's interop layer runs classic modules unmodified under both the classic and New Architecture (Fabric/TurboModules), so every method and type on this page behaves identically regardless of which architecture your app runs.

Two properties of the bridge shape are worth knowing when debugging:

- Every promise-returning method here (`handleDeepLink`, `checkDeferredDeepLink`, `getAttributionResult`, `isConfigured`, `sdkVersion`, `isAttributionComplete`) makes one native call and resolves or rejects from its answer. None of them poll.
- `onDeepLink()` and the automatic `onLink` sink both read from the same underlying native event stream; the TypeScript layer fans one native event out to every JavaScript subscriber rather than opening a separate native subscription per listener.

If the module is not linked (`NativeModules['WarpLinkModule']` is `undefined`), every method on `WarpLink` throws synchronously with a linking error rather than rejecting a promise, since there is no native module to make the call against. See [Deep Links: Troubleshooting](https://warplink.app/docs/sdks/react-native/deep-links#troubleshooting) for the common causes.

## Platform Requirements

```json
{
  "peerDependencies": {
    "react": ">=18.0.0",
    "react-native": ">=0.75.0"
  }
}
```

The native side has its own floor: iOS 15.0 (set in `warplink-react-native.podspec`) and Android API 26 / Android 8.0 (`minSdk` in the module's `android/build.gradle.kts`), matching the standalone iOS and Android SDKs exactly, since this package embeds them rather than reimplementing anything. Node.js 18+ is required to build the package itself, not to run the resulting app.

### TypeScript Types Exported

Every type in this reference is exported from the package root, not from an internal path:

```typescript
import {
  WarpLink,
  WarpLinkError,
  ErrorCodes,
  type ErrorCode,
  type WarpLinkConfig,
  type WarpLinkDeepLink,
  type AttributionResult,
  type DeepLinkEvent,
  type DeepLinkListener,
  type ReferralClaimResult,
  type ReferralClaimStatus,
  type MatchMethod,
  type EvidenceClass,
  type ReplayState,
  type AttributionEvidence,
  type TetherReadMode,
  type TetherMissReason,
  type TetherReadResult,
  WarpLinkPasteButton,
  type WarpLinkPasteButtonProps,
  type PasteButtonCornerStyle,
  type PasteButtonDisplayMode,
} from '@warplink/react-native';
```

Importing from an internal path such as `@warplink/react-native/src/WarpLink` is unsupported and will break on a future release; the package's `main`/`module`/`types` fields all resolve through the root entry point.

### Expo

The SDK works in an Expo development build (`npx expo prebuild` or EAS Build). Add the iOS host hook (`WarpLinkModule.handleIncomingURL`, see [Deep Links](https://warplink.app/docs/sdks/react-native/deep-links#platform-asymmetry-the-host-hook)) to the generated `AppDelegate`/`SceneDelegate`, or reinsert it on every prebuild with a small `withAppDelegate` config plugin. Associated Domains and the Android intent filter both have `app.json` equivalents and need no manual native editing.

## Troubleshooting

**`customParams` values come back as `unknown` and TypeScript complains.** This is deliberate. Custom parameters are the query parameters of the link's destination URL, returned as a JSON object, so the type is `Record<string, unknown>` rather than a link-specific shape the SDK cannot know ahead of time. Narrow with a type assertion or a runtime check at the call site: `link.customParams['product_id'] as string | undefined`.

**`sdkVersion()` reports a different version than the npm package.** The native SDK version is versioned separately and reflects the SDK your app runs.

## FAQ

**Does `configure()` need to be awaited before calling other methods?** Not strictly. `configure()`'s promise resolves once native configuration, cold-start dispatch, and (when a sink is present) the deferred check have all settled, but `handleDeepLink()` and the other methods each make their own native call and will queue behind an in-progress native configuration rather than fail. Awaiting `configure()` is still the simplest way to know setup fully finished.

**How do I use WarpLink from React function components?** The package exports a single module-level `WarpLink` object with promise-based methods and an event subscription (`onDeepLink`), the same shape on every platform this SDK supports. Wrap it in your own hook if your codebase prefers that pattern; there is nothing React-specific in the underlying calls that a hook would add.

**What TypeScript version is required?** The package ships its own `.d.ts` files built against the `react-native` peer dependency's types; any TypeScript version compatible with your installed `react-native` and `@types/react` versions works. There is no WarpLink-specific TypeScript floor beyond what React Native itself requires.

**Does `getAttributionResult()` make a network call, or read a cached value?** It reads the native SDK's cached result from the deferred check that already ran; it does not trigger a new attribution request. Call `checkDeferredDeepLink()` if you need to force the check to run (only meaningful before it has completed for the current install).
