@conduitplatform/grpc-sdk 0.16.0-alpha.2 → 0.16.0-alpha.21

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 (249) hide show
  1. package/README.mdx +1 -7
  2. package/dist/classes/ConduitAuthorizedResource.js +5 -6
  3. package/dist/classes/ConduitAuthorizedResource.js.map +1 -1
  4. package/dist/classes/ConduitModule.d.ts +9 -6
  5. package/dist/classes/ConduitModule.js +68 -141
  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/Error.js +17 -40
  10. package/dist/classes/Error.js.map +1 -1
  11. package/dist/classes/HealthCheck.js +30 -71
  12. package/dist/classes/HealthCheck.js.map +1 -1
  13. package/dist/classes/index.d.ts +2 -6
  14. package/dist/classes/index.js +2 -6
  15. package/dist/classes/index.js.map +1 -1
  16. package/dist/index.d.ts +34 -31
  17. package/dist/index.js +331 -499
  18. package/dist/index.js.map +1 -1
  19. package/dist/interceptors/grpcSignedToken.d.ts +1 -1
  20. package/dist/interceptors/grpcSignedToken.js +7 -79
  21. package/dist/interceptors/grpcSignedToken.js.map +1 -1
  22. package/dist/interceptors/moduleName.d.ts +1 -1
  23. package/dist/interceptors/moduleName.js +7 -79
  24. package/dist/interceptors/moduleName.js.map +1 -1
  25. package/dist/interfaces/ConduitMiddleware.js.map +1 -0
  26. package/dist/{routing/interfaces → interfaces}/ConduitRoute.d.ts +2 -3
  27. package/dist/interfaces/ConduitRoute.js.map +1 -0
  28. package/dist/{routing → interfaces}/ConduitRouteReturn.d.ts +3 -3
  29. package/dist/{routing → interfaces}/ConduitRouteReturn.js +9 -18
  30. package/dist/interfaces/ConduitRouteReturn.js.map +1 -0
  31. package/dist/interfaces/ConduitSchemaExtension.d.ts +1 -1
  32. package/dist/interfaces/GrpcCallback.d.ts +1 -1
  33. package/dist/{utilities/Logger.d.ts → interfaces/IConduitLogger.d.ts} +4 -7
  34. package/dist/interfaces/{ConduitService.js → IConduitLogger.js} +1 -1
  35. package/dist/interfaces/IConduitLogger.js.map +1 -0
  36. package/dist/{metrics/index.d.ts → interfaces/IConduitMetrics.d.ts} +5 -11
  37. package/dist/interfaces/IConduitMetrics.js +3 -0
  38. package/dist/interfaces/IConduitMetrics.js.map +1 -0
  39. package/dist/interfaces/Indexable.d.ts +7 -8
  40. package/dist/interfaces/Model.d.ts +66 -13
  41. package/dist/interfaces/Model.js.map +1 -1
  42. package/dist/interfaces/Params.d.ts +3 -3
  43. package/dist/interfaces/ProxyRoute.js.map +1 -0
  44. package/dist/interfaces/RawQuery.d.ts +2 -2
  45. package/dist/interfaces/Route.d.ts +64 -0
  46. package/dist/interfaces/Route.js +12 -0
  47. package/dist/interfaces/Route.js.map +1 -0
  48. package/dist/{routing/interfaces → interfaces}/Socket.d.ts +4 -5
  49. package/dist/interfaces/Socket.js.map +1 -0
  50. package/dist/interfaces/UntypedArray.d.ts +1 -1
  51. package/dist/interfaces/index.d.ts +9 -2
  52. package/dist/interfaces/index.js +9 -2
  53. package/dist/interfaces/index.js.map +1 -1
  54. package/dist/{routing/interfaces → interfaces}/types.d.ts +11 -9
  55. package/dist/{routing/interfaces → interfaces}/types.js.map +1 -1
  56. package/dist/module.proto +72 -0
  57. package/dist/modules/admin/index.d.ts +5 -5
  58. package/dist/modules/admin/index.js +18 -37
  59. package/dist/modules/admin/index.js.map +1 -1
  60. package/dist/modules/authentication/index.d.ts +5 -2
  61. package/dist/modules/authentication/index.js +30 -40
  62. package/dist/modules/authentication/index.js.map +1 -1
  63. package/dist/modules/authorization/index.d.ts +6 -2
  64. package/dist/modules/authorization/index.js +38 -47
  65. package/dist/modules/authorization/index.js.map +1 -1
  66. package/dist/modules/chat/index.js +16 -34
  67. package/dist/modules/chat/index.js.map +1 -1
  68. package/dist/modules/config/index.d.ts +14 -5
  69. package/dist/modules/config/index.js +85 -177
  70. package/dist/modules/config/index.js.map +1 -1
  71. package/dist/modules/core/index.js +8 -26
  72. package/dist/modules/core/index.js.map +1 -1
  73. package/dist/modules/database/index.d.ts +24 -14
  74. package/dist/modules/database/index.js +193 -134
  75. package/dist/modules/database/index.js.map +1 -1
  76. package/dist/modules/email/index.js +15 -33
  77. package/dist/modules/email/index.js.map +1 -1
  78. package/dist/modules/index.d.ts +0 -2
  79. package/dist/modules/index.js +0 -2
  80. package/dist/modules/index.js.map +1 -1
  81. package/dist/modules/pushNotifications/index.js +38 -56
  82. package/dist/modules/pushNotifications/index.js.map +1 -1
  83. package/dist/modules/router/index.d.ts +5 -5
  84. package/dist/modules/router/index.js +20 -39
  85. package/dist/modules/router/index.js.map +1 -1
  86. package/dist/modules/sms/index.js +17 -35
  87. package/dist/modules/sms/index.js.map +1 -1
  88. package/dist/modules/storage/index.d.ts +8 -4
  89. package/dist/modules/storage/index.js +66 -37
  90. package/dist/modules/storage/index.js.map +1 -1
  91. package/dist/protoUtils/authentication.d.ts +127 -46
  92. package/dist/protoUtils/authentication.js +481 -220
  93. package/dist/protoUtils/authentication.js.map +1 -1
  94. package/dist/protoUtils/authorization.d.ts +147 -82
  95. package/dist/protoUtils/authorization.js +684 -512
  96. package/dist/protoUtils/authorization.js.map +1 -1
  97. package/dist/protoUtils/chat.d.ts +7 -61
  98. package/dist/protoUtils/chat.js +130 -313
  99. package/dist/protoUtils/chat.js.map +1 -1
  100. package/dist/protoUtils/core.d.ts +88 -107
  101. package/dist/protoUtils/core.js +699 -733
  102. package/dist/protoUtils/core.js.map +1 -1
  103. package/dist/protoUtils/database.d.ts +195 -15
  104. package/dist/protoUtils/database.js +1077 -666
  105. package/dist/protoUtils/database.js.map +1 -1
  106. package/dist/protoUtils/email.d.ts +3 -48
  107. package/dist/protoUtils/email.js +145 -284
  108. package/dist/protoUtils/email.js.map +1 -1
  109. package/dist/protoUtils/google/protobuf/empty.d.ts +27 -0
  110. package/dist/protoUtils/google/protobuf/empty.js +46 -0
  111. package/dist/protoUtils/google/protobuf/empty.js.map +1 -0
  112. package/dist/protoUtils/grpc_health_check.d.ts +3 -4
  113. package/dist/protoUtils/grpc_health_check.js +37 -36
  114. package/dist/protoUtils/grpc_health_check.js.map +1 -1
  115. package/dist/protoUtils/index.d.ts +12 -0
  116. package/dist/{routing/interfaces → protoUtils}/index.js +12 -6
  117. package/dist/protoUtils/index.js.map +1 -0
  118. package/dist/protoUtils/module.d.ts +251 -0
  119. package/dist/protoUtils/module.js +874 -0
  120. package/dist/protoUtils/module.js.map +1 -0
  121. package/dist/protoUtils/push-notifications.d.ts +7 -50
  122. package/dist/protoUtils/push-notifications.js +269 -356
  123. package/dist/protoUtils/push-notifications.js.map +1 -1
  124. package/dist/protoUtils/router.d.ts +45 -111
  125. package/dist/protoUtils/router.js +357 -575
  126. package/dist/protoUtils/router.js.map +1 -1
  127. package/dist/protoUtils/sms.d.ts +3 -48
  128. package/dist/protoUtils/sms.js +120 -219
  129. package/dist/protoUtils/sms.js.map +1 -1
  130. package/dist/protoUtils/storage.d.ts +144 -62
  131. package/dist/protoUtils/storage.js +782 -282
  132. package/dist/protoUtils/storage.js.map +1 -1
  133. package/dist/types/db.d.ts +11 -11
  134. package/dist/types/index.d.ts +3 -10
  135. package/dist/types/index.js +21 -24
  136. package/dist/types/index.js.map +1 -1
  137. package/dist/utilities/EventBus.d.ts +3 -1
  138. package/dist/utilities/EventBus.js +38 -17
  139. package/dist/utilities/EventBus.js.map +1 -1
  140. package/dist/utilities/RedisManager.js +11 -21
  141. package/dist/utilities/RedisManager.js.map +1 -1
  142. package/dist/utilities/StateManager.js +13 -14
  143. package/dist/utilities/StateManager.js.map +1 -1
  144. package/dist/utilities/env.js +4 -4
  145. package/dist/utilities/env.js.map +1 -1
  146. package/dist/utilities/index.d.ts +3 -2
  147. package/dist/utilities/index.js +3 -2
  148. package/dist/utilities/index.js.map +1 -1
  149. package/dist/utilities/sleep.js +1 -1
  150. package/dist/utilities/sleep.js.map +1 -1
  151. package/package.json +24 -25
  152. package/dist/classes/ConduitActiveSchema.d.ts +0 -19
  153. package/dist/classes/ConduitActiveSchema.js +0 -57
  154. package/dist/classes/ConduitActiveSchema.js.map +0 -1
  155. package/dist/classes/ConduitServiceModule.d.ts +0 -26
  156. package/dist/classes/ConduitServiceModule.js +0 -166
  157. package/dist/classes/ConduitServiceModule.js.map +0 -1
  158. package/dist/classes/ConfigController.d.ts +0 -7
  159. package/dist/classes/ConfigController.js +0 -27
  160. package/dist/classes/ConfigController.js.map +0 -1
  161. package/dist/classes/GrpcServer.d.ts +0 -22
  162. package/dist/classes/GrpcServer.js +0 -207
  163. package/dist/classes/GrpcServer.js.map +0 -1
  164. package/dist/classes/ManagedModule.d.ts +0 -74
  165. package/dist/classes/ManagedModule.js +0 -333
  166. package/dist/classes/ManagedModule.js.map +0 -1
  167. package/dist/classes/ModuleManager.d.ts +0 -11
  168. package/dist/classes/ModuleManager.js +0 -204
  169. package/dist/classes/ModuleManager.js.map +0 -1
  170. package/dist/helpers/GrpcHelper.d.ts +0 -8
  171. package/dist/helpers/GrpcHelper.js +0 -43
  172. package/dist/helpers/GrpcHelper.js.map +0 -1
  173. package/dist/helpers/TypeHelpers.d.ts +0 -44
  174. package/dist/helpers/TypeHelpers.js +0 -144
  175. package/dist/helpers/TypeHelpers.js.map +0 -1
  176. package/dist/helpers/index.d.ts +0 -3
  177. package/dist/helpers/index.js +0 -20
  178. package/dist/helpers/index.js.map +0 -1
  179. package/dist/helpers/wrapGrpcFunctions.d.ts +0 -5
  180. package/dist/helpers/wrapGrpcFunctions.js +0 -56
  181. package/dist/helpers/wrapGrpcFunctions.js.map +0 -1
  182. package/dist/interfaces/ConduitService.d.ts +0 -8
  183. package/dist/interfaces/ConduitService.js.map +0 -1
  184. package/dist/metrics/MetricsServer.d.ts +0 -9
  185. package/dist/metrics/MetricsServer.js +0 -94
  186. package/dist/metrics/MetricsServer.js.map +0 -1
  187. package/dist/metrics/clientMiddleware.d.ts +0 -2
  188. package/dist/metrics/clientMiddleware.js +0 -265
  189. package/dist/metrics/clientMiddleware.js.map +0 -1
  190. package/dist/metrics/config/defaults.d.ts +0 -91
  191. package/dist/metrics/config/defaults.js +0 -93
  192. package/dist/metrics/config/defaults.js.map +0 -1
  193. package/dist/metrics/index.js +0 -152
  194. package/dist/metrics/index.js.map +0 -1
  195. package/dist/modules/forms/index.d.ts +0 -6
  196. package/dist/modules/forms/index.js +0 -32
  197. package/dist/modules/forms/index.js.map +0 -1
  198. package/dist/modules/functions/index.d.ts +0 -6
  199. package/dist/modules/functions/index.js +0 -32
  200. package/dist/modules/functions/index.js.map +0 -1
  201. package/dist/protoUtils/forms.d.ts +0 -58
  202. package/dist/protoUtils/forms.js +0 -127
  203. package/dist/protoUtils/forms.js.map +0 -1
  204. package/dist/protoUtils/functions.d.ts +0 -58
  205. package/dist/protoUtils/functions.js +0 -127
  206. package/dist/protoUtils/functions.js.map +0 -1
  207. package/dist/routing/ConduitRouteReturn.js.map +0 -1
  208. package/dist/routing/ProxyRouteBuilder.d.ts +0 -21
  209. package/dist/routing/ProxyRouteBuilder.js +0 -81
  210. package/dist/routing/ProxyRouteBuilder.js.map +0 -1
  211. package/dist/routing/RouteBuilder.d.ts +0 -24
  212. package/dist/routing/RouteBuilder.js +0 -107
  213. package/dist/routing/RouteBuilder.js.map +0 -1
  214. package/dist/routing/RoutingManager.d.ts +0 -33
  215. package/dist/routing/RoutingManager.js +0 -201
  216. package/dist/routing/RoutingManager.js.map +0 -1
  217. package/dist/routing/RoutingUtilities.d.ts +0 -7
  218. package/dist/routing/RoutingUtilities.js +0 -13
  219. package/dist/routing/RoutingUtilities.js.map +0 -1
  220. package/dist/routing/index.d.ts +0 -7
  221. package/dist/routing/index.js +0 -24
  222. package/dist/routing/index.js.map +0 -1
  223. package/dist/routing/interfaces/ConduitMiddleware.js.map +0 -1
  224. package/dist/routing/interfaces/ConduitRoute.js.map +0 -1
  225. package/dist/routing/interfaces/ProxyRoute.js.map +0 -1
  226. package/dist/routing/interfaces/Route.d.ts +0 -52
  227. package/dist/routing/interfaces/Route.js +0 -21
  228. package/dist/routing/interfaces/Route.js.map +0 -1
  229. package/dist/routing/interfaces/Socket.js.map +0 -1
  230. package/dist/routing/interfaces/index.d.ts +0 -6
  231. package/dist/routing/interfaces/index.js.map +0 -1
  232. package/dist/routing/wrapRouterFunctions.d.ts +0 -8
  233. package/dist/routing/wrapRouterFunctions.js +0 -132
  234. package/dist/routing/wrapRouterFunctions.js.map +0 -1
  235. package/dist/utilities/Logger.js +0 -255
  236. package/dist/utilities/Logger.js.map +0 -1
  237. package/dist/utilities/linearBackoffTimeout.d.ts +0 -10
  238. package/dist/utilities/linearBackoffTimeout.js +0 -119
  239. package/dist/utilities/linearBackoffTimeout.js.map +0 -1
  240. package/dist/utilities/merge.d.ts +0 -1
  241. package/dist/utilities/merge.js +0 -15
  242. package/dist/utilities/merge.js.map +0 -1
  243. /package/dist/{routing/interfaces → interfaces}/ConduitMiddleware.d.ts +0 -0
  244. /package/dist/{routing/interfaces → interfaces}/ConduitMiddleware.js +0 -0
  245. /package/dist/{routing/interfaces → interfaces}/ConduitRoute.js +0 -0
  246. /package/dist/{routing/interfaces → interfaces}/ProxyRoute.d.ts +0 -0
  247. /package/dist/{routing/interfaces → interfaces}/ProxyRoute.js +0 -0
  248. /package/dist/{routing/interfaces → interfaces}/Socket.js +0 -0
  249. /package/dist/{routing/interfaces → interfaces}/types.js +0 -0
