@azure/app-configuration-importer 1.1.3-preview → 3.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 (50) hide show
  1. package/dist/index.js +206 -93
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/src/appConfigurationImporter.js +138 -66
  4. package/dist-esm/src/appConfigurationImporter.js.map +1 -1
  5. package/dist-esm/src/enums.js +10 -0
  6. package/dist-esm/src/enums.js.map +1 -1
  7. package/dist-esm/src/index.js +1 -0
  8. package/dist-esm/src/index.js.map +1 -1
  9. package/dist-esm/src/internal/parsers/configurationSettingsConverter.js.map +1 -1
  10. package/dist-esm/src/internal/parsers/defaultConfigurationSettingsConverter.js.map +1 -1
  11. package/dist-esm/src/internal/utils.js.map +1 -1
  12. package/dist-esm/src/models.js.map +1 -1
  13. package/dist-esm/src/{importOptions.js → options.js} +1 -1
  14. package/dist-esm/src/options.js.map +1 -0
  15. package/dist-esm/src/settingsImport/configurationChangesSource.js +33 -0
  16. package/dist-esm/src/settingsImport/configurationChangesSource.js.map +1 -0
  17. package/dist-esm/src/settingsImport/configurationSettingsSource.js.map +1 -1
  18. package/dist-esm/src/settingsImport/iterableConfigurationSettingsSource.js.map +1 -1
  19. package/dist-esm/src/settingsImport/readableStreamConfigurationSettingsSource.js.map +1 -1
  20. package/dist-esm/src/settingsImport/stringConfigurationSettingsSource.js.map +1 -1
  21. package/package.json +1 -1
  22. package/types/azure-app-configuration-importer.d.ts +104 -12
  23. package/types/src/appConfigurationImporter.d.ts +37 -10
  24. package/types/src/appConfigurationImporter.d.ts.map +1 -1
  25. package/types/src/enums.d.ts +9 -0
  26. package/types/src/enums.d.ts.map +1 -1
  27. package/types/src/index.d.ts +3 -2
  28. package/types/src/index.d.ts.map +1 -1
  29. package/types/src/internal/parsers/configurationSettingsConverter.d.ts +1 -1
  30. package/types/src/internal/parsers/configurationSettingsConverter.d.ts.map +1 -1
  31. package/types/src/internal/parsers/defaultConfigurationSettingsConverter.d.ts +1 -1
  32. package/types/src/internal/parsers/defaultConfigurationSettingsConverter.d.ts.map +1 -1
  33. package/types/src/internal/utils.d.ts +1 -1
  34. package/types/src/internal/utils.d.ts.map +1 -1
  35. package/types/src/models.d.ts +9 -0
  36. package/types/src/models.d.ts.map +1 -1
  37. package/types/src/{importOptions.d.ts → options.d.ts} +26 -3
  38. package/types/src/options.d.ts.map +1 -0
  39. package/types/src/settingsImport/configurationChangesSource.d.ts +27 -0
  40. package/types/src/settingsImport/configurationChangesSource.d.ts.map +1 -0
  41. package/types/src/settingsImport/configurationSettingsSource.d.ts +4 -3
  42. package/types/src/settingsImport/configurationSettingsSource.d.ts.map +1 -1
  43. package/types/src/settingsImport/iterableConfigurationSettingsSource.d.ts +1 -1
  44. package/types/src/settingsImport/iterableConfigurationSettingsSource.d.ts.map +1 -1
  45. package/types/src/settingsImport/readableStreamConfigurationSettingsSource.d.ts +1 -1
  46. package/types/src/settingsImport/readableStreamConfigurationSettingsSource.d.ts.map +1 -1
  47. package/types/src/settingsImport/stringConfigurationSettingsSource.d.ts +1 -1
  48. package/types/src/settingsImport/stringConfigurationSettingsSource.d.ts.map +1 -1
  49. package/dist-esm/src/importOptions.js.map +0 -1
  50. 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,75 @@
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
+ /**
532
+ * Enums of change type for configuration settings changes
533
+ */
534
+ exports.ChangeType = void 0;
535
+ (function (ChangeType) {
536
+ ChangeType[ChangeType["None"] = 0] = "None";
537
+ ChangeType[ChangeType["Create"] = 1] = "Create";
538
+ ChangeType[ChangeType["Delete"] = 2] = "Delete";
539
+ ChangeType[ChangeType["Update"] = 3] = "Update";
540
+ })(exports.ChangeType || (exports.ChangeType = {}));
541
+
501
542
  function isFunction(value) {
502
543
  return typeof value === 'function';
503
544
  }
@@ -18995,31 +19036,88 @@
18995
19036
  this.configurationClient = configurationClient;
18996
19037
  }
