@conduitplatform/grpc-sdk 0.14.6 → 0.15.0-rc.0

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.
Files changed (180) hide show
  1. package/dist/classes/ConduitActiveSchema.d.ts +12 -12
  2. package/dist/classes/ConduitActiveSchema.js +2 -2
  3. package/dist/classes/ConduitActiveSchema.js.map +1 -1
  4. package/dist/classes/ConduitModule.js.map +1 -1
  5. package/dist/classes/ConduitParser.d.ts +5 -2
  6. package/dist/classes/ConduitParser.js +8 -5
  7. package/dist/classes/ConduitParser.js.map +1 -1
  8. package/dist/classes/ConduitSchema.d.ts +3 -4
  9. package/dist/classes/ConduitSchema.js +2 -9
  10. package/dist/classes/ConduitSchema.js.map +1 -1
  11. package/dist/classes/ConduitServiceModule.js +29 -3
  12. package/dist/classes/ConduitServiceModule.js.map +1 -1
  13. package/dist/classes/GrpcServer.js +1 -3
  14. package/dist/classes/GrpcServer.js.map +1 -1
  15. package/dist/classes/HealthCheck.js +4 -1
  16. package/dist/classes/HealthCheck.js.map +1 -1
  17. package/dist/classes/ManagedModule.d.ts +12 -1
  18. package/dist/classes/ManagedModule.js +32 -14
  19. package/dist/classes/ManagedModule.js.map +1 -1
  20. package/dist/classes/ModuleManager.js +27 -21
  21. package/dist/classes/ModuleManager.js.map +1 -1
  22. package/dist/classes/index.d.ts +0 -7
  23. package/dist/classes/index.js +0 -7
  24. package/dist/classes/index.js.map +1 -1
  25. package/dist/helpers/index.d.ts +0 -2
  26. package/dist/helpers/index.js +0 -2
  27. package/dist/helpers/index.js.map +1 -1
  28. package/dist/helpers/wrapGrpcFunctions.js +32 -15
  29. package/dist/helpers/wrapGrpcFunctions.js.map +1 -1
  30. package/dist/index.d.ts +6 -2
  31. package/dist/index.js +27 -5
  32. package/dist/index.js.map +1 -1
  33. package/dist/interfaces/ConduitSchemaExtension.d.ts +5 -0
  34. package/dist/interfaces/ConduitSchemaExtension.js +3 -0
  35. package/dist/interfaces/ConduitSchemaExtension.js.map +1 -0
  36. package/dist/interfaces/Indexable.d.ts +1 -0
  37. package/dist/interfaces/Model.d.ts +1 -1
  38. package/dist/interfaces/index.d.ts +1 -3
  39. package/dist/interfaces/index.js +1 -3
  40. package/dist/interfaces/index.js.map +1 -1
  41. package/dist/metrics/MetricsServer.d.ts +9 -0
  42. package/dist/metrics/MetricsServer.js +94 -0
  43. package/dist/metrics/MetricsServer.js.map +1 -0
  44. package/dist/metrics/clientMiddleware.d.ts +2 -0
  45. package/dist/metrics/clientMiddleware.js +265 -0
  46. package/dist/metrics/clientMiddleware.js.map +1 -0
  47. package/dist/metrics/config/defaults.d.ts +61 -0
  48. package/dist/metrics/config/defaults.js +63 -0
  49. package/dist/metrics/config/defaults.js.map +1 -0
  50. package/dist/metrics/index.d.ts +26 -0
  51. package/dist/metrics/index.js +176 -0
  52. package/dist/metrics/index.js.map +1 -0
  53. package/dist/modules/admin/index.d.ts +3 -9
  54. package/dist/modules/admin/index.js +1 -92
  55. package/dist/modules/admin/index.js.map +1 -1
  56. package/dist/modules/authorization/index.d.ts +13 -0
  57. package/dist/modules/authorization/index.js +53 -0
  58. package/dist/modules/authorization/index.js.map +1 -0
  59. package/dist/modules/config/index.d.ts +1 -3
  60. package/dist/modules/config/index.js +2 -19
  61. package/dist/modules/config/index.js.map +1 -1
  62. package/dist/modules/database/index.d.ts +27 -18
  63. package/dist/modules/database/index.js +23 -25
  64. package/dist/modules/database/index.js.map +1 -1
  65. package/dist/modules/index.d.ts +2 -0
  66. package/dist/modules/index.js +2 -0
  67. package/dist/modules/index.js.map +1 -1
  68. package/dist/modules/router/index.d.ts +2 -2
  69. package/dist/modules/router/index.js.map +1 -1
  70. package/dist/protoUtils/authentication.d.ts +2 -2
  71. package/dist/protoUtils/authentication.js +47 -57
  72. package/dist/protoUtils/authentication.js.map +1 -1
  73. package/dist/protoUtils/authorization.d.ts +293 -0
  74. package/dist/protoUtils/authorization.js +727 -0
  75. package/dist/protoUtils/authorization.js.map +1 -0
  76. package/dist/protoUtils/chat.d.ts +1 -1
  77. package/dist/protoUtils/chat.js +44 -58
  78. package/dist/protoUtils/chat.js.map +1 -1
  79. package/dist/protoUtils/core.d.ts +2 -41
  80. package/dist/protoUtils/core.js +124 -169
  81. package/dist/protoUtils/core.js.map +1 -1
  82. package/dist/protoUtils/database.d.ts +29 -65
  83. package/dist/protoUtils/database.js +160 -351
  84. package/dist/protoUtils/database.js.map +1 -1
  85. package/dist/protoUtils/email.d.ts +1 -1
  86. package/dist/protoUtils/email.js +54 -81
  87. package/dist/protoUtils/email.js.map +1 -1
  88. package/dist/protoUtils/forms.d.ts +1 -1
  89. package/dist/protoUtils/forms.js +12 -16
  90. package/dist/protoUtils/forms.js.map +1 -1
  91. package/dist/protoUtils/grpc_health_check.d.ts +1 -1
  92. package/dist/protoUtils/grpc_health_check.js +21 -28
  93. package/dist/protoUtils/grpc_health_check.js.map +1 -1
  94. package/dist/protoUtils/push-notifications.d.ts +1 -1
  95. package/dist/protoUtils/push-notifications.js +46 -61
  96. package/dist/protoUtils/push-notifications.js.map +1 -1
  97. package/dist/protoUtils/router.d.ts +1 -1
  98. package/dist/protoUtils/router.js +56 -75
  99. package/dist/protoUtils/router.js.map +1 -1
  100. package/dist/protoUtils/sms.d.ts +1 -1
  101. package/dist/protoUtils/sms.js +44 -62
  102. package/dist/protoUtils/sms.js.map +1 -1
  103. package/dist/protoUtils/storage.d.ts +1 -1
  104. package/dist/protoUtils/storage.js +63 -71
  105. package/dist/protoUtils/storage.js.map +1 -1
  106. package/dist/{classes → routing}/ConduitRouteReturn.d.ts +1 -1
  107. package/dist/{classes → routing}/ConduitRouteReturn.js +9 -1
  108. package/dist/routing/ConduitRouteReturn.js.map +1 -0
  109. package/dist/{classes/Routing → routing}/RouteBuilder.d.ts +5 -8
  110. package/dist/{classes/Routing → routing}/RouteBuilder.js +1 -1
  111. package/dist/routing/RouteBuilder.js.map +1 -0
  112. package/dist/routing/RoutingJsonConstructor.d.ts +3 -0
  113. package/dist/routing/RoutingJsonConstructor.js +29 -0
  114. package/dist/routing/RoutingJsonConstructor.js.map +1 -0
  115. package/dist/{classes/Routing → routing}/RoutingManager.d.ts +11 -6
  116. package/dist/{classes/Routing → routing}/RoutingManager.js +43 -58
  117. package/dist/routing/RoutingManager.js.map +1 -0
  118. package/dist/routing/RoutingUtilities.d.ts +15 -0
  119. package/dist/{helpers → routing}/RoutingUtilities.js +14 -10
  120. package/dist/routing/RoutingUtilities.js.map +1 -0
  121. package/dist/routing/index.d.ts +7 -0
  122. package/dist/routing/index.js +24 -0
  123. package/dist/routing/index.js.map +1 -0
  124. package/dist/routing/interfaces/ConduitMiddleware.d.ts +11 -0
  125. package/dist/routing/interfaces/ConduitMiddleware.js +3 -0
  126. package/dist/routing/interfaces/ConduitMiddleware.js.map +1 -0
  127. package/dist/routing/interfaces/ConduitRoute.d.ts +8 -0
  128. package/dist/routing/interfaces/ConduitRoute.js +3 -0
  129. package/dist/routing/interfaces/ConduitRoute.js.map +1 -0
  130. package/dist/routing/interfaces/ConduitSocket.d.ts +5 -0
  131. package/dist/routing/interfaces/ConduitSocket.js +3 -0
  132. package/dist/routing/interfaces/ConduitSocket.js.map +1 -0
  133. package/dist/{interfaces → routing/interfaces}/Route.d.ts +7 -4
  134. package/dist/{interfaces → routing/interfaces}/Route.js +0 -0
  135. package/dist/routing/interfaces/Route.js.map +1 -0
  136. package/dist/{interfaces → routing/interfaces}/Socket.d.ts +3 -3
  137. package/dist/{interfaces/Middleware.js → routing/interfaces/Socket.js} +1 -1
  138. package/dist/routing/interfaces/Socket.js.map +1 -0
  139. package/dist/routing/interfaces/index.d.ts +6 -0
  140. package/dist/routing/interfaces/index.js +23 -0
  141. package/dist/routing/interfaces/index.js.map +1 -0
  142. package/dist/routing/interfaces/types.d.ts +32 -0
  143. package/dist/routing/interfaces/types.js +3 -0
  144. package/dist/routing/interfaces/types.js.map +1 -0
  145. package/dist/{helpers → routing}/wrapRouterFunctions.d.ts +2 -3
  146. package/dist/{helpers → routing}/wrapRouterFunctions.js +22 -22
  147. package/dist/routing/wrapRouterFunctions.js.map +1 -0
  148. package/dist/types/db.d.ts +24 -0
  149. package/dist/types/db.js +3 -0
  150. package/dist/types/db.js.map +1 -0
  151. package/dist/types/index.d.ts +8 -29
  152. package/dist/types/index.js +8 -1
  153. package/dist/types/index.js.map +1 -1
  154. package/package.json +5 -1
  155. package/dist/classes/ConduitMiddleware.d.ts +0 -8
  156. package/dist/classes/ConduitMiddleware.js +0 -26
  157. package/dist/classes/ConduitMiddleware.js.map +0 -1
  158. package/dist/classes/ConduitRoute.d.ts +0 -12
  159. package/dist/classes/ConduitRoute.js +0 -44
  160. package/dist/classes/ConduitRoute.js.map +0 -1
  161. package/dist/classes/ConduitRouteReturn.js.map +0 -1
  162. package/dist/classes/ConduitSchemaExtension.d.ts +0 -7
  163. package/dist/classes/ConduitSchemaExtension.js +0 -19
  164. package/dist/classes/ConduitSchemaExtension.js.map +0 -1
  165. package/dist/classes/ConduitSocket.d.ts +0 -9
  166. package/dist/classes/ConduitSocket.js +0 -27
  167. package/dist/classes/ConduitSocket.js.map +0 -1
  168. package/dist/classes/Routing/RouteBuilder.js.map +0 -1
  169. package/dist/classes/Routing/RoutingManager.js.map +0 -1
  170. package/dist/helpers/RoutingJsonConstructor.d.ts +0 -9
  171. package/dist/helpers/RoutingJsonConstructor.js +0 -89
  172. package/dist/helpers/RoutingJsonConstructor.js.map +0 -1
  173. package/dist/helpers/RoutingUtilities.d.ts +0 -13
  174. package/dist/helpers/RoutingUtilities.js.map +0 -1
  175. package/dist/helpers/wrapRouterFunctions.js.map +0 -1
  176. package/dist/interfaces/Middleware.d.ts +0 -7
  177. package/dist/interfaces/Middleware.js.map +0 -1
  178. package/dist/interfaces/Route.js.map +0 -1
  179. package/dist/interfaces/Socket.js +0 -9
  180. package/dist/interfaces/Socket.js.map +0 -1
