MCPcopy Create free account
hub / github.com/Noumena-Network/code / createAndStoreApiKey

Function createAndStoreApiKey

src/services/oauth/client.ts:441–478  ·  view source on GitHub ↗
(
  accessToken: string,
)

Source from the content-addressed store, hash-verified

439}
440
441export async function createAndStoreApiKey(
442 accessToken: string,
443): Promise<string | null> {
444 try {
445 const response = await getIdentityClient().createApiKey({ accessToken })
446 const apiKey = response.raw_key
447 if (apiKey) {
448 try {
449 /* eslint-disable @typescript-eslint/no-require-imports */
450 const { getAuthRuntime } =
451 require('../../auth/runtime/AuthRuntime.js') as typeof import('../../auth/runtime/AuthRuntime.js')
452 /* eslint-enable @typescript-eslint/no-require-imports */
453 await getAuthRuntime().persistStoredApiKey(apiKey)
454 } catch {
455 // Keep oauth client usable in isolated tests/bundles where AuthRuntime
456 // is not available yet.
457 }
458 logEvent('ncode_oauth_api_key', {
459 status:
460 'success' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
461 statusCode: response.status,
462 })
463 return apiKey
464 }
465 return null
466 } catch (error) {
467 logEvent('ncode_oauth_api_key', {
468 status:
469 'failure' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
470 error: (error instanceof Error
471 ? error.message
472 : String(
473 error,
474 )) as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
475 })
476 throw error
477 }
478}
479
480export function isOAuthTokenExpired(expiresAt: number | null): boolean {
481 if (expiresAt === null || Number.isNaN(expiresAt)) {

Callers 1

installOAuthTokensFunction · 0.85

Calls 4

getIdentityClientFunction · 0.85
getAuthRuntimeFunction · 0.85
persistStoredApiKeyMethod · 0.65
logEventFunction · 0.50

Tested by

no test coverage detected