@@ -10,13 +10,15 @@ export interface ProxyConfigurationFunction {
1010 ( sessionId : string | number , options ?: { request ?: Request } ) : string | null | Promise < string | null > ;
1111}
1212
13+ type UrlList = ( string | null ) [ ] ;
14+
1315export interface ProxyConfigurationOptions {
1416 /**
1517 * An array of custom proxy URLs to be rotated.
1618 * Custom proxies are not compatible with Apify Proxy and an attempt to use both
1719 * configuration options will cause an error to be thrown on initialize.
1820 */
19- proxyUrls ?: string [ ] ;
21+ proxyUrls ?: UrlList ;
2022
2123 /**
2224 * Custom function that allows you to generate the new proxy URL dynamically. It gets the `sessionId` as a parameter and an optional parameter with the `Request` object when applicable.
@@ -37,7 +39,7 @@ export interface ProxyConfigurationOptions {
3739 *
3840 * Use `null` as a proxy URL to disable the proxy for the given tier.
3941 */
40- tieredProxyUrls ?: ( string | null ) [ ] [ ] ;
42+ tieredProxyUrls ?: UrlList [ ] ;
4143}
4244
4345export interface TieredProxy {
@@ -201,9 +203,9 @@ class ProxyTierTracker {
201203export class ProxyConfiguration {
202204 isManInTheMiddle = false ;
203205 protected nextCustomUrlIndex = 0 ;
204- protected proxyUrls ?: string [ ] ;
205- protected tieredProxyUrls ?: ( string | null ) [ ] [ ] ;
206- protected usedProxyUrls = new Map < string , string > ( ) ;
206+ protected proxyUrls ?: UrlList ;
207+ protected tieredProxyUrls ?: UrlList [ ] ;
208+ protected usedProxyUrls = new Map < string , string | null > ( ) ;
207209 protected newUrlFunction ?: ProxyConfigurationFunction ;
208210 protected log = log . child ( { prefix : 'ProxyConfiguration' } ) ;
209211 protected domainTiers = new Map < string , ProxyTierTracker > ( ) ;
@@ -233,7 +235,7 @@ export class ProxyConfiguration {
233235 ow (
234236 rest ,
235237 ow . object . exactShape ( {
236- proxyUrls : ow . optional . array . nonEmpty . ofType ( ow . string . url ) ,
238+ proxyUrls : ow . optional . array . nonEmpty . ofType ( ow . any ( ow . string . url , ow . null ) ) ,
237239 newUrlFunction : ow . optional . function ,
238240 tieredProxyUrls : ow . optional . array . nonEmpty . ofType (
239241 ow . array . nonEmpty . ofType ( ow . any ( ow . string . url , ow . null ) ) ,
@@ -389,14 +391,14 @@ export class ProxyConfiguration {
389391 return this . _handleTieredUrl ( sessionId ?? cryptoRandomObjectId ( 6 ) , options ) . proxyUrl ?? undefined ;
390392 }
391393
392- return this . _handleCustomUrl ( sessionId ) ;
394+ return this . _handleCustomUrl ( sessionId ) ?? undefined ;
393395 }
394396
395397 /**
396398 * Handles custom url rotation with session
397399 */
398- protected _handleCustomUrl ( sessionId ?: string ) : string {
399- let customUrlToUse : string ;
400+ protected _handleCustomUrl ( sessionId ?: string ) : string | null {
401+ let customUrlToUse : string | null ;
400402
401403 if ( ! sessionId ) {
402404 return this . proxyUrls ! [ this . nextCustomUrlIndex ++ % this . proxyUrls ! . length ] ;
0 commit comments