@zero-transfer/ssh 0.4.0 → 0.4.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/dist/index.mjs CHANGED
@@ -4785,6 +4785,19 @@ function isModifiedAtDifferent2(source, destination, toleranceMs) {
4785
4785
  return Math.abs(sourceTime - destinationTime) > toleranceMs;
4786
4786
  }
4787
4787
 
4788
+ // src/utils/mainModule.ts
4789
+ import { fileURLToPath } from "url";
4790
+ function isMainModule(importMetaUrl) {
4791
+ if (typeof process === "undefined" || !process.argv || process.argv.length < 2) {
4792
+ return false;
4793
+ }
4794
+ try {
4795
+ return process.argv[1] === fileURLToPath(importMetaUrl);
4796
+ } catch {
4797
+ return false;
4798
+ }
4799
+ }
4800
+
4788
4801
  // src/protocols/ssh/transport/SshTransportConnection.ts
4789
4802
  import { Buffer as Buffer16 } from "buffer";
4790
4803
 
@@ -6160,7 +6173,7 @@ var SshTransportPacketUnprotector = class {
6160
6173
  }
6161
6174
  /**
6162
6175
  * Feeds raw encrypted bytes from the socket and returns any fully decoded payloads.
6163
- * Maintains internal framing state across calls pass each `data` event chunk directly.
6176
+ * Maintains internal framing state across calls - pass each `data` event chunk directly.
6164
6177
  */
6165
6178
  pushBytes(chunk) {
6166
6179
  this.framePendingRaw = Buffer15.concat([this.framePendingRaw, chunk]);
@@ -6668,7 +6681,7 @@ var SshTransportConnection = class {
6668
6681
  assertConnected() {
6669
6682
  if (!this.connected) {
6670
6683
  throw new ProtocolError({
6671
- message: "SshTransportConnection is not yet connected \u2014 call connect() first",
6684
+ message: "SshTransportConnection is not yet connected - call connect() first",
6672
6685
  protocol: "sftp",
6673
6686
  retryable: false
6674
6687
  });
@@ -7624,6 +7637,84 @@ var SshConnectionManager = class {
7624
7637
  }
7625
7638
  }
7626
7639
  };
7640
+
7641
+ // src/protocols/ssh/runSshCommand.ts
7642
+ import { connect } from "net";
7643
+ var DEFAULT_PORT = 22;
7644
+ var DEFAULT_CONNECT_TIMEOUT_MS = 1e4;
7645
+ var DEFAULT_HANDSHAKE_TIMEOUT_MS = 1e4;
7646
+ var DEFAULT_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
7647
+ async function runSshCommand(options) {
7648
+ const {
7649
+ host,
7650
+ port = DEFAULT_PORT,
7651
+ command,
7652
+ auth,
7653
+ transport: transportOptions,
7654
+ connectTimeoutMs = DEFAULT_CONNECT_TIMEOUT_MS,
7655
+ maxOutputBytes = DEFAULT_MAX_OUTPUT_BYTES
7656
+ } = options;
7657
+ const socket = await openTcpSocket(host, port, connectTimeoutMs);
7658
+ const transport = new SshTransportConnection({
7659
+ handshakeTimeoutMs: DEFAULT_HANDSHAKE_TIMEOUT_MS,
7660
+ ...transportOptions
7661
+ });
7662
+ try {
7663
+ const handshake = await transport.connect(socket);
7664
+ const authSession = new SshAuthSession(transport);
7665
+ await authSession.authenticate({
7666
+ credential: auth,
7667
+ sessionId: handshake.keyExchange.sessionId
7668
+ });
7669
+ const conn = new SshConnectionManager(transport);
7670
+ const channel = await conn.openExecChannel(command);
7671
+ const pump = conn.start();
7672
+ pump.catch(() => {
7673
+ });
7674
+ const chunks = [];
7675
+ let bytesReceived = 0;
7676
+ try {
7677
+ for await (const chunk of channel.receiveData()) {
7678
+ bytesReceived += chunk.length;
7679
+ if (bytesReceived > maxOutputBytes) {
7680
+ throw new Error(
7681
+ `runSshCommand: stdout exceeded ${maxOutputBytes} bytes (set maxOutputBytes to allow more)`
7682
+ );
7683
+ }
7684
+ chunks.push(chunk);
7685
+ }
7686
+ } finally {
7687
+ channel.close();
7688
+ }
7689
+ const stdout = Buffer.concat(chunks);
7690
+ return {
7691
+ stdout,
7692
+ stdoutText: stdout.toString("utf8"),
7693
+ bytesReceived
7694
+ };
7695
+ } finally {
7696
+ transport.disconnect();
7697
+ }
7698
+ }
7699
+ function openTcpSocket(host, port, timeoutMs) {
7700
+ return new Promise((resolve, reject) => {
7701
+ const socket = connect({ host, port });
7702
+ const timer = setTimeout(() => {
7703
+ socket.destroy();
7704
+ reject(
7705
+ new Error(`runSshCommand: TCP connect to ${host}:${port} timed out after ${timeoutMs}ms`)
7706
+ );
7707
+ }, timeoutMs);
7708
+ socket.once("connect", () => {
7709
+ clearTimeout(timer);
7710
+ resolve(socket);
7711
+ });
7712
+ socket.once("error", (error) => {
7713
+ clearTimeout(timer);
7714
+ reject(error);
7715
+ });
7716
+ });
7717
+ }
7627
7718
  export {
7628
7719
  AbortError,
7629
7720
  AuthenticationError,
@@ -7687,6 +7778,7 @@ export {
7687
7778
  importOpenSshConfig,
7688
7779
  importWinScpSessions,
7689
7780
  isClassicProviderId,
7781
+ isMainModule,
7690
7782
  isSensitiveKey,
7691
7783
  joinRemotePath,
7692
7784
  matchKnownHosts,
@@ -7708,6 +7800,7 @@ export {
7708
7800
  resolveProviderId,
7709
7801
  resolveSecret,
7710
7802
  runConnectionDiagnostics,
7803
+ runSshCommand,
7711
7804
  serializeRemoteManifest,
7712
7805
  sortRemoteEntries,
7713
7806
  summarizeClientDiagnostics,