chore: improve and add TSDocs for next release (#14170)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-12-01 13:41:31 +02:00
1 parent d9e3965a10
commit 73ae136965
6 files changed
+71 -14

No files matched your search

@@ -4,6 +4,8 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
/** /**
* This step lists order change actions filtered by action type. * This step lists order change actions filtered by action type.
*
* @since v2.11.4
*/ */
export const listOrderChangeActionsByTypeStep = createStep( export const listOrderChangeActionsByTypeStep = createStep(
"list-order-change-actions-by-type", "list-order-change-actions-by-type",
@@ -29,7 +29,12 @@ export type ComputeAdjustmentsForPreviewWorkflowInput = {
/** /**
* The order's details. * The order's details.
*/ */
order: OrderDTO & { promotions: PromotionDTO[] } order: OrderDTO & {
/**
* The promotions applied to the order.
*/
promotions: PromotionDTO[]
}
/** /**
* The order change's details. * The order change's details.
*/ */
@@ -42,13 +47,13 @@ export const computeAdjustmentsForPreviewWorkflowId =
* This workflow computes adjustments for an order change if the carry over promotions flag is true on the order change. * This workflow computes adjustments for an order change if the carry over promotions flag is true on the order change.
* If the flag is false, it deletes the existing adjustments replacement actions. * If the flag is false, it deletes the existing adjustments replacement actions.
* *
* It is currently used as a part of the order edit and exchange flows. * It is currently used as a part of the order edit and exchange flows. It's used by workflows
* It's used by the [Add Items to Order Edit Admin API Route](https://docs.medusajs.com/api/admin#order-edits_postordereditsiditems), * like {@link orderExchangeAddNewItemWorkflow} and {@link orderEditAddNewItemWorkflow}.
* [Add Outbound Items Admin API Route](https://docs.medusajs.com/api/admin#exchanges_postexchangesidoutbounditems),
* and [Add Inbound Items Admin API Route](https://docs.medusajs.com/api/admin#exchanges_postexchangesidinbounditems).
* *
* You can use this workflow within your customizations or your own custom workflows, allowing you to compute adjustments * You can use this workflow within your customizations or your own custom workflows, allowing you to compute adjustments
* in your custom flows. * in your custom flows.
*
* @since v2.11.4
* *
* @example * @example
* const { result } = await computeAdjustmentsForPreviewWorkflow(container) * const { result } = await computeAdjustmentsForPreviewWorkflow(container)
@@ -62,7 +67,6 @@ export const computeAdjustmentsForPreviewWorkflowId =
* id: "orch_123", * id: "orch_123",
* // other order change details... * // other order change details...
* }, * },
* exchange_id: "exchange_123", // optional, for exchanges
* } * }
* }) * })
* *
@@ -34,7 +34,33 @@ export type OnCarryPromotionsFlagSetWorkflowInput = {
} }
/** /**
* This step validates that the order change is an exchange and validates promotion allocation. * This step validates that the order change is an exchange and validates that
* the promotion allocation is valid for carrying over promotions.
*
* :::note
*
* You can retrieve details of the order and order change using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),
* or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).
*
* :::
*
* @since v2.11.4
*
* @example
* const data = validateCarryPromotionsFlagStep({
* order: {
* id: "order_123",
* // other order details...
* },
* orderChange: {
* id: "orch_123",
* // other order change details...
* },
* input: {
* order_change_id: "orch_123",
* carry_over_promotions: true,
* }
* })
*/ */
export const validateCarryPromotionsFlagStep = createStep( export const validateCarryPromotionsFlagStep = createStep(
"validate-carry-promotions-flag", "validate-carry-promotions-flag",
@@ -114,9 +140,17 @@ export const validateCarryPromotionsFlagStep = createStep(
export const onCarryPromotionsFlagSetId = "on-carry-promotions-flag-set" export const onCarryPromotionsFlagSetId = "on-carry-promotions-flag-set"
/** /**
* This workflow sets the carry over promotions flag for an order change. * This workflow toggles whether promotions are carried over to outbound items of an exchange.
* It validates that the order change is active and is an exchange, validates promotion allocation, * It validates that the order change is an exchange and that it's active. It also validates that the promotion allocation
* and either applies or removes promotion adjustments based on the flag value. * is valid for carrying over promotions. Finally, it computes adjustments for the order change
* and either applies or removes promotion adjustments based on whether promotions are to be carried over.
*
* This workflow is used by other workflows, such as the {@link updateOrderChangeWorkflow}.
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to
* set the carry over promotions flag for an order change in your custom flows.
*
* @since v2.11.4
* *
* @example * @example
* const { result } = await onCarryPromotionsFlagSet(container) * const { result } = await onCarryPromotionsFlagSet(container)
@@ -129,7 +163,7 @@ export const onCarryPromotionsFlagSetId = "on-carry-promotions-flag-set"
* *
* @summary * @summary
* *
* Set the carry over promotions flag for an order change. * Toggle carrying over promotions to outbound exchange items.
*/ */
export const onCarryPromotionsFlagSet = createWorkflow( export const onCarryPromotionsFlagSet = createWorkflow(
onCarryPromotionsFlagSetId, onCarryPromotionsFlagSetId,
@@ -13,8 +13,13 @@ export const updateOrderChangeWorkflowId = "update-order-change-workflow"
/** /**
* This workflow updates an order change. * This workflow updates an order change.
* If the carry_over_promotions flag is provided, it calls onCarryPromotionsFlagSet * If the `carry_over_promotions` flag is provided, it calls {@link onCarryPromotionsFlagSet}
* to handle the promotion logic. Otherwise, it updates the order change directly. * to handle the promotion update logic. Otherwise, it updates the order change directly.
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* updating an order change and conditionally handling promotion carry-over.
*
* @since v2.11.4
* *
* @example * @example
* const { result } = await updateOrderChangeWorkflow(container) * const { result } = await updateOrderChangeWorkflow(container)
@@ -27,7 +32,7 @@ export const updateOrderChangeWorkflowId = "update-order-change-workflow"
* *
* @summary * @summary
* *
* Update an order change, conditionally handling promotion carry-over if specified. * Update an order change.
*/ */
export const updateOrderChangeWorkflow = createWorkflow( export const updateOrderChangeWorkflow = createWorkflow(
updateOrderChangeWorkflowId, updateOrderChangeWorkflowId,
@@ -27,6 +27,9 @@ const _OrderChange = model
declined_at: model.dateTime().nullable(), declined_at: model.dateTime().nullable(),
canceled_by: model.text().nullable(), canceled_by: model.text().nullable(),
canceled_at: model.dateTime().nullable(), canceled_at: model.dateTime().nullable(),
/**
* @since v2.11.4
*/
carry_over_promotions: model.boolean().nullable(), carry_over_promotions: model.boolean().nullable(),
order: model.belongsTo<() => typeof Order>(() => Order, { order: model.belongsTo<() => typeof Order>(() => Order, {
mappedBy: "changes", mappedBy: "changes",
@@ -9,7 +9,13 @@ const Promotion = model
code: model.text().searchable(), code: model.text().searchable(),
is_automatic: model.boolean().default(false), is_automatic: model.boolean().default(false),
is_tax_inclusive: model.boolean().default(false), is_tax_inclusive: model.boolean().default(false),
/**
* @since v2.11.4
*/
limit: model.number().nullable(), limit: model.number().nullable(),
/**
* @since v2.11.4
*/
used: model.number().default(0), used: model.number().default(0),
type: model.enum(PromotionUtils.PromotionType).index("IDX_promotion_type"), type: model.enum(PromotionUtils.PromotionType).index("IDX_promotion_type"),
status: model status: model
@@ -30,6 +36,9 @@ const Promotion = model
pivotTable: "promotion_promotion_rule", pivotTable: "promotion_promotion_rule",
mappedBy: "promotions", mappedBy: "promotions",
}), }),
/**
* @since v2.11.4
*/
metadata: model.json().nullable(), metadata: model.json().nullable(),
}) })
.cascades({ .cascades({