tokentracky 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 XPO8 Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,31 @@
1
- # Temporary Holding Version
1
+ # Tokentracky npm distribution
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This package is a Node launcher for the native Rust CLI. Node is needed to run `npx tokentracky` or the installed npm command; the downloaded Tokentracky CLI itself has no Node runtime dependency.
4
+
5
+ The package currently contains an empty release manifest, so it intentionally reports that a verified binary is not available. Release publication must replace `release-manifest.json` with the verified manifest for the matching package version. Each entry has the form:
6
+
7
+ ```json
8
+ {
9
+ "schemaVersion": 1,
10
+ "latest": "0.1.0",
11
+ "releases": {
12
+ "0.1.0": {
13
+ "verified": true,
14
+ "macos": { "arm64": {
15
+ "cli": {
16
+ "file": "tokentracky-0.1.0-macos-arm64",
17
+ "url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.1.0/tokentracky-0.1.0-macos-arm64",
18
+ "sha256": "<64 lowercase hex characters from the verified release>"
19
+ },
20
+ "app": {
21
+ "file": "tokentracky-0.1.0-macos-arm64.dmg",
22
+ "url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.1.0/tokentracky-0.1.0-macos-arm64.dmg",
23
+ "sha256": "<64 lowercase hex characters from the verified release>"
24
+ }
25
+ }}
26
+ }
27
+ }
28
+ }
29
+ ```
30
+
31
+ The launcher supports macOS 13+ on arm64 only. It verifies SHA-256 before execution, caches the binary under the user's cache directory, 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.
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env node
2
+ import process from 'node:process';
3
+ import { Buffer } from 'node:buffer';
4
+ import { setTimeout, clearTimeout } from 'node:timers';
5
+ import { createHash } from 'node:crypto';
6
+ import { chmod, mkdir, readFile, rename, rm, stat } from 'node:fs/promises';
7
+ import { realpathSync } from 'node:fs';
8
+ import { homedir, release as kernelRelease } from 'node:os';
9
+ import { dirname, join, resolve } from 'node:path';
10
+ import { spawn } from 'node:child_process';
11
+ import { URL, fileURLToPath } from 'node:url';
12
+
13
+ const { fetch, AbortController } = globalThis;
14
+ const REPOSITORY = 'AuvreyDurelle/tokentracky';
15
+ const MANIFEST_PATH = new URL('../release-manifest.json', import.meta.url);
16
+ const VERSION = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8')).version;
17
+
18
+ export function platformError(platform = process.platform, arch = process.arch, release = kernelRelease()) {
19
+ if (platform !== 'darwin') return `Tokentracky currently supports macOS 13 or later on Apple Silicon only; this system is ${platform}/${arch}.`;
20
+ if (arch !== 'arm64') return `Tokentracky currently supports Apple Silicon (arm64) only; this system is macOS/${arch}.`;
21
+ const [major] = release.split('.').map(Number);
22
+ if (!Number.isFinite(major) || major < 22) return `Tokentracky requires macOS 13 or later; detected macOS kernel ${release || 'unknown'}.`;
23
+ return null;
24
+ }
25
+
26
+ function fail(message) {
27
+ process.stderr.write(`${message}\n`);
28
+ process.exitCode = 1;
29
+ }
30
+
31
+ function safeManifestEntry(manifest, version) {
32
+ if (!manifest || manifest.schemaVersion !== 1 || manifest.latest !== version || !manifest.releases || !Object.hasOwn(manifest.releases, version)) {
33
+ throw new Error(`No verified Tokentracky ${version} binary is published for macOS arm64 yet.`);
34
+ }
35
+ const entry = manifest.releases[version]?.macos?.arm64;
36
+ const artifact = entry?.cli;
37
+ const file = `tokentracky-${version}-macos-arm64`;
38
+ const url = `https://github.com/${REPOSITORY}/releases/download/v${version}/${file}`;
39
+ if (manifest.releases[version]?.verified !== true || artifact?.file !== file || !/^[a-f0-9]{64}$/.test(artifact.sha256 ?? '') || artifact.url !== url) {
40
+ throw new Error(`The packaged integrity manifest for Tokentracky ${version} is invalid.`);
41
+ }
42
+ return { file, url, sha256: artifact.sha256 };
43
+ }
44
+
45
+ const MAX_BINARY_BYTES = 100 * 1024 * 1024;
46
+ const DOWNLOAD_TIMEOUT_MS = 60_000;
47
+
48
+ export async function download(url, destination, fetchImpl = fetch, { maxBytes = MAX_BINARY_BYTES, timeoutMs = DOWNLOAD_TIMEOUT_MS } = {}) {
49
+ const controller = new AbortController();
50
+ const timeout = setTimeout(() => controller.abort(new Error('Tokentracky release download timed out.')), timeoutMs);
51
+ let current = new URL(url);
52
+ try {
53
+ for (let redirects = 0; redirects <= 5; redirects++) {
54
+ if (current.protocol !== 'https:' || current.username || current.password || current.port ||
55
+ !['github.com', 'release-assets.githubusercontent.com', 'objects.githubusercontent.com'].includes(current.hostname)) {
56
+ throw new Error('The release download redirected outside the trusted GitHub HTTPS hosts.');
57
+ }
58
+ const response = await fetchImpl(current, { signal: controller.signal, redirect: 'manual', headers: { 'user-agent': 'tokentracky-npm-launcher' } });
59
+ if (response.status >= 300 && response.status < 400) {
60
+ await response.body?.cancel();
61
+ const location = response.headers.get('location');
62
+ if (!location || redirects === 5) throw new Error('The GitHub release download returned an invalid redirect.');
63
+ current = new URL(location, current);
64
+ continue;
65
+ }
66
+ if (!response.ok) {
67
+ await response.body?.cancel();
68
+ throw new Error(`The Tokentracky release download failed (HTTP ${response.status}).`);
69
+ }
70
+ if (Number(response.headers.get('content-length')) > maxBytes) {
71
+ await response.body?.cancel();
72
+ throw new Error('Tokentracky release download exceeds the binary size limit.');
73
+ }
74
+ const reader = response.body?.getReader();
75
+ if (!reader) throw new Error('The Tokentracky release download was empty.');
76
+ const abortReader = () => { void reader.cancel(controller.signal.reason).catch(() => {}); };
77
+ controller.signal.addEventListener('abort', abortReader, { once: true });
78
+ if (controller.signal.aborted) abortReader();
79
+ const chunks = [];
80
+ let size = 0;
81
+ try {
82
+ while (true) {
83
+ const { done, value } = await reader.read();
84
+ controller.signal.throwIfAborted();
85
+ if (done) break;
86
+ size += value.byteLength;
87
+ if (size > maxBytes) throw new Error('Tokentracky release download exceeds the binary size limit.');
88
+ chunks.push(Buffer.from(value));
89
+ }
90
+ } catch (error) {
91
+ await reader.cancel().catch(() => {});
92
+ throw error;
93
+ } finally { controller.signal.removeEventListener('abort', abortReader); reader.releaseLock(); }
94
+ const bytes = Buffer.concat(chunks, size);
95
+ controller.signal.throwIfAborted();
96
+ await import('node:fs/promises').then(({ writeFile }) => writeFile(destination, bytes, { flag: 'wx', mode: 0o700 }));
97
+ return bytes;
98
+ }
99
+ throw new Error('Too many redirects while downloading the Tokentracky release.');
100
+ } finally { clearTimeout(timeout); }
101
+ }
102
+
103
+ export async function installVerifiedBinary({ manifest, version = VERSION, platform = process.platform, arch = process.arch, osVersion = kernelRelease(), cacheRoot, fetchImpl = fetch }) {
104
+ const problem = platformError(platform, arch, osVersion);
105
+ if (problem) throw new Error(problem);
106
+ const entry = safeManifestEntry(manifest, version);
107
+ cacheRoot ??= join(homedir(), '.cache', 'tokentracky', version, 'darwin-arm64');
108
+ const target = resolve(cacheRoot, entry.file);
109
+ if (!target.startsWith(`${resolve(cacheRoot)}/`)) throw new Error('Invalid binary cache path.');
110
+ try {
111
+ const metadata = await stat(target);
112
+ if (!metadata.isFile() || metadata.size > MAX_BINARY_BYTES) throw new Error('Invalid binary cache entry.');
113
+ const existing = await readFile(target);
114
+ if (createHash('sha256').update(existing).digest('hex') === entry.sha256 && (await stat(target)).isFile()) return target;
115
+ await rm(target, { force: true });
116
+ } catch (error) { if (error?.code !== 'ENOENT') throw error; }
117
+
118
+ await mkdir(dirname(target), { recursive: true, mode: 0o700 });
119
+ const temporary = join(dirname(target), `.tokentracky-${process.pid}-${Date.now()}.tmp`);
120
+ try {
121
+ const bytes = await download(entry.url, temporary, fetchImpl);
122
+ const actual = createHash('sha256').update(bytes).digest('hex');
123
+ if (actual !== entry.sha256) throw new Error(`Tokentracky binary integrity check failed (expected ${entry.sha256}, received ${actual}).`);
124
+ await chmod(temporary, 0o700);
125
+ await rename(temporary, target);
126
+ } catch (error) {
127
+ await rm(temporary, { force: true });
128
+ throw error;
129
+ }
130
+ return target;
131
+ }
132
+
133
+ async function getBinary() {
134
+ const manifest = JSON.parse(await readFile(MANIFEST_PATH, 'utf8'));
135
+ return installVerifiedBinary({ manifest, cacheRoot: process.env.TOKENTRACKY_CACHE_DIR });
136
+ }
137
+
138
+ export async function main(args = process.argv.slice(2)) {
139
+ try {
140
+ const binary = await getBinary();
141
+ const child = spawn(binary, args, { stdio: 'inherit' });
142
+ const handlers = new Map(['SIGINT', 'SIGTERM', 'SIGHUP'].map((signal) => [signal, () => child.kill(signal)]));
143
+ for (const [signal, handler] of handlers) process.on(signal, handler);
144
+ const cleanup = () => { for (const [name, handler] of handlers) process.off(name, handler); };
145
+ child.once('error', (error) => { cleanup(); fail(`Could not start the Tokentracky binary: ${error.message}`); });
146
+ child.once('exit', (code, signal) => {
147
+ cleanup();
148
+ if (signal) { process.kill(process.pid, signal); return; }
149
+ process.exitCode = code ?? 1;
150
+ });
151
+ } catch (error) { fail(error instanceof Error ? error.message : String(error)); }
152
+ }
153
+
154
+ if (process.argv[1] && realpathSync(resolve(process.argv[1])) === realpathSync(fileURLToPath(import.meta.url))) await main();
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "tokentracky",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Tokentracky Rust CLI for Apple Silicon Macs",
5
+ "type": "module",
6
+ "repository": { "type": "git", "url": "git+https://github.com/AuvreyDurelle/tokentracky.git" },
7
+ "bin": { "tokentracky": "bin/tokentracky.mjs" },
8
+ "files": ["bin/tokentracky.mjs", "release-manifest.json", "README.md", "LICENSE"],
9
+ "engines": { "node": ">=18" },
10
+ "scripts": { "prepublishOnly": "node scripts/validate-publication.mjs", "test": "node --test test/*.test.mjs", "test:harness": "node scripts/npm-harness.mjs", "pack:check": "npm pack --dry-run" },
11
+ "license": "MIT"
12
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "latest": "0.1.0",
4
+ "releases": {
5
+ "0.1.0": {
6
+ "verified": true,
7
+ "macos": {
8
+ "arm64": {
9
+ "cli": {
10
+ "file": "tokentracky-0.1.0-macos-arm64",
11
+ "url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.1.0/tokentracky-0.1.0-macos-arm64",
12
+ "sha256": "d948406c8e6baf8b3809639cc1ec556451d1e0bc528fce6f5a8c812c9d320ac6"
13
+ },
14
+ "app": {
15
+ "file": "tokentracky-0.1.0-macos-arm64.dmg",
16
+ "url": "https://github.com/AuvreyDurelle/tokentracky/releases/download/v0.1.0/tokentracky-0.1.0-macos-arm64.dmg",
17
+ "sha256": "1c50688f053ede61ea0039227e198af22e0b8088a3ae4a7de96eee78a7243851"
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
23
+ }