From ed5b88058d8f8c9c0a85e630cfbff70d136cfb33 Mon Sep 17 00:00:00 2001 From: Dominik Ferber Date: Tue, 25 Mar 2025 04:49:42 -0700 Subject: [PATCH 1/4] embed clientInitializeResponse and statsigUser --- .../app/api/bootstrap/route.ts | 29 --------- .../experimentation-statsig/app/layout.tsx | 7 +++ .../experimentation-statsig/middleware.ts | 52 ++++++++++++---- .../experimentation-statsig/package.json | 1 + .../experimentation-statsig/pnpm-lock.yaml | 8 +++ .../statsig/statsig-provider.tsx | 60 +++++++++++-------- 6 files changed, 94 insertions(+), 63 deletions(-) delete mode 100644 flags-sdk/experimentation-statsig/app/api/bootstrap/route.ts diff --git a/flags-sdk/experimentation-statsig/app/api/bootstrap/route.ts b/flags-sdk/experimentation-statsig/app/api/bootstrap/route.ts deleted file mode 100644 index 238c3fea9..000000000 --- a/flags-sdk/experimentation-statsig/app/api/bootstrap/route.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { getStableId } from "@/utils/get-stable-id"; -import { statsigAdapter, Statsig, type StatsigUser } from "@flags-sdk/statsig"; -import { NextResponse } from "next/server"; - -export const runtime = "edge"; - -export async function GET(request: Request): Promise { - await statsigAdapter.initialize(); - const stableId = await getStableId(); - - const user: StatsigUser = { - customIDs: { - // since we're not having authentication, we're using the stable id for targeting - // otherwise, you can define a userID at the root of the user object - stableID: stableId.value, - }, - }; - - const values = await Statsig.getClientInitializeResponse(user, { - hash: "djb2", - }); - - return NextResponse.json(values, { - headers: { - "Cache-Control": "private, max-age=60", - Vary: "Cookie", - }, - }); -} \ No newline at end of file diff --git a/flags-sdk/experimentation-statsig/app/layout.tsx b/flags-sdk/experimentation-statsig/app/layout.tsx index 0850a3820..d94e45af9 100644 --- a/flags-sdk/experimentation-statsig/app/layout.tsx +++ b/flags-sdk/experimentation-statsig/app/layout.tsx @@ -22,6 +22,13 @@ export default function RootLayout({ {children} +