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

main
ts 60 lines 2.12 KB
Raw
1 import type * as frauddetector from "@distilled.cloud/aws/frauddetector";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4 import type { EventType } from "./EventType.ts";
5
6 /**
7 * The `eventTypeName` is injected by the binding from the bound event type;
8 * everything else (the event id, timestamp, entities, variable values, and
9 * optional label) is the raw distilled request.
10 */
11 export interface SendEventRequest extends Omit<frauddetector.SendEventRequest, "eventTypeName"> {}
12
13 /**
14 * Store an event in Amazon Fraud Detector without generating a prediction —
15 * the effectful ingestion call made from a deployed Lambda or Task. Stored
16 * events build the historical dataset used to train models and can be
17 * labeled later via `UpdateEventLabel`. The bound event type must have
18 * `eventIngestion: "ENABLED"`.
19 *
20 * ### Ingesting Events
21 * Provide the `SendEventHttp` implementation layer on the Function effect,
22 * bind the event type in the init phase, then call the returned client at
23 * runtime. The binding grants `frauddetector:SendEvent` on the event type
24 * and injects its `eventTypeName` automatically.
25 *
26 * **Example:** Ingest from a Lambda
27 * ```typescript
28 * // init
29 * const sendEvent = yield* FraudDetector.SendEvent(eventType);
30 *
31 * return {
32 * fetch: Effect.gen(function* () {
33 * // runtime
34 * yield* sendEvent({
35 * eventId: "order-123",
36 * eventTimestamp: new Date().toISOString(),
37 * entities: [{ entityType: "customer", entityId: "cust-1" }],
38 * eventVariables: { email: "buyer@example.com", ip: "1.2.3.4" },
39 * });
40 * return HttpServerResponse.json({ ok: true });
41 * }),
42 * };
43 * // on the Function effect:
44 * // .pipe(Effect.provide(FraudDetector.SendEventHttp))
45 * ```
46 *
47 * @binding
48 */
49 export interface SendEvent extends Binding.Service<
50 SendEvent,
51 "AWS.FraudDetector.SendEvent",
52 (
53 eventType: EventType,
54 ) => Effect.Effect<
55 (
56 request: SendEventRequest,
57 ) => Effect.Effect<frauddetector.SendEventResult, frauddetector.SendEventError>
58 >
59 > {}
60 export const SendEvent = Binding.Service<SendEvent>("AWS.FraudDetector.SendEvent");