twilio / twilio-node

Node.js helper library
MIT License
1.37k stars 495 forks source link

Misleading / Incorrect documentation for webhook validation #1021

Closed maxiimillian closed 1 month ago

maxiimillian commented 1 month ago

Issue Summary

The comments above the webhook middleware function say that the optional validate property will default to true, however this is only the case when no options are passed in,

Steps to Reproduce

  1. Create a webhook using the additional options parameter, but don't include the validate property. Make sure that the options will make the request invalid.
  2. Send a webhook request

Existing Code

if (!options) { options = { validate: true, }; }

I think the documentation should state this clearly or should actually set the validate to true if its not being set

tiwarishubham635 commented 1 month ago

HI @maxiimillian! I am able to reproduce this. Will create a PR for this

maxiimillian commented 1 month ago

Thanks for having a look, just a heads up I believe this will set validate to true even when its been set in the options, since if validate is false, if (!options.validate) will be true.

Maybe a !('validate' in options) or (options.validate === undefined) would work better.

tiwarishubham635 commented 1 month ago

Yeah that makes sense, I'll make the change

tiwarishubham635 commented 1 month ago

@maxiimillian please check the PR now

maxiimillian commented 1 month ago

Looks good