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:
1 parent
fa0c7dfbb5
commit
f0e78d062e
25 files changed
+348
-173
No files matched your search
@@ -1,8 +1,4 @@
|
|||||||
import {
|
import { HttpTypes } from "@medusajs/types"
|
||||||
AdminPostTaxRatesReq,
|
|
||||||
AdminPostTaxRatesTaxRateReq,
|
|
||||||
} from "@medusajs/medusa"
|
|
||||||
import { AdminTaxRateListResponse, AdminTaxRateResponse } from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
QueryKey,
|
QueryKey,
|
||||||
UseMutationOptions,
|
UseMutationOptions,
|
||||||
@@ -10,10 +6,9 @@ import {
|
|||||||
useMutation,
|
useMutation,
|
||||||
useQuery,
|
useQuery,
|
||||||
} from "@tanstack/react-query"
|
} from "@tanstack/react-query"
|
||||||
import { client } from "../../lib/client"
|
import { sdk } from "../../lib/client"
|
||||||
import { queryClient } from "../../lib/query-client"
|
import { queryClient } from "../../lib/query-client"
|
||||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||||
import { TaxRateDeleteRes } from "../../types/api-responses"
|
|
||||||
|
|
||||||
const TAX_RATES_QUERY_KEY = "tax_rates" as const
|
const TAX_RATES_QUERY_KEY = "tax_rates" as const
|
||||||
export const taxRatesQueryKeys = queryKeysFactory(TAX_RATES_QUERY_KEY)
|
export const taxRatesQueryKeys = queryKeysFactory(TAX_RATES_QUERY_KEY)
|
||||||
@@ -23,9 +18,9 @@ export const useTaxRate = (
|
|||||||
query?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminTaxRateResponse,
|
HttpTypes.AdminTaxRateResponse,
|
||||||
Error,
|
Error,
|
||||||
AdminTaxRateResponse,
|
HttpTypes.AdminTaxRateResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
@@ -33,7 +28,7 @@ export const useTaxRate = (
|
|||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryKey: taxRatesQueryKeys.detail(id),
|
queryKey: taxRatesQueryKeys.detail(id),
|
||||||
queryFn: async () => client.taxes.retrieveTaxRate(id, query),
|
queryFn: async () => sdk.admin.taxRate.retrieve(id, query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -44,16 +39,16 @@ export const useTaxRates = (
|
|||||||
query?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminTaxRateListResponse,
|
HttpTypes.AdminTaxRateListResponse,
|
||||||
Error,
|
Error,
|
||||||
AdminTaxRateListResponse,
|
HttpTypes.AdminTaxRateListResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryFn: () => client.taxes.listTaxRates(query),
|
queryFn: () => sdk.admin.taxRate.list(query),
|
||||||
queryKey: taxRatesQueryKeys.list(query),
|
queryKey: taxRatesQueryKeys.list(query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
@@ -64,13 +59,13 @@ export const useTaxRates = (
|
|||||||
export const useUpdateTaxRate = (
|
export const useUpdateTaxRate = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminTaxRateResponse,
|
HttpTypes.AdminTaxRateResponse,
|
||||||
Error,
|
Error,
|
||||||
AdminPostTaxRatesTaxRateReq
|
HttpTypes.AdminUpdateTaxRate
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.taxes.updateTaxRate(id, payload),
|
mutationFn: (payload) => sdk.admin.taxRate.update(id, payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: taxRatesQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: taxRatesQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
@@ -85,13 +80,13 @@ export const useUpdateTaxRate = (
|
|||||||
|
|
||||||
export const useCreateTaxRate = (
|
export const useCreateTaxRate = (
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminTaxRateResponse,
|
HttpTypes.AdminTaxRateResponse,
|
||||||
Error,
|
Error,
|
||||||
AdminPostTaxRatesReq
|
HttpTypes.AdminCreateTaxRate
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.taxes.createTaxRate(payload),
|
mutationFn: (payload) => sdk.admin.taxRate.create(payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: taxRatesQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: taxRatesQueryKeys.lists() })
|
||||||
options?.onSuccess?.(data, variables, context)
|
options?.onSuccess?.(data, variables, context)
|
||||||
@@ -102,10 +97,14 @@ export const useCreateTaxRate = (
|
|||||||
|
|
||||||
export const useDeleteTaxRate = (
|
export const useDeleteTaxRate = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<TaxRateDeleteRes, Error, void>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.AdminTaxRateDeleteResponse,
|
||||||
|
Error,
|
||||||
|
void
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => client.taxes.deleteTaxRate(id),
|
mutationFn: () => sdk.admin.taxRate.delete(id),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: taxRatesQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: taxRatesQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import { AdminCreateTaxRegion } from "@medusajs/medusa"
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import {
|
|
||||||
AdminTaxRegionListResponse,
|
|
||||||
AdminTaxRegionResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
QueryKey,
|
QueryKey,
|
||||||
UseMutationOptions,
|
UseMutationOptions,
|
||||||
@@ -10,10 +6,9 @@ import {
|
|||||||
useMutation,
|
useMutation,
|
||||||
useQuery,
|
useQuery,
|
||||||
} from "@tanstack/react-query"
|
} from "@tanstack/react-query"
|
||||||
import { client } from "../../lib/client"
|
import { sdk } from "../../lib/client"
|
||||||
import { queryClient } from "../../lib/query-client"
|
import { queryClient } from "../../lib/query-client"
|
||||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||||
import { TaxRegionDeleteRes } from "../../types/api-responses"
|
|
||||||
|
|
||||||
const TAX_REGIONS_QUERY_KEY = "tax_regions" as const
|
const TAX_REGIONS_QUERY_KEY = "tax_regions" as const
|
||||||
export const taxRegionsQueryKeys = queryKeysFactory(TAX_REGIONS_QUERY_KEY)
|
export const taxRegionsQueryKeys = queryKeysFactory(TAX_REGIONS_QUERY_KEY)
|
||||||
@@ -23,9 +18,9 @@ export const useTaxRegion = (
|
|||||||
query?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminTaxRegionResponse,
|
HttpTypes.AdminTaxRegionResponse,
|
||||||
Error,
|
Error,
|
||||||
AdminTaxRegionResponse,
|
HttpTypes.AdminTaxRegionResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
@@ -33,7 +28,7 @@ export const useTaxRegion = (
|
|||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryKey: taxRegionsQueryKeys.detail(id),
|
queryKey: taxRegionsQueryKeys.detail(id),
|
||||||
queryFn: async () => client.taxes.retrieveTaxRegion(id, query),
|
queryFn: async () => sdk.admin.taxRegion.retrieve(id, query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -44,16 +39,16 @@ export const useTaxRegions = (
|
|||||||
query?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminTaxRegionListResponse,
|
HttpTypes.AdminTaxRegionListResponse,
|
||||||
Error,
|
Error,
|
||||||
AdminTaxRegionListResponse,
|
HttpTypes.AdminTaxRegionListResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryFn: () => client.taxes.listTaxRegions(query),
|
queryFn: () => sdk.admin.taxRegion.list(query),
|
||||||
queryKey: taxRegionsQueryKeys.list(query),
|
queryKey: taxRegionsQueryKeys.list(query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
@@ -63,13 +58,13 @@ export const useTaxRegions = (
|
|||||||
|
|
||||||
export const useCreateTaxRegion = (
|
export const useCreateTaxRegion = (
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminTaxRegionResponse,
|
HttpTypes.AdminTaxRegionResponse,
|
||||||
Error,
|
Error,
|
||||||
AdminCreateTaxRegion
|
HttpTypes.AdminCreateTaxRegion
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.taxes.createTaxRegion(payload),
|
mutationFn: (payload) => sdk.admin.taxRegion.create(payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.all })
|
queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.all })
|
||||||
options?.onSuccess?.(data, variables, context)
|
options?.onSuccess?.(data, variables, context)
|
||||||
@@ -80,10 +75,14 @@ export const useCreateTaxRegion = (
|
|||||||
|
|
||||||
export const useDeleteTaxRegion = (
|
export const useDeleteTaxRegion = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<TaxRegionDeleteRes, Error, void>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.AdminTaxRegionDeleteResponse,
|
||||||
|
Error,
|
||||||
|
void
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => client.taxes.deleteTaxRegion(id),
|
mutationFn: () => sdk.admin.taxRegion.delete(id),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import { shippingProfiles } from "./shipping-profiles"
|
|||||||
import { stockLocations } from "./stock-locations"
|
import { stockLocations } from "./stock-locations"
|
||||||
import { stores } from "./stores"
|
import { stores } from "./stores"
|
||||||
import { tags } from "./tags"
|
import { tags } from "./tags"
|
||||||
import { taxes } from "./taxes"
|
|
||||||
import { users } from "./users"
|
import { users } from "./users"
|
||||||
import { workflowExecutions } from "./workflow-executions"
|
import { workflowExecutions } from "./workflow-executions"
|
||||||
|
|
||||||
@@ -40,7 +39,6 @@ export const client = {
|
|||||||
shippingProfiles: shippingProfiles,
|
shippingProfiles: shippingProfiles,
|
||||||
productTags: tags,
|
productTags: tags,
|
||||||
users: users,
|
users: users,
|
||||||
taxes: taxes,
|
|
||||||
invites: invites,
|
invites: invites,
|
||||||
inventoryItems: inventoryItems,
|
inventoryItems: inventoryItems,
|
||||||
reservations: reservations,
|
reservations: reservations,
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
import {
|
|
||||||
AdminCreateTaxRegion,
|
|
||||||
AdminPostTaxRatesTaxRateReq,
|
|
||||||
} from "@medusajs/medusa"
|
|
||||||
import {
|
|
||||||
AdminTaxRateResponse,
|
|
||||||
AdminTaxRegionListResponse,
|
|
||||||
AdminTaxRegionResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import { TaxRateDeleteRes, TaxRegionDeleteRes } from "../../types/api-responses"
|
|
||||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
|
||||||
|
|
||||||
async function retrieveTaxRegion(id: string, query?: Record<string, any>) {
|
|
||||||
return getRequest<AdminTaxRegionResponse>(`/admin/tax-regions/${id}`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listTaxRegions(query?: Record<string, any>) {
|
|
||||||
return getRequest<AdminTaxRegionListResponse>(`/admin/tax-regions`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createTaxRegion(payload: AdminCreateTaxRegion) {
|
|
||||||
return postRequest<AdminTaxRegionResponse>(`/admin/tax-regions`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteTaxRegion(id: string) {
|
|
||||||
return deleteRequest<TaxRegionDeleteRes>(`/admin/tax-regions/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function retrieveTaxRate(id: string, query?: Record<string, any>) {
|
|
||||||
return getRequest<AdminTaxRegionResponse>(`/admin/tax-rates/${id}`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listTaxRates(query?: Record<string, any>) {
|
|
||||||
return getRequest<AdminTaxRegionListResponse>(`/admin/tax-rates`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateTaxRate(id: string, payload: AdminPostTaxRatesTaxRateReq) {
|
|
||||||
return postRequest<AdminTaxRateResponse>(`/admin/tax-rates/${id}`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createTaxRate(payload: AdminCreateTaxRate) {
|
|
||||||
return postRequest<AdminTaxRateResponse>(`/admin/tax-rates`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteTaxRate(id: string) {
|
|
||||||
return deleteRequest<TaxRateDeleteRes>(`/admin/tax-rates/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const taxes = {
|
|
||||||
retrieveTaxRegion,
|
|
||||||
listTaxRegions,
|
|
||||||
retrieveTaxRate,
|
|
||||||
listTaxRates,
|
|
||||||
updateTaxRate,
|
|
||||||
createTaxRegion,
|
|
||||||
deleteTaxRegion,
|
|
||||||
createTaxRate,
|
|
||||||
deleteTaxRate,
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
import { LoaderFunctionArgs } from "react-router-dom"
|
|
||||||
|
|
||||||
import { AdminTaxRateResponse } from "@medusajs/types"
|
import { AdminTaxRateResponse } from "@medusajs/types"
|
||||||
|
import { LoaderFunctionArgs } from "react-router-dom"
|
||||||
import { taxRatesQueryKeys } from "../../../hooks/api/tax-rates"
|
import { taxRatesQueryKeys } from "../../../hooks/api/tax-rates"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
|
|
||||||
const taxRateDetailQuery = (id: string) => ({
|
const taxRateDetailQuery = (id: string) => ({
|
||||||
queryKey: taxRatesQueryKeys.detail(id),
|
queryKey: taxRatesQueryKeys.detail(id),
|
||||||
queryFn: async () => client.taxes.retrieveTaxRate(id),
|
queryFn: async () => sdk.admin.taxRate.retrieve(id),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const taxRateLoader = async ({ params }: LoaderFunctionArgs) => {
|
export const taxRateLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import { LoaderFunctionArgs } from "react-router-dom"
|
|
||||||
|
|
||||||
import { AdminTaxRegionResponse } from "@medusajs/types"
|
import { AdminTaxRegionResponse } from "@medusajs/types"
|
||||||
|
import { LoaderFunctionArgs } from "react-router-dom"
|
||||||
import { taxRegionsQueryKeys } from "../../../hooks/api/tax-regions"
|
import { taxRegionsQueryKeys } from "../../../hooks/api/tax-regions"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
|
|
||||||
const taxRegionDetailQuery = (id: string) => ({
|
const taxRegionDetailQuery = (id: string) => ({
|
||||||
queryKey: taxRegionsQueryKeys.detail(id),
|
queryKey: taxRegionsQueryKeys.detail(id),
|
||||||
queryFn: async () => client.taxes.retrieveTaxRegion(id),
|
queryFn: async () => sdk.admin.taxRegion.retrieve(id),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const taxRegionLoader = async ({ params }: LoaderFunctionArgs) => {
|
export const taxRegionLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import { SalesChannel } from "./sales-channel"
|
|||||||
import { ShippingOption } from "./shipping-option"
|
import { ShippingOption } from "./shipping-option"
|
||||||
import { ShippingProfile } from "./shipping-profile"
|
import { ShippingProfile } from "./shipping-profile"
|
||||||
import { StockLocation } from "./stock-location"
|
import { StockLocation } from "./stock-location"
|
||||||
|
import { TaxRate } from "./tax-rate"
|
||||||
|
import { TaxRegion } from "./tax-region"
|
||||||
import { Upload } from "./upload"
|
import { Upload } from "./upload"
|
||||||
|
|
||||||
export class Admin {
|
export class Admin {
|
||||||
@@ -27,6 +29,8 @@ export class Admin {
|
|||||||
public shippingOption: ShippingOption
|
public shippingOption: ShippingOption
|
||||||
public shippingProfile: ShippingProfile
|
public shippingProfile: ShippingProfile
|
||||||
public order: Order
|
public order: Order
|
||||||
|
public taxRate: TaxRate
|
||||||
|
public taxRegion: TaxRegion
|
||||||
|
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
this.invite = new Invite(client)
|
this.invite = new Invite(client)
|
||||||
@@ -42,5 +46,7 @@ export class Admin {
|
|||||||
this.shippingOption = new ShippingOption(client)
|
this.shippingOption = new ShippingOption(client)
|
||||||
this.shippingProfile = new ShippingProfile(client)
|
this.shippingProfile = new ShippingProfile(client)
|
||||||
this.order = new Order(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-option"
|
||||||
export * from "./shipping-profile"
|
export * from "./shipping-profile"
|
||||||
export * from "./stock-locations"
|
export * from "./stock-locations"
|
||||||
export * from "./tax"
|
export * from "./tax-rate"
|
||||||
|
export * from "./tax-region"
|
||||||
export * from "./user"
|
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"> {}
|
||||||
File renamed without changes.
@@ -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