@audialize/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 ADDED
@@ -0,0 +1,263 @@
1
+ # @audialize/sdk
2
+
3
+ Official TypeScript/JavaScript SDK for the [Audialize](https://audialize.com) API — broadcast-grade audio localization and subtitle generation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @audialize/sdk
9
+ # or
10
+ pnpm add @audialize/sdk
11
+ ```
12
+
13
+ **Requires Node.js ≥ 18** (native `fetch`).
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { AudiolizeClient } from '@audialize/sdk';
19
+
20
+ const client = new AudiolizeClient({
21
+ apiKey: process.env.AUDIALIZE_API_KEY,
22
+ });
23
+
24
+ // High-level: entire pipeline in one call
25
+ const job = await client.localize({
26
+ file: './interview.mp4',
27
+ languages: ['nl', 'de'],
28
+ sourceLanguage: 'en',
29
+ onUploadProgress: (pct) => console.log(`Upload: ${pct}%`),
30
+ onProgress: (step, pct) => console.log(`${step}: ${pct}%`),
31
+ });
32
+
33
+ const srt = await client.subtitles.download(job.jobId, 'nl', 'srt');
34
+ console.log(srt);
35
+ ```
36
+
37
+ ## API Reference
38
+
39
+ ### `new AudiolizeClient(options)`
40
+
41
+ | Option | Type | Default | Description |
42
+ |--------|------|---------|-------------|
43
+ | `apiKey` | `string` | **required** | Your Audialize API key |
44
+ | `baseUrl` | `string` | `https://api.audialize.com` | API base URL override |
45
+ | `timeout` | `number` | `30000` | Request timeout in ms |
46
+ | `maxRetries` | `number` | `3` | Max retry attempts for transient errors |
47
+
48
+ ---
49
+
50
+ ### `client.localize(options)` → `Promise<Job>`
51
+
52
+ Full pipeline: upload → poll → return completed job.
53
+
54
+ ```typescript
55
+ const job = await client.localize({
56
+ file: './speech.mp4', // string path, Buffer, Blob, or File
57
+ languages: ['nl', 'de', 'fr'],
58
+ sourceLanguage: 'en',
59
+ context: { domain: 'sports' },
60
+ multipartThreshold: 100 * 1024 * 1024, // 100 MB (default)
61
+ onUploadProgress: (percent) => {},
62
+ onProgress: (step, percent) => {},
63
+ pollOptions: { interval: 3000, timeout: 600000 },
64
+ });
65
+ ```
66
+
67
+ `transcriptionMethod` is intentionally not exposed in the SDK API. The platform selects the optimal transcription engine automatically.
68
+
69
+ ---
70
+
71
+ ### `client.files`
72
+
73
+ #### `client.files.upload(file, options)` → `Promise<{ jobId: string }>`
74
+
75
+ Uploads a file (single PUT to GCS via presigned URL) and creates a job.
76
+
77
+ ```typescript
78
+ const { jobId } = await client.files.upload('./speech.mp4', {
79
+ languages: ['nl'],
80
+ sourceLanguage: 'en',
81
+ onUploadProgress: (pct) => console.log(pct),
82
+ });
83
+ ```
84
+
85
+ #### `client.files.uploadMultipart(file, options)` → `Promise<{ jobId: string }>`
86
+
87
+ Uploads large files (≥ 100 MB by default) in parallel parts.
88
+
89
+ ```typescript
90
+ const { jobId } = await client.files.uploadMultipart(buffer, {
91
+ languages: ['nl'],
92
+ concurrency: 4,
93
+ onUploadProgress: (pct) => console.log(pct),
94
+ });
95
+ ```
96
+
97
+ ---
98
+
99
+ ### `client.jobs`
100
+
101
+ #### `client.jobs.get(jobId)` → `Promise<Job>`
102
+
103
+ Fetch current job status.
104
+
105
+ #### `client.jobs.list(options?)` → `Promise<PagedResponse<Job>>`
106
+
107
+ List jobs with optional `limit` and `pageToken`.
108
+
109
+ #### `client.jobs.waitForCompletion(jobId, options?)` → `Promise<Job>`
110
+
111
+ Poll until the job completes or fails.
112
+
113
+ ```typescript
114
+ const job = await client.jobs.waitForCompletion(jobId, {
115
+ interval: 3000,
116
+ timeout: 600_000,
117
+ onProgress: (step, percent) => console.log(`${step}: ${percent}%`),
118
+ });
119
+ ```
120
+
121
+ #### `client.jobs.poll(jobId, options?)` → `JobPoller`
122
+
123
+ Returns an event-emitting `JobPoller` for fine-grained control.
124
+
125
+ ```typescript
126
+ const poller = client.jobs.poll(jobId, { interval: 5000 });
127
+
128
+ poller.on('progress', ({ step, progress }) => {
129
+ process.stdout.write(`\r${step}: ${progress}%`);
130
+ });
131
+
132
+ poller.on('completed', (job) => console.log('\nDone!', job.jobId));
133
+ poller.on('failed', (err) => console.error(err));
134
+
135
+ await poller.start();
136
+ ```
137
+
138
+ ---
139
+
140
+ ### `client.subtitles`
141
+
142
+ #### `client.subtitles.download(jobId, language, format)` → `Promise<string | SubtitleResult>`
143
+
144
+ Downloads subtitle output. `format` is `'srt'`, `'vtt'`, or `'json'`.
145
+
146
+ ```typescript
147
+ const srt = await client.subtitles.download(jobId, 'nl', 'srt');
148
+ const vtt = await client.subtitles.download(jobId, 'nl', 'vtt');
149
+ const obj = await client.subtitles.download(jobId, 'nl', 'json'); // SubtitleResult
150
+ ```
151
+
152
+ ---
153
+
154
+ ### `client.languages`
155
+
156
+ #### `client.languages.list()` → `Promise<Language[]>`
157
+
158
+ Returns all supported transcription/translation languages.
159
+
160
+ ---
161
+
162
+ ## Error Handling
163
+
164
+ All SDK errors extend `AudiolizeError`. Import them for typed `catch` blocks:
165
+
166
+ ```typescript
167
+ import {
168
+ AuthenticationError,
169
+ AuthorizationError,
170
+ NotFoundError,
171
+ RateLimitError,
172
+ PaywallError,
173
+ ServerError,
174
+ AudiolizeUploadError,
175
+ AudiolizeTimeoutError,
176
+ AudiolizeValidationError,
177
+ } from '@audialize/sdk';
178
+
179
+ try {
180
+ await client.localize({ file: './video.mp4', languages: ['nl'] });
181
+ } catch (err) {
182
+ if (err instanceof AuthenticationError) {
183
+ console.error('Invalid API key');
184
+ } else if (err instanceof PaywallError) {
185
+ console.error('Budget limit reached — upgrade your plan');
186
+ } else if (err instanceof AudiolizeTimeoutError) {
187
+ console.error('Job timed out');
188
+ } else {
189
+ throw err;
190
+ }
191
+ }
192
+ ```
193
+
194
+ ---
195
+
196
+ ## Retry Behaviour
197
+
198
+ | Scenario | Behaviour |
199
+ |----------|-----------|
200
+ | `429` with `Retry-After` | Waits exactly that many seconds |
201
+ | `429` without header | Exponential backoff: 1s, 2s, 4s … cap 60s |
202
+ | `502 / 503 / 504` | Exponential backoff, up to `maxRetries` |
203
+ | `401 / 402 / 403 / 404` | Throws immediately |
204
+ | Network error | Exponential backoff, up to `maxRetries` |
205
+ | GCS presigned PUT | Up to 3 retries (independent counter) |
206
+
207
+ ---
208
+
209
+ ## Environment Variable
210
+
211
+ For server-side and CI use, set `AUDIALIZE_API_KEY` and pass it via `process.env`:
212
+
213
+ ```typescript
214
+ const client = new AudiolizeClient({
215
+ apiKey: process.env.AUDIALIZE_API_KEY,
216
+ });
217
+ ```
218
+
219
+ ---
220
+
221
+ ## Browser Support
222
+
223
+ The SDK is ESM-native and works in modern browsers. File system access (`node:fs`) is only used when a file path string is passed — the import is dynamic so it does not appear in browser bundles.
224
+
225
+ ## Frontend Safety
226
+
227
+ Use this SDK from server-side boundaries for production apps:
228
+
229
+ - ✅ Node backends, workers, server routes/actions
230
+ - ⚠️ Browser-only usage only when credentials are short-lived and scoped
231
+ - ❌ Never expose long-lived API keys in client-side bundles
232
+
233
+ For a secure web-app pattern, see `../../docs/FRONTEND_SAFE_USAGE.md` and `../../examples/nextjs-server-route/README.md`.
234
+
235
+ ---
236
+
237
+ ## Troubleshooting
238
+
239
+ | Problem | Likely cause | Fix |
240
+ |---------|--------------|-----|
241
+ | `AuthenticationError` | Missing/invalid API key | Verify `AUDIALIZE_API_KEY` on server runtime |
242
+ | `RateLimitError` | Too many requests in short window | Back off and retry, honor `Retry-After` |
243
+ | `AudiolizeTimeoutError` | Upstream slow response | Increase `timeout`, keep retries enabled |
244
+ | Upload fails with `UPLOAD_ERROR` | Presigned PUT failed or multipart part issue | Retry upload and verify file/network constraints |
245
+ | `PaywallError` | Subscription/budget limit reached | Upgrade plan or reduce requested workload |
246
+
247
+ ---
248
+
249
+ ## Release Readiness (Maintainers)
250
+
251
+ Before publishing to npm, run:
252
+
253
+ ```bash
254
+ pnpm release:check
255
+ ```
256
+
257
+ This enforces lint, typecheck, unit tests, contract tests, strict OpenAPI validation, and build gates.
258
+
259
+ ---
260
+
261
+ ## License
262
+
263
+ MIT © Audialize