Skip to content

Commit

Permalink
chore(types): add price types for shipping option endpoints (medusajs…
Browse files Browse the repository at this point in the history
…#10509)

what:

- adds missing price types for shipping options
  • Loading branch information
riqwan authored Dec 9, 2024
1 parent 9534751 commit f8f5d57
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
"rules.operator",

"calculated_price.*",
"prices.*",
"prices.price_rules.*",
],
variables: queryVariables,
}).config({ name: "shipping-options-query" })
Expand Down
15 changes: 13 additions & 2 deletions packages/core/types/src/http/fulfillment/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ShippingOptionPriceType } from "../../../fulfillment"
import { StoreCalculatedPrice, StorePrice } from "../../pricing/store/entities"

// TODO: The way the cart shipping options are listed now differs from most other endpoints as it is fetched in a workflow.
// We should consider refactoring this to be more consistent with other endpoints.
Expand All @@ -13,7 +14,7 @@ export interface StoreCartShippingOption {
name: string
/**
* The type of the shipping option's price. `flat` means the price
* is fixed, whereas `calculated` means the price is calculated by the
* is fixed, whereas `calculated` means the price is calculated by the
* associated fulfillment provider.
*/
price_type: ShippingOptionPriceType
Expand All @@ -31,7 +32,7 @@ export interface StoreCartShippingOption {
provider_id: string
/**
* The data useful for the fulfillment provider when handling the shipment and fulfillment.
*
*
* Learn more in [this documentation](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#data-property).
*/
data: Record<string, unknown> | null
Expand Down Expand Up @@ -73,4 +74,14 @@ export interface StoreCartShippingOption {
* The shipping option's amount.
*/
amount: number

/**
* All the prices for this shipping option
*/
prices: StorePrice[]

/**
* Calculated price for the shipping option
*/
calculated_price: StoreCalculatedPrice
}
1 change: 1 addition & 0 deletions packages/core/types/src/http/pricing/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./admin"
export * from "./store"
56 changes: 56 additions & 0 deletions packages/core/types/src/http/pricing/store/entities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { PricingRuleOperatorValues } from "../../../pricing"
import { BaseCalculatedPriceSet } from "../common"

export interface StorePrice {
/**
* The price's ID.
*/
id: string
/**
* The price's currency code.
*
* @example
* usd
*/
currency_code: string
/**
* The price's amount.
*/
amount: number
/**
* The minimum quantity that must be available in the cart for the price to be applied.
*/
min_quantity: number | null
/**
* The maximum quantity allowed to be available in the cart for the price to be applied.
*/
max_quantity: number | null

/**
* The rules enabled to enable the current price
*/
price_rules?: StorePriceRule[]
}

export interface StorePriceRule {
/**
* The ID of the price rule.
*/
id: string
/**
* The attribute of the price rule
*/
attribute: string

/**
* The operator of the price rule
*/
operator: PricingRuleOperatorValues

/**
* The value of the price rule.
*/
value: string
}

export interface StoreCalculatedPrice extends BaseCalculatedPriceSet {}
1 change: 1 addition & 0 deletions packages/core/types/src/http/pricing/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./entities"

0 comments on commit f8f5d57

Please sign in to comment.