@fluojs/throttler 1.0.0-beta.1 → 1.0.0-beta.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.ko.md +14 -7
- package/README.md +14 -7
- package/package.json +5 -5
package/README.ko.md
CHANGED
|
@@ -31,12 +31,12 @@ npm install @fluojs/throttler
|
|
|
31
31
|
|
|
32
32
|
## 빠른 시작
|
|
33
33
|
|
|
34
|
-
`ThrottlerModule`을
|
|
34
|
+
`ThrottlerModule`을 등록하고, `@UseGuards(...)`로 `ThrottlerGuard`를 연결한 뒤, 라우트별 제한이 필요한 컨트롤러나 메서드에 `Throttle` 데코레이터를 적용합니다.
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
import { Module } from '@fluojs/core';
|
|
38
|
-
import { ThrottlerModule, Throttle, SkipThrottle } from '@fluojs/throttler';
|
|
39
|
-
import { Controller, Post } from '@fluojs/http';
|
|
38
|
+
import { ThrottlerGuard, ThrottlerModule, Throttle, SkipThrottle } from '@fluojs/throttler';
|
|
39
|
+
import { Controller, Post, UseGuards } from '@fluojs/http';
|
|
40
40
|
|
|
41
41
|
@Module({
|
|
42
42
|
imports: [
|
|
@@ -49,6 +49,7 @@ import { Controller, Post } from '@fluojs/http';
|
|
|
49
49
|
class AppModule {}
|
|
50
50
|
|
|
51
51
|
@Controller('/auth')
|
|
52
|
+
@UseGuards(ThrottlerGuard)
|
|
52
53
|
class AuthController {
|
|
53
54
|
@Post('/login')
|
|
54
55
|
@Throttle({ ttl: 60, limit: 5 }) // 오버라이드: 분당 5회 요청
|
|
@@ -101,8 +102,14 @@ ThrottlerModule.forRoot({
|
|
|
101
102
|
ttl: 60,
|
|
102
103
|
limit: 100,
|
|
103
104
|
keyGenerator: (context) => {
|
|
104
|
-
const
|
|
105
|
-
|
|
105
|
+
const apiKeyHeader = context.request.headers['x-api-key'];
|
|
106
|
+
const apiKey = Array.isArray(apiKeyHeader) ? apiKeyHeader[0] : apiKeyHeader;
|
|
107
|
+
|
|
108
|
+
if (!apiKey) {
|
|
109
|
+
throw new Error('Missing API key for throttler tracking.');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return `api-key:${apiKey}`;
|
|
106
113
|
},
|
|
107
114
|
});
|
|
108
115
|
```
|
|
@@ -110,7 +117,7 @@ ThrottlerModule.forRoot({
|
|
|
110
117
|
## 공개 API 개요
|
|
111
118
|
|
|
112
119
|
### 모듈
|
|
113
|
-
- `ThrottlerModule.forRoot(options)`:
|
|
120
|
+
- `ThrottlerModule.forRoot(options)`: throttler 옵션, 저장소, `ThrottlerGuard`를 모듈 그래프에 제공합니다.
|
|
114
121
|
- 패키지 수준 등록은 `ThrottlerModule.forRoot(options)`를 통해 지원합니다. 내부 프로바이더 조합 헬퍼는 공개 계약에 포함되지 않습니다.
|
|
115
122
|
|
|
116
123
|
### 데코레이터
|
|
@@ -118,7 +125,7 @@ ThrottlerModule.forRoot({
|
|
|
118
125
|
- `@SkipThrottle()`: 클래스나 메서드에 대해 속도 제한을 비활성화합니다.
|
|
119
126
|
|
|
120
127
|
### 가드
|
|
121
|
-
- `ThrottlerGuard`: 속도 제한을 강제하는 가드입니다. `ThrottlerModule.forRoot()`
|
|
128
|
+
- `ThrottlerGuard`: 속도 제한을 강제하는 가드입니다. `ThrottlerModule.forRoot()`는 이를 주입 가능하게 만들며, 라우트 핸들러는 `@UseGuards(ThrottlerGuard)` 같은 Fluo guard metadata로 직접 활성화해야 합니다.
|
|
122
129
|
|
|
123
130
|
### 저장소(Store)
|
|
124
131
|
- `createMemoryThrottlerStore()`: 간단한 메모리 내 저장소를 생성합니다 (기본값).
|
package/README.md
CHANGED
|
@@ -31,12 +31,12 @@ npm install @fluojs/throttler
|
|
|
31
31
|
|
|
32
32
|
## Quick Start
|
|
33
33
|
|
|
34
|
-
Register the `ThrottlerModule` and apply the `Throttle` decorator to
|
|
34
|
+
Register the `ThrottlerModule`, wire `ThrottlerGuard` with `@UseGuards(...)`, and apply the `Throttle` decorator to controllers or methods that need route-specific limits.
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
import { Module } from '@fluojs/core';
|
|
38
|
-
import { ThrottlerModule, Throttle, SkipThrottle } from '@fluojs/throttler';
|
|
39
|
-
import { Controller, Post } from '@fluojs/http';
|
|
38
|
+
import { ThrottlerGuard, ThrottlerModule, Throttle, SkipThrottle } from '@fluojs/throttler';
|
|
39
|
+
import { Controller, Post, UseGuards } from '@fluojs/http';
|
|
40
40
|
|
|
41
41
|
@Module({
|
|
42
42
|
imports: [
|
|
@@ -49,6 +49,7 @@ import { Controller, Post } from '@fluojs/http';
|
|
|
49
49
|
class AppModule {}
|
|
50
50
|
|
|
51
51
|
@Controller('/auth')
|
|
52
|
+
@UseGuards(ThrottlerGuard)
|
|
52
53
|
class AuthController {
|
|
53
54
|
@Post('/login')
|
|
54
55
|
@Throttle({ ttl: 60, limit: 5 }) // Override: 5 requests per minute
|
|
@@ -101,8 +102,14 @@ ThrottlerModule.forRoot({
|
|
|
101
102
|
ttl: 60,
|
|
102
103
|
limit: 100,
|
|
103
104
|
keyGenerator: (context) => {
|
|
104
|
-
const
|
|
105
|
-
|
|
105
|
+
const apiKeyHeader = context.request.headers['x-api-key'];
|
|
106
|
+
const apiKey = Array.isArray(apiKeyHeader) ? apiKeyHeader[0] : apiKeyHeader;
|
|
107
|
+
|
|
108
|
+
if (!apiKey) {
|
|
109
|
+
throw new Error('Missing API key for throttler tracking.');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return `api-key:${apiKey}`;
|
|
106
113
|
},
|
|
107
114
|
});
|
|
108
115
|
```
|
|
@@ -110,7 +117,7 @@ ThrottlerModule.forRoot({
|
|
|
110
117
|
## Public API Overview
|
|
111
118
|
|
|
112
119
|
### Modules
|
|
113
|
-
- `ThrottlerModule.forRoot(options)`:
|
|
120
|
+
- `ThrottlerModule.forRoot(options)`: Provides throttler options, storage, and `ThrottlerGuard` to the module graph.
|
|
114
121
|
- Package-level registration is supported through `ThrottlerModule.forRoot(options)`. Internal provider-composition helpers are not part of the public contract.
|
|
115
122
|
|
|
116
123
|
### Decorators
|
|
@@ -118,7 +125,7 @@ ThrottlerModule.forRoot({
|
|
|
118
125
|
- `@SkipThrottle()`: Disables throttling for a class or method.
|
|
119
126
|
|
|
120
127
|
### Guards
|
|
121
|
-
- `ThrottlerGuard`: The guard responsible for enforcing
|
|
128
|
+
- `ThrottlerGuard`: The guard responsible for enforcing rate limits. `ThrottlerModule.forRoot()` makes it injectable; route handlers still activate it through Fluo guard metadata such as `@UseGuards(ThrottlerGuard)`.
|
|
122
129
|
|
|
123
130
|
### Stores
|
|
124
131
|
- `createMemoryThrottlerStore()`: Creates a simple in-memory store (default).
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"redis",
|
|
10
10
|
"decorator"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.0-beta.
|
|
12
|
+
"version": "1.0.0-beta.2",
|
|
13
13
|
"private": false,
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@fluojs/core": "^1.0.0-beta.1",
|
|
40
|
-
"@fluojs/
|
|
41
|
-
"@fluojs/
|
|
42
|
-
"@fluojs/
|
|
40
|
+
"@fluojs/di": "^1.0.0-beta.2",
|
|
41
|
+
"@fluojs/http": "^1.0.0-beta.1",
|
|
42
|
+
"@fluojs/runtime": "^1.0.0-beta.2"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"ioredis": "^5.0.0",
|
|
46
|
-
"@fluojs/redis": "^1.0.0-beta.
|
|
46
|
+
"@fluojs/redis": "^1.0.0-beta.2"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"@fluojs/redis": {
|