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.
Files changed (30) hide show
  1. package/ARCHITECTURE.md +90 -36
  2. package/CLAUDE.md +18 -8
  3. package/dist/{TunnelManager-DXNXIH5W.js → TunnelManager-JRVEADS4.js} +4 -3
  4. package/dist/{TunnelTui-K7KESRTQ.js → TunnelTui-6H4NPUNF.js} +4 -3
  5. package/dist/{chunk-QZJGTQZC.js → chunk-2GIJXE4K.js} +3 -2
  6. package/dist/{chunk-EMCDDH3B.js → chunk-3WMTTJHI.js} +11 -299
  7. package/dist/chunk-4XXAHYCJ.js +927 -0
  8. package/dist/{chunk-X6TZN5CT.js → chunk-CZOKR73F.js} +1 -1
  9. package/dist/chunk-FQ22KFVV.js +882 -0
  10. package/dist/{chunk-K5QHR5KU.js → chunk-HAFTH5MX.js} +498 -551
  11. package/dist/chunk-HTIWY3O5.js +293 -0
  12. package/dist/{chunk-IRKMUV37.js → chunk-LWCVB42S.js} +2 -2
  13. package/dist/{chunk-N5WE4DYD.js → chunk-MAK5R4WQ.js} +12 -0
  14. package/dist/{chunk-7EQKHVQX.js → chunk-MHQ3CVEB.js} +4 -51
  15. package/dist/chunk-MKGD2QAI.js +51 -0
  16. package/dist/{chunk-3PTLHLFL.js → chunk-Q5NCTGNS.js} +33 -240
  17. package/dist/{configStore-DXC6WMYO.js → configStore-JJUWT2YO.js} +3 -3
  18. package/dist/{daemonChild-HZ27YJKQ.js → daemonChild-Q6WGYKYX.js} +14 -10
  19. package/dist/{daemonConfig-MCAKZHY2.js → daemonConfig-VWK4TXVS.js} +2 -2
  20. package/dist/index.cjs +3555 -1791
  21. package/dist/index.d.cts +142 -129
  22. package/dist/index.d.ts +142 -129
  23. package/dist/index.js +18 -13
  24. package/dist/{ipcClient-XGF2KCQO.js → ipcClient-IZ5R6TPN.js} +2 -1
  25. package/dist/{main-TDQB5ZB4.js → main-BI7ACRHS.js} +19 -14
  26. package/dist/updateChild-Z3SIRYO5.js +237 -0
  27. package/dist/workers/file_serve_worker.js +1 -1
  28. package/package.json +2 -1
  29. package/scripts/install/install.ps1 +3 -1
  30. package/scripts/install/install.sh +34 -6
