@token-dashboard/codex-usage-uploader 0.1.6 → 0.1.7
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/dist/bin/codex-usage-uploader.js +5 -0
- package/dist/cli.mjs +1 -0
- package/package.json +9 -4
- package/bin/codex-usage-uploader.js +0 -9
- package/src/auth.js +0 -56
- package/src/cli.js +0 -759
- package/src/collector.js +0 -676
- package/src/constants.js +0 -44
- package/src/install.js +0 -156
- package/src/launchd.js +0 -170
- package/src/local-usage.js +0 -342
- package/src/parser.js +0 -180
- package/src/runtime-config.js +0 -182
- package/src/state-db.js +0 -325
- package/src/utils.js +0 -68
package/src/utils.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { Buffer } from 'node:buffer';
|
|
5
|
-
import { createHash } from 'node:crypto';
|
|
6
|
-
|
|
7
|
-
export function nowTs() {
|
|
8
|
-
return Date.now() / 1000;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function sleep(ms) {
|
|
12
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function stableStringify(value) {
|
|
16
|
-
return JSON.stringify(sortForJson(value));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function sortForJson(value) {
|
|
20
|
-
if (Array.isArray(value)) {
|
|
21
|
-
return value.map(sortForJson);
|
|
22
|
-
}
|
|
23
|
-
if (value && typeof value === 'object') {
|
|
24
|
-
return Object.fromEntries(
|
|
25
|
-
Object.keys(value)
|
|
26
|
-
.sort()
|
|
27
|
-
.map((key) => [key, sortForJson(value[key])]),
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
return value;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function isoToEpochMs(value) {
|
|
34
|
-
if (!value) return null;
|
|
35
|
-
const normalized = String(value).replace('Z', '+00:00');
|
|
36
|
-
const timestamp = Date.parse(normalized);
|
|
37
|
-
return Number.isNaN(timestamp) ? null : timestamp;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function deriveRepoName(repositoryUrl, cwd) {
|
|
41
|
-
if (repositoryUrl) {
|
|
42
|
-
let last = repositoryUrl.replace(/\/+$/, '').split('/').pop() ?? '';
|
|
43
|
-
if (last.endsWith('.git')) last = last.slice(0, -4);
|
|
44
|
-
if (last) return last;
|
|
45
|
-
}
|
|
46
|
-
if (cwd) return path.basename(cwd) || null;
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function computeEventUid(collectorId, relpath, lineNo) {
|
|
51
|
-
const raw = Buffer.from(`${collectorId}|${relpath}|${lineNo}`, 'utf8');
|
|
52
|
-
return createHash('sha1').update(raw).digest('hex');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function readPersistentCollectorId(filePath) {
|
|
56
|
-
try {
|
|
57
|
-
const content = fs.readFileSync(filePath, 'utf8').trim();
|
|
58
|
-
return content || null;
|
|
59
|
-
} catch {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function writePersistentCollectorId(filePath, id) {
|
|
65
|
-
const tmpPath = `${filePath}.${process.pid}.tmp`;
|
|
66
|
-
fs.writeFileSync(tmpPath, id, 'utf8');
|
|
67
|
-
fs.renameSync(tmpPath, filePath);
|
|
68
|
-
}
|