@fedify/cli 2.5.0-dev.2844 → 2.5.0-dev.2860

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/config.js CHANGED
@@ -74,7 +74,8 @@ const nodeinfoSchema = object$1({
74
74
  raw: optional$1(boolean()),
75
75
  bestEffort: optional$1(boolean()),
76
76
  showFavicon: optional$1(boolean()),
77
- showMetadata: optional$1(boolean())
77
+ showMetadata: optional$1(boolean()),
78
+ timeout: optional$1(number())
78
79
  });
79
80
  /**
80
81
  * Schema for the bench command configuration.
package/dist/deno.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "temporal-polyfill";
2
2
  //#region deno.json
3
- var version = "2.5.0-dev.2844+3ed9e778";
3
+ var version = "2.5.0-dev.2860+54e6d1c2";
4
4
  //#endregion
5
5
  export { version };
package/dist/nodeinfo.js CHANGED
@@ -3,7 +3,7 @@ import { configContext } from "./config.js";
3
3
  import { userAgentOption } from "./options.js";
4
4
  import { colors, formatObject } from "./utils.js";
5
5
  import process from "node:process";
6
- import { argument, command, constant, flag, group, merge, message, object, string, text } from "@optique/core";
6
+ import { argument, command, constant, flag, float, group, merge, message, object, option, optional, string, text } from "@optique/core";
7
7
  import { print, printError } from "@optique/run";
8
8
  import os from "node:os";
9
9
  import { bindConfig } from "@optique/config";
@@ -26,6 +26,53 @@ const logger = getLogger([
26
26
  ]);
27
27
  const MAX_FAVICON_REDIRECTS = 5;
28
28
  const SVG_SNIFF_LENGTH = 1024;
29
+ const DEFAULT_NODEINFO_TIMEOUT_SECONDS = 10;
30
+ const MAX_TIMER_DELAY = 2147483647;
31
+ /**
32
+ * Uses a CLI-owned signal so a timeout can be distinguished from the other
33
+ * lookup failures that `getNodeInfo()` reports as `undefined`.
34
+ * @internal
35
+ */
36
+ async function withNodeInfoTimeout(timeoutSeconds, lookup) {
37
+ const seconds = timeoutSeconds ?? DEFAULT_NODEINFO_TIMEOUT_SECONDS;
38
+ const milliseconds = Math.ceil(seconds * 1e3);
39
+ if (!Number.isFinite(seconds) || seconds <= 0 || milliseconds > MAX_TIMER_DELAY) throw new RangeError("The NodeInfo timeout must be a positive, finite number of seconds within the timer range.");
40
+ const controller = new AbortController();
41
+ let timer;
42
+ const deadline = new Promise((resolve) => {
43
+ timer = setTimeout(() => {
44
+ resolve({ timedOut: true });
45
+ controller.abort();
46
+ }, milliseconds);
47
+ });
48
+ try {
49
+ const loading = lookup(controller.signal).then((value) => ({
50
+ timedOut: false,
51
+ value
52
+ }));
53
+ loading.catch(() => {});
54
+ const outcome = await Promise.race([loading, deadline]);
55
+ return outcome.timedOut ? {
56
+ value: void 0,
57
+ timedOut: true,
58
+ timeoutSeconds: seconds
59
+ } : {
60
+ value: outcome.value,
61
+ timedOut: false,
62
+ timeoutSeconds: seconds
63
+ };
64
+ } finally {
65
+ clearTimeout(timer);
66
+ }
67
+ }
68
+ /**
69
+ * Describes a lookup failure without treating a timeout as a missing document.
70
+ * @internal
71
+ */
72
+ function describeNodeInfoFailure(timedOut, raw, timeoutSeconds) {
73
+ if (timedOut) return `NodeInfo request timed out after ${timeoutSeconds} seconds.`;
74
+ return raw ? "No NodeInfo document found." : "No NodeInfo document found or it is invalid.";
75
+ }
29
76
  async function fetchFaviconResource(url, userAgent) {
30
77
  let current = typeof url === "string" ? new URL(url) : url;
31
78
  for (let redirects = 0;; redirects++) {
@@ -158,7 +205,14 @@ const nodeInfoOption = merge(object("Display options", {
158
205
  const nodeInfoOptions = merge(object("Arguments", {
159
206
  command: constant("nodeinfo"),
160
207
  host: argument(string({ metavar: "HOST" }), { description: message`Bare hostname or a full URL of the instance` })
161
- }), nodeInfoOption, group("Network options", userAgentOption));
208
+ }), nodeInfoOption, group("Network options", merge(userAgentOption, object({ timeout: bindConfig(optional(option("-T", "--timeout", float({
209
+ min: Number.MIN_VALUE,
210
+ metavar: "SECONDS"
211
+ }), { description: message`Set the NodeInfo lookup timeout in seconds (default: 10).` })), {
212
+ context: configContext,
213
+ key: (config) => config.nodeinfo?.timeout,
214
+ default: DEFAULT_NODEINFO_TIMEOUT_SECONDS
215
+ }) }))));
162
216
  const nodeInfoMetadata = {
163
217
  brief: message`Get information about a remote node using the NodeInfo protocol`,
164
218
  description: message`Get information about a remote node using the NodeInfo protocol.
@@ -190,28 +244,36 @@ async function runNodeInfo(command) {
190
244
  }).start();
191
245
  const url = new URL(URL.canParse(command.host) ? command.host : `https://${command.host}`);
192
246
  if (command.raw) {
193
- const nodeInfo = await getNodeInfo(url, {
247
+ const { value: nodeInfo, timedOut, timeoutSeconds } = await withNodeInfoTimeout(command.timeout, (signal) => getNodeInfo(url, {
194
248
  parse: "none",
195
- userAgent: command.userAgent
196
- });
249
+ userAgent: command.userAgent,
250
+ timeout: null,
251
+ signal
252
+ }));
197
253
  if (nodeInfo === void 0) {
198
- spinner.fail("No NodeInfo document found.");
199
- printError(message`No NodeInfo document found.`);
254
+ const failure = describeNodeInfoFailure(timedOut, true, timeoutSeconds);
255
+ spinner.fail(failure);
256
+ printError(message`${text(failure)}`);
257
+ if (timedOut) printError(message`Try increasing the timeout with -T/--timeout or check network connectivity.`);
200
258
  process.exit(1);
201
259
  }
202
260
  spinner.succeed("NodeInfo document fetched.");
203
261
  print(message`${text(formatObject(nodeInfo, void 0, true))}`);
204
262
  return;
205
263
  }
206
- const nodeInfo = await getNodeInfo(url, {
264
+ const { value: nodeInfo, timedOut, timeoutSeconds } = await withNodeInfoTimeout(command.timeout, (signal) => getNodeInfo(url, {
207
265
  parse: command.bestEffort ? "best-effort" : "strict",
208
- userAgent: command.userAgent
209
- });
266
+ userAgent: command.userAgent,
267
+ timeout: null,
268
+ signal
269
+ }));
210
270
  logger.debug("NodeInfo document: {nodeInfo}", { nodeInfo });
211
271
  if (nodeInfo == void 0) {
212
- spinner.fail("No NodeInfo document found or it is invalid.");
213
- printError(message`No NodeInfo document found or it is invalid.`);
214
- if (!command.bestEffort) printError(message`Use the -b/--best-effort option to try to parse the document anyway.`);
272
+ const failure = describeNodeInfoFailure(timedOut, false, timeoutSeconds);
273
+ spinner.fail(failure);
274
+ printError(message`${text(failure)}`);
275
+ if (timedOut) printError(message`Try increasing the timeout with -T/--timeout or check network connectivity.`);
276
+ else if (!command.bestEffort) printError(message`Use the -b/--best-effort option to try to parse the document anyway.`);
215
277
  process.exit(1);
216
278
  }
217
279
  let layout;
@@ -400,4 +462,4 @@ function getAsciiArt(image, width = DEFAULT_IMAGE_WIDTH, colorSupport, colors) {
400
462
  return art;
401
463
  }
402
464
  //#endregion
403
- export { Jimp, getAsciiArt, getFaviconUrl, nodeInfoMetadata, nodeInfoOptions, rasterizeSvg, readImage, rgbTo256Color, runNodeInfo };
465
+ export { Jimp, describeNodeInfoFailure, getAsciiArt, getFaviconUrl, nodeInfoMetadata, nodeInfoOptions, rasterizeSvg, readImage, rgbTo256Color, runNodeInfo, withNodeInfoTimeout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cli",
3
- "version": "2.5.0-dev.2844+3ed9e778",
3
+ "version": "2.5.0-dev.2860+54e6d1c2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "README.md",
@@ -103,14 +103,14 @@
103
103
  "temporal-polyfill": "^1.0.1",
104
104
  "valibot": "^1.4.0",
105
105
  "yaml": "^2.9.0",
106
- "@fedify/fedify": "2.5.0-dev.2844+3ed9e778",
107
- "@fedify/init": "2.5.0-dev.2844+3ed9e778",
108
- "@fedify/relay": "2.5.0-dev.2844+3ed9e778",
109
- "@fedify/sqlite": "2.5.0-dev.2844+3ed9e778",
110
- "@fedify/vocab": "2.5.0-dev.2844+3ed9e778",
111
- "@fedify/vocab-tools": "2.5.0-dev.2844+3ed9e778",
112
- "@fedify/vocab-runtime": "2.5.0-dev.2844+3ed9e778",
113
- "@fedify/webfinger": "2.5.0-dev.2844+3ed9e778"
106
+ "@fedify/relay": "2.5.0-dev.2860+54e6d1c2",
107
+ "@fedify/sqlite": "2.5.0-dev.2860+54e6d1c2",
108
+ "@fedify/fedify": "2.5.0-dev.2860+54e6d1c2",
109
+ "@fedify/vocab": "2.5.0-dev.2860+54e6d1c2",
110
+ "@fedify/vocab-tools": "2.5.0-dev.2860+54e6d1c2",
111
+ "@fedify/webfinger": "2.5.0-dev.2860+54e6d1c2",
112
+ "@fedify/init": "2.5.0-dev.2860+54e6d1c2",
113
+ "@fedify/vocab-runtime": "2.5.0-dev.2860+54e6d1c2"
114
114
  },
115
115
  "devDependencies": {
116
116
  "@types/bun": "^1.2.23",