A lightweight TypeScript SDK for fetching configuration from Togglit.
npm install togglit-sdkyarn add togglit-sdkpnpm add togglit-sdkimport { getConfig } from 'togglit-sdk';
const config = await getConfig({
apiKey: 'your-api-key',
projectId: 'your-project-id',
env: 'production',
version: 1
});
console.log(config);Fetches configuration from Togglit with automatic fallback support.
| Parameter | Type | Required | Description |
|---|---|---|---|
| apiKey | string | ✅ | Your Togglit API key |
| projectId | string | ✅ | Your project identifier |
| env | string | ✅ | Environment name (e.g. 'production') |
| version | number | ❌ | Optional config version |
| fallback | object | ❌ | Fallback config object |
const config = await getConfig({
apiKey: process.env.TOGGLIT_API_KEY,
projectId: 'my-app',
env: process.env.NODE_ENV,
fallback: {
enableBetaFeatures: false,
showMaintenanceMode: false
}
});
if (config.enableBetaFeatures) {
// Show beta UI
}If the API call fails, the SDK will log a warning, use your fallback, and continue.
const config = await getConfig({
apiKey: 'invalid-key',
projectId: 'my-project',
env: 'production',
fallback: {
enableNewFeature: false,
maxRetries: 3
}
});
// fallback config is used if request failsimport { getConfig, GetConfigOptions } from 'togglit-sdk';
const options: GetConfigOptions = {
apiKey: 'your-api-key',
projectId: 'your-project-id',
env: 'production',
version: 1,
fallback: {
feature1: true,
feature2: false
}
};
const config = await getConfig(options);