@sasjs/adapter 3.10.16 → 3.10.18
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/SASjs.d.ts +1 -5
- package/auth/AuthManager.d.ts +6 -7
- package/index.js +2 -2
- package/node/SASjs.d.ts +1 -5
- package/node/auth/AuthManager.d.ts +6 -7
- package/node/index.js +2 -2
- package/node/types/Login.d.ts +7 -0
- package/node/utils/sas9/extractUserLongNameSas9.d.ts +6 -0
- package/package.json +6 -5
- package/src/auth/AuthManager.ts +61 -49
- package/src/types/Login.ts +7 -0
- package/src/utils/sas9/extractUserLongNameSas9.ts +31 -0
- package/types/Login.d.ts +7 -0
- package/utils/sas9/extractUserLongNameSas9.d.ts +6 -0
- package/utils/spec/extractUserLongNameSas9.spec.d.ts +1 -0
package/node/types/Login.d.ts
CHANGED
|
@@ -4,4 +4,11 @@ export interface LoginOptions {
|
|
|
4
4
|
export interface LoginResult {
|
|
5
5
|
isLoggedIn: boolean;
|
|
6
6
|
userName: string;
|
|
7
|
+
userLongName: string;
|
|
8
|
+
}
|
|
9
|
+
export interface LoginResultInternal {
|
|
10
|
+
isLoggedIn: boolean;
|
|
11
|
+
userName: string;
|
|
12
|
+
userLongName: string;
|
|
13
|
+
loginForm?: any;
|
|
7
14
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts user full name assuming the first word after "title" means log off if not found otherwise in the dictionary
|
|
3
|
+
* @param response SAS response content
|
|
4
|
+
* @returns user full name
|
|
5
|
+
*/
|
|
6
|
+
export declare const extractUserLongNameSas9: (response: string) => string;
|
package/package.json
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
"description": "JavaScript adapter for SAS",
|
|
4
4
|
"homepage": "https://adapter.sasjs.io",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"nodeVersionMessage": "echo \u001b[33m make sure you are running node lts version \u001b[0m",
|
|
7
|
+
"preinstall": "npm run nodeVersionMessage",
|
|
8
|
+
"prebuild": "npm run nodeVersionMessage",
|
|
8
9
|
"build": "rimraf build && rimraf node && mkdir node && copyfiles -u 1 \"./src/**/*\" ./node && webpack && rimraf build/src && rimraf node",
|
|
9
|
-
"package:lib": "npm run build && copyfiles ./package.json
|
|
10
|
+
"package:lib": "npm run build && copyfiles ./package.json build && cd build && npm version \"5.0.0\" && npm pack",
|
|
10
11
|
"publish:lib": "npm run build && cd build && npm publish",
|
|
11
12
|
"lint:fix": "npx prettier --loglevel silent --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --loglevel silent --write \"sasjs-tests/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --loglevel silent --write \"cypress/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
|
|
12
13
|
"lint": "npx prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --check \"sasjs-tests/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --check \"cypress/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
|
|
@@ -78,12 +79,12 @@
|
|
|
78
79
|
},
|
|
79
80
|
"main": "index.js",
|
|
80
81
|
"dependencies": {
|
|
81
|
-
"@sasjs/utils": "2.
|
|
82
|
+
"@sasjs/utils": "2.48.2",
|
|
82
83
|
"axios": "0.26.0",
|
|
83
84
|
"axios-cookiejar-support": "1.0.1",
|
|
84
85
|
"form-data": "4.0.0",
|
|
85
86
|
"https": "1.0.0",
|
|
86
87
|
"tough-cookie": "4.0.0"
|
|
87
88
|
},
|
|
88
|
-
"version": "3.10.
|
|
89
|
+
"version": "3.10.18"
|
|
89
90
|
}
|
package/src/auth/AuthManager.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ServerType } from '@sasjs/utils/types'
|
|
2
2
|
import { RequestClient } from '../request/RequestClient'
|
|
3
|
-
import { LoginOptions, LoginResult } from '../types/Login'
|
|
3
|
+
import { LoginOptions, LoginResult, LoginResultInternal } from '../types/Login'
|
|
4
4
|
import { serialize } from '../utils'
|
|
5
|
+
import { extractUserLongNameSas9 } from '../utils/sas9/extractUserLongNameSas9'
|
|
5
6
|
import { openWebPage } from './openWebPage'
|
|
6
7
|
import { verifySas9Login } from './verifySas9Login'
|
|
7
8
|
import { verifySasViyaLogin } from './verifySasViyaLogin'
|
|
8
9
|
|
|
9
10
|
export class AuthManager {
|
|
10
11
|
public userName = ''
|
|
12
|
+
public userLongName = ''
|
|
11
13
|
private loginUrl: string
|
|
12
14
|
private logoutUrl: string
|
|
13
15
|
private redirectedLoginUrl = `/SASLogon/home`
|
|
@@ -33,15 +35,19 @@ export class AuthManager {
|
|
|
33
35
|
public async redirectedLogIn({
|
|
34
36
|
onLoggedOut
|
|
35
37
|
}: LoginOptions): Promise<LoginResult> {
|
|
36
|
-
const {
|
|
37
|
-
|
|
38
|
+
const {
|
|
39
|
+
isLoggedIn: isLoggedInAlready,
|
|
40
|
+
userName: currentSessionUserName,
|
|
41
|
+
userLongName: currentSessionUserLongName
|
|
42
|
+
} = await this.fetchUserName()
|
|
38
43
|
|
|
39
44
|
if (isLoggedInAlready) {
|
|
40
45
|
await this.loginCallback()
|
|
41
46
|
|
|
42
47
|
return {
|
|
43
48
|
isLoggedIn: true,
|
|
44
|
-
userName:
|
|
49
|
+
userName: currentSessionUserName,
|
|
50
|
+
userLongName: currentSessionUserLongName
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
|
|
@@ -56,7 +62,7 @@ export class AuthManager {
|
|
|
56
62
|
)
|
|
57
63
|
|
|
58
64
|
if (!loginPopup) {
|
|
59
|
-
return { isLoggedIn: false, userName: '' }
|
|
65
|
+
return { isLoggedIn: false, userName: '', userLongName: '' }
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
const { isLoggedIn } =
|
|
@@ -71,14 +77,14 @@ export class AuthManager {
|
|
|
71
77
|
await this.performCASSecurityCheck()
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
const { userName } = await this.fetchUserName()
|
|
80
|
+
const { userName, userLongName } = await this.fetchUserName()
|
|
75
81
|
|
|
76
82
|
await this.loginCallback()
|
|
77
83
|
|
|
78
|
-
return { isLoggedIn: true, userName }
|
|
84
|
+
return { isLoggedIn: true, userName, userLongName }
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
return { isLoggedIn: false, userName: '' }
|
|
87
|
+
return { isLoggedIn: false, userName: '', userLongName: '' }
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
/**
|
|
@@ -93,27 +99,26 @@ export class AuthManager {
|
|
|
93
99
|
username,
|
|
94
100
|
password
|
|
95
101
|
}
|
|
102
|
+
this.userName = ''
|
|
103
|
+
this.userLongName = ''
|
|
96
104
|
|
|
97
105
|
let {
|
|
98
106
|
isLoggedIn: isLoggedInAlready,
|
|
99
107
|
loginForm,
|
|
100
|
-
|
|
108
|
+
userLongName: currentSessionUserLongName
|
|
101
109
|
} = await this.checkSession()
|
|
102
110
|
|
|
103
111
|
if (isLoggedInAlready) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
} else {
|
|
113
|
-
await this.logOut()
|
|
114
|
-
loginForm = await this.getNewLoginForm()
|
|
112
|
+
await this.loginCallback()
|
|
113
|
+
|
|
114
|
+
this.userName = loginParams.username
|
|
115
|
+
this.userLongName = currentSessionUserLongName
|
|
116
|
+
return {
|
|
117
|
+
isLoggedIn: true,
|
|
118
|
+
userName: this.userName,
|
|
119
|
+
userLongName: this.userLongName
|
|
115
120
|
}
|
|
116
|
-
}
|
|
121
|
+
}
|
|
117
122
|
|
|
118
123
|
let loginResponse = await this.sendLoginRequest(loginForm, loginParams)
|
|
119
124
|
|
|
@@ -128,10 +133,7 @@ export class AuthManager {
|
|
|
128
133
|
|
|
129
134
|
const res = await this.checkSession()
|
|
130
135
|
isLoggedIn = res.isLoggedIn
|
|
131
|
-
|
|
132
|
-
if (isLoggedIn) this.userName = res.userName
|
|
133
|
-
} else {
|
|
134
|
-
this.userName = loginParams.username
|
|
136
|
+
this.userLongName = res.userLongName
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
if (isLoggedIn) {
|
|
@@ -140,11 +142,13 @@ export class AuthManager {
|
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
this.loginCallback()
|
|
143
|
-
|
|
145
|
+
this.userName = loginParams.username
|
|
146
|
+
}
|
|
144
147
|
|
|
145
148
|
return {
|
|
146
149
|
isLoggedIn,
|
|
147
|
-
userName: this.userName
|
|
150
|
+
userName: this.userName,
|
|
151
|
+
userLongName: this.userLongName
|
|
148
152
|
}
|
|
149
153
|
}
|
|
150
154
|
|
|
@@ -195,15 +199,12 @@ export class AuthManager {
|
|
|
195
199
|
* Checks whether a session is active, or login is required.
|
|
196
200
|
* @returns - a promise which resolves with an object containing three values
|
|
197
201
|
* - a boolean `isLoggedIn`
|
|
198
|
-
* - a string `userName
|
|
202
|
+
* - a string `userName`,
|
|
203
|
+
* - a string `userFullName` and
|
|
199
204
|
* - a form `loginForm` if not loggedin.
|
|
200
205
|
*/
|
|
201
|
-
public async checkSession(): Promise<{
|
|
202
|
-
isLoggedIn
|
|
203
|
-
userName: string
|
|
204
|
-
loginForm?: any
|
|
205
|
-
}> {
|
|
206
|
-
const { isLoggedIn, userName } = await this.fetchUserName()
|
|
206
|
+
public async checkSession(): Promise<LoginResultInternal> {
|
|
207
|
+
const { isLoggedIn, userName, userLongName } = await this.fetchUserName()
|
|
207
208
|
let loginForm = null
|
|
208
209
|
|
|
209
210
|
if (!isLoggedIn) {
|
|
@@ -216,7 +217,8 @@ export class AuthManager {
|
|
|
216
217
|
|
|
217
218
|
return Promise.resolve({
|
|
218
219
|
isLoggedIn,
|
|
219
|
-
userName
|
|
220
|
+
userName,
|
|
221
|
+
userLongName,
|
|
220
222
|
loginForm
|
|
221
223
|
})
|
|
222
224
|
}
|
|
@@ -245,10 +247,7 @@ export class AuthManager {
|
|
|
245
247
|
return await this.getLoginForm(formResponse)
|
|
246
248
|
}
|
|
247
249
|
|
|
248
|
-
private async fetchUserName(): Promise<{
|
|
249
|
-
isLoggedIn: boolean
|
|
250
|
-
userName: string
|
|
251
|
-
}> {
|
|
250
|
+
private async fetchUserName(): Promise<LoginResult> {
|
|
252
251
|
const url =
|
|
253
252
|
this.serverType === ServerType.SasViya
|
|
254
253
|
? `${this.serverUrl}/identities/users/@currentUser`
|
|
@@ -263,15 +262,19 @@ export class AuthManager {
|
|
|
263
262
|
})
|
|
264
263
|
|
|
265
264
|
const isLoggedIn = loginResponse !== 'authErr'
|
|
266
|
-
const userName = isLoggedIn ? this.extractUserName(loginResponse) : ''
|
|
267
265
|
|
|
268
266
|
if (!isLoggedIn) {
|
|
269
267
|
//We will logout to make sure cookies are removed and login form is presented
|
|
270
268
|
//Residue can happen in case of session expiration
|
|
271
269
|
await this.logOut()
|
|
270
|
+
return { isLoggedIn, userName: '', userLongName: '' }
|
|
272
271
|
}
|
|
273
272
|
|
|
274
|
-
return {
|
|
273
|
+
return {
|
|
274
|
+
isLoggedIn,
|
|
275
|
+
userName: this.extractUserName(loginResponse),
|
|
276
|
+
userLongName: this.extractUserLongName(loginResponse)
|
|
277
|
+
}
|
|
275
278
|
}
|
|
276
279
|
|
|
277
280
|
private extractUserName = (response: any): string => {
|
|
@@ -280,18 +283,27 @@ export class AuthManager {
|
|
|
280
283
|
return response?.id
|
|
281
284
|
|
|
282
285
|
case ServerType.Sas9:
|
|
283
|
-
|
|
284
|
-
|
|
286
|
+
return ''
|
|
287
|
+
|
|
288
|
+
case ServerType.Sasjs:
|
|
289
|
+
return response?.username
|
|
290
|
+
|
|
291
|
+
default:
|
|
292
|
+
console.error('Server Type not found in extractUserName function')
|
|
293
|
+
return ''
|
|
294
|
+
}
|
|
295
|
+
}
|
|
285
296
|
|
|
286
|
-
|
|
297
|
+
private extractUserLongName = (response: any): string => {
|
|
298
|
+
switch (this.serverType) {
|
|
299
|
+
case ServerType.SasViya:
|
|
300
|
+
return response?.name
|
|
287
301
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
.map((name: string) => name.slice(0, 3).toLowerCase())
|
|
291
|
-
.join('')
|
|
302
|
+
case ServerType.Sas9:
|
|
303
|
+
return extractUserLongNameSas9(response)
|
|
292
304
|
|
|
293
305
|
case ServerType.Sasjs:
|
|
294
|
-
return response?.
|
|
306
|
+
return response?.displayName
|
|
295
307
|
|
|
296
308
|
default:
|
|
297
309
|
console.error('Server Type not found in extractUserName function')
|
package/src/types/Login.ts
CHANGED
|
@@ -5,4 +5,11 @@ export interface LoginOptions {
|
|
|
5
5
|
export interface LoginResult {
|
|
6
6
|
isLoggedIn: boolean
|
|
7
7
|
userName: string
|
|
8
|
+
userLongName: string
|
|
9
|
+
}
|
|
10
|
+
export interface LoginResultInternal {
|
|
11
|
+
isLoggedIn: boolean
|
|
12
|
+
userName: string
|
|
13
|
+
userLongName: string
|
|
14
|
+
loginForm?: any
|
|
8
15
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dictionary should contain only languages in SAS where `logout` text
|
|
3
|
+
* is represented with more then one word
|
|
4
|
+
*/
|
|
5
|
+
const dictionary = ['Log Off']
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Extracts user full name assuming the first word after "title" means log off if not found otherwise in the dictionary
|
|
9
|
+
* @param response SAS response content
|
|
10
|
+
* @returns user full name
|
|
11
|
+
*/
|
|
12
|
+
export const extractUserLongNameSas9 = (response: string) => {
|
|
13
|
+
const regex = /"title":\s?".*?"/
|
|
14
|
+
|
|
15
|
+
const matched = response?.match(regex)
|
|
16
|
+
let fullName = matched?.[0].split(':')[1].trim()
|
|
17
|
+
let breakIndex = fullName?.indexOf(' ')
|
|
18
|
+
|
|
19
|
+
if (!fullName) return 'unknown'
|
|
20
|
+
|
|
21
|
+
dictionary.map((logoutWord) => {
|
|
22
|
+
const index = fullName?.indexOf(logoutWord) || -1
|
|
23
|
+
|
|
24
|
+
if (index > -1) {
|
|
25
|
+
breakIndex = index + logoutWord.length
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
//Cut only name
|
|
30
|
+
return fullName.slice(breakIndex, -1).trim()
|
|
31
|
+
}
|
package/types/Login.d.ts
CHANGED
|
@@ -4,4 +4,11 @@ export interface LoginOptions {
|
|
|
4
4
|
export interface LoginResult {
|
|
5
5
|
isLoggedIn: boolean;
|
|
6
6
|
userName: string;
|
|
7
|
+
userLongName: string;
|
|
8
|
+
}
|
|
9
|
+
export interface LoginResultInternal {
|
|
10
|
+
isLoggedIn: boolean;
|
|
11
|
+
userName: string;
|
|
12
|
+
userLongName: string;
|
|
13
|
+
loginForm?: any;
|
|
7
14
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts user full name assuming the first word after "title" means log off if not found otherwise in the dictionary
|
|
3
|
+
* @param response SAS response content
|
|
4
|
+
* @returns user full name
|
|
5
|
+
*/
|
|
6
|
+
export declare const extractUserLongNameSas9: (response: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|