@camstack/system 1.2.131 → 1.2.133

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.
@@ -9,6 +9,139 @@ node_os = require_chunk.__toESM(node_os);
9
9
  let node_fs = require("node:fs");
10
10
  let node_http = require("node:http");
11
11
  let node_net = require("node:net");
12
+ //#region src/http/lan-http-bind.ts
13
+ /**
14
+ * Second HTTP listener that shares the hub's existing request handler.
15
+ *
16
+ * Fastify is one protocol per instance; HTTPS stays on :4443 and this
17
+ * binds a plain `http.Server` that emits `request` AND `upgrade` onto the
18
+ * same handler graph (tRPC HTTP, cookies, data-plane, static, tRPC WS).
19
+ *
20
+ * Forwarding only `request` is not enough: the viewer speaks tRPC exclusively
21
+ * over WebSocket (`wsLink`). `/health` wins the LAN race, then `ws://…/trpc`
22
+ * hangs because nobody handles the upgrade on this socket.
23
+ */
24
+ var DEFAULT_HTTP_PORT = 4480;
25
+ var handlers = null;
26
+ var server = null;
27
+ var pending = null;
28
+ var state = {
29
+ listening: false,
30
+ error: null,
31
+ port: DEFAULT_HTTP_PORT
32
+ };
33
+ var boundRequestedHost = null;
34
+ var DEFAULT_LAN_HTTP_PORT = DEFAULT_HTTP_PORT;
35
+ /** Map "all IPv4" to dual-stack IPv6 (`::`, ipv6Only false) so IPv4 still works. */
36
+ function allFamiliesListenHost(host) {
37
+ if (host === "0.0.0.0" || host === "*" || host === "") return {
38
+ host: "::",
39
+ ipv6Only: false
40
+ };
41
+ return {
42
+ host,
43
+ ipv6Only: false
44
+ };
45
+ }
46
+ function registerLanHttpHandler(next) {
47
+ handlers = next;
48
+ }
49
+ function readLanHttpState() {
50
+ return state;
51
+ }
52
+ async function applyLanHttp(options) {
53
+ pending = options;
54
+ if (!options.enabled) {
55
+ await closeLanHttp();
56
+ state = {
57
+ listening: false,
58
+ error: null,
59
+ port: options.port
60
+ };
61
+ return state;
62
+ }
63
+ if (handlers === null) {
64
+ state = {
65
+ listening: false,
66
+ error: "HTTP listener is not registered yet",
67
+ port: options.port
68
+ };
69
+ return state;
70
+ }
71
+ if (server !== null && state.listening && (options.port === 0 || state.port === options.port) && boundRequestedHost === options.host) return state;
72
+ await closeLanHttp();
73
+ try {
74
+ const bound = await listenHttp(options.port, options.host, handlers);
75
+ server = bound;
76
+ boundRequestedHost = options.host;
77
+ const addr = bound.address();
78
+ state = {
79
+ listening: true,
80
+ error: null,
81
+ port: typeof addr === "object" && addr !== null ? addr.port : options.port
82
+ };
83
+ return state;
84
+ } catch (err) {
85
+ server = null;
86
+ state = {
87
+ listening: false,
88
+ error: err instanceof Error ? err.message : String(err),
89
+ port: options.port
90
+ };
91
+ return state;
92
+ }
93
+ }
94
+ /** After the hub registers the Fastify request handler, bind whatever was pending. */
95
+ async function bindPendingLanHttp() {
96
+ if (pending === null) return applyLanHttp({
97
+ enabled: true,
98
+ port: DEFAULT_HTTP_PORT,
99
+ host: "0.0.0.0"
100
+ });
101
+ return applyLanHttp(pending);
102
+ }
103
+ async function closeLanHttp() {
104
+ const current = server;
105
+ server = null;
106
+ boundRequestedHost = null;
107
+ if (current === null) return;
108
+ await new Promise((resolve) => {
109
+ current.close(() => resolve());
110
+ });
111
+ }
112
+ function listenHttp(port, host, next) {
113
+ const resolved = allFamiliesListenHost(host);
114
+ return listenOn(port, resolved, next).catch((err) => {
115
+ if (resolved.host === "::" && host !== "::") return listenOn(port, {
116
+ host: "0.0.0.0",
117
+ ipv6Only: false
118
+ }, next);
119
+ throw err;
120
+ });
121
+ }
122
+ function listenOn(port, bind, next) {
123
+ return new Promise((resolve, reject) => {
124
+ const created = (0, node_http.createServer)(next.onRequest);
125
+ created.on("upgrade", next.onUpgrade);
126
+ const onError = (err) => {
127
+ created.off("listening", onListening);
128
+ created.close();
129
+ reject(err);
130
+ };
131
+ const onListening = () => {
132
+ created.off("error", onError);
133
+ resolve(created);
134
+ };
135
+ created.once("error", onError);
136
+ created.once("listening", onListening);
137
+ created.listen({
138
+ port,
139
+ host: bind.host,
140
+ ipv6Only: bind.ipv6Only
141
+ });
142
+ });
143
+ }
144
+ //#endregion
12
145
  //#region src/tls/cert-evaluation.ts
