@sasjs/adapter 3.8.4 → 3.9.1
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 -1
- package/SASjsApiClient.d.ts +6 -0
- package/index.js +2 -2
- package/node/SASjs.d.ts +7 -1
- package/node/SASjsApiClient.d.ts +6 -0
- package/node/index.js +2 -2
- package/node/types/errors/CertificateError.d.ts +3 -0
- package/node/types/errors/index.d.ts +5 -4
- package/package.json +1 -1
- package/src/SASViyaApiClient.ts +9 -3
- package/src/SASjs.ts +12 -1
- package/src/SASjsApiClient.ts +33 -0
- package/src/auth/getAccessTokenForViya.ts +2 -0
- package/src/request/RequestClient.ts +6 -1
- package/src/types/errors/CertificateError.ts +12 -0
- package/src/types/errors/index.ts +5 -4
- package/types/errors/CertificateError.d.ts +3 -0
- package/types/errors/index.d.ts +5 -4
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export * from './AuthorizeError';
|
|
2
|
+
export * from './CertificateError';
|
|
2
3
|
export * from './ComputeJobExecutionError';
|
|
4
|
+
export * from './ErrorResponse';
|
|
3
5
|
export * from './InternalServerError';
|
|
6
|
+
export * from './InvalidJsonError';
|
|
4
7
|
export * from './JobExecutionError';
|
|
5
8
|
export * from './JobStatePollError';
|
|
9
|
+
export * from './JsonParseArrayError';
|
|
6
10
|
export * from './LoginRequiredError';
|
|
7
|
-
export * from './NotFoundError';
|
|
8
|
-
export * from './ErrorResponse';
|
|
9
11
|
export * from './NoSessionStateError';
|
|
12
|
+
export * from './NotFoundError';
|
|
10
13
|
export * from './RootFolderNotFoundError';
|
|
11
|
-
export * from './JsonParseArrayError';
|
|
12
14
|
export * from './WeboutResponseError';
|
|
13
|
-
export * from './InvalidJsonError';
|
package/package.json
CHANGED
package/src/SASViyaApiClient.ts
CHANGED
|
@@ -11,7 +11,11 @@ import {
|
|
|
11
11
|
JobDefinition,
|
|
12
12
|
PollOptions
|
|
13
13
|
} from './types'
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
CertificateError,
|
|
16
|
+
JobExecutionError,
|
|
17
|
+
RootFolderNotFoundError
|
|
18
|
+
} from './types/errors'
|
|
15
19
|
import { SessionManager } from './SessionManager'
|
|
16
20
|
import { ContextManager } from './ContextManager'
|
|
17
21
|
import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
|
@@ -878,7 +882,8 @@ export class SASViyaApiClient {
|
|
|
878
882
|
|
|
879
883
|
const { result: folder } = await this.requestClient
|
|
880
884
|
.get<Folder>(`${this.serverUrl}${url}`, accessToken)
|
|
881
|
-
.catch(() => {
|
|
885
|
+
.catch((err) => {
|
|
886
|
+
if (err instanceof CertificateError) throw err
|
|
882
887
|
return { result: null }
|
|
883
888
|
})
|
|
884
889
|
|
|
@@ -899,7 +904,8 @@ export class SASViyaApiClient {
|
|
|
899
904
|
|
|
900
905
|
const { result: folder } = await this.requestClient
|
|
901
906
|
.get<Folder>(`${this.serverUrl}${url}`, accessToken)
|
|
902
|
-
.catch(() => {
|
|
907
|
+
.catch((err) => {
|
|
908
|
+
if (err instanceof CertificateError) throw err
|
|
903
909
|
return { result: null }
|
|
904
910
|
})
|
|
905
911
|
|
package/src/SASjs.ts
CHANGED
|
@@ -77,7 +77,7 @@ export default class SASjs {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* Executes code
|
|
80
|
+
* Executes SAS code on a SAS 9 server. Requires a runner to be present in
|
|
81
81
|
* the users home directory in metadata.
|
|
82
82
|
* @param linesOfCode - lines of sas code from the file to run.
|
|
83
83
|
* @param username - a string representing the username.
|
|
@@ -97,6 +97,17 @@ export default class SASjs {
|
|
|
97
97
|
)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Executes SAS code on a SASJS server
|
|
102
|
+
* @param code - a string of code from the file to run.
|
|
103
|
+
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
|
|
104
|
+
*/
|
|
105
|
+
public async executeScriptSASjs(code: string, authConfig?: AuthConfig) {
|
|
106
|
+
this.isMethodSupported('executeScriptSASJS', [ServerType.Sasjs])
|
|
107
|
+
|
|
108
|
+
return await this.sasJSApiClient?.executeScript(code, authConfig)
|
|
109
|
+
}
|
|
110
|
+
|
|
100
111
|
/**
|
|
101
112
|
* Executes sas code in a SAS Viya compute session.
|
|
102
113
|
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
|
package/src/SASjsApiClient.ts
CHANGED
|
@@ -60,6 +60,39 @@ export class SASjsApiClient {
|
|
|
60
60
|
return Promise.resolve(result)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Executes code on a SASJS server.
|
|
65
|
+
* @param code - a string of code to execute.
|
|
66
|
+
* @param authConfig - an object for authentication.
|
|
67
|
+
*/
|
|
68
|
+
public async executeScript(code: string, authConfig?: AuthConfig) {
|
|
69
|
+
let access_token = (authConfig || {}).access_token
|
|
70
|
+
if (authConfig) {
|
|
71
|
+
;({ access_token } = await getTokens(
|
|
72
|
+
this.requestClient,
|
|
73
|
+
authConfig,
|
|
74
|
+
ServerType.Sasjs
|
|
75
|
+
))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let parsedSasjsServerLog = ''
|
|
79
|
+
|
|
80
|
+
await this.requestClient
|
|
81
|
+
.post('SASjsApi/code/execute', { code }, access_token)
|
|
82
|
+
.then((res: any) => {
|
|
83
|
+
if (res.result?.log) {
|
|
84
|
+
parsedSasjsServerLog = res.result.log
|
|
85
|
+
.map((logLine: any) => logLine.line)
|
|
86
|
+
.join('\n')
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
.catch((err) => {
|
|
90
|
+
parsedSasjsServerLog = err
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
return parsedSasjsServerLog
|
|
94
|
+
}
|
|
95
|
+
|
|
63
96
|
/**
|
|
64
97
|
* Exchanges the auth code for an access token for the given client.
|
|
65
98
|
* @param clientId - the client ID to authenticate with.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SasAuthResponse } from '@sasjs/utils/types'
|
|
2
2
|
import { prefixMessage } from '@sasjs/utils/error'
|
|
3
3
|
import { RequestClient } from '../request/RequestClient'
|
|
4
|
+
import { CertificateError } from '../types/errors'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Exchanges the auth code for an access token for the given client.
|
|
@@ -36,6 +37,7 @@ export async function getAccessTokenForViya(
|
|
|
36
37
|
.post(url, data, undefined, 'application/x-www-form-urlencoded', headers)
|
|
37
38
|
.then((res) => res.result as SasAuthResponse)
|
|
38
39
|
.catch((err) => {
|
|
40
|
+
if (err instanceof CertificateError) throw err
|
|
39
41
|
throw prefixMessage(err, 'Error while getting access token. ')
|
|
40
42
|
})
|
|
41
43
|
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
LoginRequiredError,
|
|
8
8
|
NotFoundError,
|
|
9
9
|
InternalServerError,
|
|
10
|
-
JobExecutionError
|
|
10
|
+
JobExecutionError,
|
|
11
|
+
CertificateError
|
|
11
12
|
} from '../types/errors'
|
|
12
13
|
import { SASjsRequest } from '../types'
|
|
13
14
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
|
@@ -517,6 +518,10 @@ export class RequestClient implements HttpClient {
|
|
|
517
518
|
else return
|
|
518
519
|
}
|
|
519
520
|
|
|
521
|
+
if (e.isAxiosError && e.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {
|
|
522
|
+
throw new CertificateError(e.message)
|
|
523
|
+
}
|
|
524
|
+
|
|
520
525
|
if (e.message) throw e
|
|
521
526
|
else throw prefixMessage(e, 'Error while handling error. ')
|
|
522
527
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const instructionsToFix =
|
|
2
|
+
'https://github.com/sasjs/cli/issues/1181#issuecomment-1090638584'
|
|
3
|
+
|
|
4
|
+
export class CertificateError extends Error {
|
|
5
|
+
constructor(message: string) {
|
|
6
|
+
super(
|
|
7
|
+
`${message}\nPlease visit the link below for further information on this issue:\n- ${instructionsToFix}\n`
|
|
8
|
+
)
|
|
9
|
+
this.name = 'CertificateError'
|
|
10
|
+
Object.setPrototypeOf(this, CertificateError.prototype)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export * from './AuthorizeError'
|
|
2
|
+
export * from './CertificateError'
|
|
2
3
|
export * from './ComputeJobExecutionError'
|
|
4
|
+
export * from './ErrorResponse'
|
|
3
5
|
export * from './InternalServerError'
|
|
6
|
+
export * from './InvalidJsonError'
|
|
4
7
|
export * from './JobExecutionError'
|
|
5
8
|
export * from './JobStatePollError'
|
|
9
|
+
export * from './JsonParseArrayError'
|
|
6
10
|
export * from './LoginRequiredError'
|
|
7
|
-
export * from './NotFoundError'
|
|
8
|
-
export * from './ErrorResponse'
|
|
9
11
|
export * from './NoSessionStateError'
|
|
12
|
+
export * from './NotFoundError'
|
|
10
13
|
export * from './RootFolderNotFoundError'
|
|
11
|
-
export * from './JsonParseArrayError'
|
|
12
14
|
export * from './WeboutResponseError'
|
|
13
|
-
export * from './InvalidJsonError'
|
package/types/errors/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export * from './AuthorizeError';
|
|
2
|
+
export * from './CertificateError';
|
|
2
3
|
export * from './ComputeJobExecutionError';
|
|
4
|
+
export * from './ErrorResponse';
|
|
3
5
|
export * from './InternalServerError';
|
|
6
|
+
export * from './InvalidJsonError';
|
|
4
7
|
export * from './JobExecutionError';
|
|
5
8
|
export * from './JobStatePollError';
|
|
9
|
+
export * from './JsonParseArrayError';
|
|
6
10
|
export * from './LoginRequiredError';
|
|
7
|
-
export * from './NotFoundError';
|
|
8
|
-
export * from './ErrorResponse';
|
|
9
11
|
export * from './NoSessionStateError';
|
|
12
|
+
export * from './NotFoundError';
|
|
10
13
|
export * from './RootFolderNotFoundError';
|
|
11
|
-
export * from './JsonParseArrayError';
|
|
12
14
|
export * from './WeboutResponseError';
|
|
13
|
-
export * from './InvalidJsonError';
|