chore(core-flows, types): add tsdocs for draft orders workflows (#12279)

This commit is contained in:
Shahed Nasser
2025-04-24 11:31:28 +03:00
committed by GitHub
parent 7d498227d1
commit 71a5dc448d
34 changed files with 918 additions and 36 deletions

View File

@@ -8,11 +8,35 @@ import {
export const createDraftOrderLineItemAdjustmentsStepId =
"create-draft-order-line-item-adjustments"
interface CreateDraftOrderLineItemAdjustmentsStepInput {
/**
* The details of the line item adjustments to create.
*/
export interface CreateDraftOrderLineItemAdjustmentsStepInput {
/**
* The ID of the draft order to create the line item adjustments for.
*/
order_id: string
/**
* The line item adjustments to create.
*/
lineItemAdjustmentsToCreate: CreateLineItemAdjustmentDTO[]
}
/**
* This step creates line item adjustments for a draft order.
*
* @example
* const data = createDraftOrderLineItemAdjustmentsStep({
* order_id: "order_123",
* lineItemAdjustmentsToCreate: [
* {
* item_id: "orli_123",
* code: "PROMO_123",
* amount: 10,
* }
* ]
* })
*/
export const createDraftOrderLineItemAdjustmentsStep = createStep(
createDraftOrderLineItemAdjustmentsStepId,
async function (

View File

@@ -8,10 +8,30 @@ import {
export const createDraftOrderShippingMethodAdjustmentsStepId =
"create-draft-order-shipping-method-adjustments"
interface CreateDraftOrderShippingMethodAdjustmentsStepInput {
/**
* The details of the shipping method adjustments to create.
*/
export interface CreateDraftOrderShippingMethodAdjustmentsStepInput {
/**
* The shipping method adjustments to create.
*/
shippingMethodAdjustmentsToCreate: CreateShippingMethodAdjustmentDTO[]
}
/**
* This step creates shipping method adjustments for a draft order.
*
* @example
* const data = createDraftOrderShippingMethodAdjustmentsStep({
* shippingMethodAdjustmentsToCreate: [
* {
* shipping_method_id: "sm_123",
* code: "PROMO_123",
* amount: 10,
* }
* ]
* })
*/
export const createDraftOrderShippingMethodAdjustmentsStep = createStep(
createDraftOrderShippingMethodAdjustmentsStepId,
async function (

View File

@@ -2,10 +2,34 @@ import { Modules } from "@medusajs/framework/utils"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
import { IOrderModuleService, OrderDTO } from "@medusajs/types"
interface GetDraftOrderPromotionContextStepInput {
/**
* The details of the draft order to get the promotion context for.
*/
export interface GetDraftOrderPromotionContextStepInput {
/**
* The draft order to get the promotion context for.
*/
order: OrderDTO
}
/**
* This step gets the promotion context for a draft order.
*
* :::note
*
* You can retrieve a draft order'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
* const data = getDraftOrderPromotionContextStep({
* order: {
* id: "order_123",
* // other order details...
* }
* })
*/
export const getDraftOrderPromotionContextStep = createStep(
"get-draft-order-promotion-context",
async ({ order }: GetDraftOrderPromotionContextStepInput, { container }) => {

View File

@@ -4,10 +4,24 @@ import { IOrderModuleService } from "@medusajs/types"
export const removeDraftOrderLineItemAdjustmentsStepId =
"remove-draft-order-line-item-adjustments"
interface RemoveDraftOrderLineItemAdjustmentsStepInput {
/**
* The details of the line item adjustments to remove.
*/
export interface RemoveDraftOrderLineItemAdjustmentsStepInput {
/**
* The IDs of the line item adjustments to remove.
*/
lineItemAdjustmentIdsToRemove: string[]
}
/**
* This step removes line item adjustments from a draft order.
*
* @example
* const data = removeDraftOrderLineItemAdjustmentsStep({
* lineItemAdjustmentIdsToRemove: ["adj_123", "adj_456"],
* })
*/
export const removeDraftOrderLineItemAdjustmentsStep = createStep(
removeDraftOrderLineItemAdjustmentsStepId,
async function (

View File

@@ -5,10 +5,24 @@ import { IOrderModuleService } from "@medusajs/types"
export const removeDraftOrderShippingMethodAdjustmentsStepId =
"remove-draft-order-shipping-method-adjustments"
interface RemoveDraftOrderShippingMethodAdjustmentsStepInput {
/**
* The details of the shipping method adjustments to remove.
*/
export interface RemoveDraftOrderShippingMethodAdjustmentsStepInput {
/**
* The IDs of the shipping method adjustments to remove.
*/
shippingMethodAdjustmentIdsToRemove: string[]
}
/**
* This step removes shipping method adjustments from a draft order.
*
* @example
* const data = removeDraftOrderShippingMethodAdjustmentsStep({
* shippingMethodAdjustmentIdsToRemove: ["adj_123", "adj_456"],
* })
*/
export const removeDraftOrderShippingMethodAdjustmentsStep = createStep(
removeDraftOrderShippingMethodAdjustmentsStepId,
async function (

View File

@@ -5,20 +5,68 @@ import { BigNumberInput, IOrderModuleService } from "@medusajs/types"
export const restoreDraftOrderShippingMethodsStepId =
"restore-draft-order-shipping-methods"
interface RestoreDraftOrderShippingMethodsStepInput {
/**
* The details of the shipping methods to restore.
*/
export interface RestoreDraftOrderShippingMethodsStepInput {
/**
* The shipping methods to restore.
*/
shippingMethods: {
/**
* The ID of the shipping method.
*/
id: string
/**
* The shipping method's details before the edit.
*/
before: {
/**
* The ID of the shipping option.
*/
shipping_option_id: string
/**
* The amount of the shipping method.
*/
amount: BigNumberInput
}
/**
* The shipping method's details after the edit.
*/
after: {
/**
* The ID of the shipping option.
*/
shipping_option_id: string
/**
* The amount of the shipping method.
*/
amount: BigNumberInput
}
}[]
}
/**
* This step restores the shipping methods of a draft order.
* It's useful when you need to revert changes made by a canceled draft order edit.
*
* @example
* const data = restoreDraftOrderShippingMethodsStep({
* shippingMethods: [
* {
* id: "shipping_method_123",
* before: {
* shipping_option_id: "shipping_option_123",
* amount: 10
* },
* after: {
* shipping_option_id: "shipping_option_123",
* amount: 10
* }
* },
* ],
* })
*/
export const restoreDraftOrderShippingMethodsStep = createStep(
restoreDraftOrderShippingMethodsStepId,
async function (

View File

@@ -8,12 +8,39 @@ import { IPromotionModuleService } from "@medusajs/types"
export const updateDraftOrderPromotionsStepId = "update-draft-order-promotions"
interface UpdateDraftOrderPromotionsStepInput {
/**
* The details of the promotions to update in a draft order.
*/
export interface UpdateDraftOrderPromotionsStepInput {
/**
* The ID of the draft order.
*/
id: string
/**
* The promo codes to add, replace, or remove from the draft order.
*/
promo_codes: string[]
/**
* The action to perform on the promotions. You can either:
*
* - Add the promotions to the draft order.
* - Replace the existing promotions with the new ones.
* - Remove the promotions from the draft order.
*/
action?: PromotionActions
}
/**
* This step updates the promotions of a draft order.
*
* @example
* const data = updateDraftOrderPromotionsStep({
* id: "order_123",
* promo_codes: ["PROMO_123", "PROMO_456"],
* // Import from "@medusajs/framework/utils"
* action: PromotionActions.ADD,
* })
*/
export const updateDraftOrderPromotionsStep = createStep(
updateDraftOrderPromotionsStepId,
async function (data: UpdateDraftOrderPromotionsStepInput, { container }) {

View File

@@ -5,14 +5,42 @@ import { BigNumberInput, IOrderModuleService } from "@medusajs/types"
export const updateDraftOrderShippingMethodStepId =
"update-draft-order-shipping-method"
interface UpdateDraftOrderShippingMethodStepInput {
/**
* The details of the shipping method to update in a draft order.
*/
export interface UpdateDraftOrderShippingMethodStepInput {
/**
* The ID of the draft order.
*/
order_id: string
/**
* The ID of the shipping method to update.
*/
shipping_method_id: string
/**
* The ID of the shipping method's option.
*/
shipping_option_id?: string
/**
* The amount of the shipping method.
*/
amount?: BigNumberInput
/**
* The metadata of the shipping method.
*/
metadata?: Record<string, unknown> | null
}
/**
* This step updates the shipping method of a draft order.
*
* @example
* const data = updateDraftOrderShippingMethodStep({
* order_id: "order_123",
* shipping_method_id: "sm_123",
* amount: 10,
* })
*/
export const updateDraftOrderShippingMethodStep = createStep(
updateDraftOrderShippingMethodStepId,
async function (

View File

@@ -3,13 +3,45 @@ import { OrderChangeDTO, OrderDTO } from "@medusajs/types"
import { throwIfOrderChangeIsNotActive } from "../../order/utils/order-validation"
import { throwIfNotDraftOrder } from "../utils/validation"
interface ValidateDraftOrderChangeStepInput {
/**
* The details of the draft order and its change to validate.
*/
export interface ValidateDraftOrderChangeStepInput {
/**
* The draft order to validate.
*/
order: OrderDTO
/**
* The order change to validate.
*/
orderChange: OrderChangeDTO
}
export const validateDraftOrderChangeStepId = "validate-draft-order-change"
/**
* This step validates that a draft order and its change are valid. It throws an error if the
* order is not a draft order or the order change is not active.
*
* :::note
*
* You can retrieve a draft order and its change'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
* const data = validateDraftOrderChangeStep({
* order: {
* id: "order_123",
* // other order details...
* },
* orderChange: {
* id: "orch_123",
* // other order change details...
* }
* })
*/
export const validateDraftOrderChangeStep = createStep(
validateDraftOrderChangeStepId,
async function ({ order, orderChange }: ValidateDraftOrderChangeStepInput) {

View File

@@ -4,11 +4,43 @@ import { ChangeActionType, MedusaError } from "@medusajs/framework/utils"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { OrderChangeDTO, OrderWorkflow } from "@medusajs/types"
/**
* The details of the draft order and its change to validate.
*/
export interface ValidateDraftOrderUpdateActionItemStepInput {
/**
* The details of the item removal action.
*/
input: OrderWorkflow.DeleteOrderEditItemActionWorkflowInput
/**
* The order change to validate.
*/
orderChange: OrderChangeDTO
}
/**
* This step validates that an item change can be removed from a draft order edit. It throws an error if the
* item change is not in the draft order edit, or if the item change is not adding or updating an item.
*
* :::note
*
* You can retrieve a draft order change'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
* const data = validateDraftOrderRemoveActionItemStep({
* input: {
* action_id: "action_123",
* order_id: "order_123",
* },
* orderChange: {
* id: "orch_123",
* // other order change details...
* }
* })
*/
export const validateDraftOrderRemoveActionItemStep = createStep(
"validate-draft-order-remove-action-item",
async function ({

View File

@@ -6,11 +6,43 @@ import {
OrderWorkflow,
} from "@medusajs/types"
/**
* The details of the draft order and its change to validate.
*/
export interface ValidateDraftOrderShippingMethodActionStepInput {
/**
* The details of the shipping method removal action.
*/
input: OrderWorkflow.DeleteOrderEditShippingMethodWorkflowInput
/**
* The order change to validate.
*/
orderChange: OrderChangeDTO
}
/**
* This step validates that a shipping method change can be removed from a draft order edit. It throws an error if the
* shipping method change is not in the draft order edit, or if the shipping method change is not adding a shipping method.
*
* :::note
*
* You can retrieve a draft order change'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
* const data = validateDraftOrderShippingMethodActionStep({
* input: {
* action_id: "action_123",
* order_id: "order_123",
* },
* orderChange: {
* id: "orch_123",
* // other order change details...
* }
* })
*/
export const validateDraftOrderShippingMethodActionStep = createStep(
"validate-draft-order-shipping-method-action",
async function ({

View File

@@ -4,11 +4,43 @@ import { ChangeActionType, MedusaError } from "@medusajs/framework/utils"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { OrderChangeDTO, OrderWorkflow } from "@medusajs/types"
/**
* The details of the draft order and its change to validate.
*/
export interface ValidateDraftOrderUpdateActionItemStepInput {
/**
* The details of updating a new item in a draft order edit.
*/
input: OrderWorkflow.UpdateOrderEditAddNewItemWorkflowInput
/**
* The order change to validate.
*/
orderChange: OrderChangeDTO
}
/**
* This step validates that a new item can be updated in a draft order edit. It throws an error if the
* item change is not in the draft order edit, or if the item change is not adding an item.
*
* :::note
*
* You can retrieve a draft order change'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
* const data = validateDraftOrderUpdateActionItemStep({
* input: {
* action_id: "action_123",
* order_id: "order_123",
* },
* orderChange: {
* id: "orch_123",
* // other order change details...
* }
* })
*/
export const validateDraftOrderUpdateActionItemStep = createStep(
"validate-draft-order-update-action-item",
async function ({

View File

@@ -2,10 +2,34 @@ import { MedusaError, OrderStatus } from "@medusajs/framework/utils"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { OrderDTO } from "@medusajs/types"
interface ValidateDraftOrderStepInput {
/**
* The details of the draft order to validate.
*/
export interface ValidateDraftOrderStepInput {
/**
* The draft order to validate.
*/
order: OrderDTO
}
/**
* This step validates that an order is a draft order. It throws an error otherwise.
*
* :::note
*
* You can retrieve a draft order'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
* const data = validateDraftOrderStep({
* order: {
* id: "order_123",
* // other order details...
* }
* })
*/
export const validateDraftOrderStep = createStep(
"validate-draft-order",
async function ({ order }: ValidateDraftOrderStepInput) {

View File

@@ -7,11 +7,43 @@ import {
export const validatePromoCodesToAddId = "validate-promo-codes-to-add"
interface ValidatePromoCodesToAddStepInput {
/**
* The details of the promo codes to add to a draft order.
*/
export interface ValidatePromoCodesToAddStepInput {
/**
* The promo codes to add to the draft order.
*/
promo_codes: string[]
/**
* The promotions to add to the draft order.
*/
promotions: PromotionDTO[]
}
/**
* This step validates that the promo codes to add to a draft order are valid. It throws an error if the
* promo codes don't exist or are inactive.
*
* :::note
*
* You can retrieve a promotion'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
* const data = validatePromoCodesToAddStep({
* promo_codes: ["PROMO_123", "PROMO_456"],
* promotions: [{
* id: "promo_123",
* code: "PROMO_123"
* }, {
* id: "promo_456",
* code: "PROMO_456"
* }],
* })
*/
export const validatePromoCodesToAddStep = createStep(
validatePromoCodesToAddId,
async function (input: ValidatePromoCodesToAddStepInput) {

View File

@@ -4,11 +4,43 @@ import { throwIfCodesAreMissing } from "../utils/validation"
export const validatePromoCodesToRemoveId = "validate-promo-codes-to-remove"
interface ValidatePromoCodesToRemoveStepInput {
/**
* The details of the promo codes removal to validate.
*/
export interface ValidatePromoCodesToRemoveStepInput {
/**
* The promo codes to remove from the draft order.
*/
promo_codes: string[]
/**
* The promotions to remove from the draft order.
*/
promotions: PromotionDTO[]
}
/**
* This step validates that the promo codes can be removed from a draft order. It throws an error if the promo
* codes don't exist.
*
* :::note
*
* You can retrieve a promotion'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
* const data = validatePromoCodesToRemoveStep({
* promo_codes: ["PROMO_123", "PROMO_456"],
* promotions: [{
* id: "promo_123",
* code: "PROMO_123"
* }, {
* id: "promo_456",
* code: "PROMO_456"
* }],
* })
*/
export const validatePromoCodesToRemoveStep = createStep(
validatePromoCodesToRemoveId,
async function (input: ValidatePromoCodesToRemoveStepInput) {

View File

@@ -24,6 +24,29 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const addDraftOrderItemsWorkflowId = "add-draft-order-items"
/**
* This workflow adds items to a draft order. It's used by the
* [Add Item to Draft Order Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersidedititems).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around adding items to
* a draft order.
*
* @example
* const { result } = await addDraftOrderItemsWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* items: [{
* variant_id: "variant_123",
* quantity: 1
* }]
* }
* })
*
* @summary
*
* Add items to a draft order.
*/
export const addDraftOrderItemsWorkflow = createWorkflow(
addDraftOrderItemsWorkflowId,
function (

View File

@@ -22,11 +22,40 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const addDraftOrderPromotionWorkflowId = "add-draft-order-promotion"
interface AddDraftOrderPromotionWorkflowInput {
/**
* The details of the promotions to add to a draft order.
*/
export interface AddDraftOrderPromotionWorkflowInput {
/**
* The ID of the draft order to add the promotions to.
*/
order_id: string
/**
* The codes of the promotions to add to the draft order.
*/
promo_codes: string[]
}
/**
* This workflow adds promotions to a draft order. It's used by the
* [Add Promotion to Draft Order Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersideditpromotions).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around adding promotions to
* a draft order.
*
* @example
* const { result } = await addDraftOrderPromotionWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* promo_codes: ["PROMO_CODE_1", "PROMO_CODE_2"]
* }
* })
*
* @summary
*
* Add promotions to a draft order.
*/
export const addDraftOrderPromotionWorkflow = createWorkflow(
addDraftOrderPromotionWorkflowId,
function (input: WorkflowData<AddDraftOrderPromotionWorkflowInput>) {

View File

@@ -26,21 +26,46 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const addDraftOrderShippingMethodsWorkflowId =
"add-draft-order-shipping-methods"
interface AddDraftOrderShippingMethodsWorkflowInput {
/**
* The details of the shipping methods to add to a draft order.
*/
export interface AddDraftOrderShippingMethodsWorkflowInput {
/**
* The ID of the draft order to add the shipping methods to.
*/
order_id: string
/**
* The ID of the shipping option to add the shipping methods from.
* The ID of the shipping option to add as a shipping method.
*/
shipping_option_id: string
/**
* The custom amount to add the shipping methods with.
* The custom amount to add the shipping method with.
* If not specified, the shipping option's fixed or calculated price will be used.
*/
custom_amount?: BigNumberInput | null
}
/**
* This workflow adds shipping methods to a draft order. It's used by the
* [Add Shipping Method to Draft Order Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersideditshippingmethods).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around adding shipping methods to
* a draft order.
*
* @example
* const { result } = await addDraftOrderShippingMethodsWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* shipping_option_id: "so_123",
* custom_amount: 10
* }
* })
*
* @summary
*
* Add shipping methods to a draft order.
*/
export const addDraftOrderShippingMethodsWorkflow = createWorkflow(
addDraftOrderShippingMethodsWorkflowId,
function (input: WorkflowData<AddDraftOrderShippingMethodsWorkflowInput>) {

View File

@@ -11,6 +11,27 @@ import { validateDraftOrderStep } from "../steps"
export const beginDraftOrderEditWorkflowId = "begin-draft-order-edit"
/**
* This workflow begins a draft order edit. It's used by the
* [Create Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersidedit).
*
* The draft order edit can later be requested using {@link requestDraftOrderEditWorkflow} or confirmed using {@link confirmDraftOrderEditWorkflow}.
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* creating a draft order edit request.
*
* @example
* const { result } = await beginDraftOrderEditWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* }
* })
*
* @summary
*
* Create a draft order edit request.
*/
export const beginDraftOrderEditWorkflow = createWorkflow(
beginDraftOrderEditWorkflowId,
function (input: WorkflowData<OrderWorkflow.BeginorderEditWorkflowInput>) {

View File

@@ -20,10 +20,35 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const cancelDraftOrderEditWorkflowId = "cancel-draft-order-edit"
/**
* The details of the draft order edit to cancel.
*/
export interface CancelDraftOrderEditWorkflowInput {
/**
* The ID of the draft order to cancel the edit for.
*/
order_id: string
}
/**
* This workflow cancels a draft order edit. It's used by the
* [Cancel Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_deletedraftordersidedit).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* cancelling a draft order edit.
*
* @example
* const { result } = await cancelDraftOrderEditWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* }
* })
*
* @summary
*
* Cancel a draft order edit.
*/
export const cancelDraftOrderEditWorkflow = createWorkflow(
cancelDraftOrderEditWorkflowId,
function (input: WorkflowData<CancelDraftOrderEditWorkflowInput>) {

View File

@@ -33,6 +33,26 @@ export interface ConfirmDraftOrderEditWorkflowInput {
confirmed_by: string
}
/**
* This workflow confirms a draft order edit. It's used by the
* [Confirm Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersideditconfirm).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* confirming a draft order edit.
*
* @example
* const { result } = await confirmDraftOrderEditWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* confirmed_by: "user_123",
* }
* })
*
* @summary
*
* Confirm a draft order edit.
*/
export const confirmDraftOrderEditWorkflow = createWorkflow(
confirmDraftOrderEditWorkflowId,
function (input: ConfirmDraftOrderEditWorkflowInput) {

View File

@@ -16,23 +16,30 @@ import { validateDraftOrderStep } from "../steps/validate-draft-order"
const convertDraftOrderWorkflowId = "convert-draft-order"
interface ConvertDraftOrderWorkflowInput {
/**
* The details of the draft order to convert to an order.
*/
export interface ConvertDraftOrderWorkflowInput {
/**
* The ID of the draft order to convert to an order.
*/
id: string
}
interface ConvertDraftOrderStepInput {
/**
* The details of the draft order to convert to an order.
*/
export interface ConvertDraftOrderStepInput {
/**
* The ID of the draft order to convert to an order.
*/
id: string
}
/**
* This step converts a draft order to a pending order.
*
* @example
* ```typescript
* const order = await convertDraftOrderStep({ id: "order_123" })
* ```
*/
const convertDraftOrderStep = createStep(
export const convertDraftOrderStep = createStep(
"convert-draft-order",
async function ({ id }: ConvertDraftOrderStepInput, { container }) {
const service = container.resolve<IOrderModuleService>(Modules.ORDER)
@@ -69,12 +76,23 @@ const convertDraftOrderStep = createStep(
)
/**
* This workflow converts a draft order to a pending order.
*
* This workflow converts a draft order to a pending order. It's used by the
* [Convert Draft Order to Order Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersidconverttoorder).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* converting a draft order to a pending order.
*
* @example
* ```typescript
* const order = await convertDraftOrderWorkflow({ id: "order_123" })
* ```
* const { result } = await convertDraftOrderWorkflow(container)
* .run({
* input: {
* id: "order_123",
* }
* })
*
* @summary
*
* Convert a draft order to a pending order.
*/
export const convertDraftOrderWorkflow = createWorkflow(
convertDraftOrderWorkflowId,

View File

@@ -20,12 +20,52 @@ import { updateDraftOrderPromotionsStep } from "../steps/update-draft-order-prom
export const refreshDraftOrderAdjustmentsWorkflowId =
"refresh-draft-order-adjustments"
interface RefreshDraftOrderAdjustmentsWorkflowInput {
/**
* The details of the draft order to refresh the adjustments for.
*/
export interface RefreshDraftOrderAdjustmentsWorkflowInput {
/**
* The draft order to refresh the adjustments for.
*/
order: OrderDTO
/**
* The promo codes to add or remove from the draft order.
*/
promo_codes: string[]
/**
* The action to apply with the promo codes. You can
* either:
*
* - Add the promo codes to the draft order.
* - Remove the promo codes from the draft order.
* - Replace the existing promo codes with the new ones.
*/
action: PromotionActions
}
/**
* This workflow refreshes the adjustments or promotions for a draft order. It's used by other workflows
* like {@link addDraftOrderItemsWorkflow} to refresh the promotions whenever changes
* are made to the draft order.
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* refreshing the adjustments or promotions for a draft order.
*
* @example
* const { result } = await refreshDraftOrderAdjustmentsWorkflow(container)
* .run({
* input: {
* order: order,
* promo_codes: ["PROMO_CODE_1", "PROMO_CODE_2"],
* // imported from "@medusajs/framework/utils"
* action: PromotionActions.ADD,
* }
* })
*
* @summary
*
* Refresh the promotions in a draft order.
*/
export const refreshDraftOrderAdjustmentsWorkflow = createWorkflow(
refreshDraftOrderAdjustmentsWorkflowId,
function (input: WorkflowData<RefreshDraftOrderAdjustmentsWorkflowInput>) {

View File

@@ -25,6 +25,26 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const removeDraftOrderActionItemWorkflowId =
"remove-draft-order-action-item"
/**
* This workflow removes an item that was added or updated in a draft order edit. It's used by the
* [Remove Item from Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_deletedraftordersidedititemsaction_id).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* removing an item from a draft order edit.
*
* @example
* const { result } = await removeDraftOrderActionItemWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* action_id: "action_123",
* }
* })
*
* @summary
*
* Remove an item from a draft order edit.
*/
export const removeDraftOrderActionItemWorkflow = createWorkflow(
removeDraftOrderActionItemWorkflowId,
function (

View File

@@ -29,6 +29,26 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const removeDraftOrderActionShippingMethodWorkflowId =
"remove-draft-order-action-shipping-method"
/**
* This workflow removes a shipping method that was added to an edited draft order. It's used by the
* [Remove Shipping Method from Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_deletedraftordersideditshippingmethodsaction_id).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* removing a shipping method from an edited draft order.
*
* @example
* const { result } = await removeDraftOrderActionShippingMethodWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* action_id: "action_123",
* }
* })
*
* @summary
*
* Remove a shipping method from an edited draft order.
*/
export const removeDraftOrderActionShippingMethodWorkflow = createWorkflow(
removeDraftOrderActionShippingMethodWorkflowId,
function (

View File

@@ -23,11 +23,40 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const removeDraftOrderPromotionsWorkflowId =
"remove-draft-order-promotions"
interface RemoveDraftOrderPromotionsWorkflowInput {
/**
* The details of the promotions to remove from a draft order.
*/
export interface RemoveDraftOrderPromotionsWorkflowInput {
/**
* The ID of the draft order to remove the promotions from.
*/
order_id: string
/**
* The codes of the promotions to remove from the draft order.
*/
promo_codes: string[]
}
/**
* This workflow removes promotions from a draft order edit. It's used by the
* [Remove Promotions from Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_deletedraftordersideditpromotions).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* removing promotions from a draft order edit.
*
* @example
* const { result } = await removeDraftOrderPromotionsWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* promo_codes: ["PROMO_CODE_1", "PROMO_CODE_2"],
* }
* })
*
* @summary
*
* Remove promotions from a draft order edit.
*/
export const removeDraftOrderPromotionsWorkflow = createWorkflow(
removeDraftOrderPromotionsWorkflowId,
function (input: WorkflowData<RemoveDraftOrderPromotionsWorkflowInput>) {

View File

@@ -24,9 +24,12 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const removeDraftOrderShippingMethodWorkflowId =
"remove-draft-order-shipping-method"
interface RemoveDraftOrderShippingMethodWorkflowInput {
/**
* The details of the shipping method to remove from a draft order.
*/
export interface RemoveDraftOrderShippingMethodWorkflowInput {
/**
* The ID of the draft order to add the shipping methods to.
* The ID of the draft order to remove the shipping method from.
*/
order_id: string
/**
@@ -35,6 +38,26 @@ interface RemoveDraftOrderShippingMethodWorkflowInput {
shipping_method_id: string
}
/**
* This workflow removes an existing shipping method from a draft order edit. It's used by the
* [Remove Shipping Method from Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_deletedraftordersideditshippingmethodsmethodmethod_id).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* removing a shipping method from a draft order edit.
*
* @example
* const { result } = await removeDraftOrderShippingMethodWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* shipping_method_id: "sm_123",
* }
* })
*
* @summary
*
* Remove an existing shipping method from a draft order edit.
*/
export const removeDraftOrderShippingMethodWorkflow = createWorkflow(
removeDraftOrderShippingMethodWorkflowId,
function (input: WorkflowData<RemoveDraftOrderShippingMethodWorkflowInput>) {

View File

@@ -48,6 +48,26 @@ export type RequestDraftOrderEditWorkflowInput = {
requested_by?: string
}
/**
* This workflow requests a draft order edit. It's used by the
* [Request Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersideditrequest).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* requesting a draft order edit.
*
* @example
* const { result } = await requestDraftOrderEditWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* requested_by: "user_123",
* }
* })
*
* @summary
*
* Request a draft order edit.
*/
export const requestDraftOrderEditWorkflow = createWorkflow(
requestDraftOrderEditId,
function (input: RequestDraftOrderEditWorkflowInput) {

View File

@@ -25,6 +25,29 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const updateDraftOrderActionItemId = "update-draft-order-action-item"
/**
* This workflow updates a new item that was added to a draft order edit. It's used by the
* [Update New Item in Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersidedititemsaction_id).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* updating a new item in a draft order edit.
*
* @example
* const { result } = await updateDraftOrderActionItemWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* action_id: "action_123",
* data: {
* quantity: 2,
* }
* }
* })
*
* @summary
*
* Update a new item in a draft order edit.
*/
export const updateDraftOrderActionItemWorkflow = createWorkflow(
updateDraftOrderActionItemId,
function (

View File

@@ -30,6 +30,29 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const updateDraftOrderActionShippingMethodWorkflowId =
"update-draft-order-action-shipping-method"
/**
* This workflow updates a new shipping method that was added to a draft order edit. It's used by the
* [Update New Shipping Method in Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersideditshippingmethodsaction_id).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* updating a new shipping method in a draft order edit.
*
* @example
* const { result } = await updateDraftOrderActionShippingMethodWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* action_id: "action_123",
* data: {
* custom_amount: 10,
* }
* }
* })
*
* @summary
*
* Update a new shipping method in a draft order edit.
*/
export const updateDraftOrderActionShippingMethodWorkflow = createWorkflow(
updateDraftOrderActionShippingMethodWorkflowId,
function (

View File

@@ -30,6 +30,26 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const updateDraftOrderItemWorkflowId = "update-draft-order-item"
/**
* This workflow updates an item in a draft order edit. It's used by the
* [Update Item in Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersidedititemsitemitem_id).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* updating an item in a draft order edit.
*
* @example
* const { result } = await updateDraftOrderItemWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* items: [{ id: "orli_123", quantity: 2 }],
* }
* })
*
* @summary
*
* Update an item in a draft order edit.
*/
export const updateDraftOrderItemWorkflow = createWorkflow(
updateDraftOrderItemWorkflowId,
function (

View File

@@ -25,6 +25,9 @@ import { refreshDraftOrderAdjustmentsWorkflow } from "./refresh-draft-order-adju
export const updateDraftOrderShippingMethodWorkflowId =
"update-draft-order-shipping-method"
/**
* The details of the shipping method to update in the order edit.
*/
export interface UpdateDraftOrderShippingMethodWorkflowInput {
/**
* The ID of the order to update the shipping method in its edit.
@@ -36,7 +39,7 @@ export interface UpdateDraftOrderShippingMethodWorkflowInput {
*/
shipping_method_id: string
/**
* The ID of the shipping option to associate with the shipping method.
* The ID of the shipping method's option.
*/
shipping_option_id?: string
/**
@@ -50,6 +53,29 @@ export interface UpdateDraftOrderShippingMethodWorkflowInput {
}
}
/**
* This workflow updates an existing shipping method in a draft order edit. It's used by the
* [Update Shipping Method in Draft Order Edit Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersideditshippingmethodsmethodmethod_id).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* updating an existing shipping method in a draft order edit.
*
* @example
* const { result } = await updateDraftOrderShippingMethodWorkflow(container)
* .run({
* input: {
* order_id: "order_123",
* data: {
* shipping_method_id: "sm_123",
* custom_amount: 10,
* }
* }
* })
*
* @summary
*
* Update an existing shipping method in a draft order edit.
*/
export const updateDraftOrderShippingMethodWorkflow = createWorkflow(
updateDraftOrderShippingMethodWorkflowId,
function (input: WorkflowData<UpdateDraftOrderShippingMethodWorkflowInput>) {

View File

@@ -20,6 +20,9 @@ import { validateDraftOrderStep } from "../steps/validate-draft-order"
export const updateDraftOrderWorkflowId = "update-draft-order"
/**
* The details of the draft order to update.
*/
export interface UpdateDraftOrderWorkflowInput {
/**
* The ID of the draft order to update.
@@ -55,12 +58,42 @@ export interface UpdateDraftOrderWorkflowInput {
metadata?: Record<string, unknown> | null
}
interface UpdateDraftOrderStepInput {
/**
* The input for the update draft order step.
*/
export interface UpdateDraftOrderStepInput {
/**
* The draft order to update.
*/
order: OrderDTO
/**
* The details to update in the draft order.
*/
input: UpdateOrderDTO
}
const updateDraftOrderStep = createStep(
/**
* This step updates a draft order's details.
*
* :::note
*
* You can retrieve a draft order'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
* const data = updateDraftOrderStep({
* order: {
* id: "order_123",
* // other order details...
* },
* input: {
* // details to update...
* }
* })
*/
export const updateDraftOrderStep = createStep(
"update-draft-order",
async ({ order, input }: UpdateDraftOrderStepInput, { container }) => {
const service = container.resolve<IOrderModuleService>(Modules.ORDER)
@@ -87,6 +120,32 @@ const updateDraftOrderStep = createStep(
}
)
/**
* This workflow updates a draft order's details. It's used by the
* [Update Draft Order Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftordersid).
*
* This workflow doesn't update the draft order's items, shipping methods, or promotions. Instead, you have to
* create a draft order edit using {@link beginDraftOrderEditWorkflow} and make updates in the draft order edit.
* Then, you can confirm the draft order edit using {@link confirmDraftOrderEditWorkflow} or request a draft order edit
* using {@link requestDraftOrderEditWorkflow}.
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* updating a draft order.
*
* @example
* const { result } = await updateDraftOrderWorkflow(container)
* .run({
* input: {
* id: "order_123",
* user_id: "user_123",
* customer_id: "cus_123",
* }
* })
*
* @summary
*
* Update a draft order's details.
*/
export const updateDraftOrderWorkflow = createWorkflow(
updateDraftOrderWorkflowId,
function (input: WorkflowData<UpdateDraftOrderWorkflowInput>) {

View File

@@ -8,6 +8,9 @@ export interface BeginorderEditWorkflowInput {
order_id: string
/**
* The ID of the user requesting the order edit.
*
* @example
* "user_123"
*/
created_by?: string
/**