TypeScript SDK
The DeployRamp TypeScript SDK lets you evaluate feature flags, set user traits, and report errors for automatic rollback in any Node.js or browser environment.
Installation
npm install @deployramp/sdkInitialization
Import the SDK and call init() with your public token. Optionally pass initial traits that will be sent with every flag evaluation.
import { init, flag, setTraits, report, close } from "@deployramp/sdk";
init({
publicToken: "pk_live_abc123",
traits: { plan: "pro", region: "us-east" },
});Evaluating Flags
Use flag() to check whether a feature is enabled. It returns false if the SDK has not been initialized. You can pass trait overrides to evaluate the flag for a different context without changing the global traits.
if (flag("new-checkout")) {
renderNewCheckout();
} else {
renderOldCheckout();
}
// With trait overrides
const enabled = flag("beta-feature", { role: "admin" });Setting Traits
Call setTraits() to replace the current global traits. These traits are sent with every subsequent flag evaluation.
setTraits({ plan: "enterprise", region: "eu-west" });Error Reporting
Report errors to DeployRamp so it can correlate failures with flag states and trigger automatic rollbacks when error rates spike.
try {
processPayment();
} catch (err) {
report(err, "new-checkout");
}Shutdown
Call close() before your process exits to flush pending evaluations and disconnect the WebSocket connection.
process.on("SIGTERM", () => {
close();
process.exit(0);
});API Reference
| Function | Parameters | Returns | Description |
|---|---|---|---|
init | config: SdkConfig — publicToken: string, optional baseUrl, traits | void | Initializes the SDK with your project token and optional default traits. |
flag | name: string, traitOverrides?: UserTraits | boolean | Evaluates a feature flag. Returns false if the SDK is not initialized. |
setTraits | traits: UserTraits (Record<string, string>) | void | Replaces the current global traits. |
report | error: unknown, flagName?: string, traitOverrides?: UserTraits | void | Reports an error for auto-rollback correlation. |
close | — | void | Flushes pending evaluations and disconnects the WebSocket. |