Hypertune
  • Introduction
  • Getting Started
    • Set up Hypertune
    • Next.js (App Router) quickstart
    • Next.js (Pages Router) quickstart
    • React quickstart
    • Remix quickstart
    • Gatsby quickstart
    • Vue quickstart
    • Nuxt quickstart
    • Node.js quickstart
    • React Native quickstart
    • JavaScript quickstart
    • Python quickstart
    • Rust quickstart
    • Go quickstart
    • Web quickstart
    • GraphQL quickstart
  • Example apps
    • Next.js and Vercel example app
  • Concepts
    • Architecture
    • Project
    • Schema
    • Flag lifecycle
    • Logic
    • Variables
    • Splits
    • A/B tests
    • Staged rollouts
    • Multivariate tests
    • Machine learning loops
    • Events
    • Funnels
    • Hypertune Edge
    • Reduction
    • SDKs
    • GraphQL API
    • Git-style version control
    • App configuration
  • Use Cases
    • Feature flags and A/B testing
    • Landing page optimization
    • In-app content management
    • Pricing plan management
    • Permissions, rules and limits
    • Optimizing magic numbers
    • Backend configuration
    • Product analytics
  • Integrations
    • Vercel Edge Config integration
    • Google Analytics integration
    • Segment integration
    • Webhooks
      • Creating webhooks
      • Handling webhooks
  • SDK Reference
    • Installation
    • Type-safe client generation
    • Initialization
    • Build-time logic snapshot
    • Hard-coded fallbacks
    • Local-only, offline mode
    • Hydrate from your own server
    • Wait for server initialization
    • Provide targeting attributes
    • Local, synchronous evaluation
    • Remote logging
    • Getting flag updates
    • Serverless environments
    • Vercel Edge Config
    • Custom logging
    • Shutting down
Powered by GitBook
On this page
  1. SDK Reference

Type-safe client generation

SDKs come with a CLI tool to auto-generate a client so you can access your flags with end-to-end type-safety. This ensures typos in flag names or incorrectly passed targeting attributes can be caught at build-time rather than runtime. It also improves the developer experience with code completion, "find all references" and type-safe flag clean up.

To generate a client, first define the following environment variables in your .env file:

NEXT_PUBLIC_HYPERTUNE_TOKEN=token
HYPERTUNE_FRAMEWORK=nextApp
HYPERTUNE_OUTPUT_DIRECTORY_PATH=generated

Replace token with your project token which you can find in the Settings tab of your project.

Then run:

npx hypertune
yarn hypertune
pnpm hypertune

Customize client generation

You can customize client generation with the following environment variables:

# Set whether Hypertune should include a build-time snapshot of your flag logic
HYPERTUNE_INCLUDE_INIT_DATA=true

# Set whether Hypertune should include your token in the generated code
HYPERTUNE_INCLUDE_TOKEN=true

# Set where Hypertune should find your query file path
HYPERTUNE_QUERY_FILE_PATH=hypertune.graphql

You can also pass these as command-line arguments. To see all available options, run:

npx hypertune --help
yarn hypertune --help
pnpm hypertune --help

This will output:

Usage:
  $ hypertune 

Commands:
    Generate Hypertune files for your project

For more info, run any command with the `--help` flag:
  $ hypertune --help

Options:
  --token [value]                   Project token 
  --branchName [value]              Project branch to use 
  --queryFilePath [value]           File path to the GraphQL initialization query (default: hypertune.graphql)
  --outputFilePath [value]          (Deprecated) The path to write the generated file to 
  --outputDirectoryPath [value]     The directory to write the generated files to (default: generated)
  --includeToken                    Include the project token in the generated code (default: false)
  --includeInitData                 Embed a static snapshot of your flag logic in the generated code so the SDK can reliably, locally and instantly initialize first, before fetching the latest logic from the server, and can function even if the server is unreachable (default: false)
  --language [value]                Target language (ts or js) (default: ts)
  --framework [value]               Framework (nextApp, nextPages, react, remix or gatsby) 
  --platform [value]                Platform (vercel) 
  --getHypertuneImportPath [value]  Relative import path for a file with a default export of the `getHypertune` function, which takes a single object argument containing readonly `headers` and `cookies`; only used for the nextApp framework and vercel platform 
  -h, --help                        Display this message 
  -v, --version                     Display version number 
PreviousInstallationNextInitialization

Last updated 10 months ago