mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 19:34:34 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a6b972c65 | ||
|
|
be11707042 | ||
| 2412622367 | |||
|
|
de3a190a8d | ||
|
|
d5daafc6ed | ||
|
|
b1a2677b8c | ||
|
|
94072c3d24 | ||
|
|
b64c0c12da | ||
|
|
79bc7b0e28 | ||
|
|
fda0e0b57d | ||
|
|
14731e8824 | ||
|
|
258cc35f14 | ||
|
|
2295a518f0 | ||
|
|
1e5d621817 | ||
| 4d64420c45 |
30
CHANGELOG.md
30
CHANGELOG.md
@@ -1,3 +1,33 @@
|
|||||||
|
## [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)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* ldap issues ([4d64420](https://github.com/sasjs/server/commit/4d64420c45424134b4d2014a2d5dd6e846ed03b3))
|
||||||
|
|
||||||
# [0.23.0](https://github.com/sasjs/server/compare/v0.22.1...v0.23.0) (2022-10-03)
|
# [0.23.0](https://github.com/sasjs/server/compare/v0.22.1...v0.23.0) (2022-10-03)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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,7 +15,7 @@ HELMET_COEP=[true|false] if omitted HELMET default will be used
|
|||||||
|
|
||||||
DB_CONNECT=mongodb+srv://<DB_USERNAME>:<DB_PASSWORD>@<CLUSTER>/<DB_NAME>?retryWrites=true&w=majority
|
DB_CONNECT=mongodb+srv://<DB_USERNAME>:<DB_PASSWORD>@<CLUSTER>/<DB_NAME>?retryWrites=true&w=majority
|
||||||
|
|
||||||
AUTH_PROVIDERS=[ldap|internal] default considered as internal
|
AUTH_PROVIDERS=[ldap]
|
||||||
|
|
||||||
LDAP_URL= <LDAP_SERVER_URL>
|
LDAP_URL= <LDAP_SERVER_URL>
|
||||||
LDAP_BIND_DN= <cn=admin,ou=system,dc=cloudron>
|
LDAP_BIND_DN= <cn=admin,ou=system,dc=cloudron>
|
||||||
|
|||||||
14
api/package-lock.json
generated
14
api/package-lock.json
generated
@@ -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",
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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!')
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ const updateUsersListInGroup = async (
|
|||||||
message: `Can't add/remove user to '${PUBLIC_GROUP_NAME}' group.`
|
message: `Can't add/remove user to '${PUBLIC_GROUP_NAME}' group.`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group.authProvider !== AuthProviderType.Internal)
|
if (group.authProvider)
|
||||||
throw {
|
throw {
|
||||||
code: 405,
|
code: 405,
|
||||||
status: 'Method Not Allowed',
|
status: 'Method Not Allowed',
|
||||||
@@ -266,7 +266,7 @@ const updateUsersListInGroup = async (
|
|||||||
message: 'User not found.'
|
message: 'User not found.'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.authProvider !== AuthProviderType.Internal)
|
if (user.authProvider)
|
||||||
throw {
|
throw {
|
||||||
code: 405,
|
code: 405,
|
||||||
status: 'Method Not Allowed',
|
status: 'Method Not Allowed',
|
||||||
|
|||||||
@@ -299,14 +299,19 @@ const updateUser = async (
|
|||||||
|
|
||||||
const user = await User.findOne(findBy)
|
const user = await User.findOne(findBy)
|
||||||
|
|
||||||
if (
|
if (username && username !== user?.username && user?.authProvider) {
|
||||||
user?.authProvider !== AuthProviderType.Internal &&
|
|
||||||
(username !== user?.username || displayName !== user?.displayName)
|
|
||||||
) {
|
|
||||||
throw {
|
throw {
|
||||||
code: 405,
|
code: 405,
|
||||||
message:
|
message:
|
||||||
'Can not update username and display name of user that is created by an external auth provider.'
|
'Can not update username of user that is created by an external auth provider.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (displayName && displayName !== user?.displayName && user?.authProvider) {
|
||||||
|
throw {
|
||||||
|
code: 405,
|
||||||
|
message:
|
||||||
|
'Can not update display name of user that is created by an external auth provider.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,8 +50,7 @@ const groupSchema = new Schema<IGroupDocument>({
|
|||||||
},
|
},
|
||||||
authProvider: {
|
authProvider: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: AuthProviderType,
|
enum: AuthProviderType
|
||||||
default: 'internal'
|
|
||||||
},
|
},
|
||||||
isActive: {
|
isActive: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ const userSchema = new Schema<IUserDocument>({
|
|||||||
},
|
},
|
||||||
authProvider: {
|
authProvider: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: AuthProviderType,
|
enum: AuthProviderType
|
||||||
default: 'internal'
|
|
||||||
},
|
},
|
||||||
isAdmin: {
|
isAdmin: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|||||||
@@ -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>`
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ export enum ModeType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum AuthProviderType {
|
export enum AuthProviderType {
|
||||||
LDAP = 'ldap',
|
LDAP = 'ldap'
|
||||||
Internal = 'internal'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ProtocolType {
|
export enum ProtocolType {
|
||||||
@@ -111,7 +110,7 @@ const verifyMODE = (): string[] => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.MODE === ModeType.Server) {
|
if (process.env.MODE === ModeType.Server) {
|
||||||
const { DB_CONNECT, AUTH_MECHANISM } = process.env
|
const { DB_CONNECT, AUTH_PROVIDERS } = process.env
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'test') {
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
if (!DB_CONNECT)
|
if (!DB_CONNECT)
|
||||||
@@ -119,14 +118,12 @@ const verifyMODE = (): string[] => {
|
|||||||
`- DB_CONNECT is required for PROTOCOL '${ModeType.Server}'`
|
`- DB_CONNECT is required for PROTOCOL '${ModeType.Server}'`
|
||||||
)
|
)
|
||||||
|
|
||||||
if (AUTH_MECHANISM) {
|
if (AUTH_PROVIDERS) {
|
||||||
const authMechanismTypes = Object.values(AuthProviderType)
|
const authProvidersType = Object.values(AuthProviderType)
|
||||||
if (!authMechanismTypes.includes(AUTH_MECHANISM as AuthProviderType))
|
if (!authProvidersType.includes(AUTH_PROVIDERS as AuthProviderType))
|
||||||
errors.push(
|
errors.push(
|
||||||
`- AUTH_MECHANISM '${AUTH_MECHANISM}'\n - valid options ${authMechanismTypes}`
|
`- AUTH_PROVIDERS '${AUTH_PROVIDERS}'\n - valid options ${authProvidersType}`
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
process.env.AUTH_MECHANISM = DEFAULTS.AUTH_MECHANISM
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -270,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
|
||||||
@@ -307,37 +304,37 @@ const verifyLDAPVariables = () => {
|
|||||||
LDAP_USERS_BASE_DN,
|
LDAP_USERS_BASE_DN,
|
||||||
LDAP_GROUPS_BASE_DN,
|
LDAP_GROUPS_BASE_DN,
|
||||||
MODE,
|
MODE,
|
||||||
AUTH_MECHANISM
|
AUTH_PROVIDERS
|
||||||
} = process.env
|
} = process.env
|
||||||
|
|
||||||
if (MODE === ModeType.Server && AUTH_MECHANISM === AuthProviderType.LDAP) {
|
if (MODE === ModeType.Server && AUTH_PROVIDERS === AuthProviderType.LDAP) {
|
||||||
if (!LDAP_URL) {
|
if (!LDAP_URL) {
|
||||||
errors.push(
|
errors.push(
|
||||||
`- LDAP_URL is required for AUTH_MECHANISM '${AuthProviderType.LDAP}'`
|
`- LDAP_URL is required for AUTH_PROVIDER '${AuthProviderType.LDAP}'`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LDAP_BIND_DN) {
|
if (!LDAP_BIND_DN) {
|
||||||
errors.push(
|
errors.push(
|
||||||
`- LDAP_BIND_DN is required for AUTH_MECHANISM '${AuthProviderType.LDAP}'`
|
`- LDAP_BIND_DN is required for AUTH_PROVIDER '${AuthProviderType.LDAP}'`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LDAP_BIND_PASSWORD) {
|
if (!LDAP_BIND_PASSWORD) {
|
||||||
errors.push(
|
errors.push(
|
||||||
`- LDAP_BIND_PASSWORD is required for AUTH_MECHANISM '${AuthProviderType.LDAP}'`
|
`- LDAP_BIND_PASSWORD is required for AUTH_PROVIDER '${AuthProviderType.LDAP}'`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LDAP_USERS_BASE_DN) {
|
if (!LDAP_USERS_BASE_DN) {
|
||||||
errors.push(
|
errors.push(
|
||||||
`- LDAP_USERS_BASE_DN is required for AUTH_MECHANISM '${AuthProviderType.LDAP}'`
|
`- LDAP_USERS_BASE_DN is required for AUTH_PROVIDER '${AuthProviderType.LDAP}'`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LDAP_GROUPS_BASE_DN) {
|
if (!LDAP_GROUPS_BASE_DN) {
|
||||||
errors.push(
|
errors.push(
|
||||||
`- LDAP_GROUPS_BASE_DN is required for AUTH_MECHANISM '${AuthProviderType.LDAP}'`
|
`- LDAP_GROUPS_BASE_DN is required for AUTH_PROVIDER '${AuthProviderType.LDAP}'`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,7 +344,6 @@ const verifyLDAPVariables = () => {
|
|||||||
|
|
||||||
const DEFAULTS = {
|
const DEFAULTS = {
|
||||||
MODE: ModeType.Desktop,
|
MODE: ModeType.Desktop,
|
||||||
AUTH_MECHANISM: AuthProviderType.Internal,
|
|
||||||
PROTOCOL: ProtocolType.HTTP,
|
PROTOCOL: ProtocolType.HTTP,
|
||||||
PORT: '5000',
|
PORT: '5000',
|
||||||
HELMET_COEP: HelmetCoepType.TRUE,
|
HELMET_COEP: HelmetCoepType.TRUE,
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user