@fedify/fedify 2.0.0-dev.1641 → 2.0.0-dev.1690

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 (147) hide show
  1. package/dist/{actor-CP03csrm.cjs → actor-Be0ThtXy.cjs} +7263 -2440
  2. package/dist/{actor-DU511yTk.js → actor-ChbPLm6n.js} +7263 -2440
  3. package/dist/{actor-DMgu-ZjT.d.cts → actor-D6K058Tb.d.cts} +1 -1
  4. package/dist/{actor-DVpsNXhn.js → actor-DuCeRiNh.js} +1 -1
  5. package/dist/{actor-C22bXuuC.d.ts → actor-T6RyhRgk.d.ts} +1 -1
  6. package/dist/{assert_rejects-7UF4R_Qs.js → assert_rejects-DiIiJbZn.js} +1 -1
  7. package/dist/{assert_throws-53_pKeP3.js → assert_throws-BOO88avQ.js} +1 -1
  8. package/dist/{authdocloader-BkIZCKQv.js → authdocloader-Brax1A32.js} +3 -3
  9. package/dist/{authdocloader-DCgMyo82.js → authdocloader-CrxhFL8e.js} +3 -3
  10. package/dist/{authdocloader-BnsFSERg.cjs → authdocloader-OSn_teLV.cjs} +3 -3
  11. package/dist/{builder-E2Icrl_a.js → builder-CYOcDUkj.js} +10 -4
  12. package/dist/{client-BW4V0OJx.js → client-CnOdwLLN.js} +1 -1
  13. package/dist/compat/mod.d.cts +7 -7
  14. package/dist/compat/mod.d.ts +7 -7
  15. package/dist/compat/transformers.test.js +18 -17
  16. package/dist/{context-CDSZdQHD.d.ts → context-ByZprN0S.d.ts} +66 -6
  17. package/dist/{context-Dq8aCtMH.d.cts → context-C5BsZkDr.d.cts} +66 -6
  18. package/dist/{docloader-kae6M-GI.cjs → docloader-CCqXeagZ.cjs} +2 -2
  19. package/dist/{docloader-BtqIh1OE.js → docloader-XK3y2jn5.js} +2 -2
  20. package/dist/{esm-mtx3XJAD.js → esm-DnIzfEj0.js} +1 -1
  21. package/dist/federation/builder.test.js +10 -10
  22. package/dist/federation/collection.test.js +8 -8
  23. package/dist/federation/handler.test.js +26 -145
  24. package/dist/federation/idempotency.test.d.ts +3 -0
  25. package/dist/federation/idempotency.test.js +202 -0
  26. package/dist/federation/inbox.test.js +6 -6
  27. package/dist/federation/keycache.test.js +4 -4
  28. package/dist/federation/kv.test.js +8 -8
  29. package/dist/federation/middleware.test.js +232 -38
  30. package/dist/federation/mod.cjs +10 -10
  31. package/dist/federation/mod.d.cts +7 -7
  32. package/dist/federation/mod.d.ts +7 -7
  33. package/dist/federation/mod.js +10 -10
  34. package/dist/federation/mq.test.js +10 -10
  35. package/dist/federation/negotiation.test.d.ts +3 -0
  36. package/dist/federation/negotiation.test.js +28 -0
  37. package/dist/federation/retry.test.js +5 -5
  38. package/dist/federation/router.test.js +8 -8
  39. package/dist/federation/send.test.js +15 -15
  40. package/dist/fixtures/media.example.com/avatars/test-avatar.jpg.json +6 -0
  41. package/dist/{http-Cox5GsED.js → http-BNOYnVsU.js} +2 -2
  42. package/dist/{http-C7uYFcBo.js → http-BxbM8sEy.js} +3 -3
  43. package/dist/{http-ZhcoaYEa.cjs → http-C7vbQwbz.cjs} +3 -3
  44. package/dist/{http-BS6766zs.d.cts → http-D-e6AFwR.d.cts} +1 -1
  45. package/dist/{http-DqSNLFNY.d.ts → http-D6Uj2x2y.d.ts} +1 -1
  46. package/dist/{inbox-BDdRbWNI.js → inbox-BRru9pX3.js} +24 -7
  47. package/dist/{key-CfiBDu3o.js → key-1KXru8Ug.js} +2 -2
  48. package/dist/{key-B9Z5ZuX9.js → key-B3uag-rz.js} +4 -4
  49. package/dist/key-BiBmb1Yy.cjs +10 -0
  50. package/dist/{key-CgwCzDC4.js → key-DK_nfU4I.js} +3 -3
  51. package/dist/{key-HqzOCwDc.cjs → key-Z6ceKnZC.cjs} +2 -2
  52. package/dist/{key-Cc0JlcKe.js → key-jyNTxCvK.js} +2 -2
  53. package/dist/{keycache-CVBjz3xi.js → keycache-CN61iGVj.js} +1 -1
  54. package/dist/{keys-CBKbYaJA.js → keys-BPdFKgiy.js} +1 -1
  55. package/dist/{ld-CxgmnSO3.js → ld-Dv8DNNAT.js} +2 -2
  56. package/dist/{lookup-NuT9cCSl.js → lookup-BPviO8ij.js} +1 -1
  57. package/dist/{lookup-QHjmy4Og.cjs → lookup-hnMAAU5r.cjs} +1 -1
  58. package/dist/{lookup-CiU3QxQz.js → lookup-pV0JOsuV.js} +21 -12
  59. package/dist/{middleware-LyCG_YVM.cjs → middleware-BmoOlgc1.cjs} +69 -73
  60. package/dist/{middleware-DXidHY4N.js → middleware-Bz_A2jeJ.js} +69 -73
  61. package/dist/middleware-CI0-zw4U.js +26 -0
  62. package/dist/{middleware-ByPnvMMS.js → middleware-DY9B2lL8.js} +43 -134
  63. package/dist/middleware-QNK-W-jE.cjs +17 -0
  64. package/dist/middleware-_vjt6FWU.js +17 -0
  65. package/dist/{mod-BhMnAkFX.d.cts → mod-8DMWKtQE.d.cts} +2 -2
  66. package/dist/{mod-Drmz72EK.d.ts → mod-BhUKmBJD.d.ts} +2 -2
  67. package/dist/{mod-TFoH2Ql8.d.ts → mod-CerN_Sza.d.ts} +1 -1
  68. package/dist/{mod-Dc_-mf8s.d.cts → mod-Cj1tHXBR.d.cts} +1 -1
  69. package/dist/{mod-evzlRVZq.d.cts → mod-CxkWO3Mg.d.cts} +19 -1
  70. package/dist/{mod-RI3-KvUI.d.ts → mod-D6hQoxC5.d.ts} +2 -2
  71. package/dist/{mod-BClfg3ej.d.cts → mod-Djzcw2ry.d.cts} +2 -2
  72. package/dist/{mod-Cxt4Kpf6.d.ts → mod-DlU8ISoa.d.ts} +19 -1
  73. package/dist/mod.cjs +10 -10
  74. package/dist/mod.d.cts +10 -10
  75. package/dist/mod.d.ts +10 -10
  76. package/dist/mod.js +10 -10
  77. package/dist/negotiation-5NPJL6zp.js +71 -0
  78. package/dist/nodeinfo/client.test.js +10 -10
  79. package/dist/nodeinfo/handler.test.js +23 -22
  80. package/dist/nodeinfo/mod.cjs +2 -2
  81. package/dist/nodeinfo/mod.js +2 -2
  82. package/dist/nodeinfo/types.test.js +8 -8
  83. package/dist/{owner-B-7Ptt_m.d.cts → owner-BN_tO3cY.d.cts} +2 -2
  84. package/dist/{owner-Cxob5_PK.js → owner-e3FYDhsk.js} +2 -2
  85. package/dist/{owner-CQPnQVtf.d.ts → owner-hd9lvQcP.d.ts} +2 -2
  86. package/dist/{proof-BiSQNUmQ.js → proof-6gFMwMNJ.js} +2 -2
  87. package/dist/{proof-2Gcor0_N.cjs → proof-B-eqv0Ug.cjs} +3 -3
  88. package/dist/{proof-DkxwMaWE.js → proof-DfgvA3al.js} +3 -3
  89. package/dist/runtime/authdocloader.test.js +14 -14
  90. package/dist/runtime/docloader.test.js +9 -9
  91. package/dist/runtime/key.test.js +10 -10
  92. package/dist/runtime/langstr.test.js +8 -8
  93. package/dist/runtime/link.test.js +3 -3
  94. package/dist/runtime/mod.cjs +6 -6
  95. package/dist/runtime/mod.d.cts +3 -3
  96. package/dist/runtime/mod.d.ts +3 -3
  97. package/dist/runtime/mod.js +6 -6
  98. package/dist/runtime/multibase/multibase.test.js +8 -8
  99. package/dist/runtime/url.test.js +5 -5
  100. package/dist/{send-DSEhWIYD.js → send-Tl9NOnmO.js} +2 -2
  101. package/dist/sig/http.test.js +13 -13
  102. package/dist/sig/key.test.js +11 -11
  103. package/dist/sig/ld.test.js +10 -10
  104. package/dist/sig/mod.cjs +6 -6
  105. package/dist/sig/mod.d.cts +5 -5
  106. package/dist/sig/mod.d.ts +5 -5
  107. package/dist/sig/mod.js +6 -6
  108. package/dist/sig/owner.test.js +12 -12
  109. package/dist/sig/proof.test.js +12 -12
  110. package/dist/testing/docloader.test.js +8 -8
  111. package/dist/testing/mod.d.ts +272 -0
  112. package/dist/testing/mod.js +3 -3
  113. package/dist/{testing-ByQmUvf-.js → testing-BWNCAbL-.js} +2 -2
  114. package/dist/{type-B4NJkfVg.js → type-C69ZBu7f.js} +6944 -2121
  115. package/dist/{types-l2uh_ZhP.js → types-DqxyTxOf.js} +1 -1
  116. package/dist/{types-Bqt2EgP0.cjs → types-zqdWZh4O.cjs} +1 -1
  117. package/dist/vocab/actor.test.js +10 -10
  118. package/dist/vocab/lookup.test.js +259 -9
  119. package/dist/vocab/mod.cjs +4 -4
  120. package/dist/vocab/mod.d.cts +3 -3
  121. package/dist/vocab/mod.d.ts +3 -3
  122. package/dist/vocab/mod.js +4 -4
  123. package/dist/vocab/type.test.js +3 -3
  124. package/dist/vocab/vocab.test.js +402 -13
  125. package/dist/{vocab-B0-5a8pw.cjs → vocab-B39-pFl9.cjs} +23 -14
  126. package/dist/{vocab-SOE1ifCr.d.ts → vocab-BI0Ak5lL.d.ts} +290 -0
  127. package/dist/{vocab-lBFcVxVF.js → vocab-BWoeZsME.js} +23 -14
  128. package/dist/{vocab-DJTYMqyU.d.cts → vocab-Dw1-yVGg.d.cts} +290 -0
  129. package/dist/webfinger/handler.test.js +23 -22
  130. package/dist/webfinger/lookup.test.js +9 -9
  131. package/dist/webfinger/mod.cjs +2 -2
  132. package/dist/webfinger/mod.js +2 -2
  133. package/dist/x/cfworkers.test.js +8 -8
  134. package/dist/x/hono.d.cts +6 -6
  135. package/dist/x/hono.d.ts +6 -6
  136. package/dist/x/sveltekit.d.cts +6 -6
  137. package/dist/x/sveltekit.d.ts +6 -6
  138. package/package.json +1 -1
  139. package/dist/key-D-7DPHNl.cjs +0 -10
  140. package/dist/middleware-BHboQ4BE.js +0 -25
  141. package/dist/middleware-Bp3I9z8r.js +0 -17
  142. package/dist/middleware-oYqSU5ky.cjs +0 -17
  143. /package/dist/{assert_is_error-B035L3om.js → assert_is_error-BPGph1Jx.js} +0 -0
  144. /package/dist/{assert_not_equals-C80BG-_5.js → assert_not_equals-f3m3epl3.js} +0 -0
  145. /package/dist/{denokv-jZ0Z2h0M.js → denokv-Bv33Xxea.js} +0 -0
  146. /package/dist/{retry-CfF8Gn4d.js → retry-D4GJ670a.js} +0 -0
  147. /package/dist/{std__assert-DWivtrGR.js → std__assert-X-_kMxKM.js} +0 -0
