@tankpkg/cli 0.0.0-nightly.20260401.49863f7
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/tank.d.ts +1 -0
- package/dist/bin/tank.js +3205 -0
- package/dist/bin/tank.js.map +1 -0
- package/dist/debug-logger-CvbB8v_c.js +140 -0
- package/dist/debug-logger-CvbB8v_c.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +49 -0
- package/package.json +49 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import fs, { appendFileSync } from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import pino from "pino";
|
|
6
|
+
//#region src/lib/config.ts
|
|
7
|
+
const DEFAULT_CONFIG = { registry: process.env.TANK_REGISTRY_URL || "https://www.tankpkg.dev" };
|
|
8
|
+
/**
|
|
9
|
+
* Get the path to the tank config directory.
|
|
10
|
+
* Override with configDir parameter for testing.
|
|
11
|
+
*/
|
|
12
|
+
function getConfigDir(configDir) {
|
|
13
|
+
return configDir ?? path.join(os.homedir(), ".tank");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get the path to the tank config file.
|
|
17
|
+
* Override with configDir parameter for testing.
|
|
18
|
+
*/
|
|
19
|
+
function getConfigPath(configDir) {
|
|
20
|
+
return path.join(getConfigDir(configDir), "config.json");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Read the tank config file. Returns defaults if file doesn't exist.
|
|
24
|
+
* Override configDir for testing (avoids writing to real ~/.tank/).
|
|
25
|
+
*/
|
|
26
|
+
function getConfig(configDir) {
|
|
27
|
+
const configPath = getConfigPath(configDir);
|
|
28
|
+
try {
|
|
29
|
+
const raw = fs.readFileSync(configPath, "utf-8");
|
|
30
|
+
const parsed = JSON.parse(raw);
|
|
31
|
+
const merged = {
|
|
32
|
+
...DEFAULT_CONFIG,
|
|
33
|
+
...parsed
|
|
34
|
+
};
|
|
35
|
+
const envToken = process.env.TANK_TOKEN?.trim();
|
|
36
|
+
if (envToken) merged.token = envToken;
|
|
37
|
+
return merged;
|
|
38
|
+
} catch {
|
|
39
|
+
const envToken = process.env.TANK_TOKEN?.trim();
|
|
40
|
+
return {
|
|
41
|
+
...DEFAULT_CONFIG,
|
|
42
|
+
...envToken ? { token: envToken } : {}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Write config to disk. Merges with existing config.
|
|
48
|
+
* Creates ~/.tank/ directory if it doesn't exist.
|
|
49
|
+
* Sets file permissions to 0600 (owner read/write only) on Unix.
|
|
50
|
+
*/
|
|
51
|
+
function setConfig(partial, configDir) {
|
|
52
|
+
const dir = getConfigDir(configDir);
|
|
53
|
+
const configPath = getConfigPath(configDir);
|
|
54
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, {
|
|
55
|
+
recursive: true,
|
|
56
|
+
mode: 448
|
|
57
|
+
});
|
|
58
|
+
const merged = {
|
|
59
|
+
...getConfig(configDir),
|
|
60
|
+
...partial
|
|
61
|
+
};
|
|
62
|
+
fs.writeFileSync(configPath, `${JSON.stringify(merged, null, 2)}\n`, {
|
|
63
|
+
encoding: "utf-8",
|
|
64
|
+
mode: 384
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/lib/logger.ts
|
|
69
|
+
const logger = {
|
|
70
|
+
info: (msg) => console.log(chalk.blue("ℹ"), msg),
|
|
71
|
+
success: (msg) => console.log(chalk.green("✓"), msg),
|
|
72
|
+
warn: (msg) => console.log(chalk.yellow("⚠"), msg),
|
|
73
|
+
error: (msg) => console.error(chalk.red("✗"), msg)
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/version.ts
|
|
77
|
+
const VERSION = "0.0.0-nightly.20260401.49863f7";
|
|
78
|
+
const USER_AGENT = `tank-cli/${VERSION}`;
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/lib/debug-logger.ts
|
|
81
|
+
const lokiUrl = process.env.TANK_LOKI_URL || "http://localhost:3100";
|
|
82
|
+
const debugEnabled = process.env.TANK_DEBUG === "1" || process.env.TANK_DEBUG === "true";
|
|
83
|
+
const logBuffer = [];
|
|
84
|
+
let flushTimer = null;
|
|
85
|
+
async function flushToLoki() {
|
|
86
|
+
if (logBuffer.length === 0) return;
|
|
87
|
+
const logs = logBuffer.splice(0);
|
|
88
|
+
const values = logs.map((line) => {
|
|
89
|
+
try {
|
|
90
|
+
const parsed = JSON.parse(line);
|
|
91
|
+
return [parsed.time ? String(new Date(parsed.time).getTime() * 1e6) : String(Date.now() * 1e6), line];
|
|
92
|
+
} catch {
|
|
93
|
+
return [String(Date.now() * 1e6), line];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
try {
|
|
97
|
+
await fetch(`${lokiUrl}/loki/api/v1/push`, {
|
|
98
|
+
method: "POST",
|
|
99
|
+
headers: { "Content-Type": "application/json" },
|
|
100
|
+
body: JSON.stringify({ streams: [{
|
|
101
|
+
stream: { app: "tank-cli" },
|
|
102
|
+
values
|
|
103
|
+
}] })
|
|
104
|
+
});
|
|
105
|
+
} catch {
|
|
106
|
+
logBuffer.unshift(...logs);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const debugLog = pino({
|
|
110
|
+
level: "debug",
|
|
111
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
112
|
+
formatters: { level(label) {
|
|
113
|
+
return { level: label };
|
|
114
|
+
} }
|
|
115
|
+
}, { write(line) {
|
|
116
|
+
const trimmed = line.trimEnd();
|
|
117
|
+
logBuffer.push(trimmed);
|
|
118
|
+
if (debugEnabled) try {
|
|
119
|
+
appendFileSync("/tmp/tank-cli-debug.log", `${trimmed}\n`);
|
|
120
|
+
} catch {}
|
|
121
|
+
if (!flushTimer) flushTimer = setInterval(flushToLoki, 2e3);
|
|
122
|
+
if (logBuffer.length >= 50) flushToLoki();
|
|
123
|
+
} });
|
|
124
|
+
const httpLog = debugLog.child({ module: "http" });
|
|
125
|
+
const authFlowLog = debugLog.child({ module: "auth-flow" });
|
|
126
|
+
/**
|
|
127
|
+
* Flush pending logs before process exit.
|
|
128
|
+
* Call this at the end of CLI commands to ensure logs are delivered.
|
|
129
|
+
*/
|
|
130
|
+
async function flushLogs() {
|
|
131
|
+
if (flushTimer) {
|
|
132
|
+
clearInterval(flushTimer);
|
|
133
|
+
flushTimer = null;
|
|
134
|
+
}
|
|
135
|
+
await flushToLoki();
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
export { VERSION as a, getConfigDir as c, USER_AGENT as i, getConfigPath as l, flushLogs as n, logger as o, httpLog as r, getConfig as s, authFlowLog as t, setConfig as u };
|
|
139
|
+
|
|
140
|
+
//# sourceMappingURL=debug-logger-CvbB8v_c.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-logger-CvbB8v_c.js","names":["pkg.version"],"sources":["../src/lib/config.ts","../src/lib/logger.ts","../package.json","../src/version.ts","../src/lib/debug-logger.ts"],"sourcesContent":["import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport interface TankConfig {\n token?: string;\n user?: { name: string; email: string };\n registry: string;\n}\n\nconst DEFAULT_CONFIG: TankConfig = {\n registry: process.env.TANK_REGISTRY_URL || 'https://www.tankpkg.dev'\n};\n\n/**\n * Get the path to the tank config directory.\n * Override with configDir parameter for testing.\n */\nexport function getConfigDir(configDir?: string): string {\n return configDir ?? path.join(os.homedir(), '.tank');\n}\n\n/**\n * Get the path to the tank config file.\n * Override with configDir parameter for testing.\n */\nexport function getConfigPath(configDir?: string): string {\n return path.join(getConfigDir(configDir), 'config.json');\n}\n\n/**\n * Read the tank config file. Returns defaults if file doesn't exist.\n * Override configDir for testing (avoids writing to real ~/.tank/).\n */\nexport function getConfig(configDir?: string): TankConfig {\n const configPath = getConfigPath(configDir);\n\n try {\n const raw = fs.readFileSync(configPath, 'utf-8');\n const parsed = JSON.parse(raw) as Partial<TankConfig>;\n const merged = { ...DEFAULT_CONFIG, ...parsed };\n const envToken = process.env.TANK_TOKEN?.trim();\n if (envToken) {\n merged.token = envToken;\n }\n return merged;\n } catch {\n const envToken = process.env.TANK_TOKEN?.trim();\n return {\n ...DEFAULT_CONFIG,\n ...(envToken ? { token: envToken } : {})\n };\n }\n}\n\n/**\n * Write config to disk. Merges with existing config.\n * Creates ~/.tank/ directory if it doesn't exist.\n * Sets file permissions to 0600 (owner read/write only) on Unix.\n */\nexport function setConfig(partial: Partial<TankConfig>, configDir?: string): void {\n const dir = getConfigDir(configDir);\n const configPath = getConfigPath(configDir);\n\n // Create directory with 0700 permissions if it doesn't exist\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true, mode: 0o700 });\n }\n\n // Merge with existing config\n const existing = getConfig(configDir);\n const merged = { ...existing, ...partial };\n\n // Write config file\n fs.writeFileSync(configPath, `${JSON.stringify(merged, null, 2)}\\n`, {\n encoding: 'utf-8',\n mode: 0o600\n });\n}\n","import chalk from 'chalk';\n\nexport const logger = {\n info: (msg: string) => console.log(chalk.blue('ℹ'), msg),\n success: (msg: string) => console.log(chalk.green('✓'), msg),\n warn: (msg: string) => console.log(chalk.yellow('⚠'), msg),\n error: (msg: string) => console.error(chalk.red('✗'), msg)\n};\n","","import pkg from '../package.json' with { type: 'json' };\n\nexport const VERSION = pkg.version ?? '0.0.0';\nexport const USER_AGENT = `tank-cli/${VERSION}`;\n","import { appendFileSync } from 'node:fs';\n\nimport pino from 'pino';\n\nconst lokiUrl = process.env.TANK_LOKI_URL || 'http://localhost:3100';\nconst debugEnabled = process.env.TANK_DEBUG === '1' || process.env.TANK_DEBUG === 'true';\n\n// Buffer logs and push to Loki via HTTP (avoids pino.transport() worker thread serialization issues)\nconst logBuffer: string[] = [];\nlet flushTimer: ReturnType<typeof setInterval> | null = null;\n\nasync function flushToLoki() {\n if (logBuffer.length === 0) return;\n\n const logs = logBuffer.splice(0);\n const values: [string, string][] = logs.map((line) => {\n try {\n const parsed = JSON.parse(line);\n const ts = parsed.time ? String(new Date(parsed.time).getTime() * 1_000_000) : String(Date.now() * 1_000_000);\n return [ts, line];\n } catch {\n return [String(Date.now() * 1_000_000), line];\n }\n });\n\n try {\n await fetch(`${lokiUrl}/loki/api/v1/push`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n streams: [{ stream: { app: 'tank-cli' }, values }]\n })\n });\n } catch {\n logBuffer.unshift(...logs);\n }\n}\n\nconst lokiStream = {\n write(line: string) {\n const trimmed = line.trimEnd();\n logBuffer.push(trimmed);\n\n if (debugEnabled) {\n try {\n appendFileSync('/tmp/tank-cli-debug.log', `${trimmed}\\n`);\n } catch {\n // intentionally empty\n }\n }\n\n if (!flushTimer) {\n flushTimer = setInterval(flushToLoki, 2000);\n }\n if (logBuffer.length >= 50) {\n void flushToLoki();\n }\n }\n};\n\nexport const debugLog = pino(\n {\n level: 'debug',\n timestamp: pino.stdTimeFunctions.isoTime,\n formatters: {\n level(label: string) {\n return { level: label };\n }\n }\n },\n lokiStream as unknown as pino.DestinationStream\n);\n\nexport const httpLog = debugLog.child({ module: 'http' });\nexport const authFlowLog = debugLog.child({ module: 'auth-flow' });\n\n/**\n * Flush pending logs before process exit.\n * Call this at the end of CLI commands to ensure logs are delivered.\n */\nexport async function flushLogs(): Promise<void> {\n if (flushTimer) {\n clearInterval(flushTimer);\n flushTimer = null;\n }\n await flushToLoki();\n}\n"],"mappings":";;;;;;AAUA,MAAM,iBAA6B,EACjC,UAAU,QAAQ,IAAI,qBAAqB,2BAC5C;;;;;AAMD,SAAgB,aAAa,WAA4B;AACvD,QAAO,aAAa,KAAK,KAAK,GAAG,SAAS,EAAE,QAAQ;;;;;;AAOtD,SAAgB,cAAc,WA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C/C,KAAI,YAAY;AACd,gBAAc,WAAW;AACzB,eAAa;;AAEf,OAAM,aAAa"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/lib/config.d.ts
|
|
2
|
+
interface TankConfig {
|
|
3
|
+
token?: string;
|
|
4
|
+
user?: {
|
|
5
|
+
name: string;
|
|
6
|
+
email: string;
|
|
7
|
+
};
|
|
8
|
+
registry: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Get the path to the tank config directory.
|
|
12
|
+
* Override with configDir parameter for testing.
|
|
13
|
+
*/
|
|
14
|
+
declare function getConfigDir(configDir?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Get the path to the tank config file.
|
|
17
|
+
* Override with configDir parameter for testing.
|
|
18
|
+
*/
|
|
19
|
+
declare function getConfigPath(configDir?: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Read the tank config file. Returns defaults if file doesn't exist.
|
|
22
|
+
* Override configDir for testing (avoids writing to real ~/.tank/).
|
|
23
|
+
*/
|
|
24
|
+
declare function getConfig(configDir?: string): TankConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Write config to disk. Merges with existing config.
|
|
27
|
+
* Creates ~/.tank/ directory if it doesn't exist.
|
|
28
|
+
* Sets file permissions to 0600 (owner read/write only) on Unix.
|
|
29
|
+
*/
|
|
30
|
+
declare function setConfig(partial: Partial<TankConfig>, configDir?: string): void;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/lib/api-client.d.ts
|
|
33
|
+
declare class ApiClient {
|
|
34
|
+
private baseUrl;
|
|
35
|
+
private token?;
|
|
36
|
+
constructor(config: TankConfig);
|
|
37
|
+
private headers;
|
|
38
|
+
get(path: string): Promise<Response>;
|
|
39
|
+
post(path: string, body: unknown): Promise<Response>;
|
|
40
|
+
put(path: string, body: unknown): Promise<Response>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Factory: reads config and returns an ApiClient instance.
|
|
44
|
+
*/
|
|
45
|
+
declare function createApiClient(configDir?: string): ApiClient;
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/lib/logger.d.ts
|
|
48
|
+
declare const logger: {
|
|
49
|
+
info: (msg: string) => void;
|
|
50
|
+
success: (msg: string) => void;
|
|
51
|
+
warn: (msg: string) => void;
|
|
52
|
+
error: (msg: string) => void;
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/version.d.ts
|
|
56
|
+
declare const VERSION: string;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { ApiClient, type TankConfig, VERSION, createApiClient, getConfig, getConfigDir, getConfigPath, logger, setConfig };
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/lib/config.ts","../src/lib/api-client.ts","../src/lib/logger.ts","../src/version.ts"],"mappings":";UAIiB,UAAA;EACf,KAAA;EACA,IAAA;IAAS,IAAA;IAAc,KAAA;EAAA;EACvB,QAAA;AAAA;;;;;iBAWc,YAAA,CAAa,SAAA;;;;;iBAQb,aAAA,CAAc,SAAA;;;;;iBAQd,SAAA,CAAU,SAAA,YAAqB,UAAA;;;;;AA0B/C;iBAAgB,SAAA,CAAU,OAAA,EAAS,OAAA,CAAQ,UAAA,GAAa,SAAA;;;cCvD3C,SAAA;EAAA,QACH,OAAA;EAAA,QACA,KAAA;cAEI,MAAA,EAAQ,UAAA;EAAA,QAKZ,OAAA;EAgBF,GAAA,CAAI,IAAA,WAAe,OAAA,CAAQ,QAAA;EAW3B,IAAA,CAAK,IAAA,UAAc,IAAA,YAAgB,OAAA,CAAQ,QAAA;EAe3C,GAAA,CAAI,IAAA,UAAc,IAAA,YAAgB,OAAA,CAAQ,QAAA;AAAA;;;ADtClD;iBCyDgB,eAAA,CAAgB,SAAA,YAAqB,SAAA;;;cCzExC,MAAA;;;;;;;;cCAA,OAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { a as VERSION, c as getConfigDir, i as USER_AGENT, l as getConfigPath, o as logger, r as httpLog, s as getConfig, u as setConfig } from "./debug-logger-CvbB8v_c.js";
|
|
2
|
+
//#region src/lib/api-client.ts
|
|
3
|
+
var ApiClient = class {
|
|
4
|
+
baseUrl;
|
|
5
|
+
token;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.baseUrl = config.registry;
|
|
8
|
+
this.token = config.token;
|
|
9
|
+
}
|
|
10
|
+
headers(hasBody) {
|
|
11
|
+
const h = { "User-Agent": USER_AGENT };
|
|
12
|
+
if (this.token) h.Authorization = `Bearer ${this.token}`;
|
|
13
|
+
if (hasBody) h["Content-Type"] = "application/json";
|
|
14
|
+
return h;
|
|
15
|
+
}
|
|
16
|
+
async get(path) {
|
|
17
|
+
const url = `${this.baseUrl}${path}`;
|
|
18
|
+
httpLog.info({
|
|
19
|
+
method: "GET",
|
|
20
|
+
url
|
|
21
|
+
}, "Request");
|
|
22
|
+
const res = await fetch(url, {
|
|
23
|
+
method: "GET",
|
|
24
|
+
headers: this.headers(false)
|
|
25
|
+
});
|
|
26
|
+
httpLog.info({
|
|
27
|
+
method: "GET",
|
|
28
|
+
url,
|
|
29
|
+
status: res.status,
|
|
30
|
+
ok: res.ok
|
|
31
|
+
}, "Response");
|
|
32
|
+
return res;
|
|
33
|
+
}
|
|
34
|
+
async post(path, body) {
|
|
35
|
+
const url = `${this.baseUrl}${path}`;
|
|
36
|
+
httpLog.info({
|
|
37
|
+
method: "POST",
|
|
38
|
+
url,
|
|
39
|
+
bodyKeys: body && typeof body === "object" ? Object.keys(body) : void 0
|
|
40
|
+
}, "Request");
|
|
41
|
+
const res = await fetch(url, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: this.headers(true),
|
|
44
|
+
body: JSON.stringify(body)
|
|
45
|
+
});
|
|
46
|
+
httpLog.info({
|
|
47
|
+
method: "POST",
|
|
48
|
+
url,
|
|
49
|
+
status: res.status,
|
|
50
|
+
ok: res.ok
|
|
51
|
+
}, "Response");
|
|
52
|
+
return res;
|
|
53
|
+
}
|
|
54
|
+
async put(path, body) {
|
|
55
|
+
const url = `${this.baseUrl}${path}`;
|
|
56
|
+
httpLog.info({
|
|
57
|
+
method: "PUT",
|
|
58
|
+
url,
|
|
59
|
+
bodyKeys: body && typeof body === "object" ? Object.keys(body) : void 0
|
|
60
|
+
}, "Request");
|
|
61
|
+
const res = await fetch(url, {
|
|
62
|
+
method: "PUT",
|
|
63
|
+
headers: this.headers(true),
|
|
64
|
+
body: JSON.stringify(body)
|
|
65
|
+
});
|
|
66
|
+
httpLog.info({
|
|
67
|
+
method: "PUT",
|
|
68
|
+
url,
|
|
69
|
+
status: res.status,
|
|
70
|
+
ok: res.ok
|
|
71
|
+
}, "Response");
|
|
72
|
+
return res;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Factory: reads config and returns an ApiClient instance.
|
|
77
|
+
*/
|
|
78
|
+
function createApiClient(configDir) {
|
|
79
|
+
return new ApiClient(getConfig(configDir));
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { ApiClient, VERSION, createApiClient, getConfig, getConfigDir, getConfigPath, logger, setConfig };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/lib/api-client.ts"],"sourcesContent":["import { USER_AGENT } from '~/version.js';\n\nimport { getConfig, type TankConfig } from './config.js';\nimport { httpLog } from './debug-logger.js';\n\nexport class ApiClient {\n private baseUrl: string;\n private token?: string;\n\n constructor(config: TankConfig) {\n this.baseUrl = config.registry;\n this.token = config.token;\n }\n\n private headers(hasBody: boolean): Record<string, string> {\n const h: Record<string, string> = {\n 'User-Agent': USER_AGENT\n };\n\n if (this.token) {\n h.Authorization = `Bearer ${this.token}`;\n }\n\n if (hasBody) {\n h['Content-Type'] = 'application/json';\n }\n\n return h;\n }\n\n async get(path: string): Promise<Response> {\n const url = `${this.baseUrl}${path}`;\n httpLog.info({ method: 'GET', url }, 'Request');\n const res = await fetch(url, {\n method: 'GET',\n headers: this.headers(false)\n });\n httpLog.info({ method: 'GET', url, status: res.status, ok: res.ok }, 'Response');\n return res;\n }\n\n async post(path: string, body: unknown): Promise<Response> {\n const url = `${this.baseUrl}${path}`;\n httpLog.info(\n { method: 'POST', url, bodyKeys: body && typeof body === 'object' ? Object.keys(body) : undefined },\n 'Request'\n );\n const res = await fetch(url, {\n method: 'POST',\n headers: this.headers(true),\n body: JSON.stringify(body)\n });\n httpLog.info({ method: 'POST', url, status: res.status, ok: res.ok }, 'Response');\n return res;\n }\n\n async put(path: string, body: unknown): Promise<Response> {\n const url = `${this.baseUrl}${path}`;\n httpLog.info(\n { method: 'PUT', url, bodyKeys: body && typeof body === 'object' ? Object.keys(body) : undefined },\n 'Request'\n );\n const res = await fetch(url, {\n method: 'PUT',\n headers: this.headers(true),\n body: JSON.stringify(body)\n });\n httpLog.info({ method: 'PUT', url, status: res.status, ok: res.ok }, 'Response');\n return res;\n }\n}\n\n/**\n * Factory: reads config and returns an ApiClient instance.\n */\nexport function createApiClient(configDir?: string): ApiClient {\n const config = getConfig(configDir);\n return new ApiClient(config);\n}\n"],"mappings":";;AAKA,IAAa,YAAb,MAAuB;CACrB;CACA;CAEA,YAAY,QAAoB;AAC9B,OAAK,UAAU,OAAO;AACtB,OAAK,QAAQ,OAAO;;CAGtB,QAAgB,SAA0C;EACxD,MAAM,IAA4B,EAChC,cAAc,YACf;AAED,MAAI,KAAK,MACP,GAAE,gBAAgB,UAAU,KAAK;AAGnC,MAAI,QACF,GAAE,kBAAkB;AAGtB,SAAO;;CAGT,MAAM,IAAI,MAAiC;EACzC,MAAM,MAAM,GAAG,KAAK,UAAU;AAC9B,UAAQ,KAAK;GAAE,QAAQ;GAAO;GAAK,EAAE,UAAU;EAC/C,MAAM,MAAM,MAAM,MAAM,KA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ent skills",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"tank": "dist/bin/tank.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsdown",
|
|
17
|
+
"build:bundle": "esbuild dist/bin/tank.js --bundle --platform=node --format=esm --outfile=build/tank-bundle.mjs --external:fsevents",
|
|
18
|
+
"build:sea": "bash scripts/build-binary.sh",
|
|
19
|
+
"build:binary": "bun run build && bun run build:bundle && bun run build:sea",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"lint": "biome check .",
|
|
23
|
+
"lint:fix": "biome check --write ."
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@internals/helpers": "workspace:*",
|
|
27
|
+
"@internals/schemas": "workspace:*",
|
|
28
|
+
"@tankpkg/sdk": "workspace:*",
|
|
29
|
+
"@tankpkg/vault": "workspace:*",
|
|
30
|
+
"@types/node": "^25.5.0",
|
|
31
|
+
"@types/tar": "^7.0.87",
|
|
32
|
+
"esbuild": "^0.27.4",
|
|
33
|
+
"tsdown": "^0.21.3",
|
|
34
|
+
"vitest": "^4.1.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@inquirer/prompts": "^8.3.0",
|
|
38
|
+
"chalk": "^5.6.2",
|
|
39
|
+
"commander": "^14.0.3",
|
|
40
|
+
"ignore": "^7.0.5",
|
|
41
|
+
"open": "^11.0.0",
|
|
42
|
+
"ora": "^9.3.0",
|
|
43
|
+
"pino": "^10.3.1",
|
|
44
|
+
"pino-loki": "^3.0.0",
|
|
45
|
+
"semver": "^7.7.4",
|
|
46
|
+
"tar": "^7.5.11",
|
|
47
|
+
"zod": "^4.3.6"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tankpkg/cli",
|
|
3
|
+
"version": "0.0.0-nightly.20260401.49863f7",
|
|
4
|
+
"description": "Security-first package manager for AI agent skills",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"tank": "dist/bin/tank.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsdown",
|
|
17
|
+
"build:bundle": "esbuild dist/bin/tank.js --bundle --platform=node --format=esm --outfile=build/tank-bundle.mjs --external:fsevents",
|
|
18
|
+
"build:sea": "bash scripts/build-binary.sh",
|
|
19
|
+
"build:binary": "bun run build && bun run build:bundle && bun run build:sea",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"lint": "biome check .",
|
|
23
|
+
"lint:fix": "biome check --write ."
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@internals/helpers": "workspace:*",
|
|
27
|
+
"@internals/schemas": "workspace:*",
|
|
28
|
+
"@tankpkg/sdk": "workspace:*",
|
|
29
|
+
"@tankpkg/vault": "workspace:*",
|
|
30
|
+
"@types/node": "^25.5.0",
|
|
31
|
+
"@types/tar": "^7.0.87",
|
|
32
|
+
"esbuild": "^0.27.4",
|
|
33
|
+
"tsdown": "^0.21.3",
|
|
34
|
+
"vitest": "^4.1.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@inquirer/prompts": "^8.3.0",
|
|
38
|
+
"chalk": "^5.6.2",
|
|
39
|
+
"commander": "^14.0.3",
|
|
40
|
+
"ignore": "^7.0.5",
|
|
41
|
+
"open": "^11.0.0",
|
|
42
|
+
"ora": "^9.3.0",
|
|
43
|
+
"pino": "^10.3.1",
|
|
44
|
+
"pino-loki": "^3.0.0",
|
|
45
|
+
"semver": "^7.7.4",
|
|
46
|
+
"tar": "^7.5.11",
|
|
47
|
+
"zod": "^4.3.6"
|
|
48
|
+
}
|
|
49
|
+
}
|