@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
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
- 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; }
3
+ 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 }; })(); }
4
+ 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); }
5
5
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
6
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
7
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -10,22 +10,22 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
10
10
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
11
11
  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); }
12
12
  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
- /*
14
- * ------------------------------------------------------------------------------------
15
- * Copyright (c) SAS Institute Inc.
16
- * Licensed under the Apache License, Version 2.0 (the "License");
17
- * you may not use this file except in compliance with the License.
18
- * You may obtain a copy of the License at
19
- *
20
- * http://www.apache.org/licenses/LICENSE-2.0
21
- *
22
- * Unless required by applicable law or agreed to in writing, software
23
- * distributed under the License is distributed on an "AS IS" BASIS,
24
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
- * See the License for the specific language governing permissions and
26
- * limitations under the License.
27
- * ---------------------------------------------------------------------------------------
28
- *
13
+ /*
14
+ * ------------------------------------------------------------------------------------
15
+ * Copyright (c) SAS Institute Inc.
16
+ * Licensed under the Apache License, Version 2.0 (the "License");
17
+ * you may not use this file except in compliance with the License.
18
+ * You may obtain a copy of the License at
19
+ *
20
+ * http://www.apache.org/licenses/LICENSE-2.0
21
+ *
22
+ * Unless required by applicable law or agreed to in writing, software
23
+ * distributed under the License is distributed on an "AS IS" BASIS,
24
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ * See the License for the specific language governing permissions and
26
+ * limitations under the License.
27
+ * ---------------------------------------------------------------------------------------
28
+ *
29
29
  */
30
30
  // lean code to handle of incoming tokens if present
31
31
  // designed to used with appCookie and SASauth
