@fedify/fedify 2.1.30 → 2.1.32

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.
Files changed (104) hide show
  1. package/dist/attachment-arrays-DZ4JHJD8.mjs +111 -0
  2. package/dist/{builder-CTpfuuVp.mjs → builder--sc-rozj.mjs} +3 -3
  3. package/dist/callback-BARPujV7.d.mts +2388 -0
  4. package/dist/{client-CAM_bQXx.d.cts → client-9DPcy_Yx.d.ts} +16 -1
  5. package/dist/{client-CSddvgWN.d.ts → client-B3ruDgWg.d.cts} +16 -1
  6. package/dist/{client-CjDMsn4a.mjs → client-cpPaW7Ww.mjs} +189 -65
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +254 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/transformers.test.mjs +1 -1
  12. package/dist/{context-DLLaDau8.d.ts → context-DE2YrQwM.d.ts} +56 -13
  13. package/dist/{context-BNwv9Q1v.d.cts → context-y6ZUQCMf.d.cts} +56 -13
  14. package/dist/{deno-BATJ1hq6.mjs → deno-L23b3Hba.mjs} +1 -1
  15. package/dist/docloader-DUXr9k_O.mjs +124 -0
  16. package/dist/federation/attachment-responses.test.d.mts +2 -0
  17. package/dist/federation/attachment-responses.test.mjs +182 -0
  18. package/dist/federation/builder.test.mjs +1 -1
  19. package/dist/federation/collection.test.mjs +1 -1
  20. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  21. package/dist/federation/delivery-attachments.test.mjs +280 -0
  22. package/dist/federation/handler.test.mjs +208 -16
  23. package/dist/federation/idempotency.test.mjs +2 -2
  24. package/dist/federation/inbox.test.mjs +1 -1
  25. package/dist/federation/middleware.test.mjs +1559 -26
  26. package/dist/federation/mod.cjs +1 -1
  27. package/dist/federation/mod.d.cts +2 -2
  28. package/dist/federation/mod.d.ts +2 -2
  29. package/dist/federation/mod.js +1 -1
  30. package/dist/federation/negotiation.test.mjs +1 -1
  31. package/dist/federation/retry.test.mjs +1 -1
  32. package/dist/federation/send.test.mjs +723 -68
  33. package/dist/federation/temporal.test.mjs +25 -1
  34. package/dist/federation/webfinger.test.mjs +1 -1
  35. package/dist/{http-CK3efjgM.js → http-BtbMAgTA.js} +176 -105
  36. package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
  37. package/dist/{http-BoR1M3W7.cjs → http-D5woFKA_.cjs} +177 -106
  38. package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
  39. package/dist/{http-Bjd6I92u.mjs → http-HX6wVyJh.mjs} +198 -98
  40. package/dist/{inbox-9MlBGgs9.mjs → inbox-CL7A0HXT.mjs} +1 -1
  41. package/dist/{key-ClQh9Qqh.mjs → key-Dai3f5yI.mjs} +3 -2
  42. package/dist/{kv-cache-BxSx_Iyp.cjs → kv-cache-B0V_e231.cjs} +59 -17
  43. package/dist/{kv-cache-ImApO425.js → kv-cache-BsDg-cT8.js} +60 -18
  44. package/dist/{ld-Crg0Xmwr.mjs → ld-DN6x1iZ8.mjs} +153 -21
  45. package/dist/ld-signature-DoZcbsZR.mjs +23 -0
  46. package/dist/{middleware-jL9p9V9G.cjs → middleware-Cl6k5Hrm.cjs} +1 -1
  47. package/dist/{middleware-CmD3lpy4.cjs → middleware-CrfRuKCf.cjs} +728 -143
  48. package/dist/{middleware-CE0b69gj.mjs → middleware-DiquMgtt.mjs} +444 -115
  49. package/dist/{middleware-C2AJFk8W.js → middleware-DunNtbo9.js} +727 -143
  50. package/dist/{middleware-Bi5D6DBT.mjs → middleware-SnQS8eIb.mjs} +1 -1
  51. package/dist/{mod-DiuFTYUt.d.cts → mod-CehHJOV4.d.cts} +30 -13
  52. package/dist/{mod-CWJNbyju.d.ts → mod-DLJpnqdw.d.ts} +1 -1
  53. package/dist/{mod-BLDHhuW0.d.ts → mod-Mh3oIuRK.d.ts} +30 -13
  54. package/dist/{mod-DNEgTI8M.d.ts → mod-REfljt0T.d.ts} +4 -9
  55. package/dist/{mod-Cn9GJ5ex.d.cts → mod-UvIGUHqW.d.cts} +4 -9
  56. package/dist/{mod-BmlfRBmU.d.cts → mod-sTa1Zzxk.d.cts} +1 -1
  57. package/dist/mod.cjs +5 -5
  58. package/dist/mod.d.cts +8 -8
  59. package/dist/mod.d.ts +8 -8
  60. package/dist/mod.js +5 -5
  61. package/dist/nodeinfo/client.test.mjs +764 -19
  62. package/dist/nodeinfo/handler.test.mjs +1 -1
  63. package/dist/nodeinfo/mod.cjs +1 -1
  64. package/dist/nodeinfo/mod.d.cts +1 -1
  65. package/dist/nodeinfo/mod.d.ts +1 -1
  66. package/dist/nodeinfo/mod.js +1 -1
  67. package/dist/nodeinfo/types.test.mjs +1 -1
  68. package/dist/otel/exporter.test.mjs +292 -30
  69. package/dist/otel/mod.cjs +36 -30
  70. package/dist/otel/mod.d.cts +13 -0
  71. package/dist/otel/mod.d.ts +13 -0
  72. package/dist/otel/mod.js +36 -30
  73. package/dist/{owner-BRoKojK1.mjs → owner-DwyDorZI.mjs} +2 -2
  74. package/dist/{proof-CHXVlsH_.cjs → proof-Be-4K4jn.cjs} +193 -46
  75. package/dist/{proof-DMIAezxz.mjs → proof-DYjmyrHh.mjs} +38 -13
  76. package/dist/{proof-7R4s10TJ.js → proof-Du4-5SHY.js} +187 -46
  77. package/dist/send-BGSfQkIK.mjs +416 -0
  78. package/dist/sig/http.test.mjs +506 -2
  79. package/dist/sig/key-types.test.d.mts +218 -0
  80. package/dist/sig/key-types.test.mjs +8 -0
  81. package/dist/sig/key.test.mjs +2 -2
  82. package/dist/sig/ld.test.mjs +573 -8
  83. package/dist/sig/mod.cjs +2 -2
  84. package/dist/sig/mod.d.cts +3 -3
  85. package/dist/sig/mod.d.ts +3 -3
  86. package/dist/sig/mod.js +2 -2
  87. package/dist/sig/owner.test.mjs +1 -1
  88. package/dist/sig/proof.test.mjs +95 -3
  89. package/dist/{temporal-DR0JahMu.mjs → temporal-CNCchWly.mjs} +3 -5
  90. package/dist/testing/mod.d.mts +1 -2177
  91. package/dist/{types-DRPjmHVV.cjs → types-B5wRhemi.cjs} +187 -63
  92. package/dist/{types-miAYfiGO.js → types-CXy2lRVU.js} +188 -64
  93. package/dist/utils/docloader.test.mjs +316 -32
  94. package/dist/utils/mod.cjs +1 -1
  95. package/dist/utils/mod.d.cts +1 -1
  96. package/dist/utils/mod.d.ts +1 -1
  97. package/dist/utils/mod.js +1 -1
  98. package/package.json +7 -7
  99. package/dist/docloader-OLWc7P2D.mjs +0 -82
  100. package/dist/send-BHIt_8ia.mjs +0 -260
  101. /package/dist/{collection-BD6-SZ6O.mjs → collection-DnoYNwBC.mjs} +0 -0
  102. /package/dist/{negotiation-BehA2uul.mjs → negotiation-xb0QR3u_.mjs} +0 -0
  103. /package/dist/{retry-B_E3V_Dx.mjs → retry-CI1flGDD.mjs} +0 -0
  104. /package/dist/{types-DCP0WLdt.mjs → types-s4mCTGkT.mjs} +0 -0
