{"_id":"@composable-software/commercetools-pino-middleware","_rev":"1-197b45653eb50c567e4552b0706d1189","name":"@composable-software/commercetools-pino-middleware","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@composable-software/commercetools-pino-middleware","version":"1.0.0","description":"Pino logger for commercetools SDK","main":"dist/index.js","license":"MIT","scripts":{"prebuild":"rimraf dist","prepack":"yarn build","build":"tsc","release":"release-it","lint":"eslint \"{src,tests}/**/*.ts\" --fix","test":"jest --coverage"},"keywords":["commercetools","pino","middleware","logger"],"homepage":"https://github.com/composable-software/commercetools-pino-middleware","bugs":{"url":"https://github.com/composable-software/commercetools-pino-middleware/issues"},"devDependencies":{"@commercetools/sdk-client-v2":"^2.2.0","@types/jest":"^27.0.2","@types/node":"^16.10.2","@typescript-eslint/eslint-plugin":"^4.31.2","@typescript-eslint/parser":"^4.31.2","eslint":"^7.32.0","eslint-config-standard":"^16.0.3","eslint-plugin-import":"^2.24.2","eslint-plugin-jest":"^24.4.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^5.1.0","jest":"^27.2.4","pino":"^8.14.1","rambda":"^8.2.0","rimraf":"^3.0.2","ts-jest":"^27.0.5","type-fest":"^4.0.0","typescript":"^4.4.3"},"jest":{"moduleFileExtensions":["js","json","ts"],"testRegex":"(/tests/(.*))\\.test.ts$","transform":{"^.+\\.(t|j)s$":"ts-jest"},"collectCoverageFrom":["src/*.ts","src/**/*.ts"],"coverageDirectory":"../coverage","testEnvironment":"node"},"peerDependencies":{"pino":"^8.14.1"},"types":"./dist/index.d.ts","gitHead":"1a4fcd63595f046a6930438cb852335c67f9d5a1","_id":"@composable-software/commercetools-pino-middleware@1.0.0","_nodeVersion":"18.17.0","_npmVersion":"9.6.7","dist":{"integrity":"sha512-yMgRtq5uvH1atBe3vYaq6mpK6O1lfbJUAJqX/BJhPb2yMh/ctsOwybYhN86zQx/2IRpSXCItdgwhyeJ1B1+4ZA==","shasum":"bf660a97d508c19f63476fb827e062438cc6336c","tarball":"https://registry.npmjs.org/@composable-software/commercetools-pino-middleware/-/commercetools-pino-middleware-1.0.0.tgz","fileCount":11,"unpackedSize":8732,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCEZqBOHqCjUymgF9tiBgMfiEz3ZDXH8N+/SlxPhgbE4wIhAPRAiKHjwGgpBaoobBI74F5Z2foGdE4eWtdSOQtSDEy9"}]},"_npmUser":{"name":"mrdck","email":"mperlakio@outlook.com"},"directories":{},"maintainers":[{"name":"mrdck","email":"mperlakio@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/commercetools-pino-middleware_1.0.0_1690388173139_0.6758237691402553"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-26T16:16:13.027Z","1.0.0":"2023-07-26T16:16:13.307Z","modified":"2023-07-26T20:11:53.009Z"},"maintainers":[{"email":"illyahvost@gmail.com","name":"ikhvost"},{"email":"mperlakio@outlook.com","name":"mrdck"}],"description":"Pino logger for commercetools SDK","homepage":"https://github.com/composable-software/commercetools-pino-middleware","keywords":["commercetools","pino","middleware","logger"],"bugs":{"url":"https://github.com/composable-software/commercetools-pino-middleware/issues"},"license":"MIT","readme":"# commercetools-pino-middleware\n\n![npm](https://img.shields.io/npm/v/@composable-commerce/commercetools-pino-middleware?color=blue) ![npm](https://img.shields.io/npm/l/@composable-commerce/commercetools-pino-middleware)\n\n## Overview\n\n`commercetools-pino-middleware` is a library that provides a seamless integration of Pino logger with the commercetools SDK. It allows you to easily log SDK requests, responses, and other relevant information with Pino, a fast and minimalist Node.js logger. The middleware is designed to be flexible and can be set up with either an auto-generated Pino instance or a custom Pino logger with specific configurations.\n\n## Installation\n\nYou can install the library via npm:\n\n```bash\nnpm install @composable-software/commercetools-pino-middleware\n```\nor with yarn\n```bash\nyarn add @composable-software/commercetools-pino-middleware\n```\n\n## Usage\n\n### 1. Using Auto-generated Pino Instance\n\nIf you prefer a hassle-free setup, you can let the middleware create and configure the Pino instance for you. Simply pass an empty object when setting up the middleware:\n\n```javascript\nimport { createPinoMiddleware } from '@composable-software/commercetools-pino-middleware';\nimport { ClientBuilder } from '@commercetools/sdk-client-v2';\n\n/**\n * Middleware with automatic Pino factory\n */\nconst client = new ClientBuilder()\n  .withMiddleware(createPinoMiddleware({}))\n  .build();\n```\n\nIn this method, the middleware will handle the instantiation and configuration of the Pino logger automatically.\n\n### 2. Using a Custom Pino Instance\n\nIf you need a more customized Pino logger, you can pass your own Pino instance through options:\n\n```javascript\nimport pino from 'pino';\nimport { createPinoMiddleware } from '@composable-software/commercetools-pino-middleware';\nimport { ClientBuilder } from '@commercetools/sdk-client-v2';\n\n/**\n * Custom Pino logger instance that can be passed to the middleware\n */\nconst logger = pino({\n  name: 'custom-logger',\n  level: 'info',\n});\n\nconst options = {\n  logger: logger,\n};\n\nconst client = new ClientBuilder()\n  .withMiddleware(createPinoMiddleware(options))\n  .build();\n```\n\nIn this case, the middleware will use the provided Pino instance to log the information, allowing you to have full control over the logger's configuration.\n\n## Logging Details\n\nThe `commercetools-pino-middleware` logs essential details related to SDK requests and responses, including:\n\n- Request method and URL\n- Request headers\n- Request body (if applicable)\n- Response status code\n- Response headers\n- Response body (if applicable)\n\nAll logs are output in a structured JSON format, which makes it easy to parse and analyze the logged data.\n\n## Examples\n\nHere are some examples of how the middleware logs different scenarios:\n\n- **Successful Request:**\n\n```json\n{\"level\":\"info\",\"time\":1678376443924,\"msg\":\"Request sent\",\"method\":\"POST\",\"url\":\"https://api.commercetools.com/products\",\"headers\":{\"Authorization\":\"Bearer <access_token>\",\"Content-Type\":\"application/json\"},\"body\":{\"typeId\":\"product\",\"id\":\"abc123\",\"version\":5}}\n{\"level\":\"info\",\"time\":1678376453920,\"msg\":\"Response received\",\"status\":201,\"headers\":{\"x-request-id\":\"abc123\",\"content-type\":\"application/json\"},\"body\":{\"id\":\"abc123\",\"version\":5}}\n```\n\n- **Failed Request:**\n\n```json\n{\"level\":\"error\",\"time\":1678376463922,\"msg\":\"Request failed\",\"method\":\"GET\",\"url\":\"https://api.commercetools.com/products/xyz789\",\"headers\":{\"Authorization\":\"Bearer <access_token>\"}}\n{\"level\":\"error\",\"time\":1678376473923,\"msg\":\"Response received with error\",\"status\":404,\"headers\":{\"x-request-id\":\"xyz789\"},\"body\":{\"statusCode\":404,\"message\":\"Not Found\"}}\n```\n\n## Contributing\n\nWe welcome contributions from the community! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on our [GitHub repository](https://github.com/your-github-account/commercetools-pino-middleware).\n\n## License\n\nThis library is licensed under the [MIT License](https://opensource.org/licenses/MIT). See the [LICENSE](./LICENSE) file for more details.","readmeFilename":"README.md"}