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 */