@sasjs/adapter 3.0.2 → 3.1.0
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 +7 -2
- package/auth/AuthManager.d.ts +7 -2
- package/index.js +2 -2
- package/node/SASjs.d.ts +7 -2
- package/node/auth/AuthManager.d.ts +7 -2
- package/node/index.js +2 -2
- package/node/types/SASjsConfig.d.ts +5 -0
- package/node/utils/getValidJson.d.ts +1 -1
- package/node/utils/parseViyaDebugResponse.d.ts +1 -1
- package/package.json +1 -1
- package/src/SASjs.ts +10 -5
- package/src/auth/AuthManager.ts +21 -10
- package/src/job-execution/WebJobExecutor.ts +18 -3
- package/src/types/SASjsConfig.ts +5 -0
- package/src/utils/getValidJson.ts +1 -1
- package/src/utils/parseWeboutResponse.ts +1 -1
- package/types/SASjsConfig.d.ts +5 -0
- package/utils/getValidJson.d.ts +1 -1
- package/utils/parseViyaDebugResponse.d.ts +1 -1
|
@@ -12,6 +12,11 @@ export declare class SASjsConfig {
|
|
|
12
12
|
* streamed.
|
|
13
13
|
*/
|
|
14
14
|
serverUrl: string;
|
|
15
|
+
/**
|
|
16
|
+
* The location of the STP Process Web Application. By default the adapter
|
|
17
|
+
* will use '/SASjsApi/stp/execute' on SAS JS.
|
|
18
|
+
*/
|
|
19
|
+
pathSASJS?: string;
|
|
15
20
|
/**
|
|
16
21
|
* The location of the Stored Process Web Application. By default the adapter
|
|
17
22
|
* will use '/SASStoredProcess/do' on SAS 9.
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* if string passed then parse the string to json else if throw error for all other types unless it is not a valid json object.
|
|
3
3
|
* @param str - string to check.
|
|
4
4
|
*/
|
|
5
|
-
export declare const getValidJson: (str: string | object) =>
|
|
5
|
+
export declare const getValidJson: (str: string | object) => object;
|
|
@@ -9,4 +9,4 @@ import { RequestClient } from '../request/RequestClient';
|
|
|
9
9
|
* @param serverUrl
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
export declare const parseSasViyaDebugResponse: (response: string, requestClient: RequestClient, serverUrl: string) => Promise<
|
|
12
|
+
export declare const parseSasViyaDebugResponse: (response: string, requestClient: RequestClient, serverUrl: string) => Promise<object>;
|
package/package.json
CHANGED
package/src/SASjs.ts
CHANGED
|
@@ -33,6 +33,7 @@ import { LoginOptions, LoginResult } from './types/Login'
|
|
|
33
33
|
|
|
34
34
|
const defaultConfig: SASjsConfig = {
|
|
35
35
|
serverUrl: '',
|
|
36
|
+
pathSASJS: '/SASjsApi/stp/execute',
|
|
36
37
|
pathSAS9: '/SASStoredProcess/do',
|
|
37
38
|
pathSASViya: '/SASJobExecution',
|
|
38
39
|
appLoc: '/Public/seedapp',
|
|
@@ -527,10 +528,11 @@ export default class SASjs {
|
|
|
527
528
|
|
|
528
529
|
/**
|
|
529
530
|
* Checks whether a session is active, or login is required.
|
|
531
|
+
* @param accessToken - an optional access token is required for SASjs server type.
|
|
530
532
|
* @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`.
|
|
531
533
|
*/
|
|
532
|
-
public async checkSession() {
|
|
533
|
-
return this.authManager!.checkSession()
|
|
534
|
+
public async checkSession(accessToken?: string) {
|
|
535
|
+
return this.authManager!.checkSession(accessToken)
|
|
534
536
|
}
|
|
535
537
|
|
|
536
538
|
/**
|
|
@@ -563,9 +565,10 @@ export default class SASjs {
|
|
|
563
565
|
|
|
564
566
|
/**
|
|
565
567
|
* Logs out of the configured SAS server.
|
|
568
|
+
* @param accessToken - an optional access token is required for SASjs server type.
|
|
566
569
|
*/
|
|
567
|
-
public logOut() {
|
|
568
|
-
return this.authManager!.logOut()
|
|
570
|
+
public logOut(accessToken?: string) {
|
|
571
|
+
return this.authManager!.logOut(accessToken)
|
|
569
572
|
}
|
|
570
573
|
|
|
571
574
|
/**
|
|
@@ -975,7 +978,9 @@ export default class SASjs {
|
|
|
975
978
|
this.jobsPath =
|
|
976
979
|
this.sasjsConfig.serverType === ServerType.SasViya
|
|
977
980
|
? this.sasjsConfig.pathSASViya
|
|
978
|
-
: this.sasjsConfig.
|
|
981
|
+
: this.sasjsConfig.serverType === ServerType.Sas9
|
|
982
|
+
? this.sasjsConfig.pathSAS9
|
|
983
|
+
: this.sasjsConfig.pathSASJS || ''
|
|
979
984
|
|
|
980
985
|
this.authManager = new AuthManager(
|
|
981
986
|
this.sasjsConfig.serverUrl,
|
package/src/auth/AuthManager.ts
CHANGED
|
@@ -21,7 +21,9 @@ export class AuthManager {
|
|
|
21
21
|
this.logoutUrl =
|
|
22
22
|
this.serverType === ServerType.Sas9
|
|
23
23
|
? '/SASLogon/logout?'
|
|
24
|
-
:
|
|
24
|
+
: this.serverType === ServerType.SasViya
|
|
25
|
+
? '/SASLogon/logout.do?'
|
|
26
|
+
: '/SASjsApi/auth/logout'
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
/**
|
|
@@ -180,20 +182,21 @@ export class AuthManager {
|
|
|
180
182
|
|
|
181
183
|
/**
|
|
182
184
|
* Checks whether a session is active, or login is required.
|
|
185
|
+
* @param accessToken - an optional access token is required for SASjs server type.
|
|
183
186
|
* @returns - a promise which resolves with an object containing three values
|
|
184
187
|
* - a boolean `isLoggedIn`
|
|
185
188
|
* - a string `userName` and
|
|
186
189
|
* - a form `loginForm` if not loggedin.
|
|
187
190
|
*/
|
|
188
|
-
public async checkSession(): Promise<{
|
|
191
|
+
public async checkSession(accessToken?: string): Promise<{
|
|
189
192
|
isLoggedIn: boolean
|
|
190
193
|
userName: string
|
|
191
194
|
loginForm?: any
|
|
192
195
|
}> {
|
|
193
|
-
const { isLoggedIn, userName } = await this.fetchUserName()
|
|
196
|
+
const { isLoggedIn, userName } = await this.fetchUserName(accessToken)
|
|
194
197
|
let loginForm = null
|
|
195
198
|
|
|
196
|
-
if (!isLoggedIn) {
|
|
199
|
+
if (!isLoggedIn && this.serverType !== ServerType.Sasjs) {
|
|
197
200
|
//We will logout to make sure cookies are removed and login form is presented
|
|
198
201
|
//Residue can happen in case of session expiration
|
|
199
202
|
await this.logOut()
|
|
@@ -218,19 +221,20 @@ export class AuthManager {
|
|
|
218
221
|
return await this.getLoginForm(formResponse)
|
|
219
222
|
}
|
|
220
223
|
|
|
221
|
-
private async fetchUserName(): Promise<{
|
|
224
|
+
private async fetchUserName(accessToken?: string): Promise<{
|
|
222
225
|
isLoggedIn: boolean
|
|
223
226
|
userName: string
|
|
224
227
|
}> {
|
|
225
|
-
//For VIYA we will send request on API endpoint. Which is faster then pinging SASJobExecution.
|
|
226
|
-
//For SAS9 we will send request on SASStoredProcess
|
|
227
228
|
const url =
|
|
228
229
|
this.serverType === ServerType.SasViya
|
|
229
230
|
? `${this.serverUrl}/identities/users/@currentUser`
|
|
230
|
-
:
|
|
231
|
+
: this.serverType === ServerType.Sas9
|
|
232
|
+
? `${this.serverUrl}/SASStoredProcess`
|
|
233
|
+
: `${this.serverUrl}/SASjsApi/session`
|
|
231
234
|
|
|
235
|
+
// Access token is required for server type `SASjs`
|
|
232
236
|
const { result: loginResponse } = await this.requestClient
|
|
233
|
-
.get<string>(url,
|
|
237
|
+
.get<string>(url, accessToken, 'text/plain')
|
|
234
238
|
.catch((err: any) => {
|
|
235
239
|
return { result: 'authErr' }
|
|
236
240
|
})
|
|
@@ -257,6 +261,9 @@ export class AuthManager {
|
|
|
257
261
|
.map((name: string) => name.slice(0, 3).toLowerCase())
|
|
258
262
|
.join('')
|
|
259
263
|
|
|
264
|
+
case ServerType.Sasjs:
|
|
265
|
+
return response?.username
|
|
266
|
+
|
|
260
267
|
default:
|
|
261
268
|
console.error('Server Type not found in extractUserName function')
|
|
262
269
|
return ''
|
|
@@ -306,8 +313,12 @@ export class AuthManager {
|
|
|
306
313
|
|
|
307
314
|
/**
|
|
308
315
|
* Logs out of the configured SAS server.
|
|
316
|
+
* @param accessToken - an optional access token is required for SASjs server type.
|
|
309
317
|
*/
|
|
310
|
-
public logOut() {
|
|
318
|
+
public logOut(accessToken?: string) {
|
|
319
|
+
if (this.serverType === ServerType.Sasjs) {
|
|
320
|
+
return this.requestClient.post(this.logoutUrl, undefined, accessToken)
|
|
321
|
+
}
|
|
311
322
|
this.requestClient.clearCsrfTokens()
|
|
312
323
|
return this.requestClient.get(this.logoutUrl, undefined).then(() => true)
|
|
313
324
|
}
|
|
@@ -15,7 +15,8 @@ import { SASViyaApiClient } from '../SASViyaApiClient'
|
|
|
15
15
|
import {
|
|
16
16
|
isRelativePath,
|
|
17
17
|
parseSasViyaDebugResponse,
|
|
18
|
-
appendExtraResponseAttributes
|
|
18
|
+
appendExtraResponseAttributes,
|
|
19
|
+
getValidJson
|
|
19
20
|
} from '../utils'
|
|
20
21
|
import { BaseJobExecutor } from './JobExecutor'
|
|
21
22
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
|
@@ -113,6 +114,7 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|
|
113
114
|
const stringifiedData = JSON.stringify(data)
|
|
114
115
|
if (
|
|
115
116
|
config.serverType === ServerType.Sas9 ||
|
|
117
|
+
config.serverType === ServerType.Sasjs ||
|
|
116
118
|
stringifiedData.length > 500000 ||
|
|
117
119
|
stringifiedData.includes(';')
|
|
118
120
|
) {
|
|
@@ -142,12 +144,25 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
const requestPromise = new Promise((resolve, reject) => {
|
|
145
|
-
|
|
147
|
+
// Access token is required for server type `SASjs`
|
|
148
|
+
this.requestClient!.post(apiUrl, formData, authConfig?.access_token)
|
|
146
149
|
.then(async (res: any) => {
|
|
147
|
-
|
|
150
|
+
const resObj =
|
|
151
|
+
this.serverType === ServerType.Sasjs
|
|
152
|
+
? {
|
|
153
|
+
result: res.result._webout,
|
|
154
|
+
log: res.result.log
|
|
155
|
+
}
|
|
156
|
+
: res
|
|
157
|
+
this.requestClient!.appendRequest(resObj, sasJob, config.debug)
|
|
148
158
|
|
|
149
159
|
let jsonResponse = res.result
|
|
150
160
|
|
|
161
|
+
if (this.serverType === ServerType.Sasjs) {
|
|
162
|
+
const webout = parseWeboutResponse(res.result._webout, apiUrl)
|
|
163
|
+
jsonResponse = getValidJson(webout)
|
|
164
|
+
}
|
|
165
|
+
|
|
151
166
|
if (config.debug) {
|
|
152
167
|
switch (this.serverType) {
|
|
153
168
|
case ServerType.SasViya:
|
package/src/types/SASjsConfig.ts
CHANGED
|
@@ -12,6 +12,11 @@ export class SASjsConfig {
|
|
|
12
12
|
* streamed.
|
|
13
13
|
*/
|
|
14
14
|
serverUrl: string = ''
|
|
15
|
+
/**
|
|
16
|
+
* The location of the STP Process Web Application. By default the adapter
|
|
17
|
+
* will use '/SASjsApi/stp/execute' on SAS JS.
|
|
18
|
+
*/
|
|
19
|
+
pathSASJS?: string = ''
|
|
15
20
|
/**
|
|
16
21
|
* The location of the Stored Process Web Application. By default the adapter
|
|
17
22
|
* will use '/SASStoredProcess/do' on SAS 9.
|
|
@@ -4,7 +4,7 @@ import { JsonParseArrayError, InvalidJsonError } from '../types/errors'
|
|
|
4
4
|
* if string passed then parse the string to json else if throw error for all other types unless it is not a valid json object.
|
|
5
5
|
* @param str - string to check.
|
|
6
6
|
*/
|
|
7
|
-
export const getValidJson = (str: string | object) => {
|
|
7
|
+
export const getValidJson = (str: string | object): object => {
|
|
8
8
|
try {
|
|
9
9
|
if (str === null || str === undefined) throw new InvalidJsonError()
|
|
10
10
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WeboutResponseError } from '../types/errors'
|
|
2
2
|
|
|
3
|
-
export const parseWeboutResponse = (response: string, url?: string) => {
|
|
3
|
+
export const parseWeboutResponse = (response: string, url?: string): string => {
|
|
4
4
|
let sasResponse = ''
|
|
5
5
|
|
|
6
6
|
if (response.includes('>>weboutBEGIN<<')) {
|
package/types/SASjsConfig.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ export declare class SASjsConfig {
|
|
|
12
12
|
* streamed.
|
|
13
13
|
*/
|
|
14
14
|
serverUrl: string;
|
|
15
|
+
/**
|
|
16
|
+
* The location of the STP Process Web Application. By default the adapter
|
|
17
|
+
* will use '/SASjsApi/stp/execute' on SAS JS.
|
|
18
|
+
*/
|
|
19
|
+
pathSASJS?: string;
|
|
15
20
|
/**
|
|
16
21
|
* The location of the Stored Process Web Application. By default the adapter
|
|
17
22
|
* will use '/SASStoredProcess/do' on SAS 9.
|
package/utils/getValidJson.d.ts
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* if string passed then parse the string to json else if throw error for all other types unless it is not a valid json object.
|
|
3
3
|
* @param str - string to check.
|
|
4
4
|
*/
|
|
5
|
-
export declare const getValidJson: (str: string | object) =>
|
|
5
|
+
export declare const getValidJson: (str: string | object) => object;
|
|
@@ -9,4 +9,4 @@ import { RequestClient } from '../request/RequestClient';
|
|
|
9
9
|
* @param serverUrl
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
export declare const parseSasViyaDebugResponse: (response: string, requestClient: RequestClient, serverUrl: string) => Promise<
|
|
12
|
+
export declare const parseSasViyaDebugResponse: (response: string, requestClient: RequestClient, serverUrl: string) => Promise<object>;
|