@nsshunt/stsappframework 3.0.104 → 3.0.106

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 (124) hide show
  1. package/dist/influxdb/influxDBManager.js +16 -17
  2. package/dist/influxdb/influxDBManager.js.map +1 -1
  3. package/dist/influxdb/influxDBManagerAgent.js +9 -13
  4. package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
  5. package/dist/influxdb/influxDBManagerBase.js +2 -6
  6. package/dist/influxdb/influxDBManagerBase.js.map +1 -1
  7. package/dist/influxdb/influxDBManagerService.js +10 -14
  8. package/dist/influxdb/influxDBManagerService.js.map +1 -1
  9. package/dist/instrumentationsubscriber.js +11 -15
  10. package/dist/instrumentationsubscriber.js.map +1 -1
  11. package/dist/kafka/IMKafkaManager.js +2 -6
  12. package/dist/kafka/IMKafkaManager.js.map +1 -1
  13. package/dist/kafkatesting/produce.js +1 -5
  14. package/dist/kafkatesting/produce.js.map +1 -1
  15. package/dist/processbase.js +7 -8
  16. package/dist/processbase.js.map +1 -1
  17. package/dist/server.js +1 -1
  18. package/dist/server.js.map +1 -1
  19. package/dist/tcpclient/app2.js +2 -2
  20. package/dist/tcpserver/appmaster.js +39 -16
  21. package/dist/tcpserver/appmaster.js.map +1 -1
  22. package/package.json +7 -7
  23. package/src/influxdb/influxDBManager.ts +16 -18
  24. package/src/influxdb/influxDBManagerAgent.ts +9 -11
  25. package/src/influxdb/influxDBManagerBase.ts +2 -4
  26. package/src/influxdb/influxDBManagerService.ts +10 -12
  27. package/src/instrumentationsubscriber.ts +11 -14
  28. package/src/kafka/IMKafkaManager.ts +2 -4
  29. package/src/kafkatesting/produce.ts +1 -3
  30. package/src/processbase.ts +7 -9
  31. package/src/server.ts +1 -1
  32. package/src/tcpclient/app2.ts +2 -2
  33. package/src/tcpserver/appmaster.ts +39 -17
  34. package/types/influxdb/influxDBManager.d.ts.map +1 -1
  35. package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
  36. package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
  37. package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
  38. package/types/instrumentationsubscriber.d.ts.map +1 -1
  39. package/types/kafka/IMKafkaManager.d.ts.map +1 -1
  40. package/types/processbase.d.ts +2 -2
  41. package/types/processbase.d.ts.map +1 -1
  42. package/types/tcpserver/appmaster.d.ts.map +1 -1
  43. package/src_working/authDefs.ts +0 -37
  44. package/src_working/authutilsnode.ts +0 -373
  45. package/src_working/commonTypes.ts +0 -239
  46. package/src_working/index.ts +0 -22
  47. package/src_working/influxdb/influxDBManager.ts +0 -970
  48. package/src_working/influxdb/influxDBManagerAgent.ts +0 -314
  49. package/src_working/influxdb/influxDBManagerBase.ts +0 -109
  50. package/src_working/influxdb/influxDBManagerService.ts +0 -373
  51. package/src_working/instrumentationsubscriber.ts +0 -283
  52. package/src_working/kafka/IMKafkaManager.ts +0 -152
  53. package/src_working/kafka/kafkaconsumer.ts +0 -82
  54. package/src_working/kafka/kafkamanager.ts +0 -186
  55. package/src_working/kafka/kafkaproducer.ts +0 -58
  56. package/src_working/kafkatesting/config.ts +0 -10
  57. package/src_working/kafkatesting/consume.ts +0 -116
  58. package/src_working/kafkatesting/produce.ts +0 -153
  59. package/src_working/masterprocessbase.ts +0 -598
  60. package/src_working/middleware/serverNetworkMiddleware.ts +0 -240
  61. package/src_working/network.ts +0 -36
  62. package/src_working/processbase.ts +0 -411
  63. package/src_working/processoptions.ts +0 -164
  64. package/src_working/publishertransports/publishTransportDirect.ts +0 -45
  65. package/src_working/publishertransports/publishTransportUtils.ts +0 -53
  66. package/src_working/server.ts +0 -141
  67. package/src_working/serverprocessbase.ts +0 -393
  68. package/src_working/singleprocessbase.ts +0 -121
  69. package/src_working/socketIoServerHelper.ts +0 -177
  70. package/src_working/stscontrollerbase.ts +0 -15
  71. package/src_working/stslatencycontroller.ts +0 -27
  72. package/src_working/stslatencyroute.ts +0 -16
  73. package/src_working/stsrouterbase.ts +0 -22
  74. package/src_working/tcpclient/app.ts +0 -19
  75. package/src_working/tcpclient/app2.ts +0 -56
  76. package/src_working/tcpserver/app.ts +0 -11
  77. package/src_working/tcpserver/appConfig.ts +0 -65
  78. package/src_working/tcpserver/appmaster.ts +0 -544
  79. package/src_working/validation/errors.ts +0 -6
  80. package/src_working/webworkertesting/app.ts +0 -49
  81. package/src_working/webworkertesting/worker.ts +0 -24
  82. package/src_working/workerprocessbase.test.ts +0 -47
  83. package/src_working/workerprocessbase.ts +0 -185
  84. package/src_working2/authDefs.ts +0 -37
  85. package/src_working2/authutilsnode.ts +0 -375
  86. package/src_working2/commonTypes.ts +0 -239
  87. package/src_working2/index.ts +0 -22
  88. package/src_working2/influxdb/influxDBManager.ts +0 -972
  89. package/src_working2/influxdb/influxDBManagerAgent.ts +0 -316
  90. package/src_working2/influxdb/influxDBManagerBase.ts +0 -111
  91. package/src_working2/influxdb/influxDBManagerService.ts +0 -375
  92. package/src_working2/instrumentationsubscriber.ts +0 -286
  93. package/src_working2/kafka/IMKafkaManager.ts +0 -154
  94. package/src_working2/kafka/kafkaconsumer.ts +0 -82
  95. package/src_working2/kafka/kafkamanager.ts +0 -186
  96. package/src_working2/kafka/kafkaproducer.ts +0 -58
  97. package/src_working2/kafkatesting/config.ts +0 -10
  98. package/src_working2/kafkatesting/consume.ts +0 -116
  99. package/src_working2/kafkatesting/produce.ts +0 -155
  100. package/src_working2/masterprocessbase.ts +0 -590
  101. package/src_working2/middleware/serverNetworkMiddleware.ts +0 -240
  102. package/src_working2/network.ts +0 -36
  103. package/src_working2/processbase.ts +0 -415
  104. package/src_working2/processoptions.ts +0 -164
  105. package/src_working2/publishertransports/publishTransportDirect.ts +0 -45
  106. package/src_working2/publishertransports/publishTransportUtils.ts +0 -53
  107. package/src_working2/server.ts +0 -141
  108. package/src_working2/serverprocessbase.ts +0 -393
  109. package/src_working2/singleprocessbase.ts +0 -123
  110. package/src_working2/socketIoServerHelper.ts +0 -177
  111. package/src_working2/stscontrollerbase.ts +0 -15
  112. package/src_working2/stslatencycontroller.ts +0 -27
  113. package/src_working2/stslatencyroute.ts +0 -16
  114. package/src_working2/stsrouterbase.ts +0 -22
  115. package/src_working2/tcpclient/app.ts +0 -19
  116. package/src_working2/tcpclient/app2.ts +0 -56
  117. package/src_working2/tcpserver/app.ts +0 -11
  118. package/src_working2/tcpserver/appConfig.ts +0 -65
  119. package/src_working2/tcpserver/appmaster.ts +0 -522
  120. package/src_working2/validation/errors.ts +0 -6
  121. package/src_working2/webworkertesting/app.ts +0 -49
  122. package/src_working2/webworkertesting/worker.ts +0 -24
  123. package/src_working2/workerprocessbase.test.ts +0 -47
  124. package/src_working2/workerprocessbase.ts +0 -187
