@amerged/ohmyhost-cli 0.1.54 → 0.1.56

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 (32) hide show
  1. package/README.md +1 -1
  2. package/dist/bin.js +1 -1
  3. package/dist/{chunk-ZEKUTE7M.js → chunk-HNFWXGDN.js} +511 -60
  4. package/dist/index.js +3 -1
  5. package/package.json +1 -1
  6. package/src/apps/product-cli/package.json +1 -1
  7. package/src/apps/product-cli/src/cli.ts +128 -25
  8. package/src/apps/product-cli/src/command.ts +143 -20
  9. package/src/apps/product-cli/src/index.ts +1 -0
  10. package/src/apps/product-cli/src/product-api.ts +75 -2
  11. package/src/apps/product-cli/src/repository-init.ts +46 -9
  12. package/src/apps/product-cli/src/runtime-contract.ts +52 -4
  13. package/src/packages/contracts/package.json +10 -0
  14. package/src/packages/contracts/src/database-events.ts +1 -0
  15. package/src/packages/contracts/src/database-migration-admission.ts +33 -3
  16. package/src/packages/contracts/src/database-migration-errors.ts +10 -2
  17. package/src/packages/contracts/src/feedback.ts +9 -0
  18. package/src/packages/contracts/src/framework-admission.ts +4 -0
  19. package/src/packages/contracts/src/framework-source-rules.ts +55 -0
  20. package/src/packages/contracts/src/operation-failure.ts +8 -0
  21. package/src/packages/contracts/src/organization-mcp-connections.ts +7 -0
  22. package/src/packages/contracts/src/problem-policy.ts +74 -2
  23. package/src/packages/contracts/src/project-exports.ts +30 -0
  24. package/src/packages/contracts/src/secret-names.ts +9 -2
  25. package/src/packages/contracts/src/wfp-dispatch.ts +43 -0
  26. package/src/packages/sdk-ts/package.json +1 -1
  27. package/src/packages/sdk-ts/src/generated/index.ts +39 -0
  28. package/src/packages/sdk-ts/src/generated/sdk.gen.ts +303 -13
  29. package/src/packages/sdk-ts/src/generated/types.gen.ts +460 -12
  30. package/src/packages/sdk-ts/src/managed-mail-response.ts +12 -0
  31. package/src/packages/sdk-ts/src/managed-mail.ts +10 -1
  32. package/src/packages/workos-auth-contracts/src/webhooks.ts +7 -0
@@ -1,4 +1,5 @@
1
1
  import { parseFeedbackSubmissionDetail } from "@ohmyhost/contracts/feedback";
