Skip to main content

Overview

The defineFeature() function defines a feature (entitlement) in your billing configuration. It’s an identity function that provides type inference and autocomplete while returning the input as-is. Features represent capabilities or resources in your product that can be gated based on subscription plans.

Function Signature

function defineFeature<T extends FeatureDefInput>(config: T): T

Type Parameters

T
T extends FeatureDefInput
The feature configuration type. Must extend FeatureDefInput.

Parameters

config
FeatureDefInput
required
The feature configuration object.

Returns

config
T
The same configuration object passed in, with full type inference preserved.

Usage

Boolean Feature

import { defineFeature } from "@revstack/core";

export const sso = defineFeature({
  name: "Single Sign-On",
  description: "SAML/OAuth SSO authentication",
  type: "boolean",
  unit_type: "count",
});

Static Feature

import { defineFeature } from "@revstack/core";

export const seats = defineFeature({
  name: "Team Seats",
  description: "Number of team members who can access the workspace",
  type: "static",
  unit_type: "count",
});

Metered Feature

import { defineFeature } from "@revstack/core";

export const apiCalls = defineFeature({
  name: "API Calls",
  description: "Monthly API request quota",
  type: "metered",
  unit_type: "requests",
});

export const storage = defineFeature({
  name: "Cloud Storage",
  description: "Total storage capacity in bytes",
  type: "metered",
  unit_type: "bytes",
});

export const aiTokens = defineFeature({
  name: "AI Tokens",
  description: "LLM token usage for AI features",
  type: "metered",
  unit_type: "tokens",
});

Complete Configuration

import { defineConfig, defineFeature, definePlan } from "@revstack/core";

export default defineConfig({
  features: {
    // Boolean feature
    sso: defineFeature({
      name: "Single Sign-On",
      type: "boolean",
      unit_type: "count",
    }),
    
    // Static feature
    seats: defineFeature({
      name: "Team Seats",
      type: "static",
      unit_type: "count",
    }),
    
    // Metered feature
    api_calls: defineFeature({
      name: "API Calls",
      type: "metered",
      unit_type: "requests",
    }),
  },
  plans: {
    starter: definePlan({
      name: "Starter",
      is_default: true,
      is_public: true,
      type: "free",
      features: {
        sso: { value_bool: false },
        seats: { value_limit: 3 },
        api_calls: { value_limit: 1000, reset_period: "monthly" },
      },
    }),
  },
});

Feature Types Explained

Boolean Features

Simple on/off toggles. Use value_bool: true or value_bool: false in plan feature values. Examples: SSO, Priority Support, Custom Branding

Static Features

Fixed limits that don’t reset. Use value_limit in plan feature values. Examples: Team Seats, Projects, Workspaces

Metered Features

Usage-based limits that can reset periodically. Use value_limit and reset_period in plan feature values. Examples: API Calls, Storage, AI Tokens, Email Sends

Source

Location: packages/core/src/define.ts:18-20

Build docs developers (and LLMs) love