@conduitplatform/grpc-sdk 0.15.17 → 0.15.19

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 (138) hide show
  1. package/dist/classes/ConduitActiveSchema.js +25 -43
  2. package/dist/classes/ConduitActiveSchema.js.map +1 -1
  3. package/dist/classes/ConduitAuthorizedResource.js +5 -6
  4. package/dist/classes/ConduitAuthorizedResource.js.map +1 -1
  5. package/dist/classes/ConduitModule.js +44 -138
  6. package/dist/classes/ConduitModule.js.map +1 -1
  7. package/dist/classes/ConduitSchema.js +3 -4
  8. package/dist/classes/ConduitSchema.js.map +1 -1
  9. package/dist/classes/ConduitServiceModule.js +39 -98
  10. package/dist/classes/ConduitServiceModule.js.map +1 -1
  11. package/dist/classes/ConfigController.js +10 -17
  12. package/dist/classes/ConfigController.js.map +1 -1
  13. package/dist/classes/Error.js +17 -40
  14. package/dist/classes/Error.js.map +1 -1
  15. package/dist/classes/GrpcServer.js +88 -172
  16. package/dist/classes/GrpcServer.js.map +1 -1
  17. package/dist/classes/HealthCheck.js +26 -72
  18. package/dist/classes/HealthCheck.js.map +1 -1
  19. package/dist/classes/ManagedModule.js +93 -245
  20. package/dist/classes/ManagedModule.js.map +1 -1
  21. package/dist/classes/ModuleManager.js +51 -149
  22. package/dist/classes/ModuleManager.js.map +1 -1
  23. package/dist/helpers/GrpcHelper.js +11 -11
  24. package/dist/helpers/GrpcHelper.js.map +1 -1
  25. package/dist/helpers/TypeHelpers.js +57 -119
  26. package/dist/helpers/TypeHelpers.js.map +1 -1
  27. package/dist/helpers/wrapGrpcFunctions.js +14 -15
  28. package/dist/helpers/wrapGrpcFunctions.js.map +1 -1
  29. package/dist/index.js +299 -467
  30. package/dist/index.js.map +1 -1
  31. package/dist/interceptors/grpcSignedToken.js +7 -79
  32. package/dist/interceptors/grpcSignedToken.js.map +1 -1
  33. package/dist/interceptors/moduleName.js +7 -79
  34. package/dist/interceptors/moduleName.js.map +1 -1
  35. package/dist/metrics/MetricsServer.js +25 -70
  36. package/dist/metrics/MetricsServer.js.map +1 -1
  37. package/dist/metrics/clientMiddleware.js +76 -217
  38. package/dist/metrics/clientMiddleware.js.map +1 -1
  39. package/dist/metrics/config/defaults.js +1 -1
  40. package/dist/metrics/config/defaults.js.map +1 -1
  41. package/dist/metrics/index.js +53 -89
  42. package/dist/metrics/index.js.map +1 -1
  43. package/dist/modules/admin/index.js +16 -34
  44. package/dist/modules/admin/index.js.map +1 -1
  45. package/dist/modules/authentication/index.js +20 -39
  46. package/dist/modules/authentication/index.js.map +1 -1
  47. package/dist/modules/authorization/index.js +29 -47
  48. package/dist/modules/authorization/index.js.map +1 -1
  49. package/dist/modules/chat/index.js +16 -34
  50. package/dist/modules/chat/index.js.map +1 -1
  51. package/dist/modules/config/index.js +70 -175
  52. package/dist/modules/config/index.js.map +1 -1
  53. package/dist/modules/core/index.js +8 -26
  54. package/dist/modules/core/index.js.map +1 -1
  55. package/dist/modules/database/index.js +80 -122
  56. package/dist/modules/database/index.js.map +1 -1
  57. package/dist/modules/email/index.js +15 -33
  58. package/dist/modules/email/index.js.map +1 -1
  59. package/dist/modules/forms/index.js +8 -26
  60. package/dist/modules/forms/index.js.map +1 -1
  61. package/dist/modules/functions/index.js +8 -26
  62. package/dist/modules/functions/index.js.map +1 -1
  63. package/dist/modules/pushNotifications/index.js +38 -56
  64. package/dist/modules/pushNotifications/index.js.map +1 -1
  65. package/dist/modules/router/index.js +18 -36
  66. package/dist/modules/router/index.js.map +1 -1
  67. package/dist/modules/sms/index.js +17 -35
  68. package/dist/modules/sms/index.js.map +1 -1
  69. package/dist/modules/storage/index.js +17 -36
  70. package/dist/modules/storage/index.js.map +1 -1
  71. package/dist/protoUtils/authentication.d.ts +1 -1
  72. package/dist/protoUtils/authentication.js +188 -169
  73. package/dist/protoUtils/authentication.js.map +1 -1
  74. package/dist/protoUtils/authorization.d.ts +1 -1
  75. package/dist/protoUtils/authorization.js +332 -391
  76. package/dist/protoUtils/authorization.js.map +1 -1
  77. package/dist/protoUtils/chat.d.ts +1 -1
  78. package/dist/protoUtils/chat.js +176 -212
  79. package/dist/protoUtils/chat.js.map +1 -1
  80. package/dist/protoUtils/core.d.ts +1 -1
  81. package/dist/protoUtils/core.js +643 -605
  82. package/dist/protoUtils/core.js.map +1 -1
  83. package/dist/protoUtils/database.d.ts +1 -1
  84. package/dist/protoUtils/database.js +563 -554
  85. package/dist/protoUtils/database.js.map +1 -1
  86. package/dist/protoUtils/email.d.ts +1 -1
  87. package/dist/protoUtils/email.js +180 -208
  88. package/dist/protoUtils/email.js.map +1 -1
  89. package/dist/protoUtils/forms.d.ts +1 -1
  90. package/dist/protoUtils/forms.js +37 -35
  91. package/dist/protoUtils/forms.js.map +1 -1
  92. package/dist/protoUtils/functions.d.ts +1 -1
  93. package/dist/protoUtils/functions.js +37 -35
  94. package/dist/protoUtils/functions.js.map +1 -1
  95. package/dist/protoUtils/grpc_health_check.d.ts +1 -1
  96. package/dist/protoUtils/grpc_health_check.js +36 -34
  97. package/dist/protoUtils/grpc_health_check.js.map +1 -1
  98. package/dist/protoUtils/push-notifications.d.ts +1 -1
  99. package/dist/protoUtils/push-notifications.js +252 -272
  100. package/dist/protoUtils/push-notifications.js.map +1 -1
  101. package/dist/protoUtils/router.d.ts +1 -1
  102. package/dist/protoUtils/router.js +381 -387
  103. package/dist/protoUtils/router.js.map +1 -1
  104. package/dist/protoUtils/sms.d.ts +1 -1
  105. package/dist/protoUtils/sms.js +155 -143
  106. package/dist/protoUtils/sms.js.map +1 -1
  107. package/dist/protoUtils/storage.d.ts +1 -1
  108. package/dist/protoUtils/storage.js +190 -164
  109. package/dist/protoUtils/storage.js.map +1 -1
  110. package/dist/routing/ConduitRouteReturn.js +9 -18
  111. package/dist/routing/ConduitRouteReturn.js.map +1 -1
  112. package/dist/routing/ProxyRouteBuilder.js +21 -24
  113. package/dist/routing/ProxyRouteBuilder.js.map +1 -1
  114. package/dist/routing/RouteBuilder.js +31 -34
  115. package/dist/routing/RouteBuilder.js.map +1 -1
  116. package/dist/routing/RoutingManager.js +65 -115
  117. package/dist/routing/RoutingManager.js.map +1 -1
  118. package/dist/routing/RoutingUtilities.js +3 -3
  119. package/dist/routing/RoutingUtilities.js.map +1 -1
  120. package/dist/routing/wrapRouterFunctions.js +25 -34
  121. package/dist/routing/wrapRouterFunctions.js.map +1 -1
  122. package/dist/types/index.js +6 -24
  123. package/dist/types/index.js.map +1 -1
  124. package/dist/utilities/EventBus.js +16 -17
  125. package/dist/utilities/EventBus.js.map +1 -1
  126. package/dist/utilities/Logger.js +80 -180
  127. package/dist/utilities/Logger.js.map +1 -1
  128. package/dist/utilities/RedisManager.js +11 -21
  129. package/dist/utilities/RedisManager.js.map +1 -1
  130. package/dist/utilities/StateManager.js +13 -14
  131. package/dist/utilities/StateManager.js.map +1 -1
  132. package/dist/utilities/linearBackoffTimeout.js +28 -92
  133. package/dist/utilities/linearBackoffTimeout.js.map +1 -1
  134. package/dist/utilities/merge.js +2 -2
  135. package/dist/utilities/merge.js.map +1 -1
  136. package/dist/utilities/sleep.js +1 -1
  137. package/dist/utilities/sleep.js.map +1 -1
  138. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -24,67 +13,29 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
