API & SDK

SDK

@trustfix/sdk — a tiny, type-safe TypeScript client whose types are generated from the canonical OpenAPI spec, with no runtime dependencies.

@trustfix/sdk is a tiny, type-safe client for the TrustFix public API. Its types are generated from the canonical OpenAPI spec (docs-site/openapi.yaml), so they always match the live API surface — CI keeps the spec at 100% coverage of the public routes. The only hand-written code is a thin fetch wrapper with no runtime dependencies.

Usage

import { createTrustFixClient } from '@trustfix/sdk';
import type { paths } from '@trustfix/sdk/schema';

const client = createTrustFixClient({
  baseUrl: 'https://trustfix.dev/api',
  apiKey: process.env.TRUSTFIX_API_KEY, // tfx_live_… / tfx_test_…
});

// The path is checked against the documented surface; cast the result to the
// schema's response type for full type safety.
type Passports =
  paths['/agent-passport']['get']['responses']['200']['content']['application/json'];

const passports = (await client.get('/agent-passport')) as Passports;

createTrustFixClient returns get / post / patch / delete helpers plus a request escape hatch. The path argument is constrained to the documented surface, and you cast the result to the corresponding response type from paths for end-to-end type safety.

Errors

Non-2xx responses throw TrustFixApiError, which carries the status and the parsed body:

import { TrustFixApiError } from '@trustfix/sdk';

try {
  await client.get('/findings');
} catch (err) {
  if (err instanceof TrustFixApiError) {
    console.error(err.status, err.body);
  }
}

Notes

  • Auth is a Bearer API key (see the API reference). Session-cookie (browser) auth is out of scope for the SDK.
  • Regenerate the types after any API change with npm run sdk:generate.
  • The package is consumed from the workspace and is not yet published to a public registry.