18997
19038
  /**
18998
- * Import source settings into the Azure App Configuration service
19039
+ * Import settings into the Azure App Configuration service.
18999
19040
  *
19000
19041
  * Example usage:
19001
19042
  * ```ts
19002
19043
  * const fileData = fs.readFileSync("mylocalPath").toString();
19003
- * const result = await asyncClient.Import(new StringConfigurationSettingsSource({data:fileData, format: ConfigurationFormat.Json}));
19044
+ * const source = new StringConfigurationSettingsSource({data:fileData, format: ConfigurationFormat.Json});
19045
+ * await importer.Import(source, { timeout: 60 });
19046
+ * ```
19047
+ *
19048
+ * @param configurationSettingsSource - A ConfigurationSettingsSource instance.
19049
+ * @param options - Import options including timeout, progress callback, strict mode, and import mode.
19050
+ * @returns Promise<void>
19051
+ */
19052
+ async Import(configurationSettingsSource, options) {
19053
+ if (configurationSettingsSource instanceof ConfigurationChangesSource) {
19054
+ // When using ConfigurationChanges, strict and importMode parameters are not applicable
19055
+ if ((options === null || options === void 0 ? void 0 : options.strict) || (options === null || options === void 0 ? void 0 : options.importMode)) {
19056
+ throw new ArgumentError("Parameters 'strict' and 'importMode' are not applicable when importing pre-calculated changes.");
19057
+ }
19058
+ }
19059
+ // Generate correlationRequestId for operations in the same activity
19060
+ const customCorrelationRequestId = v4();
19061
+ const customHeadersOption = {
19062
+ requestOptions: {
19063
+ customHeaders: {
19064
+ [Constants.CorrelationRequestIdHeader]: customCorrelationRequestId
19065
+ }
19066
+ }
19067
+ };
19068
+ 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);
19069
+ const settingsToWrite = configurationChanges
19070
+ .filter(c => (c.changeType === exports.ChangeType.Create || c.changeType === exports.ChangeType.Update || c.changeType === exports.ChangeType.None) && c.newValue)
19071
+ .map(c => c.newValue);
19072
+ const settingsToDelete = configurationChanges
19073
+ .filter(c => c.changeType === exports.ChangeType.Delete && c.currentValue)
19074
+ .map(c => c.currentValue);
19075
+ return await this.applyUpdatesToServer(settingsToWrite, settingsToDelete, options.timeout, customHeadersOption, options.progressCallback);
19076
+ }
19077
+ /**
19078
+ * Get configuration changes between source settings and existing settings in Azure App Configuration service without applying any changes
19079
+ *
19080
+ * Example usage:
19081
+ * ```ts
19082
+ * const fileData = fs.readFileSync("mylocalPath").toString();
19083
+ * const configurationChanges = await client.GetConfigurationChanges(
19084
+ * new StringConfigurationSettingsSource({data:fileData, format: ConfigurationFormat.Json}),
19085
+ * false,
19086
+ * ImportMode.All,
19087
+ * options
19088
+ * );
19004
19089
  * ```
19005
19090
  * @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
19091
+ * @param strict - Use strict mode to delete settings not in source.
19092
+ * @param importMode - Determines the behavior when analyzing key-values.
19093
+ * 'All' will include all key-values.
19094
+ * 'Ignore-Match' will exclude settings that have matching key-values in App Configuration.
19095
+ * @param customHeadersOption - Custom headers for the operation.
19096
+ * @returns Array of ConfigurationSettingChange objects representing the changes
19011
19097
  */
