@sassoftware/viya-serverjs 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/.babelrc +6 -6
  2. package/.dockerignore +2 -2
  3. package/.env +42 -28
  4. package/.env.server +32 -30
  5. package/.eslintignore +3 -3
  6. package/.eslintrc.json +42 -42
  7. package/Dockerfile +44 -44
  8. package/README.md +67 -99
  9. package/cli.js +9 -9
  10. package/lib/config.js +16 -16
  11. package/lib/handlers/appCallback.js +23 -24
  12. package/lib/handlers/codeAuth.js +17 -18
  13. package/lib/handlers/decodeJwt.js +3 -3
  14. package/lib/handlers/favicon.js +22 -25
  15. package/lib/handlers/getApp.js +20 -21
  16. package/lib/handlers/getApp2.js +22 -25
  17. package/lib/handlers/getUser.js +14 -17
  18. package/lib/handlers/index.js +3 -3
  19. package/lib/handlers/keepAlive.js +28 -31
  20. package/lib/handlers/keepAlive2.js +9 -12
  21. package/lib/handlers/logon.js +12 -15
  22. package/lib/handlers/logout.js +24 -28
  23. package/lib/handlers/proxyMapUri.js +6 -11
  24. package/lib/handlers/proxyOnResponse.js +6 -7
  25. package/lib/handlers/reactDev.js +22 -25
  26. package/lib/handlers/setCookies.js +51 -53
  27. package/lib/iService.js +105 -103
  28. package/lib/index.js +25 -30
  29. package/lib/parseDocker.js +3 -3
  30. package/lib/plugins/SASauth.js +34 -34
  31. package/lib/plugins/appCookie.js +35 -38
  32. package/lib/plugins/setContext.js +22 -25
  33. package/lib/plugins/setDefaultRoutes.js +71 -59
  34. package/lib/plugins/setupAuth.js +35 -38
  35. package/lib/plugins/setupUserRoutes.js +17 -16
  36. package/lib/plugins/token.js +9 -10
  37. package/lib/schemes/SASTokenScheme.js +24 -27
  38. package/mcpServer.js +364 -0
  39. package/package.json +85 -79
  40. package/public/data/Cluster_SDOH1.sas +181 -181
  41. package/public/data/Cluster_SDOH6.sas +179 -179
  42. package/public/data/NeuralNetwork_High_med.sas +2408 -2408
  43. package/public/data/NeuralNetwork_high_med1.sas +2408 -2408
  44. package/public/data/cars.csv +429 -429
  45. package/public/data/cmdList.txt +15 -15
  46. package/public/data/iris.csv +151 -151
  47. package/public/index.html +360 -350
  48. package/public/indexProxy.html +351 -351
  49. package/public/simplesubmit.html +233 -0
  50. package/server.js +363 -362
  51. package/src/config.js +90 -90
  52. package/src/handlers/appCallback.js +40 -40
  53. package/src/handlers/codeAuth.js +31 -31
  54. package/src/handlers/decodeJwt.js +10 -10
  55. package/src/handlers/favicon.js +23 -23
  56. package/src/handlers/getApp.js +52 -52
  57. package/src/handlers/getApp2.js +25 -25
  58. package/src/handlers/getUser.js +20 -20
  59. package/src/handlers/index.js +36 -36
  60. package/src/handlers/keepAlive.js +53 -53
  61. package/src/handlers/keepAlive2.js +12 -12
  62. package/src/handlers/logon.js +23 -23
  63. package/src/handlers/logout.js +42 -42
  64. package/src/handlers/proxyMapUri.js +25 -25
  65. package/src/handlers/proxyOnResponse.js +11 -11
  66. package/src/handlers/reactDev.js +29 -29
  67. package/src/handlers/setCookies.js +80 -79
  68. package/src/iService.js +360 -345
  69. package/src/index.js +247 -249
  70. package/src/parseDocker.js +32 -32
  71. package/src/plugins/SASauth.js +82 -78
  72. package/src/plugins/appCookie.js +50 -49
  73. package/src/plugins/setContext.js +33 -33
  74. package/src/plugins/setDefaultRoutes.js +261 -253
  75. package/src/plugins/setupAuth.js +49 -49
  76. package/src/plugins/setupUserRoutes.js +48 -47
  77. package/src/plugins/token.js +10 -10
  78. package/src/schemes/SASTokenScheme.js +43 -43
  79. package/src/visionIndex.html +23 -23
  80. package/start.sh +14 -14
  81. package/.env.proxy +0 -32
  82. package/tls/viyatls.sh +0 -3
