@sasjs/adapter 3.9.3 → 3.9.4

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/package.json CHANGED
@@ -8,8 +8,9 @@
8
8
  "build": "rimraf build && rimraf node && mkdir node && copyfiles -u 1 \"./src/**/*\" ./node && webpack && rimraf build/src && rimraf node",
9
9
  "package:lib": "npm run build && copyfiles ./package.json ./checkNodeVersion.js build && cd build && npm version \"5.0.0\" && npm pack",
10
10
  "publish:lib": "npm run build && cd build && npm publish",
11
- "lint:fix": "npx prettier --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --write \"sasjs-tests/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
11
+ "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}\"",
12
12
  "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}\"",
13
+ "lint:silent": "npx prettier --loglevel silent --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --loglevel silent --check \"sasjs-tests/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
13
14
  "test": "jest --silent --coverage",
14
15
  "prepublishOnly": "cp -r ./build/* . && rm -rf ./build",
15
16
  "postpublish": "git clean -fd",
@@ -79,5 +80,5 @@
79
80
  "https": "1.0.0",
80
81
  "tough-cookie": "4.0.0"
81
82
  },
82
- "version": "3.9.3"
83
+ "version": "3.9.4"
83
84
  }
package/src/SASjs.ts CHANGED
@@ -592,15 +592,6 @@ export default class SASjs {
592
592
  'A username and password are required when using the default login mechanism.'
593
593
  )
594
594
 
595
- if (this.sasjsConfig.serverType === ServerType.Sasjs) {
596
- if (!clientId)
597
- throw new Error(
598
- 'A username, password and clientId are required when using the default login mechanism with server type SASJS.'
599
- )
600
-
601
- return this.authManager!.logInSasjs(username, password, clientId)
602
- }
603
-
604
595
  return this.authManager!.logIn(username, password)
605
596
  }
606
597
 
@@ -3,7 +3,6 @@ import { ExecutionQuery } from './types'
3
3
  import { RequestClient } from './request/RequestClient'
4
4
  import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
5
5
  import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs'
6
- import { getAuthCodeForSasjs } from './auth/getAuthCodeForSasjs'
7
6
  import { parseWeboutResponse } from './utils'
8
7
  import { getTokens } from './auth/getTokens'
9
8
 
@@ -114,20 +113,6 @@ export class SASjsApiClient {
114
113
  public async refreshTokens(refreshToken: string): Promise<SASjsAuthResponse> {
115
114
  return refreshTokensForSasjs(this.requestClient, refreshToken)
116
115
  }
117
-
118
- /**
119
- * Performs a login authenticate and returns an auth code for the given client.
120
- * @param username - a string representing the username.
121
- * @param password - a string representing the password.
122
- * @param clientId - the client ID to authenticate with.
123
- */
124
- public async getAuthCode(
125
- username: string,
126
- password: string,
127
- clientId: string
128
- ) {
129
- return getAuthCodeForSasjs(this.requestClient, username, password, clientId)
130
- }
131
116
  }
132
117
 
133
118
  // todo move to sasjs/utils
@@ -2,8 +2,6 @@ import { ServerType } from '@sasjs/utils/types'
2
2
  import { RequestClient } from '../request/RequestClient'
3
3
  import { LoginOptions, LoginResult } from '../types/Login'
4
4
  import { serialize } from '../utils'
5
- import { getAccessTokenForSasjs } from './getAccessTokenForSasjs'
6
- import { getAuthCodeForSasjs } from './getAuthCodeForSasjs'
7
5
  import { openWebPage } from './openWebPage'
8
6
  import { verifySas9Login } from './verifySas9Login'
9
7
  import { verifySasViyaLogin } from './verifySasViyaLogin'
@@ -83,39 +81,6 @@ export class AuthManager {
83
81
  return { isLoggedIn: false, userName: '' }
84
82
  }
85
83
 
