@lubes/sdk
v0.1.0
Published
Official TypeScript/JavaScript SDK for Lubes
Downloads
31
Maintainers
Readme
@agentbase/sdk
Official TypeScript/JavaScript SDK for AgentBase.
Installation
npm install @agentbase/sdkQuick Start
import { AgentBase } from '@agentbase/sdk';
// Initialize with API key
const client = new AgentBase({
apiKey: 'your-api-key',
org: 'your-org',
project: 'your-project',
});
// List tables
const tables = await client.listTables();
console.log(tables);
// Execute a query
const result = await client.executeQuery('SELECT * FROM users LIMIT 10');
console.log(result.rows);Authentication
API Key Authentication
const client = new AgentBase({
apiKey: 'ab_your_api_key_here',
org: 'my-org',
project: 'my-project',
});Email/Password Authentication
const client = new AgentBase({
apiUrl: 'https://api.agentbase.dev',
});
// Login
const { user, tokens } = await client.login({
email: '[email protected]',
password: 'password',
});
// Set org and project
client.setOrg('my-org').setProject('my-project');Database Operations
List Tables
const tables = await client.listTables();Get Table Schema
const schema = await client.getTableSchema('users');
console.log(schema.columns);Execute Queries
// Simple query
const result = await client.executeQuery('SELECT * FROM users WHERE active = true');
// Parameterized query
const result = await client.executeQuery(
'SELECT * FROM users WHERE email = $1',
['[email protected]']
);Database Branches
// List branches
const branches = await client.listBranches();
// Create branch
const branch = await client.createBranch({ name: 'feature-branch' });
// Delete branch
await client.deleteBranch('feature-branch');Functions
List Functions
const functions = await client.listFunctions();Invoke Function
const result = await client.invokeFunction('my-function', {
input: 'data',
});
console.log(result.result);Function Logs
const logs = await client.getFunctionLogs('my-function', { limit: 50 });Deployments
// List deployments
const deployments = await client.listDeployments();
// Create deployment
const deployment = await client.createDeployment({
description: 'New feature release',
});
// Rollback
await client.rollbackDeployment(deploymentId);Environment Variables
// List env vars
const envVars = await client.listEnvVars();
// Create env var
const envVar = await client.createEnvVar({
key: 'API_KEY',
value: 'secret-value',
is_secret: true,
});
// Reveal secret value
const revealed = await client.revealEnvVar(envVar.id);Storage
Buckets
// List buckets
const buckets = await client.listBuckets();
// Create bucket
const bucket = await client.createBucket({
name: 'my-bucket',
is_public: false,
});Objects
// List objects
const objects = await client.listObjects(bucketId, {
prefix: 'uploads/',
});
// Get signed URL for download
const { url } = await client.getSignedUrl(bucketId, {
key: 'uploads/file.pdf',
expires_in: 3600,
});
// Delete object
await client.deleteObject(bucketId, 'uploads/file.pdf');Webhooks
// Create webhook
const webhook = await client.createWebhook({
name: 'My Webhook',
url: 'https://example.com/webhook',
events: ['deployment.created', 'deployment.completed'],
});
// Get deliveries
const deliveries = await client.getWebhookDeliveries(webhook.id);Organization Management
// List organizations
const orgs = await client.listOrganizations();
// Create organization
const org = await client.createOrganization({
name: 'My Org',
slug: 'my-org',
});
// Invite member
await client.inviteMember({
email: '[email protected]',
role: 'member',
});Error Handling
import { AgentBase, AgentBaseError } from '@agentbase/sdk';
try {
await client.executeQuery('INVALID SQL');
} catch (error) {
if (error instanceof AgentBaseError) {
console.error(`Error: ${error.code} - ${error.message}`);
console.error('Details:', error.details);
}
}Configuration Options
const client = new AgentBase({
apiUrl: 'https://api.agentbase.dev', // API URL (default)
apiKey: 'your-api-key', // API key authentication
accessToken: 'jwt-token', // JWT token authentication
org: 'your-org', // Organization slug
project: 'your-project', // Project slug
timeout: 30000, // Request timeout in ms (default: 30000)
});TypeScript Support
Full TypeScript support with exported types:
import type {
User,
Organization,
Project,
TableSchema,
QueryResult,
ServerlessFunction,
Deployment,
EnvVar,
Bucket,
StorageObject,
Webhook,
} from '@agentbase/sdk';License
MIT
