@fedify/fedify 2.5.0-dev.2687 → 2.5.0-dev.2710

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 (244) hide show
  1. package/dist/federation/mod.cjs +1 -1
  2. package/dist/federation/mod.js +1 -1
  3. package/dist/{federation-pFFwPyoZ.cjs → federation-JvzYDx0P.cjs} +3 -3
  4. package/dist/{http-CXX-QPzs.cjs → http-BG5cDmTS.cjs} +1 -1
  5. package/dist/{http-T7h9GBAN.js → http-MUf125Jc.js} +1 -1
  6. package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-A2po7h0_.cjs} +1 -1
  7. package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CbWc1BZA.js} +1 -1
  8. package/dist/{middleware-Bj91r7r2.js → middleware-DzzdJ7Wz.js} +3 -3
  9. package/dist/mod.cjs +4 -4
  10. package/dist/mod.js +4 -4
  11. package/dist/{portable-collection-Do5QA2oy.js → portable-collection-CAer9RWN.js} +1 -1
  12. package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
  13. package/dist/sig/mod.cjs +2 -2
  14. package/dist/sig/mod.js +2 -2
  15. package/dist/utils/mod.cjs +1 -1
  16. package/dist/utils/mod.js +1 -1
  17. package/package.json +22 -9
  18. package/skills/fedify/SKILL.md +10 -0
  19. package/dist/accept-CPVqki78.mjs +0 -145
  20. package/dist/activity-listener-CELFAodc.mjs +0 -44
  21. package/dist/assert-D1Eafmd_.mjs +0 -23
  22. package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
  23. package/dist/assert_exists-cffSpJ7X.mjs +0 -28
  24. package/dist/assert_false-CPdRnc3E.mjs +0 -23
  25. package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
  26. package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
  27. package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
  28. package/dist/assert_rejects-CTptdYck.mjs +0 -39
  29. package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
  30. package/dist/assert_throws-BYITOvPO.mjs +0 -74
  31. package/dist/assertion_error-B-cx0fFA.mjs +0 -31
  32. package/dist/audience-CHQ-FlLD.mjs +0 -95
  33. package/dist/builder-D1FP_5nQ.mjs +0 -911
  34. package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
  35. package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
  36. package/dist/client-5SIFzW3q.mjs +0 -441
  37. package/dist/codec-C6rTrpIp.mjs +0 -147
  38. package/dist/collection-CnnP1UAv.mjs +0 -44
  39. package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
  40. package/dist/compat/outgoing-jsonld.test.mjs +0 -257
  41. package/dist/compat/public-audience.test.d.mts +0 -2
  42. package/dist/compat/public-audience.test.mjs +0 -187
  43. package/dist/compat/secured-document.test.d.mts +0 -2
  44. package/dist/compat/secured-document.test.mjs +0 -58
  45. package/dist/compat/transformers.test.d.mts +0 -2
  46. package/dist/compat/transformers.test.mjs +0 -62
  47. package/dist/compound-proof-DSHhnOEW.mjs +0 -1019
  48. package/dist/context-LgGFFSz7.mjs +0 -146
  49. package/dist/deno-C50ikGBU.mjs +0 -8
  50. package/dist/dist-_geWsuaI.mjs +0 -189
  51. package/dist/docloader-BY-SEID0.mjs +0 -136
  52. package/dist/esm-BHXXx4Wx.mjs +0 -1233
  53. package/dist/exporter-DVG68ozH.mjs +0 -263
  54. package/dist/federation/audience.test.d.mts +0 -2
  55. package/dist/federation/audience.test.mjs +0 -130
  56. package/dist/federation/builder.test.d.mts +0 -2
  57. package/dist/federation/builder.test.mjs +0 -396
  58. package/dist/federation/circuit-breaker.test.d.mts +0 -2
  59. package/dist/federation/circuit-breaker.test.mjs +0 -1277
  60. package/dist/federation/collection.test.d.mts +0 -2
  61. package/dist/federation/collection.test.mjs +0 -21
  62. package/dist/federation/compound-fanout.test.d.mts +0 -2
  63. package/dist/federation/compound-fanout.test.mjs +0 -231
  64. package/dist/federation/handler-compound-proof.test.d.mts +0 -2
  65. package/dist/federation/handler-compound-proof.test.mjs +0 -384
  66. package/dist/federation/handler.test.d.mts +0 -2
  67. package/dist/federation/handler.test.mjs +0 -5445
  68. package/dist/federation/hashlink-media.test.d.mts +0 -2
  69. package/dist/federation/hashlink-media.test.mjs +0 -422
  70. package/dist/federation/idempotency.test.d.mts +0 -2
  71. package/dist/federation/idempotency.test.mjs +0 -207
  72. package/dist/federation/inbox-actorless.test.d.mts +0 -2
  73. package/dist/federation/inbox-actorless.test.mjs +0 -522
  74. package/dist/federation/inbox-authentication.test.d.mts +0 -2
  75. package/dist/federation/inbox-authentication.test.mjs +0 -220
  76. package/dist/federation/inbox-report.test.d.mts +0 -2
  77. package/dist/federation/inbox-report.test.mjs +0 -719
  78. package/dist/federation/inbox-view.test.d.mts +0 -2
  79. package/dist/federation/inbox-view.test.mjs +0 -369
  80. package/dist/federation/inbox.test.d.mts +0 -2
  81. package/dist/federation/inbox.test.mjs +0 -139
  82. package/dist/federation/keycache.test.d.mts +0 -2
  83. package/dist/federation/keycache.test.mjs +0 -337
  84. package/dist/federation/kv.test.d.mts +0 -2
  85. package/dist/federation/kv.test.mjs +0 -88
  86. package/dist/federation/metrics.test.d.mts +0 -2
  87. package/dist/federation/metrics.test.mjs +0 -634
  88. package/dist/federation/middleware.test.d.mts +0 -2
  89. package/dist/federation/middleware.test.mjs +0 -9314
  90. package/dist/federation/mq.test.d.mts +0 -2
  91. package/dist/federation/mq.test.mjs +0 -591
  92. package/dist/federation/negotiation.test.d.mts +0 -2
  93. package/dist/federation/negotiation.test.mjs +0 -18
  94. package/dist/federation/outbound-body.test.d.mts +0 -2
  95. package/dist/federation/outbound-body.test.mjs +0 -149
  96. package/dist/federation/outbound-capture.test.d.mts +0 -2
  97. package/dist/federation/outbound-capture.test.mjs +0 -394
  98. package/dist/federation/outbound-dispatch.test.d.mts +0 -2
  99. package/dist/federation/outbound-dispatch.test.mjs +0 -368
  100. package/dist/federation/outbound-document.test.d.mts +0 -2
  101. package/dist/federation/outbound-document.test.mjs +0 -171
  102. package/dist/federation/outbound-provenance.test.d.mts +0 -2
  103. package/dist/federation/outbound-provenance.test.mjs +0 -543
  104. package/dist/federation/outbound-report.test.d.mts +0 -2
  105. package/dist/federation/outbound-report.test.mjs +0 -5475
  106. package/dist/federation/outbound-workers.test.d.mts +0 -2
  107. package/dist/federation/outbound-workers.test.mjs +0 -64
  108. package/dist/federation/outbound-workflow.test.d.mts +0 -2
  109. package/dist/federation/outbound-workflow.test.mjs +0 -154
  110. package/dist/federation/outgoing-proof.test.d.mts +0 -2
  111. package/dist/federation/outgoing-proof.test.mjs +0 -933
  112. package/dist/federation/portable-actor.test.d.mts +0 -2
  113. package/dist/federation/portable-actor.test.mjs +0 -496
  114. package/dist/federation/portable-chain.test.d.mts +0 -2
  115. package/dist/federation/portable-chain.test.mjs +0 -370
  116. package/dist/federation/portable-collection.test.d.mts +0 -2
  117. package/dist/federation/portable-collection.test.mjs +0 -832
  118. package/dist/federation/portable-delivery.test.d.mts +0 -2
  119. package/dist/federation/portable-delivery.test.mjs +0 -845
  120. package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
  121. package/dist/federation/portable-gateway-keys.test.mjs +0 -692
  122. package/dist/federation/portable-inbox.test.d.mts +0 -2
  123. package/dist/federation/portable-inbox.test.mjs +0 -1960
  124. package/dist/federation/portable-parse-uri.test.d.mts +0 -2
  125. package/dist/federation/portable-parse-uri.test.mjs +0 -348
  126. package/dist/federation/portable-route-activity.test.d.mts +0 -2
  127. package/dist/federation/portable-route-activity.test.mjs +0 -259
  128. package/dist/federation/portable.test.d.mts +0 -2
  129. package/dist/federation/portable.test.mjs +0 -1072
  130. package/dist/federation/retry.test.d.mts +0 -2
  131. package/dist/federation/retry.test.mjs +0 -42
  132. package/dist/federation/router.test.d.mts +0 -2
  133. package/dist/federation/router.test.mjs +0 -123
  134. package/dist/federation/send.test.d.mts +0 -2
  135. package/dist/federation/send.test.mjs +0 -1421
  136. package/dist/federation/tasks/codec.test.d.mts +0 -2
  137. package/dist/federation/tasks/codec.test.mjs +0 -302
  138. package/dist/federation/tasks/enqueue.test.d.mts +0 -2
  139. package/dist/federation/tasks/enqueue.test.mjs +0 -1095
  140. package/dist/federation/tasks/tasks.test.d.mts +0 -2
  141. package/dist/federation/tasks/tasks.test.mjs +0 -1229
  142. package/dist/federation/temporal.test.d.mts +0 -2
  143. package/dist/federation/temporal.test.mjs +0 -71
  144. package/dist/federation/webfinger.test.d.mts +0 -2
  145. package/dist/federation/webfinger.test.mjs +0 -944
  146. package/dist/http-BXbQQZDM.mjs +0 -1449
  147. package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
  148. package/dist/inbox-cS97XzOD.mjs +0 -399
  149. package/dist/inbox-view-D-d0Ar6o.mjs +0 -385
  150. package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
  151. package/dist/keycache-N2opu4-3.mjs +0 -221
  152. package/dist/keys-DIJNHW-Y.mjs +0 -120
  153. package/dist/kv-DBRWVx3Q.mjs +0 -104
  154. package/dist/kv-DCHkaJ9-.mjs +0 -92
  155. package/dist/kv-cache-fgbLHGVL.mjs +0 -121
  156. package/dist/ld-BpkhkDGj.mjs +0 -1752
  157. package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
  158. package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
  159. package/dist/metrics-Uqf8GomB.mjs +0 -818
  160. package/dist/middleware-DcXzz-YK.mjs +0 -9971
  161. package/dist/middleware-DgwZkvJR.mjs +0 -5
  162. package/dist/mq-eF96QxUT.mjs +0 -288
  163. package/dist/negotiation-BAKO9nih.mjs +0 -96
  164. package/dist/nodeinfo/client.test.d.mts +0 -2
  165. package/dist/nodeinfo/client.test.mjs +0 -1364
  166. package/dist/nodeinfo/handler.test.d.mts +0 -2
  167. package/dist/nodeinfo/handler.test.mjs +0 -94
  168. package/dist/nodeinfo/types.test.d.mts +0 -2
  169. package/dist/nodeinfo/types.test.mjs +0 -192
  170. package/dist/otel/exporter.test.d.mts +0 -2
  171. package/dist/otel/exporter.test.mjs +0 -887
  172. package/dist/outbound-body-CckPA5gc.mjs +0 -83
  173. package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
  174. package/dist/outbound-document-BMgwLXTY.mjs +0 -179
  175. package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
  176. package/dist/owner-BVenIFg1.mjs +0 -267
  177. package/dist/portable-collection-DIk9gpjL.mjs +0 -418
  178. package/dist/portable-key-C7pVaHNR.mjs +0 -549
  179. package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
  180. package/dist/proof-BlfZ95--.mjs +0 -1420
  181. package/dist/public-audience--klBIOk1.mjs +0 -197
  182. package/dist/retry-zX5xw5e0.mjs +0 -34
  183. package/dist/router-u5O5KCQr.mjs +0 -156
  184. package/dist/secured-document-CxzZZ9nL.mjs +0 -35
  185. package/dist/send-DEGHPGFk.mjs +0 -710
  186. package/dist/sig/accept.test.d.mts +0 -2
  187. package/dist/sig/accept.test.mjs +0 -416
  188. package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
  189. package/dist/sig/compound-proof-discovery.test.mjs +0 -331
  190. package/dist/sig/compound-proof-producer.test.d.mts +0 -2
  191. package/dist/sig/compound-proof-producer.test.mjs +0 -107
  192. package/dist/sig/compound-proof-verification.test.d.mts +0 -2
  193. package/dist/sig/compound-proof-verification.test.mjs +0 -1017
  194. package/dist/sig/compound-proof.test.d.mts +0 -2
  195. package/dist/sig/compound-proof.test.mjs +0 -411
  196. package/dist/sig/http.test.d.mts +0 -2
  197. package/dist/sig/http.test.mjs +0 -3328
  198. package/dist/sig/key-owner-evidence.test.d.mts +0 -2
  199. package/dist/sig/key-owner-evidence.test.mjs +0 -100
  200. package/dist/sig/key.test.d.mts +0 -2
  201. package/dist/sig/key.test.mjs +0 -1250
  202. package/dist/sig/ld.test.d.mts +0 -2
  203. package/dist/sig/ld.test.mjs +0 -1044
  204. package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
  205. package/dist/sig/mitra-receive-interop.test.mjs +0 -260
  206. package/dist/sig/mitra-send-interop.test.d.mts +0 -2
  207. package/dist/sig/mitra-send-interop.test.mjs +0 -461
  208. package/dist/sig/owner.test.d.mts +0 -2
  209. package/dist/sig/owner.test.mjs +0 -202
  210. package/dist/sig/portable-collection.test.d.mts +0 -2
  211. package/dist/sig/portable-collection.test.mjs +0 -697
  212. package/dist/sig/portable-interop.test.d.mts +0 -2
  213. package/dist/sig/portable-interop.test.mjs +0 -156
  214. package/dist/sig/portable-key-id.test.d.mts +0 -2
  215. package/dist/sig/portable-key-id.test.mjs +0 -67
  216. package/dist/sig/portable-key.test.d.mts +0 -2
  217. package/dist/sig/portable-key.test.mjs +0 -1438
  218. package/dist/sig/proof.test.d.mts +0 -2
  219. package/dist/sig/proof.test.mjs +0 -2638
  220. package/dist/sig/tootik-request-interop.test.d.mts +0 -2
  221. package/dist/sig/tootik-request-interop.test.mjs +0 -190
  222. package/dist/sig/tootik-send-interop.test.d.mts +0 -2
  223. package/dist/sig/tootik-send-interop.test.mjs +0 -331
  224. package/dist/sig/verification.test.d.mts +0 -2
  225. package/dist/sig/verification.test.mjs +0 -310
  226. package/dist/std__assert-DvMDRPes.mjs +0 -8
  227. package/dist/tasks-BCUmQbbz.mjs +0 -77
  228. package/dist/temporal-B4oQ8HpW.mjs +0 -95
  229. package/dist/testing/context.test.d.mts +0 -2
  230. package/dist/testing/context.test.mjs +0 -19
  231. package/dist/testing/kv.test.d.mts +0 -2
  232. package/dist/testing/kv.test.mjs +0 -101
  233. package/dist/testing/mod.d.mts +0 -6099
  234. package/dist/testing/mod.mjs +0 -9
  235. package/dist/testing-vrnD5Uaa.mjs +0 -8
  236. package/dist/types-DE_LV1JB.mjs +0 -46
  237. package/dist/utils/docloader.test.d.mts +0 -2
  238. package/dist/utils/docloader.test.mjs +0 -1076
  239. package/dist/utils/kv-cache.test.d.mts +0 -2
  240. package/dist/utils/kv-cache.test.mjs +0 -261
  241. package/dist/verification-C3954hQh.mjs +0 -5
  242. package/dist/verification-Dpfcw8ml.mjs +0 -105
  243. package/dist/vocab/cjs.test.d.mts +0 -2
  244. package/dist/vocab/cjs.test.mjs +0 -27
