@amerged/ohmyhost-cli 0.1.55 → 0.1.57

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 (30) hide show
  1. package/README.md +1 -1
  2. package/dist/bin.js +1 -1
  3. package/dist/{chunk-4OAAJX5B.js → chunk-GODV5QDC.js} +797 -86
  4. package/dist/index.js +9 -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 +208 -11
  8. package/src/apps/product-cli/src/command.ts +276 -19
  9. package/src/apps/product-cli/src/index.ts +1 -0
  10. package/src/apps/product-cli/src/product-api.ts +165 -3
  11. package/src/apps/product-cli/src/repository-init.ts +8 -0
  12. package/src/apps/product-cli/src/runtime-contract.ts +81 -5
  13. package/src/apps/product-cli/src/user-token-file.ts +73 -0
  14. package/src/packages/contracts/package.json +5 -0
  15. package/src/packages/contracts/src/credit-pricing.ts +1 -1
  16. package/src/packages/contracts/src/database-events.ts +67 -0
  17. package/src/packages/contracts/src/framework-admission.ts +5 -4
  18. package/src/packages/contracts/src/framework-source-rules.ts +9 -2
  19. package/src/packages/contracts/src/index.ts +9 -0
  20. package/src/packages/contracts/src/operation-deployment-result.ts +121 -1
  21. package/src/packages/contracts/src/operation-failure.ts +72 -1
  22. package/src/packages/contracts/src/organization-mcp-connections.ts +7 -0
  23. package/src/packages/contracts/src/problem-policy.ts +17 -5
  24. package/src/packages/contracts/src/secret-names.ts +10 -2
  25. package/src/packages/sdk-ts/package.json +1 -1
  26. package/src/packages/sdk-ts/src/generated/index.ts +36 -0
  27. package/src/packages/sdk-ts/src/generated/sdk.gen.ts +265 -1
  28. package/src/packages/sdk-ts/src/generated/types.gen.ts +445 -2
  29. package/src/packages/sdk-ts/src/managed-mail-response.ts +12 -0
  30. package/src/packages/sdk-ts/src/managed-mail.ts +10 -1
