@sassoftware/viya-serverjs 0.0.3 → 0.1.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.
@@ -25,12 +25,6 @@ exports["default"] = void 0;
25
25
  var _parseDocker = _interopRequireDefault(require("./parseDocker"));
26
26
  var _debug = _interopRequireDefault(require("debug"));
27
27
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
28
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
29
- 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."); }
30
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
31
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
32
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
33
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
34
28
  var fs = require('fs');
35
29
  var configDebug = (0, _debug["default"])('config');
36
30
  function config(appEnv, dockerFile) {
@@ -88,18 +82,12 @@ function iconfig(appEnv) {
88
82
  var d = data.split(/\r?\n/);
89
83
  d.forEach(function (l) {
90
84
  if (l.length > 0 && l.indexOf('#') === -1) {
91
- var _l$split = l.split('='),
92
- _l$split2 = _slicedToArray(_l$split, 2),
93
- envName = _l$split2[0],
94
- value = _l$split2[1];
95
- if (value.trim().length > 0) {
96
- if (value.startsWith('$')) {
97
- var envVar = value.substring(1);
98
- value = process.env[envVar];
99
- }
100
- process.env[envName] = value;
85
+ var la = l.split('=');
86
+ var envName = la[0];
87
+ if (la.length === 2 && la[1].length > 0) {
88
+ process.env[envName] = la[1];
101
89
  }
102
- configDebug(envName, '=', value);
90
+ configDebug(la[1]);
103
91
  }
104
92
  });
105
93
  } catch (err) {
@@ -20,7 +20,7 @@ function codeAuth(_x, _x2, _x3) {
20
20
  }
21
21
  function _codeAuth() {
22
22
  _codeAuth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, h, options) {
23
- var cookieResult, indexHTML;
23
+ var indexHTML;
24
24
  return _regeneratorRuntime().wrap(function _callee$(_context) {
25
25
  while (1) switch (_context.prev = _context.next) {
26
26
  case 0:
@@ -28,33 +28,29 @@ function _codeAuth() {
28
28
  _context.next = 3;
29
29
  return (0, _setCookies["default"])(req, h, options);
30
30
  case 3:
31
- cookieResult = _context.sent;
32
- console.log('cookieResult:', cookieResult);
33
- debug('options', options);
31
+ console.log(options);
34
32
  indexHTML = process.env.APPENTRY == null ? 'index.html' : process.env.APPENTRY;
35
- debug('indexHTML', indexHTML);
36
- if (process.env.REDIRECT !== undefined) {
37
- debug('..redirect', process.env.REDIRECT);
33
+ if (process.env.REDIRECT != null) {
38
34
  debug('using REDIRECT env variable', process.env.REDIRECT);
39
35
  indexHTML = process.env.REDIRECT;
40
36
  }
41
- debug('..................', indexHTML);
42
- debugger;
37
+ console.log('..................', indexHTML);
43
38
  if (!(indexHTML.indexOf('/') === 0)) {
44
- _context.next = 16;
39
+ _context.next = 13;
45
40
  break;
46
41
  }
47
42
  // added to support create-react-restaf-viya-app cli
48
43
  if (indexHTML !== '/develop') {
49
- /* hmr support */
50
- indexHTML = "/".concat(process.env.APPNAME, "/").concat(indexHTML);
44
+ indexHTML = "/".concat(process.env.APPNAME).concat(indexHTML);
51
45
  }
46
+ console.log("Redirecting to ".concat(indexHTML));
52
47
  return _context.abrupt("return", h.redirect(indexHTML));
53
- case 16:
54
- // return h.file(indexHTML);
55
- console.log('redirecting to :', "/".concat(indexHTML));
48
+ case 13:
49
+ console.log("Redirecting to ".concat(indexHTML));
56
50
  return _context.abrupt("return", h.file(indexHTML));
57
- case 18:
51
+ case 15:
52
+ ;
53
+ case 16:
58
54
  case "end":
59
55
  return _context.stop();
60
56
  }
@@ -13,84 +13,54 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
13
13
  * Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
14
14
  * SPDX-License-Identifier: Apache-2.0
15
15
  */
16
- var debug = require("debug")("getapp");
16
+ var debug = require('debug')('getapp');
17
17
  function getApp(_x, _x2, _x3) {
18
18
  return _getApp.apply(this, arguments);
19
19
  }
20
20
  function _getApp() {
21
- _getApp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options, req, h) {
22
- var authType, indexHTML, handleImplicit, _handleImplicit;
23
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
24
- while (1) switch (_context2.prev = _context2.next) {
21
+ _getApp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options, req, h) {
22
+ var x, redirect, redirectUri, protocol, url, indexHTML;
23
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
24
+ while (1) switch (_context.prev = _context.next) {
25
25
  case 0:
26
- _handleImplicit = function _handleImplicit3() {
27
- _handleImplicit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options, req, h) {
28
- var x, redirect, redirectUri, protocol, url;
29
- return _regeneratorRuntime().wrap(function _callee$(_context) {
30
- while (1) switch (_context.prev = _context.next) {
31
- case 0:
32
- if (!(process.env.AUTHFLOW === "implicit")) {
33
- _context.next = 8;
34
- break;
35
- }
36
- x = "".concat(process.env.VIYA_SERVER, "/SASLogon/oauth/authorize?response_type=token&client_id=").concat(process.env.CLIENTID);
37
- redirect = "".concat(process.env.APPNAME, "/callback");
38
- if (process.env.REDIRECT != null) {
39
- redirect = process.env.REDIRECT.trim();
40
- if (redirect.indexOf("http") === -1) {
41
- redirect = "".concat(process.env.APPNAME, "/").concat(redirect);
42
- protocol = process.env.HTTPS === "true" ? "https://" : "http://";
43
- redirectUri = "".concat(protocol).concat(process.env.APPHOST, ":").concat(process.env.APPPORT, "/").concat(redirect, "?host=").concat(process.env.VIYA_SERVER);
44
- } else {
45
- redirectUri = "".concat(redirect, "?host=").concat(process.env.VIYA_SERVER);
46
- }
47
- }
48
- debug(process.env.REDIRECT);
49
- url = "".concat(x, "&redirect_uri=").concat(redirectUri);
50
- debug(url);
51
- return _context.abrupt("return", h.redirect(url));
52
- case 8:
53
- case "end":
54
- return _context.stop();
55
- }
56
- }, _callee);
57
- }));
58
- return _handleImplicit.apply(this, arguments);
59
- };
60
- handleImplicit = function _handleImplicit2(_x4, _x5, _x6) {
61
- return _handleImplicit.apply(this, arguments);
62
- };
63
- debugger;
64
- ;
65
- authType = process.env.AUTHFLOW.trim();
66
- if (!(authType === "implicit")) {
67
- _context2.next = 9;
26
+ if (!(process.env.AUTHFLOW === 'implicit')) {
27
+ _context.next = 10;
68
28
  break;
69
29
  }
70
- debugger;
71
- debug("calling handleImplicit");
72
- return _context2.abrupt("return", handleImplicit(options, req, h));
73
- case 9:
74
- if (!(authType === "server")) {
75
- _context2.next = 14;
76
- break;
30
+ x = "".concat(process.env.VIYA_SERVER, "/SASLogon/oauth/authorize?response_type=token&client_id=").concat(process.env.CLIENTID);
31
+ redirect = "".concat(process.env.APPNAME, "/callback");
32
+ if (process.env.REDIRECT != null) {
33
+ redirect = process.env.REDIRECT.trim();
34
+ if (redirect.indexOf('http') === -1) {
35
+ redirect = "".concat(process.env.APPNAME, "/").concat(redirect);
36
+ protocol = process.env.HTTPS === 'true' ? 'https://' : 'http://';
37
+ redirectUri = "".concat(protocol).concat(process.env.APPHOST, ":").concat(process.env.APPPORT, "/").concat(redirect, "?host=").concat(process.env.VIYA_SERVER);
38
+ } else {
39
+ redirectUri = "".concat(redirect, "?host=").concat(process.env.VIYA_SERVER);
40
+ }
77
41
  }
78
- debugger;
79
- return _context2.abrupt("return", (0, _codeAuth["default"])(req, h, options));
80
- case 14:
81
- if (!(authType === null)) {
82
- _context2.next = 18;
42
+ debug(process.env.REDIRECT);
43
+ url = "".concat(x, "&redirect_uri=").concat(redirectUri);
44
+ debug(url);
45
+ return _context.abrupt("return", h.redirect(url));
46
+ case 10:
47
+ if (!(process.env.AUTHFLOW === 'server')) {
48
+ _context.next = 16;
83
49
  break;
84
50
  }
85
- /* case of no auth */
86
- indexHTML = process.env.APPENTRY == null ? "index.html" : process.env.APPENTRY;
51
+ debugger;
52
+ debug('calling codeauth');
53
+ return _context.abrupt("return", (0, _codeAuth["default"])(req, h, options));
54
+ case 16:
55
+ debug('default getapp');
56
+ indexHTML = process.env.APPENTRY == null ? 'index.html' : process.env.APPENTRY;
87
57
  console.log("Redirecting to default ".concat(indexHTML));
88
- return _context2.abrupt("return", h.file(indexHTML));
89
- case 18:
58
+ return _context.abrupt("return", h.file(indexHTML));
59
+ case 20:
90
60
  case "end":
91
- return _context2.stop();
61
+ return _context.stop();
92
62
  }
93
- }, _callee2);
63
+ }, _callee);
94
64
  }));
95
65
  return _getApp.apply(this, arguments);
96
66
  }
@@ -36,9 +36,8 @@ function _getApp() {
36
36
  case 0:
37
37
  debug('in getApp2');
38
38
  debug(req.params);
39
- console.log(h.request.auth);
40
39
  return _context.abrupt("return", h.file("".concat(req.params.param)));
41
- case 4:
40
+ case 3:
42
41
  case "end":
43
42
  return _context.stop();
44
43
  }
@@ -22,24 +22,23 @@ function _getUser() {
22
22
  return _regeneratorRuntime().wrap(function _callee$(_context) {
23
23
  while (1) switch (_context.prev = _context.next) {
24
24
  case 0:
25
- debugger;
26
25
  debug(req.state);
27
26
  name = 'SAS User';
28
27
  if (!(req.state.ocookie != null)) {
29
- _context.next = 10;
28
+ _context.next = 9;
30
29
  break;
31
30
  }
32
31
  sid = req.state.ocookie.sid;
33
32
  debug(sid);
34
- _context.next = 8;
33
+ _context.next = 7;
35
34
  return req.server.app.cache.get(sid);
36
- case 8:
35
+ case 7:
37
36
  credentials = _context.sent;
38
37
  name = credentials.user_name;
39
- case 10:
38
+ case 9:
40
39
  debug(name);
41
40
  return _context.abrupt("return", "let USER_NAME='".concat(name, "'"));
42
- case 12:
41
+ case 11:
43
42
  case "end":
44
43
  return _context.stop();
45
44
  }
@@ -52,7 +52,6 @@ function _refreshToken() {
52
52
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
53
53
  while (1) switch (_context2.prev = _context2.next) {
54
54
  case 0:
55
- debugger;
56
55
  credentials = req.auth.credentials;
57
56
  sid = credentials.sid;
58
57
  config = {
@@ -69,28 +68,28 @@ function _refreshToken() {
69
68
  client_secret: process.env.CLIENTSECRET
70
69
  })
71
70
  };
72
- _context2.prev = 4;
73
- _context2.next = 7;
71
+ _context2.prev = 3;
72
+ _context2.next = 6;
74
73
  return (0, _axios["default"])(config);
75
- case 7:
74
+ case 6:
76
75
  r = _context2.sent;
77
76
  newcred = _objectSpread({}, credentials);
78
77
  newcred.token = r.data.access_token;
79
78
  newcred.refreshToken = r.data.refresh_token;
80
- _context2.next = 13;
79
+ _context2.next = 12;
81
80
  return req.server.app.cache.set(sid, credentials);
82
- case 13:
81
+ case 12:
83
82
  return _context2.abrupt("return", credentials);
84
- case 16:
85
- _context2.prev = 16;
86
- _context2.t0 = _context2["catch"](4);
83
+ case 15:
84
+ _context2.prev = 15;
85
+ _context2.t0 = _context2["catch"](3);
87
86
  error = Boom.badRequest('Unable to refresh tokens in KeepAlive', JSON.stringify(_context2.t0, null, 4));
88
87
  throw error;
89
- case 20:
88
+ case 19:
90
89
  case "end":
91
90
  return _context2.stop();
92
91
  }
93
- }, _callee2, null, [[4, 16]]);
92
+ }, _callee2, null, [[3, 15]]);
94
93
  }));
