@jeffusion/bungee-types 4.1.0 → 4.3.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.
Files changed (2) hide show
  1. package/dist/types.d.ts +59 -11
  2. package/package.json +1 -1
package/dist/types.d.ts CHANGED
@@ -81,22 +81,28 @@ export interface Endpoint extends ModificationRules {
81
81
  description?: string;
82
82
  condition?: string;
83
83
  }
84
- export interface StickySessionConfig {
85
- enabled: boolean;
86
- key_expression?: string;
87
- }
88
84
  export interface RouteTimeoutsConfig {
89
- connect_ms?: number;
90
85
  request_ms?: number;
91
86
  }
87
+ /**
88
+ * Service-level transport timeouts.
89
+ * Describes how to connect to and exchange data with this pool of upstreams.
90
+ * Route-level request deadline (RouteTimeoutsConfig.request_ms) is unaffected.
91
+ */
92
+ export interface ServiceTimeoutsConfig {
93
+ connect_ms?: number;
94
+ send_ms?: number;
95
+ read_ms?: number;
96
+ }
92
97
  export interface FailoverPassiveHealthConfig {
93
98
  consecutive_failures?: number;
94
99
  healthy_successes?: number;
95
100
  auto_disable_threshold?: number;
96
- auto_enable_on_active_health_check?: boolean;
97
101
  }
98
102
  export interface FailoverRecoveryConfig {
99
- probe_interval_ms?: number;
103
+ /** UNHEALTHY 重新允许尝试的退避基准间隔(实际退避 = base × 2^recovery_attempt_count + 20% jitter) */
104
+ backoff_base_ms?: number;
105
+ /** HALF_OPEN/UNHEALTHY 状态下请求的超时切片 */
100
106
  probe_timeout_ms?: number;
101
107
  }
102
108
  export interface FailoverSlowStartConfig {
@@ -104,7 +110,11 @@ export interface FailoverSlowStartConfig {
104
110
  duration_ms?: number;
105
111
  initial_weight_factor?: number;
106
112
  }
107
- export interface FailoverHealthCheckConfig {
113
+ /**
114
+ * Service-level active health check configuration.
115
+ * Independent subsystem — no longer nested under FailoverConfig.
116
+ */
117
+ export interface ServiceHealthCheckConfig {
108
118
  enabled: boolean;
109
119
  interval_ms?: number;
110
120
  timeout_ms?: number;
@@ -117,21 +127,43 @@ export interface FailoverHealthCheckConfig {
117
127
  content_type?: string;
118
128
  headers?: Record<string, string>;
119
129
  query?: Record<string, string>;
130
+ /** 主动健康检查恢复后自动 re-enable 被 auto_disable 的 upstream */
131
+ auto_enable_on_active_health_check?: boolean;
132
+ }
133
+ export interface HashPolicyConfig {
134
+ /** 直接读 header 名作为 hash 输入(简单场景) */
135
+ header?: string;
136
+ /** 表达式返回值作为 hash 输入(可 access headers/body/url/method/env 全 context) */
137
+ expression?: string;
138
+ }
139
+ export interface LoadBalancingConfig {
140
+ policy: 'weighted_random' | 'round_robin' | 'least_requests' | 'consistent_hash';
141
+ /** 仅 policy='consistent_hash' 时有意义 */
142
+ hash_policy?: HashPolicyConfig;
120
143
  }
121
144
  export interface Service {
122
145
  name: string;
123
146
  endpoints: Endpoint[];
124
- health_check?: FailoverHealthCheckConfig;
147
+ plugins?: Array<PluginConfig | string>;
148
+ health_check?: ServiceHealthCheckConfig;
125
149
  failover?: FailoverConfig;
126
- sticky_session?: StickySessionConfig;
150
+ load_balancing?: LoadBalancingConfig;
151
+ timeouts?: ServiceTimeoutsConfig;
127
152
  }
128
153
  export interface FailoverConfig {
129
154
  enabled: boolean;
130
155
  retry_on?: number | string | (number | string)[];
156
+ /**
157
+ * 响应内容触发关键字列表(与 retry_on 为 OR 关系)。
158
+ * 任一关键字在响应体中出现即触发 failover(大小写敏感子串匹配)。
159
+ *
160
+ * 流式:first-peek 首 4KB / 首个 SSE event;非流式:完整 body(1MB 上限)。
161
+ * 中段(5KB 后)错误无配置层方案。
162
+ */
163
+ retry_on_response?: string[];
131
164
  passive_health?: FailoverPassiveHealthConfig;
132
165
  recovery?: FailoverRecoveryConfig;
133
166
  slow_start?: FailoverSlowStartConfig;
134
- health_check?: FailoverHealthCheckConfig;
135
167
  }
136
168
  export interface RateLimitConfig {
137
169
  enabled: boolean;
@@ -235,6 +267,22 @@ export interface PluginConfig {
235
267
  */
236
268
  enabled?: boolean;
237
269
  }
270
+ /** Plugin execution phase in the three-phase pipeline */
271
+ export type PluginPhase = 'route' | 'service' | 'upstream';
272
+ /**
273
+ * Result of onInterceptRequest hook.
274
+ * Distinguishes terminal short-circuit from failover trigger.
275
+ * - respond: terminal short-circuit, no failover
276
+ * - failover: trigger upstream switch (only valid in Phase 3/upstream)
277
+ * - undefined: continue normal flow
278
+ */
279
+ export type InterceptResult = {
280
+ action: 'respond';
281
+ response: Response;
282
+ } | {
283
+ action: 'failover';
284
+ reason?: string;
285
+ } | undefined;
238
286
  export interface AppConfig {
239
287
  config_version?: number;
240
288
  log_level?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeffusion/bungee-types",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "description": "TypeScript type definitions for Bungee",
5
5
  "main": "./dist/index.d.ts",
6
6
  "types": "./dist/index.d.ts",