@fedify/fedify 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/attachment-arrays-5yDbmjEb.mjs +16 -0
- package/dist/{builder-kj5boG2l.mjs → builder-CadJYxhX.mjs} +2 -2
- package/dist/callback-DPDs_dxC.d.mts +5280 -0
- package/dist/{client-3InDZbba.d.cts → client-DLHsPY7X.d.cts} +16 -0
- package/dist/{client-3InDZbba.d.ts → client-DLHsPY7X.d.ts} +16 -0
- package/dist/{client-5SIFzW3q.mjs → client-DU3owZBD.mjs} +86 -11
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +255 -0
- package/dist/compat/mod.cjs +1 -1
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/mod.js +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{compound-proof-BoNAYSHt.mjs → compound-proof-CbWKyg2H.mjs} +2 -2
- package/dist/{context-D0gFIgev.d.cts → context-DUwicVx-.d.cts} +31 -14
- package/dist/{context-CVOOd9pD.d.ts → context-iGMHITvS.d.ts} +31 -14
- package/dist/{deno-ksnVeCA7.mjs → deno-BKSRi6w3.mjs} +1 -1
- package/dist/{docloader-BhVNi06k.mjs → docloader-BcDiJfFl.mjs} +2 -2
- 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/compound-fanout.test.mjs +4 -4
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler-compound-proof.test.mjs +3 -3
- package/dist/federation/handler.test.mjs +206 -14
- package/dist/federation/hashlink-media.test.mjs +2 -2
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox-report.test.mjs +5 -5
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1188 -13
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +3 -3
- package/dist/federation/mod.d.ts +3 -3
- package/dist/federation/mod.js +1 -1
- package/dist/federation/outgoing-proof.test.mjs +4 -4
- package/dist/federation/portable-actor.test.mjs +3 -3
- package/dist/federation/portable-chain.test.mjs +3 -3
- package/dist/federation/portable-collection.test.mjs +4 -4
- package/dist/federation/portable-delivery.test.mjs +2 -2
- package/dist/federation/portable-gateway-keys.test.mjs +5 -5
- package/dist/federation/portable-inbox.test.mjs +4 -4
- package/dist/federation/portable-parse-uri.test.mjs +1 -1
- package/dist/federation/portable-route-activity.test.mjs +2 -2
- package/dist/federation/portable.test.mjs +3 -3
- package/dist/federation/send.test.mjs +293 -3
- package/dist/federation/tasks/enqueue.test.mjs +1 -1
- package/dist/federation/tasks/tasks.test.mjs +2 -2
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{federation-BtPz9sr3.cjs → federation-CM4nzbhO.cjs} +501 -145
- package/dist/{http-BSARoDPh.mjs → http-B6sfb5xN.mjs} +8 -6
- package/dist/{http-rH230xCD.js → http-BwgldAIk.js} +2803 -2633
- package/dist/{http-CeVcKQMZ.cjs → http-Tj9eQ_rd.cjs} +2640 -2458
- package/dist/{inbox-BdZenpZQ.mjs → inbox-B7NVkb8j.mjs} +2 -2
- package/dist/{key-VEL1QqHF.d.cts → key-CIdQA7Pc.d.cts} +5 -5
- package/dist/{key-CyCcut3h.d.ts → key-CjtBFzaE.d.ts} +5 -5
- package/dist/{kv-cache-CNfNI_95.js → kv-cache-C-5yfTw-.js} +1 -1
- package/dist/{kv-cache-Cxn7pNMx.mjs → kv-cache-CvWuigft.mjs} +1 -1
- package/dist/{kv-cache-BpGIONmd.cjs → kv-cache-Vbq0yM7W.cjs} +1 -1
- package/dist/{ld-DJZrjNuN.mjs → ld-BGnZDnia.mjs} +176 -24
- package/dist/ld-signature-D1tFSFK8.mjs +23 -0
- package/dist/{metrics-DtxsYIkN.mjs → metrics-DHUP4F1-.mjs} +1 -1
- package/dist/{middleware-DyEjt33n.mjs → middleware-CUb31OGG.mjs} +1 -1
- package/dist/{middleware-DDvck2q9.js → middleware-DX8wADUa.js} +452 -98
- package/dist/{middleware-DblGj642.mjs → middleware-mRXKHq68.mjs} +445 -176
- package/dist/{mod-B1Qt5cQQ.d.ts → mod-B6s6hA4y.d.ts} +3 -3
- package/dist/{mod-ss0wBUH1.d.cts → mod-CJf5GcVD.d.cts} +3 -3
- package/dist/{mod-makPMVMg.d.cts → mod-CSlxqNto.d.cts} +1 -1
- package/dist/{mod-CpyjFA9s.d.ts → mod-D2DiA8u5.d.cts} +29 -7
- package/dist/{mod-BTxJG7ZH.d.cts → mod-DKRf1FLm.d.ts} +29 -7
- package/dist/{mod-B5COx5Wd.d.ts → mod-Dqu6Dl1k.d.ts} +1 -1
- package/dist/mod.cjs +6 -6
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +6 -6
- package/dist/nodeinfo/client.test.mjs +432 -4
- 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/{outgoing-jsonld-4IJqPYos.mjs → outgoing-jsonld-Dsca6G_Y.mjs} +35 -4
- package/dist/{owner-2vfqhUJw.mjs → owner-DEiBiiqR.mjs} +4 -4
- package/dist/{portable-collection-Cs--KD5A.cjs → portable-collection--h11WDIi.cjs} +3 -2
- package/dist/{portable-collection-DKJwGO8S.mjs → portable-collection-D0-tInp2.mjs} +2 -2
- package/dist/{portable-collection-B7AQ_dW7.js → portable-collection-M6d5I5JQ.js} +3 -2
- package/dist/{portable-key-DXGepvtD.mjs → portable-key-CyVJpWWJ.mjs} +1 -1
- package/dist/portable-verifier-CPA86vIP.js +22 -0
- package/dist/portable-verifier-DiLU8c9T.cjs +26 -0
- package/dist/{proof-DW0FK6Cp.mjs → proof-C4pwAF2k.mjs} +31 -11
- package/dist/{send-CqsocpvF.mjs → send-ivzJCtb-.mjs} +100 -22
- package/dist/sig/compound-proof-discovery.test.mjs +1 -1
- package/dist/sig/compound-proof-producer.test.mjs +1 -1
- package/dist/sig/compound-proof-verification.test.mjs +2 -2
- package/dist/sig/compound-proof.test.mjs +3 -3
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key-types.test.d.mts +162 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +572 -7
- package/dist/sig/mitra-receive-interop.test.mjs +4 -4
- package/dist/sig/mitra-send-interop.test.mjs +3 -3
- 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/portable-collection.test.mjs +1 -1
- package/dist/sig/portable-interop.test.mjs +3 -3
- package/dist/sig/portable-key.test.mjs +5 -5
- package/dist/sig/proof.test.mjs +100 -6
- package/dist/sig/tootik-request-interop.test.mjs +4 -4
- package/dist/sig/tootik-send-interop.test.mjs +3 -3
- package/dist/sig/verification.test.mjs +3 -3
- package/dist/{temporal-Dm2E1-vs.mjs → temporal-B6OlxwK_.mjs} +3 -5
- package/dist/testing/kv.test.mjs +1 -1
- package/dist/testing/mod.d.mts +3 -5045
- package/dist/{transformers-DAtXl_Kc.js → transformers-BlJ53iKs.js} +3 -2
- package/dist/{transformers-BalCrSsr.cjs → transformers-aIK89ibB.cjs} +3 -2
- package/dist/{types-DUjZb4i6.js → types-BbCbtwZp.js} +86 -11
- package/dist/{types-hKCCjii0.cjs → types-C8gac_AD.cjs} +85 -10
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/kv-cache.test.mjs +1 -1
- 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/dist/utils/portable-verifier.test.d.mts +2 -0
- package/dist/utils/portable-verifier.test.mjs +126 -0
- package/package.json +6 -6
|
@@ -165,6 +165,22 @@ interface GetNodeInfoOptions {
|
|
|
165
165
|
* @since 1.3.0
|
|
166
166
|
*/
|
|
167
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;
|
|
168
184
|
}
|
|
169
185
|
/**
|
|
170
186
|
* Fetches a NodeInfo document from the given URL.
|
|
@@ -165,6 +165,22 @@ interface GetNodeInfoOptions {
|
|
|
165
165
|
* @since 1.3.0
|
|
166
166
|
*/
|
|
167
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;
|
|
168
184
|
}
|
|
169
185
|
/**
|
|
170
186
|
* Fetches a NodeInfo document from the given URL.
|
|
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { getLogger } from "@logtape/logtape";
|
|
5
5
|
import { FetchError, UrlError, getUserAgent } from "@fedify/vocab-runtime";
|
|
6
|
-
import { openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
6
|
+
import { detectRuntime, lookupAllAddressesBounded, openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
7
7
|
//#region src/utils/body.ts
|
|
8
8
|
/** Decoded JSON body limit: 16 MiB. @internal */
|
|
9
9
|
const MAX_BODY_SIZE = 16 * 1024 * 1024;
|
|
@@ -25,13 +25,18 @@ function validateBodySizeLimit(maxBytes) {
|
|
|
25
25
|
* @param message The response or request to read.
|
|
26
26
|
* @param maxBytes The maximum number of decoded bytes to read.
|
|
27
27
|
* @param url The URL to include in errors and logs.
|
|
28
|
+
* @param signal An optional signal for cancelling the body read.
|
|
28
29
|
* @returns The decoded body text.
|
|
29
30
|
* @throws {BodyTooLargeError} If the body exceeds the limit.
|
|
30
31
|
* @internal
|
|
31
32
|
*/
|
|
32
|
-
async function readBoundedText(message, maxBytes, url) {
|
|
33
|
+
async function readBoundedText(message, maxBytes, url, signal) {
|
|
33
34
|
validateBodySizeLimit(maxBytes);
|
|
34
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 });
|
|
35
40
|
const tooLarge = () => {
|
|
36
41
|
getLogger([
|
|
37
42
|
"fedify",
|
|
@@ -44,6 +49,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
44
49
|
throw new BodyTooLargeError(url, maxBytes);
|
|
45
50
|
};
|
|
46
51
|
try {
|
|
52
|
+
signal?.throwIfAborted();
|
|
47
53
|
const length = message.headers.get("Content-Length");
|
|
48
54
|
const encoding = message.headers.get("Content-Encoding");
|
|
49
55
|
if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
|
|
@@ -51,6 +57,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
51
57
|
let size = 0;
|
|
52
58
|
const textReader = new ReadableStream({ async pull(controller) {
|
|
53
59
|
const { done, value } = await reader.read();
|
|
60
|
+
signal?.throwIfAborted();
|
|
54
61
|
if (done) {
|
|
55
62
|
controller.close();
|
|
56
63
|
return;
|
|
@@ -63,6 +70,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
63
70
|
const chunks = [];
|
|
64
71
|
while (true) {
|
|
65
72
|
const { done, value } = await textReader.read();
|
|
73
|
+
signal?.throwIfAborted();
|
|
66
74
|
if (done) break;
|
|
67
75
|
chunks.push(value);
|
|
68
76
|
}
|
|
@@ -74,6 +82,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
74
82
|
if (reader != null) reader.cancel(error).catch(() => {});
|
|
75
83
|
throw error;
|
|
76
84
|
} finally {
|
|
85
|
+
signal?.removeEventListener("abort", onAbort);
|
|
77
86
|
reader?.releaseLock();
|
|
78
87
|
}
|
|
79
88
|
}
|
|
@@ -85,6 +94,8 @@ const logger = getLogger([
|
|
|
85
94
|
"client"
|
|
86
95
|
]);
|
|
87
96
|
const DEFAULT_MAX_REDIRECTION = 5;
|
|
97
|
+
const DEFAULT_TIMEOUT = 1e4;
|
|
98
|
+
const MAX_TIMEOUT = 2147483647;
|
|
88
99
|
/**
|
|
89
100
|
* Fetches a URL while guarding against SSRF. Every request—including each
|
|
90
101
|
* redirect hop—is made in its own session opened with `openPublicFetch()`,
|
|
@@ -101,20 +112,27 @@ const DEFAULT_MAX_REDIRECTION = 5;
|
|
|
101
112
|
* @param headers The request headers.
|
|
102
113
|
* @param consume The function to consume the final response with.
|
|
103
114
|
* @param deps The dependencies.
|
|
115
|
+
* @param signal The signal for the whole NodeInfo lookup.
|
|
104
116
|
* @returns The value returned by `consume`, or `null` if the URL is
|
|
105
117
|
* disallowed, its hostname cannot be resolved, or there are too many
|
|
106
118
|
* redirects.
|
|
107
119
|
* @internal
|
|
108
120
|
*/
|
|
109
|
-
async function fetchPublicUrl(url, headers, consume, deps = {}) {
|
|
110
|
-
const openHop = deps.openHop ?? ((hopUrl) => openPublicFetch(hopUrl)
|
|
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 }));
|
|
111
126
|
let current = url instanceof URL ? url : new URL(url);
|
|
112
127
|
let redirected = 0;
|
|
128
|
+
const visited = /* @__PURE__ */ new Set([redirectKey(current)]);
|
|
113
129
|
while (true) {
|
|
130
|
+
signal?.throwIfAborted();
|
|
114
131
|
let session;
|
|
115
132
|
try {
|
|
116
|
-
session = await openHop(current.href);
|
|
133
|
+
session = await openHop(current.href, signal);
|
|
117
134
|
} catch (e) {
|
|
135
|
+
signal?.throwIfAborted();
|
|
118
136
|
if (e instanceof UrlError) {
|
|
119
137
|
if (e.reason === "dns") logger.error("DNS lookup failed for {url}: {error}", {
|
|
120
138
|
url: current.href,
|
|
@@ -130,10 +148,16 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
|
|
|
130
148
|
}
|
|
131
149
|
let location;
|
|
132
150
|
try {
|
|
151
|
+
signal?.throwIfAborted();
|
|
133
152
|
const response = await session.fetch(current, {
|
|
134
153
|
headers,
|
|
135
|
-
redirect: "manual"
|
|
154
|
+
redirect: "manual",
|
|
155
|
+
signal
|
|
136
156
|
});
|
|
157
|
+
if (signal?.aborted) {
|
|
158
|
+
cancelBody(response, current);
|
|
159
|
+
signal.throwIfAborted();
|
|
160
|
+
}
|
|
137
161
|
if (response.status < 300 || response.status >= 400 || !response.headers.has("Location")) return await consume(response);
|
|
138
162
|
location = response.headers.get("Location");
|
|
139
163
|
cancelBody(response, current);
|
|
@@ -156,9 +180,20 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
|
|
|
156
180
|
});
|
|
157
181
|
return null;
|
|
158
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);
|
|
159
189
|
current = next;
|
|
160
190
|
}
|
|
161
191
|
}
|
|
192
|
+
function redirectKey(url) {
|
|
193
|
+
const withoutFragment = new URL(url);
|
|
194
|
+
withoutFragment.hash = "";
|
|
195
|
+
return withoutFragment.href;
|
|
196
|
+
}
|
|
162
197
|
/**
|
|
163
198
|
* Starts cancelling a response body that is not read, without waiting for it
|
|
164
199
|
* to settle. The cancellation of a branch of a tee (e.g., a body cloned by
|
|
@@ -189,6 +224,46 @@ async function getNodeInfo(url, options = {}) {
|
|
|
189
224
|
* @internal
|
|
190
225
|
*/
|
|
191
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(() => {});
|
|
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) {
|
|
192
267
|
try {
|
|
193
268
|
const headers = {
|
|
194
269
|
Accept: "application/json",
|
|
@@ -207,8 +282,8 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
|
207
282
|
cancelBody(response, wellKnownUrl);
|
|
208
283
|
return;
|
|
209
284
|
}
|
|
210
|
-
return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl)) };
|
|
211
|
-
}, deps);
|
|
285
|
+
return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl, signal)) };
|
|
286
|
+
}, deps, signal);
|
|
212
287
|
if (wellKnown == null) return void 0;
|
|
213
288
|
const wellKnownRd = wellKnown.rd;
|
|
214
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);
|
|
@@ -231,14 +306,14 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
|
231
306
|
cancelBody(response, nodeInfoUrl);
|
|
232
307
|
return;
|
|
233
308
|
}
|
|
234
|
-
return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl)) };
|
|
235
|
-
}, deps);
|
|
309
|
+
return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl, signal)) };
|
|
310
|
+
}, deps, signal);
|
|
236
311
|
if (document == null) return void 0;
|
|
237
312
|
const { data } = document;
|
|
238
313
|
if (options.parse === "none") return data;
|
|
239
314
|
return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
|
|
240
315
|
} catch (error) {
|
|
241
|
-
logger
|
|
316
|
+
logger[signal?.aborted ? "debug" : "error"]("Failed to fetch NodeInfo document from {url}: {error}", {
|
|
242
317
|
url: url.toString(),
|
|
243
318
|
error
|
|
244
319
|
});
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import "temporal-polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
|
|
5
|
+
import "../std__assert-DvMDRPes.mjs";
|
|
6
|
+
import { t as assertStrictEquals } from "../assert_strict_equals-CYvBmkpC.mjs";
|
|
7
|
+
import { t as normalizeAttachmentArrays } from "../attachment-arrays-5yDbmjEb.mjs";
|
|
8
|
+
import { preloadedContexts } from "@fedify/vocab-runtime";
|
|
9
|
+
import { test } from "@fedify/fixture";
|
|
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.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const require_transformers = require("../transformers-
|
|
3
|
+
const require_transformers = require("../transformers-aIK89ibB.cjs");
|
|
4
4
|
exports.actorDehydrator = require_transformers.actorDehydrator;
|
|
5
5
|
exports.autoIdAssigner = require_transformers.autoIdAssigner;
|
|
6
6
|
exports.getDefaultActivityTransformers = require_transformers.getDefaultActivityTransformers;
|
package/dist/compat/mod.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { en as ActivityTransformer, n as Context } from "../context-
|
|
2
|
+
import { en as ActivityTransformer, n as Context } from "../context-DUwicVx-.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 { en as ActivityTransformer, n as Context } from "../context-
|
|
2
|
+
import { en as ActivityTransformer, n as Context } from "../context-iGMHITvS.js";
|
|
3
3
|
import { Activity } from "@fedify/vocab";
|
|
4
4
|
|
|
5
5
|
//#region src/compat/transformers.d.ts
|
package/dist/compat/mod.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Temporal } from "temporal-polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import { n as autoIdAssigner, r as getDefaultActivityTransformers, t as actorDehydrator } from "../transformers-
|
|
3
|
+
import { n as autoIdAssigner, r as getDefaultActivityTransformers, t as actorDehydrator } from "../transformers-BlJ53iKs.js";
|
|
4
4
|
export { actorDehydrator, autoIdAssigner, getDefaultActivityTransformers };
|
|
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
|
|
5
5
|
import { t as assertStrictEquals } from "../assert_strict_equals-CYvBmkpC.mjs";
|
|
6
|
-
import { n as normalizeAttachmentArrays, r as normalizeOutgoingActivityJsonLd, t as isPreloadedContextAttachmentSafe } from "../outgoing-jsonld-
|
|
6
|
+
import { n as normalizeAttachmentArrays, r as normalizeOutgoingActivityJsonLd, t as isPreloadedContextAttachmentSafe } from "../outgoing-jsonld-Dsca6G_Y.mjs";
|
|
7
7
|
import { Create, Document, Note, PUBLIC_COLLECTION } from "@fedify/vocab";
|
|
8
8
|
import { mockDocumentLoader, test } from "@fedify/fixture";
|
|
9
9
|
//#region src/compat/outgoing-jsonld.test.ts
|
|
@@ -5,7 +5,7 @@ import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
|
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
|
|
6
6
|
import { t as assertInstanceOf } from "../assert_instance_of-mrXWWNY-.mjs";
|
|
7
7
|
import { t as assert } from "../assert-D1Eafmd_.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { A as autoIdAssigner, k as actorDehydrator, n as FederationImpl } from "../middleware-mRXKHq68.mjs";
|
|
9
9
|
import { Follow, Person } from "@fedify/vocab";
|
|
10
10
|
import { test } from "@fedify/fixture";
|
|
11
11
|
//#region src/compat/transformers.test.ts
|
|
@@ -3,9 +3,9 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { a as getRawCanonicalPortableId, l as isPortableId, n as getCanonicalPortableId } from "./portable-key-id-Ca30-hOa.mjs";
|
|
5
5
|
import { a as verificationObservation, t as observeAttempt } from "./verification-Dpfcw8ml.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { l as getNormalizationContextLoader } from "./ld-BGnZDnia.mjs";
|
|
7
7
|
import { n as preloadedOnlyDocumentLoader } from "./public-audience--klBIOk1.mjs";
|
|
8
|
-
import { l as verifyPortableObjectProofPolicy, n as classifyFep2277CoreType, o as verifyMapLocalProof } from "./proof-
|
|
8
|
+
import { l as verifyPortableObjectProofPolicy, n as classifyFep2277CoreType, o as verifyMapLocalProof } from "./proof-C4pwAF2k.mjs";
|
|
9
9
|
import { parseIri, preloadedContexts } from "@fedify/vocab-runtime";
|
|
10
10
|
import jsonld from "@fedify/vocab-runtime/jsonld";
|
|
11
11
|
//#region src/sig/compound-proof.ts
|