-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathBaseClient.ts
More file actions
64 lines (58 loc) · 2.57 KB
/
BaseClient.ts
File metadata and controls
64 lines (58 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// This file was auto-generated by Fern from our API Definition.
import * as core from "./core";
import { mergeHeaders } from "./core/headers";
import type * as environments from "./environments";
export interface BaseClientOptions {
environment?: core.Supplier<environments.ElevenLabsEnvironment | string>;
/** Specify a custom URL to connect the client to. */
baseUrl?: core.Supplier<string>;
/** Override the xi-api-key header */
apiKey?: core.Supplier<string | undefined>;
/** Additional headers to include in requests. */
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
/** The default maximum time to wait for a response in seconds. */
timeoutInSeconds?: number;
/** The default number of times to retry the request. Defaults to 2. */
maxRetries?: number;
/** Provide a custom fetch implementation. Useful for platforms that don't have a built-in fetch or need a custom implementation. */
fetch?: typeof fetch;
fetcher?: core.FetchFunction;
/** Configure logging for the client. */
logging?: core.logging.LogConfig | core.logging.Logger;
}
export interface BaseRequestOptions {
/** The maximum time to wait for a response in seconds. */
timeoutInSeconds?: number;
/** The number of times to retry the request. Defaults to 2. */
maxRetries?: number;
/** A hook to abort the request. */
abortSignal?: AbortSignal;
/** Override the xi-api-key header */
apiKey?: string | undefined;
/** Additional query string parameters to include in the request. */
queryParams?: Record<string, unknown>;
/** Additional headers to include in the request. */
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
}
export type NormalizedClientOptions<T extends BaseClientOptions> = T & {
logging: core.logging.Logger;
};
export function normalizeClientOptions<T extends BaseClientOptions>(options: T): NormalizedClientOptions<T> {
const headers = mergeHeaders(
{
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@elevenlabs/elevenlabs-js",
"X-Fern-SDK-Version": "v2.36.0",
"User-Agent": "@elevenlabs/elevenlabs-js/v2.36.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
"xi-api-key": options?.apiKey,
},
options?.headers,
);
return {
...options,
logging: core.logging.createLogger(options?.logging),
headers,
} as NormalizedClientOptions<T>;
}