@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,37 +0,0 @@
1
- export enum Permission {
2
- STS_GLOBAL_ADMIN_PERMISSION = "STSGlobalAdminPermission",
3
-
4
- STSREST01_CREATE_PERMISSION = "STSREST01CreatePermission",
5
- STSREST01_READ_PERMISSION = "STSREST01ReadPermission",
6
- STSREST01_UPDATE_PERMISSION = "STSREST01UpdatePermission",
7
- STSREST01_DELETE_PERMISSION = "STSREST01DeletePermission",
8
-
9
- STSAUTH_LOGIN_PERMISSION = "STSAuthLoginPermission",
10
- STSAUTH_CREATE_PERMISSION = "STSAuthCreatePermission",
11
- STSAUTH_READ_PERMISSION = "STSAuthReadPermission",
12
- STSAUTH_UPDATE_PERMISSION = "STSAuthUpdatePermission",
13
- STSAUTH_DELETE_PERMISSION = "STSAuthDeletePermission",
14
-
15
- STSUITERMINAL_EXECUTE = "STSUITerminalExecute",
16
-
17
- STSCLI_EXECUTE = "STSCLIExecute",
18
-
19
- STSUIWEBAPP_EXECUTE = "STSUIWebAppExecute",
20
-
21
- STSUSERAGENTRUNNER_EXECUTE = "STSUserAgentRunnerExecute",
22
-
23
- STSINSTRUMENTMANAGER_CREATE_PERMISSION = "STSInstrumentManagerCreatePermission",
24
- STSINSTRUMENTMANAGER_READ_PERMISSION = "STSInstrumentManagerReadPermission",
25
- STSINSTRUMENTMANAGER_UPDATE_PERMISSION = "STSInstrumentManagerUpdatePermission",
26
- STSINSTRUMENTMANAGER_DELETE_PERMISSION = "STSInstrumentManagerDeletePermission",
27
-
28
- STSTESTORCHESTRATOR_CREATE_PERMISSION = "STSTestOrchestratorCreatePermission",
29
- STSTESTORCHESTRATOR_READ_PERMISSION = "STSTestOrchestratorReadPermission",
30
- STSTESTORCHESTRATOR_UPDATE_PERMISSION = "STSTestOrchestratorUpdatePermission",
31
- STSTESTORCHESTRATOR_DELETE_PERMISSION = "STSTestOrchestratorDeletePermission",
32
-
33
- STSTESTRUNNER_CREATE_PERMISSION = "STSTestRunnerCreatePermission",
34
- STSTESTRUNNER_READ_PERMISSION = "STSTestRunnerReadPermission",
35
- STSTESTRUNNER_UPDATE_PERMISSION = "STSTestRunnerUpdatePermission",
36
- STSTESTRUNNER_DELETE_PERMISSION = "STSTestRunnerDeletePermission"
37
- }
@@ -1,373 +0,0 @@
1
- import tough from 'tough-cookie';
2
- import https from 'https'
3
- import jwt from 'jsonwebtoken';
4
- import { jwtDecode } from "jwt-decode";
5
- import jwksClient from 'jwks-rsa';
6
-
7
- import axios from 'axios';
8
-
9
- import { $Options } from '@nsshunt/stsconfig'
10
- const goptions = $Options()
11
-
12
- import debugModule from 'debug'
13
-
14
- import { GetErrorPayload, JSONObject } from '@nsshunt/stsutils'
15
-
16
- import { AppFrameworkErrorCode } from './validation/errors'
17
-
18
- import { StatusCodes } from 'http-status-codes';
19
-
20
- export interface IAuthUtilsNodeOptions {
21
- permissions: string[]
22
- }
23
-
24
- /*
25
- export enum STSClientID {
26
- STSRest01Service = 'KgSyRECcvnJwwOZqf7GPqUw508sx7VBFEbDC0iP4oeY=',
27
- STSAuthService = 'q6a9F0kksXDDcrsCUKRwHKDnTNh7yZfxCShAgIJqfGg=',
28
- STSUITerminal = 'U0E4c4cuRKlBsGo7OhOl3qTkoNGFBXjORUS/T4R4xyA=',
29
- STSCLI = 'EcCpnQOIQFizAnWphlFJ4tSylosgVnwKTSNtgwuL2tw=',
30
- STSUIWebApp = 'lww8Je8n2P0OI/KEfJ+4p/bqsk8uE/noeq13tl4zlQ0=',
31
- XXSTSUserAgentRunnerX = 'y1h2nNr1BzTVPIzNmP/f041uxbnyZYTJeF/5GcwRCtw=',
32
- STSInstrumentManagerService = 'l8u2E912eR44ZYRHUkSBCCnDOXxQqYOPahDVQzYowrw=',
33
- STSTestOrchestratorService = 'CU1sVlS6vsEe3O3VvNzKFdBnQd9pQ83w9RyVx/7tJfc=',
34
- STSTestRunnerNode = 'aX9dJbsT06V1G4j06xEIQ/rZ2CDlpzggU58aLtZ8fzE=',
35
- STSBrokerService = 'TRppBuvxcjL7jrY9lCASJ5st8JpU8WlhAUAWoX/KKQ4=',
36
- STSTestingService = '4Mtb3ABdSzZvSz4T51HPJhT14znVnqVDRFiZsvDNAOg=',
37
- XXSTSAuthenticateSPAXX = 'v4qBrds3Autl/i86xT+5z0K53kJ/2hHTfxNo0QO/0Jk=',
38
- STSTestRunnerAgentSPA = 'yDbklCH3awzDNuHICuco9mjDqhdzCa8m7w/UE9Opexc=',
39
- STSClientApp01SPA = 'FDX/CPyDb3m6d9G2k+wDX8Uvey+yCkllaT4EuEt4QyU=',
40
- PowerPlatformCustomConnectorSPA = 'fcdcebb5-d154-4699-b99d-87d29e5e148f'
41
- }
42
- */
43
-
44
- export class AuthUtilsNode
45
- {
46
- #cookiejar: tough.CookieJar;
47
- #httpsAgent: https.Agent | null = null;
48
- #debug = debugModule(`proc:${process.pid}:AuthUtilsNode`);
49
- // Regular expression to match the origin
50
- #originRegex = /^(api:\/\/\w+)/;
51
-
52
- constructor() {
53
- this.#cookiejar = new tough.CookieJar();
54
- }
55
-
56
- #GetHttpsAgent = () =>
57
- {
58
- if (this.#httpsAgent === null) {
59
- // https://nodejs.org/api/http.html#class-httpagent
60
- this.#httpsAgent = new https.Agent({
61
- keepAlive: goptions.keepAlive,
62
- maxSockets: goptions.maxSockets,
63
- maxTotalSockets: goptions.maxTotalSockets,
64
- maxFreeSockets: goptions.maxFreeSockets,
65
- timeout: goptions.timeout,
66
- rejectUnauthorized: false
67
- });
68
- }
69
- return this.#httpsAgent;
70
- }
71
-
72
- VerifyRequestMiddlewareFactory(options: IAuthUtilsNodeOptions) {
73
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
- return async function(req: any, res: any, next: any) {
75
- if (options.permissions) {
76
- const scopes = req.auth.scope.split(' ');
77
- const requiredPermissions = [ ];
78
- for (let i=0; i < options.permissions.length; i++) {
79
- const permission = options.permissions[i];
80
- if (!scopes.includes(permission)) {
81
- requiredPermissions.push(permission);
82
- }
83
- }
84
- if (requiredPermissions.length > 0) {
85
- const errorPayload = GetErrorPayload(AppFrameworkErrorCode.APPFRAMEWORK_MISSING_PERMISSION, requiredPermissions);
86
- res.status(StatusCodes.UNAUTHORIZED).send( { status: StatusCodes.UNAUTHORIZED, error: errorPayload });
87
- return;
88
- }
89
- }
90
- next();
91
- }
92
- }
93
- /*
94
- let cookies = await this.GetCookiesFromJar();
95
- const valid = this.#ValidateCookies(cookies);
96
- if (valid) {
97
- next();
98
- } else {
99
- const error = { }; //@@
100
- const invalidToken = false; //@@
101
- if (invalidToken)
102
- {
103
- res.status(StatusCodes.UNAUTHORIZED).send( { status: StatusCodes.UNAUTHORIZED, error: 'Invalid Token', detail: error } );
104
- } else{
105
- res.status(StatusCodes.INTERNAL_SERVER_ERROR).send( { status: StatusCodes.INTERNAL_SERVER_ERROR, error: 'Operation was not successful', detail: error } );
106
- }
107
- }
108
- */
109
-
110
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
- async verifyRequestMiddleware(req: any, res: any, next: any)
112
- {
113
- next();
114
- /*
115
-
116
- let cookies = await this.GetCookiesFromJar();
117
-
118
- const valid = this.#ValidateCookies(cookies);
119
-
120
- if (valid) {
121
- next();
122
- } else {
123
- const error = { }; //@@
124
- const invalidToken = false; //@@
125
- if (invalidToken)
126
- {
127
- res.status(StatusCodes.UNAUTHORIZED).send( { status: StatusCodes.UNAUTHORIZED, error: 'Invalid Token', detail: error } );
128
- } else{
129
- res.status(StatusCodes.INTERNAL_SERVER_ERROR).send( { status: StatusCodes.INTERNAL_SERVER_ERROR, error: 'Operation was not successful', detail: error } );
130
- }
131
- }
132
- */
133
- }
134
-
135
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
136
- SetCookiesToJar = async (headers: Record<string, any>, endpoint: string): Promise<tough.Cookie[]> =>
137
- {
138
- if (headers['set-cookie']) {
139
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
140
- headers['set-cookie'].map((headerCookie: any) => {
141
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
- const cookie: any = tough.Cookie.parse(headerCookie);
143
- this.#cookiejar.setCookieSync(cookie, endpoint);
144
- });
145
- } else {
146
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
- const cookie: any = tough.Cookie.parse(headers['set-cookie']);
148
- this.#cookiejar.setCookieSync(cookie, endpoint);
149
- }
150
-
151
- return this.#cookiejar.getCookies(endpoint);
152
- };
153
-
154
- GetCookiesFromJar = async (endpoint: string): Promise<tough.Cookie[]> =>
155
- {
156
- return this.#cookiejar.getCookies(endpoint);
157
- };
158
-
159
- ValidateJWT = async (token: string, audience: string, endpoint?: string): Promise<string> => {
160
- const jwksClientUri = (endpoint
161
- ? `${endpoint}${goptions.asoauthapiroot}${goptions.asjwksjsonpath}`
162
- : `${goptions.asendpoint}:${goptions.asport}${goptions.asoauthapiroot}${goptions.asjwksjsonpath}`);
163
-
164
- const jwks = jwksClient({
165
- cache: true, //@@ all config items
166
- cacheMaxEntries: 5, // Default value
167
- cacheMaxAge: 600000, // Defaults to 10m
168
- rateLimit: true,
169
- jwksRequestsPerMinute: 10, // Default value
170
- jwksUri: jwksClientUri,
171
- timeout: 30000, //@@ config
172
- requestAgent: this.#GetHttpsAgent()
173
- });
174
-
175
- // Use decode to get the kid
176
- const decodedRefreshToken = jwtDecode<JSONObject>(token, { header: true });
177
- const kid = decodedRefreshToken.kid;
178
-
179
- const key = await jwks.getSigningKey(kid);
180
- const signingKey = key.getPublicKey();
181
-
182
- const verifyOptions = {
183
- issuer: 'https://stsmda.com.au/stsauth/',
184
- //subject: s,
185
- audience: audience,
186
- //expiresIn: 600, // 10 minutes
187
- algorithm: ["RS256"] // RSASSA [ "RS256", "RS384", "RS512" ]
188
- };
189
-
190
- return jwt.verify(token, signingKey, verifyOptions) as string;
191
- }
192
-
193
- // Function to extract the origin from a URI
194
- ExtractOrigin = (uri: string) => {
195
- const match = uri.match(this.#originRegex);
196
- return match ? match[1] : null;
197
- }
198
-
199
- /**
200
- *
201
- * @param clientId
202
- * @param authClientSecret
203
- * @param scope space seperate list of fully qualifed required scopes (i.e. api://<<api id>>/<<resource>>.<<permission>>). Note the scopes must all be for the same client api.
204
- * @param endPoint
205
- * @returns
206
- */
207
- GetAPITokenFromAuthServerUsingScope = async (clientId: string, authClientSecret: string, scope: string, endPoint?: string): Promise<string> => {
208
- try {
209
- const scopes = scope.split(' ');
210
- let origin: string | null = null;
211
- scopes.forEach((s) => {
212
- if (!origin) {
213
- origin = this.ExtractOrigin(s);
214
- if (!origin) {
215
- throw new Error(`Scope: [${scope}] not in required format. Must use (space seperated) api://<client id>[/<resource>.<permission>].`);
216
- }
217
- } else {
218
- const nextOrigin: string | null = this.ExtractOrigin(s);
219
- if (!nextOrigin) {
220
- throw new Error(`Scope: [${scope}] not in required format. Must use (space seperated) api://<client id>[/<resource>.<permission>].`);
221
- } else {
222
- if (origin.localeCompare(nextOrigin) !== 0) {
223
- throw new Error(`Scope: [${scope}] not all from the same client API. All scopes must come from the same client API.`);
224
- }
225
- }
226
- }
227
- });
228
-
229
- const headers = { 'Content-Type': 'application/json'};
230
- const payload = { //@@ make a type
231
- client_id: clientId, // The service calling this method
232
- client_secret: authClientSecret, // Auth service client secret
233
- //client_secret: goptions.brokerclientsecret, // Broker service client secret
234
- scope: scope, // required API
235
- //@@ remove audience
236
- //@@ need scope to be the API identifier
237
- grant_type: "client_credentials"
238
- }
239
- const url = (endPoint
240
- ? `${endPoint}${goptions.asoauthapiroot}/token`
241
- : `${goptions.asendpoint}:${goptions.asport}${goptions.asoauthapiroot}/token`);
242
- const retVal = await axios({
243
- url
244
- ,method: 'post'
245
- ,data: payload
246
- ,headers: headers
247
- ,httpsAgent: this.#GetHttpsAgent()
248
- });
249
-
250
- if (retVal.status) {
251
- if (retVal.status !== 200) {
252
- // Just provide a warning here
253
- this.#debug(`Error (AuthUtilsNode:GetAPITokenFromServer): Invalid response from server: [${retVal.status}]`.magenta);
254
- }
255
- } else {
256
- const msg = `Error (AuthUtilsNode:GetAPITokenFromServer:No retVal.status)`.red
257
- this.#debug(msg);
258
- throw new Error(msg);
259
- }
260
- if (retVal.data) {
261
- if (retVal.data.access_token) {
262
- return retVal.data.access_token as string;
263
- } else {
264
- const msg = `Error (AuthUtilsNode:GetAPITokenFromServer:No retVal.data.access_token)`.red
265
- this.#debug(msg);
266
- throw new Error(msg);
267
- }
268
- } else {
269
- const msg = `Error (AuthUtilsNode:GetAPITokenFromServer:No retVal.data)`.red
270
- this.#debug(msg);
271
- throw new Error(msg);
272
- }
273
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
274
- } catch (error: any) {
275
- this.#debug(`Error (AuthUtilsNode:GetAPITokenFromServer:catch): ${error}`.red);
276
- if (error.response && error.response.data) {
277
- this.#debug(`Details: [${JSON.stringify(error.response.data)}]`.red);
278
- }
279
- throw error;
280
- }
281
- }
282
-
283
- /*
284
- #getHttpsAgent = () =>
285
- {
286
- if (this.#httpsAgent === null) {
287
- // https://nodejs.org/api/http.html#class-httpagent
288
- this.#httpsAgent = new https.Agent({
289
- keepAlive: goptions.keepAlive,
290
- maxSockets: goptions.maxSockets,
291
- maxTotalSockets: goptions.maxTotalSockets,
292
- maxFreeSockets: goptions.maxFreeSockets,
293
- timeout: goptions.timeout,
294
- rejectUnauthorized: goptions.isProduction // Allows self signed certs in non production mode(s)
295
- });
296
- }
297
- return this.#httpsAgent;
298
- }
299
-
300
- Login = async (opts) =>
301
- {
302
- const { authendpoint, authUserName, authUserEMail, authUserPassword, defaultTimeout, publishDebug } = opts;
303
- try {
304
- const processStart = performance.now();
305
- let duration = '';
306
- let loginData = null;
307
- const payload = { name: authUserName, password: authUserPassword, email: authUserEMail }
308
- const retVal = await axios({
309
- url: `${authendpoint}/login`
310
- ,method: 'post'
311
- ,data: payload
312
- ,timeout: defaultTimeout
313
- ,httpsAgent: this.#getHttpsAgent()
314
- // Use below if using a socket endpoint
315
- //,socketPath: '/var/run/sts/stsrest01.sock'
316
- });
317
- duration = (performance.now() - processStart).toFixed(4);
318
- if (publishDebug) debug(`AuthUtilsNode.LoginNode request duration: [${duration}]`);
319
- loginData = retVal.data.detail;
320
-
321
-
322
- if (retVal.headers['set-cookie'] instanceof Array) {
323
- this.#cookies = retVal.headers['set-cookie'].map(cookie.parse);
324
- } else {
325
- this.#cookies = [cookie.parse(retVal.headers['set-cookie'])];
326
- }
327
-
328
- //await this.SetCookiesToJar(retVal.headers);
329
-
330
- return loginData;
331
- } catch (error)
332
- {
333
- if (publishDebug) debug(`Error (AuthUtilsNode:LoginNode): ${error}`.red);
334
- throw error;
335
- }
336
- }
337
-
338
- // https://stackoverflow.com/questions/43002444/make-axios-send-cookies-in-its-requests-automatically
339
- // axios.get('some api url', {withCredentials: true});
340
- // https://medium.com/@adityasrivast/handling-cookies-with-axios-872790241a9b
341
- // https://www.codegrepper.com/code-examples/javascript/axios+send+cookies
342
- // http only cookies
343
- RefreshSessionToken = async (opts) =>
344
- {
345
- const { authendpoint, defaultTimeout, publishDebug } = opts;
346
- try {
347
- const processStart = performance.now();
348
- let duration = '';
349
- let loginData = null;
350
- const cookies = await this.GetCookiesFromJar();
351
- const retVal = await axios({
352
- url: `${authendpoint}/refreshtoken`
353
- ,method: 'post'
354
- ,headers: {
355
- Cookie: cookies
356
- }
357
- ,timeout: defaultTimeout
358
- ,httpsAgent: this.#httpsAgent,
359
- // Use below for socket connections
360
- //,socketPath: '/var/run/sts/stsrest01.sock'
361
- });
362
- duration = (performance.now() - processStart).toFixed(4);
363
- if (publishDebug) debug(`AuthUtilsNode.RefreshAuthTokenBrowser request duration: [${duration}]`);
364
- loginData = retVal.data.detail;
365
- await this.SetCookiesToJar(retVal.headers);
366
- return loginData;
367
- } catch (error) {
368
- if (publishDebug) debug(`Error (AuthUtilsNode:RefreshAuthTokenBrowser): ${error}`.red);
369
- throw error;
370
- }
371
- }
372
- */
373
- }
@@ -1,239 +0,0 @@
1
- /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
- import { Server, Socket, Namespace } from "socket.io";
3
-
4
- import { STSOptionsBase, JSONObject } from "@nsshunt/stsutils"
5
- import { PublishInstrumentControllerV2, InstrumentDefinitions } from '@nsshunt/stspublisherserver'
6
- import { InstrumentBaseTelemetry, Gauge, InstrumentBase } from '@nsshunt/stsinstrumentation'
7
- import { PGAccessLayer } from '@nsshunt/stsdatamanagement'
8
- import { STSDefaultClientToServerEvents, STSDefaultServerToClientEvents } from '@nsshunt/stssocketio-client'
9
- import { Consumer, IHeaders } from 'kafkajs'
10
-
11
- export enum IPCMessageCommand {
12
- AddWorker = 'AddWorker',
13
- DeleteWorker = 'DeleteWorker'
14
- }
15
-
16
- export interface IPCMessagePayload {
17
- requestResponse: boolean,
18
- id: string,
19
- command: IPCMessageCommand,
20
- requestDetail?: JSONObject,
21
- responseDetail?: JSONObject
22
- }
23
-
24
- export interface IPCMessage {
25
- iPCMessagePayload: IPCMessagePayload
26
- cb: () => void,
27
- timeout: NodeJS.Timeout
28
- }
29
-
30
- export type IPCMessages = Record<string, IPCMessage>
31
-
32
- //------------------------------------
33
-
34
- export interface IProcessBase extends STSOptionsBase {
35
- SetupInstrumentation(): void
36
- GetAdditionalInstruments(): InstrumentDefinitions
37
- CollectAdditionalTelemetry(): void
38
- ProcessStartup: () => void
39
- UpdateInstrument: (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry) => void
40
- get InstrumentController(): PublishInstrumentControllerV2 | null
41
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
- LogEx: (message: any) => void
43
- InstrumentExists(instrumentName: Gauge): boolean
44
- ProcessTerminate: () => Promise<void>
45
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- GetUIController(): any
47
- get socketIoServerHelper(): ISocketIoServerHelper<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents> | null
48
- set socketIoServerHelper(value: ISocketIoServerHelper<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents> | null)
49
- TerminateDatabase(): Promise<void>
50
- get accessLayer(): PGAccessLayer | null
51
- get shuttingDown(): boolean
52
- }
53
-
54
- export interface IMasterProcessBase extends IProcessBase {
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
56
- WorkerMessageEvent(msg: any): any
57
- SetupServer: () => Promise<void>
58
- SetupServerEx: () => Promise<void>
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
- KillWorker: (id: string, signal: NodeJS.Signals, options: any, killProcess: boolean, allowKillAll: boolean) => boolean
61
- KillWorkers: (signal: NodeJS.Signals) => void
62
- IncWorkers: () => void
63
- DecWorkers: () => void
64
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- AddWorker: (options: any) => number
66
- MasterStarted(): void
67
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
- BroadcastDataToWorkers: (command: any, data: any) => void
69
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
- ProcessTerminating(): Promise<void>
71
- }
72
-
73
- export interface ISingleProcessBase extends IProcessBase {
74
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
- get httpServer(): any
76
- CollectAdditionalTelemetry(): void
77
- ProcessStarted(): any
78
- get io(): any
79
- ProcessTerminating(): Promise<void>
80
- get expressServer(): any // STSExpressServer - need to put interface in common types - circular reference
81
- SetupServer(): Promise<boolean>
82
- SetupServerEx: () => Promise<void>
83
- TerminateApplication(): Promise<void>
84
- }
85
-
86
- export interface IWorkerProcessBase extends IProcessBase {
87
- get httpServer(): any
88
- WorkerStarted(): any
89
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
90
- ReceivedMessageFromMaster(msg: any): void
91
- CollectAdditionalTelemetry(): void
92
- get io(): any
93
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
- AddWorker: (options: any) => Promise<string>
95
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
- DeleteWorker: (workerId: string, options: any) => Promise<JSONObject>
97
- ProcessTerminating(): Promise<void>
98
- get expressServer(): any
99
- SetupServer: () => Promise<void>
100
- SetupServerEx: () => Promise<void>
101
- }
102
-
103
- // -----------------------------------------------------------------------------
104
-
105
- export type ServerEventCb = (socket: any, data: any) => void
106
-
107
- export interface ServerSocketEvent {
108
- serverEventName: string,
109
- serverEventCb: ServerEventCb
110
- }
111
-
112
- export enum STSNamespace {
113
- STSMonitor = 'stsmonitor',
114
- STSControl = 'stscontrol'
115
- }
116
-
117
- export enum STSRoom {
118
- // STSMonitor rooms
119
- STSInstrumentDataRoom = 'stsinstrumentdataroom', // This room is for all instrument data messages
120
- STSInstrumentDataSubscriptionRoom = 'stsinstrumentdatasubscriptionroom', // This room is only for subscribed instrument data messages
121
-
122
- // STSControl rooms
123
- STSRunnerRoom = 'stsrunnerroom',
124
- STSNodeRunnerRoom = 'stsnoderunnerroom'
125
- }
126
-
127
- export enum STSEvent {
128
- // STSInstrumentData
129
- STSInstrumentData = 'stsinstrumentdata',
130
- STSSubInstrumentData = 'stssubinstrumentdata', // sub-scribed instrument data. This only outputs the nodes that have been subscribed by the client(s).
131
- STSResetInstrumentData = 'stsresetinstrumentdata',
132
-
133
- STSStartLoggingInstrumentData = 'stsStartLoggingInstrumentData',
134
- STSStopLoggingInstrumentData = 'stsStopLoggingInstrumentData',
135
-
136
- // STSRunner events
137
- STSStart = 'stsstart', // Start a test run with options as payload.
138
- STSStop = 'stsstop', // Stop test run(s).
139
- STSPause = 'stspause', // Pause test run(s).
140
- STSResume = 'stsresume', // Resume test run(s).
141
- STSTerminate = 'ststerminate', // Terminate runner instances and exit applications.
142
- // This may also be uysed to force trigger self healing (i.e. auto re-start) when
143
- // running within a container orchestrator such as K8, K3 or Docker Swarm.
144
- STSUpdateStaticConfig = 'stsupdatestaticconfig', // Update base configuration. Options as payload.
145
- STSUpdateDynamicConfig = 'stsupdatedynamicconfig', // Update running configuration. This is used
146
- // to control the runnning behaviour of test(s) in-flight. Options as payload.
147
-
148
- STSSendToRoom = 'sendToRoom',
149
-
150
- // Standard socket events
151
- connect = 'connect'
152
- }
153
-
154
- // https://socket.io/docs/v4/typescript/
155
-
156
- export interface InterServerEvents {
157
- ping: () => void;
158
- }
159
-
160
- export interface STSSocketIONamespace {
161
- namespace: string
162
- pid: number
163
- socketionamespace: Namespace<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents, InterServerEvents>
164
- }
165
-
166
- export type STSServerSocket = Socket<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents, InterServerEvents>
167
- export type STSClientSocket = Socket<STSDefaultServerToClientEvents, STSDefaultClientToServerEvents, InterServerEvents>
168
-
169
- export interface ISocketIoServerHelper<ClientToServerEvents extends STSDefaultClientToServerEvents, ServerToClientEvents extends STSDefaultServerToClientEvents>
170
- {
171
- LogMessage: (namespace: STSSocketIONamespace, message: string) => void
172
- LeaveRoom: (namespace: STSSocketIONamespace, socket: STSServerSocket, room: STSRoom) => void
173
- JoinRoom: (namespace: STSSocketIONamespace, socket: STSServerSocket, room: STSRoom) => void
174
- SetupNamespace: (io: Server, namespace: STSNamespace, rooms: string[], autoJoinRooms: boolean,
175
- /* serverSocketEvents: ServerSocketEvent[], */
176
- socketConnectCallBack: ((socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => void) | null,
177
- socketEventsCallBack: ((socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => void) | null
178
- ) => Namespace<ClientToServerEvents, ServerToClientEvents, InterServerEvents>
179
- GetSTSSocketIONamespace: (namespace: any) => STSSocketIONamespace
180
- DisconnectSockets: () => void
181
- SetupEvent(event: ClientToServerEvents, eventCb: ServerEventCb): ISocketIoServerHelper<ClientToServerEvents, ServerToClientEvents>
182
- }
183
-
184
- export interface IInfluxDBManagerOptions {
185
- token: string // API access token
186
- url: string // end-pont for API
187
- org: string // organisation
188
- bucket: string // bucket to store results
189
- agent?: {
190
- influxDB_keepAlive: boolean
191
- influxDB_maxSockets?: number
192
- influxDB_maxTotalSockets?: number
193
- influxDB_maxFreeSockets?: number
194
- influxDB_timeout?: number
195
- influxDB_rejectUnauthorized?: boolean
196
- }
197
- }
198
-
199
- export type Nid = string;
200
-
201
- export interface ContextBase extends JSONObject {
202
- nid?: Nid
203
- }
204
-
205
- export interface ServiceProcessContext extends ContextBase {
206
- serviceId?: string // Service name and the service version
207
-
208
- serviceInstanceId?: string // Service unique id and the host name
209
- sid?: string // Service unique id only, does not include host
210
- hostName?: string // Service Instance Host Name
211
-
212
- // Left level attributes
213
- serviceInstanceProcessId?: string // Service Instance OS Process ID (parent process id)
214
- pid?: number // Service Instance OS Process ID (parent process id)
215
- ppid?: number// Service Instance OS Parent Process ID if worker. Will be pid if parent process.
216
- isMaster?: boolean // True if is Master Process
217
- isWorker?: boolean // True if is Worker Process
218
- serviceName?: string // Defined in .env or environment variable
219
- serviceVersion?: string // Defined in .env or environment variable
220
- }
221
-
222
- export interface InstrumentPayload {
223
- //nid: string
224
- context: ServiceProcessContext
225
- instruments: Record<string, InstrumentBase>
226
- }
227
-
228
- export interface IKafkaConsumer {
229
- get consumer(): Consumer
230
- get id(): string
231
- Connect(): Promise<void>
232
- Disconnect(): Promise<void>
233
- Subscribe: (topics: string[], fromBeginning: boolean) => Promise<void>
234
- Stop: () => Promise<void>
235
- StartConsumingMessages: (cb: (topic: string, key: string, partition: number, value: string, headers: IHeaders | undefined) => void) => Promise<void>
236
- }
237
-
238
- export type logFunction = (msg: any) => void
239
-
@@ -1,22 +0,0 @@
1
- export * from './commonTypes'
2
- export * from './processoptions'
3
- export * from './authDefs'
4
- export * from './authutilsnode'
5
- export * from './stsrouterbase'
6
- export * from './stscontrollerbase'
7
- export * from './singleprocessbase'
8
- export * from './masterprocessbase'
9
- export * from './workerprocessbase'
10
- export * from './socketIoServerHelper'
11
- export * from './stslatencycontroller'
12
- export * from './stslatencyroute'
13
- export * from './kafka/kafkamanager'
14
- export * from './kafka/kafkaproducer'
15
- export * from './kafka/kafkaconsumer'
16
- export * from './kafka/IMKafkaManager'
17
- export * from './influxdb/influxDBManager'
18
- export * from './influxdb/influxDBManagerBase'
19
- export * from './influxdb/influxDBManagerService'
20
- export * from './influxdb/influxDBManagerAgent'
21
- export * from './publishertransports/publishTransportUtils'
22
- export * from './instrumentationsubscriber'