@sassoftware/viya-serverjs 0.6.2 → 0.6.3-1

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.
package/.env CHANGED
@@ -12,7 +12,9 @@ REDIRECT=
12
12
  # USELOGON=FALSE
13
13
  # USETOKEN=FALSE
14
14
  HTTPS=true
15
-
16
- VIYACERT=c:\Users\kumar\viyaCert\xf1
15
+ # SSLCERT=
16
+ # VIYACERT=c:\Users\kumar\viyaCert\xf1
17
17
  NODE_TLS_REJECT_UNAUTHORIZED=0
18
+ AUTOSTART=TRUE
18
19
 
20
+ CUSTOMTEXT="<h1> sas-score-mcp-server</h>"
package/autoStart.js ADDED
@@ -0,0 +1,6 @@
1
+ import open from 'open';
2
+ async function autoStart(url) {
3
+ await open(url, {wait:true});
4
+ console.error(`[Note]URL: ${url} closed by user`);
5
+ }
6
+ export default autoStart;
package/cli.js CHANGED
@@ -4,7 +4,25 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- let core = require('./lib/index.js');
7
+ import api from './lib/index.js';
8
+ import autoStart from './autoStart.js';
9
+
8
10
  console.log('Starting the cli for @sassoftware/viya-serverjs');
9
11
  let userCache = {};
10
- core(null, true, 'app', null, userCache);
12
+
13
+ api.asyncCore(null, true, 'app', null, userCache)
14
+ .then ((r) => {
15
+ console.log('core returned', r);
16
+ if (process.env.AUTOSTART && process.env.AUTOSTART.toUpperCase() ==='TRUE'){
17
+ console.log('Auto-starting the server as per AUTOSTART env variable');
18
+ autoStart(r).catch((err) => {
19
+ console.log('Error in autoStart', err);
20
+ });
21
+ }
22
+ return r;
23
+ })
24
+ .catch((err) => {
25
+ console.log('Error in core', err);
26
+ });
27
+
28
+
package/lib/iService.js CHANGED
@@ -47,279 +47,333 @@ var Vision = require('@hapi/vision');
47
47
  var inert = require('@hapi/inert');
48
48
  var selfsigned = require('selfsigned');
49
49
  var os = require('os');
