@thoughtspot/visual-embed-sdk 1.11.0-auth.10 → 1.11.0-auth.13

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.
Files changed (53) hide show
  1. package/dist/src/auth.d.ts +11 -0
  2. package/dist/src/embed/base.d.ts +18 -4
  3. package/dist/src/embed/ts-embed.d.ts +0 -1
  4. package/dist/src/index.d.ts +2 -1
  5. package/dist/src/types.d.ts +5 -0
  6. package/dist/src/utils/processData.d.ts +1 -1
  7. package/dist/tsembed.es.js +451 -42
  8. package/dist/tsembed.js +448 -41
  9. package/lib/package.json +2 -1
  10. package/lib/src/auth.d.ts +11 -0
  11. package/lib/src/auth.js +17 -8
  12. package/lib/src/auth.js.map +1 -1
  13. package/lib/src/auth.spec.js +54 -1
  14. package/lib/src/auth.spec.js.map +1 -1
  15. package/lib/src/embed/base.d.ts +18 -4
  16. package/lib/src/embed/base.js +60 -12
  17. package/lib/src/embed/base.js.map +1 -1
  18. package/lib/src/embed/base.spec.js +47 -2
  19. package/lib/src/embed/base.spec.js.map +1 -1
  20. package/lib/src/embed/embed.spec.js +1 -1
  21. package/lib/src/embed/embed.spec.js.map +1 -1
  22. package/lib/src/embed/ts-embed.d.ts +0 -1
  23. package/lib/src/embed/ts-embed.js +5 -16
  24. package/lib/src/embed/ts-embed.js.map +1 -1
  25. package/lib/src/index.d.ts +2 -1
  26. package/lib/src/index.js +2 -1
  27. package/lib/src/index.js.map +1 -1
  28. package/lib/src/types.d.ts +5 -0
  29. package/lib/src/types.js +5 -0
  30. package/lib/src/types.js.map +1 -1
  31. package/lib/src/utils/authService.js +4 -5
  32. package/lib/src/utils/authService.js.map +1 -1
  33. package/lib/src/utils/authService.spec.js +10 -0
  34. package/lib/src/utils/authService.spec.js.map +1 -1
  35. package/lib/src/utils/processData.d.ts +1 -1
  36. package/lib/src/utils/processData.js +27 -3
  37. package/lib/src/utils/processData.js.map +1 -1
  38. package/lib/src/utils/processData.spec.js +85 -4
  39. package/lib/src/utils/processData.spec.js.map +1 -1
  40. package/lib/src/visual-embed-sdk.d.ts +86 -5
  41. package/package.json +2 -1
  42. package/src/auth.spec.ts +67 -1
  43. package/src/auth.ts +17 -7
  44. package/src/embed/base.spec.ts +54 -3
  45. package/src/embed/base.ts +75 -16
  46. package/src/embed/embed.spec.ts +1 -1
  47. package/src/embed/ts-embed.ts +10 -19
  48. package/src/index.ts +3 -0
  49. package/src/types.ts +5 -0
  50. package/src/utils/authService.spec.ts +13 -0
  51. package/src/utils/authService.ts +3 -5
  52. package/src/utils/processData.spec.ts +114 -4
  53. package/src/utils/processData.ts +41 -4
@@ -306,6 +306,11 @@ var EmbedEvent;
306
306
  * The ThoughtSpot auth session has expired.
307
307
  */
308
308
  EmbedEvent["AuthExpire"] = "ThoughtspotAuthExpired";
