@amerged/ohmyhost-cli 0.1.38 → 0.1.39

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 (36) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +26 -0
  3. package/dist/bin.js +1 -1
  4. package/dist/{chunk-EWKJGJQU.js → chunk-R2BC42EW.js} +4195 -34
  5. package/dist/index.js +1 -1
  6. package/dist/licenses/pgcf-bridge-LICENSE +201 -0
  7. package/dist/licenses/pgcf-bridge-NOTICE +1 -0
  8. package/package.json +1 -1
  9. package/src/apps/product-cli/package.json +3 -2
  10. package/src/apps/product-cli/src/cli.ts +7 -5
  11. package/src/apps/product-cli/src/command.ts +18 -5
  12. package/src/apps/product-cli/src/product-api.ts +22 -15
  13. package/src/apps/product-cli/src/psql-session.ts +54 -19
  14. package/src/packages/contracts/package.json +5 -0
  15. package/src/packages/contracts/src/credit-pricing.ts +7 -1
  16. package/src/packages/contracts/src/database-access.ts +53 -12
  17. package/src/packages/contracts/src/database-compute.ts +66 -11
  18. package/src/packages/contracts/src/database-sizes.ts +114 -0
  19. package/src/packages/contracts/src/index.ts +1 -1
  20. package/src/packages/contracts/src/operation-failure.ts +2 -2
  21. package/src/packages/contracts/src/platform-origins.ts +8 -0
  22. package/src/packages/contracts/src/problem-policy.ts +16 -2
  23. package/src/packages/contracts/src/storage-gateway-origin.ts +93 -0
  24. package/src/packages/postgres-bridge/LICENSE +201 -0
  25. package/src/packages/postgres-bridge/NOTICE +1 -0
  26. package/src/packages/postgres-bridge/package.json +26 -0
  27. package/src/packages/postgres-bridge/src/auth.ts +159 -0
  28. package/src/packages/postgres-bridge/src/bridge.ts +168 -0
  29. package/src/packages/postgres-bridge/src/index.ts +2 -0
  30. package/src/packages/postgres-bridge/src/options.ts +49 -0
  31. package/src/packages/sdk-ts/package.json +1 -1
  32. package/src/packages/sdk-ts/src/generated/index.ts +1 -0
  33. package/src/packages/sdk-ts/src/generated/sdk.gen.ts +9 -8
  34. package/src/packages/sdk-ts/src/generated/types.gen.ts +91 -24
  35. package/src/packages/sdk-ts/src/index.ts +1 -0
  36. package/src/packages/sdk-ts/src/managed-mail-attachment.ts +107 -0
