@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/lib/iService.js CHANGED
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports["default"] = void 0;
8
+ var _file = require("@hapi/inert/lib/file");
8
9
  var _setupAuth = _interopRequireDefault(require("./plugins/setupAuth"));
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
11
+ 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 }; })(); }
12
+ 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); }
11
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
15
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -21,22 +23,22 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
21
23
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
22
24
  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); }
23
25
  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); }); }; }
24
- /*
25
- * ------------------------------------------------------------------------------------
26
- * * Copyright (c) SAS Institute Inc.
27
- * * Licensed under the Apache License, Version 2.0 (the "License");
28
- * * you may not use this file except in compliance with the License.
29
- * * You may obtain a copy of the License at
30
- * *
31
- * * http://www.apache.org/licenses/LICENSE-2.0
32
- * *
33
- * * Unless required by applicable law or agreed to in writing, software
34
- * * distributed under the License is distributed on an "AS IS" BASIS,
35
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36
- * * See the License for the specific language governing permissions and
37
- * limitations under the License.
38
- * ----------------------------------------------------------------------------------------
39
- *
26
+ /*
27
+ * ------------------------------------------------------------------------------------
28
+ * * Copyright (c) SAS Institute Inc.
29
+ * * Licensed under the Apache License, Version 2.0 (the "License");
30
+ * * you may not use this file except in compliance with the License.
31
+ * * You may obtain a copy of the License at
32
+ * *
33
+ * * http://www.apache.org/licenses/LICENSE-2.0
34
+ * *
35
+ * * Unless required by applicable law or agreed to in writing, software
36
+ * * distributed under the License is distributed on an "AS IS" BASIS,
37
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
+ * * See the License for the specific language governing permissions and
39
+ * limitations under the License.
40
+ * ----------------------------------------------------------------------------------------
41
+ *
40
42
  */
41
43
 
42
44
  var fs = require('fs');
