@nsshunt/stsappframework 3.2.1 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonTypes.js +69 -0
- package/dist/commonTypes.js.map +1 -0
- package/dist/controller/stscontrollerbase.js +14 -0
- package/dist/controller/stscontrollerbase.js.map +1 -0
- package/dist/controller/stslatencycontroller.js +28 -0
- package/dist/controller/stslatencycontroller.js.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/stsTransportLoggerWinston.js +22 -0
- package/dist/logger/stsTransportLoggerWinston.js.map +1 -0
- package/dist/logger/stsTransportWinston.js +43 -0
- package/dist/logger/stsTransportWinston.js.map +1 -0
- package/{src/middleware/serverNetworkMiddleware.ts → dist/middleware/serverNetworkMiddleware.js} +80 -124
- package/dist/middleware/serverNetworkMiddleware.js.map +1 -0
- package/dist/network.js +38 -0
- package/dist/network.js.map +1 -0
- package/dist/process/masterprocessbase.js +558 -0
- package/dist/process/masterprocessbase.js.map +1 -0
- package/{src/process/processbase.ts → dist/process/processbase.js} +150 -222
- package/dist/process/processbase.js.map +1 -0
- package/{src/process/serverprocessbase.ts → dist/process/serverprocessbase.js} +158 -212
- package/dist/process/serverprocessbase.js.map +1 -0
- package/dist/process/singleprocessbase.js +55 -0
- package/dist/process/singleprocessbase.js.map +1 -0
- package/{src/process/workerprocessbase.ts → dist/process/workerprocessbase.js} +93 -107
- package/dist/process/workerprocessbase.js.map +1 -0
- package/{src/publishertransports/publishTransportUtils.ts → dist/publishertransports/publishTransportUtils.js} +18 -24
- package/dist/publishertransports/publishTransportUtils.js.map +1 -0
- package/dist/route/stslatencyroute.js +15 -0
- package/dist/route/stslatencyroute.js.map +1 -0
- package/dist/route/stsrouterbase.js +21 -0
- package/dist/route/stsrouterbase.js.map +1 -0
- package/dist/stsexpressserver.js +115 -0
- package/dist/stsexpressserver.js.map +1 -0
- package/dist/validation/errors.js +10 -0
- package/dist/validation/errors.js.map +1 -0
- package/dist/vitesttesting/appConfig.js +93 -0
- package/dist/vitesttesting/appConfig.js.map +1 -0
- package/dist/vitesttesting/appSingleWSS.js +122 -0
- package/dist/vitesttesting/appSingleWSS.js.map +1 -0
- package/dist/vitesttesting/server.js +15 -0
- package/dist/vitesttesting/server.js.map +1 -0
- package/dist/vitesttesting/singleservertest.test.js +286 -0
- package/dist/vitesttesting/singleservertest.test.js.map +1 -0
- package/dist/vitesttesting/wsevents.js +3 -0
- package/dist/vitesttesting/wsevents.js.map +1 -0
- package/package.json +7 -3
- package/.github/dependabot.yml +0 -13
- package/.github/workflows/npm-publish.yml +0 -47
- package/.gitignore copy +0 -108
- package/build.sh +0 -37
- package/esbuild.config.js +0 -81
- package/eslint.config.mjs +0 -55
- package/jest/setEnvVars.js +0 -19
- package/keys/server.cert +0 -21
- package/keys/server.key +0 -28
- package/local-redis-stack.conf +0 -2
- package/run-grpc-client.sh +0 -2
- package/run-grpc-server.sh +0 -2
- package/run1.sh +0 -20
- package/run2.sh +0 -20
- package/run3.sh +0 -20
- package/runc1.sh +0 -19
- package/runc2.sh +0 -19
- package/runkafka.sh +0 -19
- package/runkafkaconsume01.sh +0 -21
- package/runkafkaconsume02.sh +0 -21
- package/runpromise.sh +0 -5
- package/runredis.sh +0 -5
- package/runredis1.sh +0 -4
- package/runredis2.sh +0 -24
- package/runredis3.sh +0 -4
- package/runtest1.sh +0 -19
- package/runtest2.sh +0 -19
- package/runtest_ipc_legacy.sh +0 -19
- package/runtest_ipcex.sh +0 -19
- package/runtest_redis.sh +0 -19
- package/runtest_ww.sh +0 -19
- package/src/commonTypes.ts +0 -374
- package/src/controller/stscontrollerbase.ts +0 -14
- package/src/controller/stslatencycontroller.ts +0 -26
- package/src/index.ts +0 -13
- package/src/logger/stsTransportLoggerWinston.ts +0 -24
- package/src/logger/stsTransportWinston.ts +0 -48
- package/src/network.ts +0 -36
- package/src/process/masterprocessbase.ts +0 -674
- package/src/process/singleprocessbase.ts +0 -63
- package/src/route/stslatencyroute.ts +0 -15
- package/src/route/stsrouterbase.ts +0 -21
- package/src/stsexpressserver.ts +0 -137
- package/src/validation/errors.ts +0 -6
- package/src/vitesttesting/appConfig.ts +0 -111
- package/src/vitesttesting/appSingleWSS.ts +0 -142
- package/src/vitesttesting/server.ts +0 -17
- package/src/vitesttesting/singleservertest.test.ts +0 -352
- package/src/vitesttesting/wsevents.ts +0 -44
- package/tsconfig.json +0 -42
- package/vite.config.ts +0 -19
package/runtest_ipc_legacy.sh
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
# openssl req -nodes -new -x509 -keyout server.key -out server.cert
|
|
3
|
-
clear; \
|
|
4
|
-
export STS_PROJ_ROOT=./..; \
|
|
5
|
-
STSENVFILE=$STS_PROJ_ROOT/stsglobalresources/.env \
|
|
6
|
-
REST01_PORT=3003 \
|
|
7
|
-
REST01_HOST_PORT=3003 \
|
|
8
|
-
REST01_ENDPOINT="https://stscore.stsmda.org" \
|
|
9
|
-
MAX_CPU=4 \
|
|
10
|
-
AS_ENDPOINT=https://stscore.stsmda.org \
|
|
11
|
-
AS_HOST_PORT=3002 \
|
|
12
|
-
AS_PORT=3002 \
|
|
13
|
-
DB_HOST=localhost:5432 \
|
|
14
|
-
DB_PASSWORD=postgres \
|
|
15
|
-
HTTPS_SERVER_KEY_PATH=/etc/letsencrypt/live/stsmda.org/privkey.pem \
|
|
16
|
-
HTTPS_SERVER_CERT_PATH=/etc/letsencrypt/live/stsmda.org/fullchain.pem \
|
|
17
|
-
DEBUG=proc* \
|
|
18
|
-
UV_THREADPOOL_SIZE=64 \
|
|
19
|
-
node dist/testing/app_ipc_legacy
|
package/runtest_ipcex.sh
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
# openssl req -nodes -new -x509 -keyout server.key -out server.cert
|
|
3
|
-
clear; \
|
|
4
|
-
export STS_PROJ_ROOT=./..; \
|
|
5
|
-
STSENVFILE=$STS_PROJ_ROOT/stsglobalresources/.env \
|
|
6
|
-
REST01_PORT=3003 \
|
|
7
|
-
REST01_HOST_PORT=3003 \
|
|
8
|
-
REST01_ENDPOINT="https://stscore.stsmda.org" \
|
|
9
|
-
MAX_CPU=4 \
|
|
10
|
-
AS_ENDPOINT=https://stscore.stsmda.org \
|
|
11
|
-
AS_HOST_PORT=3002 \
|
|
12
|
-
AS_PORT=3002 \
|
|
13
|
-
DB_HOST=localhost:5432 \
|
|
14
|
-
DB_PASSWORD=postgres \
|
|
15
|
-
HTTPS_SERVER_KEY_PATH=/etc/letsencrypt/live/stsmda.org/privkey.pem \
|
|
16
|
-
HTTPS_SERVER_CERT_PATH=/etc/letsencrypt/live/stsmda.org/fullchain.pem \
|
|
17
|
-
DEBUG=proc* \
|
|
18
|
-
UV_THREADPOOL_SIZE=64 \
|
|
19
|
-
node dist/testing/app_ipcex
|
package/runtest_redis.sh
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
# openssl req -nodes -new -x509 -keyout server.key -out server.cert
|
|
3
|
-
clear; \
|
|
4
|
-
export STS_PROJ_ROOT=./..; \
|
|
5
|
-
STSENVFILE=$STS_PROJ_ROOT/stsglobalresources/.env \
|
|
6
|
-
REST01_PORT=3003 \
|
|
7
|
-
REST01_HOST_PORT=3003 \
|
|
8
|
-
REST01_ENDPOINT="https://stscore.stsmda.org" \
|
|
9
|
-
MAX_CPU=4 \
|
|
10
|
-
AS_ENDPOINT=https://stscore.stsmda.org \
|
|
11
|
-
AS_HOST_PORT=3002 \
|
|
12
|
-
AS_PORT=3002 \
|
|
13
|
-
DB_HOST=localhost:5432 \
|
|
14
|
-
DB_PASSWORD=postgres \
|
|
15
|
-
HTTPS_SERVER_KEY_PATH=/etc/letsencrypt/live/stsmda.org/privkey.pem \
|
|
16
|
-
HTTPS_SERVER_CERT_PATH=/etc/letsencrypt/live/stsmda.org/fullchain.pem \
|
|
17
|
-
DEBUG=proc* \
|
|
18
|
-
UV_THREADPOOL_SIZE=64 \
|
|
19
|
-
node dist/testing/app
|
package/runtest_ww.sh
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
# openssl req -nodes -new -x509 -keyout server.key -out server.cert
|
|
3
|
-
clear; \
|
|
4
|
-
export STS_PROJ_ROOT=./..; \
|
|
5
|
-
STSENVFILE=$STS_PROJ_ROOT/stsglobalresources/.env \
|
|
6
|
-
REST01_PORT=3003 \
|
|
7
|
-
REST01_HOST_PORT=3003 \
|
|
8
|
-
REST01_ENDPOINT="https://stscore.stsmda.org" \
|
|
9
|
-
MAX_CPU=1 \
|
|
10
|
-
AS_ENDPOINT=https://stscore.stsmda.org \
|
|
11
|
-
AS_HOST_PORT=3002 \
|
|
12
|
-
AS_PORT=3002 \
|
|
13
|
-
DB_HOST=localhost:5432 \
|
|
14
|
-
DB_PASSWORD=postgres \
|
|
15
|
-
HTTPS_SERVER_KEY_PATH=/etc/letsencrypt/live/stsmda.org/privkey.pem \
|
|
16
|
-
HTTPS_SERVER_CERT_PATH=/etc/letsencrypt/live/stsmda.org/fullchain.pem \
|
|
17
|
-
DEBUG=proc* \
|
|
18
|
-
UV_THREADPOOL_SIZE=64 \
|
|
19
|
-
node dist/testing/app_ww
|
package/src/commonTypes.ts
DELETED
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
-
import express from 'express'
|
|
3
|
-
|
|
4
|
-
import { JSONObject, ISTSLogger, ModelDelimeter, CheckValidChar } from "@nsshunt/stsutils"
|
|
5
|
-
import { PublishInstrumentController, InstrumentDefinitions,
|
|
6
|
-
IContextBase, InstrumentBaseTelemetry, Gauge} from '@nsshunt/stsobservability'
|
|
7
|
-
|
|
8
|
-
import { STSDefaultClientToServerEvents, STSDefaultServerToClientEvents } from '@nsshunt/stssocketioutils'
|
|
9
|
-
|
|
10
|
-
import { IDBAccessLayer } from '@nsshunt/stsdatamanagement'
|
|
11
|
-
import { TinyEmitter } from "tiny-emitter";
|
|
12
|
-
|
|
13
|
-
import { Worker, Address } from 'node:cluster'
|
|
14
|
-
|
|
15
|
-
import { ISocketIoServerHelper } from '@nsshunt/stssocketioutils'
|
|
16
|
-
|
|
17
|
-
export interface IServiceProcessContext extends IContextBase {
|
|
18
|
-
serviceId?: string // Service name and the service version
|
|
19
|
-
|
|
20
|
-
serviceInstanceId?: string // Service unique id and the host name
|
|
21
|
-
sid?: string // Service unique id only, does not include host
|
|
22
|
-
hostName?: string // Service Instance Host Name
|
|
23
|
-
|
|
24
|
-
// Leaf level attributes
|
|
25
|
-
serviceInstanceProcessId?: string // Service Instance OS Process ID (parent process id)
|
|
26
|
-
pid?: number // Service Instance OS Process ID (parent process id)
|
|
27
|
-
ppid?: number// Service Instance OS Parent Process ID if worker. Will be pid if parent process.
|
|
28
|
-
isMaster?: boolean // True if is Master Process
|
|
29
|
-
isWorker?: boolean // True if is Worker Process
|
|
30
|
-
serviceName?: string // Defined in .env or environment variable
|
|
31
|
-
serviceVersion?: string // Defined in .env or environment variable
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function CreateServiceProcessContext(serviceName: string, serviceVersion: string, serviceInstanceId: string,
|
|
35
|
-
hostName: string, processId: number, parentProcessId: number): IServiceProcessContext {
|
|
36
|
-
|
|
37
|
-
const checkParams = [
|
|
38
|
-
[ 'servicename', serviceName ],
|
|
39
|
-
[ 'serviceversion', serviceVersion ],
|
|
40
|
-
[ 'hostname', hostName ],
|
|
41
|
-
[ 'serviceInstanceId', serviceInstanceId ]
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
// CHeck for invalid strings
|
|
45
|
-
CheckValidChar(checkParams);
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
nid: `\
|
|
49
|
-
${serviceName}${ModelDelimeter.COMPONENT_SEPERATOR}${serviceVersion}\
|
|
50
|
-
${ModelDelimeter.SEPERATOR}\
|
|
51
|
-
${serviceInstanceId}${ModelDelimeter.COMPONENT_SEPERATOR}${hostName}\
|
|
52
|
-
${ModelDelimeter.NID_SEPERATOR}\
|
|
53
|
-
${processId.toString()}${ModelDelimeter.COMPONENT_SEPERATOR}${parentProcessId.toString()}`,
|
|
54
|
-
serviceName,
|
|
55
|
-
serviceVersion,
|
|
56
|
-
serviceInstanceId,
|
|
57
|
-
hostName,
|
|
58
|
-
processId: processId.toString(),
|
|
59
|
-
parentProcessId: parentProcessId.toString()
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export enum IPCMessageCommand {
|
|
64
|
-
AddWorker = 'AddWorker',
|
|
65
|
-
DeleteWorker = 'DeleteWorker',
|
|
66
|
-
GetConfig = 'GetConfig'
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface IPCMessagePayload {
|
|
70
|
-
requestResponse: boolean,
|
|
71
|
-
id: string,
|
|
72
|
-
command: IPCMessageCommand,
|
|
73
|
-
requestDetail?: JSONObject,
|
|
74
|
-
responseDetail?: JSONObject
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface IPCMessage {
|
|
78
|
-
iPCMessagePayload: IPCMessagePayload
|
|
79
|
-
cb: () => void,
|
|
80
|
-
timeout: NodeJS.Timeout
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export type IPCMessages = Record<string, IPCMessage>
|
|
84
|
-
|
|
85
|
-
//------------------------------------
|
|
86
|
-
|
|
87
|
-
export interface IProcessBaseEvents {
|
|
88
|
-
'processSigint': []
|
|
89
|
-
'processSigterm': []
|
|
90
|
-
'processExit': [ workerid: number ]
|
|
91
|
-
|
|
92
|
-
'ProcessTerminate': []
|
|
93
|
-
|
|
94
|
-
'clusterListening': [ worker: Worker, address: Address ];
|
|
95
|
-
'clusterOnline': [ worker: Worker ]
|
|
96
|
-
'clusterExit': [ worker: Worker, code: number, signal: string ]
|
|
97
|
-
'allListening': []
|
|
98
|
-
|
|
99
|
-
'workerMessage': [ id: number, payload: any ]
|
|
100
|
-
'workerError': [ error: Error ]
|
|
101
|
-
'workerAdded': [ id: number ]
|
|
102
|
-
'workerExit': [ code: number, signal: string ]
|
|
103
|
-
|
|
104
|
-
'prometheusScrapesListening': [ url: string, endpoint: string, prometheusClusterPort: string ]
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface IProcessBase extends TinyEmitter {
|
|
108
|
-
SetupInstrumentation(): void
|
|
109
|
-
GetAdditionalInstruments(): InstrumentDefinitions
|
|
110
|
-
CollectAdditionalTelemetry(): void
|
|
111
|
-
ProcessStartup: () => void
|
|
112
|
-
UpdateInstrument: (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry) => void
|
|
113
|
-
get InstrumentController(): PublishInstrumentController | null
|
|
114
|
-
|
|
115
|
-
LogErrorMessage(message: any): void
|
|
116
|
-
LogInfoMessage(message: any): void
|
|
117
|
-
LogMessageToLoggerInstrument(message: any): void
|
|
118
|
-
InstrumentExists(instrumentName: Gauge): boolean
|
|
119
|
-
ProcessTerminate(): Promise<void>
|
|
120
|
-
|
|
121
|
-
GetUIController(): any
|
|
122
|
-
get options(): ProcessOptions
|
|
123
|
-
get socketIoServerHelper(): ISocketIoServerHelper<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents> | null
|
|
124
|
-
set socketIoServerHelper(value: ISocketIoServerHelper<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents> | null)
|
|
125
|
-
TerminateDatabase(): Promise<void>
|
|
126
|
-
get accessLayer(): IDBAccessLayer | null
|
|
127
|
-
get shuttingDown(): boolean
|
|
128
|
-
//@@get redisMessageHandler(): RedisMessageHandler
|
|
129
|
-
|
|
130
|
-
emit<K extends keyof IProcessBaseEvents>(event: K, ...arg: IProcessBaseEvents[K]): this
|
|
131
|
-
on<K extends keyof IProcessBaseEvents>(event: K, callback: (...arg: IProcessBaseEvents[K]) => void): this
|
|
132
|
-
off<K extends keyof IProcessBaseEvents>(event: K, callback: (...arg: IProcessBaseEvents[K]) => void): this
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export interface IMasterProcessBase extends IProcessBase {
|
|
136
|
-
WorkerMessageEvent(messageId: number, msg: any): any
|
|
137
|
-
SetupServer: () => Promise<void>
|
|
138
|
-
SetupServerEx: () => Promise<void>
|
|
139
|
-
|
|
140
|
-
KillWorker: (id: string, signal: NodeJS.Signals, options: any, killProcess: boolean, allowKillAll: boolean) => boolean
|
|
141
|
-
KillWorkers: (signal: NodeJS.Signals, keepOne?: boolean) => void
|
|
142
|
-
IncWorkers: () => void
|
|
143
|
-
DecWorkers: () => void
|
|
144
|
-
|
|
145
|
-
AddWorker: (options: any) => number
|
|
146
|
-
MasterStarted(): void
|
|
147
|
-
|
|
148
|
-
BroadcastDataToWorkers: (command: any, data: any) => void
|
|
149
|
-
ProcessIPCCommand(iPCMessagePayload: IPCMessagePayload): Promise<IPCMessagePayload>
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export interface IServerProcessBase extends IProcessBase {
|
|
153
|
-
get httpServer(): any
|
|
154
|
-
get io(): any
|
|
155
|
-
get expressServer(): STSExpressServer | null
|
|
156
|
-
set expressServer(server: STSExpressServer | null)
|
|
157
|
-
Terminate: (clusterPerformExit: boolean, signal?: any) => Promise<void>
|
|
158
|
-
SetupSTSServer: () => Promise<void>
|
|
159
|
-
CollectAdditionalTelemetry(): void
|
|
160
|
-
SetupServer(): Promise<boolean>
|
|
161
|
-
SetupServerEx: () => Promise<boolean>
|
|
162
|
-
ProcessStarted(): void
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export interface ISingleProcessBase extends IServerProcessBase {
|
|
166
|
-
TerminateApplication(): Promise<void>
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export interface IWorkerProcessBase extends IServerProcessBase {
|
|
170
|
-
ReceivedMessageFromMaster(msg: any): void
|
|
171
|
-
AddWorker: (options: any) => Promise<string>
|
|
172
|
-
DeleteWorker: (workerId: string, options: any) => Promise<JSONObject>
|
|
173
|
-
GetMasterProcessOptions: () => Promise<JSONObject>
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// -----------------------------------------------------------------------------
|
|
177
|
-
|
|
178
|
-
/*
|
|
179
|
-
export interface IInfluxDBManagerOptions {
|
|
180
|
-
token: string // API access token
|
|
181
|
-
url: string // end-pont for API
|
|
182
|
-
org: string // organisation
|
|
183
|
-
bucket: string // bucket to store results
|
|
184
|
-
agent?: {
|
|
185
|
-
influxDB_keepAlive: boolean
|
|
186
|
-
influxDB_maxSockets?: number
|
|
187
|
-
influxDB_maxTotalSockets?: number
|
|
188
|
-
influxDB_maxFreeSockets?: number
|
|
189
|
-
influxDB_timeout?: number
|
|
190
|
-
influxDB_rejectUnauthorized?: boolean
|
|
191
|
-
}
|
|
192
|
-
logger: ISTSLogger
|
|
193
|
-
}
|
|
194
|
-
*/
|
|
195
|
-
|
|
196
|
-
/*
|
|
197
|
-
export type ConsumeMessageCB = (topic: string, partition: number, message: KafkaMessage, heartbeat: () => Promise<void>, pause: () => () => void) => void;
|
|
198
|
-
export type ConsumeMessageErrorCB = (error: any) => void;
|
|
199
|
-
|
|
200
|
-
export interface IKafkaConsumer {
|
|
201
|
-
get consumer(): Consumer
|
|
202
|
-
get id(): string
|
|
203
|
-
Connect(errorCb: (error: any) => void): Promise<void>
|
|
204
|
-
Disconnect(errorCb: (error: any) => void): Promise<void>
|
|
205
|
-
Subscribe: (topics: string[], fromBeginning: boolean, errorCb: (error: any) => void) => Promise<void>
|
|
206
|
-
Stop: (errorCb: (error: any) => void) => Promise<void>
|
|
207
|
-
StartConsumingMessages: (autoCommit: boolean, cb: ConsumeMessageCB, errorCb: ConsumeMessageErrorCB) => Promise<void>
|
|
208
|
-
}
|
|
209
|
-
*/
|
|
210
|
-
|
|
211
|
-
export const iss = `https://stscore.stsmda.org/oauth2/v2.0`;
|
|
212
|
-
|
|
213
|
-
export interface STSExpressServer {
|
|
214
|
-
get App(): express.Express
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Factory method that adds express routes to the express app object.
|
|
219
|
-
*/
|
|
220
|
-
export type ExpressRouteFactory = (app: express.Express, stsApp: IProcessBase) => void
|
|
221
|
-
|
|
222
|
-
/*
|
|
223
|
-
export enum STSServerType {
|
|
224
|
-
NONE = "NONE",
|
|
225
|
-
EXPRESS = "EXPRESS",
|
|
226
|
-
EXPRESS_TLS = "EXPRESS_TLS",
|
|
227
|
-
TCPRAW_TLS = "TCPRAW_TLS",
|
|
228
|
-
JSONRPC2_TLS = "JSONRPC_TLS"
|
|
229
|
-
}
|
|
230
|
-
*/
|
|
231
|
-
|
|
232
|
-
//export interface ProcessOptions extends JSONObject {
|
|
233
|
-
export interface ProcessOptions {
|
|
234
|
-
/**
|
|
235
|
-
* Is this service worker the master worker (thread).
|
|
236
|
-
*/
|
|
237
|
-
isMaster: boolean
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Unique service instance ID (uuidv4).
|
|
241
|
-
*/
|
|
242
|
-
serviceInstanceId: string
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* HTTPS service public key path.
|
|
246
|
-
*/
|
|
247
|
-
httpsServerKeyPath: string
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* HTTPS service certificate (private key) path.
|
|
251
|
-
*/
|
|
252
|
-
httpsServerCertificatePath: string
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Determines whether the process will explicitly exit (using code 0) when any terminate signal is received.
|
|
256
|
-
*/
|
|
257
|
-
processExitOnTerminate: boolean
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Does this service run a Web Socket Server (wss).
|
|
261
|
-
*/
|
|
262
|
-
wssServer: boolean
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Service Prometheus metric support.
|
|
266
|
-
*/
|
|
267
|
-
prometheusSupport: boolean
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Service endpoint (without trailing /). Example: https://localhost
|
|
271
|
-
*/
|
|
272
|
-
endpoint: string
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Service API root (without trailing /). Example: /stsrest01/v1
|
|
276
|
-
*/
|
|
277
|
-
apiRoot: string
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Service listen port. Example: 3001.
|
|
281
|
-
* Note that unix domain sockets are also supported. Example: /tmp/stsrest01.sock.
|
|
282
|
-
* The socket file may also need permissions changed, i.e. chmodSync(port, 511); or chmodSync(port, 777);
|
|
283
|
-
* Axios client calls will also need to use socketPath. Example: ..., socketPath: '/tmp/stsrest01.sock'
|
|
284
|
-
* Ref: https://stackoverflow.com/questions/21342828/node-express-unix-domain-socket-permissions
|
|
285
|
-
* To setup side car service (per running machine/node)
|
|
286
|
-
* sudo mkdir /var/run/sts
|
|
287
|
-
* sudo chown marcusbettens /var/run/sts
|
|
288
|
-
* In .env file per service
|
|
289
|
-
* PORT=/var/run/sts/stsrest01.sock
|
|
290
|
-
*/
|
|
291
|
-
listenPort: string
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Port that this service will be exposed externally on, i.e. clients will use this port to invoke APIs on this service.
|
|
295
|
-
*/
|
|
296
|
-
port: string
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Prometheus Cluster Server port (port used for cluster prometheus scrapes). Example: 3011.
|
|
300
|
-
*/
|
|
301
|
-
prometheusClusterPort: string
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Service Name. Example: Rest01
|
|
305
|
-
*/
|
|
306
|
-
serviceName: string
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Service Version. Example: 1.0.0
|
|
310
|
-
*/
|
|
311
|
-
serviceVersion: string
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Determines where logging is output to the console (stdout).
|
|
315
|
-
*/
|
|
316
|
-
consoleLogging: boolean
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Determines where logging is output to the logging instrument (if present).
|
|
320
|
-
*/
|
|
321
|
-
instrumentLogging: boolean
|
|
322
|
-
|
|
323
|
-
// Publisher options.
|
|
324
|
-
|
|
325
|
-
serviceProcessContext?: IServiceProcessContext
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Factory method that adds express routes to the express app object. Used for non-static content.
|
|
329
|
-
* Non-Static content is applied after logging middleware.
|
|
330
|
-
*/
|
|
331
|
-
expressServerRouteFactory?: ExpressRouteFactory
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Factory method that adds express routes to the express app object for static content.
|
|
335
|
-
* Static content is applied before logging middleware.
|
|
336
|
-
*/
|
|
337
|
-
expressServerRouteStaticFactory?: ExpressRouteFactory
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Determines whether the service will monitor its own health via the /latency API endpoint.
|
|
341
|
-
* Note: The service must implement the /latency end-point for this to work.
|
|
342
|
-
*/
|
|
343
|
-
useLatency: boolean
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Determines whether this service is going to need database access.
|
|
347
|
-
*/
|
|
348
|
-
useDatabase: boolean
|
|
349
|
-
|
|
350
|
-
instrumentationObservationInterval: number
|
|
351
|
-
|
|
352
|
-
instrumentationTimeWindow: number
|
|
353
|
-
|
|
354
|
-
useSocketIoRedisAdaptor: boolean
|
|
355
|
-
|
|
356
|
-
socketIoRedisAdaptorUrl?: string
|
|
357
|
-
|
|
358
|
-
useRedisInstrumentationTransport?: boolean
|
|
359
|
-
|
|
360
|
-
redisInstrumentationTransportUrl?: string
|
|
361
|
-
|
|
362
|
-
workerExec?: string
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Is this application using nodejs cluster mode?
|
|
366
|
-
*/
|
|
367
|
-
clusterMode: boolean
|
|
368
|
-
|
|
369
|
-
logger: ISTSLogger
|
|
370
|
-
|
|
371
|
-
publisherLogger: ISTSLogger
|
|
372
|
-
|
|
373
|
-
publishInterval: number
|
|
374
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
-
import { IProcessBase } from './../commonTypes';
|
|
3
|
-
|
|
4
|
-
export abstract class STSControllerBase {
|
|
5
|
-
#stsApp: any;
|
|
6
|
-
|
|
7
|
-
constructor(stsApp: IProcessBase) {
|
|
8
|
-
this.#stsApp = stsApp;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
get stsApp(): IProcessBase {
|
|
12
|
-
return this.#stsApp
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
-
import { StatusCodes } from 'http-status-codes'
|
|
3
|
-
import { STSControllerBase } from './stscontrollerbase'
|
|
4
|
-
import { IProcessBase } from './../commonTypes'
|
|
5
|
-
|
|
6
|
-
export class STSLatencyController extends STSControllerBase {
|
|
7
|
-
constructor(stsApp: IProcessBase) {
|
|
8
|
-
super(stsApp);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// curl http://localhost:3000/api/v1/latency/latency
|
|
12
|
-
async stslatency(req: any, res: any)
|
|
13
|
-
{
|
|
14
|
-
try {
|
|
15
|
-
const retVal = {
|
|
16
|
-
data: `Ping Completed At: ${Date.now()}`,
|
|
17
|
-
pid: process.pid,
|
|
18
|
-
ppid: process.ppid
|
|
19
|
-
};
|
|
20
|
-
return res.status(StatusCodes.OK).send(retVal);
|
|
21
|
-
} catch (error) {
|
|
22
|
-
this.stsApp.LogErrorMessage(error);
|
|
23
|
-
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send( { status: StatusCodes.INTERNAL_SERVER_ERROR, error: 'Operation was not successful', detail: error } );
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from './commonTypes'
|
|
2
|
-
export * from './process/masterprocessbase'
|
|
3
|
-
export * from './process/processbase'
|
|
4
|
-
export * from './process/serverprocessbase'
|
|
5
|
-
export * from './process/singleprocessbase'
|
|
6
|
-
export * from './process/workerprocessbase'
|
|
7
|
-
export * from './controller/stscontrollerbase'
|
|
8
|
-
export * from './controller/stslatencycontroller'
|
|
9
|
-
export * from './route/stslatencyroute'
|
|
10
|
-
export * from './route/stsrouterbase'
|
|
11
|
-
export * from './publishertransports/publishTransportUtils'
|
|
12
|
-
export * from './logger/stsTransportLoggerWinston'
|
|
13
|
-
export * from './logger/stsTransportWinston'
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
-
import Transport, { TransportStreamOptions } from 'winston-transport'
|
|
3
|
-
|
|
4
|
-
import { IProcessBase } from './../commonTypes'
|
|
5
|
-
|
|
6
|
-
export interface ISTSTransportLoggerWinstonOptions extends TransportStreamOptions {
|
|
7
|
-
stsApp: IProcessBase
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class STSTransportLoggerWinston extends Transport {
|
|
11
|
-
|
|
12
|
-
#options: ISTSTransportLoggerWinstonOptions;
|
|
13
|
-
|
|
14
|
-
constructor(opts: ISTSTransportLoggerWinstonOptions) {
|
|
15
|
-
super(opts);
|
|
16
|
-
this.#options = opts;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
log(info: any, callback: any) {
|
|
20
|
-
this.#options.stsApp.LogMessageToLoggerInstrument(info.message);
|
|
21
|
-
this.emit('logged', info);
|
|
22
|
-
callback();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
-
import Transport, { TransportStreamOptions } from 'winston-transport'
|
|
3
|
-
|
|
4
|
-
import debugModule from 'debug'
|
|
5
|
-
|
|
6
|
-
export interface ISTSTransportWinstonOptions extends TransportStreamOptions {
|
|
7
|
-
stsContext: string
|
|
8
|
-
debugger?: debugModule.Debugger
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function UpdateSTSTransportWithDebugger(logger: any, newDebugger: any): void {
|
|
12
|
-
const stsTransport: Transport | undefined = logger.transports.find((transport: any) => {
|
|
13
|
-
return transport instanceof STSTransportWinston
|
|
14
|
-
});
|
|
15
|
-
if (stsTransport) {
|
|
16
|
-
(stsTransport as STSTransportWinston).debugger = newDebugger
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class STSTransportWinston extends Transport {
|
|
21
|
-
|
|
22
|
-
#options: ISTSTransportWinstonOptions;
|
|
23
|
-
|
|
24
|
-
constructor(opts: ISTSTransportWinstonOptions) {
|
|
25
|
-
super(opts);
|
|
26
|
-
this.#options = opts;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get debugger() : debugModule.Debugger | undefined {
|
|
30
|
-
return this.#options.debugger;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
set debugger(newDebugger: debugModule.Debugger) {
|
|
34
|
-
this.#options.debugger = newDebugger;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
log(info: any, callback: any) {
|
|
38
|
-
//setImmediate(() => {
|
|
39
|
-
if (info[Symbol.for('level')] == 'debug') {
|
|
40
|
-
if (this.#options.debugger) {
|
|
41
|
-
this.#options.debugger(info.message);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
this.emit('logged', info);
|
|
45
|
-
callback();
|
|
46
|
-
//});
|
|
47
|
-
}
|
|
48
|
-
}
|
package/src/network.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import os from 'os'
|
|
2
|
-
|
|
3
|
-
export type NetworkInterfaces = Record<string, string[]>
|
|
4
|
-
|
|
5
|
-
export function GetNetworkInterfaces(): NetworkInterfaces {
|
|
6
|
-
const nets = os.networkInterfaces();
|
|
7
|
-
const results: NetworkInterfaces = { };
|
|
8
|
-
for (const name of Object.keys(nets)) {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
for (const net of nets[name] as any) {
|
|
11
|
-
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
|
12
|
-
if (net.family === 'IPv4' && !net.internal) {
|
|
13
|
-
if (!results[name]) {
|
|
14
|
-
results[name] = [];
|
|
15
|
-
}
|
|
16
|
-
results[name].push(net.address);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return results;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function GetFirstNetworkInterface(): string | null {
|
|
24
|
-
const nics: NetworkInterfaces = GetNetworkInterfaces();
|
|
25
|
-
let hostaddr = null;
|
|
26
|
-
for (const nic in nics)
|
|
27
|
-
{
|
|
28
|
-
const val: string[] = nics[nic];
|
|
29
|
-
if (val.length > 0)
|
|
30
|
-
{
|
|
31
|
-
hostaddr = val[0];
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return hostaddr;
|
|
36
|
-
}
|