package/dist/index.js CHANGED
@@ -99,7 +99,7 @@ import {
99
99
  selectWorkspace,
100
100
  verifiedUserId,
101
101
  workspaceOf
102
- } from "./chunk-EWKJGJQU.js";
102
+ } from "./chunk-R2BC42EW.js";
103
103
  import {
104
104
  CredentialStoreIntegrityError,
105
105
  CredentialStoreUnavailableError,
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1 @@
1
+ PostgreSQL WebSocket bridge and authentication prelude handling adapted from cloudflare-postgres packages/cli, commit e05d9102c840e283602272ed0e16a95be3e3b8ea. Upstream license: Apache-2.0.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amerged/ohmyhost-cli",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohmyhost/product-cli",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
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 hosting region so storage.jurisdiction matches it; us when omitted)",
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 places the database, files and builds in the EU; it cannot be changed later)",
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 --profile standard|performance --idempotency-key KEY --yes [--wait] --json\n" +
402
- " standard: Free 0.25 CU/1 GB, Paid 0.5 CU/2 GB. performance: Paid 1 CU/4 GB, 2.5x database compute credits per equal active minute. All profiles use the provider-default idle suspension.",
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"] !== "standard" && options["--profile"] !== "performance") ||
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
- profile: options["--profile"],
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(input: {
177
- projectId: string;
178
- environment: "dev" | "prod";
179
- profile: "standard" | "performance";
180
- idempotencyKey: string;
181
- }): Promise<import("@ohmyhost/sdk-ts").Operation>;
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(input: {
460
- projectId: string;
461
- environment: "dev" | "prod";
462
- profile: "standard" | "performance";
463
- idempotencyKey: string;
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
- environment: input.environment,
469
- profile: input.profile,
470
- confirm: true,
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
- * Starts the customer's own psql against a temporary database credential.
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
- new Promise<number>((resolve, reject) => {
18
- const child = spawn("psql", ["-h", input.host, "-U", input.user, "-d", input.database], {
19
- stdio: "inherit",
20
- signal: input.signal,
21
- env: { ...process.env, PGPASSWORD: input.password, PGSSLMODE: "require" },
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
- child.once("error", (error: NodeJS.ErrnoException) => {
24
- reject(error.code === "ENOENT" ? new PsqlUnavailableError() : error);
25
- });
26
- child.once("close", (code, signalName) => {
27
- resolve(code ?? (signalName === null ? 1 : 130));
28
- });
29
- });
61
+ } finally {
62
+ await bridge?.close();
63
+ }
64
+ };
@@ -5,6 +5,11 @@
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "exports": {
8
+ "./database-sizes": {
9
+ "source": "./src/database-sizes.ts",
10
+ "types": "./dist/database-sizes.d.ts",
11
+ "import": "./dist/database-sizes.js"
12
+ },
8
13
  "./shared-mail": {
9
14
  "source": "./src/shared-mail.ts",
10
15
  "types": "./dist/shared-mail.d.ts",
@@ -96,7 +96,7 @@ export interface PublishedCreditRateCard {
96
96
  readonly meter: string;
97
97
  readonly unit: string;
98
98
  readonly units_per_charge: string;
99
- readonly provider_cost_micros: string;
99
+ readonly provider_cost_micros: string | null;
100
100
  readonly credit_micros: string;
101
101
  }[];
102
102
  }
@@ -159,6 +159,12 @@ export function assertPublishedCreditRateCards(
159
159
  meters.add(identity);
160
160
  for (const key of ["units_per_charge", "provider_cost_micros", "credit_micros"]) {
161
161
  const amount = rate[key];
162
+ if (
163
+ key === "provider_cost_micros" &&
164
+ amount === null &&
165
+ rate["meter"] === "pgcf.memory.active"
166
+ )
167
+ continue;
162
168
  if (
163
169
  typeof amount !== "string" ||
164
170
  !/^(0|[1-9][0-9]{0,18})$/u.test(amount) ||
@@ -93,13 +93,12 @@ export interface ProjectDatabaseAccessRequest {
93
93
  readonly ttl_seconds: number;
94
94
  readonly label: string | null;
95
95
  }
96
- export interface ProjectDatabaseAccess {
96
+ export interface ProjectDatabaseAccessFields {
97
97
  readonly access_id: string;
98
98
  readonly environment: DatabaseEnvironment;
99
99
  readonly mode: DatabaseAccessMode;
100
100
  readonly role_name: string;
101
101
  readonly host: string;
102
- readonly database: "neondb";
103
102
  readonly label: string | null;
104
103
  readonly state: "active" | "expired" | "revoked";
105
104
  readonly issued_at: string;
@@ -113,10 +112,25 @@ export interface ProjectDatabaseAccess {
113
112
  | "data_change"
114
113
  | null;
115
114
  }
116
- export interface ProjectDatabaseAccessCredential extends ProjectDatabaseAccess {
115
+ export type ProjectDatabaseAccess = ProjectDatabaseAccessFields &
116
+ (
117
+ | {
118
+ readonly database: "neondb";
119
+ readonly provider?: never;
120
+ readonly transport?: never;
121
+ readonly websocket_url?: never;
122
+ }
123
+ | {
124
+ readonly provider: "pgcf";
125
+ readonly transport: "wss";
126
+ readonly websocket_url: string;
127
+ readonly database: string;
128
+ }
129
+ );
130
+ export type ProjectDatabaseAccessCredential = ProjectDatabaseAccess & {
117
131
  readonly connection_uri: string;
118
132
  readonly psql_command: string;
119
- }
133
+ };
120
134
  export interface ProjectDatabaseAccessPage {
121
135
  readonly items: readonly ProjectDatabaseAccess[];
122
136
  }
@@ -163,17 +177,27 @@ export function parseProjectDatabaseAccessRequest(value: unknown): ProjectDataba
163
177
  export function assertProjectDatabaseAccess(
164
178
  value: unknown,
165
179
  ): asserts value is ProjectDatabaseAccess {
166
- if (!record(value) || !exact(value, ACCESS_KEYS)) throw new TypeError("Invalid database access");
180
+ if (!record(value) || !exact(value, accessKeys(value)))
181
+ throw new TypeError("Invalid database access");
167
182
  assertAccessFields(value);
168
183
  }
169
184
  export function assertProjectDatabaseAccessCredential(
170
185
  value: unknown,
171
186
  ): asserts value is ProjectDatabaseAccessCredential {
172
- if (!record(value) || !exact(value, [...ACCESS_KEYS, "connection_uri", "psql_command"]))
187
+ if (!record(value) || !exact(value, [...accessKeys(value), "connection_uri", "psql_command"]))
173
188
  throw new TypeError("Invalid database access credential");
174
189
  assertAccessFields(value);
175
190
  const uri = value["connection_uri"];
176
- if (typeof uri !== "string" || value["psql_command"] !== `psql '${uri}'`)
191
+ if (
192
+ typeof uri !== "string" ||
193
+ (value["provider"] === "pgcf"
194
+ ? typeof value["psql_command"] !== "string" ||
195
+ !new RegExp(
196
+ `^ohmyhost database psql --project [0-7][0-9A-HJKMNP-TV-Z]{25} --environment ${value["environment"]} --mode ${value["mode"]}$`,
197
+ "u",
198
+ ).test(value["psql_command"])
199
+ : value["psql_command"] !== `psql '${uri}'`)
200
+ )
177
201
  throw new TypeError("Invalid database access credential");
178
202
  let parsed: URL;
179
203
  try {
@@ -182,13 +206,20 @@ export function assertProjectDatabaseAccessCredential(
182
206
  throw new TypeError("Invalid database access credential");
183
207
  }
184
208
  if (
185
- parsed.protocol !== "postgresql:" ||
209
+ (value["provider"] === "pgcf"
210
+ ? !["postgres:", "postgresql:"].includes(parsed.protocol)
211
+ : parsed.protocol !== "postgresql:") ||
186
212
  decodeURIComponent(parsed.username) !== value["role_name"] ||
187
213
  parsed.password === "" ||
188
214
  parsed.hostname !== value["host"] ||
189
- parsed.host !== value["host"] ||
190
- decodeURIComponent(parsed.pathname.slice(1)) !== "neondb" ||
191
- parsed.search !== "?sslmode=require"
215
+ (value["provider"] === "pgcf"
216
+ ? parsed.port !== "" && parsed.port !== "5432"
217
+ : parsed.host !== value["host"]) ||
218
+ decodeURIComponent(parsed.pathname.slice(1)) !== value["database"] ||
219
+ parsed.hash !== "" ||
220
+ (value["provider"] === "pgcf"
221
+ ? !["", "?sslmode=require", "?sslmode=verify-full"].includes(parsed.search)
222
+ : parsed.search !== "?sslmode=require")
192
223
  )
193
224
  throw new TypeError("Invalid database access credential");
194
225
  }
@@ -204,6 +235,11 @@ export function assertProjectDatabaseAccessPage(
204
235
  throw new TypeError("Invalid database access page");
205
236
  for (const item of value["items"]) assertProjectDatabaseAccess(item);
206
237
  }
238
+ function accessKeys(value: Record<string, unknown>): readonly string[] {
239
+ return value["provider"] === "pgcf"
240
+ ? [...ACCESS_KEYS, "provider", "transport", "websocket_url"]
241
+ : ACCESS_KEYS;
242
+ }
207
243
  function assertAccessFields(value: Record<string, unknown>): void {
208
244
  const revoked = value["revoked_at"],
209
245
  reason = value["revocation_reason"];
@@ -216,7 +252,12 @@ function assertAccessFields(value: Record<string, unknown>): void {
216
252
  !ACCESS_ROLE_PATTERN.test(value["role_name"]) ||
217
253
  typeof value["host"] !== "string" ||
218
254
  !/^[a-z0-9]([a-z0-9.-]{0,251}[a-z0-9])?$/u.test(value["host"]) ||
219
- value["database"] !== "neondb" ||
255
+ (value["provider"] === "pgcf"
256
+ ? typeof value["database"] !== "string" ||
257
+ !/^[a-z][a-z0-9]{19}$/u.test(value["database"]) ||
258
+ value["transport"] !== "wss" ||
259
+ value["websocket_url"] !== `wss://${value["host"]}/`
260
+ : value["database"] !== "neondb") ||
220
261
  (value["label"] !== null && accessLabel(value["label"]) !== value["label"]) ||
221
262
  !["active", "expired", "revoked"].includes(String(value["state"])) ||
222
263
  !timestamp(value["issued_at"]) ||