@rendobar/sdk 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 +229 -0
- package/dist/index.cjs +641 -0
- package/dist/index.d.cts +2851 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +2851 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +640 -0
- package/dist/index.mjs.map +1 -0
- package/dist/webhooks.cjs +25 -0
- package/dist/webhooks.d.cts +13 -0
- package/dist/webhooks.d.cts.map +1 -0
- package/dist/webhooks.d.mts +13 -0
- package/dist/webhooks.d.mts.map +1 -0
- package/dist/webhooks.mjs +26 -0
- package/dist/webhooks.mjs.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# @rendobar/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript client for the Rendobar media processing API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @rendobar/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createClient } from "@rendobar/sdk";
|
|
15
|
+
|
|
16
|
+
const client = createClient({ apiKey: "rb_..." });
|
|
17
|
+
|
|
18
|
+
// Submit a job
|
|
19
|
+
const job = await client.jobs.create({
|
|
20
|
+
type: "watermark.apply",
|
|
21
|
+
inputs: { source: "https://example.com/video.mp4" },
|
|
22
|
+
params: { text: "PREVIEW", position: "center", opacity: 0.3 },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Wait for completion
|
|
26
|
+
const result = await client.jobs.wait(job.id);
|
|
27
|
+
console.log(result.outputUrl);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Authentication
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
// API key (external users, CLI, scripts)
|
|
34
|
+
const client = createClient({ apiKey: "rb_..." });
|
|
35
|
+
|
|
36
|
+
// Session cookie (internal dashboard)
|
|
37
|
+
const client = createClient({
|
|
38
|
+
baseUrl: "https://api.rendobar.com",
|
|
39
|
+
credentials: "include",
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Configuration
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const client = createClient({
|
|
47
|
+
apiKey: "rb_...",
|
|
48
|
+
baseUrl: "https://api.rendobar.com", // default
|
|
49
|
+
timeout: 30_000, // default: 30s
|
|
50
|
+
maxRetries: 2, // default: 2 (retries 429, 5xx)
|
|
51
|
+
orgId: "org_abc", // X-Org-Id header
|
|
52
|
+
debug: false, // log request metadata
|
|
53
|
+
fetch: customFetch, // custom fetch for testing
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Jobs
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
// Create
|
|
61
|
+
const job = await client.jobs.create({
|
|
62
|
+
type: "watermark.apply",
|
|
63
|
+
inputs: { source: "https://example.com/video.mp4" },
|
|
64
|
+
params: { text: "PREVIEW", position: "center" },
|
|
65
|
+
idempotencyKey: "unique-key-123",
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Get
|
|
69
|
+
const job = await client.jobs.get("job_abc");
|
|
70
|
+
|
|
71
|
+
// List (paginated — works with React Query)
|
|
72
|
+
const page = await client.jobs.list({ status: "complete", limit: 20 });
|
|
73
|
+
// page.data: Job[], page.meta: { total, page, limit }
|
|
74
|
+
|
|
75
|
+
// Auto-paginate all pages
|
|
76
|
+
for await (const job of client.jobs.listAll({ status: "complete" })) {
|
|
77
|
+
console.log(job.id);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Wait for completion (polls until terminal status)
|
|
81
|
+
const result = await client.jobs.wait("job_abc", {
|
|
82
|
+
timeout: 300_000,
|
|
83
|
+
interval: 2_000,
|
|
84
|
+
onProgress: (job) => console.log(job.status),
|
|
85
|
+
signal: abortController.signal,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Cancel
|
|
89
|
+
await client.jobs.cancel("job_abc");
|
|
90
|
+
|
|
91
|
+
// Download output (returns raw Response)
|
|
92
|
+
const response = await client.jobs.download("job_abc");
|
|
93
|
+
const blob = await response.blob();
|
|
94
|
+
|
|
95
|
+
// Execution logs
|
|
96
|
+
const logs = await client.jobs.logs("job_abc");
|
|
97
|
+
|
|
98
|
+
// Available job types
|
|
99
|
+
const types = await client.jobs.types();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Billing
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const state = await client.billing.state();
|
|
106
|
+
const usage = await client.billing.usage({ start: "2026-01-01", end: "2026-03-29" });
|
|
107
|
+
const txns = await client.billing.transactions({ page: 1, limit: 50 });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Uploads
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// Upload a file, get a URL to use as job input
|
|
114
|
+
const { downloadUrl } = await client.uploads.upload(file, { filename: "input.mp4" });
|
|
115
|
+
|
|
116
|
+
const job = await client.jobs.create({
|
|
117
|
+
type: "watermark.apply",
|
|
118
|
+
inputs: { source: downloadUrl },
|
|
119
|
+
params: { text: "PREVIEW" },
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Batches
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
const batch = await client.batches.create({
|
|
127
|
+
jobs: [
|
|
128
|
+
{ type: "watermark.apply", inputs: { source: url1 }, params: { text: "1" } },
|
|
129
|
+
{ type: "watermark.apply", inputs: { source: url2 }, params: { text: "2" } },
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Webhooks
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// Create endpoint
|
|
138
|
+
const endpoint = await client.webhooks.create({
|
|
139
|
+
name: "My Webhook",
|
|
140
|
+
url: "https://example.com/webhook",
|
|
141
|
+
subscribedEvents: ["job.completed", "job.failed"],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Verify signature in your webhook handler
|
|
145
|
+
import { verifyWebhookSignature } from "@rendobar/sdk/webhooks";
|
|
146
|
+
|
|
147
|
+
const isValid = await verifyWebhookSignature(
|
|
148
|
+
requestBody,
|
|
149
|
+
request.headers.get("X-Rendobar-Signature"),
|
|
150
|
+
signingSecret,
|
|
151
|
+
);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Realtime Events (WebSocket)
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// Org-wide event stream
|
|
158
|
+
const connection = client.realtime.connect({
|
|
159
|
+
onEvent: (event) => console.log(event.type, event),
|
|
160
|
+
onLive: () => console.log("Replay complete, now live"),
|
|
161
|
+
onResync: () => console.log("Buffer overflow — refresh data"),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Per-job subscription
|
|
165
|
+
const sub = client.realtime.subscribeJob("job_abc", {
|
|
166
|
+
onProgress: (e) => console.log(`${e.progress}%`),
|
|
167
|
+
onStep: (e) => console.log(`Step: ${e.stepName}`),
|
|
168
|
+
onComplete: (e) => console.log("Done!", e.status),
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Cleanup
|
|
172
|
+
connection.disconnect();
|
|
173
|
+
sub.unsubscribe();
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
> **Note:** Realtime requires session cookie auth. API key users should use `jobs.wait()` for polling.
|
|
177
|
+
|
|
178
|
+
## Error Handling
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { createClient, ApiError, isApiError } from "@rendobar/sdk";
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
await client.jobs.create({ type: "watermark.apply", ... });
|
|
185
|
+
} catch (err) {
|
|
186
|
+
if (isApiError(err)) {
|
|
187
|
+
console.log(err.code); // "INSUFFICIENT_CREDITS"
|
|
188
|
+
console.log(err.statusCode); // 402
|
|
189
|
+
console.log(err.message); // "Not enough credits"
|
|
190
|
+
console.log(err.retryAfter); // seconds (for 429s)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Error codes: `UNAUTHORIZED`, `FORBIDDEN`, `VALIDATION_ERROR`, `INSUFFICIENT_CREDITS`, `RATE_LIMITED`, `NOT_FOUND`, `CONFLICT`, `INTERNAL_ERROR`.
|
|
196
|
+
|
|
197
|
+
## Retries
|
|
198
|
+
|
|
199
|
+
The SDK automatically retries:
|
|
200
|
+
- **429** (rate limited) — respects `Retry-After` header
|
|
201
|
+
- **500, 502, 503, 504** — server errors
|
|
202
|
+
|
|
203
|
+
Retries use exponential backoff (500ms, 1s). Max 2 retries by default. Non-retryable errors (400, 401, 403, 404) throw immediately.
|
|
204
|
+
|
|
205
|
+
## AbortSignal
|
|
206
|
+
|
|
207
|
+
Every method accepts an optional `signal` for cancellation:
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
const controller = new AbortController();
|
|
211
|
+
const job = await client.jobs.get("job_abc", { signal: controller.signal });
|
|
212
|
+
|
|
213
|
+
// Cancel the request
|
|
214
|
+
controller.abort();
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Types
|
|
218
|
+
|
|
219
|
+
All response types are exported:
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import type {
|
|
223
|
+
Job, JobStep, JobType, JobCreatedResponse,
|
|
224
|
+
BillingState, Transaction, UsageSummary,
|
|
225
|
+
WebhookEndpoint, WebhookDelivery,
|
|
226
|
+
Organization, ApiKey, PaginationMeta,
|
|
227
|
+
BillingInvoice, PaymentMethod, LogEntryData,
|
|
228
|
+
} from "@rendobar/sdk";
|
|
229
|
+
```
|