@@ -34,30 +34,27 @@ var Boom = require('@hapi/boom');
34
34
  module.exports = function SASTokenScheme(server, options) {
35
35
  var scheme = {
36
36
  authenticate: function () {
37
- var _authenticate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request, h) {
37
+ var _authenticate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(request, h) {
38
38
  var authorization, _authorization$split, _authorization$split2, tokenType, token, credentials;
39
- return _regeneratorRuntime().wrap(function _callee$(_context) {
40
- while (1) switch (_context.prev = _context.next) {
39
+ return _regenerator().w(function (_context) {
40
+ while (1) switch (_context.n) {
41
41
  case 0:
42
42
  authorization = request.headers.authorization;
43
43
  server.log('SASToken', authorization);
44
44
  if (authorization) {
45
- _context.next = 4;
45
+ _context.n = 1;
46
46
  break;
47
47
  }
48
48
  throw Boom.unauthorized(null, 'session');
49
- case 4:
49
+ case 1:
50
50
  _authorization$split = authorization.split(' '), _authorization$split2 = _slicedToArray(_authorization$split, 2), tokenType = _authorization$split2[0], token = _authorization$split2[1];
51
51
  credentials = {
52
52
  token: token,
53
53
  tokenType: tokenType
54
54
  };
55
- return _context.abrupt("return", h.authenticated({
55
+ return _context.a(2, h.authenticated({
56
56
  credentials: credentials
57
57
  }));
58
- case 7:
59
- case "end":
60
- return _context.stop();
61
58
  }
62
59
  }, _callee);
63
60
  }));
package/mcpServer.js ADDED
@@ -0,0 +1,364 @@
1
+ /*
2
+ * Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ let core = require('./lib/index.js');
6
+ debugger;
7
+ core(getCustomHandler, true, 'app', null);
8
+
9
+ function getCustomHandler() {
10
+ let appName = `/${process.env.APPNAME}`; /* does not have to be this - your choice */
11
+ debugger;
12
+ let routes = [
13
+ {
14
+ method: ["GET"],
15
+ path: "/help",
16
+ options: {
17
+ files: {
18
+ relativeTo: "./public",
19
+ },
20
+ handler: async (req, h) => {
21
+ debugger;
22
+ let hf = 'help.html';
23
+ return h.file(hf);
24
+ },
25
+ auth: false,
26
+ description: "Help",
27
+ notes: "Help",
28
+ tags: ["app"],
29
+ },
30
+ },
31
+ {
32
+ method: ["GET"],
33
+ path: `${appName}/new`,
34
+ options: {
35
+ files: {
36
+ relativeTo: "./public",
37
+ },
38
+ handler: async (req, h) => {
39
+ console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in new');
40
+ return h.file('index.html');
41
+ },
42
+ // auth: 'logon',
43
+ description: "Create new application",
44
+ notes: "Index file created from env data",
45
+ tags: ["app"],
46
+ },
47
+ }
48
+
49
+ ];
50
+ return routes;
51
+ }
52
+ function customize(key, options) {
53
+ let info = {
54
+ swaggerOptions: {
55
+ info: {
56
+ title: "Test API",
57
+ version: "0.0.1",
58
+ description: "This document was auto-generated at run time",
59
+ },
60
+ documentationPage: true,
61
+ documentationPath: `/${process.env.APPNAME}/documentation`,
62
+ swaggerUI: true,
63
+ swaggerUIPath: `/${process.env.APPNAME}/swaggerui`,
64
+ schemes: ["https", "http"],
65
+ cors: true,
66
+ auth: options.authDefault,
67
+ },
68
+ APPENV: {
69
+ x: 1,
70
+ y: 2,
71
+ },
72
+ };
73
+ let r = info[key];
74
+ return r == null ? {} : r;
75
+ }
76
+
77
+ function getIndex() {
78
+
79
+ let template = `
80
+ <html lang="en">
81
+ <head>
82
+ <meta charset="UTF-8" />
83
+
84
+ <script
85
+ crossorigin
86
+ src="https://unpkg.com/react@16/umd/react.production.min.js"
87
+ ></script>
88
+ <script
89
+ crossorigin
90
+ src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"
91
+ ></script>
92
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
93
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.min.js"></script>
94
+ <script src="https://unpkg.com/@sassoftware/restaf@5.2.4/dist/restaf.js"></script>
95
+ <script src="https://unpkg.com/@sassoftware/restaflib@5.2.4/dist/restaflib.js"></script>
96
+
97
+ <style>
98
+ .container {
99
+ display: flex;
100
+ flex-direction: column;
101
+ flex-wrap: nowrap;
102
+ min-height: 800px;
103
+ }
104
+ .elabel {
105
+ display: inline-block;
106
+
107
+ clear: left;
108
+ width: 250px;
109
+ text-align: right;
110
+ }
111
+ .einput {
112
+ display: inline-block;
113
+ }
114
+ .div1 {
115
+ border: 1px solid black;
116
+ background: lightskyblue;
117
+ }
118
+ .div2 {
119
+ border: 1px solid black;
120
+ background: lightskyblue;
121
+ height: 200px;
122
+ }
123
+ </style>
124
+
125
+ <script>
126
+ let LOGONPAYLOAD = {
127
+ host: "${process.env.VIYA_SERVER}",
128
+ authType: "server",
129
+ appName: "${process.env.APPNAME}",
130
+ };
131
+ </script>
132
+
133
+ <script>
134
+ debugger;
135
+ let store = restaf.initStore({
136
+ casProxy: true});
137
+ debugger; console.log(store.config);
138
+
139
+ let session = null;
140
+ let servers = null;
141
+ let services = null;
142
+ let files = null;
143
+ let reports = null;
144
+ let compute = null;
145
+
146
+ function setup() {
147
+ debugger;
148
+ document.getElementById('output').innerHTML = '...initializing';
149
+
150
+ initSession()
151
+ .then(r => {
152
+ document.getElementById('output').innerHTML = 'ready';
153
+ keepAlive();
154
+ })
155
+ .catch(e => {
156
+
157
+ console.log(e);
158
+ });
159
+ }
160
+
161
+
162
+ async function initSession() {
163
+
164
+ console.log(LOGONPAYLOAD);
165
+ debugger;
166
+ let msg = await store.logon(LOGONPAYLOAD);
167
+ console.log(msg);
168
+
169
+ // let { identities } = await store.addServices('identities');
170
+ let name = 'user';
171
+ // if (identities.links('currentUser') != null) {
172
+ // let c = await store.apiCall(identities.links('currentUser'));
173
+ // name = c.items('id');
174
+ // }
175
+ console.log(name);
176
+ debugger;
177
+ /*
178
+ services = await store.addServices(
179
+ 'files', 'compute', 'casManagement'
180
+ );
181
+ console.log(services.casManagement.links().toJS())
182
+ */
183
+ debugger;
184
+ return 'done';
185
+ }
186
+ function runit(type) {
187
+
188
+
189
+ document.getElementById('output').innerHTML = '...running';
190
+ let testcase;
191
+ switch (type) {
192
+ case 'files': {
193
+ testcase = SASfileService;
194
+ break;
195
+ }
196
+ case 'compute': {
197
+ testcase = dsCompute;
198
+ break;
199
+ }
200
+ case 'cas': {
201
+ testcase = runCas;
202
+ break;
203
+ }
204
+
205
+ case 'spre': {
206
+ testcase= spre;
207
+
208
+ break;
209
+ }
210
+ default: {
211
+ testcase = SASfileService;
212
+ break;
213
+ }
214
+ }
215
+
216
+ testcase(store)
217
+ .then(r => {
218
+ document.getElementById(
219
+ 'output'
220
+ ).innerHTML = JSON.stringify(r, null, 4);
221
+ })
222
+ .catch(err => {
223
+
224
+ document.getElementById(
225
+ 'output'
226
+ ).innerHTML = JSON.stringify(err, null, 4);
227
+ });
228
+ }
229
+ async function noaction() {
230
+ r = {msg: 'redirects completed'};
231
+ return r;
232
+ }
233
+ async function spre(store) {
234
+ let p = {
235
+ method: 'GET',
236
+ url : 'http://localhost:3000/api/test',
237
+ withCredentials: true
238
+ }
239
+ let r = await store.request(p);
240
+ return r.data;
241
+ }
242
+ async function runCas(store) {
243
+
244
+ let {casManagement} = await store.addServices('casManagement');
245
+ let servers = await store.apiCall(
246
+ casManagement.links('servers')
247
+ );
248
+ let serverName = servers.itemsList(0);
249
+ let session = await store.apiCall(
250
+ servers.itemsCmd(serverName, 'createSession')
251
+ );
252
+ let payload = {
253
+ action: 'builtins.echo',
254
+ data: { code: { x: 1 } }
255
+ };
256
+ console.log(JSON.stringify(session.links("execute"), null, 4));
257
+ let r = await store.runAction(session, payload);
258
+ console.log('echo completed');
259
+ await store.apiCall(session.links('delete'));
260
+ return r.items();
261
+ }
262
+
263
+ async function SASfileService(store) {
264
+ debugger;
265
+ let content;
266
+ try {
267
+ debugger;
268
+ let {files} = await store.addServices('files');
269
+ debugger;
270
+ console.log(JSON.stringify(files.links(), null, 4));
271
+ //console.log('items - should be an array of files(empty array is ok)')
272
+ // console.log(files.items().toJS());
273
+ let payload = {
274
+ data: { x: 1, y: 'This was saved earlier in the step' },
275
+ headers: { 'content-type': 'application/json' }
276
+ };
277
+ let createCmd = files.links('create');
278
+ let newFile = await store.apiCall(createCmd, payload);
279
+ debugger;
280
+ console.log(JSON.stringify(newFile.links('content'), null, 4));
281
+ content = await store.apiCall(newFile.links('content'));
282
+
283
+ } catch(err) {
284
+ console.log(JSON.stringify(err, null, 4));
285
+ debugger;
286
+ }
287
+ console.log(content);
288
+ return content.items();
289
+ }
290
+ async function dsCompute(store) {
291
+ let log = null;
292
+ debugger;
293
+ let {compute} = await store.addServices('compute');
294
+ let servers = await store.apiCall(compute.links('servers'));
295
+
296
+ let contexts = await store.apiCall(compute.links('contexts'));
297
+
298
+ // lookup the name of the first context and then use it to get the associated createSession restafLink
299
+ let createSession = contexts.itemsCmd(
300
+ contexts.itemsList(0),
301
+ 'createSession'
302
+ );
303
+ let session = await store.apiCall(createSession);
304
+
305
+ // Now run a simple data step in that session
306
+ let payload = {
307
+ data: {
308
+ code: ["data _null_; do i = 1 to 100; x=1; end; run; "]
309
+ }
310
+ };
311
+
312
+ // Now execute the data step and wait for completion
313
+ let job = await store.apiCall(
314
+ session.links('execute'),
315
+ payload
316
+ );
317
+ let status = await store.jobState(job, null, 5, 2);
318
+
319
+ if (status.data === 'running') {
320
+ throw "ERROR: Job did not complete in allotted time";
321
+ } else {
322
+ switch (status.data) {
323
+ case 'warning':
324
+ console.log("Warning: check your log for warnings");
325
+ break;
326
+ case 'error':
327
+ throw "Please correct errors and rerun program";
328
+ default:
329
+ log = await store.apiCall(status.job.links('log'));
330
+ break;
331
+ }
332
+ }
333
+ return log === null ? status : log.items();
334
+ }
335
+ </script>
336
+ </head>
337
+ <body onload="setup()">
338
+ <h1 id="head">Hi</h1>
339
+ <div>
340
+
341
+ <button onclick="runit('files')">
342
+ Press to make a call to file service
343
+ </button>
344
+ <br />
345
+ <br />
346
+ <button onclick="runit('compute')">
347
+ Press to make a call compute service
348
+ </button>
349
+ <br />
350
+ <br />
351
+ <button onclick="runit('cas')">
352
+ Press to make a call to cas echo
353
+ </button>
354
+ <br />
355
+ <br />
356
+
357
+ <div>
358
+ <pre id="output"></pre>
359
+ </div>
360
+ </body>
361
+ </html>
362
+ `;
363
+ return template;
364
+ }
package/package.json CHANGED
@@ -1,79 +1,85 @@
1
- {
2
- "name": "@sassoftware/viya-serverjs",
3
- "version": "0.3.0",
4
- "description": "Easy to use app server for SAS Viya applications",
5
- "author": "Deva Kumaraswamy <deva.kumar@sas.com>",
6
- "license": "Apache-2.0",
7
- "main": "./lib/index.js",
8
- "bin": {
9
- "@sassoftware/viya-appserverjs": "cli.js"
10
- },
11
- "keywords": [
12
- "restaf",
13
- "Viya",
14
- "SAS",
15
- "server",
16
- "RESTAPI"
17
- ],
18
- "engines": {
19
- "node": ">=20.4.0"
20
- },
21
- "homepage": "https://github.com/sassoftware/viya-server#readme",
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/sassoftware/viya-server.git"
25
- },
26
- "bugs": {
27
- "url": "https://github.com/sassoftware/viya-server/issues"
28
- },
29
- "unpkg": "./lib/index.js",
30
- "scripts": {
31
- "build": "rimraf lib && babel src --out-dir lib",
32
- "test": "cross-env node cli --env=./.env --docker=./Dockerfile",
33
- "server": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node server.js --env=./.env.server --docker=./Dockerfile",
34
- "proxy": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli --env=./.env.proxy --docker=./Dockerfile",
35
- "pub": "npm publish --tag dev --access public",
36
- "lint": "npx eslint --fix src/*.js"
37
- },
38
- "dependencies": {
39
- "@hapi/bell": "^12.3.0",
40
- "@hapi/boom": "^9.1.4",
41
- "@hapi/cookie": "^11.0.2",
42
- "@hapi/h2o2": "^9.1.0",
43
- "@hapi/hapi": "^21.3.2",
44
- "@hapi/inert": "^6.0.5",
45
- "@hapi/vision": "^6.1.0",
46
- "axios": "^1.6.8",
47
- "core-js": "^3.22.2",
48
- "cross-spawn": "^7.0.3",
49
- "debug": "^4.3.4",
50
- "docker-file-parser": "^1.0.7",
51
- "eslint-config-prettier": "^8.5.0",
52
- "handlebars": "^4.7.7",
53
- "hapi-require-https": "^5.0.0",
54
- "joi": "^17.6.0",
55
- "jwt-decode": "^3.1.2",
56
- "node-cache-promise": "^1.0.2",
57
- "only": "0.0.2",
58
- "qs": "^6.10.3",
59
- "regenerator-runtime": "^0.13.9",
60
- "request-debug": "^0.2.0",
61
- "selfsigned": "^2.0.1",
62
- "uuid": "^8.3.2",
63
- "yargs": "17.4.1"
64
- },
65
- "devDependencies": {
66
- "@babel/cli": "^7.17.6",
67
- "@babel/core": "^7.17.9",
68
- "@babel/eslint-parser": "7.19.1",
69
- "@babel/preset-env": "^7.26.0",
70
- "cross-env": "^7.0.3",
71
- "eslint": "^8.14.0",
72
- "prettier": "^2.6.2",
73
- "rimraf": "^3.0.2",
74
- "shx": "^0.3.4"
75
- },
76
- "resolutions": {
77
- "@babel/traverse": "7.26.10"
78
- }
79
- }
1
+ {
2
+ "name": "@sassoftware/viya-serverjs",
3
+ "version": "0.5.0",
4
+ "description": "Easy to use app server for SAS Viya applications",
5
+ "author": "Deva Kumaraswamy <deva.kumar@sas.com>",
6
+ "license": "Apache-2.0",
7
+ "main": "./lib/index.js",
8
+ "bin": {
9
+ "@sassoftware/viya-serverjs": "cli.js"
10
+ },
11
+ "keywords": [
12
+ "restaf",
13
+ "Viya",
14
+ "SAS",
15
+ "server",
16
+ "RESTAPI"
17
+ ],
18
+ "engines": {
19
+ "node": ">=20.4.0"
20
+ },
21
+ "homepage": "https://github.com/sassoftware/viya-server#readme",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/sassoftware/viya-server.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/sassoftware/viya-server/issues"
28
+ },
29
+ "unpkg": "./lib/index.js",
30
+ "scripts": {
31
+ "build": "rimraf lib && babel src --out-dir lib",
32
+ "test": "node cli --env=./.env --docker=./Dockerfile",
33
+ "submit": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 APPENTRY=simplesubmit.html node cli --env=./.env --docker=./Dockerfile",
34
+ "server": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node server.js --env=./.env.server --docker=./Dockerfile",
35
+ "debug": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk server.js --env=./.env.server --docker=./Dockerfile",
36
+ "proxy": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli --env=./.env.proxy --docker=./Dockerfile",
37
+ "pub": "npm publish --tag dev --access public",
38
+ "lint": "npx eslint --fix src/*.js"
39
+ },
40
+ "dependencies": {
41
+ "@hapi/bell": "^13.1.0",
42
+ "@hapi/boom": "^10.0.1",
43
+ "@hapi/cookie": "^12.0.1",
44
+ "@hapi/h2o2": "^10.0.4",
45
+ "@hapi/hapi": "^21.4.4",
46
+ "@hapi/inert": "^7.1.0",
47
+ "@hapi/vision": "^7.0.3",
48
+ "axios": "^1.13.2",
49
+ "core-js": "^3.47.0",
50
+ "cross-spawn": "^7.0.6",
51
+ "debug": "^4.4.3",
52
+ "docker-file-parser": "^1.0.7",
53
+ "eslint-config-prettier": "^10.1.8",
54
+ "handlebars": "^4.7.8",
55
+ "hapi-require-https": "^6.0.0",
56
+ "joi": "^18.0.2",
57
+ "jwt-decode": "^4.0.0",
58
+ "node-cache-promise": "^1.0.2",
59
+ "only": "0.0.2",
60
+ "qs": "^6.14.0",
61
+ "regenerator-runtime": "^0.14.1",
62
+ "request-debug": "^0.2.0",
63
+ "selfsigned": "^5.4.0",
64
+ "uuid": "^13.0.0",
65
+ "yargs": "18.0.0"
66
+ },
67
+ "devDependencies": {
68
+ "@babel/cli": "^7.28.3",
69
+ "@babel/core": "^7.28.5",
70
+ "@babel/eslint-parser": "7.28.5",
71
+ "@babel/preset-env": "^7.28.5",
72
+ "cross-env": "^10.1.0",
73
+ "eslint": "^9.39.2",
74
+ "prettier": "^3.7.4",
75
+ "rimraf": "^6.1.2",
76
+ "shx": "^0.4.0"
77
+ },
78
+ "resolutions": {
79
+ "@babel/traverse": "7.26.10"
80
+ },
81
+ "overrides": {
82
+ "gopd": "1.2.0",
83
+ "get-intrinsic": "1.2.7"
84
+ }
85
+ }