@deepgram/sdk 4.9.0 → 4.10.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 (53) hide show
  1. package/README.md +155 -331
  2. package/dist/main/lib/helpers.d.ts.map +1 -1
  3. package/dist/main/lib/helpers.js +11 -2
  4. package/dist/main/lib/helpers.js.map +1 -1
  5. package/dist/main/lib/types/DeepgramSource.d.ts +1 -1
  6. package/dist/main/lib/types/DeepgramSource.d.ts.map +1 -1
  7. package/dist/main/lib/types/GrantTokenSchema.d.ts +10 -0
  8. package/dist/main/lib/types/GrantTokenSchema.d.ts.map +1 -0
  9. package/dist/main/lib/types/GrantTokenSchema.js +3 -0
  10. package/dist/main/lib/types/GrantTokenSchema.js.map +1 -0
  11. package/dist/main/lib/types/index.d.ts +1 -0
  12. package/dist/main/lib/types/index.d.ts.map +1 -1
  13. package/dist/main/lib/types/index.js +1 -0
  14. package/dist/main/lib/types/index.js.map +1 -1
  15. package/dist/main/lib/version.d.ts +1 -1
  16. package/dist/main/lib/version.js +1 -1
  17. package/dist/main/packages/AbstractRestClient.d.ts +1 -1
  18. package/dist/main/packages/AbstractRestClient.d.ts.map +1 -1
  19. package/dist/main/packages/AuthRestClient.d.ts +3 -1
  20. package/dist/main/packages/AuthRestClient.d.ts.map +1 -1
  21. package/dist/main/packages/AuthRestClient.js +6 -2
  22. package/dist/main/packages/AuthRestClient.js.map +1 -1
  23. package/dist/module/lib/helpers.d.ts.map +1 -1
  24. package/dist/module/lib/helpers.js +11 -2
  25. package/dist/module/lib/helpers.js.map +1 -1
  26. package/dist/module/lib/types/DeepgramSource.d.ts +1 -1
  27. package/dist/module/lib/types/DeepgramSource.d.ts.map +1 -1
  28. package/dist/module/lib/types/GrantTokenSchema.d.ts +10 -0
  29. package/dist/module/lib/types/GrantTokenSchema.d.ts.map +1 -0
  30. package/dist/module/lib/types/GrantTokenSchema.js +2 -0
  31. package/dist/module/lib/types/GrantTokenSchema.js.map +1 -0
  32. package/dist/module/lib/types/index.d.ts +1 -0
  33. package/dist/module/lib/types/index.d.ts.map +1 -1
  34. package/dist/module/lib/types/index.js +1 -0
  35. package/dist/module/lib/types/index.js.map +1 -1
  36. package/dist/module/lib/version.d.ts +1 -1
  37. package/dist/module/lib/version.js +1 -1
  38. package/dist/module/packages/AbstractRestClient.d.ts +1 -1
  39. package/dist/module/packages/AbstractRestClient.d.ts.map +1 -1
  40. package/dist/module/packages/AuthRestClient.d.ts +3 -1
  41. package/dist/module/packages/AuthRestClient.d.ts.map +1 -1
  42. package/dist/module/packages/AuthRestClient.js +6 -2
  43. package/dist/module/packages/AuthRestClient.js.map +1 -1
  44. package/dist/umd/deepgram.js +1 -2
  45. package/package.json +1 -1
  46. package/src/lib/helpers.ts +14 -2
  47. package/src/lib/types/DeepgramSource.ts +1 -1
  48. package/src/lib/types/GrantTokenSchema.ts +9 -0
  49. package/src/lib/types/index.ts +1 -0
  50. package/src/lib/version.ts +1 -1
  51. package/src/packages/AbstractRestClient.ts +1 -1
  52. package/src/packages/AuthRestClient.ts +7 -3
  53. package/dist/umd/deepgram.js.LICENSE.txt +0 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepgram/sdk",
3
- "version": "4.9.0",
3
+ "version": "4.10.0",
4
4
  "description": "Isomorphic Javascript client for Deepgram",
