@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.
package/dist/squatch.d.ts CHANGED
@@ -60,7 +60,7 @@ export declare function widget(widgetConfig: WidgetConfig): Promise<WidgetResult
60
60
  * Called by default on startup via the loader script.
61
61
  * @private
62
62
  */
63
- export declare function _auto(configIn: ConfigOptions): Promise<WidgetResult | undefined> | undefined;
63
+ export declare function _auto(): Promise<WidgetResult | undefined> | undefined;
64
64
  /**
65
65
  * Initializes the static `squatch` global. This sets up:
66
66
  *
@@ -1787,7 +1787,8 @@ function _pushCookie() {
1787
1787
  }
1788
1788
  }
1789
1789
  const _log$3 = browserExports.debug("squatch-js");
1790
- function _getAutoConfig(configIn) {
1790
+ function _getAutoConfig() {
1791
+ var _a2;
1791
1792
  const queryString = window.location.search;
1792
1793
  const urlParams = new URLSearchParams(queryString);
1793
1794
  const refParam = urlParams.get("_saasquatchExtra") || "";
@@ -1795,6 +1796,13 @@ function _getAutoConfig(configIn) {
1795
1796
  _log$3("No _saasquatchExtra param");
1796
1797
  return;
1797
1798
  }
1799
+ const config = validateConfig();
1800
+ if (!config.domain || !config.tenantAlias) {
1801
+ _log$3(
1802
+ "domain and tenantAlias must be provided in config to use _saasquatchExtra"
1803
+ );
1804
+ return;
1805
+ }
1798
1806
  let raw;
1799
1807
  try {
1800
1808
  raw = JSON.parse(b64decode(refParam));
@@ -1802,8 +1810,12 @@ function _getAutoConfig(configIn) {
1802
1810
  _log$3("Unable to decode _saasquatchExtra config");
1803
1811
  return;
1804
1812
  }
1805
- const { domain, tenantAlias, widgetConfig } = convertExtraToConfig(raw);
1806
- if (!domain || !tenantAlias || !widgetConfig) {
1813
+ function normalizeDomain(domain) {
1814
+ return domain.replace(/^https?:\/\//, "");
1815
+ }
1816
+ const normalizedDomain = normalizeDomain(config.domain);
1817
+ const widgetConfig = (_a2 = raw == null ? void 0 : raw[normalizedDomain]) == null ? void 0 : _a2[config.tenantAlias];
1818
+ if (!widgetConfig) {
1807
1819
  _log$3("_saasquatchExtra did not have an expected structure");
1808
1820
  return void 0;
1809
1821
  }
@@ -1815,20 +1827,12 @@ function _getAutoConfig(configIn) {
1815
1827
  ...rest
1816
1828
  },
1817
1829
  squatchConfig: {
1818
- ...configIn ? { configIn } : {},
1819
- domain,
1820
- tenantAlias
1830
+ ...config,
1831
+ domain: config.domain,
1832
+ tenantAlias: config.tenantAlias
1821
1833
  }
1822
1834
  };
1823
1835
  }
1824
- function convertExtraToConfig(obj) {
1825
- var _a2;
1826
- const _domain = Object.keys(obj || {})[0];
1827
- const tenantAlias = Object.keys((obj == null ? void 0 : obj[_domain]) || {})[0];
1828
- const widgetConfig = (_a2 = obj == null ? void 0 : obj[_domain]) == null ? void 0 : _a2[tenantAlias];
1829
- const domain = _domain ? `https://${_domain}` : void 0;
1830
- return { domain, tenantAlias, widgetConfig };
1831
- }
1832
1836
  const _log$2 = browserExports.debug("squatch-js:decodeUserJwt");
1833
1837
  function decodeUserJwt(tokenStr) {
1834
1838
  var _a2;
@@ -2141,9 +2145,9 @@ function widget(widgetConfig) {
2141
2145
  var _a2;
2142
2146
  return (_a2 = widgets()) == null ? void 0 : _a2.render(widgetConfig);
2143
2147
  }
2144
- function _auto(configIn) {
2148
+ function _auto() {
2145
2149
  var _a2;
2146
- const configs = _getAutoConfig(configIn);
2150
+ const configs = _getAutoConfig();
2147
2151
  if (configs) {
2148
2152
  const { squatchConfig, widgetConfig } = configs;
2149
2153
  init(squatchConfig);