Files
ui/pkg/commerce/package.json
zooqueen 34f4b978c4 feat(commerce): add server-side usage-metering hook (@hanzo/commerce/metering)
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.
2026-06-19 09:20:40 -07:00

61 lines
1.5 KiB
JSON

{
"name": "@hanzo/commerce",
"version": "7.6.2",
"description": "e-commerce framework.",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public",
"scope": "@hanzo"
},
"author": "Hanzo AI, Inc.",
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "git+https://github.com/hanzoai/ui.git",
"directory": "pkg/commerce"
},
"keywords": [
"cart",
"hanzoai",
"hanzo"
],
"scripts": {
"lat": "npm show @hanzo/commerce version",
"pub": "npm publish",
"tc": "tsc",
"build": "tsc --outDir dist --declaration --emitDeclarationOnly false --module ESNext --esModuleInterop true --skipLibCheck true --sourceMap true"
},
"exports": {
".": "./index.ts",
"./types": "./types/index.ts",
"./client": "./client.ts",
"./billing": "./billing.ts",
"./metering": "./metering.ts",
"./debug": "./service/debug.ts"
},
"dependencies": {
"ethers": "^6.16.0",
"next-usequerystate": "^1.20.0"
},
"peerDependencies": {
"@hanzo/ui": ">=5.0.0",
"@hookform/resolvers": "^3.3.4",
"@radix-ui/react-radio-group": "^1.1.3",
"lucide-react": ">=0.456.0",
"mobx": "^6.12.3",
"mobx-react-lite": "^4.0.7",
"mobx-utils": "^6.0.8",
"next": ">=14.2.16",
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0",
"react-hook-form": ">=7.51.4",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/react": "19.2.14",
"@types/react-dom": "19.2.3",
"cross-fetch": "^4.1.0",
"typescript": "^5.9.3"
}
}