@sassoftware/viya-serverjs 0.6.1-0 → 0.6.1-2

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.
@@ -23,7 +23,7 @@ function _getApp() {
23
23
  return _regenerator().w(function (_context) {
24
24
  while (1) switch (_context.n) {
25
25
  case 0:
26
- console.log('In getApp handler', options);
26
+ debug('In getApp handler', options);
27
27
  if (!(process.env.AUTHFLOW === 'implicit')) {
28
28
  _context.n = 1;
29
29
  break;
@@ -51,16 +51,16 @@ function _getApp() {
51
51
  }
52
52
  debug('calling codeauth');
53
53
  r = (0, _codeAuth["default"])(req, h, options);
54
- console.log(options.userCache);
54
+ debug(options.userCache);
55
55
  return _context.a(2, r);
56
56
  case 2:
57
57
  debug('default processing in getapp');
58
- console.log('Processing non authenticated use case');
58
+ debug('Processing non authenticated use case');
59
59
  indexHTML = process.env.APPENTRY == null ? 'index.html' : process.env.APPENTRY;
60
60
  if (process.env.REDIRECT != null) {
61
61
  indexHTML = process.env.REDIRECT;
62
62
  }
63
- console.log('redirecting to ', indexHTML);
63
+ debug('redirecting to ', indexHTML);
64
64
  if (!indexHTML.startsWith('/')) {
65
65
  _context.n = 3;
66
66
  break;
@@ -8,6 +8,7 @@ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present,
8
8
  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); }
9
9
  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); }
10
10
  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); }); }; }
11
+ var debug = require('debug')('proxyMapUri');
11
12
  function proxyMapUri(_x) {
12
13
  return _proxyMapUri.apply(this, arguments);
13
14
  }
