namirasoft-node 1.2.5 → 1.2.6
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.
- package/dist/BaseController.js +28 -19
- package/dist/BaseController.js.map +1 -1
- package/package.json +2 -2
- package/src/BaseController.ts +31 -20
package/dist/BaseController.js
CHANGED
|
@@ -36,25 +36,34 @@ class BaseController {
|
|
|
36
36
|
this.meta.onStart();
|
|
37
37
|
if (this.showLogAtTheBeginning)
|
|
38
38
|
this.logger.info(JSON.stringify(this.meta));
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
39
|
+
let accpet = new namirasoft_core_1.ObjectService(this.req.headers.accept).getString();
|
|
40
|
+
let isJson = accpet == "application/json" || accpet == "" || !accpet;
|
|
41
|
+
let isSchema = accpet == "application/schema";
|
|
42
|
+
if (isJson) {
|
|
43
|
+
// init controller
|
|
44
|
+
this.database = this.getDatabase();
|
|
45
|
+
this.database.init();
|
|
46
|
+
this.state = yield this.getState();
|
|
47
|
+
this.props = yield this.getProps();
|
|
48
|
+
// preHandle
|
|
49
|
+
yield this.preHandle();
|
|
50
|
+
// check for anomaly
|
|
51
|
+
let anomaly = this.getAnomaly();
|
|
52
|
+
if (anomaly != null)
|
|
53
|
+
if (anomaly.isAnomaly(this.meta.ip, this.meta.url))
|
|
54
|
+
namirasoft_core_1.ErrorOperation.throwHTTP(403, 'Suspicious activity detected.');
|
|
55
|
+
// check
|
|
56
|
+
namirasoft_schema_1.JoiValidator.check(yield this.getBodySchema(), this.req.body);
|
|
57
|
+
namirasoft_schema_1.JoiValidator.checkArray(yield this.getQueriesSchema(), this.req.query);
|
|
58
|
+
// call controller
|
|
59
|
+
this.output = yield this.handle();
|
|
60
|
+
// postHandle
|
|
61
|
+
yield this.postHandle();
|
|
62
|
+
}
|
|
63
|
+
else if (isSchema)
|
|
64
|
+
this.result = yield this.getSchema();
|
|
65
|
+
else
|
|
66
|
+
namirasoft_core_1.ErrorOperation.throwHTTP(400, "Invalid accept: " + accpet);
|
|
58
67
|
}
|
|
59
68
|
catch (error) {
|
|
60
69
|
let message;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseController.js","sourceRoot":"","sources":["../src/BaseController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,iCAA8B;AAC9B,
|
|
1
|
+
{"version":3,"file":"BaseController.js","sourceRoot":"","sources":["../src/BaseController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,iCAA8B;AAC9B,qDAAuF;AAEvF,yDAAuG;AAEvG,MAAsB,cAAc;IAchC,YAAY,GAAuB,EAAE,GAAoB,EAAE,GAAqB;QAZtE,0BAAqB,GAAY,KAAK,CAAC;QACvC,oBAAe,GAAY,IAAI,CAAC;QAatC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACnC,CAAC;IACS,UAAU;QAEhB,OAAO,IAAI,CAAC;IAChB,CAAC;IAeK,GAAG;;YAEL,IAAI,CAAC,IAAI,GAAG,IAAI,WAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC/B,SAAS;YACT,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,IACA;gBACI,OAAO;gBACP,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACpB,IAAI,IAAI,CAAC,qBAAqB;oBAC1B,IAAI,CAAC,MAAM,CAAC,I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YACf,OAAO,MAAM,CAAC;QAClB,CAAC;KAAA;CACJ;AA5ID,wCA4IC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "namirasoft-node",
|
|
3
3
|
"description": "Namira Software Corporation Node NPM Package",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.6",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {},
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"joi": "^17.11.0",
|
|
22
22
|
"namirasoft-core": "^1.2.0",
|
|
23
23
|
"namirasoft-log": "^1.2.0",
|
|
24
|
-
"namirasoft-schema": "^1.2.
|
|
24
|
+
"namirasoft-schema": "^1.2.4",
|
|
25
25
|
"nodemailer": "^6.9.7",
|
|
26
26
|
"nodemailer-smtp-transport": "^2.7.4",
|
|
27
27
|
"request-ip": "^3.3.0",
|
package/src/BaseController.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BaseDatabase } from './BaseDatabase';
|
|
|
3
3
|
import { AnomalyDetector } from './AnomalyDetector';
|
|
4
4
|
import { ILogger } from 'namirasoft-log';
|
|
5
5
|
import { Meta } from './Meta';
|
|
6
|
-
import { ErrorOperation, HTTPError, HTTPMethod } from 'namirasoft-core';
|
|
6
|
+
import { ErrorOperation, HTTPError, HTTPMethod, ObjectService } from 'namirasoft-core';
|
|
7
7
|
import { BaseApplication } from './BaseApplication';
|
|
8
8
|
import { BaseTypeSchema, BaseVariableSchema, ControllerSchema, JoiValidator } from 'namirasoft-schema';
|
|
9
9
|
|
|
@@ -58,30 +58,41 @@ export abstract class BaseController<D extends BaseDatabase, State, Props, Outpu
|
|
|
58
58
|
this.meta.onStart();
|
|
59
59
|
if (this.showLogAtTheBeginning)
|
|
60
60
|
this.logger.info(JSON.stringify(this.meta));
|
|
61
|
-
// init controller
|
|
62
|
-
this.database = this.getDatabase();
|
|
63
|
-
this.database.init();
|
|
64
|
-
this.state = await this.getState();
|
|
65
|
-
this.props = await this.getProps();
|
|
66
61
|
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
let accpet: string = new ObjectService(this.req.headers.accept).getString();
|
|
63
|
+
let isJson = accpet == "application/json" || accpet == "" || !accpet;
|
|
64
|
+
let isSchema = accpet == "application/schema";
|
|
65
|
+
if (isJson)
|
|
66
|
+
{
|
|
67
|
+
// init controller
|
|
68
|
+
this.database = this.getDatabase();
|
|
69
|
+
this.database.init();
|
|
70
|
+
this.state = await this.getState();
|
|
71
|
+
this.props = await this.getProps();
|
|
72
|
+
|
|
73
|
+
// preHandle
|
|
74
|
+
await this.preHandle();
|
|
69
75
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
// check for anomaly
|
|
77
|
+
let anomaly: AnomalyDetector | null = this.getAnomaly();
|
|
78
|
+
if (anomaly != null)
|
|
79
|
+
if (anomaly.isAnomaly(this.meta.ip, this.meta.url))
|
|
80
|
+
ErrorOperation.throwHTTP(403, 'Suspicious activity detected.');
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
// check
|
|
83
|
+
JoiValidator.check(await this.getBodySchema(), this.req.body);
|
|
84
|
+
JoiValidator.checkArray(await this.getQueriesSchema(), this.req.query);
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
// call controller
|
|
87
|
+
this.output = await this.handle();
|
|
82
88
|
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
// postHandle
|
|
90
|
+
await this.postHandle();
|
|
91
|
+
}
|
|
92
|
+
else if (isSchema)
|
|
93
|
+
this.result = await this.getSchema();
|
|
94
|
+
else
|
|
95
|
+
ErrorOperation.throwHTTP(400, "Invalid accept: " + accpet);
|
|
85
96
|
} catch (error)
|
|
86
97
|
{
|
|
87
98
|
let message: string;
|