@fedify/fedify 1.9.0-pr.443.1682 → 1.9.0-pr.455.1742

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 (138) hide show
  1. package/dist/{actor-sT_gcgkl.d.ts → actor-C1Euqngb.d.ts} +1 -1
  2. package/dist/{actor-DNoKtm0e.js → actor-CL8lYYUx.js} +1 -1
  3. package/dist/{actor-BfM4acO7.js → actor-CYnaKz6k.js} +6169 -2946
  4. package/dist/{actor-C84MVjvg.cjs → actor-D_0j9hMV.cjs} +6169 -2946
  5. package/dist/{actor-D8GmZX63.d.cts → actor-Ydzhc8dj.d.cts} +1 -1
  6. package/dist/{authdocloader-BZ3wxRbU.cjs → authdocloader-AGT1bvSf.cjs} +3 -3
  7. package/dist/{authdocloader-BMUj-LDP.js → authdocloader-BlVoSqyh.js} +3 -3
  8. package/dist/{authdocloader-CSF0HpUd.js → authdocloader-CRuH00Tu.js} +3 -3
  9. package/dist/{builder-DbzYJjYW.js → builder-CqMKWEN0.js} +14 -8
  10. package/dist/{client-BXo-ifnJ.js → client-BM12q1DJ.js} +1 -1
  11. package/dist/compat/mod.d.cts +7 -7
  12. package/dist/compat/mod.d.ts +7 -7
  13. package/dist/compat/transformers.test.js +16 -16
  14. package/dist/{context-Cp-kboln.d.ts → context-CXUibY4L.d.ts} +179 -116
  15. package/dist/{context-BkqGJwLI.d.cts → context-CwUAkopp.d.cts} +179 -116
  16. package/dist/{docloader-vwID5KeD.js → docloader-BggS4E4F.js} +1 -1
  17. package/dist/{docloader-C8VNT_Xq.cjs → docloader-CLtA3Ji8.cjs} +1 -1
  18. package/dist/{esm-BrKG8Ydq.js → esm-B3jpomik.js} +1 -1
  19. package/dist/federation/builder.test.js +5 -5
  20. package/dist/federation/collection.test.js +3 -3
  21. package/dist/federation/handler.test.js +17 -17
  22. package/dist/federation/idempotency.test.d.ts +3 -0
  23. package/dist/federation/idempotency.test.js +202 -0
  24. package/dist/federation/inbox.test.js +4 -4
  25. package/dist/federation/keycache.test.js +4 -4
  26. package/dist/federation/kv.test.js +3 -3
  27. package/dist/federation/middleware.test.js +18 -18
  28. package/dist/federation/mod.cjs +10 -10
  29. package/dist/federation/mod.d.cts +7 -7
  30. package/dist/federation/mod.d.ts +7 -7
  31. package/dist/federation/mod.js +10 -10
  32. package/dist/federation/mq.test.js +3 -3
  33. package/dist/federation/retry.test.js +3 -3
  34. package/dist/federation/router.test.js +3 -3
  35. package/dist/federation/send.test.js +10 -10
  36. package/dist/fixtures/media.example.com/avatars/test-avatar.jpg.json +6 -0
  37. package/dist/{http-D21OQwhJ.cjs → http-2m_h3SPQ.cjs} +3 -3
  38. package/dist/{http-B9UPBFJz.d.cts → http-B1_DzfAU.d.cts} +1 -1
  39. package/dist/{http-1S7OolRE.js → http-D53H7oqD.js} +3 -3
  40. package/dist/{http-PJ3EklL0.js → http-DNkYeLxx.js} +2 -2
  41. package/dist/{http-BGqh2jzk.d.ts → http-wsGR6KkT.d.ts} +1 -1
  42. package/dist/{inbox-4wLOWRkP.js → inbox-FbqGLKha.js} +29 -7
  43. package/dist/{key-CH7qaiOX.js → key-B42BY6RL.js} +2 -2
  44. package/dist/{key-7YeppNTi.js → key-BVNVEpXg.js} +2 -2
  45. package/dist/key-CYO3d3Bc.cjs +10 -0
  46. package/dist/{key-Bt6aeupK.cjs → key-CZzEU9nv.cjs} +2 -2
  47. package/dist/{key-DTUnLJZM.js → key-Dj6-orIK.js} +3 -3
  48. package/dist/{key-DbudJOUz.js → key-NaBDH7FK.js} +4 -4
  49. package/dist/{keycache-OXZYOWra.js → keycache-BLtGOP6f.js} +1 -1
  50. package/dist/{keys-DMbcSHvH.js → keys-BO3n2h_L.js} +1 -1
  51. package/dist/{ld-BLx5h_2L.js → ld-CMWQXDty.js} +2 -2
  52. package/dist/{lookup-B8X3pPjF.js → lookup-B5jlZrQb.js} +21 -12
  53. package/dist/{lookup-BQHLqqvB.cjs → lookup-BsOmKssB.cjs} +1 -1
  54. package/dist/{lookup-tJvVI01W.js → lookup-C-jJgyrW.js} +1 -1
  55. package/dist/middleware-BV1L9XDk.cjs +17 -0
  56. package/dist/{middleware-DpNXnRa6.js → middleware-CNAH05Vn.js} +78 -47
  57. package/dist/middleware-Cr46LoSG.js +26 -0
  58. package/dist/middleware-DAFFQX5e.js +17 -0
  59. package/dist/{middleware-BN1ZyxrJ.cjs → middleware-DOd67qPG.cjs} +78 -47
  60. package/dist/{middleware-CPgUeSYU.js → middleware-lg47b3mK.js} +43 -40
  61. package/dist/{mod-DxjZ8kbs.d.cts → mod-BUbqxBev.d.cts} +19 -1
  62. package/dist/{mod-OfRtcQo1.d.ts → mod-BcObK1Lz.d.ts} +2 -2
  63. package/dist/{mod-CnEwcmyF.d.ts → mod-CDObsV1d.d.ts} +19 -1
  64. package/dist/{mod-TsyIDkKn.d.ts → mod-CIbqfZW0.d.ts} +1 -1
  65. package/dist/{mod-Cuem8g-I.d.ts → mod-DgcYoyZK.d.ts} +2 -2
  66. package/dist/{mod-bscaBAIo.d.cts → mod-Dt-G9ZOS.d.cts} +1 -1
  67. package/dist/{mod-BihGJmMM.d.cts → mod-fjqfsrty.d.cts} +2 -2
  68. package/dist/{mod-Ds5wiXHw.d.cts → mod-mXx9V0q5.d.cts} +2 -2
  69. package/dist/mod.cjs +10 -10
  70. package/dist/mod.d.cts +10 -10
  71. package/dist/mod.d.ts +10 -10
  72. package/dist/mod.js +10 -10
  73. package/dist/nodeinfo/client.test.js +5 -5
  74. package/dist/nodeinfo/handler.test.js +16 -16
  75. package/dist/nodeinfo/mod.cjs +2 -2
  76. package/dist/nodeinfo/mod.js +2 -2
  77. package/dist/nodeinfo/semver.test.js +3 -3
  78. package/dist/nodeinfo/types.test.js +3 -3
  79. package/dist/{owner-BYxDl2qi.d.cts → owner-6KSEp9eV.d.cts} +2 -2
  80. package/dist/{owner-DOUl7e-t.d.ts → owner-BbeUDvOu.d.ts} +2 -2
  81. package/dist/{owner-DeXz0uXj.js → owner-Ch2ApIpq.js} +2 -2
  82. package/dist/{proof-1YMXAyHu.cjs → proof-BtqGVz24.cjs} +3 -3
  83. package/dist/{proof-C5AaUlDb.js → proof-Cge6SysA.js} +3 -3
  84. package/dist/{proof-DEbHE-Rp.js → proof-DaD7vIAi.js} +2 -2
  85. package/dist/runtime/authdocloader.test.js +9 -9
  86. package/dist/runtime/docloader.test.js +4 -4
  87. package/dist/runtime/key.test.js +5 -5
  88. package/dist/runtime/langstr.test.js +3 -3
  89. package/dist/runtime/link.test.js +3 -3
  90. package/dist/runtime/mod.cjs +6 -6
  91. package/dist/runtime/mod.d.cts +3 -3
  92. package/dist/runtime/mod.d.ts +3 -3
  93. package/dist/runtime/mod.js +6 -6
  94. package/dist/runtime/multibase/multibase.test.js +3 -3
  95. package/dist/runtime/url.test.js +3 -3
  96. package/dist/{send-ZLr2Fq_j.js → send-DE79ptpc.js} +2 -2
  97. package/dist/sig/http.test.js +8 -8
  98. package/dist/sig/key.test.js +6 -6
  99. package/dist/sig/ld.test.js +7 -7
  100. package/dist/sig/mod.cjs +6 -6
  101. package/dist/sig/mod.d.cts +5 -5
  102. package/dist/sig/mod.d.ts +5 -5
  103. package/dist/sig/mod.js +6 -6
  104. package/dist/sig/owner.test.js +7 -7
  105. package/dist/sig/proof.test.js +7 -7
  106. package/dist/testing/docloader.test.js +3 -3
  107. package/dist/testing/mod.d.ts +341 -379
  108. package/dist/testing/mod.js +3 -3
  109. package/dist/{testing-CyBcyXDK.js → testing-Bh2wmeXp.js} +2 -2
  110. package/dist/{type-C9v8GMO6.js → type-Du-WE8NC.js} +6297 -3074
  111. package/dist/{types-B2Gwh9uw.cjs → types-B1n1v8Fa.cjs} +1 -1
  112. package/dist/{types-KhFFD-xZ.js → types-ChEbJU3f.js} +1 -1
  113. package/dist/vocab/actor.test.js +5 -5
  114. package/dist/vocab/lookup.test.js +255 -5
  115. package/dist/vocab/mod.cjs +4 -4
  116. package/dist/vocab/mod.d.cts +3 -3
  117. package/dist/vocab/mod.d.ts +3 -3
  118. package/dist/vocab/mod.js +4 -4
  119. package/dist/vocab/type.test.js +3 -3
  120. package/dist/vocab/vocab.test.js +395 -24
  121. package/dist/{vocab-BW6SWH9P.d.ts → vocab-CDHNj5zp.d.ts} +158 -497
  122. package/dist/{vocab-qpRpljdS.d.cts → vocab-Cfs0937i.d.cts} +158 -497
  123. package/dist/{vocab-95nbu41B.cjs → vocab-DY3aCxLN.cjs} +23 -14
  124. package/dist/{vocab-DUIA4PK3.js → vocab-Q8XBm9oV.js} +23 -14
  125. package/dist/webfinger/handler.test.js +16 -16
  126. package/dist/webfinger/lookup.test.js +4 -4
  127. package/dist/webfinger/mod.cjs +2 -2
  128. package/dist/webfinger/mod.js +2 -2
  129. package/dist/x/cfworkers.test.js +3 -3
  130. package/dist/x/hono.d.cts +6 -6
  131. package/dist/x/hono.d.ts +6 -6
  132. package/dist/x/sveltekit.d.cts +6 -6
  133. package/dist/x/sveltekit.d.ts +6 -6
  134. package/package.json +1 -1
  135. package/dist/key-C-eEPc5P.cjs +0 -10
  136. package/dist/middleware-BKKzirBh.cjs +0 -17
  137. package/dist/middleware-D9dqPUdF.js +0 -17
  138. package/dist/middleware-ofHkiPKA.js +0 -26
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, deno_default } from "./type-C9v8GMO6.js";
7
- import { fetchKey, validateCryptoKey } from "./key-CH7qaiOX.js";
6
+ import { CryptographicKey, deno_default } from "./type-Du-WE8NC.js";
7
+ import { fetchKey, validateCryptoKey } from "./key-B42BY6RL.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
10
10
  import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
