From 91d29cb1272c28afbceaf39d1e0a87e17fbfdcd6 Mon Sep 17 00:00:00 2001 From: sabhas Date: Mon, 20 Jun 2022 17:12:32 +0500 Subject: [PATCH 1/4] fix: default runtime should be sas --- README.md | 4 ++-- api/.env.example | 2 +- api/src/utils/verifyEnvVariables.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 365b4c2..2a4df5b 100644 --- a/README.md +++ b/README.md @@ -140,10 +140,10 @@ HELMET_CSP_CONFIG_PATH=./csp.config.json LOG_FORMAT_MORGAN= # A comma separated string that defines the available runTimes. -# Priority is given to the runtime that cSAS_PATHomes first in string. +# Priority is given to the runtime that comes first in the string. # Possible options at the moment are sas and js -# options: [sas,js|js,sas|sas|js] default:sas,js +# options: [sas,js|js,sas|sas|js] default:sas RUN_TIMES= ``` diff --git a/api/.env.example b/api/.env.example index cdb2431..d11bd43 100644 --- a/api/.env.example +++ b/api/.env.example @@ -17,7 +17,7 @@ AUTH_CODE_SECRET= SESSION_SECRET= DB_CONNECT=mongodb+srv://:@/?retryWrites=true&w=majority -RUN_TIMES=[sas|js|sas,js|js,sas] default considered as sas,js +RUN_TIMES=[sas|js|sas,js|js,sas] default considered as sas SAS_PATH=/opt/sas/sas9/SASHome/SASFoundation/9.4/sas NODE_PATH=~/.nvm/versions/node/v16.14.0/bin/node diff --git a/api/src/utils/verifyEnvVariables.ts b/api/src/utils/verifyEnvVariables.ts index 3c51363..d53338f 100644 --- a/api/src/utils/verifyEnvVariables.ts +++ b/api/src/utils/verifyEnvVariables.ts @@ -258,5 +258,5 @@ const DEFAULTS = { PORT: '5000', HELMET_COEP: HelmetCoepType.TRUE, LOG_FORMAT_MORGAN: LOG_FORMAT_MORGANType.Common, - RUN_TIMES: `${RunTimeType.SAS},${RunTimeType.JS}` + RUN_TIMES: `${RunTimeType.SAS}` } From 99a110736448f66f99a512396b268fc31a3feef0 Mon Sep 17 00:00:00 2001 From: sabhas Date: Mon, 20 Jun 2022 17:28:25 +0500 Subject: [PATCH 2/4] fix: webout path fixed in code.js when running on windows --- api/src/controllers/internal/createJSProgram.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/src/controllers/internal/createJSProgram.ts b/api/src/controllers/internal/createJSProgram.ts index f2e3333..5176dae 100644 --- a/api/src/controllers/internal/createJSProgram.ts +++ b/api/src/controllers/internal/createJSProgram.ts @@ -19,7 +19,11 @@ export const createJSProgram = async ( const preProgramVarStatments = ` let _webout = ''; -const weboutPath = '${weboutPath}'; +const weboutPath = '${ + process.platform === 'win32' + ? weboutPath.replace(/\\/g, '\\\\') + : weboutPath + }'; const _sasjs_tokenfile = '${tokenFile}'; const _sasjs_username = '${preProgramVariables?.username}'; const _sasjs_userid = '${preProgramVariables?.userId}'; From eb569c7b827c872ed2c4bc114559b97d87fd2aa0 Mon Sep 17 00:00:00 2001 From: sabhas Date: Mon, 20 Jun 2022 17:29:19 +0500 Subject: [PATCH 3/4] fix(Studio): default selection of runtime fixed --- api/public/swagger.yaml | 16 ++++++++-------- api/src/utils/validation.ts | 2 +- web/src/containers/Studio/index.tsx | 17 +++++++++++++---- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/api/public/swagger.yaml b/api/public/swagger.yaml index 0ab1c0e..6acdb14 100644 --- a/api/public/swagger.yaml +++ b/api/public/swagger.yaml @@ -144,7 +144,7 @@ components: - sas - js type: string - ExecuteSASCodePayload: + ExecuteCodePayload: properties: code: type: string @@ -666,7 +666,7 @@ paths: $ref: '#/components/schemas/ClientPayload' /SASjsApi/code/execute: post: - operationId: ExecuteSASCode + operationId: ExecuteCode responses: '200': description: Ok @@ -687,7 +687,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ExecuteSASCodePayload' + $ref: '#/components/schemas/ExecuteCodePayload' /SASjsApi/drive/deploy: post: operationId: Deploy @@ -763,7 +763,7 @@ paths: examples: 'Example 1': value: {status: failure, message: 'Deployment failed!'} - description: "Accepts JSON file and zipped compressed JSON file as well.\nCompressed file should only contain one JSON file and should have same name\nas of compressed file e.g. deploy.JSON should be compressed to deploy.JSON.zip\nAny other file or JSON file in zipped will be ignored!" + description: "Accepts JSON file and zipped compressed JSON file as well.\r\nCompressed file should only contain one JSON file and should have same name\r\nas of compressed file e.g. deploy.JSON should be compressed to deploy.JSON.zip\r\nAny other file or JSON file in zipped will be ignored!" summary: 'Creates/updates files within SASjs Drive using uploaded JSON/compressed JSON file.' tags: - Drive @@ -851,7 +851,7 @@ paths: examples: 'Example 1': value: {status: failure, message: 'File request failed.'} - description: "It's optional to either provide `_filePath` in url as query parameter\nOr provide `filePath` in body as form field.\nBut it's required to provide else API will respond with Bad Request." + description: "It's optional to either provide `_filePath` in url as query parameter\r\nOr provide `filePath` in body as form field.\r\nBut it's required to provide else API will respond with Bad Request." summary: 'Create a file in SASjs Drive' tags: - Drive @@ -902,7 +902,7 @@ paths: examples: 'Example 1': value: {status: failure, message: 'File request failed.'} - description: "It's optional to either provide `_filePath` in url as query parameter\nOr provide `filePath` in body as form field.\nBut it's required to provide else API will respond with Bad Request." + description: "It's optional to either provide `_filePath` in url as query parameter\r\nOr provide `filePath` in body as form field.\r\nBut it's required to provide else API will respond with Bad Request." summary: 'Modify a file in SASjs Drive' tags: - Drive @@ -1454,7 +1454,7 @@ paths: anyOf: - {type: string} - {type: string, format: byte} - description: "Trigger a SAS or JS program using the _program URL parameter.\n\nAccepts URL parameters and file uploads. For more details, see docs:\n\nhttps://server.sasjs.io/storedprograms" + description: "Trigger a SAS or JS program using the _program URL parameter.\r\n\r\nAccepts URL parameters and file uploads. For more details, see docs:\r\n\r\nhttps://server.sasjs.io/storedprograms" summary: 'Execute a Stored Program, returns raw _webout content.' tags: - STP @@ -1482,7 +1482,7 @@ paths: examples: 'Example 1': value: {status: success, _webout: 'webout content', log: [], httpHeaders: {Content-type: application/zip, Cache-Control: 'public, max-age=1000'}} - description: "Trigger a SAS or JS program using the _program URL parameter.\n\nAccepts URL parameters and file uploads. For more details, see docs:\n\nhttps://server.sasjs.io/storedprograms\n\nThe response will be a JSON object with the following root attributes:\nlog, webout, headers.\n\nThe webout attribute will be nested JSON ONLY if the response-header\ncontains a content-type of application/json AND it is valid JSON.\nOtherwise it will be a stringified version of the webout content." + description: "Trigger a SAS or JS program using the _program URL parameter.\r\n\r\nAccepts URL parameters and file uploads. For more details, see docs:\r\n\r\nhttps://server.sasjs.io/storedprograms\r\n\r\nThe response will be a JSON object with the following root attributes:\r\nlog, webout, headers.\r\n\r\nThe webout attribute will be nested JSON ONLY if the response-header\r\ncontains a content-type of application/json AND it is valid JSON.\r\nOtherwise it will be a stringified version of the webout content." summary: 'Execute a Stored Program, return a JSON object' tags: - STP diff --git a/api/src/utils/validation.ts b/api/src/utils/validation.ts index c406b4b..d8eff6f 100644 --- a/api/src/utils/validation.ts +++ b/api/src/utils/validation.ts @@ -124,7 +124,7 @@ export const folderParamValidation = (data: any): Joi.ValidationResult => export const runCodeValidation = (data: any): Joi.ValidationResult => Joi.object({ code: Joi.string().required(), - runTime: Joi.string().valid(...Object.values(RunTimeType)) + runTime: Joi.string().valid(...process.runTimes) }).validate(data) export const executeProgramRawValidation = (data: any): Joi.ValidationResult => diff --git a/web/src/containers/Studio/index.tsx b/web/src/containers/Studio/index.tsx index 10bd25d..4c44995 100644 --- a/web/src/containers/Studio/index.tsx +++ b/web/src/containers/Studio/index.tsx @@ -48,7 +48,16 @@ const Studio = () => { const [ctrlPressed, setCtrlPressed] = useState(false) const [webout, setWebout] = useState('') const [tab, setTab] = useState('1') - const [selectedRunTime, setSelectedRunTime] = useState(RunTimeType.SAS) + const [runTimes, setRunTimes] = useState([]) + const [selectedRunTime, setSelectedRunTime] = useState('') + + useEffect(() => { + setRunTimes(Object.values(appContext.runTimes)) + }, [appContext.runTimes]) + + useEffect(() => { + if(runTimes.length) setSelectedRunTime(runTimes[0]) + }, [runTimes]) const handleTabChange = (_e: any, newValue: string) => { setTab(newValue) @@ -153,7 +162,7 @@ const Studio = () => { - +