@common-stack/server-stack 8.2.5-alpha.8 → 8.3.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/lib/MainStackServer.cjs +17 -10
  2. package/lib/MainStackServer.cjs.map +1 -1
  3. package/lib/MainStackServer.mjs +17 -10
  4. package/lib/MainStackServer.mjs.map +1 -1
  5. package/lib/StackServer.cjs +1 -1
  6. package/lib/StackServer.cjs.map +1 -1
  7. package/lib/StackServer.mjs +1 -1
  8. package/lib/StackServer.mjs.map +1 -1
  9. package/lib/config/env-config.cjs +6 -0
  10. package/lib/config/env-config.cjs.map +1 -1
  11. package/lib/config/env-config.mjs +6 -0
  12. package/lib/config/env-config.mjs.map +1 -1
  13. package/lib/infrastructure/container-module.cjs +2 -1
  14. package/lib/infrastructure/container-module.cjs.map +1 -1
  15. package/lib/infrastructure/container-module.mjs +2 -1
  16. package/lib/infrastructure/container-module.mjs.map +1 -1
  17. package/lib/infrastructure/inngest-factory.cjs +6 -2
  18. package/lib/infrastructure/inngest-factory.cjs.map +1 -1
  19. package/lib/infrastructure/inngest-factory.mjs +6 -2
  20. package/lib/infrastructure/inngest-factory.mjs.map +1 -1
  21. package/lib/servers/ExpressApp.cjs +3 -3
  22. package/lib/servers/ExpressApp.cjs.map +1 -1
  23. package/lib/servers/ExpressApp.mjs +1 -1
  24. package/lib/servers/ExpressApp.mjs.map +1 -1
  25. package/lib/servers/WebsocketMultipathUpdate.cjs +51 -9
  26. package/lib/servers/WebsocketMultipathUpdate.cjs.map +1 -1
  27. package/lib/servers/WebsocketMultipathUpdate.mjs +51 -9
  28. package/lib/servers/WebsocketMultipathUpdate.mjs.map +1 -1
  29. package/package.json +8 -8
  30. package/lib/MainStackServer.d.ts +0 -34
  31. package/lib/StackServer.d.ts +0 -29
  32. package/lib/api/remote-config.d.ts +0 -6
  33. package/lib/api/resolver.d.ts +0 -10
  34. package/lib/api/scalar.d.ts +0 -2
  35. package/lib/api/schema-builder.d.ts +0 -24
  36. package/lib/api/sub-graph-schema-builder.d.ts +0 -24
  37. package/lib/api/utils.d.ts +0 -4
  38. package/lib/config/env-config.d.ts +0 -28
  39. package/lib/config/index.d.ts +0 -1
  40. package/lib/config/moleculer.config.d.ts +0 -20
  41. package/lib/connectors/connection-broker.d.ts +0 -26
  42. package/lib/connectors/graphql-pubsub-connector.d.ts +0 -22
  43. package/lib/connectors/mongo-connector.d.ts +0 -21
  44. package/lib/connectors/nats-connector.d.ts +0 -20
  45. package/lib/connectors/redis-connector.d.ts +0 -30
  46. package/lib/examples/tenant-feature-example.d.ts +0 -13
  47. package/lib/examples/tenant-feature-integration.d.ts +0 -14
  48. package/lib/features/multi-module-example.d.ts +0 -17
  49. package/lib/index.d.ts +0 -4
  50. package/lib/infrastructure/container-module.d.ts +0 -3
  51. package/lib/infrastructure/example-workflows.d.ts +0 -16
  52. package/lib/infrastructure/index.d.ts +0 -5
  53. package/lib/infrastructure/infrastructure-factory.d.ts +0 -45
  54. package/lib/infrastructure/inngest-factory.d.ts +0 -8
  55. package/lib/infrastructure/types.d.ts +0 -28
  56. package/lib/infrastructure/usage-examples.d.ts +0 -9
  57. package/lib/infrastructure/workflow-orchestrator.d.ts +0 -10
  58. package/lib/inngest/client-id-generator.d.ts +0 -29
  59. package/lib/inngest/handler-factory.d.ts +0 -24
  60. package/lib/inngest/middleware/auto-resolve-invoke.middleware.d.ts +0 -111
  61. package/lib/inngest/middleware/function-reference-helper.d.ts +0 -211
  62. package/lib/inngest/middleware/index.d.ts +0 -31
  63. package/lib/inngest/middleware/types.d.ts +0 -162
  64. package/lib/inngest/multi-module-functions.d.ts +0 -133
  65. package/lib/inngest/setup.d.ts +0 -10
  66. package/lib/interfaces/dbMigration.d.ts +0 -8
  67. package/lib/interfaces/graphql-request-context.d.ts +0 -20
  68. package/lib/interfaces/index.d.ts +0 -4
  69. package/lib/interfaces/module-interface.d.ts +0 -13
  70. package/lib/interfaces/moleculer.d.ts +0 -7
  71. package/lib/middleware/cors.d.ts +0 -6
  72. package/lib/middleware/error.d.ts +0 -9
  73. package/lib/middleware/index.d.ts +0 -5
  74. package/lib/middleware/moleculer-inter-namespace.d.ts +0 -2
  75. package/lib/middleware/redis-client.d.ts +0 -16
  76. package/lib/middleware/sentry.d.ts +0 -2
  77. package/lib/middleware/services.d.ts +0 -2
  78. package/lib/plugins/index.d.ts +0 -2
  79. package/lib/plugins/invalidateCachePlugin.d.ts +0 -8
  80. package/lib/plugins/responseCachePlugin.d.ts +0 -12
  81. package/lib/servers/ExpressApp.d.ts +0 -3
  82. package/lib/servers/GraphqlServer.d.ts +0 -25
  83. package/lib/servers/GraphqlWs.d.ts +0 -14
  84. package/lib/servers/WebsocketMultipathUpdate.d.ts +0 -18
  85. package/lib/servers/mongodb-migration-update.d.ts +0 -12
  86. package/lib/servers/utils.d.ts +0 -14
  87. package/lib/servers/websocket-context.d.ts +0 -30
  88. package/lib/utils/add-shareable-directive-to-schema.d.ts +0 -1
  89. package/lib/utils/index.d.ts +0 -3
  90. package/lib/utils/migrations.d.ts +0 -8
  91. package/lib/utils/safe-model-factory.d.ts +0 -18