19012
- async Import(configSettingsSource, timeout, strict = false, progressCallback, importMode, dryRun) {
19098
+ async GetConfigurationChanges(configSettingsSource, strict = false, importMode = exports.ImportMode.IgnoreMatch, customHeadersOption) {
19013
19099
  var _a, e_1, _b, _c;
19014
- if (importMode == undefined) {
19015
- importMode = exports.ImportMode.IgnoreMatch;
19100
+ this.validateImportMode(importMode);
19101
+ // Generate correlationRequestId for operations in the same activity
19102
+ if (!customHeadersOption) {
19103
+ const customCorrelationRequestId = v4();
19104
+ customHeadersOption = {
19105
+ requestOptions: {
19106
+ customHeaders: {
19107
+ [Constants.CorrelationRequestIdHeader]: customCorrelationRequestId
19108
+ }
19109
+ }
19110
+ };
19016
19111
  }
19017
- if (dryRun == undefined) {
19018
- dryRun = false;
19112
+ const configSettingsResult = await configSettingsSource.GetConfigurationSettings();
19113
+ // If the source returns ConfigurationChanges (e.g., ConfigurationChangesSource),
19114
+ // return them directly without further processing since changes are already calculated
19115
+ if (this.isConfigurationChanges(configSettingsResult)) {
19116
+ return configSettingsResult;
19019
19117
  }
19020
- this.validateImportMode(importMode);
19021
- const configSettings = await configSettingsSource.GetConfigurationSettings();
19022
- const configurationSettingToDelete = [];
19118
+ const configSettings = configSettingsResult;
19119
+ const configurationChanges = [];
19120
+ const configurationSettingToAdd = [];
19023
19121
  const srcKeyLabelLookUp = {};
19024
19122
  configSettings.forEach((config) => {
19025
19123
  if (!srcKeyLabelLookUp[config.key]) {
@@ -19027,72 +19125,70 @@
19027
19125
  }
19028
19126
  srcKeyLabelLookUp[config.key][config.label || ""] = true;
19029
19127
  });
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);
19128
+ configurationSettingToAdd.push(...configSettings);
19129
+ try {
19130
+ 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;) {
19131
+ _c = _f.value;
19132
+ _d = false;
19133
+ try {
19134
+ const existing = _c;
19135
+ const isKeyLabelPresent = srcKeyLabelLookUp[existing.key] && srcKeyLabelLookUp[existing.key][existing.label || ""];
19136
+ if (strict && !isKeyLabelPresent) {
19137
+ configurationChanges.push({
19138
+ changeType: exports.ChangeType.Delete,
19139
+ currentValue: existing,
19140
+ newValue: null
19141
+ });
19142
+ }
19143
+ const incoming = configSettings.find(configSetting => configSetting.key == existing.key && configSetting.label === existing.label);
19144
+ if (incoming) {
19145
+ // Remove from add list since it already exists
19146
+ configurationSettingToAdd.splice(configurationSettingToAdd.indexOf(incoming), 1);
19147
+ if (!isConfigSettingEqual(incoming, existing)) {
19148
+ configurationChanges.push({
19149
+ changeType: exports.ChangeType.Update,
19150
+ currentValue: existing,
19151
+ newValue: incoming
19152
+ });
19049
19153
  }
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
- }
19154
+ else if (importMode === exports.ImportMode.All) {
19155
+ configurationChanges.push({
19156
+ changeType: exports.ChangeType.None,
19157
+ currentValue: existing,
19158
+ newValue: incoming
19159
+ });
19056
19160
  }
19057
19161
  }
19058
- finally {
19059
- _d = true;
19060
- }
19061
19162
  }
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);
19163
+ finally {
19164
+ _d = true;
19067
19165
  }
19068
- finally { if (e_1) throw e_1.error; }
19069
19166
  }
19070
19167
  }
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 }));
19168
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
19169
+ finally {
19170
+ try {
19171
+ if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
19172
+ }
19173
+ finally { if (e_1) throw e_1.error; }
19082
19174
  }
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 }));
19175
+ for (const setting of configurationSettingToAdd) {
19176
+ configurationChanges.push({
19177
+ changeType: exports.ChangeType.Create,
19178
+ currentValue: null,
19179
+ newValue: setting
19180
+ });
19086
19181
  }
19182
+ return configurationChanges;
19087
19183
  }
19088
- async applyUpdatesToServer(settingsToAdd, settingsToDelete, timeout, options, progressCallback) {
19184
+ async applyUpdatesToServer(settingsToPut, settingsToDelete, timeout, options, progressCallback) {
19089
19185
  const deleteTaskManager = this.newAdaptiveTaskManager((setting) => this.configurationClient.deleteConfigurationSetting(setting, options), settingsToDelete);
19090
19186
  const startTime = Date.now();
19091
19187
  await this.executeTasksWithTimeout(deleteTaskManager, timeout);
19092
19188
  const endTime = Date.now();
19093
19189
  const deleteTimeConsumed = (endTime - startTime) / 1000;
19094
19190
  timeout -= deleteTimeConsumed;
19095
- const importTaskManager = this.newAdaptiveTaskManager((setting) => this.configurationClient.setConfigurationSetting(setting, options), settingsToAdd);
19191
+ const importTaskManager = this.newAdaptiveTaskManager((setting) => this.configurationClient.setConfigurationSetting(setting, options), settingsToPut);
19096
19192
  await this.executeTasksWithTimeout(importTaskManager, timeout, progressCallback);
19097
19193
  }
19098
19194
  newAdaptiveTaskManager(task, configurationSettings) {
@@ -19123,6 +19219,22 @@
19123
19219
  throw new ArgumentError("Only options supported for Import Mode are 'All' and 'Ignore-Match'.");
19124
19220
  }
19125
19221
  }
19222
+ /**
19223
+ * Type guard to detect a ConfigurationChanges object.
19224
+ * @internal
19225
+ */
19226
+ isConfigurationChanges(obj) {
19227
+ if (!Array.isArray(obj)) {
19228
+ return false;
19229
+ }
19230
+ // Validate it's an array of ConfigurationSettingChange objects
19231
+ return obj.every(item => item &&
19232
+ typeof item === "object" &&
19233
+ "changeType" in item &&
19234
+ "currentValue" in item &&
19235
+ "newValue" in item &&
19236
+ Object.values(exports.ChangeType).includes(item.changeType));
19237
+ }
19126
19238
  }
19127
19239
 
19128
19240
  /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
@@ -29452,6 +29564,7 @@
29452
29564
  exports.AppConfigurationImporter = AppConfigurationImporter;
29453
29565
  exports.ArgumentError = ArgumentError;
29454
29566
  exports.ArgumentNullError = ArgumentNullError;
29567
+ exports.ConfigurationChangesSource = ConfigurationChangesSource;
29455
29568
  exports.IterableConfigurationSettingsSource = IterableConfigurationSettingsSource;
29456
29569
  exports.OperationTimeoutError = OperationTimeoutError;
29457
29570
  exports.ParseError = ParseError;