@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

main
ts 32 lines 1.15 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Config from "effect/Config";
3 import * as Effect from "effect/Effect";
4 import * as HttpServerResponse from "effect/http/HttpServerResponse";
5
6 /**
7 * Binds {@link Cloudflare.Access.GetIdentityProvider} so the deployed Worker
8 * can look up an Access IdP at runtime through the scoped token the binding
9 * mints and attaches.
10 */
11 export default class IdpLookupWorker extends Cloudflare.Worker<IdpLookupWorker>()(
12 "IdpLookupWorker",
13 {
14 main: import.meta.url,
15 },
16 Effect.gen(function* () {
17 // The test's stage-derived IdP name, read at deploy time and bound into
18 // the Worker as a plain-text variable.
19 const name = yield* Config.String("IDP_LOOKUP_NAME");
20 const findIdp = yield* Cloudflare.Access.GetIdentityProvider({ name });
21
22 return {
23 fetch: Effect.gen(function* () {
24 const idp = yield* findIdp().pipe(Effect.orDie);
25 return yield* HttpServerResponse.json({
26 identityProviderId: idp?.identityProviderId ?? null,
27 type: idp?.type ?? null,
28 });
29 }),
30 };
31 }).pipe(Effect.provide(Cloudflare.Access.GetIdentityProviderHttp)),
32 ) {}