mirror of
https://github.com/hanzoai/ui.git
synced 2026-11-21 00:18:41 +00:00
The TypeScript counterpart of github.com/hanzoai/go-sdk/metering — the one way every Hanzo product meters usage to commerce (the billing source of truth) so everything can be paid for, not just the LLM/cloud path. Shares an identical wire contract with the Go client. - Metering class composes the existing Commerce client (no HTTP dup): authorize() pre-request balance gate (fail-closed by default; 402 vs 503), record() post-request usage write. tierAware gates on effectiveAvailable (prepaid + included plan allotment). - S2S auth: Authorization: Bearer COMMERCE_SERVICE_TOKEN (KMS-sourced) + X-IAM-Org-Id. Metering.fromEnv() for canonical env wiring. - identityFromHeaders(): reads gateway-minted X-User-Id/X-Org-Id. - client.ts: getTier() + custom-headers support on request/getBalance/ addUsageRecord (DRY enablers for the S2S org header). - 14 contract tests (mock fetch) mirroring the Go suite; isolated tsc clean. - exports: ./metering ; index re-exports ; version 7.6.1 -> 7.6.2. Refs universe task #28.