1import type * as frauddetector from "@distilled.cloud/aws/frauddetector";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Detector } from "./Detector.ts";
5
6/**
7 * The `detectorId` is injected by the binding from the bound detector;
8 * everything else (the event id, timestamp, entities, and variable values) is
9 * the raw distilled request. Pin `detectorVersionId` to evaluate a specific
10 * version; omit it to use the detector's `ACTIVE` version.
11 */
12export interface GetEventPredictionRequest extends Omit<
13 frauddetector.GetEventPredictionRequest,
14 "detectorId"
15> {}
16
17/**
18 * Submit an event to a bound Amazon Fraud Detector detector and receive the
19 * real-time model scores and rule outcomes for it — the effectful prediction
20 * call made from a deployed Lambda or Task.
21 *
22 * ### Scoring Events
23 * Provide the `GetEventPredictionHttp` implementation layer on the Function
24 * effect, bind the detector in the init phase, then call the returned client
25 * at runtime. The binding grants `frauddetector:GetEventPrediction` on the
26 * detector and injects its `detectorId` automatically.
27 *
28 * **Example:** Predict from a Lambda
29 * ```typescript
30 * // init
31 * const getEventPrediction = yield* FraudDetector.GetEventPrediction(detector);
32 *
33 * return {
34 * fetch: Effect.gen(function* () {
35 * // runtime
36 * const { ruleResults } = yield* getEventPrediction({
37 * eventId: "order-123",
38 * eventTypeName: "purchase",
39 * eventTimestamp: new Date().toISOString(),
40 * entities: [{ entityType: "customer", entityId: "cust-1" }],
41 * eventVariables: { email: "fraud@example.com", ip: "1.2.3.4" },
42 * });
43 * const outcomes = ruleResults?.flatMap((r) => r.outcomes ?? []);
44 * return HttpServerResponse.json({ outcomes });
45 * }),
46 * };
47 * // on the Function effect:
48 * // .pipe(Effect.provide(FraudDetector.GetEventPredictionHttp))
49 * ```
50 *
51 * @binding
52 */
53export interface GetEventPrediction extends Binding.Service<
54 GetEventPrediction,
55 "AWS.FraudDetector.GetEventPrediction",
56 (
57 detector: Detector,
58 ) => Effect.Effect<
59 (
60 request: GetEventPredictionRequest,
61 ) => Effect.Effect<
62 frauddetector.GetEventPredictionResult,
63 frauddetector.GetEventPredictionError
64 >
65 >
66> {}
67export const GetEventPrediction = Binding.Service<GetEventPrediction>(
68 "AWS.FraudDetector.GetEventPrediction",
69);