1import type { AsyncWorkerEnv } from "./stack.ts";
2
3/**
4 * Async (non-Effect) Worker fixture for the Cloudflare Flagship binding
5 * declared via `env: { FLAGS: App }` with a `FlagshipApp` resource. `InferEnv`
6 * maps the resource to the native `Flagship` runtime binding, so the handler
7 * calls `env.FLAGS.getBooleanValue(...)` directly.
8 */
9export default {
10 async fetch(request: Request, env: AsyncWorkerEnv): Promise<Response> {
11 const url = new URL(request.url);
12
13 if (url.pathname.startsWith("/bool")) {
14 const enabled = await env.FLAGS.getBooleanValue("test-flag", false, {
15 userId: "user-42",
16 });
17 return Response.json({ mode: "async", enabled });
18 }
19
20 if (url.pathname.startsWith("/details")) {
21 const details = await env.FLAGS.getStringDetails(
22 "nonexistent-flag",
23 "fallback",
24 { userId: "user-42" },
25 );
26 return Response.json({ mode: "async", details });
27 }
28
29 return new Response("ok");
30 },
31};