@flags-sdk/growthbook: support stringified json (#210)

closes #209
This commit is contained in:
Dominik Ferber
2025-11-06 14:45:49 +02:00
committed by GitHub
parent df76e2c641
commit d43589a0f5
2 changed files with 22 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@flags-sdk/growthbook": patch
---
support strings in Edge Config
+17 -1
View File
@@ -75,7 +75,7 @@ export function createGrowthbookAdapter(options: {
let _initializePromise: Promise<void> | undefined;
const initializeGrowthBook = async (): Promise<void> => {
let payload: FeatureApiResponse | undefined;
let payload: FeatureApiResponse | string | undefined;
if (options.edgeConfig) {
try {
const edgeConfigClient = createClient(
@@ -92,6 +92,22 @@ export function createGrowthbookAdapter(options: {
}
}
// Older GrowthBook integrations use WebHooks directly to store
// data in Edge Config, but they store the data as a string.
//
// We need to parse the string to JSON before passing it to GrowthBook.
//
// https://docs.growthbook.io/app/webhooks/sdk-webhooks#vercel-edge-config
// https://github.com/vercel/flags/issues/209
if (typeof payload === 'string') {
try {
payload = JSON.parse(payload) as FeatureApiResponse;
} catch {
console.error('Invalid payload format');
payload = undefined;
}
}
await growthbook.init({
streaming: false,
payload,