@fedify/cli 2.1.31 → 2.1.32
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 +2 -1
- package/dist/deno.js +1 -1
- package/dist/nodeinfo.js +75 -13
- package/package.json +9 -9
package/dist/config.js
CHANGED
|
@@ -71,7 +71,8 @@ const nodeinfoSchema = object$1({
|
|
|
71
71
|
raw: optional$1(boolean()),
|
|
72
72
|
bestEffort: optional$1(boolean()),
|
|
73
73
|
showFavicon: optional$1(boolean()),
|
|
74
|
-
showMetadata: optional$1(boolean())
|
|
74
|
+
showMetadata: optional$1(boolean()),
|
|
75
|
+
timeout: optional$1(number())
|
|
75
76
|
});
|
|
76
77
|
/**
|
|
77
78
|
* Config context for use with bindConfig().
|
package/dist/deno.js
CHANGED
package/dist/nodeinfo.js
CHANGED
|
@@ -2,7 +2,7 @@ import "@js-temporal/polyfill";
|
|
|
2
2
|
import { configContext } from "./config.js";
|
|
3
3
|
import { userAgentOption } from "./options.js";
|
|
4
4
|
import { colors, formatObject } from "./utils.js";
|
|
5
|
-
import { argument, command, constant, flag, group, merge, message, object, string, text } from "@optique/core";
|
|
5
|
+
import { argument, command, constant, flag, float, group, merge, message, object, option, optional, string, text } from "@optique/core";
|
|
6
6
|
import { print, printError } from "@optique/run";
|
|
7
7
|
import os from "node:os";
|
|
8
8
|
import process from "node:process";
|
|
@@ -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
|
-
|
|
94
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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.1.
|
|
3
|
+
"version": "2.1.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"README.md",
|
|
@@ -86,14 +86,14 @@
|
|
|
86
86
|
"smol-toml": "^1.6.0",
|
|
87
87
|
"srvx": "^0.8.7",
|
|
88
88
|
"valibot": "^1.2.0",
|
|
89
|
-
"@fedify/fedify": "2.1.
|
|
90
|
-
"@fedify/init": "2.1.
|
|
91
|
-
"@fedify/relay": "2.1.
|
|
92
|
-
"@fedify/sqlite": "2.1.
|
|
93
|
-
"@fedify/vocab
|
|
94
|
-
"@fedify/vocab": "2.1.
|
|
95
|
-
"@fedify/
|
|
96
|
-
"@fedify/
|
|
89
|
+
"@fedify/fedify": "2.1.32",
|
|
90
|
+
"@fedify/init": "2.1.32",
|
|
91
|
+
"@fedify/relay": "2.1.32",
|
|
92
|
+
"@fedify/sqlite": "2.1.32",
|
|
93
|
+
"@fedify/vocab": "2.1.32",
|
|
94
|
+
"@fedify/vocab-runtime": "2.1.32",
|
|
95
|
+
"@fedify/vocab-tools": "2.1.32",
|
|
96
|
+
"@fedify/webfinger": "2.1.32"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@types/bun": "^1.2.23",
|