@hanzo/commerce 7.6.1 → 7.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/LICENSE.md +21 -0
  2. package/client.ts +124 -64
  3. package/components/add-to-cart-widget.tsx +6 -0
  4. package/components/item/product-card.tsx +18 -1
  5. package/dist/billing.d.ts +2 -0
  6. package/dist/billing.js +3 -0
  7. package/dist/billing.js.map +1 -0
  8. package/dist/client.d.ts +432 -0
  9. package/dist/client.js +392 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/components/Icons.d.ts +18 -0
  12. package/dist/components/Icons.js +19 -0
  13. package/dist/components/Icons.js.map +1 -0
  14. package/dist/components/add-to-cart-widget.d.ts +11 -0
  15. package/dist/components/add-to-cart-widget.js +85 -0
  16. package/dist/components/add-to-cart-widget.js.map +1 -0
  17. package/dist/components/buy/buy-card.d.ts +30 -0
  18. package/dist/components/buy/buy-card.js +109 -0
  19. package/dist/components/buy/buy-card.js.map +1 -0
  20. package/dist/components/buy/carousel-buy-card.d.ts +12 -0
  21. package/dist/components/buy/carousel-buy-card.js +94 -0
  22. package/dist/components/buy/carousel-buy-card.js.map +1 -0
  23. package/dist/components/buy/multi-family/all-variants-carousel.d.ts +4 -0
  24. package/dist/components/buy/multi-family/all-variants-carousel.js +115 -0
  25. package/dist/components/buy/multi-family/all-variants-carousel.js.map +1 -0
  26. package/dist/components/buy/multi-family/family-carousel/index.d.ts +4 -0
  27. package/dist/components/buy/multi-family/family-carousel/index.js +27 -0
  28. package/dist/components/buy/multi-family/family-carousel/index.js.map +1 -0
  29. package/dist/components/buy/multi-family/family-carousel/slide.d.ts +11 -0
  30. package/dist/components/buy/multi-family/family-carousel/slide.js +35 -0
  31. package/dist/components/buy/multi-family/family-carousel/slide.js.map +1 -0
  32. package/dist/components/buy/multi-family/family-carousel/state.d.ts +20 -0
  33. package/dist/components/buy/multi-family/family-carousel/state.js +59 -0
  34. package/dist/components/buy/multi-family/family-carousel/state.js.map +1 -0
  35. package/dist/components/buy/multi-family/index.d.ts +2 -0
  36. package/dist/components/buy/multi-family/index.js +3 -0
  37. package/dist/components/buy/multi-family/index.js.map +1 -0
  38. package/dist/components/buy/single-family-selector.d.ts +15 -0
  39. package/dist/components/buy/single-family-selector.js +28 -0
  40. package/dist/components/buy/single-family-selector.js.map +1 -0
  41. package/dist/components/buy/title-and-byline.d.ts +8 -0
  42. package/dist/components/buy/title-and-byline.js +7 -0
  43. package/dist/components/buy/title-and-byline.js.map +1 -0
  44. package/dist/components/cart/cart-panel/cart-line-item.d.ts +11 -0
  45. package/dist/components/cart/cart-panel/cart-line-item.js +25 -0
  46. package/dist/components/cart/cart-panel/cart-line-item.js.map +1 -0
  47. package/dist/components/cart/cart-panel/index.d.ts +19 -0
  48. package/dist/components/cart/cart-panel/index.js +65 -0
  49. package/dist/components/cart/cart-panel/index.js.map +1 -0
  50. package/dist/components/cart/cart-panel/promo-code.d.ts +4 -0
  51. package/dist/components/cart/cart-panel/promo-code.js +62 -0
  52. package/dist/components/cart/cart-panel/promo-code.js.map +1 -0
  53. package/dist/components/cart/cart-panel/total-area.d.ts +7 -0
  54. package/dist/components/cart/cart-panel/total-area.js +14 -0
  55. package/dist/components/cart/cart-panel/total-area.js.map +1 -0
  56. package/dist/components/checkout/payment-step-form/card-icon-row.d.ts +2 -0
  57. package/dist/components/checkout/payment-step-form/card-icon-row.js +14 -0
  58. package/dist/components/checkout/payment-step-form/card-icon-row.js.map +1 -0
  59. package/dist/components/checkout/payment-step-form/card-icons/amex.d.ts +4 -0
  60. package/dist/components/checkout/payment-step-form/card-icons/amex.js +6 -0
  61. package/dist/components/checkout/payment-step-form/card-icons/amex.js.map +1 -0
  62. package/dist/components/checkout/payment-step-form/card-icons/diners-club.d.ts +4 -0
  63. package/dist/components/checkout/payment-step-form/card-icons/diners-club.js +6 -0
  64. package/dist/components/checkout/payment-step-form/card-icons/diners-club.js.map +1 -0
  65. package/dist/components/checkout/payment-step-form/card-icons/discover.d.ts +4 -0
  66. package/dist/components/checkout/payment-step-form/card-icons/discover.js +6 -0
  67. package/dist/components/checkout/payment-step-form/card-icons/discover.js.map +1 -0
  68. package/dist/components/checkout/payment-step-form/card-icons/jcb.d.ts +4 -0
  69. package/dist/components/checkout/payment-step-form/card-icons/jcb.js +6 -0
  70. package/dist/components/checkout/payment-step-form/card-icons/jcb.js.map +1 -0
  71. package/dist/components/checkout/payment-step-form/card-icons/mastercard.d.ts +4 -0
  72. package/dist/components/checkout/payment-step-form/card-icons/mastercard.js +6 -0
  73. package/dist/components/checkout/payment-step-form/card-icons/mastercard.js.map +1 -0
  74. package/dist/components/checkout/payment-step-form/card-icons/visa.d.ts +4 -0
  75. package/dist/components/checkout/payment-step-form/card-icons/visa.js +6 -0
  76. package/dist/components/checkout/payment-step-form/card-icons/visa.js.map +1 -0
  77. package/dist/components/checkout/payment-step-form/cc-button.d.ts +3 -0
  78. package/dist/components/checkout/payment-step-form/cc-button.js +6 -0
  79. package/dist/components/checkout/payment-step-form/cc-button.js.map +1 -0
  80. package/dist/components/checkout/payment-step-form/contact-form.d.ts +5 -0
  81. package/dist/components/checkout/payment-step-form/contact-form.js +6 -0
  82. package/dist/components/checkout/payment-step-form/contact-form.js.map +1 -0
  83. package/dist/components/checkout/payment-step-form/crypto-icons/btc.d.ts +4 -0
  84. package/dist/components/checkout/payment-step-form/crypto-icons/btc.js +6 -0
  85. package/dist/components/checkout/payment-step-form/crypto-icons/btc.js.map +1 -0
  86. package/dist/components/checkout/payment-step-form/crypto-icons/eth.d.ts +4 -0
  87. package/dist/components/checkout/payment-step-form/crypto-icons/eth.js +6 -0
  88. package/dist/components/checkout/payment-step-form/crypto-icons/eth.js.map +1 -0
  89. package/dist/components/checkout/payment-step-form/crypto-icons/usdt.d.ts +4 -0
  90. package/dist/components/checkout/payment-step-form/crypto-icons/usdt.js +6 -0
  91. package/dist/components/checkout/payment-step-form/crypto-icons/usdt.js.map +1 -0
  92. package/dist/components/checkout/payment-step-form/index.d.ts +4 -0
  93. package/dist/components/checkout/payment-step-form/index.js +66 -0
  94. package/dist/components/checkout/payment-step-form/index.js.map +1 -0
  95. package/dist/components/checkout/payment-step-form/methods/bank-transfer.d.ts +4 -0
  96. package/dist/components/checkout/payment-step-form/methods/bank-transfer.js +24 -0
  97. package/dist/components/checkout/payment-step-form/methods/bank-transfer.js.map +1 -0
  98. package/dist/components/checkout/payment-step-form/methods/card.d.ts +4 -0
  99. package/dist/components/checkout/payment-step-form/methods/card.js +160 -0
  100. package/dist/components/checkout/payment-step-form/methods/card.js.map +1 -0
  101. package/dist/components/checkout/payment-step-form/methods/crypto.d.ts +9 -0
  102. package/dist/components/checkout/payment-step-form/methods/crypto.js +137 -0
  103. package/dist/components/checkout/payment-step-form/methods/crypto.js.map +1 -0
  104. package/dist/components/checkout/payment-step-form/methods/index.d.ts +6 -0
  105. package/dist/components/checkout/payment-step-form/methods/index.js +21 -0
  106. package/dist/components/checkout/payment-step-form/methods/index.js.map +1 -0
  107. package/dist/components/checkout/shipping-step-form.d.ts +3 -0
  108. package/dist/components/checkout/shipping-step-form.js +53 -0
  109. package/dist/components/checkout/shipping-step-form.js.map +1 -0
  110. package/dist/components/index.d.ts +8 -0
  111. package/dist/components/index.js +9 -0
  112. package/dist/components/index.js.map +1 -0
  113. package/dist/components/item/product-card.d.ts +7 -0
  114. package/dist/components/item/product-card.js +9 -0
  115. package/dist/components/item/product-card.js.map +1 -0
  116. package/dist/components/item-selector/button.d.ts +4 -0
  117. package/dist/components/item-selector/button.js +47 -0
  118. package/dist/components/item-selector/button.js.map +1 -0
  119. package/dist/components/item-selector/carousel/index.d.ts +12 -0
  120. package/dist/components/item-selector/carousel/index.js +74 -0
  121. package/dist/components/item-selector/carousel/index.js.map +1 -0
  122. package/dist/components/item-selector/carousel/slider.d.ts +8 -0
  123. package/dist/components/item-selector/carousel/slider.js +12 -0
  124. package/dist/components/item-selector/carousel/slider.js.map +1 -0
  125. package/dist/components/item-selector/index.d.ts +2 -0
  126. package/dist/components/item-selector/index.js +3 -0
  127. package/dist/components/item-selector/index.js.map +1 -0
  128. package/dist/components/item-selector/quantity-indicator.d.ts +9 -0
  129. package/dist/components/item-selector/quantity-indicator.js +16 -0
  130. package/dist/components/item-selector/quantity-indicator.js.map +1 -0
  131. package/dist/components/node-tabs/index.d.ts +14 -0
  132. package/dist/components/node-tabs/index.js +42 -0
  133. package/dist/components/node-tabs/index.js.map +1 -0
  134. package/dist/components/node-tabs/node-image.d.ts +6 -0
  135. package/dist/components/node-tabs/node-image.js +13 -0
  136. package/dist/components/node-tabs/node-image.js.map +1 -0
  137. package/dist/index.d.ts +9 -0
  138. package/dist/index.js +9 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/metering.d.ts +162 -0
  141. package/dist/metering.js +204 -0
  142. package/dist/metering.js.map +1 -0
  143. package/dist/metering.test.d.ts +13 -0
  144. package/dist/metering.test.js +181 -0
  145. package/dist/metering.test.js.map +1 -0
  146. package/dist/product-card.test.d.ts +14 -0
  147. package/dist/product-card.test.js +96 -0
  148. package/dist/product-card.test.js.map +1 -0
  149. package/dist/service/context.d.ts +8 -0
  150. package/dist/service/context.js +19 -0
  151. package/dist/service/context.js.map +1 -0
  152. package/dist/service/debug.d.ts +10 -0
  153. package/dist/service/debug.js +30 -0
  154. package/dist/service/debug.js.map +1 -0
  155. package/dist/service/impls/standalone/actual-line-item.d.ts +40 -0
  156. package/dist/service/impls/standalone/actual-line-item.js +84 -0
  157. package/dist/service/impls/standalone/actual-line-item.js.map +1 -0
  158. package/dist/service/impls/standalone/get-instance.d.ts +2 -0
  159. package/dist/service/impls/standalone/get-instance.js +39 -0
  160. package/dist/service/impls/standalone/get-instance.js.map +1 -0
  161. package/dist/service/impls/standalone/index.d.ts +67 -0
  162. package/dist/service/impls/standalone/index.js +416 -0
  163. package/dist/service/impls/standalone/index.js.map +1 -0
  164. package/dist/service/impls/standalone/order/firebase.d.ts +6 -0
  165. package/dist/service/impls/standalone/order/firebase.js +6 -0
  166. package/dist/service/impls/standalone/order/firebase.js.map +1 -0
  167. package/dist/service/impls/standalone/order/index.d.ts +30 -0
  168. package/dist/service/impls/standalone/order/index.js +21 -0
  169. package/dist/service/impls/standalone/order/index.js.map +1 -0
  170. package/dist/service/impls/standalone/persistence.d.ts +4 -0
  171. package/dist/service/impls/standalone/persistence.js +22 -0
  172. package/dist/service/impls/standalone/persistence.js.map +1 -0
  173. package/dist/service/path-utils.d.ts +7 -0
  174. package/dist/service/path-utils.js +16 -0
  175. package/dist/service/path-utils.js.map +1 -0
  176. package/dist/service/sep.d.ts +6 -0
  177. package/dist/service/sep.js +6 -0
  178. package/dist/service/sep.js.map +1 -0
  179. package/dist/types/category-node.d.ts +36 -0
  180. package/dist/types/category-node.js +2 -0
  181. package/dist/types/category-node.js.map +1 -0
  182. package/dist/types/checkout.d.ts +33 -0
  183. package/dist/types/checkout.js +2 -0
  184. package/dist/types/checkout.js.map +1 -0
  185. package/dist/types/commerce-config.d.ts +11 -0
  186. package/dist/types/commerce-config.js +2 -0
  187. package/dist/types/commerce-config.js.map +1 -0
  188. package/dist/types/commerce-service.d.ts +109 -0
  189. package/dist/types/commerce-service.js +2 -0
  190. package/dist/types/commerce-service.js.map +1 -0
  191. package/dist/types/family.d.ts +16 -0
  192. package/dist/types/family.js +2 -0
  193. package/dist/types/family.js.map +1 -0
  194. package/dist/types/index.d.ts +13 -0
  195. package/dist/types/index.js +8 -0
  196. package/dist/types/index.js.map +1 -0
  197. package/dist/types/item-selector.d.ts +72 -0
  198. package/dist/types/item-selector.js +2 -0
  199. package/dist/types/item-selector.js.map +1 -0
  200. package/dist/types/line-item.d.ts +14 -0
  201. package/dist/types/line-item.js +2 -0
  202. package/dist/types/line-item.js.map +1 -0
  203. package/dist/types/multi-family-selector-props.d.ts +16 -0
  204. package/dist/types/multi-family-selector-props.js +2 -0
  205. package/dist/types/multi-family-selector-props.js.map +1 -0
  206. package/dist/types/product.d.ts +15 -0
  207. package/dist/types/product.js +2 -0
  208. package/dist/types/product.js.map +1 -0
  209. package/dist/types/promo.d.ts +7 -0
  210. package/dist/types/promo.js +2 -0
  211. package/dist/types/promo.js.map +1 -0
  212. package/dist/types/selection-ui-specifier.d.ts +40 -0
  213. package/dist/types/selection-ui-specifier.js +2 -0
  214. package/dist/types/selection-ui-specifier.js.map +1 -0
  215. package/dist/types/string-mutator.d.ts +9 -0
  216. package/dist/types/string-mutator.js +2 -0
  217. package/dist/types/string-mutator.js.map +1 -0
  218. package/dist/types/token-separators.d.ts +6 -0
  219. package/dist/types/token-separators.js +2 -0
  220. package/dist/types/token-separators.js.map +1 -0
  221. package/dist/util/analytics.d.ts +9 -0
  222. package/dist/util/analytics.js +10 -0
  223. package/dist/util/analytics.js.map +1 -0
  224. package/dist/util/countries.d.ts +7 -0
  225. package/dist/util/countries.js +197 -0
  226. package/dist/util/countries.js.map +1 -0
  227. package/dist/util/error.d.ts +1 -0
  228. package/dist/util/error.js +22 -0
  229. package/dist/util/error.js.map +1 -0
  230. package/dist/util/index.d.ts +15 -0
  231. package/dist/util/index.js +54 -0
  232. package/dist/util/index.js.map +1 -0
  233. package/dist/util/item-selector-options-accessor.d.ts +3 -0
  234. package/dist/util/item-selector-options-accessor.js +27 -0
  235. package/dist/util/item-selector-options-accessor.js.map +1 -0
  236. package/dist/util/line-item-ref.d.ts +8 -0
  237. package/dist/util/line-item-ref.js +15 -0
  238. package/dist/util/line-item-ref.js.map +1 -0
  239. package/dist/util/multi-family-selector-options-accessor.d.ts +3 -0
  240. package/dist/util/multi-family-selector-options-accessor.js +11 -0
  241. package/dist/util/multi-family-selector-options-accessor.js.map +1 -0
  242. package/dist/util/obs-string-mutator.d.ts +8 -0
  243. package/dist/util/obs-string-mutator.js +15 -0
  244. package/dist/util/obs-string-mutator.js.map +1 -0
  245. package/dist/util/product-media-accessor.d.ts +29 -0
  246. package/dist/util/product-media-accessor.js +22 -0
  247. package/dist/util/product-media-accessor.js.map +1 -0
  248. package/dist/util/promo-codes.d.ts +3 -0
  249. package/dist/util/promo-codes.js +100 -0
  250. package/dist/util/promo-codes.js.map +1 -0
  251. package/dist/util/selection-ui-specifiers.d.ts +3 -0
  252. package/dist/util/selection-ui-specifiers.js +24 -0
  253. package/dist/util/selection-ui-specifiers.js.map +1 -0
  254. package/dist/util/square-payment.d.ts +7 -0
  255. package/dist/util/square-payment.js +37 -0
  256. package/dist/util/square-payment.js.map +1 -0
  257. package/dist/util/use-sync-sku-param-w-current-item.d.ts +2 -0
  258. package/dist/util/use-sync-sku-param-w-current-item.js +61 -0
  259. package/dist/util/use-sync-sku-param-w-current-item.js.map +1 -0
  260. package/index.ts +18 -3
  261. package/metering.test.ts +199 -0
  262. package/metering.ts +289 -0
  263. package/package.json +19 -17
  264. package/product-card.test.tsx +104 -0