50
- function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, userCache) {
51
- // process.env.APPHOST_ADDR = process.env.APPHOST;
52
- var init = /*#__PURE__*/function () {
53
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
54
- var defaultMaxBytes, maxBytes, isSameSite, isSecure, https, _process$env$SAMESITE, _process$env$SAMESITE2, s1, s2, sConfig, hapiServer, nodeCacheOptions, storeCache, visionOptions, options, allRoutes, hh, msg;
55
- return _regenerator().w(function (_context) {
56
- while (1) switch (_context.n) {
57
- case 0:
58
- if (process.env.APPHOST === '*') {
59
- process.env.APPHOST = os.hostname();
60
- }
61
- defaultMaxBytes = 10485760;
62
- if (isNaN(process.env.PAYLOADMAXBYTES)) {
63
- maxBytes = defaultMaxBytes;
64
- } else {
65
- maxBytes = Number(process.env.PAYLOADMAXBYTES);
66
- }
67
- isSameSite = 'Lax';
68
- isSecure = false;
69
- https = process.env.HTTPS || 'TRUE';
70
- https = https.toUpperCase();
71
- if (process.env.SAMESITE != null) {
72
- _process$env$SAMESITE = process.env.SAMESITE.split(','), _process$env$SAMESITE2 = _slicedToArray(_process$env$SAMESITE, 2), s1 = _process$env$SAMESITE2[0], s2 = _process$env$SAMESITE2[1];
73
- isSameSite = s1;
74
- isSecure = s2 === 'secure' ? true : false;
75
- if (https !== 'TRUE') {
76
- isSecure = false;
77
- }
78
- }
79
- sConfig = {
80
- port: process.env.APPPORT,
81
- host: process.env.APPHOST,
82
- state: {
83
- isSameSite: isSameSite,
84
- isSecure: isSecure
85
- },
86
- routes: {
87
- payload: {
88
- maxBytes: maxBytes
89
- },
90
- cors: {
91
- origin: ['*'],
92
- credentials: true,
93
- "headers": ["Accept", "Authorization", "Content-Type", "If-None-Match", "Accept-language"]
94
- /*
95
- 'Access-Control-Allow-Methods': ['GET', 'POST', 'OPTIONS'],
96
- additionalHeaders : ['multipart/form-data', 'content-disposition'],
97
- additionalExposedHeaders : ['location'],
98
- */
99
- }
100
- }
101
- };
102
- if (process.env.HAPIDEBUG === 'YES') {
103
- sConfig.debug = {
104
- request: '*'
105
- };
106
- }
107
- debug(JSON.stringify(sConfig, null, 4));
108
- if (https === 'TRUE') {
109
- sConfig.tls = getCertificates();
110
- debug('Setup of SSL certificates completed');
111
- } else {
112
- debug('Running with no SSL certificates');
113
- }
114
- if (asset !== null) {
115
- sConfig.routes.files = {
116
- relativeTo: asset
117
- };
118
- }
119
- debug2("Application information: \n\t\tAPPLOC : ".concat(process.env.APPLOC, "\n\t\tAPPENTRY: ").concat(process.env.APPENTRY, "\n"));
120
- hapiServer = Hapi.server(sConfig);
121
- /*
122
- const cache = hapiServer.cache({ segment: 'sid', expiresIn: 3 * 24 * 60 * 60 * 1000 });
123
- hapiServer.app.cache = cache;
124
- */
125
- nodeCacheOptions = {
126
- stdTTL: 24 * 60 * 60 * 1000,
127
- checkPeriod: 3600,
128
- errorOnMissing: true,
129
- useClones: false,
130
- deleteOnExpire: true
131
- };
132
- storeCache = new NodeCache(nodeCacheOptions);
133
- hapiServer.app.cache = storeCache;
50
+ function iService(_x, _x2, _x3, _x4, _x5, _x6) {
51
+ return _iService.apply(this, arguments);
52
+ }
53
+ function _iService() {
54
+ _iService = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(userRouteTable, useDefault, asset, allAppEnv, serverMode, userCache) {
55
+ var init, r, _t;
56
+ return _regenerator().w(function (_context2) {
57
+ while (1) switch (_context2.p = _context2.n) {
58
+ case 0:
59
+ // process.env.APPHOST_ADDR = process.env.APPHOST;
60
+ init = /*#__PURE__*/function () {
61
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
62
+ var defaultMaxBytes, maxBytes, isSameSite, isSecure, https, _process$env$SAMESITE, _process$env$SAMESITE2, s1, s2, sConfig, hapiServer, nodeCacheOptions, storeCache, visionOptions, options, allRoutes, hh, msg;
63
+ return _regenerator().w(function (_context) {
64
+ while (1) switch (_context.n) {
65
+ case 0:
66
+ if (process.env.APPHOST === '*') {
67
+ process.env.APPHOST = os.hostname();
68
+ }
69
+ defaultMaxBytes = 10485760;
70
+ if (isNaN(process.env.PAYLOADMAXBYTES)) {
71
+ maxBytes = defaultMaxBytes;
72
+ } else {
73
+ maxBytes = Number(process.env.PAYLOADMAXBYTES);
74
+ }
75
+ isSameSite = 'Lax';
76
+ isSecure = false;
77
+ https = process.env.HTTPS || 'TRUE';
78
+ https = https.toUpperCase();
79
+ if (process.env.SAMESITE != null) {
80
+ _process$env$SAMESITE = process.env.SAMESITE.split(','), _process$env$SAMESITE2 = _slicedToArray(_process$env$SAMESITE, 2), s1 = _process$env$SAMESITE2[0], s2 = _process$env$SAMESITE2[1];
81
+ isSameSite = s1;
82
+ isSecure = s2 === 'secure' ? true : false;
83
+ if (https !== 'TRUE') {
84
+ isSecure = false;
85
+ }
86
+ }
87
+ sConfig = {
88
+ port: process.env.APPPORT,
89
+ host: process.env.APPHOST,
90
+ state: {
91
+ isSameSite: isSameSite,
92
+ isSecure: isSecure
93
+ },
94
+ routes: {
95
+ payload: {
96
+ maxBytes: maxBytes
97
+ },
98
+ cors: {
99
+ origin: ['*'],
100
+ credentials: true,
101
+ "headers": ["Accept", "Authorization", "Content-Type", "If-None-Match", "Accept-language"]
102
+ /*
103
+ 'Access-Control-Allow-Methods': ['GET', 'POST', 'OPTIONS'],
104
+ additionalHeaders : ['multipart/form-data', 'content-disposition'],
105
+ additionalExposedHeaders : ['location'],
106
+ */
107
+ }
108
+ }
109
+ };
110
+ if (process.env.HAPIDEBUG === 'YES') {
111
+ sConfig.debug = {
112
+ request: '*'
113
+ };
114
+ }
115
+ debug(JSON.stringify(sConfig, null, 4));
116
+ if (!(https === 'TRUE')) {
117
+ _context.n = 2;
118
+ break;
119
+ }
120
+ _context.n = 1;
121
+ return getCertificates();
122
+ case 1:
123
+ sConfig.tls = _context.v;
124
+ debug('Setup of SSL certificates completed');
125
+ _context.n = 3;
126
+ break;
127
+ case 2:
128
+ debug('Running with no SSL certificates');
129
+ case 3:
130
+ if (asset !== null) {
131
+ sConfig.routes.files = {
132
+ relativeTo: asset
133
+ };
134
+ }
135
+ debug2("Application information: \n\t\tAPPLOC : ".concat(process.env.APPLOC, "\n\t\tAPPENTRY: ").concat(process.env.APPENTRY, "\n"));
136
+ hapiServer = Hapi.server(sConfig);
137
+ /*
138
+ const cache = hapiServer.cache({ segment: 'sid', expiresIn: 3 * 24 * 60 * 60 * 1000 });
139
+ hapiServer.app.cache = cache;
140
+ */
141
+ nodeCacheOptions = {
142
+ stdTTL: 24 * 60 * 60 * 1000,
143
+ checkPeriod: 3600,
144
+ errorOnMissing: true,
145
+ useClones: false,
146
+ deleteOnExpire: true
147
+ };
148
+ storeCache = new NodeCache(nodeCacheOptions);
149
+ hapiServer.app.cache = storeCache;
134
150
 
135
- // common plugins
136
- visionOptions = {
137
- engines: {
138
- html: require('handlebars')
139
- },
140
- relativeTo: __dirname,
141
- path: '.'
142
- };
143
- _context.n = 1;
144
- return hapiServer.register(Vision);
145
- case 1:
146
- hapiServer.views(visionOptions);
147
- _context.n = 2;
148
- return hapiServer.register(inert);
149
- case 2:
150
- if (!(https === 'TRUE')) {
151
- _context.n = 3;
152
- break;
153
- }
154
- _context.n = 3;
155
- return hapiServer.register({
156
- plugin: require('hapi-require-https'),
157
- options: {}
158
- });
159
- case 3:
160
- _context.n = 4;
161
- return hapiServer.register(H202);
162
- case 4:
163
- // setup authentication related plugins
164
- options = {
165
- serverMode: serverMode,
166
- authFlow: process.env.AUTHFLOW,
167
- host: process.env.VIYA_SERVER,
168
- isSameSite: isSameSite,
169
- isSecure: isSecure,
170
- ns: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.ns : null,
171
- nsHost: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.nsHost : null,
172
- redirect: process.env.REDIRECT,
173
- clientId: process.env.CLIENTID,
174
- clientSecret: process.env.CLIENTSECRET,
175
- redirectTo: "/".concat(process.env.APPNAME, "/logon"),
176
- allAppEnv: allAppEnv,
177
- useHapiCookie: true,
178
- appName: process.env.APPNAME,
179
- appHost: process.env.APPHOST,
180
- appPort: process.env.APPPORT,
181
- userRouteTable: userRouteTable,
182
- useDefault: useDefault,
183
- /* not used - left here for potential reuse */
184
- userCache: userCache || {},
185
- https: https,
186
- authDefault: false,
187
- /* set later in setDefaultRoutes */
188
- authLogon: false /* set later in setDefaultRoutes */
189
- };
190
- debug2('Options', options);
191
- if (!(process.env.AUTHFLOW != null)) {
192
- _context.n = 6;
193
- break;
194
- }
195
- _context.n = 5;
196
- return (0, _setupAuth["default"])(hapiServer, options);
197
- case 5:
198
- if (process.env.PREAUTH === 'YES') {
199
- console.log('Preauth enabled');
200
- hapiServer.ext('onPreAuth', function (request, h) {
201
- debugger;
202
- if (!request.auth.isAuthenticated && !request.path.startsWith("/login")) {
203
- var redirectTo = "".concat(request.path, "?").concat(new URLSearchParams(request.query).toString());
204
- console.log('Redirect to login', {
205
- redirectTo: redirectTo
206
- });
207
- debugger;
208
- return h.redirect("/login").takeover();
151
+ // common plugins
152
+ visionOptions = {
153
+ engines: {
154
+ html: require('handlebars')
155
+ },
156
+ relativeTo: __dirname,
157
+ path: '.'
158
+ };
159
+ _context.n = 4;
160
+ return hapiServer.register(Vision);
161
+ case 4:
162
+ hapiServer.views(visionOptions);
163
+ _context.n = 5;
164
+ return hapiServer.register(inert);
165
+ case 5:
166
+ if (!(https === 'TRUE')) {
167
+ _context.n = 6;
168
+ break;
169
+ }
170
+ _context.n = 6;
171
+ return hapiServer.register({
172
+ plugin: require('hapi-require-https'),
173
+ options: {}
174
+ });
175
+ case 6:
176
+ _context.n = 7;
177
+ return hapiServer.register(H202);
178
+ case 7:
179
+ // setup authentication related plugins
180
+ options = {
181
+ serverMode: serverMode,
182
+ authFlow: process.env.AUTHFLOW,
183
+ host: process.env.VIYA_SERVER,
184
+ isSameSite: isSameSite,
185
+ isSecure: isSecure,
186
+ ns: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.ns : null,
187
+ nsHost: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.nsHost : null,
188
+ redirect: process.env.REDIRECT,
189
+ clientId: process.env.CLIENTID,
190
+ clientSecret: process.env.CLIENTSECRET,
191
+ redirectTo: "/".concat(process.env.APPNAME, "/logon"),
192
+ allAppEnv: allAppEnv,
193
+ useHapiCookie: true,
194
+ appName: process.env.APPNAME,
195
+ appHost: process.env.APPHOST,
196
+ appPort: process.env.APPPORT,
197
+ userRouteTable: userRouteTable,
198
+ useDefault: useDefault,
199
+ /* not used - left here for potential reuse */
200
+ userCache: userCache || {},
201
+ https: https,
202
+ authDefault: false,
203
+ /* set later in setDefaultRoutes */
204
+ authLogon: false /* set later in setDefaultRoutes */
205
+ };
206
+ debug2('Options', options);
207
+ if (!(process.env.AUTHFLOW != null)) {
208
+ _context.n = 9;
209
+ break;
210
+ }
211
+ _context.n = 8;
212
+ return (0, _setupAuth["default"])(hapiServer, options);
213
+ case 8:
214
+ if (process.env.PREAUTH === 'YES') {
215
+ console.log('Preauth enabled');
216
+ hapiServer.ext('onPreAuth', function (request, h) {
217
+ debugger;
218
+ if (!request.auth.isAuthenticated && !request.path.startsWith("/login")) {
219
+ var redirectTo = "".concat(request.path, "?").concat(new URLSearchParams(request.query).toString());
220
+ console.log('Redirect to login', {
221
+ redirectTo: redirectTo
222
+ });
223
+ debugger;
224
+ return h.redirect("/login").takeover();
225
+ }
226
+ return h["continue"];
227
+ });
228
+ }
229
+ case 9:
230
+ //
231
+ // Start server
232
+ //
233
+ // eslint-disable-next-line no-unused-vars
234
+ allRoutes = hapiServer.table();
235
+ _context.n = 10;
236
+ return hapiServer.start();
237
+ case 10:
238
+ hh = hapiServer.info.uri;
239
+ hh = hh.replace(/0.0.0.0/, 'localhost');
240
+ console.log('====================================================================================');
241
+ console.log('Server Start Time: ', Date());
242
+ msg = options.serverMode === 'app' ? "Visit ".concat(hh, "/").concat(process.env.APPNAME, " to access application") : "Visit ".concat(hh, "/").concat(process.env.APPNAME, "/api to access swagger");
243
+ console.log('\x1b[1m%s\x1b[0m', msg);
244
+ console.log('NOTE: If running in container use the exported port');
245
+ process.env.APPSERVER = "".concat(hh, "/").concat(process.env.APPNAME);
246
+ process.env.HEALTH = 'true';
247
+ console.log('====================================================================================');
248
+ return _context.a(2, "".concat(hh, "/").concat(process.env.APPNAME));
209
249
  }
210
- return h["continue"];
211
- });
212
- }
213
- case 6:
214
- //
215
- // Start server
216
- //
217
- // eslint-disable-next-line no-unused-vars
218
- allRoutes = hapiServer.table();
219
- _context.n = 7;
220
- return hapiServer.start();
221
- case 7:
222
- hh = hapiServer.info.uri;
223
- hh = hh.replace(/0.0.0.0/, 'localhost');
224
- console.log('====================================================================================');
225
- console.log('Server Start Time: ', Date());
226
- msg = options.serverMode === 'app' ? "Visit ".concat(hh, "/").concat(process.env.APPNAME, " to access application") : "Visit ".concat(hh, "/").concat(process.env.APPNAME, "/api to access swagger");
227
- console.log('\x1b[1m%s\x1b[0m', msg);
228
- console.log('NOTE: If running in container use the exported port');
229
- process.env.APPSERVER = "".concat(hh, "/").concat(process.env.APPNAME);
230
- process.env.HEALTH = 'true';
231
- console.log('====================================================================================');
232
- case 8:
233
- return _context.a(2);
234
- }
235
- }, _callee);
236
- }));
237
- return function init() {
238
- return _ref.apply(this, arguments);
239
- };
240
- }();
241
- process.on('unhandledRejection', function (err) {
242
- console.log(err);
243
- process.exit(1);
244
- });
245
- init();
250
+ }, _callee);
251
+ }));
252
+ return function init() {
253
+ return _ref.apply(this, arguments);
254
+ };
255
+ }();
256
+ process.on('unhandledRejection', function (err) {
257
+ console.log(err);
258
+ process.exit(1);
259
+ });
260
+ _context2.p = 1;
261
+ _context2.n = 2;
262
+ return init();
263
+ case 2:
264
+ r = _context2.v;
265
+ return _context2.a(2, r);
266
+ case 3:
267
+ _context2.p = 3;
268
+ _t = _context2.v;
269
+ console.log('Error starting server', _t);
270
+ return _context2.a(2, false);
271
+ case 4:
272
+ return _context2.a(2);
273
+ }
274
+ }, _callee2, null, [[1, 3]]);
275
+ }));
276
+ return _iService.apply(this, arguments);
246
277
  }
