/** * The fake Google as a Worker of its own (src/fake_google/fake.ts), deployed to dev alone * (`npx wrangler deploy -c wrangler.fake-google.jsonc`): one Durable Object holds every invented account, grant and * event, so the dev business Worker's calls (GOOGLE_BASE) and a proof's admin calls see one Google. Never live. */import { DurableObject } from"cloudflare:workers";import { empty, FakeGoogle, typeClient, typeState } from"./fake.ts";interfaceEnv { FAKE_GOOGLE: DurableObjectNamespace<FakeGoogleState>;/** The OAuth clients this Google knows, JSON: { "<client id>": { "secret": "…", "redirects": ["https://…/v1/google/callback"] } }. */ FAKE_GOOGLE_CLIENTS: string;/** The token a proof sends to /fake/admin/* (Google Calendar's own web page, in effect). */ FAKE_GOOGLE_ADMIN?: string;}exportclassFakeGoogleStateextendsDurableObject<Env> {async fetch(request: Request): Promise<Response> {const state = ((awaitthis.ctx.storage.get<State>("state")) ?? empty()) asState;const clients = JSON.parse(this.env.FAKE_GOOGLE_CLIENTS || "{}") asRecord<string, Client>;const random = () => {const bytes = crypto.getRandomValues(newUint8Array(24));return btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); };const fake = newFakeGoogle(state, clients, () => Date.now(), random, this.env.FAKE_GOOGLE_ADMIN ?? null);const answer = await fake.handle(request);awaitthis.ctx.storage.put("state", fake.state);return answer; }}exportdefault {async fetch(request: Request, env: Env): Promise<Response> {return env.FAKE_GOOGLE.get(env.FAKE_GOOGLE.idFromName("google")).fetch(request); },} satisfiesExportedHandler<Env>;