@deepgram/sdk 4.4.0 → 4.5.1

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 +15 -4
  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 +15 -4
  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 +19 -4
  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
@@ -117,6 +127,7 @@ export abstract class AbstractLiveClient extends AbstractClient {
117
127
  this.conn = new this.transport(requestUrl, undefined, {
118
128
  headers: this.headers,
119
129
  });
130
+ this.setupConnection();
120
131
  return;
121
132
  }
122
133
 
@@ -132,8 +143,8 @@ export abstract class AbstractLiveClient extends AbstractClient {
132
143
  headers: this.headers,
133
144
  });
134
145
  console.log(`Using WS package`);
135
- this.setupConnection();
136
146
  });
147
+ this.setupConnection();
137
148
  return;
138
149
  }
139
150
 
@@ -141,7 +152,10 @@ export abstract class AbstractLiveClient extends AbstractClient {
141
152
  * Native websocket transport (browser)
142
153
  */
143
154
  if (NATIVE_WEBSOCKET_AVAILABLE) {
144
- this.conn = new WebSocket(requestUrl, ["token", this.namespaceOptions.key]);
155
+ this.conn = new WebSocket(
156
+ requestUrl,
157
+ accessToken ? ["bearer", accessToken] : ["token", apiKey!]
158
+ );
145
159
  this.setupConnection();
146
160
  return;
147
161
  }
@@ -162,8 +176,9 @@ export abstract class AbstractLiveClient extends AbstractClient {
162
176
  this.conn = new WS(requestUrl, undefined, {
163
177
  headers: this.headers,
164
178
  });
165
- this.setupConnection();
166
179
  });
180
+
181
+ this.setupConnection();
167
182
  }
168
183
 
169
184
  /**
@@ -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;