@conduitplatform/grpc-sdk 0.13.0-rc0
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/README.md +20 -0
- package/dist/classes/ConduitActiveSchema.d.ts +19 -0
- package/dist/classes/ConduitActiveSchema.js +57 -0
- package/dist/classes/ConduitActiveSchema.js.map +1 -0
- package/dist/classes/ConduitMiddleware.d.ts +8 -0
- package/dist/classes/ConduitMiddleware.js +26 -0
- package/dist/classes/ConduitMiddleware.js.map +1 -0
- package/dist/classes/ConduitModule.d.ts +26 -0
- package/dist/classes/ConduitModule.js +170 -0
- package/dist/classes/ConduitModule.js.map +1 -0
- package/dist/classes/ConduitParser.d.ts +20 -0
- package/dist/classes/ConduitParser.js +84 -0
- package/dist/classes/ConduitParser.js.map +1 -0
- package/dist/classes/ConduitRoute.d.ts +12 -0
- package/dist/classes/ConduitRoute.js +44 -0
- package/dist/classes/ConduitRoute.js.map +1 -0
- package/dist/classes/ConduitRouteReturn.d.ts +48 -0
- package/dist/classes/ConduitRouteReturn.js +66 -0
- package/dist/classes/ConduitRouteReturn.js.map +1 -0
- package/dist/classes/ConduitSchema.d.ts +10 -0
- package/dist/classes/ConduitSchema.js +22 -0
- package/dist/classes/ConduitSchema.js.map +1 -0
- package/dist/classes/ConduitSchemaExtension.d.ts +7 -0
- package/dist/classes/ConduitSchemaExtension.js +19 -0
- package/dist/classes/ConduitSchemaExtension.js.map +1 -0
- package/dist/classes/ConduitServiceModule.d.ts +25 -0
- package/dist/classes/ConduitServiceModule.js +139 -0
- package/dist/classes/ConduitServiceModule.js.map +1 -0
- package/dist/classes/ConduitSocket.d.ts +9 -0
- package/dist/classes/ConduitSocket.js +27 -0
- package/dist/classes/ConduitSocket.js.map +1 -0
- package/dist/classes/ConfigController.d.ts +7 -0
- package/dist/classes/ConfigController.js +27 -0
- package/dist/classes/ConfigController.js.map +1 -0
- package/dist/classes/Error.d.ts +11 -0
- package/dist/classes/Error.js +51 -0
- package/dist/classes/Error.js.map +1 -0
- package/dist/classes/GrpcServer.d.ts +19 -0
- package/dist/classes/GrpcServer.js +185 -0
- package/dist/classes/GrpcServer.js.map +1 -0
- package/dist/classes/ManagedModule.d.ts +20 -0
- package/dist/classes/ManagedModule.js +212 -0
- package/dist/classes/ManagedModule.js.map +1 -0
- package/dist/classes/ModuleManager.d.ts +11 -0
- package/dist/classes/ModuleManager.js +191 -0
- package/dist/classes/ModuleManager.js.map +1 -0
- package/dist/classes/Routing/RouteBuilder.d.ts +28 -0
- package/dist/classes/Routing/RouteBuilder.js +107 -0
- package/dist/classes/Routing/RouteBuilder.js.map +1 -0
- package/dist/classes/Routing/RoutingManager.d.ts +25 -0
- package/dist/classes/Routing/RoutingManager.js +193 -0
- package/dist/classes/Routing/RoutingManager.js.map +1 -0
- package/dist/classes/index.d.ts +16 -0
- package/dist/classes/index.js +29 -0
- package/dist/classes/index.js.map +1 -0
- package/dist/constants/enums/PlatformTypesEnum.d.ts +9 -0
- package/dist/constants/enums/PlatformTypesEnum.js +14 -0
- package/dist/constants/enums/PlatformTypesEnum.js.map +1 -0
- package/dist/constants/enums/index.d.ts +1 -0
- package/dist/constants/enums/index.js +14 -0
- package/dist/constants/enums/index.js.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +14 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/helpers/GrpcHelper.d.ts +8 -0
- package/dist/helpers/GrpcHelper.js +44 -0
- package/dist/helpers/GrpcHelper.js.map +1 -0
- package/dist/helpers/RoutingJsonConstructor.d.ts +9 -0
- package/dist/helpers/RoutingJsonConstructor.js +89 -0
- package/dist/helpers/RoutingJsonConstructor.js.map +1 -0
- package/dist/helpers/RoutingUtilities.d.ts +13 -0
- package/dist/helpers/RoutingUtilities.js +69 -0
- package/dist/helpers/RoutingUtilities.js.map +1 -0
- package/dist/helpers/TypeHelpers.d.ts +44 -0
- package/dist/helpers/TypeHelpers.js +144 -0
- package/dist/helpers/TypeHelpers.js.map +1 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +18 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/wrapGrpcFunctions.d.ts +5 -0
- package/dist/helpers/wrapGrpcFunctions.js +37 -0
- package/dist/helpers/wrapGrpcFunctions.js.map +1 -0
- package/dist/helpers/wrapRouterFunctions.d.ts +7 -0
- package/dist/helpers/wrapRouterFunctions.js +111 -0
- package/dist/helpers/wrapRouterFunctions.js.map +1 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +481 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/grpcSignedToken.d.ts +2 -0
- package/dist/interceptors/grpcSignedToken.js +88 -0
- package/dist/interceptors/grpcSignedToken.js.map +1 -0
- package/dist/interceptors/index.d.ts +2 -0
- package/dist/interceptors/index.js +15 -0
- package/dist/interceptors/index.js.map +1 -0
- package/dist/interceptors/moduleName.d.ts +2 -0
- package/dist/interceptors/moduleName.js +88 -0
- package/dist/interceptors/moduleName.js.map +1 -0
- package/dist/interfaces/ConduitService.d.ts +8 -0
- package/dist/interfaces/ConduitService.js +3 -0
- package/dist/interfaces/ConduitService.js.map +1 -0
- package/dist/interfaces/GrpcCallback.d.ts +4 -0
- package/dist/interfaces/GrpcCallback.js +3 -0
- package/dist/interfaces/GrpcCallback.js.map +1 -0
- package/dist/interfaces/Indexable.d.ts +9 -0
- package/dist/interfaces/Indexable.js +3 -0
- package/dist/interfaces/Indexable.js.map +1 -0
- package/dist/interfaces/Middleware.d.ts +7 -0
- package/dist/interfaces/Middleware.js +3 -0
- package/dist/interfaces/Middleware.js.map +1 -0
- package/dist/interfaces/Model.d.ts +37 -0
- package/dist/interfaces/Model.js +19 -0
- package/dist/interfaces/Model.js.map +1 -0
- package/dist/interfaces/Route.d.ts +54 -0
- package/dist/interfaces/Route.js +21 -0
- package/dist/interfaces/Route.js.map +1 -0
- package/dist/interfaces/Socket.d.ts +34 -0
- package/dist/interfaces/Socket.js +9 -0
- package/dist/interfaces/Socket.js.map +1 -0
- package/dist/interfaces/index.d.ts +7 -0
- package/dist/interfaces/index.js +20 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/modules/admin/index.d.ts +13 -0
- package/dist/modules/admin/index.js +131 -0
- package/dist/modules/admin/index.js.map +1 -0
- package/dist/modules/authentication/index.d.ts +11 -0
- package/dist/modules/authentication/index.js +50 -0
- package/dist/modules/authentication/index.js.map +1 -0
- package/dist/modules/chat/index.d.ts +10 -0
- package/dist/modules/chat/index.js +46 -0
- package/dist/modules/chat/index.js.map +1 -0
- package/dist/modules/config/index.d.ts +25 -0
- package/dist/modules/config/index.js +234 -0
- package/dist/modules/config/index.js.map +1 -0
- package/dist/modules/core/index.d.ts +6 -0
- package/dist/modules/core/index.js +32 -0
- package/dist/modules/core/index.js.map +1 -0
- package/dist/modules/database/index.d.ts +30 -0
- package/dist/modules/database/index.js +201 -0
- package/dist/modules/database/index.js.map +1 -0
- package/dist/modules/email/index.d.ts +21 -0
- package/dist/modules/email/index.js +63 -0
- package/dist/modules/email/index.js.map +1 -0
- package/dist/modules/forms/index.d.ts +7 -0
- package/dist/modules/forms/index.js +37 -0
- package/dist/modules/forms/index.js.map +1 -0
- package/dist/modules/index.d.ts +11 -0
- package/dist/modules/index.js +24 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/pushNotifications/index.d.ts +10 -0
- package/dist/modules/pushNotifications/index.js +63 -0
- package/dist/modules/pushNotifications/index.js.map +1 -0
- package/dist/modules/router/index.d.ts +8 -0
- package/dist/modules/router/index.js +43 -0
- package/dist/modules/router/index.js.map +1 -0
- package/dist/modules/sms/index.d.ts +10 -0
- package/dist/modules/sms/index.js +46 -0
- package/dist/modules/sms/index.js.map +1 -0
- package/dist/modules/storage/index.d.ts +10 -0
- package/dist/modules/storage/index.js +47 -0
- package/dist/modules/storage/index.js.map +1 -0
- package/dist/protoUtils/authentication.d.ts +209 -0
- package/dist/protoUtils/authentication.js +533 -0
- package/dist/protoUtils/authentication.js.map +1 -0
- package/dist/protoUtils/chat.d.ts +178 -0
- package/dist/protoUtils/chat.js +534 -0
- package/dist/protoUtils/chat.js.map +1 -0
- package/dist/protoUtils/core.d.ts +607 -0
- package/dist/protoUtils/core.js +1883 -0
- package/dist/protoUtils/core.js.map +1 -0
- package/dist/protoUtils/database.d.ts +496 -0
- package/dist/protoUtils/database.js +1275 -0
- package/dist/protoUtils/database.js.map +1 -0
- package/dist/protoUtils/email.d.ts +153 -0
- package/dist/protoUtils/email.js +543 -0
- package/dist/protoUtils/email.js.map +1 -0
- package/dist/protoUtils/forms.d.ts +54 -0
- package/dist/protoUtils/forms.js +141 -0
- package/dist/protoUtils/forms.js.map +1 -0
- package/dist/protoUtils/grpc_health_check.d.ts +83 -0
- package/dist/protoUtils/grpc_health_check.js +197 -0
- package/dist/protoUtils/grpc_health_check.js.map +1 -0
- package/dist/protoUtils/push-notifications.d.ts +179 -0
- package/dist/protoUtils/push-notifications.js +512 -0
- package/dist/protoUtils/push-notifications.js.map +1 -0
- package/dist/protoUtils/sms.d.ts +176 -0
- package/dist/protoUtils/sms.js +459 -0
- package/dist/protoUtils/sms.js.map +1 -0
- package/dist/protoUtils/storage.d.ts +203 -0
- package/dist/protoUtils/storage.js +522 -0
- package/dist/protoUtils/storage.js.map +1 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/index.js +37 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utilities/EventBus.d.ts +10 -0
- package/dist/utilities/EventBus.js +52 -0
- package/dist/utilities/EventBus.js.map +1 -0
- package/dist/utilities/RedisManager.d.ts +6 -0
- package/dist/utilities/RedisManager.js +32 -0
- package/dist/utilities/RedisManager.js.map +1 -0
- package/dist/utilities/StateManager.d.ts +10 -0
- package/dist/utilities/StateManager.js +31 -0
- package/dist/utilities/StateManager.js.map +1 -0
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.js +10 -0
- package/dist/utilities/index.js.map +1 -0
- package/package.json +56 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
49
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
50
|
+
};
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
var modules_1 = require("./modules");
|
|
53
|
+
var authentication_1 = require("./modules/authentication");
|
|
54
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
55
|
+
var EventBus_1 = require("./utilities/EventBus");
|
|
56
|
+
var RedisManager_1 = require("./utilities/RedisManager");
|
|
57
|
+
var StateManager_1 = require("./utilities/StateManager");
|
|
58
|
+
var ConduitModule_1 = require("./classes/ConduitModule");
|
|
59
|
+
var grpc_js_1 = require("@grpc/grpc-js");
|
|
60
|
+
var utilities_1 = require("./utilities");
|
|
61
|
+
var grpc_health_check_1 = require("./protoUtils/grpc_health_check");
|
|
62
|
+
var types_1 = require("./types");
|
|
63
|
+
var fast_jwt_1 = require("fast-jwt");
|
|
64
|
+
var ConduitGrpcSdk = /** @class */ (function () {
|
|
65
|
+
function ConduitGrpcSdk(serverUrl, serviceHealthStatusGetter, name, watchModules) {
|
|
66
|
+
if (watchModules === void 0) { watchModules = true; }
|
|
67
|
+
this._modules = {};
|
|
68
|
+
this._availableModules = {
|
|
69
|
+
database: modules_1.DatabaseProvider,
|
|
70
|
+
storage: modules_1.Storage,
|
|
71
|
+
email: modules_1.Email,
|
|
72
|
+
pushNotifications: modules_1.PushNotifications,
|
|
73
|
+
authentication: authentication_1.Authentication,
|
|
74
|
+
sms: modules_1.SMS,
|
|
75
|
+
chat: modules_1.Chat,
|
|
76
|
+
forms: modules_1.Forms,
|
|
77
|
+
};
|
|
78
|
+
this._dynamicModules = {};
|
|
79
|
+
this.lastSearch = Date.now();
|
|
80
|
+
this._initialized = false;
|
|
81
|
+
if (!name) {
|
|
82
|
+
this.name = 'module_' + crypto_1.default.randomBytes(16).toString('hex');
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.name = name;
|
|
86
|
+
}
|
|
87
|
+
this.serverUrl = serverUrl;
|
|
88
|
+
this._watchModules = watchModules;
|
|
89
|
+
this._serviceHealthStatusGetter = serviceHealthStatusGetter;
|
|
90
|
+
var grpcKey = process.env.GRPC_KEY;
|
|
91
|
+
if (grpcKey) {
|
|
92
|
+
var sign = fast_jwt_1.createSigner({ key: grpcKey });
|
|
93
|
+
this._grpcToken = sign({
|
|
94
|
+
moduleName: this.name,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
ConduitGrpcSdk.prototype.initialize = function () {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
var delay, state, err_1;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
switch (_a.label) {
|
|
103
|
+
case 0:
|
|
104
|
+
if (!(this.name === 'core')) return [3 /*break*/, 1];
|
|
105
|
+
this._initialize();
|
|
106
|
+
return [3 /*break*/, 8];
|
|
107
|
+
case 1:
|
|
108
|
+
this._core = new modules_1.Core(this.name, this.serverUrl, this._grpcToken);
|
|
109
|
+
console.log('Waiting for Core...');
|
|
110
|
+
delay = this.name === 'database' ? 250 : 1000;
|
|
111
|
+
_a.label = 2;
|
|
112
|
+
case 2:
|
|
113
|
+
if (!true) return [3 /*break*/, 8];
|
|
114
|
+
_a.label = 3;
|
|
115
|
+
case 3:
|
|
116
|
+
_a.trys.push([3, 5, , 7]);
|
|
117
|
+
return [4 /*yield*/, this.core.check()];
|
|
118
|
+
case 4:
|
|
119
|
+
state = _a.sent();
|
|
120
|
+
if (this.name === 'database' ||
|
|
121
|
+
state === types_1.HealthCheckStatus.SERVING) {
|
|
122
|
+
console.log('Core connection established');
|
|
123
|
+
this._initialize();
|
|
124
|
+
return [3 /*break*/, 8];
|
|
125
|
+
}
|
|
126
|
+
return [3 /*break*/, 7];
|
|
127
|
+
case 5:
|
|
128
|
+
err_1 = _a.sent();
|
|
129
|
+
if (err_1.code === grpc_js_1.status.PERMISSION_DENIED) {
|
|
130
|
+
console.error(err_1);
|
|
131
|
+
process.exit(-1);
|
|
132
|
+
}
|
|
133
|
+
return [4 /*yield*/, utilities_1.sleep(delay)];
|
|
134
|
+
case 6:
|
|
135
|
+
_a.sent();
|
|
136
|
+
return [3 /*break*/, 7];
|
|
137
|
+
case 7: return [3 /*break*/, 2];
|
|
138
|
+
case 8: return [2 /*return*/];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
ConduitGrpcSdk.prototype._initialize = function () {
|
|
144
|
+
if (this._initialized)
|
|
145
|
+
throw new Error("Module's grpc-sdk has already been initialized");
|
|
146
|
+
this._config = new modules_1.Config(this.name, this.serverUrl, this._serviceHealthStatusGetter, this._grpcToken);
|
|
147
|
+
this._admin = new modules_1.Admin(this.name, this.serverUrl, this._grpcToken);
|
|
148
|
+
this._router = new modules_1.Router(this.name, this.serverUrl, this._grpcToken);
|
|
149
|
+
this.initializeModules().then();
|
|
150
|
+
if (this._watchModules) {
|
|
151
|
+
this.watchModules();
|
|
152
|
+
}
|
|
153
|
+
this._initialized = true;
|
|
154
|
+
};
|
|
155
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "bus", {
|
|
156
|
+
get: function () {
|
|
157
|
+
if (this._eventBus) {
|
|
158
|
+
return this._eventBus;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
console.warn('Event bus not initialized');
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
enumerable: false,
|
|
166
|
+
configurable: true
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "state", {
|
|
169
|
+
get: function () {
|
|
170
|
+
if (this._stateManager) {
|
|
171
|
+
return this._stateManager;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
console.warn('State Manager not initialized');
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
enumerable: false,
|
|
179
|
+
configurable: true
|
|
180
|
+
});
|
|
181
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "core", {
|
|
182
|
+
get: function () {
|
|
183
|
+
return this._core;
|
|
184
|
+
},
|
|
185
|
+
enumerable: false,
|
|
186
|
+
configurable: true
|
|
187
|
+
});
|
|
188
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "config", {
|
|
189
|
+
get: function () {
|
|
190
|
+
return this._config;
|
|
191
|
+
},
|
|
192
|
+
enumerable: false,
|
|
193
|
+
configurable: true
|
|
194
|
+
});
|
|
195
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "admin", {
|
|
196
|
+
get: function () {
|
|
197
|
+
return this._admin;
|
|
198
|
+
},
|
|
199
|
+
enumerable: false,
|
|
200
|
+
configurable: true
|
|
201
|
+
});
|
|
202
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "router", {
|
|
203
|
+
get: function () {
|
|
204
|
+
return this._router;
|
|
205
|
+
},
|
|
206
|
+
enumerable: false,
|
|
207
|
+
configurable: true
|
|
208
|
+
});
|
|
209
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "database", {
|
|
210
|
+
get: function () {
|
|
211
|
+
if (this._modules['database']) {
|
|
212
|
+
return this._modules['database'];
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
console.warn('Database provider not up yet!');
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
enumerable: false,
|
|
220
|
+
configurable: true
|
|
221
|
+
});
|
|
222
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "databaseProvider", {
|
|
223
|
+
get: function () {
|
|
224
|
+
return this.database;
|
|
225
|
+
},
|
|
226
|
+
enumerable: false,
|
|
227
|
+
configurable: true
|
|
228
|
+
});
|
|
229
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "storage", {
|
|
230
|
+
get: function () {
|
|
231
|
+
if (this._modules['storage']) {
|
|
232
|
+
return this._modules['storage'];
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
console.warn('Storage module not up yet!');
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
enumerable: false,
|
|
240
|
+
configurable: true
|
|
241
|
+
});
|
|
242
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "forms", {
|
|
243
|
+
get: function () {
|
|
244
|
+
if (this._modules['forms']) {
|
|
245
|
+
return this._modules['forms'];
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
console.warn('Forms module not up yet!');
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
enumerable: false,
|
|
253
|
+
configurable: true
|
|
254
|
+
});
|
|
255
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "emailProvider", {
|
|
256
|
+
get: function () {
|
|
257
|
+
if (this._modules['email']) {
|
|
258
|
+
return this._modules['email'];
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
console.warn('Email provider not up yet!');
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
enumerable: false,
|
|
266
|
+
configurable: true
|
|
267
|
+
});
|
|
268
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "pushNotifications", {
|
|
269
|
+
get: function () {
|
|
270
|
+
if (this._modules['pushNotifications']) {
|
|
271
|
+
return this._modules['pushNotifications'];
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
console.warn('Push notifications module not up yet!');
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
enumerable: false,
|
|
279
|
+
configurable: true
|
|
280
|
+
});
|
|
281
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "authentication", {
|
|
282
|
+
get: function () {
|
|
283
|
+
if (this._modules['authentication']) {
|
|
284
|
+
return this._modules['authentication'];
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
console.warn('Authentication module not up yet!');
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
enumerable: false,
|
|
292
|
+
configurable: true
|
|
293
|
+
});
|
|
294
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "sms", {
|
|
295
|
+
get: function () {
|
|
296
|
+
if (this._modules['sms']) {
|
|
297
|
+
return this._modules['sms'];
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
console.warn('SMS module not up yet!');
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
enumerable: false,
|
|
305
|
+
configurable: true
|
|
306
|
+
});
|
|
307
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "chat", {
|
|
308
|
+
get: function () {
|
|
309
|
+
if (this._modules['chat']) {
|
|
310
|
+
return this._modules['chat'];
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
console.warn('Chat module not up yet!');
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
enumerable: false,
|
|
318
|
+
configurable: true
|
|
319
|
+
});
|
|
320
|
+
ConduitGrpcSdk.prototype.watchModules = function () {
|
|
321
|
+
var _this = this;
|
|
322
|
+
var emitter = this.config.getModuleWatcher();
|
|
323
|
+
this.config.watchModules().then();
|
|
324
|
+
emitter.on('serving-modules-update', function (modules) {
|
|
325
|
+
Object.keys(_this._modules).forEach(function (r) {
|
|
326
|
+
var _a;
|
|
327
|
+
var found = modules.filter(function (m) { return m.moduleName === r && m.serving; });
|
|
328
|
+
if ((!found || found.length === 0) && _this._availableModules[r]) {
|
|
329
|
+
(_a = _this._modules[r]) === null || _a === void 0 ? void 0 : _a.closeConnection();
|
|
330
|
+
emitter.emit("module-connection-update:" + r, false);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
modules.forEach(function (m) {
|
|
334
|
+
var _a;
|
|
335
|
+
if (m.serving) {
|
|
336
|
+
if (_this._modules[m.moduleName] && _this._availableModules[m.moduleName]) {
|
|
337
|
+
(_a = _this._modules[m.moduleName]) === null || _a === void 0 ? void 0 : _a.openConnection();
|
|
338
|
+
}
|
|
339
|
+
_this.createModuleClient(m.moduleName, m.url);
|
|
340
|
+
emitter.emit("module-connection-update:" + m.moduleName, true);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
};
|
|
345
|
+
ConduitGrpcSdk.prototype.monitorModule = function (moduleName, callback, wait) {
|
|
346
|
+
var _a, _b;
|
|
347
|
+
if (wait === void 0) { wait = true; }
|
|
348
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
349
|
+
var emitter;
|
|
350
|
+
return __generator(this, function (_c) {
|
|
351
|
+
switch (_c.label) {
|
|
352
|
+
case 0:
|
|
353
|
+
if (!wait) return [3 /*break*/, 2];
|
|
354
|
+
return [4 /*yield*/, this.waitForExistence(moduleName)];
|
|
355
|
+
case 1:
|
|
356
|
+
_c.sent();
|
|
357
|
+
_c.label = 2;
|
|
358
|
+
case 2:
|
|
359
|
+
(_b = (_a = this._modules['chat']) === null || _a === void 0 ? void 0 : _a.healthClient) === null || _b === void 0 ? void 0 : _b.check({}).then(function (res) {
|
|
360
|
+
callback((res === null || res === void 0 ? void 0 : res.status) === grpc_health_check_1.HealthCheckResponse_ServingStatus.SERVING);
|
|
361
|
+
}).catch(function () {
|
|
362
|
+
callback(false);
|
|
363
|
+
});
|
|
364
|
+
emitter = this.config.getModuleWatcher();
|
|
365
|
+
emitter.on("module-connection-update:" + moduleName, callback);
|
|
366
|
+
return [2 /*return*/];
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
ConduitGrpcSdk.prototype.unmonitorModule = function (moduleName) {
|
|
372
|
+
var emitter = this.config.getModuleWatcher();
|
|
373
|
+
emitter.removeAllListeners("module-connection-update:" + moduleName);
|
|
374
|
+
};
|
|
375
|
+
ConduitGrpcSdk.prototype.initializeEventBus = function () {
|
|
376
|
+
var _this = this;
|
|
377
|
+
return this.config
|
|
378
|
+
.getRedisDetails()
|
|
379
|
+
.then(function (r) {
|
|
380
|
+
var redisManager = new RedisManager_1.RedisManager(r.redisHost, r.redisPort);
|
|
381
|
+
_this._eventBus = new EventBus_1.EventBus(redisManager);
|
|
382
|
+
_this._stateManager = new StateManager_1.StateManager(redisManager, _this.name);
|
|
383
|
+
return _this._eventBus;
|
|
384
|
+
})
|
|
385
|
+
.catch(function (err) {
|
|
386
|
+
console.error('Failed to initialize event bus');
|
|
387
|
+
throw err;
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Gets all the registered modules from the config and creates clients for them.
|
|
392
|
+
* This will only work on known modules, since the primary usage for the sdk is internal
|
|
393
|
+
*/
|
|
394
|
+
ConduitGrpcSdk.prototype.initializeModules = function () {
|
|
395
|
+
var _this = this;
|
|
396
|
+
return this._config.moduleList()
|
|
397
|
+
.then(function (r) {
|
|
398
|
+
_this.lastSearch = Date.now();
|
|
399
|
+
r.forEach(function (m) {
|
|
400
|
+
_this.createModuleClient(m.moduleName, m.url);
|
|
401
|
+
});
|
|
402
|
+
return 'ok';
|
|
403
|
+
})
|
|
404
|
+
.catch(function (err) {
|
|
405
|
+
if (err.code !== 5) {
|
|
406
|
+
console.error(err);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
ConduitGrpcSdk.prototype.createModuleClient = function (moduleName, moduleUrl) {
|
|
411
|
+
if (this._modules[moduleName] ||
|
|
412
|
+
(!this._availableModules[moduleName] && !this._dynamicModules[moduleName]))
|
|
413
|
+
return;
|
|
414
|
+
if (this._availableModules[moduleName]) {
|
|
415
|
+
this._modules[moduleName] = new this._availableModules[moduleName](this.name, moduleUrl, this._grpcToken);
|
|
416
|
+
}
|
|
417
|
+
else if (this._dynamicModules[moduleName]) {
|
|
418
|
+
this._modules[moduleName] = new ConduitModule_1.ConduitModule(this.name, moduleName, moduleUrl, this._grpcToken);
|
|
419
|
+
this._modules[moduleName].initializeClient(this._dynamicModules[moduleName]);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
ConduitGrpcSdk.prototype.moduleClient = function (name, type) {
|
|
423
|
+
this._dynamicModules[name] = type;
|
|
424
|
+
};
|
|
425
|
+
ConduitGrpcSdk.prototype.getModule = function (name) {
|
|
426
|
+
if (this._modules[name])
|
|
427
|
+
return this._modules[name].client;
|
|
428
|
+
};
|
|
429
|
+
ConduitGrpcSdk.prototype.getHealthClient = function (name) {
|
|
430
|
+
if (this._modules[name])
|
|
431
|
+
return this._modules[name].healthClient;
|
|
432
|
+
};
|
|
433
|
+
ConduitGrpcSdk.prototype.isAvailable = function (moduleName) {
|
|
434
|
+
return !!(this._modules[moduleName] && this._modules[moduleName].active);
|
|
435
|
+
};
|
|
436
|
+
ConduitGrpcSdk.prototype.waitForExistence = function (moduleName) {
|
|
437
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
438
|
+
return __generator(this, function (_a) {
|
|
439
|
+
switch (_a.label) {
|
|
440
|
+
case 0:
|
|
441
|
+
if (!!this._modules[moduleName]) return [3 /*break*/, 2];
|
|
442
|
+
return [4 /*yield*/, utilities_1.sleep(1000)];
|
|
443
|
+
case 1:
|
|
444
|
+
_a.sent();
|
|
445
|
+
return [3 /*break*/, 0];
|
|
446
|
+
case 2: return [2 /*return*/, true];
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
};
|
|
451
|
+
/**
|
|
452
|
+
* Used to refresh all modules to check for new registrations
|
|
453
|
+
* @param force If true will check for new modules no matter the interval
|
|
454
|
+
*/
|
|
455
|
+
ConduitGrpcSdk.prototype.refreshModules = function (force) {
|
|
456
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
457
|
+
return __generator(this, function (_a) {
|
|
458
|
+
if (this.lastSearch < Date.now() - 3000 || force) {
|
|
459
|
+
return [2 /*return*/, this.initializeModules()];
|
|
460
|
+
}
|
|
461
|
+
return [2 /*return*/, 'ok'];
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
};
|
|
465
|
+
Object.defineProperty(ConduitGrpcSdk.prototype, "grpcToken", {
|
|
466
|
+
get: function () {
|
|
467
|
+
return this._grpcToken;
|
|
468
|
+
},
|
|
469
|
+
enumerable: false,
|
|
470
|
+
configurable: true
|
|
471
|
+
});
|
|
472
|
+
return ConduitGrpcSdk;
|
|
473
|
+
}());
|
|
474
|
+
exports.default = ConduitGrpcSdk;
|
|
475
|
+
__exportStar(require("./interfaces"), exports);
|
|
476
|
+
__exportStar(require("./classes"), exports);
|
|
477
|
+
__exportStar(require("./modules"), exports);
|
|
478
|
+
__exportStar(require("./helpers"), exports);
|
|
479
|
+
__exportStar(require("./constants"), exports);
|
|
480
|
+
__exportStar(require("./types"), exports);
|
|
481
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAYmB;AACnB,2DAA0D;AAC1D,kDAA4B;AAC5B,iDAAgD;AAChD,yDAAwD;AACxD,yDAAwD;AAExD,yDAAwD;AAExD,yCAAuC;AACvC,yCAAoC;AACpC,oEAGwC;AAKxC,iCAA4C;AAC5C,qCAAwC;AAExC;IA2BE,wBACE,SAAiB,EACjB,yBAAmC,EACnC,IAAa,EACb,YAAmB;QAAnB,6BAAA,EAAA,mBAAmB;QAxBJ,aAAQ,GAA0C,EAAE,CAAC;QACrD,sBAAiB,GAAQ;YACxC,QAAQ,EAAE,0BAAgB;YAC1B,OAAO,EAAE,iBAAO;YAChB,KAAK,EAAE,eAAK;YACZ,iBAAiB,EAAE,2BAAiB;YACpC,cAAc,EAAE,+BAAc;YAC9B,GAAG,EAAE,aAAG;YACR,IAAI,EAAE,cAAI;YACV,KAAK,EAAE,eAAK;SACb,CAAC;QACM,oBAAe,GAA+C,EAAE,CAAC;QAGjE,eAAU,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;QAIhC,iBAAY,GAAY,KAAK,CAAC;QAQpC,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,CAAC,IAAI,GAAG,SAAS,GAAG,gBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;SAChE;aAAM;YACL,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;SAClB;QACD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,0BAA0B,GAAG,yBAAyB,CAAC;QAC5D,IAAM,O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BAAO,IAAI,EAAC;;;KACb;IAED,sBAAI,qCAAS;aAAb;YACE,OAAO,IAAI,CAAC,UAAU,CAAC;QACzB,CAAC;;;OAAA;IACH,qBAAC;AAAD,CAAC,AAhWD,IAgWC;;AAED,+CAA6B;AAC7B,4CAA0B;AAC1B,4CAA0B;AAC1B,4CAA0B;AAC1B,8CAA4B;AAC5B,0CAAwB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { CallOptions, ClientMiddlewareCall } from 'nice-grpc';
|
|
2
|
+
export declare function getGrpcSignedTokenInterceptor(grpcToken: string): <Request_1, Response_1>(call: ClientMiddlewareCall<Request_1, Response_1, {}>, options: CallOptions) => AsyncGenerator<Response_1, void | Response_1, undefined>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
+
function step(op) {
|
|
7
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
+
while (_) try {
|
|
9
|
+
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;
|
|
10
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
+
switch (op[0]) {
|
|
12
|
+
case 0: case 1: t = op; break;
|
|
13
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
+
default:
|
|
17
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
+
if (t[2]) _.ops.pop();
|
|
22
|
+
_.trys.pop(); continue;
|
|
23
|
+
}
|
|
24
|
+
op = body.call(thisArg, _);
|
|
25
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
30
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
31
|
+
var m = o[Symbol.asyncIterator], i;
|
|
32
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
33
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
34
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
35
|
+
};
|
|
36
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
37
|
+
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
|
38
|
+
var i, p;
|
|
39
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
40
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
41
|
+
};
|
|
42
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
43
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
44
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
45
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
46
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
47
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
48
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
49
|
+
function fulfill(value) { resume("next", value); }
|
|
50
|
+
function reject(value) { resume("throw", value); }
|
|
51
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
52
|
+
};
|
|
53
|
+
var __values = (this && this.__values) || function(o) {
|
|
54
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
55
|
+
if (m) return m.call(o);
|
|
56
|
+
if (o && typeof o.length === "number") return {
|
|
57
|
+
next: function () {
|
|
58
|
+
if (o && i >= o.length) o = void 0;
|
|
59
|
+
return { value: o && o[i++], done: !o };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.getGrpcSignedTokenInterceptor = void 0;
|
|
66
|
+
var nice_grpc_1 = require("nice-grpc");
|
|
67
|
+
function getGrpcSignedTokenInterceptor(grpcToken) {
|
|
68
|
+
return function middleware(call, options) {
|
|
69
|
+
var _a;
|
|
70
|
+
return __asyncGenerator(this, arguments, function middleware_1() {
|
|
71
|
+
return __generator(this, function (_b) {
|
|
72
|
+
switch (_b.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
if (!options.metadata) {
|
|
75
|
+
options.metadata = nice_grpc_1.Metadata();
|
|
76
|
+
}
|
|
77
|
+
(_a = options.metadata) === null || _a === void 0 ? void 0 : _a.set('grpc-token', grpcToken);
|
|
78
|
+
return [5 /*yield**/, __values(__asyncDelegator(__asyncValues(call.next(call.request, options))))];
|
|
79
|
+
case 1: return [4 /*yield*/, __await.apply(void 0, [_b.sent()])];
|
|
80
|
+
case 2: return [4 /*yield*/, __await.apply(void 0, [_b.sent()])];
|
|
81
|
+
case 3: return [2 /*return*/, _b.sent()];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.getGrpcSignedTokenInterceptor = getGrpcSignedTokenInterceptor;
|
|
88
|
+
//# sourceMappingURL=grpcSignedToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpcSignedToken.js","sourceRoot":"","sources":["../../src/interceptors/grpcSignedToken.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAwE;AAExE,SAAgB,6BAA6B,CAAC,SAAiB;IAC7D,OAAO,SAAgB,UAAU,CAC/B,IAA6C,EAC7C,OAAoB;;;;;;wBAEpB,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;4BACrB,OAAO,CAAC,QAAQ,GAAG,oBAAQ,EAAE,CAAC;yBAC/B;wBACD,MAAA,OAAO,CAAC,QAAQ,0CAAE,GAAG,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;wBACxC,sBAAA,SAAO,iBAAA,cAAA,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA,CAAA,CAAA,EAAA;4BAAvC,4CAAA,SAAuC,IAAA;wEAAvC,SAAuC;4BAA9C,iCAA+C;;;;KAChD,CAAC;AACJ,CAAC;AAXD,sEAWC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./moduleName"), exports);
|
|
14
|
+
__exportStar(require("./grpcSignedToken"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interceptors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA6B;AAC7B,oDAAkC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { CallOptions, ClientMiddlewareCall } from 'nice-grpc';
|
|
2
|
+
export declare function getModuleNameInterceptor(moduleName: string): <Request_1, Response_1>(call: ClientMiddlewareCall<Request_1, Response_1, {}>, options: CallOptions) => AsyncGenerator<Response_1, void | Response_1, undefined>;
|