247
278
  function getCertificates() {
248
- var tlsdir = process.env.SSLCERT;
249
- var options = (0, _readCerts["default"])(tlsdir);
250
- if (options === null) {
251
- console.log('No SSL certificates found, generating self-signed certificates');
252
- options = getTls();
253
- options.rejectUnauthorized = false;
254
- }
255
- return options;
279
+ return _getCertificates.apply(this, arguments);
280
+ }
281
+ function _getCertificates() {
282
+ _getCertificates = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
283
+ var tlsdir, options;
284
+ return _regenerator().w(function (_context3) {
285
+ while (1) switch (_context3.n) {
286
+ case 0:
287
+ tlsdir = process.env.SSLCERT;
288
+ options = (0, _readCerts["default"])(tlsdir);
289
+ if (!(options === null)) {
290
+ _context3.n = 2;
291
+ break;
292
+ }
293
+ console.log('No SSL certificates found, generating self-signed certificates');
294
+ _context3.n = 1;
295
+ return getTls();
296
+ case 1:
297
+ options = _context3.v;
298
+ options.rejectUnauthorized = false;
299
+ case 2:
300
+ return _context3.a(2, options);
301
+ }
302
+ }, _callee3);
303
+ }));
304
+ return _getCertificates.apply(this, arguments);
256
305
  }