package/.babelrc CHANGED
@@ -1,6 +1,6 @@
1
- {
2
- "presets": [
3
- "@babel/preset-env"
4
- ]
5
-
6
- }
1
+ {
2
+ "presets": [
3
+ "@babel/preset-env"
4
+ ]
5
+
6
+ }
package/.dockerignore CHANGED
@@ -1,2 +1,2 @@
1
- node_modules
2
-
1
+ node_modules
2
+
package/.env CHANGED
@@ -1,28 +1,42 @@
1
- APPHOST=localhost
2
- APPENTRY=index.html
3
- APPLOC=./public
4
- # VIYA_SERVER=
5
- # VIYA_SERVER=none
6
- APPPORT=8080
7
- APPNAME=viyaapp
8
- AUTHFLOW=server
9
- CLIENTID=viyaapp
10
- CLIENTSECRET=jellico
11
- REDIRECT=
12
- # APPDIR=./appDir
13
- HTTPS=true
14
-
15
-
16
- USETOKEN=YES
17
- SHOWENV=YES
18
-
19
- APPENV_XYZ=AA
20
- APPENV_BAD=
21
-
22
- # APPENV_PUPID=NSHOST=https://sas-logon-app.viya.svc.cluster.local
23
-
24
- # NAMESPACE=viya
25
-
26
-
27
-
28
-
1
+ APPHOST=localhost
2
+ # APPENTRY=index.html
3
+ APPLOC=./public
4
+ # VIYA_SERVER=your viya server
5
+
6
+ APPPORT=8080
7
+ APPNAME=viyaapp
8
+ AUTHFLOW=code
9
+ CLIENTID=viyaapp
10
+ CLIENTSECRET=jellico
11
+
12
+ REDIRECT=
13
+ # APPDIR=./appDir
14
+ HTTPS=true
15
+
16
+
17
+ # Most modern browsers do not accept self-signed certs from localhost
18
+ # Options:
19
+
20
+ # 1. provide signed certificates for localhost
21
+ # 2. Use libraries like mkcert to create temporary trusted certs for localhost
22
+ # 3. Use the app server as a proxy to the Viya server to avoid CORS issues.
23
+ # This requires that the app redirect all Viya API calls to the app server proxy endpoint
24
+ # Users of restaf can simply set the APPENV_PROXY env to TRUE to enable this behavior
25
+ # 4. set USETOKEN to TRUE and use the token in the APPENV object to make the calls
26
+ // either use the proper ssl/tsl certs or use the "proxy" method
27
+ // to avoid CORS issues with self-signed certs
28
+ // so run all apps thru the proxy and call Viya from there
29
+ APPENV_PROXY=false
30
+
31
+
32
+ # APPENV_PROXYSERVER=true
33
+ # USETOKEN=true
34
+ SHOWENV=true
35
+
36
+ APPENV_XYZ=AA
37
+ APPENV_BAD=
38
+
39
+
40
+
41
+
42
+
package/.env.server CHANGED
@@ -1,30 +1,32 @@
1
- APPHOST=localhost
2
- APPENTRY=index.html
3
- APPLOC=./public
4
- VIYA_SERVER=
5
- APPENV_PROXYSERVER=https://localhost:8080/viyaapp/proxy
6
- APPPORT=8080
7
- APPNAME=viyaapp
8
- AUTHFLOW=server
9
- CLIENTID=viyaapp
10
- CLIENTSECRET=jellico
11
- REDIRECT=/new
12
- # APPDIR=./appDir
13
- # HTTPS=true
14
- USELOGON=YES
15
-
16
-
17
- USETOKEN=YES
18
- # SHOWENV=YES
19
- # APPENV=
20
- APPENV_XYZ=AA
21
- APPENV_BAD=
22
-
23
-
24
-
25
- # NAMESPACE=viya
26
- # TLS_CERT=./certs/tls.crt
27
- # TLS_KEY=./certs/tls.key
28
-
29
-
30
-
1
+ APPHOST=localhost
2
+ APPENTRY=index.html
3
+ APPLOC=./public
4
+ # viya-server set preset
5
+ # VIYA_SERVER=
6
+ APPENV_PROXYSERVER=https://localhost:8080/viyaapp/proxy
7
+
8
+ APPPORT=8080
9
+ APPNAME=viyaapp
10
+ AUTHFLOW=server
11
+ CLIENTID=viyaapp
12
+ CLIENTSECRET=jellico
13
+ REDIRECT=/new
14
+ # APPDIR=./appDir
15
+ # HTTPS=true
16
+ USELOGON=YES
17
+
18
+
19
+ USETOKEN=YES
20
+ # SHOWENV=YES
21
+ # APPENV=
22
+ APPENV_XYZ=AA
23
+ APPENV_BAD=
24
+
25
+
26
+
27
+ # NAMESPACE=viya
28
+ # TLS_CERT=./certs/tls.crt
29
+ # TLS_KEY=./certs/tls.key
30
+
31
+
32
+
package/.eslintignore CHANGED
@@ -1,4 +1,4 @@
1
- node_modules
2
- public
3
- env
1
+ node_modules
2
+ public
3
+ env
4
4
  lib
