@deepgram/sdk 3.3.4 → 3.4.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 (300) hide show
  1. package/README.md +129 -9
  2. package/dist/main/DeepgramClient.d.ts +65 -12
  3. package/dist/main/DeepgramClient.d.ts.map +1 -1
  4. package/dist/main/DeepgramClient.js +73 -18
  5. package/dist/main/DeepgramClient.js.map +1 -1
  6. package/dist/main/index.d.ts +13 -4
  7. package/dist/main/index.d.ts.map +1 -1
  8. package/dist/main/index.js +18 -8
  9. package/dist/main/index.js.map +1 -1
  10. package/dist/main/lib/constants.d.ts +16 -7
  11. package/dist/main/lib/constants.d.ts.map +1 -1
  12. package/dist/main/lib/constants.js +26 -9
  13. package/dist/main/lib/constants.js.map +1 -1
  14. package/dist/main/lib/enums/LiveConnectionState.d.ts +5 -0
  15. package/dist/main/lib/enums/LiveConnectionState.d.ts.map +1 -1
  16. package/dist/main/lib/enums/LiveConnectionState.js +5 -0
  17. package/dist/main/lib/enums/LiveConnectionState.js.map +1 -1
  18. package/dist/main/lib/enums/LiveTranscriptionEvents.d.ts +24 -3
  19. package/dist/main/lib/enums/LiveTranscriptionEvents.d.ts.map +1 -1
  20. package/dist/main/lib/enums/LiveTranscriptionEvents.js +23 -2
  21. package/dist/main/lib/enums/LiveTranscriptionEvents.js.map +1 -1
  22. package/dist/main/lib/enums/index.d.ts +2 -2
  23. package/dist/main/lib/enums/index.d.ts.map +1 -1
  24. package/dist/main/lib/enums/index.js +16 -5
  25. package/dist/main/lib/enums/index.js.map +1 -1
  26. package/dist/main/lib/fetch.d.ts +19 -1
  27. package/dist/main/lib/fetch.d.ts.map +1 -1
  28. package/dist/main/lib/fetch.js +19 -1
  29. package/dist/main/lib/fetch.js.map +1 -1
  30. package/dist/main/lib/helpers.d.ts +9 -5
  31. package/dist/main/lib/helpers.d.ts.map +1 -1
  32. package/dist/main/lib/helpers.js +82 -7
  33. package/dist/main/lib/helpers.js.map +1 -1
  34. package/dist/main/lib/types/CreateProjectKeySchema.d.ts +0 -1
  35. package/dist/main/lib/types/CreateProjectKeySchema.d.ts.map +1 -1
  36. package/dist/main/lib/types/DeepgramClientOptions.d.ts +75 -8
  37. package/dist/main/lib/types/DeepgramClientOptions.d.ts.map +1 -1
  38. package/dist/main/lib/types/Fetch.d.ts +3 -13
  39. package/dist/main/lib/types/Fetch.d.ts.map +1 -1
  40. package/dist/main/lib/types/LiveConfigOptions.d.ts +6 -3
  41. package/dist/main/lib/types/LiveConfigOptions.d.ts.map +1 -1
  42. package/dist/main/lib/types/SyncPrerecordedResponse.d.ts +1 -0
  43. package/dist/main/lib/types/SyncPrerecordedResponse.d.ts.map +1 -1
  44. package/dist/main/lib/types/TranscriptionSchema.d.ts +0 -1
  45. package/dist/main/lib/types/TranscriptionSchema.d.ts.map +1 -1
  46. package/dist/main/lib/types/UpdateProjectMemberScopeSchema.d.ts +1 -1
  47. package/dist/main/lib/types/UpdateProjectMemberScopeSchema.d.ts.map +1 -1
  48. package/dist/main/lib/types/UpdateProjectSchema.d.ts +0 -1
  49. package/dist/main/lib/types/UpdateProjectSchema.d.ts.map +1 -1
  50. package/dist/main/lib/types/index.d.ts +39 -39
  51. package/dist/main/lib/types/index.d.ts.map +1 -1
  52. package/dist/main/lib/types/index.js +53 -0
  53. package/dist/main/lib/types/index.js.map +1 -1
  54. package/dist/main/lib/version.d.ts +1 -1
  55. package/dist/main/lib/version.js +1 -1
  56. package/dist/main/packages/AbstractClient.d.ts +63 -10
  57. package/dist/main/packages/AbstractClient.d.ts.map +1 -1
  58. package/dist/main/packages/AbstractClient.js +103 -50
  59. package/dist/main/packages/AbstractClient.js.map +1 -1
  60. package/dist/main/packages/AbstractLiveClient.d.ts +114 -0
  61. package/dist/main/packages/AbstractLiveClient.d.ts.map +1 -0
  62. package/dist/main/packages/AbstractLiveClient.js +238 -0
  63. package/dist/main/packages/AbstractLiveClient.js.map +1 -0
  64. package/dist/main/packages/AbstractRestClient.d.ts +105 -0
  65. package/dist/main/packages/AbstractRestClient.d.ts.map +1 -0
  66. package/dist/main/packages/AbstractRestClient.js +185 -0
  67. package/dist/main/packages/AbstractRestClient.js.map +1 -0
  68. package/dist/main/packages/ListenClient.d.ts +21 -4
  69. package/dist/main/packages/ListenClient.d.ts.map +1 -1
  70. package/dist/main/packages/ListenClient.js +25 -5
  71. package/dist/main/packages/ListenClient.js.map +1 -1
  72. package/dist/main/packages/ListenLiveClient.d.ts +58 -0
  73. package/dist/main/packages/ListenLiveClient.d.ts.map +1 -0
  74. package/dist/main/packages/ListenLiveClient.js +119 -0
  75. package/dist/main/packages/ListenLiveClient.js.map +1 -0
  76. package/dist/main/packages/ListenRestClient.d.ts +57 -0
  77. package/dist/main/packages/ListenRestClient.d.ts.map +1 -0
  78. package/dist/main/packages/ListenRestClient.js +167 -0
  79. package/dist/main/packages/ListenRestClient.js.map +1 -0
  80. package/dist/main/packages/ManageRestClient.d.ts +286 -0
  81. package/dist/main/packages/ManageRestClient.d.ts.map +1 -0
  82. package/dist/main/packages/ManageRestClient.js +628 -0
  83. package/dist/main/packages/ManageRestClient.js.map +1 -0
  84. package/dist/main/packages/ReadRestClient.d.ts +57 -0
  85. package/dist/main/packages/ReadRestClient.d.ts.map +1 -0
  86. package/dist/main/packages/ReadRestClient.js +165 -0
  87. package/dist/main/packages/ReadRestClient.js.map +1 -0
  88. package/dist/main/packages/SelfHostedRestClient.d.ts +47 -0
  89. package/dist/main/packages/SelfHostedRestClient.d.ts.map +1 -0
  90. package/dist/main/packages/SelfHostedRestClient.js +120 -0
  91. package/dist/main/packages/SelfHostedRestClient.js.map +1 -0
  92. package/dist/main/packages/SpeakRestClient.d.ts +36 -0
  93. package/dist/main/packages/SpeakRestClient.d.ts.map +1 -0
  94. package/dist/main/packages/SpeakRestClient.js +84 -0
  95. package/dist/main/packages/SpeakRestClient.js.map +1 -0
  96. package/dist/main/packages/index.d.ts +10 -8
  97. package/dist/main/packages/index.d.ts.map +1 -1
  98. package/dist/main/packages/index.js +24 -17
  99. package/dist/main/packages/index.js.map +1 -1
  100. package/dist/module/DeepgramClient.d.ts +65 -12
  101. package/dist/module/DeepgramClient.d.ts.map +1 -1
  102. package/dist/module/DeepgramClient.js +72 -17
  103. package/dist/module/DeepgramClient.js.map +1 -1
  104. package/dist/module/index.d.ts +13 -4
  105. package/dist/module/index.d.ts.map +1 -1
  106. package/dist/module/index.js +18 -8
  107. package/dist/module/index.js.map +1 -1
  108. package/dist/module/lib/constants.d.ts +16 -7
  109. package/dist/module/lib/constants.d.ts.map +1 -1
  110. package/dist/module/lib/constants.js +26 -9
  111. package/dist/module/lib/constants.js.map +1 -1
  112. package/dist/module/lib/enums/LiveConnectionState.d.ts +5 -0
  113. package/dist/module/lib/enums/LiveConnectionState.d.ts.map +1 -1
  114. package/dist/module/lib/enums/LiveConnectionState.js +5 -0
  115. package/dist/module/lib/enums/LiveConnectionState.js.map +1 -1
  116. package/dist/module/lib/enums/LiveTranscriptionEvents.d.ts +24 -3
  117. package/dist/module/lib/enums/LiveTranscriptionEvents.d.ts.map +1 -1
  118. package/dist/module/lib/enums/LiveTranscriptionEvents.js +23 -2
  119. package/dist/module/lib/enums/LiveTranscriptionEvents.js.map +1 -1
  120. package/dist/module/lib/enums/index.d.ts +2 -2
  121. package/dist/module/lib/enums/index.d.ts.map +1 -1
  122. package/dist/module/lib/enums/index.js +2 -2
  123. package/dist/module/lib/enums/index.js.map +1 -1
  124. package/dist/module/lib/fetch.d.ts +19 -1
  125. package/dist/module/lib/fetch.d.ts.map +1 -1
  126. package/dist/module/lib/fetch.js +19 -1
  127. package/dist/module/lib/fetch.js.map +1 -1
  128. package/dist/module/lib/helpers.d.ts +9 -5
  129. package/dist/module/lib/helpers.d.ts.map +1 -1
  130. package/dist/module/lib/helpers.js +75 -4
  131. package/dist/module/lib/helpers.js.map +1 -1
  132. package/dist/module/lib/types/CreateProjectKeySchema.d.ts +0 -1
  133. package/dist/module/lib/types/CreateProjectKeySchema.d.ts.map +1 -1
  134. package/dist/module/lib/types/DeepgramClientOptions.d.ts +75 -8
  135. package/dist/module/lib/types/DeepgramClientOptions.d.ts.map +1 -1
  136. package/dist/module/lib/types/Fetch.d.ts +3 -13
  137. package/dist/module/lib/types/Fetch.d.ts.map +1 -1
  138. package/dist/module/lib/types/LiveConfigOptions.d.ts +6 -3
  139. package/dist/module/lib/types/LiveConfigOptions.d.ts.map +1 -1
  140. package/dist/module/lib/types/SyncPrerecordedResponse.d.ts +1 -0
  141. package/dist/module/lib/types/SyncPrerecordedResponse.d.ts.map +1 -1
  142. package/dist/module/lib/types/TranscriptionSchema.d.ts +0 -1
  143. package/dist/module/lib/types/TranscriptionSchema.d.ts.map +1 -1
  144. package/dist/module/lib/types/UpdateProjectMemberScopeSchema.d.ts +1 -1
  145. package/dist/module/lib/types/UpdateProjectMemberScopeSchema.d.ts.map +1 -1
  146. package/dist/module/lib/types/UpdateProjectSchema.d.ts +0 -1
  147. package/dist/module/lib/types/UpdateProjectSchema.d.ts.map +1 -1
  148. package/dist/module/lib/types/index.d.ts +39 -39
  149. package/dist/module/lib/types/index.d.ts.map +1 -1
  150. package/dist/module/lib/types/index.js +39 -1
  151. package/dist/module/lib/types/index.js.map +1 -1
  152. package/dist/module/lib/version.d.ts +1 -1
  153. package/dist/module/lib/version.js +1 -1
  154. package/dist/module/packages/AbstractClient.d.ts +63 -10
  155. package/dist/module/packages/AbstractClient.d.ts.map +1 -1
  156. package/dist/module/packages/AbstractClient.js +99 -50
  157. package/dist/module/packages/AbstractClient.js.map +1 -1
  158. package/dist/module/packages/AbstractLiveClient.d.ts +114 -0
  159. package/dist/module/packages/AbstractLiveClient.d.ts.map +1 -0
  160. package/dist/module/packages/AbstractLiveClient.js +211 -0
  161. package/dist/module/packages/AbstractLiveClient.js.map +1 -0
  162. package/dist/module/packages/AbstractRestClient.d.ts +105 -0
  163. package/dist/module/packages/AbstractRestClient.d.ts.map +1 -0
  164. package/dist/module/packages/AbstractRestClient.js +178 -0
  165. package/dist/module/packages/AbstractRestClient.js.map +1 -0
  166. package/dist/module/packages/ListenClient.d.ts +21 -4
  167. package/dist/module/packages/ListenClient.d.ts.map +1 -1
  168. package/dist/module/packages/ListenClient.js +25 -5
  169. package/dist/module/packages/ListenClient.js.map +1 -1
  170. package/dist/module/packages/ListenLiveClient.d.ts +58 -0
  171. package/dist/module/packages/ListenLiveClient.d.ts.map +1 -0
  172. package/dist/module/packages/ListenLiveClient.js +115 -0
  173. package/dist/module/packages/ListenLiveClient.js.map +1 -0
  174. package/dist/module/packages/ListenRestClient.d.ts +57 -0
  175. package/dist/module/packages/ListenRestClient.d.ts.map +1 -0
  176. package/dist/module/packages/ListenRestClient.js +163 -0
  177. package/dist/module/packages/ListenRestClient.js.map +1 -0
  178. package/dist/module/packages/ManageRestClient.d.ts +286 -0
  179. package/dist/module/packages/ManageRestClient.d.ts.map +1 -0
  180. package/dist/module/packages/ManageRestClient.js +624 -0
  181. package/dist/module/packages/ManageRestClient.js.map +1 -0
  182. package/dist/module/packages/ReadRestClient.d.ts +57 -0
  183. package/dist/module/packages/ReadRestClient.d.ts.map +1 -0
  184. package/dist/module/packages/ReadRestClient.js +161 -0
  185. package/dist/module/packages/ReadRestClient.js.map +1 -0
  186. package/dist/module/packages/SelfHostedRestClient.d.ts +47 -0
  187. package/dist/module/packages/SelfHostedRestClient.d.ts.map +1 -0
  188. package/dist/module/packages/SelfHostedRestClient.js +116 -0
  189. package/dist/module/packages/SelfHostedRestClient.js.map +1 -0
  190. package/dist/module/packages/SpeakRestClient.d.ts +36 -0
  191. package/dist/module/packages/SpeakRestClient.d.ts.map +1 -0
  192. package/dist/module/packages/SpeakRestClient.js +80 -0
  193. package/dist/module/packages/SpeakRestClient.js.map +1 -0
  194. package/dist/module/packages/index.d.ts +10 -8
  195. package/dist/module/packages/index.d.ts.map +1 -1
  196. package/dist/module/packages/index.js +10 -8
  197. package/dist/module/packages/index.js.map +1 -1
  198. package/dist/umd/deepgram.js +1 -1
  199. package/package.json +8 -6
  200. package/src/DeepgramClient.ts +81 -17
  201. package/src/index.ts +32 -7
  202. package/src/lib/constants.ts +33 -13
  203. package/src/lib/enums/LiveConnectionState.ts +11 -4
  204. package/src/lib/enums/LiveTranscriptionEvents.ts +27 -4
  205. package/src/lib/enums/index.ts +2 -2
  206. package/src/lib/fetch.ts +22 -2
  207. package/src/lib/helpers.ts +98 -9
  208. package/src/lib/types/CreateProjectKeySchema.ts +0 -1
  209. package/src/lib/types/DeepgramClientOptions.ts +75 -11
  210. package/src/lib/types/Fetch.ts +2 -24
  211. package/src/lib/types/LiveConfigOptions.ts +7 -3
  212. package/src/lib/types/SyncPrerecordedResponse.ts +1 -0
  213. package/src/lib/types/TranscriptionSchema.ts +0 -2
  214. package/src/lib/types/UpdateProjectMemberScopeSchema.ts +1 -1
  215. package/src/lib/types/UpdateProjectSchema.ts +0 -1
  216. package/src/lib/types/index.ts +39 -54
  217. package/src/lib/version.ts +1 -1
  218. package/src/packages/AbstractClient.ts +129 -61
  219. package/src/packages/AbstractLiveClient.ts +280 -0
  220. package/src/packages/AbstractRestClient.ts +221 -0
  221. package/src/packages/ListenClient.ts +26 -5
  222. package/src/packages/ListenLiveClient.ts +133 -0
  223. package/src/packages/ListenRestClient.ts +201 -0
  224. package/src/packages/ManageRestClient.ts +760 -0
  225. package/src/packages/ReadRestClient.ts +200 -0
  226. package/src/packages/SelfHostedRestClient.ts +134 -0
  227. package/src/packages/SpeakRestClient.ts +79 -0
  228. package/src/packages/index.ts +10 -8
  229. package/dist/main/packages/AbstractRestfulClient.d.ts +0 -26
  230. package/dist/main/packages/AbstractRestfulClient.d.ts.map +0 -1
  231. package/dist/main/packages/AbstractRestfulClient.js +0 -118
  232. package/dist/main/packages/AbstractRestfulClient.js.map +0 -1
  233. package/dist/main/packages/AbstractWsClient.d.ts +0 -10
  234. package/dist/main/packages/AbstractWsClient.d.ts.map +0 -1
  235. package/dist/main/packages/AbstractWsClient.js +0 -33
  236. package/dist/main/packages/AbstractWsClient.js.map +0 -1
  237. package/dist/main/packages/LiveClient.d.ts +0 -28
  238. package/dist/main/packages/LiveClient.d.ts.map +0 -1
  239. package/dist/main/packages/LiveClient.js +0 -110
  240. package/dist/main/packages/LiveClient.js.map +0 -1
  241. package/dist/main/packages/ManageClient.d.ts +0 -97
  242. package/dist/main/packages/ManageClient.d.ts.map +0 -1
  243. package/dist/main/packages/ManageClient.js +0 -463
  244. package/dist/main/packages/ManageClient.js.map +0 -1
  245. package/dist/main/packages/OnPremClient.d.ts +0 -21
  246. package/dist/main/packages/OnPremClient.d.ts.map +0 -1
  247. package/dist/main/packages/OnPremClient.js +0 -99
  248. package/dist/main/packages/OnPremClient.js.map +0 -1
  249. package/dist/main/packages/PrerecordedClient.d.ts +0 -10
  250. package/dist/main/packages/PrerecordedClient.d.ts.map +0 -1
  251. package/dist/main/packages/PrerecordedClient.js +0 -125
  252. package/dist/main/packages/PrerecordedClient.js.map +0 -1
  253. package/dist/main/packages/ReadClient.d.ts +0 -10
  254. package/dist/main/packages/ReadClient.d.ts.map +0 -1
  255. package/dist/main/packages/ReadClient.js +0 -123
  256. package/dist/main/packages/ReadClient.js.map +0 -1
  257. package/dist/main/packages/SpeakClient.d.ts +0 -12
  258. package/dist/main/packages/SpeakClient.d.ts.map +0 -1
  259. package/dist/main/packages/SpeakClient.js +0 -57
  260. package/dist/main/packages/SpeakClient.js.map +0 -1
  261. package/dist/module/packages/AbstractRestfulClient.d.ts +0 -26
  262. package/dist/module/packages/AbstractRestfulClient.d.ts.map +0 -1
  263. package/dist/module/packages/AbstractRestfulClient.js +0 -114
  264. package/dist/module/packages/AbstractRestfulClient.js.map +0 -1
  265. package/dist/module/packages/AbstractWsClient.d.ts +0 -10
  266. package/dist/module/packages/AbstractWsClient.d.ts.map +0 -1
  267. package/dist/module/packages/AbstractWsClient.js +0 -29
  268. package/dist/module/packages/AbstractWsClient.js.map +0 -1
  269. package/dist/module/packages/LiveClient.d.ts +0 -28
  270. package/dist/module/packages/LiveClient.d.ts.map +0 -1
  271. package/dist/module/packages/LiveClient.js +0 -106
  272. package/dist/module/packages/LiveClient.js.map +0 -1
  273. package/dist/module/packages/ManageClient.d.ts +0 -97
  274. package/dist/module/packages/ManageClient.d.ts.map +0 -1
  275. package/dist/module/packages/ManageClient.js +0 -459
  276. package/dist/module/packages/ManageClient.js.map +0 -1
  277. package/dist/module/packages/OnPremClient.d.ts +0 -21
  278. package/dist/module/packages/OnPremClient.d.ts.map +0 -1
  279. package/dist/module/packages/OnPremClient.js +0 -95
  280. package/dist/module/packages/OnPremClient.js.map +0 -1
  281. package/dist/module/packages/PrerecordedClient.d.ts +0 -10
  282. package/dist/module/packages/PrerecordedClient.d.ts.map +0 -1
  283. package/dist/module/packages/PrerecordedClient.js +0 -121
  284. package/dist/module/packages/PrerecordedClient.js.map +0 -1
  285. package/dist/module/packages/ReadClient.d.ts +0 -10
  286. package/dist/module/packages/ReadClient.d.ts.map +0 -1
  287. package/dist/module/packages/ReadClient.js +0 -119
  288. package/dist/module/packages/ReadClient.js.map +0 -1
  289. package/dist/module/packages/SpeakClient.d.ts +0 -12
  290. package/dist/module/packages/SpeakClient.d.ts.map +0 -1
  291. package/dist/module/packages/SpeakClient.js +0 -53
  292. package/dist/module/packages/SpeakClient.js.map +0 -1
  293. package/src/packages/AbstractRestfulClient.ts +0 -160
  294. package/src/packages/AbstractWsClient.ts +0 -42
  295. package/src/packages/LiveClient.ts +0 -140
  296. package/src/packages/ManageClient.ts +0 -584
  297. package/src/packages/OnPremClient.ts +0 -113
  298. package/src/packages/PrerecordedClient.ts +0 -162
  299. package/src/packages/ReadClient.ts +0 -161
  300. package/src/packages/SpeakClient.ts +0 -50
