@saasquatch/squatch-js 2.8.0 → 2.8.1

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/squatch.js CHANGED
@@ -1791,7 +1791,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1791
1791
  }
1792
1792
  }
1793
1793
  const _log$3 = browserExports.debug("squatch-js");
1794
- function _getAutoConfig(configIn) {
1794
+ function _getAutoConfig() {
1795
+ var _a2;
1795
1796
  const queryString = window.location.search;
1796
1797
  const urlParams = new URLSearchParams(queryString);
1797
1798
  const refParam = urlParams.get("_saasquatchExtra") || "";
@@ -1799,6 +1800,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1799
1800
  _log$3("No _saasquatchExtra param");
1800
1801
  return;
1801
1802
  }
1803
+ const config = validateConfig({
1804
+ tenantAlias: "UNKNOWN"
1805
+ });
1806
+ if (!config.domain) {
1807
+ _log$3("domain must be provided in config to use _saasquatchExtra");
1808
+ return;
1809
+ }
1802
1810
  let raw;
1803
1811
  try {
1804
1812
  raw = JSON.parse(b64decode(refParam));
@@ -1806,8 +1814,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1806
1814
  _log$3("Unable to decode _saasquatchExtra config");
1807
1815
  return;
1808
1816
  }
1809
- const { domain, tenantAlias, widgetConfig } = convertExtraToConfig(raw);
1810
- if (!domain || !tenantAlias || !widgetConfig) {
1817
+ function normalizeDomain(domain) {
1818
+ return domain.replace(/^https?:\/\//, "");
1819
+ }
1820
+ const normalizedDomain = normalizeDomain(config.domain);
1821
+ const tenantAlias = Object.keys((raw == null ? void 0 : raw[normalizedDomain]) || {})[0];
1822
+ const widgetConfig = (_a2 = raw == null ? void 0 : raw[normalizedDomain]) == null ? void 0 : _a2[tenantAlias];
1823
+ if (!widgetConfig) {
1811
1824
  _log$3("_saasquatchExtra did not have an expected structure");
1812
1825
  return void 0;
1813
1826
  }
@@ -1819,20 +1832,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1819
1832
  ...rest
1820
1833
  },
1821
1834
  squatchConfig: {
1822
- ...configIn ? { configIn } : {},
1823
- domain,
1835
+ ...config,
1824
1836
  tenantAlias
1825
1837
  }
1826
1838
  };
1827
1839
  }
1828
- function convertExtraToConfig(obj) {
1829
- var _a2;
1830
- const _domain = Object.keys(obj || {})[0];
1831
- const tenantAlias = Object.keys((obj == null ? void 0 : obj[_domain]) || {})[0];
1832
- const widgetConfig = (_a2 = obj == null ? void 0 : obj[_domain]) == null ? void 0 : _a2[tenantAlias];
1833
- const domain = _domain ? `https://${_domain}` : void 0;
1834
- return { domain, tenantAlias, widgetConfig };
1835
- }
1836
1840
  const _log$2 = browserExports.debug("squatch-js:decodeUserJwt");
1837
1841
  function decodeUserJwt(tokenStr) {
1838
1842
  var _a2;
@@ -2145,9 +2149,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2145
2149
  var _a2;
2146
2150
  return (_a2 = widgets()) == null ? void 0 : _a2.render(widgetConfig);
2147
2151
  }
2148
- function _auto(configIn) {
2152
+ function _auto() {
2149
2153
  var _a2;
2150
- const configs = _getAutoConfig(configIn);
2154
+ const configs = _getAutoConfig();
2151
2155
  if (configs) {
2152
2156
  const { squatchConfig, widgetConfig } = configs;
2153
2157
  init(squatchConfig);