@nsshunt/stsappframework 3.0.94 → 3.0.96

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 (83) hide show
  1. package/package.json +1 -1
  2. package/src_new/authDefs.ts +37 -0
  3. package/src_new/authutilsnode.ts +375 -0
  4. package/src_new/commonTypes.ts +239 -0
  5. package/src_new/index.ts +22 -0
  6. package/src_new/influxdb/influxDBManager.ts +972 -0
  7. package/src_new/influxdb/influxDBManagerAgent.ts +316 -0
  8. package/src_new/influxdb/influxDBManagerBase.ts +111 -0
  9. package/src_new/influxdb/influxDBManagerService.ts +375 -0
  10. package/src_new/instrumentationsubscriber.ts +286 -0
  11. package/src_new/kafka/IMKafkaManager.ts +154 -0
  12. package/src_new/kafka/kafkaconsumer.ts +82 -0
  13. package/src_new/kafka/kafkamanager.ts +186 -0
  14. package/src_new/kafka/kafkaproducer.ts +58 -0
  15. package/src_new/kafkatesting/config.ts +10 -0
  16. package/src_new/kafkatesting/consume.ts +116 -0
  17. package/src_new/kafkatesting/produce.ts +155 -0
  18. package/src_new/masterprocessbase.ts +590 -0
  19. package/src_new/middleware/serverNetworkMiddleware.ts +240 -0
  20. package/src_new/network.ts +36 -0
  21. package/src_new/processbase.ts +413 -0
  22. package/src_new/processoptions.ts +164 -0
  23. package/src_new/publishertransports/publishTransportDirect.ts +45 -0
  24. package/src_new/publishertransports/publishTransportUtils.ts +53 -0
  25. package/src_new/server.ts +141 -0
  26. package/src_new/serverprocessbase.ts +393 -0
  27. package/src_new/singleprocessbase.ts +123 -0
  28. package/src_new/socketIoServerHelper.ts +177 -0
  29. package/src_new/stscontrollerbase.ts +15 -0
  30. package/src_new/stslatencycontroller.ts +27 -0
  31. package/src_new/stslatencyroute.ts +16 -0
  32. package/src_new/stsrouterbase.ts +22 -0
  33. package/src_new/tcpclient/app.ts +19 -0
  34. package/src_new/tcpclient/app2.ts +56 -0
  35. package/src_new/tcpserver/app.ts +11 -0
  36. package/src_new/tcpserver/appConfig.ts +65 -0
  37. package/src_new/tcpserver/appmaster.ts +522 -0
  38. package/src_new/validation/errors.ts +6 -0
  39. package/src_new/webworkertesting/app.ts +49 -0
  40. package/src_new/webworkertesting/worker.ts +24 -0
  41. package/src_new/workerprocessbase.test.ts +47 -0
  42. package/src_new/workerprocessbase.ts +187 -0
  43. package/src_working/authDefs.ts +37 -0
  44. package/src_working/authutilsnode.ts +373 -0
  45. package/src_working/commonTypes.ts +239 -0
  46. package/src_working/index.ts +22 -0
  47. package/src_working/influxdb/influxDBManager.ts +970 -0
  48. package/src_working/influxdb/influxDBManagerAgent.ts +314 -0
  49. package/src_working/influxdb/influxDBManagerBase.ts +109 -0
  50. package/src_working/influxdb/influxDBManagerService.ts +373 -0
  51. package/src_working/instrumentationsubscriber.ts +283 -0
  52. package/src_working/kafka/IMKafkaManager.ts +152 -0
  53. package/src_working/kafka/kafkaconsumer.ts +82 -0
  54. package/src_working/kafka/kafkamanager.ts +186 -0
  55. package/src_working/kafka/kafkaproducer.ts +58 -0
  56. package/src_working/kafkatesting/config.ts +10 -0
  57. package/src_working/kafkatesting/consume.ts +116 -0
  58. package/src_working/kafkatesting/produce.ts +153 -0
  59. package/src_working/masterprocessbase.ts +598 -0
  60. package/src_working/middleware/serverNetworkMiddleware.ts +240 -0
  61. package/src_working/network.ts +36 -0
  62. package/src_working/processbase.ts +411 -0
  63. package/src_working/processoptions.ts +164 -0
  64. package/src_working/publishertransports/publishTransportDirect.ts +45 -0
  65. package/src_working/publishertransports/publishTransportUtils.ts +53 -0
  66. package/src_working/server.ts +141 -0
  67. package/src_working/serverprocessbase.ts +393 -0
  68. package/src_working/singleprocessbase.ts +121 -0
  69. package/src_working/socketIoServerHelper.ts +177 -0
  70. package/src_working/stscontrollerbase.ts +15 -0
  71. package/src_working/stslatencycontroller.ts +27 -0
  72. package/src_working/stslatencyroute.ts +16 -0
  73. package/src_working/stsrouterbase.ts +22 -0
  74. package/src_working/tcpclient/app.ts +19 -0
  75. package/src_working/tcpclient/app2.ts +56 -0
  76. package/src_working/tcpserver/app.ts +11 -0
  77. package/src_working/tcpserver/appConfig.ts +65 -0
  78. package/src_working/tcpserver/appmaster.ts +544 -0
  79. package/src_working/validation/errors.ts +6 -0
  80. package/src_working/webworkertesting/app.ts +49 -0
  81. package/src_working/webworkertesting/worker.ts +24 -0
  82. package/src_working/workerprocessbase.test.ts +47 -0
  83. package/src_working/workerprocessbase.ts +185 -0
