@amerged/ohmyhost-mcp 0.1.38 → 0.1.40
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 +1 -1
- package/THIRD_PARTY_NOTICES.md +26 -0
- package/dist/{chunk-Z7AT2PTU.js → chunk-OW4IDEWK.js} +11 -11
- package/dist/index.js +1 -1
- package/dist/licenses/pgcf-bridge-LICENSE +201 -0
- package/dist/licenses/pgcf-bridge-NOTICE +1 -0
- package/dist/stdio-main.js +3847 -32
- package/package.json +1 -1
- package/src/apps/mcp/package.json +1 -1
- package/src/apps/mcp/src/local-client.ts +15 -9
- package/src/apps/mcp/src/local-server.ts +36 -18
- package/src/apps/product-cli/package.json +3 -2
- package/src/apps/product-cli/src/cli.ts +7 -5
- package/src/apps/product-cli/src/command.ts +18 -5
- package/src/apps/product-cli/src/product-api.ts +22 -15
- package/src/apps/product-cli/src/psql-session.ts +54 -19
- package/src/packages/agent-skills/src/generated-skill-resources.ts +10 -10
- package/src/packages/contracts/package.json +5 -0
- package/src/packages/contracts/src/credit-pricing.ts +7 -1
- package/src/packages/contracts/src/database-access.ts +53 -12
- package/src/packages/contracts/src/database-compute.ts +66 -11
- package/src/packages/contracts/src/database-sizes.ts +114 -0
- package/src/packages/contracts/src/framework-admission.ts +1 -1
- package/src/packages/contracts/src/framework-source-rules.ts +1 -1
- package/src/packages/contracts/src/index.ts +1 -1
- package/src/packages/contracts/src/operation-failure.ts +2 -2
- package/src/packages/contracts/src/platform-origins.ts +8 -0
- package/src/packages/contracts/src/problem-policy.ts +16 -2
- package/src/packages/contracts/src/storage-gateway-origin.ts +93 -0
- package/src/packages/postgres-bridge/LICENSE +201 -0
- package/src/packages/postgres-bridge/NOTICE +1 -0
- package/src/packages/postgres-bridge/package.json +26 -0
- package/src/packages/postgres-bridge/src/auth.ts +159 -0
- package/src/packages/postgres-bridge/src/bridge.ts +168 -0
- package/src/packages/postgres-bridge/src/index.ts +2 -0
- package/src/packages/postgres-bridge/src/options.ts +49 -0
- package/src/packages/sdk-ts/package.json +1 -1
- package/src/packages/sdk-ts/src/generated/index.ts +1 -0
- package/src/packages/sdk-ts/src/generated/sdk.gen.ts +9 -8
- package/src/packages/sdk-ts/src/generated/types.gen.ts +91 -24
- package/src/packages/sdk-ts/src/index.ts +1 -0
- package/src/packages/sdk-ts/src/managed-mail-attachment.ts +107 -0
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "@ohmyhost/contracts/database-access";
|
|
13
13
|
import { assertOrganizationAccount } from "@ohmyhost/contracts/credit-pricing";
|
|
14
14
|
import { assertDatabaseCompute } from "@ohmyhost/contracts/database-compute";
|
|
15
|
+
import type { DatabaseComputeSelection } from "@ohmyhost/contracts/database-sizes";
|
|
15
16
|
import {
|
|
16
17
|
assertProjectContext,
|
|
17
18
|
assertProjectNotesReceipt,
|
|
@@ -279,18 +280,23 @@ export class GeneratedSdkLocalMcpClient implements LocalMcpProductClient {
|
|
|
279
280
|
return bound;
|
|
280
281
|
}
|
|
281
282
|
|
|
282
|
-
public async changeDatabaseCompute(
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
283
|
+
public async changeDatabaseCompute(
|
|
284
|
+
input: {
|
|
285
|
+
projectId: string;
|
|
286
|
+
environment: "dev" | "prod";
|
|
287
|
+
idempotencyKey: string;
|
|
288
|
+
} & DatabaseComputeSelection,
|
|
289
|
+
) {
|
|
288
290
|
return changeDatabaseCompute(
|
|
289
291
|
{
|
|
290
292
|
project_id: input.projectId,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
293
|
+
body: {
|
|
294
|
+
environment: input.environment,
|
|
295
|
+
...(input.memoryMiB === undefined
|
|
296
|
+
? { profile: input.profile }
|
|
297
|
+
: { memory_mib: input.memoryMiB }),
|
|
298
|
+
confirm: true,
|
|
299
|
+
},
|
|
294
300
|
"Idempotency-Key": input.idempotencyKey,
|
|
295
301
|
},
|
|
296
302
|
{ client: this.#client },
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isUserSecretName, USER_SECRET_NAME_PATTERN } from "@ohmyhost/contracts/secret-names";
|
|
2
|
+
import type { DatabaseComputeSelection } from "@ohmyhost/contracts/database-sizes";
|
|
2
3
|
import {
|
|
3
4
|
normalizeMcpSourceChanges,
|
|
4
5
|
formatMcpSourceFileResponse,
|
|
@@ -113,12 +114,13 @@ export interface LocalMcpProductClient {
|
|
|
113
114
|
projectId: string;
|
|
114
115
|
idempotencyKey: string;
|
|
115
116
|
}): Promise<import("@ohmyhost/sdk-ts").DevAccessState>;
|
|
116
|
-
changeDatabaseCompute(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
changeDatabaseCompute(
|
|
118
|
+
input: {
|
|
119
|
+
projectId: string;
|
|
120
|
+
environment: "dev" | "prod";
|
|
121
|
+
idempotencyKey: string;
|
|
122
|
+
} & DatabaseComputeSelection,
|
|
123
|
+
): Promise<import("@ohmyhost/sdk-ts").Operation>;
|
|
122
124
|
getDatabaseCompute(input: {
|
|
123
125
|
projectId: string;
|
|
124
126
|
environment: "dev" | "prod";
|
|
@@ -513,7 +515,7 @@ export function createLocalOhmyhostMcpServer(dependencies: LocalOhmyhostMcpDepen
|
|
|
513
515
|
server,
|
|
514
516
|
dependencies,
|
|
515
517
|
"database_compute_get",
|
|
516
|
-
"Read current managed database
|
|
518
|
+
"Read current managed database memory, total storage, region and observed state without running SQL or waking the database. Shared Dev/Prod resolves to one physical database. First provisioning is distinct from cold (sleeping) and warm (running). A null database means no confirmed placement. A configured size does not prove an in-progress resize finished. This read never resizes or changes billing.",
|
|
517
519
|
z.object({ project_id: identifier, environment: z.enum(["dev", "prod"]).default("dev") }),
|
|
518
520
|
(client, input) =>
|
|
519
521
|
client.getDatabaseCompute({ projectId: input.project_id, environment: input.environment }),
|
|
@@ -523,19 +525,35 @@ export function createLocalOhmyhostMcpServer(dependencies: LocalOhmyhostMcpDepen
|
|
|
523
525
|
server,
|
|
524
526
|
dependencies,
|
|
525
527
|
"database_compute_set",
|
|
526
|
-
"
|
|
527
|
-
z
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
528
|
+
"Choose fixed database RAM: 256, 512, 1024, 2048 or 4096 MiB. Free permits only 256 MiB; larger sizes require Paid. Included total disk is 500, 1024, 2048, 4096 or 8192 MiB, including PostgreSQL/WAL, plus seven-day backups. Prices are 10, 20, 40, 80 or 160 credits per active hour respectively, prorated. Sleep follows 300 idle seconds; sleeping has no active-RAM charge. No separate database CPU, network or connection charges apply. First read database_compute_get, explain the size, price, possible interruption and shared Dev/Prod scope, then obtain the user's choice before confirm=true. Smaller volumes need a separate data move. Poll the original operation; never duplicate a pending request. Legacy profile input applies only during provider transition. Supply exactly one of memory_mib and profile.",
|
|
529
|
+
z
|
|
530
|
+
.object({
|
|
531
|
+
project_id: identifier,
|
|
532
|
+
environment: z.enum(["dev", "prod"]),
|
|
533
|
+
profile: z.enum(["standard", "performance"]).optional(),
|
|
534
|
+
memory_mib: z
|
|
535
|
+
.union([
|
|
536
|
+
z.literal(256),
|
|
537
|
+
z.literal(512),
|
|
538
|
+
z.literal(1024),
|
|
539
|
+
z.literal(2048),
|
|
540
|
+
z.literal(4096),
|
|
541
|
+
])
|
|
542
|
+
.optional(),
|
|
543
|
+
confirm: z.literal(true),
|
|
544
|
+
idempotency_key: idempotencyKey,
|
|
545
|
+
})
|
|
546
|
+
.refine(
|
|
547
|
+
(value) => (value.memory_mib === undefined) !== (value.profile === undefined),
|
|
548
|
+
"Select exactly one database size",
|
|
549
|
+
),
|
|
534
550
|
(client, input) =>
|
|
535
551
|
client.changeDatabaseCompute({
|
|
536
552
|
projectId: input.project_id,
|
|
537
553
|
environment: input.environment,
|
|
538
|
-
|
|
554
|
+
...(input.memory_mib === undefined
|
|
555
|
+
? { profile: z.enum(["standard", "performance"]).parse(input.profile) }
|
|
556
|
+
: { memoryMiB: input.memory_mib }),
|
|
539
557
|
idempotencyKey: input.idempotency_key,
|
|
540
558
|
}),
|
|
541
559
|
mutationAnnotations(),
|
|
@@ -972,7 +990,7 @@ export function createLocalOhmyhostMcpServer(dependencies: LocalOhmyhostMcpDepen
|
|
|
972
990
|
server,
|
|
973
991
|
dependencies,
|
|
974
992
|
"database_access_create",
|
|
975
|
-
"Issue a time-bound PostgreSQL credential for this project's own Dev or Prod database.
|
|
993
|
+
"Issue a time-bound PostgreSQL credential for this project's own Dev or Prod database. The credential URI and password are RETURNED EXACTLY ONCE: never write them into files, notes, source, commit messages or later messages; keep credentials out of command arguments, logs and feedback. PGCF declares transport=wss and websocket_url; its URI is not a public TCP endpoint. Use the secret-free psql_command to run the local ohmyhost database psql helper, which creates its own access, bridges verified WSS to loopback, and closes/revokes on exit. Mode read (default) is read-only; mode write joins the restricted runtime role and requires confirmed: true. Neither mode can change schema, application row-level security still applies, and schema changes stay in GitHub migrations. The lifetime is 5 minutes to 24 hours (3600 seconds by default) and at most three credentials are active per environment. Database compute wakes and is metered normally. Call database_access_revoke as soon as the work is finished.",
|
|
976
994
|
z
|
|
977
995
|
.object({
|
|
978
996
|
project_id: identifier,
|
|
@@ -1243,7 +1261,7 @@ export function createLocalOhmyhostMcpServer(dependencies: LocalOhmyhostMcpDepen
|
|
|
1243
1261
|
server,
|
|
1244
1262
|
dependencies,
|
|
1245
1263
|
"project_create",
|
|
1246
|
-
"Create an ohmyho.st project. Ask whether Dev should be protected (default) or public before creation; public means anyone with the Dev URL can open it, including when Dev and Prod share data. Recommend isolated Dev/Prod data, but respect the customer's choice and added database consumption. data_mode is optional and defaults to shared, using one database/file namespace; isolated separates database/Auth records and files. Later changes use project_data_plan and project_data_change; ohmyho.st never copies data and ordinary usage prices apply. region defaults to us;
|
|
1264
|
+
"Create an ohmyho.st project. Ask whether Dev should be protected (default) or public before creation; public means anyone with the Dev URL can open it, including when Dev and Prod share data. Recommend isolated Dev/Prod data, but respect the customer's choice and added database consumption. data_mode is optional and defaults to shared, using one database/file namespace; isolated separates database/Auth records and files. Later changes use project_data_plan and project_data_change; ohmyho.st never copies data and ordinary usage prices apply. region defaults to us; new projects provision their PGCF database, new files and builds in the selected us or eu region at the same prices. Read database_compute_get for the observed database region. Existing projects migrated with their owner's authorization now use US databases; their existing R2 object locations remain unchanged. The customer API cannot change region later. ohmyhost.yaml storage.jurisdiction must match the recorded R2 bucket or reservation jurisdiction, using project region only for new storage. Read the Storage jurisdiction line in project_context_get; if unavailable, report it rather than guessing.",
|
|
1247
1265
|
z.object({
|
|
1248
1266
|
organization_id: identifier,
|
|
1249
1267
|
name: z.string().min(1).max(128),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohmyhost/product-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"private": true,
|
|
5
5
|
"ohmyhost": {
|
|
6
6
|
"deployment": "production",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"@ohmyhost/sdk-ts": "workspace:*",
|
|
42
42
|
"@ohmyhost/workos-auth-contracts": "workspace:*",
|
|
43
43
|
"ignore": "7.0.12",
|
|
44
|
-
"isomorphic-git": "1.43.0"
|
|
44
|
+
"isomorphic-git": "1.43.0",
|
|
45
|
+
"@ohmyhost/postgres-bridge": "workspace:*"
|
|
45
46
|
},
|
|
46
47
|
"license": "Apache-2.0"
|
|
47
48
|
}
|
|
@@ -281,6 +281,7 @@ export interface ProductCliDependencies {
|
|
|
281
281
|
readonly operationEventSink?: { write(value: string): void };
|
|
282
282
|
readonly readSecretValue: (signal: AbortSignal) => Promise<string>;
|
|
283
283
|
readonly spawnPsql?: (input: {
|
|
284
|
+
readonly websocketUrl?: string;
|
|
284
285
|
readonly host: string;
|
|
285
286
|
readonly user: string;
|
|
286
287
|
readonly password: string;
|
|
@@ -321,7 +322,7 @@ type CustomerCommandLabel = Exclude<CommandLabel, "unknown" | "help" | "version"
|
|
|
321
322
|
|
|
322
323
|
const CLI_VERSION = cliPackage.version;
|
|
323
324
|
const HELP_USAGE = Object.freeze({
|
|
324
|
-
init: "ohmyhost init [--directory PATH] [--root PATH] [--project SLUG] [--region us|eu] [--dry-run] --json (pass the project's
|
|
325
|
+
init: "ohmyhost init [--directory PATH] [--root PATH] [--project SLUG] [--region us|eu] [--dry-run] --json (preserve existing storage jurisdiction; for new storage pass the project's region, us when omitted)",
|
|
325
326
|
login:
|
|
326
327
|
"ohmyhost login [--organization ULID] [--user USER_ID] [--profile-name NAME] --json (adds one saved login; nothing is saved unless the browser signed in as that user and organization)",
|
|
327
328
|
logout:
|
|
@@ -372,7 +373,7 @@ const HELP_USAGE = Object.freeze({
|
|
|
372
373
|
"feedback submit":
|
|
373
374
|
"ohmyhost feedback submit --organization ULID --kind bug|issue|feature_request --title TITLE --description REDACTED_REPORT [--project ULID] [--environment ULID] [--operation ULID] [--error-code CODE] [--client-version VERSION] --idempotency-key KEY --json",
|
|
374
375
|
"project create":
|
|
375
|
-
"ohmyhost project create --organization ULID --name NAME [--data-mode shared|isolated] [--dev-access-mode protected|public] [--region us|eu] --idempotency-key KEY --json (data mode is optional and defaults to shared; later assignments use project data plan/change without copying data; the region is chosen once: us is the default, eu
|
|
376
|
+
"ohmyhost project create --organization ULID --name NAME [--data-mode shared|isolated] [--dev-access-mode protected|public] [--region us|eu] --idempotency-key KEY --json (data mode is optional and defaults to shared; later assignments use project data plan/change without copying data; the region is chosen once: us is the default, eu selects EU database, new files and builds; existing R2 locations survive authorized region moves; the customer API cannot change region later)",
|
|
376
377
|
"project data plan":
|
|
377
378
|
"ohmyhost project data plan --project ULID --change isolate_prod_keeps_data|isolate_dev_keeps_data|share_prod_keeps_data|reset_dev --json (shared is the optional creation default; review which data is kept or deleted; no data is copied)",
|
|
378
379
|
"project data change":
|
|
@@ -398,8 +399,8 @@ const HELP_USAGE = Object.freeze({
|
|
|
398
399
|
"project handle set":
|
|
399
400
|
"ohmyhost project handle set --project ULID --handle HANDLE --if-match ETAG --idempotency-key KEY --json (moves the project to a free address; the old one stops working and anyone may claim it)",
|
|
400
401
|
"database compute set":
|
|
401
|
-
"ohmyhost database compute set --project ULID --environment dev|prod --
|
|
402
|
-
"
|
|
402
|
+
"ohmyhost database compute set --project ULID --environment dev|prod --memory-mib 256|512|1024|2048|4096 --idempotency-key KEY --yes [--wait] --json\n" +
|
|
403
|
+
" 10/20/40/80/160 credits per active hour, prorated; includes 500 MiB/1/2/4/8 GiB total disk and seven-day backups. Free supports 256 MiB; larger sizes require Paid. Sleep after 300 idle seconds. No separate database CPU, network or connection charge. Smaller disk requires a separate data migration. Transitional --profile standard|performance is accepted only for legacy provider use; never combine it with --memory-mib.",
|
|
403
404
|
"database compute get":
|
|
404
405
|
"ohmyhost database compute get --project ULID [--environment dev|prod] --json",
|
|
405
406
|
"database write":
|
|
@@ -1872,7 +1873,8 @@ export class ProductCli {
|
|
|
1872
1873
|
exitCode = await spawnPsql({
|
|
1873
1874
|
host: credential.host,
|
|
1874
1875
|
user: credential.role_name,
|
|
1875
|
-
password: new URL(credential.connection_uri).password,
|
|
1876
|
+
password: decodeURIComponent(new URL(credential.connection_uri).password),
|
|
1877
|
+
...(credential.provider === "pgcf" ? { websocketUrl: credential.websocket_url } : {}),
|
|
1876
1878
|
database: credential.database,
|
|
1877
1879
|
mode: credential.mode,
|
|
1878
1880
|
signal,
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { isUserSecretName } from "@ohmyhost/contracts/secret-names";
|
|
2
|
+
import {
|
|
3
|
+
databaseSizeForMemory,
|
|
4
|
+
type DatabaseComputeSelection,
|
|
5
|
+
} from "@ohmyhost/contracts/database-sizes";
|
|
2
6
|
import {
|
|
3
7
|
isProjectDataChangeKind,
|
|
4
8
|
type ProjectDataChangeKind,
|
|
@@ -92,15 +96,14 @@ export type ProductCliCommand =
|
|
|
92
96
|
readonly organizationId: string;
|
|
93
97
|
readonly credentialStore: "native";
|
|
94
98
|
}
|
|
95
|
-
| {
|
|
99
|
+
| ({
|
|
96
100
|
readonly kind: "database-compute-set";
|
|
97
101
|
readonly projectId: string;
|
|
98
102
|
readonly environment: "dev" | "prod";
|
|
99
|
-
readonly profile: "standard" | "performance";
|
|
100
103
|
readonly idempotencyKey: string;
|
|
101
104
|
readonly wait: boolean;
|
|
102
105
|
readonly credentialStore: "native";
|
|
103
|
-
}
|
|
106
|
+
} & DatabaseComputeSelection)
|
|
104
107
|
| {
|
|
105
108
|
readonly kind: "database-compute-get";
|
|
106
109
|
readonly projectId: string;
|
|
@@ -1761,20 +1764,30 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
|
|
|
1761
1764
|
"--project",
|
|
1762
1765
|
"--environment",
|
|
1763
1766
|
"--profile",
|
|
1767
|
+
"--memory-mib",
|
|
1764
1768
|
"--idempotency-key",
|
|
1765
1769
|
]);
|
|
1766
1770
|
if (
|
|
1767
1771
|
!options["--project"] ||
|
|
1768
1772
|
!options["--idempotency-key"] ||
|
|
1769
|
-
(options["--profile"]
|
|
1773
|
+
(options["--profile"] === undefined) === (options["--memory-mib"] === undefined) ||
|
|
1774
|
+
(options["--profile"] !== undefined &&
|
|
1775
|
+
options["--profile"] !== "standard" &&
|
|
1776
|
+
options["--profile"] !== "performance") ||
|
|
1770
1777
|
(options["--environment"] !== "dev" && options["--environment"] !== "prod")
|
|
1771
1778
|
)
|
|
1772
1779
|
throw new InvalidCommandError();
|
|
1780
|
+
let selection: DatabaseComputeSelection;
|
|
1781
|
+
if (options["--memory-mib"] !== undefined) {
|
|
1782
|
+
if (!/^(256|512|1024|2048|4096)$/u.test(options["--memory-mib"]))
|
|
1783
|
+
throw new InvalidCommandError();
|
|
1784
|
+
selection = { memoryMiB: databaseSizeForMemory(Number(options["--memory-mib"])).memoryMiB };
|
|
1785
|
+
} else selection = { profile: options["--profile"] as "standard" | "performance" };
|
|
1773
1786
|
return {
|
|
1774
1787
|
kind: "database-compute-set",
|
|
1775
1788
|
projectId: options["--project"],
|
|
1776
1789
|
environment: options["--environment"],
|
|
1777
|
-
|
|
1790
|
+
...selection,
|
|
1778
1791
|
idempotencyKey: options["--idempotency-key"],
|
|
1779
1792
|
wait,
|
|
1780
1793
|
credentialStore,
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
type ProjectDatabaseWriteReceipt,
|
|
21
21
|
} from "@ohmyhost/contracts/database-access";
|
|
22
22
|
import { assertDatabaseCompute, type DatabaseCompute } from "@ohmyhost/contracts/database-compute";
|
|
23
|
+
import type { DatabaseComputeSelection } from "@ohmyhost/contracts/database-sizes";
|
|
23
24
|
import {
|
|
24
25
|
assertProjectContext,
|
|
25
26
|
assertProjectNotesReceipt,
|
|
@@ -173,12 +174,13 @@ export interface ProductApi {
|
|
|
173
174
|
confirmationToken: string;
|
|
174
175
|
idempotencyKey: string;
|
|
175
176
|
}): Promise<Operation>;
|
|
176
|
-
changeDatabaseCompute(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
177
|
+
changeDatabaseCompute(
|
|
178
|
+
input: {
|
|
179
|
+
projectId: string;
|
|
180
|
+
environment: "dev" | "prod";
|
|
181
|
+
idempotencyKey: string;
|
|
182
|
+
} & DatabaseComputeSelection,
|
|
183
|
+
): Promise<import("@ohmyhost/sdk-ts").Operation>;
|
|
182
184
|
getDatabaseCompute(input: {
|
|
183
185
|
projectId: string;
|
|
184
186
|
environment: "dev" | "prod";
|
|
@@ -456,18 +458,23 @@ export class GeneratedSdkProductApi implements ProductApi {
|
|
|
456
458
|
this.managedSource = new GeneratedSdkManagedSourceApi(() => this.#client);
|
|
457
459
|
}
|
|
458
460
|
|
|
459
|
-
public async changeDatabaseCompute(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
461
|
+
public async changeDatabaseCompute(
|
|
462
|
+
input: {
|
|
463
|
+
projectId: string;
|
|
464
|
+
environment: "dev" | "prod";
|
|
465
|
+
idempotencyKey: string;
|
|
466
|
+
} & DatabaseComputeSelection,
|
|
467
|
+
) {
|
|
465
468
|
return changeDatabaseCompute(
|
|
466
469
|
{
|
|
467
470
|
project_id: input.projectId,
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
+
body: {
|
|
472
|
+
environment: input.environment,
|
|
473
|
+
...(input.memoryMiB === undefined
|
|
474
|
+
? { profile: input.profile }
|
|
475
|
+
: { memory_mib: input.memoryMiB }),
|
|
476
|
+
confirm: true,
|
|
477
|
+
},
|
|
471
478
|
"Idempotency-Key": input.idempotencyKey,
|
|
472
479
|
},
|
|
473
480
|
{ client: this.#client },
|
|
@@ -1,29 +1,64 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { startBridge } from "@ohmyhost/postgres-bridge";
|
|
2
3
|
|
|
3
4
|
import { PsqlUnavailableError } from "./cli.js";
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
* The password reaches psql only through its private environment, never through
|
|
8
|
-
* argv, the terminal title or any file; no authentication credential is involved.
|
|
9
|
-
*/
|
|
10
|
-
export const runLocalPsql = (input: {
|
|
6
|
+
/** One private loopback bridge lasts exactly as long as the customer's native psql session. */
|
|
7
|
+
export const runLocalPsql = async (input: {
|
|
11
8
|
readonly host: string;
|
|
12
9
|
readonly user: string;
|
|
13
10
|
readonly password: string;
|
|
14
11
|
readonly database: string;
|
|
12
|
+
readonly websocketUrl?: string;
|
|
15
13
|
readonly signal: AbortSignal;
|
|
16
|
-
}): Promise<number> =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
}): Promise<number> => {
|
|
15
|
+
input.signal.throwIfAborted();
|
|
16
|
+
if (input.websocketUrl !== undefined && input.websocketUrl !== `wss://${input.host}/`)
|
|
17
|
+
throw new Error("Invalid PGCF transport");
|
|
18
|
+
const bridge =
|
|
19
|
+
input.websocketUrl === undefined
|
|
20
|
+
? null
|
|
21
|
+
: await startBridge({
|
|
22
|
+
endpoint: input.websocketUrl,
|
|
23
|
+
database: input.database,
|
|
24
|
+
user: input.user,
|
|
25
|
+
port: 0,
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
input.signal.throwIfAborted();
|
|
29
|
+
// A caller's libpq service/hostaddr settings must not redirect this temporary credential.
|
|
30
|
+
const environment = Object.fromEntries(
|
|
31
|
+
Object.entries(process.env).filter(([key]) => !/^PG[A-Z_]+$/iu.test(key)),
|
|
32
|
+
);
|
|
33
|
+
return await new Promise<number>((resolve, reject) => {
|
|
34
|
+
const child = spawn(
|
|
35
|
+
"psql",
|
|
36
|
+
["-h", bridge?.host ?? input.host, "-U", input.user, "-d", input.database],
|
|
37
|
+
{
|
|
38
|
+
stdio: "inherit",
|
|
39
|
+
signal: input.signal,
|
|
40
|
+
env: {
|
|
41
|
+
...environment,
|
|
42
|
+
PGPASSWORD: input.password,
|
|
43
|
+
PGSSLMODE: bridge ? "disable" : "require",
|
|
44
|
+
...(bridge
|
|
45
|
+
? {
|
|
46
|
+
PGPORT: String(bridge.port),
|
|
47
|
+
PGCHANNELBINDING: "disable",
|
|
48
|
+
PGGSSENCMODE: "disable",
|
|
49
|
+
}
|
|
50
|
+
: {}),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
child.once("error", (error: NodeJS.ErrnoException) => {
|
|
55
|
+
reject(error.code === "ENOENT" ? new PsqlUnavailableError() : error);
|
|
56
|
+
});
|
|
57
|
+
child.once("close", (code, signalName) => {
|
|
58
|
+
resolve(code ?? (signalName === null ? 1 : 130));
|
|
59
|
+
});
|
|
22
60
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
resolve(code ?? (signalName === null ? 1 : 130));
|
|
28
|
-
});
|
|
29
|
-
});
|
|
61
|
+
} finally {
|
|
62
|
+
await bridge?.close();
|
|
63
|
+
}
|
|
64
|
+
};
|