95
94
  return _refreshToken.apply(this, arguments);
96
95
  }
@@ -4,47 +4,34 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- 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); }
8
- 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 new 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 new 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 new 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; }
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
11
- function proxyMapUri(_x) {
12
- return _proxyMapUri.apply(this, arguments);
13
- }
14
- function _proxyMapUri() {
15
- _proxyMapUri = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
16
- var credentials, sid, path, params, search, uri;
17
- return _regeneratorRuntime().wrap(function _callee$(_context) {
18
- while (1) switch (_context.prev = _context.next) {
19
- case 0:
20
- debugger;
21
- credentials = req.auth.credentials;
22
- console.log('------------------------------------------');
23
- if (credentials != null) {
24
- sid = credentials.sid;
25
- console.log('sid=', sid);
26
- }
27
- path = process.env.PROXYSERVER;
28
- console.log('proxying to= ', path);
29
- params = req.params;
30
- console.log('params=', params);
31
- search = req.url.search;
32
- console.log('query=', search);
33
- uri = path + '/' + params.param;
34
- if (search != null && search.trim().length > 0) {
35
- uri = uri + search;
36
- }
37
- console.log('destination= ', uri);
38
- return _context.abrupt("return", {
39
- uri: uri
40
- });
41
- case 14:
42
- case "end":
43
- return _context.stop();
44
- }
45
- }, _callee);
46
- }));
47
- return _proxyMapUri.apply(this, arguments);
7
+ function proxyMapUri(req) {
8
+ var credentials = req.auth.credentials;
9
+ console.log('------------------------------------------');
10
+ if (credentials != null) {
11
+ var sid = credentials.sid;
12
+ console.log('sid=', sid);
13
+ }
14
+ var path = process.env.PROXYSERVER;
15
+ console.log('proxying to= ', path);
16
+ var params = req.params;
17
+ console.log('params=', params);
18
+ var search = req.url.search;
19
+ console.log('query=', search);
20
+ var uri = path + '/' + params.param;
21
+ if (search != null && search.trim().length > 0) {
22
+ uri = uri + search;
23
+ }
24
+ console.log('destination= ', uri);
25
+ var r = {
26
+ uri: uri
27
+ };
28
+ if (credentials) {
29
+ console.log('credentials.token=', credentials.token);
30
+ r.headers = {
31
+ Authorization: "Bearer ".concat(credentials.token)
32
+ };
33
+ }
34
+ return r;
48
35
  }
