66import type { ProxyConfig } from '@frp-bridge/types'
77import type { RuntimeLogger } from '../../runtime'
88import type { ConfigurationStore , FrpConfig } from './configuration-store'
9- import { ProxyType } from '@frp-bridge/types'
109import { ConfigInvalidError , NotFoundError } from '../../errors'
1110import { createLogger } from '../../logging'
11+ import { typeUsesRemotePort } from '../../utils'
1212
1313/**
1414 * Extended config type that includes proxies array
@@ -82,15 +82,15 @@ export class TunnelManager {
8282
8383 // Handle [[proxies]] array syntax
8484 if ( Array . isArray ( config . proxies ) ) {
85- const tunnel = config . proxies . find ( ( p : any ) => p && p . name === name ) as ProxyConfig || null
85+ const tunnel = config . proxies . find ( p => p && p . name === name ) || null
8686 if ( ! tunnel ) {
8787 this . log . debug ( 'Tunnel not found in proxies array' , { name } )
8888 }
8989 return tunnel
9090 }
9191
9292 // Handle legacy format
93- return ( config as any ) [ name ] as ProxyConfig || null
93+ return ( config as Record < string , unknown > ) [ name ] as ProxyConfig || null
9494 }
9595
9696 /**
@@ -104,7 +104,7 @@ export class TunnelManager {
104104
105105 // Handle [[proxies]] array syntax
106106 if ( Array . isArray ( config . proxies ) ) {
107- const tunnelIndex = config . proxies . findIndex ( ( p : any ) => p && p . name === name )
107+ const tunnelIndex = config . proxies . findIndex ( p => p && p . name === name )
108108 if ( tunnelIndex === - 1 ) {
109109 throw new NotFoundError ( `Tunnel ${ name } not found` )
110110 }
@@ -113,16 +113,17 @@ export class TunnelManager {
113113 const updatedTunnel = { ...existingTunnel , ...proxy }
114114
115115 // Check remotePort conflict if changed
116- const newRemotePort = ( proxy as any ) . remotePort
117- if ( newRemotePort && newRemotePort !== ( existingTunnel as any ) . remotePort ) {
118- this . validateRemotePort ( config . proxies , newRemotePort , ( updatedTunnel as any ) . type , tunnelIndex )
116+ const newRemotePort = proxy . remotePort
117+ if ( newRemotePort && newRemotePort !== existingTunnel . remotePort ) {
118+ this . validateRemotePort ( config . proxies , newRemotePort , updatedTunnel . type , tunnelIndex )
119119 }
120120
121121 config . proxies [ tunnelIndex ] = updatedTunnel
122122 }
123123 // Handle legacy format
124- else if ( ( config as any ) [ name ] ) {
125- ; ( config as any ) [ name ] = { ...( config as any ) [ name ] , ...proxy }
124+ else if ( ( config as Record < string , unknown > ) [ name ] ) {
125+ const existing = ( config as Record < string , unknown > ) [ name ] as ProxyConfig
126+ ; ( config as Record < string , unknown > ) [ name ] = { ...existing , ...proxy }
126127 }
127128 else {
128129 throw new NotFoundError ( `Tunnel ${ name } not found` )
@@ -147,7 +148,7 @@ export class TunnelManager {
147148
148149 // Handle [[proxies]] array syntax
149150 if ( Array . isArray ( config . proxies ) ) {
150- const tunnelIndex = config . proxies . findIndex ( ( p : any ) => p && p . name === name )
151+ const tunnelIndex = config . proxies . findIndex ( p => p && p . name === name )
151152 if ( tunnelIndex !== - 1 ) {
152153 config . proxies . splice ( tunnelIndex , 1 )
153154 modified = true
@@ -158,8 +159,8 @@ export class TunnelManager {
158159 }
159160 }
160161 // Handle legacy format
161- else if ( ( config as any ) [ name ] ) {
162- delete ( config as any ) [ name ]
162+ else if ( ( config as Record < string , unknown > ) [ name ] ) {
163+ delete ( config as Record < string , unknown > ) [ name ]
163164 modified = true
164165 this . log . success ( 'Tunnel removed' , { name } )
165166 }
@@ -194,12 +195,12 @@ export class TunnelManager {
194195 }
195196
196197 // Handle legacy format
197- const proxyKeys = new Set ( tunnels . map ( ( t : any ) => t . name ) )
198+ const proxyKeys = new Set ( tunnels . map ( t => t . name ) )
198199 for ( const [ key , value ] of Object . entries ( config ) ) {
199200 if ( key === 'proxies' )
200201 continue
201202 if ( typeof value === 'object' && value !== null && 'type' in value && ! Array . isArray ( value ) ) {
202- const proxy = { ...value , name : ( value as any ) . name || key } as ProxyConfig
203+ const proxy = { ...value , name : ( ( value as ProxyConfig ) . name ) || key } as ProxyConfig
203204 if ( ! proxyKeys . has ( proxy . name ) ) {
204205 tunnels . push ( proxy )
205206 proxyKeys . add ( proxy . name )
@@ -257,19 +258,19 @@ export class TunnelManager {
257258 /**
258259 * Validate tunnel uniqueness
259260 */
260- private validateUniqueness ( config : any , proxy : ProxyConfig ) : void {
261- const proxies = config . proxies || [ ]
261+ private validateUniqueness ( config : Record < string , unknown > , proxy : ProxyConfig ) : void {
262+ const proxies = ( config . proxies as ProxyConfig [ ] ) || [ ]
262263
263264 // Check name uniqueness
264- const existingName = proxies . find ( ( p : any ) => p && p . name === proxy . name )
265+ const existingName = proxies . find ( p => p && p . name === proxy . name )
265266 if ( existingName ) {
266267 this . log . warn ( 'Tunnel name already exists' , { name : proxy . name } )
267268 throw new ConfigInvalidError ( `Tunnel ${ proxy . name } already exists` )
268269 }
269270
270271 // Check remotePort conflict for types that use it
271- const proxyRemotePort = ( proxy as any ) . remotePort
272- if ( proxyRemotePort && this . typeUsesRemotePort ( proxy . type ) ) {
272+ const proxyRemotePort = proxy . remotePort
273+ if ( proxyRemotePort && typeUsesRemotePort ( proxy . type ) ) {
273274 this . validateRemotePort ( proxies , proxyRemotePort , proxy . type )
274275 }
275276
@@ -279,16 +280,16 @@ export class TunnelManager {
279280 /**
280281 * Validate remotePort conflict
281282 */
282- private validateRemotePort ( proxies : any [ ] , remotePort : number , type : string , excludeIndex = - 1 ) : void {
283- if ( ! this . typeUsesRemotePort ( type ) ) {
283+ private validateRemotePort ( proxies : ProxyConfig [ ] , remotePort : number , type : string , excludeIndex = - 1 ) : void {
284+ if ( ! typeUsesRemotePort ( type ) ) {
284285 return
285286 }
286287
287- const inUse = proxies . some ( ( p : any , idx : number ) => {
288+ const inUse = proxies . some ( ( p , idx ) => {
288289 if ( idx === excludeIndex )
289290 return false
290- const pRemotePort = ( p as any ) . remotePort
291- return p && pRemotePort === remotePort && this . typeUsesRemotePort ( p . type )
291+ const pRemotePort = p . remotePort
292+ return p && pRemotePort === remotePort && typeUsesRemotePort ( p . type )
292293 } )
293294
294295 if ( inUse ) {
@@ -298,18 +299,4 @@ export class TunnelManager {
298299
299300 this . log . debug ( 'Remote port validation passed' , { remotePort, type } )
300301 }
301-
302- /**
303- * Check if proxy type uses remotePort
304- */
305- private typeUsesRemotePort ( type : string ) : boolean {
306- return [
307- ProxyType . TCP ,
308- ProxyType . UDP ,
309- ProxyType . STCP ,
310- ProxyType . XTCP ,
311- ProxyType . SUDP ,
312- ProxyType . TCPMUX
313- ] . includes ( type as ProxyType )
314- }
315302}
0 commit comments