@@ -0,0 +1,202 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import { Create, Follow, Person } from "../type-C69ZBu7f.js";
7
+ import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
+ import "../assert-MZs1qjMx.js";
9
+ import "../assert_instance_of-DHz7EHNU.js";
10
+ import { MemoryKvStore } from "../kv-CRZrzyXm.js";
11
+ import { createFederation } from "../middleware-DY9B2lL8.js";
12
+ import "../client-CnOdwLLN.js";
13
+ import "../lookup-pV0JOsuV.js";
14
+ import "../types-BSuWJsOm.js";
15
+ import "../actor-DuCeRiNh.js";
16
+ import "../key-1KXru8Ug.js";
17
+ import "../http-BNOYnVsU.js";
18
+ import "../authdocloader-Brax1A32.js";
19
+ import "../ld-Dv8DNNAT.js";
20
+ import "../owner-e3FYDhsk.js";
21
+ import { signObject } from "../proof-6gFMwMNJ.js";
22
+ import "../inbox-BRru9pX3.js";
23
+ import "../builder-CYOcDUkj.js";
24
+ import "../collection-CcnIw1qY.js";
25
+ import "../keycache-CN61iGVj.js";
26
+ import "../negotiation-5NPJL6zp.js";
27
+ import "../retry-D4GJ670a.js";
28
+ import "../send-Tl9NOnmO.js";
29
+ import { mockDocumentLoader, test } from "../testing-BWNCAbL-.js";
30
+ import "../std__assert-X-_kMxKM.js";
31
+ import "../assert_rejects-DiIiJbZn.js";
32
+ import "../assert_is_error-BPGph1Jx.js";
33
+ import "../assert_not_equals-f3m3epl3.js";
34
+ import "../assert_throws-BOO88avQ.js";
35
+ import { ed25519Multikey, ed25519PrivateKey, ed25519PublicKey } from "../keys-BPdFKgiy.js";
36
+
37
+ //#region src/federation/idempotency.test.ts
38
+ const kv = new MemoryKvStore();
39
+ const federationOptions = {
40
+ kv,
41
+ documentLoaderFactory: () => mockDocumentLoader,
42
+ authenticatedDocumentLoaderFactory: () => mockDocumentLoader
43
+ };
44
+ function createTestFederation() {
45
+ const federation = createFederation(federationOptions);
46
+ federation.setActorDispatcher("/users/{identifier}", (_, identifier) => identifier === "john" ? new Person({}) : null).setKeyPairsDispatcher(() => [{
47
+ privateKey: ed25519PrivateKey,
48
+ publicKey: ed25519PublicKey.publicKey
49
+ }]);
50
+ return federation;
51
+ }
52
+ test("Federation.setInboxListeners().withIdempotency() - per-origin strategy", async () => {
53
+ const federation = createTestFederation();
54
+ const processedActivities = [];
55
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").withIdempotency("per-origin").on(Create, (ctx, activity$1) => {
56
+ processedActivities.push([ctx.recipient, activity$1]);
57
+ });
58
+ const activity = new Create({
59
+ id: new URL("https://example.com/activities/1"),
60
+ actor: new URL("https://example.com/person2")
61
+ });
62
+ const signedActivity = await signObject(activity, ed25519PrivateKey, ed25519Multikey.id);
63
+ const body = JSON.stringify(await signedActivity.toJsonLd({ contextLoader: mockDocumentLoader }));
64
+ let response = await federation.fetch(new Request("https://example.com/users/john/inbox", {
65
+ method: "POST",
66
+ headers: { "Content-Type": "application/activity+json" },
67
+ body
68
+ }), { contextData: void 0 });
69
+ assertEquals(response.status, 202);
70
+ assertEquals(processedActivities.length, 1);
71
+ assertEquals(processedActivities[0][0], "john");
72
+ response = await federation.fetch(new Request("https://example.com/inbox", {
73
+ method: "POST",
74
+ headers: { "Content-Type": "application/activity+json" },
75
+ body
76
+ }), { contextData: void 0 });
77
+ assertEquals(response.status, 202);
78
+ assertEquals(processedActivities.length, 1);
79
+ await kv.delete([
80
+ "_fedify",
81
+ "activityIdempotence",
82
+ "https://example.com:https://example.com/activities/1"
83
+ ]);
84
+ });
85
+ test("Federation.setInboxListeners().withIdempotency() - per-inbox strategy", async () => {
86
+ const federation = createTestFederation();
87
+ const processedActivities = [];
88
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").withIdempotency("per-inbox").on(Create, (ctx, activity$1) => {
89
+ processedActivities.push([ctx.recipient, activity$1]);
90
+ });
91
+ const activity = new Create({
92
+ id: new URL("https://example.com/activities/2"),
93
+ actor: new URL("https://example.com/person2")
94
+ });
95
+ const signedActivity = await signObject(activity, ed25519PrivateKey, ed25519Multikey.id);
96
+ const body = JSON.stringify(await signedActivity.toJsonLd({ contextLoader: mockDocumentLoader }));
97
+ let response = await federation.fetch(new Request("https://example.com/users/john/inbox", {
98
+ method: "POST",
99
+ headers: { "Content-Type": "application/activity+json" },
100
+ body
101
+ }), { contextData: void 0 });
102
+ assertEquals(response.status, 202);
103
+ assertEquals(processedActivities.length, 1);
104
+ assertEquals(processedActivities[0][0], "john");
105
+ response = await federation.fetch(new Request("https://example.com/inbox", {
106
+ method: "POST",
107
+ headers: { "Content-Type": "application/activity+json" },
108
+ body
109
+ }), { contextData: void 0 });
110
+ assertEquals(response.status, 202);
111
+ assertEquals(processedActivities.length, 2);
112
+ assertEquals(processedActivities[1][0], null);
113
+ response = await federation.fetch(new Request("https://example.com/users/john/inbox", {
114
+ method: "POST",
115
+ headers: { "Content-Type": "application/activity+json" },
116
+ body
117
+ }), { contextData: void 0 });
118
+ assertEquals(response.status, 202);
119
+ assertEquals(processedActivities.length, 2);
120
+ });
121
+ test("Federation.setInboxListeners().withIdempotency() - global strategy", async () => {
122
+ const federation = createTestFederation();
123
+ const processedActivities = [];
124
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").withIdempotency("global").on(Create, (ctx, activity$1) => {
125
+ processedActivities.push([ctx.recipient, activity$1]);
126
+ });
127
+ const activity = new Create({
128
+ id: new URL("https://example.com/activities/3"),
129
+ actor: new URL("https://example.com/person2")
130
+ });
131
+ const signedActivity = await signObject(activity, ed25519PrivateKey, ed25519Multikey.id);
132
+ const body = JSON.stringify(await signedActivity.toJsonLd({ contextLoader: mockDocumentLoader }));
133
+ let response = await federation.fetch(new Request("https://example.com/users/john/inbox", {
134
+ method: "POST",
135
+ headers: { "Content-Type": "application/activity+json" },
136
+ body
137
+ }), { contextData: void 0 });
138
+ assertEquals(response.status, 202);
139
+ assertEquals(processedActivities.length, 1);
140
+ response = await federation.fetch(new Request("https://example.com/inbox", {
141
+ method: "POST",
142
+ headers: { "Content-Type": "application/activity+json" },
143
+ body
144
+ }), { contextData: void 0 });
145
+ assertEquals(response.status, 202);
146
+ assertEquals(processedActivities.length, 1);
147
+ });
148
+ test("Federation.setInboxListeners().withIdempotency() - custom callback", async () => {
149
+ const federation = createTestFederation();
150
+ const processedActivities = [];
151
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").withIdempotency((ctx, activity) => {
152
+ if (activity instanceof Follow) return null;
153
+ const inboxId = ctx.recipient ?? "shared";
154
+ return `${ctx.origin}:${activity.id?.href}:${inboxId}`;
155
+ }).on(Create, (ctx, activity) => {
156
+ processedActivities.push([ctx.recipient, activity]);
157
+ }).on(Follow, (ctx, activity) => {
158
+ processedActivities.push([ctx.recipient, activity]);
159
+ });
160
+ const createActivity = new Create({
161
+ id: new URL("https://example.com/activities/4"),
162
+ actor: new URL("https://example.com/person2")
163
+ });
164
+ const signedCreate = await signObject(createActivity, ed25519PrivateKey, ed25519Multikey.id);
165
+ const createBody = JSON.stringify(await signedCreate.toJsonLd({ contextLoader: mockDocumentLoader }));
166
+ let response = await federation.fetch(new Request("https://example.com/users/john/inbox", {
167
+ method: "POST",
168
+ headers: { "Content-Type": "application/activity+json" },
169
+ body: createBody
170
+ }), { contextData: void 0 });
171
+ assertEquals(response.status, 202);
172
+ assertEquals(processedActivities.length, 1);
173
+ response = await federation.fetch(new Request("https://example.com/users/john/inbox", {
174
+ method: "POST",
175
+ headers: { "Content-Type": "application/activity+json" },
176
+ body: createBody
177
+ }), { contextData: void 0 });
178
+ assertEquals(response.status, 202);
179
+ assertEquals(processedActivities.length, 1);
180
+ const followActivity = new Follow({
181
+ id: new URL("https://example.com/activities/5"),
182
+ actor: new URL("https://example.com/person2")
183
+ });
184
+ const signedFollow = await signObject(followActivity, ed25519PrivateKey, ed25519Multikey.id);
185
+ const followBody = JSON.stringify(await signedFollow.toJsonLd({ contextLoader: mockDocumentLoader }));
186
+ response = await federation.fetch(new Request("https://example.com/users/john/inbox", {
187
+ method: "POST",
188
+ headers: { "Content-Type": "application/activity+json" },
189
+ body: followBody
190
+ }), { contextData: void 0 });
191
+ assertEquals(response.status, 202);
192
+ assertEquals(processedActivities.length, 2);
193
+ response = await federation.fetch(new Request("https://example.com/users/john/inbox", {
194
+ method: "POST",
195
+ headers: { "Content-Type": "application/activity+json" },
196
+ body: followBody
197
+ }), { contextData: void 0 });
198
+ assertEquals(response.status, 202);
199
+ assertEquals(processedActivities.length, 3);
200
+ });
201
+
202
+ //#endregion
@@ -3,13 +3,13 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Activity, Create, Invite, Offer, Update } from "../type-B4NJkfVg.js";
6
+ import { Activity, Create, Invite, Offer, Update } from "../type-C69ZBu7f.js";
7
7
  import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
