Skip to content

fix!: do not return undefined headers (Node 16 update)#33

Merged
Manuel Spagnolo (shikaan) merged 10 commits intomasterfrom
fix/no-undefined-headers
Aug 23, 2021
Merged

fix!: do not return undefined headers (Node 16 update)#33
Manuel Spagnolo (shikaan) merged 10 commits intomasterfrom
fix/no-undefined-headers

Conversation

@shikaan
Copy link
Copy Markdown
Contributor

@shikaan Manuel Spagnolo (shikaan) commented Aug 19, 2021

Node 16 seems to be much less tolerant when it comes to undefined headers (previous versions were ignoring headers, nwer versions are complaining about the headers type not being a string).

@shikaan Manuel Spagnolo (shikaan) changed the title fix: do not return undefined headers, cleanup fix!: do not return undefined headers (Node 16 update) Aug 20, 2021
@shikaan Manuel Spagnolo (shikaan) marked this pull request as ready for review August 20, 2021 07:25
@shikaan Manuel Spagnolo (shikaan) requested a review from a team August 20, 2021 07:25
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
rawTimestamp?: Timestamp,
rawContext?: any
) {
const maybeDefaultTimestamp = rawTimestamp ?? Date.now()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I don't really like that variable name. It doesn't really say what it is actually storing. Also: Why not using the fallback date in the function's signature as we did in the old impementation?

Comment thread src/requests/sign-request.ts Outdated
{ ...headers, ...(contextHeaders as Record<string, string>) },
timestamp
)
const contextHeaders = rawContext ? normalizeContextHeaders(rawContext) : undefined
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can simplify the next few lines by setting contextHeaders to {} if rawContext is not defined.

That way you can remove the condition in line 106-108 and remove the nullish coalescing (??) from line 114.

This would make things easier to read imo.

  const contextHeaders = rawContext ? normalizeContextHeaders(rawContext) : {}

  const { sortedHeaders, signedHeaders } = getSortedAndSignedHeaders(
    { ...headers, ...contextHeaders },
    timestamp
  )

  return {
    [ContentfulHeader.Signature]: hash({ method, headers: sortedHeaders, path, body }, secret),
    [ContentfulHeader.SignedHeaders]: signedHeaders,
    [ContentfulHeader.Timestamp]: timestamp.toString(),
    ...contextHeaders,
  }

Copy link
Copy Markdown
Contributor

@kdamball Kado (kdamball) left a comment

Choose a reason for hiding this comment

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

LGTM beside the point Andi made

@shikaan Manuel Spagnolo (shikaan) merged commit 5ff5bc1 into master Aug 23, 2021
@shikaan Manuel Spagnolo (shikaan) deleted the fix/no-undefined-headers branch August 23, 2021 07:08
Manuel Spagnolo (shikaan) added a commit that referenced this pull request Aug 23, 2021
* fix!: do not return undefined headers, cleanup
* test!: cover no context case + cleanup

BREAKING CHANGE: this changes typings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants