aptunnel 1.0.4 → 1.1.0

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/README.md CHANGED
@@ -23,6 +23,7 @@
23
23
  ```
24
24
  aptunnel dev-db # open tunnel to dev database
25
25
  aptunnel all # open all configured tunnels
26
+ aptunnel dbs # list all configured databases
26
27
  aptunnel status # see what's running
27
28
  ```
28
29
 
@@ -49,13 +50,32 @@ npm install -g aptunnel
49
50
  aptunnel init
50
51
  ```
51
52
 
52
- The wizard will:
53
- 1. Verify Aptible CLI is installed
54
- 2. Log you in (supports 2FA)
53
+ The setup wizard will:
54
+
55
+ 1. Verify the Aptible CLI is installed
56
+ 2. Log you in — supports **2FA** (OTP prompt appears directly in your terminal)
55
57
  3. Discover all your environments and databases
56
- 4. Auto-assign ports starting at `55550`
57
- 5. Let you set short aliases (e.g. `dev-db`, `dev-redis`)
58
- 6. Write `~/.aptunnel/config.yaml`
58
+ 4. Auto-assign local ports starting at `55550`
59
+ 5. Let you customize short aliases (e.g. `dev-db`, `dev-redis`) and ports
60
+ 6. Ask which environment to use as the **default** (or skip with `0` for no default)
61
+ 7. Write `~/.aptunnel/config.yaml`
62
+
63
+ **Environment selection during init:**
64
+
65
+ ```
66
+ Available environments:
67
+ [1] my-company-production-abc123
68
+ [2] my-company-staging-def456
69
+ [3] my-company-development-ghi789
70
+
71
+ Select environments (comma-separated numbers, "all", or press Enter for all): 1,3
72
+
73
+ Set a default environment (used when no --env flag is given):
74
+ [1] my-company-production-abc123
75
+ [2] my-company-development-ghi789
76
+ [0] None (no default)
77
+ Default environment (0 to skip) [1]:
78
+ ```
59
79
 
60
80
  ---
61
81
 
@@ -95,6 +115,22 @@ aptunnel all # uses default environment
95
115
  aptunnel all --env=staging
96
116
  ```
97
117
 
118
+ ### List databases
119
+
120
+ ```bash
121
+ aptunnel dbs # all configured databases
122
+ aptunnel dbs --env=staging # filter by environment
123
+ ```
124
+
125
+ Output:
126
+ ```
127
+ ALIAS DATABASE TYPE PORT ENVIRONMENT
128
+ ─────────────────────────────────────────────────────────────────────
129
+ dev-db mydb-dev postgresql 55550 dev
130
+ dev-redis mydb-dev-redis redis 55551 dev
131
+ stg-db mydb-staging postgresql 55552 staging
132
+ ```
133
+
98
134
  ### Status
99
135
 
100
136
  ```bash
@@ -109,9 +145,9 @@ LOGIN STATUS
109
145
  TUNNELS
110
146
 
111
147
  ENVIRONMENT DATABASE ALIAS PORT STATUS UPTIME PID CONNECTION URL
112
- ──────────── ─────────────── ─────────── ────── ─────── ──────────── ────── ──────────────────────────────────────────
113
- dev ekaredb-dev dev-db 55554 UP 02h15m30s 12345 postgresql://aptible:xxx@localhost.aptible.in:55554/db
114
- dev ekaredb-redis dev-redis 55555 DOWN - - -
148
+ ──────────────────────────────────────────────────────────────────────────────────────────────
149
+ dev ekaredb-dev dev-db 55554 UP 02h15m30s 12345 postgresql://aptible:xxx@localhost.aptible.in:55554/db
150
+ dev ekaredb-redis dev-redis 55555 DOWN - - -
115
151
  ```
116
152
 
117
153
  ### Login
@@ -119,7 +155,7 @@ dev ekaredb-redis dev-redis 55555 DOWN - - -
119
155
  ```bash
120
156
  aptunnel login # uses saved credentials, supports 2FA
121
157
  aptunnel login --email=x@y.com --password=secret
122
- aptunnel login --lifetime=14d # custom token lifetime
158
+ aptunnel login --lifetime=14d # custom token lifetime (default: 7d)
123
159
  aptunnel login --status # show token info only
124
160
  ```
125
161
 
@@ -147,7 +183,7 @@ credentials:
147
183
  email: you@company.com
148
184
 
149
185
  defaults:
150
- environment: my-env-development
186
+ environment: my-env-development # omitted if you chose "no default" during init
151
187
  lifetime: 7d
152
188
 
153
189
  environments:
