@thoughtspot/visual-embed-sdk 1.11.0-auth.1 → 1.11.0-auth.12
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/src/auth.d.ts +13 -0
- package/dist/src/embed/base.d.ts +17 -3
- package/dist/src/index.d.ts +3 -2
- package/dist/src/types.d.ts +10 -0
- package/dist/src/utils/authService.d.ts +1 -0
- package/dist/src/utils/processData.d.ts +1 -1
- package/dist/tsembed.es.js +482 -29
- package/dist/tsembed.js +480 -28
- package/lib/package.json +2 -1
- package/lib/src/auth.d.ts +13 -0
- package/lib/src/auth.js +40 -8
- package/lib/src/auth.js.map +1 -1
- package/lib/src/auth.spec.js +63 -9
- package/lib/src/auth.spec.js.map +1 -1
- package/lib/src/embed/base.d.ts +17 -3
- package/lib/src/embed/base.js +50 -5
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/base.spec.js +38 -3
- package/lib/src/embed/base.spec.js.map +1 -1
- package/lib/src/embed/embed.spec.js +1 -1
- package/lib/src/embed/embed.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.js +5 -10
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +16 -6
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/index.d.ts +3 -2
- package/lib/src/index.js +3 -2
- package/lib/src/index.js.map +1 -1
- package/lib/src/test/test-utils.js +1 -1
- package/lib/src/test/test-utils.js.map +1 -1
- package/lib/src/types.d.ts +10 -0
- package/lib/src/types.js +5 -0
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/authService.d.ts +1 -0
- package/lib/src/utils/authService.js +17 -6
- package/lib/src/utils/authService.js.map +1 -1
- package/lib/src/utils/authService.spec.js +7 -3
- package/lib/src/utils/authService.spec.js.map +1 -1
- package/lib/src/utils/processData.d.ts +1 -1
- package/lib/src/utils/processData.js +27 -3
- package/lib/src/utils/processData.js.map +1 -1
- package/lib/src/utils/processData.spec.js +85 -4
- package/lib/src/utils/processData.spec.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +91 -5
- package/package.json +2 -1
- package/src/auth.spec.ts +80 -9
- package/src/auth.ts +43 -6
- package/src/embed/base.spec.ts +44 -4
- package/src/embed/base.ts +65 -9
- package/src/embed/embed.spec.ts +1 -1
- package/src/embed/ts-embed.spec.ts +19 -9
- package/src/embed/ts-embed.ts +10 -12
- package/src/index.ts +5 -1
- package/src/test/test-utils.ts +1 -1
- package/src/types.ts +11 -0
- package/src/utils/authService.spec.ts +10 -3
- package/src/utils/authService.ts +20 -6
- package/src/utils/processData.spec.ts +114 -4
- 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,17 +8660,361 @@
|
|
|
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
|
-
function
|
|
9007
|
+
function failureLoggedFetch(url, options = {}) {
|
|
8660
9008
|
return fetch(url, options).then(async (r) => {
|
|
8661
|
-
|
|
8662
|
-
|
|
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
|
});
|
|
8666
9015
|
}
|
|
8667
9016
|
function fetchSessionInfoService(authVerificationUrl) {
|
|
8668
|
-
return
|
|
9017
|
+
return failureLoggedFetch(authVerificationUrl, {
|
|
8669
9018
|
credentials: 'include',
|
|
8670
9019
|
});
|
|
8671
9020
|
}
|
|
@@ -8673,10 +9022,14 @@
|
|
|
8673
9022
|
return fetch(authEndpoint);
|
|
8674
9023
|
}
|
|
8675
9024
|
async function fetchAuthService(thoughtSpotHost, username, authToken) {
|
|
8676
|
-
return
|
|
9025
|
+
return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.TOKEN_LOGIN}?username=${username}&auth_token=${authToken}`, {
|
|
9026
|
+
credentials: 'include',
|
|
9027
|
+
// We do not want to follow the redirect, as it starts giving a CORS error
|
|
9028
|
+
redirect: 'manual',
|
|
9029
|
+
});
|
|
8677
9030
|
}
|
|
8678
9031
|
async function fetchBasicAuthService(thoughtSpotHost, username, password) {
|
|
8679
|
-
return
|
|
9032
|
+
return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.BASIC_LOGIN}`, {
|
|
8680
9033
|
method: 'POST',
|
|
8681
9034
|
headers: {
|
|
8682
9035
|
'content-type': 'application/x-www-form-urlencoded',
|
|
@@ -8685,6 +9038,12 @@
|
|
|
8685
9038
|
body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`,
|
|
8686
9039
|
credentials: 'include',
|
|
8687
9040
|
});
|
|
9041
|
+
}
|
|
9042
|
+
async function fetchLogoutService(thoughtSpotHost) {
|
|
9043
|
+
return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
|
|
9044
|
+
credentials: 'include',
|
|
9045
|
+
mode: 'no-cors',
|
|
9046
|
+
});
|
|
8688
9047
|
}
|
|
8689
9048
|
|
|
8690
9049
|
// eslint-disable-next-line import/no-mutable-exports
|
|
@@ -8702,7 +9061,19 @@
|
|
|
8702
9061
|
OIDC_LOGIN_TEMPLATE: (targetUrl) => `/callosum/v1/oidc/login?targetURLPath=${targetUrl}`,
|
|
8703
9062
|
TOKEN_LOGIN: '/callosum/v1/session/login/token',
|
|
8704
9063
|
BASIC_LOGIN: '/callosum/v1/session/login',
|
|
9064
|
+
LOGOUT: '/callosum/v1/session/logout',
|
|
8705
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 = {}));
|
|
8706
9077
|
/**
|
|
8707
9078
|
* Check if we are logged into the ThoughtSpot cluster
|
|
8708
9079
|
* @param thoughtSpotHost The ThoughtSpot cluster hostname or IP
|
|
@@ -8722,6 +9093,17 @@
|
|
|
8722
9093
|
sessionInfo = sessionDetails;
|
|
8723
9094
|
initMixpanel(sessionInfo);
|
|
8724
9095
|
}
|
|
9096
|
+
const DUPLICATE_TOKEN_ERR = 'Duplicate token, please issue a new token every time getAuthToken callback is called.' +
|
|
9097
|
+
'See https://developers.thoughtspot.com/docs/?pageid=embed-auth#trusted-auth-embed for more details.';
|
|
9098
|
+
let prevAuthToken = null;
|
|
9099
|
+
function alertForDuplicateToken(authtoken) {
|
|
9100
|
+
if (prevAuthToken === authtoken) {
|
|
9101
|
+
// eslint-disable-next-line no-alert
|
|
9102
|
+
alert(DUPLICATE_TOKEN_ERR);
|
|
9103
|
+
throw new Error(DUPLICATE_TOKEN_ERR);
|
|
9104
|
+
}
|
|
9105
|
+
prevAuthToken = authtoken;
|
|
9106
|
+
}
|
|
8725
9107
|
/**
|
|
8726
9108
|
* Check if we are stuck at the SSO redirect URL
|
|
8727
9109
|
*/
|
|
@@ -8747,21 +9129,20 @@
|
|
|
8747
9129
|
if (!authEndpoint && !getAuthToken) {
|
|
8748
9130
|
throw new Error('Either auth endpoint or getAuthToken function must be provided');
|
|
8749
9131
|
}
|
|
8750
|
-
|
|
8751
|
-
if (!
|
|
9132
|
+
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
9133
|
+
if (!loggedInStatus) {
|
|
8752
9134
|
let authToken = null;
|
|
8753
9135
|
if (getAuthToken) {
|
|
8754
9136
|
authToken = await getAuthToken();
|
|
9137
|
+
alertForDuplicateToken(authToken);
|
|
8755
9138
|
}
|
|
8756
9139
|
else {
|
|
8757
9140
|
const response = await fetchAuthTokenService(authEndpoint);
|
|
8758
9141
|
authToken = await response.text();
|
|
8759
9142
|
}
|
|
8760
9143
|
const resp = await fetchAuthService(thoughtSpotHost, username, authToken);
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
else {
|
|
8764
|
-
loggedInStatus = true;
|
|
9144
|
+
// token login issues a 302 when successful
|
|
9145
|
+
loggedInStatus = resp.ok || resp.type === 'opaqueredirect';
|
|
8765
9146
|
}
|
|
8766
9147
|
return loggedInStatus;
|
|
8767
9148
|
};
|
|
@@ -8778,7 +9159,7 @@
|
|
|
8778
9159
|
const loggedIn = await isLoggedIn(thoughtSpotHost);
|
|
8779
9160
|
if (!loggedIn) {
|
|
8780
9161
|
const response = await fetchBasicAuthService(thoughtSpotHost, username, password);
|
|
8781
|
-
loggedInStatus = response.
|
|
9162
|
+
loggedInStatus = response.ok;
|
|
8782
9163
|
}
|
|
8783
9164
|
else {
|
|
8784
9165
|
loggedInStatus = true;
|
|
@@ -8833,6 +9214,8 @@
|
|
|
8833
9214
|
const ssoURL = `${thoughtSpotHost}${ssoEndPoint}`;
|
|
8834
9215
|
if (embedConfig.noRedirect) {
|
|
8835
9216
|
await samlPopupFlow(ssoURL);
|
|
9217
|
+
console.log('here');
|
|
9218
|
+
loggedInStatus = true;
|
|
8836
9219
|
return;
|
|
8837
9220
|
}
|
|
8838
9221
|
window.location.href = ssoURL;
|
|
@@ -8861,6 +9244,12 @@
|
|
|
8861
9244
|
await doSSOAuth(embedConfig, ssoEndPoint);
|
|
8862
9245
|
return loggedInStatus;
|
|
8863
9246
|
};
|
|
9247
|
+
const logout = async (embedConfig) => {
|
|
9248
|
+
const { thoughtSpotHost } = embedConfig;
|
|
9249
|
+
const response = await fetchLogoutService(thoughtSpotHost);
|
|
9250
|
+
loggedInStatus = false;
|
|
9251
|
+
return loggedInStatus;
|
|
9252
|
+
};
|
|
8864
9253
|
/**
|
|
8865
9254
|
* Perform authentication on the ThoughtSpot cluster
|
|
8866
9255
|
* @param embedConfig The embed configuration
|
|
@@ -8883,7 +9272,35 @@
|
|
|
8883
9272
|
|
|
8884
9273
|
/* eslint-disable import/no-mutable-exports */
|
|
8885
9274
|
let config = {};
|
|
9275
|
+
const CONFIG_DEFAULTS = {
|
|
9276
|
+
loginFailedMessage: 'Login failed',
|
|
9277
|
+
authType: exports.AuthType.None,
|
|
9278
|
+
};
|
|
8886
9279
|
let authPromise;
|
|
9280
|
+
const getEmbedConfig = () => config;
|
|
9281
|
+
const getAuthPromise = () => authPromise;
|
|
9282
|
+
let authEE;
|
|
9283
|
+
function notifyAuthSuccess() {
|
|
9284
|
+
if (!authEE) {
|
|
9285
|
+
console.error('SDK not initialized');
|
|
9286
|
+
return;
|
|
9287
|
+
}
|
|
9288
|
+
authEE.emit(exports.AuthStatus.SUCCESS);
|
|
9289
|
+
}
|
|
9290
|
+
function notifyAuthFailure(failureType) {
|
|
9291
|
+
if (!authEE) {
|
|
9292
|
+
console.error('SDK not initialized');
|
|
9293
|
+
return;
|
|
9294
|
+
}
|
|
9295
|
+
authEE.emit(exports.AuthStatus.FAILURE, failureType);
|
|
9296
|
+
}
|
|
9297
|
+
function notifyLogout() {
|
|
9298
|
+
if (!authEE) {
|
|
9299
|
+
console.error('SDK not initialized');
|
|
9300
|
+
return;
|
|
9301
|
+
}
|
|
9302
|
+
authEE.emit(exports.AuthStatus.LOGOUT);
|
|
9303
|
+
}
|
|
8887
9304
|
/**
|
|
8888
9305
|
* Perform authentication on the ThoughtSpot app as applicable.
|
|
8889
9306
|
*/
|
|
@@ -8893,10 +9310,15 @@
|
|
|
8893
9310
|
thoughtSpotHost: getThoughtSpotHost(config),
|
|
8894
9311
|
};
|
|
8895
9312
|
authPromise = authenticate(authConfig);
|
|
9313
|
+
authPromise.then((isLoggedIn) => {
|
|
9314
|
+
if (!isLoggedIn) {
|
|
9315
|
+
notifyAuthFailure(exports.AuthFailureType.SDK);
|
|
9316
|
+
}
|
|
9317
|
+
}, () => {
|
|
9318
|
+
notifyAuthFailure(exports.AuthFailureType.SDK);
|
|
9319
|
+
});
|
|
8896
9320
|
return authPromise;
|
|
8897
9321
|
};
|
|
8898
|
-
const getEmbedConfig = () => config;
|
|
8899
|
-
const getAuthPromise = () => authPromise;
|
|
8900
9322
|
/**
|
|
8901
9323
|
* 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.
|
|
8902
9324
|
* @param url The URL provided for prefetch
|
|
@@ -8925,7 +9347,8 @@
|
|
|
8925
9347
|
* @returns authPromise Promise which resolves when authentication is complete.
|
|
8926
9348
|
*/
|
|
8927
9349
|
const init = (embedConfig) => {
|
|
8928
|
-
config = embedConfig;
|
|
9350
|
+
config = { ...CONFIG_DEFAULTS, ...embedConfig };
|
|
9351
|
+
authEE = new eventemitter3();
|
|
8929
9352
|
handleAuth();
|
|
8930
9353
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_CALLED_INIT, {
|
|
8931
9354
|
authType: config.authType,
|
|
@@ -8934,7 +9357,16 @@
|
|
|
8934
9357
|
if (config.callPrefetch) {
|
|
8935
9358
|
prefetch(config.thoughtSpotHost);
|
|
8936
9359
|
}
|
|
8937
|
-
return
|
|
9360
|
+
return authEE;
|
|
9361
|
+
};
|
|
9362
|
+
const logout$1 = (doNotDisableAutoLogin = false) => {
|
|
9363
|
+
if (!doNotDisableAutoLogin) {
|
|
9364
|
+
config.autoLogin = false;
|
|
9365
|
+
}
|
|
9366
|
+
return logout(config).then((isLoggedIn) => {
|
|
9367
|
+
notifyLogout();
|
|
9368
|
+
return isLoggedIn;
|
|
9369
|
+
});
|
|
8938
9370
|
};
|
|
8939
9371
|
let renderQueue = Promise.resolve();
|
|
8940
9372
|
/**
|
|
@@ -9020,6 +9452,7 @@
|
|
|
9020
9452
|
var _a, _b;
|
|
9021
9453
|
// Store user session details sent by app.
|
|
9022
9454
|
initSession(e.data);
|
|
9455
|
+
notifyAuthSuccess();
|
|
9023
9456
|
// Expose only allowed details (eg: userGUID) back to SDK users.
|
|
9024
9457
|
return {
|
|
9025
9458
|
...e,
|
|
@@ -9033,9 +9466,28 @@
|
|
|
9033
9466
|
if (autoLogin) {
|
|
9034
9467
|
handleAuth();
|
|
9035
9468
|
}
|
|
9469
|
+
notifyAuthFailure(exports.AuthFailureType.EXPIRY);
|
|
9470
|
+
return e;
|
|
9471
|
+
}
|
|
9472
|
+
function processNoCookieAccess(e, containerEl) {
|
|
9473
|
+
const { loginFailedMessage, suppressNoCookieAccessAlert, } = getEmbedConfig();
|
|
9474
|
+
if (!suppressNoCookieAccessAlert) {
|
|
9475
|
+
// eslint-disable-next-line no-alert
|
|
9476
|
+
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.');
|
|
9477
|
+
}
|
|
9478
|
+
// eslint-disable-next-line no-param-reassign
|
|
9479
|
+
containerEl.innerHTML = loginFailedMessage;
|
|
9480
|
+
notifyAuthFailure(exports.AuthFailureType.NO_COOKIE_ACCESS);
|
|
9481
|
+
return e;
|
|
9482
|
+
}
|
|
9483
|
+
function processAuthFailure(e, containerEl) {
|
|
9484
|
+
const { loginFailedMessage } = getEmbedConfig();
|
|
9485
|
+
// eslint-disable-next-line no-param-reassign
|
|
9486
|
+
containerEl.innerHTML = loginFailedMessage;
|
|
9487
|
+
notifyAuthFailure(exports.AuthFailureType.OTHER);
|
|
9036
9488
|
return e;
|
|
9037
9489
|
}
|
|
9038
|
-
function
|
|
9490
|
+
function processEventData(type, e, thoughtSpotHost, containerEl) {
|
|
9039
9491
|
switch (type) {
|
|
9040
9492
|
case exports.EmbedEvent.CustomAction:
|
|
9041
9493
|
return processCustomAction(e, thoughtSpotHost);
|
|
@@ -9043,6 +9495,10 @@
|
|
|
9043
9495
|
return processAuthInit(e);
|
|
9044
9496
|
case exports.EmbedEvent.AuthExpire:
|
|
9045
9497
|
return processAuthExpire(e);
|
|
9498
|
+
case exports.EmbedEvent.NoCookieAccess:
|
|
9499
|
+
return processNoCookieAccess(e, containerEl);
|
|
9500
|
+
case exports.EmbedEvent.AuthFailure:
|
|
9501
|
+
return processAuthFailure(e, containerEl);
|
|
9046
9502
|
}
|
|
9047
9503
|
return e;
|
|
9048
9504
|
}
|
|
@@ -9071,7 +9527,7 @@
|
|
|
9071
9527
|
}
|
|
9072
9528
|
}
|
|
9073
9529
|
|
|
9074
|
-
var name="@thoughtspot/visual-embed-sdk";var version="1.11.0-auth.
|
|
9530
|
+
var name="@thoughtspot/visual-embed-sdk";var version="1.11.0-auth.12";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};
|
|
9075
9531
|
|
|
9076
9532
|
/**
|
|
9077
9533
|
* Copyright (c) 2022
|
|
@@ -9118,12 +9574,6 @@
|
|
|
9118
9574
|
this.isError = false;
|
|
9119
9575
|
this.viewConfig = viewConfig;
|
|
9120
9576
|
this.shouldEncodeUrlQueryParams = this.embedConfig.shouldEncodeUrlQueryParams;
|
|
9121
|
-
if (!this.embedConfig.suppressNoCookieAccessAlert) {
|
|
9122
|
-
this.on(exports.EmbedEvent.NoCookieAccess, () => {
|
|
9123
|
-
// eslint-disable-next-line no-alert
|
|
9124
|
-
alert('Third party cookie access is blocked on this browser, please allow third party cookies for ThoughtSpot to work properly');
|
|
9125
|
-
});
|
|
9126
|
-
}
|
|
9127
9577
|
}
|
|
9128
9578
|
/**
|
|
9129
9579
|
* Gets a reference to the root DOM node where
|
|
@@ -9200,7 +9650,7 @@
|
|
|
9200
9650
|
const eventPort = this.getEventPort(event);
|
|
9201
9651
|
const eventData = this.formatEventData(event, eventType);
|
|
9202
9652
|
if (event.source === this.iFrame.contentWindow) {
|
|
9203
|
-
this.executeCallbacks(eventType,
|
|
9653
|
+
this.executeCallbacks(eventType, processEventData(eventType, eventData, this.thoughtSpotHost, this.el), eventPort);
|
|
9204
9654
|
}
|
|
9205
9655
|
});
|
|
9206
9656
|
}
|
|
@@ -9321,7 +9771,7 @@
|
|
|
9321
9771
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_START);
|
|
9322
9772
|
(_a = getAuthPromise()) === null || _a === void 0 ? void 0 : _a.then((isLoggedIn) => {
|
|
9323
9773
|
if (!isLoggedIn) {
|
|
9324
|
-
this.el.innerHTML =
|
|
9774
|
+
this.el.innerHTML = this.embedConfig.loginFailedMessage;
|
|
9325
9775
|
return;
|
|
9326
9776
|
}
|
|
9327
9777
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_COMPLETE);
|
|
@@ -9339,7 +9789,7 @@
|
|
|
9339
9789
|
this.iFrame.mozallowfullscreen = true;
|
|
9340
9790
|
const { height: frameHeight, width: frameWidth, ...restParams } = frameOptions;
|
|
9341
9791
|
const width = getCssDimension(frameWidth || DEFAULT_EMBED_WIDTH);
|
|
9342
|
-
const height = getCssDimension(
|
|
9792
|
+
const height = getCssDimension(frameHeight || DEFAULT_EMBED_HEIGHT);
|
|
9343
9793
|
setAttributes(this.iFrame, restParams);
|
|
9344
9794
|
this.iFrame.style.width = `${width}`;
|
|
9345
9795
|
this.iFrame.style.height = `${height}`;
|
|
@@ -9373,6 +9823,7 @@
|
|
|
9373
9823
|
}).catch((error) => {
|
|
9374
9824
|
nextInQueue();
|
|
9375
9825
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_FAILED);
|
|
9826
|
+
this.el.innerHTML = this.embedConfig.loginFailedMessage;
|
|
9376
9827
|
this.handleError(error);
|
|
9377
9828
|
});
|
|
9378
9829
|
});
|
|
@@ -9944,6 +10395,7 @@
|
|
|
9944
10395
|
exports.PinboardEmbed = PinboardEmbed;
|
|
9945
10396
|
exports.SearchEmbed = SearchEmbed;
|
|
9946
10397
|
exports.init = init;
|
|
10398
|
+
exports.logout = logout$1;
|
|
9947
10399
|
exports.prefetch = prefetch;
|
|
9948
10400
|
|
|
9949
10401
|
Object.defineProperty(exports, '__esModule', { value: true });
|