mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 01:14:36 +00:00
Merge branch 'master' into releaseScript
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
3772
package-lock.json
generated
3772
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@@ -37,30 +37,31 @@
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/isomorphic-fetch": "0.0.35",
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/jest": "^26.0.20",
|
||||
"cp": "^0.2.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"jest": "^25.5.4",
|
||||
"path": "^0.12.7",
|
||||
"rimraf": "^3.0.2",
|
||||
"semantic-release": "^17.3.0",
|
||||
"semantic-release": "^17.3.1",
|
||||
"terser-webpack-plugin": "^4.2.3",
|
||||
"ts-jest": "^25.5.1",
|
||||
"ts-loader": "^8.0.11",
|
||||
"ts-loader": "^8.0.14",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0",
|
||||
"typedoc": "^0.17.8",
|
||||
"typedoc": "^0.19.2",
|
||||
"typedoc-neo-theme": "^1.0.10",
|
||||
"typedoc-plugin-external-module-name": "^4.0.3",
|
||||
"typedoc-plugin-external-module-name": "^4.0.6",
|
||||
"typescript": "^3.9.7",
|
||||
"webpack": "^4.44.2",
|
||||
"webpack-cli": "^4.2.0"
|
||||
"webpack": "^5.13.0",
|
||||
"webpack-cli": "^4.3.1"
|
||||
},
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@sasjs/utils": "^1.5.0",
|
||||
"@sasjs/utils": "^2.0.2",
|
||||
"es6-promise": "^4.2.8",
|
||||
"form-data": "^3.0.0",
|
||||
"https": "^1.0.0",
|
||||
"isomorphic-fetch": "^2.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,11 +701,13 @@ export class SASViyaApiClient {
|
||||
* @param clientId - the client ID to authenticate with.
|
||||
* @param clientSecret - the client secret to authenticate with.
|
||||
* @param authCode - the auth code received from the server.
|
||||
* @param insecure - this boolean tells adapter to ignore SSL errors. [Not Recommended]
|
||||
*/
|
||||
public async getAccessToken(
|
||||
clientId: string,
|
||||
clientSecret: string,
|
||||
authCode: string
|
||||
authCode: string,
|
||||
insecure: boolean = false
|
||||
) {
|
||||
const url = this.serverUrl + '/SASLogon/oauth/token'
|
||||
let token
|
||||
@@ -729,12 +731,23 @@ export class SASViyaApiClient {
|
||||
formData.append('code', authCode)
|
||||
}
|
||||
|
||||
let moreOptions = {}
|
||||
if (insecure) {
|
||||
const https = require('https')
|
||||
moreOptions = {
|
||||
agent: new https.Agent({
|
||||
rejectUnauthorized: false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const authResponse = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers,
|
||||
body: formData as any,
|
||||
referrerPolicy: 'same-origin'
|
||||
referrerPolicy: 'same-origin',
|
||||
...moreOptions
|
||||
}).then((res) => res.json())
|
||||
|
||||
return authResponse
|
||||
@@ -833,23 +846,20 @@ export class SASViyaApiClient {
|
||||
)
|
||||
}
|
||||
|
||||
if (isRelativePath(sasJob)) {
|
||||
const folderName = sasJob.split('/')[0]
|
||||
await this.populateFolderMap(
|
||||
`${this.rootFolderName}/${folderName}`,
|
||||
accessToken
|
||||
)
|
||||
const folderPathParts = sasJob.split('/')
|
||||
const jobName = folderPathParts.pop()
|
||||
const folderPath = folderPathParts.join('/')
|
||||
const fullFolderPath = isRelativePath(sasJob)
|
||||
? `${this.rootFolderName}/${folderPath}`
|
||||
: folderPath
|
||||
|
||||
if (!this.folderMap.get(`${this.rootFolderName}/${folderName}`)) {
|
||||
throw new Error(
|
||||
`The folder '${folderName}' was not found at '${this.serverUrl}/${this.rootFolderName}'`
|
||||
)
|
||||
}
|
||||
} else {
|
||||
const folderPathParts = sasJob.split('/')
|
||||
folderPathParts.pop()
|
||||
const folderPath = folderPathParts.join('/')
|
||||
await this.populateFolderMap(folderPath, accessToken)
|
||||
await this.populateFolderMap(fullFolderPath, accessToken)
|
||||
|
||||
const jobFolder = this.folderMap.get(fullFolderPath)
|
||||
if (!jobFolder) {
|
||||
throw new Error(
|
||||
`The folder '${fullFolderPath}' was not found on '${this.serverUrl}'`
|
||||
)
|
||||
}
|
||||
|
||||
const headers: any = { 'Content-Type': 'application/json' }
|
||||
@@ -857,21 +867,7 @@ export class SASViyaApiClient {
|
||||
headers.Authorization = `Bearer ${accessToken}`
|
||||
}
|
||||
|
||||
let jobToExecute
|
||||
if (isRelativePath(sasJob)) {
|
||||
const folderName = sasJob.split('/')[0]
|
||||
const jobName = sasJob.split('/')[1]
|
||||
const jobFolder = this.folderMap.get(
|
||||
`${this.rootFolderName}/${folderName}`
|
||||
)
|
||||
jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||
} else {
|
||||
const folderPathParts = sasJob.split('/')
|
||||
const jobName = folderPathParts.pop()
|
||||
const folderPath = folderPathParts.join('/')
|
||||
const jobFolder = this.folderMap.get(folderPath)
|
||||
jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||
}
|
||||
const jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||
|
||||
if (!jobToExecute) {
|
||||
throw new Error(`Job was not found.`)
|
||||
@@ -937,52 +933,28 @@ export class SASViyaApiClient {
|
||||
)
|
||||
}
|
||||
|
||||
if (isRelativePath(sasJob)) {
|
||||
const folderName = sasJob.split('/')[0]
|
||||
await this.populateFolderMap(
|
||||
`${this.rootFolderName}/${folderName}`,
|
||||
accessToken
|
||||
)
|
||||
const folderPathParts = sasJob.split('/')
|
||||
const jobName = folderPathParts.pop()
|
||||
const folderPath = folderPathParts.join('/')
|
||||
const fullFolderPath = isRelativePath(sasJob)
|
||||
? `${this.rootFolderName}/${folderPath}`
|
||||
: folderPath
|
||||
await this.populateFolderMap(fullFolderPath, accessToken)
|
||||
|
||||
if (!this.folderMap.get(`${this.rootFolderName}/${folderName}`)) {
|
||||
throw new Error(
|
||||
`The folder '${folderName}' was not found at '${this.serverUrl}/${this.rootFolderName}'.`
|
||||
)
|
||||
}
|
||||
} else {
|
||||
const folderPathParts = sasJob.split('/')
|
||||
folderPathParts.pop()
|
||||
const folderPath = folderPathParts.join('/')
|
||||
await this.populateFolderMap(folderPath, accessToken)
|
||||
if (!this.folderMap.get(folderPath)) {
|
||||
throw new Error(
|
||||
`The folder '${folderPath}' was not found at '${this.serverUrl}'.`
|
||||
)
|
||||
}
|
||||
const jobFolder = this.folderMap.get(fullFolderPath)
|
||||
if (!jobFolder) {
|
||||
throw new Error(
|
||||
`The folder '${fullFolderPath}' was not found on '${this.serverUrl}'.`
|
||||
)
|
||||
}
|
||||
|
||||
const jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||
|
||||
let files: any[] = []
|
||||
if (data && Object.keys(data).length) {
|
||||
files = await this.uploadTables(data, accessToken)
|
||||
}
|
||||
|
||||
let jobToExecute: Job | undefined
|
||||
let jobName: string | undefined
|
||||
let jobPath: string | undefined
|
||||
if (isRelativePath(sasJob)) {
|
||||
const folderName = sasJob.split('/')[0]
|
||||
jobName = sasJob.split('/')[1]
|
||||
jobPath = `${this.rootFolderName}/${folderName}`
|
||||
const jobFolder = this.folderMap.get(jobPath)
|
||||
jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||
} else {
|
||||
const folderPathParts = sasJob.split('/')
|
||||
jobName = folderPathParts.pop()
|
||||
jobPath = folderPathParts.join('/')
|
||||
const jobFolder = this.folderMap.get(jobPath)
|
||||
jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||
}
|
||||
|
||||
if (!jobToExecute) {
|
||||
throw new Error(`Job was not found.`)
|
||||
}
|
||||
@@ -1007,7 +979,7 @@ export class SASViyaApiClient {
|
||||
|
||||
const jobArguments: { [key: string]: any } = {
|
||||
_contextName: contextName,
|
||||
_program: `${jobPath}/${jobName}`,
|
||||
_program: `${fullFolderPath}/${jobName}`,
|
||||
_webin_file_count: files.length,
|
||||
_OMITJSONLISTING: true,
|
||||
_OMITJSONLOG: true,
|
||||
@@ -1148,6 +1120,8 @@ export class SASViyaApiClient {
|
||||
}
|
||||
|
||||
return new Promise(async (resolve, _) => {
|
||||
let printedState = ''
|
||||
|
||||
const interval = setInterval(async () => {
|
||||
if (
|
||||
postedJobState === 'running' ||
|
||||
@@ -1155,9 +1129,6 @@ export class SASViyaApiClient {
|
||||
postedJobState === 'pending'
|
||||
) {
|
||||
if (stateLink) {
|
||||
if (this.debug) {
|
||||
console.log('Polling job status... \n')
|
||||
}
|
||||
const { result: jobState } = await this.request<string>(
|
||||
`${this.serverUrl}${stateLink.href}?_action=wait&wait=30`,
|
||||
{
|
||||
@@ -1167,10 +1138,16 @@ export class SASViyaApiClient {
|
||||
)
|
||||
|
||||
postedJobState = jobState.trim()
|
||||
if (this.debug) {
|
||||
console.log(`Current state: ${postedJobState}\n`)
|
||||
|
||||
if (this.debug && printedState !== postedJobState) {
|
||||
console.log('Polling job status...')
|
||||
console.log(`Current job state: ${postedJobState}`)
|
||||
|
||||
printedState = postedJobState
|
||||
}
|
||||
|
||||
pollCount++
|
||||
|
||||
if (pollCount >= MAX_POLL_COUNT) {
|
||||
resolve(postedJobState)
|
||||
}
|
||||
|
||||
18
src/SASjs.ts
18
src/SASjs.ts
@@ -386,17 +386,26 @@ export default class SASjs {
|
||||
return await this.sasViyaApiClient!.getAuthCode(clientId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchanges the auth code for an access token for the given client.
|
||||
* @param clientId - the client ID to authenticate with.
|
||||
* @param clientSecret - the client secret to authenticate with.
|
||||
* @param authCode - the auth code received from the server.
|
||||
* @param insecure - this boolean tells adapter to ignore SSL errors. [Not Recommended]
|
||||
*/
|
||||
public async getAccessToken(
|
||||
clientId: string,
|
||||
clientSecret: string,
|
||||
authCode: string
|
||||
authCode: string,
|
||||
insecure: boolean = false
|
||||
) {
|
||||
this.isMethodSupported('getAccessToken', ServerType.SASViya)
|
||||
|
||||
return await this.sasViyaApiClient!.getAccessToken(
|
||||
clientId,
|
||||
clientSecret,
|
||||
authCode
|
||||
authCode,
|
||||
insecure
|
||||
)
|
||||
}
|
||||
|
||||
@@ -747,10 +756,7 @@ export default class SASjs {
|
||||
)
|
||||
}
|
||||
|
||||
const members =
|
||||
serviceJson.members[0].name === 'services'
|
||||
? serviceJson.members[0].members
|
||||
: serviceJson.members
|
||||
const members = serviceJson.members
|
||||
|
||||
await this.createFoldersAndServices(
|
||||
appLoc,
|
||||
|
||||
@@ -23,6 +23,10 @@ export class SessionManager {
|
||||
private currentContext: Context | null = null
|
||||
private csrfToken: CsrfToken | null = null
|
||||
private _debug: boolean = false
|
||||
private printedSessionState = {
|
||||
printed: false,
|
||||
state: ''
|
||||
}
|
||||
|
||||
public get debug() {
|
||||
return this._debug
|
||||
@@ -175,8 +179,10 @@ export class SessionManager {
|
||||
sessionState === ''
|
||||
) {
|
||||
if (stateLink) {
|
||||
if (this.debug) {
|
||||
console.log('Polling session status... \n')
|
||||
if (this.debug && !this.printedSessionState.printed) {
|
||||
console.log('Polling session status...')
|
||||
|
||||
this.printedSessionState.printed = true
|
||||
}
|
||||
|
||||
const { result: state } = await this.requestSessionStatus<string>(
|
||||
@@ -191,8 +197,11 @@ export class SessionManager {
|
||||
|
||||
sessionState = state.trim()
|
||||
|
||||
if (this.debug) {
|
||||
console.log(`Current state is '${sessionState}'\n`)
|
||||
if (this.debug && this.printedSessionState.state !== sessionState) {
|
||||
console.log(`Current session state is '${sessionState}'`)
|
||||
|
||||
this.printedSessionState.state = sessionState
|
||||
this.printedSessionState.printed = false
|
||||
}
|
||||
|
||||
// There is an internal error present in SAS Viya 3.5
|
||||
|
||||
@@ -26,7 +26,8 @@ const browserConfig = {
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js']
|
||||
extensions: ['.ts', '.js'],
|
||||
fallback: { https: false }
|
||||
},
|
||||
output: {
|
||||
filename: 'index.js',
|
||||
|
||||
Reference in New Issue
Block a user