freestyle-sandboxes 0.1.34 → 0.1.36

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 (6) hide show
  1. package/cli.mjs +78 -7
  2. package/index.cjs +1624 -1271
  3. package/index.d.cts +1016 -864
  4. package/index.d.mts +1016 -864
  5. package/index.mjs +1624 -1272
  6. package/package.json +1 -1
package/cli.mjs CHANGED
@@ -457,7 +457,7 @@ async function getTeamsForCli() {
457
457
  const stored = loadStoredAuth(config);
458
458
  if (!stored?.refreshToken) {
459
459
  throw new Error(
460
- "No authentication found. Please run 'freestyle login' first."
460
+ "No authentication found. Please run 'npx freestyle-sandboxes@latest login' first."
461
461
  );
462
462
  }
463
463
  const tokenResponse = await refreshStackAccessToken(
@@ -480,7 +480,7 @@ async function setDefaultTeam(teamId) {
480
480
  const stored = loadStoredAuth(config);
481
481
  if (!stored?.refreshToken) {
482
482
  throw new Error(
483
- "No authentication found. Please run 'freestyle login' first."
483
+ "No authentication found. Please run 'npx freestyle-sandboxes@latest login' first."
484
484
  );
485
485
  }
486
486
  const auth = {
@@ -499,6 +499,51 @@ function getDefaultTeamId() {
499
499
  return stored?.defaultTeamId;
500
500
  }
501
501
 
502
+ function normalizeCliProxyErrorWithStatus(errorText, status) {
503
+ const fallbackCode = status === 400 ? "BAD_REQUEST" : status === 401 ? "UNAUTHORIZED_ERROR" : status === 403 ? "FORBIDDEN" : "INTERNAL_ERROR";
504
+ try {
505
+ const parsed = JSON.parse(errorText);
506
+ if (typeof parsed.code === "string" && typeof parsed.message === "string") {
507
+ return {
508
+ body: JSON.stringify(parsed),
509
+ contentType: "application/json"
510
+ };
511
+ }
512
+ const message2 = [parsed.error, parsed.message, parsed.reason].find(
513
+ (value) => typeof value === "string" && value.length > 0
514
+ );
515
+ if (message2) {
516
+ const normalized2 = fallbackCode === "UNAUTHORIZED_ERROR" ? {
517
+ code: fallbackCode,
518
+ message: message2,
519
+ route: "/api/proxy/request",
520
+ reason: message2
521
+ } : {
522
+ code: fallbackCode,
523
+ message: message2
524
+ };
525
+ return {
526
+ body: JSON.stringify(normalized2),
527
+ contentType: "application/json"
528
+ };
529
+ }
530
+ } catch {
531
+ }
532
+ const message = errorText || "Request failed";
533
+ const normalized = fallbackCode === "UNAUTHORIZED_ERROR" ? {
534
+ code: fallbackCode,
535
+ message,
536
+ route: "/api/proxy/request",
537
+ reason: message
538
+ } : {
539
+ code: fallbackCode,
540
+ message
541
+ };
542
+ return {
543
+ body: JSON.stringify(normalized),
544
+ contentType: "application/json"
545
+ };
546
+ }
502
547
  function createProxyFetch(accessToken, teamId) {
503
548
  const dashboardApiUrl = process.env.FREESTYLE_DASHBOARD_URL || "https://dash.freestyle.sh";
504
549
  return async (url, init) => {
@@ -522,9 +567,16 @@ function createProxyFetch(accessToken, teamId) {
522
567
  });
523
568
  if (!proxyResponse.ok) {
524
569
  const errorText = await proxyResponse.text();
525
- return new Response(errorText, {
570
+ const normalizedError = normalizeCliProxyErrorWithStatus(
571
+ errorText,
572
+ proxyResponse.status
573
+ );
574
+ return new Response(normalizedError.body, {
526
575
  status: proxyResponse.status,
527
- statusText: proxyResponse.statusText
576
+ statusText: proxyResponse.statusText,
577
+ headers: {
578
+ "Content-Type": normalizedError.contentType
579
+ }
528
580
  });
529
581
  }
530
582
  const data = await proxyResponse.json();
@@ -543,14 +595,14 @@ async function getFreestyleClient(teamId) {
543
595
  const accessToken = await getStackAccessTokenForCli();
544
596
  if (!accessToken) {
545
597
  console.error(
546
- "Error: No API key found. Please run 'freestyle login' or set FREESTYLE_API_KEY in your .env file."
598
+ "Error: No API key found. Please run 'npx freestyle-sandboxes@latest login' or set FREESTYLE_API_KEY in your .env file."
547
599
  );
548
600
  process.exit(1);
549
601
  }
550
602
  const resolvedTeamId = process.env.FREESTYLE_TEAM_ID ?? getDefaultTeamId();
551
603
  if (!resolvedTeamId) {
552
604
  console.error(
553
- "Error: No team selected. Please run 'freestyle login' to set a default team."
605
+ "Error: No team selected. Please run 'npx freestyle-sandboxes@latest login' to set a default team."
554
606
  );
555
607
  process.exit(1);
556
608
  }
@@ -1911,6 +1963,25 @@ const logoutCommand = {
1911
1963
  }
1912
1964
  };
1913
1965
 
1966
+ const whoamiCommand = {
1967
+ command: "whoami",
1968
+ describe: "Display information about the currently authenticated user",
1969
+ builder: (yargs) => yargs,
1970
+ handler: async (_argv) => {
1971
+ loadEnv();
1972
+ try {
1973
+ const client = await getFreestyleClient();
1974
+ const info = await client.whoami();
1975
+ console.log(`Account ID: ${info.accountId}`);
1976
+ if (info.identityId) {
1977
+ console.log(`Identity ID: ${info.identityId}`);
1978
+ }
1979
+ } catch (e) {
1980
+ handleError(e);
1981
+ }
1982
+ }
1983
+ };
1984
+
1914
1985
  dotenv.config({ quiet: true });
1915
1986
  yargs(hideBin(process.argv)).scriptName("freestyle").usage("$0 <command> [options]").option("team", {
1916
1987
  type: "string",
@@ -1920,4 +1991,4 @@ yargs(hideBin(process.argv)).scriptName("freestyle").usage("$0 <command> [option
1920
1991
  if (argv.team && typeof argv.team === "string") {
1921
1992
  process.env.FREESTYLE_TEAM_ID = argv.team;
1922
1993
  }
1923
- }).command(vmCommand).command(gitCommand).command(domainsCommand).command(cronCommand).command(loginCommand).command(logoutCommand).command(deployCommand).command(runCommand).demandCommand(1, "You need to specify a command").help().alias("help", "h").version().alias("version", "v").strict().parse();
1994
+ }).command(vmCommand).command(gitCommand).command(domainsCommand).command(cronCommand).command(loginCommand).command(logoutCommand).command(whoamiCommand).command(deployCommand).command(runCommand).demandCommand(1, "You need to specify a command").help().alias("help", "h").version().alias("version", "v").strict().parse();