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/sdk

Initialization

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

FunctionParametersReturnsDescription
initconfig: SdkConfig publicToken: string, optional baseUrl, traitsvoidInitializes the SDK with your project token and optional default traits.
flagname: string, traitOverrides?: UserTraitsbooleanEvaluates a feature flag. Returns false if the SDK is not initialized.
setTraitstraits: UserTraits (Record<string, string>)voidReplaces the current global traits.
reporterror: unknown, flagName?: string, traitOverrides?: UserTraitsvoidReports an error for auto-rollback correlation.
closevoidFlushes pending evaluations and disconnects the WebSocket.

We use cookies to analyze site usage and improve your experience.