@azure/app-configuration-importer 1.1.3-preview → 2.0.0-preview

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/index.js +178 -93
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/src/appConfigurationImporter.js +119 -65
  4. package/dist-esm/src/appConfigurationImporter.js.map +1 -1
  5. package/dist-esm/src/index.js +1 -0
  6. package/dist-esm/src/index.js.map +1 -1
  7. package/dist-esm/src/internal/parsers/configurationSettingsConverter.js.map +1 -1
  8. package/dist-esm/src/internal/parsers/defaultConfigurationSettingsConverter.js.map +1 -1
  9. package/dist-esm/src/internal/utils.js.map +1 -1
  10. package/dist-esm/src/models.js.map +1 -1
  11. package/dist-esm/src/{importOptions.js → options.js} +1 -1
  12. package/dist-esm/src/options.js.map +1 -0
  13. package/dist-esm/src/settingsImport/configurationChangesSource.js +33 -0
  14. package/dist-esm/src/settingsImport/configurationChangesSource.js.map +1 -0
  15. package/dist-esm/src/settingsImport/configurationSettingsSource.js.map +1 -1
  16. package/dist-esm/src/settingsImport/iterableConfigurationSettingsSource.js.map +1 -1
  17. package/dist-esm/src/settingsImport/readableStreamConfigurationSettingsSource.js.map +1 -1
  18. package/dist-esm/src/settingsImport/stringConfigurationSettingsSource.js.map +1 -1
  19. package/package.json +1 -1
  20. package/types/azure-app-configuration-importer.d.ts +93 -12
  21. package/types/src/appConfigurationImporter.d.ts +37 -10
  22. package/types/src/appConfigurationImporter.d.ts.map +1 -1
  23. package/types/src/index.d.ts +3 -2
  24. package/types/src/index.d.ts.map +1 -1
  25. package/types/src/internal/parsers/configurationSettingsConverter.d.ts +1 -1
  26. package/types/src/internal/parsers/configurationSettingsConverter.d.ts.map +1 -1
  27. package/types/src/internal/parsers/defaultConfigurationSettingsConverter.d.ts +1 -1
  28. package/types/src/internal/parsers/defaultConfigurationSettingsConverter.d.ts.map +1 -1
  29. package/types/src/internal/utils.d.ts +1 -1
  30. package/types/src/internal/utils.d.ts.map +1 -1
  31. package/types/src/models.d.ts +7 -0
  32. package/types/src/models.d.ts.map +1 -1
  33. package/types/src/{importOptions.d.ts → options.d.ts} +26 -3
  34. package/types/src/options.d.ts.map +1 -0
  35. package/types/src/settingsImport/configurationChangesSource.d.ts +27 -0
  36. package/types/src/settingsImport/configurationChangesSource.d.ts.map +1 -0
  37. package/types/src/settingsImport/configurationSettingsSource.d.ts +4 -3
  38. package/types/src/settingsImport/configurationSettingsSource.d.ts.map +1 -1
  39. package/types/src/settingsImport/iterableConfigurationSettingsSource.d.ts +1 -1
  40. package/types/src/settingsImport/iterableConfigurationSettingsSource.d.ts.map +1 -1
  41. package/types/src/settingsImport/readableStreamConfigurationSettingsSource.d.ts +1 -1
  42. package/types/src/settingsImport/readableStreamConfigurationSettingsSource.d.ts.map +1 -1
  43. package/types/src/settingsImport/stringConfigurationSettingsSource.d.ts +1 -1
  44. package/types/src/settingsImport/stringConfigurationSettingsSource.d.ts.map +1 -1
  45. package/dist-esm/src/importOptions.js.map +0 -1
  46. package/types/src/importOptions.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -417,34 +417,6 @@
417
417
  'default': _tslib
418
418
  });
419
419
 
