@suluk/cost - v0.2.0
    Preparing search index...

    Interface CostModel

    @suluk/cost — cost as a contract facet + runtime metering. You can't price a user without knowing what they cost you. So: declare per-operation cost (incl. third-party usage) on the contract — it bubbles into the v4 doc, Scalar, and the audit; meter the ACTUAL cost per request at runtime, traced from the frontend action down to each third party; and read the raw per-user picture from the ledger. We display the data as it is and let you build pricing on top (Stripe via @suluk/stripe). CANDIDATE tooling — NOT official OAS.

    interface CostModel {
        components: CostComponent[];
        estimateMicroUsd?: number;
        trigger?: CostTrigger;
        triggerRef?: string;
        attribution?: CostAttribution;
        idempotencyKey?: string;
        reconciliationBasis?: ReconciliationBasis;
        amountExpression?: string;
        amountUnit?: "micro-usd" | "cents" | "usd";
        settlement?: CostSettlement;
    }
    Index

    Properties

    components: CostComponent[]
    estimateMicroUsd?: number

    Optional typical total for one call (µ$), for display + tests when usage isn't yet known.

    trigger?: CostTrigger

    WHEN/WHAT fires this cost (C024; default "synchronous"). STATIC — decouples accrual-time from the declaring op.

    triggerRef?: string

    the by-name handle (C009) of the webhook/callback/op whose firing accrues this cost (for a non-sync trigger).

    attribution?: CostAttribution

    WHO is charged when there is no live session (runtime strategy; the expression never enters the static matcher).

    idempotencyKey?: string

    a runtime-expression yielding a stable id to DEDUPE at-least-once delivery (e.g. "{$event.id}") — prevents double-counting a cost charged on both the receipt op and the triggered op. Runtime-only.

    reconciliationBasis?: ReconciliationBasis

    How the amount RECONCILES with the third party's actual charge (C026; default "declared-estimate"). A declared estimate is a guess; "payload-reconciled" reads the ACTUAL charged amount from the event at runtime (the real invoice line — proration/tax/refund included), so the recorded cost is authoritative, not an approximation.

    amountExpression?: string

    for "payload-reconciled": a runtime-expression yielding the ACTUAL amount (e.g. "{$event.body#/amount}"). Runtime-only — never the static matcher. Interpreted in amountUnit.

    amountUnit?: "micro-usd" | "cents" | "usd"

    the unit amountExpression yields (default "micro-usd"). "cents" (Stripe) → ×10_000; "usd" → ×1_000_000.

    settlement?: CostSettlement

    HOW the operator RECOVERS this cost (C044). The fifth orthogonal axis — basis=how-meters · trigger=when-fires · attribution=who-pays · reconciliation=declared-vs-actual · settlement=how-recovered.