Skip to content

Commit f69a071

Browse files
Merge pull request #258 from Azure/preview
Merge preview to release/v2
2 parents 1b804dd + 76677d2 commit f69a071

File tree

15 files changed

+1224
-100
lines changed

15 files changed

+1224
-100
lines changed

examples/console-app/package-lock.json

Lines changed: 955 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/web-app/package-lock.json

Lines changed: 25 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 35 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/app-configuration-provider",
3-
"version": "2.3.0-preview",
3+
"version": "2.4.0-preview",
44
"description": "The JavaScript configuration provider for Azure App Configuration",
55
"files": [
66
"dist/",
@@ -66,7 +66,7 @@
6666
"playwright": "^1.55.0"
6767
},
6868
"dependencies": {
69-
"@azure/app-configuration": "^1.9.2",
69+
"@azure/app-configuration": "^1.10.0",
7070
"@azure/core-rest-pipeline": "^1.6.0",
7171
"@azure/identity": "^4.2.1",
7272
"@azure/keyvault-secrets": "^4.7.0",

src/appConfigurationImpl.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {
1111
featureFlagPrefix,
1212
isFeatureFlag,
1313
isSecretReference,
14+
isSnapshotReference,
15+
parseSnapshotReference,
16+
SnapshotReferenceValue,
1417
GetSnapshotOptions,
1518
ListConfigurationSettingsForSnapshotOptions,
1619
GetSnapshotResponse,
@@ -66,7 +69,7 @@ import { AIConfigurationTracingOptions } from "./requestTracing/aiConfigurationT
6669
import { KeyFilter, LabelFilter, SettingWatcher, SettingSelector, PagedSettingsWatcher, WatchedSetting } from "./types.js";
6770
import { ConfigurationClientManager } from "./configurationClientManager.js";
6871
import { getFixedBackoffDuration, getExponentialBackoffDuration } from "./common/backoffUtils.js";
69-
import { InvalidOperationError, ArgumentError, isFailoverableError, isInputError } from "./common/errors.js";
72+
import { InvalidOperationError, ArgumentError, isFailoverableError, isInputError, SnapshotReferenceError } from "./common/errors.js";
7073
import { ErrorMessages } from "./common/errorMessages.js";
7174
import { X_MS_DATE_HEADER } from "./afd/constants.js";
7275

@@ -92,6 +95,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
9295
#featureFlagTracing: FeatureFlagTracingOptions | undefined;
9396
#fmVersion: string | undefined;
9497
#aiConfigurationTracing: AIConfigurationTracingOptions | undefined;
98+
#useSnapshotReference: boolean = false;
9599

96100
// Refresh
97101
#refreshInProgress: boolean = false;
@@ -229,7 +233,8 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
229233
featureFlagTracing: this.#featureFlagTracing,
230234
fmVersion: this.#fmVersion,
231235
aiConfigurationTracing: this.#aiConfigurationTracing,
232-
isAfdUsed: this.#isAfdUsed
236+
isAfdUsed: this.#isAfdUsed,
237+
useSnapshotReference: this.#useSnapshotReference
233238
};
234239
}
235240

@@ -521,17 +526,29 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
521526
selector.pageWatchers = pageWatchers;
522527
settings = items;
523528
} else { // snapshot selector
524-
const snapshot = await this.#getSnapshot(selector.snapshotName);
525-
if (snapshot === undefined) {
526-
throw new InvalidOperationError(`Could not find snapshot with name ${selector.snapshotName}.`);
527-
}
528-
if (snapshot.compositionType != KnownSnapshotComposition.Key) {
529-
throw new InvalidOperationError(`Composition type for the selected snapshot with name ${selector.snapshotName} must be 'key'.`);
530-
}
531-
settings = await this.#listConfigurationSettingsForSnapshot(selector.snapshotName);
529+
settings = await this.#loadConfigurationSettingsFromSnapshot(selector.snapshotName);
532530
}
533531

534532
for (const setting of settings) {
533+
if (isSnapshotReference(setting) && !loadFeatureFlag) {
534+
this.#useSnapshotReference = true;
535+
536+
const snapshotRef: ConfigurationSetting<SnapshotReferenceValue> = parseSnapshotReference(setting);
537+
const snapshotName = snapshotRef.value.snapshotName;
538+
if (!snapshotName) {
539+
throw new SnapshotReferenceError(`Invalid format for Snapshot reference setting '${setting.key}'.`);
540+
}
541+
const settingsFromSnapshot = await this.#loadConfigurationSettingsFromSnapshot(snapshotName);
542+
543+
for (const snapshotSetting of settingsFromSnapshot) {
544+
if (!isFeatureFlag(snapshotSetting)) {
545+
// Feature flags inside snapshot are ignored. This is consistent the behavior that key value selectors ignore feature flags.
546+
loadedSettings.set(snapshotSetting.key, snapshotSetting);
547+
}
548+
}
549+
continue;
550+
}
551+
535552
if (loadFeatureFlag === isFeatureFlag(setting)) {
536553
loadedSettings.set(setting.key, setting);
537554
}
@@ -592,6 +609,18 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
592609
}
593610
}
594611

612+
async #loadConfigurationSettingsFromSnapshot(snapshotName: string): Promise<ConfigurationSetting[]> {
613+
const snapshot = await this.#getSnapshot(snapshotName);
614+
if (snapshot === undefined) {
615+
return []; // treat non-existing snapshot as empty
616+
}
617+
if (snapshot.compositionType != KnownSnapshotComposition.Key) {
618+
throw new InvalidOperationError(`Composition type for the selected snapshot with name ${snapshotName} must be 'key'.`);
619+
}
620+
const settings: ConfigurationSetting[] = await this.#listConfigurationSettingsForSnapshot(snapshotName);
621+
return settings;
622+
}
623+
595624
/**
596625
* Clears all existing key-values in the local configuration except feature flags.
597626
*/

0 commit comments

Comments
 (0)