The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as Domain from "@alchemy.run/domain"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | import { AccountId } from "../Account/Account.id.ts"; |
| 4 | import { Actor } from "../Actor.ts"; |
| 5 | import { MfaChallenge } from "../MfaChallenge.middleware.ts"; |
| 6 | import { Cents } from "../Money.ts"; |
| 7 | import { Session } from "../Session.middleware.ts"; |
| 8 | import { TransferId } from "./Transfer.id.ts"; |
| 9 | |
| 10 | /** Transfers of at least this many cents wait for a support agent's approval. */ |
| 11 | export const APPROVAL_THRESHOLD = 10_000; |
| 12 | |
| 13 | export class AlreadyRequested extends Domain.Rejection("AlreadyRequested") {} |
| 14 | |
| 15 | export class SameAccount extends Domain.Rejection("SameAccount") {} |
| 16 | |
| 17 | export class TransferRequested extends Domain.Event("TransferRequested", { |
| 18 | transferId: TransferId, |
| 19 | from: AccountId, |
| 20 | to: AccountId, |
| 21 | amount: Cents, |
| 22 | requestedBy: Actor, |
| 23 | /** At or above {@link APPROVAL_THRESHOLD}: execution waits for `ApproveTransfer`. */ |
| 24 | needsApproval: Schema.Boolean, |
| 25 | }) {} |
| 26 | |
| 27 | /** |
| 28 | * Ask to move money between two accounts; `TransferExecution` carries it out |
| 29 | * on behalf of the requester, after a support agent approves it if it is |
| 30 | * large. The client picks the transfer id, so a retry is idempotent. |
| 31 | */ |
| 32 | export class RequestTransfer extends Domain.Command("RequestTransfer", { |
| 33 | target: TransferId, |
| 34 | middleware: [Session, MfaChallenge], |
| 35 | input: { from: AccountId, to: AccountId, amount: Cents }, |
| 36 | events: [TransferRequested], |
| 37 | rejects: [AlreadyRequested, SameAccount], |
| 38 | }) {} |