@transcommerce/cwm-shared 1.1.21 → 1.1.23

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.
@@ -26863,16 +26863,17 @@ const MockInventoryApiResponse = {
26863
26863
  };
26864
26864
 
26865
26865
  const MockConfig = {
26866
+ "companyName": "Test Weed Dispensary",
26866
26867
  "authConfig": {
26867
26868
  "logLevel": "Info",
26868
26869
  "configConnectString": "Endpoint=https://cheap-weed-menus-appconfig.azconfig.io;Id=tyjA;Secret=1FgL95lHkXViZX4Qf2GcRqn26mhTYDVYany8ToXpTnO68AzrdUUEJQQJ99AHAC8vTInIcYexAAACAZACsteF",
26869
26870
  "clientId": "af1486e0-a27f-4c8d-8503-0752d90ce72d",
26870
- "tenantId": "445012c4-563a-4795-84d0-f7473a3197e0",
26871
- "authority": "https://login.microsoft.com/445012c4-563a-4795-84d0-f7473a3197e0",
26871
+ "tenantId": "72950c7a-314c-4ce9-87e5-a9866db20070",
26872
+ "authority": "https://login.microsoft.com/72950c7a-314c-4ce9-87e5-a9866db20070",
26872
26873
  "scopes": "openid,email,profile",
26873
- "menu_uri": "http://localhost:4200/",
26874
- "redirect_uri": "https://www.cheapweedmenu.com",
26875
- "logout_redirect_uri": "https://www.cheapweedmenu.com",
26874
+ "menu_uri": "http://localhost:4280/",
26875
+ "redirect_uri": "https://localhost:4280",
26876
+ "logout_redirect_uri": "https://localhost:4280/logout",
26876
26877
  "prompt": "login"
26877
26878
  },
26878
26879
  "apiConfig": {
@@ -26960,19 +26961,18 @@ const MockConfig = {
26960
26961
  };
26961
26962
 
26962
26963
  const MockProfile = {
26963
- companyName: "The Portland Pot Shop",
26964
- businessPhones: ["503.555.1212"],
26965
- displayName: "PPS User",
26966
- givenName: "PPS Menu User",
26967
- id: "",
26968
- jobTitle: "Menu",
26969
- mail: "portlandpotshop@google.com",
26970
- mobilePhone: "503.555.1212",
26971
- officeLocation: "autoscroll",
26972
- photoUrl: "",
26973
- preferredLanguage: "en-us",
26974
- surname: "Pot Shop",
26975
- userPrincipalName: "portlandpotshop"
26964
+ "companyName": "Test Weed Dispensary",
26965
+ "businessPhones": ["503.555.1212"],
26966
+ "displayName": "Demo User",
26967
+ "givenName": "Demo",
26968
+ "id": "1",
26969
+ "jobTitle": "Budtender",
26970
+ "mail": "demo@app.cheapweedmenu.com",
26971
+ "mobilePhone": "503.555.1212",
26972
+ "photoUrl": "",
26973
+ "preferredLanguage": "en-us",
26974
+ "surname": "User",
26975
+ "userPrincipalName": "demo@app.cheapweedmenu.com"
26976
26976
  };
26977
26977
 
26978
26978
  class AuthService {
@@ -27099,13 +27099,27 @@ class ConfigService {
27099
27099
  }
27100
27100
  async getConfigurationSettingAsync(key, label) {
27101
27101
  this.logService.methodName = "getConfigurationSettingAsync()";
27102
- const setting = await this.configClient.getConfigurationSetting({ key: key, label: label.replace(".", "") });
27102
+ var setting;
27103
+ if (this.mockData) {
27104
+ setting = {};
27105
+ setting.key = key;
27106
+ setting.value = JSON.stringify(MockConfig);
27107
+ this.logService.log("Mock Data Enabled, Skipping getConfigurationSettingAsync()");
27108
+ }
27109
+ else {
27110
+ this.logService.log("Getting Configuration Setting Key/Label", key, label);
27111
+ setting = await this.configClient.getConfigurationSetting({ key: key, label: label.replace(".", "") });
27112
+ }
27103
27113
  this.logService.log("Configuration Setting Key/Value", key, setting.value);
27104
27114
  return setting.value;
27105
27115
  }
27106
27116
  async setConfigurationSettingAsync(templateName, label, setting, contentType = "Text") {
27107
27117
  this.logService.className = "ConfigService";
27108
27118
  this.logService.methodName = "setConfigurationSettingAsync()";
27119
+ if (this.mockData) {
27120
+ this.logService.log("Mock Data Enabled, Skipping setConfigurationSettingAsync()");
27121
+ return;
27122
+ }
27109
27123
  const configurationSetting = {
27110
27124
  key: templateName,
27111
27125
  label: label,
@@ -27119,18 +27133,19 @@ class ConfigService {
27119
27133
  async getConfigAsync(company) {
27120
27134
  this.logService.className = "ConfigService";
27121
27135
  this.logService.methodName = "getConfigAsync()";
27122
- if (this.configCache == undefined) {
27123
- this.logService.log("configCache == undefined");
27124
- // If we want to use Mock data then load the Mock data into the cache
27125
- if (this.mockData) {
27126
- this.configCache = MockConfig;
27127
- }
27128
- else {
27129
- const jsonConfig = await this.getConfigurationSettingAsync("App.Config.Json", company) ?? "{ }";
27130
- this.configCache = JSON.parse(jsonConfig);
27131
- }
27136
+ if (this.mockData) {
27137
+ this.configCache = MockConfig;
27138
+ this.logService.log("Mock Data Enabled, Using Mock Config", this.configCache);
27139
+ }
27140
+ else if (this.configCache == undefined) {
27141
+ this.logService.log("Loading Configuration from Azure App Configuration");
27142
+ const jsonConfig = await this.getConfigurationSettingAsync("App.Config.Json", company) ?? "{ }";
27143
+ this.configCache = JSON.parse(jsonConfig);
27144
+ this.logService.log("Loaded and Cached Configuration from Azure App Configuration", this.configCache);
27145
+ }
27146
+ else {
27147
+ this.logService.log("Using Cached Configuration", this.configCache);
27132
27148
  }
27133
- this.logService.log("Config Cache", this.configCache);
27134
27149
  const config = this.configCache;
27135
27150
  this.logService.methodName = "";
27136
27151
  return config;
@@ -27142,9 +27157,12 @@ class ConfigService {
27142
27157
  this.configCache = config;
27143
27158
  this.logService.log("Updated Config Cache", this.configCache);
27144
27159
  if (this.mockData) {
27160
+ this.logService.log("Mock Data Enabled, Skipping setConfigurationSettingAsync()");
27145
27161
  return;
27146
27162
  }
27163
+ this.logService.log("Saving Configuration to Azure App Configuration");
27147
27164
  await this.setConfigurationSettingAsync("App.Config.Json", company, config, "JSON");
27165
+ this.logService.log("Saved Configuration to Azure App Configuration");
27148
27166
  this.logService.methodName = "";
27149
27167
  }
27150
27168
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: ConfigService, deps: [{ token: LogService }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -27207,7 +27225,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
27207
27225
  }] });
27208
27226
 
27209
27227
  class InventoryApiService extends BaseApiService {
27210
- demoData = false;
27228
+ useMockData = false;
27211
27229
  constructor(configService, httpClient, logService) {
27212
27230
  super(configService, httpClient, logService);
27213
27231
  logService.className = "InventoryApiService";
@@ -27221,17 +27239,18 @@ class InventoryApiService extends BaseApiService {
27221
27239
  get apiFullUrl() {
27222
27240
  return this.apiBaseUrl + this.config?.getInventoryApiRoute;
27223
27241
  }
27224
- async getProductsAsync(companyName = "Cheap Weed Menus") {
27242
+ async getProductsAsync(companyName) {
27225
27243
  this.logService.methodName = "getProductsAsync()";
27226
27244
  var response;
27245
+ this.configService.mockData = this.useMockData;
27246
+ this.logService.log("Fetching Configuration for Company", companyName);
27247
+ this.config = (await this.configService.getConfigAsync(companyName)).apiConfig;
27227
27248
  this.logService.log("Fetching Products for Company", companyName);
27228
- if (this.demoData) {
27229
- this.config = MockConfig.apiConfig;
27249
+ if (this.useMockData) {
27230
27250
  response = Promise.resolve(MockInventoryApiResponse);
27231
27251
  this.logService.log("Mock Data Returned", response);
27232
27252
  }
27233
27253
  else {
27234
- this.config = (await this.configService.getConfigAsync(companyName)).apiConfig;
27235
27254
  response = firstValueFrom(this.httpClient.get(this.apiFullUrl, { headers: this.httpHeaders }));
27236
27255
  this.logService.log("Inventory API Response", response);
27237
27256
  }