@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
package/dist/tsembed.js CHANGED
@@ -296,6 +296,11 @@
296
296
  * The ThoughtSpot auth session has expired.
297
297
  */
298
298
  EmbedEvent["AuthExpire"] = "ThoughtspotAuthExpired";
299
+ /**
300
+ * ThoughtSpot failed to validate the auth session.
301
+ * @hidden
302
+ */
303
+ EmbedEvent["AuthFailure"] = "ThoughtspotAuthFailure";
299
304
  /**
300
305
  * The height of the embedded Liveboard or visualization has been computed.
301
306
  * @return data - The height of the embedded Liveboard or visualization
@@ -8655,11 +8660,355 @@
8655
8660
  }
8656
8661
  }
8657
8662
 
8663
+ function createCommonjsModule(fn) {
8664
+ var module = { exports: {} };
8665
+ return fn(module, module.exports), module.exports;
8666
+ }
8667
+
8668
+ var eventemitter3 = createCommonjsModule(function (module) {
8669
+
8670
+ var has = Object.prototype.hasOwnProperty
8671
+ , prefix = '~';
8672
+
8673
+ /**
8674
+ * Constructor to create a storage for our `EE` objects.
8675
+ * An `Events` instance is a plain object whose properties are event names.
8676
+ *
8677
+ * @constructor
8678
+ * @private
8679
+ */
8680
+ function Events() {}
8681
+
8682
+ //
8683
+ // We try to not inherit from `Object.prototype`. In some engines creating an
8684
+ // instance in this way is faster than calling `Object.create(null)` directly.
8685
+ // If `Object.create(null)` is not supported we prefix the event names with a
8686
+ // character to make sure that the built-in object properties are not
8687
+ // overridden or used as an attack vector.
8688
+ //
8689
+ if (Object.create) {
8690
+ Events.prototype = Object.create(null);
8691
+
8692
+ //
8693
+ // This hack is needed because the `__proto__` property is still inherited in
8694
+ // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
8695
+ //
8696
+ if (!new Events().__proto__) prefix = false;
8697
+ }
8698
+
8699
+ /**
8700
+ * Representation of a single event listener.
8701
+ *
8702
+ * @param {Function} fn The listener function.
8703
+ * @param {*} context The context to invoke the listener with.
8704
+ * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
8705
+ * @constructor
8706
+ * @private
8707
+ */
8708
+ function EE(fn, context, once) {
8709
+ this.fn = fn;
8710
+ this.context = context;
8711
+ this.once = once || false;
8712
+ }
8713
+
8714
+ /**
8715
+ * Add a listener for a given event.
8716
+ *
8717
+ * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
8718
+ * @param {(String|Symbol)} event The event name.
8719
+ * @param {Function} fn The listener function.
8720
+ * @param {*} context The context to invoke the listener with.
8721
+ * @param {Boolean} once Specify if the listener is a one-time listener.
8722
+ * @returns {EventEmitter}
8723
+ * @private
8724
+ */
8725
+ function addListener(emitter, event, fn, context, once) {
8726
+ if (typeof fn !== 'function') {
8727
+ throw new TypeError('The listener must be a function');
8728
+ }
8729
+
8730
+ var listener = new EE(fn, context || emitter, once)
8731
+ , evt = prefix ? prefix + event : event;
8732
+
8733
+ if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
8734
+ else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
8735
+ else emitter._events[evt] = [emitter._events[evt], listener];
8736
+
8737
+ return emitter;
8738
+ }
8739
+
8740
+ /**
8741
+ * Clear event by name.
8742
+ *
8743
+ * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
8744
+ * @param {(String|Symbol)} evt The Event name.
8745
+ * @private
8746
+ */
8747
+ function clearEvent(emitter, evt) {
8748
+ if (--emitter._eventsCount === 0) emitter._events = new Events();
8749
+ else delete emitter._events[evt];
8750
+ }
8751
+
8752
+ /**
8753
+ * Minimal `EventEmitter` interface that is molded against the Node.js
8754
+ * `EventEmitter` interface.
8755
+ *
8756
+ * @constructor
8757
+ * @public
8758
+ */
8759
+ function EventEmitter() {
8760
+ this._events = new Events();
8761
+ this._eventsCount = 0;
8762
+ }
8763
+
8764
+ /**
8765
+ * Return an array listing the events for which the emitter has registered
8766
+ * listeners.
8767
+ *
8768
+ * @returns {Array}
8769
+ * @public
8770
+ */
8771
+ EventEmitter.prototype.eventNames = function eventNames() {
8772
+ var names = []
8773
+ , events
8774
+ , name;
8775
+
8776
+ if (this._eventsCount === 0) return names;
8777
+
8778
+ for (name in (events = this._events)) {
8779
+ if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
8780
+ }
8781
+
8782
+ if (Object.getOwnPropertySymbols) {
8783
+ return names.concat(Object.getOwnPropertySymbols(events));
8784
+ }
8785
+
8786
+ return names;
8787
+ };
8788
+
8789
+ /**
8790
+ * Return the listeners registered for a given event.
8791
+ *
8792
+ * @param {(String|Symbol)} event The event name.
8793
+ * @returns {Array} The registered listeners.
8794
+ * @public
8795
+ */
8796
+ EventEmitter.prototype.listeners = function listeners(event) {
8797
+ var evt = prefix ? prefix + event : event
8798
+ , handlers = this._events[evt];
8799
+
8800
+ if (!handlers) return [];
8801
+ if (handlers.fn) return [handlers.fn];
8802
+
8803
+ for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
8804
+ ee[i] = handlers[i].fn;
8805
+ }
8806
+
8807
+ return ee;
8808
+ };
8809
+
8810
+ /**
8811
+ * Return the number of listeners listening to a given event.
8812
+ *
8813
+ * @param {(String|Symbol)} event The event name.
8814
+ * @returns {Number} The number of listeners.
8815
+ * @public
8816
+ */
8817
+ EventEmitter.prototype.listenerCount = function listenerCount(event) {
8818
+ var evt = prefix ? prefix + event : event
8819
+ , listeners = this._events[evt];
8820
+
8821
+ if (!listeners) return 0;
8822
+ if (listeners.fn) return 1;
8823
+ return listeners.length;
8824
+ };
8825
+
8826
+ /**
8827
+ * Calls each of the listeners registered for a given event.
8828
+ *
8829
+ * @param {(String|Symbol)} event The event name.
8830
+ * @returns {Boolean} `true` if the event had listeners, else `false`.
8831
+ * @public
8832
+ */
8833
+ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
8834
+ var evt = prefix ? prefix + event : event;
8835
+
8836
+ if (!this._events[evt]) return false;
8837
+
8838
+ var listeners = this._events[evt]
8839
+ , len = arguments.length
8840
+ , args
8841
+ , i;
8842
+
8843
+ if (listeners.fn) {
8844
+ if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
8845
+
8846
+ switch (len) {
8847
+ case 1: return listeners.fn.call(listeners.context), true;
8848
+ case 2: return listeners.fn.call(listeners.context, a1), true;
8849
+ case 3: return listeners.fn.call(listeners.context, a1, a2), true;
8850
+ case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
8851
+ case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
8852
+ case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
8853
+ }
8854
+
8855
+ for (i = 1, args = new Array(len -1); i < len; i++) {
8856
+ args[i - 1] = arguments[i];
8857
+ }
8858
+
8859
+ listeners.fn.apply(listeners.context, args);
8860
+ } else {
8861
+ var length = listeners.length
8862
+ , j;
8863
+
8864
+ for (i = 0; i < length; i++) {
8865
+ if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
8866
+
8867
+ switch (len) {
8868
+ case 1: listeners[i].fn.call(listeners[i].context); break;
8869
+ case 2: listeners[i].fn.call(listeners[i].context, a1); break;
8870
+ case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
8871
+ case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
8872
+ default:
8873
+ if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
8874
+ args[j - 1] = arguments[j];
8875
+ }
8876
+
8877
+ listeners[i].fn.apply(listeners[i].context, args);
8878
+ }
8879
+ }
8880
+ }
8881
+
8882
+ return true;
8883
+ };
8884
+
8885
+ /**
8886
+ * Add a listener for a given event.
8887
+ *
8888
+ * @param {(String|Symbol)} event The event name.
8889
+ * @param {Function} fn The listener function.
8890
+ * @param {*} [context=this] The context to invoke the listener with.
8891
+ * @returns {EventEmitter} `this`.
8892
+ * @public
8893
+ */
8894
+ EventEmitter.prototype.on = function on(event, fn, context) {
8895
+ return addListener(this, event, fn, context, false);
8896
+ };
8897
+
8898
+ /**
8899
+ * Add a one-time listener for a given event.
8900
+ *
8901
+ * @param {(String|Symbol)} event The event name.
8902
+ * @param {Function} fn The listener function.
8903
+ * @param {*} [context=this] The context to invoke the listener with.
8904
+ * @returns {EventEmitter} `this`.
8905
+ * @public
8906
+ */
8907
+ EventEmitter.prototype.once = function once(event, fn, context) {
8908
+ return addListener(this, event, fn, context, true);
8909
+ };
8910
+
8911
+ /**
8912
+ * Remove the listeners of a given event.
8913
+ *
8914
+ * @param {(String|Symbol)} event The event name.
8915
+ * @param {Function} fn Only remove the listeners that match this function.
8916
+ * @param {*} context Only remove the listeners that have this context.
8917
+ * @param {Boolean} once Only remove one-time listeners.
8918
+ * @returns {EventEmitter} `this`.
8919
+ * @public
8920
+ */
8921
+ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
8922
+ var evt = prefix ? prefix + event : event;
8923
+
8924
+ if (!this._events[evt]) return this;
8925
+ if (!fn) {
8926
+ clearEvent(this, evt);
8927
+ return this;
8928
+ }
8929
+
8930
+ var listeners = this._events[evt];
8931
+
8932
+ if (listeners.fn) {
8933
+ if (
8934
+ listeners.fn === fn &&
8935
+ (!once || listeners.once) &&
8936
+ (!context || listeners.context === context)
8937
+ ) {
8938
+ clearEvent(this, evt);
8939
+ }
8940
+ } else {
8941
+ for (var i = 0, events = [], length = listeners.length; i < length; i++) {
8942
+ if (
8943
+ listeners[i].fn !== fn ||
8944
+ (once && !listeners[i].once) ||
8945
+ (context && listeners[i].context !== context)
8946
+ ) {
8947
+ events.push(listeners[i]);
8948
+ }
8949
+ }
8950
+
8951
+ //
8952
+ // Reset the array, or remove it completely if we have no more listeners.
8953
+ //
8954
+ if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
8955
+ else clearEvent(this, evt);
8956
+ }
8957
+
8958
+ return this;
8959
+ };
8960
+
8961
+ /**
8962
+ * Remove all listeners, or those of the specified event.
8963
+ *
8964
+ * @param {(String|Symbol)} [event] The event name.
8965
+ * @returns {EventEmitter} `this`.
8966
+ * @public
8967
+ */
8968
+ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
8969
+ var evt;
8970
+
8971
+ if (event) {
8972
+ evt = prefix ? prefix + event : event;
8973
+ if (this._events[evt]) clearEvent(this, evt);
8974
+ } else {
8975
+ this._events = new Events();
8976
+ this._eventsCount = 0;
8977
+ }
8978
+
8979
+ return this;
8980
+ };
8981
+
8982
+ //
8983
+ // Alias methods names because people roll like that.
8984
+ //
8985
+ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
8986
+ EventEmitter.prototype.addListener = EventEmitter.prototype.on;
8987
+
8988
+ //
8989
+ // Expose the prefix.
8990
+ //
8991
+ EventEmitter.prefixed = prefix;
8992
+
8993
+ //
8994
+ // Allow `EventEmitter` to be imported as module namespace.
8995
+ //
8996
+ EventEmitter.EventEmitter = EventEmitter;
8997
+
8998
+ //
8999
+ // Expose the module.
9000
+ //
9001
+ {
9002
+ module.exports = EventEmitter;
9003
+ }
9004
+ });
9005
+
8658
9006
  // eslint-disable-next-line import/no-cycle
