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