@amerged/ohmyhost-mcp 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 (40) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +26 -0
  3. package/dist/{chunk-Z7AT2PTU.js → chunk-KQS5IMSO.js} +11 -11
  4. package/dist/index.js +1 -1
  5. package/dist/licenses/pgcf-bridge-LICENSE +201 -0
  6. package/dist/licenses/pgcf-bridge-NOTICE +1 -0
  7. package/dist/stdio-main.js +3846 -31
  8. package/package.json +1 -1
  9. package/src/apps/mcp/package.json +1 -1
  10. package/src/apps/mcp/src/local-client.ts +15 -9
  11. package/src/apps/mcp/src/local-server.ts +36 -18
  12. package/src/apps/product-cli/package.json +3 -2
  13. package/src/apps/product-cli/src/cli.ts +7 -5
  14. package/src/apps/product-cli/src/command.ts +18 -5
  15. package/src/apps/product-cli/src/product-api.ts +22 -15
  16. package/src/apps/product-cli/src/psql-session.ts +54 -19
  17. package/src/packages/agent-skills/src/generated-skill-resources.ts +10 -10
  18. package/src/packages/contracts/package.json +5 -0
  19. package/src/packages/contracts/src/credit-pricing.ts +7 -1
  20. package/src/packages/contracts/src/database-access.ts +53 -12
  21. package/src/packages/contracts/src/database-compute.ts +66 -11
  22. package/src/packages/contracts/src/database-sizes.ts +114 -0
  23. package/src/packages/contracts/src/index.ts +1 -1
  24. package/src/packages/contracts/src/operation-failure.ts +2 -2
  25. package/src/packages/contracts/src/platform-origins.ts +8 -0
  26. package/src/packages/contracts/src/problem-policy.ts +16 -2
  27. package/src/packages/contracts/src/storage-gateway-origin.ts +93 -0
  28. package/src/packages/postgres-bridge/LICENSE +201 -0
  29. package/src/packages/postgres-bridge/NOTICE +1 -0
  30. package/src/packages/postgres-bridge/package.json +26 -0
  31. package/src/packages/postgres-bridge/src/auth.ts +159 -0
  32. package/src/packages/postgres-bridge/src/bridge.ts +168 -0
  33. package/src/packages/postgres-bridge/src/index.ts +2 -0
  34. package/src/packages/postgres-bridge/src/options.ts +49 -0
  35. package/src/packages/sdk-ts/package.json +1 -1
  36. package/src/packages/sdk-ts/src/generated/index.ts +1 -0
  37. package/src/packages/sdk-ts/src/generated/sdk.gen.ts +9 -8
  38. package/src/packages/sdk-ts/src/generated/types.gen.ts +91 -24
  39. package/src/packages/sdk-ts/src/index.ts +1 -0
  40. package/src/packages/sdk-ts/src/managed-mail-attachment.ts +107 -0
