Skip to main content
Glama
checkAccess.ts2.33 kB
import type { AIOptions } from '@intlayer/api'; import { getIntlayerAPIProxy } from '@intlayer/api'; import { ANSIColors, colorize, extractErrorMessage, getAppLogger, } from '@intlayer/config'; import type { IntlayerConfig } from '@intlayer/types'; export const checkCMSAuth = async ( configuration: IntlayerConfig ): Promise<boolean> => { const appLogger = getAppLogger(configuration, { config: { prefix: '', }, }); const hasCMSAuth = configuration.editor.clientId && configuration.editor.clientSecret; if (!hasCMSAuth) { appLogger('CMS auth not provided.', { level: 'error', }); return false; } const intlayerAPI = getIntlayerAPIProxy(undefined, configuration); try { await intlayerAPI.oAuth.getOAuth2AccessToken(); } catch (error) { const message = extractErrorMessage(error); appLogger(message, { level: 'error', }); return false; } return true; }; export const checkAIAccess = async ( configuration: IntlayerConfig, aiOptions?: AIOptions ): Promise<boolean> => { const appLogger = getAppLogger(configuration); const hasCMSAuth = Boolean( configuration.editor.clientId && configuration.editor.clientSecret ); const hasHisOwnAIAPIKey = Boolean( configuration.ai?.apiKey || aiOptions?.apiKey ); if (hasHisOwnAIAPIKey) { return true; } // User need to provide either his own AI API key or the CMS auth if (!hasCMSAuth) { appLogger( [ 'AI options or API key not provided. You can either retreive the CMS access key on', colorize('https://intlayer.org/dahboard', ANSIColors.GREY), colorize('(see doc:', ANSIColors.GREY_DARK), colorize('https://intlayer.org/doc/concept/cms', ANSIColors.GREY), colorize(')', ANSIColors.GREY_DARK), '. Alternatively, you can add your own OpenAI API key in the settings', colorize('(see doc:', ANSIColors.GREY_DARK), colorize( 'https://intlayer.org/doc/concept/configuration', ANSIColors.GREY ), colorize(')', ANSIColors.GREY_DARK), '.', ], { level: 'error', } ); return false; } // If the user do not have his own AI API key, we need to check the CMS auth return await checkCMSAuth(configuration); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server