@@ -54,10 +56,10 @@ var os = require('os');
54
56
  function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, userInfo) {
55
57
  // process.env.APPHOST_ADDR = process.env.APPHOST;
56
58
  var init = /*#__PURE__*/function () {
57
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
59
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
58
60
  var defaultMaxBytes, maxBytes, isSameSite, isSecure, _process$env$SAMESITE, _process$env$SAMESITE2, s1, s2, sConfig, hapiServer, nodeCacheOptions, storeCache, visionOptions, options, swaggerOptions, override, allRoutes, hh, msg;
59
- return _regeneratorRuntime().wrap(function _callee$(_context) {
60
- while (1) switch (_context.prev = _context.next) {
61
+ return _regenerator().w(function (_context) {
62
+ while (1) switch (_context.n) {
61
63
  case 0:
62
64
  if (process.env.APPHOST === '*') {
63
65
  process.env.APPHOST = os.hostname();
@@ -93,10 +95,10 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
93
95
  origin: ['*'],
94
96
  credentials: true,
95
97
  "headers": ["Accept", "Authorization", "Content-Type", "If-None-Match", "Accept-language"]
96
- /*
97
- 'Access-Control-Allow-Methods': ['GET', 'POST', 'OPTIONS'],
98
- additionalHeaders : ['multipart/form-data', 'content-disposition'],
99
- additionalExposedHeaders : ['location'],
98
+ /*
99
+ 'Access-Control-Allow-Methods': ['GET', 'POST', 'OPTIONS'],
100
+ additionalHeaders : ['multipart/form-data', 'content-disposition'],
101
+ additionalExposedHeaders : ['location'],
100
102
  */
101
103
  }
102
104
  }
@@ -108,19 +110,19 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
108
110
  }
109
111
  debug(JSON.stringify(sConfig, null, 4));
110
112
  if (!(process.env.HTTPS === 'true')) {
111
- _context.next = 16;
113
+ _context.n = 2;
112
114
  break;
113
115
  }
114
- _context.next = 12;
116
+ _context.n = 1;
115
117
  return getCertificates();
116
- case 12:
117
- sConfig.tls = _context.sent;
118
+ case 1:
119
+ sConfig.tls = _context.v;
118
120
  debug('Setup of SSL certificates completed');
119
- _context.next = 17;
121
+ _context.n = 3;
120
122
  break;
121
- case 16:
123
+ case 2:
122
124
  debug('Running with no SSL certificates');
123
- case 17:
125
+ case 3:
124
126
  if (asset !== null) {
125
127
  sConfig.routes.files = {
126
128
  relativeTo: asset
@@ -128,9 +130,9 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
128
130
  }
129
131
  debug2("Application information: \n\t\tAPPLOC : ".concat(process.env.APPLOC, "\n\t\tAPPENTRY: ").concat(process.env.APPENTRY, "\n"));
130
132
  hapiServer = Hapi.server(sConfig);
131
- /*
132
- const cache = hapiServer.cache({ segment: 'sessions', expiresIn: 3 * 24 * 60 * 60 * 1000 });
133
- hapiServer.app.cache = cache;
133
+ /*
134
+ const cache = hapiServer.cache({ segment: 'sessions', expiresIn: 3 * 24 * 60 * 60 * 1000 });
135
+ hapiServer.app.cache = cache;
134
136
  */
135
137
  nodeCacheOptions = {
136
138
  stdTTL: 24 * 60 * 60 * 1000,
@@ -150,34 +152,34 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
150
152
  relativeTo: __dirname,
151
153
  path: '.'
152
154
  };
153
- _context.next = 26;
155
+ _context.n = 4;
154
156
  return hapiServer.register(Vision);
155
- case 26:
157
+ case 4:
156
158
  hapiServer.views(visionOptions);
157
- _context.next = 29;
159
+ _context.n = 5;
158
160
  return hapiServer.register(inert);
159
- case 29:
161
+ case 5:
160
162
  if (!(process.env.HTTPS === 'true')) {
161
- _context.next = 32;
163
+ _context.n = 6;
162
164
  break;
163
165
  }
164
- _context.next = 32;
166
+ _context.n = 6;
165
167
  return hapiServer.register({
166
168
  plugin: require('hapi-require-https'),
167
169
  options: {}
168
170
  });
169
- case 32:
170
- _context.next = 34;
171
+ case 6:
172
+ _context.n = 7;
171
173
  return hapiServer.register(H202);
172
- case 34:
173
- /*
174
- await hapiServer.register({
175
- plugin : require('hapi-pino'),
176
- options: {
177
- prettyPrint: process.env.NODE_ENV !== 'production',
178
- level : process.env.LOGLEVEL == null ? 'silent' : process.env.LOGLEVEL,
179
- },
180
- });
174
+ case 7:
175
+ /*
176
+ await hapiServer.register({
177
+ plugin : require('hapi-pino'),
178
+ options: {
179
+ prettyPrint: process.env.NODE_ENV !== 'production',
180
+ level : process.env.LOGLEVEL == null ? 'silent' : process.env.LOGLEVEL,
181
+ },
182
+ });
181
183
  */
182
184
  // setup authentication related plugins
183
185
  options = {
@@ -191,6 +193,7 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
191
193
  redirect: process.env.REDIRECT,
192
194
  clientId: process.env.CLIENTID,
193
195
  clientSecret: process.env.CLIENTSECRET,
196
+ pkce: allAppEnv.LOGONPAYLOAD.pkce,
194
197
  redirectTo: "/".concat(process.env.APPNAME, "/logon"),
195
198
  allAppEnv: allAppEnv,
196
199
  useHapiCookie: true,
@@ -208,12 +211,12 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
208
211
  };
209
212
  debug2('Options', options);
210
213
  if (!(process.env.AUTHFLOW != null)) {
211
- _context.next = 40;
214
+ _context.n = 9;
212
215
  break;
213
216
  }
214
- _context.next = 39;
217
+ _context.n = 8;
215
218
  return (0, _setupAuth["default"])(hapiServer, options);
216
- case 39:
219
+ case 8:
217
220
  if (process.env.PREAUTH === 'YES') {
218
221
  console.log('Preauth enabled');
219
222
  hapiServer.ext('onPreAuth', function (request, h) {
@@ -229,10 +232,10 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
229
232
  return h["continue"];
230
233
  });
231
234
  }
232
- case 40:
235
+ case 9:
233
236
  console.log('Plugin', process.env.PLUGIN);
234
237
  if (!(process.env.PLUGIN === 'hapi-swagger' && serverMode === 'api')) {
235
- _context.next = 49;
238
+ _context.n = 11;
236
239
  break;
237
240
  }
238
241
  swaggerOptions = {
@@ -257,27 +260,27 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
257
260
  swaggerOptions = _objectSpread(_objectSpread({}, swaggerOptions), override);
258
261
  }
259
262
  debug('Swagger Options:', swaggerOptions);
260
- _context.next = 47;
263
+ _context.n = 10;
261
264
  return hapiServer.register({
262
265
  plugin: serverMode,
263
266
  options: swaggerOptions
264
267
  });
265
- case 47:
266
- _context.next = 50;
268
+ case 10:
269
+ _context.n = 12;
267
270
  break;
268
- case 49:
271
+ case 11:
269
272
  if (process.env.PLUGIN == 'hapi-openapi' && serverMode === 'api') {
270
273
  console.log('hapi-openapi', 'coming soon');
271
274
  }
272
- case 50:
275
+ case 12:
273
276
  //
274
277
  // Start server
275
278
  //
276
279
  // eslint-disable-next-line no-unused-vars
277
280
  allRoutes = hapiServer.table();
278
- _context.next = 53;
281
+ _context.n = 13;
279
282
  return hapiServer.start();
280
- case 53:
283
+ case 13:
281
284
  hh = hapiServer.info.uri;
282
285
  hh = hh.replace(/0.0.0.0/, 'localhost');
283
286
  console.log('====================================================================================');
@@ -288,9 +291,8 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
288
291
  process.env.APPSERVER = "".concat(hh, "/").concat(process.env.APPNAME);
289
292
  process.env.HEALTH = 'true';
290
293
  console.log('====================================================================================');
291
- case 63:
292
- case "end":
293
- return _context.stop();
294
+ case 14:
295
+ return _context.a(2);
294
296
  }
295
297
  }, _callee);
296
298
  }));
@@ -308,60 +310,63 @@ function getCertificates() {
308
310
  return _getCertificates.apply(this, arguments);
309
311
  }
310
312
  function _getCertificates() {
311
- _getCertificates = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
313
+ _getCertificates = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
312
314
  var options, tlsdir;
313
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
314
- while (1) switch (_context2.prev = _context2.next) {
315
+ return _regenerator().w(function (_context2) {
316
+ while (1) switch (_context2.n) {
315
317
  case 0:
316
318
  options = null;
317
319
  tlsdir = process.env.SSLCERT;
318
320
  if (!(tlsdir != null && tlsdir.trim().length > 0)) {
319
- _context2.next = 7;
321
+ _context2.n = 1;
320
322
  break;
321
323
  }
322
- console.log('ssl CERTIFICATES', tlsdir);
323
- if (fs.existsSync("".concat(tlsdir, "/key.pem")) === true) {
324
- options = {};
325
- options.key = fs.readFileSync("".concat(tlsdir, "/key.pem"), {
326
- encoding: 'utf8'
327
- });
328
- options.cert = fs.readFileSync("".concat(tlsdir, "/crt.pem"), {
329
- encoding: 'utf8'
330
- });
331
- if (fs.existsSync("".concat(tlsdir, "/ca.pem")) === true) {
332
- options.ca = fs.readFileSync("".concat(tlsdir, "/ca.pem"), {
333
- encoding: 'utf8'
334
- });
335
- }
336
- options.rejectUnauthorized = true;
337
- }
338
- _context2.next = 12;
324
+ options = readTLS(tlsdir);
325
+ options.rejectUnauthorized = true;
326
+ _context2.n = 3;
339
327
  break;
340
- case 7:
328
+ case 1:
341
329
  console.log('No SSL certificates found, generating self-signed certificates');
342
- _context2.next = 10;
330
+ _context2.n = 2;
343
331
  return getTls();
344
- case 10:
345
- options = _context2.sent;
332
+ case 2:
333
+ options = _context2.v;
346
334
  options.rejectUnauthorized = false;
347
- case 12:
348
- return _context2.abrupt("return", options);
349
- case 13:
350
- case "end":
351
- return _context2.stop();
335
+ case 3:
336
+ return _context2.a(2, options);
352
337
  }
353
338
  }, _callee2);
354
339
  }));
