22// Licensed under the MIT license.
33
44import { AppConfigurationClient , AppConfigurationClientOptions } from "@azure/app-configuration" ;
5- import { ConfigurationClientWrapper } from "./ConfigurationClientWrapper"
5+ import { ConfigurationClientWrapper } from "./ConfigurationClientWrapper" ;
66import { TokenCredential } from "@azure/identity" ;
77import { AzureAppConfigurationOptions , MaxRetries , MaxRetryDelayInMs } from "./AzureAppConfigurationOptions" ;
88import { isFailoverableEnv } from "./requestTracing/utils" ;
@@ -14,18 +14,18 @@ const TCP = "_tcp";
1414const EndpointSection = "Endpoint" ;
1515const IdSection = "Id" ;
1616const SecretSection = "Secret" ;
17- const AzConfigDomainLabel = ".azconfig."
18- const AppConfigDomainLabel = ".appconfig."
17+ const AzConfigDomainLabel = ".azconfig." ;
18+ const AppConfigDomainLabel = ".appconfig." ;
1919const FallbackClientRefreshExpireInterval = 60 * 60 * 1000 ; // 1 hour in milliseconds
2020const MinimalClientRefreshInterval = 30 * 1000 ; // 30 seconds in milliseconds
2121const SrvQueryTimeout = 5000 ; // 5 seconds
2222
2323interface IConfigurationClientManager {
24- getClients ( ) : ConfigurationClientWrapper [ ] ;
24+ getClients ( ) : Promise < ConfigurationClientWrapper [ ] > ;
2525 refreshClients ( ) : Promise < void > ;
2626}
2727
28- export class ConfigurationClientManager {
28+ export class ConfigurationClientManager implements IConfigurationClientManager {
2929 isFailoverable : boolean ;
3030 #endpoint: string ;
3131 #secret : string ;
@@ -55,7 +55,7 @@ export class ConfigurationClientManager {
5555 this . #id = parseConnectionString ( connectionString , IdSection ) ;
5656 // TODO: need to check if it's CDN or not
5757 this . #endpoint = parseConnectionString ( connectionString , EndpointSection ) ;
58-
58+
5959 } else if ( connectionStringOrEndpoint instanceof URL ) {
6060 const credential = credentialOrOptions as TokenCredential ;
6161 options = appConfigOptions as AzureAppConfigurationOptions ;
@@ -69,7 +69,7 @@ export class ConfigurationClientManager {
6969
7070 this . #staticClients = [ new ConfigurationClientWrapper ( this . #endpoint, staticClient ) ] ;
7171 this . #validDomain = getValidDomain ( this . #endpoint) ;
72- this . isFailoverable = ( options ?. replicaDiscoveryEnabled ?? true ) && isFailoverableEnv ( ) ;
72+ this . isFailoverable = ( options ?. replicaDiscoveryEnabled ?? true ) && isFailoverableEnv ( ) ;
7373 }
7474
7575 async getClients ( ) {
@@ -93,7 +93,7 @@ export class ConfigurationClientManager {
9393 . filter ( client => client . backoffEndTime <= currentTime ) ) ;
9494 }
9595
96- return availableClients
96+ return availableClients ;
9797 }
9898
9999 async refreshClients ( ) {
@@ -155,7 +155,7 @@ export class ConfigurationClientManager {
155155
156156 #isFallbackClientDiscoveryDue( dateTime ) {
157157 return dateTime >= this . #lastFallbackClientRefreshAttempt + MinimalClientRefreshInterval
158- && ( ! this . #dynamicClients
158+ && ( ! this . #dynamicClients
159159 || this . #dynamicClients. every ( client => dateTime < client . backoffEndTime )
160160 || dateTime >= this . #lastFallbackClientRefreshTime + FallbackClientRefreshExpireInterval ) ;
161161 }
@@ -171,7 +171,7 @@ async function querySrvTargetHost(host) {
171171 let dns ;
172172
173173 if ( isFailoverableEnv ( ) ) {
174- dns = require ( ' dns/promises' ) ;
174+ dns = require ( " dns/promises" ) ;
175175 } else {
176176 return results ;
177177 }
@@ -184,16 +184,18 @@ async function querySrvTargetHost(host) {
184184 }
185185
186186 // Add the first origin record to results
187- const originHost = originRecords [ 0 ] . name
187+ const originHost = originRecords [ 0 ] . name ;
188188 results . push ( originHost ) ;
189-
189+
190190 // Look up SRV records for alternate hosts
191191 let index = 0 ;
192- while ( true ) {
192+ let moreAltRecordsExist = true ;
193+ while ( moreAltRecordsExist ) {
193194 const currentAlt = `${ ALT } ${ index } ` ;
194195 try {
195196 const altRecords = await dns . resolveSrv ( `${ currentAlt } .${ TCP } .${ originHost } ` ) ;
196197 if ( altRecords . length === 0 ) {
198+ moreAltRecordsExist = false ;
197199 break ; // No more alternate records, exit loop
198200 }
199201
@@ -205,7 +207,7 @@ async function querySrvTargetHost(host) {
205207 } ) ;
206208 index ++ ;
207209 } catch ( err ) {
208- if ( err . code === ' ENOTFOUND' ) {
210+ if ( err . code === " ENOTFOUND" ) {
209211 break ; // No more alternate records, exit loop
210212 } else {
211213 throw new Error ( `Failed to lookup alternate SRV records: ${ err . message } ` ) ;
@@ -221,7 +223,7 @@ async function querySrvTargetHost(host) {
221223
222224/**
223225 * Parses the connection string to extract the value associated with a specific token.
224- *
226+ *
225227 * @param {string } connectionString - The connection string containing tokens.
226228 * @param {string } token - The token whose value needs to be extracted.
227229 * @returns {string } The value associated with the token, or an empty string if not found.
@@ -241,7 +243,7 @@ function parseConnectionString(connectionString, token) {
241243
242244 // Move startIndex to the beginning of the token value
243245 const valueStartIndex = startIndex + searchToken . length ;
244- const endIndex = connectionString . indexOf ( ';' , valueStartIndex ) ;
246+ const endIndex = connectionString . indexOf ( ";" , valueStartIndex ) ;
245247 const valueEndIndex = endIndex === - 1 ? connectionString . length : endIndex ;
246248
247249 // Extract and return the token value
@@ -251,15 +253,15 @@ function parseConnectionString(connectionString, token) {
251253/**
252254 * Builds a connection string from the given endpoint, secret, and id.
253255 * Returns an empty string if either secret or id is empty.
254- *
256+ *
255257 * @param {string } endpoint - The endpoint to include in the connection string.
256258 * @param {string } secret - The secret to include in the connection string.
257259 * @param {string } id - The ID to include in the connection string.
258260 * @returns {string } - The formatted connection string or an empty string if invalid input.
259261 */
260262function buildConnectionString ( endpoint , secret , id ) {
261263 if ( ! secret || ! id ) {
262- return '' ;
264+ return "" ;
263265 }
264266
265267 return `${ EndpointSection } =${ endpoint } ;${ IdSection } =${ id } ;${ SecretSection } =${ secret } ` ;
@@ -276,7 +278,7 @@ function getValidDomain(endpoint) {
276278 const url = new URL ( endpoint ) ;
277279 const trustedDomainLabels = [ AzConfigDomainLabel , AppConfigDomainLabel ] ;
278280 const host = url . hostname . toLowerCase ( ) ;
279-
281+
280282 for ( const label of trustedDomainLabels ) {
281283 const index = host . lastIndexOf ( label ) ;
282284 if ( index !== - 1 ) {
@@ -292,7 +294,7 @@ function getValidDomain(endpoint) {
292294
293295/**
294296 * Checks if the given host ends with the valid domain.
295- *
297+ *
296298 * @param {string } host - The host to be validated.
297299 * @param {string } validDomain - The valid domain to check against.
298300 * @returns {boolean } - True if the host ends with the valid domain, false otherwise.
@@ -317,7 +319,7 @@ export function getClientOptions(options?: AzureAppConfigurationOptions): AppCon
317319 const defaultRetryOptions = {
318320 maxRetries : MaxRetries ,
319321 maxRetryDelayInMs : MaxRetryDelayInMs ,
320- }
322+ } ;
321323 const retryOptions = Object . assign ( { } , defaultRetryOptions , options ?. clientOptions ?. retryOptions ) ;
322324
323325 return Object . assign ( { } , options ?. clientOptions , {
0 commit comments