@amerged/ohmyhost-cli 0.1.53 → 0.1.55

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 (28) hide show
  1. package/README.md +1 -1
  2. package/dist/bin.js +1 -1
  3. package/dist/{chunk-7GS4HXFT.js → chunk-4OAAJX5B.js} +297 -54
  4. package/dist/index.js +1 -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 +70 -25
  8. package/src/apps/product-cli/src/command.ts +52 -5
  9. package/src/apps/product-cli/src/product-api.ts +36 -2
  10. package/src/apps/product-cli/src/repository-init.ts +46 -9
  11. package/src/apps/product-cli/src/runtime-contract.ts +14 -4
  12. package/src/packages/contracts/package.json +5 -5
  13. package/src/packages/contracts/src/database-events.ts +1 -0
  14. package/src/packages/contracts/src/database-migration-admission.ts +33 -3
  15. package/src/packages/contracts/src/database-migration-errors.ts +10 -2
  16. package/src/packages/contracts/src/feedback.ts +9 -0
  17. package/src/packages/contracts/src/framework-admission.ts +4 -0
  18. package/src/packages/contracts/src/framework-source-rules.ts +55 -0
  19. package/src/packages/contracts/src/operation-failure.ts +8 -0
  20. package/src/packages/contracts/src/problem-policy.ts +74 -2
  21. package/src/packages/contracts/src/project-exports.ts +30 -0
  22. package/src/packages/contracts/src/wfp-dispatch.ts +43 -0
  23. package/src/packages/sdk-ts/package.json +1 -1
  24. package/src/packages/sdk-ts/src/generated/index.ts +33 -0
  25. package/src/packages/sdk-ts/src/generated/sdk.gen.ts +253 -13
  26. package/src/packages/sdk-ts/src/generated/types.gen.ts +385 -11
  27. package/src/packages/workos-auth-contracts/src/webhooks.ts +7 -0
  28. package/src/packages/contracts/src/previews.ts +0 -179
