From 28d57b7bf8bceee62449564228b9e08d4f706cd7 Mon Sep 17 00:00:00 2001 From: William Bouchard <46496014+willbouch@users.noreply.github.com> Date: Mon, 6 Oct 2025 11:22:55 -0400 Subject: [PATCH] fix(types): missing rules in prices types (#13669) This was missing from the types although they are in validators. https://github.com/medusajs/medusa/blob/bb6cc586f7e883ea2eaa29ef459f8b3dbd3a345b/packages/medusa/src/api/admin/shipping-options/validators.ts#L88-L103 CLOSES #13610 CLOSES #12910 --- .changeset/metal-mayflies-add.md | 5 ++ .../http/shipping-option/admin/payloads.ts | 63 +++++++++---------- .../fulfillment/create-shipping-options.ts | 7 ++- 3 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 .changeset/metal-mayflies-add.md diff --git a/.changeset/metal-mayflies-add.md b/.changeset/metal-mayflies-add.md new file mode 100644 index 0000000000..82d036440d --- /dev/null +++ b/.changeset/metal-mayflies-add.md @@ -0,0 +1,5 @@ +--- +"@medusajs/types": patch +--- + +fix(types): missing rules in prices types diff --git a/packages/core/types/src/http/shipping-option/admin/payloads.ts b/packages/core/types/src/http/shipping-option/admin/payloads.ts index 701b6d9e7b..ccd93d2219 100644 --- a/packages/core/types/src/http/shipping-option/admin/payloads.ts +++ b/packages/core/types/src/http/shipping-option/admin/payloads.ts @@ -1,5 +1,6 @@ import { RuleOperatorType } from "../../../common" import { ShippingOptionPriceType } from "../../../fulfillment" +import { PriceRule } from "../../../pricing" export interface AdminCreateShippingOptionRule { /** @@ -52,36 +53,12 @@ export interface AdminUpdateShippingOptionType { code?: string } -interface AdminShippingOptionPriceRulePayload { - /** - * The operator of the shipping option price rule. - * - * @example - * "eq" - */ - operator: string - /** - * The attribute of the shipping option price rule. - * - * @example - * "region_id" - */ - attribute: string - /** - * The value of the shipping option price rule. - * - * @example - * "region_123" - */ - value: string | string[] | number -} - interface AdminShippingOptionPriceWithRules { /** * The rules of the shipping option price that * indicate when the price should be applied. */ - rules?: AdminShippingOptionPriceRulePayload[] + rules?: PriceRule[] } export interface AdminCreateShippingOptionPriceWithCurrency @@ -111,7 +88,10 @@ export interface AdminCreateShippingOptionPriceWithRegion amount: number } -export interface AdminCreateShippingOption { +/** + * Common properties for all shipping option create inputs. + */ +interface AdminCreateShippingOptionBase { /** * The name of the shipping option. Customers can * view this name during checkout. @@ -164,13 +144,6 @@ export interface AdminCreateShippingOption { * documentation. */ type_id?: string - /** - * The prices of the shipping option. - */ - prices: ( - | AdminCreateShippingOptionPriceWithCurrency - | AdminCreateShippingOptionPriceWithRegion - )[] /** * The rules of the shipping option. * @@ -184,6 +157,30 @@ export interface AdminCreateShippingOption { metadata?: Record } +/** + * Flat rate shipping option creation input. + */ +export interface AdminCreateFlatRateShippingOption + extends AdminCreateShippingOptionBase { + price_type: "flat" + prices: ( + | AdminCreateShippingOptionPriceWithCurrency + | AdminCreateShippingOptionPriceWithRegion + )[] +} + +/** + * Calculated shipping option creation input. + */ +export interface AdminCreateCalculatedShippingOption + extends AdminCreateShippingOptionBase { + price_type: "calculated" +} + +export type AdminCreateShippingOption = + | AdminCreateFlatRateShippingOption + | AdminCreateCalculatedShippingOption + export interface AdminUpdateShippingOptionRule extends AdminCreateShippingOptionRule { /** diff --git a/packages/core/types/src/workflow/fulfillment/create-shipping-options.ts b/packages/core/types/src/workflow/fulfillment/create-shipping-options.ts index 2976402d1d..56a9c2336e 100644 --- a/packages/core/types/src/workflow/fulfillment/create-shipping-options.ts +++ b/packages/core/types/src/workflow/fulfillment/create-shipping-options.ts @@ -1,14 +1,17 @@ import { ShippingOptionDTO } from "../../fulfillment" import { RuleOperatorType } from "../../common" +import { PriceRule } from "../../pricing" type CreateFlatRateShippingOptionPriceRecord = | { currency_code: string amount: number + rules?: PriceRule[] } | { region_id: string amount: number + rules?: PriceRule[] } /** @@ -69,14 +72,14 @@ type CreateFlatShippingOptionInputBase = { attribute: string /** * The operator to use when matching the attribute. - * + * * @example * in */ operator: RuleOperatorType /** * The value to match against. - * + * * @example * cusgrp_123 */