Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Prevent raw curies from being sent in a request. Allow removing empty… #153

Merged
merged 2 commits into from
May 29, 2019

Conversation

stevelikesmusic
Copy link
Contributor

@stevelikesmusic stevelikesmusic commented May 27, 2019

Ticket

https://zapierorg.atlassian.net/browse/PDE-889 from Issue

From issue: https://github.com/zapier/zapier/issues/25928

This PR addresses two issues:

  1. Prevent unresolved curlies from being sent in query params or the request body
  2. Check if we should prune missing values from the body

A couple considerations, we don't remove unresolved curlies from url path. This might allow something like https://api.com/resouce/{{bundle.inputData.id}}

Some context from slack

if (req.removeMissingValuesFrom.params) {
pruneMissingQueryParams(req.params);
}
Object.entries(req.params).forEach(normalizeEmptyParamField(req));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toyed with using reduce to return a new object that could get piped to later operations. In the end, we're mutating request many other places, so stuck with that pattern.

@@ -110,9 +110,39 @@ const createBundleBank = (appRaw, event = {}) => {

const maskOutput = output => _.pick(output, 'results', 'status');

const normalizeEmptyRequestField = (shouldCleanup, field) => req => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept this as a callback to an array iterator function like forEach. We could pull that part in here and have a simple call to normalize that loops for the supplied field from request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I like the idea of centralizing the call to Object.entries so we don't need to keep re-typing that. Doesn't look like there's any place where the calling function needs to change that callback directly.

@stevelikesmusic stevelikesmusic force-pushed the fix/handle-empty-body-fields branch from f953cf7 to 914941a Compare May 27, 2019 15:23
Copy link
Contributor

@xavdid xavdid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the code itself looks good, but i'm a little worried about changing default behavior (even if it's bad). I get that we need to abstract this some for godzilla use, but I think we should be careful. ¯\_(ツ)_/¯

Also, you sure do like your function factories 😀

@stevelikesmusic
Copy link
Contributor Author

I go back and forth between factories and partial application 😆 Definitely a fan of some type of curried pattern.

I agree about being careful. What would you suggest? This is a CLI problem as well. Godzilla is just a CLI perform using the request shorthand. If a CLI app uses curlies for an input that comes back empty in a shorthand request, won't we do the same?

We could totally limit the surface area and check for is_ui, but I think it's really affecting all v3 integrations—not just UI.

@xavdid
Copy link
Contributor

xavdid commented May 28, 2019

Totally. I think this is a good way to do it, just that "changing default behavior" sets off warning bells. 😁 should be good though!

@bcooksey
Copy link
Contributor

I think this all checks out. I too was worried about default behavior change, but thinking a bit more on it, this is just being helpful. There is never a reason to send curlies, so replacing those with empty string by default now is a slight improvement. And then the option is there to strip the key out completely if the dev needs it.

@stevelikesmusic stevelikesmusic merged commit 1051626 into master May 29, 2019
@stevelikesmusic stevelikesmusic deleted the fix/handle-empty-body-fields branch May 29, 2019 10:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants