Skip to Content
Developer GuideJavaScriptSDK Reference

JavaScript SDK API Reference

Complete API reference for @supashiphq/javascript-sdk (browser).

Constructor

const client = new SupaClient(config)

Parameters:

  • config (object) - Configuration object

Config Options:

  • apiKey (string, required) - Your Supaship client API key
  • environment (string, required) - The environment slug (e.g., ‘production’, ‘staging’, ‘development’)
  • features (FeaturesWithFallbacks, required) - Feature definitions should satisfy FeaturesWithFallbacks
  • context (object, optional) - Default user context for all requests
  • networkConfig (object, optional) - Network settings including endpoints, retry configurations, timeout, and custom fetch functions
  • plugins (array, optional) - Plugins for observability, caching, etc.

Methods

getFeature(featureKey, options)

Gets single feature flag value with full TypeScript type safety. Returns the type defined in your features config.

// Basic usage const isEnabled = await client.getFeature('new-feature') // Returns the type defined in FEATURE_FLAGS for 'new-feature' // With context override const value = await client.getFeature('feature-name', { context: { plan: 'premium' }, }) // Object/JSON configuration const config = await client.getFeature('api-config') // Returns object type configured in FEATURE_FLAGS console.log(config.timeout, config.retries)

Parameters:

  • featureKey (string, required) - The name of the feature flag (must be defined in features config)
  • options.context (object, optional) - Context override for this request

getFeatures(featureNames, options)

Get multiple feature flags at once. Returns an object with the feature flag names as keys and the flag values as values.

// Get multiple features const results = await client.getFeatures(['new-navigation', 'api-config'], { context: { userID: '456', // Override default context for this request }, }) console.log(results) // { 'new-navigation': true, 'api-config': { ... } }

Parameters:

  • featureNames (array, required) - Array of feature flag names (must be defined in features config)
  • options.context (object, optional) - Context override for this request

updateContext(context, mergeWithExisting)

Update the default context for all subsequent requests. This context is used for all feature flag evaluations unless overridden by the context parameter in the getFeature or getFeatures methods.

This is helpful when the context data is not available at the time of client initialization, and you need to wait for async data to be available before evaluating feature flags.

const client = new SupaClient({ apiKey: YOUR_PROJECT_API_KEY, // Client API Key, found in your project settings environment: 'production', // Environment slug features: FEATURE_FLAGS, context: {}, // Empty context }) const context = await apiCallToGetContext() // Updates the default context for all subsequent requests client.updateContext(context) // All subsequent getFeature calls will use the updated context const isEnabled = await client.getFeature('new-navigation') // Replace entire context (don't merge) client.updateContext({ userID: '789' }, false)

Parameters:

  • context (object, required) - New context data
  • mergeWithExisting (boolean, optional) - Whether to merge with existing context (default: true)

getContext()

Get the current default context. Returns an object with the current context data.

const context = client.getContext() console.log('Current context:', context)
Last updated on