5
5
  "keywords": [
6
6
  "javascript",
@@ -9,8 +9,9 @@ import {
9
9
  TranscriptionSchema,
10
10
  } from "./types";
11
11
  import { Headers as CrossFetchHeaders } from "cross-fetch";
12
- import { Readable } from "stream";
12
+ import type { Readable } from "node:stream";
13
13
  import merge from "deepmerge";
14
+ import { isBrowser } from "./runtime";
14
15
 
15
16
  export function stripTrailingSlash(url: string): string {
16
17
  return url.replace(/\/$/, "");
@@ -71,7 +72,18 @@ const isBufferSource = (providedSource: PrerecordedSource): providedSource is Bu
71
72
  };
72
73
 
73
74
  const isReadStreamSource = (providedSource: PrerecordedSource): providedSource is Readable => {
74
- return providedSource != null && providedSource instanceof Readable;
75
+ if (providedSource == null) return false;
76
+
77
+ // In browser environments, there's no Readable stream from Node.js
78
+ if (isBrowser()) return false;
79
+
80
+ // Check for stream-like properties without importing Readable
81
+ return (
82
+ typeof providedSource === "object" &&
83
+ typeof (providedSource as any).pipe === "function" &&
84
+ typeof (providedSource as any).read === "function" &&
85
+ typeof (providedSource as any)._readableState === "object"
86
+ );
75
87
  };
76
88
 
77
89
  export class CallbackUrl extends URL {
@@ -1,4 +1,4 @@
1
- import { Readable } from "stream";
1
+ import type { Readable } from "node:stream";
2
2
 
3
3
  export type PrerecordedSource = UrlSource | Buffer | Readable;
4
4
 
@@ -0,0 +1,9 @@
1
+ export interface GrantTokenSchema extends Record<string, unknown> {
2
+ /**
3
+ * Time to live in seconds for the token. Defaults to 30 seconds.
4
+ * @minimum 1
5
+ * @maximum 3600
6
+ * @example 30
7
+ */
8
+ ttl_seconds?: number;
9
+ }
@@ -27,6 +27,7 @@ export * from "./GetProjectUsageSummaryResponse";
27
27
  export * from "./GetProjectUsageSummarySchema";
28
28
  export * from "./GetTokenDetailsResponse";
29
29
  export * from "./GrantTokenResponse";
30
+ export * from "./GrantTokenSchema";
30
31
  export * from "./ListOnPremCredentialsResponse";
31
32
  export * from "./LiveConfigOptions";
32
33
  export * from "./LiveMetadataEvent";
@@ -1 +1 @@
1
- export const version = "4.9.0";
1
+ export const version = "4.10.0";
@@ -1,5 +1,5 @@
1
1
  import { DeepgramApiError, DeepgramError, DeepgramUnknownError } from "../lib/errors";
2
- import { Readable } from "stream";
2
+ import type { Readable } from "node:stream";
3
3
  import { fetchWithAuth, resolveResponse } from "../lib/fetch";
4
4
  import type { Fetch, FetchOptions, RequestMethodType } from "../lib/types/Fetch";
5
5
  import { AbstractClient } from "./AbstractClient";
@@ -1,6 +1,7 @@
1
1
  import { isDeepgramError } from "../lib/errors";
2
2
  import type { DeepgramResponse } from "../lib/types/DeepgramResponse";
3
3
  import type { GrantTokenResponse } from "../lib/types/GrantTokenResponse";
4
+ import type { GrantTokenSchema } from "../lib/types/GrantTokenSchema";
4
5
  import { AbstractRestClient } from "./AbstractRestClient";
5
6
 
6
7
  export class AuthRestClient extends AbstractRestClient {
@@ -8,17 +9,20 @@ export class AuthRestClient extends AbstractRestClient {
8
9
 
9
10
  /**
10
11
  * Generates a new temporary token for the Deepgram API.
12
+ * @param options Optional configuration options for the token generation. Includes ttl_seconds to set token expiration.
11
13
  * @param endpoint Optional custom endpoint to use for the request. Defaults to ":version/auth/grant".
12
14
  * @returns Object containing the result of the request or an error if one occurred. Result will contain access_token and expires_in properties.
13
15
  */
14
16
  public async grantToken(
17
+ options: GrantTokenSchema = {},
15
18
  endpoint = ":version/auth/grant"
16
19
  ): Promise<DeepgramResponse<GrantTokenResponse>> {
17
20
  try {
18
21
  const requestUrl = this.getRequestUrl(endpoint);
19
- const result: GrantTokenResponse = await this.post(requestUrl, "").then((result) =>
20
- result.json()
21
- );
22
+ const body = JSON.stringify(options);
23
+ const result: GrantTokenResponse = await this.post(requestUrl, body, {
24
+ headers: { "Content-Type": "application/json" },
25
+ }).then((result) => result.json());
22
26
 
23
27
  return { result, error: null };
24
28
  } catch (error) {
@@ -1,10 +0,0 @@
1
- /*!
2
- * The buffer module from node.js, for the browser.
3
- *
4
- * @author Feross Aboukhadijeh <https://feross.org>
5
- * @license MIT
6
- */
7
-
8
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
9
-
10
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */