@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, 06:00 UTC

main
ts 96 lines 3.5 KB
Raw
1 import type * as AVP from "@distilled.cloud/aws/verifiedpermissions";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4 import type { PolicyStore } from "./PolicyStore.ts";
5
6 export interface IsAuthorizedRequest extends Omit<AVP.IsAuthorizedInput, "policyStoreId"> {}
7 export interface IsAuthorizedWithTokenRequest extends Omit<
8 AVP.IsAuthorizedWithTokenInput,
9 "policyStoreId"
10 > {}
11 export interface BatchIsAuthorizedRequest extends Omit<
12 AVP.BatchIsAuthorizedInput,
13 "policyStoreId"
14 > {}
15 export interface BatchIsAuthorizedWithTokenRequest extends Omit<
16 AVP.BatchIsAuthorizedWithTokenInput,
17 "policyStoreId"
18 > {}
19
20 /**
21 * The runtime authorization client returned by binding `IsAuthorized` to a
22 * `PolicyStore`. Each method injects the store's `policyStoreId`
23 * automatically.
24 */
25 export interface IsAuthorizedClient {
26 /**
27 * Make a single authorization decision (`Allow` / `Deny`) for a principal,
28 * action, and resource against the store's policies.
29 */
30 isAuthorized(
31 request: IsAuthorizedRequest,
32 ): Effect.Effect<AVP.IsAuthorizedOutput, AVP.IsAuthorizedError>;
33 /**
34 * Make an authorization decision where the principal is derived from a JWT
35 * (identity or access token) issued by a configured identity source.
36 */
37 isAuthorizedWithToken(
38 request: IsAuthorizedWithTokenRequest,
39 ): Effect.Effect<AVP.IsAuthorizedWithTokenOutput, AVP.IsAuthorizedWithTokenError>;
40 /**
41 * Make up to 30 authorization decisions in one call, sharing one principal
42 * or one resource across the batch.
43 */
44 batchIsAuthorized(
45 request: BatchIsAuthorizedRequest,
46 ): Effect.Effect<AVP.BatchIsAuthorizedOutput, AVP.BatchIsAuthorizedError>;
47 /**
48 * Make up to 30 authorization decisions in one call for the principal
49 * derived from a JWT (identity or access token) issued by a configured
50 * identity source.
51 */
52 batchIsAuthorizedWithToken(
53 request: BatchIsAuthorizedWithTokenRequest,
54 ): Effect.Effect<AVP.BatchIsAuthorizedWithTokenOutput, AVP.BatchIsAuthorizedWithTokenError>;
55 }
56
57 /**
58 * Runtime binding for Verified Permissions authorization — bind it to a
59 * `PolicyStore` inside a function runtime to get a client that evaluates
60 * authorization requests against the store's Cedar policies.
61 *
62 * This is the effectful-function DX for authorization: a Lambda calls
63 * `isAuthorized(...)` and Verified Permissions returns `Allow` or `Deny`
64 * along with the determining policies.
65 * ### Authorizing Requests
66 * **Example:** Decide a Request in a Lambda
67 * ```typescript
68 * // init
69 * const authz = yield* AWS.VerifiedPermissions.IsAuthorized(store);
70 *
71 * // runtime
72 * const { decision } = yield* authz.isAuthorized({
73 * principal: { entityType: "PhotoApp::User", entityId: "alice" },
74 * action: { actionType: "PhotoApp::Action", actionId: "viewPhoto" },
75 * resource: { entityType: "PhotoApp::Photo", entityId: "vacation.jpg" },
76 * });
77 * // decision === "ALLOW" | "DENY"
78 * ```
79 *
80 * **Example:** Decide from a JWT
81 * ```typescript
82 * const { decision } = yield* authz.isAuthorizedWithToken({
83 * identityToken,
84 * action: { actionType: "PhotoApp::Action", actionId: "viewPhoto" },
85 * resource: { entityType: "PhotoApp::Photo", entityId: "vacation.jpg" },
86 * });
87 * ```
88 *
89 * @binding
90 */
91 export interface IsAuthorized extends Binding.Service<
92 IsAuthorized,
93 "AWS.VerifiedPermissions.IsAuthorized",
94 <S extends PolicyStore>(store: S) => Effect.Effect<IsAuthorizedClient>
95 > {}
96 export const IsAuthorized = Binding.Service<IsAuthorized>("AWS.VerifiedPermissions.IsAuthorized");