-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathBaseClient.ts
More file actions
131 lines (122 loc) · 4.16 KB
/
BaseClient.ts
File metadata and controls
131 lines (122 loc) · 4.16 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// This file was auto-generated by Fern from our API Definition.
import { BearerAuthProvider } from "./auth/BearerAuthProvider.js";
import { mergeHeaders } from "./core/headers.js";
import * as core from "./core/index.js";
import type * as environments from "./environments.js";
export interface BaseClientOptions {
environment?: core.Supplier<environments.IntercomEnvironment | string>;
/** Specify a custom URL to connect the client to. */
baseUrl?: core.Supplier<string>;
token?: core.Supplier<core.BearerToken | undefined>;
/** Override the Intercom-Version header */
version?:
| "1.0"
| "1.1"
| "1.2"
| "1.3"
| "1.4"
| "2.0"
| "2.1"
| "2.2"
| "2.3"
| "2.4"
| "2.5"
| "2.6"
| "2.7"
| "2.8"
| "2.9"
| "2.10"
| "2.11"
| "2.12"
| "2.13"
| "2.14"
| "Unstable";
/** 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;
/** 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>;
/** Override the Intercom-Version header */
version?:
| "1.0"
| "1.1"
| "1.2"
| "1.3"
| "1.4"
| "2.0"
| "2.1"
| "2.2"
| "2.3"
| "2.4"
| "2.5"
| "2.6"
| "2.7"
| "2.8"
| "2.9"
| "2.10"
| "2.11"
| "2.12"
| "2.13"
| "2.14"
| "Unstable";
}
export type NormalizedClientOptions<T extends BaseClientOptions> = T & {
logging: core.logging.Logger;
authProvider?: core.AuthProvider;
};
export type NormalizedClientOptionsWithAuth<T extends BaseClientOptions> = NormalizedClientOptions<T> & {
authProvider: core.AuthProvider;
};
export function normalizeClientOptions<T extends BaseClientOptions>(options: T): NormalizedClientOptions<T> {
const headers = mergeHeaders(
{
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "intercom-client",
"X-Fern-SDK-Version": "7.0.3",
"User-Agent": "intercom-client/7.0.3",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
"Intercom-Version": options?.version ?? "2.14",
},
options?.headers,
);
return {
...options,
logging: core.logging.createLogger(options?.logging),
headers,
} as NormalizedClientOptions<T>;
}
export function normalizeClientOptionsWithAuth<T extends BaseClientOptions>(
options: T,
): NormalizedClientOptionsWithAuth<T> {
const normalized = normalizeClientOptions(options) as NormalizedClientOptionsWithAuth<T>;
const normalizedWithNoOpAuthProvider = withNoOpAuthProvider(normalized);
normalized.authProvider ??= new BearerAuthProvider(normalizedWithNoOpAuthProvider);
return normalized;
}
function withNoOpAuthProvider<T extends BaseClientOptions>(
options: NormalizedClientOptions<T>,
): NormalizedClientOptionsWithAuth<T> {
return {
...options,
authProvider: new core.NoOpAuthProvider(),
};
}