309
+ /**
310
+ * ThoughtSpot failed to validate the auth session.
311
+ * @hidden
312
+ */
313
+ EmbedEvent["AuthFailure"] = "ThoughtspotAuthFailure";
309
314
  /**
310
315
  * The height of the embedded Liveboard or visualization has been computed.
311
316
  * @return data - The height of the embedded Liveboard or visualization
@@ -8686,11 +8691,355 @@ function initMixpanel(sessionInfo) {
8686
8691
  }
8687
8692
  }
8688
8693
 
8694
+ function createCommonjsModule(fn) {
8695
+ var module = { exports: {} };
8696
+ return fn(module, module.exports), module.exports;
8697
+ }
8698
+
8699
+ var eventemitter3 = createCommonjsModule(function (module) {
8700
+
8701
+ var has = Object.prototype.hasOwnProperty
8702
+ , prefix = '~';
8703
+
8704
+ /**
8705
+ * Constructor to create a storage for our `EE` objects.
8706
+ * An `Events` instance is a plain object whose properties are event names.
8707
+ *
8708
+ * @constructor
8709
+ * @private
8710
+ */
8711
+ function Events() {}
8712
+
8713
+ //
8714
+ // We try to not inherit from `Object.prototype`. In some engines creating an
8715
+ // instance in this way is faster than calling `Object.create(null)` directly.
8716
+ // If `Object.create(null)` is not supported we prefix the event names with a
8717
+ // character to make sure that the built-in object properties are not
8718
+ // overridden or used as an attack vector.
8719
+ //
8720
+ if (Object.create) {
8721
+ Events.prototype = Object.create(null);
8722
+
8723
+ //
8724
+ // This hack is needed because the `__proto__` property is still inherited in
8725
+ // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
8726
+ //
8727
+ if (!new Events().__proto__) prefix = false;
8728
+ }
8729
+
8730
+ /**
8731
+ * Representation of a single event listener.
8732
+ *
8733
+ * @param {Function} fn The listener function.
8734
+ * @param {*} context The context to invoke the listener with.
8735
+ * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
8736
+ * @constructor
8737
+ * @private
8738
+ */
8739
+ function EE(fn, context, once) {
8740
+ this.fn = fn;
8741
+ this.context = context;
8742
+ this.once = once || false;
8743
+ }
8744
+
8745
+ /**
8746
+ * Add a listener for a given event.
8747
+ *
8748
+ * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
8749
+ * @param {(String|Symbol)} event The event name.
8750
+ * @param {Function} fn The listener function.
8751
+ * @param {*} context The context to invoke the listener with.
8752
+ * @param {Boolean} once Specify if the listener is a one-time listener.
8753
+ * @returns {EventEmitter}
8754
+ * @private
8755
+ */
8756
+ function addListener(emitter, event, fn, context, once) {
8757
+ if (typeof fn !== 'function') {
8758
+ throw new TypeError('The listener must be a function');
8759
+ }
8760
+
8761
+ var listener = new EE(fn, context || emitter, once)
8762
+ , evt = prefix ? prefix + event : event;
8763
+
8764
+ if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
8765
+ else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
8766
+ else emitter._events[evt] = [emitter._events[evt], listener];
8767
+
8768
+ return emitter;
8769
+ }
8770
+
8771
+ /**
8772
+ * Clear event by name.
8773
+ *
8774
+ * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
8775
+ * @param {(String|Symbol)} evt The Event name.
8776
+ * @private
8777
+ */
8778
+ function clearEvent(emitter, evt) {
8779
+ if (--emitter._eventsCount === 0) emitter._events = new Events();
8780
+ else delete emitter._events[evt];
8781
+ }
8782
+
8783
+ /**
8784
+ * Minimal `EventEmitter` interface that is molded against the Node.js
8785
+ * `EventEmitter` interface.
8786
+ *
8787
+ * @constructor
8788
+ * @public
8789
+ */
8790
+ function EventEmitter() {
8791
+ this._events = new Events();
8792
+ this._eventsCount = 0;
8793
+ }
8794
+
8795
+ /**
8796
+ * Return an array listing the events for which the emitter has registered
8797
+ * listeners.
8798
+ *
8799
+ * @returns {Array}
8800
+ * @public
8801
+ */
8802
+ EventEmitter.prototype.eventNames = function eventNames() {
8803
+ var names = []
8804
+ , events
8805
+ , name;
8806
+
8807
+ if (this._eventsCount === 0) return names;
8808
+
8809
+ for (name in (events = this._events)) {
8810
+ if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
8811
+ }
8812
+
8813
+ if (Object.getOwnPropertySymbols) {
8814
+ return names.concat(Object.getOwnPropertySymbols(events));
8815
+ }
8816
+
8817
+ return names;
8818
+ };
8819
+
8820
+ /**
8821
+ * Return the listeners registered for a given event.
8822
+ *
8823
+ * @param {(String|Symbol)} event The event name.
8824
+ * @returns {Array} The registered listeners.
8825
+ * @public
8826
+ */
8827
+ EventEmitter.prototype.listeners = function listeners(event) {
8828
+ var evt = prefix ? prefix + event : event
8829
+ , handlers = this._events[evt];
8830
+
8831
+ if (!handlers) return [];
8832
+ if (handlers.fn) return [handlers.fn];
8833
+
8834
+ for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
8835
+ ee[i] = handlers[i].fn;
8836
+ }
8837
+
8838
+ return ee;
8839
+ };
8840
+
8841
+ /**
8842
+ * Return the number of listeners listening to a given event.
8843
+ *
8844
+ * @param {(String|Symbol)} event The event name.
8845
+ * @returns {Number} The number of listeners.
8846
+ * @public
8847
+ */
8848
+ EventEmitter.prototype.listenerCount = function listenerCount(event) {
8849
+ var evt = prefix ? prefix + event : event
8850
+ , listeners = this._events[evt];
8851
+
8852
+ if (!listeners) return 0;
8853
+ if (listeners.fn) return 1;
8854
+ return listeners.length;
8855
+ };
8856
+
8857
+ /**
8858
+ * Calls each of the listeners registered for a given event.
8859
+ *
8860
+ * @param {(String|Symbol)} event The event name.
8861
+ * @returns {Boolean} `true` if the event had listeners, else `false`.
8862
+ * @public
8863
+ */
8864
+ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
8865
+ var evt = prefix ? prefix + event : event;
8866
+
8867
+ if (!this._events[evt]) return false;
8868
+
8869
+ var listeners = this._events[evt]
8870
+ , len = arguments.length
8871
+ , args
8872
+ , i;
8873
+
8874
+ if (listeners.fn) {
8875
+ if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
8876
+
8877
+ switch (len) {
8878
+ case 1: return listeners.fn.call(listeners.context), true;
8879
+ case 2: return listeners.fn.call(listeners.context, a1), true;
8880
+ case 3: return listeners.fn.call(listeners.context, a1, a2), true;
8881
+ case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
8882
+ case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
8883
+ case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
8884
+ }
8885
+
8886
+ for (i = 1, args = new Array(len -1); i < len; i++) {
8887
+ args[i - 1] = arguments[i];
8888
+ }
8889
+
8890
+ listeners.fn.apply(listeners.context, args);
8891
+ } else {
8892
+ var length = listeners.length
8893
+ , j;
8894
+
8895
+ for (i = 0; i < length; i++) {
8896
+ if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
8897
+
8898
+ switch (len) {
8899
+ case 1: listeners[i].fn.call(listeners[i].context); break;
8900
+ case 2: listeners[i].fn.call(listeners[i].context, a1); break;
8901
+ case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
8902
+ case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
8903
+ default:
8904
+ if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
8905
+ args[j - 1] = arguments[j];
8906
+ }
8907
+
8908
+ listeners[i].fn.apply(listeners[i].context, args);
8909
+ }
8910
+ }
8911
+ }
8912
+
8913
+ return true;
8914
+ };
8915
+
8916
+ /**
8917
+ * Add a listener for a given event.
8918
+ *
8919
+ * @param {(String|Symbol)} event The event name.
8920
+ * @param {Function} fn The listener function.
8921
+ * @param {*} [context=this] The context to invoke the listener with.
8922
+ * @returns {EventEmitter} `this`.
8923
+ * @public
8924
+ */
8925
+ EventEmitter.prototype.on = function on(event, fn, context) {
8926
+ return addListener(this, event, fn, context, false);
8927
+ };
8928
+
8929
+ /**
8930
+ * Add a one-time listener for a given event.
8931
+ *
8932
+ * @param {(String|Symbol)} event The event name.
8933
+ * @param {Function} fn The listener function.
8934
+ * @param {*} [context=this] The context to invoke the listener with.
8935
+ * @returns {EventEmitter} `this`.
8936
+ * @public
8937
+ */
8938
+ EventEmitter.prototype.once = function once(event, fn, context) {
8939
+ return addListener(this, event, fn, context, true);
8940
+ };
8941
+
8942
+ /**
8943
+ * Remove the listeners of a given event.
8944
+ *
8945
+ * @param {(String|Symbol)} event The event name.
8946
+ * @param {Function} fn Only remove the listeners that match this function.
8947
+ * @param {*} context Only remove the listeners that have this context.
8948
+ * @param {Boolean} once Only remove one-time listeners.
8949
+ * @returns {EventEmitter} `this`.
8950
+ * @public
8951
+ */
8952
+ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
8953
+ var evt = prefix ? prefix + event : event;
8954
+
8955
+ if (!this._events[evt]) return this;
8956
+ if (!fn) {
8957
+ clearEvent(this, evt);
8958
+ return this;
8959
+ }
8960
+
8961
+ var listeners = this._events[evt];
8962
+
8963
+ if (listeners.fn) {
8964
+ if (
8965
+ listeners.fn === fn &&
8966
+ (!once || listeners.once) &&
8967
+ (!context || listeners.context === context)
8968
+ ) {
8969
+ clearEvent(this, evt);
8970
+ }
8971
+ } else {
8972
+ for (var i = 0, events = [], length = listeners.length; i < length; i++) {
8973
+ if (
8974
+ listeners[i].fn !== fn ||
8975
+ (once && !listeners[i].once) ||
8976
+ (context && listeners[i].context !== context)
8977
+ ) {
8978
+ events.push(listeners[i]);
8979
+ }
8980
+ }
8981
+
8982
+ //
8983
+ // Reset the array, or remove it completely if we have no more listeners.
8984
+ //
8985
+ if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
8986
+ else clearEvent(this, evt);
8987
+ }
8988
+
8989
+ return this;
8990
+ };
8991
+
8992
+ /**
8993
+ * Remove all listeners, or those of the specified event.
8994
+ *
8995
+ * @param {(String|Symbol)} [event] The event name.
8996
+ * @returns {EventEmitter} `this`.
8997
+ * @public
8998
+ */
8999
+ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
9000
+ var evt;
9001
+
9002
+ if (event) {
9003
+ evt = prefix ? prefix + event : event;
9004
+ if (this._events[evt]) clearEvent(this, evt);
9005
+ } else {
9006
+ this._events = new Events();
9007
+ this._eventsCount = 0;
9008
+ }
9009
+
9010
+ return this;
9011
+ };
9012
+
9013
+ //
9014
+ // Alias methods names because people roll like that.
9015
+ //
9016
+ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
9017
+ EventEmitter.prototype.addListener = EventEmitter.prototype.on;
9018
+
9019
+ //
9020
+ // Expose the prefix.
9021
+ //
9022
+ EventEmitter.prefixed = prefix;
9023
+
9024
+ //
9025
+ // Allow `EventEmitter` to be imported as module namespace.
9026
+ //
9027
+ EventEmitter.EventEmitter = EventEmitter;
9028
+
9029
+ //
9030
+ // Expose the module.
9031
+ //
9032
+ {
9033
+ module.exports = EventEmitter;
9034
+ }
9035
+ });
9036
+
8689
9037
  // eslint-disable-next-line import/no-cycle
