SDK Reference
Complete reference for the Gatepost SDK.
Installation
bash
npm install @gatepost/clientInitialization
typescript
import { GatepostProvider } from "@gatepost/client";
import { OpenFeature } from "@openfeature/client";
await OpenFeature.setProvider(new GatepostProvider({
apiKey: process.env.GATEPOST_API_KEY, // Required
environment: "production", // Optional: default environment
projectId: "xxx", // Optional: specific project
}));Client methods
getBooleanValue
typescript
getBooleanValue(
flagKey: string,
defaultValue: boolean,
options?: EvaluationOptions
): Promise<boolean>getStringValue
typescript
getStringValue(
flagKey: string,
defaultValue: string,
options?: EvaluationOptions
): Promise<string>getNumberValue
typescript
getNumberValue(
flagKey: string,
defaultValue: number,
options?: EvaluationOptions
): Promise<number>getObjectValue
typescript
getObjectValue<T>(
flagKey: string,
defaultValue: T,
options?: EvaluationOptions
): Promise<T>Options
typescript
interface EvaluationOptions {
/** User attributes for targeting */
attributes?: Record<string, string | string[]>;
/** Segment keys to evaluate against */
segments?: string[];
/** Rollout percentage (0-100) */
rolloutPercentage?: number;
/** Override default environment */
environment?: string;
}Hooks (React)
If using React, use the useFeature hook:
typescript
import { useFeature } from "@gatepost/client/react";
function MyComponent() {
const enabled = useFeature("my-flag", false);
const theme = useFeature("theme", "light");
return <div>{enabled ? "On" : "Off"}</div>;
}