()
| 120 | * machine falls back to env-setup on next load. |
| 121 | */ |
| 122 | export async function createDefaultEnvironment(): Promise<boolean> { |
| 123 | let accessToken: string, orgUUID: string |
| 124 | try { |
| 125 | ;({ accessToken, orgUUID } = await prepareApiRequest()) |
| 126 | } catch { |
| 127 | return false |
| 128 | } |
| 129 | |
| 130 | if (await hasExistingEnvironment()) { |
| 131 | return true |
| 132 | } |
| 133 | |
| 134 | // The /private/organizations/{org}/ path rejects CLI OAuth tokens (wrong |
| 135 | // auth dep). The public path uses build_flexible_auth — same path |
| 136 | // fetchEnvironments() uses. Org is passed via x-organization-uuid header. |
| 137 | const url = buildNoumenaPlatformUrl('/v1/environment_providers/cloud/create') |
| 138 | const headers = { |
| 139 | ...getOAuthHeaders(accessToken), |
| 140 | 'x-organization-uuid': orgUUID, |
| 141 | } |
| 142 | |
| 143 | try { |
| 144 | const response = await axios.post( |
| 145 | url, |
| 146 | { |
| 147 | name: 'Default', |
| 148 | kind: NOUMENA_CLOUD_ENVIRONMENT_KIND, |
| 149 | description: 'Default - trusted network access', |
| 150 | config: { |
| 151 | environment_type: 'noumena', |
| 152 | cwd: '/home/user', |
| 153 | init_script: null, |
| 154 | environment: {}, |
| 155 | languages: [ |
| 156 | { name: 'python', version: '3.11' }, |
| 157 | { name: 'node', version: '20' }, |
| 158 | ], |
| 159 | network_config: { |
| 160 | allowed_hosts: [], |
| 161 | allow_default_hosts: true, |
| 162 | }, |
| 163 | }, |
| 164 | }, |
| 165 | { headers, timeout: 15000, validateStatus: () => true }, |
| 166 | ) |
| 167 | return response.status >= 200 && response.status < 300 |
| 168 | } catch { |
| 169 | return false |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | /** Returns true when the user has valid Noumena OAuth credentials. */ |
| 174 | export async function isSignedIn(): Promise<boolean> { |
no test coverage detected