257
306
  function getTls() {
258
- var options = {
259
- keySize: 2048,
260
- days: 360,
261
- algorithm: "sha256",
262
- clientCertificate: true,
263
- extensions: {}
264
- };
265
- var subjt = process.env.TLS_CREATE.replaceAll('"', '').trim();
266
- var subj = subjt.split(',');
267
- var d = {};
268
- subj.map(function (c) {
269
- var r = c.split(':');
270
- d[r[0]] = r[1];
271
- return {
272
- value: r[1]
273
- };
274
- });
307
+ return _getTls.apply(this, arguments);
308
+ }
309
+ function _getTls() {
310
+ _getTls = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
311
+ var options, subjt, subj, d, attr, pems, tls;
312
+ return _regenerator().w(function (_context4) {
313
+ while (1) switch (_context4.n) {
314
+ case 0:
315
+ options = {
316
+ keySize: 2048,
317
+ days: 360,
318
+ algorithm: "sha256",
319
+ clientCertificate: true,
320
+ extensions: {}
321
+ };
322
+ subjt = process.env.TLS_CREATE.replaceAll('"', '').trim();
323
+ subj = subjt.split(',');
324
+ d = {};
325
+ subj.map(function (c) {
326
+ var r = c.split(':');
327
+ d[r[0]] = r[1];
328
+ return {
329
+ value: r[1]
330
+ };
331
+ });
275
332
 
276
- // TLS_CREATE=C:US,ST:NC,L:Cary,O:SAS Institute,OU:STO,CN:localhost,ALT:na.sas.com
277
- var attr = [{
278
- name: 'commonName',
279
- value: d.CN /*process.env.APPHOST*/
280
- }, {
281
- name: 'countryName',
282
- value: d.C
283
- }, {
284
- shortName: 'ST',
285
- value: d.ST
286
- }, {
287
- name: 'localityName',
288
- value: d.L
289
- }, {
290
- name: 'organizationName',
291
- value: d.O
292
- }, {
293
- shortName: 'OU',
294
- value: d.OU
295
- }];
296
- options.extensions.altNames = [
297
- // { type: 6, value: `http://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
298
- {
299
- type: 6,
300
- value: "https://".concat(process.env.APPHOST, ":").concat(process.env.APPPORT, "/").concat(process.env.APPNAME)
301
- }, {
302
- type: 6,
303
- value: "https://".concat(process.env.APPHOST, ":").concat(process.env.APPPORT, "/").concat(process.env.APPNAME, "/api")
304
- }, {
305
- type: 6,
306
- value: "https://".concat(process.env.APPHOST, ":").concat(process.env.APPPORT, "/").concat(process.env.APPNAME, "/logon")
307
- }, {
308
- type: 6,
309
- value: "https://".concat(process.env.APPHOST, "/").concat(process.env.APPNAME)
310
- }, {
311
- type: 6,
312
- value: "https://".concat(process.env.APPHOST, "/").concat(process.env.APPNAME, "/api")
313
- }, {
314
- type: 6,
315
- value: "https://".concat(process.env.APPHOST, "/").concat(process.env.APPNAME, "/logon")
316
- }];
317
- debug('tls options ', JSON.stringify(options, null, 4));
318
- var pems = selfsigned.generate(attr, options);
319
- var tls = {
320
- cert: pems.cert,
321
- key: pems["private"]
322
- };
323
- return tls;
333
+ // TLS_CREATE=C:US,ST:NC,L:Cary,O:SAS Institute,OU:STO,CN:localhost,ALT:na.sas.com
334
+ attr = [{
335
+ name: 'commonName',
336
+ value: d.CN /*process.env.APPHOST*/
337
+ }, {
338
+ name: 'countryName',
339
+ value: d.C
340
+ }, {
341
+ shortName: 'ST',
342
+ value: d.ST
343
+ }, {
344
+ name: 'localityName',
345
+ value: d.L
346
+ }, {
347
+ name: 'organizationName',
348
+ value: d.O
349
+ }, {
350
+ shortName: 'OU',
351
+ value: d.OU
352
+ }];
353
+ /*
354
+ options.extensions.altNames = [
355
+ // { type: 6, value: `http://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
356
+ { type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
357
+ { type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}/api` },
358
+ { type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}/logon` },
359
+ { type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}` },
360
+ { type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/api` },
361
+ { type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/logon` },
362
+ ];
363
+ */
364
+ debug('tls options ', JSON.stringify(options, null, 4));
365
+ _context4.n = 1;
366
+ return selfsigned.generate(attr);
367
+ case 1:
368
+ pems = _context4.v;
369
+ tls = {
370
+ cert: pems.cert,
371
+ key: pems["private"]
372
+ };
373
+ return _context4.a(2, tls);
374
+ }
375
+ }, _callee4);
376
+ }));
377
+ return _getTls.apply(this, arguments);
324
378
  }