8659
9007
  function failureLoggedFetch(url, options = {}) {
8660
9008
  return fetch(url, options).then(async (r) => {
8661
- if (!r.ok && r.type !== 'opaqueredirect') {
8662
- console.error('Failure', await r.text());
9009
+ var _a;
9010
+ if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
9011
+ console.error('Failure', await ((_a = r.text) === null || _a === void 0 ? void 0 : _a.call(r)));
8663
9012
  }
8664
9013
  return r;
8665
9014
  });
@@ -8693,9 +9042,7 @@
8693
9042
  async function fetchLogoutService(thoughtSpotHost) {
8694
9043
  return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
8695
9044
  credentials: 'include',
8696
- headers: {
8697
- 'x-requested-by': 'ThoughtSpot',
8698
- },
9045
+ mode: 'no-cors',
8699
9046
  });
8700
9047
  }
8701
9048
 
@@ -8716,6 +9063,17 @@
8716
9063
  BASIC_LOGIN: '/callosum/v1/session/login',
8717
9064
  LOGOUT: '/callosum/v1/session/logout',
8718
9065
  };
9066
+ (function (AuthFailureType) {
9067
+ AuthFailureType["SDK"] = "SDK";
9068
+ AuthFailureType["NO_COOKIE_ACCESS"] = "NO_COOKIE_ACCESS";
9069
+ AuthFailureType["EXPIRY"] = "EXPIRY";
9070
+ AuthFailureType["OTHER"] = "OTHER";
9071
+ })(exports.AuthFailureType || (exports.AuthFailureType = {}));
9072
+ (function (AuthStatus) {
9073
+ AuthStatus["FAILURE"] = "FAILURE";
9074
+ AuthStatus["SUCCESS"] = "SUCCESS";
9075
+ AuthStatus["LOGOUT"] = "LOGOUT";
9076
+ })(exports.AuthStatus || (exports.AuthStatus = {}));
8719
9077
  /**
8720
9078
  * Check if we are logged into the ThoughtSpot cluster
8721
9079
  * @param thoughtSpotHost The ThoughtSpot cluster hostname or IP
@@ -8771,8 +9129,8 @@
8771
9129
  if (!authEndpoint && !getAuthToken) {
8772
9130
  throw new Error('Either auth endpoint or getAuthToken function must be provided');
8773
9131
  }
8774
- const loggedIn = await isLoggedIn(thoughtSpotHost);
8775
- if (!loggedIn) {
9132
+ loggedInStatus = await isLoggedIn(thoughtSpotHost);
9133
+ if (!loggedInStatus) {
8776
9134
  let authToken = null;
8777
9135
  if (getAuthToken) {
8778
9136
  authToken = await getAuthToken();
@@ -8786,9 +9144,6 @@
8786
9144
  // token login issues a 302 when successful
8787
9145
  loggedInStatus = resp.ok || resp.type === 'opaqueredirect';
8788
9146
  }
8789
- else {
8790
- loggedInStatus = true;
8791
- }
8792
9147
  return loggedInStatus;
8793
9148
  };
8794
9149
  /**
@@ -8859,6 +9214,7 @@
8859
9214
  const ssoURL = `${thoughtSpotHost}${ssoEndPoint}`;
8860
9215
  if (embedConfig.noRedirect) {
8861
9216
  await samlPopupFlow(ssoURL);
9217
+ loggedInStatus = true;
8862
9218
  return;
8863
9219
  }
8864
9220
  window.location.href = ssoURL;
@@ -8890,9 +9246,7 @@
8890
9246
  const logout = async (embedConfig) => {
8891
9247
  const { thoughtSpotHost } = embedConfig;
8892
9248
  const response = await fetchLogoutService(thoughtSpotHost);
8893
- if (response.ok || response.status === 401) {
8894
- loggedInStatus = false;
8895
- }
9249
+ loggedInStatus = false;
8896
9250
  return loggedInStatus;
8897
9251
  };
8898
9252
  /**
@@ -8917,20 +9271,49 @@
8917
9271
 
8918
9272
  /* eslint-disable import/no-mutable-exports */
