adobe/helix-shared

body-data and requiredConfig do not work together

dominique-pfister opened this issue · 3 comments

I have a universal action that fetches its required configuration from a JSON request body, including other properties I need to look at. If I set up my action like this:

module.exports.main = wrap(main)
  .with(bodyData)
  .with(requiredConfig, 'index')

the index configuration is valid, but the JSON request body expected in context.data is empty.

If I inverse the order:

module.exports.main = wrap(main)
  .with(requiredConfig, 'index')
  .with(bodyData)

I get my JSON request body in context.data, but the required configuration fails.

Reason for that is both wrappers replace the initial request with a new one, e.g.:

const newreq = new Request(request.url, request.init);

which effectively hides any request body parameters for the wrapper following.

No, that is not the reason, will investigate further.

As a workaround, I can set up my index configuration "by hand", just wanted to advise if someone else runs into this.

Making requiredConfig aware of context.data will fix this issue, with this order of wraps:

module.exports.main = wrap(main)
  .with(requiredConfig, 'index')
  .with(bodyData)

Tested this again with a universal action deployed on AWS, and I can no longer reproduce it: I logged the request.init on both entry and exit of bodyData.getData() and configWrapper.getData() and everything runs perfect.