@instafy/cli 0.1.8-staging.351 → 0.1.8-staging.353
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.
- package/dist/auth.js +27 -2
- package/package.json +1 -1
package/dist/auth.js
CHANGED
|
@@ -3,7 +3,7 @@ import { randomBytes } from "node:crypto";
|
|
|
3
3
|
import * as http from "node:http";
|
|
4
4
|
import { createInterface } from "node:readline/promises";
|
|
5
5
|
import { stdin as input, stdout as output } from "node:process";
|
|
6
|
-
import { clearInstafyCliConfig, getInstafyConfigPath,
|
|
6
|
+
import { clearInstafyCliConfig, getInstafyConfigPath, resolveConfiguredControllerUrl, resolveConfiguredStudioUrl, resolveUserAccessToken, writeInstafyCliConfig, } from "./config.js";
|
|
7
7
|
import { installGitCredentialHelper, uninstallGitCredentialHelper } from "./git-setup.js";
|
|
8
8
|
function normalizeUrl(raw) {
|
|
9
9
|
const trimmed = typeof raw === "string" ? raw.trim() : "";
|
|
@@ -39,6 +39,22 @@ function deriveDefaultStudioUrl(controllerUrl) {
|
|
|
39
39
|
}
|
|
40
40
|
return "https://staging.instafy.dev";
|
|
41
41
|
}
|
|
42
|
+
async function isControllerHealthy(controllerUrl, timeoutMs) {
|
|
43
|
+
const target = `${controllerUrl.replace(/\/$/, "")}/healthz`;
|
|
44
|
+
const abort = new AbortController();
|
|
45
|
+
const timeout = setTimeout(() => abort.abort(), timeoutMs);
|
|
46
|
+
timeout.unref?.();
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(target, { signal: abort.signal });
|
|
49
|
+
return response.ok;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
clearTimeout(timeout);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
42
58
|
function readRequestBody(request, maxBytes = 1000000) {
|
|
43
59
|
return new Promise((resolve, reject) => {
|
|
44
60
|
let buffer = "";
|
|
@@ -184,7 +200,16 @@ async function startCliLoginCallbackServer() {
|
|
|
184
200
|
};
|
|
185
201
|
}
|
|
186
202
|
export async function login(options) {
|
|
187
|
-
const
|
|
203
|
+
const explicitControllerUrl = normalizeUrl(options.controllerUrl ?? null) ??
|
|
204
|
+
normalizeUrl(process.env["INSTAFY_SERVER_URL"] ?? null) ??
|
|
205
|
+
normalizeUrl(process.env["CONTROLLER_BASE_URL"] ?? null) ??
|
|
206
|
+
resolveConfiguredControllerUrl();
|
|
207
|
+
const defaultLocalControllerUrl = "http://127.0.0.1:8788";
|
|
208
|
+
const defaultHostedControllerUrl = "https://controller.instafy.dev";
|
|
209
|
+
const controllerUrl = explicitControllerUrl ??
|
|
210
|
+
((await isControllerHealthy(defaultLocalControllerUrl, 250))
|
|
211
|
+
? defaultLocalControllerUrl
|
|
212
|
+
: defaultHostedControllerUrl);
|
|
188
213
|
const studioUrl = normalizeUrl(options.studioUrl ?? null) ??
|
|
189
214
|
normalizeUrl(process.env["INSTAFY_STUDIO_URL"] ?? null) ??
|
|
190
215
|
resolveConfiguredStudioUrl() ??
|
package/package.json
CHANGED