1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-18 17:40:06 +00:00

chore: code refactor renamed variables/functions

This commit is contained in:
Saad Jutt
2021-09-08 05:49:24 +05:00
parent cd2b32f2f4
commit 19a57dbf6e
6 changed files with 21 additions and 16 deletions

View File

@@ -25,7 +25,7 @@ import {
Sas9JobExecutor Sas9JobExecutor
} from './job-execution' } from './job-execution'
import { ErrorResponse } from './types/errors' import { ErrorResponse } from './types/errors'
import { LoginOptions, LoginReturn } from './types/Login' import { LoginOptions, LoginResult } from './types/Login'
const defaultConfig: SASjsConfig = { const defaultConfig: SASjsConfig = {
serverUrl: '', serverUrl: '',
@@ -538,7 +538,7 @@ export default class SASjs {
username?: string, username?: string,
password?: string, password?: string,
options: LoginOptions = {} options: LoginOptions = {}
): Promise<LoginReturn> { ): Promise<LoginResult> {
if (this.sasjsConfig.loginMechanism === LoginMechanism.Default) { if (this.sasjsConfig.loginMechanism === LoginMechanism.Default) {
if (!username || !password) { if (!username || !password) {
throw new Error( throw new Error(

View File

@@ -1,10 +1,10 @@
import { ServerType } from '@sasjs/utils/types' import { ServerType } from '@sasjs/utils/types'
import { RequestClient } from '../request/RequestClient' import { RequestClient } from '../request/RequestClient'
import { LoginOptions, LoginReturn } from '../types/Login' import { LoginOptions, LoginResult } from '../types/Login'
import { serialize } from '../utils' import { serialize } from '../utils'
import { openWebPage } from './openWebPage' import { openWebPage } from './openWebPage'
import { verifyingPopUpLoginSAS9 } from './verifyingPopUpLoginSAS9' import { verifySas9Login } from './verifySas9Login'
import { verifyingPopUpLoginSASVIYA } from './verifyingPopUpLoginSASVIYA' import { verifySasViyaLogin } from './verifySasViyaLogin'
export class AuthManager { export class AuthManager {
public userName = '' public userName = ''
@@ -30,7 +30,7 @@ export class AuthManager {
*/ */
public async redirectedLogIn({ public async redirectedLogIn({
onLoggedOut onLoggedOut
}: LoginOptions): Promise<LoginReturn> { }: LoginOptions): Promise<LoginResult> {
const loginPopup = await openWebPage( const loginPopup = await openWebPage(
this.loginPreventRedirectUrl, this.loginPreventRedirectUrl,
'SASLogon', 'SASLogon',
@@ -47,8 +47,8 @@ export class AuthManager {
const { isLoggedIn } = const { isLoggedIn } =
this.serverType === ServerType.SasViya this.serverType === ServerType.SasViya
? await verifyingPopUpLoginSASVIYA(loginPopup) ? await verifySasViyaLogin(loginPopup)
: await verifyingPopUpLoginSAS9(loginPopup) : await verifySas9Login(loginPopup)
loginPopup.close() loginPopup.close()
@@ -78,7 +78,7 @@ export class AuthManager {
* @param password - a string representing the password. * @param password - a string representing the password.
* @returns - a boolean `isLoggedin` and a string `username` * @returns - a boolean `isLoggedin` and a string `username`
*/ */
public async logIn(username: string, password: string): Promise<LoginReturn> { public async logIn(username: string, password: string): Promise<LoginResult> {
const loginParams = { const loginParams = {
_service: 'default', _service: 'default',
username, username,
@@ -209,7 +209,7 @@ export class AuthManager {
//For VIYA we will send request on API endpoint. Which is faster then pinging SASJobExecution. //For VIYA we will send request on API endpoint. Which is faster then pinging SASJobExecution.
//For SAS9 we will send request on SASStoredProcess //For SAS9 we will send request on SASStoredProcess
const url = const url =
this.serverType === 'SASVIYA' this.serverType === ServerType.SasViya
? `${this.serverUrl}/identities/users/@currentUser` ? `${this.serverUrl}/identities/users/@currentUser`
: `${this.serverUrl}/SASStoredProcess` : `${this.serverUrl}/SASStoredProcess`

View File

@@ -1,16 +1,19 @@
import { openLoginPrompt } from '../utils/loginPrompt' import { openLoginPrompt } from '../utils/loginPrompt'
interface windowFeatures { interface WindowFeatures {
width: number width: number
height: number height: number
} }
const defaultWindowFeatures: WindowFeatures = { width: 500, height: 600 }
export async function openWebPage( export async function openWebPage(
url: string, url: string,
windowName: string = '', windowName: string = '',
{ width, height }: windowFeatures, WindowFeatures: WindowFeatures = defaultWindowFeatures,
onLoggedOut?: () => Promise<Boolean> onLoggedOut?: () => Promise<Boolean>
): Promise<Window | null> { ): Promise<Window | null> {
const { width, height } = WindowFeatures
const left = screen.width / 2 - width / 2 const left = screen.width / 2 - width / 2
const top = screen.height / 2 - height / 2 const top = screen.height / 2 - height / 2

View File

@@ -1,6 +1,6 @@
import { delay } from '../utils' import { delay } from '../utils'
export async function verifyingPopUpLoginSAS9(loginPopup: Window) { export async function verifySas9Login(loginPopup: Window) {
let isLoggedIn = false let isLoggedIn = false
let startTime = new Date() let startTime = new Date()
let elapsedSeconds = 0 let elapsedSeconds = 0

View File

@@ -1,6 +1,6 @@
import { delay } from '../utils' import { delay } from '../utils'
export async function verifyingPopUpLoginSASVIYA(loginPopup: Window) { export async function verifySasViyaLogin(loginPopup: Window) {
let isLoggedIn = false let isLoggedIn = false
let startTime = new Date() let startTime = new Date()
let elapsedSeconds = 0 let elapsedSeconds = 0
@@ -18,7 +18,9 @@ export async function verifyingPopUpLoginSASVIYA(loginPopup: Window) {
if (loginPopup.closed) break if (loginPopup.closed) break
isAuthorized = isAuthorized =
!loginPopup.window.location.href.includes('SASLogon') || !loginPopup.window.location.href.includes('SASLogon') ||
loginPopup.window.document.body.innerText.includes('You have signed in.') loginPopup.window.document.body?.innerText?.includes(
'You have signed in.'
)
elapsedSeconds = (new Date().valueOf() - startTime.valueOf()) / 1000 elapsedSeconds = (new Date().valueOf() - startTime.valueOf()) / 1000
} while (!isAuthorized && elapsedSeconds < 5 * 60) } while (!isAuthorized && elapsedSeconds < 5 * 60)

View File

@@ -2,7 +2,7 @@ export interface LoginOptions {
onLoggedOut?: () => Promise<boolean> onLoggedOut?: () => Promise<boolean>
} }
export interface LoginReturn { export interface LoginResult {
isLoggedIn: boolean isLoggedIn: boolean
userName: string userName: string
} }