1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-11 19:44:35 +00:00

Compare commits

...

12 Commits

Author SHA1 Message Date
semantic-release-bot
0a6b972c65 chore(release): 0.23.4 [skip ci]
## [0.23.4](https://github.com/sasjs/server/compare/v0.23.3...v0.23.4) (2022-10-11)

### Bug Fixes

* add action to editor ref for running code ([2412622](2412622367))
2022-10-11 15:26:38 +00:00
Allan Bowe
be11707042 Merge pull request #303 from sasjs/issue-301
fix: add action to editor ref for running code
2022-10-11 16:08:57 +01:00
2412622367 fix: add action to editor ref for running code 2022-10-10 16:51:46 +05:00
semantic-release-bot
de3a190a8d chore(release): 0.23.3 [skip ci]
## [0.23.3](https://github.com/sasjs/server/compare/v0.23.2...v0.23.3) (2022-10-09)

### Bug Fixes

* added domain for session cookies ([94072c3](94072c3d24))
2022-10-09 20:32:07 +00:00
Allan Bowe
d5daafc6ed Merge pull request #302 from sasjs/cookies-with-domain
fix: added domain for session cookies
2022-10-09 21:26:40 +01:00
Saad Jutt
b1a2677b8c chore: specified domain for cookie for csrf as well 2022-10-10 00:48:13 +05:00
Saad Jutt
94072c3d24 fix: added domain for session cookies 2022-10-09 22:08:01 +05:00
semantic-release-bot
b64c0c12da chore(release): 0.23.2 [skip ci]
## [0.23.2](https://github.com/sasjs/server/compare/v0.23.1...v0.23.2) (2022-10-06)

### Bug Fixes

* bump in correct place ([14731e8](14731e8824))
* bumping sasjs/score ([258cc35](258cc35f14))
* reverting commit ([fda0e0b](fda0e0b57d))
2022-10-06 12:41:15 +00:00
Allan Bowe
79bc7b0e28 Merge pull request #300 from sasjs/corebump
fix: bumping sasjs/score
2022-10-06 13:36:20 +01:00
Allan Bowe
fda0e0b57d fix: reverting commit 2022-10-06 12:35:59 +00:00
Allan Bowe
14731e8824 fix: bump in correct place 2022-10-06 12:34:48 +00:00
Allan Bowe
258cc35f14 fix: bumping sasjs/score 2022-10-06 12:32:13 +00:00
10 changed files with 111 additions and 82 deletions

View File

