Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
*/
export enum AuthFailureType {
SDK = 'SDK',
INVALID_TS_HOST = 'INVALID_TS_HOST',
NO_COOKIE_ACCESS = 'NO_COOKIE_ACCESS',
EXPIRY = 'EXPIRY',
OTHER = 'OTHER',
}

/**
* Enum for auth status emitted by the emitter returned from {@link init}.

Check warning on line 46 in src/auth.ts

View workflow job for this annotation

GitHub Actions / build

The type 'init' is undefined
* @group Authentication / Init
*/
export enum AuthStatus {
Expand All @@ -66,13 +67,13 @@
* Emitted when inPopup is true in the SAMLRedirect flow and the
* popup is waiting to be triggered either programmatically
* or by the trigger button.
* @version SDK: 1.19.0

Check warning on line 70 in src/auth.ts

View workflow job for this annotation

GitHub Actions / build

Invalid JSDoc @Version: "SDK: 1.19.0"
*/
WAITING_FOR_POPUP = 'WAITING_FOR_POPUP',
}

/**
* Event emitter returned from {@link init}.

Check warning on line 76 in src/auth.ts

View workflow job for this annotation

GitHub Actions / build

The type 'init' is undefined
* @group Authentication / Init
*/
export interface AuthEventEmitter {
Expand Down Expand Up @@ -100,7 +101,7 @@
once(event: AuthStatus.SUCCESS, listener: (sessionInfo: any) => void): this;
/**
* Trigger an event on the emitter returned from init.
* @param {@link AuthEvent}

Check warning on line 104 in src/auth.ts

View workflow job for this annotation

GitHub Actions / build

Syntax error in type: @link AuthEvent
*/
emit(event: AuthEvent, ...args: any[]): boolean;
/**
Expand All @@ -119,7 +120,7 @@
}

/**
* Events which can be triggered on the emitter returned from {@link init}.

Check warning on line 123 in src/auth.ts

View workflow job for this annotation

GitHub Actions / build

The type 'init' is undefined
* @group Authentication / Init
*/
export enum AuthEvent {
Expand All @@ -132,7 +133,7 @@

let authEE: EventEmitter<AuthStatus | AuthEvent>;

/**

Check warning on line 136 in src/auth.ts

View workflow job for this annotation

GitHub Actions / build

Missing JSDoc @returns declaration
*
*/
export function getAuthEE(): EventEmitter<AuthStatus | AuthEvent> {
Expand All @@ -141,7 +142,7 @@

/**
*
* @param eventEmitter

Check warning on line 145 in src/auth.ts

View workflow job for this annotation

GitHub Actions / build

Missing JSDoc @param "eventEmitter" description

Check warning on line 145 in src/auth.ts

View workflow job for this annotation

GitHub Actions / build

Missing JSDoc @param "eventEmitter" type
*/
export function setAuthEE(eventEmitter: EventEmitter<AuthStatus | AuthEvent>): void {
authEE = eventEmitter;
Expand Down Expand Up @@ -176,7 +177,7 @@

/**
*
* @param failureType

Check warning on line 180 in src/auth.ts

View workflow job for this annotation

GitHub Actions / build

Missing JSDoc @param "failureType" description

Check warning on line 180 in src/auth.ts

View workflow job for this annotation

GitHub Actions / build

Missing JSDoc @param "failureType" type
*/
export function notifyAuthFailure(failureType: AuthFailureType): void {
if (!authEE) {
Expand Down
16 changes: 16 additions & 0 deletions src/embed/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,25 @@
if (getEmbedConfig().callPrefetch) {
prefetch(getEmbedConfig().thoughtSpotHost);
}
validateThoughtSpotHost(embedConfig.thoughtSpotHost);
return authEE as AuthEventEmitter;
};

Check failure on line 215 in src/embed/base.ts

View workflow job for this annotation

GitHub Actions / build

More than 1 blank line not allowed

const validateThoughtSpotHost = async (thoughtSpotHost: string) => {
try {
const response = await fetch(`${thoughtSpotHost}`);
if (response.status !== 200) {
logger.error(`Check if Thoughtspot Host is Valid: ${response.statusText}`);
notifyAuthFailure(AuthFailureType.INVALID_TS_HOST);
} else {

Check failure on line 223 in src/embed/base.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
logger.info("ThoughtSpot host is valid.");
}
} catch (error) {

Check failure on line 226 in src/embed/base.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
logger.error("Error validating ThoughtSpot host:", error);
notifyAuthFailure(AuthFailureType.INVALID_TS_HOST);
}
};
/**
*
*/
Expand Down
Loading