@fedify/fedify 2.3.0-dev.1119 → 2.3.0-dev.1137

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 (116) hide show
  1. package/README.md +3 -0
  2. package/dist/{assert-DikXweDx.mjs → assert-OguE97r2.mjs} +1 -1
  3. package/dist/{assert_instance_of-C4Ri6VuN.mjs → assert_instance_of-DBC5X09g.mjs} +1 -1
  4. package/dist/{assert_not_equals--wG9hV7u.mjs → assert_not_equals-DkVK8oqV.mjs} +1 -1
  5. package/dist/{assert_rejects-DQP-q39h.mjs → assert_rejects-DN60FHPX.mjs} +2 -2
  6. package/dist/{assert_strict_equals-Dmjbg-bA.mjs → assert_strict_equals-XEgZAlrj.mjs} +1 -1
  7. package/dist/{assert_throws-4NwKEy2q.mjs → assert_throws-BOkhLGYc.mjs} +1 -1
  8. package/dist/{builder-Ond_h57y.mjs → builder-BCkBXxky.mjs} +60 -41
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/outgoing-jsonld.test.mjs +3 -3
  12. package/dist/compat/public-audience.test.mjs +3 -3
  13. package/dist/compat/transformers.test.mjs +5 -5
  14. package/dist/{context-cSUMk2da.d.ts → context-DCtsSHDv.d.ts} +4 -293
  15. package/dist/{context-Ch-ZLyTQ.d.cts → context-DI2gRbyN.d.cts} +3 -294
  16. package/dist/{context-BAE7AKLA.mjs → context-DVoTs_wM.mjs} +1 -1
  17. package/dist/{deno-DVsHS7rA.mjs → deno-B_9yJW3w.mjs} +1 -1
  18. package/dist/{docloader-WsWfKaE5.mjs → docloader-BT89tyFr.mjs} +3 -3
  19. package/dist/federation/builder.test.mjs +138 -10
  20. package/dist/federation/collection.test.mjs +3 -3
  21. package/dist/federation/handler.test.mjs +12 -12
  22. package/dist/federation/idempotency.test.mjs +6 -6
  23. package/dist/federation/inbox.test.mjs +3 -3
  24. package/dist/federation/keycache.test.mjs +5 -5
  25. package/dist/federation/kv.test.mjs +3 -3
  26. package/dist/federation/metrics.test.mjs +231 -3
  27. package/dist/federation/middleware.test.mjs +88 -18
  28. package/dist/federation/mod.cjs +155 -3
  29. package/dist/federation/mod.d.cts +3 -2
  30. package/dist/federation/mod.d.ts +3 -2
  31. package/dist/federation/mod.js +153 -1
  32. package/dist/federation/mq.test.mjs +5 -5
  33. package/dist/federation/negotiation.test.mjs +4 -4
  34. package/dist/federation/retry.test.mjs +3 -3
  35. package/dist/federation/router.test.mjs +190 -9
  36. package/dist/federation/send.test.mjs +16 -16
  37. package/dist/federation/webfinger.test.mjs +5 -5
  38. package/dist/{getMachineId-bsd-BY01PL1n.mjs → getMachineId-bsd-etIyxDet.mjs} +1 -1
  39. package/dist/{getMachineId-darwin-Dr1gkBkp.mjs → getMachineId-darwin-D23zTf4g.mjs} +1 -1
  40. package/dist/{getMachineId-win-QEYwcJiy.mjs → getMachineId-win-Dpap6v5i.mjs} +1 -1
  41. package/dist/{http-CouJSFVK.js → http-CToqG5ap.js} +252 -20
  42. package/dist/{http-CubOB9wq.cjs → http-CWoeyogl.cjs} +263 -19
  43. package/dist/{http-DUV8ysti.mjs → http-Cyx5SNuu.mjs} +8 -6
  44. package/dist/{http-D6LP89UO.d.ts → http-VyDTd4G3.d.cts} +8 -1
  45. package/dist/{http-D6aw3j2U.d.cts → http-lf8Hsd91.d.ts} +8 -1
  46. package/dist/{key-BoWaYRHm.mjs → key-CkkMJBjF.mjs} +42 -17
  47. package/dist/{kv-cache-DBNpsneh.js → kv-cache-CuCn2xvM.js} +19 -2
  48. package/dist/{kv-cache-Dz31ATUT.cjs → kv-cache-DuEwFYcN.cjs} +19 -2
  49. package/dist/{kv-cache-DihufyAQ.mjs → kv-cache-VHFP42vY.mjs} +19 -1
  50. package/dist/{ld-B5K1mSuG.mjs → ld-k8yqD2a-.mjs} +3 -3
  51. package/dist/{metrics-C4attqv0.mjs → metrics-iRBg8jTk.mjs} +209 -2
  52. package/dist/{middleware-CmsDtIHI.cjs → middleware-BWLUrbS9.cjs} +137 -210
  53. package/dist/{middleware-BDKFRjue.mjs → middleware-CztxpARM.mjs} +1 -1
  54. package/dist/{middleware-Dtjz-hSk.js → middleware-D7FrhN9q.js} +101 -162
  55. package/dist/{middleware-t0jC8I99.mjs → middleware-DQEgdr83.mjs} +64 -36
  56. package/dist/{mod-BDhgfjP7.d.cts → mod-B0hW12_O.d.cts} +1 -1
  57. package/dist/mod-C504qevA.d.cts +173 -0
  58. package/dist/{mod-B-Lin9Sy.d.ts → mod-COIAjwRS.d.ts} +1 -1
  59. package/dist/{mod-DLrRb0dx.d.ts → mod-DFvNJcNb.d.ts} +54 -3
  60. package/dist/mod-wYfuXeDE.d.ts +173 -0
  61. package/dist/{mod-BR_BB0bh.d.cts → mod-yvIXFAEi.d.cts} +54 -3
  62. package/dist/mod.cjs +6 -6
  63. package/dist/mod.d.cts +6 -5
  64. package/dist/mod.d.ts +6 -5
  65. package/dist/mod.js +5 -5
  66. package/dist/mq-D-nlpY04.d.ts +208 -0
  67. package/dist/mq-D8uSFzxe.d.cts +208 -0
  68. package/dist/nodeinfo/client.test.mjs +4 -4
  69. package/dist/nodeinfo/handler.test.mjs +5 -5
  70. package/dist/nodeinfo/types.test.mjs +4 -4
  71. package/dist/otel/exporter.test.mjs +3 -3
  72. package/dist/{outgoing-jsonld-BNL8AC14.mjs → outgoing-jsonld-BgFLCJQ_.mjs} +1 -1
  73. package/dist/{owner-hDxI0ufu.mjs → owner-nmXdvXpc.mjs} +2 -2
  74. package/dist/{proof-BUWfVr6Q.cjs → proof-CcsIJLTn.cjs} +1 -1
  75. package/dist/{proof-DhVuz4bc.mjs → proof-DpwO1T4S.mjs} +5 -5
  76. package/dist/{proof-n60t8o9P.js → proof-NRmtrTDu.js} +1 -1
  77. package/dist/{send-BPhyR5Oo.mjs → send-DvX2tYyZ.mjs} +3 -3
  78. package/dist/sig/accept.test.mjs +1 -1
  79. package/dist/sig/http.test.mjs +13 -9
  80. package/dist/sig/key.test.mjs +104 -7
  81. package/dist/sig/ld.test.mjs +7 -7
  82. package/dist/sig/mod.cjs +2 -2
  83. package/dist/sig/mod.d.cts +2 -2
  84. package/dist/sig/mod.d.ts +2 -2
  85. package/dist/sig/mod.js +2 -2
  86. package/dist/sig/owner.test.mjs +6 -6
  87. package/dist/sig/proof.test.mjs +8 -8
  88. package/dist/{std__assert-BTEgfoJo.mjs → std__assert-BBjXFNOb.mjs} +4 -4
  89. package/dist/testing/mod.d.mts +1 -0
  90. package/dist/testing/mod.mjs +1 -1
  91. package/dist/utils/docloader.test.mjs +7 -7
  92. package/dist/utils/kv-cache.test.mjs +67 -2
  93. package/dist/utils/mod.cjs +1 -1
  94. package/dist/utils/mod.d.cts +1 -1
  95. package/dist/utils/mod.d.ts +1 -1
  96. package/dist/utils/mod.js +1 -1
  97. package/package.json +6 -7
  98. package/dist/mod-C6E8rkcz.d.ts +0 -63
  99. package/dist/mod-P9tE2WmM.d.cts +0 -63
  100. package/dist/router-BT_F5748.mjs +0 -114
  101. /package/dist/{accept-CgDcxvjV.mjs → accept-CceiKpCy.mjs} +0 -0
  102. /package/dist/{activity-listener-BeTGV3wc.mjs → activity-listener-tztVvlNb.mjs} +0 -0
  103. /package/dist/{assert_equals-Ew3jOFa3.mjs → assert_equals-C-ZRDbaf.mjs} +0 -0
  104. /package/dist/{client-Bneh_DYR.mjs → client-B_A6mfn3.mjs} +0 -0
  105. /package/dist/{collection-Cc3DVAhE.mjs → collection-CA3V5zyK.mjs} +0 -0
  106. /package/dist/{esm-sdtqOUPu.mjs → esm-BQRw925N.mjs} +0 -0
  107. /package/dist/{execAsync-Dxb7rNf3.mjs → execAsync-DCBrgFiV.mjs} +0 -0
  108. /package/dist/{getMachineId-linux-Bbhofx-s.mjs → getMachineId-linux-ObI47Hql.mjs} +0 -0
  109. /package/dist/{getMachineId-unsupported-dIOte2Ct.mjs → getMachineId-unsupported-Ddu-PFeh.mjs} +0 -0
  110. /package/dist/{keycache-BeU0LCII.mjs → keycache-BYMd8q7F.mjs} +0 -0
  111. /package/dist/{keys-CSYsOMFG.mjs → keys-C3kae-6B.mjs} +0 -0
  112. /package/dist/{kv-QHE0oeM3.mjs → kv-x2IvBUyq.mjs} +0 -0
  113. /package/dist/{negotiation-DDstyBvc.mjs → negotiation-CDW-_gUU.mjs} +0 -0
  114. /package/dist/{public-audience-c9zmYKgA.mjs → public-audience-N3pyOx2p.mjs} +0 -0
  115. /package/dist/{retry-_VvV0h9f.mjs → retry-v_sGLH1d.mjs} +0 -0
  116. /package/dist/{types-D09GN0uZ.mjs → types-BFowWFTT.mjs} +0 -0