@@ -1,710 +0,0 @@
1
- import "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { d as isPortableUri } from "./portable-key-id-Ca30-hOa.mjs";
5
- import { n as version, t as name } from "./deno-C50ikGBU.mjs";
6
- import { n as getDurationMs, r as getFederationMetrics } from "./metrics-Uqf8GomB.mjs";
7
- import { r as doubleKnockScoped } from "./http-BXbQQZDM.mjs";
8
- import { t as ResponseBodyPump } from "./outbound-body-CckPA5gc.mjs";
9
- import { r as takeCapturedDiagnostic } from "./outbound-capture-DVgnRzlf.mjs";
10
- import { getLogger, withContext } from "@logtape/logtape";
11
- import { SpanKind, SpanStatusCode, context, trace } from "@opentelemetry/api";
12
- import { FetchError, UrlError, canonicalizePortableUri, getFe34Origin, isGatewayUrl, toCompatibleEf61Id } from "@fedify/vocab-runtime";
13
- import { getPortableGatewayCandidates } from "@fedify/vocab-runtime/internal/portable-dereference";
14
- import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
15
- /**
16
- * Resolves a portable inbox, i.e., an `ap:` or `ap+ef61:` URI, to
17
- * the compatible identifiers of the inbox on the recipient's gateways.
18
- *
19
- * The gateways are taken from the recipient's `gateways`, or, if it has no
20
- * valid gateway, from the `@gateway` location hints of the inbox URI. Both
21
- * come from the recipient object, so they are as trustworthy as its inbox.
22
- * Gateways whose origins are in `excludeBaseUris` are skipped.
23
- * @param recipient The recipient that owns the inbox.
24
- * @param inbox The portable inbox.
25
- * @param excludeBaseUris The base URIs whose origins are not delivered to.
26
- * @returns The delivery target, or `null` if the inbox is malformed, or no
27
- * gateway is left to deliver through.
28
- */
29
- function resolvePortableDeliveryTarget(recipient, inbox, excludeBaseUris) {
30
- const logger = getLogger([
31
- "fedify",
32
- "federation",
33
- "outbox"
34
- ]);
35
- let portableInbox;
36
- try {
37
- portableInbox = canonicalizePortableUri(inbox.href);
38
- } catch (error) {
39
- if (!(error instanceof TypeError)) throw error;
40
- logger.warn("Skipping the recipient {recipient}, as its portable inbox {inbox} is malformed.", {
41
- recipient: recipient.id?.href,
42
- inbox: inbox.href,
43
- error
44
- });
45
- return null;
46
- }
47
- let gateways = (recipient.gateways ?? []).filter(isGatewayUrl);
48
- if (gateways.length < 1) gateways = getPortableGatewayCandidates(inbox);
49
- if (gateways.length < 1) {
50
- logger.warn("Skipping the recipient {recipient}, as it has no gateway to deliver to its portable inbox {inbox} through.", {
51
- recipient: recipient.id?.href,
52
- inbox: portableInbox
53
- });
54
- return null;
55
- }
56
- const excludedOrigins = new Set(excludeBaseUris?.map((u) => u.origin));
57
- const seen = /* @__PURE__ */ new Set();
58
- const inboxes = [];
59
- for (const gateway of gateways) {
60
- if (inboxes.length >= 5) break;
61
- if (seen.has(gateway.origin)) continue;
62
- seen.add(gateway.origin);
63
- if (excludedOrigins.has(gateway.origin)) continue;
64
- try {
65
- inboxes.push(toCompatibleEf61Id(inbox, gateway.origin));
66
- } catch (error) {
67
- if (!(error instanceof TypeError)) throw error;
68
- logger.warn("Cannot deliver to the portable inbox {inbox} through the gateway {gateway}, as the inbox cannot be represented as its compatible identifier.", {
69
- inbox: portableInbox,
70
- gateway: gateway.origin,
71
- error
72
- });
73
- }
74
- }
75
- if (inboxes.length < 1) {
76
- logger.debug("Skipping the recipient {recipient}, as no gateway is left to deliver to its portable inbox {inbox} through.", {
77
- recipient: recipient.id?.href,
78
- inbox: portableInbox
79
- });
80
- return null;
81
- }
82
- return {
83
- portableInbox,
84
- inboxes
85
- };
86
- }
87
- /**
88
- * Merges two ordered lists of compatible inbox URLs, keeping the first URL
89
- * for each gateway origin and at most {@link MAX_DELIVERY_GATEWAYS} URLs.
90
- * @param a The preferred list.
91
- * @param b The other list.
92
- * @returns The merged list.
93
- */
94
- function mergeGatewayInboxes(a, b) {
95
- const seen = /* @__PURE__ */ new Set();
96
- const merged = [];
97
- for (const inbox of [...a, ...b]) {
98
- if (merged.length >= 5) break;
99
- const { origin } = new URL(inbox);
100
- if (seen.has(origin)) continue;
101
- seen.add(origin);
102
- merged.push(inbox);
103
- }
104
- return merged;
105
- }
106
- /**
107
- * Gets the part of a delivery's ordering key that tells its destination
108
- * apart: the DID of a portable inbox, so that deliveries to it stay in order
109
- * whichever gateway they go through, or the origin of any other inbox.
110
- * @param inbox The inbox URL.
111
- * @param portableInbox The canonical portable inbox, if the inbox is
112
- * the compatible identifier of one.
113
- * @returns The destination part of the ordering key.
114
- */
115
- function getOrderingDestination(inbox, portableInbox) {
116
- return portableInbox == null ? new URL(inbox).origin : getFe34Origin(portableInbox);
117
- }
118
- //#endregion
119
- //#region src/federation/send.ts
120
- /**
121
- * Extracts the inbox URLs from recipients.
122
- *
123
- * An [FEP-ef61] portable inbox, i.e., an `ap:` or `ap+ef61:` URI, is resolved
124
- * to its compatible identifiers on the recipient's gateways, or, if the
125
- * recipient has no valid gateway, on the gateways in the `@gateway` location
126
- * hints of the inbox URI. The inbox is keyed by the compatible identifier on
127
- * the first gateway, and the others are listed in
128
- * {@link ExtractedInbox.gatewayInboxes}. A recipient whose portable inbox
129
- * has no gateway to deliver through is skipped. The shared inbox of
130
- * a recipient with a portable inbox is never preferred, since only a portable
131
- * inbox is synchronized between the gateways.
132
- *
133
- * [FEP-ef61]: https://w3id.org/fep/ef61
134
- * @param parameters The parameters to extract the inboxes.
135
- * See also {@link ExtractInboxesParameters}.
136
- * @returns The inboxes as a map of inbox URL to actor URIs.
137
- */
138
- function extractInboxes({ recipients, preferSharedInbox, excludeBaseUris }) {
139
- const inboxes = {};
140
- const portableKeys = /* @__PURE__ */ new Map();
141
- const compatibleKeys = /* @__PURE__ */ new Map();
142
- for (const recipient of recipients) {
143
- if (recipient.id == null) continue;
144
- let inbox;
145
- let sharedInbox = false;
146
- if (preferSharedInbox && recipient.endpoints?.sharedInbox != null && (recipient.inboxId == null || !isPortableUri(recipient.inboxId))) {
147
- inbox = recipient.endpoints.sharedInbox;
148
- sharedInbox = true;
149
- } else inbox = recipient.inboxId;
150
- if (inbox == null) continue;
151
- if (isPortableUri(inbox)) {
152
- const target = resolvePortableDeliveryTarget(recipient, inbox, excludeBaseUris);
153
- if (target == null) continue;
154
- const gatewayInboxes = target.inboxes.map((u) => u.href);
155
- const existingKeys = /* @__PURE__ */ new Set();
156
- const portableKey = portableKeys.get(target.portableInbox);
157
- if (portableKey != null) existingKeys.add(portableKey);
158
- for (const i of gatewayInboxes) {
159
- const k = compatibleKeys.get(i) ?? i;
160
- if (Object.hasOwn(inboxes, k)) existingKeys.add(k);
161
- }
162
- const [key = gatewayInboxes[0], ...otherKeys] = existingKeys;
163
- portableKeys.set(target.portableInbox, key);
164
- const entry = inboxes[key] ??= {
165
- actorIds: /* @__PURE__ */ new Set(),
166
- sharedInbox
167
- };
168
- for (const k of otherKeys) {
169
- for (const actorId of inboxes[k].actorIds) entry.actorIds.add(actorId);
170
- delete inboxes[k];
171
- }
172
- entry.sharedInbox = false;
173
- entry.portableInbox = target.portableInbox;
174
- entry.gatewayInboxes = mergeGatewayInboxes(entry.gatewayInboxes ?? [key], gatewayInboxes);
175
- for (const i of entry.gatewayInboxes) compatibleKeys.set(i, key);
176
- entry.actorIds.add(recipient.id.href);
177
- continue;
178
- }
179
- if (excludeBaseUris != null && excludeBaseUris.some((u) => u.origin === inbox?.origin)) continue;
180
- const key = compatibleKeys.get(inbox.href) ?? inbox.href;
181
- inboxes[key] ??= {
182
- actorIds: /* @__PURE__ */ new Set(),
183
- sharedInbox
184
- };
185
- inboxes[key].actorIds.add(recipient.id.href);
186
- }
187
- return inboxes;
188
- }
189
- /**
190
- * Sends an {@link Activity} to an inbox.
191
- *
192
- * @param parameters The parameters for sending the activity.
193
- * See also {@link SendActivityParameters}.
194
- * @param deps The dependencies, for tests.
195
- * @throws {Error} If the activity fails to send.
196
- */
197
- function sendActivity(options, deps = {}) {
198
- options.attemptStarted?.(options.inbox.href);
199
- const attempt = options.observation?.startAttempt(options.inbox.href);
200
- const parentSpanContext = trace.getSpanContext(context.active());
201
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
202
- return tracerProvider.getTracer(name, version).startActiveSpan("activitypub.send_activity", {
203
- kind: SpanKind.CLIENT,
204
- attributes: { "activitypub.shared_inbox": options.sharedInbox ?? false }
205
- }, async (span) => {
206
- attempt?.setSpan(span, parentSpanContext);
207
- if (options.activityId != null) span.setAttribute("activitypub.activity.id", options.activityId);
208
- if (options.activityType != null) span.setAttribute("activitypub.activity.type", options.activityType);
209
- const spanContext = span.spanContext();
210
- try {
211
- await withContext({
212
- traceId: spanContext.traceId,
213
- spanId: spanContext.spanId
214
- }, () => sendActivityInternal({
215
- ...options,
216
- tracerProvider
217
- }, span, deps, attempt));
218
- await attempt?.succeeded();
219
- } catch (e) {
220
- span.setStatus({
221
- code: SpanStatusCode.ERROR,
222
- message: String(e)
223
- });
224
- await attempt?.failed(e);
225
- throw e;
226
- } finally {
227
- span.end();
228
- }
229
- });
230
- }
231
- /**
232
- * Sends an activity to the first of the given inboxes that accepts it, i.e.,
233
- * the compatible identifiers of a portable inbox on its gateways, trying them
234
- * one after another.
235
- * @param parameters The parameters, except for the inbox.
236
- * @param inboxes The inboxes to try, in order. Must not be empty.
237
- * @throws {Error} The error of the last inbox if no inbox accepts it.
238
- */
239
- async function sendActivityThroughGateways(parameters, inboxes) {
240
- const logger = getLogger([
241
- "fedify",
242
- "federation",
243
- "outbox"
244
- ]);
245
- let lastError;
246
- for (const [i, inbox] of inboxes.entries()) try {
247
- await sendActivity({
248
- ...parameters,
249
- inbox
250
- });
251
- return;
252
- } catch (error) {
253
- lastError = error;
254
- if (i < inboxes.length - 1) logger.warn("Failed to send activity {activityId} to {inbox}; trying the next gateway {next}:\n{error}", {
255
- activityId: parameters.activityId,
256
- inbox: inbox.href,
257
- next: inboxes[i + 1].href,
258
- error
259
- });
260
- }
261
- throw lastError;
262
- }
263
- const MAX_ERROR_RESPONSE_BODY_BYTES = 1024;
264
- const ERROR_RESPONSE_BODY_TIMEOUT_MS = 1e3;
265
- function getActivityActorId(activity) {
266
- if (!isRecord(activity)) return void 0;
267
- return getIdValue(activity.actor);
268
- }
269
- function getIdValue(value) {
270
- if (typeof value === "string" && value !== "") return value;
271
- if (value instanceof URL) return value.href;
272
- if (Array.isArray(value)) {
273
- for (const item of value) {
274
- const id = getIdValue(item);
275
- if (id != null) return id;
276
- }
277
- return;
278
- }
279
- if (isRecord(value)) return getIdValue(value.id);
280
- }
281
- function isRecord(value) {
282
- return typeof value === "object" && value != null;
283
- }
284
- async function readLimitedResponseBody(response, maxBytes) {
285
- const captured = takeCapturedDiagnostic(response);
286
- if (captured !== void 0) return captured;
287
- if (response.body == null) return "";
288
- const pump = new ResponseBodyPump(response.body, ERROR_RESPONSE_BODY_TIMEOUT_MS);
289
- const decoder = new TextDecoder();
290
- const chunks = [];
291
- let totalBytes = 0;
292
- let truncated = false;
293
- let timedOut = false;
294
- try {
295
- while (true) {
296
- const result = await pump.read();
297
- if (result == null) {
298
- timedOut = true;
299
- break;
300
- }
301
- const { done, value } = result;
302
- if (done) break;
303
- if (value.length === 0) continue;
304
- if (totalBytes + value.length > maxBytes) {
305
- const remaining = maxBytes - totalBytes;
306
- if (remaining > 0) chunks.push(decoder.decode(value.slice(0, remaining), { stream: true }));
307
- truncated = true;
308
- break;
309
- }
310
- chunks.push(decoder.decode(value, { stream: true }));
311
- totalBytes += value.length;
312
- }
313
- } finally {
314
- pump.close();
315
- }
316
- let result = chunks.join("");
317
- if (truncated) result += "… (truncated)";
318
- else if (timedOut) result += "… (timed out)";
319
- return result;
320
- }
321
- async function sendActivityInternal({ activity, activityId, activityType, keys, inbox, allowPrivateAddress, headers, specDeterminer, meterProvider, tracerProvider }, span, deps, attempt) {
322
- const logger = getLogger([
323
- "fedify",
324
- "federation",
325
- "outbox"
326
- ]);
327
- const federationMetrics = getFederationMetrics(meterProvider);
328
- const started = performance.now();
329
- let deliverySuccess = false;
330
- const openUnvalidatedHop = deps.openHop ?? (allowPrivateAddress ? openDirectFetch : (url) => openPublicFetch(url));
331
- async function openHop(url) {
332
- let session;
333
- try {
334
- session = await openUnvalidatedHop(url);
335
- } catch (error) {
336
- if (error instanceof UrlError && error.reason === "dns") {
337
- attempt?.failure({
338
- kind: "transport",
339
- phase: "validation",
340
- error
341
- });
342
- logger.error("DNS resolution failed for URL: {url}", {
343
- url,
344
- error
345
- });
346
- const failure = new FetchError(url, error.message);
347
- failure.cause = error;
348
- throw failure;
349
- }
350
- if (error instanceof UrlError) {
351
- if (error.reason === "disallowed") attempt?.failure({
352
- kind: "policy",
353
- phase: "validation",
354
- error
355
- });
356
- logger.error("Disallowed private URL: {url}", {
357
- url,
358
- error
359
- });
360
- }
361
- throw error;
362
- }
363
- if (attempt == null) return session;
364
- return {
365
- url: session.url,
366
- async fetch(input, init) {
367
- try {
368
- return await session.fetch(input, init);
369
- } catch (error) {
370
- attempt.failure({
371
- kind: "transport",
372
- phase: "request",
373
- error
374
- });
375
- throw error;
376
- }
377
- },
378
- async close() {
379
- try {
380
- await session.close();
381
- } catch (error) {
382
- attempt.failure({
383
- kind: "local",
384
- phase: "cleanup",
385
- error
386
- });
387
- throw error;
388
- }
389
- }
390
- };
391
- }
392
- let initialSession;
393
- try {
394
- initialSession = await openHop(inbox.href);
395
- } catch (error) {
396
- if (error instanceof FetchError) federationMetrics.recordDelivery(inbox, getDurationMs(started), false, activityType);
397
- throw error;
398
- }
399
- let initialPending = true;
400
- const openDeliveryHop = (url) => {
401
- if (initialPending) {
402
- initialPending = false;
403
- return Promise.resolve(initialSession);
404
- }
405
- return openHop(url);
406
- };
407
- try {
408
- let request;
409
- let body;
410
- try {
411
- headers = new Headers(headers);
412
- headers.set("Content-Type", "application/activity+json");
413
- } catch (error) {
414
- attempt?.failure({
415
- kind: "local",
416
- phase: "request-preparation",
417
- error
418
- });
419
- throw error;
420
- }
421
- try {
422
- attempt?.snapshotSenderPayload(activity);
423
- body = JSON.stringify(activity);
424
- } catch (error) {
425
- attempt?.failure({
426
- kind: "local",
427
- phase: "serialization",
428
- error
429
- });
430
- throw error;
431
- }
432
- try {
433
- request = new Request(inbox, {
434
- method: "POST",
435
- headers,
436
- body,
437
- redirect: "manual"
438
- });
439
- } catch (error) {
440
- attempt?.failure({
441
- kind: "local",
442
- phase: "request-preparation",
443
- error
444
- });
445
- throw error;
446
- }
447
- let rsaKey = null;
448
- for (const key of keys) if (key.privateKey.algorithm.name === "RSASSA-PKCS1-v1_5") {
449
- rsaKey = key;
450
- break;
451
- }
452
- if (rsaKey == null && keys.length < 1) logger.debug("Sending the activity {activityId} to {inbox} without a signature.", {
453
- activityId,
454
- inbox: inbox.href
455
- });
456
- else if (rsaKey == null) logger.warn("No supported key found to sign the request to {inbox}. The request will be sent without a signature. In order to sign the request, at least one RSASSA-PKCS1-v1_5 key must be provided.", {
457
- inbox: inbox.href,
458
- keys: keys.map((pair) => ({
459
- keyId: pair.keyId.href,
460
- privateKey: pair.privateKey
461
- }))
462
- });
463
- const consume = (response) => {
464
- return consumeSendActivityResponse(response, inbox);
465
- };
466
- let outcome;
467
- try {
468
- outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openDeliveryHop, consume, attempt) : await doubleKnockScoped(request, rsaKey, {
469
- tracerProvider,
470
- specDeterminer
471
- }, openDeliveryHop, consume, attempt == null ? void 0 : {
472
- fetch: (request, submit) => attempt.fetch(request, submit),
473
- response: (response, disposition) => attempt.response(response, disposition),
474
- error: (phase, error) => attempt.failure({
475
- kind: "local",
476
- phase,
477
- error
478
- })
479
- });
480
- } catch (error) {
481
- attempt?.unknown(error);
482
- const failure = error instanceof FetchError || error instanceof UrlError ? error : createFetchError(inbox.href, error);
483
- logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
484
- activityId,
485
- inbox: inbox.href,
486
- error: failure
487
- });
488
- federationMetrics.recordDelivery(inbox, getDurationMs(started), false, activityType);
489
- throw failure;
490
- }
491
- try {
492
- if (!outcome.ok) {
493
- const { status, statusText, error, responseHeaders } = outcome;
494
- logger.error("Failed to send activity {activityId} to {inbox} ({status} {statusText}):\n{error}", {
495
- activityId,
496
- inbox: inbox.href,
497
- status,
498
- statusText,
499
- error
500
- });
501
- const failure = new SendActivityError(inbox, status, `Failed to send activity ${activityId} to ${inbox.href} (${status} ${statusText}):\n${error}`, error, responseHeaders);
502
- attempt?.failure({
503
- kind: "http",
504
- phase: "response",
505
- error: failure
506
- });
507
- throw failure;
508
- }
509
- deliverySuccess = true;
510
- const eventAttributes = {
511
- "activitypub.inbox.url": inbox.href,
512
- "activitypub.activity.id": activityId ?? ""
513
- };
514
- if (activityType != null) eventAttributes["activitypub.activity.type"] = activityType;
515
- const actorId = getActivityActorId(activity);
516
- if (actorId != null) eventAttributes["activitypub.actor.id"] = actorId;
517
- span.addEvent("activitypub.activity.sent", eventAttributes);
518
- } finally {
519
- federationMetrics.recordDelivery(inbox, getDurationMs(started), deliverySuccess, activityType);
520
- }
521
- } finally {
522
- if (initialPending) await initialSession.close();
523
- }
524
- }
525
- function createFetchError(url, cause) {
526
- const error = new FetchError(url, cause instanceof Error ? cause.message : String(cause));
527
- error.cause = cause;
528
- return error;
529
- }
530
- /**
531
- * Starts cancelling the body of a response without waiting for it to settle.
532
- * The cancellation of a branch of a tee (e.g., a body cloned by a fetch mock)
533
- * settles only after the other branch is cancelled too, per the Streams
534
- * standard, so awaiting it could block forever. Failures are only logged.
535
- */
536
- function cancelResponseBody(response, url) {
537
- response.body?.cancel().catch((error) => {
538
- getLogger([
539
- "fedify",
540
- "federation",
541
- "outbox"
542
- ]).debug("Failed to cancel the response body from {url}: {error}", {
543
- url,
544
- error
545
- });
546
- });
547
- }
548
- /**
549
- * Reads what is needed from the final response of a delivery while its
550
- * session is open: the body of a successful response is cancelled, and at
551
- * most 1 KiB of an error response body is read within its diagnostic budget.
552
- */
553
- async function consumeSendActivityResponse(response, inbox) {
554
- if (response.ok) {
555
- cancelResponseBody(response, response.url || inbox.href);
556
- return { ok: true };
557
- }
558
- let error;
559
- try {
560
- error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES);
561
- } catch (_) {
562
- error = "";
563
- }
564
- return {
565
- ok: false,
566
- status: response.status,
567
- statusText: response.statusText,
568
- error,
569
- responseHeaders: new Headers(response.headers)
570
- };
571
- }
572
- /**
573
- * Sends a request without signing it, following redirects manually like the
574
- * Fetch standard does. Every hop is opened with `openHop()`, which validates
575
- * the destination, after the previous hop is closed. The final response is
576
- * passed to `consume()`, and its session is closed after that.
577
- * This is exported only for tests; it is not exported from any entry point.
578
- * @param request The request to send.
579
- * @param openHop The function to open a session for each hop.
580
- * @param consume The function to consume the final response.
581
- * @param attempt The in-process attempt observation, if registered.
582
- * @returns The value returned by `consume`.
583
- */
584
- async function fetchWithValidatedRedirects(request, openHop, consume, attempt) {
585
- const logger = getLogger([
586
- "fedify",
587
- "federation",
588
- "outbox"
589
- ]);
590
- let body = await request.clone().text();
591
- for (let redirects = 0;; redirects++) {
592
- const session = await openHop(request.url);
593
- let response;
594
- try {
595
- response = await (attempt == null ? session.fetch(request, { redirect: "manual" }) : attempt.fetch(request, () => session.fetch(request, { redirect: "manual" })));
596
- } catch (error) {
597
- await closeAfterError(session, logger);
598
- throw error;
599
- }
600
- const location = response.headers.get("Location");
601
- if (![
602
- 301,
603
- 302,
604
- 303,
605
- 307,
606
- 308
607
- ].includes(response.status) || location == null) {
608
- attempt?.response(response, "final");
609
- try {
610
- return await consume(response);
611
- } catch (error) {
612
- logger.debug("Failed to consume the response from {url}; closing the session: {error}", {
613
- url: request.url,
614
- error
615
- });
616
- throw error;
617
- } finally {
618
- await session.close();
619
- }
620
- }
621
- attempt?.response(response, "intermediate");
622
- cancelResponseBody(response, request.url);
623
- await session.close();
624
- if (redirects >= 20) throw new TypeError("Too many redirects");
625
- const url = new URL(location, request.url);
626
- const headers = new Headers(request.headers);
627
- if (url.origin !== new URL(request.url).origin) {
628
- headers.delete("Authorization");
629
- headers.delete("Proxy-Authorization");
630
- headers.delete("Cookie");
631
- headers.delete("Host");
632
- }
633
- let method = request.method;
634
- if ((response.status === 301 || response.status === 302) && method === "POST" || response.status === 303 && method !== "GET" && method !== "HEAD") {
635
- method = "GET";
636
- body = void 0;
637
- for (const name of [
638
- "Content-Encoding",
639
- "Content-Language",
640
- "Content-Length",
641
- "Content-Location",
642
- "Content-Type"
643
- ]) headers.delete(name);
644
- }
645
- request = new Request(url, {
646
- method,
647
- headers,
648
- body,
649
- redirect: "manual"
650
- });
651
- }
652
- }
653
- async function closeAfterError(session, logger) {
654
- try {
655
- await session.close();
656
- } catch (error) {
657
- logger.debug("Failed to close the session for {url}: {error}", {
658
- url: session.url.href,
659
- error
660
- });
661
- }
662
- }
663
- /**
664
- * An error that is thrown when an activity fails to send to a remote inbox.
665
- * It contains structured information about the failure, including the HTTP
666
- * status code, the inbox URL, and the response body.
667
- * @since 2.0.0
668
- */
669
- var SendActivityError = class extends Error {
670
- /**
671
- * The inbox URL that the activity was being sent to.
672
- */
673
- inbox;
674
- /**
675
- * The HTTP status code returned by the inbox.
676
- */
677
- statusCode;
678
- /**
679
- * The response body from the inbox, if any. Note that this may be
680
- * truncated to a maximum of 1 KiB to prevent excessive memory consumption
681
- * when remote servers return large error pages (e.g., Cloudflare error pages).
682
- * If truncated, the string will end with `"… (truncated)"`. Diagnostic reading
683
- * has a separate one-second budget; a deadline retains any partial preview and
684
- * appends `"… (timed out)"`. This is independent of application body capture.
685
- */
686
- responseBody;
687
- /**
688
- * The response headers from the inbox.
689
- * @since 2.3.0
690
- */
691
- responseHeaders;
692
- /**
693
- * Creates a new {@link SendActivityError}.
694
- * @param inbox The inbox URL.
695
- * @param statusCode The HTTP status code.
696
- * @param message The error message.
697
- * @param responseBody The response body.
698
- * @param responseHeaders The response headers.
699
- */
700
- constructor(inbox, statusCode, message, responseBody, responseHeaders) {
701
- super(message);
702
- this.name = "SendActivityError";
703
- this.inbox = inbox;
704
- this.statusCode = statusCode;
705
- this.responseBody = responseBody;
706
- this.responseHeaders = new Headers(responseHeaders);
707
- }
708
- };
709
- //#endregion
710
- export { sendActivityThroughGateways as a, sendActivity as i, extractInboxes as n, getOrderingDestination as o, fetchWithValidatedRedirects as r, SendActivityError as t };
@@ -1,2 +0,0 @@
1
- import { Temporal } from "temporal-polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";