pinggy 0.6.5 → 0.6.6
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.
- package/ARCHITECTURE.md +90 -36
- package/CLAUDE.md +18 -8
- package/dist/{TunnelManager-DXNXIH5W.js → TunnelManager-JRVEADS4.js} +4 -3
- package/dist/{TunnelTui-K7KESRTQ.js → TunnelTui-6H4NPUNF.js} +4 -3
- package/dist/{chunk-QZJGTQZC.js → chunk-2GIJXE4K.js} +3 -2
- package/dist/{chunk-EMCDDH3B.js → chunk-3WMTTJHI.js} +11 -299
- package/dist/chunk-4XXAHYCJ.js +927 -0
- package/dist/{chunk-X6TZN5CT.js → chunk-CZOKR73F.js} +1 -1
- package/dist/chunk-FQ22KFVV.js +882 -0
- package/dist/{chunk-K5QHR5KU.js → chunk-HAFTH5MX.js} +498 -551
- package/dist/chunk-HTIWY3O5.js +293 -0
- package/dist/{chunk-IRKMUV37.js → chunk-LWCVB42S.js} +2 -2
- package/dist/{chunk-N5WE4DYD.js → chunk-MAK5R4WQ.js} +12 -0
- package/dist/{chunk-7EQKHVQX.js → chunk-MHQ3CVEB.js} +4 -51
- package/dist/chunk-MKGD2QAI.js +51 -0
- package/dist/{chunk-3PTLHLFL.js → chunk-Q5NCTGNS.js} +33 -240
- package/dist/{configStore-DXC6WMYO.js → configStore-JJUWT2YO.js} +3 -3
- package/dist/{daemonChild-HZ27YJKQ.js → daemonChild-Q6WGYKYX.js} +14 -10
- package/dist/{daemonConfig-MCAKZHY2.js → daemonConfig-VWK4TXVS.js} +2 -2
- package/dist/index.cjs +3555 -1791
- package/dist/index.d.cts +142 -129
- package/dist/index.d.ts +142 -129
- package/dist/index.js +18 -13
- package/dist/{ipcClient-XGF2KCQO.js → ipcClient-IZ5R6TPN.js} +2 -1
- package/dist/{main-TDQB5ZB4.js → main-BI7ACRHS.js} +19 -14
- package/dist/updateChild-Z3SIRYO5.js +237 -0
- package/dist/workers/file_serve_worker.js +1 -1
- package/package.json +2 -1
- package/scripts/install/install.ps1 +3 -1
- package/scripts/install/install.sh +34 -6
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
IPCClient
|
|
3
|
+
} from "./chunk-MHQ3CVEB.js";
|
|
4
|
+
import {
|
|
5
|
+
TunnelAlreadyRunningError,
|
|
6
|
+
TunnelManager,
|
|
7
|
+
TunnelRebuildInProgressError
|
|
8
|
+
} from "./chunk-3WMTTJHI.js";
|
|
9
|
+
import {
|
|
10
|
+
ensureDaemonRunning,
|
|
11
|
+
getDaemonInfo,
|
|
12
|
+
getInProcessDaemonHandle,
|
|
13
|
+
ipcMismatchMessage,
|
|
14
|
+
isIpcCompatible,
|
|
15
|
+
printDaemonVersionNoticeOnce
|
|
16
|
+
} from "./chunk-4XXAHYCJ.js";
|
|
17
|
+
import {
|
|
18
|
+
SessionMode
|
|
19
|
+
} from "./chunk-MKGD2QAI.js";
|
|
8
20
|
import {
|
|
9
21
|
ErrorCode,
|
|
10
22
|
NewErrorResponseObject,
|
|
11
23
|
NewResponseObject,
|
|
12
24
|
RemoteManagementStatus,
|
|
13
|
-
TunnelAlreadyRunningError,
|
|
14
|
-
TunnelManager,
|
|
15
|
-
TunnelRebuildInProgressError,
|
|
16
25
|
errorMessage,
|
|
17
|
-
getLocalAddress,
|
|
18
26
|
getVersion,
|
|
19
27
|
isErrorResponse,
|
|
20
28
|
isValidPort,
|
|
@@ -22,14 +30,10 @@ import {
|
|
|
22
30
|
newStats,
|
|
23
31
|
newStatus,
|
|
24
32
|
printer_default
|
|
25
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-HTIWY3O5.js";
|
|
26
34
|
import {
|
|
27
35
|
logger
|
|
28
|
-
} from "./chunk-
|
|
29
|
-
import {
|
|
30
|
-
getDaemonInfoPath,
|
|
31
|
-
getDaemonLogPath
|
|
32
|
-
} from "./chunk-N5WE4DYD.js";
|
|
36
|
+
} from "./chunk-LWCVB42S.js";
|
|
33
37
|
|
|
34
38
|
// src/remote_management/remote_schema.ts
|
|
35
39
|
import { HaProxyVersion, TunnelType } from "@pinggy/pinggy";
|
|
@@ -1500,217 +1504,6 @@ function setRemoteManagementState(state, errorMessage2) {
|
|
|
1500
1504
|
};
|
|
1501
1505
|
}
|
|
1502
1506
|
|
|
1503
|
-
// src/daemon/lifecycle/daemonManager.ts
|
|
1504
|
-
import os from "os";
|
|
1505
|
-
import fs from "fs";
|
|
1506
|
-
import { spawn } from "child_process";
|
|
1507
|
-
var inProcessHandle = null;
|
|
1508
|
-
var DAEMON_SPAWN_TIMEOUT_MS = 8e3;
|
|
1509
|
-
var DAEMON_POLL_INTERVAL_MS = 200;
|
|
1510
|
-
var BOOT_TIME_TOLERANCE_MILLIS = 6e4;
|
|
1511
|
-
function isProcessAlive(pid) {
|
|
1512
|
-
try {
|
|
1513
|
-
process.kill(pid, 0);
|
|
1514
|
-
return true;
|
|
1515
|
-
} catch (err) {
|
|
1516
|
-
return err.code === "EPERM";
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
function startedBeforeBoot(startedAt) {
|
|
1520
|
-
const startedAtMillis = Date.parse(startedAt);
|
|
1521
|
-
const bootMillis = Date.now() - os.uptime() * 1e3;
|
|
1522
|
-
return Number.isNaN(startedAtMillis) || startedAtMillis < bootMillis - BOOT_TIME_TOLERANCE_MILLIS;
|
|
1523
|
-
}
|
|
1524
|
-
function getDaemonInfo() {
|
|
1525
|
-
const infoPath = getDaemonInfoPath();
|
|
1526
|
-
if (!fs.existsSync(infoPath)) return null;
|
|
1527
|
-
try {
|
|
1528
|
-
const data = JSON.parse(fs.readFileSync(infoPath, "utf-8"));
|
|
1529
|
-
if (!data.pid || !data.port) return null;
|
|
1530
|
-
if (startedBeforeBoot(data.startedAt) || !isProcessAlive(data.pid)) {
|
|
1531
|
-
logger.info("Stale daemon.json found, cleaning up", { stalePid: data.pid });
|
|
1532
|
-
try {
|
|
1533
|
-
fs.unlinkSync(infoPath);
|
|
1534
|
-
} catch {
|
|
1535
|
-
}
|
|
1536
|
-
return null;
|
|
1537
|
-
}
|
|
1538
|
-
return data;
|
|
1539
|
-
} catch {
|
|
1540
|
-
return null;
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
function isDaemonRunning() {
|
|
1544
|
-
return getDaemonInfo() !== null;
|
|
1545
|
-
}
|
|
1546
|
-
function daemonIpcVersion(info) {
|
|
1547
|
-
return info.ipcVersion ?? 0;
|
|
1548
|
-
}
|
|
1549
|
-
function isIpcCompatible(info) {
|
|
1550
|
-
return daemonIpcVersion(info) === IPC_VERSION;
|
|
1551
|
-
}
|
|
1552
|
-
function ipcMismatchMessage(info) {
|
|
1553
|
-
const versions = `daemon IPC v${daemonIpcVersion(info)}, this CLI expects v${IPC_VERSION}`;
|
|
1554
|
-
if (info.host === DaemonHost.APP) {
|
|
1555
|
-
return `The Pinggy app is running a daemon from a different version (${versions}). Update or restart the Pinggy app.`;
|
|
1556
|
-
}
|
|
1557
|
-
return `A daemon from a different Pinggy CLI version is running (PID ${info.pid}; ${versions}). Run "pinggy daemon stop" and retry. This stops all running tunnels.`;
|
|
1558
|
-
}
|
|
1559
|
-
function getDaemonSpawnArgs() {
|
|
1560
|
-
return {
|
|
1561
|
-
command: process.execPath,
|
|
1562
|
-
args: [process.argv[1], "--_daemon-child"],
|
|
1563
|
-
env: { ...process.env }
|
|
1564
|
-
};
|
|
1565
|
-
}
|
|
1566
|
-
async function startDaemon() {
|
|
1567
|
-
const existing = getDaemonInfo();
|
|
1568
|
-
if (existing) {
|
|
1569
|
-
return existing;
|
|
1570
|
-
}
|
|
1571
|
-
const { command, args, env } = getDaemonSpawnArgs();
|
|
1572
|
-
logger.info("Spawning daemon child", { command, args });
|
|
1573
|
-
let stderrOutput = "";
|
|
1574
|
-
let exited = false;
|
|
1575
|
-
let exitCode = null;
|
|
1576
|
-
const child = spawn(command, args, {
|
|
1577
|
-
detached: true,
|
|
1578
|
-
stdio: ["ignore", "ignore", "pipe"],
|
|
1579
|
-
env,
|
|
1580
|
-
...os.platform() === "win32" ? { windowsHide: true } : {}
|
|
1581
|
-
});
|
|
1582
|
-
child.stderr?.on("data", (chunk) => {
|
|
1583
|
-
stderrOutput += chunk.toString("utf-8");
|
|
1584
|
-
});
|
|
1585
|
-
child.on("exit", (code) => {
|
|
1586
|
-
exited = true;
|
|
1587
|
-
exitCode = code;
|
|
1588
|
-
});
|
|
1589
|
-
child.unref();
|
|
1590
|
-
const info = await pollForDaemonInfo(DAEMON_SPAWN_TIMEOUT_MS, () => exited && exitCode !== 0);
|
|
1591
|
-
if (!info) {
|
|
1592
|
-
const logPath = getDaemonLogPath();
|
|
1593
|
-
if (exited) {
|
|
1594
|
-
const detail = stderrOutput.trim() || `Check ${logPath} for details.`;
|
|
1595
|
-
throw new Error(`Daemon child exited with code ${exitCode}. ${detail}`);
|
|
1596
|
-
}
|
|
1597
|
-
throw new Error(`Daemon failed to start within timeout. Check ${logPath} for details.`);
|
|
1598
|
-
}
|
|
1599
|
-
child.stderr?.removeAllListeners();
|
|
1600
|
-
child.stderr?.destroy();
|
|
1601
|
-
return info;
|
|
1602
|
-
}
|
|
1603
|
-
async function ensureDaemonRunning() {
|
|
1604
|
-
const existing = getDaemonInfo();
|
|
1605
|
-
if (existing) {
|
|
1606
|
-
if (!isIpcCompatible(existing)) throw new Error(ipcMismatchMessage(existing));
|
|
1607
|
-
return existing;
|
|
1608
|
-
}
|
|
1609
|
-
if (process.versions.electron) {
|
|
1610
|
-
const { runDaemonChild } = await import("./daemonChild-HZ27YJKQ.js");
|
|
1611
|
-
const handle = await runDaemonChild({
|
|
1612
|
-
installSignalHandlers: false,
|
|
1613
|
-
exitOnFailure: false,
|
|
1614
|
-
host: DaemonHost.APP
|
|
1615
|
-
});
|
|
1616
|
-
inProcessHandle = handle;
|
|
1617
|
-
return getDaemonInfo() ?? {
|
|
1618
|
-
pid: handle.pid,
|
|
1619
|
-
port: handle.port,
|
|
1620
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1621
|
-
host: DaemonHost.APP,
|
|
1622
|
-
ipcVersion: IPC_VERSION
|
|
1623
|
-
};
|
|
1624
|
-
}
|
|
1625
|
-
return startDaemon();
|
|
1626
|
-
}
|
|
1627
|
-
function getInProcessDaemonHandle() {
|
|
1628
|
-
return inProcessHandle;
|
|
1629
|
-
}
|
|
1630
|
-
async function getActiveTunnelSummaries(origin = "app") {
|
|
1631
|
-
const info = getDaemonInfo();
|
|
1632
|
-
if (!info) return [];
|
|
1633
|
-
const { IPCClient: IPCClient2 } = await import("./ipcClient-XGF2KCQO.js");
|
|
1634
|
-
const client = new IPCClient2(info.port, origin);
|
|
1635
|
-
let tunnels;
|
|
1636
|
-
try {
|
|
1637
|
-
tunnels = await client.listTunnels();
|
|
1638
|
-
} catch (err) {
|
|
1639
|
-
logger.warn("Failed to list tunnels from daemon", { error: errorMessage(err) });
|
|
1640
|
-
return [];
|
|
1641
|
-
}
|
|
1642
|
-
if (!Array.isArray(tunnels)) return [];
|
|
1643
|
-
return tunnels.filter((t) => {
|
|
1644
|
-
const state = t?.status?.state;
|
|
1645
|
-
return state !== "closed" /* Closed */ && state !== "exited" /* Exited */;
|
|
1646
|
-
}).map((t) => ({
|
|
1647
|
-
tunnelId: t.tunnelid,
|
|
1648
|
-
name: t.tunnelconfig?.name || t.tunnelid.slice(0, 8),
|
|
1649
|
-
localAddress: getLocalAddress(t.tunnelconfig),
|
|
1650
|
-
urls: t.remoteurls ?? []
|
|
1651
|
-
}));
|
|
1652
|
-
}
|
|
1653
|
-
function pollForDaemonInfo(timeoutMs, hasExited) {
|
|
1654
|
-
return new Promise((resolve) => {
|
|
1655
|
-
const start = Date.now();
|
|
1656
|
-
const check = () => {
|
|
1657
|
-
const info = getDaemonInfo();
|
|
1658
|
-
if (info) {
|
|
1659
|
-
resolve(info);
|
|
1660
|
-
return;
|
|
1661
|
-
}
|
|
1662
|
-
if (hasExited?.()) {
|
|
1663
|
-
resolve(null);
|
|
1664
|
-
return;
|
|
1665
|
-
}
|
|
1666
|
-
if (Date.now() - start > timeoutMs) {
|
|
1667
|
-
resolve(null);
|
|
1668
|
-
return;
|
|
1669
|
-
}
|
|
1670
|
-
setTimeout(check, DAEMON_POLL_INTERVAL_MS);
|
|
1671
|
-
};
|
|
1672
|
-
check();
|
|
1673
|
-
});
|
|
1674
|
-
}
|
|
1675
|
-
async function stopDaemon() {
|
|
1676
|
-
const info = getDaemonInfo();
|
|
1677
|
-
if (!info) return { ok: false, error: "No daemon is running." };
|
|
1678
|
-
let daemonErrors = [];
|
|
1679
|
-
try {
|
|
1680
|
-
const { IPCClient: IPCClient2 } = await import("./ipcClient-XGF2KCQO.js");
|
|
1681
|
-
const client = new IPCClient2(info.port);
|
|
1682
|
-
const result = await client.shutdown();
|
|
1683
|
-
logger.debug("Sent shutdown command to daemon", { result });
|
|
1684
|
-
if (result?.status === ShutdownStatus.RefusedInApp) {
|
|
1685
|
-
return {
|
|
1686
|
-
ok: false,
|
|
1687
|
-
reason: DaemonHost.APP,
|
|
1688
|
-
error: "The daemon is running inside the Pinggy app."
|
|
1689
|
-
};
|
|
1690
|
-
}
|
|
1691
|
-
if (Array.isArray(result?.errors)) daemonErrors = result.errors;
|
|
1692
|
-
} catch (e) {
|
|
1693
|
-
return { ok: false, error: `Failed to reach daemon: ${errorMessage(e)}` };
|
|
1694
|
-
}
|
|
1695
|
-
const exited = await waitForExit(info.pid, 5e3);
|
|
1696
|
-
if (!exited) {
|
|
1697
|
-
const detail = daemonErrors.length > 0 ? ` Daemon reported: ${daemonErrors.join("; ")}` : "";
|
|
1698
|
-
return { ok: false, error: `Daemon PID ${info.pid} did not exit within 5s.${detail}` };
|
|
1699
|
-
}
|
|
1700
|
-
if (daemonErrors.length > 0) {
|
|
1701
|
-
return { ok: false, error: `Daemon exited but reported errors: ${daemonErrors.join("; ")}` };
|
|
1702
|
-
}
|
|
1703
|
-
return { ok: true };
|
|
1704
|
-
}
|
|
1705
|
-
async function waitForExit(pid, timeoutMs) {
|
|
1706
|
-
const deadline = Date.now() + timeoutMs;
|
|
1707
|
-
while (Date.now() < deadline) {
|
|
1708
|
-
if (!isProcessAlive(pid)) return true;
|
|
1709
|
-
await new Promise((r) => setTimeout(r, 100));
|
|
1710
|
-
}
|
|
1711
|
-
return !isProcessAlive(pid);
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
1507
|
// src/daemon/ws/wsStream.ts
|
|
1715
1508
|
import { WebSocket as WebSocket2 } from "ws";
|
|
1716
1509
|
var WS_NORMAL_CLOSE = 1e3;
|
|
@@ -2092,15 +1885,25 @@ var TunnelClient = class _TunnelClient {
|
|
|
2092
1885
|
this.shimDisconnectListeners = /* @__PURE__ */ new Map();
|
|
2093
1886
|
this.shimSubscribedTunnels = /* @__PURE__ */ new Set();
|
|
2094
1887
|
this.shimListenerSeq = 0;
|
|
1888
|
+
this.boundDaemon = null;
|
|
2095
1889
|
this.origin = options.origin ?? "cli";
|
|
1890
|
+
this.printVersionNotice = options.printVersionNotice ?? printDaemonVersionNoticeOnce;
|
|
2096
1891
|
this.stream = new WsStream(() => {
|
|
2097
1892
|
if (!this.ipc) throw new Error("TunnelClient not initialized. Call ensureDaemon() first.");
|
|
2098
1893
|
return this.ipc.getWsUrl();
|
|
2099
1894
|
});
|
|
2100
1895
|
this.health = new DaemonHealth(() => this.ipc, this.stream);
|
|
2101
1896
|
}
|
|
2102
|
-
|
|
1897
|
+
/**
|
|
1898
|
+
* @param options.holdVersionNotice leaves the "daemon runs an older version" line for `printHeldVersionNotice()`.
|
|
1899
|
+
* A caller with a spinner running uses this, so the line does not land on the spinner.
|
|
1900
|
+
*/
|
|
1901
|
+
async ensureDaemon(options = {}) {
|
|
2103
1902
|
this.bindDaemon(await ensureDaemonRunning());
|
|
1903
|
+
if (!options.holdVersionNotice) this.printHeldVersionNotice();
|
|
1904
|
+
}
|
|
1905
|
+
printHeldVersionNotice() {
|
|
1906
|
+
if (this.boundDaemon) this.printVersionNotice(this.boundDaemon);
|
|
2104
1907
|
}
|
|
2105
1908
|
/**
|
|
2106
1909
|
* Connects to the daemon that runs now, and never starts one. For commands that only read state.
|
|
@@ -2113,9 +1916,11 @@ var TunnelClient = class _TunnelClient {
|
|
|
2113
1916
|
if (!info) return false;
|
|
2114
1917
|
if (!isIpcCompatible(info)) throw new Error(ipcMismatchMessage(info));
|
|
2115
1918
|
this.bindDaemon(info);
|
|
1919
|
+
this.printHeldVersionNotice();
|
|
2116
1920
|
return true;
|
|
2117
1921
|
}
|
|
2118
1922
|
bindDaemon(info) {
|
|
1923
|
+
this.boundDaemon = info;
|
|
2119
1924
|
this.ipc = new IPCClient(info.port, this.origin);
|
|
2120
1925
|
this.health.bindPid(info.pid);
|
|
2121
1926
|
this.health.reset();
|
|
@@ -2395,17 +2200,5 @@ export {
|
|
|
2395
2200
|
closeRemoteManagement,
|
|
2396
2201
|
startRemoteManagement,
|
|
2397
2202
|
getRemoteManagementState,
|
|
2398
|
-
isProcessAlive,
|
|
2399
|
-
startedBeforeBoot,
|
|
2400
|
-
getDaemonInfo,
|
|
2401
|
-
isDaemonRunning,
|
|
2402
|
-
daemonIpcVersion,
|
|
2403
|
-
isIpcCompatible,
|
|
2404
|
-
ipcMismatchMessage,
|
|
2405
|
-
startDaemon,
|
|
2406
|
-
ensureDaemonRunning,
|
|
2407
|
-
getInProcessDaemonHandle,
|
|
2408
|
-
getActiveTunnelSummaries,
|
|
2409
|
-
stopDaemon,
|
|
2410
2203
|
TunnelClient
|
|
2411
2204
|
};
|
|
@@ -22,9 +22,9 @@ import {
|
|
|
22
22
|
validateName,
|
|
23
23
|
validateNameForStorage,
|
|
24
24
|
validateNameStrict
|
|
25
|
-
} from "./chunk-
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-2GIJXE4K.js";
|
|
26
|
+
import "./chunk-LWCVB42S.js";
|
|
27
|
+
import "./chunk-MAK5R4WQ.js";
|
|
28
28
|
export {
|
|
29
29
|
CONFIG_VERBS,
|
|
30
30
|
ConfigVerb,
|
|
@@ -6,18 +6,22 @@ import {
|
|
|
6
6
|
trackIPCTunnelStart,
|
|
7
7
|
trackTunnelStart,
|
|
8
8
|
trackTunnelStop
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
} from "./chunk-7EQKHVQX.js";
|
|
15
|
-
import "./chunk-QZJGTQZC.js";
|
|
9
|
+
} from "./chunk-HAFTH5MX.js";
|
|
10
|
+
import "./chunk-Q5NCTGNS.js";
|
|
11
|
+
import "./chunk-CZOKR73F.js";
|
|
12
|
+
import "./chunk-MHQ3CVEB.js";
|
|
13
|
+
import "./chunk-2GIJXE4K.js";
|
|
16
14
|
import "./chunk-XZ64ZAGO.js";
|
|
17
|
-
import "./chunk-
|
|
15
|
+
import "./chunk-3WMTTJHI.js";
|
|
18
16
|
import "./chunk-UB26QJ4T.js";
|
|
19
|
-
import "./chunk-
|
|
20
|
-
import "./chunk-
|
|
17
|
+
import "./chunk-FQ22KFVV.js";
|
|
18
|
+
import "./chunk-4XXAHYCJ.js";
|
|
19
|
+
import {
|
|
20
|
+
DaemonHost
|
|
21
|
+
} from "./chunk-MKGD2QAI.js";
|
|
22
|
+
import "./chunk-HTIWY3O5.js";
|
|
23
|
+
import "./chunk-LWCVB42S.js";
|
|
24
|
+
import "./chunk-MAK5R4WQ.js";
|
|
21
25
|
export {
|
|
22
26
|
DaemonHost,
|
|
23
27
|
getDaemonHost,
|