@crypticdot/defituna-api 3.1.2 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -13
- package/dist/index.cjs +18254 -1665
- package/dist/index.d.cts +10246 -2517
- package/dist/index.d.ts +10246 -2517
- package/dist/index.js +18020 -1516
- package/package.json +8 -11
package/README.md
CHANGED
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
This package provides
|
|
6
|
-
|
|
7
|
-
## Key Features
|
|
8
|
-
|
|
9
|
-
- **TunaApiClient**: The package includes a client for DefiTuna's public API. This allows to fetch the latest data from DefiTuna's on-chain program in a fast and efficient way without using Solana's RPC.
|
|
5
|
+
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.
|
|
10
6
|
|
|
11
7
|
## Installation
|
|
12
8
|
|
|
@@ -21,18 +17,94 @@ pnpm add @crypticdot/defituna-api
|
|
|
21
17
|
|
|
22
18
|
## Usage
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
```ts
|
|
21
|
+
import { TunaBackendSdk, createClient, unwrap } from "@crypticdot/defituna-api";
|
|
22
|
+
|
|
23
|
+
const client = createClient({
|
|
24
|
+
baseUrl: "https://api.defituna.com/api",
|
|
25
|
+
});
|
|
26
|
+
const sdk = new TunaBackendSdk({ client });
|
|
27
|
+
|
|
28
|
+
const positions = await unwrap(
|
|
29
|
+
sdk.getTunaPositions({
|
|
30
|
+
userAddress: "CYCf8sBj4zLZheRovh37rWLe7pK8Yn5G7nb4SeBmgfMG",
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## How the SDK works
|
|
36
|
+
|
|
37
|
+
- Generation source: `openapi.yaml` is the canonical spec.
|
|
38
|
+
- Pre-processing: `scripts/camelize-openapi.mjs` produces `openapi.camel.yaml` (converts snake_case into cameCase).
|
|
39
|
+
- Code generation: `@hey-api/openapi-ts` generates `src/client/**`.
|
|
40
|
+
- Post-processing: `scripts/postprocess-openapi-ts.mjs` patches the generated client to:
|
|
41
|
+
- snake_case request payloads/params
|
|
42
|
+
- camelCase response payloads
|
|
43
|
+
- apply response transforms before validators where needed
|
|
44
|
+
- apply custom SSE transforms (see below)
|
|
45
|
+
|
|
46
|
+
## Case transforms and scalar transforms
|
|
47
|
+
|
|
48
|
+
- Requests: payloads and query params are snake_cased in `src/caseTransforms.ts`.
|
|
49
|
+
- Responses: payloads are camelCased and then transformed for BigInt/Date via generated transformers.
|
|
50
|
+
|
|
51
|
+
## SSE streams
|
|
52
|
+
|
|
53
|
+
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.
|
|
54
|
+
|
|
55
|
+
If you add or modify SSE event types in `openapi.yaml`:
|
|
25
56
|
|
|
26
|
-
|
|
57
|
+
1. Update the SSE schemas and discriminator mapping.
|
|
58
|
+
2. Regenerate the SDK (`pnpm generate`).
|
|
59
|
+
3. Update `src/sseTransforms.ts` to apply the correct transforms for the new event type.
|
|
27
60
|
|
|
28
|
-
|
|
29
|
-
import { TunaApiClient } from "@crypticdot/defituna-api";
|
|
61
|
+
## Maintenance workflow
|
|
30
62
|
|
|
31
|
-
|
|
63
|
+
1. Update `openapi.yaml`.
|
|
64
|
+
2. Run `pnpm generate` (or `pnpm openapi-ts`).
|
|
65
|
+
3. Verify generated output and postprocess changes.
|
|
66
|
+
4. Update `src/sseTransforms.ts` if SSE payloads changed.
|
|
67
|
+
5. Run `pnpm run lint` and `pnpm run test`.
|
|
68
|
+
|
|
69
|
+
## Global error behavior
|
|
70
|
+
|
|
71
|
+
To throw on non-2xx responses for all SDK calls, set `throwOnError: true` on the client instance
|
|
72
|
+
and attach the built-in interceptor that wraps errors as `TunaSdkError`:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { TunaBackendSdk, createClient, tunaSdkErrorInterceptor } from "@crypticdot/defituna-api";
|
|
76
|
+
|
|
77
|
+
const client = createClient({
|
|
78
|
+
baseUrl: "https://api.defituna.com/api",
|
|
79
|
+
throwOnError: true,
|
|
80
|
+
});
|
|
81
|
+
client.interceptors.error.use(tunaSdkErrorInterceptor);
|
|
82
|
+
|
|
83
|
+
const sdk = new TunaBackendSdk({ client });
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`TunaSdkError` includes the HTTP status and the original error payload in `cause`.
|
|
87
|
+
|
|
88
|
+
If you already have a client, you can also enable it later:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { client, tunaSdkErrorInterceptor } from "@crypticdot/defituna-api";
|
|
92
|
+
|
|
93
|
+
client.setConfig({ throwOnError: true });
|
|
94
|
+
client.interceptors.error.use(tunaSdkErrorInterceptor);
|
|
32
95
|
```
|
|
33
96
|
|
|
34
|
-
|
|
97
|
+
When `responseStyle` is set to `"data"`, SDK calls return only the response payload
|
|
98
|
+
(no `{ data, error, request, response }` wrapper). This is useful for simpler call sites:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { TunaBackendSdk, createClient } from "@crypticdot/defituna-api";
|
|
102
|
+
|
|
103
|
+
const client = createClient({
|
|
104
|
+
baseUrl: "https://api.defituna.com/api",
|
|
105
|
+
responseStyle: "data",
|
|
106
|
+
});
|
|
35
107
|
|
|
36
|
-
|
|
37
|
-
const
|
|
108
|
+
const sdk = new TunaBackendSdk({ client });
|
|
109
|
+
const vaults = await sdk.getVaults();
|
|
38
110
|
```
|