@@ -0,0 +1,111 @@
1
+ import "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { preloadedContexts } from "@fedify/vocab-runtime";
5
+ import { getLogger } from "@logtape/logtape";
6
+ import jsonld from "@fedify/vocab-runtime/jsonld";
7
+ //#region src/compat/attachment-arrays.ts
8
+ const logger = getLogger([
9
+ "fedify",
10
+ "compat",
11
+ "attachment-arrays"
12
+ ]);
13
+ const MAX_DEPTH = 64;
14
+ const ATTACHMENT = "https://www.w3.org/ns/activitystreams#attachment";
15
+ const PROOF = "https://w3id.org/security#proof";
16
+ /** Recognizes JSON-LD maps without accepting arrays or scalar values. */
17
+ function isMap(value) {
18
+ return typeof value === "object" && value != null && !Array.isArray(value);
19
+ }
20
+ /** Copies only changed branches; cached vocabulary JSON belongs to its owner. */
21
+ function walk(value, depth = 0) {
22
+ if (depth >= MAX_DEPTH) throw new RangeError("JSON-LD nesting limit exceeded.");
23
+ if (Array.isArray(value)) {
24
+ const items = value.map((item) => walk(item, depth + 1));
25
+ return items.some((item, i) => item !== value[i]) ? items : value;
26
+ }
27
+ if (!isMap(value)) return value;
28
+ if (Object.hasOwn(value, "@value")) return value;
29
+ let result;
30
+ for (const [key, item] of Object.entries(value)) {
31
+ let next = key === "@context" ? item : walk(item, depth + 1);
32
+ if ((key === "attachment" || key === ATTACHMENT) && next != null && !Array.isArray(next) && !(isMap(next) && Object.hasOwn(next, "@list"))) next = [next];
33
+ if (next !== item) {
34
+ result ??= Object.assign(Object.create(null), value);
35
+ result[key] = next;
36
+ }
37
+ }
38
+ return result ?? value;
39
+ }
40
+ const preloadedLoader = (url) => {
41
+ if (!Object.hasOwn(preloadedContexts, url)) return Promise.reject(/* @__PURE__ */ new Error("Unknown JSON-LD context: " + url));
42
+ return Promise.resolve({
43
+ contextUrl: null,
44
+ documentUrl: url,
45
+ document: preloadedContexts[url]
46
+ });
47
+ };
48
+ /** Reuses each context resolution across the complete equivalence check. */
49
+ function memoizeLoader(loader) {
50
+ const pending = /* @__PURE__ */ new Map();
51
+ return (url, options) => {
52
+ let result = pending.get(url);
53
+ if (result == null) {
54
+ result = loader(url, options);
55
+ pending.set(url, result);
56
+ }
57
+ return result;
58
+ };
59
+ }
60
+ /** Finds security predicates in expanded nodes, never inside JSON literals. */
61
+ function hasSecurityPredicate(value) {
62
+ if (Array.isArray(value)) return value.some(hasSecurityPredicate);
63
+ if (!isMap(value) || Object.hasOwn(value, "@value")) return false;
64
+ for (const [key, child] of Object.entries(value)) {
65
+ if (key === PROOF || key === "https://w3id.org/security#signature") return true;
66
+ if (hasSecurityPredicate(child)) return true;
67
+ }
68
+ return false;
69
+ }
70
+ /**
71
+ * Keeps singleton attachments in arrays for raw-JSON ActivityPub consumers.
72
+ * Mastodon's property_values() ignores valid compact JSON-LD scalar values,
73
+ * and its caller clears the profile fields in that case:
74
+ * https://github.com/mastodon/mastodon/blob/594166519a623584920c7e696bae9a009d9183ab/app/services/activitypub/process_account_service.rb#L465-L472
75
+ * Pixelfed likewise rejects singleton media attachments:
76
+ * https://github.com/pixelfed/pixelfed/issues/6588
77
+ *
78
+ * This workaround changes only attachment representation, after serialization.
79
+ * RDF equality protects custom contexts, including JSON literals; it does not
80
+ * protect JCS signatures. Any semantic proof or Linked Data signature leaves
81
+ * the whole serialized document unchanged, as does an unresolved context.
82
+ * This layer does not compose signed objects or repair vocabulary serialization.
83
+ * Remove this
84
+ * workaround only when the supported consumer versions, including deployed
85
+ * older releases, accept scalar attachments. Do not replace it with a
86
+ * vocabulary transformer: subsequent compaction collapses arrays.
87
+ * @internal
88
+ */
89
+ async function normalizeAttachmentArrays(document, contextLoader) {
90
+ try {
91
+ const normalized = walk(document);
92
+ if (normalized === document) return document;
93
+ const loader = memoizeLoader(contextLoader ?? preloadedLoader);
94
+ if (hasSecurityPredicate(await jsonld.expand(document, { documentLoader: loader }))) return document;
95
+ const [before, after] = await Promise.allSettled([jsonld.canonize(document, {
96
+ format: "application/n-quads",
97
+ documentLoader: loader
98
+ }), jsonld.canonize(normalized, {
99
+ format: "application/n-quads",
100
+ documentLoader: loader
101
+ })]);
102
+ if (before.status === "rejected") throw before.reason;
103
+ if (after.status === "rejected") throw after.reason;
104
+ if (before.value === after.value) return normalized;
105
+ } catch (error) {
106
+ logger.debug("Could not safely normalize attachment arrays; preserving the document: {error}", { error });
107
+ }
108
+ return document;
109
+ }
110
+ //#endregion
111
+ export { normalizeAttachmentArrays as t };
@@ -2,8 +2,8 @@ import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { n as RouterError, t as Router } from "./router-CrMLXoOr.mjs";
5
- import { n as version, t as name } from "./deno-BATJ1hq6.mjs";
6
- import { t as InboxListenerSet } from "./inbox-9MlBGgs9.mjs";
5
+ import { n as version, t as name } from "./deno-L23b3Hba.mjs";
6
+ import { t as InboxListenerSet } from "./inbox-CL7A0HXT.mjs";
7
7
  import { getTypeId } from "@fedify/vocab";
8
8
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
9
9
  import { getLogger } from "@logtape/logtape";
@@ -44,7 +44,7 @@ var FederationBuilderImpl = class {
44
44
  this.collectionTypeIds = {};
45
45
  }
46
46
  async build(options) {
47
- const { FederationImpl } = await import("./middleware-Bi5D6DBT.mjs");
47
+ const { FederationImpl } = await import("./middleware-SnQS8eIb.mjs");
48
48
  const f = new FederationImpl(options);
49
49
  const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
50
50
  f.router = this.router.clone();