From c4dd805849fee483d52ee61078e15f9be111b414 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Wed, 7 May 2025 12:02:08 +0300 Subject: [PATCH] fix(core-flows): export order-related utility workflows (#12380) --- .changeset/good-kiwis-applaud.md | 5 ++++ .../workflows/convert-draft-order.ts | 2 +- packages/core/core-flows/src/order/index.ts | 3 +- .../claim/create-claim-shipping-method.ts | 2 +- .../order/workflows/claim/refresh-shipping.ts | 2 +- .../create-exchange-shipping-method.ts | 2 +- .../workflows/exchange/refresh-shipping.ts | 2 +- .../fetch-shipping-option.ts | 4 +-- .../core-flows/src/order/workflows/index.ts | 2 ++ .../maybe-refresh-shipping-methods.ts | 30 +++++++++++++++++-- .../return/create-return-shipping-method.ts | 2 +- .../workflows/return/refresh-shipping.ts | 2 +- .../src/payment/workflows/process-payment.ts | 2 +- .../src/workflow/order/request-transfer.ts | 16 ++++++++++ packages/core/utils/src/core-flows/events.ts | 2 +- 15 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 .changeset/good-kiwis-applaud.md rename packages/core/core-flows/src/order/{utils => workflows}/fetch-shipping-option.ts (98%) rename packages/core/core-flows/src/order/{utils => workflows}/maybe-refresh-shipping-methods.ts (83%) diff --git a/.changeset/good-kiwis-applaud.md b/.changeset/good-kiwis-applaud.md new file mode 100644 index 0000000000..6c8c9814c6 --- /dev/null +++ b/.changeset/good-kiwis-applaud.md @@ -0,0 +1,5 @@ +--- +"@medusajs/core-flows": patch +--- + +fix(core-flows): export order-related workflows diff --git a/packages/core/core-flows/src/draft-order/workflows/convert-draft-order.ts b/packages/core/core-flows/src/draft-order/workflows/convert-draft-order.ts index b427132081..8753caa13b 100644 --- a/packages/core/core-flows/src/draft-order/workflows/convert-draft-order.ts +++ b/packages/core/core-flows/src/draft-order/workflows/convert-draft-order.ts @@ -14,7 +14,7 @@ import { IOrderModuleService, OrderDTO } from "@medusajs/types" import { emitEventStep, useRemoteQueryStep } from "../../common" import { validateDraftOrderStep } from "../steps/validate-draft-order" -const convertDraftOrderWorkflowId = "convert-draft-order" +export const convertDraftOrderWorkflowId = "convert-draft-order" /** * The details of the draft order to convert to an order. diff --git a/packages/core/core-flows/src/order/index.ts b/packages/core/core-flows/src/order/index.ts index 5f45d573ed..c4c6682e60 100644 --- a/packages/core/core-flows/src/order/index.ts +++ b/packages/core/core-flows/src/order/index.ts @@ -1,3 +1,2 @@ export * from "./steps" -export * from "./workflows" -export * from "./utils/fetch-shipping-option" \ No newline at end of file +export * from "./workflows" \ No newline at end of file diff --git a/packages/core/core-flows/src/order/workflows/claim/create-claim-shipping-method.ts b/packages/core/core-flows/src/order/workflows/claim/create-claim-shipping-method.ts index 82ae6f09ed..b121bc6d16 100644 --- a/packages/core/core-flows/src/order/workflows/claim/create-claim-shipping-method.ts +++ b/packages/core/core-flows/src/order/workflows/claim/create-claim-shipping-method.ts @@ -23,7 +23,7 @@ import { import { prepareShippingMethod } from "../../utils/prepare-shipping-method" import { createOrderChangeActionsWorkflow } from "../create-order-change-actions" import { updateOrderTaxLinesWorkflow } from "../update-tax-lines" -import { fetchShippingOptionForOrderWorkflow } from "../../utils/fetch-shipping-option" +import { fetchShippingOptionForOrderWorkflow } from "../fetch-shipping-option" /** * The data to validate that a shipping method can be created for a claim. diff --git a/packages/core/core-flows/src/order/workflows/claim/refresh-shipping.ts b/packages/core/core-flows/src/order/workflows/claim/refresh-shipping.ts index e16bbe3ccb..0174a7143b 100644 --- a/packages/core/core-flows/src/order/workflows/claim/refresh-shipping.ts +++ b/packages/core/core-flows/src/order/workflows/claim/refresh-shipping.ts @@ -7,7 +7,7 @@ import { when, } from "@medusajs/framework/workflows-sdk" -import { maybeRefreshShippingMethodsWorkflow } from "../../utils/maybe-refresh-shipping-methods" +import { maybeRefreshShippingMethodsWorkflow } from "../maybe-refresh-shipping-methods" import { useQueryGraphStep } from "../../../common" /** diff --git a/packages/core/core-flows/src/order/workflows/exchange/create-exchange-shipping-method.ts b/packages/core/core-flows/src/order/workflows/exchange/create-exchange-shipping-method.ts index b96cd6f28f..718965521c 100644 --- a/packages/core/core-flows/src/order/workflows/exchange/create-exchange-shipping-method.ts +++ b/packages/core/core-flows/src/order/workflows/exchange/create-exchange-shipping-method.ts @@ -23,7 +23,7 @@ import { import { prepareShippingMethod } from "../../utils/prepare-shipping-method" import { createOrderChangeActionsWorkflow } from "../create-order-change-actions" import { updateOrderTaxLinesWorkflow } from "../update-tax-lines" -import { fetchShippingOptionForOrderWorkflow } from "../../utils/fetch-shipping-option" +import { fetchShippingOptionForOrderWorkflow } from "../fetch-shipping-option" /** * The data to validate that a shipping method can be created for an exchange. diff --git a/packages/core/core-flows/src/order/workflows/exchange/refresh-shipping.ts b/packages/core/core-flows/src/order/workflows/exchange/refresh-shipping.ts index b52ca9046c..0983ecb06a 100644 --- a/packages/core/core-flows/src/order/workflows/exchange/refresh-shipping.ts +++ b/packages/core/core-flows/src/order/workflows/exchange/refresh-shipping.ts @@ -8,7 +8,7 @@ import { when, } from "@medusajs/framework/workflows-sdk" -import { maybeRefreshShippingMethodsWorkflow } from "../../utils/maybe-refresh-shipping-methods" +import { maybeRefreshShippingMethodsWorkflow } from "../maybe-refresh-shipping-methods" import { useQueryGraphStep } from "../../../common" /** diff --git a/packages/core/core-flows/src/order/utils/fetch-shipping-option.ts b/packages/core/core-flows/src/order/workflows/fetch-shipping-option.ts similarity index 98% rename from packages/core/core-flows/src/order/utils/fetch-shipping-option.ts rename to packages/core/core-flows/src/order/workflows/fetch-shipping-option.ts index 2e30974513..1a6d484a9b 100644 --- a/packages/core/core-flows/src/order/utils/fetch-shipping-option.ts +++ b/packages/core/core-flows/src/order/workflows/fetch-shipping-option.ts @@ -46,7 +46,7 @@ const COMMON_OPTIONS_FIELDS = [ /** * The data to create a shipping method for an order edit. */ -export type FetchShippingOptionForOrderWorkflowInput = { +export type FetchShippingOptionForOrderWorkflowInput = AdditionalData & { /** * The ID of the shipping option to fetch. */ @@ -165,7 +165,7 @@ export const fetchShippingOptionsForOrderWorkflowId = "fetch-shipping-option" */ export const fetchShippingOptionForOrderWorkflow = createWorkflow( fetchShippingOptionsForOrderWorkflowId, - function (input: FetchShippingOptionForOrderWorkflowInput & AdditionalData) { + function (input: FetchShippingOptionForOrderWorkflowInput) { const initialOption = useRemoteQueryStep({ entry_point: "shipping_option", variables: { id: input.shipping_option_id }, diff --git a/packages/core/core-flows/src/order/workflows/index.ts b/packages/core/core-flows/src/order/workflows/index.ts index 09844ab602..676b13abde 100644 --- a/packages/core/core-flows/src/order/workflows/index.ts +++ b/packages/core/core-flows/src/order/workflows/index.ts @@ -30,6 +30,7 @@ export * from "./decline-order-change" export * from "./delete-order-change" export * from "./delete-order-change-actions" export * from "./delete-order-payment-collection" +export * from "./fetch-shipping-option" export * from "./exchange/begin-order-exchange" export * from "./exchange/cancel-begin-order-exchange" export * from "./exchange/cancel-exchange" @@ -45,6 +46,7 @@ export * from "./get-order-detail" export * from "./get-orders-list" export * from "./mark-order-fulfillment-as-delivered" export * from "./mark-payment-collection-as-paid" +export * from "./maybe-refresh-shipping-methods" export * from "./order-edit/begin-order-edit" export * from "./order-edit/cancel-begin-order-edit" export * from "./order-edit/confirm-order-edit-request" diff --git a/packages/core/core-flows/src/order/utils/maybe-refresh-shipping-methods.ts b/packages/core/core-flows/src/order/workflows/maybe-refresh-shipping-methods.ts similarity index 83% rename from packages/core/core-flows/src/order/utils/maybe-refresh-shipping-methods.ts rename to packages/core/core-flows/src/order/workflows/maybe-refresh-shipping-methods.ts index 0388bd4010..3ca85d65d8 100644 --- a/packages/core/core-flows/src/order/utils/maybe-refresh-shipping-methods.ts +++ b/packages/core/core-flows/src/order/workflows/maybe-refresh-shipping-methods.ts @@ -68,8 +68,34 @@ export type MaybeRefreshShippingMethodsWorkflowInput = { export const maybeRefreshShippingMethodsWorkflowId = "maybe-refresh-shipping-methods" /** - * This workflows refreshes shipping method an order (used in RMA flows). - * The shipping method and the action is updated if the shipping option is calculated. + * This workflows refreshes shipping method prices of an order and its changes. It's used in Return Merchandise Authorization (RMA) flows. It's used + * by other workflows, such as {@link refreshExchangeShippingWorkflow}. + * + * You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around + * refreshing shipping methods in your custom flows. + * + * @example + * const { result } = await maybeRefreshShippingMethodsWorkflow(container) + * .run({ + * input: { + * shipping_method_id: "shipping_method_123", + * order_id: "order_123", + * action_id: "orchact_123", + * context: { + * return_id: "ret_123", + * return_items: [ + * { + * id: "orli_123", + * quantity: 1, + * } + * ] + * } + * } + * }) + * + * @summary + * + * Refreshes the shipping method prices of an order and its changes. */ export const maybeRefreshShippingMethodsWorkflow = createWorkflow( maybeRefreshShippingMethodsWorkflowId, diff --git a/packages/core/core-flows/src/order/workflows/return/create-return-shipping-method.ts b/packages/core/core-flows/src/order/workflows/return/create-return-shipping-method.ts index eb5344dab1..77cc3bcc2b 100644 --- a/packages/core/core-flows/src/order/workflows/return/create-return-shipping-method.ts +++ b/packages/core/core-flows/src/order/workflows/return/create-return-shipping-method.ts @@ -22,7 +22,7 @@ import { import { prepareShippingMethod } from "../../utils/prepare-shipping-method" import { createOrderChangeActionsWorkflow } from "../create-order-change-actions" import { updateOrderTaxLinesWorkflow } from "../update-tax-lines" -import { fetchShippingOptionForOrderWorkflow } from "../../utils/fetch-shipping-option" +import { fetchShippingOptionForOrderWorkflow } from "../fetch-shipping-option" /** * The data to validate that a shipping method can be created for a return. diff --git a/packages/core/core-flows/src/order/workflows/return/refresh-shipping.ts b/packages/core/core-flows/src/order/workflows/return/refresh-shipping.ts index d833f8257e..802fff4ce6 100644 --- a/packages/core/core-flows/src/order/workflows/return/refresh-shipping.ts +++ b/packages/core/core-flows/src/order/workflows/return/refresh-shipping.ts @@ -8,7 +8,7 @@ import { when, } from "@medusajs/framework/workflows-sdk" -import { maybeRefreshShippingMethodsWorkflow } from "../../utils/maybe-refresh-shipping-methods" +import { maybeRefreshShippingMethodsWorkflow } from "../maybe-refresh-shipping-methods" import { useQueryGraphStep } from "../../../common" /** diff --git a/packages/core/core-flows/src/payment/workflows/process-payment.ts b/packages/core/core-flows/src/payment/workflows/process-payment.ts index 4926dd84f6..e357021eff 100644 --- a/packages/core/core-flows/src/payment/workflows/process-payment.ts +++ b/packages/core/core-flows/src/payment/workflows/process-payment.ts @@ -9,7 +9,7 @@ import { capturePaymentWorkflow } from "./capture-payment" /** * The data to process a payment from a webhook action. */ -interface ProcessPaymentWorkflowInput extends WebhookActionResult {} +export interface ProcessPaymentWorkflowInput extends WebhookActionResult {} export const processPaymentWorkflowId = "process-payment-workflow" /** diff --git a/packages/core/types/src/workflow/order/request-transfer.ts b/packages/core/types/src/workflow/order/request-transfer.ts index f557f5f329..5166370a08 100644 --- a/packages/core/types/src/workflow/order/request-transfer.ts +++ b/packages/core/types/src/workflow/order/request-transfer.ts @@ -1,8 +1,24 @@ export interface RequestOrderTransferWorkflowInput { + /** + * The ID of the order to transfer. + */ order_id: string + /** + * The ID of the customer to transfer the order to. + */ customer_id: string + /** + * The ID of the logged in user requesting the transfer. + * Can be an admin user or a customer. + */ logged_in_user: string + /** + * Details of the transfer request. + */ description?: string + /** + * A note viewed by admin users only. + */ internal_note?: string } diff --git a/packages/core/utils/src/core-flows/events.ts b/packages/core/utils/src/core-flows/events.ts index 703c68c374..b5ac78a81f 100644 --- a/packages/core/utils/src/core-flows/events.ts +++ b/packages/core/utils/src/core-flows/events.ts @@ -38,7 +38,7 @@ export const CartWorkflowEvents = { CUSTOMER_UPDATED: "cart.customer_updated", /** * Emitted when the cart's region is updated. This - * event is emitted alongside the {@link CartWorkflowEvents.UPDATED} event. + * event is emitted alongside the `cart.updated` event. * * @eventPayload * ```ts