@hanzo/commerce 7.6.0 → 7.6.3

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 (258) hide show
  1. package/LICENSE.md +21 -0
  2. package/client.ts +155 -39
  3. package/dist/billing.d.ts +2 -0
  4. package/dist/billing.js +3 -0
  5. package/dist/billing.js.map +1 -0
  6. package/dist/client.d.ts +464 -0
  7. package/dist/client.js +424 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/components/Icons.d.ts +18 -0
  10. package/dist/components/Icons.js +19 -0
  11. package/dist/components/Icons.js.map +1 -0
  12. package/dist/components/add-to-cart-widget.d.ts +11 -0
  13. package/dist/components/add-to-cart-widget.js +85 -0
  14. package/dist/components/add-to-cart-widget.js.map +1 -0
  15. package/dist/components/buy/buy-card.d.ts +30 -0
  16. package/dist/components/buy/buy-card.js +109 -0
  17. package/dist/components/buy/buy-card.js.map +1 -0
  18. package/dist/components/buy/carousel-buy-card.d.ts +12 -0
  19. package/dist/components/buy/carousel-buy-card.js +94 -0
  20. package/dist/components/buy/carousel-buy-card.js.map +1 -0
  21. package/dist/components/buy/multi-family/all-variants-carousel.d.ts +4 -0
  22. package/dist/components/buy/multi-family/all-variants-carousel.js +115 -0
  23. package/dist/components/buy/multi-family/all-variants-carousel.js.map +1 -0
  24. package/dist/components/buy/multi-family/family-carousel/index.d.ts +4 -0
  25. package/dist/components/buy/multi-family/family-carousel/index.js +27 -0
  26. package/dist/components/buy/multi-family/family-carousel/index.js.map +1 -0
  27. package/dist/components/buy/multi-family/family-carousel/slide.d.ts +11 -0
  28. package/dist/components/buy/multi-family/family-carousel/slide.js +35 -0
  29. package/dist/components/buy/multi-family/family-carousel/slide.js.map +1 -0
  30. package/dist/components/buy/multi-family/family-carousel/state.d.ts +20 -0
  31. package/dist/components/buy/multi-family/family-carousel/state.js +59 -0
  32. package/dist/components/buy/multi-family/family-carousel/state.js.map +1 -0
  33. package/dist/components/buy/multi-family/index.d.ts +2 -0
  34. package/dist/components/buy/multi-family/index.js +3 -0
  35. package/dist/components/buy/multi-family/index.js.map +1 -0
  36. package/dist/components/buy/single-family-selector.d.ts +15 -0
  37. package/dist/components/buy/single-family-selector.js +28 -0
  38. package/dist/components/buy/single-family-selector.js.map +1 -0
  39. package/dist/components/buy/title-and-byline.d.ts +8 -0
  40. package/dist/components/buy/title-and-byline.js +7 -0
  41. package/dist/components/buy/title-and-byline.js.map +1 -0
  42. package/dist/components/cart/cart-panel/cart-line-item.d.ts +11 -0
  43. package/dist/components/cart/cart-panel/cart-line-item.js +25 -0
  44. package/dist/components/cart/cart-panel/cart-line-item.js.map +1 -0
  45. package/dist/components/cart/cart-panel/index.d.ts +19 -0
  46. package/dist/components/cart/cart-panel/index.js +65 -0
  47. package/dist/components/cart/cart-panel/index.js.map +1 -0
  48. package/dist/components/cart/cart-panel/promo-code.d.ts +4 -0
  49. package/dist/components/cart/cart-panel/promo-code.js +62 -0
  50. package/dist/components/cart/cart-panel/promo-code.js.map +1 -0
  51. package/dist/components/cart/cart-panel/total-area.d.ts +7 -0
  52. package/dist/components/cart/cart-panel/total-area.js +14 -0
  53. package/dist/components/cart/cart-panel/total-area.js.map +1 -0
  54. package/dist/components/checkout/payment-step-form/card-icon-row.d.ts +2 -0
  55. package/dist/components/checkout/payment-step-form/card-icon-row.js +14 -0
  56. package/dist/components/checkout/payment-step-form/card-icon-row.js.map +1 -0
  57. package/dist/components/checkout/payment-step-form/card-icons/amex.d.ts +4 -0
  58. package/dist/components/checkout/payment-step-form/card-icons/amex.js +6 -0
  59. package/dist/components/checkout/payment-step-form/card-icons/amex.js.map +1 -0
  60. package/dist/components/checkout/payment-step-form/card-icons/diners-club.d.ts +4 -0
  61. package/dist/components/checkout/payment-step-form/card-icons/diners-club.js +6 -0
  62. package/dist/components/checkout/payment-step-form/card-icons/diners-club.js.map +1 -0
  63. package/dist/components/checkout/payment-step-form/card-icons/discover.d.ts +4 -0
  64. package/dist/components/checkout/payment-step-form/card-icons/discover.js +6 -0
  65. package/dist/components/checkout/payment-step-form/card-icons/discover.js.map +1 -0
  66. package/dist/components/checkout/payment-step-form/card-icons/jcb.d.ts +4 -0
  67. package/dist/components/checkout/payment-step-form/card-icons/jcb.js +6 -0
  68. package/dist/components/checkout/payment-step-form/card-icons/jcb.js.map +1 -0
  69. package/dist/components/checkout/payment-step-form/card-icons/mastercard.d.ts +4 -0
  70. package/dist/components/checkout/payment-step-form/card-icons/mastercard.js +6 -0
  71. package/dist/components/checkout/payment-step-form/card-icons/mastercard.js.map +1 -0
  72. package/dist/components/checkout/payment-step-form/card-icons/visa.d.ts +4 -0
  73. package/dist/components/checkout/payment-step-form/card-icons/visa.js +6 -0
  74. package/dist/components/checkout/payment-step-form/card-icons/visa.js.map +1 -0
  75. package/dist/components/checkout/payment-step-form/cc-button.d.ts +3 -0
  76. package/dist/components/checkout/payment-step-form/cc-button.js +6 -0
  77. package/dist/components/checkout/payment-step-form/cc-button.js.map +1 -0
  78. package/dist/components/checkout/payment-step-form/contact-form.d.ts +5 -0
  79. package/dist/components/checkout/payment-step-form/contact-form.js +6 -0
  80. package/dist/components/checkout/payment-step-form/contact-form.js.map +1 -0
  81. package/dist/components/checkout/payment-step-form/crypto-icons/btc.d.ts +4 -0
  82. package/dist/components/checkout/payment-step-form/crypto-icons/btc.js +6 -0
  83. package/dist/components/checkout/payment-step-form/crypto-icons/btc.js.map +1 -0
  84. package/dist/components/checkout/payment-step-form/crypto-icons/eth.d.ts +4 -0
  85. package/dist/components/checkout/payment-step-form/crypto-icons/eth.js +6 -0
  86. package/dist/components/checkout/payment-step-form/crypto-icons/eth.js.map +1 -0
  87. package/dist/components/checkout/payment-step-form/crypto-icons/usdt.d.ts +4 -0
  88. package/dist/components/checkout/payment-step-form/crypto-icons/usdt.js +6 -0
  89. package/dist/components/checkout/payment-step-form/crypto-icons/usdt.js.map +1 -0
  90. package/dist/components/checkout/payment-step-form/index.d.ts +4 -0
  91. package/dist/components/checkout/payment-step-form/index.js +66 -0
  92. package/dist/components/checkout/payment-step-form/index.js.map +1 -0
  93. package/dist/components/checkout/payment-step-form/methods/bank-transfer.d.ts +4 -0
  94. package/dist/components/checkout/payment-step-form/methods/bank-transfer.js +24 -0
  95. package/dist/components/checkout/payment-step-form/methods/bank-transfer.js.map +1 -0
  96. package/dist/components/checkout/payment-step-form/methods/card.d.ts +4 -0
  97. package/dist/components/checkout/payment-step-form/methods/card.js +160 -0
  98. package/dist/components/checkout/payment-step-form/methods/card.js.map +1 -0
  99. package/dist/components/checkout/payment-step-form/methods/crypto.d.ts +9 -0
  100. package/dist/components/checkout/payment-step-form/methods/crypto.js +137 -0
  101. package/dist/components/checkout/payment-step-form/methods/crypto.js.map +1 -0
  102. package/dist/components/checkout/payment-step-form/methods/index.d.ts +6 -0
  103. package/dist/components/checkout/payment-step-form/methods/index.js +21 -0
  104. package/dist/components/checkout/payment-step-form/methods/index.js.map +1 -0
  105. package/dist/components/checkout/shipping-step-form.d.ts +3 -0
  106. package/dist/components/checkout/shipping-step-form.js +53 -0
  107. package/dist/components/checkout/shipping-step-form.js.map +1 -0
  108. package/dist/components/index.d.ts +8 -0
  109. package/dist/components/index.js +9 -0
  110. package/dist/components/index.js.map +1 -0
  111. package/dist/components/item/product-card.d.ts +7 -0
  112. package/dist/components/item/product-card.js +9 -0
  113. package/dist/components/item/product-card.js.map +1 -0
  114. package/dist/components/item-selector/button.d.ts +4 -0
  115. package/dist/components/item-selector/button.js +47 -0
  116. package/dist/components/item-selector/button.js.map +1 -0
  117. package/dist/components/item-selector/carousel/index.d.ts +12 -0
  118. package/dist/components/item-selector/carousel/index.js +74 -0
  119. package/dist/components/item-selector/carousel/index.js.map +1 -0
  120. package/dist/components/item-selector/carousel/slider.d.ts +8 -0
  121. package/dist/components/item-selector/carousel/slider.js +12 -0
  122. package/dist/components/item-selector/carousel/slider.js.map +1 -0
  123. package/dist/components/item-selector/index.d.ts +2 -0
  124. package/dist/components/item-selector/index.js +3 -0
  125. package/dist/components/item-selector/index.js.map +1 -0
  126. package/dist/components/item-selector/quantity-indicator.d.ts +9 -0
  127. package/dist/components/item-selector/quantity-indicator.js +16 -0
  128. package/dist/components/item-selector/quantity-indicator.js.map +1 -0
  129. package/dist/components/node-tabs/index.d.ts +14 -0
  130. package/dist/components/node-tabs/index.js +42 -0
  131. package/dist/components/node-tabs/index.js.map +1 -0
  132. package/dist/components/node-tabs/node-image.d.ts +6 -0
  133. package/dist/components/node-tabs/node-image.js +13 -0
  134. package/dist/components/node-tabs/node-image.js.map +1 -0
  135. package/dist/index.d.ts +9 -0
  136. package/dist/index.js +9 -0
  137. package/dist/index.js.map +1 -0
  138. package/dist/metering.d.ts +162 -0
  139. package/dist/metering.js +204 -0
  140. package/dist/metering.js.map +1 -0
  141. package/dist/metering.test.d.ts +13 -0
  142. package/dist/metering.test.js +181 -0
  143. package/dist/metering.test.js.map +1 -0
  144. package/dist/service/context.d.ts +8 -0
  145. package/dist/service/context.js +19 -0
  146. package/dist/service/context.js.map +1 -0
  147. package/dist/service/debug.d.ts +10 -0
  148. package/dist/service/debug.js +30 -0
  149. package/dist/service/debug.js.map +1 -0
  150. package/dist/service/impls/standalone/actual-line-item.d.ts +40 -0
  151. package/dist/service/impls/standalone/actual-line-item.js +84 -0
  152. package/dist/service/impls/standalone/actual-line-item.js.map +1 -0
  153. package/dist/service/impls/standalone/get-instance.d.ts +2 -0
  154. package/dist/service/impls/standalone/get-instance.js +39 -0
  155. package/dist/service/impls/standalone/get-instance.js.map +1 -0
  156. package/dist/service/impls/standalone/index.d.ts +67 -0
  157. package/dist/service/impls/standalone/index.js +416 -0
  158. package/dist/service/impls/standalone/index.js.map +1 -0
  159. package/dist/service/impls/standalone/order/firebase.d.ts +6 -0
  160. package/dist/service/impls/standalone/order/firebase.js +6 -0
  161. package/dist/service/impls/standalone/order/firebase.js.map +1 -0
  162. package/dist/service/impls/standalone/order/index.d.ts +30 -0
  163. package/dist/service/impls/standalone/order/index.js +21 -0
  164. package/dist/service/impls/standalone/order/index.js.map +1 -0
  165. package/dist/service/impls/standalone/persistence.d.ts +4 -0
  166. package/dist/service/impls/standalone/persistence.js +22 -0
  167. package/dist/service/impls/standalone/persistence.js.map +1 -0
  168. package/dist/service/path-utils.d.ts +7 -0
  169. package/dist/service/path-utils.js +16 -0
  170. package/dist/service/path-utils.js.map +1 -0
  171. package/dist/service/sep.d.ts +6 -0
  172. package/dist/service/sep.js +6 -0
  173. package/dist/service/sep.js.map +1 -0
  174. package/dist/types/category-node.d.ts +36 -0
  175. package/dist/types/category-node.js +2 -0
  176. package/dist/types/category-node.js.map +1 -0
  177. package/dist/types/checkout.d.ts +33 -0
  178. package/dist/types/checkout.js +2 -0
  179. package/dist/types/checkout.js.map +1 -0
  180. package/dist/types/commerce-config.d.ts +11 -0
  181. package/dist/types/commerce-config.js +2 -0
  182. package/dist/types/commerce-config.js.map +1 -0
  183. package/dist/types/commerce-service.d.ts +109 -0
  184. package/dist/types/commerce-service.js +2 -0
  185. package/dist/types/commerce-service.js.map +1 -0
  186. package/dist/types/family.d.ts +16 -0
  187. package/dist/types/family.js +2 -0
  188. package/dist/types/family.js.map +1 -0
  189. package/dist/types/index.d.ts +13 -0
  190. package/dist/types/index.js +8 -0
  191. package/dist/types/index.js.map +1 -0
  192. package/dist/types/item-selector.d.ts +72 -0
  193. package/dist/types/item-selector.js +2 -0
  194. package/dist/types/item-selector.js.map +1 -0
  195. package/dist/types/line-item.d.ts +14 -0
  196. package/dist/types/line-item.js +2 -0
  197. package/dist/types/line-item.js.map +1 -0
  198. package/dist/types/multi-family-selector-props.d.ts +16 -0
  199. package/dist/types/multi-family-selector-props.js +2 -0
  200. package/dist/types/multi-family-selector-props.js.map +1 -0
  201. package/dist/types/product.d.ts +15 -0
  202. package/dist/types/product.js +2 -0
  203. package/dist/types/product.js.map +1 -0
  204. package/dist/types/promo.d.ts +7 -0
  205. package/dist/types/promo.js +2 -0
  206. package/dist/types/promo.js.map +1 -0
  207. package/dist/types/selection-ui-specifier.d.ts +40 -0
  208. package/dist/types/selection-ui-specifier.js +2 -0
  209. package/dist/types/selection-ui-specifier.js.map +1 -0
  210. package/dist/types/string-mutator.d.ts +9 -0
  211. package/dist/types/string-mutator.js +2 -0
  212. package/dist/types/string-mutator.js.map +1 -0
  213. package/dist/types/token-separators.d.ts +6 -0
  214. package/dist/types/token-separators.js +2 -0
  215. package/dist/types/token-separators.js.map +1 -0
  216. package/dist/util/analytics.d.ts +9 -0
  217. package/dist/util/analytics.js +10 -0
  218. package/dist/util/analytics.js.map +1 -0
  219. package/dist/util/countries.d.ts +7 -0
  220. package/dist/util/countries.js +197 -0
  221. package/dist/util/countries.js.map +1 -0
  222. package/dist/util/error.d.ts +1 -0
  223. package/dist/util/error.js +22 -0
  224. package/dist/util/error.js.map +1 -0
  225. package/dist/util/index.d.ts +15 -0
  226. package/dist/util/index.js +54 -0
  227. package/dist/util/index.js.map +1 -0
  228. package/dist/util/item-selector-options-accessor.d.ts +3 -0
  229. package/dist/util/item-selector-options-accessor.js +27 -0
  230. package/dist/util/item-selector-options-accessor.js.map +1 -0
  231. package/dist/util/line-item-ref.d.ts +8 -0
  232. package/dist/util/line-item-ref.js +15 -0
  233. package/dist/util/line-item-ref.js.map +1 -0
  234. package/dist/util/multi-family-selector-options-accessor.d.ts +3 -0
  235. package/dist/util/multi-family-selector-options-accessor.js +11 -0
  236. package/dist/util/multi-family-selector-options-accessor.js.map +1 -0
  237. package/dist/util/obs-string-mutator.d.ts +8 -0
  238. package/dist/util/obs-string-mutator.js +15 -0
  239. package/dist/util/obs-string-mutator.js.map +1 -0
  240. package/dist/util/product-media-accessor.d.ts +29 -0
  241. package/dist/util/product-media-accessor.js +22 -0
  242. package/dist/util/product-media-accessor.js.map +1 -0
  243. package/dist/util/promo-codes.d.ts +3 -0
  244. package/dist/util/promo-codes.js +100 -0
  245. package/dist/util/promo-codes.js.map +1 -0
  246. package/dist/util/selection-ui-specifiers.d.ts +3 -0
  247. package/dist/util/selection-ui-specifiers.js +24 -0
  248. package/dist/util/selection-ui-specifiers.js.map +1 -0
  249. package/dist/util/square-payment.d.ts +7 -0
  250. package/dist/util/square-payment.js +37 -0
  251. package/dist/util/square-payment.js.map +1 -0
  252. package/dist/util/use-sync-sku-param-w-current-item.d.ts +2 -0
  253. package/dist/util/use-sync-sku-param-w-current-item.js +61 -0
  254. package/dist/util/use-sync-sku-param-w-current-item.js.map +1 -0
  255. package/index.ts +18 -1
  256. package/metering.test.ts +199 -0
  257. package/metering.ts +289 -0
  258. package/package.json +18 -16
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 hanzo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/client.ts CHANGED
@@ -67,6 +67,29 @@ export type Balance = {
67
67
  available: number
68
68
  }
