@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.
- 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/SyncPrerecordedResponse.d.ts +1 -0
- package/dist/main/lib/types/SyncPrerecordedResponse.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/SyncPrerecordedResponse.d.ts +1 -0
- package/dist/module/lib/types/SyncPrerecordedResponse.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/SyncPrerecordedResponse.ts +1 -0
- 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
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { CallbackUrl, appendSearchParams, isTextSource, isUrlSource } from "../lib/helpers";
|
|
2
|
+
import { DeepgramError, isDeepgramError } from "../lib/errors";
|
|
3
|
+
import type {
|
|
4
|
+
AnalyzeSchema,
|
|
5
|
+
AsyncAnalyzeResponse,
|
|
6
|
+
DeepgramResponse,
|
|
7
|
+
SyncAnalyzeResponse,
|
|
8
|
+
TextSource,
|
|
9
|
+
UrlSource,
|
|
10
|
+
} from "../lib/types";
|
|
11
|
+
import { AbstractRestClient } from "./AbstractRestClient";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The `ReadRestClient` class extends the `AbstractRestClient` class and provides methods for analyzing audio sources synchronously and asynchronously.
|
|
15
|
+
*
|
|
16
|
+
* The `analyzeUrl` method analyzes a URL-based audio source synchronously, returning a promise that resolves to the analysis response or an error.
|
|
17
|
+
*
|
|
18
|
+
* The `analyzeText` method analyzes a text-based audio source synchronously, returning a promise that resolves to the analysis response or an error.
|
|
19
|
+
*
|
|
20
|
+
* The `analyzeUrlCallback` method analyzes a URL-based audio source asynchronously, returning a promise that resolves to the analysis response or an error.
|
|
21
|
+
*
|
|
22
|
+
* The `analyzeTextCallback` method analyzes a text-based audio source asynchronously, returning a promise that resolves to the analysis response or an error.
|
|
23
|
+
*/
|
|
24
|
+
export class ReadRestClient extends AbstractRestClient {
|
|
25
|
+
public namespace: string = "read";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Analyzes a URL-based audio source synchronously.
|
|
29
|
+
*
|
|
30
|
+
* @param source - The URL-based audio source to analyze.
|
|
31
|
+
* @param options - Optional analysis options.
|
|
32
|
+
* @param endpoint - The API endpoint to use for the analysis. Defaults to ":version/read".
|
|
33
|
+
* @returns A promise that resolves to the analysis response, or an error if the analysis fails.
|
|
34
|
+
*/
|
|
35
|
+
async analyzeUrl(
|
|
36
|
+
source: UrlSource,
|
|
37
|
+
options?: AnalyzeSchema,
|
|
38
|
+
endpoint = ":version/read"
|
|
39
|
+
): Promise<DeepgramResponse<SyncAnalyzeResponse>> {
|
|
40
|
+
try {
|
|
41
|
+
let body;
|
|
42
|
+
|
|
43
|
+
if (isUrlSource(source)) {
|
|
44
|
+
body = JSON.stringify(source);
|
|
45
|
+
} else {
|
|
46
|
+
throw new DeepgramError("Unknown source type");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (options !== undefined && "callback" in options) {
|
|
50
|
+
throw new DeepgramError(
|
|
51
|
+
"Callback cannot be provided as an option to a synchronous transcription. Use `analyzeUrlCallback` or `analyzeTextCallback` instead."
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const requestUrl = this.getRequestUrl(endpoint, {}, { ...{}, ...options });
|
|
56
|
+
const result: SyncAnalyzeResponse = await this.post(requestUrl, body).then((result) =>
|
|
57
|
+
result.json()
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return { result, error: null };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (isDeepgramError(error)) {
|
|
63
|
+
return { result: null, error };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Analyzes a text-based audio source synchronously.
|
|
72
|
+
*
|
|
73
|
+
* @param source - The text-based audio source to analyze.
|
|
74
|
+
* @param options - Optional analysis options.
|
|
75
|
+
* @param endpoint - The API endpoint to use for the analysis. Defaults to ":version/read".
|
|
76
|
+
* @returns A promise that resolves to the analysis response, or an error if the analysis fails.
|
|
77
|
+
*/
|
|
78
|
+
async analyzeText(
|
|
79
|
+
source: TextSource,
|
|
80
|
+
options?: AnalyzeSchema,
|
|
81
|
+
endpoint = ":version/read"
|
|
82
|
+
): Promise<DeepgramResponse<SyncAnalyzeResponse>> {
|
|
83
|
+
try {
|
|
84
|
+
let body;
|
|
85
|
+
|
|
86
|
+
if (isTextSource(source)) {
|
|
87
|
+
body = JSON.stringify(source);
|
|
88
|
+
} else {
|
|
89
|
+
throw new DeepgramError("Unknown source type");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (options !== undefined && "callback" in options) {
|
|
93
|
+
throw new DeepgramError(
|
|
94
|
+
"Callback cannot be provided as an option to a synchronous requests. Use `analyzeUrlCallback` or `analyzeTextCallback` instead."
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const requestUrl = this.getRequestUrl(endpoint, {}, { ...{}, ...options });
|
|
99
|
+
const result: SyncAnalyzeResponse = await this.post(requestUrl, body).then((result) =>
|
|
100
|
+
result.json()
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return { result, error: null };
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (isDeepgramError(error)) {
|
|
106
|
+
return { result: null, error };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Analyzes a URL-based audio source asynchronously.
|
|
115
|
+
*
|
|
116
|
+
* @param source - The URL-based audio source to analyze.
|
|
117
|
+
* @param callback - The URL to call back with the analysis results.
|
|
118
|
+
* @param options - Optional analysis options.
|
|
119
|
+
* @param endpoint - The API endpoint to use for the analysis. Defaults to ":version/read".
|
|
120
|
+
* @returns A promise that resolves to the analysis response, or an error if the analysis fails.
|
|
121
|
+
*/
|
|
122
|
+
async analyzeUrlCallback(
|
|
123
|
+
source: UrlSource,
|
|
124
|
+
callback: CallbackUrl,
|
|
125
|
+
options?: AnalyzeSchema,
|
|
126
|
+
endpoint = ":version/read"
|
|
127
|
+
): Promise<DeepgramResponse<AsyncAnalyzeResponse>> {
|
|
128
|
+
try {
|
|
129
|
+
let body;
|
|
130
|
+
|
|
131
|
+
if (isUrlSource(source)) {
|
|
132
|
+
body = JSON.stringify(source);
|
|
133
|
+
} else {
|
|
134
|
+
throw new DeepgramError("Unknown source type");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const requestUrl = this.getRequestUrl(
|
|
138
|
+
endpoint,
|
|
139
|
+
{},
|
|
140
|
+
{ ...options, callback: callback.toString() }
|
|
141
|
+
);
|
|
142
|
+
const result: AsyncAnalyzeResponse = await this.post(requestUrl, body).then((result) =>
|
|
143
|
+
result.json()
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return { result, error: null };
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (isDeepgramError(error)) {
|
|
149
|
+
return { result: null, error };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Analyzes a text-based audio source asynchronously.
|
|
158
|
+
*
|
|
159
|
+
* @param source - The text-based audio source to analyze.
|
|
160
|
+
* @param callback - The URL to call back with the analysis results.
|
|
161
|
+
* @param options - Optional analysis options.
|
|
162
|
+
* @param endpoint - The API endpoint to use for the analysis. Defaults to ":version/read".
|
|
163
|
+
* @returns A promise that resolves to the analysis response, or an error if the analysis fails.
|
|
164
|
+
*/
|
|
165
|
+
async analyzeTextCallback(
|
|
166
|
+
source: TextSource,
|
|
167
|
+
callback: CallbackUrl,
|
|
168
|
+
options?: AnalyzeSchema,
|
|
169
|
+
endpoint = ":version/read"
|
|
170
|
+
): Promise<DeepgramResponse<AsyncAnalyzeResponse>> {
|
|
171
|
+
try {
|
|
172
|
+
let body;
|
|
173
|
+
|
|
174
|
+
if (isTextSource(source)) {
|
|
175
|
+
body = JSON.stringify(source);
|
|
176
|
+
} else {
|
|
177
|
+
throw new DeepgramError("Unknown source type");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const requestUrl = this.getRequestUrl(
|
|
181
|
+
endpoint,
|
|
182
|
+
{},
|
|
183
|
+
{ ...options, callback: callback.toString() }
|
|
184
|
+
);
|
|
185
|
+
const result: AsyncAnalyzeResponse = await this.post(requestUrl, body, {
|
|
186
|
+
headers: { "Content-Type": "deepgram/audio+video" },
|
|
187
|
+
}).then((result) => result.json());
|
|
188
|
+
|
|
189
|
+
return { result, error: null };
|
|
190
|
+
} catch (error) {
|
|
191
|
+
if (isDeepgramError(error)) {
|
|
192
|
+
return { result: null, error };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export { ReadRestClient as ReadClient };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { isDeepgramError } from "../lib/errors";
|
|
2
|
+
import type {
|
|
3
|
+
CreateOnPremCredentialsSchema,
|
|
4
|
+
DeepgramResponse,
|
|
5
|
+
ListOnPremCredentialsResponse,
|
|
6
|
+
MessageResponse,
|
|
7
|
+
OnPremCredentialResponse,
|
|
8
|
+
} from "../lib/types";
|
|
9
|
+
import { AbstractRestClient } from "./AbstractRestClient";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The `SelfHostedRestClient` class extends the `AbstractRestClient` class and provides methods for interacting with the Deepgram self-hosted API.
|
|
13
|
+
*
|
|
14
|
+
* This class is used to list, retrieve, create, and delete self-hosted credentials for a Deepgram project.
|
|
15
|
+
*/
|
|
16
|
+
export class SelfHostedRestClient extends AbstractRestClient {
|
|
17
|
+
public namespace: string = "selfhosted";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Lists the self-hosted credentials for a Deepgram project.
|
|
21
|
+
*
|
|
22
|
+
* @param projectId - The ID of the Deepgram project.
|
|
23
|
+
* @returns A promise that resolves to an object containing the list of self-hosted credentials and any error that occurred.
|
|
24
|
+
* @see https://developers.deepgram.com/reference/list-credentials
|
|
25
|
+
*/
|
|
26
|
+
async listCredentials(
|
|
27
|
+
projectId: string,
|
|
28
|
+
endpoint = ":version/projects/:projectId/onprem/distribution/credentials"
|
|
29
|
+
): Promise<DeepgramResponse<ListOnPremCredentialsResponse>> {
|
|
30
|
+
try {
|
|
31
|
+
const requestUrl = this.getRequestUrl(endpoint, { projectId });
|
|
32
|
+
const result: ListOnPremCredentialsResponse = await this.get(requestUrl).then((result) =>
|
|
33
|
+
result.json()
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return { result, error: null };
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (isDeepgramError(error)) {
|
|
39
|
+
return { result: null, error };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the self-hosted credentials for a specific Deepgram project and credentials ID.
|
|
48
|
+
*
|
|
49
|
+
* @param projectId - The ID of the Deepgram project.
|
|
50
|
+
* @param credentialsId - The ID of the self-hosted credentials to retrieve.
|
|
51
|
+
* @returns A promise that resolves to an object containing the self-hosted credentials and any error that occurred.
|
|
52
|
+
* @see https://developers.deepgram.com/reference/get-credentials
|
|
53
|
+
*/
|
|
54
|
+
async getCredentials(
|
|
55
|
+
projectId: string,
|
|
56
|
+
credentialsId: string,
|
|
57
|
+
endpoint = ":version/projects/:projectId/onprem/distribution/credentials/:credentialsId"
|
|
58
|
+
): Promise<DeepgramResponse<OnPremCredentialResponse>> {
|
|
59
|
+
try {
|
|
60
|
+
const requestUrl = this.getRequestUrl(endpoint, { projectId, credentialsId });
|
|
61
|
+
const result: OnPremCredentialResponse = await this.get(requestUrl).then((result) =>
|
|
62
|
+
result.json()
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return { result, error: null };
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (isDeepgramError(error)) {
|
|
68
|
+
return { result: null, error };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Creates self-hosted credentials for a specific Deepgram project.
|
|
77
|
+
*
|
|
78
|
+
* @param projectId - The ID of the Deepgram project.
|
|
79
|
+
* @param options - The options for creating the self-hosted credentials.
|
|
80
|
+
* @returns A promise that resolves to an object containing the created self-hosted credentials and any error that occurred.
|
|
81
|
+
* @see https://developers.deepgram.com/reference/create-credentials
|
|
82
|
+
*/
|
|
83
|
+
async createCredentials(
|
|
84
|
+
projectId: string,
|
|
85
|
+
options: CreateOnPremCredentialsSchema,
|
|
86
|
+
endpoint = ":version/projects/:projectId/onprem/distribution/credentials"
|
|
87
|
+
): Promise<DeepgramResponse<OnPremCredentialResponse>> {
|
|
88
|
+
try {
|
|
89
|
+
const requestUrl = this.getRequestUrl(endpoint, { projectId });
|
|
90
|
+
const body = JSON.stringify(options);
|
|
91
|
+
|
|
92
|
+
const result: OnPremCredentialResponse = await this.post(requestUrl, body).then((result) =>
|
|
93
|
+
result.json()
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return { result, error: null };
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (isDeepgramError(error)) {
|
|
99
|
+
return { result: null, error };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Deletes self-hosted credentials for a specific Deepgram project.
|
|
108
|
+
*
|
|
109
|
+
* @param projectId - The ID of the Deepgram project.
|
|
110
|
+
* @param credentialsId - The ID of the self-hosted credentials to delete.
|
|
111
|
+
* @returns A promise that resolves to an object containing a message response and any error that occurred.
|
|
112
|
+
* @see https://developers.deepgram.com/reference/delete-credentials
|
|
113
|
+
*/
|
|
114
|
+
async deleteCredentials(
|
|
115
|
+
projectId: string,
|
|
116
|
+
credentialsId: string,
|
|
117
|
+
endpoint = ":version/projects/:projectId/onprem/distribution/credentials/:credentialsId"
|
|
118
|
+
): Promise<DeepgramResponse<MessageResponse>> {
|
|
119
|
+
try {
|
|
120
|
+
const requestUrl = this.getRequestUrl(endpoint, { projectId, credentialsId });
|
|
121
|
+
const result: MessageResponse = await this.delete(requestUrl).then((result) => result.json());
|
|
122
|
+
|
|
123
|
+
return { result, error: null };
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (isDeepgramError(error)) {
|
|
126
|
+
return { result: null, error };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { SelfHostedRestClient as OnPremClient };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { DeepgramError, DeepgramUnknownError } from "../lib/errors";
|
|
2
|
+
import { isTextSource } from "../lib/helpers";
|
|
3
|
+
import { SpeakSchema, TextSource } from "../lib/types";
|
|
4
|
+
import { AbstractRestClient } from "./AbstractRestClient";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Provides a client for interacting with the Deepgram Text-to-Speech API.
|
|
8
|
+
*/
|
|
9
|
+
export class SpeakRestClient extends AbstractRestClient {
|
|
10
|
+
public namespace: string = "speak";
|
|
11
|
+
public result: undefined | Response;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Sends a request to the Deepgram Text-to-Speech API to generate audio from the provided text source.
|
|
15
|
+
*
|
|
16
|
+
* @param source - The text source to be converted to audio.
|
|
17
|
+
* @param options - Optional configuration options for the text-to-speech request.
|
|
18
|
+
* @param endpoint - The API endpoint to use for the request. Defaults to ":version/speak".
|
|
19
|
+
* @returns A promise that resolves to the SpeakRestClient instance, which can be used to retrieve the response headers and body.
|
|
20
|
+
* @throws {DeepgramError} If the text source type is unknown.
|
|
21
|
+
* @throws {DeepgramUnknownError} If the request was made before a previous request completed.
|
|
22
|
+
* @see https://developers.deepgram.com/reference/text-to-speech-api
|
|
23
|
+
*/
|
|
24
|
+
async request(
|
|
25
|
+
source: TextSource,
|
|
26
|
+
options?: SpeakSchema,
|
|
27
|
+
endpoint = ":version/speak"
|
|
28
|
+
): Promise<SpeakRestClient> {
|
|
29
|
+
try {
|
|
30
|
+
let body;
|
|
31
|
+
|
|
32
|
+
if (isTextSource(source)) {
|
|
33
|
+
body = JSON.stringify(source);
|
|
34
|
+
} else {
|
|
35
|
+
throw new DeepgramError("Unknown transcription source type");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const requestUrl = this.getRequestUrl(
|
|
39
|
+
endpoint,
|
|
40
|
+
{},
|
|
41
|
+
{ ...{ model: "aura-asteria-en" }, ...options }
|
|
42
|
+
);
|
|
43
|
+
this.result = await this.post(requestUrl, body, {
|
|
44
|
+
headers: { Accept: "audio/*", "Content-Type": "application/json" },
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return this;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves the response body as a readable stream.
|
|
55
|
+
*
|
|
56
|
+
* @returns A promise that resolves to the response body as a readable stream, or `null` if no request has been made yet.
|
|
57
|
+
* @throws {DeepgramUnknownError} If a request has not been made yet.
|
|
58
|
+
*/
|
|
59
|
+
async getStream(): Promise<ReadableStream<Uint8Array> | null> {
|
|
60
|
+
if (!this.result)
|
|
61
|
+
throw new DeepgramUnknownError("Tried to get stream before making request", "");
|
|
62
|
+
|
|
63
|
+
return this.result.body;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves the response headers from the previous request.
|
|
68
|
+
*
|
|
69
|
+
* @returns A promise that resolves to the response headers, or throws a `DeepgramUnknownError` if no request has been made yet.
|
|
70
|
+
*/
|
|
71
|
+
async getHeaders(): Promise<Headers> {
|
|
72
|
+
if (!this.result)
|
|
73
|
+
throw new DeepgramUnknownError("Tried to get headers before making request", "");
|
|
74
|
+
|
|
75
|
+
return this.result.headers;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { SpeakRestClient as SpeakClient };
|
package/src/packages/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
1
|
+
export * from "./AbstractClient";
|
|
2
|
+
export * from "./AbstractLiveClient";
|
|
3
|
+
export * from "./AbstractRestClient";
|
|
4
|
+
export * from "./ListenClient";
|
|
5
|
+
export * from "./ListenLiveClient";
|
|
6
|
+
export * from "./ListenRestClient";
|
|
7
|
+
export * from "./ManageRestClient";
|
|
8
|
+
export * from "./ReadRestClient";
|
|
9
|
+
export * from "./SelfHostedRestClient";
|
|
10
|
+
export * from "./SpeakRestClient";
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { Readable } from "stream";
|
|
4
|
-
import type { Fetch, FetchParameters, RequestMethodType } from "../lib/types/Fetch";
|
|
5
|
-
import { AbstractClient } from "./AbstractClient";
|
|
6
|
-
import { DeepgramClientOptions } from "../lib/types";
|
|
7
|
-
export declare abstract class AbstractRestfulClient extends AbstractClient {
|
|
8
|
-
protected key: string;
|
|
9
|
-
protected options: DeepgramClientOptions;
|
|
10
|
-
protected fetch: Fetch;
|
|
11
|
-
constructor(key: string, options: DeepgramClientOptions);
|
|
12
|
-
protected _getErrorMessage(err: any): string;
|
|
13
|
-
protected handleError(error: unknown, reject: (reason?: any) => void): Promise<void>;
|
|
14
|
-
protected _getRequestParams(method: RequestMethodType, headers?: Record<string, string>, parameters?: FetchParameters, body?: string | Buffer | Readable): {
|
|
15
|
-
[k: string]: any;
|
|
16
|
-
};
|
|
17
|
-
protected _handleRequest(fetcher: Fetch, method: RequestMethodType, url: string | URL, headers?: Record<string, string>, parameters?: FetchParameters, body?: string | Buffer | Readable): Promise<any>;
|
|
18
|
-
protected _handleRawRequest(fetcher: Fetch, method: RequestMethodType, url: string | URL, headers?: Record<string, string>, parameters?: FetchParameters, body?: string | Buffer | Readable): Promise<any>;
|
|
19
|
-
protected get(fetcher: Fetch, url: string | URL, headers?: Record<string, string>, parameters?: FetchParameters): Promise<any>;
|
|
20
|
-
protected post(fetcher: Fetch, url: string | URL, body: string | Buffer | Readable, headers?: Record<string, string>, parameters?: FetchParameters): Promise<any>;
|
|
21
|
-
protected put(fetcher: Fetch, url: string | URL, body: string | Buffer | Readable, headers?: Record<string, string>, parameters?: FetchParameters): Promise<any>;
|
|
22
|
-
protected patch(fetcher: Fetch, url: string | URL, body: string | Buffer | Readable, headers?: Record<string, string>, parameters?: FetchParameters): Promise<any>;
|
|
23
|
-
protected delete(fetcher: Fetch, url: string | URL, headers?: Record<string, string>, parameters?: FetchParameters): Promise<any>;
|
|
24
|
-
private _willProxy;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=AbstractRestfulClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractRestfulClient.d.ts","sourceRoot":"","sources":["../../../src/packages/AbstractRestfulClient.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGrD,8BAAsB,qBAAsB,SAAQ,cAAc;IAGpD,SAAS,CAAC,GAAG,EAAE,MAAM;IAAE,SAAS,CAAC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IC,IAAI,CAClB,OAAO,EAAE,KAAK,EACd,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,EAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,GAAG,CAAC;cAIC,GAAG,CACjB,OAAO,EAAE,KAAK,EACd,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,EAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,GAAG,CAAC;cAIC,KAAK,CACnB,OAAO,EAAE,KAAK,EACd,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,EAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,GAAG,CAAC;cAIC,MAAM,CACpB,OAAO,EAAE,KAAK,EACd,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,GAAG,CAAC;IAIf,OAAO,CAAC,UAAU;CAKnB"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AbstractRestfulClient = void 0;
|
|
13
|
-
const errors_1 = require("../lib/errors");
|
|
14
|
-
const fetch_1 = require("../lib/fetch");
|
|
15
|
-
const AbstractClient_1 = require("./AbstractClient");
|
|
16
|
-
const helpers_1 = require("../lib/helpers");
|
|
17
|
-
class AbstractRestfulClient extends AbstractClient_1.AbstractClient {
|
|
18
|
-
constructor(key, options) {
|
|
19
|
-
super(key, options);
|
|
20
|
-
this.key = key;
|
|
21
|
-
this.options = options;
|
|
22
|
-
if ((0, helpers_1.isBrowser)() && !this._willProxy()) {
|
|
23
|
-
throw new errors_1.DeepgramError("Due to CORS we are unable to support REST-based API calls to our API from the browser. Please consider using a proxy, and including a `restProxy: { url: ''}` in your Deepgram client options.");
|
|
24
|
-
}
|
|
25
|
-
this.fetch = (0, fetch_1.fetchWithAuth)(this.key, options._experimentalCustomFetch);
|
|
26
|
-
}
|
|
27
|
-
_getErrorMessage(err) {
|
|
28
|
-
return err.msg || err.message || err.error_description || err.error || JSON.stringify(err);
|
|
29
|
-
}
|
|
30
|
-
handleError(error, reject) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const Res = yield (0, fetch_1.resolveResponse)();
|
|
33
|
-
if (error instanceof Res) {
|
|
34
|
-
error
|
|
35
|
-
.json()
|
|
36
|
-
.then((err) => {
|
|
37
|
-
reject(new errors_1.DeepgramApiError(this._getErrorMessage(err), error.status || 500));
|
|
38
|
-
})
|
|
39
|
-
.catch((err) => {
|
|
40
|
-
reject(new errors_1.DeepgramUnknownError(this._getErrorMessage(err), err));
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
reject(new errors_1.DeepgramUnknownError(this._getErrorMessage(error), error));
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
_getRequestParams(method, headers, parameters, body) {
|
|
49
|
-
var _a, _b, _c;
|
|
50
|
-
const params = Object.assign(Object.assign({}, (_a = this.options) === null || _a === void 0 ? void 0 : _a.fetch), { method, headers: Object.assign(Object.assign({}, (_c = (_b = this.options) === null || _b === void 0 ? void 0 : _b.fetch) === null || _c === void 0 ? void 0 : _c.headers), headers) || {} });
|
|
51
|
-
if (method === "GET") {
|
|
52
|
-
return params;
|
|
53
|
-
}
|
|
54
|
-
params.body = body;
|
|
55
|
-
params.duplex = "half";
|
|
56
|
-
return Object.assign(Object.assign({}, params), parameters);
|
|
57
|
-
}
|
|
58
|
-
_handleRequest(fetcher, method, url, headers, parameters, body) {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
return new Promise((resolve, reject) => {
|
|
61
|
-
fetcher(url, this._getRequestParams(method, headers, parameters, body))
|
|
62
|
-
.then((result) => {
|
|
63
|
-
if (!result.ok)
|
|
64
|
-
throw result;
|
|
65
|
-
return result.json();
|
|
66
|
-
})
|
|
67
|
-
.then((data) => resolve(data))
|
|
68
|
-
.catch((error) => this.handleError(error, reject));
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
_handleRawRequest(fetcher, method, url, headers, parameters, body) {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
return new Promise((resolve, reject) => {
|
|
75
|
-
fetcher(url, this._getRequestParams(method, headers, parameters, body))
|
|
76
|
-
.then((result) => {
|
|
77
|
-
if (!result.ok)
|
|
78
|
-
throw result;
|
|
79
|
-
return result;
|
|
80
|
-
})
|
|
81
|
-
.then((data) => resolve(data))
|
|
82
|
-
.catch((error) => this.handleError(error, reject));
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
get(fetcher, url, headers, parameters) {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
return this._handleRequest(fetcher, "GET", url, headers, parameters);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
post(fetcher, url, body, headers, parameters) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
return this._handleRequest(fetcher, "POST", url, headers, parameters, body);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
put(fetcher, url, body, headers, parameters) {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
return this._handleRequest(fetcher, "PUT", url, headers, parameters, body);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
patch(fetcher, url, body, headers, parameters) {
|
|
102
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
return this._handleRequest(fetcher, "PATCH", url, headers, parameters, body);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
delete(fetcher, url, headers, parameters) {
|
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
return this._handleRequest(fetcher, "DELETE", url, headers, parameters);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
_willProxy() {
|
|
112
|
-
var _a;
|
|
113
|
-
const proxyUrl = (_a = this.options.restProxy) === null || _a === void 0 ? void 0 : _a.url;
|
|
114
|
-
return !!proxyUrl;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.AbstractRestfulClient = AbstractRestfulClient;
|
|
118
|
-
//# sourceMappingURL=AbstractRestfulClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractRestfulClient.js","sourceRoot":"","sources":["../../../src/packages/AbstractRestfulClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAsF;AAEtF,wCAA8D;AAE9D,qDAAkD;AAElD,4CAA2C;AAE3C,MAAsB,qBAAsB,SAAQ,+BAAc;IAGhE,YAAs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gC,EAChC,UAA4B;;YAE5B,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;QAC/E,CAAC;KAAA;IAEe,MAAM,CACpB,OAAc,EACd,GAAiB,EACjB,OAAgC,EAChC,UAA4B;;YAE5B,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAC1E,CAAC;KAAA;IAEO,UAAU;;QAChB,MAAM,QAAQ,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,SAAS,0CAAE,GAAG,CAAC;QAE7C,OAAO,CAAC,CAAC,QAAQ,CAAC;IACpB,CAAC;CACF;AAvJD,sDAuJC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from "events";
|
|
3
|
-
import { DeepgramClientOptions } from "../lib/types";
|
|
4
|
-
export declare abstract class AbstractWsClient extends EventEmitter {
|
|
5
|
-
protected key: string;
|
|
6
|
-
protected options: DeepgramClientOptions | undefined;
|
|
7
|
-
protected baseUrl: URL;
|
|
8
|
-
constructor(key: string, options?: DeepgramClientOptions | undefined);
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=AbstractWsClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractWsClient.d.ts","sourceRoot":"","sources":["../../../src/packages/AbstractWsClient.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,8BAAsB,gBAAiB,SAAQ,YAAY;IAIvD,SAAS,CAAC,GAAG,EAAE,MAAM;IACrB,SAAS,CAAC,OAAO,EAAE,qBAAqB,GAAG,SAAS;IAJtD,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC;gBAGX,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,qBAAqB,GAAG,SAA2B;CA+BzE"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractWsClient = void 0;
|
|
4
|
-
const events_1 = require("events");
|
|
5
|
-
const constants_1 = require("../lib/constants");
|
|
6
|
-
const helpers_1 = require("../lib/helpers");
|
|
7
|
-
class AbstractWsClient extends events_1.EventEmitter {
|
|
8
|
-
constructor(key, options = constants_1.DEFAULT_OPTIONS) {
|
|
9
|
-
var _a;
|
|
10
|
-
super();
|
|
11
|
-
this.key = key;
|
|
12
|
-
this.options = options;
|
|
13
|
-
this.key = key;
|
|
14
|
-
if (!key) {
|
|
15
|
-
this.key = process.env.DEEPGRAM_API_KEY;
|
|
16
|
-
}
|
|
17
|
-
if (!this.key) {
|
|
18
|
-
throw new Error("A deepgram API key is required");
|
|
19
|
-
}
|
|
20
|
-
this.options = (0, helpers_1.applySettingDefaults)(options, constants_1.DEFAULT_OPTIONS);
|
|
21
|
-
if (!((_a = this.options.global) === null || _a === void 0 ? void 0 : _a.url)) {
|
|
22
|
-
throw new Error(`An API URL is required. It should be set to ${constants_1.DEFAULT_URL} by default. No idea what happened!`);
|
|
23
|
-
}
|
|
24
|
-
let url = this.options.global.url;
|
|
25
|
-
if (!/^https?:\/\//i.test(url)) {
|
|
26
|
-
url = "https://" + url;
|
|
27
|
-
}
|
|
28
|
-
this.baseUrl = new URL((0, helpers_1.stripTrailingSlash)(url));
|
|
29
|
-
this.baseUrl.protocol = this.baseUrl.protocol.toLowerCase().replace(/(http)(s)?/gi, "ws$2");
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.AbstractWsClient = AbstractWsClient;
|
|
33
|
-
//# sourceMappingURL=AbstractWsClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractWsClient.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