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

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-C0zalE9W.cjs} +8 -3
  4. package/dist/{http-T7h9GBAN.js → http-BC5Bd3-E.js} +1 -1
  5. package/dist/{http-CXX-QPzs.cjs → http-Dqzgc4Rj.cjs} +1 -1
  6. package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CQ0u0Ry0.js} +1 -1
  7. package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-ihEHdx1v.cjs} +1 -1
  8. package/dist/{middleware-Bj91r7r2.js → middleware-Bgm3A90j.js} +8 -3
  9. package/dist/mod.cjs +4 -4
  10. package/dist/mod.js +4 -4
  11. package/dist/{portable-collection-Do5QA2oy.js → portable-collection-DZ_XqNUM.js} +1 -1
  12. package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-nvog8lS6.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 +35 -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,543 +0,0 @@
1
- import "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { t as esm_default } from "../esm-BHXXx4Wx.mjs";
5
- import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
6
- import { s as signObject } from "../proof-BlfZ95--.mjs";
7
- import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
8
- import { o as createFederation, t as ContextImpl } from "../middleware-DcXzz-YK.mjs";
9
- import { configure, getLogger, reset, withContext } from "@logtape/logtape";
10
- import { Create, Note, Person } from "@fedify/vocab";
11
- import { computeDigestMultibase, exportDidKey, parseIri } from "@fedify/vocab-runtime";
12
- import { mockDocumentLoader, test } from "@fedify/fixture";
13
- import { deepStrictEqual, notStrictEqual, ok, rejects, strictEqual } from "node:assert/strict";
14
- import { AsyncLocalStorage } from "node:async_hooks";
15
- //#region src/federation/outbound-provenance.test.ts
16
- const sender = {
17
- keyId: rsaPublicKey2.id,
18
- privateKey: rsaPrivateKey2
19
- };
20
- const outgoing = new Create({
21
- id: new URL("https://example.com/outgoing"),
22
- actor: new URL("https://example.com/person2")
23
- });
24
- const target = new Person({
25
- id: new URL("https://remote.example/bob"),
26
- inbox: new URL("https://remote.example/inbox")
27
- });
28
- const loaders = {
29
- documentLoaderFactory: () => mockDocumentLoader,
30
- contextLoaderFactory: () => mockDocumentLoader,
31
- authenticatedDocumentLoaderFactory: () => mockDocumentLoader
32
- };
33
- function post(path, body) {
34
- return new Request(`https://inbox.example:8443${path}`, {
35
- method: "POST",
36
- headers: {
37
- "Content-Type": "application/activity+json",
38
- "X-Request-Id": "shared-external-label"
39
- },
40
- body: JSON.stringify(body)
41
- });
42
- }
43
- async function payload() {
44
- return await new Create({
45
- id: new URL("https://example.com/incoming"),
46
- actor: new URL("https://example.com/person2")
47
- }).toJsonLd({ contextLoader: mockDocumentLoader });
48
- }
49
- test("outbound inbox provenance follows clones, conversions, loaders, sends, and forwarding", async (t) => {
50
- for (const path of ["/users/alice/inbox", "/inbox"]) await t.step(path, async () => {
51
- const reports = [];
52
- const events = [];
53
- const messages = [];
54
- let retained;
55
- const federation = createFederation({
56
- ...loaders,
57
- kv: new MemoryKvStore(),
58
- origin: "https://canonical.example",
59
- skipSignatureVerification: true,
60
- manuallyStartQueue: true,
61
- queue: { outbox: {
62
- enqueue(message) {
63
- messages.push(message);
64
- return Promise.resolve();
65
- },
66
- listen: () => Promise.resolve()
67
- } }
68
- });
69
- federation.setOutboundObservers({
70
- onBroadcast(_ctx, event) {
71
- events.push(event);
72
- },
73
- onDelivery(_ctx, event) {
74
- events.push(event);
75
- }
76
- });
77
- federation.setActorDispatcher("/users/{identifier}", () => new Person({})).setKeyPairsDispatcher(async (ctx) => {
78
- await ctx.sendActivity(sender, [], outgoing);
79
- return [];
80
- });
81
- federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").setSharedKeyDispatcher(async (ctx) => {
82
- await ctx.sendActivity(sender, [], outgoing);
83
- return sender;
84
- }).on(Create, async (ctx) => {
85
- ok(ctx instanceof ContextImpl);
86
- const clone = ctx.clone(void 0);
87
- ok(clone instanceof ContextImpl);
88
- const outbox = clone.toOutboxContext("alice", {}, outgoing.id.href, Create.typeId.href);
89
- const inbox = outbox.toInboxContext(null, {}, outgoing.id.href, Create.typeId.href).clone(void 0);
90
- ctx.url.host = "changed.example:9443";
91
- retained = inbox;
92
- await clone.sendActivity(sender, target, outgoing);
93
- await outbox.clone(void 0).sendActivity(sender, target, outgoing);
94
- await inbox.forwardActivity(sender, target, { skipIfUnsigned: false });
95
- }).onRequestFinished(async (ctx, report) => {
96
- reports.push(report);
97
- await ctx.clone(void 0).sendActivity(sender, [], outgoing);
98
- });
99
- const body = await payload();
100
- for (let index = 0; index < 2; index++) {
101
- const start = events.length;
102
- strictEqual((await federation.fetch(post(path, body), { contextData: void 0 })).status, 202);
103
- const report = reports[index];
104
- ok(report.inboxRequestId);
105
- strictEqual(report.requestId, "shared-external-label");
106
- const observed = events.slice(start);
107
- ok(observed.length > 0);
108
- for (const event of observed) {
109
- const source = event.provenance.inboxRequest;
110
- ok(source);
111
- strictEqual(source.inboxRequestId, report.inboxRequestId);
112
- strictEqual(source.requestId, report.requestId);
113
- deepStrictEqual(source.context, {
114
- origin: "https://inbox.example:8443",
115
- host: "inbox.example:8443",
116
- hostname: "inbox.example",
117
- canonicalOrigin: "https://canonical.example"
118
- });
119
- ok(Object.isFrozen(event.provenance));
120
- ok(Object.isFrozen(source));
121
- ok(Object.isFrozen(source.context));
122
- ok(Object.isFrozen(event.local));
123
- }
124
- }
125
- notStrictEqual(reports[0].inboxRequestId, reports[1].inboxRequestId);
126
- strictEqual(messages.length, 3);
127
- ok(events.some((event) => event.local.host === "changed.example:9443"));
128
- ok(events.some((event) => event.local.host === "inbox.example:8443"));
129
- ok(events.some((event) => "operation" in event && event.operation === "forward"));
130
- ok(retained);
131
- const count = events.length;
132
- await retained.sendActivity(sender, [], outgoing);
133
- strictEqual(events[count].provenance.inboxRequest?.inboxRequestId, reports[0].inboxRequestId);
134
- for (const input of [new URL("https://inbox.example:8443"), post(path, body)]) {
135
- const independent = input instanceof URL ? federation.createContext(input, void 0) : federation.createContext(input, void 0);
136
- ok(independent instanceof ContextImpl);
137
- await independent.toInboxContext(null, body, "https://example.com/manual", Create.typeId.href).sendActivity(sender, [], outgoing);
138
- deepStrictEqual(events.at(-1).provenance, {});
139
- }
140
- });
141
- });
142
- test("outbound inbox provenance exists before loader preparation fails", async () => {
143
- const failure = /* @__PURE__ */ new Error("loader construction failed");
144
- const reports = [];
145
- const events = [];
146
- const federation = createFederation({
147
- ...loaders,
148
- kv: new MemoryKvStore(),
149
- contextLoaderFactory() {
150
- throw failure;
151
- }
152
- });
153
- federation.setOutboundObservers({ onBroadcast(_ctx, event) {
154
- events.push(event);
155
- } });
156
- federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").onRequestFinished(async (ctx, report) => {
157
- reports.push(report);
158
- await ctx.sendActivity(sender, [], outgoing);
159
- });
160
- for (const path of ["/users/alice/inbox", "/inbox"]) {
161
- await rejects(federation.fetch(post(path, {}), { contextData: void 0 }), (error) => error === failure);
162
- const report = reports.at(-1);
163
- ok(report.inboxRequestId);
164
- strictEqual(report.requestId, "shared-external-label");
165
- strictEqual(report.outcome.type, "exception");
166
- strictEqual(events.at(-1)?.provenance.inboxRequest?.inboxRequestId, report.inboxRequestId);
167
- }
168
- notStrictEqual(reports[0].inboxRequestId, reports[1].inboxRequestId);
169
- });
170
- test("outbound provenance keeps source log labels separate from current request labels", async () => {
171
- const records = [];
172
- await reset();
173
- await configure({
174
- sinks: { buffer: (record) => records.push(record) },
175
- loggers: [{
176
- category: [],
177
- sinks: ["buffer"],
178
- lowestLevel: "info"
179
- }, {
180
- category: ["logtape", "meta"],
181
- sinks: []
182
- }],
183
- contextLocalStorage: new AsyncLocalStorage()
184
- });
185
- try {
186
- const events = [];
187
- let retained;
188
- let report;
189
- const federation = createFederation({
190
- ...loaders,
191
- kv: new MemoryKvStore(),
192
- skipSignatureVerification: true
193
- });
194
- federation.setActorDispatcher("/users/{identifier}", async (ctx) => {
195
- await ctx.sendActivity(sender, [], outgoing);
196
- return new Person({});
197
- }).setKeyPairsDispatcher(() => []);
198
- federation.setOutboundObservers({ onBroadcast(_ctx, event) {
199
- events.push(event);
200
- getLogger(["test", "provenance"]).info("outbound callback");
201
- } });
202
- federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, async () => {
203
- await withContext({
204
- sourceInboxRequestId: "ambient-inbox",
205
- sourceRequestId: "ambient-source"
206
- }, () => federation.fetch(new Request("https://inbox.example/users/alice?nested=1", { headers: {
207
- Accept: "application/activity+json",
208
- "X-Request-Id": "nested-request"
209
- } }), { contextData: void 0 }));
210
- }).onRequestFinished((ctx, value) => {
211
- retained = ctx;
212
- report = value;
213
- getLogger(["test", "provenance"]).info("inbox callback");
214
- });
215
- strictEqual((await federation.fetch(post("/users/alice/inbox", await payload()), { contextData: void 0 })).status, 202);
216
- ok(retained && report?.inboxRequestId);
217
- const ingress = records.find((record) => record.rawMessage === "inbox callback");
218
- ok(ingress);
219
- strictEqual(ingress.properties.inboxRequestId, report.inboxRequestId);
220
- strictEqual(ingress.properties.requestId, report.requestId);
221
- const nested = records.find((record) => record.properties.url === "https://inbox.example/users/alice?nested=1" && record.properties.requestId === "nested-request");
222
- ok(nested);
223
- strictEqual(nested.properties.inboxRequestId, void 0);
224
- strictEqual(nested.properties.sourceInboxRequestId, void 0);
225
- strictEqual(nested.properties.sourceRequestId, void 0);
226
- const original = records.find((record) => record.properties.url === "https://inbox.example:8443/users/alice/inbox" && record.properties.status === 202);
227
- ok(original);
228
- strictEqual(original.properties.inboxRequestId, report.inboxRequestId);
229
- await withContext({ requestId: "unrelated-current" }, () => retained.sendActivity(sender, [], outgoing));
230
- const descendant = records.filter((record) => record.rawMessage === "outbound callback").at(-1);
231
- ok(descendant);
232
- strictEqual(descendant.properties.requestId, "unrelated-current");
233
- strictEqual(descendant.properties.sourceRequestId, report.requestId);
234
- strictEqual(descendant.properties.sourceInboxRequestId, report.inboxRequestId);
235
- const independent = federation.createContext(new URL("https://inbox.example"), void 0);
236
- await withContext({
237
- requestId: "independent-current",
238
- sourceRequestId: "ambient-source",
239
- sourceInboxRequestId: "ambient-inbox"
240
- }, () => independent.sendActivity(sender, [], outgoing));
241
- deepStrictEqual(events.at(-1).provenance, {});
242
- const independentLog = records.filter((record) => record.rawMessage === "outbound callback").at(-1);
243
- ok(independentLog);
244
- strictEqual(independentLog.properties.requestId, "independent-current");
245
- strictEqual(independentLog.properties.sourceRequestId, void 0);
246
- strictEqual(independentLog.properties.sourceInboxRequestId, void 0);
247
- const start = events.length;
248
- await federation.fetch(new Request("https://inbox.example/users/alice", { headers: {
249
- Accept: "application/activity+json",
250
- "X-Request-Id": "actor-request"
251
- } }), { contextData: void 0 });
252
- ok(events.length > start);
253
- for (const event of events.slice(start)) deepStrictEqual(event.provenance, { originatingRequestId: "actor-request" });
254
- } finally {
255
- await reset();
256
- }
257
- });
258
- test("outbound provenance does not invent an inbox cause for programmatic routing", async () => {
259
- const events = [];
260
- const federation = createFederation({
261
- ...loaders,
262
- kv: new MemoryKvStore()
263
- });
264
- federation.setOutboundObservers({ onBroadcast(_ctx, event) {
265
- events.push(event);
266
- } });
267
- federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, async (ctx) => {
268
- await ctx.sendActivity(sender, [], outgoing);
269
- });
270
- const ctx = federation.createContext(new URL("https://inbox.example"), void 0);
271
- const signed = await signObject(new Create({
272
- id: new URL("https://example.com/programmatic"),
273
- actor: new URL("https://example.com/person2")
274
- }), ed25519PrivateKey, ed25519Multikey.id, { contextLoader: mockDocumentLoader });
275
- strictEqual(await ctx.routeActivity(null, signed), true);
276
- strictEqual(events.length, 2);
277
- for (const event of events) deepStrictEqual(event.provenance, {});
278
- });
279
- test("outbound provenance retains request labels on gateway dispatchers", async (t) => {
280
- const did = await exportDidKey(ed25519PublicKey.publicKey);
281
- const digest = await computeDigestMultibase(new TextEncoder().encode("gateway media"));
282
- for (const route of [
283
- "actor",
284
- "object",
285
- "collection",
286
- "media"
287
- ]) await t.step(route, async () => {
288
- const events = [];
289
- const federation = createFederation({
290
- ...loaders,
291
- kv: new MemoryKvStore()
292
- });
293
- const send = (ctx) => ctx.clone(void 0).sendActivity(sender, [], outgoing);
294
- federation.setOutboundObservers({ onBroadcast(_ctx, event) {
295
- events.push(event);
296
- } });
297
- federation.setActorDispatcher("/users/{identifier}", async (ctx) => {
298
- await send(ctx);
299
- return route === "collection" ? new Person({
300
- id: parseIri(`ap+ef61://${did}/users/alice`),
301
- followers: parseIri(`ap+ef61://${did}/users/alice/followers`)
302
- }) : null;
303
- });
304
- federation.setObjectDispatcher(Note, "/notes/{id}", async (ctx) => {
305
- await send(ctx);
306
- return null;
307
- });
308
- federation.setFollowersDispatcher("/users/{identifier}/followers", async (ctx) => {
309
- await send(ctx);
310
- return { items: [] };
311
- });
312
- federation.setHashlinkMediaDispatcher(async (ctx) => {
313
- await send(ctx);
314
- return null;
315
- });
316
- const suffix = route === "actor" ? `${did}/users/alice` : route === "object" ? `${did}/notes/1` : route === "collection" ? `${did}/users/alice/followers` : `hl:${digest}`;
317
- strictEqual((await federation.fetch(new Request(`https://example.com/.well-known/apgateway/${suffix}`, { headers: {
318
- Accept: "application/activity+json",
319
- "X-Request-Id": `${route}-request`
320
- } }), { contextData: void 0 })).status, route === "collection" ? 200 : 404);
321
- strictEqual(events.length, route === "collection" ? 4 : 2);
322
- for (const event of events) {
323
- deepStrictEqual(event.provenance, { originatingRequestId: `${route}-request` });
324
- strictEqual(event.local.host, "example.com");
325
- }
326
- });
327
- });
328
- test("queued provenance survives inbox retries, fanout, and outbox worker reconstruction", async (t) => {
329
- const records = [];
330
- await reset();
331
- await configure({
332
- sinks: { buffer: (record) => records.push(record) },
333
- loggers: [{
334
- category: [],
335
- sinks: ["buffer"],
336
- lowestLevel: "info"
337
- }, {
338
- category: ["logtape", "meta"],
339
- sinks: []
340
- }],
341
- contextLocalStorage: new AsyncLocalStorage()
342
- });
343
- try {
344
- for (const { legacy, native } of [
345
- {
346
- legacy: false,
347
- native: false
348
- },
349
- {
350
- legacy: false,
351
- native: true
352
- },
353
- {
354
- legacy: true,
355
- native: false
356
- }
357
- ]) await t.step(`${legacy ? "legacy" : "source"}: ${native ? "native redelivery" : "scheduled retry"}`, async () => {
358
- const messages = [];
359
- const events = [];
360
- const reports = [];
361
- const queue = {
362
- nativeRetrial: native,
363
- enqueue(message) {
364
- messages.push(message);
365
- return Promise.resolve();
366
- },
367
- listen: () => Promise.resolve()
368
- };
369
- const federation = createFederation({
370
- ...loaders,
371
- kv: new MemoryKvStore(),
372
- origin: "https://canonical.example",
373
- skipSignatureVerification: true,
374
- manuallyStartQueue: true,
375
- queue: {
376
- inbox: queue,
377
- fanout: queue,
378
- outbox: queue
379
- }
380
- });
381
- federation.setActorDispatcher("/users/{identifier}", () => new Person({})).setKeyPairsDispatcher(async (ctx) => {
382
- await ctx.sendActivity(sender, [], outgoing);
383
- return [];
384
- });
385
- let calls = 0;
386
- const failure = /* @__PURE__ */ new Error("retry listener");
387
- federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").setSharedKeyDispatcher(async (ctx) => {
388
- await ctx.sendActivity(sender, [], outgoing);
389
- return sender;
390
- }).on(Create, async (ctx) => {
391
- getLogger(["test", "queued-source"]).info("queued listener");
392
- await ctx.sendActivity(sender, [], outgoing);
393
- if (++calls === 1) throw failure;
394
- ok(ctx instanceof ContextImpl);
395
- const clone = ctx.clone(void 0);
396
- await clone.sendActivity(sender, target, outgoing, { fanout: "force" });
397
- await ctx.toOutboxContext("alice", {}, outgoing.id.href, Create.typeId.href).clone(void 0).sendActivity(sender, target, outgoing, { fanout: "skip" });
398
- await clone.forwardActivity(sender, target, { skipIfUnsigned: false });
399
- }).onRequestFinished((_ctx, report) => {
400
- reports.push(report);
401
- });
402
- strictEqual((await federation.fetch(post(native ? "/inbox" : "/users/alice/inbox", await payload()), { contextData: void 0 })).status, 202);
403
- const produced = messages[0];
404
- ok(produced.type === "inbox");
405
- ok(produced.provenance?.inboxRequest);
406
- strictEqual(produced.provenance.inboxRequest.inboxRequestId, reports[0].inboxRequestId);
407
- deepStrictEqual(JSON.parse(JSON.stringify(produced.provenance)), produced.provenance);
408
- const task = JSON.parse(JSON.stringify(produced));
409
- if (legacy) delete task.provenance;
410
- const expected = task.provenance ?? {};
411
- federation.setOutboundObservers({
412
- onBroadcast(_ctx, event) {
413
- events.push(event);
414
- },
415
- onDelivery(_ctx, event) {
416
- events.push(event);
417
- }
418
- });
419
- const execute = (message) => withContext({
420
- requestId: "worker-current",
421
- inboxRequestId: "unrelated-inbox",
422
- sourceInboxRequestId: "ambient-source",
423
- sourceRequestId: "ambient-label"
424
- }, () => federation.processQueuedTask(void 0, message));
425
- messages.length = 0;
426
- const logStart = records.length;
427
- if (native) await rejects(execute(task), (error) => error === failure);
428
- else await execute(task);
429
- const retry = native ? task : messages.find((message) => message.type === "inbox");
430
- ok(retry?.type === "inbox");
431
- deepStrictEqual(retry.provenance ?? {}, expected);
432
- strictEqual(retry.attempt, native ? 0 : 1);
433
- await execute({
434
- ...structuredClone(retry),
435
- id: crypto.randomUUID()
436
- });
437
- strictEqual(calls, 2);
438
- const fanout = messages.find((message) => message.type === "fanout");
439
- ok(fanout?.type === "fanout");
440
- deepStrictEqual(fanout.provenance ?? {}, expected);
441
- await execute(JSON.parse(JSON.stringify(fanout)));
442
- const outgoingTasks = messages.filter((message) => message.type === "outbox");
443
- strictEqual(outgoingTasks.length, 3);
444
- for (const message of outgoingTasks) {
445
- deepStrictEqual(message.provenance ?? {}, expected);
446
- strictEqual("provenance" in message, !legacy);
447
- }
448
- const consumer = createFederation({
449
- kv: new MemoryKvStore(),
450
- allowPrivateAddress: true,
451
- origin: "https://consumer.example",
452
- manuallyStartQueue: true,
453
- queue: { outbox: queue }
454
- });
455
- consumer.setOutboundObservers({ onBroadcast(_ctx, event) {
456
- events.push(event);
457
- } });
458
- let permanent = 0;
459
- consumer.setOutboxPermanentFailureHandler(async (ctx) => {
460
- permanent++;
461
- getLogger(["test", "queued-source"]).info("permanent callback");
462
- await ctx.clone(void 0).sendActivity(sender, [], outgoing);
463
- });
464
- esm_default.mockGlobal().post(target.inboxId.href, 410);
465
- try {
466
- await withContext({
467
- requestId: "worker-current",
468
- sourceInboxRequestId: "ambient-source",
469
- sourceRequestId: "ambient-label"
470
- }, () => consumer.processQueuedTask(void 0, {
471
- ...structuredClone(outgoingTasks[0]),
472
- baseUrl: "https://worker.example"
473
- }));
474
- } finally {
475
- esm_default.hardReset();
476
- }
477
- strictEqual(permanent, 1);
478
- ok(events.length > 0);
479
- for (const event of events) {
480
- deepStrictEqual(event.provenance, expected);
481
- ok(Object.isFrozen(event.provenance));
482
- if (!legacy) ok(Object.isFrozen(event.provenance.inboxRequest?.context));
483
- }
484
- strictEqual(events.at(-1).local.host, "worker.example");
485
- strictEqual(events.at(-1).local.canonicalOrigin, "https://consumer.example");
486
- const workerLogs = records.slice(logStart).filter((record) => record.rawMessage === "queued listener" || record.rawMessage === "permanent callback");
487
- strictEqual(workerLogs.length, 3);
488
- for (const record of workerLogs) {
489
- strictEqual(record.properties.requestId, "worker-current");
490
- strictEqual(record.properties.inboxRequestId, void 0);
491
- strictEqual(record.properties.sourceInboxRequestId, expected.inboxRequest?.inboxRequestId);
492
- strictEqual(record.properties.sourceRequestId, expected.inboxRequest?.requestId);
493
- }
494
- });
495
- } finally {
496
- await reset();
497
- }
498
- });
499
- test("queued provenance retains a non-inbox HTTP request label without inventing an inbox cause", async () => {
500
- const messages = [];
501
- const queue = {
502
- enqueue(message) {
503
- messages.push(message);
504
- return Promise.resolve();
505
- },
506
- listen: () => Promise.resolve()
507
- };
508
- const federation = createFederation({
509
- ...loaders,
510
- kv: new MemoryKvStore(),
511
- manuallyStartQueue: true,
512
- queue: {
513
- fanout: queue,
514
- outbox: queue
515
- }
516
- });
517
- federation.setActorDispatcher("/users/{identifier}", async (ctx) => {
518
- await ctx.sendActivity(sender, target, outgoing, { fanout: "force" });
519
- return null;
520
- });
521
- strictEqual((await federation.fetch(new Request("https://example.com/users/alice", { headers: {
522
- Accept: "application/activity+json",
523
- "X-Request-Id": "original-http-label"
524
- } }), { contextData: void 0 })).status, 404);
525
- const message = messages[0];
526
- ok(message?.type === "fanout");
527
- deepStrictEqual(message.provenance, { originatingRequestId: "original-http-label" });
528
- const events = [];
529
- federation.setOutboundObservers({ onDelivery(_ctx, event) {
530
- events.push(event);
531
- } });
532
- await withContext({
533
- requestId: "worker-current",
534
- sourceInboxRequestId: "unrelated-inbox"
535
- }, () => federation.processQueuedTask(void 0, JSON.parse(JSON.stringify(message))));
536
- strictEqual(events.length, 1);
537
- deepStrictEqual(events[0].provenance, message.provenance);
538
- const child = messages[1];
539
- ok(child?.type === "outbox");
540
- deepStrictEqual(child.provenance, message.provenance);
541
- });
542
- //#endregion
543
- export {};
@@ -1,2 +0,0 @@
1
- import { Temporal } from "temporal-polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";