@heroku/heroku-cli-util 10.1.2 → 10.1.3
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.d.ts
CHANGED
|
@@ -3,8 +3,11 @@ import { AmbiguousError } from './errors/ambiguous.js';
|
|
|
3
3
|
import { NotFound } from './errors/not-found.js';
|
|
4
4
|
import { AddOnWithRelatedData, ExtendedAddonAttachment, Link } from './types/pg/data-api.js';
|
|
5
5
|
import { ConnectionDetails, ConnectionDetailsWithAttachment, TunnelConfig } from './types/pg/tunnel.js';
|
|
6
|
+
import { getPsqlConfigs, sshTunnel } from './utils/pg/bastion.js';
|
|
7
|
+
import { getConfigVarNameFromAttachment } from './utils/pg/config-vars.js';
|
|
6
8
|
import DatabaseResolver from './utils/pg/databases.js';
|
|
7
9
|
import getHost from './utils/pg/host.js';
|
|
10
|
+
import PsqlService from './utils/pg/psql.js';
|
|
8
11
|
import { prompt } from './ux/prompt.js';
|
|
9
12
|
import { styledHeader } from './ux/styled-header.js';
|
|
10
13
|
import { styledJSON } from './ux/styled-json.js';
|
|
@@ -28,12 +31,16 @@ export declare const utils: {
|
|
|
28
31
|
};
|
|
29
32
|
pg: {
|
|
30
33
|
DatabaseResolver: typeof DatabaseResolver;
|
|
34
|
+
PsqlService: typeof PsqlService;
|
|
31
35
|
fetcher: {
|
|
32
36
|
database(heroku: APIClient, appId: string, attachmentId?: string, namespace?: string): Promise<ConnectionDetailsWithAttachment>;
|
|
33
37
|
};
|
|
34
38
|
host: typeof getHost;
|
|
35
39
|
psql: {
|
|
36
40
|
exec(connectionDetails: ConnectionDetailsWithAttachment, query: string, psqlCmdArgs?: string[]): Promise<string>;
|
|
41
|
+
getConfigVarNameFromAttachment: typeof getConfigVarNameFromAttachment;
|
|
42
|
+
getPsqlConfigs: typeof getPsqlConfigs;
|
|
43
|
+
sshTunnel: typeof sshTunnel;
|
|
37
44
|
};
|
|
38
45
|
};
|
|
39
46
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AmbiguousError } from './errors/ambiguous.js';
|
|
2
2
|
import { NotFound } from './errors/not-found.js';
|
|
3
|
+
import { getPsqlConfigs, sshTunnel } from './utils/pg/bastion.js';
|
|
4
|
+
import { getConfigVarNameFromAttachment } from './utils/pg/config-vars.js';
|
|
3
5
|
import DatabaseResolver from './utils/pg/databases.js';
|
|
4
6
|
import getHost from './utils/pg/host.js';
|
|
5
7
|
import PsqlService from './utils/pg/psql.js';
|
|
@@ -27,6 +29,7 @@ export const utils = {
|
|
|
27
29
|
},
|
|
28
30
|
pg: {
|
|
29
31
|
DatabaseResolver,
|
|
32
|
+
PsqlService,
|
|
30
33
|
fetcher: {
|
|
31
34
|
database(heroku, appId, attachmentId, namespace) {
|
|
32
35
|
const databaseResolver = new DatabaseResolver(heroku);
|
|
@@ -39,6 +42,9 @@ export const utils = {
|
|
|
39
42
|
const psqlService = new PsqlService(connectionDetails);
|
|
40
43
|
return psqlService.execQuery(query, psqlCmdArgs);
|
|
41
44
|
},
|
|
45
|
+
getConfigVarNameFromAttachment,
|
|
46
|
+
getPsqlConfigs,
|
|
47
|
+
sshTunnel,
|
|
42
48
|
},
|
|
43
49
|
},
|
|
44
50
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { APIClient } from '@heroku-cli/command';
|
|
2
2
|
import { Server } from 'node:net';
|
|
3
3
|
import { ExtendedAddonAttachment } from '../../types/pg/data-api.js';
|
|
4
|
-
import { BastionConfig,
|
|
4
|
+
import { BastionConfig, ConnectionDetails, TunnelConfig } from '../../types/pg/tunnel.js';
|
|
5
5
|
/**
|
|
6
6
|
* Determines whether the attachment belongs to an add-on installed onto a non-shield Private Space.
|
|
7
7
|
* If true, the bastion information needs to be fetched from the Data API.
|
|
@@ -43,7 +43,7 @@ export declare const getBastionConfig: (config: Record<string, string>, baseName
|
|
|
43
43
|
* @param connectionDetails - The database connection details with attachment information
|
|
44
44
|
* @returns Object containing database environment variables and tunnel configuration
|
|
45
45
|
*/
|
|
46
|
-
export declare function getPsqlConfigs(connectionDetails:
|
|
46
|
+
export declare function getPsqlConfigs(connectionDetails: ConnectionDetails): {
|
|
47
47
|
dbEnv: NodeJS.ProcessEnv;
|
|
48
48
|
dbTunnelConfig: TunnelConfig;
|
|
49
49
|
};
|
|
@@ -58,7 +58,7 @@ export type PsqlConfigs = ReturnType<typeof getPsqlConfigs>;
|
|
|
58
58
|
* @returns Promise that resolves to the tunnel server or null if no bastion key is provided
|
|
59
59
|
* @throws Error if unable to establish the tunnel
|
|
60
60
|
*/
|
|
61
|
-
export declare function sshTunnel(connectionDetails:
|
|
61
|
+
export declare function sshTunnel(connectionDetails: ConnectionDetails, dbTunnelConfig: TunnelConfig, timeout?: number, createSSHTunnel?: typeof createSSHTunnelAdapter): Promise<Server | void>;
|
|
62
62
|
/**
|
|
63
63
|
* Adapter for tunnel-ssh v5 API. Translates our TunnelConfig into the v5
|
|
64
64
|
* createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions) call
|
|
@@ -38,7 +38,7 @@ export default class DatabaseResolver {
|
|
|
38
38
|
* @param connStringOrDbName - PostgreSQL connection string or local database name
|
|
39
39
|
* @returns Connection details object with parsed connection information
|
|
40
40
|
*/
|
|
41
|
-
parsePostgresConnectionString(connStringOrDbName: string): ConnectionDetails;
|
|
41
|
+
static parsePostgresConnectionString(connStringOrDbName: string): ConnectionDetails;
|
|
42
42
|
/**
|
|
43
43
|
* Fetches all Heroku PostgreSQL add-on attachments for a given app.
|
|
44
44
|
*
|
|
@@ -57,7 +57,7 @@ export default class DatabaseResolver {
|
|
|
57
57
|
* @param config - The record of app config vars with their values
|
|
58
58
|
* @returns Connection details with attachment information
|
|
59
59
|
*/
|
|
60
|
-
|
|
60
|
+
getConnectionDetails(attachment: ExtendedAddonAttachment, config?: Record<string, string>): ConnectionDetailsWithAttachment;
|
|
61
61
|
/**
|
|
62
62
|
* Helper function that attempts to find a single addon attachment matching the given database identifier
|
|
63
63
|
* (attachment name, id, or config var name).
|
|
@@ -92,7 +92,8 @@ export default class DatabaseResolver {
|
|
|
92
92
|
* @param connStringOrDbName - PostgreSQL connection string or local database name
|
|
93
93
|
* @returns Connection details object with parsed connection information
|
|
94
94
|
*/
|
|
95
|
-
|
|
95
|
+
// eslint-disable-next-line perfectionist/sort-classes
|
|
96
|
+
static parsePostgresConnectionString(connStringOrDbName) {
|
|
96
97
|
const dbPath = /:\/\//.test(connStringOrDbName) ? connStringOrDbName : `postgres:///${connStringOrDbName}`;
|
|
97
98
|
const url = new URL(dbPath);
|
|
98
99
|
const { hostname, password, pathname, port, username } = url;
|
|
@@ -130,11 +131,12 @@ export default class DatabaseResolver {
|
|
|
130
131
|
* @param config - The record of app config vars with their values
|
|
131
132
|
* @returns Connection details with attachment information
|
|
132
133
|
*/
|
|
134
|
+
// eslint-disable-next-line perfectionist/sort-classes
|
|
133
135
|
getConnectionDetails(attachment, config = {}) {
|
|
134
136
|
const connStringVar = getConfigVarNameFromAttachment(attachment, config);
|
|
135
137
|
// build the default payload for non-bastion dbs
|
|
136
138
|
pgDebug(`Using "${connStringVar}" to connect to your database…`);
|
|
137
|
-
const conn =
|
|
139
|
+
const conn = DatabaseResolver.parsePostgresConnectionString(config[connStringVar]);
|
|
138
140
|
const payload = {
|
|
139
141
|
attachment,
|
|
140
142
|
database: conn.database,
|
package/dist/utils/pg/psql.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { Server } from 'node:net';
|
|
3
|
-
import {
|
|
3
|
+
import { ConnectionDetails, TunnelConfig } from '../../types/pg/tunnel.js';
|
|
4
4
|
import { getPsqlConfigs, sshTunnel } from './bastion.js';
|
|
5
5
|
/**
|
|
6
6
|
* A small wrapper around tunnel-ssh so that other code doesn't have to worry about whether there is or is not a tunnel.
|
|
@@ -22,7 +22,7 @@ export declare class Tunnel {
|
|
|
22
22
|
* @param tunnelFn - The function to create the SSH tunnel (default: sshTunnel)
|
|
23
23
|
* @returns Promise that resolves to a new Tunnel instance
|
|
24
24
|
*/
|
|
25
|
-
static connect(connectionDetails:
|
|
25
|
+
static connect(connectionDetails: ConnectionDetails, tunnelConfig: TunnelConfig, tunnelFn: typeof sshTunnel): Promise<Tunnel>;
|
|
26
26
|
/**
|
|
27
27
|
* Closes the tunnel if it exists, or emits a fake close event if no tunnel is needed.
|
|
28
28
|
*
|
|
@@ -42,7 +42,7 @@ export default class PsqlService {
|
|
|
42
42
|
private readonly getPsqlConfigsFn;
|
|
43
43
|
private readonly spawnFn;
|
|
44
44
|
private readonly tunnelFn;
|
|
45
|
-
constructor(connectionDetails:
|
|
45
|
+
constructor(connectionDetails: ConnectionDetails, getPsqlConfigsFn?: typeof getPsqlConfigs, spawnFn?: typeof spawn, tunnelFn?: typeof sshTunnel);
|
|
46
46
|
/**
|
|
47
47
|
* Executes a PostgreSQL query using the instance's database connection details.
|
|
48
48
|
* It uses the `getPsqlConfigs` function to get the configuration for the database and the tunnel,
|
|
@@ -87,7 +87,7 @@ export default class PsqlService {
|
|
|
87
87
|
* @param options - The options for spawning the psql process
|
|
88
88
|
* @returns Promise that resolves to the query result as a string
|
|
89
89
|
*/
|
|
90
|
-
|
|
90
|
+
runWithTunnel(tunnelConfig: TunnelConfig, options: Parameters<typeof this.spawnPsql>[0]): Promise<string>;
|
|
91
91
|
/**
|
|
92
92
|
* Spawns the psql process with the given options.
|
|
93
93
|
*
|
package/dist/utils/pg/psql.js
CHANGED
|
@@ -164,6 +164,7 @@ export default class PsqlService {
|
|
|
164
164
|
* @param options - The options for spawning the psql process
|
|
165
165
|
* @returns Promise that resolves to the query result as a string
|
|
166
166
|
*/
|
|
167
|
+
// eslint-disable-next-line perfectionist/sort-classes
|
|
167
168
|
async runWithTunnel(tunnelConfig, options) {
|
|
168
169
|
const tunnel = await Tunnel.connect(this.connectionDetails, tunnelConfig, this.tunnelFn);
|
|
169
170
|
pgDebug('after create tunnel');
|
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.
|
|
4
|
+
"version": "10.1.3",
|
|
5
5
|
"description": "Set of helpful CLI utilities",
|
|
6
6
|
"author": "Heroku",
|
|
7
7
|
"license": "ISC",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@heroku-cli/color": "^2.0.4",
|
|
46
46
|
"@heroku-cli/command": "^12.0.0",
|
|
47
|
-
"@heroku/http-call": "^5.
|
|
47
|
+
"@heroku/http-call": "^5.5.0",
|
|
48
48
|
"@oclif/core": "^4.3.0",
|
|
49
|
-
"@oclif/table": "0.4.
|
|
49
|
+
"@oclif/table": "0.4.14",
|
|
50
50
|
"debug": "^4.4.0",
|
|
51
51
|
"inquirer": "^12.6.1",
|
|
52
52
|
"tunnel-ssh": "5.2.0"
|