This package provides a TypeScript SDK for the DefiTuna public API. The SDK is generated from OpenAPI using `@hey-api/openapi-ts` and exposes a class-based client plus typed helpers.
npm install @crypticdot/defituna-apiThis package provides a TypeScript SDK for the DefiTuna public API. The SDK is generated from OpenAPI using @hey-api/openapi-ts and exposes a class-based client plus typed helpers.
``bash`NPM
npm install @crypticdot/defituna-apiYarn
yarn add @crypticdot/defituna-apiPNPM
pnpm add @crypticdot/defituna-api
`ts
import { TunaBackendSdk, createClient, unwrap } from "@crypticdot/defituna-api";
const client = createClient({
baseUrl: "https://api.defituna.com/api",
});
const sdk = new TunaBackendSdk({ client });
const positions = await unwrap(
sdk.getTunaPositions({
userAddress: "CYCf8sBj4zLZheRovh37rWLe7pK8Yn5G7nb4SeBmgfMG",
}),
);
`
- Generation source: openapi.yaml is the canonical spec.scripts/camelize-openapi.mjs
- Pre-processing: produces openapi.camel.yaml (converts snake_case into cameCase).@hey-api/openapi-ts
- Code generation: generates src/client/**.scripts/postprocess-openapi-ts.mjs
- Post-processing: patches the generated client to:
- snake_case request payloads/params
- camelCase response payloads
- apply response transforms before validators where needed
- apply custom SSE transforms (see below)
- Requests: payloads and query params are snake_cased in src/caseTransforms.ts.
- Responses: payloads are camelCased and then transformed for BigInt/Date via generated transformers.
SSE response transforms are maintained manually in src/sseTransforms.ts. The upstream transformer plugin does not handle the SSE union schema, so any changes to SSE payloads must be reflected here.
If you add or modify SSE event types in openapi.yaml:
1. Update the SSE schemas and discriminator mapping.
2. Regenerate the SDK (pnpm generate).src/sseTransforms.ts
3. Update to apply the correct transforms for the new event type.
1. Update openapi.yaml.pnpm generate
2. Run (or pnpm openapi-ts).src/sseTransforms.ts
3. Verify generated output and postprocess changes.
4. Update if SSE payloads changed.pnpm run lint
5. Run and pnpm run test.
To throw on non-2xx responses for all SDK calls, set throwOnError: true on the client instanceTunaSdkError
and attach the built-in interceptor that wraps errors as :
`ts
import { TunaBackendSdk, createClient, tunaSdkErrorInterceptor } from "@crypticdot/defituna-api";
const client = createClient({
baseUrl: "https://api.defituna.com/api",
throwOnError: true,
});
client.interceptors.error.use(tunaSdkErrorInterceptor);
const sdk = new TunaBackendSdk({ client });
`
TunaSdkError includes the HTTP status and the original error payload in cause.
If you already have a client, you can also enable it later:
`ts
import { client, tunaSdkErrorInterceptor } from "@crypticdot/defituna-api";
client.setConfig({ throwOnError: true });
client.interceptors.error.use(tunaSdkErrorInterceptor);
`
When responseStyle is set to "data", SDK calls return only the response payload{ data, error, request, response }
(no wrapper). This is useful for simpler call sites:
`ts
import { TunaBackendSdk, createClient } from "@crypticdot/defituna-api";
const client = createClient({
baseUrl: "https://api.defituna.com/api",
responseStyle: "data",
});
const sdk = new TunaBackendSdk({ client });
const vaults = await sdk.getVaults();
``