@@ -46,6 +46,8 @@ import {
46
46
  assertDatabaseWatchDeleted,
47
47
  assertDatabaseWatchPage,
48
48
  assertDatabaseWebhookTest,
49
+ assertDatabaseWebhookSubscription,
50
+ assertDatabaseWebhookSubscriptionActivation,
49
51
  type DatabaseExecutionUsagePage,
50
52
  type DatabaseSchedule,
51
53
  type DatabaseScheduleDeleted,
@@ -65,6 +67,9 @@ import {
65
67
  type DatabaseWebhookPage,
66
68
  type DatabaseWebhookReplayAccepted,
67
69
  type DatabaseWebhookTestResult,
70
+ type DatabaseWebhookCreateRequest,
71
+ type DatabaseWebhookSubscription,
72
+ type DatabaseWebhookSubscriptionActivation,
68
73
  } from "@ohmyhost/contracts/database-events";
69
74
  import type { DatabaseComputeSelection } from "@ohmyhost/contracts/database-sizes";
70
75
  import {
@@ -128,6 +133,7 @@ import {
128
133
  setProjectPoweredByFlag,
129
134
  createDeployment,
130
135
  createProject,
136
+ addProjectDevelopmentEnvironment,
131
137
  planProjectDataChange,
132
138
  createProjectDataChange,
133
139
  submitFeedback,
@@ -136,8 +142,13 @@ import {
136
142
  type Organization,
137
143
  type GithubConnectionAuthorization,
138
144
  type GithubOrganizationConnectionStatus,
145
+ type OrganizationMcpConnectionList,
146
+ type OrganizationMcpConnectionRevocation,
139
147
  connectGithubOrganization,
140
148
  getGithubOrganizationConnection,
149
+ disconnectGithubOrganization,
150
+ listOrganizationMcpConnections,
151
+ revokeOrganizationMcpConnection,
141
152
  deleteEnvironmentSecret,
142
153
  deleteProject,
143
154
  deletePaidProjectDomain,
@@ -170,6 +181,9 @@ import {
170
181
  listProjectDatabaseAccess,
171
182
  revokeProjectDatabaseAccess,
172
183
  createProjectDatabaseWebhook,
184
+ activateDatabaseWebhookSubscription,
185
+ deactivateDatabaseWebhookSubscription,
186
+ getDatabaseWebhookSubscription,
173
187
  listProjectDatabaseWebhooks,
174
188
  getProjectDatabaseWebhook,
175
189
  deleteProjectDatabaseWebhook,
@@ -227,10 +241,17 @@ export interface ProjectCreateInput {
227
241
  readonly name: string;
228
242
  readonly dataMode?: "shared" | "isolated";
229
243
  readonly devAccessMode?: "protected" | "public";
244
+ readonly includeDevelopmentEnvironment?: boolean;
230
245
  readonly region?: "us" | "eu";
231
246
  readonly idempotencyKey: string;
232
247
  }
233
248
 
249
+ interface WebhookSubscriptionScope {
250
+ readonly projectId: string;
251
+ readonly environment: "dev" | "prod";
252
+ readonly subscriptionId: string;
253
+ }
254
+
234
255
  /** One column of a table to create; nullable, identity and default are optional as the REST body allows. */
235
256
  export interface DatabaseTableColumnInput {
236
257
  readonly name: string;
@@ -395,6 +416,22 @@ export interface ProductApi {
395
416
  readonly eventTypes: readonly DatabaseWebhookEventPattern[];
396
417
  readonly headers: Readonly<Record<string, string>>;
397
418
  }): Promise<DatabaseWebhookCreated>;
419
+ getDatabaseWebhookSubscription(
420
+ input: WebhookSubscriptionScope,
421
+ ): Promise<DatabaseWebhookSubscription>;
422
+ activateDatabaseWebhookSubscription(
423
+ input: WebhookSubscriptionScope & {
424
+ readonly generation: number;
425
+ readonly idempotencyKey: string;
426
+ readonly request: DatabaseWebhookCreateRequest;
427
+ },
428
+ ): Promise<DatabaseWebhookSubscriptionActivation>;
429
+ deactivateDatabaseWebhookSubscription(
430
+ input: WebhookSubscriptionScope & {
431
+ readonly generation: number;
432
+ readonly idempotencyKey: string;
433
+ },
434
+ ): Promise<DatabaseWebhookSubscription>;
398
435
  listProjectDatabaseWebhooks(input: {
399
436
  readonly projectId: string;
400
437
  readonly environment: "dev" | "prod";
@@ -538,6 +575,10 @@ export interface ProductApi {
538
575
  cursor?: string,
539
576
  ): Promise<import("@ohmyhost/sdk-ts").FeedbackStatus>;
540
577
  createProject(input: ProjectCreateInput): Promise<Operation>;
578
+ addProjectDevelopmentEnvironment(input: {
579
+ readonly projectId: string;
580
+ readonly idempotencyKey: string;
581
+ }): Promise<Operation>;
541
582
  getOperation(operationId: string): Promise<Operation>;
542
583
  reconcileOperation(input: {
543
584
  readonly operationId: string;
@@ -548,6 +589,12 @@ export interface ProductApi {
548
589
  readonly idempotencyKey: string;
549
590
  }): Promise<GithubConnectionAuthorization>;
550
591
  getGithubConnection(organizationId: string): Promise<GithubOrganizationConnectionStatus>;
592
+ disconnectGithub(organizationId: string): Promise<GithubOrganizationConnectionStatus>;
593
+ listOrganizationMcpConnections(organizationId: string): Promise<OrganizationMcpConnectionList>;
594
+ revokeOrganizationMcpConnection(input: {
595
+ readonly organizationId: string;
596
+ readonly connectionId: string;
597
+ }): Promise<OrganizationMcpConnectionRevocation>;
551
598
  linkSource(input: {
552
599
  readonly projectId: string;
553
600
  readonly repositoryOwner: string;
@@ -574,7 +621,7 @@ export interface ProductApi {
574
621
  planDeployment(input: {
575
622
  readonly projectId: string;
576
623
  readonly commitSha: string;
577
- readonly environment: "dev" | "prod";
624
+ readonly environment?: "dev" | "prod";
578
625
  }): Promise<DeploymentPlan>;
579
626
  createDeployment(input: {
580
627
  readonly projectId: string;
@@ -1139,6 +1186,77 @@ export class GeneratedSdkProductApi implements ProductApi {
1139
1186
  return value;
1140
1187
  }
1141
1188
 
1189
+ public async getDatabaseWebhookSubscription(
1190
+ input: WebhookSubscriptionScope,
1191
+ ): Promise<DatabaseWebhookSubscription> {
1192
+ const value = await getDatabaseWebhookSubscription(
1193
+ {
1194
+ project_id: input.projectId,
1195
+ environment: input.environment,
1196
+ subscription_id: input.subscriptionId,
1197
+ },
1198
+ { client: this.#client },
1199
+ );
1200
+ assertDatabaseWebhookSubscription(value);
1201
+ if (value.id !== input.subscriptionId || value.environment !== input.environment)
1202
+ throw new TypeError(WEBHOOK_SCOPE_MISMATCH);
1203
+ return value;
1204
+ }
1205
+ public async activateDatabaseWebhookSubscription(
1206
+ input: WebhookSubscriptionScope & {
1207
+ generation: number;
1208
+ idempotencyKey: string;
1209
+ request: DatabaseWebhookCreateRequest;
1210
+ },
1211
+ ): Promise<DatabaseWebhookSubscriptionActivation> {
1212
+ const value = await activateDatabaseWebhookSubscription(
1213
+ {
1214
+ project_id: input.projectId,
1215
+ environment: input.environment,
1216
+ subscription_id: input.subscriptionId,
1217
+ generation: input.generation,
1218
+ "Idempotency-Key": input.idempotencyKey,
1219
+ databaseWebhookCreateRequest: {
1220
+ ...input.request,
1221
+ event_types: [...input.request.event_types],
1222
+ headers: { ...input.request.headers },
1223
+ },
1224
+ },
1225
+ { client: this.#client },
1226
+ );
1227
+ assertDatabaseWebhookSubscriptionActivation(value);
1228
+ if (
1229
+ value.id !== input.subscriptionId ||
1230
+ value.environment !== input.environment ||
1231
+ value.generation !== input.generation
1232
+ )
1233
+ throw new TypeError(WEBHOOK_SCOPE_MISMATCH);
1234
+ return value;
1235
+ }
1236
+ public async deactivateDatabaseWebhookSubscription(
1237
+ input: WebhookSubscriptionScope & { generation: number; idempotencyKey: string },
1238
+ ): Promise<DatabaseWebhookSubscription> {
1239
+ const value = await deactivateDatabaseWebhookSubscription(
1240
+ {
1241
+ project_id: input.projectId,
1242
+ environment: input.environment,
1243
+ subscription_id: input.subscriptionId,
1244
+ generation: input.generation,
1245
+ "Idempotency-Key": input.idempotencyKey,
1246
+ },
1247
+ { client: this.#client },
1248
+ );
1249
+ assertDatabaseWebhookSubscription(value);
1250
+ if (
1251
+ value.id !== input.subscriptionId ||
1252
+ value.environment !== input.environment ||
1253
+ value.generation !== input.generation ||
1254
+ value.state !== "inactive"
1255
+ )
1256
+ throw new TypeError(WEBHOOK_SCOPE_MISMATCH);
1257
+ return value;
1258
+ }
1259
+
1142
1260
  public async listProjectDatabaseWebhooks(
1143
1261
  input: Parameters<ProductApi["listProjectDatabaseWebhooks"]>[0],
1144
1262
  ): Promise<DatabaseWebhookPage> {
@@ -1509,6 +1627,9 @@ export class GeneratedSdkProductApi implements ProductApi {
1509
1627
  name: input.name,
1510
1628
  ...(input.dataMode === undefined ? {} : { data_mode: input.dataMode }),
1511
1629
  ...(input.devAccessMode === undefined ? {} : { dev_access_mode: input.devAccessMode }),
1630
+ ...(input.includeDevelopmentEnvironment === undefined
1631
+ ? {}
1632
+ : { include_development_environment: input.includeDevelopmentEnvironment }),
1512
1633
  ...(input.region === undefined ? {} : { region: input.region }),
1513
1634
  },
1514
1635
  },
@@ -1516,6 +1637,16 @@ export class GeneratedSdkProductApi implements ProductApi {
1516
1637
  );
1517
1638
  }
1518
1639
 
1640
+ public async addProjectDevelopmentEnvironment(input: {
1641
+ projectId: string;
1642
+ idempotencyKey: string;
1643
+ }): Promise<Operation> {
1644
+ return addProjectDevelopmentEnvironment(
1645
+ { project_id: input.projectId, "Idempotency-Key": input.idempotencyKey, body: {} },
1646
+ { client: this.#client },
1647
+ );
1648
+ }
1649
+
1519
1650
  public async getOperation(operationId: string): Promise<Operation> {
1520
1651
  return getOperation({ operation_id: operationId }, { client: this.#client });
1521
1652
  }
@@ -1556,6 +1687,34 @@ export class GeneratedSdkProductApi implements ProductApi {
1556
1687
  );
1557
1688
  }
1558
1689
 
1690
+ public async disconnectGithub(
1691
+ organizationId: string,
1692
+ ): Promise<GithubOrganizationConnectionStatus> {
1693
+ return disconnectGithubOrganization(
1694
+ { organization_id: organizationId },
1695
+ { client: this.#client },
1696
+ );
1697
+ }
1698
+
1699
+ public async listOrganizationMcpConnections(
1700
+ organizationId: string,
1701
+ ): Promise<OrganizationMcpConnectionList> {
1702
+ return listOrganizationMcpConnections(
1703
+ { organization_id: organizationId },
1704
+ { client: this.#client },
1705
+ );
1706
+ }
1707
+
1708
+ public async revokeOrganizationMcpConnection(input: {
1709
+ readonly organizationId: string;
1710
+ readonly connectionId: string;
1711
+ }): Promise<OrganizationMcpConnectionRevocation> {
1712
+ return revokeOrganizationMcpConnection(
1713
+ { organization_id: input.organizationId, connection_id: input.connectionId },
1714
+ { client: this.#client },
1715
+ );
1716
+ }
1717
+
1559
1718
  public async linkSource(input: {
1560
1719
  readonly projectId: string;
1561
1720
  readonly repositoryOwner: string;
@@ -1629,12 +1788,15 @@ export class GeneratedSdkProductApi implements ProductApi {
1629
1788
  public async planDeployment(input: {
1630
1789
  readonly projectId: string;
1631
1790
  readonly commitSha: string;
1632
- readonly environment: "dev" | "prod";
1791
+ readonly environment?: "dev" | "prod";
1633
1792
  }): Promise<DeploymentPlan> {
1634
1793
  return planDeployment(
1635
1794
  {
1636
1795
  project_id: input.projectId,
1637
- planDeploymentRequest: { commit_sha: input.commitSha, environment: input.environment },
1796
+ planDeploymentRequest: {
1797
+ commit_sha: input.commitSha,
1798
+ ...(input.environment === undefined ? {} : { environment: input.environment }),
1799
+ },
1638
1800
  },
1639
1801
  { client: this.#client },
1640
1802
  );
@@ -111,6 +111,10 @@ const MAIL_RUNTIME_BINDINGS = Object.freeze([
111
111
  "OHMYHOST_PROJECT_ID",
112
112
  ]);
113
113
  const AI_RUNTIME_BINDINGS = Object.freeze(["OHMYHOST_AI_BASE_URL", "OHMYHOST_AI_KEY"]);
114
+ const BROWSER_RUNTIME_BINDINGS = Object.freeze([
115
+ "OHMYHOST_BROWSER_BASE_URL",
116
+ "OHMYHOST_BROWSER_KEY",
117
+ ]);
114
118
  // The runtime release is published unchanged as `@amerged/ohmyhost-runtime`; this pinned alias keeps
115
119
  // its import name and, unlike the website archive each release removes, stays installable.
116
120
  const CUSTOMER_RUNTIME_SOURCE = `npm:@amerged/ohmyhost-runtime@${cliPackage.version}`;
@@ -384,6 +388,7 @@ export async function initializeRepository(
384
388
  // Mail stays an explicit choice: Better Auth or a detected mail package never enables it.
385
389
  const targetMail = existingConfiguration?.mail?.enabled === true;
386
390
  const targetAi = existingConfiguration?.ai?.enabled === true;
391
+ const targetBrowser = existingConfiguration?.browser?.enabled === true;
387
392
  const targetStorage = r2 || supabaseStorage;
388
393
  // TanStack Start binds storage only on edge, as a Vite app does through its companion.
389
394
  const tanStackRuntime =
@@ -432,6 +437,7 @@ export async function initializeRepository(
432
437
  auth: targetBetterAuth,
433
438
  mail: targetMail,
434
439
  ai: targetAi,
440
+ browser: targetBrowser,
435
441
  storage: targetStorage,
436
442
  });
437
443
  const companion = companionRequired
@@ -1618,6 +1624,7 @@ type RuntimeCapabilities = Readonly<{
1618
1624
  auth: boolean;
1619
1625
  mail: boolean;
1620
1626
  ai: boolean;
1627
+ browser: boolean;
1621
1628
  storage: boolean;
1622
1629
  }>;
1623
1630
 
@@ -1635,6 +1642,7 @@ function runtimeContract(capabilities: RuntimeCapabilities): Readonly<{
1635
1642
  ...(capabilities.database ? ["OHMYHOST_DATABASE"] : []),
1636
1643
  ...(capabilities.mail ? MAIL_RUNTIME_BINDINGS : []),
1637
1644
  ...(capabilities.ai ? AI_RUNTIME_BINDINGS : []),
1645
+ ...(capabilities.browser ? BROWSER_RUNTIME_BINDINGS : []),
1638
1646
  ]),
1639
1647
  ].sort(),
1640
1648
  ),
@@ -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,11 +21,14 @@ 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";
26
29
  import {
27
30
  publicOperationFailure,
31
+ parseMigrationFailureDiagnostic,
28
32
  publicOperationReconciliation,
29
33
  type PublicOperationFailure,
30
34
  type PublicOperationReconciliation,
@@ -331,6 +335,41 @@ export const parseGithubOrganizationConnectionStatus = (
331
335
  return input as unknown as GithubOrganizationConnectionStatus;
332
336
  };
333
337
 
338
+ export const parseOrganizationMcpConnectionList = (
339
+ value: unknown,
340
+ ): OrganizationMcpConnectionList => {
341
+ const input = exactRecord(value, ["connections"]);
342
+ if (!Array.isArray(input["connections"])) throw new ResponseContractError();
343
+ for (const item of input["connections"]) {
344
+ const connection = exactRecord(item, ["connection_id", "client_id", "user_id", "connected_at"]);
345
+ if (
346
+ typeof connection["connection_id"] !== "string" ||
347
+ !MCP_CONNECTION_ID_PATTERN.test(connection["connection_id"]) ||
348
+ !boundedString(connection["client_id"], 1, 2048) ||
349
+ !boundedString(connection["user_id"], 1, 256) ||
350
+ !isIsoInstant(connection["connected_at"])
351
+ )
352
+ throw new ResponseContractError();
353
+ }
354
+ return input as unknown as OrganizationMcpConnectionList;
355
+ };
356
+
357
+ export const parseOrganizationMcpConnectionRevocation = (
358
+ value: unknown,
359
+ ): OrganizationMcpConnectionRevocation => {
360
+ const input = exactRecord(value, ["state"]);
361
+ if (input["state"] !== "pending" && input["state"] !== "revoked")
362
+ throw new ResponseContractError();
363
+ return input as unknown as OrganizationMcpConnectionRevocation;
364
+ };
365
+
366
+ /** A disconnect answer that still reports a live connection did not disconnect, so it is refused. */
367
+ export const parseGithubDisconnection = (value: unknown): GithubOrganizationConnectionStatus => {
368
+ const status = parseGithubOrganizationConnectionStatus(value);
369
+ if (status.status === "connected") throw new ResponseContractError();
370
+ return status;
371
+ };
372
+
334
373
  export const parseGithubConnectionAuthorization = (
335
374
  value: unknown,
336
375
  ): GithubConnectionAuthorization => {
@@ -780,6 +819,7 @@ export const parseProjectStatus = (value: unknown): Readonly<Record<string, unkn
780
819
  "prod_url",
781
820
  "latest_operation",
782
821
  "cleanup_state",
822
+ "custom_domains",
783
823
  ]);
784
824
  const handle = input["handle"];
785
825
  if (
@@ -816,6 +856,19 @@ export const parseProjectStatus = (value: unknown): Readonly<Record<string, unkn
816
856
  }
817
857
  }
818
858
  if (input["head_deployment"] !== null) parseProjectDeployment(input["head_deployment"]);
859
+ if (input["custom_domains"] !== undefined) {
860
+ if (!Array.isArray(input["custom_domains"]) || input["custom_domains"].length > 64)
861
+ throw new ResponseContractError();
862
+ for (const raw of input["custom_domains"]) {
863
+ const domain = exactRecord(raw, ["hostname", "environment", "state"]);
864
+ if (
865
+ !isPaidHostname(domain["hostname"]) ||
866
+ domain["environment"] !== "prod" ||
867
+ !["awaiting_deployment", "pending", "active", "deleting"].includes(String(domain["state"]))
868
+ )
869
+ throw new ResponseContractError();
870
+ }
871
+ }
819
872
  if (input["environments"] !== undefined) {
820
873
  const environments = input["environments"];
821
874
  if (!Array.isArray(environments) || environments.length > 2) throw new ResponseContractError();
@@ -1480,22 +1533,45 @@ export const parseOperation = (value: unknown): PublicOperation => {
1480
1533
  * detail, and only an exact catalog sentence naming the refused file; it is rendered again here.
1481
1534
  */
1482
1535
  function parseOperationFailure(value: unknown): PublicOperationFailure {
1483
- const input = exactRecord(value, ["code", "message", "retryable", "suggested_action", "detail"]);
1536
+ const input = exactRecord(value, [
1537
+ "code",
1538
+ "message",
1539
+ "retryable",
1540
+ "suggested_action",
1541
+ "detail",
1542
+ "migration",
1543
+ ]);
1484
1544
  const detail = input["detail"];
1485
- const diagnostic =
1545
+ const framework =
1486
1546
  detail === undefined || input["code"] !== "auto_deploy_plan_rejected"
1487
1547
  ? null
1488
1548
  : frameworkConversionDiagnosticFromDetail(detail);
1549
+ const migration =
1550
+ input["migration"] === undefined ? null : parseMigrationFailureDiagnostic(input["migration"]);
1551
+ const normalize = (value: Record<string, unknown>) =>
1552
+ JSON.stringify(
1553
+ Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b))),
1554
+ );
1489
1555
  if (
1490
1556
  typeof input["code"] !== "string" ||
1491
1557
  !boundedString(input["message"], 1, 512) ||
1492
1558
  input["retryable"] !== false ||
1493
1559
  !boundedString(input["suggested_action"], 1, 500) ||
1494
- (detail !== undefined && diagnostic === null)
1560
+ (detail !== undefined && framework === null) ||
1561
+ (input["migration"] !== undefined &&
1562
+ (input["code"] !== "database_migration_failed" ||
1563
+ migration === null ||
1564
+ normalize(input["migration"] as Record<string, unknown>) !==
1565
+ normalize(migration as unknown as Record<string, unknown>)))
1566
+ )
1567
+ throw new ResponseContractError();
1568
+ const safe = publicOperationFailure(input["code"], migration ?? framework);
1569
+ if (
1570
+ safe.code !== input["code"] ||
1571
+ safe.detail !== detail ||
1572
+ JSON.stringify(safe.migration) !== JSON.stringify(migration ?? undefined)
1495
1573
  )
1496
1574
  throw new ResponseContractError();
1497
- const safe = publicOperationFailure(input["code"], diagnostic);
1498
- if (safe.code !== input["code"] || safe.detail !== detail) throw new ResponseContractError();
1499
1575
  return safe;
1500
1576
  }
1501
1577
 
@@ -27,6 +27,79 @@ export class UserTokenFileError extends Error {
27
27
  }
28
28
  }
29
29
 
30
+ export class PrivateSecretFileError extends Error {
31
+ readonly code = "private_output_invalid";
32
+ constructor() {
33
+ super(
34
+ "Choose a new private output file outside the repository or ignored by Git. Existing files and links are never replaced. After an uncertain activation, retry the same key and request with a new output file.",
35
+ );
36
+ }
37
+ }
38
+
39
+ /** Reserve a new owner-only secret file before a provider mutation. Existing paths are never changed. */
40
+ export async function preparePrivateSecretFile(output: string) {
41
+ const path = resolve(output);
42
+ let file: FileHandle | undefined;
43
+ try {
44
+ await requireIgnoredTokenFile(path);
45
+ file = await open(
46
+ path,
47
+ constants.O_RDWR | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0),
48
+ 0o600,
49
+ );
50
+ const handle = file;
51
+ await secureTokenFile(path, handle);
52
+ const identity = await handle.stat();
53
+ if (!identity.isFile() || identity.nlink !== 1 || identity.size !== 0)
54
+ throw new PrivateSecretFileError();
55
+ return {
56
+ path,
57
+ async save(value: string): Promise<void> {
58
+ try {
59
+ if (!/^[\x21-\x7e]{16,512}$/u.test(value)) throw new PrivateSecretFileError();
60
+ const current = await lstat(path),
61
+ before = await handle.stat();
62
+ if (
63
+ !current.isFile() ||
64
+ current.isSymbolicLink() ||
65
+ current.nlink !== 1 ||
66
+ current.ino !== identity.ino ||
67
+ current.dev !== identity.dev ||
68
+ before.size !== 0
69
+ )
70
+ throw new PrivateSecretFileError();
71
+ await handle.writeFile(value, "utf8");
72
+ await handle.sync();
73
+ const after = await lstat(path),
74
+ stored = Buffer.alloc(Buffer.byteLength(value));
75
+ try {
76
+ const read = await handle.read(stored, 0, stored.length, 0);
77
+ if (
78
+ !after.isFile() ||
79
+ after.isSymbolicLink() ||
80
+ after.nlink !== 1 ||
81
+ after.ino !== identity.ino ||
82
+ after.dev !== identity.dev ||
83
+ after.size !== stored.length ||
84
+ read.bytesRead !== stored.length ||
85
+ stored.toString("utf8") !== value
86
+ )
87
+ throw new PrivateSecretFileError();
88
+ } finally {
89
+ stored.fill(0);
90
+ }
91
+ } catch {
92
+ throw new PrivateSecretFileError();
93
+ }
94
+ },
95
+ close: () => handle.close(),
96
+ };
97
+ } catch {
98
+ await file?.close();
99
+ throw new PrivateSecretFileError();
100
+ }
101
+ }
102
+
30
103
  /** What to do next; once a key was issued, the answer names it so it can be revoked. */
31
104
  const tokenFileAction = (code: UserTokenFileError["code"], keyId: string | undefined): string => {
32
105
  switch (code) {
@@ -162,6 +162,11 @@
162
162
  "types": "./dist/secret-names.d.ts",
163
163
  "import": "./dist/secret-names.js"
164
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
+ },
165
170
  "./project-data-changes": {
166
171
  "source": "./src/project-data-changes.ts",
167
172
  "types": "./dist/project-data-changes.d.ts",
@@ -107,7 +107,7 @@ export function assertOrganizationCreditUsage(
107
107
  throw new TypeError("Invalid usage meter");
108
108
  if (
109
109
  typeof meter["quantity"] !== "string" ||
110
- !/^(0|[1-9][0-9]{0,29})(\.[0-9]{1,12})?$/u.test(meter["quantity"]) ||
110
+ !/^(0|[1-9][0-9]{0,29})(\.[0-9]{1,20})?$/u.test(meter["quantity"]) ||
111
111
  !amount(meter["charged_micros"])
112
112
  )
113
113
  throw new TypeError("Invalid usage amount");
@@ -140,6 +140,22 @@ export interface DatabaseWebhookCreated extends DatabaseWebhook {
140
140
  readonly secret: string;
141
141
  }
142
142
 
143
+ /** A client-owned subscription remains identifiable across confirmed deactivations. */
144
+ export interface DatabaseWebhookSubscription {
145
+ readonly id: string;
146
+ readonly environment: DatabaseEnvironment;
147
+ readonly state: "creating" | "active" | "deactivating" | "inactive";
148
+ readonly generation: number;
149
+ readonly provider_id: string | null;
150
+ }
151
+
152
+ /** Only an authenticated activation or its exact retry may reveal this generation's secret. */
153
+ export interface DatabaseWebhookSubscriptionActivation extends DatabaseWebhookSubscription {
154
+ readonly state: "active";
155
+ readonly provider_id: string;
156
+ readonly secret: string;
157
+ }
158
+
143
159
  export interface DatabaseWebhookPage {
144
160
  readonly items: readonly DatabaseWebhook[];
145
161
  }
@@ -281,6 +297,20 @@ export function parseDatabaseWebhookId(value: unknown): string {
281
297
  return value;
282
298
  }
283
299
 
300
+ export function parseDatabaseWebhookSubscriptionId(value: unknown): string {
301
+ if (!matches(value, /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/u))
302
+ throw new TypeError("Invalid database webhook subscription id");
303
+ return value;
304
+ }
305
+
306
+ export function parseDatabaseWebhookGeneration(value: unknown): number {
307
+ if (typeof value !== "string" || !/^[1-9][0-9]*$/u.test(value))
308
+ throw new TypeError("Invalid database webhook generation");
309
+ const generation = Number(value);
310
+ if (!Number.isSafeInteger(generation)) throw new TypeError("Invalid database webhook generation");
311
+ return generation;
312
+ }
313
+
284
314
  export function parseDatabaseWatchId(value: unknown): string {
285
315
  if (!isDatabaseWatchTriggerName(value)) throw new TypeError("Invalid database watch id");
286
316
  return value;
@@ -431,6 +461,43 @@ export function assertDatabaseWebhook(value: unknown): asserts value is Database
431
461
  assertWebhookFields(value);
432
462
  }
433
463
 
464
+ const SUBSCRIPTION_KEYS = ["id", "environment", "state", "generation", "provider_id"];
465
+ function assertSubscriptionFields(value: Record<string, unknown>): void {
466
+ if (
467
+ !matches(value["id"], /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/u) ||
468
+ !oneOf(["dev", "prod"] as const, value["environment"]) ||
469
+ !oneOf(["creating", "active", "deactivating", "inactive"] as const, value["state"]) ||
470
+ !Number.isSafeInteger(value["generation"]) ||
471
+ Number(value["generation"]) < 1 ||
472
+ !(value["provider_id"] === null || matches(value["provider_id"], WEBHOOK_ID_PATTERN)) ||
473
+ (value["state"] === "creating" && value["provider_id"] !== null) ||
474
+ ((value["state"] === "active" || value["state"] === "deactivating") &&
475
+ value["provider_id"] === null)
476
+ )
477
+ throw new TypeError("Invalid database webhook subscription");
478
+ }
479
+ export function assertDatabaseWebhookSubscription(
480
+ value: unknown,
481
+ ): asserts value is DatabaseWebhookSubscription {
482
+ if (!record(value) || !exact(value, SUBSCRIPTION_KEYS))
483
+ throw new TypeError("Invalid database webhook subscription");
484
+ assertSubscriptionFields(value);
485
+ }
486
+ export function assertDatabaseWebhookSubscriptionActivation(
487
+ value: unknown,
488
+ ): asserts value is DatabaseWebhookSubscriptionActivation {
489
+ if (!record(value) || !exact(value, [...SUBSCRIPTION_KEYS, "secret"]))
490
+ throw new TypeError("Invalid database webhook subscription activation");
491
+ assertSubscriptionFields(value);
492
+ if (
493
+ value["state"] !== "active" ||
494
+ value["provider_id"] === null ||
495
+ typeof value["secret"] !== "string" ||
496
+ !/^[\x21-\x7e]{16,512}$/u.test(value["secret"])
497
+ )
498
+ throw new TypeError("Invalid database webhook subscription activation");
499
+ }
500
+
434
501
  export function assertDatabaseWatch(value: unknown): asserts value is DatabaseWatch {
435
502
  if (
436
503
  !record(value) ||
@@ -518,8 +518,9 @@ const FRAMEWORK_CONVERSION_DETAILS = Object.freeze({
518
518
  text: {
519
519
  nextjs: "runtime.mode: edge",
520
520
  "vite-static":
521
- "runtime.mode: edge with src/ohmyhost/companion.ts when database, auth, mail, ai, storage or functions.crons is set, and static otherwise",
522
- "tanstack-start": "runtime.mode: edge, or static without functions.crons, storage and ai",
521
+ "runtime.mode: edge with src/ohmyhost/companion.ts when database, auth, mail, ai, browser, storage or functions.crons is set, and static otherwise",
522
+ "tanstack-start":
523
+ "runtime.mode: edge, or static without functions.crons, storage, ai and browser",
523
524
  astro: "runtime.mode: static for prerendered sites, or edge with the Cloudflare adapter",
524
525
  },
525
526
  },
@@ -550,7 +551,7 @@ const FRAMEWORK_CONVERSION_DETAILS = Object.freeze({
550
551
  build_option_unsupported: {
551
552
  paths: ["repository_config"],
552
553
  template:
553
- '"{{path}}" sets a build option this runtime ignores: build.ssg_cache_max_mib applies only to Next.js, and runtime.mode: functions takes only build.install. Remove the option, commit and push the change, then plan the new commit.',
554
+ '"{{path}}" sets a build option this runtime ignores: build.ssg_cache_max_mib and build.next_revalidate_path apply only to Next.js, and runtime.mode: functions takes only build.install. Remove the option, commit and push the change, then plan the new commit.',
554
555
  },
555
556
  application_root_missing: {
556
557
  paths: ["repository_config"],
@@ -589,7 +590,7 @@ const FRAMEWORK_CONVERSION_DETAILS = Object.freeze({
589
590
  companion_entry_required: {
590
591
  paths: ["module"],
591
592
  template:
592
- '"{{path}}" is missing. A Vite app with runtime.mode: edge or with database, auth, mail, ai, storage or functions.crons needs this Worker module with export default { fetch }. Add it, or use runtime.mode: static without those settings; commit and push the change, then plan the new commit.',
593
+ '"{{path}}" is missing. A Vite app with runtime.mode: edge or with database, auth, mail, ai, browser, storage or functions.crons needs this Worker module with export default { fetch }. Add it, or use runtime.mode: static without those settings; commit and push the change, then plan the new commit.',
593
594
  },
594
595
  worker_module_required: {
595
596
  paths: ["module"],