Skip to content

feature gate

awekrx edited this page May 29, 2026 · 1 revision

feature-gate

Import

import { featureGate } from '@dev-suite/decorators/feature-gate'

Category

  • class

Use Case

Enable/disable class usage behind a runtime feature flag.

Replaces

  • Repeated flag checks in every public method
  • Forked class implementations for on/off flows

Example 1

Without decorator

class NewCheckoutFlow {
  start(cartId: string) {
    if (!flags.isEnabled('checkout.v2')) {
      throw new Error('Feature disabled');
    }

    return this.orchestrator.start(cartId);
  }
}

With decorator

import { featureGate } from '@dev-suite/decorators/feature-gate';

@featureGate({
  isEnabled: () => flags.isEnabled('checkout.v2'),
  featureName: 'checkout.v2',
})
class NewCheckoutFlow {
  start(cartId: string) {
    return this.orchestrator.start(cartId);
  }
}

Why better

  • Gate policy is declared once at class level
  • Business methods stay free from feature-toggle boilerplate

Example 2

Without decorator

class AdvancedScoringEngine {
  score(input: ScoreInput) {
    if (!config.features.advancedScoring) {
      throw new Error('advanced scoring disabled');
    }

    return this.compute(input);
  }
}

With decorator

import { featureGate } from '@dev-suite/decorators/feature-gate';

@featureGate({ isEnabled: () => config.features.advancedScoring })
class AdvancedScoringEngine {
  score(input: ScoreInput) {
    return this.compute(input);
  }
}

Why better

  • Consistent feature-gating model across multiple classes
  • Easier migration when flags are removed later

Clone this wiki locally