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

main
ts 44 lines 1.56 KB
Raw
1 import * as AVP from "@distilled.cloud/aws/verifiedpermissions";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as AWSBindings from "../AWSBindings.ts";
5 import { GetPolicies, type GetPoliciesRequest } from "./GetPolicies.ts";
6 import type { PolicyStore } from "./PolicyStore.ts";
7
8 export const GetPoliciesHttp = Layer.effect(
9 GetPolicies,
10 Effect.gen(function* () {
11 const bind = yield* AWSBindings.Bind;
12 const batchGetPolicy = yield* AWSBindings.withCredentials(AVP.batchGetPolicy);
13
14 return Effect.fn(function* <S extends PolicyStore>(store: S) {
15 const PolicyStoreId = yield* store.policyStoreId;
16 if (!globalThis.__ALCHEMY_RUNTIME__) {
17 yield* bind`AWS.VerifiedPermissions.GetPolicies(${store})`({
18 policyStatements: [
19 {
20 Effect: "Allow",
21 // BatchGetPolicy authorizes under verifiedpermissions:GetPolicy
22 Action: ["verifiedpermissions:GetPolicy", "verifiedpermissions:BatchGetPolicy"],
23 Resource: [store.policyStoreArn],
24 },
25 ],
26 });
27 }
28 const label = store.LogicalId;
29 return {
30 batchGetPolicy: Effect.fn(`AWS.VerifiedPermissions.BatchGetPolicy(${label})`)(function* (
31 request: GetPoliciesRequest,
32 ) {
33 const policyStoreId = yield* PolicyStoreId;
34 return yield* batchGetPolicy({
35 requests: request.policyIds.map((policyId) => ({
36 policyStoreId,
37 policyId,
38 })),
39 });
40 }),
41 };
42 });
43 }),
44 );