const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
let __intlayer_api = require("@intlayer/api");
let __intlayer_config = require("@intlayer/config");

//#region src/utils/checkAccess.ts
const checkCMSAuth = async (configuration) => {
	const appLogger = (0, __intlayer_config.getAppLogger)(configuration, { config: { prefix: "" } });
	if (!(configuration.editor.clientId && configuration.editor.clientSecret)) {
		appLogger("CMS auth not provided.", { level: "error" });
		return false;
	}
	const intlayerAPI = (0, __intlayer_api.getIntlayerAPIProxy)(void 0, configuration);
	try {
		await intlayerAPI.oAuth.getOAuth2AccessToken();
	} catch (error) {
		appLogger((0, __intlayer_config.extractErrorMessage)(error), { level: "error" });
		return false;
	}
	return true;
};
const checkAIAccess = async (configuration, aiOptions) => {
	const appLogger = (0, __intlayer_config.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