chore(core-flows): [7] export types and types, add basic TSDocs (#8514)

This PR exports types and steps from the core-flows package, and adds simple TSDocs for workflows / steps. This is essential for the workflows reference.

PR 7/n
This commit is contained in:
Shahed Nasser
2024-08-08 16:38:10 +00:00
committed by GitHub
parent 0bfe31e594
commit 89fd065fa3
25 changed files with 209 additions and 58 deletions
@@ -11,7 +11,10 @@ import { createOrderClaimsStep } from "../../steps/claim/create-claims"
import { createOrderChangeStep } from "../../steps/create-order-change" import { createOrderChangeStep } from "../../steps/create-order-change"
import { throwIfIsCancelled } from "../../utils/order-validation" import { throwIfIsCancelled } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that the order associated with the claim isn't canceled.
*/
export const beginClaimOrderValidationStep = createStep(
"begin-claim-order-validation", "begin-claim-order-validation",
async function ({ order }: { order: OrderDTO }) { async function ({ order }: { order: OrderDTO }) {
throwIfIsCancelled(order, "Order") throwIfIsCancelled(order, "Order")
@@ -19,6 +22,9 @@ const validationStep = createStep(
) )
export const beginClaimOrderWorkflowId = "begin-claim-order" export const beginClaimOrderWorkflowId = "begin-claim-order"
/**
* This workflow creates an order claim in requested state.
*/
export const beginClaimOrderWorkflow = createWorkflow( export const beginClaimOrderWorkflow = createWorkflow(
beginClaimOrderWorkflowId, beginClaimOrderWorkflowId,
function ( function (
@@ -32,7 +38,7 @@ export const beginClaimOrderWorkflow = createWorkflow(
throw_if_key_not_found: true, throw_if_key_not_found: true,
}) })
validationStep({ order }) beginClaimOrderValidationStep({ order })
const created = createOrderClaimsStep([ const created = createOrderClaimsStep([
{ {
@@ -19,11 +19,15 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
type WorkflowInput = { export type CancelBeginOrderClaimWorkflowInput = {
claim_id: string claim_id: string
} }
const validationStep = createStep( /**
* This step validates that the requested claim can be canceled by checking that it's not canceled,
* its order isn't canceled, and it hasn't been confirmed.
*/
export const cancelBeginOrderClaimValidationStep = createStep(
"validate-cancel-begin-order-claim", "validate-cancel-begin-order-claim",
async function ({ async function ({
order, order,
@@ -41,9 +45,12 @@ const validationStep = createStep(
) )
export const cancelBeginOrderClaimWorkflowId = "cancel-begin-order-claim" export const cancelBeginOrderClaimWorkflowId = "cancel-begin-order-claim"
/**
* This workflow cancels a requested order claim.
*/
export const cancelBeginOrderClaimWorkflow = createWorkflow( export const cancelBeginOrderClaimWorkflow = createWorkflow(
cancelBeginOrderClaimWorkflowId, cancelBeginOrderClaimWorkflowId,
function (input: WorkflowInput): WorkflowData<void> { function (input: CancelBeginOrderClaimWorkflowInput): WorkflowData<void> {
const orderClaim: OrderClaimDTO = useRemoteQueryStep({ const orderClaim: OrderClaimDTO = useRemoteQueryStep({
entry_point: "order_claim", entry_point: "order_claim",
fields: ["id", "status", "order_id", "return_id", "canceled_at"], fields: ["id", "status", "order_id", "return_id", "canceled_at"],
@@ -73,7 +80,7 @@ export const cancelBeginOrderClaimWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, orderClaim, orderChange }) cancelBeginOrderClaimValidationStep({ order, orderClaim, orderChange })
const shippingToRemove = transform( const shippingToRemove = transform(
{ orderChange, input }, { orderChange, input },
@@ -14,7 +14,10 @@ import { cancelOrderClaimStep } from "../../steps"
import { throwIfIsCancelled } from "../../utils/order-validation" import { throwIfIsCancelled } from "../../utils/order-validation"
import { cancelReturnWorkflow } from "../return/cancel-return" import { cancelReturnWorkflow } from "../return/cancel-return"
const validateOrder = createStep( /**
* This step validates that a confirmed claim can be canceled.
*/
export const cancelClaimValidateOrderStep = createStep(
"validate-claim", "validate-claim",
({ ({
orderClaim, orderClaim,
@@ -49,6 +52,9 @@ const validateOrder = createStep(
) )
export const cancelOrderClaimWorkflowId = "cancel-claim" export const cancelOrderClaimWorkflowId = "cancel-claim"
/**
* This workflow cancels a confirmed order claim.
*/
export const cancelOrderClaimWorkflow = createWorkflow( export const cancelOrderClaimWorkflow = createWorkflow(
cancelOrderClaimWorkflowId, cancelOrderClaimWorkflowId,
( (
@@ -70,7 +76,7 @@ export const cancelOrderClaimWorkflow = createWorkflow(
throw_if_key_not_found: true, throw_if_key_not_found: true,
}) })
validateOrder({ orderClaim, input }) cancelClaimValidateOrderStep({ orderClaim, input })
const lineItemIds = transform({ orderClaim }, ({ orderClaim }) => { const lineItemIds = transform({ orderClaim }, ({ orderClaim }) => {
return orderClaim.additional_items?.map((i) => i.item_id) return orderClaim.additional_items?.map((i) => i.item_id)
@@ -21,7 +21,10 @@ import {
} from "../../utils/order-validation" } from "../../utils/order-validation"
import { addOrderLineItemsWorkflow } from "../add-line-items" import { addOrderLineItemsWorkflow } from "../add-line-items"
const validationStep = createStep( /**
* This step validates that a new item can be added to the claim.
*/
export const orderClaimAddNewItemValidationStep = createStep(
"claim-add-new-item-validation", "claim-add-new-item-validation",
async function ({ async function ({
order, order,
@@ -39,6 +42,9 @@ const validationStep = createStep(
) )
export const orderClaimAddNewItemWorkflowId = "claim-add-new-item" export const orderClaimAddNewItemWorkflowId = "claim-add-new-item"
/**
* This workflow adds a new item to a claim.
*/
export const orderClaimAddNewItemWorkflow = createWorkflow( export const orderClaimAddNewItemWorkflow = createWorkflow(
orderClaimAddNewItemWorkflowId, orderClaimAddNewItemWorkflowId,
function ( function (
@@ -73,7 +79,7 @@ export const orderClaimAddNewItemWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ orderClaimAddNewItemValidationStep({
order, order,
orderClaim, orderClaim,
orderChange, orderChange,
@@ -20,7 +20,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that claim items can be added to a claim.
*/
export const orderClaimItemValidationStep = createStep(
"claim-item-validation", "claim-item-validation",
async function ({ async function ({
order, order,
@@ -38,6 +41,9 @@ const validationStep = createStep(
) )
export const orderClaimItemWorkflowId = "claim-item" export const orderClaimItemWorkflowId = "claim-item"
/**
* This workflow adds claim items to a claim.
*/
export const orderClaimItemWorkflow = createWorkflow( export const orderClaimItemWorkflow = createWorkflow(
orderClaimItemWorkflowId, orderClaimItemWorkflowId,
function ( function (
@@ -72,7 +78,7 @@ export const orderClaimItemWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ orderClaimItemValidationStep({
order, order,
orderClaim, orderClaim,
orderChange, orderChange,
@@ -25,7 +25,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that items can be requested to return as part of a claim.
*/
export const orderClaimRequestItemReturnValidationStep = createStep(
"claim-request-item-return-validation", "claim-request-item-return-validation",
async function ({ async function ({
order, order,
@@ -49,6 +52,9 @@ const validationStep = createStep(
) )
export const orderClaimRequestItemReturnWorkflowId = "claim-request-item-return" export const orderClaimRequestItemReturnWorkflowId = "claim-request-item-return"
/**
* This workflow requests one or more items to be returned as part of a claim.
*/
export const orderClaimRequestItemReturnWorkflow = createWorkflow( export const orderClaimRequestItemReturnWorkflow = createWorkflow(
orderClaimRequestItemReturnWorkflowId, orderClaimRequestItemReturnWorkflowId,
function ( function (
@@ -115,7 +121,7 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow(
name: "order-change-query", name: "order-change-query",
}) })
validationStep({ orderClaimRequestItemReturnValidationStep({
order, order,
items: input.items, items: input.items,
orderClaim, orderClaim,
@@ -32,11 +32,14 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
type WorkflowInput = { export type ConfirmClaimRequestWorkflowInput = {
claim_id: string claim_id: string
} }
const validationStep = createStep( /**
* This step validates that a requested claim can be confirmed.
*/
export const confirmClaimRequestValidationStep = createStep(
"validate-confirm-claim-request", "validate-confirm-claim-request",
async function ({ async function ({
order, order,
@@ -173,9 +176,12 @@ function extractShippingOption({ orderPreview, orderClaim, returnId }) {
} }
export const confirmClaimRequestWorkflowId = "confirm-claim-request" export const confirmClaimRequestWorkflowId = "confirm-claim-request"
/**
* This workflow confirms a requested claim.
*/
export const confirmClaimRequestWorkflow = createWorkflow( export const confirmClaimRequestWorkflow = createWorkflow(
confirmClaimRequestWorkflowId, confirmClaimRequestWorkflowId,
function (input: WorkflowInput): WorkflowResponse<OrderDTO> { function (input: ConfirmClaimRequestWorkflowInput): WorkflowResponse<OrderDTO> {
const orderClaim: OrderClaimDTO = useRemoteQueryStep({ const orderClaim: OrderClaimDTO = useRemoteQueryStep({
entry_point: "order_claim", entry_point: "order_claim",
fields: ["id", "status", "order_id", "canceled_at"], fields: ["id", "status", "order_id", "canceled_at"],
@@ -225,7 +231,7 @@ export const confirmClaimRequestWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, orderClaim, orderChange }) confirmClaimRequestValidationStep({ order, orderClaim, orderChange })
const { claimItems, returnItems } = transform( const { claimItems, returnItems } = transform(
{ orderChange }, { orderChange },
@@ -20,7 +20,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step confirms that a shipping method can be created for a claim.
*/
export const createClaimShippingMethodValidationStep = createStep(
"validate-create-claim-shipping-method", "validate-create-claim-shipping-method",
async function ({ async function ({
order, order,
@@ -39,6 +42,9 @@ const validationStep = createStep(
export const createClaimShippingMethodWorkflowId = export const createClaimShippingMethodWorkflowId =
"create-claim-shipping-method" "create-claim-shipping-method"
/**
* This workflow creates a shipping method for a claim.
*/
export const createClaimShippingMethodWorkflow = createWorkflow( export const createClaimShippingMethodWorkflow = createWorkflow(
createClaimShippingMethodWorkflowId, createClaimShippingMethodWorkflowId,
function (input: { function (input: {
@@ -92,7 +98,7 @@ export const createClaimShippingMethodWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, orderClaim, orderChange }) createClaimShippingMethodValidationStep({ order, orderClaim, orderChange })
const shippingMethodInput = transform( const shippingMethodInput = transform(
{ {
@@ -22,7 +22,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that new items can be removed from a claim.
*/
export const removeClaimAddItemActionValidationStep = createStep(
"remove-item-claim-add-action-validation", "remove-item-claim-add-action-validation",
async function ({ async function ({
order, order,
@@ -54,6 +57,9 @@ const validationStep = createStep(
) )
export const removeAddItemClaimActionWorkflowId = "remove-item-claim-add-action" export const removeAddItemClaimActionWorkflowId = "remove-item-claim-add-action"
/**
* This workflow removes new items from a claim.
*/
export const removeAddItemClaimActionWorkflow = createWorkflow( export const removeAddItemClaimActionWorkflow = createWorkflow(
removeAddItemClaimActionWorkflowId, removeAddItemClaimActionWorkflowId,
function ( function (
@@ -88,7 +94,7 @@ export const removeAddItemClaimActionWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, input, orderClaim, orderChange }) removeClaimAddItemActionValidationStep({ order, input, orderClaim, orderChange })
deleteOrderChangeActionsStep({ ids: [input.action_id] }) deleteOrderChangeActionsStep({ ids: [input.action_id] })
@@ -22,7 +22,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step confirms that a claim's items can be removed.
*/
export const removeClaimItemActionValidationStep = createStep(
"remove-item-claim-action-validation", "remove-item-claim-action-validation",
async function ({ async function ({
order, order,
@@ -54,6 +57,9 @@ const validationStep = createStep(
) )
export const removeItemClaimActionWorkflowId = "remove-item-claim-action" export const removeItemClaimActionWorkflowId = "remove-item-claim-action"
/**
* This workflow removes claim items.
*/
export const removeItemClaimActionWorkflow = createWorkflow( export const removeItemClaimActionWorkflow = createWorkflow(
removeItemClaimActionWorkflowId, removeItemClaimActionWorkflowId,
function ( function (
@@ -88,7 +94,7 @@ export const removeItemClaimActionWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, input, orderClaim, orderChange }) removeClaimItemActionValidationStep({ order, input, orderClaim, orderChange })
deleteOrderChangeActionsStep({ ids: [input.action_id] }) deleteOrderChangeActionsStep({ ids: [input.action_id] })
@@ -23,7 +23,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that a claim's shipping method can be removed.
*/
export const removeClaimShippingMethodValidationStep = createStep(
"validate-remove-claim-shipping-method", "validate-remove-claim-shipping-method",
async function ({ async function ({
orderChange, orderChange,
@@ -55,6 +58,9 @@ const validationStep = createStep(
export const removeClaimShippingMethodWorkflowId = export const removeClaimShippingMethodWorkflowId =
"remove-claim-shipping-method" "remove-claim-shipping-method"
/**
* This workflow removes the shipping method of a claim.
*/
export const removeClaimShippingMethodWorkflow = createWorkflow( export const removeClaimShippingMethodWorkflow = createWorkflow(
removeClaimShippingMethodWorkflowId, removeClaimShippingMethodWorkflowId,
function ( function (
@@ -81,7 +87,7 @@ export const removeClaimShippingMethodWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ orderClaim, orderChange, input }) removeClaimShippingMethodValidationStep({ orderClaim, orderChange, input })
const dataToRemove = transform( const dataToRemove = transform(
{ orderChange, input }, { orderChange, input },
@@ -23,7 +23,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that a claim's new item can be updated.
*/
export const updateClaimAddItemValidationStep = createStep(
"update-claim-add-item-validation", "update-claim-add-item-validation",
async function ( async function (
{ {
@@ -58,6 +61,9 @@ const validationStep = createStep(
) )
export const updateClaimAddItemWorkflowId = "update-claim-add-item" export const updateClaimAddItemWorkflowId = "update-claim-add-item"
/**
* This workflow updates a claim's new item.
*/
export const updateClaimAddItemWorkflow = createWorkflow( export const updateClaimAddItemWorkflow = createWorkflow(
updateClaimAddItemWorkflowId, updateClaimAddItemWorkflowId,
function ( function (
@@ -92,7 +98,7 @@ export const updateClaimAddItemWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, input, orderClaim, orderChange }) updateClaimAddItemValidationStep({ order, input, orderClaim, orderChange })
const updateData = transform( const updateData = transform(
{ orderChange, input }, { orderChange, input },
@@ -23,7 +23,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that a claim's item can be updated.
*/
export const updateClaimItemValidationStep = createStep(
"update-claim-item-validation", "update-claim-item-validation",
async function ( async function (
{ {
@@ -58,6 +61,9 @@ const validationStep = createStep(
) )
export const updateClaimItemWorkflowId = "update-claim-item" export const updateClaimItemWorkflowId = "update-claim-item"
/**
* This workflow updates a claim item.
*/
export const updateClaimItemWorkflow = createWorkflow( export const updateClaimItemWorkflow = createWorkflow(
updateClaimItemWorkflowId, updateClaimItemWorkflowId,
function ( function (
@@ -92,7 +98,7 @@ export const updateClaimItemWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, input, orderClaim, orderChange }) updateClaimItemValidationStep({ order, input, orderClaim, orderChange })
const updateData = transform( const updateData = transform(
{ orderChange, input }, { orderChange, input },
@@ -25,7 +25,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that a claim's shipping method can be updated.
*/
export const updateClaimShippingMethodValidationStep = createStep(
"validate-update-claim-shipping-method", "validate-update-claim-shipping-method",
async function ({ async function ({
orderChange, orderChange,
@@ -57,6 +60,9 @@ const validationStep = createStep(
export const updateClaimShippingMethodWorkflowId = export const updateClaimShippingMethodWorkflowId =
"update-claim-shipping-method" "update-claim-shipping-method"
/**
* This workflow updates a claim's shipping method.
*/
export const updateClaimShippingMethodWorkflow = createWorkflow( export const updateClaimShippingMethodWorkflow = createWorkflow(
updateClaimShippingMethodWorkflowId, updateClaimShippingMethodWorkflowId,
function ( function (
@@ -83,7 +89,7 @@ export const updateClaimShippingMethodWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ orderClaim, orderChange, input }) updateClaimShippingMethodValidationStep({ orderClaim, orderChange, input })
const updateData = transform( const updateData = transform(
{ orderChange, input }, { orderChange, input },
@@ -11,7 +11,10 @@ import { createOrderChangeStep } from "../../steps/create-order-change"
import { createOrderExchangesStep } from "../../steps/exchange/create-exchange" import { createOrderExchangesStep } from "../../steps/exchange/create-exchange"
import { throwIfOrderIsCancelled } from "../../utils/order-validation" import { throwIfOrderIsCancelled } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that an exchange can be requested for an order.
*/
export const beginOrderExchangeValidationStep = createStep(
"begin-exchange-order-validation", "begin-exchange-order-validation",
async function ({ order }: { order: OrderDTO }) { async function ({ order }: { order: OrderDTO }) {
throwIfOrderIsCancelled({ order }) throwIfOrderIsCancelled({ order })
@@ -19,6 +22,9 @@ const validationStep = createStep(
) )
export const beginExchangeOrderWorkflowId = "begin-exchange-order" export const beginExchangeOrderWorkflowId = "begin-exchange-order"
/**
* This workflow requests an order exchange.
*/
export const beginExchangeOrderWorkflow = createWorkflow( export const beginExchangeOrderWorkflow = createWorkflow(
beginExchangeOrderWorkflowId, beginExchangeOrderWorkflowId,
function ( function (
@@ -32,7 +38,7 @@ export const beginExchangeOrderWorkflow = createWorkflow(
throw_if_key_not_found: true, throw_if_key_not_found: true,
}) })
validationStep({ order }) beginOrderExchangeValidationStep({ order })
const created = createOrderExchangesStep([ const created = createOrderExchangesStep([
{ {
@@ -19,11 +19,14 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
type WorkflowInput = { export type CancelBeginOrderExchangeWorkflowInput = {
exchange_id: string exchange_id: string
} }
const validationStep = createStep( /**
* This step validates that a requested exchange can be canceled.
*/
export const cancelBeginOrderExchangeValidationStep = createStep(
"validate-cancel-begin-order-exchange", "validate-cancel-begin-order-exchange",
async function ({ async function ({
order, order,
@@ -41,9 +44,12 @@ const validationStep = createStep(
) )
export const cancelBeginOrderExchangeWorkflowId = "cancel-begin-order-exchange" export const cancelBeginOrderExchangeWorkflowId = "cancel-begin-order-exchange"
/**
* This workflow cancels a requested order exchange.
*/
export const cancelBeginOrderExchangeWorkflow = createWorkflow( export const cancelBeginOrderExchangeWorkflow = createWorkflow(
cancelBeginOrderExchangeWorkflowId, cancelBeginOrderExchangeWorkflowId,
function (input: WorkflowInput): WorkflowData<void> { function (input: CancelBeginOrderExchangeWorkflowInput): WorkflowData<void> {
const orderExchange: OrderExchangeDTO = useRemoteQueryStep({ const orderExchange: OrderExchangeDTO = useRemoteQueryStep({
entry_point: "order_exchange", entry_point: "order_exchange",
fields: ["id", "status", "order_id", "return_id", "canceled_at"], fields: ["id", "status", "order_id", "return_id", "canceled_at"],
@@ -73,7 +79,7 @@ export const cancelBeginOrderExchangeWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, orderExchange, orderChange }) cancelBeginOrderExchangeValidationStep({ order, orderExchange, orderChange })
const shippingToRemove = transform( const shippingToRemove = transform(
{ orderChange, input }, { orderChange, input },
@@ -18,7 +18,10 @@ import { cancelOrderExchangeStep } from "../../steps"
import { throwIfIsCancelled } from "../../utils/order-validation" import { throwIfIsCancelled } from "../../utils/order-validation"
import { cancelReturnWorkflow } from "../return/cancel-return" import { cancelReturnWorkflow } from "../return/cancel-return"
const validateOrder = createStep( /**
* This step validates that an exchange can be canceled.
*/
export const cancelExchangeValidateOrder = createStep(
"validate-exchange", "validate-exchange",
({ ({
orderExchange, orderExchange,
@@ -53,6 +56,9 @@ const validateOrder = createStep(
) )
export const cancelOrderExchangeWorkflowId = "cancel-exchange" export const cancelOrderExchangeWorkflowId = "cancel-exchange"
/**
* This workflow cancels a confirmed exchange.
*/
export const cancelOrderExchangeWorkflow = createWorkflow( export const cancelOrderExchangeWorkflow = createWorkflow(
cancelOrderExchangeWorkflowId, cancelOrderExchangeWorkflowId,
( (
@@ -74,7 +80,7 @@ export const cancelOrderExchangeWorkflow = createWorkflow(
throw_if_key_not_found: true, throw_if_key_not_found: true,
}) })
validateOrder({ orderExchange, input }) cancelExchangeValidateOrder({ orderExchange, input })
const lineItemIds = transform({ orderExchange }, ({ orderExchange }) => { const lineItemIds = transform({ orderExchange }, ({ orderExchange }) => {
return orderExchange.additional_items?.map((i) => i.item_id) return orderExchange.additional_items?.map((i) => i.item_id)
@@ -27,11 +27,14 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
type WorkflowInput = { export type ConfirmExchangeRequestWorkflowInput = {
exchange_id: string exchange_id: string
} }
const validationStep = createStep( /**
* This step validates that a requested exchange can be confirmed.
*/
export const confirmExchangeRequestValidationStep = createStep(
"validate-confirm-exchange-request", "validate-confirm-exchange-request",
async function ({ async function ({
order, order,
@@ -165,9 +168,12 @@ function extractShippingOption({ orderPreview, orderExchange, returnId }) {
} }
export const confirmExchangeRequestWorkflowId = "confirm-exchange-request" export const confirmExchangeRequestWorkflowId = "confirm-exchange-request"
/**
* This workflow confirms an exchange request.
*/
export const confirmExchangeRequestWorkflow = createWorkflow( export const confirmExchangeRequestWorkflow = createWorkflow(
confirmExchangeRequestWorkflowId, confirmExchangeRequestWorkflowId,
function (input: WorkflowInput): WorkflowResponse<OrderDTO> { function (input: ConfirmExchangeRequestWorkflowInput): WorkflowResponse<OrderDTO> {
const orderExchange: OrderExchangeDTO = useRemoteQueryStep({ const orderExchange: OrderExchangeDTO = useRemoteQueryStep({
entry_point: "order_exchange", entry_point: "order_exchange",
fields: ["id", "status", "order_id", "canceled_at"], fields: ["id", "status", "order_id", "canceled_at"],
@@ -217,7 +223,7 @@ export const confirmExchangeRequestWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, orderExchange, orderChange }) confirmExchangeRequestValidationStep({ order, orderExchange, orderChange })
const { exchangeItems, returnItems } = transform( const { exchangeItems, returnItems } = transform(
{ orderChange }, { orderChange },
@@ -20,7 +20,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that a shipping method can be created for an exchange.
*/
export const createExchangeShippingMethodValidationStep = createStep(
"validate-create-exchange-shipping-method", "validate-create-exchange-shipping-method",
async function ({ async function ({
order, order,
@@ -39,6 +42,9 @@ const validationStep = createStep(
export const createExchangeShippingMethodWorkflowId = export const createExchangeShippingMethodWorkflowId =
"create-exchange-shipping-method" "create-exchange-shipping-method"
/**
* This workflow creates a shipping method for an exchange.
*/
export const createExchangeShippingMethodWorkflow = createWorkflow( export const createExchangeShippingMethodWorkflow = createWorkflow(
createExchangeShippingMethodWorkflowId, createExchangeShippingMethodWorkflowId,
function (input: { function (input: {
@@ -92,7 +98,7 @@ export const createExchangeShippingMethodWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, orderExchange, orderChange }) createExchangeShippingMethodValidationStep({ order, orderExchange, orderChange })
const shippingMethodInput = transform( const shippingMethodInput = transform(
{ {
@@ -21,7 +21,10 @@ import {
} from "../../utils/order-validation" } from "../../utils/order-validation"
import { addOrderLineItemsWorkflow } from "../add-line-items" import { addOrderLineItemsWorkflow } from "../add-line-items"
const validationStep = createStep( /**
* This step validates that new items can be added to an exchange.
*/
export const exchangeAddNewItemValidationStep = createStep(
"exchange-add-new-item-validation", "exchange-add-new-item-validation",
async function ({ async function ({
order, order,
@@ -39,6 +42,9 @@ const validationStep = createStep(
) )
export const orderExchangeAddNewItemWorkflowId = "exchange-add-new-item" export const orderExchangeAddNewItemWorkflowId = "exchange-add-new-item"
/**
* This workflow adds new items to an exchange.
*/
export const orderExchangeAddNewItemWorkflow = createWorkflow( export const orderExchangeAddNewItemWorkflow = createWorkflow(
orderExchangeAddNewItemWorkflowId, orderExchangeAddNewItemWorkflowId,
function ( function (
@@ -73,7 +79,7 @@ export const orderExchangeAddNewItemWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ exchangeAddNewItemValidationStep({
order, order,
orderExchange, orderExchange,
orderChange, orderChange,
@@ -25,7 +25,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that items can be returned as part of an exchange.
*/
export const exchangeRequestItemReturnValidationStep = createStep(
"exchange-request-item-return-validation", "exchange-request-item-return-validation",
async function ({ async function ({
order, order,
@@ -50,6 +53,9 @@ const validationStep = createStep(
export const orderExchangeRequestItemReturnWorkflowId = export const orderExchangeRequestItemReturnWorkflowId =
"exchange-request-item-return" "exchange-request-item-return"
/**
* This workflow adds items to be retuned as part of the exchange.
*/
export const orderExchangeRequestItemReturnWorkflow = createWorkflow( export const orderExchangeRequestItemReturnWorkflow = createWorkflow(
orderExchangeRequestItemReturnWorkflowId, orderExchangeRequestItemReturnWorkflowId,
function ( function (
@@ -117,7 +123,7 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow(
status: [OrderChangeStatus.PENDING, OrderChangeStatus.REQUESTED], status: [OrderChangeStatus.PENDING, OrderChangeStatus.REQUESTED],
}) })
validationStep({ exchangeRequestItemReturnValidationStep({
order, order,
items: input.items, items: input.items,
orderExchange, orderExchange,
@@ -22,7 +22,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that a new item can be removed from an exchange.
*/
export const removeExchangeItemActionValidationStep = createStep(
"remove-item-exchange-action-validation", "remove-item-exchange-action-validation",
async function ({ async function ({
order, order,
@@ -54,6 +57,9 @@ const validationStep = createStep(
) )
export const removeItemExchangeActionWorkflowId = "remove-item-exchange-action" export const removeItemExchangeActionWorkflowId = "remove-item-exchange-action"
/**
* This workflow removes a new item in an exchange.
*/
export const removeItemExchangeActionWorkflow = createWorkflow( export const removeItemExchangeActionWorkflow = createWorkflow(
removeItemExchangeActionWorkflowId, removeItemExchangeActionWorkflowId,
function ( function (
@@ -88,7 +94,7 @@ export const removeItemExchangeActionWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, input, orderExchange, orderChange }) removeExchangeItemActionValidationStep({ order, input, orderExchange, orderChange })
deleteOrderChangeActionsStep({ ids: [input.action_id] }) deleteOrderChangeActionsStep({ ids: [input.action_id] })
@@ -23,7 +23,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that a shipping method can be removed from an exchange.
*/
export const removeExchangeShippingMethodValidationStep = createStep(
"validate-remove-exchange-shipping-method", "validate-remove-exchange-shipping-method",
async function ({ async function ({
orderChange, orderChange,
@@ -55,6 +58,9 @@ const validationStep = createStep(
export const removeExchangeShippingMethodWorkflowId = export const removeExchangeShippingMethodWorkflowId =
"remove-exchange-shipping-method" "remove-exchange-shipping-method"
/**
* This workflow removes a shipping method of an exchange.
*/
export const removeExchangeShippingMethodWorkflow = createWorkflow( export const removeExchangeShippingMethodWorkflow = createWorkflow(
removeExchangeShippingMethodWorkflowId, removeExchangeShippingMethodWorkflowId,
function ( function (
@@ -81,7 +87,7 @@ export const removeExchangeShippingMethodWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ orderExchange, orderChange, input }) removeExchangeShippingMethodValidationStep({ orderExchange, orderChange, input })
const dataToRemove = transform( const dataToRemove = transform(
{ orderChange, input }, { orderChange, input },
@@ -23,7 +23,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that a new item can be removed from an exchange.
*/
export const updateExchangeAddItemValidationStep = createStep(
"update-exchange-add-item-validation", "update-exchange-add-item-validation",
async function ( async function (
{ {
@@ -58,6 +61,9 @@ const validationStep = createStep(
) )
export const updateExchangeAddItemWorkflowId = "update-exchange-add-item" export const updateExchangeAddItemWorkflowId = "update-exchange-add-item"
/**
* This workflow updates a new item in the exchange.
*/
export const updateExchangeAddItemWorkflow = createWorkflow( export const updateExchangeAddItemWorkflow = createWorkflow(
updateExchangeAddItemWorkflowId, updateExchangeAddItemWorkflowId,
function ( function (
@@ -92,7 +98,7 @@ export const updateExchangeAddItemWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ order, input, orderExchange, orderChange }) updateExchangeAddItemValidationStep({ order, input, orderExchange, orderChange })
const updateData = transform( const updateData = transform(
{ orderChange, input }, { orderChange, input },
@@ -25,7 +25,10 @@ import {
throwIfOrderChangeIsNotActive, throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation" } from "../../utils/order-validation"
const validationStep = createStep( /**
* This step validates that an exchange's shipping method can be updated.
*/
export const updateExchangeShippingMethodValidationStep = createStep(
"validate-update-exchange-shipping-method", "validate-update-exchange-shipping-method",
async function ({ async function ({
orderChange, orderChange,
@@ -57,6 +60,9 @@ const validationStep = createStep(
export const updateExchangeShippingMethodWorkflowId = export const updateExchangeShippingMethodWorkflowId =
"update-exchange-shipping-method" "update-exchange-shipping-method"
/**
* This workflow updates an exchange's shipping method.
*/
export const updateExchangeShippingMethodWorkflow = createWorkflow( export const updateExchangeShippingMethodWorkflow = createWorkflow(
updateExchangeShippingMethodWorkflowId, updateExchangeShippingMethodWorkflowId,
function ( function (
@@ -83,7 +89,7 @@ export const updateExchangeShippingMethodWorkflow = createWorkflow(
list: false, list: false,
}).config({ name: "order-change-query" }) }).config({ name: "order-change-query" })
validationStep({ orderExchange, orderChange, input }) updateExchangeShippingMethodValidationStep({ orderExchange, orderChange, input })
const updateData = transform( const updateData = transform(
{ orderChange, input }, { orderChange, input },