@deepgram/sdk 3.3.5 → 3.4.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.
- package/README.md +129 -9
- package/dist/main/DeepgramClient.d.ts +65 -12
- package/dist/main/DeepgramClient.d.ts.map +1 -1
- package/dist/main/DeepgramClient.js +73 -18
- package/dist/main/DeepgramClient.js.map +1 -1
- package/dist/main/index.d.ts +13 -4
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +18 -8
- package/dist/main/index.js.map +1 -1
- package/dist/main/lib/constants.d.ts +16 -7
- package/dist/main/lib/constants.d.ts.map +1 -1
- package/dist/main/lib/constants.js +26 -9
- package/dist/main/lib/constants.js.map +1 -1
- package/dist/main/lib/enums/LiveConnectionState.d.ts +5 -0
- package/dist/main/lib/enums/LiveConnectionState.d.ts.map +1 -1
- package/dist/main/lib/enums/LiveConnectionState.js +5 -0
- package/dist/main/lib/enums/LiveConnectionState.js.map +1 -1
- package/dist/main/lib/enums/LiveTranscriptionEvents.d.ts +24 -3
- package/dist/main/lib/enums/LiveTranscriptionEvents.d.ts.map +1 -1
- package/dist/main/lib/enums/LiveTranscriptionEvents.js +23 -2
- package/dist/main/lib/enums/LiveTranscriptionEvents.js.map +1 -1
- package/dist/main/lib/enums/index.d.ts +2 -2
- package/dist/main/lib/enums/index.d.ts.map +1 -1
- package/dist/main/lib/enums/index.js +16 -5
- package/dist/main/lib/enums/index.js.map +1 -1
- package/dist/main/lib/fetch.d.ts +19 -1
- package/dist/main/lib/fetch.d.ts.map +1 -1
- package/dist/main/lib/fetch.js +19 -1
- package/dist/main/lib/fetch.js.map +1 -1
- package/dist/main/lib/helpers.d.ts +9 -5
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +82 -7
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/types/CreateProjectKeySchema.d.ts +0 -1
- package/dist/main/lib/types/CreateProjectKeySchema.d.ts.map +1 -1
- package/dist/main/lib/types/DeepgramClientOptions.d.ts +75 -8
- package/dist/main/lib/types/DeepgramClientOptions.d.ts.map +1 -1
- package/dist/main/lib/types/Fetch.d.ts +3 -13
- package/dist/main/lib/types/Fetch.d.ts.map +1 -1
- package/dist/main/lib/types/LiveConfigOptions.d.ts +6 -3
- package/dist/main/lib/types/LiveConfigOptions.d.ts.map +1 -1
- package/dist/main/lib/types/TranscriptionSchema.d.ts +0 -1
- package/dist/main/lib/types/TranscriptionSchema.d.ts.map +1 -1
- package/dist/main/lib/types/UpdateProjectMemberScopeSchema.d.ts +1 -1
- package/dist/main/lib/types/UpdateProjectMemberScopeSchema.d.ts.map +1 -1
- package/dist/main/lib/types/UpdateProjectSchema.d.ts +0 -1
- package/dist/main/lib/types/UpdateProjectSchema.d.ts.map +1 -1
- package/dist/main/lib/types/index.d.ts +39 -39
- package/dist/main/lib/types/index.d.ts.map +1 -1
- package/dist/main/lib/types/index.js +53 -0
- package/dist/main/lib/types/index.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/packages/AbstractClient.d.ts +63 -10
- package/dist/main/packages/AbstractClient.d.ts.map +1 -1
- package/dist/main/packages/AbstractClient.js +103 -50
- package/dist/main/packages/AbstractClient.js.map +1 -1
- package/dist/main/packages/AbstractLiveClient.d.ts +114 -0
- package/dist/main/packages/AbstractLiveClient.d.ts.map +1 -0
- package/dist/main/packages/AbstractLiveClient.js +238 -0
- package/dist/main/packages/AbstractLiveClient.js.map +1 -0
- package/dist/main/packages/AbstractRestClient.d.ts +105 -0
- package/dist/main/packages/AbstractRestClient.d.ts.map +1 -0
- package/dist/main/packages/AbstractRestClient.js +185 -0
- package/dist/main/packages/AbstractRestClient.js.map +1 -0
- package/dist/main/packages/ListenClient.d.ts +21 -4
- package/dist/main/packages/ListenClient.d.ts.map +1 -1
- package/dist/main/packages/ListenClient.js +25 -5
- package/dist/main/packages/ListenClient.js.map +1 -1
- package/dist/main/packages/ListenLiveClient.d.ts +58 -0
- package/dist/main/packages/ListenLiveClient.d.ts.map +1 -0
- package/dist/main/packages/ListenLiveClient.js +119 -0
- package/dist/main/packages/ListenLiveClient.js.map +1 -0
- package/dist/main/packages/ListenRestClient.d.ts +57 -0
- package/dist/main/packages/ListenRestClient.d.ts.map +1 -0
- package/dist/main/packages/ListenRestClient.js +167 -0
- package/dist/main/packages/ListenRestClient.js.map +1 -0
- package/dist/main/packages/ManageRestClient.d.ts +286 -0
- package/dist/main/packages/ManageRestClient.d.ts.map +1 -0
- package/dist/main/packages/ManageRestClient.js +628 -0
- package/dist/main/packages/ManageRestClient.js.map +1 -0
- package/dist/main/packages/ReadRestClient.d.ts +57 -0
- package/dist/main/packages/ReadRestClient.d.ts.map +1 -0
- package/dist/main/packages/ReadRestClient.js +165 -0
- package/dist/main/packages/ReadRestClient.js.map +1 -0
- package/dist/main/packages/SelfHostedRestClient.d.ts +47 -0
- package/dist/main/packages/SelfHostedRestClient.d.ts.map +1 -0
- package/dist/main/packages/SelfHostedRestClient.js +120 -0
- package/dist/main/packages/SelfHostedRestClient.js.map +1 -0
- package/dist/main/packages/SpeakRestClient.d.ts +36 -0
- package/dist/main/packages/SpeakRestClient.d.ts.map +1 -0
- package/dist/main/packages/SpeakRestClient.js +84 -0
- package/dist/main/packages/SpeakRestClient.js.map +1 -0
- package/dist/main/packages/index.d.ts +10 -8
- package/dist/main/packages/index.d.ts.map +1 -1
- package/dist/main/packages/index.js +24 -17
- package/dist/main/packages/index.js.map +1 -1
- package/dist/module/DeepgramClient.d.ts +65 -12
- package/dist/module/DeepgramClient.d.ts.map +1 -1
- package/dist/module/DeepgramClient.js +72 -17
- package/dist/module/DeepgramClient.js.map +1 -1
- package/dist/module/index.d.ts +13 -4
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +18 -8
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/constants.d.ts +16 -7
- package/dist/module/lib/constants.d.ts.map +1 -1
- package/dist/module/lib/constants.js +26 -9
- package/dist/module/lib/constants.js.map +1 -1
- package/dist/module/lib/enums/LiveConnectionState.d.ts +5 -0
- package/dist/module/lib/enums/LiveConnectionState.d.ts.map +1 -1
- package/dist/module/lib/enums/LiveConnectionState.js +5 -0
- package/dist/module/lib/enums/LiveConnectionState.js.map +1 -1
- package/dist/module/lib/enums/LiveTranscriptionEvents.d.ts +24 -3
- package/dist/module/lib/enums/LiveTranscriptionEvents.d.ts.map +1 -1
- package/dist/module/lib/enums/LiveTranscriptionEvents.js +23 -2
- package/dist/module/lib/enums/LiveTranscriptionEvents.js.map +1 -1
- package/dist/module/lib/enums/index.d.ts +2 -2
- package/dist/module/lib/enums/index.d.ts.map +1 -1
- package/dist/module/lib/enums/index.js +2 -2
- package/dist/module/lib/enums/index.js.map +1 -1
- package/dist/module/lib/fetch.d.ts +19 -1
- package/dist/module/lib/fetch.d.ts.map +1 -1
- package/dist/module/lib/fetch.js +19 -1
- package/dist/module/lib/fetch.js.map +1 -1
- package/dist/module/lib/helpers.d.ts +9 -5
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js +75 -4
- package/dist/module/lib/helpers.js.map +1 -1
- package/dist/module/lib/types/CreateProjectKeySchema.d.ts +0 -1
- package/dist/module/lib/types/CreateProjectKeySchema.d.ts.map +1 -1
- package/dist/module/lib/types/DeepgramClientOptions.d.ts +75 -8
- package/dist/module/lib/types/DeepgramClientOptions.d.ts.map +1 -1
- package/dist/module/lib/types/Fetch.d.ts +3 -13
- package/dist/module/lib/types/Fetch.d.ts.map +1 -1
- package/dist/module/lib/types/LiveConfigOptions.d.ts +6 -3
- package/dist/module/lib/types/LiveConfigOptions.d.ts.map +1 -1
- package/dist/module/lib/types/TranscriptionSchema.d.ts +0 -1
- package/dist/module/lib/types/TranscriptionSchema.d.ts.map +1 -1
- package/dist/module/lib/types/UpdateProjectMemberScopeSchema.d.ts +1 -1
- package/dist/module/lib/types/UpdateProjectMemberScopeSchema.d.ts.map +1 -1
- package/dist/module/lib/types/UpdateProjectSchema.d.ts +0 -1
- package/dist/module/lib/types/UpdateProjectSchema.d.ts.map +1 -1
- package/dist/module/lib/types/index.d.ts +39 -39
- package/dist/module/lib/types/index.d.ts.map +1 -1
- package/dist/module/lib/types/index.js +39 -1
- package/dist/module/lib/types/index.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/packages/AbstractClient.d.ts +63 -10
- package/dist/module/packages/AbstractClient.d.ts.map +1 -1
- package/dist/module/packages/AbstractClient.js +99 -50
- package/dist/module/packages/AbstractClient.js.map +1 -1
- package/dist/module/packages/AbstractLiveClient.d.ts +114 -0
- package/dist/module/packages/AbstractLiveClient.d.ts.map +1 -0
- package/dist/module/packages/AbstractLiveClient.js +211 -0
- package/dist/module/packages/AbstractLiveClient.js.map +1 -0
- package/dist/module/packages/AbstractRestClient.d.ts +105 -0
- package/dist/module/packages/AbstractRestClient.d.ts.map +1 -0
- package/dist/module/packages/AbstractRestClient.js +178 -0
- package/dist/module/packages/AbstractRestClient.js.map +1 -0
- package/dist/module/packages/ListenClient.d.ts +21 -4
- package/dist/module/packages/ListenClient.d.ts.map +1 -1
- package/dist/module/packages/ListenClient.js +25 -5
- package/dist/module/packages/ListenClient.js.map +1 -1
- package/dist/module/packages/ListenLiveClient.d.ts +58 -0
- package/dist/module/packages/ListenLiveClient.d.ts.map +1 -0
- package/dist/module/packages/ListenLiveClient.js +115 -0
- package/dist/module/packages/ListenLiveClient.js.map +1 -0
- package/dist/module/packages/ListenRestClient.d.ts +57 -0
- package/dist/module/packages/ListenRestClient.d.ts.map +1 -0
- package/dist/module/packages/ListenRestClient.js +163 -0
- package/dist/module/packages/ListenRestClient.js.map +1 -0
- package/dist/module/packages/ManageRestClient.d.ts +286 -0
- package/dist/module/packages/ManageRestClient.d.ts.map +1 -0
- package/dist/module/packages/ManageRestClient.js +624 -0
- package/dist/module/packages/ManageRestClient.js.map +1 -0
- package/dist/module/packages/ReadRestClient.d.ts +57 -0
- package/dist/module/packages/ReadRestClient.d.ts.map +1 -0
- package/dist/module/packages/ReadRestClient.js +161 -0
- package/dist/module/packages/ReadRestClient.js.map +1 -0
- package/dist/module/packages/SelfHostedRestClient.d.ts +47 -0
- package/dist/module/packages/SelfHostedRestClient.d.ts.map +1 -0
- package/dist/module/packages/SelfHostedRestClient.js +116 -0
- package/dist/module/packages/SelfHostedRestClient.js.map +1 -0
- package/dist/module/packages/SpeakRestClient.d.ts +36 -0
- package/dist/module/packages/SpeakRestClient.d.ts.map +1 -0
- package/dist/module/packages/SpeakRestClient.js +80 -0
- package/dist/module/packages/SpeakRestClient.js.map +1 -0
- package/dist/module/packages/index.d.ts +10 -8
- package/dist/module/packages/index.d.ts.map +1 -1
- package/dist/module/packages/index.js +10 -8
- package/dist/module/packages/index.js.map +1 -1
- package/dist/umd/deepgram.js +1 -1
- package/package.json +8 -6
- package/src/DeepgramClient.ts +81 -17
- package/src/index.ts +32 -7
- package/src/lib/constants.ts +33 -13
- package/src/lib/enums/LiveConnectionState.ts +11 -4
- package/src/lib/enums/LiveTranscriptionEvents.ts +27 -4
- package/src/lib/enums/index.ts +2 -2
- package/src/lib/fetch.ts +22 -2
- package/src/lib/helpers.ts +98 -9
- package/src/lib/types/CreateProjectKeySchema.ts +0 -1
- package/src/lib/types/DeepgramClientOptions.ts +75 -11
- package/src/lib/types/Fetch.ts +2 -24
- package/src/lib/types/LiveConfigOptions.ts +7 -3
- package/src/lib/types/TranscriptionSchema.ts +0 -2
- package/src/lib/types/UpdateProjectMemberScopeSchema.ts +1 -1
- package/src/lib/types/UpdateProjectSchema.ts +0 -1
- package/src/lib/types/index.ts +39 -54
- package/src/lib/version.ts +1 -1
- package/src/packages/AbstractClient.ts +129 -61
- package/src/packages/AbstractLiveClient.ts +280 -0
- package/src/packages/AbstractRestClient.ts +221 -0
- package/src/packages/ListenClient.ts +26 -5
- package/src/packages/ListenLiveClient.ts +133 -0
- package/src/packages/ListenRestClient.ts +201 -0
- package/src/packages/ManageRestClient.ts +760 -0
- package/src/packages/ReadRestClient.ts +200 -0
- package/src/packages/SelfHostedRestClient.ts +134 -0
- package/src/packages/SpeakRestClient.ts +79 -0
- package/src/packages/index.ts +10 -8
- package/dist/main/packages/AbstractRestfulClient.d.ts +0 -26
- package/dist/main/packages/AbstractRestfulClient.d.ts.map +0 -1
- package/dist/main/packages/AbstractRestfulClient.js +0 -118
- package/dist/main/packages/AbstractRestfulClient.js.map +0 -1
- package/dist/main/packages/AbstractWsClient.d.ts +0 -10
- package/dist/main/packages/AbstractWsClient.d.ts.map +0 -1
- package/dist/main/packages/AbstractWsClient.js +0 -33
- package/dist/main/packages/AbstractWsClient.js.map +0 -1
- package/dist/main/packages/LiveClient.d.ts +0 -28
- package/dist/main/packages/LiveClient.d.ts.map +0 -1
- package/dist/main/packages/LiveClient.js +0 -110
- package/dist/main/packages/LiveClient.js.map +0 -1
- package/dist/main/packages/ManageClient.d.ts +0 -97
- package/dist/main/packages/ManageClient.d.ts.map +0 -1
- package/dist/main/packages/ManageClient.js +0 -463
- package/dist/main/packages/ManageClient.js.map +0 -1
- package/dist/main/packages/OnPremClient.d.ts +0 -21
- package/dist/main/packages/OnPremClient.d.ts.map +0 -1
- package/dist/main/packages/OnPremClient.js +0 -99
- package/dist/main/packages/OnPremClient.js.map +0 -1
- package/dist/main/packages/PrerecordedClient.d.ts +0 -10
- package/dist/main/packages/PrerecordedClient.d.ts.map +0 -1
- package/dist/main/packages/PrerecordedClient.js +0 -125
- package/dist/main/packages/PrerecordedClient.js.map +0 -1
- package/dist/main/packages/ReadClient.d.ts +0 -10
- package/dist/main/packages/ReadClient.d.ts.map +0 -1
- package/dist/main/packages/ReadClient.js +0 -123
- package/dist/main/packages/ReadClient.js.map +0 -1
- package/dist/main/packages/SpeakClient.d.ts +0 -12
- package/dist/main/packages/SpeakClient.d.ts.map +0 -1
- package/dist/main/packages/SpeakClient.js +0 -57
- package/dist/main/packages/SpeakClient.js.map +0 -1
- package/dist/module/packages/AbstractRestfulClient.d.ts +0 -26
- package/dist/module/packages/AbstractRestfulClient.d.ts.map +0 -1
- package/dist/module/packages/AbstractRestfulClient.js +0 -114
- package/dist/module/packages/AbstractRestfulClient.js.map +0 -1
- package/dist/module/packages/AbstractWsClient.d.ts +0 -10
- package/dist/module/packages/AbstractWsClient.d.ts.map +0 -1
- package/dist/module/packages/AbstractWsClient.js +0 -29
- package/dist/module/packages/AbstractWsClient.js.map +0 -1
- package/dist/module/packages/LiveClient.d.ts +0 -28
- package/dist/module/packages/LiveClient.d.ts.map +0 -1
- package/dist/module/packages/LiveClient.js +0 -106
- package/dist/module/packages/LiveClient.js.map +0 -1
- package/dist/module/packages/ManageClient.d.ts +0 -97
- package/dist/module/packages/ManageClient.d.ts.map +0 -1
- package/dist/module/packages/ManageClient.js +0 -459
- package/dist/module/packages/ManageClient.js.map +0 -1
- package/dist/module/packages/OnPremClient.d.ts +0 -21
- package/dist/module/packages/OnPremClient.d.ts.map +0 -1
- package/dist/module/packages/OnPremClient.js +0 -95
- package/dist/module/packages/OnPremClient.js.map +0 -1
- package/dist/module/packages/PrerecordedClient.d.ts +0 -10
- package/dist/module/packages/PrerecordedClient.d.ts.map +0 -1
- package/dist/module/packages/PrerecordedClient.js +0 -121
- package/dist/module/packages/PrerecordedClient.js.map +0 -1
- package/dist/module/packages/ReadClient.d.ts +0 -10
- package/dist/module/packages/ReadClient.d.ts.map +0 -1
- package/dist/module/packages/ReadClient.js +0 -119
- package/dist/module/packages/ReadClient.js.map +0 -1
- package/dist/module/packages/SpeakClient.d.ts +0 -12
- package/dist/module/packages/SpeakClient.d.ts.map +0 -1
- package/dist/module/packages/SpeakClient.js +0 -53
- package/dist/module/packages/SpeakClient.js.map +0 -1
- package/src/packages/AbstractRestfulClient.ts +0 -160
- package/src/packages/AbstractWsClient.ts +0 -42
- package/src/packages/LiveClient.ts +0 -140
- package/src/packages/ManageClient.ts +0 -584
- package/src/packages/OnPremClient.ts +0 -113
- package/src/packages/PrerecordedClient.ts +0 -162
- package/src/packages/ReadClient.ts +0 -161
- package/src/packages/SpeakClient.ts +0 -50
package/src/lib/constants.ts
CHANGED
|
@@ -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
|
|
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} ${
|
|
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
|
-
|
|
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:
|
|
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 =
|
|
3
|
-
OPEN =
|
|
4
|
-
CLOSING =
|
|
5
|
-
CLOSED =
|
|
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
|
-
|
|
8
|
-
|
|
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
|
}
|
package/src/lib/enums/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
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
|
|
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;
|
package/src/lib/helpers.ts
CHANGED
|
@@ -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
|
|
18
|
-
|
|
19
|
+
export function isBrowser() {
|
|
20
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
21
|
+
}
|
|
19
22
|
|
|
20
|
-
export function
|
|
21
|
-
|
|
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
|
-
|
|
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
|
+
};
|
|
@@ -1,19 +1,83 @@
|
|
|
1
1
|
import { Fetch, FetchOptions } from "./Fetch";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
};
|
package/src/lib/types/Fetch.ts
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
export type Fetch = typeof fetch;
|
|
2
2
|
|
|
3
|
-
export
|
|
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";
|
|
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
|
-
|
|
2
|
-
|
|
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">>;
|
|
@@ -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 {
|
package/src/lib/types/index.ts
CHANGED
|
@@ -1,54 +1,39 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
export
|
|
39
|
-
|
|
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";
|
package/src/lib/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "3.
|
|
1
|
+
export const version = "3.4.1";
|