8690
9038
  function failureLoggedFetch(url, options = {}) {
8691
9039
  return fetch(url, options).then(async (r) => {
8692
- if (!r.ok && r.type !== 'opaqueredirect') {
8693
- console.error('Failure', await r.text());
9040
+ var _a;
9041
+ if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
9042
+ console.error('Failure', await ((_a = r.text) === null || _a === void 0 ? void 0 : _a.call(r)));
8694
9043
  }
8695
9044
  return r;
8696
9045
  });
@@ -8724,9 +9073,7 @@ async function fetchBasicAuthService(thoughtSpotHost, username, password) {
8724
9073
  async function fetchLogoutService(thoughtSpotHost) {
8725
9074
  return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
8726
9075
  credentials: 'include',
8727
- headers: {
8728
- 'x-requested-by': 'ThoughtSpot',
8729
- },
9076
+ mode: 'no-cors',
8730
9077
  });
8731
9078
  }
8732
9079
 
@@ -8747,6 +9094,19 @@ const EndPoints = {
8747
9094
  BASIC_LOGIN: '/callosum/v1/session/login',
8748
9095
  LOGOUT: '/callosum/v1/session/logout',
8749
9096
  };
9097
+ var AuthFailureType;
9098
+ (function (AuthFailureType) {
9099
+ AuthFailureType["SDK"] = "SDK";
9100
+ AuthFailureType["NO_COOKIE_ACCESS"] = "NO_COOKIE_ACCESS";
9101
+ AuthFailureType["EXPIRY"] = "EXPIRY";
9102
+ AuthFailureType["OTHER"] = "OTHER";
9103
+ })(AuthFailureType || (AuthFailureType = {}));
9104
+ var AuthStatus;
9105
+ (function (AuthStatus) {
9106
+ AuthStatus["FAILURE"] = "FAILURE";
9107
+ AuthStatus["SUCCESS"] = "SUCCESS";
9108
+ AuthStatus["LOGOUT"] = "LOGOUT";
9109
+ })(AuthStatus || (AuthStatus = {}));
8750
9110
  /**
8751
9111
  * Check if we are logged into the ThoughtSpot cluster
8752
9112
  * @param thoughtSpotHost The ThoughtSpot cluster hostname or IP
@@ -8802,8 +9162,8 @@ const doTokenAuth = async (embedConfig) => {
8802
9162
  if (!authEndpoint && !getAuthToken) {
8803
9163
  throw new Error('Either auth endpoint or getAuthToken function must be provided');
8804
9164
  }
8805
- const loggedIn = await isLoggedIn(thoughtSpotHost);
8806
- if (!loggedIn) {
9165
+ loggedInStatus = await isLoggedIn(thoughtSpotHost);
9166
+ if (!loggedInStatus) {
8807
9167
  let authToken = null;
8808
9168
  if (getAuthToken) {
8809
9169
  authToken = await getAuthToken();
@@ -8817,9 +9177,6 @@ const doTokenAuth = async (embedConfig) => {
8817
9177
  // token login issues a 302 when successful
8818
9178
  loggedInStatus = resp.ok || resp.type === 'opaqueredirect';
8819
9179
  }
8820
- else {
8821
- loggedInStatus = true;
8822
- }
8823
9180
  return loggedInStatus;
8824
9181
  };
8825
9182
  /**
@@ -8890,6 +9247,7 @@ const doSSOAuth = async (embedConfig, ssoEndPoint) => {
8890
9247
  const ssoURL = `${thoughtSpotHost}${ssoEndPoint}`;
8891
9248
  if (embedConfig.noRedirect) {
8892
9249
  await samlPopupFlow(ssoURL);
9250
+ loggedInStatus = true;
8893
9251
  return;
8894
9252
  }
8895
9253
  window.location.href = ssoURL;
@@ -8921,9 +9279,7 @@ const doOIDCAuth = async (embedConfig) => {
8921
9279
  const logout = async (embedConfig) => {
8922
9280
  const { thoughtSpotHost } = embedConfig;
8923
9281
  const response = await fetchLogoutService(thoughtSpotHost);
8924
- if (response.ok || response.status === 401) {
8925
- loggedInStatus = false;
8926
- }
9282
+ loggedInStatus = false;
8927
9283
  return loggedInStatus;
8928
9284
  };
8929
9285
  /**
@@ -8948,20 +9304,49 @@ const authenticate = async (embedConfig) => {
8948
9304
 
8949
9305
  /* eslint-disable import/no-mutable-exports */
