@jeffusion/bungee-types 2.0.0
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 +61 -0
- package/dist/index.d.ts +1 -0
- package/dist/types.d.ts +120 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @jeffusion/bungee-types
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for [Bungee](https://github.com/jeffusion/bungee) - a high-performance reverse proxy server.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @jeffusion/bungee-types
|
|
9
|
+
# or
|
|
10
|
+
bun add @jeffusion/bungee-types
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import type { AppConfig, RouteConfig, AuthConfig } from '@jeffusion/bungee-types';
|
|
17
|
+
|
|
18
|
+
const config: AppConfig = {
|
|
19
|
+
routes: [
|
|
20
|
+
{
|
|
21
|
+
path: '/api',
|
|
22
|
+
upstreams: [
|
|
23
|
+
{ target: 'http://localhost:3000' }
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Available Types
|
|
31
|
+
|
|
32
|
+
### Core Configuration Types
|
|
33
|
+
- `AppConfig` - Main application configuration
|
|
34
|
+
- `RouteConfig` - Route configuration with upstreams and plugins
|
|
35
|
+
- `AuthConfig` - Authentication configuration
|
|
36
|
+
- `Upstream` - Upstream server configuration
|
|
37
|
+
|
|
38
|
+
### Modification and Plugin Types
|
|
39
|
+
- `ModificationRules` - Request/response modification rules
|
|
40
|
+
- `PluginConfig` - Plugin configuration
|
|
41
|
+
- `LoggingConfig` - Logging configuration
|
|
42
|
+
|
|
43
|
+
## Type Exports
|
|
44
|
+
|
|
45
|
+
### Default Export
|
|
46
|
+
```typescript
|
|
47
|
+
import type { AppConfig } from '@jeffusion/bungee-types';
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Type-Only Export
|
|
51
|
+
```typescript
|
|
52
|
+
import type { RouteConfig } from '@jeffusion/bungee-types/types';
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Documentation
|
|
56
|
+
|
|
57
|
+
For full documentation, visit [Bungee Documentation](https://github.com/jeffusion/bungee).
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export interface ModificationRules {
|
|
2
|
+
headers?: {
|
|
3
|
+
add?: Record<string, string>;
|
|
4
|
+
replace?: Record<string, string>;
|
|
5
|
+
remove?: string[];
|
|
6
|
+
};
|
|
7
|
+
body?: {
|
|
8
|
+
add?: Record<string, any>;
|
|
9
|
+
replace?: Record<string, any>;
|
|
10
|
+
remove?: string[];
|
|
11
|
+
default?: Record<string, any>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Token 认证配置
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // 简单 token 验证
|
|
19
|
+
* {
|
|
20
|
+
* "enabled": true,
|
|
21
|
+
* "tokens": ["{{ env.API_TOKEN }}"]
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // 多 token 支持(多租户场景)
|
|
26
|
+
* {
|
|
27
|
+
* "enabled": true,
|
|
28
|
+
* "tokens": [
|
|
29
|
+
* "{{ env.TENANT_A_TOKEN }}",
|
|
30
|
+
* "{{ env.TENANT_B_TOKEN }}",
|
|
31
|
+
* "hardcoded-dev-token"
|
|
32
|
+
* ]
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* 行为说明:
|
|
36
|
+
* - 从 Authorization header 提取 token(支持 "Bearer <token>" 或直接 "<token>")
|
|
37
|
+
* - 使用恒定时间比较进行 token 验证(防止时序攻击)
|
|
38
|
+
* - 认证通过后,自动移除 Authorization header(不会转发给 upstream)
|
|
39
|
+
*/
|
|
40
|
+
export interface AuthConfig {
|
|
41
|
+
/**
|
|
42
|
+
* 是否启用认证
|
|
43
|
+
*/
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* 有效的 token 列表(支持表达式)
|
|
47
|
+
* 支持多个 token,适用于多租户、多客户端场景
|
|
48
|
+
* 示例: ["{{ env.API_TOKEN }}", "sk-1234567890"]
|
|
49
|
+
*/
|
|
50
|
+
tokens: string[];
|
|
51
|
+
}
|
|
52
|
+
export interface Upstream extends ModificationRules {
|
|
53
|
+
target: string;
|
|
54
|
+
weight?: number;
|
|
55
|
+
priority?: number;
|
|
56
|
+
plugins?: Array<PluginConfig | string>;
|
|
57
|
+
}
|
|
58
|
+
export interface RouteConfig extends ModificationRules {
|
|
59
|
+
path: string;
|
|
60
|
+
pathRewrite?: Record<string, string>;
|
|
61
|
+
auth?: AuthConfig;
|
|
62
|
+
plugins?: Array<PluginConfig | string>;
|
|
63
|
+
upstreams: Upstream[];
|
|
64
|
+
failover?: {
|
|
65
|
+
enabled: boolean;
|
|
66
|
+
retryableStatusCodes: number[];
|
|
67
|
+
consecutiveFailuresThreshold?: number;
|
|
68
|
+
recoveryIntervalMs?: number;
|
|
69
|
+
recoveryTimeoutMs?: number;
|
|
70
|
+
healthyThreshold?: number;
|
|
71
|
+
requestTimeoutMs?: number;
|
|
72
|
+
connectTimeoutMs?: number;
|
|
73
|
+
slowStart?: {
|
|
74
|
+
enabled: boolean;
|
|
75
|
+
durationMs?: number;
|
|
76
|
+
initialWeightFactor?: number;
|
|
77
|
+
};
|
|
78
|
+
healthCheck?: {
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
intervalMs?: number;
|
|
81
|
+
timeoutMs?: number;
|
|
82
|
+
path?: string;
|
|
83
|
+
method?: string;
|
|
84
|
+
expectedStatus?: number[];
|
|
85
|
+
unhealthyThreshold?: number;
|
|
86
|
+
healthyThreshold?: number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface LoggingConfig {
|
|
91
|
+
body?: {
|
|
92
|
+
enabled: boolean;
|
|
93
|
+
maxSize: number;
|
|
94
|
+
retentionDays: number;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Plugin 配置
|
|
99
|
+
*/
|
|
100
|
+
export interface PluginConfig {
|
|
101
|
+
/**
|
|
102
|
+
* Plugin 文件路径(绝对路径或相对于配置文件的路径)
|
|
103
|
+
*/
|
|
104
|
+
path: string;
|
|
105
|
+
/**
|
|
106
|
+
* 传递给 Plugin 的初始化选项
|
|
107
|
+
*/
|
|
108
|
+
options?: Record<string, any>;
|
|
109
|
+
/**
|
|
110
|
+
* Plugin 是否启用(默认 true)
|
|
111
|
+
*/
|
|
112
|
+
enabled?: boolean;
|
|
113
|
+
}
|
|
114
|
+
export interface AppConfig {
|
|
115
|
+
bodyParserLimit?: string;
|
|
116
|
+
auth?: AuthConfig;
|
|
117
|
+
logging?: LoggingConfig;
|
|
118
|
+
plugins?: Array<PluginConfig | string>;
|
|
119
|
+
routes: RouteConfig[];
|
|
120
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jeffusion/bungee-types",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "TypeScript type definitions for Bungee",
|
|
5
|
+
"main": "./dist/index.d.ts",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "bun run build",
|
|
10
|
+
"test": "echo 'No tests for types package yet'"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./types": {
|
|
17
|
+
"types": "./dist/types.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"bungee",
|
|
22
|
+
"types",
|
|
23
|
+
"typescript"
|
|
24
|
+
],
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/",
|
|
27
|
+
"*.ts",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"bun-types": "^1.3.2",
|
|
33
|
+
"typescript": "^5.7.2"
|
|
34
|
+
}
|
|
35
|
+
}
|