86
- /**
87
- * Logs into the SAS server with the supplied credentials.
88
- * @param userName - a string representing the username.
89
- * @param password - a string representing the password.
90
- * @param clientId - a string representing the client ID.
91
- * @returns - a boolean `isLoggedin` and a string `username`
92
- */
93
- public async logInSasjs(
94
- username: string,
95
- password: string,
96
- clientId: string
97
- ): Promise<LoginResult> {
98
- const isLoggedIn = await this.sendLoginRequestSasjs(
99
- username,
100
- password,
101
- clientId
102
- )
103
- .then((res) => {
104
- this.userName = username
105
- this.requestClient.saveLocalStorageToken(
106
- res.access_token,
107
- res.refresh_token
108
- )
109
- return true
110
- })
111
- .catch(() => false)
112
-
113
- return {
114
- isLoggedIn,
115
- userName: this.userName
116
- }
117
- }
118
-
119
84
  /**
120
85
  * Logs into the SAS server with the supplied credentials.
121
86
  * @param username - a string representing the username.
@@ -152,7 +117,7 @@ export class AuthManager {
152
117
 
153
118
  let loginResponse = await this.sendLoginRequest(loginForm, loginParams)
154
119
 
155
- let isLoggedIn = isLogInSuccess(loginResponse)
120
+ let isLoggedIn = isLogInSuccess(this.serverType, loginResponse)
156
121
 
157
122
  if (!isLoggedIn) {
158
123
  if (isCredentialsVerifyError(loginResponse)) {
@@ -196,6 +161,17 @@ export class AuthManager {
196
161
  loginForm: { [key: string]: any },
197
162
  loginParams: { [key: string]: any }
198
163
  ) {
164
+ if (this.serverType === ServerType.Sasjs) {
165
+ const { username, password } = loginParams
166
+ const { result: loginResponse } = await this.requestClient.post<string>(
167
+ this.loginUrl,
168
+ { username, password },
169
+ undefined
170
+ )
171
+
172
+ return loginResponse
173
+ }
174
+
199
175
  for (const key in loginForm) {
200
176
  loginParams[key] = loginForm[key]
201
177
  }
@@ -215,19 +191,6 @@ export class AuthManager {
215
191
  return loginResponse
216
192
  }
217
193
 
218
- private async sendLoginRequestSasjs(
219
- username: string,
220
- password: string,
221
- clientId: string
222
- ) {
223
- const authCode = await getAuthCodeForSasjs(
224
- this.requestClient,
225
- username,
226
- password,
227
- clientId
228
- )
229
- return getAccessTokenForSasjs(this.requestClient, clientId, authCode)
230
- }
231
194
  /**
232
195
  * Checks whether a session is active, or login is required.
233
196
  * @returns - a promise which resolves with an object containing three values
@@ -248,8 +211,7 @@ export class AuthManager {
248
211
  //Residue can happen in case of session expiration
249
212
  await this.logOut()
250
213
 
251
- if (this.serverType !== ServerType.Sasjs)
252
- loginForm = await this.getNewLoginForm()
214
+ loginForm = await this.getNewLoginForm()
253
215
  }
254
216
 
255
217
  return Promise.resolve({
@@ -260,6 +222,12 @@ export class AuthManager {
260
222
  }
261
223
 
262
224
  private async getNewLoginForm() {
225
+ if (this.serverType === ServerType.Sasjs) {
226
+ // server will be sending CSRF cookie,
227
+ // http client will use it automatically
228
+ return this.requestClient.get('/', undefined)
229
+ }
230
+
263
231
  const { result: formResponse } = await this.requestClient.get<string>(
264
232
  this.loginUrl.replace('.do', ''),
265
233
  undefined,
@@ -384,5 +352,8 @@ const isCredentialsVerifyError = (response: string): boolean =>
384
352
  response
385
353
  )
386
354
 
387
- const isLogInSuccess = (response: string): boolean =>
388
- /You have signed in/gm.test(response)
355
+ const isLogInSuccess = (serverType: ServerType, response: any): boolean => {
356
+ if (serverType === ServerType.Sasjs) return response?.loggedin
357
+
358
+ return /You have signed in/gm.test(response)
359
+ }
@@ -1,4 +1,4 @@
1
- import { isSpecialMissing } from '@sasjs/utils'
1
+ import { isSpecialMissing } from '@sasjs/utils/input/validators'
2
2
 
3
3
  /**
4
4
  * Converts the given JSON object array to a CSV string.
@@ -1,9 +0,0 @@
1
- import { RequestClient } from '../request/RequestClient';
2
- /**
3
- * Performs a login authenticate and returns an auth code for the given client.
4
- * @param requestClient - the pre-configured HTTP request client
5
- * @param username - a string representing the username.
6
- * @param password - a string representing the password.
7
- * @param clientId - the client ID to authenticate with.
8
- */
9
- export declare const getAuthCodeForSasjs: (requestClient: RequestClient, username: string, password: string, clientId: string) => Promise<string>;
@@ -1,9 +0,0 @@
1
- import { RequestClient } from '../request/RequestClient';
2
- /**
3
- * Performs a login authenticate and returns an auth code for the given client.
4
- * @param requestClient - the pre-configured HTTP request client
5
- * @param username - a string representing the username.
6
- * @param password - a string representing the password.
7
- * @param clientId - the client ID to authenticate with.
8
- */
9
- export declare const getAuthCodeForSasjs: (requestClient: RequestClient, username: string, password: string, clientId: string) => Promise<string>;
@@ -1,31 +0,0 @@
1
- import { prefixMessage } from '@sasjs/utils/error'
2
- import { RequestClient } from '../request/RequestClient'
3
-
4
- /**
5
- * Performs a login authenticate and returns an auth code for the given client.
6
- * @param requestClient - the pre-configured HTTP request client
7
- * @param username - a string representing the username.
8
- * @param password - a string representing the password.
9
- * @param clientId - the client ID to authenticate with.
10
- */
11
- export const getAuthCodeForSasjs = async (
12
- requestClient: RequestClient,
13
- username: string,
14
- password: string,
15
- clientId: string
16
- ) => {
17
- const url = '/SASjsApi/auth/authorize'
18
- const data = { username, password, clientId }
19
-
20
- const { code: authCode } = await requestClient
21
- .post<{ code: string }>(url, data, undefined)
22
- .then((res) => res.result)
23
- .catch((err) => {
24
- throw prefixMessage(
25
- err,
26
- 'Error while authenticating with provided username, password and clientId. '
27
- )
28
- })
29
-
30
- return authCode
31
- }