@supacloud/admin 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +54 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -23024,26 +23024,69 @@ function detectSource(sources) {
23024
23024
  return present.has("env") ? "env" : "dotenv";
23025
23025
  return "mixed";
23026
23026
  }
23027
+ function normalizeUrl(value) {
23028
+ const trimmed = value.trim().replace(/\/+$/, "");
23029
+ if (!trimmed)
23030
+ return "";
23031
+ try {
23032
+ return new URL(trimmed).toString().replace(/\/+$/, "");
23033
+ } catch {
23034
+ return "";
23035
+ }
23036
+ }
23037
+ function hostFromUrl(value) {
23038
+ try {
23039
+ return new URL(value).hostname;
23040
+ } catch {
23041
+ return "";
23042
+ }
23043
+ }
23044
+ function inferManagementApiUrlFromSupabaseUrl(value, projectRef = "") {
23045
+ const normalized = normalizeUrl(value);
23046
+ if (!normalized)
23047
+ return "";
23048
+ const url = new URL(normalized);
23049
+ const host = url.hostname;
23050
+ if (host.startsWith("api.")) {
23051
+ url.hostname = `studio.${host.slice("api.".length)}`;
23052
+ return url.toString().replace(/\/+$/, "");
23053
+ }
23054
+ const ref = projectRef.trim();
23055
+ if (ref && host.startsWith(`${ref}.api.`)) {
23056
+ url.hostname = `studio-${ref}.${host.slice(`${ref}.api.`.length)}`;
23057
+ return url.toString().replace(/\/+$/, "");
23058
+ }
23059
+ const managedHostMatch = host.match(/^([a-z0-9-]+)\.api\.(.+)$/i);
23060
+ if (managedHostMatch) {
23061
+ url.hostname = `studio-${managedHostMatch[1]}.${managedHostMatch[2]}`;
23062
+ return url.toString().replace(/\/+$/, "");
23063
+ }
23064
+ return normalized;
23065
+ }
23027
23066
  function resolveSupaCloudContext(env = process.env, cwd = process.cwd()) {
23028
23067
  const dotenv = readDotEnvFile(cwd);
23029
- const inferredUrl = pickValue(env, dotenv, ["SUPABASE_URL", "SUPACLOUD_API_URL"]);
23068
+ const supabaseUrl = pickValue(env, dotenv, ["SUPABASE_URL"]);
23069
+ const explicitApiUrl = pickValue(env, dotenv, ["SUPACLOUD_API_URL", "SUPACLOUD_MANAGEMENT_API_URL", "MANAGEMENT_API_URL"]);
23030
23070
  const inferredToken = pickValue(env, dotenv, ["SUPABASE_SERVICE_ROLE_KEY", "SUPACLOUD_API_TOKEN"]);
23071
+ const projectRef = pickValue(env, dotenv, ["SUPACLOUD_PROJECT_REF", "X_PROJECT_REF"]).value;
23031
23072
  const hostFromEnv = env.SUPACLOUD_HOST;
23032
- const hostFromUrl = inferredUrl.value ? new URL(inferredUrl.value).hostname : "";
23073
+ const normalizedSupabaseUrl = normalizeUrl(supabaseUrl.value);
23074
+ const apiUrl = normalizeUrl(explicitApiUrl.value) || inferManagementApiUrlFromSupabaseUrl(normalizedSupabaseUrl, projectRef) || (hostFromEnv ? `http://${hostFromEnv}:9090` : "");
23075
+ const resolvedHostFromUrl = hostFromUrl(apiUrl || normalizedSupabaseUrl);
23033
23076
  return {
23034
- host: hostFromEnv ?? hostFromUrl,
23077
+ host: hostFromEnv ?? resolvedHostFromUrl,
23035
23078
  sshUser: env.SUPACLOUD_SSH_USER ?? "root",
23036
23079
  sshPort: parseInt(env.SUPACLOUD_SSH_PORT ?? "22", 10),
23037
23080
  sshKey: env.SUPACLOUD_SSH_KEY ?? resolve(homedir(), ".ssh", "id_rsa"),
23038
23081
  sshPass: env.SUPACLOUD_SSH_PASS ?? "",
23039
- apiUrl: env.SUPACLOUD_API_URL ?? (inferredUrl.value ? inferredUrl.value.replace(/\/+$/, "") : hostFromEnv ? `http://${hostFromEnv}:9090` : ""),
23082
+ apiUrl,
23040
23083
  apiToken: env.SUPACLOUD_API_TOKEN ?? inferredToken.value,
23041
- projectRef: env.SUPACLOUD_PROJECT_REF ?? "",
23084
+ projectRef,
23042
23085
  readOnly: env.SUPACLOUD_READ_ONLY === "true",
23043
- inferredSupabaseUrl: inferredUrl.value,
23086
+ inferredSupabaseUrl: normalizedSupabaseUrl,
23044
23087
  inferredServiceRoleKey: inferredToken.value,
23045
23088
  source: detectSource([
23046
- inferredUrl.value ? inferredUrl.source : "none",
23089
+ supabaseUrl.value || explicitApiUrl.value ? supabaseUrl.value ? supabaseUrl.source : explicitApiUrl.source : "none",
23047
23090
  inferredToken.value ? inferredToken.source : "none"
23048
23091
  ])
23049
23092
  };
@@ -23410,6 +23453,9 @@ function assertSafeGithubProxy(value) {
23410
23453
  }
23411
23454
  return parsed.toString();
23412
23455
  }
23456
+ function deriveStudioDomain(publicDomain) {
23457
+ return `studio.${publicDomain.trim().replace(/^(?:api|studio)\./i, "")}`;
23458
+ }
23413
23459
  function getExecTimeoutMs(timeoutSeconds) {
23414
23460
  const seconds = timeoutSeconds || 60;
23415
23461
  if (!Number.isFinite(seconds) || seconds <= 0 || seconds > SAFE_TIMEOUT_SECONDS) {
@@ -23506,7 +23552,7 @@ ${clone.stderr.slice(-500)}`;
23506
23552
  }
23507
23553
  const envLines = [
23508
23554
  `SUPABASE_PUBLIC_DOMAIN=${args.public_domain}`,
23509
- `SUPABASE_STUDIO_DOMAIN=${args.studio_domain ?? args.public_domain}`,
23555
+ `SUPABASE_STUDIO_DOMAIN=${args.studio_domain ?? deriveStudioDomain(args.public_domain)}`,
23510
23556
  `EDGE_RUNTIME=${args.edge_runtime || "bun"}`,
23511
23557
  `S3_STORAGE_TYPE=${args.storage_type || "juicefs"}`,
23512
23558
  args.postgres_password ? `POSTGRES_PASSWORD=${args.postgres_password}` : "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/admin",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Platform administration CLI for SupaCloud operators",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",