import type { JsonObject } from "@decionis/agent-safe-pipeline"; export type HardLimitCode = "HARD_LIMIT_EXCEEDED" | "HARD_LIMIT_CURRENCY_UNKNOWN" | "HARD_LIMIT_AMOUNT_INVALID" | "HARD_LIMIT_WINDOW_COUNT_EXCEEDED" | "HARD_LIMIT_WINDOW_SUM_EXCEEDED"; export interface HardLimitSettings { /** The most one action may move, per ISO 4217 code, in minor units. */ readonly singleMinor: ReadonlyMap; readonly windowSeconds: number; readonly windowCount: number | null; readonly windowSumMinor: bigint | null; } /** What the limits read off an action: an amount in minor units and its currency. */ export interface MonetaryValue { readonly currency: string; readonly amountMinor: bigint; } export type LimitCheck = { readonly allowed: true; } | { readonly allowed: false; readonly code: HardLimitCode; }; export declare class HardLimits { readonly settings: HardLimitSettings; private readonly clock; /** * One window, in the order the actions happened: when each was committed, * and what it moved when it moved anything. The count and the sum are both * derived from it, so there is no second list to keep in step. */ private readonly window; constructor(settings: HardLimitSettings, clock: () => number); /** `CHF:2500000000,EUR:1000000`: the ceiling per currency, in minor units. */ static parseCeilings(text: string, key: string): ReadonlyMap; /** * The monetary value an action carries, when it carries one: an integer * `amountMinor` and a three-letter `currency` among the intent's * parameters. An action with neither is not a payment and is bounded by * the count window alone; an action with one and not the other is refused, * because a half-stated amount is not something to guess at. */ static monetaryValue(parameters: JsonObject): MonetaryValue | null | "INVALID"; /** Whether this action is inside every ceiling right now; it takes nothing. */ check(parameters: JsonObject): LimitCheck; /** * The decision and the value it was made about, together, so `commit` does * not read the parameters a second time and an invalid amount never * escapes this method: it is a refusal here, and what leaves is either a * value or nothing. */ private evaluate; private within; /** Takes this action's place in the windows, after the check and before it runs. */ commit(parameters: JsonObject): LimitCheck; /** * The window, pruned. Entries are pushed in the order the clock gave them, * so the old ones are at the front and dropping them is a walk from there * rather than a pass over the whole list. A clock that went backwards * stops the walk early and keeps an entry a moment longer, which refuses * more rather than less. */ private recent; private recentSum; } //# sourceMappingURL=HardLimits.d.ts.map