badmfck-api-server 1.9.0 → 1.9.3

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.
@@ -26,6 +26,7 @@ export interface APIServiceOptions {
26
26
  isProductionEnvironment: boolean;
27
27
  interceptor?: IBaseEndpoint;
28
28
  postproducer?: (req: HTTPRequestVO | undefined | null, res: Response, data: TransferPacketVO<any>, requestTime: number, endpoint?: string, log?: APIServiceNetworkLogItem | null) => Promise<TransferPacketVO>;
29
+ preproducer?: (req: HTTPRequestVO | undefined | null) => any;
29
30
  monitor?: {
30
31
  login: string;
31
32
  password: string;
@@ -186,6 +186,17 @@ class APIService extends BaseService_1.BaseService {
186
186
  endpoint: ep,
187
187
  files: req.files ?? null
188
188
  };
189
+ if (this.options.preproducer) {
190
+ try {
191
+ const preproducerResult = await this.options.preproducer(httpRequest);
192
+ if (preproducerResult)
193
+ httpRequest.preproducerResult = preproducerResult;
194
+ }
195
+ catch (e) {
196
+ this.sendResponse(res, { error: { code: 10002, message: "Internal server error", details: `${e}` }, data: null, httpStatus: 500 }, tme, ep, log, httpRequest);
197
+ return;
198
+ }
199
+ }
189
200
  let result;
190
201
  try {
191
202
  if (!j.ignoreInterceptor) {
@@ -55,5 +55,5 @@ export declare class LogService extends BaseService {
55
55
  checkTextLimit(): void;
56
56
  createDate(d?: Date): string;
57
57
  leadZero(num: number): string;
58
- createText(data: any): string;
58
+ createText(data: any, level: LOG_LEVEL): string;
59
59
  }
@@ -120,7 +120,7 @@ class LogService extends BaseService_1.BaseService {
120
120
  return;
121
121
  const msg = log.data[0];
122
122
  const optional = log.data[1];
123
- let text = this.createText(msg);
123
+ let text = this.createText(msg, log.level);
124
124
  let source = "";
125
125
  if (text.startsWith("${") && text.endsWith("}") && text.indexOf(".js") !== -1) {
126
126
  source = text.substring(2, text.length - 1);
@@ -142,7 +142,7 @@ class LogService extends BaseService_1.BaseService {
142
142
  showlog = true;
143
143
  if (optional) {
144
144
  for (let i of optional)
145
- text += ", " + this.createText(i);
145
+ text += ", " + this.createText(i, this.level);
146
146
  }
147
147
  const d = new Date();
148
148
  const logitem = {
@@ -180,7 +180,7 @@ class LogService extends BaseService_1.BaseService {
180
180
  return "0" + num;
181
181
  return num + "";
182
182
  }
183
- createText(data) {
183
+ createText(data, level) {
184
184
  if (data === null)
185
185
  return "null";
186
186
  if (data === undefined)
@@ -210,7 +210,7 @@ class LogService extends BaseService_1.BaseService {
210
210
  else {
211
211
  res = data + "";
212
212
  }
213
- if (res.length > this.options.textLimit)
213
+ if (res.length > this.options.textLimit && level === LOG_LEVEL.INFO)
214
214
  res = res.substring(0, this.options.textLimit) + "... (total: " + res.length + ")";
215
215
  return res;
216
216
  }
@@ -25,6 +25,7 @@ export interface HTTPRequestVO<T = any> {
25
25
  };
26
26
  endpoint: string;
27
27
  interceptorResult?: TransferPacketVO<any>;
28
+ preproducerResult?: any;
28
29
  precheck?: TransferPacketVO<any> | null;
29
30
  files: FileArray | null | undefined;
30
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.9.0",
3
+ "version": "1.9.3",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",