{"_id":"@asanovr/nestjs-webhooks","name":"@asanovr/nestjs-webhooks","dist-tags":{"latest":"0.3.0"},"versions":{"0.3.0":{"name":"@asanovr/nestjs-webhooks","version":"0.3.0","description":"Badass utilities for integrating webhooks and NestJS","author":{"name":"Jesse Carter","email":"jesse.r.carter@gmail.com"},"homepage":"https://github.com/golevelup/nestjs#readme","license":"MIT","keywords":["NestJS","typescript","webhook","github","stripe","slack"],"main":"lib/index.js","typings":"lib/index.d.ts","directories":{"lib":"lib","test":"__tests__"},"repository":{"type":"git","url":"git+https://github.com/asanovr/nestjs.git"},"scripts":{"build":"tsc --build tsconfig.build.json","build:watch":"tsc --build tsconfig.build.json --watch","test":"jest"},"bugs":{"url":"https://github.com/golevelup/nestjs/issues"},"publishConfig":{"access":"public"},"dependencies":{"@golevelup/nestjs-common":"^2.0.1","@golevelup/nestjs-modules":"^0.7.1"},"peerDependencies":{"body-parser":"^1.19.0"},"jest":{"moduleFileExtensions":["js","json","ts"],"rootDir":"src","testRegex":".spec.ts$","transform":{"^.+\\.ts$":"ts-jest"},"coverageDirectory":"../coverage","testEnvironment":"node"},"gitHead":"83abc8861cf5f8df94b8cd39964f41ce728aff6d","_id":"@asanovr/nestjs-webhooks@0.3.0","_nodeVersion":"16.15.1","_npmVersion":"lerna/3.22.1/node@v16.15.1+arm64 (darwin)","dist":{"integrity":"sha512-0/MLEuL5CqvpAb00Ls6zPk0ij3cGw378q9j7/WTOFKuUUw8By/oh3T+VsX9FqopwBUfPQl6O2ZmbqLzS0PKF7Q==","shasum":"d8629c3e82d6cc40976ca05b2f320bf26d86c23d","tarball":"https://registry.npmjs.org/@asanovr/nestjs-webhooks/-/nestjs-webhooks-0.3.0.tgz","fileCount":32,"unpackedSize":29185,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFXzVqShw83sbj5HZiptrDNSqN/fsWffvHcASMcrgRzMAiEApIfyJY5sIDjHU6mdZJ8iefJsHYXaJknKg2OhzJl4p50="}]},"_npmUser":{"name":"asanovr","email":"bioforge91@gmail.com"},"maintainers":[{"name":"asanovr","email":"bioforge91@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-webhooks_0.3.0_1693545916294_0.33888856796224975"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-01T05:25:16.166Z","0.3.0":"2023-09-01T05:25:16.538Z","modified":"2023-09-01T05:25:16.818Z"},"maintainers":[{"name":"asanovr","email":"bioforge91@gmail.com"}],"description":"Badass utilities for integrating webhooks and NestJS","homepage":"https://github.com/golevelup/nestjs#readme","keywords":["NestJS","typescript","webhook","github","stripe","slack"],"repository":{"type":"git","url":"git+https://github.com/asanovr/nestjs.git"},"author":{"name":"Jesse Carter","email":"jesse.r.carter@gmail.com"},"bugs":{"url":"https://github.com/golevelup/nestjs/issues"},"license":"MIT","readme":"# @golevelup/nestjs-webhooks\n\n<p align=\"center\">\n<a href=\"https://www.npmjs.com/package/@golevelup/nestjs-webhooks\"><img src=\"https://img.shields.io/npm/v/@golevelup/nestjs-webhooks.svg?style=flat\" alt=\"version\" /></a>\n<a href=\"https://www.npmjs.com/package/@golevelup/nestjs-webhooks\"><img alt=\"downloads\" src=\"https://img.shields.io/npm/dt/@golevelup/nestjs-webhooks.svg?style=flat\"></a>\n<img alt=\"license\" src=\"https://img.shields.io/npm/l/@golevelup/nestjs-webhooks.svg\">\n</p>\n\n## Motivation\n\nMake it easier to build NestJS applications that consume webhooks from third party services\n\n## Features\n\n- ✅ Simple utilities and middleware for enabling a request's raw body to be unmodified on specified routes\n- ✅ Control raw body parsing so that you can copy the raw body onto a new configurable property on the Request object\n- ✅ Provide a reusable foundation for building more specific webhook integrations\n\n### Install\n\n`npm install ---save @golevelup/nestjs-webhooks`\n\nor\n\n`yarn add @golevelup/nestjs-webhooks`\n\n## Techniques\n\n### Simple Raw Body Parsing\n\nMany third party webhook providing services require that the raw body be available on the request in order for it to be validated. However, a NestJS app in it's default state automatically includes JSON parsing middleware which will modify the req.body property.\n\nThe most basic use case is keeping JSON parsing on all routes except for the ones you specifically want to exclude such that the request body property remains unchanged.\n\n#### Step 1: Disable global raw body parsing\n\nIn your bootstrap function (normally in `main.ts`), disable body parsing. Don't worry! We'll bring it back to the other routes later.\n\n```typescript\nconst app = await NestFactory.create(AppModule, {\n  bodyParser: false,\n});\n```\n\n#### Step 2: Configure Middleware Routes\n\nIf your AppModule doesn't already, implement the `NestModule` interface from `@nestjs/common`. This will allow you to [apply middleware to specific routes](https://docs.nestjs.com/middleware#applying-middleware).\n\nWe provide a utility function to simplify configuration using the already imported middlewares. This will automatically configure your app to apply raw body parsing to the routes you specify and then to automatically apply JSON body parsing to all other routes with the exclusion of the raw routes.\n\n```typescript\nimport { applyRawBodyOnlyTo } from '@golevelup/nestjs-webhooks';\n\nclass AppModule implements NestModule {\n  configure(consumer: MiddlewareConsumer) {\n    applyRawBodyOnlyTo(consumer, {\n      method: RequestMethod.ALL,\n      path: 'webhook',\n    });\n  }\n}\n```\n\n## Contribute\n\nContributions welcome! Read the [contribution guidelines](../../CONTRIBUTING.md) first.\n\n## License\n\n[MIT License](../../LICENSE)\n","readmeFilename":"README.md"}