@grandlinex/kernel 0.26.0 → 0.27.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.
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ServerTiming = exports.ServerTimingElement = exports.ExpressServerTiming = void 0;
7
- var ExpressServerTiming_1 = __importDefault(require("./ExpressServerTiming"));
7
+ const ExpressServerTiming_1 = __importDefault(require("./ExpressServerTiming"));
8
8
  exports.ExpressServerTiming = ExpressServerTiming_1.default;
9
- var ServerTiming_1 = __importDefault(require("./ServerTiming"));
9
+ const ServerTiming_1 = __importDefault(require("./ServerTiming"));
10
10
  exports.ServerTiming = ServerTiming_1.default;
11
- var ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
11
+ const ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
12
12
  exports.ServerTimingElement = ServerTimingElement_1.default;
package/dist/index.js CHANGED
@@ -22,9 +22,9 @@ exports.Kernel = exports.KernelModule = void 0;
22
22
  * @name Kernel Main Module
23
23
  * @author David Nagy
24
24
  */
25
- var Kernel_1 = __importDefault(require("./Kernel"));
25
+ const Kernel_1 = __importDefault(require("./Kernel"));
26
26
  exports.Kernel = Kernel_1.default;
27
- var KernelModule_1 = __importDefault(require("./KernelModule"));
27
+ const KernelModule_1 = __importDefault(require("./KernelModule"));
28
28
  exports.KernelModule = KernelModule_1.default;
29
29
  __exportStar(require("./actions"), exports);
30
30
  __exportStar(require("./api"), exports);
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -23,59 +8,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
24
9
  });
25
10
  };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
54
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
55
13
  };
56
14
  Object.defineProperty(exports, "__esModule", { value: true });
