| 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 { Detector } from "./Detector.ts"; |
| 5 | |
| 6 | /** |
| 7 | * The `detectorId` is injected by the binding from the bound detector; the |
| 8 | * caller supplies the event id, event type, detector version, and the |
| 9 | * prediction timestamp (as returned by `ListEventPredictions`). |
| 10 | */ |
| 11 | export interface GetEventPredictionMetadataRequest extends Omit< |
| 12 | frauddetector.GetEventPredictionMetadataRequest, |
| 13 | "detectorId" |
| 14 | > {} |
| 15 | |
| 16 | /** |
| 17 | * Read the full evaluation details of a past prediction made by a bound |
| 18 | * Amazon Fraud Detector detector — the variables, rule evaluations, and model |
| 19 | * scores recorded for the prediction — the effectful audit call made from a |
| 20 | * deployed Lambda or Task. |
| 21 | * |
| 22 | * ### Auditing Predictions |
| 23 | * Provide the `GetEventPredictionMetadataHttp` implementation layer on the |
| 24 | * Function effect, bind the detector in the init phase, then call the |
| 25 | * returned client at runtime. The binding grants |
| 26 | * `frauddetector:GetEventPredictionMetadata` on the detector and injects its |
| 27 | * `detectorId` automatically. Find `predictionTimestamp` values via the |
| 28 | * `ListEventPredictions` binding. |
| 29 | * |
| 30 | * **Example:** Audit from a Lambda |
| 31 | * ```typescript |
| 32 | * // init |
| 33 | * const getPredictionMetadata = |
| 34 | * yield* FraudDetector.GetEventPredictionMetadata(detector); |
| 35 | * |
| 36 | * return { |
| 37 | * fetch: Effect.gen(function* () { |
| 38 | * // runtime |
| 39 | * const metadata = yield* getPredictionMetadata({ |
| 40 | * eventId: "order-123", |
| 41 | * eventTypeName: "purchase", |
| 42 | * detectorVersionId: "1", |
| 43 | * predictionTimestamp: "2026-01-01T00:00:00Z", |
| 44 | * }); |
| 45 | * return HttpServerResponse.json({ rules: metadata.rules }); |
| 46 | * }), |
| 47 | * }; |
| 48 | * // on the Function effect: |
| 49 | * // .pipe(Effect.provide(FraudDetector.GetEventPredictionMetadataHttp)) |
| 50 | * ``` |
| 51 | * |
| 52 | * @binding |
| 53 | */ |
| 54 | export interface GetEventPredictionMetadata extends Binding.Service< |
| 55 | GetEventPredictionMetadata, |
| 56 | "AWS.FraudDetector.GetEventPredictionMetadata", |
| 57 | ( |
| 58 | detector: Detector, |
| 59 | ) => Effect.Effect< |
| 60 | ( |
| 61 | request: GetEventPredictionMetadataRequest, |
| 62 | ) => Effect.Effect< |
| 63 | frauddetector.GetEventPredictionMetadataResult, |
| 64 | frauddetector.GetEventPredictionMetadataError |
| 65 | > |
| 66 | > |
| 67 | > {} |
| 68 | export const GetEventPredictionMetadata = |
| 69 | Binding.Service<GetEventPredictionMetadata>( |
| 70 | "AWS.FraudDetector.GetEventPredictionMetadata", |
| 71 | ); |