{"_id":"kansas-express","_rev":"28-bee58b843a1d981e619d8dd549a0340c","name":"kansas-express","description":"Kansas API usage limiter Middleware for Connect.","dist-tags":{"latest":"0.2.4"},"versions":{"0.0.1":{"name":"kansas-express","version":"0.0.1","main":"./","description":"Kansas API usage limiter Middleware for Connect.","homepage":"https://github.com/thanpolas/kansas-express","bugs":{"url":"https://github.com/thanpolas/kansas-express/issues"},"author":{"name":"Thanasis Polychronakis","email":"thanpolas@gmail.com","url":"https://github.com/thanpolas"},"repository":{"type":"git","url":"https://github.com/thanpolas/kansas-express"},"licenses":[{"type":"MIT"}],"scripts":{"test":"./node_modules/.bin/mocha -b test/spec -u bdd  -R spec"},"peerDependencies":{"kansas":"~0.1.7"},"dependencies":{"logg":"~0.2.2","cip":"~0.2.1","middlewarify":"~0.3.7","bluebird":"~1.0.8","lodash":"~2.4.1","grunt-release":"~0.7.0"},"devDependencies":{"kansas":"~0.1.7","load-grunt-tasks":"~0.4.0","mocha":"~1.17.1","grunt-mocha-test":"~0.9.4","supertest":"~0.9.0","grunt":"~0.4.2","chai":"~1.9.0","sinon":"~1.8.2","express":"~3.4.8"},"_id":"kansas-express@0.0.1","dist":{"shasum":"31af39cd0c0de730aa3e7e24c2f2db26a70b6a11","tarball":"https://registry.npmjs.org/kansas-express/-/kansas-express-0.0.1.tgz","integrity":"sha512-vTI+1+k8D29vcE+ESvbCYobTWt4ssmk37AQjQqtil/III2VikBajvSdoZXkf7aZOuBCoo6+HM+SMDhmt2UByrA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCqYguHFao4L6y8sit0NlajdMpdeOI8//YlKM2QpoY2QQIhALQOmI5xnBnUUyzwGB/dtZfNknh8UBwanmIb+qMTlymn"}]},"_from":".","_npmVersion":"1.3.14","_npmUser":{"name":"thanpolas","email":"thanpolas@gmail.com"},"maintainers":[{"name":"thanpolas","email":"thanpolas@gmail.com"}]},"0.0.3":{"name":"kansas-express","version":"0.0.3","main":"./","description":"Kansas API usage limiter Middleware for Connect.","homepage":"https://github.com/thanpolas/kansas-express","bugs":{"url":"https://github.com/thanpolas/kansas-express/issues"},"author":{"name":"Thanasis Polychronakis","email":"thanpolas@gmail.com","url":"https://github.com/thanpolas"},"repository":{"type":"git","url":"https://github.com/thanpolas/kansas-express"},"licenses":[{"type":"MIT"}],"scripts":{"test":"./node_modules/.bin/mocha -b test/spec -u bdd  -R spec"},"peerDependencies":{"kansas":"~0.1.8"},"dependencies":{"logg":"~0.2.2","cip":"~0.2.1","middlewarify":"~0.3.7","bluebird":"~1.0.8","lodash":"~2.4.1","grunt-release":"~0.7.0"},"devDependencies":{"kansas":"~0.1.8","load-grunt-tasks":"~0.4.0","mocha":"~1.17.1","grunt-mocha-test":"~0.9.4","supertest":"~0.9.0","grunt":"~0.4.3","chai":"~1.9.0","sinon":"~1.9.0","express":"~3.5.0"},"_id":"kansas-express@0.0.3","dist":{"shasum":"c0a7ac6d14fad761ff9d8bfe82fa464cd749514f","tarball":"https://registry.npmjs.org/kansas-express/-/kansas-express-0.0.3.tgz","integrity":"sha512-mESi/da0G1snFU5/NccPQyOuX8c/hBsY+U+xI+U2tuCbhtgDaUlhTe++LZ536x72lqgZH0UmVNVZj+VLviKeZg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCiO4Lzy7/u/fi/SDgfwg1BNJq9DMV2LtwVeZS3qsSU7gIgZ+LlJAXEdnCF/6koKZxQhvOMXS/BIRVGL1KcoV4f8Pk="}]},"_from":".","_npmVersion":"1.3.14","_npmUser":{"name":"thanpolas","email":"thanpolas@gmail.com"},"maintainers":[{"name":"thanpolas","email":"thanpolas@gmail.com"}]},"0.0.4":{"name":"kansas-express","version":"0.0.4","main":"./","description":"Kansas API usage limiter Middleware for Connect.","homepage":"https://github.com/thanpolas/kansas-express","bugs":{"url":"https://github.com/thanpolas/kansas-express/issues"},"author":{"name":"Thanasis Polychronakis","email":"thanpolas@gmail.com","url":"https://github.com/thanpolas"},"repository":{"type":"git","url":"https://github.com/thanpolas/kansas-express"},"licenses":[{"type":"MIT"}],"scripts":{"test":"./node_modules/.bin/mocha -b test/spec -u bdd  -R spec"},"peerDependencies":{"kansas":"~0.1.9"},"dependencies":{"logg":"~0.2.2","cip":"~0.2.1","middlewarify":"~0.3.7","bluebird":"~1.1.0","lodash":"~2.4.1","grunt-release":"~0.7.0"},"devDependencies":{"kansas":"~0.1.9","load-grunt-tasks":"~0.4.0","mocha":"~1.17.1","grunt-mocha-test":"~0.9.4","supertest":"~0.9.0","grunt":"~0.4.3","chai":"~1.9.0","sinon":"~1.9.0","express":"~3.5.0"},"_id":"kansas-express@0.0.4","dist":{"shasum":"c1745f53998ad6465d723dea47517a8d2e565d54","tarball":"https://registry.npmjs.org/kansas-express/-/kansas-express-0.0.4.tgz","integrity":"sha512-5QoZ8dV9IbbsXzgRHrzXPgJpdP9+HOPKLgeKVils5+hCIyJI/E/g4fk/QcwIFmN0h9mBG7pBMt5lyH3g+hkadA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEmg4Wav4ZJPiLY/xDtdjc9X5lkduM+C3UDm+KuaMwT3AiEAjFowTXhgRTaGUbXLmZgOuBZQIi+R5yOs4XBUISBIxC8="}]},"_from":".","_npmVersion":"1.3.14","_npmUser":{"name":"thanpolas","email":"thanpolas@gmail.com"},"maintainers":[{"name":"thanpolas","email":"thanpolas@gmail.com"}]},"0.0.5":{"name":"kansas-express","version":"0.0.5","main":"./","description":"Kansas API usage limiter Middleware for Connect.","homepage":"https://github.com/thanpolas/kansas-express","bugs":{"url":"https://github.com/thanpolas/kansas-express/issues"},"author":{"name":"Thanasis Polychronakis","email":"thanpolas@gmail.com","url":"https://github.com/thanpolas"},"repository":{"type":"git","url":"https://github.com/thanpolas/kansas-express"},"licenses":[{"type":"MIT"}],"scripts":{"test":"./node_modules/.bin/mocha -b test/spec -u bdd  -R spec"},"peerDependencies":{"kansas":"~0.1.10"},"dependencies":{"logg":"~0.2.2","cip":"~0.2.1","middlewarify":"~0.3.7","bluebird":"~1.1.0","lodash":"~2.4.1","grunt-release":"~0.7.0"},"devDependencies":{"kansas":"~0.1.10","load-grunt-tasks":"~0.4.0","mocha":"~1.17.1","grunt-mocha-test":"~0.9.4","supertest":"~0.9.0","grunt":"~0.4.3","chai":"~1.9.0","sinon":"~1.9.0","express":"~3.5.0"},"_id":"kansas-express@0.0.5","dist":{"shasum":"a277d9bc815785fe2b7401e5c8549dae8a27942a","tarball":"https://registry.npmjs.org/kansas-express/-/kansas-express-0.0.5.tgz","integrity":"sha512-6Uf6HOo4UkBnQcT0vFiw0Cv3NZ8Hd8ig/8jL0KV4sTUHDuc8qd29lClgdeoB5ZLpIOJi4DRtg5Xf42ZlAg+oIQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDpXF01es/H4GngaOQLCntN5GOAk5uVLUsa95H919ziDwIgP4GPjsEnizCd8cqP1FkDJCFgbWc2Aey4U8mLkBdA+5Y="}]},"_from":".","_npmVersion":"1.3.14","_npmUser":{"name":"thanpolas","email":"thanpolas@gmail.com"},"maintainers":[{"name":"thanpolas","email":"thanpolas@gmail.com"}]},"0.2.0":{"name":"kansas-express","version":"0.2.0","main":"./","description":"Kansas API usage limiter Middleware for Connect.","homepage":"https://github.com/thanpolas/kansas-express","bugs":{"url":"https://github.com/thanpolas/kansas-express/issues"},"author":{"name":"Thanasis Polychronakis","email":"thanpolas@gmail.com","url":"https://github.com/thanpolas"},"repository":{"type":"git","url":"https://github.com/thanpolas/kansas-express"},"licenses":[{"type":"MIT"}],"scripts":{"test":"mocha -b test/spec -u bdd  -R spec"},"peerDependencies":{"kansas":"^0.2.2"},"dependencies":{"logg":"~0.3.0","cip":"~0.2.4","middlewarify":"~0.3.7","bluebird":"~1.2.1","lodash":"~2.4.1","grunt-release":"~0.7.0"},"devDependencies":{"kansas":"^0.2.2","load-grunt-tasks":"~0.4.0","mocha":"~1.18.2","grunt-mocha-test":"~0.10.0","supertest":"~0.10.0","grunt":"~0.4.4","chai":"~1.9.1","sinon":"~1.9.1","express":"~3.5.1"},"_id":"kansas-express@0.2.0","dist":{"shasum":"a0426634ee2ef3b4bffc6a8060f1f8b2f51f7f89","tarball":"https://registry.npmjs.org/kansas-express/-/kansas-express-0.2.0.tgz","integrity":"sha512-g9YmiieyOrgo4w9rfavrFmw+A8FEc0NQulE5QqWqA9egyI5fSf3j9VdsA8lw9J4nIXlv91eArrcm6nKR7eW0vQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE0+90Tv7BalUcykmxR3fThxklUIo707eQ4yGyTSrGlGAiA8QTfdFvjk6FONUvrOeH3vY9qm3qEls7M0iJoyZz60Xg=="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"thanpolas","email":"thanpolas@gmail.com"},"maintainers":[{"name":"thanpolas","email":"thanpolas@gmail.com"}]},"0.2.1":{"name":"kansas-express","version":"0.2.1","main":"./","description":"Kansas API usage limiter Middleware for Connect.","homepage":"https://github.com/thanpolas/kansas-express","bugs":{"url":"https://github.com/thanpolas/kansas-express/issues"},"author":{"name":"Thanasis Polychronakis","email":"thanpolas@gmail.com","url":"https://github.com/thanpolas"},"repository":{"type":"git","url":"https://github.com/thanpolas/kansas-express"},"licenses":[{"type":"MIT"}],"scripts":{"test":"mocha -b test/spec -u bdd  -R spec"},"peerDependencies":{"kansas":"^0.2.2"},"dependencies":{"logg":"~0.3.0","cip":"~0.2.4","middlewarify":"~0.3.7","bluebird":"~1.2.1","lodash":"~2.4.1","grunt-release":"~0.7.0"},"devDependencies":{"kansas":"^0.2.2","load-grunt-tasks":"~0.4.0","mocha":"~1.18.2","grunt-mocha-test":"~0.10.0","supertest":"~0.10.0","grunt":"~0.4.4","chai":"~1.9.1","sinon":"~1.9.1","express":"~3.5.1"},"_id":"kansas-express@0.2.1","dist":{"shasum":"9e5f88730c5b6ffeb6fe33c7947512a46f341572","tarball":"https://registry.npmjs.org/kansas-express/-/kansas-express-0.2.1.tgz","integrity":"sha512-sCBFIp+3RS0IzluYb8apjRBUsg90AzCijCNHBDlueI6G9dZqwP5lnehJcAVOZItNfM4JTZGWdJWXPbnKPy3a3w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC1mVOp4A3CPSFI40q0SmyTSXpsaMo9/TlQtdw/QlRF3AiEAzxuYiFQHwSwhSQrap9n1ia8u+9bfg+co7gTDY3wPPT8="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"thanpolas","email":"thanpolas@gmail.com"},"maintainers":[{"name":"thanpolas","email":"thanpolas@gmail.com"}]},"0.2.2":{"name":"kansas-express","version":"0.2.2","main":"./","description":"Kansas API usage limiter Middleware for Connect.","homepage":"https://github.com/thanpolas/kansas-express","bugs":{"url":"https://github.com/thanpolas/kansas-express/issues"},"author":{"name":"Thanasis Polychronakis","email":"thanpolas@gmail.com","url":"https://github.com/thanpolas"},"repository":{"type":"git","url":"https://github.com/thanpolas/kansas-express"},"licenses":[{"type":"MIT"}],"scripts":{"test":"mocha -b test/spec -u bdd  -R spec"},"peerDependencies":{"kansas":"^0.2.4"},"dependencies":{"logg":"~0.3.0","cip":"~0.2.5","middlewarify":"~0.4.0","bluebird":"~2.3.4","lodash":"~2.4.1","grunt-release":"~0.7.0"},"devDependencies":{"kansas":"^0.2.4","load-grunt-tasks":"~0.6.0","mocha":"~1.21.4","grunt-mocha-test":"~0.12.1","supertest":"~0.14.0","grunt":"~0.4.5","chai":"~1.9.2","sinon":"~1.10.3","express":"~4.9.5","body-parser":"^1.9.0"},"_id":"kansas-express@0.2.2","dist":{"shasum":"c78255c77e000b02ffd0a3c91fd1525d7444e79f","tarball":"https://registry.npmjs.org/kansas-express/-/kansas-express-0.2.2.tgz","integrity":"sha512-MKBMe/FIGgcwAgv2n50JoiatSJNsHJdoi28+AkJIFAkRAoC0lfmYtCQv/bWRGnGpVkryFFnns000GEzWmUDmMA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC4DvC8SZxp+SMtnNsDGjd4kWdzGRtzec/nxaEsiqkq8AIhAOcg5mXPVUbMILjiftuNoW9RC/9LqCuMRSQlrL8E+Ky8"}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"thanpolas","email":"thanpolas@gmail.com"},"maintainers":[{"name":"thanpolas","email":"thanpolas@gmail.com"}]},"0.2.3":{"name":"kansas-express","version":"0.2.3","main":"./","description":"Kansas API usage limiter Middleware for Connect.","homepage":"https://github.com/thanpolas/kansas-express","bugs":{"url":"https://github.com/thanpolas/kansas-express/issues"},"author":{"name":"Thanasis Polychronakis","email":"thanpolas@gmail.com","url":"https://github.com/thanpolas"},"repository":{"type":"git","url":"https://github.com/thanpolas/kansas-express"},"licenses":[{"type":"MIT"}],"scripts":{"test":"mocha -b test/spec -u bdd  -R spec"},"peerDependencies":{"kansas":"^0.3.2"},"dependencies":{"logg":"~0.3.0","cip":"~0.2.5","middlewarify":"~0.4.0","bluebird":"~2.3.11","lodash":"~2.4.1"},"devDependencies":{"grunt-release":"~0.7.0","kansas":"^0.3.2","load-grunt-tasks":"~1.0.0","mocha":"~2.0.1","grunt-mocha-test":"~0.12.2","supertest":"~0.15.0","grunt":"~0.4.5","chai":"~1.10.0","sinon":"~1.11.1","express":"~4.10.2","body-parser":"^1.9.2"},"_id":"kansas-express@0.2.3","dist":{"shasum":"d3c18022f3331c27d21dd5ca271e607deaf3e8c0","tarball":"https://registry.npmjs.org/kansas-express/-/kansas-express-0.2.3.tgz","integrity":"sha512-VBlmJGuHB7iDPnxcEUo6VivuUc2hxx4Tp0sAzu6N29luCWdWsqZ7zaB23Wk9Z6+mgnv+ualnUSiUdi/Ds5xqdg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCQCbC4yahYPlQcqBGzbkpvZp2aNBQOFp8hEZc09BatCgIgZsvIcPseOGXbTx6lFGReSdEx+rKHX/YzpniHuL8R2vk="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"thanpolas","email":"thanpolas@gmail.com"},"maintainers":[{"name":"thanpolas","email":"thanpolas@gmail.com"}]},"0.2.4":{"name":"kansas-express","version":"0.2.4","main":"./","description":"Kansas API usage limiter Middleware for Connect.","homepage":"https://github.com/thanpolas/kansas-express","bugs":{"url":"https://github.com/thanpolas/kansas-express/issues"},"author":{"name":"Thanasis Polychronakis","email":"thanpolas@gmail.com","url":"https://github.com/thanpolas"},"repository":{"type":"git","url":"https://github.com/thanpolas/kansas-express"},"licenses":[{"type":"MIT"}],"scripts":{"test":"mocha -b test/spec -u bdd  -R spec"},"peerDependencies":{"kansas":"^0.3.2"},"dependencies":{"logg":"~0.3.0","cip":"~0.2.5","middlewarify":"~0.4.0","bluebird":"~2.3.11","lodash":"~2.4.1"},"devDependencies":{"grunt-release":"~0.7.0","kansas":"^0.3.2","load-grunt-tasks":"~1.0.0","mocha":"~2.0.1","grunt-mocha-test":"~0.12.2","supertest":"~0.15.0","grunt":"~0.4.5","chai":"~1.10.0","sinon":"~1.11.1","express":"~4.10.2","body-parser":"^1.9.2"},"_id":"kansas-express@0.2.4","dist":{"shasum":"0e7ed22f86608476a8507c79ea5d6b91063b49ca","tarball":"https://registry.npmjs.org/kansas-express/-/kansas-express-0.2.4.tgz","integrity":"sha512-eNJgYC1z1T+cNCFpWYjyVcnoWo+mX6VmHNkWmoZrADXP/8zHBiAgwfutvY8GETzt0cVY/U2xfXOnBIGKI4oFiA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC0rpgEx4iNWdIbuOUEMbqDz6stj1o+GG7Y8HmQBk7sSAiEA7Ou9K1sJA59KdBlNp6kR9HJvC+tA4IAhHgOzpXLz1CA="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"thanpolas","email":"thanpolas@gmail.com"},"maintainers":[{"name":"thanpolas","email":"thanpolas@gmail.com"}]}},"readme":"# Kansas Express\n\n[Kansas][] API usage limiter Middleware for [Express][].\n\n[![Build Status](https://secure.travis-ci.org/thanpolas/kansas-express.png?branch=master)](http://travis-ci.org/thanpolas/kansas-express)\n\n## Install\n\nInstall the module with: `npm install kansas-express --save`\n\n## Overview\n\nKansas Express offers the following types of Middleware:\n\n* [Consume](#the-consume-middleware) Limit your API usage based on available units per period.\n* [Count](#the-count-middleware) No limits on API usage, just count.\n* [Manage](#the-manage-middleware) CRUD operations for tokens.\n\n## The Consume Middleware\n\nAdd the consume middleware on every resource you want to apply Rate Usage Limiting. The Consume middleware requires a [Kansas][] instance.\n\n```js\nvar kansas = require('kansas');\nvar kansasConsume = require('kansas-express/consume');\n\n// initialize kansas\nexports.kansas = kansas();\n\n// initialize Consume Middleware\nvar consume = kansasConsume(exports.kansas);\n\n// add to any route\napp.get('/api/clients', consume.use());\napp.get('/api/clients', theAppLogicHandler);\n```\n\nThe Consume Middleware will check that the API Token is properly set in the request Headers. If it exists and it has available units to consume, then the API call will be allowed and the remaining usage units will be propagated on the response Headers.\n\n### Configuring the Consume Middleware\n\nUse the method `setup()` to configure the Consume Middleware, it accepts an Object with any of the following properties\n\n* **consumeUnits** `number` *default*: 1 How many units to consume per request.\n* **headerToken** `string` *default*: 'X-Api-Token' Header key to expect the API token.\n* **headerRemaining** `string` *default*: 'X-RateLimit-Remaining' Header key to populate the response with.\n* **handleError** `Function(res, err)` You can overwrite the default Error handler.\n* **handleSuccess** `Function(res, next, remaining)` You can overwrite the default Success handler.\n* **behindProxy** `boolean` *default*: false Set to true if node is running beind a reverse-proxy configuration like Heroku for e.g, this is used for fetching the correct Client IP when debug logging occurs.\n\n```js\nvar kansasConsume = require('kansas-express/consume');\n\n// create two instances of Consume Middleware\nvar consume = kansasConsume(api);\nvar consumeHeavy = kansasConsume(api);\n\n// The heavy API call will consume 5 units\nconsumeHeavy.setup({\n    consumeUnits: 5,\n});\n\n// add route for paginated clients\napp.get('/api/clients', consume.use());\napp.get('/api/clients', theAppLogicHandler);\n\n// add route for all clients\napp.get('/api/allclients', consumeHeavy.use());\napp.get('/api/allclients', anotherAppLogicHandler);\n```\n\n### Consume Error Handling and Types of errors\n\nBy default the Consume Middleware will generate these HTTP Codes on error:\n\n| Error Type | HTTP Code |\n|---|---|\n| Token Header not set | 401 |\n| Token Header set but invalid value | 401 |\n| Token does not exist in store| 401 |\n| Usage Limit Exceeded | 429 |\n| Any other error generated | 401 |\n\nIf you define your own Error Handler it will be invoked with two arguments, `res` the response object and `error` the error object. All errors will have a `httpcode` property, a number indicating the suggested HTTP error Code.\n\n### Consume Success Handling\n\nThe Consume Middleware will add a response HTTP Header named `X-RateLimit-Remaining` and have as value the remaining usage units. You can change the Header's name using the `setup()` method or you can have your own Success Handler.\n\nThe custom Success Handler will be invoked with the following three arguments:\n\n* **res** `Object` The Express response Object.\n* **next** `Function` The Express callback to pass controll to the next Express Middleware.\n* **remaining** `number` The number or remaining usage units.\n* **behindProxy** `boolean` *default*: false Set to true if node is running beind a reverse-proxy configuration like Heroku for e.g, this is used for fetching the correct Client IP when debug logging occurs.\n\n## The Count Middleware\n\nAdd the Count middleware on every resource you want to count usage. The Count middleware requires a [Kansas][] instance.\n\n```js\nvar kansas = require('kansas');\nvar kansasCount = require('kansas-express/count');\n\n// initialize kansas\nexports.kansas = kansas();\n\n// initialize Count Middleware\nvar apiCount = kansasCount(exports.kansas);\n\n// add to any route\napp.get('/api/clients', apiCount.use());\napp.get('/api/clients', theAppLogicHandler);\n```\n\n### Configuring the Count Middleware\n\nUse the method `setup()` to configure the Count Middleware, it accepts an Object with any of the following properties\n\n* **consumeUnits** `number` *default*: 1 How many units to consume per request.\n* **headerToken** `string` *default*: 'X-Api-Token' Header key to expect the API token.\n* **headerCount** `string` *default*: 'none' Define to populate the Usage Count on the response Header.\n* **handleError** `Function(res, err)` You can overwrite the default Error handler.\n* **handleSuccess** `Function(res, next, remaining)` You can overwrite the default Success handler.\n* **behindProxy** `boolean` *default*: false Set to true if node is running beind a reverse-proxy configuration like Heroku for e.g, this is used for fetching the correct Client IP when debug logging occurs.\n\n```js\nvar kansasCount = require('kansas-express/count');\n\n// create an instance of the Count Middleware\nvar apiCount = kansasCount(kansas);\n\n// Consume 5 units by default\napiCount.setup({\n    consumeUnits: 5,\n});\n```\n\n### Count Error Handling and Types of errors\n\nBy default the Count Middleware will generate these HTTP Codes on error:\n\n| Error Type | HTTP Code |\n|---|---|\n| Token Header not set | 401 |\n| Token Header set but invalid value | 401 |\n| Token does not exist in store| 401 |\n| Any other error generated | 401 |\n\nIf you define your own Error Handler it will be invoked with two arguments, `res` the response object and `error` the error object. All errors will have the `httpcode` property, a number indicating the suggested HTTP error Code.\n\n### Count Success Handling\n\nThe custom Success Handler will be invoked with the following three arguments:\n\n* **res** `Object` The Express response Object.\n* **next** `Function` The Express callback to pass control to the next Express Middleware.\n* **consumed** `number` The number or consumed usage units.\n\n## The Manage Middleware\n\nThe Manage Middleware will add Token managing routes as a convenience for creating your manage panels and dashboards. By default the following routes will be created when the middleware is initialized:\n\n| Method | Route | Action\n|---|---|---|\n| POST | /token | Create a new Token |\n| GET | /token | Fetch all owner's token items|\n| GET | /token/:token | Fetch a single token item |\n| DELETE | /token/:token | Delete a token |\n\n```js\nvar kansas = require('kansas');\nvar kansasManage = require('kansas-express/manage');\n\n// initialize kansas\nvar api = kansas();\n\nvar manage = kansasManage(api);\nmanage.setup({\n  // the provide callback is required\n  // it will provide the ownerId and policyName\n  // to the middleware\n  provide: function(req, res) {\n    return {\n      ownerId: 'hip',\n      policyName: 'free',\n    };\n  }\n});\n\n// pass the express instance to initialize routes\nmanage.addRoutes(app);\n```\n\n### Configuring the Manage Middleware\n\nUse the method `setup()` to configure the Manage Middleware, it accepts an Object with any of the following properties\n\n* **provide** `function` **Required** Will get invoked on each request, needs to provide the `ownerId` and `policyName`.\n* **prefix** `string` *default*: \"\" A prefix to use in the routes.\n* **handleError** `Function(res, err)` You can overwrite the default Error handler.\n* **handleSuccess** `Function(res, next, remaining)` You can overwrite the default Success handler.\n\n#### About the \"provide\" Callback\n\nKansas Express is agnostic to the stack used to track sessions, user objects or authentication. So you need to provide the ownerId and the policy the owner belongs to for each request. This happens with the `provide` callback.\n\nThe Provide callback will get invoked with two arguments, the Request and Response Express objects. Thus you have complete control on how the request will turn out, you can perform authentication checks and reject it there and then or provide the required data and pass control to next.\n\nIt is expected that the Provide callback will produce an Object with two keys `ownerId` and `policyName` either synchronously or asynchronously. To provide the result asynchronously you need to return a Promise that conforms to the Promises/A+ spec.\n\n```js\nmanage.setup({\n    provide: function(req, res) {\n      return new Promise(function(resole, reject) {\n        doSomethingAsync(function(udo){\n          resolve({\n              ownerId: udo.id,\n              policyName: udo.policy,\n          });\n        });\n      });\n    }\n});\n```\n\n### Manage Error Handling and Types of errors\n\nBy default the Manage middleware will generate these HTTP Codes on error:\n\n| Error Type | HTTP Code |\n|---|---|\n| Max Tokens per User Limit Exceeded | 403 |\n| Any other error generated | 500 |\n\nIf you define your own Error Handler it will be invoked with two arguments, `res` the response object and `error` the error object. All errors will have a `httpcode` property, a number indicating the suggested HTTP error Code.\n\n### Manage Success Handling\n\nBy default the Manage Middleware will send these HTTP Codes on success:\n\n| Success Type | HTTP Code |\n|---|---|\n| A request was processed ok | 200 |\n| A Delete operation was successful | 204 |\n\nAll responses will be JSON encoded and the `Content-Type` Header will have a forced value of `application/json`. You can change all that by using your own Success Handler.\n\nThe custom Success Handler will be invoked with the following three arguments:\n\n* **res** `Object` The Express response Object.\n* **result** `Object` The result of the operation.\n* **action** `Manage.Action` An enum of strings with the following possible values:\n  * create\n  * readOne\n  * readAll\n  * delete\n\n## Release History\n\n- **v0.2.4**, *12 Nov 2014*\n    - Updated Kansas *peerDependency* to latest (0.3.2).\n- **v0.2.2**, *02 Oct 2014*\n    - Added debug logging on all failure cases.\n    - Added `behindProxy` option for better IP reporting on the debug logging.\n- **v0.2.1**, *14 Jun 2014*\n    - express 4.0 OK!\n- **v0.2.0**, *04 Apr 2014*\n    - Update to Kansas v0.2.x\n    - Added the Count Middleware.\n- **v0.0.5**, *09 Mar 2014*\n    - Update to Kansas v0.1.10\n- **v0.0.3**, *08 Mar 2014*\n    - Fix not passing req/res to provide method\n    - Update Kansas to latest.\n- **v0.0.1**, *03 Mar 2014*\n    - Big Bang\n\n## License\n\nCopyright (c) 2014 Thanasis Polychronakis. Licensed under the MIT license.\n\n[express]: expressjs.com\n[kansas]: https://github.com/thanpolas/kansas\n","maintainers":[{"name":"thanpolas","email":"thanpolas@gmail.com"}],"time":{"modified":"2022-06-19T07:50:01.365Z","created":"2014-03-03T20:43:36.412Z","0.0.1":"2014-03-03T20:43:39.836Z","0.0.3":"2014-03-08T01:32:52.443Z","0.0.4":"2014-03-09T00:17:29.043Z","0.0.5":"2014-03-09T01:13:40.164Z","0.2.0":"2014-04-04T20:43:46.607Z","0.2.1":"2014-06-14T09:32:17.244Z","0.2.2":"2014-10-02T06:59:49.811Z","0.2.3":"2014-11-12T06:59:15.553Z","0.2.4":"2014-11-12T07:06:32.804Z"},"readmeFilename":"README.md","homepage":"https://github.com/thanpolas/kansas-express","repository":{"type":"git","url":"https://github.com/thanpolas/kansas-express"},"author":{"name":"Thanasis Polychronakis","email":"thanpolas@gmail.com","url":"https://github.com/thanpolas"},"bugs":{"url":"https://github.com/thanpolas/kansas-express/issues"}}