Skip to content

Latest commit

 

History

History
60 lines (46 loc) · 2.18 KB

File metadata and controls

60 lines (46 loc) · 2.18 KB

API

Subjects and policy configuration

  • risk_subject_create(kind, external_id, segment, risk_tier, metadata)
  • risk_policy_create(name, operation, subject_kind, segment, risk_tier, priority, valid_from, valid_to, metadata)
  • risk_rule_create(policy_id, name, rule_kind, config, action, priority, critical)

Policy and rule versions are assigned atomically. Definitions cannot be updated or deleted; create the next version instead.

Evaluation

risk_evaluate(subject_id, operation, input_amount, output_amount,
              account_id, destination, occurred_at, metadata)

risk_check(subject_id, operation, input_amount, output_amount,
           account_id, destination, occurred_at, metadata,
           idempotency_key, expires_at)

Both return decision_id, status, reason, and evaluated_at. risk_evaluate returns a null ID and writes nothing. A repeated idempotency_key with the same canonical request returns the existing decision; a different request raises SQLSTATE PGR03 with detail RISK_IDEMPOTENCY_CONFLICT.

Operational configuration

  • risk_hold_create(...) and risk_hold_release(hold_id, actor)
  • risk_destination_create(...)
  • risk_override_create(...)
  • risk_exposure_group_create(...)
  • risk_exposure_group_add_account(...)
  • risk_validate()
  • risk_ledger_cache_refresh(ledger_account_id); pass NULL to warm all pg_ledger accounts

The actor/created_by value supplied to hold and override functions must be the current session_user; a mismatch raises SQLSTATE PGR05 with detail RISK_ACTOR_MISMATCH.

Views

  • risk_decisions_view
  • risk_denials_view
  • risk_reviews_view
  • risk_active_holds_view

Stable error details

Machine-readable details include RISK_SUBJECT_NOT_FOUND, RISK_POLICY_INVALID, RISK_RULE_INVALID, RISK_ADAPTER_MISSING, RISK_PRICE_STALE, RISK_RECONCILIATION_STALE, RISK_IDEMPOTENCY_CONFLICT, RISK_METRIC_UNAVAILABLE, RISK_ASSET_MISMATCH, and RISK_IMMUTABLE_RECORD. Parameter identity mismatches use RISK_ACTOR_MISMATCH; unexpected internal failures use RISK_INTERNAL_ERROR. Critical missing or stale adapter data becomes an ERROR decision, which callers must treat as fail-closed.