const require_logger = require('../../../../config/dist/esm/logger.cjs');
const require_extractErrorMessage = require('../../../../config/dist/esm/utils/extractErrorMessage.cjs');
const require_proxy = require('../api/dist/esm/proxy.cjs');

//#region ../@intlayer/cli/dist/esm/utils/checkAccess.mjs
const checkCMSAuth = async (configuration) => {
	const appLogger = require_logger.getAppLogger(configuration, { config: { prefix: "" } });
	if (!(configuration.editor.clientId && configuration.editor.clientSecret)) {
		appLogger("CMS auth not provided.", { level: "error" });
		return false;
	}
	const intlayerAPI = require_proxy.getIntlayerAPIProxy(void 0, configuration);
	try {
		await intlayerAPI.oAuth.getOAuth2AccessToken();
	} catch (error) {
		appLogger(require_extractErrorMessage.extractErrorMessage(error), { level: "error" });
		return false;
	}
	return true;
};
const checkAIAccess = async (configuration, aiOptions) => {
	const appLogger = require_logger.getAppLogger(configuration);
	const hasCMSAuth = Boolean(configuration.editor.clientId && configuration.editor.clientSecret);
	if (Boolean(configuration.ai?.apiKey || aiOptions?.apiKey)) return true;
	if (!hasCMSAuth) {
		appLogger("AI options or API key not provided.", { level: "error" });
		return false;
	}
	return await checkCMSAuth(configuration);
};

//#endregion
exports.checkAIAccess = checkAIAccess;
exports.checkCMSAuth = checkCMSAuth;
//# sourceMappingURL=checkAccess.cjs.map