@heroku/heroku-cli-util 10.1.0 → 10.1.1

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.
@@ -1,5 +1,4 @@
1
1
  import { Server } from 'node:net';
2
- import * as createTunnel from 'tunnel-ssh';
3
2
  import type { ExtendedAddonAttachment } from './data-api.js';
4
3
  export type ConnectionDetails = {
5
4
  _tunnel?: Server;
@@ -14,7 +13,15 @@ export type ConnectionDetails = {
14
13
  export type ConnectionDetailsWithAttachment = {
15
14
  attachment: ExtendedAddonAttachment;
16
15
  } & ConnectionDetails;
17
- export type TunnelConfig = createTunnel.Config;
16
+ export interface TunnelConfig {
17
+ dstHost: string;
18
+ dstPort: number;
19
+ host?: string;
20
+ localHost: string;
21
+ localPort: number;
22
+ privateKey?: string;
23
+ username: string;
24
+ }
18
25
  export interface BastionConfigResponse {
19
26
  host: string;
20
27
  private_key: string;
@@ -1,6 +1,5 @@
1
1
  import type { APIClient } from '@heroku-cli/command';
2
2
  import { Server } from 'node:net';
3
- import * as createTunnel from 'tunnel-ssh';
4
3
  import { ExtendedAddonAttachment } from '../../types/pg/data-api.js';
5
4
  import { BastionConfig, ConnectionDetailsWithAttachment, TunnelConfig } from '../../types/pg/tunnel.js';
6
5
  /**
@@ -46,7 +45,7 @@ export declare const getBastionConfig: (config: Record<string, string>, baseName
46
45
  */
47
46
  export declare function getPsqlConfigs(connectionDetails: ConnectionDetailsWithAttachment): {
48
47
  dbEnv: NodeJS.ProcessEnv;
49
- dbTunnelConfig: createTunnel.Config;
48
+ dbTunnelConfig: TunnelConfig;
50
49
  };
51
50
  export type PsqlConfigs = ReturnType<typeof getPsqlConfigs>;
52
51
  /**
@@ -55,8 +54,18 @@ export type PsqlConfigs = ReturnType<typeof getPsqlConfigs>;
55
54
  * @param connectionDetails - The database connection details with attachment information
56
55
  * @param dbTunnelConfig - The tunnel configuration object
57
56
  * @param timeout - The timeout in milliseconds (default: 10000)
58
- * @param createSSHTunnel - The function to create the SSH tunnel (default: promisified createTunnel.default)
57
+ * @param createSSHTunnel - The function to create the SSH tunnel
59
58
  * @returns Promise that resolves to the tunnel server or null if no bastion key is provided
60
59
  * @throws Error if unable to establish the tunnel
61
60
  */
62
- export declare function sshTunnel(connectionDetails: ConnectionDetailsWithAttachment, dbTunnelConfig: TunnelConfig, timeout?: number, createSSHTunnel?: (arg1: createTunnel.Config | undefined) => Promise<Server>): Promise<Server | void>;
61
+ export declare function sshTunnel(connectionDetails: ConnectionDetailsWithAttachment, dbTunnelConfig: TunnelConfig, timeout?: number, createSSHTunnel?: typeof createSSHTunnelAdapter): Promise<Server | void>;
62
+ /**
63
+ * Adapter for tunnel-ssh v5 API. Translates our TunnelConfig into the v5
64
+ * createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions) call
65
+ * and returns the created local Server.
66
+ *
67
+ * @param config - The tunnel configuration to translate for v5 API
68
+ * @returns Promise that resolves to the created local TCP Server
69
+ */
70
+ declare function createSSHTunnelAdapter(config: TunnelConfig): Promise<Server>;
71
+ export {};
@@ -1,7 +1,6 @@
1
1
  import debug from 'debug';
2
2
  import { EventEmitter } from 'node:events';
3
- import { promisify } from 'node:util';
4
- import * as createTunnel from 'tunnel-ssh';
3
+ import * as tunnelSsh from 'tunnel-ssh';
5
4
  import host from './host.js';
6
5
  const pgDebug = debug('pg');
7
6
  /**
@@ -135,11 +134,11 @@ function tunnelConfig(connectionDetails) {
135
134
  * @param connectionDetails - The database connection details with attachment information
136
135
  * @param dbTunnelConfig - The tunnel configuration object
137
136
  * @param timeout - The timeout in milliseconds (default: 10000)
138
- * @param createSSHTunnel - The function to create the SSH tunnel (default: promisified createTunnel.default)
137
+ * @param createSSHTunnel - The function to create the SSH tunnel
139
138
  * @returns Promise that resolves to the tunnel server or null if no bastion key is provided
140
139
  * @throws Error if unable to establish the tunnel
141
140
  */
142
- export async function sshTunnel(connectionDetails, dbTunnelConfig, timeout = 10_000, createSSHTunnel = promisify(createTunnel.default)) {
141
+ export async function sshTunnel(connectionDetails, dbTunnelConfig, timeout = 10_000, createSSHTunnel = createSSHTunnelAdapter) {
143
142
  if (!connectionDetails.bastionKey) {
144
143
  return;
145
144
  }
@@ -203,3 +202,34 @@ class Timeout {
203
202
  }
204
203
  }
205
204
  }
205
+ /**
206
+ * Adapter for tunnel-ssh v5 API. Translates our TunnelConfig into the v5
207
+ * createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions) call
208
+ * and returns the created local Server.
209
+ *
210
+ * @param config - The tunnel configuration to translate for v5 API
211
+ * @returns Promise that resolves to the created local TCP Server
212
+ */
213
+ async function createSSHTunnelAdapter(config) {
214
+ const tunnelOptions = {
215
+ autoClose: true,
216
+ reconnectOnError: false,
217
+ };
218
+ const serverOptions = {
219
+ host: config.localHost,
220
+ port: config.localPort,
221
+ };
222
+ const sshOptions = {
223
+ host: config.host,
224
+ privateKey: config.privateKey,
225
+ username: config.username,
226
+ };
227
+ const forwardOptions = {
228
+ dstAddr: config.dstHost,
229
+ dstPort: config.dstPort,
230
+ srcAddr: config.localHost,
231
+ srcPort: config.localPort,
232
+ };
233
+ const [server] = await tunnelSsh.createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions);
234
+ return server;
235
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@heroku/heroku-cli-util",
4
- "version": "10.1.0",
4
+ "version": "10.1.1",
5
5
  "description": "Set of helpful CLI utilities",
6
6
  "author": "Heroku",
7
7
  "license": "ISC",
@@ -49,7 +49,7 @@
49
49
  "@oclif/table": "0.4.8",
50
50
  "debug": "^4.4.0",
51
51
  "inquirer": "^12.6.1",
52
- "tunnel-ssh": "4.1.6"
52
+ "tunnel-ssh": "5.2.0"
53
53
  },
54
54
  "engines": {
55
55
  "node": ">=20"