@resolveio/server-lib 4.0.21-newrole → 4.0.22

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.
@@ -0,0 +1,7 @@
1
+ import { Model, Document } from 'mongoose';
2
+ import { LogMethodLatencyModel } from '../models/log-method-latency.model';
3
+ interface ResolveIOModel extends LogMethodLatencyModel, Document {
4
+ }
5
+ export declare const LogMethodLatencies: Model<ResolveIOModel>;
6
+ export declare const LogMethodLatencyVersions: Model<ResolveIOModel>;
7
+ export {};
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var mongoose_1 = require("mongoose");
4
+ var index_1 = require("../index");
5
+ var schema = {
6
+ _id: {
7
+ type: String,
8
+ optional: true
9
+ },
10
+ __v: {
11
+ type: Number,
12
+ optional: true
13
+ },
14
+ updatedAt: {
15
+ type: Date,
16
+ optional: true
17
+ },
18
+ createdAt: {
19
+ type: Date,
20
+ optional: true
21
+ },
22
+ date_start: {
23
+ type: Date
24
+ },
25
+ date_end: {
26
+ type: Date,
27
+ optional: true
28
+ },
29
+ latency_ms: {
30
+ type: Number
31
+ },
32
+ method: {
33
+ type: String
34
+ }
35
+ };
36
+ var DefaultSchema = new mongoose_1.Schema(schema, {
37
+ skipVersioning: true,
38
+ versionKey: false,
39
+ timestamps: true
40
+ });
41
+ DefaultSchema.index({ createdAt: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 30 });
42
+ DefaultSchema.index({ latency_ms: 1 });
43
+ DefaultSchema.index({ method: 1 });
44
+ exports.LogMethodLatencies = index_1.ResolveIOServer.getMainDB().model('log-method-latencies', DefaultSchema);
45
+ schema._id = {
46
+ type: mongoose_1.Schema.Types.Mixed
47
+ };
48
+ var VersionSchema = new mongoose_1.Schema(schema, {
49
+ skipVersioning: true,
50
+ versionKey: false,
51
+ timestamps: true
52
+ });
53
+ exports.LogMethodLatencies['versionCollection'] = 'log-method-latencies.versions';
54
+ exports.LogMethodLatencyVersions = index_1.ResolveIOServer.getMainDB().model(exports.LogMethodLatencies['versionCollection'], VersionSchema);
@@ -55,6 +55,9 @@ var mongooseSchema = {
55
55
  },
56
56
  date: {
57
57
  type: Date
58
+ },
59
+ id_methodLatency: {
60
+ type: String
58
61
  }
59
62
  };
