@fedify/cli 2.4.6-dev.2628 → 2.4.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/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.4.6-dev.2628+2a78382f";
3
+ var version = "2.4.6";
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";
@@ -24,6 +24,53 @@ const logger = getLogger([
24
24
  "nodeinfo"
25
25
  ]);
26
26
  const MAX_FAVICON_REDIRECTS = 5;
27
+ const DEFAULT_NODEINFO_TIMEOUT_SECONDS = 10;
28
+ const MAX_TIMER_DELAY = 2147483647;
29
+ /**
30
+ * Uses a CLI-owned signal so a timeout can be distinguished from the other
31
+ * lookup failures that `getNodeInfo()` reports as `undefined`.
32
+ * @internal
33
+ */
34
+ async function withNodeInfoTimeout(timeoutSeconds, lookup) {
35
+ const seconds = timeoutSeconds ?? DEFAULT_NODEINFO_TIMEOUT_SECONDS;
36
+ const milliseconds = Math.ceil(seconds * 1e3);
37
+ 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.");
38
+ const controller = new AbortController();
39
+ let timer;
40
+ const deadline = new Promise((resolve) => {
41
+ timer = setTimeout(() => {
42
+ resolve({ timedOut: true });
43
+ controller.abort();
44
+ }, milliseconds);
45
+ });
46
+ try {
47
+ const loading = lookup(controller.signal).then((value) => ({
48
+ timedOut: false,
49
+ value
50
+ }));
51
+ loading.catch(() => {});
52
+ const outcome = await Promise.race([loading, deadline]);
53
+ return outcome.timedOut ? {
54
+ value: void 0,
55
+ timedOut: true,
56
+ timeoutSeconds: seconds
57
+ } : {
58
+ value: outcome.value,
59
+ timedOut: false,
60
+ timeoutSeconds: seconds
61
+ };
62
+ } finally {
63
+ clearTimeout(timer);
64
+ }
65
+ }
66
+ /**
67
+ * Describes a lookup failure without treating a timeout as a missing document.
68
+ * @internal
69
+ */
70
+ function describeNodeInfoFailure(timedOut, raw, timeoutSeconds) {
71
+ if (timedOut) return `NodeInfo request timed out after ${timeoutSeconds} seconds.`;
72
+ return raw ? "No NodeInfo document found." : "No NodeInfo document found or it is invalid.";
73
+ }
27
74
  async function fetchFaviconResource(url, userAgent) {
28
75
  let current = typeof url === "string" ? new URL(url) : url;
29
76
  for (let redirects = 0;; redirects++) {
@@ -111,7 +158,14 @@ const nodeInfoOption = merge(object("Display options", {
111
158
  const nodeInfoOptions = merge(object("Arguments", {
112
159
  command: constant("nodeinfo"),
113
160
  host: argument(string({ metavar: "HOST" }), { description: message`Bare hostname or a full URL of the instance` })
114
- }), nodeInfoOption, group("Network options", userAgentOption));
161
+ }), nodeInfoOption, group("Network options", merge(userAgentOption, object({ timeout: bindConfig(optional(option("-T", "--timeout", float({
162
+ min: Number.MIN_VALUE,
163
+ metavar: "SECONDS"
164
+ }), { description: message`Set the NodeInfo lookup timeout in seconds (default: 10).` })), {
165
+ context: configContext,
166
+ key: (config) => config.nodeinfo?.timeout,
167
+ default: DEFAULT_NODEINFO_TIMEOUT_SECONDS
168
+ }) }))));
115
169
  const nodeInfoMetadata = {
116
170
  brief: message`Get information about a remote node using the NodeInfo protocol`,
117
171
  description: message`Get information about a remote node using the NodeInfo protocol.
@@ -126,28 +180,36 @@ async function runNodeInfo(command) {
126
180
  }).start();
127
181
  const url = new URL(URL.canParse(command.host) ? command.host : `https://${command.host}`);
128
182
  if (command.raw) {
129
- const nodeInfo = await getNodeInfo(url, {
183
+ const { value: nodeInfo, timedOut, timeoutSeconds } = await withNodeInfoTimeout(command.timeout, (signal) => getNodeInfo(url, {
130
184
  parse: "none",
131
- userAgent: command.userAgent
132
- });
185
+ userAgent: command.userAgent,
186
+ timeout: null,
187
+ signal
188
+ }));
133
189
  if (nodeInfo === void 0) {
134
- spinner.fail("No NodeInfo document found.");
135
- printError(message`No NodeInfo document found.`);
190
+ const failure = describeNodeInfoFailure(timedOut, true, timeoutSeconds);
191
+ spinner.fail(failure);
192
+ printError(message`${text(failure)}`);
193
+ if (timedOut) printError(message`Try increasing the timeout with -T/--timeout or check network connectivity.`);
136
194
  process.exit(1);
137
195
  }
138
196
  spinner.succeed("NodeInfo document fetched.");
139
197
  print(message`${text(formatObject(nodeInfo, void 0, true))}`);
140
198
  return;
141
199
  }
142
- const nodeInfo = await getNodeInfo(url, {
200
+ const { value: nodeInfo, timedOut, timeoutSeconds } = await withNodeInfoTimeout(command.timeout, (signal) => getNodeInfo(url, {
143
201
  parse: command.bestEffort ? "best-effort" : "strict",
144
- userAgent: command.userAgent
145
- });
202
+ userAgent: command.userAgent,
203
+ timeout: null,
204
+ signal
205
+ }));
146
206
  logger.debug("NodeInfo document: {nodeInfo}", { nodeInfo });
147
207
  if (nodeInfo == void 0) {
148
- spinner.fail("No NodeInfo document found or it is invalid.");
149
- printError(message`No NodeInfo document found or it is invalid.`);
150
- if (!command.bestEffort) printError(message`Use the -b/--best-effort option to try to parse the document anyway.`);
208
+ const failure = describeNodeInfoFailure(timedOut, false, timeoutSeconds);
209
+ spinner.fail(failure);
210
+ printError(message`${text(failure)}`);
211
+ if (timedOut) printError(message`Try increasing the timeout with -T/--timeout or check network connectivity.`);
212
+ else if (!command.bestEffort) printError(message`Use the -b/--best-effort option to try to parse the document anyway.`);
151
213
  process.exit(1);
152
214
  }
153
215
  let layout;
@@ -337,4 +399,4 @@ function getAsciiArt(image, width = DEFAULT_IMAGE_WIDTH, colorSupport, colors) {
337
399
  return art;
338
400
  }
339
401
  //#endregion
340
- export { Jimp, getAsciiArt, getFaviconUrl, nodeInfoMetadata, nodeInfoOptions, readImage, rgbTo256Color, runNodeInfo };
402
+ export { Jimp, describeNodeInfoFailure, getAsciiArt, getFaviconUrl, nodeInfoMetadata, nodeInfoOptions, readImage, rgbTo256Color, runNodeInfo, withNodeInfoTimeout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cli",
3
- "version": "2.4.6-dev.2628+2a78382f",
3
+ "version": "2.4.6",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "README.md",
@@ -88,14 +88,14 @@
88
88
  "temporal-polyfill": "^1.0.1",
89
89
  "valibot": "^1.4.0",
90
90
  "yaml": "^2.9.0",
91
- "@fedify/fedify": "2.4.6-dev.2628+2a78382f",
92
- "@fedify/init": "2.4.6-dev.2628+2a78382f",
93
- "@fedify/sqlite": "2.4.6-dev.2628+2a78382f",
94
- "@fedify/relay": "2.4.6-dev.2628+2a78382f",
95
- "@fedify/vocab": "2.4.6-dev.2628+2a78382f",
96
- "@fedify/vocab-runtime": "2.4.6-dev.2628+2a78382f",
97
- "@fedify/webfinger": "2.4.6-dev.2628+2a78382f",
98
- "@fedify/vocab-tools": "2.4.6-dev.2628+2a78382f"
91
+ "@fedify/fedify": "2.4.6",
92
+ "@fedify/init": "2.4.6",
93
+ "@fedify/sqlite": "2.4.6",
94
+ "@fedify/relay": "2.4.6",
95
+ "@fedify/vocab": "2.4.6",
96
+ "@fedify/vocab-tools": "2.4.6",
97
+ "@fedify/webfinger": "2.4.6",
98
+ "@fedify/vocab-runtime": "2.4.6"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@types/bun": "^1.2.23",