import { fetcher } from "../fetcher.mjs";
import { built_default } from "../config/dist/esm/built.mjs";

//#region ../chokidar/dist/esm/api/dist/esm/getIntlayerAPI/oAuth.mjs
const getOAuthAPI = (intlayerConfig) => {
	const backendURL = intlayerConfig?.editor?.backendURL ?? built_default?.editor?.backendURL;
	const { clientId, clientSecret } = intlayerConfig?.editor ?? {};
	if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
	/**
	* Gets an oAuth2 accessToken
	* @return The token information
	*/
	const getOAuth2AccessToken = async (otherOptions = {}) => await fetcher(`${backendURL}/oauth2/token`, {}, otherOptions, {
		method: "POST",
		headers: { "Content-Type": "application/x-www-form-urlencoded" },
		body: {
			grant_type: "client_credentials",
			client_id: clientId,
			client_secret: clientSecret
		}
	});
	return { getOAuth2AccessToken };
};

//#endregion
export { getOAuthAPI };
//# sourceMappingURL=oAuth.mjs.map