60
63
  var DefaultSchema = new mongoose_1.Schema(mongooseSchema, {
@@ -21,6 +21,13 @@ var schema = {
21
21
  type: Date,
22
22
  optional: true
23
23
  },
24
+ readonly: {
25
+ type: Boolean,
26
+ optional: true
27
+ },
28
+ active: {
29
+ type: Boolean
30
+ },
24
31
  attempts: {
25
32
  type: Number,
26
33
  optional: true
@@ -57,67 +64,53 @@ var schema = {
57
64
  type: String
58
65
  },
59
66
  roles: {
60
- type: Object
61
- },
62
- 'roles.super_admin': {
63
- type: Boolean
64
- },
65
- 'roles.approvals': {
66
67
  type: Array
67
68
  },
68
- 'roles.approvals.$': {
69
- type: Object
70
- },
71
- 'roles.approvals.$.name': {
69
+ 'roles.$': {
72
70
  type: String
73
71
  },
74
- 'roles.approvals.$.type': {
75
- type: String
72
+ phonenumber: {
73
+ type: String,
74
+ optional: true
76
75
  },
77
- 'roles.approvals.$.accounting_code': {
78
- type: String
76
+ other: {
77
+ type: Object,
78
+ blackbox: true,
79
+ optional: true
79
80
  },
80
- 'roles.groups': {
81
- type: Array
81
+ assets: {
82
+ type: Array,
83
+ optional: true
82
84
  },
83
- 'roles.groups.$': {
85
+ 'assets.$': {
84
86
  type: Object
85
87
  },
86
- 'roles.groups.$.name': {
88
+ 'assets.$.type': {
87
89
  type: String
88
90
  },
89
- 'roles.groups.$.views': {
90
- type: Array
91
- },
92
- 'roles.groups.$.views.$': {
91
+ 'assets.$.id_asset': {
93
92
  type: String
94
93
  },
95
- 'roles.groups.$.yard': {
96
- type: String,
97
- optional: true
94
+ 'assets.$.asset_number': {
95
+ type: String
98
96
  },
99
- 'roles.notifications': {
100
- type: Array
97
+ 'assets.$.ownership': {
98
+ type: String
101
99
  },
102
- 'roles.notifications.$': {
100
+ 'assets.$.ownership_driver': {
103
101
  type: String
104
102
  },
105
- 'roles.miscs': {
106
- type: Array
103
+ 'assets.$.date_start': {
104
+ type: Date
107
105
  },
108
- 'roles.miscs.$': {
109
- type: String
106
+ 'assets.$.date_end': {
107
+ type: Date,
108
+ optional: true
110
109
  },
111
- active: Boolean,
112
- phonenumber: {
110
+ id_function: {
113
111
  type: String,
114
112
  optional: true
115
113
  },
116
- other: {
117
- type: Object,
118
- optional: true,
119
- blackbox: true
120
- },
121
114
  customers: {
122
115
  type: Array,
123
116
  optional: true,
package/fixtures/init.js CHANGED
@@ -37,8 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  var app_version_collection_1 = require("../collections/app-version.collection");
39
39
  var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
40
- var mongoose_1 = require("mongoose");
41
40
  var active_subscription_collection_1 = require("../collections/active-subscription.collection");
41
+ var mongoose_1 = require("mongoose");
42
42
  function loadServerInit() {
43
43
  return __awaiter(this, void 0, void 0, function () {
44
44
  var appVersion;
package/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export declare class ResolveIOServer {
8
8
  private static _clientDir;
9
9
  private static _dontRunSupport;
10
10
  constructor(serverConfig: any, client: string, clientDir: any, _dontRunSupport?: any);
11
- static connectAndRun(): Promise<unknown>;
11
+ static connectAndRun(): Promise<{}>;
12
12
  static getClientName(): string;
13
13
  static getMainServer(): ResolveIOMainServer;
14
14
  static getMainDB(): any;
@@ -16,13 +16,13 @@ export declare class MethodManager {
16
16
  getMainServer(): ResolveIOMainServer;
17
17
  methods(method: MethodModel): void;
18
18
  callMethodCron(method: string, ...methodData: any[]): void;
19
- callMethodQueue(update: QueueMethodModel): Promise<unknown>;
20
- callMethod(ws: WebSocket, messageDate: Date, messageId: number, method: string, ...methodData: any[]): void;
19
+ callMethodQueue(update: QueueMethodModel): Promise<{}>;
20
+ callMethod(id_methodLatency: string, ws: WebSocket, messageDate: Date, messageId: number, method: string, ...methodData: any[]): void;
21
21
  callMethodInternal(method: any, ...methodData: any[]): Promise<any>;
22
22
  callSupportMethodInternal(supportMethod: any, ...methodData: any[]): Promise<any>;
23
23
  private sendWS;
24
24
  sendEmail(sendTo: string, subject: string, text?: string, html?: string, attachments?: any[], send_from?: string): void;
25
25
  getAWS(): aws.S3;
26
- readFile(fileName: any): Promise<unknown>;
27
- readImage(fileName: any): Promise<unknown>;
26
+ readFile(fileName: any): Promise<{}>;
27
+ readImage(fileName: any): Promise<{}>;
28
28
  }
@@ -1,4 +1,39 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
2
37
  Object.defineProperty(exports, "__esModule", { value: true });
3
38
  var collections_1 = require("../methods/collections");
4
39
  var logs_1 = require("../methods/logs");
@@ -20,6 +55,8 @@ var mongoose_1 = require("mongoose");
20
55
  var common_1 = require("../util/common");
21
56
  var log_collection_1 = require("../collections/log.collection");
22
57
  var support_manager_1 = require("./support.manager");
58
+ var log_method_latency_collection_1 = require("../collections/log-method-latency.collection");
59
+ var moment = require("moment");
23
60
  var MethodManager = /** @class */ (function () {
24
61
  function MethodManager(mainServer, serverConfig, clientDir) {
25
62
  var _this = this;
@@ -282,6 +319,7 @@ var MethodManager = /** @class */ (function () {
282
319
  data: 'Internal Error'
283
320
  };
284
321
  _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
322
+ log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: update.id_methodLatency });
285
323
  return resolve('No Method: ' + update.method);
286
324
  }
287
325
  if ((update.method_data.length > 1 || update.method_data[0]) && !that._methods[update.method].skipValidation) {
@@ -294,6 +332,7 @@ var MethodManager = /** @class */ (function () {
294
332
  data: 'Internal Error'
295
333
  };
296
334
  _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
335
+ log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: update.id_methodLatency });
297
336
  return resolve('No Check Function For Method ' + update.method);
298
337
  }
299
338
  else if (!that._methods[update.method].check._schema) {
@@ -305,6 +344,7 @@ var MethodManager = /** @class */ (function () {
305
344
  data: 'Internal Error'
306
345
  };
307
346
  _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
347
+ log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: update.id_methodLatency });
308
348
  return resolve('No Check Schema For Method ' + update.method);
309
349
  }
310
350
  else {
@@ -327,6 +367,7 @@ var MethodManager = /** @class */ (function () {
327
367
  data: 'Internal Error'
328
368
  };
329
369
  _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
370
+ log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: update.id_methodLatency });
330
371
  return resolve('Error in Method Check (' + update.method + ')');
331
372
  }
332
373
  }
@@ -338,16 +379,29 @@ var MethodManager = /** @class */ (function () {
338
379
  resolve('Timeout');
339
380
  }, 5000);
340
381
  // console.log('Run Method', update.method);
341
- (_a = that._methods[update.method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: update.id_user, user: update.user, id_ws: update.id_ws })].concat(update.method_data)).then(function (res) {
342
- var serverRes = {
343
- messageId: update.messageId,
344
- hasError: false,
345
- data: res
346
- };
347
- _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
348
- clearTimeout(timeout);
349
- resolve(serverRes);
350
- }, function (err) {
382
+ (_a = that._methods[update.method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: update.id_user, user: update.user, id_ws: update.id_ws })].concat(update.method_data)).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
383
+ var serverRes, latency;
384
+ return __generator(this, function (_a) {
385
+ switch (_a.label) {
386
+ case 0:
387
+ serverRes = {
388
+ messageId: update.messageId,
389
+ hasError: false,
390
+ data: res
391
+ };
392
+ this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
393
+ clearTimeout(timeout);
394
+ return [4 /*yield*/, log_method_latency_collection_1.LogMethodLatencies.findById(update.id_methodLatency)];
395
+ case 1:
396
+ latency = _a.sent();
397
+ if (latency) {
398
+ log_method_latency_collection_1.LogMethodLatencies.updateOne({ _id: update.id_methodLatency }, { $set: { date_end: new Date(), latency_ms: moment().diff(moment(latency.date_start), 'milliseconds', true) } });
399
+ }
400
+ resolve(serverRes);
401
+ return [2 /*return*/];
402
+ }
403
+ });
404
+ }); }, function (err) {
351
405
  var serverRes = {
352
406
  messageId: update.messageId,
353
407
  hasError: true,
@@ -355,17 +409,18 @@ var MethodManager = /** @class */ (function () {
355
409
  };
356
410
  _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
357
411
  clearTimeout(timeout);
412
+ log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: update.id_methodLatency });
358
413
  resolve(serverRes);
359
414
  });
360
415
  });
361
416
  };
362
417
  // Call/run method (Emit on Socket)
363
- MethodManager.prototype.callMethod = function (ws, messageDate, messageId, method) {
364
- var _a;
418
+ MethodManager.prototype.callMethod = function (id_methodLatency, ws, messageDate, messageId, method) {
365
419
  var _this = this;
420
+ var _a;
366
421
  var methodData = [];
367
- for (var _i = 4; _i < arguments.length; _i++) {
368
- methodData[_i - 4] = arguments[_i];
422
+ for (var _i = 5; _i < arguments.length; _i++) {
423
+ methodData[_i - 5] = arguments[_i];
369
424
  }
370
425
  var that = this;
371
426
  if (!that._methods[method]) {
@@ -377,6 +432,7 @@ var MethodManager = /** @class */ (function () {
377
432
  data: 'Internal Error'
378
433
  };
379
434
  this.sendWS(ws, messageDate, method, methodData, serverRes);
435
+ log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
380
436
  return;
381
437
  }
382
438
  if ((methodData.length > 1 || methodData[0]) && !that._methods[method].skipValidation) {
@@ -389,6 +445,7 @@ var MethodManager = /** @class */ (function () {
389
445
  data: 'Internal Error'
390
446
  };
391
447
  this.sendWS(ws, messageDate, method, methodData, serverRes);
448
+ log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
392
449
  return;
393
450
  }
394
451
  else if (!that._methods[method].check._schema) {
@@ -399,6 +456,7 @@ var MethodManager = /** @class */ (function () {
399
456
  hasError: true,
400
457
  data: 'Internal Error'
401
458
  };
459
+ log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
402
460
  this.sendWS(ws, messageDate, method, methodData, serverRes);
403
461
  return;
404
462
  }
@@ -422,25 +480,40 @@ var MethodManager = /** @class */ (function () {
422
480
  data: 'Internal Error'
423
481
  };
424
482
  this.sendWS(ws, messageDate, method, methodData, serverRes);
483
+ log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
425
484
  return;
426
485
  }
427
486
  }
428
487
  }
429
488
  }
430
- (_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
431
- var serverRes = {
432
- messageId: messageId,
433
- hasError: false,
434
- data: res
435
- };
436
- _this.sendWS(ws, messageDate, method, methodData, serverRes);
437
- }, function (err) {
489
+ (_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
490
+ var serverRes, latency;
491
+ return __generator(this, function (_a) {
492
+ switch (_a.label) {
493
+ case 0:
494
+ serverRes = {
495
+ messageId: messageId,
496
+ hasError: false,
497
+ data: res
498
+ };
499
+ this.sendWS(ws, messageDate, method, methodData, serverRes);
500
+ return [4 /*yield*/, log_method_latency_collection_1.LogMethodLatencies.findById(id_methodLatency)];
501
+ case 1:
502
+ latency = _a.sent();
503
+ if (latency) {
504
+ log_method_latency_collection_1.LogMethodLatencies.updateOne({ _id: id_methodLatency }, { $set: { date_end: new Date(), latency_ms: moment().diff(moment(latency.date_start), 'milliseconds', true) } });
505
+ }
506
+ return [2 /*return*/];
507
+ }
508
+ });
509
+ }); }, function (err) {
438
510
  var serverRes = {
439
511
  messageId: messageId,
440
512
  hasError: true,
441
513
  data: err
442
514
  };
443
515
  _this.sendWS(ws, messageDate, method, methodData, serverRes);
516
+ log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
444
517
  });
445
518
  };
446
519
  // Call/run method internal (No Emit on Socket)
@@ -6,7 +6,7 @@ export declare class QueueMethodManager {
6
6
  private _runningQueue;
7
7
  private _runningMethodResponse;
8
8
  constructor(mainServer: any);
9
- addMethodToQueue(id_ws: string, id_user: string, user: string, messageDate: Date, messageId: string, method: string, data: any[]): void;
9
+ addMethodToQueue(id_methodLatency: string, id_ws: string, id_user: string, user: string, messageDate: Date, messageId: string, method: string, data: any[]): void;
10
10
  runMethodQueue(count?: number): Promise<void>;
11
11
  addMethodResponse(update: QueueMethodModel, response: ServerResponseModel): void;
12
12
  runMethodResponse(): Promise<void>;
@@ -111,7 +111,7 @@ var QueueMethodManager = /** @class */ (function () {
111
111
  }
112
112
  }, 25);
113
113
  }
114
- QueueMethodManager.prototype.addMethodToQueue = function (id_ws, id_user, user, messageDate, messageId, method, data) {
114
+ QueueMethodManager.prototype.addMethodToQueue = function (id_methodLatency, id_ws, id_user, user, messageDate, messageId, method, data) {
115
115
  // console.log('Add Method To Queue', method);
116
116
  queue_method_collection_1.QueueMethods.create({
117
117
  _id: mongoose_1.Types.ObjectId().toHexString(),
@@ -122,7 +122,8 @@ var QueueMethodManager = /** @class */ (function () {
122
122
  method_data: data,
123
123
  id_user: id_user,
124
124
  user: user,
125
- date: messageDate
125
+ date: messageDate,
126
+ id_methodLatency: id_methodLatency
126
127
  });
127
128
  };
128
129
  QueueMethodManager.prototype.runMethodQueue = function (count) {
@@ -136,8 +136,7 @@ var SubscriptionManager = /** @class */ (function () {
136
136
  subscriptionData[_i - 3] = arguments[_i];
137
137
  }
138
138
  return __awaiter(this, void 0, void 0, function () {
139
- var that, pub, valObj, valKeys, rootKeys, i, sub, _a, newActiveSub, begDate, endDate, billUser;
140
- var _b;
139
+ var _a, that, pub, valObj, valKeys, rootKeys, i, sub, _b, newActiveSub, begDate, endDate, billUser;
141
140
  return __generator(this, function (_c) {
142
141
  switch (_c.label) {
143
142
  case 0:
@@ -202,10 +201,10 @@ var SubscriptionManager = /** @class */ (function () {
202
201
  // Send pub data to client who just subscribed only, don't want to send to existing clients since nothing has changed
203
202
  that.sendPubDataOnce(ws, messageId, sub, 'newSub', that.getPublicationCollections(publication)[0]);
204
203
  if (!(that._publications[sub.publication].preFunction && !sub.preSubscriptionData)) return [3 /*break*/, 3];
205
- _a = sub;
206
- return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
204
+ _b = sub;
205
+ return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
207
206
  case 2:
208
- _a.preSubscriptionData = _c.sent();
207
+ _b.preSubscriptionData = _c.sent();
209
208
  _c.label = 3;
210
209
  case 3:
211
210
  newActiveSub = new active_subscription_collection_1.ActiveSubscriptions({
@@ -557,8 +556,7 @@ var SubscriptionManager = /** @class */ (function () {
557
556
  if (noFetchFunction === void 0) { noFetchFunction = false; }
558
557
  var that = this;
559
558
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
560
- var schemaErrors, _a, _b;
561
- var _c, _d;
559
+ var _a, _b, schemaErrors, _c, _d;
562
560
  return __generator(this, function (_e) {
563
561
  switch (_e.label) {
564
562
  case 0:
@@ -578,18 +576,18 @@ var SubscriptionManager = /** @class */ (function () {
578
576
  if (!sub.preSubscriptionData) return [3 /*break*/, 4];
579
577
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
580
578
  that.sendPubData(sub, type, collection);
581
- _a = sub;
582
- return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
579
+ _c = sub;
580
+ return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
583
581
  case 3:
584
- _a.preSubscriptionData = _e.sent();
582
+ _c.preSubscriptionData = _e.sent();
585
583
  return [2 /*return*/];
586
584
  case 4:
587
585
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 7];
588
586
  if (!!noFetchFunction) return [3 /*break*/, 6];
589
- _b = sub;
587
+ _d = sub;
590
588
  return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
591
589
  case 5:
592
- _b.preSubscriptionData = _e.sent();
590
+ _d.preSubscriptionData = _e.sent();
593
591
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
594
592
  that.sendPubData(sub, type, collection);
595
593
  }
@@ -622,7 +620,7 @@ var SubscriptionManager = /** @class */ (function () {
622
620
  else {
623
621
  if (that._publications[sub.publication].fetchFunction) {
624
622
  if (!noFetchFunction) {
625
- if ((_d = that._publications[sub.publication]).fetchFunction.apply(_d, [document].concat(sub.subscriptionData))) {
623
+ if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
626
624
  that.sendPubData(sub, type, collection);
627
625
  }
628
626
  }
@@ -641,8 +639,7 @@ var SubscriptionManager = /** @class */ (function () {
641
639
  var _this = this;
642
640
  var that = this;
643
641
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
644
- var schemaErrors, _a, _b;
645
- var _c, _d, _e;
642
+ var _a, _b, _c, schemaErrors, _d, _e;
646
643
  return __generator(this, function (_f) {
647
644
  switch (_f.label) {
648
645
  case 0:
@@ -662,17 +659,17 @@ var SubscriptionManager = /** @class */ (function () {
662
659
  if (!sub.preSubscriptionData) return [3 /*break*/, 4];
663
660
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
664
661
  that.sendPubData(sub, 'support', collection);
665
- _a = sub;
666
- return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
662
+ _d = sub;
663
+ return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
667
664
  case 3:
668
- _a.preSubscriptionData = _f.sent();
665
+ _d.preSubscriptionData = _f.sent();
669
666
  return [2 /*return*/];
670
667
  case 4:
671
668
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 6];
672
- _b = sub;
673
- return [4 /*yield*/, (_d = that._publications[sub.publication]).preFunction.apply(_d, sub.subscriptionData)];
669
+ _e = sub;
670
+ return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
674
671
  case 5:
675
- _b.preSubscriptionData = _f.sent();
672
+ _e.preSubscriptionData = _f.sent();
676
673
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
677
674
  that.sendPubData(sub, 'support', collection);
678
675
  }
@@ -701,7 +698,7 @@ var SubscriptionManager = /** @class */ (function () {
701
698
  }
702
699
  else {
703
700
  if (that._publications[sub.publication].fetchFunction) {
704
- if ((_e = that._publications[sub.publication]).fetchFunction.apply(_e, [document].concat(sub.subscriptionData))) {
701
+ if ((_c = that._publications[sub.publication]).fetchFunction.apply(_c, [document].concat(sub.subscriptionData))) {
705
702
  that.sendPubData(sub, 'support', collection);
706
703
  }
707
704
  }
@@ -718,8 +715,7 @@ var SubscriptionManager = /** @class */ (function () {
718
715
  // Fetch pub once, send to all clients linked to this pub
719
716
  SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription, type, collection) {
720
717
  return __awaiter(this, void 0, void 0, function () {
721
- var that;
722
- var _a, _b;
718
+ var _a, _b, that;
723
719
  var _this = this;
724
720
  return __generator(this, function (_c) {
725
721
  that = this;
@@ -765,8 +761,7 @@ var SubscriptionManager = /** @class */ (function () {
765
761
  // Fetch pub once, send to all clients linked to this pub
766
762
  SubscriptionManager.prototype.sendPubData = function (subscription, type, collection) {
767
763
  return __awaiter(this, void 0, void 0, function () {
768
- var that;
769
- var _a;
764
+ var _a, that;
770
765
  var _this = this;
771
766
  return __generator(this, function (_b) {
772
767
  that = this;
@@ -17,6 +17,6 @@ export declare class SupportManager {
17
17
  callMethodInternal(method: any, ...methodData: any[]): Promise<any>;
18
18
  private sendWS;
19
19
  sendEmail(sendTo: string, subject: string, text?: string, html?: string, attachments?: any[], from?: string): void;
20
- readFile(fileName: any): Promise<unknown>;
21
- readImage(fileName: any): Promise<unknown>;
20
+ readFile(fileName: any): Promise<{}>;
21
+ readImage(fileName: any): Promise<{}>;
22
22
  }
@@ -102,8 +102,8 @@ var SupportManager = /** @class */ (function () {
102
102
  };
103
103
  // Call/run method (Emit on Socket)
104
104
  SupportManager.prototype.callSupportMethod = function (ws, messageId, supportMethod) {
105
- var _a;
106
105
  var _this = this;
106
+ var _a;
107
107
  var methodData = [];
108
108
  for (var _i = 3; _i < arguments.length; _i++) {
109
109
  methodData[_i - 3] = arguments[_i];
package/methods/logs.js CHANGED
@@ -4,6 +4,7 @@ var mongoose_1 = require("mongoose");
4
4
  var log_collection_1 = require("../collections/log.collection");
5
5
  var log_subscription_collection_1 = require("../collections/log-subscription.collection");
6
6
  var index_1 = require("../index");
7
+ var log_method_latency_collection_1 = require("../collections/log-method-latency.collection");
7
8
  function loadLogMethods(methodManager) {
8
9
  methodManager.methods({
9
10
  insertErrorLog: {
@@ -38,6 +39,20 @@ function loadLogMethods(methodManager) {
38
39
  });
39
40
  },
40
41
  skipValidation: true
42
+ },
43
+ insertMethodLatencyLog: {
44
+ skipQueue: true,
45
+ function: function (method) {
46
+ return log_method_latency_collection_1.LogMethodLatencies.create({
47
+ _id: mongoose_1.Types.ObjectId().toHexString(),
48
+ __v: 0,
49
+ date_start: new Date(),
50
+ date_end: null,
51
+ latency: 0,
52
+ method: method
53
+ });
54
+ },
55
+ skipValidation: true
41
56
  }
42
57
  });
43
58
  }
@@ -0,0 +1,7 @@
1
+ import { CollectionDocument } from './collection-document.model';
2
+ export interface LogMethodLatencyModel extends CollectionDocument {
3
+ date_start: Date;
4
+ date_end?: Date;
5
+ latency_ms: number;
6
+ method: string;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -7,4 +7,5 @@ export interface QueueMethodModel extends CollectionDocument {
7
7
  id_user: string;
8
8
  user: string;
9
9
  date: Date;
10
+ id_methodLatency: string;
10
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.0.21-newrole",
3
+ "version": "4.0.22",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {
package/server-app.js CHANGED
@@ -59,6 +59,7 @@ var subscription_manager_1 = require("./managers/subscription.manager");
59
59
  var support_manager_1 = require("./managers/support.manager");
60
60
  var queue_method_manager_1 = require("./managers/queue-method.manager");
61
61
  var common_2 = require("./util/common");
62
+ var log_method_latency_collection_1 = require("./collections/log-method-latency.collection");
62
63
  var ResolveIOMainServer = /** @class */ (function () {
63
64
  function ResolveIOMainServer(mainServer, serverConfig, clientDir) {
64
65
  this._msgQueue = [];
@@ -253,8 +254,7 @@ var ResolveIOMainServer = /** @class */ (function () {
253
254
  }, 10000);
254
255
  // On data received (message)
255
256
  ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
256
- var socketData, data, messageDate, messageId, type, subType, pub;
257
- var _a, _b;
257
+ var _a, _b, socketData, data, messageDate, messageId, type, subType, pub;
258
258
  var _this = this;
259
259
  return __generator(this, function (_c) {
260
260
  socketData = JSON.parse(message, common_1.dateReviver);
@@ -329,8 +329,7 @@ var ResolveIOMainServer = /** @class */ (function () {
329
329
  if (!!this._msgQueueRunning) return [3 /*break*/, 5];
330
330
  this._msgQueueRunning = true;
331
331
  _loop_1 = function (i) {
332
- var msg, data, ws, messageDate, messageId, type, method, serverRes, query, methodCall, supportMethod, serverRes;
333
- var _a, _b;
332
+ var _a, _b, msg, data, ws, messageDate, messageId, type, method, methodLatency, serverRes, query, methodCall, supportMethod, serverRes;
334
333
  return __generator(this, function (_c) {
335
334
  switch (_c.label) {
336
335
  case 0:
@@ -341,7 +340,7 @@ var ResolveIOMainServer = /** @class */ (function () {
341
340
  messageId = data.shift();
342
341
  type = data.shift();
343
342
  method = '';
344
- if (!(type === 'method')) return [3 /*break*/, 7];
343
+ if (!(type === 'method')) return [3 /*break*/, 8];
345
344
  method = data.shift();
346
345
  if (method === 'setWSAppVersion') {
347
346
  clearTimeout(ws['versionTimer']);
@@ -355,6 +354,16 @@ var ResolveIOMainServer = /** @class */ (function () {
355
354
  if (ws['user_readonly']) {
356
355
  return [2 /*return*/, "continue"];
357
356
  }
357
+ return [4 /*yield*/, log_method_latency_collection_1.LogMethodLatencies.create({
358
+ _id: mongoose_1.Types.ObjectId().toHexString(),
359
+ __v: 0,
360
+ date_start: new Date(),
361
+ date_end: null,
362
+ latency_ms: 0,
363
+ method: method
364
+ })];
365
+ case 1:
366
+ methodLatency = _c.sent();
358
367
  if (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion' && method !== 'getDrivers') {
359
368
  if (common_1.getBinarySize(JSON.stringify(data)) < 200000) {
360
369
  log_collection_1.Logs.create({
@@ -396,7 +405,7 @@ var ResolveIOMainServer = /** @class */ (function () {
396
405
  }
397
406
  });
398
407
  }
399
- if (!this_1._methodManager._methods[method]) return [3 /*break*/, 5];
408
+ if (!this_1._methodManager._methods[method]) return [3 /*break*/, 6];
400
409
  query = { $and: [
401
410
  { id_user: ws['id_user'] },
402
411
  { message_id: messageId },
@@ -424,9 +433,9 @@ var ResolveIOMainServer = /** @class */ (function () {
424
433
  }
425
434
  }
426
435
  return [4 /*yield*/, method_call_collection_1.MethodCalls.findOne(query).exec()];
427
- case 1:
436
+ case 2:
428
437
  methodCall = _c.sent();
429
- if (!!methodCall) return [3 /*break*/, 3];
438
+ if (!!methodCall) return [3 /*break*/, 4];
430
439
  return [4 /*yield*/, method_call_collection_1.MethodCalls.create({
431
440
  _id: mongoose_1.Types.ObjectId().toHexString(),
432
441
  __v: 0,
@@ -435,21 +444,21 @@ var ResolveIOMainServer = /** @class */ (function () {
435
444
  method: method,
436
445
  date: messageDate
437
446
  })];
438
- case 2:
447
+ case 3:
439
448
  _c.sent();
440
449
  if (this_1._methodManager._methods[method]) {
441
450
  if (this_1._methodManager._methods[method].skipQueue) {
442
- (_a = this_1._methodManager).callMethod.apply(_a, [ws, messageDate, messageId, method].concat(data));
451
+ (_a = this_1._methodManager).callMethod.apply(_a, [methodLatency._id, ws, messageDate, messageId, method].concat(data));
443
452
  }
444
453
  else {
445
- this_1._queueManager.addMethodToQueue(ws['id_socket'], ws['id_user'], ws['user'], messageDate, messageId, method, data);
454
+ this_1._queueManager.addMethodToQueue(methodLatency._id, ws['id_socket'], ws['id_user'], ws['user'], messageDate, messageId, method, data);
446
455
  }
447
456
  }
448
457
  else {
449
458
  console.log('Could not find method: ' + method);
450
459
  }
451
- return [3 /*break*/, 4];
452
- case 3:
460
+ return [3 /*break*/, 5];
461
+ case 4:
453
462
  method_response_collection_1.MethodResponses.findOne({ $and: [
454
463
  { id_user: ws['id_user'] },
455
464
  { message_id: messageId },
@@ -467,13 +476,13 @@ var ResolveIOMainServer = /** @class */ (function () {
467
476
  }
468
477
  }
469
478
  });
470
- _c.label = 4;
471
- case 4: return [3 /*break*/, 6];
472
- case 5:
479
+ _c.label = 5;
480
+ case 5: return [3 /*break*/, 7];
481
+ case 6:
473
482
  console.log('Could not find method: ' + method);
474
- _c.label = 6;
475
- case 6: return [3 /*break*/, 8];
476
- case 7:
483
+ _c.label = 7;
484
+ case 7: return [3 /*break*/, 9];
485
+ case 8:
477
486
  if (type === 'methodRetry') {
478
487
  method = data.shift();
479
488
  if (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion' && method !== 'getDrivers') {
@@ -610,8 +619,8 @@ var ResolveIOMainServer = /** @class */ (function () {
610
619
  console.log('Could not find support method: ' + supportMethod);
611
620
  }
612
621
  }
613
- _c.label = 8;
614
- case 8: return [2 /*return*/];
622
+ _c.label = 9;
623
+ case 9: return [2 /*return*/];
615
624
  }
616
625
  });
617
626
  };