49
36
  var _default = exports["default"] = proxyMapUri;
50
37
  /*
@@ -36,7 +36,7 @@ function _reactDev() {
36
36
  while (1) switch (_context.prev = _context.next) {
37
37
  case 0:
38
38
  console.log('Spawning the dev server');
39
- spawn('npm', ['start:appjs'], {
39
+ spawn('yarn', ['start'], {
40
40
  stdio: 'inherit'
41
41
  });
42
42
  h2 = '<h2>Viya Server: ' + process.env.VIYA_SERVER + '<h2>';
@@ -19,56 +19,56 @@ function setCookies(_x, _x2, _x3) {
19
19
  }
20
20
  function _setCookies() {
21
21
  _setCookies = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, h, options) {
22
- var authCred, sid, credentials, redirect;
22
+ var credentials, sid, redirect;
23
23
  return _regeneratorRuntime().wrap(function _callee$(_context) {
24
24
  while (1) switch (_context.prev = _context.next) {
25
25
  case 0:
26
- authCred = req.auth.credentials;
26
+ credentials = req.auth.credentials;
27
27
  debugger;
28
- req.log('setcookie', authCred);
29
- if (!(authCred != null && req.auth.error != null)) {
30
- _context.next = 6;
28
+ req.log('setcookie', credentials);
29
+ if (!(credentials != null && req.auth.error != null)) {
30
+ _context.next = 8;
31
31
  break;
32
32
  }
33
33
  debug('logon failed');
34
+ console.log(req.auth.error);
35
+ debug('req.auth.error', req.auth.error);
34
36
  return _context.abrupt("return", {
35
37
  status: false,
36
38
  error: req.auth.error
37
39
  });
38
- case 6:
40
+ case 8:
39
41
  // create a cookie(sid) and save credentials in cache
40
42
  sid = uuid.v4();
41
- credentials = {
42
- token: authCred.token,
43
- refreshToken: authCred.refreshToken,
44
- sid: sid,
45
- user_name: ''
46
- };
47
- if (process.env.USETOKEN === 'YES') {
48
- options.allAppEnv.LOGONPAYLOAD.token = authCred.token;
43
+ credentials.sid = sid;
44
+ if (options != null) {
45
+ options.allAppEnv.LOGONPAYLOAD.token = credentials.token;
49
46
  options.allAppEnv.LOGONPAYLOAD.tokenType = 'bearer';
50
47
  debug(options.allAppEnv.LOGONPAYLOAD);
51
48
  }
52
- _context.next = 11;
49
+ debug('credentials', credentials);
50
+ _context.next = 14;
53
51
  return req.server.app.cache.set(sid, credentials, 0);
54
- case 11:
55
- debugger;
56
- console.log(h.request.auth);
57
- debugger;
58
- //req.cookieAuth.set({ sid });
59
-
60
- debugger;
61
- // await req.server.app.cache.set(sid, credentials);
62
- debugger;
63
- debug('authcred query:', authCred.query);
64
- redirect = authCred.query != null && authCred.query.next != null ? credentials.query.next : null;
52
+ case 14:
53
+ // Can we get away without setting cookie for this session?
54
+ // Need to also modify keepAlive
55
+ if (process.env.COOKIES !== 'NO') {
56
+ req.cookieAuth.set({
57
+ sid: sid
58
+ });
59
+ }
60
+ ;
61
+ req.log('credentialsquery', credentials.query);
62
+ debug(credentials.query);
63
+ redirect = credentials.query != null && credentials.query.next != null ? credentials.query.next : null;
64
+ debug('redirect', redirect);
65
65
  req.server.log('setcookie-redirect', redirect);
66
66
  return _context.abrupt("return", {
67
67
  status: true,
68
68
  error: null,
69
69
  redirect: redirect
70
70
  });
71
- case 20:
71
+ case 22:
72
72
  case "end":
73
73
  return _context.stop();
74
74
  }
@@ -103,11 +103,10 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
103
103
  };
104
104
  if (process.env.HAPIDEBUG === 'YES') {
105
105
  sConfig.debug = {
106
- log: ['hapi'],
107
- request: ['hapi']
106
+ request: '*'
108
107
  };
109
108
  }
110
- debug('sConfig:', JSON.stringify(sConfig, null, 4));
109
+ debug(JSON.stringify(sConfig, null, 4));
111
110
  if (!(process.env.HTTPS === 'true')) {
112
111
  _context.next = 16;
113
112
  break;
package/lib/core/index.js CHANGED
@@ -27,11 +27,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
27
27
  var debug = require("debug")("startup");
28
28
  module.exports = function core(uTable, useDefault, serverMode, customize, swaggerfcn) {
29
29
  var argv = require("yargs").argv;
30
- debug(argv);
31
30
  var env = argv.env == null ? null : argv.env;
32
31
  var appenv = argv.appenv == null ? null : argv.appenv;
33
32
  var docker = argv.docker == null ? null : argv.docker;
34
- process.env.SERVERMODE = serverMode !== null ? process.env.SERVERMODE : "app";
33
+ process.env.SERVERMODE = serverMode !== null ? "api" : "app";
35
34
  if (useDefault == null) {
36
35
  useDefault = true;
37
36
  }
@@ -87,7 +86,6 @@ function createPayload(srcName, cb) {
87
86
  function getAllEnv(userData) {
88
87
  var env;
89
88
  var l = null;
90
- debugger;
91
89
  if (process.env.AUTHTYPE != null) {
92
90
  process.env.AUTHFLOW = process.env.AUTHTYPE;
93
91
  }
@@ -96,6 +94,7 @@ function getAllEnv(userData) {
96
94
  authflow = "server";
97
95
  }
98
96
  process.env.AUTHFLOW = authflow;
97
+ // let redirect = (process.env.REDIRECT != null) ? process.env.REDIRECT : null;
99
98
  var redirect = trimit("REDIRECT");
100
99
  var host = trimit("VIYA_SERVER");
101
100
  var clientID = trimit("CLIENTID");
@@ -105,64 +104,76 @@ function getAllEnv(userData) {
105
104
  var appName = trimit("APPNAME");
106
105
  var ns = trimit("NAMESPACE");
107
106
  var nsHost = trimit("NSHOST");
108
- var appEntry = trimit("APPENTRY");
109
- if (appEntry === null) {
110
- appEntry = "index.html";
111
- process.env.APPENTRY = appEntry;
112
- }
113
- ;
114
107
  l = {
115
108
  authType: authflow,
116
109
  redirect: redirect,
117
110
  host: host,
118
111
  clientID: clientID,
119
- clientSecret: clientSecret,
120
112
  appName: appName,
121
- appEntry: appEntry,
122
113
  keepAlive: null,
123
114
  useToken: process.env.USETOKEN,
124
115
  ns: ns,
125
116
  nsHost: nsHost
126
117
  };
127
- if (authflow !== null) {
118
+ if (authflow === "server" || authflow === "implicit") {
128
119
  if (authflow === "implicit") {
129
120
  if (redirect === null) {
130
121
  redirect = "".concat(appName, "/callback");
131
- ;
122
+ process.env.REDIRECT = "callback";
123
+ } else {
124
+ if (redirect !== null && redirect.indexOf("/") !== 0) {
125
+ redirect = redirect.indexOf("http") != -1 ? redirect : "".concat(process.env.APPNAME, "/").concat(redirect);
126
+ }
132
127
  }
133
- }
134
- if (redirect !== null && redirect.indexOf("/") !== 0) {
135
- if (redirect.indexOf("/") !== 0) {
136
- redirect = redirect.indexOf("http") != -1 ? redirect : "".concat(process.env.APPNAME, "/").concat(redirect);
128
+ l = {
129
+ authType: authflow,
130
+ redirect: redirect,
131
+ host: host,
132
+ clientID: clientID,
133
+ appName: appName,
134
+ keepAlive: null,
135
+ useToken: process.env.USETOKEN,
136
+ ns: ns,
137
+ nsHost: nsHost
138
+ };
139
+ if (authflow === "server" && keepAlive === "YES") {
140
+ var protocol = process.env.HTTPS === "true" ? "https://" : "http://";
141
+ l.keepAlive = "".concat(protocol).concat(process.env.APPHOST, ":").concat(process.env.APPPORT, "/").concat(appName, "/keepAlive");
142
+ l.keepAlive = l.keepAlive.replace(/0.0.0.0/, "localhost");
143
+ }
144
+ if (process.env.TIMERS != null) {
145
+ l.timers = process.env.TIMERS;
137
146
  }
138
147
  }
139
- /*
140
- if (redirect === null) {
141
- redirect = `${appName}`;
142
- }*/
143
- }
144
-
145
- // process.env.REDIRECT = redirect;
146
- console.log("Redirect: ".concat(redirect));
147
- console.log(process.env.REDIRECT);
148
- l.redirect = redirect;
149
- if (authflow === "server" && keepAlive === "YES") {
150
- var protocol = process.env.HTTPS === "true" ? "https://" : "http://";
151
- l.keepAlive = "".concat(protocol).concat(process.env.APPHOST, ":").concat(process.env.APPPORT, "/").concat(appName, "/keepAlive");
152
- l.keepAlive = l.keepAlive.replace(/0.0.0.0/, "localhost");
153
- }
154
- if (process.env.TIMERS != null) {
155
- l.timers = process.env.TIMERS;
148
+ // allow for no authtype
149
+ l = {
150
+ authType: authflow,
151
+ redirect: redirect,
152
+ host: host,
153
+ clientID: clientID,
154
+ appName: appName,
155
+ keepAlive: null,
156
+ useToken: process.env.USETOKEN,
157
+ ns: ns,
158
+ nsHost: nsHost
159
+ };
156
160
  }
