Skip to content

TypeScript server SDK

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.

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.

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.

const profile = await streakline.getProfile(userId); // profiles:read
const history = await streakline.getEvents(userId, 100); // events:read
const nextPage = history.cursor
? await streakline.getEvents(userId, 100, history.cursor)
: null;
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.

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.