Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(types): add price types for shipping option endpoints #10509

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading