Skip to content

Commit 95e090b

Browse files
committed
feat(commerce): update commerce client SDK
1 parent 220c53e commit 95e090b

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

pkg/commerce/client.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,13 @@ export class Commerce {
390390
// -----------------------------------------------------------------------
391391

392392
async getBalance(user: string, currency = 'usd', token?: string): Promise<Balance> {
393-
return this.request<Balance>('/api/v1/billing/balance', {
393+
return this.request<Balance>('/v1/billing/balance', {
394394
params: { user, currency }, token,
395395
})
396396
}
397397

398398
async getAllBalances(user: string, token?: string): Promise<Record<string, Balance>> {
399-
return this.request<Record<string, Balance>>('/api/v1/billing/balance/all', {
399+
return this.request<Record<string, Balance>>('/v1/billing/balance/all', {
400400
params: { user }, token,
401401
})
402402
}
@@ -406,13 +406,13 @@ export class Commerce {
406406
// -----------------------------------------------------------------------
407407

408408
async addUsageRecord(record: UsageRecord, token?: string): Promise<Transaction> {
409-
return this.request<Transaction>('/api/v1/billing/usage', {
409+
return this.request<Transaction>('/v1/billing/usage', {
410410
method: 'POST', body: record, token,
411411
})
412412
}
413413

414414
async getUsageRecords(user: string, currency = 'usd', token?: string): Promise<Transaction[]> {
415-
return this.request<Transaction[]>('/api/v1/billing/usage', {
415+
return this.request<Transaction[]>('/v1/billing/usage', {
416416
params: { user, currency }, token,
417417
})
418418
}
@@ -425,13 +425,13 @@ export class Commerce {
425425
params: { user: string; currency?: string; amount: number; notes?: string; tags?: string[]; expiresIn?: string },
426426
token?: string,
427427
): Promise<Transaction> {
428-
return this.request<Transaction>('/api/v1/billing/deposit', {
428+
return this.request<Transaction>('/v1/billing/deposit', {
429429
method: 'POST', body: params, token,
430430
})
431431
}
432432

433433
async grantStarterCredit(user: string, token?: string): Promise<Transaction> {
434-
return this.request<Transaction>('/api/v1/billing/credit', {
434+
return this.request<Transaction>('/v1/billing/credit', {
435435
method: 'POST', body: { user }, token,
436436
})
437437
}
@@ -441,12 +441,12 @@ export class Commerce {
441441
// -----------------------------------------------------------------------
442442

443443
async getPlans(token?: string): Promise<Plan[]> {
444-
return this.request<Plan[]>('/api/v1/billing/plans', { token })
444+
return this.request<Plan[]>('/v1/billing/plans', { token })
445445
}
446446

447447
async getPlan(planId: string, token?: string): Promise<Plan | null> {
448448
try {
449-
return await this.request<Plan>(`/api/v1/billing/plans/${planId}`, { token })
449+
return await this.request<Plan>(`/v1/billing/plans/${planId}`, { token })
450450
} catch { return null }
451451
}
452452

@@ -458,37 +458,37 @@ export class Commerce {
458458
params: { planId: string; userId?: string; customerId?: string; paymentMethodId?: string; couponCode?: string; trialDays?: number },
459459
token?: string,
460460
): Promise<Subscription> {
461-
return this.request<Subscription>('/api/v1/billing/subscriptions', {
461+
return this.request<Subscription>('/v1/billing/subscriptions', {
462462
method: 'POST', body: params, token,
463463
})
464464
}
465465

466466
async getSubscription(subscriptionId: string, token?: string): Promise<Subscription | null> {
467467
try {
468-
return await this.request<Subscription>(`/api/v1/billing/subscriptions/${subscriptionId}`, { token })
468+
return await this.request<Subscription>(`/v1/billing/subscriptions/${subscriptionId}`, { token })
469469
} catch { return null }
470470
}
471471

472472
async listSubscriptions(params?: { customerId?: string }, token?: string): Promise<Subscription[]> {
473-
return this.request<Subscription[]>('/api/v1/billing/subscriptions', {
473+
return this.request<Subscription[]>('/v1/billing/subscriptions', {
474474
params: params as Record<string, string> | undefined, token,
475475
})
476476
}
477477

478478
async updateSubscription(subscriptionId: string, update: Partial<Subscription>, token?: string): Promise<Subscription> {
479-
return this.request<Subscription>(`/api/v1/billing/subscriptions/${subscriptionId}`, {
479+
return this.request<Subscription>(`/v1/billing/subscriptions/${subscriptionId}`, {
480480
method: 'PATCH', body: update, token,
481481
})
482482
}
483483

484484
async cancelSubscription(subscriptionId: string, immediately = false, token?: string): Promise<Subscription> {
485-
return this.request<Subscription>(`/api/v1/billing/subscriptions/${subscriptionId}/cancel`, {
485+
return this.request<Subscription>(`/v1/billing/subscriptions/${subscriptionId}/cancel`, {
486486
method: 'POST', body: { immediately }, token,
487487
})
488488
}
489489

490490
async reactivateSubscription(subscriptionId: string, token?: string): Promise<Subscription> {
491-
return this.request<Subscription>(`/api/v1/billing/subscriptions/${subscriptionId}/reactivate`, {
491+
return this.request<Subscription>(`/v1/billing/subscriptions/${subscriptionId}/reactivate`, {
492492
method: 'POST', token,
493493
})
494494
}
@@ -506,7 +506,7 @@ export class Commerce {
506506
params: CheckoutSessionRequest,
507507
token?: string,
508508
): Promise<CheckoutSessionResponse> {
509-
return this.request<CheckoutSessionResponse>('/api/v1/checkout/sessions', {
509+
return this.request<CheckoutSessionResponse>('/v1/checkout/sessions', {
510510
method: 'POST', body: params, token,
511511
})
512512
}
@@ -522,7 +522,7 @@ export class Commerce {
522522
* tokenizes via the configured payment provider (Stripe).
523523
*/
524524
async tokenizeCard(card: CardTokenizeRequest, token?: string): Promise<CardTokenizeResult> {
525-
return this.request<CardTokenizeResult>('/api/v1/billing/card/tokenize', {
525+
return this.request<CardTokenizeResult>('/v1/billing/card/tokenize', {
526526
method: 'POST',
527527
body: {
528528
number: card.number.replace(/\s/g, ''),
@@ -550,25 +550,25 @@ export class Commerce {
550550
},
551551
token?: string,
552552
): Promise<PaymentMethod> {
553-
return this.request<PaymentMethod>('/api/v1/billing/payment-methods', {
553+
return this.request<PaymentMethod>('/v1/billing/payment-methods', {
554554
method: 'POST', body: params, token,
555555
})
556556
}
557557

558558
async listPaymentMethods(customerId: string, token?: string): Promise<PaymentMethod[]> {
559-
return this.request<PaymentMethod[]>('/api/v1/billing/payment-methods', {
559+
return this.request<PaymentMethod[]>('/v1/billing/payment-methods', {
560560
params: { customerId }, token,
561561
})
562562
}
563563

564564
async removePaymentMethod(paymentMethodId: string, token?: string): Promise<void> {
565-
await this.request<void>(`/api/v1/billing/payment-methods/${paymentMethodId}`, {
565+
await this.request<void>(`/v1/billing/payment-methods/${paymentMethodId}`, {
566566
method: 'DELETE', token,
567567
})
568568
}
569569

570570
async setDefaultPaymentMethod(customerId: string, paymentMethodId: string, token?: string): Promise<PaymentMethod> {
571-
return this.request<PaymentMethod>(`/api/v1/billing/customers/${customerId}/default-payment-method`, {
571+
return this.request<PaymentMethod>(`/v1/billing/customers/${customerId}/default-payment-method`, {
572572
method: 'POST', body: { paymentMethodId }, token,
573573
})
574574
}
@@ -583,7 +583,7 @@ export class Commerce {
583583
*/
584584
async validateCoupon(code: string, subtotalCents?: number, token?: string): Promise<CouponValidateResult> {
585585
try {
586-
const result = await this.request<Coupon>('/api/v1/coupon/validate', {
586+
const result = await this.request<Coupon>('/v1/coupon/validate', {
587587
method: 'POST',
588588
body: { code: code.toUpperCase().trim(), subtotalCents },
589589
token,
@@ -599,7 +599,7 @@ export class Commerce {
599599
* Redeem a coupon for a user. Creates credit grant records.
600600
*/
601601
async redeemCoupon(code: string, userId: string, token?: string): Promise<CreditGrant[]> {
602-
return this.request<CreditGrant[]>('/api/v1/coupon/redeem', {
602+
return this.request<CreditGrant[]>('/v1/coupon/redeem', {
603603
method: 'POST',
604604
body: { code: code.toUpperCase().trim(), userId },
605605
token,
@@ -615,25 +615,25 @@ export class Commerce {
615615
* Returns the referral code/link the user can share.
616616
*/
617617
async getOrCreateReferrer(userId: string, token?: string): Promise<Referrer> {
618-
return this.request<Referrer>('/api/v1/referrer', {
618+
return this.request<Referrer>('/v1/referrer', {
619619
method: 'POST', body: { userId }, token,
620620
})
621621
}
622622

623623
async getReferrals(userId: string, token?: string): Promise<Referral[]> {
624-
return this.request<Referral[]>(`/api/v1/user/${userId}/referrals`, { token })
624+
return this.request<Referral[]>(`/v1/user/${userId}/referrals`, { token })
625625
}
626626

627627
async getReferrers(userId: string, token?: string): Promise<Referrer[]> {
628-
return this.request<Referrer[]>(`/api/v1/user/${userId}/referrers`, { token })
628+
return this.request<Referrer[]>(`/v1/user/${userId}/referrers`, { token })
629629
}
630630

631631
/**
632632
* Get affiliate details for a user.
633633
*/
634634
async getAffiliate(userId: string, token?: string): Promise<Affiliate | null> {
635635
try {
636-
return await this.request<Affiliate>(`/api/v1/user/${userId}/affiliate`, { token })
636+
return await this.request<Affiliate>(`/v1/user/${userId}/affiliate`, { token })
637637
} catch { return null }
638638
}
639639

@@ -642,48 +642,48 @@ export class Commerce {
642642
* After creation, user can connect their bank via the returnedconnectUrl.
643643
*/
644644
async createAffiliate(userId: string, token?: string): Promise<Affiliate> {
645-
return this.request<Affiliate>('/api/v1/affiliate', {
645+
return this.request<Affiliate>('/v1/affiliate', {
646646
method: 'POST', body: { userId }, token,
647647
})
648648
}
649649

650650
async getAffiliateReferrals(affiliateId: string, token?: string): Promise<Referral[]> {
651-
return this.request<Referral[]>(`/api/v1/affiliate/${affiliateId}/referrals`, { token })
651+
return this.request<Referral[]>(`/v1/affiliate/${affiliateId}/referrals`, { token })
652652
}
653653

654654
async getAffiliateOrders(affiliateId: string, token?: string): Promise<unknown[]> {
655-
return this.request<unknown[]>(`/api/v1/affiliate/${affiliateId}/orders`, { token })
655+
return this.request<unknown[]>(`/v1/affiliate/${affiliateId}/orders`, { token })
656656
}
657657

658658
async getAffiliateTransactions(affiliateId: string, token?: string): Promise<Transaction[]> {
659-
return this.request<Transaction[]>(`/api/v1/affiliate/${affiliateId}/transactions`, { token })
659+
return this.request<Transaction[]>(`/v1/affiliate/${affiliateId}/transactions`, { token })
660660
}
661661

662662
// -----------------------------------------------------------------------
663663
// Legacy checkout (order-based)
664664
// -----------------------------------------------------------------------
665665

666666
async authorize(orderId: string, token?: string): Promise<Payment> {
667-
return this.request<Payment>(`/api/v1/authorize/${orderId}`, { method: 'POST', token })
667+
return this.request<Payment>(`/v1/authorize/${orderId}`, { method: 'POST', token })
668668
}
669669

670670
async capture(orderId: string, token?: string): Promise<Payment> {
671-
return this.request<Payment>(`/api/v1/capture/${orderId}`, { method: 'POST', token })
671+
return this.request<Payment>(`/v1/capture/${orderId}`, { method: 'POST', token })
672672
}
673673

674674
async charge(orderId: string, token?: string): Promise<Payment> {
675-
return this.request<Payment>(`/api/v1/charge/${orderId}`, { method: 'POST', token })
675+
return this.request<Payment>(`/v1/charge/${orderId}`, { method: 'POST', token })
676676
}
677677

678678
async refund(paymentId: string, token?: string): Promise<Payment> {
679-
return this.request<Payment>(`/api/v1/refund/${paymentId}`, { method: 'POST', token })
679+
return this.request<Payment>(`/v1/refund/${paymentId}`, { method: 'POST', token })
680680
}
681681

682682
async billingRefund(
683683
params: { user: string; amount: number; originalTransactionId: string; currency?: string; notes?: string },
684684
token?: string,
685685
): Promise<Transaction> {
686-
return this.request<Transaction>('/api/v1/billing/refund', {
686+
return this.request<Transaction>('/v1/billing/refund', {
687687
method: 'POST', body: params, token,
688688
})
689689
}

pkg/commerce/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hanzo/commerce",
3-
"version": "7.6.0",
3+
"version": "7.6.1",
44
"description": "e-commerce framework.",
55
"publishConfig": {
66
"registry": "https://registry.npmjs.org/",

0 commit comments

Comments
 (0)