import { getIntlayerAPIProxy } from "@intlayer/api";
import { extractErrorMessage, getAppLogger } from "@intlayer/config";

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