@amerged/ohmyhost-cli 0.1.60 → 0.1.62
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-WER7CYZD.js} +383 -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 +25 -0
- package/src/apps/product-cli/src/command.ts +149 -0
- package/src/apps/product-cli/src/product-api.ts +83 -0
- package/src/packages/contracts/package.json +5 -0
- package/src/packages/contracts/src/connection-management.ts +90 -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 +45 -0
- package/src/packages/sdk-ts/src/generated/sdk.gen.ts +263 -0
- package/src/packages/sdk-ts/src/generated/types.gen.ts +376 -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-WER7CYZD.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,14 @@ 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 disconnect":
|
|
368
|
+
"ohmyhost connection disconnect --organization ULID --grant ULID --idempotency-key KEY --yes --json",
|
|
361
369
|
"github connect":
|
|
362
370
|
"ohmyhost github connect --organization ULID --idempotency-key KEY --json (connect once, then link covered repositories without another browser consent)",
|
|
363
371
|
"github status": "ohmyhost github status --organization ULID --json",
|
|
@@ -911,6 +919,18 @@ export class ProductCli {
|
|
|
911
919
|
: { next_action: this.githubConnectAction(command.organizationId) }),
|
|
912
920
|
});
|
|
913
921
|
}
|
|
922
|
+
if (
|
|
923
|
+
command.kind === "connection-begin" ||
|
|
924
|
+
command.kind === "connection-list" ||
|
|
925
|
+
command.kind === "connection-status" ||
|
|
926
|
+
command.kind === "connection-discover" ||
|
|
927
|
+
command.kind === "connection-disconnect"
|
|
928
|
+
) {
|
|
929
|
+
const api = await this.authenticatedApi(command.credentialStore, signal);
|
|
930
|
+
if (!api.connection) throw new ResponseContractError();
|
|
931
|
+
const result = await api.connection(command);
|
|
932
|
+
return success(name, { status: "ok", result });
|
|
933
|
+
}
|
|
914
934
|
if (command.kind === "organization-mcp-connections-list") {
|
|
915
935
|
const api = await this.authenticatedApi(command.credentialStore, signal);
|
|
916
936
|
const page = parseOrganizationMcpConnectionList(
|
|
@@ -3921,6 +3941,11 @@ const parsedCommandName = (command: ProductCliCommand): CommandLabel => {
|
|
|
3921
3941
|
if (command.kind === "github-connect") return "github connect";
|
|
3922
3942
|
if (command.kind === "github-status") return "github status";
|
|
3923
3943
|
if (command.kind === "github-disconnect") return "github disconnect";
|
|
3944
|
+
if (command.kind === "connection-begin") return "connection begin";
|
|
3945
|
+
if (command.kind === "connection-list") return "connection list";
|
|
3946
|
+
if (command.kind === "connection-status") return "connection status";
|
|
3947
|
+
if (command.kind === "connection-discover") return "connection discover";
|
|
3948
|
+
if (command.kind === "connection-disconnect") return "connection disconnect";
|
|
3924
3949
|
if (command.kind === "organization-mcp-connections-list")
|
|
3925
3950
|
return "organization mcp-connections list";
|
|
3926
3951
|
if (command.kind === "organization-mcp-connection-revoke")
|
|
@@ -131,6 +131,43 @@ 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-disconnect";
|
|
165
|
+
readonly organizationId: string;
|
|
166
|
+
readonly grantId: string;
|
|
167
|
+
readonly idempotencyKey: string;
|
|
168
|
+
readonly yes: true;
|
|
169
|
+
readonly credentialStore: "native";
|
|
170
|
+
}
|
|
134
171
|
| {
|
|
135
172
|
readonly kind: "organization-mcp-connections-list";
|
|
136
173
|
readonly organizationId: string;
|
|
@@ -1135,6 +1172,11 @@ export type RecognizedCommandLabel =
|
|
|
1135
1172
|
| "organization use"
|
|
1136
1173
|
| "organization mcp-connections list"
|
|
1137
1174
|
| "organization mcp-connections revoke"
|
|
1175
|
+
| "connection begin"
|
|
1176
|
+
| "connection list"
|
|
1177
|
+
| "connection status"
|
|
1178
|
+
| "connection discover"
|
|
1179
|
+
| "connection disconnect"
|
|
1138
1180
|
| "github connect"
|
|
1139
1181
|
| "github status"
|
|
1140
1182
|
| "github disconnect"
|
|
@@ -1269,6 +1311,11 @@ export const recognizedCommandLabel = (argv: readonly string[]): RecognizedComma
|
|
|
1269
1311
|
)
|
|
1270
1312
|
return value;
|
|
1271
1313
|
if (value === "profile" && values[0] === "list") return "profile list";
|
|
1314
|
+
if (
|
|
1315
|
+
value === "connection" &&
|
|
1316
|
+
["begin", "list", "status", "discover", "disconnect"].includes(values[0] ?? "")
|
|
1317
|
+
)
|
|
1318
|
+
return `connection ${values[0]}` as RecognizedCommandLabel;
|
|
1272
1319
|
if (value === "github" && values[0] === "connect") return "github connect";
|
|
1273
1320
|
if (value === "github" && values[0] === "status") return "github status";
|
|
1274
1321
|
if (value === "github" && values[0] === "disconnect") return "github disconnect";
|
|
@@ -2106,6 +2153,108 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
|
|
|
2106
2153
|
}
|
|
2107
2154
|
: { kind: "github-status", organizationId, credentialStore };
|
|
2108
2155
|
}
|
|
2156
|
+
if (first === "connection") {
|
|
2157
|
+
const operation = values.shift();
|
|
2158
|
+
if (wait || follow || stdin || yes !== (operation === "disconnect"))
|
|
2159
|
+
throw new InvalidCommandError();
|
|
2160
|
+
const options = parseOptionalOptions(values, [
|
|
2161
|
+
"--organization",
|
|
2162
|
+
"--project",
|
|
2163
|
+
"--environment",
|
|
2164
|
+
"--grant",
|
|
2165
|
+
"--request",
|
|
2166
|
+
"--idempotency-key",
|
|
2167
|
+
"--provider-organization",
|
|
2168
|
+
"--team",
|
|
2169
|
+
] as const);
|
|
2170
|
+
const org = options["--organization"];
|
|
2171
|
+
if (!org || !ORGANIZATION_ULID.test(org)) throw new InvalidCommandError();
|
|
2172
|
+
const exact = (names: string[]) =>
|
|
2173
|
+
Object.keys(options).every((k) => names.includes(k)) &&
|
|
2174
|
+
names.every((k) => Object.hasOwn(options, k));
|
|
2175
|
+
const scoped = () =>
|
|
2176
|
+
options["--project"] &&
|
|
2177
|
+
options["--environment"] &&
|
|
2178
|
+
ORGANIZATION_ULID.test(options["--project"]) &&
|
|
2179
|
+
ORGANIZATION_ULID.test(options["--environment"]);
|
|
2180
|
+
if (operation === "list" && exact(["--organization"]))
|
|
2181
|
+
return { kind: "connection-list", organizationId: org, credentialStore };
|
|
2182
|
+
if (
|
|
2183
|
+
operation === "begin" &&
|
|
2184
|
+
scoped() &&
|
|
2185
|
+
exact(["--organization", "--project", "--environment", "--idempotency-key"])
|
|
2186
|
+
)
|
|
2187
|
+
return {
|
|
2188
|
+
kind: "connection-begin",
|
|
2189
|
+
organizationId: org,
|
|
2190
|
+
projectId: options["--project"] ?? "",
|
|
2191
|
+
environmentId: options["--environment"] ?? "",
|
|
2192
|
+
idempotencyKey: options["--idempotency-key"] ?? "",
|
|
2193
|
+
credentialStore,
|
|
2194
|
+
};
|
|
2195
|
+
if (
|
|
2196
|
+
operation === "status" &&
|
|
2197
|
+
exact(["--organization", "--request"]) &&
|
|
2198
|
+
/^[a-f0-9]{64}$/u.test(options["--request"] ?? "")
|
|
2199
|
+
)
|
|
2200
|
+
return {
|
|
2201
|
+
kind: "connection-status",
|
|
2202
|
+
organizationId: org,
|
|
2203
|
+
requestId: options["--request"] ?? "",
|
|
2204
|
+
credentialStore,
|
|
2205
|
+
};
|
|
2206
|
+
if (
|
|
2207
|
+
operation === "disconnect" &&
|
|
2208
|
+
exact(["--organization", "--grant", "--idempotency-key"]) &&
|
|
2209
|
+
ORGANIZATION_ULID.test(options["--grant"] ?? "")
|
|
2210
|
+
)
|
|
2211
|
+
return {
|
|
2212
|
+
kind: "connection-disconnect",
|
|
2213
|
+
organizationId: org,
|
|
2214
|
+
grantId: options["--grant"] ?? "",
|
|
2215
|
+
idempotencyKey: options["--idempotency-key"] ?? "",
|
|
2216
|
+
yes: true,
|
|
2217
|
+
credentialStore,
|
|
2218
|
+
};
|
|
2219
|
+
if (
|
|
2220
|
+
operation === "discover" &&
|
|
2221
|
+
scoped() &&
|
|
2222
|
+
ORGANIZATION_ULID.test(options["--grant"] ?? "") &&
|
|
2223
|
+
Object.keys(options).every((k) =>
|
|
2224
|
+
[
|
|
2225
|
+
"--organization",
|
|
2226
|
+
"--project",
|
|
2227
|
+
"--environment",
|
|
2228
|
+
"--grant",
|
|
2229
|
+
"--provider-organization",
|
|
2230
|
+
"--team",
|
|
2231
|
+
].includes(k),
|
|
2232
|
+
)
|
|
2233
|
+
) {
|
|
2234
|
+
const number = (v: string | undefined) =>
|
|
2235
|
+
v && /^[1-9][0-9]{0,14}$/u.test(v) && Number.isSafeInteger(Number(v))
|
|
2236
|
+
? Number(v)
|
|
2237
|
+
: undefined;
|
|
2238
|
+
const providerOrganizationId = number(options["--provider-organization"]),
|
|
2239
|
+
teamId = number(options["--team"]);
|
|
2240
|
+
if (
|
|
2241
|
+
(options["--provider-organization"] && !providerOrganizationId) ||
|
|
2242
|
+
(options["--team"] && (!teamId || !providerOrganizationId))
|
|
2243
|
+
)
|
|
2244
|
+
throw new InvalidCommandError();
|
|
2245
|
+
return {
|
|
2246
|
+
kind: "connection-discover",
|
|
2247
|
+
organizationId: org,
|
|
2248
|
+
projectId: options["--project"] ?? "",
|
|
2249
|
+
environmentId: options["--environment"] ?? "",
|
|
2250
|
+
grantId: options["--grant"] ?? "",
|
|
2251
|
+
...(providerOrganizationId ? { providerOrganizationId } : {}),
|
|
2252
|
+
...(teamId ? { teamId } : {}),
|
|
2253
|
+
credentialStore,
|
|
2254
|
+
};
|
|
2255
|
+
}
|
|
2256
|
+
throw new InvalidCommandError();
|
|
2257
|
+
}
|
|
2109
2258
|
if (first === "organization" && values[0] === "mcp-connections") {
|
|
2110
2259
|
values.shift();
|
|
2111
2260
|
const subcommand = values.shift();
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import { parseConnectionResponse } from "@ohmyhost/contracts/connection-management";
|
|
2
|
+
import {
|
|
3
|
+
beginConnection,
|
|
4
|
+
listConnections,
|
|
5
|
+
getConnectionRequest,
|
|
6
|
+
discoverConnection,
|
|
7
|
+
disconnectConnection,
|
|
8
|
+
} from "@ohmyhost/sdk-ts";
|
|
9
|
+
import type { ProductCliCommand } from "./command.js";
|
|
1
10
|
import { randomUUID } from "node:crypto";
|
|
2
11
|
import { parsePreviewView } from "@ohmyhost/contracts";
|
|
3
12
|
import {
|
|
@@ -290,7 +299,19 @@ export interface DatabaseTableAnswer {
|
|
|
290
299
|
};
|
|
291
300
|
}
|
|
292
301
|
|
|
302
|
+
export type ConnectionCommand = Extract<
|
|
303
|
+
ProductCliCommand,
|
|
304
|
+
{
|
|
305
|
+
kind:
|
|
306
|
+
| "connection-begin"
|
|
307
|
+
| "connection-list"
|
|
308
|
+
| "connection-status"
|
|
309
|
+
| "connection-discover"
|
|
310
|
+
| "connection-disconnect";
|
|
311
|
+
}
|
|
312
|
+
>;
|
|
293
313
|
export interface ProductApi {
|
|
314
|
+
connection?(command: ConnectionCommand): Promise<unknown>;
|
|
294
315
|
preview?(
|
|
295
316
|
action: "get" | "open" | "stop" | "rotate",
|
|
296
317
|
input: { projectId: string; environment: "dev" | "prod"; idempotencyKey?: string },
|
|
@@ -762,8 +783,65 @@ function hasExactKeys(value: Record<string, unknown>, keys: readonly string[]):
|
|
|
762
783
|
return Object.keys(value).sort().join(",") === [...keys].sort().join(",");
|
|
763
784
|
}
|
|
764
785
|
|
|
786
|
+
export async function executeConnectionCommand(
|
|
787
|
+
client: OhMyHostClient,
|
|
788
|
+
origin: string,
|
|
789
|
+
command: ConnectionCommand,
|
|
790
|
+
): Promise<unknown> {
|
|
791
|
+
const organization_id = command.organizationId;
|
|
792
|
+
let result: unknown;
|
|
793
|
+
switch (command.kind) {
|
|
794
|
+
case "connection-begin":
|
|
795
|
+
result = await beginConnection(
|
|
796
|
+
{
|
|
797
|
+
organization_id,
|
|
798
|
+
"Idempotency-Key": command.idempotencyKey,
|
|
799
|
+
connectionBegin: {
|
|
800
|
+
provider: "make",
|
|
801
|
+
project_id: command.projectId,
|
|
802
|
+
environment_id: command.environmentId,
|
|
803
|
+
},
|
|
804
|
+
},
|
|
805
|
+
{ client: client },
|
|
806
|
+
);
|
|
807
|
+
break;
|
|
808
|
+
case "connection-list":
|
|
809
|
+
result = await listConnections({ organization_id }, { client: client });
|
|
810
|
+
break;
|
|
811
|
+
case "connection-status":
|
|
812
|
+
result = await getConnectionRequest(
|
|
813
|
+
{ organization_id, request_id: command.requestId },
|
|
814
|
+
{ client: client },
|
|
815
|
+
);
|
|
816
|
+
break;
|
|
817
|
+
case "connection-discover":
|
|
818
|
+
result = await discoverConnection(
|
|
819
|
+
{
|
|
820
|
+
organization_id,
|
|
821
|
+
grant_id: command.grantId,
|
|
822
|
+
project_id: command.projectId,
|
|
823
|
+
environment_id: command.environmentId,
|
|
824
|
+
...(command.providerOrganizationId === undefined
|
|
825
|
+
? {}
|
|
826
|
+
: { provider_organization_id: command.providerOrganizationId }),
|
|
827
|
+
...(command.teamId === undefined ? {} : { team_id: command.teamId }),
|
|
828
|
+
},
|
|
829
|
+
{ client: client },
|
|
830
|
+
);
|
|
831
|
+
break;
|
|
832
|
+
case "connection-disconnect":
|
|
833
|
+
result = await disconnectConnection(
|
|
834
|
+
{ organization_id, grant_id: command.grantId, "Idempotency-Key": command.idempotencyKey },
|
|
835
|
+
{ client: client },
|
|
836
|
+
);
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
return parseConnectionResponse(command.kind, result, origin);
|
|
840
|
+
}
|
|
841
|
+
|
|
765
842
|
export class GeneratedSdkProductApi implements ProductApi {
|
|
766
843
|
readonly #client: OhMyHostClient;
|
|
844
|
+
readonly #connectionOrigin: string;
|
|
767
845
|
public readonly managedSource: ManagedSourceApi;
|
|
768
846
|
|
|
769
847
|
public constructor(
|
|
@@ -771,10 +849,15 @@ export class GeneratedSdkProductApi implements ProductApi {
|
|
|
771
849
|
accessToken: string | (() => Promise<string>),
|
|
772
850
|
fetch: typeof globalThis.fetch,
|
|
773
851
|
) {
|
|
852
|
+
this.#connectionOrigin = new URL(baseUrl).origin;
|
|
774
853
|
this.#client = createClient({ auth: accessToken, baseUrl, fetch, throwOnError: true });
|
|
775
854
|
this.managedSource = new GeneratedSdkManagedSourceApi(() => this.#client);
|
|
776
855
|
}
|
|
777
856
|
|
|
857
|
+
public async connection(command: ConnectionCommand): Promise<unknown> {
|
|
858
|
+
return executeConnectionCommand(this.#client, this.#connectionOrigin, command);
|
|
859
|
+
}
|
|
860
|
+
|
|
778
861
|
public async changeDatabaseCompute(
|
|
779
862
|
input: {
|
|
780
863
|
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,90 @@
|
|
|
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
|
+
raw: unknown,
|
|
36
|
+
expectedOrigin?: string,
|
|
37
|
+
): unknown {
|
|
38
|
+
if (kind === "connection-begin") {
|
|
39
|
+
const v = record(raw, ["request_id", "url", "expires_at"]);
|
|
40
|
+
date(v["expires_at"]);
|
|
41
|
+
if (
|
|
42
|
+
typeof v["request_id"] !== "string" ||
|
|
43
|
+
!/^[a-f0-9]{64}$/u.test(v["request_id"]) ||
|
|
44
|
+
typeof v["url"] !== "string"
|
|
45
|
+
)
|
|
46
|
+
throw new TypeError("Invalid connection response");
|
|
47
|
+
const url = new URL(v["url"]);
|
|
48
|
+
if (
|
|
49
|
+
!["https://app.ohmyho.st", "https://dev.app.ohmyho.st"].includes(url.origin) ||
|
|
50
|
+
(expectedOrigin !== undefined && url.origin !== expectedOrigin) ||
|
|
51
|
+
url.pathname !== "/connections/authorize" ||
|
|
52
|
+
url.hash ||
|
|
53
|
+
url.searchParams.size !== 1 ||
|
|
54
|
+
!/^[A-Za-z0-9_-]{43}$/u.test(url.searchParams.get("request") ?? "")
|
|
55
|
+
)
|
|
56
|
+
throw new TypeError("Invalid connection response");
|
|
57
|
+
} else if (kind === "connection-status") {
|
|
58
|
+
const v = record(raw, ["state", "expires_at"]);
|
|
59
|
+
date(v["expires_at"]);
|
|
60
|
+
if (!["pending", "consumed", "expired"].includes(String(v["state"])))
|
|
61
|
+
throw new TypeError("Invalid connection response");
|
|
62
|
+
} else if (kind === "connection-disconnect") {
|
|
63
|
+
const v = record(raw, ["state"]);
|
|
64
|
+
if (!["disconnected", "revocation_pending"].includes(String(v["state"])))
|
|
65
|
+
throw new TypeError("Invalid connection response");
|
|
66
|
+
} else if (kind === "connection-discover") {
|
|
67
|
+
const v = record(raw, ["organizations", "teams", "connections"]);
|
|
68
|
+
items(v["organizations"]);
|
|
69
|
+
items(v["teams"]);
|
|
70
|
+
items(v["connections"]);
|
|
71
|
+
} else {
|
|
72
|
+
const v = record(raw, ["connections"]);
|
|
73
|
+
if (!Array.isArray(v["connections"]) || v["connections"].length > 10000)
|
|
74
|
+
throw new TypeError("Invalid connection response");
|
|
75
|
+
for (const row of v["connections"]) {
|
|
76
|
+
const grant = record(row, ["id", "provider", "state", "created_at"]);
|
|
77
|
+
date(grant["created_at"]);
|
|
78
|
+
if (
|
|
79
|
+
typeof grant["id"] !== "string" ||
|
|
80
|
+
!ulid.test(grant["id"]) ||
|
|
81
|
+
grant["provider"] !== "make" ||
|
|
82
|
+
!["active", "refreshing", "reconnect_required", "disconnecting", "disconnected"].includes(
|
|
83
|
+
String(grant["state"]),
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
throw new TypeError("Invalid connection response");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return raw;
|
|
90
|
+
}
|
|
@@ -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") ||
|
|
@@ -6,6 +6,7 @@ export {
|
|
|
6
6
|
applyPaidProjectDomain,
|
|
7
7
|
authorizeApplicationDomainIdentityDns,
|
|
8
8
|
authorizeWorkspaceMailDomainDns,
|
|
9
|
+
beginConnection,
|
|
9
10
|
changeDatabaseCompute,
|
|
10
11
|
changeManagedSource,
|
|
11
12
|
changeProjectHandle,
|
|
@@ -48,7 +49,9 @@ export {
|
|
|
48
49
|
detachProjectMailDomainBinding,
|
|
49
50
|
diffManagedSource,
|
|
50
51
|
disableManagedMailReceiving,
|
|
52
|
+
disconnectConnection,
|
|
51
53
|
disconnectGithubOrganization,
|
|
54
|
+
discoverConnection,
|
|
52
55
|
ensureProjectDevShareLink,
|
|
53
56
|
getAccountProfile,
|
|
54
57
|
getApplicationDomainIdentity,
|
|
@@ -56,6 +59,7 @@ export {
|
|
|
56
59
|
getBillingCheckout,
|
|
57
60
|
getBillingRecharge,
|
|
58
61
|
getCloudflareDnsAuthorizationStatus,
|
|
62
|
+
getConnectionRequest,
|
|
59
63
|
getCurrentIdentity,
|
|
60
64
|
getDatabaseCompute,
|
|
61
65
|
getDatabaseWebhookSubscription,
|
|
@@ -97,6 +101,8 @@ export {
|
|
|
97
101
|
initializeManagedSource,
|
|
98
102
|
linkProjectSource,
|
|
99
103
|
listAuditEvents,
|
|
104
|
+
listConnectionProviders,
|
|
105
|
+
listConnections,
|
|
100
106
|
listDeployments,
|
|
101
107
|
listEnvironmentSecrets,
|
|
102
108
|
listFunctionRuns,
|
|
@@ -206,6 +212,11 @@ export type {
|
|
|
206
212
|
AuthorizeWorkspaceMailDomainDnsErrors,
|
|
207
213
|
AuthorizeWorkspaceMailDomainDnsResponse,
|
|
208
214
|
AuthorizeWorkspaceMailDomainDnsResponses,
|
|
215
|
+
BeginConnectionData,
|
|
216
|
+
BeginConnectionError,
|
|
217
|
+
BeginConnectionErrors,
|
|
218
|
+
BeginConnectionResponse,
|
|
219
|
+
BeginConnectionResponses,
|
|
209
220
|
BillingCheckout,
|
|
210
221
|
BillingPortal,
|
|
211
222
|
BillingRecharge,
|
|
@@ -271,6 +282,15 @@ export type {
|
|
|
271
282
|
ConnectGithubOrganizationRequest,
|
|
272
283
|
ConnectGithubOrganizationResponse,
|
|
273
284
|
ConnectGithubOrganizationResponses,
|
|
285
|
+
ConnectionBegin,
|
|
286
|
+
ConnectionDisconnection,
|
|
287
|
+
ConnectionDiscovery,
|
|
288
|
+
ConnectionDiscoveryItem,
|
|
289
|
+
ConnectionGrant,
|
|
290
|
+
ConnectionGrantList,
|
|
291
|
+
ConnectionHandoff,
|
|
292
|
+
ConnectionProviders,
|
|
293
|
+
ConnectionRequestStatus,
|
|
274
294
|
CostEstimate,
|
|
275
295
|
CreateBillingCheckoutData,
|
|
276
296
|
CreateBillingCheckoutError,
|
|
@@ -492,11 +512,21 @@ export type {
|
|
|
492
512
|
DisableManagedMailReceivingErrors,
|
|
493
513
|
DisableManagedMailReceivingResponse,
|
|
494
514
|
DisableManagedMailReceivingResponses,
|
|
515
|
+
DisconnectConnectionData,
|
|
516
|
+
DisconnectConnectionError,
|
|
517
|
+
DisconnectConnectionErrors,
|
|
518
|
+
DisconnectConnectionResponse,
|
|
519
|
+
DisconnectConnectionResponses,
|
|
495
520
|
DisconnectGithubOrganizationData,
|
|
496
521
|
DisconnectGithubOrganizationError,
|
|
497
522
|
DisconnectGithubOrganizationErrors,
|
|
498
523
|
DisconnectGithubOrganizationResponse,
|
|
499
524
|
DisconnectGithubOrganizationResponses,
|
|
525
|
+
DiscoverConnectionData,
|
|
526
|
+
DiscoverConnectionError,
|
|
527
|
+
DiscoverConnectionErrors,
|
|
528
|
+
DiscoverConnectionResponse,
|
|
529
|
+
DiscoverConnectionResponses,
|
|
500
530
|
EnsureProjectDevShareLinkData,
|
|
501
531
|
EnsureProjectDevShareLinkError,
|
|
502
532
|
EnsureProjectDevShareLinkErrors,
|
|
@@ -545,6 +575,11 @@ export type {
|
|
|
545
575
|
GetCloudflareDnsAuthorizationStatusErrors,
|
|
546
576
|
GetCloudflareDnsAuthorizationStatusResponse,
|
|
547
577
|
GetCloudflareDnsAuthorizationStatusResponses,
|
|
578
|
+
GetConnectionRequestData,
|
|
579
|
+
GetConnectionRequestError,
|
|
580
|
+
GetConnectionRequestErrors,
|
|
581
|
+
GetConnectionRequestResponse,
|
|
582
|
+
GetConnectionRequestResponses,
|
|
548
583
|
GetCurrentIdentityData,
|
|
549
584
|
GetCurrentIdentityError,
|
|
550
585
|
GetCurrentIdentityErrors,
|
|
@@ -763,6 +798,16 @@ export type {
|
|
|
763
798
|
ListAuditEventsErrors,
|
|
764
799
|
ListAuditEventsResponse,
|
|
765
800
|
ListAuditEventsResponses,
|
|
801
|
+
ListConnectionProvidersData,
|
|
802
|
+
ListConnectionProvidersError,
|
|
803
|
+
ListConnectionProvidersErrors,
|
|
804
|
+
ListConnectionProvidersResponse,
|
|
805
|
+
ListConnectionProvidersResponses,
|
|
806
|
+
ListConnectionsData,
|
|
807
|
+
ListConnectionsError,
|
|
808
|
+
ListConnectionsErrors,
|
|
809
|
+
ListConnectionsResponse,
|
|
810
|
+
ListConnectionsResponses,
|
|
766
811
|
ListDeploymentsData,
|
|
767
812
|
ListDeploymentsError,
|
|
768
813
|
ListDeploymentsErrors,
|