feat(dashboard, js-sdk, medusa, tax, types): custom tax providers (#12297)
* wip: setup loaders, add endpoints, module work, types, js sdk * fix: tax module provider loader * feat: select provider on region create, fix enpoint middleware registration * feat: edit form * fix: rename param * chore: changeset * fix: don't default to system provider * fix: admin fixes, dispalt tax provider * fix: some tests and types * fix: remove provider from province regions in test * fix: more tests, optional provider for sublevel regions, fix few types * fix: OE test * feat: edit tax region admin, update tax region core flow changes * feat: migrate script * fix: refactor * chore: use query graph * feat: provider section
This commit is contained in:
@@ -37,6 +37,7 @@ import { ShippingOption } from "./shipping-option"
|
||||
import { ShippingProfile } from "./shipping-profile"
|
||||
import { StockLocation } from "./stock-location"
|
||||
import { Store } from "./store"
|
||||
import { TaxProvider } from "./tax-provider"
|
||||
import { TaxRate } from "./tax-rate"
|
||||
import { TaxRegion } from "./tax-region"
|
||||
import { Upload } from "./upload"
|
||||
@@ -208,6 +209,10 @@ export class Admin {
|
||||
* @tags promotion
|
||||
*/
|
||||
public promotion: Promotion
|
||||
/**
|
||||
* @tags tax
|
||||
*/
|
||||
public taxProvider: TaxProvider
|
||||
/**
|
||||
* @tags promotion
|
||||
*/
|
||||
@@ -261,5 +266,6 @@ export class Admin {
|
||||
this.promotion = new Promotion(client)
|
||||
this.campaign = new Campaign(client)
|
||||
this.plugin = new Plugin(client)
|
||||
this.taxProvider = new TaxProvider(client)
|
||||
}
|
||||
}
|
||||
|
||||
51
packages/core/js-sdk/src/admin/tax-provider.ts
Normal file
51
packages/core/js-sdk/src/admin/tax-provider.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
|
||||
const taxProviderUrl = "/admin/tax-providers"
|
||||
|
||||
export class TaxProvider {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
private client: Client
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
constructor(client: Client) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
/**
|
||||
* This method retrieves a list of tax providers. It sends a request to the
|
||||
* [List Tax Providers](https://docs.medusajs.com/api/admin#tax-providers_gettaxproviders)
|
||||
* API route.
|
||||
*
|
||||
* @param query - Filters and pagination configurations.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The list of tax providers.
|
||||
*
|
||||
* @example
|
||||
* To retrieve the list of tax providers:
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxProvider.list()
|
||||
* .then(({ tax_providers, count, limit, offset }) => {
|
||||
* console.log(tax_providers)
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
async list(
|
||||
query?: HttpTypes.AdminGetTaxProvidersParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxProviderListResponse>(
|
||||
taxProviderUrl,
|
||||
{
|
||||
method: "GET",
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,12 @@ export class TaxRate {
|
||||
* This method creates a tax rate. It sends a request to the
|
||||
* [Create Tax Rate](https://docs.medusajs.com/api/admin#tax-rates_posttaxrates)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param body - The details of the tax rate to create.
|
||||
* @param query - Configure the fields and relations to retrieve in the tax rate.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The tax rate's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.taxRate.create({
|
||||
* name: "VAT",
|
||||
@@ -54,13 +54,13 @@ export class TaxRate {
|
||||
* This method updates a tax rate. It sends a request to the
|
||||
* [Update Tax Rate](https://docs.medusajs.com/api/admin#tax-rates_posttaxratesid)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param id - The ID of the tax rate to update.
|
||||
* @param body - The details of the tax rate to update.
|
||||
* @param query - Configure the fields and relations to retrieve in the tax rate.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The tax rate's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.taxRate.update("txrat_123", {
|
||||
* name: "VAT",
|
||||
@@ -91,11 +91,11 @@ export class TaxRate {
|
||||
* This method deletes a tax rate. It sends a request to the
|
||||
* [Delete Tax Rate](https://docs.medusajs.com/api/admin#tax-rates_deletetaxratesid)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param id - The ID of the tax rate to delete.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The deletion's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.taxRate.delete("txrat_123")
|
||||
* .then(({ deleted }) => {
|
||||
@@ -116,24 +116,24 @@ export class TaxRate {
|
||||
* This method retrieves a tax rate. It sends a request to the
|
||||
* [Get Tax Rate](https://docs.medusajs.com/api/admin#tax-rates_gettaxratesid)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param id - The ID of the tax rate to retrieve.
|
||||
* @param query - Configure the fields and relations to retrieve in the tax rate.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The tax rate's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* To retrieve a tax rate by its ID:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxRate.retrieve("txrat_123")
|
||||
* .then(({ tax_rate }) => {
|
||||
* console.log(tax_rate)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* To specify the fields and relations to retrieve:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxRate.retrieve("txrat_123", {
|
||||
* fields: "id,*tax_region"
|
||||
@@ -142,7 +142,7 @@ export class TaxRate {
|
||||
* console.log(tax_rate)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin#select-fields-and-relations).
|
||||
*/
|
||||
async retrieve(
|
||||
@@ -164,25 +164,25 @@ export class TaxRate {
|
||||
* This method retrieves a list of tax rates. It sends a request to the
|
||||
* [List Tax Rates](https://docs.medusajs.com/api/admin#tax-rates_gettaxrates)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param query - Filters and pagination configurations.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The list of tax rates.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* To retrieve the list of tax rates:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxRate.list()
|
||||
* .then(({ tax_rates, count, limit, offset }) => {
|
||||
* console.log(tax_rates)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
||||
*
|
||||
*
|
||||
* For example, to retrieve only 10 items and skip 10 items:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxRate.list({
|
||||
* limit: 10,
|
||||
@@ -192,10 +192,10 @@ export class TaxRate {
|
||||
* console.log(tax_rates)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
||||
* in each tax rate:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxRate.list({
|
||||
* fields: "id,*tax_region"
|
||||
@@ -204,7 +204,7 @@ export class TaxRate {
|
||||
* console.log(tax_rates)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin#select-fields-and-relations).
|
||||
*/
|
||||
async list(
|
||||
|
||||
@@ -6,7 +6,7 @@ const taxRegionUrl = "/admin/tax-regions"
|
||||
|
||||
/**
|
||||
* @privateRemarks
|
||||
*
|
||||
*
|
||||
* TODO: Add support for updating a tax region
|
||||
*/
|
||||
export class TaxRegion {
|
||||
@@ -25,12 +25,12 @@ export class TaxRegion {
|
||||
* This method creates a tax region. It sends a request to the
|
||||
* [Create Tax Region](https://docs.medusajs.com/api/admin#tax-regions_posttaxregions)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param body - The details of the tax region to create.
|
||||
* @param query - Configure the fields and relations to retrieve in the tax region.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The tax region's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.taxRegion.create({
|
||||
* country_code: "us",
|
||||
@@ -62,15 +62,51 @@ export class TaxRegion {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method updates a tax region. It sends a request to the
|
||||
* [Update Tax Region](https://docs.medusajs.com/api/admin#tax-regions_posttaxregionsid)
|
||||
* API route.
|
||||
*
|
||||
* @param id - The ID of the tax region to update.
|
||||
* @param body - The details of the tax region to update.
|
||||
* @param query - Configure the fields and relations to retrieve in the tax region.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The tax region's details.
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.taxRegion.update("txreg_123", {
|
||||
* province_code: "ca",
|
||||
* })
|
||||
* .then(({ tax_region }) => {
|
||||
* console.log(tax_region)
|
||||
* })
|
||||
*/
|
||||
async update(
|
||||
id: string,
|
||||
body: HttpTypes.AdminUpdateTaxRegion,
|
||||
query?: HttpTypes.SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminTaxRegionResponse>(
|
||||
`${taxRegionUrl}/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method deletes a tax region. It sends a request to the
|
||||
* [Delete Tax Region](https://docs.medusajs.com/api/admin#tax-regions_deletetaxregionsid)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param id - The ID of the tax region to delete.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The deletion's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.taxRegion.delete("txreg_123")
|
||||
* .then(({ deleted }) => {
|
||||
@@ -91,24 +127,24 @@ export class TaxRegion {
|
||||
* This method retrieves a tax region. It sends a request to the
|
||||
* [Get Tax Region](https://docs.medusajs.com/api/admin#tax-regions_gettaxregionsid)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param id - The ID of the tax region to retrieve.
|
||||
* @param query - Configure the fields and relations to retrieve in the tax region.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The tax region's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* To retrieve a tax region by its ID:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxRegion.retrieve("txreg_123")
|
||||
* .then(({ tax_region }) => {
|
||||
* console.log(tax_region)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* To specify the fields and relations to retrieve:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxRegion.retrieve("txreg_123", {
|
||||
* fields: "id,*tax_rates"
|
||||
@@ -117,7 +153,7 @@ export class TaxRegion {
|
||||
* console.log(tax_region)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin#select-fields-and-relations).
|
||||
*/
|
||||
async retrieve(
|
||||
@@ -139,25 +175,25 @@ export class TaxRegion {
|
||||
* This method retrieves a list of tax regions. It sends a request to the
|
||||
* [List Tax Regions](https://docs.medusajs.com/api/admin#tax-regions_gettaxregions)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param query - Filters and pagination configurations.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The list of tax regions.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* To retrieve the list of tax regions:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxRegion.list()
|
||||
* .then(({ tax_regions, count, limit, offset }) => {
|
||||
* console.log(tax_regions)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
||||
*
|
||||
*
|
||||
* For example, to retrieve only 10 items and skip 10 items:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxRegion.list({
|
||||
* limit: 10,
|
||||
@@ -167,10 +203,10 @@ export class TaxRegion {
|
||||
* console.log(tax_regions)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
||||
* in each tax region:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.taxRegion.list({
|
||||
* fields: "id,*tax_rates"
|
||||
@@ -179,7 +215,7 @@ export class TaxRegion {
|
||||
* console.log(tax_regions)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin#select-fields-and-relations).
|
||||
*/
|
||||
async list(
|
||||
|
||||
Reference in New Issue
Block a user