mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 01:14:36 +00:00
chore: code refactor renamed variables/functions
This commit is contained in:
@@ -25,7 +25,7 @@ import {
|
||||
Sas9JobExecutor
|
||||
} from './job-execution'
|
||||
import { ErrorResponse } from './types/errors'
|
||||
import { LoginOptions, LoginReturn } from './types/Login'
|
||||
import { LoginOptions, LoginResult } from './types/Login'
|
||||
|
||||
const defaultConfig: SASjsConfig = {
|
||||
serverUrl: '',
|
||||
@@ -538,7 +538,7 @@ export default class SASjs {
|
||||
username?: string,
|
||||
password?: string,
|
||||
options: LoginOptions = {}
|
||||
): Promise<LoginReturn> {
|
||||
): Promise<LoginResult> {
|
||||
if (this.sasjsConfig.loginMechanism === LoginMechanism.Default) {
|
||||
if (!username || !password) {
|
||||
throw new Error(
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ServerType } from '@sasjs/utils/types'
|
||||
import { RequestClient } from '../request/RequestClient'
|
||||
import { LoginOptions, LoginReturn } from '../types/Login'
|
||||
import { LoginOptions, LoginResult } from '../types/Login'
|
||||
import { serialize } from '../utils'
|
||||
import { openWebPage } from './openWebPage'
|
||||
import { verifyingPopUpLoginSAS9 } from './verifyingPopUpLoginSAS9'
|
||||
import { verifyingPopUpLoginSASVIYA } from './verifyingPopUpLoginSASVIYA'
|
||||
import { verifySas9Login } from './verifySas9Login'
|
||||
import { verifySasViyaLogin } from './verifySasViyaLogin'
|
||||
|
||||
export class AuthManager {
|
||||
public userName = ''
|
||||
@@ -30,7 +30,7 @@ export class AuthManager {
|
||||
*/
|
||||
public async redirectedLogIn({
|
||||
onLoggedOut
|
||||
}: LoginOptions): Promise<LoginReturn> {
|
||||
}: LoginOptions): Promise<LoginResult> {
|
||||
const loginPopup = await openWebPage(
|
||||
this.loginPreventRedirectUrl,
|
||||
'SASLogon',
|
||||
@@ -47,8 +47,8 @@ export class AuthManager {
|
||||
|
||||
const { isLoggedIn } =
|
||||
this.serverType === ServerType.SasViya
|
||||
? await verifyingPopUpLoginSASVIYA(loginPopup)
|
||||
: await verifyingPopUpLoginSAS9(loginPopup)
|
||||
? await verifySasViyaLogin(loginPopup)
|
||||
: await verifySas9Login(loginPopup)
|
||||
|
||||
loginPopup.close()
|
||||
|
||||
@@ -78,7 +78,7 @@ export class AuthManager {
|
||||
* @param password - a string representing the password.
|
||||
* @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 = {
|
||||
_service: 'default',
|
||||
username,
|
||||
@@ -209,7 +209,7 @@ export class AuthManager {
|
||||
//For VIYA we will send request on API endpoint. Which is faster then pinging SASJobExecution.
|
||||
//For SAS9 we will send request on SASStoredProcess
|
||||
const url =
|
||||
this.serverType === 'SASVIYA'
|
||||
this.serverType === ServerType.SasViya
|
||||
? `${this.serverUrl}/identities/users/@currentUser`
|
||||
: `${this.serverUrl}/SASStoredProcess`
|
||||
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { openLoginPrompt } from '../utils/loginPrompt'
|
||||
|
||||
interface windowFeatures {
|
||||
interface WindowFeatures {
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
|
||||
const defaultWindowFeatures: WindowFeatures = { width: 500, height: 600 }
|
||||
|
||||
export async function openWebPage(
|
||||
url: string,
|
||||
windowName: string = '',
|
||||
{ width, height }: windowFeatures,
|
||||
WindowFeatures: WindowFeatures = defaultWindowFeatures,
|
||||
onLoggedOut?: () => Promise<Boolean>
|
||||
): Promise<Window | null> {
|
||||
const { width, height } = WindowFeatures
|
||||
const left = screen.width / 2 - width / 2
|
||||
const top = screen.height / 2 - height / 2
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { delay } from '../utils'
|
||||
|
||||
export async function verifyingPopUpLoginSAS9(loginPopup: Window) {
|
||||
export async function verifySas9Login(loginPopup: Window) {
|
||||
let isLoggedIn = false
|
||||
let startTime = new Date()
|
||||
let elapsedSeconds = 0
|
||||
@@ -1,6 +1,6 @@
|
||||
import { delay } from '../utils'
|
||||
|
||||
export async function verifyingPopUpLoginSASVIYA(loginPopup: Window) {
|
||||
export async function verifySasViyaLogin(loginPopup: Window) {
|
||||
let isLoggedIn = false
|
||||
let startTime = new Date()
|
||||
let elapsedSeconds = 0
|
||||
@@ -18,7 +18,9 @@ export async function verifyingPopUpLoginSASVIYA(loginPopup: Window) {
|
||||
if (loginPopup.closed) break
|
||||
isAuthorized =
|
||||
!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
|
||||
} while (!isAuthorized && elapsedSeconds < 5 * 60)
|
||||
|
||||
@@ -2,7 +2,7 @@ export interface LoginOptions {
|
||||
onLoggedOut?: () => Promise<boolean>
|
||||
}
|
||||
|
||||
export interface LoginReturn {
|
||||
export interface LoginResult {
|
||||
isLoggedIn: boolean
|
||||
userName: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user