Skip to content

Commit 61565d2

Browse files
authored
chore: improve TSDocs for tax provider module (medusajs#13846)
1 parent 8d574d6 commit 61565d2

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

packages/core/types/src/tax/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ export interface TaxCalculationContext {
523523
interface TaxLineDTO {
524524
/**
525525
* The associated rate's ID.
526+
* When integrating with a third-party, you don't need to provide it.
527+
* This is mainly used for the built-in rates.
526528
*/
527529
rate_id?: string
528530

packages/core/types/src/tax/provider.ts

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export type ItemTaxCalculationLine = {
5757
*
5858
* ### constructor
5959
*
60-
* You can use the `constructor` of your tax provider to access the resources registered in the [Module Container](https://docs.medusajs.com/resources/medusa-container-resources#module-container-resources).
60+
* You can use the `constructor` of your Tax Module Provider's service to access the resources registered in the [Module Container](https://docs.medusajs.com/resources/medusa-container-resources#module-container-resources).
6161
*
6262
* You can also use the constructor to initialize your integration with the third-party provider. For example, if you use a client to connect to the third-party provider’s APIs, you can initialize it in the constructor and use it in other methods in the service.
6363
*
@@ -66,13 +66,34 @@ export type ItemTaxCalculationLine = {
6666
* For example:
6767
*
6868
* ```ts
69+
* import {
70+
* ITaxProvider,
71+
* Logger
72+
* } from "@medusajs/framework/types"
73+
*
74+
* type InjectedDependencies = {
75+
* logger: Logger
76+
* }
77+
*
78+
* type Options = {
79+
* apiKey: string
80+
* }
81+
*
6982
* export default class MyTaxProvider implements ITaxProvider {
70-
* // ...
71-
* constructor(container, options) {
72-
* // you can access options here
83+
* static identifier = "my-tax"
84+
* protected logger_: Logger
85+
* protected options_: Options
86+
* // assuming you're initializing a client
87+
* protected client
88+
*
89+
* constructor (
90+
* { logger }: InjectedDependencies,
91+
* options: Options
92+
* ) {
93+
* this.logger_ = logger
94+
* this.options_ = options
7395
*
74-
* // you can also initialize a client that
75-
* // communicates with a third-party service.
96+
* // assuming you're initializing a client
7697
* this.client = new Client(options)
7798
* }
7899
* }
@@ -82,7 +103,18 @@ export type ItemTaxCalculationLine = {
82103
*/
83104
export interface ITaxProvider {
84105
/**
85-
* @ignore
106+
* This method is used to retrieve the unique identifier of the tax provider.
107+
*
108+
* @return {string} The unique identifier of the tax provider.
109+
*
110+
* @example
111+
* export default class MyTaxProvider implements ITaxProvider {
112+
* static identifier = "my-tax"
113+
*
114+
* getIdentifier(): string {
115+
* return MyTaxProvider.identifier
116+
* }
117+
* }
86118
*/
87119
getIdentifier(): string
88120

@@ -115,8 +147,8 @@ export interface ITaxProvider {
115147
* let taxLines: (TaxTypes.ItemTaxLineDTO | TaxTypes.ShippingTaxLineDTO)[] =
116148
* itemLines.flatMap((l) => {
117149
* return l.rates.map((r) => ({
118-
* rate_id: r.id,
119-
* rate: r.rate || 0,
150+
* rate_id: r.id, // this is optional. When integrating with a third-party, you don't need to provide it
151+
* rate: r.rate || 0, // For example, 10 for 10%
120152
* name: r.name,
121153
* code: r.code,
122154
* line_item_id: l.line_item.id,
@@ -127,8 +159,8 @@ export interface ITaxProvider {
127159
* taxLines = taxLines.concat(
128160
* shippingLines.flatMap((l) => {
129161
* return l.rates.map((r) => ({
130-
* rate_id: r.id,
131-
* rate: r.rate || 0,
162+
* rate_id: r.id, // this is optional. When integrating with a third-party, you don't need to provide it
163+
* rate: r.rate || 0, // For example, 10 for 10%
132164
* name: r.name,
133165
* code: r.code,
134166
* shipping_line_id: l.shipping_line.id,

0 commit comments

Comments
 (0)