package/dist/index.js CHANGED
@@ -102,7 +102,7 @@ import {
102
102
  selectWorkspace,
103
103
  verifiedUserId,
104
104
  workspaceOf
105
- } from "./chunk-7GS4HXFT.js";
105
+ } from "./chunk-4OAAJX5B.js";
106
106
  import {
107
107
  CredentialStoreIntegrityError,
108
108
  CredentialStoreUnavailableError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amerged/ohmyhost-cli",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohmyhost/product-cli",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
4
4
  "private": true,
5
5
  "ohmyhost": {
6
6
  "deployment": "production",
@@ -39,7 +39,12 @@ import {
39
39
  assertProjectContext,
40
40
  assertProjectNotesReceipt,
41
41
  } from "@ohmyhost/contracts/project-context";
42
- import { assertProjectExport } from "@ohmyhost/contracts/project-exports";
42
+ import {
43
+ assertProjectExport,
44
+ assertProjectExportDownloadLink,
45
+ EXPORT_PASSWORD_MIN_CHARACTERS,
46
+ exportPasswordMeetsMinimum,
47
+ } from "@ohmyhost/contracts/project-exports";
43
48
  import { prepareUserTokenFile, UserTokenFileError } from "./user-token-file.js";
44
49
  import { parseUserApiKeyPage } from "@ohmyhost/contracts/user-api-keys";
45
50
  import { assertOrganizationCreditUsage } from "@ohmyhost/contracts/credit-pricing";
@@ -350,7 +355,9 @@ const HELP_USAGE = Object.freeze({
350
355
  "export create":
351
356
  "ohmyhost export create --project ULID --idempotency-key KEY --stdin --json (password on stdin only; one accepted SQL ZIP per project per 24 hours)",
352
357
  "export get":
353
- "ohmyhost export get EXPORT_ULID --project ULID --json (poll the original job; signed ZIP download lasts 24 hours)",
358
+ "ohmyhost export get EXPORT_ULID --project ULID --json (poll the original job: progress and error only, never a download URL; once it succeeds, run 'ohmyhost export download-link' for the signed 24-hour ZIP link)",
359
+ "export download-link":
360
+ "ohmyhost export download-link EXPORT_ULID --project ULID --json (signs one audited 24-hour link of a succeeded SQL ZIP; the URL is a secret, keep it out of files and notes; each call signs another link)",
354
361
  "credits account": "ohmyhost credits account --organization ULID --json",
355
362
  "referral link":
356
363
  "ohmyhost referral link --organization ULID --json (the workspace's link to share; a new user whose first workspace comes from it starts with 30 days of Paid and 1,000 credits, and its first payment gives this workspace 1,000 credits plus 30 days of Paid unless a subscription or an unbounded grant already covers it)",
@@ -442,13 +449,13 @@ const HELP_USAGE = Object.freeze({
442
449
  "database webhook get":
443
450
  "ohmyhost database webhook get --project ULID [--environment dev|prod] --webhook ID --json",
444
451
  "database webhook delete":
445
- "ohmyhost database webhook delete --project ULID --environment dev|prod --webhook ID --yes --json",
452
+ "ohmyhost database webhook delete --project ULID --environment dev|prod --webhook ID [--idempotency-key KEY] --yes --json (a retry with the same key and request returns the stored answer; without a key each call is new)",
446
453
  "database webhook test":
447
- "ohmyhost database webhook test --project ULID --environment dev|prod --webhook ID --yes --json (sends one signed test request to the receiver; nothing is stored)",
454
+ "ohmyhost database webhook test --project ULID --environment dev|prod --webhook ID [--idempotency-key KEY] --yes --json (sends one signed test request to the receiver; nothing is stored; a retry with the same key and request returns the stored outcome without sending again)",
448
455
  "database webhook deliveries":
449
456
  "ohmyhost database webhook deliveries --project ULID [--environment dev|prod] [--webhook ID] [--limit 1..100] [--cursor CURSOR] --json",
450
457
  "database webhook replay":
451
- "ohmyhost database webhook replay --project ULID --environment dev|prod --delivery ID --yes --json",
458
+ "ohmyhost database webhook replay --project ULID --environment dev|prod --delivery ID [--idempotency-key KEY] --yes --json (a retry with the same key and request returns the stored answer without queuing another attempt)",
452
459
  "database schedule set":
453
460
  "ohmyhost database schedule set --project ULID --environment dev|prod --name NAME (--cron EXPR | --every-seconds N) --statements-file PATH [--timeout-ms N] [--enabled true|false] --yes --json (runs the statements in the file, a UTF-8 JSON array of 1 to 20 SQL strings, as the runtime role of the application; cron has five fields in UTC; every-seconds is 60 to 2678400; timeout-ms is 1000 to 30000, default 10000). A project whose Stop budget is reached has its schedules disabled automatically, within about an hour of the billed usage reaching the budget: the credit service does this after its hourly pgcf pass, and Continue budgets are never touched. While the budget is reached, schedule set with enabled true and schedule run are refused with project_budget_exceeded (HTTP 402). Re-enabling is manual: raise the budget (or wait for the next UTC month) and run database schedule set --enabled true again with the schedule body (read it with schedule get).",
454
461
  "database schedule list":
@@ -460,7 +467,7 @@ const HELP_USAGE = Object.freeze({
460
467
  "database schedule runs":
461
468
  "ohmyhost database schedule runs --project ULID [--environment dev|prod] --name NAME [--limit 1..50] --json",
462
469
  "database schedule run":
463
- "ohmyhost database schedule run --project ULID --environment dev|prod --name NAME --yes --json (queues one run now, in addition to the timer; refused with project_budget_exceeded (HTTP 402) while the project's Stop budget is reached)",
470
+ "ohmyhost database schedule run --project ULID --environment dev|prod --name NAME [--idempotency-key KEY] --yes --json (queues one run now, in addition to the timer; a retry with the same key and request returns the stored answer without a second run; refused with project_budget_exceeded (HTTP 402) while the project's Stop budget is reached)",
464
471
  "database executions":
465
472
  "ohmyhost database executions --project ULID [--environment dev|prod] --from ISO --to ISO --granularity hour|day [--limit 1..100] [--cursor CURSOR] --json (UTC timestamps like 2026-10-30T00:00:00.000Z aligned to the granularity, at most 31 days; counts schedule runs, webhook attempts and events per hour or day; these are counters only, executions have no price of their own and the awake compute time of the database is what is billed)",
466
473
  "database psql":
@@ -639,11 +646,11 @@ export const invalidCommandAction = (argv: readonly string[], commandPrefix: str
639
646
  * (--yes but no key) may already have applied its change, so its state is read first. Any other
640
647
  * command only reads or signs in; it keeps the general advice.
641
648
  */
642
- const retryAdvice = (command: string): string => {
649
+ const retryAdvice = (command: string, keyed = true): string => {
643
650
  const usage = Object.hasOwn(HELP_USAGE, command)
644
651
  ? HELP_USAGE[command as CustomerCommandLabel]
645
652
  : "";
646
- if (usage.includes("--idempotency-key"))
653
+ if (keyed && usage.includes("--idempotency-key"))
647
654
  return "run the same command again with the same --idempotency-key; the change may already have been applied, and a new key could apply it twice";
648
655
  if (usage.includes("--yes"))
649
656
  return "this command has no idempotency key and the change may already have been applied; check its current state first with the matching list or get command (for example database access list --project ULID --json), and run the command again only if the change is not there";
@@ -651,18 +658,18 @@ const retryAdvice = (command: string): string => {
651
658
  };
652
659
 
653
660
  /** The next step after an unexpected client failure; the stderr diagnostic line identifies it. */
654
- export const internalErrorAction = (command: string): string =>
655
- `The ohmyhost client stopped on an unexpected error; the stderr line starting with [ohmyhost: identifies it. Compare 'ohmyhost --version' with https://ohmyho.st/client-release.json and install the published client if it is older, then ${retryAdvice(command)}. If the current client fails the same way, report it with feedback submit (kind bug, error code internal_error) and quote that stderr line.`;
661
+ export const internalErrorAction = (command: string, keyed = true): string =>
662
+ `The ohmyhost client stopped on an unexpected error; the stderr line starting with [ohmyhost: identifies it. Compare 'ohmyhost --version' with https://ohmyho.st/client-release.json and install the published client if it is older, then ${retryAdvice(command, keyed)}. If the current client fails the same way, report it with feedback submit (kind bug, error code internal_error) and quote that stderr line.`;
656
663
 
657
664
  /** The local credential store or saved-login index failed; a sandbox is the usual cause. */
658
665
  export const CREDENTIAL_STORE_UNAVAILABLE_ACTION =
659
666
  "This computer's credential store (for example macOS Keychain or Windows Credential Manager) or the saved-login list in ~/.ohmyhost/profiles could not be read or written; nothing was changed. If the agent runs in a sandbox, run the command with access to them before asking the customer to sign in again. If the store is locked, ask the customer to unlock it, then run the command again. On a server, container or CI runner without a credential store, do not run login: load OHMYHOST_TOKEN from a private env file with a token from the portal's API Tokens page.";
660
667
 
661
- const responseContractAction = (command: string): string =>
662
- `The ohmyho.st API answered in a form this client version does not accept, usually because the client is older than the service. Compare 'ohmyhost --version' with https://ohmyho.st/client-release.json; if it is older, install the published CLI and MCP and reload MCP. Then ${retryAdvice(command)}. If the current version answers this too, report it with feedback submit (kind bug, error code response_contract_invalid).`;
668
+ const responseContractAction = (command: string, keyed = true): string =>
669
+ `The ohmyho.st API answered in a form this client version does not accept, usually because the client is older than the service. Compare 'ohmyhost --version' with https://ohmyho.st/client-release.json; if it is older, install the published CLI and MCP and reload MCP. Then ${retryAdvice(command, keyed)}. If the current version answers this too, report it with feedback submit (kind bug, error code response_contract_invalid).`;
663
670
 
664
- const requestTimeoutAction = (command: string): string =>
665
- `The ohmyho.st API did not answer within 30 seconds; ${retryAdvice(command)}.`;
671
+ const requestTimeoutAction = (command: string, keyed = true): string =>
672
+ `The ohmyho.st API did not answer within 30 seconds; ${retryAdvice(command, keyed)}.`;
666
673
 
667
674
  const LOGOUT_UNCONFIRMED_ACTION =
668
675
  "The saved login was removed from this computer, but ohmyho.st did not confirm that its session ended. Running logout again cannot retry this, because the login is gone; do not sign in again just to revoke it. Tell the customer the session end was not confirmed.";
@@ -1044,7 +1051,11 @@ export class ProductCli {
1044
1051
  if (command.kind === "export-create") {
1045
1052
  const api = await this.authenticatedApi(command.credentialStore, signal);
1046
1053
  const password = await this.dependencies.readSecretValue(signal);
1047
- if (password.trim().length === 0 || new TextEncoder().encode(password).length > 1024)
1054
+ if (
1055
+ password.trim().length === 0 ||
1056
+ new TextEncoder().encode(password).length > 1024 ||
1057
+ !exportPasswordMeetsMinimum(password)
1058
+ )
1048
1059
  throw new SecretInputError();
1049
1060
  const operation = parseOperation(
1050
1061
  await api.createProjectExport({
@@ -1064,6 +1075,15 @@ export class ProductCli {
1064
1075
  assertProjectExport(result);
1065
1076
  return success("export get", { status: result.state, export: result });
1066
1077
  }
1078
+ if (command.kind === "export-download-link") {
1079
+ const api = await this.authenticatedApi(command.credentialStore, signal);
1080
+ const link = await api.createProjectExportDownloadLink({
1081
+ projectId: command.projectId,
1082
+ exportId: command.exportId,
1083
+ });
1084
+ assertProjectExportDownloadLink(link);
1085
+ return success("export download-link", { status: "succeeded", download_link: link });
1086
+ }
1067
1087
  if (command.kind === "feedback-status") {
1068
1088
  const api = await this.authenticatedApi(command.credentialStore, signal);
1069
1089
  const feedback = await api.getFeedback(command.feedbackId, command.cursor);
@@ -1328,7 +1348,14 @@ export class ProductCli {
1328
1348
  profileLimitAction(this.dependencies.commandPrefix),
1329
1349
  );
1330
1350
  this.recordDiagnostic(diagnosticDescriptor(error, signal));
1331
- return classifyFailure(name, error, signal, this.context());
1351
+ return classifyFailure(
1352
+ name,
1353
+ error,
1354
+ signal,
1355
+ this.context(),
1356
+ // A mutation parsed without its optional --idempotency-key has no key to repeat with.
1357
+ !("idempotencyKey" in command && command.idempotencyKey === null),
1358
+ );
1332
1359
  }
1333
1360
  }
1334
1361
 
@@ -2113,6 +2140,7 @@ export class ProductCli {
2113
2140
  projectId: command.projectId,
2114
2141
  environment: command.environment,
2115
2142
  webhookId: command.webhookId,
2143
+ ...(command.idempotencyKey === null ? {} : { idempotencyKey: command.idempotencyKey }),
2116
2144
  });
2117
2145
  return success("database webhook delete", { status: "succeeded", deleted });
2118
2146
  }
@@ -2126,6 +2154,7 @@ export class ProductCli {
2126
2154
  projectId: command.projectId,
2127
2155
  environment: command.environment,
2128
2156
  webhookId: command.webhookId,
2157
+ ...(command.idempotencyKey === null ? {} : { idempotencyKey: command.idempotencyKey }),
2129
2158
  });
2130
2159
  return success("database webhook test", { status: "succeeded", result });
2131
2160
  }
@@ -2158,6 +2187,7 @@ export class ProductCli {
2158
2187
  projectId: command.projectId,
2159
2188
  environment: command.environment,
2160
2189
  deliveryId: command.deliveryId,
2190
+ ...(command.idempotencyKey === null ? {} : { idempotencyKey: command.idempotencyKey }),
2161
2191
  });
2162
2192
  return success("database webhook replay", { status: "succeeded", replay });
2163
2193
  }
@@ -2239,6 +2269,7 @@ export class ProductCli {
2239
2269
  projectId: command.projectId,
2240
2270
  environment: command.environment,
2241
2271
  name: command.name,
2272
+ ...(command.idempotencyKey === null ? {} : { idempotencyKey: command.idempotencyKey }),
2242
2273
  });
2243
2274
  return success("database schedule run", { status: "succeeded", run });
2244
2275
  }
@@ -3258,6 +3289,7 @@ const classifyFailure = (
3258
3289
  error: unknown,
3259
3290
  signal: AbortSignal,
3260
3291
  actingAs?: Readonly<Record<string, unknown>>,
3292
+ keyed = true,
3261
3293
  ): CliResult => {
3262
3294
  if (error instanceof LocalSourcePublicationError)
3263
3295
  return failure(
@@ -3276,16 +3308,16 @@ const classifyFailure = (
3276
3308
  130,
3277
3309
  "command_cancelled",
3278
3310
  true,
3279
- `The command was stopped by an interrupt or termination signal, for example the shell's command timeout, before it finished; ${retryAdvice(command)}. Give login and commands with --wait or --follow several minutes, or run them in the background.`,
3311
+ `The command was stopped by an interrupt or termination signal, for example the shell's command timeout, before it finished; ${retryAdvice(command, keyed)}. Give login and commands with --wait or --follow several minutes, or run them in the background.`,
3280
3312
  );
3281
3313
  }
3282
3314
  if (isTimeout(error)) {
3283
- return failure(command, 8, "request_timeout", true, requestTimeoutAction(command));
3315
+ return failure(command, 8, "request_timeout", true, requestTimeoutAction(command, keyed));
3284
3316
  }
3285
3317
  // A retryable request_timeout is a token refresh that timed out inside this command; the logout
3286
3318
  // timeout is not retryable and keeps its own advice.
3287
3319
  if (error instanceof ProductCliFailure && error.code === "request_timeout" && error.retryable) {
3288
- return failure(command, 8, "request_timeout", true, requestTimeoutAction(command));
3320
+ return failure(command, 8, "request_timeout", true, requestTimeoutAction(command, keyed));
3289
3321
  }
3290
3322
  if (error instanceof ProductCliFailure) {
3291
3323
  return failure(
@@ -3304,7 +3336,7 @@ const classifyFailure = (
3304
3336
  "secret_input_invalid",
3305
3337
  false,
3306
3338
  command === "export create"
3307
- ? "Pipe the ZIP password through standard input: non-blank UTF-8 of at most 1024 bytes. A final line break becomes part of the password."
3339
+ ? `Pipe the ZIP password through standard input: at least ${EXPORT_PASSWORD_MIN_CHARACTERS} characters, non-blank UTF-8 of at most 1024 bytes. A final line break becomes part of the password.`
3308
3340
  : "Pipe a non-empty UTF-8 value of at most 5120 bytes through standard input.",
3309
3341
  );
3310
3342
  }
@@ -3345,7 +3377,13 @@ const classifyFailure = (
3345
3377
  );
3346
3378
  }
3347
3379
  if (error instanceof ResponseContractError) {
3348
- return failure(command, 7, "response_contract_invalid", false, responseContractAction(command));
3380
+ return failure(
3381
+ command,
3382
+ 7,
3383
+ "response_contract_invalid",
3384
+ false,
3385
+ responseContractAction(command, keyed),
3386
+ );
3349
3387
  }
3350
3388
  if (error instanceof PublicResponseTooLargeError) {
3351
3389
  return failure(
@@ -3378,12 +3416,18 @@ const classifyFailure = (
3378
3416
  7,
3379
3417
  "response_contract_invalid",
3380
3418
  false,
3381
- responseContractAction(command),
3419
+ responseContractAction(command, keyed),
3382
3420
  );
3383
3421
  }
3384
3422
  }
3385
3423
  if (looksLikeRemoteObject(error)) {
3386
- return failure(command, 7, "response_contract_invalid", false, responseContractAction(command));
3424
+ return failure(
3425
+ command,
3426
+ 7,
3427
+ "response_contract_invalid",
3428
+ false,
3429
+ responseContractAction(command, keyed),
3430
+ );
3387
3431
  }
3388
3432
  if (error instanceof NetworkTransportError) {
3389
3433
  return failure(
@@ -3391,10 +3435,10 @@ const classifyFailure = (
3391
3435
  8,
3392
3436
  "network_error",
3393
3437
  true,
3394
- `The request did not reach the ohmyho.st API, or its answer was cut off. If the agent runs in a sandbox without network access, run the command with network access. Otherwise ${retryAdvice(command)}.`,
3438
+ `The request did not reach the ohmyho.st API, or its answer was cut off. If the agent runs in a sandbox without network access, run the command with network access. Otherwise ${retryAdvice(command, keyed)}.`,
3395
3439
  );
3396
3440
  }
3397
- return failure(command, 1, "internal_error", false, internalErrorAction(command));
3441
+ return failure(command, 1, "internal_error", false, internalErrorAction(command, keyed));
3398
3442
  };
3399
3443
 
3400
3444
  /** A 409 idempotency_key_reused problem, with what its answer carries. */
@@ -3631,6 +3675,7 @@ const parsedCommandName = (command: ProductCliCommand): CommandLabel => {
3631
3675
  if (command.kind === "source-read") return `source ${command.action}`;
3632
3676
  if (command.kind === "export-create") return "export create";
3633
3677
  if (command.kind === "export-get") return "export get";
3678
+ if (command.kind === "export-download-link") return "export download-link";
3634
3679
  if (command.kind === "token-create") return "token create";
3635
3680
  if (command.kind === "token-list") return "token list";
3636
3681
  if (command.kind === "token-revoke") return "token revoke";
@@ -164,6 +164,12 @@ export type ProductCliCommand =
164
164
  readonly exportId: string;
165
165
  readonly credentialStore: "native";
166
166
  }
167
+ | {
168
+ readonly kind: "export-download-link";
169
+ readonly projectId: string;
170
+ readonly exportId: string;
171
+ readonly credentialStore: "native";
172
+ }
167
173
  | {
168
174
  readonly kind: "token-create";
169
175
  readonly organizationId: string;
@@ -485,6 +491,7 @@ export type ProductCliCommand =
485
491
  readonly projectId: string;
486
492
  readonly environment: "dev" | "prod";
487
493
  readonly webhookId: string;
494
+ readonly idempotencyKey: string | null;
488
495
  readonly yes: true;
489
496
  readonly credentialStore: "native";
490
497
  }
@@ -493,6 +500,7 @@ export type ProductCliCommand =
493
500
  readonly projectId: string;
494
501
  readonly environment: "dev" | "prod";
495
502
  readonly webhookId: string;
503
+ readonly idempotencyKey: string | null;
496
504
  readonly yes: true;
497
505
  readonly credentialStore: "native";
498
506
  }
@@ -510,6 +518,7 @@ export type ProductCliCommand =
510
518
  readonly projectId: string;
511
519
  readonly environment: "dev" | "prod";
512
520
  readonly deliveryId: string;
521
+ readonly idempotencyKey: string | null;
513
522
  readonly yes: true;
514
523
  readonly credentialStore: "native";
515
524
  }
@@ -560,6 +569,7 @@ export type ProductCliCommand =
560
569
  readonly projectId: string;
561
570
  readonly environment: "dev" | "prod";
562
571
  readonly name: string;
572
+ readonly idempotencyKey: string | null;
563
573
  readonly yes: true;
564
574
  readonly credentialStore: "native";
565
575
  }
@@ -1008,6 +1018,7 @@ export type RecognizedCommandLabel =
1008
1018
  | "project notes set"
1009
1019
  | "export create"
1010
1020
  | "export get"
1021
+ | "export download-link"
1011
1022
  | "billing recharge get"
1012
1023
  | "billing recharge set"
1013
1024
  | "billing checkout"
@@ -1181,7 +1192,10 @@ export const recognizedCommandLabel = (argv: readonly string[]): RecognizedComma
1181
1192
  if (value === "operation" && values[0] === "reconcile") return "operation reconcile";
1182
1193
  if (value === "token" && ["create", "list", "revoke"].includes(values[0] ?? ""))
1183
1194
  return `token ${values[0]}` as RecognizedCommandLabel;
1184
- if (value === "export" && (values[0] === "create" || values[0] === "get"))
1195
+ if (
1196
+ value === "export" &&
1197
+ (values[0] === "create" || values[0] === "get" || values[0] === "download-link")
1198
+ )
1185
1199
  return `export ${values[0]}`;
1186
1200
  if (value === "feedback" && values[0] === "submit") return "feedback submit";
1187
1201
  if (value === "feedback" && values[0] === "status") return "feedback status";
@@ -2552,10 +2566,16 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
2552
2566
  }
2553
2567
  if (subcommand === "delete" || subcommand === "test") {
2554
2568
  if (!yes || wait || follow || revoke || stdin) throw new InvalidCommandError();
2555
- const options = parseOptionalOptions(values, ["--project", "--environment", "--webhook"]);
2569
+ const options = parseOptionalOptions(values, [
2570
+ "--project",
2571
+ "--environment",
2572
+ "--webhook",
2573
+ "--idempotency-key",
2574
+ ]);
2556
2575
  const projectId = options["--project"],
2557
2576
  environment = options["--environment"],
2558
- webhookId = options["--webhook"];
2577
+ webhookId = options["--webhook"],
2578
+ idempotencyKey = options["--idempotency-key"] ?? null;
2559
2579
  if (!isValue(projectId)) throw new InvalidCommandError();
2560
2580
  if (environment !== "dev" && environment !== "prod") throw new InvalidCommandError();
2561
2581
  const target = contractValue(() => parseDatabaseWebhookId(webhookId));
@@ -2565,6 +2585,7 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
2565
2585
  projectId,
2566
2586
  environment,
2567
2587
  webhookId: target,
2588
+ idempotencyKey,
2568
2589
  yes: true,
2569
2590
  credentialStore,
2570
2591
  };
@@ -2573,6 +2594,7 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
2573
2594
  projectId,
2574
2595
  environment,
2575
2596
  webhookId: target,
2597
+ idempotencyKey,
2576
2598
  yes: true,
2577
2599
  credentialStore,
2578
2600
  };
@@ -2611,7 +2633,12 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
2611
2633
  }
2612
2634
  if (subcommand === "replay") {
2613
2635
  if (!yes || wait || follow || revoke || stdin) throw new InvalidCommandError();
2614
- const options = parseOptionalOptions(values, ["--project", "--environment", "--delivery"]);
2636
+ const options = parseOptionalOptions(values, [
2637
+ "--project",
2638
+ "--environment",
2639
+ "--delivery",
2640
+ "--idempotency-key",
2641
+ ]);
2615
2642
  const projectId = options["--project"],
2616
2643
  environment = options["--environment"],
2617
2644
  deliveryId = options["--delivery"];
@@ -2622,6 +2649,7 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
2622
2649
  projectId,
2623
2650
  environment,
2624
2651
  deliveryId: contractValue(() => parseDatabaseDeliveryId(deliveryId)),
2652
+ idempotencyKey: options["--idempotency-key"] ?? null,
2625
2653
  yes: true,
2626
2654
  credentialStore,
2627
2655
  };
@@ -2723,7 +2751,12 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
2723
2751
  }
2724
2752
  if (subcommand === "delete" || subcommand === "run") {
2725
2753
  if (!yes || wait || follow || revoke || stdin) throw new InvalidCommandError();
2726
- const options = parseOptionalOptions(values, ["--project", "--environment", "--name"]);
2754
+ const options = parseOptionalOptions(
2755
+ values,
2756
+ subcommand === "run"
2757
+ ? ["--project", "--environment", "--name", "--idempotency-key"]
2758
+ : ["--project", "--environment", "--name"],
2759
+ );
2727
2760
  const projectId = options["--project"],
2728
2761
  environment = options["--environment"];
2729
2762
  if (!isValue(projectId) || (environment !== "dev" && environment !== "prod"))
@@ -2743,6 +2776,7 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
2743
2776
  projectId,
2744
2777
  environment,
2745
2778
  name,
2779
+ idempotencyKey: options["--idempotency-key"] ?? null,
2746
2780
  yes: true,
2747
2781
  credentialStore,
2748
2782
  };
@@ -3087,6 +3121,19 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
3087
3121
  const options = parseOptions(values, ["--project"]);
3088
3122
  return { kind: "export-get", projectId: options["--project"], exportId, credentialStore };
3089
3123
  }
