@sassoftware/viya-serverjs 0.0.3 → 0.1.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.
@@ -1,468 +0,0 @@
1
- "use strict";
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
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _setupAuth = _interopRequireDefault(require("./plugins/setupAuth"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw 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; }
11
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
15
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
17
- 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."); }
18
- 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); }
19
- 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; }
20
- 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; } }
21
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
- 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); } }
23
- 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); }); }; }
24
- /*
25
- * ------------------------------------------------------------------------------------
26
- * * Copyright (c) SAS Institute Inc.
27
- * * Licensed under the Apache License, Version 2.0 (the "License");
28
- * * you may not use this file except in compliance with the License.
29
- * * You may obtain a copy of the License at
30
- * *
31
- * * http://www.apache.org/licenses/LICENSE-2.0
32
- * *
33
- * * Unless required by applicable law or agreed to in writing, software
34
- * * distributed under the License is distributed on an "AS IS" BASIS,
35
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36
- * * See the License for the specific language governing permissions and
37
- * limitations under the License.
38
- * ----------------------------------------------------------------------------------------
39
- *
40
- */
41
-
42
- var fs = require('fs');
43
- var debug = require('debug')('service');
44
- var debug2 = require('debug')('tls');
45
- // let isDocker = require('is-docker');
46
- var Hapi = require('@hapi/hapi');
47
- var H202 = require('@hapi/h2o2');
48
- // const { isSameSiteNoneCompatible } = require('should-send-same-site-none');
49
- var NodeCache = require("node-cache-promise");
50
- var Vision = require('@hapi/vision');
51
- var inert = require('@hapi/inert');
52
- var selfsigned = require('selfsigned');
53
- var os = require('os');
54
- function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, userInfo) {
55
- // process.env.APPHOST_ADDR = process.env.APPHOST;
56
- var init = /*#__PURE__*/function () {
57
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
58
- var defaultMaxBytes, maxBytes, isSameSite, isSecure, _process$env$SAMESITE, _process$env$SAMESITE2, s1, s2, sConfig, hapiServer, nodeCacheOptions, storeCache, visionOptions, options, swaggerOptions, override, allRoutes, hh, msg;
59
- return _regeneratorRuntime().wrap(function _callee$(_context) {
60
- while (1) switch (_context.prev = _context.next) {
61
- case 0:
62
- if (process.env.APPHOST === '*') {
63
- process.env.APPHOST = os.hostname();
64
- }
65
- defaultMaxBytes = 10485760;
66
- if (isNaN(process.env.PAYLOADMAXBYTES)) {
67
- maxBytes = defaultMaxBytes;
68
- } else {
69
- maxBytes = Number(process.env.PAYLOADMAXBYTES);
70
- }
71
- isSameSite = 'None';
72
- isSecure = false;
73
- if (process.env.SAMESITE != null) {
74
- _process$env$SAMESITE = process.env.SAMESITE.split(','), _process$env$SAMESITE2 = _slicedToArray(_process$env$SAMESITE, 2), s1 = _process$env$SAMESITE2[0], s2 = _process$env$SAMESITE2[1];
75
- isSameSite = s1;
76
- isSecure = s2 === 'secure' ? true : false;
77
- if (process.env.HTTPS !== 'true') {
78
- isSecure = false;
79
- }
80
- }
81
- sConfig = {
82
- port: process.env.APPPORT,
83
- host: process.env.APPHOST,
84
- state: {
85
- isSameSite: isSameSite,
86
- isSecure: isSecure
87
- },
88
- routes: {
89
- payload: {
90
- maxBytes: maxBytes
91
- },
92
- cors: {
93
- origin: ['*'],
94
- credentials: true,
95
- "headers": ["Accept", "Authorization", "Content-Type", "If-None-Match", "Accept-language"]
96
- /*
97
- 'Access-Control-Allow-Methods': ['GET', 'POST', 'OPTIONS'],
98
- additionalHeaders : ['multipart/form-data', 'content-disposition'],
99
- additionalExposedHeaders : ['location'],
100
- */
101
- }
102
- }
103
- };
104
- if (process.env.HAPIDEBUG === 'YES') {
105
- sConfig.debug = {
106
- log: ['hapi'],
107
- request: ['hapi']
108
- };
109
- }
110
- debug('sConfig:', JSON.stringify(sConfig, null, 4));
111
- if (!(process.env.HTTPS === 'true')) {
112
- _context.next = 16;
113
- break;
114
- }
115
- _context.next = 12;
116
- return getCertificates();
117
- case 12:
118
- sConfig.tls = _context.sent;
119
- debug('Setup of SSL certificates completed');
120
- _context.next = 17;
121
- break;
122
- case 16:
123
- debug('Running with no SSL certificates');
124
- case 17:
125
- if (asset !== null) {
126
- sConfig.routes.files = {
127
- relativeTo: asset
128
- };
129
- }
130
- debug2("Application information: \n\t\tAPPLOC : ".concat(process.env.APPLOC, "\n\t\tAPPENTRY: ").concat(process.env.APPENTRY, "\n"));
131
- hapiServer = Hapi.server(sConfig);
132
- /*
133
- const cache = hapiServer.cache({ segment: 'sessions', expiresIn: 3 * 24 * 60 * 60 * 1000 });
134
- hapiServer.app.cache = cache;
135
- */
136
- nodeCacheOptions = {
137
- stdTTL: 36000,
138
- checkPeriod: 3600,
139
- errorOnMissing: true,
140
- useClones: false,
141
- deleteOnExpire: true
142
- };
143
- storeCache = new NodeCache(nodeCacheOptions);
144
- hapiServer.app.cache = storeCache;
145
-
146
- // common plugins
147
- visionOptions = {
148
- engines: {
149
- html: require('handlebars')
150
- },
151
- relativeTo: __dirname,
152
- path: '.'
153
- };
154
- _context.next = 26;
155
- return hapiServer.register(Vision);
156
- case 26:
157
- hapiServer.views(visionOptions);
158
- _context.next = 29;
159
- return hapiServer.register(inert);
160
- case 29:
161
- if (!(process.env.HTTPS === 'true')) {
162
- _context.next = 32;
163
- break;
164
- }
165
- _context.next = 32;
166
- return hapiServer.register({
167
- plugin: require('hapi-require-https'),
168
- options: {}
169
- });
170
- case 32:
171
- _context.next = 34;
172
- return hapiServer.register(H202);
173
- case 34:
174
- /*
175
- await hapiServer.register({
176
- plugin : require('hapi-pino'),
177
- options: {
178
- prettyPrint: process.env.NODE_ENV !== 'production',
179
- level : process.env.LOGLEVEL == null ? 'silent' : process.env.LOGLEVEL,
180
- },
181
- });
182
- */
183
- // setup authentication related plugins
184
- options = {
185
- serverMode: serverMode === null ? 'app' : 'api',
186
- /* api or app */
187
- authFlow: process.env.AUTHFLOW,
188
- host: process.env.VIYA_SERVER,
189
- isSameSite: isSameSite,
190
- isSecure: isSecure,
191
- ns: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.ns : null,
192
- nsHost: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.nsHost : null,
193
- redirect: process.env.REDIRECT,
194
- clientId: process.env.CLIENTID,
195
- clientSecret: process.env.CLIENTSECRET,
196
- redirectTo: "/".concat(process.env.APPNAME, "/logon"),
197
- allAppEnv: allAppEnv,
198
- useHapiCookie: true,
199
- appName: process.env.APPNAME,
200
- appHost: process.env.APPHOST,
201
- appPort: process.env.APPPORT,
202
- userRouteTable: userRouteTable,
203
- useDefault: useDefault,
204
- /* not used - left here for potential reuse */
205
- userInfo: userInfo,
206
- https: process.env.HTTPS,
207
- authDefault: false,
208
- /* set later in setDefaultRoutes */
209
- authLogon: false /* set later in setDefaultRoutes */
210
- };
211
- debug2('Options', options);
212
- if (!(process.env.AUTHFLOW != null)) {
213
- _context.next = 39;
214
- break;
215
- }
216
- _context.next = 39;
217
- return (0, _setupAuth["default"])(hapiServer, options);
218
- case 39:
219
- hapiServer.log('Plugin', process.env.PLUGIN);
220
- if (!(process.env.PLUGIN === 'hapi-swagger' && serverMode !== null)) {
221
- _context.next = 48;
222
- break;
223
- }
224
- swaggerOptions = {
225
- "info": {
226
- "title": "API for ".concat(process.env.APPNAME),
227
- "version": "0.0.1",
228
- "description": "This document was auto-generated at run time"
229
- },
230
- "schemes": ["http", "https"],
231
- "cors": true,
232
- "debug": true,
233
- "jsonPath": "/".concat(options.appName, "/swagger.json"),
234
- "jsonRoutePath": "/".concat(options.appName, "/swagger.json"),
235
- "documentationPage": true,
236
- "documentationPath": "/".concat(options.appName, "/documentation"),
237
- "swaggerUI": true,
238
- "swaggerUIPath": "/".concat(options.appName, "/swaggerui"),
239
- auth: options.authDefault
240
- };
241
- if (userInfo != null) {
242
- override = userInfo(options, 'SWAGGEROPTIONS');
243
- swaggerOptions = _objectSpread(_objectSpread({}, swaggerOptions), override);
244
- }
245
- debug('Swagger Options:', swaggerOptions);
246
- _context.next = 46;
247
- return hapiServer.register({
248
- plugin: serverMode,
249
- options: swaggerOptions
250
- });
251
- case 46:
252
- _context.next = 49;
253
- break;
254
- case 48:
255
- if (process.env.PLUGIN == 'hapi-openapi' && serverMode !== null) {
256
- console.log('hapi-openapi', 'coming soon');
257
- }
258
- case 49:
259
- //
260
- // Start server
261
- //
262
- // eslint-disable-next-line no-unused-vars
263
- allRoutes = hapiServer.table();
264
- _context.next = 52;
265
- return hapiServer.start();
266
- case 52:
267
- hh = hapiServer.info.uri;
268
- hh = hh.replace(/0.0.0.0/, 'localhost');
269
- console.log('====================================================================================');
270
- console.log('Server Start Time: ', Date());
271
- msg = options.serverMode === 'app' ? "Visit ".concat(hh, "/").concat(process.env.APPNAME, " to access application") : "Visit ".concat(hh, "/").concat(process.env.APPNAME, "/api to access swagger");
272
- console.log('\x1b[1m%s\x1b[0m', msg);
273
- console.log('NOTE: If running in container use the exported port');
274
- process.env.APPSERVER = "".concat(hh, "/").concat(process.env.APPNAME);
275
- process.env.HEALTH = 'true';
276
- console.log('====================================================================================');
277
- case 62:
278
- case "end":
279
- return _context.stop();
280
- }
281
- }, _callee);
282
- }));
283
- return function init() {
284
- return _ref.apply(this, arguments);
285
- };
286
- }();
287
- process.on('unhandledRejection', function (err) {
288
- console.log(err);
289
- process.exit(1);
290
- });
291
- init();
292
- }
293
- function getCertificates() {
294
- return _getCertificates.apply(this, arguments);
295
- }
296
- function _getCertificates() {
297
- _getCertificates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
298
- var tls;
299
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
300
- while (1) switch (_context2.prev = _context2.next) {
301
- case 0:
302
- tls = {};
303
- debug2('Getting tls certificates');
304
- debug2('tls.crt', process.env['tls.crt'] != null);
305
- debug2('tls.key', process.env['tls.key'] != null);
306
- debug2('TLS_PFX', process.env.TLS_PFX != null);
307
- debug2('TLS_PW', process.env.TLS_PW != null);
308
- debug2('TLS_CERT', process.env.TLS_CERT != null);
309
- debug2('TLS_CRT', process.env.TLS_CRT != null);
310
- debug2('TLS_CREATE', process.env.TLS_CREATE != null);
311
- if (!(process.env.TLS_CERT != null)) {
312
- _context2.next = 15;
313
- break;
314
- }
315
- /* backward compatability */
316
- debug2('TLS set: TLS_CERT');
317
- tls.cert = fs.readFileSync(process.env.TLS_CERT);
318
- tls.key = fs.readFileSync(process.env.TLS_KEY);
319
- _context2.next = 37;
320
- break;
321
- case 15:
322
- if (!(process.env.TLS_PFX != null)) {
323
- _context2.next = 21;
324
- break;
325
- }
326
- debug2('TLS set: PFX');
327
- tls.pfx = fs.readFileSync(process.env.TLS_PFX);
328
- if (process.env.TLS_PW != null) {
329
- tls.passphrase = process.env.TLS_PW;
330
- }
331
- _context2.next = 37;
332
- break;
333
- case 21:
334
- if (!(process.env.TLS_CRT != null)) {
335
- _context2.next = 27;
336
- break;
337
- }
338
- /* new key names to conform to k8s*/
339
- debug2('TLS set: TLS_CRT');
340
- tls.cert = process.env.TLS_CRT;
341
- tls.key = process.env.TLS_KEY;
342
- _context2.next = 37;
343
- break;
344
- case 27:
345
- if (!(process.env['tls.crt'] != null)) {
346
- _context2.next = 32;
347
- break;
348
- }
349
- tls.cert = process.env['tls.crt'];
350
- tls.key = process.env['tls.key'];
351
- _context2.next = 37;
352
- break;
353
- case 32:
354
- if (!(process.env.TLS_CREATE != null)) {
355
- _context2.next = 37;
356
- break;
357
- }
358
- /* unsigned certificate */
359
- debug2('TLS set: TLS_CREATE=', process.env.TLS_CREATE);
360
- _context2.next = 36;
361
- return getTls();
362
- case 36:
363
- tls = _context2.sent;
364
- case 37:
365
- if (process.env.TLS_CABUNDLE != null) {
366
- tls.CA = fs.readFileSync(process.env.TLS_CABUNDLE);
367
- }
368
- debug2('TLS', tls);
369
- if (!(Object.keys(tls).length > 0)) {
370
- _context2.next = 43;
371
- break;
372
- }
373
- return _context2.abrupt("return", tls);
374
- case 43:
375
- console.log('Warning: The current host protocol is https: No TLS certificate information has been specified.');
376
- return _context2.abrupt("return", tls);
377
- case 45:
378
- case "end":
379
- return _context2.stop();
380
- }
381
- }, _callee2);
382
- }));
383
- return _getCertificates.apply(this, arguments);
384
- }
385
- function getTls() {
386
- return _getTls.apply(this, arguments);
387
- }
388
- function _getTls() {
389
- _getTls = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
390
- var options, subjt, subj, d, attr, pems, tls;
391
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
392
- while (1) switch (_context3.prev = _context3.next) {
393
- case 0:
394
- options = {
395
- keySize: 2048,
396
- days: 360,
397
- algorithm: "sha256",
398
- clientCertificate: true,
399
- extensions: {}
400
- };
401
- subjt = process.env.TLS_CREATE.replaceAll('"', '').trim();
402
- subj = subjt.split(',');
403
- d = {};
404
- subj.map(function (c) {
405
- var r = c.split(':');
406
- d[r[0]] = r[1];
407
- return {
408
- value: r[1]
409
- };
410
- });
411
-
412
- // TLS_CREATE=C:US,ST:NC,L:Cary,O:SAS Institute,OU:STO,CN:localhost,ALT:na.sas.com
413
- attr = [{
414
- name: 'commonName',
415
- value: d.CN /*process.env.APPHOST*/
416
- }, {
417
- name: 'countryName',
418
- value: d.C
419
- }, {
420
- shortName: 'ST',
421
- value: d.ST
422
- }, {
423
- name: 'localityName',
424
- value: d.L
425
- }, {
426
- name: 'organizationName',
427
- value: d.O
428
- }, {
429
- shortName: 'OU',
430
- value: d.OU
431
- }];
432
- options.extensions.altNames = [
433
- // { type: 6, value: `http://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
434
- {
435
- type: 6,
436
- value: "https://".concat(process.env.APPHOST, ":").concat(process.env.APPPORT, "/").concat(process.env.APPNAME)
437
- }, {
438
- type: 6,
439
- value: "https://".concat(process.env.APPHOST, ":").concat(process.env.APPPORT, "/").concat(process.env.APPNAME, "/api")
440
- }, {
441
- type: 6,
442
- value: "https://".concat(process.env.APPHOST, ":").concat(process.env.APPPORT, "/").concat(process.env.APPNAME, "/logon")
443
- }, {
444
- type: 6,
445
- value: "https://".concat(process.env.APPHOST, "/").concat(process.env.APPNAME)
446
- }, {
447
- type: 6,
448
- value: "https://".concat(process.env.APPHOST, "/").concat(process.env.APPNAME, "/api")
449
- }, {
450
- type: 6,
451
- value: "https://".concat(process.env.APPHOST, "/").concat(process.env.APPNAME, "/logon")
452
- }];
453
- debug('tls options ', JSON.stringify(options, null, 4));
454
- pems = selfsigned.generate(attr, options);
455
- tls = {
456
- cert: pems.cert,
457
- key: pems["private"]
458
- };
459
- return _context3.abrupt("return", tls);
460
- case 11:
461
- case "end":
462
- return _context3.stop();
463
- }
464
- }, _callee3);
465
- }));
466
- return _getTls.apply(this, arguments);
467
- }
468
- var _default = exports["default"] = iService;
package/lib/core/index.js DELETED
@@ -1,184 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/stable");
4
- require("regenerator-runtime/runtime");
5
- var _fs = _interopRequireDefault(require("fs"));
6
- var _iService = _interopRequireDefault(require("./iService"));
7
- var _config = _interopRequireDefault(require("./config"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- /*
10
- * ------------------------------------------------------------------------------------
11
- * * Copyright (c) SAS Institute Inc.
12
- * * Licensed under the Apache License, Version 2.0 (the 'License');
13
- * * you may not use this file except in compliance with the License.
14
- * * You may obtain a copy of the License at
15
- * *
16
- * * http://www.apache.org/licenses/LICENSE-2.0
17
- * *
18
- * * Unless required by applicable law or agreed to in writing, software
19
- * * distributed under the License is distributed on an 'AS IS' BASIS,
20
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- * ----------------------------------------------------------------------------------------
24
- *
25
- */
26
-
27
- var debug = require("debug")("startup");
28
- module.exports = function core(uTable, useDefault, serverMode, customize, swaggerfcn) {
29
- var argv = require("yargs").argv;
30
- debug(argv);
31
- var env = argv.env == null ? null : argv.env;
32
- var appenv = argv.appenv == null ? null : argv.appenv;
33
- var docker = argv.docker == null ? null : argv.docker;
34
- process.env.SERVERMODE = serverMode !== null ? process.env.SERVERMODE : "app";
35
- if (useDefault == null) {
36
- useDefault = true;
37
- }
38
- console.log("Initialization started ============================================================");
39
- console.log("version: 2, Build Date: ", Date());
40
- console.log("\nCommand Line Configuration:\n Dockerfile: ".concat(docker, "\n env file : ").concat(env, "\n appenv : ").concat(appenv, "\n customize : ").concat(customize != null, "\n "));
41
- iapp(appenv, env, docker, uTable, useDefault, serverMode, customize);
42
- };
43
- function iapp(appSrc, rafEnv, dockerFile, uTable, useDefault, serverMode, customize) {
44
- var asset = setup(rafEnv, dockerFile);
45
- if (appSrc === null) {
46
- appSrc = process.env.APPENV == null ? null : process.env.APPENV;
47
- }
48
- if (appSrc != null) {
49
- createPayload(appSrc, function (err, r) {
50
- if (err) {
51
- console.log(err);
52
- console.log("createPayload failed");
53
- process.exit(1);
54
- } else {
55
- (0, _iService["default"])(uTable, useDefault, asset, r, serverMode, customize);
56
- }
57
- });
58
- } else {
59
- var appEnv = getAllEnv({});
60
- (0, _iService["default"])(uTable, useDefault, asset, appEnv, serverMode, customize);
61
- }
62
- }
63
- function setup(rafEnv, dockerFile) {
64
- (0, _config["default"])(rafEnv, dockerFile);
65
- var asset = process.env.APPLOC === "." ? process.cwd() : process.env.APPLOC;
66
- process.env.APPASSET = asset;
67
- return asset;
68
- }
69
- function createPayload(srcName, cb) {
70
- var src = _fs["default"].readFileSync(srcName, "utf8");
71
- if (src === null) {
72
- cb("Error: ".concat(srcName, " was not found. "));
73
- }
74
- try {
75
- // console.log(src);
76
- var f = new Function(src);
77
- console.log("".concat(srcName, " compile completed"));
78
- var r = f();
79
- f = null;
80
- var ar = getAllEnv(r);
81
- cb(null, ar);
82
- } catch (err) {
83
- console.log("".concat(srcName, " compile failed"));
84
- cb(err);
85
- }
86
- }
87
- function getAllEnv(userData) {
88
- var env;
89
- var l = null;
90
- debugger;
91
- if (process.env.AUTHTYPE != null) {
92
- process.env.AUTHFLOW = process.env.AUTHTYPE;
93
- }
94
- var authflow = trimit("AUTHFLOW");
95
- if (authflow === "authorization_code" || authflow === "code") {
96
- authflow = "server";
97
- }
98
- process.env.AUTHFLOW = authflow;
99
- var redirect = trimit("REDIRECT");
100
- var host = trimit("VIYA_SERVER");
101
- var clientID = trimit("CLIENTID");
102
- // eslint-disable-next-line no-unused-vars
103
- var clientSecret = trimit("CLIENTSECRET");
104
- var keepAlive = trimit("KEEPALIVE");
105
- var appName = trimit("APPNAME");
106
- var ns = trimit("NAMESPACE");
107
- 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
- l = {
115
- authType: authflow,
116
- redirect: redirect,
117
- host: host,
118
- clientID: clientID,
119
- clientSecret: clientSecret,
120
- appName: appName,
121
- appEntry: appEntry,
122
- keepAlive: null,
123
- useToken: process.env.USETOKEN,
124
- ns: ns,
125
- nsHost: nsHost
126
- };
127
- if (authflow !== null) {
128
- if (authflow === "implicit") {
129
- if (redirect === null) {
130
- redirect = "".concat(appName, "/callback");
131
- ;
132
- }
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);
137
- }
138
- }
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;
156
- }
157
-
158
- // pick up the app env's - replacement for appenv.js
159
- // appenv.js still supported for backward compatibility
160
- for (var key in process.env) {
161
- if (key.indexOf("APPENV_") === 0) {
162
- var k = key.substring(7);
163
- var v = process.env[key];
164
- if (v != null && v.trim().length > 0) {
165
- userData[k] = v.trim();
166
- }
167
- }
168
- }
169
- env = {
170
- LOGONPAYLOAD: l,
171
- APPENV: userData
172
- };
173
- console.log("Final APPENV configuration for the server");
174
- console.log(JSON.stringify(env, null, 4));
175
- return env;
176
- }
177
- function trimit(e) {
178
- var a = process.env[e];
179
- if (a === undefined) {
180
- return null;
181
- }
182
- a = a.trim();
183
- return a.length === 0 ? null : a;
184
- }