3
  import { DocumentLoader } from "./docloader-CxWcuWqQ.js";
4
- import { CryptographicKey, Multikey } from "./vocab-BW6SWH9P.js";
4
+ import { CryptographicKey, Multikey } from "./vocab-CDHNj5zp.js";
5
5
  import { TracerProvider } from "@opentelemetry/api";
6
6
 
7
7
  //#region src/sig/key.d.ts
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Activity, deno_default, getTypeId } from "./type-C9v8GMO6.js";
6
+ import { Activity, deno_default, getTypeId } from "./type-Du-WE8NC.js";
7
7
  import { getLogger } from "@logtape/logtape";
8
8
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
9
9
 
@@ -41,17 +41,39 @@ var InboxListenerSet = class InboxListenerSet {
41
41
  return this.dispatchWithClass(activity)?.listener ?? null;
42
42
  }
43
43
  };
44
- async function routeActivity({ context: ctx, json, activity, recipient, inboxListeners, inboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider }) {
44
+ let warnedAboutDefaultIdempotency = false;
45
+ async function routeActivity({ context: ctx, json, activity, recipient, inboxListeners, inboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider, idempotencyStrategy }) {
45
46
  const logger = getLogger([
46
47
  "fedify",
47
48
  "federation",
48
49
  "inbox"
49
50
  ]);
50
- const cacheKey = activity.id == null ? null : [
51
- ...kvPrefixes.activityIdempotence,
52
- ctx.origin,
53
- activity.id.href
54
- ];
51
+ let cacheKey = null;
52
+ if (activity.id != null) {
53
+ const inboxContext = inboxContextFactory(recipient, json, activity.id?.href, getTypeId(activity).href);
54
+ const strategy = idempotencyStrategy ?? "per-origin";
55
+ if (idempotencyStrategy === void 0 && !warnedAboutDefaultIdempotency) {
56
+ logger.warn("Using default idempotency strategy 'per-origin'. This default will change to 'per-inbox' in Fedify 2.0. Please explicitly set the idempotency strategy using .withIdempotency().");
57
+ warnedAboutDefaultIdempotency = true;
58
+ }
59
+ let keyString;
60
+ if (typeof strategy === "function") {
61
+ const result = await strategy(inboxContext, activity);
62
+ keyString = result;
63
+ } else switch (strategy) {
64
+ case "global":
65
+ keyString = activity.id.href;
66
+ break;
67
+ case "per-origin":
68
+ keyString = `${ctx.origin}\n${activity.id.href}`;
69
+ break;
70
+ case "per-inbox":
71
+ keyString = `${ctx.origin}\n${activity.id.href}\n${recipient == null ? "sharedInbox" : `inbox\n${recipient}`}`;
72
+ break;
73
+ default: keyString = `${ctx.origin}\n${activity.id.href}`;
74
+ }
75
+ if (keyString != null) cacheKey = [...kvPrefixes.activityIdempotence, keyString];
76
+ }
55
77
  if (cacheKey != null) {
56
78
  const cached = await kv.get(cacheKey);
57
79
  if (cached === true) {
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Object as Object$1, deno_default, getDocumentLoader } from "./type-C9v8GMO6.js";
7
- import { isActor } from "./actor-DNoKtm0e.js";
6
+ import { CryptographicKey, Object as Object$1, deno_default, getDocumentLoader } from "./type-Du-WE8NC.js";
7
+ import { isActor } from "./actor-CL8lYYUx.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
10
10
 
@@ -2,8 +2,8 @@
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
 
5
- import { deno_default, getDocumentLoader } from "./docloader-vwID5KeD.js";
6
- import { CryptographicKey, Object as Object$1, isActor } from "./actor-BfM4acO7.js";
5
+ import { deno_default, getDocumentLoader } from "./docloader-BggS4E4F.js";
6
+ import { CryptographicKey, Object as Object$1, isActor } from "./actor-CYnaKz6k.js";
7
7
  import { getLogger } from "@logtape/logtape";
8
8
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
9
9
 
@@ -0,0 +1,10 @@
1
+
2
+ const { Temporal } = require("@js-temporal/polyfill");
3
+ const { URLPattern } = require("urlpattern-polyfill");
4
+
5
+ require('./docloader-CLtA3Ji8.cjs');
6
+ require('./actor-D_0j9hMV.cjs');
7
+ require('./lookup-BsOmKssB.cjs');
8
+ const require_key = require('./key-CZzEU9nv.cjs');
9
+
10
+ exports.validateCryptoKey = require_key.validateCryptoKey;
@@ -3,8 +3,8 @@
3
3
  const { URLPattern } = require("urlpattern-polyfill");
4
4
 
5
5
  const require_chunk = require('./chunk-DqRYRqnO.cjs');
6
- const require_docloader = require('./docloader-C8VNT_Xq.cjs');
7
- const require_actor = require('./actor-C84MVjvg.cjs');
6
+ const require_docloader = require('./docloader-CLtA3Ji8.cjs');
7
+ const require_actor = require('./actor-D_0j9hMV.cjs');
8
8
  const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
9
9
  const __opentelemetry_api = require_chunk.__toESM(require("@opentelemetry/api"));
10
10
 
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import "./type-C9v8GMO6.js";
7
- import "./actor-DNoKtm0e.js";
8
- import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-CH7qaiOX.js";
6
+ import "./type-Du-WE8NC.js";
7
+ import "./actor-CL8lYYUx.js";
8
+ import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-B42BY6RL.js";
9
9
 
10
10
  export { validateCryptoKey };
@@ -2,9 +2,9 @@
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
 
5
- import "./docloader-vwID5KeD.js";
6
- import "./actor-BfM4acO7.js";
7
- import "./lookup-tJvVI01W.js";
8
- import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-7YeppNTi.js";
5
+ import "./docloader-BggS4E4F.js";
6
+ import "./actor-CYnaKz6k.js";
7
+ import "./lookup-C-jJgyrW.js";
8
+ import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-BVNVEpXg.js";
9
9
 
10
10
  export { validateCryptoKey };
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Multikey } from "./type-C9v8GMO6.js";
6
+ import { CryptographicKey, Multikey } from "./type-Du-WE8NC.js";
7
7
 
8
8
  //#region src/federation/keycache.ts
9
9
  var KvKeyCache = class {
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Multikey, importSpki } from "./type-C9v8GMO6.js";
6
+ import { CryptographicKey, Multikey, importSpki } from "./type-Du-WE8NC.js";
7
7
 
8
8
  //#region src/testing/keys.ts
9
9
  const rsaPublicKey1 = new CryptographicKey({
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Activity, CryptographicKey, Object as Object$1, deno_default, getDocumentLoader, getTypeId } from "./type-C9v8GMO6.js";
7
- import { fetchKey, validateCryptoKey } from "./key-CH7qaiOX.js";
6
+ import { Activity, CryptographicKey, Object as Object$1, deno_default, getDocumentLoader, getTypeId } from "./type-Du-WE8NC.js";
7
+ import { fetchKey, validateCryptoKey } from "./key-B42BY6RL.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
10
10
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Object as Object$1, deno_default, getDocumentLoader, getTypeId, lookupWebFinger } from "./type-C9v8GMO6.js";
6
+ import { Object as Object$1, deno_default, getDocumentLoader, getTypeId, lookupWebFinger } from "./type-Du-WE8NC.js";
7
7
  import { cloneDeep, delay } from "es-toolkit";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
@@ -240,14 +240,13 @@ async function lookupObject(identifier, options = {}) {
240
240
  async function lookupObjectInternal(identifier, options = {}) {
241
241
  const documentLoader = options.documentLoader ?? getDocumentLoader({ userAgent: options.userAgent });
242
242
  if (typeof identifier === "string") identifier = toAcctUrl(identifier) ?? new URL(identifier);
243
- let document = null;
243
+ let remoteDoc = null;
244
244
  if (identifier.protocol === "http:" || identifier.protocol === "https:") try {
245
- const remoteDoc = await documentLoader(identifier.href, { signal: options.signal });
246
- document = remoteDoc.document;
245
+ remoteDoc = await documentLoader(identifier.href, { signal: options.signal });
247
246
  } catch (error) {
248
247
  logger.debug("Failed to fetch remote document:\n{error}", { error });
249
248
  }
250
- if (document == null) {
249
+ if (remoteDoc == null) {
251
250
  const jrd = await lookupWebFinger(identifier, {
252
251
  userAgent: options.userAgent,
253
252
  tracerProvider: options.tracerProvider,
@@ -258,8 +257,7 @@ async function lookupObjectInternal(identifier, options = {}) {
258
257
  for (const l of jrd.links) {
259
258
  if (l.type !== "application/activity+json" && !l.type?.match(/application\/ld\+json;\s*profile="https:\/\/www.w3.org\/ns\/activitystreams"/) || l.rel !== "self" || l.href == null) continue;
260
259
  try {
261
- const remoteDoc = await documentLoader(l.href, { signal: options.signal });
262
- document = remoteDoc.document;
260
+ remoteDoc = await documentLoader(l.href, { signal: options.signal });
263
261
  break;
264
262
  } catch (error) {
265
263
  logger.debug("Failed to fetch remote document:\n{error}", { error });
@@ -267,23 +265,34 @@ async function lookupObjectInternal(identifier, options = {}) {
267
265
  }
268
266
  }
269
267
  }
270
- if (document == null) return null;
268
+ if (remoteDoc == null) return null;
269
+ let object;
271
270
  try {
272
- return await Object$1.fromJsonLd(document, {
271
+ object = await Object$1.fromJsonLd(remoteDoc.document, {
273
272
  documentLoader,
274
273
  contextLoader: options.contextLoader,
275
- tracerProvider: options.tracerProvider
274
+ tracerProvider: options.tracerProvider,
275
+ baseUrl: new URL(remoteDoc.documentUrl)
276
276
  });
277
277
  } catch (error) {
278
278
  if (error instanceof TypeError) {
279
279
  logger.debug("Failed to parse JSON-LD document: {error}\n{document}", {
280
- error,
281
- document
280
+ ...remoteDoc,
281
+ error
282
282
  });
283
283
  return null;
284
284
  }
285
285
  throw error;
286
286
  }
287
+ if (options.crossOrigin !== "trust" && object.id != null && object.id.origin !== new URL(remoteDoc.documentUrl).origin) {
288
+ if (options.crossOrigin === "throw") throw new Error(`The object's @id (${object.id.href}) has a different origin than the document URL (${remoteDoc.documentUrl}); refusing to return the object. If you want to bypass this check and are aware of the security implications, set the crossOrigin option to "trust".`);
289
+ logger.warn("The object's @id ({objectId}) has a different origin than the document URL ({documentUrl}); refusing to return the object. If you want to bypass this check and are aware of the security implications, set the crossOrigin option to \"trust\".", {
290
+ ...remoteDoc,
291
+ objectId: object.id.href
292
+ });
293
+ return null;
294
+ }
295
+ return object;
287
296
  }
288
297
  /**
289
298
  * Traverses a collection, yielding each item in the collection.
@@ -3,7 +3,7 @@
3
3
  const { URLPattern } = require("urlpattern-polyfill");
4
4
 
5
5
  const require_chunk = require('./chunk-DqRYRqnO.cjs');
6
- const require_docloader = require('./docloader-C8VNT_Xq.cjs');
6
+ const require_docloader = require('./docloader-CLtA3Ji8.cjs');
7
7
  const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
8
8
  const __opentelemetry_api = require_chunk.__toESM(require("@opentelemetry/api"));
9
9
 
@@ -2,7 +2,7 @@
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
 
5
- import { UrlError, deno_default, getUserAgent, validatePublicUrl } from "./docloader-vwID5KeD.js";
5
+ import { UrlError, deno_default, getUserAgent, validatePublicUrl } from "./docloader-BggS4E4F.js";
6
6
  import { getLogger } from "@logtape/logtape";
7
7
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
8
8
 
@@ -0,0 +1,17 @@
1
+
2
+ const { Temporal } = require("@js-temporal/polyfill");
3
+ const { URLPattern } = require("urlpattern-polyfill");
4
+
5
+ require('./transformers-CoBS-oFG.cjs');
6
+ require('./docloader-CLtA3Ji8.cjs');
7
+ require('./actor-D_0j9hMV.cjs');
8
+ const require_middleware = require('./middleware-DOd67qPG.cjs');
9
+ require('./lookup-BsOmKssB.cjs');
10
+ require('./key-CZzEU9nv.cjs');
11
+ require('./http-2m_h3SPQ.cjs');
12
+ require('./proof-BtqGVz24.cjs');
13
+ require('./types-B1n1v8Fa.cjs');
14
+ require('./authdocloader-AGT1bvSf.cjs');
15
+ require('./vocab-DY3aCxLN.cjs');
16
+
17
+ exports.FederationImpl = require_middleware.FederationImpl;
@@ -3,15 +3,15 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
 
5
5
  import { getDefaultActivityTransformers } from "./transformers-BFT6d7J5.js";
6
- import { deno_default, getDocumentLoader, kvCache } from "./docloader-vwID5KeD.js";
7
- import { Activity, Collection, CollectionPage, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, getTypeId } from "./actor-BfM4acO7.js";
8
- import { lookupWebFinger } from "./lookup-tJvVI01W.js";
9
- import { exportJwk, importJwk, validateCryptoKey } from "./key-7YeppNTi.js";
10
- import { doubleKnock, verifyRequest } from "./http-1S7OolRE.js";
11
- import { detachSignature, doesActorOwnKey, getKeyOwner, hasSignature, signJsonLd, signObject, verifyJsonLd, verifyObject } from "./proof-C5AaUlDb.js";
12
- import { getNodeInfo, nodeInfoToJson } from "./types-KhFFD-xZ.js";
13
- import { getAuthenticatedDocumentLoader } from "./authdocloader-CSF0HpUd.js";
14
- import { lookupObject, traverseCollection } from "./vocab-DUIA4PK3.js";
6
+ import { deno_default, getDocumentLoader, kvCache } from "./docloader-BggS4E4F.js";
7
+ import { Activity, Collection, CollectionPage, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, getTypeId } from "./actor-CYnaKz6k.js";
8
+ import { lookupWebFinger } from "./lookup-C-jJgyrW.js";
9
+ import { exportJwk, importJwk, validateCryptoKey } from "./key-BVNVEpXg.js";
10
+ import { doubleKnock, verifyRequest } from "./http-D53H7oqD.js";
11
+ import { detachSignature, doesActorOwnKey, getKeyOwner, hasSignature, signJsonLd, signObject, verifyJsonLd, verifyObject } from "./proof-Cge6SysA.js";
12
+ import { getNodeInfo, nodeInfoToJson } from "./types-ChEbJU3f.js";
13
+ import { getAuthenticatedDocumentLoader } from "./authdocloader-CRuH00Tu.js";
14
+ import { lookupObject, traverseCollection } from "./vocab-Q8XBm9oV.js";
15
15
  import { getLogger, withContext } from "@logtape/logtape";
16
16
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
17
17
  import { encodeHex } from "byte-encodings/hex";
@@ -55,17 +55,39 @@ var InboxListenerSet = class InboxListenerSet {
55
55
  return this.dispatchWithClass(activity)?.listener ?? null;
56
56
  }
57
57
  };
58
- async function routeActivity({ context: ctx, json, activity, recipient, inboxListeners, inboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider }) {
58
+ let warnedAboutDefaultIdempotency = false;
59
+ async function routeActivity({ context: ctx, json, activity, recipient, inboxListeners, inboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider, idempotencyStrategy }) {
59
60
  const logger$1 = getLogger([
60
61
  "fedify",
61
62
  "federation",
62
63
  "inbox"
63
64
  ]);
64
- const cacheKey = activity.id == null ? null : [
65
- ...kvPrefixes.activityIdempotence,
66
- ctx.origin,
67
- activity.id.href
68
- ];
65
+ let cacheKey = null;
66
+ if (activity.id != null) {
67
+ const inboxContext = inboxContextFactory(recipient, json, activity.id?.href, getTypeId(activity).href);
68
+ const strategy = idempotencyStrategy ?? "per-origin";
69
+ if (idempotencyStrategy === void 0 && !warnedAboutDefaultIdempotency) {
70
+ logger$1.warn("Using default idempotency strategy 'per-origin'. This default will change to 'per-inbox' in Fedify 2.0. Please explicitly set the idempotency strategy using .withIdempotency().");
71
+ warnedAboutDefaultIdempotency = true;
72
+ }
73
+ let keyString;
74
+ if (typeof strategy === "function") {
75
+ const result = await strategy(inboxContext, activity);
76
+ keyString = result;
77
+ } else switch (strategy) {
78
+ case "global":
79
+ keyString = activity.id.href;
80
+ break;
81
+ case "per-origin":
82
+ keyString = `${ctx.origin}\n${activity.id.href}`;
83
+ break;
84
+ case "per-inbox":
85
+ keyString = `${ctx.origin}\n${activity.id.href}\n${recipient == null ? "sharedInbox" : `inbox\n${recipient}`}`;
86
+ break;
87
+ default: keyString = `${ctx.origin}\n${activity.id.href}`;
88
+ }
89
+ if (keyString != null) cacheKey = [...kvPrefixes.activityIdempotence, keyString];
90
+ }
69
91
  if (cacheKey != null) {
70
92
  const cached = await kv.get(cacheKey);
71
93
  if (cached === true) {
@@ -307,6 +329,7 @@ var FederationBuilderImpl = class {
307
329
  inboxListeners;
308
330
  inboxErrorHandler;
309
331
  sharedInboxKeyDispatcher;
332
+ idempotencyStrategy;
310
333
  collectionTypeIds;
311
334
  collectionCallbacks;
312
335
  /**
@@ -321,7 +344,7 @@ var FederationBuilderImpl = class {
321
344
  this.collectionTypeIds = {};
322
345
  }
323
346
  async build(options) {
324
- const { FederationImpl: FederationImpl$1 } = await import("./middleware-D9dqPUdF.js");
347
+ const { FederationImpl: FederationImpl$1 } = await import("./middleware-DAFFQX5e.js");
325
348
  const f = new FederationImpl$1(options);
326
349
  const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
327
350
  f.router = this.router.clone();
@@ -343,6 +366,7 @@ var FederationBuilderImpl = class {
343
366
  f.inboxListeners = this.inboxListeners?.clone();
344
367
  f.inboxErrorHandler = this.inboxErrorHandler;
345
368
  f.sharedInboxKeyDispatcher = this.sharedInboxKeyDispatcher;
369
+ f.idempotencyStrategy = this.idempotencyStrategy;
346
370
  return f;
347
371
  }
348
372
  _getTracer() {
@@ -765,15 +789,19 @@ var FederationBuilderImpl = class {
765
789
  setSharedKeyDispatcher: (dispatcher) => {
766
790
  this.sharedInboxKeyDispatcher = dispatcher;
767
791
  return setters;
792
+ },
793
+ withIdempotency: (strategy) => {
794
+ this.idempotencyStrategy = strategy;
795
+ return setters;
768
796
  }
769
797
  };
770
798
  return setters;
771
799
  }
772
- setCollectionDispatcher(name, ...args) {
773
- return this.#setCustomCollectionDispatcher(name, "collection", ...args);
800
+ setCollectionDispatcher(name, itemType, path, dispatcher) {
801
+ return this.#setCustomCollectionDispatcher(name, "collection", itemType, path, dispatcher);
774
802
  }
775
- setOrderedCollectionDispatcher(name, ...args) {
776
- return this.#setCustomCollectionDispatcher(name, "orderedCollection", ...args);
803
+ setOrderedCollectionDispatcher(name, itemType, path, dispatcher) {
804
+ return this.#setCustomCollectionDispatcher(name, "orderedCollection", itemType, path, dispatcher);
777
805
  }
778
806
  #setCustomCollectionDispatcher(name, collectionType, itemType, path, dispatcher) {
779
807
  const strName = String(name);
@@ -1296,7 +1324,8 @@ async function handleInbox(request, options) {
1296
1324
  * @param span The OpenTelemetry span for tracing.
1297
1325
  * @returns A promise that resolves to an HTTP response.
1298
1326
  */
1299
- async function handleInboxInternal(request, { recipient, context: ctx, inboxContextFactory, kv, kvPrefixes, queue, actorDispatcher, inboxListeners, inboxErrorHandler, onNotFound, signatureTimeWindow, skipSignatureVerification, tracerProvider }, span) {
1327
+ async function handleInboxInternal(request, parameters, span) {
1328
+ const { recipient, context: ctx, inboxContextFactory, kv, kvPrefixes, queue, actorDispatcher, inboxListeners, inboxErrorHandler, onNotFound, signatureTimeWindow, skipSignatureVerification, tracerProvider } = parameters;
1300
1329
  const logger$1 = getLogger([
1301
1330
  "fedify",
1302
1331
  "federation",
@@ -1498,7 +1527,8 @@ async function handleInboxInternal(request, { recipient, context: ctx, inboxCont
1498
1527
  kvPrefixes,
1499
1528
  queue,
1500
1529
  span,
1501
- tracerProvider
1530
+ tracerProvider,
1531
+ idempotencyStrategy: parameters.idempotencyStrategy
1502
1532
  });
1503
1533
  if (routeResult === "alreadyProcessed") return new Response(`Activity <${activity.id}> has already been processed.`, {
1504
1534
  status: 202,
@@ -1528,7 +1558,7 @@ async function handleInboxInternal(request, { recipient, context: ctx, inboxCont
1528
1558
  /**
1529
1559
  * Handles a custom collection request.
1530
1560
  * @template TItem The type of items in the collection.
1531
- * @template TParams The parameter names of the requested URL.
1561
+ * @template TParam The parameter names of the requested URL.
1532
1562
  * @template TContext The type of the context, extending {@link RequestContext}.
1533
1563
  * @template TContextData The context data to pass to the `TContext`.
1534
1564
  * @param request The HTTP request.
@@ -1547,7 +1577,7 @@ async function _handleCustomCollection(request, { name, values, context: context
1547
1577
  /**
1548
1578
  * Handles an ordered collection request.
1549
1579
  * @template TItem The type of items in the collection.
1550
- * @template TParams The parameter names of the requested URL.
1580
+ * @template TParam The parameter names of the requested URL.
1551
1581
  * @template TContext The type of the context, extending {@link RequestContext}.
1552
1582
  * @template TContextData The context data to pass to the `TContext`.
1553
1583
  * @param request The HTTP request.
@@ -1568,7 +1598,7 @@ async function _handleOrderedCollection(request, { name, values, context: contex
1568
1598
  * The main flow is on `getCollection`, `dispatch`.
1569
1599
  *
1570
1600
  * @template TItem The type of items in the collection.
1571
- * @template TParams The parameter names of the requested URL.
1601
+ * @template TParam The parameter names of the requested URL.
1572
1602
  * @template TContext The type of the context. {@link Context} or {@link RequestContext}.
1573
1603
  * @template TContextData The context data to pass to the `TContext`.
1574
1604
  * @template TCollection The type of the collection, extending {@link Collection}.
@@ -1602,14 +1632,14 @@ var CustomCollectionHandler = class {
1602
1632
  #collection = null;
1603
1633
  /**
1604
1634
  * Creates a new CustomCollection instance.
1605
- * @param {string} name The name of the collection.
1606
- * @param {TParams} values The parameter values for the collection.
1607
- * @param {TContext} context The request context.
1608
- * @param {CustomCollectionCallbacks} callbacks The collection callbacks.
1609
- * @param {TracerProvider} tracerProvider The tracer provider for telemetry.
1610
- * @param {ConstructorWithTypeId<TCollection>} Collection The Collection constructor.
1611
- * @param {ConstructorWithTypeId<TCollectionPage>} CollectionPage The CollectionPage constructor.
1612
- * @param {(item: TItem) => boolean} filterPredicate Optional filter predicate for items.
1635
+ * @param name The name of the collection.
1636
+ * @param values The parameter values for the collection.
1637
+ * @param context The request context.
1638
+ * @param callbacks The collection callbacks.
1639
+ * @param tracerProvider The tracer provider for telemetry.
1640
+ * @param Collection The Collection constructor.
1641
+ * @param CollectionPage The CollectionPage constructor.
1642
+ * @param filterPredicate Optional filter predicate for items.
1613
1643
  */
1614
1644
  constructor(name, values, context$1, callbacks, tracerProvider = trace.getTracerProvider(), Collection$1, CollectionPage$1, filterPredicate) {
1615
1645
  this.name = name;
@@ -1734,7 +1764,7 @@ var CustomCollectionHandler = class {
1734
1764
  /**
1735
1765
  * Creates a function to wrap the dispatcher so tracing can be applied.
1736
1766
  * @param params Parameters including cursor and total items.
1737
- * @returns {(span: Span) => Promise<PageItems<TItem>>} A function that handles the span operation.
1767
+ * @returns A function that handles the span operation.
1738
1768
  */
1739
1769
  spanPages = ({ totalItems = null, cursor = null }) => async (span) => {
1740
1770
  try {
@@ -1755,23 +1785,23 @@ var CustomCollectionHandler = class {
1755
1785
  };
1756
1786
  /**
1757
1787
  * Dispatches the collection request to get items.
1758
- * @param {string | null} cursor The cursor for pagination, or null for the first page.
1759
- * @returns {Promise<PageItems<TItem>>} A promise that resolves to the page items.
1788
+ * @param cursor The cursor for pagination, or null for the first page.
1789
+ * @returns A promise that resolves to the page items.
1760
1790
  */
1761
1791
  async dispatch(cursor = null) {
1762
1792
  return await this.#dispatcher(this.context, this.values, cursor) ?? new ItemsNotFoundError().throw();
1763
1793
  }
1764
1794
  /**
1765
1795
  * Filters the items in the collection.
1766
- * @param {TItem[]} items The items to filter.
1767
- * @returns {(Object | Link | URL)[]} The filtered items.
1796
+ * @param items The items to filter.
1797
+ * @returns The filtered items.
1768
1798
  */
1769
1799
  filterItems(items) {
1770
1800
  return filterCollectionItems(items, this.name, this.filterPredicate);
1771
1801
  }
1772
1802
  /**
1773
1803
  * Appends a cursor to the URL if it exists.
1774
- * @param {string | null | undefined} cursor The cursor to append, or null/undefined.
1804
+ * @param cursor The cursor to append, or null/undefined.
1775
1805
  * @returns The URL with cursor appended, or null if cursor is null/undefined.
1776
1806
  */
1777
1807
  appendToUrl(cursor) {
@@ -1779,8 +1809,7 @@ var CustomCollectionHandler = class {
1779
1809
  }
1780
1810
  /**
1781
1811
  * Gets the stored collection or collection page.
1782
- * @returns {Promise<TCollection | TCollectionPage>} A promise that resolves to
1783
- the collection or collection page.
1812
+ * @returns A promise that resolves to the collection or collection page.
1784
1813
  */
1785
1814
  get collection() {
1786
1815
  if (this.#collection === null) this.#collection = this.getCollection();
@@ -1788,8 +1817,8 @@ var CustomCollectionHandler = class {
1788
1817
  }
1789
1818
  /**
1790
1819
  * Gets the total number of items in the collection.
1791
- * @returns {Promise<number | null>} A promise that
1792
- resolves to the total items count, or null if not available.
1820
+ * @returns A promise that resolves to the total items count,
1821
+ * or null if not available.
1793
1822
  */
1794
1823
  get totalItems() {
1795
1824
  if (this.#totalItems === void 0) this.totalItems = this.callbacks.counter?.(this.context, this.values);
@@ -1805,8 +1834,8 @@ var CustomCollectionHandler = class {
1805
1834
  }
1806
1835
  /**
1807
1836
  * Gets the first cursor for pagination.
1808
- * @returns {Promise<string | null>} A promise that resolves to the first cursor,
1809
- or null if not available.
1837
+ * @returns A promise that resolves to the first cursor,
1838
+ * or null if not available.
1810
1839
  */
1811
1840
  get firstCursor() {
1812
1841
  const cursor = this.callbacks.firstCursor?.(this.context, this.values);
@@ -3095,7 +3124,8 @@ var FederationImpl = class extends FederationBuilderImpl {
3095
3124
  onNotFound,
3096
3125
  signatureTimeWindow: this.signatureTimeWindow,
3097
3126
  skipSignatureVerification: this.skipSignatureVerification,
3098
- tracerProvider: this.tracerProvider
3127
+ tracerProvider: this.tracerProvider,
3128
+ idempotencyStrategy: this.idempotencyStrategy
3099
3129
  });
3100
3130
  case "following": return await handleCollection(request, {
3101
3131
  name: "following",
@@ -3845,7 +3875,8 @@ var ContextImpl = class ContextImpl {
3845
3875
  kvPrefixes: this.federation.kvPrefixes,
3846
3876
  queue: this.federation.inboxQueue,
3847
3877
  span,
3848
- tracerProvider: options.tracerProvider ?? this.tracerProvider
3878
+ tracerProvider: options.tracerProvider ?? this.tracerProvider,
3879
+ idempotencyStrategy: this.federation.idempotencyStrategy
3849
3880
  });
3850
3881
  return routeResult === "alreadyProcessed" || routeResult === "enqueued" || routeResult === "unsupportedActivity" || routeResult === "success";
3851
3882
  }
@@ -0,0 +1,26 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import "./type-Du-WE8NC.js";
7
+ import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "./middleware-lg47b3mK.js";
8
+ import "./semver-dArNLkR9.js";
9
+ import "./client-BM12q1DJ.js";
10
+ import "./lookup-B5jlZrQb.js";
11
+ import "./types-BIgY6c-l.js";
12
+ import "./actor-CL8lYYUx.js";
13
+ import "./key-B42BY6RL.js";
14
+ import "./http-DNkYeLxx.js";
15
+ import "./authdocloader-BlVoSqyh.js";
16
+ import "./ld-CMWQXDty.js";
17
+ import "./owner-Ch2ApIpq.js";
18
+ import "./proof-DaD7vIAi.js";
19
+ import "./inbox-FbqGLKha.js";
20
+ import "./builder-CqMKWEN0.js";
21
+ import "./collection-CSzG2j1P.js";
22
+ import "./keycache-BLtGOP6f.js";
23
+ import "./retry-D4GJ670a.js";
24
+ import "./send-DE79ptpc.js";
25
+
26
+ export { FederationImpl };
@@ -0,0 +1,17 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import "./transformers-BFT6d7J5.js";
6
+ import "./docloader-BggS4E4F.js";
7
+ import "./actor-CYnaKz6k.js";
8
+ import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "./middleware-CNAH05Vn.js";
9
+ import "./lookup-C-jJgyrW.js";
10
+ import "./key-BVNVEpXg.js";
11
+ import "./http-D53H7oqD.js";
12
+ import "./proof-Cge6SysA.js";
13
+ import "./types-ChEbJU3f.js";
14
+ import "./authdocloader-CRuH00Tu.js";
15
+ import "./vocab-Q8XBm9oV.js";
16
+
17
+ export { FederationImpl };