From 93b38bf47b820f9783c3def363beb7347e9fed75 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Sat, 12 Oct 2024 05:13:13 +0530 Subject: [PATCH] fix: do not pass additional_data to service (#9532) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: FRMW-2743 This PR extracts and removes the `additional_data` from the workflow input before calling the steps and hence the `additional_data` is not passed down to the service layer. However, this bug has made me discover one inconsistency in the input structure of certain workflows. ✅ **Following is the input structure of the `updateProductsWorkflow`**. Here, we accept the `products` and the `additional_data` as two separate top-level properties. ```ts // Shape export type UpdateProductsWorkflowInputSelector = { selector: ProductTypes.FilterableProductProps update: Omit & { sales_channels?: { id: string }[] variants?: UpdateProductVariantWorkflowInputDTO[] } } & AdditionalData // Calling the workflow const { result } = await updateProductsWorkflow(req.scope).run({ input: { selector: { id: req.params.id }, update, additional_data, }, }) ``` ❌ **Following in the input structure of the `updateCartWorflow`**. In this case, we are accepting the cart properties at the top-level, hence the `additional_data` is merged within those properties, increasing the chance of passing it down to the service layer by mistake. ```ts // Shape WorkflowData // Calling the workflow await workflow.run({ input: { ...req.validatedBody // Additional data is part of the validatedBody, id: req.params.id, }, }) ``` Ideally, the input of `updateCartWorkflow` should look as follows. ```ts WorkflowData<{ cart: UpdateCartWorkflowInputDTO } & AdditionalData> ``` --- packages/core/core-flows/src/cart/workflows/update-cart.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/core-flows/src/cart/workflows/update-cart.ts b/packages/core/core-flows/src/cart/workflows/update-cart.ts index 6ba00a988d..6f30a186f2 100644 --- a/packages/core/core-flows/src/cart/workflows/update-cart.ts +++ b/packages/core/core-flows/src/cart/workflows/update-cart.ts @@ -68,7 +68,11 @@ export const updateCartWorkflow = createWorkflow( const cartInput = transform( { input, region, customerData, salesChannel, cartToUpdate }, (data) => { - const { promo_codes, ...updateCartData } = data.input + const { + promo_codes, + additional_data: _, + ...updateCartData + } = data.input const data_ = { ...updateCartData,