325
379
  var _default = exports["default"] = iService;
package/lib/index.js CHANGED
@@ -9,7 +9,10 @@ var _readCerts = _interopRequireDefault(require("./readCerts"));
9
9
  var _yargs = _interopRequireDefault(require("yargs"));
10
10
  var _helpers = require("yargs/helpers");
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
- /*
12
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
13
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
14
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
15
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /*
13
16
  * ------------------------------------------------------------------------------------
14
17
  * * Copyright (c) SAS Institute Inc.
15
18
  * * Licensed under the Apache License, Version 2.0 (the 'License');
@@ -26,43 +29,106 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default":
26
29
  * ----------------------------------------------------------------------------------------
27
30
  *
28
31
  */
29
-
30
32
  var debug = require("debug")("startup");
31
- module.exports = function core(uTable, useDefault, serverMode, customize, userCache) {
32
- var argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).argv;
33
- var env = argv.env == null ? null : argv.env;
34
- var appenv = argv.appenv == null ? null : argv.appenv;
35
- var docker = argv.docker == null ? null : argv.docker;
36
- //process.env.SERVERMODE = serverMode !== null ? "api" : "app";
37
-
38
- if (useDefault == null) {
39
- useDefault = true;
40
- }
41
- console.log("Initialization started ============================================================");
42
- console.log("version: 2, Build Date: ", Date());
43
- console.log("\nCommand Line Configuration:\n Dockerfile: ".concat(docker, "\n env file : ").concat(env, "\n appenv : ").concat(appenv, "\n customize : ").concat(customize != null, "\n "));
44
- iapp(null, env, docker, uTable, useDefault, serverMode, customize, userCache);
33
+ exports.core = function () {
34
+ icore().then(function (r) {
35
+ console.log('icore returned', r);
36
+ return r;
37
+ })["catch"](function (err) {
38
+ console.log('Error in icore', err);
39
+ return null;
40
+ });
45
41
  };
