badmfck-api-server 4.0.61 → 4.0.63

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.
@@ -65,6 +65,7 @@ export declare class APIService<TInterceptorResult = any, TInternalCallParams =
65
65
  private monitor;
66
66
  private started;
67
67
  private requestsCount;
68
+ private noCors;
68
69
  netLog: APIServiceNetworkLogItem[];
69
70
  constructor(options: APIServiceOptions);
70
71
  init(): Promise<void>;
@@ -95,11 +95,12 @@ async function Initializer(services) {
95
95
  }
96
96
  exports.Initializer = Initializer;
97
97
  class APIService extends BaseService_1.BaseService {
98
- version = "4.0.6";
98
+ version = "4.0.63";
99
99
  options;
100
100
  monitor = null;
101
101
  started = new Date();
102
102
  requestsCount = 0;
103
+ noCors = false;
103
104
  netLog = [];
104
105
  constructor(options) {
105
106
  super('HTTP Service');
@@ -109,6 +110,10 @@ class APIService extends BaseService_1.BaseService {
109
110
  const self = "http://localhost:" + this.options.port;
110
111
  if (!this.options.corsHostWhiteList.find(val => val === self))
111
112
  this.options.corsHostWhiteList.push(self);
113
+ if (this.options.corsHostWhiteList.length === 0)
114
+ this.noCors = true;
115
+ if (this.options.corsHostWhiteList.find(x => x === "*"))
116
+ this.noCors = true;
112
117
  const list = [];
113
118
  for (let h of this.options.corsHostWhiteList) {
114
119
  h = h.replace(/\/$/, "");
@@ -234,7 +239,7 @@ class APIService extends BaseService_1.BaseService {
234
239
  const originHeader = req.headers.origin;
235
240
  if (!originHeader)
236
241
  return next();
237
- if (this.options.corsHostWhiteList && this.options.corsHostWhiteList.find(x => x === "*"))
242
+ if (this.noCors)
238
243
  return next();
239
244
  let originNorm;
240
245
  try {
@@ -245,6 +250,7 @@ class APIService extends BaseService_1.BaseService {
245
250
  error: { ...DefaultErrors_1.default.FORBIDDEN, details: "Invalid Origin header" },
246
251
  data: null,
247
252
  httpStatus: 403,
253
+ version: this.options.appVersion
248
254
  });
249
255
  return;
250
256
  }
@@ -253,6 +259,7 @@ class APIService extends BaseService_1.BaseService {
253
259
  error: { ...DefaultErrors_1.default.FORBIDDEN, details: `Origin not allowed: ${originNorm}` },
254
260
  data: null,
255
261
  httpStatus: 403,
262
+ version: this.options.appVersion
256
263
  });
257
264
  return;
258
265
  }
@@ -48,6 +48,7 @@ export interface IDBError {
48
48
  export interface IDBResult {
49
49
  data?: any | null;
50
50
  error?: IDBError | null;
51
+ total?: number;
51
52
  execution: {
52
53
  started_at: number;
53
54
  finished_at: number;
@@ -445,8 +445,21 @@ class MysqlAdapter {
445
445
  let result = null;
446
446
  if (this.options.maxQueryTimeout && this.options.maxQueryTimeout > 0)
447
447
  result = await this.withTimeout(conn.query(query), this.options.maxQueryTimeout, query);
448
- else
448
+ else {
449
449
  result = await conn.query(query);
450
+ }
451
+ let total = null;
452
+ ;
453
+ if (request.calculateCount) {
454
+ const cres = await conn.query("SELECT FOUND_ROWS() as total");
455
+ if (cres && cres[0]) {
456
+ const res = cres[0];
457
+ if (Array.isArray(res) && res.length > 0 && "total" in res[0])
458
+ total = res[0].total;
459
+ else if ("total" in res)
460
+ total = res.total;
461
+ }
462
+ }
450
463
  this.lastSuccessQueryTime = +new Date();
451
464
  if (!request.transactionID && doCloseConnection)
452
465
  this.finalizeConnection(conn);
@@ -455,6 +468,7 @@ class MysqlAdapter {
455
468
  return {
456
469
  data: result[0],
457
470
  error: null,
471
+ total: total ? total : undefined,
458
472
  execution: {
459
473
  started_at: executionStartTime,
460
474
  finished_at: Date.now()
@@ -38,6 +38,7 @@ class MicroserviceClient extends BaseService_1.BaseService {
38
38
  const nonce = crypto_1.default.randomBytes(16).toString("hex");
39
39
  const headers = {
40
40
  "Content-Type": "application/json",
41
+ "x-microservice-id": this.options.id,
41
42
  "x-microservice-ts": ts,
42
43
  "x-microservice-nonce": nonce
43
44
  };
@@ -45,7 +45,7 @@ class MicroserviceHostController extends BaseEndpoint_1.BaseEndpoint {
45
45
  throw DefaultErrors_1.default.METHOD_NOT_ALLOWED;
46
46
  const microserviceHost = MicroserviceHost_1.MicroserviceHost.getMicroservice(req.headers["x-microservice-id"]);
47
47
  if (!microserviceHost)
48
- throw { ...DefaultErrors_1.default.NOT_FOUND, message: "Microservice host not found" };
48
+ throw { ...DefaultErrors_1.default.NOT_FOUND, message: "Microservice host not found with id: " + req.headers["x-microservice-id"] };
49
49
  const result = await microserviceHost.handleIncomingRequest(req);
50
50
  if (DefaultErrors_1.ErrorUtils.isError(result))
51
51
  throw result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "4.0.61",
3
+ "version": "4.0.63",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",