( accessToken: string, )
| 337 | } |
| 338 | |
| 339 | export async function createAndStoreApiKey( |
| 340 | accessToken: string, |
| 341 | ): Promise<string | null> { |
| 342 | try { |
| 343 | const response = await axios.post(getOauthConfig().API_KEY_URL, null, { |
| 344 | headers: { Authorization: `Bearer ${accessToken}` }, |
| 345 | }) |
| 346 | |
| 347 | const apiKey = response.data?.raw_key |
| 348 | if (apiKey) { |
| 349 | await saveApiKey(apiKey) |
| 350 | logEvent('tengu_oauth_api_key', { |
| 351 | status: |
| 352 | 'success' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 353 | statusCode: response.status, |
| 354 | }) |
| 355 | return apiKey |
| 356 | } |
| 357 | return null |
| 358 | } catch (error) { |
| 359 | logEvent('tengu_oauth_api_key', { |
| 360 | status: |
| 361 | 'failure' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 362 | error: (error instanceof Error |
| 363 | ? error.message |
| 364 | : String( |
| 365 | error, |
| 366 | )) as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 367 | }) |
| 368 | throw error |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | export function isOAuthTokenExpired(expiresAt: number | null): boolean { |
| 373 | if (expiresAt === null) { |
no test coverage detected