@amerged/ohmyhost-cli 0.1.65 → 0.1.67
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/dist/bin.js +1 -1
- package/dist/{chunk-GHNVKYDB.js → chunk-TTY2P5HM.js} +534 -162
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/apps/product-cli/package.json +1 -1
- package/src/apps/product-cli/src/cli.ts +131 -16
- package/src/apps/product-cli/src/command.ts +88 -13
- package/src/apps/product-cli/src/composition.ts +4 -4
- package/src/apps/product-cli/src/product-api.ts +25 -2
- package/src/apps/product-cli/src/psql-session.ts +31 -1
- package/src/apps/product-cli/src/runtime-contract.ts +65 -0
- package/src/packages/contracts/package.json +5 -0
- package/src/packages/contracts/src/browser-capabilities.ts +2 -0
- package/src/packages/contracts/src/credit-pricing.ts +1 -1
- package/src/packages/contracts/src/database-compute.ts +3 -50
- package/src/packages/contracts/src/database-migration-admission.ts +70 -7
- package/src/packages/contracts/src/database-migration-lexical.ts +20 -5
- package/src/packages/contracts/src/egress-origin.ts +48 -0
- package/src/packages/contracts/src/framework-admission.ts +7 -1
- package/src/packages/contracts/src/framework-source-rules.ts +132 -3
- package/src/packages/contracts/src/index.ts +3 -72
- package/src/packages/contracts/src/managed-sources.ts +16 -1
- package/src/packages/contracts/src/operation-deployment-result.ts +2 -2
- package/src/packages/contracts/src/operation-failure.ts +10 -6
- package/src/packages/contracts/src/problem-policy.ts +57 -2
- package/src/packages/contracts/src/secret-names.ts +3 -1
- package/src/packages/sdk-ts/package.json +1 -1
- package/src/packages/sdk-ts/src/generated/index.ts +2 -0
- package/src/packages/sdk-ts/src/generated/mcp-remote.gen.ts +205 -345
- package/src/packages/sdk-ts/src/generated/sdk.gen.ts +25 -8
- package/src/packages/sdk-ts/src/generated/types.gen.ts +96 -62
- package/src/packages/sdk-ts/src/managed-mail.ts +3 -0
|
@@ -1219,6 +1219,51 @@ function validDelivery(input: Readonly<Record<string, unknown>>): boolean {
|
|
|
1219
1219
|
);
|
|
1220
1220
|
}
|
|
1221
1221
|
|
|
1222
|
+
/** One page of a project's deployments, newest first; each record is checked where it is read. */
|
|
1223
|
+
export interface DeploymentListPage {
|
|
1224
|
+
readonly items: readonly Readonly<Record<string, unknown>>[];
|
|
1225
|
+
readonly next_cursor: string | null;
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
export const parseDeploymentPage = (value: unknown): DeploymentListPage => {
|
|
1229
|
+
const input = exactRecord(value, ["items", "next_cursor"]);
|
|
1230
|
+
const items = input["items"];
|
|
1231
|
+
const cursor = input["next_cursor"];
|
|
1232
|
+
if (
|
|
1233
|
+
!Array.isArray(items) ||
|
|
1234
|
+
(cursor !== undefined &&
|
|
1235
|
+
cursor !== null &&
|
|
1236
|
+
(typeof cursor !== "string" || !/^[A-Za-z0-9_-]+$/u.test(cursor)))
|
|
1237
|
+
)
|
|
1238
|
+
throw new ResponseContractError();
|
|
1239
|
+
return {
|
|
1240
|
+
items: items.map((item) => parseDeploymentRecord(item)),
|
|
1241
|
+
next_cursor: typeof cursor === "string" ? cursor : null,
|
|
1242
|
+
};
|
|
1243
|
+
};
|
|
1244
|
+
|
|
1245
|
+
/** The keys of the Deployment schema, which admits no other field. */
|
|
1246
|
+
const DEPLOYMENT_RECORD_KEYS = [
|
|
1247
|
+
"id",
|
|
1248
|
+
"project_id",
|
|
1249
|
+
"operation_id",
|
|
1250
|
+
"commit_sha",
|
|
1251
|
+
"source_digest",
|
|
1252
|
+
"build_plan_digest",
|
|
1253
|
+
"artifact_digest",
|
|
1254
|
+
"status",
|
|
1255
|
+
"url",
|
|
1256
|
+
"created_at",
|
|
1257
|
+
"updated_at",
|
|
1258
|
+
];
|
|
1259
|
+
|
|
1260
|
+
export const parseDeploymentRecord = (value: unknown): Readonly<Record<string, unknown>> => {
|
|
1261
|
+
const record = exactRecord(value, DEPLOYMENT_RECORD_KEYS);
|
|
1262
|
+
if (!isUlid(record["id"]) || typeof record["status"] !== "string")
|
|
1263
|
+
throw new ResponseContractError();
|
|
1264
|
+
return record;
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1222
1267
|
export const parseDeploymentPlan = (value: unknown): Readonly<Record<string, unknown>> => {
|
|
1223
1268
|
const input = exactRecord(value, [
|
|
1224
1269
|
"id",
|
|
@@ -1435,6 +1480,26 @@ export const parseSafeProblem = (value: unknown): SafeProblem => {
|
|
|
1435
1480
|
};
|
|
1436
1481
|
};
|
|
1437
1482
|
|
|
1483
|
+
/** The accepted project creation: its operation and the identifier of the new project. */
|
|
1484
|
+
export interface AcceptedProjectCreation {
|
|
1485
|
+
readonly operation: PublicOperation;
|
|
1486
|
+
readonly project_id: string;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
export const parseProjectCreateAccepted = (value: unknown): AcceptedProjectCreation => {
|
|
1490
|
+
const fields = ["created_at", "id", "project_id", "state", "updated_at"];
|
|
1491
|
+
const input = exactRecord(value, fields);
|
|
1492
|
+
const { project_id: projectId, ...operation } = input;
|
|
1493
|
+
if (
|
|
1494
|
+
Object.keys(input).length !== fields.length ||
|
|
1495
|
+
operation["state"] !== "queued" ||
|
|
1496
|
+
!isUlid(projectId)
|
|
1497
|
+
) {
|
|
1498
|
+
throw new ResponseContractError();
|
|
1499
|
+
}
|
|
1500
|
+
return { operation: parseOperation(operation), project_id: projectId };
|
|
1501
|
+
};
|
|
1502
|
+
|
|
1438
1503
|
export const parseOperation = (value: unknown): PublicOperation => {
|
|
1439
1504
|
const input = exactRecord(value, [
|
|
1440
1505
|
"blocking_operation_id",
|
|
@@ -45,6 +45,11 @@
|
|
|
45
45
|
"types": "./dist/credit-pricing.d.ts",
|
|
46
46
|
"import": "./dist/credit-pricing.js"
|
|
47
47
|
},
|
|
48
|
+
"./egress-origin": {
|
|
49
|
+
"source": "./src/egress-origin.ts",
|
|
50
|
+
"types": "./dist/egress-origin.d.ts",
|
|
51
|
+
"import": "./dist/egress-origin.js"
|
|
52
|
+
},
|
|
48
53
|
"./platform-origins": {
|
|
49
54
|
"source": "./src/platform-origins.ts",
|
|
50
55
|
"types": "./dist/platform-origins.d.ts",
|
|
@@ -102,6 +102,8 @@ function browserOrigin(value: unknown, allowWebSocket: boolean): value is string
|
|
|
102
102
|
return (
|
|
103
103
|
(url.protocol === "https:" || (allowWebSocket && url.protocol === "wss:")) &&
|
|
104
104
|
url.origin === value &&
|
|
105
|
+
// Port 0 serializes unchanged, but the 0336 browser-policy triggers require a first digit of 1 to 9.
|
|
106
|
+
(url.port === "" || /^[1-9][0-9]{0,4}$/u.test(url.port)) &&
|
|
105
107
|
url.username === "" &&
|
|
106
108
|
url.password === "" &&
|
|
107
109
|
url.pathname === "/" &&
|
|
@@ -8,7 +8,7 @@ export interface OrganizationCreditUsage {
|
|
|
8
8
|
from: string;
|
|
9
9
|
/** What each project has used so far in `period`. */
|
|
10
10
|
projects: { project_id: string; used_micros: string }[];
|
|
11
|
-
/** The credit-log
|
|
11
|
+
/** The credit-log charges of the last up to 14 UTC days, grouped by day, project and meter, oldest day first; refunds are not netted. */
|
|
12
12
|
days: {
|
|
13
13
|
day: string;
|
|
14
14
|
projects: {
|
|
@@ -20,20 +20,7 @@ export interface DatabaseCompute {
|
|
|
20
20
|
readonly environment: "dev" | "prod";
|
|
21
21
|
readonly data_mode: "shared" | "isolated";
|
|
22
22
|
readonly observed_at: string;
|
|
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
|
-
};
|
|
23
|
+
readonly database: null | PgcfDatabaseCompute;
|
|
37
24
|
}
|
|
38
25
|
export function assertDatabaseCompute(value: unknown): asserts value is DatabaseCompute {
|
|
39
26
|
if (
|
|
@@ -50,43 +37,9 @@ export function assertDatabaseCompute(value: unknown): asserts value is Database
|
|
|
50
37
|
throw new TypeError("Invalid database compute report");
|
|
51
38
|
const db = value["database"];
|
|
52
39
|
if (db === null) return;
|
|
53
|
-
if (record(db)
|
|
54
|
-
assertPgcfCompute(db);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (
|
|
58
|
-
!record(db) ||
|
|
59
|
-
!exact(db, [
|
|
60
|
-
"disabled",
|
|
61
|
-
"max_cu",
|
|
62
|
-
"max_memory_gb",
|
|
63
|
-
"min_cu",
|
|
64
|
-
"min_memory_gb",
|
|
65
|
-
"pending_state",
|
|
66
|
-
"region",
|
|
67
|
-
"state",
|
|
68
|
-
"suspend_timeout_seconds",
|
|
69
|
-
]) ||
|
|
70
|
-
typeof db["min_cu"] !== "number" ||
|
|
71
|
-
typeof db["max_cu"] !== "number" ||
|
|
72
|
-
!Number.isFinite(db["min_cu"]) ||
|
|
73
|
-
!Number.isFinite(db["max_cu"]) ||
|
|
74
|
-
db["min_cu"] < 0.25 ||
|
|
75
|
-
db["max_cu"] < db["min_cu"] ||
|
|
76
|
-
db["max_cu"] > Number.MAX_SAFE_INTEGER / 4096 ||
|
|
77
|
-
db["min_memory_gb"] !== db["min_cu"] * 4 ||
|
|
78
|
-
db["max_memory_gb"] !== db["max_cu"] * 4 ||
|
|
79
|
-
!Number.isSafeInteger(db["suspend_timeout_seconds"]) ||
|
|
80
|
-
Number(db["suspend_timeout_seconds"]) < -1 ||
|
|
81
|
-
Number(db["suspend_timeout_seconds"]) > 604800 ||
|
|
82
|
-
!["init", "active", "idle"].includes(String(db["state"])) ||
|
|
83
|
-
(db["pending_state"] !== null &&
|
|
84
|
-
!["init", "active", "idle"].includes(String(db["pending_state"]))) ||
|
|
85
|
-
typeof db["disabled"] !== "boolean" ||
|
|
86
|
-
typeof db["region"] !== "string" ||
|
|
87
|
-
!/^aws-[a-z0-9]+(?:-[a-z0-9]+)*-[0-9]+$/u.test(db["region"])
|
|
88
|
-
)
|
|
40
|
+
if (!record(db) || db["provider"] !== "pgcf")
|
|
89
41
|
throw new TypeError("Invalid database compute configuration");
|
|
42
|
+
assertPgcfCompute(db);
|
|
90
43
|
}
|
|
91
44
|
function assertPgcfCompute(db: Record<string, unknown>): void {
|
|
92
45
|
const size = databaseSizeForClass(db["size_class_id"]);
|
|
@@ -179,11 +179,76 @@ function pinsSearchPath(tokens: readonly MigrationSqlToken[]): boolean {
|
|
|
179
179
|
return found;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Joins the tokens with single spaces, except around a `.` symbol, so `public . t` reads `public.t`. Work stays linear
|
|
184
|
+
* in the token count: a regex over the joined text would backtrack quadratically through a quoted identifier's spaces.
|
|
185
|
+
*/
|
|
186
|
+
function normalizeTokens(tokens: readonly MigrationSqlToken[]): string {
|
|
187
|
+
let normalized = "";
|
|
188
|
+
let afterDot = true;
|
|
189
|
+
for (const token of tokens) {
|
|
190
|
+
const isDot = token.kind === "symbol" && token.value === ".";
|
|
191
|
+
if (!isDot && !afterDot) normalized += " ";
|
|
192
|
+
normalized += token.kind === "string" ? "'literal'" : token.text.toLowerCase();
|
|
193
|
+
afterDot = isDot;
|
|
194
|
+
}
|
|
195
|
+
return normalized;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Recognises `ALTER TABLE [IF EXISTS] [ONLY] name ADD [COLUMN|CONSTRAINT] [IF NOT EXISTS] name ...` from the tokens, so a
|
|
200
|
+
* quoted, punctuated or non-ASCII name is read as CREATE TABLE reads it. Only a top-level comma that starts another
|
|
201
|
+
* action can change the statement, so every comma outside parentheses and brackets must be followed by ADD; a comma
|
|
202
|
+
* inside them, such as the elements of ARRAY[...], belongs to an expression. Parentheses and brackets must nest, so a
|
|
203
|
+
* stray, mismatched or unclosed one refuses the statement. The rest of the column definition is left to PostgreSQL,
|
|
204
|
+
* as before.
|
|
205
|
+
*/
|
|
206
|
+
function readAdditiveAlterTable(tokens: readonly MigrationSqlToken[]): boolean {
|
|
207
|
+
let index = 0;
|
|
208
|
+
const take = (keyword: string): boolean => {
|
|
209
|
+
if (!isSqlKeyword(tokens[index], keyword)) return false;
|
|
210
|
+
index += 1;
|
|
211
|
+
return true;
|
|
212
|
+
};
|
|
213
|
+
const takeName = (): boolean => {
|
|
214
|
+
const token = tokens[index];
|
|
215
|
+
if (token?.kind !== "word" && token?.kind !== "identifier") return false;
|
|
216
|
+
index += 1;
|
|
217
|
+
return true;
|
|
218
|
+
};
|
|
219
|
+
if (!take("alter") || !take("table")) return false;
|
|
220
|
+
if (take("if") && !take("exists")) return false;
|
|
221
|
+
take("only");
|
|
222
|
+
if (!takeName()) return false;
|
|
223
|
+
while (tokens[index]?.kind === "symbol" && tokens[index]?.value === ".") {
|
|
224
|
+
index += 1;
|
|
225
|
+
if (!takeName()) return false;
|
|
226
|
+
}
|
|
227
|
+
if (!take("add")) return false;
|
|
228
|
+
if (!take("column")) take("constraint");
|
|
229
|
+
if (take("if") && (!take("not") || !take("exists"))) return false;
|
|
230
|
+
if (!takeName()) return false;
|
|
231
|
+
const expectedClosers: string[] = [];
|
|
232
|
+
for (; index < tokens.length; index += 1) {
|
|
233
|
+
const token = tokens[index];
|
|
234
|
+
if (token?.kind !== "symbol") continue;
|
|
235
|
+
if (token.value === "(") expectedClosers.push(")");
|
|
236
|
+
else if (token.value === "[") expectedClosers.push("]");
|
|
237
|
+
else if (token.value === ")" || token.value === "]") {
|
|
238
|
+
if (expectedClosers.pop() !== token.value) return false;
|
|
239
|
+
} else if (
|
|
240
|
+
token.value === "," &&
|
|
241
|
+
expectedClosers.length === 0 &&
|
|
242
|
+
!isSqlKeyword(tokens[index + 1], "add")
|
|
243
|
+
) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return expectedClosers.length === 0;
|
|
248
|
+
}
|
|
249
|
+
|
|
182
250
|
function admitStatement(tokens: readonly MigrationSqlToken[], sql: string): void {
|
|
183
|
-
const normalized = tokens
|
|
184
|
-
.map((token) => (token.kind === "string" ? "'literal'" : token.text.toLowerCase()))
|
|
185
|
-
.join(" ")
|
|
186
|
-
.replace(/\s*\.\s*/gu, ".");
|
|
251
|
+
const normalized = normalizeTokens(tokens);
|
|
187
252
|
if (normalized === "set check_function_bodies = false") return;
|
|
188
253
|
if (/^create\s+function\b/u.test(normalized)) {
|
|
189
254
|
rejectFunctionBodyReferences(sql);
|
|
@@ -207,9 +272,7 @@ function admitStatement(tokens: readonly MigrationSqlToken[], sql: string): void
|
|
|
207
272
|
normalized,
|
|
208
273
|
) ||
|
|
209
274
|
/^create\s+(?:unique\s+)?index\b/u.test(normalized) ||
|
|
210
|
-
|
|
211
|
-
normalized,
|
|
212
|
-
) ||
|
|
275
|
+
readAdditiveAlterTable(tokens) ||
|
|
213
276
|
/^comment\s+on\b/u.test(normalized)
|
|
214
277
|
) {
|
|
215
278
|
if (/^create\s+or\s+replace\b/u.test(normalized)) {
|
|
@@ -11,6 +11,12 @@ export interface MigrationSqlStatement {
|
|
|
11
11
|
readonly tokens: readonly MigrationSqlToken[];
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// PostgreSQL's scanner reads every non-ASCII code point as an identifier or dollar-tag byte (scan.l: ident_start,
|
|
15
|
+
// ident_cont, dolq_start, dolq_cont), so the lexer uses the same classes instead of Unicode letters.
|
|
16
|
+
const IDENTIFIER_START = /[A-Za-z_]|\P{ASCII}/u;
|
|
17
|
+
const IDENTIFIER_PART = /[A-Za-z0-9_$]|\P{ASCII}/u;
|
|
18
|
+
const DOLLAR_TAG = /^\$(?:(?:[A-Za-z_]|\P{ASCII})(?:[A-Za-z0-9_]|\P{ASCII})*)?\$/u;
|
|
19
|
+
|
|
14
20
|
/** SQL-aware boundaries only; PostgreSQL remains the expression parser. */
|
|
15
21
|
export function readMigrationSql(sql: string): readonly MigrationSqlStatement[] {
|
|
16
22
|
const statements: MigrationSqlStatement[] = [];
|
|
@@ -20,7 +26,8 @@ export function readMigrationSql(sql: string): readonly MigrationSqlStatement[]
|
|
|
20
26
|
while (index < sql.length) {
|
|
21
27
|
const character = sql[index] ?? "";
|
|
22
28
|
const next = sql[index + 1];
|
|
23
|
-
|
|
29
|
+
// PostgreSQL's scanner whitespace is ASCII only: a no-break space is an identifier byte to it.
|
|
30
|
+
if (/[ \t\n\r\f\v]/u.test(character)) {
|
|
24
31
|
index += 1;
|
|
25
32
|
continue;
|
|
26
33
|
}
|
|
@@ -55,18 +62,26 @@ export function readMigrationSql(sql: string): readonly MigrationSqlStatement[]
|
|
|
55
62
|
index = skipQuoted(sql, quoteStart + 1, quote, escaped);
|
|
56
63
|
kind = quote === '"' ? "identifier" : "string";
|
|
57
64
|
value = sql.slice(quoteStart + 1, index - 1).replace(/""/gu, '"');
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
// PostgreSQL silently truncates a longer identifier to 63 bytes, so an over-long one cannot be admitted as written.
|
|
66
|
+
if (kind === "identifier" && new TextEncoder().encode(value).byteLength > 63) {
|
|
67
|
+
throw new DatabaseMigrationAdmissionError("invalid");
|
|
68
|
+
}
|
|
69
|
+
} else if (character === "$" && DOLLAR_TAG.test(sql.slice(index))) {
|
|
70
|
+
const delimiter = DOLLAR_TAG.exec(sql.slice(index))?.[0] ?? "";
|
|
60
71
|
const end = sql.indexOf(delimiter, index + delimiter.length);
|
|
61
72
|
if (end < 0) throw new DatabaseMigrationAdmissionError("invalid");
|
|
62
73
|
index = end + delimiter.length;
|
|
63
74
|
kind = "string";
|
|
64
75
|
value = sql.slice(tokenStart, index);
|
|
65
|
-
} else if (
|
|
76
|
+
} else if (IDENTIFIER_START.test(character)) {
|
|
66
77
|
index += 1;
|
|
67
|
-
while (index < sql.length &&
|
|
78
|
+
while (index < sql.length && IDENTIFIER_PART.test(sql[index] ?? "")) index += 1;
|
|
68
79
|
kind = "word";
|
|
69
80
|
value = sql.slice(tokenStart, index).toLowerCase();
|
|
81
|
+
// PostgreSQL truncates an unquoted name to 63 bytes as well, so an over-long word cannot be admitted as written.
|
|
82
|
+
if (new TextEncoder().encode(sql.slice(tokenStart, index)).byteLength > 63) {
|
|
83
|
+
throw new DatabaseMigrationAdmissionError("invalid");
|
|
84
|
+
}
|
|
70
85
|
} else {
|
|
71
86
|
index += 1;
|
|
72
87
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Self-contained on purpose: the build sandbox loads this file directly, so it imports nothing.
|
|
2
|
+
|
|
3
|
+
const DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u;
|
|
4
|
+
// Local names never resolve in the platform's network: mDNS (.local, .localdomain), home and office networks (.lan,
|
|
5
|
+
// .home.arpa, .corp) and internal zones (.internal, localhost). An IP literal is never a routed DNS name.
|
|
6
|
+
const LOCAL_NAME = /(?:^|\.)(?:local|localhost|localdomain|internal|lan|home\.arpa|corp)$/u;
|
|
7
|
+
const IPV4_LITERAL = /^\d{1,3}(?:\.\d{1,3}){3}$/u;
|
|
8
|
+
// The platform supplies the mail, storage and connection origins. Customers never declare them.
|
|
9
|
+
const PLATFORM_GATEWAY_NAME =
|
|
10
|
+
/(?:^|\.)ohmyho-(?:mail|storage)-gateway-[a-z0-9][a-z0-9-]*\.[a-z0-9][a-z0-9-]*\.workers\.dev$/u;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The one DNS rule for an egress origin, shared by every validator that accepts one: `https://` with no port, path,
|
|
14
|
+
* credentials or other parts, and a hostname of at most 253 characters with at least one dot whose labels are 1 to 63
|
|
15
|
+
* lowercase letters, digits or hyphens that start and end with a letter or digit. Local names and IP literals are refused.
|
|
16
|
+
* Platform-injected origins pass here; customer-authored ones must also pass `isCustomerEgressOrigin`.
|
|
17
|
+
*/
|
|
18
|
+
export function isDnsEgressOrigin(value: unknown): value is string {
|
|
19
|
+
if (typeof value !== "string") return false;
|
|
20
|
+
let url: URL;
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(value);
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const { hostname } = url;
|
|
27
|
+
return (
|
|
28
|
+
url.protocol === "https:" &&
|
|
29
|
+
url.origin === value &&
|
|
30
|
+
url.port === "" &&
|
|
31
|
+
hostname.length <= 253 &&
|
|
32
|
+
hostname.includes(".") &&
|
|
33
|
+
hostname.split(".").every((label) => DNS_LABEL.test(label)) &&
|
|
34
|
+
!LOCAL_NAME.test(hostname) &&
|
|
35
|
+
!IPV4_LITERAL.test(hostname)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A customer-authored egress origin: the DNS rule, and never a platform gateway name. */
|
|
40
|
+
export function isCustomerEgressOrigin(value: unknown): value is string {
|
|
41
|
+
if (!isDnsEgressOrigin(value)) return false;
|
|
42
|
+
const { hostname } = new URL(value);
|
|
43
|
+
return (
|
|
44
|
+
!PLATFORM_GATEWAY_NAME.test(hostname) &&
|
|
45
|
+
hostname !== "connect.ohmyho.st" &&
|
|
46
|
+
!hostname.endsWith(".connect.ohmyho.st")
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -106,6 +106,9 @@ const ALL_LOCKFILES: readonly string[] = Object.freeze(
|
|
|
106
106
|
Object.values(PACKAGE_MANAGER_CONTRACTS).flatMap(({ lockfiles }) => lockfiles),
|
|
107
107
|
);
|
|
108
108
|
const PACKAGE_MANIFEST = "package.json";
|
|
109
|
+
// Yarn 2.0.0 introduced --immutable and Yarn 3.0.0 renamed --skip-builds to --mode=skip-build; the frozen,
|
|
110
|
+
// script-free install needs both, so an earlier Yarn is refused rather than run unfrozen or failing late.
|
|
111
|
+
const YARN_MINIMUM_MAJOR = 3;
|
|
109
112
|
const PACKAGE_MANAGER_DECLARATION =
|
|
110
113
|
/^(bun|npm|pnpm|yarn)@((?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*))$/u;
|
|
111
114
|
|
|
@@ -134,6 +137,9 @@ export function resolvePackageManager(input: PackageManagerInput): PackageManage
|
|
|
134
137
|
if (manager === "bun" && version !== PINNED_BUN_VERSION) {
|
|
135
138
|
throw new FrameworkAdmissionError("package_manager_version_unsupported", PACKAGE_MANIFEST);
|
|
136
139
|
}
|
|
140
|
+
if (manager === "yarn" && Number(version.split(".")[0]) < YARN_MINIMUM_MAJOR) {
|
|
141
|
+
throw new FrameworkAdmissionError("package_manager_version_unsupported", PACKAGE_MANIFEST);
|
|
142
|
+
}
|
|
137
143
|
return Object.freeze({
|
|
138
144
|
manager,
|
|
139
145
|
version,
|
|
@@ -502,7 +508,7 @@ const FRAMEWORK_CONVERSION_DETAILS = Object.freeze({
|
|
|
502
508
|
},
|
|
503
509
|
package_manager_version_unsupported: {
|
|
504
510
|
paths: ["manifest"],
|
|
505
|
-
template: `"{{path}}" pins a Bun
|
|
511
|
+
template: `"{{path}}" pins a version ohmyho.st cannot build with: Bun other than ${PINNED_BUN_VERSION}, the only Bun ohmyho.st builds with, or Yarn before 3.0.0, the first that runs the frozen install flags. Set packageManager to bun@${PINNED_BUN_VERSION} or to a Yarn version from 3.0.0 on, such as yarn@4.9.4, reinstall to update the lockfile, commit and push the change, then plan the new commit.`,
|
|
506
512
|
},
|
|
507
513
|
repository_configuration_invalid: {
|
|
508
514
|
paths: ["repository_config"],
|
|
@@ -513,6 +513,60 @@ export function workerModuleFindings(
|
|
|
513
513
|
return Object.freeze(findings);
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
+
const REGEX_LITERAL_KEYWORDS = new Set([
|
|
517
|
+
"await",
|
|
518
|
+
"case",
|
|
519
|
+
"do",
|
|
520
|
+
"else",
|
|
521
|
+
"return",
|
|
522
|
+
"throw",
|
|
523
|
+
"typeof",
|
|
524
|
+
"void",
|
|
525
|
+
"yield",
|
|
526
|
+
]);
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Whether a slash after the code character at `lastCode` opens a regex literal, judged from the code before it: at the
|
|
530
|
+
* start, after punctuation that cannot end an operand, or after a keyword that takes an operand. A slash after an
|
|
531
|
+
* identifier, a number or a closing bracket divides. `lastCode` is the source index of the last character written that
|
|
532
|
+
* is not white space; the test reads that character and the identifier run ending at it, so a long source stays linear.
|
|
533
|
+
*/
|
|
534
|
+
function startsRegexLiteral(source: string, lastCode: number): boolean {
|
|
535
|
+
if (lastCode === -1) return true;
|
|
536
|
+
if (/[(,=:[!&|?{};+\-*%~^]/u.test(source.charAt(lastCode))) return true;
|
|
537
|
+
let start = lastCode + 1;
|
|
538
|
+
while (start > 0 && /[\p{L}\p{N}_$]/u.test(source.charAt(start - 1))) start -= 1;
|
|
539
|
+
return REGEX_LITERAL_KEYWORDS.has(source.slice(start, lastCode + 1));
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* The index of the slash that closes a regex literal opened at `start` on its line, or -1 when it does not close.
|
|
544
|
+
* `unclosed` marks each (index, inside a class) state that an earlier scan has passed. Such a state ends the scan at
|
|
545
|
+
* once: a failing scan has passed only states that fail, and a closing scan passes only states that no later scan
|
|
546
|
+
* reaches, because sourceWithoutComments resumes after its slash. Every scan therefore reads each state once.
|
|
547
|
+
*/
|
|
548
|
+
function regexLiteralEnd(source: string, start: number, unclosed: Uint8Array): number {
|
|
549
|
+
let inClass = false;
|
|
550
|
+
for (let index = start + 1; index < source.length; index += 1) {
|
|
551
|
+
const state = index * 2 + (inClass ? 1 : 0);
|
|
552
|
+
if (unclosed[state] === 1) return -1;
|
|
553
|
+
unclosed[state] = 1;
|
|
554
|
+
const character = source[index];
|
|
555
|
+
if (character === "\n" || character === "\r") return -1;
|
|
556
|
+
if (character === "\\") {
|
|
557
|
+
index += 1;
|
|
558
|
+
if (source[index] === "\n" || source[index] === "\r") return -1;
|
|
559
|
+
} else if (inClass) {
|
|
560
|
+
if (character === "]") inClass = false;
|
|
561
|
+
} else if (character === "[") {
|
|
562
|
+
inClass = true;
|
|
563
|
+
} else if (character === "/") {
|
|
564
|
+
return index;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return -1;
|
|
568
|
+
}
|
|
569
|
+
|
|
516
570
|
/**
|
|
517
571
|
* Source text with every comment blanked and every string kept, so a URL keeps its "//". A quoted
|
|
518
572
|
* string also ends at a line break, so an apostrophe in JSX text never hides the comments after it,
|
|
@@ -521,20 +575,27 @@ export function workerModuleFindings(
|
|
|
521
575
|
export function sourceWithoutComments(source: string): string {
|
|
522
576
|
let result = "";
|
|
523
577
|
let quote: "'" | '"' | "`" | null = null;
|
|
578
|
+
// Source index of the last character written that is not white space, which decides whether a slash opens a regex.
|
|
579
|
+
// The output keeps every source index, so this index also locates that character in the output.
|
|
580
|
+
let lastCode = -1;
|
|
581
|
+
let unclosed: Uint8Array | null = null;
|
|
524
582
|
for (let index = 0; index < source.length; index += 1) {
|
|
525
583
|
const character = source[index] as string;
|
|
526
584
|
const next = source[index + 1];
|
|
527
585
|
if (quote !== null) {
|
|
528
586
|
result += character;
|
|
587
|
+
if (!/\s/u.test(character)) lastCode = index;
|
|
529
588
|
if (character === "\\") {
|
|
530
589
|
index += 1;
|
|
531
590
|
result += source[index] ?? "";
|
|
591
|
+
if (index < source.length && !/\s/u.test(source[index] as string)) lastCode = index;
|
|
532
592
|
} else if (character === quote || (character === "\n" && quote !== "`")) quote = null;
|
|
533
593
|
continue;
|
|
534
594
|
}
|
|
535
595
|
if (character === "'" || character === '"' || character === "`") {
|
|
536
596
|
quote = character;
|
|
537
597
|
result += character;
|
|
598
|
+
lastCode = index;
|
|
538
599
|
continue;
|
|
539
600
|
}
|
|
540
601
|
if (character === "/" && next === "/" && source[index - 1] !== "\\") {
|
|
@@ -545,6 +606,17 @@ export function sourceWithoutComments(source: string): string {
|
|
|
545
606
|
result += "\n";
|
|
546
607
|
continue;
|
|
547
608
|
}
|
|
609
|
+
if (character === "/" && next !== "/" && next !== "*" && startsRegexLiteral(source, lastCode)) {
|
|
610
|
+
// A regex literal is copied whole: a backtick or quote inside it opens no template or string.
|
|
611
|
+
unclosed ??= new Uint8Array(source.length * 2);
|
|
612
|
+
const end = regexLiteralEnd(source, index, unclosed);
|
|
613
|
+
if (end !== -1) {
|
|
614
|
+
result += source.slice(index, end + 1);
|
|
615
|
+
lastCode = end;
|
|
616
|
+
index = end;
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
548
620
|
if (character === "/" && next === "*" && source[index - 1] !== "\\") {
|
|
549
621
|
result += " ";
|
|
550
622
|
index += 2;
|
|
@@ -558,6 +630,7 @@ export function sourceWithoutComments(source: string): string {
|
|
|
558
630
|
continue;
|
|
559
631
|
}
|
|
560
632
|
result += character;
|
|
633
|
+
if (!/\s/u.test(character)) lastCode = index;
|
|
561
634
|
}
|
|
562
635
|
return result;
|
|
563
636
|
}
|
|
@@ -1237,6 +1310,63 @@ function hasModuleImport(tokens: readonly ConfigToken[], moduleName: string): bo
|
|
|
1237
1310
|
);
|
|
1238
1311
|
}
|
|
1239
1312
|
|
|
1313
|
+
/** The number of braces open before each token, so the depth of a key shows the object that holds it. */
|
|
1314
|
+
function openBraceDepths(tokens: readonly ConfigToken[]): readonly number[] {
|
|
1315
|
+
let depth = 0;
|
|
1316
|
+
return tokens.map((token) => {
|
|
1317
|
+
const current = depth;
|
|
1318
|
+
if (token.value === "{") depth += 1;
|
|
1319
|
+
else if (token.value === "}") depth -= 1;
|
|
1320
|
+
return current;
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
const BUILD_OUTPUT_OPTIONS = ["assetsPrefix", "client", "serverEntry", "server"] as const;
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* Whether the top-level `build` option of an Astro config can set a build output option, which changes what the build
|
|
1328
|
+
* writes. A literal `build` object counts by its direct properties and its direct spreads: a `server` key elsewhere is
|
|
1329
|
+
* the dev server, and Vite's own options nest under `vite`. Any other use of `build` (a value, a shorthand or a spread
|
|
1330
|
+
* of it) hides its keys from the tokens, so it counts as a possible output option.
|
|
1331
|
+
*/
|
|
1332
|
+
function hasBuildOutputOption(tokens: readonly ConfigToken[]): boolean {
|
|
1333
|
+
const closing = closingBraces(tokens);
|
|
1334
|
+
const depths = openBraceDepths(tokens);
|
|
1335
|
+
return tokens.some((token, index) => {
|
|
1336
|
+
if (token.value !== "build" || depths[index] !== 1 || tokens[index - 1]?.value === ":")
|
|
1337
|
+
return false;
|
|
1338
|
+
if (tokens[index + 1]?.value !== ":" || tokens[index + 2]?.value !== "{") return true;
|
|
1339
|
+
const start = index + 2;
|
|
1340
|
+
const end = closing[start] ?? -1;
|
|
1341
|
+
if (end === -1) return true;
|
|
1342
|
+
return (
|
|
1343
|
+
BUILD_OUTPUT_OPTIONS.some(
|
|
1344
|
+
(name) => directProperty(tokens, closing, start, end, name) !== null,
|
|
1345
|
+
) || hasDirectSpread(tokens, depths, start, end)
|
|
1346
|
+
);
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/** Whether the object between `start` and `end` spreads another object at its own level, which may carry any key. */
|
|
1351
|
+
function hasDirectSpread(
|
|
1352
|
+
tokens: readonly ConfigToken[],
|
|
1353
|
+
depths: readonly number[],
|
|
1354
|
+
start: number,
|
|
1355
|
+
end: number,
|
|
1356
|
+
): boolean {
|
|
1357
|
+
const level = (depths[start] ?? 0) + 1;
|
|
1358
|
+
for (let index = start + 1; index < end; index += 1) {
|
|
1359
|
+
if (
|
|
1360
|
+
depths[index] === level &&
|
|
1361
|
+
tokens[index]?.value === "." &&
|
|
1362
|
+
tokens[index + 1]?.value === "." &&
|
|
1363
|
+
tokens[index + 2]?.value === "."
|
|
1364
|
+
)
|
|
1365
|
+
return true;
|
|
1366
|
+
}
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1240
1370
|
/** Astro's build validates executable config; admission rejects known incompatible contracts. */
|
|
1241
1371
|
function astroConfigFindings(
|
|
1242
1372
|
text: string,
|
|
@@ -1250,9 +1380,8 @@ function astroConfigFindings(
|
|
|
1250
1380
|
items.some((token, index) => token.value === name && items[index + 1]?.value === ":");
|
|
1251
1381
|
const invalid =
|
|
1252
1382
|
hasNonRootProperty(tokens, ["base"], ["", "/"]) ||
|
|
1253
|
-
["srcDir", "outDir"
|
|
1254
|
-
|
|
1255
|
-
) ||
|
|
1383
|
+
["srcDir", "outDir"].some((name) => hasPropertyKey(tokens, name)) ||
|
|
1384
|
+
hasBuildOutputOption(tokens) ||
|
|
1256
1385
|
(mode === "edge"
|
|
1257
1386
|
? !text.includes("@astrojs/cloudflare") ||
|
|
1258
1387
|
!hasProperty(tokens, "output", "server") ||
|