- import "../lookup-CiU3QxQz.js";
9
- import { InboxListenerSet } from "../inbox-BDdRbWNI.js";
10
- import { test } from "../testing-ByQmUvf-.js";
11
- import "../assert_is_error-B035L3om.js";
12
- import { assertThrows } from "../assert_throws-53_pKeP3.js";
8
+ import "../lookup-pV0JOsuV.js";
9
+ import { InboxListenerSet } from "../inbox-BRru9pX3.js";
10
+ import { test } from "../testing-BWNCAbL-.js";
11
+ import "../assert_is_error-BPGph1Jx.js";
12
+ import { assertThrows } from "../assert_throws-BOO88avQ.js";
13
13
 
14
14
  //#region src/federation/inbox.test.ts
15
15
  test("InboxListenerSet", () => {
@@ -3,14 +3,14 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Multikey } from "../type-B4NJkfVg.js";
6
+ import { CryptographicKey, Multikey } from "../type-C69ZBu7f.js";
7
7
  import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
8
  import { assert } from "../assert-MZs1qjMx.js";
9
9
  import { assertInstanceOf } from "../assert_instance_of-DHz7EHNU.js";
10
10
  import { MemoryKvStore } from "../kv-CRZrzyXm.js";
11
- import "../lookup-CiU3QxQz.js";
12
- import { KvKeyCache } from "../keycache-CVBjz3xi.js";
13
- import { test } from "../testing-ByQmUvf-.js";
11
+ import "../lookup-pV0JOsuV.js";
12
+ import { KvKeyCache } from "../keycache-CN61iGVj.js";
13
+ import { test } from "../testing-BWNCAbL-.js";
14
14
 
15
15
  //#region src/federation/keycache.test.ts
16
16
  test("KvKeyCache.set()", async () => {
@@ -3,18 +3,18 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import "../type-B4NJkfVg.js";
6
+ import "../type-C69ZBu7f.js";
7
7
  import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
8
  import "../assert-MZs1qjMx.js";
9
9
  import "../assert_instance_of-DHz7EHNU.js";
10
10
  import { MemoryKvStore } from "../kv-CRZrzyXm.js";
11
- import "../lookup-CiU3QxQz.js";
12
- import { test } from "../testing-ByQmUvf-.js";
13
- import "../std__assert-DWivtrGR.js";
14
- import "../assert_rejects-7UF4R_Qs.js";
15
- import "../assert_is_error-B035L3om.js";
16
- import "../assert_not_equals-C80BG-_5.js";
17
- import "../assert_throws-53_pKeP3.js";
11
+ import "../lookup-pV0JOsuV.js";
12
+ import { test } from "../testing-BWNCAbL-.js";
13
+ import "../std__assert-X-_kMxKM.js";
14
+ import "../assert_rejects-DiIiJbZn.js";
15
+ import "../assert_is_error-BPGph1Jx.js";
16
+ import "../assert_not_equals-f3m3epl3.js";
17
+ import "../assert_throws-BOO88avQ.js";
18
18
 
19
19
  //#region src/federation/kv.test.ts
20
20
  test("MemoryKvStore", async (t) => {
@@ -3,37 +3,51 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Activity, Announce, Create, Invite, Multikey, Note, Object as Object$1, Offer, Person, fetchDocumentLoader, getTypeId } from "../type-B4NJkfVg.js";
6
+ import { Activity, Announce, Create, Invite, Multikey, Note, Object as Object$1, Offer, Person, fetchDocumentLoader, getTypeId } from "../type-C69ZBu7f.js";
7
7
  import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
8
  import { assert } from "../assert-MZs1qjMx.js";
9
9
  import { assertInstanceOf } from "../assert_instance_of-DHz7EHNU.js";
10
10
  import { MemoryKvStore } from "../kv-CRZrzyXm.js";
11
- import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "../middleware-ByPnvMMS.js";
12
- import "../client-BW4V0OJx.js";
13
- import { RouterError, lookupObject } from "../lookup-CiU3QxQz.js";
11
+ import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "../middleware-DY9B2lL8.js";
12
+ import "../client-CnOdwLLN.js";
13
+ import { RouterError, lookupObject } from "../lookup-pV0JOsuV.js";
14
14
  import "../types-BSuWJsOm.js";
15
- import "../actor-DVpsNXhn.js";
16
- import "../key-CfiBDu3o.js";
17
- import { signRequest, verifyRequest } from "../http-Cox5GsED.js";
18
- import { getAuthenticatedDocumentLoader } from "../authdocloader-BkIZCKQv.js";
19
- import { detachSignature, signJsonLd, verifyJsonLd } from "../ld-CxgmnSO3.js";
20
- import { doesActorOwnKey } from "../owner-Cxob5_PK.js";
21
- import { signObject, verifyObject } from "../proof-BiSQNUmQ.js";
22
- import "../inbox-BDdRbWNI.js";
23
- import "../builder-E2Icrl_a.js";
15
+ import "../actor-DuCeRiNh.js";
16
+ import "../key-1KXru8Ug.js";
17
+ import { signRequest, verifyRequest } from "../http-BNOYnVsU.js";
18
+ import { getAuthenticatedDocumentLoader } from "../authdocloader-Brax1A32.js";
19
+ import { detachSignature, signJsonLd, verifyJsonLd } from "../ld-Dv8DNNAT.js";
20
+ import { doesActorOwnKey } from "../owner-e3FYDhsk.js";
21
+ import { signObject, verifyObject } from "../proof-6gFMwMNJ.js";
22
+ import "../inbox-BRru9pX3.js";
23
+ import "../builder-CYOcDUkj.js";
24
24
  import "../collection-CcnIw1qY.js";
25
- import "../keycache-CVBjz3xi.js";
26
- import "../retry-CfF8Gn4d.js";
27
- import "../send-DSEhWIYD.js";
28
- import { mockDocumentLoader, test } from "../testing-ByQmUvf-.js";
29
- import { assertStrictEquals } from "../std__assert-DWivtrGR.js";
30
- import { assertFalse, assertRejects } from "../assert_rejects-7UF4R_Qs.js";
31
- import "../assert_is_error-B035L3om.js";
32
- import { assertNotEquals } from "../assert_not_equals-C80BG-_5.js";
33
- import { assertThrows } from "../assert_throws-53_pKeP3.js";
34
- import { ed25519Multikey, ed25519PrivateKey, ed25519PublicKey, rsaPrivateKey2, rsaPrivateKey3, rsaPublicKey2, rsaPublicKey3 } from "../keys-CBKbYaJA.js";
35
- import { esm_default } from "../esm-mtx3XJAD.js";
25
+ import "../keycache-CN61iGVj.js";
26
+ import "../negotiation-5NPJL6zp.js";
27
+ import "../retry-D4GJ670a.js";
28
+ import "../send-Tl9NOnmO.js";
29
+ import { mockDocumentLoader, test } from "../testing-BWNCAbL-.js";
30
+ import { assertStrictEquals } from "../std__assert-X-_kMxKM.js";
31
+ import { assertFalse, assertRejects } from "../assert_rejects-DiIiJbZn.js";
32
+ import "../assert_is_error-BPGph1Jx.js";
33
+ import { assertNotEquals } from "../assert_not_equals-f3m3epl3.js";
34
+ import { assertThrows } from "../assert_throws-BOO88avQ.js";
35
+ import { ed25519Multikey, ed25519PrivateKey, ed25519PublicKey, rsaPrivateKey2, rsaPrivateKey3, rsaPublicKey2, rsaPublicKey3 } from "../keys-BPdFKgiy.js";
36
+ import { esm_default } from "../esm-DnIzfEj0.js";
36
37
 
38
+ //#region src/testing/fixtures/example.com/create.json
39
+ var __context$2 = "https://www.w3.org/ns/activitystreams";
40
+ var type$2 = "Create";
41
+ var id$2 = "https://example.com/create";
42
+ var actor = "https://example.com/person";
43
+ var create_default = {
44
+ "@context": __context$2,
45
+ type: type$2,
46
+ id: id$2,
47
+ actor
48
+ };
49
+
50
+ //#endregion
37
51
  //#region src/testing/fixtures/example.com/person.json
38
52
  var __context$1 = ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"];
39
53
  var id$1 = "https://example.com/person";
@@ -680,7 +694,7 @@ test({
680
694
  kv,
681
695
  documentLoaderFactory: () => mockDocumentLoader
682
696
  });
683
- const req = new Request("https://example.com/");
697
+ const req = new Request("https://example.com/", { headers: { "accept": "application/ld+json" } });
684
698
  const ctx = federation.createContext(req, 123);
685
699
  assertEquals(ctx.request, req);
686
700
  assertEquals(ctx.url, new URL("https://example.com/"));
@@ -698,7 +712,7 @@ test({
698
712
  assertEquals(await ctx.getSignedKey(), null);
699
713
  assertEquals(await ctx.getSignedKeyOwner(), null);
700
714
  await assertRejects(() => ctx.getActor("someone"), Error, "No actor dispatcher registered");
701
- const signedReq = await signRequest(new Request("https://example.com/"), rsaPrivateKey2, rsaPublicKey2.id);
715
+ const signedReq = await signRequest(new Request("https://example.com/", { headers: { "accept": "application/ld+json" } }), rsaPrivateKey2, rsaPublicKey2.id);
702
716
  const signedCtx = federation.createContext(signedReq, 456);
703
717
  assertEquals(signedCtx.request, signedReq);
704
718
  assertEquals(signedCtx.url, new URL("https://example.com/"));
@@ -707,7 +721,7 @@ test({
707
721
  assertEquals(await signedCtx.getSignedKeyOwner(), null);
708
722
  assertEquals(await signedCtx.getSignedKey(), rsaPublicKey2);
709
723
  assertEquals(await signedCtx.getSignedKeyOwner(), null);
710
- const signedReq2 = await signRequest(new Request("https://example.com/"), rsaPrivateKey3, rsaPublicKey3.id);
724
+ const signedReq2 = await signRequest(new Request("https://example.com/", { headers: { "accept": "application/ld+json" } }), rsaPrivateKey3, rsaPublicKey3.id);
711
725
  const signedCtx2 = federation.createContext(signedReq2, 456);
712
726
  assertEquals(signedCtx2.request, signedReq2);
713
727
  assertEquals(signedCtx2.url, new URL("https://example.com/"));
@@ -740,7 +754,7 @@ test({
740
754
  });
741
755
  await t.step("RequestContext.clone()", () => {
742
756
  const federation = createFederation({ kv });
743
- const req = new Request("https://example.com/");
757
+ const req = new Request("https://example.com/", { headers: { "accept": "application/ld+json" } });
744
758
  const ctx = federation.createContext(req, 123);
745
759
  const clone = ctx.clone(456);
746
760
  assertStrictEquals(clone.request, ctx.request);
@@ -756,6 +770,157 @@ test({
756
770
  esm_default.hardReset();
757
771
  }
758
772
  });
773
+ test("Federation.fetch()", async (t) => {
774
+ esm_default.spyGlobal();
775
+ esm_default.get("https://example.com/key2", {
776
+ headers: { "Content-Type": "application/activity+json" },
777
+ body: await rsaPublicKey2.toJsonLd({ contextLoader: mockDocumentLoader })
778
+ });
779
+ esm_default.get("begin:https://example.com/person", {
780
+ headers: { "Content-Type": "application/activity+json" },
781
+ body: person_default
782
+ });
783
+ const createTestContext = () => {
784
+ const kv = new MemoryKvStore();
785
+ const inbox = [];
786
+ const dispatches = [];
787
+ const federation = createFederation({
788
+ kv,
789
+ documentLoaderFactory: () => mockDocumentLoader,
790
+ authenticatedDocumentLoaderFactory(identity) {
791
+ const docLoader = getAuthenticatedDocumentLoader(identity);
792
+ return (url) => {
793
+ const urlObj = new URL(url);
794
+ if (urlObj.host === "example.com") return docLoader(url);
795
+ return mockDocumentLoader(url);
796
+ };
797
+ }
798
+ });
799
+ federation.setActorDispatcher("/users/{identifier}", (ctx, identifier) => {
800
+ dispatches.push(identifier);
801
+ return new Person({
802
+ id: ctx.getActorUri(identifier),
803
+ inbox: ctx.getInboxUri(identifier),
804
+ preferredUsername: identifier
805
+ });
806
+ }).setKeyPairsDispatcher(() => {
807
+ return [{
808
+ privateKey: rsaPrivateKey2,
809
+ publicKey: rsaPublicKey2.publicKey
810
+ }];
811
+ });
812
+ federation.setInboxDispatcher("/users/{identifier}/inbox", () => {
813
+ return { items: [] };
814
+ });
815
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, (_ctx, activity) => {
816
+ inbox.push(activity.id.toString());
817
+ return;
818
+ });
819
+ return {
820
+ federation,
821
+ inbox,
822
+ dispatches
823
+ };
824
+ };
825
+ await t.step("GET without accepts header", async () => {
826
+ const { federation, dispatches } = createTestContext();
827
+ const response = await federation.fetch(new Request("https://example.com/users/actor", { method: "GET" }), { contextData: void 0 });
828
+ assertEquals(dispatches, []);
829
+ assertEquals(response.status, 406);
830
+ });
831
+ await t.step("POST with application/json", async () => {
832
+ const { federation, inbox } = createTestContext();
833
+ const request = await signRequest(new Request("https://example.com/users/json/inbox", {
834
+ method: "POST",
835
+ headers: {
836
+ "Accept": "application/json",
837
+ "Content-Type": "application/json"
838
+ },
839
+ body: JSON.stringify(create_default)
840
+ }), rsaPrivateKey2, rsaPublicKey2.id);
841
+ const response = await federation.fetch(request, { contextData: void 0 });
842
+ assertEquals(response.status, 202);
843
+ assertEquals(inbox.length, 1, "Expected one item in the inbox, json");
844
+ assertEquals(inbox[0], create_default.id);
845
+ });
846
+ await t.step("GET with application/json", async () => {
847
+ const { federation, dispatches } = createTestContext();
848
+ const response = await federation.fetch(new Request("https://example.com/users/json", {
849
+ method: "GET",
850
+ headers: { "Accept": "application/json" }
851
+ }), { contextData: void 0 });
852
+ assertEquals(dispatches, ["json"]);
853
+ assertEquals(response.status, 200);
854
+ });
855
+ await t.step("POST with application/ld+json", async () => {
856
+ const { federation, inbox } = createTestContext();
857
+ const request = await signRequest(new Request("https://example.com/users/ld/inbox", {
858
+ method: "POST",
859
+ headers: {
860
+ "Accept": "application/ld+json",
861
+ "Content-Type": "application/activity+json"
862
+ },
863
+ body: JSON.stringify(create_default)
864
+ }), rsaPrivateKey2, rsaPublicKey2.id);
865
+ const response = await federation.fetch(request, { contextData: void 0 });
866
+ assertEquals(response.status, 202);
867
+ assertEquals(inbox.length, 1, "Expected one inbox activity, ld+json");
868
+ assertEquals(inbox[0], create_default.id);
869
+ });
870
+ await t.step("GET with application/ld+json", async () => {
871
+ const { federation, dispatches } = createTestContext();
872
+ const request = new Request("https://example.com/users/ld", {
873
+ method: "GET",
874
+ headers: { "Accept": "application/ld+json" }
875
+ });
876
+ const response = await federation.fetch(request, { contextData: void 0 });
877
+ assertEquals(dispatches, ["ld"]);
878
+ assertEquals(response.status, 200);
879
+ });
880
+ await t.step("POST with application/activity+json", async () => {
881
+ const { federation, inbox } = createTestContext();
882
+ const request = await signRequest(new Request("https://example.com/users/activity/inbox", {
883
+ method: "POST",
884
+ headers: {
885
+ "Accept": "application/activity+json",
886
+ "Content-Type": "application/activity+json"
887
+ },
888
+ body: JSON.stringify(create_default)
889
+ }), rsaPrivateKey2, rsaPublicKey2.id);
890
+ const response = await federation.fetch(request, { contextData: void 0 });
891
+ assertEquals(response.status, 202);
892
+ assertEquals(inbox.length, 1);
893
+ assertEquals(inbox[0], create_default.id);
894
+ });
895
+ await t.step("GET with application/activity+json", async () => {
896
+ const { federation, dispatches } = createTestContext();
897
+ const request = new Request("https://example.com/users/activity", {
898
+ method: "GET",
899
+ headers: { "Accept": "application/ld+json" }
900
+ });
901
+ const response = await federation.fetch(request, { contextData: void 0 });
902
+ assertEquals(dispatches, ["activity"]);
903
+ assertEquals(response.status, 200);
904
+ });
905
+ await t.step("onNotAcceptable with GET", async () => {
906
+ const { federation } = createTestContext();
907
+ let notAcceptableCalled = false;
908
+ const response = await federation.fetch(new Request("https://example.com/users/html", {
909
+ method: "GET",
910
+ headers: { "Accept": "text/html" }
911
+ }), {
912
+ contextData: void 0,
913
+ onNotAcceptable: () => {
914
+ notAcceptableCalled = true;
915
+ return new Response("handled by onNotAcceptable", { status: 200 });
916
+ }
917
+ });
918
+ assertEquals(notAcceptableCalled, true);
919
+ assertEquals(response.status, 200);
920
+ assertEquals(await response.text(), "handled by onNotAcceptable");
921
+ });
922
+ esm_default.hardReset();
923
+ });
759
924
  test("Federation.setInboxListeners()", async (t) => {
760
925
  const kv = new MemoryKvStore();
761
926
  esm_default.spyGlobal();
@@ -808,7 +973,10 @@ test("Federation.setInboxListeners()", async (t) => {
808
973
  federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, (ctx, create) => {
809
974
  inbox.push([ctx, create]);
810
975
  });
811
- let response = await federation.fetch(new Request("https://example.com/inbox", { method: "POST" }), { contextData: void 0 });
976
+ let response = await federation.fetch(new Request("https://example.com/inbox", {
977
+ method: "POST",
978
+ headers: { "accept": "application/ld+json" }
979
+ }), { contextData: void 0 });
812
980
  assertEquals(inbox, []);
813
981
  assertEquals(response.status, 404);
814
982
  federation.setActorDispatcher("/users/{identifier}", (_, identifier) => identifier === "john" ? new Person({}) : null).setKeyPairsDispatcher(() => [{
@@ -825,23 +993,37 @@ test("Federation.setInboxListeners()", async (t) => {
825
993
  });
826
994
  response = await federation.fetch(new Request("https://example.com/inbox", {
827
995
  method: "POST",
828
- body: JSON.stringify(await activity().toJsonLd(options))
996
+ body: JSON.stringify(await activity().toJsonLd(options)),
997
+ headers: {
998
+ "accept": "application/ld+json",
999
+ "content-type": "application/ld+json"
1000
+ }
829
1001
  }), { contextData: void 0 });
830
1002
  assertEquals(inbox, []);
831
1003
  assertEquals(response.status, 401);
832
- response = await federation.fetch(new Request("https://example.com/users/no-one/inbox", { method: "POST" }), { contextData: void 0 });
1004
+ response = await federation.fetch(new Request("https://example.com/users/no-one/inbox", {
1005
+ method: "POST",
1006
+ headers: { "accept": "application/ld+json" }
1007
+ }), { contextData: void 0 });
833
1008
  assertEquals(inbox, []);
834
1009
  assertEquals(response.status, 404);
835
1010
  response = await federation.fetch(new Request("https://example.com/users/john/inbox", {
836
1011
  method: "POST",
837
- body: JSON.stringify(await activity().toJsonLd(options))
1012
+ body: JSON.stringify(await activity().toJsonLd(options)),
1013
+ headers: {
1014
+ "accept": "application/ld+json",
1015
+ "content-type": "application/ld+json"
1016
+ }
838
1017
  }), { contextData: void 0 });
839
1018
  assertEquals(inbox, []);
840
1019
  assertEquals(response.status, 401);
841
1020
  const activityPayload = await activity().toJsonLd(options);
842
1021
  let request = new Request("https://example.com/users/john/inbox", {
843
1022
  method: "POST",
844
- headers: { "Content-Type": "application/activity+json" },
1023
+ headers: {
1024
+ "Content-Type": "application/activity+json",
1025
+ accept: "application/ld+json"
1026
+ },
845
1027
  body: JSON.stringify(activityPayload)
846
1028
  });
847
1029
  request = await signRequest(request, rsaPrivateKey3, new URL("https://example.com/person2#key3"));
@@ -858,7 +1040,10 @@ test("Federation.setInboxListeners()", async (t) => {
858
1040
  inbox.shift();
859
1041
  request = new Request("https://another.host/users/john/inbox", {
860
1042
  method: "POST",
861
- headers: { "Content-Type": "application/activity+json" },
1043
+ headers: {
1044
+ "Content-Type": "application/activity+json",
1045
+ "accept": "application/ld+json"
1046
+ },
862
1047
  body: JSON.stringify(activityPayload)
863
1048
  });
864
1049
  request = await signRequest(request, rsaPrivateKey3, new URL("https://example.com/person2#key3"));
@@ -873,7 +1058,10 @@ test("Federation.setInboxListeners()", async (t) => {
873
1058
  inbox.shift();
874
1059
  request = new Request("https://example.com/inbox", {
875
1060
  method: "POST",
876
- headers: { "Content-Type": "application/activity+json" },
1061
+ headers: {
1062
+ "Content-Type": "application/activity+json",
1063
+ "accept": "application/ld+json"
1064
+ },
877
1065
  body: JSON.stringify(await activity().toJsonLd(options))
878
1066
  });
879
1067
  request = await signRequest(request, rsaPrivateKey3, new URL("https://example.com/person2#key3"));
@@ -888,7 +1076,10 @@ test("Federation.setInboxListeners()", async (t) => {
888
1076
  inbox.shift();
889
1077
  request = new Request("https://example.com/users/john/inbox", {
890
1078
  method: "POST",
891
- headers: { "Content-Type": "application/activity+json" },
1079
+ headers: {
1080
+ "Content-Type": "application/activity+json",
1081
+ "accept": "application/ld+json"
1082
+ },
892
1083
  body: JSON.stringify(await (await signObject(activity(), ed25519PrivateKey, ed25519Multikey.id, options)).toJsonLd(options))
893
1084
  });
894
1085
  response = await federation.fetch(request, { contextData: void 0 });
@@ -927,7 +1118,10 @@ test("Federation.setInboxListeners()", async (t) => {
927
1118
  const activity = new Create({ actor: new URL("https://example.com/person") });
928
1119
  let request = new Request("https://example.com/users/john/inbox", {
929
1120
  method: "POST",
930
- headers: { "Content-Type": "application/activity+json" },
1121
+ headers: {
1122
+ "Content-Type": "application/activity+json",
1123
+ "Accept": "application/activity+json"
1124
+ },
931
1125
  body: JSON.stringify(await activity.toJsonLd({ contextLoader: mockDocumentLoader }))
932
1126
  });
933
1127
  request = await signRequest(request, rsaPrivateKey2, new URL("https://example.com/key2"));
@@ -1243,7 +1437,7 @@ test("ContextImpl.sendActivity()", async (t) => {
1243
1437
  collectionSyncHeader = cl.request.headers.get("Collection-Synchronization");
1244
1438
  const options = {
1245
1439
  async documentLoader(url) {
1246
- const response = await federation.fetch(new Request(url), { contextData: void 0 });
1440
+ const response = await federation.fetch(new Request(url, { headers: { "accept": "application/ld+json" } }), { contextData: void 0 });
1247
1441
  if (response.ok) return {
1248
1442
  contextUrl: null,
1249
1443
  document: await response.json(),