TypeScript SDK
The official Oproto SDK for TypeScript and JavaScript applications.
Installation
npm install @oproto/sdk
Requirements
- Node.js 18+ (or compatible runtime)
- TypeScript 5.0+ (recommended)
Quick Start
import { OprotoClient } from '@oproto/sdk';
// Initialize the client
const client = new OprotoClient({
accessToken: 'your-access-token',
});
// Make API calls
const companies = await client.companies.list();
Authentication
The SDK supports OAuth 2.0 authentication. You can provide credentials in several ways:
Access Token
const client = new OprotoClient({
accessToken: 'your-access-token',
});
Token Refresh
For long-running applications, configure automatic token refresh:
const client = new OprotoClient({
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
tokenEndpoint: 'https://auth.oproto.io/oauth/token',
});
Configuration Options
| Option | Type | Description |
|---|---|---|
accessToken | string | OAuth access token |
clientId | string | OAuth client ID for token refresh |
clientSecret | string | OAuth client secret for token refresh |
baseUrl | string | API base URL (defaults to production) |
timeout | number | Request timeout in milliseconds |
Error Handling
The SDK throws typed errors for API failures:
import { OprotoClient, OprotoError } from '@oproto/sdk';
try {
const company = await client.companies.get('invalid-id');
} catch (error) {
if (error instanceof OprotoError) {
console.error(`API Error: ${error.code} - ${error.message}`);
}
}