@xyo-network/xl1-system-status 4.5.0 → 4.5.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.
@@ -2,6 +2,7 @@ import type { Logger } from '@ariestools/sdk';
2
2
  import type { SystemStatusPublisher, SystemStatusRunner } from '@xyo-network/xl1-protocol/protocol-lib';
3
3
  /** Options for the console system-status publisher. */
4
4
  export interface ConsoleSystemStatusPublisherOptions {
5
+ /** Logger used by this instance and the providers it creates. */
5
6
  logger?: Logger;
6
7
  }
7
8
  /**
@@ -16,12 +17,16 @@ export interface ConsoleSystemStatusPublisherOptions {
16
17
  * actual services.
17
18
  */
18
19
  export declare class ConsoleSystemStatusPublisher implements SystemStatusPublisher {
20
+ /** Moniker implemented by this provider instance. */
19
21
  readonly moniker: "SystemStatusPublisher";
20
22
  private _started;
21
23
  private readonly options;
22
24
  private readonly status;
25
+ /** Creates a console observer for global status transitions. */
23
26
  constructor(status: SystemStatusRunner, options?: ConsoleSystemStatusPublisherOptions);
27
+ /** Enables logging and subscribes to subsequent global status transitions. */
24
28
  start(): void;
29
+ /** Disables output from the registered transition callback. */
25
30
  stop(): void;
26
31
  }
27
32
  //# sourceMappingURL=ConsoleSystemStatusPublisher.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConsoleSystemStatusPublisher.d.ts","sourceRoot":"","sources":["../../src/ConsoleSystemStatusPublisher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAA;AAGvG,uDAAuD;AACvD,MAAM,WAAW,mCAAmC;IAClD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,4BAA6B,YAAW,qBAAqB;IACxE,QAAQ,CAAC,OAAO,0BAA+B;IAE/C,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqC;IAC7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;gBAE/B,MAAM,EAAE,kBAAkB,EAAE,OAAO,GAAE,mCAAwC;IAKzF,KAAK,IAAI,IAAI;IAUb,IAAI,IAAI,IAAI;CAGb"}
