@fedify/relay 2.4.0-dev.1528 → 2.4.0-dev.1564

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.
@@ -1,7 +1,7 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-Dx-fpm5w.js";
4
+ import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-ZE06J1U1.js";
5
5
  import { MemoryKvStore, signRequest } from "@fedify/fedify";
6
6
  import { createRelay } from "@fedify/relay";
7
7
  import { Accept, Announce, Create, Delete, Follow, Move, Note, Person, Undo, Update } from "@fedify/vocab";
@@ -1,7 +1,7 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-Dx-fpm5w.js";
4
+ import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-ZE06J1U1.js";
5
5
  import { MemoryKvStore, signRequest } from "@fedify/fedify";
6
6
  import { createRelay } from "@fedify/relay";
7
7
  import { Create, Delete, Follow, Move, Note, Person, Undo, Update } from "@fedify/vocab";
@@ -26048,6 +26048,28 @@ const preloadedContexts = {
26048
26048
  "@type": "@id"
26049
26049
  }
26050
26050
  } },
26051
+ "https://w3id.org/fep/7aa9": { "@context": {
26052
+ "FeaturedCollection": "https://w3id.org/fep/7aa9#FeaturedCollection",
26053
+ "FeaturedItem": "https://w3id.org/fep/7aa9#FeaturedItem",
26054
+ "FeatureRequest": "https://w3id.org/fep/7aa9#FeatureRequest",
26055
+ "FeatureAuthorization": "https://w3id.org/fep/7aa9#FeatureAuthorization",
26056
+ "topic": {
26057
+ "@id": "https://w3id.org/fep/7aa9#topic",
26058
+ "@type": "@id"
26059
+ },
26060
+ "featuredObject": {
26061
+ "@id": "https://w3id.org/fep/7aa9#featuredObject",
26062
+ "@type": "@id"
26063
+ },
26064
+ "canFeature": {
26065
+ "@id": "https://w3id.org/fep/7aa9#canFeature",
26066
+ "@type": "@id"
26067
+ },
26068
+ "featureAuthorization": {
26069
+ "@id": "https://w3id.org/fep/7aa9#featureAuthorization",
26070
+ "@type": "@id"
26071
+ }
26072
+ } },
26051
26073
  "https://join-lemmy.org/context.json": { "@context": ["https://w3id.org/security/v1", {
26052
26074
  "as": "https://www.w3.org/ns/activitystreams#",
26053
26075
  "lemmy": "https://join-lemmy.org/ns#",
@@ -26104,7 +26126,7 @@ const preloadedContexts = {
26104
26126
  } }
26105
26127
  };
26106
26128
  var name = "@fedify/vocab-runtime";
26107
- var version = "2.4.0-dev.1528+fea670ad";
26129
+ var version = "2.4.0-dev.1564+5a2c6c2c";
26108
26130
  const parametersNeedLowerCase = ["rel", "type"];
26109
26131
  const regexpLinkWhitespace = /[\n\r\s\t]/;
26110
26132
  function validateURI(uri) {
@@ -26358,6 +26380,66 @@ const logger = getLogger([
26358
26380
  "docloader"
26359
26381
  ]);
26360
26382
  const DEFAULT_MAX_REDIRECTION = 20;
26383
+ const MAX_HTML_SIZE = 1024 * 1024;
26384
+ function createResponseMetadata(response) {
26385
+ return new Response(null, {
26386
+ headers: response.headers,
26387
+ status: response.status,
26388
+ statusText: response.statusText
26389
+ });
26390
+ }
26391
+ async function cancelResponseBody(response) {
26392
+ if (response.body != null) await response.body.cancel();
26393
+ }
26394
+ async function readBoundedText(response, maxBytes) {
26395
+ const contentLength = response.headers.get("Content-Length");
26396
+ if (contentLength != null) {
26397
+ const size = Number(contentLength);
26398
+ if (size > maxBytes) {
26399
+ await cancelResponseBody(response);
26400
+ return {
26401
+ text: "",
26402
+ size,
26403
+ tooLarge: true
26404
+ };
26405
+ }
26406
+ }
26407
+ if (response.body == null) return {
26408
+ text: "",
26409
+ size: 0,
26410
+ tooLarge: false
26411
+ };
26412
+ const reader = response.body.getReader();
26413
+ const decoder = new TextDecoder();
26414
+ let text = "";
26415
+ let size = 0;
26416
+ try {
26417
+ while (true) {
26418
+ const result = await reader.read();
26419
+ if (result.done) break;
26420
+ const chunkSize = result.value.byteLength;
26421
+ if (size + chunkSize > maxBytes) {
26422
+ size += chunkSize;
26423
+ await reader.cancel();
26424
+ return {
26425
+ text: "",
26426
+ size,
26427
+ tooLarge: true
26428
+ };
26429
+ }
26430
+ size += chunkSize;
26431
+ text += decoder.decode(result.value, { stream: true });
26432
+ }
26433
+ text += decoder.decode();
26434
+ return {
26435
+ text,
26436
+ size,
26437
+ tooLarge: false
26438
+ };
26439
+ } finally {
26440
+ reader.releaseLock();
26441
+ }
26442
+ }
26361
26443
  /**
26362
26444
  * Gets a {@link RemoteDocument} from the given response.
26363
26445
  * @param url The URL of the document to load.
@@ -26412,19 +26494,19 @@ async function getRemoteDocument(url, response, fetch) {
26412
26494
  }
26413
26495
  let document;
26414
26496
  if (!jsonLd && (contentType === "text/html" || contentType?.startsWith("text/html;") || contentType === "application/xhtml+xml" || contentType?.startsWith("application/xhtml+xml;"))) {
26415
- const MAX_HTML_SIZE = 1024 * 1024;
26416
- const html = await response.text();
26417
- if (html.length > MAX_HTML_SIZE) {
26497
+ const errorResponse = createResponseMetadata(response);
26498
+ const html = await readBoundedText(response, MAX_HTML_SIZE);
26499
+ if (html.tooLarge) {
26418
26500
  logger.warn("HTML response too large, skipping alternate link discovery: {url}", {
26419
26501
  url: documentUrl,
26420
- size: html.length
26502
+ size: html.size
26421
26503
  });
26422
- document = JSON.parse(html);
26504
+ throw new FetchError(documentUrl, `HTML document is too large to scan for an ActivityPub alternate link (Content-Type: ${contentType})`, errorResponse);
26423
26505
  } else {
26424
26506
  const tagPattern = /<(a|link)\s+([^>]*?)\s*\/?>/gi;
26425
26507
  const attrPattern = /([a-z][a-z:_-]*)=(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi;
26426
26508
  let tagMatch;
26427
- while ((tagMatch = tagPattern.exec(html)) !== null) {
26509
+ while ((tagMatch = tagPattern.exec(html.text)) !== null) {
26428
26510
  const tagContent = tagMatch[2];
26429
26511
  let attrMatch;
26430
26512
  const attribs = {};
@@ -26441,7 +26523,12 @@ async function getRemoteDocument(url, response, fetch) {
26441
26523
  return await fetch(new URL(attribs.href, docUrl).href);
26442
26524
  }
26443
26525
  }
26444
- document = JSON.parse(html);
26526
+ try {
26527
+ document = JSON.parse(html.text);
26528
+ } catch (error) {
26529
+ if (!(error instanceof SyntaxError)) throw error;
26530
+ throw new FetchError(documentUrl, `HTML document has no ActivityPub alternate link (Content-Type: ${contentType})`, errorResponse);
26531
+ }
26445
26532
  }
26446
26533
  } else document = await response.json();
26447
26534
  logger.debug("Fetched document: {status} {url} {headers}", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/relay",
3
- "version": "2.4.0-dev.1528+fea670ad",
3
+ "version": "2.4.0-dev.1564+5a2c6c2c",
4
4
  "description": "ActivityPub relay support for Fedify",
5
5
  "keywords": [
6
6
  "Fedify",
@@ -47,14 +47,14 @@
47
47
  "dependencies": {
48
48
  "@js-temporal/polyfill": "^0.5.1",
49
49
  "@logtape/logtape": "^2.2.0",
50
- "@fedify/vocab": "2.4.0-dev.1528+fea670ad",
51
- "@fedify/fedify": "^2.4.0-dev.1528+fea670ad"
50
+ "@fedify/vocab": "2.4.0-dev.1564+5a2c6c2c",
51
+ "@fedify/fedify": "^2.4.0-dev.1564+5a2c6c2c"
52
52
  },
53
53
  "devDependencies": {
54
54
  "tsdown": "^0.22.0",
55
55
  "typescript": "^6.0.0",
56
56
  "urlpattern-polyfill": "^10.1.0",
57
- "@fedify/vocab-runtime": "^2.4.0-dev.1528+fea670ad"
57
+ "@fedify/vocab-runtime": "^2.4.0-dev.1564+5a2c6c2c"
58
58
  },
59
59
  "scripts": {
60
60
  "build:self": "tsdown",