feat: Add tax region + rates to SDK and types (#7635)
* feat: Add tax region + rates to SDK and types * replace client with sdk in loaders * Address PR feedback
This commit is contained in:
@@ -11,6 +11,8 @@ import { SalesChannel } from "./sales-channel"
|
||||
import { ShippingOption } from "./shipping-option"
|
||||
import { ShippingProfile } from "./shipping-profile"
|
||||
import { StockLocation } from "./stock-location"
|
||||
import { TaxRate } from "./tax-rate"
|
||||
import { TaxRegion } from "./tax-region"
|
||||
import { Upload } from "./upload"
|
||||
|
||||
export class Admin {
|
||||
@@ -27,6 +29,8 @@ export class Admin {
|
||||
public shippingOption: ShippingOption
|
||||
public shippingProfile: ShippingProfile
|
||||
public order: Order
|
||||
public taxRate: TaxRate
|
||||
public taxRegion: TaxRegion
|
||||
|
||||
constructor(client: Client) {
|
||||
this.invite = new Invite(client)
|
||||
@@ -42,5 +46,7 @@ export class Admin {
|
||||
this.shippingOption = new ShippingOption(client)
|
||||
this.shippingProfile = new ShippingProfile(client)
|
||||
this.order = new Order(client)
|
||||
this.taxRate = new TaxRate(client)
|
||||
this.taxRegion = new TaxRegion(client)
|
||||
}
|
||||
}
|
||||
|
||||
81
packages/core/js-sdk/src/admin/tax-rate.ts
Normal file
81
packages/core/js-sdk/src/admin/tax-rate.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
|
||||
const taxRateUrl = "/admin/tax-rates"
|
||||
|
||||
export class TaxRate {
|
||||
private client: Client
|
||||
constructor(client: Client) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async create(
|
||||
body: HttpTypes.AdminCreateTaxRate,
|
||||
query?: HttpTypes.SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxRateResponse>(taxRateUrl, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
})
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
body: HttpTypes.AdminUpdateTaxRate,
|
||||
query?: HttpTypes.SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxRateResponse>(
|
||||
`${taxRateUrl}/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxRateDeleteResponse>(
|
||||
`${taxRateUrl}/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async retrieve(
|
||||
id: string,
|
||||
query?: HttpTypes.SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxRateResponse>(
|
||||
`${taxRateUrl}/${id}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async list(
|
||||
query?: HttpTypes.AdminTaxRateListParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxRateListResponse>(
|
||||
taxRateUrl,
|
||||
{
|
||||
method: "GET",
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
68
packages/core/js-sdk/src/admin/tax-region.ts
Normal file
68
packages/core/js-sdk/src/admin/tax-region.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
|
||||
const taxRegionUrl = "/admin/tax-regions"
|
||||
|
||||
// TODO: Add support for updating a tax region
|
||||
export class TaxRegion {
|
||||
private client: Client
|
||||
constructor(client: Client) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async create(
|
||||
body: HttpTypes.AdminCreateTaxRegion,
|
||||
query?: HttpTypes.SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxRegionResponse>(
|
||||
taxRegionUrl,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxRegionDeleteResponse>(
|
||||
`${taxRegionUrl}/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async retrieve(
|
||||
id: string,
|
||||
query?: HttpTypes.SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxRegionResponse>(
|
||||
`${taxRegionUrl}/${id}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async list(
|
||||
query?: HttpTypes.AdminTaxRegionListParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxRegionListResponse>(
|
||||
taxRegionUrl,
|
||||
{
|
||||
method: "GET",
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user