mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-20 01:11:18 +00:00
refactor: Remove dead code and stale references (#2154)
* refactor: Remove redundant loadTokenFromConfig wrappers in hetzner, daytona, digitalocean The previous PR (#2151) introduced shared loadApiToken() in shared/ui.ts and updated hetzner/daytona to delegate to it via thin wrapper functions. This commit removes the now-unnecessary wrapper functions entirely, inlining the loadApiToken() calls directly at the callsite. Also removes the 16-line duplicate loadTokenFromConfig() implementation in digitalocean.ts (which replicates the same api_key/token field reading and regex validation logic as loadApiToken) and replaces it with a direct call to loadApiToken("digitalocean"). -- qa/code-quality Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * bump version to 0.12.12 (main already has 0.12.11) --------- Co-authored-by: spawn-qa-bot <qa@openrouter.ai> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: L <6723574+louisgv@users.noreply.github.com>
This commit is contained in:
parent
a6b92e1e86
commit
4d3f2ba54a
4 changed files with 5 additions and 29 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@openrouter/spawn",
|
||||
"version": "0.12.11",
|
||||
"version": "0.12.12",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"spawn": "cli.js"
|
||||
|
|
|
|||
|
|
@ -108,10 +108,6 @@ async function saveTokenToConfig(token: string): Promise<void> {
|
|||
});
|
||||
}
|
||||
|
||||
function loadTokenFromConfig(): string | null {
|
||||
return loadApiToken("daytona");
|
||||
}
|
||||
|
||||
async function testDaytonaToken(): Promise<boolean> {
|
||||
if (!daytonaApiKey) {
|
||||
return false;
|
||||
|
|
@ -138,7 +134,7 @@ export async function ensureDaytonaToken(): Promise<void> {
|
|||
}
|
||||
|
||||
// 2. Saved config
|
||||
const saved = loadTokenFromConfig();
|
||||
const saved = loadApiToken("daytona");
|
||||
if (saved) {
|
||||
daytonaApiKey = saved;
|
||||
if (await testDaytonaToken()) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import {
|
|||
defaultSpawnName,
|
||||
sanitizeTermValue,
|
||||
selectFromList,
|
||||
loadApiToken,
|
||||
} from "../shared/ui";
|
||||
import type { CloudInitTier } from "../shared/agents";
|
||||
import { getPackagesForTier, needsNode, needsBun, NODE_INSTALL_CMD } from "../shared/cloud-init";
|
||||
|
|
@ -176,23 +177,6 @@ async function saveTokenToConfig(token: string, refreshToken?: string, expiresIn
|
|||
await saveConfig(config);
|
||||
}
|
||||
|
||||
function loadTokenFromConfig(): string | null {
|
||||
const data = loadConfig();
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
const apiKey = isString(data.api_key) ? data.api_key : "";
|
||||
const tok = isString(data.token) ? data.token : "";
|
||||
const token = apiKey || tok;
|
||||
if (!token) {
|
||||
return null;
|
||||
}
|
||||
if (!/^[a-zA-Z0-9._/@:+=-]+$/.test(token)) {
|
||||
return null;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
function loadRefreshToken(): string | null {
|
||||
const data = loadConfig();
|
||||
if (!data) {
|
||||
|
|
@ -513,7 +497,7 @@ export async function ensureDoToken(): Promise<boolean> {
|
|||
}
|
||||
|
||||
// 2. Saved config (check expiry first, try refresh if needed)
|
||||
const saved = loadTokenFromConfig();
|
||||
const saved = loadApiToken("digitalocean");
|
||||
if (saved) {
|
||||
if (isTokenExpired()) {
|
||||
logWarn("Saved DigitalOcean token has expired, trying refresh...");
|
||||
|
|
|
|||
|
|
@ -105,10 +105,6 @@ async function saveTokenToConfig(token: string): Promise<void> {
|
|||
});
|
||||
}
|
||||
|
||||
function loadTokenFromConfig(): string | null {
|
||||
return loadApiToken("hetzner");
|
||||
}
|
||||
|
||||
// ─── Token Validation ────────────────────────────────────────────────────────
|
||||
|
||||
async function testHcloudToken(): Promise<boolean> {
|
||||
|
|
@ -146,7 +142,7 @@ export async function ensureHcloudToken(): Promise<void> {
|
|||
}
|
||||
|
||||
// 2. Saved config
|
||||
const saved = loadTokenFromConfig();
|
||||
const saved = loadApiToken("hetzner");
|
||||
if (saved) {
|
||||
hcloudToken = saved;
|
||||
if (await testHcloudToken()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue