Skip to content
Tools

TypeScript SDK

The @fomodata/sdk package: install, configure, use.

@fomodata/sdk is the TypeScript-first client for FomoData. Response types are generated from the OpenAPI document; the ergonomic wrapper on top is handcrafted. It runs anywhere fetch and WebCrypto do: Node 20+, Bun, Deno and edge runtimes.

Install

Terminal
npm install https://fomodata.dev/sdk/fomodata-sdk-0.1.0.tgz

The npm package is coming soon. The tarball above is the exact package build, served by this deployment. Pin it in package.json like any other dependency.

Configure

fomo.ts
import { FomoData } from "@fomodata/sdk";

export const fomo = new FomoData({ apiKey: process.env.FOMODATA_API_KEY });

The client talks to https://fomodata.dev/v1 by default. Pass baseUrl (or set FOMODATA_API_BASE_URL, including /v1) only for a self-hosted or local API. Receiving webhooks (handle, constructEvent) needs only webhookSecret. Other options: streamUrl (or FOMODATA_STREAM_URL; otherwise the SDK discovers the active stream service from the API), timeoutMs (30 s), maxRetries (2), fetch, WebSocket, headers.

Keep keys server-side

Use live keys only on servers. Never ship a key in browser bundles or mobile apps.

Modules

ModuleWhat it coversDocs
fomo.profilesget(ref), list({ id | handle | fomo_user_id }) / lookup(…) (both return one Profile)Profiles
fomo.theseslist(filters), iterate(filters), get(id), verify(input), createTest(input)Theses
fomo.tokensget(ref), activity(ref), velocity(ref)Tokens
fomo.searchquery(q, { types, limit })Search
fomo.eventslist(params), iterate(params), get(id)Events
fomo.webhookscreate, list, update, delete, rotateSecret, test, deliveries, replay; receiving: constructEvent and verifySignature (both async, WebCrypto), on(type, handler), handle(request)Webhooks
fomo.streamssubscribe(options) with auto-reconnect and cursor resume (fromCursor, subscription.cursor); reconnects after 1013 / 1001 with from_cursorStreams

Examples

Profile

const profile =
  await fomo.profiles.get("@milo");

Theses

const theses =
  await fomo.theses.list({
    token: "$RUN",
    since: "1h"
  });

Verify

const result =
  await fomo.theses.verify({
    handle: "@milo",
    token: "$RUN",
    after: start,
    before: end
  });

Stream

fomo.streams.subscribe({
  event: "thesis.created",
  token: "$RUN",
  onEvent(event) {
    console.log(event);
  }
});

Errors

Non-2xx responses throw a FomoDataError carrying the API's code, HTTP status and requestId. Codes are listed on the errors page.

errors.ts
import { FomoDataError } from "@fomodata/sdk";

try {
  await fomo.profiles.get("@sbx_nobody");
} catch (err) {
  if (err instanceof FomoDataError && err.code === "PROFILE_NOT_FOUND") {
    // show "unknown handle"
  } else {
    throw err;
  }
}

GET requests and verifications are retried on 429, 5xx and network errors (twice by default, set maxRetries), honouring Retry-After. Other errors are thrown immediately. fomo.lastRequestId and fomo.rateLimit expose the latest request id and X-RateLimit-* values.

Other languages and tools

ToolStatus
TypeScript / JavaScriptAvailable
PythonComing soon
GoComing soon
npx fomodata login · keys create · listen thesis.createdComing soon

Until then, any HTTP client works: the API reference shows curl for every endpoint, and the OpenAPI document at https://fomodata.dev/openapi.json can generate clients in other languages.