Skip to content

Commit

Permalink
fix: do not pass additional_data to service (#9532)
Browse files Browse the repository at this point in the history
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<ProductTypes.UpdateProductDTO, "variants"> & {
    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<UpdateCartWorkflowInputDTO & AdditionalData>

// 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>
```
  • Loading branch information
thetutlage authored Oct 11, 2024
1 parent c8b375a commit 93b38bf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/core/core-flows/src/cart/workflows/update-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 93b38bf

Please sign in to comment.