@bulolo/hermes-link 0.2.2 → 0.2.6
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/cli/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
currentCliScriptPath,
|
|
9
9
|
detectRuntimeEnvironment,
|
|
10
10
|
disableAutostart,
|
|
11
|
+
discoverRouteCandidates,
|
|
11
12
|
enableAutostart,
|
|
12
13
|
ensureIdentity,
|
|
13
14
|
generateAppConnectToken,
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
saveConfig,
|
|
23
24
|
startLinkService,
|
|
24
25
|
writeJsonFile
|
|
25
|
-
} from "../chunk-
|
|
26
|
+
} from "../chunk-YARHXGP4.js";
|
|
26
27
|
|
|
27
28
|
// src/cli/index.ts
|
|
28
29
|
import { mkdir as mkdir3 } from "fs/promises";
|
|
@@ -233,28 +234,43 @@ function pairingSessionPath(sessionId, paths) {
|
|
|
233
234
|
}
|
|
234
235
|
async function runPairingPreflight(options) {
|
|
235
236
|
const token = await generateAppConnectToken(options.paths);
|
|
237
|
+
const routes = options.identity.link_id ? await discoverRouteCandidates({
|
|
238
|
+
port: options.config.port,
|
|
239
|
+
relayBaseUrl: options.config.relayBaseUrl,
|
|
240
|
+
linkId: options.identity.link_id,
|
|
241
|
+
installId: options.identity.install_id,
|
|
242
|
+
publicKeyPem: options.identity.public_key_pem,
|
|
243
|
+
configuredLanHost: options.config.lanHost
|
|
244
|
+
}).catch(() => null) : null;
|
|
236
245
|
const localApiUrl = `http://127.0.0.1:${options.config.port}`;
|
|
246
|
+
const preferredUrls = (routes?.preferredUrls ?? []).filter(
|
|
247
|
+
(u) => !u.includes("/api/v1/relay/")
|
|
248
|
+
);
|
|
249
|
+
const bestUrl = preferredUrls[0] ?? localApiUrl;
|
|
237
250
|
const sessionId = `ps_${token.token.slice(0, 16)}`;
|
|
238
251
|
const session = {
|
|
239
252
|
session_id: sessionId,
|
|
240
253
|
code: token.token,
|
|
241
254
|
link_id: options.identity.link_id ?? "",
|
|
242
255
|
display_name: "Hermes Link",
|
|
243
|
-
local_api_url:
|
|
256
|
+
local_api_url: bestUrl,
|
|
244
257
|
server_base_url: options.config.serverBaseUrl,
|
|
245
258
|
relay_base_url: options.config.relayBaseUrl,
|
|
246
|
-
preferred_urls: [localApiUrl],
|
|
259
|
+
preferred_urls: preferredUrls.length > 0 ? preferredUrls : [localApiUrl],
|
|
247
260
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
248
261
|
expires_at: token.expiresAt
|
|
249
262
|
};
|
|
250
263
|
await mkdir2(options.paths.pairingDir, { recursive: true, mode: 448 }).catch(() => void 0);
|
|
251
264
|
await writeJsonFile(pairingSessionPath(sessionId, options.paths), session);
|
|
265
|
+
const lanUrls = (routes?.lanIps ?? []).map((ip) => `http://${ip}:${options.config.port}`);
|
|
266
|
+
const publicUrls = (routes?.publicIpv4s ?? []).map((ip) => `http://${ip}:${options.config.port}`);
|
|
252
267
|
const pairingUrl = buildPairingUrl({
|
|
253
268
|
linkId: options.identity.link_id ?? "",
|
|
254
269
|
installId: options.identity.install_id,
|
|
255
270
|
connectToken: token.token,
|
|
256
271
|
port: options.config.port,
|
|
257
|
-
|
|
272
|
+
lanUrls,
|
|
273
|
+
publicUrls
|
|
258
274
|
});
|
|
259
275
|
if (options.openBrowser !== false) {
|
|
260
276
|
await openSystemBrowser(pairingUrl).catch(() => void 0);
|
|
@@ -266,11 +282,16 @@ function buildPairingUrl(params) {
|
|
|
266
282
|
link_id: params.linkId,
|
|
267
283
|
install_id: params.installId,
|
|
268
284
|
connect_token: params.connectToken,
|
|
269
|
-
port: String(params.port)
|
|
270
|
-
local_url: params.localApiUrl
|
|
285
|
+
port: String(params.port)
|
|
271
286
|
});
|
|
287
|
+
if (params.lanUrls.length > 0) qs.set("lan_urls", params.lanUrls.join(","));
|
|
288
|
+
if (params.publicUrls.length > 0) qs.set("public_urls", params.publicUrls.join(","));
|
|
272
289
|
return `hermesapp://pair?${qs.toString()}`;
|
|
273
290
|
}
|
|
291
|
+
function buildLocalPairingPageUrl(port, connectToken) {
|
|
292
|
+
const qs = new URLSearchParams({ connect_token: connectToken });
|
|
293
|
+
return `http://127.0.0.1:${port}/pair?${qs.toString()}`;
|
|
294
|
+
}
|
|
274
295
|
|
|
275
296
|
// src/cli/index.ts
|
|
276
297
|
var args = process.argv.slice(2);
|
|
@@ -426,10 +447,13 @@ async function cmdPair(paths) {
|
|
|
426
447
|
return;
|
|
427
448
|
}
|
|
428
449
|
const result = await runPairingPreflight({ identity, config, paths });
|
|
450
|
+
const localPageUrl = buildLocalPairingPageUrl(config.port, result.connectToken);
|
|
429
451
|
process.stdout.write("\n");
|
|
430
452
|
qrcode.generate(result.pairingUrl, { small: true });
|
|
431
453
|
process.stdout.write(`
|
|
432
454
|
Pairing URL: ${result.pairingUrl}
|
|
455
|
+
`);
|
|
456
|
+
process.stdout.write(`Pairing page: ${localPageUrl}
|
|
433
457
|
`);
|
|
434
458
|
process.stdout.write(`Connect token: ${result.connectToken}
|
|
435
459
|
`);
|
package/dist/http/app.js
CHANGED