@saasquatch/squatch-js 2.8.0 → 2.8.1-0

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