@uns-kit/api 2.0.0 → 2.0.1

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.
@@ -13,6 +13,7 @@ export default class UnsApiProxy extends UnsProxy {
13
13
  private options;
14
14
  private jwksCache?;
15
15
  private catchAllRouteRegistered;
16
+ private startedAt;
16
17
  constructor(processName: string, instanceName: string, options: IApiProxyOptions);
17
18
  /**
18
19
  * Unregister endpoint
@@ -43,6 +44,7 @@ export default class UnsApiProxy extends UnsProxy {
43
44
  queryParams?: IGetEndpointOptions["queryParams"];
44
45
  }): Promise<void>;
45
46
  post(..._args: any[]): any;
47
+ private registerHealthEndpoint;
46
48
  private extractBearerToken;
47
49
  private getPublicKeyFromJwks;
48
50
  private fetchJwksKeys;
@@ -21,11 +21,13 @@ export default class UnsApiProxy extends UnsProxy {
21
21
  options;
22
22
  jwksCache;
23
23
  catchAllRouteRegistered = false;
24
+ startedAt;
24
25
  constructor(processName, instanceName, options) {
25
26
  super();
26
27
  this.options = options;
27
28
  this.app = new App(0, processName, instanceName);
28
29
  this.app.start();
30
+ this.startedAt = Date.now();
29
31
  this.instanceName = instanceName;
30
32
  this.processName = processName;
31
33
  // Create the topic builder using packageJson values and the processName.
@@ -36,6 +38,7 @@ export default class UnsApiProxy extends UnsProxy {
36
38
  this.instanceStatusTopic = this.processStatusTopic + instanceName + "/";
37
39
  // Concatenate processName with instanceName for the worker identification.
38
40
  this.instanceNameWithSuffix = `${processName}-${instanceName}`;
41
+ this.registerHealthEndpoint();
39
42
  }
40
43
  /**
41
44
  * Unregister endpoint
@@ -312,6 +315,32 @@ export default class UnsApiProxy extends UnsProxy {
312
315
  // Implement POST logic or route binding here
313
316
  return "POST called";
314
317
  }
318
+ registerHealthEndpoint() {
319
+ const fullPath = "/status";
320
+ this.app.router.get(fullPath, (_req, res) => {
321
+ res.json({
322
+ alive: true,
323
+ processName: this.processName,
324
+ instanceName: this.instanceName,
325
+ package: packageJson.name,
326
+ version: packageJson.version,
327
+ startedAt: new Date(this.startedAt).toISOString(),
328
+ uptimeMs: Date.now() - this.startedAt,
329
+ timestamp: new Date().toISOString(),
330
+ });
331
+ });
332
+ if (this.app.swaggerSpec) {
333
+ this.app.swaggerSpec.paths = this.app.swaggerSpec.paths || {};
334
+ this.app.swaggerSpec.paths[`/api${fullPath}`] = {
335
+ get: {
336
+ summary: "Health status",
337
+ responses: {
338
+ "200": { description: "OK" },
339
+ },
340
+ },
341
+ };
342
+ }
343
+ }
315
344
  extractBearerToken(req, res) {
316
345
  const authHeader = req.headers["authorization"];
317
346
  if (!authHeader || !authHeader.startsWith("Bearer ")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/api",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Express-powered API gateway plugin for UnsProxyProcess with JWT/JWKS support.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "cookie-parser": "^1.4.7",
36
36
  "express": "^5.1.0",
37
37
  "multer": "^2.0.2",
38
- "@uns-kit/core": "2.0.0"
38
+ "@uns-kit/core": "2.0.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/jsonwebtoken": "^9.0.10",