@thoughtspot/visual-embed-sdk 1.11.0-auth.0 → 1.11.0-auth.11
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 +16 -3
- package/dist/src/index.d.ts +2 -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 +465 -23
- package/dist/tsembed.js +465 -22
- package/lib/package.json +2 -1
- package/lib/src/auth.d.ts +13 -0
- package/lib/src/auth.js +38 -3
- package/lib/src/auth.js.map +1 -1
- package/lib/src/auth.spec.js +9 -8
- package/lib/src/auth.spec.js.map +1 -1
- package/lib/src/embed/base.d.ts +16 -3
- package/lib/src/embed/base.js +37 -5
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/base.spec.js +21 -3
- package/lib/src/embed/base.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.js +4 -9
- 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 +2 -2
- package/lib/src/index.js +2 -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 +16 -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 +89 -5
- package/package.json +2 -1
- package/src/auth.spec.ts +13 -8
- package/src/auth.ts +41 -2
- package/src/embed/base.spec.ts +23 -4
- package/src/embed/base.ts +51 -9
- package/src/embed/ts-embed.spec.ts +19 -9
- package/src/embed/ts-embed.ts +9 -11
- package/src/index.ts +2 -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 -7
- 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,360 @@
|
|
|
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
|
-
if (!r.ok) {
|
|
8662
|
-
console.error('Failure', await r.
|
|
9009
|
+
if (!r.ok && r.type !== 'opaqueredirect') {
|
|
9010
|
+
console.error('Failure', await r.text());
|
|
8663
9011
|
}
|
|
8664
9012
|
return r;
|
|
8665
9013
|
});
|
|
8666
9014
|
}
|
|
8667
9015
|
function fetchSessionInfoService(authVerificationUrl) {
|
|
8668
|
-
return
|
|
9016
|
+
return failureLoggedFetch(authVerificationUrl, {
|
|
8669
9017
|
credentials: 'include',
|
|
8670
9018
|
});
|
|
8671
9019
|
}
|
|
@@ -8673,12 +9021,14 @@
|
|
|
8673
9021
|
return fetch(authEndpoint);
|
|
8674
9022
|
}
|
|
8675
9023
|
async function fetchAuthService(thoughtSpotHost, username, authToken) {
|
|
8676
|
-
return
|
|
9024
|
+
return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.TOKEN_LOGIN}?username=${username}&auth_token=${authToken}`, {
|
|
8677
9025
|
credentials: 'include',
|
|
9026
|
+
// We do not want to follow the redirect, as it starts giving a CORS error
|
|
9027
|
+
redirect: 'manual',
|
|
8678
9028
|
});
|
|
8679
9029
|
}
|
|
8680
9030
|
async function fetchBasicAuthService(thoughtSpotHost, username, password) {
|
|
8681
|
-
return
|
|
9031
|
+
return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.BASIC_LOGIN}`, {
|
|
8682
9032
|
method: 'POST',
|
|
8683
9033
|
headers: {
|
|
8684
9034
|
'content-type': 'application/x-www-form-urlencoded',
|
|
@@ -8687,6 +9037,14 @@
|
|
|
8687
9037
|
body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`,
|
|
8688
9038
|
credentials: 'include',
|
|
8689
9039
|
});
|
|
9040
|
+
}
|
|
9041
|
+
async function fetchLogoutService(thoughtSpotHost) {
|
|
9042
|
+
return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
|
|
9043
|
+
credentials: 'include',
|
|
9044
|
+
headers: {
|
|
9045
|
+
'x-requested-by': 'ThoughtSpot',
|
|
9046
|
+
},
|
|
9047
|
+
});
|
|
8690
9048
|
}
|
|
8691
9049
|
|
|
8692
9050
|
// eslint-disable-next-line import/no-mutable-exports
|
|
@@ -8704,7 +9062,21 @@
|
|
|
8704
9062
|
OIDC_LOGIN_TEMPLATE: (targetUrl) => `/callosum/v1/oidc/login?targetURLPath=${targetUrl}`,
|
|
8705
9063
|
TOKEN_LOGIN: '/callosum/v1/session/login/token',
|
|
8706
9064
|
BASIC_LOGIN: '/callosum/v1/session/login',
|
|
9065
|
+
LOGOUT: '/callosum/v1/session/logout',
|
|
8707
9066
|
};
|
|
9067
|
+
var AuthFailureType;
|
|
9068
|
+
(function (AuthFailureType) {
|
|
9069
|
+
AuthFailureType["SDK"] = "SDK";
|
|
9070
|
+
AuthFailureType["NO_COOKIE_ACCESS"] = "NO_COOKIE_ACCESS";
|
|
9071
|
+
AuthFailureType["EXPIRY"] = "EXPIRY";
|
|
9072
|
+
AuthFailureType["OTHER"] = "OTHER";
|
|
9073
|
+
})(AuthFailureType || (AuthFailureType = {}));
|
|
9074
|
+
var AuthStatus;
|
|
9075
|
+
(function (AuthStatus) {
|
|
9076
|
+
AuthStatus["FAILURE"] = "FAILURE";
|
|
9077
|
+
AuthStatus["SUCCESS"] = "SUCCESS";
|
|
9078
|
+
AuthStatus["LOGOUT"] = "LOGOUT";
|
|
9079
|
+
})(AuthStatus || (AuthStatus = {}));
|
|
8708
9080
|
/**
|
|
8709
9081
|
* Check if we are logged into the ThoughtSpot cluster
|
|
8710
9082
|
* @param thoughtSpotHost The ThoughtSpot cluster hostname or IP
|
|
@@ -8724,6 +9096,17 @@
|
|
|
8724
9096
|
sessionInfo = sessionDetails;
|
|
8725
9097
|
initMixpanel(sessionInfo);
|
|
8726
9098
|
}
|
|
9099
|
+
const DUPLICATE_TOKEN_ERR = 'Duplicate token, please issue a new token every time getAuthToken callback is called.' +
|
|
9100
|
+
'See https://developers.thoughtspot.com/docs/?pageid=embed-auth#trusted-auth-embed for more details.';
|
|
9101
|
+
let prevAuthToken = null;
|
|
9102
|
+
function alertForDuplicateToken(authtoken) {
|
|
9103
|
+
if (prevAuthToken === authtoken) {
|
|
9104
|
+
// eslint-disable-next-line no-alert
|
|
9105
|
+
alert(DUPLICATE_TOKEN_ERR);
|
|
9106
|
+
throw new Error(DUPLICATE_TOKEN_ERR);
|
|
9107
|
+
}
|
|
9108
|
+
prevAuthToken = authtoken;
|
|
9109
|
+
}
|
|
8727
9110
|
/**
|
|
8728
9111
|
* Check if we are stuck at the SSO redirect URL
|
|
8729
9112
|
*/
|
|
@@ -8754,13 +9137,15 @@
|
|
|
8754
9137
|
let authToken = null;
|
|
8755
9138
|
if (getAuthToken) {
|
|
8756
9139
|
authToken = await getAuthToken();
|
|
9140
|
+
alertForDuplicateToken(authToken);
|
|
8757
9141
|
}
|
|
8758
9142
|
else {
|
|
8759
9143
|
const response = await fetchAuthTokenService(authEndpoint);
|
|
8760
9144
|
authToken = await response.text();
|
|
8761
9145
|
}
|
|
8762
9146
|
const resp = await fetchAuthService(thoughtSpotHost, username, authToken);
|
|
8763
|
-
|
|
9147
|
+
// token login issues a 302 when successful
|
|
9148
|
+
loggedInStatus = resp.ok || resp.type === 'opaqueredirect';
|
|
8764
9149
|
}
|
|
8765
9150
|
else {
|
|
8766
9151
|
loggedInStatus = true;
|
|
@@ -8780,7 +9165,7 @@
|
|
|
8780
9165
|
const loggedIn = await isLoggedIn(thoughtSpotHost);
|
|
8781
9166
|
if (!loggedIn) {
|
|
8782
9167
|
const response = await fetchBasicAuthService(thoughtSpotHost, username, password);
|
|
8783
|
-
loggedInStatus = response.
|
|
9168
|
+
loggedInStatus = response.ok;
|
|
8784
9169
|
}
|
|
8785
9170
|
else {
|
|
8786
9171
|
loggedInStatus = true;
|
|
@@ -8863,6 +9248,14 @@
|
|
|
8863
9248
|
await doSSOAuth(embedConfig, ssoEndPoint);
|
|
8864
9249
|
return loggedInStatus;
|
|
8865
9250
|
};
|
|
9251
|
+
const logout = async (embedConfig) => {
|
|
9252
|
+
const { thoughtSpotHost } = embedConfig;
|
|
9253
|
+
const response = await fetchLogoutService(thoughtSpotHost);
|
|
9254
|
+
if (response.ok || response.status === 401) {
|
|
9255
|
+
loggedInStatus = false;
|
|
9256
|
+
}
|
|
9257
|
+
return loggedInStatus;
|
|
9258
|
+
};
|
|
8866
9259
|
/**
|
|
8867
9260
|
* Perform authentication on the ThoughtSpot cluster
|
|
8868
9261
|
* @param embedConfig The embed configuration
|
|
@@ -8885,7 +9278,28 @@
|
|
|
8885
9278
|
|
|
8886
9279
|
/* eslint-disable import/no-mutable-exports */
|
|
8887
9280
|
let config = {};
|
|
9281
|
+
const CONFIG_DEFAULTS = {
|
|
9282
|
+
loginFailedMessage: 'Login failed',
|
|
9283
|
+
authType: exports.AuthType.None,
|
|
9284
|
+
};
|
|
8888
9285
|
let authPromise;
|
|
9286
|
+
const getEmbedConfig = () => config;
|
|
9287
|
+
const getAuthPromise = () => authPromise;
|
|
9288
|
+
let authEE;
|
|
9289
|
+
function notifyAuthSuccess() {
|
|
9290
|
+
if (!authEE) {
|
|
9291
|
+
console.error('SDK not initialized');
|
|
9292
|
+
return;
|
|
9293
|
+
}
|
|
9294
|
+
authEE.emit(AuthStatus.SUCCESS);
|
|
9295
|
+
}
|
|
9296
|
+
function notifyAuthFailure(failureType) {
|
|
9297
|
+
if (!authEE) {
|
|
9298
|
+
console.error('SDK not initialized');
|
|
9299
|
+
return;
|
|
9300
|
+
}
|
|
9301
|
+
authEE.emit(AuthStatus.FAILURE, failureType);
|
|
9302
|
+
}
|
|
8889
9303
|
/**
|
|
8890
9304
|
* Perform authentication on the ThoughtSpot app as applicable.
|
|
8891
9305
|
*/
|
|
@@ -8895,10 +9309,15 @@
|
|
|
8895
9309
|
thoughtSpotHost: getThoughtSpotHost(config),
|
|
8896
9310
|
};
|
|
8897
9311
|
authPromise = authenticate(authConfig);
|
|
9312
|
+
authPromise.then((isLoggedIn) => {
|
|
9313
|
+
if (!isLoggedIn) {
|
|
9314
|
+
notifyAuthFailure(AuthFailureType.SDK);
|
|
9315
|
+
}
|
|
9316
|
+
}, () => {
|
|
9317
|
+
notifyAuthFailure(AuthFailureType.SDK);
|
|
9318
|
+
});
|
|
8898
9319
|
return authPromise;
|
|
8899
9320
|
};
|
|
8900
|
-
const getEmbedConfig = () => config;
|
|
8901
|
-
const getAuthPromise = () => authPromise;
|
|
8902
9321
|
/**
|
|
8903
9322
|
* 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.
|
|
8904
9323
|
* @param url The URL provided for prefetch
|
|
@@ -8927,7 +9346,8 @@
|
|
|
8927
9346
|
* @returns authPromise Promise which resolves when authentication is complete.
|
|
8928
9347
|
*/
|
|
8929
9348
|
const init = (embedConfig) => {
|
|
8930
|
-
config = embedConfig;
|
|
9349
|
+
config = { ...CONFIG_DEFAULTS, ...embedConfig };
|
|
9350
|
+
authEE = new eventemitter3();
|
|
8931
9351
|
handleAuth();
|
|
8932
9352
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_CALLED_INIT, {
|
|
8933
9353
|
authType: config.authType,
|
|
@@ -8936,7 +9356,10 @@
|
|
|
8936
9356
|
if (config.callPrefetch) {
|
|
8937
9357
|
prefetch(config.thoughtSpotHost);
|
|
8938
9358
|
}
|
|
8939
|
-
return
|
|
9359
|
+
return authEE;
|
|
9360
|
+
};
|
|
9361
|
+
const logout$1 = () => {
|
|
9362
|
+
return logout(config);
|
|
8940
9363
|
};
|
|
8941
9364
|
let renderQueue = Promise.resolve();
|
|
8942
9365
|
/**
|
|
@@ -9022,6 +9445,7 @@
|
|
|
9022
9445
|
var _a, _b;
|
|
9023
9446
|
// Store user session details sent by app.
|
|
9024
9447
|
initSession(e.data);
|
|
9448
|
+
notifyAuthSuccess();
|
|
9025
9449
|
// Expose only allowed details (eg: userGUID) back to SDK users.
|
|
9026
9450
|
return {
|
|
9027
9451
|
...e,
|
|
@@ -9035,9 +9459,28 @@
|
|
|
9035
9459
|
if (autoLogin) {
|
|
9036
9460
|
handleAuth();
|
|
9037
9461
|
}
|
|
9462
|
+
notifyAuthFailure(AuthFailureType.EXPIRY);
|
|
9463
|
+
return e;
|
|
9464
|
+
}
|
|
9465
|
+
function processNoCookieAccess(e, containerEl) {
|
|
9466
|
+
const { loginFailedMessage, suppressNoCookieAccessAlert, } = getEmbedConfig();
|
|
9467
|
+
if (!suppressNoCookieAccessAlert) {
|
|
9468
|
+
// eslint-disable-next-line no-alert
|
|
9469
|
+
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.');
|
|
9470
|
+
}
|
|
9471
|
+
// eslint-disable-next-line no-param-reassign
|
|
9472
|
+
containerEl.innerHTML = loginFailedMessage;
|
|
9473
|
+
notifyAuthFailure(AuthFailureType.NO_COOKIE_ACCESS);
|
|
9474
|
+
return e;
|
|
9475
|
+
}
|
|
9476
|
+
function processAuthFailure(e, containerEl) {
|
|
9477
|
+
const { loginFailedMessage } = getEmbedConfig();
|
|
9478
|
+
// eslint-disable-next-line no-param-reassign
|
|
9479
|
+
containerEl.innerHTML = loginFailedMessage;
|
|
9480
|
+
notifyAuthFailure(AuthFailureType.OTHER);
|
|
9038
9481
|
return e;
|
|
9039
9482
|
}
|
|
9040
|
-
function
|
|
9483
|
+
function processEventData(type, e, thoughtSpotHost, containerEl) {
|
|
9041
9484
|
switch (type) {
|
|
9042
9485
|
case exports.EmbedEvent.CustomAction:
|
|
9043
9486
|
return processCustomAction(e, thoughtSpotHost);
|
|
@@ -9045,6 +9488,10 @@
|
|
|
9045
9488
|
return processAuthInit(e);
|
|
9046
9489
|
case exports.EmbedEvent.AuthExpire:
|
|
9047
9490
|
return processAuthExpire(e);
|
|
9491
|
+
case exports.EmbedEvent.NoCookieAccess:
|
|
9492
|
+
return processNoCookieAccess(e, containerEl);
|
|
9493
|
+
case exports.EmbedEvent.AuthFailure:
|
|
9494
|
+
return processAuthFailure(e, containerEl);
|
|
9048
9495
|
}
|
|
9049
9496
|
return e;
|
|
9050
9497
|
}
|
|
@@ -9073,7 +9520,7 @@
|
|
|
9073
9520
|
}
|
|
9074
9521
|
}
|
|
9075
9522
|
|
|
9076
|
-
var name="@thoughtspot/visual-embed-sdk";var version="1.11.0-auth.
|
|
9523
|
+
var name="@thoughtspot/visual-embed-sdk";var version="1.11.0-auth.11";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};
|
|
9077
9524
|
|
|
9078
9525
|
/**
|
|
9079
9526
|
* Copyright (c) 2022
|
|
@@ -9120,12 +9567,6 @@
|
|
|
9120
9567
|
this.isError = false;
|
|
9121
9568
|
this.viewConfig = viewConfig;
|
|
9122
9569
|
this.shouldEncodeUrlQueryParams = this.embedConfig.shouldEncodeUrlQueryParams;
|
|
9123
|
-
if (!this.embedConfig.suppressNoCookieAccessAlert) {
|
|
9124
|
-
this.on(exports.EmbedEvent.NoCookieAccess, () => {
|
|
9125
|
-
// eslint-disable-next-line no-alert
|
|
9126
|
-
alert('Third party cookie access is blocked on this browser, please allow third party cookies for ThoughtSpot to work properly');
|
|
9127
|
-
});
|
|
9128
|
-
}
|
|
9129
9570
|
}
|
|
9130
9571
|
/**
|
|
9131
9572
|
* Gets a reference to the root DOM node where
|
|
@@ -9202,7 +9643,7 @@
|
|
|
9202
9643
|
const eventPort = this.getEventPort(event);
|
|
9203
9644
|
const eventData = this.formatEventData(event, eventType);
|
|
9204
9645
|
if (event.source === this.iFrame.contentWindow) {
|
|
9205
|
-
this.executeCallbacks(eventType,
|
|
9646
|
+
this.executeCallbacks(eventType, processEventData(eventType, eventData, this.thoughtSpotHost, this.el), eventPort);
|
|
9206
9647
|
}
|
|
9207
9648
|
});
|
|
9208
9649
|
}
|
|
@@ -9323,7 +9764,7 @@
|
|
|
9323
9764
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_START);
|
|
9324
9765
|
(_a = getAuthPromise()) === null || _a === void 0 ? void 0 : _a.then((isLoggedIn) => {
|
|
9325
9766
|
if (!isLoggedIn) {
|
|
9326
|
-
this.el.innerHTML =
|
|
9767
|
+
this.el.innerHTML = this.embedConfig.loginFailedMessage;
|
|
9327
9768
|
return;
|
|
9328
9769
|
}
|
|
9329
9770
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_COMPLETE);
|
|
@@ -9375,6 +9816,7 @@
|
|
|
9375
9816
|
}).catch((error) => {
|
|
9376
9817
|
nextInQueue();
|
|
9377
9818
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_FAILED);
|
|
9819
|
+
this.el.innerHTML = this.embedConfig.loginFailedMessage;
|
|
9378
9820
|
this.handleError(error);
|
|
9379
9821
|
});
|
|
9380
9822
|
});
|
|
@@ -9946,6 +10388,7 @@
|
|
|
9946
10388
|
exports.PinboardEmbed = PinboardEmbed;
|
|
9947
10389
|
exports.SearchEmbed = SearchEmbed;
|
|
9948
10390
|
exports.init = init;
|
|
10391
|
+
exports.logout = logout$1;
|
|
9949
10392
|
exports.prefetch = prefetch;
|
|
9950
10393
|
|
|
9951
10394
|
Object.defineProperty(exports, '__esModule', { value: true });
|