| 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 | * the `eventId`, `assignedLabel`, and `labelTimestamp` remain. The label must |
| 9 | * be one of the labels associated with the event type. |
| 10 | */ |
| 11 | export interface UpdateEventLabelRequest extends Omit< |
| 12 | frauddetector.UpdateEventLabelRequest, |
| 13 | "eventTypeName" |
| 14 | > {} |
| 15 | |
| 16 | /** |
| 17 | * Label a stored event in Amazon Fraud Detector — the effectful feedback |
| 18 | * call made from a deployed Lambda or Task when ground truth arrives (e.g. a |
| 19 | * chargeback confirms fraud). Labeled events improve future model training. |
| 20 | * |
| 21 | * ### Labeling Stored Events |
| 22 | * Provide the `UpdateEventLabelHttp` implementation layer on the Function |
| 23 | * effect, bind the event type in the init phase, then call the returned |
| 24 | * client at runtime. The binding grants `frauddetector:UpdateEventLabel` on |
| 25 | * the event type and injects its `eventTypeName` automatically. |
| 26 | * |
| 27 | * **Example:** Label from a Lambda |
| 28 | * ```typescript |
| 29 | * // init |
| 30 | * const updateEventLabel = yield* FraudDetector.UpdateEventLabel(eventType); |
| 31 | * |
| 32 | * return { |
| 33 | * fetch: Effect.gen(function* () { |
| 34 | * // runtime — a chargeback arrived for this order |
| 35 | * yield* updateEventLabel({ |
| 36 | * eventId: "order-123", |
| 37 | * assignedLabel: "fraud", |
| 38 | * labelTimestamp: new Date().toISOString(), |
| 39 | * }); |
| 40 | * return HttpServerResponse.json({ ok: true }); |
| 41 | * }), |
| 42 | * }; |
| 43 | * // on the Function effect: |
| 44 | * // .pipe(Effect.provide(FraudDetector.UpdateEventLabelHttp)) |
| 45 | * ``` |
| 46 | * |
| 47 | * @binding |
| 48 | */ |
| 49 | export interface UpdateEventLabel extends Binding.Service< |
| 50 | UpdateEventLabel, |
| 51 | "AWS.FraudDetector.UpdateEventLabel", |
| 52 | ( |
| 53 | eventType: EventType, |
| 54 | ) => Effect.Effect< |
| 55 | ( |
| 56 | request: UpdateEventLabelRequest, |
| 57 | ) => Effect.Effect< |
| 58 | frauddetector.UpdateEventLabelResult, |
| 59 | frauddetector.UpdateEventLabelError |
| 60 | > |
| 61 | > |
| 62 | > {} |
| 63 | export const UpdateEventLabel = Binding.Service<UpdateEventLabel>( |
| 64 | "AWS.FraudDetector.UpdateEventLabel", |
| 65 | ); |