@transcribe-api/sdk 0.1.1 → 0.1.3

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.
Files changed (4) hide show
  1. package/README.md +12 -4
  2. package/index.js +47 -28
  3. package/package.json +19 -17
  4. package/worker.js +1377 -0
package/README.md CHANGED
@@ -10,8 +10,8 @@ npm install @transcribe-api/sdk
10
10
 
11
11
  ## Usage
12
12
 
13
- ```js
14
- import { TranscribeAPI } from "@transcribe-api/sdk";
13
+ ```js
14
+ import { TranscribeAPI } from "@transcribe-api/sdk";
15
15
 
16
16
  const client = new TranscribeAPI({
17
17
  apiKey: "YOUR_API_KEY",
@@ -54,8 +54,14 @@ const mixedBatchJob = await client.batch.transcribe({
54
54
  { reference_id: "episode_1", file: "local.mp3" },
55
55
  { reference_id: "episode_2", url: "https://signed-get-url-2" },
56
56
  ],
57
- });
58
- ```
57
+ });
58
+ ```
59
+
60
+ For Cloudflare Workers and other web-style runtimes, use the Worker entrypoint:
61
+
62
+ ```js
63
+ import { TranscribeAPI } from "@transcribe-api/sdk/worker";
64
+ ```
59
65
 
60
66
  Async uploads use signed R2 URLs returned by the API. Multipart upload is used automatically when the backend returns a multipart flow.
61
67
  Async job creation now goes through `POST /v1/transcribe` for single-file and batch jobs. For batch calls, each item must be `{ reference_id, file }` or `{ reference_id, url }`, and local plus remote entries can be mixed in the same batch. The SDK adds `size_bytes` automatically for large local files when the backend needs multipart upload.
@@ -65,3 +71,5 @@ The SDK defaults `multipartConcurrency` to `8` for reliability. You can increase
65
71
  For Node path uploads, multipart progress is persisted to a sidecar resume file and the SDK will resume the existing big-file job on the next run instead of starting over.
66
72
  Multipart uploads also adaptively reduce concurrency on retryable transport errors instead of failing the whole upload immediately.
67
73
  Set `showLogs: true` on the client or per async call to let the SDK print upload URL receipt, upload progress, and the final `/upload-completed` response automatically. Pass a custom `logger` object if you want those messages redirected somewhere other than `console`.
74
+
75
+ Use `@transcribe-api/sdk/worker` when you need a runtime-safe build for Cloudflare Workers. The Worker entrypoint supports remote URLs, `Blob`, `File`, and byte inputs, but does not support local file path strings or Node.js filesystem resume state.
package/index.js CHANGED
@@ -15,24 +15,34 @@ const TERMINAL_JOB_STATUSES = new Set(["completed", "failed", "insufficient_fund
15
15
  const BATCH_MP4_UNSUPPORTED_MESSAGE = "Batch uploads do not support .mp4 for MVP. Supported batch audio formats: mp3, mpeg, mpga, m4a, wav, webm.";
16
16
  const BATCH_UNSUPPORTED_MESSAGE = "Unsupported batch audio format. Supported batch audio formats: mp3, mpeg, mpga, m4a, wav, webm.";
17
17
 
18
- export class TranscribeAPIError extends Error {
19
- constructor(error, { status = null, code = null, extra = null, response = null } = {}) {
20
- super(error);
21
- this.name = "TranscribeAPIError";
22
- this.status = status;
23
- this.code = code;
24
- this.error = error;
25
- this.response = response;
26
- if (extra && typeof extra === "object") {
27
- for (const [key, value] of Object.entries(extra)) {
28
- if (key === "status" || key === "stack" || key === "name") {
29
- continue;
30
- }
31
- this[key] = value;
32
- }
33
- }
34
- }
35
- }
18
+ export class TranscribeAPIError extends Error {
19
+ constructor(message, { status = null, code = null, extra = null, response = null } = {}) {
20
+ super(message);
21
+ this.name = "TranscribeAPIError";
22
+ this.status = status;
23
+ this.code = code;
24
+ this.response = response || { message, ...(code ? { code } : {}) };
25
+ if (extra && typeof extra === "object") {
26
+ for (const [key, value] of Object.entries(extra)) {
27
+ if (key === "status" || key === "stack" || key === "name" || key === "message" || key === "code") {
28
+ continue;
29
+ }
30
+ this[key] = value;
31
+ }
32
+ }
33
+ }
34
+
35
+ toJSON() {
36
+ return {
37
+ message: this.message,
38
+ ...(this.code ? { code: this.code } : {}),
39
+ ...Object.fromEntries(
40
+ Object.entries(this)
41
+ .filter(([key]) => !["name", "status", "code", "response"].includes(key)),
42
+ ),
43
+ };
44
+ }
45
+ }
36
46
 
37
47
  function sleep(ms) {
38
48
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -803,16 +813,25 @@ async function parseApiResponse(response) {
803
813
  } catch {
804
814
  data = { raw: text };
805
815
  }
806
- if (!response.ok) {
807
- throw new TranscribeAPIError(data.error || text || `HTTP ${response.status}`, {
808
- status: response.status,
809
- code: data.code || null,
810
- extra: data,
811
- response: data,
812
- });
813
- }
814
- return data;
815
- }
816
+ if (!response.ok) {
817
+ const message = data.message || data.error || text || `HTTP ${response.status}`;
818
+ const extra = { ...data };
819
+ delete extra.message;
820
+ delete extra.error;
821
+ delete extra.code;
822
+ throw new TranscribeAPIError(message, {
823
+ status: response.status,
824
+ code: data.code || null,
825
+ extra,
826
+ response: {
827
+ message,
828
+ ...(data.code ? { code: data.code } : {}),
829
+ ...extra,
830
+ },
831
+ });
832
+ }
833
+ return data;
834
+ }
816
835
 
817
836
  function normalizeHeaders(headers = {}) {
818
837
  return Object.fromEntries(
package/package.json CHANGED
@@ -1,26 +1,28 @@
1
- {
2
- "name": "@transcribe-api/sdk",
3
- "version": "0.1.1",
4
- "description": "Official JavaScript SDK for Transcribe API.",
5
- "type": "module",
6
- "main": "index.js",
1
+ {
2
+ "name": "@transcribe-api/sdk",
3
+ "version": "0.1.3",
4
+ "description": "Official JavaScript SDK for Transcribe API.",
5
+ "type": "module",
6
+ "main": "index.js",
7
7
  "exports": {
8
- ".": "./index.js"
8
+ ".": "./index.js",
9
+ "./worker": "./worker.js"
9
10
  },
10
11
  "scripts": {
11
12
  "test": "node --test"
12
13
  },
13
14
  "files": [
14
15
  "index.js",
16
+ "worker.js",
15
17
  "README.md"
16
18
  ],
17
- "keywords": [
18
- "transcription",
19
- "speech-to-text",
20
- "whisper",
21
- "audio",
22
- "api"
23
- ],
24
- "author": "Transcribe API",
25
- "license": "MIT"
26
- }
19
+ "keywords": [
20
+ "transcription",
21
+ "speech-to-text",
22
+ "whisper",
23
+ "audio",
24
+ "api"
25
+ ],
26
+ "author": "Transcribe API",
27
+ "license": "MIT"
28
+ }