@amerged/ohmyhost-cli 0.1.64 → 0.1.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-RW66TG5O.js → chunk-WV6POHNU.js} +534 -162
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/apps/product-cli/package.json +1 -1
- package/src/apps/product-cli/src/cli.ts +131 -16
- package/src/apps/product-cli/src/command.ts +88 -13
- package/src/apps/product-cli/src/composition.ts +4 -4
- package/src/apps/product-cli/src/product-api.ts +25 -2
- package/src/apps/product-cli/src/psql-session.ts +31 -1
- package/src/apps/product-cli/src/runtime-contract.ts +65 -0
- package/src/packages/contracts/package.json +5 -0
- package/src/packages/contracts/src/browser-capabilities.ts +2 -0
- package/src/packages/contracts/src/credit-pricing.ts +1 -1
- package/src/packages/contracts/src/database-compute.ts +3 -50
- package/src/packages/contracts/src/database-migration-admission.ts +70 -7
- package/src/packages/contracts/src/database-migration-lexical.ts +20 -5
- package/src/packages/contracts/src/egress-origin.ts +48 -0
- package/src/packages/contracts/src/framework-admission.ts +7 -1
- package/src/packages/contracts/src/framework-source-rules.ts +132 -3
- package/src/packages/contracts/src/index.ts +3 -72
- package/src/packages/contracts/src/managed-sources.ts +16 -1
- package/src/packages/contracts/src/operation-deployment-result.ts +2 -2
- package/src/packages/contracts/src/operation-failure.ts +10 -6
- package/src/packages/contracts/src/problem-policy.ts +57 -2
- package/src/packages/contracts/src/secret-names.ts +3 -1
- package/src/packages/sdk-ts/package.json +1 -1
- package/src/packages/sdk-ts/src/generated/index.ts +2 -0
- package/src/packages/sdk-ts/src/generated/mcp-remote.gen.ts +29734 -0
- package/src/packages/sdk-ts/src/generated/sdk.gen.ts +22 -6
- package/src/packages/sdk-ts/src/generated/types.gen.ts +96 -62
- package/src/packages/sdk-ts/src/index.ts +1 -0
- package/src/packages/sdk-ts/src/managed-mail.ts +3 -0
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -139,6 +139,9 @@ import {
|
|
|
139
139
|
type PublicEnvironmentSecret,
|
|
140
140
|
parseOperation,
|
|
141
141
|
parseOperationEvent,
|
|
142
|
+
parseDeploymentPage,
|
|
143
|
+
parseDeploymentRecord,
|
|
144
|
+
parseProjectCreateAccepted,
|
|
142
145
|
parseProjectPage,
|
|
143
146
|
parseProjectStatus,
|
|
144
147
|
parseProjectSourceBinding,
|
|
@@ -281,7 +284,11 @@ export interface ProductCliDependencies {
|
|
|
281
284
|
readonly currentIdentity?: (accessToken: () => Promise<string>) => Promise<unknown>;
|
|
282
285
|
readonly deviceFlow: WorkosDeviceFlowClient;
|
|
283
286
|
readonly deviceAuthorizationPresenter: DeviceAuthorizationPresenter;
|
|
284
|
-
|
|
287
|
+
/** The optional parent signal bounds only the requests of that API; by default the process signal does. */
|
|
288
|
+
readonly productApi: (
|
|
289
|
+
accessToken: () => Promise<string>,
|
|
290
|
+
parentSignal?: AbortSignal,
|
|
291
|
+
) => ProductApi;
|
|
285
292
|
/**
|
|
286
293
|
* Reads the signed-in customer's workspaces through a separate read-only dependency,
|
|
287
294
|
* keeping product mutation capabilities out of login.
|
|
@@ -549,7 +556,11 @@ const HELP_USAGE = Object.freeze({
|
|
|
549
556
|
deploy:
|
|
550
557
|
"ohmyhost deploy --project ULID (--plan-id ULID | --commit SHA [--environment dev|prod]) --idempotency-key KEY --yes [--wait] --json",
|
|
551
558
|
logs: "ohmyhost logs OPERATION_ULID --follow --json",
|
|
552
|
-
"deployment
|
|
559
|
+
"deployment list":
|
|
560
|
+
"ohmyhost deployment list --project ULID [--cursor CURSOR] [--limit 1-100] --json (newest first; a returned deployment ULID is a rollback target)",
|
|
561
|
+
"deployment get": "ohmyhost deployment get --project ULID --deployment ULID --json",
|
|
562
|
+
"deployment logs":
|
|
563
|
+
"ohmyhost deployment logs --project ULID --deployment ULID [--cursor CURSOR] --json (one page of diagnostics, newest first; a next_cursor in the answer reads the older page)",
|
|
553
564
|
"rollback plan": "ohmyhost rollback plan --project ULID --deployment DEPLOYMENT_ULID --json",
|
|
554
565
|
rollback:
|
|
555
566
|
"ohmyhost rollback --project ULID --deployment DEPLOYMENT_ULID --if-match ETAG --confirmation-token TOKEN --idempotency-key KEY --yes --json",
|
|
@@ -634,9 +645,18 @@ const HELP_COMMANDS = Object.freeze(
|
|
|
634
645
|
const helpEntries = (topic: string | undefined) => {
|
|
635
646
|
if (topic === undefined) return HELP_COMMANDS;
|
|
636
647
|
const exact = HELP_COMMANDS.filter((entry) => entry.command === topic);
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
648
|
+
if (exact.length > 0) return exact;
|
|
649
|
+
const under = HELP_COMMANDS.filter((entry) => entry.command.startsWith(`${topic} `));
|
|
650
|
+
if (under.length > 0) return under;
|
|
651
|
+
// A deeper subcommand, such as `auth users list`, is documented by its longest leading group, `auth`.
|
|
652
|
+
const words = topic.split(" ");
|
|
653
|
+
const group = HELP_COMMANDS.filter((entry) => {
|
|
654
|
+
const entryWords = entry.command.split(" ");
|
|
655
|
+
return (
|
|
656
|
+
entryWords.length <= words.length && entryWords.every((word, index) => word === words[index])
|
|
657
|
+
);
|
|
658
|
+
}).sort((left, right) => right.command.split(" ").length - left.command.split(" ").length);
|
|
659
|
+
return group.slice(0, 1);
|
|
640
660
|
};
|
|
641
661
|
|
|
642
662
|
export const helpTopicKnown = (topic: string): boolean => helpEntries(topic).length > 0;
|
|
@@ -671,6 +691,8 @@ export const invalidCommandAction = (argv: readonly string[], commandPrefix: str
|
|
|
671
691
|
const usage = Object.hasOwn(HELP_USAGE, label)
|
|
672
692
|
? HELP_USAGE[label as CustomerCommandLabel].split("\n")[0]
|
|
673
693
|
: undefined;
|
|
694
|
+
if (label === "help")
|
|
695
|
+
return "Unknown help topic; nothing was sent. 'ohmyhost --help --json' lists every command with its flags.";
|
|
674
696
|
if (usage === undefined)
|
|
675
697
|
return "Unknown command; nothing was sent. 'ohmyhost --help --json' lists every command with its flags. If a documented command is missing, this CLI is older than https://ohmyho.st/client-release.json: install the published version.";
|
|
676
698
|
// A required --project may come from this checkout's link; an optional one never needs it.
|
|
@@ -1416,6 +1438,8 @@ export class ProductCli {
|
|
|
1416
1438
|
if (command.kind === "deploy") return await this.deploy(command, signal);
|
|
1417
1439
|
if (command.kind === "logs") return await this.logs(command, signal);
|
|
1418
1440
|
if (command.kind === "deployment-logs") return await this.deploymentLogs(command, signal);
|
|
1441
|
+
if (command.kind === "deployment-list") return await this.listDeployments(command, signal);
|
|
1442
|
+
if (command.kind === "deployment-get") return await this.getDeployment(command, signal);
|
|
1419
1443
|
if (command.kind === "rollback-plan") return await this.planRollback(command, signal);
|
|
1420
1444
|
if (command.kind === "rollback") return await this.rollback(command, signal);
|
|
1421
1445
|
if (command.kind === "promotion-plan") return await this.planPromotion(command, signal);
|
|
@@ -2028,7 +2052,7 @@ export class ProductCli {
|
|
|
2028
2052
|
signal: AbortSignal,
|
|
2029
2053
|
): Promise<CliResult> {
|
|
2030
2054
|
const api = await this.authenticatedApi(command.credentialStore, signal);
|
|
2031
|
-
const
|
|
2055
|
+
const accepted = parseProjectCreateAccepted(
|
|
2032
2056
|
await api.createProject({
|
|
2033
2057
|
organizationId: command.organizationId,
|
|
2034
2058
|
name: command.name,
|
|
@@ -2041,7 +2065,12 @@ export class ProductCli {
|
|
|
2041
2065
|
idempotencyKey: command.idempotencyKey,
|
|
2042
2066
|
}),
|
|
2043
2067
|
);
|
|
2044
|
-
return success("project create", {
|
|
2068
|
+
return success("project create", {
|
|
2069
|
+
status: "accepted",
|
|
2070
|
+
project_id: accepted.project_id,
|
|
2071
|
+
operation: accepted.operation,
|
|
2072
|
+
next_action: `Run '${this.dependencies.commandPrefix} operation get ${accepted.operation.id} --json' until it succeeds; the new project is ${accepted.project_id}. A retry with the same idempotency key returns the same project_id.`,
|
|
2073
|
+
});
|
|
2045
2074
|
}
|
|
2046
2075
|
|
|
2047
2076
|
private async listProjects(
|
|
@@ -2518,6 +2547,13 @@ export class ProductCli {
|
|
|
2518
2547
|
const { connection_uri, psql_command, ...access } = credential;
|
|
2519
2548
|
void connection_uri;
|
|
2520
2549
|
void psql_command;
|
|
2550
|
+
// The revoke runs on its own bounded requests: Ctrl-C or SIGTERM must not cancel the cleanup.
|
|
2551
|
+
const cleanupSignal = new AbortController().signal;
|
|
2552
|
+
const cleanup = this.dependencies.productApi(
|
|
2553
|
+
() => this.authenticatedToken(command.credentialStore, cleanupSignal),
|
|
2554
|
+
cleanupSignal,
|
|
2555
|
+
);
|
|
2556
|
+
const revokeAction = `The temporary credential could not be revoked. Run '${this.dependencies.commandPrefix} database access revoke --project ${command.projectId} --access ${credential.access_id} --yes --json' now; it expires on its own at ${credential.expires_at}.`;
|
|
2521
2557
|
let exitCode: number;
|
|
2522
2558
|
try {
|
|
2523
2559
|
exitCode = await spawnPsql({
|
|
@@ -2530,13 +2566,20 @@ export class ProductCli {
|
|
|
2530
2566
|
signal,
|
|
2531
2567
|
});
|
|
2532
2568
|
} catch (error) {
|
|
2533
|
-
await this.revokeIssuedAccess(
|
|
2569
|
+
const revoked = await this.revokeIssuedAccess(
|
|
2570
|
+
cleanup,
|
|
2571
|
+
command.projectId,
|
|
2572
|
+
credential.access_id,
|
|
2573
|
+
);
|
|
2534
2574
|
if (error instanceof PsqlUnavailableError) return psqlUnavailable();
|
|
2575
|
+
if (!revoked && (signal.aborted || isCancellation(error)))
|
|
2576
|
+
return failure("database psql", 130, "command_cancelled", true, revokeAction);
|
|
2535
2577
|
throw error;
|
|
2536
2578
|
}
|
|
2537
|
-
await this.revokeIssuedAccess(
|
|
2579
|
+
const revoked = await this.revokeIssuedAccess(cleanup, command.projectId, credential.access_id);
|
|
2580
|
+
const notRevoked = revoked ? {} : { next_action: revokeAction };
|
|
2538
2581
|
if (exitCode === 0)
|
|
2539
|
-
return success("database psql", { status: "succeeded", access, exit_code: 0 });
|
|
2582
|
+
return success("database psql", { status: "succeeded", access, exit_code: 0, ...notRevoked });
|
|
2540
2583
|
return {
|
|
2541
2584
|
exitCode,
|
|
2542
2585
|
stdout: `${JSON.stringify({
|
|
@@ -2546,8 +2589,9 @@ export class ProductCli {
|
|
|
2546
2589
|
error: {
|
|
2547
2590
|
code: "psql_failed",
|
|
2548
2591
|
retryable: false,
|
|
2549
|
-
suggested_action:
|
|
2550
|
-
"Read the psql output above. The temporary credential was revoked; request a new one with 'ohmyhost database access create'."
|
|
2592
|
+
suggested_action: revoked
|
|
2593
|
+
? "Read the psql output above. The temporary credential was revoked; request a new one with 'ohmyhost database access create'."
|
|
2594
|
+
: revokeAction,
|
|
2551
2595
|
},
|
|
2552
2596
|
})}\n`,
|
|
2553
2597
|
stderr: "",
|
|
@@ -2558,11 +2602,12 @@ export class ProductCli {
|
|
|
2558
2602
|
api: ProductApi,
|
|
2559
2603
|
projectId: string,
|
|
2560
2604
|
accessId: string,
|
|
2561
|
-
): Promise<
|
|
2605
|
+
): Promise<boolean> {
|
|
2562
2606
|
try {
|
|
2563
2607
|
await api.revokeProjectDatabaseAccess({ projectId, accessId });
|
|
2608
|
+
return true;
|
|
2564
2609
|
} catch {
|
|
2565
|
-
|
|
2610
|
+
return false;
|
|
2566
2611
|
}
|
|
2567
2612
|
}
|
|
2568
2613
|
|
|
@@ -2988,7 +3033,9 @@ export class ProductCli {
|
|
|
2988
3033
|
status: command.wait ? "completed" : "accepted",
|
|
2989
3034
|
operation,
|
|
2990
3035
|
...(plan === null ? {} : { plan }),
|
|
2991
|
-
|
|
3036
|
+
// The note is conditional ("if this is a Dev deployment"), so a --plan-id deploy, whose environment the CLI
|
|
3037
|
+
// cannot read, gets it too. A plan known to target Prod gets none.
|
|
3038
|
+
...(notes.length > 0 && (plan === null || plan["environment"] === "dev") ? { notes } : {}),
|
|
2992
3039
|
});
|
|
2993
3040
|
}
|
|
2994
3041
|
|
|
@@ -3038,6 +3085,32 @@ export class ProductCli {
|
|
|
3038
3085
|
operation,
|
|
3039
3086
|
);
|
|
3040
3087
|
}
|
|
3088
|
+
private async listDeployments(
|
|
3089
|
+
command: Extract<ProductCliCommand, { kind: "deployment-list" }>,
|
|
3090
|
+
signal: AbortSignal,
|
|
3091
|
+
): Promise<CliResult> {
|
|
3092
|
+
const api = await this.authenticatedApi(command.credentialStore, signal);
|
|
3093
|
+
const page = parseDeploymentPage(
|
|
3094
|
+
await api.listDeployments({
|
|
3095
|
+
projectId: command.projectId,
|
|
3096
|
+
...(command.cursor === undefined ? {} : { cursor: command.cursor }),
|
|
3097
|
+
...(command.limit === undefined ? {} : { limit: command.limit }),
|
|
3098
|
+
}),
|
|
3099
|
+
);
|
|
3100
|
+
return success("deployment list", { items: page.items, next_cursor: page.next_cursor });
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
private async getDeployment(
|
|
3104
|
+
command: Extract<ProductCliCommand, { kind: "deployment-get" }>,
|
|
3105
|
+
signal: AbortSignal,
|
|
3106
|
+
): Promise<CliResult> {
|
|
3107
|
+
const api = await this.authenticatedApi(command.credentialStore, signal);
|
|
3108
|
+
const deployment = parseDeploymentRecord(
|
|
3109
|
+
await api.getDeployment({ projectId: command.projectId, deploymentId: command.deploymentId }),
|
|
3110
|
+
);
|
|
3111
|
+
return success("deployment get", { deployment });
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3041
3114
|
private async deploymentLogs(
|
|
3042
3115
|
command: Extract<ProductCliCommand, { kind: "deployment-logs" }>,
|
|
3043
3116
|
signal: AbortSignal,
|
|
@@ -3049,10 +3122,15 @@ export class ProductCli {
|
|
|
3049
3122
|
projectId: command.projectId,
|
|
3050
3123
|
deploymentId: command.deploymentId,
|
|
3051
3124
|
limit: 100,
|
|
3125
|
+
...(command.cursor === undefined ? {} : { cursor: command.cursor }),
|
|
3052
3126
|
});
|
|
3053
3127
|
for (const item of page.items)
|
|
3054
3128
|
this.dependencies.operationEventSink?.write(`${JSON.stringify(item)}\n`);
|
|
3055
|
-
return success("deployment logs", {
|
|
3129
|
+
return success("deployment logs", {
|
|
3130
|
+
status: "completed",
|
|
3131
|
+
event_count: page.items.length,
|
|
3132
|
+
...(page.next_cursor === undefined ? {} : { next_cursor: page.next_cursor }),
|
|
3133
|
+
});
|
|
3056
3134
|
}
|
|
3057
3135
|
|
|
3058
3136
|
private async planRollback(
|
|
@@ -3598,6 +3676,14 @@ const classifyFailure = (
|
|
|
3598
3676
|
"Retry only after the remote response is repaired.",
|
|
3599
3677
|
);
|
|
3600
3678
|
}
|
|
3679
|
+
if (isLocalFileError(error))
|
|
3680
|
+
return failure(
|
|
3681
|
+
command,
|
|
3682
|
+
2,
|
|
3683
|
+
"local_state_unavailable",
|
|
3684
|
+
false,
|
|
3685
|
+
`The local CLI state could not be read or written (${error.code}). Check the permissions and free space of the local directories named in the error, then retry. A remote change that already succeeded is not undone.`,
|
|
3686
|
+
);
|
|
3601
3687
|
if (looksLikeProblem(error)) {
|
|
3602
3688
|
try {
|
|
3603
3689
|
const problem = parseSafeProblem(error);
|
|
@@ -4016,6 +4102,8 @@ const parsedCommandName = (command: ProductCliCommand): CommandLabel => {
|
|
|
4016
4102
|
if (command.kind === "rollback-plan") return "rollback plan";
|
|
4017
4103
|
if (command.kind === "promotion-plan") return "deployment promote plan";
|
|
4018
4104
|
if (command.kind === "deployment-logs") return "deployment logs";
|
|
4105
|
+
if (command.kind === "deployment-list") return "deployment list";
|
|
4106
|
+
if (command.kind === "deployment-get") return "deployment get";
|
|
4019
4107
|
if (command.kind === "promote") return "deployment promote";
|
|
4020
4108
|
if (command.kind === "delete-plan") return "delete plan";
|
|
4021
4109
|
if (command.kind === "secret-list") return "secret list";
|
|
@@ -4076,6 +4164,31 @@ const looksLikeProblem = (error: unknown): boolean =>
|
|
|
4076
4164
|
error !== null &&
|
|
4077
4165
|
("code" in error || "status" in error || "suggested_action" in error);
|
|
4078
4166
|
|
|
4167
|
+
/**
|
|
4168
|
+
* Node filesystem errors describe local state, never a remote response. Network codes such as ECONNRESET or EPIPE
|
|
4169
|
+
* are not local; ENOENT is local only when it names the path that is missing.
|
|
4170
|
+
*/
|
|
4171
|
+
const LOCAL_FILE_ERROR_CODES: ReadonlySet<string> = new Set([
|
|
4172
|
+
"EACCES",
|
|
4173
|
+
"EPERM",
|
|
4174
|
+
"ENOSPC",
|
|
4175
|
+
"EROFS",
|
|
4176
|
+
"EDQUOT",
|
|
4177
|
+
"EMFILE",
|
|
4178
|
+
"ENFILE",
|
|
4179
|
+
"EEXIST",
|
|
4180
|
+
"EISDIR",
|
|
4181
|
+
"ENOTDIR",
|
|
4182
|
+
"EBUSY",
|
|
4183
|
+
"ENAMETOOLONG",
|
|
4184
|
+
]);
|
|
4185
|
+
const isLocalFileError = (error: unknown): error is Error & { code: string } =>
|
|
4186
|
+
error instanceof Error &&
|
|
4187
|
+
"code" in error &&
|
|
4188
|
+
typeof error.code === "string" &&
|
|
4189
|
+
(LOCAL_FILE_ERROR_CODES.has(error.code) ||
|
|
4190
|
+
(error.code === "ENOENT" && "path" in error && typeof error.path === "string"));
|
|
4191
|
+
|
|
4079
4192
|
const looksLikeRemoteObject = (error: unknown): boolean =>
|
|
4080
4193
|
typeof error === "object" && error !== null && !(error instanceof Error);
|
|
4081
4194
|
|
|
@@ -4140,6 +4253,8 @@ const diagnosticDescriptor = (
|
|
|
4140
4253
|
};
|
|
4141
4254
|
}
|
|
4142
4255
|
}
|
|
4256
|
+
if (isLocalFileError(error))
|
|
4257
|
+
return { category: "configuration", subsystem: "runtime", errorKind: "unavailable" };
|
|
4143
4258
|
if (looksLikeProblem(error)) {
|
|
4144
4259
|
try {
|
|
4145
4260
|
parseSafeProblem(error);
|
|
@@ -774,7 +774,20 @@ export type ProductCliCommand =
|
|
|
774
774
|
readonly kind: "deployment-logs";
|
|
775
775
|
readonly projectId: string;
|
|
776
776
|
readonly deploymentId: string;
|
|
777
|
-
readonly
|
|
777
|
+
readonly cursor?: string;
|
|
778
|
+
readonly credentialStore: "native";
|
|
779
|
+
}
|
|
780
|
+
| {
|
|
781
|
+
readonly kind: "deployment-list";
|
|
782
|
+
readonly projectId: string;
|
|
783
|
+
readonly cursor?: string;
|
|
784
|
+
readonly limit?: number;
|
|
785
|
+
readonly credentialStore: "native";
|
|
786
|
+
}
|
|
787
|
+
| {
|
|
788
|
+
readonly kind: "deployment-get";
|
|
789
|
+
readonly projectId: string;
|
|
790
|
+
readonly deploymentId: string;
|
|
778
791
|
readonly credentialStore: "native";
|
|
779
792
|
}
|
|
780
793
|
| {
|
|
@@ -1112,7 +1125,7 @@ function parseSourceCommand(values: string[], wait: boolean): SourceCliCommand {
|
|
|
1112
1125
|
(operationId === undefined || !/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/u.test(operationId)))
|
|
1113
1126
|
)
|
|
1114
1127
|
throw new InvalidCommandError();
|
|
1115
|
-
const limit = options["--limit"] === undefined ? undefined :
|
|
1128
|
+
const limit = options["--limit"] === undefined ? undefined : decimalLimit(options["--limit"]);
|
|
1116
1129
|
if (limit !== undefined && (!Number.isSafeInteger(limit) || limit < 1 || limit > 100))
|
|
1117
1130
|
throw new InvalidCommandError();
|
|
1118
1131
|
return {
|
|
@@ -1250,6 +1263,8 @@ export type RecognizedCommandLabel =
|
|
|
1250
1263
|
| "deploy"
|
|
1251
1264
|
| "logs"
|
|
1252
1265
|
| "deployment logs"
|
|
1266
|
+
| "deployment list"
|
|
1267
|
+
| "deployment get"
|
|
1253
1268
|
| "rollback plan"
|
|
1254
1269
|
| "rollback"
|
|
1255
1270
|
| "deployment promote plan"
|
|
@@ -1483,6 +1498,8 @@ export const recognizedCommandLabel = (argv: readonly string[]): RecognizedComma
|
|
|
1483
1498
|
if (value === "deployment" && values[0] === "promote")
|
|
1484
1499
|
return values[1] === "plan" ? "deployment promote plan" : "deployment promote";
|
|
1485
1500
|
if (value === "deployment" && values[0] === "logs") return "deployment logs";
|
|
1501
|
+
if (value === "deployment" && values[0] === "list") return "deployment list";
|
|
1502
|
+
if (value === "deployment" && values[0] === "get") return "deployment get";
|
|
1486
1503
|
if (value === "delete") return values[0] === "plan" ? "delete plan" : "delete";
|
|
1487
1504
|
if (value === "secret") {
|
|
1488
1505
|
if (values[0] === "list") return "secret list";
|
|
@@ -1718,7 +1735,7 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
|
|
|
1718
1735
|
...(options["--client-id"] ? { clientId: options["--client-id"] } : {}),
|
|
1719
1736
|
};
|
|
1720
1737
|
else if (actionKey === "users_list") {
|
|
1721
|
-
const limit = options["--limit"] === undefined ? undefined :
|
|
1738
|
+
const limit = options["--limit"] === undefined ? undefined : decimalLimit(options["--limit"]);
|
|
1722
1739
|
if (limit !== undefined && (!Number.isInteger(limit) || limit < 1 || limit > 100))
|
|
1723
1740
|
throw new InvalidCommandError();
|
|
1724
1741
|
request = {
|
|
@@ -1865,7 +1882,7 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
|
|
|
1865
1882
|
name.length > 64 ||
|
|
1866
1883
|
/\p{Cc}/u.test(name) ||
|
|
1867
1884
|
!idempotencyKey ||
|
|
1868
|
-
|
|
1885
|
+
!IDEMPOTENCY_KEY.test(idempotencyKey) ||
|
|
1869
1886
|
!outputPath
|
|
1870
1887
|
)
|
|
1871
1888
|
throw new InvalidCommandError();
|
|
@@ -2108,7 +2125,7 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
|
|
|
2108
2125
|
if (!/^(0|[1-9][0-9]{0,12})(\.[0-9]{1,6})?$/u.test(value)) throw new InvalidCommandError();
|
|
2109
2126
|
const [whole, fraction = ""] = value.split(".");
|
|
2110
2127
|
const amount = BigInt(whole ?? "0") * 1_000_000n + BigInt(fraction.padEnd(6, "0"));
|
|
2111
|
-
if (amount >
|
|
2128
|
+
if (amount > 9007199254740991n) throw new InvalidCommandError();
|
|
2112
2129
|
return {
|
|
2113
2130
|
kind: "budget-set",
|
|
2114
2131
|
projectId,
|
|
@@ -2535,7 +2552,7 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
|
|
|
2535
2552
|
if (subcommand === "list") {
|
|
2536
2553
|
if (yes || wait || follow || stdin) throw new InvalidCommandError();
|
|
2537
2554
|
const options = parseOptionalOptions(values, ["--cursor", "--limit"]);
|
|
2538
|
-
const limit = options["--limit"] === undefined ? 50 :
|
|
2555
|
+
const limit = options["--limit"] === undefined ? 50 : decimalLimit(options["--limit"]);
|
|
2539
2556
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) {
|
|
2540
2557
|
throw new InvalidCommandError();
|
|
2541
2558
|
}
|
|
@@ -3527,13 +3544,63 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
|
|
|
3527
3544
|
}
|
|
3528
3545
|
if (first === "deployment" && values[0] === "logs") {
|
|
3529
3546
|
values.shift();
|
|
3530
|
-
|
|
3531
|
-
|
|
3547
|
+
// The command reads one page of diagnostics; it never streams, so --follow is refused.
|
|
3548
|
+
if (follow || yes || wait || stdin) throw new InvalidCommandError();
|
|
3549
|
+
const options = parseOptionalOptions(values, ["--project", "--deployment", "--cursor"]);
|
|
3550
|
+
const projectId = options["--project"];
|
|
3551
|
+
const deploymentId = options["--deployment"];
|
|
3552
|
+
const cursor = options["--cursor"];
|
|
3553
|
+
if (
|
|
3554
|
+
projectId === undefined ||
|
|
3555
|
+
deploymentId === undefined ||
|
|
3556
|
+
!ORGANIZATION_ULID.test(projectId) ||
|
|
3557
|
+
!ORGANIZATION_ULID.test(deploymentId) ||
|
|
3558
|
+
(cursor !== undefined && !/^[A-Za-z0-9_-]+$/u.test(cursor))
|
|
3559
|
+
)
|
|
3560
|
+
throw new InvalidCommandError();
|
|
3532
3561
|
return {
|
|
3533
3562
|
kind: "deployment-logs",
|
|
3563
|
+
projectId,
|
|
3564
|
+
deploymentId,
|
|
3565
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
3566
|
+
credentialStore,
|
|
3567
|
+
};
|
|
3568
|
+
}
|
|
3569
|
+
if (first === "deployment" && values[0] === "list") {
|
|
3570
|
+
values.shift();
|
|
3571
|
+
if (yes || wait || follow || stdin) throw new InvalidCommandError();
|
|
3572
|
+
const options = parseOptionalOptions(values, ["--project", "--cursor", "--limit"]);
|
|
3573
|
+
const projectId = options["--project"];
|
|
3574
|
+
const cursor = options["--cursor"];
|
|
3575
|
+
const limit = options["--limit"] === undefined ? undefined : decimalLimit(options["--limit"]);
|
|
3576
|
+
if (
|
|
3577
|
+
projectId === undefined ||
|
|
3578
|
+
!ORGANIZATION_ULID.test(projectId) ||
|
|
3579
|
+
(cursor !== undefined && !/^[A-Za-z0-9_-]+$/u.test(cursor)) ||
|
|
3580
|
+
(limit !== undefined && (!Number.isSafeInteger(limit) || limit < 1 || limit > 100))
|
|
3581
|
+
)
|
|
3582
|
+
throw new InvalidCommandError();
|
|
3583
|
+
return {
|
|
3584
|
+
kind: "deployment-list",
|
|
3585
|
+
projectId,
|
|
3586
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
3587
|
+
...(limit === undefined ? {} : { limit }),
|
|
3588
|
+
credentialStore,
|
|
3589
|
+
};
|
|
3590
|
+
}
|
|
3591
|
+
if (first === "deployment" && values[0] === "get") {
|
|
3592
|
+
values.shift();
|
|
3593
|
+
if (yes || wait || follow || stdin) throw new InvalidCommandError();
|
|
3594
|
+
const options = parseOptions(values, ["--project", "--deployment"]);
|
|
3595
|
+
if (
|
|
3596
|
+
!ORGANIZATION_ULID.test(options["--project"]) ||
|
|
3597
|
+
!ORGANIZATION_ULID.test(options["--deployment"])
|
|
3598
|
+
)
|
|
3599
|
+
throw new InvalidCommandError();
|
|
3600
|
+
return {
|
|
3601
|
+
kind: "deployment-get",
|
|
3534
3602
|
projectId: options["--project"],
|
|
3535
3603
|
deploymentId: options["--deployment"],
|
|
3536
|
-
follow: true,
|
|
3537
3604
|
credentialStore,
|
|
3538
3605
|
};
|
|
3539
3606
|
}
|
|
@@ -3864,15 +3931,16 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
|
|
|
3864
3931
|
let request: ManagedMailCommand,
|
|
3865
3932
|
label: Extract<ProductCliCommand, { kind: "managed-mail" }>["label"];
|
|
3866
3933
|
if (area === "setup" || (area === "domain" && sub === "set")) {
|
|
3934
|
+
// The managed domain always sends: the API accepts only sending true, so any other value is a usage error.
|
|
3867
3935
|
const sending = required("--sending"),
|
|
3868
3936
|
receiving = required("--receiving");
|
|
3869
|
-
if (
|
|
3937
|
+
if (sending !== "true" || !["true", "false"].includes(receiving))
|
|
3870
3938
|
throw new InvalidCommandError();
|
|
3871
3939
|
request = {
|
|
3872
3940
|
...scope,
|
|
3873
3941
|
action: "configure",
|
|
3874
3942
|
domain: required("--domain"),
|
|
3875
|
-
sending:
|
|
3943
|
+
sending: true,
|
|
3876
3944
|
receiving: receiving === "true",
|
|
3877
3945
|
idempotencyKey: required("--idempotency-key"),
|
|
3878
3946
|
};
|
|
@@ -3952,7 +4020,8 @@ const parseOptions = <T extends string>(
|
|
|
3952
4020
|
if (option === undefined || !allowed.includes(option as T) || !isValue(value)) {
|
|
3953
4021
|
throw new InvalidCommandError();
|
|
3954
4022
|
}
|
|
3955
|
-
if (option === "--idempotency-key" &&
|
|
4023
|
+
if (option === "--idempotency-key" && !IDEMPOTENCY_KEY.test(value))
|
|
4024
|
+
throw new InvalidCommandError();
|
|
3956
4025
|
if (option in result) throw new InvalidCommandError();
|
|
3957
4026
|
result[option as T] = value;
|
|
3958
4027
|
}
|
|
@@ -3977,7 +4046,8 @@ const parseOptionalOptions = <T extends string>(
|
|
|
3977
4046
|
if (option === undefined || !allowed.includes(option as T) || !isValue(value)) {
|
|
3978
4047
|
throw new InvalidCommandError();
|
|
3979
4048
|
}
|
|
3980
|
-
if (option === "--idempotency-key" &&
|
|
4049
|
+
if (option === "--idempotency-key" && !IDEMPOTENCY_KEY.test(value))
|
|
4050
|
+
throw new InvalidCommandError();
|
|
3981
4051
|
if (option in result) throw new InvalidCommandError();
|
|
3982
4052
|
result[option as T] = value;
|
|
3983
4053
|
}
|
|
@@ -3998,6 +4068,11 @@ const accessTtlSeconds = (value: string | undefined): number => {
|
|
|
3998
4068
|
|
|
3999
4069
|
/** A platform organization identifier as the API returns it. */
|
|
4000
4070
|
const ORGANIZATION_ULID = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/u;
|
|
4071
|
+
/** The Idempotency-Key set that IdempotencyKeyToken documents (letters, digits and . _ : -, 1 to 128 characters); the CLI refuses any other key before a request is sent. */
|
|
4072
|
+
const IDEMPOTENCY_KEY = /^[A-Za-z0-9._:-]{1,128}$/u;
|
|
4073
|
+
/** A --limit written as a decimal integer: no sign, prefix, exponent or leading zero. Anything else is NaN, which fails the range check. */
|
|
4074
|
+
const decimalLimit = (value: string): number =>
|
|
4075
|
+
/^(?:0|[1-9][0-9]*)$/u.test(value) ? Number(value) : Number.NaN;
|
|
4001
4076
|
|
|
4002
4077
|
/** The account a command handed to a terminal must run as; never a credential. */
|
|
4003
4078
|
export interface HandedAccount {
|
|
@@ -791,8 +791,8 @@ export const runProductionCli = async (
|
|
|
791
791
|
const transport = new FetchWorkosPublicTransport(signal, REQUEST_TIMEOUT_MS);
|
|
792
792
|
const now = (): Date => new Date();
|
|
793
793
|
const refresher = new PublicWorkosTokenRefresher(environment);
|
|
794
|
-
const boundedFetch = (): typeof globalThis.fetch =>
|
|
795
|
-
createBoundedFetch(fetch,
|
|
794
|
+
const boundedFetch = (parentSignal: AbortSignal = signal): typeof globalThis.fetch =>
|
|
795
|
+
createBoundedFetch(fetch, parentSignal, REQUEST_TIMEOUT_MS, MAX_PUBLIC_RESPONSE_BYTES);
|
|
796
796
|
let profile: LocalProfile | undefined;
|
|
797
797
|
try {
|
|
798
798
|
if (apiToken !== undefined) {
|
|
@@ -928,8 +928,8 @@ export const runProductionCli = async (
|
|
|
928
928
|
{ now },
|
|
929
929
|
),
|
|
930
930
|
deviceAuthorizationPresenter: new StderrDeviceAuthorizationPresenter(io),
|
|
931
|
-
productApi: (accessToken) =>
|
|
932
|
-
new GeneratedSdkProductApi(productApiOrigin, accessToken, boundedFetch()),
|
|
931
|
+
productApi: (accessToken, parentSignal) =>
|
|
932
|
+
new GeneratedSdkProductApi(productApiOrigin, accessToken, boundedFetch(parentSignal)),
|
|
933
933
|
// Login receives read-only identity, workspace and GitHub queries instead of the product surface.
|
|
934
934
|
accountProfile: async (accessToken) =>
|
|
935
935
|
await new GeneratedSdkProductApi(
|
|
@@ -172,6 +172,7 @@ import {
|
|
|
172
172
|
getAccountProfile,
|
|
173
173
|
getCurrentIdentity,
|
|
174
174
|
getDeployment,
|
|
175
|
+
listDeployments,
|
|
175
176
|
getProjectSourceAutoDeploy,
|
|
176
177
|
getProjectStatus,
|
|
177
178
|
getPaidProjectDomain,
|
|
@@ -224,6 +225,7 @@ import {
|
|
|
224
225
|
type GuardedActionPlan,
|
|
225
226
|
type Operation,
|
|
226
227
|
type OperationEvent,
|
|
228
|
+
type ProjectCreateOperation,
|
|
227
229
|
type EnvironmentSecret,
|
|
228
230
|
type EnvironmentSecretPage,
|
|
229
231
|
type FunctionRunPage,
|
|
@@ -239,6 +241,7 @@ import {
|
|
|
239
241
|
type PaidDomainPlan,
|
|
240
242
|
type ProjectDatabaseQueryResult,
|
|
241
243
|
type DeploymentDiagnosticPage,
|
|
244
|
+
type DeploymentPage,
|
|
242
245
|
type Deployment,
|
|
243
246
|
type SourceAutoDeploy,
|
|
244
247
|
} from "@ohmyhost/sdk-ts";
|
|
@@ -606,7 +609,7 @@ export interface ProductApi {
|
|
|
606
609
|
feedbackId: string,
|
|
607
610
|
cursor?: string,
|
|
608
611
|
): Promise<import("@ohmyhost/sdk-ts").FeedbackStatus>;
|
|
609
|
-
createProject(input: ProjectCreateInput): Promise<
|
|
612
|
+
createProject(input: ProjectCreateInput): Promise<ProjectCreateOperation>;
|
|
610
613
|
addProjectDevelopmentEnvironment(input: {
|
|
611
614
|
readonly projectId: string;
|
|
612
615
|
readonly idempotencyKey: string;
|
|
@@ -664,6 +667,11 @@ export interface ProductApi {
|
|
|
664
667
|
readonly projectId: string;
|
|
665
668
|
readonly deploymentId: string;
|
|
666
669
|
}): Promise<Deployment>;
|
|
670
|
+
listDeployments(input: {
|
|
671
|
+
readonly projectId: string;
|
|
672
|
+
readonly cursor?: string;
|
|
673
|
+
readonly limit?: number;
|
|
674
|
+
}): Promise<DeploymentPage>;
|
|
667
675
|
/**
|
|
668
676
|
* One connection to the operation's events, resumed after `lastEventId` when given. It ends,
|
|
669
677
|
* without retrying, when the server closes it or refuses it; the caller decides what follows.
|
|
@@ -1761,7 +1769,7 @@ export class GeneratedSdkProductApi implements ProductApi {
|
|
|
1761
1769
|
),
|
|
1762
1770
|
);
|
|
1763
1771
|
}
|
|
1764
|
-
public async createProject(input: ProjectCreateInput): Promise<
|
|
1772
|
+
public async createProject(input: ProjectCreateInput): Promise<ProjectCreateOperation> {
|
|
1765
1773
|
return createProject(
|
|
1766
1774
|
{
|
|
1767
1775
|
"Idempotency-Key": input.idempotencyKey,
|
|
@@ -1991,6 +1999,21 @@ export class GeneratedSdkProductApi implements ProductApi {
|
|
|
1991
1999
|
)
|
|
1992
2000
|
).stream;
|
|
1993
2001
|
}
|
|
2002
|
+
public async listDeployments(input: {
|
|
2003
|
+
readonly projectId: string;
|
|
2004
|
+
readonly cursor?: string;
|
|
2005
|
+
readonly limit?: number;
|
|
2006
|
+
}): Promise<DeploymentPage> {
|
|
2007
|
+
return listDeployments(
|
|
2008
|
+
{
|
|
2009
|
+
project_id: input.projectId,
|
|
2010
|
+
...(input.cursor === undefined ? {} : { cursor: input.cursor }),
|
|
2011
|
+
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
2012
|
+
},
|
|
2013
|
+
{ client: this.#client },
|
|
2014
|
+
);
|
|
2015
|
+
}
|
|
2016
|
+
|
|
1994
2017
|
public async getDeploymentLogs(input: {
|
|
1995
2018
|
readonly projectId: string;
|
|
1996
2019
|
readonly deploymentId: string;
|
|
@@ -3,6 +3,9 @@ import { startBridge } from "@ohmyhost/postgres-bridge";
|
|
|
3
3
|
|
|
4
4
|
import { PsqlUnavailableError } from "./cli.js";
|
|
5
5
|
|
|
6
|
+
/** A psql still running this long after SIGTERM is killed, so a stuck session cannot keep its bridge and credential open. */
|
|
7
|
+
const KILL_AFTER_TERMINATE_MS = 5_000;
|
|
8
|
+
|
|
6
9
|
/** One private loopback bridge lasts exactly as long as the customer's native psql session. */
|
|
7
10
|
export const runLocalPsql = async (input: {
|
|
8
11
|
readonly host: string;
|
|
@@ -27,9 +30,11 @@ export const runLocalPsql = async (input: {
|
|
|
27
30
|
Object.entries(process.env).filter(([key]) => !/^PG[A-Z_]+$/iu.test(key)),
|
|
28
31
|
);
|
|
29
32
|
return await new Promise<number>((resolve, reject) => {
|
|
33
|
+
// The command's AbortSignal is not handed to psql. On a terminal, Ctrl-C reaches psql itself because psql shares
|
|
34
|
+
// this process group, so it cancels a query or leaves its prompt; this process only keeps listening. Without a
|
|
35
|
+
// terminal a SIGINT sent to this process is forwarded. A termination or hangup ends psql, and with it the session.
|
|
30
36
|
const child = spawn("psql", ["-h", bridge.host, "-U", input.user, "-d", input.database], {
|
|
31
37
|
stdio: "inherit",
|
|
32
|
-
signal: input.signal,
|
|
33
38
|
env: {
|
|
34
39
|
...environment,
|
|
35
40
|
PGPASSWORD: input.password,
|
|
@@ -39,10 +44,35 @@ export const runLocalPsql = async (input: {
|
|
|
39
44
|
PGGSSENCMODE: "disable",
|
|
40
45
|
},
|
|
41
46
|
});
|
|
47
|
+
let killer: NodeJS.Timeout | undefined;
|
|
48
|
+
const forwardInterrupt = (): void => {
|
|
49
|
+
child.kill("SIGINT");
|
|
50
|
+
};
|
|
51
|
+
// A terminal's Ctrl-C is already psql's interrupt, so forwarding it would interrupt psql twice.
|
|
52
|
+
const keepAlive = (): void => undefined;
|
|
53
|
+
const interrupt = process.stdin.isTTY ? keepAlive : forwardInterrupt;
|
|
54
|
+
const terminate = (): void => {
|
|
55
|
+
child.kill("SIGTERM");
|
|
56
|
+
killer ??= setTimeout(() => {
|
|
57
|
+
child.kill("SIGKILL");
|
|
58
|
+
}, KILL_AFTER_TERMINATE_MS);
|
|
59
|
+
};
|
|
60
|
+
const release = (): void => {
|
|
61
|
+
clearTimeout(killer);
|
|
62
|
+
process.off("SIGINT", interrupt);
|
|
63
|
+
process.off("SIGTERM", terminate);
|
|
64
|
+
process.off("SIGHUP", terminate);
|
|
65
|
+
};
|
|
66
|
+
process.on("SIGINT", interrupt);
|
|
67
|
+
process.on("SIGTERM", terminate);
|
|
68
|
+
// A hangup ends the terminal's session; the same orderly end keeps the bridge closing in its finally block.
|
|
69
|
+
process.on("SIGHUP", terminate);
|
|
42
70
|
child.once("error", (error: NodeJS.ErrnoException) => {
|
|
71
|
+
release();
|
|
43
72
|
reject(error.code === "ENOENT" ? new PsqlUnavailableError() : error);
|
|
44
73
|
});
|
|
45
74
|
child.once("close", (code, signalName) => {
|
|
75
|
+
release();
|
|
46
76
|
resolve(code ?? (signalName === null ? 1 : 130));
|
|
47
77
|
});
|
|
48
78
|
});
|