@rmdes/indiekit-endpoint-activitypub 1.0.25 → 1.0.26

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.
@@ -44,8 +44,9 @@ export function fromExpressRequest(req) {
44
44
  *
45
45
  * @param {import("express").Response} res - Express response
46
46
  * @param {Response} response - Standard Response from federation.fetch()
47
+ * @param {Request} [request] - Original request (for targeted patching)
47
48
  */
48
- async function sendFedifyResponse(res, response) {
49
+ async function sendFedifyResponse(res, response, request) {
49
50
  res.status(response.status);
50
51
  response.headers.forEach((value, key) => {
51
52
  res.setHeader(key, value);
@@ -56,6 +57,33 @@ async function sendFedifyResponse(res, response) {
56
57
  return;
57
58
  }
58
59
 
60
+ // WORKAROUND: Fedify serializes endpoints with "type": "as:Endpoints"
61
+ // which is not a real ActivityStreams type (fails browser.pub validation).
62
+ // For actor JSON responses, buffer the body and strip the invalid type.
63
+ // See: https://github.com/fedify-dev/fedify/issues/576
64
+ // TODO: Remove this workaround when Fedify fixes the upstream issue.
65
+ const contentType = response.headers.get("content-type") || "";
66
+ const isActorJson =
67
+ contentType.includes("activity+json") ||
68
+ contentType.includes("ld+json");
69
+
70
+ if (isActorJson) {
71
+ const body = await response.text();
72
+ try {
73
+ const json = JSON.parse(body);
74
+ if (json.endpoints?.type) {
75
+ delete json.endpoints.type;
76
+ }
77
+ const patched = JSON.stringify(json);
78
+ res.setHeader("content-length", Buffer.byteLength(patched));
79
+ res.end(patched);
80
+ } catch {
81
+ // Not valid JSON — send as-is
82
+ res.end(body);
83
+ }
84
+ return;
85
+ }
86
+
59
87
  const reader = response.body.getReader();
60
88
  await new Promise((resolve) => {
61
89
  function read({ done, value }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-activitypub",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
5
5
  "keywords": [
6
6
  "indiekit",