Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687import * as Effect from "effect/Effect";export { InstallationWorkflow } from "../../control-plane/installation-workflow.ts";// Explicit test-only storage/RPC inspection. Never part of a production entry.import oauth, { network } from "./oauth-worker.ts";export { AuthVault } from "./oauth-worker.ts";import { InstallationRegistry as ProductionRegistry } from "../../control-plane/installation-registry.ts";import { installationRegistryStub as installationRegistry } from "../../control-plane/registry-client.ts";import { handleInstallations } from "../../control-plane/installations.ts";import { authenticatedPrincipal } from "../../control-plane/session.ts";import type { Env } from "../../control-plane/config.ts";import type { InstallationChanges } from "../../control-plane/installation-metadata.ts";
export class InstallationRegistry extends ProductionRegistry { async fixtureInspect() { return Object.fromEntries(await this.ctx.storage.list()); } async fixturePut(id: string, value: unknown) { await this.ctx.storage.put(`installation:${id}`, value); }}const calls: string[] = [];export default { async fetch(request, env, ctx) { const path = new URL(request.url).pathname; if (path.startsWith("/__test__/metadata/")) { const principal = await Effect.runPromise( authenticatedPrincipal(request, env), ); const body = request.method === "POST" ? ((await request.json()) as Record<string, unknown>) : {}; const subject = principal.subject; const stub = installationRegistry( env, subject, ) as unknown as DurableObjectStub<InstallationRegistry>; if (path.endsWith("/inspect")) return Response.json(await stub.fixtureInspect()); if (path.endsWith("/put")) { await stub.fixturePut(body.id as string, body.value); return Response.json({ ok: true }); } if (path.endsWith("/update")) return Response.json( await stub.update( subject, body.id as string, body.revision as number, body.changes as InstallationChanges, ), ); if (path.endsWith("/wrong-owner")) return Response.json( await stub.get(body.subject as string, body.id as string), ); if (path.endsWith("/private-rpc")) { try { await ( stub as unknown as { owner(subject: string): Promise<void> } ).owner(subject); return Response.json({ exposed: true }); } catch { return Response.json({ exposed: false }); } } if (path.endsWith("/network")) return Response.json(calls); return new Response(null, { status: 404 }); } return ( (await Effect.runPromise( handleInstallations(request, env, async (input, init) => { const url = new URL( typeof input === "string" ? input : input instanceof URL ? input.href : input.url, ); calls.push(url.origin + url.pathname); return network(input, init); }), )) ?? oauth.fetch(request, env, ctx) ); },} satisfies ExportedHandler<Env>;