The SDK key validation now uses a regex (/^vf_(?:server|client)_/) to require
the format vf_server_* or vf_client_* instead of accepting any string starting
with vf_. This prevents false positives with third-party service identifiers
that happen to start with vf_ (e.g., Stripe identity flow IDs like
vf_1PyHgVLpWuMxVFx...).
Adds isValidSdkKey() helper function and updates parseSdkKeyFromFlagsConnectionString()
to use the stricter validation. Updates all tests to use valid SDK key formats.
* use __no_flags__ to handle precompute with empty flags
* handle __no_flags__ in serialize
* add __no_flags__ handling to sveltekit
* avoid returning undefined when defaultValue is set
This could only happen on precomputed flags in case of bad usage.
* add error messages
* test console logs
* update changeset
* Return meaningful result from prepareFlagsDefinitions
- Add PrepareFlagsDefinitionsResult discriminated union type that indicates whether definitions were created
- Change prepareFlagsDefinitions return type from Promise<void> to Promise<PrepareFlagsDefinitionsResult>
- Return { created: false, reason: 'no-sdk-keys' } when no SDK keys are found
- Return { created: true, sdkKeysCount: N } when definitions are successfully created
- Add tests for both return paths to verify the function communicates its result properly
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
* Add changeset for prepareFlagsDefinitions result type
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
* Replace version param with userAgentSuffix in prepare-flags-definitions
Changed the API to use a cleaner approach:
- Removed `version?: string` option in favor of `userAgentSuffix?: string`
- Now imports package version directly from package.json
- Constructs user-agent as: `@vercel/prepare-flags-definitions/{pkgVersion} {suffix}`
- Allows consumers (e.g., vercel-cli, vercel-api) to add context to the header
Added tests verifying both default and suffixed user-agent headers.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
* add changeset
---------
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
* Extract @vercel/prepare-flags-definitions package
Extract the core flag definitions preparation logic from the Vercel CLI into a standalone, reusable package. This includes:
- prepareFlagsDefinitions() function that collects SDK keys from env, fetches definitions, and writes to node_modules
- hashSdkKey() helper for SHA-256 hashing
- generateDefinitionsModule() for JS module generation with deduplication and lazy parsing
Follows repo conventions: pnpm workspaces, tsup, vitest, ES modules with CJS fallback.
* Add JSDoc comments from original CLI source
* Add inline comments from original CLI source
* Add optional output parameter with debug logging
* Add output.time for datafile fetching
* Add changeset for @vercel/prepare-flags-definitions
* Added new comparators: (not_)contains and case-insensitive versions
* Switched to "ci" option instead of creating new condition for every ci-case
* Cleanup
* More cleanup
* Some more cleanup & finetuning
Made-with: Cursor
* Changeset
* Switch options key to just "i" and also allow for passing "i" as string instead of options object
* Apply suggestions from code review
* Update packages/vercel-flags-core/src/evaluate.ts
Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com>
* naming
* Renaming
---------
Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com>
* Add CJS support for @vercel/flags-core
Update tsup config to build both ESM and CJS formats, and update package.json exports to use import/require conditions with separate entry points for CommonJS consumers.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
* changeset
---------
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
* add primed stream message support
Implements client-side support for version-based caching. When the client
already has the current datafile (indicated by revision), the server can
send a lightweight primed message instead of the full datafile, reducing
bandwidth. Tracks revision from datafile and sends X-Revision header on
reconnections.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
* use getRevision getter for single source of truth and fix type errors
Refactors StreamConfig.revision to a getRevision getter function so
connectStream always reads the latest revision from client state instead
of tracking a separate copy. Fixes CI type-check errors in tests.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
When shutdown() is called on a client using FlagNetworkDataSource, the stream abort error is expected and should not be logged. The break statement still exits the loop properly.
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
* Add custom fetch option to flags client
Allow passing a custom fetch function to createClient() for testing purposes (e.g. resolving to a different IP). Threads fetch through FlagNetworkDataSource, fetchDatafile(), and connectStream().
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
* changeset
---------
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>