@@ -1,33 +1,38 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  runDaemonChild
4
- } from "./chunk-K5QHR5KU.js";
4
+ } from "./chunk-HAFTH5MX.js";
5
5
  import {
6
6
  RemoteManagementUnauthorizedError,
7
7
  TunnelOperations,
8
8
  closeRemoteManagement,
9
+ getRemoteManagementState,
10
+ initiateRemoteManagement
11
+ } from "./chunk-Q5NCTGNS.js";
12
+ import "./chunk-CZOKR73F.js";
13
+ import "./chunk-MHQ3CVEB.js";
14
+ import "./chunk-2GIJXE4K.js";
15
+ import "./chunk-XZ64ZAGO.js";
16
+ import {
17
+ TunnelManager
18
+ } from "./chunk-3WMTTJHI.js";
19
+ import "./chunk-UB26QJ4T.js";
20
+ import "./chunk-FQ22KFVV.js";
21
+ import {
9
22
  ensureDaemonRunning,
10
23
  getActiveTunnelSummaries,
11
24
  getDaemonInfo,
12
25
  getInProcessDaemonHandle,
13
- getRemoteManagementState,
14
- initiateRemoteManagement,
15
26
  isDaemonRunning
16
- } from "./chunk-3PTLHLFL.js";
17
- import "./chunk-X6TZN5CT.js";
27
+ } from "./chunk-4XXAHYCJ.js";
18
28
  import {
19
29
  DaemonHost
20
- } from "./chunk-7EQKHVQX.js";
21
- import "./chunk-QZJGTQZC.js";
22
- import "./chunk-XZ64ZAGO.js";
23
- import {
24
- TunnelManager
25
- } from "./chunk-EMCDDH3B.js";
26
- import "./chunk-UB26QJ4T.js";
30
+ } from "./chunk-MKGD2QAI.js";
31
+ import "./chunk-HTIWY3O5.js";
27
32
  import {
28
33
  enablePackageLogging
29
- } from "./chunk-IRKMUV37.js";
30
- import "./chunk-N5WE4DYD.js";
34
+ } from "./chunk-LWCVB42S.js";
35
+ import "./chunk-MAK5R4WQ.js";
31
36
  export {
32
37
  DaemonHost,
33
38
  RemoteManagementUnauthorizedError,
@@ -0,0 +1,237 @@
1
+ import {
2
+ UpdateError,
3
+ acquireUpdateLock,
4
+ assetNameFor,
5
+ createUpdateTarget,
6
+ downloadRelease,
7
+ isNewerVersion,
8
+ isReleaseComplete,
9
+ isUpdateLockOurs,
10
+ readBinaryIpcVersion,
11
+ releaseUpdateLock,
12
+ removeQuietly,
13
+ removeStaleUnixFiles,
14
+ removeStaleUpdateFiles,
15
+ resolveLatestNpmVersion,
16
+ resolveLatestTag,
17
+ runPinggyBinary,
18
+ versionFromTag
19
+ } from "./chunk-FQ22KFVV.js";
20
+ import {
21
+ InstallKind,
22
+ backgroundInstallKind,
23
+ canReplaceItself,
24
+ createInstallProbe,
25
+ daemonIpcVersion,
26
+ detectInstallKind,
27
+ getDaemonInfo,
28
+ nowEpochSeconds,
29
+ readUpdateState,
30
+ recordLatestVersion,
31
+ unixLayoutPaths,
32
+ writeUpdateState
33
+ } from "./chunk-4XXAHYCJ.js";
34
+ import "./chunk-MKGD2QAI.js";
35
+ import {
36
+ errorMessage,
37
+ getVersion
38
+ } from "./chunk-HTIWY3O5.js";
39
+ import "./chunk-LWCVB42S.js";
40
+ import {
41
+ ensurePinggyLogDir,
42
+ getUpdateLogPath
43
+ } from "./chunk-MAK5R4WQ.js";
44
+
45
+ // src/update/updateChild.ts
46
+ import fs from "fs";
47
+ import os from "os";
48
+ var TIME_LIMIT_MILLIS = 30 * 60 * 1e3;
49
+ var CHECK_TIMEOUT_MILLIS = 15e3;
50
+ var CHECK_INTERVAL_SECONDS = 24 * 60 * 60;
51
+ var MAX_FAILED_ATTEMPTS = 3;
52
+ function checkedRecently(state, now) {
53
+ const last = state.lastCheckEpochSeconds;
54
+ return last !== void 0 && last <= now && now - last < CHECK_INTERVAL_SECONDS;
55
+ }
56
+ function saveCheckTime(environment) {
57
+ environment.writeState({ lastCheckEpochSeconds: environment.nowEpochSeconds() });
58
+ }
59
+ async function latestVersionAndTag(environment) {
60
+ try {
61
+ if (environment.kind === InstallKind.Npm) {
62
+ const latest = await environment.resolveNpmVersion();
63
+ return { tag: `v${latest}`, latest };
64
+ }
65
+ const tag = await environment.resolveTag();
66
+ return { tag, latest: versionFromTag(tag) };
67
+ } catch (error) {
68
+ environment.log(`Could not find the latest version: ${errorMessage(error)}`);
69
+ return null;
70
+ }
71
+ }
72
+ async function releaseIsReady(tag, environment) {
73
+ if (environment.kind === InstallKind.Npm) return true;
74
+ try {
75
+ if (await environment.isReleaseComplete(tag)) return true;
76
+ environment.log(`Release ${tag} has no SHA256SUMS yet`);
77
+ } catch (error) {
78
+ environment.log(`Could not check release ${tag}: ${errorMessage(error)}`);
79
+ }
80
+ return false;
81
+ }
82
+ function daemonStillDiffers(state, environment) {
83
+ const daemon = environment.liveDaemon();
84
+ return daemon !== null && daemonIpcVersion(daemon) !== state.deferredIpcVersion;
85
+ }
86
+ function skipReason(latest, state, environment) {
87
+ if (!canReplaceItself(environment.kind) || environment.target === null) return "this install cannot update itself";
88
+ if (latest === state.rolledBackFromVersion) return "the user rolled back from this version";
89
+ if (latest === state.failedVersion && (state.failedAttempts ?? 0) >= MAX_FAILED_ATTEMPTS) return "this version failed too many times";
90
+ if (latest === state.deferredVersion && daemonStillDiffers(state, environment)) return "a live daemon still needs a restart first";
91
+ return null;
92
+ }
93
+ function countFailure(latest, environment) {
94
+ const state = environment.readState();
95
+ const attempts = state.failedVersion === latest ? (state.failedAttempts ?? 0) + 1 : 1;
96
+ environment.writeState({ failedVersion: latest, failedAttempts: attempts });
97
+ }
98
+ async function holdForLiveDaemon(latest, target, environment) {
99
+ const newIpcVersion = await environment.readIpcVersion(target.downloadPath);
100
+ const daemon = environment.liveDaemon();
101
+ if (daemon === null || daemonIpcVersion(daemon) === newIpcVersion) return false;
102
+ environment.writeState({ deferredVersion: latest, deferredIpcVersion: newIpcVersion });
103
+ environment.log(`Held ${latest}: the running daemon speaks IPC v${daemonIpcVersion(daemon)}, this release v${newIpcVersion}`);
104
+ return true;
105
+ }
106
+ function lostTheRight(latest, environment) {
107
+ return !environment.isLockOurs() || environment.readState().rolledBackFromVersion === latest;
108
+ }
109
+ var Outcome = {
110
+ Finished: "finished",
111
+ TryAgainSoon: "try-again-soon"
112
+ };
113
+ async function installRelease(release, installed, target, environment) {
114
+ const { tag, latest } = release;
115
+ try {
116
+ await environment.download(target, tag);
117
+ if (await holdForLiveDaemon(latest, target, environment)) return Outcome.Finished;
118
+ if (lostTheRight(latest, environment)) {
119
+ environment.log("Stopped before the swap: the lock was lost, or the user rolled back");
120
+ return Outcome.TryAgainSoon;
121
+ }
122
+ await target.install({ newVersion: latest, runningVersion: environment.runningVersion });
123
+ environment.writeState({
124
+ updatedFromVersion: installed,
125
+ updatedToVersion: latest,
126
+ failedVersion: void 0,
127
+ failedAttempts: void 0,
128
+ deferredVersion: void 0,
129
+ deferredIpcVersion: void 0
130
+ });
131
+ environment.log(`Updated ${installed} to ${latest}`);
132
+ } catch (error) {
133
+ if (error instanceof UpdateError && error.countsAsBadRelease) countFailure(latest, environment);
134
+ environment.log(`Update to ${latest} failed: ${errorMessage(error)}`);
135
+ } finally {
136
+ environment.removeFile(target.downloadPath);
137
+ }
138
+ return Outcome.Finished;
139
+ }
140
+ async function runLocked(environment) {
141
+ environment.startLog();
142
+ if (checkedRecently(environment.readState(), environment.nowEpochSeconds())) {
143
+ environment.log("Another update checked within the last 24 hours");
144
+ return;
145
+ }
146
+ const release = await latestVersionAndTag(environment);
147
+ if (!release) return;
148
+ const installed = environment.target?.installedVersion(environment.runningVersion) ?? environment.runningVersion;
149
+ if (!isNewerVersion(release.latest, installed)) {
150
+ environment.recordLatestVersion(release.latest);
151
+ saveCheckTime(environment);
152
+ environment.log(`${installed} is up to date`);
153
+ return;
154
+ }
155
+ if (!await releaseIsReady(release.tag, environment)) return;
156
+ environment.recordLatestVersion(release.latest);
157
+ const reason = skipReason(release.latest, environment.readState(), environment);
158
+ if (reason || environment.target === null) {
159
+ saveCheckTime(environment);
160
+ environment.log(`No download: ${reason}`);
161
+ return;
162
+ }
163
+ if (await installRelease(release, installed, environment.target, environment) === Outcome.Finished) saveCheckTime(environment);
164
+ }
165
+ async function runUpdateChild(environment = createUpdateChildEnvironment()) {
166
+ const cancelTimeLimit = environment.startTimeLimit(() => {
167
+ if (environment.target) environment.removeFile(environment.target.downloadPath);
168
+ environment.exitProcess();
169
+ });
170
+ try {
171
+ environment.removeStaleFiles();
172
+ if (!await environment.acquireLock()) return;
173
+ try {
174
+ await runLocked(environment);
175
+ } finally {
176
+ environment.releaseLock();
177
+ }
178
+ } catch (error) {
179
+ environment.log(`Failed: ${errorMessage(error)}`);
180
+ } finally {
181
+ cancelTimeLimit();
182
+ }
183
+ }
184
+ function removeStaleFilesFor(platform, homeRealPath) {
185
+ if (platform === "win32") removeStaleUpdateFiles();
186
+ else removeStaleUnixFiles(unixLayoutPaths(homeRealPath));
187
+ }
188
+ function writeLogLine(logPath, line) {
189
+ try {
190
+ fs.appendFileSync(logPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}${os.EOL}`);
191
+ } catch {
192
+ }
193
+ }
194
+ function startLogFile(logPath) {
195
+ try {
196
+ ensurePinggyLogDir();
197
+ fs.writeFileSync(logPath, "");
198
+ } catch {
199
+ }
200
+ }
201
+ function createUpdateChildEnvironment() {
202
+ const probe = createInstallProbe();
203
+ const kind = backgroundInstallKind(detectInstallKind(probe), probe.execPath, probe.homeRealPath);
204
+ const runningVersion = getVersion();
205
+ const timeout = { timeoutMillis: CHECK_TIMEOUT_MILLIS };
206
+ const logPath = getUpdateLogPath();
207
+ return {
208
+ kind,
209
+ target: createUpdateTarget(kind, probe),
210
+ runningVersion,
211
+ nowEpochSeconds,
212
+ acquireLock: acquireUpdateLock,
213
+ releaseLock: releaseUpdateLock,
214
+ isLockOurs: isUpdateLockOurs,
215
+ readState: readUpdateState,
216
+ writeState: writeUpdateState,
217
+ recordLatestVersion,
218
+ resolveTag: () => resolveLatestTag(timeout),
219
+ resolveNpmVersion: () => resolveLatestNpmVersion(timeout),
220
+ isReleaseComplete: (tag) => isReleaseComplete(tag, timeout),
221
+ download: (target, tag) => downloadRelease(target, tag, assetNameFor(probe.platform, process.arch), runningVersion),
222
+ readIpcVersion: (binaryPath) => readBinaryIpcVersion(binaryPath, runPinggyBinary),
223
+ liveDaemon: getDaemonInfo,
224
+ removeStaleFiles: () => removeStaleFilesFor(probe.platform, probe.homeRealPath),
225
+ removeFile: removeQuietly,
226
+ startLog: () => startLogFile(logPath),
227
+ log: (line) => writeLogLine(logPath, line),
228
+ startTimeLimit: (onLimit) => {
229
+ const timer = setTimeout(onLimit, TIME_LIMIT_MILLIS);
230
+ return () => clearTimeout(timer);
231
+ },
232
+ exitProcess: () => process.exit(0)
233
+ };
234
+ }
235
+ export {
236
+ runUpdateChild
237
+ };
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-UB26QJ4T.js";
4
4
  import {
5
5
  logger
6
- } from "../chunk-IRKMUV37.js";
6
+ } from "../chunk-LWCVB42S.js";
7
7
 
8
8
  // src/workers/file_serve_worker.ts
9
9
  import { parentPort, workerData } from "worker_threads";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinggy",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "Create secure, shareable tunnels to your localhost and manage them from the command line. ",
@@ -48,6 +48,7 @@
48
48
  "node_modules/@pinggy/pinggy/**/*",
49
49
  "node_modules/blessed/lib/**/*",
50
50
  "node_modules/blessed/usr/**/*",
51
+ "node_modules/node-pty/build/Release/pty.node",
51
52
  "dist/workers/**/*"
52
53
  ],
53
54
  "ignore": [
@@ -17,7 +17,6 @@
17
17
  # $env:PINGGY_MANAGE a non-production dashboard host, passed to `pinggy device login` or `connect` as --manage
18
18
  #
19
19
  # The source lives in Pinggy-io/cli-js, scripts/install/. A release copies it to pinggy.io.
20
- # Design: docs/pinggy-devices/install-script-plan.md in the pinggy_backend repo.
21
20
  #
22
21
  # iex runs this inside the user's own session. So it never calls exit, which would close their window, and every
23
22
  # helper and preference is local to Install-Pinggy. Nothing runs until the last line.
@@ -35,6 +34,7 @@ function Install-Pinggy {
35
34
  $installDir = Join-Path $env:LOCALAPPDATA 'Pinggy\bin'
36
35
  $installPath = Join-Path $installDir 'pinggy.exe'
37
36
  $versionPattern = 'Pinggy CLI version:\s*(\S+)'
37
+ $autoUpdatePinLine = 'Auto-update replaces this version. Set PINGGY_AUTO_UPDATE=false to keep it.'
38
38
  # The task `pinggy daemon service-install` registers. Its name lives in src/daemon/lifecycle/serviceInstaller.ts.
39
39
  $loginTaskName = 'PinggyDaemon'
40
40
  $cpuArchitectureX64 = 9
@@ -184,6 +184,7 @@ function Install-Pinggy {
184
184
  Install-Binary $tag $cpu
185
185
  } else {
186
186
  Write-Host "Keeping pinggy $installedVersion."
187
+ if (-not $env:PINGGY_VERSION) { Write-Host $autoUpdatePinLine }
187
188
  }
188
189
  }
189
190
 
@@ -288,6 +289,7 @@ function Install-Pinggy {
288
289
  try {
289
290
  $cpu = Get-Cpu
290
291
  Install-OrUpdate $cpu
292
+ if ($env:PINGGY_VERSION) { Write-Host $autoUpdatePinLine }
291
293
  Add-InstallDirToPath
292
294
  if ($env:DEVICE_AGENT_TOKEN) {
293
295
  Invoke-DeviceConnect
@@ -5,8 +5,9 @@
5
5
  # curl -fsSL https://pinggy.io/install.sh | sh
6
6
  # curl -fsSL https://pinggy.io/install.sh | DEVICE_AGENT_TOKEN=<token> sh
7
7
  #
8
- # The binary goes to ~/.pinggy/bin/pinggy, and a symlink in ~/.local/bin puts it on PATH. No sudo: every write is
9
- # under $HOME. When ~/.local/bin is not on PATH, 1 marked block goes into the shell's rc file, once.
8
+ # The binary goes to ~/.pinggy/versions/<version>/pinggy. ~/.pinggy/bin/pinggy links to it, and a symlink in
9
+ # ~/.local/bin puts it on PATH. No sudo: every write is under $HOME. When ~/.local/bin is not on PATH, 1 marked block
10
+ # goes into the shell's rc file, once.
10
11
  #
11
12
  # Setting, from the dashboard's command:
12
13
  # DEVICE_AGENT_TOKEN a device token. An older pinggy updates without asking, then `pinggy device connect` runs
@@ -19,7 +20,6 @@
19
20
  # PINGGY_MANAGE a non-production dashboard host, passed to `pinggy device login` or `connect` as --manage
20
21
  #
21
22
  # The source lives in Pinggy-io/cli-js, scripts/install/. A release copies it to pinggy.io.
22
- # Design: docs/pinggy-devices/install-script-plan.md in the pinggy_backend repo.
23
23
  #
24
24
  # Nothing runs until the last line. A download cut off halfway defines some functions and runs no command.
25
25
 
@@ -28,6 +28,7 @@ set -eu
28
28
  RELEASES_URL="https://github.com/Pinggy-io/cli-js/releases"
29
29
  INSTALL_DIR="$HOME/.pinggy/bin"
30
30
  INSTALL_PATH="$INSTALL_DIR/pinggy"
31
+ VERSIONS_DIR="$HOME/.pinggy/versions"
31
32
  LINK_DIR="$HOME/.local/bin"
32
33
  LINK_PATH="$LINK_DIR/pinggy"
33
34
  RC_MARKER="# Added by the Pinggy installer"
@@ -198,8 +199,8 @@ remove_partial_download() {
198
199
  fi
199
200
  }
200
201
 
201
- # Writes the binary to a temp file in the install directory, so the final mv is a rename on 1 filesystem. A
202
- # running agent keeps the old inode, so replacing the file under it is safe.
202
+ # Writes the binary to a temp file under ~/.pinggy, so the final mv is a rename on 1 filesystem. The binary goes in its
203
+ # own version folder and ~/.pinggy/bin/pinggy links to it. A running agent keeps its own file.
203
204
  install_binary() {
204
205
  if [ -n "${PINGGY_BINARY_URL:-}" ]; then
205
206
  url="$PINGGY_BINARY_URL"
@@ -222,11 +223,29 @@ install_binary() {
222
223
  fail_does_not_run
223
224
  fi
224
225
 
225
- mv -f "$download_path" "$INSTALL_PATH"
226
+ previous_target=$(readlink "$INSTALL_PATH" 2>/dev/null || true)
227
+ mkdir -p "$VERSIONS_DIR/$downloaded_version"
228
+ mv -f "$download_path" "$VERSIONS_DIR/$downloaded_version/pinggy"
226
229
  download_path=""
230
+ # A temp link and a rename, because ln -sf removes the old link before it creates the new one.
231
+ ln -s "$VERSIONS_DIR/$downloaded_version/pinggy" "$INSTALL_DIR/pinggy.link.$$"
232
+ mv -f "$INSTALL_DIR/pinggy.link.$$" "$INSTALL_PATH"
233
+ prune_versions "$downloaded_version" "$(basename "$(dirname "${previous_target:-none}")")"
227
234
  say "Installed pinggy $downloaded_version to $(shown "$INSTALL_PATH")"
228
235
  }
229
236
 
237
+ # Keeps the new version and the one the link named before. Only names made of digits and dots are versions. With
238
+ # auto-update off, nothing else removes old versions.
239
+ prune_versions() {
240
+ for version_dir in "$VERSIONS_DIR"/*/; do
241
+ version_name=$(basename "$version_dir")
242
+ case "$version_name" in
243
+ *[!0-9.]* | "$1" | "$2") continue ;;
244
+ esac
245
+ rm -rf "$version_dir"
246
+ done
247
+ }
248
+
230
249
  # Steps 2 to 6 of the plan: compare with the installed binary, then download only when needed.
231
250
  install_or_update() {
232
251
  if [ -n "${PINGGY_BINARY_URL:-}" ]; then
@@ -256,6 +275,14 @@ install_or_update() {
256
275
  install_binary
257
276
  else
258
277
  say "Keeping pinggy $installed_version."
278
+ kept_older_version=1
279
+ fi
280
+ }
281
+
282
+ # A pinned or kept version lasts only until the next terminal command, unless auto-update is off.
283
+ warn_auto_update_replaces_it() {
284
+ if [ -n "${PINGGY_VERSION:-}" ] || [ "${kept_older_version:-0}" = 1 ]; then
285
+ say "Auto-update replaces this version. Set PINGGY_AUTO_UPDATE=false to keep it."
259
286
  fi
260
287
  }
261
288
 
@@ -437,6 +464,7 @@ main() {
437
464
  *) require_downloader ;;
438
465
  esac
439
466
  install_or_update
467
+ warn_auto_update_replaces_it
440
468
  link_into_path
441
469
  if has_device_token; then
442
470
  connect_with_device_token