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

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

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 

Last updated