@@ -1,164 +0,0 @@
1
- import { IServiceProcessContext } from '@nsshunt/stspublisherserver'
2
- //import { JSONObject } from '@nsshunt/stsutils'
3
- import express from 'express'
4
-
5
- import { IProcessBase } from './commonTypes'
6
-
7
- export interface STSExpressServer {
8
- get App(): express.Express
9
- }
10
-
11
- /**
12
- * Factory method that adds express routes to the express app object.
13
- */
14
- export type ExpressRouteFactory = (app: express.Express, stsApp: IProcessBase) => void
15
-
16
- export enum STSServerType {
17
- NONE = "NONE",
18
- EXPRESS = "EXPRESS",
19
- EXPRESS_TLS = "EXPRESS_TLS",
20
- TCPRAW_TLS = "TCPRAW_TLS",
21
- JSONRPC2_TLS = "JSONRPC_TLS"
22
- }
23
-
24
- //export interface ProcessOptions extends JSONObject {
25
- export interface ProcessOptions {
26
- /**
27
- * Is this service worker the master worker (thread).
28
- */
29
- isMaster: boolean
30
-
31
- /**
32
- * Unique service instance ID (uuidv4).
33
- */
34
- serviceInstanceId: string
35
-
36
- // Service details
37
-
38
- serverType: STSServerType
39
-
40
- /**
41
- * HTTPS service public key path.
42
- */
43
- httpsServerKeyPath: string
44
-
45
- /**
46
- * HTTPS service certificate (private key) path.
47
- */
48
- httpsServerCertificatePath: string
49
-
50
- /**
51
- * Determines whether the process will explicitly exit (using code 0) when any terminate signal is received.
52
- */
53
- processExitOnTerminate: boolean
54
-
55
- /**
56
- * Does this service run a Web Socket Server (wss).
57
- */
58
- wssServer: boolean
59
-
60
- /**
61
- * Service Prometheus metric support.
62
- */
63
- prometheusSupport: boolean
64
-
65
- /**
66
- * Service endpoint (without trailing /). Example: https://localhost
67
- */
68
- endpoint: string
69
-
70
- /**
71
- * Service API root (without trailing /). Example: /stsrest01/v1
72
- */
73
- apiRoot: string
74
-
75
- /**
76
- * Service listen port. Example: 3001.
77
- * Note that unix domain sockets are also supported. Example: /tmp/stsrest01.sock.
78
- * The socket file may also need permissions changed, i.e. chmodSync(port, 511); or chmodSync(port, 777);
79
- * Axios client calls will also need to use socketPath. Example: ..., socketPath: '/tmp/stsrest01.sock'
80
- * Ref: https://stackoverflow.com/questions/21342828/node-express-unix-domain-socket-permissions
81
- * To setup side car service (per running machine/node)
82
- * sudo mkdir /var/run/sts
83
- * sudo chown marcusbettens /var/run/sts
84
- * In .env file per service
85
- * PORT=/var/run/sts/stsrest01.sock
86
- */
87
- listenPort: string
88
-
89
- /**
90
- * Port that this service will be exposed externally on, i.e. clients will use this port to invoke APIs on this service.
91
- */
92
- port: string
93
-
94
- /**
95
- * Prometheus Cluster Server port (port used for cluster prometheus scrapes). Example: 3011.
96
- */
97
- prometheusClusterPort: string
98
-
99
- /**
100
- * Service Name. Example: Rest01
101
- */
102
- serviceName: string
103
-
104
- /**
105
- * Service Version. Example: 1.0.0
106
- */
107
- serviceVersion: string
108
-
109
- /**
110
- * Determines where logging is output to the console (stdout).
111
- */
112
- consoleLogging: boolean
113
-
114
- /**
115
- * Determines where logging is output to the logging instrument (if present).
116
- */
117
- instrumentLogging: boolean
118
-
119
- // Publisher options.
120
-
121
- serviceProcessContext?: IServiceProcessContext
122
-
123
- /**
124
- * Factory method that adds express routes to the express app object. Used for non-static content.
125
- * Non-Static content is applied after logging middleware.
126
- */
127
- expressServerRouteFactory?: ExpressRouteFactory
128
-
129
- /**
130
- * Factory method that adds express routes to the express app object for static content.
131
- * Static content is applied before logging middleware.
132
- */
133
- expressServerRouteStaticFactory?: ExpressRouteFactory
134
-
135
- /**
136
- * Determines whether the service will monitor its own health via the /latency API endpoint.
137
- * Note: The service must implement the /latency end-point for this to work.
138
- */
139
- useLatency: boolean
140
-
141
- /**
142
- * Determines whether this service is going to need database access.
143
- */
144
- useDatabase: boolean
145
-
146
- instrumentationObservationInterval: number
147
-
148
- instrumentationTimeWindow: number
149
-
150
- useRedisAdaptor: boolean
151
-
152
- redisAdaptorUrl?: string
153
-
154
- useRedisInstrumentationTransport?: boolean
155
-
156
- redisInstrumentationTransportUrl?: string
157
-
158
- workerExec?: string
159
-
160
- /**
161
- * Is this application using nodejs cluster mode?
162
- */
163
- clusterMode: boolean
164
- }
@@ -1,45 +0,0 @@
1
- /* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
2
-
3
- //import Debug from "debug";
4
- //const debug = Debug(`proc:${process.pid}:PublishRESTServer`);
5
-
6
- import { IPublisherTransport, IInstrumentPayload } from '@nsshunt/stspublisherserver'
7
- import { IMKafkaManager } from './../kafka/IMKafkaManager'
8
- import { InfluxDBManager } from './../influxdb/influxDBManager'
9
-
10
- import { PublishTransportUtils } from './publishTransportUtils'
11
-
12
- export class PublishTransportDirect implements IPublisherTransport
13
- {
14
- #influxDBManager: InfluxDBManager;
15
- #IMkafkaManager: IMKafkaManager;
16
-
17
- constructor()
18
- {
19
- this.#influxDBManager = new InfluxDBManager();
20
- this.#IMkafkaManager = new IMKafkaManager();
21
- this.#IMkafkaManager.Start();
22
- }
23
-
24
- // Returns true for success or false for failure.
25
- Publish = async (payload: IInstrumentPayload): Promise<boolean> =>
26
- {
27
- try {
28
- const updatedContext = PublishTransportUtils.GetServiceContext(payload.context.nid);
29
- payload.context = updatedContext as any;
30
-
31
- //this.#SendIPCMessageToMaster(InstrumentManagerEventName.UPDATE_INSTRUMENT_DATA, instrumentPayload)
32
- this.#influxDBManager.OutputInfluxDB(payload);
33
- this.#IMkafkaManager.OutputLogs(payload);
34
-
35
- return true;
36
- } catch (error)
37
- {
38
- return false;
39
- }
40
- }
41
-
42
- async Close(): Promise<boolean> {
43
- return true;
44
- }
45
- }
@@ -1,53 +0,0 @@
1
- import { ServiceProcessContext } from './../commonTypes'
2
- import { ModelDelimeter } from '@nsshunt/stsutils'
3
-
4
- export class PublishTransportUtils
5
- {
6
- static GetServiceContext(nid: string): ServiceProcessContext {
7
- // Return null if no context is required
8
- //return null;
9
- if (nid === ModelDelimeter.ROOT) {
10
- return { root: ModelDelimeter.ROOT };
11
- }
12
- const context: ServiceProcessContext = { nid };
13
- const idsplit = nid.split(ModelDelimeter.SEPERATOR);
14
-
15
- const serviceId = idsplit[0];
16
- const serviceInstanceId = idsplit[1].split(ModelDelimeter.NID_SEPERATOR)[0];
17
- const serviceInstanceProcessId = idsplit[1].split(ModelDelimeter.NID_SEPERATOR)[1];
18
-
19
- const serviceIdSplit = serviceId.split(ModelDelimeter.COMPONENT_SEPERATOR);
20
- const serviceName =serviceIdSplit[0]; // Defined in .env or environment variable
21
- const serviceVersion = serviceIdSplit[1]; // Defined in .env or environment variable
22
-
23
- context.serviceId = serviceId; // Service name and the service version
24
-
25
- if (typeof serviceInstanceId != 'undefined') {
26
- const serviceInstanceIdSplit = serviceInstanceId.split(ModelDelimeter.COMPONENT_SEPERATOR);
27
- const sid = serviceInstanceIdSplit[0];
28
- const hostName = serviceInstanceIdSplit[1];
29
-
30
- context.serviceInstanceId = serviceInstanceId; // Service unique id and the host name
31
- context.sid = sid; // Service unique id only, does not include host
32
- context.hostName = hostName; // Service Instance Host Name
33
-
34
- if (typeof serviceInstanceProcessId != 'undefined') {
35
- const serviceInstanceProcessIdSplit = serviceInstanceProcessId.split(ModelDelimeter.COMPONENT_SEPERATOR);
36
- const pid = parseInt(serviceInstanceProcessIdSplit[0]);
37
- const ppid = parseInt(serviceInstanceProcessIdSplit[1]);
38
- const isMaster = (pid === ppid ? true : false);
39
-
40
- context.serviceInstanceProcessId = serviceInstanceProcessId; // Service Instance OS Process ID (parent process id)
41
- context.pid = pid; // Service Instance OS Process ID (parent process id)
42
- context.ppid = ppid; // Service Instance OS Parent Process ID if worker. Will be pid if parent process.
43
- context.isMaster = isMaster; // True if is Master Process
44
- context.isWorker = !isMaster; // True if is Worker Process
45
- context.serviceName = serviceName; // Defined in .env or environment variable
46
- context.serviceVersion = serviceVersion; // Defined in .env or environment variable
47
- context.serviceInstanceId = serviceInstanceId; // unique service id with host
48
- }
49
- }
50
-
51
- return context;
52
- }
53
- }
@@ -1,141 +0,0 @@
1
- /* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
2
- import express, { Express, Request, Response, NextFunction } from 'express';
3
-
4
- import cors from 'cors';
5
- import cookieParser from 'cookie-parser';
6
-
7
- import { RequestLoggerMiddleware, RequestLoggerMiddlewareEventName } from '@nsshunt/stspublisherserver'
8
-
9
- import { ProcessOptions } from './processoptions'
10
-
11
- import { $Options } from '@nsshunt/stsconfig'
12
- const goptions = $Options()
13
-
14
- import { IProcessBase } from './commonTypes'
15
- import { Gauge, InstrumentGaugeTelemetry, InstrumentHistogramTelemetry, InstrumentVelocityTelemetry } from '@nsshunt/stsinstrumentation'
16
-
17
- import { ISocketRecord, ServerNetworkMiddleware, ServerNetworkMiddlewareEventName } from './middleware/serverNetworkMiddleware'
18
-
19
- export class STSExpressServer
20
- {
21
- #app: Express;
22
-
23
- constructor(options: ProcessOptions, stsApp: IProcessBase)
24
- {
25
- // Standard RequestLoggerMiddleware for all STS services
26
- const requestLoggerMiddleware = new RequestLoggerMiddleware({
27
- ignoresocketio: goptions.ignoresocketio
28
- });
29
-
30
- const serverNetworkMiddleware = new ServerNetworkMiddleware({
31
- name: (stsApp.options as ProcessOptions).serviceName,
32
- outputDebug: false
33
- });
34
-
35
- serverNetworkMiddleware.on(ServerNetworkMiddlewareEventName.UpdateInstrument_SERVER_NET_VAL, (data: ISocketRecord) => {
36
- //console.log(chalk.magenta(`serverNetworkMiddleware: [${JSON.stringify(data)}]`));
37
- stsApp.UpdateInstrument(Gauge.NETWORK_RX_GAUGE, {
38
- Inc: data.requestBytesRead
39
- } as InstrumentGaugeTelemetry);
40
-
41
- stsApp.UpdateInstrument(Gauge.NETWORK_TX_GAUGE, {
42
- Inc: data.requestBytesWritten
43
- } as InstrumentGaugeTelemetry);
44
- });
45
-
46
- requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_AR_INC, () => {
47
- stsApp.UpdateInstrument(Gauge.ACTIVE_REQUEST_GAUGE, {
48
- Inc: 1
49
- } as InstrumentGaugeTelemetry);
50
- });
51
-
52
- requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_AR_DEC, () => {
53
- stsApp.UpdateInstrument(Gauge.ACTIVE_REQUEST_GAUGE, {
54
- Dec: 1
55
- } as InstrumentGaugeTelemetry);
56
- });
57
-
58
- requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_DH_VAL, (timeInMs) => {
59
- stsApp.UpdateInstrument(Gauge.DURATION_HISTOGRAM_GAUGE, {
60
- val: timeInMs
61
- } as InstrumentHistogramTelemetry);
62
- });
63
-
64
- requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_D_VAL, (timeInMs) => {
65
- stsApp.UpdateInstrument(Gauge.DURATION_GAUGE, {
66
- val: timeInMs
67
- } as InstrumentHistogramTelemetry);
68
- });
69
-
70
- requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_RC_INC, () => {
71
- stsApp.UpdateInstrument(Gauge.REQUEST_COUNT_GAUGE, {
72
- Inc: 1
73
- } as InstrumentGaugeTelemetry);
74
- });
75
-
76
- requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_V_INC, () => {
77
- if (stsApp.InstrumentExists(Gauge.VELOCITY_GAUGE)) {
78
- stsApp.UpdateInstrument(Gauge.VELOCITY_GAUGE, {
79
- Inc: 1
80
- } as InstrumentVelocityTelemetry);
81
- }
82
- });
83
-
84
- const app = express();
85
- this.#app = app;
86
-
87
- // https://stackoverflow.com/questions/19743396/cors-cannot-use-wildcard-in-access-control-allow-origin-when-credentials-flag-i
88
- // See answer from Christoph Hansen is thread above ...
89
- // https://expressjs.com/en/resources/middleware/cors.html
90
- const corsConfig = {
91
- credentials: true,
92
- origin: true,
93
- };
94
-
95
- app.use(cors(corsConfig));
96
-
97
- app.use(cookieParser())
98
-
99
- app.use(express.urlencoded({ extended: false, limit: goptions.maxPayloadSize }));
100
-
101
- app.use(express.json({limit: goptions.maxPayloadSize}));
102
-
103
- // Allow the static SPA to also be servered by this app
104
- //app.use('/static', express.static(path.join(__dirname, 'public')))
105
- if (options.expressServerRouteStaticFactory) {
106
- options.expressServerRouteStaticFactory(app, stsApp);
107
- }
108
-
109
- app.use(requestLoggerMiddleware.Middleware.bind(requestLoggerMiddleware));
110
-
111
- app.use(serverNetworkMiddleware.Middleware.bind(serverNetworkMiddleware));
112
-
113
- if (options.expressServerRouteFactory) {
114
- options.expressServerRouteFactory(app, stsApp);
115
- }
116
-
117
- // Express error handling fall-back
118
- app.use(function(err: any, req: Request, res: Response, next: NextFunction) {
119
- //@@ add to errors metric here - perhaps break down by type
120
-
121
- if (err) {
122
- //@@console.log(err);
123
- res.status(err.status).send(err);
124
- } else {
125
- next();
126
- }
127
- /*
128
- if(err.name === 'UnauthorizedError') {
129
- res.status(401).send(err);
130
- } else {
131
- next();
132
- }
133
- */
134
- });
135
- }
136
-
137
- get App(): Express
138
- {
139
- return this.#app;
140
- }
141
- }