pinggy 0.6.5 → 0.6.7
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 +103 -39
- package/CLAUDE.md +21 -11
- package/README.md +12 -2
- 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-3KCXR33Y.js +954 -0
- package/dist/{chunk-EMCDDH3B.js → chunk-3WMTTJHI.js} +11 -299
- package/dist/{chunk-X6TZN5CT.js → chunk-CZOKR73F.js} +1 -1
- package/dist/{chunk-K5QHR5KU.js → chunk-FWTQF6AB.js} +519 -556
- package/dist/{chunk-3PTLHLFL.js → chunk-H527WMTF.js} +33 -240
- 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-PMZJ6HFH.js +882 -0
- package/dist/{configStore-DXC6WMYO.js → configStore-JJUWT2YO.js} +3 -3
- package/dist/{daemonChild-HZ27YJKQ.js → daemonChild-24Y3AKII.js} +14 -10
- package/dist/{daemonConfig-MCAKZHY2.js → daemonConfig-VWK4TXVS.js} +2 -2
- package/dist/index.cjs +3621 -1814
- 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-HSIFQAGU.js} +19 -14
- package/dist/updateChild-JNGDWIAK.js +237 -0
- package/dist/workers/file_serve_worker.js +1 -1
- package/package.json +4 -3
- package/scripts/build_node_pty_linux.sh +27 -0
- package/scripts/check_linux_addons.js +168 -0
- package/scripts/install/install.ps1 +16 -16
- package/scripts/install/install.sh +57 -20
|
@@ -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-3KCXR33Y.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
|
};
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// src/utils/printer.ts
|
|
2
|
+
import pico2 from "picocolors";
|
|
3
|
+
|
|
4
|
+
// src/tui/spinner/spinner.ts
|
|
5
|
+
import pico from "picocolors";
|
|
6
|
+
var spinners = {
|
|
7
|
+
dots: {
|
|
8
|
+
interval: 80,
|
|
9
|
+
frames: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"]
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var currentTimer = null;
|
|
13
|
+
var currentText = "";
|
|
14
|
+
function startSpinner(name = "dots", text = "Loading") {
|
|
15
|
+
const spinner = spinners[name];
|
|
16
|
+
let i = 0;
|
|
17
|
+
currentText = text;
|
|
18
|
+
if (currentTimer) {
|
|
19
|
+
clearInterval(currentTimer);
|
|
20
|
+
}
|
|
21
|
+
currentTimer = setInterval(() => {
|
|
22
|
+
const frame = spinner.frames[i = ++i % spinner.frames.length];
|
|
23
|
+
process.stdout.write(`\r${pico.cyan(frame)} ${text}\x1B[K`);
|
|
24
|
+
}, spinner.interval);
|
|
25
|
+
return () => stopSpinner();
|
|
26
|
+
}
|
|
27
|
+
function stopSpinner() {
|
|
28
|
+
if (currentTimer) {
|
|
29
|
+
clearInterval(currentTimer);
|
|
30
|
+
currentTimer = null;
|
|
31
|
+
process.stdout.write("\r\x1B[K");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function stopSpinnerSuccess(message) {
|
|
35
|
+
if (currentTimer) {
|
|
36
|
+
clearInterval(currentTimer);
|
|
37
|
+
currentTimer = null;
|
|
38
|
+
const finalMessage = message || currentText;
|
|
39
|
+
process.stdout.write(`\r${pico.green("\u2714")} ${finalMessage}\x1B[K
|
|
40
|
+
`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function stopSpinnerFail(message) {
|
|
44
|
+
if (currentTimer) {
|
|
45
|
+
clearInterval(currentTimer);
|
|
46
|
+
currentTimer = null;
|
|
47
|
+
const finalMessage = message || currentText;
|
|
48
|
+
process.stdout.write(`\r${pico.red("\u2716")} ${finalMessage}\x1B[K
|
|
49
|
+
`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/utils/printer.ts
|
|
54
|
+
var _CLIPrinter = class _CLIPrinter {
|
|
55
|
+
static isCLIError(err) {
|
|
56
|
+
return err instanceof Error;
|
|
57
|
+
}
|
|
58
|
+
static print(message, ...args) {
|
|
59
|
+
console.log(message, ...args);
|
|
60
|
+
}
|
|
61
|
+
static error(err) {
|
|
62
|
+
const def = this.errorDefinitions.find((d) => d.match(err));
|
|
63
|
+
const msg = def.message(err);
|
|
64
|
+
console.error(pico2.red(pico2.bold("\u2716 Error:")), pico2.red(msg));
|
|
65
|
+
}
|
|
66
|
+
static fatal(err) {
|
|
67
|
+
const def = this.errorDefinitions.find((d) => d.match(err));
|
|
68
|
+
const msg = def.message(err);
|
|
69
|
+
console.error(pico2.red(pico2.bold("\u2716 Fatal Error:")), pico2.red(msg));
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
static red(message) {
|
|
73
|
+
return pico2.red(message);
|
|
74
|
+
}
|
|
75
|
+
static warn(message) {
|
|
76
|
+
console.warn(pico2.yellow(pico2.bold("\u26A0 Warning:")), pico2.yellow(message));
|
|
77
|
+
}
|
|
78
|
+
static warnTxt(message) {
|
|
79
|
+
console.warn(pico2.yellow(pico2.bold("\u26A0 Warning:")), pico2.yellow(message));
|
|
80
|
+
}
|
|
81
|
+
static success(message) {
|
|
82
|
+
console.log(pico2.green(pico2.bold(" \u2714 Success:")), pico2.green(message));
|
|
83
|
+
}
|
|
84
|
+
static info(message) {
|
|
85
|
+
console.log(pico2.blue(message));
|
|
86
|
+
}
|
|
87
|
+
static startSpinner(message) {
|
|
88
|
+
startSpinner("dots", message);
|
|
89
|
+
}
|
|
90
|
+
static stopSpinnerSuccess(message) {
|
|
91
|
+
stopSpinnerSuccess(message);
|
|
92
|
+
}
|
|
93
|
+
static stopSpinnerFail(message) {
|
|
94
|
+
stopSpinnerFail(message);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
_CLIPrinter.errorDefinitions = [
|
|
98
|
+
{
|
|
99
|
+
match: (err) => _CLIPrinter.isCLIError(err) && err.code === "ERR_PARSE_ARGS_UNKNOWN_OPTION",
|
|
100
|
+
message: (err) => {
|
|
101
|
+
const match = /Unknown option '(.+?)'/.exec(err.message);
|
|
102
|
+
const option = match ? match[1] : "(unknown)";
|
|
103
|
+
return `Unknown option '${option}'. Please check your command or use pinggy -h for guidance.`;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
match: (err) => _CLIPrinter.isCLIError(err) && err.code === "ERR_PARSE_ARGS_MISSING_OPTION_VALUE",
|
|
108
|
+
message: (err) => `Missing required argument for option '${err.option}'.`
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
match: (err) => _CLIPrinter.isCLIError(err) && err.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE",
|
|
112
|
+
message: (err) => `Invalid argument'${err.message}'.`
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
match: (err) => _CLIPrinter.isCLIError(err) && err.code === "ENOENT",
|
|
116
|
+
message: (err) => `File or directory not found: ${err.message}`
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
match: () => true,
|
|
120
|
+
// fallback
|
|
121
|
+
message: (err) => _CLIPrinter.isCLIError(err) ? err.message : String(err)
|
|
122
|
+
}
|
|
123
|
+
];
|
|
124
|
+
var CLIPrinter = _CLIPrinter;
|
|
125
|
+
var printer_default = CLIPrinter;
|
|
126
|
+
|
|
127
|
+
// src/types.ts
|
|
128
|
+
var TunnelStateType = /* @__PURE__ */ ((TunnelStateType2) => {
|
|
129
|
+
TunnelStateType2["New"] = "idle";
|
|
130
|
+
TunnelStateType2["Starting"] = "starting";
|
|
131
|
+
TunnelStateType2["Running"] = "running";
|
|
132
|
+
TunnelStateType2["Live"] = "live";
|
|
133
|
+
TunnelStateType2["Closed"] = "closed";
|
|
134
|
+
TunnelStateType2["Exited"] = "exited";
|
|
135
|
+
return TunnelStateType2;
|
|
136
|
+
})(TunnelStateType || {});
|
|
137
|
+
var TunnelErrorCodeType = /* @__PURE__ */ ((TunnelErrorCodeType2) => {
|
|
138
|
+
TunnelErrorCodeType2["NonResponsive"] = "non_responsive";
|
|
139
|
+
TunnelErrorCodeType2["FailedToConnect"] = "failed_to_connect";
|
|
140
|
+
TunnelErrorCodeType2["ErrorInAdditionalForwarding"] = "additional_forwarding_error";
|
|
141
|
+
TunnelErrorCodeType2["WebdebuggerError"] = "webdebugger_error";
|
|
142
|
+
TunnelErrorCodeType2["NoError"] = "";
|
|
143
|
+
return TunnelErrorCodeType2;
|
|
144
|
+
})(TunnelErrorCodeType || {});
|
|
145
|
+
var TunnelWarningCode = /* @__PURE__ */ ((TunnelWarningCode2) => {
|
|
146
|
+
TunnelWarningCode2["InvalidTunnelServePath"] = "INVALID_TUNNEL_SERVE_PATH";
|
|
147
|
+
TunnelWarningCode2["UnknownWarning"] = "UNKNOWN_WARNING";
|
|
148
|
+
return TunnelWarningCode2;
|
|
149
|
+
})(TunnelWarningCode || {});
|
|
150
|
+
var ErrorCode = {
|
|
151
|
+
InvalidRequestMethodError: "INVALID_REQUEST_METHOD",
|
|
152
|
+
InvalidRequestBodyError: "COULD_NOT_READ_BODY",
|
|
153
|
+
InternalServerError: "INTERNAL_SERVER_ERROR",
|
|
154
|
+
InvalidBodyFormatError: "INVALID_DATA_FORMAT",
|
|
155
|
+
ErrorStartingTunnel: "ERROR_STARTING_TUNNEL",
|
|
156
|
+
TunnelNotFound: "TUNNEL_WITH_ID_OR_CONFIG_ID_NOT_FOUND",
|
|
157
|
+
TunnelAlreadyRunningError: "TUNNEL_WITH_ID_OR_CONFIG_ID_ALREADY_RUNNING",
|
|
158
|
+
WebsocketUpgradeFailError: "WEBSOCKET_UPGRADE_FAILED",
|
|
159
|
+
RemoteManagementAlreadyRunning: "REMOTE_MANAGEMENT_ALREADY_RUNNING",
|
|
160
|
+
RemoteManagementNotRunning: "REMOTE_MANAGEMENT_NOT_RUNNING",
|
|
161
|
+
RemoteManagementDeserializationFailed: "REMOTE_MANAGEMENT_DESERIALIZATION_FAILED",
|
|
162
|
+
DeviceNotEnrolled: "DEVICE_NOT_ENROLLED"
|
|
163
|
+
};
|
|
164
|
+
function isErrorResponse(obj) {
|
|
165
|
+
return typeof obj === "object" && obj !== null && "code" in obj && "message" in obj && typeof obj.message === "string" && Object.values(ErrorCode).includes(obj.code);
|
|
166
|
+
}
|
|
167
|
+
function newErrorResponse(codeOrError, message) {
|
|
168
|
+
if (typeof codeOrError === "object") {
|
|
169
|
+
return codeOrError;
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
code: codeOrError,
|
|
173
|
+
message
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function NewResponseObject(data) {
|
|
177
|
+
const encoder = new TextEncoder();
|
|
178
|
+
const bytes = encoder.encode(JSON.stringify(data));
|
|
179
|
+
return {
|
|
180
|
+
response: bytes,
|
|
181
|
+
requestid: "",
|
|
182
|
+
command: "",
|
|
183
|
+
error: false,
|
|
184
|
+
errorresponse: {}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function NewErrorResponseObject(errorResponse) {
|
|
188
|
+
return {
|
|
189
|
+
response: new Uint8Array(),
|
|
190
|
+
requestid: "",
|
|
191
|
+
command: "",
|
|
192
|
+
error: true,
|
|
193
|
+
errorresponse: errorResponse
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function newStatus(tunnelState, errorCode, errorMsg) {
|
|
197
|
+
let assignedState = tunnelState;
|
|
198
|
+
if (tunnelState === "live" /* Live */) {
|
|
199
|
+
assignedState = "running" /* Running */;
|
|
200
|
+
} else if (tunnelState === "idle" /* New */) {
|
|
201
|
+
assignedState = "idle" /* New */;
|
|
202
|
+
} else if (tunnelState === "closed" /* Closed */) {
|
|
203
|
+
assignedState = "exited" /* Exited */;
|
|
204
|
+
}
|
|
205
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
206
|
+
return {
|
|
207
|
+
state: assignedState,
|
|
208
|
+
errorcode: errorCode,
|
|
209
|
+
errormsg: errorMsg,
|
|
210
|
+
createdtimestamp: now,
|
|
211
|
+
starttimestamp: now,
|
|
212
|
+
endtimestamp: now,
|
|
213
|
+
warnings: []
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function newStats() {
|
|
217
|
+
return {
|
|
218
|
+
numLiveConnections: 0,
|
|
219
|
+
numTotalConnections: 0,
|
|
220
|
+
numTotalReqBytes: 0,
|
|
221
|
+
numTotalResBytes: 0,
|
|
222
|
+
numTotalTxBytes: 0,
|
|
223
|
+
elapsedTime: 0
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
var RemoteManagementStatus = {
|
|
227
|
+
Connecting: "CONNECTING",
|
|
228
|
+
Disconnecting: "DISCONNECTING",
|
|
229
|
+
Reconnecting: "RECONNECTING",
|
|
230
|
+
Running: "RUNNING",
|
|
231
|
+
NotRunning: "NOT_RUNNING",
|
|
232
|
+
Error: "ERROR"
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// src/utils/util.ts
|
|
236
|
+
import { readFileSync } from "fs";
|
|
237
|
+
import { randomUUID } from "crypto";
|
|
238
|
+
import { fileURLToPath } from "url";
|
|
239
|
+
import { dirname, join } from "path";
|
|
240
|
+
function getRandomId() {
|
|
241
|
+
return randomUUID();
|
|
242
|
+
}
|
|
243
|
+
function isValidPort(p) {
|
|
244
|
+
return Number.isInteger(p) && p > 0 && p < 65536;
|
|
245
|
+
}
|
|
246
|
+
function errorMessage(err) {
|
|
247
|
+
return err instanceof Error ? err.message : String(err);
|
|
248
|
+
}
|
|
249
|
+
var __filename2 = fileURLToPath(import.meta.url);
|
|
250
|
+
var __dirname2 = dirname(__filename2);
|
|
251
|
+
function getVersion() {
|
|
252
|
+
try {
|
|
253
|
+
const packageJsonPath = join(__dirname2, "../package.json");
|
|
254
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
255
|
+
return pkg.version ?? "";
|
|
256
|
+
} catch (error) {
|
|
257
|
+
printer_default.error("Error reading version info");
|
|
258
|
+
return "";
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function getLocalAddress(config) {
|
|
262
|
+
if (!config) return "-";
|
|
263
|
+
if (config.forwarding) {
|
|
264
|
+
if (typeof config.forwarding === "string") return config.forwarding;
|
|
265
|
+
if (Array.isArray(config.forwarding) && config.forwarding.length > 0) {
|
|
266
|
+
const f = config.forwarding[0];
|
|
267
|
+
if (f.address) return f.address;
|
|
268
|
+
if (f.localDomain && f.localPort) return `${f.localDomain}:${f.localPort}`;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (config.localAddress) return config.localAddress;
|
|
272
|
+
return "-";
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export {
|
|
276
|
+
printer_default,
|
|
277
|
+
TunnelStateType,
|
|
278
|
+
TunnelErrorCodeType,
|
|
279
|
+
TunnelWarningCode,
|
|
280
|
+
ErrorCode,
|
|
281
|
+
isErrorResponse,
|
|
282
|
+
newErrorResponse,
|
|
283
|
+
NewResponseObject,
|
|
284
|
+
NewErrorResponseObject,
|
|
285
|
+
newStatus,
|
|
286
|
+
newStats,
|
|
287
|
+
RemoteManagementStatus,
|
|
288
|
+
getRandomId,
|
|
289
|
+
isValidPort,
|
|
290
|
+
errorMessage,
|
|
291
|
+
getVersion,
|
|
292
|
+
getLocalAddress
|
|
293
|
+
};
|
|
@@ -14,9 +14,9 @@ function setLogLevel(level) {
|
|
|
14
14
|
if (_sdkLogFilePath) {
|
|
15
15
|
enableLoggingByLogLevelInSdk(level, _sdkLogFilePath);
|
|
16
16
|
}
|
|
17
|
-
import("./daemonConfig-
|
|
17
|
+
import("./daemonConfig-VWK4TXVS.js").then(({ writeDaemonConfig }) => writeDaemonConfig({ logLevel: level })).catch(() => {
|
|
18
18
|
});
|
|
19
|
-
import("./TunnelManager-
|
|
19
|
+
import("./TunnelManager-JRVEADS4.js").then(({ TunnelManager }) => TunnelManager.getInstance().applyLogLevelToActiveTunnels(level)).catch(() => {
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
var _logger = null;
|
|
@@ -23,6 +23,15 @@ function ensureTunnelConfigDir() {
|
|
|
23
23
|
function getDaemonInfoPath() {
|
|
24
24
|
return path.join(getPinggyConfigDir(), "daemon.json");
|
|
25
25
|
}
|
|
26
|
+
function getUpdateStatePath() {
|
|
27
|
+
return path.join(getPinggyConfigDir(), "update.json");
|
|
28
|
+
}
|
|
29
|
+
function getUpdateLockPath() {
|
|
30
|
+
return path.join(getPinggyConfigDir(), "update.lock");
|
|
31
|
+
}
|
|
32
|
+
function getUpdateLogPath() {
|
|
33
|
+
return path.join(getPinggyLogDir(), "update.log");
|
|
34
|
+
}
|
|
26
35
|
function getDaemonLockPath() {
|
|
27
36
|
return path.join(getPinggyConfigDir(), "daemon.lock");
|
|
28
37
|
}
|
|
@@ -77,6 +86,9 @@ export {
|
|
|
77
86
|
getTunnelConfigDir,
|
|
78
87
|
ensureTunnelConfigDir,
|
|
79
88
|
getDaemonInfoPath,
|
|
89
|
+
getUpdateStatePath,
|
|
90
|
+
getUpdateLockPath,
|
|
91
|
+
getUpdateLogPath,
|
|
80
92
|
getDaemonLockPath,
|
|
81
93
|
getDaemonConfigPath,
|
|
82
94
|
ensurePinggyLogDir,
|