@@ -48,11 +48,38 @@ export class AppConfigurationImporter {
4848 public async Import (
4949 configSettingsSource : ConfigurationSettingsSource ,
5050 timeout : number ,
51- strict = false ,
5251 progressCallback ?: ( progress : ImportProgress ) => unknown ,
53- importMode = ImportMode . IgnoreMatch
52+ strict ?: boolean ,
53+ importMode ?: ImportMode
54+ ) : Promise < void > ;
55+
56+ /**
57+ * Import pre-calculated configuration changes.
58+ * Use when changes were previously obtained via GetConfigurationChanges().
59+ *
60+ * Example usage:
61+ * ```ts
62+ * const changes = await importer.GetConfigurationChanges(source);
63+ * then:
64+ * await importer.Import(changes, 60);
65+ * ```
66+ * @param configurationChanges - Pre-calculated changes object.
67+ * @param timeout - Seconds of entire import progress timeout.
68+ * @param progressCallback - Callback to report progress of import.
69+ */
70+ public async Import (
71+ configurationChanges : ConfigurationChanges ,
72+ timeout : number ,
73+ progressCallback ?: ( progress : ImportProgress ) => unknown
74+ ) : Promise < void > ;
75+
76+ public async Import (
77+ configuration : ConfigurationSettingsSource | ConfigurationChanges ,
78+ timeout : number ,
79+ progressCallback ?: ( ( progress : ImportProgress ) => unknown ) ,
80+ strict : boolean = false ,
81+ importMode : ImportMode = ImportMode . IgnoreMatch
5482 ) : Promise < void > {
55- this . validateImportMode ( importMode ) ;
5683
5784 // Generate correlationRequestId for operations in the same activity
5885 const customCorrelationRequestId : string = uuidv4 ( ) ;
@@ -64,9 +91,16 @@ export class AppConfigurationImporter {
6491 }
6592 } ;
6693
67- const configurationChanges : ConfigurationChanges = await this . GetConfigurationChanges ( configSettingsSource , strict , importMode , customHeadersOption ) ;
94+ if ( this . isConfigurationChanges ( configuration ) ) {
95+ const configurationChanges = configuration as ConfigurationChanges ;
96+ return await this . applyUpdatesToServer ( [ ...configurationChanges . ToAdd , ...configurationChanges . ToModify ] , configurationChanges . ToDelete , timeout , customHeadersOption , progressCallback ) ;
97+ }
98+
99+ const source = configuration as ConfigurationSettingsSource ;
100+ this . validateImportMode ( importMode ) ;
68101
69- await this . applyUpdatesToServer ( [ ...configurationChanges . ToAdd , ...configurationChanges . ToModify ] , configurationChanges . ToDelete , timeout , customHeadersOption , progressCallback ) ;
102+ const configurationChanges : ConfigurationChanges = await this . GetConfigurationChanges ( source , strict , importMode , customHeadersOption ) ;
103+ return await this . applyUpdatesToServer ( [ ...configurationChanges . ToAdd , ...configurationChanges . ToModify ] , configurationChanges . ToDelete , timeout , customHeadersOption , progressCallback ) ;
70104 }
71105
72106 /**
@@ -206,4 +240,16 @@ export class AppConfigurationImporter {
206240 throw new ArgumentError ( "Only options supported for Import Mode are 'All' and 'Ignore-Match'." ) ;
207241 }
208242 }
243+
244+ /**
245+ * Type guard to detect a ConfigurationChanges object.
246+ * @internal
247+ */
248+ private isConfigurationChanges ( obj : unknown ) : obj is ConfigurationChanges {
249+ if ( obj === null || typeof obj !== "object" ) {
250+ return false ;
251+ }
252+ const configChanges = obj as Partial < ConfigurationChanges > ;
253+ return Array . isArray ( configChanges . ToAdd ) && Array . isArray ( configChanges . ToModify ) && Array . isArray ( configChanges . ToDelete ) ;
254+ }
209255}
0 commit comments