-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathapi.ts
More file actions
51 lines (40 loc) · 1.25 KB
/
api.ts
File metadata and controls
51 lines (40 loc) · 1.25 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
import { API_ENDPOINTS } from '@/stores/constants'
export interface EnvironmentVariable {
key: string
value: string
}
export interface WorkspaceEnvironmentData {
workspace: Record<string, string>
personal: Record<string, string>
conflicts: string[]
}
export async function fetchPersonalEnvironment(
signal?: AbortSignal
): Promise<Record<string, EnvironmentVariable>> {
const response = await fetch(API_ENDPOINTS.ENVIRONMENT, { signal })
if (!response.ok) {
await response.text().catch(() => {})
throw new Error(`Failed to load environment variables: ${response.statusText}`)
}
const { data } = await response.json()
if (data && typeof data === 'object') {
return data
}
return {}
}
export async function fetchWorkspaceEnvironment(
workspaceId: string,
signal?: AbortSignal
): Promise<WorkspaceEnvironmentData> {
const response = await fetch(API_ENDPOINTS.WORKSPACE_ENVIRONMENT(workspaceId), { signal })
if (!response.ok) {
await response.text().catch(() => {})
throw new Error(`Failed to load workspace environment: ${response.statusText}`)
}
const { data } = await response.json()
return {
workspace: data.workspace || {},
personal: data.personal || {},
conflicts: data.conflicts || [],
}
}