{"_id":"@seedrs/middyjs-middleware","_rev":"102-280a6ad3537432244b89580bec901929","name":"@seedrs/middyjs-middleware","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@seedrs/middyjs-middleware","version":"1.0.0","author":{"name":"tech@seedrs.com"},"_id":"@seedrs/middyjs-middleware@1.0.0","maintainers":[{"name":"benjamin_sotty","email":"benjamin.sotty@gmail.com"},{"name":"brizido","email":"ricardo.brizido@gmail.com"},{"name":"catarinasantana","email":"catarina.santana@seedrs.com"},{"name":"davidlewisseedrs","email":"david.lewis@seedrs.com"},{"name":"dkeen0123","email":"keendaniel01@gmail.com"},{"name":"kenleytomlin","email":"kenleytomlin@gmail.com"},{"name":"risheepatel","email":"rishee.patel@gmail.com"},{"name":"sahmed","email":"safin.ahmed@seedrs.com"},{"name":"seedrs.bot","email":"development.team@seedrs.com"},{"name":"seedrs1","email":"development.team@seedrs.com"}],"dist":{"shasum":"d2928fb32137b3d3f1b9b51e9e05ea3eb14acc87","tarball":"https://registry.npmjs.org/@seedrs/middyjs-middleware/-/middyjs-middleware-1.0.0.tgz","fileCount":42,"integrity":"sha512-LJL58Lvr42EFPxZhpU7Rm8sD0UpQT/z2DgHDlxbNAiHvJt1W4kwpLtvdTySakDRNFCaXJW/j3++053Zso0nMXg==","signatures":[{"sig":"MEQCIDkyj25Yhq4OHFIOl119eM7ZmGtV0m48x+aNt1RVzxImAiAmt3krj+FPDdyDx+zD//hC01xbzTm67iuvMl0Upz3KiQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":261312,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbvhcNCRA9TVsSAnZWagAAahgP+gLrCM5kVgJlhCIr0e25\n/YKifz2QYbRe0tAQw8B72/FhkyHsN9ej4EmdCFLdMYKg6F3BoRbt2kiN9a/6\n/ShxqOX3F68hTNanL36kzOL93kIujroLtPuq7mRhDA28esJ4BeeCdIKQ4tJl\nY+AJDZRJ1AlT/4s/NJXekcjrRV0VzuuMAKHybOMixAtxFlbS1EWYxvl4VhGs\nesxJ9yXgxEtxxgpuJR0D5t9hKQwJdwOKuQc+Ebxkn4+NV3epR1R0oKTwg7we\n+4Bvsg+ICIs6JPRtaopbyrma9um83z4LCbqspmiCsaO+zXHB5AVeZilpFw9P\nK1+LMKsQdHK4G0V8hg3ro+he/f4ryRljO3uIgYP9AGsBqfBJyVI46+3ujIk5\n1yJ0hxf5qaM4EW1OGU/iHpN+V6/ih/nucc0HTHY3d0Kdi8GcRYK9GPebO0uA\nRw+z/L9PZF0OUkSNTEBNvjkMzGqDJCf0+EBVA+r3914v5XxitURP7d2xf/VQ\nliDfxR8HFL7fyqyalGP7zS7gc1GL4Xbm4gt8xWq2E9nv+Ij/uAupXXezZjKy\n7OcW9sptAYJ3ellzMHlwkEiuq8v8KpIwBHfhCSL1yRvfgjDQzfpyCUJqcZhI\nJfZXypJTrdgoLFyR3K464BtdW5K9di/nd+qVfoD5Uk9dKR0r5QfcR7BXrR/X\neFtI\r\n=fEp3\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"testURL":"http://localhost","testMatch":["<rootDir>__tests__/**/*.{js}"],"transform":{"^.+\\.(js|jsx|mjs)$":"<rootDir>/node_modules/babel-jest"},"testEnvironment":"node","moduleNameMapper":{"^mocks(.+)":"<rootDir>mocks$1","^fixtures(.+)":"<rootDir>__tests__/fixtures$1","^middlewares(.+)":"<rootDir>src$1"},"moduleFileExtensions":["js"],"transformIgnorePatterns":["[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"]},"main":"lib/index.js","config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"gitHead":"9fc9675c911a532801ed1108b0fab742ab16fd09","scripts":{"lint":"eslint ./src/*","test":"node scripts/test.js","build":"babel src --presets babel-preset-env --out-dir lib","commit":"git-cz","semantic-release":"semantic-release --no-ci -b $BUILDKITE_JOB_ID"},"_npmUser":{"name":"seedrs.bot","email":"development.team@seedrs.com"},"_npmVersion":"6.4.1","description":"Middleware for middyjs","directories":{},"_nodeVersion":"8.10.0","dependencies":{"http-errors":"^1.7.1"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^23.6.0","middy":"^0.19.1","eslint":"^5.6.0","babel-cli":"^6.26.0","babel-core":"^6.26.3","babel-preset-env":"^1.7.0","semantic-release":"^15.9.15","eslint-plugin-jest":"^21.22.0","eslint-plugin-import":"^2.14.0","cz-conventional-changelog":"^2.1.0","@seedrs/eslint-config-seedrs-base":"^1.1.1","babel-plugin-transform-object-rest-spread":"^6.26.0"},"_npmOperationalInternal":{"tmp":"tmp/middyjs-middleware_1.0.0_1539184396469_0.5234460101134548","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@seedrs/middyjs-middleware","version":"1.0.1","author":{"name":"tech@seedrs.com"},"_id":"@seedrs/middyjs-middleware@1.0.1","maintainers":[{"name":"antonjseedrs","email":"anton.jidkov@seedrs.com"},{"name":"benjamin_sotty","email":"benjamin.sotty@gmail.com"},{"name":"brizido","email":"ricardo.brizido@gmail.com"},{"name":"catarinasantana","email":"catarina.santana@seedrs.com"},{"name":"dkeen0123","email":"keendaniel01@gmail.com"},{"name":"jmgcrespo","email":"jmgcrespo@gmail.com"},{"name":"kenleytomlin","email":"kenleytomlin@gmail.com"},{"name":"risheepatel","email":"rishee.patel@gmail.com"},{"name":"rodrigo.tomonari","email":"rodrigo.tomonari@seedrs.com"},{"name":"sahmed","email":"safin.ahmed@seedrs.com"},{"name":"seedrs.bot","email":"development.team@seedrs.com"},{"name":"seedrs1","email":"development.team@seedrs.com"}],"dist":{"shasum":"9494b6ee5c3e32e1989cf5ddae802941b2506f62","tarball":"https://registry.npmjs.org/@seedrs/middyjs-middleware/-/middyjs-middleware-1.0.1.tgz","fileCount":42,"integrity":"sha512-ggckRJmejbfdbxDmT1F/Z51o7seUJTCLZk7aU+m+a0fG4Zp0Miot34x54K+EGC8JlBuw5+176sPvihd5DzIvhQ==","signatures":[{"sig":"MEUCICkBsmSgcB/M/ntNenTETdquc5/cifuJdQryTFoTcBvrAiEAugYDs9iNEr0jmAThdmo0rBvnObUr332qUJRpa34hHEI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":266617,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb7ar4CRA9TVsSAnZWagAA0BgQAKFgHz1qwtyFWS7dfJpr\nFWYLpxMcCse4q6ZLUfTv+3m4Om5BNRV7ZKXeZUAkABWHLJPXqLr+sRS5trHs\n7/YYUVMRlPnSiRA2wuS5MfAoykcxaZg3P9FdrXIwQYb+LN1XWcp5ew/qUFMV\nnaJuJWd4/bhc/OClBhtqYONx65D/0u508NSUX1c2g93NXeloEKxzE7UEKU8I\nrvIYKIZAaurBojNWM8fR6VyIwCnug0JM4Z5sLItc3N477sgpije63mmMDipe\nkm4dlGtQAphytGcdFLbkK8Ull18IQ+JvSFwK8xZF8JiS2vRItHm4X9YwVlEO\nASvQm6Xp+fABO8hb6/Sikc7zEnHwugABikNQ8BeA6LH+R6XYJsfb6aqGxuse\nwETnyg/fJzZrByiCOLlOxoeDI+xuRjAQ0kbUWL7jdSu8L1Fba0w/h+gSOIT9\nf6q/9Ls9x/VX6EyGDjgN0gpX0H4Zf545Bg3TpfxqcfbiEftHnuM0f5/uYFgx\nL513BiCWkRvUuf2xCGjjWzgCSK97cOmFvWfSKCXWnQGZj1s9bx0Ts0CtnI7q\nkOQLnE0gBM4Jq2hKQidA3oJxbWlNtEFyMFe5fMxt65j1QsuKHgH6dl1cJf3G\nQnYHcYp9XW3cu4g6sXqYyr41J6sRJtWmnCZJSrTrTcrCN7MQa523GbQJOuRk\n3X8i\r\n=xR1o\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"testURL":"http://localhost","testMatch":["<rootDir>__tests__/**/*.{js}"],"transform":{"^.+\\.(js|jsx|mjs)$":"<rootDir>/node_modules/babel-jest"},"testEnvironment":"node","moduleNameMapper":{"^mocks(.+)":"<rootDir>mocks$1","^fixtures(.+)":"<rootDir>__tests__/fixtures$1","^middlewares(.+)":"<rootDir>src$1"},"moduleFileExtensions":["js"],"transformIgnorePatterns":["[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"]},"main":"lib/index.js","config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"gitHead":"9c7252f5c9daa157baba68c1ad87c376d95fd67f","scripts":{"lint":"eslint ./src/*","test":"node scripts/test.js","build":"babel src --presets babel-preset-env --out-dir lib","commit":"git-cz","semantic-release":"semantic-release --no-ci -b $BUILDKITE_JOB_ID"},"_npmUser":{"name":"seedrs.bot","email":"development.team@seedrs.com"},"_npmVersion":"6.4.1","description":"Middleware for middyjs","directories":{},"_nodeVersion":"8.10.0","dependencies":{"http-errors":"^1.7.1"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^23.6.0","middy":"^0.19.1","eslint":"^5.6.0","babel-cli":"^6.26.0","babel-core":"^6.26.3","babel-preset-env":"^1.7.0","semantic-release":"^15.9.15","eslint-plugin-jest":"^21.22.0","eslint-plugin-import":"^2.14.0","cz-conventional-changelog":"^2.1.0","@seedrs/eslint-config-seedrs-base":"^1.1.1","babel-plugin-transform-object-rest-spread":"^6.26.0"},"_npmOperationalInternal":{"tmp":"tmp/middyjs-middleware_1.0.1_1542302455223_0.7794814084209429","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-10-10T15:13:16.467Z","modified":"2026-10-01T13:54:50.427Z","1.0.0":"2018-10-10T15:13:16.627Z","1.0.1":"2018-11-15T17:20:55.353Z"},"author":{"name":"tech@seedrs.com"},"description":"Middleware for middyjs","maintainers":[{"email":"rishee.patel@gmail.com","name":"risheepatel"},{"email":"jonas.pereira@seedrs.com","name":"jpxiv"},{"email":"development.team@seedrs.com","name":"seedrs1"}],"readme":"# middyjs-middleware\n\nMiddleware for use with middyjs 🛵 [middyjs](https://github.com/middyjs/middy)\n\n## Setup\n\n#### Install with `npm` or `yarn` (preferred)\n\n```bash\nnpm i @seedrs/middyjs-middleware --save\n```\n\n##### OR\n\n```bash\nyarn add @seedrs/middyjs-middleware\n```\n\n## Available middleware\n\n### ensureJson\n\nThis middleware is used to ensure the client has set the\nContent-Type header to application/json when sending a request body.\nA 406 error is returned when application/json is not present in the\nContent-Type header. To ensure that header names are normalized use in\nconjunction with [middyjs/middlewares/httpHeaderNormalizer](https://github.com/middyjs/middy/blob/master/docs/middlewares.md#httpheadernormalizer) and with [middyjs/middlewares/jsonBodyParser](https://github.com/middyjs/middy/blob/master/docs/middlewares.md#jsonbodyparser) to parse the incoming body for you.\n\n```javascript\nconst middy = require('middy');\nconst {\n  httpHeaderNormalizer,\n  jsonBodyParser\n} = require('middyjs/middlewares');\nconst { ensureJson } = require('@seedrs/middyjs-middleware');\n\nconst handler = middy((event, context, cb) => {\n  return cb(null, {});\n})\n.use(httpHeaderNormalizer())\n.use(ensureJson())\n.use(jsonBodyParser())\n.use(httpErrorHandler(logger);\n```\n\n### httpErrorHandler\n\nThis middleware is used to catch any errors thrown in your application\ncode and return a formatted message using errors created with\n[jshttp/http-errors](https://github.com/jshttp/http-errors). Errors are logged\nby the logger passed as the argument to the middleware. Intended for use\nwith [node-bunyan](https://github.com/trentm/node-bunyan) and [@seedrs/bunyan-seedrs-serverless-serializer](https://github.com/Seedrs/bunyan-seedrs-serverless-serializer).\n\n```javascript\nconst middy = require('middy');\nconst createError = require('http-errors');\nconst { httpErrorHandler } = require('@seedrs/middyjs-middleware');\n\nconst handler = middy((event, context, cb) => {\n  const error = createError.NotFoundError();\n  return cb(error);\n})\n.use(httpErrorHandler(logger));\n```\n\n### dynamodbStreamErrorHandler\n\nThis middleware will log errors when consuming a dynamodb stream. It is\nintended for use with [node-bunyan](https://github.com/trentm/node-bunyan) and [@seedrs/bunyan-seedrs-serverless-serializer](https://github.com/Seedrs/bunyan-seedrs-serverless-serializer).\n\n```javascript\nconst middy = require('middy');\nconst { dynamodbStreamErrorHandler\n} = require('@seedrs/middyjs-middleware');\n\nconst handler = middy((event, context, cb) => {\n  throw new Error('Whoops');\n})\n.use(dynamodbStreamErrorHandler(logger));\n```\n\n### dynamodbStreamFilter\n\nThis middleware filters out unwanted events and ends the\nlambda execution early if there are no matching events in the stream. In the example below the\nbusiness logic will only execute when there are Records with the INSERT\nevent type.\n\n```javascript\nconst middy = require('middy');\nconst { dynamodbStreamFilter } = require('@seedrs/middyjs-middleware');\n\nconst handler = middy((event, context, cb) => {\n  //Some business logic runs when there are INSERT events\n})\n.use(dynamodbStreamFilter({ eventName: 'INSERT' }));\n```\n\n### dynamodbStreamParser\n\nThis middleware parses and extracts fields specified in the\nevent. You can specify either to extract from the OldImage or the\nNewImage (if your stream is configured to show both) or specify either\nOldImage or NewImage.\n\n```javascript\nconst middy = require('middy');\nconst { dynamodbStreamParser } = require('@seedrs/middyjs-middleware');\n\nconst handler = middy((event, context, cb) => {\n  console.log(event.Records);\n  /* Shown below is the parsed stream objects\n  [{\n    {\n      OldImage: {\n        key_one: 1\n      },\n      NewImage: {\n        key_one: 2\n      }\n    }\n  }]\n  */\n})\n.use(dynamodbStreamParser({\n  NewImage: [\n    'key_one'\n  ],\n  OldImage: [\n    'key_one'\n  ]\n});\n```\n\n### s3ErrorHandler\n\nThis middleware is intended to be used with [node-bunyan](https://github.com/trentm/node-bunyan) and [@seedrs/bunyan-seedrs-serverless-serializer](https://github.com/Seedrs/bunyan-seedrs-serverless-serializer). It logs the error produced along with the S3 event that triggered the invocation.\n\n```javascript\nconst middy = require('middy');\nconst { httpErrorHandler } = require('@seedrs/middyjs-middleware');\n\nconst handler = middy((event, context, cb) => {\n  //Some business logic\n})\n.use(s3ErrorHandler(logger));\n```\n\n#### Usage without bunyan and seedrs/bunyan-seedrs-serverless-serializer\n\nIt is possible to provide a custom object that uses your own logging\nsystem with these middlewares. However we suggest using bunyan with our\nserializers to help parse and log events and responses as JSON. Shown\nbelow is an example using the default console object.\n\n```javascript\nconst middy = require('middy');\nconst { httpErrorHandler } = require('@seedrs/middyjs-middleware');\n\nconst handler = middy((event, context, cb) => {\n  //Some business logic\n})\n.use(httpErrorHandler(console));\n```\n\n## Contribute\n\nTo contribute to the project, please read the [guide](CONTRIBUTING.md).\n","readmeFilename":"README.md"}