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 typedFlynetError 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:Without flynet.ts | With flynet.ts |
|---|---|
Build a fetch wrapper per auth scheme | flynet({ credentials }) per scheme |
| Discriminate the error envelopes by hand | FlynetError with typed .code |
Parse WWW-Authenticate for OAuth 401/403 causes | Done; reason surfaces as err.code |
| Track which routes need which header | Methods only accept the right credential’s client |
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:
What’s not included
flynet.ts is starter code, not a full SDK. Out of scope:
| Feature | Where to find it |
|---|---|
| 401 → refresh → retry wrapper | OAuth Step 3: the callApi wrapper |
| Refresh-token race-condition handling (singleton in-flight refresh) | Add yourself; see OAuth Step 4 for the contract |
| Webhook verification | Webhooks ship post-launch; see FAQ |
Per-method response typing (vs unknown) | Generate from the OpenAPI spec; next section |
Generated types
For exhaustively-typed responses, generate from the OpenAPI spec and swapunknown for the generated types:
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.