@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.
@@ -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) => any;
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<any>;
12
+ export declare const parseSasViyaDebugResponse: (response: string, requestClient: RequestClient, serverUrl: string) => Promise<object>;
package/package.json CHANGED
@@ -80,5 +80,5 @@
80
80
  "https": "^1.0.0",
81
81
  "tough-cookie": "^4.0.0"
82
82
  },
83
- "version": "3.0.2"
83
+ "version": "3.1.0"
84
84
  }
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.pathSAS9
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,
@@ -21,7 +21,9 @@ export class AuthManager {
21
21
  this.logoutUrl =
22
22
  this.serverType === ServerType.Sas9
23
23
  ? '/SASLogon/logout?'
24
- : '/SASLogon/logout.do?'
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
- : `${this.serverUrl}/SASStoredProcess`
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, undefined, 'text/plain')
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
- this.requestClient!.post(apiUrl, formData, undefined)
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
- this.requestClient!.appendRequest(res, sasJob, config.debug)
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:
@@ -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<<')) {
@@ -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) => any;
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<any>;
12
+ export declare const parseSasViyaDebugResponse: (response: string, requestClient: RequestClient, serverUrl: string) => Promise<object>;