@@ -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
5760import { KeyFilter , LabelFilter , SettingWatcher , SettingSelector , PagedSettingsWatcher , WatchedSetting } from "./types.js" ;
5861import { ConfigurationClientManager } from "./configurationClientManager.js" ;
5962import { 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" ;
6164import { ErrorMessages } from "./common/errorMessages.js" ;
6265
6366const 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- }
0 commit comments