2
+ import { MCP_CONNECTION_ID_PATTERN } from "@ohmyhost/contracts/organization-mcp-connections";
2
3
  import {
3
4
  assertGithubSourceResponse,
4
5
  assertManagedSourceResponse,
@@ -20,6 +21,8 @@ import type {
20
21
  GithubOrganizationConnection,
21
22
  GithubOrganizationConnectionStatus,
22
23
  OrganizationCredits,
24
+ OrganizationMcpConnectionList,
25
+ OrganizationMcpConnectionRevocation,
23
26
  ProjectCreditBudget,
24
27
  } from "@ohmyhost/sdk-ts";
25
28
  import { isSaasCnameTarget, type SaasCnameTarget } from "@ohmyhost/contracts/platform-origins";
@@ -232,7 +235,13 @@ export interface PublicCloudflareDnsAuthorization {
232
235
  }
233
236
 
234
237
  export interface PublicCloudflareDnsAuthorizationStatus {
235
- readonly status: "not_authorized" | "pending" | "authorized" | "expired" | "revoked";
238
+ readonly status:
239
+ | "not_authorized"
240
+ | "pending"
241
+ | "authorized"
242
+ | "reauthorization_required"
243
+ | "expired"
244
+ | "revoked";
236
245
  readonly zone: string | null;
237
246
  readonly scopes: readonly ("dns.write" | "zone.read")[];
238
247
  readonly expires_at: string | null;
@@ -325,6 +334,41 @@ export const parseGithubOrganizationConnectionStatus = (
325
334
  return input as unknown as GithubOrganizationConnectionStatus;
326
335
  };
327
336
 
337
+ export const parseOrganizationMcpConnectionList = (
338
+ value: unknown,
339
+ ): OrganizationMcpConnectionList => {
340
+ const input = exactRecord(value, ["connections"]);
341
+ if (!Array.isArray(input["connections"])) throw new ResponseContractError();
342
+ for (const item of input["connections"]) {
343
+ const connection = exactRecord(item, ["connection_id", "client_id", "user_id", "connected_at"]);
344
+ if (
345
+ typeof connection["connection_id"] !== "string" ||
346
+ !MCP_CONNECTION_ID_PATTERN.test(connection["connection_id"]) ||
347
+ !boundedString(connection["client_id"], 1, 2048) ||
348
+ !boundedString(connection["user_id"], 1, 256) ||
349
+ !isIsoInstant(connection["connected_at"])
350
+ )
351
+ throw new ResponseContractError();
352
+ }
353
+ return input as unknown as OrganizationMcpConnectionList;
354
+ };
355
+
356
+ export const parseOrganizationMcpConnectionRevocation = (
357
+ value: unknown,
358
+ ): OrganizationMcpConnectionRevocation => {
359
+ const input = exactRecord(value, ["state"]);
360
+ if (input["state"] !== "pending" && input["state"] !== "revoked")
361
+ throw new ResponseContractError();
362
+ return input as unknown as OrganizationMcpConnectionRevocation;
363
+ };
364
+
365
+ /** A disconnect answer that still reports a live connection did not disconnect, so it is refused. */
366
+ export const parseGithubDisconnection = (value: unknown): GithubOrganizationConnectionStatus => {
367
+ const status = parseGithubOrganizationConnectionStatus(value);
368
+ if (status.status === "connected") throw new ResponseContractError();
369
+ return status;
370
+ };
371
+
328
372
  export const parseGithubConnectionAuthorization = (
329
373
  value: unknown,
330
374
  ): GithubConnectionAuthorization => {
@@ -428,6 +472,7 @@ export const parseCloudflareDnsAuthorizationStatus = (
428
472
  (status !== "not_authorized" &&
429
473
  status !== "pending" &&
430
474
  status !== "authorized" &&
475
+ status !== "reauthorization_required" &&
431
476
  status !== "expired" &&
432
477
  status !== "revoked") ||
433
478
  (status === "not_authorized"
@@ -439,7 +484,8 @@ export const parseCloudflareDnsAuthorizationStatus = (
439
484
  new Set(scopes).size !== scopes.length ||
440
485
  (input["expires_at"] !== null && !isIsoInstant(input["expires_at"])) ||
441
486
  (status === "authorized" && [...scopes].sort().join(",") !== "dns.write,zone.read") ||
442
- (status === "not_authorized" && (scopes.length !== 0 || input["expires_at"] !== null))
487
+ (status === "not_authorized" && (scopes.length !== 0 || input["expires_at"] !== null)) ||
488
+ (status === "reauthorization_required" && (scopes.length !== 0 || input["expires_at"] !== null))
443
489
  ) {
444
490
  throw new ResponseContractError();
445
491
  }
@@ -1042,7 +1088,7 @@ export interface PublicFunctionRun {
1042
1088
  readonly deployment_id: string;
1043
1089
  readonly cron: string;
1044
1090
  readonly scheduled_at: string;
1045
- readonly state: "due" | "running" | "retry" | "succeeded" | "failed";
1091
+ readonly state: "due" | "running" | "retry" | "succeeded" | "failed" | "skipped";
1046
1092
  readonly attempt: number;
1047
1093
  readonly status_code: number | null;
1048
1094
  readonly started_at: string | null;
@@ -1073,7 +1119,9 @@ const parseFunctionRun = (value: unknown): PublicFunctionRun => {
1073
1119
  input["cron"].length === 0 ||
1074
1120
  input["cron"].length > 64 ||
1075
1121
  !isIsoInstant(input["scheduled_at"]) ||
1076
- !["due", "running", "retry", "succeeded", "failed"].includes(String(input["state"])) ||
1122
+ !["due", "running", "retry", "succeeded", "failed", "skipped"].includes(
1123
+ String(input["state"]),
1124
+ ) ||
1077
1125
  !Number.isSafeInteger(input["attempt"]) ||
1078
1126
  Number(input["attempt"]) < 0 ||
1079
1127
  Number(input["attempt"]) > 3 ||
@@ -45,6 +45,11 @@
45
45
  "types": "./dist/platform-origins.d.ts",
46
46
  "import": "./dist/platform-origins.js"
47
47
  },
48
+ "./wfp-dispatch": {
49
+ "source": "./src/wfp-dispatch.ts",
50
+ "types": "./dist/wfp-dispatch.d.ts",
51
+ "import": "./dist/wfp-dispatch.js"
52
+ },
48
53
  ".": {
49
54
  "source": "./src/index.ts",
50
55
  "types": "./dist/index.d.ts",
@@ -157,6 +162,11 @@
157
162
  "types": "./dist/secret-names.d.ts",
158
163
  "import": "./dist/secret-names.js"
159
164
  },
165
+ "./organization-mcp-connections": {
166
+ "source": "./src/organization-mcp-connections.ts",
167
+ "types": "./dist/organization-mcp-connections.d.ts",
168
+ "import": "./dist/organization-mcp-connections.js"
169
+ },
160
170
  "./project-data-changes": {
161
171
  "source": "./src/project-data-changes.ts",
162
172
  "types": "./dist/project-data-changes.d.ts",
@@ -33,6 +33,7 @@ export const DATABASE_SCHEDULE_STATEMENT_MAX_BYTES = 16 * 1024;
33
33
  export const DATABASE_SCHEDULE_STATEMENTS_MAX_BYTES = 64 * 1024;
34
34
  export const DATABASE_SCHEDULE_MIN_TIMEOUT_MS = 1_000;
35
35
  export const DATABASE_SCHEDULE_DEFAULT_TIMEOUT_MS = 10_000;
36
+ /** timeout_ms sets only the schedule's initial statement_timeout; the schedule's own statements can change it. The real bound is the platform abort at timeout_ms plus 75 seconds. */
36
37
  export const DATABASE_SCHEDULE_MAX_TIMEOUT_MS = 30_000;
37
38
 
38
39
  export const DATABASE_SCHEDULE_OUTCOMES = [
@@ -5,6 +5,7 @@ import {
5
5
  type DatabaseMigrationCaptureTrigger,
6
6
  } from "./database-migration-capture.js";
7
7
  import {
8
+ isSqlKeyword,
8
9
  readMigrationSql,
9
10
  rejectMigrationSqlReferences,
10
11
  type MigrationSqlToken,
@@ -151,6 +152,33 @@ function rejectFunctionBodyReferences(sql: string): void {
151
152
  }
152
153
  }
153
154
 
155
+ /**
156
+ * A SECURITY DEFINER body runs with its definer's rights, so every `SET search_path` in the statement header must pin the
157
+ * path to an empty list or one that starts with pg_catalog. A path the session can change, or one that starts with a
158
+ * customer schema, lets the caller decide which relation or function the definer touches. The body is one dollar-quoted
159
+ * token, so only the header can name a path, and a later SET overrides an earlier one: each occurrence must pin.
160
+ */
161
+ function pinsSearchPath(tokens: readonly MigrationSqlToken[]): boolean {
162
+ let found = false;
163
+ for (let index = 0; index + 2 < tokens.length; index += 1) {
164
+ if (!isSqlKeyword(tokens[index], "set") || !isSqlKeyword(tokens[index + 1], "search_path"))
165
+ continue;
166
+ const operator = tokens[index + 2];
167
+ const assigns =
168
+ isSqlKeyword(operator, "to") || (operator?.kind === "symbol" && operator.value === "=");
169
+ const first = tokens[index + 3];
170
+ if (!assigns || !first) return false;
171
+ found = true;
172
+ if (first.kind === "string") {
173
+ const list = first.value.trim().toLowerCase();
174
+ if (list !== "" && !/^pg_catalog(?:\s*,|$)/u.test(list)) return false;
175
+ } else if (first.kind === "word" || first.kind === "identifier") {
176
+ if (first.value.toLowerCase() !== "pg_catalog") return false;
177
+ } else return false;
178
+ }
179
+ return found;
180
+ }
181
+
154
182
  function admitStatement(tokens: readonly MigrationSqlToken[], sql: string): void {
155
183
  const normalized = tokens
156
184
  .map((token) => (token.kind === "string" ? "'literal'" : token.text.toLowerCase()))
@@ -161,10 +189,12 @@ function admitStatement(tokens: readonly MigrationSqlToken[], sql: string): void
161
189
  rejectFunctionBodyReferences(sql);
162
190
  if (
163
191
  !/\blanguage\s+(?:sql|plpgsql)\b/u.test(normalized) ||
164
- (/\bsecurity\s+definer\b/u.test(normalized) &&
165
- !/\bset\s+search_path\s*(?:=\s*|to\s+)/u.test(normalized))
192
+ (/\bsecurity\s+definer\b/u.test(normalized) && !pinsSearchPath(tokens))
166
193
  ) {
167
- throw new DatabaseMigrationAdmissionError("unsupported");
194
+ throw new DatabaseMigrationAdmissionError(
195
+ "unsupported",
196
+ "a SECURITY DEFINER function needs every SET search_path to be '' or to start with pg_catalog",
197
+ );
168
198
  }
169
199
  return;
170
200
  }
@@ -7,8 +7,16 @@ export type DatabaseMigrationAdmissionReason =
7
7
  export class DatabaseMigrationAdmissionError extends Error {
8
8
  public readonly code = "database_migration_not_admitted";
9
9
 
10
- public constructor(public readonly reason: DatabaseMigrationAdmissionReason) {
11
- super("Database migration is not admitted");
10
+ /** `detail` names the exact requirement for a refusal whose cause the customer can change; the code and reason do not change. */
11
+ public constructor(
12
+ public readonly reason: DatabaseMigrationAdmissionReason,
13
+ detail?: string,
14
+ ) {
15
+ super(
16
+ detail === undefined
17
+ ? "Database migration is not admitted"
18
+ : `Database migration is not admitted: ${detail}`,
19
+ );
12
20
  this.name = "DatabaseMigrationAdmissionError";
13
21
  }
14
22
  }
@@ -93,6 +93,7 @@ const detailSentence = new RegExp(
93
93
  "(?:title|description) must be a string\\.",
94
94
  "(?:title|description) must not be empty\\.",
95
95
  "(?:title|description) must not start or end with whitespace; trim it\\.",
96
+ "(?:title|description) must not contain a credential, key or connection string; remove it and submit again\\.",
96
97
  "(?:title|description) has [1-9][0-9]{0,8} characters, over the (?:160|8000)-character limit; shorten it, it is never truncated\\.",
97
98
  "title must not contain line breaks, tabs or other control characters\\.",
98
99
  "description must not contain control characters other than tabs and line breaks, such as terminal color codes\\.",
@@ -147,6 +148,10 @@ export function parseFeedbackSubmission(value: unknown): FeedbackSubmission {
147
148
  return v as unknown as FeedbackSubmission;
148
149
  }
149
150
 
151
+ /** Token, key and connection-string shapes that a customer must not paste into feedback; feedback is stored without expiry. */
152
+ const CREDENTIAL_SHAPE =
153
+ /whsec_[A-Za-z0-9]{20,}|omh_(?:ab|am)_[A-Za-z0-9_-]{16,}|sk_(?:live|test)_[A-Za-z0-9]{10,}|gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|AKIA[0-9A-Z]{16}|-----BEGIN [A-Z ]*PRIVATE KEY-----|[a-z][a-z0-9+.-]*:\/\/[^\s:/@]+:[^\s@/?#]+@/iu;
154
+
150
155
  /** The same rules as validText, each failure named for one field. */
151
156
  function textProblems(field: string, value: unknown, max: number, multiline: boolean): string[] {
152
157
  if (typeof value !== "string") return [`${field} must be a string.`];
@@ -159,6 +164,10 @@ function textProblems(field: string, value: unknown, max: number, multiline: boo
159
164
  problems.push(
160
165
  `${field} has ${String(length)} characters, over the ${String(max)}-character limit; shorten it, it is never truncated.`,
161
166
  );
167
+ if (CREDENTIAL_SHAPE.test(value))
168
+ problems.push(
169
+ `${field} must not contain a credential, key or connection string; remove it and submit again.`,
170
+ );
162
171
  if (hasControlCharacter(value, multiline))
163
172
  problems.push(
164
173
  multiline
@@ -375,6 +375,10 @@ const FRAMEWORK_CONVERSION_DETAILS = Object.freeze({
375
375
  paths: ["module"],
376
376
  template: `"{{path}}" imports a database socket driver (pg, postgres, pg-native or mysql2); customer Workers cannot open sockets. Call the database with createPrivateDatabaseClient from "@ohmyhost/customer-runtime/database". ${PUSH_AND_PLAN}`,
377
377
  },
378
+ socket_primitive_unsupported: {
379
+ paths: ["module"],
380
+ template: `"{{path}}" loads cloudflare:sockets; customer Workers cannot open sockets. Call HTTPS services through the global fetch function and declare each origin in runtime.egress.allow in ohmyhost.yaml. ${PUSH_AND_PLAN}`,
381
+ },
378
382
  source_syntax_invalid: {
379
383
  paths: ["module"],
380
384
  template:
@@ -143,6 +143,21 @@ const PNPM_RESOLVED_VERSION = /^([^()]+)(?:\(.*\))?$/u;
143
143
  const DEFAULT_EXPORT_PATTERN = /\bexport\s+default\b/u;
144
144
  const FETCH_HANDLER_PATTERN = /(?:[{,;}]|\basync)\s*fetch\s*(?:\(|:|,|\})/u;
145
145
  const SCHEDULED_HANDLER_PATTERN = /\bscheduled\s*(?:\(|:|,|\})/u;
146
+ /** The raw TCP primitive of the Workers runtime; a customer Worker never loads it. */
147
+ export const SOCKET_PRIMITIVE_SPECIFIER = "cloudflare:sockets" as const;
148
+ // The early hint reads the raw text: the quoted specifier, after string escapes are decoded.
149
+ const SOCKET_PRIMITIVE_PATTERN = new RegExp(`["'\`]${SOCKET_PRIMITIVE_SPECIFIER}["'\`]`, "u");
150
+ const STRING_ESCAPE =
151
+ /\\(?:x([0-9A-Fa-f]{2})|u([0-9A-Fa-f]{4})|u\{([0-9A-Fa-f]{1,6})\}|(?:\r\n|[\n\r\u2028\u2029])|([^\n\r\u2028\u2029]))/gu;
152
+ const SIMPLE_STRING_ESCAPES: Readonly<Record<string, string>> = Object.freeze({
153
+ b: "\b",
154
+ f: "\f",
155
+ n: "\n",
156
+ r: "\r",
157
+ t: "\t",
158
+ v: "\v",
159
+ "0": "\0",
160
+ });
146
161
  // No connection string reaches a customer Worker, and a Worker cannot open a socket.
147
162
  const DATABASE_CONTRACT_PATTERNS = Object.freeze([
148
163
  [
@@ -440,6 +455,38 @@ export function databaseContractCodes(source: string): readonly DatabaseContract
440
455
  );
441
456
  }
442
457
 
458
+ /**
459
+ * The early hint that a module names the raw socket primitive `cloudflare:sockets` in quotes, for
460
+ * `ohmyhost init`, which cannot parse source. It reads the raw text with string escapes decoded
461
+ * (`"cloudflare\x3asockets"` is found) and blanks no comment, so a regex literal cannot hide an
462
+ * import; a mention in a comment, a type-only import and a variable that holds the specifier count
463
+ * too. Planning does not rely on it: SourceFetcher decides from parsed, decoded specifiers.
464
+ */
465
+ export function importsSocketPrimitive(source: string): boolean {
466
+ return SOCKET_PRIMITIVE_PATTERN.test(decodeStringEscapes(source));
467
+ }
468
+
469
+ function decodeStringEscapes(source: string): string {
470
+ return source.replace(
471
+ STRING_ESCAPE,
472
+ (
473
+ match,
474
+ hex: string | undefined,
475
+ unit: string | undefined,
476
+ braces: string | undefined,
477
+ plain: string | undefined,
478
+ ) => {
479
+ const code = hex ?? unit ?? braces;
480
+ if (code !== undefined) {
481
+ const point = Number.parseInt(code, 16);
482
+ return point > 0x10ffff ? match : String.fromCodePoint(point);
483
+ }
484
+ // A line continuation spells nothing; any other escaped character stands for itself.
485
+ return plain === undefined ? "" : (SIMPLE_STRING_ESCAPES[plain] ?? plain);
486
+ },
487
+ );
488
+ }
489
+
443
490
  /**
444
491
  * The handler rules a Worker module breaks, ignoring comments: a default export, with fetch when
445
492
  * the module serves requests (runtime.mode: functions) and scheduled when crons are declared.
@@ -522,6 +569,14 @@ export function isDatabaseContractModule(path: string): boolean {
522
569
  return /\.(?:astro|ts|tsx|js|jsx|mjs|mts)$/u.test(path) && !/\.d\.[cm]?ts$/u.test(path);
523
570
  }
524
571
 
572
+ /**
573
+ * Whether `ohmyhost init` scans a module for the socket primitive: every source extension a Worker
574
+ * bundle can load, without TypeScript declaration files, which never run.
575
+ */
576
+ export function isSocketPrimitiveModule(path: string): boolean {
577
+ return /\.(?:astro|[cm]?[jt]sx?)$/u.test(path) && !/\.d\.[cm]?ts$/u.test(path);
578
+ }
579
+
525
580
  function manifestFindings(
526
581
  input: FrameworkSourceRuleInput,
527
582
  versions: readonly FrameworkVersionAdmission[],
@@ -130,6 +130,14 @@ const failures = {
130
130
  "The Prod deployment changed before promotion could start.",
131
131
  "Read current Prod status, run 'ohmyhost deployment promote plan' again and confirm it with the new resource_etag and confirmation_token. Replaying this terminal operation cannot replace its stale target.",
132
132
  ],
133
+ project_handle_taken: [
134
+ "The requested project handle was taken before the rename could finish. The project keeps its current handle.",
135
+ "Run 'ohmyhost project handle check --handle NAME --json' or MCP project_handle_check, choose a handle that is still free, then submit the rename again with the current ETag and a new idempotency key. Replaying this terminal operation cannot take the handle.",
136
+ ],
137
+ managed_source_dispatch_failed: [
138
+ "The managed source change could not be dispatched for processing, so it was ended.",
139
+ "Read the current source to confirm it did not change, then submit the change again with a new idempotency key.",
140
+ ],
133
141
  } as const;
134
142
 
135
143
  export interface PublicOperationFailure {
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The connection_id of one workspace MCP consent. The public contract names it as a UUID; the
3
+ * clients accept any hex UUID in the 8-4-4-4-12 form, so a server id that RFC 4122 would refuse is
4
+ * still reachable from the CLI and the MCP tools.
5
+ */
6
+ export const MCP_CONNECTION_ID_PATTERN =
7
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
@@ -326,6 +326,13 @@ export const PROBLEM_POLICY = {
326
326
  action: "The project already answers on this address; no rename is needed.",
327
327
  title: "Project address is unchanged",
328
328
  },
329
+ database_limit_reached: {
330
+ status: 409,
331
+ retryable: false,
332
+ action:
333
+ "Delete a database you no longer need, or the project whose database it is, then deploy again. The limit counts the organization's live databases.",
334
+ title: "Database limit reached",
335
+ },
329
336
  project_rename_blocked: {
330
337
  status: 409,
331
338
  retryable: true,
@@ -407,6 +414,13 @@ export const PROBLEM_POLICY = {
407
414
  "Read the workspace sender resource and project binding. Reuse requires explicit domain-use authority, target-project editing and a current verified application identity with the same registrable main domain. Read the current revision before changing settings. Detach a shared project binding explicitly; legacy domain deletion cannot retire a resource used by another project.",
408
415
  title: "Mail domain conflict",
409
416
  },
417
+ mail_domain_pending_limit: {
418
+ status: 409,
419
+ retryable: false,
420
+ action:
421
+ "This organization already holds the maximum number of unverified workspace mail domains. Verify one of them, or retire an unused one, and then add this domain again.",
422
+ title: "Mail domain pending limit",
423
+ },
410
424
  mail_domain_required: {
411
425
  status: 409,
412
426
  retryable: false,
@@ -501,6 +515,13 @@ export const PROBLEM_POLICY = {
501
515
  "Keep the flag on, remove the custom domain with 'ohmyhost domain paid delete', or buy Paid, then switch the flag off.",
502
516
  title: "Powered-by flag required",
503
517
  },
518
+ build_capacity_reached: {
519
+ status: 429,
520
+ retryable: false,
521
+ action:
522
+ "This organization already has its maximum number of open builds. Wait for an open deployment to finish, then start a new deployment with a new idempotency key.",
523
+ title: "Build capacity reached",
524
+ },
504
525
  rate_limited: {
505
526
  status: 429,
506
527
  retryable: true,
@@ -561,6 +582,13 @@ export const PROBLEM_POLICY = {
561
582
  "Stop retries and submit feedback with this operation ID. A platform recovery review is required.",
562
583
  title: "Recovery attempts exhausted",
563
584
  },
585
+ reconciliation_not_pending: {
586
+ status: 409,
587
+ retryable: false,
588
+ action:
589
+ "Do not repeat this reconciliation: no uncertain delivery or provider mutation is pending for this operation. If the operation still does not finish, submit feedback with this operation ID.",
590
+ title: "No recovery pending",
591
+ },
564
592
  service_unavailable: {
565
593
  status: 503,
566
594
  retryable: true,
@@ -583,11 +611,20 @@ export const PROBLEM_POLICY = {
583
611
  status: 409,
584
612
  retryable: false,
585
613
  action:
586
- "A live project connection already holds this hostname. Remove it from the project you manage with 'ohmyhost domain paid delete --project ULID --hostname HOST --yes --json', then apply it to the new project. Repeating while that connection remains cannot work; report the request_id if you cannot manage its owning project.",
614
+ "A live connection holds it; its holder removes it with ohmyhost domain paid delete --project ULID --hostname HOST --yes --json. To connect it here, add the _omh-project.HOST TXT record that ohmyhost domain paid status --project ULID --json shows for it, then apply again with ohmyhost domain paid apply --project ULID --hostname HOST --idempotency-key KEY --json.",
587
615
  restAction:
588
- "A live project connection already holds this hostname. Remove it from the project you manage with 'ohmyhost domain paid delete --project ULID --hostname HOST --yes --json', then apply it to the new project. Repeating while that connection remains cannot work; report the request_id if you cannot manage its owning project.",
616
+ "A live connection holds it; its holder removes it with ohmyhost domain paid delete --project ULID --hostname HOST --yes --json. To connect it here, add the _omh-project.HOST TXT record that ohmyhost domain paid status --project ULID --json shows for it, then apply again with ohmyhost domain paid apply --project ULID --hostname HOST --idempotency-key KEY --json.",
589
617
  title: "Domain hostname is already connected",
590
618
  },
619
+ domain_ownership_required: {
620
+ status: 409,
621
+ retryable: false,
622
+ action:
623
+ "This hostname is not verified for this project yet. Add the _omh-project.HOST TXT record that ohmyhost domain paid status --project ULID --json shows for it, then apply again with ohmyhost domain paid apply --project ULID --hostname HOST --idempotency-key KEY --json. Repeating before the record is published cannot work.",
624
+ restAction:
625
+ "This hostname is not verified for this project yet. Add the _omh-project.HOST TXT record that ohmyhost domain paid status --project ULID --json shows for it, then apply again with ohmyhost domain paid apply --project ULID --hostname HOST --idempotency-key KEY --json. Repeating before the record is published cannot work.",
626
+ title: "Verify the domain before connecting it",
627
+ },
591
628
  domain_dns_conflict: {
592
629
  status: 409,
593
630
  retryable: false,
@@ -645,6 +682,41 @@ export const PROBLEM_POLICY = {
645
682
  action:
646
683
  "Read project status and Paid domain status to identify the pending change. If a Paid domain removal is pending, retry it as a current owner with a new idempotency key. If a project address change is pending, submit a fresh address change as a current owner. After it finishes, create a new project deletion plan.",
647
684
  },
685
+ native_auth_launch_unavailable: {
686
+ status: 409,
687
+ retryable: false,
688
+ title: "Native Auth cannot launch yet",
689
+ action:
690
+ "Read the Native Auth configuration with 'ohmyhost auth config get --project ULID --environment ULID --json'. Its readiness shows which requirement is missing: a Paid plan, a verified sender domain, an approved canonical origin or storage. Complete that requirement, then send the change again with a new idempotency key. Repeating unchanged does not help.",
691
+ },
692
+ native_auth_provider_unavailable: {
693
+ status: 409,
694
+ retryable: false,
695
+ title: "Native Auth provider unavailable",
696
+ action:
697
+ "This sign-in provider cannot be enabled for this project's current Native Auth state. Read the provider with 'ohmyhost auth provider get --project ULID --environment ULID --provider google|github --json' and complete the Native Auth configuration it reports. Repeating unchanged does not help.",
698
+ },
699
+ native_auth_epoch_exhausted: {
700
+ status: 409,
701
+ retryable: false,
702
+ title: "Native Auth policy changes exhausted",
703
+ action:
704
+ "This project's Native Auth policy has reached its revision limit, so no further policy change is accepted. Do not retry. Contact support with the request_id of this response.",
705
+ },
706
+ project_domains_conflict: {
707
+ status: 409,
708
+ retryable: false,
709
+ title: "Project domains belong to another handle",
710
+ action:
711
+ "The domains of this project were configured under another project handle. Read the project with 'ohmyhost project status --project ULID --json' to see its current handle, then repeat the domain configuration with a new idempotency key. Do not replay the earlier request.",
712
+ },
713
+ native_user_conflict: {
714
+ status: 409,
715
+ retryable: false,
716
+ title: "Native Auth user conflicts with current state",
717
+ action:
718
+ "The user already exists, or the user is not in the state this action needs (for example a pending user cannot be suspended, and only a pending invitation can be resent). Read the user with 'ohmyhost auth user get --project ULID --environment ULID --user UUID --json' and choose the action that matches its status.",
719
+ },
648
720
  } as const;
649
721
 
650
722
  export type ProblemCode = keyof typeof PROBLEM_POLICY;
@@ -1,4 +1,10 @@
1
1
  import { publicOperationFailure, type PublicOperationFailure } from "./operation-failure.js";
2
+ /** Minimum characters for a new export password; restore and capture keep their own bounds. */
3
+ export const EXPORT_PASSWORD_MIN_CHARACTERS = 12;
4
+ /** Counts code points, the characters a customer types, matching JSON Schema minLength. */
5
+ export function exportPasswordMeetsMinimum(value: string): boolean {
6
+ return Array.from(value).length >= EXPORT_PASSWORD_MIN_CHARACTERS;
7
+ }
2
8
  export interface ProjectExport {
3
9
  readonly id: string;
4
10
  readonly project_id: string;
@@ -18,6 +24,30 @@ export interface ProjectExport {
18
24
  } | null;
19
25
  }
20
26
  /** The public export shape carries no job password, source URL or permanent storage credential. */
27
+ /** The answer of one audited download link: a signed URL and its expiry, never the archive state. */
28
+ export interface ProjectExportDownloadLink {
29
+ id: string;
30
+ project_id: string;
31
+ download_url: string;
32
+ download_expires_at: string;
33
+ }
34
+ export function assertProjectExportDownloadLink(
35
+ value: unknown,
36
+ ): asserts value is ProjectExportDownloadLink {
37
+ if (
38
+ !record(value) ||
39
+ Object.keys(value).sort().join(",") !== "download_expires_at,download_url,id,project_id" ||
40
+ typeof value["id"] !== "string" ||
41
+ !id.test(value["id"]) ||
42
+ typeof value["project_id"] !== "string" ||
43
+ !id.test(value["project_id"]) ||
44
+ typeof value["download_url"] !== "string" ||
45
+ !value["download_url"].startsWith("https://") ||
46
+ !timestamp(value["download_expires_at"])
47
+ )
48
+ throw new TypeError("Project export download link is invalid");
49
+ }
50
+
21
51
  export function assertProjectExport(value: unknown): asserts value is ProjectExport {
22
52
  if (
23
53
  !record(value) ||
@@ -10,12 +10,19 @@ const FIXED_PLATFORM_NAMES = new Set([
10
10
  "IMAGES",
11
11
  "STORAGE",
12
12
  ]);
13
- const INSTALLED_PLATFORM_KEYS = new Set([
13
+ /** The four keys the platform installs; control-store's rotation accepts exactly these names. */
14
+ export const INSTALLED_PLATFORM_KEY_NAMES = [
14
15
  "OHMYHOST_STORAGE_KEY",
15
16
  "OHMYHOST_MAIL_KEY",
16
17
  "OHMYHOST_AI_KEY",
17
18
  "BETTER_AUTH_SECRET",
18
- ]);
19
+ ] as const;
20
+ const INSTALLED_PLATFORM_KEYS = new Set<string>(INSTALLED_PLATFORM_KEY_NAMES);
21
+
22
+ /** The four keys the platform installs. An owner may rotate them; a customer may never set or delete them. */
23
+ export function isInstalledPlatformKeyName(value: unknown): value is string {
24
+ return typeof value === "string" && INSTALLED_PLATFORM_KEYS.has(value);
25
+ }
19
26
 
20
27
  export function isUserSecretName(
21
28
  value: unknown,
@@ -0,0 +1,43 @@
1
+ /**
2
+ * What every dynamic-dispatch call that runs customer code carries. The public gateway, the
3
+ * functions scheduler and the deploy health probe all read this module, so no path runs customer
4
+ * code under looser limits than the live request path, and the egress context has one shape for
5
+ * the one outbound policy Worker that parses it.
6
+ */
7
+ export const WFP_DISPATCH_LIMITS = Object.freeze({
8
+ cpuMs: 50,
9
+ subRequests: 10,
10
+ });
11
+ export const WFP_EGRESS_CONTEXT_VERSION = 1 as const;
12
+
13
+ /** The trusted `EGRESS_CONTEXT` parameter the dispatcher hands the outbound policy Worker. */
14
+ export type WfpEgressContext = Readonly<{
15
+ version: typeof WFP_EGRESS_CONTEXT_VERSION;
16
+ projectId: string;
17
+ allowedOrigins: readonly string[];
18
+ }>;
19
+
20
+ /**
21
+ * The context of one project: its ULID and the sorted allowed HTTPS origins, nothing else. The
22
+ * outbound Worker fails closed on anything it cannot parse, so every dispatcher builds it here.
23
+ */
24
+ export function buildEgressContext(
25
+ projectId: string,
26
+ allowedOrigins: readonly string[],
27
+ ): WfpEgressContext {
28
+ return Object.freeze({
29
+ version: WFP_EGRESS_CONTEXT_VERSION,
30
+ projectId,
31
+ allowedOrigins: Object.freeze([...allowedOrigins]),
32
+ });
33
+ }
34
+
35
+ /** The error a Worker raises when an invocation exceeds the CPU limit above. */
36
+ export function isCpuLimitError(error: unknown): boolean {
37
+ return error instanceof Error && error.message.includes("CPU time limit");
38
+ }
39
+
40
+ /** What a visitor and the deploy health verdict are told when that limit stops an invocation. */
41
+ export function cpuLimitMessage(): string {
42
+ return `Runtime limit exceeded: this request used more than ${WFP_DISPATCH_LIMITS.cpuMs} ms of CPU time. This is not a rate limit; reduce the work per request.`;
43
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohmyhost/sdk-ts",
3
- "version": "0.1.54",
3
+ "version": "0.1.56",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": {