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