Skip to main content

TypeScript client

A minimal, dependency-free TypeScript client. Drop it in, import it, ship. Handles OAuth bearer and API key auth, discriminates the three partner error envelopes documented in Pagination + errors (plus the empty-body OAuth 401/403 and the OAuth token-endpoint shape), and throws a typed FlynetError you can match on status and code. Download flynet.ts: ~220 lines, no dependencies, MIT-style use-it-however.

Why use it

Hand-rolling the basics costs ~30 to 60 minutes before you write any business logic:

What’s inside

Configure

Most apps end up with both schemes in the same codebase. The file lets you spin up one client per scheme and never mix them up:
baseUrl defaults to staging. Override when shipping to production:

Use

Handle errors

FlynetError exposes a typed .code, so you can switch on the codes in Debugging:

Identify the authenticated member

/users/me/* resolves the subject from the token, so you usually don’t need the UUID; member.getMe() returns the authenticated member directly. When you do need the UUID for your own state, the helper decodes it from the access token’s sub claim, the same pattern documented in OAuth → Identify the authenticated member:
Decode once when you receive a fresh token; cache alongside the token in memory; re-decode on refresh.

What’s not included

flynet.ts is starter code, not a full SDK. Out of scope:

Generated types

For exhaustively-typed responses, generate from the OpenAPI spec and swap unknown for the generated types:
Then adjust flynet.ts return types from unknown to paths["…"]["get"]["responses"]["200"]…. Stretch into a full SDK at your own pace. The file is yours.

Maintenance

flynet.ts is a reference implementation, not a maintained library. We update it when a breaking API change ships; track those in Changelog. If the snippet drifts from the live API, file an issue via Support.