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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -22,5 +22,7 @@ export * from "./sales-channel"
|
||||
export * from "./shipping-option"
|
||||
export * from "./shipping-profile"
|
||||
export * from "./stock-locations"
|
||||
export * from "./tax"
|
||||
export * from "./tax-rate"
|
||||
export * from "./tax-region"
|
||||
export * from "./user"
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { AdminTaxRegion } from "../../tax-region"
|
||||
|
||||
export interface AdminTaxRateRule {
|
||||
reference: string
|
||||
reference_id: string
|
||||
}
|
||||
|
||||
export interface AdminTaxRate {
|
||||
id: string
|
||||
rate: number | null
|
||||
code: string | null
|
||||
name: string
|
||||
metadata: Record<string, unknown> | null
|
||||
tax_region_id: string
|
||||
is_combinable: boolean
|
||||
is_default: boolean
|
||||
created_at: string
|
||||
updated_at: string
|
||||
deleted_at: null
|
||||
created_by: string | null
|
||||
tax_region: AdminTaxRegion
|
||||
rules: AdminTaxRateRule[]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
@@ -0,0 +1,25 @@
|
||||
interface AdminCreateTaxRateRule {
|
||||
reference: string
|
||||
reference_id: string
|
||||
}
|
||||
|
||||
export interface AdminCreateTaxRate {
|
||||
name: string
|
||||
tax_region_id: string
|
||||
rate?: number
|
||||
code?: string
|
||||
rules?: AdminCreateTaxRateRule[]
|
||||
is_default?: boolean
|
||||
is_combinable?: boolean
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface AdminUpdateTaxRate {
|
||||
name?: string
|
||||
rate?: number
|
||||
code?: string
|
||||
rules?: AdminCreateTaxRateRule[]
|
||||
is_default?: boolean
|
||||
is_combinable?: boolean
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { OperatorMap } from "../../../dal"
|
||||
import { FindParams } from "../../common"
|
||||
|
||||
export interface AdminTaxRateListParams extends FindParams {
|
||||
id?: string | string[]
|
||||
q?: string
|
||||
tax_region_id?: string | string[] | OperatorMap<string | string[]>
|
||||
is_default?: string
|
||||
service_zone_id?: string
|
||||
shipping_profile_id?: string
|
||||
provider_id?: string
|
||||
shipping_option_type_id?: string
|
||||
created_at?: string | OperatorMap<string>
|
||||
updated_at?: string | OperatorMap<string>
|
||||
deleted_at?: string | OperatorMap<string>
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { AdminTaxRate } from "./entities"
|
||||
|
||||
export interface AdminTaxRateResponse {
|
||||
tax_rate: AdminTaxRate
|
||||
}
|
||||
|
||||
export type AdminTaxRateListResponse = PaginatedResponse<{
|
||||
tax_rates: AdminTaxRate[]
|
||||
}>
|
||||
|
||||
export interface AdminTaxRateDeleteResponse
|
||||
extends DeleteResponse<"tax_rate"> {}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { AdminTaxRate } from "../../tax-rate"
|
||||
|
||||
export interface AdminTaxRegion {
|
||||
id: string
|
||||
rate: number | null
|
||||
code: string | null
|
||||
country_code: string | null
|
||||
province_code: string | null
|
||||
name: string
|
||||
metadata: Record<string, unknown> | null
|
||||
tax_region_id: string
|
||||
is_combinable: boolean
|
||||
is_default: boolean
|
||||
parent_id: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
deleted_at: string | null
|
||||
created_by: string | null
|
||||
tax_rates: AdminTaxRate[]
|
||||
parent: AdminTaxRegion
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
@@ -0,0 +1,13 @@
|
||||
export interface AdminCreateTaxRegion {
|
||||
country_code: string
|
||||
province_code?: string
|
||||
parent_id?: string
|
||||
default_tax_rate?: {
|
||||
rate?: number
|
||||
code?: string
|
||||
name: string
|
||||
is_combinable?: boolean
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { OperatorMap } from "../../../dal"
|
||||
import { FindParams } from "../../common"
|
||||
|
||||
export interface AdminTaxRegionListParams extends FindParams {
|
||||
id?: string | string[]
|
||||
q?: string
|
||||
parent_id?: string | string[] | OperatorMap<string | string[]>
|
||||
country_code?: string | string[] | OperatorMap<string | string[]>
|
||||
province_code?: string | string[] | OperatorMap<string | string[]>
|
||||
created_at?: string | OperatorMap<string>
|
||||
updated_at?: string | OperatorMap<string>
|
||||
deleted_at?: string | OperatorMap<string>
|
||||
created_by?: string | OperatorMap<string>
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { AdminTaxRegion } from "./entities"
|
||||
|
||||
export interface AdminTaxRegionResponse {
|
||||
tax_region: AdminTaxRegion
|
||||
}
|
||||
|
||||
export type AdminTaxRegionListResponse = PaginatedResponse<{
|
||||
tax_regions: AdminTaxRegion[]
|
||||
}>
|
||||
|
||||
export interface AdminTaxRegionDeleteResponse
|
||||
extends DeleteResponse<"tax_region"> {}
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./admin"
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./tax-rates"
|
||||
export * from "./tax-regions"
|
||||
@@ -1,30 +0,0 @@
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { TaxRegionResponse } from "./tax-regions"
|
||||
|
||||
export interface TaxRateResponse {
|
||||
id: string
|
||||
rate: number | null
|
||||
code: string | null
|
||||
name: string
|
||||
metadata: Record<string, unknown> | null
|
||||
tax_region_id: string
|
||||
is_combinable: boolean
|
||||
is_default: boolean
|
||||
created_at: string | Date
|
||||
updated_at: string | Date
|
||||
deleted_at: Date | null
|
||||
created_by: string | null
|
||||
tax_region: TaxRegionResponse
|
||||
rules: {
|
||||
reference: string
|
||||
reference_id: string
|
||||
}[]
|
||||
}
|
||||
|
||||
export interface AdminTaxRateResponse {
|
||||
tax_rate: TaxRateResponse
|
||||
}
|
||||
|
||||
export type AdminTaxRateListResponse = PaginatedResponse<{
|
||||
tax_rates: TaxRateResponse[]
|
||||
}>
|
||||
@@ -1,32 +0,0 @@
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { TaxRateResponse } from "./tax-rates"
|
||||
|
||||
export interface TaxRegionResponse {
|
||||
id: string
|
||||
rate: number | null
|
||||
code: string | null
|
||||
country_code: string | null
|
||||
province_code: string | null
|
||||
name: string
|
||||
metadata: Record<string, unknown> | null
|
||||
tax_region_id: string
|
||||
is_combinable: boolean
|
||||
is_default: boolean
|
||||
parent_id: string | null
|
||||
created_at: string | Date
|
||||
updated_at: string | Date
|
||||
deleted_at: Date | null
|
||||
created_by: string | null
|
||||
|
||||
tax_rates: TaxRateResponse[]
|
||||
|
||||
parent: TaxRegionResponse
|
||||
}
|
||||
|
||||
export interface AdminTaxRegionResponse {
|
||||
tax_region: TaxRegionResponse
|
||||
}
|
||||
|
||||
export type AdminTaxRegionListResponse = PaginatedResponse<{
|
||||
tax_regions: TaxRegionResponse[]
|
||||
}>
|
||||
Reference in New Issue
Block a user