{"_id":"@hono-rate-limiter/cloudflare","_rev":"5-8c2b0a612b8441060ee7590a246c8535","name":"@hono-rate-limiter/cloudflare","dist-tags":{"latest":"0.2.2"},"versions":{"0.1.0":{"name":"@hono-rate-limiter/cloudflare","version":"0.1.0","keywords":["hono","cloudflare","database","serverless","edge","rate-limiting","rate-limiter","honojs"],"license":"MIT","_id":"@hono-rate-limiter/cloudflare@0.1.0","homepage":"https://hono-rate-limiter.vercel.app","bugs":{"url":"https://github.com/rhinobase/hono-rate-limiter/issues"},"dist":{"shasum":"b4cac30db464f6b4ebca28bcf9b2a93cd8337bab","tarball":"https://registry.npmjs.org/@hono-rate-limiter/cloudflare/-/cloudflare-0.1.0.tgz","fileCount":10,"integrity":"sha512-oUo7lW7hZxPPwxLldqquH8EWJQ7EmaqGBl5bSo3ui5nF1QyH6XVdTBejc0gSSP0TE4mXcHrTe/gvAJWvq44FLw==","signatures":[{"sig":"MEUCIQD9ged9HA3fV64jpWjVKpN4fgMwjgyMHMVr8kheTYFG4QIgPlcLLw61yOoIeGqrpcL3qb3H6UirQsbUR2sTiqH7T+Y=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13140},"main":"./index.cjs.js","types":"./index.cjs.d.ts","module":"./index.esm.js","gitHead":"fda99a8a833df250a9f7e0318bf17af58f912a33","_npmUser":{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"},"repository":{"url":"git+https://github.com/rhinobase/hono-rate-limiter.git","type":"git","directory":"packages/cloudflare"},"_npmVersion":"10.2.4","description":"<div align=\"center\">","directories":{},"_nodeVersion":"20.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"hono":"^4.4.8","hono-rate-limiter":"^0.2.1"},"_npmOperationalInternal":{"tmp":"tmp/cloudflare_0.1.0_1719387707679_0.8467611092626139","host":"s3://npm-registry-packages"}},"0.1.1":{"name":"@hono-rate-limiter/cloudflare","version":"0.1.1","keywords":["hono","cloudflare","database","serverless","edge","rate-limiting","rate-limiter","honojs"],"license":"MIT","_id":"@hono-rate-limiter/cloudflare@0.1.1","homepage":"https://hono-rate-limiter.rhinobase.workers.dev","bugs":{"url":"https://github.com/rhinobase/hono-rate-limiter/issues"},"dist":{"shasum":"0458eaf519d07e787060eb18a85ac1ba338f250a","tarball":"https://registry.npmjs.org/@hono-rate-limiter/cloudflare/-/cloudflare-0.1.1.tgz","fileCount":10,"integrity":"sha512-JVNxrry/H9o0DncmXQINNMHXF5uFtMkqOr7k4QdJGOaqwyCiWL1A4pE9EFoOP9SQajueoho/5Hc7S4/B8ascvg==","signatures":[{"sig":"MEUCIF8c9swvK4Unq1Ur+91oPZeUpaHPHHba+3P326KW0qPKAiEA7HUAiZeDCe3WpRlRVbMyRNNdSNtkzEXCwHzxugOFW0o=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13249},"main":"./index.cjs.js","types":"./index.cjs.d.ts","module":"./index.esm.js","gitHead":"9a2501eb5aea19f9a0cf8eab10cb3743c7e2a5b1","_npmUser":{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"},"repository":{"url":"git+https://github.com/rhinobase/hono-rate-limiter.git","type":"git","directory":"packages/cloudflare"},"_npmVersion":"10.2.4","description":"<div align=\"center\">","directories":{},"_nodeVersion":"20.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"hono-rate-limiter":"^0.2.1"},"peerDependencies":{"hono":"^4.4.8"},"_npmOperationalInternal":{"tmp":"tmp/cloudflare_0.1.1_1719388981165_0.7793907283744455","host":"s3://npm-registry-packages"}},"0.1.2":{"name":"@hono-rate-limiter/cloudflare","version":"0.1.2","keywords":["hono","cloudflare","database","serverless","edge","rate-limiting","rate-limiter","honojs"],"license":"MIT","_id":"@hono-rate-limiter/cloudflare@0.1.2","maintainers":[{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"}],"homepage":"https://hono-rate-limiter.rhinobase.workers.dev","bugs":{"url":"https://github.com/rhinobase/hono-rate-limiter/issues"},"dist":{"shasum":"ef3d1b96d498a6f5dbd7c9914444c0acbed767b4","tarball":"https://registry.npmjs.org/@hono-rate-limiter/cloudflare/-/cloudflare-0.1.2.tgz","fileCount":12,"integrity":"sha512-s0eTlzY+7AI6oHoToAVkRiCZmS9hxnuVe1f+4zQ2iq+wsoWNOla+dIrdwFezNeBwuMBRFnhoNSw8DeNNijAydw==","signatures":[{"sig":"MEYCIQDktySsB/SWBNHBsvjjsiJvVnYVOjqGt6ZbakLEK3JP7QIhANe7b1p+/P/Oi15J73H3mw4O/FIIA0klXDFIrYK5jMSZ","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14623},"main":"./index.cjs.js","types":"./index.cjs.d.ts","module":"./index.esm.js","gitHead":"b32ad9f1c714e62a0340dd745291dc0dcad16338","_npmUser":{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"},"repository":{"url":"git+https://github.com/rhinobase/hono-rate-limiter.git","type":"git","directory":"packages/cloudflare"},"_npmVersion":"10.7.0","description":"<div align=\"center\">","directories":{},"_nodeVersion":"22.1.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"hono-rate-limiter":"^0.2.1"},"peerDependencies":{"hono":"^4.4.8"},"_npmOperationalInternal":{"tmp":"tmp/cloudflare_0.1.2_1720040122015_0.5729825103579675","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"@hono-rate-limiter/cloudflare","version":"0.2.0","keywords":["hono","cloudflare","database","serverless","edge","rate-limiting","rate-limiter","honojs"],"license":"MIT","_id":"@hono-rate-limiter/cloudflare@0.2.0","maintainers":[{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"}],"homepage":"https://hono-rate-limiter.rhinobase.workers.dev","bugs":{"url":"https://github.com/rhinobase/hono-rate-limiter/issues"},"dist":{"shasum":"26a71d601a98168275edb61291dc8503185c624a","tarball":"https://registry.npmjs.org/@hono-rate-limiter/cloudflare/-/cloudflare-0.2.0.tgz","fileCount":14,"integrity":"sha512-mOBk9EshKiShN5zQpDN146TlW2PghQEI0Uvw9Fx1LeFwCUOmgDR9IoXIq6zTk9qgqQWTlco+PoAKGzzaOU3xTw==","signatures":[{"sig":"MEQCIAYPZo46F3zI61gcKGw/WgQza/iXLiW1KGzfZcr77AtLAiBqDiGBRRcZr1IOPl9F+Zutfcs1oFwdqfa7MnhsaiRxbQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":21545},"main":"./index.cjs.js","types":"./index.cjs.d.ts","module":"./index.esm.js","gitHead":"c3526da6404d91dd4dc1e335b763967cc3085779","_npmUser":{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"},"repository":{"url":"git+https://github.com/rhinobase/hono-rate-limiter.git","type":"git","directory":"packages/cloudflare"},"_npmVersion":"10.7.0","description":"<div align=\"center\">","directories":{},"_nodeVersion":"22.1.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"hono-rate-limiter":"^0.2.1"},"peerDependencies":{"hono":"^4.4.8","@cloudflare/workers-types":"^4.20240529.0"},"_npmOperationalInternal":{"tmp":"tmp/cloudflare_0.2.0_1725130284320_0.4039923166452881","host":"s3://npm-registry-packages"}},"0.2.1":{"name":"@hono-rate-limiter/cloudflare","version":"0.2.1","keywords":["hono","cloudflare","database","serverless","edge","rate-limiting","rate-limiter","honojs"],"license":"MIT","_id":"@hono-rate-limiter/cloudflare@0.2.1","maintainers":[{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"}],"homepage":"https://hono-rate-limiter.rhinobase.workers.dev","bugs":{"url":"https://github.com/rhinobase/hono-rate-limiter/issues"},"dist":{"shasum":"4a68ac030f11e11bd87894092580695d52380bc7","tarball":"https://registry.npmjs.org/@hono-rate-limiter/cloudflare/-/cloudflare-0.2.1.tgz","fileCount":14,"integrity":"sha512-Ax0xHm3Q9V0dJ8nfdAZOm34tT9uoF+GY4qFXSiNliLb78wMhRp9wg0v7YlQYPSXMNu8aoEmdCwx2LpQw8iVDMA==","signatures":[{"sig":"MEYCIQDE2Sl/wfoJSYhGWwV3ezVjLWnoYEntNEHU4HbArJ4FFwIhAMX9FbJPE+9DWX+OSIEYlFf0KvTk1BZmgfZpHK32We7a","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":22036},"main":"./index.cjs.js","types":"./index.cjs.d.ts","module":"./index.esm.js","gitHead":"a56b7133e2dad2fca7af060fe86a34c602b3f413","_npmUser":{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"},"repository":{"url":"git+https://github.com/rhinobase/hono-rate-limiter.git","type":"git","directory":"packages/cloudflare"},"_npmVersion":"10.7.0","description":"<div align=\"center\">","directories":{},"_nodeVersion":"22.1.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"hono-rate-limiter":"^0.2.1"},"peerDependencies":{"hono":"^4.4.8","@cloudflare/workers-types":"^4.20240529.0"},"_npmOperationalInternal":{"tmp":"tmp/cloudflare_0.2.1_1725303763203_0.5421058309762814","host":"s3://npm-registry-packages"}},"0.2.2":{"name":"@hono-rate-limiter/cloudflare","description":"Cloudflare stores and helper functions for hono-rate-limiter.","version":"0.2.2","license":"MIT","keywords":["hono","cloudflare","database","serverless","edge","rate-limiting","rate-limiter","honojs"],"homepage":"https://hono-rate-limiter.rhinobase.workers.dev","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/rhinobase/hono-rate-limiter.git","directory":"packages/cloudflare"},"bugs":{"url":"https://github.com/rhinobase/hono-rate-limiter/issues"},"peerDependencies":{"@cloudflare/workers-types":"^4.20240529.0","hono":"^4.4.8"},"devDependencies":{"hono-rate-limiter":"^0.2.1"},"types":"./index.cjs.d.ts","module":"./index.esm.js","main":"./index.cjs.js","_id":"@hono-rate-limiter/cloudflare@0.2.2","gitHead":"720da9f9b3469214e2e427876a53080076410176","_nodeVersion":"22.1.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-wMnqeV+cb5Wov2npLIMFtCVm3tiNMtqw9LhPWSzSMwHOzh2qbhI3mCS6s962fxcJ6UUNJhRqDbVMEsB/NinCIQ==","shasum":"42ea32f5381b1ec2bf65a2eaa038cfaf42757d1e","tarball":"https://registry.npmjs.org/@hono-rate-limiter/cloudflare/-/cloudflare-0.2.2.tgz","fileCount":13,"unpackedSize":20521,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD2MBMyguoa3WzXpN0ahzqh1gVZZifRUlH0BcHKE1ilvAIhANfXCrh4dMMjaF7lt3qpMq83uOp6PqSnifFVUkQlEN8Z"}]},"_npmUser":{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"},"directories":{},"maintainers":[{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cloudflare_0.2.2_1733337112176_0.5593683345893701"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-26T07:41:47.587Z","modified":"2024-12-04T18:31:52.565Z","0.1.0":"2024-06-26T07:41:47.826Z","0.1.1":"2024-06-26T08:03:01.345Z","0.1.2":"2024-07-03T20:55:22.152Z","0.2.0":"2024-08-31T18:51:24.494Z","0.2.1":"2024-09-02T19:02:43.389Z","0.2.2":"2024-12-04T18:31:52.354Z"},"bugs":{"url":"https://github.com/rhinobase/hono-rate-limiter/issues"},"license":"MIT","homepage":"https://hono-rate-limiter.rhinobase.workers.dev","keywords":["hono","cloudflare","database","serverless","edge","rate-limiting","rate-limiter","honojs"],"repository":{"type":"git","url":"git+https://github.com/rhinobase/hono-rate-limiter.git","directory":"packages/cloudflare"},"description":"Cloudflare stores and helper functions for hono-rate-limiter.","maintainers":[{"name":"mathuraditya724","email":"mathuraditya724@gmail.com"}],"readme":"# <div align=\"center\">🔥`@hono-rate-limiter/cloudflare`🔥</div>\n\n<div align=\"center\">\n\n[![tests](https://img.shields.io/github/actions/workflow/status/rhinobase/hono-rate-limiter/test.yml)](https://github.com/rhinobase/hono-rate-limiter/actions/workflows/test.yml)\n[![npm version](https://img.shields.io/npm/v/@hono-rate-limiter/cloudflare.svg)](https://npmjs.org/package/@hono-rate-limiter/cloudflare \"View this project on NPM\")\n[![npm downloads](https://img.shields.io/npm/dm/@hono-rate-limiter/cloudflare)](https://www.npmjs.com/package/@hono-rate-limiter/cloudflare)\n[![license](https://img.shields.io/npm/l/%40hono-rate-limiter%2Fcloudflare)](LICENSE)\n\n</div>\n\nThis package includes [`WorkersKV`](https://developers.cloudflare.com/kv/) and [Durable Object](https://developers.cloudflare.com/durable-objects/) store for the [`hono-rate-limiter`](https://github.com/rhinobase/hono-rate-limiter) middleware and `cloudflareRateLimiter` func for [Workers Rate Limiting](https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/) API.\n\n> [!NOTE]  \n> The `keyGenerator` function and `rateLimitBinding` bindings needs to be defined for `cloudflareRateLimiter` to work properly in your environment. Please ensure that you define the `keyGenerator` function according to the documentation before using the library.\n\n## Installation\n\n```sh\n# Using npm/yarn/pnpm/bun\nnpm add @hono-rate-limiter/cloudflare\n```\n\n## Usage\n\n### Examples\n\n#### Using `cloudflareRateLimiter`\n\n```toml\n# wrangler.toml\n# The rate limiting API is in open beta.\n[[unsafe.bindings]]\nname = \"MY_RATE_LIMITER\"\ntype = \"ratelimit\"\n# An identifier you define, that is unique to your Cloudflare account.\n# Must be an integer.\nnamespace_id = \"1001\"\n\n# Limit: the number of tokens allowed within a given period in a single\n# Cloudflare location\n# Period: the duration of the period, in seconds. Must be either 10 or 60\nsimple = { limit = 100, period = 60 }\n```\n\nFor more info on setting up your Workers Rate Limiting API you can check out [Rate Limiting Guide](https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/) on cloudflare.\n\n```ts\nimport { cloudflareRateLimiter } from \"@hono-rate-limiter/cloudflare\";\n\ntype AppType = {\n  Variables: {\n    rateLimit: boolean;\n  };\n  Bindings: {\n    RATE_LIMITER: RateLimit;\n  };\n};\n\n// Apply the rate limiting middleware to all requests.\nconst app = new Hono<AppType>().use(\n  cloudflareRateLimiter<AppType>({\n    rateLimitBinding: (c) => c.env.RATE_LIMITER,\n    keyGenerator: (c) => c.req.header(\"cf-connecting-ip\") ?? \"\", // Method to generate custom identifiers for clients.\n  })\n);\n```\n\n#### Using `WorkersKVStore`\n\n```toml\n# wrangler.toml\n[[kv_namespaces]]\nbinding = \"CACHE\"\nid = \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n```\n\nFor more info on setting up your `WorkersKV` you can check out [Get Started Guide](https://developers.cloudflare.com/kv/get-started) on cloudflare.\n\n```ts\n// index.ts\nimport { WorkersKVStore } from \"@hono-rate-limiter/cloudflare\";\nimport { rateLimiter } from \"hono-rate-limiter\";\nimport { Context, Next } from \"hono\";\nimport { KVNamespace } from \"cloudflare:worker\";\n\n// Add this in Hono app\ntype Bindings = {\n  CACHE: KVNamespace;\n  // ... other binding types\n};\n\nconst app = new Hono<{ Bindings: Bindings }>();\n\n// Apply the rate limiting middleware to all requests.\napp.use((c: Context, next: Next) =>\n  rateLimiter<{ Bindings: Bindings }>({\n    windowMs: 15 * 60 * 1000, // 15 minutes\n    limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).\n    standardHeaders: \"draft-6\", // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header\n    keyGenerator: (c) => c.req.header(\"cf-connecting-ip\") ?? \"\", // Method to generate custom identifiers for clients.\n    store: new WorkersKVStore({ namespace: c.env.CACHE }), // Here CACHE is your WorkersKV Binding.\n  })(c, next)\n);\n```\n\n#### Using `DurableObjectStore`\n\n```toml\n# wrangler.toml\n[[durable_objects.bindings]]\nname = \"CACHE\"\nclass_name = \"DurableObjectRateLimiter\"\n\n[[migrations]]\ntag = \"v1\" # Should be unique for each entry\nnew_classes = [\"DurableObjectRateLimiter\"]\n```\n\nFor more info on setting up your `Durable Objects` you can check out [Get Started Guide](https://developers.cloudflare.com/durable-objects/get-started/) on cloudflare.\n\n```ts\n// index.ts\nimport { DurableObjectStore, DurableObjectRateLimiter } from \"@hono-rate-limiter/cloudflare\";\nimport { rateLimiter } from \"hono-rate-limiter\";\nimport { Context, Next } from \"hono\";\nimport { DurableObjectNamespace } from \"cloudflare:worker\";\n\n// Add this in Hono app\ntype Bindings = {\n  CACHE: DurableObjectNamespace<DurableObjectRateLimiter>;\n  // ... other binding types\n};\n\nconst app = new Hono<{ Bindings: Bindings }>();\n\n// Apply the rate limiting middleware to all requests.\napp.use((c: Context, next: Next) =>\n  rateLimiter<{ Bindings: Bindings }>({\n    windowMs: 15 * 60 * 1000, // 15 minutes\n    limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).\n    standardHeaders: \"draft-6\", // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header\n    keyGenerator: (c) => c.req.header(\"cf-connecting-ip\") ?? \"\", // Method to generate custom identifiers for clients.\n    store: new DurableObjectStore({ namespace: c.env.CACHE }), // Here CACHE is your Durable Object Binding.\n  })(c, next)\n);\n\n// ...\n\nexport { DurableObjectRateLimiter };\n\nexport default app;\n```\n\n### Configuration Props of `WorkersKVStore` and `DurableObjectStore`\n\n#### `namespace`\n\nThe KV / Durable Object namespace to use. The value you set for <BINDING_NAME> will be used to reference this database / durable object in your Worker.\n\n#### `prefix`\n\nThe text to prepend to the key in the KV / Durable Object namespace.\n\nDefaults to `hrl:`.\n\n## Contributing\n\nWe would love to have more contributors involved!\n\nTo get started, please read our [Contributing Guide](https://github.com/rhinobase/hono-rate-limiter/blob/main/CONTRIBUTING.md).\n","readmeFilename":"README.md"}