@fedify/fedify 2.2.19 → 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/attachment-arrays-CalAATqD.mjs +16 -0
- package/dist/{builder-UmydCxtK.mjs → builder-4ImvtjG4.mjs} +3 -3
- package/dist/callback-0KrwzutD.d.mts +2607 -0
- package/dist/{client-CSddvgWN.d.ts → client-9DPcy_Yx.d.ts} +16 -1
- package/dist/{client-CAM_bQXx.d.cts → client-B3ruDgWg.d.cts} +16 -1
- package/dist/{client-9F_u23dc.mjs → client-XYMC0Mmk.mjs} +189 -65
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +255 -0
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/public-audience.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-tJbL_Hkw.d.cts → context-CjWuov0g.d.cts} +57 -14
- package/dist/{context-OkwEpc3-.d.ts → context-DZqI2LJD.d.ts} +57 -14
- package/dist/{deno-CD-8UlUi.mjs → deno-AWk3S2Ug.mjs} +1 -1
- package/dist/docloader-Bogpjg4d.mjs +125 -0
- package/dist/federation/attachment-responses.test.d.mts +2 -0
- package/dist/federation/attachment-responses.test.mjs +182 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +2 -2
- package/dist/federation/middleware.test.mjs +1567 -30
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +723 -68
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-BBBUbwKh.mjs → http-B3wCvgu8.mjs} +199 -99
- package/dist/{http-DrUG4fPS.cjs → http-BNaPJVnF.cjs} +178 -107
- package/dist/{http-DJK2udgX.js → http-BpdLaGy8.js} +177 -106
- package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
- package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
- package/dist/{inbox-Dca_0fwc.mjs → inbox-DLy6WBXU.mjs} +1 -1
- package/dist/{key-DolXUaLH.mjs → key-Bhc8cQC7.mjs} +3 -2
- package/dist/{kv-cache-Bk3V1Tiu.cjs → kv-cache-Bj3CY9Jo.cjs} +59 -17
- package/dist/{kv-cache-DDm80t1K.js → kv-cache-CvjLUQTf.js} +60 -18
- package/dist/{ld-rTdIfZ63.mjs → ld-DTeykI0e.mjs} +153 -21
- package/dist/ld-signature-Dgz_b89j.mjs +23 -0
- package/dist/{middleware-BWOwEGpy.cjs → middleware-BSQP4d9p.cjs} +642 -149
- package/dist/{middleware-B4-Rzdi3.cjs → middleware-CWOzxb3o.cjs} +1 -1
- package/dist/{middleware-DYK_res8.mjs → middleware-DkMsC5mQ.mjs} +1 -1
- package/dist/{middleware-BimXKBcP.js → middleware-Dx1iwFk8.js} +641 -149
- package/dist/{middleware-CpXoRHs3.mjs → middleware-dlGvSrXl.mjs} +452 -122
- package/dist/{mod-D2JyWtW3.d.cts → mod-BmxqcEnU.d.ts} +30 -13
- package/dist/{mod-a6kmB8xD.d.cts → mod-DWEx2D4q.d.cts} +1 -1
- package/dist/{mod-DQGjRJUG.d.ts → mod-DnPmz3-S.d.ts} +1 -1
- package/dist/{mod-ej_rLx8h.d.ts → mod-INjDw-m0.d.cts} +30 -13
- package/dist/{mod-B6LmugJ4.d.ts → mod-REfljt0T.d.ts} +4 -10
- package/dist/{mod-V2vDnYNu.d.cts → mod-UvIGUHqW.d.cts} +4 -10
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +764 -18
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +292 -30
- package/dist/otel/mod.cjs +36 -30
- package/dist/otel/mod.d.cts +13 -0
- package/dist/otel/mod.d.ts +13 -0
- package/dist/otel/mod.js +36 -30
- package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
- package/dist/{owner-CVfzyM5V.mjs → owner-BsA7qMHB.mjs} +2 -2
- package/dist/{proof-gOGM-sJS.mjs → proof-C63Hqt9N.mjs} +40 -15
- package/dist/{proof-DhaTTn-P.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
- package/dist/{proof-CaQ4KG6y.js → proof-QV_o5ZqS.js} +1174 -1003
- package/dist/send-CAdpwbFX.mjs +416 -0
- package/dist/sig/http.test.mjs +528 -2
- package/dist/sig/key-types.test.d.mts +218 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +573 -8
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +96 -4
- package/dist/{temporal-CA4Y9hBJ.mjs → temporal-B3JGkVgk.mjs} +3 -5
- package/dist/testing/mod.d.mts +1 -2396
- package/dist/{types-DRPjmHVV.cjs → types-BWx7zw3Y.cjs} +187 -63
- package/dist/{types-miAYfiGO.js → types-Dx_w2JSM.js} +188 -64
- package/dist/utils/docloader.test.mjs +318 -34
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +6 -6
- package/dist/docloader-D1ghurDJ.mjs +0 -83
- package/dist/send-D35Va72B.mjs +0 -260
- /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
- /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
- /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
- /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
- /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
- /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
3
|
import { getLogger } from "@logtape/logtape";
|
|
4
|
-
import { FetchError, UrlError, getUserAgent
|
|
4
|
+
import { FetchError, UrlError, getUserAgent } from "@fedify/vocab-runtime";
|
|
5
|
+
import { detectRuntime, lookupAllAddressesBounded, openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
5
6
|
//#region src/utils/body.ts
|
|
6
7
|
/** Decoded JSON body limit: 16 MiB. @internal */
|
|
7
8
|
const MAX_BODY_SIZE = 16 * 1024 * 1024;
|
|
@@ -23,13 +24,18 @@ function validateBodySizeLimit(maxBytes) {
|
|
|
23
24
|
* @param message The response or request to read.
|
|
24
25
|
* @param maxBytes The maximum number of decoded bytes to read.
|
|
25
26
|
* @param url The URL to include in errors and logs.
|
|
27
|
+
* @param signal An optional signal for cancelling the body read.
|
|
26
28
|
* @returns The decoded body text.
|
|
27
29
|
* @throws {BodyTooLargeError} If the body exceeds the limit.
|
|
28
30
|
* @internal
|
|
29
31
|
*/
|
|
30
|
-
async function readBoundedText(message, maxBytes, url) {
|
|
32
|
+
async function readBoundedText(message, maxBytes, url, signal) {
|
|
31
33
|
validateBodySizeLimit(maxBytes);
|
|
32
34
|
const reader = message.body?.getReader();
|
|
35
|
+
const onAbort = () => {
|
|
36
|
+
if (reader != null) reader.cancel(signal?.reason).catch(() => {});
|
|
37
|
+
};
|
|
38
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
33
39
|
const tooLarge = () => {
|
|
34
40
|
getLogger([
|
|
35
41
|
"fedify",
|
|
@@ -42,6 +48,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
42
48
|
throw new BodyTooLargeError(url, maxBytes);
|
|
43
49
|
};
|
|
44
50
|
try {
|
|
51
|
+
signal?.throwIfAborted();
|
|
45
52
|
const length = message.headers.get("Content-Length");
|
|
46
53
|
const encoding = message.headers.get("Content-Encoding");
|
|
47
54
|
if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
|
|
@@ -49,6 +56,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
49
56
|
let size = 0;
|
|
50
57
|
const textReader = new ReadableStream({ async pull(controller) {
|
|
51
58
|
const { done, value } = await reader.read();
|
|
59
|
+
signal?.throwIfAborted();
|
|
52
60
|
if (done) {
|
|
53
61
|
controller.close();
|
|
54
62
|
return;
|
|
@@ -61,6 +69,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
61
69
|
const chunks = [];
|
|
62
70
|
while (true) {
|
|
63
71
|
const { done, value } = await textReader.read();
|
|
72
|
+
signal?.throwIfAborted();
|
|
64
73
|
if (done) break;
|
|
65
74
|
chunks.push(value);
|
|
66
75
|
}
|
|
@@ -72,6 +81,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
72
81
|
if (reader != null) reader.cancel(error).catch(() => {});
|
|
73
82
|
throw error;
|
|
74
83
|
} finally {
|
|
84
|
+
signal?.removeEventListener("abort", onAbort);
|
|
75
85
|
reader?.releaseLock();
|
|
76
86
|
}
|
|
77
87
|
}
|
|
@@ -83,25 +93,45 @@ const logger = getLogger([
|
|
|
83
93
|
"client"
|
|
84
94
|
]);
|
|
85
95
|
const DEFAULT_MAX_REDIRECTION = 5;
|
|
96
|
+
const DEFAULT_TIMEOUT = 1e4;
|
|
97
|
+
const MAX_TIMEOUT = 2147483647;
|
|
86
98
|
/**
|
|
87
|
-
* Fetches a URL while guarding against SSRF.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* bounce the request to an internal
|
|
99
|
+
* Fetches a URL while guarding against SSRF. Every request—including each
|
|
100
|
+
* redirect hop—is made in its own session opened with `openPublicFetch()`,
|
|
101
|
+
* which rejects loopback, link-local, and private addresses, as well as
|
|
102
|
+
* non-HTTP(S) schemes such as `data:`, and connects only to the validated
|
|
103
|
+
* addresses where the runtime supports it. Redirects are followed manually
|
|
104
|
+
* with a cap, so that a public URL cannot bounce the request to an internal
|
|
105
|
+
* address.
|
|
106
|
+
*
|
|
107
|
+
* The final response is passed to `consume`, which must consume or cancel its
|
|
108
|
+
* body; the session is closed after `consume` settles. The cancellation of
|
|
109
|
+
* redirect response bodies is started before their sessions are closed.
|
|
93
110
|
* @param url The URL to fetch.
|
|
94
111
|
* @param headers The request headers.
|
|
95
|
-
* @
|
|
96
|
-
*
|
|
112
|
+
* @param consume The function to consume the final response with.
|
|
113
|
+
* @param deps The dependencies.
|
|
114
|
+
* @param signal The signal for the whole NodeInfo lookup.
|
|
115
|
+
* @returns The value returned by `consume`, or `null` if the URL is
|
|
116
|
+
* disallowed, its hostname cannot be resolved, or there are too many
|
|
117
|
+
* redirects.
|
|
118
|
+
* @internal
|
|
97
119
|
*/
|
|
98
|
-
async function fetchPublicUrl(url, headers) {
|
|
120
|
+
async function fetchPublicUrl(url, headers, consume, deps = {}, signal) {
|
|
121
|
+
const openHop = deps.openHop ?? ((hopUrl, signal) => openPublicFetch(hopUrl, detectRuntime() === "node" ? {
|
|
122
|
+
signal,
|
|
123
|
+
lookup: (hostname) => lookupAllAddressesBounded(hostname, signal)
|
|
124
|
+
} : { signal }));
|
|
99
125
|
let current = url instanceof URL ? url : new URL(url);
|
|
100
126
|
let redirected = 0;
|
|
127
|
+
const visited = new Set([redirectKey(current)]);
|
|
101
128
|
while (true) {
|
|
129
|
+
signal?.throwIfAborted();
|
|
130
|
+
let session;
|
|
102
131
|
try {
|
|
103
|
-
await
|
|
132
|
+
session = await openHop(current.href, signal);
|
|
104
133
|
} catch (e) {
|
|
134
|
+
signal?.throwIfAborted();
|
|
105
135
|
if (e instanceof UrlError) {
|
|
106
136
|
if (e.reason === "dns") logger.error("DNS lookup failed for {url}: {error}", {
|
|
107
137
|
url: current.href,
|
|
@@ -115,52 +145,146 @@ async function fetchPublicUrl(url, headers) {
|
|
|
115
145
|
}
|
|
116
146
|
throw e;
|
|
117
147
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
const next = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? current : response.url);
|
|
132
|
-
if (next.protocol !== current.protocol) {
|
|
133
|
-
logger.error("Refused a redirect to a different protocol ({protocol} to {redirectedProtocol}) while fetching NodeInfo.", {
|
|
134
|
-
protocol: current.protocol,
|
|
135
|
-
redirectedProtocol: next.protocol
|
|
136
|
-
});
|
|
137
|
-
return null;
|
|
148
|
+
let location;
|
|
149
|
+
try {
|
|
150
|
+
signal?.throwIfAborted();
|
|
151
|
+
const response = await session.fetch(current, {
|
|
152
|
+
headers,
|
|
153
|
+
redirect: "manual",
|
|
154
|
+
signal
|
|
155
|
+
});
|
|
156
|
+
if (signal?.aborted) {
|
|
157
|
+
cancelBody(response, current);
|
|
158
|
+
signal.throwIfAborted();
|
|
138
159
|
}
|
|
139
|
-
|
|
140
|
-
|
|
160
|
+
if (response.status < 300 || response.status >= 400 || !response.headers.has("Location")) return await consume(response);
|
|
161
|
+
location = response.headers.get("Location");
|
|
162
|
+
cancelBody(response, current);
|
|
163
|
+
} finally {
|
|
164
|
+
await session.close();
|
|
165
|
+
}
|
|
166
|
+
redirected++;
|
|
167
|
+
if (redirected >= DEFAULT_MAX_REDIRECTION) {
|
|
168
|
+
logger.error("Too many redirections ({redirections}) while fetching {url}.", {
|
|
169
|
+
redirections: redirected,
|
|
170
|
+
url: current.href
|
|
171
|
+
});
|
|
172
|
+
return null;
|
|
141
173
|
}
|
|
142
|
-
|
|
174
|
+
const next = new URL(location, current);
|
|
175
|
+
if (next.protocol !== current.protocol) {
|
|
176
|
+
logger.error("Refused a redirect to a different protocol ({protocol} to {redirectedProtocol}) while fetching NodeInfo.", {
|
|
177
|
+
protocol: current.protocol,
|
|
178
|
+
redirectedProtocol: next.protocol
|
|
179
|
+
});
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const key = redirectKey(next);
|
|
183
|
+
if (visited.has(key)) {
|
|
184
|
+
logger.error("Redirect cycle while fetching NodeInfo: {url}.", { url: next.href });
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
visited.add(key);
|
|
188
|
+
current = next;
|
|
143
189
|
}
|
|
144
190
|
}
|
|
191
|
+
function redirectKey(url) {
|
|
192
|
+
const withoutFragment = new URL(url);
|
|
193
|
+
withoutFragment.hash = "";
|
|
194
|
+
return withoutFragment.href;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Starts cancelling a response body that is not read, without waiting for it
|
|
198
|
+
* to settle. The cancellation of a branch of a tee (e.g., a body cloned by
|
|
199
|
+
* a fetch mock) settles only after the other branch is cancelled too, per
|
|
200
|
+
* the Streams standard, so awaiting it could block forever. A failure is
|
|
201
|
+
* only logged.
|
|
202
|
+
*/
|
|
203
|
+
function cancelBody(response, url) {
|
|
204
|
+
response.body?.cancel().catch((error) => {
|
|
205
|
+
logger.debug("Failed to cancel the response body from {url}: {error}", {
|
|
206
|
+
url: url.toString(),
|
|
207
|
+
error
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
145
211
|
async function getNodeInfo(url, options = {}) {
|
|
212
|
+
return await getNodeInfoInternal(url, options);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The implementation of {@link getNodeInfo}, which is not exported from any
|
|
216
|
+
* entry point.
|
|
217
|
+
* @param url The base URL of the server, or the URL of the NodeInfo document
|
|
218
|
+
* if `options.direct` is turned on.
|
|
219
|
+
* @param options Options for fetching the NodeInfo document.
|
|
220
|
+
* @param deps The dependencies.
|
|
221
|
+
* @returns The NodeInfo document if it could be fetched successfully.
|
|
222
|
+
* Otherwise, `undefined` is returned.
|
|
223
|
+
* @internal
|
|
224
|
+
*/
|
|
225
|
+
async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
226
|
+
const timeout = resolveTimeout(options.timeout);
|
|
227
|
+
if (timeout == null && options.signal == null) return await getNodeInfoWithSignal(url, options, deps);
|
|
228
|
+
const controller = new AbortController();
|
|
229
|
+
const timeoutReason = timeout == null ? void 0 : new DOMException(`The NodeInfo lookup timed out after ${timeout} ms.`, "TimeoutError");
|
|
230
|
+
const timer = timeout == null ? void 0 : setTimeout(() => controller.abort(timeoutReason), timeout);
|
|
231
|
+
const onCallerAbort = () => controller.abort(options.signal?.reason);
|
|
232
|
+
options.signal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
233
|
+
if (options.signal?.aborted) onCallerAbort();
|
|
234
|
+
let onAbort;
|
|
235
|
+
const aborted = new Promise((_, reject) => {
|
|
236
|
+
onAbort = () => reject(controller.signal.reason);
|
|
237
|
+
controller.signal.addEventListener("abort", onAbort, { once: true });
|
|
238
|
+
});
|
|
239
|
+
const loading = getNodeInfoWithSignal(url, options, deps, controller.signal);
|
|
240
|
+
loading.catch(() => {});
|
|
146
241
|
try {
|
|
242
|
+
return await Promise.race([loading, aborted]);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (!controller.signal.aborted) throw error;
|
|
245
|
+
if (controller.signal.reason === timeoutReason) logger.error("Timed out after {timeout} ms while fetching NodeInfo: {url}", {
|
|
246
|
+
timeout,
|
|
247
|
+
url: url.toString()
|
|
248
|
+
});
|
|
249
|
+
else logger.debug("Cancelled NodeInfo lookup for {url}.", { url: url.toString() });
|
|
250
|
+
return;
|
|
251
|
+
} finally {
|
|
252
|
+
clearTimeout(timer);
|
|
253
|
+
options.signal?.removeEventListener("abort", onCallerAbort);
|
|
254
|
+
if (onAbort != null) controller.signal.removeEventListener("abort", onAbort);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function resolveTimeout(timeout) {
|
|
258
|
+
if (timeout === void 0) return DEFAULT_TIMEOUT;
|
|
259
|
+
if (timeout === null) return null;
|
|
260
|
+
if (!Number.isFinite(timeout) || timeout <= 0) throw new RangeError(`The NodeInfo timeout must be a positive finite number of milliseconds, but got ${String(timeout)}.`);
|
|
261
|
+
const ms = Math.ceil(timeout);
|
|
262
|
+
if (ms > MAX_TIMEOUT) throw new RangeError(`The NodeInfo timeout must not be greater than ${MAX_TIMEOUT} milliseconds, but got ${timeout}.`);
|
|
263
|
+
return ms;
|
|
264
|
+
}
|
|
265
|
+
async function getNodeInfoWithSignal(url, options, deps, signal) {
|
|
266
|
+
try {
|
|
267
|
+
const headers = {
|
|
268
|
+
Accept: "application/json",
|
|
269
|
+
"User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
|
|
270
|
+
};
|
|
147
271
|
let nodeInfoUrl = url;
|
|
148
272
|
if (!options.direct) {
|
|
149
273
|
const wellKnownUrl = new URL("/.well-known/nodeinfo", url);
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const wellKnownRd =
|
|
274
|
+
const wellKnown = await fetchPublicUrl(wellKnownUrl, headers, async (response) => {
|
|
275
|
+
if (!response.ok) {
|
|
276
|
+
logger.error("Failed to fetch {url}: {status} {statusText}", {
|
|
277
|
+
url: wellKnownUrl.href,
|
|
278
|
+
status: response.status,
|
|
279
|
+
statusText: response.statusText
|
|
280
|
+
});
|
|
281
|
+
cancelBody(response, wellKnownUrl);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl, signal)) };
|
|
285
|
+
}, deps, signal);
|
|
286
|
+
if (wellKnown == null) return void 0;
|
|
287
|
+
const wellKnownRd = wellKnown.rd;
|
|
164
288
|
const link = wellKnownRd?.links?.find((link) => link != null && "rel" in link && (link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.0" || link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.1") && "href" in link && link.href != null);
|
|
165
289
|
if (link == null || link.href == null) {
|
|
166
290
|
logger.error("Failed to find a NodeInfo document link from {url}: {resourceDescriptor}", {
|
|
@@ -171,24 +295,24 @@ async function getNodeInfo(url, options = {}) {
|
|
|
171
295
|
}
|
|
172
296
|
nodeInfoUrl = link.href;
|
|
173
297
|
}
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const data =
|
|
298
|
+
const document = await fetchPublicUrl(nodeInfoUrl, headers, async (response) => {
|
|
299
|
+
if (!response.ok) {
|
|
300
|
+
logger.error("Failed to fetch NodeInfo document from {url}: {status} {statusText}", {
|
|
301
|
+
url: nodeInfoUrl.toString(),
|
|
302
|
+
status: response.status,
|
|
303
|
+
statusText: response.statusText
|
|
304
|
+
});
|
|
305
|
+
cancelBody(response, nodeInfoUrl);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl, signal)) };
|
|
309
|
+
}, deps, signal);
|
|
310
|
+
if (document == null) return void 0;
|
|
311
|
+
const { data } = document;
|
|
188
312
|
if (options.parse === "none") return data;
|
|
189
313
|
return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
|
|
190
314
|
} catch (error) {
|
|
191
|
-
logger
|
|
315
|
+
logger[signal?.aborted ? "debug" : "error"]("Failed to fetch NodeInfo document from {url}: {error}", {
|
|
192
316
|
url: url.toString(),
|
|
193
317
|
error
|
|
194
318
|
});
|