npm package: @lubes/sdk
Description: Official TypeScript/JavaScript SDK for Lubes
Author: Lubes
Latest version: 0.1.0

# @agentbase/sdk

Official TypeScript/JavaScript SDK for AgentBase.

## Installation

```bash
npm install @agentbase/sdk
```

## Quick Start

```typescript
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

```typescript
const client = new AgentBase({
  apiKey: 'ab_your_api_key_here',
  org: 'my-org',
  project: 'my-project',
});
```

### Email/Password Authentication

```typescript
const client = new AgentBase({
  apiUrl: 'https://api.agentbase.dev',
});

// Login
const { user, tokens } = await client.login({
  email: 'user@example.com',
  password: 'password',
});

// Set org and project
client.setOrg('my-org').setProject('my-project');
```

## Database Operations

### List Tables

```typescript
const tables = await client.listTables();
```

### Get Table Schema

```typescript
const schema = await client.getTableSchema('users');
console.log(schema.columns);
```

### Execute Queries

```typescript
// 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',
  ['user@example.com']
);
```

### Database Branches

```typescript
// 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

```typescript
const functions = await client.listFunctions();
```

### Invoke Function

```typescript
const result = await client.invokeFunction('my-function', {
  input: 'data',
});
console.log(result.result);
```

### Function Logs

```typescript
const logs = await client.getFunctionLogs('my-function', { limit: 50 });
```

## Deployments

```typescript
// 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

```typescript
// 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

```typescript
// List buckets
const buckets = await client.listBuckets();

// Create bucket
const bucket = await client.createBucket({
  name: 'my-bucket',
  is_public: false,
});
```

### Objects

```typescript
// 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

```typescript
// 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

```typescript
// 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: 'teammate@example.com',
  role: 'member',
});
```

## Error Handling

```typescript
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

```typescript
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:

```typescript
import type {
  User,
  Organization,
  Project,
  TableSchema,
  QueryResult,
  ServerlessFunction,
  Deployment,
  EnvVar,
  Bucket,
  StorageObject,
  Webhook,
} from '@agentbase/sdk';
```

## License

MIT