355
340
  return _getCertificates.apply(this, arguments);
356
341
  }
342
+ function readTLS(tlsdir) {
343
+ console.log("[Note] Using TLS dir: " + tlsdir);
344
+ if (fs.existsSync(tlsdir) === false) {
345
+ console.log("[Warning] Specified TLS dir does not exist: " + tlsdir);
346
+ return null;
347
+ }
348
+ var listOfFiles = fs.readdirSync(tlsdir);
349
+ console.log("[Note] TLS/SSL files found: " + listOfFiles);
350
+ var options = {};
351
+ for (var i = 0; i < listOfFiles.length; i++) {
352
+ var fname = listOfFiles[i];
353
+ var name = tlsdir + '/' + listOfFiles[i];
354
+ var key = fname.split('.')[0];
355
+ options[key] = fs.readFileSync(name, {
356
+ encoding: 'utf8'
357
+ });
358
+ }
359
+ console.log('TLS FILES', Object.keys(options));
360
+ return options;
361
+ }
357
362
  function getTls() {
358
363
  return _getTls.apply(this, arguments);
359
364
  }
360
365
  function _getTls() {
361
- _getTls = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
366
+ _getTls = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
362
367
  var options, subjt, subj, d, attr, pems, tls;
363
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
364
- while (1) switch (_context3.prev = _context3.next) {
368
+ return _regenerator().w(function (_context3) {
369
+ while (1) switch (_context3.n) {
365
370
  case 0:
366
371
  options = {
367
372
  keySize: 2048,
@@ -428,10 +433,7 @@ function _getTls() {
428
433
  cert: pems.cert,
429
434
  key: pems["private"]
430
435
  };
431
- return _context3.abrupt("return", tls);
432
- case 11:
433
- case "end":
434
- return _context3.stop();
436
+ return _context3.a(2, tls);
435
437
  }
436
438
  }, _callee3);
437
439
  }));
