Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Plugin options validation #25

Open
jeff-sexton opened this issue Sep 3, 2020 · 2 comments
Open

Add Plugin options validation #25

jeff-sexton opened this issue Sep 3, 2020 · 2 comments
Labels
question Further information is requested

Comments

@jeff-sexton
Copy link
Contributor

Needs discussion:

The plugin needs to validate options after we construct the options object. We can iterate over the keys and ensure everything we expect exists and is the correct type.

Possible implementation:

  const optionsTypeValidations = {
    sharedSecret: 'string',
    verificationError: 'string',
    verificationErrorMessage: 'string',
    extractSignature: () => {},
    constructSignatureString: () => {},
    getDigest: () => {},
    digestEncoding: 'string',
    getAlgorithm: () => {},
    algorithmMap: {},
    getSignatureEncoding: () => {}
  }

  for (const [key, value] of Object.entries(optionsTypeValidations)) {
    if (!options[key] || typeof options[key] !== typeof value) {
      throw new Error(`${key} option does not exist or is not of type ${typeof value}`)
    }
@jeff-sexton jeff-sexton added the question Further information is requested label Sep 3, 2020
@jkirkpatrick24
Copy link
Contributor

This is something we definitely want. let's do some investigating on the best way to validate these inputs. A few thoughts

  • Should we only validate in development mode to avoid any performance hits?
  • if so, how do we want to surface the errors in a useful way for developers?
  • Are there some validation libraries we can use to help us?

@jeff-sexton
Copy link
Contributor Author

I ran across this library https://github.com/dsheiko/bycontract . It uses JSDoc expressions to configure the validation tests. It might kill two birds with one stone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants