forked from openfga/js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.ts
72 lines (61 loc) · 1.83 KB
/
base.ts
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
/**
* JavaScript and Node.js SDK for OpenFGA
*
* API version: 0.1
* Website: https://openfga.dev
* Documentation: https://openfga.dev/docs
* Support: https://openfga.dev/community
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE)
*
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
*/
// Some imports not used depending on template conditions
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);
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,
});
}
}
public get storeId() {
return this.configuration.storeId;
}
public set storeId(storeId: string) {
this.configuration.storeId = storeId;
}
}