badmfck-api-server 2.0.1 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,4 +59,5 @@ export declare class APIService extends BaseService {
59
59
  constructor(options?: APIServiceOptions | null);
60
60
  init(): Promise<void>;
61
61
  sendResponse(res: Response, data: TransferPacketVO<any>, requestTime: number, endpoint?: string, log?: APIServiceNetworkLogItem | null, req?: HTTPRequestVO): Promise<void>;
62
+ checkDataLength(data: any, result?: any, lvl?: number): any;
62
63
  }
@@ -194,8 +194,8 @@ class APIService extends BaseService_1.BaseService {
194
194
  log = await exports.REQ_CREATE_NET_LOG.request();
195
195
  log.request = {
196
196
  method: req.method,
197
- data: req.body,
198
- params: req.params
197
+ data: this.checkDataLength(req.body),
198
+ params: this.checkDataLength(req.params)
199
199
  };
200
200
  }
201
201
  const execute = async () => {
@@ -386,5 +386,28 @@ class APIService extends BaseService_1.BaseService {
386
386
  if (this.options.onNetworkLog && log)
387
387
  this.options.onNetworkLog(log);
388
388
  }
389
+ checkDataLength(data, result, lvl) {
390
+ if (!result)
391
+ result = {};
392
+ if (!lvl)
393
+ lvl = 0;
394
+ if (typeof data !== "object") {
395
+ if (typeof data === "string" && data.length > 1024)
396
+ return data.substring(0, 1000) + "... (total:" + data.length + ")";
397
+ return data;
398
+ }
399
+ if (typeof data === "object") {
400
+ let arrcnt = 100;
401
+ for (let i in data) {
402
+ result[i] = this.checkDataLength(data[i], result[i], lvl + 1);
403
+ arrcnt--;
404
+ if (arrcnt <= 0) {
405
+ result["..."] = "...";
406
+ break;
407
+ }
408
+ }
409
+ }
410
+ return result;
411
+ }
389
412
  }
390
413
  exports.APIService = APIService;
@@ -1,12 +1,13 @@
1
+ export type TValidatorType = "string" | "number" | "boolean" | "date" | "array" | "object" | "email" | "phone";
1
2
  export interface IValidatorOptions {
2
3
  min?: number;
3
4
  max?: number;
4
- type?: "string" | "boolean" | "number";
5
+ type?: TValidatorType;
5
6
  regex?: RegExp;
6
7
  }
7
8
  export interface IValidaotrType {
8
9
  name: string;
9
- type: "string" | "number" | "boolean" | "date" | "array" | "object" | "email" | "phone";
10
+ type: TValidatorType;
10
11
  optional?: boolean;
11
12
  arrayType?: IValidaotrType;
12
13
  }
@@ -86,6 +86,9 @@ class Validator {
86
86
  return ValidationReport.VALUE_TOO_BIG;
87
87
  if (opt.min && value.length < opt.min)
88
88
  return ValidationReport.VALUE_TOO_SHORT;
89
+ if (opt.type === "email" && !opt.regex) {
90
+ opt.regex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,6}$/g;
91
+ }
89
92
  if (opt.regex) {
90
93
  const tmp = value.replaceAll(opt.regex, "");
91
94
  if (tmp.length !== 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",