mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 12:30:06 +00:00
chore(*): remove unused dependencies and variables, fix imports
This commit is contained in:
46
package-lock.json
generated
46
package-lock.json
generated
@@ -16,6 +16,8 @@
|
|||||||
"url": "^0.11.0"
|
"url": "^0.11.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/axios": "^0.14.0",
|
||||||
|
"@types/form-data": "^2.5.0",
|
||||||
"@types/jest": "^26.0.23",
|
"@types/jest": "^26.0.23",
|
||||||
"@types/mime": "^2.0.3",
|
"@types/mime": "^2.0.3",
|
||||||
"@types/tough-cookie": "^4.0.0",
|
"@types/tough-cookie": "^4.0.0",
|
||||||
@@ -24,7 +26,6 @@
|
|||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"jest": "^27.0.6",
|
"jest": "^27.0.6",
|
||||||
"jest-extended": "^0.11.5",
|
"jest-extended": "^0.11.5",
|
||||||
"mime": "^2.5.2",
|
|
||||||
"node-polyfill-webpack-plugin": "^1.1.4",
|
"node-polyfill-webpack-plugin": "^1.1.4",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
@@ -1435,6 +1436,16 @@
|
|||||||
"node": ">= 6"
|
"node": ">= 6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/axios": {
|
||||||
|
"version": "0.14.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz",
|
||||||
|
"integrity": "sha1-7CMA++fX3d1+udOr+HmZlkyvzkY=",
|
||||||
|
"deprecated": "This is a stub types definition for axios (https://github.com/mzabriskie/axios). axios provides its own type definitions, so you don't need @types/axios installed!",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/babel__core": {
|
"node_modules/@types/babel__core": {
|
||||||
"version": "7.1.14",
|
"version": "7.1.14",
|
||||||
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.14.tgz",
|
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.14.tgz",
|
||||||
@@ -1502,6 +1513,16 @@
|
|||||||
"integrity": "sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==",
|
"integrity": "sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/form-data": {
|
||||||
|
"version": "2.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-2.5.0.tgz",
|
||||||
|
"integrity": "sha512-23/wYiuckYYtFpL+4RPWiWmRQH2BjFuqCUi2+N3amB1a1Drv+i/byTrGvlLwRVLFNAZbwpbQ7JvTK+VCAPMbcg==",
|
||||||
|
"deprecated": "This is a stub types definition. form-data provides its own type definitions, so you do not need this installed.",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"form-data": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/graceful-fs": {
|
"node_modules/@types/graceful-fs": {
|
||||||
"version": "4.1.5",
|
"version": "4.1.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.5.tgz",
|
||||||
@@ -11155,11 +11176,6 @@
|
|||||||
"safer-buffer": "^2.0.2",
|
"safer-buffer": "^2.0.2",
|
||||||
"tweetnacl": "~0.14.0"
|
"tweetnacl": "~0.14.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
|
||||||
"sshpk-conv": "bin/sshpk-conv",
|
|
||||||
"sshpk-sign": "bin/sshpk-sign",
|
|
||||||
"sshpk-verify": "bin/sshpk-verify"
|
|
||||||
},
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
@@ -15848,6 +15864,15 @@
|
|||||||
"integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==",
|
"integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/axios": {
|
||||||
|
"version": "0.14.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz",
|
||||||
|
"integrity": "sha1-7CMA++fX3d1+udOr+HmZlkyvzkY=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"axios": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/babel__core": {
|
"@types/babel__core": {
|
||||||
"version": "7.1.14",
|
"version": "7.1.14",
|
||||||
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.14.tgz",
|
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.14.tgz",
|
||||||
@@ -15915,6 +15940,15 @@
|
|||||||
"integrity": "sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==",
|
"integrity": "sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/form-data": {
|
||||||
|
"version": "2.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-2.5.0.tgz",
|
||||||
|
"integrity": "sha512-23/wYiuckYYtFpL+4RPWiWmRQH2BjFuqCUi2+N3amB1a1Drv+i/byTrGvlLwRVLFNAZbwpbQ7JvTK+VCAPMbcg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"form-data": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/graceful-fs": {
|
"@types/graceful-fs": {
|
||||||
"version": "4.1.5",
|
"version": "4.1.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.5.tgz",
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
},
|
},
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/axios": "^0.14.0",
|
||||||
|
"@types/form-data": "^2.5.0",
|
||||||
"@types/jest": "^26.0.23",
|
"@types/jest": "^26.0.23",
|
||||||
"@types/mime": "^2.0.3",
|
"@types/mime": "^2.0.3",
|
||||||
"@types/tough-cookie": "^4.0.0",
|
"@types/tough-cookie": "^4.0.0",
|
||||||
@@ -46,7 +48,6 @@
|
|||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"jest": "^27.0.6",
|
"jest": "^27.0.6",
|
||||||
"jest-extended": "^0.11.5",
|
"jest-extended": "^0.11.5",
|
||||||
"mime": "^2.5.2",
|
|
||||||
"node-polyfill-webpack-plugin": "^1.1.4",
|
"node-polyfill-webpack-plugin": "^1.1.4",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
|||||||
import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
import * as mime from 'mime'
|
|
||||||
import { pollJobState } from './api/viya/pollJobState'
|
import { pollJobState } from './api/viya/pollJobState'
|
||||||
import { getAccessToken, getTokens, refreshTokens } from './auth/tokens'
|
import { getAccessToken, getTokens, refreshTokens } from './auth/tokens'
|
||||||
import { uploadTables } from './api/viya/uploadTables'
|
import { uploadTables } from './api/viya/uploadTables'
|
||||||
@@ -334,9 +333,6 @@ export class SASViyaApiClient {
|
|||||||
const formData = new NodeFormData()
|
const formData = new NodeFormData()
|
||||||
formData.append('file', contentBuffer, fileName)
|
formData.append('file', contentBuffer, fileName)
|
||||||
|
|
||||||
const mimeType =
|
|
||||||
mime.getType(fileName.match(/\.[0-9a-z]+$/i)?.[0] || '') ?? 'text/plain'
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
await this.requestClient.post<File>(
|
await this.requestClient.post<File>(
|
||||||
`/files/files?parentFolderUri=${parentFolderUri}&typeDefName=file#rawUpload`,
|
`/files/files?parentFolderUri=${parentFolderUri}&typeDefName=file#rawUpload`,
|
||||||
@@ -939,14 +935,6 @@ export class SASViyaApiClient {
|
|||||||
? sourceFolder
|
? sourceFolder
|
||||||
: await this.getFolderUri(sourceFolder, accessToken)
|
: await this.getFolderUri(sourceFolder, accessToken)
|
||||||
|
|
||||||
const requestInfo = {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: 'Bearer ' + accessToken
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { result: members } = await this.requestClient.get<{ items: any[] }>(
|
const { result: members } = await this.requestClient.get<{ items: any[] }>(
|
||||||
`${this.serverUrl}${sourceFolderUri}/members?limit=${limit}`,
|
`${this.serverUrl}${sourceFolderUri}/members?limit=${limit}`,
|
||||||
accessToken
|
accessToken
|
||||||
|
|||||||
@@ -4,7 +4,12 @@ import { SASViyaApiClient } from './SASViyaApiClient'
|
|||||||
import { SAS9ApiClient } from './SAS9ApiClient'
|
import { SAS9ApiClient } from './SAS9ApiClient'
|
||||||
import { FileUploader } from './FileUploader'
|
import { FileUploader } from './FileUploader'
|
||||||
import { AuthManager } from './auth'
|
import { AuthManager } from './auth'
|
||||||
import { ServerType, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
import {
|
||||||
|
ServerType,
|
||||||
|
MacroVar,
|
||||||
|
AuthConfig,
|
||||||
|
ExtraResponseAttributes
|
||||||
|
} from '@sasjs/utils/types'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import {
|
import {
|
||||||
JobExecutor,
|
JobExecutor,
|
||||||
@@ -14,7 +19,6 @@ import {
|
|||||||
Sas9JobExecutor
|
Sas9JobExecutor
|
||||||
} from './job-execution'
|
} from './job-execution'
|
||||||
import { ErrorResponse } from './types/errors'
|
import { ErrorResponse } from './types/errors'
|
||||||
import { ExtraResponseAttributes } from '@sasjs/utils/types'
|
|
||||||
|
|
||||||
const defaultConfig: SASjsConfig = {
|
const defaultConfig: SASjsConfig = {
|
||||||
serverUrl: '',
|
serverUrl: '',
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
import {
|
import { timestampToYYYYMMDDHHMMSS } from '@sasjs/utils/time'
|
||||||
AuthConfig,
|
import { AuthConfig, MacroVar } from '@sasjs/utils/types'
|
||||||
MacroVar,
|
|
||||||
Logger,
|
|
||||||
LogLevel,
|
|
||||||
timestampToYYYYMMDDHHMMSS
|
|
||||||
} from '@sasjs/utils'
|
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
import {
|
import {
|
||||||
PollOptions,
|
PollOptions,
|
||||||
@@ -42,7 +37,7 @@ export async function executeScript(
|
|||||||
linesOfCode: string[],
|
linesOfCode: string[],
|
||||||
contextName: string,
|
contextName: string,
|
||||||
authConfig?: AuthConfig,
|
authConfig?: AuthConfig,
|
||||||
data = null,
|
data: any = null,
|
||||||
debug: boolean = false,
|
debug: boolean = false,
|
||||||
expectWebout = false,
|
expectWebout = false,
|
||||||
waitForResult = true,
|
waitForResult = true,
|
||||||
@@ -80,7 +75,7 @@ export async function executeScript(
|
|||||||
? jobPath.split(rootFolderName).join('').replace(/^\//, '')
|
? jobPath.split(rootFolderName).join('').replace(/^\//, '')
|
||||||
: jobPath
|
: jobPath
|
||||||
|
|
||||||
const logger = new Logger(debug ? LogLevel.Debug : LogLevel.Info)
|
const logger = process.logger || console
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`Triggered '${relativeJobPath}' with PID ${
|
`Triggered '${relativeJobPath}' with PID ${
|
||||||
@@ -235,18 +230,15 @@ export async function executeScript(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (jobStatus === 'failed' || jobStatus === 'error') {
|
if (jobStatus === 'failed' || jobStatus === 'error') {
|
||||||
return Promise.reject(new ComputeJobExecutionError(currentJob, log))
|
throw new ComputeJobExecutionError(currentJob, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
let resultLink
|
if (!expectWebout) {
|
||||||
|
|
||||||
if (expectWebout) {
|
|
||||||
resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`
|
|
||||||
} else {
|
|
||||||
return { job: currentJob, log }
|
return { job: currentJob, log }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultLink) {
|
const resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`
|
||||||
|
|
||||||
jobResult = await requestClient
|
jobResult = await requestClient
|
||||||
.get<any>(resultLink, access_token, 'text/plain')
|
.get<any>(resultLink, access_token, 'text/plain')
|
||||||
.catch(async (e) => {
|
.catch(async (e) => {
|
||||||
@@ -272,7 +264,6 @@ export async function executeScript(
|
|||||||
result: JSON.stringify(e)
|
result: JSON.stringify(e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
await sessionManager
|
await sessionManager
|
||||||
.clearSession(executionSessionId, access_token)
|
.clearSession(executionSessionId, access_token)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { AuthConfig, createFile, generateTimestamp } from '@sasjs/utils'
|
import { AuthConfig } from '@sasjs/utils'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
|
import { generateTimestamp } from '@sasjs/utils/time'
|
||||||
|
import { createFile } from '@sasjs/utils/file'
|
||||||
import { Job, PollOptions } from '../..'
|
import { Job, PollOptions } from '../..'
|
||||||
import { getTokens } from '../../auth/tokens'
|
import { getTokens } from '../../auth/tokens'
|
||||||
import { RequestClient } from '../../request/RequestClient'
|
import { RequestClient } from '../../request/RequestClient'
|
||||||
@@ -15,17 +17,23 @@ export async function pollJobState(
|
|||||||
) {
|
) {
|
||||||
const logger = process.logger || console
|
const logger = process.logger || console
|
||||||
|
|
||||||
let POLL_INTERVAL = 300
|
let pollInterval = 300
|
||||||
let MAX_POLL_COUNT = 1000
|
let maxPollCount = 1000
|
||||||
let MAX_ERROR_COUNT = 5
|
let maxErrorCount = 5
|
||||||
let access_token = (authConfig || {}).access_token
|
let access_token = (authConfig || {}).access_token
|
||||||
|
|
||||||
|
const logFileName = `${postedJob.name || 'job'}-${generateTimestamp()}.log`
|
||||||
|
const logFilePath = `${
|
||||||
|
pollOptions?.logFilePath || process.cwd()
|
||||||
|
}/${logFileName}`
|
||||||
|
|
||||||
if (authConfig) {
|
if (authConfig) {
|
||||||
;({ access_token } = await getTokens(requestClient, authConfig))
|
;({ access_token } = await getTokens(requestClient, authConfig))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pollOptions) {
|
if (pollOptions) {
|
||||||
POLL_INTERVAL = pollOptions.pollInterval || POLL_INTERVAL
|
pollInterval = pollOptions.pollInterval || pollInterval
|
||||||
MAX_POLL_COUNT = pollOptions.maxPollCount || MAX_POLL_COUNT
|
maxPollCount = pollOptions.maxPollCount || maxPollCount
|
||||||
}
|
}
|
||||||
|
|
||||||
let postedJobState = ''
|
let postedJobState = ''
|
||||||
@@ -89,10 +97,7 @@ export async function pollJobState(
|
|||||||
)
|
)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
errorCount++
|
errorCount++
|
||||||
if (
|
if (pollCount >= maxPollCount || errorCount >= maxErrorCount) {
|
||||||
pollCount >= MAX_POLL_COUNT ||
|
|
||||||
errorCount >= MAX_ERROR_COUNT
|
|
||||||
) {
|
|
||||||
throw prefixMessage(
|
throw prefixMessage(
|
||||||
err,
|
err,
|
||||||
'Error while getting job state after interval. '
|
'Error while getting job state after interval. '
|
||||||
@@ -123,11 +128,11 @@ export async function pollJobState(
|
|||||||
postedJob,
|
postedJob,
|
||||||
requestClient,
|
requestClient,
|
||||||
pollOptions?.streamLog || false,
|
pollOptions?.streamLog || false,
|
||||||
pollOptions?.logFilePath,
|
logFilePath,
|
||||||
access_token
|
access_token
|
||||||
)
|
)
|
||||||
|
|
||||||
if (pollCount >= MAX_POLL_COUNT) {
|
if (pollCount >= maxPollCount) {
|
||||||
resolve(postedJobState)
|
resolve(postedJobState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,7 +140,7 @@ export async function pollJobState(
|
|||||||
clearInterval(interval)
|
clearInterval(interval)
|
||||||
resolve(postedJobState)
|
resolve(postedJobState)
|
||||||
}
|
}
|
||||||
}, POLL_INTERVAL)
|
}, pollInterval)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +148,7 @@ async function saveLog(
|
|||||||
job: Job,
|
job: Job,
|
||||||
requestClient: RequestClient,
|
requestClient: RequestClient,
|
||||||
shouldSaveLog: boolean,
|
shouldSaveLog: boolean,
|
||||||
logFilePath?: string,
|
logFilePath: string,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
) {
|
) {
|
||||||
if (!shouldSaveLog) {
|
if (!shouldSaveLog) {
|
||||||
@@ -157,8 +162,6 @@ async function saveLog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const logger = process.logger || console
|
const logger = process.logger || console
|
||||||
const logFileName = `${job.name || 'job'}-${generateTimestamp()}.log`
|
|
||||||
const logPath = `${logFilePath || process.cwd()}/${logFileName}`
|
|
||||||
const jobLogUrl = job.links.find((l) => l.rel === 'log')
|
const jobLogUrl = job.links.find((l) => l.rel === 'log')
|
||||||
|
|
||||||
if (!jobLogUrl) {
|
if (!jobLogUrl) {
|
||||||
@@ -173,6 +176,6 @@ async function saveLog(
|
|||||||
logCount
|
logCount
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(`Writing logs to ${logPath}`)
|
logger.info(`Writing logs to ${logFilePath}`)
|
||||||
await createFile(logPath, log)
|
await createFile(logFilePath, log)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,5 @@
|
|||||||
"sourceMap": true
|
"sourceMap": true
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"exclude": ["node_modules", "**/*.spec.ts"]
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user