package/.eslintrc.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "root": true,
3
- "env": {
4
- "browser": true,
5
- "node": true,
6
- "es6": true
7
- },
8
- "parser": "@babel/eslint-parser",
9
- "extends": ["eslint:recommended", "prettier"],
10
- "parserOptions": {
11
- "requireConfigFile": false,
12
- "babelOptions": {"configFile": "./.babelrc"},
13
- "ecmaVersion": 6,
14
- "sourceType": "module",
15
- "ecmaFeatures": {
16
- "jsx": true
17
- }
18
- },
19
- "rules": {
20
- "key-spacing": [
21
- 2,
22
- {
23
- "align": "colon"
24
- }
25
- ],
26
- "jsx-quotes": [2, "prefer-double"],
27
- "no-console": 0,
28
- "no-unused-vars": [
29
- 1,
30
- {
31
- "args": "none"
32
- }
33
- ],
34
- "no-debugger": 0,
35
- "react/prop-types": 0,
36
- "array-bracket-spacing": [2, "never"],
37
- "space-in-parens": [2, "never"],
38
- "space-before-function-paren": [2, "always"],
39
- "semi": [2, "always"],
40
- "no-prototype-builtins": 0
41
- }
42
- }
1
+ {
2
+ "root": true,
3
+ "env": {
4
+ "browser": true,
5
+ "node": true,
6
+ "es6": true
7
+ },
8
+ "parser": "@babel/eslint-parser",
9
+ "extends": ["eslint:recommended", "prettier"],
10
+ "parserOptions": {
11
+ "requireConfigFile": false,
12
+ "babelOptions": {"configFile": "./.babelrc"},
13
+ "ecmaVersion": 6,
14
+ "sourceType": "module",
15
+ "ecmaFeatures": {
16
+ "jsx": true
17
+ }
18
+ },
19
+ "rules": {
20
+ "key-spacing": [
21
+ 2,
22
+ {
23
+ "align": "colon"
24
+ }
25
+ ],
26
+ "jsx-quotes": [2, "prefer-double"],
27
+ "no-console": 0,
28
+ "no-unused-vars": [
29
+ 1,
30
+ {
31
+ "args": "none"
32
+ }
33
+ ],
34
+ "no-debugger": 0,
35
+ "react/prop-types": 0,
36
+ "array-bracket-spacing": [2, "never"],
37
+ "space-in-parens": [2, "never"],
38
+ "space-before-function-paren": [2, "always"],
39
+ "semi": [2, "always"],
40
+ "no-prototype-builtins": 0
41
+ }
42
+ }
package/Dockerfile CHANGED
@@ -1,44 +1,44 @@
1
- FROM node:12.16.1-alpine
2
- LABEL maintainer="deva.kumar@sas.com"
3
- WORKDIR /usr/src/app
4
- COPY . .
5
- # COPY package*.json ./
6
- RUN npm install
7
- # RUN npm run build
8
-
9
- # will auto change to localhost in non-docker environments
10
- ENV APPHOST=0.0.0.0
11
- ENV PORT=8080
12
- EXPOSE 8080
13
- ENV HTTPS=true
14
- # ENV APPSERVERLEVEL=v2
15
- #######################################################################
16
- # You can override these(but in container leave APPHOST as shown below)
17
- ########################################################################
18
-
19
- # set this the same as EXPOSE here and override in env or as -p option in dockerrun
20
- # ENV APPPORT=8080
21
-
22
- ENV APPNAME=viyaapp
23
- # ENV AUTHFLOW=
24
- ENV CLIENTID=viyaapp
25
- ENV CLIENTSECRET=jellico
26
- ENV HAPIDEBUG=NO
27
- # ENV LOGLEVEL=info
28
- # ENV USETOKEN=YES
29
-
30
- #sample setup for creating a temporary cert and key
31
- ENV TLS_CREATE="C:US,ST:NC,L:Cary,O:SAS Institute,OU:STO,CN:localhost"
32
-
33
- # You can specify your own cet and key
34
- # ENV TLS_CRT=./tls/tls.crt
35
- # ENV TLS_KEY=./tls/tls.key
36
-
37
- # Samesite specification
38
- ENV SAMESITE=None,secure
39
-
40
- # If your Viya instance still has a unsigned certificate set this value prior to invoking the server
41
- # ENV NODE_TLS_REJECT_UNAUTHORIZED=0
42
-
43
- #####################################################################
44
- CMD ["npm", "run", "indocker"]
1
+ FROM node:12.16.1-alpine
2
+ LABEL maintainer="deva.kumar@sas.com"
3
+ WORKDIR /usr/src/app
4
+ COPY . .
5
+ # COPY package*.json ./
6
+ RUN npm install
7
+ # RUN npm run build
8
+
9
+ # will auto change to localhost in non-docker environments
10
+ ENV APPHOST=0.0.0.0
11
+ ENV PORT=8080
12
+ EXPOSE 8080
13
+ ENV HTTPS=true
14
+ ENV VIYA_SERVER=
15
+ # ENV APPSERVERLEVEL=v2
16
+ #######################################################################
17
+ # You can override these(but in container leave APPHOST as shown below)
18
+ ########################################################################
19
+
20
+ # set this the same as EXPOSE here and override in env or as -p option in dockerrun
21
+ # ENV APPPORT=8080
22
+
23
+ ENV APPNAME=viyaapp
24
+ ENV AUTHFLOW=server
25
+ ENV CLIENTID=viyaapp
26
+ ENV CLIENTSECRET=
27
+ # ENV HAPIDEBUG=NO
28
+ # ENV LOGLEVEL=info
29
+ # ENV USETOKEN=YES
30
+
31
+ # specify ssl/tls cert and key in a folder
32
+ # example below
33
+ ENV SSLCERT=c:/Users/kumar/.tls
34
+ #sample setup for creating a temporary cert and key
35
+ ENV TLS_CREATE="C:US,ST:NC,L:Cary,O:SAS Institute,OU:STO,CN:localhost"
36
+
37
+ # Samesite specification
38
+ ENV SAMESITE=None,secure
39
+
40
+ # If your Viya instance still has a unsigned certificate set this value prior to invoking the server
41
+ # ENV NODE_TLS_REJECT_UNAUTHORIZED=0
42
+
43
+ #####################################################################
44
+ CMD ["npm", "run", "indocker"]
package/README.md CHANGED
@@ -1,99 +1,67 @@
1
- # `Application servers for use with SAS Viya`
2
-
3
- This package has two servers:
4
-
5
- 1. viya-appserverjs - Use this for developing an app server for web applications(see packages/appjs)
6
-
7
- 2. viya-apiserverjs - Use this to develop rest api servers(see packages/apijs)
8
-
9
- ## Usage
10
-
11
- Specify it as a dependency in your package.json just as you do with other dependencies
12
-
13
- Use npx command to start the server
14
-
15
- ```sh
16
- npx @sassoftware/viyaappserverjs
17
- ```
18
-
19
- ## `Basic configuration`
20
-
21
- 1. Set the default settings in Dockerfile. This will ensure these are set when you build containers.
22
- 2. The defaults can be overriden using environment variables.
23
-
24
- ### `Sample env file`
25
-
26
- When running on a non-docker environment, you can use a .env
27
-
28
- ```env
29
- VIYA_SERVER=<your viya server>
30
- APPHOST=localhost < can also be dns name of your server. ex: viyaiscool.unx.sas.com>
31
- APPPORT=5000 <any port of your choice>
32
- APPNAME=viyaapp
33
-
34
- CLIENTID=viyaapp
35
- CLIENTSECRET=secret
36
- ```
37
-
38
- ### `Sample Dockerfile`
39
-
40
- ```env
41
- FROM node:12.16.1-alpine
42
- LABEL maintainer="your email"
43
- WORKDIR /usr/src/app
44
- COPY . .
45
- RUN npm install
46
- # RUN npm run build (if you have to build something)
47
- EXPOSE 8080
48
- ENV APPHOST=0.0.0.0
49
-
50
- AUTHFLOW=code
51
-
52
- # The following are defaults. Override them as needed
53
- # APPLOC - where the file specified in APPENTRY is
54
- # APPENTRY - the main entry of the application
55
- ENV APPLOC=./public
56
- ENV APPENTRY=index.html
57
- # if your app takes advantage of appenv.js to pass configuration to the web application
58
- # ENV APPENV=appenv.js
59
-
60
- # See notes below on running with SSL enabled
61
- ENV TLS_CREATE="C:US,ST:NC,L:Cary,O:yourcompany,OU:STO,CN:localhost"
62
- ENV SAMESITE=None,secure
63
-
64
- # It is better to set this before invoking the server
65
- ENV NODE_TLS_REJECT_UNAUTHORIZED=0
66
-
67
- # set this to YES if you want access to the authentication token in the app
68
- ENV USETOKEN=NO
69
-
70
- CMD ["npx", "@sassoftware/viya-appserverjs"]
71
-
72
- ```
73
-
74
- ### `Running with SSL enabled -- Recommended`
75
-
76
- This is the recommended setting. This will also make browsers like Chrome run with the SAMESITE settings set to Default - your users will thank you.
77
-
78
- Make sure you specify the VIYA_SERVER with a protocol of https.
79
-
80
- ### `TLS certificates`
81
-
82
- - Option 1: Let server create a temporary unsigned certificate
83
-
84
- ```env
85
- ENV TLS_CREATE=C:US,ST:NC,L:Cary,O:YourCompany,OU:yourgroup,CN:localhost
86
- ```
87
-
88
- - Option 2: Provide your own key and certificate key
89
-
90
- ```env
91
- ENV TLS_KEY=../certs/self/key.pem
92
- ENV TLS_CERT=../certs/self/certificate.pem
93
- ```
94
-
95
- - Option 3: Provide key and certificate as a pfx file
96
-
97
- ```env
98
- ENV TLS_PFX=../certs/sascert/sascert2.pfx
99
- ```
1
+ # `Application server for use with SAS Viya`
2
+
3
+ viya-serverjs is a app server designed to support user written SAS Viya applications. The applications can be written using any framework.
4
+
5
+ Key features:
6
+
7
+ 1. Handles authentication
8
+ 2. Extendable with additional end points
9
+
10
+ ## Usage
11
+
12
+ Use npx command to start the server
13
+
14
+ ```sh
15
+ npx @sassoftware/viya-serverjs
16
+ ```
17
+
18
+ ## `Basic configuration`
19
+
20
+ Configure the server using a .env file
21
+
22
+ ### `Sample env file`
23
+
24
+ >[Note] Sample values shown below. See Advanced section for other ways to configure the server
25
+
26
+ ```env
27
+
28
+ # Base setup
29
+ # With the configuration below the app server url will be
30
+ # https://localhost:8080/viyaapp
31
+ #
32
+ APPHOST=localhost
33
+ APPPORT=8080
34
+ HTTPS=true
35
+ APPNAME=viyaapp
36
+
37
+ # Most modern browsers will reject self-signed certs from localhost
38
+ # And SAS Viya might also refuse connection.
39
+ # Supply your own SSL/TLS values in a folder. All files in this folder will be used.
40
+ # Options:
41
+ # 1. provide signed certificates for localhost
42
+ # 2. Use libraries like mkcert to create temporary trusted certs for localhost
43
+ # 3. For other options see the Advanced Section
44
+ SSLCERT=./tls
45
+
46
+ # AUTHENTICATION
47
+ VIYA_SERVER=<viya servrer url>
48
+
49
+ # By default it uses authorization_code flow
50
+
51
+ CLIENTID=<clientid>
52
+ CLIENTSECRET=<clientSecret if present>
53
+ AUTHFLOW=code|pkce
54
+
55
+ ##########################
56
+ # Read the Advanced Section in the README before turning on these options
57
+ #
58
+ APPENV_PROXY=false
59
+ USETOKEN=false
60
+
61
+ APPENV_A=somevalue
62
+ APPENV_B=somevalue
63
+
64
+ ```
65
+
66
+
67
+
package/cli.js CHANGED
@@ -1,9 +1,9 @@
1
- #!/usr/bin/env node
2
- /*
3
- * Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- let core = require('./lib/index.js');
8
- console.log('Starting the cli for @sassoftware/viya-serverjs');
9
- core(null, true, 'app', null);
1
+ #!/usr/bin/env node
2
+ /*
3
+ * Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ let core = require('./lib/index.js');
8
+ console.log('Starting the cli for @sassoftware/viya-serverjs');
9
+ core(null, true, 'app', null);
package/lib/config.js CHANGED
@@ -1,19 +1,19 @@
1
- /*
2
- * ------------------------------------------------------------------------------------
3
- * * Copyright (c) SAS Institute Inc.
4
- * * Licensed under the Apache License, Version 2.0 (the "License");
5
- * * you may not use this file except in compliance with the License.
6
- * * You may obtain a copy of the License at
7
- * *
8
- * * http://www.apache.org/licenses/LICENSE-2.0
9
- * *
10
- * * Unless required by applicable law or agreed to in writing, software
11
- * * distributed under the License is distributed on an "AS IS" BASIS,
12
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- * ----------------------------------------------------------------------------------------
16
- *
1
+ /*
2
+ * ------------------------------------------------------------------------------------
3
+ * * Copyright (c) SAS Institute Inc.
4
+ * * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * * you may not use this file except in compliance with the License.
6
+ * * You may obtain a copy of the License at
7
+ * *
8
+ * * http://www.apache.org/licenses/LICENSE-2.0
9
+ * *
10
+ * * Unless required by applicable law or agreed to in writing, software
11
+ * * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ * ----------------------------------------------------------------------------------------
16
+ *
17
17
  */
18
18
 
19
19
  'use strict';