tokenmaxxing 1.101.0 → 1.103.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenmaxxing",
3
- "version": "1.101.0",
3
+ "version": "1.103.0",
4
4
  "description": "Automatic Claude Code account switching: pool multiple accounts, start each session on its own account, and resume a session on a fresher account when quota fills.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/lib/codex.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { existsSync, readFileSync, rmSync } from "node:fs";
2
2
  import { join } from "node:path";
3
+ import { z } from "zod";
3
4
  import { writeFileAtomic } from "./atomic.ts";
4
5
  import { CODEX_BIN, MAX_WRAP_DEPTH, WRAP_DEPTH_ENV, resolveRealBin, verifyRealBin } from "./claudebin.ts";
5
6
  import { codexIdentityOf, codexStoreUsable, deleteCodexStoreAuth, ensureCodexStoreHome, isCodexAccessExpiring, readCodexAuthAt, readCodexStoreAuth, writeCodexStoreAuth } from "./codexauth.ts";
@@ -189,11 +190,13 @@ async function importLive(): Promise<Harvest | null> {
189
190
  return login();
190
191
  }
191
192
 
193
+ const CodexStoreModeSchema = z.looseObject({ cli_auth_credentials_store: z.string().optional() });
194
+
192
195
  function storePinnedAwayFromFile(): boolean {
193
196
  const configToml = `${codexPaths.home}/config.toml`;
194
197
  if (!existsSync(configToml)) return false;
195
- const config = Bun.TOML.parse(readFileSync(configToml, "utf8"));
196
- return "cli_auth_credentials_store" in config && config.cli_auth_credentials_store !== "file";
198
+ const store = CodexStoreModeSchema.parse(Bun.TOML.parse(readFileSync(configToml, "utf8"))).cli_auth_credentials_store;
199
+ return store !== undefined && store !== "file";
197
200
  }
198
201
 
199
202
  function preflight(): void {
package/src/lib/grok.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { readFileSync } from "node:fs";
2
1
  import { join } from "node:path";
3
2
  import { z } from "zod";
4
3
  import { writeFileAtomic } from "./atomic.ts";
@@ -6,9 +5,9 @@ import { fetchGrokUsage, GrokUsageReadError, type GrokUsage } from "./grokusage.
6
5
  import { errorMessage } from "./log.ts";
7
6
  import { grokAuthJsonFor, grokPaths, grokPool, grokSeatFromEnv, grokStoreDirFor } from "./paths.ts";
8
7
  import type { Provider, SampleReport } from "./provider.ts";
9
- import { loadAccounts, type Harvest } from "./state.ts";
8
+ import { loadAccounts, readJsonFile, type Harvest } from "./state.ts";
10
9
  import { statusOnlyProvider, type AuthEntry } from "./statusonly.ts";
11
- import { InstantSchema, type Account } from "./types.ts";
10
+ import { ErrnoSchema, InstantSchema, type Account } from "./types.ts";
12
11
  import { c } from "../cli/render.ts";
13
12
 
14
13
  const GrokAuthEntrySchema = z.looseObject({
@@ -37,16 +36,15 @@ function harvestOf(id: string, key: string, entry: GrokAuthEntry): Harvest {
37
36
  }
38
37
 
39
38
  function readMap(path: string): [string, GrokAuthEntry][] {
40
- let raw: unknown;
39
+ let map: Record<string, unknown>;
41
40
  try {
42
- raw = JSON.parse(readFileSync(path, "utf8"));
43
- } catch {
44
- return [];
41
+ map = readJsonFile(path, z.record(z.string(), z.unknown()));
42
+ } catch (e) {
43
+ if (ErrnoSchema.safeParse(e).data?.code === "ENOENT") return [];
44
+ throw e;
45
45
  }
46
- const map = z.record(z.string(), z.unknown()).safeParse(raw);
47
- if (!map.success) return [];
48
46
  const out: [string, GrokAuthEntry][] = [];
49
- for (const [key, value] of Object.entries(map.data)) {
47
+ for (const [key, value] of Object.entries(map)) {
50
48
  const parsed = GrokAuthEntrySchema.safeParse(value);
51
49
  if (!parsed.success) continue;
52
50
  out.push([key, parsed.data]);
@@ -1,11 +1,11 @@
1
- import { readFileSync } from "node:fs";
2
1
  import { join } from "node:path";
3
2
  import { z } from "zod";
4
3
  import { writeFileAtomic } from "./atomic.ts";
5
4
  import { env, HOME, opencodeGoAuthJsonFor, opencodeGoPaths, opencodeGoPool, opencodeGoStoreDirFor } from "./paths.ts";
6
5
  import type { Provider } from "./provider.ts";
7
- import { type Harvest } from "./state.ts";
6
+ import { readJsonFile, type Harvest } from "./state.ts";
8
7
  import { statusOnlyProvider, type AuthEntry } from "./statusonly.ts";
8
+ import { ErrnoSchema } from "./types.ts";
9
9
  import { c } from "../cli/render.ts";
10
10
 
11
11
  const OpencodeAuthEntrySchema = z.looseObject({ type: z.string(), key: z.string().optional() });
@@ -35,15 +35,14 @@ function harvestOf(key: string): Harvest {
35
35
  }
36
36
 
37
37
  function readAuth(path: string): AuthEntry[] {
38
- let raw: unknown;
38
+ let map: z.infer<typeof OpencodeAuthFileSchema>;
39
39
  try {
40
- raw = JSON.parse(readFileSync(path, "utf8"));
41
- } catch {
42
- return [];
40
+ map = readJsonFile(path, OpencodeAuthFileSchema);
41
+ } catch (e) {
42
+ if (ErrnoSchema.safeParse(e).data?.code === "ENOENT") return [];
43
+ throw e;
43
44
  }
44
- const map = OpencodeAuthFileSchema.safeParse(raw);
45
- if (!map.success) return [];
46
- const entry = OpencodeAuthEntrySchema.safeParse(map.data["opencode-go"]);
45
+ const entry = OpencodeAuthEntrySchema.safeParse(map["opencode-go"]);
47
46
  if (!entry.success || entry.data.type !== "api" || !entry.data.key) return [];
48
47
  return [{ id: idOfKey(entry.data.key), usable: true, harvest: harvestOf(entry.data.key) }];
49
48
  }