@grandlinex/kernel 0.22.0 → 0.22.1-alpha.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +71 -71
  2. package/LICENSE +29 -29
  3. package/README.md +30 -30
  4. package/dist/Kernel.d.ts +22 -22
  5. package/dist/Kernel.js +68 -68
  6. package/dist/KernelModule.d.ts +8 -8
  7. package/dist/KernelModule.js +89 -89
  8. package/dist/actions/ApiAuthTestAction.d.ts +27 -27
  9. package/dist/actions/ApiAuthTestAction.js +93 -92
  10. package/dist/actions/ApiVersionAction.d.ts +30 -30
  11. package/dist/actions/ApiVersionAction.js +96 -96
  12. package/dist/actions/GetTokenAction.d.ts +43 -43
  13. package/dist/actions/GetTokenAction.js +135 -133
  14. package/dist/actions/index.d.ts +4 -4
  15. package/dist/actions/index.js +12 -12
  16. package/dist/api/KernelEndpoint.d.ts +3 -3
  17. package/dist/api/KernelEndpoint.js +29 -29
  18. package/dist/api/index.d.ts +2 -2
  19. package/dist/api/index.js +8 -8
  20. package/dist/classes/BaseAction.d.ts +13 -13
  21. package/dist/classes/BaseAction.js +103 -103
  22. package/dist/classes/BaseApiAction.d.ts +8 -8
  23. package/dist/classes/BaseApiAction.js +67 -67
  24. package/dist/classes/BaseAuthProvider.d.ts +23 -16
  25. package/dist/classes/BaseAuthProvider.js +8 -8
  26. package/dist/classes/BaseEndpoint.d.ts +12 -12
  27. package/dist/classes/BaseEndpoint.js +61 -61
  28. package/dist/classes/BaseKernelModule.d.ts +5 -5
  29. package/dist/classes/BaseKernelModule.js +26 -26
  30. package/dist/classes/index.d.ts +8 -7
  31. package/dist/classes/index.js +34 -23
  32. package/dist/database/KernelDB.d.ts +14 -0
  33. package/dist/database/KernelDB.js +115 -0
  34. package/dist/database/entity/GKey.d.ts +8 -0
  35. package/dist/database/entity/GKey.js +61 -0
  36. package/dist/index.d.ts +14 -14
  37. package/dist/index.js +31 -35
  38. package/dist/lib/index.d.ts +31 -28
  39. package/dist/lib/index.js +2 -2
  40. package/dist/modules/crypto/CryptoClient.d.ts +19 -17
  41. package/dist/modules/crypto/CryptoClient.js +152 -142
  42. package/dist/modules/crypto/index.d.ts +3 -3
  43. package/dist/modules/crypto/index.js +19 -23
  44. package/dist/modules/crypto/utils/cors.d.ts +3 -3
  45. package/dist/modules/crypto/utils/cors.js +10 -10
  46. package/package.json +69 -69
