mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-09 13:30:04 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
296a543b2d | ||
| 70b31dcb8f | |||
| b0c2a81989 | |||
| 53e167b17d | |||
|
|
5159318d0d | ||
|
|
6842ee13e4 | ||
|
|
2ce0395a2e | ||
|
|
63440ddfd2 | ||
|
|
eb6729a9c7 | ||
|
|
9cd9dc83f3 | ||
|
|
7608887a0e |
22
.github/workflows/generateDocs.yml
vendored
22
.github/workflows/generateDocs.yml
vendored
@@ -26,17 +26,19 @@ jobs:
|
|||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Ensure docs folder exists
|
||||||
|
run: |
|
||||||
|
rm -rf docs || true # avoid error if docs folder does not exist
|
||||||
|
mkdir docs
|
||||||
|
|
||||||
- name: Generate Docs
|
- name: Generate Docs
|
||||||
run: npm run typedoc
|
run: npm run typedoc
|
||||||
|
|
||||||
- name: Create CNAME file in docs
|
- name: Push generated docs
|
||||||
run: |
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
touch CNAME
|
with:
|
||||||
echo adapter.sasjs.io >> CNAME
|
github_token: ${{ secrets.GH_TOKEN }}
|
||||||
|
publish_branch: gh-pages
|
||||||
|
publish_dir: ./docs
|
||||||
|
cname: adapter.sasjs.io
|
||||||
|
|
||||||
- name: Push generated docs to docs branch
|
|
||||||
uses: nicholasgriffintn/github-branch-deployment-action@0.0.1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
||||||
BRANCH: docs
|
|
||||||
MESSAGE: 'Docs: ({sha}) {msg}'
|
|
||||||
|
|||||||
2
.github/workflows/npmpublish.yml
vendored
2
.github/workflows/npmpublish.yml
vendored
@@ -40,4 +40,4 @@ jobs:
|
|||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
- name: Send Matrix message
|
- name: Send Matrix message
|
||||||
run: curl -X POST --data-urlencode "payload={\"msgtype\":\"m.text\", \"body\":\"New version of @sasjs/adapter has been released! \n Please deploy and run `dctests` with new adapter to make sure everything is still in place.\"}" https://matrix.4gl.io/_matrix/client/r0/rooms/%21BDUPBPEGVvRLKLQUxY:4gl.io/send/m.room.message?access_token=${{ secrets.MATRIX_TOKEN }}
|
run: curl -XPOST -d "{\"msgtype\":\"m.text\", \"body\":\"New version of @sasjs/adapter has been released! \n Please deploy and run 'dctests' with new adapter to make sure everything is still in place.\"}" https://matrix.4gl.io/_matrix/client/r0/rooms/!BDUPBPEGVvRLKLQUxY:4gl.io/send/m.room.message?access_token=${{ secrets.MATRIX_TOKEN }}
|
||||||
@@ -71,13 +71,12 @@ export const computeTests = (adapter: SASjs, appLoc: string): TestSuite => ({
|
|||||||
test: () => {
|
test: () => {
|
||||||
const fileLines = [`data;`, `do x=1 to 100;`, `output;`, `end;`, `run;`]
|
const fileLines = [`data;`, `do x=1 to 100;`, `output;`, `end;`, `run;`]
|
||||||
|
|
||||||
return adapter.executeScriptSASViya(
|
return adapter.executeScript({
|
||||||
'sasCode.sas',
|
fileName: 'sasCode.sas',
|
||||||
fileLines,
|
linesOfCode: fileLines,
|
||||||
'SAS Studio compute context',
|
contextName: 'SAS Studio compute context',
|
||||||
undefined,
|
debug: true
|
||||||
true
|
})
|
||||||
)
|
|
||||||
},
|
},
|
||||||
assertion: (res: any) => {
|
assertion: (res: any) => {
|
||||||
const expectedLogContent = `1 data;\\n2 do x=1 to 100;\\n3 output;\\n4 end;\\n5 run;\\n\\n`
|
const expectedLogContent = `1 data;\\n2 do x=1 to 100;\\n3 output;\\n4 end;\\n5 run;\\n\\n`
|
||||||
@@ -92,13 +91,12 @@ export const computeTests = (adapter: SASjs, appLoc: string): TestSuite => ({
|
|||||||
const fileLines = [`%abort;`]
|
const fileLines = [`%abort;`]
|
||||||
|
|
||||||
return adapter
|
return adapter
|
||||||
.executeScriptSASViya(
|
.executeScript({
|
||||||
'sasCode.sas',
|
fileName: 'sasCode.sas',
|
||||||
fileLines,
|
linesOfCode: fileLines,
|
||||||
'SAS Studio compute context',
|
contextName: 'SAS Studio compute context',
|
||||||
undefined,
|
debug: true
|
||||||
true
|
})
|
||||||
)
|
|
||||||
.catch((err: any) => err)
|
.catch((err: any) => err)
|
||||||
},
|
},
|
||||||
assertion: (res: any) => {
|
assertion: (res: any) => {
|
||||||
|
|||||||
159
src/SASjs.ts
159
src/SASjs.ts
@@ -17,7 +17,8 @@ import {
|
|||||||
AuthConfig,
|
AuthConfig,
|
||||||
ExtraResponseAttributes,
|
ExtraResponseAttributes,
|
||||||
SasAuthResponse,
|
SasAuthResponse,
|
||||||
ServicePackSASjs
|
ServicePackSASjs,
|
||||||
|
AuthConfigSas9
|
||||||
} from '@sasjs/utils/types'
|
} from '@sasjs/utils/types'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { SasjsRequestClient } from './request/SasjsRequestClient'
|
import { SasjsRequestClient } from './request/SasjsRequestClient'
|
||||||
@@ -33,6 +34,16 @@ import {
|
|||||||
import { ErrorResponse } from './types/errors'
|
import { ErrorResponse } from './types/errors'
|
||||||
import { LoginOptions, LoginResult } from './types/Login'
|
import { LoginOptions, LoginResult } from './types/Login'
|
||||||
|
|
||||||
|
interface ExecuteScriptParams {
|
||||||
|
linesOfCode: string[]
|
||||||
|
fileName?: string
|
||||||
|
contextName?: string
|
||||||
|
runTime?: string
|
||||||
|
authConfig?: AuthConfig
|
||||||
|
authConfigSas9?: AuthConfigSas9
|
||||||
|
debug?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
const defaultConfig: SASjsConfig = {
|
const defaultConfig: SASjsConfig = {
|
||||||
serverUrl: '',
|
serverUrl: '',
|
||||||
pathSASJS: '/SASjsApi/stp/execute',
|
pathSASJS: '/SASjsApi/stp/execute',
|
||||||
@@ -79,74 +90,73 @@ export default class SASjs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes SAS code on a SAS 9 server. Requires a runner to be present in
|
* Executes code on a SAS server.
|
||||||
* the users home directory in metadata.
|
* @param linesOfCode - lines of code to run.
|
||||||
* @param linesOfCode - lines of sas code from the file to run.
|
* @param fileName - (required for server type sas viya) name of the file to run. It will be converted to path to the file being submitted for execution.
|
||||||
* @param username - a string representing the username.
|
* @param contextName - (required for server type sas viya) context name on which code will be run on the server.
|
||||||
* @param password - a string representing the password.
|
* @param runTime - (required for server type sasjs) a string to represent runTime for code execution.
|
||||||
*/
|
|
||||||
public async executeScriptSAS9(
|
|
||||||
linesOfCode: string[],
|
|
||||||
userName: string,
|
|
||||||
password: string
|
|
||||||
) {
|
|
||||||
this.isMethodSupported('executeScriptSAS9', [ServerType.Sas9])
|
|
||||||
|
|
||||||
return await this.sas9ApiClient?.executeScript(
|
|
||||||
linesOfCode,
|
|
||||||
userName,
|
|
||||||
password
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes SAS code on a SASJS server
|
|
||||||
* @param code - a string of code from the file to run.
|
|
||||||
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
|
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
|
||||||
*/
|
* @param authConfigSas9 - (required for server type sas9) a valid username and password that are authorised to execute scripts.
|
||||||
public async executeScriptSASjs(
|
|
||||||
code: string,
|
|
||||||
runTime?: string,
|
|
||||||
authConfig?: AuthConfig
|
|
||||||
) {
|
|
||||||
this.isMethodSupported('executeScriptSASJS', [ServerType.Sasjs])
|
|
||||||
|
|
||||||
return await this.sasJSApiClient?.executeScript(code, runTime, authConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes sas code in a SAS Viya compute session.
|
|
||||||
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
|
|
||||||
* @param linesOfCode - lines of sas code from the file to run.
|
|
||||||
* @param contextName - context name on which code will be run on the server.
|
|
||||||
* @param authConfig - (optional) the access token, refresh token, client and secret for authorizing the request.
|
|
||||||
* @param debug - (optional) if true, global debug config will be overriden
|
* @param debug - (optional) if true, global debug config will be overriden
|
||||||
*/
|
*/
|
||||||
public async executeScriptSASViya(
|
public async executeScript({
|
||||||
fileName: string,
|
linesOfCode,
|
||||||
linesOfCode: string[],
|
fileName,
|
||||||
contextName: string,
|
contextName,
|
||||||
authConfig?: AuthConfig,
|
runTime,
|
||||||
debug?: boolean
|
authConfig,
|
||||||
) {
|
authConfigSas9,
|
||||||
this.isMethodSupported('executeScriptSASViya', [ServerType.SasViya])
|
debug
|
||||||
|
}: ExecuteScriptParams) {
|
||||||
|
this.isMethodSupported('executeScript', [
|
||||||
|
ServerType.Sas9,
|
||||||
|
ServerType.Sasjs,
|
||||||
|
ServerType.SasViya
|
||||||
|
])
|
||||||
|
|
||||||
contextName = contextName || this.sasjsConfig.contextName
|
if (this.sasjsConfig.serverType === ServerType.Sas9) {
|
||||||
|
if (!authConfigSas9)
|
||||||
|
throw new Error('Auth config for sas9 is not provided')
|
||||||
|
|
||||||
if (!contextName) {
|
return await this.sas9ApiClient?.executeScript(
|
||||||
throw new Error(
|
linesOfCode,
|
||||||
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
authConfigSas9.userName,
|
||||||
|
authConfigSas9.password
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.executeScript(
|
if (this.sasjsConfig.serverType === ServerType.Sasjs) {
|
||||||
fileName,
|
return await this.sasJSApiClient?.executeScript(
|
||||||
linesOfCode,
|
linesOfCode.join('\n'),
|
||||||
contextName,
|
runTime,
|
||||||
authConfig,
|
authConfig
|
||||||
null,
|
)
|
||||||
debug ? debug : this.sasjsConfig.debug
|
}
|
||||||
)
|
|
||||||
|
if (this.sasjsConfig.serverType === ServerType.SasViya) {
|
||||||
|
contextName = contextName || this.sasjsConfig.contextName
|
||||||
|
|
||||||
|
if (!contextName) {
|
||||||
|
throw new Error(
|
||||||
|
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fileName) {
|
||||||
|
throw new Error(
|
||||||
|
'File name is required in case of SAS VIYA. Please provide a `fileName`.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return await this.sasViyaApiClient!.executeScript(
|
||||||
|
fileName,
|
||||||
|
linesOfCode,
|
||||||
|
contextName,
|
||||||
|
authConfig,
|
||||||
|
null,
|
||||||
|
debug ? debug : this.sasjsConfig.debug
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -826,33 +836,6 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
|
|
||||||
* @param dataJson - the JSON specifying the folders and files to be created, can also includes
|
|
||||||
* appLoc, streamServiceName, streamWebFolder, streamLogo
|
|
||||||
* @param appLoc - (optional) the base folder in which to create the new folders and
|
|
||||||
* services. If not provided, is taken from SASjsConfig. Precedence will be of appLoc present in dataJson.
|
|
||||||
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
|
|
||||||
*/
|
|
||||||
public async deployToSASjs(
|
|
||||||
dataJson: ServicePackSASjs,
|
|
||||||
appLoc?: string,
|
|
||||||
authConfig?: AuthConfig
|
|
||||||
) {
|
|
||||||
if (!appLoc) {
|
|
||||||
appLoc = this.sasjsConfig.appLoc
|
|
||||||
}
|
|
||||||
return await this.sasJSApiClient?.deploy(dataJson, appLoc, authConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async executeJobSASjs(query: ExecutionQuery, authConfig?: AuthConfig) {
|
|
||||||
return await this.sasJSApiClient?.executeJob(
|
|
||||||
query,
|
|
||||||
this.sasjsConfig.appLoc,
|
|
||||||
authConfig
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kicks off execution of the given job via the compute API.
|
* Kicks off execution of the given job via the compute API.
|
||||||
* @returns an object representing the compute session created for the given job.
|
* @returns an object representing the compute session created for the given job.
|
||||||
|
|||||||
@@ -8,6 +8,13 @@ import { getTokens } from './auth/getTokens'
|
|||||||
export class SASjsApiClient {
|
export class SASjsApiClient {
|
||||||
constructor(private requestClient: RequestClient) {}
|
constructor(private requestClient: RequestClient) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
|
||||||
|
* @param dataJson - the JSON specifying the folders and files to be created, can also includes
|
||||||
|
* appLoc, streamServiceName, streamWebFolder, streamLogo
|
||||||
|
* @param appLoc - the base folder in which to create the new folders and services.
|
||||||
|
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
|
||||||
|
*/
|
||||||
public async deploy(
|
public async deploy(
|
||||||
dataJson: ServicePackSASjs,
|
dataJson: ServicePackSASjs,
|
||||||
appLoc: string,
|
appLoc: string,
|
||||||
|
|||||||
@@ -3,4 +3,6 @@ export * from './types'
|
|||||||
export * from './types/errors'
|
export * from './types/errors'
|
||||||
export * from './SASViyaApiClient'
|
export * from './SASViyaApiClient'
|
||||||
export * from './SAS9ApiClient'
|
export * from './SAS9ApiClient'
|
||||||
|
export * from './SASjsApiClient'
|
||||||
|
export * from './request/SasjsRequestClient'
|
||||||
export default SASjs
|
export default SASjs
|
||||||
|
|||||||
Reference in New Issue
Block a user