@@ -1,28 +1,48 @@
1
- import { isBrowser } from "./helpers";
2
- import { DeepgramClientOptions } from "./types/DeepgramClientOptions";
3
- import { FetchOptions } from "./types/Fetch";
1
+ import { convertProtocolToWs, isBrowser } from "./helpers";
4
2
  import { version } from "./version";
3
+ import type { DefaultNamespaceOptions, DefaultClientOptions } from "./types";
5
4
 
6
5
  export const NODE_VERSION =
7
- typeof process === "undefined" ? "Unknown" : process?.versions?.node || "Unknown";
6
+ typeof process !== "undefined" && process.versions && process.versions.node
7
+ ? process.versions.node
8
+ : "unknown";
9
+
10
+ export const BROWSER_AGENT =
11
+ typeof window !== "undefined" && window.navigator && window.navigator.userAgent
12
+ ? window.navigator.userAgent
13
+ : "unknown";
8
14
 
9
15
  export const DEFAULT_HEADERS = {
10
16
  "Content-Type": `application/json`,
11
17
  "X-Client-Info": `@deepgram/sdk; ${isBrowser() ? "browser" : "server"}; v${version}`,
12
- "User-Agent": `@deepgram/sdk/${version} ${isBrowser() ? "javascript" : `node/${NODE_VERSION}`}`,
18
+ "User-Agent": `@deepgram/sdk/${version} ${
19
+ isBrowser() ? `javascript ${BROWSER_AGENT}` : `node/${NODE_VERSION}`
20
+ }`,
13
21
  };
