mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-06 12:10:04 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9af45799b9 | ||
|
|
fdbb87ed7b | ||
|
|
5e7ffc1f58 | ||
|
|
3369b28933 | ||
|
|
129c582785 | ||
|
|
23bdeaafaf |
File diff suppressed because one or more lines are too long
231
docs/classes/reflection-713.reflection-180.fileuploader.html
Normal file
231
docs/classes/reflection-713.reflection-180.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
312
docs/classes/reflection-713.reflection-180.sas9apiclient.html
Normal file
312
docs/classes/reflection-713.reflection-180.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1333
docs/classes/reflection-713.reflection-180.sasjs.html
Normal file
1333
docs/classes/reflection-713.reflection-180.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1265
docs/classes/reflection-713.reflection-180.sasviyaapiclient.html
Normal file
1265
docs/classes/reflection-713.reflection-180.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
271
docs/classes/reflection-713.reflection-180.sessionmanager.html
Normal file
271
docs/classes/reflection-713.reflection-180.sessionmanager.html
Normal file
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
106
docs/modules/reflection-713.html
Normal file
106
docs/modules/reflection-713.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-713.reflection-180.html
Normal file
128
docs/modules/reflection-713.reflection-180.html
Normal file
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
@@ -88,14 +88,18 @@ export class SASViyaApiClient {
|
|||||||
const headers: any = {
|
const headers: any = {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
headers.Authorization = `Bearer ${accessToken}`
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result: contexts } = await this.request<{ items: Context[] }>(
|
const { result: contexts } = await this.request<{ items: Context[] }>(
|
||||||
`${this.serverUrl}/compute/contexts`,
|
`${this.serverUrl}/compute/contexts?limit=10000`,
|
||||||
{ headers }
|
{ headers }
|
||||||
)
|
)
|
||||||
|
|
||||||
const contextsList = contexts && contexts.items ? contexts.items : []
|
const contextsList = contexts && contexts.items ? contexts.items : []
|
||||||
|
|
||||||
return contextsList.map((context: any) => ({
|
return contextsList.map((context: any) => ({
|
||||||
createdBy: context.createdBy,
|
createdBy: context.createdBy,
|
||||||
id: context.id,
|
id: context.id,
|
||||||
@@ -113,36 +117,48 @@ export class SASViyaApiClient {
|
|||||||
const headers: any = {
|
const headers: any = {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
headers.Authorization = `Bearer ${accessToken}`
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result: contexts } = await this.request<{ items: Context[] }>(
|
const { result: contexts } = await this.request<{ items: Context[] }>(
|
||||||
`${this.serverUrl}/compute/contexts`,
|
`${this.serverUrl}/compute/contexts?limit=10000`,
|
||||||
{ headers }
|
{ headers }
|
||||||
)
|
).catch((err) => {
|
||||||
const contextsList = contexts && contexts.items ? contexts.items : []
|
throw new Error(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
const contextsList = contexts.items || []
|
||||||
const executableContexts: any[] = []
|
const executableContexts: any[] = []
|
||||||
|
|
||||||
const promises = contextsList.map((context: any) => {
|
const promises = contextsList.map((context: any) => {
|
||||||
const linesOfCode = ['%put &=sysuserid;']
|
const linesOfCode = ['%put &=sysuserid;']
|
||||||
|
|
||||||
return this.executeScript(
|
return this.executeScript(
|
||||||
`test-${context.name}`,
|
`test-${context.name}`,
|
||||||
linesOfCode,
|
linesOfCode,
|
||||||
context.name,
|
context.name,
|
||||||
accessToken
|
accessToken,
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
true
|
||||||
).catch(() => null)
|
).catch(() => null)
|
||||||
})
|
})
|
||||||
|
|
||||||
const results = await Promise.all(promises)
|
const results = await Promise.all(promises)
|
||||||
|
|
||||||
results.forEach((result: any, index: number) => {
|
results.forEach((result: any, index: number) => {
|
||||||
if (result && result.jobStatus === 'completed') {
|
if (result) {
|
||||||
let sysUserId = ''
|
let sysUserId = ''
|
||||||
if (result && result.log && result.log.items) {
|
|
||||||
const sysUserIdLog = result.log.items.find((i: any) =>
|
if (result.log) {
|
||||||
i.line.startsWith('SYSUSERID=')
|
const sysUserIdLog = result.log
|
||||||
)
|
.split('\n')
|
||||||
|
.find((line: string) => line.startsWith('SYSUSERID='))
|
||||||
|
|
||||||
if (sysUserIdLog) {
|
if (sysUserIdLog) {
|
||||||
sysUserId = sysUserIdLog.line.replace('SYSUSERID=', '')
|
sysUserId = sysUserIdLog.replace('SYSUSERID=', '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,6 +396,9 @@ export class SASViyaApiClient {
|
|||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
* @param sessionId - optional session ID to reuse.
|
* @param sessionId - optional session ID to reuse.
|
||||||
* @param silent - optional flag to turn of logging.
|
* @param silent - optional flag to turn of logging.
|
||||||
|
* @param data - execution data.
|
||||||
|
* @param debug - flag taht indicates debug mode.
|
||||||
|
* @param expectWebout - flag that indicates that web output is expected
|
||||||
*/
|
*/
|
||||||
public async executeScript(
|
public async executeScript(
|
||||||
jobName: string,
|
jobName: string,
|
||||||
@@ -388,7 +407,8 @@ export class SASViyaApiClient {
|
|||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
silent = false,
|
silent = false,
|
||||||
data = null,
|
data = null,
|
||||||
debug = false
|
debug = false,
|
||||||
|
expectWebout = false
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
silent = !debug
|
silent = !debug
|
||||||
try {
|
try {
|
||||||
@@ -433,7 +453,9 @@ export class SASViyaApiClient {
|
|||||||
if (data) {
|
if (data) {
|
||||||
if (JSON.stringify(data).includes(';')) {
|
if (JSON.stringify(data).includes(';')) {
|
||||||
files = await this.uploadTables(data, accessToken)
|
files = await this.uploadTables(data, accessToken)
|
||||||
|
|
||||||
jobVariables['_webin_file_count'] = files.length
|
jobVariables['_webin_file_count'] = files.length
|
||||||
|
|
||||||
files.forEach((fileInfo, index) => {
|
files.forEach((fileInfo, index) => {
|
||||||
jobVariables[
|
jobVariables[
|
||||||
`_webin_fileuri${index + 1}`
|
`_webin_fileuri${index + 1}`
|
||||||
@@ -503,7 +525,12 @@ export class SASViyaApiClient {
|
|||||||
if (jobStatus === 'failed' || jobStatus === 'error') {
|
if (jobStatus === 'failed' || jobStatus === 'error') {
|
||||||
return Promise.reject({ error: currentJob.error, log })
|
return Promise.reject({ error: currentJob.error, log })
|
||||||
}
|
}
|
||||||
const resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`
|
|
||||||
|
let resultLink
|
||||||
|
|
||||||
|
if (expectWebout) {
|
||||||
|
resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`
|
||||||
|
}
|
||||||
|
|
||||||
if (resultLink) {
|
if (resultLink) {
|
||||||
jobResult = await this.request<any>(
|
jobResult = await this.request<any>(
|
||||||
@@ -891,22 +918,26 @@ export class SASViyaApiClient {
|
|||||||
const jobName = sasJob.split('/')[1]
|
const jobName = sasJob.split('/')[1]
|
||||||
const jobFolder = this.rootFolderMap.get(folderName)
|
const jobFolder = this.rootFolderMap.get(folderName)
|
||||||
const jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
const jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||||
|
|
||||||
if (!jobToExecute) {
|
if (!jobToExecute) {
|
||||||
throw new Error('Job was not found.')
|
throw new Error('Job was not found.')
|
||||||
}
|
}
|
||||||
|
|
||||||
let code = jobToExecute?.code
|
let code = jobToExecute?.code
|
||||||
|
|
||||||
if (!code) {
|
if (!code) {
|
||||||
const jobDefinitionLink = jobToExecute?.links.find(
|
const jobDefinitionLink = jobToExecute?.links.find(
|
||||||
(l) => l.rel === 'getResource'
|
(l) => l.rel === 'getResource'
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!jobDefinitionLink) {
|
if (!jobDefinitionLink) {
|
||||||
console.error('Job definition URI was not found.')
|
console.error('Job definition URI was not found.')
|
||||||
throw new Error('Job definition URI was not found.')
|
throw new Error('Job definition URI was not found.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result: jobDefinition } = await this.request<JobDefinition>(
|
const { result: jobDefinition } = await this.request<JobDefinition>(
|
||||||
`${this.serverUrl}${jobDefinitionLink.href}`,
|
`${this.serverUrl}${jobDefinitionLink.href}`,
|
||||||
headers
|
{ headers }
|
||||||
)
|
)
|
||||||
|
|
||||||
code = jobDefinition.code
|
code = jobDefinition.code
|
||||||
@@ -914,6 +945,7 @@ export class SASViyaApiClient {
|
|||||||
// Add code to existing job definition
|
// Add code to existing job definition
|
||||||
jobToExecute.code = code
|
jobToExecute.code = code
|
||||||
}
|
}
|
||||||
|
|
||||||
const linesToExecute = code.replace(/\r\n/g, '\n').split('\n')
|
const linesToExecute = code.replace(/\r\n/g, '\n').split('\n')
|
||||||
return await this.executeScript(
|
return await this.executeScript(
|
||||||
sasJob,
|
sasJob,
|
||||||
@@ -922,7 +954,8 @@ export class SASViyaApiClient {
|
|||||||
accessToken,
|
accessToken,
|
||||||
true,
|
true,
|
||||||
data,
|
data,
|
||||||
debug
|
debug,
|
||||||
|
true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -965,6 +998,7 @@ export class SASViyaApiClient {
|
|||||||
const jobName = path.basename(sasJob)
|
const jobName = path.basename(sasJob)
|
||||||
const jobFolder = sasJob.replace(`/${jobName}`, '')
|
const jobFolder = sasJob.replace(`/${jobName}`, '')
|
||||||
const allJobsInFolder = this.rootFolderMap.get(jobFolder.replace('/', ''))
|
const allJobsInFolder = this.rootFolderMap.get(jobFolder.replace('/', ''))
|
||||||
|
|
||||||
if (allJobsInFolder) {
|
if (allJobsInFolder) {
|
||||||
const jobSpec = allJobsInFolder.find((j: Job) => j.name === jobName)
|
const jobSpec = allJobsInFolder.find((j: Job) => j.name === jobName)
|
||||||
const jobDefinitionLink = jobSpec?.links.find(
|
const jobDefinitionLink = jobSpec?.links.find(
|
||||||
@@ -974,10 +1008,13 @@ export class SASViyaApiClient {
|
|||||||
method: 'GET'
|
method: 'GET'
|
||||||
}
|
}
|
||||||
const headers: any = { 'Content-Type': 'application/json' }
|
const headers: any = { 'Content-Type': 'application/json' }
|
||||||
|
|
||||||
if (!!accessToken) {
|
if (!!accessToken) {
|
||||||
headers.Authorization = `Bearer ${accessToken}`
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
requestInfo.headers = headers
|
requestInfo.headers = headers
|
||||||
|
|
||||||
const { result: jobDefinition } = await this.request<Job>(
|
const { result: jobDefinition } = await this.request<Job>(
|
||||||
`${this.serverUrl}${jobDefinitionLink}`,
|
`${this.serverUrl}${jobDefinitionLink}`,
|
||||||
requestInfo
|
requestInfo
|
||||||
|
|||||||
@@ -728,7 +728,7 @@ export default class SASjs {
|
|||||||
async (resolve, reject) => {
|
async (resolve, reject) => {
|
||||||
const session = await this.checkSession()
|
const session = await this.checkSession()
|
||||||
|
|
||||||
if (!session.isLoggedIn) {
|
if (!session.isLoggedIn && !accessToken) {
|
||||||
if (loginRequiredCallback) loginRequiredCallback(true)
|
if (loginRequiredCallback) loginRequiredCallback(true)
|
||||||
sasjsWaitingRequest.requestPromise.resolve = resolve
|
sasjsWaitingRequest.requestPromise.resolve = resolve
|
||||||
sasjsWaitingRequest.requestPromise.reject = reject
|
sasjsWaitingRequest.requestPromise.reject = reject
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export async function makeRequest<T>(
|
|||||||
? (res: Response) => res.json()
|
? (res: Response) => res.json()
|
||||||
: (res: Response) => res.text()
|
: (res: Response) => res.text()
|
||||||
let etag = null
|
let etag = null
|
||||||
|
|
||||||
const result = await fetch(url, request).then(async (response) => {
|
const result = await fetch(url, request).then(async (response) => {
|
||||||
if (response.redirected && response.url.includes('SASLogon/login')) {
|
if (response.redirected && response.url.includes('SASLogon/login')) {
|
||||||
return Promise.reject({ status: 401 })
|
return Promise.reject({ status: 401 })
|
||||||
|
|||||||
Reference in New Issue
Block a user