@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 38 lines 1.43 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as Layer from "effect/Layer";
3 import { authorizeWith } from "../HttpClientUtils.ts";
4 import { makeHttpBucketBinding, type R2Auth } from "./BucketHttp.ts";
5 import { makeReadR2HttpClient } from "./ReadBucketHttp.ts";
6 import { ReadWriteBucket, type ReadWriteBucketClient } from "./ReadWriteBucket.ts";
7 import { makeWriteR2HttpClient } from "./WriteBucketHttp.ts";
8
9 /**
10 * HTTP-backed implementation of the {@link ReadWriteBucket} binding.
11 *
12 * It creates a scoped {@link AccountApiToken} with the `Workers R2 Storage Read` and `Workers R2 Storage Write` permissions.
13 */
14 export const ReadWriteBucketHttp = Layer.effect(
15 ReadWriteBucket,
16 Effect.suspend(() =>
17 makeHttpBucketBinding({
18 permissionGroups: ["Workers R2 Storage Read", "Workers R2 Storage Write"],
19 makeClient: (token, bucketName, jurisdiction) =>
20 makeReadWriteR2HttpClient(
21 { authorize: authorizeWith(token), accountId: token.accountId },
22 bucketName,
23 jurisdiction,
24 ),
25 }),
26 ),
27 );
28
29 /** Build the HTTP-backed {@link ReadWrite} over a bound token + bucket. */
30 export const makeReadWriteR2HttpClient = (
31 auth: R2Auth,
32 bucketName: Effect.Effect<string>,
33 jurisdiction: Effect.Effect<string>,
34 ): ReadWriteBucketClient =>
35 ({
36 ...makeReadR2HttpClient(auth, bucketName, jurisdiction),
37 ...makeWriteR2HttpClient(auth, bucketName, jurisdiction),
38 }) satisfies ReadWriteBucketClient;