feat: Add metadata to shipping options endpoints (#13554)

This commit is contained in:
Bastien
2025-09-19 12:28:20 +02:00
committed by GitHub
parent 5b7187c261
commit bb6cc586f7
4 changed files with 74 additions and 15 deletions

View File

@@ -292,6 +292,54 @@ medusaIntegrationTestRunner({
metadata: null, metadata: null,
}) })
}) })
it("should retrieve a shipping option with metadata successfully", async () => {
const shippingOptionPayload = {
name: "Test shipping option with metadata",
service_zone_id: fulfillmentSet.service_zones[0].id,
shipping_profile_id: shippingProfile.id,
provider_id: "manual_test-provider",
price_type: "flat",
type: {
label: "Test type",
description: "Test description",
code: "test-code",
},
prices: [{ currency_code: "usd", amount: 1000 }],
metadata: {
priority: "high",
tracking: "enabled",
carrier: "express",
specialHandling: true,
},
}
const {
data: { shipping_option: shippingOption },
} = await api.post(
`/admin/shipping-options`,
shippingOptionPayload,
adminHeaders
)
const shippingOptionRes = await api.get(
`/admin/shipping-options/${shippingOption.id}`,
adminHeaders
)
expect(shippingOptionRes.data.shipping_option).toEqual(
expect.objectContaining({
id: expect.any(String),
name: "Test shipping option with metadata",
metadata: {
priority: "high",
tracking: "enabled",
carrier: "express",
specialHandling: true,
},
})
)
})
}) })
describe("POST /admin/shipping-options", () => { describe("POST /admin/shipping-options", () => {

View File

@@ -55,21 +55,21 @@ export interface AdminUpdateShippingOptionType {
interface AdminShippingOptionPriceRulePayload { interface AdminShippingOptionPriceRulePayload {
/** /**
* The operator of the shipping option price rule. * The operator of the shipping option price rule.
* *
* @example * @example
* "eq" * "eq"
*/ */
operator: string operator: string
/** /**
* The attribute of the shipping option price rule. * The attribute of the shipping option price rule.
* *
* @example * @example
* "region_id" * "region_id"
*/ */
attribute: string attribute: string
/** /**
* The value of the shipping option price rule. * The value of the shipping option price rule.
* *
* @example * @example
* "region_123" * "region_123"
*/ */
@@ -88,7 +88,7 @@ export interface AdminCreateShippingOptionPriceWithCurrency
extends AdminShippingOptionPriceWithRules { extends AdminShippingOptionPriceWithRules {
/** /**
* The currency code of the shipping option price. * The currency code of the shipping option price.
* *
* @example * @example
* "usd" * "usd"
*/ */
@@ -115,21 +115,21 @@ export interface AdminCreateShippingOption {
/** /**
* The name of the shipping option. Customers can * The name of the shipping option. Customers can
* view this name during checkout. * view this name during checkout.
* *
* @example * @example
* "Standard Shipping" * "Standard Shipping"
*/ */
name: string name: string
/** /**
* The ID of the service zone that the shipping option belongs to. * The ID of the service zone that the shipping option belongs to.
* *
* Learn more in the [Shipping Options](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#service-zone-restrictions) * Learn more in the [Shipping Options](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#service-zone-restrictions)
* documentation. * documentation.
*/ */
service_zone_id: string service_zone_id: string
/** /**
* The ID of the shipping profile that the shipping option belongs to. * The ID of the shipping profile that the shipping option belongs to.
* *
* Learn more in the [Shipping Options](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types) * Learn more in the [Shipping Options](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types)
* documentation. * documentation.
*/ */
@@ -137,7 +137,7 @@ export interface AdminCreateShippingOption {
/** /**
* Additional data that is useful for third-party fulfillment providers * Additional data that is useful for third-party fulfillment providers
* that process fulfillments for the shipping option. * that process fulfillments for the shipping option.
* *
* Learn more in the [Shipping Options](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#data-property) * Learn more in the [Shipping Options](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#data-property)
* documentation. * documentation.
*/ */
@@ -152,7 +152,7 @@ export interface AdminCreateShippingOption {
provider_id: string provider_id: string
/** /**
* The type of shipping option. * The type of shipping option.
* *
* Learn more in the [Shipping Option](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types) * Learn more in the [Shipping Option](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types)
* documentation. * documentation.
*/ */
@@ -173,11 +173,15 @@ export interface AdminCreateShippingOption {
)[] )[]
/** /**
* The rules of the shipping option. * The rules of the shipping option.
* *
* Learn more in the [Shipping Option Rules](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-option-rules) * Learn more in the [Shipping Option Rules](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-option-rules)
* documentation. * documentation.
*/ */
rules?: AdminCreateShippingOptionRule[] rules?: AdminCreateShippingOptionRule[]
/**
* Custom key-value pairs that can be added to the shipping option.
*/
metadata?: Record<string, unknown>
} }
export interface AdminUpdateShippingOptionRule export interface AdminUpdateShippingOptionRule
@@ -197,7 +201,7 @@ export interface AdminUpdateShippingOptionPriceWithCurrency
id?: string id?: string
/** /**
* The currency code of the shipping option price. * The currency code of the shipping option price.
* *
* @example * @example
* "usd" * "usd"
*/ */
@@ -229,7 +233,7 @@ export interface AdminUpdateShippingOption {
/** /**
* The name of the shipping option. Customers can * The name of the shipping option. Customers can
* view this name during checkout. * view this name during checkout.
* *
* @example * @example
* "Standard Shipping" * "Standard Shipping"
*/ */
@@ -249,14 +253,14 @@ export interface AdminUpdateShippingOption {
provider_id?: string provider_id?: string
/** /**
* The ID of the shipping profile that the shipping option belongs to. * The ID of the shipping profile that the shipping option belongs to.
* *
* Learn more in the [Shipping Options](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types) * Learn more in the [Shipping Options](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types)
* documentation. * documentation.
*/ */
shipping_profile_id?: string shipping_profile_id?: string
/** /**
* The type of shipping option. * The type of shipping option.
* *
* Learn more in the [Shipping Options](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types) * Learn more in the [Shipping Options](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types)
* documentation. * documentation.
*/ */
@@ -277,11 +281,15 @@ export interface AdminUpdateShippingOption {
)[] )[]
/** /**
* The rules of the shipping option. * The rules of the shipping option.
* *
* Learn more in the [Shipping Option Rules](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-option-rules) * Learn more in the [Shipping Option Rules](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-option-rules)
* documentation. * documentation.
*/ */
rules?: (AdminUpdateShippingOptionRule | AdminCreateShippingOptionRule)[] rules?: (AdminUpdateShippingOptionRule | AdminCreateShippingOptionRule)[]
/**
* Custom key-value pairs that can be added to the shipping option.
*/
metadata?: Record<string, unknown>
} }
export interface AdminUpdateShippingOptionRules { export interface AdminUpdateShippingOptionRules {

View File

@@ -142,6 +142,7 @@ export const AdminCreateShippingOption = z
AdminCreateShippingOptionPriceWithRegion AdminCreateShippingOptionPriceWithRegion
).array(), ).array(),
rules: AdminCreateShippingOptionRule.array().optional(), rules: AdminCreateShippingOptionRule.array().optional(),
metadata: z.record(z.unknown()).optional(),
}) })
.strict() .strict()
.refine((data) => isDefined(data.type_id) !== isDefined(data.type), { .refine((data) => isDefined(data.type_id) !== isDefined(data.type), {
@@ -170,6 +171,7 @@ export const AdminUpdateShippingOption = z
rules: AdminUpdateShippingOptionRule.or(AdminCreateShippingOptionRule) rules: AdminUpdateShippingOptionRule.or(AdminCreateShippingOptionRule)
.array() .array()
.optional(), .optional(),
metadata: z.record(z.unknown()).optional(),
}) })
.strict() .strict()
.refine( .refine(

View File

@@ -6,6 +6,7 @@ export const defaultStoreShippingOptionsFields = [
"shipping_profile_id", "shipping_profile_id",
"fulfillment_provider_id", "fulfillment_provider_id",
"shipping_option_type_id", "shipping_option_type_id",
"metadata",
] ]
export const listTransformQueryConfig = { export const listTransformQueryConfig = {