flags
The `flags` package provides the core functionality for integrating with Vercel.
reportValue
Reports the value of a feature flag to Vercel so it can show up in Runtime Logs and be used with Web Analytics custom server-side events. Returns undefined
.
Parameter | Type | Description |
---|---|---|
key | string | Key of the feature flag |
value | any | Value of the feature flag |
encrypt
A method for encrypting data (Flag definitions, overrides, and values). Returns a Promise
.
Parameter | Type | Description |
---|---|---|
data | Object | Data to be encrypted |
secret (Optional) | string | The secret being used to encrypt. Defaults to process.env.FLAGS_SECRET |
Here is an example of encrypting flag values to be used by the Vercel Toolbar.
decrypt
A method for decrypting data. Returns a Promise
.
Parameter | Type | Description |
---|---|---|
encryptedData | string | Data to be decrypted |
secret (Optional) | string | The secret being used to encrypt data. Defaults to process.env.FLAGS_SECRET |
The decrypt
method's primary use case is decrypting the data stored inside the vercel-flag-overrides
cookie. It's also used by the Vercel Toolbar to handle your feature flag data.
verifyAccess
A method for verifying whether a request to your application's flags endpoint was made by the Vercel Toolbar.
You can use verifyAccess
to keep your endpoint private. Returns a Promise
with a true
or false
value.
Parameter | Type | Description |
---|---|---|
authHeader . | string | Authorization header to check |
secret (Optional) | string | The secret being used to encrypt data. Defaults to process.env.FLAGS_SECRET |
If you are using the Pages
router, you will need to add the following to your next.config.js
. This is because the Pages
router can't specify API routes outside of the api
folder. This means you need a rewrite.
safeJsonStringify
A safe version of JSON.stringify
that escapes the resulting output to prevent XSS attacks. Returns string
.
Parameter | Type | Description |
---|---|---|
value | any | A valid JSON object to convert |
replacer (Optional) | function | Array | A replacer function or Array |
space (Optional) | string | number | Specifies the spacing in the output |
mergeProviderData
Merges provider data from multiple sources. Extends the feature flags defined in code with metadata from your feature flag provider, for use with the Flags Explorer.
Parameter | Type | Description |
---|---|---|
data | (ProviderData | Promise<ProviderData>)[] | A list of provider data objects to merge. |