badmfck-api-server 3.8.4 → 3.8.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.
@@ -40,7 +40,6 @@ export interface APIServiceOptions<TInterceptor = unknown> {
40
40
  monitor?: IMonitorUser[];
41
41
  documentation?: IMonitorUser[];
42
42
  };
43
- monitor?: IMonitorUser[];
44
43
  appVersion?: string;
45
44
  fileTempDir: string;
46
45
  fileLimit: number;
@@ -61,7 +60,6 @@ export declare const REQ_MONITOR_USERS: Req<void, IMonitorUser[]>;
61
60
  export declare const REQ_DOC_USERS: Req<void, IMonitorUser[]>;
62
61
  export declare function Initializer(services: IBaseService[]): Promise<void>;
63
62
  export declare class APIService extends BaseService {
64
- private static nextLogID;
65
63
  private version;
66
64
  private options;
67
65
  private monitor;
@@ -46,23 +46,22 @@ const MysqlAdapter_1 = require("./db/MysqlAdapter");
46
46
  const DocumentService_1 = require("./DocumentService");
47
47
  const Documentation_1 = require("./documentation/Documentation");
48
48
  let nextLogID = 0;
49
- function bindRequestToOptions(opts, req) {
50
- return req;
51
- }
52
49
  function defaultOptions() {
53
50
  return {
54
51
  port: 8080,
55
52
  baseEndPoint: "/api/",
56
- corsHostWhiteList: [],
57
- projectName: "App",
53
+ corsHostWhiteList: ["localhost:3000"],
58
54
  endpoints: [],
59
55
  jsonLimit: "10mb",
56
+ projectName: "Application project",
60
57
  isProductionEnvironment: false,
61
58
  interceptor: undefined,
62
59
  postproducer: undefined,
63
60
  preproducer: undefined,
64
- access: {},
65
- monitor: undefined,
61
+ access: {
62
+ monitor: [],
63
+ documentation: []
64
+ },
66
65
  appVersion: undefined,
67
66
  fileTempDir: "/tmp",
68
67
  fileLimit: 10_000_000,
@@ -94,8 +93,7 @@ async function Initializer(services) {
94
93
  }
95
94
  exports.Initializer = Initializer;
96
95
  class APIService extends BaseService_1.BaseService {
97
- static nextLogID = 0;
98
- version = "3.8.4";
96
+ version = "3.8.6";
99
97
  options;
100
98
  monitor = null;
101
99
  started = new Date();
@@ -109,7 +107,7 @@ class APIService extends BaseService_1.BaseService {
109
107
  const self = "http://localhost:" + this.options.port;
110
108
  if (!this.options.corsHostWhiteList.find(val => val === self))
111
109
  this.options.corsHostWhiteList.push();
112
- exports.REQ_MONITOR_USERS.listener = async () => this.options.access.monitor ?? this.options.monitor ?? [];
110
+ exports.REQ_MONITOR_USERS.listener = async () => this.options.access.monitor ?? [];
113
111
  exports.REQ_DOC_USERS.listener = async () => this.options.access.documentation ?? [];
114
112
  this.options.endpoints.push(new Monitor_1.Monitor(this.options));
115
113
  this.options.endpoints.push(new Documentation_1.Documentation(this.options));
@@ -276,14 +274,12 @@ class APIService extends BaseService_1.BaseService {
276
274
  if (!ignoreInterceptor) {
277
275
  let interceptorResult;
278
276
  if (this.options.interceptor) {
279
- const httpRequestBound = bindRequestToOptions(this.options, httpRequest);
280
277
  interceptorResult = await this.options.interceptor.intercept(httpRequest);
281
278
  if (DefaultErrors_1.ErrorUtils.isError(interceptorResult) && !allowInterceptorError) {
282
279
  this.sendResponse(req.get("Referer") ?? "", res, interceptorResult, tme, ep, httpRequest);
283
280
  return;
284
281
  }
285
- httpRequestBound.interceptorResult = interceptorResult;
286
- httpRequest = httpRequestBound;
282
+ httpRequest.interceptorResult = interceptorResult;
287
283
  }
288
284
  }
289
285
  const precheck = await i.__precheck(httpRequest);
@@ -412,6 +408,10 @@ class APIService extends BaseService_1.BaseService {
412
408
  httpStatus: 500
413
409
  }, requestTime, data.endpoint, req);
414
410
  }
411
+ else {
412
+ if (req)
413
+ this.addNetlog(data, req, requestTime, 0);
414
+ }
415
415
  });
416
416
  return;
417
417
  }
@@ -444,6 +444,8 @@ class APIService extends BaseService_1.BaseService {
444
444
  console.error(e);
445
445
  }
446
446
  }
447
+ if (req)
448
+ this.addNetlog(data, req, requestTime, 0);
447
449
  }
448
450
  checkDataLength(data, result, lvl) {
449
451
  if (!lvl)
@@ -9,6 +9,7 @@ export interface IDBQueryField {
9
9
  ignoreInUpdate?: boolean;
10
10
  useInReplace?: boolean;
11
11
  __parsedValue?: string | number | boolean | null | undefined;
12
+ fields?: Record<string, number | boolean | string | null>;
12
13
  }
13
14
  export interface IDBQueryFields {
14
15
  [key: string]: string | number | boolean | IDBQueryField | null;
@@ -606,6 +606,14 @@ class MysqlAdapter {
606
606
  }
607
607
  if (typeof value === "boolean")
608
608
  value = value ? 1 : 0;
609
+ if (field.fields && typeof field.fields === "object" && value && typeof value === "string" && value.indexOf("@") !== -1) {
610
+ for (let key in field.fields) {
611
+ if (!field.fields[key])
612
+ continue;
613
+ const val = promise_1.default.escape(field.fields[key]);
614
+ value = this.safeReplace(value, key, val);
615
+ }
616
+ }
609
617
  field.__parsedValue = value;
610
618
  if (field.__parsedValue === null || field.__parsedValue === undefined) {
611
619
  field.__parsedValue = "NULL";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "3.8.4",
3
+ "version": "3.8.6",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",