@@ -1,133 +1,135 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
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 (_) 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
- Object.defineProperty(exports, "__esModule", { value: true });
54
- var classes_1 = require("../classes");
55
- /**
56
- * @openapi
57
- * /token:
58
- * post:
59
- * summary: Get Bearer for user.
60
- * tags:
61
- * - Kernel
62
- * description: Returns JWT.
63
- * responses:
64
- * '200':
65
- * description: OK
66
- * content:
67
- * application/json:
68
- * schema:
69
- * type: object
70
- * properties:
71
- * token:
72
- * type: string
73
- * '403':
74
- * description: Not Authorized
75
- * requestBody:
76
- * required: true
77
- * content:
78
- * application/json:
79
- * schema:
80
- * type: object
81
- * properties:
82
- * username:
83
- * type: string
84
- * token:
85
- * type: string
86
- */
87
- var GetTokenAction = /** @class */ (function (_super) {
88
- __extends(GetTokenAction, _super);
89
- /**
90
- *
91
- * @param module Parent Module
92
- */
93
- function GetTokenAction(module) {
94
- var _this = _super.call(this, 'POST', '/token', module) || this;
95
- _this.handler = _this.handler.bind(_this);
96
- _this.setDmz(true);
97
- return _this;
98
- }
99
- GetTokenAction.prototype.handler = function (req, res, next) {
100
- return __awaiter(this, void 0, void 0, function () {
101
- var cc, _a, username, token, jwt;
102
- return __generator(this, function (_b) {
103
- switch (_b.label) {
104
- case 0:
105
- cc = this.getKernel().getCryptoClient();
106
- if (!req.body.token) {
107
- res.status(400).send('no token');
108
- return [2 /*return*/];
109
- }
110
- if (!req.body.username) {
111
- res.status(401).send('no username');
112
- return [2 /*return*/];
113
- }
114
- _a = req.body, username = _a.username, token = _a.token;
115
- return [4 /*yield*/, cc.apiTokenValidation(username, token, 'api')];
116
- case 1:
117
- if (_b.sent()) {
118
- jwt = cc.jwtGenerateAccessToken({
119
- username: username,
120
- });
121
- res.status(200).send({ token: jwt });
122
- }
123
- else {
124
- res.status(403).send('no no no ...');
125
- }
126
- return [2 /*return*/];
127
- }
128
- });
129
- });
130
- };
131
- return GetTokenAction;
132
- }(classes_1.BaseApiAction));
133
- exports.default = GetTokenAction;
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
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 (_) 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
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ var classes_1 = require("../classes");
55
+ /**
56
+ * @openapi
57
+ * /token:
58
+ * post:
59
+ * summary: Get Bearer for user.
60
+ * tags:
61
+ * - Kernel
62
+ * description: Returns JWT.
63
+ * responses:
64
+ * '200':
65
+ * description: OK
66
+ * content:
67
+ * application/json:
68
+ * schema:
69
+ * type: object
70
+ * properties:
71
+ * token:
72
+ * type: string
73
+ * '403':
74
+ * description: Not Authorized
75
+ * requestBody:
76
+ * required: true
77
+ * content:
78
+ * application/json:
79
+ * schema:
80
+ * type: object
81
+ * properties:
82
+ * username:
83
+ * type: string
84
+ * token:
85
+ * type: string
86
+ */
87
+ var GetTokenAction = /** @class */ (function (_super) {
88
+ __extends(GetTokenAction, _super);
89
+ /**
90
+ *
91
+ * @param module Parent Module
92
+ */
93
+ function GetTokenAction(module) {
94
+ var _this = _super.call(this, 'POST', '/token', module) || this;
95
+ _this.handler = _this.handler.bind(_this);
96
+ _this.setDmz(true);
97
+ return _this;
98
+ }
99
+ GetTokenAction.prototype.handler = function (req, res, next) {
100
+ return __awaiter(this, void 0, void 0, function () {
101
+ var cc, _a, username, token, valid, jwt;
102
+ return __generator(this, function (_b) {
103
+ switch (_b.label) {
104
+ case 0:
105
+ cc = this.getKernel().getCryptoClient();
106
+ if (!req.body.token) {
107
+ res.status(400).send('no token');
108
+ return [2 /*return*/];
109
+ }
110
+ if (!req.body.username) {
111
+ res.status(401).send('no username');
112
+ return [2 /*return*/];
113
+ }
114
+ _a = req.body, username = _a.username, token = _a.token;
115
+ return [4 /*yield*/, cc.apiTokenValidation(username, token, 'api')];
116
+ case 1:
117
+ valid = _b.sent();
118
+ if (valid.valid && valid.userId) {
119
+ jwt = cc.jwtGenerateAccessToken({
120
+ userid: valid.userId,
121
+ username: username,
122
+ });
123
+ res.status(200).send({ token: jwt });
124
+ }
125
+ else {
126
+ res.status(403).send('no no no ...');
127
+ }
128
+ return [2 /*return*/];
129
+ }
130
+ });
131
+ });
132
+ };
133
+ return GetTokenAction;
134
+ }(classes_1.BaseApiAction));
135
+ exports.default = GetTokenAction;
@@ -1,4 +1,4 @@
1
- import ApiAuthTestAction from './ApiAuthTestAction';
2
- import ApiVersionAction from './ApiVersionAction';
3
- import GetTokenAction from './GetTokenAction';
4
- export { ApiVersionAction, ApiAuthTestAction, GetTokenAction };
1
+ import ApiAuthTestAction from './ApiAuthTestAction';
2
+ import ApiVersionAction from './ApiVersionAction';
3
+ import GetTokenAction from './GetTokenAction';
4
+ export { ApiVersionAction, ApiAuthTestAction, GetTokenAction };
@@ -1,12 +1,12 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.GetTokenAction = exports.ApiAuthTestAction = exports.ApiVersionAction = void 0;
7
- var ApiAuthTestAction_1 = __importDefault(require("./ApiAuthTestAction"));
8
- exports.ApiAuthTestAction = ApiAuthTestAction_1.default;
9
- var ApiVersionAction_1 = __importDefault(require("./ApiVersionAction"));
10
- exports.ApiVersionAction = ApiVersionAction_1.default;
11
- var GetTokenAction_1 = __importDefault(require("./GetTokenAction"));
12
- exports.GetTokenAction = GetTokenAction_1.default;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GetTokenAction = exports.ApiAuthTestAction = exports.ApiVersionAction = void 0;
7
+ var ApiAuthTestAction_1 = __importDefault(require("./ApiAuthTestAction"));
8
+ exports.ApiAuthTestAction = ApiAuthTestAction_1.default;
9
+ var ApiVersionAction_1 = __importDefault(require("./ApiVersionAction"));
10
+ exports.ApiVersionAction = ApiVersionAction_1.default;
11
+ var GetTokenAction_1 = __importDefault(require("./GetTokenAction"));
12
+ exports.GetTokenAction = GetTokenAction_1.default;
@@ -1,3 +1,3 @@
1
- import BaseEndpoint from '../classes/BaseEndpoint';
2
- export default class KernelEndpoint extends BaseEndpoint {
3
- }
1
+ import BaseEndpoint from '../classes/BaseEndpoint';
2
+ export default class KernelEndpoint extends BaseEndpoint {
3
+ }
@@ -1,29 +1,29 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- var BaseEndpoint_1 = __importDefault(require("../classes/BaseEndpoint"));
22
- var KernelEndpoint = /** @class */ (function (_super) {
23
- __extends(KernelEndpoint, _super);
24
- function KernelEndpoint() {
25
- return _super !== null && _super.apply(this, arguments) || this;
26
- }
27
- return KernelEndpoint;
28
- }(BaseEndpoint_1.default));
29
- exports.default = KernelEndpoint;
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var BaseEndpoint_1 = __importDefault(require("../classes/BaseEndpoint"));
22
+ var KernelEndpoint = /** @class */ (function (_super) {
23
+ __extends(KernelEndpoint, _super);
24
+ function KernelEndpoint() {
25
+ return _super !== null && _super.apply(this, arguments) || this;
26
+ }
27
+ return KernelEndpoint;
28
+ }(BaseEndpoint_1.default));
29
+ exports.default = KernelEndpoint;
@@ -1,2 +1,2 @@
1
- import KernelEndpoint from './KernelEndpoint';
2
- export { KernelEndpoint };
1
+ import KernelEndpoint from './KernelEndpoint';
2
+ export { KernelEndpoint };
package/dist/api/index.js CHANGED
@@ -1,8 +1,8 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.KernelEndpoint = void 0;
7
- var KernelEndpoint_1 = __importDefault(require("./KernelEndpoint"));
8
- exports.KernelEndpoint = KernelEndpoint_1.default;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.KernelEndpoint = void 0;
7
+ var KernelEndpoint_1 = __importDefault(require("./KernelEndpoint"));
8
+ exports.KernelEndpoint = KernelEndpoint_1.default;
@@ -1,13 +1,13 @@
1
- import { Request, Response } from 'express';
2
- import { CoreAction } from '@grandlinex/core';
3
- import { IBaseAction, IBaseKernelModule } from '../lib';
4
- import { JwtToken } from './BaseAuthProvider';
5
- export default abstract class BaseAction extends CoreAction implements IBaseAction {
6
- dmz: boolean;
7
- constructor(chanel: string, module: IBaseKernelModule<any, any, any, any>);
8
- abstract handler(req: Request, res: Response, next: () => void, data: JwtToken | null): Promise<void>;
9
- secureHandler(req: Request, res: Response, next: () => void): Promise<void>;
10
- abstract register(): void;
11
- setDmz(val: boolean): void;
12
- getDmz(): boolean;
13
- }
1
+ import { Request, Response } from 'express';
2
+ import { CoreAction } from '@grandlinex/core';
3
+ import { IBaseAction, IBaseKernelModule } from '../lib';
4
+ import { JwtToken } from './BaseAuthProvider';
5
+ export default abstract class BaseAction extends CoreAction implements IBaseAction {
6
+ dmz: boolean;
7
+ constructor(chanel: string, module: IBaseKernelModule<any, any, any, any>);
8
+ abstract handler(req: Request, res: Response, next: () => void, data: JwtToken | null): Promise<void>;
9
+ secureHandler(req: Request, res: Response, next: () => void): Promise<void>;
10
+ abstract register(): void;
11
+ setDmz(val: boolean): void;
12
+ getDmz(): boolean;
13
+ }
@@ -1,103 +1,103 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
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 (_) 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
- Object.defineProperty(exports, "__esModule", { value: true });
54
- var core_1 = require("@grandlinex/core");
55
- var BaseAction = /** @class */ (function (_super) {
56
- __extends(BaseAction, _super);
57
- function BaseAction(chanel, module) {
58
- var _this = _super.call(this, chanel, module) || this;
59
- _this.dmz = false;
60
- _this.secureHandler = _this.secureHandler.bind(_this);
61
- return _this;
62
- }
63
- BaseAction.prototype.secureHandler = function (req, res, next) {
64
- return __awaiter(this, void 0, void 0, function () {
65
- var cc, dat;
66
- return __generator(this, function (_a) {
67
- switch (_a.label) {
68
- case 0:
69
- cc = this.getKernel().getCryptoClient();
70
- if (!cc) {
71
- res.status(504).send('internal server error');
72
- return [2 /*return*/];
73
- }
74
- if (!this.dmz) return [3 /*break*/, 2];
75
- return [4 /*yield*/, this.handler(req, res, next, null)];
76
- case 1:
77
- _a.sent();
78
- return [2 /*return*/];
79
- case 2: return [4 /*yield*/, cc.bearerTokenValidation(req)];
80
- case 3:
81
- dat = _a.sent();
82
- if (!dat) return [3 /*break*/, 5];
83
- return [4 /*yield*/, this.handler(req, res, next, dat)];
84
- case 4:
85
- _a.sent();
86
- return [3 /*break*/, 6];
87
- case 5:
88
- res.status(401).send('no no no ...');
89
- _a.label = 6;
90
- case 6: return [2 /*return*/];
91
- }
92
- });
93
- });
94
- };
95
- BaseAction.prototype.setDmz = function (val) {
96
- this.dmz = val;
97
- };
98
- BaseAction.prototype.getDmz = function () {
99
- return this.dmz;
100
- };
101
- return BaseAction;
102
- }(core_1.CoreAction));
103
- exports.default = BaseAction;
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
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 (_) 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
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ var core_1 = require("@grandlinex/core");
55
+ var BaseAction = /** @class */ (function (_super) {
56
+ __extends(BaseAction, _super);
57
+ function BaseAction(chanel, module) {
58
+ var _this = _super.call(this, chanel, module) || this;
59
+ _this.dmz = false;
60
+ _this.secureHandler = _this.secureHandler.bind(_this);
61
+ return _this;
62
+ }
63
+ BaseAction.prototype.secureHandler = function (req, res, next) {
64
+ return __awaiter(this, void 0, void 0, function () {
65
+ var cc, dat;
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0:
69
+ cc = this.getKernel().getCryptoClient();
70
+ if (!cc) {
71
+ res.status(504).send('internal server error');
72
+ return [2 /*return*/];
73
+ }
74
+ if (!this.dmz) return [3 /*break*/, 2];
75
+ return [4 /*yield*/, this.handler(req, res, next, null)];
76
+ case 1:
77
+ _a.sent();
78
+ return [2 /*return*/];
79
+ case 2: return [4 /*yield*/, cc.bearerTokenValidation(req)];
80
+ case 3:
81
+ dat = _a.sent();
82
+ if (!dat) return [3 /*break*/, 5];
83
+ return [4 /*yield*/, this.handler(req, res, next, dat)];
84
+ case 4:
85
+ _a.sent();
86
+ return [3 /*break*/, 6];
87
+ case 5:
88
+ res.status(401).send('no no no ...');
89
+ _a.label = 6;
90
+ case 6: return [2 /*return*/];
91
+ }
92
+ });
93
+ });
94
+ };
95
+ BaseAction.prototype.setDmz = function (val) {
96
+ this.dmz = val;
97
+ };
98
+ BaseAction.prototype.getDmz = function () {
99
+ return this.dmz;
100
+ };
101
+ return BaseAction;
102
+ }(core_1.CoreAction));
103
+ exports.default = BaseAction;