@drisp/cli 0.4.4 → 0.4.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.
@@ -1,161 +0,0 @@
1
- import {
2
- isLoopbackHost
3
- } from "./chunk-4CRZXLIP.js";
4
-
5
- // src/gateway/auth.ts
6
- import crypto from "crypto";
7
- import fs from "fs";
8
- import path from "path";
9
- var TOKEN_BYTES = 32;
10
- function loadOrCreateToken(tokenPath) {
11
- try {
12
- const buf = fs.readFileSync(tokenPath);
13
- const text = buf.toString("utf-8").trim();
14
- if (text.length >= 16) return text;
15
- } catch (err) {
16
- const code = err.code;
17
- if (code !== "ENOENT") throw err;
18
- }
19
- return writeNewToken(tokenPath);
20
- }
21
- function rotateGatewayToken(tokenPath) {
22
- return writeNewToken(tokenPath);
23
- }
24
- function writeNewToken(tokenPath) {
25
- const dir = path.dirname(tokenPath);
26
- fs.mkdirSync(dir, { recursive: true, mode: 448 });
27
- const token = crypto.randomBytes(TOKEN_BYTES).toString("base64url");
28
- const tmpPath = `${tokenPath}.tmp-${process.pid}-${crypto.randomBytes(4).toString("hex")}`;
29
- fs.writeFileSync(tmpPath, token + "\n", { mode: 384 });
30
- try {
31
- fs.renameSync(tmpPath, tokenPath);
32
- } catch (err) {
33
- try {
34
- fs.unlinkSync(tmpPath);
35
- } catch {
36
- }
37
- throw err;
38
- }
39
- if (process.platform !== "win32") {
40
- fs.chmodSync(dir, 448);
41
- fs.chmodSync(tokenPath, 384);
42
- }
43
- return token;
44
- }
45
- function timingSafeTokenEqual(a, b) {
46
- const ab = Buffer.from(a, "utf-8");
47
- const bb = Buffer.from(b, "utf-8");
48
- if (ab.length !== bb.length) {
49
- const filler = Buffer.alloc(Math.max(ab.length, bb.length));
50
- crypto.timingSafeEqual(filler, filler);
51
- return false;
52
- }
53
- return crypto.timingSafeEqual(ab, bb);
54
- }
55
- function requireTokenForBind(spec, token) {
56
- if (spec.kind === "uds" || isLoopbackHost(spec.host)) return;
57
- if (!token || token.length < 16) {
58
- throw new Error(
59
- `gateway: refusing to bind ${spec.host}:${spec.port} without token configured`
60
- );
61
- }
62
- if (spec.tls) return;
63
- if (!spec.insecure) {
64
- throw new Error(
65
- `gateway: refusing to bind ${spec.host}:${spec.port} without TLS; pass --tls-cert/--tls-key, or --insecure only for trusted reverse-proxy/tunnel deployments`
66
- );
67
- }
68
- }
69
-
70
- // src/infra/config/channels.ts
71
- import fs2 from "fs";
72
- import os from "os";
73
- import path2 from "path";
74
- function channelSidecarDir(home = os.homedir()) {
75
- return path2.join(home, ".config", "athena", "channels");
76
- }
77
- function loadChannelSidecars(home = os.homedir()) {
78
- const dir = channelSidecarDir(home);
79
- const sidecars = [];
80
- const errors = [];
81
- let entries;
82
- try {
83
- entries = fs2.readdirSync(dir);
84
- } catch (err) {
85
- const code = err.code;
86
- if (code === "ENOENT") return { sidecars, errors };
87
- errors.push({
88
- path: dir,
89
- reason: `read dir failed: ${err instanceof Error ? err.message : String(err)}`
90
- });
91
- return { sidecars, errors };
92
- }
93
- for (const entry of entries) {
94
- if (!entry.endsWith(".json")) continue;
95
- const full = path2.join(dir, entry);
96
- const name = entry.slice(0, -".json".length);
97
- const result = loadOne(name, full);
98
- if (result.ok) sidecars.push(result.sidecar);
99
- else errors.push({ path: full, reason: result.reason });
100
- }
101
- return { sidecars, errors };
102
- }
103
- function loadOne(name, filePath) {
104
- let raw;
105
- try {
106
- if (process.platform !== "win32") {
107
- const stat = fs2.statSync(filePath);
108
- if ((stat.mode & 63) !== 0) {
109
- return {
110
- ok: false,
111
- reason: `file ${filePath} is too permissive (mode ${(stat.mode & 511).toString(8)}); chmod 600`
112
- };
113
- }
114
- }
115
- raw = JSON.parse(fs2.readFileSync(filePath, "utf-8"));
116
- } catch (err) {
117
- return {
118
- ok: false,
119
- reason: err instanceof Error ? err.message : String(err)
120
- };
121
- }
122
- if (typeof raw !== "object" || raw === null) {
123
- return { ok: false, reason: "config root must be an object" };
124
- }
125
- const obj = raw;
126
- const userIdsRaw = obj["allowed_user_ids"];
127
- const allowedUserIds = [];
128
- if (userIdsRaw !== void 0) {
129
- if (!Array.isArray(userIdsRaw)) {
130
- return { ok: false, reason: "allowed_user_ids must be an array" };
131
- }
132
- for (const id of userIdsRaw) {
133
- if (typeof id === "string") allowedUserIds.push(id);
134
- else if (typeof id === "number") allowedUserIds.push(String(id));
135
- else
136
- return {
137
- ok: false,
138
- reason: "allowed_user_ids entries must be string or number"
139
- };
140
- }
141
- }
142
- const options = {};
143
- for (const [key, value] of Object.entries(obj)) {
144
- if (key === "allowed_user_ids") continue;
145
- options[key] = value;
146
- }
147
- return {
148
- ok: true,
149
- sidecar: { name, path: filePath, allowedUserIds, options }
150
- };
151
- }
152
-
153
- export {
154
- loadOrCreateToken,
155
- rotateGatewayToken,
156
- timingSafeTokenEqual,
157
- requireTokenForBind,
158
- channelSidecarDir,
159
- loadChannelSidecars
160
- };
161
- //# sourceMappingURL=chunk-6TJHAUNB.js.map