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