freestyle-sandboxes 0.1.35 → 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 +35 -12
  2. package/index.cjs +1620 -1277
  3. package/index.d.cts +1008 -863
  4. package/index.d.mts +1008 -863
  5. package/index.mjs +1620 -1278
  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,7 +499,8 @@ function getDefaultTeamId() {
499
499
  return stored?.defaultTeamId;
500
500
  }
501
501
 
502
- function normalizeCliProxyError(errorText) {
502
+ function normalizeCliProxyErrorWithStatus(errorText, status) {
503
+ const fallbackCode = status === 400 ? "BAD_REQUEST" : status === 401 ? "UNAUTHORIZED_ERROR" : status === 403 ? "FORBIDDEN" : "INTERNAL_ERROR";
503
504
  try {
504
505
  const parsed = JSON.parse(errorText);
505
506
  if (typeof parsed.code === "string" && typeof parsed.message === "string") {
@@ -508,20 +509,39 @@ function normalizeCliProxyError(errorText) {
508
509
  contentType: "application/json"
509
510
  };
510
511
  }
511
- const message = [parsed.error, parsed.message, parsed.reason].find(
512
+ const message2 = [parsed.error, parsed.message, parsed.reason].find(
512
513
  (value) => typeof value === "string" && value.length > 0
513
514
  );
514
- if (message) {
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
+ };
515
525
  return {
516
- body: message,
517
- contentType: "text/plain; charset=utf-8"
526
+ body: JSON.stringify(normalized2),
527
+ contentType: "application/json"
518
528
  };
519
529
  }
520
530
  } catch {
521
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
+ };
522
542
  return {
523
- body: errorText || "Request failed",
524
- contentType: "text/plain; charset=utf-8"
543
+ body: JSON.stringify(normalized),
544
+ contentType: "application/json"
525
545
  };
526
546
  }
527
547
  function createProxyFetch(accessToken, teamId) {
@@ -547,7 +567,10 @@ function createProxyFetch(accessToken, teamId) {
547
567
  });
548
568
  if (!proxyResponse.ok) {
549
569
  const errorText = await proxyResponse.text();
550
- const normalizedError = normalizeCliProxyError(errorText);
570
+ const normalizedError = normalizeCliProxyErrorWithStatus(
571
+ errorText,
572
+ proxyResponse.status
573
+ );
551
574
  return new Response(normalizedError.body, {
552
575
  status: proxyResponse.status,
553
576
  statusText: proxyResponse.statusText,
@@ -572,14 +595,14 @@ async function getFreestyleClient(teamId) {
572
595
  const accessToken = await getStackAccessTokenForCli();
573
596
  if (!accessToken) {
574
597
  console.error(
575
- "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."
576
599
  );
577
600
  process.exit(1);
578
601
  }
579
602
  const resolvedTeamId = process.env.FREESTYLE_TEAM_ID ?? getDefaultTeamId();
580
603
  if (!resolvedTeamId) {
581
604
  console.error(
582
- "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."
583
606
  );
584
607
  process.exit(1);
585
608
  }