157
161
 
158
162
  // pick up the app env's - replacement for appenv.js
159
163
  // appenv.js still supported for backward compatibility
164
+
160
165
  for (var key in process.env) {
166
+ debug(key);
161
167
  if (key.indexOf("APPENV_") === 0) {
162
168
  var k = key.substring(7);
163
169
  var v = process.env[key];
164
170
  if (v != null && v.trim().length > 0) {
165
- userData[k] = v.trim();
171
+ if (v.startsWith('$')) {
172
+ v = process.env[v.substring(1)];
173
+ }
174
+ userData[k] = v != null ? v.trim() : null;
175
+ } else {
176
+ userData[k] = null;
166
177
  }
167
178
  }
168
179
  }
@@ -176,7 +187,7 @@ function getAllEnv(userData) {
176
187
  }
177
188
  function trimit(e) {
178
189
  var a = process.env[e];
179
- if (a === undefined) {
190
+ if (a == null || a === undefined) {
180
191
  return null;
181
192
  }
182
193
  a = a.trim();
@@ -62,17 +62,8 @@ function _iSASauth() {
62
62
  return _regeneratorRuntime().wrap(function _callee$(_context) {
63
63
  while (1) switch (_context.prev = _context.next) {
64
64
  case 0:
65
- debugger;
66
- console.log('in profile', credentials);
67
- debug(credentials);
68
- debug(params);
69
- debugger;
70
-
71
- //let r = await get();
72
- //debug(r);
73
- debugger;
74
65
  server.log('SASAuth profile', credentials);
75
- case 7:
66
+ case 1:
76
67
  case "end":
77
68
  return _context.stop();
78
69
  }
@@ -32,19 +32,16 @@ module.exports = /*#__PURE__*/function () {
32
32
  return _regeneratorRuntime().wrap(function _callee$(_context) {
33
33
  while (1) switch (_context.prev = _context.next) {
34
34
  case 0:
35
- debugger;
36
- debug('in validateFunc');
37
- debug(req.path);
38
35
  server.log('Cookie validateFunc', "path - ".concat(req.path));
39
36
  if (!(session == null)) {
40
- _context.next = 7;
37
+ _context.next = 4;
41
38
  break;
42
39
  }
43
40
  console.log('session is null');
44
41
  return _context.abrupt("return", {
45
42
  valid: false
46
43
  });
47
- case 7:
44
+ case 4:
48
45
  credentials = null;
49
46
  if (Array.isArray(session) === true && session.length > 0) {
50
47
  sid = session[0].sid;
@@ -52,29 +49,28 @@ module.exports = /*#__PURE__*/function () {
52
49
  sid = session.sid;
53
50
  }
54
51
  if (!(sid != null)) {
55
- _context.next = 13;
52
+ _context.next = 10;
56
53
  break;
57
54
  }
58
- _context.next = 12;
55
+ _context.next = 9;
59
56
  return req.server.app.cache.get(sid);
60
- case 12:
57
+ case 9:
61
58
  credentials = _context.sent;
62
- case 13:
59
+ case 10:
63
60
  if (!(credentials == null)) {
64
- _context.next = 15;
61
+ _context.next = 12;
65
62
  break;
66
63
  }
67
64
  return _context.abrupt("return", {
68
65
  valid: false
69
66
  });
70
- case 15:
67
+ case 12:
71
68
  server.log('Cookie validateFunc', sid);
72
- debug(sid);
73
69
  return _context.abrupt("return", {
74
70
  valid: true,
75
71
  credentials: credentials
76
72
  });
77
- case 18:
73
+ case 14:
78
74
  case "end":
79
75
  return _context.stop();
80
76
  }
@@ -86,8 +82,8 @@ module.exports = /*#__PURE__*/function () {
86
82
  return validateFunc;
87
83
  }()
88
84
  }; // console.log('cookie options', cookieOptions);
89
- server.log('Cookie Options', cookieOptions);
90
85
  debug('Cookie Options', cookieOptions);
86
+ server.log('Cookie Options', cookieOptions);
91
87
  server.auth.strategy('session', 'cookie', cookieOptions);
92
88
  case 6:
93
89
  case "end":
@@ -35,7 +35,6 @@ function _setContext() {
35
35
  while (1) switch (_context.prev = _context.next) {
36
36
  case 0:
37
37
  credentials = req.auth.credentials;
38
- debugger;
39
38
  context = {
40
39
  path: req.path,
41
40
  params: req.params,
@@ -45,7 +44,7 @@ function _setContext() {
45
44
  host: process.env.VIYA_SERVER
46
45
  };
47
46
  return _context.abrupt("return", context);
48
- case 4:
47
+ case 3:
49
48
  case "end":
50
49
  return _context.stop();
51
50
  }
@@ -42,11 +42,7 @@ module.exports = function setDefaultRoutes(server, options) {
42
42
  strategy: 'sas'
43
43
  };
44
44
  }
45
- debug('authDefault', authDefault);
46
- debug('authLogon', authLogon);
47
-
48
- //let getAppb = getApp.bind(null, (process.env.USETOKEN === 'YES' ? options : null));
49
- var getAppb = _handlers.getApp.bind(null, options);
45
+ var getAppb = _handlers.getApp.bind(null, process.env.USETOKEN === 'YES' ? options : null);
50
46
  server.log('Default strategy', authDefault);
51
47
  server.log('Logon strategy', authLogon);
52
48
  options.authDefault = authDefault;
@@ -115,14 +111,6 @@ module.exports = function setDefaultRoutes(server, options) {
115
111
  cors: true,
116
112
  handler: _handlers.reactDev
117
113
  }
118
- }, {
119
- method: ['GET'],
120
- path: "".concat(appName, "/develop"),
121
- options: {
122
- auth: false,
123
- cors: true,
124
- handler: _handlers.reactDev
125
- }
126
114
  }, {
127
115
  method: ['GET'],
128
116
  path: "".concat(appName, "/logon"),
@@ -197,38 +185,15 @@ module.exports = function setDefaultRoutes(server, options) {
197
185
  method: ['GET'],
198
186
  path: "".concat(appName, "/{param*}"),
199
187
  options: {
200
- auth: authLogon,
201
- /*authDefault,*/
202
-
203
- // handler: getApp2,
204
- handler: {
205
- file: function file(req, h) {
206
- debugger;
207
- console.log('in file1 handler');
208
- console.log(req.auth);
209
- console.log(req.params);
210
- return req.params.param;
211
- }
212
- }
188
+ auth: authDefault,
189
+ handler: _handlers.getApp2
213
190
  }
214
191
  }, {
215
192
  method: ['GET'],
216
193
  path: "/{param*}",
217
194
  options: {
218
- auth: authLogon,
195
+ auth: authDefault,
219
196
  handler: _handlers.getApp2
220
- /*
221
- handler: {
222
- file: function (req,h) {
223
- debugger;
224
- console.log('in file2 handler');
225
- console.log(req.auth);
226
- console.log(req.params);
227
- return req.params.param;
228
- }
229
-
230
- },
231
- */
232
197
  }
233
198
  }, {
234
199
  method: ['GET'],
@@ -262,7 +227,7 @@ module.exports = function setDefaultRoutes(server, options) {
262
227
  }
263
228
  }
264
229
  };
265
- console.log(pr);
230
+ // console.log(pr);
266
231
  defaultTable.push(pr);
267
232
  }
268
233
  var routeTables = uTable !== null ? defaultTable.concat(uTable) : defaultTable;
@@ -44,38 +44,37 @@ function _setupAuth() {
44
44
  return _regeneratorRuntime().wrap(function _callee$(_context) {
45
45
  while (1) switch (_context.prev = _context.next) {
46
46
  case 0:
47
- debugger;
48
47
  if (!(options.authFlow === 'server')) {
49
- _context.next = 13;
48
+ _context.next = 12;
50
49
  break;
51
50
  }
52
- _context.next = 4;
51
+ _context.next = 3;
53
52
  return server.register({
54
53
  plugin: SASauth,
55
54
  options: options
56
55
  });
57
- case 4:
58
- _context.next = 6;
56
+ case 3:
57
+ _context.next = 5;
59
58
  return appCookie(server, options);
60
- case 6:
59
+ case 5:
61
60
  def = 'session';
62
61
  if (!(options.serverMode === 'api')) {
63
- _context.next = 11;
62
+ _context.next = 10;
64
63
  break;
65
64
  }
66
- _context.next = 10;
65
+ _context.next = 9;
67
66
  return server.register({
68
67
  plugin: token
69
68
  });
70
- case 10:
69
+ case 9:
71
70
  def = 'token';
72
- case 11:
71
+ case 10:
73
72
  server.log('***********************Default auth', def);
74
73
  server.auth["default"](def);
75
74
  // console.log(server.registerations);
76
- case 13:
75
+ case 12:
77
76
  setDefaultRoutes(server, options);
78
- case 14:
77
+ case 13:
79
78
  case "end":
80
79
  return _context.stop();
81
80
  }
@@ -17,12 +17,11 @@ function _itoken() {
17
17
  return _regeneratorRuntime().wrap(function _callee$(_context) {
18
18
  while (1) switch (_context.prev = _context.next) {
19
19
  case 0:
20
- debugger;
21
- _context.next = 3;
20
+ _context.next = 2;
22
21
  return server.auth.scheme('SAStoken', require('../schemes/SASTokenScheme'));
23
- case 3:
22
+ case 2:
24
23
  server.auth.strategy('token', 'SAStoken');
25
- case 4:
24
+ case 3:
26
25
  case "end":
27
26
  return _context.stop();
28
27
  }
@@ -39,15 +39,14 @@ module.exports = function SASTokenScheme(server, options) {
39
39
  return _regeneratorRuntime().wrap(function _callee$(_context) {
40
40
  while (1) switch (_context.prev = _context.next) {
41
41
  case 0:
42
- debugger;
43
42
  authorization = request.headers.authorization;
44
43
  server.log('SASToken', authorization);
45
44
  if (authorization) {
46
- _context.next = 5;
45
+ _context.next = 4;
47
46
  break;
48
47
  }
49
48
  throw Boom.unauthorized(null, 'session');
50
- case 5:
49
+ case 4:
51
50
  _authorization$split = authorization.split(' '), _authorization$split2 = _slicedToArray(_authorization$split, 2), tokenType = _authorization$split2[0], token = _authorization$split2[1];
52
51
  credentials = {
53
52
  token: token,
@@ -56,7 +55,7 @@ module.exports = function SASTokenScheme(server, options) {
56
55
  return _context.abrupt("return", h.authenticated({
57
56
  credentials: credentials
58
57
  }));
59
- case 8:
58
+ case 7:
60
59
  case "end":
61
60
  return _context.stop();
62
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sassoftware/viya-serverjs",
3
- "version": "0.0.3",
3
+ "version": "0.1.1",
4
4
  "description": "App server for Custom Viya Applications",
5
5
  "author": "Deva Kumaraswamy <deva.kumar@sas.com>",
6
6
  "license": "Apache-2.0",
@@ -32,5 +32,4 @@
32
32
  "pub": "npm publish --tag dev --access public",
33
33
  "lint": "npx eslint --fix src/*.js"
34
34
  }
35
-
36
35
  }