@amerged/ohmyhost-cli 0.1.60 → 0.1.63
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-DYRDZNIR.js → chunk-NRFJFQTV.js} +468 -85
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/src/apps/product-cli/package.json +1 -1
- package/src/apps/product-cli/src/cli.ts +29 -0
- package/src/apps/product-cli/src/command.ts +210 -0
- package/src/apps/product-cli/src/product-api.ts +109 -0
- package/src/packages/contracts/package.json +5 -0
- package/src/packages/contracts/src/connection-management.ts +107 -0
- package/src/packages/contracts/src/index.ts +2 -0
- package/src/packages/sdk-ts/package.json +1 -1
- package/src/packages/sdk-ts/src/generated/index.ts +53 -0
- package/src/packages/sdk-ts/src/generated/sdk.gen.ts +314 -0
- package/src/packages/sdk-ts/src/generated/types.gen.ts +463 -0
package/dist/index.js
CHANGED
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
defaultProfileName,
|
|
50
50
|
describeProfile,
|
|
51
51
|
endedLoginAction,
|
|
52
|
+
executeConnectionCommand,
|
|
52
53
|
executeNativeAuth,
|
|
53
54
|
extractProfileName,
|
|
54
55
|
helpTopicKnown,
|
|
@@ -106,7 +107,7 @@ import {
|
|
|
106
107
|
selectWorkspace,
|
|
107
108
|
verifiedUserId,
|
|
108
109
|
workspaceOf
|
|
109
|
-
} from "./chunk-
|
|
110
|
+
} from "./chunk-NRFJFQTV.js";
|
|
110
111
|
import {
|
|
111
112
|
CredentialStoreIntegrityError,
|
|
112
113
|
CredentialStoreUnavailableError,
|
|
@@ -309,6 +310,7 @@ export {
|
|
|
309
310
|
defaultProfileName,
|
|
310
311
|
describeProfile,
|
|
311
312
|
endedLoginAction,
|
|
313
|
+
executeConnectionCommand,
|
|
312
314
|
executeNativeAuth,
|
|
313
315
|
extractProfileName,
|
|
314
316
|
helpTopicKnown,
|
package/package.json
CHANGED
|
@@ -358,6 +358,16 @@ const HELP_USAGE = Object.freeze({
|
|
|
358
358
|
"ohmyhost whoami [--profile-name NAME] --json (the effective user, organization and saved login)",
|
|
359
359
|
"profile list":
|
|
360
360
|
"ohmyhost profile list --json (saved logins on this computer: name, user and organization, never a token; pass --profile-name NAME or set OHMYHOST_PROFILE to choose one)",
|
|
361
|
+
"connection begin":
|
|
362
|
+
"ohmyhost connection begin --organization ULID [--project ULID --environment ULID] --idempotency-key KEY --json",
|
|
363
|
+
"connection list": "ohmyhost connection list --organization ULID --json",
|
|
364
|
+
"connection status": "ohmyhost connection status --organization ULID --request HASH --json",
|
|
365
|
+
"connection discover":
|
|
366
|
+
"ohmyhost connection discover --organization ULID [--project ULID --environment ULID] --grant ULID [--provider-organization ID] [--team ID] --json",
|
|
367
|
+
"connection import":
|
|
368
|
+
"ohmyhost connection import --organization ULID --grant ULID --project ULID --environment ULID --provider-organization ID --team ID --connection ID --idempotency-key KEY --json",
|
|
369
|
+
"connection disconnect":
|
|
370
|
+
"ohmyhost connection disconnect --organization ULID --grant ULID --idempotency-key KEY --yes --json",
|
|
361
371
|
"github connect":
|
|
362
372
|
"ohmyhost github connect --organization ULID --idempotency-key KEY --json (connect once, then link covered repositories without another browser consent)",
|
|
363
373
|
"github status": "ohmyhost github status --organization ULID --json",
|
|
@@ -911,6 +921,19 @@ export class ProductCli {
|
|
|
911
921
|
: { next_action: this.githubConnectAction(command.organizationId) }),
|
|
912
922
|
});
|
|
913
923
|
}
|
|
924
|
+
if (
|
|
925
|
+
command.kind === "connection-begin" ||
|
|
926
|
+
command.kind === "connection-list" ||
|
|
927
|
+
command.kind === "connection-status" ||
|
|
928
|
+
command.kind === "connection-discover" ||
|
|
929
|
+
command.kind === "connection-import" ||
|
|
930
|
+
command.kind === "connection-disconnect"
|
|
931
|
+
) {
|
|
932
|
+
const api = await this.authenticatedApi(command.credentialStore, signal);
|
|
933
|
+
if (!api.connection) throw new ResponseContractError();
|
|
934
|
+
const result = await api.connection(command);
|
|
935
|
+
return success(name, { status: "ok", result });
|
|
936
|
+
}
|
|
914
937
|
if (command.kind === "organization-mcp-connections-list") {
|
|
915
938
|
const api = await this.authenticatedApi(command.credentialStore, signal);
|
|
916
939
|
const page = parseOrganizationMcpConnectionList(
|
|
@@ -3921,6 +3944,12 @@ const parsedCommandName = (command: ProductCliCommand): CommandLabel => {
|
|
|
3921
3944
|
if (command.kind === "github-connect") return "github connect";
|
|
3922
3945
|
if (command.kind === "github-status") return "github status";
|
|
3923
3946
|
if (command.kind === "github-disconnect") return "github disconnect";
|
|
3947
|
+
if (command.kind === "connection-begin") return "connection begin";
|
|
3948
|
+
if (command.kind === "connection-list") return "connection list";
|
|
3949
|
+
if (command.kind === "connection-status") return "connection status";
|
|
3950
|
+
if (command.kind === "connection-discover") return "connection discover";
|
|
3951
|
+
if (command.kind === "connection-import") return "connection import";
|
|
3952
|
+
if (command.kind === "connection-disconnect") return "connection disconnect";
|
|
3924
3953
|
if (command.kind === "organization-mcp-connections-list")
|
|
3925
3954
|
return "organization mcp-connections list";
|
|
3926
3955
|
if (command.kind === "organization-mcp-connection-revoke")
|
|
@@ -131,6 +131,55 @@ export type ProductCliCommand =
|
|
|
131
131
|
readonly yes: true;
|
|
132
132
|
readonly credentialStore: "native";
|
|
133
133
|
}
|
|
134
|
+
| {
|
|
135
|
+
readonly kind: "connection-begin";
|
|
136
|
+
readonly organizationId: string;
|
|
137
|
+
readonly projectId?: string;
|
|
138
|
+
readonly environmentId?: string;
|
|
139
|
+
readonly idempotencyKey: string;
|
|
140
|
+
readonly credentialStore: "native";
|
|
141
|
+
}
|
|
142
|
+
| {
|
|
143
|
+
readonly kind: "connection-list";
|
|
144
|
+
readonly organizationId: string;
|
|
145
|
+
readonly credentialStore: "native";
|
|
146
|
+
}
|
|
147
|
+
| {
|
|
148
|
+
readonly kind: "connection-status";
|
|
149
|
+
readonly organizationId: string;
|
|
150
|
+
readonly requestId: string;
|
|
151
|
+
readonly credentialStore: "native";
|
|
152
|
+
}
|
|
153
|
+
| {
|
|
154
|
+
readonly kind: "connection-discover";
|
|
155
|
+
readonly organizationId: string;
|
|
156
|
+
readonly projectId?: string;
|
|
157
|
+
readonly environmentId?: string;
|
|
158
|
+
readonly grantId: string;
|
|
159
|
+
readonly providerOrganizationId?: number;
|
|
160
|
+
readonly teamId?: number;
|
|
161
|
+
readonly credentialStore: "native";
|
|
162
|
+
}
|
|
163
|
+
| {
|
|
164
|
+
readonly kind: "connection-import";
|
|
165
|
+
readonly organizationId: string;
|
|
166
|
+
readonly projectId: string;
|
|
167
|
+
readonly environmentId: string;
|
|
168
|
+
readonly grantId: string;
|
|
169
|
+
readonly providerOrganizationId: number;
|
|
170
|
+
readonly teamId: number;
|
|
171
|
+
readonly connectionId: number;
|
|
172
|
+
readonly idempotencyKey: string;
|
|
173
|
+
readonly credentialStore: "native";
|
|
174
|
+
}
|
|
175
|
+
| {
|
|
176
|
+
readonly kind: "connection-disconnect";
|
|
177
|
+
readonly organizationId: string;
|
|
178
|
+
readonly grantId: string;
|
|
179
|
+
readonly idempotencyKey: string;
|
|
180
|
+
readonly yes: true;
|
|
181
|
+
readonly credentialStore: "native";
|
|
182
|
+
}
|
|
134
183
|
| {
|
|
135
184
|
readonly kind: "organization-mcp-connections-list";
|
|
136
185
|
readonly organizationId: string;
|
|
@@ -1135,6 +1184,12 @@ export type RecognizedCommandLabel =
|
|
|
1135
1184
|
| "organization use"
|
|
1136
1185
|
| "organization mcp-connections list"
|
|
1137
1186
|
| "organization mcp-connections revoke"
|
|
1187
|
+
| "connection begin"
|
|
1188
|
+
| "connection list"
|
|
1189
|
+
| "connection status"
|
|
1190
|
+
| "connection discover"
|
|
1191
|
+
| "connection import"
|
|
1192
|
+
| "connection disconnect"
|
|
1138
1193
|
| "github connect"
|
|
1139
1194
|
| "github status"
|
|
1140
1195
|
| "github disconnect"
|
|
@@ -1269,6 +1324,11 @@ export const recognizedCommandLabel = (argv: readonly string[]): RecognizedComma
|
|
|
1269
1324
|
)
|
|
1270
1325
|
return value;
|
|
1271
1326
|
if (value === "profile" && values[0] === "list") return "profile list";
|
|
1327
|
+
if (
|
|
1328
|
+
value === "connection" &&
|
|
1329
|
+
["begin", "list", "status", "discover", "import", "disconnect"].includes(values[0] ?? "")
|
|
1330
|
+
)
|
|
1331
|
+
return `connection ${values[0]}` as RecognizedCommandLabel;
|
|
1272
1332
|
if (value === "github" && values[0] === "connect") return "github connect";
|
|
1273
1333
|
if (value === "github" && values[0] === "status") return "github status";
|
|
1274
1334
|
if (value === "github" && values[0] === "disconnect") return "github disconnect";
|
|
@@ -2106,6 +2166,156 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
|
|
|
2106
2166
|
}
|
|
2107
2167
|
: { kind: "github-status", organizationId, credentialStore };
|
|
2108
2168
|
}
|
|
2169
|
+
if (first === "connection") {
|
|
2170
|
+
const operation = values.shift();
|
|
2171
|
+
if (wait || follow || stdin || yes !== (operation === "disconnect"))
|
|
2172
|
+
throw new InvalidCommandError();
|
|
2173
|
+
const options = parseOptionalOptions(values, [
|
|
2174
|
+
"--organization",
|
|
2175
|
+
"--project",
|
|
2176
|
+
"--environment",
|
|
2177
|
+
"--grant",
|
|
2178
|
+
"--request",
|
|
2179
|
+
"--idempotency-key",
|
|
2180
|
+
"--provider-organization",
|
|
2181
|
+
"--team",
|
|
2182
|
+
"--connection",
|
|
2183
|
+
] as const);
|
|
2184
|
+
const org = options["--organization"];
|
|
2185
|
+
if (!org || !ORGANIZATION_ULID.test(org)) throw new InvalidCommandError();
|
|
2186
|
+
const exact = (names: string[]) =>
|
|
2187
|
+
Object.keys(options).every((k) => names.includes(k)) &&
|
|
2188
|
+
names.every((k) => Object.hasOwn(options, k));
|
|
2189
|
+
const scoped = () =>
|
|
2190
|
+
options["--project"] &&
|
|
2191
|
+
options["--environment"] &&
|
|
2192
|
+
ORGANIZATION_ULID.test(options["--project"]) &&
|
|
2193
|
+
ORGANIZATION_ULID.test(options["--environment"]);
|
|
2194
|
+
if (operation === "list" && exact(["--organization"]))
|
|
2195
|
+
return { kind: "connection-list", organizationId: org, credentialStore };
|
|
2196
|
+
if (
|
|
2197
|
+
operation === "begin" &&
|
|
2198
|
+
(exact(["--organization", "--idempotency-key"]) ||
|
|
2199
|
+
(scoped() && exact(["--organization", "--project", "--environment", "--idempotency-key"])))
|
|
2200
|
+
)
|
|
2201
|
+
return {
|
|
2202
|
+
kind: "connection-begin",
|
|
2203
|
+
organizationId: org,
|
|
2204
|
+
...(options["--project"]
|
|
2205
|
+
? { projectId: options["--project"], environmentId: options["--environment"] }
|
|
2206
|
+
: {}),
|
|
2207
|
+
idempotencyKey: options["--idempotency-key"] ?? "",
|
|
2208
|
+
credentialStore,
|
|
2209
|
+
};
|
|
2210
|
+
if (
|
|
2211
|
+
operation === "status" &&
|
|
2212
|
+
exact(["--organization", "--request"]) &&
|
|
2213
|
+
/^[a-f0-9]{64}$/u.test(options["--request"] ?? "")
|
|
2214
|
+
)
|
|
2215
|
+
return {
|
|
2216
|
+
kind: "connection-status",
|
|
2217
|
+
organizationId: org,
|
|
2218
|
+
requestId: options["--request"] ?? "",
|
|
2219
|
+
credentialStore,
|
|
2220
|
+
};
|
|
2221
|
+
if (
|
|
2222
|
+
operation === "disconnect" &&
|
|
2223
|
+
exact(["--organization", "--grant", "--idempotency-key"]) &&
|
|
2224
|
+
ORGANIZATION_ULID.test(options["--grant"] ?? "")
|
|
2225
|
+
)
|
|
2226
|
+
return {
|
|
2227
|
+
kind: "connection-disconnect",
|
|
2228
|
+
organizationId: org,
|
|
2229
|
+
grantId: options["--grant"] ?? "",
|
|
2230
|
+
idempotencyKey: options["--idempotency-key"] ?? "",
|
|
2231
|
+
yes: true,
|
|
2232
|
+
credentialStore,
|
|
2233
|
+
};
|
|
2234
|
+
if (
|
|
2235
|
+
operation === "import" &&
|
|
2236
|
+
scoped() &&
|
|
2237
|
+
ORGANIZATION_ULID.test(options["--grant"] ?? "") &&
|
|
2238
|
+
exact([
|
|
2239
|
+
"--organization",
|
|
2240
|
+
"--project",
|
|
2241
|
+
"--environment",
|
|
2242
|
+
"--grant",
|
|
2243
|
+
"--provider-organization",
|
|
2244
|
+
"--team",
|
|
2245
|
+
"--connection",
|
|
2246
|
+
"--idempotency-key",
|
|
2247
|
+
])
|
|
2248
|
+
) {
|
|
2249
|
+
const projectId = options["--project"],
|
|
2250
|
+
environmentId = options["--environment"],
|
|
2251
|
+
grantId = options["--grant"],
|
|
2252
|
+
idempotencyKey = options["--idempotency-key"];
|
|
2253
|
+
const providerOrganizationId = Number(options["--provider-organization"]),
|
|
2254
|
+
teamId = Number(options["--team"]),
|
|
2255
|
+
connectionId = Number(options["--connection"]);
|
|
2256
|
+
if (
|
|
2257
|
+
!projectId ||
|
|
2258
|
+
!environmentId ||
|
|
2259
|
+
!grantId ||
|
|
2260
|
+
!idempotencyKey ||
|
|
2261
|
+
[providerOrganizationId, teamId, connectionId].some(
|
|
2262
|
+
(n) => !Number.isSafeInteger(n) || n < 1,
|
|
2263
|
+
)
|
|
2264
|
+
)
|
|
2265
|
+
throw new InvalidCommandError();
|
|
2266
|
+
return {
|
|
2267
|
+
kind: "connection-import",
|
|
2268
|
+
organizationId: org,
|
|
2269
|
+
projectId,
|
|
2270
|
+
environmentId,
|
|
2271
|
+
grantId,
|
|
2272
|
+
providerOrganizationId,
|
|
2273
|
+
teamId,
|
|
2274
|
+
connectionId,
|
|
2275
|
+
idempotencyKey,
|
|
2276
|
+
credentialStore,
|
|
2277
|
+
};
|
|
2278
|
+
}
|
|
2279
|
+
if (
|
|
2280
|
+
operation === "discover" &&
|
|
2281
|
+
((!options["--project"] && !options["--environment"]) || scoped()) &&
|
|
2282
|
+
ORGANIZATION_ULID.test(options["--grant"] ?? "") &&
|
|
2283
|
+
Object.keys(options).every((k) =>
|
|
2284
|
+
[
|
|
2285
|
+
"--organization",
|
|
2286
|
+
"--project",
|
|
2287
|
+
"--environment",
|
|
2288
|
+
"--grant",
|
|
2289
|
+
"--provider-organization",
|
|
2290
|
+
"--team",
|
|
2291
|
+
].includes(k),
|
|
2292
|
+
)
|
|
2293
|
+
) {
|
|
2294
|
+
const number = (v: string | undefined) =>
|
|
2295
|
+
v && /^[1-9][0-9]{0,14}$/u.test(v) && Number.isSafeInteger(Number(v))
|
|
2296
|
+
? Number(v)
|
|
2297
|
+
: undefined;
|
|
2298
|
+
const providerOrganizationId = number(options["--provider-organization"]),
|
|
2299
|
+
teamId = number(options["--team"]);
|
|
2300
|
+
if (
|
|
2301
|
+
(options["--provider-organization"] && !providerOrganizationId) ||
|
|
2302
|
+
(options["--team"] && (!teamId || !providerOrganizationId))
|
|
2303
|
+
)
|
|
2304
|
+
throw new InvalidCommandError();
|
|
2305
|
+
return {
|
|
2306
|
+
kind: "connection-discover",
|
|
2307
|
+
organizationId: org,
|
|
2308
|
+
...(options["--project"]
|
|
2309
|
+
? { projectId: options["--project"], environmentId: options["--environment"] }
|
|
2310
|
+
: {}),
|
|
2311
|
+
grantId: options["--grant"] ?? "",
|
|
2312
|
+
...(providerOrganizationId ? { providerOrganizationId } : {}),
|
|
2313
|
+
...(teamId ? { teamId } : {}),
|
|
2314
|
+
credentialStore,
|
|
2315
|
+
};
|
|
2316
|
+
}
|
|
2317
|
+
throw new InvalidCommandError();
|
|
2318
|
+
}
|
|
2109
2319
|
if (first === "organization" && values[0] === "mcp-connections") {
|
|
2110
2320
|
values.shift();
|
|
2111
2321
|
const subcommand = values.shift();
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import { parseConnectionResponse } from "@ohmyhost/contracts/connection-management";
|
|
2
|
+
import {
|
|
3
|
+
beginConnection,
|
|
4
|
+
importConnection,
|
|
5
|
+
listConnections,
|
|
6
|
+
getConnectionRequest,
|
|
7
|
+
discoverConnection,
|
|
8
|
+
disconnectConnection,
|
|
9
|
+
} from "@ohmyhost/sdk-ts";
|
|
10
|
+
import type { ProductCliCommand } from "./command.js";
|
|
1
11
|
import { randomUUID } from "node:crypto";
|
|
2
12
|
import { parsePreviewView } from "@ohmyhost/contracts";
|
|
3
13
|
import {
|
|
@@ -290,7 +300,20 @@ export interface DatabaseTableAnswer {
|
|
|
290
300
|
};
|
|
291
301
|
}
|
|
292
302
|
|
|
303
|
+
export type ConnectionCommand = Extract<
|
|
304
|
+
ProductCliCommand,
|
|
305
|
+
{
|
|
306
|
+
kind:
|
|
307
|
+
| "connection-begin"
|
|
308
|
+
| "connection-list"
|
|
309
|
+
| "connection-status"
|
|
310
|
+
| "connection-discover"
|
|
311
|
+
| "connection-disconnect"
|
|
312
|
+
| "connection-import";
|
|
313
|
+
}
|
|
314
|
+
>;
|
|
293
315
|
export interface ProductApi {
|
|
316
|
+
connection?(command: ConnectionCommand): Promise<unknown>;
|
|
294
317
|
preview?(
|
|
295
318
|
action: "get" | "open" | "stop" | "rotate",
|
|
296
319
|
input: { projectId: string; environment: "dev" | "prod"; idempotencyKey?: string },
|
|
@@ -762,8 +785,89 @@ function hasExactKeys(value: Record<string, unknown>, keys: readonly string[]):
|
|
|
762
785
|
return Object.keys(value).sort().join(",") === [...keys].sort().join(",");
|
|
763
786
|
}
|
|
764
787
|
|
|
788
|
+
export async function executeConnectionCommand(
|
|
789
|
+
client: OhMyHostClient,
|
|
790
|
+
origin: string,
|
|
791
|
+
command: ConnectionCommand,
|
|
792
|
+
): Promise<unknown> {
|
|
793
|
+
const organization_id = command.organizationId;
|
|
794
|
+
if (
|
|
795
|
+
(command.kind === "connection-begin" || command.kind === "connection-discover") &&
|
|
796
|
+
(command.projectId === undefined) !== (command.environmentId === undefined)
|
|
797
|
+
)
|
|
798
|
+
throw new TypeError("Invalid connection scope");
|
|
799
|
+
let result: unknown;
|
|
800
|
+
switch (command.kind) {
|
|
801
|
+
case "connection-begin":
|
|
802
|
+
result = await beginConnection(
|
|
803
|
+
{
|
|
804
|
+
organization_id,
|
|
805
|
+
"Idempotency-Key": command.idempotencyKey,
|
|
806
|
+
connectionBegin: {
|
|
807
|
+
provider: "make",
|
|
808
|
+
...(command.projectId
|
|
809
|
+
? { project_id: command.projectId, environment_id: command.environmentId }
|
|
810
|
+
: {}),
|
|
811
|
+
},
|
|
812
|
+
},
|
|
813
|
+
{ client: client },
|
|
814
|
+
);
|
|
815
|
+
break;
|
|
816
|
+
case "connection-list":
|
|
817
|
+
result = await listConnections({ organization_id, scope: "workspace" }, { client: client });
|
|
818
|
+
break;
|
|
819
|
+
case "connection-status":
|
|
820
|
+
result = await getConnectionRequest(
|
|
821
|
+
{ organization_id, request_id: command.requestId },
|
|
822
|
+
{ client: client },
|
|
823
|
+
);
|
|
824
|
+
break;
|
|
825
|
+
case "connection-discover":
|
|
826
|
+
result = await discoverConnection(
|
|
827
|
+
{
|
|
828
|
+
organization_id,
|
|
829
|
+
grant_id: command.grantId,
|
|
830
|
+
...(command.projectId
|
|
831
|
+
? { project_id: command.projectId, environment_id: command.environmentId }
|
|
832
|
+
: {}),
|
|
833
|
+
...(command.providerOrganizationId === undefined
|
|
834
|
+
? {}
|
|
835
|
+
: { provider_organization_id: command.providerOrganizationId }),
|
|
836
|
+
...(command.teamId === undefined ? {} : { team_id: command.teamId }),
|
|
837
|
+
},
|
|
838
|
+
{ client: client },
|
|
839
|
+
);
|
|
840
|
+
break;
|
|
841
|
+
case "connection-import":
|
|
842
|
+
result = await importConnection(
|
|
843
|
+
{
|
|
844
|
+
organization_id,
|
|
845
|
+
grant_id: command.grantId,
|
|
846
|
+
"Idempotency-Key": command.idempotencyKey,
|
|
847
|
+
connectionImportRequest: {
|
|
848
|
+
project_id: command.projectId,
|
|
849
|
+
environment_id: command.environmentId,
|
|
850
|
+
provider_organization_id: command.providerOrganizationId,
|
|
851
|
+
team_id: command.teamId,
|
|
852
|
+
connection_id: command.connectionId,
|
|
853
|
+
},
|
|
854
|
+
},
|
|
855
|
+
{ client },
|
|
856
|
+
);
|
|
857
|
+
break;
|
|
858
|
+
case "connection-disconnect":
|
|
859
|
+
result = await disconnectConnection(
|
|
860
|
+
{ organization_id, grant_id: command.grantId, "Idempotency-Key": command.idempotencyKey },
|
|
861
|
+
{ client: client },
|
|
862
|
+
);
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
return parseConnectionResponse(command.kind, result, origin);
|
|
866
|
+
}
|
|
867
|
+
|
|
765
868
|
export class GeneratedSdkProductApi implements ProductApi {
|
|
766
869
|
readonly #client: OhMyHostClient;
|
|
870
|
+
readonly #connectionOrigin: string;
|
|
767
871
|
public readonly managedSource: ManagedSourceApi;
|
|
768
872
|
|
|
769
873
|
public constructor(
|
|
@@ -771,10 +875,15 @@ export class GeneratedSdkProductApi implements ProductApi {
|
|
|
771
875
|
accessToken: string | (() => Promise<string>),
|
|
772
876
|
fetch: typeof globalThis.fetch,
|
|
773
877
|
) {
|
|
878
|
+
this.#connectionOrigin = new URL(baseUrl).origin;
|
|
774
879
|
this.#client = createClient({ auth: accessToken, baseUrl, fetch, throwOnError: true });
|
|
775
880
|
this.managedSource = new GeneratedSdkManagedSourceApi(() => this.#client);
|
|
776
881
|
}
|
|
777
882
|
|
|
883
|
+
public async connection(command: ConnectionCommand): Promise<unknown> {
|
|
884
|
+
return executeConnectionCommand(this.#client, this.#connectionOrigin, command);
|
|
885
|
+
}
|
|
886
|
+
|
|
778
887
|
public async changeDatabaseCompute(
|
|
779
888
|
input: {
|
|
780
889
|
projectId: string;
|
|
@@ -192,6 +192,11 @@
|
|
|
192
192
|
"types": "./dist/usage-log.d.ts",
|
|
193
193
|
"import": "./dist/usage-log.js"
|
|
194
194
|
},
|
|
195
|
+
"./connection-management": {
|
|
196
|
+
"source": "./src/connection-management.ts",
|
|
197
|
+
"types": "./dist/connection-management.d.ts",
|
|
198
|
+
"import": "./dist/connection-management.js"
|
|
199
|
+
},
|
|
195
200
|
"./previews": {
|
|
196
201
|
"source": "./src/previews.ts",
|
|
197
202
|
"types": "./dist/previews.d.ts",
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const ulid = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/u;
|
|
2
|
+
function record(raw: unknown, keys: readonly string[]): Record<string, unknown> {
|
|
3
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
4
|
+
throw new TypeError("Invalid connection response");
|
|
5
|
+
const value = raw as Record<string, unknown>;
|
|
6
|
+
if (Object.keys(value).length !== keys.length || keys.some((key) => !Object.hasOwn(value, key)))
|
|
7
|
+
throw new TypeError("Invalid connection response");
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
function date(raw: unknown): void {
|
|
11
|
+
if (typeof raw !== "string" || !Number.isFinite(Date.parse(raw)))
|
|
12
|
+
throw new TypeError("Invalid connection response");
|
|
13
|
+
}
|
|
14
|
+
function items(raw: unknown): void {
|
|
15
|
+
if (!Array.isArray(raw) || raw.length > 10000) throw new TypeError("Invalid connection response");
|
|
16
|
+
for (const row of raw) {
|
|
17
|
+
const v = record(row, ["id", "name"]);
|
|
18
|
+
if (
|
|
19
|
+
!Number.isSafeInteger(v["id"]) ||
|
|
20
|
+
Number(v["id"]) < 1 ||
|
|
21
|
+
typeof v["name"] !== "string" ||
|
|
22
|
+
!v["name"] ||
|
|
23
|
+
v["name"].length > 1024
|
|
24
|
+
)
|
|
25
|
+
throw new TypeError("Invalid connection response");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function parseConnectionResponse(
|
|
29
|
+
kind:
|
|
30
|
+
| "connection-begin"
|
|
31
|
+
| "connection-list"
|
|
32
|
+
| "connection-status"
|
|
33
|
+
| "connection-discover"
|
|
34
|
+
| "connection-disconnect"
|
|
35
|
+
| "connection-import",
|
|
36
|
+
raw: unknown,
|
|
37
|
+
expectedOrigin?: string,
|
|
38
|
+
): unknown {
|
|
39
|
+
if (kind === "connection-begin") {
|
|
40
|
+
const v = record(raw, ["request_id", "url", "expires_at"]);
|
|
41
|
+
date(v["expires_at"]);
|
|
42
|
+
if (
|
|
43
|
+
typeof v["request_id"] !== "string" ||
|
|
44
|
+
!/^[a-f0-9]{64}$/u.test(v["request_id"]) ||
|
|
45
|
+
typeof v["url"] !== "string"
|
|
46
|
+
)
|
|
47
|
+
throw new TypeError("Invalid connection response");
|
|
48
|
+
const url = new URL(v["url"]);
|
|
49
|
+
if (
|
|
50
|
+
!["https://app.ohmyho.st", "https://dev.app.ohmyho.st"].includes(url.origin) ||
|
|
51
|
+
(expectedOrigin !== undefined && url.origin !== expectedOrigin) ||
|
|
52
|
+
url.pathname !== "/connections/authorize" ||
|
|
53
|
+
url.hash ||
|
|
54
|
+
url.searchParams.size !== 1 ||
|
|
55
|
+
!/^[A-Za-z0-9_-]{43}$/u.test(url.searchParams.get("request") ?? "")
|
|
56
|
+
)
|
|
57
|
+
throw new TypeError("Invalid connection response");
|
|
58
|
+
} else if (kind === "connection-status") {
|
|
59
|
+
const v = record(raw, ["state", "expires_at"]);
|
|
60
|
+
date(v["expires_at"]);
|
|
61
|
+
if (!["pending", "consumed", "expired"].includes(String(v["state"])))
|
|
62
|
+
throw new TypeError("Invalid connection response");
|
|
63
|
+
} else if (kind === "connection-disconnect") {
|
|
64
|
+
const v = record(raw, ["state"]);
|
|
65
|
+
if (!["disconnected", "revocation_pending"].includes(String(v["state"])))
|
|
66
|
+
throw new TypeError("Invalid connection response");
|
|
67
|
+
} else if (kind === "connection-import") {
|
|
68
|
+
const v = record(raw, [
|
|
69
|
+
"id",
|
|
70
|
+
"grant_id",
|
|
71
|
+
"project_id",
|
|
72
|
+
"environment_id",
|
|
73
|
+
"provider_organization_id",
|
|
74
|
+
"team_id",
|
|
75
|
+
"connection_id",
|
|
76
|
+
]);
|
|
77
|
+
for (const key of ["id", "grant_id", "project_id", "environment_id"])
|
|
78
|
+
if (typeof v[key] !== "string" || !ulid.test(v[key] as string))
|
|
79
|
+
throw new TypeError("Invalid connection response");
|
|
80
|
+
for (const key of ["provider_organization_id", "team_id", "connection_id"])
|
|
81
|
+
if (!Number.isSafeInteger(v[key]) || Number(v[key]) < 1)
|
|
82
|
+
throw new TypeError("Invalid connection response");
|
|
83
|
+
} else if (kind === "connection-discover") {
|
|
84
|
+
const v = record(raw, ["organizations", "teams", "connections"]);
|
|
85
|
+
items(v["organizations"]);
|
|
86
|
+
items(v["teams"]);
|
|
87
|
+
items(v["connections"]);
|
|
88
|
+
} else {
|
|
89
|
+
const v = record(raw, ["connections"]);
|
|
90
|
+
if (!Array.isArray(v["connections"]) || v["connections"].length > 10000)
|
|
91
|
+
throw new TypeError("Invalid connection response");
|
|
92
|
+
for (const row of v["connections"]) {
|
|
93
|
+
const grant = record(row, ["id", "provider", "state", "created_at"]);
|
|
94
|
+
date(grant["created_at"]);
|
|
95
|
+
if (
|
|
96
|
+
typeof grant["id"] !== "string" ||
|
|
97
|
+
!ulid.test(grant["id"]) ||
|
|
98
|
+
grant["provider"] !== "make" ||
|
|
99
|
+
!["active", "refreshing", "reconnect_required", "disconnecting", "disconnected"].includes(
|
|
100
|
+
String(grant["state"]),
|
|
101
|
+
)
|
|
102
|
+
)
|
|
103
|
+
throw new TypeError("Invalid connection response");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return raw;
|
|
107
|
+
}
|
|
@@ -236,6 +236,8 @@ function forbiddenEgressHostname(hostname: string): boolean {
|
|
|
236
236
|
/(?:^|\.)ohmyho-(?:mail|storage)-gateway-[a-z0-9][a-z0-9-]*\.[a-z0-9][a-z0-9-]*\.workers\.dev\.?$/u.test(
|
|
237
237
|
normalized,
|
|
238
238
|
) ||
|
|
239
|
+
normalized.replace(/\.+$/u, "") === "connect.ohmyho.st" ||
|
|
240
|
+
normalized.replace(/\.+$/u, "").endsWith(".connect.ohmyho.st") ||
|
|
239
241
|
normalized === "localhost" ||
|
|
240
242
|
normalized.endsWith(".localhost") ||
|
|
241
243
|
normalized.endsWith(".local") ||
|