@@ -1,3 +1,26 @@
## [0.23.4](https://github.com/sasjs/server/compare/v0.23.3...v0.23.4) (2022-10-11)
### Bug Fixes
* add action to editor ref for running code ([2412622](https://github.com/sasjs/server/commit/2412622367eb46c40f388e988ae4606a7ec239b2))
## [0.23.3](https://github.com/sasjs/server/compare/v0.23.2...v0.23.3) (2022-10-09)
### Bug Fixes
* added domain for session cookies ([94072c3](https://github.com/sasjs/server/commit/94072c3d24a4d0d4c97900dc31bfbf1c9d2559b7))
## [0.23.2](https://github.com/sasjs/server/compare/v0.23.1...v0.23.2) (2022-10-06)
### Bug Fixes
* bump in correct place ([14731e8](https://github.com/sasjs/server/commit/14731e8824fa9f3d1daf89fd62f9916d5e3fcae4))
* bumping sasjs/score ([258cc35](https://github.com/sasjs/server/commit/258cc35f14cf50f2160f607000c60de27593fd79))
* reverting commit ([fda0e0b](https://github.com/sasjs/server/commit/fda0e0b57d56e3b5231e626a8d933343ac0c5cdc))
## [0.23.1](https://github.com/sasjs/server/compare/v0.23.0...v0.23.1) (2022-10-04) ## [0.23.1](https://github.com/sasjs/server/compare/v0.23.0...v0.23.1) (2022-10-04)

View File

@@ -1,5 +1,6 @@
MODE=[desktop|server] default considered as desktop MODE=[desktop|server] default considered as desktop
CORS=[disable|enable] default considered as disable for server MODE & enable for desktop MODE CORS=[disable|enable] default considered as disable for server MODE & enable for desktop MODE
ALLOWED_DOMAIN=<just domain e.g. example.com >
WHITELIST=<space separated urls, each starting with protocol `http` or `https`> WHITELIST=<space separated urls, each starting with protocol `http` or `https`>
PROTOCOL=[http|https] default considered as http PROTOCOL=[http|https] default considered as http

14
api/package-lock.json generated
View File

@@ -8,7 +8,7 @@
"name": "api", "name": "api",
"version": "0.0.2", "version": "0.0.2",
"dependencies": { "dependencies": {
"@sasjs/core": "^4.31.3", "@sasjs/core": "^4.40.1",
"@sasjs/utils": "2.48.1", "@sasjs/utils": "2.48.1",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"connect-mongo": "^4.6.0", "connect-mongo": "^4.6.0",
@@ -1394,9 +1394,9 @@
} }
}, },
"node_modules/@sasjs/core": { "node_modules/@sasjs/core": {
"version": "4.31.3", "version": "4.40.1",
"resolved": "https://registry.npmjs.org/@sasjs/core/-/core-4.31.3.tgz", "resolved": "https://registry.npmjs.org/@sasjs/core/-/core-4.40.1.tgz",
"integrity": "sha512-TpVqWl5bqp3JTQjIg0r4WiQg7Ima5f17eAJILJbdYDdXsnLXlA/Csbb95G7eDPhzWpM3C0NrzKek3yvCMGzXIA==" "integrity": "sha512-hVEVnH8tej57Cran/X/iUoDms7EoL+2fwAPvjQMgHBHh8ynsF8aqYBreiRCwbrvdrjBsnmayOVh2RiQLtfHhoQ=="
}, },
"node_modules/@sasjs/utils": { "node_modules/@sasjs/utils": {
"version": "2.48.1", "version": "2.48.1",
@@ -11135,9 +11135,9 @@
} }
}, },
"@sasjs/core": { "@sasjs/core": {
"version": "4.31.3", "version": "4.40.1",
"resolved": "https://registry.npmjs.org/@sasjs/core/-/core-4.31.3.tgz", "resolved": "https://registry.npmjs.org/@sasjs/core/-/core-4.40.1.tgz",
"integrity": "sha512-TpVqWl5bqp3JTQjIg0r4WiQg7Ima5f17eAJILJbdYDdXsnLXlA/Csbb95G7eDPhzWpM3C0NrzKek3yvCMGzXIA==" "integrity": "sha512-hVEVnH8tej57Cran/X/iUoDms7EoL+2fwAPvjQMgHBHh8ynsF8aqYBreiRCwbrvdrjBsnmayOVh2RiQLtfHhoQ=="
}, },
"@sasjs/utils": { "@sasjs/utils": {
"version": "2.48.1", "version": "2.48.1",

View File

@@ -48,7 +48,7 @@
}, },
"author": "4GL Ltd", "author": "4GL Ltd",
"dependencies": { "dependencies": {
"@sasjs/core": "^4.31.3", "@sasjs/core": "^4.40.1",
"@sasjs/utils": "2.48.1", "@sasjs/utils": "2.48.1",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"connect-mongo": "^4.6.0", "connect-mongo": "^4.6.0",

View File

@@ -1,10 +1,9 @@
import { Express } from 'express' import { Express, CookieOptions } from 'express'
import mongoose from 'mongoose' import mongoose from 'mongoose'
import session from 'express-session' import session from 'express-session'
import MongoStore from 'connect-mongo' import MongoStore from 'connect-mongo'
import { ModeType } from '../utils' import { ModeType, ProtocolType } from '../utils'
import { cookieOptions } from '../app'
export const configureExpressSession = (app: Express) => { export const configureExpressSession = (app: Express) => {
const { MODE } = process.env const { MODE } = process.env
@@ -19,6 +18,15 @@ export const configureExpressSession = (app: Express) => {
}) })
} }
const { PROTOCOL, ALLOWED_DOMAIN } = process.env
const cookieOptions: CookieOptions = {
secure: PROTOCOL === ProtocolType.HTTPS,
httpOnly: true,
sameSite: PROTOCOL === ProtocolType.HTTPS ? 'none' : undefined,
maxAge: 24 * 60 * 60 * 1000, // 24 hours
domain: ALLOWED_DOMAIN?.trim() || undefined
}
app.use( app.use(
session({ session({
secret: process.secrets.SESSION_SECRET, secret: process.secrets.SESSION_SECRET,

View File

@@ -1,5 +1,5 @@
import path from 'path' import path from 'path'
import express, { ErrorRequestHandler, CookieOptions } from 'express' import express, { ErrorRequestHandler } from 'express'
import cookieParser from 'cookie-parser' import cookieParser from 'cookie-parser'
import dotenv from 'dotenv' import dotenv from 'dotenv'
@@ -8,7 +8,6 @@ import {
getWebBuildFolder, getWebBuildFolder,
instantiateLogger, instantiateLogger,
loadAppStreamConfig, loadAppStreamConfig,
ProtocolType,
ReturnCode, ReturnCode,
setProcessVariables, setProcessVariables,
setupFolders, setupFolders,
@@ -29,15 +28,6 @@ if (verifyEnvVariables()) process.exit(ReturnCode.InvalidEnv)
const app = express() const app = express()
const { PROTOCOL } = process.env
export const cookieOptions: CookieOptions = {
secure: PROTOCOL === ProtocolType.HTTPS,
httpOnly: true,
sameSite: PROTOCOL === ProtocolType.HTTPS ? 'none' : undefined,
maxAge: 24 * 60 * 60 * 1000 // 24 hours
}
const onError: ErrorRequestHandler = (err, req, res, next) => { const onError: ErrorRequestHandler = (err, req, res, next) => {
console.error(err.stack) console.error(err.stack)
res.status(500).send('Something broke!') res.status(500).send('Something broke!')

View File

@@ -14,7 +14,10 @@ webRouter.get('/', async (req, res) => {
} catch (_) { } catch (_) {
response = '<html><head></head><body>Web Build is not present</body></html>' response = '<html><head></head><body>Web Build is not present</body></html>'
} finally { } finally {
const codeToInject = `<script>document.cookie = 'XSRF-TOKEN=${generateCSRFToken()}; Max-Age=86400; SameSite=Strict; Path=/;'</script>` const { ALLOWED_DOMAIN } = process.env
const allowedDomain = ALLOWED_DOMAIN?.trim()
const domain = allowedDomain ? ` Domain=${allowedDomain};` : ''
const codeToInject = `<script>document.cookie = 'XSRF-TOKEN=${generateCSRFToken()};${domain} Max-Age=86400; SameSite=Strict; Path=/;'</script>`
const injectedContent = response?.replace( const injectedContent = response?.replace(
'</head>', '</head>',
`${codeToInject}</head>` `${codeToInject}</head>`

View File

@@ -267,7 +267,7 @@ const verifyRUN_TIMES = (): string[] => {
return errors return errors
} }
const verifyExecutablePaths = () => { const verifyExecutablePaths = (): string[] => {
const errors: string[] = [] const errors: string[] = []
const { RUN_TIMES, SAS_PATH, NODE_PATH, PYTHON_PATH, R_PATH, MODE } = const { RUN_TIMES, SAS_PATH, NODE_PATH, PYTHON_PATH, R_PATH, MODE } =
process.env process.env

View File

@@ -48,7 +48,6 @@ const SASjsEditor = ({
setTab setTab
}: SASjsEditorProps) => { }: SASjsEditorProps) => {
const { const {
ctrlPressed,
fileContent, fileContent,
isLoading, isLoading,
log, log,
@@ -64,8 +63,6 @@ const SASjsEditor = ({
handleDiffEditorDidMount, handleDiffEditorDidMount,
handleEditorDidMount, handleEditorDidMount,
handleFilePathInput, handleFilePathInput,
handleKeyDown,
handleKeyUp,
handleRunBtnClick, handleRunBtnClick,
handleTabChange, handleTabChange,
saveFile, saveFile,
@@ -99,7 +96,6 @@ const SASjsEditor = ({
original={prevFileContent} original={prevFileContent}
value={fileContent} value={fileContent}
editorDidMount={handleDiffEditorDidMount} editorDidMount={handleDiffEditorDidMount}
options={{ readOnly: ctrlPressed }}
onChange={(val) => setFileContent(val)} onChange={(val) => setFileContent(val)}
/> />
) : ( ) : (
@@ -108,7 +104,6 @@ const SASjsEditor = ({
language={getLanguageFromExtension(selectedFileExtension)} language={getLanguageFromExtension(selectedFileExtension)}
value={fileContent} value={fileContent}
editorDidMount={handleEditorDidMount} editorDidMount={handleEditorDidMount}
options={{ readOnly: ctrlPressed }}
onChange={(val) => setFileContent(val)} onChange={(val) => setFileContent(val)}
/> />
) )
@@ -176,8 +171,6 @@ const SASjsEditor = ({
{fileMenu} {fileMenu}
</Box> </Box>
<Paper <Paper
onKeyUp={handleKeyUp}
onKeyDown={handleKeyDown}
sx={{ sx={{
height: 'calc(100vh - 170px)', height: 'calc(100vh - 170px)',
padding: '10px', padding: '10px',

View File

@@ -42,7 +42,6 @@ const useEditor = ({
const [prevFileContent, setPrevFileContent] = useStateWithCallback('') const [prevFileContent, setPrevFileContent] = useStateWithCallback('')
const [fileContent, setFileContent] = useState('') const [fileContent, setFileContent] = useState('')
const [log, setLog] = useState('') const [log, setLog] = useState('')
const [ctrlPressed, setCtrlPressed] = useState(false)
const [webout, setWebout] = useState('') const [webout, setWebout] = useState('')
const [runTimes, setRunTimes] = useState<string[]>([]) const [runTimes, setRunTimes] = useState<string[]>([])
const [selectedRunTime, setSelectedRunTime] = useState('') const [selectedRunTime, setSelectedRunTime] = useState('')
@@ -148,53 +147,47 @@ const useEditor = ({
const handleRunBtnClick = () => const handleRunBtnClick = () =>
runCode(getSelection(editorRef.current as any) || fileContent) runCode(getSelection(editorRef.current as any) || fileContent)
const runCode = (code: string) => { const runCode = useCallback(
setIsLoading(true) (code: string) => {
axios setIsLoading(true)
.post(`/SASjsApi/code/execute`, { axios
code: programPathInjection( .post(`/SASjsApi/code/execute`, {
code, code: programPathInjection(
selectedFilePath, code,
selectedRunTime as RunTimeType selectedFilePath,
), selectedRunTime as RunTimeType
runTime: selectedRunTime ),
}) runTime: selectedRunTime
.then((res: any) => { })
setWebout(res.data.split(SASJS_LOGS_SEPARATOR)[0] ?? '') .then((res: any) => {
setLog(res.data.split(SASJS_LOGS_SEPARATOR)[1] ?? '') setWebout(res.data.split(SASJS_LOGS_SEPARATOR)[0] ?? '')
setTab('log') setLog(res.data.split(SASJS_LOGS_SEPARATOR)[1] ?? '')
setTab('log')
// Scroll to bottom of log // Scroll to bottom of log
const logElement = document.getElementById('log') const logElement = document.getElementById('log')
if (logElement) logElement.scrollTop = logElement.scrollHeight if (logElement) logElement.scrollTop = logElement.scrollHeight
}) })
.catch((err) => { .catch((err) => {
setModalTitle('Abort') setModalTitle('Abort')
setModalPayload( setModalPayload(
typeof err.response.data === 'object' typeof err.response.data === 'object'
? JSON.stringify(err.response.data) ? JSON.stringify(err.response.data)
: err.response.data : err.response.data
) )
setOpenModal(true) setOpenModal(true)
}) })
.finally(() => setIsLoading(false)) .finally(() => setIsLoading(false))
} },
[
const handleKeyDown = (event: any) => { selectedFilePath,
if (event.ctrlKey) { selectedRunTime,
if (event.key === 'v') { setModalPayload,
setCtrlPressed(false) setModalTitle,
} setOpenModal,
setTab
if (event.key === 'Enter') ]
runCode(getSelection(editorRef.current as any) || fileContent) )
if (!ctrlPressed) setCtrlPressed(true)
}
}
const handleKeyUp = (event: any) => {
if (!event.ctrlKey && ctrlPressed) setCtrlPressed(false)
}
const handleChangeRunTime = (event: SelectChangeEvent) => { const handleChangeRunTime = (event: SelectChangeEvent) => {
setSelectedRunTime(event.target.value as RunTimeType) setSelectedRunTime(event.target.value as RunTimeType)
@@ -223,7 +216,28 @@ const useEditor = ({
if (prevFileContent !== fileContent) return saveFile() if (prevFileContent !== fileContent) return saveFile()
} }
}) })
}, [fileContent, prevFileContent, selectedFilePath, saveFile])
editorRef.current.addAction({
// An unique identifier of the contributed action.
id: 'run-code',
// A label of the action that will be presented to the user.
label: 'Run Code',
// An optional array of keybindings for the action.
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
contextMenuGroupId: 'navigation',
contextMenuOrder: 1,
// Method that will be executed when the action is triggered.
// @param editor The editor instance is passed in as a convenience
run: function () {
runCode(getSelection(editorRef.current as any) || fileContent)
}
})
}, [fileContent, prevFileContent, selectedFilePath, saveFile, runCode])
useEffect(() => { useEffect(() => {
setRunTimes(Object.values(appContext.runTimes)) setRunTimes(Object.values(appContext.runTimes))
@@ -277,7 +291,6 @@ const useEditor = ({
}, [selectedFileExtension, runTimes]) }, [selectedFileExtension, runTimes])
return { return {
ctrlPressed,
fileContent, fileContent,
isLoading, isLoading,
log, log,
@@ -293,8 +306,6 @@ const useEditor = ({
handleDiffEditorDidMount, handleDiffEditorDidMount,
handleEditorDidMount, handleEditorDidMount,
handleFilePathInput, handleFilePathInput,
handleKeyDown,
handleKeyUp,
handleRunBtnClick, handleRunBtnClick,
handleTabChange, handleTabChange,
saveFile, saveFile,