@transcommerce/cwm-shared 1.1.68 → 1.1.74
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.
|
@@ -27699,21 +27699,23 @@ const MockProfile = DEFAULT_PROFILE;
|
|
|
27699
27699
|
const MockCustomer = DEFAULT_CUSTOMER;
|
|
27700
27700
|
|
|
27701
27701
|
class ConfigService {
|
|
27702
|
+
authConfig;
|
|
27702
27703
|
logger;
|
|
27703
27704
|
mockData = false;
|
|
27704
27705
|
configClient;
|
|
27705
27706
|
configConnectString;
|
|
27706
|
-
_configCache;
|
|
27707
|
+
static _configCache;
|
|
27707
27708
|
get configCache() {
|
|
27708
|
-
return
|
|
27709
|
+
return ConfigService._configCache;
|
|
27709
27710
|
}
|
|
27710
27711
|
set configCache(value) {
|
|
27711
|
-
|
|
27712
|
+
ConfigService._configCache = value;
|
|
27712
27713
|
}
|
|
27713
|
-
constructor(logger) {
|
|
27714
|
+
constructor(authConfig, logger) {
|
|
27715
|
+
this.authConfig = authConfig;
|
|
27714
27716
|
this.logger = logger;
|
|
27715
27717
|
this.logger.className = this.constructor.name; //"ConfigService";
|
|
27716
|
-
this.configConnectString =
|
|
27718
|
+
this.configConnectString = this.authConfig.configConnectString;
|
|
27717
27719
|
this.configClient = new AppConfigurationClient(this.configConnectString);
|
|
27718
27720
|
this.logger.debug("Config Client", this.configClient);
|
|
27719
27721
|
this.logger.methodName = "";
|
|
@@ -27722,6 +27724,7 @@ class ConfigService {
|
|
|
27722
27724
|
this.logger.methodName = "getConfigurationSettingAsync()";
|
|
27723
27725
|
let setting = {};
|
|
27724
27726
|
this.logger.debug("Get Configuration Setting for Key/Label requested", key, label);
|
|
27727
|
+
// --- CACHE OR MOCK DATA ---
|
|
27725
27728
|
if (this.mockData || this.configCache != undefined) {
|
|
27726
27729
|
if (this.configCache == undefined) {
|
|
27727
27730
|
this.configCache = DEFAULT_CONFIGURATION;
|
|
@@ -27736,21 +27739,58 @@ class ConfigService {
|
|
|
27736
27739
|
}
|
|
27737
27740
|
else if (this.configCache == undefined) {
|
|
27738
27741
|
this.logger.debug("Configuration Cache was undefined and Mock Data disabled. Getting Configuration Setting Key/Label. Configuration will be cached and used for this and all subsequent calls", key, label);
|
|
27739
|
-
setting = await this.configClient.getConfigurationSetting({
|
|
27742
|
+
setting = await this.configClient.getConfigurationSetting({
|
|
27743
|
+
key: key,
|
|
27744
|
+
label: label.replace(".", "")
|
|
27745
|
+
});
|
|
27746
|
+
}
|
|
27747
|
+
// --- FIX: AUTO-PARSE JSON IF APPLICABLE ---
|
|
27748
|
+
if (setting.contentType === "application/json" || setting.contentType === "JSON") {
|
|
27749
|
+
try {
|
|
27750
|
+
return JSON.parse(setting.value ?? "{}");
|
|
27751
|
+
}
|
|
27752
|
+
catch (err) {
|
|
27753
|
+
this.logger.error("Failed to parse JSON configuration value", err);
|
|
27754
|
+
return setting.value; // fallback to raw string
|
|
27755
|
+
}
|
|
27740
27756
|
}
|
|
27741
27757
|
return setting.value;
|
|
27742
27758
|
}
|
|
27743
|
-
async setConfigurationSettingAsync(templateName, label, setting, contentType = "
|
|
27759
|
+
async setConfigurationSettingAsync(templateName, label, setting, contentType = "application/json") {
|
|
27744
27760
|
this.logger.methodName = "setConfigurationSettingAsync()";
|
|
27745
27761
|
if (this.mockData) {
|
|
27746
27762
|
this.logger.info("Mock Data Enabled, Skipping setConfigurationSettingAsync()");
|
|
27747
27763
|
this.logger.methodName = "";
|
|
27748
27764
|
return;
|
|
27749
27765
|
}
|
|
27766
|
+
this.logger.debug(`Saving this value to app config ${setting}`, setting, contentType);
|
|
27767
|
+
// --- FIX: Ensure JSON objects are stringified before saving ---
|
|
27768
|
+
let valueToSave;
|
|
27769
|
+
if (contentType === "application/json") {
|
|
27770
|
+
// If it's already a string, trust it. Otherwise stringify.
|
|
27771
|
+
if (typeof setting === "string") {
|
|
27772
|
+
contentType = "text/plain";
|
|
27773
|
+
valueToSave = setting;
|
|
27774
|
+
this.logger.trace("This is just a sting marked as JSON so we are correcting the contentType");
|
|
27775
|
+
}
|
|
27776
|
+
else {
|
|
27777
|
+
valueToSave = JSON.stringify(setting);
|
|
27778
|
+
this.logger.trace("This is a valid JSON configuration");
|
|
27779
|
+
}
|
|
27780
|
+
}
|
|
27781
|
+
else if (contentType !== "text/html" && contentType !== "text/markdown") {
|
|
27782
|
+
this.logger.trace("This is just a string so marking it contentType correctly");
|
|
27783
|
+
contentType = "text/plain";
|
|
27784
|
+
valueToSave = String(setting);
|
|
27785
|
+
}
|
|
27786
|
+
else {
|
|
27787
|
+
this.logger.trace("This is a string");
|
|
27788
|
+
valueToSave = String(setting);
|
|
27789
|
+
}
|
|
27750
27790
|
const configurationSetting = {
|
|
27751
27791
|
key: templateName,
|
|
27752
27792
|
label: label,
|
|
27753
|
-
value:
|
|
27793
|
+
value: valueToSave,
|
|
27754
27794
|
contentType: contentType,
|
|
27755
27795
|
};
|
|
27756
27796
|
this.logger.debug("Calling configClient.setConfigurationSetting", configurationSetting);
|
|
@@ -27789,11 +27829,11 @@ class ConfigService {
|
|
|
27789
27829
|
return;
|
|
27790
27830
|
}
|
|
27791
27831
|
this.logger.info("Saving Configuration to Azure App Configuration");
|
|
27792
|
-
await this.setConfigurationSettingAsync("App.Config.Json", company, config, "
|
|
27832
|
+
await this.setConfigurationSettingAsync("App.Config.Json", company, config, "application/json");
|
|
27793
27833
|
this.logger.info("Saved Configuration to Azure App Configuration");
|
|
27794
27834
|
this.logger.methodName = "";
|
|
27795
27835
|
}
|
|
27796
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: ConfigService, deps: [{ token: ClassLoggerService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
27836
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: ConfigService, deps: [{ token: AUTH_CONFIG }, { token: ClassLoggerService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
27797
27837
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: ConfigService, providedIn: 'root' });
|
|
27798
27838
|
}
|
|
27799
27839
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: ConfigService, decorators: [{
|
|
@@ -27801,7 +27841,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
|
|
|
27801
27841
|
args: [{
|
|
27802
27842
|
providedIn: 'root'
|
|
27803
27843
|
}]
|
|
27804
|
-
}], ctorParameters: () => [{ type:
|
|
27844
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
27845
|
+
type: Inject,
|
|
27846
|
+
args: [AUTH_CONFIG]
|
|
27847
|
+
}] }, { type: ClassLoggerService }] });
|
|
27805
27848
|
|
|
27806
27849
|
class BaseApiService {
|
|
27807
27850
|
document;
|