# TypeScript SDK

> **Coming Soon** — The `@diapleo/sdk` package is under active development.

## @diapleo/sdk

The official TypeScript SDK will wrap the REST API with a fully-typed, ergonomic interface. It will handle authentication, rate-limit headers, error typing, retries, and response deserialization.

```
npm install @diapleo/sdk
```

### Planned Client Configuration

```typescript
import { DiapleoClient } from "@diapleo/sdk";

const client = new DiapleoClient({
  apiKey: process.env.DIAPLEO_API_KEY, // optional for public endpoints; required for wallet scan
  baseUrl: "https://api.diapleo.xyz/v1",
  timeout: 10_000,
  retries: 2,
  onRateLimit: "wait",                   // "wait" | "throw" | "skip"
});
```

### Planned SDK Methods

| **SDK Method**                      | **REST Equivalent**             | **Description**                  |
| ----------------------------------- | ------------------------------- | -------------------------------- |
| `client.protocols.list(params?)`    | `GET /v1/protocols`             | List scored protocols            |
| `client.protocols.get(id)`          | `GET /v1/protocols/{id}`        | Full protocol detail             |
| `client.protocols.listAll(params?)` | `GET /v1/protocols` (all pages) | Auto-paginate                    |
| `client.screener.list(params?)`     | `GET /v1/screener`              | Filter by any risk dimension     |
| `client.wallet.scan(address)`       | `GET /v1/wallet/{address}`      | Scan wallet for DeFi risk (Pro+) |
| `client.stats()`                    | `GET /v1/stats`                 | Global ecosystem stats           |
| `client.usage.get()`                | `GET /v1/usage`                 | Usage report for your key        |
| `client.health()`                   | `GET /v1/health`                | Health check                     |

### Usage Examples

```typescript
import { DiapleoClient } from "@diapleo/sdk";

const client = new DiapleoClient({ apiKey: process.env.DIAPLEO_API_KEY });

// Safest Solana lending, sorted low-to-high composite
const { data, meta } = await client.protocols.list({
  chain: "Solana",
  category: "Lending",
  sortBy: "compositeScore",
  sortDir: "asc",
  perPage: 10,
});

console.log(`Found ${meta.total} matching protocols`);
for (const p of data) {
  console.log(`${p.name}: composite=${p.compositeScore} (${p.riskLevel}), tvl=$${p.tvlUsd}`);
}

// Full detail — includes dimensions, chainTvls, similar, incidents, scoreHistory
const { data: detail } = await client.protocols.get("kamino-lend");
console.log(detail.dimensions?.oracle.score);          // 1.0
console.log(detail.dimensions?.smartContract.score);    // 4.5
console.log(detail.chainTvls[0]);                       // { chain: "Solana", tvlUsd, borrowedUsd }

// Screen for protocols with tight oracle + smart contract discipline
const { data: safe } = await client.screener.list({
  maxOracleRisk: 2,
  maxSmartContractRisk: 3,
  sort: "tvl",
  order: "desc",
});

// Scan a Solana wallet — SNS names also resolve
const scan = await client.wallet.scan("toly.sol");
console.log(scan.data.portfolioScore, scan.data.positionSource);

// Ecosystem snapshot
const { data: stats } = await client.stats();
console.log(`${stats.protocolCount} protocols, ${stats.chainCount} chains`);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.diapleo.com/api-reference/integrations/typescript-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
