tthr 0.3.16 → 0.3.18

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 +18 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -59,7 +59,7 @@ async function deployCommand(options) {
59
59
  process.exit(1);
60
60
  }
61
61
  const environment = options.env || config.environment || await resolveEnvironmentFromApiKey() || "development";
62
- const API_URL2 = `${getApiUrl(config)}/api/v1`;
62
+ const API_URL2 = `${await resolveApiUrl(config)}/api/v1`;
63
63
  console.log(chalk.bold("\n\u26A1 Deploying to Tether\n"));
64
64
  console.log(chalk.dim(` Project: ${projectId}`));
65
65
  console.log(chalk.dim(` Environment: ${environment}`));
@@ -2072,6 +2072,8 @@ async function loginCommand() {
2072
2072
  console.log(chalk4.dim("\nRun `tthr logout` to sign out\n"));
2073
2073
  return;
2074
2074
  }
2075
+ console.log(chalk4.dim(` URL: ${API_URL}
2076
+ `));
2075
2077
  const spinner = ora4("Generating authentication code...").start();
2076
2078
  try {
2077
2079
  const deviceCode = await requestDeviceCode();
@@ -2082,10 +2084,13 @@ async function loginCommand() {
2082
2084
  `));
2083
2085
  console.log(chalk4.dim(`Your code: ${chalk4.white.bold(deviceCode.userCode)}
2084
2086
  `));
2085
- await waitForEnter(chalk4.dim("Press Enter to open in browser..."));
2086
- openBrowser(authUrl);
2087
- console.log();
2088
- const credentials = await pollForApproval(deviceCode.deviceCode, deviceCode.interval, deviceCode.expiresIn);
2087
+ const pollPromise = pollForApproval(deviceCode.deviceCode, deviceCode.interval, deviceCode.expiresIn);
2088
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
2089
+ rl.question(chalk4.dim("Press Enter to open in browser..."), () => {
2090
+ openBrowser(authUrl);
2091
+ });
2092
+ const credentials = await pollPromise;
2093
+ rl.close();
2089
2094
  await saveCredentials(credentials);
2090
2095
  console.log(chalk4.green("\u2713") + ` Logged in as ${chalk4.cyan(credentials.email)}`);
2091
2096
  console.log();
@@ -2188,9 +2193,12 @@ async function pollForApproval(deviceCode, interval, expiresIn) {
2188
2193
  while (Date.now() < expiresAt) {
2189
2194
  await sleep(interval * 1e3);
2190
2195
  spinner.text = `Checking... ${chalk4.dim(`(${Math.ceil((expiresAt - Date.now()) / 1e3)}s remaining)`)}`;
2191
- const response = await fetch(`${API_URL}/auth/device/${deviceCode}`, {
2192
- method: "GET"
2193
- }).catch(() => null);
2196
+ let response = null;
2197
+ try {
2198
+ response = await fetch(`${API_URL}/auth/device/${deviceCode}`);
2199
+ } catch (err) {
2200
+ spinner.text = `Waiting for approval... ${chalk4.dim(`(connection error, retrying)`)}`;
2201
+ }
2194
2202
  updateCountdown();
2195
2203
  if (response?.ok) {
2196
2204
  const data = await response.json();
@@ -2206,6 +2214,8 @@ async function pollForApproval(deviceCode, interval, expiresIn) {
2206
2214
  spinner.fail("Authentication expired");
2207
2215
  throw new Error("Authentication request expired");
2208
2216
  }
2217
+ } else if (response) {
2218
+ spinner.text = `Waiting for approval... ${chalk4.dim(`(server: ${response.status})`)}`;
2209
2219
  }
2210
2220
  }
2211
2221
  spinner.fail("Authentication timed out");
@@ -2233,18 +2243,6 @@ function openBrowser(url) {
2233
2243
  }
2234
2244
  });
2235
2245
  }
2236
- function waitForEnter(prompt) {
2237
- return new Promise((resolve) => {
2238
- const rl = readline.createInterface({
2239
- input: process.stdin,
2240
- output: process.stdout
2241
- });
2242
- rl.question(prompt, () => {
2243
- rl.close();
2244
- resolve();
2245
- });
2246
- });
2247
- }
2248
2246
 
2249
2247
  // src/commands/update.ts
2250
2248
  import chalk5 from "chalk";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tthr",
3
- "version": "0.3.16",
3
+ "version": "0.3.18",
4
4
  "description": "Tether CLI - project scaffolding and deployment",
5
5
  "type": "module",
6
6
  "bin": {