@transcommerce/cwm-shared 1.1.67 → 1.1.69

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 this._configCache;
27709
+ return ConfigService._configCache;
27709
27710
  }
27710
27711
  set configCache(value) {
27711
- this._configCache = value;
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 = "Endpoint=https://cheap-weed-menus-appconfig.azconfig.io;Id=tyjA;Secret=1FgL95lHkXViZX4Qf2GcRqn26mhTYDVYany8ToXpTnO68AzrdUUEJQQJ99AHAC8vTInIcYexAAACAZACsteF";
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,7 +27739,20 @@ 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({ key: key, label: label.replace(".", "") });
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
  }
@@ -27747,10 +27763,22 @@ class ConfigService {
27747
27763
  this.logger.methodName = "";
27748
27764
  return;
27749
27765
  }
27766
+ // --- FIX: Ensure JSON objects are stringified before saving ---
27767
+ let valueToSave;
27768
+ if (contentType === "JSON") {
27769
+ // If it's already a string, trust it. Otherwise stringify.
27770
+ valueToSave = typeof setting === "string"
27771
+ ? setting
27772
+ : JSON.stringify(setting);
27773
+ }
27774
+ else {
27775
+ // Non‑JSON settings must still be strings
27776
+ valueToSave = String(setting);
27777
+ }
27750
27778
  const configurationSetting = {
27751
27779
  key: templateName,
27752
27780
  label: label,
27753
- value: setting,
27781
+ value: valueToSave,
27754
27782
  contentType: contentType,
27755
27783
  };
27756
27784
  this.logger.debug("Calling configClient.setConfigurationSetting", configurationSetting);
@@ -27793,7 +27821,7 @@ class ConfigService {
27793
27821
  this.logger.info("Saved Configuration to Azure App Configuration");
27794
27822
  this.logger.methodName = "";
27795
27823
  }
27796
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: ConfigService, deps: [{ token: ClassLoggerService }], target: i0.ɵɵFactoryTarget.Injectable });
27824
+ 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
27825
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: ConfigService, providedIn: 'root' });
27798
27826
  }
27799
27827
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: ConfigService, decorators: [{
@@ -27801,7 +27829,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
27801
27829
  args: [{
27802
27830
  providedIn: 'root'
27803
27831
  }]
27804
- }], ctorParameters: () => [{ type: ClassLoggerService }] });
27832
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
27833
+ type: Inject,
27834
+ args: [AUTH_CONFIG]
27835
+ }] }, { type: ClassLoggerService }] });
27805
27836
 
27806
27837
  class BaseApiService {
27807
27838
  document;