{"id":22308841,"url":"https://github.com/pay-k/nestjs-response-utils","last_synced_at":"2025-07-29T06:31:08.077Z","repository":{"id":36257263,"uuid":"222254506","full_name":"pay-k/nestjs-response-utils","owner":"pay-k","description":null,"archived":false,"fork":false,"pushed_at":"2022-04-29T02:26:41.000Z","size":125,"stargazers_count":4,"open_issues_count":4,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-05T03:41:07.545Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pay-k.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-17T13:45:29.000Z","updated_at":"2024-03-18T20:44:25.000Z","dependencies_parsed_at":"2022-08-08T13:47:31.183Z","dependency_job_id":null,"html_url":"https://github.com/pay-k/nestjs-response-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pay-k/nestjs-response-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pay-k%2Fnestjs-response-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pay-k%2Fnestjs-response-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pay-k%2Fnestjs-response-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pay-k%2Fnestjs-response-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pay-k","download_url":"https://codeload.github.com/pay-k/nestjs-response-utils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pay-k%2Fnestjs-response-utils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267639569,"owners_count":24119780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T20:15:36.810Z","updated_at":"2025-07-29T06:31:07.782Z","avatar_url":"https://github.com/pay-k.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n@payk/nestjs-response-utils\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com\"\u003e\u003cimg src=\"https://nestjs.com/img/logo_text.svg\" width=\"320\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  Response (\u0026 Request) utils for \u003ca href=\"https://github.com/nestjs/nest\"\u003eNestJS\u003c/a\u003e\n  \u003cbr /\u003e\u003cbr /\u003e\n\n  [![Build Status](https://dev.azure.com/payk/PayK%20Public/_apis/build/status/pay-k.nestjs-response-utils?branchName=master)](https://dev.azure.com/payk/PayK%20Public/_build/latest?definitionId=12\u0026branchName=master)\n\n## Installation\n```\nnpm install @payk/nestjs-response-utils\n```\n\n\n## What does it do?\n\n## Quick Start\nAdd a decorator on top of your method or controller\n```ts\n@UseInterceptors(new LoggingInterceptor(), new TransformResponseInterceptor(ResponseKYCDto))\n```\n\nThe `LogginInterceptor` can also be added globally according to NestJS documentation.\n\nThe `TransformResponseInterceptor` accepts in his ctor the object it's supposed to transform and also a mapping function if the properties are named differently.\n\u003caside class=\"warning\"\u003e\nIt's important to always put the logging interceptor first, as he needs to be the first to run and last to catch errors.\n\u003c/aside\u003e\n\n## Why \u0026 How\nOur operation mode is that Dto goes into the controller and then into the service. And the service works with Models (DB Models mainly). The service then returns to the controller the Model and the controller transforms it into a Response DTO. To remove the boilerplate, the service should use a MetaResponse object and the controller the TransformResponseInterceptor that will do the transformation of the MetaResponse\u003cModel\u003e into the ResponseDTO.\n\nThe Service gets a RequestDTO and returns a `MetaRespone\u003cModel\u003e` created by the `MetaResponseGenerator` to the controller.\n\n### MetaResponse\nDo create a MetaResponse we have a MetaResponseGenerator class.\n```ts\n// Return an object (Model) and the require ResponseCode (HttpResponse normally)\nMetaResponseGenerator.generateByResponseCode(\n    dbModel,\n    ResponseCodes.OK,\n  );\n\n// Return an Error, no object needed.\nMetaResponseGenerator.generateAnErrorResponse(\n    ResponseCodes.NOT_FOUND,\n  );\n\n// Return an HttpStatus error\nMetaResponseGenerator.generateErrorByStatus(\n  HttpStatus.OK,\n  { error: 'object' }\n)\n```\n\n### ResponseCode\nThe ResponseCode object assists in returning errors mainly. A few come by default in the `ResponseCodes` class. More can be initiated using the `ResponseCode` ctor\n\n## LoggingInterceptor\nThe logging interceptor will log the request and response to the service.\n### Masking Data\nIn order to mask data that shouldn't be logged, the `LoggingInterceptor` supports getting an array in his constructor of property names that should be masked.\n\n```ts\nnew LoggingInterceptors(['propertyName','properyThatShouldBeMasked'])\n```\nAssuming the following Json:\n```ts\n{\n  name: 'Dan',\n  test: 'ing',\n  propertyName: 'I'll be masked',\n  inner: {\n    here: 'there',\n    properyThatShouldBeMasked: 123,\n    propertyName: 1111999\n  }\n}\n```\n\nWill result in the following:\n```ts\n{\n  name: 'Dan',\n  test: 'ing',\n  propertyName: '--REDACTED--',\n  inner: {\n    here: 'there',\n    properyThatShouldBeMasked: '--REDACTED--',\n    propertyName: '--REDACTED--'\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpay-k%2Fnestjs-response-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpay-k%2Fnestjs-response-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpay-k%2Fnestjs-response-utils/lists"}