1
1
import axios , { AxiosRequestHeaders } from "axios"
2
2
import { mutate } from "swr"
3
- import * as Types from "./types"
4
3
import * as TypesGen from "./typesGenerated"
5
4
6
5
const CONTENT_TYPE_JSON : AxiosRequestHeaders = {
7
6
"Content-Type" : "application/json" ,
8
7
}
9
8
10
- export const provisioners : Types . Provisioner [ ] = [
9
+ export const provisioners : TypesGen . ProvisionerDaemon [ ] = [
11
10
{
12
11
id : "terraform" ,
13
12
name : "Terraform" ,
13
+ created_at : "" ,
14
+ provisioners : [ ] ,
14
15
} ,
15
16
{
16
17
id : "cdr-basic" ,
17
18
name : "Basic" ,
19
+ created_at : "" ,
20
+ provisioners : [ ] ,
18
21
} ,
19
22
]
20
23
21
24
export namespace Workspace {
22
- export const create = async ( request : Types . CreateWorkspaceRequest ) : Promise < Types . Workspace > => {
23
- const response = await fetch ( `/api/v2/organizations/${ request . organization_id } /workspaces` , {
25
+ export const create = async (
26
+ organizationId : string ,
27
+ request : TypesGen . CreateWorkspaceRequest ,
28
+ ) : Promise < TypesGen . Workspace > => {
29
+ const response = await fetch ( `/api/v2/organizations/${ organizationId } /workspaces` , {
24
30
method : "POST" ,
25
31
headers : {
26
32
"Content-Type" : "application/json" ,
@@ -43,13 +49,13 @@ export namespace Workspace {
43
49
}
44
50
}
45
51
46
- export const login = async ( email : string , password : string ) : Promise < Types . LoginResponse > => {
52
+ export const login = async ( email : string , password : string ) : Promise < TypesGen . LoginWithPasswordResponse > => {
47
53
const payload = JSON . stringify ( {
48
54
email,
49
55
password,
50
56
} )
51
57
52
- const response = await axios . post < Types . LoginResponse > ( "/api/v2/users/login" , payload , {
58
+ const response = await axios . post < TypesGen . LoginWithPasswordResponse > ( "/api/v2/users/login" , payload , {
53
59
headers : { ...CONTENT_TYPE_JSON } ,
54
60
} )
55
61
@@ -60,8 +66,8 @@ export const logout = async (): Promise<void> => {
60
66
await axios . post ( "/api/v2/users/logout" )
61
67
}
62
68
63
- export const getUser = async ( ) : Promise < Types . UserResponse > => {
64
- const response = await axios . get < Types . UserResponse > ( "/api/v2/users/me" )
69
+ export const getUser = async ( ) : Promise < TypesGen . User > => {
70
+ const response = await axios . get < TypesGen . User > ( "/api/v2/users/me" )
65
71
return response . data
66
72
}
67
73
@@ -70,8 +76,8 @@ export const getAuthMethods = async (): Promise<TypesGen.AuthMethods> => {
70
76
return response . data
71
77
}
72
78
73
- export const getApiKey = async ( ) : Promise < Types . APIKeyResponse > => {
74
- const response = await axios . post < Types . APIKeyResponse > ( "/api/v2/users/me/keys" )
79
+ export const getApiKey = async ( ) : Promise < TypesGen . GenerateAPIKeyResponse > => {
80
+ const response = await axios . post < TypesGen . GenerateAPIKeyResponse > ( "/api/v2/users/me/keys" )
75
81
return response . data
76
82
}
77
83
@@ -80,55 +86,57 @@ export const getUsers = async (): Promise<TypesGen.User[]> => {
80
86
return response . data
81
87
}
82
88
83
- export const getOrganization = async ( organizationId : string ) : Promise < Types . Organization > => {
84
- const response = await axios . get < Types . Organization > ( `/api/v2/organizations/${ organizationId } ` )
89
+ export const getOrganization = async ( organizationId : string ) : Promise < TypesGen . Organization > => {
90
+ const response = await axios . get < TypesGen . Organization > ( `/api/v2/organizations/${ organizationId } ` )
85
91
return response . data
86
92
}
87
93
88
- export const getOrganizations = async ( ) : Promise < Types . Organization [ ] > => {
89
- const response = await axios . get < Types . Organization [ ] > ( "/api/v2/users/me/organizations" )
94
+ export const getOrganizations = async ( ) : Promise < TypesGen . Organization [ ] > => {
95
+ const response = await axios . get < TypesGen . Organization [ ] > ( "/api/v2/users/me/organizations" )
90
96
return response . data
91
97
}
92
98
93
- export const getTemplate = async ( templateId : string ) : Promise < Types . Template > => {
94
- const response = await axios . get < Types . Template > ( `/api/v2/templates/${ templateId } ` )
99
+ export const getTemplate = async ( templateId : string ) : Promise < TypesGen . Template > => {
100
+ const response = await axios . get < TypesGen . Template > ( `/api/v2/templates/${ templateId } ` )
95
101
return response . data
96
102
}
97
103
98
- export const getWorkspace = async ( workspaceId : string ) : Promise < Types . Workspace > => {
99
- const response = await axios . get < Types . Workspace > ( `/api/v2/workspaces/${ workspaceId } ` )
104
+ export const getWorkspace = async ( workspaceId : string ) : Promise < TypesGen . Workspace > => {
105
+ const response = await axios . get < TypesGen . Workspace > ( `/api/v2/workspaces/${ workspaceId } ` )
100
106
return response . data
101
107
}
102
108
103
109
export const getWorkspaceByOwnerAndName = async (
104
110
organizationID : string ,
105
111
username = "me" ,
106
112
workspaceName : string ,
107
- ) : Promise < Types . Workspace > => {
108
- const response = await axios . get < Types . Workspace > (
113
+ ) : Promise < TypesGen . Workspace > => {
114
+ const response = await axios . get < TypesGen . Workspace > (
109
115
`/api/v2/organizations/${ organizationID } /workspaces/${ username } /${ workspaceName } ` ,
110
116
)
111
117
return response . data
112
118
}
113
119
114
- export const getWorkspaceResources = async ( workspaceBuildID : string ) : Promise < Types . WorkspaceResource [ ] > => {
115
- const response = await axios . get < Types . WorkspaceResource [ ] > ( `/api/v2/workspacebuilds/${ workspaceBuildID } /resources` )
120
+ export const getWorkspaceResources = async ( workspaceBuildID : string ) : Promise < TypesGen . WorkspaceResource [ ] > => {
121
+ const response = await axios . get < TypesGen . WorkspaceResource [ ] > (
122
+ `/api/v2/workspacebuilds/${ workspaceBuildID } /resources` ,
123
+ )
116
124
return response . data
117
125
}
118
126
119
- export const createUser = async ( user : Types . CreateUserRequest ) : Promise < TypesGen . User > => {
127
+ export const createUser = async ( user : TypesGen . CreateUserRequest ) : Promise < TypesGen . User > => {
120
128
const response = await axios . post < TypesGen . User > ( "/api/v2/users" , user )
121
129
return response . data
122
130
}
123
131
124
- export const getBuildInfo = async ( ) : Promise < Types . BuildInfoResponse > => {
132
+ export const getBuildInfo = async ( ) : Promise < TypesGen . BuildInfoResponse > => {
125
133
const response = await axios . get ( "/api/v2/buildinfo" )
126
134
return response . data
127
135
}
128
136
129
137
export const putWorkspaceAutostart = async (
130
138
workspaceID : string ,
131
- autostart : Types . WorkspaceAutostartRequest ,
139
+ autostart : TypesGen . UpdateWorkspaceAutostartRequest ,
132
140
) : Promise < void > => {
133
141
const payload = JSON . stringify ( autostart )
134
142
await axios . put ( `/api/v2/workspaces/${ workspaceID } /autostart` , payload , {
@@ -138,15 +146,18 @@ export const putWorkspaceAutostart = async (
138
146
139
147
export const putWorkspaceAutostop = async (
140
148
workspaceID : string ,
141
- autostop : Types . WorkspaceAutostopRequest ,
149
+ autostop : TypesGen . UpdateWorkspaceAutostopRequest ,
142
150
) : Promise < void > => {
143
151
const payload = JSON . stringify ( autostop )
144
152
await axios . put ( `/api/v2/workspaces/${ workspaceID } /autostop` , payload , {
145
153
headers : { ...CONTENT_TYPE_JSON } ,
146
154
} )
147
155
}
148
156
149
- export const updateProfile = async ( userId : string , data : Types . UpdateProfileRequest ) : Promise < Types . UserResponse > => {
157
+ export const updateProfile = async (
158
+ userId : string ,
159
+ data : TypesGen . UpdateUserProfileRequest ,
160
+ ) : Promise < TypesGen . User > => {
150
161
const response = await axios . put ( `/api/v2/users/${ userId } /profile` , data )
151
162
return response . data
152
163
}
0 commit comments