-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: request verification example code in comments not being usable #15
Conversation
VaguelySerious
commented
Nov 4, 2020
•
edited
Loading
edited
- Fix error from missing number casting of timestamp header
- Fix code in comments/documentation not being usable due to wrong imports
- Some beauty changes
src/requests/sign-request.ts
Outdated
* const {pick} = require('lodash') | ||
* const {server} = require('./imaginary-server') | ||
* | ||
* const SECRET = process.env.SECRET | ||
* | ||
* server.post('/api/my-resources', (req, res) => { | ||
* const incomingSignature = req.headers['x-contentful-signature'] | ||
* const incomingTimestamp = req.headers['x-contentful-timestamp'] | ||
* const incomingTimestamp = Number(req.headers['x-contentful-timestamp']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This really depends on the imaginary framework, I don't it's a mistake. If we want to enforce type, then we should use Number.parseInt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Headers are always strings, and this code will, as far as I can see, fail 100% of the time, because we pass incomingTimestamp
to TimestampValidator
internally which will throw if it is a string.
I will use Number.parseInt
, that's fine
src/requests/utils.ts
Outdated
return headers | ||
} | ||
|
||
export const pickHeaders = (headers: Record<string, string>, keys: string[]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Headers are generally speaking not mandatory in our model. This should stay optional for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These if
statements are unused, even if the user passes no headers, because we already validate it beforehand and pass an empty object here
src/index.ts
Outdated
@@ -1,3 +1,3 @@ | |||
export { getManagementToken } from './keys' | |||
export { signRequest, verifyRequest, ContentfulHeader } from './requests' | |||
export { Secret, CanonicalRequest, Timestamp, SignedRequestHeaders } from './requests/typings' | |||
export { CanonicalRequest, SignedRequestHeaders } from './requests/typings' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus, this should be moved into the ./requests/index.ts
and exported from there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Secret and Timestamp are just string
and number
types, and they are not otherwise relevant to the user, so it make little sense to export them.
I agree that the other types should be exported through requests/index
Forgot to mention, the commit type should be |
How do I change the commit type after the fact? Force push? And since we are exporting more types, a fix version seems appropriate |
🎉 This PR is included in version 1.3.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |