@temps-sdk/cli 0.1.21 → 0.1.22
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/index.js +233 -292
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -74447,15 +74447,79 @@ function getErrorMessage(error3) {
|
|
|
74447
74447
|
|
|
74448
74448
|
// src/commands/auth/login.ts
|
|
74449
74449
|
init_sdk_gen();
|
|
74450
|
-
import { hostname } from "node:os";
|
|
74451
|
-
|
|
74452
|
-
|
|
74450
|
+
import { hostname, platform } from "node:os";
|
|
74451
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
74452
|
+
function debugEnabled(opts = {}) {
|
|
74453
|
+
if (opts.debug)
|
|
74454
|
+
return true;
|
|
74455
|
+
const env3 = process.env.TEMPS_DEBUG;
|
|
74456
|
+
return env3 === "1" || env3 === "true" || env3 === "yes";
|
|
74453
74457
|
}
|
|
74454
|
-
function
|
|
74455
|
-
|
|
74458
|
+
function debugLog(message, payload) {
|
|
74459
|
+
if (payload === undefined) {
|
|
74460
|
+
process.stderr.write(`[temps-cli debug] ${message}
|
|
74461
|
+
`);
|
|
74462
|
+
return;
|
|
74463
|
+
}
|
|
74464
|
+
let rendered;
|
|
74465
|
+
try {
|
|
74466
|
+
rendered = typeof payload === "string" ? payload : JSON.stringify(payload, null, 2);
|
|
74467
|
+
} catch {
|
|
74468
|
+
rendered = String(payload);
|
|
74469
|
+
}
|
|
74470
|
+
process.stderr.write(`[temps-cli debug] ${message} ${rendered}
|
|
74471
|
+
`);
|
|
74472
|
+
}
|
|
74473
|
+
async function debugFetch(url, init, debug) {
|
|
74474
|
+
if (debug) {
|
|
74475
|
+
debugLog(`-> ${init.method ?? "GET"} ${url}`);
|
|
74476
|
+
if (init.body)
|
|
74477
|
+
debugLog(" request body:", init.body);
|
|
74478
|
+
}
|
|
74479
|
+
let res;
|
|
74480
|
+
try {
|
|
74481
|
+
res = await fetch(url, init);
|
|
74482
|
+
} catch (err) {
|
|
74483
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
74484
|
+
if (debug)
|
|
74485
|
+
debugLog(` fetch failed: ${reason}`);
|
|
74486
|
+
throw new AuthenticationError(`Unable to connect to ${url}: ${reason}. Is the server reachable from this machine?`);
|
|
74487
|
+
}
|
|
74488
|
+
const rawBody = await res.text();
|
|
74489
|
+
if (debug) {
|
|
74490
|
+
debugLog(`<- ${res.status} ${res.statusText} (${url})`);
|
|
74491
|
+
const headers = {};
|
|
74492
|
+
res.headers.forEach((value, key) => {
|
|
74493
|
+
headers[key] = value;
|
|
74494
|
+
});
|
|
74495
|
+
debugLog(" response headers:", headers);
|
|
74496
|
+
const preview = rawBody.length > 2000 ? `${rawBody.slice(0, 2000)}…[truncated]` : rawBody;
|
|
74497
|
+
debugLog(" response body:", preview || "(empty)");
|
|
74498
|
+
}
|
|
74499
|
+
let json2 = null;
|
|
74500
|
+
if (rawBody.length > 0) {
|
|
74501
|
+
try {
|
|
74502
|
+
json2 = JSON.parse(rawBody);
|
|
74503
|
+
} catch {
|
|
74504
|
+
json2 = null;
|
|
74505
|
+
}
|
|
74506
|
+
}
|
|
74507
|
+
return { res, rawBody, json: json2 };
|
|
74508
|
+
}
|
|
74509
|
+
function serverBaseUrl(rawApiUrl) {
|
|
74510
|
+
const trimmed = rawApiUrl.replace(/\/+$/, "");
|
|
74511
|
+
return /\/api$/.test(trimmed) ? trimmed : `${trimmed}/api`;
|
|
74456
74512
|
}
|
|
74457
74513
|
async function login2(options) {
|
|
74458
74514
|
newline();
|
|
74515
|
+
const debug = debugEnabled(options);
|
|
74516
|
+
if (debug) {
|
|
74517
|
+
debugLog("login invoked with options:", {
|
|
74518
|
+
url: options.url,
|
|
74519
|
+
context: options.context,
|
|
74520
|
+
hasApiKey: !!options.apiKey
|
|
74521
|
+
});
|
|
74522
|
+
}
|
|
74459
74523
|
const switchingContext = !!(options.url || options.context);
|
|
74460
74524
|
if (!switchingContext && await credentials.isAuthenticated()) {
|
|
74461
74525
|
const existingEmail = await credentials.get("email");
|
|
@@ -74463,53 +74527,152 @@ async function login2(options) {
|
|
|
74463
74527
|
info('Run "temps logout" first to switch accounts, or pass --url / --context to add another.');
|
|
74464
74528
|
return;
|
|
74465
74529
|
}
|
|
74466
|
-
if (options.magic) {
|
|
74467
|
-
await loginWithMagicLink(typeof options.magic === "string" ? options.magic : undefined);
|
|
74468
|
-
return;
|
|
74469
|
-
}
|
|
74470
|
-
if (options.email) {
|
|
74471
|
-
await loginWithEmail(typeof options.email === "string" ? options.email : undefined, {
|
|
74472
|
-
url: options.url,
|
|
74473
|
-
context: options.context,
|
|
74474
|
-
mfa: options.mfa
|
|
74475
|
-
});
|
|
74476
|
-
return;
|
|
74477
|
-
}
|
|
74478
74530
|
if (options.apiKey) {
|
|
74479
74531
|
await loginWithApiKey(options.apiKey);
|
|
74480
74532
|
return;
|
|
74481
74533
|
}
|
|
74482
|
-
|
|
74483
|
-
|
|
74484
|
-
|
|
74485
|
-
|
|
74486
|
-
|
|
74487
|
-
|
|
74488
|
-
|
|
74534
|
+
await loginWithDevice({ url: options.url, context: options.context, debug });
|
|
74535
|
+
}
|
|
74536
|
+
async function loginWithDevice(opts = {}) {
|
|
74537
|
+
const debug = debugEnabled(opts);
|
|
74538
|
+
const apiBaseUrl = opts.url ? serverBaseUrl(opts.url) : serverBaseUrl(config.get("apiUrl"));
|
|
74539
|
+
const webBaseUrl = apiBaseUrl.replace(/\/api$/, "");
|
|
74540
|
+
if (opts.url) {
|
|
74541
|
+
config.set("apiUrl", apiBaseUrl);
|
|
74489
74542
|
}
|
|
74490
|
-
|
|
74491
|
-
|
|
74492
|
-
|
|
74493
|
-
|
|
74494
|
-
|
|
74495
|
-
|
|
74496
|
-
|
|
74543
|
+
if (debug) {
|
|
74544
|
+
debugLog(`resolved apiBaseUrl: ${apiBaseUrl}`);
|
|
74545
|
+
debugLog(`resolved webBaseUrl: ${webBaseUrl}`);
|
|
74546
|
+
debugLog(`raw url arg: ${opts.url ?? "(none, using config apiUrl)"}`);
|
|
74547
|
+
}
|
|
74548
|
+
const deviceName = (() => {
|
|
74549
|
+
try {
|
|
74550
|
+
return hostname() || "cli";
|
|
74551
|
+
} catch {
|
|
74552
|
+
return "cli";
|
|
74553
|
+
}
|
|
74554
|
+
})();
|
|
74555
|
+
const startUrl = `${apiBaseUrl}/auth/cli/device/start`;
|
|
74556
|
+
const start = await withSpinner("Requesting device authorization...", async () => {
|
|
74557
|
+
const { res, rawBody, json: json2 } = await debugFetch(startUrl, {
|
|
74558
|
+
method: "POST",
|
|
74559
|
+
headers: { "Content-Type": "application/json" },
|
|
74560
|
+
body: JSON.stringify({ client_name: deviceName })
|
|
74561
|
+
}, debug);
|
|
74562
|
+
if (!res.ok) {
|
|
74563
|
+
const problem = json2 ?? null;
|
|
74564
|
+
throw new AuthenticationError(problem?.detail || problem?.title || `Device authorization start failed at ${startUrl} (status ${res.status}). ` + `Response body: ${rawBody.slice(0, 200) || "(empty)"}`);
|
|
74565
|
+
}
|
|
74566
|
+
if (json2 === null) {
|
|
74567
|
+
throw new AuthenticationError(`Server at ${startUrl} returned a non-JSON response (status ${res.status}, ` + `content-type ${res.headers.get("content-type") ?? "unknown"}). ` + `First 200 chars: ${rawBody.slice(0, 200) || "(empty)"}. ` + `Re-run with --debug for the full response.`);
|
|
74568
|
+
}
|
|
74569
|
+
return json2;
|
|
74570
|
+
}, { successText: "Device authorization ready" });
|
|
74571
|
+
const fullUrl = absoluteVerificationUri(webBaseUrl, start);
|
|
74572
|
+
newline();
|
|
74573
|
+
box([
|
|
74574
|
+
`Open this URL to authorize:`,
|
|
74575
|
+
` ${colors.primary(fullUrl)}`,
|
|
74576
|
+
``,
|
|
74577
|
+
`If your browser doesn't open automatically, paste the code:`,
|
|
74578
|
+
` ${colors.bold(start.user_code)}`,
|
|
74579
|
+
`at ${colors.muted(`${webBaseUrl}/cli-login`)}`
|
|
74580
|
+
].join(`
|
|
74581
|
+
`), `${icons.sparkles} Authorize the Temps CLI`);
|
|
74582
|
+
await tryOpenBrowser(fullUrl);
|
|
74583
|
+
const intervalMs = Math.max(500, (start.interval ?? 2) * 1000);
|
|
74584
|
+
const deadline = Date.now() + (start.expires_in ?? 900) * 1000;
|
|
74585
|
+
const success3 = await withSpinner(`Waiting for browser approval (code ${colors.bold(start.user_code)})...`, async () => {
|
|
74586
|
+
let pollDelay = intervalMs;
|
|
74587
|
+
const pollUrl = `${apiBaseUrl}/auth/cli/device/poll`;
|
|
74588
|
+
while (Date.now() < deadline) {
|
|
74589
|
+
await sleep(pollDelay);
|
|
74590
|
+
const { res, rawBody, json: json2 } = await debugFetch(pollUrl, {
|
|
74591
|
+
method: "POST",
|
|
74592
|
+
headers: { "Content-Type": "application/json" },
|
|
74593
|
+
body: JSON.stringify({ device_code: start.device_code })
|
|
74594
|
+
}, debug);
|
|
74595
|
+
if (!res.ok) {
|
|
74596
|
+
const problem = json2 ?? null;
|
|
74597
|
+
throw new AuthenticationError(problem?.detail || problem?.title || `Polling failed at ${pollUrl} (status ${res.status}). ` + `Response body: ${rawBody.slice(0, 200) || "(empty)"}`);
|
|
74598
|
+
}
|
|
74599
|
+
if (json2 === null) {
|
|
74600
|
+
throw new AuthenticationError(`Server at ${pollUrl} returned a non-JSON response (status ${res.status}). ` + `First 200 chars: ${rawBody.slice(0, 200) || "(empty)"}`);
|
|
74601
|
+
}
|
|
74602
|
+
const body = json2;
|
|
74603
|
+
switch (body.status) {
|
|
74604
|
+
case "authorization_pending":
|
|
74605
|
+
pollDelay = intervalMs;
|
|
74606
|
+
continue;
|
|
74607
|
+
case "slow_down":
|
|
74608
|
+
pollDelay = Math.min(pollDelay * 2, 1e4);
|
|
74609
|
+
continue;
|
|
74610
|
+
case "access_denied":
|
|
74611
|
+
throw new AuthenticationError("Authorization denied in the browser.");
|
|
74612
|
+
case "expired_token":
|
|
74613
|
+
throw new AuthenticationError("Authorization code expired before approval. Run `temps login` again.");
|
|
74614
|
+
case "approved":
|
|
74615
|
+
return body;
|
|
74616
|
+
}
|
|
74617
|
+
}
|
|
74618
|
+
throw new AuthenticationError("Timed out waiting for browser approval. Run `temps login` again.");
|
|
74619
|
+
}, { successText: "Browser approval received" });
|
|
74620
|
+
const contextName = opts.context ?? defaultContextName(apiBaseUrl);
|
|
74621
|
+
await upsertContext({
|
|
74622
|
+
name: contextName,
|
|
74623
|
+
url: apiBaseUrl,
|
|
74624
|
+
apiKey: success3.api_key,
|
|
74625
|
+
email: success3.email,
|
|
74626
|
+
keyPrefix: success3.key_prefix,
|
|
74627
|
+
expiresAt: success3.expires_at ?? undefined
|
|
74497
74628
|
});
|
|
74498
|
-
|
|
74499
|
-
|
|
74500
|
-
|
|
74501
|
-
|
|
74502
|
-
|
|
74503
|
-
|
|
74504
|
-
|
|
74505
|
-
|
|
74506
|
-
|
|
74507
|
-
|
|
74508
|
-
|
|
74509
|
-
|
|
74510
|
-
|
|
74511
|
-
|
|
74629
|
+
config.set("apiUrl", apiBaseUrl);
|
|
74630
|
+
await credentials.setAll({
|
|
74631
|
+
apiKey: success3.api_key,
|
|
74632
|
+
userId: success3.user_id,
|
|
74633
|
+
email: success3.email
|
|
74634
|
+
});
|
|
74635
|
+
displayWelcome(success3.email, contextName, apiBaseUrl, {
|
|
74636
|
+
role: success3.role,
|
|
74637
|
+
key_prefix: success3.key_prefix,
|
|
74638
|
+
expires_at: success3.expires_at
|
|
74639
|
+
});
|
|
74640
|
+
}
|
|
74641
|
+
function absoluteVerificationUri(baseUrl, start) {
|
|
74642
|
+
if (/^https?:\/\//i.test(start.verification_uri_complete)) {
|
|
74643
|
+
return start.verification_uri_complete;
|
|
74512
74644
|
}
|
|
74645
|
+
const path6 = start.verification_uri_complete.startsWith("/") ? start.verification_uri_complete : `/${start.verification_uri_complete}`;
|
|
74646
|
+
return `${baseUrl.replace(/\/+$/, "")}${path6}`;
|
|
74647
|
+
}
|
|
74648
|
+
async function tryOpenBrowser(url) {
|
|
74649
|
+
if (process.env.CI || process.env.TEMPS_NO_BROWSER || !process.stdout.isTTY) {
|
|
74650
|
+
return;
|
|
74651
|
+
}
|
|
74652
|
+
const plat = platform();
|
|
74653
|
+
let cmd2;
|
|
74654
|
+
let args;
|
|
74655
|
+
if (plat === "darwin") {
|
|
74656
|
+
cmd2 = "open";
|
|
74657
|
+
args = [url];
|
|
74658
|
+
} else if (plat === "win32") {
|
|
74659
|
+
cmd2 = "cmd";
|
|
74660
|
+
args = ["/c", "start", '""', url];
|
|
74661
|
+
} else {
|
|
74662
|
+
cmd2 = "xdg-open";
|
|
74663
|
+
args = [url];
|
|
74664
|
+
}
|
|
74665
|
+
try {
|
|
74666
|
+
const child = spawn2(cmd2, args, {
|
|
74667
|
+
stdio: "ignore",
|
|
74668
|
+
detached: true
|
|
74669
|
+
});
|
|
74670
|
+
child.on("error", () => {});
|
|
74671
|
+
child.unref();
|
|
74672
|
+
} catch {}
|
|
74673
|
+
}
|
|
74674
|
+
function sleep(ms) {
|
|
74675
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
74513
74676
|
}
|
|
74514
74677
|
async function loginWithApiKey(apiKey) {
|
|
74515
74678
|
const key = apiKey ?? await promptPassword({
|
|
@@ -74549,233 +74712,11 @@ async function loginWithApiKey(apiKey) {
|
|
|
74549
74712
|
keyPrefix: key.slice(0, 8)
|
|
74550
74713
|
});
|
|
74551
74714
|
displayWelcome(result.email, ctxName, baseUrl);
|
|
74552
|
-
} catch
|
|
74715
|
+
} catch {
|
|
74553
74716
|
await credentials.clear();
|
|
74554
74717
|
throw new AuthenticationError("Invalid API key");
|
|
74555
74718
|
}
|
|
74556
74719
|
}
|
|
74557
|
-
async function loginWithEmail(emailArg, opts = {}) {
|
|
74558
|
-
const baseUrl = opts.url ? serverBaseUrl(opts.url) : serverBaseUrl(config.get("apiUrl"));
|
|
74559
|
-
if (opts.url) {
|
|
74560
|
-
config.set("apiUrl", baseUrl);
|
|
74561
|
-
}
|
|
74562
|
-
const email = emailArg ?? await promptEmail("Email");
|
|
74563
|
-
const password = await promptPassword({
|
|
74564
|
-
message: "Password",
|
|
74565
|
-
validate: (value) => {
|
|
74566
|
-
if (!value || value.trim().length === 0) {
|
|
74567
|
-
return "Password is required";
|
|
74568
|
-
}
|
|
74569
|
-
return true;
|
|
74570
|
-
}
|
|
74571
|
-
});
|
|
74572
|
-
const deviceName = (() => {
|
|
74573
|
-
try {
|
|
74574
|
-
return hostname() || "cli";
|
|
74575
|
-
} catch {
|
|
74576
|
-
return "cli";
|
|
74577
|
-
}
|
|
74578
|
-
})();
|
|
74579
|
-
const firstResponse = await withSpinner("Logging in...", async () => {
|
|
74580
|
-
return cliLoginRequest(baseUrl, {
|
|
74581
|
-
email,
|
|
74582
|
-
password,
|
|
74583
|
-
mfa_code: opts.mfa,
|
|
74584
|
-
device_name: deviceName
|
|
74585
|
-
});
|
|
74586
|
-
}, { successText: "Authenticated" });
|
|
74587
|
-
let success3;
|
|
74588
|
-
if (isMfaChallenge(firstResponse)) {
|
|
74589
|
-
const mfaCode = opts.mfa ?? await promptText({
|
|
74590
|
-
message: "MFA Code",
|
|
74591
|
-
required: true,
|
|
74592
|
-
validate: (value) => /^\d{6}$/.test(value) || "Enter a 6-digit code"
|
|
74593
|
-
});
|
|
74594
|
-
success3 = await withSpinner("Verifying MFA...", async () => {
|
|
74595
|
-
const r = await cliLoginRequest(baseUrl, {
|
|
74596
|
-
email,
|
|
74597
|
-
password,
|
|
74598
|
-
mfa_code: mfaCode,
|
|
74599
|
-
mfa_session_token: firstResponse.mfa_session_token,
|
|
74600
|
-
device_name: deviceName
|
|
74601
|
-
});
|
|
74602
|
-
if (isMfaChallenge(r)) {
|
|
74603
|
-
throw new AuthenticationError("Server requested MFA again after we supplied a code");
|
|
74604
|
-
}
|
|
74605
|
-
return r;
|
|
74606
|
-
}, { successText: "MFA verified" });
|
|
74607
|
-
} else {
|
|
74608
|
-
success3 = firstResponse;
|
|
74609
|
-
}
|
|
74610
|
-
const contextName = opts.context ?? defaultContextName(baseUrl);
|
|
74611
|
-
await upsertContext({
|
|
74612
|
-
name: contextName,
|
|
74613
|
-
url: baseUrl,
|
|
74614
|
-
apiKey: success3.api_key,
|
|
74615
|
-
email: success3.email || email,
|
|
74616
|
-
keyPrefix: success3.key_prefix,
|
|
74617
|
-
expiresAt: success3.expires_at ?? undefined
|
|
74618
|
-
});
|
|
74619
|
-
config.set("apiUrl", baseUrl);
|
|
74620
|
-
await credentials.setAll({
|
|
74621
|
-
apiKey: success3.api_key,
|
|
74622
|
-
userId: success3.user_id,
|
|
74623
|
-
email: success3.email || email
|
|
74624
|
-
});
|
|
74625
|
-
displayWelcome(success3.email || email, contextName, baseUrl, success3);
|
|
74626
|
-
}
|
|
74627
|
-
async function cliLoginRequest(baseUrl, body) {
|
|
74628
|
-
const url = `${baseUrl}/auth/cli/login`;
|
|
74629
|
-
const response = await fetch(url, {
|
|
74630
|
-
method: "POST",
|
|
74631
|
-
headers: { "Content-Type": "application/json" },
|
|
74632
|
-
body: JSON.stringify(body)
|
|
74633
|
-
});
|
|
74634
|
-
if (!response.ok) {
|
|
74635
|
-
let detail = "";
|
|
74636
|
-
try {
|
|
74637
|
-
const problem = await response.json();
|
|
74638
|
-
detail = problem.detail || problem.title || "";
|
|
74639
|
-
} catch {}
|
|
74640
|
-
if (response.status === 401) {
|
|
74641
|
-
throw new AuthenticationError(detail || "Invalid email or password");
|
|
74642
|
-
}
|
|
74643
|
-
if (response.status === 403) {
|
|
74644
|
-
throw new AuthenticationError(detail || "Access denied");
|
|
74645
|
-
}
|
|
74646
|
-
throw new AuthenticationError(detail ? `Login failed (${response.status}): ${detail}` : `Login failed (status ${response.status})`);
|
|
74647
|
-
}
|
|
74648
|
-
return await response.json();
|
|
74649
|
-
}
|
|
74650
|
-
async function loginWithMagicLink(emailArg) {
|
|
74651
|
-
const email = emailArg ?? await promptEmail("Email");
|
|
74652
|
-
const apiUrl = normalizeApiUrl(config.get("apiUrl"));
|
|
74653
|
-
await withSpinner("Sending magic link...", async () => {
|
|
74654
|
-
const response = await fetch(`${apiUrl}/auth/magic-link/request`, {
|
|
74655
|
-
method: "POST",
|
|
74656
|
-
headers: { "Content-Type": "application/json" },
|
|
74657
|
-
body: JSON.stringify({ email })
|
|
74658
|
-
});
|
|
74659
|
-
if (!response.ok && response.status !== 200) {
|
|
74660
|
-
if (response.status === 503) {
|
|
74661
|
-
throw new Error("Email service is not configured on this server");
|
|
74662
|
-
}
|
|
74663
|
-
throw new Error("Failed to send magic link");
|
|
74664
|
-
}
|
|
74665
|
-
}, { successText: "Magic link sent" });
|
|
74666
|
-
newline();
|
|
74667
|
-
info("Check your email for a magic link.");
|
|
74668
|
-
info("After clicking the link, paste the token from the URL below.");
|
|
74669
|
-
newline();
|
|
74670
|
-
const tokenInput = await promptText({
|
|
74671
|
-
message: "Magic link token (from URL or email)",
|
|
74672
|
-
required: true
|
|
74673
|
-
});
|
|
74674
|
-
const token = extractTokenFromInput(tokenInput);
|
|
74675
|
-
const verifyResult = await withSpinner("Verifying token...", async () => {
|
|
74676
|
-
const response = await fetch(`${apiUrl}/auth/magic-link/verify?token=${encodeURIComponent(token)}`, {
|
|
74677
|
-
method: "GET",
|
|
74678
|
-
headers: { "Content-Type": "application/json" }
|
|
74679
|
-
});
|
|
74680
|
-
if (!response.ok) {
|
|
74681
|
-
if (response.status === 400) {
|
|
74682
|
-
throw new AuthenticationError("Invalid or expired token");
|
|
74683
|
-
}
|
|
74684
|
-
throw new AuthenticationError("Verification failed");
|
|
74685
|
-
}
|
|
74686
|
-
const data = await response.json();
|
|
74687
|
-
const setCookie = response.headers.get("set-cookie");
|
|
74688
|
-
return { data, setCookie };
|
|
74689
|
-
}, { successText: "Token verified" });
|
|
74690
|
-
const sessionCookie = extractSessionCookie(verifyResult.setCookie);
|
|
74691
|
-
if (!sessionCookie) {
|
|
74692
|
-
warning("Could not extract session. Please create an API key from the dashboard.");
|
|
74693
|
-
info(`Dashboard: ${colors.primary(`${apiUrl}/dashboard/settings/api-keys`)}`);
|
|
74694
|
-
newline();
|
|
74695
|
-
info("Then run: temps login --api-key <your-key>");
|
|
74696
|
-
return;
|
|
74697
|
-
}
|
|
74698
|
-
const apiKey = await withSpinner("Creating API token...", async () => {
|
|
74699
|
-
const response = await fetch(`${apiUrl}/api/tokens`, {
|
|
74700
|
-
method: "POST",
|
|
74701
|
-
headers: {
|
|
74702
|
-
"Content-Type": "application/json",
|
|
74703
|
-
Cookie: sessionCookie
|
|
74704
|
-
},
|
|
74705
|
-
body: JSON.stringify({
|
|
74706
|
-
name: `temps-cli-${new Date().toISOString().split("T")[0]}`,
|
|
74707
|
-
permissions: ["*"]
|
|
74708
|
-
})
|
|
74709
|
-
});
|
|
74710
|
-
if (!response.ok) {
|
|
74711
|
-
throw new Error("Could not create API token from session");
|
|
74712
|
-
}
|
|
74713
|
-
const tokenData = await response.json();
|
|
74714
|
-
return tokenData.token ?? tokenData.api_key;
|
|
74715
|
-
}, { successText: "API token created" });
|
|
74716
|
-
if (!apiKey) {
|
|
74717
|
-
warning("Could not create API token. Please generate one from the dashboard.");
|
|
74718
|
-
return;
|
|
74719
|
-
}
|
|
74720
|
-
await credentials.set("apiKey", apiKey);
|
|
74721
|
-
await setupClient();
|
|
74722
|
-
const user = await withSpinner("Validating...", async () => {
|
|
74723
|
-
const { data, error: error3 } = await getCurrentUser({ client });
|
|
74724
|
-
if (error3 || !data)
|
|
74725
|
-
throw new AuthenticationError("Token validation failed");
|
|
74726
|
-
return data;
|
|
74727
|
-
}, { successText: "Validated" });
|
|
74728
|
-
await credentials.setAll({
|
|
74729
|
-
apiKey,
|
|
74730
|
-
userId: user.id,
|
|
74731
|
-
email: user.email ?? undefined
|
|
74732
|
-
});
|
|
74733
|
-
const baseUrl = serverBaseUrl(config.get("apiUrl"));
|
|
74734
|
-
const ctxName = defaultContextName(baseUrl);
|
|
74735
|
-
await upsertContext({
|
|
74736
|
-
name: ctxName,
|
|
74737
|
-
url: baseUrl,
|
|
74738
|
-
apiKey,
|
|
74739
|
-
email: user.email ?? "",
|
|
74740
|
-
keyPrefix: apiKey.slice(0, 8)
|
|
74741
|
-
});
|
|
74742
|
-
displayWelcome(user.email, ctxName, baseUrl);
|
|
74743
|
-
}
|
|
74744
|
-
function extractCookieValue(setCookie, name) {
|
|
74745
|
-
if (!setCookie)
|
|
74746
|
-
return null;
|
|
74747
|
-
const cookies = setCookie.split(/,(?=\s*\w+=)/);
|
|
74748
|
-
for (const cookie of cookies) {
|
|
74749
|
-
const match = cookie.match(new RegExp(`${name}=([^;]+)`));
|
|
74750
|
-
if (match)
|
|
74751
|
-
return `${name}=${match[1]}`;
|
|
74752
|
-
}
|
|
74753
|
-
return null;
|
|
74754
|
-
}
|
|
74755
|
-
function extractSessionCookie(setCookie) {
|
|
74756
|
-
if (!setCookie)
|
|
74757
|
-
return null;
|
|
74758
|
-
const cookieNames = ["session_token", "session", "id", "sid"];
|
|
74759
|
-
for (const name of cookieNames) {
|
|
74760
|
-
const cookie = extractCookieValue(setCookie, name);
|
|
74761
|
-
if (cookie)
|
|
74762
|
-
return cookie;
|
|
74763
|
-
}
|
|
74764
|
-
const match = setCookie.match(/^([^=]+=[^;]+)/);
|
|
74765
|
-
if (match?.[1])
|
|
74766
|
-
return match[1];
|
|
74767
|
-
return null;
|
|
74768
|
-
}
|
|
74769
|
-
function extractTokenFromInput(input) {
|
|
74770
|
-
const trimmed = input.trim();
|
|
74771
|
-
try {
|
|
74772
|
-
const url = new URL(trimmed);
|
|
74773
|
-
const token = url.searchParams.get("token");
|
|
74774
|
-
if (token)
|
|
74775
|
-
return token;
|
|
74776
|
-
} catch {}
|
|
74777
|
-
return trimmed;
|
|
74778
|
-
}
|
|
74779
74720
|
function displayWelcome(email, contextName, baseUrl, meta) {
|
|
74780
74721
|
newline();
|
|
74781
74722
|
const url = baseUrl ?? config.get("apiUrl");
|
|
@@ -74899,7 +74840,7 @@ async function whoami(options) {
|
|
|
74899
74840
|
|
|
74900
74841
|
// src/commands/auth/index.ts
|
|
74901
74842
|
function registerAuthCommands(program2) {
|
|
74902
|
-
program2.command("login [url]").description("Authenticate with a Temps server
|
|
74843
|
+
program2.command("login [url]").description("Authenticate with a Temps server. Opens the browser for interactive logins; use --api-key for headless / CI.").option("-k, --api-key <key>", "Use a pre-minted API key (Settings → API Keys) instead of opening the browser. Required for headless / CI.").option("--context <name>", "Save the credentials under this context name (defaults to URL host)").option("--debug", "Print every request/response (URL, status, headers, raw body) to stderr. Also enabled via TEMPS_DEBUG=1.").action(async (url, opts) => {
|
|
74903
74844
|
await login2({
|
|
74904
74845
|
...opts,
|
|
74905
74846
|
url: typeof url === "string" && url.length > 0 ? url : opts.url
|
|
@@ -77024,12 +76965,12 @@ var isWebWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanc
|
|
|
77024
76965
|
var isDedicatedWorker = typeof DedicatedWorkerGlobalScope !== "undefined" && globalThis instanceof DedicatedWorkerGlobalScope;
|
|
77025
76966
|
var isSharedWorker = typeof SharedWorkerGlobalScope !== "undefined" && globalThis instanceof SharedWorkerGlobalScope;
|
|
77026
76967
|
var isServiceWorker = typeof ServiceWorkerGlobalScope !== "undefined" && globalThis instanceof ServiceWorkerGlobalScope;
|
|
77027
|
-
var
|
|
77028
|
-
var isMacOs =
|
|
77029
|
-
var isWindows =
|
|
77030
|
-
var isLinux =
|
|
77031
|
-
var isIos =
|
|
77032
|
-
var isAndroid =
|
|
76968
|
+
var platform2 = globalThis.navigator?.userAgentData?.platform;
|
|
76969
|
+
var isMacOs = platform2 === "macOS" || globalThis.navigator?.platform === "MacIntel" || globalThis.navigator?.userAgent?.includes(" Mac ") === true || globalThis.process?.platform === "darwin";
|
|
76970
|
+
var isWindows = platform2 === "Windows" || globalThis.navigator?.platform === "Win32" || globalThis.process?.platform === "win32";
|
|
76971
|
+
var isLinux = platform2 === "Linux" || globalThis.navigator?.platform?.startsWith("Linux") === true || globalThis.navigator?.userAgent?.includes(" Linux ") === true || globalThis.process?.platform === "linux";
|
|
76972
|
+
var isIos = platform2 === "iOS" || globalThis.navigator?.platform === "MacIntel" && globalThis.navigator?.maxTouchPoints > 1 || /iPad|iPhone|iPod/.test(globalThis.navigator?.platform);
|
|
76973
|
+
var isAndroid = platform2 === "Android" || globalThis.navigator?.platform === "Android" || globalThis.navigator?.userAgent?.includes(" Android ") === true || globalThis.process?.platform === "android";
|
|
77033
76974
|
|
|
77034
76975
|
// node_modules/ansi-escapes/base.js
|
|
77035
76976
|
var ESC3 = "\x1B[";
|
|
@@ -82202,7 +82143,7 @@ async function watchDeployment(options) {
|
|
|
82202
82143
|
init_sdk_gen();
|
|
82203
82144
|
init_prompts();
|
|
82204
82145
|
init_output();
|
|
82205
|
-
import { spawn as
|
|
82146
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
82206
82147
|
import { existsSync as existsSync6, createWriteStream, writeFileSync as writeFileSync3, mkdirSync } from "node:fs";
|
|
82207
82148
|
import { unlink as unlink2 } from "node:fs/promises";
|
|
82208
82149
|
import { resolve as resolve2, basename, join as join3 } from "node:path";
|
|
@@ -82541,7 +82482,7 @@ async function dockerBuild(options) {
|
|
|
82541
82482
|
args.push("--build-arg", arg);
|
|
82542
82483
|
}
|
|
82543
82484
|
args.push(options.context);
|
|
82544
|
-
const docker =
|
|
82485
|
+
const docker = spawn3("docker", args, {
|
|
82545
82486
|
stdio: ["ignore", "pipe", "pipe"]
|
|
82546
82487
|
});
|
|
82547
82488
|
let stderr = "";
|
|
@@ -82579,7 +82520,7 @@ ${stderr}`));
|
|
|
82579
82520
|
}
|
|
82580
82521
|
async function checkImageExists(imageName) {
|
|
82581
82522
|
return new Promise((resolve3) => {
|
|
82582
|
-
const docker =
|
|
82523
|
+
const docker = spawn3("docker", ["image", "inspect", imageName], {
|
|
82583
82524
|
stdio: ["ignore", "pipe", "pipe"]
|
|
82584
82525
|
});
|
|
82585
82526
|
docker.on("close", (code) => {
|
|
@@ -82592,7 +82533,7 @@ async function checkImageExists(imageName) {
|
|
|
82592
82533
|
}
|
|
82593
82534
|
async function getImageSize(imageName) {
|
|
82594
82535
|
return new Promise((resolve3) => {
|
|
82595
|
-
const docker =
|
|
82536
|
+
const docker = spawn3("docker", ["image", "inspect", "--format", "{{.Size}}", imageName], {
|
|
82596
82537
|
stdio: ["ignore", "pipe", "pipe"]
|
|
82597
82538
|
});
|
|
82598
82539
|
let output = "";
|
|
@@ -82615,7 +82556,7 @@ async function getImageSize(imageName) {
|
|
|
82615
82556
|
async function dockerSaveToFile(imageName, outputPath, onProgress) {
|
|
82616
82557
|
return new Promise((resolve3, reject2) => {
|
|
82617
82558
|
let totalBytes = 0;
|
|
82618
|
-
const docker =
|
|
82559
|
+
const docker = spawn3("docker", ["save", imageName], {
|
|
82619
82560
|
stdio: ["ignore", "pipe", "pipe"]
|
|
82620
82561
|
});
|
|
82621
82562
|
const writeStream = createWriteStream(outputPath);
|
|
@@ -82752,7 +82693,7 @@ init_output();
|
|
|
82752
82693
|
import { existsSync as existsSync7, statSync } from "node:fs";
|
|
82753
82694
|
import { readFile as readFile5 } from "node:fs/promises";
|
|
82754
82695
|
import { basename as basename2, extname, resolve as resolve3 } from "node:path";
|
|
82755
|
-
import { spawn as
|
|
82696
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
82756
82697
|
async function deployStatic(options) {
|
|
82757
82698
|
await requireAuth();
|
|
82758
82699
|
await setupClient();
|
|
@@ -83028,7 +82969,7 @@ async function createTarGzFromDirectory(dirPath) {
|
|
|
83028
82969
|
const filename = `${dirName}.tar.gz`;
|
|
83029
82970
|
return new Promise((resolve4, reject2) => {
|
|
83030
82971
|
const chunks = [];
|
|
83031
|
-
const tar =
|
|
82972
|
+
const tar = spawn4("tar", ["-czf", "-", "-C", dirPath, "."], {
|
|
83032
82973
|
stdio: ["ignore", "pipe", "pipe"]
|
|
83033
82974
|
});
|
|
83034
82975
|
tar.stdout.on("data", (chunk2) => {
|
|
@@ -99067,11 +99008,11 @@ async function listTemplatesAction(options) {
|
|
|
99067
99008
|
init_sdk_gen();
|
|
99068
99009
|
init_output();
|
|
99069
99010
|
function registerPlatformCommands(program2) {
|
|
99070
|
-
const
|
|
99071
|
-
|
|
99072
|
-
|
|
99073
|
-
|
|
99074
|
-
|
|
99011
|
+
const platform3 = program2.command("platform").alias("plat").description("View platform and server information");
|
|
99012
|
+
platform3.command("info").description("Get platform information").option("--json", "Output in JSON format").action(platformInfoAction);
|
|
99013
|
+
platform3.command("access").description("Get access and networking information").option("--json", "Output in JSON format").action(accessInfoAction);
|
|
99014
|
+
platform3.command("private-ip").description("Get the server private IP address").action(privateIpAction);
|
|
99015
|
+
platform3.command("public-ip").description("Get the server public IP address").action(publicIpAction);
|
|
99075
99016
|
}
|
|
99076
99017
|
async function platformInfoAction(options) {
|
|
99077
99018
|
await requireAuth();
|
|
@@ -104014,11 +103955,11 @@ init_sdk_gen();
|
|
|
104014
103955
|
init_prompts();
|
|
104015
103956
|
init_output();
|
|
104016
103957
|
function openUrl(url) {
|
|
104017
|
-
const
|
|
103958
|
+
const platform3 = process.platform;
|
|
104018
103959
|
try {
|
|
104019
|
-
if (
|
|
103960
|
+
if (platform3 === "darwin") {
|
|
104020
103961
|
execSync3(`open "${url}"`);
|
|
104021
|
-
} else if (
|
|
103962
|
+
} else if (platform3 === "win32") {
|
|
104022
103963
|
execSync3(`start "" "${url}"`);
|
|
104023
103964
|
} else {
|
|
104024
103965
|
execSync3(`xdg-open "${url}"`);
|
|
@@ -104633,7 +104574,7 @@ function openBrowser2(url) {
|
|
|
104633
104574
|
}
|
|
104634
104575
|
} catch {}
|
|
104635
104576
|
}
|
|
104636
|
-
function
|
|
104577
|
+
function sleep2(ms) {
|
|
104637
104578
|
return new Promise((resolve9) => setTimeout(resolve9, ms));
|
|
104638
104579
|
}
|
|
104639
104580
|
async function cloudLogin() {
|
|
@@ -104673,7 +104614,7 @@ async function cloudLogin() {
|
|
|
104673
104614
|
const deadline = Date.now() + deviceCode.expires_in * 1000;
|
|
104674
104615
|
let accessToken = null;
|
|
104675
104616
|
while (Date.now() < deadline) {
|
|
104676
|
-
await
|
|
104617
|
+
await sleep2(interval);
|
|
104677
104618
|
try {
|
|
104678
104619
|
const response = await fetch(`${cloudUrl}/api/auth/device/token`, {
|
|
104679
104620
|
method: "POST",
|