()
| 53 | * @throws Error if the API request fails or no access token is available |
| 54 | */ |
| 55 | export async function fetchEnvironments(): Promise<EnvironmentResource[]> { |
| 56 | const { accessToken, orgUUID } = await resolveManagedRemoteCapability() |
| 57 | |
| 58 | const url = buildNoumenaPlatformUrl('/v1/environment_providers') |
| 59 | |
| 60 | try { |
| 61 | const headers = { |
| 62 | ...getOAuthHeaders(accessToken), |
| 63 | 'x-organization-uuid': orgUUID, |
| 64 | } |
| 65 | |
| 66 | const response = await axios.get<EnvironmentListResponse>(url, { |
| 67 | headers, |
| 68 | timeout: 15000, |
| 69 | }) |
| 70 | |
| 71 | if (response.status !== 200) { |
| 72 | throw new Error( |
| 73 | `Failed to fetch environments: ${response.status} ${response.statusText}`, |
| 74 | ) |
| 75 | } |
| 76 | |
| 77 | return response.data.environments.map(environment => ({ |
| 78 | ...environment, |
| 79 | kind: normalizeEnvironmentKind(environment.kind), |
| 80 | })) |
| 81 | } catch (error) { |
| 82 | const err = toError(error) |
| 83 | logError(err) |
| 84 | throw new Error(`Failed to fetch environments: ${err.message}`) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Creates a default noumena_cloud environment for users who have none. |
no test coverage detected