@backflow.sdk/client
v0.1.0
Published
Tenant SDK for Backflow API (user-facing resources only)
Maintainers
Readme
@backflow/sdk
Auto-generated TypeScript SDK for Backflow API.
Installation
npm install @backflow/sdkQuick Start
import { createBackflow } from '@backflow/sdk';
const bf = await createBackflow({
apiKey: 'bf_live_xxx',
tenantId: 'my-tenant-id',
});
// Typed resource methods
await bf.files.upload(file, { entityType: 'project', entityId: 'proj-123' });
await bf.workflows.execute({ steps: [...] });
await bf.tenant.secrets.set('API_KEY', 'secret-value');
// Dynamic resources for tenant-specific routes
await bf.resource('projects').list();
await bf.resource('classes').create({ name: 'Yoga' });Configuration
interface BackflowConfig {
apiKey?: string; // For server-to-server auth
getAuthToken?: () => Promise<string>; // For browser/dynamic auth
tenantId: string; // Required
endpoint?: string; // Defaults to https://api.backflow.dev
}With Firebase Auth (Browser)
import { createBackflow } from '@backflow/sdk';
import { getAuth } from 'firebase/auth';
const bf = await createBackflow({
tenantId: 'my-tenant-id',
getAuthToken: async () => {
const user = getAuth().currentUser;
return user?.getIdToken() || '';
}
});Typed Resources
Files
// Single file upload
const result = await bf.files.upload(file, {
entityType: 'project',
entityId: 'proj-123',
});
// Multiple files
const results = await bf.files.uploadMultiple(files, {
entityType: 'project',
entityId: 'proj-123',
});
// List files
const files = await bf.files.list('project', 'proj-123');
// Get signed URL
const { url } = await bf.files.getSignedUrl('bucket', 'path/to/file.pdf');
// Delete
await bf.files.delete('bucket', 'path/to/file.pdf');
await bf.files.deleteByEntity('project', 'proj-123');Workflows
// Execute workflow
const execution = await bf.workflows.execute({
steps: [
{ id: 'fetch', action: 'api_call', params: { url: '...' } },
{ id: 'analyze', action: 'llm_call', params: { prompt: '...' } },
],
});
// Subscribe to progress (WebSocket)
const unsubscribe = bf.workflows.subscribe(execution.id, {
onProgress: (event) => console.log('Step:', event.stepId, event.status),
onComplete: (result) => console.log('Done:', result),
onError: (err) => console.error(err),
});
// Control
await bf.workflows.pause(execution.id);
await bf.workflows.resume(execution.id);
await bf.workflows.cancel(execution.id);
await bf.workflows.retry(execution.id);
// List & history
const { data } = await bf.workflows.list({ limit: 10 });
const { history } = await bf.workflows.getHistory(execution.id);Tenant & Secrets
// Get/update config
const config = await bf.tenant.getConfig();
await bf.tenant.updateConfig({ settings: { theme: 'dark' } });
// Secrets management
await bf.tenant.secrets.set('STRIPE_KEY', 'sk_xxx', {
provider: 'stripe',
description: 'Production API key',
});
const secrets = await bf.tenant.secrets.list();
await bf.tenant.secrets.rotate('STRIPE_KEY', 'sk_new_xxx');
await bf.tenant.secrets.delete('OLD_KEY');Embeddings
// Embed document
const result = await bf.embeddings.embedDocument({
document: 'Your document text...',
documentId: 'doc-123',
contentType: 'article',
});
// Batch embed
const batchResult = await bf.embeddings.embedBatch([
{ document: 'Doc 1...', documentId: 'doc-1' },
{ document: 'Doc 2...', documentId: 'doc-2' },
]);
// Search
const { results } = await bf.embeddings.search('doc-123', 'query text', 5);
// Semantic search across all docs
const { results } = await bf.embeddings.semanticSearch('find similar content');
// Delete
await bf.embeddings.delete('doc-123');LLM
// Chat
const response = await bf.llm.chat([
{ role: 'user', content: 'Hello!' }
], { model: 'gpt-4', temperature: 0.7 });
// Simple completion
const response = await bf.llm.complete('Explain quantum computing');
// List models
const { models } = await bf.llm.models();Usage
const myUsage = await bf.usage.getMyUsage();
const userUsage = await bf.usage.getUserUsage('user-123');
const summary = await bf.usage.getSummary('user-123');Dynamic Resources
For tenant-defined routes (projects, users, teams, etc.):
// Use resource() for any endpoint
const projects = await bf.resource('projects').list();
const project = await bf.resource('projects').get('proj-123');
await bf.resource('projects').create({ name: 'New Project' });
await bf.resource('projects').update('proj-123', { name: 'Updated' });
await bf.resource('projects').delete('proj-123');
// Nested resources
await bf.resource('teams/team-123/members').list();Raw Requests
// Direct HTTP methods
const data = await bf.get('/custom/endpoint', { param: 'value' });
await bf.post('/custom/endpoint', { body: 'data' });
await bf.put('/custom/endpoint', { body: 'data' });
await bf.patch('/custom/endpoint', { body: 'data' });
await bf.delete('/custom/endpoint');License
ISC
