Skip to content

Commit a2d2782

Browse files
update
1 parent 90d0727 commit a2d2782

File tree

5 files changed

+23
-36
lines changed

5 files changed

+23
-36
lines changed

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export default defineConfig([globalIgnores([
5353
}],
5454

5555
"@typescript-eslint/no-explicit-any": "off",
56-
"@typescript-eslint/no-require-imports": "off",
5756
"eol-last": ["error", "always"],
5857
"no-trailing-spaces": "error",
5958
"space-before-blocks": ["error", "always"],

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"playwright": "^1.55.0"
6767
},
6868
"dependencies": {
69-
"@azure/app-configuration": "^1.9.0",
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: 10 additions & 29 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,
@@ -57,7 +60,7 @@ import { AIConfigurationTracingOptions } from "./requestTracing/aiConfigurationT
5760
import { KeyFilter, LabelFilter, SettingWatcher, SettingSelector, PagedSettingsWatcher, WatchedSetting } from "./types.js";
5861
import { ConfigurationClientManager } from "./configurationClientManager.js";
5962
import { getFixedBackoffDuration, getExponentialBackoffDuration } from "./common/backoffUtils.js";
60-
import { InvalidOperationError, ArgumentError, isFailoverableError, isInputError } from "./common/errors.js";
63+
import { InvalidOperationError, ArgumentError, isFailoverableError, isInputError, SnapshotReferenceError } from "./common/errors.js";
6164
import { ErrorMessages } from "./common/errorMessages.js";
6265

6366
const MIN_DELAY_FOR_UNHANDLED_FAILURE = 5_000; // 5 seconds
@@ -513,8 +516,11 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
513516
if (isSnapshotReference(setting) && !loadFeatureFlag) {
514517
this.#useSnapshotReference = true;
515518

516-
// TODO: When SDK supports snapshot reference, use the helper method from SDK.
517-
const snapshotName = parseSnapshotReference(setting).value.snapshotName;
519+
const snapshotRef: ConfigurationSetting<SnapshotReferenceValue> = parseSnapshotReference(setting);
520+
const snapshotName = snapshotRef.value.snapshotName;
521+
if (!snapshotName) {
522+
throw new SnapshotReferenceError(`Invalid format for Snapshot reference setting '${setting.key}'.`);
523+
}
518524
const settingsFromSnapshot = await this.#loadConfigurationSettingsFromSnapshot(snapshotName);
519525

520526
for (const snapshotSetting of settingsFromSnapshot) {
@@ -589,7 +595,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
589595
async #loadConfigurationSettingsFromSnapshot(snapshotName: string): Promise<ConfigurationSetting[]> {
590596
const snapshot = await this.#getSnapshot(snapshotName);
591597
if (snapshot === undefined) {
592-
throw new InvalidOperationError(`Could not find snapshot with name ${snapshotName}.`);
598+
return []; // treat non-existing snapshot as empty
593599
}
594600
if (snapshot.compositionType != KnownSnapshotComposition.Key) {
595601
throw new InvalidOperationError(`Composition type for the selected snapshot with name ${snapshotName} must be 'key'.`);
@@ -1094,28 +1100,3 @@ function validateTagFilters(tagFilters: string[]): void {
10941100
}
10951101
}
10961102
}
1097-
1098-
// TODO: Temporary workaround until SDK supports snapshot reference
1099-
const snapshotReferenceContentType = "application/json; profile=\"https://azconfig.io/mime-profiles/snapshot-ref\"; charset=utf-8";
1100-
1101-
interface JsonSnapshotReferenceValue {
1102-
snapshot_name: string;
1103-
}
1104-
1105-
function isSnapshotReference(setting: ConfigurationSetting):
1106-
setting is ConfigurationSetting & Required<Pick<ConfigurationSetting, "value">> {
1107-
return (setting && setting.contentType === snapshotReferenceContentType && typeof setting.value === "string");
1108-
}
1109-
1110-
function parseSnapshotReference(setting: ConfigurationSetting) {
1111-
if (!isSnapshotReference(setting)) {
1112-
throw new Error(`Invalid snapshot reference: ${setting}`);
1113-
}
1114-
const jsonSnapshotReferenceValue = JSON.parse(setting.value) as JsonSnapshotReferenceValue;
1115-
1116-
const snapshotReference = {
1117-
...setting,
1118-
value: { snapshotName: jsonSnapshotReferenceValue.snapshot_name },
1119-
};
1120-
return snapshotReference;
1121-
}

src/common/errors.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ export class KeyVaultReferenceError extends Error {
3333
}
3434
}
3535

36+
export class SnapshotReferenceError extends Error {
37+
constructor(message: string, options?: ErrorOptions) {
38+
super(message, options);
39+
this.name = "SnapshotReferenceError";
40+
}
41+
}
42+
3643
export function isFailoverableError(error: any): boolean {
3744
if (!isRestError(error)) {
3845
return false;

0 commit comments

Comments
 (0)