@bulolo/hermes-link 0.1.0 → 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/LICENSE +21 -0
- package/README.md +109 -0
- package/dist/chunk-CIUWLPSN.js +3662 -0
- package/dist/cli/index.js +46 -4
- package/dist/http/app.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-C24HF73Y.js +0 -1843
package/dist/cli/index.js
CHANGED
|
@@ -10,21 +10,23 @@ import {
|
|
|
10
10
|
disableAutostart,
|
|
11
11
|
enableAutostart,
|
|
12
12
|
ensureIdentity,
|
|
13
|
-
generateAppConnectToken,
|
|
14
13
|
getAutostartStatus,
|
|
15
14
|
loadConfig,
|
|
16
15
|
loadIdentity,
|
|
17
16
|
normalizeLanHost,
|
|
17
|
+
readJsonFile,
|
|
18
18
|
readRecentGatewayLogEntries,
|
|
19
19
|
readRecentLogEntries,
|
|
20
20
|
resolveRuntimePaths,
|
|
21
21
|
saveAssignedLinkId,
|
|
22
22
|
saveConfig,
|
|
23
|
-
startLinkService
|
|
24
|
-
|
|
23
|
+
startLinkService,
|
|
24
|
+
writeJsonFile
|
|
25
|
+
} from "../chunk-CIUWLPSN.js";
|
|
25
26
|
|
|
26
27
|
// src/cli/index.ts
|
|
27
28
|
import { mkdir as mkdir2 } from "fs/promises";
|
|
29
|
+
import qrcode from "qrcode-terminal";
|
|
28
30
|
|
|
29
31
|
// src/daemon/process.ts
|
|
30
32
|
import { execFile, spawn } from "child_process";
|
|
@@ -188,6 +190,43 @@ async function runDaemonSupervisor(options) {
|
|
|
188
190
|
await cleanup();
|
|
189
191
|
}
|
|
190
192
|
|
|
193
|
+
// src/security/app-connect-token.ts
|
|
194
|
+
import crypto from "crypto";
|
|
195
|
+
import path2 from "path";
|
|
196
|
+
var TOKENS_FILE = "app-connect-tokens.json";
|
|
197
|
+
var TOKEN_EXPIRY_MS = 5 * 60 * 1e3;
|
|
198
|
+
function tokensFilePath(paths) {
|
|
199
|
+
return path2.join(paths.homeDir, TOKENS_FILE);
|
|
200
|
+
}
|
|
201
|
+
async function readTokens(paths) {
|
|
202
|
+
const raw = await readJsonFile(tokensFilePath(paths));
|
|
203
|
+
if (!Array.isArray(raw)) return [];
|
|
204
|
+
const now = /* @__PURE__ */ new Date();
|
|
205
|
+
return raw.filter(isValidToken).filter((t) => new Date(t.expiresAt) > now);
|
|
206
|
+
}
|
|
207
|
+
function isValidToken(value) {
|
|
208
|
+
if (!value || typeof value !== "object") return false;
|
|
209
|
+
const t = value;
|
|
210
|
+
return typeof t.token === "string" && typeof t.createdAt === "string" && typeof t.expiresAt === "string";
|
|
211
|
+
}
|
|
212
|
+
async function saveTokens(tokens, paths) {
|
|
213
|
+
await writeJsonFile(tokensFilePath(paths), tokens);
|
|
214
|
+
}
|
|
215
|
+
async function generateAppConnectToken(paths) {
|
|
216
|
+
const runtimePaths = paths ?? resolveRuntimePaths();
|
|
217
|
+
const now = /* @__PURE__ */ new Date();
|
|
218
|
+
const token = {
|
|
219
|
+
token: crypto.randomBytes(32).toString("base64url"),
|
|
220
|
+
createdAt: now.toISOString(),
|
|
221
|
+
usedAt: null,
|
|
222
|
+
expiresAt: new Date(now.getTime() + TOKEN_EXPIRY_MS).toISOString()
|
|
223
|
+
};
|
|
224
|
+
const tokens = await readTokens(runtimePaths);
|
|
225
|
+
tokens.push(token);
|
|
226
|
+
await saveTokens(tokens, runtimePaths);
|
|
227
|
+
return token;
|
|
228
|
+
}
|
|
229
|
+
|
|
191
230
|
// src/runtime/browser.ts
|
|
192
231
|
import { spawn as spawn2 } from "child_process";
|
|
193
232
|
async function openSystemBrowser(url) {
|
|
@@ -400,7 +439,10 @@ async function cmdPair(paths) {
|
|
|
400
439
|
return;
|
|
401
440
|
}
|
|
402
441
|
const result = await runPairingPreflight({ identity, config, paths });
|
|
403
|
-
process.stdout.write(
|
|
442
|
+
process.stdout.write("\n");
|
|
443
|
+
qrcode.generate(result.pairingUrl, { small: true });
|
|
444
|
+
process.stdout.write(`
|
|
445
|
+
Pairing URL: ${result.pairingUrl}
|
|
404
446
|
`);
|
|
405
447
|
process.stdout.write(`Connect token: ${result.connectToken}
|
|
406
448
|
`);
|
package/dist/http/app.js
CHANGED