57
- var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
58
- var core_1 = require("@grandlinex/core");
59
- var CryptoClient = /** @class */ (function (_super) {
60
- __extends(CryptoClient, _super);
61
- function CryptoClient(key, kernel) {
62
- var _this = _super.call(this, kernel, key) || this;
63
- _this.kernel = kernel;
64
- _this.authProvider = null;
65
- _this.expiresIn = kernel.getConfigStore().get('JWT_EXPIRE') || '1 days';
66
- return _this;
15
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
16
+ const core_1 = require("@grandlinex/core");
17
+ class CryptoClient extends core_1.CoreCryptoClient {
18
+ constructor(key, kernel) {
19
+ super(kernel, key);
20
+ this.kernel = kernel;
21
+ this.authProvider = null;
22
+ this.expiresIn = kernel.getConfigStore().get('JWT_EXPIRE') || '1 days';
67
23
  }
68
- CryptoClient.prototype.setAuthProvider = function (provider) {
24
+ setAuthProvider(provider) {
69
25
  if (this.authProvider) {
70
26
  return false;
71
27
  }
72
28
  this.authProvider = provider;
73
29
  return true;
74
- };
75
- CryptoClient.prototype.jwtVerifyAccessToken = function (token) {
76
- var _this = this;
77
- return new Promise(function (resolve) {
78
- jsonwebtoken_1.default.verify(token, _this.AesKey, function (err, user) {
30
+ }
31
+ jwtVerifyAccessToken(token) {
32
+ return new Promise((resolve) => {
33
+ jsonwebtoken_1.default.verify(token, this.AesKey, (err, user) => {
79
34
  if (err || user === null) {
80
35
  resolve(null);
81
36
  }
@@ -84,69 +39,55 @@ var CryptoClient = /** @class */ (function (_super) {
84
39
  }
85
40
  });
86
41
  });
87
- };
88
- CryptoClient.prototype.jwtGenerateAccessToken = function (data) {
42
+ }
43
+ jwtGenerateAccessToken(data) {
89
44
  return jsonwebtoken_1.default.sign(data, this.AesKey, { expiresIn: this.expiresIn });
90
- };
91
- CryptoClient.prototype.apiTokenValidation = function (username, token, requestType) {
92
- return __awaiter(this, void 0, void 0, function () {
93
- var store;
94
- return __generator(this, function (_a) {
95
- if (this.authProvider) {
96
- return [2 /*return*/, this.authProvider.authorizeToken(username, token, requestType)];
97
- }
98
- store = this.kernel.getConfigStore();
99
- if (!store.has('SERVER_PASSWORD')) {
100
- return [2 /*return*/, { valid: false, userId: null }];
101
- }
102
- if (token === store.get('SERVER_PASSWORD') && username === 'admin') {
103
- return [2 /*return*/, {
104
- valid: true,
105
- userId: 'admin',
106
- }];
107
- }
108
- return [2 /*return*/, {
109
- valid: false,
110
- userId: null,
111
- }];
112
- });
45
+ }
46
+ apiTokenValidation(username, token, requestType) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ if (this.authProvider) {
49
+ return this.authProvider.authorizeToken(username, token, requestType);
50
+ }
51
+ const store = this.kernel.getConfigStore();
52
+ if (!store.has('SERVER_PASSWORD')) {
53
+ return { valid: false, userId: null };
54
+ }
55
+ if (token === store.get('SERVER_PASSWORD') && username === 'admin') {
56
+ return {
57
+ valid: true,
58
+ userId: 'admin',
59
+ };
60
+ }
61
+ return {
62
+ valid: false,
63
+ userId: null,
64
+ };
113
65
  });
114
- };
115
- CryptoClient.prototype.permissionValidation = function (token, requestType) {
116
- return __awaiter(this, void 0, void 0, function () {
117
- return __generator(this, function (_a) {
118
- if (this.authProvider) {
119
- return [2 /*return*/, this.authProvider.validateAccess(token, requestType)];
120
- }
121
- return [2 /*return*/, false];
122
- });
66
+ }
67
+ permissionValidation(token, requestType) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ if (this.authProvider) {
70
+ return this.authProvider.validateAccess(token, requestType);
71
+ }
72
+ return false;
123
73
  });
124
- };
125
- CryptoClient.prototype.bearerTokenValidation = function (req) {
126
- return __awaiter(this, void 0, void 0, function () {
127
- var authHeader, token, tokenData;
128
- return __generator(this, function (_a) {
129
- switch (_a.label) {
130
- case 0:
131
- if (this.authProvider) {
132
- return [2 /*return*/, this.authProvider.bearerTokenValidation(req)];
133
- }
134
- authHeader = req.headers.authorization;
135
- token = authHeader && authHeader.split(' ')[1];
136
- if (token == null) {
137
- return [2 /*return*/, null];
138
- }
139
- return [4 /*yield*/, this.jwtVerifyAccessToken(token)];
140
- case 1:
141
- tokenData = _a.sent();
142
- if (tokenData) {
143
- return [2 /*return*/, tokenData];
144
- }
145
- return [2 /*return*/, null];
146
- }
147
- });
74
+ }
75
+ bearerTokenValidation(req) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (this.authProvider) {
78
+ return this.authProvider.bearerTokenValidation(req);
79
+ }
80
+ const authHeader = req.headers.authorization;
81
+ const token = authHeader && authHeader.split(' ')[1];
82
+ if (token == null) {
83
+ return null;
84
+ }
85
+ const tokenData = yield this.jwtVerifyAccessToken(token);
86
+ if (tokenData) {
87
+ return tokenData;
88
+ }
89
+ return null;
148
90
  });
149
- };
150
- return CryptoClient;
151
- }(core_1.CoreCryptoClient));
91
+ }
92
+ }
152
93
  exports.default = CryptoClient;
@@ -18,6 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.CryptoClient = void 0;
21
- var CryptoClient_1 = __importDefault(require("./CryptoClient"));
21
+ const CryptoClient_1 = __importDefault(require("./CryptoClient"));
22
22
  exports.CryptoClient = CryptoClient_1.default;
23
23
  __exportStar(require("./utils/cors"), exports);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cors = void 0;
4
- var cors = function (req, res, next) {
4
+ const cors = (req, res, next) => {
5
5
  res.setHeader('Access-Control-Allow-Headers', '*');
6
6
  res.setHeader('Access-Control-Allow-Origin', '*');
7
7
  res.setHeader('Access-Control-Allow-Methods', '*');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grandlinex/kernel",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "GrandLineX is an out-of-the-box server framework on top of ExpressJs.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "license": "BSD-3-Clause",
29
29
  "dependencies": {
30
- "@grandlinex/core": "^0.26.0",
30
+ "@grandlinex/core": "^0.27.0",
31
31
  "axios": "^0.27.2",
32
32
  "body-parser": "^1.20.1",
33
33
  "express": "^4.18.2",