Skip to content

Commit 3d95750

Browse files
committed
resolve comments
1 parent 7483ad8 commit 3d95750

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

src/AzureAppConfigurationImpl.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,23 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
182182
}
183183

184184
async #executeWithFailoverPolicy(funcToExecute) {
185-
const clients = await this.#clientManager.getClients();
186-
if (clients.length === 0) {
185+
const clientWrappers = await this.#clientManager.getClients();
186+
if (clientWrappers.length === 0) {
187187
this.#clientManager.refreshClients();
188188
throw new Error("No client is available to connect to the target App Configuration store.");
189189
}
190190

191-
for (const client of clients) {
191+
for (const clientWrapper of clientWrappers) {
192192
let successful = false;
193193
try {
194-
const result = await funcToExecute(client.client);
194+
const result = await funcToExecute(clientWrapper.client);
195195
this.#isFailoverRequest = false;
196196
successful = true;
197-
updateClientBackoffStatus(client, successful);
197+
updateClientBackoffStatus(clientWrapper, successful);
198198
return result;
199199
} catch (error) {
200200
if (isFailoverableError(error)) {
201-
updateClientBackoffStatus(client, successful);
201+
updateClientBackoffStatus(clientWrapper, successful);
202202
this.#isFailoverRequest = true;
203203
continue;
204204
}
@@ -297,6 +297,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
297297
// Temporary map to store feature flags, key is the key of the setting, value is the raw value of the setting
298298
const funcToExecute = async (client) => {
299299
const featureFlagSettings: ConfigurationSetting[] = [];
300+
// deep copy selectors to avoid modification if current client fails
300301
const selectors = JSON.parse(
301302
JSON.stringify(this.#featureFlagSelectors)
302303
);

src/ConfigurationClientManager.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class ConfigurationClientManager implements IConfigurationClientManager {
7272
this.isFailoverable = (options?.replicaDiscoveryEnabled ?? true) && isFailoverableEnv();
7373
}
7474

75-
async getClients() {
75+
async getClients() : Promise<ConfigurationClientWrapper[]> {
7676
if (!this.isFailoverable) {
7777
return this.#staticClients;
7878
}
@@ -163,10 +163,8 @@ export class ConfigurationClientManager implements IConfigurationClientManager {
163163

164164
/**
165165
* Query SRV records and return target hosts.
166-
* @param {string} host - The host to query.
167-
* @returns {Promise<string[]>} - A promise that resolves to an array of target hosts.
168166
*/
169-
async function querySrvTargetHost(host) {
167+
async function querySrvTargetHost(host: string): Promise<string[]> {
170168
const results: string[] = [];
171169
let dns;
172170

@@ -227,13 +225,8 @@ async function querySrvTargetHost(host) {
227225

228226
/**
229227
* Parses the connection string to extract the value associated with a specific token.
230-
*
231-
* @param {string} connectionString - The connection string containing tokens.
232-
* @param {string} token - The token whose value needs to be extracted.
233-
* @returns {string} The value associated with the token, or an empty string if not found.
234-
* @throws {Error} If the connection string is empty or the token is not found.
235228
*/
236-
function parseConnectionString(connectionString, token) {
229+
function parseConnectionString(connectionString, token: string): string {
237230
if (!connectionString) {
238231
throw new Error("connectionString is empty");
239232
}
@@ -257,13 +250,8 @@ function parseConnectionString(connectionString, token) {
257250
/**
258251
* Builds a connection string from the given endpoint, secret, and id.
259252
* Returns an empty string if either secret or id is empty.
260-
*
261-
* @param {string} endpoint - The endpoint to include in the connection string.
262-
* @param {string} secret - The secret to include in the connection string.
263-
* @param {string} id - The ID to include in the connection string.
264-
* @returns {string} - The formatted connection string or an empty string if invalid input.
265253
*/
266-
function buildConnectionString(endpoint, secret, id) {
254+
function buildConnectionString(endpoint, secret, id: string): string {
267255
if (!secret || !id) {
268256
return "";
269257
}
@@ -273,11 +261,8 @@ function buildConnectionString(endpoint, secret, id) {
273261

274262
/**
275263
* Extracts a valid domain from the given endpoint URL based on trusted domain labels.
276-
*
277-
* @param {string} endpoint - The endpoint URL.
278-
* @returns {string} - The valid domain or an empty string if no valid domain is found.
279264
*/
280-
export function getValidDomain(endpoint) {
265+
export function getValidDomain(endpoint: string): string {
281266
try {
282267
const url = new URL(endpoint);
283268
const trustedDomainLabels = [AzConfigDomainLabel, AppConfigDomainLabel];
@@ -298,12 +283,8 @@ export function getValidDomain(endpoint) {
298283

299284
/**
300285
* Checks if the given host ends with the valid domain.
301-
*
302-
* @param {string} host - The host to be validated.
303-
* @param {string} validDomain - The valid domain to check against.
304-
* @returns {boolean} - True if the host ends with the valid domain, false otherwise.
305286
*/
306-
export function isValidEndpoint(host, validDomain) {
287+
export function isValidEndpoint(host: string, validDomain: string): boolean {
307288
if (!validDomain) {
308289
return false;
309290
}

0 commit comments

Comments
 (0)