1
+ {"version":3,"file":"ConsoleSystemStatusPublisher.d.ts","sourceRoot":"","sources":["../../src/ConsoleSystemStatusPublisher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAA;AAGvG,uDAAuD;AACvD,MAAM,WAAW,mCAAmC;IAClD,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,4BAA6B,YAAW,qBAAqB;IACxE,qDAAqD;IACrD,QAAQ,CAAC,OAAO,0BAA+B;IAE/C,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqC;IAC7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAE3C,gEAAgE;gBACpD,MAAM,EAAE,kBAAkB,EAAE,OAAO,GAAE,mCAAwC;IAKzF,8EAA8E;IAC9E,KAAK,IAAI,IAAI;IAUb,+DAA+D;IAC/D,IAAI,IAAI,IAAI;CAGb"}
@@ -2,13 +2,18 @@ import type { Logger } from '@ariestools/sdk';
2
2
  import type { SystemStatusPublisher, SystemStatusRunner, SystemStatusViewerMethods } from '@xyo-network/xl1-protocol/protocol-lib';
3
3
  /** Options for the HTTP system-status publisher. */
4
4
  export interface HttpSystemStatusPublisherOptions {
5
+ /** Optional host or interface on which the probe server listens. */
5
6
  host?: string;
7
+ /** Logger used by this instance and the providers it creates. */
6
8
  logger?: Logger;
9
+ /** TCP port on which the probe server listens. */
7
10
  port: number;
8
11
  }
9
12
  /** A resolved probe response (HTTP status code + JSON body). */
10
13
  export interface StatusProbeResponse {
14
+ /** JSON-serializable probe response body. */
11
15
  body: unknown;
16
+ /** HTTP status code returned for the probe route. */
12
17
  statusCode: number;
13
18
  }
14
19
  /**
@@ -32,13 +37,17 @@ export declare function resolveStatusProbe(status: SystemStatusViewerMethods, ur
32
37
  * thus `/healthz`) reflecting only the actual services.
33
38
  */
34
39
  export declare class HttpSystemStatusPublisher implements SystemStatusPublisher {
40
+ /** Moniker implemented by this provider instance. */
35
41
  readonly moniker: "SystemStatusPublisher";
36
42
  private _server;
37
43
  private _started;
38
44
  private readonly options;
39
45
  private readonly status;
46
+ /** Creates an HTTP probe publisher for the supplied status runner. */
40
47
  constructor(status: SystemStatusRunner, options: HttpSystemStatusPublisherOptions);
48
+ /** Starts the probe HTTP server and enables transition logging. */
41
49
  start(): Promise<void>;
50
+ /** Disables transition logging and closes the probe HTTP server. */
42
51
  stop(): Promise<void>;
43
52
  private handleRequest;
44
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"HttpSystemStatusPublisher.d.ts","sourceRoot":"","sources":["../../src/HttpSystemStatusPublisher.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EACV,qBAAqB,EAAE,kBAAkB,EAAE,yBAAyB,EACrE,MAAM,wCAAwC,CAAA;AAG/C,oDAAoD;AACpD,MAAM,WAAW,gCAAgC;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb;AAED,gEAAgE;AAChE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,yBAAyB,EAAE,GAAG,EAAE,MAAM,GAAG,mBAA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OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;IAC1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAE3C,sEAAsE;gBAC1D,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,gCAAgC;IAKjF,mEAAmE;IAC7D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB5B,oEAAoE;IAC9D,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,OAAO,CAAC,aAAa;CAItB"}
@@ -1,14 +1,17 @@
1
1
  // src/ConsoleSystemStatusPublisher.ts
2
2
  import { SystemStatusPublisherMoniker } from "@xyo-network/xl1-protocol/protocol-lib";
3
3
  var ConsoleSystemStatusPublisher = class {
4
+ /** Moniker implemented by this provider instance. */
4
5
  moniker = SystemStatusPublisherMoniker;
5
6
  _started = false;
6
7
  options;
7
8
  status;
9
+ /** Creates a console observer for global status transitions. */
8
10
  constructor(status, options = {}) {
9
11
  this.status = status;
10
12
  this.options = options;
11
13
  }
14
+ /** Enables logging and subscribes to subsequent global status transitions. */
12
15
  start() {
13
16
  this._started = true;
14
17
  const { logger } = this.options;
@@ -18,6 +21,7 @@ var ConsoleSystemStatusPublisher = class {
18
21
  if (to === "started") logger?.log("All services started.");
19
22
  });
20
23
  }
24
+ /** Disables output from the registered transition callback. */
21
25
  stop() {
22
26
  this._started = false;
23
27
  }
@@ -53,15 +57,18 @@ var sendJson = (res, statusCode, body) => {
53
57
  res.end(JSON.stringify(body));
54
58
  };
55
59
  var HttpSystemStatusPublisher = class {
60
+ /** Moniker implemented by this provider instance. */
56
61
  moniker = SystemStatusPublisherMoniker2;
57
62
  _server;
58
63
  _started = false;
59
64
  options;
60
65
  status;
66
+ /** Creates an HTTP probe publisher for the supplied status runner. */
61
67
  constructor(status, options) {
62
68
  this.status = status;
63
69
  this.options = options;
64
70
  }
71
+ /** Starts the probe HTTP server and enables transition logging. */
65
72
  async start() {
66
73
  this._started = true;
67
74
  const {
@@ -87,6 +94,7 @@ var HttpSystemStatusPublisher = class {
87
94
  });
88
95
  this._server = server;
89
96
  }
97
+ /** Disables transition logging and closes the probe HTTP server. */
90
98
  async stop() {
91
99
  this._started = false;
92
100
  const server = this._server;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/ConsoleSystemStatusPublisher.ts", "../../src/HttpSystemStatusPublisher.ts"],
4
- "sourcesContent": ["import type { Logger } from '@ariestools/sdk'\nimport type { SystemStatusPublisher, SystemStatusRunner } from '@xyo-network/xl1-protocol/protocol-lib'\nimport { SystemStatusPublisherMoniker } from '@xyo-network/xl1-protocol/protocol-lib'\n\n/** Options for the console system-status publisher. */\nexport interface ConsoleSystemStatusPublisherOptions {\n logger?: Logger\n}\n\n/**\n * Publishes system status to the console by subscribing to the Runner's global\n * status transitions.\n *\n * It is a plain start/stop observer \u2014 NOT a CreatableProvider \u2014 so it never\n * reports its own lifecycle into the Runner. A self-reporting publisher would\n * report itself `started` before any real service is up, falsely flipping the\n * aggregate status to `started` (and any HTTP `/healthz` derived from it to\n * 200). Being a plain observer keeps the global status reflecting only the\n * actual services.\n */\nexport class ConsoleSystemStatusPublisher implements SystemStatusPublisher {\n readonly moniker = SystemStatusPublisherMoniker\n\n private _started = false\n private readonly options: ConsoleSystemStatusPublisherOptions\n private readonly status: SystemStatusRunner\n\n constructor(status: SystemStatusRunner, options: ConsoleSystemStatusPublisherOptions = {}) {\n this.status = status\n this.options = options\n }\n\n start(): void {\n this._started = true\n const { logger } = this.options\n this.status.onGlobalTransition({}, (from, to) => {\n if (!this._started) return\n logger?.log(`System status: ${from} -> ${to}`)\n if (to === 'started') logger?.log('All services started.')\n })\n }\n\n stop(): void {\n this._started = false\n }\n}\n", "import type {\n IncomingMessage, Server, ServerResponse,\n} from 'node:http'\nimport http from 'node:http'\n\nimport type { Logger } from '@ariestools/sdk'\nimport type {\n SystemStatusPublisher, SystemStatusRunner, SystemStatusViewerMethods,\n} from '@xyo-network/xl1-protocol/protocol-lib'\nimport { SystemStatusPublisherMoniker } from '@xyo-network/xl1-protocol/protocol-lib'\n\n/** Options for the HTTP system-status publisher. */\nexport interface HttpSystemStatusPublisherOptions {\n host?: string\n logger?: Logger\n port: number\n}\n\n/** A resolved probe response (HTTP status code + JSON body). */\nexport interface StatusProbeResponse {\n body: unknown\n statusCode: number\n}\n\n/**\n * Pure routing for the status probe endpoints. Extracted from the HTTP server\n * so the routing logic is testable without binding a socket.\n */\nexport function resolveStatusProbe(status: SystemStatusViewerMethods, url: string): StatusProbeResponse {\n switch (url) {\n case '/healthz': {\n const global = status.getGlobalStatus()\n return { statusCode: global === 'started' ? 200 : 500, body: { status: global } }\n }\n case '/livez': {\n return { statusCode: 200, body: { status: 'live' } }\n }\n case '/readyz': {\n if (status.isShuttingDown()) return { statusCode: 503, body: { status: 'shutting-down' } }\n if (status.isReady()) return { statusCode: 200, body: { status: 'ready' } }\n return { statusCode: 503, body: { status: 'pending' } }\n }\n case '/status': {\n return { statusCode: 200, body: status.snapshot() }\n }\n default: {\n return { statusCode: 404, body: { status: 'not found' } }\n }\n }\n}\n\nconst sendJson = (res: ServerResponse, statusCode: number, body: unknown): void => {\n res.writeHead(statusCode, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(body))\n}\n\n/**\n * Publishes system status over HTTP with Kubernetes-style probes plus a richer\n * `/status` snapshot:\n * - `/healthz` \u2014 200 once the global status is `started`, otherwise 500.\n * - `/livez` \u2014 200 unconditionally while the process is running.\n * - `/readyz` \u2014 503 while shutting down, 200 once `isReady()`, else 503.\n * - `/status` \u2014 200 with the full status snapshot as JSON.\n *\n * It publishes to two sinks: the HTTP endpoints above, and the logger (it logs\n * each global status transition via the Runner's subscription).\n *\n * It is a plain start/stop observer (not a CreatableProvider) so it does not\n * report its own lifecycle into the Runner \u2014 keeping the global status (and\n * thus `/healthz`) reflecting only the actual services.\n */\nexport class HttpSystemStatusPublisher implements SystemStatusPublisher {\n readonly moniker = SystemStatusPublisherMoniker\n\n private _server: Server | undefined\n private _started = false\n private readonly options: HttpSystemStatusPublisherOptions\n private readonly status: SystemStatusRunner\n\n constructor(status: SystemStatusRunner, options: HttpSystemStatusPublisherOptions) {\n this.status = status\n this.options = options\n }\n\n async start(): Promise<void> {\n this._started = true\n const {\n host, logger, port,\n } = this.options\n // Console sink: log every global status transition via the logger.\n this.status.onGlobalTransition({}, (from, to) => {\n if (!this._started) return\n logger?.log(`System status: ${from} -> ${to}`)\n })\n const server = http.createServer((req, res) => this.handleRequest(req, res))\n await new Promise<void>((resolve, reject) => {\n server.once('error', reject)\n server.listen(port, host, () => {\n logger?.log(`System status HTTP server running on http://${host ?? 'localhost'}:${port}`)\n logger?.log(' - /healthz')\n logger?.log(' - /livez')\n logger?.log(' - /readyz')\n logger?.log(' - /status')\n resolve()\n })\n })\n this._server = server\n }\n\n async stop(): Promise<void> {\n this._started = false\n const server = this._server\n this._server = undefined\n if (server !== undefined) {\n await new Promise<void>((resolve) => {\n server.close(() => resolve())\n })\n }\n }\n\n private handleRequest(req: IncomingMessage, res: ServerResponse): void {\n const { statusCode, body } = resolveStatusProbe(this.status, req.url ?? '')\n sendJson(res, statusCode, body)\n }\n}\n"],
5
- "mappings": ";AAEA,SAAS,oCAAoC;AAkBtC,IAAM,+BAAN,MAAoE;AAAA,EAChE,UAAU;AAAA,EAEX,WAAW;AAAA,EACF;AAAA,EACA;AAAA,EAEjB,YAAY,QAA4B,UAA+C,CAAC,GAAG;AACzF,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,QAAc;AACZ,SAAK,WAAW;AAChB,UAAM,EAAE,OAAO,IAAI,KAAK;AACxB,SAAK,OAAO,mBAAmB,CAAC,GAAG,CAAC,MAAM,OAAO;AAC/C,UAAI,CAAC,KAAK,SAAU;AACpB,cAAQ,IAAI,kBAAkB,IAAI,OAAO,EAAE,EAAE;AAC7C,UAAI,OAAO,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,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QAAuB;AAC3B,SAAK,WAAW;AAChB,UAAM;AAAA,MACJ;AAAA,MAAM;AAAA,MAAQ;AAAA,IAChB,IAAI,KAAK;AAET,SAAK,OAAO,mBAAmB,CAAC,GAAG,CAAC,MAAM,OAAO;AAC/C,UAAI,CAAC,KAAK,SAAU;AACpB,cAAQ,IAAI,kBAAkB,IAAI,OAAO,EAAE,EAAE;AAAA,IAC/C,CAAC;AACD,UAAM,SAAS,KAAK,aAAa,CAAC,KAAK,QAAQ,KAAK,cAAc,KAAK,GAAG,CAAC;AAC3E,UAAM,IAAI,QAAc,CAAC,SAAS,WAAW;AAC3C,aAAO,KAAK,SAAS,MAAM;AAC3B,aAAO,OAAO,MAAM,MAAM,MAAM;AAC9B,gBAAQ,IAAI,+CAA+C,QAAQ,WAAW,IAAI,IAAI,EAAE;AACxF,gBAAQ,IAAI,aAAa;AACzB,gBAAQ,IAAI,WAAW;AACvB,gBAAQ,IAAI,YAAY;AACxB,gBAAQ,IAAI,YAAY;AACxB,gBAAQ;AAAA,MACV,CAAC;AAAA,IACH,CAAC;AACD,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,OAAsB;AAC1B,SAAK,WAAW;AAChB,UAAM,SAAS,KAAK;AACpB,SAAK,UAAU;AACf,QAAI,WAAW,QAAW;AACxB,YAAM,IAAI,QAAc,CAAC,YAAY;AACnC,eAAO,MAAM,MAAM,QAAQ,CAAC;AAAA,MAC9B,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEQ,cAAc,KAAsB,KAA2B;AACrE,UAAM,EAAE,YAAY,KAAK,IAAI,mBAAmB,KAAK,QAAQ,IAAI,OAAO,EAAE;AAC1E,aAAS,KAAK,YAAY,IAAI;AAAA,EAChC;AACF;",
4
+ "sourcesContent": ["import type { Logger } from '@ariestools/sdk'\nimport type { SystemStatusPublisher, SystemStatusRunner } from '@xyo-network/xl1-protocol/protocol-lib'\nimport { SystemStatusPublisherMoniker } from '@xyo-network/xl1-protocol/protocol-lib'\n\n/** Options for the console system-status publisher. */\nexport interface ConsoleSystemStatusPublisherOptions {\n /** Logger used by this instance and the providers it creates. */\n logger?: Logger\n}\n\n/**\n * Publishes system status to the console by subscribing to the Runner's global\n * status transitions.\n *\n * It is a plain start/stop observer \u2014 NOT a CreatableProvider \u2014 so it never\n * reports its own lifecycle into the Runner. A self-reporting publisher would\n * report itself `started` before any real service is up, falsely flipping the\n * aggregate status to `started` (and any HTTP `/healthz` derived from it to\n * 200). Being a plain observer keeps the global status reflecting only the\n * actual services.\n */\nexport class ConsoleSystemStatusPublisher implements SystemStatusPublisher {\n /** Moniker implemented by this provider instance. */\n readonly moniker = SystemStatusPublisherMoniker\n\n private _started = false\n private readonly options: ConsoleSystemStatusPublisherOptions\n private readonly status: SystemStatusRunner\n\n /** Creates a console observer for global status transitions. */\n constructor(status: SystemStatusRunner, options: ConsoleSystemStatusPublisherOptions = {}) {\n this.status = status\n this.options = options\n }\n\n /** Enables logging and subscribes to subsequent global status transitions. */\n start(): void {\n this._started = true\n const { logger } = this.options\n this.status.onGlobalTransition({}, (from, to) => {\n if (!this._started) return\n logger?.log(`System status: ${from} -> ${to}`)\n if (to === 'started') logger?.log('All services started.')\n })\n }\n\n /** Disables output from the registered transition callback. */\n stop(): void {\n this._started = false\n }\n}\n", "import type {\n IncomingMessage, Server, ServerResponse,\n} from 'node:http'\nimport http from 'node:http'\n\nimport type { Logger } from '@ariestools/sdk'\nimport type {\n SystemStatusPublisher, SystemStatusRunner, SystemStatusViewerMethods,\n} from '@xyo-network/xl1-protocol/protocol-lib'\nimport { SystemStatusPublisherMoniker } from '@xyo-network/xl1-protocol/protocol-lib'\n\n/** Options for the HTTP system-status publisher. */\nexport interface HttpSystemStatusPublisherOptions {\n /** Optional host or interface on which the probe server listens. */\n host?: string\n /** Logger used by this instance and the providers it creates. */\n logger?: Logger\n /** TCP port on which the probe server listens. */\n port: number\n}\n\n/** A resolved probe response (HTTP status code + JSON body). */\nexport interface StatusProbeResponse {\n /** JSON-serializable probe response body. */\n body: unknown\n /** HTTP status code returned for the probe route. */\n statusCode: number\n}\n\n/**\n * Pure routing for the status probe endpoints. Extracted from the HTTP server\n * so the routing logic is testable without binding a socket.\n */\nexport function resolveStatusProbe(status: SystemStatusViewerMethods, url: string): StatusProbeResponse {\n switch (url) {\n case '/healthz': {\n const global = status.getGlobalStatus()\n return { statusCode: global === 'started' ? 200 : 500, body: { status: global } }\n }\n case '/livez': {\n return { statusCode: 200, body: { status: 'live' } }\n }\n case '/readyz': {\n if (status.isShuttingDown()) return { statusCode: 503, body: { status: 'shutting-down' } }\n if (status.isReady()) return { statusCode: 200, body: { status: 'ready' } }\n return { statusCode: 503, body: { status: 'pending' } }\n }\n case '/status': {\n return { statusCode: 200, body: status.snapshot() }\n }\n default: {\n return { statusCode: 404, body: { status: 'not found' } }\n }\n }\n}\n\nconst sendJson = (res: ServerResponse, statusCode: number, body: unknown): void => {\n res.writeHead(statusCode, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(body))\n}\n\n/**\n * Publishes system status over HTTP with Kubernetes-style probes plus a richer\n * `/status` snapshot:\n * - `/healthz` \u2014 200 once the global status is `started`, otherwise 500.\n * - `/livez` \u2014 200 unconditionally while the process is running.\n * - `/readyz` \u2014 503 while shutting down, 200 once `isReady()`, else 503.\n * - `/status` \u2014 200 with the full status snapshot as JSON.\n *\n * It publishes to two sinks: the HTTP endpoints above, and the logger (it logs\n * each global status transition via the Runner's subscription).\n *\n * It is a plain start/stop observer (not a CreatableProvider) so it does not\n * report its own lifecycle into the Runner \u2014 keeping the global status (and\n * thus `/healthz`) reflecting only the actual services.\n */\nexport class HttpSystemStatusPublisher implements SystemStatusPublisher {\n /** Moniker implemented by this provider instance. */\n readonly moniker = SystemStatusPublisherMoniker\n\n private _server: Server | undefined\n private _started = false\n private readonly options: HttpSystemStatusPublisherOptions\n private readonly status: SystemStatusRunner\n\n /** Creates an HTTP probe publisher for the supplied status runner. */\n constructor(status: SystemStatusRunner, options: HttpSystemStatusPublisherOptions) {\n this.status = status\n this.options = options\n }\n\n /** Starts the probe HTTP server and enables transition logging. */\n async start(): Promise<void> {\n this._started = true\n const {\n host, logger, port,\n } = this.options\n // Console sink: log every global status transition via the logger.\n this.status.onGlobalTransition({}, (from, to) => {\n if (!this._started) return\n logger?.log(`System status: ${from} -> ${to}`)\n })\n const server = http.createServer((req, res) => this.handleRequest(req, res))\n await new Promise<void>((resolve, reject) => {\n server.once('error', reject)\n server.listen(port, host, () => {\n logger?.log(`System status HTTP server running on http://${host ?? 'localhost'}:${port}`)\n logger?.log(' - /healthz')\n logger?.log(' - /livez')\n logger?.log(' - /readyz')\n logger?.log(' - /status')\n resolve()\n })\n })\n this._server = server\n }\n\n /** Disables transition logging and closes the probe HTTP server. */\n async stop(): Promise<void> {\n this._started = false\n const server = this._server\n this._server = undefined\n if (server !== undefined) {\n await new Promise<void>((resolve) => {\n server.close(() => resolve())\n })\n }\n }\n\n private handleRequest(req: IncomingMessage, res: ServerResponse): void {\n const { statusCode, body } = resolveStatusProbe(this.status, req.url ?? '')\n sendJson(res, statusCode, body)\n }\n}\n"],
5
+ "mappings": ";AAEA,SAAS,oCAAoC;AAmBtC,IAAM,+BAAN,MAAoE;AAAA;AAAA,EAEhE,UAAU;AAAA,EAEX,WAAW;AAAA,EACF;AAAA,EACA;AAAA;AAAA,EAGjB,YAAY,QAA4B,UAA+C,CAAC,GAAG;AACzF,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA,EAGA,QAAc;AACZ,SAAK,WAAW;AAChB,UAAM,EAAE,OAAO,IAAI,KAAK;AACxB,SAAK,OAAO,mBAAmB,CAAC,GAAG,CAAC,MAAM,OAAO;AAC/C,UAAI,CAAC,KAAK,SAAU;AACpB,cAAQ,IAAI,kBAAkB,IAAI,OAAO,EAAE,EAAE;AAC7C,UAAI,OAAO,UAAW,SAAQ,IAAI,uBAAuB;AAAA,IAC3D,CAAC;AA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system-status",
4
- "version": "4.5.0",
4
+ "version": "4.5.2",
5
5
  "description": "XYO Layer One system status publishers (console + HTTP health endpoints)",
6
6
  "homepage": "https://xylabs.com",
7
7
  "bugs": {
@@ -35,12 +35,12 @@
35
35
  "README.md"
36
36
  ],
37
37
  "dependencies": {
38
- "@xyo-network/xl1-protocol": "~4.5.0"
38
+ "@xyo-network/xl1-protocol": "~4.5.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@ariestools/sdk": "~8.1.1",
42
- "@ariestools/toolchain": "~8.7.16",
43
- "@ariestools/tsconfig": "~8.7.16",
42
+ "@ariestools/toolchain": "~8.7.18",
43
+ "@ariestools/tsconfig": "~8.7.18",
44
44
  "@metamask/json-rpc-engine": "~10.5.0",
45
45
  "@opentelemetry/api": "~1.9.1",
46
46
  "@xyo-network/sdk": "~7.2.1",
@@ -53,7 +53,7 @@
53
53
  "vite": "~8.1.5",
54
54
  "vitest": "~4.1.10",
55
55
  "zod": "~4.4.3",
56
- "@xyo-network/xl1-sdk": "~4.5.0"
56
+ "@xyo-network/xl1-sdk": "~4.5.2"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@ariestools/sdk": "^8.1"