@@ -37,101 +37,67 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.RoutingManager = void 0;
40
- var interfaces_1 = require("../../interfaces");
41
- var RoutingUtilities_1 = require("../../helpers/RoutingUtilities");
40
+ var modules_1 = require("../modules");
42
41
  var RouteBuilder_1 = require("./RouteBuilder");
42
+ var RoutingUtilities_1 = require("./RoutingUtilities");
43
+ var Route_1 = require("./interfaces/Route");
43
44
  var RoutingManager = /** @class */ (function () {
44
45
  function RoutingManager(_router, _server) {
45
46
  this._router = _router;
46
47
  this._server = _server;
47
48
  this._moduleRoutes = {};
48
49
  this._routeHandlers = {};
50
+ this.isAdmin = false;
51
+ if (_router instanceof modules_1.Admin) {
52
+ this.isAdmin = true;
53
+ }
49
54
  }
50
55
  RoutingManager.prototype.get = function (path) {
51
- return new RouteBuilder_1.RouteBuilder(this).method(interfaces_1.ConduitRouteActions.GET).path(path);
56
+ return new RouteBuilder_1.RouteBuilder(this).method(Route_1.ConduitRouteActions.GET).path(path);
52
57
  };
53
58
  RoutingManager.prototype.post = function (path) {
54
- return new RouteBuilder_1.RouteBuilder(this).method(interfaces_1.ConduitRouteActions.POST).path(path);
59
+ return new RouteBuilder_1.RouteBuilder(this).method(Route_1.ConduitRouteActions.POST).path(path);
55
60
  };
56
61
  RoutingManager.prototype.delete = function (path) {
57
- return new RouteBuilder_1.RouteBuilder(this).method(interfaces_1.ConduitRouteActions.DELETE).path(path);
62
+ return new RouteBuilder_1.RouteBuilder(this).method(Route_1.ConduitRouteActions.DELETE).path(path);
58
63
  };
59
64
  RoutingManager.prototype.update = function (path) {
60
- return new RouteBuilder_1.RouteBuilder(this).method(interfaces_1.ConduitRouteActions.UPDATE).path(path);
65
+ return new RouteBuilder_1.RouteBuilder(this).method(Route_1.ConduitRouteActions.UPDATE).path(path);
61
66
  };
62
67
  RoutingManager.prototype.patch = function (path) {
63
- return new RouteBuilder_1.RouteBuilder(this).method(interfaces_1.ConduitRouteActions.PATCH).path(path);
68
+ return new RouteBuilder_1.RouteBuilder(this).method(Route_1.ConduitRouteActions.PATCH).path(path);
64
69
  };
65
70
  RoutingManager.prototype.clear = function () {
66
71
  this._moduleRoutes = {};
67
72
  this._routeHandlers = {};
68
73
  };
69
74
  RoutingManager.prototype.middleware = function (input, handler) {
70
- var routeObject = {
75
+ var routeObject = this.parseRouteObject({
71
76
  options: input,
72
77
  grpcFunction: input.name,
73
- };
74
- if (!routeObject.options.middlewares) {
75
- routeObject.options.middlewares = [];
76
- }
77
- for (var option in routeObject.options) {
78
- if (!routeObject.options.hasOwnProperty(option))
79
- continue;
80
- if (option === 'middlewares')
81
- continue;
82
- if (typeof routeObject.options[option] === 'string' ||
83
- routeObject.options[option] instanceof String)
84
- continue;
85
- routeObject.options[option] = JSON.stringify(routeObject.options[option]);
86
- }
78
+ });
87
79
  this._moduleRoutes[routeObject.grpcFunction] = routeObject;
88
80
  this._routeHandlers[routeObject.grpcFunction] = handler;
89
81
  };
90
82
  RoutingManager.prototype.route = function (input, type, handler) {
91
- var routeObject = {
83
+ var routeObject = this.parseRouteObject({
92
84
  options: input,
93
85
  returns: {
94
86
  name: type.name,
95
87
  fields: JSON.stringify(type.fields),
96
88
  },
97
89
  grpcFunction: this.generateGrpcName(input),
98
- };
99
- if (!routeObject.options.middlewares) {
100
- routeObject.options.middlewares = [];
101
- }
102
- for (var option in routeObject.options) {
103
- if (!routeObject.options.hasOwnProperty(option))
104
- continue;
105
- if (option === 'middlewares')
106
- continue;
107
- if (typeof routeObject.options[option] === 'string' ||
108
- routeObject.options[option] instanceof String)
109
- continue;
110
- routeObject.options[option] = JSON.stringify(routeObject.options[option]);
111
- }
90
+ });
112
91
  this._moduleRoutes[routeObject.grpcFunction] = routeObject;
113
92
  this._routeHandlers[routeObject.grpcFunction] = handler;
114
93
  };
115
94
  RoutingManager.prototype.socket = function (input, events) {
116
95
  var _this = this;
117
- var routeObject = {
96
+ var eventsObj = {};
97
+ var routeObject = this.parseRouteObject({
118
98
  options: input,
119
99
  events: '',
120
- };
121
- var eventsObj = {};
122
- if (!routeObject.options.middlewares) {
123
- routeObject.options.middlewares = [];
124
- }
125
- for (var option in routeObject.options) {
126
- if (!routeObject.options.hasOwnProperty(option))
127
- continue;
128
- if (option === 'middlewares')
129
- continue;
130
- if (typeof routeObject.options[option] === 'string' ||
131
- routeObject.options[option] instanceof String)
132
- continue;
133
- routeObject.options[option] = JSON.stringify(routeObject.options[option]);
134
- }
100
+ });
135
101
  var primary;
136
102
  Object.keys(events).forEach(function (eventName) {
137
103
  var _a, _b, _c;
@@ -153,18 +119,21 @@ var RoutingManager = /** @class */ (function () {
153
119
  };
154
120
  RoutingManager.prototype.registerRoutes = function () {
155
121
  return __awaiter(this, void 0, void 0, function () {
156
- var modifiedFunctions, protoDescriptions;
122
+ var modifiedFunctions, protoDescriptions, paths;
157
123
  return __generator(this, function (_a) {
158
124
  switch (_a.label) {
159
125
  case 0:
160
126
  if (Object.keys(this._routeHandlers).length === 0)
161
127
  return [2 /*return*/];
162
- modifiedFunctions = (0, RoutingUtilities_1.wrapFunctionsAsync)(this._routeHandlers);
163
- protoDescriptions = (0, RoutingUtilities_1.constructProtoFile)(this._router.moduleName, Object.values(this._moduleRoutes));
164
- return [4 /*yield*/, this._server.addService(protoDescriptions.path, protoDescriptions.name + '.router.Router', modifiedFunctions)];
128
+ modifiedFunctions = (0, RoutingUtilities_1.wrapFunctionsAsync)(this._routeHandlers, this.isAdmin ? 'admin' : 'client');
129
+ protoDescriptions = (0, RoutingUtilities_1.constructProtoFile)(this._router.moduleName, Object.values(this._moduleRoutes), this.isAdmin);
130
+ return [4 /*yield*/, this._server.addService(protoDescriptions.path, protoDescriptions.name + (this.isAdmin ? '.admin.Admin' : '.router.Router'), modifiedFunctions)];
165
131
  case 1:
166
132
  _a.sent();
167
- return [2 /*return*/, this._router.register(Object.values(this._moduleRoutes), protoDescriptions.file)];
133
+ paths = Object.values(this._moduleRoutes);
134
+ return [2 /*return*/, this._router.register(this.isAdmin
135
+ ? paths
136
+ : paths, protoDescriptions.file)];
168
137
  }
169
138
  });
170
139
  });
@@ -187,6 +156,22 @@ var RoutingManager = /** @class */ (function () {
187
156
  .map(function (word) { return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); })
188
157
  .join('');
189
158
  };
159
+ RoutingManager.prototype.parseRouteObject = function (routeObject) {
160
+ if (!routeObject.options.middlewares) {
161
+ routeObject.options.middlewares = [];
162
+ }
163
+ for (var option in routeObject.options) {
164
+ if (!routeObject.options.hasOwnProperty(option))
165
+ continue;
166
+ if (option === 'middlewares')
167
+ continue;
168
+ if (typeof routeObject.options[option] === 'string' ||
169
+ routeObject.options[option] instanceof String)
170
+ continue;
171
+ routeObject.options[option] = JSON.stringify(routeObject.options[option]);
172
+ }
173
+ return routeObject;
174
+ };
190
175
  return RoutingManager;
191
176
  }());
192
177
  exports.RoutingManager = RoutingManager;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RoutingManager.js","sourceRoot":"","sources":["../../src/routing/RoutingManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,sCAA2C;AAC3C,+CAA8C;AAG9C,uDAA4E;AAE5E,4CAI4B;AAU5B;IASE,wBACmB,OAAuB,EACvB,OAAmB;QADnB,YAAO,GAAP,OAAO,CAAgB;QACvB,YAAO,GAAP,OAAO,CAAY;QAV9B,kBAAa,GAEjB,EAAE,CAAC;QACC,mBAAc,GAElB,EAAE,CAAC;QACU,YAAO,GAAY,KAAK,CAAC;QAMxC,IAAI,OAAO,YAAY,eAAK,EAAE;YAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;SACrB;IACH,CAAC;IAED,4BAAG,GAAH,UAAI,IAAY;QACd,OAAO,IAAI,2BAAY,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,2BAAmB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED,6BAAI,GAAJ,UAAK,IAAY;QACf,OAAO,IAAI,2BAAY,CAAC,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AAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;SAC3E;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IACH,qBAAC;AAAD,CAAC,AA/JD,IA+JC;AA/JY,wCAAc"}
@@ -0,0 +1,15 @@
1
+ import { RequestHandlers } from './wrapRouterFunctions';
2
+ import { ConduitRouteObject } from './interfaces/Route';
3
+ import { SocketProtoDescription } from './interfaces/Socket';
4
+ import { Indexable } from '../interfaces';
5
+ export declare function constructProtoFile(moduleName: string, paths: (ConduitRouteObject | SocketProtoDescription)[], isAdmin?: boolean): {
6
+ path: string;
7
+ name: string;
8
+ file: string;
9
+ };
10
+ export declare function wrapFunctionsAsync(functions: {
11
+ [name: string]: RequestHandlers;
12
+ }, routerType: 'admin' | 'client'): {
13
+ [name: string]: (call: Indexable, callback?: Indexable) => void;
14
+ };
15
+ export declare function createProtoFunctions(paths: (ConduitRouteObject | SocketProtoDescription)[], isAdmin: boolean): string;
@@ -7,11 +7,13 @@ exports.createProtoFunctions = exports.wrapFunctionsAsync = exports.constructPro
7
7
  var wrapRouterFunctions_1 = require("./wrapRouterFunctions");
8
8
  var path_1 = __importDefault(require("path"));
9
9
  var fs_1 = __importDefault(require("fs"));
10
- var protofile_template = "\nsyntax = \"proto3\";\npackage MODULE_NAME.router;\n\nservice Router {\n MODULE_FUNCTIONS\n}\n\nmessage RouterRequest {\n string params = 1;\n string path = 2;\n string headers = 3;\n string context = 4;\n}\n\nmessage RouterResponse {\n string result = 1;\n string redirect = 2;\n repeated Cookie setCookies = 3;\n repeated Cookie removeCookies = 4;\n}\n\nmessage SocketRequest {\n string event = 1;\n string socketId = 2;\n string params = 3;\n string context = 4;\n}\n\nmessage Cookie {\n string name = 1;\n optional string value = 2;\n Options options = 3;\n}\n\nmessage Options {\n bool httpOnly = 1;\n bool secure = 2;\n bool signed = 3;\n int32 maxAge = 4;\n string path = 5;\n string domain = 6;\n string sameSite = 7;\n \n}\nmessage SocketResponse {\n string event = 1;\n string data = 2;\n repeated string receivers = 3;\n repeated string rooms = 4;\n}\n";
11
- function constructProtoFile(moduleName, paths) {
10
+ var protofile_template = "\nsyntax = \"proto3\";\npackage MODULE_NAME.router;\n\nservice Router {\n MODULE_FUNCTIONS\n}\n\nmessage RouterRequest {\n string params = 1;\n string path = 2;\n string headers = 3;\n string context = 4;\n string cookies = 5;\n}\n\nmessage RouterResponse {\n string result = 1;\n string redirect = 2;\n repeated Cookie setCookies = 3;\n repeated Cookie removeCookies = 4;\n}\n\nmessage SocketRequest {\n string event = 1;\n string socketId = 2;\n string params = 3;\n string context = 4;\n}\n\nmessage Cookie {\n string name = 1;\n optional string value = 2;\n Options options = 3;\n}\n\nmessage Options {\n bool httpOnly = 1;\n bool secure = 2;\n bool signed = 3;\n int32 maxAge = 4;\n string path = 5;\n string domain = 6;\n string sameSite = 7;\n \n}\nmessage SocketResponse {\n string event = 1;\n string data = 2;\n repeated string receivers = 3;\n repeated string rooms = 4;\n}\n";
11
+ var admin_protofile_template = "\nsyntax = \"proto3\";\npackage MODULE_NAME.admin;\n\nservice Admin {\n MODULE_FUNCTIONS\n}\n\nmessage AdminRequest {\n string params = 1;\n string path = 2;\n string headers = 3;\n string context = 4;\n string cookies = 5;\n}\n\nmessage AdminResponse {\n string result = 1;\n string redirect = 2;\n repeated Cookie setCookies = 3;\n repeated Cookie removeCookies = 4;\n}\n\nmessage SocketRequest {\n string event = 1;\n string socketId = 2;\n string params = 3;\n string context = 4;\n}\n\nmessage Cookie {\n string name = 1;\n optional string value = 2;\n Options options = 3;\n}\n\nmessage Options {\n bool httpOnly = 1;\n bool secure = 2;\n bool signed = 3;\n int32 maxAge = 4;\n string path = 5;\n string domain = 6;\n string sameSite = 7;\n \n}\nmessage SocketResponse {\n string event = 1;\n string data = 2;\n repeated string receivers = 3;\n repeated string rooms = 4;\n}\n";
12
+ function constructProtoFile(moduleName, paths, isAdmin) {
13
+ if (isAdmin === void 0) { isAdmin = false; }
12
14
  var formattedModuleName = getFormattedModuleName(moduleName);
13
- var protoFunctions = createProtoFunctions(paths);
14
- var protoFile = protofile_template
15
+ var protoFunctions = createProtoFunctions(paths, isAdmin);
16
+ var protoFile = (isAdmin ? admin_protofile_template : protofile_template)
15
17
  .toString()
16
18
  .replace('MODULE_FUNCTIONS', protoFunctions);
17
19
  protoFile = protoFile.replace('MODULE_NAME', formattedModuleName);
@@ -23,22 +25,22 @@ exports.constructProtoFile = constructProtoFile;
23
25
  function getFormattedModuleName(moduleName) {
24
26
  return moduleName.replace('-', '_');
25
27
  }
26
- function wrapFunctionsAsync(functions) {
28
+ function wrapFunctionsAsync(functions, routerType) {
27
29
  var modifiedFunctions = {};
28
30
  Object.keys(functions).forEach(function (key) {
29
- modifiedFunctions[key] = (0, wrapRouterFunctions_1.wrapRouterGrpcFunction)(functions[key]);
31
+ modifiedFunctions[key] = (0, wrapRouterFunctions_1.wrapRouterGrpcFunction)(functions[key], routerType);
30
32
  });
31
33
  return modifiedFunctions;
32
34
  }
33
35
  exports.wrapFunctionsAsync = wrapFunctionsAsync;
34
- function createProtoFunctions(paths) {
36
+ function createProtoFunctions(paths, isAdmin) {
35
37
  var protoFunctions = '';
36
38
  paths.forEach(function (r) {
37
39
  if (r.hasOwnProperty('events')) {
38
40
  protoFunctions += createProtoFunctionsForSocket(r, protoFunctions);
39
41
  }
40
42
  else {
41
- protoFunctions += createProtoFunctionForRoute(r, protoFunctions);
43
+ protoFunctions += createProtoFunctionForRoute(r, protoFunctions, isAdmin);
42
44
  }
43
45
  });
44
46
  return protoFunctions;
@@ -56,12 +58,14 @@ function createProtoFunctionsForSocket(path, protoFunctions) {
56
58
  });
57
59
  return newFunctions;
58
60
  }
59
- function createProtoFunctionForRoute(path, protoFunctions) {
61
+ function createProtoFunctionForRoute(path, protoFunctions, isAdmin) {
60
62
  var newFunction = createGrpcFunctionName(path.grpcFunction);
61
63
  if (protoFunctions.indexOf("rpc ".concat(newFunction, "(")) !== -1) {
62
64
  return '';
63
65
  }
64
- return "rpc ".concat(newFunction, "(RouterRequest) returns (RouterResponse);\n");
66
+ return isAdmin
67
+ ? "rpc ".concat(newFunction, "(AdminRequest) returns (AdminResponse);\n")
68
+ : "rpc ".concat(newFunction, "(RouterRequest) returns (RouterResponse);\n");
65
69
  }
66
70
  function createGrpcFunctionName(grpcFunction) {
67
71
  return grpcFunction.charAt(0).toUpperCase() + grpcFunction.slice(1);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RoutingUtilities.js","sourceRoot":"","sources":["../../src/routing/RoutingUtilities.ts"],"names":[],"mappings":";;;;;;AAAA,6DAAgF;AAChF,8CAAwB;AACxB,0CAAoB;AAKpB,IAAM,kBAAkB,GAAG,o5BAoD1B,CAAC;AAEF,IAAM,wBAAwB,GAAG,g5BAoDhC,CAAC;AAEF,SAAgB,kBAAkB,CAChC,UAAkB,EAClB,KAAsD,EACtD,OAAwB;IAAxB,wBAAA,EAAA,eAAwB;IAExB,IAAM,mBAAmB,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAC;IAC/D,IAAM,cAAc,GAAG,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5D,IAAI,SAAS,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,kBAAkB,CAAC;SACtE,QAAQ,EAAE;SACV,OAAO,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC;IAC/C,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC;IAElE,IAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACnF,YAAE,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAA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E,IAAI,cAAc,CAAC,OAAO,CAAC,cAAO,WAAW,MAAG,CAAC,KAAK,CAAC,CAAC,EAAE;YACxD,OAAO;SACR;QAED,YAAY,IAAI,cAAO,WAAW,gDAA6C,CAAC;IAClF,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,2BAA2B,CAClC,IAAwB,EACxB,cAAsB,EACtB,OAAgB;IAEhB,IAAM,WAAW,GAAG,sBAAsB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAE9D,IAAI,cAAc,CAAC,OAAO,CAAC,cAAO,WAAW,MAAG,CAAC,KAAK,CAAC,CAAC,EAAE;QACxD,OAAO,EAAE,CAAC;KACX;IACD,OAAO,OAAO;QACZ,CAAC,CAAC,cAAO,WAAW,8CAA2C;QAC/D,CAAC,CAAC,cAAO,WAAW,gDAA6C,CAAC;AACtE,CAAC;AAED,SAAS,sBAAsB,CAAC,YAAoB;IAClD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from './interfaces';
2
+ export * from './ConduitRouteReturn';
3
+ export * from './RouteBuilder';
4
+ export * from './RoutingJsonConstructor';
5
+ export * from './RoutingManager';
6
+ export * from './RoutingUtilities';
7
+ export * from './wrapRouterFunctions';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./interfaces"), exports);
18
+ __exportStar(require("./ConduitRouteReturn"), exports);
19
+ __exportStar(require("./RouteBuilder"), exports);
20
+ __exportStar(require("./RoutingJsonConstructor"), exports);
21
+ __exportStar(require("./RoutingManager"), exports);
22
+ __exportStar(require("./RoutingUtilities"), exports);
23
+ __exportStar(require("./wrapRouterFunctions"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,uDAAqC;AACrC,iDAA+B;AAC/B,2DAAyC;AACzC,mDAAiC;AACjC,qDAAmC;AACnC,wDAAsC"}
@@ -0,0 +1,11 @@
1
+ import { ConduitRouteActions } from './Route';
2
+ export interface ConduitMiddlewareOptions {
3
+ action?: ConduitRouteActions;
4
+ path?: string;
5
+ name: string;
6
+ description?: string;
7
+ }
8
+ export interface ConduitMiddleware {
9
+ _input: ConduitMiddlewareOptions;
10
+ _handler: string;
11
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ConduitMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConduitMiddleware.js","sourceRoot":"","sources":["../../../src/routing/interfaces/ConduitMiddleware.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { ConduitRouteReturnDefinition } from '../ConduitRouteReturn';
2
+ import { ConduitRouteOptions } from './Route';
3
+ import { RequestHandlers } from '../wrapRouterFunctions';
4
+ export interface ConduitRoute {
5
+ returnType: ConduitRouteReturnDefinition;
6
+ input: ConduitRouteOptions;
7
+ handler: RequestHandlers;
8
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ConduitRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConduitRoute.js","sourceRoot":"","sources":["../../../src/routing/interfaces/ConduitRoute.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { ConduitSocketEvent, ConduitSocketOptions } from './Socket';
2
+ export interface ConduitSocket {
3
+ readonly _input: ConduitSocketOptions;
4
+ events: Record<string, ConduitSocketEvent>;
5
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ConduitSocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConduitSocket.js","sourceRoot":"","sources":["../../../src/routing/interfaces/ConduitSocket.ts"],"names":[],"mappings":""}
@@ -1,15 +1,18 @@
1
- /// <reference types="node" />
2
- import { ConduitModel } from './Model';
3
- import { IncomingHttpHeaders } from 'http';
1
+ import { ConduitModel } from '../../interfaces';
4
2
  export interface ConduitRouteParameters {
5
3
  params?: {
6
4
  [field: string]: any;
7
5
  };
8
6
  path?: string;
9
- headers: IncomingHttpHeaders;
7
+ headers: {
8
+ [field: string]: any;
9
+ };
10
10
  context?: {
11
11
  [field: string]: any;
12
12
  };
13
+ cookies?: {
14
+ [field: string]: any;
15
+ };
13
16
  }
14
17
  export declare enum RouteOptionType {
15
18
  String = "String",
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Route.js","sourceRoot":"","sources":["../../../src/routing/interfaces/Route.ts"],"names":[],"mappings":";;;AAUA,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;IACnB,gCAAa,CAAA;IACb,wCAAqB,CAAA;IACrB,gCAAa,CAAA;AACf,CAAC,EAPW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAO1B;AAgBD,IAAY,mBAMX;AAND,WAAY,mBAAmB;IAC7B,kCAAW,CAAA;IACX,oCAAa,CAAA;IACb,qCAAc,CAAA;IACd,sCAAe,CAAA;IACf,wCAAiB,CAAA;AACnB,CAAC,EANW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAM9B"}
@@ -1,6 +1,6 @@
1
- import { TYPE } from './Model';
2
- import { ConduitRouteReturnDefinition } from '../classes';
3
- import { RequestHandlers } from '../helpers';
1
+ import { ConduitRouteReturnDefinition } from '../ConduitRouteReturn';
2
+ import { RequestHandlers } from '../wrapRouterFunctions';
3
+ import { TYPE } from '../../interfaces';
4
4
  export declare type ConduitSocketParamTypes = (TYPE | ConduitSocketParamTypes)[];
5
5
  export interface ConduitSocketOptions {
6
6
  path: string;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=Middleware.js.map
3
+ //# sourceMappingURL=Socket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Socket.js","sourceRoot":"","sources":["../../../src/routing/interfaces/Socket.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export * from './ConduitMiddleware';
2
+ export * from './ConduitRoute';
3
+ export * from './ConduitSocket';
4
+ export * from './Route';
5
+ export * from './Socket';
6
+ export * from './types';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ConduitMiddleware"), exports);
18
+ __exportStar(require("./ConduitRoute"), exports);
19
+ __exportStar(require("./ConduitSocket"), exports);
20
+ __exportStar(require("./Route"), exports);
21
+ __exportStar(require("./Socket"), exports);
22
+ __exportStar(require("./types"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,iDAA+B;AAC/B,kDAAgC;AAChC,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB"}
@@ -0,0 +1,32 @@
1
+ import { Context, Cookies, Headers, Indexable, Params } from '../../interfaces';
2
+ import { GrpcRequest } from '../../types';
3
+ export declare type ParsedRouterRequest = GrpcRequest<{
4
+ params: Params;
5
+ path: string;
6
+ headers: Headers;
7
+ context: Context;
8
+ cookies: Cookies;
9
+ }>;
10
+ export declare type UnparsedRouterResponse = {
11
+ result?: Indexable;
12
+ redirect?: string;
13
+ setCookies: Indexable;
14
+ removeCookies: Indexable;
15
+ } | Indexable | string;
16
+ export declare type ParsedSocketRequest = GrpcRequest<{
17
+ event: string;
18
+ socketId: string;
19
+ params: string[];
20
+ context: Context;
21
+ cookies: Cookies;
22
+ }>;
23
+ declare type EventResponse = {
24
+ event: string;
25
+ data: Indexable;
26
+ receivers?: string[];
27
+ };
28
+ export declare type UnparsedSocketResponse = EventResponse | JoinRoomResponse;
29
+ declare type JoinRoomResponse = {
30
+ rooms: string[];
31
+ };
32
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/routing/interfaces/types.ts"],"names":[],"mappings":""}
@@ -1,7 +1,6 @@
1
- import { ParsedRouterRequest, ParsedSocketRequest, UnparsedRouterResponse, UnparsedSocketResponse } from '../types';
1
+ import { ParsedRouterRequest, ParsedSocketRequest, UnparsedRouterResponse, UnparsedSocketResponse } from './interfaces/types';
2
2
  import { Indexable } from '../interfaces';
3
3
  export declare type RouterRequestHandler = (call: ParsedRouterRequest) => Promise<UnparsedRouterResponse>;
4
4
  export declare type SocketRequestHandler = (call: ParsedSocketRequest) => Promise<UnparsedSocketResponse>;
5
5
  export declare type RequestHandlers = RouterRequestHandler | SocketRequestHandler;
6
- export declare function wrapCallObjectForRouter(call: Indexable): ParsedRouterRequest;
7
- export declare function wrapRouterGrpcFunction(fun: RequestHandlers): (call: Indexable, callback: any) => void;
6
+ export declare function wrapRouterGrpcFunction(fun: RequestHandlers, routerType: string): (call: Indexable, callback: any) => void;
@@ -14,30 +14,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.wrapRouterGrpcFunction = exports.wrapCallObjectForRouter = void 0;
17
+ exports.wrapRouterGrpcFunction = void 0;
18
18
  var grpc_js_1 = require("@grpc/grpc-js");
19
19
  var index_1 = __importDefault(require("../index"));
20
- function wrapCallObjectForRouter(call) {
21
- return {
22
- request: {
23
- params: call.request,
24
- path: '',
25
- headers: {},
26
- context: {},
27
- },
28
- };
29
- }
30
- exports.wrapCallObjectForRouter = wrapCallObjectForRouter;
31
20
  function generateLog(routerRequest, requestReceive, call, status) {
21
+ var _a, _b;
32
22
  var log = '';
23
+ var latency = Date.now() - requestReceive;
33
24
  if (routerRequest) {
34
25
  log += "Request: ".concat(call.request.path);
35
26
  }
36
27
  else {
37
28
  log += "Socket: ".concat(call.request.event, " socket: ").concat(call.request.socket);
38
29
  }
39
- log += " ".concat(status !== null && status !== void 0 ? status : '200', " ").concat(Date.now() - requestReceive);
30
+ log += " ".concat(status !== null && status !== void 0 ? status : '200', " ").concat(latency);
40
31
  index_1.default.Logger.log(log);
32
+ (_a = index_1.default.Metrics) === null || _a === void 0 ? void 0 : _a.set('grpc_request_latency_seconds', latency / 1000);
33
+ var successStatus = !status || status.toString().charAt(0) === '2';
34
+ (_b = index_1.default.Metrics) === null || _b === void 0 ? void 0 : _b.increment('grpc_response_statuses_total', 1, {
35
+ success: successStatus ? 'true' : 'false',
36
+ });
41
37
  }
42
38
  function parseRequestData(data) {
43
39
  if (typeof data === 'string' && data.length !== 0) {
@@ -47,25 +43,28 @@ function parseRequestData(data) {
47
43
  return {};
48
44
  }
49
45
  }
50
- function wrapRouterGrpcFunction(fun) {
46
+ function wrapRouterGrpcFunction(fun, routerType) {
51
47
  return function (call, callback) {
52
- var _a, _b;
48
+ var _a, _b, _c, _d;
53
49
  var requestReceive = Date.now();
54
50
  var routerRequest = true;
51
+ (_a = index_1.default.Metrics) === null || _a === void 0 ? void 0 : _a.increment("".concat(routerType, "_grpc_requests_total"));
55
52
  try {
56
53
  call.request.context = parseRequestData(call.request.context);
57
54
  call.request.params = parseRequestData(call.request.params);
55
+ call.request.cookies = parseRequestData(call.request.cookies);
58
56
  routerRequest = !call.request.hasOwnProperty('event');
59
57
  if (routerRequest) {
60
58
  call.request.headers = parseRequestData(call.request.headers);
61
59
  }
62
60
  }
63
61
  catch (e) {
62
+ (_b = index_1.default.Metrics) === null || _b === void 0 ? void 0 : _b.increment("".concat(routerType, "_grpc_errors_total"));
64
63
  generateLog(routerRequest, requestReceive, call, grpc_js_1.status.INTERNAL);
65
- index_1.default.Logger.error((_a = e.message) !== null && _a !== void 0 ? _a : 'Something went wrong');
64
+ index_1.default.Logger.error((_c = e.message) !== null && _c !== void 0 ? _c : 'Something went wrong');
66
65
  return callback({
67
66
  code: grpc_js_1.status.INTERNAL,
68
- message: (_b = e.message) !== null && _b !== void 0 ? _b : 'Something went wrong',
67
+ message: (_d = e.message) !== null && _d !== void 0 ? _d : 'Something went wrong',
69
68
  });
70
69
  }
71
70
  fun(call)
@@ -101,12 +100,13 @@ function wrapRouterGrpcFunction(fun) {
101
100
  generateLog(routerRequest, requestReceive, call, undefined);
102
101
  })
103
102
  .catch(function (error) {
104
- var _a, _b, _c, _d;
105
- generateLog(routerRequest, requestReceive, call, (_a = error.code) !== null && _a !== void 0 ? _a : grpc_js_1.status.INTERNAL);
106
- index_1.default.Logger.error((_b = error.message) !== null && _b !== void 0 ? _b : 'Something went wrong');
103
+ var _a, _b, _c, _d, _e;
104
+ (_a = index_1.default.Metrics) === null || _a === void 0 ? void 0 : _a.increment("".concat(routerType, "_grpc_errors_total"));
105
+ generateLog(routerRequest, requestReceive, call, (_b = error.code) !== null && _b !== void 0 ? _b : grpc_js_1.status.INTERNAL);
106
+ index_1.default.Logger.error((_c = error.message) !== null && _c !== void 0 ? _c : 'Something went wrong');
107
107
  callback({
108
- code: (_c = error.code) !== null && _c !== void 0 ? _c : grpc_js_1.status.INTERNAL,
109
- message: (_d = error.message) !== null && _d !== void 0 ? _d : 'Something went wrong',
108
+ code: (_d = error.code) !== null && _d !== void 0 ? _d : grpc_js_1.status.INTERNAL,
109
+ message: (_e = error.message) !== null && _e !== void 0 ? _e : 'Something went wrong',
110
110
  });
111
111
  });
112
112
  };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapRouterFunctions.js","sourceRoot":"","sources":["../../src/routing/wrapRouterFunctions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAOA,yCAAuC;AAGvC,mDAAsC;AAUtC,SAAS,WAAW,CAClB,aAAsB,EACtB,cAAsB,EACtB,IAAe,EACf,MAAe;;IAEf,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,CAAC;IAC5C,IAAI,aAAa,EAAE;QACjB,GAAG,IAAI,mBAAY,IAAI,CAAC,OAAO,CAAC,IAAI,CAAE,CAAC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