import { SoluteClient } from '@solute-ai/sdk';const solute = new SoluteClient({ apiKey: 'your_api_key', host: 'https://api.solute.dev',});// Check if a feature is enabledif (solute.isFeatureEnabled('new-checkout-flow')) { // Show new checkout flow} else { // Show old checkout flow}
// Get the flag value (can be boolean, string, number, or object)const flagValue = solute.getFeatureFlag('new-checkout-flow');if (flagValue === true) { // Feature is enabled}// With default valueconst flagValue = solute.getFeatureFlag('new-checkout-flow', { defaultValue: false,});
// Get the variant for an A/B testconst variant = solute.getExperimentVariant('pricing-test');if (variant === 'variant-a') { // Show variant A} else if (variant === 'variant-b') { // Show variant B} else { // Show control/default}// With default valueconst variant = solute.getExperimentVariant('pricing-test', { defaultValue: 'control',});
const variant = solute.getExperimentVariant('pricing-page-test');switch (variant) { case 'variant-a': // Show new pricing layout renderNewPricingLayout(); break; case 'variant-b': // Show alternative pricing layout renderAlternativePricingLayout(); break; default: // Show original pricing layout renderOriginalPricingLayout();}
// Get all feature flags at onceconst allFlags = solute.getAllFlags();// Access individual flagsif (allFlags['new-checkout-flow']?.enabled) { // Feature is enabled}// Get experiment variant from all flagsconst experiment = allFlags['pricing-test'];if (experiment?.variant === 'variant-a') { // Show variant A}
Feature flags can be targeted based on user properties. The SDK automatically includes user properties when fetching flags:
Copy
// Identify user with propertiessolute.identify('user_123', { plan: 'premium', country: 'US', beta_tester: true,});// Flags will be evaluated based on these propertiesconst flag = solute.getFeatureFlag('premium-feature');