13
146
  /**
14
147
  * The regeneration rule (D227), as a pure function.
@@ -617,139 +750,6 @@ function readTlsAccessStatus(dataDir, restartRequired = false) {
617
750
  }
618
751
  }
619
752
  //#endregion
620
- //#region src/http/lan-http-bind.ts
621
- /**
622
- * Second HTTP listener that shares the hub's existing request handler.
623
- *
624
- * Fastify is one protocol per instance; HTTPS stays on :4443 and this
625
- * binds a plain `http.Server` that emits `request` AND `upgrade` onto the
626
- * same handler graph (tRPC HTTP, cookies, data-plane, static, tRPC WS).
627
- *
628
- * Forwarding only `request` is not enough: the viewer speaks tRPC exclusively
629
- * over WebSocket (`wsLink`). `/health` wins the LAN race, then `ws://…/trpc`
630
- * hangs because nobody handles the upgrade on this socket.
631
- */
632
- var DEFAULT_HTTP_PORT = 4480;
633
- var handlers = null;
634
- var server = null;
635
- var pending = null;
636
- var state = {
637
- listening: false,
638
- error: null,
639
- port: DEFAULT_HTTP_PORT
640
- };
641
- var boundRequestedHost = null;
642
- var DEFAULT_LAN_HTTP_PORT = DEFAULT_HTTP_PORT;
643
- /** Map "all IPv4" to dual-stack IPv6 (`::`, ipv6Only false) so IPv4 still works. */
644
- function allFamiliesListenHost(host) {
645
- if (host === "0.0.0.0" || host === "*" || host === "") return {
646
- host: "::",
647
- ipv6Only: false
648
- };
649
- return {
650
- host,
651
- ipv6Only: false
652
- };
653
- }
654
- function registerLanHttpHandler(next) {
655
- handlers = next;
656
- }
657
- function readLanHttpState() {
658
- return state;
659
- }
660
- async function applyLanHttp(options) {
661
- pending = options;
662
- if (!options.enabled) {
663
- await closeLanHttp();
664
- state = {
665
- listening: false,
666
- error: null,
667
- port: options.port
668
- };
669
- return state;
670
- }
671
- if (handlers === null) {
672
- state = {
673
- listening: false,
674
- error: "HTTP listener is not registered yet",
675
- port: options.port
676
- };
677
- return state;
678
- }
679
- if (server !== null && state.listening && (options.port === 0 || state.port === options.port) && boundRequestedHost === options.host) return state;
680
- await closeLanHttp();
681
- try {
682
- const bound = await listenHttp(options.port, options.host, handlers);
683
- server = bound;
684
- boundRequestedHost = options.host;
685
- const addr = bound.address();
686
- state = {
687
- listening: true,
688
- error: null,
689
- port: typeof addr === "object" && addr !== null ? addr.port : options.port
690
- };
691
- return state;
692
- } catch (err) {
693
- server = null;
694
- state = {
695
- listening: false,
696
- error: err instanceof Error ? err.message : String(err),
697
- port: options.port
698
- };
699
- return state;
700
- }
701
- }
702
- /** After the hub registers the Fastify request handler, bind whatever was pending. */
703
- async function bindPendingLanHttp() {
704
- if (pending === null) return applyLanHttp({
705
- enabled: true,
706
- port: DEFAULT_HTTP_PORT,
707
- host: "0.0.0.0"
708
- });
709
- return applyLanHttp(pending);
710
- }
711
- async function closeLanHttp() {
712
- const current = server;
713
- server = null;
714
- boundRequestedHost = null;
715
- if (current === null) return;
716
- await new Promise((resolve) => {
717
- current.close(() => resolve());
718
- });
719
- }
720
- function listenHttp(port, host, next) {
721
- const resolved = allFamiliesListenHost(host);
722
- return listenOn(port, resolved, next).catch((err) => {
723
- if (resolved.host === "::" && host !== "::") return listenOn(port, {
724
- host: "0.0.0.0",
725
- ipv6Only: false
726
- }, next);
727
- throw err;
728
- });
729
- }
730
- function listenOn(port, bind, next) {
731
- return new Promise((resolve, reject) => {
732
- const created = (0, node_http.createServer)(next.onRequest);
733
- created.on("upgrade", next.onUpgrade);
734
- const onError = (err) => {
735
- created.off("listening", onListening);
736
- created.close();
737
- reject(err);
738
- };
739
- const onListening = () => {
740
- created.off("error", onError);
741
- resolve(created);
742
- };
743
- created.once("error", onError);
744
- created.once("listening", onListening);
745
- created.listen({
746
- port,
747
- host: bind.host,
748
- ipv6Only: bind.ipv6Only
749
- });
750
- });
751
- }
752
- //#endregion
753
753
  Object.defineProperty(exports, "CA_COMMON_NAME", {
754
754
  enumerable: true,
755
755
  get: function() {