@sassoftware/viya-serverjs 0.1.0 → 0.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.
@@ -0,0 +1,195 @@
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
+ var env = argv.env == null ? null : argv.env;
31
+ var appenv = argv.appenv == null ? null : argv.appenv;
32
+ var docker = argv.docker == null ? null : argv.docker;
33
+ process.env.SERVERMODE = serverMode !== null ? "api" : "app";
34
+ if (useDefault == null) {
35
+ useDefault = true;
36
+ }
37
+ console.log("Initialization started ============================================================");
38
+ console.log("version: 2, Build Date: ", Date());
39
+ console.log("\nCommand Line Configuration:\n Dockerfile: ".concat(docker, "\n env file : ").concat(env, "\n appenv : ").concat(appenv, "\n customize : ").concat(customize != null, "\n "));
40
+ iapp(appenv, env, docker, uTable, useDefault, serverMode, customize);
41
+ };
42
+ function iapp(appSrc, rafEnv, dockerFile, uTable, useDefault, serverMode, customize) {
43
+ var asset = setup(rafEnv, dockerFile);
44
+ if (appSrc === null) {
45
+ appSrc = process.env.APPENV == null ? null : process.env.APPENV;
46
+ }
47
+ if (appSrc != null) {
48
+ createPayload(appSrc, function (err, r) {
49
+ if (err) {
50
+ console.log(err);
51
+ console.log("createPayload failed");
52
+ process.exit(1);
53
+ } else {
54
+ (0, _iService["default"])(uTable, useDefault, asset, r, serverMode, customize);
55
+ }
56
+ });
57
+ } else {
58
+ var appEnv = getAllEnv({});
59
+ (0, _iService["default"])(uTable, useDefault, asset, appEnv, serverMode, customize);
60
+ }
61
+ }
62
+ function setup(rafEnv, dockerFile) {
63
+ (0, _config["default"])(rafEnv, dockerFile);
64
+ var asset = process.env.APPLOC === "." ? process.cwd() : process.env.APPLOC;
65
+ process.env.APPASSET = asset;
66
+ return asset;
67
+ }
68
+ function createPayload(srcName, cb) {
69
+ var src = _fs["default"].readFileSync(srcName, "utf8");
70
+ if (src === null) {
71
+ cb("Error: ".concat(srcName, " was not found. "));
72
+ }
73
+ try {
74
+ // console.log(src);
75
+ var f = new Function(src);
76
+ console.log("".concat(srcName, " compile completed"));
77
+ var r = f();
78
+ f = null;
79
+ var ar = getAllEnv(r);
80
+ cb(null, ar);
81
+ } catch (err) {
82
+ console.log("".concat(srcName, " compile failed"));
83
+ cb(err);
84
+ }
85
+ }
86
+ function getAllEnv(userData) {
87
+ var env;
88
+ var l = null;
89
+ if (process.env.AUTHTYPE != null) {
90
+ process.env.AUTHFLOW = process.env.AUTHTYPE;
91
+ }
92
+ var authflow = trimit("AUTHFLOW");
93
+ if (authflow === "authorization_code" || authflow === "code") {
94
+ authflow = "server";
95
+ }
96
+ process.env.AUTHFLOW = authflow;
97
+ // let redirect = (process.env.REDIRECT != null) ? process.env.REDIRECT : null;
98
+ var redirect = trimit("REDIRECT");
99
+ var host = trimit("VIYA_SERVER");
100
+ var clientID = trimit("CLIENTID");
101
+ // eslint-disable-next-line no-unused-vars
102
+ var clientSecret = trimit("CLIENTSECRET");
103
+ var keepAlive = trimit("KEEPALIVE");
104
+ var appName = trimit("APPNAME");
105
+ var ns = trimit("NAMESPACE");
106
+ var nsHost = trimit("NSHOST");
107
+ l = {
108
+ authType: authflow,
109
+ redirect: redirect,
110
+ host: host,
111
+ clientID: clientID,
112
+ appName: appName,
113
+ keepAlive: null,
114
+ useToken: process.env.USETOKEN,
115
+ ns: ns,
116
+ nsHost: nsHost
117
+ };
118
+ if (authflow === "server" || authflow === "implicit") {
119
+ if (authflow === "implicit") {
120
+ if (redirect === null) {
121
+ redirect = "".concat(appName, "/callback");
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
+ }
127
+ }
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;
146
+ }
147
+ }
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
+ };
160
+ }
161
+
162
+ // pick up the app env's - replacement for appenv.js
163
+ // appenv.js still supported for backward compatibility
164
+
165
+ for (var key in process.env) {
166
+ debug(key);
167
+ if (key.indexOf("APPENV_") === 0) {
168
+ var k = key.substring(7);
169
+ var v = process.env[key];
170
+ if (v != null && v.trim().length > 0) {
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;
177
+ }
178
+ }
179
+ }
180
+ env = {
181
+ LOGONPAYLOAD: l,
182
+ APPENV: userData
183
+ };
184
+ console.log("Final APPENV configuration for the server");
185
+ console.log(JSON.stringify(env, null, 4));
186
+ return env;
187
+ }
188
+ function trimit(e) {
189
+ var a = process.env[e];
190
+ if (a == null || a === undefined) {
191
+ return null;
192
+ }
193
+ a = a.trim();
194
+ return a.length === 0 ? null : a;
195
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ 'use strict';
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports["default"] = void 0;
11
+ var parser = require('docker-file-parser');
12
+ var fs = require('fs');
13
+ function parseDocker(dockerFile) {
14
+ ;
15
+ var d = fs.readFileSync(dockerFile, 'utf8');
16
+ var data = parser.parse(d);
17
+ data.forEach(function (d) {
18
+ if (d.name === 'EXPOSE') {
19
+ process.env.EXPOSEDPORT = d.args[0];
20
+ console.log("Exposed port: ".concat(process.env.EXPOSEDPORT));
21
+ } else if (d.name === 'ENV') {
22
+ for (var key in d.args) {
23
+ var v = d.args[key];
24
+ if (v.length === 0) {
25
+ console.log("Value for ".concat(key, " inherited as ").concat(process.env[key]));
26
+ } else {
27
+ process.env[key] = v;
28
+ }
29
+ }
30
+ }
31
+ });
32
+ }
33
+ var _default = exports["default"] = parseDocker;
@@ -0,0 +1,100 @@
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
+ 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; }
5
+ 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); } }
6
+ 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); }); }; }
7
+ /*
8
+ * ------------------------------------------------------------------------------------
9
+ * * Copyright (c) SAS Institute Inc.
10
+ * * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * * you may not use this file except in compliance with the License.
12
+ * * You may obtain a copy of the License at
13
+ * *
14
+ * * http://www.apache.org/licenses/LICENSE-2.0
15
+ * *
16
+ * * Unless required by applicable law or agreed to in writing, software
17
+ * * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ * ----------------------------------------------------------------------------------------
22
+ *
23
+ */
24
+
25
+ var bell = require('@hapi/bell');
26
+ var uuid = require('uuid');
27
+ var debug = require('debug')('sasauth');
28
+ exports.plugin = {
29
+ name: 'SASauth',
30
+ version: '1.0.0',
31
+ register: iSASauth
32
+ };
33
+ function iSASauth(_x, _x2) {
34
+ return _iSASauth.apply(this, arguments);
35
+ }
36
+ function _iSASauth() {
37
+ _iSASauth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(server, options) {
38
+ var bellAuthOptions, provider, host;
39
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
40
+ while (1) switch (_context2.prev = _context2.next) {
41
+ case 0:
42
+ debug('in iSASauth');
43
+ debug(options);
44
+ // test for k8s deployment
45
+ host = options.host + '/SASLogon';
46
+ if (options.ns != null) {
47
+ host = "https://sas-logon-app.".concat(options.ns, ".svc.cluster.local");
48
+ } else if (options.nsHost != null) {
49
+ host = options.nsHost;
50
+ }
51
+ // ...
52
+ debug(host);
53
+ provider = {
54
+ name: 'sas',
55
+ protocol: 'oauth2',
56
+ useParamsAuth: false,
57
+ auth: host + '/oauth/authorize',
58
+ token: host + '/oauth/token',
59
+ profileMethod: 'get',
60
+ profile: function () {
61
+ var _profile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(credentials, params, get) {
62
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
63
+ while (1) switch (_context.prev = _context.next) {
64
+ case 0:
65
+ server.log('SASAuth profile', credentials);
66
+ case 1:
67
+ case "end":
68
+ return _context.stop();
69
+ }
70
+ }, _callee);
71
+ }));
72
+ function profile(_x3, _x4, _x5) {
73
+ return _profile.apply(this, arguments);
74
+ }
75
+ return profile;
76
+ }()
77
+ };
78
+ bellAuthOptions = {
79
+ provider: provider,
80
+ password: uuid.v4(),
81
+ clientId: options.clientId,
82
+ clientSecret: options.clientSecret,
83
+ // isSameSite : options.isSameSite,
84
+ isSecure: options.isSecure
85
+ };
86
+ // console.log('SASAuth options', bellAuthOptions);
87
+ debug(bellAuthOptions);
88
+ server.log('SASAuth', bellAuthOptions);
89
+ _context2.next = 11;
90
+ return server.register(bell);
91
+ case 11:
92
+ server.auth.strategy('sas', 'bell', bellAuthOptions);
93
+ case 12:
94
+ case "end":
95
+ return _context2.stop();
96
+ }
97
+ }, _callee2);
98
+ }));
99
+ return _iSASauth.apply(this, arguments);
100
+ }
@@ -0,0 +1,98 @@
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
+ 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; }
5
+ 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); } }
6
+ 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); }); }; }
7
+ var uuid = require('uuid');
8
+ var debug = require('debug')('appcookie');
9
+ module.exports = /*#__PURE__*/function () {
10
+ var _appCookie = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(server, options) {
11
+ var cookieOptions;
12
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
13
+ while (1) switch (_context2.prev = _context2.next) {
14
+ case 0:
15
+ _context2.next = 2;
16
+ return server.register(require('@hapi/cookie'));
17
+ case 2:
18
+ cookieOptions = {
19
+ cookie: {
20
+ name: 'cookie',
21
+ password: uuid.v4(),
22
+ isSecure: options.isSecure,
23
+ isSameSite: options.isSameSite
24
+ },
25
+ redirectTo: options.redirectTo,
26
+ appendNext: {
27
+ name: 'next'
28
+ },
29
+ validateFunc: function () {
30
+ var _validateFunc = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, session) {
31
+ var credentials, sid;
32
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
33
+ while (1) switch (_context.prev = _context.next) {
34
+ case 0:
35
+ server.log('Cookie validateFunc', "path - ".concat(req.path));
36
+ if (!(session == null)) {
37
+ _context.next = 4;
38
+ break;
39
+ }
40
+ console.log('session is null');
41
+ return _context.abrupt("return", {
42
+ valid: false
43
+ });
44
+ case 4:
45
+ credentials = null;
46
+ if (Array.isArray(session) === true && session.length > 0) {
47
+ sid = session[0].sid;
48
+ } else {
49
+ sid = session.sid;
50
+ }
51
+ if (!(sid != null)) {
52
+ _context.next = 10;
53
+ break;
54
+ }
55
+ _context.next = 9;
56
+ return req.server.app.cache.get(sid);
57
+ case 9:
58
+ credentials = _context.sent;
59
+ case 10:
60
+ if (!(credentials == null)) {
61
+ _context.next = 12;
62
+ break;
63
+ }
64
+ return _context.abrupt("return", {
65
+ valid: false
66
+ });
67
+ case 12:
68
+ server.log('Cookie validateFunc', sid);
69
+ return _context.abrupt("return", {
70
+ valid: true,
71
+ credentials: credentials
72
+ });
73
+ case 14:
74
+ case "end":
75
+ return _context.stop();
76
+ }
77
+ }, _callee);
78
+ }));
79
+ function validateFunc(_x3, _x4) {
80
+ return _validateFunc.apply(this, arguments);
81
+ }
82
+ return validateFunc;
83
+ }()
84
+ }; // console.log('cookie options', cookieOptions);
85
+ debug('Cookie Options', cookieOptions);
86
+ server.log('Cookie Options', cookieOptions);
87
+ server.auth.strategy('session', 'cookie', cookieOptions);
88
+ case 6:
89
+ case "end":
90
+ return _context2.stop();
91
+ }
92
+ }, _callee2);
93
+ }));
94
+ function appCookie(_x, _x2) {
95
+ return _appCookie.apply(this, arguments);
96
+ }
97
+ return appCookie;
98
+ }();
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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
+ /*
12
+ * ------------------------------------------------------------------------------------
13
+ * Copyright (c) SAS Institute Inc.
14
+ * Licensed under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License.
16
+ * You may obtain a copy of the License at
17
+ *
18
+ * http://www.apache.org/licenses/LICENSE-2.0
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ * ---------------------------------------------------------------------------------------
26
+ *
27
+ */
28
+ function setContext(_x, _x2) {
29
+ return _setContext.apply(this, arguments);
30
+ }
31
+ function _setContext() {
32
+ _setContext = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, h) {
33
+ var credentials, context;
34
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
35
+ while (1) switch (_context.prev = _context.next) {
36
+ case 0:
37
+ credentials = req.auth.credentials;
38
+ context = {
39
+ path: req.path,
40
+ params: req.params,
41
+ query: req.query,
42
+ payload: req.payload,
43
+ token: credentials != null ? "bearer ".concat(credentials.token) : null,
44
+ host: process.env.VIYA_SERVER
45
+ };
46
+ return _context.abrupt("return", context);
47
+ case 3:
48
+ case "end":
49
+ return _context.stop();
50
+ }
51
+ }, _callee);
52
+ }));
53
+ return _setContext.apply(this, arguments);
54
+ }
55
+ var _default = exports["default"] = setContext;