@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 146 lines 5.12 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3 import type { Detector } from "./Detector.ts";
4 import type { EventType } from "./EventType.ts";
5 import type { List } from "./List.ts";
6
7 /**
8 * Shared scaffolding for Amazon Fraud Detector HTTP bindings.
9 *
10 * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is
11 * a `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the two builders
12 * below. Everything except the operation and the IAM action list is
13 * boilerplate.
14 */
15
16 /**
17 * Build the impl Effect for a Fraud Detector operation scoped to a
18 * {@link Detector}: the deploy-time half grants `actions` on the bound
19 * detector's ARN, and the runtime half injects the detector's `detectorId`
20 * into every request.
21 */
22 export const makeFraudDetectorDetectorHttpBinding = <
23 I extends { detectorId: string },
24 A,
25 E,
26 R,
27 >(options: {
28 /** Fully-qualified binding tag, e.g. `AWS.FraudDetector.GetEventPrediction`. */
29 tag: string;
30 /** The distilled operation. */
31 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
32 /** IAM actions granted on the detector ARN. */
33 actions: readonly string[];
34 }) =>
35 Effect.gen(function* () {
36 const bind = yield* AWSBindings.Bind;
37 const op = yield* AWSBindings.withCredentials(options.operation);
38
39 return Effect.fn(function* (detector: Detector) {
40 // Output yields a DEFERRED effect — resolve again per invocation below.
41 const DetectorId = yield* detector.detectorId;
42 if (!globalThis.__ALCHEMY_RUNTIME__) {
43 yield* bind`${options.tag}(${detector})`({
44 policyStatements: [
45 {
46 Effect: "Allow",
47 Action: [...options.actions],
48 Resource: [detector.arn],
49 },
50 ],
51 });
52 }
53 return Effect.fn(`${options.tag}(${detector.LogicalId})`)(function* (
54 request: Omit<I, "detectorId">,
55 ) {
56 const detectorId = yield* DetectorId;
57 return yield* op({ ...request, detectorId } as I);
58 });
59 });
60 });
61
62 /**
63 * Build the impl Effect for a Fraud Detector event data-plane operation
64 * scoped to an {@link EventType} (`SendEvent`, `GetEvent`, `DeleteEvent`,
65 * `UpdateEventLabel`): the deploy-time half grants `actions` on the bound
66 * event type's ARN, and the runtime half injects the event type's
67 * `eventTypeName` into every request.
68 */
69 /**
70 * Build the impl Effect for a Fraud Detector list data-plane operation scoped
71 * to a {@link List} (`GetListElements`, `UpdateList`): the deploy-time half
72 * grants `actions` on the bound list's ARN, and the runtime half injects the
73 * list's `name` into every request.
74 */
75 export const makeFraudDetectorListHttpBinding = <I extends { name: string }, A, E, R>(options: {
76 /** Fully-qualified binding tag, e.g. `AWS.FraudDetector.GetListElements`. */
77 tag: string;
78 /** The distilled operation. */
79 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
80 /** IAM actions granted on the list ARN. */
81 actions: readonly string[];
82 }) =>
83 Effect.gen(function* () {
84 const bind = yield* AWSBindings.Bind;
85 const op = yield* AWSBindings.withCredentials(options.operation);
86
87 return Effect.fn(function* (list: List) {
88 // Output yields a DEFERRED effect — resolve again per invocation below.
89 const ListName = yield* list.name;
90 if (!globalThis.__ALCHEMY_RUNTIME__) {
91 yield* bind`${options.tag}(${list})`({
92 policyStatements: [
93 {
94 Effect: "Allow",
95 Action: [...options.actions],
96 Resource: [list.arn],
97 },
98 ],
99 });
100 }
101 return Effect.fn(`${options.tag}(${list.LogicalId})`)(function* (request: Omit<I, "name">) {
102 const name = yield* ListName;
103 return yield* op({ ...request, name } as unknown as I);
104 });
105 });
106 });
107
108 export const makeFraudDetectorEventTypeHttpBinding = <
109 I extends { eventTypeName: string },
110 A,
111 E,
112 R,
113 >(options: {
114 /** Fully-qualified binding tag, e.g. `AWS.FraudDetector.SendEvent`. */
115 tag: string;
116 /** The distilled operation. */
117 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
118 /** IAM actions granted on the event type ARN. */
119 actions: readonly string[];
120 }) =>
121 Effect.gen(function* () {
122 const bind = yield* AWSBindings.Bind;
123 const op = yield* AWSBindings.withCredentials(options.operation);
124
125 return Effect.fn(function* (eventType: EventType) {
126 // Output yields a DEFERRED effect — resolve again per invocation below.
127 const EventTypeName = yield* eventType.name;
128 if (!globalThis.__ALCHEMY_RUNTIME__) {
129 yield* bind`${options.tag}(${eventType})`({
130 policyStatements: [
131 {
132 Effect: "Allow",
133 Action: [...options.actions],
134 Resource: [eventType.arn],
135 },
136 ],
137 });
138 }
139 return Effect.fn(`${options.tag}(${eventType.LogicalId})`)(function* (
140 request: Omit<I, "eventTypeName">,
141 ) {
142 const eventTypeName = yield* EventTypeName;
143 return yield* op({ ...request, eventTypeName } as unknown as I);
144 });
145 });
146 });