420
- // Copyright (c) Microsoft Corporation.
421
- // Licensed under the MIT license.
422
- /**
423
- * Enums of configuration Format.
424
- */
425
- exports.ConfigurationFormat = void 0;
426
- (function (ConfigurationFormat) {
427
- ConfigurationFormat[ConfigurationFormat["Json"] = 0] = "Json";
428
- ConfigurationFormat[ConfigurationFormat["Properties"] = 1] = "Properties";
429
- ConfigurationFormat[ConfigurationFormat["Yaml"] = 2] = "Yaml";
430
- })(exports.ConfigurationFormat || (exports.ConfigurationFormat = {}));
431
- /**
432
- * Enums of configuration Profile.
433
- */
434
- exports.ConfigurationProfile = void 0;
435
- (function (ConfigurationProfile) {
436
- ConfigurationProfile[ConfigurationProfile["Default"] = 0] = "Default";
437
- ConfigurationProfile[ConfigurationProfile["KvSet"] = 1] = "KvSet";
438
- })(exports.ConfigurationProfile || (exports.ConfigurationProfile = {}));
439
- /**
440
- * Enums of import mode.
441
- */
442
- exports.ImportMode = void 0;
443
- (function (ImportMode) {
444
- ImportMode[ImportMode["All"] = 0] = "All";
445
- ImportMode[ImportMode["IgnoreMatch"] = 1] = "IgnoreMatch";
446
- })(exports.ImportMode || (exports.ImportMode = {}));
447
-
448
420
  // Copyright (c) Microsoft Corporation.
449
421
  // Licensed under the MIT license.
450
422
  /**
@@ -498,6 +470,65 @@
498
470
  }
499
471
  }
500
472
 
473
+ // Copyright (c) Microsoft Corporation.
474
+ /**
475
+ * A ConfigurationSettingsSource that wraps pre-calculated configuration changes.
476
+ *
477
+ * Use this class to import changes that were previously obtained via GetConfigurationChanges().
478
+ *
479
+ * Example usage:
480
+ * ```ts
481
+ * // First, get the configuration changes
482
+ * const changes = await importer.GetConfigurationChanges(source);
483
+ *
484
+ * // Import the pre-calculated changes
485
+ * const changesSource = new ConfigurationChangesSource(changes);
486
+ * await importer.Import(changesSource, { timeout: 60 });
487
+ * ```
488
+ */
489
+ class ConfigurationChangesSource {
490
+ constructor(configurationChanges, filterOptions) {
491
+ if (filterOptions && Object.keys(filterOptions).length > 0) {
492
+ throw new ArgumentError("FilterOptions are not supported for ConfigurationChangesSource.");
493
+ }
494
+ this.configurationChanges = configurationChanges;
495
+ }
496
+ /**
497
+ * @inheritdoc
498
+ */
499
+ async GetConfigurationSettings() {
500
+ return this.configurationChanges;
501
+ }
502
+ }
503
+
504
+ // Copyright (c) Microsoft Corporation.
505
+ // Licensed under the MIT license.
506
+ /**
507
+ * Enums of configuration Format.
508
+ */
509
+ exports.ConfigurationFormat = void 0;
510
+ (function (ConfigurationFormat) {
511
+ ConfigurationFormat[ConfigurationFormat["Json"] = 0] = "Json";
512
+ ConfigurationFormat[ConfigurationFormat["Properties"] = 1] = "Properties";
513
+ ConfigurationFormat[ConfigurationFormat["Yaml"] = 2] = "Yaml";
514
+ })(exports.ConfigurationFormat || (exports.ConfigurationFormat = {}));
515
+ /**
516
+ * Enums of configuration Profile.
517
+ */
518
+ exports.ConfigurationProfile = void 0;
519
+ (function (ConfigurationProfile) {
520
+ ConfigurationProfile[ConfigurationProfile["Default"] = 0] = "Default";
521
+ ConfigurationProfile[ConfigurationProfile["KvSet"] = 1] = "KvSet";
522
+ })(exports.ConfigurationProfile || (exports.ConfigurationProfile = {}));
523
+ /**
524
+ * Enums of import mode.
525
+ */
526
+ exports.ImportMode = void 0;
527
+ (function (ImportMode) {
528
+ ImportMode[ImportMode["All"] = 0] = "All";
529
+ ImportMode[ImportMode["IgnoreMatch"] = 1] = "IgnoreMatch";
530
+ })(exports.ImportMode || (exports.ImportMode = {}));
531
+
501
532
  function isFunction(value) {
502
533
  return typeof value === 'function';
503
534
  }
@@ -18995,31 +19026,84 @@
18995
19026
  this.configurationClient = configurationClient;
18996
19027
  }
