@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, 04:45 UTC

main
ts 61 lines 2.39 KB
Raw
1 import * as ci from "@distilled.cloud/aws/cognito-identity";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as AWSBindings from "../AWSBindings.ts";
5 import { cognitoMethods } from "./BindingHttp.ts";
6 import type { IdentityPool } from "./IdentityPool.ts";
7 import {
8 IdentityPoolAuth,
9 type GetIdRequest,
10 type IdentityPoolAuthClient,
11 } from "./IdentityPoolAuth.ts";
12
13 /**
14 * HTTP implementation of {@link IdentityPoolAuth}. The credentials-vending
15 * flows are unauthenticated (Cognito does not evaluate IAM for them), so the
16 * deploy-time half only records the binding — no policy statements are
17 * attached.
18 */
19 export const IdentityPoolAuthHttp = Layer.effect(
20 IdentityPoolAuth,
21 Effect.gen(function* () {
22 const bind = yield* AWSBindings.Bind;
23 const getId = yield* AWSBindings.withCredentials(ci.getId);
24 const getCredentialsForIdentity = yield* AWSBindings.withCredentials(
25 ci.getCredentialsForIdentity,
26 );
27 const getOpenIdToken = yield* AWSBindings.withCredentials(ci.getOpenIdToken);
28 const unlinkIdentity = yield* AWSBindings.withCredentials(ci.unlinkIdentity);
29
30 return Effect.fn(function* <P extends IdentityPool>(pool: P) {
31 const IdentityPoolId = yield* pool.identityPoolId;
32 if (!globalThis.__ALCHEMY_RUNTIME__) {
33 // No IAM is required for the public identity flows; the binding is
34 // recorded so the identity pool deploys before the function.
35 yield* bind`AWS.Cognito.IdentityPoolAuth(${pool})`({
36 policyStatements: [],
37 });
38 }
39 const methods = cognitoMethods("AWS.Cognito.IdentityPoolAuth", pool.LogicalId);
40 const authClient: IdentityPoolAuthClient = {
41 // optional-request operation stays bespoke (the helper's wrapped
42 // methods take a required request object)
43 getId: Effect.fn(`AWS.Cognito.IdentityPoolAuth.getId(${pool.LogicalId})`)(function* (
44 request: GetIdRequest = {},
45 ) {
46 return yield* getId({
47 ...request,
48 IdentityPoolId: yield* IdentityPoolId,
49 });
50 }),
51 getCredentialsForIdentity: methods.plain(
52 "getCredentialsForIdentity",
53 getCredentialsForIdentity,
54 ),
55 getOpenIdToken: methods.plain("getOpenIdToken", getOpenIdToken),
56 unlinkIdentity: methods.plain("unlinkIdentity", unlinkIdentity),
57 };
58 return authClient;
59 });
60 }),
61 );