TypeScript server SDK
Configure a client
Section titled “Configure a client”import { StreaklineServer } from "@streakline/sdk/server";
const streakline = new StreaklineServer({ baseUrl: "https://api.qa.streakline.dev", auth: process.env.STREAKLINE_ACCESS_TOKEN!, timeoutMs: 10_000,});For a long-running service, use auth: async () => tokenProvider.getAccessToken() with your own token provider. The default timeout is ten seconds. Use separate client instances for separate environments or credential contexts.
Track one occurrence
Section titled “Track one occurrence”const result = await streakline.track(userId, "lesson.completed", { idempotencyKey: `lesson:${completionId}`, occurredAt: new Date(), localDate: "2026-09-09", metadata: { lesson_id: "lesson-42" },});userId and completionId are application values. The event key must exist in your released configuration. A resolved call has committed its event and profile update. Rejections throw StreaklineApiError.
Track a batch
Section titled “Track a batch”const result = await streakline.trackBatch([ { userId, event_type: "lesson.completed", idempotency_key: `lesson:${completionId}`, occurred_at: new Date().toISOString(), },]);
for (const event of result.results) { if (!event.accepted) console.log(event.code, event.error);}The facade splits batches into chunks of 100 events. Inspect individual results: a successful HTTP response can contain rejected events. Batch payload fields use the API’s snake_case naming; the facade’s user selector is userId.
Read progress
Section titled “Read progress”const profile = await streakline.getProfile(userId); // profiles:readconst history = await streakline.getEvents(userId, 100); // events:readconst nextPage = history.cursor ? await streakline.getEvents(userId, 100, history.cursor) : null;Purchase a store item
Section titled “Purchase a store item”const purchase = await streakline.purchaseStoreItem(userId, "blue-theme", { idempotencyKey: `order:${orderId}`,});console.log(purchase.paid_with.balance_after);The item must exist in the active released store configuration. This server operation requires store:purchase. Retrying the same purchase key returns the original response.
Use generated operations directly
Section titled “Use generated operations directly”The package exposes the full public API through Hey API:
import { createClient } from "@streakline/sdk/client";import { listUserAchievements } from "@streakline/sdk/generated";
const client = createClient({ baseUrl: "https://api.qa.streakline.dev", auth: process.env.STREAKLINE_ACCESS_TOKEN!,});const { data, error, response } = await listUserAchievements({ client, path: { userId },});if (error !== undefined) throw error;console.log(data);Generated operations return response fields instead of the facade’s unwrapped data by default. They do not manage token renewal, offline queues, or scoring predictions. Public SDK payload types derive from the OpenAPI contract.