8950
9306
  let config = {};
9307
+ const CONFIG_DEFAULTS = {
9308
+ loginFailedMessage: 'Login failed',
9309
+ authType: AuthType.None,
9310
+ };
8951
9311
  let authPromise;
9312
+ const getEmbedConfig = () => config;
9313
+ const getAuthPromise = () => authPromise;
9314
+ let authEE;
9315
+ function notifyAuthSuccess() {
9316
+ if (!authEE) {
9317
+ console.error('SDK not initialized');
9318
+ return;
9319
+ }
9320
+ authEE.emit(AuthStatus.SUCCESS);
9321
+ }
9322
+ function notifyAuthFailure(failureType) {
9323
+ if (!authEE) {
9324
+ console.error('SDK not initialized');
9325
+ return;
9326
+ }
9327
+ authEE.emit(AuthStatus.FAILURE, failureType);
9328
+ }
9329
+ function notifyLogout() {
9330
+ if (!authEE) {
9331
+ console.error('SDK not initialized');
9332
+ return;
9333
+ }
9334
+ authEE.emit(AuthStatus.LOGOUT);
9335
+ }
8952
9336
  /**
8953
9337
  * Perform authentication on the ThoughtSpot app as applicable.
8954
9338
  */
8955
9339
  const handleAuth = () => {
8956
- const authConfig = {
8957
- ...config,
8958
- thoughtSpotHost: getThoughtSpotHost(config),
8959
- };
8960
- authPromise = authenticate(authConfig);
9340
+ authPromise = authenticate(config);
9341
+ authPromise.then((isLoggedIn) => {
9342
+ if (!isLoggedIn) {
9343
+ notifyAuthFailure(AuthFailureType.SDK);
9344
+ }
9345
+ }, () => {
9346
+ notifyAuthFailure(AuthFailureType.SDK);
9347
+ });
8961
9348
  return authPromise;
8962
9349
  };
