| 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 | * only the `eventId` remains. |
| 9 | */ |
| 10 | export interface GetEventRequest extends Omit< |
| 11 | frauddetector.GetEventRequest, |
| 12 | "eventTypeName" |
| 13 | > {} |
| 14 | |
| 15 | /** |
| 16 | * Read a stored event (its entities and variable values) back from Amazon |
| 17 | * Fraud Detector — the effectful lookup call made from a deployed Lambda or |
| 18 | * Task. Events are stored by `SendEvent` or by predictions on an event type |
| 19 | * with ingestion enabled. |
| 20 | * |
| 21 | * ### Reading Stored Events |
| 22 | * Provide the `GetEventHttp` implementation layer on the Function effect, |
| 23 | * bind the event type in the init phase, then call the returned client at |
| 24 | * runtime. The binding grants `frauddetector:GetEvent` on the event type and |
| 25 | * injects its `eventTypeName` automatically. |
| 26 | * |
| 27 | * **Example:** Read from a Lambda |
| 28 | * ```typescript |
| 29 | * // init |
| 30 | * const getEvent = yield* FraudDetector.GetEvent(eventType); |
| 31 | * |
| 32 | * return { |
| 33 | * fetch: Effect.gen(function* () { |
| 34 | * // runtime |
| 35 | * const { event } = yield* getEvent({ eventId: "order-123" }); |
| 36 | * return HttpServerResponse.json({ variables: event?.eventVariables }); |
| 37 | * }), |
| 38 | * }; |
| 39 | * // on the Function effect: |
| 40 | * // .pipe(Effect.provide(FraudDetector.GetEventHttp)) |
| 41 | * ``` |
| 42 | * |
| 43 | * @binding |
| 44 | */ |
| 45 | export interface GetEvent extends Binding.Service< |
| 46 | GetEvent, |
| 47 | "AWS.FraudDetector.GetEvent", |
| 48 | ( |
| 49 | eventType: EventType, |
| 50 | ) => Effect.Effect< |
| 51 | ( |
| 52 | request: GetEventRequest, |
| 53 | ) => Effect.Effect< |
| 54 | frauddetector.GetEventResult, |
| 55 | frauddetector.GetEventError |
| 56 | > |
| 57 | > |
| 58 | > {} |
| 59 | export const GetEvent = Binding.Service<GetEvent>("AWS.FraudDetector.GetEvent"); |