axusage 2.2.0 → 3.1.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/README.md +61 -15
- package/dist/adapters/github-copilot.js +2 -1
- package/dist/cli.js +58 -41
- package/dist/commands/auth-clear-command.d.ts +2 -0
- package/dist/commands/auth-clear-command.js +62 -3
- package/dist/commands/auth-setup-command.d.ts +1 -0
- package/dist/commands/auth-setup-command.js +36 -5
- package/dist/commands/auth-status-command.js +36 -4
- package/dist/commands/fetch-service-usage-with-reauth.js +2 -2
- package/dist/commands/fetch-service-usage.js +4 -2
- package/dist/commands/run-auth-setup.js +26 -5
- package/dist/commands/usage-command.js +5 -3
- package/dist/config/credential-sources.d.ts +9 -1
- package/dist/config/credential-sources.js +36 -1
- package/dist/services/create-auth-context.js +2 -1
- package/dist/services/do-setup-auth.js +2 -8
- package/dist/services/persist-storage-state.d.ts +1 -1
- package/dist/services/persist-storage-state.js +8 -8
- package/dist/services/setup-auth-flow.js +38 -11
- package/dist/services/shared-browser-auth-manager.js +14 -7
- package/dist/services/supported-service.js +4 -2
- package/dist/services/verify-session.js +3 -1
- package/dist/services/wait-for-login.d.ts +3 -2
- package/dist/services/wait-for-login.js +89 -18
- package/dist/utils/check-cli-dependency.d.ts +25 -0
- package/dist/utils/check-cli-dependency.js +81 -0
- package/dist/utils/color.d.ts +5 -0
- package/dist/utils/color.js +27 -0
- package/dist/utils/format-service-usage.js +1 -1
- package/dist/utils/resolve-prompt-capability.d.ts +1 -0
- package/dist/utils/resolve-prompt-capability.js +3 -0
- package/dist/utils/validate-root-options.d.ts +11 -0
- package/dist/utils/validate-root-options.js +18 -0
- package/dist/utils/write-atomic-json.d.ts +1 -0
- package/dist/utils/write-atomic-json.js +56 -0
- package/package.json +6 -5
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { chmod, rename, unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
function getErrorCode(error) {
|
|
4
|
+
if (error instanceof Error && "code" in error) {
|
|
5
|
+
return error.code;
|
|
6
|
+
}
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
export async function writeAtomicJson(filePath, data, mode) {
|
|
10
|
+
const temporaryPath = `${filePath}.${randomUUID()}.tmp`;
|
|
11
|
+
const writeOptions = mode === undefined ? "utf8" : { encoding: "utf8", mode };
|
|
12
|
+
await writeFile(temporaryPath, JSON.stringify(data), writeOptions);
|
|
13
|
+
if (mode !== undefined) {
|
|
14
|
+
await chmod(temporaryPath, mode).catch(() => {
|
|
15
|
+
// Best-effort: some filesystems ignore chmod, but the mode was set at write.
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
await rename(temporaryPath, filePath);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
const code = getErrorCode(error);
|
|
23
|
+
if (code === "EPERM" || code === "EACCES" || code === "EEXIST") {
|
|
24
|
+
// Windows can reject rename over an existing file; fall back to a backup swap.
|
|
25
|
+
// Best-effort: not fully atomic and assumes a single writer. Backups are
|
|
26
|
+
// cleaned up by auth-clear when possible.
|
|
27
|
+
const backupPath = `${filePath}.${randomUUID()}.bak`;
|
|
28
|
+
let hasBackup = false;
|
|
29
|
+
try {
|
|
30
|
+
await rename(filePath, backupPath);
|
|
31
|
+
hasBackup = true;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// Best-effort: source file may not exist or be locked.
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
await rename(temporaryPath, filePath);
|
|
38
|
+
}
|
|
39
|
+
catch (fallbackError) {
|
|
40
|
+
if (hasBackup) {
|
|
41
|
+
await rename(backupPath, filePath).catch(() => {
|
|
42
|
+
console.warn(`Warning: Failed to restore backup from ${backupPath}`);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
await unlink(temporaryPath).catch(() => { });
|
|
46
|
+
throw fallbackError;
|
|
47
|
+
}
|
|
48
|
+
if (hasBackup) {
|
|
49
|
+
await unlink(backupPath).catch(() => { });
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
await unlink(temporaryPath).catch(() => { });
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "axusage",
|
|
3
3
|
"author": "Łukasz Jerciński",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "3.1.0",
|
|
6
6
|
"description": "Monitor API usage across Claude, ChatGPT, GitHub Copilot, and Gemini from a single CLI",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@commander-js/extra-typings": "^14.0.0",
|
|
57
|
-
"
|
|
57
|
+
"@inquirer/prompts": "^8.2.0",
|
|
58
|
+
"axauth": "^2.1.0",
|
|
58
59
|
"chalk": "^5.6.2",
|
|
59
60
|
"commander": "^14.0.2",
|
|
60
61
|
"conf": "^15.0.2",
|
|
@@ -66,14 +67,14 @@
|
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
69
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
69
|
-
"@types/node": "^25.0.
|
|
70
|
+
"@types/node": "^25.0.9",
|
|
70
71
|
"@vitest/coverage-v8": "^4.0.17",
|
|
71
72
|
"eslint": "^9.39.2",
|
|
72
|
-
"eslint-config-axkit": "^1.
|
|
73
|
+
"eslint-config-axkit": "^1.1.0",
|
|
73
74
|
"fta-check": "^1.5.1",
|
|
74
75
|
"fta-cli": "^3.0.0",
|
|
75
76
|
"knip": "^5.81.0",
|
|
76
|
-
"prettier": "3.
|
|
77
|
+
"prettier": "3.8.0",
|
|
77
78
|
"semantic-release": "^25.0.2",
|
|
78
79
|
"typescript": "^5.9.3",
|
|
79
80
|
"vitest": "^4.0.17"
|