-
Notifications
You must be signed in to change notification settings - Fork 2
/
Brex.ts
74 lines (66 loc) · 1.81 KB
/
Brex.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
73
74
import {
ApiOptions,
ApiRequestOptions,
} from './types';
import { apiRequest } from './util/apiRequest';
import { VendorsAPI } from './VendorsAPI';
import { TransfersAPI } from './TransfersAPI';
import { AccountsAPI } from './AccountsAPI';
/**
* A Brex API instance.
*/
export class Brex {
/**
* The user auth token.
*/
token: string;
/**
* The base URL for this API instance. Generally, this will always be `https://platform.brexapis.com`.
*/
baseURL: string;
/**
* The version of the Brex API to be used; defaults to `v1`.
*/
apiVersion: string;
/**
* Constructs a Brex API instance.
* @param token - Your Brex API user token.
* @param options - Additional options (see {@link ApiOptions}).
*/
constructor(
token: string,
options?: ApiOptions,
) {
this.token = token;
this.baseURL = 'https://platform.brexapis.com';
if (options?.baseURL) {
this.baseURL = options.baseURL;
} else if (options?.environment) {
this.baseURL = options.environment === 'staging' ? 'https://platform.staging.brexapps.com' : this.baseURL;
}
this.apiVersion = options?.apiVersion || 'v1';
}
/**
* A generic request function for accessing the Brex API.
* @param options - See {@link ApiRequestOptions}.
*/
request = async (
options: ApiRequestOptions,
) => apiRequest(
this.token,
this.baseURL,
options,
);
/**
* Payments API: Vendors endpoints
*/
vendors = new VendorsAPI(this.request);
/**
* Payments API: Transfers endpoints
*/
transfers = new TransfersAPI(this.request);
/**
* Transactions API: Accounts endpoints
*/
accounts = new AccountsAPI(this.request);
}