ratelimit-flex 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/cjs/fastify.d.ts +6 -0
- package/dist/cjs/fastify.d.ts.map +1 -0
- package/dist/cjs/fastify.js +10 -0
- package/dist/cjs/fastify.js.map +1 -0
- package/dist/cjs/index.d.ts +5 -8
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -17
- package/dist/cjs/index.js.map +1 -1
- package/dist/fastify.d.ts +6 -0
- package/dist/fastify.d.ts.map +1 -0
- package/dist/fastify.js +6 -0
- package/dist/fastify.js.map +1 -0
- package/dist/index.d.ts +5 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -14
- package/dist/index.js.map +1 -1
- package/package.json +12 -1
package/README.md
CHANGED
|
@@ -58,7 +58,6 @@ Simplest and most memory-efficient approach. Best for straightforward rate limit
|
|
|
58
58
|
```ts
|
|
59
59
|
import rateLimit, {
|
|
60
60
|
expressRateLimiter,
|
|
61
|
-
fastifyRateLimiter,
|
|
62
61
|
createRateLimiter,
|
|
63
62
|
createRateLimitEngine,
|
|
64
63
|
MemoryStore,
|
|
@@ -71,7 +70,12 @@ import rateLimit, {
|
|
|
71
70
|
} from 'ratelimit-flex';
|
|
72
71
|
```
|
|
73
72
|
|
|
73
|
+
```ts
|
|
74
|
+
import { fastifyRateLimiter } from 'ratelimit-flex/fastify';
|
|
75
|
+
```
|
|
76
|
+
|
|
74
77
|
- Default export: `expressRateLimiter`
|
|
78
|
+
- Fastify plugin: import from `ratelimit-flex/fastify` (keeps `fastify` / `fastify-plugin` off the main entry for Express-only apps)
|
|
75
79
|
- Named exports include all of the above plus all types from `types/index.ts`
|
|
76
80
|
- `createRateLimitEngine(options)`: factory that returns a `RateLimitEngine` instance (for advanced use cases)
|
|
77
81
|
|
|
@@ -103,16 +107,13 @@ import rateLimit, {
|
|
|
103
107
|
|
|
104
108
|
### Convenience Factory: `createRateLimiter(options)`
|
|
105
109
|
|
|
106
|
-
`createRateLimiter` returns
|
|
110
|
+
`createRateLimiter` returns `{ express }` — Express middleware only. For Fastify, use `import { fastifyRateLimiter } from 'ratelimit-flex/fastify'`.
|
|
107
111
|
|
|
108
112
|
```ts
|
|
109
113
|
const limiter = createRateLimiter({ maxRequests: 100 });
|
|
110
|
-
app.use(limiter.express);
|
|
111
|
-
await app.register(limiter.fastify); // Fastify
|
|
114
|
+
app.use(limiter.express);
|
|
112
115
|
```
|
|
113
116
|
|
|
114
|
-
**Note**: This function requires `fastify-plugin` as a peer dependency (already listed). For best type-safety and clarity, prefer direct imports (`expressRateLimiter` or `fastifyRateLimiter`) when you already know your framework.
|
|
115
|
-
|
|
116
117
|
## Examples
|
|
117
118
|
|
|
118
119
|
### Basic Express usage
|
|
@@ -135,7 +136,8 @@ app.use(
|
|
|
135
136
|
|
|
136
137
|
```ts
|
|
137
138
|
import Fastify from 'fastify';
|
|
138
|
-
import { fastifyRateLimiter
|
|
139
|
+
import { fastifyRateLimiter } from 'ratelimit-flex/fastify';
|
|
140
|
+
import { RateLimitStrategy } from 'ratelimit-flex';
|
|
139
141
|
|
|
140
142
|
const app = Fastify();
|
|
141
143
|
await app.register(fastifyRateLimiter, {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify integration — import from `ratelimit-flex/fastify` so Express-only apps
|
|
3
|
+
* do not resolve `fastify` or `fastify-plugin` from the main package entry.
|
|
4
|
+
*/
|
|
5
|
+
export { fastifyRateLimiter } from './middleware/fastify.js';
|
|
6
|
+
//# sourceMappingURL=fastify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../../src/fastify.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fastifyRateLimiter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Fastify integration — import from `ratelimit-flex/fastify` so Express-only apps
|
|
6
|
+
* do not resolve `fastify` or `fastify-plugin` from the main package entry.
|
|
7
|
+
*/
|
|
8
|
+
var fastify_js_1 = require("./middleware/fastify.js");
|
|
9
|
+
Object.defineProperty(exports, "fastifyRateLimiter", { enumerable: true, get: function () { return fastify_js_1.fastifyRateLimiter; } });
|
|
10
|
+
//# sourceMappingURL=fastify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../../src/fastify.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,sDAA6D;AAApD,gHAAA,kBAAkB,OAAA"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* ratelimit-flex — flexible rate limiting for Node.js
|
|
3
3
|
*/
|
|
4
4
|
import { expressRateLimiter } from './middleware/express.js';
|
|
5
|
-
import { fastifyRateLimiter } from './middleware/fastify.js';
|
|
6
5
|
import type { RateLimitOptions } from './types/index.js';
|
|
7
6
|
export declare const VERSION = "0.1.0";
|
|
8
|
-
export { expressRateLimiter
|
|
7
|
+
export { expressRateLimiter };
|
|
9
8
|
export { RateLimitEngine, createRateLimiter as createRateLimitEngine, defaultKeyGenerator, type RateLimitConsumeResult, type RateLimiterConfigInput, } from './strategies/rate-limit-engine.js';
|
|
10
9
|
export { MemoryStore } from './stores/memory-store.js';
|
|
11
10
|
export { RedisStore } from './stores/redis-store.js';
|
|
@@ -13,20 +12,18 @@ export { fixedWindowDefaults, slidingWindowDefaults, tokenBucketDefaults } from
|
|
|
13
12
|
export * from './types/index.js';
|
|
14
13
|
export { RateLimitStrategy } from './types/index.js';
|
|
15
14
|
/**
|
|
16
|
-
* Convenience factory that returns
|
|
15
|
+
* Convenience factory that returns Express middleware.
|
|
16
|
+
*
|
|
17
|
+
* For Fastify, use `import { fastifyRateLimiter } from 'ratelimit-flex/fastify'`.
|
|
17
18
|
*
|
|
18
19
|
* Usage:
|
|
19
20
|
* ```ts
|
|
20
21
|
* const limiter = createRateLimiter({ maxRequests: 100 });
|
|
21
|
-
* app.use(limiter.express);
|
|
22
|
-
* await app.register(limiter.fastify); // Fastify
|
|
22
|
+
* app.use(limiter.express);
|
|
23
23
|
* ```
|
|
24
|
-
*
|
|
25
|
-
* Prefer importing `expressRateLimiter` or `fastifyRateLimiter` directly when framework is known.
|
|
26
24
|
*/
|
|
27
25
|
export declare function createRateLimiter(options: Partial<RateLimitOptions>): {
|
|
28
26
|
express: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
29
|
-
fastify: typeof fastifyRateLimiter;
|
|
30
27
|
};
|
|
31
28
|
export default expressRateLimiter;
|
|
32
29
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAG9B,OAAO,EACL,eAAe,EACf,iBAAiB,IAAI,qBAAqB,EAC1C,mBAAmB,EACnB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG3G,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC;;EAInE;AAGD,eAAe,kBAAkB,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -16,17 +16,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
16
16
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
18
|
};
|
|
19
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
-
};
|
|
22
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.RateLimitStrategy = exports.tokenBucketDefaults = exports.slidingWindowDefaults = exports.fixedWindowDefaults = exports.RedisStore = exports.MemoryStore = exports.defaultKeyGenerator = exports.createRateLimitEngine = exports.RateLimitEngine = exports.
|
|
20
|
+
exports.RateLimitStrategy = exports.tokenBucketDefaults = exports.slidingWindowDefaults = exports.fixedWindowDefaults = exports.RedisStore = exports.MemoryStore = exports.defaultKeyGenerator = exports.createRateLimitEngine = exports.RateLimitEngine = exports.expressRateLimiter = exports.VERSION = void 0;
|
|
24
21
|
exports.createRateLimiter = createRateLimiter;
|
|
25
22
|
const express_js_1 = require("./middleware/express.js");
|
|
26
23
|
Object.defineProperty(exports, "expressRateLimiter", { enumerable: true, get: function () { return express_js_1.expressRateLimiter; } });
|
|
27
|
-
const fastify_js_1 = require("./middleware/fastify.js");
|
|
28
|
-
Object.defineProperty(exports, "fastifyRateLimiter", { enumerable: true, get: function () { return fastify_js_1.fastifyRateLimiter; } });
|
|
29
|
-
const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
|
|
30
24
|
exports.VERSION = '0.1.0';
|
|
31
25
|
// Core engine and stores
|
|
32
26
|
var rate_limit_engine_js_1 = require("./strategies/rate-limit-engine.js");
|
|
@@ -47,25 +41,19 @@ __exportStar(require("./types/index.js"), exports);
|
|
|
47
41
|
var index_js_1 = require("./types/index.js");
|
|
48
42
|
Object.defineProperty(exports, "RateLimitStrategy", { enumerable: true, get: function () { return index_js_1.RateLimitStrategy; } });
|
|
49
43
|
/**
|
|
50
|
-
* Convenience factory that returns
|
|
44
|
+
* Convenience factory that returns Express middleware.
|
|
45
|
+
*
|
|
46
|
+
* For Fastify, use `import { fastifyRateLimiter } from 'ratelimit-flex/fastify'`.
|
|
51
47
|
*
|
|
52
48
|
* Usage:
|
|
53
49
|
* ```ts
|
|
54
50
|
* const limiter = createRateLimiter({ maxRequests: 100 });
|
|
55
|
-
* app.use(limiter.express);
|
|
56
|
-
* await app.register(limiter.fastify); // Fastify
|
|
51
|
+
* app.use(limiter.express);
|
|
57
52
|
* ```
|
|
58
|
-
*
|
|
59
|
-
* Prefer importing `expressRateLimiter` or `fastifyRateLimiter` directly when framework is known.
|
|
60
53
|
*/
|
|
61
54
|
function createRateLimiter(options) {
|
|
62
|
-
const wrappedPlugin = (0, fastify_plugin_1.default)(async (fastify, pluginOpts = {}) => {
|
|
63
|
-
const merged = { ...options, ...pluginOpts };
|
|
64
|
-
return fastify_js_1.fastifyRateLimiter(fastify, merged);
|
|
65
|
-
}, { name: 'ratelimit-flex-wrapper' });
|
|
66
55
|
return {
|
|
67
56
|
express: (0, express_js_1.expressRateLimiter)(options),
|
|
68
|
-
fastify: wrappedPlugin,
|
|
69
57
|
};
|
|
70
58
|
}
|
|
71
59
|
// Express is the most common default integration path.
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAuCH,8CAIC;AAzCD,wDAA6D;AAMpD,mGANA,+BAAkB,OAMA;AAHd,QAAA,OAAO,GAAG,OAAO,CAAC;AAK/B,yBAAyB;AACzB,0EAM2C;AALzC,uHAAA,eAAe,OAAA;AACf,6HAAA,iBAAiB,OAAyB;AAC1C,2HAAA,mBAAmB,OAAA;AAIrB,4DAAuD;AAA9C,8GAAA,WAAW,OAAA;AACpB,0DAAqD;AAA5C,4GAAA,UAAU,OAAA;AAEnB,oBAAoB;AACpB,wDAA2G;AAAlG,kHAAA,mBAAmB,OAAA;AAAE,oHAAA,qBAAqB,OAAA;AAAE,kHAAA,mBAAmB,OAAA;AAExE,yBAAyB;AACzB,mDAAiC;AACjC,6CAAqD;AAA5C,6GAAA,iBAAiB,OAAA;AAE1B;;;;;;;;;;GAUG;AACH,SAAgB,iBAAiB,CAAC,OAAkC;IAClE,OAAO;QACL,OAAO,EAAE,IAAA,+BAAkB,EAAC,OAAO,CAAC;KACrC,CAAC;AACJ,CAAC;AAED,uDAAuD;AACvD,kBAAe,+BAAkB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify integration — import from `ratelimit-flex/fastify` so Express-only apps
|
|
3
|
+
* do not resolve `fastify` or `fastify-plugin` from the main package entry.
|
|
4
|
+
*/
|
|
5
|
+
export { fastifyRateLimiter } from './middleware/fastify.js';
|
|
6
|
+
//# sourceMappingURL=fastify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/fastify.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify integration — import from `ratelimit-flex/fastify` so Express-only apps
|
|
3
|
+
* do not resolve `fastify` or `fastify-plugin` from the main package entry.
|
|
4
|
+
*/
|
|
5
|
+
export { fastifyRateLimiter } from './middleware/fastify.js';
|
|
6
|
+
//# sourceMappingURL=fastify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* ratelimit-flex — flexible rate limiting for Node.js
|
|
3
3
|
*/
|
|
4
4
|
import { expressRateLimiter } from './middleware/express.js';
|
|
5
|
-
import { fastifyRateLimiter } from './middleware/fastify.js';
|
|
6
5
|
import type { RateLimitOptions } from './types/index.js';
|
|
7
6
|
export declare const VERSION = "0.1.0";
|
|
8
|
-
export { expressRateLimiter
|
|
7
|
+
export { expressRateLimiter };
|
|
9
8
|
export { RateLimitEngine, createRateLimiter as createRateLimitEngine, defaultKeyGenerator, type RateLimitConsumeResult, type RateLimiterConfigInput, } from './strategies/rate-limit-engine.js';
|
|
10
9
|
export { MemoryStore } from './stores/memory-store.js';
|
|
11
10
|
export { RedisStore } from './stores/redis-store.js';
|
|
@@ -13,20 +12,18 @@ export { fixedWindowDefaults, slidingWindowDefaults, tokenBucketDefaults } from
|
|
|
13
12
|
export * from './types/index.js';
|
|
14
13
|
export { RateLimitStrategy } from './types/index.js';
|
|
15
14
|
/**
|
|
16
|
-
* Convenience factory that returns
|
|
15
|
+
* Convenience factory that returns Express middleware.
|
|
16
|
+
*
|
|
17
|
+
* For Fastify, use `import { fastifyRateLimiter } from 'ratelimit-flex/fastify'`.
|
|
17
18
|
*
|
|
18
19
|
* Usage:
|
|
19
20
|
* ```ts
|
|
20
21
|
* const limiter = createRateLimiter({ maxRequests: 100 });
|
|
21
|
-
* app.use(limiter.express);
|
|
22
|
-
* await app.register(limiter.fastify); // Fastify
|
|
22
|
+
* app.use(limiter.express);
|
|
23
23
|
* ```
|
|
24
|
-
*
|
|
25
|
-
* Prefer importing `expressRateLimiter` or `fastifyRateLimiter` directly when framework is known.
|
|
26
24
|
*/
|
|
27
25
|
export declare function createRateLimiter(options: Partial<RateLimitOptions>): {
|
|
28
26
|
express: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
29
|
-
fastify: typeof fastifyRateLimiter;
|
|
30
27
|
};
|
|
31
28
|
export default expressRateLimiter;
|
|
32
29
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAG9B,OAAO,EACL,eAAe,EACf,iBAAiB,IAAI,qBAAqB,EAC1C,mBAAmB,EACnB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG3G,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC;;EAInE;AAGD,eAAe,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
* ratelimit-flex — flexible rate limiting for Node.js
|
|
3
3
|
*/
|
|
4
4
|
import { expressRateLimiter } from './middleware/express.js';
|
|
5
|
-
import { fastifyRateLimiter } from './middleware/fastify.js';
|
|
6
|
-
import fp from 'fastify-plugin';
|
|
7
5
|
export const VERSION = '0.1.0';
|
|
8
|
-
// Framework adapters
|
|
9
|
-
export { expressRateLimiter
|
|
6
|
+
// Framework adapters (Fastify: `import { fastifyRateLimiter } from 'ratelimit-flex/fastify'`)
|
|
7
|
+
export { expressRateLimiter };
|
|
10
8
|
// Core engine and stores
|
|
11
9
|
export { RateLimitEngine, createRateLimiter as createRateLimitEngine, defaultKeyGenerator, } from './strategies/rate-limit-engine.js';
|
|
12
10
|
export { MemoryStore } from './stores/memory-store.js';
|
|
@@ -17,25 +15,19 @@ export { fixedWindowDefaults, slidingWindowDefaults, tokenBucketDefaults } from
|
|
|
17
15
|
export * from './types/index.js';
|
|
18
16
|
export { RateLimitStrategy } from './types/index.js';
|
|
19
17
|
/**
|
|
20
|
-
* Convenience factory that returns
|
|
18
|
+
* Convenience factory that returns Express middleware.
|
|
19
|
+
*
|
|
20
|
+
* For Fastify, use `import { fastifyRateLimiter } from 'ratelimit-flex/fastify'`.
|
|
21
21
|
*
|
|
22
22
|
* Usage:
|
|
23
23
|
* ```ts
|
|
24
24
|
* const limiter = createRateLimiter({ maxRequests: 100 });
|
|
25
|
-
* app.use(limiter.express);
|
|
26
|
-
* await app.register(limiter.fastify); // Fastify
|
|
25
|
+
* app.use(limiter.express);
|
|
27
26
|
* ```
|
|
28
|
-
*
|
|
29
|
-
* Prefer importing `expressRateLimiter` or `fastifyRateLimiter` directly when framework is known.
|
|
30
27
|
*/
|
|
31
28
|
export function createRateLimiter(options) {
|
|
32
|
-
const wrappedPlugin = fp(async (fastify, pluginOpts = {}) => {
|
|
33
|
-
const merged = { ...options, ...pluginOpts };
|
|
34
|
-
return fastifyRateLimiter(fastify, merged);
|
|
35
|
-
}, { name: 'ratelimit-flex-wrapper' });
|
|
36
29
|
return {
|
|
37
30
|
express: expressRateLimiter(options),
|
|
38
|
-
fastify: wrappedPlugin,
|
|
39
31
|
};
|
|
40
32
|
}
|
|
41
33
|
// Express is the most common default integration path.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,8FAA8F;AAC9F,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,yBAAyB;AACzB,OAAO,EACL,eAAe,EACf,iBAAiB,IAAI,qBAAqB,EAC1C,mBAAmB,GAGpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,oBAAoB;AACpB,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE3G,yBAAyB;AACzB,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAkC;IAClE,OAAO;QACL,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC;KACrC,CAAC;AACJ,CAAC;AAED,uDAAuD;AACvD,eAAe,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ratelimit-flex",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Flexible rate limiting for Node.js (Express, Fastify, sliding window, token bucket)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -27,6 +27,17 @@
|
|
|
27
27
|
"default": "./dist/cjs/index.js"
|
|
28
28
|
},
|
|
29
29
|
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./fastify": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/fastify.d.ts",
|
|
34
|
+
"default": "./dist/fastify.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/cjs/fastify.d.ts",
|
|
38
|
+
"default": "./dist/cjs/fastify.js"
|
|
39
|
+
},
|
|
40
|
+
"default": "./dist/fastify.js"
|
|
30
41
|
}
|
|
31
42
|
},
|
|
32
43
|
"peerDependencies": {
|