-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.ts
More file actions
75 lines (64 loc) · 2.02 KB
/
index.ts
File metadata and controls
75 lines (64 loc) · 2.02 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
import { HttpClient } from './http-client';
import { Accounts } from './Accounts';
import { Actions } from './Actions';
import { Clusters } from './Clusters';
import { Events } from './Events';
import { Instances } from './Instances';
import { Overview } from './Overview';
import { Schedule } from './Schedule';
// Initialize HTTP client with base settings
const http = new HttpClient({
baseURL: '/api',
timeout: 20000,
headers: {
'Content-Type': 'application/json',
},
});
const PAGINATED_ENDPOINTS = ['/accounts', '/clusters', '/instances'];
http.instance.interceptors.request.use(config => {
const isListEndpoint = PAGINATED_ENDPOINTS.some(endpoint => {
const url = config.url || '';
return url.includes(endpoint) && !url.match(/\/[^/]+\/[^/]+$/);
});
if (isListEndpoint && config.method === 'get') {
if (!config.params?.page_size) {
config.params = {
page: config.params?.page || 1,
page_size: 100,
...config.params,
};
}
}
return config;
});
// Initialize API classes
export const api = {
accounts: new Accounts(http),
actions: new Actions(http),
clusters: new Clusters(http),
events: new Events(http),
instances: new Instances(http),
overview: new Overview(http),
schedule: new Schedule(http),
};
export const startCluster = (clusterID: string, userEmail?: string, description?: string) =>
http.instance.post(`/clusters/${clusterID}/power_on`, {
requester: userEmail || 'unknown',
description: description,
});
export const stopCluster = (clusterID: string, userEmail?: string, description?: string) =>
http.instance.post(`/clusters/${clusterID}/power_off`, {
requester: userEmail || 'unknown',
description: description,
});
export type {
ClusterResponseApi,
InstanceResponseApi,
AccountResponseApi,
ClusterListResponseApi,
InstanceListResponseApi,
AccountListResponseApi,
SystemEventResponseApi,
} from './data-contracts';
export { ResourceStatusApi, ProviderApi } from './data-contracts';
export * from './data-contracts';