-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbase.ts
More file actions
50 lines (43 loc) · 1.26 KB
/
base.ts
File metadata and controls
50 lines (43 loc) · 1.26 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
import globalAxios, { AxiosInstance } from "axios";
import * as http from "http";
import * as https from "https";
import { Configuration, UserConfigurationParams } from "./configuration";
import { Credentials } from "./credentials";
const DEFAULT_CONNECTION_TIMEOUT_IN_MS = 10000;
/**
*
* @export
* @interface RequestArgs
*/
export interface RequestArgs {
url: string;
options: any;
}
/**
*
* @export
* @class BaseAPI
*/
export class BaseAPI {
protected configuration: Configuration;
protected credentials: Credentials;
constructor(configuration: UserConfigurationParams | Configuration, protected axios?: AxiosInstance) {
if (configuration instanceof Configuration) {
this.configuration = configuration;
} else {
this.configuration = new Configuration(configuration);
}
this.configuration.isValid();
this.credentials = Credentials.init(this.configuration, this.axios);
if (!this.axios) {
const httpAgent = new http.Agent({ keepAlive: true });
const httpsAgent = new https.Agent({ keepAlive: true });
this.axios = globalAxios.create({
httpAgent,
httpsAgent,
timeout: DEFAULT_CONNECTION_TIMEOUT_IN_MS,
headers: this.configuration.baseOptions?.headers,
});
}
}
}