46
- function iapp(appSrc, rafEnv, dockerFile, uTable, useDefault, serverMode, customize, userCache) {
47
- var asset = setup(rafEnv, dockerFile);
48
- if (appSrc == null) {
49
- appSrc = process.env.APPENV == null ? null : process.env.APPENV;
50
- }
51
- if (appSrc != null) {
52
- console.log("appSrc", "+".concat(appSrc, "+"));
53
- createPayload(appSrc, function (err, r) {
54
- if (err) {
55
- console.log(err);
56
- console.log("createPayload failed");
57
- process.exit(1);
58
- } else {
59
- (0, _iService["default"])(uTable, useDefault, asset, r, serverMode, customize, userCache);
42
+ exports.asyncCore = icore;
43
+ function icore(_x, _x2, _x3, _x4, _x5) {
44
+ return _icore.apply(this, arguments);
45
+ }
46
+ function _icore() {
47
+ _icore = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(uTable, useDefault, serverMode, customize, userCache) {
48
+ var argv, env, appenv, docker;
49
+ return _regenerator().w(function (_context) {
50
+ while (1) switch (_context.n) {
51
+ case 0:
52
+ argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).argv;
53
+ env = argv.env == null ? null : argv.env;
54
+ appenv = argv.appenv == null ? null : argv.appenv;
55
+ docker = argv.docker == null ? null : argv.docker; //process.env.SERVERMODE = serverMode !== null ? "api" : "app";
56
+ if (useDefault == null) {
57
+ useDefault = true;
58
+ }
59
+ console.log("Initialization started ============================================================");
60
+ console.log("version: 2, Build Date: ", Date());
61
+ console.log("\nCommand Line Configuration:\n Dockerfile: ".concat(docker, "\n env file : ").concat(env, "\n appenv : ").concat(appenv, "\n customize : ").concat(customize != null, "\n "));
62
+ _context.n = 1;
63
+ return iapp(null, env, docker, uTable, useDefault, serverMode, customize, userCache);
64
+ case 1:
65
+ return _context.a(2, _context.v);
60
66
  }
61
- });
62
- } else {
63
- var appEnv = getAllEnv({});
64
- (0, _iService["default"])(uTable, useDefault, asset, appEnv, serverMode, customize, userCache);
65
- }
67
+ }, _callee);
68
+ }));
69
+ return _icore.apply(this, arguments);
70
+ }
71
+ ;
72
+ function iapp(_x6, _x7, _x8, _x9, _x0, _x1, _x10, _x11) {
73
+ return _iapp.apply(this, arguments);
74
+ }
75
+ function _iapp() {
76
+ _iapp = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(appSrc, rafEnv, dockerFile, uTable, useDefault, serverMode, customize, userCache) {
77
+ var asset, appEnv;
78
+ return _regenerator().w(function (_context3) {
79
+ while (1) switch (_context3.n) {
80
+ case 0:
81
+ asset = setup(rafEnv, dockerFile);
82
+ if (appSrc == null) {
83
+ appSrc = process.env.APPENV == null ? null : process.env.APPENV;
84
+ }
85
+ if (!(appSrc != null)) {
86
+ _context3.n = 1;
87
+ break;
88
+ }
89
+ console.log("appSrc", "+".concat(appSrc, "+"));
90
+ createPayload(appSrc, /*#__PURE__*/function () {
91
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(err, r) {
92
+ return _regenerator().w(function (_context2) {
93
+ while (1) switch (_context2.n) {
94
+ case 0:
95
+ if (!err) {
96
+ _context2.n = 1;
97
+ break;
98
+ }
99
+ console.log(err);
100
+ console.log("createPayload failed");
101
+ process.exit(1);
102
+ _context2.n = 3;
103
+ break;
104
+ case 1:
105
+ _context2.n = 2;
106
+ return (0, _iService["default"])(uTable, useDefault, asset, r, serverMode, customize, userCache);
107
+ case 2:
108
+ return _context2.a(2, _context2.v);
109
+ case 3:
110
+ return _context2.a(2);
111
+ }
112
+ }, _callee2);
113
+ }));
114
+ return function (_x12, _x13) {
115
+ return _ref.apply(this, arguments);
116
+ };
117
+ }());
118
+ _context3.n = 3;
119
+ break;
120
+ case 1:
121
+ appEnv = getAllEnv({});
122
+ _context3.n = 2;
123
+ return (0, _iService["default"])(uTable, useDefault, asset, appEnv, serverMode, customize, userCache);
124
+ case 2:
125
+ return _context3.a(2, _context3.v);
126
+ case 3:
127
+ return _context3.a(2);
128
+ }
129
+ }, _callee3);
130
+ }));
131
+ return _iapp.apply(this, arguments);
66
132
  }
