{"_id":"@cobraz/nestjs-unleash","_rev":"5-e3aa613c9fe929ea1e373f7b2e42c00b","name":"@cobraz/nestjs-unleash","dist-tags":{"latest":"0.0.2-beta"},"versions":{"0.0.1-beta":{"name":"@cobraz/nestjs-unleash","version":"0.0.1-beta","description":"Unleash integration for NestJS","author":{"name":"Philipp Busse"},"main":"dist/src/index.js","types":"dist/src/index.d.ts","publishConfig":{"access":"public"},"bugs":{"url":"https://github.com/pmb0/nestjs-unleash/issues"},"homepage":"https://github.com/pmb0/nestjs-unleash#readme","repository":{"type":"git","url":"git+https://github.com/pmb0/nestjs-unleash.git"},"husky":{"hooks":{"pre-commit":"lint-staged","commit-msg":"commitlint -E HUSKY_GIT_PARAMS"}},"license":"MIT","scripts":{"prebuild":"rimraf dist","build":"tsc -p tsconfig.build.json","format":"prettier --write \"src/**/*.ts\" \"test/**/*.ts\"","start:dev":"nodemon  --exec ts-node --files e2e/src/main.ts","lint":"eslint --cache .","_postinstall":"is-ci || husky install","prepublish":"pinst --disable","postpublish":"pinst --enable","test":"jest","test:watch":"jest --watch","test:cov":"jest --coverage","test:debug":"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand","test:e2e":"jest --config ./e2e/jest-e2e.json"},"engines":{"node":">= 12.0.0"},"dependencies":{"ip":"^1.1.5","murmurhash3js":"^3.0.1"},"peerDependencies":{"@nestjs/common":"^7.0.0","@nestjs/core":"^7.0.0","@nestjs/schedule":"^0.4.1","axios":"^0.21.0","reflect-metadata":"^0.1.2"},"devDependencies":{"@commitlint/cli":"^12.0.0","@commitlint/config-conventional":"^12.0.0","@heise/eslint-config":"^17.0.0","@nestjs/cli":"^7.0.0","@nestjs/common":"^7.0.0","@nestjs/config":"^0.6.1","@nestjs/core":"^7.0.0","@nestjs/platform-express":"^7.5.5","@nestjs/schedule":"^0.4.1","@nestjs/schematics":"^7.0.0","@nestjs/testing":"^7.5.5","@semantic-release/changelog":"^5.0.1","@semantic-release/commit-analyzer":"^8.0.1","@semantic-release/git":"^9.0.0","@semantic-release/npm":"^7.0.6","@semantic-release/release-notes-generator":"^9.0.1","@types/cron":"^1.7.2","@types/express":"^4.17.9","@types/ip":"^1.1.0","@types/jest":"26.0.23","@types/murmurhash3js":"^3.0.2","@types/node":"^14.14.10","@types/supertest":"^2.0.10","@unleash/client-specification":"^4.0.0","axios":"^0.21.0","express":"^4.17.1","husky":"^6.0.0","is-ci":"^3.0.0","jest":"^26.6.3","lint-staged":"^11.0.0","mockdate":"^3.0.2","pinst":"^2.1.1","reflect-metadata":"^0.1.12","rimraf":"^3.0.2","rxjs":"^6.6.3","semantic-release":"^17.3.0","ts-jest":"26.5.6","ts-loader":"^9.0.0","ts-node":"^10.0.0","tsconfig-paths":"^3.9.0","typescript":"^4.1.2"},"jest":{"moduleFileExtensions":["js","json","ts"],"coveragePathIgnorePatterns":["node_modules",".module.ts","testing"],"rootDir":"src","testRegex":".spec.ts$","transform":{"^.+\\.(t|j)s$":"ts-jest"},"coverageDirectory":"../coverage","testEnvironment":"node"},"licenseText":"MIT License\n\nCopyright (c) 2020 pmb0\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@cobraz/nestjs-unleash@0.0.1-beta","dist":{"shasum":"ba0ce0dbf8760846922497b105c9e6b1ba5b76b5","integrity":"sha512-sGzrIYON6WY2YwSNRZHDx/BDCYBPBpXYjLgAbh0HjnrPg9IgKHKKJxjA8dml3V4BvKgZp7/O4jYQaVJaSctrJg==","tarball":"https://registry.npmjs.org/@cobraz/nestjs-unleash/-/nestjs-unleash-0.0.1-beta.tgz","fileCount":166,"unpackedSize":205524,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg14VfCRA9TVsSAnZWagAAAzwP/1hFew8goE7PAlYZYZwZ\nKFtz7jzMmqL4cHtPz8M1Q602WO0fVXcoYwBtyiSgbgN1rFC3AypNsin4Xgs6\nMZnE2FoZsdYgM7YbPO48eAud8mWNuYi1cy+F1TrF9bBrpLeKzLYGSNTmo8zV\nA91O9jxyDJOA414xiCjaXDAi/1d/u7m3cQ7RYS0who3MP/uGrI7DpUKD7ujm\nboszEyV+93ju0vkQGTi7Tl0jNFP+1qyJ59Vn9qMb3JRxepN29NJq9V6fIIxq\n80CZKWXZVUvlzFgthnWLB1o/+rPPZ8zyMItw8IwIGL4FOSOV9B4nL4kl9i1/\nuakh5uL5fWEcheXyND1JFQzPYBBVoezn1YZE+G3EJbs4bHBCr1gS/CtffoYm\n5I5K108AeYYctkA08YKnURW74GLOm9erdFEKfd8xDW2JyA49QBZHoSgvugMd\nt/XZeZqOUFjdo3f22vdCTpoaA9KpcnM3XxbVWF4g8zy25rgInDIu0NO/t6g5\nb2qyFvMMtFo07A/NLuL0Lq90YWtzvyHMxL4KHgtKB3gIxyMuwqGnpvyn86vG\nwjC8Dw9RhmhuA8oPVSvCZV7l3HyE66aUOIc91O6FehxK5aD2GWyFji4CF4IP\naRwEfrPxjnzC83VAJEj1IEXevwRBmmf9558+iLBuhNet2UWhF+79E3rspZEN\nQi41\r\n=P2Q9\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCCqy6Rz6ywULH+V34OQGcI3JK9710zyZ+8/Py9v2WCfAIgFE2kk+S08drZp4ELtk8FZsDi4CREkaoiDo7TiNzJX7w="}]},"_npmUser":{"name":"cobraz","email":"so@bjerk.io"},"directories":{},"maintainers":[{"name":"cobraz","email":"so@bjerk.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-unleash_0.0.1-beta_1624737119355_0.7951202306439331"},"_hasShrinkwrap":false},"0.0.2-beta":{"name":"@cobraz/nestjs-unleash","version":"0.0.2-beta","description":"Unleash integration for NestJS","author":{"name":"Philipp Busse"},"main":"dist/src/index.js","types":"dist/src/index.d.ts","publishConfig":{"access":"public"},"bugs":{"url":"https://github.com/pmb0/nestjs-unleash/issues"},"homepage":"https://github.com/pmb0/nestjs-unleash#readme","repository":{"type":"git","url":"git+https://github.com/pmb0/nestjs-unleash.git"},"husky":{"hooks":{"pre-commit":"lint-staged","commit-msg":"commitlint -E HUSKY_GIT_PARAMS"}},"license":"MIT","scripts":{"prebuild":"rimraf dist","build":"tsc -p tsconfig.build.json","format":"prettier --write \"src/**/*.ts\" \"test/**/*.ts\"","start:dev":"nodemon  --exec ts-node --files e2e/src/main.ts","lint":"eslint --cache .","postinstall":"is-ci || husky install","prepublish":"pinst --disable","postpublish":"pinst --enable","test":"jest","test:watch":"jest --watch","test:cov":"jest --coverage","test:debug":"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand","test:e2e":"jest --config ./e2e/jest-e2e.json"},"engines":{"node":">= 12.0.0"},"dependencies":{"ip":"^1.1.5","murmurhash3js":"^3.0.1"},"peerDependencies":{"@nestjs/common":"^7.0.0","@nestjs/core":"^7.0.0","@nestjs/schedule":"^0.4.1","axios":"^0.21.0","reflect-metadata":"^0.1.2"},"devDependencies":{"@commitlint/cli":"^12.0.0","@commitlint/config-conventional":"^12.0.0","@heise/eslint-config":"^17.0.0","@nestjs/cli":"^7.0.0","@nestjs/common":"^7.0.0","@nestjs/config":"^0.6.1","@nestjs/core":"^7.0.0","@nestjs/platform-express":"^7.5.5","@nestjs/schedule":"^0.4.1","@nestjs/schematics":"^7.0.0","@nestjs/testing":"^7.5.5","@semantic-release/changelog":"^5.0.1","@semantic-release/commit-analyzer":"^8.0.1","@semantic-release/git":"^9.0.0","@semantic-release/npm":"^7.0.6","@semantic-release/release-notes-generator":"^9.0.1","@types/cron":"^1.7.2","@types/express":"^4.17.9","@types/ip":"^1.1.0","@types/jest":"26.0.23","@types/murmurhash3js":"^3.0.2","@types/node":"^14.14.10","@types/supertest":"^2.0.10","@unleash/client-specification":"^4.0.0","axios":"^0.21.0","express":"^4.17.1","husky":"^6.0.0","is-ci":"^3.0.0","jest":"^26.6.3","lint-staged":"^11.0.0","mockdate":"^3.0.2","pinst":"^2.1.1","reflect-metadata":"^0.1.12","rimraf":"^3.0.2","rxjs":"^6.6.3","semantic-release":"^17.3.0","ts-jest":"26.5.6","ts-loader":"^9.0.0","ts-node":"^10.0.0","tsconfig-paths":"^3.9.0","typescript":"^4.1.2"},"jest":{"moduleFileExtensions":["js","json","ts"],"coveragePathIgnorePatterns":["node_modules",".module.ts","testing"],"rootDir":"src","testRegex":".spec.ts$","transform":{"^.+\\.(t|j)s$":"ts-jest"},"coverageDirectory":"../coverage","testEnvironment":"node"},"licenseText":"MIT License\n\nCopyright (c) 2020 pmb0\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@cobraz/nestjs-unleash@0.0.2-beta","dist":{"shasum":"99287a739f10caa201f2108c19a1490f1932ba6d","integrity":"sha512-SbNCP+3yiZqFTD5spkPZkOD5prpYyQube6FUfFGfo/OGzZR8reu8+lKEqyUi4TRWIdmK2G6pxPRmFbW3Dc1LVA==","tarball":"https://registry.npmjs.org/@cobraz/nestjs-unleash/-/nestjs-unleash-0.0.2-beta.tgz","fileCount":166,"unpackedSize":205716,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg14jpCRA9TVsSAnZWagAAZDsP/j+aoy6UxH/8d/BZLNnT\n4cZk7fktGMoSyOrY/9PfJtdoFun3xj0q44rdir26r965OTSV4OuTDd/6tLI4\nZ8RqzMFl1k2SSrNRRgos54/9B5exoa9MkosDTTdEA5wmOO/TbWGThYBZupSm\ndIhcFQyJi1DMncCwRWaNu7XuifG6VZ8wZOKMAB1Z7Zd5S87soM0gaK1YZENR\nWPrJuc/dp/BYue9V4rZhiXQQ9V35f4r/ceL2nMRogqu0Vl0GYB5mYOWQSWml\nWHVD5WBaK4x8DKrzOGIDvW5Um7MyvIjKZ77jqf8u4Z6wn34n4i58GfjVBl5g\nEZSmjzJVzZdUUSo+3PAoSHcY9Ey1xz2qhECoETDE3dyZ6frydOi5q09KU17F\nzTiE4criYhq1KQR30GgIwdPyELnJALqx3V1sPEaHbBcZUn8on2diGehYgPUb\ncGGHQDJvDFySOJAatU0x4LfESAsaN9eIV1GnIKcPenuLLztxj6oKufyXoXiK\n11hB6i9N4JE1x+GV4E1izqLBqGt4dzqW12RJsEVv40o/S6mue3oeqfHD3Urq\nO/pBNB5Zv9muwVkgIWOtyOapN21t9oFD9exG77cT0jDqqEcqrGAkojqyksyO\ndUziBRA1FnZVET4cUX9Dx5NOnT2WNIgpGhKEL6iy1cr/uOYMyqy+xyBvNxGu\n4vos\r\n=/Sic\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAUYSGnlKtepESgNTYe9fXSMU7DNTguSugzlnptK0PUEAiEAiOG45bA4c1K5Sxarl36xYteApQzOhbJsqvB0/TAMIjo="}]},"_npmUser":{"name":"cobraz","email":"so@bjerk.io"},"directories":{},"maintainers":[{"name":"cobraz","email":"so@bjerk.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-unleash_0.0.2-beta_1624738025417_0.7110353550804689"},"_hasShrinkwrap":false}},"time":{"created":"2021-06-26T19:51:59.304Z","0.0.1-beta":"2021-06-26T19:51:59.524Z","modified":"2023-04-19T11:20:23.815Z","0.0.2-beta":"2021-06-26T20:07:05.533Z"},"maintainers":[{"email":"hello@simenandre.no","name":"simenandre"}],"description":"Unleash integration for NestJS","homepage":"https://github.com/pmb0/nestjs-unleash#readme","repository":{"type":"git","url":"git+https://github.com/pmb0/nestjs-unleash.git"},"author":{"name":"Philipp Busse"},"bugs":{"url":"https://github.com/pmb0/nestjs-unleash/issues"},"license":"MIT","readme":"<div align=\"center\">\n  <h1>NestJS-Unleash</h1>\n  <a href=\"https://www.npmjs.com/package/nestjs-unleash\">\n    <img src=\"https://badge.fury.io/js/nestjs-unleash.svg\">\n  </a>\n  <a href=\"https://coveralls.io/r/pmb0/nestjs-unleash?branch=master\">\n    <img src=\"https://img.shields.io/coveralls/pmb0/nestjs-unleash/master.svg\">\n  </a>\n  <a href=\"https://github.com/pmb0/nestjs-unleash/actions?query=workflow%3ATests\">\n    <img src=\"https://github.com/pmb0/nestjs-unleash/workflows/Tests/badge.svg\">\n  </a>\n  <p>\n    <a href=\"https://github.com/Unleash/unleash\">Unleash</a> module for <a href=\"https://nestjs.com/\">NestJS</a>\n  </p>\n</div>\n\n# Table of contents <!-- omit in toc -->\n\n- [Usage](#usage)\n  - [Synchronous configuration](#synchronous-configuration)\n  - [Asynchronous configuration](#asynchronous-configuration)\n  - [Usage in controllers or providers](#usage-in-controllers-or-providers)\n  - [Configuration](#configuration)\n  - [Default strategies](#default-strategies)\n  - [Custom strategies](#custom-strategies)\n- [License](#license)\n\n# Usage\n\n```sh\n$ npm install --save nestjs-unleash\n```\n\nImport the module with `UnleashModule.forRoot(...)` or `UnleashModule.forRootAsync(...)`.\n\n## Synchronous configuration\n\nUse `UnleashModule.forRoot()`. Available ptions are described in the [UnleashModuleOptions interface](#configuration).\n\n```ts\n@Module({\n  imports: [\n    UnleashModule.forRoot({\n      url: \"https://example.com/unleash\",\n      appName: \"my-app-name\",\n      instanceId: \"my-unique-instance\",\n    }),\n  ],\n})\nexport class MyModule {}\n```\n\n## Asynchronous configuration\n\nIf you want to use retrieve you [Unleash options](#configuration) dynamically, use `UnleashModule.forRootAsync()`. Use `useFactory` and `inject` to import your dependencies. Example using the `ConfigService`:\n\n```ts\n@Module({\n  imports: [\n    UnleashModule.forRootAsync({\n      useFactory: (config: ConfigService) => ({\n        url: config.get(\"UNLEASH_URL\"),\n        appName: config.get(\"UNLEASH_APP_NAME\"),\n        instanceId: config.get(\"UNLEASH_INSTANCE_ID\"),\n        refreshInterval: config.get(\"UNLEASH_REFRESH_INTERVAL\"),\n        metricsInterval: config.get(\"UNLEASH_METRICS_INTERVAL\"),\n      }),\n      inject: [ConfigService],\n    }),\n  ],\n})\nexport class MyModule {}\n```\n\n## Usage in controllers or providers\n\nIn your controller use the `UnleashService` or the `@IfEnabled(...)` route decorator:\n\n```ts\nimport { UnleashService } from \"nestjs-unleash\";\n\n@Controller()\n@UseGuards(UserGuard)\nexport class AppController {\n  constructor(private readonly unleash: UnleashService) {}\n\n  @Get(\"/\")\n  index(): string {\n    // the UnleashService can be used in all controllerrs and provideers\n    return this.unleash.isEnabled(\"test\")\n      ? \"feature is active\"\n      : \"feature is not active\";\n  }\n\n  // Throws a NotFoundException if the feature is not enabled\n  @IfEnabled(\"test\")\n  @Get(\"/foo\")\n  getFoo(): string {\n    return \"my foo\";\n  }\n}\n```\n\n## Configuration\n\nNestJS-Unleash can be configured with the following options:\n\n```ts\ninterface UnleashModuleOptions {\n  /**\n   * If \"true\", registers `UnleashModule` as a global module.\n   * See: https://docs.nestjs.com/modules#global-modules\n   *\n   * @default true\n   */\n  global?: boolean;\n\n  /**\n   * URL of your Unleash server\n   *\n   * @example http://unleash.herokuapp.com/api/client\n   */\n  url: string;\n\n  /**\n   * Name of the application seen by unleash-server\n   */\n  appName: string;\n\n  /**\n   * Instance id for this application (typically hostname, podId or similar)\n   */\n  instanceId: string;\n\n  /**\n   * Additional options for the HTTP request to the Unleash server, e.g. custom\n   * HTTP headers\n   */\n  http?: AxiosRequestConfig;\n\n  /**\n   * At which interval, in milliseconds, will this client update its feature\n   * state\n   */\n  refreshInterval?: number;\n\n  /**\n   * At which interval, in milliseconds, will this client send metrics\n   */\n  metricsInterval?: number;\n\n  /**\n   * Array of custom strategies. These classes mus implement the `UnleashStrategy` interface.\n   */\n  strategies?: Type<UnleashStrategy>[];\n\n  /**\n   * `nestjs-unleash` sends an initial registration request to the unleash server at startup. This behavior can be disabled by this option.\n   */\n  disableRegistration?: boolean;\n\n  /**\n   * Some strategies depend on the user ID of the currently logged in user. The\n   * user ID is expected by default in `request.user.id`. To customize this\n   * behavior, a custom user ID factory can be provided.\n   */\n  userIdFactory?: (request: Request<{ id: string }>) => string;\n}\n```\n\n## Default strategies\n\nThis module supports the [official standard activation strategies](https://docs.getunleash.io/docs/user_guide/activation_strategy). They do not need to be activated separately and work out of the box.\n\n## Custom strategies\n\nIn order to create a custom strategy you have to create a class wich inplements the `UnleashStrategy` interface:\n\n```ts\nimport { UnleashContext } from \"nestjs-unleash\";\n\nexport interface UnleashStrategy {\n  /**\n   * Must match the name you used to create the strategy in your Unleash\n   * server UI\n   */\n  name: string;\n\n  /**\n   * Determines whether the feature toggle is active\n   *\n   * @param parameters Custom paramemters as configured in Unleash server UI\n   * @param context applicaton/request context, i.e. UserID\n   */\n  isEnabled(parameters: unknown, context: UnleashContext): boolean;\n}\n```\n\nExample custom strategy:\n\n```ts\nimport { Injectable } from \"@nestjs/common\";\nimport { UnleashContext, UnleashStrategy } from \"nestjs-unleash\";\n\n@Injectable()\nexport class MyCustomStrategy implements UnleashStrategy {\n  name = \"MyCustomStrategy\";\n\n  isEnabled(parameters: any, context: UnleashContext): boolean {\n    return Math.random() < 0.5;\n  }\n}\n```\n\nNow you can use it your module setup as follows:\n\n```ts\nimport { MyCustomStrategy } from \"./my-custom-strategy\";\n\n@Module({\n  imports: [\n    UnleashModule.forRoot({\n      // ...\n      strategies: [MyCustomStrategy],\n    }),\n  ],\n})\nexport class ApplicationModule {}\n```\n\n# License\n\nnestjs-unleash is distributed under the MIT license. [See LICENSE](./LICENSE) for details.\n","readmeFilename":"README.md"}