Web / JS SDK
PreviewThe @ctrlapp/sdk package wraps the REST endpoints with caching, polling, and typed control accessors.
Source preview · registry release pending
This SDK's source lives in this repository. A public registry install may not resolve yet. Use REST today, or use a local path / project reference from a checked-out source tree (requires repository access) — see SDK & package availability.
Source preview · registry release pending
The
@ctrlapp/sdk package source lives at packages/ctrl-sdk/in this repo. A public npm i @ctrlapp/sdk is not guaranteed to succeed today. Until the registry release ships, either vendor the package or call REST directly — see REST quickstart.Intended usage once released
ts· ctrl.ts
import { Ctrl } from "@ctrlapp/sdk";
const ctrl = Ctrl.init({
apiKey: "<PUBLISHABLE_KEY>",
deviceId: "<DEVICE_ID>", // stable per install
baseUrl: "https://ctrlapp.krdcode.com", // override if self-hosted
pollIntervalMs: 60_000, // 0 = disabled
appVersion: "0.1.0",
platform: "web",
});
await ctrl.load();
if (ctrl.blocked()) {
showMaintenance(ctrl.blockReason());
return;
}
if (ctrl.flag("checkout_v2").isOn) mountNewCheckout();
button.textContent = ctrl.text("cta_primary", "Buy now");React hooks
tsx· Checkout.tsx
import { useFlag, useControl } from "@ctrlapp/sdk/react";
export function Checkout() {
const enabled = useFlag("checkout_v2");
const cta = useControl("cta_primary", { text: "Buy now" });
return enabled ? <NewFlow cta={cta.text} /> : <LegacyFlow />;
}Security
Do not enable request signing in the browser. The signing secret would be exfiltrable from any client bundle. Publishable-key auth alone is designed to be safe in browsers.
Verify it
- The SDK initializes without errors in the browser console.
- Toggling a flag in the dashboard changes the value the SDK returns within one poll interval.