@transcribe-api/sdk 0.1.6 → 0.1.7

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 CHANGED
@@ -185,7 +185,7 @@ You can also pass a comma-separated string:
185
185
  exclude: "metadata,billing"
186
186
  ```
187
187
 
188
- If `exclude` leaves only one transcript field and removes metadata, billing, and detected language, the API returns that remaining value directly instead of a JSON object. For example, text-only responses return a plain string, VTT-only responses return a plain string, and segments-only responses return an array.
188
+ For single-file outputs, if `exclude` leaves only one transcript field and removes metadata, billing, and detected language, the API returns that remaining value directly instead of a JSON object. Text-only responses return a plain string, VTT-only responses return a plain string, and segments-only responses return an array. Multi-file outputs still return JSON so each result stays associated with its `reference_id`.
189
189
 
190
190
  ## Webhooks
191
191
 
package/index.js CHANGED
@@ -1364,8 +1364,6 @@ export class TranscribeAPI {
1364
1364
  : (normalizedItem.durationEstimateSec || await estimateDurationFromFile(normalizedSingleFile));
1365
1365
  const effectiveLanguage = normalizedItem.hasLanguage ? normalizedItem.language : normalizeLanguageCode(language);
1366
1366
  const isAsync = files.length > 1
1367
- || Boolean(normalizedItem.url)
1368
- || Boolean(webhookUrl)
1369
1367
  || (
1370
1368
  normalizedSingleFile
1371
1369
  && (
@@ -1387,6 +1385,18 @@ export class TranscribeAPI {
1387
1385
  });
1388
1386
  }
1389
1387
 
1388
+ if (normalizedItem.url) {
1389
+ return this.transcribeUrlDirect({
1390
+ url: normalizedItem.url,
1391
+ referenceId: normalizedItem.referenceId,
1392
+ language: effectiveLanguage,
1393
+ exclude,
1394
+ webhookUrl,
1395
+ showLogs: showLogs ?? this.showLogs,
1396
+ logger: logger ?? this.logger,
1397
+ });
1398
+ }
1399
+
1390
1400
  return this.transcribeDirect({
1391
1401
  file: normalizedSingleFile,
1392
1402
  referenceId: normalizedItem.referenceId,
@@ -1485,6 +1495,44 @@ export class TranscribeAPI {
1485
1495
  return result;
1486
1496
  }
1487
1497
 
1498
+ async transcribeUrlDirect({
1499
+ url,
1500
+ referenceId,
1501
+ language,
1502
+ exclude,
1503
+ webhookUrl,
1504
+ showLogs = false,
1505
+ logger = console,
1506
+ } = {}) {
1507
+ const form = new FormData();
1508
+ form.set("url", String(url || "").trim());
1509
+ if (String(referenceId || "").trim()) form.set("reference_id", String(referenceId).trim());
1510
+ if (language) form.set("language", language);
1511
+ if (exclude) form.set("exclude", Array.isArray(exclude) ? exclude.join(",") : exclude);
1512
+ if (webhookUrl) form.set("webhook_url", webhookUrl);
1513
+
1514
+ const response = await fetch(`${this.baseUrl}/transcribe`, {
1515
+ method: "POST",
1516
+ headers: {
1517
+ Authorization: `Bearer ${this.apiKey}`,
1518
+ },
1519
+ body: form,
1520
+ });
1521
+ const result = await parseApiResponse(response);
1522
+ if (this.polling && result && typeof result === "object" && result.job_status && !TERMINAL_JOB_STATUSES.has(String(result.job_status))) {
1523
+ return this.waitForJobCompletion(result.job_id, {
1524
+ polling: this.polling,
1525
+ showLogs,
1526
+ logger,
1527
+ initialJob: result,
1528
+ });
1529
+ }
1530
+ if (showLogs && typeof logger?.log === "function") {
1531
+ logger.log(typeof result === "string" ? result : JSON.stringify(result, null, 2));
1532
+ }
1533
+ return result;
1534
+ }
1535
+
1488
1536
  async transcribeMany({
1489
1537
  files,
1490
1538
  webhookUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transcribe-api/sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Official JavaScript SDK for Transcribe API.",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/worker.js CHANGED
@@ -1364,8 +1364,6 @@ export class TranscribeAPI {
1364
1364
  : (normalizedItem.durationEstimateSec || await estimateDurationFromFile(normalizedSingleFile));
1365
1365
  const effectiveLanguage = normalizedItem.hasLanguage ? normalizedItem.language : normalizeLanguageCode(language);
1366
1366
  const isAsync = files.length > 1
1367
- || Boolean(normalizedItem.url)
1368
- || Boolean(webhookUrl)
1369
1367
  || (
1370
1368
  normalizedSingleFile
1371
1369
  && (
@@ -1387,6 +1385,18 @@ export class TranscribeAPI {
1387
1385
  });
1388
1386
  }
1389
1387
 
1388
+ if (normalizedItem.url) {
1389
+ return this.transcribeUrlDirect({
1390
+ url: normalizedItem.url,
1391
+ referenceId: normalizedItem.referenceId,
1392
+ language: effectiveLanguage,
1393
+ exclude,
1394
+ webhookUrl,
1395
+ showLogs: showLogs ?? this.showLogs,
1396
+ logger: logger ?? this.logger,
1397
+ });
1398
+ }
1399
+
1390
1400
  return this.transcribeDirect({
1391
1401
  file: normalizedSingleFile,
1392
1402
  referenceId: normalizedItem.referenceId,
@@ -1485,6 +1495,44 @@ export class TranscribeAPI {
1485
1495
  return result;
1486
1496
  }
1487
1497
 
1498
+ async transcribeUrlDirect({
1499
+ url,
1500
+ referenceId,
1501
+ language,
1502
+ exclude,
1503
+ webhookUrl,
1504
+ showLogs = false,
1505
+ logger = console,
1506
+ } = {}) {
1507
+ const form = new FormData();
1508
+ form.set("url", String(url || "").trim());
1509
+ if (String(referenceId || "").trim()) form.set("reference_id", String(referenceId).trim());
1510
+ if (language) form.set("language", language);
1511
+ if (exclude) form.set("exclude", Array.isArray(exclude) ? exclude.join(",") : exclude);
1512
+ if (webhookUrl) form.set("webhook_url", webhookUrl);
1513
+
1514
+ const response = await fetch(`${this.baseUrl}/transcribe`, {
1515
+ method: "POST",
1516
+ headers: {
1517
+ Authorization: `Bearer ${this.apiKey}`,
1518
+ },
1519
+ body: form,
1520
+ });
1521
+ const result = await parseApiResponse(response);
1522
+ if (this.polling && result && typeof result === "object" && result.job_status && !TERMINAL_JOB_STATUSES.has(String(result.job_status))) {
1523
+ return this.waitForJobCompletion(result.job_id, {
1524
+ polling: this.polling,
1525
+ showLogs,
1526
+ logger,
1527
+ initialJob: result,
1528
+ });
1529
+ }
1530
+ if (showLogs && typeof logger?.log === "function") {
1531
+ logger.log(typeof result === "string" ? result : JSON.stringify(result, null, 2));
1532
+ }
1533
+ return result;
1534
+ }
1535
+
1488
1536
  async transcribeMany({
1489
1537
  files,
1490
1538
  webhookUrl,