@@ -168,6 +204,13 @@ tunnel_defaults:
168
204
  port_increment: 1
169
205
  ```
170
206
 
207
+ ### Overridable environment variables
208
+
209
+ | Variable | Default | Purpose |
210
+ |---|---|---|
211
+ | `APTUNNEL_CONFIG_HOME` | `~/.aptunnel` | Config directory location |
212
+ | `APTUNNEL_TEMP_DIR` | system tmpdir | PID/log file directory |
213
+
171
214
  ---
172
215
 
173
216
  ## Shell Completions
@@ -200,7 +243,7 @@ Completions are dynamic — your actual database aliases appear in tab-completio
200
243
  | **Linux** | ✅ Full | `lsof`, `ps`, Unix signals |
201
244
  | **macOS** | ✅ Full | Same as Linux |
202
245
  | **Windows** | ✅ Full | `netstat`, `tasklist`, `taskkill` |
203
- | **WSL** | ✅ Full | Treated as Linux, `wslview` for browser |
246
+ | **WSL** | ✅ Full | Treated as Linux |
204
247
 
205
248
  **Install Aptible CLI:**
206
249
 
@@ -221,9 +264,11 @@ curl -s https://toolbelt.aptible.com/install.sh | bash
221
264
 
222
265
  `aptible db:tunnel` is a blocking foreground process. aptunnel spawns it **detached** with `stdio` redirected to a log file (`/tmp/aptunnel-<alias>.log`), then saves the PID to `/tmp/aptunnel-<alias>.pid`.
223
266
 
267
+ The tunnel is considered open once aptible prints `Connect at` in the log (polled every 500ms, timeout 60s).
268
+
224
269
  On `aptunnel status`, each PID file is checked to determine if the process is still alive.
225
270
 
226
- When you close a tunnel (`aptunnel dev-db --close`), aptunnel kills the process and cleans up the PID file.
271
+ When you close a tunnel (`aptunnel dev-db --close`), aptunnel kills the process and cleans up PID/log files.
227
272
 
228
273
  Pressing **Ctrl+C** while aptunnel is running closes all open tunnels before exiting.
229
274
 
@@ -241,6 +286,8 @@ Pressing **Ctrl+C** while aptunnel is running closes all open tunnels before exi
241
286
 
242
287
  **Tunnel fails silently** — Check the log file: `cat /tmp/aptunnel-<alias>.log`.
243
288
 
289
+ **`aptunnel init` hangs after email/password** — This can happen if the terminal is not a TTY. Make sure you're running aptunnel directly in a terminal, not piped.
290
+
244
291
  ---
245
292
 
246
293
  ## Contributing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aptunnel",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Cross-platform Aptible tunnel manager — multi-tunnel, auto-discovery, background process management",
5
5
  "type": "module",
6
6
  "bin": {
@@ -87,12 +87,17 @@ export async function runInit(args) {
87
87
  }
88
88
 
89
89
  // 7. Set default environment
90
- let defaultEnvHandle = selectedEnvs[0].handle;
91
- if (selectedEnvs.length > 1) {
92
- console.log('');
93
- selectedEnvs.forEach((env, i) => console.log(` [${i + 1}] ${env.handle}`));
94
- const defChoice = await ask(`Default environment [1]: `);
95
- const defIdx = parseInt(defChoice.trim() || '1', 10) - 1;
90
+ console.log('');
91
+ console.log('Set a default environment (used when no --env flag is given):');
92
+ selectedEnvs.forEach((env, i) => console.log(` [${i + 1}] ${env.handle}`));
93
+ console.log(' [0] None (no default)');
94
+ const defChoice = await ask(`Default environment (0 to skip) [1]: `);
95
+ const defTrimmed = defChoice.trim();
96
+ let defaultEnvHandle = null;
97
+ if (defTrimmed === '0') {
98
+ defaultEnvHandle = null;
99
+ } else {
100
+ const defIdx = parseInt(defTrimmed || '1', 10) - 1;
96
101
  if (defIdx >= 0 && defIdx < selectedEnvs.length) {
97
102
  defaultEnvHandle = selectedEnvs[defIdx].handle;
98
103
  }
@@ -166,8 +171,8 @@ export async function runInit(args) {
166
171
  version: 1,
167
172
  credentials: { email },
168
173
  defaults: {
169
- environment: defaultEnvHandle,
170
- lifetime: '7d',
174
+ ...(defaultEnvHandle ? { environment: defaultEnvHandle } : {}),
175
+ lifetime: '7d',
171
176
  },
172
177
  environments: configEnvironments,
173
178
  tunnel_defaults: {