badmfck-api-server 1.8.9 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  import { Response } from 'express';
2
2
  import { BaseService, IBaseService } from './BaseService';
3
3
  import { IBaseEndpoint } from './BaseEndpoint';
4
- import { TransferPacketVO } from './structures/Interfaces';
4
+ import { HTTPRequestVO, TransferPacketVO } from './structures/Interfaces';
5
5
  import { Req } from "badmfck-signal";
6
6
  export interface APIServiceNetworkLogItem {
7
7
  id: number;
@@ -25,7 +25,7 @@ export interface APIServiceOptions {
25
25
  onError?: ((...rest: any[]) => void) | null;
26
26
  isProductionEnvironment: boolean;
27
27
  interceptor?: IBaseEndpoint;
28
- postproducer?: (packet: TransferPacketVO) => Promise<TransferPacketVO>;
28
+ postproducer?: (req: HTTPRequestVO | undefined | null, res: Response, data: TransferPacketVO<any>, requestTime: number, endpoint?: string, log?: APIServiceNetworkLogItem | null) => Promise<TransferPacketVO>;
29
29
  monitor?: {
30
30
  login: string;
31
31
  password: string;
@@ -50,5 +50,5 @@ export declare class APIService extends BaseService {
50
50
  netLog: APIServiceNetworkLogItem[];
51
51
  constructor(options?: APIServiceOptions | null);
52
52
  init(): Promise<void>;
53
- sendResponse(res: Response, data: TransferPacketVO<any>, requestTime: number, endpoint?: string, log?: APIServiceNetworkLogItem | null): Promise<void>;
53
+ sendResponse(res: Response, data: TransferPacketVO<any>, requestTime: number, endpoint?: string, log?: APIServiceNetworkLogItem | null, req?: HTTPRequestVO): Promise<void>;
54
54
  }
@@ -193,7 +193,7 @@ class APIService extends BaseService_1.BaseService {
193
193
  if (this.options.interceptor) {
194
194
  interceptorResult = await this.options.interceptor.execute(httpRequest);
195
195
  if (interceptorResult.error && !j.allowInterceptorError) {
196
- this.sendResponse(res, interceptorResult, tme, ep, log);
196
+ this.sendResponse(res, interceptorResult, tme, ep, log, httpRequest);
197
197
  return;
198
198
  }
199
199
  httpRequest.interceptorResult = interceptorResult;
@@ -203,7 +203,7 @@ class APIService extends BaseService_1.BaseService {
203
203
  httpRequest.precheck = { data: this.options.monitor };
204
204
  const precheck = await i.precheck(httpRequest);
205
205
  if (precheck && precheck.error) {
206
- this.sendResponse(res, precheck, tme, ep, log);
206
+ this.sendResponse(res, precheck, tme, ep, log, httpRequest);
207
207
  return;
208
208
  }
209
209
  httpRequest.precheck = precheck;
@@ -222,10 +222,10 @@ class APIService extends BaseService_1.BaseService {
222
222
  message: "Internal server error",
223
223
  details: `${e}`
224
224
  }
225
- }, tme, ep, log);
225
+ }, tme, ep, log, httpRequest);
226
226
  return;
227
227
  }
228
- this.sendResponse(res, result, tme, ep, log);
228
+ this.sendResponse(res, result, tme, ep, log, httpRequest);
229
229
  };
230
230
  execute();
231
231
  });
@@ -277,10 +277,10 @@ class APIService extends BaseService_1.BaseService {
277
277
  (0, LogService_1.logCrit)('${APIService.js}', 'API Service started at: ' + this.options.port + ", with base endpoint:" + this.options.baseEndPoint + ", ver.: " + this.version);
278
278
  });
279
279
  }
280
- async sendResponse(res, data, requestTime, endpoint, log) {
280
+ async sendResponse(res, data, requestTime, endpoint, log, req) {
281
281
  if (this.options.postproducer) {
282
282
  try {
283
- data = await this.options.postproducer({ ...data });
283
+ data = await this.options.postproducer(req, res, data, requestTime, endpoint, log);
284
284
  }
285
285
  catch (e) {
286
286
  (0, LogService_1.logError)("Postproducer error", e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.8.9",
3
+ "version": "1.9.0",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",