diff --git a/.changeset/forty-seas-begin.md b/.changeset/forty-seas-begin.md new file mode 100644 index 0000000000..ceb365cf83 --- /dev/null +++ b/.changeset/forty-seas-begin.md @@ -0,0 +1,5 @@ +--- +"@medusajs/core-flows": patch +--- + +chore(core-flows): update the TSDocs of new steps diff --git a/packages/core/core-flows/src/cart/steps/validate-shipping.ts b/packages/core/core-flows/src/cart/steps/validate-shipping.ts index d9a8f62cb0..3e49427f68 100644 --- a/packages/core/core-flows/src/cart/steps/validate-shipping.ts +++ b/packages/core/core-flows/src/cart/steps/validate-shipping.ts @@ -8,12 +8,27 @@ import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { MedusaError } from "../../../../utils/dist/common" +/** + * The data to validate shipping data when cart is completed. + */ export type ValidateShippingInput = { + /** + * The cart's details. + */ cart: Omit & { + /** + * The cart's line items. + */ items: (CartLineItemDTO & { + /** + * The item's variant. + */ variant: ProductVariantDTO })[] } + /** + * The selected shipping options. + */ shippingOptions: ShippingOptionDTO[] } @@ -22,7 +37,39 @@ export const validateShippingStepId = "validate-shipping" * This step validates shipping data when cart is completed. * * It ensures that a shipping method is selected if there is an item in the cart that requires shipping. - * It also ensures that product's shipping profile mathes the selected shipping options. + * It also ensures that product's shipping profile mathes the selected shipping options. If the + * conditions are not met, an error is thrown. + * + * :::note + * + * You can retrieve cart or shipping option's details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query), + * or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep). + * + * ::: + * + * @example + * validateShippingStep({ + * cart: { + * id: "cart_123", + * items: [ + * { + * id: "item_123", + * variant: { + * id: "variant_123", + * // other item details... + * }, + * } + * ], + * // other cart details... + * }, + * shippingOptions: [ + * { + * id: "option_123", + * shipping_profile_id: "sp_123", + * // other option details... + * } + * ] + * }) */ export const validateShippingStep = createStep( validateShippingStepId, diff --git a/packages/core/core-flows/src/product/workflows/create-products.ts b/packages/core/core-flows/src/product/workflows/create-products.ts index f837533ea2..3a7911cfc5 100644 --- a/packages/core/core-flows/src/product/workflows/create-products.ts +++ b/packages/core/core-flows/src/product/workflows/create-products.ts @@ -46,7 +46,7 @@ export interface ValidateProductInputStepInput { const validateProductInputStepId = "validate-product-input" /** * This step validates that all provided products have options. - * If a product is missing options, an error is thrown. + * If a product is missing options or a shipping profile, an error is thrown. * * @example * const data = validateProductInputStep({ diff --git a/packages/core/core-flows/src/shipping-profile/workflows/delete-shipping-profile.ts b/packages/core/core-flows/src/shipping-profile/workflows/delete-shipping-profile.ts index 4ddbe6a8f7..fa3bbe6894 100644 --- a/packages/core/core-flows/src/shipping-profile/workflows/delete-shipping-profile.ts +++ b/packages/core/core-flows/src/shipping-profile/workflows/delete-shipping-profile.ts @@ -9,11 +9,41 @@ import { deleteShippingProfilesStep } from "../steps" import { removeRemoteLinkStep, useQueryGraphStep } from "../../common" /** - * This step validates that the shipping profiles to delete are not linked to any products. + * The data to validate the deletion of shipping profiles. */ -const validateStepShippingProfileDelete = createStep( +export type ValidateStepShippingProfileDeleteInput = { + /** + * The links between products and shipping profiles. + */ + links: { + /** + * The ID of the product linked to the shipping profile. + */ + product_id: string + /** + * The ID of the shipping profile to be deleted. + */ + shipping_profile_id: string + }[] +} + +/** + * This step validates that the shipping profiles to delete are not linked to any products. + * Otherwise, an error is thrown. + * + * @example + * validateStepShippingProfileDelete({ + * links: [ + * { + * product_id: "product_123", + * shipping_profile_id: "sp_123" + * } + * ] + * }) + */ +export const validateStepShippingProfileDelete = createStep( "validate-step-shipping-profile-delete", - (data: { links: { product_id: string; shipping_profile_id: string }[] }) => { + (data: ValidateStepShippingProfileDeleteInput ) => { const { links } = data if (links.length > 0) {