@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 50 lines 1.94 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3 import type { IdMappingWorkflow } from "./IdMappingWorkflow.ts";
4 import type { MatchingWorkflow } from "./MatchingWorkflow.ts";
5
6 /**
7 * Shared scaffolding for Entity Resolution HTTP bindings.
8 *
9 * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is
10 * a `Layer.effect(Cap, makeWorkflowHttpBinding({ … }))` over the builder
11 * below. Everything except the operation and the IAM action is boilerplate:
12 * all Entity Resolution data-plane operations are scoped to a matching or ID
13 * mapping workflow and inject the bound workflow's name as the request's
14 * `workflowName` field.
15 */
16 export const makeWorkflowHttpBinding = <I extends { workflowName: string }, A, E, R>(options: {
17 /** Fully-qualified binding tag, e.g. `AWS.EntityResolution.GetMatchId`. */
18 tag: string;
19 /** The distilled operation; `workflowName` is injected from the resource. */
20 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
21 /** IAM actions granted on the workflow ARN. */
22 actions: readonly string[];
23 }) =>
24 Effect.gen(function* () {
25 const bind = yield* AWSBindings.Bind;
26 const op = yield* AWSBindings.withCredentials(options.operation);
27
28 return Effect.fn(function* (workflow: MatchingWorkflow | IdMappingWorkflow) {
29 const WorkflowName = yield* workflow.workflowName;
30 if (!globalThis.__ALCHEMY_RUNTIME__) {
31 yield* bind`${options.tag}(${workflow})`({
32 policyStatements: [
33 {
34 Effect: "Allow",
35 Action: [...options.actions],
36 Resource: [workflow.workflowArn],
37 },
38 ],
39 });
40 }
41 return Effect.fn(`${options.tag}(${workflow.LogicalId})`)(function* (
42 request: Omit<I, "workflowName">,
43 ) {
44 return yield* op({
45 ...request,
46 workflowName: yield* WorkflowName,
47 } as I);
48 });
49 });
50 });