@fedify/cli 2.3.16-dev.2841 → 2.3.16
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
|
@@ -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
|
* Schema for the bench command configuration.
|
package/dist/deno.js
CHANGED
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
|
-
|
|
135
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/cli",
|
|
3
|
-
"version": "2.3.16
|
|
3
|
+
"version": "2.3.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"README.md",
|
|
@@ -91,14 +91,14 @@
|
|
|
91
91
|
"srvx": "^0.8.7",
|
|
92
92
|
"valibot": "^1.4.0",
|
|
93
93
|
"yaml": "^2.9.0",
|
|
94
|
-
"@fedify/
|
|
95
|
-
"@fedify/
|
|
96
|
-
"@fedify/
|
|
97
|
-
"@fedify/
|
|
98
|
-
"@fedify/vocab": "2.3.16
|
|
99
|
-
"@fedify/
|
|
100
|
-
"@fedify/
|
|
101
|
-
"@fedify/
|
|
94
|
+
"@fedify/init": "2.3.16",
|
|
95
|
+
"@fedify/relay": "2.3.16",
|
|
96
|
+
"@fedify/vocab-runtime": "2.3.16",
|
|
97
|
+
"@fedify/vocab": "2.3.16",
|
|
98
|
+
"@fedify/vocab-tools": "2.3.16",
|
|
99
|
+
"@fedify/fedify": "2.3.16",
|
|
100
|
+
"@fedify/webfinger": "2.3.16",
|
|
101
|
+
"@fedify/sqlite": "2.3.16"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
104
|
"@types/bun": "^1.2.23",
|