serverpreconfigured 2.2.3 → 2.2.4

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.
@@ -10,11 +10,15 @@ export interface SaveLogOptions {
10
10
  userId?: number;
11
11
  data: string;
12
12
  severity: LogSeverity;
13
+ addPath?: string;
14
+ filePrefix?: string;
13
15
  penTestSuspcion?: boolean;
14
16
  req?: Request;
15
17
  ip?: string;
16
18
  url?: string;
17
19
  }
20
+ export declare function stringfyError(err: any): string;
21
+ export declare function getIpFromRequest(req: Request): string;
18
22
  export declare function saveInternalErrorLog(req: Request, error: any, options?: {
19
23
  penTestSuspcion?: boolean;
20
24
  severity?: LogSeverity;
package/dist/logs/logs.js CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.saveLog = exports.saveInternalErrorLog = exports.LogSeverity = exports.BASE_LOG_PATH = void 0;
15
+ exports.saveLog = exports.saveInternalErrorLog = exports.getIpFromRequest = exports.stringfyError = exports.LogSeverity = exports.BASE_LOG_PATH = void 0;
16
16
  const fs_1 = __importDefault(require("fs"));
17
17
  const path_1 = __importDefault(require("path"));
18
18
  exports.BASE_LOG_PATH = './logs';
@@ -41,6 +41,7 @@ function stringfyError(err) {
41
41
  }
42
42
  return retData;
43
43
  }
44
+ exports.stringfyError = stringfyError;
44
45
  function getIpFromRequest(req) {
45
46
  //@
46
47
  let ips = (req.headers['cf-connecting-ip'] ||
@@ -52,6 +53,7 @@ function getIpFromRequest(req) {
52
53
  }
53
54
  return ips[0].trim();
54
55
  }
56
+ exports.getIpFromRequest = getIpFromRequest;
55
57
  function saveInternalErrorLog(req, error, options) {
56
58
  var _a;
57
59
  return __awaiter(this, void 0, void 0, function* () {
@@ -81,6 +83,12 @@ function saveLog(options) {
81
83
  fs_1.default.mkdirSync(exports.BASE_LOG_PATH);
82
84
  }
83
85
  let basePath = exports.BASE_LOG_PATH;
86
+ if (options.addPath) {
87
+ basePath = path_1.default.join(basePath, options.addPath);
88
+ if (!fs_1.default.existsSync(basePath)) {
89
+ fs_1.default.mkdirSync(basePath);
90
+ }
91
+ }
84
92
  if (options.userId) {
85
93
  basePath = path_1.default.join(basePath, options.userId.toString());
86
94
  }
@@ -90,7 +98,7 @@ function saveLog(options) {
90
98
  if (!fs_1.default.existsSync(basePath)) {
91
99
  fs_1.default.mkdirSync(basePath);
92
100
  }
93
- let fileName = path_1.default.join(basePath, `${getDateString(new Date())}.csv`);
101
+ let fileName = path_1.default.join(basePath, `${options.filePrefix ? options.filePrefix + '_' : ""}${getDateString(new Date())}.csv`);
94
102
  let data = "";
95
103
  if (fs_1.default.existsSync(fileName)) {
96
104
  data = fs_1.default.readFileSync(fileName).toString() + "\n";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverpreconfigured",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "\"Pre-configured server with authentication system and database integration\"",
5
5
  "main": "dist/server.js",
6
6
  "keywords": [
package/src/logs/logs.ts CHANGED
@@ -12,6 +12,8 @@ export interface SaveLogOptions{
12
12
  userId?:number;
13
13
  data:string;
14
14
  severity:LogSeverity;
15
+ addPath?:string;
16
+ filePrefix?:string;
15
17
  penTestSuspcion?:boolean;
16
18
  req?:Request;
17
19
  ip?:string;
@@ -19,7 +21,7 @@ export interface SaveLogOptions{
19
21
  }
20
22
 
21
23
 
22
- function stringfyError(err:any):string{
24
+ export function stringfyError(err:any):string{
23
25
  const type=typeof(err);
24
26
  if(type!=='object')
25
27
  return err.toString();
@@ -36,7 +38,7 @@ function stringfyError(err:any):string{
36
38
  }
37
39
  return retData;
38
40
  }
39
- function getIpFromRequest(req:Request){
41
+ export function getIpFromRequest(req:Request){
40
42
  //@
41
43
  let ips = (
42
44
  req.headers['cf-connecting-ip'] ||
@@ -73,6 +75,12 @@ export function saveLog(options:SaveLogOptions){
73
75
  fs.mkdirSync(BASE_LOG_PATH);
74
76
  }
75
77
  let basePath=BASE_LOG_PATH;
78
+ if(options.addPath){
79
+ basePath=path.join(basePath,options.addPath);
80
+ if(!fs.existsSync(basePath)){
81
+ fs.mkdirSync(basePath);
82
+ }
83
+ }
76
84
  if(options.userId){
77
85
  basePath=path.join(basePath,options.userId.toString());
78
86
  }else{
@@ -81,7 +89,7 @@ export function saveLog(options:SaveLogOptions){
81
89
  if(!fs.existsSync(basePath)){
82
90
  fs.mkdirSync(basePath);
83
91
  }
84
- let fileName=path.join(basePath,`${getDateString(new Date())}.csv`);
92
+ let fileName=path.join(basePath,`${options.filePrefix?options.filePrefix+'_':""}${getDateString(new Date())}.csv`);
85
93
  let data="";
86
94
  if(fs.existsSync(fileName)){
87
95
  data=fs.readFileSync(fileName).toString()+"\n";