@fedify/cli 2.2.20 → 2.2.21

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
@@ -73,7 +73,8 @@ const nodeinfoSchema = object$1({
73
73
  raw: optional$1(boolean()),
74
74
  bestEffort: optional$1(boolean()),
75
75
  showFavicon: optional$1(boolean()),
76
- showMetadata: optional$1(boolean())
76
+ showMetadata: optional$1(boolean()),
77
+ timeout: optional$1(number())
77
78
  });
78
79
  /**
79
80
  * Config context for use with bindConfig().
package/dist/deno.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "@js-temporal/polyfill";
2
2
  //#region deno.json
3
- var version = "2.2.20";
3
+ var version = "2.2.21";
4
4
  //#endregion
5
5
  export { version };
package/dist/nodeinfo.js CHANGED
@@ -4,7 +4,7 @@ import { configContext } from "./config.js";
4
4
  import { userAgentOption } from "./options.js";
5
5
  import { print, printError } from "@optique/run";
6
6
  import process from "node:process";
7
- import { argument, command, constant, flag, group, merge, message, object, string, text } from "@optique/core";
7
+ import { argument, command, constant, flag, float, group, merge, message, object, option, optional, string, text } from "@optique/core";
8
8
  import { getNodeInfo } from "@fedify/fedify";
9
9
  import { getLogger } from "@logtape/logtape";
10
10
  import ora from "ora";
@@ -22,6 +22,53 @@ const logger = getLogger([
22
22
  "nodeinfo"
23
23
  ]);
24
24
  const MAX_FAVICON_REDIRECTS = 5;
25
+ const DEFAULT_NODEINFO_TIMEOUT_SECONDS = 10;
26
+ const MAX_TIMER_DELAY = 2147483647;
27
+ /**
28
+ * Uses a CLI-owned signal so a timeout can be distinguished from the other
29
+ * lookup failures that `getNodeInfo()` reports as `undefined`.
30
+ * @internal
31
+ */
32
+ async function withNodeInfoTimeout(timeoutSeconds, lookup) {
33
+ const seconds = timeoutSeconds ?? DEFAULT_NODEINFO_TIMEOUT_SECONDS;
34
+ const milliseconds = Math.ceil(seconds * 1e3);
35
+ 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.");
36
+ const controller = new AbortController();
37
+ let timer;
38
+ const deadline = new Promise((resolve) => {
39
+ timer = setTimeout(() => {
40
+ resolve({ timedOut: true });
41
+ controller.abort();
42
+ }, milliseconds);
43
+ });
44
+ try {
45
+ const loading = lookup(controller.signal).then((value) => ({
46
+ timedOut: false,
47
+ value
48
+ }));
49
+ loading.catch(() => {});
50
+ const outcome = await Promise.race([loading, deadline]);
51
+ return outcome.timedOut ? {
52
+ value: void 0,
53
+ timedOut: true,
54
+ timeoutSeconds: seconds
55
+ } : {
56
+ value: outcome.value,
57
+ timedOut: false,
58
+ timeoutSeconds: seconds
59
+ };
60
+ } finally {
61
+ clearTimeout(timer);
62
+ }
63
+ }
64
+ /**
65
+ * Describes a lookup failure without treating a timeout as a missing document.
66
+ * @internal
67
+ */
68
+ function describeNodeInfoFailure(timedOut, raw, timeoutSeconds) {
69
+ if (timedOut) return `NodeInfo request timed out after ${timeoutSeconds} seconds.`;
70
+ return raw ? "No NodeInfo document found." : "No NodeInfo document found or it is invalid.";
71
+ }
25
72
  async function fetchFaviconResource(url, userAgent) {
26
73
  let current = typeof url === "string" ? new URL(url) : url;
27
74
  for (let redirects = 0;; redirects++) {
@@ -72,7 +119,14 @@ const nodeInfoOption = merge(object("Display options", {
72
119
  const nodeInfoCommand = command("nodeinfo", merge(object("Arguments", {
73
120
  command: constant("nodeinfo"),
74
121
  host: argument(string({ metavar: "HOST" }), { description: message`Bare hostname or a full URL of the instance` })
75
- }), nodeInfoOption, group("Network options", userAgentOption)), {
122
+ }), nodeInfoOption, group("Network options", merge(userAgentOption, object({ timeout: bindConfig(optional(option("-T", "--timeout", float({
123
+ min: Number.MIN_VALUE,
124
+ metavar: "SECONDS"
125
+ }), { description: message`Set the NodeInfo lookup timeout in seconds (default: 10).` })), {
126
+ context: configContext,
127
+ key: (config) => config.nodeinfo?.timeout,
128
+ default: DEFAULT_NODEINFO_TIMEOUT_SECONDS
129
+ }) })))), {
76
130
  brief: message`Get information about a remote node using the NodeInfo protocol`,
77
131
  description: message`Get information about a remote node using the NodeInfo protocol.
78
132
 
@@ -85,28 +139,36 @@ async function runNodeInfo(command) {
85
139
  }).start();
86
140
  const url = new URL(URL.canParse(command.host) ? command.host : `https://${command.host}`);
87
141
  if (command.raw) {
88
- const nodeInfo = await getNodeInfo(url, {
142
+ const { value: nodeInfo, timedOut, timeoutSeconds } = await withNodeInfoTimeout(command.timeout, (signal) => getNodeInfo(url, {
89
143
  parse: "none",
90
- userAgent: command.userAgent
91
- });
144
+ userAgent: command.userAgent,
145
+ timeout: null,
146
+ signal
147
+ }));
92
148
  if (nodeInfo === void 0) {
93
- spinner.fail("No NodeInfo document found.");
94
- printError(message`No NodeInfo document found.`);
149
+ const failure = describeNodeInfoFailure(timedOut, true, timeoutSeconds);
150
+ spinner.fail(failure);
151
+ printError(message`${text(failure)}`);
152
+ if (timedOut) printError(message`Try increasing the timeout with -T/--timeout or check network connectivity.`);
95
153
  process.exit(1);
96
154
  }
97
155
  spinner.succeed("NodeInfo document fetched.");
98
156
  print(message`${text(formatObject(nodeInfo, void 0, true))}`);
99
157
  return;
100
158
  }
101
- const nodeInfo = await getNodeInfo(url, {
159
+ const { value: nodeInfo, timedOut, timeoutSeconds } = await withNodeInfoTimeout(command.timeout, (signal) => getNodeInfo(url, {
102
160
  parse: command.bestEffort ? "best-effort" : "strict",
103
- userAgent: command.userAgent
104
- });
161
+ userAgent: command.userAgent,
162
+ timeout: null,
163
+ signal
164
+ }));
105
165
  logger.debug("NodeInfo document: {nodeInfo}", { nodeInfo });
106
166
  if (nodeInfo == void 0) {
107
- spinner.fail("No NodeInfo document found or it is invalid.");
108
- printError(message`No NodeInfo document found or it is invalid.`);
109
- if (!command.bestEffort) printError(message`Use the -b/--best-effort option to try to parse the document anyway.`);
167
+ const failure = describeNodeInfoFailure(timedOut, false, timeoutSeconds);
168
+ spinner.fail(failure);
169
+ printError(message`${text(failure)}`);
170
+ if (timedOut) printError(message`Try increasing the timeout with -T/--timeout or check network connectivity.`);
171
+ else if (!command.bestEffort) printError(message`Use the -b/--best-effort option to try to parse the document anyway.`);
110
172
  process.exit(1);
111
173
  }
112
174
  let layout;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cli",
3
- "version": "2.2.20",
3
+ "version": "2.2.21",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "README.md",
@@ -87,14 +87,14 @@
87
87
  "smol-toml": "^1.6.0",
88
88
  "srvx": "^0.8.7",
89
89
  "valibot": "^1.2.0",
90
- "@fedify/init": "2.2.20",
91
- "@fedify/relay": "2.2.20",
92
- "@fedify/sqlite": "2.2.20",
93
- "@fedify/vocab": "2.2.20",
94
- "@fedify/fedify": "2.2.20",
95
- "@fedify/vocab-tools": "2.2.20",
96
- "@fedify/vocab-runtime": "2.2.20",
97
- "@fedify/webfinger": "2.2.20"
90
+ "@fedify/fedify": "2.2.21",
91
+ "@fedify/init": "2.2.21",
92
+ "@fedify/relay": "2.2.21",
93
+ "@fedify/sqlite": "2.2.21",
94
+ "@fedify/vocab": "2.2.21",
95
+ "@fedify/vocab-runtime": "2.2.21",
96
+ "@fedify/vocab-tools": "2.2.21",
97
+ "@fedify/webfinger": "2.2.21"
98
98
  },
99
99
  "devDependencies": {
100
100
  "@types/bun": "^1.2.23",