@@ -0,0 +1,432 @@
1
+ /**
2
+ * @hanzo/commerce/client
3
+ *
4
+ * Universal TypeScript client for the Hanzo Commerce API.
5
+ * Works in browser, Node.js, and edge runtimes — no backend required.
6
+ * Covers billing, subscriptions, payments, checkout, coupons,
7
+ * referrals, affiliates, usage, and plans.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { Commerce } from '@hanzo/commerce/client'
12
+ *
13
+ * const commerce = new Commerce({ baseUrl: 'https://api.hanzo.ai', token: iamToken })
14
+ *
15
+ * // Validate a coupon before checkout
16
+ * const coupon = await commerce.validateCoupon('LAUNCH50')
17
+ *
18
+ * // Create a checkout session
19
+ * const session = await commerce.createCheckoutSession({
20
+ * items: [{ id: 'plan_pro', quantity: 1 }],
21
+ * couponCode: 'LAUNCH50',
22
+ * referrerId: 'ref_abc123',
23
+ * successUrl: 'https://app.example.com/success',
24
+ * cancelUrl: 'https://app.example.com/cancel',
25
+ * })
26
+ * window.location.href = session.checkoutUrl
27
+ *
28
+ * // Subscribe
29
+ * const sub = await commerce.subscribe({ planId: 'pro', userId: 'user_xyz' })
30
+ * ```
31
+ */
32
+ export type CommerceClientConfig = {
33
+ /**
34
+ * Commerce API base URL.
35
+ * Defaults to https://api.hanzo.ai
36
+ */
37
+ baseUrl?: string;
38
+ /** @deprecated use baseUrl */
39
+ commerceUrl?: string;
40
+ /** IAM access token for authenticated requests. */
41
+ token?: string;
42
+ /** Request timeout in milliseconds. Default 15 000. */
43
+ timeoutMs?: number;
44
+ };
45
+ export type Balance = {
46
+ balance: number;
47
+ holds: number;
48
+ available: number;
49
+ };
50
+ /**
51
+ * Tier-aware balance from GET /v1/billing/tier. effectiveAvailable folds the
52
+ * tenant's included plan allotment (e.g. the free-tier daily credit) into the
53
+ * prepaid available balance — gate on this to honor included usage first.
54
+ */
55
+ export type TierResponse = {
56
+ user: string;
57
+ tier: {
58
+ name: string;
59
+ displayName?: string;
60
+ maxAgents?: number;
61
+ unlimitedAgents?: boolean;
62
+ dailyCreditsCents?: number;
63
+ allowedModels?: string[];
64
+ };
65
+ balance: {
66
+ currency: string;
67
+ prepaidAvailable: number;
68
+ dailyRemaining: number;
69
+ effectiveAvailable: number;
70
+ };
71
+ };
72
+ export type Transaction = {
73
+ id?: string;
74
+ owner?: string;
75
+ type: 'hold' | 'hold-removed' | 'transfer' | 'deposit' | 'withdraw';
76
+ destinationId?: string;
77
+ destinationKind?: string;
78
+ sourceId?: string;
79
+ sourceKind?: string;
80
+ currency: string;
81
+ amount: number;
82
+ tags?: string[];
83
+ expiresAt?: string;
84
+ metadata?: Record<string, unknown>;
85
+ createdAt?: string;
86
+ };
87
+ export type Subscription = {
88
+ id?: string;
89
+ planId?: string;
90
+ userId?: string;
91
+ customerId?: string;
92
+ status?: 'trialing' | 'active' | 'past_due' | 'canceled' | 'unpaid' | string;
93
+ billingType?: 'charge_automatically' | 'send_invoice';
94
+ periodStart?: string;
95
+ periodEnd?: string;
96
+ trialStart?: string;
97
+ trialEnd?: string;
98
+ quantity?: number;
99
+ createdAt?: string;
100
+ cancelAtPeriodEnd?: boolean;
101
+ currentPeriodEnd?: string;
102
+ };
103
+ export type Plan = {
104
+ id?: string;
105
+ slug?: string;
106
+ name?: string;
107
+ description?: string;
108
+ price?: number;
109
+ priceMonthly?: number;
110
+ priceAnnual?: number;
111
+ currency?: string;
112
+ interval?: 'monthly' | 'yearly' | string;
113
+ intervalCount?: number;
114
+ trialPeriodDays?: number;
115
+ features?: string[];
116
+ popular?: boolean;
117
+ contactSales?: boolean;
118
+ metadata?: Record<string, unknown>;
119
+ };
120
+ export type Payment = {
121
+ id?: string;
122
+ orderId?: string;
123
+ userId?: string;
124
+ amount?: number;
125
+ amountRefunded?: number;
126
+ fee?: number;
127
+ currency?: string;
128
+ status?: 'cancelled' | 'credit' | 'disputed' | 'failed' | 'fraudulent' | 'paid' | 'refunded' | 'unpaid' | string;
129
+ captured?: boolean;
130
+ live?: boolean;
131
+ createdAt?: string;
132
+ };
133
+ export type UsageRecord = {
134
+ user: string;
135
+ currency?: string;
136
+ amount: number;
137
+ model?: string;
138
+ provider?: string;
139
+ tokens?: number;
140
+ promptTokens?: number;
141
+ completionTokens?: number;
142
+ };
143
+ export type CouponType = 'Percent' | 'Flat' | 'FreeShipping' | 'FreeItem';
144
+ export type Coupon = {
145
+ id?: string;
146
+ code: string;
147
+ type: CouponType;
148
+ /** Amount: percentage (0-100) for Percent, cents for Flat */
149
+ amount: number;
150
+ description?: string;
151
+ limit?: number;
152
+ used?: number;
153
+ startDate?: string;
154
+ endDate?: string;
155
+ enabled?: boolean;
156
+ /** Calculated discount in cents (returned by validateCoupon) */
157
+ discountCents?: number;
158
+ };
159
+ export type CouponValidateResult = {
160
+ valid: boolean;
161
+ coupon?: Coupon;
162
+ error?: string;
163
+ /** Discount in cents for a given subtotal */
164
+ discountCents?: number;
165
+ };
166
+ export type Discount = {
167
+ id?: string;
168
+ type: 'Percent' | 'Flat' | 'FreeShipping' | 'FreeItem' | 'Bulk';
169
+ amount: number;
170
+ scope?: 'Product' | 'Variant' | 'Collection' | 'Store';
171
+ enabled?: boolean;
172
+ startDate?: string;
173
+ endDate?: string;
174
+ };
175
+ export type CheckoutItem = {
176
+ id: string;
177
+ quantity?: number;
178
+ /** Price override in cents */
179
+ price?: number;
180
+ name?: string;
181
+ description?: string;
182
+ imageUrl?: string;
183
+ metadata?: Record<string, unknown>;
184
+ };
185
+ export type CheckoutSessionRequest = {
186
+ items: CheckoutItem[];
187
+ successUrl: string;
188
+ cancelUrl: string;
189
+ couponCode?: string;
190
+ referrerId?: string;
191
+ affiliateId?: string;
192
+ currency?: string;
193
+ customer?: {
194
+ email?: string;
195
+ name?: string;
196
+ address?: string;
197
+ city?: string;
198
+ zip?: string;
199
+ };
200
+ metadata?: Record<string, unknown>;
201
+ };
202
+ export type CheckoutSessionResponse = {
203
+ checkoutUrl: string;
204
+ sessionId: string;
205
+ /** Original total in cents before discount */
206
+ originalTotal?: number;
207
+ /** Final total in cents after discount */
208
+ finalTotal?: number;
209
+ discount?: {
210
+ code: string;
211
+ type: CouponType;
212
+ amount: number;
213
+ discountCents: number;
214
+ };
215
+ };
216
+ export type PaymentMethodType = 'card' | 'bank_account' | 'balance' | 'crypto' | 'wire';
217
+ export type PaymentMethod = {
218
+ id: string;
219
+ type: PaymentMethodType;
220
+ isDefault?: boolean;
221
+ customerId?: string;
222
+ card?: {
223
+ brand: string;
224
+ last4: string;
225
+ expMonth: number;
226
+ expYear: number;
227
+ };
228
+ bank_account?: {
229
+ bankName?: string;
230
+ last4?: string;
231
+ accountType?: 'checking' | 'savings';
232
+ routingNumber?: string;
233
+ };
234
+ crypto?: {
235
+ chain: string;
236
+ address: string;
237
+ label?: string;
238
+ };
239
+ providerRef?: string;
240
+ providerType?: string;
241
+ createdAt?: string;
242
+ };
243
+ export type Referral = {
244
+ id?: string;
245
+ userId?: string;
246
+ referrerId?: string;
247
+ affiliateId?: string;
248
+ orderId?: string;
249
+ fee?: number;
250
+ createdAt?: string;
251
+ };
252
+ export type Referrer = {
253
+ id?: string;
254
+ userId?: string;
255
+ enabled?: boolean;
256
+ code?: string;
257
+ referrals?: Referral[];
258
+ };
259
+ export type Affiliate = {
260
+ id?: string;
261
+ userId?: string;
262
+ enabled?: boolean;
263
+ commission?: number;
264
+ couponId?: string;
265
+ connectUrl?: string;
266
+ };
267
+ export type CreditGrant = {
268
+ id?: string;
269
+ userId?: string;
270
+ amount: number;
271
+ currency: string;
272
+ expiresAt?: string;
273
+ tags?: string[];
274
+ };
275
+ export declare class Commerce {
276
+ private readonly baseUrl;
277
+ private token;
278
+ private readonly timeoutMs;
279
+ constructor(config?: CommerceClientConfig);
280
+ /** Update the auth token (e.g. after IAM token refresh). */
281
+ setToken(token: string): void;
282
+ private request;
283
+ getBalance(user: string, currency?: string, token?: string, headers?: Record<string, string>): Promise<Balance>;
284
+ getAllBalances(user: string, token?: string): Promise<Record<string, Balance>>;
285
+ /**
286
+ * Tier-aware balance: prepaid available plus the tenant's included plan
287
+ * allotment (effectiveAvailable). Use this for the metering gate when you
288
+ * want included usage (e.g. free-tier daily credit) honored before prepaid
289
+ * funds are drawn down.
290
+ */
291
+ getTier(user: string, opts?: {
292
+ token?: string;
293
+ headers?: Record<string, string>;
294
+ }): Promise<TierResponse>;
295
+ addUsageRecord(record: UsageRecord, token?: string, headers?: Record<string, string>): Promise<Transaction>;
296
+ getUsageRecords(user: string, currency?: string, token?: string): Promise<Transaction[]>;
297
+ addDeposit(params: {
298
+ user: string;
299
+ currency?: string;
300
+ amount: number;
301
+ notes?: string;
302
+ tags?: string[];
303
+ expiresIn?: string;
304
+ }, token?: string): Promise<Transaction>;
305
+ grantStarterCredit(user: string, token?: string): Promise<Transaction>;
306
+ getPlans(token?: string): Promise<Plan[]>;
307
+ getPlan(planId: string, token?: string): Promise<Plan | null>;
308
+ subscribe(params: {
309
+ planId: string;
310
+ userId?: string;
311
+ customerId?: string;
312
+ paymentMethodId?: string;
313
+ couponCode?: string;
314
+ trialDays?: number;
315
+ }, token?: string): Promise<Subscription>;
316
+ getSubscription(subscriptionId: string, token?: string): Promise<Subscription | null>;
317
+ listSubscriptions(params?: {
318
+ customerId?: string;
319
+ }, token?: string): Promise<Subscription[]>;
320
+ updateSubscription(subscriptionId: string, update: Partial<Subscription>, token?: string): Promise<Subscription>;
321
+ cancelSubscription(subscriptionId: string, immediately?: boolean, token?: string): Promise<Subscription>;
322
+ reactivateSubscription(subscriptionId: string, token?: string): Promise<Subscription>;
323
+ /**
324
+ * Create a hosted checkout session.
325
+ * Returns a URL to redirect the customer to for payment.
326
+ * Supports coupons, referral tracking, and multiple currencies.
327
+ */
328
+ createCheckoutSession(params: CheckoutSessionRequest, token?: string): Promise<CheckoutSessionResponse>;
329
+ addPaymentMethod(params: {
330
+ customerId: string;
331
+ type: PaymentMethodType;
332
+ token?: string;
333
+ providerRef?: string;
334
+ providerType?: string;
335
+ }, token?: string): Promise<PaymentMethod>;
336
+ listPaymentMethods(customerId: string, token?: string): Promise<PaymentMethod[]>;
337
+ removePaymentMethod(paymentMethodId: string, token?: string): Promise<void>;
338
+ setDefaultPaymentMethod(customerId: string, paymentMethodId: string, token?: string): Promise<PaymentMethod>;
339
+ /**
340
+ * Validate a coupon code.
341
+ * Optionally pass a subtotalCents to get the calculated discount amount.
342
+ */
343
+ validateCoupon(code: string, subtotalCents?: number, token?: string): Promise<CouponValidateResult>;
344
+ /**
345
+ * Redeem a coupon for a user. Creates credit grant records.
346
+ */
347
+ redeemCoupon(code: string, userId: string, token?: string): Promise<CreditGrant[]>;
348
+ /**
349
+ * Get or create a referrer record for a user.
350
+ * Returns the referral code/link the user can share.
351
+ */
352
+ getOrCreateReferrer(userId: string, token?: string): Promise<Referrer>;
353
+ getReferrals(userId: string, token?: string): Promise<Referral[]>;
354
+ getReferrers(userId: string, token?: string): Promise<Referrer[]>;
355
+ /**
356
+ * Get affiliate details for a user.
357
+ */
358
+ getAffiliate(userId: string, token?: string): Promise<Affiliate | null>;
359
+ /**
360
+ * Create an affiliate account for a user.
361
+ * After creation, user can connect their bank via the returnedconnectUrl.
362
+ */
363
+ createAffiliate(userId: string, token?: string): Promise<Affiliate>;
364
+ getAffiliateReferrals(affiliateId: string, token?: string): Promise<Referral[]>;
365
+ getAffiliateOrders(affiliateId: string, token?: string): Promise<unknown[]>;
366
+ getAffiliateTransactions(affiliateId: string, token?: string): Promise<Transaction[]>;
367
+ authorize(orderId: string, token?: string): Promise<Payment>;
368
+ capture(orderId: string, token?: string): Promise<Payment>;
369
+ charge(orderId: string, token?: string): Promise<Payment>;
370
+ refund(paymentId: string, token?: string): Promise<Payment>;
371
+ billingRefund(params: {
372
+ user: string;
373
+ amount: number;
374
+ originalTransactionId: string;
375
+ currency?: string;
376
+ notes?: string;
377
+ }, token?: string): Promise<Transaction>;
378
+ /**
379
+ * Get or create a deposit address for a given chain.
380
+ * Used for crypto top-up — user sends funds to this address.
381
+ */
382
+ getWalletAddress(params: {
383
+ chain: string;
384
+ userId: string;
385
+ }, token?: string): Promise<{
386
+ address: string;
387
+ chain: string;
388
+ qrCode?: string;
389
+ }>;
390
+ /**
391
+ * Add a bank account payment method (ACH).
392
+ * plaidToken from Plaid Link or Square bank OAuth.
393
+ */
394
+ addBankAccount(params: {
395
+ customerId: string;
396
+ plaidToken?: string;
397
+ bankName?: string;
398
+ accountType?: 'checking' | 'savings';
399
+ }, token?: string): Promise<PaymentMethod>;
400
+ addCryptoWallet(params: {
401
+ customerId: string;
402
+ chain: string;
403
+ address: string;
404
+ label?: string;
405
+ }, token?: string): Promise<PaymentMethod>;
406
+ /**
407
+ * Convenience: charge a saved payment method and deposit credits.
408
+ * amount is in cents.
409
+ */
410
+ topup(params: {
411
+ userId: string;
412
+ paymentMethodId: string;
413
+ amountCents: number;
414
+ currency?: string;
415
+ }, token?: string): Promise<Transaction>;
416
+ }
417
+ /**
418
+ * Create a commerce client pre-configured for api.hanzo.ai.
419
+ * Pass your IAM access token (read from localStorage or cookie).
420
+ *
421
+ * @example
422
+ * ```ts
423
+ * import { hanzoCommerce } from '@hanzo/commerce/client'
424
+ * const commerce = hanzoCommerce(localStorage.getItem('hanzo-auth-token') ?? undefined)
425
+ * const plans = await commerce.getPlans()
426
+ * ```
427
+ */
428
+ export declare function hanzoCommerce(token?: string): Commerce;
429
+ export declare class CommerceApiError extends Error {
430
+ readonly status: number;
431
+ constructor(status: number, message: string);
432
+ }