Skip to content

Commit

Permalink
Merge pull request #32 from dbartholomae/add_header_normalizer_middle…
Browse files Browse the repository at this point in the history
…ware

Add header normalizer middleware
  • Loading branch information
dbartholomae authored Aug 13, 2020
2 parents 5a4f47e + 540b4b4 commit aa314af
Show file tree
Hide file tree
Showing 29 changed files with 576 additions and 57 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This monorepo is a collection of middleware for AWS lambda functions.
middleware.
* [@lambda-middleware/no-sniff](/packages/no-sniff): A middleware for adding the content type options no-sniff header
to AWS lambdas.
* [@lambda-middleware/http-header-normalizer](/packages/http-header-normalizer): Middleware for AWS lambdas that
normalizes headers to lower-case.

## Other packages

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
to: packages/<%= h.inflection.dasherize(name.toLowerCase()) %>/examples/hellowWorld.int-test.ts
to: packages/<%= h.inflection.dasherize(name.toLowerCase()) %>/examples/helloWorld.int-test.ts
---
import request from "supertest";
const server = request("http://localhost:3000/dev");

describe("Handler with no sniff middleware", () => {
describe("Handler with <%= h.inflection.dasherize(name) %> middleware", () => {
it("returns 200", async () => {
await server.get("/hello").expect(200);
});
Expand Down
2 changes: 1 addition & 1 deletion _templates/middleware/new/package/examples/helloWorld.ts.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
to: packages/<%= h.inflection.dasherize(name.toLowerCase()) %>/examples/hellowWorld.ts
to: packages/<%= h.inflection.dasherize(name.toLowerCase()) %>/examples/helloWorld.ts
---
import { <%=h.inflection.camelize(name, true) %> } from "../";

Expand Down
2 changes: 1 addition & 1 deletion _templates/middleware/new/package/src/middleware.test.ts.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("<%=h.inflection.camelize(name, true) %>", () => {
body: "",
};
const handler = jest.fn().mockResolvedValue(response);
expect(await noSniff()(handler)({} as any, {} as any)).toMatchObject(
expect(await <%=h.inflection.camelize(name, true) %>()(handler)({} as any, {} as any)).toMatchObject(
response
);
});
Expand Down
20 changes: 17 additions & 3 deletions _templates/middleware/new/prompt.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
const uppercase = new RegExp("([A-Z])", "g");
const underbar_prefix = new RegExp("^_");

function replaceAll(str, subStrs, by) {
let result = str;
for (const subStr of subStrs) {
result = result.split(subStr).join(by);
}
return result;
}

function underscore(str) {
return replaceAll(str.replace(uppercase, "_$1"), ["-", " "], "_");
}

module.exports = [
{
type: "input",
name: "name",
message:
"How do you want to call the middleware? Please separate with spaces, e. g. 'no sniff'",
result: (name) => name.toLowerCase(),
message: "How do you want to call the middleware?",
result: (name) => underscore(name),
},
{
type: "input",
Expand Down
121 changes: 72 additions & 49 deletions common/config/rush/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,39 @@
wait-on "^5.2.0"
webpack "^4.41.5"

"@rush-temp/http-header-normalizer@file:./projects/http-header-normalizer.tgz":
version "0.0.0"
resolved "file:./projects/http-header-normalizer.tgz#a22144ea0a51e6f48bd299b046b9d7a37bc8e465"
dependencies:
"@types/aws-lambda" "^8.10.47"
"@types/debug" "^4.1.5"
"@types/jest" "^25.2.1"
"@types/supertest" "^2.0.8"
"@typescript-eslint/eslint-plugin" "^2.26.0"
"@typescript-eslint/parser" "^2.26.0"
aws-lambda "^1.0.5"
concurrently "^5.1.0"
debug ">=4.1.0"
eslint "^6.8.0"
eslint-config-prettier "^6.10.1"
eslint-plugin-prettier "^3.1.2"
jest "^25.2.7"
jest-junit "^10.0.0"
pkg-ok "^2.3.1"
prettier "^2.0.2"
prettier-config-standard "^1.0.1"
rimraf "^3.0.2"
serverless "^1.67.0"
serverless-offline "^6.1.4"
serverless-webpack "^5.3.1"
source-map-support "^0.5.16"
supertest "^4.0.2"
ts-jest "^25.3.1"
ts-loader "^6.2.2"
typescript "^3.7.5"
wait-on "^5.2.0"
webpack "^4.41.5"

"@rush-temp/ie-no-open@file:./projects/ie-no-open.tgz":
version "0.0.0"
resolved "file:./projects/ie-no-open.tgz#4bf132dac67ae18dff973d89ae4137cb1b91bdeb"
Expand Down Expand Up @@ -1309,8 +1342,8 @@
shortid "^2.2.14"

"@serverless/components@^2.33.4":
version "2.34.1"
resolved "https://registry.yarnpkg.com/@serverless/components/-/components-2.34.1.tgz#a33c02c8607aa935ee03b1ef8a7a8cdfb9477fac"
version "2.34.3"
resolved "https://registry.yarnpkg.com/@serverless/components/-/components-2.34.3.tgz#5764e225c5306cac7dc2b6496a8a3e16703c1a07"
dependencies:
"@serverless/inquirer" "^1.1.2"
"@serverless/platform-client" "^1.1.1"
Expand Down Expand Up @@ -1527,8 +1560,8 @@
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"

"@types/aws-lambda@^8.10.47":
version "8.10.59"
resolved "https://registry.yarnpkg.com/@types/aws-lambda/-/aws-lambda-8.10.59.tgz#64f602aef1cac9b21a74aad6705bf350c4a5173a"
version "8.10.61"
resolved "https://registry.yarnpkg.com/@types/aws-lambda/-/aws-lambda-8.10.61.tgz#7471e08843dbdcf09b2494ac5b34c4d1a391e6d0"

"@types/babel__core@^7.1.7":
version "7.1.9"
Expand Down Expand Up @@ -2213,21 +2246,18 @@ arrify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"

arrify@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/arrify/-/arrify-2.0.1.tgz#c9655e9331e0abcd588d2a7cad7e9956f66701fa"

asap@^2.0.0:
version "2.0.6"
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"

asn1.js@^4.0.0:
version "4.10.1"
resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-4.10.1.tgz#b9c2bf5805f1e64aadeed6df3a2bfafb5a73f5a0"
asn1.js@^5.2.0:
version "5.4.1"
resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-5.4.1.tgz#11a980b84ebb91781ce35b0fdc2ee294e3783f07"
dependencies:
bn.js "^4.0.0"
inherits "^2.0.1"
minimalistic-assert "^1.0.0"
safer-buffer "^2.1.0"

asn1@~0.2.3:
version "0.2.4"
Expand Down Expand Up @@ -2298,8 +2328,8 @@ aws-lambda@^1.0.5:
watchpack "^2.0.0-beta.10"

aws-sdk@*, aws-sdk@^2.726.0:
version "2.729.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.729.0.tgz#3d850f7825b94b5d8b2aca58ec096973bc4c7e34"
version "2.732.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.732.0.tgz#03305b69c0d7ea18767aa0d99a9458e1bed48d65"
dependencies:
buffer "4.9.2"
events "1.1.1"
Expand All @@ -2316,8 +2346,8 @@ aws-sign2@~0.7.0:
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8"

aws4@^1.8.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.10.0.tgz#a17b3a8ea811060e74d47d306122400ad4497ae2"
version "1.10.1"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.10.1.tgz#e1e82e4f3e999e2cfd61b161280d16a111f86428"

axios@^0.19.2:
version "0.19.2"
Expand Down Expand Up @@ -2810,10 +2840,6 @@ camelcase@^5.0.0, camelcase@^5.3.1:
version "5.3.1"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"

camelcase@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.0.0.tgz#5259f7c30e35e278f1bdc2a4d91230b37cad981e"

capture-exit@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4"
Expand Down Expand Up @@ -2944,8 +2970,8 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3:
safe-buffer "^5.0.1"

class-transformer-validator@>=0.8.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/class-transformer-validator/-/class-transformer-validator-0.9.0.tgz#966c419e5243f146f8c32e5b6c3dc90d6ef264f8"
version "0.9.1"
resolved "https://registry.yarnpkg.com/class-transformer-validator/-/class-transformer-validator-0.9.1.tgz#81af4bab5e13ce619a25a74cc70f723a8c4e2779"

class-transformer@>=0.2.3:
version "0.3.1"
Expand Down Expand Up @@ -3557,8 +3583,8 @@ dateformat@^3.0.0:
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"

dayjs@^1.8.32:
version "1.8.32"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.32.tgz#66c48b95c397d9f7907e89bd29f78b3d19d40294"
version "1.8.33"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.33.tgz#18bc4a2b6c1c6f4d67b4c4f2536c0b97e5b766f7"

[email protected], debug@=3.1.0, debug@~3.1.0:
version "3.1.0"
Expand Down Expand Up @@ -4956,8 +4982,8 @@ globby@^9.2.0:
slash "^2.0.0"

google-libphonenumber@^3.2.8:
version "3.2.10"
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.10.tgz#021a314652747d736a39e2e60dc670f0431425ad"
version "3.2.11"
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.11.tgz#c5704513366b18f468a9505ea13e53f6fbcc9eec"

got@^6.7.1:
version "6.7.1"
Expand Down Expand Up @@ -7070,16 +7096,14 @@ meow@^5.0.0:
yargs-parser "^10.0.0"

meow@^7.0.0:
version "7.0.1"
resolved "https://registry.yarnpkg.com/meow/-/meow-7.0.1.tgz#1ed4a0a50b3844b451369c48362eb0515f04c1dc"
version "7.1.0"
resolved "https://registry.yarnpkg.com/meow/-/meow-7.1.0.tgz#50ecbcdafa16f8b58fb7eb9675b933f6473b3a59"
dependencies:
"@types/minimist" "^1.2.0"
arrify "^2.0.1"
camelcase "^6.0.0"
camelcase-keys "^6.2.2"
decamelize-keys "^1.1.0"
hard-rejection "^2.1.0"
minimist-options "^4.0.2"
minimist-options "4.1.0"
normalize-package-data "^2.5.0"
read-pkg-up "^7.0.1"
redent "^3.0.0"
Expand Down Expand Up @@ -7183,20 +7207,20 @@ minimatch@^3.0.2, minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"

minimist-options@^3.0.1:
version "3.0.2"
resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-3.0.2.tgz#fba4c8191339e13ecf4d61beb03f070103f3d954"
minimist-options@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-4.1.0.tgz#c0655713c53a8a2ebd77ffa247d342c40f010619"
dependencies:
arrify "^1.0.1"
is-plain-obj "^1.1.0"
kind-of "^6.0.3"

minimist-options@^4.0.2:
version "4.1.0"
resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-4.1.0.tgz#c0655713c53a8a2ebd77ffa247d342c40f010619"
minimist-options@^3.0.1:
version "3.0.2"
resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-3.0.2.tgz#fba4c8191339e13ecf4d61beb03f070103f3d954"
dependencies:
arrify "^1.0.1"
is-plain-obj "^1.1.0"
kind-of "^6.0.3"

minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5:
version "1.2.5"
Expand Down Expand Up @@ -8092,12 +8116,11 @@ parent-module@^1.0.0:
callsites "^3.0.0"

parse-asn1@^5.0.0, parse-asn1@^5.1.5:
version "5.1.5"
resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.5.tgz#003271343da58dc94cace494faef3d2147ecea0e"
version "5.1.6"
resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.6.tgz#385080a3ec13cb62a62d39409cb3e88844cdaed4"
dependencies:
asn1.js "^4.0.0"
asn1.js "^5.2.0"
browserify-aes "^1.0.0"
create-hash "^1.1.0"
evp_bytestokey "^1.0.0"
pbkdf2 "^3.0.3"
safe-buffer "^5.1.1"
Expand Down Expand Up @@ -9107,9 +9130,9 @@ serialize-error@>=5.0.0:
dependencies:
type-fest "^0.13.1"

serialize-javascript@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-3.1.0.tgz#8bf3a9170712664ef2561b44b691eafe399214ea"
serialize-javascript@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-4.0.0.tgz#b525e1238489a5ecfc42afacc3fe99e666f4b1aa"
dependencies:
randombytes "^2.1.0"

Expand Down Expand Up @@ -9974,14 +9997,14 @@ terminal-link@^2.0.0:
supports-hyperlinks "^2.0.0"

terser-webpack-plugin@^1.4.3:
version "1.4.4"
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.4.4.tgz#2c63544347324baafa9a56baaddf1634c8abfc2f"
version "1.4.5"
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.4.5.tgz#a217aefaea330e734ffacb6120ec1fa312d6040b"
dependencies:
cacache "^12.0.2"
find-cache-dir "^2.1.0"
is-wsl "^1.1.0"
schema-utils "^1.0.0"
serialize-javascript "^3.1.0"
serialize-javascript "^4.0.0"
source-map "^0.6.1"
terser "^4.1.2"
webpack-sources "^1.4.0"
Expand Down Expand Up @@ -10736,8 +10759,8 @@ widest-line@^3.1.0:
string-width "^4.0.0"

windows-release@^3.1.0:
version "3.3.1"
resolved "https://registry.yarnpkg.com/windows-release/-/windows-release-3.3.1.tgz#cb4e80385f8550f709727287bf71035e209c4ace"
version "3.3.3"
resolved "https://registry.yarnpkg.com/windows-release/-/windows-release-3.3.3.tgz#1c10027c7225743eec6b89df160d64c2e0293999"
dependencies:
execa "^1.0.0"

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
roots: ["<rootDir>/src"],
transform: {
"^.+\\.(t|j)sx?$": "ts-jest",
"^.+\\.tsx?$": "ts-jest",
},
testRegex: ".*(int-)?test\\.(t|j)sx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
Expand Down
12 changes: 12 additions & 0 deletions packages/http-header-normalizer/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
extends: [
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
sourceType: "module",
},
};
29 changes: 29 additions & 0 deletions packages/http-header-normalizer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# IDEs
.idea

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
package-lock.json
yarn-debug.log*
yarn-error.log*
yarn.lock

# Built library
lib
21 changes: 21 additions & 0 deletions packages/http-header-normalizer/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Daniel Bartholomae

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit aa314af

Please sign in to comment.