69
69
 
70
+ /**
71
+ * Tier-aware balance from GET /v1/billing/tier. effectiveAvailable folds the
72
+ * tenant's included plan allotment (e.g. the free-tier daily credit) into the
73
+ * prepaid available balance — gate on this to honor included usage first.
74
+ */
75
+ export type TierResponse = {
76
+ user: string
77
+ tier: {
78
+ name: string
79
+ displayName?: string
80
+ maxAgents?: number
81
+ unlimitedAgents?: boolean
82
+ dailyCreditsCents?: number
83
+ allowedModels?: string[]
84
+ }
85
+ balance: {
86
+ currency: string
87
+ prepaidAvailable: number
88
+ dailyRemaining: number
89
+ effectiveAvailable: number
90
+ }
91
+ }
92
+
70
93
  export type Transaction = {
71
94
  id?: string
72
95
  owner?: string
@@ -270,6 +293,17 @@ export type PaymentMethod = {
270
293
  expMonth: number
271
294
  expYear: number
272
295
  }
296
+ bank_account?: {
297
+ bankName?: string
298
+ last4?: string
299
+ accountType?: 'checking' | 'savings'
300
+ routingNumber?: string
301
+ }
302
+ crypto?: {
303
+ chain: string
304
+ address: string
305
+ label?: string
306
+ }
273
307
  providerRef?: string
274
308
  providerType?: string
275
309
  createdAt?: string
@@ -349,6 +383,8 @@ export class Commerce {
349
383
  body?: unknown
350
384
  token?: string
351
385
  params?: Record<string, string>
386
+ /** Extra request headers, e.g. X-IAM-Org-Id for S2S calls. */
387
+ headers?: Record<string, string>
352
388
  },
353
389
  ): Promise<T> {
354
390
  const url = new URL(path, this.baseUrl)
@@ -365,6 +401,7 @@ export class Commerce {
365
401
  const authToken = opts?.token ?? this.token
366
402
  if (authToken) headers['Authorization'] = `Bearer ${authToken}`
367
403
  if (opts?.body) headers['Content-Type'] = 'application/json'
404
+ if (opts?.headers) Object.assign(headers, opts.headers)
368
405
 
369
406
  try {
370
407
  const res = await fetch(url.toString(), {
@@ -389,30 +426,42 @@ export class Commerce {
389
426
  // Balance
390
427
  // -----------------------------------------------------------------------
391
428
 
392
- async getBalance(user: string, currency = 'usd', token?: string): Promise<Balance> {
393
- return this.request<Balance>('/api/v1/billing/balance', {
394
- params: { user, currency }, token,
429
+ async getBalance(user: string, currency = 'usd', token?: string, headers?: Record<string, string>): Promise<Balance> {
430
+ return this.request<Balance>('/v1/billing/balance', {
431
+ params: { user, currency }, token, headers,
395
432
  })
396
433
  }
397
434
 
398
435
  async getAllBalances(user: string, token?: string): Promise<Record<string, Balance>> {
399
- return this.request<Record<string, Balance>>('/api/v1/billing/balance/all', {
436
+ return this.request<Record<string, Balance>>('/v1/billing/balance/all', {
400
437
  params: { user }, token,
401
438
  })
402
439
  }
403
440
 
441
+ /**
442
+ * Tier-aware balance: prepaid available plus the tenant's included plan
443
+ * allotment (effectiveAvailable). Use this for the metering gate when you
444
+ * want included usage (e.g. free-tier daily credit) honored before prepaid
445
+ * funds are drawn down.
446
+ */
447
+ async getTier(user: string, opts?: { token?: string; headers?: Record<string, string> }): Promise<TierResponse> {
448
+ return this.request<TierResponse>('/v1/billing/tier', {
449
+ params: { user }, token: opts?.token, headers: opts?.headers,
450
+ })
451
+ }
452
+
404
453
  // -----------------------------------------------------------------------
405
454
  // Usage
406
455
  // -----------------------------------------------------------------------
407
456
 
408
- async addUsageRecord(record: UsageRecord, token?: string): Promise<Transaction> {
409
- return this.request<Transaction>('/api/v1/billing/usage', {
410
- method: 'POST', body: record, token,
457
+ async addUsageRecord(record: UsageRecord, token?: string, headers?: Record<string, string>): Promise<Transaction> {
458
+ return this.request<Transaction>('/v1/billing/usage', {
459
+ method: 'POST', body: record, token, headers,
411
460
  })
412
461
  }
413
462
 
414
463
  async getUsageRecords(user: string, currency = 'usd', token?: string): Promise<Transaction[]> {
415
- return this.request<Transaction[]>('/api/v1/billing/usage', {
464
+ return this.request<Transaction[]>('/v1/billing/usage', {
416
465
  params: { user, currency }, token,
417
466
  })
418
467
  }
@@ -425,13 +474,13 @@ export class Commerce {
425
474
  params: { user: string; currency?: string; amount: number; notes?: string; tags?: string[]; expiresIn?: string },
426
475
  token?: string,
427
476
  ): Promise<Transaction> {
428
- return this.request<Transaction>('/api/v1/billing/deposit', {
477
+ return this.request<Transaction>('/v1/billing/deposit', {
429
478
  method: 'POST', body: params, token,
430
479
  })
431
480
  }
432
481
 
433
482
  async grantStarterCredit(user: string, token?: string): Promise<Transaction> {
434
- return this.request<Transaction>('/api/v1/billing/credit', {
483
+ return this.request<Transaction>('/v1/billing/credit', {
435
484
  method: 'POST', body: { user }, token,
436
485
  })
437
486
  }
@@ -441,12 +490,12 @@ export class Commerce {
441
490
  // -----------------------------------------------------------------------
442
491
 
443
492
  async getPlans(token?: string): Promise<Plan[]> {
444
- return this.request<Plan[]>('/api/v1/billing/plans', { token })
493
+ return this.request<Plan[]>('/v1/billing/plans', { token })
445
494
  }
446
495
 
447
496
  async getPlan(planId: string, token?: string): Promise<Plan | null> {
448
497
  try {
449
- return await this.request<Plan>(`/api/v1/billing/plans/${planId}`, { token })
498
+ return await this.request<Plan>(`/v1/billing/plans/${planId}`, { token })
450
499
  } catch { return null }
451
500
  }
452
501
 
@@ -458,37 +507,37 @@ export class Commerce {
458
507
  params: { planId: string; userId?: string; customerId?: string; paymentMethodId?: string; couponCode?: string; trialDays?: number },
459
508
  token?: string,
460
509
  ): Promise<Subscription> {
461
- return this.request<Subscription>('/api/v1/billing/subscriptions', {
510
+ return this.request<Subscription>('/v1/billing/subscriptions', {
462
511
  method: 'POST', body: params, token,
463
512
  })
464
513
  }
465
514
 
466
515
  async getSubscription(subscriptionId: string, token?: string): Promise<Subscription | null> {
467
516
  try {
468
- return await this.request<Subscription>(`/api/v1/billing/subscriptions/${subscriptionId}`, { token })
517
+ return await this.request<Subscription>(`/v1/billing/subscriptions/${subscriptionId}`, { token })
469
518
  } catch { return null }
470
519
  }
471
520
 
472
521
  async listSubscriptions(params?: { customerId?: string }, token?: string): Promise<Subscription[]> {
473
- return this.request<Subscription[]>('/api/v1/billing/subscriptions', {
522
+ return this.request<Subscription[]>('/v1/billing/subscriptions', {
474
523
  params: params as Record<string, string> | undefined, token,
475
524
  })
476
525
  }
477
526
 
478
527
  async updateSubscription(subscriptionId: string, update: Partial<Subscription>, token?: string): Promise<Subscription> {
479
- return this.request<Subscription>(`/api/v1/billing/subscriptions/${subscriptionId}`, {
528
+ return this.request<Subscription>(`/v1/billing/subscriptions/${subscriptionId}`, {
480
529
  method: 'PATCH', body: update, token,
481
530
  })
482
531
  }
483
532
 
484
533
  async cancelSubscription(subscriptionId: string, immediately = false, token?: string): Promise<Subscription> {
485
- return this.request<Subscription>(`/api/v1/billing/subscriptions/${subscriptionId}/cancel`, {
534
+ return this.request<Subscription>(`/v1/billing/subscriptions/${subscriptionId}/cancel`, {
486
535
  method: 'POST', body: { immediately }, token,
487
536
  })
488
537
  }
489
538
 
490
539
  async reactivateSubscription(subscriptionId: string, token?: string): Promise<Subscription> {
491
- return this.request<Subscription>(`/api/v1/billing/subscriptions/${subscriptionId}/reactivate`, {
540
+ return this.request<Subscription>(`/v1/billing/subscriptions/${subscriptionId}/reactivate`, {
492
541
  method: 'POST', token,
493
542
  })
494
543
  }
@@ -506,7 +555,7 @@ export class Commerce {
506
555
  params: CheckoutSessionRequest,
507
556
  token?: string,
508
557
  ): Promise<CheckoutSessionResponse> {
509
- return this.request<CheckoutSessionResponse>('/api/v1/checkout/sessions', {
558
+ return this.request<CheckoutSessionResponse>('/v1/checkout/sessions', {
510
559
  method: 'POST', body: params, token,
511
560
  })
512
561
  }
@@ -522,7 +571,7 @@ export class Commerce {
522
571
  * tokenizes via the configured payment provider (Stripe).
523
572
  */
524
573
  async tokenizeCard(card: CardTokenizeRequest, token?: string): Promise<CardTokenizeResult> {
525
- return this.request<CardTokenizeResult>('/api/v1/billing/card/tokenize', {
574
+ return this.request<CardTokenizeResult>('/v1/billing/card/tokenize', {
526
575
  method: 'POST',
527
576
  body: {
528
577
  number: card.number.replace(/\s/g, ''),
@@ -550,25 +599,25 @@ export class Commerce {
550
599
  },
551
600
  token?: string,
552
601
  ): Promise<PaymentMethod> {
553
- return this.request<PaymentMethod>('/api/v1/billing/payment-methods', {
602
+ return this.request<PaymentMethod>('/v1/billing/payment-methods', {
554
603
  method: 'POST', body: params, token,
555
604
  })
556
605
  }
557
606
 
558
607
  async listPaymentMethods(customerId: string, token?: string): Promise<PaymentMethod[]> {
559
- return this.request<PaymentMethod[]>('/api/v1/billing/payment-methods', {
608
+ return this.request<PaymentMethod[]>('/v1/billing/payment-methods', {
560
609
  params: { customerId }, token,
561
610
  })
562
611
  }
563
612
 
564
613
  async removePaymentMethod(paymentMethodId: string, token?: string): Promise<void> {
565
- await this.request<void>(`/api/v1/billing/payment-methods/${paymentMethodId}`, {
614
+ await this.request<void>(`/v1/billing/payment-methods/${paymentMethodId}`, {
566
615
  method: 'DELETE', token,
567
616
  })
568
617
  }
569
618
 
570
619
  async setDefaultPaymentMethod(customerId: string, paymentMethodId: string, token?: string): Promise<PaymentMethod> {
571
- return this.request<PaymentMethod>(`/api/v1/billing/customers/${customerId}/default-payment-method`, {
620
+ return this.request<PaymentMethod>(`/v1/billing/customers/${customerId}/default-payment-method`, {
572
621
  method: 'POST', body: { paymentMethodId }, token,
573
622
  })
574
623
  }
@@ -583,7 +632,7 @@ export class Commerce {
583
632
  */
584
633
  async validateCoupon(code: string, subtotalCents?: number, token?: string): Promise<CouponValidateResult> {
585
634
  try {
586
- const result = await this.request<Coupon>('/api/v1/coupon/validate', {
635
+ const result = await this.request<Coupon>('/v1/coupon/validate', {
587
636
  method: 'POST',
588
637
  body: { code: code.toUpperCase().trim(), subtotalCents },
589
638
  token,
@@ -599,7 +648,7 @@ export class Commerce {
599
648
  * Redeem a coupon for a user. Creates credit grant records.
600
649
  */
601
650
  async redeemCoupon(code: string, userId: string, token?: string): Promise<CreditGrant[]> {
602
- return this.request<CreditGrant[]>('/api/v1/coupon/redeem', {
651
+ return this.request<CreditGrant[]>('/v1/coupon/redeem', {
603
652
  method: 'POST',
604
653
  body: { code: code.toUpperCase().trim(), userId },
605
654
  token,
@@ -615,17 +664,17 @@ export class Commerce {
615
664
  * Returns the referral code/link the user can share.
616
665
  */
617
666
  async getOrCreateReferrer(userId: string, token?: string): Promise<Referrer> {
618
- return this.request<Referrer>('/api/v1/referrer', {
667
+ return this.request<Referrer>('/v1/referrer', {
619
668
  method: 'POST', body: { userId }, token,
620
669
  })
621
670
  }
622
671
 
623
672
  async getReferrals(userId: string, token?: string): Promise<Referral[]> {
624
- return this.request<Referral[]>(`/api/v1/user/${userId}/referrals`, { token })
673
+ return this.request<Referral[]>(`/v1/user/${userId}/referrals`, { token })
625
674
  }
626
675
 
627
676
  async getReferrers(userId: string, token?: string): Promise<Referrer[]> {
628
- return this.request<Referrer[]>(`/api/v1/user/${userId}/referrers`, { token })
677
+ return this.request<Referrer[]>(`/v1/user/${userId}/referrers`, { token })
629
678
  }
630
679
 
631
680
  /**
@@ -633,7 +682,7 @@ export class Commerce {
633
682
  */
634
683
  async getAffiliate(userId: string, token?: string): Promise<Affiliate | null> {
635
684
  try {
636
- return await this.request<Affiliate>(`/api/v1/user/${userId}/affiliate`, { token })
685
+ return await this.request<Affiliate>(`/v1/user/${userId}/affiliate`, { token })
637
686
  } catch { return null }
638
687
  }
639
688
 
@@ -642,21 +691,21 @@ export class Commerce {
642
691
  * After creation, user can connect their bank via the returnedconnectUrl.
643
692
  */
644
693
  async createAffiliate(userId: string, token?: string): Promise<Affiliate> {
645
- return this.request<Affiliate>('/api/v1/affiliate', {
694
+ return this.request<Affiliate>('/v1/affiliate', {
646
695
  method: 'POST', body: { userId }, token,
647
696
  })
648
697
  }
649
698
 
650
699
  async getAffiliateReferrals(affiliateId: string, token?: string): Promise<Referral[]> {
651
- return this.request<Referral[]>(`/api/v1/affiliate/${affiliateId}/referrals`, { token })
700
+ return this.request<Referral[]>(`/v1/affiliate/${affiliateId}/referrals`, { token })
652
701
  }
653
702
 
654
703
  async getAffiliateOrders(affiliateId: string, token?: string): Promise<unknown[]> {
655
- return this.request<unknown[]>(`/api/v1/affiliate/${affiliateId}/orders`, { token })
704
+ return this.request<unknown[]>(`/v1/affiliate/${affiliateId}/orders`, { token })
656
705
  }
657
706
 
658
707
  async getAffiliateTransactions(affiliateId: string, token?: string): Promise<Transaction[]> {
659
- return this.request<Transaction[]>(`/api/v1/affiliate/${affiliateId}/transactions`, { token })
708
+ return this.request<Transaction[]>(`/v1/affiliate/${affiliateId}/transactions`, { token })
660
709
  }
661
710
 
662
711
  // -----------------------------------------------------------------------
@@ -664,29 +713,96 @@ export class Commerce {
664
713
  // -----------------------------------------------------------------------
665
714
 
666
715
  async authorize(orderId: string, token?: string): Promise<Payment> {
667
- return this.request<Payment>(`/api/v1/authorize/${orderId}`, { method: 'POST', token })
716
+ return this.request<Payment>(`/v1/authorize/${orderId}`, { method: 'POST', token })
668
717
  }
669
718
 
670
719
  async capture(orderId: string, token?: string): Promise<Payment> {
671
- return this.request<Payment>(`/api/v1/capture/${orderId}`, { method: 'POST', token })
720
+ return this.request<Payment>(`/v1/capture/${orderId}`, { method: 'POST', token })
672
721
  }
673
722
 
674
723
  async charge(orderId: string, token?: string): Promise<Payment> {
675
- return this.request<Payment>(`/api/v1/charge/${orderId}`, { method: 'POST', token })
724
+ return this.request<Payment>(`/v1/charge/${orderId}`, { method: 'POST', token })
676
725
  }
677
726
 
678
727
  async refund(paymentId: string, token?: string): Promise<Payment> {
679
- return this.request<Payment>(`/api/v1/refund/${paymentId}`, { method: 'POST', token })
728
+ return this.request<Payment>(`/v1/refund/${paymentId}`, { method: 'POST', token })
680
729
  }
681
730
 
682
731
  async billingRefund(
683
732
  params: { user: string; amount: number; originalTransactionId: string; currency?: string; notes?: string },
684
733
  token?: string,
685
734
  ): Promise<Transaction> {
686
- return this.request<Transaction>('/api/v1/billing/refund', {
735
+ return this.request<Transaction>('/v1/billing/refund', {
687
736
  method: 'POST', body: params, token,
688
737
  })
689
738
  }
739
+
740
+ // -----------------------------------------------------------------------
741
+ // Crypto wallet deposit address
742
+ // -----------------------------------------------------------------------
743
+
744
+ /**
745
+ * Get or create a deposit address for a given chain.
746
+ * Used for crypto top-up — user sends funds to this address.
747
+ */
748
+ async getWalletAddress(params: { chain: string; userId: string }, token?: string): Promise<{ address: string; chain: string; qrCode?: string }> {
749
+ return this.request<{ address: string; chain: string; qrCode?: string }>('/api/wallet/account', {
750
+ method: 'POST',
751
+ body: { name: `${params.userId}-${params.chain}`, blockchainType: params.chain },
752
+ token,
753
+ })
754
+ }
755
+
756
+ // -----------------------------------------------------------------------
757
+ // Bank account (ACH) and crypto payment methods
758
+ // -----------------------------------------------------------------------
759
+
760
+ /**
761
+ * Add a bank account payment method (ACH).
762
+ * plaidToken from Plaid Link or Square bank OAuth.
763
+ */
764
+ async addBankAccount(
765
+ params: {
766
+ customerId: string
767
+ plaidToken?: string // Plaid public token
768
+ bankName?: string
769
+ accountType?: 'checking' | 'savings'
770
+ },
771
+ token?: string,
772
+ ): Promise<PaymentMethod> {
773
+ return this.request<PaymentMethod>('/v1/billing/payment-methods', {
774
+ method: 'POST',
775
+ body: { customerId: params.customerId, type: 'bank_account', plaidToken: params.plaidToken, bankName: params.bankName, accountType: params.accountType },
776
+ token,
777
+ })
778
+ }
779
+
780
+ async addCryptoWallet(
781
+ params: { customerId: string; chain: string; address: string; label?: string },
782
+ token?: string,
783
+ ): Promise<PaymentMethod> {
784
+ return this.request<PaymentMethod>('/v1/billing/payment-methods', {
785
+ method: 'POST',
786
+ body: { customerId: params.customerId, type: 'crypto', chain: params.chain, address: params.address, label: params.label },
787
+ token,
788
+ })
789
+ }
790
+
791
+ // -----------------------------------------------------------------------
792
+ // Top-up
793
+ // -----------------------------------------------------------------------
794
+
795
+ /**
796
+ * Convenience: charge a saved payment method and deposit credits.
797
+ * amount is in cents.
798
+ */
799
+ async topup(params: { userId: string; paymentMethodId: string; amountCents: number; currency?: string }, token?: string): Promise<Transaction> {
800
+ return this.request<Transaction>('/v1/billing/topup', {
801
+ method: 'POST',
802
+ body: params,
803
+ token,
804
+ })
805
+ }
690
806
  }
691
807
 
692
808
  // ---------------------------------------------------------------------------
@@ -0,0 +1,2 @@
1
+ /** @hanzo/commerce/billing — re-exports from @hanzo/commerce/client */
2
+ export * from './client';
@@ -0,0 +1,3 @@
1
+ /** @hanzo/commerce/billing — re-exports from @hanzo/commerce/client */
2
+ export * from './client';
3
+ //# sourceMappingURL=billing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"billing.js","sourceRoot":"","sources":["../billing.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,cAAc,UAAU,CAAA"}