The best way to control Claude Code, Codex and more from any computer or phone

main
ts 33 lines 1.25 KB
Raw
1 import * as Domain from "@alchemy.run/domain";
2 import { MfaChallenge } from "../MfaChallenge.middleware.ts";
3 import { Cents } from "../Money.ts";
4 import { Session } from "../Session.middleware.ts";
5 import { AccountId } from "./Account.id.ts";
6 import { Frozen } from "./Frozen.rejection.ts";
7 import { InsufficientFunds } from "./InsufficientFunds.rejection.ts";
8 import { NotOpen } from "./NotOpen.rejection.ts";
9 import { NotOwner } from "./NotOwner.rejection.ts";
10
11 /** Daily withdrawal limit, in cents. */
12 export const DAILY_LIMIT = 100_000;
13
14 export class DailyLimitExceeded extends Domain.Rejection("DailyLimitExceeded", {
15 remaining: Cents,
16 }) {}
17
18 export class MoneyWithdrawn extends Domain.Event("MoneyWithdrawn", {
19 amount: Cents,
20 balanceAfter: Cents,
21 }) {}
22
23 /** Take money out of an account, within the balance and the daily limit. */
24 export class WithdrawMoney extends Domain.Command("WithdrawMoney", {
25 target: AccountId,
26 middleware: [Session, MfaChallenge],
27 input: { amount: Cents },
28 events: [MoneyWithdrawn],
29 rejects: [NotOpen, NotOwner, Frozen, InsufficientFunds, DailyLimitExceeded],
30 reply: { balance: Cents },
31 // Recorded on every span the withdrawal passes through; nothing else from it is.
32 attributes: (cmd) => ({ "bank.amount": cmd.amount }),
33 }) {}