@@ -1,11 +1,11 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { o as validateCryptoKey } from "./key-BoWaYRHm.mjs";
5
- import { n as doubleKnock } from "./http-DUV8ysti.mjs";
4
+ import { o as validateCryptoKey } from "./key-CkkMJBjF.mjs";
5
+ import { n as doubleKnock } from "./http-Cyx5SNuu.mjs";
6
6
  import { getLogger } from "@logtape/logtape";
7
- import { curry } from "es-toolkit";
8
7
  import { UrlError, createActivityPubRequest, getRemoteDocument, logRequest, validatePublicUrl } from "@fedify/vocab-runtime";
8
+ import { curry } from "es-toolkit";
9
9
  //#region src/utils/docloader.ts
10
10
  const logger = getLogger([
11
11
  "fedify",
@@ -1,12 +1,12 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as RouterError } from "../router-BT_F5748.mjs";
5
- import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
- import { r as assertExists } from "../std__assert-BTEgfoJo.mjs";
7
- import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
8
- import { t as MemoryKvStore } from "../kv-QHE0oeM3.mjs";
9
- import { r as createFederationBuilder } from "../builder-Ond_h57y.mjs";
4
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
+ import { r as assertExists } from "../std__assert-BBjXFNOb.mjs";
6
+ import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
7
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
8
+ import { r as createFederationBuilder } from "../builder-BCkBXxky.mjs";
9
+ import { DisallowedOperatorError, DisallowedVarSpecModifierError, DuplicateRouteVariableError, RouteTemplateOptionsNotMatchedError, RouterError } from "@fedify/uri-template";
10
10
  import { Activity, Note, Person } from "@fedify/vocab";
11
11
  import { test } from "@fedify/fixture";
12
12
  //#region src/federation/builder.test.ts
@@ -74,6 +74,21 @@ test("FederationBuilder", async (t) => {
74
74
  assertEquals(impl.router.build("inbox", { identifier: "user1" }), "/users/user1/inbox");
75
75
  await builder.build({ kv });
76
76
  });
77
+ await t.step("should snapshot router state on build", async () => {
78
+ const builder = createFederationBuilder();
79
+ const kv = new MemoryKvStore();
80
+ const noteRouteName = `object:${Note.typeId.href}`;
81
+ builder.setActorDispatcher("/users/{identifier}", () => null);
82
+ const impl1 = await builder.build({ kv });
83
+ builder.setObjectDispatcher(Note, "/notes/{id}", () => null);
84
+ assertEquals(impl1.router.route("/notes/1"), null);
85
+ const impl2 = await builder.build({ kv });
86
+ assertEquals(impl2.router.route("/notes/1")?.name, noteRouteName);
87
+ impl1.router.add("/leaked/{id}", "leaked");
88
+ assertEquals(impl1.router.route("/leaked/1")?.name, "leaked");
89
+ assertEquals(impl2.router.route("/leaked/1"), null);
90
+ assertEquals((await builder.build({ kv })).router.route("/leaked/1"), null);
91
+ });
77
92
  await t.step("should build with default options", async () => {
78
93
  const builder = createFederationBuilder();
79
94
  const kv = new MemoryKvStore();
@@ -89,15 +104,128 @@ test("FederationBuilder", async (t) => {
89
104
  assertThrows(() => builder.setOutboxListeners("/users/{identifier}/outbox/{extra}"), RouterError);
90
105
  assertThrows(() => builder.setOutboxListeners("/users/{identifier}/outbox/{identifier}"), RouterError);
91
106
  const builderAfterInvalid = createFederationBuilder();
92
- assertThrows(() => builderAfterInvalid.setOutboxListeners("/users/{identifier}/outbox/{extra}"), RouterError);
107
+ assertThrows(() => builderAfterInvalid.setOutboxListeners("/users/{identifier}/outbox/{extra}"), RouteTemplateOptionsNotMatchedError);
108
+ assertThrows(() => builderAfterInvalid.setOutboxListeners("/users/{identifier:3}/outbox"), DisallowedVarSpecModifierError);
109
+ assertThrows(() => builderAfterInvalid.setOutboxListeners("/users/{identifier*}/outbox"), DisallowedVarSpecModifierError);
110
+ assertThrows(() => builderAfterInvalid.setOutboxListeners("/users/{identifier,identifier}/outbox"), DuplicateRouteVariableError);
93
111
  builderAfterInvalid.setOutboxListeners("/users/{identifier}/outbox");
94
112
  const builder2 = createFederationBuilder();
95
- builder2.setOutboxListeners("/users{/identifier}/outbox");
113
+ builder2.setOutboxListeners("/users/{identifier}/outbox");
96
114
  assertThrows(() => builder2.setOutboxDispatcher("/actors/{identifier}/outbox", () => ({ items: [] })), RouterError);
97
115
  const builder3 = createFederationBuilder();
98
- assertThrows(() => builder3.setOutboxListeners("/users{?identifier}/outbox"), RouterError);
116
+ assertThrows(() => builder3.setOutboxListeners("/users{?identifier}/outbox"), DisallowedOperatorError);
117
+ const builder3a = createFederationBuilder();
118
+ assertThrows(() => builder3a.setOutboxListeners("/users{;identifier}/outbox"), DisallowedOperatorError);
119
+ const builder3b = createFederationBuilder();
120
+ assertThrows(() => builder3b.setOutboxListeners("/users{.identifier}/outbox"), DisallowedOperatorError);
99
121
  const builder4 = createFederationBuilder();
100
- assertThrows(() => builder4.setOutboxDispatcher("/users{?identifier}/outbox", () => ({ items: [] })), RouterError);
122
+ assertThrows(() => builder4.setOutboxDispatcher("/users{?identifier}/outbox", () => ({ items: [] })), DisallowedOperatorError);
123
+ const builder5 = createFederationBuilder();
124
+ assertThrows(() => builder5.setOutboxDispatcher("/users/{identifier:3}/outbox", () => ({ items: [] })), DisallowedVarSpecModifierError);
125
+ });
126
+ await t.step("rejects non-segment-boundary identifier operators at registration for required-identifier routes", () => {
127
+ assertThrows(() => createFederationBuilder().setActorDispatcher("/users{/identifier}", () => null), DisallowedOperatorError);
128
+ assertThrows(() => createFederationBuilder().setActorDispatcher("{/identifier}", () => null), DisallowedOperatorError);
129
+ assertThrows(() => createFederationBuilder().setActorDispatcher("/users/{/identifier}", () => null), DisallowedOperatorError);
130
+ assertThrows(() => createFederationBuilder().setActorDispatcher("/users{?identifier}", () => null), DisallowedOperatorError);
131
+ assertThrows(() => createFederationBuilder().setInboxListeners("/users{/identifier}/inbox"), DisallowedOperatorError);
132
+ assertThrows(() => createFederationBuilder().setOutboxListeners("/users{/identifier}/outbox"), DisallowedOperatorError);
133
+ assertThrows(() => createFederationBuilder().setActorDispatcher("/users/{identifier:3}", () => null), DisallowedVarSpecModifierError);
134
+ assertThrows(() => createFederationBuilder().setActorDispatcher("/users/{identifier*}", () => null), DisallowedVarSpecModifierError);
135
+ createFederationBuilder().setActorDispatcher("/users/{identifier}", () => null);
136
+ createFederationBuilder().setInboxListeners("/users/{identifier}/inbox");
137
+ });
138
+ await t.step("every required-identifier setter rejects every omissible operator", () => {
139
+ const omissibleExprs = [
140
+ "{/identifier}",
141
+ "{?identifier}",
142
+ "{;identifier}",
143
+ "{.identifier}"
144
+ ];
145
+ const registrars = [
146
+ ["setActorDispatcher", (expr) => createFederationBuilder().setActorDispatcher(`/users${expr}`, () => null)],
147
+ ["setInboxListeners", (expr) => createFederationBuilder().setInboxListeners(`/users${expr}/inbox`)],
148
+ ["setOutboxListeners", (expr) => createFederationBuilder().setOutboxListeners(`/users${expr}/outbox`)],
149
+ ["setOutboxDispatcher", (expr) => createFederationBuilder().setOutboxDispatcher(`/users${expr}/outbox`, () => ({ items: [] }))],
150
+ ["setFollowingDispatcher", (expr) => createFederationBuilder().setFollowingDispatcher(`/users${expr}/following`, () => ({ items: [] }))],
151
+ ["setFollowersDispatcher", (expr) => createFederationBuilder().setFollowersDispatcher(`/users${expr}/followers`, () => ({ items: [] }))],
152
+ ["setLikedDispatcher", (expr) => createFederationBuilder().setLikedDispatcher(`/users${expr}/liked`, () => ({ items: [] }))],
153
+ ["setFeaturedDispatcher", (expr) => createFederationBuilder().setFeaturedDispatcher(`/users${expr}/featured`, () => ({ items: [] }))],
154
+ ["setFeaturedTagsDispatcher", (expr) => createFederationBuilder().setFeaturedTagsDispatcher(`/users${expr}/tags`, () => ({ items: [] }))]
155
+ ];
156
+ for (const [name, register] of registrars) {
157
+ for (const expr of omissibleExprs) assertThrows(() => register(expr), DisallowedOperatorError, void 0, `${name} must reject ${expr} at registration`);
158
+ register("{identifier}");
159
+ }
160
+ });
161
+ await t.step("empty or missing identifier segments produce a runtime no-match", async () => {
162
+ const kv = new MemoryKvStore();
163
+ const builder = createFederationBuilder();
164
+ builder.setActorDispatcher("/users/{identifier}", () => null);
165
+ builder.setInboxListeners("/users/{identifier}/inbox");
166
+ builder.setOutboxDispatcher("/users/{identifier}/outbox", () => ({ items: [] }));
167
+ builder.setObjectDispatcher(Note, "/notes/{id}", () => null);
168
+ const impl = await builder.build({ kv });
169
+ assertEquals(impl.router.route("/users/alice")?.name, "actor");
170
+ assertEquals(impl.router.route("/users/alice/inbox")?.name, "inbox");
171
+ assertEquals(impl.router.route("/users/alice/outbox")?.name, "outbox");
172
+ assertEquals(impl.router.route("/notes/1")?.name, `object:${Note.typeId.href}`);
173
+ assertEquals(impl.router.route("/users/"), null);
174
+ assertEquals(impl.router.route("/users//inbox"), null);
175
+ assertEquals(impl.router.route("/users//outbox"), null);
176
+ assertEquals(impl.router.route("/notes/"), null);
177
+ });
178
+ await t.step("object dispatcher optional-operator routes no-match when unbound", async () => {
179
+ const kv = new MemoryKvStore();
180
+ const objectName = `object:${Note.typeId.href}`;
181
+ const query = createFederationBuilder();
182
+ query.setObjectDispatcher(Note, "/notes{?id}", () => null);
183
+ const queryImpl = await query.build({ kv });
184
+ assertEquals(queryImpl.router.route("/notes"), null);
185
+ assertEquals(queryImpl.router.route("/notes?id=1")?.name, objectName);
186
+ const matrix = createFederationBuilder();
187
+ matrix.setObjectDispatcher(Note, "/notes{;id}", () => null);
188
+ const matrixImpl = await matrix.build({ kv });
189
+ assertEquals(matrixImpl.router.route("/notes"), null);
190
+ assertEquals(matrixImpl.router.route("/notes;id=1")?.name, objectName);
191
+ const label = createFederationBuilder();
192
+ label.setObjectDispatcher(Note, "/notes{.id}", () => null);
193
+ const labelImpl = await label.build({ kv });
194
+ assertEquals(labelImpl.router.route("/notes"), null);
195
+ assertEquals(labelImpl.router.route("/notes.1")?.name, objectName);
196
+ });
197
+ await t.step("custom collection routes no-match empty or unbound variables", async () => {
198
+ const kv = new MemoryKvStore();
199
+ const builder = createFederationBuilder();
200
+ builder.setCollectionDispatcher("samples", Note, "/groups/{id}", () => ({ items: [] }));
201
+ builder.setCollectionDispatcher("optionals", Note, "/optional-groups{?id}", () => ({ items: [] }));
202
+ builder.setCollectionDispatcher("matrixOptionals", Note, "/matrix-groups{;id}", () => ({ items: [] }));
203
+ builder.setCollectionDispatcher("labelOptionals", Note, "/label-groups{.id}", () => ({ items: [] }));
204
+ const impl = await builder.build({ kv });
205
+ assertEquals(impl.router.route("/groups/1"), {
206
+ name: "collection:samples",
207
+ values: { id: "1" },
208
+ template: "/groups/{id}"
209
+ });
210
+ assertEquals(impl.router.route("/optional-groups?id=1"), {
211
+ name: "collection:optionals",
212
+ values: { id: "1" },
213
+ template: "/optional-groups{?id}"
214
+ });
215
+ assertEquals(impl.router.route("/matrix-groups;id=1"), {
216
+ name: "collection:matrixOptionals",
217
+ values: { id: "1" },
218
+ template: "/matrix-groups{;id}"
219
+ });
220
+ assertEquals(impl.router.route("/label-groups.1"), {
221
+ name: "collection:labelOptionals",
222
+ values: { id: "1" },
223
+ template: "/label-groups{.id}"
224
+ });
225
+ assertEquals(impl.router.route("/groups/"), null);
226
+ assertEquals(impl.router.route("/optional-groups"), null);
227
+ assertEquals(impl.router.route("/matrix-groups"), null);
228
+ assertEquals(impl.router.route("/label-groups"), null);
101
229
  });
102
230
  await t.step("should pass build options correctly", async () => {
103
231
  const builder = createFederationBuilder();
@@ -1,9 +1,9 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
- import "../std__assert-BTEgfoJo.mjs";
6
- import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-Cc3DVAhE.mjs";
4
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
+ import "../std__assert-BBjXFNOb.mjs";
6
+ import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-CA3V5zyK.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { decodeHex } from "byte-encodings/hex";
9
9
  //#region src/federation/collection.test.ts
@@ -1,18 +1,18 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-BAE7AKLA.mjs";
5
- import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
- import "../std__assert-BTEgfoJo.mjs";
7
- import { n as assertGreaterOrEqual } from "../assert_rejects-DQP-q39h.mjs";
8
- import { t as assertInstanceOf } from "../assert_instance_of-C4Ri6VuN.mjs";
9
- import { t as assert } from "../assert-DikXweDx.mjs";
10
- import { r as parseAcceptSignature } from "../accept-CgDcxvjV.mjs";
11
- import { s as signRequest } from "../http-DUV8ysti.mjs";
12
- import { a as rsaPrivateKey3, c as rsaPublicKey3, s as rsaPublicKey2 } from "../keys-CSYsOMFG.mjs";
13
- import { t as MemoryKvStore } from "../kv-QHE0oeM3.mjs";
14
- import { c as handleActor, d as handleInbox, f as handleObject, h as respondWithObjectIfAcceptable, l as handleCollection, m as respondWithObject, o as createFederation, p as handleOutbox, u as handleCustomCollection } from "../middleware-t0jC8I99.mjs";
15
- import { t as ActivityListenerSet } from "../activity-listener-BeTGV3wc.mjs";
4
+ import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-DVoTs_wM.mjs";
5
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
6
+ import "../std__assert-BBjXFNOb.mjs";
7
+ import { n as assertGreaterOrEqual } from "../assert_rejects-DN60FHPX.mjs";
8
+ import { t as assertInstanceOf } from "../assert_instance_of-DBC5X09g.mjs";
9
+ import { t as assert } from "../assert-OguE97r2.mjs";
10
+ import { r as parseAcceptSignature } from "../accept-CceiKpCy.mjs";
11
+ import { s as signRequest } from "../http-Cyx5SNuu.mjs";
12
+ import { a as rsaPrivateKey3, c as rsaPublicKey3, s as rsaPublicKey2 } from "../keys-C3kae-6B.mjs";
13
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
14
+ import { c as handleActor, d as handleInbox, f as handleObject, h as respondWithObjectIfAcceptable, l as handleCollection, m as respondWithObject, o as createFederation, p as handleOutbox, u as handleCustomCollection } from "../middleware-DQEgdr83.mjs";
15
+ import { t as ActivityListenerSet } from "../activity-listener-tztVvlNb.mjs";
16
16
  import { Activity, Create, Note, Person, Tombstone } from "@fedify/vocab";
17
17
  import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
18
18
  import { FetchError } from "@fedify/vocab-runtime";
@@ -1,12 +1,12 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
- import "../std__assert-BTEgfoJo.mjs";
6
- import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-CSYsOMFG.mjs";
7
- import { r as signObject } from "../proof-DhVuz4bc.mjs";
8
- import { t as MemoryKvStore } from "../kv-QHE0oeM3.mjs";
9
- import { o as createFederation } from "../middleware-t0jC8I99.mjs";
4
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
+ import "../std__assert-BBjXFNOb.mjs";
6
+ import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-C3kae-6B.mjs";
7
+ import { r as signObject } from "../proof-DpwO1T4S.mjs";
8
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
9
+ import { o as createFederation } from "../middleware-DQEgdr83.mjs";
10
10
  import { Create, Follow, Person } from "@fedify/vocab";
11
11
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
12
  //#region src/federation/idempotency.test.ts
@@ -1,9 +1,9 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
- import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
6
- import { t as ActivityListenerSet } from "../activity-listener-BeTGV3wc.mjs";
4
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
+ import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
6
+ import { t as ActivityListenerSet } from "../activity-listener-tztVvlNb.mjs";
7
7
  import { Activity, Create, Invite, Offer, Update } from "@fedify/vocab";
8
8
  import { test } from "@fedify/fixture";
9
9
  //#region src/federation/inbox.test.ts
@@ -1,11 +1,11 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
- import { t as assertInstanceOf } from "../assert_instance_of-C4Ri6VuN.mjs";
6
- import { t as assert } from "../assert-DikXweDx.mjs";
7
- import { t as MemoryKvStore } from "../kv-QHE0oeM3.mjs";
8
- import { t as KvKeyCache } from "../keycache-BeU0LCII.mjs";
4
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
+ import { t as assertInstanceOf } from "../assert_instance_of-DBC5X09g.mjs";
6
+ import { t as assert } from "../assert-OguE97r2.mjs";
7
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
8
+ import { t as KvKeyCache } from "../keycache-BYMd8q7F.mjs";
9
9
  import { CryptographicKey, Multikey } from "@fedify/vocab";
10
10
  import { test } from "@fedify/fixture";
11
11
  //#region src/federation/keycache.test.ts
@@ -1,9 +1,9 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
- import "../std__assert-BTEgfoJo.mjs";
6
- import { t as MemoryKvStore } from "../kv-QHE0oeM3.mjs";
4
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
+ import "../std__assert-BBjXFNOb.mjs";
6
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  //#region src/federation/kv.test.ts
9
9
  test("MemoryKvStore", async (t) => {
@@ -1,10 +1,12 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
- import "../std__assert-BTEgfoJo.mjs";
6
- import { c as recordOutboxActivity, l as recordOutboxEnqueue, o as recordFanoutRecipients, s as recordInboxActivity } from "../metrics-C4attqv0.mjs";
4
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
+ import "../std__assert-BBjXFNOb.mjs";
6
+ import { t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
7
+ import { a as instrumentDocumentLoader, c as recordDocumentCache, d as recordInboxActivity, f as recordKeyLookup, l as recordDocumentFetch, m as recordOutboxEnqueue, p as recordOutboxActivity, t as classifyFetchError, u as recordFanoutRecipients } from "../metrics-iRBg8jTk.mjs";
7
8
  import { createTestMeterProvider, test } from "@fedify/fixture";
9
+ import { FetchError } from "@fedify/vocab-runtime";
8
10
  //#region src/federation/metrics.test.ts
9
11
  const noopQueue = {
10
12
  enqueue() {
@@ -103,5 +105,231 @@ test("recordOutboxActivity() records counter with result and activity type", ()
103
105
  "abandoned"
104
106
  ]);
105
107
  });
108
+ test("recordKeyLookup() records counter and duration with all attributes", () => {
109
+ const [meterProvider, recorder] = createTestMeterProvider();
110
+ recordKeyLookup(meterProvider, {
111
+ durationMs: 42,
112
+ result: "fetched",
113
+ remoteUrl: new URL("https://example.com/users/alice#main-key"),
114
+ cacheEnabled: true,
115
+ statusCode: 200
116
+ });
117
+ const counters = recorder.getMeasurements("activitypub.key.lookup");
118
+ assertEquals(counters.length, 1);
119
+ assertEquals(counters[0].type, "counter");
120
+ assertEquals(counters[0].value, 1);
121
+ assertEquals(counters[0].attributes["activitypub.lookup.kind"], "public_key");
122
+ assertEquals(counters[0].attributes["activitypub.lookup.result"], "fetched");
123
+ assertEquals(counters[0].attributes["activitypub.remote.host"], "example.com");
124
+ assertEquals(counters[0].attributes["activitypub.cache.enabled"], true);
125
+ assertEquals(counters[0].attributes["http.response.status_code"], 200);
126
+ const durations = recorder.getMeasurements("activitypub.key.lookup.duration");
127
+ assertEquals(durations.length, 1);
128
+ assertEquals(durations[0].type, "histogram");
129
+ assertEquals(durations[0].value, 42);
130
+ assertEquals(durations[0].attributes["activitypub.lookup.kind"], "public_key");
131
+ assertEquals(durations[0].attributes["activitypub.lookup.result"], "fetched");
132
+ assertEquals(durations[0].attributes["activitypub.remote.host"], "example.com");
133
+ assertEquals(durations[0].attributes["activitypub.cache.enabled"], true);
134
+ assertEquals(durations[0].attributes["http.response.status_code"], 200);
135
+ });
136
+ test("recordKeyLookup() omits optional attributes when not provided", () => {
137
+ const [meterProvider, recorder] = createTestMeterProvider();
138
+ recordKeyLookup(meterProvider, {
139
+ durationMs: 0,
140
+ result: "error",
141
+ cacheEnabled: false
142
+ });
143
+ const counter = recorder.getMeasurement("activitypub.key.lookup");
144
+ assertEquals(counter?.attributes["activitypub.lookup.result"], "error");
145
+ assertEquals(counter?.attributes["activitypub.cache.enabled"], false);
146
+ assertEquals("activitypub.remote.host" in counter.attributes, false);
147
+ assertEquals("http.response.status_code" in counter.attributes, false);
148
+ const duration = recorder.getMeasurement("activitypub.key.lookup.duration");
149
+ assertEquals("activitypub.remote.host" in duration.attributes, false);
150
+ assertEquals("http.response.status_code" in duration.attributes, false);
151
+ });
152
+ test("recordDocumentFetch() records counter and duration with all attributes", () => {
153
+ const [meterProvider, recorder] = createTestMeterProvider();
154
+ recordDocumentFetch(meterProvider, {
155
+ durationMs: 123,
156
+ kind: "object",
157
+ result: "not_found",
158
+ remoteUrl: new URL("https://remote.test/objects/123"),
159
+ cacheEnabled: true,
160
+ statusCode: 404
161
+ });
162
+ const counter = recorder.getMeasurement("activitypub.document.fetch");
163
+ assertEquals(counter?.type, "counter");
164
+ assertEquals(counter?.value, 1);
165
+ assertEquals(counter?.attributes["activitypub.lookup.kind"], "object");
166
+ assertEquals(counter?.attributes["activitypub.lookup.result"], "not_found");
167
+ assertEquals(counter?.attributes["activitypub.remote.host"], "remote.test");
168
+ assertEquals(counter?.attributes["activitypub.cache.enabled"], true);
169
+ assertEquals(counter?.attributes["http.response.status_code"], 404);
170
+ const duration = recorder.getMeasurement("activitypub.document.fetch.duration");
171
+ assertEquals(duration?.type, "histogram");
172
+ assertEquals(duration?.value, 123);
173
+ assertEquals(duration?.attributes["activitypub.lookup.kind"], "object");
174
+ assertEquals(duration?.attributes["activitypub.lookup.result"], "not_found");
175
+ });
176
+ test("recordDocumentFetch() omits optional attributes when not provided", () => {
177
+ const [meterProvider, recorder] = createTestMeterProvider();
178
+ recordDocumentFetch(meterProvider, {
179
+ durationMs: 5,
180
+ kind: "context",
181
+ result: "fetched"
182
+ });
183
+ const counter = recorder.getMeasurement("activitypub.document.fetch");
184
+ assertEquals(counter?.attributes["activitypub.lookup.kind"], "context");
185
+ assertEquals(counter?.attributes["activitypub.lookup.result"], "fetched");
186
+ assertEquals("activitypub.remote.host" in counter.attributes, false);
187
+ assertEquals("activitypub.cache.enabled" in counter.attributes, false);
188
+ assertEquals("http.response.status_code" in counter.attributes, false);
189
+ assertEquals(recorder.getMeasurement("activitypub.document.fetch.duration")?.value, 5);
190
+ });
191
+ test("recordDocumentCache() records hit and miss as a counter", () => {
192
+ const [meterProvider, recorder] = createTestMeterProvider();
193
+ recordDocumentCache(meterProvider, {
194
+ kind: "object",
195
+ result: "hit",
196
+ remoteUrl: new URL("https://remote.test/objects/1")
197
+ });
198
+ recordDocumentCache(meterProvider, {
199
+ kind: "context",
200
+ result: "miss",
201
+ remoteUrl: new URL("https://w3id.org/security/v1")
202
+ });
203
+ const measurements = recorder.getMeasurements("activitypub.document.cache");
204
+ assertEquals(measurements.length, 2);
205
+ for (const m of measurements) {
206
+ assertEquals(m.type, "counter");
207
+ assertEquals(m.value, 1);
208
+ }
209
+ assertEquals(measurements[0].attributes["activitypub.lookup.kind"], "object");
210
+ assertEquals(measurements[0].attributes["activitypub.lookup.result"], "hit");
211
+ assertEquals(measurements[0].attributes["activitypub.remote.host"], "remote.test");
212
+ assertEquals(measurements[1].attributes["activitypub.lookup.kind"], "context");
213
+ assertEquals(measurements[1].attributes["activitypub.lookup.result"], "miss");
214
+ assertEquals(measurements[1].attributes["activitypub.remote.host"], "w3id.org");
215
+ });
216
+ test("classifyFetchError() classifies FetchError with 404 as not_found", () => {
217
+ assertEquals(classifyFetchError(new FetchError("https://example.com/k", "not found", new Response("", { status: 404 }))), {
218
+ result: "not_found",
219
+ statusCode: 404
220
+ });
221
+ });
222
+ test("classifyFetchError() classifies FetchError with 410 as not_found", () => {
223
+ assertEquals(classifyFetchError(new FetchError("https://example.com/k", "gone", new Response("", { status: 410 }))), {
224
+ result: "not_found",
225
+ statusCode: 410
226
+ });
227
+ });
228
+ test("classifyFetchError() classifies FetchError with 500 as error", () => {
229
+ assertEquals(classifyFetchError(new FetchError("https://example.com/k", "server error", new Response("", { status: 500 }))), {
230
+ result: "error",
231
+ statusCode: 500
232
+ });
233
+ });
234
+ test("classifyFetchError() classifies FetchError without response as network_error", () => {
235
+ assertEquals(classifyFetchError(new FetchError("https://example.com/k", "boom")), { result: "network_error" });
236
+ });
237
+ test("classifyFetchError() classifies a bare TypeError as network_error", () => {
238
+ assertEquals(classifyFetchError(/* @__PURE__ */ new TypeError("connect failed")), { result: "network_error" });
239
+ });
240
+ test("classifyFetchError() classifies an AbortError as network_error", () => {
241
+ const abort = /* @__PURE__ */ new Error("aborted");
242
+ abort.name = "AbortError";
243
+ assertEquals(classifyFetchError(abort), { result: "network_error" });
244
+ });
245
+ test("classifyFetchError() classifies any other thrown value as error", () => {
246
+ assertEquals(classifyFetchError(/* @__PURE__ */ new Error("nope")), { result: "error" });
247
+ assertEquals(classifyFetchError("string error"), { result: "error" });
248
+ assertEquals(classifyFetchError(void 0), { result: "error" });
249
+ });
250
+ test("instrumentDocumentLoader() records fetched on success", async () => {
251
+ const [meterProvider, recorder] = createTestMeterProvider();
252
+ const inner = (url) => Promise.resolve({
253
+ contextUrl: null,
254
+ documentUrl: url,
255
+ document: { ok: true }
256
+ });
257
+ assertEquals((await instrumentDocumentLoader(inner, {
258
+ meterProvider,
259
+ kind: "object",
260
+ cacheEnabled: true
261
+ })("https://example.com/o")).document, { ok: true });
262
+ const counter = recorder.getMeasurement("activitypub.document.fetch");
263
+ assertEquals(counter?.attributes["activitypub.lookup.kind"], "object");
264
+ assertEquals(counter?.attributes["activitypub.lookup.result"], "fetched");
265
+ assertEquals(counter?.attributes["activitypub.remote.host"], "example.com");
266
+ assertEquals(counter?.attributes["activitypub.cache.enabled"], true);
267
+ assertEquals("http.response.status_code" in counter.attributes, false);
268
+ const duration = recorder.getMeasurement("activitypub.document.fetch.duration");
269
+ assertEquals(duration?.type, "histogram");
270
+ assertEquals(duration?.attributes["activitypub.lookup.result"], "fetched");
271
+ });
272
+ test("instrumentDocumentLoader() records not_found on FetchError 404", async () => {
273
+ const [meterProvider, recorder] = createTestMeterProvider();
274
+ const inner = (url) => Promise.reject(new FetchError(url, "HTTP 404", new Response("", { status: 404 })));
275
+ const wrapped = instrumentDocumentLoader(inner, {
276
+ meterProvider,
277
+ kind: "context",
278
+ cacheEnabled: false
279
+ });
280
+ await assertRejects(() => wrapped("https://example.com/missing"), FetchError);
281
+ const counter = recorder.getMeasurement("activitypub.document.fetch");
282
+ assertEquals(counter?.attributes["activitypub.lookup.kind"], "context");
283
+ assertEquals(counter?.attributes["activitypub.lookup.result"], "not_found");
284
+ assertEquals(counter?.attributes["activitypub.remote.host"], "example.com");
285
+ assertEquals(counter?.attributes["activitypub.cache.enabled"], false);
286
+ assertEquals(counter?.attributes["http.response.status_code"], 404);
287
+ });
288
+ test("instrumentDocumentLoader() records network_error on TypeError", async () => {
289
+ const [meterProvider, recorder] = createTestMeterProvider();
290
+ const inner = () => Promise.reject(/* @__PURE__ */ new TypeError("fetch failed"));
291
+ const wrapped = instrumentDocumentLoader(inner, {
292
+ meterProvider,
293
+ kind: "object"
294
+ });
295
+ await assertRejects(() => wrapped("https://example.com/o"), TypeError);
296
+ const counter = recorder.getMeasurement("activitypub.document.fetch");
297
+ assertEquals(counter?.attributes["activitypub.lookup.result"], "network_error");
298
+ assertEquals("activitypub.cache.enabled" in counter.attributes, false);
299
+ });
300
+ test("instrumentDocumentLoader() returns inner loader unchanged when meterProvider is omitted", async () => {
301
+ const [, recorder] = createTestMeterProvider();
302
+ let callCount = 0;
303
+ const inner = (url) => {
304
+ callCount++;
305
+ return Promise.resolve({
306
+ contextUrl: null,
307
+ documentUrl: url,
308
+ document: { ok: true }
309
+ });
310
+ };
311
+ const wrapped = instrumentDocumentLoader(inner, { kind: "object" });
312
+ assertEquals(wrapped, inner);
313
+ await wrapped("https://example.com/o");
314
+ assertEquals(callCount, 1);
315
+ assertEquals(recorder.getMeasurements("activitypub.document.fetch").length, 0);
316
+ assertEquals(recorder.getMeasurements("activitypub.document.fetch.duration").length, 0);
317
+ });
318
+ test("instrumentDocumentLoader() omits remote.host when URL is unparseable", async () => {
319
+ const [meterProvider, recorder] = createTestMeterProvider();
320
+ const inner = (url) => Promise.resolve({
321
+ contextUrl: null,
322
+ documentUrl: url,
323
+ document: {}
324
+ });
325
+ await instrumentDocumentLoader(inner, {
326
+ meterProvider,
327
+ kind: "other"
328
+ })("not a url");
329
+ const counter = recorder.getMeasurement("activitypub.document.fetch");
330
+ assertEquals(counter?.attributes["activitypub.lookup.kind"], "other");
331
+ assertEquals(counter?.attributes["activitypub.lookup.result"], "fetched");
332
+ assertEquals("activitypub.remote.host" in counter.attributes, false);
333
+ });
106
334
  //#endregion
107
335
  export {};