3124
+ if (first === "export" && values[0] === "download-link") {
3125
+ if (yes || wait || follow || stdin) throw new InvalidCommandError();
3126
+ values.shift();
3127
+ const exportId = values.shift();
3128
+ if (!exportId) throw new InvalidCommandError();
3129
+ const options = parseOptions(values, ["--project"]);
3130
+ return {
3131
+ kind: "export-download-link",
3132
+ projectId: options["--project"],
3133
+ exportId,
3134
+ credentialStore,
3135
+ };
3136
+ }
3090
3137
  if (first === "secret" && values[0] === "list") {
3091
3138
  if (yes || wait || follow || stdin) throw new InvalidCommandError();
3092
3139
  values.shift();
@@ -1,3 +1,4 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  import {
2
3
  executeManagedMail,
3
4
  executeSharedMail,
@@ -72,7 +73,12 @@ import {
72
73
  type ProjectContext,
73
74
  type ProjectNotesReceipt,
74
75
  } from "@ohmyhost/contracts/project-context";
75
- import { assertProjectExport, type ProjectExport } from "@ohmyhost/contracts/project-exports";
76
+ import {
77
+ assertProjectExport,
78
+ assertProjectExportDownloadLink,
79
+ type ProjectExport,
80
+ type ProjectExportDownloadLink,
81
+ } from "@ohmyhost/contracts/project-exports";
76
82
  import {
77
83
  parseUserApiKeyCreation,
78
84
  parseUserApiKeyPage,
@@ -88,6 +94,7 @@ import {
88
94
  createClient,
89
95
  createProjectExport,
90
96
  getProjectExport,
97
+ createProjectExportDownloadLink,
91
98
  createUserApiKey,
92
99
  listUserApiKeys,
93
100
  revokeUserApiKey,
@@ -295,6 +302,10 @@ export interface ProductApi {
295
302
  idempotencyKey: string;
296
303
  }): Promise<Operation>;
297
304
  getProjectExport(input: { projectId: string; exportId: string }): Promise<ProjectExport>;
305
+ createProjectExportDownloadLink(input: {
306
+ projectId: string;
307
+ exportId: string;
308
+ }): Promise<ProjectExportDownloadLink>;
298
309
  createUserApiKey(input: {
299
310
  organizationId: string;
300
311
  name: string;
@@ -397,11 +408,14 @@ export interface ProductApi {
397
408
  readonly projectId: string;
398
409
  readonly environment: "dev" | "prod";
399
410
  readonly webhookId: string;
411
+ /** One new key per call when absent; the same key retries the same request and gets its stored answer. */
412
+ readonly idempotencyKey?: string;
400
413
  }): Promise<DatabaseWebhookDeleted>;
401
414
  testProjectDatabaseWebhook(input: {
402
415
  readonly projectId: string;
403
416
  readonly environment: "dev" | "prod";
404
417
  readonly webhookId: string;
418
+ readonly idempotencyKey?: string;
405
419
  }): Promise<DatabaseWebhookTestResult>;
406
420
  createProjectDatabaseWatch(input: {
407
421
  readonly projectId: string;
@@ -436,6 +450,7 @@ export interface ProductApi {
436
450
  readonly projectId: string;
437
451
  readonly environment: "dev" | "prod";
438
452
  readonly deliveryId: string;
453
+ readonly idempotencyKey?: string;
439
454
  }): Promise<DatabaseWebhookReplayAccepted>;
440
455
  setProjectDatabaseSchedule(input: {
441
456
  readonly projectId: string;
@@ -467,6 +482,7 @@ export interface ProductApi {
467
482
  readonly projectId: string;
468
483
  readonly environment: "dev" | "prod";
469
484
  readonly name: string;
485
+ readonly idempotencyKey?: string;
470
486
  }): Promise<DatabaseScheduleRunAccepted>;
471
487
  getProjectDatabaseExecutionUsage(input: {
472
488
  readonly projectId: string;
@@ -777,6 +793,16 @@ export class GeneratedSdkProductApi implements ProductApi {
777
793
  assertProjectExport(result);
778
794
  return result;
779
795
  }
796
+ public async createProjectExportDownloadLink(
797
+ input: Parameters<ProductApi["createProjectExportDownloadLink"]>[0],
798
+ ) {
799
+ const result = await createProjectExportDownloadLink(
800
+ { project_id: input.projectId, export_id: input.exportId },
801
+ { client: this.#client },
802
+ );
803
+ assertProjectExportDownloadLink(result);
804
+ return result;
805
+ }
780
806
  public async getCurrentIdentity(): Promise<CurrentIdentity> {
781
807
  return getCurrentIdentity({}, { client: this.#client });
782
808
  }
@@ -1148,6 +1174,7 @@ export class GeneratedSdkProductApi implements ProductApi {
1148
1174
  ): Promise<DatabaseWebhookDeleted> {
1149
1175
  const value = await deleteProjectDatabaseWebhook(
1150
1176
  {
1177
+ "Idempotency-Key": input.idempotencyKey ?? randomUUID(),
1151
1178
  project_id: input.projectId,
1152
1179
  environment: input.environment,
1153
1180
  webhook_id: input.webhookId,
@@ -1164,6 +1191,7 @@ export class GeneratedSdkProductApi implements ProductApi {
1164
1191
  ): Promise<DatabaseWebhookTestResult> {
1165
1192
  const value = await testProjectDatabaseWebhook(
1166
1193
  {
1194
+ "Idempotency-Key": input.idempotencyKey ?? randomUUID(),
1167
1195
  project_id: input.projectId,
1168
1196
  environment: input.environment,
1169
1197
  webhook_id: input.webhookId,
@@ -1201,6 +1229,7 @@ export class GeneratedSdkProductApi implements ProductApi {
1201
1229
  ): Promise<DatabaseWebhookReplayAccepted> {
1202
1230
  const value = await replayProjectDatabaseWebhookDelivery(
1203
1231
  {
1232
+ "Idempotency-Key": input.idempotencyKey ?? randomUUID(),
1204
1233
  project_id: input.projectId,
1205
1234
  environment: input.environment,
1206
1235
  delivery_id: input.deliveryId,
@@ -1299,7 +1328,12 @@ export class GeneratedSdkProductApi implements ProductApi {
1299
1328
  input: Parameters<ProductApi["runProjectDatabaseSchedule"]>[0],
1300
1329
  ): Promise<DatabaseScheduleRunAccepted> {
1301
1330
  const value = await runProjectDatabaseSchedule(
1302
- { project_id: input.projectId, environment: input.environment, name: input.name },
1331
+ {
1332
+ "Idempotency-Key": input.idempotencyKey ?? randomUUID(),
1333
+ project_id: input.projectId,
1334
+ environment: input.environment,
1335
+ name: input.name,
1336
+ },
1303
1337
  { client: this.#client },
1304
1338
  );
1305
1339
  assertDatabaseScheduleRunAccepted(value);
@@ -23,7 +23,9 @@ import {
23
23
  import {
24
24
  databaseContractCodes,
25
25
  declaredDependencyNames,
26
+ importsSocketPrimitive,
26
27
  isDatabaseContractModule,
28
+ isSocketPrimitiveModule,
27
29
  MANAGED_BETTER_AUTH_VERSION,
28
30
  packageManagerDeclaration,
29
31
  parsePackageManifest,
@@ -79,11 +81,15 @@ const GATEWAY_BINDING_NAME = /^OHMYHOST_(?:MAIL|STORAGE)_GATEWAY$/u;
79
81
  const GATEWAY_WORD_TOKEN = /[\p{ID_Start}_$][\p{ID_Continue}$]*/uy;
80
82
  // The catalog names a module only by a path of its grammar; a file name with a space, for example,
81
83
  // is not one, so its blocker carries the path beside a sentence that does not quote it.
82
- const UNNAMED_MODULE_MESSAGES: Readonly<Record<DatabaseContractCode, string>> = Object.freeze({
84
+ const UNNAMED_MODULE_MESSAGES: Readonly<
85
+ Record<DatabaseContractCode | "socket_primitive_unsupported", string>
86
+ > = Object.freeze({
83
87
  database_binding_private:
84
88
  'The module at path reads a database connection string (DATABASE_URL, HYPERDRIVE, connectionString or a postgres:// URL); none reaches a customer Worker. Call the database with createPrivateDatabaseClient from "@ohmyhost/customer-runtime/database". Commit and push the change, then plan the new commit.',
85
89
  database_driver_unsupported:
86
90
  'The module at 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". Commit and push the change, then plan the new commit.',
91
+ socket_primitive_unsupported:
92
+ "The module at 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. Commit and push the change, then plan the new commit.",
87
93
  });
88
94
 
89
95
  // Only a call constructs the client; a comment or a type-only import never does.
@@ -538,6 +544,7 @@ async function judgeSource(
538
544
  ...source.findings.map((finding) => requiredCatalogBlocker(finding, context.applicationRoot)),
539
545
  ...(await workerModuleBlockers(context)),
540
546
  ...(await databaseContractBlockers(context, context.provider)),
547
+ ...(await socketPrimitiveBlockers(context)),
541
548
  ...(await gatewayBindingBlockers(context)),
542
549
  ...(await storageClientBlockers(context)),
543
550
  ...(await migrationSqlBlockers(context, context.provider)),
@@ -837,14 +844,44 @@ async function databaseContractBlockers(
837
844
  const information = await stat(absolute);
838
845
  if (!information.isFile() || information.size > MAXIMUM_SOURCE_BYTES) continue;
839
846
  for (const code of databaseContractCodes(await readFile(absolute, "utf8")))
840
- blockers.push(
841
- catalogBlocker({ code, path }, context.applicationRoot) ??
842
- Object.freeze({
843
- code,
844
- path: repositoryPath(context.applicationRoot, path),
845
- message: UNNAMED_MODULE_MESSAGES[code],
846
- }),
847
- );
847
+ blockers.push(moduleBlocker(code, path, context.applicationRoot));
848
+ }
849
+ return blockers;
850
+ }
851
+
852
+ /** The blocker of a module refused by a code of the catalog's module grammar. */
853
+ function moduleBlocker(
854
+ code: keyof typeof UNNAMED_MODULE_MESSAGES,
855
+ path: string,
856
+ applicationRoot: ApplicationRoot,
857
+ ): RepositoryInitBlocker {
858
+ return (
859
+ catalogBlocker({ code, path }, applicationRoot) ??
860
+ Object.freeze({
861
+ code,
862
+ path: repositoryPath(applicationRoot, path),
863
+ message: UNNAMED_MODULE_MESSAGES[code],
864
+ })
865
+ );
866
+ }
867
+
868
+ /**
869
+ * A customer Worker opens no raw TCP socket: only fetch() passes the egress policy. Planning parses
870
+ * the reachable modules and refuses `cloudflare:sockets` whatever the configuration. Init cannot
871
+ * parse (the CLI denies `@babel/`), so its early hint lists every module whose raw text names the
872
+ * quoted specifier, reachable or not and comments included, with or without the database.
873
+ */
874
+ async function socketPrimitiveBlockers(
875
+ context: SourceCheckContext,
876
+ ): Promise<RepositoryInitBlocker[]> {
877
+ const blockers: RepositoryInitBlocker[] = [];
878
+ for (const path of context.files) {
879
+ if (!isSocketPrimitiveModule(path)) continue;
880
+ const absolute = resolve(context.applicationDirectory, path);
881
+ const information = await stat(absolute);
882
+ if (!information.isFile() || information.size > MAXIMUM_SOURCE_BYTES) continue;
883
+ if (importsSocketPrimitive(await readFile(absolute, "utf8")))
884
+ blockers.push(moduleBlocker("socket_primitive_unsupported", path, context.applicationRoot));
848
885
  }
849
886
  return blockers;
850
887
  }