@deepgram/sdk 3.3.5 → 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/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
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
import type { Fetch, FetchOptions, RequestMethodType } from "../lib/types/Fetch";
|
|
5
|
+
import { AbstractClient } from "./AbstractClient";
|
|
6
|
+
import { DeepgramClientOptions } from "../lib/types";
|
|
7
|
+
/**
|
|
8
|
+
* An abstract class that extends `AbstractClient` and provides a base implementation for a REST-based API client.
|
|
9
|
+
* This class handles authentication, error handling, and other common functionality for REST API clients.
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class AbstractRestClient extends AbstractClient {
|
|
12
|
+
protected fetch: Fetch;
|
|
13
|
+
/**
|
|
14
|
+
* Constructs a new instance of the `AbstractRestClient` class with the provided options.
|
|
15
|
+
*
|
|
16
|
+
* @param options - The client options to use for this instance.
|
|
17
|
+
* @throws {DeepgramError} If the client is being used in a browser and no proxy is provided.
|
|
18
|
+
*/
|
|
19
|
+
constructor(options: DeepgramClientOptions);
|
|
20
|
+
/**
|
|
21
|
+
* Constructs an error message from the provided error object.
|
|
22
|
+
*
|
|
23
|
+
* @param err - The error object to extract the error message from.
|
|
24
|
+
* @returns The constructed error message.
|
|
25
|
+
*/
|
|
26
|
+
protected _getErrorMessage(err: any): string;
|
|
27
|
+
/**
|
|
28
|
+
* Handles an error that occurred during a request.
|
|
29
|
+
*
|
|
30
|
+
* @param error - The error that occurred during the request.
|
|
31
|
+
* @param reject - The rejection function to call with the error.
|
|
32
|
+
* @returns A Promise that resolves when the error has been handled.
|
|
33
|
+
*/
|
|
34
|
+
protected _handleError(error: unknown, reject: (reason?: any) => void): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Constructs the options object to be used for a fetch request.
|
|
37
|
+
*
|
|
38
|
+
* @param method - The HTTP method to use for the request, such as "GET", "POST", "PUT", "PATCH", or "DELETE".
|
|
39
|
+
* @param bodyOrOptions - For "POST", "PUT", and "PATCH" requests, the request body as a string, Buffer, or Readable stream. For "GET" and "DELETE" requests, the fetch options to use.
|
|
40
|
+
* @param options - Additional fetch options to use for the request.
|
|
41
|
+
* @returns The constructed fetch options object.
|
|
42
|
+
*/
|
|
43
|
+
protected _getRequestOptions(method: RequestMethodType, bodyOrOptions?: string | Buffer | Readable | FetchOptions, options?: FetchOptions): FetchOptions;
|
|
44
|
+
/**
|
|
45
|
+
* Handles an HTTP request using the provided method, URL, and optional request body and options.
|
|
46
|
+
*
|
|
47
|
+
* @param method - The HTTP method to use for the request, such as "GET", "POST", "PUT", "PATCH", or "DELETE".
|
|
48
|
+
* @param url - The URL to send the request to.
|
|
49
|
+
* @param bodyOrOptions - For "POST", "PUT", and "PATCH" requests, the request body as a string, Buffer, or Readable stream. For "GET" and "DELETE" requests, the fetch options to use.
|
|
50
|
+
* @param options - Additional fetch options to use for the request.
|
|
51
|
+
* @returns A Promise that resolves to the Response object for the request.
|
|
52
|
+
*/
|
|
53
|
+
protected _handleRequest(method: "GET" | "DELETE", url: URL, options?: FetchOptions): Promise<Response>;
|
|
54
|
+
protected _handleRequest(method: "POST" | "PUT" | "PATCH", url: URL, body: string | Buffer | Readable, options?: FetchOptions): Promise<Response>;
|
|
55
|
+
/**
|
|
56
|
+
* Handles an HTTP GET request using the provided URL and optional request options.
|
|
57
|
+
*
|
|
58
|
+
* @param url - The URL to send the GET request to.
|
|
59
|
+
* @param options - Additional fetch options to use for the GET request.
|
|
60
|
+
* @returns A Promise that resolves to the Response object for the GET request.
|
|
61
|
+
*/
|
|
62
|
+
protected get(url: URL, options?: FetchOptions): Promise<any>;
|
|
63
|
+
/**
|
|
64
|
+
* Handles an HTTP POST request using the provided URL, request body, and optional request options.
|
|
65
|
+
*
|
|
66
|
+
* @param url - The URL to send the POST request to.
|
|
67
|
+
* @param body - The request body as a string, Buffer, or Readable stream.
|
|
68
|
+
* @param options - Additional fetch options to use for the POST request.
|
|
69
|
+
* @returns A Promise that resolves to the Response object for the POST request.
|
|
70
|
+
*/
|
|
71
|
+
protected post(url: URL, body: string | Buffer | Readable, options?: FetchOptions): Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* Handles an HTTP PUT request using the provided URL, request body, and optional request options.
|
|
74
|
+
*
|
|
75
|
+
* @param url - The URL to send the PUT request to.
|
|
76
|
+
* @param body - The request body as a string, Buffer, or Readable stream.
|
|
77
|
+
* @param options - Additional fetch options to use for the PUT request.
|
|
78
|
+
* @returns A Promise that resolves to the Response object for the PUT request.
|
|
79
|
+
*/
|
|
80
|
+
protected put(url: URL, body: string | Buffer | Readable, options?: FetchOptions): Promise<any>;
|
|
81
|
+
/**
|
|
82
|
+
* Handles an HTTP PATCH request using the provided URL, request body, and optional request options.
|
|
83
|
+
*
|
|
84
|
+
* @param url - The URL to send the PATCH request to.
|
|
85
|
+
* @param body - The request body as a string, Buffer, or Readable stream.
|
|
86
|
+
* @param options - Additional fetch options to use for the PATCH request.
|
|
87
|
+
* @returns A Promise that resolves to the Response object for the PATCH request.
|
|
88
|
+
*/
|
|
89
|
+
protected patch(url: URL, body: string | Buffer | Readable, options?: FetchOptions): Promise<any>;
|
|
90
|
+
/**
|
|
91
|
+
* Handles an HTTP DELETE request using the provided URL and optional request options.
|
|
92
|
+
*
|
|
93
|
+
* @param url - The URL to send the DELETE request to.
|
|
94
|
+
* @param options - Additional fetch options to use for the DELETE request.
|
|
95
|
+
* @returns A Promise that resolves to the Response object for the DELETE request.
|
|
96
|
+
*/
|
|
97
|
+
protected delete(url: URL, options?: FetchOptions): Promise<any>;
|
|
98
|
+
/**
|
|
99
|
+
* Determines whether the current instance should proxy requests.
|
|
100
|
+
* @returns {boolean} true if the current instance should proxy requests; otherwise, false
|
|
101
|
+
*/
|
|
102
|
+
get proxy(): boolean;
|
|
103
|
+
}
|
|
104
|
+
export { AbstractRestClient as AbstractRestfulClient };
|
|
105
|
+
//# sourceMappingURL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Q,CAAC;IAmBpB;;;;;;OAMG;cACa,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC;IAInE;;;;;;;OAOG;cACa,IAAI,CAClB,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,EAChC,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,GAAG,CAAC;IAIf;;;;;;;OAOG;cACa,GAAG,CACjB,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,EAChC,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,GAAG,CAAC;IAIf;;;;;;;OAOG;cACa,KAAK,CACnB,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,EAChC,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,GAAG,CAAC;IAIf;;;;;;OAMG;cACa,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC;IAItE;;;OAGG;IACH,IAAI,KAAK,IAAI,OAAO,CAEnB;CACF;AAED,OAAO,EAAE,kBAAkB,IAAI,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { DeepgramApiError, DeepgramError, DeepgramUnknownError } from "../lib/errors";
|
|
11
|
+
import { fetchWithAuth, resolveResponse } from "../lib/fetch";
|
|
12
|
+
import { AbstractClient } from "./AbstractClient";
|
|
13
|
+
import { isBrowser } from "../lib/helpers";
|
|
14
|
+
import merge from "deepmerge";
|
|
15
|
+
/**
|
|
16
|
+
* An abstract class that extends `AbstractClient` and provides a base implementation for a REST-based API client.
|
|
17
|
+
* This class handles authentication, error handling, and other common functionality for REST API clients.
|
|
18
|
+
*/
|
|
19
|
+
export class AbstractRestClient extends AbstractClient {
|
|
20
|
+
/**
|
|
21
|
+
* Constructs a new instance of the `AbstractRestClient` class with the provided options.
|
|
22
|
+
*
|
|
23
|
+
* @param options - The client options to use for this instance.
|
|
24
|
+
* @throws {DeepgramError} If the client is being used in a browser and no proxy is provided.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options) {
|
|
27
|
+
super(options);
|
|
28
|
+
if (isBrowser() && !this.proxy) {
|
|
29
|
+
throw new DeepgramError("Due to CORS we are unable to support REST-based API calls to our API from the browser. Please consider using a proxy: https://dpgr.am/js-proxy for more information.");
|
|
30
|
+
}
|
|
31
|
+
this.fetch = fetchWithAuth(this.key, this.namespaceOptions.fetch.client);
|
|
32
|
+
if (this.proxy) {
|
|
33
|
+
this.baseUrl = this.namespaceOptions.fetch.options.proxy.url;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.baseUrl = this.namespaceOptions.fetch.options.url;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Constructs an error message from the provided error object.
|
|
41
|
+
*
|
|
42
|
+
* @param err - The error object to extract the error message from.
|
|
43
|
+
* @returns The constructed error message.
|
|
44
|
+
*/
|
|
45
|
+
_getErrorMessage(err) {
|
|
46
|
+
return err.msg || err.message || err.error_description || err.error || JSON.stringify(err);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Handles an error that occurred during a request.
|
|
50
|
+
*
|
|
51
|
+
* @param error - The error that occurred during the request.
|
|
52
|
+
* @param reject - The rejection function to call with the error.
|
|
53
|
+
* @returns A Promise that resolves when the error has been handled.
|
|
54
|
+
*/
|
|
55
|
+
_handleError(error, reject) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const Res = yield resolveResponse();
|
|
58
|
+
if (error instanceof Res) {
|
|
59
|
+
error
|
|
60
|
+
.json()
|
|
61
|
+
.then((err) => {
|
|
62
|
+
reject(new DeepgramApiError(this._getErrorMessage(err), error.status || 500));
|
|
63
|
+
})
|
|
64
|
+
.catch((err) => {
|
|
65
|
+
reject(new DeepgramUnknownError(this._getErrorMessage(err), err));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
reject(new DeepgramUnknownError(this._getErrorMessage(error), error));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Constructs the options object to be used for a fetch request.
|
|
75
|
+
*
|
|
76
|
+
* @param method - The HTTP method to use for the request, such as "GET", "POST", "PUT", "PATCH", or "DELETE".
|
|
77
|
+
* @param bodyOrOptions - For "POST", "PUT", and "PATCH" requests, the request body as a string, Buffer, or Readable stream. For "GET" and "DELETE" requests, the fetch options to use.
|
|
78
|
+
* @param options - Additional fetch options to use for the request.
|
|
79
|
+
* @returns The constructed fetch options object.
|
|
80
|
+
*/
|
|
81
|
+
_getRequestOptions(method, bodyOrOptions, options) {
|
|
82
|
+
let reqOptions = { method };
|
|
83
|
+
if (method === "GET" || method === "DELETE") {
|
|
84
|
+
reqOptions = Object.assign(Object.assign({}, reqOptions), bodyOrOptions);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
reqOptions = Object.assign(Object.assign({ duplex: "half", body: bodyOrOptions }, reqOptions), options);
|
|
88
|
+
}
|
|
89
|
+
return merge(this.namespaceOptions.fetch.options, reqOptions, { clone: false });
|
|
90
|
+
}
|
|
91
|
+
_handleRequest(method, url, bodyOrOptions, options) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
const fetcher = this.fetch;
|
|
95
|
+
fetcher(url, this._getRequestOptions(method, bodyOrOptions, options))
|
|
96
|
+
.then((result) => {
|
|
97
|
+
if (!result.ok)
|
|
98
|
+
throw result;
|
|
99
|
+
resolve(result);
|
|
100
|
+
})
|
|
101
|
+
.catch((error) => this._handleError(error, reject));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Handles an HTTP GET request using the provided URL and optional request options.
|
|
107
|
+
*
|
|
108
|
+
* @param url - The URL to send the GET request to.
|
|
109
|
+
* @param options - Additional fetch options to use for the GET request.
|
|
110
|
+
* @returns A Promise that resolves to the Response object for the GET request.
|
|
111
|
+
*/
|
|
112
|
+
get(url, options) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
return this._handleRequest("GET", url, options);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Handles an HTTP POST request using the provided URL, request body, and optional request options.
|
|
119
|
+
*
|
|
120
|
+
* @param url - The URL to send the POST request to.
|
|
121
|
+
* @param body - The request body as a string, Buffer, or Readable stream.
|
|
122
|
+
* @param options - Additional fetch options to use for the POST request.
|
|
123
|
+
* @returns A Promise that resolves to the Response object for the POST request.
|
|
124
|
+
*/
|
|
125
|
+
post(url, body, options) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
return this._handleRequest("POST", url, body, options);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Handles an HTTP PUT request using the provided URL, request body, and optional request options.
|
|
132
|
+
*
|
|
133
|
+
* @param url - The URL to send the PUT request to.
|
|
134
|
+
* @param body - The request body as a string, Buffer, or Readable stream.
|
|
135
|
+
* @param options - Additional fetch options to use for the PUT request.
|
|
136
|
+
* @returns A Promise that resolves to the Response object for the PUT request.
|
|
137
|
+
*/
|
|
138
|
+
put(url, body, options) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
return this._handleRequest("PUT", url, body, options);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Handles an HTTP PATCH request using the provided URL, request body, and optional request options.
|
|
145
|
+
*
|
|
146
|
+
* @param url - The URL to send the PATCH request to.
|
|
147
|
+
* @param body - The request body as a string, Buffer, or Readable stream.
|
|
148
|
+
* @param options - Additional fetch options to use for the PATCH request.
|
|
149
|
+
* @returns A Promise that resolves to the Response object for the PATCH request.
|
|
150
|
+
*/
|
|
151
|
+
patch(url, body, options) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
return this._handleRequest("PATCH", url, body, options);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Handles an HTTP DELETE request using the provided URL and optional request options.
|
|
158
|
+
*
|
|
159
|
+
* @param url - The URL to send the DELETE request to.
|
|
160
|
+
* @param options - Additional fetch options to use for the DELETE request.
|
|
161
|
+
* @returns A Promise that resolves to the Response object for the DELETE request.
|
|
162
|
+
*/
|
|
163
|
+
delete(url, options) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
return this._handleRequest("DELETE", url, options);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Determines whether the current instance should proxy requests.
|
|
170
|
+
* @returns {boolean} true if the current instance should proxy requests; otherwise, false
|
|
171
|
+
*/
|
|
172
|
+
get proxy() {
|
|
173
|
+
var _a;
|
|
174
|
+
return this.key === "proxy" && !!((_a = this.namespaceOptions.fetch.options.proxy) === null || _a === void 0 ? void 0 : _a.url);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export { AbstractRestClient as AbstractRestfulClient };
|
|
178
|
+
//# sourceMappingURL=AbstractRestClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractRestClient.js","sourceRoot":"","sources":["../../../src/packages/AbstractRestClient.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAEtF,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,MAAM,WAAW,CAAC;AAE9B;;;GAGG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,cAAc;IAG7D;;;;;OAKG;IACH,YAAY,OAA8B;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YAC9B,MAAM,IAAI,aAAa,CACrB,sKAAsK,CACvK,CAAC;SACH;QAED,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAEzE,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAM,CAAC,GAAG,CAAC;SAC/D;aAAM;YACL,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;SACxD;IACH,CAAC;IAED;;;;;OAKG;IACO,gBAAgB,CAAC,GAAQ;QACjC,OAAO,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,iBAAiB,IAAI,GAAG,CAA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AG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC1D,CAAC;KAAA;IAED;;;;;;OAMG;IACa,MAAM,CAAC,GAAQ,EAAE,OAAsB;;YACrD,OAAO,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;KAAA;IAED;;;OAGG;IACH,IAAI,KAAK;;QACP,OAAO,IAAI,CAAC,GAAG,KAAK,OAAO,IAAI,CAAC,CAAC,CAAA,MAAA,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,0CAAE,GAAG,CAAA,CAAC;IAClF,CAAC;CACF;AAED,OAAO,EAAE,kBAAkB,IAAI,qBAAqB,EAAE,CAAC"}
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import { AbstractClient } from "./AbstractClient";
|
|
2
|
-
import {
|
|
2
|
+
import { ListenLiveClient } from "./ListenLiveClient";
|
|
3
|
+
import { ListenRestClient } from "./ListenRestClient";
|
|
3
4
|
import { LiveSchema } from "../lib/types";
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The `ListenClient` class extends the `AbstractClient` class and provides access to the "listen" namespace.
|
|
7
|
+
* It exposes two methods:
|
|
8
|
+
*
|
|
9
|
+
* 1. `prerecorded()`: Returns a `ListenRestClient` instance for interacting with the prerecorded listen API.
|
|
10
|
+
* 2. `live(transcriptionOptions: LiveSchema = {}, endpoint = ":version/listen")`: Returns a `ListenLiveClient` instance for interacting with the live listen API, with the provided transcription options and endpoint.
|
|
11
|
+
*/
|
|
5
12
|
export declare class ListenClient extends AbstractClient {
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
namespace: string;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a `ListenRestClient` instance for interacting with the prerecorded listen API.
|
|
16
|
+
*/
|
|
17
|
+
get prerecorded(): ListenRestClient;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a `ListenLiveClient` instance for interacting with the live listen API, with the provided transcription options and endpoint.
|
|
20
|
+
* @param {LiveSchema} [transcriptionOptions={}] - The transcription options to use for the live listen API.
|
|
21
|
+
* @param {string} [endpoint=":version/listen"] - The endpoint to use for the live listen API.
|
|
22
|
+
* @returns {ListenLiveClient} - A `ListenLiveClient` instance for interacting with the live listen API.
|
|
23
|
+
*/
|
|
24
|
+
live(transcriptionOptions?: LiveSchema, endpoint?: string): ListenLiveClient;
|
|
8
25
|
}
|
|
9
26
|
//# sourceMappingURL=ListenClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListenClient.d.ts","sourceRoot":"","sources":["../../../src/packages/ListenClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ListenClient.d.ts","sourceRoot":"","sources":["../../../src/packages/ListenClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;GAMG;AACH,qBAAa,YAAa,SAAQ,cAAc;IACvC,SAAS,EAAE,MAAM,CAAY;IAEpC;;OAEG;IACH,IAAI,WAAW,qBAEd;IAED;;;;;OAKG;IACI,IAAI,CACT,oBAAoB,GAAE,UAAe,EACrC,QAAQ,GAAE,MAA0B,GACnC,gBAAgB;CAGpB"}
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import { AbstractClient } from "./AbstractClient";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ListenLiveClient } from "./ListenLiveClient";
|
|
3
|
+
import { ListenRestClient } from "./ListenRestClient";
|
|
4
|
+
/**
|
|
5
|
+
* The `ListenClient` class extends the `AbstractClient` class and provides access to the "listen" namespace.
|
|
6
|
+
* It exposes two methods:
|
|
7
|
+
*
|
|
8
|
+
* 1. `prerecorded()`: Returns a `ListenRestClient` instance for interacting with the prerecorded listen API.
|
|
9
|
+
* 2. `live(transcriptionOptions: LiveSchema = {}, endpoint = ":version/listen")`: Returns a `ListenLiveClient` instance for interacting with the live listen API, with the provided transcription options and endpoint.
|
|
10
|
+
*/
|
|
4
11
|
export class ListenClient extends AbstractClient {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.namespace = "listen";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns a `ListenRestClient` instance for interacting with the prerecorded listen API.
|
|
18
|
+
*/
|
|
5
19
|
get prerecorded() {
|
|
6
|
-
return new
|
|
20
|
+
return new ListenRestClient(this.options);
|
|
7
21
|
}
|
|
8
|
-
|
|
9
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Returns a `ListenLiveClient` instance for interacting with the live listen API, with the provided transcription options and endpoint.
|
|
24
|
+
* @param {LiveSchema} [transcriptionOptions={}] - The transcription options to use for the live listen API.
|
|
25
|
+
* @param {string} [endpoint=":version/listen"] - The endpoint to use for the live listen API.
|
|
26
|
+
* @returns {ListenLiveClient} - A `ListenLiveClient` instance for interacting with the live listen API.
|
|
27
|
+
*/
|
|
28
|
+
live(transcriptionOptions = {}, endpoint = ":version/listen") {
|
|
29
|
+
return new ListenLiveClient(this.options, transcriptionOptions, endpoint);
|
|
10
30
|
}
|
|
11
31
|
}
|
|
12
32
|
//# sourceMappingURL=ListenClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListenClient.js","sourceRoot":"","sources":["../../../src/packages/ListenClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ListenClient.js","sourceRoot":"","sources":["../../../src/packages/ListenClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD;;;;;;GAMG;AACH,MAAM,OAAO,YAAa,SAAQ,cAAc;IAAhD;;QACS,cAAS,GAAW,QAAQ,CAAC;IAqBtC,CAAC;IAnBC;;OAEG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACI,IAAI,CACT,uBAAmC,EAAE,EACrC,WAAmB,iBAAiB;QAEpC,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,oBAAoB,EAAE,QAAQ,CAAC,CAAC;IAC5E,CAAC;CACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AbstractLiveClient } from "./AbstractLiveClient";
|
|
2
|
+
import type { LiveSchema, LiveConfigOptions, DeepgramClientOptions } from "../lib/types";
|
|
3
|
+
/**
|
|
4
|
+
* The `ListenLiveClient` class extends the `AbstractLiveClient` class and provides functionality for setting up and managing a WebSocket connection for live transcription.
|
|
5
|
+
*
|
|
6
|
+
* The constructor takes in `DeepgramClientOptions` and an optional `LiveSchema` object, as well as an optional `endpoint` string. It then calls the `connect` method of the parent `AbstractLiveClient` class to establish the WebSocket connection.
|
|
7
|
+
*
|
|
8
|
+
* The `setupConnection` method is responsible for handling the various events that can occur on the WebSocket connection, such as opening, closing, and receiving messages. It sets up event handlers for these events and emits the appropriate events based on the message type.
|
|
9
|
+
*
|
|
10
|
+
* The `configure` method allows you to send additional configuration options to the connected session, such as enabling numerals.
|
|
11
|
+
*
|
|
12
|
+
* The `keepAlive` method sends a "KeepAlive" message to the server to maintain the connection.
|
|
13
|
+
*
|
|
14
|
+
* The `requestClose` method requests the server to close the connection.
|
|
15
|
+
*
|
|
16
|
+
* The `finish` method is deprecated as of version 3.4 and will be removed in version 4.0. Use `requestClose` instead.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ListenLiveClient extends AbstractLiveClient {
|
|
19
|
+
namespace: string;
|
|
20
|
+
/**
|
|
21
|
+
* Constructs a new `ListenLiveClient` instance with the provided options.
|
|
22
|
+
*
|
|
23
|
+
* @param options - The `DeepgramClientOptions` to use for the client connection.
|
|
24
|
+
* @param transcriptionOptions - An optional `LiveSchema` object containing additional configuration options for the live transcription.
|
|
25
|
+
* @param endpoint - An optional string representing the WebSocket endpoint to connect to. Defaults to `:version/listen`.
|
|
26
|
+
*/
|
|
27
|
+
constructor(options: DeepgramClientOptions, transcriptionOptions?: LiveSchema, endpoint?: string);
|
|
28
|
+
/**
|
|
29
|
+
* Sets up the connection event handlers.
|
|
30
|
+
* This method is responsible for handling the various events that can occur on the WebSocket connection, such as opening, closing, and receiving messages.
|
|
31
|
+
* - When the connection is opened, it emits the `LiveTranscriptionEvents.Open` event.
|
|
32
|
+
* - When the connection is closed, it emits the `LiveTranscriptionEvents.Close` event.
|
|
33
|
+
* - When an error occurs on the connection, it emits the `LiveTranscriptionEvents.Error` event.
|
|
34
|
+
* - When a message is received, it parses the message and emits the appropriate event based on the message type, such as `LiveTranscriptionEvents.Metadata`, `LiveTranscriptionEvents.Transcript`, `LiveTranscriptionEvents.UtteranceEnd`, and `LiveTranscriptionEvents.SpeechStarted`.
|
|
35
|
+
*/
|
|
36
|
+
setupConnection(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Sends additional config to the connected session.
|
|
39
|
+
*
|
|
40
|
+
* @param config - The configuration options to apply to the LiveClient.
|
|
41
|
+
* @param config.numerals - We currently only support numerals.
|
|
42
|
+
*/
|
|
43
|
+
configure(config: LiveConfigOptions): void;
|
|
44
|
+
/**
|
|
45
|
+
* Sends a "KeepAlive" message to the server to maintain the connection.
|
|
46
|
+
*/
|
|
47
|
+
keepAlive(): void;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Since version 3.4. Will be removed in version 4.0. Use `close` instead.
|
|
50
|
+
*/
|
|
51
|
+
finish(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Requests the server close the connection.
|
|
54
|
+
*/
|
|
55
|
+
requestClose(): void;
|
|
56
|
+
}
|
|
57
|
+
export { ListenLiveClient as Liveclient };
|
|
58
|
+
//# sourceMappingURL=ListenLiveClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListenLiveClient.d.ts","sourceRoot":"","sources":["../../../src/packages/ListenLiveClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEzF;;;;;;;;;;;;;;GAcG;AACH,qBAAa,gBAAiB,SAAQ,kBAAkB;IAC/C,SAAS,EAAE,MAAM,CAAY;IAEpC;;;;;;OAMG;gBAED,OAAO,EAAE,qBAAqB,EAC9B,oBAAoB,GAAE,UAAe,EACrC,QAAQ,GAAE,MAA0B;IAOtC;;;;;;;OAOG;IACI,eAAe,IAAI,IAAI;IAwC9B;;;;;OAKG;IACI,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IASjD;;OAEG;IACI,SAAS,IAAI,IAAI;IAQxB;;OAEG;IACI,MAAM,IAAI,IAAI;IAIrB;;OAEG;IACI,YAAY,IAAI,IAAI;CAO5B;AAED,OAAO,EAAE,gBAAgB,IAAI,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { AbstractLiveClient } from "./AbstractLiveClient";
|
|
2
|
+
import { LiveTranscriptionEvents } from "../lib/enums";
|
|
3
|
+
/**
|
|
4
|
+
* The `ListenLiveClient` class extends the `AbstractLiveClient` class and provides functionality for setting up and managing a WebSocket connection for live transcription.
|
|
5
|
+
*
|
|
6
|
+
* The constructor takes in `DeepgramClientOptions` and an optional `LiveSchema` object, as well as an optional `endpoint` string. It then calls the `connect` method of the parent `AbstractLiveClient` class to establish the WebSocket connection.
|
|
7
|
+
*
|
|
8
|
+
* The `setupConnection` method is responsible for handling the various events that can occur on the WebSocket connection, such as opening, closing, and receiving messages. It sets up event handlers for these events and emits the appropriate events based on the message type.
|
|
9
|
+
*
|
|
10
|
+
* The `configure` method allows you to send additional configuration options to the connected session, such as enabling numerals.
|
|
11
|
+
*
|
|
12
|
+
* The `keepAlive` method sends a "KeepAlive" message to the server to maintain the connection.
|
|
13
|
+
*
|
|
14
|
+
* The `requestClose` method requests the server to close the connection.
|
|
15
|
+
*
|
|
16
|
+
* The `finish` method is deprecated as of version 3.4 and will be removed in version 4.0. Use `requestClose` instead.
|
|
17
|
+
*/
|
|
18
|
+
export class ListenLiveClient extends AbstractLiveClient {
|
|
19
|
+
/**
|
|
20
|
+
* Constructs a new `ListenLiveClient` instance with the provided options.
|
|
21
|
+
*
|
|
22
|
+
* @param options - The `DeepgramClientOptions` to use for the client connection.
|
|
23
|
+
* @param transcriptionOptions - An optional `LiveSchema` object containing additional configuration options for the live transcription.
|
|
24
|
+
* @param endpoint - An optional string representing the WebSocket endpoint to connect to. Defaults to `:version/listen`.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options, transcriptionOptions = {}, endpoint = ":version/listen") {
|
|
27
|
+
super(options);
|
|
28
|
+
this.namespace = "listen";
|
|
29
|
+
this.connect(transcriptionOptions, endpoint);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Sets up the connection event handlers.
|
|
33
|
+
* This method is responsible for handling the various events that can occur on the WebSocket connection, such as opening, closing, and receiving messages.
|
|
34
|
+
* - When the connection is opened, it emits the `LiveTranscriptionEvents.Open` event.
|
|
35
|
+
* - When the connection is closed, it emits the `LiveTranscriptionEvents.Close` event.
|
|
36
|
+
* - When an error occurs on the connection, it emits the `LiveTranscriptionEvents.Error` event.
|
|
37
|
+
* - When a message is received, it parses the message and emits the appropriate event based on the message type, such as `LiveTranscriptionEvents.Metadata`, `LiveTranscriptionEvents.Transcript`, `LiveTranscriptionEvents.UtteranceEnd`, and `LiveTranscriptionEvents.SpeechStarted`.
|
|
38
|
+
*/
|
|
39
|
+
setupConnection() {
|
|
40
|
+
if (this.conn) {
|
|
41
|
+
this.conn.onopen = () => {
|
|
42
|
+
this.emit(LiveTranscriptionEvents.Open, this);
|
|
43
|
+
};
|
|
44
|
+
this.conn.onclose = (event) => {
|
|
45
|
+
this.emit(LiveTranscriptionEvents.Close, event);
|
|
46
|
+
};
|
|
47
|
+
this.conn.onerror = (event) => {
|
|
48
|
+
this.emit(LiveTranscriptionEvents.Error, event);
|
|
49
|
+
};
|
|
50
|
+
this.conn.onmessage = (event) => {
|
|
51
|
+
try {
|
|
52
|
+
const data = JSON.parse(event.data.toString());
|
|
53
|
+
if (data.type === LiveTranscriptionEvents.Metadata) {
|
|
54
|
+
this.emit(LiveTranscriptionEvents.Metadata, data);
|
|
55
|
+
}
|
|
56
|
+
else if (data.type === LiveTranscriptionEvents.Transcript) {
|
|
57
|
+
this.emit(LiveTranscriptionEvents.Transcript, data);
|
|
58
|
+
}
|
|
59
|
+
else if (data.type === LiveTranscriptionEvents.UtteranceEnd) {
|
|
60
|
+
this.emit(LiveTranscriptionEvents.UtteranceEnd, data);
|
|
61
|
+
}
|
|
62
|
+
else if (data.type === LiveTranscriptionEvents.SpeechStarted) {
|
|
63
|
+
this.emit(LiveTranscriptionEvents.SpeechStarted, data);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.emit(LiveTranscriptionEvents.Unhandled, data);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
this.emit(LiveTranscriptionEvents.Error, {
|
|
71
|
+
event,
|
|
72
|
+
message: "Unable to parse `data` as JSON.",
|
|
73
|
+
error,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sends additional config to the connected session.
|
|
81
|
+
*
|
|
82
|
+
* @param config - The configuration options to apply to the LiveClient.
|
|
83
|
+
* @param config.numerals - We currently only support numerals.
|
|
84
|
+
*/
|
|
85
|
+
configure(config) {
|
|
86
|
+
this.send(JSON.stringify({
|
|
87
|
+
type: "Configure",
|
|
88
|
+
processors: config,
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Sends a "KeepAlive" message to the server to maintain the connection.
|
|
93
|
+
*/
|
|
94
|
+
keepAlive() {
|
|
95
|
+
this.send(JSON.stringify({
|
|
96
|
+
type: "KeepAlive",
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @deprecated Since version 3.4. Will be removed in version 4.0. Use `close` instead.
|
|
101
|
+
*/
|
|
102
|
+
finish() {
|
|
103
|
+
this.requestClose();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Requests the server close the connection.
|
|
107
|
+
*/
|
|
108
|
+
requestClose() {
|
|
109
|
+
this.send(JSON.stringify({
|
|
110
|
+
type: "CloseStream",
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export { ListenLiveClient as Liveclient };
|
|
115
|
+
//# sourceMappingURL=ListenLiveClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListenLiveClient.js","sourceRoot":"","sources":["../../../src/packages/ListenLiveClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAGvD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,gBAAiB,SAAQ,kBAAkB;IAGtD;;;;;;OAMG;IACH,YACE,OAA8B,EAC9B,uBAAmC,EAAE,EACrC,WAAmB,iBAAiB;QAEpC,KAAK,CAAC,OA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C,uBAAuB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;qBACvD;yBAAM,IAAI,IAAI,CAAC,IAAI,KAAK,uBAAuB,CAAC,aAAa,EAAE;wBAC9D,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;qBACxD;yBAAM;wBACL,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;qBACpD;iBACF;gBAAC,OAAO,KAAK,EAAE;oBACd,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE;wBACvC,KAAK;wBACL,OAAO,EAAE,iCAAiC;wBAC1C,KAAK;qBACN,CAAC,CAAC;iBACJ;YACH,CAAC,CAAC;SACH;IACH,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,MAAyB;QACxC,IAAI,CAAC,IAAI,CACP,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,WAAW;YACjB,UAAU,EAAE,MAAM;SACnB,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,SAAS;QACd,IAAI,CAAC,IAAI,CACP,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,WAAW;SAClB,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,MAAM;QACX,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED;;OAEG;IACI,YAAY;QACjB,IAAI,CAAC,IAAI,CACP,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,aAAa;SACpB,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AAED,OAAO,EAAE,gBAAgB,IAAI,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CallbackUrl } from "../lib/helpers";
|
|
2
|
+
import type { AsyncPrerecordedResponse, DeepgramResponse, FileSource, PrerecordedSchema, SyncPrerecordedResponse, UrlSource } from "../lib/types";
|
|
3
|
+
import { AbstractRestClient } from "./AbstractRestClient";
|
|
4
|
+
/**
|
|
5
|
+
* The `ListenRestClient` class extends the `AbstractRestClient` class and provides methods for transcribing audio from URLs or files using the Deepgram API.
|
|
6
|
+
*
|
|
7
|
+
* The `transcribeUrl` method is used to transcribe audio from a URL synchronously. It takes a `UrlSource` object as the source, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
|
|
8
|
+
*
|
|
9
|
+
* The `transcribeFile` method is used to transcribe audio from a file synchronously. It takes a `FileSource` object as the source, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
|
|
10
|
+
*
|
|
11
|
+
* The `transcribeUrlCallback` method is used to transcribe audio from a URL asynchronously. It takes a `UrlSource` object as the source, a `CallbackUrl` object as the callback, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
|
|
12
|
+
*
|
|
13
|
+
* The `transcribeFileCallback` method is used to transcribe audio from a file asynchronously. It takes a `FileSource` object as the source, a `CallbackUrl` object as the callback, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ListenRestClient extends AbstractRestClient {
|
|
16
|
+
namespace: string;
|
|
17
|
+
/**
|
|
18
|
+
* Transcribes audio from a URL synchronously.
|
|
19
|
+
*
|
|
20
|
+
* @param source - The URL source object containing the audio URL to transcribe.
|
|
21
|
+
* @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
|
|
22
|
+
* @param endpoint - An optional endpoint string to use for the transcription request.
|
|
23
|
+
* @returns A `DeepgramResponse` object containing the transcription result or an error.
|
|
24
|
+
*/
|
|
25
|
+
transcribeUrl(source: UrlSource, options?: PrerecordedSchema, endpoint?: string): Promise<DeepgramResponse<SyncPrerecordedResponse>>;
|
|
26
|
+
/**
|
|
27
|
+
* Transcribes audio from a file asynchronously.
|
|
28
|
+
*
|
|
29
|
+
* @param source - The file source object containing the audio file to transcribe.
|
|
30
|
+
* @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
|
|
31
|
+
* @param endpoint - An optional endpoint string to use for the transcription request.
|
|
32
|
+
* @returns A `DeepgramResponse` object containing the transcription result or an error.
|
|
33
|
+
*/
|
|
34
|
+
transcribeFile(source: FileSource, options?: PrerecordedSchema, endpoint?: string): Promise<DeepgramResponse<SyncPrerecordedResponse>>;
|
|
35
|
+
/**
|
|
36
|
+
* Transcribes audio from a URL asynchronously.
|
|
37
|
+
*
|
|
38
|
+
* @param source - The URL source object containing the audio file to transcribe.
|
|
39
|
+
* @param callback - The callback URL to receive the transcription result.
|
|
40
|
+
* @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
|
|
41
|
+
* @param endpoint - An optional endpoint string to use for the transcription request.
|
|
42
|
+
* @returns A `DeepgramResponse` object containing the transcription result or an error.
|
|
43
|
+
*/
|
|
44
|
+
transcribeUrlCallback(source: UrlSource, callback: CallbackUrl, options?: PrerecordedSchema, endpoint?: string): Promise<DeepgramResponse<AsyncPrerecordedResponse>>;
|
|
45
|
+
/**
|
|
46
|
+
* Transcribes audio from a file asynchronously.
|
|
47
|
+
*
|
|
48
|
+
* @param source - The file source object containing the audio file to transcribe.
|
|
49
|
+
* @param callback - The callback URL to receive the transcription result.
|
|
50
|
+
* @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
|
|
51
|
+
* @param endpoint - An optional endpoint string to use for the transcription request.
|
|
52
|
+
* @returns A `DeepgramResponse` object containing the transcription result or an error.
|
|
53
|
+
*/
|
|
54
|
+
transcribeFileCallback(source: FileSource, callback: CallbackUrl, options?: PrerecordedSchema, endpoint?: string): Promise<DeepgramResponse<AsyncPrerecordedResponse>>;
|
|
55
|
+
}
|
|
56
|
+
export { ListenRestClient as PrerecordedClient };
|
|
57
|
+
//# sourceMappingURL=ListenRestClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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