@instafy/cli 0.1.8-staging.351 → 0.1.8-staging.354

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/auth.js +41 -2
  2. package/package.json +1 -1
package/dist/auth.js CHANGED
@@ -1,10 +1,22 @@
1
1
  import kleur from "kleur";
2
2
  import { randomBytes } from "node:crypto";
3
3
  import * as http from "node:http";
4
+ import { createRequire } from "node:module";
4
5
  import { createInterface } from "node:readline/promises";
5
6
  import { stdin as input, stdout as output } from "node:process";
6
- import { clearInstafyCliConfig, getInstafyConfigPath, resolveConfiguredStudioUrl, resolveControllerUrl, resolveUserAccessToken, writeInstafyCliConfig, } from "./config.js";
7
+ import { clearInstafyCliConfig, getInstafyConfigPath, resolveConfiguredControllerUrl, resolveConfiguredStudioUrl, resolveUserAccessToken, writeInstafyCliConfig, } from "./config.js";
7
8
  import { installGitCredentialHelper, uninstallGitCredentialHelper } from "./git-setup.js";
9
+ const require = createRequire(import.meta.url);
10
+ const cliVersion = (() => {
11
+ try {
12
+ const pkg = require("../package.json");
13
+ return typeof pkg.version === "string" ? pkg.version : "";
14
+ }
15
+ catch {
16
+ return "";
17
+ }
18
+ })();
19
+ const isStagingCli = cliVersion.includes("-staging.");
8
20
  function normalizeUrl(raw) {
9
21
  const trimmed = typeof raw === "string" ? raw.trim() : "";
10
22
  if (!trimmed) {
@@ -39,6 +51,22 @@ function deriveDefaultStudioUrl(controllerUrl) {
39
51
  }
40
52
  return "https://staging.instafy.dev";
41
53
  }
54
+ async function isControllerHealthy(controllerUrl, timeoutMs) {
55
+ const target = `${controllerUrl.replace(/\/$/, "")}/healthz`;
56
+ const abort = new AbortController();
57
+ const timeout = setTimeout(() => abort.abort(), timeoutMs);
58
+ timeout.unref?.();
59
+ try {
60
+ const response = await fetch(target, { signal: abort.signal });
61
+ return response.ok;
62
+ }
63
+ catch {
64
+ return false;
65
+ }
66
+ finally {
67
+ clearTimeout(timeout);
68
+ }
69
+ }
42
70
  function readRequestBody(request, maxBytes = 1000000) {
43
71
  return new Promise((resolve, reject) => {
44
72
  let buffer = "";
@@ -184,7 +212,18 @@ async function startCliLoginCallbackServer() {
184
212
  };
185
213
  }
186
214
  export async function login(options) {
187
- const controllerUrl = resolveControllerUrl({ controllerUrl: options.controllerUrl ?? null });
215
+ const explicitControllerUrl = normalizeUrl(options.controllerUrl ?? null) ??
216
+ normalizeUrl(process.env["INSTAFY_SERVER_URL"] ?? null) ??
217
+ normalizeUrl(process.env["CONTROLLER_BASE_URL"] ?? null) ??
218
+ resolveConfiguredControllerUrl();
219
+ const defaultLocalControllerUrl = "http://127.0.0.1:8788";
220
+ const defaultHostedControllerUrl = "https://controller.instafy.dev";
221
+ const controllerUrl = explicitControllerUrl ??
222
+ (isStagingCli
223
+ ? defaultHostedControllerUrl
224
+ : (await isControllerHealthy(defaultLocalControllerUrl, 250))
225
+ ? defaultLocalControllerUrl
226
+ : defaultHostedControllerUrl);
188
227
  const studioUrl = normalizeUrl(options.studioUrl ?? null) ??
189
228
  normalizeUrl(process.env["INSTAFY_STUDIO_URL"] ?? null) ??
190
229
  resolveConfiguredStudioUrl() ??
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instafy/cli",
3
- "version": "0.1.8-staging.351",
3
+ "version": "0.1.8-staging.354",
4
4
  "description": "Run Instafy projects locally, link folders to Studio, and share previews/webhooks via tunnels.",
5
5
  "private": false,
6
6
  "publishConfig": {