14
22
 
15
23
  export const DEFAULT_URL = "https://api.deepgram.com";
16
24
 
17
- export const DEFAULT_GLOBAL_OPTIONS = {
18
- url: DEFAULT_URL,
19
- };
20
-
21
- export const DEFAULT_FETCH_OPTIONS: FetchOptions = {
22
- headers: DEFAULT_HEADERS,
25
+ export const DEFAULT_GLOBAL_OPTIONS: Partial<DefaultNamespaceOptions> = {
26
+ fetch: { options: { url: DEFAULT_URL, headers: DEFAULT_HEADERS } },
27
+ websocket: {
28
+ options: { url: convertProtocolToWs(DEFAULT_URL), _nodeOnlyHeaders: DEFAULT_HEADERS },
29
+ },
23
30
  };
24
31
 
25
- export const DEFAULT_OPTIONS: DeepgramClientOptions = {
32
+ export const DEFAULT_OPTIONS: DefaultClientOptions = {
26
33
  global: DEFAULT_GLOBAL_OPTIONS,
27
- fetch: DEFAULT_FETCH_OPTIONS,
28
34
  };
35
+
36
+ export enum SOCKET_STATES {
37
+ connecting = 0,
38
+ open = 1,
39
+ closing = 2,
40
+ closed = 3,
41
+ }
42
+
43
+ export enum CONNECTION_STATE {
44
+ Connecting = "connecting",
45
+ Open = "open",
46
+ Closing = "closing",
47
+ Closed = "closed",
48
+ }
@@ -1,6 +1,13 @@
1
+ import { SOCKET_STATES } from "../constants";
2
+
3
+ /**
4
+ * Enum representing the different states of a live connection.
5
+ *
6
+ * @deprecated Since 3.4. Use `SOCKET_STATES` for generic socket connection states instead.
7
+ */
1
8
  export enum LiveConnectionState {
2
- CONNECTING = 0,
3
- OPEN = 1,
4
- CLOSING = 2,
5
- CLOSED = 3,
9
+ CONNECTING = SOCKET_STATES.connecting,
10
+ OPEN = SOCKET_STATES.open,
11
+ CLOSING = SOCKET_STATES.closing,
12
+ CLOSED = SOCKET_STATES.closed,
6
13
  }
@@ -1,10 +1,33 @@
1
+ /**
2
+ * Enumeration of events related to live transcription.
3
+ *
4
+ * - `Open`: Built-in socket event for when the connection is opened.
5
+ * - `Close`: Built-in socket event for when the connection is closed.
6
+ * - `Error`: Built-in socket event for when an error occurs.
7
+ * - `Transcript`: Event for when a transcript message is received.
8
+ * - `Metadata`: Event for when metadata is received.
9
+ * - `UtteranceEnd`: Event for when an utterance ends.
10
+ * - `SpeechStarted`: Event for when speech is detected.
11
+ * - `Unhandled`: Catch-all event for any other message event.
12
+ */
1
13
  export enum LiveTranscriptionEvents {
14
+ /**
15
+ * Built in socket events.
16
+ */
2
17
  Open = "open",
3
18
  Close = "close",
4
- Transcript = "Results", // exact match to data type from API
5
- Metadata = "Metadata", // exact match to data type from API
6
19
  Error = "error",
7
- Warning = "warning",
8
- UtteranceEnd = "UtteranceEnd", // exact match to data type from API
20
+
21
+ /**
22
+ * Message { type: string }
23
+ */
24
+ Transcript = "Results",
25
+ Metadata = "Metadata",
26
+ UtteranceEnd = "UtteranceEnd",
9
27
  SpeechStarted = "SpeechStarted",
28
+
29
+ /**
30
+ * Catch all for any other message event
31
+ */
32
+ Unhandled = "Unhandled",
10
33
  }
@@ -1,2 +1,2 @@
1
- export { LiveConnectionState } from "./LiveConnectionState";
2
- export { LiveTranscriptionEvents } from "./LiveTranscriptionEvents";
1
+ export * from "./LiveConnectionState";
2
+ export * from "./LiveTranscriptionEvents";
package/src/lib/fetch.ts CHANGED
@@ -1,9 +1,16 @@
1
- import crossFetch from "cross-fetch";
2
1
  import { resolveHeadersConstructor } from "./helpers";
3
- import type { Fetch } from "./types/Fetch";
2
+ import crossFetch from "cross-fetch";
3
+ import type { Fetch } from "./types";
4
4
 
5
+ /**
6
+ * Resolves the appropriate fetch function to use, either a custom fetch function provided as an argument, or the global fetch function if available, or the cross-fetch library if the global fetch function is not available.
7
+ *
8
+ * @param customFetch - An optional custom fetch function to use instead of the global fetch function.
9
+ * @returns A fetch function that can be used to make HTTP requests.
10
+ */
5
11
  export const resolveFetch = (customFetch?: Fetch): Fetch => {
6
12
  let _fetch: Fetch;
13
+
7
14
  if (customFetch) {
8
15
  _fetch = customFetch;
9
16
  } else if (typeof fetch === "undefined") {
@@ -11,9 +18,17 @@ export const resolveFetch = (customFetch?: Fetch): Fetch => {
11
18
  } else {
12
19
  _fetch = fetch;
13
20
  }
21
+
14
22
  return (...args) => _fetch(...args);
15
23
  };
16
24
 
25
+ /**
26
+ * Resolves a fetch function that includes an "Authorization" header with the provided API key.
27
+ *
28
+ * @param apiKey - The API key to include in the "Authorization" header.
29
+ * @param customFetch - An optional custom fetch function to use instead of the global fetch function.
30
+ * @returns A fetch function that can be used to make HTTP requests with the provided API key in the "Authorization" header.
31
+ */
17
32
  export const fetchWithAuth = (apiKey: string, customFetch?: Fetch): Fetch => {
18
33
  const fetch = resolveFetch(customFetch);
19
34
  const HeadersConstructor = resolveHeadersConstructor();
@@ -29,6 +44,11 @@ export const fetchWithAuth = (apiKey: string, customFetch?: Fetch): Fetch => {
29
44
  };
30
45
  };
31
46
 
47
+ /**
48
+ * Resolves the appropriate Response object to use, either the global Response object if available, or the Response object from the cross-fetch library if the global Response object is not available.
49
+ *
50
+ * @returns The appropriate Response object to use for making HTTP requests.
51
+ */
32
52
  export const resolveResponse = async () => {
33
53
  if (typeof Response === "undefined") {
34
54
  return (await import("cross-fetch")).Response;
@@ -1,4 +1,3 @@
1
- import { Headers as CrossFetchHeaders } from "cross-fetch";
2
1
  import {
3
2
  DeepgramClientOptions,
4
3
  FileSource,
@@ -6,7 +5,10 @@ import {
6
5
  UrlSource,
7
6
  TextSource,
8
7
  AnalyzeSource,
8
+ LiveSchema,
9
+ TranscriptionSchema,
9
10
  } from "./types";
11
+ import { Headers as CrossFetchHeaders } from "cross-fetch";
10
12
  import { Readable } from "stream";
11
13
  import merge from "deepmerge";
12
14
 
@@ -14,14 +16,12 @@ export function stripTrailingSlash(url: string): string {
14
16
  return url.replace(/\/$/, "");
15
17
  }
16
18
 
17
- export const isBrowser = () => typeof window !== "undefined";
18
- export const isServer = () => typeof process !== "undefined";
19
+ export function isBrowser() {
20
+ return typeof window !== "undefined" && typeof window.document !== "undefined";
21
+ }
19
22
 
20
- export function applySettingDefaults(
21
- options: DeepgramClientOptions,
22
- defaults: DeepgramClientOptions
23
- ): DeepgramClientOptions {
24
- return merge(defaults, options);
23
+ export function applyDefaults<O, S>(options: Partial<O> = {}, subordinate: Partial<S> = {}): S {
24
+ return merge(subordinate, options);
25
25
  }
26
26
 
27
27
  export function appendSearchParams(
@@ -83,5 +83,94 @@ const isReadStreamSource = (providedSource: PrerecordedSource): providedSource i
83
83
  };
84
84
 
85
85
  export class CallbackUrl extends URL {
86
- private callbackUrl = true;
86
+ public callbackUrl = true;
87
+ }
88
+
89
+ export const convertProtocolToWs = (url: string) => {
90
+ const convert = (string: string) => string.toLowerCase().replace(/^http/, "ws");
91
+
92
+ return convert(url);
93
+ };
94
+
95
+ export const buildRequestUrl = (
96
+ endpoint: string,
97
+ baseUrl: string | URL,
98
+ transcriptionOptions: LiveSchema | TranscriptionSchema
99
+ ): URL => {
100
+ const url = new URL(endpoint, baseUrl);
101
+ appendSearchParams(url.searchParams, transcriptionOptions);
102
+
103
+ return url;
104
+ };
105
+
106
+ export function isLiveSchema(arg: any): arg is LiveSchema {
107
+ return arg && typeof arg.interim_results !== "undefined";
108
+ }
109
+
110
+ export function isDeepgramClientOptions(arg: any): arg is DeepgramClientOptions {
111
+ return arg && typeof arg.global !== "undefined";
87
112
  }
113
+
114
+ export const convertLegacyOptions = (optionsArg: DeepgramClientOptions): DeepgramClientOptions => {
115
+ const newOptions: DeepgramClientOptions = {};
116
+
117
+ if (optionsArg._experimentalCustomFetch) {
118
+ newOptions.global = {
119
+ fetch: {
120
+ client: optionsArg._experimentalCustomFetch,
121
+ },
122
+ };
123
+ }
124
+
125
+ optionsArg = merge(optionsArg, newOptions);
126
+
127
+ if (optionsArg.restProxy?.url) {
128
+ newOptions.global = {
129
+ fetch: {
130
+ options: {
131
+ proxy: {
132
+ url: optionsArg.restProxy?.url,
133
+ },
134
+ },
135
+ },
136
+ };
137
+ }
138
+
139
+ optionsArg = merge(optionsArg, newOptions);
140
+
141
+ if (optionsArg.global?.url) {
142
+ newOptions.global = {
143
+ fetch: {
144
+ options: {
145
+ url: optionsArg.global.url,
146
+ },
147
+ },
148
+ websocket: {
149
+ options: {
150
+ url: optionsArg.global.url,
151
+ },
152
+ },
153
+ };
154
+ }
155
+
156
+ optionsArg = merge(optionsArg, newOptions);
157
+
158
+ if (optionsArg.global?.headers) {
159
+ newOptions.global = {
160
+ fetch: {
161
+ options: {
162
+ headers: optionsArg.global?.headers,
163
+ },
164
+ },
165
+ websocket: {
166
+ options: {
167
+ _nodeOnlyHeaders: optionsArg.global?.headers,
168
+ },
169
+ },
170
+ };
171
+ }
172
+
173
+ optionsArg = merge(optionsArg, newOptions);
174
+
175
+ return optionsArg;
176
+ };
@@ -12,5 +12,4 @@ interface CommonOptions extends Record<string, unknown> {
12
12
  comment: string;
13
13
  scopes: string[];
14
14
  tags?: string[];
15
- [key: string]: unknown;
16
15
  }
@@ -1,19 +1,83 @@
1
1
  import { Fetch, FetchOptions } from "./Fetch";
2
2
 
3
- export interface DeepgramClientOptions {
4
- global?: {
5
- /**
6
- * Optional headers for initializing the client.
7
- */
8
- headers?: Record<string, string>;
9
-
10
- /**
11
- * The URL used to interact with production, On-prem and other Deepgram environments. Defaults to `api.deepgram.com`.
12
- */
13
- url?: string;
3
+ export type IKeyFactory = () => string;
4
+ export type IFetch = typeof fetch;
5
+ export type IWebSocket = typeof WebSocket;
6
+
7
+ interface TransportFetchOptions extends TransportOptions, FetchOptions {}
8
+ interface TransportWebSocketOptions extends TransportOptions {
9
+ _nodeOnlyHeaders?: { [index: string]: any };
10
+ }
11
+
12
+ type TransportUrl = string;
13
+
14
+ interface TransportOptions {
15
+ url?: TransportUrl;
16
+ proxy?: {
17
+ url: TransportUrl;
18
+ };
19
+ }
20
+
21
+ interface ITransport<C, O> {
22
+ client?: C;
23
+ options?: O;
24
+ }
25
+
26
+ export type DefaultNamespaceOptions = {
27
+ key: string;
28
+ fetch: {
29
+ options: { url: TransportUrl };
14
30
  };
31
+ websocket: {
32
+ options: { url: TransportUrl };
33
+ };
34
+ } & NamespaceOptions;
35
+
36
+ export interface NamespaceOptions {
37
+ key?: string;
38
+ fetch?: ITransport<IFetch, TransportFetchOptions>;
39
+ websocket?: ITransport<IWebSocket, TransportWebSocketOptions>;
40
+ }
41
+
42
+ export type DefaultClientOptions = {
43
+ global: Partial<DefaultNamespaceOptions>;
44
+ } & DeepgramClientOptions;
45
+
46
+ /**
47
+ * Configures the options for a Deepgram client.
48
+ *
49
+ * The `DeepgramClientOptions` interface defines the configuration options for a Deepgram client. It includes options for various namespaces, such as `global`, `listen`, `manage`, `onprem`, `read`, and `speak`. Each namespace has its own options for configuring the transport, including the URL, proxy, and options for the fetch and WebSocket clients.
50
+ *
51
+ * The `global` namespace is used to configure options that apply globally to the Deepgram client. The other namespaces are used to configure options specific to different Deepgram API endpoints.
52
+ * Support introductory formats:
53
+ * - fetch: FetchOptions;
54
+ * - _experimentalCustomFetch?: Fetch;
55
+ * - restProxy?: {
56
+ * url: null | string;
57
+ * };
58
+ */
59
+ export interface DeepgramClientOptions {
60
+ key?: string | IKeyFactory;
61
+ global?: NamespaceOptions & { url?: string; headers?: { [index: string]: any } };
62
+ listen?: NamespaceOptions;
63
+ manage?: NamespaceOptions;
64
+ onprem?: NamespaceOptions;
65
+ read?: NamespaceOptions;
66
+ speak?: NamespaceOptions;
67
+
68
+ /**
69
+ * @deprecated as of 3.4, use a namespace like `global` instead
70
+ */
15
71
  fetch?: FetchOptions;
72
+
73
+ /**
74
+ * @deprecated as of 3.4, use a namespace like `global` instead
75
+ */
16
76
  _experimentalCustomFetch?: Fetch;
77
+
78
+ /**
79
+ * @deprecated as of 3.4, use a namespace like `global` instead
80
+ */
17
81
  restProxy?: {
18
82
  url: null | string;
19
83
  };
@@ -1,27 +1,5 @@
1
1
  export type Fetch = typeof fetch;
2
2
 
3
- export interface FetchOptions {
4
- method?: RequestMethodType;
5
- headers?: Record<string, string>;
6
- cache?: "default" | "no-cache" | "reload" | "force-cache" | "only-if-cached"; // default, no-cache, reload, force-cache, only-if-cached
7
- credentials?: "include" | "same-origin" | "omit"; // include, same-origin, omit
8
- redirect?: "manual" | "follow" | "error"; // manual, follow, error
9
- referrerPolicy?: // no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
10
- | "no-referrer"
11
- | "no-referrer-when-downgrade"
12
- | "origin"
13
- | "origin-when-cross-origin"
14
- | "same-origin"
15
- | "strict-origin"
16
- | "strict-origin-when-cross-origin"
17
- | "unsafe-url";
18
- }
3
+ export type FetchOptions = RequestInit & { method?: RequestMethodType; duplex?: string };
19
4
 
20
- export type RequestMethodType = "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; // GET, POST, PUT, DELETE, etc.
21
-
22
- export interface FetchParameters {
23
- /**
24
- * Pass in an AbortController's signal to cancel the request.
25
- */
26
- signal?: AbortSignal;
27
- }
5
+ export type RequestMethodType = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
@@ -1,3 +1,7 @@
1
- export interface LiveConfigOptions {
2
- numerals?: boolean;
3
- }
1
+ import { LiveSchema } from "./TranscriptionSchema";
2
+
3
+ /**
4
+ * Partial configuration options for the LiveSchema, including:
5
+ * - `numerals`: Configures how numerals are handled in the live transcription.
6
+ */
7
+ export type LiveConfigOptions = Partial<Pick<LiveSchema, "numerals">>;
@@ -90,6 +90,7 @@ interface Paragraph {
90
90
  start: number;
91
91
  end: number;
92
92
  num_words: number;
93
+ speaker?: number;
93
94
  }
94
95
 
95
96
  interface ParagraphGroup {
@@ -138,8 +138,6 @@ interface TranscriptionSchema extends Record<string, unknown> {
138
138
  * @see https://developers.deepgram.com/docs/extra-metadata
139
139
  */
140
140
  extra?: string[] | string;
141
-
142
- [key: string]: unknown;
143
141
  }
144
142
 
145
143
  interface PrerecordedSchema extends TranscriptionSchema {
@@ -1,3 +1,3 @@
1
- export interface UpdateProjectMemberScopeSchema {
1
+ export interface UpdateProjectMemberScopeSchema extends Record<string, unknown> {
2
2
  scope: string;
3
3
  }
@@ -1,5 +1,4 @@
1
1
  export interface UpdateProjectSchema extends Record<string, unknown> {
2
2
  name?: string;
3
3
  company?: string;
4
- [key: string]: unknown;
5
4
  }
@@ -1,54 +1,39 @@
1
- export type { AnalyzeSchema } from "./AnalyzeSchema";
2
- export type { AsyncPrerecordedResponse } from "./AsyncPrerecordedResponse";
3
- export type { AsyncAnalyzeResponse } from "./AsyncAnalyzeResponse";
4
- export type { CreateOnPremCredentialsSchema } from "./CreateOnPremCredentialsSchema";
5
- export type { CreateProjectKeySchema } from "./CreateProjectKeySchema";
6
- export type { CreateProjectKeyResponse } from "./CreateProjectKeyResponse";
7
- export type { DeepgramClientOptions } from "./DeepgramClientOptions";
8
- export type { DeepgramResponse } from "./DeepgramResponse";
9
- export type { Fetch } from "./Fetch";
10
- export type {
11
- GetProjectBalanceResponse,
12
- GetProjectBalancesResponse,
13
- } from "./GetProjectBalancesResponse";
14
- export type { GetProjectInvitesResponse } from "./GetProjectInvitesResponse";
15
- export type { GetProjectKeyResponse, GetProjectKeysResponse } from "./GetProjectKeysResponse";
16
- export type { GetProjectMemberScopesResponse } from "./GetProjectMemberScopesResponse";
17
- export type { GetProjectMembersResponse } from "./GetProjectMembersResponse";
18
- export type { GetProjectResponse } from "./GetProjectResponse";
19
- export type { GetProjectsResponse } from "./GetProjectsResponse";
20
- export type { GetProjectUsageFieldsSchema } from "./GetProjectUsageFieldsSchema";
21
- export type { GetProjectUsageFieldsResponse } from "./GetProjectUsageFieldsResponse";
22
- export type {
23
- GetProjectUsageRequestResponse,
24
- GetProjectUsageRequestsResponse,
25
- } from "./GetProjectUsageRequestsResponse";
26
- export type { GetProjectUsageRequestsSchema } from "./GetProjectUsageRequestsSchema";
27
- export type { GetProjectUsageSummarySchema } from "./GetProjectUsageSummarySchema";
28
- export type { GetProjectUsageSummaryResponse } from "./GetProjectUsageSummaryResponse";
29
- export type { GetTokenDetailsResponse } from "./GetTokenDetailsResponse";
30
- export type {
31
- ListOnPremCredentialsResponse,
32
- OnPremCredentialResponse,
33
- } from "./ListOnPremCredentialsResponse";
34
- export type { LiveConfigOptions } from "./LiveConfigOptions";
35
- export type { LiveMetadataEvent } from "./LiveMetadataEvent";
36
- export type { LiveTranscriptionEvent } from "./LiveTranscriptionEvent";
37
- export type { MessageResponse } from "./MessageResponse";
38
- export type {
39
- FileSource,
40
- PrerecordedSource,
41
- UrlSource,
42
- TextSource,
43
- AnalyzeSource,
44
- } from "./DeepgramSource";
45
- export type { SendProjectInviteSchema } from "./SendProjectInviteSchema";
46
- export type { SpeakSchema } from "./SpeakSchema";
47
- export type { SpeechStartedEvent } from "./SpeechStartedEvent";
48
- export type { SyncPrerecordedResponse } from "./SyncPrerecordedResponse";
49
- export type { SyncAnalyzeResponse } from "./SyncAnalyzeResponse";
50
- export type { TranscriptionSchema, PrerecordedSchema, LiveSchema } from "./TranscriptionSchema";
51
- export type { UpdateProjectMemberScopeSchema } from "./UpdateProjectMemberScopeSchema";
52
- export type { UpdateProjectSchema } from "./UpdateProjectSchema";
53
- export type { UtteranceEndEvent } from "./UtteranceEndEvent";
54
- export type { VoidResponse } from "./VoidResponse";
1
+ export * from "./AnalyzeSchema";
2
+ export * from "./AsyncAnalyzeResponse";
3
+ export * from "./AsyncPrerecordedResponse";
4
+ export * from "./CreateOnPremCredentialsSchema";
5
+ export * from "./CreateProjectKeyResponse";
6
+ export * from "./CreateProjectKeySchema";
7
+ export * from "./DeepgramClientOptions";
8
+ export * from "./DeepgramResponse";
9
+ export * from "./DeepgramSource";
10
+ export * from "./Fetch";
11
+ export * from "./GetProjectBalancesResponse";
12
+ export * from "./GetProjectInvitesResponse";
13
+ export * from "./GetProjectKeysResponse";
14
+ export * from "./GetProjectMemberScopesResponse";
15
+ export * from "./GetProjectMembersResponse";
16
+ export * from "./GetProjectResponse";
17
+ export * from "./GetProjectsResponse";
18
+ export * from "./GetProjectUsageFieldsResponse";
19
+ export * from "./GetProjectUsageFieldsSchema";
20
+ export * from "./GetProjectUsageRequestsResponse";
21
+ export * from "./GetProjectUsageRequestsSchema";
22
+ export * from "./GetProjectUsageSummaryResponse";
23
+ export * from "./GetProjectUsageSummarySchema";
24
+ export * from "./GetTokenDetailsResponse";
25
+ export * from "./ListOnPremCredentialsResponse";
26
+ export * from "./LiveConfigOptions";
27
+ export * from "./LiveMetadataEvent";
28
+ export * from "./LiveTranscriptionEvent";
29
+ export * from "./MessageResponse";
30
+ export * from "./SendProjectInviteSchema";
31
+ export * from "./SpeakSchema";
32
+ export * from "./SpeechStartedEvent";
33
+ export * from "./SyncAnalyzeResponse";
34
+ export * from "./SyncPrerecordedResponse";
35
+ export * from "./TranscriptionSchema";
36
+ export * from "./UpdateProjectMemberScopeSchema";
37
+ export * from "./UpdateProjectSchema";
38
+ export * from "./UtteranceEndEvent";
39
+ export * from "./VoidResponse";
@@ -1 +1 @@
1
- export const version = "3.3.4";
1
+ export const version = "3.4.0";