@deepgram/sdk 4.4.0 → 4.5.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.
Files changed (45) hide show
  1. package/README.md +3 -0
  2. package/dist/main/lib/fetch.d.ts +7 -1
  3. package/dist/main/lib/fetch.d.ts.map +1 -1
  4. package/dist/main/lib/fetch.js +2 -2
  5. package/dist/main/lib/fetch.js.map +1 -1
  6. package/dist/main/lib/types/DeepgramClientOptions.d.ts +5 -2
  7. package/dist/main/lib/types/DeepgramClientOptions.d.ts.map +1 -1
  8. package/dist/main/lib/version.d.ts +1 -1
  9. package/dist/main/lib/version.js +1 -1
  10. package/dist/main/packages/AbstractClient.d.ts +2 -1
  11. package/dist/main/packages/AbstractClient.d.ts.map +1 -1
  12. package/dist/main/packages/AbstractClient.js +19 -8
  13. package/dist/main/packages/AbstractClient.js.map +1 -1
  14. package/dist/main/packages/AbstractLiveClient.d.ts.map +1 -1
  15. package/dist/main/packages/AbstractLiveClient.js +13 -5
  16. package/dist/main/packages/AbstractLiveClient.js.map +1 -1
  17. package/dist/main/packages/AbstractRestClient.d.ts.map +1 -1
  18. package/dist/main/packages/AbstractRestClient.js +2 -1
  19. package/dist/main/packages/AbstractRestClient.js.map +1 -1
  20. package/dist/module/lib/fetch.d.ts +7 -1
  21. package/dist/module/lib/fetch.d.ts.map +1 -1
  22. package/dist/module/lib/fetch.js +2 -2
  23. package/dist/module/lib/fetch.js.map +1 -1
  24. package/dist/module/lib/types/DeepgramClientOptions.d.ts +5 -2
  25. package/dist/module/lib/types/DeepgramClientOptions.d.ts.map +1 -1
  26. package/dist/module/lib/version.d.ts +1 -1
  27. package/dist/module/lib/version.js +1 -1
  28. package/dist/module/packages/AbstractClient.d.ts +2 -1
  29. package/dist/module/packages/AbstractClient.d.ts.map +1 -1
  30. package/dist/module/packages/AbstractClient.js +19 -8
  31. package/dist/module/packages/AbstractClient.js.map +1 -1
  32. package/dist/module/packages/AbstractLiveClient.d.ts.map +1 -1
  33. package/dist/module/packages/AbstractLiveClient.js +13 -5
  34. package/dist/module/packages/AbstractLiveClient.js.map +1 -1
  35. package/dist/module/packages/AbstractRestClient.d.ts.map +1 -1
  36. package/dist/module/packages/AbstractRestClient.js +2 -1
  37. package/dist/module/packages/AbstractRestClient.js.map +1 -1
  38. package/dist/umd/deepgram.js +1 -1
  39. package/package.json +1 -1
  40. package/src/lib/fetch.ts +12 -2
  41. package/src/lib/types/DeepgramClientOptions.ts +5 -2
  42. package/src/lib/version.ts +1 -1
  43. package/src/packages/AbstractClient.ts +18 -10
  44. package/src/packages/AbstractLiveClient.ts +17 -5
  45. package/src/packages/AbstractRestClient.ts +3 -1
@@ -90,7 +90,11 @@ export abstract class AbstractLiveClient extends AbstractClient {
90
90
  }
91
91
 
92
92
  if (!("Authorization" in this.headers)) {
93
- this.headers["Authorization"] = `Token ${key}`; // Add default token
93
+ if (this.accessToken) {
94
+ this.headers["Authorization"] = `Bearer ${this.accessToken}`; // Use token if available
95
+ } else {
96
+ this.headers["Authorization"] = `Token ${key}`; // Add default token
97
+ }
94
98
  }
95
99
  }
96
100
 
@@ -109,6 +113,12 @@ export abstract class AbstractLiveClient extends AbstractClient {
109
113
  };
110
114
 
111
115
  const requestUrl = this.getRequestUrl(endpoint, {}, transcriptionOptions);
116
+ const accessToken = this.accessToken;
117
+ const apiKey = this.key;
118
+
119
+ if (!accessToken && !apiKey) {
120
+ throw new Error("No key or access token provided for WebSocket connection.");
121
+ }
112
122
 
113
123
  /**
114
124
  * Custom websocket transport
@@ -132,7 +142,6 @@ export abstract class AbstractLiveClient extends AbstractClient {
132
142
  headers: this.headers,
133
143
  });
134
144
  console.log(`Using WS package`);
135
- this.setupConnection();
136
145
  });
137
146
  return;
138
147
  }
@@ -141,8 +150,10 @@ export abstract class AbstractLiveClient extends AbstractClient {
141
150
  * Native websocket transport (browser)
142
151
  */
143
152
  if (NATIVE_WEBSOCKET_AVAILABLE) {
144
- this.conn = new WebSocket(requestUrl, ["token", this.namespaceOptions.key]);
145
- this.setupConnection();
153
+ this.conn = new WebSocket(
154
+ requestUrl,
155
+ accessToken ? ["bearer", accessToken] : ["token", apiKey!]
156
+ );
146
157
  return;
147
158
  }
148
159
 
@@ -162,8 +173,9 @@ export abstract class AbstractLiveClient extends AbstractClient {
162
173
  this.conn = new WS(requestUrl, undefined, {
163
174
  headers: this.headers,
164
175
  });
165
- this.setupConnection();
166
176
  });
177
+
178
+ this.setupConnection();
167
179
  }
168
180
 
169
181
  /**
@@ -29,7 +29,9 @@ export abstract class AbstractRestClient extends AbstractClient {
29
29
  );
30
30
  }
31
31
 
32
- this.fetch = fetchWithAuth(this.key, this.namespaceOptions.fetch.client);
32
+ const { accessToken, key: apiKey, fetch: customFetch } = this;
33
+
34
+ this.fetch = fetchWithAuth({ accessToken, apiKey, customFetch });
33
35
 
34
36
  if (this.proxy) {
35
37
  this.baseUrl = this.namespaceOptions.fetch.options.proxy!.url;