67
133
  function setup(rafEnv, dockerFile) {
68
134
  (0, _config["default"])(rafEnv, dockerFile);
@@ -205,8 +271,4 @@ function trimit(e) {
205
271
  }
206
272
  a = a.trim();
207
273
  return a.length === 0 ? null : a;
208
- }
209
- function readVIYACERT() {
210
- var certs = null;
211
- var certfile = process.env.VIYACERT;
212
274
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sassoftware/viya-serverjs",
3
- "version": "0.6.2",
3
+ "version": "0.6.3-1",
4
4
  "description": "Easy to use app server for SAS Viya applications",
5
5
  "author": "Deva Kumaraswamy <deva.kumar@sas.com>",
6
6
  "license": "Apache-2.0",
package/server.js CHANGED
@@ -2,10 +2,10 @@
2
2
  * Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- let core = require('./lib/index.js');
5
+ let api = require('./lib/index.js');
6
6
  debugger;
7
7
  let userCache = {};
8
- core(getCustomHandler, true, 'app', null, userCache);
8
+ api.core(getCustomHandler, true, 'app', null, userCache);
9
9
  console.log('Finished cli setup', userCache);
10
10
 
11
11
  function getCustomHandler() {
package/src/iService.js CHANGED
@@ -32,7 +32,7 @@ import readCerts from './readCerts';
32
32
 
33
33
  let os = require('os');
34
34
 
35
- function iService (userRouteTable, useDefault, asset, allAppEnv, serverMode, userCache) {
35
+ async function iService (userRouteTable, useDefault, asset, allAppEnv, serverMode, userCache) {
36
36
  // process.env.APPHOST_ADDR = process.env.APPHOST;
37
37
  const init = async () => {
38
38
 
@@ -95,7 +95,7 @@ function iService (userRouteTable, useDefault, asset, allAppEnv, serverMode, use
95
95
  }
96
96
  debug(JSON.stringify(sConfig, null,4));
97
97
  if (https === 'TRUE') {
98
- sConfig.tls = getCertificates();
98
+ sConfig.tls = await getCertificates();
99
99
  debug('Setup of SSL certificates completed');
100
100
  } else {
101
101
  debug('Running with no SSL certificates');
@@ -211,28 +211,36 @@ function iService (userRouteTable, useDefault, asset, allAppEnv, serverMode, use
211
211
  process.env.APPSERVER = `${hh}/${process.env.APPNAME}`;
212
212
  process.env.HEALTH = 'true';
213
213
  console.log('====================================================================================');
214
-
214
+ return `${hh}/${process.env.APPNAME}`
215
215
  };
216
216
 
217
217
  process.on('unhandledRejection', (err) => {
218
218
  console.log(err);
219
219
  process.exit(1);
220
220
  });
221
- init();
221
+ try {
222
+ let r = await init();
223
+ return r;
224
+ }
225
+ catch(err){
226
+
227
+ console.log('Error starting server', err);
228
+ return false;
229
+ };
222
230
  }
223
231
 
224
- function getCertificates () {
232
+ async function getCertificates () {
225
233
  let tlsdir = process.env.SSLCERT;
226
234
  let options = readCerts(tlsdir);
227
235
  if (options === null){
228
236
  console.log('No SSL certificates found, generating self-signed certificates');
229
- options = getTls();
237
+ options = await getTls();
230
238
  options.rejectUnauthorized= false;
231
239
  }
232
240
  return options;
233
241
  }
234
242
 
235
- function getTls () {
243
+ async function getTls () {
236
244
  let options = {
237
245
  keySize : 2048,
238
246
  days : 360,
@@ -275,6 +283,7 @@ function getTls () {
275
283
  }
276
284
  ];
277
285
 
286
+ /*
278
287
  options.extensions.altNames = [
279
288
  // { type: 6, value: `http://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
280
289
  { type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
@@ -284,8 +293,9 @@ function getTls () {
284
293
  { type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/api` },
285
294
  { type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/logon` },
286
295
  ];
296
+ */
287
297
  debug('tls options ', JSON.stringify(options, null,4));
288
- let pems = selfsigned.generate(attr, options);
298
+ let pems = await selfsigned.generate(attr);
289
299
  let tls = {
290
300
  cert: pems.cert,
291
301
  key : pems.private
package/src/index.js CHANGED
@@ -26,7 +26,21 @@ import yargs from "yargs";
26
26
  import { hideBin } from 'yargs/helpers';
27
27
  let debug = require("debug")("startup");
28
28
 
29
- module.exports = function core(
29
+ exports.core = function () {
30
+ icore()
31
+ .then ((r) => {
32
+ console.log('icore returned', r);
33
+ return r;
34
+ })
35
+ .catch((err) => {
36
+ console.log('Error in icore', err);
37
+ return null;
38
+ });
39
+
40
+ }
41
+ exports.asyncCore = icore;
42
+
43
+ async function icore (
30
44
  uTable,
31
45
  useDefault,
32
46
  serverMode,
@@ -56,10 +70,10 @@ module.exports = function core(
56
70
  `
57
71
  );
58
72
 
59
- iapp(null, env, docker, uTable, useDefault, serverMode, customize,userCache);
73
+ return await iapp(null, env, docker, uTable, useDefault, serverMode, customize,userCache);
60
74
  };
61
75
 
62
- function iapp(
76
+ async function iapp(
63
77
  appSrc,
64
78
  rafEnv,
65
79
  dockerFile,
@@ -75,18 +89,18 @@ function iapp(
75
89
  }
76
90
  if (appSrc != null) {
77
91
  console.log("appSrc", `+${appSrc}+`);
78
- createPayload(appSrc, (err, r) => {
92
+ createPayload(appSrc, async (err, r) => {
79
93
  if (err) {
80
94
  console.log(err);
81
95
  console.log("createPayload failed");
82
96
  process.exit(1);
83
97
  } else {
84
- iService(uTable, useDefault, asset, r, serverMode, customize, userCache);
98
+ return await iService(uTable, useDefault, asset, r, serverMode, customize, userCache);
85
99
  }
86
100
  });
87
101
  } else {
88
102
  let appEnv = getAllEnv({});
89
- iService(uTable, useDefault, asset, appEnv, serverMode, customize, userCache);
103
+ return await iService(uTable, useDefault, asset, appEnv, serverMode, customize, userCache);
90
104
  }
91
105
  }
92
106
 
@@ -253,8 +267,3 @@ function trimit(e) {
253
267
  return a.length === 0 ? null : a;
254
268
  }
255
269
 
256
- function readVIYACERT(){
257
- let certs = null;
258
- let certfile = process.env.VIYACERT;
259
-
260
- }