@@ -0,0 +1,15 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
+ import { IProcessBase } from './commonTypes';
3
+
4
+ export abstract class STSControllerBase
5
+ {
6
+ #stsApp: any;
7
+
8
+ constructor(stsApp: IProcessBase) {
9
+ this.#stsApp = stsApp;
10
+ }
11
+
12
+ get stsApp(): IProcessBase {
13
+ return this.#stsApp
14
+ }
15
+ }
@@ -0,0 +1,27 @@
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
+ {
8
+ constructor(stsApp: IProcessBase) {
9
+ super(stsApp);
10
+ }
11
+
12
+ // curl http://localhost:3000/api/v1/latency/latency
13
+ async stslatency(req: any, res: any)
14
+ {
15
+ try {
16
+ const retVal = {
17
+ data: `Ping Completed At: ${Date.now()}`,
18
+ pid: process.pid,
19
+ ppid: process.ppid
20
+ };
21
+ return res.status(StatusCodes.OK).send(retVal);
22
+ } catch (error) {
23
+ console.error(error);
24
+ return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send( { status: StatusCodes.INTERNAL_SERVER_ERROR, error: 'Operation was not successful', detail: error } );
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,16 @@
1
+ import { STSRouterBase } from './stsrouterbase'
2
+ import { STSLatencyController } from './stslatencycontroller'
3
+ import { IProcessBase } from './commonTypes'
4
+
5
+ export class STSLatencyRoute extends STSRouterBase
6
+ {
7
+ constructor(stsApp: IProcessBase)
8
+ {
9
+ super(stsApp);
10
+
11
+ const latencyController = new STSLatencyController(stsApp);
12
+ const { stslatency } = latencyController;
13
+
14
+ this.router.get('/latency', stslatency.bind(latencyController)); // Create new test
15
+ }
16
+ }
@@ -0,0 +1,22 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
+ import { Router } from 'express';
3
+ import { IProcessBase } from './commonTypes';
4
+
5
+ export abstract class STSRouterBase
6
+ {
7
+ #router: Router;
8
+ #stsApp: any;
9
+
10
+ constructor(stsApp: IProcessBase) {
11
+ this.#stsApp = stsApp;
12
+ this.#router = Router();
13
+ }
14
+
15
+ get router(): Router {
16
+ return this.#router;
17
+ }
18
+
19
+ get stsApp(): IProcessBase {
20
+ return this.#stsApp
21
+ }
22
+ }
@@ -0,0 +1,19 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
+ import jayson from 'jayson'
3
+
4
+ // Read node's tls documentation for more information about these options:
5
+ // https://nodejs.org/api/tls.html#tls_tls_connect_options_callback
6
+ const options: jayson.TcpClientOptions = {
7
+ port: 3003,
8
+ host: 'stscore.stsmda.org'
9
+ };
10
+
11
+ const client = jayson.client.tls(options);
12
+
13
+ // create a client
14
+
15
+ // invoke "add"
16
+ client.request('add', [1, 1], function(err: any, response: any) {
17
+ if(err) throw err;
18
+ console.log(response.result); // 2
19
+ });
@@ -0,0 +1,56 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
2
+ import tls from 'tls';
3
+ import { Sleep } from '@nsshunt/stsutils'
4
+
5
+ import 'colors'
6
+
7
+ const options = {
8
+ port: 3003,
9
+ host: 'stscore.stsmda.org'
10
+ };
11
+
12
+ const done: boolean[] = [];
13
+
14
+ const dosomework = (socket: any, index: number) => {
15
+ console.log('Connected');
16
+ socket.write("Hello From Client " + JSON.stringify(socket.address()));
17
+ (async () => {
18
+ for (;;) {
19
+ const msg = `${new Date()}: Hello`;
20
+ console.log(`sending: [${msg}]`);
21
+ socket.write(msg);
22
+ await Sleep(1000);
23
+ if (done[index]) {
24
+ break;
25
+ }
26
+ }
27
+ })();
28
+ }
29
+
30
+ for (let i=0; i < 6; i++) {
31
+ const socket1 = tls.connect(options);
32
+ done[i] = false;
33
+ socket1.on('secureConnect', () => {
34
+ dosomework(socket1, i);
35
+ });
36
+ socket1.on('close', function(data: any) {
37
+ console.log(`CLOSED: ${socket1.remoteAddress} ${socket1.remotePort}`.yellow);
38
+ done[i]=true;
39
+ });
40
+ socket1.on('data', function(data: any) {
41
+ console.log(`DATA ${socket1.remoteAddress} ${socket1.remotePort} ${data}`.yellow);
42
+ });
43
+ }
44
+
45
+ /*
46
+ const socket2 = tls.connect(options);
47
+ socket2.on('secureConnect', () => {
48
+ dosomework(socket2);
49
+ });
50
+ socket2.on('close', function(data: any) {
51
+ console.log(`CLOSED: ${socket2.remoteAddress} ${socket2.remotePort}`.green);
52
+ });
53
+ socket2.on('data', function(data: any) {
54
+ console.log(`DATA ${socket2.remoteAddress} ${socket2.remotePort} ${data}`.green);
55
+ });
56
+ */
@@ -0,0 +1,11 @@
1
+ import { ServiceConfigOptions } from './appConfig.js'
2
+ import { WorkerProcessBase } from '../index'
3
+ import { AppMaster } from './appmaster'
4
+
5
+ import cluster from 'cluster';
6
+
7
+ if (cluster.isPrimary) {
8
+ new AppMaster(ServiceConfigOptions(true, cluster.isPrimary)).SetupServer();
9
+ } else {
10
+ new WorkerProcessBase(ServiceConfigOptions(true, cluster.isPrimary)).SetupServer();
11
+ }
@@ -0,0 +1,65 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+
3
+ import { $Options } from '@nsshunt/stsconfig'
4
+ const goptions = $Options()
5
+
6
+ import { ProcessOptions, STSServerType } from '../index'
7
+
8
+ /*
9
+ // nid: `${goptions.rest01servicename} @ ${goptions.rest01serviceversion} | ${this.options.globalServiceData.serviceInstanceId} @ ${os.hostname()} ^ ${process.pid} @ ${(cluster.isMaster ? process.pid : process.ppid)}`,
10
+ // <serviceId> <serviceInstanceId> <serviceInstanceProcessId>
11
+ // <serviceName> <serviceVersion> <sid> <hostName> <pid> <ppid>
12
+ // << ............... Static Nid ............... >> << ............... Dynamic Nid ............... >>
13
+ // Note: The final nid will NOT contain the NID_SEPERATOR character. This will be replaced with the SEPERATOR character.
14
+ const Context = (isMaster, serviceInstanceId) => {
15
+ return {
16
+ nid: `\
17
+ ${goptions.rest01servicename}${ModelDelimeter.COMPONENT_SEPERATOR}${goptions.rest01serviceversion}\
18
+ ${ModelDelimeter.SEPERATOR}\
19
+ ${serviceInstanceId}${ModelDelimeter.COMPONENT_SEPERATOR}${os.hostname()}\
20
+ ${ModelDelimeter.NID_SEPERATOR}\
21
+ ${process.pid}${ModelDelimeter.COMPONENT_SEPERATOR}${(isMaster ? process.pid : process.ppid)}`
22
+ }
23
+ }
24
+ */
25
+
26
+ export function ServiceConfigOptions(clusterMode: boolean, isMaster: boolean): ProcessOptions {
27
+ if (isMaster === true) {
28
+ const serviceInstanceId = uuidv4();
29
+ const data: ProcessOptions = {
30
+ serverType: STSServerType.TCPRAW_TLS,
31
+
32
+ clusterMode: clusterMode,
33
+ wssServer: false,
34
+ useLatency: false,
35
+ httpsServerKeyPath: goptions.httpsserverkeypath,
36
+ httpsServerCertificatePath: goptions.httpsservercertpath,
37
+ processExitOnTerminate: true,
38
+ serviceInstanceId: serviceInstanceId,
39
+ useDatabase: true,
40
+
41
+ isMaster: isMaster,
42
+ endpoint: goptions.rest01endpoint,
43
+ apiRoot: goptions.rest01apiroot,
44
+ listenPort: goptions.rest01hostport,
45
+ port: goptions.rest01port,
46
+
47
+ prometheusSupport: false,
48
+ prometheusClusterPort: goptions.rest01prometheusclusterport,
49
+
50
+ serviceName: goptions.rest01servicename,
51
+ serviceVersion: goptions.rest01serviceversion,
52
+ consoleLogging: true,
53
+ instrumentLogging: true,
54
+
55
+ instrumentationObservationInterval: goptions.instrumentationObservationInterval,
56
+ instrumentationTimeWindow: goptions.instrumentationTimeWindow,
57
+
58
+ useRedisAdaptor: false
59
+ }
60
+ return data;
61
+ } else {
62
+ const data: ProcessOptions = JSON.parse(process.env['STS_GSD_SII'] as string) as ProcessOptions;
63
+ return data;
64
+ }
65
+ }