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

main
ts 90 lines 3.44 KB
Raw
1 /**
2 * Raw (non-distilled) HTTP helpers against the floci emulator gateway —
3 * out-of-band proof that a resource exists IN THE EMULATOR, not the real
4 * cloud. The dummy SigV4 Authorization header is never verified by the
5 * emulator; it only carries the service/region/account scoping the gateway
6 * routes by.
7 */
8 import * as Effect from "effect/Effect";
9 import * as HttpBody from "effect/http/HttpBody";
10 import * as HttpClient from "effect/http/HttpClient";
11 import * as HttpClientRequest from "effect/http/HttpClientRequest";
12
13 export const FLOCI_ENDPOINT = "http://localhost:4566";
14
15 /** POST an AWS-JSON operation straight at the emulator gateway. */
16 export const rawAwsJson = Effect.fn(function* (options: {
17 service: string;
18 region: string;
19 target: string;
20 contentType: string;
21 body: Record<string, unknown>;
22 }) {
23 const client = yield* HttpClient.HttpClient;
24 return yield* client.execute(
25 HttpClientRequest.post(`${FLOCI_ENDPOINT}/`).pipe(
26 HttpClientRequest.setHeaders({
27 "content-type": options.contentType,
28 "x-amz-target": options.target,
29 "x-amz-date": "20260101T000000Z",
30 authorization: `AWS4-HMAC-SHA256 Credential=test/20260101/${options.region}/${options.service}/aws4_request, SignedHeaders=host;x-amz-date, Signature=dummy`,
31 }),
32 HttpClientRequest.setBody(HttpBody.text(JSON.stringify(options.body), options.contentType)),
33 ),
34 );
35 });
36
37 /** POST an AWS query-protocol operation (SNS, …) straight at the gateway. */
38 export const rawAwsQuery = Effect.fn(function* (options: {
39 service: string;
40 region: string;
41 params: Record<string, string>;
42 }) {
43 const client = yield* HttpClient.HttpClient;
44 return yield* client.execute(
45 HttpClientRequest.post(`${FLOCI_ENDPOINT}/`).pipe(
46 HttpClientRequest.setHeaders({
47 "content-type": "application/x-www-form-urlencoded",
48 "x-amz-date": "20260101T000000Z",
49 authorization: `AWS4-HMAC-SHA256 Credential=test/20260101/${options.region}/${options.service}/aws4_request, SignedHeaders=host;x-amz-date, Signature=dummy`,
50 }),
51 HttpClientRequest.setBody(
52 HttpBody.text(
53 new URLSearchParams(options.params).toString(),
54 "application/x-www-form-urlencoded",
55 ),
56 ),
57 ),
58 );
59 });
60
61 /** Path-style S3 GET against the gateway (list the bucket's objects). */
62 export const rawS3GetBucket = Effect.fn(function* (bucketName: string) {
63 const client = yield* HttpClient.HttpClient;
64 return yield* client.execute(
65 HttpClientRequest.get(`${FLOCI_ENDPOINT}/${bucketName}`).pipe(
66 HttpClientRequest.setHeaders({
67 "x-amz-date": "20260101T000000Z",
68 authorization:
69 "AWS4-HMAC-SHA256 Credential=test/20260101/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-date, Signature=dummy",
70 }),
71 ),
72 );
73 });
74
75 /** Path-style S3 object GET against the gateway. */
76 export const rawS3GetObject = Effect.fn(function* (bucketName: string, key: string) {
77 const client = yield* HttpClient.HttpClient;
78 return yield* client.execute(
79 HttpClientRequest.get(`${FLOCI_ENDPOINT}/${bucketName}/${key}`).pipe(
80 HttpClientRequest.setHeaders({
81 "x-amz-date": "20260101T000000Z",
82 authorization:
83 "AWS4-HMAC-SHA256 Credential=test/20260101/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-date, Signature=dummy",
84 }),
85 ),
86 );
87 });
88
89 /** Region segment of an ARN (`arn:aws:sqs:REGION:ACCOUNT:name`). */
90 export const regionOfArn = (arn: string) => arn.split(":")[3]!;