24
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
26
15
  };
27
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
28
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
- return new (P || (P = Promise))(function (resolve, reject) {
30
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
- step((generator = generator.apply(thisArg, _arguments || [])).next());
34
- });
35
- };
36
- var __generator = (this && this.__generator) || function (thisArg, body) {
37
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
38
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
39
- function verb(n) { return function (v) { return step([n, v]); }; }
40
- function step(op) {
41
- if (f) throw new TypeError("Generator is already executing.");
42
- while (_) try {
43
- 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;
44
- if (y = 0, t) op = [op[0] & 2, t.value];
45
- switch (op[0]) {
46
- case 0: case 1: t = op; break;
47
- case 4: _.label++; return { value: op[1], done: false };
48
- case 5: _.label++; y = op[1]; op = [0]; continue;
49
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
50
- default:
51
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
52
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
53
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
54
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
55
- if (t[2]) _.ops.pop();
56
- _.trys.pop(); continue;
57
- }
58
- op = body.call(thisArg, _);
59
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
60
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
61
- }
62
- };
63
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
64
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
65
18
  };
66
19
  Object.defineProperty(exports, "__esModule", { value: true });
67
- var modules_1 = require("./modules");
68
- var crypto_1 = __importDefault(require("crypto"));
69
- var EventBus_1 = require("./utilities/EventBus");
70
- var RedisManager_1 = require("./utilities/RedisManager");
71
- var StateManager_1 = require("./utilities/StateManager");
72
- var ConduitModule_1 = require("./classes/ConduitModule");
73
- var grpc_js_1 = require("@grpc/grpc-js");
74
- var utilities_1 = require("./utilities");
75
- var grpc_health_check_1 = require("./protoUtils/grpc_health_check");
76
- var types_1 = require("./types");
77
- var fast_jwt_1 = require("fast-jwt");
78
- var HealthCheck_1 = require("./classes/HealthCheck");
79
- var Logger_1 = require("./utilities/Logger");
80
- var winston_1 = __importDefault(require("winston"));
81
- var path_1 = __importDefault(require("path"));
82
- var metrics_1 = require("./metrics");
83
- var fs_extra_1 = __importDefault(require("fs-extra"));
84
- var ConduitGrpcSdk = /** @class */ (function () {
85
- function ConduitGrpcSdk(serverUrl, serviceHealthStatusGetter, name, watchModules, urlRemap) {
86
- if (serviceHealthStatusGetter === void 0) { serviceHealthStatusGetter = function () { return types_1.HealthCheckStatus.SERVING; }; }
87
- if (watchModules === void 0) { watchModules = true; }
20
+ const modules_1 = require("./modules");
21
+ const crypto_1 = __importDefault(require("crypto"));
22
+ const EventBus_1 = require("./utilities/EventBus");
23
+ const RedisManager_1 = require("./utilities/RedisManager");
24
+ const StateManager_1 = require("./utilities/StateManager");
25
+ const ConduitModule_1 = require("./classes/ConduitModule");
26
+ const grpc_js_1 = require("@grpc/grpc-js");
27
+ const utilities_1 = require("./utilities");
28
+ const grpc_health_check_1 = require("./protoUtils/grpc_health_check");
29
+ const types_1 = require("./types");
30
+ const fast_jwt_1 = require("fast-jwt");
31
+ const HealthCheck_1 = require("./classes/HealthCheck");
32
+ const Logger_1 = require("./utilities/Logger");
33
+ const winston_1 = __importDefault(require("winston"));
34
+ const path_1 = __importDefault(require("path"));
35
+ const metrics_1 = require("./metrics");
36
+ const fs_extra_1 = __importDefault(require("fs-extra"));
37
+ class ConduitGrpcSdk {
38
+ constructor(serverUrl, serviceHealthStatusGetter = () => types_1.HealthCheckStatus.SERVING, name, watchModules = true, urlRemap) {
88
39
  this.urlRemap = urlRemap;
89
40
  this._redisManager = null;
90
41
  this._modules = {};
@@ -121,55 +72,37 @@ var ConduitGrpcSdk = /** @class */ (function () {
121
72
  this._watchModules = watchModules;
122
73
  this._serviceHealthStatusGetter = serviceHealthStatusGetter;
123
74
  if (process.env.GRPC_KEY) {
124
- var sign = (0, fast_jwt_1.createSigner)({ key: process.env.GRPC_KEY });
75
+ const sign = (0, fast_jwt_1.createSigner)({ key: process.env.GRPC_KEY });
125
76
  this._grpcToken = sign({
126
77
  moduleName: this.name,
127
78
  });
128
79
  }
129
80
  }
130
- ConduitGrpcSdk.prototype.initialize = function () {
131
- return __awaiter(this, void 0, void 0, function () {
132
- var state, err_1;
133
- return __generator(this, function (_a) {
134
- switch (_a.label) {
135
- case 0:
136
- if (this.name === 'core') {
137
- return [2 /*return*/, this._initialize()];
138
- }
139
- this._core = new modules_1.Core(this.name, this.serverUrl, this._grpcToken);
140
- ConduitGrpcSdk.Logger.log('Waiting for Core...');
141
- _a.label = 1;
142
- case 1:
143
- if (!true) return [3 /*break*/, 7];
144
- _a.label = 2;
145
- case 2:
146
- _a.trys.push([2, 4, , 6]);
147
- return [4 /*yield*/, this.core.check()];
148
- case 3:
149
- state = _a.sent();
150
- if (state === types_1.HealthCheckStatus.SERVING) {
151
- ConduitGrpcSdk.Logger.log('Core connection established');
152
- this._initialize();
153
- return [3 /*break*/, 7];
154
- }
155
- return [3 /*break*/, 6];
156
- case 4:
157
- err_1 = _a.sent();
158
- if (err_1.code === grpc_js_1.status.PERMISSION_DENIED) {
159
- ConduitGrpcSdk.Logger.error(err_1);
160
- process.exit(-1);
161
- }
162
- return [4 /*yield*/, (0, utilities_1.sleep)(1000)];
163
- case 5:
164
- _a.sent();
165
- return [3 /*break*/, 6];
166
- case 6: return [3 /*break*/, 1];
167
- case 7: return [2 /*return*/];
81
+ async initialize() {
82
+ if (this.name === 'core') {
83
+ return this._initialize();
84
+ }
85
+ this._core = new modules_1.Core(this.name, this.serverUrl, this._grpcToken);
86
+ ConduitGrpcSdk.Logger.log('Waiting for Core...');
87
+ while (true) {
88
+ try {
89
+ const state = await this.core.check();
90
+ if (state === types_1.HealthCheckStatus.SERVING) {
91
+ ConduitGrpcSdk.Logger.log('Core connection established');
92
+ this._initialize();
93
+ break;
168
94
  }
169
- });
170
- });
171
- };
172
- ConduitGrpcSdk.prototype._initialize = function () {
95
+ }
96
+ catch (err) {
97
+ if (err.code === grpc_js_1.status.PERMISSION_DENIED) {
98
+ ConduitGrpcSdk.Logger.error(err);
99
+ process.exit(-1);
100
+ }
101
+ await (0, utilities_1.sleep)(1000);
102
+ }
103
+ }
104
+ }
105
+ _initialize() {
173
106
  if (this._initialized)
174
107
  throw new Error("Module's grpc-sdk has already been initialized");
175
108
  this._config = new modules_1.Config(this.name, this.serverUrl, this._serviceHealthStatusGetter, this._grpcToken);
@@ -181,275 +114,199 @@ var ConduitGrpcSdk = /** @class */ (function () {
181
114
  this.watchModules();
182
115
  }
183
116
  this._initialized = true;
184
- };
185
- Object.defineProperty(ConduitGrpcSdk.prototype, "bus", {
186
- get: function () {
187
- if (this._eventBus) {
188
- return this._eventBus;
189
- }
190
- else {
191
- ConduitGrpcSdk.Logger.warn('Event bus not initialized');
192
- return null;
193
- }
194
- },
195
- enumerable: false,
196
- configurable: true
197
- });
198
- Object.defineProperty(ConduitGrpcSdk.prototype, "state", {
199
- get: function () {
200
- if (this._stateManager) {
201
- return this._stateManager;
202
- }
203
- else {
204
- ConduitGrpcSdk.Logger.warn('State Manager not initialized');
205
- return null;
206
- }
207
- },
208
- enumerable: false,
209
- configurable: true
210
- });
211
- Object.defineProperty(ConduitGrpcSdk.prototype, "core", {
212
- get: function () {
213
- return this._core;
214
- },
215
- enumerable: false,
216
- configurable: true
217
- });
218
- Object.defineProperty(ConduitGrpcSdk.prototype, "config", {
219
- get: function () {
220
- return this._config;
221
- },
222
- enumerable: false,
223
- configurable: true
224
- });
225
- Object.defineProperty(ConduitGrpcSdk.prototype, "admin", {
226
- get: function () {
227
- return this._admin;
228
- },
229
- enumerable: false,
230
- configurable: true
231
- });
232
- Object.defineProperty(ConduitGrpcSdk.prototype, "router", {
233
- get: function () {
234
- if (this._modules['router']) {
235
- return this._modules['router'];
236
- }
237
- else {
238
- ConduitGrpcSdk.Logger.warn('Router not up yet!');
239
- return null;
240
- }
241
- },
242
- enumerable: false,
243
- configurable: true
244
- });
245
- Object.defineProperty(ConduitGrpcSdk.prototype, "database", {
246
- get: function () {
247
- if (this._modules['database']) {
248
- return this._modules['database'];
249
- }
250
- else {
251
- ConduitGrpcSdk.Logger.warn('Database provider not up yet!');
252
- return null;
253
- }
254
- },
255
- enumerable: false,
256
- configurable: true
257
- });
258
- Object.defineProperty(ConduitGrpcSdk.prototype, "databaseProvider", {
259
- get: function () {
260
- return this.database;
261
- },
262
- enumerable: false,
263
- configurable: true
264
- });
265
- Object.defineProperty(ConduitGrpcSdk.prototype, "storage", {
266
- get: function () {
267
- if (this._modules['storage']) {
268
- return this._modules['storage'];
269
- }
270
- else {
271
- ConduitGrpcSdk.Logger.warn('Storage module not up yet!');
272
- return null;
273
- }
274
- },
275
- enumerable: false,
276
- configurable: true
277
- });
278
- Object.defineProperty(ConduitGrpcSdk.prototype, "forms", {
279
- get: function () {
280
- if (this._modules['forms']) {
281
- return this._modules['forms'];
282
- }
283
- else {
284
- ConduitGrpcSdk.Logger.warn('Forms module not up yet!');
285
- return null;
286
- }
287
- },
288
- enumerable: false,
289
- configurable: true
290
- });
291
- Object.defineProperty(ConduitGrpcSdk.prototype, "emailProvider", {
292
- get: function () {
293
- if (this._modules['email']) {
294
- return this._modules['email'];
295
- }
296
- else {
297
- ConduitGrpcSdk.Logger.warn('Email provider not up yet!');
298
- return null;
299
- }
300
- },
301
- enumerable: false,
302
- configurable: true
303
- });
304
- Object.defineProperty(ConduitGrpcSdk.prototype, "pushNotifications", {
305
- get: function () {
306
- if (this._modules['pushNotifications']) {
307
- return this._modules['pushNotifications'];
308
- }
309
- else {
310
- ConduitGrpcSdk.Logger.warn('Push notifications module not up yet!');
311
- return null;
312
- }
313
- },
314
- enumerable: false,
315
- configurable: true
316
- });
317
- Object.defineProperty(ConduitGrpcSdk.prototype, "authentication", {
318
- get: function () {
319
- if (this._modules['authentication']) {
320
- return this._modules['authentication'];
321
- }
322
- else {
323
- ConduitGrpcSdk.Logger.warn('Authentication module not up yet!');
324
- return null;
325
- }
326
- },
327
- enumerable: false,
328
- configurable: true
329
- });
330
- Object.defineProperty(ConduitGrpcSdk.prototype, "authorization", {
331
- get: function () {
332
- if (this._modules['authorization']) {
333
- return this._modules['authorization'];
334
- }
335
- else {
336
- ConduitGrpcSdk.Logger.warn('Authorization module not up yet!');
337
- return null;
338
- }
339
- },
340
- enumerable: false,
341
- configurable: true
342
- });
343
- Object.defineProperty(ConduitGrpcSdk.prototype, "sms", {
344
- get: function () {
345
- if (this._modules['sms']) {
346
- return this._modules['sms'];
347
- }
348
- else {
349
- ConduitGrpcSdk.Logger.warn('SMS module not up yet!');
350
- return null;
351
- }
352
- },
353
- enumerable: false,
354
- configurable: true
355
- });
356
- Object.defineProperty(ConduitGrpcSdk.prototype, "chat", {
357
- get: function () {
358
- if (this._modules['chat']) {
359
- return this._modules['chat'];
360
- }
361
- else {
362
- ConduitGrpcSdk.Logger.warn('Chat module not up yet!');
363
- return null;
364
- }
365
- },
366
- enumerable: false,
367
- configurable: true
368
- });
369
- Object.defineProperty(ConduitGrpcSdk.prototype, "functions", {
370
- get: function () {
371
- if (this._modules['functions']) {
372
- return this._modules['functions'];
373
- }
374
- else {
375
- ConduitGrpcSdk.Logger.warn('Functions module not up yet!');
376
- return null;
377
- }
378
- },
379
- enumerable: false,
380
- configurable: true
381
- });
382
- Object.defineProperty(ConduitGrpcSdk.prototype, "redisDetails", {
383
- get: function () {
384
- if (this._redisDetails) {
385
- return this._redisDetails;
386
- }
387
- else {
388
- throw new Error('Redis not available');
389
- }
390
- },
391
- enumerable: false,
392
- configurable: true
393
- });
394
- ConduitGrpcSdk.prototype.watchModules = function () {
395
- var _this = this;
396
- var emitter = this.config.getModuleWatcher();
117
+ }
118
+ get bus() {
119
+ if (this._eventBus) {
120
+ return this._eventBus;
121
+ }
122
+ else {
123
+ ConduitGrpcSdk.Logger.warn('Event bus not initialized');
124
+ return null;
125
+ }
126
+ }
127
+ get state() {
128
+ if (this._stateManager) {
129
+ return this._stateManager;
130
+ }
131
+ else {
132
+ ConduitGrpcSdk.Logger.warn('State Manager not initialized');
133
+ return null;
134
+ }
135
+ }
136
+ get core() {
137
+ return this._core;
138
+ }
139
+ get config() {
140
+ return this._config;
141
+ }
142
+ get admin() {
143
+ return this._admin;
144
+ }
145
+ get router() {
146
+ if (this._modules['router']) {
147
+ return this._modules['router'];
148
+ }
149
+ else {
150
+ ConduitGrpcSdk.Logger.warn('Router not up yet!');
151
+ return null;
152
+ }
153
+ }
154
+ get database() {
155
+ if (this._modules['database']) {
156
+ return this._modules['database'];
157
+ }
158
+ else {
159
+ ConduitGrpcSdk.Logger.warn('Database provider not up yet!');
160
+ return null;
161
+ }
162
+ }
163
+ get databaseProvider() {
164
+ return this.database;
165
+ }
166
+ get storage() {
167
+ if (this._modules['storage']) {
168
+ return this._modules['storage'];
169
+ }
170
+ else {
171
+ ConduitGrpcSdk.Logger.warn('Storage module not up yet!');
172
+ return null;
173
+ }
174
+ }
175
+ get forms() {
176
+ if (this._modules['forms']) {
177
+ return this._modules['forms'];
178
+ }
179
+ else {
180
+ ConduitGrpcSdk.Logger.warn('Forms module not up yet!');
181
+ return null;
182
+ }
183
+ }
184
+ get emailProvider() {
185
+ if (this._modules['email']) {
186
+ return this._modules['email'];
187
+ }
188
+ else {
189
+ ConduitGrpcSdk.Logger.warn('Email provider not up yet!');
190
+ return null;
191
+ }
192
+ }
193
+ get pushNotifications() {
194
+ if (this._modules['pushNotifications']) {
195
+ return this._modules['pushNotifications'];
196
+ }
197
+ else {
198
+ ConduitGrpcSdk.Logger.warn('Push notifications module not up yet!');
199
+ return null;
200
+ }
201
+ }
202
+ get authentication() {
203
+ if (this._modules['authentication']) {
204
+ return this._modules['authentication'];
205
+ }
206
+ else {
207
+ ConduitGrpcSdk.Logger.warn('Authentication module not up yet!');
208
+ return null;
209
+ }
210
+ }
211
+ get authorization() {
212
+ if (this._modules['authorization']) {
213
+ return this._modules['authorization'];
214
+ }
215
+ else {
216
+ ConduitGrpcSdk.Logger.warn('Authorization module not up yet!');
217
+ return null;
218
+ }
219
+ }
220
+ get sms() {
221
+ if (this._modules['sms']) {
222
+ return this._modules['sms'];
223
+ }
224
+ else {
225
+ ConduitGrpcSdk.Logger.warn('SMS module not up yet!');
226
+ return null;
227
+ }
228
+ }
229
+ get chat() {
230
+ if (this._modules['chat']) {
231
+ return this._modules['chat'];
232
+ }
233
+ else {
234
+ ConduitGrpcSdk.Logger.warn('Chat module not up yet!');
235
+ return null;
236
+ }
237
+ }
238
+ get functions() {
239
+ if (this._modules['functions']) {
240
+ return this._modules['functions'];
241
+ }
242
+ else {
243
+ ConduitGrpcSdk.Logger.warn('Functions module not up yet!');
244
+ return null;
245
+ }
246
+ }
247
+ get redisDetails() {
248
+ if (this._redisDetails) {
249
+ return this._redisDetails;
250
+ }
251
+ else {
252
+ throw new Error('Redis not available');
253
+ }
254
+ }
255
+ watchModules() {
256
+ const emitter = this.config.getModuleWatcher();
397
257
  this.config.watchModules().then();
398
- emitter.on('serving-modules-update', function (modules) {
399
- Object.keys(_this._modules).forEach(function (r) {
258
+ emitter.on('serving-modules-update', (modules) => {
259
+ Object.keys(this._modules).forEach(r => {
400
260
  var _a;
401
- if (r !== _this.name) {
402
- var found = modules.filter(function (m) { return m.moduleName === r && m.serving; });
403
- if ((!found || found.length === 0) && _this._modules[r]) {
404
- (_a = _this._modules[r]) === null || _a === void 0 ? void 0 : _a.closeConnection();
405
- emitter.emit("module-connection-update:".concat(r), false);
261
+ if (r !== this.name) {
262
+ const found = modules.filter((m) => m.moduleName === r && m.serving);
263
+ if ((!found || found.length === 0) && this._modules[r]) {
264
+ (_a = this._modules[r]) === null || _a === void 0 ? void 0 : _a.closeConnection();
265
+ emitter.emit(`module-connection-update:${r}`, false);
406
266
  }
407
267
  }
408
268
  });
409
- modules.forEach(function (m) {
269
+ modules.forEach((m) => {
410
270
  var _a;
411
- if (m.moduleName !== _this.name) {
412
- var alreadyActive = (_a = _this._modules[m.moduleName]) === null || _a === void 0 ? void 0 : _a.active;
271
+ if (m.moduleName !== this.name) {
272
+ const alreadyActive = (_a = this._modules[m.moduleName]) === null || _a === void 0 ? void 0 : _a.active;
413
273
  if (!alreadyActive && m.serving) {
414
- if (_this._availableModules[m.moduleName] && _this._modules[m.moduleName]) {
415
- _this._modules[m.moduleName].openConnection();
274
+ if (this._availableModules[m.moduleName] && this._modules[m.moduleName]) {
275
+ this._modules[m.moduleName].openConnection();
416
276
  }
417
277
  else {
418
- _this.createModuleClient(m.moduleName, m.url);
278
+ this.createModuleClient(m.moduleName, m.url);
419
279
  }
420
- emitter.emit("module-connection-update:".concat(m.moduleName), true);
280
+ emitter.emit(`module-connection-update:${m.moduleName}`, true);
421
281
  }
422
282
  }
423
283
  });
424
284
  });
425
- };
426
- ConduitGrpcSdk.prototype.monitorModule = function (moduleName, callback, wait) {
427
- var _this = this;
428
- if (wait === void 0) { wait = true; }
429
- var waitPromise = wait ? this.waitForExistence(moduleName) : Promise.resolve();
285
+ }
286
+ monitorModule(moduleName, callback, wait = true) {
287
+ const waitPromise = wait ? this.waitForExistence(moduleName) : Promise.resolve();
430
288
  waitPromise
431
- .then(function () { var _a, _b; return (_b = (_a = _this._modules[moduleName]) === null || _a === void 0 ? void 0 : _a.healthClient) === null || _b === void 0 ? void 0 : _b.check({}); })
432
- .then(function (res) {
289
+ .then(() => { var _a, _b; return (_b = (_a = this._modules[moduleName]) === null || _a === void 0 ? void 0 : _a.healthClient) === null || _b === void 0 ? void 0 : _b.check({}); })
290
+ .then(res => {
433
291
  callback((res === null || res === void 0 ? void 0 : res.status) === grpc_health_check_1.HealthCheckResponse_ServingStatus.SERVING);
434
292
  })
435
- .catch(function () {
293
+ .catch(() => {
436
294
  callback(false);
437
295
  })
438
- .then(function () {
439
- var emitter = _this.config.getModuleWatcher();
440
- emitter.on("module-connection-update:".concat(moduleName), callback);
296
+ .then(() => {
297
+ const emitter = this.config.getModuleWatcher();
298
+ emitter.on(`module-connection-update:${moduleName}`, callback);
441
299
  });
442
- };
443
- ConduitGrpcSdk.prototype.unmonitorModule = function (moduleName) {
444
- var emitter = this.config.getModuleWatcher();
445
- emitter.removeAllListeners("module-connection-update:".concat(moduleName));
446
- };
447
- ConduitGrpcSdk.prototype.initializeEventBus = function () {
448
- var _this = this;
449
- var promise = Promise.resolve();
300
+ }
301
+ unmonitorModule(moduleName) {
302
+ const emitter = this.config.getModuleWatcher();
303
+ emitter.removeAllListeners(`module-connection-update:${moduleName}`);
304
+ }
305
+ initializeEventBus() {
306
+ let promise = Promise.resolve();
450
307
  if (process.env.REDIS_CONFIG) {
451
- var redisConfig = process.env.REDIS_CONFIG;
452
- var redisJson = void 0;
308
+ const redisConfig = process.env.REDIS_CONFIG;
309
+ let redisJson;
453
310
  if (redisConfig.startsWith('{')) {
454
311
  try {
455
312
  redisJson = JSON.parse(redisConfig);
@@ -480,13 +337,13 @@ var ConduitGrpcSdk = /** @class */ (function () {
480
337
  }
481
338
  else {
482
339
  promise = promise
483
- .then(function () { return _this.config.getRedisDetails(); })
484
- .then(function (r) {
340
+ .then(() => this.config.getRedisDetails())
341
+ .then((r) => {
485
342
  if (r.redisConfig) {
486
- _this._redisDetails = JSON.parse(r.redisConfig);
343
+ this._redisDetails = JSON.parse(r.redisConfig);
487
344
  }
488
345
  else {
489
- _this._redisDetails = {
346
+ this._redisDetails = {
490
347
  host: r.redisHost,
491
348
  port: r.redisPort,
492
349
  username: r.redisUsername,
@@ -496,155 +353,130 @@ var ConduitGrpcSdk = /** @class */ (function () {
496
353
  });
497
354
  }
498
355
  return promise
499
- .then(function () {
356
+ .then(() => {
500
357
  var _a;
501
- if (_this._redisDetails.hasOwnProperty('nodes')) {
502
- _this._redisManager = new RedisManager_1.RedisManager(_this._redisDetails);
358
+ if (this._redisDetails.hasOwnProperty('nodes')) {
359
+ this._redisManager = new RedisManager_1.RedisManager(this._redisDetails);
503
360
  }
504
361
  else {
505
- var redisHost = (_a = _this.urlRemap) !== null && _a !== void 0 ? _a : _this._redisDetails.host;
506
- _this._redisManager = new RedisManager_1.RedisManager(__assign(__assign({}, _this._redisDetails), { host: redisHost }));
507
- }
508
- _this._eventBus = new EventBus_1.EventBus(_this._redisManager);
509
- _this._stateManager = new StateManager_1.StateManager(_this._redisManager, _this.name);
510
- return _this._eventBus;
362
+ const redisHost = (_a = this.urlRemap) !== null && _a !== void 0 ? _a : this._redisDetails.host;
363
+ this._redisManager = new RedisManager_1.RedisManager({
364
+ ...this._redisDetails,
365
+ host: redisHost,
366
+ });
367
+ }
368
+ this._eventBus = new EventBus_1.EventBus(this._redisManager);
369
+ this._stateManager = new StateManager_1.StateManager(this._redisManager, this.name);
370
+ return this._eventBus;
511
371
  })
512
- .catch(function (err) {
372
+ .catch((err) => {
513
373
  ConduitGrpcSdk.Logger.error('Failed to initialize event bus');
514
374
  throw err;
515
375
  });
516
- };
517
- Object.defineProperty(ConduitGrpcSdk.prototype, "redisManager", {
518
- get: function () {
519
- if (this._redisManager) {
520
- return this._redisManager;
521
- }
522
- else {
523
- throw new Error('Redis not available');
524
- }
525
- },
526
- enumerable: false,
527
- configurable: true
528
- });
376
+ }
377
+ get redisManager() {
378
+ if (this._redisManager) {
379
+ return this._redisManager;
380
+ }
381
+ else {
382
+ throw new Error('Redis not available');
383
+ }
384
+ }
529
385
  /**
530
386
  * Gets all the registered modules from the config and creates clients for them.
531
387
  * This will only work on known modules, since the primary usage for the sdk is internal
532
388
  */
533
- ConduitGrpcSdk.prototype.initializeModules = function () {
534
- var _this = this;
389
+ initializeModules() {
535
390
  return this._config.moduleList()
536
- .then(function (r) {
537
- _this.lastSearch = Date.now();
538
- r.forEach(function (m) {
539
- _this.createModuleClient(m.moduleName, m.url);
391
+ .then(r => {
392
+ this.lastSearch = Date.now();
393
+ r.forEach(m => {
394
+ this.createModuleClient(m.moduleName, m.url);
540
395
  });
541
396
  return 'ok';
542
397
  })
543
- .catch(function (err) {
398
+ .catch(err => {
544
399
  if (err.code !== 5) {
545
400
  ConduitGrpcSdk.Logger.error(err);
546
401
  }
547
402
  });
548
- };
549
- ConduitGrpcSdk.prototype.createModuleClient = function (moduleName, moduleUrl) {
403
+ }
404
+ createModuleClient(moduleName, moduleUrl) {
550
405
  if (this._modules[moduleName] ||
551
406
  (!this._availableModules[moduleName] && !this._dynamicModules[moduleName]))
552
407
  return;
553
408
  if (this._availableModules[moduleName]) {
554
409
  // ConduitGrpcSdk.Logger.log(`Creating gRPC client for ${moduleName}`);
555
- this._modules[moduleName] = new this._availableModules[moduleName](this.name, this.urlRemap ? "".concat(this.urlRemap, ":").concat(moduleUrl.split(':')[1]) : moduleUrl, this._grpcToken);
410
+ this._modules[moduleName] = new this._availableModules[moduleName](this.name, this.urlRemap ? `${this.urlRemap}:${moduleUrl.split(':')[1]}` : moduleUrl, this._grpcToken);
556
411
  }
557
412
  else if (this._dynamicModules[moduleName]) {
558
413
  // ConduitGrpcSdk.Logger.log(`Creating gRPC client for ${moduleName}`);
559
- this._modules[moduleName] = new ConduitModule_1.ConduitModule(this.name, moduleName, this.urlRemap ? "".concat(this.urlRemap, ":").concat(moduleUrl.split(':')[1]) : moduleUrl, this._grpcToken);
414
+ this._modules[moduleName] = new ConduitModule_1.ConduitModule(this.name, moduleName, this.urlRemap ? `${this.urlRemap}:${moduleUrl.split(':')[1]}` : moduleUrl, this._grpcToken);
560
415
  this._modules[moduleName].initializeClient(this._dynamicModules[moduleName]);
561
416
  }
562
- };
563
- ConduitGrpcSdk.prototype.isModuleUp = function (moduleName, moduleUrl, service) {
564
- if (service === void 0) { service = ''; }
417
+ }
418
+ isModuleUp(moduleName, moduleUrl, service = '') {
565
419
  return (0, HealthCheck_1.checkModuleHealth)(moduleName, moduleUrl, service, this._grpcToken);
566
- };
567
- ConduitGrpcSdk.prototype.moduleClient = function (name, type) {
420
+ }
421
+ moduleClient(name, type) {
568
422
  this._dynamicModules[name] = type;
569
- };
570
- ConduitGrpcSdk.prototype.getModule = function (name) {
423
+ }
424
+ getModule(name) {
571
425
  return this._modules[name];
572
- };
573
- ConduitGrpcSdk.prototype.getServiceClient = function (name) {
426
+ }
427
+ getServiceClient(name) {
574
428
  var _a;
575
429
  return (_a = this._modules[name]) === null || _a === void 0 ? void 0 : _a.client;
576
- };
577
- ConduitGrpcSdk.prototype.getHealthClient = function (name) {
430
+ }
431
+ getHealthClient(name) {
578
432
  var _a;
579
433
  return (_a = this._modules[name]) === null || _a === void 0 ? void 0 : _a.healthClient;
580
- };
581
- ConduitGrpcSdk.prototype.isAvailable = function (moduleName) {
434
+ }
435
+ isAvailable(moduleName) {
582
436
  var _a;
583
437
  return !!((_a = this._modules[moduleName]) === null || _a === void 0 ? void 0 : _a.active);
584
- };
585
- ConduitGrpcSdk.prototype.waitForExistence = function (moduleName) {
586
- return __awaiter(this, void 0, void 0, function () {
587
- return __generator(this, function (_a) {
588
- switch (_a.label) {
589
- case 0:
590
- if (!!this._modules[moduleName]) return [3 /*break*/, 2];
591
- return [4 /*yield*/, (0, utilities_1.sleep)(1000)];
592
- case 1:
593
- _a.sent();
594
- return [3 /*break*/, 0];
595
- case 2: return [2 /*return*/, true];
596
- }
597
- });
598
- });
599
- };
600
- ConduitGrpcSdk.prototype.onceModuleUp = function (moduleName, callback) {
438
+ }
439
+ async waitForExistence(moduleName) {
440
+ while (!this._modules[moduleName]) {
441
+ await (0, utilities_1.sleep)(1000);
442
+ }
443
+ return true;
444
+ }
445
+ onceModuleUp(moduleName, callback) {
601
446
  if (this.isAvailable(moduleName))
602
447
  callback();
603
- var emitter = this.config.getModuleWatcher();
604
- emitter.once("module-connection-update:".concat(moduleName), function (serving) {
605
- return serving ? callback() : null;
606
- });
607
- };
608
- ConduitGrpcSdk.prototype.onceModuleDown = function (moduleName, callback) {
609
- var emitter = this.config.getModuleWatcher();
610
- emitter.once("module-connection-update:".concat(moduleName), function (serving) {
611
- return serving ? null : callback();
612
- });
613
- };
448
+ const emitter = this.config.getModuleWatcher();
449
+ emitter.once(`module-connection-update:${moduleName}`, (serving) => serving ? callback() : null);
450
+ }
451
+ onceModuleDown(moduleName, callback) {
452
+ const emitter = this.config.getModuleWatcher();
453
+ emitter.once(`module-connection-update:${moduleName}`, (serving) => serving ? null : callback());
454
+ }
614
455
  /**
615
456
  * Used to refresh all modules to check for new registrations
616
457
  * @param force If true will check for new modules no matter the interval
617
458
  */
618
- ConduitGrpcSdk.prototype.refreshModules = function (force) {
619
- return __awaiter(this, void 0, void 0, function () {
620
- return __generator(this, function (_a) {
621
- if (this.lastSearch < Date.now() - 3000 || force) {
622
- return [2 /*return*/, this.initializeModules()];
623
- }
624
- return [2 /*return*/, 'ok'];
625
- });
626
- });
627
- };
628
- Object.defineProperty(ConduitGrpcSdk.prototype, "grpcToken", {
629
- get: function () {
630
- return this._grpcToken;
631
- },
632
- enumerable: false,
633
- configurable: true
634
- });
635
- ConduitGrpcSdk.Logger = new Logger_1.ConduitLogger([
636
- new winston_1.default.transports.File({
637
- filename: path_1.default.join(__dirname, '.logs/combined.log'),
638
- level: 'info',
639
- }),
640
- new winston_1.default.transports.File({
641
- filename: path_1.default.join(__dirname, '.logs/errors.log'),
642
- level: 'error',
643
- }),
644
- ]);
645
- return ConduitGrpcSdk;
646
- }());
459
+ async refreshModules(force) {
460
+ if (this.lastSearch < Date.now() - 3000 || force) {
461
+ return this.initializeModules();
462
+ }
463
+ return 'ok';
464
+ }
465
+ get grpcToken() {
466
+ return this._grpcToken;
467
+ }
468
+ }
647
469
  exports.default = ConduitGrpcSdk;
470
+ ConduitGrpcSdk.Logger = new Logger_1.ConduitLogger([
471
+ new winston_1.default.transports.File({
472
+ filename: path_1.default.join(__dirname, '.logs/combined.log'),
473
+ level: 'info',
474
+ }),
475
+ new winston_1.default.transports.File({
476
+ filename: path_1.default.join(__dirname, '.logs/errors.log'),
477
+ level: 'error',
478
+ }),
479
+ ]);
648
480
  __exportStar(require("./interfaces"), exports);
649
481
  __exportStar(require("./classes"), exports);
650
482
  __exportStar(require("./modules"), exports);