@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.
- package/LICENSE.md +21 -0
- package/client.ts +155 -39
- package/dist/billing.d.ts +2 -0
- package/dist/billing.js +3 -0
- package/dist/billing.js.map +1 -0
- package/dist/client.d.ts +464 -0
- package/dist/client.js +424 -0
- package/dist/client.js.map +1 -0
- package/dist/components/Icons.d.ts +18 -0
- package/dist/components/Icons.js +19 -0
- package/dist/components/Icons.js.map +1 -0
- package/dist/components/add-to-cart-widget.d.ts +11 -0
- package/dist/components/add-to-cart-widget.js +85 -0
- package/dist/components/add-to-cart-widget.js.map +1 -0
- package/dist/components/buy/buy-card.d.ts +30 -0
- package/dist/components/buy/buy-card.js +109 -0
- package/dist/components/buy/buy-card.js.map +1 -0
- package/dist/components/buy/carousel-buy-card.d.ts +12 -0
- package/dist/components/buy/carousel-buy-card.js +94 -0
- package/dist/components/buy/carousel-buy-card.js.map +1 -0
- package/dist/components/buy/multi-family/all-variants-carousel.d.ts +4 -0
- package/dist/components/buy/multi-family/all-variants-carousel.js +115 -0
- package/dist/components/buy/multi-family/all-variants-carousel.js.map +1 -0
- package/dist/components/buy/multi-family/family-carousel/index.d.ts +4 -0
- package/dist/components/buy/multi-family/family-carousel/index.js +27 -0
- package/dist/components/buy/multi-family/family-carousel/index.js.map +1 -0
- package/dist/components/buy/multi-family/family-carousel/slide.d.ts +11 -0
- package/dist/components/buy/multi-family/family-carousel/slide.js +35 -0
- package/dist/components/buy/multi-family/family-carousel/slide.js.map +1 -0
- package/dist/components/buy/multi-family/family-carousel/state.d.ts +20 -0
- package/dist/components/buy/multi-family/family-carousel/state.js +59 -0
- package/dist/components/buy/multi-family/family-carousel/state.js.map +1 -0
- package/dist/components/buy/multi-family/index.d.ts +2 -0
- package/dist/components/buy/multi-family/index.js +3 -0
- package/dist/components/buy/multi-family/index.js.map +1 -0
- package/dist/components/buy/single-family-selector.d.ts +15 -0
- package/dist/components/buy/single-family-selector.js +28 -0
- package/dist/components/buy/single-family-selector.js.map +1 -0
- package/dist/components/buy/title-and-byline.d.ts +8 -0
- package/dist/components/buy/title-and-byline.js +7 -0
- package/dist/components/buy/title-and-byline.js.map +1 -0
- package/dist/components/cart/cart-panel/cart-line-item.d.ts +11 -0
- package/dist/components/cart/cart-panel/cart-line-item.js +25 -0
- package/dist/components/cart/cart-panel/cart-line-item.js.map +1 -0
- package/dist/components/cart/cart-panel/index.d.ts +19 -0
- package/dist/components/cart/cart-panel/index.js +65 -0
- package/dist/components/cart/cart-panel/index.js.map +1 -0
- package/dist/components/cart/cart-panel/promo-code.d.ts +4 -0
- package/dist/components/cart/cart-panel/promo-code.js +62 -0
- package/dist/components/cart/cart-panel/promo-code.js.map +1 -0
- package/dist/components/cart/cart-panel/total-area.d.ts +7 -0
- package/dist/components/cart/cart-panel/total-area.js +14 -0
- package/dist/components/cart/cart-panel/total-area.js.map +1 -0
- package/dist/components/checkout/payment-step-form/card-icon-row.d.ts +2 -0
- package/dist/components/checkout/payment-step-form/card-icon-row.js +14 -0
- package/dist/components/checkout/payment-step-form/card-icon-row.js.map +1 -0
- package/dist/components/checkout/payment-step-form/card-icons/amex.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/card-icons/amex.js +6 -0
- package/dist/components/checkout/payment-step-form/card-icons/amex.js.map +1 -0
- package/dist/components/checkout/payment-step-form/card-icons/diners-club.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/card-icons/diners-club.js +6 -0
- package/dist/components/checkout/payment-step-form/card-icons/diners-club.js.map +1 -0
- package/dist/components/checkout/payment-step-form/card-icons/discover.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/card-icons/discover.js +6 -0
- package/dist/components/checkout/payment-step-form/card-icons/discover.js.map +1 -0
- package/dist/components/checkout/payment-step-form/card-icons/jcb.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/card-icons/jcb.js +6 -0
- package/dist/components/checkout/payment-step-form/card-icons/jcb.js.map +1 -0
- package/dist/components/checkout/payment-step-form/card-icons/mastercard.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/card-icons/mastercard.js +6 -0
- package/dist/components/checkout/payment-step-form/card-icons/mastercard.js.map +1 -0
- package/dist/components/checkout/payment-step-form/card-icons/visa.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/card-icons/visa.js +6 -0
- package/dist/components/checkout/payment-step-form/card-icons/visa.js.map +1 -0
- package/dist/components/checkout/payment-step-form/cc-button.d.ts +3 -0
- package/dist/components/checkout/payment-step-form/cc-button.js +6 -0
- package/dist/components/checkout/payment-step-form/cc-button.js.map +1 -0
- package/dist/components/checkout/payment-step-form/contact-form.d.ts +5 -0
- package/dist/components/checkout/payment-step-form/contact-form.js +6 -0
- package/dist/components/checkout/payment-step-form/contact-form.js.map +1 -0
- package/dist/components/checkout/payment-step-form/crypto-icons/btc.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/crypto-icons/btc.js +6 -0
- package/dist/components/checkout/payment-step-form/crypto-icons/btc.js.map +1 -0
- package/dist/components/checkout/payment-step-form/crypto-icons/eth.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/crypto-icons/eth.js +6 -0
- package/dist/components/checkout/payment-step-form/crypto-icons/eth.js.map +1 -0
- package/dist/components/checkout/payment-step-form/crypto-icons/usdt.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/crypto-icons/usdt.js +6 -0
- package/dist/components/checkout/payment-step-form/crypto-icons/usdt.js.map +1 -0
- package/dist/components/checkout/payment-step-form/index.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/index.js +66 -0
- package/dist/components/checkout/payment-step-form/index.js.map +1 -0
- package/dist/components/checkout/payment-step-form/methods/bank-transfer.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/methods/bank-transfer.js +24 -0
- package/dist/components/checkout/payment-step-form/methods/bank-transfer.js.map +1 -0
- package/dist/components/checkout/payment-step-form/methods/card.d.ts +4 -0
- package/dist/components/checkout/payment-step-form/methods/card.js +160 -0
- package/dist/components/checkout/payment-step-form/methods/card.js.map +1 -0
- package/dist/components/checkout/payment-step-form/methods/crypto.d.ts +9 -0
- package/dist/components/checkout/payment-step-form/methods/crypto.js +137 -0
- package/dist/components/checkout/payment-step-form/methods/crypto.js.map +1 -0
- package/dist/components/checkout/payment-step-form/methods/index.d.ts +6 -0
- package/dist/components/checkout/payment-step-form/methods/index.js +21 -0
- package/dist/components/checkout/payment-step-form/methods/index.js.map +1 -0
- package/dist/components/checkout/shipping-step-form.d.ts +3 -0
- package/dist/components/checkout/shipping-step-form.js +53 -0
- package/dist/components/checkout/shipping-step-form.js.map +1 -0
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.js +9 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/item/product-card.d.ts +7 -0
- package/dist/components/item/product-card.js +9 -0
- package/dist/components/item/product-card.js.map +1 -0
- package/dist/components/item-selector/button.d.ts +4 -0
- package/dist/components/item-selector/button.js +47 -0
- package/dist/components/item-selector/button.js.map +1 -0
- package/dist/components/item-selector/carousel/index.d.ts +12 -0
- package/dist/components/item-selector/carousel/index.js +74 -0
- package/dist/components/item-selector/carousel/index.js.map +1 -0
- package/dist/components/item-selector/carousel/slider.d.ts +8 -0
- package/dist/components/item-selector/carousel/slider.js +12 -0
- package/dist/components/item-selector/carousel/slider.js.map +1 -0
- package/dist/components/item-selector/index.d.ts +2 -0
- package/dist/components/item-selector/index.js +3 -0
- package/dist/components/item-selector/index.js.map +1 -0
- package/dist/components/item-selector/quantity-indicator.d.ts +9 -0
- package/dist/components/item-selector/quantity-indicator.js +16 -0
- package/dist/components/item-selector/quantity-indicator.js.map +1 -0
- package/dist/components/node-tabs/index.d.ts +14 -0
- package/dist/components/node-tabs/index.js +42 -0
- package/dist/components/node-tabs/index.js.map +1 -0
- package/dist/components/node-tabs/node-image.d.ts +6 -0
- package/dist/components/node-tabs/node-image.js +13 -0
- package/dist/components/node-tabs/node-image.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/metering.d.ts +162 -0
- package/dist/metering.js +204 -0
- package/dist/metering.js.map +1 -0
- package/dist/metering.test.d.ts +13 -0
- package/dist/metering.test.js +181 -0
- package/dist/metering.test.js.map +1 -0
- package/dist/service/context.d.ts +8 -0
- package/dist/service/context.js +19 -0
- package/dist/service/context.js.map +1 -0
- package/dist/service/debug.d.ts +10 -0
- package/dist/service/debug.js +30 -0
- package/dist/service/debug.js.map +1 -0
- package/dist/service/impls/standalone/actual-line-item.d.ts +40 -0
- package/dist/service/impls/standalone/actual-line-item.js +84 -0
- package/dist/service/impls/standalone/actual-line-item.js.map +1 -0
- package/dist/service/impls/standalone/get-instance.d.ts +2 -0
- package/dist/service/impls/standalone/get-instance.js +39 -0
- package/dist/service/impls/standalone/get-instance.js.map +1 -0
- package/dist/service/impls/standalone/index.d.ts +67 -0
- package/dist/service/impls/standalone/index.js +416 -0
- package/dist/service/impls/standalone/index.js.map +1 -0
- package/dist/service/impls/standalone/order/firebase.d.ts +6 -0
- package/dist/service/impls/standalone/order/firebase.js +6 -0
- package/dist/service/impls/standalone/order/firebase.js.map +1 -0
- package/dist/service/impls/standalone/order/index.d.ts +30 -0
- package/dist/service/impls/standalone/order/index.js +21 -0
- package/dist/service/impls/standalone/order/index.js.map +1 -0
- package/dist/service/impls/standalone/persistence.d.ts +4 -0
- package/dist/service/impls/standalone/persistence.js +22 -0
- package/dist/service/impls/standalone/persistence.js.map +1 -0
- package/dist/service/path-utils.d.ts +7 -0
- package/dist/service/path-utils.js +16 -0
- package/dist/service/path-utils.js.map +1 -0
- package/dist/service/sep.d.ts +6 -0
- package/dist/service/sep.js +6 -0
- package/dist/service/sep.js.map +1 -0
- package/dist/types/category-node.d.ts +36 -0
- package/dist/types/category-node.js +2 -0
- package/dist/types/category-node.js.map +1 -0
- package/dist/types/checkout.d.ts +33 -0
- package/dist/types/checkout.js +2 -0
- package/dist/types/checkout.js.map +1 -0
- package/dist/types/commerce-config.d.ts +11 -0
- package/dist/types/commerce-config.js +2 -0
- package/dist/types/commerce-config.js.map +1 -0
- package/dist/types/commerce-service.d.ts +109 -0
- package/dist/types/commerce-service.js +2 -0
- package/dist/types/commerce-service.js.map +1 -0
- package/dist/types/family.d.ts +16 -0
- package/dist/types/family.js +2 -0
- package/dist/types/family.js.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/item-selector.d.ts +72 -0
- package/dist/types/item-selector.js +2 -0
- package/dist/types/item-selector.js.map +1 -0
- package/dist/types/line-item.d.ts +14 -0
- package/dist/types/line-item.js +2 -0
- package/dist/types/line-item.js.map +1 -0
- package/dist/types/multi-family-selector-props.d.ts +16 -0
- package/dist/types/multi-family-selector-props.js +2 -0
- package/dist/types/multi-family-selector-props.js.map +1 -0
- package/dist/types/product.d.ts +15 -0
- package/dist/types/product.js +2 -0
- package/dist/types/product.js.map +1 -0
- package/dist/types/promo.d.ts +7 -0
- package/dist/types/promo.js +2 -0
- package/dist/types/promo.js.map +1 -0
- package/dist/types/selection-ui-specifier.d.ts +40 -0
- package/dist/types/selection-ui-specifier.js +2 -0
- package/dist/types/selection-ui-specifier.js.map +1 -0
- package/dist/types/string-mutator.d.ts +9 -0
- package/dist/types/string-mutator.js +2 -0
- package/dist/types/string-mutator.js.map +1 -0
- package/dist/types/token-separators.d.ts +6 -0
- package/dist/types/token-separators.js +2 -0
- package/dist/types/token-separators.js.map +1 -0
- package/dist/util/analytics.d.ts +9 -0
- package/dist/util/analytics.js +10 -0
- package/dist/util/analytics.js.map +1 -0
- package/dist/util/countries.d.ts +7 -0
- package/dist/util/countries.js +197 -0
- package/dist/util/countries.js.map +1 -0
- package/dist/util/error.d.ts +1 -0
- package/dist/util/error.js +22 -0
- package/dist/util/error.js.map +1 -0
- package/dist/util/index.d.ts +15 -0
- package/dist/util/index.js +54 -0
- package/dist/util/index.js.map +1 -0
- package/dist/util/item-selector-options-accessor.d.ts +3 -0
- package/dist/util/item-selector-options-accessor.js +27 -0
- package/dist/util/item-selector-options-accessor.js.map +1 -0
- package/dist/util/line-item-ref.d.ts +8 -0
- package/dist/util/line-item-ref.js +15 -0
- package/dist/util/line-item-ref.js.map +1 -0
- package/dist/util/multi-family-selector-options-accessor.d.ts +3 -0
- package/dist/util/multi-family-selector-options-accessor.js +11 -0
- package/dist/util/multi-family-selector-options-accessor.js.map +1 -0
- package/dist/util/obs-string-mutator.d.ts +8 -0
- package/dist/util/obs-string-mutator.js +15 -0
- package/dist/util/obs-string-mutator.js.map +1 -0
- package/dist/util/product-media-accessor.d.ts +29 -0
- package/dist/util/product-media-accessor.js +22 -0
- package/dist/util/product-media-accessor.js.map +1 -0
- package/dist/util/promo-codes.d.ts +3 -0
- package/dist/util/promo-codes.js +100 -0
- package/dist/util/promo-codes.js.map +1 -0
- package/dist/util/selection-ui-specifiers.d.ts +3 -0
- package/dist/util/selection-ui-specifiers.js +24 -0
- package/dist/util/selection-ui-specifiers.js.map +1 -0
- package/dist/util/square-payment.d.ts +7 -0
- package/dist/util/square-payment.js +37 -0
- package/dist/util/square-payment.js.map +1 -0
- package/dist/util/use-sync-sku-param-w-current-item.d.ts +2 -0
- package/dist/util/use-sync-sku-param-w-current-item.js +61 -0
- package/dist/util/use-sync-sku-param-w-current-item.js.map +1 -0
- package/index.ts +18 -1
- package/metering.test.ts +199 -0
- package/metering.ts +289 -0
- 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>('/
|
|
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>>('/
|
|
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>('/
|
|
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[]>('/
|
|
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>('/
|
|
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>('/
|
|
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[]>('/
|
|
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>(`/
|
|
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>('/
|
|
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>(`/
|
|
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[]>('/
|
|
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>(`/
|
|
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>(`/
|
|
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>(`/
|
|
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>('/
|
|
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>('/
|
|
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>('/
|
|
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[]>('/
|
|
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>(`/
|
|
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>(`/
|
|
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>('/
|
|
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[]>('/
|
|
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>('/
|
|
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[]>(`/
|
|
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[]>(`/
|
|
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>(`/
|
|
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>('/
|
|
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[]>(`/
|
|
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[]>(`/
|
|
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[]>(`/
|
|
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>(`/
|
|
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>(`/
|
|
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>(`/
|
|
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>(`/
|
|
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>('/
|
|
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
|
// ---------------------------------------------------------------------------
|
package/dist/billing.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../billing.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,cAAc,UAAU,CAAA"}
|