@deepgram/sdk 5.0.0-alpha.1 → 5.0.0-alpha.2

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.
@@ -3,14 +3,13 @@ import { RUNTIME } from "../runtime/index.mjs";
3
3
  import { toQueryString } from "../url/qs.mjs";
4
4
  import * as Events from "./events.mjs";
5
5
  const getGlobalWebSocket = () => {
6
- // In Node.js, prefer the ws library over the built-in WebSocket for better header support
7
- if (RUNTIME.type === "node") {
8
- return NodeWebSocket;
9
- }
10
- else if (typeof WebSocket !== "undefined") {
6
+ if (typeof WebSocket !== "undefined") {
11
7
  // @ts-ignore
12
8
  return WebSocket;
13
9
  }
10
+ else if (RUNTIME.type === "node") {
11
+ return NodeWebSocket;
12
+ }
14
13
  return undefined;
15
14
  };
16
15
  /**
@@ -86,14 +85,12 @@ export class ReconnectingWebSocket {
86
85
  };
87
86
  this._handleError = (event) => {
88
87
  this._debug("error event", event.message);
89
- // Use a non-1000 close code so _shouldReconnect remains true for retries
90
- this._disconnect(1006, event.message === "TIMEOUT" ? "timeout" : undefined);
88
+ this._disconnect(undefined, event.message === "TIMEOUT" ? "timeout" : undefined);
91
89
  if (this.onerror) {
92
90
  this.onerror(event);
93
91
  }
92
+ this._debug("exec error listeners");
94
93
  this._listeners.error.forEach((listener) => this._callEventListener(event, listener));
95
- // Ensure we can retry by setting _shouldReconnect to true
96
- this._shouldReconnect = true;
97
94
  this._connect();
98
95
  };
99
96
  this._handleClose = (event) => {
@@ -330,18 +327,7 @@ export class ReconnectingWebSocket {
330
327
  }
331
328
  const options = {};
332
329
  if (this._headers) {
333
- // Ensure all header values are strings for ws library
334
- const stringHeaders = {};
335
- for (const [key, value] of Object.entries(this._headers)) {
336
- if (typeof value === "string") {
337
- stringHeaders[key] = value;
338
- }
339
- else if (value != null) {
340
- // Convert non-string values to strings
341
- stringHeaders[key] = String(value);
342
- }
343
- }
344
- options.headers = stringHeaders;
330
+ options.headers = this._headers;
345
331
  }
346
332
  if (this._queryParameters && Object.keys(this._queryParameters).length > 0) {
347
333
  const queryString = toQueryString(this._queryParameters, { arrayFormat: "repeat" });
@@ -395,14 +381,7 @@ export class ReconnectingWebSocket {
395
381
  this._debug("removeListeners");
396
382
  this._ws.removeEventListener("open", this._handleOpen);
397
383
  this._ws.removeEventListener("close", this._handleClose);
398
- if (RUNTIME.type === "node" && this._nodeMessageHandler) {
399
- // Remove the message listener we added with .on()
400
- this._ws.off("message", this._nodeMessageHandler);
401
- this._nodeMessageHandler = undefined;
402
- }
403
- else {
404
- this._ws.removeEventListener("message", this._handleMessage);
405
- }
384
+ this._ws.removeEventListener("message", this._handleMessage);
406
385
  // @ts-ignore
407
386
  this._ws.removeEventListener("error", this._handleError);
408
387
  }
@@ -413,24 +392,7 @@ export class ReconnectingWebSocket {
413
392
  this._debug("addListeners");
414
393
  this._ws.addEventListener("open", this._handleOpen);
415
394
  this._ws.addEventListener("close", this._handleClose);
416
- // For ws library, we need to wrap the message data in a MessageEvent-like object
417
- if (RUNTIME.type === "node") {
418
- // ws library emits data directly via .on(), not as MessageEvent
419
- // Convert Buffer to string for text messages
420
- this._nodeMessageHandler = (data, isBinary) => {
421
- // Convert Buffer to string if it's a text message
422
- let messageData = data;
423
- if (!isBinary && Buffer.isBuffer(data)) {
424
- messageData = data.toString("utf8");
425
- }
426
- const event = { data: messageData, type: "message", target: this._ws };
427
- this._handleMessage(event);
428
- };
429
- this._ws.on("message", this._nodeMessageHandler);
430
- }
431
- else {
432
- this._ws.addEventListener("message", this._handleMessage);
433
- }
395
+ this._ws.addEventListener("message", this._handleMessage);
434
396
  // @ts-ignore
435
397
  this._ws.addEventListener("error", this._handleError);
436
398
  }
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION = "0.0.219";
@@ -0,0 +1 @@
1
+ export const SDK_VERSION = "0.0.219";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepgram/sdk",
3
- "version": "5.0.0-alpha.1",
3
+ "version": "5.0.0-alpha.2",
4
4
  "private": false,
5
5
  "repository": "github:deepgram/deepgram-js-sdk",
6
6
  "license": "MIT",
@@ -53,33 +53,6 @@
53
53
  },
54
54
  "sideEffects": false,
55
55
  "scripts": {
56
- "examples": "pnpm run examples:1 && pnpm run examples:2 && pnpm run examples:3 && pnpm run examples:4 && pnpm run examples:5 && pnpm run examples:6 && pnpm run examples:7 && pnpm run examples:8 && pnpm run examples:9 && pnpm run examples:10 && pnpm run examples:11 && pnpm run examples:12 && pnpm run examples:13 && pnpm run examples:14 && pnpm run examples:15 && pnpm run examples:16 && pnpm run examples:17 && pnpm run examples:18 && pnpm run examples:19 && pnpm run examples:20 && pnpm run examples:21 && pnpm run examples:22 && pnpm run examples:23 && pnpm run examples:24 && pnpm run examples:25",
57
- "examples:1": "node examples/01-authentication-api-key.js",
58
- "examples:2": "node examples/02-authentication-access-token.js",
59
- "examples:3": "node examples/03-authentication-proxy.js",
60
- "examples:4": "node examples/04-transcription-prerecorded-url.js",
61
- "examples:5": "node examples/05-transcription-prerecorded-file.js",
62
- "examples:6": "node examples/06-transcription-prerecorded-callback.js",
63
- "examples:7": "node examples/07-transcription-live-websocket.js",
64
- "examples:8": "node examples/08-transcription-captions.js",
65
- "examples:9": "node examples/09-voice-agent.js",
66
- "examples:10": "node examples/10-text-to-speech-single.js",
67
- "examples:11": "node examples/11-text-to-speech-streaming.js",
68
- "examples:12": "node examples/12-text-intelligence.js",
69
- "examples:13": "node examples/13-management-projects.js",
70
- "examples:14": "node examples/14-management-keys.js",
71
- "examples:15": "node examples/15-management-members.js",
72
- "examples:16": "node examples/16-management-invites.js",
73
- "examples:17": "node examples/17-management-usage.js",
74
- "examples:18": "node examples/18-management-billing.js",
75
- "examples:19": "node examples/19-management-models.js",
76
- "examples:20": "node examples/20-onprem-credentials.js",
77
- "examples:21": "node examples/21-configuration-scoped.js",
78
- "examples:22": "node examples/22-transcription-advanced-options.js",
79
- "examples:23": "node examples/23-file-upload-types.js",
80
- "examples:24": "node examples/24-error-handling.js",
81
- "examples:25": "node examples/25-binary-response.js",
82
- "examples:26": "node examples/26-transcription-live-websocket-v2.js",
83
56
  "format": "biome format --write --skip-parse-errors --no-errors-on-unmatched --max-diagnostics=none",
84
57
  "format:check": "biome format --skip-parse-errors --no-errors-on-unmatched --max-diagnostics=none",
85
58
  "lint": "biome lint --skip-parse-errors --no-errors-on-unmatched --max-diagnostics=none",
@@ -91,6 +64,8 @@
91
64
  "build:esm": "tsc --project ./tsconfig.esm.json && node scripts/rename-to-esm-files.js dist/esm",
92
65
  "test": "vitest",
93
66
  "test:unit": "vitest --project unit",
94
- "test:wire": "vitest --project wire"
67
+ "test:wire": "vitest --project wire",
68
+ "test:browser": "vitest --project browser",
69
+ "test:browser:ui": "vitest --project browser --ui"
95
70
  }
96
71
  }