@byorouter/node
v0.1.0
Published
BYORouter Node.js SDK
Downloads
9
Readme
@byorouter/node
BYORouter Node.js SDK for backend operations like code exchange and connection management.
Installation
npm install @byorouter/nodeUsage
Exchange Authorization Code
After the user completes the Connect flow, exchange the code for a connection ID:
import { BYORouter } from '@byorouter/node';
const byorouter = new BYORouter({
apiKey: process.env.BYOROUTER_API_KEY!,
});
// Exchange the code from the callback URL
const { connectionId } = await byorouter.exchangeCode(code);
// Store connectionId in your database for the user
await db.users.update({ id: userId }, { connectionId });Get Connection Details
const connection = await byorouter.getConnection(connectionId);
console.log(connection.providerCount); // Number of connected providersList Connected Providers
const providers = await byorouter.getProviders(connectionId);
// [{ provider: 'openai', credentialType: 'api_key', ... }]Delete Connection
await byorouter.deleteConnection(connectionId);API Reference
new BYORouter(options)
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| apiKey | string | Yes | Your BYORouter API key (sk_live_xxx) |
| baseURL | string | No | API base URL (default: https://api.byorouter.com) |
Methods
exchangeCode(code: string)- Exchange auth code for connection IDgetConnection(connectionId: string)- Get connection detailsgetProviders(connectionId: string)- List connected providersdeleteConnection(connectionId: string)- Delete a connection
Error Handling
import { BYORouter, BYORouterError } from '@byorouter/node';
try {
await byorouter.exchangeCode(code);
} catch (error) {
if (error instanceof BYORouterError) {
console.error(error.code); // 'invalid_code', 'expired_code', etc.
console.error(error.message);
}
}License
MIT