8919
9273
  let config = {};
9274
+ const CONFIG_DEFAULTS = {
9275
+ loginFailedMessage: 'Login failed',
9276
+ authType: exports.AuthType.None,
9277
+ };
8920
9278
  let authPromise;
9279
+ const getEmbedConfig = () => config;
9280
+ const getAuthPromise = () => authPromise;
9281
+ let authEE;
9282
+ function notifyAuthSuccess() {
9283
+ if (!authEE) {
9284
+ console.error('SDK not initialized');
9285
+ return;
9286
+ }
9287
+ authEE.emit(exports.AuthStatus.SUCCESS);
9288
+ }
9289
+ function notifyAuthFailure(failureType) {
9290
+ if (!authEE) {
9291
+ console.error('SDK not initialized');
9292
+ return;
9293
+ }
9294
+ authEE.emit(exports.AuthStatus.FAILURE, failureType);
9295
+ }
9296
+ function notifyLogout() {
9297
+ if (!authEE) {
9298
+ console.error('SDK not initialized');
9299
+ return;
9300
+ }
9301
+ authEE.emit(exports.AuthStatus.LOGOUT);
9302
+ }
8921
9303
  /**
8922
9304
  * Perform authentication on the ThoughtSpot app as applicable.
8923
9305
  */
8924
9306
  const handleAuth = () => {
8925
- const authConfig = {
8926
- ...config,
8927
- thoughtSpotHost: getThoughtSpotHost(config),
8928
- };
8929
- authPromise = authenticate(authConfig);
9307
+ authPromise = authenticate(config);
9308
+ authPromise.then((isLoggedIn) => {
9309
+ if (!isLoggedIn) {
9310
+ notifyAuthFailure(exports.AuthFailureType.SDK);
9311
+ }
9312
+ }, () => {
9313
+ notifyAuthFailure(exports.AuthFailureType.SDK);
9314
+ });
8930
9315
  return authPromise;
8931
9316
  };