@@ -1,74 +0,0 @@
1
- import ConduitGrpcSdk, { ConduitService, SetConfigRequest, SetConfigResponse } from '..';
2
- import { ConduitServiceModule } from './ConduitServiceModule';
3
- import convict from 'convict';
4
- export declare abstract class ManagedModule<T> extends ConduitServiceModule {
5
- protected abstract readonly configSchema?: object;
6
- protected abstract readonly metricsSchema?: object;
7
- readonly config?: convict.Config<T>;
8
- configOverride: boolean;
9
- service?: ConduitService;
10
- protected constructor(moduleName: string);
11
- get name(): string;
12
- get address(): string;
13
- /**
14
- * This is the first function triggered on module spin up.
15
- * @param grpcSdk {ConduitGrpcSdk}
16
- * @param address {string} external address:port of service (LoadBalancer)
17
- * @param port {string} port to bring up gRPC service
18
- */
19
- initialize(grpcSdk: ConduitGrpcSdk, address: string, port: string): void;
20
- /**
21
- * This is triggered before spinning up the Grpc Server
22
- * of the module. On this stage, the redis bus and state have
23
- * not yet been initialized, and only communications with Conduit core
24
- * have been established.
25
- */
26
- preServerStart(): Promise<void>;
27
- /**
28
- * This is triggered right after Grpc Server start.
29
- * At this stage the core module will communicate with your service
30
- * for health checks, and the Bus and State management mechanics
31
- * are online and available.
32
- */
33
- onServerStart(): Promise<void>;
34
- /**
35
- * Triggers right before registering the module with Conduit Core.
36
- */
37
- preRegister(): Promise<void>;
38
- /**
39
- * Triggers when module has been registered with Conduit Core
40
- * This is the step where you should initialize your
41
- * module's general routing (admin or client) and any other operation,
42
- * that would require other modules being able to reach you
43
- */
44
- onRegister(): Promise<void>;
45
- /**
46
- * This is triggered when the module receives new configuration.
47
- * At this step the configuration has not been checked yet,
48
- * and has only been parsed.
49
- * @param config
50
- */
51
- preConfig(config: T): Promise<T>;
52
- /**
53
- * This is triggered when new configuration has been applied.
54
- * This happens either when changes are being made on the configuration,
55
- * or on module start up, where the config is recovered from the database.
56
- * In either case the configuration is now available through the
57
- * Config Controller of the sdk.
58
- */
59
- onConfig(): Promise<void>;
60
- /**
61
- * Registers common and module-specific metric types.
62
- */
63
- registerMetrics(): Promise<void>;
64
- /**
65
- * Initializes metric startup values.
66
- * Implemented by individual modules.
67
- */
68
- initializeMetrics(): Promise<void>;
69
- createGrpcServer(): Promise<void>;
70
- startGrpcServer(): Promise<void>;
71
- setConfig(call: SetConfigRequest, callback: SetConfigResponse): Promise<void>;
72
- /** Used to update the module's configuration on initial Redis/DB reconciliation. */
73
- handleConfigSyncUpdate(): Promise<void>;
74
- }
@@ -1,333 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
- return new (P || (P = Promise))(function (resolve, reject) {
43
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
- step((generator = generator.apply(thisArg, _arguments || [])).next());
47
- });
48
- };
49
- var __generator = (this && this.__generator) || function (thisArg, body) {
50
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
51
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
52
- function verb(n) { return function (v) { return step([n, v]); }; }
53
- function step(op) {
54
- if (f) throw new TypeError("Generator is already executing.");
55
- while (_) try {
56
- 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;
57
- if (y = 0, t) op = [op[0] & 2, t.value];
58
- switch (op[0]) {
59
- case 0: case 1: t = op; break;
60
- case 4: _.label++; return { value: op[1], done: false };
61
- case 5: _.label++; y = op[1]; op = [0]; continue;
62
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
63
- default:
64
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
65
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
66
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
67
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
68
- if (t[2]) _.ops.pop();
69
- _.trys.pop(); continue;
70
- }
71
- op = body.call(thisArg, _);
72
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
73
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
74
- }
75
- };
76
- var __importDefault = (this && this.__importDefault) || function (mod) {
77
- return (mod && mod.__esModule) ? mod : { "default": mod };
78
- };
79
- Object.defineProperty(exports, "__esModule", { value: true });
80
- exports.ManagedModule = void 0;
81
- var __1 = __importStar(require(".."));
82
- var ConduitServiceModule_1 = require("./ConduitServiceModule");
83
- var ConfigController_1 = require("./ConfigController");
84
- var lodash_1 = require("lodash");
85
- var grpc_js_1 = require("@grpc/grpc-js");
86
- var convict_1 = __importDefault(require("convict"));
87
- var ManagedModule = /** @class */ (function (_super) {
88
- __extends(ManagedModule, _super);
89
- function ManagedModule(moduleName) {
90
- var _this = _super.call(this, moduleName) || this;
91
- _this.configOverride = false;
92
- return _this;
93
- }
94
- Object.defineProperty(ManagedModule.prototype, "name", {
95
- get: function () {
96
- return this._moduleName;
97
- },
98
- enumerable: false,
99
- configurable: true
100
- });
101
- Object.defineProperty(ManagedModule.prototype, "address", {
102
- get: function () {
103
- return this._address;
104
- },
105
- enumerable: false,
106
- configurable: true
107
- });
108
- /**
109
- * This is the first function triggered on module spin up.
110
- * @param grpcSdk {ConduitGrpcSdk}
111
- * @param address {string} external address:port of service (LoadBalancer)
112
- * @param port {string} port to bring up gRPC service
113
- */
114
- ManagedModule.prototype.initialize = function (grpcSdk, address, port) {
115
- this.grpcSdk = grpcSdk;
116
- this._address = address;
117
- this._port = port;
118
- if (this.configSchema) {
119
- this.config = (0, convict_1.default)(this.configSchema);
120
- }
121
- };
122
- /**
123
- * This is triggered before spinning up the Grpc Server
124
- * of the module. On this stage, the redis bus and state have
125
- * not yet been initialized, and only communications with Conduit core
126
- * have been established.
127
- */
128
- ManagedModule.prototype.preServerStart = function () {
129
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
130
- return [2 /*return*/];
131
- }); });
132
- };
133
- /**
134
- * This is triggered right after Grpc Server start.
135
- * At this stage the core module will communicate with your service
136
- * for health checks, and the Bus and State management mechanics
137
- * are online and available.
138
- */
139
- ManagedModule.prototype.onServerStart = function () {
140
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
141
- return [2 /*return*/];
142
- }); });
143
- };
144
- /**
145
- * Triggers right before registering the module with Conduit Core.
146
- */
147
- ManagedModule.prototype.preRegister = function () {
148
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
149
- return [2 /*return*/];
150
- }); });
151
- };
152
- /**
153
- * Triggers when module has been registered with Conduit Core
154
- * This is the step where you should initialize your
155
- * module's general routing (admin or client) and any other operation,
156
- * that would require other modules being able to reach you
157
- */
158
- ManagedModule.prototype.onRegister = function () {
159
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
160
- return [2 /*return*/];
161
- }); });
162
- };
163
- /**
164
- * This is triggered when the module receives new configuration.
165
- * At this step the configuration has not been checked yet,
166
- * and has only been parsed.
167
- * @param config
168
- */
169
- ManagedModule.prototype.preConfig = function (config) {
170
- return __awaiter(this, void 0, void 0, function () {
171
- return __generator(this, function (_a) {
172
- return [2 /*return*/, config];
173
- });
174
- });
175
- };
176
- /**
177
- * This is triggered when new configuration has been applied.
178
- * This happens either when changes are being made on the configuration,
179
- * or on module start up, where the config is recovered from the database.
180
- * In either case the configuration is now available through the
181
- * Config Controller of the sdk.
182
- */
183
- ManagedModule.prototype.onConfig = function () {
184
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
185
- return [2 /*return*/];
186
- }); });
187
- };
188
- /**
189
- * Registers common and module-specific metric types.
190
- */
191
- ManagedModule.prototype.registerMetrics = function () {
192
- return __awaiter(this, void 0, void 0, function () {
193
- return __generator(this, function (_a) {
194
- if (__1.default.Metrics) {
195
- __1.default.Metrics.initializeDefaultMetrics();
196
- if (this.metricsSchema) {
197
- Object.values(this.metricsSchema).forEach(function (metric) {
198
- __1.default.Metrics.registerMetric(metric.type, metric.config);
199
- });
200
- }
201
- }
202
- return [2 /*return*/];
203
- });
204
- });
205
- };
206
- /**
207
- * Initializes metric startup values.
208
- * Implemented by individual modules.
209
- */
210
- ManagedModule.prototype.initializeMetrics = function () {
211
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
212
- return [2 /*return*/];
213
- }); });
214
- };
215
- ManagedModule.prototype.createGrpcServer = function () {
216
- return __awaiter(this, void 0, void 0, function () {
217
- var _a;
218
- return __generator(this, function (_b) {
219
- switch (_b.label) {
220
- case 0:
221
- this.grpcServer = new __1.GrpcServer(this._port);
222
- _a = this;
223
- return [4 /*yield*/, this.grpcServer.createNewServer()];
224
- case 1:
225
- _a._port = (_b.sent()).toString();
226
- return [2 /*return*/];
227
- }
228
- });
229
- });
230
- };
231
- ManagedModule.prototype.startGrpcServer = function () {
232
- return __awaiter(this, void 0, void 0, function () {
233
- return __generator(this, function (_a) {
234
- switch (_a.label) {
235
- case 0:
236
- if (!this.service) return [3 /*break*/, 4];
237
- this._serviceName = this.service.protoDescription.substring(this.service.protoDescription.indexOf('.') + 1);
238
- return [4 /*yield*/, this.grpcServer.addService(this.service.protoPath, this.service.protoDescription, this.service.functions)];
239
- case 1:
240
- _a.sent();
241
- return [4 /*yield*/, this.addHealthCheckService()];
242
- case 2:
243
- _a.sent();
244
- return [4 /*yield*/, this.grpcServer.start()];
245
- case 3:
246
- _a.sent();
247
- __1.default.Logger.log('gRPC server listening on ' + this._port);
248
- _a.label = 4;
249
- case 4: return [2 /*return*/];
250
- }
251
- });
252
- });
253
- };
254
- ManagedModule.prototype.setConfig = function (call, callback) {
255
- var _a;
256
- return __awaiter(this, void 0, void 0, function () {
257
- var config, previousConfig, e_1;
258
- return __generator(this, function (_b) {
259
- switch (_b.label) {
260
- case 0:
261
- _b.trys.push([0, 3, , 4]);
262
- if (!this.config) {
263
- return [2 /*return*/, callback({
264
- code: grpc_js_1.status.INVALID_ARGUMENT,
265
- message: 'Module is not configurable',
266
- })];
267
- }
268
- config = JSON.parse(call.request.newConfig);
269
- config = (0, __1.merge)(this.config.getProperties(), config);
270
- return [4 /*yield*/, this.preConfig(config)];
271
- case 1:
272
- config = _b.sent();
273
- previousConfig = this.config.getProperties();
274
- try {
275
- this.config.load(config).validate({
276
- allowed: 'strict',
277
- });
278
- config = this.config.getProperties();
279
- callback(null, { updatedConfig: JSON.stringify(config) });
280
- }
281
- catch (e) {
282
- this.config = (0, convict_1.default)(this.configSchema);
283
- this.config.load(previousConfig);
284
- return [2 /*return*/, callback({
285
- code: grpc_js_1.status.INVALID_ARGUMENT,
286
- message: 'Invalid configuration values: ' + e.message,
287
- })];
288
- }
289
- ConfigController_1.ConfigController.getInstance().config = config;
290
- return [4 /*yield*/, this.onConfig()];
291
- case 2:
292
- _b.sent();
293
- (_a = this.grpcSdk.bus) === null || _a === void 0 ? void 0 : _a.publish((0, lodash_1.kebabCase)(this.name) + ':config:update', JSON.stringify(config));
294
- return [3 /*break*/, 4];
295
- case 3:
296
- e_1 = _b.sent();
297
- return [2 /*return*/, callback({ code: grpc_js_1.status.INTERNAL, message: e_1.message })];
298
- case 4: return [2 /*return*/];
299
- }
300
- });
301
- });
302
- };
303
- /** Used to update the module's configuration on initial Redis/DB reconciliation. */
304
- ManagedModule.prototype.handleConfigSyncUpdate = function () {
305
- return __awaiter(this, void 0, void 0, function () {
306
- var _this = this;
307
- return __generator(this, function (_a) {
308
- if (!this.config)
309
- return [2 /*return*/];
310
- this.grpcSdk.bus.subscribe("".concat(this.name, ":config:update"), function (message) { return __awaiter(_this, void 0, void 0, function () {
311
- var _a;
312
- return __generator(this, function (_b) {
313
- switch (_b.label) {
314
- case 0:
315
- _a = ConfigController_1.ConfigController.getInstance();
316
- return [4 /*yield*/, this.preConfig(JSON.parse(message))];
317
- case 1:
318
- _a.config = _b.sent();
319
- return [4 /*yield*/, this.onConfig()];
320
- case 2:
321
- _b.sent();
322
- return [2 /*return*/];
323
- }
324
- });
325
- }); });
326
- return [2 /*return*/];
327
- });
328
- });
329
- };
330
- return ManagedModule;
331
- }(ConduitServiceModule_1.ConduitServiceModule));
332
- exports.ManagedModule = ManagedModule;
333
- //# sourceMappingURL=ManagedModule.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ManagedModule.js","sourceRoot":"","sources":["../../src/classes/ManagedModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAMY;AACZ,+DAA8D;AAC9D,uDAAsD;AAC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AO,CAAC,GAAG,0CAAE,OAAO,CACvB,IAAA,kBAAS,EAAC,IAAI,CAAC,IAAI,CAAC,GAAG,gBAAgB,EACvC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CACvB,CAAC;;;;wBAEF,sBAAO,QAAQ,CAAC,EAAE,IAAI,EAAE,gBAAM,CAAC,QAAQ,EAAE,OAAO,EAAG,GAAW,CAAC,OAAO,EAAE,CAAC,EAAC;;;;;KAE7E;IAED,oFAAoF;IAC9E,8CAAsB,GAA5B;;;;gBACE,IAAI,CAAC,IAAI,CAAC,MAAM;oBAAE,sBAAO;gBACzB,IAAI,CAAC,OAAO,CAAC,GAAI,CAAC,SAAS,CAAC,UAAG,IAAI,CAAC,IAAI,mBAAgB,EAAE,UAAM,OAAO;;;;;gCACrE,KAAA,mCAAgB,CAAC,WAAW,EAAE,CAAA;gCAAU,qBAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAA;;gCAAjF,GAA+B,MAAM,GAAG,SAAyC,CAAC;gCAClF,qBAAM,IAAI,CAAC,QAAQ,EAAE,EAAA;;gCAArB,SAAqB,CAAC;;;;qBACvB,CAAC,CAAC;;;;KACJ;IACH,oBAAC;AAAD,CAAC,AAxKD,CAA+C,2CAAoB,GAwKlE;AAxKqB,sCAAa"}
@@ -1,11 +0,0 @@
1
- import { ManagedModule } from '..';
2
- export declare class ModuleManager<T> {
3
- private readonly module;
4
- private readonly serviceAddress;
5
- private readonly servicePort;
6
- private readonly grpcSdk;
7
- constructor(module: ManagedModule<T>);
8
- start(): Promise<void>;
9
- private preRegisterLifecycle;
10
- private postRegisterLifecycle;
11
- }
@@ -1,204 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
41
- 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;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.ModuleManager = void 0;
63
- var __1 = __importStar(require(".."));
64
- var convictConfigParser = function (config) {
65
- if (typeof config === 'object') {
66
- Object.keys(config).forEach(function (key) {
67
- if (key === '_cvtProperties') {
68
- config = convictConfigParser(config._cvtProperties);
69
- }
70
- else {
71
- config[key] = convictConfigParser(config[key]);
72
- }
73
- });
74
- }
75
- return config;
76
- };
77
- var ModuleManager = /** @class */ (function () {
78
- function ModuleManager(module) {
79
- var _this = this;
80
- var _a;
81
- this.module = module;
82
- if (!process.env.CONDUIT_SERVER) {
83
- throw new Error('CONDUIT_SERVER is undefined, specify Conduit server URL');
84
- }
85
- this.servicePort = (_a = process.env.GRPC_PORT) !== null && _a !== void 0 ? _a : '5000';
86
- this.serviceAddress =
87
- // @compat (v0.15): SERVICE_IP -> SERVICE_URL
88
- process.env.SERVICE_URL || process.env.SERVICE_IP || '0.0.0.0:' + this.servicePort;
89
- try {
90
- this.grpcSdk = new __1.default(process.env.CONDUIT_SERVER, function () {
91
- return _this.module.healthState;
92
- }, module.name, true);
93
- }
94
- catch (_b) {
95
- throw new Error('Failed to initialize grpcSdk');
96
- }
97
- }
98
- ModuleManager.prototype.start = function () {
99
- return __awaiter(this, void 0, void 0, function () {
100
- var err_1;
101
- return __generator(this, function (_a) {
102
- switch (_a.label) {
103
- case 0: return [4 /*yield*/, this.grpcSdk.initialize()];
104
- case 1:
105
- _a.sent();
106
- this.module.initialize(this.grpcSdk, this.serviceAddress, this.servicePort);
107
- _a.label = 2;
108
- case 2:
109
- _a.trys.push([2, 5, , 6]);
110
- return [4 /*yield*/, this.preRegisterLifecycle()];
111
- case 3:
112
- _a.sent();
113
- return [4 /*yield*/, this.grpcSdk.config.registerModule(this.module.name, this.module.address, this.module.healthState)];
114
- case 4:
115
- _a.sent();
116
- return [3 /*break*/, 6];
117
- case 5:
118
- err_1 = _a.sent();
119
- __1.default.Logger.error('Failed to initialize server');
120
- __1.default.Logger.error(err_1);
121
- process.exit(-1);
122
- return [3 /*break*/, 6];
123
- case 6: return [4 /*yield*/, this.postRegisterLifecycle().catch(function (err) {
124
- __1.default.Logger.error('Failed to activate module');
125
- __1.default.Logger.error(err);
126
- process.exit(-1);
127
- })];
128
- case 7:
129
- _a.sent();
130
- return [2 /*return*/];
131
- }
132
- });
133
- });
134
- };
135
- ModuleManager.prototype.preRegisterLifecycle = function () {
136
- return __awaiter(this, void 0, void 0, function () {
137
- return __generator(this, function (_a) {
138
- switch (_a.label) {
139
- case 0: return [4 /*yield*/, this.module.createGrpcServer()];
140
- case 1:
141
- _a.sent();
142
- return [4 /*yield*/, this.module.preServerStart()];
143
- case 2:
144
- _a.sent();
145
- return [4 /*yield*/, this.grpcSdk.initializeEventBus()];
146
- case 3:
147
- _a.sent();
148
- return [4 /*yield*/, this.module.handleConfigSyncUpdate()];
149
- case 4:
150
- _a.sent();
151
- return [4 /*yield*/, this.module.registerMetrics()];
152
- case 5:
153
- _a.sent();
154
- return [4 /*yield*/, this.module.startGrpcServer()];
155
- case 6:
156
- _a.sent();
157
- return [4 /*yield*/, this.module.onServerStart()];
158
- case 7:
159
- _a.sent();
160
- return [4 /*yield*/, this.module.initializeMetrics()];
161
- case 8:
162
- _a.sent();
163
- return [4 /*yield*/, this.module.preRegister()];
164
- case 9:
165
- _a.sent();
166
- return [2 /*return*/];
167
- }
168
- });
169
- });
170
- };
171
- ModuleManager.prototype.postRegisterLifecycle = function () {
172
- return __awaiter(this, void 0, void 0, function () {
173
- var configSchema, config;
174
- return __generator(this, function (_a) {
175
- switch (_a.label) {
176
- case 0: return [4 /*yield*/, this.module.onRegister()];
177
- case 1:
178
- _a.sent();
179
- if (!this.module.config) return [3 /*break*/, 5];
180
- configSchema = this.module.config.getSchema();
181
- config = this.module.config.getProperties();
182
- return [4 /*yield*/, this.module.preConfig(config)];
183
- case 2:
184
- config = _a.sent();
185
- return [4 /*yield*/, this.grpcSdk.config.configure(config, convictConfigParser(configSchema), this.module.configOverride)];
186
- case 3:
187
- config = _a.sent();
188
- __1.ConfigController.getInstance();
189
- if (config)
190
- __1.ConfigController.getInstance().config = config;
191
- if (!(!config || config.active || !config.hasOwnProperty('active'))) return [3 /*break*/, 5];
192
- return [4 /*yield*/, this.module.onConfig()];
193
- case 4:
194
- _a.sent();
195
- _a.label = 5;
196
- case 5: return [2 /*return*/];
197
- }
198
- });
199
- });
200
- };
201
- return ModuleManager;
202
- }());
203
- exports.ModuleManager = ModuleManager;
204
- //# sourceMappingURL=ModuleManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ModuleManager.js","sourceRoot":"","sources":["../../src/classes/ModuleManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAgF;AAEhF,IAAM,mBAAmB,GAAG,UAAC,MAAiB;IAC5C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;YAC7B,IAAI,GAAG,KAAK,gBAAg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a"}
@@ -1,8 +0,0 @@
1
- import { Server } from '@grpc/grpc-js';
2
- export declare function createServer(port: string): Promise<{
3
- server: Server;
4
- port: number;
5
- }>;
6
- export declare function addServiceToServer(server: Server, protoPath: string, descriptorObject: string, functions: {
7
- [name: string]: Function;
8
- }): void;