@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,6 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
2
|
import { GetUserAgentOptions } from "@fedify/vocab-runtime";
|
|
3
|
-
|
|
4
3
|
//#region src/nodeinfo/types.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* The type of the result of parsing JSON.
|
|
@@ -166,6 +165,22 @@ interface GetNodeInfoOptions {
|
|
|
166
165
|
* @since 1.3.0
|
|
167
166
|
*/
|
|
168
167
|
userAgent?: GetUserAgentOptions | string;
|
|
168
|
+
/**
|
|
169
|
+
* The timeout in milliseconds for the entire NodeInfo lookup, including
|
|
170
|
+
* discovery, redirects, and reading the document. Defaults to 10 seconds.
|
|
171
|
+
* Set to `null` to disable the timeout. A timeout returns `undefined`.
|
|
172
|
+
* Fractional values are rounded up.
|
|
173
|
+
* @throws {RangeError} If the value is not a positive finite number or is
|
|
174
|
+
* greater than 2,147,483,647.
|
|
175
|
+
* @since 2.0.36
|
|
176
|
+
*/
|
|
177
|
+
timeout?: number | null;
|
|
178
|
+
/**
|
|
179
|
+
* A signal to cancel the entire NodeInfo lookup. Cancellation returns
|
|
180
|
+
* `undefined`, including when the timeout is disabled.
|
|
181
|
+
* @since 2.0.36
|
|
182
|
+
*/
|
|
183
|
+
signal?: AbortSignal;
|
|
169
184
|
}
|
|
170
185
|
/**
|
|
171
186
|
* Fetches a NodeInfo document from the given URL.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
2
|
import { GetUserAgentOptions } from "@fedify/vocab-runtime";
|
|
3
|
-
|
|
4
3
|
//#region src/nodeinfo/types.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* The type of the result of parsing JSON.
|
|
@@ -166,6 +165,22 @@ interface GetNodeInfoOptions {
|
|
|
166
165
|
* @since 1.3.0
|
|
167
166
|
*/
|
|
168
167
|
userAgent?: GetUserAgentOptions | string;
|
|
168
|
+
/**
|
|
169
|
+
* The timeout in milliseconds for the entire NodeInfo lookup, including
|
|
170
|
+
* discovery, redirects, and reading the document. Defaults to 10 seconds.
|
|
171
|
+
* Set to `null` to disable the timeout. A timeout returns `undefined`.
|
|
172
|
+
* Fractional values are rounded up.
|
|
173
|
+
* @throws {RangeError} If the value is not a positive finite number or is
|
|
174
|
+
* greater than 2,147,483,647.
|
|
175
|
+
* @since 2.0.36
|
|
176
|
+
*/
|
|
177
|
+
timeout?: number | null;
|
|
178
|
+
/**
|
|
179
|
+
* A signal to cancel the entire NodeInfo lookup. Cancellation returns
|
|
180
|
+
* `undefined`, including when the timeout is disabled.
|
|
181
|
+
* @since 2.0.36
|
|
182
|
+
*/
|
|
183
|
+
signal?: AbortSignal;
|
|
169
184
|
}
|
|
170
185
|
/**
|
|
171
186
|
* Fetches a NodeInfo document from the given URL.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
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
|
import { getLogger } from "@logtape/logtape";
|
|
6
7
|
//#region src/utils/body.ts
|
|
7
8
|
/** Decoded JSON body limit: 16 MiB. @internal */
|
|
@@ -24,13 +25,18 @@ function validateBodySizeLimit(maxBytes) {
|
|
|
24
25
|
* @param message The response or request to read.
|
|
25
26
|
* @param maxBytes The maximum number of decoded bytes to read.
|
|
26
27
|
* @param url The URL to include in errors and logs.
|
|
28
|
+
* @param signal An optional signal for cancelling the body read.
|
|
27
29
|
* @returns The decoded body text.
|
|
28
30
|
* @throws {BodyTooLargeError} If the body exceeds the limit.
|
|
29
31
|
* @internal
|
|
30
32
|
*/
|
|
31
|
-
async function readBoundedText(message, maxBytes, url) {
|
|
33
|
+
async function readBoundedText(message, maxBytes, url, signal) {
|
|
32
34
|
validateBodySizeLimit(maxBytes);
|
|
33
35
|
const reader = message.body?.getReader();
|
|
36
|
+
const onAbort = () => {
|
|
37
|
+
if (reader != null) reader.cancel(signal?.reason).catch(() => {});
|
|
38
|
+
};
|
|
39
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
34
40
|
const tooLarge = () => {
|
|
35
41
|
getLogger([
|
|
36
42
|
"fedify",
|
|
@@ -43,6 +49,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
43
49
|
throw new BodyTooLargeError(url, maxBytes);
|
|
44
50
|
};
|
|
45
51
|
try {
|
|
52
|
+
signal?.throwIfAborted();
|
|
46
53
|
const length = message.headers.get("Content-Length");
|
|
47
54
|
const encoding = message.headers.get("Content-Encoding");
|
|
48
55
|
if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
|
|
@@ -50,6 +57,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
50
57
|
let size = 0;
|
|
51
58
|
const textReader = new ReadableStream({ async pull(controller) {
|
|
52
59
|
const { done, value } = await reader.read();
|
|
60
|
+
signal?.throwIfAborted();
|
|
53
61
|
if (done) {
|
|
54
62
|
controller.close();
|
|
55
63
|
return;
|
|
@@ -62,6 +70,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
62
70
|
const chunks = [];
|
|
63
71
|
while (true) {
|
|
64
72
|
const { done, value } = await textReader.read();
|
|
73
|
+
signal?.throwIfAborted();
|
|
65
74
|
if (done) break;
|
|
66
75
|
chunks.push(value);
|
|
67
76
|
}
|
|
@@ -73,6 +82,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
73
82
|
if (reader != null) reader.cancel(error).catch(() => {});
|
|
74
83
|
throw error;
|
|
75
84
|
} finally {
|
|
85
|
+
signal?.removeEventListener("abort", onAbort);
|
|
76
86
|
reader?.releaseLock();
|
|
77
87
|
}
|
|
78
88
|
}
|
|
@@ -84,25 +94,45 @@ const logger = getLogger([
|
|
|
84
94
|
"client"
|
|
85
95
|
]);
|
|
86
96
|
const DEFAULT_MAX_REDIRECTION = 5;
|
|
97
|
+
const DEFAULT_TIMEOUT = 1e4;
|
|
98
|
+
const MAX_TIMEOUT = 2147483647;
|
|
87
99
|
/**
|
|
88
|
-
* Fetches a URL while guarding against SSRF.
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* bounce the request to an internal
|
|
100
|
+
* Fetches a URL while guarding against SSRF. Every request—including each
|
|
101
|
+
* redirect hop—is made in its own session opened with `openPublicFetch()`,
|
|
102
|
+
* which rejects loopback, link-local, and private addresses, as well as
|
|
103
|
+
* non-HTTP(S) schemes such as `data:`, and connects only to the validated
|
|
104
|
+
* addresses where the runtime supports it. Redirects are followed manually
|
|
105
|
+
* with a cap, so that a public URL cannot bounce the request to an internal
|
|
106
|
+
* address.
|
|
107
|
+
*
|
|
108
|
+
* The final response is passed to `consume`, which must consume or cancel its
|
|
109
|
+
* body; the session is closed after `consume` settles. The cancellation of
|
|
110
|
+
* redirect response bodies is started before their sessions are closed.
|
|
94
111
|
* @param url The URL to fetch.
|
|
95
112
|
* @param headers The request headers.
|
|
96
|
-
* @
|
|
97
|
-
*
|
|
113
|
+
* @param consume The function to consume the final response with.
|
|
114
|
+
* @param deps The dependencies.
|
|
115
|
+
* @param signal The signal for the whole NodeInfo lookup.
|
|
116
|
+
* @returns The value returned by `consume`, or `null` if the URL is
|
|
117
|
+
* disallowed, its hostname cannot be resolved, or there are too many
|
|
118
|
+
* redirects.
|
|
119
|
+
* @internal
|
|
98
120
|
*/
|
|
99
|
-
async function fetchPublicUrl(url, headers) {
|
|
121
|
+
async function fetchPublicUrl(url, headers, consume, deps = {}, signal) {
|
|
122
|
+
const openHop = deps.openHop ?? ((hopUrl, signal) => openPublicFetch(hopUrl, detectRuntime() === "node" ? {
|
|
123
|
+
signal,
|
|
124
|
+
lookup: (hostname) => lookupAllAddressesBounded(hostname, signal)
|
|
125
|
+
} : { signal }));
|
|
100
126
|
let current = url instanceof URL ? url : new URL(url);
|
|
101
127
|
let redirected = 0;
|
|
128
|
+
const visited = new Set([redirectKey(current)]);
|
|
102
129
|
while (true) {
|
|
130
|
+
signal?.throwIfAborted();
|
|
131
|
+
let session;
|
|
103
132
|
try {
|
|
104
|
-
await
|
|
133
|
+
session = await openHop(current.href, signal);
|
|
105
134
|
} catch (e) {
|
|
135
|
+
signal?.throwIfAborted();
|
|
106
136
|
if (e instanceof UrlError) {
|
|
107
137
|
if (e.reason === "dns") logger.error("DNS lookup failed for {url}: {error}", {
|
|
108
138
|
url: current.href,
|
|
@@ -116,52 +146,146 @@ async function fetchPublicUrl(url, headers) {
|
|
|
116
146
|
}
|
|
117
147
|
throw e;
|
|
118
148
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
const next = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? current : response.url);
|
|
133
|
-
if (next.protocol !== current.protocol) {
|
|
134
|
-
logger.error("Refused a redirect to a different protocol ({protocol} to {redirectedProtocol}) while fetching NodeInfo.", {
|
|
135
|
-
protocol: current.protocol,
|
|
136
|
-
redirectedProtocol: next.protocol
|
|
137
|
-
});
|
|
138
|
-
return null;
|
|
149
|
+
let location;
|
|
150
|
+
try {
|
|
151
|
+
signal?.throwIfAborted();
|
|
152
|
+
const response = await session.fetch(current, {
|
|
153
|
+
headers,
|
|
154
|
+
redirect: "manual",
|
|
155
|
+
signal
|
|
156
|
+
});
|
|
157
|
+
if (signal?.aborted) {
|
|
158
|
+
cancelBody(response, current);
|
|
159
|
+
signal.throwIfAborted();
|
|
139
160
|
}
|
|
140
|
-
|
|
141
|
-
|
|
161
|
+
if (response.status < 300 || response.status >= 400 || !response.headers.has("Location")) return await consume(response);
|
|
162
|
+
location = response.headers.get("Location");
|
|
163
|
+
cancelBody(response, current);
|
|
164
|
+
} finally {
|
|
165
|
+
await session.close();
|
|
166
|
+
}
|
|
167
|
+
redirected++;
|
|
168
|
+
if (redirected >= DEFAULT_MAX_REDIRECTION) {
|
|
169
|
+
logger.error("Too many redirections ({redirections}) while fetching {url}.", {
|
|
170
|
+
redirections: redirected,
|
|
171
|
+
url: current.href
|
|
172
|
+
});
|
|
173
|
+
return null;
|
|
142
174
|
}
|
|
143
|
-
|
|
175
|
+
const next = new URL(location, current);
|
|
176
|
+
if (next.protocol !== current.protocol) {
|
|
177
|
+
logger.error("Refused a redirect to a different protocol ({protocol} to {redirectedProtocol}) while fetching NodeInfo.", {
|
|
178
|
+
protocol: current.protocol,
|
|
179
|
+
redirectedProtocol: next.protocol
|
|
180
|
+
});
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
const key = redirectKey(next);
|
|
184
|
+
if (visited.has(key)) {
|
|
185
|
+
logger.error("Redirect cycle while fetching NodeInfo: {url}.", { url: next.href });
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
visited.add(key);
|
|
189
|
+
current = next;
|
|
144
190
|
}
|
|
145
191
|
}
|
|
192
|
+
function redirectKey(url) {
|
|
193
|
+
const withoutFragment = new URL(url);
|
|
194
|
+
withoutFragment.hash = "";
|
|
195
|
+
return withoutFragment.href;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Starts cancelling a response body that is not read, without waiting for it
|
|
199
|
+
* to settle. The cancellation of a branch of a tee (e.g., a body cloned by
|
|
200
|
+
* a fetch mock) settles only after the other branch is cancelled too, per
|
|
201
|
+
* the Streams standard, so awaiting it could block forever. A failure is
|
|
202
|
+
* only logged.
|
|
203
|
+
*/
|
|
204
|
+
function cancelBody(response, url) {
|
|
205
|
+
response.body?.cancel().catch((error) => {
|
|
206
|
+
logger.debug("Failed to cancel the response body from {url}: {error}", {
|
|
207
|
+
url: url.toString(),
|
|
208
|
+
error
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
146
212
|
async function getNodeInfo(url, options = {}) {
|
|
213
|
+
return await getNodeInfoInternal(url, options);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The implementation of {@link getNodeInfo}, which is not exported from any
|
|
217
|
+
* entry point.
|
|
218
|
+
* @param url The base URL of the server, or the URL of the NodeInfo document
|
|
219
|
+
* if `options.direct` is turned on.
|
|
220
|
+
* @param options Options for fetching the NodeInfo document.
|
|
221
|
+
* @param deps The dependencies.
|
|
222
|
+
* @returns The NodeInfo document if it could be fetched successfully.
|
|
223
|
+
* Otherwise, `undefined` is returned.
|
|
224
|
+
* @internal
|
|
225
|
+
*/
|
|
226
|
+
async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
227
|
+
const timeout = resolveTimeout(options.timeout);
|
|
228
|
+
if (timeout == null && options.signal == null) return await getNodeInfoWithSignal(url, options, deps);
|
|
229
|
+
const controller = new AbortController();
|
|
230
|
+
const timeoutReason = timeout == null ? void 0 : new DOMException(`The NodeInfo lookup timed out after ${timeout} ms.`, "TimeoutError");
|
|
231
|
+
const timer = timeout == null ? void 0 : setTimeout(() => controller.abort(timeoutReason), timeout);
|
|
232
|
+
const onCallerAbort = () => controller.abort(options.signal?.reason);
|
|
233
|
+
options.signal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
234
|
+
if (options.signal?.aborted) onCallerAbort();
|
|
235
|
+
let onAbort;
|
|
236
|
+
const aborted = new Promise((_, reject) => {
|
|
237
|
+
onAbort = () => reject(controller.signal.reason);
|
|
238
|
+
controller.signal.addEventListener("abort", onAbort, { once: true });
|
|
239
|
+
});
|
|
240
|
+
const loading = getNodeInfoWithSignal(url, options, deps, controller.signal);
|
|
241
|
+
loading.catch(() => {});
|
|
147
242
|
try {
|
|
243
|
+
return await Promise.race([loading, aborted]);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (!controller.signal.aborted) throw error;
|
|
246
|
+
if (controller.signal.reason === timeoutReason) logger.error("Timed out after {timeout} ms while fetching NodeInfo: {url}", {
|
|
247
|
+
timeout,
|
|
248
|
+
url: url.toString()
|
|
249
|
+
});
|
|
250
|
+
else logger.debug("Cancelled NodeInfo lookup for {url}.", { url: url.toString() });
|
|
251
|
+
return;
|
|
252
|
+
} finally {
|
|
253
|
+
clearTimeout(timer);
|
|
254
|
+
options.signal?.removeEventListener("abort", onCallerAbort);
|
|
255
|
+
if (onAbort != null) controller.signal.removeEventListener("abort", onAbort);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function resolveTimeout(timeout) {
|
|
259
|
+
if (timeout === void 0) return DEFAULT_TIMEOUT;
|
|
260
|
+
if (timeout === null) return null;
|
|
261
|
+
if (!Number.isFinite(timeout) || timeout <= 0) throw new RangeError(`The NodeInfo timeout must be a positive finite number of milliseconds, but got ${String(timeout)}.`);
|
|
262
|
+
const ms = Math.ceil(timeout);
|
|
263
|
+
if (ms > MAX_TIMEOUT) throw new RangeError(`The NodeInfo timeout must not be greater than ${MAX_TIMEOUT} milliseconds, but got ${timeout}.`);
|
|
264
|
+
return ms;
|
|
265
|
+
}
|
|
266
|
+
async function getNodeInfoWithSignal(url, options, deps, signal) {
|
|
267
|
+
try {
|
|
268
|
+
const headers = {
|
|
269
|
+
Accept: "application/json",
|
|
270
|
+
"User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
|
|
271
|
+
};
|
|
148
272
|
let nodeInfoUrl = url;
|
|
149
273
|
if (!options.direct) {
|
|
150
274
|
const wellKnownUrl = new URL("/.well-known/nodeinfo", url);
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const wellKnownRd =
|
|
275
|
+
const wellKnown = await fetchPublicUrl(wellKnownUrl, headers, async (response) => {
|
|
276
|
+
if (!response.ok) {
|
|
277
|
+
logger.error("Failed to fetch {url}: {status} {statusText}", {
|
|
278
|
+
url: wellKnownUrl.href,
|
|
279
|
+
status: response.status,
|
|
280
|
+
statusText: response.statusText
|
|
281
|
+
});
|
|
282
|
+
cancelBody(response, wellKnownUrl);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl, signal)) };
|
|
286
|
+
}, deps, signal);
|
|
287
|
+
if (wellKnown == null) return void 0;
|
|
288
|
+
const wellKnownRd = wellKnown.rd;
|
|
165
289
|
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);
|
|
166
290
|
if (link == null || link.href == null) {
|
|
167
291
|
logger.error("Failed to find a NodeInfo document link from {url}: {resourceDescriptor}", {
|
|
@@ -172,24 +296,24 @@ async function getNodeInfo(url, options = {}) {
|
|
|
172
296
|
}
|
|
173
297
|
nodeInfoUrl = link.href;
|
|
174
298
|
}
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const data =
|
|
299
|
+
const document = await fetchPublicUrl(nodeInfoUrl, headers, async (response) => {
|
|
300
|
+
if (!response.ok) {
|
|
301
|
+
logger.error("Failed to fetch NodeInfo document from {url}: {status} {statusText}", {
|
|
302
|
+
url: nodeInfoUrl.toString(),
|
|
303
|
+
status: response.status,
|
|
304
|
+
statusText: response.statusText
|
|
305
|
+
});
|
|
306
|
+
cancelBody(response, nodeInfoUrl);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl, signal)) };
|
|
310
|
+
}, deps, signal);
|
|
311
|
+
if (document == null) return void 0;
|
|
312
|
+
const { data } = document;
|
|
189
313
|
if (options.parse === "none") return data;
|
|
190
314
|
return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
|
|
191
315
|
} catch (error) {
|
|
192
|
-
logger
|
|
316
|
+
logger[signal?.aborted ? "debug" : "error"]("Failed to fetch NodeInfo document from {url}: {error}", {
|
|
193
317
|
url: url.toString(),
|
|
194
318
|
error
|
|
195
319
|
});
|
|
@@ -389,4 +513,4 @@ function parseUsage(data, options = {}) {
|
|
|
389
513
|
};
|
|
390
514
|
}
|
|
391
515
|
//#endregion
|
|
392
|
-
export {
|
|
516
|
+
export { parseOutboundService as a, parseSoftware as c, MAX_BODY_SIZE as d, readBoundedText as f, parseNodeInfo as i, parseUsage as l, getNodeInfoInternal as n, parseProtocol as o, parseInboundService as r, parseServices as s, getNodeInfo as t, BodyTooLargeError as u };
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
|
+
import "../std__assert-DNZ4Liil.mjs";
|
|
6
|
+
import { t as assertStrictEquals } from "../assert_strict_equals-Dmjbg-bA.mjs";
|
|
7
|
+
import { t as normalizeAttachmentArrays } from "../attachment-arrays-CalAATqD.mjs";
|
|
8
|
+
import { test } from "@fedify/fixture";
|
|
9
|
+
import { preloadedContexts } from "@fedify/vocab-runtime";
|
|
10
|
+
//#region src/compat/attachment-arrays.test.ts
|
|
11
|
+
const AS = "https://www.w3.org/ns/activitystreams";
|
|
12
|
+
const SEC = "https://w3id.org/security#";
|
|
13
|
+
test("attachment arrays: singleton, multiple, nested and expanded properties", async () => {
|
|
14
|
+
const document = {
|
|
15
|
+
"@context": AS,
|
|
16
|
+
type: "Collection",
|
|
17
|
+
items: [
|
|
18
|
+
{
|
|
19
|
+
type: "Note",
|
|
20
|
+
attachment: {
|
|
21
|
+
type: "Image",
|
|
22
|
+
url: "https://example.com/a"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: "Note",
|
|
27
|
+
attachment: ["https://example.com/b", "https://example.com/c"]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: "Note",
|
|
31
|
+
attachment: null
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: "Note",
|
|
35
|
+
[`${AS}#attachment`]: "https://example.com/d"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
};
|
|
39
|
+
const before = structuredClone(document);
|
|
40
|
+
const result = await normalizeAttachmentArrays(document);
|
|
41
|
+
assertEquals(result, {
|
|
42
|
+
...document,
|
|
43
|
+
items: [
|
|
44
|
+
{
|
|
45
|
+
type: "Note",
|
|
46
|
+
attachment: [document.items[0].attachment]
|
|
47
|
+
},
|
|
48
|
+
document.items[1],
|
|
49
|
+
document.items[2],
|
|
50
|
+
{
|
|
51
|
+
type: "Note",
|
|
52
|
+
[`${AS}#attachment`]: ["https://example.com/d"]
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
assertEquals(document, before);
|
|
57
|
+
assertStrictEquals(await normalizeAttachmentArrays(result), result);
|
|
58
|
+
});
|
|
59
|
+
test("attachment arrays: preserve lists, contexts and value objects", async () => {
|
|
60
|
+
for (const document of [{
|
|
61
|
+
"@context": AS,
|
|
62
|
+
attachment: { "@list": ["https://example.com/a"] }
|
|
63
|
+
}, {
|
|
64
|
+
"@context": AS,
|
|
65
|
+
content: {
|
|
66
|
+
"@value": { attachment: 1 },
|
|
67
|
+
"@type": "@json"
|
|
68
|
+
}
|
|
69
|
+
}]) assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
70
|
+
});
|
|
71
|
+
test("attachment arrays: inline and remote contexts share one loader snapshot", async () => {
|
|
72
|
+
let loads = 0;
|
|
73
|
+
const loader = (url) => {
|
|
74
|
+
loads++;
|
|
75
|
+
return Promise.resolve({
|
|
76
|
+
documentUrl: url,
|
|
77
|
+
contextUrl: null,
|
|
78
|
+
document: preloadedContexts[AS]
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
const document = {
|
|
82
|
+
"@context": "https://example.com/context",
|
|
83
|
+
attachment: "https://example.com/a"
|
|
84
|
+
};
|
|
85
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
86
|
+
assertEquals(await normalizeAttachmentArrays(document, loader), {
|
|
87
|
+
...document,
|
|
88
|
+
attachment: [document.attachment]
|
|
89
|
+
});
|
|
90
|
+
assertEquals(loads, 1);
|
|
91
|
+
const inline = {
|
|
92
|
+
"@context": [AS, {
|
|
93
|
+
schema: "http://schema.org/",
|
|
94
|
+
value: "schema:value"
|
|
95
|
+
}],
|
|
96
|
+
attachment: { type: "Image" }
|
|
97
|
+
};
|
|
98
|
+
assertEquals(await normalizeAttachmentArrays(inline), {
|
|
99
|
+
...inline,
|
|
100
|
+
attachment: [inline.attachment]
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
test("attachment arrays: JSON literals and context redefinitions remain unchanged", async () => {
|
|
104
|
+
for (const document of [
|
|
105
|
+
{
|
|
106
|
+
"@context": [AS, { attachment: {
|
|
107
|
+
"@id": `${AS}#attachment`,
|
|
108
|
+
"@type": "@json"
|
|
109
|
+
} }],
|
|
110
|
+
attachment: { type: "Image" }
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"@context": [AS, { payload: {
|
|
114
|
+
"@id": "https://example.com/payload",
|
|
115
|
+
"@type": "@json"
|
|
116
|
+
} }],
|
|
117
|
+
attachment: "https://example.com/a",
|
|
118
|
+
payload: { attachment: { proof: "literal" } }
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"@context": [AS, "https://www.w3.org/ns/cid/v1"],
|
|
122
|
+
attachment: "https://example.com/a",
|
|
123
|
+
publicKeyJwk: { attachment: { type: "Image" } }
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"@context": [
|
|
127
|
+
AS,
|
|
128
|
+
null,
|
|
129
|
+
{
|
|
130
|
+
"@vocab": "https://example.com/",
|
|
131
|
+
attachment: {
|
|
132
|
+
"@id": "https://example.com/attachment",
|
|
133
|
+
"@type": "@json"
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
attachment: { type: "Image" }
|
|
138
|
+
}
|
|
139
|
+
]) assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
140
|
+
});
|
|
141
|
+
test("attachment arrays: language and index maps retain their semantics", async () => {
|
|
142
|
+
for (const container of ["@language", "@index"]) {
|
|
143
|
+
const document = {
|
|
144
|
+
"@context": [AS, { attachment: {
|
|
145
|
+
"@id": `${AS}#attachment`,
|
|
146
|
+
"@container": container
|
|
147
|
+
} }],
|
|
148
|
+
attachment: container === "@language" ? { en: "example" } : { sample: { type: "Image" } }
|
|
149
|
+
};
|
|
150
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
test("attachment arrays: scoped contexts cannot change literal payloads", async () => {
|
|
154
|
+
const document = {
|
|
155
|
+
"@context": [AS, { Special: {
|
|
156
|
+
"@id": "https://example.com/Special",
|
|
157
|
+
"@context": { attachment: {
|
|
158
|
+
"@id": `${AS}#attachment`,
|
|
159
|
+
"@type": "@json"
|
|
160
|
+
} }
|
|
161
|
+
} }],
|
|
162
|
+
type: "Special",
|
|
163
|
+
attachment: { type: "Image" }
|
|
164
|
+
};
|
|
165
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
166
|
+
});
|
|
167
|
+
test("attachment arrays: root proofs and signed siblings are immutable", async () => {
|
|
168
|
+
const signed = Object.freeze({
|
|
169
|
+
"@context": [AS, { proof: `${SEC}proof` }],
|
|
170
|
+
attachment: "https://example.com/a",
|
|
171
|
+
proof: Object.freeze({ id: "https://example.com/proof" })
|
|
172
|
+
});
|
|
173
|
+
assertStrictEquals(await normalizeAttachmentArrays(signed), signed);
|
|
174
|
+
const document = {
|
|
175
|
+
"@context": AS,
|
|
176
|
+
type: "Collection",
|
|
177
|
+
items: [signed, {
|
|
178
|
+
type: "Note",
|
|
179
|
+
attachment: "https://example.com/b"
|
|
180
|
+
}]
|
|
181
|
+
};
|
|
182
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
183
|
+
for (const proof of [[], [{ proofValue: "one" }, { proofValue: "two" }]]) {
|
|
184
|
+
const root = {
|
|
185
|
+
"@context": [AS, { proof: `${SEC}proof` }],
|
|
186
|
+
attachment: "https://example.com/a",
|
|
187
|
+
proof
|
|
188
|
+
};
|
|
189
|
+
assertStrictEquals(await normalizeAttachmentArrays(root), root);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
test("attachment arrays: semantic proof aliases preserve the whole document", async () => {
|
|
193
|
+
for (const nested of [false, true]) {
|
|
194
|
+
const document = {
|
|
195
|
+
"@context": [AS, { seal: `${SEC}proof` }],
|
|
196
|
+
attachment: "https://example.com/a",
|
|
197
|
+
...nested ? { object: { seal: { "@id": "https://example.com/proof" } } } : { seal: { "@id": "https://example.com/proof" } }
|
|
198
|
+
};
|
|
199
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
200
|
+
}
|
|
201
|
+
const literal = {
|
|
202
|
+
"@context": AS,
|
|
203
|
+
content: `<${SEC}proof>`,
|
|
204
|
+
attachment: "https://example.com/a"
|
|
205
|
+
};
|
|
206
|
+
assertEquals(await normalizeAttachmentArrays(literal), {
|
|
207
|
+
...literal,
|
|
208
|
+
attachment: [literal.attachment]
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
test("attachment arrays: excessive depth and failing loaders preserve input", async () => {
|
|
212
|
+
let document = { attachment: "https://example.com/a" };
|
|
213
|
+
for (let i = 0; i < 70; i++) document = { object: document };
|
|
214
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
215
|
+
const custom = {
|
|
216
|
+
"@context": "https://example.com/unavailable",
|
|
217
|
+
attachment: "https://example.com/a"
|
|
218
|
+
};
|
|
219
|
+
assertStrictEquals(await normalizeAttachmentArrays(custom, () => Promise.reject(/* @__PURE__ */ new Error("unavailable"))), custom);
|
|
220
|
+
});
|
|
221
|
+
test("attachment arrays: context-coerced security-shaped JSON is ordinary data", async () => {
|
|
222
|
+
const data = { proof: { signature: "application data" } };
|
|
223
|
+
const document = {
|
|
224
|
+
"@context": [AS, { data: {
|
|
225
|
+
"@id": "https://example.com/data",
|
|
226
|
+
"@type": "@json"
|
|
227
|
+
} }],
|
|
228
|
+
attachment: "https://example.com/a",
|
|
229
|
+
data
|
|
230
|
+
};
|
|
231
|
+
assertEquals(await normalizeAttachmentArrays(document), {
|
|
232
|
+
...document,
|
|
233
|
+
attachment: [document.attachment]
|
|
234
|
+
});
|
|
235
|
+
assertEquals(document.data, data);
|
|
236
|
+
let deep = { signature: "application data" };
|
|
237
|
+
for (let i = 0; i < 70; i++) deep = { child: deep };
|
|
238
|
+
const large = {
|
|
239
|
+
...document,
|
|
240
|
+
data: deep
|
|
241
|
+
};
|
|
242
|
+
assertStrictEquals(await normalizeAttachmentArrays(large), large);
|
|
243
|
+
});
|
|
244
|
+
test("attachment arrays: root and nested semantic LD signatures block rewriting", async () => {
|
|
245
|
+
for (const nested of [false, true]) {
|
|
246
|
+
const document = {
|
|
247
|
+
"@context": [AS, { seal: `${SEC}signature` }],
|
|
248
|
+
attachment: "https://example.com/a",
|
|
249
|
+
...nested ? { object: { seal: { "@id": "https://example.com/sig" } } } : { seal: { "@id": "https://example.com/sig" } }
|
|
250
|
+
};
|
|
251
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
//#endregion
|
|
255
|
+
export {};
|
package/dist/compat/mod.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { Ot as ActivityTransformer, n as Context } from "../context-
|
|
2
|
+
import { Ot as ActivityTransformer, n as Context } from "../context-CjWuov0g.cjs";
|
|
3
3
|
import { Activity } from "@fedify/vocab";
|
|
4
4
|
|
|
5
5
|
//#region src/compat/transformers.d.ts
|
package/dist/compat/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { Ot as ActivityTransformer, n as Context } from "../context-
|
|
2
|
+
import { Ot as ActivityTransformer, n as Context } from "../context-DZqI2LJD.js";
|
|
3
3
|
import { Activity } from "@fedify/vocab";
|
|
4
4
|
|
|
5
5
|
//#region src/compat/transformers.d.ts
|