@@ -18,22 +19,22 @@ function _proxyMapUri() {
18
19
  while (1) switch (_context.n) {
19
20
  case 0:
20
21
  credentials = req.auth.credentials;
21
- console.log('------------------------------------------');
22
+ debug('------------------------------------------');
22
23
  if (credentials != null) {
23
24
  sid = credentials.sid;
24
- console.log('sid=', sid);
25
+ debug('sid=', sid);
25
26
  }
26
27
  path = process.env.VIYA_SERVER; //let path = (process.env.PROXYSERVER == null) ? process.env.VIYA_SERVER : process.env.PROXYSERVER;
27
- console.log('proxying to= ', path);
28
+ debug('proxying to= ', path);
28
29
  params = req.params;
29
- console.log('params=', params);
30
+ debug('params=', params);
30
31
  search = req.url.search;
31
- console.log('query=', search);
32
+ debug('query=', search);
32
33
  uri = path + '/' + params.param;
33
34
  if (search != null && search.trim().length > 0) {
34
35
  uri = uri + search;
35
36
  }
36
- console.log('destination= ', uri);
37
+ debug('destination= ', uri);
37
38
  return _context.a(2, {
38
39
  uri: uri
39
40
  });
@@ -52,7 +52,7 @@ function _setCookies() {
52
52
  options.userCache = _objectSpread({}, credentials);
53
53
  debug(options.allAppEnv.LOGONPAYLOAD);
54
54
  }
55
- console.log('userCache', options.userCache);
55
+ debug('userCache', options.userCache);
56
56
  _context.n = 2;
57
57
  return req.server.app.cache.set(sid, credentials, 0);
58
58
  case 2:
@@ -25,6 +25,8 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
25
25
  * ---------------------------------------------------------------------------------------
26
26
  *
27
27
  */
28
+
29
+ var debug = require('debug')('context');
28
30
  function setContext(_x, _x2) {
29
31
  return _setContext.apply(this, arguments);
30
32
  }
@@ -35,8 +37,7 @@ function _setContext() {
35
37
  while (1) switch (_context.n) {
36
38
  case 0:
37
39
  credentials = req.auth.credentials;
38
- console.log('in setContext');
39
- console.log('credentials=', credentials);
40
+ debug(credentials);
40
41
  context = {
41
42
  path: req.path,
42
43
  params: req.params,
@@ -36,9 +36,18 @@ module.exports = function setDefaultRoutes(server, options) {
36
36
  var authDefault = false;
37
37
  var authLogon = false;
38
38
  if (options.authFlow === "server") {
39
- authDefault = options.serverMode === "app" ? false : {
40
- strategies: ["token", "session"],
41
- mode: "required"
39
+ /*
40
+ authDefault =
41
+ options.serverMode === "app"
42
+ ? false
43
+ : {
44
+ strategies: ["token", "session"],
45
+ mode: "required",
46
+ };
47
+ */
48
+ authDefault = {
49
+ strategy: "session",
50
+ mode: "try"
42
51
  };
43
52
  authLogon = {
44
53
  mode: "required",
@@ -95,34 +104,6 @@ module.exports = function setDefaultRoutes(server, options) {
95
104
  auth: process.env.USELOGON === 'YES' ? null : options.serverMode === "app" ? authLogon : authDefault,
96
105
  handler: getAppb
97
106
  }
98
- }, {
99
- method: ["GET"],
100
- path: "".concat(appName, "/api"),
101
- options: {
102
- auth: authDefault,
103
- handler: function () {
104
- var _handler2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(req, h) {
105
- return _regenerator().w(function (_context2) {
106
- while (1) switch (_context2.n) {
107
- case 0:
108
- return _context2.a(2, h.redirect("".concat(appName, "/documentation")));
109
- }
110
- }, _callee2);
111
- }));
112
- function handler(_x3, _x4) {
113
- return _handler2.apply(this, arguments);
114
- }
115
- return handler;
116
- }()
117
- }
118
- }, {
119
- method: ["GET"],
120
- path: "/develop",
121
- options: {
122
- auth: false,
123
- cors: true,
124
- handler: _handlers.reactDev
125
- }
126
107
  }, {
127
108
  method: ["GET"],
128
109
  path: "".concat(appName, "/callback"),
@@ -150,10 +131,10 @@ module.exports = function setDefaultRoutes(server, options) {
150
131
  options: {
151
132
  auth: /*authDefault*/false,
152
133
  handler: function () {
153
- var _handler3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(req, h) {
134
+ var _handler2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(req, h) {
154
135
  var allAppEnv, uappenv, s;
155
- return _regenerator().w(function (_context3) {
156
- while (1) switch (_context3.n) {
136
+ return _regenerator().w(function (_context2) {
137
+ while (1) switch (_context2.n) {
157
138
  case 0:
158
139
  allAppEnv = options.allAppEnv;
159
140
  if (options.userInfo != null) {
@@ -168,12 +149,12 @@ module.exports = function setDefaultRoutes(server, options) {
168
149
  console.log(s);
169
150
  }
170
151
  debug(s);
171
- return _context3.a(2, s);
152
+ return _context2.a(2, s);
172
153
  }
173
- }, _callee3);
154
+ }, _callee2);
174
155
  }));
175
- function handler(_x5, _x6) {
176
- return _handler3.apply(this, arguments);
156
+ function handler(_x3, _x4) {
157
+ return _handler2.apply(this, arguments);
177
158
  }
178
159
  return handler;
179
160
  }()
@@ -184,10 +165,10 @@ module.exports = function setDefaultRoutes(server, options) {
184
165
  options: {
185
166
  auth: /*authDefault*/false,
186
167
  handler: function () {
187
- var _handler4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(req, h) {
168
+ var _handler3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(req, h) {
188
169
  var allAppEnv, uappenv, s;
189
- return _regenerator().w(function (_context4) {
190
- while (1) switch (_context4.n) {
170
+ return _regenerator().w(function (_context3) {
171
+ while (1) switch (_context3.n) {
191
172
  case 0:
192
173
  allAppEnv = options.allAppEnv;
193
174
  if (options.userInfo != null) {
@@ -202,12 +183,12 @@ module.exports = function setDefaultRoutes(server, options) {
202
183
  debug(options.allAppEnv);
203
184
  }
204
185
  debug(s);
205
- return _context4.a(2, s);
186
+ return _context3.a(2, s);
206
187
  }
207
- }, _callee4);
188
+ }, _callee3);
208
189
  }));
209
- function handler(_x7, _x8) {
210
- return _handler4.apply(this, arguments);
190
+ function handler(_x5, _x6) {
191
+ return _handler3.apply(this, arguments);
211
192
  }
212
193
  return handler;
213
194
  }()
@@ -41,12 +41,11 @@ function setupAuth(_x, _x2) {
41
41
  }
42
42
  function _setupAuth() {
43
43
  _setupAuth = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(server, options) {
44
- var def;
45
44
  return _regenerator().w(function (_context) {
46
45
  while (1) switch (_context.n) {
47
46
  case 0:
48
47
  if (!(options.authFlow === 'server')) {
49
- _context.n = 5;
48
+ _context.n = 2;
50
49
  break;
51
50
  }
52
51
  _context.n = 1;
@@ -58,22 +57,6 @@ function _setupAuth() {
58
57
  _context.n = 2;
59
58
  return appCookie(server, options);
60
59
  case 2:
61
- def = 'session';
62
- if (!(options.serverMode === 'api')) {
63
- _context.n = 4;
64
- break;
65
- }
66
- _context.n = 3;
67
- return server.register({
68
- plugin: token
69
- });
70
- case 3:
71
- def = 'token';
72
- case 4:
73
- log('***********************Default auth', def);
74
- server.auth["default"](def);
75
- // console.log(server.registerations);
76
- case 5:
77
60
  setDefaultRoutes(server, options);
78
61
  return _context.a(2, true);
79
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sassoftware/viya-serverjs",
3
- "version": "0.6.1-0",
3
+ "version": "0.6.1-2",
4
4
  "description": "Easy to use app server for SAS Viya applications",
5
5
  "author": "Deva Kumaraswamy <deva.kumar@sas.com>",
6
6
  "license": "Apache-2.0",
package/server.js CHANGED
@@ -32,7 +32,7 @@ function getCustomHandler() {
32
32
  },
33
33
  {
34
34
  method: ["GET"],
35
- path: `${appName}/new`,
35
+ path: `/new`,
36
36
  options: {
37
37
  files: {
38
38
  relativeTo: "./public",
@@ -44,6 +44,10 @@ function getCustomHandler() {
44
44
  console.log(req.pre.context);
45
45
  return h.file('index.html');
46
46
  },
47
+ auth: {
48
+ strategy: 'session',
49
+ mode: 'optional'
50
+ },
47
51
  description: "Create new application",
48
52
  notes: "Index file created from env data",
49
53
  tags: ["app"],
@@ -7,7 +7,7 @@ import codeAuth from './codeAuth';
7
7
  let debug = require('debug')('getapp');
8
8
 
9
9
  async function getApp (options, req, h) {
10
- console.log('In getApp handler', options);
10
+ debug('In getApp handler', options);
11
11
  if (process.env.AUTHFLOW === 'implicit') {
12
12
  let x = `${process.env.VIYA_SERVER}/SASLogon/oauth/authorize?response_type=token&client_id=${process.env.CLIENTID}`;
13
13
  let redirect = `${process.env.APPNAME}/callback`;
@@ -30,18 +30,18 @@ async function getApp (options, req, h) {
30
30
 
31
31
  debug('calling codeauth');
32
32
  let r = codeAuth(req, h, options);
33
- console.log(options.userCache);
33
+ debug(options.userCache);
34
34
  return r;
35
35
 
36
36
  } else {
37
37
  debug('default processing in getapp');
38
- console.log('Processing non authenticated use case');
38
+ debug('Processing non authenticated use case');
39
39
 
40
40
  let indexHTML = process.env.APPENTRY == null ? 'index.html' : process.env.APPENTRY;
41
41
  if (process.env.REDIRECT != null) {
42
42
  indexHTML = process.env.REDIRECT;
43
43
  }
44
- console.log('redirecting to ', indexHTML);
44
+ debug('redirecting to ', indexHTML);
45
45
  if (indexHTML.startsWith('/')) {
46
46
  indexHTML = `/${process.env.APPNAME}${indexHTML}`;
47
47
  return h.redirect(indexHTML);
@@ -1,23 +1,24 @@
1
+ let debug = require('debug')('proxyMapUri');
1
2
  async function proxyMapUri (req) {
2
3
  let credentials = req.auth.credentials;
3
- console.log('------------------------------------------');
4
+ debug('------------------------------------------');
4
5
  if (credentials != null) {
5
6
  let sid = credentials.sid;
6
- console.log('sid=', sid);
7
+ debug('sid=', sid);
7
8
  }
8
9
 
9
10
  let path = process.env.VIYA_SERVER;
10
11
  //let path = (process.env.PROXYSERVER == null) ? process.env.VIYA_SERVER : process.env.PROXYSERVER;
11
- console.log('proxying to= ', path);
12
+ debug('proxying to= ', path);
12
13
  let params = req.params;
13
- console.log('params=', params);
14
+ debug('params=', params);
14
15
  let search = req.url.search;
15
- console.log('query=', search);
16
+ debug('query=', search);
16
17
  let uri = path + '/' + params.param;
17
18
  if (search != null && search.trim().length > 0) {
18
19
  uri = uri + search;
19
20
  }
20
- console.log('destination= ',uri);
21
+ debug('destination= ',uri);
21
22
  return {
22
23
  uri: uri
23
24
  };
@@ -26,7 +26,7 @@ async function setCookies (req, h, options) {
26
26
  options.userCache = {...credentials};
27
27
  debug(options.allAppEnv.LOGONPAYLOAD);
28
28
  }
29
- console.log('userCache', options.userCache);
29
+ debug('userCache', options.userCache);
30
30
 
31
31
  await req.server.app.cache.set(sid, credentials, 0);
32
32
  // Can we get away without setting cookie for this session?
@@ -16,11 +16,10 @@
16
16
  *
17
17
  */
18
18
 
19
-
19
+ let debug = require('debug')('context');
20
20
  async function setContext (req,h){
21
- let credentials = req.auth.credentials;
22
- console.log('in setContext');
23
- console.log('credentials=', credentials);
21
+ let credentials = req.auth.credentials
22
+ debug(credentials);
24
23
  let context = {
25
24
  path : req.path,
26
25
  params : req.params,
@@ -37,6 +37,7 @@ module.exports = function setDefaultRoutes(server, options) {
37
37
  let authDefault = false;
38
38
  let authLogon = false;
39
39
  if (options.authFlow === "server") {
40
+ /*
40
41
  authDefault =
41
42
  options.serverMode === "app"
42
43
  ? false
@@ -44,7 +45,11 @@ module.exports = function setDefaultRoutes(server, options) {
44
45
  strategies: ["token", "session"],
45
46
  mode: "required",
46
47
  };
47
-
48
+ */
49
+ authDefault = {
50
+ strategy: "session",
51
+ mode: "try",
52
+ };
48
53
  authLogon = {
49
54
  mode: "required",
50
55
  strategy: "sas",
@@ -96,26 +101,6 @@ module.exports = function setDefaultRoutes(server, options) {
96
101
  },
97
102
  },
98
103
 
99
- {
100
- method: ["GET"],
101
- path: `${appName}/api`,
102
- options: {
103
- auth: authDefault,
104
- handler: async (req, h) => {
105
- return h.redirect(`${appName}/documentation`);
106
- },
107
- },
108
- },
109
- {
110
- method: ["GET"],
111
- path: `/develop`,
112
- options: {
113
- auth: false,
114
- cors: true,
115
- handler: reactDev,
116
- },
117
- },
118
-
119
104
  {
120
105
  method: ["GET"],
121
106
  path: `${appName}/callback`,
@@ -33,7 +33,7 @@ async function setupAuth (server, options){
33
33
  await server.register({plugin: SASauth, options: options});
34
34
  // await server.register({plugin: appCookie, options: options});
35
35
  await appCookie(server,options);
36
-
36
+ /*
37
37
  let def = 'session';
38
38
  if (options.serverMode === 'api') {
39
39
  await server.register({ plugin: token });
@@ -41,6 +41,7 @@ async function setupAuth (server, options){
41
41
  }
42
42
  log('***********************Default auth', def);
43
43
  server.auth.default(def);
44
+ */
44
45
  // console.log(server.registerations);
45
46
  }
46
47
  setDefaultRoutes(server, options);