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:
Oli Juhl
2024-06-06 18:31:39 +02:00
committed by GitHub
parent fa0c7dfbb5
commit f0e78d062e
25 changed files with 348 additions and 173 deletions

View File

@@ -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)
}
}

View 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,
}
)
}
}

View 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,
}
)
}
}