@@ -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.
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@ohmyhost/postgres-bridge",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "description": "Bounded loopback PostgreSQL transport to verified PGCF WSS; no provider authority",
8
+ "exports": {
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsc --project tsconfig.build.json",
17
+ "typecheck": "tsc --project tsconfig.json --noEmit --incremental --tsBuildInfoFile typecheck.tsbuildinfo",
18
+ "test": "vitest run --root ../.. packages/postgres-bridge/test"
19
+ },
20
+ "dependencies": {
21
+ "ws": "8.22.0"
22
+ },
23
+ "devDependencies": {
24
+ "@types/ws": "8.18.2"
25
+ }
26
+ }
@@ -0,0 +1,159 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Adapted from cloudflare-postgres packages/cli at e05d9102c840e283602272ed0e16a95be3e3b8ea.
3
+ import { Transform } from "node:stream";
4
+ import type { TransformCallback } from "node:stream";
5
+
6
+ export const AUTH_BYTES = 64 * 1024;
7
+ const SSL_REQUEST = 80877103;
8
+ const GSS_REQUEST = 80877104;
9
+
10
+ export class BackendAuthentication extends Transform {
11
+ private frame = Buffer.alloc(AUTH_BYTES);
12
+ private length = 0;
13
+ private target = 5;
14
+ private offered = false;
15
+ private typed = false;
16
+ private preludes = 0;
17
+ authenticated = false;
18
+
19
+ constructor() {
20
+ super({ highWaterMark: AUTH_BYTES });
21
+ }
22
+
23
+ expectPrelude(): void {
24
+ if (this.typed || this.authenticated || this.preludes >= 2)
25
+ throw new Error("invalid_auth_prelude");
26
+ this.preludes++;
27
+ }
28
+
29
+ private authentication(frame: Buffer): Buffer {
30
+ if (frame.length < 9) throw new Error("invalid_auth_frame");
31
+ const code = frame.readUInt32BE(5);
32
+ if (code === 3) throw new Error("cleartext_auth_refused");
33
+ if (code !== 0 && code !== 10 && code !== 11 && code !== 12)
34
+ throw new Error("unsupported_authentication");
35
+ if (code === 0) {
36
+ if (frame.length !== 9) throw new Error("invalid_auth_frame");
37
+ this.authenticated = true;
38
+ return frame;
39
+ }
40
+ if (code !== 10) return frame;
41
+ if (this.offered) throw new Error("duplicate_sasl_offer");
42
+ this.offered = true;
43
+ const bytes = frame.subarray(9);
44
+ if (bytes.length < 2 || bytes.at(-1) !== 0 || bytes.at(-2) !== 0)
45
+ throw new Error("invalid_sasl_offer");
46
+ const names = bytes.subarray(0, -2).toString("ascii").split("\0");
47
+ if (
48
+ bytes.some((value) => value > 127) ||
49
+ names.length > 16 ||
50
+ names.some((name) => !/^[A-Z0-9_-]{1,128}$/.test(name)) ||
51
+ new Set(names).size !== names.length ||
52
+ !names.includes("SCRAM-SHA-256")
53
+ )
54
+ throw new Error("invalid_sasl_offer");
55
+ const retained = names.filter((name) => name !== "SCRAM-SHA-256-PLUS");
56
+ if (retained.length === names.length) return frame;
57
+ const mechanisms = Buffer.from(retained.join("\0") + "\0\0");
58
+ const rewritten = Buffer.alloc(9 + mechanisms.length);
59
+ rewritten[0] = 0x52;
60
+ rewritten.writeUInt32BE(8 + mechanisms.length, 1);
61
+ rewritten.writeUInt32BE(10, 5);
62
+ mechanisms.copy(rewritten, 9);
63
+ return rewritten;
64
+ }
65
+
66
+ override _transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback): void {
67
+ try {
68
+ let offset = 0;
69
+ while (offset < chunk.length) {
70
+ if (this.authenticated) {
71
+ this.push(chunk.subarray(offset));
72
+ break;
73
+ }
74
+ if (this.preludes && this.length === 0) {
75
+ if (chunk[offset] !== 0x4e) throw new Error("invalid_auth_prelude");
76
+ this.preludes--;
77
+ this.push(chunk.subarray(offset, ++offset));
78
+ continue;
79
+ }
80
+ this.typed = true;
81
+ const count = Math.min(this.target - this.length, chunk.length - offset);
82
+ chunk.copy(this.frame, this.length, offset, offset + count);
83
+ this.length += count;
84
+ offset += count;
85
+ if (this.length !== this.target) continue;
86
+ if (this.target === 5) {
87
+ const length = this.frame.readUInt32BE(1);
88
+ if (length < 4 || length + 1 > AUTH_BYTES) throw new Error("invalid_auth_frame");
89
+ this.target = length + 1;
90
+ if (this.length !== this.target) continue;
91
+ }
92
+ const frame = Buffer.from(this.frame.subarray(0, this.target));
93
+ this.push(frame[0] === 0x52 ? this.authentication(frame) : frame);
94
+ this.length = 0;
95
+ this.target = 5;
96
+ }
97
+ callback();
98
+ } catch (error) {
99
+ callback(error instanceof Error ? error : new Error("invalid_auth_frame"));
100
+ }
101
+ }
102
+
103
+ override _flush(callback: TransformCallback): void {
104
+ callback(this.length || this.preludes ? new Error("truncated_auth_frame") : undefined);
105
+ }
106
+ }
107
+
108
+ export class FrontendPrelude extends Transform {
109
+ private header = Buffer.alloc(8);
110
+ private length = 0;
111
+ private startup = false;
112
+ private count = 0;
113
+ private backend: BackendAuthentication;
114
+
115
+ constructor(backend: BackendAuthentication) {
116
+ super({ highWaterMark: AUTH_BYTES });
117
+ this.backend = backend;
118
+ }
119
+
120
+ override _transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback): void {
121
+ try {
122
+ let offset = 0;
123
+ while (offset < chunk.length) {
124
+ if (this.startup || this.backend.authenticated) {
125
+ if (this.length) {
126
+ this.push(Buffer.from(this.header.subarray(0, this.length)));
127
+ this.length = 0;
128
+ }
129
+ this.push(chunk.subarray(offset));
130
+ break;
131
+ }
132
+ const count = Math.min(8 - this.length, chunk.length - offset);
133
+ chunk.copy(this.header, this.length, offset, offset + count);
134
+ this.length += count;
135
+ offset += count;
136
+ if (this.length !== 8) continue;
137
+ const code = this.header.readUInt32BE(4);
138
+ if (code === SSL_REQUEST || code === GSS_REQUEST) {
139
+ if (this.header.readUInt32BE(0) !== 8 || ++this.count > 2)
140
+ throw new Error("invalid_frontend_prelude");
141
+ this.backend.expectPrelude();
142
+ } else this.startup = true;
143
+ this.push(Buffer.from(this.header));
144
+ this.length = 0;
145
+ }
146
+ callback();
147
+ } catch (error) {
148
+ callback(error instanceof Error ? error : new Error("invalid_frontend_prelude"));
149
+ }
150
+ }
151
+
152
+ override _flush(callback: TransformCallback): void {
153
+ if (this.backend.authenticated && this.length) {
154
+ this.push(Buffer.from(this.header.subarray(0, this.length)));
155
+ this.length = 0;
156
+ }
157
+ callback(this.length ? new Error("truncated_frontend_prelude") : undefined);
158
+ }
159
+ }
@@ -0,0 +1,168 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Adapted from cloudflare-postgres packages/cli at e05d9102c840e283602272ed0e16a95be3e3b8ea.
3
+ import { createServer } from "node:net";
4
+ import type { AddressInfo, Socket } from "node:net";
5
+ import type { Duplex } from "node:stream";
6
+ import WebSocket, { createWebSocketStream } from "ws";
7
+ import { upstreamUrl, validateOptions } from "./options.js";
8
+ import type { ConnectOptions } from "./options.js";
9
+ import { BackendAuthentication, FrontendPrelude } from "./auth.js";
10
+
11
+ export const STREAM_BYTES = 64 * 1024;
12
+ export const MESSAGE_BYTES = 1024 * 1024;
13
+ export const CLIENT_LIMIT = 16;
14
+ // The edge answers the upgrade only after a sleeping database is admitted, within its 60 s
15
+ // admission deadline (ADMISSION_DEADLINE_MS in @pgcf/contracts); the handshake waits for that plus margin.
16
+ export const HANDSHAKE_MS = 65_000;
17
+ export const FRAGMENT_LIMIT = 128;
18
+ export const HALF_CLOSE_MS = 10_000;
19
+
20
+ export interface Session {
21
+ local: Socket;
22
+ upstream: WebSocket;
23
+ stream: Duplex;
24
+ authentication: BackendAuthentication;
25
+ frontend: FrontendPrelude;
26
+ }
27
+ export type Connector = (url: string) => WebSocket;
28
+ export const UPSTREAM_OPTIONS: Readonly<WebSocket.ClientOptions> = Object.freeze({
29
+ rejectUnauthorized: true,
30
+ followRedirects: false,
31
+ perMessageDeflate: false,
32
+ autoPong: false,
33
+ allowSynchronousEvents: false,
34
+ maxFragments: FRAGMENT_LIMIT,
35
+ maxBufferedChunks: 256,
36
+ maxPayload: MESSAGE_BYTES,
37
+ handshakeTimeout: HANDSHAKE_MS,
38
+ });
39
+ export const connectUpstream: Connector = (url) => {
40
+ if (new URL(url).protocol !== "wss:") throw new Error("invalid_endpoint");
41
+ return new WebSocket(url, UPSTREAM_OPTIONS);
42
+ };
43
+
44
+ export interface Bridge {
45
+ readonly host: string;
46
+ readonly port: number;
47
+ readonly clients: number;
48
+ close(): Promise<void>;
49
+ }
50
+ export interface BridgeHooks {
51
+ connect?: Connector;
52
+ session?: (value: Session) => void;
53
+ disconnected?: () => void;
54
+ }
55
+
56
+ export async function startBridge(raw: ConnectOptions, hooks: BridgeHooks = {}): Promise<Bridge> {
57
+ const options = validateOptions(raw);
58
+ const sessions = new Set<Session>();
59
+ const endings = new Set<Promise<void>>();
60
+ let closing: Promise<void> | undefined;
61
+ const server = createServer({ highWaterMark: STREAM_BYTES, allowHalfOpen: true }, (local) => {
62
+ local.on("error", () => {});
63
+ if (closing || sessions.size >= CLIENT_LIMIT) {
64
+ local.destroy();
65
+ return;
66
+ }
67
+ let upstream: WebSocket;
68
+ try {
69
+ upstream = (hooks.connect ?? connectUpstream)(upstreamUrl(options));
70
+ } catch {
71
+ local.destroy();
72
+ return;
73
+ }
74
+ const stream = createWebSocketStream(upstream, {
75
+ highWaterMark: STREAM_BYTES,
76
+ });
77
+ const authentication = new BackendAuthentication();
78
+ const frontend = new FrontendPrelude(authentication);
79
+ const session = { local, upstream, stream, authentication, frontend };
80
+ sessions.add(session);
81
+ const ended = new Promise<void>((resolve) => upstream.once("close", () => resolve()));
82
+ endings.add(ended);
83
+ void ended.then(() => endings.delete(ended));
84
+ let finished = false;
85
+ let halfCloseTimer: ReturnType<typeof setTimeout> | undefined;
86
+ const finish = () => {
87
+ if (finished) return;
88
+ finished = true;
89
+ if (halfCloseTimer) clearTimeout(halfCloseTimer);
90
+ local.unpipe(frontend);
91
+ frontend.unpipe(stream);
92
+ stream.unpipe(authentication);
93
+ authentication.unpipe(local);
94
+ local.destroy();
95
+ frontend.destroy();
96
+ authentication.destroy();
97
+ stream.destroy();
98
+ upstream.terminate();
99
+ sessions.delete(session);
100
+ hooks.disconnected?.();
101
+ };
102
+ stream.on("error", finish);
103
+ authentication.on("error", finish);
104
+ frontend.on("error", finish);
105
+ upstream.on("error", finish);
106
+ local.once("error", finish);
107
+ local.once("close", finish);
108
+ local.once("end", () => {
109
+ if (finished) return;
110
+ // WebSocket has no half-close: retain its readable side while queued bytes drain.
111
+ halfCloseTimer = setTimeout(
112
+ finish,
113
+ HALF_CLOSE_MS + (upstream.readyState === WebSocket.CONNECTING ? HANDSHAKE_MS : 0),
114
+ );
115
+ });
116
+ stream.once("close", finish);
117
+ upstream.once("close", () => {
118
+ // Let the readable stream flush admitted bytes before ending local TCP.
119
+ if (local.destroyed) finish();
120
+ });
121
+ authentication.once("end", () => local.end());
122
+ upstream.prependListener("message", (_data, binary) => {
123
+ if (!binary) finish();
124
+ });
125
+ upstream.on("ping", (data) => {
126
+ if (upstream.bufferedAmount >= STREAM_BYTES) {
127
+ finish();
128
+ return;
129
+ }
130
+ upstream.pong(data, true, (error) => {
131
+ if (error) finish();
132
+ });
133
+ });
134
+ local.setNoDelay(true);
135
+ hooks.session?.(session);
136
+ local.pipe(frontend);
137
+ frontend.pipe(stream, { end: false });
138
+ stream.pipe(authentication).pipe(local);
139
+ });
140
+ server.maxConnections = CLIENT_LIMIT;
141
+ await new Promise<void>((resolve, reject) => {
142
+ const failed = () => reject(new Error("listener_failed"));
143
+ server.once("error", failed);
144
+ server.listen(options.port, [127, 0, 0, 1].join("."), () => {
145
+ server.removeListener("error", failed);
146
+ resolve();
147
+ });
148
+ });
149
+ const address = server.address() as AddressInfo;
150
+ const bridge: Bridge = {
151
+ host: address.address,
152
+ port: address.port,
153
+ get clients() {
154
+ return sessions.size;
155
+ },
156
+ close() {
157
+ closing ??= (async () => {
158
+ const listener = new Promise<void>((resolve) => server.close(() => resolve()));
159
+ for (const session of [...sessions]) session.local.destroy();
160
+ await listener;
161
+ await Promise.all([...endings]);
162
+ })();
163
+ return closing;
164
+ },
165
+ };
166
+ server.on("error", bridge.close);
167
+ return bridge;
168
+ }
@@ -0,0 +1,2 @@
1
+ export { startBridge, type Bridge } from "./bridge.js";
2
+ export { validateOptions, type ConnectOptions } from "./options.js";
@@ -0,0 +1,49 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ const isDatabaseId = (value: string) => /^[a-z][a-z0-9]{19}$/u.test(value);
3
+ const isRoleName = (value: string) => /^[a-z][a-z0-9_]{0,62}$/u.test(value);
4
+
5
+ export interface ConnectOptions {
6
+ endpoint: string;
7
+ database: string;
8
+ user: string;
9
+ port: number;
10
+ }
11
+
12
+ export function validateOptions(value: ConnectOptions): ConnectOptions {
13
+ let endpoint: URL;
14
+ try {
15
+ endpoint = new URL(value.endpoint);
16
+ } catch {
17
+ throw new Error("invalid_endpoint");
18
+ }
19
+ if (
20
+ endpoint.protocol !== "wss:" ||
21
+ !endpoint.hostname ||
22
+ endpoint.username ||
23
+ endpoint.password ||
24
+ endpoint.search ||
25
+ endpoint.hash ||
26
+ endpoint.pathname !== "/" ||
27
+ value.endpoint.length > 2048 ||
28
+ /[\s\\?#@]/.test(value.endpoint)
29
+ )
30
+ throw new Error("invalid_endpoint");
31
+ if (!isDatabaseId(value.database)) throw new Error("invalid_database");
32
+ if (!isRoleName(value.user)) throw new Error("invalid_user");
33
+ if (!Number.isInteger(value.port) || value.port < 0 || value.port > 65535)
34
+ throw new Error("invalid_port");
35
+ return {
36
+ endpoint: endpoint.href,
37
+ database: value.database,
38
+ user: value.user,
39
+ port: value.port,
40
+ };
41
+ }
42
+
43
+ export function upstreamUrl(options: ConnectOptions): string {
44
+ const url = new URL(options.endpoint);
45
+ url.pathname = "/v2";
46
+ url.searchParams.set("database", options.database);
47
+ url.searchParams.set("user", options.user);
48
+ return url.href;
49
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohmyhost/sdk-ts",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": {
@@ -360,6 +360,7 @@ export type {
360
360
  FeedbackStatus,
361
361
  FeedbackSubmission,
362
362
  FeedbackUpdate,
363
+ FixedDatabaseCompute,
363
364
  FunctionRun,
364
365
  FunctionRunPage,
365
366
  GetAccountProfileData,
@@ -4441,18 +4441,21 @@ export const getDatabaseCompute = <ThrowOnError extends boolean = true>(
4441
4441
  };
4442
4442
 
4443
4443
  /**
4444
- * Select standard or Paid performance database compute
4444
+ * Select database memory and included storage
4445
4445
  *
4446
- * Requires project-write access and explicit confirmation. Reads the organization plan at acceptance (Free 0.25 CU/1 GB/60 idle seconds or Paid 0.5 CU/2 GB/60 idle seconds). Changes the existing database in place without copying or resetting data. Shared Dev/Prod data changes both environments. A brief connection interruption is possible. Poll the returned operation every 60 seconds; do not submit a second change while it runs. Completion requires actual provider settings and settled operations. Actual CU consumption remains metered. Performance requires effective Paid access and an active rate; it selects fixed 1 CU/4 GB/300 idle seconds at 2.5 times Paid-standard database compute credits per equal active minute. Only database compute changes price. Raw CU-second measurements are preserved; mixed or uncertain transition hours waive the premium. Returning to standard restores the effective plan size.
4446
+ * Requires project-write access and explicit confirmation. Select 256, 512, 1024, 2048 or 4096 MiB RAM; Free permits only 256 MiB. Included total storage is respectively 500, 1024, 2048, 4096 or 8192 MiB, including PostgreSQL and WAL. Seven-day backups are included. Each 256 MiB costs 10 credits per active hour, prorated by time; sleeping costs no active RAM credits. Shared Dev/Prod data changes both environments. A smaller volume requires a separate data migration and is refused here. A brief connection interruption is possible. Poll the original operation until observed completion. The legacy profile input is accepted only for databases still on the transitional provider; it does not imply PGCF autoscaling.
4447
4447
  */
4448
4448
  export const changeDatabaseCompute = <ThrowOnError extends boolean = true>(
4449
4449
  parameters: {
4450
4450
  "X-Request-Id"?: string;
4451
4451
  "Idempotency-Key": string;
4452
4452
  project_id: Ulid;
4453
- environment: "dev" | "prod";
4454
- profile: "standard" | "performance";
4455
- confirm: true;
4453
+ body: unknown & {
4454
+ environment: "dev" | "prod";
4455
+ profile?: "standard" | "performance";
4456
+ memory_mib?: 256 | 512 | 1024 | 2048 | 4096;
4457
+ confirm: true;
4458
+ };
4456
4459
  },
4457
4460
  options?: Options<never, ThrowOnError>,
4458
4461
  ): RequestResult<
@@ -4469,9 +4472,7 @@ export const changeDatabaseCompute = <ThrowOnError extends boolean = true>(
4469
4472
  { in: "headers", key: "X-Request-Id" },
4470
4473
  { in: "headers", key: "Idempotency-Key" },
4471
4474
  { in: "path", key: "project_id" },
4472
- { in: "body", key: "environment" },
4473
- { in: "body", key: "profile" },
4474
- { in: "body", key: "confirm" },
4475
+ { key: "body", map: "body" },
4475
4476
  ],
4476
4477
  },
4477
4478
  ],