@@ -1,21 +1,28 @@
1
- import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'graphql-ws/lib/use/ws';import {createWebSocketContext}from'./websocket-context.mjs';class WebsocketMultiPathServer {
1
+ import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'graphql-ws/lib/use/ws';import {createWebSocketContext}from'./websocket-context.mjs';import {config}from'../config/env-config.mjs';class WebsocketMultiPathServer {
2
2
  moduleService;
3
3
  cache;
4
4
  webSockets = {};
5
5
  // private graphqlSubscriptionServer: GraphqlSubscriptionServer;
6
6
  _graphqlWs;
7
- constructor(moduleService, cache, multiplePathConfig) {
7
+ /** Maximum WebSocket connections allowed per instance */
8
+ maxConnections;
9
+ /** Whether connection limiting is enabled */
10
+ limitEnabled;
11
+ constructor(moduleService, cache, multiplePathConfig, limitConfig) {
8
12
  this.moduleService = moduleService;
9
13
  this.cache = cache;
14
+ // Read from validated config (Kubernetes configmap) or use defaults
15
+ this.maxConnections = limitConfig?.maxConnections ?? config.WEBSOCKET_MAX_CONNECTIONS;
16
+ this.limitEnabled = limitConfig?.limitEnabled ?? config.WEBSOCKET_LIMIT_ENABLED;
10
17
  this._graphqlWs = new WebSocketServer({ noServer: true, path: __GRAPHQL_ENDPOINT__ });
11
18
  this.webSockets[__GRAPHQL_ENDPOINT__] = this._graphqlWs;
12
- this.webSockets[__GRAPHQL_ENDPOINT__].on('connection', () => {
13
- useServer({
14
- schema: moduleService.schema,
15
- // Using shared context creation function to maintain consistency with GraphqlWs
16
- context: async (ctx) => createWebSocketContext(ctx, moduleService, cache),
17
- }, this._graphqlWs);
18
- });
19
+ // Initialize useServer ONCE for the GraphQL WebSocket server
20
+ // This prevents memory leaks from creating new listeners on each connection
21
+ useServer({
22
+ schema: moduleService.schema,
23
+ // Using shared context creation function to maintain consistency with GraphqlWs
24
+ context: async (ctx) => createWebSocketContext(ctx, moduleService, cache),
25
+ }, this._graphqlWs);
19
26
  for (let key in multiplePathConfig) {
20
27
  if (!multiplePathConfig.hasOwnProperty(key)) {
21
28
  continue;
@@ -34,12 +41,22 @@ import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'
34
41
  httpServerUpgrade(httpServer) {
35
42
  httpServer.on('upgrade', (request, socket, head) => {
36
43
  const pathname = url.parse(request.url).pathname;
44
+ // Check connection limit before accepting new connections
45
+ if (this.limitEnabled && this.isConnectionLimitReached()) {
46
+ this.moduleService.logger?.warn?.(`WebSocket connection limit reached (${this.maxConnections}). Rejecting new connection.`);
47
+ socket.write('HTTP/1.1 503 Service Unavailable\r\n');
48
+ socket.write('Retry-After: 60\r\n');
49
+ socket.write('\r\n');
50
+ socket.destroy();
51
+ return;
52
+ }
37
53
  if (!this.webSockets[pathname]) {
38
54
  // in development
39
55
  if (pathname !== '/sockjs-node') {
40
56
  // need to destroy
41
57
  socket.destroy();
42
58
  }
59
+ return;
43
60
  }
44
61
  // code to run when a new connection is made
45
62
  this.webSockets[pathname].handleUpgrade(request, socket, head, (ws) => {
@@ -52,6 +69,31 @@ import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'
52
69
  // }, this.graphqlWs);
53
70
  return httpServer;
54
71
  }
72
+ /**
73
+ * Get total number of active WebSocket connections across all paths
74
+ */
75
+ getTotalConnections() {
76
+ return Object.values(this.webSockets).reduce((total, wsServer) => total + wsServer.clients.size, 0);
77
+ }
78
+ /**
79
+ * Get connection statistics for monitoring
80
+ */
81
+ getConnectionStats() {
82
+ const total = this.getTotalConnections();
83
+ return {
84
+ total,
85
+ graphql: this._graphqlWs.clients.size,
86
+ maxConnections: this.maxConnections,
87
+ limitEnabled: this.limitEnabled,
88
+ utilizationPercent: Math.round((total / this.maxConnections) * 100),
89
+ };
90
+ }
91
+ /**
92
+ * Check if connection limit has been reached
93
+ */
94
+ isConnectionLimitReached() {
95
+ return this.getTotalConnections() >= this.maxConnections;
96
+ }
55
97
  get graphqlWs() {
56
98
  return this._graphqlWs;
57
99
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WebsocketMultipathUpdate.mjs","sources":["../../src/servers/WebsocketMultipathUpdate.ts"],"sourcesContent":[null],"names":[],"mappings":"0KAea,wBAAwB,CAAA;AAKtB,IAAA,aAAA,CAAA;AACA,IAAA,KAAA,CAAA;IALH,UAAU,GAAoB,EAAE,CAAC;;AAEjC,IAAA,UAAU,CAAkB;AACpC,IAAA,WAAA,CACW,aAA6B,EAC7B,KAAsC,EAC7C,kBAAyC,EAAA;QAFlC,IAAa,CAAA,aAAA,GAAb,aAAa,CAAgB;QAC7B,IAAK,CAAA,KAAA,GAAL,KAAK,CAAiC;AAG7C,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI,eAAe,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC,CAAC;QACtF,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC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,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,QAAQ,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;KACvG;AAED;;AAEG;IACI,kBAAkB,GAAA;AAOrB,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzC,OAAO;YACH,KAAK;AACL,YAAA,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI;YACrC,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,YAAY,EAAE,IAAI,CAAC,YAAY;AAC/B,YAAA,kBAAkB,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,cAAc,IAAI,GAAG,CAAC;SACtE,CAAC;KACL;AAED;;AAEG;IACK,wBAAwB,GAAA;QAC5B,OAAO,IAAI,CAAC,mBAAmB,EAAE,IAAI,IAAI,CAAC,cAAc,CAAC;KAC5D;AAED,IAAA,IAAW,SAAS,GAAA;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;KAC1B;IACM,KAAK,GAAA;AACR,QAAA,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE;YAC/B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;SAChC;KACJ;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@common-stack/server-stack",
3
- "version": "8.2.5-alpha.8",
3
+ "version": "8.3.1-alpha.0",
4
4
  "description": "common core for higher packages to depend on",
5
5
  "license": "UNLICENSED",
6
6
  "author": "CDMBase LLC",
@@ -32,8 +32,8 @@
32
32
  "@cdm-logger/client": "^9.0.17",
33
33
  "@cdm-logger/server": "^9.0.17",
34
34
  "@cdmbase/graphql-type-uri": "^4.0.0",
35
- "@common-stack/codegen-zod": "8.2.4-alpha.18",
36
- "@common-stack/graphql-api": "8.2.5-alpha.1",
35
+ "@common-stack/codegen-zod": "8.2.5-alpha.15",
36
+ "@common-stack/graphql-api": "8.2.5-alpha.36",
37
37
  "@graphql-tools/links": "~9.0.1",
38
38
  "@graphql-tools/schema": "~10.0.6",
39
39
  "@graphql-tools/stitch": "~9.2.10",
@@ -78,12 +78,12 @@
78
78
  "subscriptions-transport-ws": "^0.11.0",
79
79
  "universal-cookie-express": "^4.0.1",
80
80
  "ws": "^8.11.0",
81
- "xstate": "^5.19.0",
81
+ "xstate": "^5.20.0",
82
82
  "zod": "^4.0.0"
83
83
  },
84
84
  "devDependencies": {
85
- "@common-stack/server-core": "8.2.5-alpha.0",
86
- "common": "8.2.4-alpha.14"
85
+ "@common-stack/server-core": "8.3.1-alpha.0",
86
+ "common": "8.2.5-alpha.35"
87
87
  },
88
88
  "peerDependencies": {
89
89
  "@cdm-logger/core": ">=7.0.12",
@@ -93,8 +93,8 @@
93
93
  "publishConfig": {
94
94
  "access": "public"
95
95
  },
96
- "gitHead": "24ee9761f4728e0e569bcc26cf49fc1693dcdc81",
97
96
  "typescript": {
98
97
  "definition": "lib/index.d.ts"
99
- }
98
+ },
99
+ "gitHead": "896a0a80a57b2ec62925bdda9ed35e61cd5c1e9f"
100
100
  }
@@ -1,34 +0,0 @@
1
- import 'reflect-metadata';
2
- import * as http from 'http';
3
- import * as express from 'express';
4
- import { Feature as ServerFeature } from '@common-stack/server-core';
5
- /**
6
- * Controls the lifecycle of the Application Server
7
- *
8
- * @export
9
- * @class StackServer
10
- */
11
- export declare class MainStackServer {
12
- httpServer: http.Server & {
13
- startListening?: (port: any) => void;
14
- };
15
- app: express.Express;
16
- private logger;
17
- private infrastructureFactory;
18
- private mainServiceContext;
19
- private microserviceContext;
20
- private multiPathWebsocket;
21
- private serverFeature;
22
- private settings;
23
- private options;
24
- private serviceBroker;
25
- private allModules;
26
- constructor(feature: ServerFeature, settings: any, options?: Record<string, unknown>);
27
- initialize(): Promise<void>;
28
- private setupMainServiceBrokerLifecycle;
29
- private setupMicroserviceBrokerLifecycle;
30
- private setupGraphQLSchema;
31
- private setupHttpServer;
32
- start(): Promise<void>;
33
- cleanup(): Promise<void>;
34
- }
@@ -1,29 +0,0 @@
1
- import { Feature as ServerFeature } from '@common-stack/server-core';
2
- import { Container } from 'inversify';
3
- import { ServiceBroker } from 'moleculer';
4
- import { InfrastructureContext } from './infrastructure';
5
- /**
6
- * Controls the lifecycle of the Microservice Server
7
- *
8
- * @export
9
- * @class StackServer
10
- */
11
- export declare class StackServer {
12
- private logger;
13
- private infrastructureFactory;
14
- private microserviceContext;
15
- private serverFeature;
16
- private settings;
17
- private onContainerCreated?;
18
- constructor(feature: ServerFeature, settings: any, options?: {
19
- onContainerCreated?: (params: {
20
- container: Container;
21
- broker: ServiceBroker;
22
- context: InfrastructureContext;
23
- }) => void | Promise<void>;
24
- });
25
- initialize(): Promise<void>;
26
- private setupMicroserviceBrokerLifecycle;
27
- start(): Promise<void>;
28
- cleanup(): Promise<void>;
29
- }
@@ -1,6 +0,0 @@
1
- interface ISchemaConfig {
2
- uri: string;
3
- wsUri: string;
4
- }
5
- export declare const remoteSchemaDetails: ISchemaConfig[];
6
- export {};
@@ -1,10 +0,0 @@
1
- export declare const resolvers: {
2
- AnyObject: import("graphql").GraphQLScalarType<unknown, unknown>;
3
- Date: import("graphql").GraphQLScalarType<Date, string>;
4
- Time: import("graphql").GraphQLScalarType<Date, string>;
5
- URI: any;
6
- URIInput: any;
7
- DateTime: import("graphql").GraphQLScalarType<Date, Date>;
8
- JSON: import("graphql").GraphQLScalarType<unknown, unknown>;
9
- JSONObject: import("graphql").GraphQLScalarType<unknown, unknown>;
10
- };
@@ -1,2 +0,0 @@
1
- import { GraphQLScalarType } from 'graphql';
2
- export declare const GraphQLAnyObject: GraphQLScalarType<unknown, unknown>;
@@ -1,24 +0,0 @@
1
- import { GraphQLSchema } from 'graphql';
2
- import { IGraphqlShieldRules } from '@common-stack/server-core';
3
- import { CdmLogger } from '@cdm-logger/core';
4
- interface IGraphqlOptions {
5
- schema: string | string[];
6
- resolvers: any;
7
- directives: any[];
8
- directiveResolvers: {
9
- [key: string]: any;
10
- };
11
- middlewares: any[];
12
- rules?: IGraphqlShieldRules;
13
- logger: CdmLogger.ILogger;
14
- }
15
- export declare class GatewaySchemaBuilder {
16
- private options;
17
- constructor(options: IGraphqlOptions);
18
- build(): Promise<GraphQLSchema>;
19
- private load;
20
- private createRemoteSchema;
21
- private loadRemoteSchema;
22
- private createOwnSchema;
23
- }
24
- export {};
@@ -1,24 +0,0 @@
1
- import { GraphQLSchema } from 'graphql';
2
- import { IGraphqlShieldRules } from '@common-stack/server-core';
3
- import { CdmLogger } from '@cdm-logger/core';
4
- interface IGraphqlOptions {
5
- schema: string | string[];
6
- resolvers: any;
7
- directives: any[];
8
- directiveResolvers: {
9
- [key: string]: any;
10
- };
11
- middlewares: any[];
12
- rules?: IGraphqlShieldRules;
13
- logger: CdmLogger.ILogger;
14
- }
15
- export declare class SubGraphSchemaBuilder {
16
- private readonly options;
17
- constructor(options: IGraphqlOptions);
18
- build(): Promise<GraphQLSchema>;
19
- private load;
20
- private createRemoteSchema;
21
- private loadRemoteSchema;
22
- private createOwnSchema;
23
- }
24
- export {};
@@ -1,4 +0,0 @@
1
- import { GraphQLSchema } from 'graphql';
2
- export declare function attachDirectiveResolvers(schema: GraphQLSchema, directiveResolvers: {
3
- [key: string]: Function;
4
- }): GraphQLSchema;
@@ -1,28 +0,0 @@
1
- import * as envalid from 'envalid';
2
- export declare const config: Readonly<{
3
- NODE_ENV: string;
4
- NATS_URL: string;
5
- NATS_USER: string;
6
- NATS_PW: string;
7
- GRAPHQL_ENDPOINT: string;
8
- BACKEND_URL: string;
9
- GRAPHQL_URL: string;
10
- CLIENT_URL: string;
11
- MONGO_URL: string;
12
- APP_NAME: string;
13
- REDIS_CLUSTER_URL: string;
14
- REDIS_URL: string;
15
- REDIS_CLUSTER_ENABLED: boolean;
16
- REDIS_SENTINEL_ENABLED: boolean;
17
- CONNECTION_ID: string;
18
- NAMESPACE: string;
19
- CROSS_NAMESPACES: string;
20
- LOG_LEVEL: string;
21
- METRICS_CONFIG: string;
22
- INNGEST_EVENT_KEY: string;
23
- INNGEST_SIGNING_KEY: string;
24
- INNGEST_IS_DEV: boolean;
25
- INNGEST_ENVIRONMENT: string;
26
- INNGEST_BASE_URL: string;
27
- INNGEST_CLIENT_ID: string;
28
- } & envalid.CleanedEnvAccessors>;
@@ -1 +0,0 @@
1
- export * from './env-config';
@@ -1,20 +0,0 @@
1
- import { BrokerOptions } from 'moleculer';
2
- /**
3
- * Moleculer ServiceBroker configuration file
4
- *
5
- * More info about options:
6
- * https://moleculer.services/docs/0.14/configuration.html
7
- *
8
- *
9
- * Overwrite options in production:
10
- * ================================
11
- * You can overwrite any option with environment variables.
12
- * For example to overwrite the 'logLevel', use `LOGLEVEL=warn` env var.
13
- * To overwrite a nested parameter, e.g. retryPolicy.retries, use `RETRYPOLICY_RETRIES=10` env var.
14
- *
15
- * To overwrite broker’s deeply nested default options, which are not presented in 'moleculer.config.ts',
16
- * via environment variables, use the `MOL_` prefix and double underscore `__` for nested properties in .env file.
17
- * For example, to set the cacher prefix to `MYCACHE`, you should declare an env var as `MOL_CACHER__OPTIONS__PREFIX=MYCACHE`.
18
- */
19
- declare const brokerConfig: BrokerOptions;
20
- export default brokerConfig;
@@ -1,26 +0,0 @@
1
- import { CdmLogger } from '@cdm-logger/core';
2
- import { TransporterType } from '../interfaces/moleculer';
3
- type ILogger = CdmLogger.ILogger;
4
- /**
5
- * Connection broker class
6
- *
7
- * @class ConnectionBroker
8
- */
9
- export declare class ConnectionBroker {
10
- private _mongoConnector;
11
- private _redisConnector;
12
- private _natsConnector;
13
- private _graphqlPubsubConnector;
14
- /**
15
- * Creates an instance of ConnectionBroker.
16
- * @param {*} options
17
- * @memberof ConnectionBroker
18
- */
19
- constructor(transporter: TransporterType, logger: ILogger);
20
- get mongoConnection(): Promise<import("mongoose").Connection>;
21
- get redisConnection(): Promise<import("ioredis").default | import("ioredis").Cluster>;
22
- get natsConnection(): import("nats").Client | Promise<import("nats").Client>;
23
- get graphqlPubsub(): Promise<import("graphql-nats-subscriptions").NatsPubSub | import("graphql-subscriptions").PubSub>;
24
- stop(): Promise<void>;
25
- }
26
- export {};
@@ -1,22 +0,0 @@
1
- import { PubSub } from 'graphql-subscriptions';
2
- import { NatsPubSub } from 'graphql-nats-subscriptions';
3
- import { GenericObject } from 'moleculer';
4
- import { CdmLogger } from '@cdm-logger/core';
5
- type ILogger = CdmLogger.ILogger;
6
- type PubSubOptions = {
7
- apolloLogging?: boolean;
8
- logger: ILogger;
9
- } & GenericObject;
10
- export declare class GraphqlPubSubConnector {
11
- private client;
12
- private opts;
13
- private logger;
14
- /**
15
- * Creates an instance of GraphqlPubSubConnector.
16
- * @param {*} opts
17
- * @memberof GraphqlPubSubConnector
18
- */
19
- constructor(opts?: PubSubOptions);
20
- getClient(): Promise<NatsPubSub | PubSub>;
21
- }
22
- export {};
@@ -1,21 +0,0 @@
1
- import { Connection, ConnectOptions } from 'mongoose';
2
- export declare class MongoConnector {
3
- private client;
4
- private db;
5
- private opts;
6
- private uri;
7
- private logger;
8
- constructor(uri: string, opts?: ConnectOptions);
9
- /**
10
- * Connect to database
11
- *
12
- * @memberof MongoConnector
13
- */
14
- connect(): Promise<Connection>;
15
- /**
16
- * Disconnect from database
17
- *
18
- * @memberof MongoConnector
19
- */
20
- disconnect(): Promise<void>;
21
- }
@@ -1,20 +0,0 @@
1
- import * as nats from 'nats';
2
- export declare class NatsConnector {
3
- private opts;
4
- private client;
5
- private logger;
6
- private connected;
7
- constructor(opts: nats.ClientOpts);
8
- /**
9
- * Connect to a NATS server
10
- *
11
- * @memberof NatsConnector
12
- */
13
- connect(): nats.Client | Promise<nats.Client>;
14
- /**
15
- * Disconnect from a NATS server
16
- *
17
- * @memberof NatsTransporter
18
- */
19
- disconnect(): void;
20
- }
@@ -1,30 +0,0 @@
1
- import * as IORedis from 'ioredis';
2
- export declare class RedisConnector {
3
- private client;
4
- private opts;
5
- private logger;
6
- /**
7
- * Creates an instance of RedisConnector.
8
- *
9
- * @param {object} opts
10
- */
11
- constructor(opts?: IORedis.ClusterOptions | IORedis.RedisOptions);
12
- /**
13
- * Connect to the Redis server
14
- *
15
- * @memberof RedisConnector
16
- */
17
- connect(): Promise<IORedis.Cluster | IORedis.Redis>;
18
- /**
19
- * Return redis or redis.cluster Client
20
- *
21
- * @memberof RedisConnection
22
- */
23
- getRedisClient(): IORedis.Cluster | IORedis.Redis;
24
- /**
25
- * Close Redis client connection.
26
- *
27
- * @memberof RedisConnection
28
- */
29
- disconnect(): Promise<void>;
30
- }
@@ -1,13 +0,0 @@
1
- import { Container } from 'inversify';
2
- /**
3
- * Example Inngest functions factory for tenant management
4
- * This is how individual modules can register their Inngest functions
5
- */
6
- export declare const tenantInngestFunctions: (container: Container) => {};
7
- /**
8
- * Example Feature configuration for a tenant module
9
- */
10
- export declare const TenantFeature: {
11
- inngestFunctions: (container: Container) => {};
12
- registerExpressMiddlewareFunc: (app: any, container: any) => void;
13
- };
@@ -1,14 +0,0 @@
1
- import { Feature } from '@common-stack/server-core';
2
- /**
3
- * Example of how to create a Feature that includes Inngest functions
4
- */
5
- export declare const TenantFeature: Feature<any, any>;
6
- /**
7
- * Example of how other modules can also contribute Inngest functions
8
- */
9
- export declare const NotificationFeature: Feature<any, any>;
10
- export declare const AnalyticsFeature: Feature<any, any>;
11
- /**
12
- * Example of combining multiple features with Inngest functions
13
- */
14
- export declare const createApplicationFeature: () => Feature<any, any>;
@@ -1,17 +0,0 @@
1
- import { Feature } from '@common-stack/server-core';
2
- /**
3
- * Example Feature that demonstrates using an array of Inngest function factories
4
- */
5
- export declare const MultiModuleFeature: Feature<any, any>;
6
- /**
7
- * Example: Feature for just user management
8
- */
9
- export declare const UserManagementFeature: Feature<any, any>;
10
- /**
11
- * Example: Feature for email campaigns
12
- */
13
- export declare const EmailCampaignFeature: Feature<any, any>;
14
- /**
15
- * Example: Combining multiple features - each with their own Inngest functions
16
- */
17
- export declare const ApplicationFeature: Feature<any, any>;
package/lib/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export { StackServer } from './StackServer';
2
- export { MainStackServer } from './MainStackServer';
3
- export { RESTDataSource } from '@apollo/datasource-rest';
4
- export { redisClientMiddleware } from './middleware/redis-client';
@@ -1,3 +0,0 @@
1
- import { ContainerModule } from 'inversify';
2
- import { InfrastructureContext, ConnectorConfig } from './types';
3
- export declare const createInfrastructureModule: (context: InfrastructureContext, connectorConfig: ConnectorConfig) => ContainerModule;
@@ -1,16 +0,0 @@
1
- import { WorkflowStep, ConnectorConfig } from './types';
2
- /**
3
- * Example custom workflow steps that can be added to the infrastructure initialization
4
- */
5
- export declare const metricsInitializationStep: WorkflowStep;
6
- export declare const customMigrationStep: WorkflowStep;
7
- export declare const healthCheckStep: WorkflowStep;
8
- export declare const cacheWarmingStep: WorkflowStep;
9
- export declare const HIGH_PERFORMANCE_CONFIG: ConnectorConfig;
10
- export declare const MINIMAL_CONFIG: ConnectorConfig;
11
- export declare function createCustomWorkflow(environment: string): WorkflowStep[];
12
- export declare function createCustomInfrastructureConfig(environment: string): {
13
- connectors: ConnectorConfig;
14
- workflows: WorkflowStep[];
15
- environment: string;
16
- };
@@ -1,5 +0,0 @@
1
- export * from './types';
2
- export * from './container-module';
3
- export * from './workflow-orchestrator';
4
- export * from './infrastructure-factory';
5
- export * from './inngest-factory';
@@ -1,45 +0,0 @@
1
- import { ServiceBroker } from 'moleculer';
2
- import { Container } from 'inversify';
3
- import { Feature as ServerFeature } from '@common-stack/server-core';
4
- import { CdmLogger } from '@cdm-logger/core';
5
- import { InfrastructureContext, ConnectorConfig, WorkflowStep } from './types';
6
- import { ConnectionBroker } from '../connectors/connection-broker';
7
- export interface BrokerInitializationOptions {
8
- type: 'main' | 'microservice';
9
- nodeId?: string;
10
- connectorConfig: ConnectorConfig;
11
- enableMetrics?: boolean;
12
- workflows?: WorkflowStep[];
13
- /**
14
- * Optional callback invoked immediately after container creation,
15
- * before services are instantiated.
16
- */
17
- onContainerCreated?: (params: {
18
- container: Container;
19
- broker: ServiceBroker;
20
- context: InfrastructureContext;
21
- }) => void | Promise<void>;
22
- }
23
- export declare class InfrastructureFactory {
24
- private logger;
25
- private connectionBroker;
26
- private orchestrator;
27
- constructor(logger: CdmLogger.ILogger);
28
- initialize(): Promise<void>;
29
- createBrokerAndContainer(options: BrokerInitializationOptions, serverFeature: ServerFeature, settings: any, existingAllModules?: ServerFeature): Promise<{
30
- broker: ServiceBroker;
31
- container: Container;
32
- context: InfrastructureContext;
33
- allModules: ServerFeature;
34
- }>;
35
- private loadAndComposeModules;
36
- private createContainerFromModules;
37
- private loadMoleculerServices;
38
- private createInfrastructureContext;
39
- private createServiceBroker;
40
- getConnectionBroker(): ConnectionBroker;
41
- cleanup(): Promise<void>;
42
- static createMainServiceConfig(): BrokerInitializationOptions;
43
- static createMicroserviceConfig(nodeId?: string): BrokerInitializationOptions;
44
- static createDevelopmentMicroserviceConfig(): BrokerInitializationOptions;
45
- }
@@ -1,8 +0,0 @@
1
- import { Inngest } from 'inngest';
2
- import { CdmLogger } from '@cdm-logger/core';
3
- export declare const generateInngestClientId: (configParams: {
4
- APP_NAME: string;
5
- NODE_ENV: string;
6
- INNGEST_CLIENT_ID?: string;
7
- }, logger: CdmLogger.ILogger) => string;
8
- export declare const createInngestClient: (logger: CdmLogger.ILogger) => Inngest;
@@ -1,28 +0,0 @@
1
- import { ServiceBroker } from 'moleculer';
2
- import { CdmLogger } from '@cdm-logger/core';
3
- import { Inngest } from 'inngest';
4
- export interface InfrastructureContext {
5
- broker: ServiceBroker;
6
- pubsub: any;
7
- mongoClient: any;
8
- logger: CdmLogger.ILogger;
9
- redisClient: any;
10
- inngestClient?: Inngest;
11
- }
12
- export interface WorkflowStep {
13
- name: string;
14
- order: number;
15
- enabled: boolean;
16
- execute: (context: InfrastructureContext) => Promise<void> | void;
17
- }
18
- export interface ConnectorConfig {
19
- redis: boolean;
20
- mongo: boolean;
21
- pubsub: boolean;
22
- inngest: boolean;
23
- }
24
- export interface InfrastructureConfig {
25
- connectors: ConnectorConfig;
26
- workflows: WorkflowStep[];
27
- environment: string;
28
- }