mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-08 13:00:05 +00:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4026b03005 | ||
|
|
eab19a0e6e | ||
|
|
1d7b7d654d | ||
|
|
de51946850 | ||
|
|
ebd55c5b02 | ||
|
|
f48089cb8c | ||
|
|
30a99f9cc5 | ||
|
|
b1979f63ef | ||
|
|
97c3cfd574 | ||
|
|
56df578ab2 | ||
|
|
556ab608c5 | ||
|
|
0633a6de84 | ||
|
|
a39f9bb7e8 | ||
|
|
a0172337ea | ||
|
|
56683bcee2 | ||
|
|
8d99612695 | ||
|
|
f232fe158c | ||
|
|
11b218702b |
3
.github/reviewer-lottery.yml
vendored
3
.github/reviewer-lottery.yml
vendored
@@ -2,11 +2,8 @@ groups:
|
|||||||
- name: SASjs Devs # name of the group
|
- name: SASjs Devs # name of the group
|
||||||
reviewers: 1 # how many reviewers do you want to assign?
|
reviewers: 1 # how many reviewers do you want to assign?
|
||||||
usernames: # github usernames of the reviewers
|
usernames: # github usernames of the reviewers
|
||||||
- krishna-acondy
|
|
||||||
- YuryShkoda
|
- YuryShkoda
|
||||||
- saadjutt01
|
|
||||||
- medjedovicm
|
- medjedovicm
|
||||||
- allanbowe
|
|
||||||
- sabhas
|
- sabhas
|
||||||
- name: SASjs QA
|
- name: SASjs QA
|
||||||
reviewers: 1
|
reviewers: 1
|
||||||
|
|||||||
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -22,6 +22,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
cache: npm
|
cache: npm
|
||||||
|
- name: Check npm audit
|
||||||
|
run: npm audit --production --audit-level=low
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: Check code style
|
- name: Check code style
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ module.exports = {
|
|||||||
setupFiles: [],
|
setupFiles: [],
|
||||||
|
|
||||||
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
||||||
setupFilesAfterEnv: ['jest-extended'],
|
setupFilesAfterEnv: ['jest-extended/all'],
|
||||||
|
|
||||||
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
||||||
// snapshotSerializers: [],
|
// snapshotSerializers: [],
|
||||||
|
|||||||
6338
package-lock.json
generated
6338
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
72
package.json
72
package.json
@@ -40,44 +40,44 @@
|
|||||||
},
|
},
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/axios": "^0.14.0",
|
"@types/axios": "0.14.0",
|
||||||
"@types/express": "^4.17.13",
|
"@types/express": "4.17.13",
|
||||||
"@types/form-data": "^2.5.0",
|
"@types/form-data": "2.5.0",
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "27.0.2",
|
||||||
"@types/mime": "^2.0.3",
|
"@types/mime": "2.0.3",
|
||||||
"@types/pem": "^1.9.6",
|
"@types/pem": "1.9.6",
|
||||||
"@types/tough-cookie": "^4.0.1",
|
"@types/tough-cookie": "4.0.1",
|
||||||
"copyfiles": "^2.4.1",
|
"copyfiles": "2.4.1",
|
||||||
"cp": "^0.2.0",
|
"cp": "0.2.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "10.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "4.17.1",
|
||||||
"jest": "^27.2.0",
|
"jest": "27.4.7",
|
||||||
"jest-extended": "^0.11.5",
|
"jest-extended": "2.0.0",
|
||||||
"node-polyfill-webpack-plugin": "^1.1.4",
|
"node-polyfill-webpack-plugin": "1.1.4",
|
||||||
"path": "^0.12.7",
|
"path": "0.12.7",
|
||||||
"pem": "^1.14.4",
|
"pem": "1.14.4",
|
||||||
"process": "^0.11.10",
|
"process": "0.11.10",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "3.0.2",
|
||||||
"semantic-release": "^18.0.0",
|
"semantic-release": "18.0.0",
|
||||||
"terser-webpack-plugin": "^5.2.4",
|
"terser-webpack-plugin": "5.3.0",
|
||||||
"ts-jest": "^27.0.3",
|
"ts-jest": "27.1.3",
|
||||||
"ts-loader": "^9.2.6",
|
"ts-loader": "9.2.6",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0",
|
"tslint-config-prettier": "1.18.0",
|
||||||
"typedoc": "0.19.2",
|
"typedoc": "0.22.11",
|
||||||
"typedoc-neo-theme": "^1.1.1",
|
"typedoc-neo-theme": "1.1.1",
|
||||||
"typedoc-plugin-external-module-name": "^4.0.6",
|
"typedoc-plugin-external-module-name": "4.0.6",
|
||||||
"typescript": "4.3.5",
|
"typescript": "4.5.4",
|
||||||
"webpack": "^5.56.0",
|
"webpack": "5.66.0",
|
||||||
"webpack-cli": "^4.7.2"
|
"webpack-cli": "4.7.2"
|
||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/utils": "^2.32.0",
|
"@sasjs/utils": "2.35.0",
|
||||||
"axios": "^0.21.4",
|
"axios": "0.26.0",
|
||||||
"axios-cookiejar-support": "^1.0.1",
|
"axios-cookiejar-support": "2.0.3",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "4.0.0",
|
||||||
"https": "^1.0.0",
|
"https": "1.0.0",
|
||||||
"tough-cookie": "^4.0.0"
|
"tough-cookie": "4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/SASjs.ts
23
src/SASjs.ts
@@ -5,9 +5,8 @@ import {
|
|||||||
EditContextInput,
|
EditContextInput,
|
||||||
PollOptions,
|
PollOptions,
|
||||||
LoginMechanism,
|
LoginMechanism,
|
||||||
FolderMember,
|
ExecutionQuery,
|
||||||
ServiceMember,
|
FileTree
|
||||||
ExecutionQuery
|
|
||||||
} from './types'
|
} from './types'
|
||||||
import { SASViyaApiClient } from './SASViyaApiClient'
|
import { SASViyaApiClient } from './SASViyaApiClient'
|
||||||
import { SAS9ApiClient } from './SAS9ApiClient'
|
import { SAS9ApiClient } from './SAS9ApiClient'
|
||||||
@@ -865,8 +864,22 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deployToSASjs(members: [FolderMember, ServiceMember]) {
|
/**
|
||||||
return await this.sasJSApiClient?.deploy(members, this.sasjsConfig.appLoc)
|
* Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
|
||||||
|
* @param members - the JSON specifying the folders and services to be created.
|
||||||
|
* @param appLoc - the base folder in which to create the new folders and
|
||||||
|
* services. If not provided, is taken from SASjsConfig.
|
||||||
|
* @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
|
||||||
|
*/
|
||||||
|
public async deployToSASjs(
|
||||||
|
members: FileTree,
|
||||||
|
appLoc?: string,
|
||||||
|
authConfig?: AuthConfig
|
||||||
|
) {
|
||||||
|
if (!appLoc) {
|
||||||
|
appLoc = this.sasjsConfig.appLoc
|
||||||
|
}
|
||||||
|
return await this.sasJSApiClient?.deploy(members, appLoc, authConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async executeJobSASjs(query: ExecutionQuery) {
|
public async executeJobSASjs(query: ExecutionQuery) {
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import { FolderMember, ServiceMember, ExecutionQuery } from './types'
|
import { AuthConfig, ServerType } from '@sasjs/utils/types'
|
||||||
|
import { FileTree, ExecutionQuery } from './types'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
|
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
|
||||||
import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs'
|
import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs'
|
||||||
import { getAuthCodeForSasjs } from './auth/getAuthCodeForSasjs'
|
import { getAuthCodeForSasjs } from './auth/getAuthCodeForSasjs'
|
||||||
|
import { parseWeboutResponse } from './utils'
|
||||||
|
import { getTokens } from './auth/getTokens'
|
||||||
|
|
||||||
export class SASjsApiClient {
|
export class SASjsApiClient {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -14,7 +17,19 @@ export class SASjsApiClient {
|
|||||||
if (serverUrl) this.serverUrl = serverUrl
|
if (serverUrl) this.serverUrl = serverUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deploy(members: [FolderMember, ServiceMember], appLoc: string) {
|
public async deploy(
|
||||||
|
members: FileTree,
|
||||||
|
appLoc: string,
|
||||||
|
authConfig?: AuthConfig
|
||||||
|
) {
|
||||||
|
let access_token = (authConfig || {}).access_token
|
||||||
|
if (authConfig) {
|
||||||
|
;({ access_token } = await getTokens(
|
||||||
|
this.requestClient,
|
||||||
|
authConfig,
|
||||||
|
ServerType.Sasjs
|
||||||
|
))
|
||||||
|
}
|
||||||
const { result } = await this.requestClient.post<{
|
const { result } = await this.requestClient.post<{
|
||||||
status: string
|
status: string
|
||||||
message: string
|
message: string
|
||||||
@@ -22,7 +37,7 @@ export class SASjsApiClient {
|
|||||||
}>(
|
}>(
|
||||||
'SASjsApi/drive/deploy',
|
'SASjsApi/drive/deploy',
|
||||||
{ fileTree: members, appLoc: appLoc },
|
{ fileTree: members, appLoc: appLoc },
|
||||||
undefined
|
access_token
|
||||||
)
|
)
|
||||||
|
|
||||||
return Promise.resolve(result)
|
return Promise.resolve(result)
|
||||||
@@ -35,8 +50,13 @@ export class SASjsApiClient {
|
|||||||
log?: string
|
log?: string
|
||||||
logPath?: string
|
logPath?: string
|
||||||
error?: {}
|
error?: {}
|
||||||
|
_webout?: string
|
||||||
}>('SASjsApi/stp/execute', query, undefined)
|
}>('SASjsApi/stp/execute', query, undefined)
|
||||||
|
|
||||||
|
if (Object.keys(result).includes('_webout')) {
|
||||||
|
result._webout = parseWeboutResponse(result._webout!)
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve(result)
|
return Promise.resolve(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -272,7 +272,13 @@ export async function executeScript(
|
|||||||
|
|
||||||
return { result: jobResult?.result, log }
|
return { result: jobResult?.result, log }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e && e.status === 404) {
|
interface HttpError {
|
||||||
|
status: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const error = e as HttpError
|
||||||
|
|
||||||
|
if (error.status === 404) {
|
||||||
return executeScript(
|
return executeScript(
|
||||||
requestClient,
|
requestClient,
|
||||||
sessionManager,
|
sessionManager,
|
||||||
@@ -287,7 +293,7 @@ export async function executeScript(
|
|||||||
true
|
true
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
throw prefixMessage(e, 'Error while executing script. ')
|
throw prefixMessage(e as Error, 'Error while executing script. ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,34 @@
|
|||||||
import { WriteStream } from '../../../types'
|
import { WriteStream } from '../../../types'
|
||||||
import { writeStream } from '../writeStream'
|
import { writeStream } from '../writeStream'
|
||||||
import 'jest-extended'
|
import {
|
||||||
|
createWriteStream,
|
||||||
|
fileExists,
|
||||||
|
readFile,
|
||||||
|
deleteFile
|
||||||
|
} from '@sasjs/utils'
|
||||||
|
|
||||||
describe('writeStream', () => {
|
describe('writeStream', () => {
|
||||||
const stream: WriteStream = {
|
const filename = 'test.txt'
|
||||||
write: jest.fn(),
|
const content = 'test'
|
||||||
path: 'test'
|
let stream: WriteStream
|
||||||
}
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
stream = await createWriteStream(filename)
|
||||||
|
})
|
||||||
|
|
||||||
it('should resolve when the stream is written successfully', async () => {
|
it('should resolve when the stream is written successfully', async () => {
|
||||||
expect(writeStream(stream, 'test')).toResolve()
|
await expect(writeStream(stream, content)).toResolve()
|
||||||
|
await expect(fileExists(filename)).resolves.toEqual(true)
|
||||||
|
await expect(readFile(filename)).resolves.toEqual(content + '\n')
|
||||||
|
|
||||||
expect(stream.write).toHaveBeenCalledWith('test\n', expect.anything())
|
await deleteFile(filename)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should reject when the write errors out', async () => {
|
it('should reject when the write errors out', async () => {
|
||||||
jest
|
jest
|
||||||
.spyOn(stream, 'write')
|
.spyOn(stream, 'write')
|
||||||
.mockImplementation((_, callback) => callback(new Error('Test Error')))
|
.mockImplementation((_, callback) => callback(new Error('Test Error')))
|
||||||
const error = await writeStream(stream, 'test').catch((e) => e)
|
const error = await writeStream(stream, content).catch((e) => e)
|
||||||
|
|
||||||
expect(error.message).toEqual('Test Error')
|
expect(error.message).toEqual('Test Error')
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,13 +3,9 @@ import { WriteStream } from '../../types'
|
|||||||
export const writeStream = async (
|
export const writeStream = async (
|
||||||
stream: WriteStream,
|
stream: WriteStream,
|
||||||
content: string
|
content: string
|
||||||
): Promise<void> => {
|
): Promise<void> =>
|
||||||
return new Promise((resolve, reject) => {
|
stream.write(content + '\n', (e) => {
|
||||||
stream.write(content + '\n', (e) => {
|
if (e) return Promise.reject(e)
|
||||||
if (e) {
|
|
||||||
return reject(e)
|
return Promise.resolve()
|
||||||
}
|
|
||||||
return resolve()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as https from 'https'
|
import * as https from 'https'
|
||||||
import { AxiosRequestConfig } from 'axios'
|
import { AxiosRequestConfig } from 'axios'
|
||||||
import axiosCookieJarSupport from 'axios-cookiejar-support'
|
import * as axiosCookieJarSupport from 'axios-cookiejar-support'
|
||||||
import * as tough from 'tough-cookie'
|
import * as tough from 'tough-cookie'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
import { RequestClient, throwIfError } from './RequestClient'
|
import { RequestClient, throwIfError } from './RequestClient'
|
||||||
@@ -17,7 +17,7 @@ export class Sas9RequestClient extends RequestClient {
|
|||||||
status >= 200 && status < 303
|
status >= 200 && status < 303
|
||||||
|
|
||||||
if (axiosCookieJarSupport) {
|
if (axiosCookieJarSupport) {
|
||||||
axiosCookieJarSupport(this.httpClient)
|
axiosCookieJarSupport.wrapper(this.httpClient)
|
||||||
this.httpClient.defaults.jar = new tough.CookieJar()
|
this.httpClient.defaults.jar = new tough.CookieJar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -423,7 +423,7 @@ describe('ContextManager', () => {
|
|||||||
true
|
true
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
editError = error
|
editError = error as Error
|
||||||
}
|
}
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
@@ -542,7 +542,7 @@ describe('ContextManager', () => {
|
|||||||
true
|
true
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
deleteError = error
|
deleteError = error as Error
|
||||||
}
|
}
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
|
|||||||
1
src/types/system/global.d.ts
vendored
Normal file
1
src/types/system/global.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
import 'jest-extended'
|
||||||
@@ -10,6 +10,7 @@ export const parseWeboutResponse = (response: string, url?: string): string => {
|
|||||||
.split('>>weboutEND<<')[0]
|
.split('>>weboutEND<<')[0]
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (url) throw new WeboutResponseError(url)
|
if (url) throw new WeboutResponseError(url)
|
||||||
|
|
||||||
sasResponse = ''
|
sasResponse = ''
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
"declaration": true,
|
"declaration": true,
|
||||||
"outDir": "./build",
|
"outDir": "./build",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"sourceMap": true
|
"sourceMap": true,
|
||||||
|
"typeRoots": ["./node_modules/@types", "./src/types/system"]
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
|
|||||||
Reference in New Issue
Block a user