18997
19028
  /**
18998
- * Import source settings into the Azure App Configuration service
19029
+ * Import settings into the Azure App Configuration service.
18999
19030
  *
19000
19031
  * Example usage:
19001
19032
  * ```ts
19002
19033
  * const fileData = fs.readFileSync("mylocalPath").toString();
19003
- * const result = await asyncClient.Import(new StringConfigurationSettingsSource({data:fileData, format: ConfigurationFormat.Json}));
19034
+ * const source = new StringConfigurationSettingsSource({data:fileData, format: ConfigurationFormat.Json});
19035
+ * await importer.Import(source, { timeout: 60 });
19036
+ * ```
19037
+ *
19038
+ * @param configurationSettingsSource - A ConfigurationSettingsSource instance.
19039
+ * @param options - Import options including timeout, progress callback, strict mode, and import mode.
19040
+ * @returns Promise<void>
19041
+ */
19042
+ async Import(configurationSettingsSource, options) {
19043
+ if (configurationSettingsSource instanceof ConfigurationChangesSource) {
19044
+ // When using ConfigurationChanges, strict and importMode parameters are not applicable
19045
+ if ((options === null || options === void 0 ? void 0 : options.strict) || (options === null || options === void 0 ? void 0 : options.importMode)) {
19046
+ throw new ArgumentError("Parameters 'strict' and 'importMode' are not applicable when importing pre-calculated changes.");
19047
+ }
19048
+ }
19049
+ // Generate correlationRequestId for operations in the same activity
19050
+ const customCorrelationRequestId = v4();
19051
+ const customHeadersOption = {
19052
+ requestOptions: {
19053
+ customHeaders: {
19054
+ [Constants.CorrelationRequestIdHeader]: customCorrelationRequestId
19055
+ }
19056
+ }
19057
+ };
19058
+ const configurationChanges = await this.GetConfigurationChanges(configurationSettingsSource, options === null || options === void 0 ? void 0 : options.strict, options === null || options === void 0 ? void 0 : options.importMode, customHeadersOption);
19059
+ return await this.applyUpdatesToServer([...configurationChanges.ToAdd, ...configurationChanges.ToModify, ...configurationChanges.ToRefresh], configurationChanges.ToDelete, options.timeout, customHeadersOption, options.progressCallback);
19060
+ }
19061
+ /**
19062
+ * Get configuration changes between source settings and existing settings in Azure App Configuration service without applying any changes
19063
+ *
19064
+ * Example usage:
19065
+ * ```ts
19066
+ * const fileData = fs.readFileSync("mylocalPath").toString();
19067
+ * const configurationChanges = await client.GetConfigurationChanges(
19068
+ * new StringConfigurationSettingsSource({data:fileData, format: ConfigurationFormat.Json}),
19069
+ * false,
19070
+ * ImportMode.All,
19071
+ * options
19072
+ * );
19004
19073
  * ```
19005
19074
  * @param configSettingsSource - A ConfigurationSettingsSource instance.
19006
- * @param strict - Use strict mode or not.
19007
- * @param timeout - Seconds of entire import progress timeout
19008
- * @param progressCallback - Callback for report the progress of import
19009
- * @param importMode - Determines the behavior when importing key-values. The default value, 'All' will import all key-values in the input file to App Configuration. 'Ignore-Match' will only import settings that have no matching key-value in App Configuration.
19010
- * @param dryRun - When dry run is enabled, no updates will be performed to App Configuration. Instead, any updates that would have been performed in a normal run will be printed to the console for review
19075
+ * @param strict - Use strict mode to delete settings not in source.
19076
+ * @param importMode - Determines the behavior when analyzing key-values.
19077
+ * 'All' will include all key-values.
19078
+ * 'Ignore-Match' will exclude settings that have matching key-values in App Configuration.
19079
+ * @param customHeadersOption - Custom headers for the operation.
19080
+ * @returns ConfigurationChanges object containing Added, Modified, and Deleted settings
19011
19081
  */
