( accessToken: string, )
| 309 | } |
| 310 | |
| 311 | export async function createAndStoreApiKey( |
| 312 | accessToken: string, |
| 313 | ): Promise<string | null> { |
| 314 | try { |
| 315 | const response = await axios.post(getOauthConfig().API_KEY_URL, null, { |
| 316 | headers: { Authorization: `Bearer ${accessToken}` }, |
| 317 | }) |
| 318 | |
| 319 | const apiKey = response.data?.raw_key |
| 320 | if (apiKey) { |
| 321 | await saveApiKey(apiKey) |
| 322 | logEvent('tengu_oauth_api_key', { |
| 323 | status: |
| 324 | 'success' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 325 | statusCode: response.status, |
| 326 | }) |
| 327 | return apiKey |
| 328 | } |
| 329 | return null |
| 330 | } catch (error) { |
| 331 | logEvent('tengu_oauth_api_key', { |
| 332 | status: |
| 333 | 'failure' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 334 | error: (error instanceof Error |
| 335 | ? error.message |
| 336 | : String( |
| 337 | error, |
| 338 | )) as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 339 | }) |
| 340 | throw error |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | export function isOAuthTokenExpired(expiresAt: number | null): boolean { |
| 345 | if (expiresAt === null) { |
no test coverage detected