package/lib/index.js CHANGED
@@ -5,29 +5,31 @@ require("regenerator-runtime/runtime");
5
5
  var _fs = _interopRequireDefault(require("fs"));
6
6
  var _iService = _interopRequireDefault(require("./iService"));
7
7
  var _config = _interopRequireDefault(require("./config"));
8
+ var _yargs = _interopRequireDefault(require("yargs"));
9
+ var _helpers = require("yargs/helpers");
8
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
- /*
10
- * ------------------------------------------------------------------------------------
11
- * * Copyright (c) SAS Institute Inc.
12
- * * Licensed under the Apache License, Version 2.0 (the 'License');
13
- * * you may not use this file except in compliance with the License.
14
- * * You may obtain a copy of the License at
15
- * *
16
- * * http://www.apache.org/licenses/LICENSE-2.0
17
- * *
18
- * * Unless required by applicable law or agreed to in writing, software
19
- * * distributed under the License is distributed on an 'AS IS' BASIS,
20
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- * ----------------------------------------------------------------------------------------
24
- *
11
+ /*
12
+ * ------------------------------------------------------------------------------------
13
+ * * Copyright (c) SAS Institute Inc.
14
+ * * Licensed under the Apache License, Version 2.0 (the 'License');
15
+ * * you may not use this file except in compliance with the License.
16
+ * * You may obtain a copy of the License at
17
+ * *
18
+ * * http://www.apache.org/licenses/LICENSE-2.0
19
+ * *
20
+ * * Unless required by applicable law or agreed to in writing, software
21
+ * * distributed under the License is distributed on an 'AS IS' BASIS,
22
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ * ----------------------------------------------------------------------------------------
26
+ *
25
27
  */
26
28
 
27
29
  var debug = require("debug")("startup");
28
30
  module.exports = function core(uTable, useDefault, serverMode, customize, swaggerfcn) {
29
- var argv = require("yargs").argv;
30
- var env = argv.env == null ? null : argv.env;
31
+ var argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).argv;
32
+ var env = argv.env == null ? '.env' : argv.env;
31
33
  var appenv = argv.appenv == null ? null : argv.appenv;
32
34
  var docker = argv.docker == null ? null : argv.docker;
33
35
  //process.env.SERVERMODE = serverMode !== null ? "api" : "app";
@@ -93,20 +95,11 @@ function getAllEnv(userData) {
93
95
  console.log('Note: setting host to null');
94
96
  host = null;
95
97
  }
96
-
97
- /*
98
- if (process.env.AUTHTYPE != null) {
99
- process.env.AUTHFLOW = process.env.AUTHTYPE;
100
- }
101
- */
102
-
103
98
  var authflow = trimit("AUTHFLOW");
104
- if (authflow === "authorization_code" || authflow === "code") {
99
+ var pkce = authflow === "pkce" ? true : false;
100
+ if (authflow === "authorization_code" || authflow === "code" || authflow === "server" || authflow === "null" || authflow === "pkce") {
105
101
  authflow = "server";
106
102
  }
107
- if (authflow === null) {
108
- host = null;
109
- }
110
103
  if (host === null) {
111
104
  authflow = null;
112
105
  console.log('Note: setting authflow to null');
@@ -117,7 +110,7 @@ function getAllEnv(userData) {
117
110
  var clientID = trimit("CLIENTID");
118
111
 
119
112
  // eslint-disable-next-line no-unused-vars
120
- var clientSecret = trimit("CLIENTSECRET");
113
+ //let clientSecret = trimit("CLIENTSECRET");
121
114
  var keepAlive = trimit("KEEPALIVE");
122
115
  var appName = trimit("APPNAME");
123
116
  var ns = trimit("NAMESPACE");
@@ -128,6 +121,7 @@ function getAllEnv(userData) {
128
121
  host: host,
129
122
  clientID: clientID,
130
123
  appName: appName,
124
+ pkce: pkce,
131
125
  keepAlive: null,
132
126
  useToken: process.env.USETOKEN,
133
127
  ns: ns,
@@ -184,6 +178,7 @@ function getAllEnv(userData) {
184
178
  }
185
179
  }
186
180
  }
181
+ userData.APPNAME = l.appName;
187
182
  env = {
188
183
  LOGONPAYLOAD: l,
189
184
  APPENV: userData
@@ -1,6 +1,6 @@
1
- /*
2
- * Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
- * SPDX-License-Identifier: Apache-2.0
1
+ /*
2
+ * Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  'use strict';
6
6