@conduitplatform/grpc-sdk 0.16.0-alpha.9 → 0.16.0-rc.1
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.
- package/dist/classes/ConduitAuthorizedResource.js +5 -6
- package/dist/classes/ConduitAuthorizedResource.js.map +1 -1
- package/dist/classes/ConduitModule.d.ts +1 -2
- package/dist/classes/ConduitModule.js +69 -163
- package/dist/classes/ConduitModule.js.map +1 -1
- package/dist/classes/ConduitSchema.js +3 -4
- package/dist/classes/ConduitSchema.js.map +1 -1
- package/dist/classes/Error.js +17 -40
- package/dist/classes/Error.js.map +1 -1
- package/dist/classes/HealthCheck.js +27 -96
- package/dist/classes/HealthCheck.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +320 -464
- package/dist/index.js.map +1 -1
- package/dist/interceptors/grpcSignedToken.d.ts +1 -1
- package/dist/interceptors/grpcSignedToken.js +7 -79
- package/dist/interceptors/grpcSignedToken.js.map +1 -1
- package/dist/interceptors/moduleName.d.ts +1 -1
- package/dist/interceptors/moduleName.js +7 -79
- package/dist/interceptors/moduleName.js.map +1 -1
- package/dist/interfaces/ConduitRouteReturn.js +9 -18
- package/dist/interfaces/ConduitRouteReturn.js.map +1 -1
- package/dist/interfaces/GrpcCallback.d.ts +1 -1
- package/dist/interfaces/Indexable.d.ts +7 -7
- package/dist/interfaces/Model.d.ts +19 -16
- package/dist/interfaces/Params.d.ts +3 -3
- package/dist/interfaces/RawQuery.d.ts +2 -2
- package/dist/interfaces/Route.d.ts +12 -9
- package/dist/interfaces/Route.js.map +1 -1
- package/dist/interfaces/Socket.d.ts +1 -1
- package/dist/interfaces/UntypedArray.d.ts +1 -1
- package/dist/interfaces/types.d.ts +6 -6
- package/dist/module.proto +58 -0
- package/dist/modules/admin/index.d.ts +2 -3
- package/dist/modules/admin/index.js +13 -39
- package/dist/modules/admin/index.js.map +1 -1
- package/dist/modules/authentication/index.d.ts +6 -2
- package/dist/modules/authentication/index.js +33 -40
- package/dist/modules/authentication/index.js.map +1 -1
- package/dist/modules/authorization/index.d.ts +4 -1
- package/dist/modules/authorization/index.js +38 -47
- package/dist/modules/authorization/index.js.map +1 -1
- package/dist/modules/chat/index.js +16 -34
- package/dist/modules/chat/index.js.map +1 -1
- package/dist/modules/config/index.d.ts +12 -3
- package/dist/modules/config/index.js +85 -177
- package/dist/modules/config/index.js.map +1 -1
- package/dist/modules/core/index.js +8 -26
- package/dist/modules/core/index.js.map +1 -1
- package/dist/modules/database/index.d.ts +19 -10
- package/dist/modules/database/index.js +184 -125
- package/dist/modules/database/index.js.map +1 -1
- package/dist/modules/email/index.js +15 -33
- package/dist/modules/email/index.js.map +1 -1
- package/dist/modules/pushNotifications/index.d.ts +4 -4
- package/dist/modules/pushNotifications/index.js +38 -60
- package/dist/modules/pushNotifications/index.js.map +1 -1
- package/dist/modules/router/index.d.ts +2 -3
- package/dist/modules/router/index.js +15 -41
- package/dist/modules/router/index.js.map +1 -1
- package/dist/modules/sms/index.js +17 -35
- package/dist/modules/sms/index.js.map +1 -1
- package/dist/modules/storage/index.d.ts +7 -7
- package/dist/modules/storage/index.js +64 -55
- package/dist/modules/storage/index.js.map +1 -1
- package/dist/protoUtils/authentication.d.ts +200 -4
- package/dist/protoUtils/authentication.js +789 -194
- package/dist/protoUtils/authentication.js.map +1 -1
- package/dist/protoUtils/authorization.d.ts +185 -15
- package/dist/protoUtils/authorization.js +965 -448
- package/dist/protoUtils/authorization.js.map +1 -1
- package/dist/protoUtils/chat.d.ts +18 -7
- package/dist/protoUtils/chat.js +210 -227
- package/dist/protoUtils/chat.js.map +1 -1
- package/dist/protoUtils/core.d.ts +55 -50
- package/dist/protoUtils/core.js +1018 -902
- package/dist/protoUtils/core.js.map +1 -1
- package/dist/protoUtils/database.d.ts +262 -16
- package/dist/protoUtils/database.js +1489 -832
- package/dist/protoUtils/database.js.map +1 -1
- package/dist/protoUtils/email.d.ts +13 -4
- package/dist/protoUtils/email.js +242 -253
- package/dist/protoUtils/email.js.map +1 -1
- package/dist/protoUtils/google/protobuf/empty.d.ts +4 -3
- package/dist/protoUtils/google/protobuf/empty.js +21 -38
- package/dist/protoUtils/google/protobuf/empty.js.map +1 -1
- package/dist/protoUtils/grpc_health_check.d.ts +10 -4
- package/dist/protoUtils/grpc_health_check.js +72 -83
- package/dist/protoUtils/grpc_health_check.js.map +1 -1
- package/dist/protoUtils/module.d.ts +202 -4
- package/dist/protoUtils/module.js +810 -72
- package/dist/protoUtils/module.js.map +1 -1
- package/dist/protoUtils/push-notifications.d.ts +26 -6
- package/dist/protoUtils/push-notifications.js +381 -317
- package/dist/protoUtils/push-notifications.js.map +1 -1
- package/dist/protoUtils/router.d.ts +18 -48
- package/dist/protoUtils/router.js +502 -560
- package/dist/protoUtils/router.js.map +1 -1
- package/dist/protoUtils/sms.d.ts +16 -4
- package/dist/protoUtils/sms.js +199 -175
- package/dist/protoUtils/sms.js.map +1 -1
- package/dist/protoUtils/storage.d.ts +37 -4
- package/dist/protoUtils/storage.js +639 -318
- package/dist/protoUtils/storage.js.map +1 -1
- package/dist/types/db.d.ts +13 -11
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +6 -24
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/EventBus.d.ts +3 -1
- package/dist/utilities/EventBus.js +38 -17
- package/dist/utilities/EventBus.js.map +1 -1
- package/dist/utilities/RedisManager.js +11 -21
- package/dist/utilities/RedisManager.js.map +1 -1
- package/dist/utilities/StateManager.d.ts +9 -0
- package/dist/utilities/StateManager.js +58 -15
- package/dist/utilities/StateManager.js.map +1 -1
- package/dist/utilities/env.js +4 -4
- package/dist/utilities/env.js.map +1 -1
- package/dist/utilities/sleep.js +1 -1
- package/dist/utilities/sleep.js.map +1 -1
- package/package.json +26 -19
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,58 +13,20 @@ 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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (watchModules === void 0) { watchModules = true; }
|
|
78
|
-
if (serviceHealthStatusGetter === void 0) { serviceHealthStatusGetter = function () { return types_1.HealthCheckStatus.SERVING; }; }
|
|
20
|
+
const modules_1 = require("./modules");
|
|
21
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
22
|
+
const utilities_1 = require("./utilities");
|
|
23
|
+
const classes_1 = require("./classes");
|
|
24
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
25
|
+
const protoUtils_1 = require("./protoUtils");
|
|
26
|
+
const types_1 = require("./types");
|
|
27
|
+
const fast_jwt_1 = require("fast-jwt");
|
|
28
|
+
class ConduitGrpcSdk {
|
|
29
|
+
constructor(serverUrl, name, watchModules = true, logger, serviceHealthStatusGetter = () => types_1.HealthCheckStatus.SERVING) {
|
|
79
30
|
this._modules = {};
|
|
80
31
|
this._availableModules = {
|
|
81
32
|
router: modules_1.Router,
|
|
@@ -107,346 +58,253 @@ var ConduitGrpcSdk = /** @class */ (function () {
|
|
|
107
58
|
this.instance = this.name.startsWith('module_')
|
|
108
59
|
? this.name.substring(8)
|
|
109
60
|
: crypto_1.default.randomBytes(16).toString('hex');
|
|
110
|
-
this.urlRemap = (0, utilities_1.getJsonEnv)('URL_REMAP', process.env.URL_REMAP,
|
|
61
|
+
this.urlRemap = (0, utilities_1.getJsonEnv)('URL_REMAP', process.env.URL_REMAP, stringConf => ({
|
|
111
62
|
'*': stringConf,
|
|
112
|
-
})
|
|
63
|
+
}));
|
|
113
64
|
this.serverUrl = serverUrl;
|
|
114
65
|
this._watchModules = watchModules;
|
|
115
66
|
this._serviceHealthStatusGetter = serviceHealthStatusGetter;
|
|
116
67
|
if (process.env.GRPC_KEY) {
|
|
117
|
-
|
|
68
|
+
const sign = (0, fast_jwt_1.createSigner)({ key: process.env.GRPC_KEY });
|
|
118
69
|
this._grpcToken = sign({
|
|
119
70
|
moduleName: this.name,
|
|
120
71
|
});
|
|
121
72
|
}
|
|
122
73
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return this.
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (this._modules['email']) {
|
|
267
|
-
return this._modules['email'];
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
ConduitGrpcSdk.Logger.warn('Email provider not up yet!');
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
enumerable: false,
|
|
275
|
-
configurable: true
|
|
276
|
-
});
|
|
277
|
-
Object.defineProperty(ConduitGrpcSdk.prototype, "pushNotifications", {
|
|
278
|
-
get: function () {
|
|
279
|
-
if (this._modules['pushNotifications']) {
|
|
280
|
-
return this._modules['pushNotifications'];
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
ConduitGrpcSdk.Logger.warn('Push notifications module not up yet!');
|
|
284
|
-
return null;
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
enumerable: false,
|
|
288
|
-
configurable: true
|
|
289
|
-
});
|
|
290
|
-
Object.defineProperty(ConduitGrpcSdk.prototype, "authentication", {
|
|
291
|
-
get: function () {
|
|
292
|
-
if (this._modules['authentication']) {
|
|
293
|
-
return this._modules['authentication'];
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
ConduitGrpcSdk.Logger.warn('Authentication module not up yet!');
|
|
297
|
-
return null;
|
|
298
|
-
}
|
|
299
|
-
},
|
|
300
|
-
enumerable: false,
|
|
301
|
-
configurable: true
|
|
302
|
-
});
|
|
303
|
-
Object.defineProperty(ConduitGrpcSdk.prototype, "authorization", {
|
|
304
|
-
get: function () {
|
|
305
|
-
if (this._modules['authorization']) {
|
|
306
|
-
return this._modules['authorization'];
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
ConduitGrpcSdk.Logger.warn('Authorization module not up yet!');
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
enumerable: false,
|
|
314
|
-
configurable: true
|
|
315
|
-
});
|
|
316
|
-
Object.defineProperty(ConduitGrpcSdk.prototype, "sms", {
|
|
317
|
-
get: function () {
|
|
318
|
-
if (this._modules['sms']) {
|
|
319
|
-
return this._modules['sms'];
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
ConduitGrpcSdk.Logger.warn('SMS module not up yet!');
|
|
323
|
-
return null;
|
|
324
|
-
}
|
|
325
|
-
},
|
|
326
|
-
enumerable: false,
|
|
327
|
-
configurable: true
|
|
328
|
-
});
|
|
329
|
-
Object.defineProperty(ConduitGrpcSdk.prototype, "chat", {
|
|
330
|
-
get: function () {
|
|
331
|
-
if (this._modules['chat']) {
|
|
332
|
-
return this._modules['chat'];
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
ConduitGrpcSdk.Logger.warn('Chat module not up yet!');
|
|
336
|
-
return null;
|
|
337
|
-
}
|
|
338
|
-
},
|
|
339
|
-
enumerable: false,
|
|
340
|
-
configurable: true
|
|
341
|
-
});
|
|
342
|
-
Object.defineProperty(ConduitGrpcSdk.prototype, "grpcToken", {
|
|
343
|
-
get: function () {
|
|
344
|
-
return this._grpcToken;
|
|
345
|
-
},
|
|
346
|
-
enumerable: false,
|
|
347
|
-
configurable: true
|
|
348
|
-
});
|
|
349
|
-
ConduitGrpcSdk.prototype.addMiddleware = function (middleware) {
|
|
74
|
+
static get Logger() {
|
|
75
|
+
return ConduitGrpcSdk._Logger;
|
|
76
|
+
}
|
|
77
|
+
static get Metrics() {
|
|
78
|
+
return ConduitGrpcSdk._Metrics;
|
|
79
|
+
}
|
|
80
|
+
static set Metrics(metrics) {
|
|
81
|
+
ConduitGrpcSdk._Metrics = metrics;
|
|
82
|
+
}
|
|
83
|
+
static get interceptors() {
|
|
84
|
+
return ConduitGrpcSdk.middleware;
|
|
85
|
+
}
|
|
86
|
+
get redisManager() {
|
|
87
|
+
if (this._redisManager) {
|
|
88
|
+
return this._redisManager;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error('Redis not available');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
get redisDetails() {
|
|
95
|
+
if (this._redisDetails) {
|
|
96
|
+
return this._redisDetails;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
throw new Error('Redis not available');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
get bus() {
|
|
103
|
+
if (this._eventBus) {
|
|
104
|
+
return this._eventBus;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
ConduitGrpcSdk.Logger.warn('Event bus not initialized');
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
get state() {
|
|
112
|
+
if (this._stateManager) {
|
|
113
|
+
return this._stateManager;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
ConduitGrpcSdk.Logger.warn('State Manager not initialized');
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
get core() {
|
|
121
|
+
return this._core;
|
|
122
|
+
}
|
|
123
|
+
get config() {
|
|
124
|
+
return this._config;
|
|
125
|
+
}
|
|
126
|
+
get admin() {
|
|
127
|
+
return this._admin;
|
|
128
|
+
}
|
|
129
|
+
get router() {
|
|
130
|
+
if (this._modules['router']) {
|
|
131
|
+
return this._modules['router'];
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
ConduitGrpcSdk.Logger.warn('Router not up yet!');
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
get database() {
|
|
139
|
+
if (this._modules['database']) {
|
|
140
|
+
return this._modules['database'];
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
ConduitGrpcSdk.Logger.warn('Database provider not up yet!');
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
get databaseProvider() {
|
|
148
|
+
return this.database;
|
|
149
|
+
}
|
|
150
|
+
get storage() {
|
|
151
|
+
if (this._modules['storage']) {
|
|
152
|
+
return this._modules['storage'];
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
ConduitGrpcSdk.Logger.warn('Storage module not up yet!');
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
get emailProvider() {
|
|
160
|
+
if (this._modules['email']) {
|
|
161
|
+
return this._modules['email'];
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
ConduitGrpcSdk.Logger.warn('Email provider not up yet!');
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
get pushNotifications() {
|
|
169
|
+
if (this._modules['pushNotifications']) {
|
|
170
|
+
return this._modules['pushNotifications'];
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
ConduitGrpcSdk.Logger.warn('Push notifications module not up yet!');
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
get authentication() {
|
|
178
|
+
if (this._modules['authentication']) {
|
|
179
|
+
return this._modules['authentication'];
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
ConduitGrpcSdk.Logger.warn('Authentication module not up yet!');
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
get authorization() {
|
|
187
|
+
if (this._modules['authorization']) {
|
|
188
|
+
return this._modules['authorization'];
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
ConduitGrpcSdk.Logger.warn('Authorization module not up yet!');
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
get sms() {
|
|
196
|
+
if (this._modules['sms']) {
|
|
197
|
+
return this._modules['sms'];
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
ConduitGrpcSdk.Logger.warn('SMS module not up yet!');
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
get chat() {
|
|
205
|
+
if (this._modules['chat']) {
|
|
206
|
+
return this._modules['chat'];
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
ConduitGrpcSdk.Logger.warn('Chat module not up yet!');
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
get grpcToken() {
|
|
214
|
+
return this._grpcToken;
|
|
215
|
+
}
|
|
216
|
+
addMiddleware(middleware) {
|
|
350
217
|
ConduitGrpcSdk.middleware.push(middleware);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
return [4 /*yield*/, this.core.check()];
|
|
370
|
-
case 3:
|
|
371
|
-
state = _a.sent();
|
|
372
|
-
if (state === types_1.HealthCheckStatus.SERVING) {
|
|
373
|
-
ConduitGrpcSdk.Logger.log('Core connection established');
|
|
374
|
-
this._initialize();
|
|
375
|
-
return [3 /*break*/, 7];
|
|
376
|
-
}
|
|
377
|
-
return [3 /*break*/, 6];
|
|
378
|
-
case 4:
|
|
379
|
-
err_1 = _a.sent();
|
|
380
|
-
if (err_1.code === grpc_js_1.status.PERMISSION_DENIED) {
|
|
381
|
-
ConduitGrpcSdk.Logger.error(err_1);
|
|
382
|
-
process.exit(-1);
|
|
383
|
-
}
|
|
384
|
-
return [4 /*yield*/, (0, utilities_1.sleep)(1000)];
|
|
385
|
-
case 5:
|
|
386
|
-
_a.sent();
|
|
387
|
-
return [3 /*break*/, 6];
|
|
388
|
-
case 6: return [3 /*break*/, 1];
|
|
389
|
-
case 7: return [2 /*return*/];
|
|
218
|
+
}
|
|
219
|
+
async initialize() {
|
|
220
|
+
if (this.name === 'core') {
|
|
221
|
+
return this._initialize();
|
|
222
|
+
}
|
|
223
|
+
this._core = new modules_1.Core(this.name, this.serverUrl, this._grpcToken);
|
|
224
|
+
await this.connectToCore().catch(() => process.exit(-1));
|
|
225
|
+
this._initialize();
|
|
226
|
+
}
|
|
227
|
+
async connectToCore() {
|
|
228
|
+
ConduitGrpcSdk.Logger.log('Waiting for Core...');
|
|
229
|
+
while (true) {
|
|
230
|
+
try {
|
|
231
|
+
this.core.openConnection();
|
|
232
|
+
const state = await this.core.check();
|
|
233
|
+
if (state === types_1.HealthCheckStatus.SERVING) {
|
|
234
|
+
ConduitGrpcSdk.Logger.log('Core connection established');
|
|
235
|
+
return;
|
|
390
236
|
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
if (err.code === grpc_js_1.status.PERMISSION_DENIED) {
|
|
240
|
+
ConduitGrpcSdk.Logger.error(err);
|
|
241
|
+
throw err;
|
|
242
|
+
}
|
|
243
|
+
await (0, utilities_1.sleep)(1000);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
watchModules() {
|
|
248
|
+
const emitter = this.config.getModuleWatcher();
|
|
397
249
|
this.config.watchModules().then();
|
|
398
|
-
emitter.on('serving-modules-update',
|
|
399
|
-
Object.keys(
|
|
250
|
+
emitter.on('serving-modules-update', modules => {
|
|
251
|
+
Object.keys(this._modules).forEach(r => {
|
|
400
252
|
var _a;
|
|
401
|
-
if (r
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
253
|
+
if (r === this.name)
|
|
254
|
+
return;
|
|
255
|
+
const found = modules.filter((m) => m.moduleName === r && m.serving);
|
|
256
|
+
if ((!found || found.length === 0) && this._modules[r]) {
|
|
257
|
+
(_a = this._modules[r]) === null || _a === void 0 ? void 0 : _a.closeConnection();
|
|
258
|
+
emitter.emit(`module-connection-update:${r}`, false);
|
|
407
259
|
}
|
|
408
260
|
});
|
|
409
|
-
modules.forEach(
|
|
261
|
+
modules.forEach((m) => {
|
|
410
262
|
var _a;
|
|
411
|
-
if (m.moduleName
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
263
|
+
if (m.moduleName === this.name || !m.serving)
|
|
264
|
+
return;
|
|
265
|
+
const alreadyActive = (_a = this._modules[m.moduleName]) === null || _a === void 0 ? void 0 : _a.active;
|
|
266
|
+
if (alreadyActive)
|
|
267
|
+
return;
|
|
268
|
+
if (this._availableModules[m.moduleName] && this._modules[m.moduleName]) {
|
|
269
|
+
this._modules[m.moduleName].openConnection();
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
this.createModuleClient(m.moduleName, m.url);
|
|
422
273
|
}
|
|
274
|
+
emitter.emit(`module-connection-update:${m.moduleName}`, true);
|
|
423
275
|
});
|
|
424
276
|
});
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
277
|
+
emitter.on('core-status-update', () => {
|
|
278
|
+
this.connectToCore()
|
|
279
|
+
.then(() => {
|
|
280
|
+
this._initialize();
|
|
281
|
+
})
|
|
282
|
+
.catch(() => {
|
|
283
|
+
process.exit(-1);
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
monitorModule(moduleName, callback, wait = true) {
|
|
288
|
+
const waitPromise = wait ? this.waitForExistence(moduleName) : Promise.resolve();
|
|
430
289
|
waitPromise
|
|
431
|
-
.then(
|
|
432
|
-
.then(
|
|
290
|
+
.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({}); })
|
|
291
|
+
.then(res => {
|
|
433
292
|
callback((res === null || res === void 0 ? void 0 : res.status) === protoUtils_1.HealthCheckResponse_ServingStatus.SERVING);
|
|
434
293
|
})
|
|
435
|
-
.catch(
|
|
294
|
+
.catch(() => {
|
|
436
295
|
callback(false);
|
|
437
296
|
})
|
|
438
|
-
.then(
|
|
439
|
-
|
|
440
|
-
emitter.on(
|
|
297
|
+
.then(() => {
|
|
298
|
+
const emitter = this.config.getModuleWatcher();
|
|
299
|
+
emitter.on(`module-connection-update:${moduleName}`, callback);
|
|
441
300
|
});
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
emitter.removeAllListeners(
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
var promise = Promise.resolve();
|
|
301
|
+
}
|
|
302
|
+
unmonitorModule(moduleName) {
|
|
303
|
+
const emitter = this.config.getModuleWatcher();
|
|
304
|
+
emitter.removeAllListeners(`module-connection-update:${moduleName}`);
|
|
305
|
+
}
|
|
306
|
+
initializeEventBus() {
|
|
307
|
+
let promise = Promise.resolve();
|
|
450
308
|
if (process.env.REDIS_CONFIG) {
|
|
451
309
|
this._redisDetails = (0, utilities_1.getJsonEnv)('REDIS_CONFIG');
|
|
452
310
|
}
|
|
@@ -454,72 +312,76 @@ var ConduitGrpcSdk = /** @class */ (function () {
|
|
|
454
312
|
this._redisDetails = {
|
|
455
313
|
host: process.env.REDIS_HOST,
|
|
456
314
|
port: parseInt(process.env.REDIS_PORT, 10),
|
|
457
|
-
|
|
458
|
-
|
|
315
|
+
db: parseInt(process.env.REDIS_DB, 10) || 0,
|
|
316
|
+
...(process.env.REDIS_USERNAME ? { username: process.env.REDIS_USERNAME } : {}),
|
|
317
|
+
...(process.env.REDIS_PASSWORD ? { password: process.env.REDIS_PASSWORD } : {}),
|
|
459
318
|
};
|
|
460
319
|
}
|
|
461
320
|
else {
|
|
462
321
|
promise = promise
|
|
463
|
-
.then(
|
|
464
|
-
.then(
|
|
465
|
-
if (r.
|
|
466
|
-
|
|
322
|
+
.then(() => this.config.getRedisDetails())
|
|
323
|
+
.then(r => {
|
|
324
|
+
if (r.standalone) {
|
|
325
|
+
this._redisDetails = r.standalone;
|
|
467
326
|
}
|
|
468
327
|
else {
|
|
469
|
-
|
|
470
|
-
host: r.redisHost,
|
|
471
|
-
port: r.redisPort,
|
|
472
|
-
username: r.redisUsername,
|
|
473
|
-
password: r.redisPassword,
|
|
474
|
-
};
|
|
328
|
+
this._redisDetails = r.cluster;
|
|
475
329
|
}
|
|
476
330
|
});
|
|
477
331
|
}
|
|
478
332
|
return promise
|
|
479
|
-
.then(
|
|
480
|
-
if (
|
|
481
|
-
|
|
333
|
+
.then(() => {
|
|
334
|
+
if (this._redisDetails.hasOwnProperty('nodes')) {
|
|
335
|
+
this._redisManager = new utilities_1.RedisManager(this._redisDetails);
|
|
482
336
|
}
|
|
483
337
|
else {
|
|
484
|
-
|
|
485
|
-
|
|
338
|
+
const redisHost = this._redisDetails.host;
|
|
339
|
+
this._redisManager = new utilities_1.RedisManager({
|
|
340
|
+
...this._redisDetails,
|
|
341
|
+
host: redisHost,
|
|
342
|
+
});
|
|
486
343
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
return
|
|
344
|
+
this._eventBus = new utilities_1.EventBus(this._redisManager);
|
|
345
|
+
this._stateManager = new utilities_1.StateManager(this._redisManager, this.name);
|
|
346
|
+
return this._eventBus;
|
|
490
347
|
})
|
|
491
|
-
.catch(
|
|
348
|
+
.catch((err) => {
|
|
492
349
|
ConduitGrpcSdk.Logger.error('Failed to initialize event bus');
|
|
493
350
|
throw err;
|
|
494
351
|
});
|
|
495
|
-
}
|
|
352
|
+
}
|
|
496
353
|
/**
|
|
497
354
|
* Gets all the registered modules from the config and creates clients for them.
|
|
498
355
|
* This will only work on known modules, since the primary usage for the sdk is internal
|
|
499
356
|
*/
|
|
500
|
-
|
|
501
|
-
var _this = this;
|
|
357
|
+
initializeModules() {
|
|
502
358
|
return this._config.moduleList()
|
|
503
|
-
.then(
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
359
|
+
.then(r => {
|
|
360
|
+
const emitter = this.config.getModuleWatcher();
|
|
361
|
+
this.lastSearch = Date.now();
|
|
362
|
+
r.forEach(m => {
|
|
363
|
+
this.createModuleClient(m.moduleName, m.url);
|
|
364
|
+
emitter.emit(`module-connection-update:${m.moduleName}`, m.serving);
|
|
507
365
|
});
|
|
508
366
|
return 'ok';
|
|
509
367
|
})
|
|
510
|
-
.catch(
|
|
368
|
+
.catch(err => {
|
|
511
369
|
if (err.code !== 5) {
|
|
512
370
|
ConduitGrpcSdk.Logger.error(err);
|
|
513
371
|
}
|
|
514
372
|
});
|
|
515
|
-
}
|
|
516
|
-
|
|
373
|
+
}
|
|
374
|
+
updateModuleHealth(moduleName, serving) {
|
|
375
|
+
const emitter = this.config.getModuleWatcher();
|
|
376
|
+
emitter.emit(`module-connection-update:${moduleName}`, serving);
|
|
377
|
+
}
|
|
378
|
+
createModuleClient(moduleName, moduleUrl) {
|
|
517
379
|
var _a, _b, _c;
|
|
518
380
|
if (this._modules[moduleName])
|
|
519
381
|
return;
|
|
520
382
|
moduleUrl =
|
|
521
383
|
(_b = (_a = this.urlRemap) === null || _a === void 0 ? void 0 : _a[moduleUrl]) !== null && _b !== void 0 ? _b : (((_c = this.urlRemap) === null || _c === void 0 ? void 0 : _c['*'])
|
|
522
|
-
?
|
|
384
|
+
? `${this.urlRemap['*']}:${moduleUrl.split(':')[1]}`
|
|
523
385
|
: moduleUrl);
|
|
524
386
|
if (this._availableModules[moduleName]) {
|
|
525
387
|
// ConduitGrpcSdk.Logger.log(`Creating gRPC client for ${moduleName}`);
|
|
@@ -536,79 +398,74 @@ var ConduitGrpcSdk = /** @class */ (function () {
|
|
|
536
398
|
this._modules[moduleName] = new classes_1.ConduitModule(this.name, moduleName, moduleUrl, this._grpcToken);
|
|
537
399
|
this._modules[moduleName].initializeClient(protoUtils_1.ConduitModuleDefinition);
|
|
538
400
|
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
if (service === void 0) { service = ''; }
|
|
401
|
+
}
|
|
402
|
+
isModuleUp(moduleName, moduleUrl, service = '') {
|
|
542
403
|
return (0, classes_1.checkModuleHealth)(moduleName, moduleUrl, service, this._grpcToken);
|
|
543
|
-
}
|
|
544
|
-
|
|
404
|
+
}
|
|
405
|
+
moduleClient(name, type) {
|
|
545
406
|
this._dynamicModules[name] = type;
|
|
546
|
-
}
|
|
547
|
-
|
|
407
|
+
}
|
|
408
|
+
getModule(name) {
|
|
548
409
|
return this._modules[name];
|
|
549
|
-
}
|
|
550
|
-
|
|
410
|
+
}
|
|
411
|
+
getServiceClient(name) {
|
|
551
412
|
var _a;
|
|
552
413
|
return (_a = this._modules[name]) === null || _a === void 0 ? void 0 : _a.client;
|
|
553
|
-
}
|
|
554
|
-
|
|
414
|
+
}
|
|
415
|
+
getModuleClient(name) {
|
|
555
416
|
var _a;
|
|
556
417
|
return (_a = this._modules[name]) === null || _a === void 0 ? void 0 : _a.moduleClient;
|
|
557
|
-
}
|
|
558
|
-
|
|
418
|
+
}
|
|
419
|
+
getHealthClient(name) {
|
|
559
420
|
var _a;
|
|
560
421
|
return (_a = this._modules[name]) === null || _a === void 0 ? void 0 : _a.healthClient;
|
|
561
|
-
}
|
|
562
|
-
|
|
422
|
+
}
|
|
423
|
+
isAvailable(moduleName) {
|
|
563
424
|
var _a;
|
|
564
425
|
return !!((_a = this._modules[moduleName]) === null || _a === void 0 ? void 0 : _a.active);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
return
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return [3 /*break*/, 0];
|
|
576
|
-
case 2: return [2 /*return*/, true];
|
|
426
|
+
}
|
|
427
|
+
async waitForExistence(moduleName, onlyIfServing = true) {
|
|
428
|
+
if (this.isAvailable(moduleName))
|
|
429
|
+
return true;
|
|
430
|
+
const emitter = this.config.getModuleWatcher();
|
|
431
|
+
return new Promise(resolve => {
|
|
432
|
+
const listener = (serving) => {
|
|
433
|
+
if (!onlyIfServing || (onlyIfServing && serving)) {
|
|
434
|
+
emitter.removeListener(`module-connection-update:${moduleName}`, listener);
|
|
435
|
+
return resolve(true);
|
|
577
436
|
}
|
|
578
|
-
}
|
|
437
|
+
};
|
|
438
|
+
emitter.on(`module-connection-update:${moduleName}`, listener);
|
|
579
439
|
});
|
|
580
|
-
}
|
|
581
|
-
|
|
440
|
+
}
|
|
441
|
+
onceModuleUp(moduleName, callback) {
|
|
582
442
|
if (this.isAvailable(moduleName))
|
|
583
443
|
callback();
|
|
584
|
-
|
|
585
|
-
emitter.once(
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
emitter.once("module-connection-update:".concat(moduleName), function (serving) {
|
|
592
|
-
return serving ? null : callback();
|
|
593
|
-
});
|
|
594
|
-
};
|
|
444
|
+
const emitter = this.config.getModuleWatcher();
|
|
445
|
+
emitter.once(`module-connection-update:${moduleName}`, (serving) => serving ? callback() : null);
|
|
446
|
+
}
|
|
447
|
+
onceModuleDown(moduleName, callback) {
|
|
448
|
+
const emitter = this.config.getModuleWatcher();
|
|
449
|
+
emitter.once(`module-connection-update:${moduleName}`, (serving) => serving ? null : callback());
|
|
450
|
+
}
|
|
595
451
|
/**
|
|
596
452
|
* Used to refresh all modules to check for new registrations
|
|
597
453
|
* @param force If true will check for new modules no matter the interval
|
|
598
454
|
*/
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
return
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
455
|
+
async refreshModules(force) {
|
|
456
|
+
if (this.lastSearch < Date.now() - 3000 || force) {
|
|
457
|
+
return this.initializeModules();
|
|
458
|
+
}
|
|
459
|
+
return 'ok';
|
|
460
|
+
}
|
|
461
|
+
_initialize() {
|
|
462
|
+
var _a, _b;
|
|
463
|
+
if (this._initialized) {
|
|
464
|
+
(_a = this._config) === null || _a === void 0 ? void 0 : _a.openConnection();
|
|
465
|
+
(_b = this._admin) === null || _b === void 0 ? void 0 : _b.openConnection();
|
|
466
|
+
this.config.watchModules().then();
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
612
469
|
this._config = new modules_1.Config(this.name, this.serverUrl, this._serviceHealthStatusGetter, this._grpcToken);
|
|
613
470
|
this._admin = new modules_1.Admin(this.name, this.serverUrl, this._grpcToken);
|
|
614
471
|
if (this.name !== 'core') {
|
|
@@ -618,11 +475,10 @@ var ConduitGrpcSdk = /** @class */ (function () {
|
|
|
618
475
|
this.watchModules();
|
|
619
476
|
}
|
|
620
477
|
this._initialized = true;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}());
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
ConduitGrpcSdk.middleware = [];
|
|
481
|
+
ConduitGrpcSdk._Metrics = undefined;
|
|
626
482
|
exports.default = ConduitGrpcSdk;
|
|
627
483
|
__exportStar(require("./interfaces"), exports);
|
|
628
484
|
__exportStar(require("./classes"), exports);
|