typescript-virtual-container 1.1.3 → 1.1.4

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 (38) hide show
  1. package/dist/SSHMimic/exec.d.ts.map +1 -1
  2. package/dist/SSHMimic/exec.js +8 -2
  3. package/dist/SSHMimic/index.d.ts +1 -0
  4. package/dist/SSHMimic/index.d.ts.map +1 -1
  5. package/dist/SSHMimic/index.js +9 -3
  6. package/dist/SSHMimic/sftp.d.ts +46 -0
  7. package/dist/SSHMimic/sftp.d.ts.map +1 -0
  8. package/dist/SSHMimic/sftp.js +576 -0
  9. package/dist/VirtualFileSystem/index.d.ts +6 -4
  10. package/dist/VirtualFileSystem/index.d.ts.map +1 -1
  11. package/dist/VirtualFileSystem/index.js +144 -153
  12. package/dist/VirtualShell/index.d.ts +6 -0
  13. package/dist/VirtualShell/index.d.ts.map +1 -1
  14. package/dist/VirtualShell/index.js +16 -4
  15. package/dist/VirtualShell/shell.d.ts.map +1 -1
  16. package/dist/VirtualShell/shell.js +7 -0
  17. package/dist/VirtualUserManager/index.d.ts +1 -0
  18. package/dist/VirtualUserManager/index.d.ts.map +1 -1
  19. package/dist/VirtualUserManager/index.js +15 -0
  20. package/dist/commands/exit.d.ts.map +1 -1
  21. package/dist/commands/exit.js +1 -0
  22. package/dist/index.d.ts +2 -2
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +2 -2
  25. package/dist/standalone.js +10 -1
  26. package/package.json +1 -1
  27. package/src/SSHMimic/exec.ts +18 -12
  28. package/src/SSHMimic/index.ts +16 -7
  29. package/src/SSHMimic/sftp.ts +833 -0
  30. package/src/VirtualFileSystem/index.ts +158 -188
  31. package/src/VirtualShell/index.ts +19 -8
  32. package/src/VirtualShell/shell.ts +7 -0
  33. package/src/VirtualUserManager/index.ts +20 -0
  34. package/src/commands/exit.ts +1 -0
  35. package/src/index.ts +2 -1
  36. package/src/standalone.ts +11 -1
  37. package/tests/sftp.test.ts +319 -0
  38. package/tests/ssh-exec.test.ts +45 -0
@@ -1,4 +1,4 @@
1
- import { VirtualShell, VirtualSshServer } from ".";
1
+ import { VirtualSftpServer, VirtualShell, VirtualSshServer } from ".";
2
2
  const hostname = process.env.SSH_MIMIC_HOSTNAME ?? "typescript-vm";
3
3
  const virtualShell = new VirtualShell(hostname);
4
4
  virtualShell.addCommand("demo", [], () => {
@@ -23,3 +23,12 @@ new VirtualSshServer({
23
23
  console.error("Failed to start SSH Mimic:", error);
24
24
  process.exit(1);
25
25
  });
26
+ new VirtualSftpServer({ port: 2223, hostname, shell: virtualShell })
27
+ .start()
28
+ .then((port) => {
29
+ console.log(`SFTP Mimic initialized. Listening on port ${port}.`);
30
+ })
31
+ .catch((error) => {
32
+ console.error("Failed to start SFTP Mimic:", error);
33
+ process.exit(1);
34
+ });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
7
- "version": "1.1.3",
7
+ "version": "1.1.4",
8
8
  "license": "MIT",
9
9
  "keywords": [
10
10
  "ssh",
@@ -18,18 +18,24 @@ export function runExec(
18
18
  ): void {
19
19
  Promise.resolve(
20
20
  runCommand(cmd, authUser, hostname, "exec", `/home/${authUser}`, shell),
21
- ).then((result) => {
22
- if (result.stdout) {
23
- stream.write(`${toTtyLines(result.stdout)}\r\n`);
24
- }
21
+ )
22
+ .then((result) => {
23
+ if (result.stdout) {
24
+ stream.write(`${toTtyLines(result.stdout)}\r\n`);
25
+ }
25
26
 
26
- if (result.stderr) {
27
- stream.stderr.write(`${toTtyLines(result.stderr)}\r\n`);
28
- }
27
+ if (result.stderr) {
28
+ stream.stderr.write(`${toTtyLines(result.stderr)}\r\n`);
29
+ }
29
30
 
30
- stream.exit(result.exitCode ?? 0);
31
- console.log(shell.vfs);
32
- void shell.vfs.flushMirror();
33
- stream.end();
34
- });
31
+ stream.exit(result.exitCode ?? 0);
32
+ void shell.vfs.flushMirror();
33
+ stream.end();
34
+ })
35
+ .catch((error) => {
36
+ console.error("Exec error:", error);
37
+ stream.stderr.write(`Error: ${String(error)}\r\n`);
38
+ stream.exit(1);
39
+ stream.end();
40
+ });
35
41
  }
@@ -1,5 +1,6 @@
1
1
  import { Server as SshServer } from "ssh2";
2
2
  import { VirtualShell } from "../VirtualShell";
3
+ import { runExec } from "./exec";
3
4
  import { loadOrCreateHostKey } from "./hostKey";
4
5
 
5
6
  /**
@@ -46,6 +47,9 @@ class SshMimic {
46
47
  const shell = this.shell;
47
48
  const privateKey = loadOrCreateHostKey();
48
49
 
50
+ // Ensure VirtualShell is fully initialized before accepting connections
51
+ await shell.ensureInitialized();
52
+
49
53
  this.server = new SshServer(
50
54
  {
51
55
  hostKeys: [privateKey],
@@ -125,12 +129,16 @@ class SshMimic {
125
129
  });
126
130
 
127
131
  session.on("exec", (acceptExec, _rejectExec, info) => {
128
- const _stream = acceptExec();
129
- shell?.executeCommand(
130
- info.command.trim(),
131
- authUser,
132
- `/home/${authUser}`,
133
- );
132
+ const stream = acceptExec();
133
+ if (stream) {
134
+ runExec(
135
+ stream,
136
+ info.command.trim(),
137
+ authUser,
138
+ shell.hostname,
139
+ shell,
140
+ );
141
+ }
134
142
  });
135
143
  });
136
144
  });
@@ -139,7 +147,7 @@ class SshMimic {
139
147
 
140
148
  return new Promise<number>((resolve, reject) => {
141
149
  this.server?.once("error", (err: unknown) => reject(err));
142
- this.server?.listen(this.port, "127.0.0.1", () => {
150
+ this.server?.listen(this.port, "0.0.0.0", () => {
143
151
  console.log(`SSH Mimic listening on port ${this.port}`);
144
152
  resolve(this.port);
145
153
  });
@@ -158,4 +166,5 @@ class SshMimic {
158
166
  }
159
167
  }
160
168
 
169
+ export { SftpMimic } from "./sftp";
161
170
  export { SshMimic };