8932
- const getEmbedConfig = () => config;
8933
- const getAuthPromise = () => authPromise;
8934
9317
  /**
8935
9318
  * 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.
8936
9319
  * @param url The URL provided for prefetch
@@ -8959,7 +9342,12 @@
8959
9342
  * @returns authPromise Promise which resolves when authentication is complete.
8960
9343
  */
8961
9344
  const init = (embedConfig) => {
8962
- config = embedConfig;
9345
+ config = {
9346
+ ...CONFIG_DEFAULTS,
9347
+ ...embedConfig,
9348
+ thoughtSpotHost: getThoughtSpotHost(embedConfig),
9349
+ };
9350
+ authEE = new eventemitter3();
8963
9351
  handleAuth();
8964
9352
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_CALLED_INIT, {
8965
9353
  authType: config.authType,
@@ -8968,10 +9356,16 @@
8968
9356
  if (config.callPrefetch) {
8969
9357
  prefetch(config.thoughtSpotHost);
8970
9358
  }
8971
- return authPromise;
9359
+ return authEE;
8972
9360
  };
8973
- const logout$1 = () => {
8974
- return logout(config);
9361
+ const logout$1 = (doNotDisableAutoLogin = false) => {
9362
+ if (!doNotDisableAutoLogin) {
9363
+ config.autoLogin = false;
9364
+ }
9365
+ return logout(config).then((isLoggedIn) => {
9366
+ notifyLogout();
9367
+ return isLoggedIn;
9368
+ });
8975
9369
  };
8976
9370
  let renderQueue = Promise.resolve();
8977
9371
  /**
@@ -9057,6 +9451,7 @@
9057
9451
  var _a, _b;
9058
9452
  // Store user session details sent by app.
9059
9453
  initSession(e.data);
9454
+ notifyAuthSuccess();
9060
9455
  // Expose only allowed details (eg: userGUID) back to SDK users.
9061
9456
  return {
9062
9457
  ...e,
@@ -9070,9 +9465,28 @@
9070
9465
  if (autoLogin) {
9071
9466
  handleAuth();
9072
9467
  }
9468
+ notifyAuthFailure(exports.AuthFailureType.EXPIRY);
9469
+ return e;
9470
+ }
9471
+ function processNoCookieAccess(e, containerEl) {
9472
+ const { loginFailedMessage, suppressNoCookieAccessAlert, } = getEmbedConfig();
9473
+ if (!suppressNoCookieAccessAlert) {
9474
+ // eslint-disable-next-line no-alert
9475
+ 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.');
9476
+ }
9477
+ // eslint-disable-next-line no-param-reassign
9478
+ containerEl.innerHTML = loginFailedMessage;
9479
+ notifyAuthFailure(exports.AuthFailureType.NO_COOKIE_ACCESS);
9073
9480
  return e;
9074
9481
  }
9075
- function getProcessData(type, e, thoughtSpotHost) {
9482
+ function processAuthFailure(e, containerEl) {
9483
+ const { loginFailedMessage } = getEmbedConfig();
9484
+ // eslint-disable-next-line no-param-reassign
9485
+ containerEl.innerHTML = loginFailedMessage;
9486
+ notifyAuthFailure(exports.AuthFailureType.OTHER);
9487
+ return e;
9488
+ }
9489
+ function processEventData(type, e, thoughtSpotHost, containerEl) {
9076
9490
  switch (type) {
9077
9491
  case exports.EmbedEvent.CustomAction:
9078
9492
  return processCustomAction(e, thoughtSpotHost);
@@ -9080,6 +9494,10 @@
9080
9494
  return processAuthInit(e);
9081
9495
  case exports.EmbedEvent.AuthExpire:
9082
9496
  return processAuthExpire(e);
9497
+ case exports.EmbedEvent.NoCookieAccess:
9498
+ return processNoCookieAccess(e, containerEl);
9499
+ case exports.EmbedEvent.AuthFailure:
9500
+ return processAuthFailure(e, containerEl);
9083
9501
  }
9084
9502
  return e;
9085
9503
  }
@@ -9108,7 +9526,7 @@
9108
9526
  }
9109
9527
  }
9110
9528
 
9111
- 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$1={".":"./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$1,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};
9529
+ 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$1={".":"./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$1,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};
9112
9530
 
9113
9531
  /**
9114
9532
  * Copyright (c) 2022
@@ -9155,17 +9573,6 @@
9155
9573
  this.isError = false;
9156
9574
  this.viewConfig = viewConfig;
9157
9575
  this.shouldEncodeUrlQueryParams = this.embedConfig.shouldEncodeUrlQueryParams;
9158
- this.on(exports.EmbedEvent.NoCookieAccess, () => {
9159
- if (!this.embedConfig.suppressNoCookieAccessAlert) {
9160
- // eslint-disable-next-line no-alert
9161
- 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.');
9162
- }
9163
- this.el.innerHTML = this.getLoginFiledMessage();
9164
- });
9165
- }
9166
- getLoginFiledMessage() {
9167
- const { loginFailedMessage } = this.embedConfig;
9168
- return loginFailedMessage || 'Login failed';
9169
9576
  }
9170
9577
  /**
9171
9578
  * Gets a reference to the root DOM node where
@@ -9242,7 +9649,7 @@
9242
9649
  const eventPort = this.getEventPort(event);
9243
9650
  const eventData = this.formatEventData(event, eventType);
9244
9651
  if (event.source === this.iFrame.contentWindow) {
9245
- this.executeCallbacks(eventType, getProcessData(eventType, eventData, this.thoughtSpotHost), eventPort);
9652
+ this.executeCallbacks(eventType, processEventData(eventType, eventData, this.thoughtSpotHost, this.el), eventPort);
9246
9653
  }
9247
9654
  });
9248
9655
  }
@@ -9363,7 +9770,7 @@
9363
9770
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_START);
9364
9771
  (_a = getAuthPromise()) === null || _a === void 0 ? void 0 : _a.then((isLoggedIn) => {
9365
9772
  if (!isLoggedIn) {
9366
- this.el.innerHTML = this.getLoginFiledMessage();
9773
+ this.el.innerHTML = this.embedConfig.loginFailedMessage;
9367
9774
  return;
9368
9775
  }
9369
9776
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_COMPLETE);
@@ -9381,7 +9788,7 @@
9381
9788
  this.iFrame.mozallowfullscreen = true;
9382
9789
  const { height: frameHeight, width: frameWidth, ...restParams } = frameOptions;
9383
9790
  const width = getCssDimension(frameWidth || DEFAULT_EMBED_WIDTH);
9384
- const height = getCssDimension(frameWidth || DEFAULT_EMBED_HEIGHT);
9791
+ const height = getCssDimension(frameHeight || DEFAULT_EMBED_HEIGHT);
9385
9792
  setAttributes(this.iFrame, restParams);
9386
9793
  this.iFrame.style.width = `${width}`;
9387
9794
  this.iFrame.style.height = `${height}`;
@@ -9415,7 +9822,7 @@
9415
9822
  }).catch((error) => {
9416
9823
  nextInQueue();
9417
9824
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_FAILED);
9418
- this.el.innerHTML = this.getLoginFiledMessage();
9825
+ this.el.innerHTML = this.embedConfig.loginFailedMessage;
9419
9826
  this.handleError(error);
9420
9827
  });
9421
9828
  });
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thoughtspot/visual-embed-sdk",
3
- "version": "1.11.0-auth.10",
3
+ "version": "1.11.0-auth.13",
4
4
  "description": "ThoughtSpot Embed SDK",
5
5
  "module": "lib/src/index.js",
6
6
  "main": "dist/tsembed.js",
@@ -44,6 +44,7 @@
44
44
  "dependencies": {
45
45
  "algoliasearch": "^4.10.5",
46
46
  "classnames": "^2.3.1",
47
+ "eventemitter3": "^4.0.7",
47
48
  "mixpanel-browser": "^2.41.0"
48
49
  },
49
50
  "devDependencies": {