44import { AppConfigurationClient , AppConfigurationClientOptions } from "@azure/app-configuration" ;
55import { ConfigurationClientWrapper } from "./ConfigurationClientWrapper.js" ;
66import { TokenCredential } from "@azure/identity" ;
7- import { AzureAppConfigurationOptions , MaxRetries , MaxRetryDelayInMs } from "./AzureAppConfigurationOptions.js" ;
7+ import { AzureAppConfigurationOptions } from "./AzureAppConfigurationOptions.js" ;
88import { isBrowser , isWebWorker } from "./requestTracing/utils.js" ;
99import * as RequestTracing from "./requestTracing/constants.js" ;
10- import { shuffleList } from "./common/utils.js" ;
10+ import { shuffleList , instanceOfTokenCredential } from "./common/utils.js" ;
11+ import { ArgumentError } from "./common/error.js" ;
12+
13+ // Configuration client retry options
14+ const CLIENT_MAX_RETRIES = 2 ;
15+ const CLIENT_MAX_RETRY_DELAY = 60_000 ; // 1 minute in milliseconds
1116
1217const TCP_ORIGIN_KEY_NAME = "_origin._tcp" ;
1318const ALT_KEY_NAME = "_alt" ;
@@ -54,18 +59,18 @@ export class ConfigurationClientManager {
5459 const regexMatch = connectionString . match ( ConnectionStringRegex ) ;
5560 if ( regexMatch ) {
5661 const endpointFromConnectionStr = regexMatch [ 1 ] ;
57- this . endpoint = getValidUrl ( endpointFromConnectionStr ) ;
62+ this . endpoint = new URL ( endpointFromConnectionStr ) ;
5863 this . #id = regexMatch [ 2 ] ;
5964 this . #secret = regexMatch [ 3 ] ;
6065 } else {
61- throw new Error ( `Invalid connection string. Valid connection strings should match the regex '${ ConnectionStringRegex . source } '.` ) ;
66+ throw new ArgumentError ( `Invalid connection string. Valid connection strings should match the regex '${ ConnectionStringRegex . source } '.` ) ;
6267 }
6368 staticClient = new AppConfigurationClient ( connectionString , this . #clientOptions) ;
6469 } else if ( ( connectionStringOrEndpoint instanceof URL || typeof connectionStringOrEndpoint === "string" ) && credentialPassed ) {
6570 let endpoint = connectionStringOrEndpoint ;
6671 // ensure string is a valid URL.
6772 if ( typeof endpoint === "string" ) {
68- endpoint = getValidUrl ( endpoint ) ;
73+ endpoint = new URL ( endpoint ) ;
6974 }
7075
7176 const credential = credentialOrOptions as TokenCredential ;
@@ -75,7 +80,7 @@ export class ConfigurationClientManager {
7580 this . #credential = credential ;
7681 staticClient = new AppConfigurationClient ( this . endpoint . origin , this . #credential, this . #clientOptions) ;
7782 } else {
78- throw new Error ( "A connection string or an endpoint with credential must be specified to create a client." ) ;
83+ throw new ArgumentError ( "A connection string or an endpoint with credential must be specified to create a client." ) ;
7984 }
8085
8186 this . #staticClients = [ new ConfigurationClientWrapper ( this . endpoint . origin , staticClient ) ] ;
@@ -200,12 +205,12 @@ export class ConfigurationClientManager {
200205 } ) ;
201206 index ++ ;
202207 }
203- } catch ( err ) {
204- if ( err . code === "ENOTFOUND" ) {
208+ } catch ( error ) {
209+ if ( error . code === "ENOTFOUND" ) {
205210 // No more SRV records found, return results.
206211 return results ;
207212 } else {
208- throw new Error ( `Failed to lookup SRV records: ${ err . message } ` ) ;
213+ throw new Error ( `Failed to lookup SRV records: ${ error . message } ` ) ;
209214 }
210215 }
211216
@@ -260,8 +265,8 @@ function getClientOptions(options?: AzureAppConfigurationOptions): AppConfigurat
260265
261266 // retry options
262267 const defaultRetryOptions = {
263- maxRetries : MaxRetries ,
264- maxRetryDelayInMs : MaxRetryDelayInMs ,
268+ maxRetries : CLIENT_MAX_RETRIES ,
269+ maxRetryDelayInMs : CLIENT_MAX_RETRY_DELAY ,
265270 } ;
266271 const retryOptions = Object . assign ( { } , defaultRetryOptions , options ?. clientOptions ?. retryOptions ) ;
267272
@@ -272,20 +277,3 @@ function getClientOptions(options?: AzureAppConfigurationOptions): AppConfigurat
272277 }
273278 } ) ;
274279}
275-
276- function getValidUrl ( endpoint : string ) : URL {
277- try {
278- return new URL ( endpoint ) ;
279- } catch ( error ) {
280- if ( error . code === "ERR_INVALID_URL" ) {
281- throw new Error ( "Invalid endpoint URL." , { cause : error } ) ;
282- } else {
283- throw error ;
284- }
285- }
286- }
287-
288- export function instanceOfTokenCredential ( obj : unknown ) {
289- return obj && typeof obj === "object" && "getToken" in obj && typeof obj . getToken === "function" ;
290- }
291-
0 commit comments