@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.
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES.md +26 -0
- package/dist/bin.js +1 -1
- package/dist/{chunk-EWKJGJQU.js → chunk-R2BC42EW.js} +4195 -34
- package/dist/index.js +1 -1
- package/dist/licenses/pgcf-bridge-LICENSE +201 -0
- package/dist/licenses/pgcf-bridge-NOTICE +1 -0
- package/package.json +1 -1
- 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/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/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
|
@@ -1,19 +1,39 @@
|
|
|
1
|
+
import { databaseSizeForClass } from "./database-sizes.js";
|
|
2
|
+
|
|
3
|
+
export type PgcfComputeState = "provisioning" | "cold" | "warm" | "suspended" | "error";
|
|
4
|
+
export interface PgcfDatabaseCompute {
|
|
5
|
+
readonly provider: "pgcf";
|
|
6
|
+
readonly size_class_id: string;
|
|
7
|
+
readonly memory_mib: number;
|
|
8
|
+
readonly cpu_millicores: number;
|
|
9
|
+
readonly storage_mib: number;
|
|
10
|
+
readonly max_connections: number;
|
|
11
|
+
readonly suspend_timeout_seconds: number;
|
|
12
|
+
readonly state: PgcfComputeState;
|
|
13
|
+
readonly pending_state: PgcfComputeState | null;
|
|
14
|
+
readonly disabled: boolean;
|
|
15
|
+
readonly region: "us" | "eu";
|
|
16
|
+
}
|
|
17
|
+
|
|
1
18
|
export interface DatabaseCompute {
|
|
2
19
|
readonly project_id: string;
|
|
3
20
|
readonly environment: "dev" | "prod";
|
|
4
21
|
readonly data_mode: "shared" | "isolated";
|
|
5
22
|
readonly observed_at: string;
|
|
6
|
-
readonly database:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
readonly database:
|
|
24
|
+
| null
|
|
25
|
+
| PgcfDatabaseCompute
|
|
26
|
+
| {
|
|
27
|
+
readonly min_cu: number;
|
|
28
|
+
readonly max_cu: number;
|
|
29
|
+
readonly min_memory_gb: number;
|
|
30
|
+
readonly max_memory_gb: number;
|
|
31
|
+
readonly suspend_timeout_seconds: number;
|
|
32
|
+
readonly state: "init" | "active" | "idle";
|
|
33
|
+
readonly pending_state: "init" | "active" | "idle" | null;
|
|
34
|
+
readonly disabled: boolean;
|
|
35
|
+
readonly region: string;
|
|
36
|
+
};
|
|
17
37
|
}
|
|
18
38
|
export function assertDatabaseCompute(value: unknown): asserts value is DatabaseCompute {
|
|
19
39
|
if (
|
|
@@ -30,6 +50,10 @@ export function assertDatabaseCompute(value: unknown): asserts value is Database
|
|
|
30
50
|
throw new TypeError("Invalid database compute report");
|
|
31
51
|
const db = value["database"];
|
|
32
52
|
if (db === null) return;
|
|
53
|
+
if (record(db) && db["provider"] === "pgcf") {
|
|
54
|
+
assertPgcfCompute(db);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
33
57
|
if (
|
|
34
58
|
!record(db) ||
|
|
35
59
|
!exact(db, [
|
|
@@ -64,6 +88,37 @@ export function assertDatabaseCompute(value: unknown): asserts value is Database
|
|
|
64
88
|
)
|
|
65
89
|
throw new TypeError("Invalid database compute configuration");
|
|
66
90
|
}
|
|
91
|
+
function assertPgcfCompute(db: Record<string, unknown>): void {
|
|
92
|
+
const size = databaseSizeForClass(db["size_class_id"]);
|
|
93
|
+
const states = ["provisioning", "cold", "warm", "suspended", "error"];
|
|
94
|
+
if (
|
|
95
|
+
!exact(db, [
|
|
96
|
+
"cpu_millicores",
|
|
97
|
+
"disabled",
|
|
98
|
+
"max_connections",
|
|
99
|
+
"memory_mib",
|
|
100
|
+
"pending_state",
|
|
101
|
+
"provider",
|
|
102
|
+
"region",
|
|
103
|
+
"size_class_id",
|
|
104
|
+
"state",
|
|
105
|
+
"storage_mib",
|
|
106
|
+
"suspend_timeout_seconds",
|
|
107
|
+
]) ||
|
|
108
|
+
db["memory_mib"] !== size.memoryMiB ||
|
|
109
|
+
db["cpu_millicores"] !== size.cpuMillicores ||
|
|
110
|
+
db["storage_mib"] !== size.storageMiB ||
|
|
111
|
+
db["max_connections"] !== size.maxConnections ||
|
|
112
|
+
!Number.isSafeInteger(db["suspend_timeout_seconds"]) ||
|
|
113
|
+
Number(db["suspend_timeout_seconds"]) < 60 ||
|
|
114
|
+
Number(db["suspend_timeout_seconds"]) > 900 ||
|
|
115
|
+
!states.includes(String(db["state"])) ||
|
|
116
|
+
(db["pending_state"] !== null && !states.includes(String(db["pending_state"]))) ||
|
|
117
|
+
typeof db["disabled"] !== "boolean" ||
|
|
118
|
+
!["us", "eu"].includes(String(db["region"]))
|
|
119
|
+
)
|
|
120
|
+
throw new TypeError("Invalid fixed database compute configuration");
|
|
121
|
+
}
|
|
67
122
|
function record(v: unknown): v is Record<string, unknown> {
|
|
68
123
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
69
124
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export type DatabaseMemoryMiB = 256 | 512 | 1024 | 2048 | 4096;
|
|
2
|
+
export type DatabaseComputeSelection =
|
|
3
|
+
| { readonly memoryMiB: DatabaseMemoryMiB; readonly profile?: never }
|
|
4
|
+
| { readonly profile: "standard" | "performance"; readonly memoryMiB?: never };
|
|
5
|
+
|
|
6
|
+
export function parseDatabaseComputeChangeRequest(value: unknown): {
|
|
7
|
+
readonly environment: "dev" | "prod";
|
|
8
|
+
readonly selection: DatabaseComputeSelection;
|
|
9
|
+
} {
|
|
10
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
11
|
+
throw new TypeError("Invalid database compute change");
|
|
12
|
+
const input = value as Record<string, unknown>;
|
|
13
|
+
const keys = Object.keys(input).sort().join(",");
|
|
14
|
+
if (
|
|
15
|
+
(keys !== "confirm,environment,memory_mib" && keys !== "confirm,environment,profile") ||
|
|
16
|
+
input["confirm"] !== true ||
|
|
17
|
+
(input["environment"] !== "dev" && input["environment"] !== "prod")
|
|
18
|
+
)
|
|
19
|
+
throw new TypeError("Invalid database compute change");
|
|
20
|
+
if (keys === "confirm,environment,memory_mib")
|
|
21
|
+
return {
|
|
22
|
+
environment: input["environment"],
|
|
23
|
+
selection: { memoryMiB: databaseSizeForMemory(input["memory_mib"]).memoryMiB },
|
|
24
|
+
};
|
|
25
|
+
if (input["profile"] !== "standard" && input["profile"] !== "performance")
|
|
26
|
+
throw new TypeError("Invalid transitional database profile");
|
|
27
|
+
return { environment: input["environment"], selection: { profile: input["profile"] } };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DatabaseSize {
|
|
31
|
+
readonly memoryMiB: DatabaseMemoryMiB;
|
|
32
|
+
readonly storageMiB: number;
|
|
33
|
+
readonly cpuMillicores: number;
|
|
34
|
+
readonly maxConnections: number;
|
|
35
|
+
readonly sizeClassId: string;
|
|
36
|
+
readonly creditsPerAwakeHour: number;
|
|
37
|
+
readonly paidRequired: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Operator-approved product sizes; storage is total nominal volume, including WAL. */
|
|
41
|
+
export const DATABASE_SIZES: readonly DatabaseSize[] = Object.freeze([
|
|
42
|
+
Object.freeze({
|
|
43
|
+
memoryMiB: 256,
|
|
44
|
+
storageMiB: 500,
|
|
45
|
+
cpuMillicores: 250,
|
|
46
|
+
maxConnections: 20,
|
|
47
|
+
sizeClassId: "r256-s500m",
|
|
48
|
+
creditsPerAwakeHour: 10,
|
|
49
|
+
paidRequired: false,
|
|
50
|
+
} as const),
|
|
51
|
+
Object.freeze({
|
|
52
|
+
memoryMiB: 512,
|
|
53
|
+
storageMiB: 1024,
|
|
54
|
+
cpuMillicores: 250,
|
|
55
|
+
maxConnections: 40,
|
|
56
|
+
sizeClassId: "r512-s1g",
|
|
57
|
+
creditsPerAwakeHour: 20,
|
|
58
|
+
paidRequired: true,
|
|
59
|
+
} as const),
|
|
60
|
+
Object.freeze({
|
|
61
|
+
memoryMiB: 1024,
|
|
62
|
+
storageMiB: 2048,
|
|
63
|
+
cpuMillicores: 500,
|
|
64
|
+
maxConnections: 80,
|
|
65
|
+
sizeClassId: "r1024-s2g",
|
|
66
|
+
creditsPerAwakeHour: 40,
|
|
67
|
+
paidRequired: true,
|
|
68
|
+
} as const),
|
|
69
|
+
Object.freeze({
|
|
70
|
+
memoryMiB: 2048,
|
|
71
|
+
storageMiB: 4096,
|
|
72
|
+
cpuMillicores: 1000,
|
|
73
|
+
maxConnections: 160,
|
|
74
|
+
sizeClassId: "r2048-s4g",
|
|
75
|
+
creditsPerAwakeHour: 80,
|
|
76
|
+
paidRequired: true,
|
|
77
|
+
} as const),
|
|
78
|
+
Object.freeze({
|
|
79
|
+
memoryMiB: 4096,
|
|
80
|
+
storageMiB: 8192,
|
|
81
|
+
cpuMillicores: 2000,
|
|
82
|
+
maxConnections: 200,
|
|
83
|
+
sizeClassId: "r4096-s8g",
|
|
84
|
+
creditsPerAwakeHour: 160,
|
|
85
|
+
paidRequired: true,
|
|
86
|
+
} as const),
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
export function databaseSizeForMemory(value: unknown): DatabaseSize {
|
|
90
|
+
const size = DATABASE_SIZES.find((candidate) => candidate.memoryMiB === value);
|
|
91
|
+
if (size === undefined) throw new TypeError("Unsupported database memory size");
|
|
92
|
+
return size;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function databaseSizeForClass(value: unknown): DatabaseSize {
|
|
96
|
+
const size = DATABASE_SIZES.find((candidate) => candidate.sizeClassId === value);
|
|
97
|
+
if (size === undefined) throw new TypeError("Unsupported database size class");
|
|
98
|
+
return size;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A downgrade never silently reduces a database's physical allocation. */
|
|
102
|
+
export function assertDatabaseSizeChange(input: {
|
|
103
|
+
readonly memoryMiB: unknown;
|
|
104
|
+
readonly paid: boolean;
|
|
105
|
+
readonly currentStorageMiB: number;
|
|
106
|
+
}): DatabaseSize {
|
|
107
|
+
const size = databaseSizeForMemory(input.memoryMiB);
|
|
108
|
+
if (size.paidRequired && !input.paid) throw new TypeError("Database size requires Paid");
|
|
109
|
+
if (!Number.isSafeInteger(input.currentStorageMiB) || input.currentStorageMiB < 0)
|
|
110
|
+
throw new TypeError("Invalid current database allocation");
|
|
111
|
+
if (size.storageMiB < input.currentStorageMiB)
|
|
112
|
+
throw new TypeError("A smaller database volume requires a separate data migration");
|
|
113
|
+
return size;
|
|
114
|
+
}
|
|
@@ -209,7 +209,7 @@ function normalizeEgressOrigins(value: readonly string[] | undefined): readonly
|
|
|
209
209
|
function forbiddenEgressHostname(hostname: string): boolean {
|
|
210
210
|
const normalized = hostname.toLowerCase();
|
|
211
211
|
return (
|
|
212
|
-
|
|
212
|
+
/(?:^|\.)ohmyho-(?:mail|storage)-gateway-[a-z0-9][a-z0-9-]*\.[a-z0-9][a-z0-9-]*\.workers\.dev\.?$/u.test(
|
|
213
213
|
normalized,
|
|
214
214
|
) ||
|
|
215
215
|
normalized === "localhost" ||
|
|
@@ -111,8 +111,8 @@ const failures = {
|
|
|
111
111
|
"The built Worker could not be loaded: top-level code throws or calls fetch, timers or random values outside a handler, an import cannot be resolved, a Worker module such as src/ohmyhost/companion.ts has no default export, or the bundle is too large. Fix that, save or push the corrected version and plan its commit; replaying this operation cannot pass. If none of this applies, report the operation ID through feedback.",
|
|
112
112
|
],
|
|
113
113
|
storage_jurisdiction_conflict: [
|
|
114
|
-
"storage.jurisdiction must
|
|
115
|
-
"
|
|
114
|
+
"storage.jurisdiction must match the project's recorded storage jurisdiction.",
|
|
115
|
+
"Read 'Storage jurisdiction' in 'ohmyhost project context --project ULID --json' and set storage.jurisdiction in ohmyhost.yaml to that recorded value (us or eu). Existing R2 buckets and reservations keep their jurisdiction after a project-region migration; only new storage without a recorded bucket uses the project region. If context reports unavailable, report the request ID through feedback rather than guessing. Save or push the corrected version and plan its commit; for promotion, deploy it to Dev and promote again. Do not delete or recreate the project to move files.",
|
|
116
116
|
],
|
|
117
117
|
provider_state_absent: [
|
|
118
118
|
"Reconciliation confirmed that the required deployment resources are absent.",
|
|
@@ -3,3 +3,11 @@ export type SaasCnameTarget = "customers.omh.st" | "customers.ohmyho.st";
|
|
|
3
3
|
export function isSaasCnameTarget(value: unknown): value is SaasCnameTarget {
|
|
4
4
|
return value === "customers.omh.st" || value === "customers.ohmyho.st";
|
|
5
5
|
}
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
classifyPlatformGatewayHostname,
|
|
9
|
+
createPinnedStorageGatewayOrigin,
|
|
10
|
+
parsePinnedStorageGatewayOrigin,
|
|
11
|
+
type PinnedStorageGatewayOrigin,
|
|
12
|
+
type StorageGatewayOriginScope,
|
|
13
|
+
} from "./storage-gateway-origin.js";
|
|
@@ -120,6 +120,20 @@ export const PROBLEM_POLICY = {
|
|
|
120
120
|
restAction:
|
|
121
121
|
"Performance compute needs active Paid and usable credits or grace; repeating unchanged does not help. Read 'ohmyhost credits account --organization ULID --json'. On Free, the Owner may start Paid with 'ohmyhost billing checkout --offer paid'; without usable credits, they may add credits. Until then, keep standard compute.",
|
|
122
122
|
},
|
|
123
|
+
compute_paid_required: {
|
|
124
|
+
status: 403,
|
|
125
|
+
retryable: false,
|
|
126
|
+
action:
|
|
127
|
+
"Database sizes above 256 MiB require active Paid access. Read the account status; keep the existing database until the owner chooses an eligible size or Paid access.",
|
|
128
|
+
title: "Database size requires Paid access",
|
|
129
|
+
},
|
|
130
|
+
compute_storage_shrink_requires_migration: {
|
|
131
|
+
status: 409,
|
|
132
|
+
retryable: false,
|
|
133
|
+
action:
|
|
134
|
+
"This size includes less storage than the current volume. Keep the current database and plan an explicit data migration to a fresh smaller volume; do not retry the resize or delete data automatically.",
|
|
135
|
+
title: "Smaller storage requires a data migration",
|
|
136
|
+
},
|
|
123
137
|
compute_performance_unavailable: {
|
|
124
138
|
status: 503,
|
|
125
139
|
retryable: false,
|
|
@@ -327,10 +341,10 @@ export const PROBLEM_POLICY = {
|
|
|
327
341
|
status: 409,
|
|
328
342
|
retryable: false,
|
|
329
343
|
action:
|
|
330
|
-
"
|
|
344
|
+
"Read 'Storage jurisdiction' in 'ohmyhost project context --project ULID --json' and set storage.jurisdiction in ohmyhost.yaml to that recorded value (us or eu). Existing R2 buckets and reservations keep their jurisdiction after a project-region migration; only new storage without a recorded bucket uses the project region. If context reports unavailable, report the request ID through feedback rather than guessing. Save or push the corrected version and plan its commit; for promotion, deploy it to Dev and promote again. Do not delete or recreate the project to move files.",
|
|
331
345
|
title: "Storage jurisdiction conflict",
|
|
332
346
|
restAction:
|
|
333
|
-
"
|
|
347
|
+
"Read 'Storage jurisdiction' in 'ohmyhost project context --project ULID --json' and set storage.jurisdiction in ohmyhost.yaml to that recorded value (us or eu). Existing R2 buckets and reservations keep their jurisdiction after a project-region migration; only new storage without a recorded bucket uses the project region. If context reports unavailable, report the request ID through feedback rather than guessing. Save or push the corrected version and plan its commit; for promotion, deploy it to Dev and promote again. Do not delete or recreate the project to move files.",
|
|
334
348
|
},
|
|
335
349
|
shared_data_requires_promotion: {
|
|
336
350
|
status: 409,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** The platform supplies the project separately through its trusted dispatch context. */
|
|
2
|
+
export interface StorageGatewayOriginScope {
|
|
3
|
+
readonly organizationId: string;
|
|
4
|
+
readonly environmentId: string;
|
|
5
|
+
readonly dataEnvironmentId: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PinnedStorageGatewayOrigin extends StorageGatewayOriginScope {
|
|
8
|
+
readonly baseOrigin: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const GATEWAY_FAMILY =
|
|
12
|
+
/(?:^|\.)ohmyho-(mail|storage)-gateway-[a-z0-9][a-z0-9-]*\.[a-z0-9][a-z0-9-]*\.workers\.dev\.?$/u;
|
|
13
|
+
const ULID = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/u;
|
|
14
|
+
const PIN_ORGANIZATION = /^s1-([0-7][0-9a-hjkmnp-tv-z]{25})$/u;
|
|
15
|
+
const PIN_ENVIRONMENTS = /^([0-7][0-9a-hjkmnp-tv-z]{25})-([0-7][0-9a-hjkmnp-tv-z]{25})$/u;
|
|
16
|
+
|
|
17
|
+
/** A malformed prefixed pin is still a platform gateway and must never reach public fetch. */
|
|
18
|
+
export function classifyPlatformGatewayHostname(hostname: unknown): "mail" | "storage" | null {
|
|
19
|
+
if (typeof hostname !== "string") return null;
|
|
20
|
+
const family = GATEWAY_FAMILY.exec(hostname)?.[1];
|
|
21
|
+
return family === "mail" || family === "storage" ? family : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Encodes all three immutable data identities using two canonical, bounded DNS labels. */
|
|
25
|
+
export function createPinnedStorageGatewayOrigin(baseOrigin: string, scope: unknown): string {
|
|
26
|
+
const base = canonicalOrigin(baseOrigin);
|
|
27
|
+
if (
|
|
28
|
+
base === null ||
|
|
29
|
+
base.hostname.split(".").length !== 4 ||
|
|
30
|
+
classifyPlatformGatewayHostname(base.hostname) !== "storage" ||
|
|
31
|
+
typeof scope !== "object" ||
|
|
32
|
+
scope === null ||
|
|
33
|
+
Array.isArray(scope)
|
|
34
|
+
)
|
|
35
|
+
throw new TypeError("Storage gateway origin scope is invalid");
|
|
36
|
+
const record = scope as Record<string, unknown>;
|
|
37
|
+
const values = [record["organizationId"], record["environmentId"], record["dataEnvironmentId"]];
|
|
38
|
+
if (values.some((value) => typeof value !== "string" || value.length !== 26 || !ULID.test(value)))
|
|
39
|
+
throw new TypeError("Storage gateway origin scope is invalid");
|
|
40
|
+
const [organization, environment, data] = values.map((value) => String(value).toLowerCase());
|
|
41
|
+
const origin = `https://s1-${organization}.${environment}-${data}.${base.hostname}`;
|
|
42
|
+
if (canonicalOrigin(origin) === null) throw new TypeError("Storage gateway origin is too long");
|
|
43
|
+
return origin;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Decodes only the versioned canonical pin; the trusted caller must bind its base and project. */
|
|
47
|
+
export function parsePinnedStorageGatewayOrigin(value: unknown): PinnedStorageGatewayOrigin | null {
|
|
48
|
+
const origin = canonicalOrigin(value);
|
|
49
|
+
if (origin === null) return null;
|
|
50
|
+
const labels = origin.hostname.split(".");
|
|
51
|
+
if (labels.length !== 6) return null;
|
|
52
|
+
const organization = PIN_ORGANIZATION.exec(labels[0] ?? "")?.[1];
|
|
53
|
+
const environments = PIN_ENVIRONMENTS.exec(labels[1] ?? "");
|
|
54
|
+
const environment = environments?.[1];
|
|
55
|
+
const data = environments?.[2];
|
|
56
|
+
const baseHostname = labels.slice(2).join(".");
|
|
57
|
+
if (
|
|
58
|
+
organization === undefined ||
|
|
59
|
+
environment === undefined ||
|
|
60
|
+
data === undefined ||
|
|
61
|
+
classifyPlatformGatewayHostname(baseHostname) !== "storage"
|
|
62
|
+
)
|
|
63
|
+
return null;
|
|
64
|
+
return Object.freeze({
|
|
65
|
+
baseOrigin: `https://${baseHostname}`,
|
|
66
|
+
organizationId: organization.toUpperCase(),
|
|
67
|
+
environmentId: environment.toUpperCase(),
|
|
68
|
+
dataEnvironmentId: data.toUpperCase(),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function canonicalOrigin(value: unknown): URL | null {
|
|
73
|
+
if (typeof value !== "string") return null;
|
|
74
|
+
try {
|
|
75
|
+
const url = new URL(value);
|
|
76
|
+
return url.protocol === "https:" &&
|
|
77
|
+
url.origin === value &&
|
|
78
|
+
url.port === "" &&
|
|
79
|
+
url.username === "" &&
|
|
80
|
+
url.password === "" &&
|
|
81
|
+
url.pathname === "/" &&
|
|
82
|
+
url.search === "" &&
|
|
83
|
+
url.hash === "" &&
|
|
84
|
+
url.hostname.length <= 253 &&
|
|
85
|
+
url.hostname
|
|
86
|
+
.split(".")
|
|
87
|
+
.every((label) => /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u.test(label))
|
|
88
|
+
? url
|
|
89
|
+
: null;
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -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
|
+
}
|