tokentracky 0.1.2 → 0.2.1
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 +11 -2
- package/bin/tokentracky.mjs +118 -19
- package/package.json +2 -2
- package/release-manifest.json +33 -8
package/README.md
CHANGED
|
@@ -22,10 +22,19 @@ The package currently contains an empty release manifest, so it intentionally re
|
|
|
22
22
|
"url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.1.0/tokentracky-0.1.0-macos-arm64.dmg",
|
|
23
23
|
"sha256": "<64 lowercase hex characters from the verified release>"
|
|
24
24
|
}
|
|
25
|
-
}}
|
|
25
|
+
}},
|
|
26
|
+
"linux": {
|
|
27
|
+
"x86_64": { "cli": { "file": "tokentracky-0.1.0-linux-x86_64", "url": "…", "sha256": "…" } },
|
|
28
|
+
"aarch64": { "cli": { "file": "tokentracky-0.1.0-linux-aarch64", "url": "…", "sha256": "…" } }
|
|
29
|
+
},
|
|
30
|
+
"windows": {
|
|
31
|
+
"x86_64": { "cli": { "file": "tokentracky-0.1.0-windows-x86_64.exe", "url": "…", "sha256": "…" } }
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
```
|
|
30
37
|
|
|
31
|
-
The launcher supports macOS 13+ on arm64
|
|
38
|
+
Each CLI's `url` is its file under the same release tag. The launcher supports macOS 13+ on arm64, Linux on x64 and arm64 (one static binary for every distribution) and Windows on x64. It verifies SHA-256 before execution, caches the binary under the user's cache directory (`%LOCALAPPDATA%\tokentracky` on Windows), and rejects redirects outside GitHub's HTTPS release asset hosts. `TOKENTRACKY_CACHE_DIR` selects an isolated cache. The disposable install harness edits only its installed manifest; the shipped launcher has no test manifest override. Downloads have a 60-second total deadline and a 100 MiB limit, reject URL credentials/nondefault ports, and cancel redirect bodies.
|
|
39
|
+
|
|
40
|
+
`login` from a Mac terminal without `Tokentracky.app` in `/Applications` or `~/Applications` first asks whether to install it (Enter or Ctrl-D is no; Ctrl-C stops). On yes the launcher downloads the version's DMG from the manifest's `macos.arm64.app` entry under the same checks, refuses it unless its SHA-256 matches, attaches it read-only, copies the app into `/Applications` (else `~/Applications`) and detaches it. The CLI then opens the app once the computer is approved. A failed install says why and carries on without the app.
|
package/bin/tokentracky.mjs
CHANGED
|
@@ -3,10 +3,10 @@ import process from 'node:process';
|
|
|
3
3
|
import { Buffer } from 'node:buffer';
|
|
4
4
|
import { setTimeout, clearTimeout } from 'node:timers';
|
|
5
5
|
import { createHash } from 'node:crypto';
|
|
6
|
-
import { chmod, mkdir, readFile, rename, rm, stat } from 'node:fs/promises';
|
|
6
|
+
import { chmod, mkdir, mkdtemp, readFile, rename, rm, stat } from 'node:fs/promises';
|
|
7
7
|
import { realpathSync } from 'node:fs';
|
|
8
|
-
import { homedir, release as kernelRelease } from 'node:os';
|
|
9
|
-
import { dirname, join, resolve } from 'node:path';
|
|
8
|
+
import { homedir, tmpdir, release as kernelRelease } from 'node:os';
|
|
9
|
+
import { dirname, join, resolve, sep } from 'node:path';
|
|
10
10
|
import { spawn } from 'node:child_process';
|
|
11
11
|
import { URL, fileURLToPath } from 'node:url';
|
|
12
12
|
|
|
@@ -15,26 +15,48 @@ const REPOSITORY = 'AuvreyDurelle/tokentracky';
|
|
|
15
15
|
const MANIFEST_PATH = new URL('../release-manifest.json', import.meta.url);
|
|
16
16
|
const VERSION = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
17
17
|
|
|
18
|
+
/** Each supported Node `platform-arch`: its name, its place in the manifest and its asset's suffix. */
|
|
19
|
+
export const PLATFORMS = {
|
|
20
|
+
'darwin-arm64': { name: 'macOS arm64', os: 'macos', arch: 'arm64', asset: 'macos-arm64' },
|
|
21
|
+
'linux-x64': { name: 'Linux x86_64', os: 'linux', arch: 'x86_64', asset: 'linux-x86_64' },
|
|
22
|
+
'linux-arm64': { name: 'Linux aarch64', os: 'linux', arch: 'aarch64', asset: 'linux-aarch64' },
|
|
23
|
+
'win32-x64': { name: 'Windows x86_64', os: 'windows', arch: 'x86_64', asset: 'windows-x86_64.exe' },
|
|
24
|
+
};
|
|
25
|
+
|
|
18
26
|
export function platformError(platform = process.platform, arch = process.arch, release = kernelRelease()) {
|
|
19
|
-
if (platform
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
if (platform === 'darwin') {
|
|
28
|
+
if (arch !== 'arm64') return `Tokentracky currently supports Apple Silicon (arm64) only; this system is macOS/${arch}.`;
|
|
29
|
+
const [major] = release.split('.').map(Number);
|
|
30
|
+
if (!Number.isFinite(major) || major < 22) return `Tokentracky requires macOS 13 or later; detected macOS kernel ${release || 'unknown'}.`;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (!Object.hasOwn(PLATFORMS, `${platform}-${arch}`)) {
|
|
34
|
+
return `Tokentracky supports macOS 13 or later on Apple Silicon, Linux on x64 and arm64, and Windows on x64; this system is ${platform}/${arch}.`;
|
|
35
|
+
}
|
|
23
36
|
return null;
|
|
24
37
|
}
|
|
25
38
|
|
|
39
|
+
/** Where a version's binary is cached: the user's cache folder, or local application data on Windows. */
|
|
40
|
+
export function cacheFolder(version, platform, arch, env = process.env) {
|
|
41
|
+
const base = platform === 'win32'
|
|
42
|
+
? join(env.LOCALAPPDATA || join(homedir(), 'AppData', 'Local'), 'tokentracky')
|
|
43
|
+
: join(homedir(), '.cache', 'tokentracky');
|
|
44
|
+
return join(base, version, `${platform}-${arch}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
26
47
|
function fail(message) {
|
|
27
48
|
process.stderr.write(`${message}\n`);
|
|
28
49
|
process.exitCode = 1;
|
|
29
50
|
}
|
|
30
51
|
|
|
31
|
-
function safeManifestEntry(manifest, version) {
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
function safeManifestEntry(manifest, version, platform) {
|
|
53
|
+
const { name, os, arch, asset } = platform;
|
|
54
|
+
if (!manifest || manifest.schemaVersion !== 1 || manifest.latest !== version || !manifest.releases || !Object.hasOwn(manifest.releases, version) ||
|
|
55
|
+
!Object.hasOwn(manifest.releases[version]?.[os] ?? {}, arch)) {
|
|
56
|
+
throw new Error(`No verified Tokentracky ${version} binary is published for ${name} yet.`);
|
|
34
57
|
}
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const file = `tokentracky-${version}-macos-arm64`;
|
|
58
|
+
const artifact = manifest.releases[version][os][arch]?.cli;
|
|
59
|
+
const file = `tokentracky-${version}-${asset}`;
|
|
38
60
|
const url = `https://github.com/${REPOSITORY}/releases/download/v${version}/${file}`;
|
|
39
61
|
if (manifest.releases[version]?.verified !== true || artifact?.file !== file || !/^[a-f0-9]{64}$/.test(artifact.sha256 ?? '') || artifact.url !== url) {
|
|
40
62
|
throw new Error(`The packaged integrity manifest for Tokentracky ${version} is invalid.`);
|
|
@@ -103,10 +125,10 @@ export async function download(url, destination, fetchImpl = fetch, { maxBytes =
|
|
|
103
125
|
export async function installVerifiedBinary({ manifest, version = VERSION, platform = process.platform, arch = process.arch, osVersion = kernelRelease(), cacheRoot, fetchImpl = fetch }) {
|
|
104
126
|
const problem = platformError(platform, arch, osVersion);
|
|
105
127
|
if (problem) throw new Error(problem);
|
|
106
|
-
const entry = safeManifestEntry(manifest, version);
|
|
107
|
-
cacheRoot ??=
|
|
128
|
+
const entry = safeManifestEntry(manifest, version, PLATFORMS[`${platform}-${arch}`]);
|
|
129
|
+
cacheRoot ??= cacheFolder(version, platform, arch);
|
|
108
130
|
const target = resolve(cacheRoot, entry.file);
|
|
109
|
-
if (!target.startsWith(`${resolve(cacheRoot)}
|
|
131
|
+
if (!target.startsWith(`${resolve(cacheRoot)}${sep}`)) throw new Error('Invalid binary cache path.');
|
|
110
132
|
try {
|
|
111
133
|
const metadata = await stat(target);
|
|
112
134
|
if (!metadata.isFile() || metadata.size > MAX_BINARY_BYTES) throw new Error('Invalid binary cache entry.');
|
|
@@ -121,7 +143,7 @@ export async function installVerifiedBinary({ manifest, version = VERSION, platf
|
|
|
121
143
|
const bytes = await download(entry.url, temporary, fetchImpl);
|
|
122
144
|
const actual = createHash('sha256').update(bytes).digest('hex');
|
|
123
145
|
if (actual !== entry.sha256) throw new Error(`Tokentracky binary integrity check failed (expected ${entry.sha256}, received ${actual}).`);
|
|
124
|
-
await chmod(temporary, 0o700);
|
|
146
|
+
if (platform !== 'win32') await chmod(temporary, 0o700);
|
|
125
147
|
await rename(temporary, target);
|
|
126
148
|
} catch (error) {
|
|
127
149
|
await rm(temporary, { force: true });
|
|
@@ -130,6 +152,78 @@ export async function installVerifiedBinary({ manifest, version = VERSION, platf
|
|
|
130
152
|
return target;
|
|
131
153
|
}
|
|
132
154
|
|
|
155
|
+
/** Where the Mac app is looked for and put: the system's Applications folder, then the user's own. */
|
|
156
|
+
export const APP_FOLDERS = ['/Applications', join(homedir(), 'Applications')];
|
|
157
|
+
const APP = 'Tokentracky.app';
|
|
158
|
+
|
|
159
|
+
/** `login` from a Mac terminal, where the launcher offers the app before the CLI starts. Not with `TOKENTRACKY_HOME`:
|
|
160
|
+
* the app opens with the system's environment, so the CLI does not hand that credential to it. */
|
|
161
|
+
export function offersApp(args, { platform = process.platform, interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY), env = process.env } = {}) {
|
|
162
|
+
return platform === 'darwin' && interactive && !env.TOKENTRACKY_HOME && args.includes('login') && !args.some((arg) => ['-h', '--help', '-v', '--version'].includes(arg));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The installed Mac app, or null. */
|
|
166
|
+
export async function installedApp(folders = APP_FOLDERS) {
|
|
167
|
+
for (const folder of folders) {
|
|
168
|
+
const app = join(folder, APP);
|
|
169
|
+
if (await stat(app).then((metadata) => metadata.isDirectory(), () => false)) return app;
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function run(command, args) {
|
|
175
|
+
return new Promise((resolve, reject) => {
|
|
176
|
+
const child = spawn(command, args, { stdio: 'ignore' });
|
|
177
|
+
child.once('error', reject);
|
|
178
|
+
child.once('exit', (code) => (code === 0 ? resolve() : reject(new Error(`${command} exited with ${code}.`))));
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Downloads this version's DMG, checks it against the manifest, and copies the app into the first folder that takes it. */
|
|
183
|
+
export async function installMacApp({ manifest, version = VERSION, folders = APP_FOLDERS, fetchImpl = fetch }) {
|
|
184
|
+
const file = `tokentracky-${version}-macos-arm64.dmg`;
|
|
185
|
+
const url = `https://github.com/${REPOSITORY}/releases/download/v${version}/${file}`;
|
|
186
|
+
const entry = manifest?.releases?.[version]?.macos?.arm64?.app;
|
|
187
|
+
if (manifest?.latest !== version || manifest.releases?.[version]?.verified !== true || entry?.file !== file || entry.url !== url || !/^[a-f0-9]{64}$/.test(entry.sha256 ?? '')) {
|
|
188
|
+
throw new Error(`No verified Tokentracky ${version} Mac app is published.`);
|
|
189
|
+
}
|
|
190
|
+
const temporary = await mkdtemp(join(tmpdir(), 'tokentracky-app-'));
|
|
191
|
+
try {
|
|
192
|
+
const image = join(temporary, file);
|
|
193
|
+
const actual = createHash('sha256').update(await download(url, image, fetchImpl)).digest('hex');
|
|
194
|
+
if (actual !== entry.sha256) throw new Error(`Tokentracky app integrity check failed (expected ${entry.sha256}, received ${actual}).`);
|
|
195
|
+
const volume = join(temporary, 'volume');
|
|
196
|
+
await run('hdiutil', ['attach', image, '-nobrowse', '-readonly', '-noautoopen', '-mountpoint', volume]);
|
|
197
|
+
try {
|
|
198
|
+
for (const folder of folders) {
|
|
199
|
+
await mkdir(folder, { recursive: true }).catch(() => {});
|
|
200
|
+
if (await run('ditto', [join(volume, APP), join(folder, APP)]).then(() => true, () => false)) return join(folder, APP);
|
|
201
|
+
}
|
|
202
|
+
throw new Error('Tokentracky.app could not be copied into Applications.');
|
|
203
|
+
} finally { await run('hdiutil', ['detach', volume, '-quiet']).catch(() => {}); }
|
|
204
|
+
} finally { await rm(temporary, { recursive: true, force: true }); }
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** On a Mac without the app, `login` offers it first: after approval the CLI opens it, and it keeps uploading from the
|
|
208
|
+
* menu bar. Without it the CLI keeps uploading itself while its terminal stays open. */
|
|
209
|
+
async function offerMacApp(args) {
|
|
210
|
+
if (!offersApp(args) || (await installedApp())) return;
|
|
211
|
+
const { createInterface } = await import('node:readline/promises');
|
|
212
|
+
const terminal = createInterface({ input: process.stdin, output: process.stdout });
|
|
213
|
+
// Ctrl-C stops here, as it stops the CLI; Ctrl-D answers no.
|
|
214
|
+
terminal.once('SIGINT', () => { terminal.close(); process.stdout.write('\n'); process.exit(130); });
|
|
215
|
+
const answer = await terminal.question('Tokentracky for Mac keeps uploading from the menu bar after you close this terminal. Install it in Applications? [y/N] ').catch(() => '');
|
|
216
|
+
terminal.close();
|
|
217
|
+
if (!/^y(es)?$/i.test(answer.trim())) return;
|
|
218
|
+
try {
|
|
219
|
+
process.stdout.write('Downloading Tokentracky for Mac…\n');
|
|
220
|
+
const app = await installMacApp({ manifest: JSON.parse(await readFile(MANIFEST_PATH, 'utf8')) });
|
|
221
|
+
process.stdout.write(`Installed ${app}. It opens once you approve this computer.\n`);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)} Continuing without the app.\n`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
133
227
|
async function getBinary() {
|
|
134
228
|
const manifest = JSON.parse(await readFile(MANIFEST_PATH, 'utf8'));
|
|
135
229
|
return installVerifiedBinary({ manifest, cacheRoot: process.env.TOKENTRACKY_CACHE_DIR });
|
|
@@ -138,14 +232,19 @@ async function getBinary() {
|
|
|
138
232
|
export async function main(args = process.argv.slice(2)) {
|
|
139
233
|
try {
|
|
140
234
|
const binary = await getBinary();
|
|
235
|
+
await offerMacApp(args);
|
|
141
236
|
const child = spawn(binary, args, { stdio: 'inherit' });
|
|
142
|
-
|
|
237
|
+
// Windows has no signals to pass on: the console sends Ctrl+C and Ctrl+Break to the CLI itself, and Node could
|
|
238
|
+
// only end it outright. The launcher waits for it to stop.
|
|
239
|
+
const windows = process.platform === 'win32';
|
|
240
|
+
const signals = windows ? ['SIGINT', 'SIGBREAK', 'SIGHUP'] : ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
241
|
+
const handlers = new Map(signals.map((signal) => [signal, () => { if (!windows) child.kill(signal); }]));
|
|
143
242
|
for (const [signal, handler] of handlers) process.on(signal, handler);
|
|
144
243
|
const cleanup = () => { for (const [name, handler] of handlers) process.off(name, handler); };
|
|
145
244
|
child.once('error', (error) => { cleanup(); fail(`Could not start the Tokentracky binary: ${error.message}`); });
|
|
146
245
|
child.once('exit', (code, signal) => {
|
|
147
246
|
cleanup();
|
|
148
|
-
if (signal) { process.kill(process.pid, signal); return; }
|
|
247
|
+
if (signal && !windows) { process.kill(process.pid, signal); return; }
|
|
149
248
|
process.exitCode = code ?? 1;
|
|
150
249
|
});
|
|
151
250
|
} catch (error) { fail(error instanceof Error ? error.message : String(error)); }
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokentracky",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "Tokentracky Rust CLI for Apple Silicon Macs",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Tokentracky Rust CLI for Apple Silicon Macs, Linux and Windows",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": { "type": "git", "url": "git+https://github.com/AuvreyDurelle/tokentracky.git" },
|
|
7
7
|
"bin": { "tokentracky": "bin/tokentracky.mjs" },
|
package/release-manifest.json
CHANGED
|
@@ -1,20 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"latest": "0.1
|
|
3
|
+
"latest": "0.2.1",
|
|
4
4
|
"releases": {
|
|
5
|
-
"0.1
|
|
5
|
+
"0.2.1": {
|
|
6
6
|
"verified": true,
|
|
7
7
|
"macos": {
|
|
8
8
|
"arm64": {
|
|
9
9
|
"cli": {
|
|
10
|
-
"file": "tokentracky-0.1
|
|
11
|
-
"url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.1
|
|
12
|
-
"sha256": "
|
|
10
|
+
"file": "tokentracky-0.2.1-macos-arm64",
|
|
11
|
+
"url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.2.1/tokentracky-0.2.1-macos-arm64",
|
|
12
|
+
"sha256": "bad7a1fa9b20ce37cda55c0a4042b168162f85a37c0c06c5c2dca53fa608a3fb"
|
|
13
13
|
},
|
|
14
14
|
"app": {
|
|
15
|
-
"file": "tokentracky-0.1
|
|
16
|
-
"url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.1
|
|
17
|
-
"sha256": "
|
|
15
|
+
"file": "tokentracky-0.2.1-macos-arm64.dmg",
|
|
16
|
+
"url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.2.1/tokentracky-0.2.1-macos-arm64.dmg",
|
|
17
|
+
"sha256": "524a88b5d13aa74051e8ae783660e831d5a691faf8d387ee9cba7417a6d8649c"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"linux": {
|
|
22
|
+
"aarch64": {
|
|
23
|
+
"cli": {
|
|
24
|
+
"file": "tokentracky-0.2.1-linux-aarch64",
|
|
25
|
+
"url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.2.1/tokentracky-0.2.1-linux-aarch64",
|
|
26
|
+
"sha256": "2b185606154670c92f6c8e511406199f56d8fd6d058fb303a9b62cec71c727aa"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"x86_64": {
|
|
30
|
+
"cli": {
|
|
31
|
+
"file": "tokentracky-0.2.1-linux-x86_64",
|
|
32
|
+
"url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.2.1/tokentracky-0.2.1-linux-x86_64",
|
|
33
|
+
"sha256": "b1afc2c080c415787940dd07a6014e5f134a2ceba500b7ceea812ceb288d2c47"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"windows": {
|
|
38
|
+
"x86_64": {
|
|
39
|
+
"cli": {
|
|
40
|
+
"file": "tokentracky-0.2.1-windows-x86_64.exe",
|
|
41
|
+
"url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.2.1/tokentracky-0.2.1-windows-x86_64.exe",
|
|
42
|
+
"sha256": "424b8dd1bd240014829e27f610d75ee613dbcb249853ca6e8ed31858c7e4232a"
|
|
18
43
|
}
|
|
19
44
|
}
|
|
20
45
|
}
|