From e3d6814fa3106b6cdb6f45ff5cbcc9c6e8201271 Mon Sep 17 00:00:00 2001 From: Henrique Serro Date: Tue, 5 Oct 2021 21:33:13 +0200 Subject: [PATCH] Linting fixes --- src/Oauth.ts | 6 +-- src/index.ts | 113 +++++++++++++++++++++++++++------------------------ 2 files changed, 60 insertions(+), 59 deletions(-) diff --git a/src/Oauth.ts b/src/Oauth.ts index 30cf8b5..a46f62d 100644 --- a/src/Oauth.ts +++ b/src/Oauth.ts @@ -128,11 +128,7 @@ export async function pollOauthSession(config: AuthenticationConfig, sessionId: } } -export async function getAccessToken( - config: AuthenticationConfig, - code: string, - codeVerifier: string, -): Promise { +export async function getAccessToken(config: AuthenticationConfig, code: string, codeVerifier: string): Promise { if (!config.domain) { throw new Error('No domain provided!'); } diff --git a/src/index.ts b/src/index.ts index 9abc005..19b3811 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,27 +7,26 @@ import { pollOauthSession, getAccessToken, getRefreshToken, - revokeToken + revokeToken, } from './Oauth'; const DOMAIN_WINDOW_DEFAULT_URL = 'https://dev.frontify.test/finder'; const POPUP_DEFAULT_TITLE = 'Authorize Frontify'; const POPUP_STATE = { - open: false -} + open: false, +}; let popup: Popup; export async function authorize( configuration: AuthenticationConfig, - popupConfiguration?: PopupConfiguration -): Promise{ - + popupConfiguration?: PopupConfiguration, +): Promise { if (POPUP_STATE.open) { logMessage('warning', { code: 'ERR_POPUP_OPEN', - message: 'Popup already open!' - }) + message: 'Popup already open!', + }); throw new Error('Popup already open!'); } @@ -44,29 +43,33 @@ export async function authorize( POPUP_STATE.open = true; if (!configuration.domain) { - return openDomainPopUp(configuration, popup).then((res) => { - POPUP_STATE.open = false; - if (res) { - return res; - } - }).catch(() => { - delete(configuration.domain); - logMessage('error', { - code: 'ERR_AUTH_SKIPPED', - message: 'Domain not inserted!' + return openDomainPopUp(configuration, popup) + .then((res) => { + POPUP_STATE.open = false; + if (res) { + return res; + } + }) + .catch(() => { + delete configuration.domain; + logMessage('error', { + code: 'ERR_AUTH_SKIPPED', + message: 'Domain not inserted!', + }); + throw new Error('Domain not inserted!'); }); - throw new Error('Domain not inserted!'); - }); } else { - return authenticate(configuration, popup).then((res) => { - POPUP_STATE.open = false; - if (res) { - return res; - } - }).catch((error) => { - POPUP_STATE.open = false; - throw new Error(error); - }); + return authenticate(configuration, popup) + .then((res) => { + POPUP_STATE.open = false; + if (res) { + return res; + } + }) + .catch((error) => { + POPUP_STATE.open = false; + throw new Error(error); + }); } } @@ -75,7 +78,7 @@ export async function refresh(token: Token): Promise { } export async function revoke(token: Token): Promise { - await revokeToken(token.bearerToken.domain, token.bearerToken.accessToken) + await revokeToken(token.bearerToken.domain, token.bearerToken.accessToken); return token; } @@ -87,10 +90,10 @@ async function authenticate(configuration: AuthenticationConfig, popUp: Popup): return getAccessToken(configuration, authorizationCode, codeVerifier); } catch (error) { const errorMessage = `Error generating session. Make sure that the inserted domain is a valid and secure Frontify instance.`; - popUp.popUp?.postMessage({domainError: errorMessage}, '*'); + popUp.popUp?.postMessage({ domainError: errorMessage }, '*'); logMessage('error', { code: 'ERR_AUTH_FAILED', - message: errorMessage + message: errorMessage, }); throw new Error(errorMessage); } @@ -101,7 +104,7 @@ function openDomainPopUp(configuration: AuthenticationConfig, popUp: Popup): Pro logMessage('warning', { code: 'WARN_DOMAIN_OPEN', - message: 'Popup window opened!' + message: 'Popup window opened!', }); return new Promise((resolve, reject) => { @@ -111,22 +114,24 @@ function openDomainPopUp(configuration: AuthenticationConfig, popUp: Popup): Pro reject(); logMessage('error', { code: 'ERR_DOMAIN_TIMEOUT', - message: 'Popup window timeout!' - }) + message: 'Popup window timeout!', + }); }, 5 * 60 * 1000); popUp.onDomain(() => { clearTimeout(timeout); configuration.domain = popup.getDomain(); - authenticate(configuration, popup).then((result) => { - resolve(result); - }).catch((error) => { - throw new Error(error ?? 'Could not verify instance!'); - }); + authenticate(configuration, popup) + .then((result) => { + resolve(result); + }) + .catch((error) => { + throw new Error(error ?? 'Could not verify instance!'); + }); logMessage('warning', { code: 'WARN_DOMAIN_SELECT', - message: 'Domain input submitted!' - }) + message: 'Domain input submitted!', + }); }); popUp.onAborted(() => { @@ -136,8 +141,8 @@ function openDomainPopUp(configuration: AuthenticationConfig, popUp: Popup): Pro reject(); logMessage('warning', { code: 'WARN_DOMAIN_CLOSED', - message: 'Popup window closed!' - }) + message: 'Popup window closed!', + }); }); }); } @@ -147,7 +152,7 @@ function openAuthPopUp(url: string, popUp: Popup): Promise { logMessage('warning', { code: 'WARN_DOMAIN_OPEN', - message: 'Popup window opened!' + message: 'Popup window opened!', }); return new Promise((resolve, reject) => { @@ -157,8 +162,8 @@ function openAuthPopUp(url: string, popUp: Popup): Promise { reject(); logMessage('error', { code: 'ERR_DOMAIN_TIMEOUT', - message: 'Popup window timeout!' - }) + message: 'Popup window timeout!', + }); }, 5 * 60 * 1000); popUp.onAborted(() => { @@ -168,8 +173,8 @@ function openAuthPopUp(url: string, popUp: Popup): Promise { reject(); logMessage('warning', { code: 'WARN_DOMAIN_CLOSED', - message: 'Popup window closed!' - }) + message: 'Popup window closed!', + }); }); popUp.onSuccess(() => { @@ -179,8 +184,8 @@ function openAuthPopUp(url: string, popUp: Popup): Promise { resolve(); logMessage('warning', { code: 'WARN_AUTH_SUCCESS', - message: 'Auth success!' - }) + message: 'Auth success!', + }); }); popUp.onCancelled(() => { @@ -190,12 +195,12 @@ function openAuthPopUp(url: string, popUp: Popup): Promise { reject(); logMessage('warning', { code: 'WARN_AUTH_CANCELLED', - message: 'Auth cancelled!' - }) + message: 'Auth cancelled!', + }); }); }); } function createPopUp(configuration: PopupConfiguration): Popup { return new Popup(configuration ?? {}); -} \ No newline at end of file +}