@backflow.sdk/client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +210 -0
- package/dist/index.d.mts +1845 -0
- package/dist/index.d.ts +1845 -0
- package/dist/index.js +2945 -0
- package/dist/index.mjs +2862 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# @backflow/sdk
|
|
2
|
+
|
|
3
|
+
Auto-generated TypeScript SDK for Backflow API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @backflow/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createBackflow } from '@backflow/sdk';
|
|
15
|
+
|
|
16
|
+
const bf = await createBackflow({
|
|
17
|
+
apiKey: 'bf_live_xxx',
|
|
18
|
+
tenantId: 'my-tenant-id',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Typed resource methods
|
|
22
|
+
await bf.files.upload(file, { entityType: 'project', entityId: 'proj-123' });
|
|
23
|
+
await bf.workflows.execute({ steps: [...] });
|
|
24
|
+
await bf.tenant.secrets.set('API_KEY', 'secret-value');
|
|
25
|
+
|
|
26
|
+
// Dynamic resources for tenant-specific routes
|
|
27
|
+
await bf.resource('projects').list();
|
|
28
|
+
await bf.resource('classes').create({ name: 'Yoga' });
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
interface BackflowConfig {
|
|
35
|
+
apiKey?: string; // For server-to-server auth
|
|
36
|
+
getAuthToken?: () => Promise<string>; // For browser/dynamic auth
|
|
37
|
+
tenantId: string; // Required
|
|
38
|
+
endpoint?: string; // Defaults to https://api.backflow.dev
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### With Firebase Auth (Browser)
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { createBackflow } from '@backflow/sdk';
|
|
46
|
+
import { getAuth } from 'firebase/auth';
|
|
47
|
+
|
|
48
|
+
const bf = await createBackflow({
|
|
49
|
+
tenantId: 'my-tenant-id',
|
|
50
|
+
getAuthToken: async () => {
|
|
51
|
+
const user = getAuth().currentUser;
|
|
52
|
+
return user?.getIdToken() || '';
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Typed Resources
|
|
58
|
+
|
|
59
|
+
### Files
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
// Single file upload
|
|
63
|
+
const result = await bf.files.upload(file, {
|
|
64
|
+
entityType: 'project',
|
|
65
|
+
entityId: 'proj-123',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Multiple files
|
|
69
|
+
const results = await bf.files.uploadMultiple(files, {
|
|
70
|
+
entityType: 'project',
|
|
71
|
+
entityId: 'proj-123',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// List files
|
|
75
|
+
const files = await bf.files.list('project', 'proj-123');
|
|
76
|
+
|
|
77
|
+
// Get signed URL
|
|
78
|
+
const { url } = await bf.files.getSignedUrl('bucket', 'path/to/file.pdf');
|
|
79
|
+
|
|
80
|
+
// Delete
|
|
81
|
+
await bf.files.delete('bucket', 'path/to/file.pdf');
|
|
82
|
+
await bf.files.deleteByEntity('project', 'proj-123');
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Workflows
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
// Execute workflow
|
|
89
|
+
const execution = await bf.workflows.execute({
|
|
90
|
+
steps: [
|
|
91
|
+
{ id: 'fetch', action: 'api_call', params: { url: '...' } },
|
|
92
|
+
{ id: 'analyze', action: 'llm_call', params: { prompt: '...' } },
|
|
93
|
+
],
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Subscribe to progress (WebSocket)
|
|
97
|
+
const unsubscribe = bf.workflows.subscribe(execution.id, {
|
|
98
|
+
onProgress: (event) => console.log('Step:', event.stepId, event.status),
|
|
99
|
+
onComplete: (result) => console.log('Done:', result),
|
|
100
|
+
onError: (err) => console.error(err),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Control
|
|
104
|
+
await bf.workflows.pause(execution.id);
|
|
105
|
+
await bf.workflows.resume(execution.id);
|
|
106
|
+
await bf.workflows.cancel(execution.id);
|
|
107
|
+
await bf.workflows.retry(execution.id);
|
|
108
|
+
|
|
109
|
+
// List & history
|
|
110
|
+
const { data } = await bf.workflows.list({ limit: 10 });
|
|
111
|
+
const { history } = await bf.workflows.getHistory(execution.id);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Tenant & Secrets
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
// Get/update config
|
|
118
|
+
const config = await bf.tenant.getConfig();
|
|
119
|
+
await bf.tenant.updateConfig({ settings: { theme: 'dark' } });
|
|
120
|
+
|
|
121
|
+
// Secrets management
|
|
122
|
+
await bf.tenant.secrets.set('STRIPE_KEY', 'sk_xxx', {
|
|
123
|
+
provider: 'stripe',
|
|
124
|
+
description: 'Production API key',
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const secrets = await bf.tenant.secrets.list();
|
|
128
|
+
await bf.tenant.secrets.rotate('STRIPE_KEY', 'sk_new_xxx');
|
|
129
|
+
await bf.tenant.secrets.delete('OLD_KEY');
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Embeddings
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// Embed document
|
|
136
|
+
const result = await bf.embeddings.embedDocument({
|
|
137
|
+
document: 'Your document text...',
|
|
138
|
+
documentId: 'doc-123',
|
|
139
|
+
contentType: 'article',
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Batch embed
|
|
143
|
+
const batchResult = await bf.embeddings.embedBatch([
|
|
144
|
+
{ document: 'Doc 1...', documentId: 'doc-1' },
|
|
145
|
+
{ document: 'Doc 2...', documentId: 'doc-2' },
|
|
146
|
+
]);
|
|
147
|
+
|
|
148
|
+
// Search
|
|
149
|
+
const { results } = await bf.embeddings.search('doc-123', 'query text', 5);
|
|
150
|
+
|
|
151
|
+
// Semantic search across all docs
|
|
152
|
+
const { results } = await bf.embeddings.semanticSearch('find similar content');
|
|
153
|
+
|
|
154
|
+
// Delete
|
|
155
|
+
await bf.embeddings.delete('doc-123');
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### LLM
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// Chat
|
|
162
|
+
const response = await bf.llm.chat([
|
|
163
|
+
{ role: 'user', content: 'Hello!' }
|
|
164
|
+
], { model: 'gpt-4', temperature: 0.7 });
|
|
165
|
+
|
|
166
|
+
// Simple completion
|
|
167
|
+
const response = await bf.llm.complete('Explain quantum computing');
|
|
168
|
+
|
|
169
|
+
// List models
|
|
170
|
+
const { models } = await bf.llm.models();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Usage
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
const myUsage = await bf.usage.getMyUsage();
|
|
177
|
+
const userUsage = await bf.usage.getUserUsage('user-123');
|
|
178
|
+
const summary = await bf.usage.getSummary('user-123');
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Dynamic Resources
|
|
182
|
+
|
|
183
|
+
For tenant-defined routes (projects, users, teams, etc.):
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
// Use resource() for any endpoint
|
|
187
|
+
const projects = await bf.resource('projects').list();
|
|
188
|
+
const project = await bf.resource('projects').get('proj-123');
|
|
189
|
+
await bf.resource('projects').create({ name: 'New Project' });
|
|
190
|
+
await bf.resource('projects').update('proj-123', { name: 'Updated' });
|
|
191
|
+
await bf.resource('projects').delete('proj-123');
|
|
192
|
+
|
|
193
|
+
// Nested resources
|
|
194
|
+
await bf.resource('teams/team-123/members').list();
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Raw Requests
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
// Direct HTTP methods
|
|
201
|
+
const data = await bf.get('/custom/endpoint', { param: 'value' });
|
|
202
|
+
await bf.post('/custom/endpoint', { body: 'data' });
|
|
203
|
+
await bf.put('/custom/endpoint', { body: 'data' });
|
|
204
|
+
await bf.patch('/custom/endpoint', { body: 'data' });
|
|
205
|
+
await bf.delete('/custom/endpoint');
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
ISC
|