chore(medusa): do not use transaction id on cart operations (#13931)
This commit is contained in:
committed by
GitHub
parent
224ab39a81
commit
990691e78a
6
.changeset/red-pants-raise.md
Normal file
6
.changeset/red-pants-raise.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/core-flows": patch
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
chore(medusa): do not use transactionId for cart operations
|
||||
@@ -1922,7 +1922,7 @@ medusaIntegrationTestRunner({
|
||||
expect(res.data.order).toEqual(successData)
|
||||
}
|
||||
|
||||
expect(failure.length).toBeGreaterThan(0)
|
||||
expect(failure.length).toBe(0)
|
||||
|
||||
expect(successData).toEqual(
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import { acquireLockStep, releaseLockStep } from "../../locking"
|
||||
import { updateLineItemsStep } from "../steps"
|
||||
import { updateLineItemsStep, validateCartStep } from "../steps"
|
||||
import { cartFieldsForRefreshSteps } from "../utils/fields"
|
||||
import { pricingContextResult } from "../utils/schemas"
|
||||
import { getVariantsAndItemsWithPrices } from "./get-variants-and-items-with-prices"
|
||||
@@ -155,6 +155,8 @@ export const refreshCartItemsWorkflow = createWorkflow(
|
||||
},
|
||||
})
|
||||
|
||||
validateCartStep({ cart })
|
||||
|
||||
const { lineItems } = getVariantsAndItemsWithPrices.runAsStep({
|
||||
input: {
|
||||
cart,
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { AdditionalData } from "@medusajs/types"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import { acquireLockStep, releaseLockStep } from "../../locking"
|
||||
import { removeShippingMethodFromCartStep } from "../steps"
|
||||
import { removeShippingMethodFromCartStep, validateCartStep } from "../steps"
|
||||
import { updateShippingMethodsStep } from "../steps/update-shipping-methods"
|
||||
import { listShippingOptionsForCartWithPricingWorkflow } from "./list-shipping-options-for-cart-with-pricing"
|
||||
|
||||
@@ -109,6 +109,8 @@ export const refreshCartShippingMethodsWorkflow = createWorkflow(
|
||||
return fetchCart ?? input.cart
|
||||
})
|
||||
|
||||
validateCartStep({ cart })
|
||||
|
||||
acquireLockStep({
|
||||
key: cart.id,
|
||||
timeout: 2,
|
||||
|
||||
@@ -12,6 +12,7 @@ import { useQueryGraphStep } from "../../common"
|
||||
import { acquireLockStep, releaseLockStep } from "../../locking"
|
||||
import { updatePaymentCollectionStep } from "../../payment-collection"
|
||||
import { deletePaymentSessionsWorkflow } from "../../payment-collection/workflows/delete-payment-sessions"
|
||||
import { validateCartStep } from "../steps"
|
||||
|
||||
/**
|
||||
* The details of the cart to refresh.
|
||||
@@ -107,6 +108,8 @@ export const refreshPaymentCollectionForCartWorkflow = createWorkflow(
|
||||
return fetchCart ?? input.cart
|
||||
})
|
||||
|
||||
validateCartStep({ cart })
|
||||
|
||||
acquireLockStep({
|
||||
key: cart.id,
|
||||
timeout: 2,
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
prepareAdjustmentsFromPromotionActionsStep,
|
||||
removeLineItemAdjustmentsStep,
|
||||
removeShippingMethodAdjustmentsStep,
|
||||
validateCartStep,
|
||||
} from "../steps"
|
||||
import { updateCartPromotionsStep } from "../steps/update-cart-promotions"
|
||||
import { cartFieldsForRefreshSteps } from "../utils/fields"
|
||||
@@ -96,6 +97,8 @@ export const updateCartPromotionsWorkflow = createWorkflow(
|
||||
return input.cart ?? fetchCart
|
||||
})
|
||||
|
||||
validateCartStep({ cart })
|
||||
|
||||
acquireLockStep({
|
||||
key: cart.id,
|
||||
timeout: 2,
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
findOrCreateCustomerStep,
|
||||
findSalesChannelStep,
|
||||
updateCartsStep,
|
||||
validateCartStep,
|
||||
} from "../steps"
|
||||
import { validateSalesChannelStep } from "../steps/validate-sales-channel"
|
||||
import { refreshCartItemsWorkflow } from "./refresh-cart-items"
|
||||
@@ -111,6 +112,8 @@ export const updateCartWorkflow = createWorkflow(
|
||||
},
|
||||
}).config({ name: "get-cart" })
|
||||
|
||||
validateCartStep({ cart: cartToUpdate })
|
||||
|
||||
const cartDataInput = transform(
|
||||
{ input, cartToUpdate },
|
||||
(data: { input: UpdateCartWorkflowInput; cartToUpdate: CartDTO }) => {
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import { acquireLockStep, releaseLockStep } from "../../locking"
|
||||
import { getItemTaxLinesStep } from "../../tax/steps/get-item-tax-lines"
|
||||
import { setTaxLinesForItemsStep } from "../steps"
|
||||
import { setTaxLinesForItemsStep, validateCartStep } from "../steps"
|
||||
|
||||
const cartFields = [
|
||||
"id",
|
||||
@@ -144,6 +144,8 @@ export const updateTaxLinesWorkflow = createWorkflow(
|
||||
return input.cart ?? fetchCart
|
||||
})
|
||||
|
||||
validateCartStep({ cart })
|
||||
|
||||
acquireLockStep({
|
||||
key: cart.id,
|
||||
timeout: 2,
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import { getItemTaxLinesStep } from "../../tax/steps/get-item-tax-lines"
|
||||
import { validateCartStep } from "../steps"
|
||||
import { upsertTaxLinesForItemsStep } from "../steps/upsert-tax-lines-for-items"
|
||||
|
||||
const cartFields = [
|
||||
@@ -141,6 +142,8 @@ export const upsertTaxLinesWorkflow = createWorkflow(
|
||||
return input.cart ?? fetchCart
|
||||
})
|
||||
|
||||
validateCartStep({ cart })
|
||||
|
||||
const taxLineItems = getItemTaxLinesStep(
|
||||
transform({ input, cart }, (data) => ({
|
||||
orderOrCart: data.cart,
|
||||
|
||||
@@ -25,7 +25,6 @@ export const completeCartAfterPaymentStep = createStep(
|
||||
input: {
|
||||
id: input.cart_id,
|
||||
},
|
||||
transactionId: input.cart_id,
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
@@ -19,7 +19,6 @@ export const POST = async (
|
||||
|
||||
const { errors, result, transaction } = await we.run(completeCartWorkflowId, {
|
||||
input: { id: cart_id },
|
||||
transactionId: cart_id,
|
||||
throwOnError: false,
|
||||
})
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import {
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { refetchCart } from "../../helpers"
|
||||
import { AdditionalData } from "@medusajs/types"
|
||||
import { refetchCart } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdditionalData, HttpTypes.SelectParams>,
|
||||
@@ -21,7 +21,6 @@ export const POST = async (
|
||||
customer_id: req.auth_context?.actor_id,
|
||||
additional_data: req.validatedBody.additional_data,
|
||||
},
|
||||
transactionId: "cart-transfer-customer-" + req.params.id,
|
||||
})
|
||||
|
||||
const cart = await refetchCart(
|
||||
|
||||
@@ -22,7 +22,6 @@ export const POST = async (
|
||||
update: req.validatedBody,
|
||||
additional_data: req.validatedBody.additional_data,
|
||||
},
|
||||
transactionId: "cart-update-item-" + req.params.id,
|
||||
})
|
||||
|
||||
const updatedCart = await refetchCart(
|
||||
@@ -46,7 +45,6 @@ export const DELETE = async (
|
||||
cart_id: req.params.id,
|
||||
ids: [id],
|
||||
},
|
||||
transactionId: "cart-delete-item-" + req.params.id,
|
||||
})
|
||||
|
||||
const cart = await refetchCart(
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { addToCartWorkflowId } from "@medusajs/core-flows"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import { AdditionalData } from "@medusajs/types"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { refetchCart } from "../../helpers"
|
||||
import { AdditionalData } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: MedusaRequest<
|
||||
@@ -19,7 +19,6 @@ export const POST = async (
|
||||
items: [req.validatedBody],
|
||||
additional_data: req.validatedBody.additional_data,
|
||||
},
|
||||
transactionId: "cart-add-item-" + req.params.id,
|
||||
})
|
||||
|
||||
const cart = await refetchCart(
|
||||
|
||||
@@ -5,10 +5,7 @@ import { Modules, PromotionActions } from "@medusajs/framework/utils"
|
||||
import { refetchCart } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: MedusaRequest<
|
||||
HttpTypes.StoreCartAddPromotion,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
req: MedusaRequest<HttpTypes.StoreCartAddPromotion, HttpTypes.SelectParams>,
|
||||
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||
) => {
|
||||
const we = req.scope.resolve(Modules.WORKFLOW_ENGINE)
|
||||
@@ -23,7 +20,6 @@ export const POST = async (
|
||||
? PromotionActions.ADD
|
||||
: PromotionActions.REPLACE,
|
||||
},
|
||||
transactionId: "cart-update-promotions-" + req.params.id,
|
||||
})
|
||||
|
||||
const cart = await refetchCart(
|
||||
@@ -36,7 +32,10 @@ export const POST = async (
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: MedusaRequest<HttpTypes.StoreCartRemovePromotion, HttpTypes.SelectParams>,
|
||||
req: MedusaRequest<
|
||||
HttpTypes.StoreCartRemovePromotion,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<{
|
||||
cart: HttpTypes.StoreCart
|
||||
}>
|
||||
@@ -50,7 +49,6 @@ export const DELETE = async (
|
||||
cart_id: req.params.id,
|
||||
action: PromotionActions.REMOVE,
|
||||
},
|
||||
transactionId: "cart-delete-promotions-" + req.params.id,
|
||||
})
|
||||
|
||||
const cart = await refetchCart(
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { updateCartWorkflowId } from "@medusajs/core-flows"
|
||||
import {
|
||||
AdditionalData,
|
||||
HttpTypes,
|
||||
} from "@medusajs/framework/types"
|
||||
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
@@ -38,7 +35,6 @@ export const POST = async (
|
||||
id: req.params.id,
|
||||
additional_data: req.validatedBody.additional_data,
|
||||
},
|
||||
transactionId: "cart-update-" + req.params.id,
|
||||
})
|
||||
|
||||
const cart = await refetchCart(
|
||||
|
||||
@@ -34,7 +34,6 @@ export const POST = async (
|
||||
const we = req.scope.resolve(Modules.WORKFLOW_ENGINE)
|
||||
await we.run(createPaymentCollectionForCartWorkflowId, {
|
||||
input: req.body,
|
||||
transactionId: "create-payment-collection-for-cart-" + cart_id,
|
||||
})
|
||||
|
||||
const [cartCollectionRelation] = await remoteQuery(
|
||||
|
||||
Reference in New Issue
Block a user