@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.
- package/dist/index.js +178 -93
- package/dist/index.js.map +1 -1
- package/dist-esm/src/appConfigurationImporter.js +119 -65
- package/dist-esm/src/appConfigurationImporter.js.map +1 -1
- package/dist-esm/src/index.js +1 -0
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/internal/parsers/configurationSettingsConverter.js.map +1 -1
- package/dist-esm/src/internal/parsers/defaultConfigurationSettingsConverter.js.map +1 -1
- package/dist-esm/src/internal/utils.js.map +1 -1
- package/dist-esm/src/models.js.map +1 -1
- package/dist-esm/src/{importOptions.js → options.js} +1 -1
- package/dist-esm/src/options.js.map +1 -0
- package/dist-esm/src/settingsImport/configurationChangesSource.js +33 -0
- package/dist-esm/src/settingsImport/configurationChangesSource.js.map +1 -0
- package/dist-esm/src/settingsImport/configurationSettingsSource.js.map +1 -1
- package/dist-esm/src/settingsImport/iterableConfigurationSettingsSource.js.map +1 -1
- package/dist-esm/src/settingsImport/readableStreamConfigurationSettingsSource.js.map +1 -1
- package/dist-esm/src/settingsImport/stringConfigurationSettingsSource.js.map +1 -1
- package/package.json +1 -1
- package/types/azure-app-configuration-importer.d.ts +93 -12
- package/types/src/appConfigurationImporter.d.ts +37 -10
- package/types/src/appConfigurationImporter.d.ts.map +1 -1
- package/types/src/index.d.ts +3 -2
- package/types/src/index.d.ts.map +1 -1
- package/types/src/internal/parsers/configurationSettingsConverter.d.ts +1 -1
- package/types/src/internal/parsers/configurationSettingsConverter.d.ts.map +1 -1
- package/types/src/internal/parsers/defaultConfigurationSettingsConverter.d.ts +1 -1
- package/types/src/internal/parsers/defaultConfigurationSettingsConverter.d.ts.map +1 -1
- package/types/src/internal/utils.d.ts +1 -1
- package/types/src/internal/utils.d.ts.map +1 -1
- package/types/src/models.d.ts +7 -0
- package/types/src/models.d.ts.map +1 -1
- package/types/src/{importOptions.d.ts → options.d.ts} +26 -3
- package/types/src/options.d.ts.map +1 -0
- package/types/src/settingsImport/configurationChangesSource.d.ts +27 -0
- package/types/src/settingsImport/configurationChangesSource.d.ts.map +1 -0
- package/types/src/settingsImport/configurationSettingsSource.d.ts +4 -3
- package/types/src/settingsImport/configurationSettingsSource.d.ts.map +1 -1
- package/types/src/settingsImport/iterableConfigurationSettingsSource.d.ts +1 -1
- package/types/src/settingsImport/iterableConfigurationSettingsSource.d.ts.map +1 -1
- package/types/src/settingsImport/readableStreamConfigurationSettingsSource.d.ts +1 -1
- package/types/src/settingsImport/readableStreamConfigurationSettingsSource.d.ts.map +1 -1
- package/types/src/settingsImport/stringConfigurationSettingsSource.d.ts +1 -1
- package/types/src/settingsImport/stringConfigurationSettingsSource.d.ts.map +1 -1
- package/dist-esm/src/importOptions.js.map +0 -1
- 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
|
|
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
|
|
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
|
|
19007
|
-
* @param
|
|
19008
|
-
*
|
|
19009
|
-
*
|
|
19010
|
-
* @param
|
|
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
|
|
19082
|
+
async GetConfigurationChanges(configSettingsSource, strict = false, importMode = exports.ImportMode.IgnoreMatch, customHeadersOption) {
|
|
19013
19083
|
var _a, e_1, _b, _c;
|
|
19014
|
-
|
|
19015
|
-
|
|
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
|
-
|
|
19018
|
-
|
|
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
|
-
|
|
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
|
-
|
|
19031
|
-
|
|
19032
|
-
|
|
19033
|
-
|
|
19034
|
-
|
|
19035
|
-
|
|
19036
|
-
|
|
19037
|
-
|
|
19038
|
-
|
|
19039
|
-
|
|
19040
|
-
|
|
19041
|
-
|
|
19042
|
-
|
|
19043
|
-
|
|
19044
|
-
|
|
19045
|
-
|
|
19046
|
-
|
|
19047
|
-
|
|
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
|
|
19051
|
-
|
|
19052
|
-
|
|
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
|
-
|
|
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
|
-
|
|
19072
|
-
|
|
19073
|
-
|
|
19074
|
-
|
|
19075
|
-
|
|
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(
|
|
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),
|
|
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;
|