@biteasy/javascript-sdk
v1.0.4
Published
BitEasy JavaScript SDK
Readme
@biteasy/javascript-sdk
A thin, strictly-typed, framework-agnostic JavaScript SDK for the BitEasy attribution API. Tree-shakeable, side-effect free, and lightweight.
Features
- Zero Dependencies: Uses native
fetchand standard promises. - Framework Agnostic: Works in Browser, Node.js, React Native, and Expo.
- Tree-Shakeable: Import only the functions you use.
- Runtime Validation: Zod validation on both requests and responses.
Installation
npm install @biteasy/javascript-sdk
# or
bun add @biteasy/javascript-sdkUsage
1. Create a Client
import { createClient } from "@biteasy/javascript-sdk";
const client = createClient({
appId: "your-app-id",
});
// Optional overrides:
const customClient = createClient({
appId: "your-app-id",
version: "2", // default: "1"
baseUrl: "https://custom.api.com", // default: "https://api.biteasy.com/api"
fetch: customFetch, // default: globalThis.fetch
});2. API Functions
All functions throw on non-2xx responses. Use try/catch for error handling.
Claim Attribution
Attribute an app installation to a referral partner.
import { createClient, claimAttribution } from "@biteasy/javascript-sdk";
const client = createClient({ appId: "your-app-id" });
const result = await claimAttribution(client, {
installId: "unique-install-id",
platform: "ios", // or "android"
claimCode: "ABC-123", // optional: for explicit attribution
});
if (result.status === "claimed") {
console.log("Attributed to:", result.referrer);
}Defer Preflight
Issue a short-lived claim code for explicit attribution.
import { deferPreflight } from "@biteasy/javascript-sdk";
const result = await deferPreflight(client, {
referrer: "referrer-id",
});
console.log(result.claimCode); // "ABC-123"
console.log(result.expiresAt); // "2025-01-01T00:00:00Z"Defer
Register a referral intent for time-based or explicit attribution.
import { defer } from "@biteasy/javascript-sdk";
const result = await defer(client, {
referrer: "referrer-id",
platform: "ios",
path: "/premium", // optional
claimCode: "ABC-123", // optional
});
console.log(result.success); // trueTypes
TypeScript types are exported:
BitEasyClient/BitEasyClientConfigV1ClaimResponseV1DeferPreflightResponseV1DeferResponse