19012
- async Import(configSettingsSource, timeout, strict = false, progressCallback, importMode, dryRun) {
19082
+ async GetConfigurationChanges(configSettingsSource, strict = false, importMode = exports.ImportMode.IgnoreMatch, customHeadersOption) {
19013
19083
  var _a, e_1, _b, _c;
19014
- if (importMode == undefined) {
19015
- importMode = exports.ImportMode.IgnoreMatch;
19084
+ this.validateImportMode(importMode);
19085
+ // Generate correlationRequestId for operations in the same activity
19086
+ if (!customHeadersOption) {
19087
+ const customCorrelationRequestId = v4();
19088
+ customHeadersOption = {
19089
+ requestOptions: {
19090
+ customHeaders: {
19091
+ [Constants.CorrelationRequestIdHeader]: customCorrelationRequestId
19092
+ }
19093
+ }
19094
+ };
19016
19095
  }
19017
- if (dryRun == undefined) {
19018
- dryRun = false;
19096
+ const configSettingsResult = await configSettingsSource.GetConfigurationSettings();
19097
+ // If the source returns ConfigurationChanges (e.g., ConfigurationChangesSource),
19098
+ // return them directly without further processing since changes are already calculated
19099
+ if (this.isConfigurationChanges(configSettingsResult)) {
19100
+ return configSettingsResult;
19019
19101
  }
19020
- this.validateImportMode(importMode);
19021
- const configSettings = await configSettingsSource.GetConfigurationSettings();
19102
+ const configSettings = configSettingsResult;
19022
19103
  const configurationSettingToDelete = [];
19104
+ const configurationSettingToModify = [];
19105
+ const configurationSettingToAdd = [];
19106
+ const configurationSettingToRefresh = [];
19023
19107
  const srcKeyLabelLookUp = {};
19024
19108
  configSettings.forEach((config) => {
19025
19109
  if (!srcKeyLabelLookUp[config.key]) {
@@ -19027,72 +19111,58 @@
19027
19111
  }
19028
19112
  srcKeyLabelLookUp[config.key][config.label || ""] = true;
19029
19113
  });
19030
- // generate correlationRequestId for operations in the same activity
19031
- const customCorrelationRequestId = v4();
19032
- const customHeadersOption = {
19033
- requestOptions: {
19034
- customHeaders: {
19035
- [Constants.CorrelationRequestIdHeader]: customCorrelationRequestId
19036
- }
19037
- }
19038
- };
19039
- if (strict || importMode == exports.ImportMode.IgnoreMatch) {
19040
- try {
19041
- for (var _d = true, _e = __asyncValues(this.configurationClient.listConfigurationSettings(Object.assign(Object.assign({}, configSettingsSource.FilterOptions), customHeadersOption))), _f; _f = await _e.next(), _a = _f.done, !_a;) {
19042
- _c = _f.value;
19043
- _d = false;
19044
- try {
19045
- const existing = _c;
19046
- const isKeyLabelPresent = srcKeyLabelLookUp[existing.key] && srcKeyLabelLookUp[existing.key][existing.label || ""];
19047
- if (strict && !isKeyLabelPresent) {
19048
- configurationSettingToDelete.push(existing);
19114
+ configurationSettingToAdd.push(...configSettings);
19115
+ try {
19116
+ for (var _d = true, _e = __asyncValues(this.configurationClient.listConfigurationSettings(Object.assign(Object.assign({}, configSettingsSource.FilterOptions), customHeadersOption))), _f; _f = await _e.next(), _a = _f.done, !_a;) {
19117
+ _c = _f.value;
19118
+ _d = false;
19119
+ try {
19120
+ const existing = _c;
19121
+ const isKeyLabelPresent = srcKeyLabelLookUp[existing.key] && srcKeyLabelLookUp[existing.key][existing.label || ""];
19122
+ if (strict && !isKeyLabelPresent) {
19123
+ configurationSettingToDelete.push(existing);
19124
+ }
19125
+ const incoming = configSettings.find(configSetting => configSetting.key == existing.key && configSetting.label === existing.label);
19126
+ if (incoming) {
19127
+ // Remove from add list since it already exists
19128
+ configurationSettingToAdd.splice(configurationSettingToAdd.indexOf(incoming), 1);
19129
+ if (!isConfigSettingEqual(incoming, existing)) {
19130
+ // Key-value has changed, add to ToModify
19131
+ configurationSettingToModify.push(incoming);
19049
19132
  }
19050
- if (importMode == exports.ImportMode.IgnoreMatch) {
19051
- const incoming = configSettings.find(configSetting => configSetting.key == existing.key &&
19052
- configSetting.label == existing.label);
19053
- if (incoming && isConfigSettingEqual(incoming, existing)) {
19054
- configSettings.splice(configSettings.indexOf(incoming), 1);
19055
- }
19133
+ else if (importMode === exports.ImportMode.All) {
19134
+ // Key-value is unchanged and importMode is All, add to ToRefresh
19135
+ configurationSettingToRefresh.push(incoming);
19056
19136
  }
19057
19137
  }
19058
- finally {
19059
- _d = true;
19060
- }
19061
19138
  }
19062
- }
19063
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
19064
- finally {
19065
- try {
19066
- if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
19139
+ finally {
19140
+ _d = true;
19067
19141
  }
19068
- finally { if (e_1) throw e_1.error; }
19069
19142
  }
19070
19143
  }
19071
- if (dryRun) {
19072
- this.printUpdatesToConsole(configSettings, configurationSettingToDelete);
19073
- }
19074
- else {
19075
- await this.applyUpdatesToServer(configSettings, configurationSettingToDelete, timeout, customHeadersOption, progressCallback);
19076
- }
19077
- }
19078
- printUpdatesToConsole(settingsToAdd, settingsToDelete) {
19079
- console.log("The following settings will be removed from App Configuration:");
19080
- for (const setting of settingsToDelete) {
19081
- console.log(JSON.stringify({ key: setting.key, label: setting.label, contentType: setting.contentType, tags: setting.tags }));
19082
- }
19083
- console.log("\nThe following settings will be written to App Configuration:");
19084
- for (const setting of settingsToAdd) {
19085
- console.log(JSON.stringify({ key: setting.key, label: setting.label, contentType: setting.contentType, tags: setting.tags }));
19144
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
19145
+ finally {
19146
+ try {
19147
+ if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
19148
+ }
19149
+ finally { if (e_1) throw e_1.error; }
19086
19150
  }
19151
+ return {
19152
+ ToAdd: configurationSettingToAdd,
19153
+ ToModify: configurationSettingToModify,
19154
+ ToDelete: configurationSettingToDelete,
19155
+ ToRefresh: configurationSettingToRefresh
19156
+ };
19087
19157
  }
19088
- async applyUpdatesToServer(settingsToAdd, settingsToDelete, timeout, options, progressCallback) {
19158
+ async applyUpdatesToServer(settingsToPut, settingsToDelete, timeout, options, progressCallback) {
19089
19159
  const deleteTaskManager = this.newAdaptiveTaskManager((setting) => this.configurationClient.deleteConfigurationSetting(setting, options), settingsToDelete);
19090
19160
  const startTime = Date.now();
19091
19161
  await this.executeTasksWithTimeout(deleteTaskManager, timeout);
19092
19162
  const endTime = Date.now();
19093
19163
  const deleteTimeConsumed = (endTime - startTime) / 1000;
19094
19164
  timeout -= deleteTimeConsumed;
19095
- const importTaskManager = this.newAdaptiveTaskManager((setting) => this.configurationClient.setConfigurationSetting(setting, options), settingsToAdd);
19165
+ const importTaskManager = this.newAdaptiveTaskManager((setting) => this.configurationClient.setConfigurationSetting(setting, options), settingsToPut);
19096
19166
  await this.executeTasksWithTimeout(importTaskManager, timeout, progressCallback);
19097
19167
  }
19098
19168
  newAdaptiveTaskManager(task, configurationSettings) {
@@ -19123,6 +19193,20 @@
19123
19193
  throw new ArgumentError("Only options supported for Import Mode are 'All' and 'Ignore-Match'.");
19124
19194
  }
19125
19195
  }
19196
+ /**
19197
+ * Type guard to detect a ConfigurationChanges object.
19198
+ * @internal
19199
+ */
19200
+ isConfigurationChanges(obj) {
19201
+ if (obj === null || typeof obj !== "object") {
19202
+ return false;
19203
+ }
19204
+ const configChanges = obj;
19205
+ return Array.isArray(configChanges.ToAdd) &&
19206
+ Array.isArray(configChanges.ToModify) &&
19207
+ Array.isArray(configChanges.ToDelete) &&
19208
+ Array.isArray(configChanges.ToRefresh);
19209
+ }
19126
19210
  }
19127
19211
 
19128
19212
  /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
@@ -29452,6 +29536,7 @@
29452
29536
  exports.AppConfigurationImporter = AppConfigurationImporter;
29453
29537
  exports.ArgumentError = ArgumentError;
29454
29538
  exports.ArgumentNullError = ArgumentNullError;
29539
+ exports.ConfigurationChangesSource = ConfigurationChangesSource;
29455
29540
  exports.IterableConfigurationSettingsSource = IterableConfigurationSettingsSource;
29456
29541
  exports.OperationTimeoutError = OperationTimeoutError;
29457
29542
  exports.ParseError = ParseError;