8963
- const getEmbedConfig = () => config;
8964
- const getAuthPromise = () => authPromise;
8965
9350
  /**
8966
9351
  * Prefetches static resources from the specified URL. Web browsers can then cache the prefetched resources and serve them from the user's local disk to provide faster access to your app.
8967
9352
  * @param url The URL provided for prefetch
@@ -8990,7 +9375,12 @@ const prefetch = (url) => {
8990
9375
  * @returns authPromise Promise which resolves when authentication is complete.
8991
9376
  */
8992
9377
  const init = (embedConfig) => {
8993
- config = embedConfig;
9378
+ config = {
9379
+ ...CONFIG_DEFAULTS,
9380
+ ...embedConfig,
9381
+ thoughtSpotHost: getThoughtSpotHost(embedConfig),
9382
+ };
9383
+ authEE = new eventemitter3();
8994
9384
  handleAuth();
8995
9385
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_CALLED_INIT, {
8996
9386
  authType: config.authType,
@@ -8999,10 +9389,16 @@ const init = (embedConfig) => {
8999
9389
  if (config.callPrefetch) {
9000
9390
  prefetch(config.thoughtSpotHost);
9001
9391
  }
9002
- return authPromise;
9392
+ return authEE;
9003
9393
  };
9004
- const logout$1 = () => {
9005
- return logout(config);
9394
+ const logout$1 = (doNotDisableAutoLogin = false) => {
9395
+ if (!doNotDisableAutoLogin) {
9396
+ config.autoLogin = false;
9397
+ }
9398
+ return logout(config).then((isLoggedIn) => {
9399
+ notifyLogout();
9400
+ return isLoggedIn;
9401
+ });
9006
9402
  };
9007
9403
  let renderQueue = Promise.resolve();
9008
9404
  /**
@@ -9088,6 +9484,7 @@ function processAuthInit(e) {
9088
9484
  var _a, _b;
9089
9485
  // Store user session details sent by app.
9090
9486
  initSession(e.data);
9487
+ notifyAuthSuccess();
9091
9488
  // Expose only allowed details (eg: userGUID) back to SDK users.
9092
9489
  return {
9093
9490
  ...e,
@@ -9101,9 +9498,28 @@ function processAuthExpire(e) {
9101
9498
  if (autoLogin) {
9102
9499
  handleAuth();
9103
9500
  }
9501
+ notifyAuthFailure(AuthFailureType.EXPIRY);
9502
+ return e;
9503
+ }
9504
+ function processNoCookieAccess(e, containerEl) {
9505
+ const { loginFailedMessage, suppressNoCookieAccessAlert, } = getEmbedConfig();
9506
+ if (!suppressNoCookieAccessAlert) {
9507
+ // eslint-disable-next-line no-alert
9508
+ alert('Third party cookie access is blocked on this browser, please allow third party cookies for this to work properly. \nYou can use `suppressNoCookieAccessAlert` to suppress this message.');
9509
+ }
9510
+ // eslint-disable-next-line no-param-reassign
9511
+ containerEl.innerHTML = loginFailedMessage;
9512
+ notifyAuthFailure(AuthFailureType.NO_COOKIE_ACCESS);
9104
9513
  return e;
9105
9514
  }
9106
- function getProcessData(type, e, thoughtSpotHost) {
9515
+ function processAuthFailure(e, containerEl) {
9516
+ const { loginFailedMessage } = getEmbedConfig();
9517
+ // eslint-disable-next-line no-param-reassign
9518
+ containerEl.innerHTML = loginFailedMessage;
9519
+ notifyAuthFailure(AuthFailureType.OTHER);
9520
+ return e;
9521
+ }
9522
+ function processEventData(type, e, thoughtSpotHost, containerEl) {
9107
9523
  switch (type) {
9108
9524
  case EmbedEvent.CustomAction:
9109
9525
  return processCustomAction(e, thoughtSpotHost);
@@ -9111,6 +9527,10 @@ function getProcessData(type, e, thoughtSpotHost) {
9111
9527
  return processAuthInit(e);
9112
9528
  case EmbedEvent.AuthExpire:
9113
9529
  return processAuthExpire(e);
9530
+ case EmbedEvent.NoCookieAccess:
9531
+ return processNoCookieAccess(e, containerEl);
9532
+ case EmbedEvent.AuthFailure:
9533
+ return processAuthFailure(e, containerEl);
9114
9534
  }
9115
9535
  return e;
9116
9536
  }
@@ -9139,7 +9559,7 @@ function processTrigger(iFrame, messageType, thoughtSpotHost, data) {
9139
9559
  }
9140
9560
  }
9141
9561
 
9142
- var name="@thoughtspot/visual-embed-sdk";var version="1.11.0-auth.10";var description="ThoughtSpot Embed SDK";var module="lib/src/index.js";var main="dist/tsembed.js";var types="lib/src/index.d.ts";var files=["dist/**","lib/**","src/**"];var exports={".":"./lib/src/index.js","./react":"./lib/src/react/index.js"};var scripts={lint:"eslint 'src/**'","lint:fix":"eslint 'src/**/*.*' --fix",tsc:"tsc -p . --incremental false",start:"gatsby develop","build:gatsby":"npm run clean:gatsby && gatsby build --prefix-paths","build:gatsby:noprefix":"npm run clean:gatsby && gatsby build","serve:gatsby":"gatsby serve","clean:gatsby":"gatsby clean","build-and-publish":"npm run build:gatsby && npm run publish","bundle-dts":"dts-bundle --name @thoughtspot/visual-embed-sdk --out visual-embed-sdk.d.ts --main lib/src/index.d.ts",build:"rollup -c",watch:"rollup -cw","docs-cmd":"node scripts/gatsby-commands.js",docgen:"typedoc --tsconfig tsconfig.json --theme typedoc-theme","test-sdk":"jest -c jest.config.sdk.js","test-docs":"jest -c jest.config.docs.js",test:"npm run test-sdk && npm run test-docs && npx istanbul-merge --out ./coverage/coverage.json ./coverage/docs/coverage-final.json ./coverage/sdk/coverage-final.json && npx istanbul report --include ./coverage/coverage.json --dir ./coverage lcov",posttest:"cat ./coverage/sdk/lcov.info | coveralls",prepublishOnly:"npm run test; npm run tsc; npm run bundle-dts; npm run build","publish-dev":"npm publish --tag dev","publish-prod":"npm publish --tag latest"};var peerDependencies={react:"> 16.8.0","react-dom":"> 16.8.0"};var dependencies={algoliasearch:"^4.10.5",classnames:"^2.3.1","mixpanel-browser":"^2.41.0"};var devDependencies={"@mdx-js/mdx":"^1.6.22","@mdx-js/react":"^1.6.22","@react-icons/all-files":"^4.1.0","@rollup/plugin-commonjs":"^18.0.0","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^11.2.1","@testing-library/dom":"^7.31.0","@testing-library/jest-dom":"^5.14.1","@testing-library/react":"^11.2.7","@testing-library/user-event":"^13.1.8","@types/jest":"^22.2.3","@types/mixpanel-browser":"^2.35.6","@types/react-test-renderer":"^17.0.1","@typescript-eslint/eslint-plugin":"^4.6.0","@typescript-eslint/parser":"^4.6.0",asciidoctor:"^2.2.1","babel-jest":"^26.6.3","babel-preset-gatsby":"^1.10.0","command-line-args":"^5.1.1",coveralls:"^3.1.0","dts-bundle":"0.7.3",eslint:"^7.12.1","eslint-config-airbnb-base":"^14.2.0","eslint-config-prettier":"^6.15.0","eslint-import-resolver-typescript":"^2.3.0","eslint-plugin-import":"^2.22.1","eslint-plugin-prettier":"^3.1.4","eslint-plugin-react-hooks":"^4.2.0","fs-extra":"^10.0.0",gatsby:"3.1.0","gatsby-plugin-algolia":"^0.22.2","gatsby-plugin-catch-links":"^3.1.0","gatsby-plugin-env-variables":"^2.1.0","gatsby-plugin-intl":"^0.3.3","gatsby-plugin-manifest":"^3.2.0","gatsby-plugin-output":"^0.1.3","gatsby-plugin-sass":"4.1.0","gatsby-plugin-sitemap":"^4.10.0","gatsby-source-filesystem":"3.1.0","gatsby-transformer-asciidoc":"2.1.0","gatsby-transformer-rehype":"2.0.0","gh-pages":"^3.1.0","highlight.js":"^10.6.0","html-to-text":"^8.0.0","identity-obj-proxy":"^3.0.0","istanbul-merge":"^1.1.1",jest:"^26.6.3","jest-puppeteer":"^4.4.0",jsdom:"^17.0.0","node-sass":"^4.0.0",prettier:"2.1.2",puppeteer:"^7.0.1",react:"^16.14.0","react-dom":"^16.14.0","react-resizable":"^1.11.0","react-resize-detector":"^6.6.0","react-test-renderer":"^17.0.2","react-use-flexsearch":"^0.1.1",rollup:"2.30.0","rollup-plugin-typescript2":"0.27.3","ts-jest":"^26.5.5","ts-loader":"8.0.4",typedoc:"0.21.6","typedoc-neo-theme":"^1.1.0","typedoc-plugin-toc-group":"0.0.5",typescript:"^4.1.0","url-search-params-polyfill":"^8.1.0",util:"^0.12.4"};var author="ThoughtSpot";var email="support@thoughtspot.com";var license="ThoughtSpot Development Tools End User License Agreement";var directories={lib:"lib"};var repository={type:"git",url:"git+https://github.com/thoughtspot/visual-embed-sdk.git"};var publishConfig={registry:"https://registry.npmjs.org"};var keywords=["thoughtspot","everywhere","embed","sdk","analytics"];var bugs={url:"https://github.com/thoughtspot/visual-embed-sdk/issues"};var homepage="https://github.com/thoughtspot/visual-embed-sdk#readme";var globals={window:{}};var pkgInfo = {name:name,version:version,description:description,module:module,main:main,types:types,files:files,exports:exports,scripts:scripts,peerDependencies:peerDependencies,dependencies:dependencies,devDependencies:devDependencies,author:author,email:email,license:license,directories:directories,repository:repository,publishConfig:publishConfig,keywords:keywords,bugs:bugs,homepage:homepage,globals:globals};
9562
+ var name="@thoughtspot/visual-embed-sdk";var version="1.11.0-auth.13";var description="ThoughtSpot Embed SDK";var module="lib/src/index.js";var main="dist/tsembed.js";var types="lib/src/index.d.ts";var files=["dist/**","lib/**","src/**"];var exports={".":"./lib/src/index.js","./react":"./lib/src/react/index.js"};var scripts={lint:"eslint 'src/**'","lint:fix":"eslint 'src/**/*.*' --fix",tsc:"tsc -p . --incremental false",start:"gatsby develop","build:gatsby":"npm run clean:gatsby && gatsby build --prefix-paths","build:gatsby:noprefix":"npm run clean:gatsby && gatsby build","serve:gatsby":"gatsby serve","clean:gatsby":"gatsby clean","build-and-publish":"npm run build:gatsby && npm run publish","bundle-dts":"dts-bundle --name @thoughtspot/visual-embed-sdk --out visual-embed-sdk.d.ts --main lib/src/index.d.ts",build:"rollup -c",watch:"rollup -cw","docs-cmd":"node scripts/gatsby-commands.js",docgen:"typedoc --tsconfig tsconfig.json --theme typedoc-theme","test-sdk":"jest -c jest.config.sdk.js","test-docs":"jest -c jest.config.docs.js",test:"npm run test-sdk && npm run test-docs && npx istanbul-merge --out ./coverage/coverage.json ./coverage/docs/coverage-final.json ./coverage/sdk/coverage-final.json && npx istanbul report --include ./coverage/coverage.json --dir ./coverage lcov",posttest:"cat ./coverage/sdk/lcov.info | coveralls",prepublishOnly:"npm run test; npm run tsc; npm run bundle-dts; npm run build","publish-dev":"npm publish --tag dev","publish-prod":"npm publish --tag latest"};var peerDependencies={react:"> 16.8.0","react-dom":"> 16.8.0"};var dependencies={algoliasearch:"^4.10.5",classnames:"^2.3.1",eventemitter3:"^4.0.7","mixpanel-browser":"^2.41.0"};var devDependencies={"@mdx-js/mdx":"^1.6.22","@mdx-js/react":"^1.6.22","@react-icons/all-files":"^4.1.0","@rollup/plugin-commonjs":"^18.0.0","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^11.2.1","@testing-library/dom":"^7.31.0","@testing-library/jest-dom":"^5.14.1","@testing-library/react":"^11.2.7","@testing-library/user-event":"^13.1.8","@types/jest":"^22.2.3","@types/mixpanel-browser":"^2.35.6","@types/react-test-renderer":"^17.0.1","@typescript-eslint/eslint-plugin":"^4.6.0","@typescript-eslint/parser":"^4.6.0",asciidoctor:"^2.2.1","babel-jest":"^26.6.3","babel-preset-gatsby":"^1.10.0","command-line-args":"^5.1.1",coveralls:"^3.1.0","dts-bundle":"0.7.3",eslint:"^7.12.1","eslint-config-airbnb-base":"^14.2.0","eslint-config-prettier":"^6.15.0","eslint-import-resolver-typescript":"^2.3.0","eslint-plugin-import":"^2.22.1","eslint-plugin-prettier":"^3.1.4","eslint-plugin-react-hooks":"^4.2.0","fs-extra":"^10.0.0",gatsby:"3.1.0","gatsby-plugin-algolia":"^0.22.2","gatsby-plugin-catch-links":"^3.1.0","gatsby-plugin-env-variables":"^2.1.0","gatsby-plugin-intl":"^0.3.3","gatsby-plugin-manifest":"^3.2.0","gatsby-plugin-output":"^0.1.3","gatsby-plugin-sass":"4.1.0","gatsby-plugin-sitemap":"^4.10.0","gatsby-source-filesystem":"3.1.0","gatsby-transformer-asciidoc":"2.1.0","gatsby-transformer-rehype":"2.0.0","gh-pages":"^3.1.0","highlight.js":"^10.6.0","html-to-text":"^8.0.0","identity-obj-proxy":"^3.0.0","istanbul-merge":"^1.1.1",jest:"^26.6.3","jest-puppeteer":"^4.4.0",jsdom:"^17.0.0","node-sass":"^4.0.0",prettier:"2.1.2",puppeteer:"^7.0.1",react:"^16.14.0","react-dom":"^16.14.0","react-resizable":"^1.11.0","react-resize-detector":"^6.6.0","react-test-renderer":"^17.0.2","react-use-flexsearch":"^0.1.1",rollup:"2.30.0","rollup-plugin-typescript2":"0.27.3","ts-jest":"^26.5.5","ts-loader":"8.0.4",typedoc:"0.21.6","typedoc-neo-theme":"^1.1.0","typedoc-plugin-toc-group":"0.0.5",typescript:"^4.1.0","url-search-params-polyfill":"^8.1.0",util:"^0.12.4"};var author="ThoughtSpot";var email="support@thoughtspot.com";var license="ThoughtSpot Development Tools End User License Agreement";var directories={lib:"lib"};var repository={type:"git",url:"git+https://github.com/thoughtspot/visual-embed-sdk.git"};var publishConfig={registry:"https://registry.npmjs.org"};var keywords=["thoughtspot","everywhere","embed","sdk","analytics"];var bugs={url:"https://github.com/thoughtspot/visual-embed-sdk/issues"};var homepage="https://github.com/thoughtspot/visual-embed-sdk#readme";var globals={window:{}};var pkgInfo = {name:name,version:version,description:description,module:module,main:main,types:types,files:files,exports:exports,scripts:scripts,peerDependencies:peerDependencies,dependencies:dependencies,devDependencies:devDependencies,author:author,email:email,license:license,directories:directories,repository:repository,publishConfig:publishConfig,keywords:keywords,bugs:bugs,homepage:homepage,globals:globals};
9143
9563
 
9144
9564
  /**
9145
9565
  * Copyright (c) 2022
@@ -9186,17 +9606,6 @@ class TsEmbed {
9186
9606
  this.isError = false;
9187
9607
  this.viewConfig = viewConfig;
9188
9608
  this.shouldEncodeUrlQueryParams = this.embedConfig.shouldEncodeUrlQueryParams;
9189
- this.on(EmbedEvent.NoCookieAccess, () => {
9190
- if (!this.embedConfig.suppressNoCookieAccessAlert) {
9191
- // eslint-disable-next-line no-alert
9192
- alert('Third party cookie access is blocked on this browser, please allow third party cookies for this to work properly. \nYou can use `suppressNoCookieAccessAlert` to suppress this message.');
9193
- }
9194
- this.el.innerHTML = this.getLoginFiledMessage();
9195
- });
9196
- }
9197
- getLoginFiledMessage() {
9198
- const { loginFailedMessage } = this.embedConfig;
9199
- return loginFailedMessage || 'Login failed';
9200
9609
  }
9201
9610
  /**
9202
9611
  * Gets a reference to the root DOM node where
@@ -9273,7 +9682,7 @@ class TsEmbed {
9273
9682
  const eventPort = this.getEventPort(event);
9274
9683
  const eventData = this.formatEventData(event, eventType);
9275
9684
  if (event.source === this.iFrame.contentWindow) {
9276
- this.executeCallbacks(eventType, getProcessData(eventType, eventData, this.thoughtSpotHost), eventPort);
9685
+ this.executeCallbacks(eventType, processEventData(eventType, eventData, this.thoughtSpotHost, this.el), eventPort);
9277
9686
  }
9278
9687
  });
9279
9688
  }
@@ -9394,7 +9803,7 @@ class TsEmbed {
9394
9803
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_START);
9395
9804
  (_a = getAuthPromise()) === null || _a === void 0 ? void 0 : _a.then((isLoggedIn) => {
9396
9805
  if (!isLoggedIn) {
9397
- this.el.innerHTML = this.getLoginFiledMessage();
9806
+ this.el.innerHTML = this.embedConfig.loginFailedMessage;
9398
9807
  return;
9399
9808
  }
9400
9809
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_COMPLETE);
@@ -9412,7 +9821,7 @@ class TsEmbed {
9412
9821
  this.iFrame.mozallowfullscreen = true;
9413
9822
  const { height: frameHeight, width: frameWidth, ...restParams } = frameOptions;
9414
9823
  const width = getCssDimension(frameWidth || DEFAULT_EMBED_WIDTH);
9415
- const height = getCssDimension(frameWidth || DEFAULT_EMBED_HEIGHT);
9824
+ const height = getCssDimension(frameHeight || DEFAULT_EMBED_HEIGHT);
9416
9825
  setAttributes(this.iFrame, restParams);
9417
9826
  this.iFrame.style.width = `${width}`;
9418
9827
  this.iFrame.style.height = `${height}`;
@@ -9446,7 +9855,7 @@ class TsEmbed {
9446
9855
  }).catch((error) => {
9447
9856
  nextInQueue();
9448
9857
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_FAILED);
9449
- this.el.innerHTML = this.getLoginFiledMessage();
9858
+ this.el.innerHTML = this.embedConfig.loginFailedMessage;
9450
9859
  this.handleError(error);
9451
9860
  });
9452
9861
  });
@@ -10018,4 +10427,4 @@ class SearchEmbed extends TsEmbed {
10018
10427
  }
10019
10428
  }
10020
10429
 
10021
- export { Action, AppEmbed, AuthType, DataSourceVisualMode, EmbedEvent, HostEvent, LiveboardEmbed, Page, PinboardEmbed, RuntimeFilterOp, SearchEmbed, init, logout$1 as logout, prefetch };
10430
+ export { Action, AppEmbed, AuthFailureType, AuthStatus, AuthType, DataSourceVisualMode, EmbedEvent, HostEvent, LiveboardEmbed, Page, PinboardEmbed, RuntimeFilterOp, SearchEmbed, init, logout$1 as logout, prefetch };