charge-connect 0.1.5 → 0.1.6
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/collect.js +17 -5
- package/package.json +1 -1
package/collect.js
CHANGED
|
@@ -255,13 +255,24 @@ async function collectLive() {
|
|
|
255
255
|
return (data.blocks ?? []).find((b) => b.isActive) ?? null;
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
// Claude Code 자격증명: macOS는 Keychain, Windows/Linux는 ~/.claude/.credentials.json
|
|
258
|
+
// Claude Code 자격증명: macOS는 Keychain, Windows/Linux는 ~/.claude/.credentials.json.
|
|
259
|
+
// macOS라도 SSH 세션의 Claude Code는 Keychain에 못 쓰고 파일에 토큰을 갱신하므로
|
|
260
|
+
// 한 곳만 읽으면 낡은 토큰으로 401/429를 반복할 수 있다. 둘 다 읽어 최신 쪽을 쓴다.
|
|
261
|
+
function freshestCredentials(sources) {
|
|
262
|
+
const expiresAt = (c) => Number((c?.claudeAiOauth ?? c)?.expiresAt) || 0;
|
|
263
|
+
return sources.reduce((a, b) => (expiresAt(b) > expiresAt(a) ? b : a));
|
|
264
|
+
}
|
|
265
|
+
|
|
259
266
|
async function claudeCredentials() {
|
|
267
|
+
const sources = [];
|
|
260
268
|
try {
|
|
261
|
-
|
|
262
|
-
} catch {
|
|
263
|
-
|
|
264
|
-
|
|
269
|
+
sources.push(JSON.parse(await runAsync("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"])));
|
|
270
|
+
} catch {}
|
|
271
|
+
try {
|
|
272
|
+
sources.push(JSON.parse(fs.readFileSync(path.join(HOME, ".claude", ".credentials.json"), "utf8")));
|
|
273
|
+
} catch {}
|
|
274
|
+
if (!sources.length) throw new Error("Claude Code 자격증명 없음");
|
|
275
|
+
return freshestCredentials(sources);
|
|
265
276
|
}
|
|
266
277
|
|
|
267
278
|
// Claude: Claude Code OAuth 세션을 재사용해 공식 usage API 조회.
|
|
@@ -798,6 +809,7 @@ module.exports = {
|
|
|
798
809
|
collectCodexBarProviders,
|
|
799
810
|
dropExpired,
|
|
800
811
|
durationLabel,
|
|
812
|
+
freshestCredentials,
|
|
801
813
|
normalizeRateWindow,
|
|
802
814
|
normalizeResetAt,
|
|
803
815
|
parseCodexBarJSON,
|