@amerged/ohmyhost-cli 0.1.59 → 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/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-KBB6XJQ7.js";
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amerged/ohmyhost-cli",
3
- "version": "0.1.59",
3
+ "version": "0.1.62",
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.59",
3
+ "version": "0.1.62",
4
4
  "private": true,
5
5
  "ohmyhost": {
6
6
  "deployment": "production",
@@ -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",
@@ -419,6 +427,14 @@ const HELP_USAGE = Object.freeze({
419
427
  "ohmyhost project notes set --project ULID --version NUMBER --markdown TEXT --idempotency-key KEY --json (no credentials or signed URLs)",
420
428
  "project status": "ohmyhost project status --project ULID --json",
421
429
  "project dev add": "ohmyhost project dev add --project ULID --idempotency-key KEY --json",
430
+ "project preview get":
431
+ "ohmyhost project preview get --project ULID --environment dev|prod --json",
432
+ "project preview open":
433
+ "ohmyhost project preview open --project ULID --environment dev|prod --json",
434
+ "project preview stop":
435
+ "ohmyhost project preview stop --project ULID --environment dev|prod --idempotency-key KEY --yes --json",
436
+ "project preview rotate":
437
+ "ohmyhost project preview rotate --project ULID --environment dev|prod --idempotency-key KEY --yes --json",
422
438
  "project dev-access create": "ohmyhost project dev-access create --project ULID --json",
423
439
  "project dev-share link": "ohmyhost project dev-share link --project ULID --json",
424
440
  "project dev-share rotate":
@@ -903,6 +919,18 @@ export class ProductCli {
903
919
  : { next_action: this.githubConnectAction(command.organizationId) }),
904
920
  });
905
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
+ }
906
934
  if (command.kind === "organization-mcp-connections-list") {
907
935
  const api = await this.authenticatedApi(command.credentialStore, signal);
908
936
  const page = parseOrganizationMcpConnectionList(
@@ -1201,6 +1229,29 @@ export class ProductCli {
1201
1229
  if (command.kind === "project-status") return await this.getProjectStatus(command, signal);
1202
1230
  if (command.kind === "project-development-add")
1203
1231
  return await this.addProjectDevelopment(command, signal);
1232
+ if (
1233
+ command.kind === "project-preview-get" ||
1234
+ command.kind === "project-preview-open" ||
1235
+ command.kind === "project-preview-stop" ||
1236
+ command.kind === "project-preview-rotate"
1237
+ ) {
1238
+ const api = await this.authenticatedApi(command.credentialStore, signal);
1239
+ if (!api.preview) throw new Error("Preview unavailable");
1240
+ const action = command.kind.slice("project-preview-".length) as
1241
+ | "get"
1242
+ | "open"
1243
+ | "stop"
1244
+ | "rotate";
1245
+ const preview = await api.preview(action, {
1246
+ projectId: command.projectId,
1247
+ environment: command.environment,
1248
+ ...("idempotencyKey" in command ? { idempotencyKey: command.idempotencyKey } : {}),
1249
+ });
1250
+ return success(`project preview ${action}` as RecognizedCommandLabel, {
1251
+ status: "succeeded",
1252
+ preview,
1253
+ });
1254
+ }
1204
1255
  if (command.kind === "project-dev-access-create")
1205
1256
  return await this.createDevAccessTicket(command, signal);
1206
1257
  if (command.kind === "project-flag-status" || command.kind === "project-flag-set") {
@@ -1401,7 +1452,9 @@ export class ProductCli {
1401
1452
  if (!api.managedMail) throw new Error("Mail unavailable");
1402
1453
  return success(command.label, { mail: await api.managedMail(command.request) });
1403
1454
  }
1404
- return await this.deleteEnvironmentSecret(command, signal);
1455
+ if (command.kind === "secret-delete")
1456
+ return await this.deleteEnvironmentSecret(command, signal);
1457
+ throw new Error("Unsupported command");
1405
1458
  } catch (error) {
1406
1459
  if (error instanceof UserTokenFileError || error instanceof PrivateSecretFileError)
1407
1460
  return failure(name, 3, error.code, false, error.message);
@@ -3888,6 +3941,11 @@ const parsedCommandName = (command: ProductCliCommand): CommandLabel => {
3888
3941
  if (command.kind === "github-connect") return "github connect";
3889
3942
  if (command.kind === "github-status") return "github status";
3890
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";
3891
3949
  if (command.kind === "organization-mcp-connections-list")
3892
3950
  return "organization mcp-connections list";
3893
3951
  if (command.kind === "organization-mcp-connection-revoke")
@@ -3899,6 +3957,10 @@ const parsedCommandName = (command: ProductCliCommand): CommandLabel => {
3899
3957
  if (command.kind === "project-notes-set") return "project notes set";
3900
3958
  if (command.kind === "project-status") return "project status";
3901
3959
  if (command.kind === "project-development-add") return "project dev add";
3960
+ if (command.kind === "project-preview-get") return "project preview get";
3961
+ if (command.kind === "project-preview-open") return "project preview open";
3962
+ if (command.kind === "project-preview-stop") return "project preview stop";
3963
+ if (command.kind === "project-preview-rotate") return "project preview rotate";
3902
3964
  if (command.kind === "project-dev-access-create") return "project dev-access create";
3903
3965
  if (command.kind === "project-dev-share-link") return "project dev-share link";
3904
3966
  if (command.kind === "project-dev-share-rotate") return "project dev-share rotate";
@@ -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;
@@ -371,6 +408,32 @@ export type ProductCliCommand =
371
408
  readonly idempotencyKey: string;
372
409
  readonly credentialStore: "native";
373
410
  }
411
+ | {
412
+ readonly kind: "project-preview-get";
413
+ readonly projectId: string;
414
+ readonly environment: "dev" | "prod";
415
+ readonly credentialStore: "native";
416
+ }
417
+ | {
418
+ readonly kind: "project-preview-open";
419
+ readonly projectId: string;
420
+ readonly environment: "dev" | "prod";
421
+ readonly credentialStore: "native";
422
+ }
423
+ | {
424
+ readonly kind: "project-preview-stop";
425
+ readonly projectId: string;
426
+ readonly environment: "dev" | "prod";
427
+ readonly idempotencyKey: string;
428
+ readonly credentialStore: "native";
429
+ }
430
+ | {
431
+ readonly kind: "project-preview-rotate";
432
+ readonly projectId: string;
433
+ readonly environment: "dev" | "prod";
434
+ readonly idempotencyKey: string;
435
+ readonly credentialStore: "native";
436
+ }
374
437
  | {
375
438
  readonly kind: "project-dev-share-link";
376
439
  readonly projectId: string;
@@ -1109,6 +1172,11 @@ export type RecognizedCommandLabel =
1109
1172
  | "organization use"
1110
1173
  | "organization mcp-connections list"
1111
1174
  | "organization mcp-connections revoke"
1175
+ | "connection begin"
1176
+ | "connection list"
1177
+ | "connection status"
1178
+ | "connection discover"
1179
+ | "connection disconnect"
1112
1180
  | "github connect"
1113
1181
  | "github status"
1114
1182
  | "github disconnect"
@@ -1117,6 +1185,10 @@ export type RecognizedCommandLabel =
1117
1185
  | "project dev add"
1118
1186
  | "project dev-access create"
1119
1187
  | "project dev-share link"
1188
+ | "project preview get"
1189
+ | "project preview open"
1190
+ | "project preview stop"
1191
+ | "project preview rotate"
1120
1192
  | "project dev-share rotate"
1121
1193
  | "project dev-share revoke"
1122
1194
  | "project dev-access mode"
@@ -1239,6 +1311,11 @@ export const recognizedCommandLabel = (argv: readonly string[]): RecognizedComma
1239
1311
  )
1240
1312
  return value;
1241
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;
1242
1319
  if (value === "github" && values[0] === "connect") return "github connect";
1243
1320
  if (value === "github" && values[0] === "status") return "github status";
1244
1321
  if (value === "github" && values[0] === "disconnect") return "github disconnect";
@@ -1284,6 +1361,12 @@ export const recognizedCommandLabel = (argv: readonly string[]): RecognizedComma
1284
1361
  return "project notes set";
1285
1362
  if (value === "project" && values[0] === "status") return "project status";
1286
1363
  if (value === "project" && values[0] === "dev" && values[1] === "add") return "project dev add";
1364
+ if (
1365
+ value === "project" &&
1366
+ values[0] === "preview" &&
1367
+ ["get", "open", "stop", "rotate"].includes(values[1] ?? "")
1368
+ )
1369
+ return `project preview ${values[1]}` as RecognizedCommandLabel;
1287
1370
  if (value === "project" && values[0] === "handle" && values[1] === "check")
1288
1371
  return "project handle check";
1289
1372
  if (value === "project" && values[0] === "handle" && values[1] === "set")
@@ -2070,6 +2153,108 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
2070
2153
  }
2071
2154
  : { kind: "github-status", organizationId, credentialStore };
2072
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
+ }
2073
2258
  if (first === "organization" && values[0] === "mcp-connections") {
2074
2259
  values.shift();
2075
2260
  const subcommand = values.shift();
@@ -2189,6 +2374,41 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
2189
2374
  const options = parseOptions(values, ["--handle"]);
2190
2375
  return { kind: "project-handle-check", handle: options["--handle"], credentialStore };
2191
2376
  }
2377
+ if (subcommand === "preview") {
2378
+ const action = values.shift();
2379
+ if (
2380
+ !action ||
2381
+ !["get", "open", "stop", "rotate"].includes(action) ||
2382
+ wait ||
2383
+ follow ||
2384
+ stdin ||
2385
+ (action === "stop" || action === "rotate") !== yes
2386
+ )
2387
+ throw new InvalidCommandError();
2388
+ const changing = action === "stop" || action === "rotate";
2389
+ const options = parseOptions(
2390
+ values,
2391
+ changing
2392
+ ? ["--project", "--environment", "--idempotency-key"]
2393
+ : ["--project", "--environment"],
2394
+ );
2395
+ const environment = options["--environment"];
2396
+ if (environment !== "dev" && environment !== "prod") throw new InvalidCommandError();
2397
+ if (changing)
2398
+ return {
2399
+ kind: action === "stop" ? "project-preview-stop" : "project-preview-rotate",
2400
+ projectId: options["--project"],
2401
+ environment,
2402
+ idempotencyKey: options["--idempotency-key"],
2403
+ credentialStore,
2404
+ };
2405
+ return {
2406
+ kind: action === "get" ? "project-preview-get" : "project-preview-open",
2407
+ projectId: options["--project"],
2408
+ environment,
2409
+ credentialStore,
2410
+ };
2411
+ }
2192
2412
  if (subcommand === "dev-share") {
2193
2413
  const action = values.shift();
2194
2414
  if (action === "link") {
@@ -1,4 +1,14 @@
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";
11
+ import { parsePreviewView } from "@ohmyhost/contracts";
2
12
  import {
3
13
  executeManagedMail,
4
14
  executeSharedMail,
@@ -126,6 +136,10 @@ import {
126
136
  createCloudflareDnsAuthorization,
127
137
  createProjectDevAccessTicket,
128
138
  ensureProjectDevShareLink,
139
+ getProjectPreview,
140
+ openProjectPreview,
141
+ stopProjectPreview,
142
+ rotateProjectPreviewToken,
129
143
  rotateProjectDevShareLink,
130
144
  revokeProjectDevShareLink,
131
145
  setProjectDevAccessMode,
@@ -285,7 +299,23 @@ export interface DatabaseTableAnswer {
285
299
  };
286
300
  }
287
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
+ >;
288
313
  export interface ProductApi {
314
+ connection?(command: ConnectionCommand): Promise<unknown>;
315
+ preview?(
316
+ action: "get" | "open" | "stop" | "rotate",
317
+ input: { projectId: string; environment: "dev" | "prod"; idempotencyKey?: string },
318
+ ): Promise<import("@ohmyhost/sdk-ts").Preview>;
289
319
  nativeAuth?(input: NativeAuthCommand): Promise<unknown>;
290
320
  readonly managedSource?: ManagedSourceApi;
291
321
  planProjectDataChange(input: {
@@ -753,8 +783,65 @@ function hasExactKeys(value: Record<string, unknown>, keys: readonly string[]):
753
783
  return Object.keys(value).sort().join(",") === [...keys].sort().join(",");
754
784
  }
755
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
+
756
842
  export class GeneratedSdkProductApi implements ProductApi {
757
843
  readonly #client: OhMyHostClient;
844
+ readonly #connectionOrigin: string;
758
845
  public readonly managedSource: ManagedSourceApi;
759
846
 
760
847
  public constructor(
@@ -762,10 +849,15 @@ export class GeneratedSdkProductApi implements ProductApi {
762
849
  accessToken: string | (() => Promise<string>),
763
850
  fetch: typeof globalThis.fetch,
764
851
  ) {
852
+ this.#connectionOrigin = new URL(baseUrl).origin;
765
853
  this.#client = createClient({ auth: accessToken, baseUrl, fetch, throwOnError: true });
766
854
  this.managedSource = new GeneratedSdkManagedSourceApi(() => this.#client);
767
855
  }
768
856
 
857
+ public async connection(command: ConnectionCommand): Promise<unknown> {
858
+ return executeConnectionCommand(this.#client, this.#connectionOrigin, command);
859
+ }
860
+
769
861
  public async changeDatabaseCompute(
770
862
  input: {
771
863
  projectId: string;
@@ -1525,6 +1617,31 @@ export class GeneratedSdkProductApi implements ProductApi {
1525
1617
  public async ensureDevShareLink(projectId: string) {
1526
1618
  return ensureProjectDevShareLink({ project_id: projectId }, { client: this.#client });
1527
1619
  }
1620
+ public async preview(
1621
+ action: "get" | "open" | "stop" | "rotate",
1622
+ input: { projectId: string; environment: "dev" | "prod"; idempotencyKey?: string },
1623
+ ) {
1624
+ const args = { project_id: input.projectId, environment: input.environment };
1625
+ const result =
1626
+ action === "get"
1627
+ ? await getProjectPreview(args, { client: this.#client })
1628
+ : action === "open"
1629
+ ? await openProjectPreview(args, { client: this.#client })
1630
+ : input.idempotencyKey === undefined
1631
+ ? (() => {
1632
+ throw new TypeError("Preview idempotency key is required");
1633
+ })()
1634
+ : action === "stop"
1635
+ ? await stopProjectPreview(
1636
+ { ...args, "Idempotency-Key": input.idempotencyKey },
1637
+ { client: this.#client },
1638
+ )
1639
+ : await rotateProjectPreviewToken(
1640
+ { ...args, "Idempotency-Key": input.idempotencyKey },
1641
+ { client: this.#client },
1642
+ );
1643
+ return parsePreviewView(result, input);
1644
+ }
1528
1645
  public async rotateDevShareLink(projectId: string, idempotencyKey: string) {
1529
1646
  return rotateProjectDevShareLink(
1530
1647
  { project_id: projectId, "Idempotency-Key": idempotencyKey },
@@ -191,6 +191,16 @@
191
191
  "source": "./src/usage-log.ts",
192
192
  "types": "./dist/usage-log.d.ts",
193
193
  "import": "./dist/usage-log.js"
194
+ },
195
+ "./connection-management": {
196
+ "source": "./src/connection-management.ts",
197
+ "types": "./dist/connection-management.d.ts",
198
+ "import": "./dist/connection-management.js"
199
+ },
200
+ "./previews": {
201
+ "source": "./src/previews.ts",
202
+ "types": "./dist/previews.d.ts",
203
+ "import": "./dist/previews.js"
194
204
  }
195
205
  },
196
206
  "scripts": {