@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/src/index.js CHANGED
@@ -1,249 +1,247 @@
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
- */
18
-
19
- import "core-js/stable";
20
- import "regenerator-runtime/runtime";
21
- import fs from "fs";
22
- import iService from "./iService";
23
- import config from "./config";
24
- let debug = require("debug")("startup");
25
-
26
- module.exports = function core(
27
- uTable,
28
- useDefault,
29
- serverMode,
30
- customize,
31
- swaggerfcn
32
- ) {
33
- let argv = require("yargs").argv;
34
- let env = argv.env == null ? null : argv.env;
35
- let appenv = argv.appenv == null ? null : argv.appenv;
36
- let docker = argv.docker == null ? null : argv.docker;
37
- //process.env.SERVERMODE = serverMode !== null ? "api" : "app";
38
-
39
-
40
- if (useDefault == null) {
41
- useDefault = true;
42
- }
43
- console.log(
44
- "Initialization started ============================================================"
45
- );
46
- console.log(`version: 2, Build Date: `, Date());
47
- console.log(
48
- `\nCommand Line Configuration:
49
- Dockerfile: ${docker}
50
- env file : ${env}
51
- appenv : ${appenv}
52
- customize : ${customize != null}
53
- `
54
- );
55
-
56
- iapp(null, env, docker, uTable, useDefault, serverMode, customize);
57
- };
58
-
59
- function iapp(
60
- appSrc,
61
- rafEnv,
62
- dockerFile,
63
- uTable,
64
- useDefault,
65
- serverMode,
66
- customize
67
- ) {
68
- let asset = setup(rafEnv, dockerFile);
69
- if (appSrc == null) {
70
- appSrc = process.env.APPENV == null ? null : process.env.APPENV;
71
- }
72
- if (appSrc != null) {
73
- console.log("appSrc", `+${appSrc}+`);
74
- createPayload(appSrc, (err, r) => {
75
- if (err) {
76
- console.log(err);
77
- console.log("createPayload failed");
78
- process.exit(1);
79
- } else {
80
- iService(uTable, useDefault, asset, r, serverMode, customize);
81
- }
82
- });
83
- } else {
84
- let appEnv = getAllEnv({});
85
- iService(uTable, useDefault, asset, appEnv, serverMode, customize);
86
- }
87
- }
88
-
89
- function setup(rafEnv, dockerFile) {
90
- config(rafEnv, dockerFile);
91
- let asset = process.env.APPLOC === "." ? process.cwd() : process.env.APPLOC;
92
- process.env.APPASSET = asset;
93
- return asset;
94
- }
95
-
96
- function createPayload(srcName, cb) {
97
- let src = fs.readFileSync(srcName, "utf8");
98
- if (src === null) {
99
- cb(`Error: ${srcName} was not found. `);
100
- }
101
- try {
102
- // console.log(src);
103
- let f = new Function(src);
104
- console.log(`${srcName} compile completed`);
105
- let r = f();
106
- f = null;
107
-
108
- let ar = getAllEnv(r);
109
- cb(null, ar);
110
- } catch (err) {
111
- console.log(`${srcName} compile failed`);
112
- cb(err);
113
- }
114
- }
115
-
116
- function getAllEnv(userData) {
117
- let env;
118
- let l = null;
119
- let host = trimit("VIYA_SERVER");
120
- if (host === 'none' || host == null) {
121
- console.log('Note: setting host to null');
122
- host = null;
123
- }
124
-
125
- /*
126
- if (process.env.AUTHTYPE != null) {
127
- process.env.AUTHFLOW = process.env.AUTHTYPE;
128
- }
129
- */
130
-
131
- let authflow = trimit("AUTHFLOW");
132
- if (authflow === "authorization_code" || authflow === "code") {
133
- authflow = "server";
134
- }
135
-
136
- if (authflow === null) {
137
- host = null;
138
- }
139
-
140
- if (host === null) {
141
- authflow = null;
142
- console.log('Note: setting authflow to null');
143
- }
144
-
145
- process.env.AUTHFLOW = authflow;
146
- // let redirect = (process.env.REDIRECT != null) ? process.env.REDIRECT : null;
147
- let redirect = trimit("REDIRECT");
148
-
149
- let clientID = trimit("CLIENTID");
150
-
151
- // eslint-disable-next-line no-unused-vars
152
- let clientSecret = trimit("CLIENTSECRET");
153
- let keepAlive = trimit("KEEPALIVE");
154
- let appName = trimit("APPNAME");
155
- let ns = trimit("NAMESPACE");
156
- let nsHost = trimit("NSHOST");
157
-
158
- l = {
159
- authflow: authflow,
160
- redirect: redirect,
161
-
162
- host: host,
163
- clientID: clientID,
164
- appName: appName,
165
-
166
- keepAlive: null,
167
- useToken: process.env.USETOKEN,
168
-
169
- ns: ns,
170
- nsHost: nsHost,
171
- };
172
- if (authflow === "server" || authflow === "implicit") {
173
- if (authflow === "implicit") {
174
- if (redirect === null) {
175
- redirect = `${appName}/callback`;
176
- process.env.REDIRECT = "callback";
177
- } else {
178
- if (redirect !== null && redirect.indexOf("/") !== 0) {
179
- redirect =
180
- redirect.indexOf("http") != -1
181
- ? redirect
182
- : `${process.env.APPNAME}/${redirect}`;
183
- }
184
- }
185
- l.redirect = redirect;
186
- }
187
-
188
- if (authflow === "server" && keepAlive === "YES") {
189
- let protocol = process.env.HTTPS === "true" ? "https://" : "http://";
190
- l.keepAlive = `${protocol}${process.env.APPHOST}:${process.env.APPPORT}/${appName}/keepAlive`;
191
- l.keepAlive = l.keepAlive.replace(/0.0.0.0/, "localhost");
192
- }
193
- if (process.env.TIMERS != null) {
194
- l.timers = process.env.TIMERS;
195
- }
196
- }
197
- // allow for no authtype
198
- l = {
199
- authType: authflow,
200
- redirect: redirect,
201
-
202
- host: host,
203
- clientID: clientID,
204
- appName: appName,
205
-
206
- keepAlive: null,
207
- useToken: process.env.USETOKEN,
208
-
209
- ns: ns,
210
- nsHost: nsHost,
211
- };
212
-
213
- // pick up the app env's - replacement for appenv.js
214
- // appenv.js still supported for backward compatibility
215
- for (let key in process.env) {
216
- debug(key);
217
- if (key.indexOf("APPENV_") === 0) {
218
- let k = key.substring(7);
219
- let v = process.env[key];
220
- if (v != null && v.trim().length > 0) {
221
- if (v.startsWith('$')) {
222
- v = process.env[v.substring(1)];
223
- }
224
- userData[k] = (v != null) ? v.trim() : null;
225
- } else {
226
- userData[k] = null;
227
-
228
- }
229
- }
230
- }
231
-
232
- env = {
233
- LOGONPAYLOAD: l,
234
- APPENV: userData,
235
- };
236
- console.log("Final APPENV configuration for the server");
237
- console.log(JSON.stringify(env, null, 4));
238
- console.log(Date());
239
- return env;
240
- }
241
-
242
- function trimit(e) {
243
- let a = process.env[e];
244
- if (a == null) {
245
- return null;
246
- }
247
- a = a.trim();
248
- return a.length === 0 ? null : a;
249
- }
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
+ */
18
+
19
+ import "core-js/stable";
20
+ import "regenerator-runtime/runtime";
21
+ import fs from "fs";
22
+ import iService from "./iService";
23
+ import config from "./config";
24
+ import yargs from "yargs";
25
+ import { hideBin } from 'yargs/helpers';
26
+ let debug = require("debug")("startup");
27
+
28
+ module.exports = function core(
29
+ uTable,
30
+ useDefault,
31
+ serverMode,
32
+ customize,
33
+ swaggerfcn
34
+ ) {
35
+ let argv = yargs(hideBin(process.argv)).argv;
36
+ let env = argv.env == null ? '.env' : argv.env;
37
+ let appenv = argv.appenv == null ? null : argv.appenv;
38
+ let docker = argv.docker == null ? null : argv.docker;
39
+ //process.env.SERVERMODE = serverMode !== null ? "api" : "app";
40
+
41
+
42
+ if (useDefault == null) {
43
+ useDefault = true;
44
+ }
45
+ console.log(
46
+ "Initialization started ============================================================"
47
+ );
48
+ console.log(`version: 2, Build Date: `, Date());
49
+ console.log(
50
+ `\nCommand Line Configuration:
51
+ Dockerfile: ${docker}
52
+ env file : ${env}
53
+ appenv : ${appenv}
54
+ customize : ${customize != null}
55
+ `
56
+ );
57
+
58
+ iapp(null, env, docker, uTable, useDefault, serverMode, customize);
59
+ };
60
+
61
+ function iapp(
62
+ appSrc,
63
+ rafEnv,
64
+ dockerFile,
65
+ uTable,
66
+ useDefault,
67
+ serverMode,
68
+ customize
69
+ ) {
70
+ let asset = setup(rafEnv, dockerFile);
71
+ if (appSrc == null) {
72
+ appSrc = process.env.APPENV == null ? null : process.env.APPENV;
73
+ }
74
+ if (appSrc != null) {
75
+ console.log("appSrc", `+${appSrc}+`);
76
+ createPayload(appSrc, (err, r) => {
77
+ if (err) {
78
+ console.log(err);
79
+ console.log("createPayload failed");
80
+ process.exit(1);
81
+ } else {
82
+ iService(uTable, useDefault, asset, r, serverMode, customize);
83
+ }
84
+ });
85
+ } else {
86
+ let appEnv = getAllEnv({});
87
+ iService(uTable, useDefault, asset, appEnv, serverMode, customize);
88
+ }
89
+ }
90
+
91
+ function setup(rafEnv, dockerFile) {
92
+ config(rafEnv, dockerFile);
93
+ let asset = process.env.APPLOC === "." ? process.cwd() : process.env.APPLOC;
94
+ process.env.APPASSET = asset;
95
+ return asset;
96
+ }
97
+
98
+ function createPayload(srcName, cb) {
99
+ let src = fs.readFileSync(srcName, "utf8");
100
+ if (src === null) {
101
+ cb(`Error: ${srcName} was not found. `);
102
+ }
103
+ try {
104
+ // console.log(src);
105
+ let f = new Function(src);
106
+ console.log(`${srcName} compile completed`);
107
+ let r = f();
108
+ f = null;
109
+
110
+ let ar = getAllEnv(r);
111
+ cb(null, ar);
112
+ } catch (err) {
113
+ console.log(`${srcName} compile failed`);
114
+ cb(err);
115
+ }
116
+ }
117
+
118
+ function getAllEnv(userData) {
119
+ let env;
120
+ let l = null;
121
+ let host = trimit("VIYA_SERVER");
122
+ if (host === 'none' || host == null) {
123
+ console.log('Note: setting host to null');
124
+ host = null;
125
+ }
126
+
127
+
128
+ let authflow = trimit("AUTHFLOW");
129
+ let pkce = (authflow === "pkce") ? true : false;
130
+ if (authflow === "authorization_code" || authflow === "code" || authflow === "server" ||
131
+ authflow === "null" || authflow === "pkce") {
132
+ authflow = "server";
133
+
134
+ }
135
+
136
+
137
+ if (host === null) {
138
+ authflow = null;
139
+ console.log('Note: setting authflow to null');
140
+ }
141
+
142
+ process.env.AUTHFLOW = authflow;
143
+ // let redirect = (process.env.REDIRECT != null) ? process.env.REDIRECT : null;
144
+ let redirect = trimit("REDIRECT");
145
+
146
+ let clientID = trimit("CLIENTID");
147
+
148
+ // eslint-disable-next-line no-unused-vars
149
+ //let clientSecret = trimit("CLIENTSECRET");
150
+ let keepAlive = trimit("KEEPALIVE");
151
+ let appName = trimit("APPNAME");
152
+ let ns = trimit("NAMESPACE");
153
+ let nsHost = trimit("NSHOST");
154
+
155
+ l = {
156
+ authflow: authflow,
157
+ redirect: redirect,
158
+
159
+ host: host,
160
+ clientID: clientID,
161
+ appName: appName,
162
+ pkce: pkce,
163
+
164
+ keepAlive: null,
165
+ useToken: process.env.USETOKEN,
166
+
167
+ ns: ns,
168
+ nsHost: nsHost,
169
+ };
170
+ if (authflow === "server" || authflow === "implicit") {
171
+ if (authflow === "implicit") {
172
+ if (redirect === null) {
173
+ redirect = `${appName}/callback`;
174
+ process.env.REDIRECT = "callback";
175
+ } else {
176
+ if (redirect !== null && redirect.indexOf("/") !== 0) {
177
+ redirect =
178
+ redirect.indexOf("http") != -1
179
+ ? redirect
180
+ : `${process.env.APPNAME}/${redirect}`;
181
+ }
182
+ }
183
+ l.redirect = redirect;
184
+ }
185
+
186
+ if (authflow === "server" && keepAlive === "YES") {
187
+ let protocol = process.env.HTTPS === "true" ? "https://" : "http://";
188
+ l.keepAlive = `${protocol}${process.env.APPHOST}:${process.env.APPPORT}/${appName}/keepAlive`;
189
+ l.keepAlive = l.keepAlive.replace(/0.0.0.0/, "localhost");
190
+ }
191
+ if (process.env.TIMERS != null) {
192
+ l.timers = process.env.TIMERS;
193
+ }
194
+ }
195
+ // allow for no authtype
196
+ l = {
197
+ authType: authflow,
198
+ redirect: redirect,
199
+
200
+ host: host,
201
+ clientID: clientID,
202
+ appName: appName,
203
+
204
+ keepAlive: null,
205
+ useToken: process.env.USETOKEN,
206
+
207
+ ns: ns,
208
+ nsHost: nsHost,
209
+ };
210
+
211
+ // pick up the app env's - replacement for appenv.js
212
+ // appenv.js still supported for backward compatibility
213
+ for (let key in process.env) {
214
+ debug(key);
215
+ if (key.indexOf("APPENV_") === 0) {
216
+ let k = key.substring(7);
217
+ let v = process.env[key];
218
+ if (v != null && v.trim().length > 0) {
219
+ if (v.startsWith('$')) {
220
+ v = process.env[v.substring(1)];
221
+ }
222
+ userData[k] = (v != null) ? v.trim() : null;
223
+ } else {
224
+ userData[k] = null;
225
+
226
+ }
227
+ }
228
+ }
229
+ userData.APPNAME = l.appName;
230
+ env = {
231
+ LOGONPAYLOAD: l,
232
+ APPENV: userData,
233
+ };
234
+ console.log("Final APPENV configuration for the server");
235
+ console.log(JSON.stringify(env, null, 4));
236
+ console.log(Date());
237
+ return env;
238
+ }
239
+
240
+ function trimit(e) {
241
+ let a = process.env[e];
242
+ if (a == null) {
243
+ return null;
244
+ }
245
+ a = a.trim();
246
+ return a.length === 0 ? null : a;
247
+ }
@@ -1,32 +1,32 @@
1
- /*
2
- * Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- 'use strict';
6
- let parser = require('docker-file-parser');
7
- let fs = require('fs');
8
-
9
- function parseDocker (dockerFile) {
10
- ;
11
- let d = fs.readFileSync(dockerFile, 'utf8');
12
- let data = parser.parse(d);
13
- data.forEach(d => {
14
- if (d.name === 'EXPOSE') {
15
- process.env.EXPOSEDPORT = d.args[0];
16
- console.log(`Exposed port: ${process.env.EXPOSEDPORT}`);
17
- } else if (d.name === 'ENV') {
18
- for (let key in d.args) {
19
- let v = d.args[key];
20
- if (v.length === 0) {
21
- console.log(
22
- `Value for ${key} inherited as ${process.env[key]}`
23
- );
24
- } else {
25
- process.env[key] = v;
26
- }
27
- }
28
- }
29
- });
30
- }
31
-
32
- export default parseDocker;
1
+ /*
2
+ * Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ 'use strict';
6
+ let parser = require('docker-file-parser');
7
+ let fs = require('fs');
8
+
9
+ function parseDocker (dockerFile) {
10
+ ;
11
+ let d = fs.readFileSync(dockerFile, 'utf8');
12
+ let data = parser.parse(d);
13
+ data.forEach(d => {
14
+ if (d.name === 'EXPOSE') {
15
+ process.env.EXPOSEDPORT = d.args[0];
16
+ console.log(`Exposed port: ${process.env.EXPOSEDPORT}`);
17
+ } else if (d.name === 'ENV') {
18
+ for (let key in d.args) {
19
+ let v = d.args[key];
20
+ if (v.length === 0) {
21
+ console.log(
22
+ `Value for ${key} inherited as ${process.env[key]}`
23
+ );
24
+ } else {
25
+ process.env[key] = v;
26
+ }
27
+ }
28
+ }
29
+ });
30
+ }
31
+
32
+ export default parseDocker;