UNPKG

togglit-sdk

Version:

ToggLit SDK makes it easy to fetch dynamic JSON config files from your ToggLit project environments using just a project ID and API key. Ideal for feature toggles, remote settings, A/B testing, and more — without redeploying code.

25 lines (24 loc) 791 B
export async function getConfig({ projectId, env, apiKey, version, fallback = {}, }) { const url = new URL("https://togglit.dev/api/config"); url.searchParams.append("projectId", projectId); url.searchParams.append("env", env); if (version) { url.searchParams.append("version", version.toString()); } try { const res = await fetch(url.toString(), { headers: { Authorization: `Bearer ${apiKey}`, }, }); if (!res.ok) { throw new Error("Failed to fetch config"); } const data = await res.json(); return data.config ?? fallback; } catch (error) { console.warn("Togglit fallback config used due to error:", error); return fallback; } }