thalixtower-cli 0.6.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 +63 -0
- package/bin/atc.js +3 -0
- package/dist/client.js +125 -0
- package/dist/hook.js +440 -0
- package/dist/human.js +86 -0
- package/dist/index.js +736 -0
- package/dist/init.js +456 -0
- package/package.json +45 -0
package/dist/human.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadHuman = loadHuman;
|
|
37
|
+
exports.saveHuman = saveHuman;
|
|
38
|
+
exports.clearHuman = clearHuman;
|
|
39
|
+
exports.humanApi = humanApi;
|
|
40
|
+
exports.requireHuman = requireHuman;
|
|
41
|
+
/**
|
|
42
|
+
* Human-plane session store for `atc login` / management commands.
|
|
43
|
+
* Stores the `atcu_` CLI session token at ~/.config/atc/session.json (chmod 0600).
|
|
44
|
+
* Deliberately separate from the agent session in .atc/session.json.
|
|
45
|
+
*/
|
|
46
|
+
const fs = __importStar(require("node:fs"));
|
|
47
|
+
const os = __importStar(require("node:os"));
|
|
48
|
+
const path = __importStar(require("node:path"));
|
|
49
|
+
const client_1 = require("./client");
|
|
50
|
+
const CONFIG_DIR = path.join(os.homedir(), '.config', 'atc');
|
|
51
|
+
const SESSION_FILE = path.join(CONFIG_DIR, 'session.json');
|
|
52
|
+
function loadHuman() {
|
|
53
|
+
try {
|
|
54
|
+
const raw = fs.readFileSync(SESSION_FILE, 'utf8');
|
|
55
|
+
const s = JSON.parse(raw);
|
|
56
|
+
if (typeof s?.token === 'string' && s.token)
|
|
57
|
+
return s;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
/* missing or unreadable */
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function saveHuman(session) {
|
|
65
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
66
|
+
fs.writeFileSync(SESSION_FILE, JSON.stringify(session, null, 2), { mode: 0o600 });
|
|
67
|
+
}
|
|
68
|
+
function clearHuman() {
|
|
69
|
+
try {
|
|
70
|
+
fs.rmSync(SESSION_FILE);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
/* already gone */
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Return an api() wrapper that uses the atcu_ token from the saved human session. */
|
|
77
|
+
function humanApi(session, method, apiPath, body) {
|
|
78
|
+
return (0, client_1.api)({ api: session.api, token: session.token }, session.token, method, apiPath, body);
|
|
79
|
+
}
|
|
80
|
+
/** Fail with a friendly message if no human session exists. */
|
|
81
|
+
function requireHuman(fail) {
|
|
82
|
+
const s = loadHuman();
|
|
83
|
+
if (!s)
|
|
84
|
+
fail("not logged in — run 'atc login'");
|
|
85
|
+
return s;
|
|
86
|
+
}
|