( accessToken: string, )
| 274 | } |
| 275 | |
| 276 | export async function fetchAndStoreUserRoles( |
| 277 | accessToken: string, |
| 278 | ): Promise<void> { |
| 279 | const response = await axios.get(getOauthConfig().ROLES_URL, { |
| 280 | headers: { Authorization: `Bearer ${accessToken}` }, |
| 281 | }) |
| 282 | |
| 283 | if (response.status !== 200) { |
| 284 | throw new Error(`Failed to fetch user roles: ${response.statusText}`) |
| 285 | } |
| 286 | const data = response.data as UserRolesResponse |
| 287 | const config = getGlobalConfig() |
| 288 | |
| 289 | if (!config.oauthAccount) { |
| 290 | throw new Error('OAuth account information not found in config') |
| 291 | } |
| 292 | |
| 293 | saveGlobalConfig(current => ({ |
| 294 | ...current, |
| 295 | oauthAccount: current.oauthAccount |
| 296 | ? { |
| 297 | ...current.oauthAccount, |
| 298 | organizationRole: data.organization_role, |
| 299 | workspaceRole: data.workspace_role, |
| 300 | organizationName: data.organization_name, |
| 301 | } |
| 302 | : current.oauthAccount, |
| 303 | })) |
| 304 | |
| 305 | logEvent('tengu_oauth_roles_stored', { |
| 306 | org_role: |
| 307 | data.organization_role as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 308 | }) |
| 309 | } |
| 310 | |
| 311 | export async function createAndStoreApiKey( |
| 312 | accessToken: string, |
no test coverage detected