Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"devDependencies": {
"@cloudflare/workers-types": "catalog:platform",
"@electric-sql/pglite": "0.5.8",
"@napi-rs/keyring": "2.0.0",
"@types/pg": "8.23.1",
"drizzle-kit": "^0.31.10",
"miniflare": "^4.20260421.0",
Expand Down
27 changes: 23 additions & 4 deletions platform/packages/api/scripts/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Usage:
* node scripts/health.ts # production
* node scripts/health.ts --staging # staging
* VOID_TOKEN=... node scripts/health.ts # CI / explicit token
*/

import { readFileSync, readdirSync } from 'node:fs';
Expand All @@ -17,6 +18,20 @@ import { join, resolve } from 'node:path';

const isStaging = process.argv.includes('--staging');

const KEYRING_SERVICE = 'dev.void.cli';

// The keyring is a native addon. Load it lazily and treat a missing binary
// (CI, Docker, SSH) like an empty keychain, so VOID_TOKEN and the file
// fallback keep working without it.
async function keyringGet(account: string): Promise<string | null> {
try {
const { Entry } = await import('@napi-rs/keyring');
return new Entry(KEYRING_SERVICE, account).getPassword();
} catch {
return null;
}
}

type Config = Readonly<{
token?: string;
stagingToken?: string;
Expand All @@ -31,13 +46,17 @@ function readConfig(): Config {
}
}

const config = readConfig();
const token = isStaging ? config.stagingToken : config.token;
// Token resolution order: VOID_TOKEN env > system keychain > ~/.void/config.json.
// Mirrors getToken() in packages/void/src/cli/auth.ts (read-only: no migration here).
const account = isStaging ? 'stagingToken' : 'token';
const token = process.env.VOID_TOKEN || (await keyringGet(account)) || readConfig()[account];
const baseUrl = isStaging ? 'https://api.staging.void.cloud' : 'https://api.void.cloud';

if (!token) {
console.error(`No ${isStaging ? 'stagingToken' : 'token'} found in ~/.void/config.json`);
console.error('Run `void login` first.');
console.error(`No ${account} found in the system keychain or ~/.void/config.json.`);
console.error(
'Run `void auth login` first (in a staging project for --staging), or set VOID_TOKEN.',
);
process.exit(1);
}

Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.