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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/dist/compat/mod.d.cts +1 -1
  2. package/dist/compat/mod.d.ts +1 -1
  3. package/dist/{context-xrqq4Hrq.d.ts → context-CuLvR1Os.d.ts} +2 -2
  4. package/dist/{context-C1NqcIct.d.cts → context-apq0IBg2.d.cts} +2 -2
  5. package/dist/federation/mod.cjs +1 -1
  6. package/dist/federation/mod.d.cts +3 -3
  7. package/dist/federation/mod.d.ts +3 -3
  8. package/dist/federation/mod.js +1 -1
  9. package/dist/{federation-FbwcnRHg.cjs → federation-JvzYDx0P.cjs} +5 -5
  10. package/dist/{http-DbvOPsFZ.cjs → http-BG5cDmTS.cjs} +1 -1
  11. package/dist/{http-CWn0K5jD.js → http-MUf125Jc.js} +1 -1
  12. package/dist/{key-dwwAg5bA.d.ts → key-BZw-YiK5.d.ts} +2 -2
  13. package/dist/{key-DlHT4R6k.d.cts → key-D5fbQkKM.d.cts} +2 -2
  14. package/dist/{kv-cache-B-fOrhb-.cjs → kv-cache-A2po7h0_.cjs} +1 -1
  15. package/dist/{kv-cache-BC837EqC.js → kv-cache-CbWc1BZA.js} +1 -1
  16. package/dist/{ld-CWVpo_NM.d.cts → ld-DEi9ERHf.d.cts} +1 -1
  17. package/dist/{ld-o4LnhCYY.d.ts → ld-DlC78ioJ.d.ts} +1 -1
  18. package/dist/{middleware-n2UrG62B.js → middleware-DzzdJ7Wz.js} +5 -5
  19. package/dist/{mod-D22ZsiKi.d.ts → mod-BJRtsw7l.d.ts} +1 -1
  20. package/dist/{mod-C1nT74IG.d.cts → mod-BamwZjJx.d.cts} +1 -1
  21. package/dist/{mod-DO0epJGH.d.ts → mod-BkTi19dI.d.ts} +1 -1
  22. package/dist/{mod-CQC9xlLZ.d.ts → mod-CMtF0VVy.d.ts} +1 -1
  23. package/dist/{mod-YvA4Rk8J.d.cts → mod-D2Z9MiCm.d.cts} +1 -1
  24. package/dist/{mod-TwiQgEf3.d.cts → mod-DB2NOzQF.d.cts} +1 -1
  25. package/dist/mod.cjs +4 -4
  26. package/dist/mod.d.cts +6 -6
  27. package/dist/mod.d.ts +6 -6
  28. package/dist/mod.js +4 -4
  29. package/dist/{portable-collection-DQhIkX5a.js → portable-collection-CAer9RWN.js} +1 -1
  30. package/dist/{portable-collection-DseoiPPj.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
  31. package/dist/sig/mod.cjs +2 -2
  32. package/dist/sig/mod.d.cts +3 -3
  33. package/dist/sig/mod.d.ts +3 -3
  34. package/dist/sig/mod.js +2 -2
  35. package/dist/utils/mod.cjs +1 -1
  36. package/dist/utils/mod.d.cts +1 -1
  37. package/dist/utils/mod.d.ts +1 -1
  38. package/dist/utils/mod.js +1 -1
  39. package/package.json +22 -9
  40. package/skills/fedify/SKILL.md +10 -0
  41. package/dist/accept-CPVqki78.mjs +0 -145
  42. package/dist/activity-listener-CELFAodc.mjs +0 -44
  43. package/dist/assert-D1Eafmd_.mjs +0 -23
  44. package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
  45. package/dist/assert_exists-cffSpJ7X.mjs +0 -28
  46. package/dist/assert_false-CPdRnc3E.mjs +0 -23
  47. package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
  48. package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
  49. package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
  50. package/dist/assert_rejects-CTptdYck.mjs +0 -39
  51. package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
  52. package/dist/assert_throws-BYITOvPO.mjs +0 -74
  53. package/dist/assertion_error-B-cx0fFA.mjs +0 -31
  54. package/dist/audience-CHQ-FlLD.mjs +0 -95
  55. package/dist/builder-CGJ-NXcZ.mjs +0 -911
  56. package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
  57. package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
  58. package/dist/client-5SIFzW3q.mjs +0 -441
  59. package/dist/codec-C6rTrpIp.mjs +0 -147
  60. package/dist/collection-CnnP1UAv.mjs +0 -44
  61. package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
  62. package/dist/compat/outgoing-jsonld.test.mjs +0 -257
  63. package/dist/compat/public-audience.test.d.mts +0 -2
  64. package/dist/compat/public-audience.test.mjs +0 -187
  65. package/dist/compat/secured-document.test.d.mts +0 -2
  66. package/dist/compat/secured-document.test.mjs +0 -58
  67. package/dist/compat/transformers.test.d.mts +0 -2
  68. package/dist/compat/transformers.test.mjs +0 -62
  69. package/dist/compound-proof-CnzwOddk.mjs +0 -1019
  70. package/dist/context-LgGFFSz7.mjs +0 -146
  71. package/dist/deno-eoFpPk7W.mjs +0 -8
  72. package/dist/dist-_geWsuaI.mjs +0 -189
  73. package/dist/docloader-DwkipyL1.mjs +0 -136
  74. package/dist/esm-BHXXx4Wx.mjs +0 -1233
  75. package/dist/exporter-DVG68ozH.mjs +0 -263
  76. package/dist/federation/audience.test.d.mts +0 -2
  77. package/dist/federation/audience.test.mjs +0 -130
  78. package/dist/federation/builder.test.d.mts +0 -2
  79. package/dist/federation/builder.test.mjs +0 -396
  80. package/dist/federation/circuit-breaker.test.d.mts +0 -2
  81. package/dist/federation/circuit-breaker.test.mjs +0 -1277
  82. package/dist/federation/collection.test.d.mts +0 -2
  83. package/dist/federation/collection.test.mjs +0 -21
  84. package/dist/federation/compound-fanout.test.d.mts +0 -2
  85. package/dist/federation/compound-fanout.test.mjs +0 -231
  86. package/dist/federation/handler-compound-proof.test.d.mts +0 -2
  87. package/dist/federation/handler-compound-proof.test.mjs +0 -384
  88. package/dist/federation/handler.test.d.mts +0 -2
  89. package/dist/federation/handler.test.mjs +0 -5445
  90. package/dist/federation/hashlink-media.test.d.mts +0 -2
  91. package/dist/federation/hashlink-media.test.mjs +0 -422
  92. package/dist/federation/idempotency.test.d.mts +0 -2
  93. package/dist/federation/idempotency.test.mjs +0 -207
  94. package/dist/federation/inbox-actorless.test.d.mts +0 -2
  95. package/dist/federation/inbox-actorless.test.mjs +0 -522
  96. package/dist/federation/inbox-authentication.test.d.mts +0 -2
  97. package/dist/federation/inbox-authentication.test.mjs +0 -220
  98. package/dist/federation/inbox-report.test.d.mts +0 -2
  99. package/dist/federation/inbox-report.test.mjs +0 -719
  100. package/dist/federation/inbox-view.test.d.mts +0 -2
  101. package/dist/federation/inbox-view.test.mjs +0 -369
  102. package/dist/federation/inbox.test.d.mts +0 -2
  103. package/dist/federation/inbox.test.mjs +0 -139
  104. package/dist/federation/keycache.test.d.mts +0 -2
  105. package/dist/federation/keycache.test.mjs +0 -337
  106. package/dist/federation/kv.test.d.mts +0 -2
  107. package/dist/federation/kv.test.mjs +0 -88
  108. package/dist/federation/metrics.test.d.mts +0 -2
  109. package/dist/federation/metrics.test.mjs +0 -634
  110. package/dist/federation/middleware.test.d.mts +0 -2
  111. package/dist/federation/middleware.test.mjs +0 -9314
  112. package/dist/federation/mq.test.d.mts +0 -2
  113. package/dist/federation/mq.test.mjs +0 -591
  114. package/dist/federation/negotiation.test.d.mts +0 -2
  115. package/dist/federation/negotiation.test.mjs +0 -18
  116. package/dist/federation/outbound-body.test.d.mts +0 -2
  117. package/dist/federation/outbound-body.test.mjs +0 -149
  118. package/dist/federation/outbound-capture.test.d.mts +0 -2
  119. package/dist/federation/outbound-capture.test.mjs +0 -394
  120. package/dist/federation/outbound-dispatch.test.d.mts +0 -2
  121. package/dist/federation/outbound-dispatch.test.mjs +0 -368
  122. package/dist/federation/outbound-document.test.d.mts +0 -2
  123. package/dist/federation/outbound-document.test.mjs +0 -171
  124. package/dist/federation/outbound-provenance.test.d.mts +0 -2
  125. package/dist/federation/outbound-provenance.test.mjs +0 -543
  126. package/dist/federation/outbound-report.test.d.mts +0 -2
  127. package/dist/federation/outbound-report.test.mjs +0 -5475
  128. package/dist/federation/outbound-workers.test.d.mts +0 -2
  129. package/dist/federation/outbound-workers.test.mjs +0 -64
  130. package/dist/federation/outbound-workflow.test.d.mts +0 -2
  131. package/dist/federation/outbound-workflow.test.mjs +0 -154
  132. package/dist/federation/outgoing-proof.test.d.mts +0 -2
  133. package/dist/federation/outgoing-proof.test.mjs +0 -933
  134. package/dist/federation/portable-actor.test.d.mts +0 -2
  135. package/dist/federation/portable-actor.test.mjs +0 -496
  136. package/dist/federation/portable-chain.test.d.mts +0 -2
  137. package/dist/federation/portable-chain.test.mjs +0 -370
  138. package/dist/federation/portable-collection.test.d.mts +0 -2
  139. package/dist/federation/portable-collection.test.mjs +0 -832
  140. package/dist/federation/portable-delivery.test.d.mts +0 -2
  141. package/dist/federation/portable-delivery.test.mjs +0 -845
  142. package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
  143. package/dist/federation/portable-gateway-keys.test.mjs +0 -692
  144. package/dist/federation/portable-inbox.test.d.mts +0 -2
  145. package/dist/federation/portable-inbox.test.mjs +0 -1960
  146. package/dist/federation/portable-parse-uri.test.d.mts +0 -2
  147. package/dist/federation/portable-parse-uri.test.mjs +0 -348
  148. package/dist/federation/portable-route-activity.test.d.mts +0 -2
  149. package/dist/federation/portable-route-activity.test.mjs +0 -259
  150. package/dist/federation/portable.test.d.mts +0 -2
  151. package/dist/federation/portable.test.mjs +0 -1072
  152. package/dist/federation/retry.test.d.mts +0 -2
  153. package/dist/federation/retry.test.mjs +0 -42
  154. package/dist/federation/router.test.d.mts +0 -2
  155. package/dist/federation/router.test.mjs +0 -123
  156. package/dist/federation/send.test.d.mts +0 -2
  157. package/dist/federation/send.test.mjs +0 -1421
  158. package/dist/federation/tasks/codec.test.d.mts +0 -2
  159. package/dist/federation/tasks/codec.test.mjs +0 -302
  160. package/dist/federation/tasks/enqueue.test.d.mts +0 -2
  161. package/dist/federation/tasks/enqueue.test.mjs +0 -1095
  162. package/dist/federation/tasks/tasks.test.d.mts +0 -2
  163. package/dist/federation/tasks/tasks.test.mjs +0 -1229
  164. package/dist/federation/temporal.test.d.mts +0 -2
  165. package/dist/federation/temporal.test.mjs +0 -71
  166. package/dist/federation/webfinger.test.d.mts +0 -2
  167. package/dist/federation/webfinger.test.mjs +0 -944
  168. package/dist/http-l1zKGCll.mjs +0 -1449
  169. package/dist/inbox-CWX3EBTO.mjs +0 -399
  170. package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
  171. package/dist/inbox-view-DkPCF71K.mjs +0 -385
  172. package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
  173. package/dist/keycache-N2opu4-3.mjs +0 -221
  174. package/dist/keys-DIJNHW-Y.mjs +0 -120
  175. package/dist/kv-DBRWVx3Q.mjs +0 -104
  176. package/dist/kv-DCHkaJ9-.mjs +0 -92
  177. package/dist/kv-cache-8eJh4Xum.mjs +0 -121
  178. package/dist/ld-Cdt8qD-r.mjs +0 -1752
  179. package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
  180. package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
  181. package/dist/metrics-BnfvSPj9.mjs +0 -818
  182. package/dist/middleware-CwnXJze2.mjs +0 -5
  183. package/dist/middleware-D_W_LdJN.mjs +0 -9971
  184. package/dist/mq-eF96QxUT.mjs +0 -288
  185. package/dist/negotiation-BAKO9nih.mjs +0 -96
  186. package/dist/nodeinfo/client.test.d.mts +0 -2
  187. package/dist/nodeinfo/client.test.mjs +0 -1364
  188. package/dist/nodeinfo/handler.test.d.mts +0 -2
  189. package/dist/nodeinfo/handler.test.mjs +0 -94
  190. package/dist/nodeinfo/types.test.d.mts +0 -2
  191. package/dist/nodeinfo/types.test.mjs +0 -192
  192. package/dist/otel/exporter.test.d.mts +0 -2
  193. package/dist/otel/exporter.test.mjs +0 -887
  194. package/dist/outbound-body-CckPA5gc.mjs +0 -83
  195. package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
  196. package/dist/outbound-document-BMgwLXTY.mjs +0 -179
  197. package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
  198. package/dist/owner-DukEQnv3.mjs +0 -267
  199. package/dist/portable-collection-OHaqa11n.mjs +0 -418
  200. package/dist/portable-key-BkOLJxVz.mjs +0 -549
  201. package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
  202. package/dist/proof-Y7omSVvc.mjs +0 -1420
  203. package/dist/public-audience--klBIOk1.mjs +0 -197
  204. package/dist/retry-zX5xw5e0.mjs +0 -34
  205. package/dist/router-u5O5KCQr.mjs +0 -156
  206. package/dist/secured-document-CxzZZ9nL.mjs +0 -35
  207. package/dist/send-ccQynabr.mjs +0 -710
  208. package/dist/sig/accept.test.d.mts +0 -2
  209. package/dist/sig/accept.test.mjs +0 -416
  210. package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
  211. package/dist/sig/compound-proof-discovery.test.mjs +0 -331
  212. package/dist/sig/compound-proof-producer.test.d.mts +0 -2
  213. package/dist/sig/compound-proof-producer.test.mjs +0 -107
  214. package/dist/sig/compound-proof-verification.test.d.mts +0 -2
  215. package/dist/sig/compound-proof-verification.test.mjs +0 -1017
  216. package/dist/sig/compound-proof.test.d.mts +0 -2
  217. package/dist/sig/compound-proof.test.mjs +0 -411
  218. package/dist/sig/http.test.d.mts +0 -2
  219. package/dist/sig/http.test.mjs +0 -3328
  220. package/dist/sig/key-owner-evidence.test.d.mts +0 -2
  221. package/dist/sig/key-owner-evidence.test.mjs +0 -100
  222. package/dist/sig/key.test.d.mts +0 -2
  223. package/dist/sig/key.test.mjs +0 -1250
  224. package/dist/sig/ld.test.d.mts +0 -2
  225. package/dist/sig/ld.test.mjs +0 -1044
  226. package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
  227. package/dist/sig/mitra-receive-interop.test.mjs +0 -260
  228. package/dist/sig/mitra-send-interop.test.d.mts +0 -2
  229. package/dist/sig/mitra-send-interop.test.mjs +0 -461
  230. package/dist/sig/owner.test.d.mts +0 -2
  231. package/dist/sig/owner.test.mjs +0 -202
  232. package/dist/sig/portable-collection.test.d.mts +0 -2
  233. package/dist/sig/portable-collection.test.mjs +0 -697
  234. package/dist/sig/portable-interop.test.d.mts +0 -2
  235. package/dist/sig/portable-interop.test.mjs +0 -156
  236. package/dist/sig/portable-key-id.test.d.mts +0 -2
  237. package/dist/sig/portable-key-id.test.mjs +0 -67
  238. package/dist/sig/portable-key.test.d.mts +0 -2
  239. package/dist/sig/portable-key.test.mjs +0 -1438
  240. package/dist/sig/proof.test.d.mts +0 -2
  241. package/dist/sig/proof.test.mjs +0 -2638
  242. package/dist/sig/tootik-request-interop.test.d.mts +0 -2
  243. package/dist/sig/tootik-request-interop.test.mjs +0 -190
  244. package/dist/sig/tootik-send-interop.test.d.mts +0 -2
  245. package/dist/sig/tootik-send-interop.test.mjs +0 -331
  246. package/dist/sig/verification.test.d.mts +0 -2
  247. package/dist/sig/verification.test.mjs +0 -310
  248. package/dist/std__assert-DvMDRPes.mjs +0 -8
  249. package/dist/tasks-BCUmQbbz.mjs +0 -77
  250. package/dist/temporal-f_K4lAVR.mjs +0 -95
  251. package/dist/testing/context.test.d.mts +0 -2
  252. package/dist/testing/context.test.mjs +0 -19
  253. package/dist/testing/kv.test.d.mts +0 -2
  254. package/dist/testing/kv.test.mjs +0 -101
  255. package/dist/testing/mod.d.mts +0 -6099
  256. package/dist/testing/mod.mjs +0 -9
  257. package/dist/testing-vrnD5Uaa.mjs +0 -8
  258. package/dist/types-DE_LV1JB.mjs +0 -46
  259. package/dist/utils/docloader.test.d.mts +0 -2
  260. package/dist/utils/docloader.test.mjs +0 -1076
  261. package/dist/utils/kv-cache.test.d.mts +0 -2
  262. package/dist/utils/kv-cache.test.mjs +0 -261
  263. package/dist/verification-C3954hQh.mjs +0 -5
  264. package/dist/verification-Dpfcw8ml.mjs +0 -105
  265. package/dist/vocab/cjs.test.d.mts +0 -2
  266. package/dist/vocab/cjs.test.mjs +0 -27
@@ -1,845 +0,0 @@
1
- import { Temporal } from "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 { i as rsaPrivateKey2, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
7
- import { n as FederationImpl, r as InboxContextImpl, t as ContextImpl } from "../middleware-D_W_LdJN.mjs";
8
- import { n as extractInboxes, t as SendActivityError } from "../send-ccQynabr.mjs";
9
- import { Create, Endpoints, Note, Person } from "@fedify/vocab";
10
- import { parseIri } from "@fedify/vocab-runtime";
11
- import { mockDocumentLoader, test } from "@fedify/fixture";
12
- import { deepStrictEqual, notStrictEqual, ok, rejects, strictEqual } from "node:assert/strict";
13
- //#region src/federation/portable-delivery.test.ts
14
- const DID = "did:key:z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2";
15
- const OTHER_DID = "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK";
16
- const PORTABLE_INBOX = `ap+ef61://${DID}/actor/inbox`;
17
- const ACTOR_ID = `ap+ef61://${encodeURIComponent(DID)}/actor`;
18
- const inboxOn = (gateway, did = DID) => `${gateway}/.well-known/apgateway/${did}/actor/inbox`;
19
- function portableActor(options = {}) {
20
- const did = options.did ?? DID;
21
- return new Person({
22
- id: parseIri(options.id ?? `ap://${did}/actor`),
23
- inbox: parseIri(options.inbox ?? `ap://${did}/actor/inbox`),
24
- gateways: (options.gateways ?? []).map((g) => new URL(g)),
25
- endpoints: options.sharedInbox == null ? null : new Endpoints({ sharedInbox: new URL(options.sharedInbox) })
26
- });
27
- }
28
- test("extractInboxes() resolves portable inboxes", async (t) => {
29
- await t.step("through the recipient's gateways", () => {
30
- deepStrictEqual(extractInboxes({ recipients: [portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] })] }), { [inboxOn("https://gw1.example")]: {
31
- actorIds: /* @__PURE__ */ new Set([ACTOR_ID]),
32
- sharedInbox: false,
33
- portableInbox: PORTABLE_INBOX,
34
- gatewayInboxes: [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]
35
- } });
36
- });
37
- await t.step("through @gateway hints of the inbox", () => {
38
- const inboxes = extractInboxes({ recipients: [portableActor({ inbox: `ap://${DID}/actor/inbox?@gateway=https%3A%2F%2Fhint1.example&@gateway=https%3A%2F%2Fhint2.example` })] });
39
- deepStrictEqual(Object.keys(inboxes), [inboxOn("https://hint1.example")]);
40
- deepStrictEqual(inboxes[inboxOn("https://hint1.example")].gatewayInboxes, [inboxOn("https://hint1.example"), inboxOn("https://hint2.example")]);
41
- });
42
- await t.step("preferring gateways to hints", () => {
43
- deepStrictEqual(extractInboxes({ recipients: [portableActor({
44
- inbox: `ap://${DID}/actor/inbox?@gateway=https%3A%2F%2Fhint.example`,
45
- gateways: ["https://gw.example"]
46
- })] })[inboxOn("https://gw.example")].gatewayInboxes, [inboxOn("https://gw.example")]);
47
- });
48
- await t.step("skipping a recipient without gateways", () => {
49
- deepStrictEqual(extractInboxes({ recipients: [portableActor()] }), {});
50
- });
51
- await t.step("skipping invalid gateways", () => {
52
- const inboxes = extractInboxes({ recipients: [{
53
- id: parseIri(`ap://${DID}/actor`),
54
- inboxId: parseIri(`ap://${DID}/actor/inbox`),
55
- gateways: [new URL("https://bad.example/path"), new URL("https://gw.example")]
56
- }] });
57
- deepStrictEqual(Object.keys(inboxes), [inboxOn("https://gw.example")]);
58
- });
59
- await t.step("capping the number of gateways", () => {
60
- strictEqual(extractInboxes({ recipients: [portableActor({ gateways: Array.from({ length: 8 }, (_, i) => `https://gw${i}.example`) })] })[inboxOn("https://gw0.example")].gatewayInboxes?.length, 5);
61
- });
62
- await t.step("merging spellings of the same portable inbox", () => {
63
- const inboxes = extractInboxes({ recipients: [portableActor({ gateways: ["https://gw1.example"] }), portableActor({
64
- id: `ap+ef61://${encodeURIComponent(DID)}/actor`,
65
- inbox: `ap+ef61://${encodeURIComponent(DID)}/actor/inbox`,
66
- gateways: ["https://gw2.example", "https://gw1.example"]
67
- })] });
68
- deepStrictEqual(Object.keys(inboxes), [inboxOn("https://gw1.example")]);
69
- deepStrictEqual(inboxes[inboxOn("https://gw1.example")].gatewayInboxes, [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]);
70
- });
71
- await t.step("merging with a compatible identifier inbox", () => {
72
- const compatible = {
73
- id: new URL(`https://gw1.example/.well-known/apgateway/${DID}/actor`),
74
- inboxId: new URL(inboxOn("https://gw1.example"))
75
- };
76
- const portable = portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] });
77
- for (const recipients of [[compatible, portable], [portable, compatible]]) deepStrictEqual(extractInboxes({ recipients }), { [inboxOn("https://gw1.example")]: {
78
- actorIds: new Set(recipients.map((r) => r.id.href)),
79
- sharedInbox: false,
80
- portableInbox: PORTABLE_INBOX,
81
- gatewayInboxes: [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]
82
- } });
83
- });
84
- await t.step("merging with an inbox on a later gateway", () => {
85
- const compatible = {
86
- id: new URL(`https://gw2.example/.well-known/apgateway/${DID}/actor`),
87
- inboxId: new URL(inboxOn("https://gw2.example"))
88
- };
89
- const portable = portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] });
90
- for (const recipients of [[compatible, portable], [portable, compatible]]) {
91
- const inboxes = extractInboxes({ recipients });
92
- const keys = Object.keys(inboxes);
93
- strictEqual(keys.length, 1);
94
- const entry = inboxes[keys[0]];
95
- strictEqual(entry.gatewayInboxes?.[0], keys[0]);
96
- deepStrictEqual(new Set(entry.gatewayInboxes), /* @__PURE__ */ new Set([inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]));
97
- strictEqual(entry.portableInbox, PORTABLE_INBOX);
98
- strictEqual(entry.actorIds.size, 2);
99
- }
100
- });
101
- await t.step("merging inboxes on several gateways", () => {
102
- const onGateway = (gateway) => ({
103
- id: new URL(`${gateway}/.well-known/apgateway/${DID}/actor`),
104
- inboxId: new URL(inboxOn(gateway))
105
- });
106
- const portable = portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] });
107
- const gw1 = onGateway("https://gw1.example");
108
- const gw2 = onGateway("https://gw2.example");
109
- for (const recipients of [
110
- [
111
- gw1,
112
- gw2,
113
- portable
114
- ],
115
- [
116
- gw2,
117
- gw1,
118
- portable
119
- ],
120
- [
121
- gw1,
122
- portable,
123
- gw2
124
- ],
125
- [
126
- portable,
127
- gw2,
128
- gw1
129
- ]
130
- ]) {
131
- const inboxes = extractInboxes({ recipients });
132
- const keys = Object.keys(inboxes);
133
- strictEqual(keys.length, 1);
134
- const entry = inboxes[keys[0]];
135
- strictEqual(entry.gatewayInboxes?.[0], keys[0]);
136
- deepStrictEqual(new Set(entry.gatewayInboxes), /* @__PURE__ */ new Set([inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]));
137
- strictEqual(entry.portableInbox, PORTABLE_INBOX);
138
- strictEqual(entry.actorIds.size, 3);
139
- }
140
- });
141
- await t.step("merging with a shared inbox of the same URL", () => {
142
- const shared = {
143
- id: new URL("https://other.example/users/bob"),
144
- inboxId: new URL("https://other.example/users/bob/inbox"),
145
- endpoints: { sharedInbox: new URL(inboxOn("https://gw1.example")) }
146
- };
147
- const portable = portableActor({ gateways: ["https://gw1.example"] });
148
- for (const recipients of [[shared, portable], [portable, shared]]) {
149
- const inboxes = extractInboxes({
150
- recipients,
151
- preferSharedInbox: true
152
- });
153
- strictEqual(inboxes[inboxOn("https://gw1.example")].sharedInbox, false);
154
- strictEqual(inboxes[inboxOn("https://gw1.example")].portableInbox, PORTABLE_INBOX);
155
- strictEqual(inboxes[inboxOn("https://gw1.example")].actorIds.size, 2);
156
- }
157
- });
158
- await t.step("not preferring the shared inbox of a portable inbox", () => {
159
- const inboxes = extractInboxes({
160
- recipients: [portableActor({
161
- gateways: ["https://gw.example"],
162
- sharedInbox: "https://gw.example/inbox"
163
- })],
164
- preferSharedInbox: true
165
- });
166
- deepStrictEqual(Object.keys(inboxes), [inboxOn("https://gw.example")]);
167
- strictEqual(inboxes[inboxOn("https://gw.example")].sharedInbox, false);
168
- });
169
- await t.step("excluding gateways by excludeBaseUris", () => {
170
- const recipients = [portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] })];
171
- let inboxes = extractInboxes({
172
- recipients,
173
- excludeBaseUris: [new URL("https://gw1.example/")]
174
- });
175
- deepStrictEqual(inboxes[inboxOn("https://gw2.example")].gatewayInboxes, [inboxOn("https://gw2.example")]);
176
- inboxes = extractInboxes({
177
- recipients,
178
- excludeBaseUris: [new URL("https://gw1.example/"), new URL("https://gw2.example/foo")]
179
- });
180
- deepStrictEqual(inboxes, {});
181
- });
182
- await t.step("keeping ordinary inboxes unchanged", () => {
183
- deepStrictEqual(extractInboxes({ recipients: [new Person({
184
- id: new URL("https://example.com/alice"),
185
- inbox: new URL("https://example.com/alice/inbox")
186
- })] }), { "https://example.com/alice/inbox": {
187
- actorIds: /* @__PURE__ */ new Set(["https://example.com/alice"]),
188
- sharedInbox: false
189
- } });
190
- });
191
- });
192
- function createQueue(options = {}) {
193
- const queued = [];
194
- return {
195
- queue: {
196
- nativeRetrial: options.nativeRetrial,
197
- enqueue(message, options) {
198
- queued.push({
199
- message: JSON.parse(JSON.stringify(message)),
200
- options
201
- });
202
- return Promise.resolve();
203
- },
204
- listen() {
205
- return Promise.resolve();
206
- }
207
- },
208
- queued
209
- };
210
- }
211
- const sender = {
212
- keyId: rsaPublicKey2.id,
213
- privateKey: rsaPrivateKey2
214
- };
215
- function createActivity(id = "https://example.com/activities/1") {
216
- return new Create({
217
- id: new URL(id),
218
- actor: new URL("https://example.com/person2"),
219
- object: new Note({
220
- id: new URL(`${id}/note`),
221
- content: "Hello"
222
- })
223
- });
224
- }
225
- test("Context.sendActivity() to a portable inbox", async (t) => {
226
- esm_default.spyGlobal();
227
- await t.step("immediately", async () => {
228
- esm_default.hardReset();
229
- esm_default.spyGlobal();
230
- const requests = [];
231
- esm_default.post("begin:https://gw1.example/", (call) => {
232
- requests.push(call.url);
233
- return 202;
234
- });
235
- await new FederationImpl({
236
- kv: new MemoryKvStore(),
237
- allowPrivateAddress: true
238
- }).createContext(new URL("https://example.com/")).sendActivity(sender, portableActor({ gateways: ["https://gw1.example"] }), createActivity(), { immediate: true });
239
- deepStrictEqual(requests, [inboxOn("https://gw1.example")]);
240
- });
241
- await t.step("immediately, failing over to the next gateway", async () => {
242
- esm_default.hardReset();
243
- esm_default.spyGlobal();
244
- const requests = [];
245
- esm_default.post("begin:https://gw1.example/", (call) => {
246
- requests.push(call.url);
247
- return 404;
248
- });
249
- esm_default.post("begin:https://gw2.example/", (call) => {
250
- requests.push(call.url);
251
- return 202;
252
- });
253
- await new FederationImpl({
254
- kv: new MemoryKvStore(),
255
- allowPrivateAddress: true
256
- }).createContext(new URL("https://example.com/")).sendActivity(sender, portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] }), createActivity(), { immediate: true });
257
- deepStrictEqual([...new Set(requests)], [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]);
258
- });
259
- await t.step("immediately, failing on every gateway", async () => {
260
- esm_default.hardReset();
261
- esm_default.spyGlobal();
262
- esm_default.post("begin:https://gw1.example/", 500);
263
- esm_default.post("begin:https://gw2.example/", 404);
264
- const ctx = new FederationImpl({
265
- kv: new MemoryKvStore(),
266
- allowPrivateAddress: true
267
- }).createContext(new URL("https://example.com/"));
268
- await rejects(() => ctx.sendActivity(sender, portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] }), createActivity(), { immediate: true }), (error) => error instanceof SendActivityError && error.statusCode === 404 && error.inbox.href === inboxOn("https://gw2.example"));
269
- });
270
- await t.step("rejecting private gateways", async () => {
271
- esm_default.hardReset();
272
- esm_default.spyGlobal();
273
- let requests = 0;
274
- esm_default.post("begin:http://127.0.0.1/", () => {
275
- requests++;
276
- return 202;
277
- });
278
- const ctx = new FederationImpl({ kv: new MemoryKvStore() }).createContext(new URL("https://example.com/"));
279
- await rejects(() => ctx.sendActivity(sender, portableActor({ gateways: ["http://127.0.0.1"] }), createActivity(), { immediate: true }));
280
- strictEqual(requests, 0);
281
- });
282
- await t.step("through the queue", async () => {
283
- esm_default.hardReset();
284
- esm_default.spyGlobal();
285
- const requests = [];
286
- esm_default.post("begin:https://gw1.example/", (call) => {
287
- requests.push(call.url);
288
- return 404;
289
- });
290
- esm_default.post("begin:https://gw2.example/", (call) => {
291
- requests.push(call.url);
292
- return 202;
293
- });
294
- const { queue, queued } = createQueue();
295
- const federation = new FederationImpl({
296
- kv: new MemoryKvStore(),
297
- queue,
298
- manuallyStartQueue: true,
299
- allowPrivateAddress: true
300
- });
301
- await federation.createContext(new URL("https://example.com/")).sendActivity(sender, [portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] }), portableActor({
302
- did: OTHER_DID,
303
- gateways: ["https://gw1.example"]
304
- })], createActivity(), {
305
- orderingKey: "key",
306
- fanout: "skip"
307
- });
308
- strictEqual(queued.length, 2);
309
- const messages = queued.map((q) => q.message);
310
- deepStrictEqual(messages.map((m) => m.inbox), [inboxOn("https://gw1.example"), inboxOn("https://gw1.example", OTHER_DID)]);
311
- deepStrictEqual(messages[0].gatewayInboxes, [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]);
312
- strictEqual(messages[0].portableInbox, PORTABLE_INBOX);
313
- deepStrictEqual(queued.map((q) => q.options?.orderingKey), [`key\n${DID}`, `key\n${OTHER_DID}`]);
314
- queued.length = 0;
315
- await federation.processQueuedTask(void 0, messages[0]);
316
- deepStrictEqual([...new Set(requests)], [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]);
317
- strictEqual(queued.length, 0);
318
- });
319
- await t.step("through the fanout queue", async () => {
320
- esm_default.hardReset();
321
- esm_default.spyGlobal();
322
- const { queue, queued } = createQueue();
323
- const federation = new FederationImpl({
324
- kv: new MemoryKvStore(),
325
- queue,
326
- manuallyStartQueue: true,
327
- allowPrivateAddress: true
328
- });
329
- await federation.createContext(new URL("https://example.com/")).sendActivity(sender, portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] }), createActivity(), { fanout: "force" });
330
- strictEqual(queued.length, 1);
331
- const fanout = queued[0].message;
332
- deepStrictEqual(fanout.inboxes, { [inboxOn("https://gw1.example")]: {
333
- actorIds: [ACTOR_ID],
334
- sharedInbox: false,
335
- portableInbox: PORTABLE_INBOX,
336
- gatewayInboxes: [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]
337
- } });
338
- queued.length = 0;
339
- await federation.processQueuedTask(void 0, fanout);
340
- strictEqual(queued.length, 1);
341
- const outbox = queued[0].message;
342
- strictEqual(outbox.inbox, inboxOn("https://gw1.example"));
343
- deepStrictEqual(outbox.gatewayInboxes, [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]);
344
- });
345
- esm_default.hardReset();
346
- });
347
- test("portable fallback attempts retain one delivery across concrete gateway sends", async (t) => {
348
- for (const operation of [
349
- "send",
350
- "inbox-forward",
351
- "outbox-forward"
352
- ]) for (const accepted of [true, false]) await t.step(`${operation}: ${accepted ? "accepted fallback" : "exhausted gateways"}`, async () => {
353
- const raw = {
354
- "@context": "https://www.w3.org/ns/activitystreams",
355
- type: "Create",
356
- id: "https://example.com/activities/forwarded",
357
- actor: "https://example.com/person2",
358
- extra: "preserve received payload"
359
- };
360
- const reports = [];
361
- const deliveries = [];
362
- const submitted = [];
363
- esm_default.mockGlobal().post("begin:https://gw1.example/", (call) => {
364
- submitted.push(JSON.parse(String(call.options.body)));
365
- return 503;
366
- }).post("begin:https://gw2.example/", (call) => {
367
- submitted.push(JSON.parse(String(call.options.body)));
368
- return accepted ? 202 : 502;
369
- });
370
- try {
371
- const federation = new FederationImpl({
372
- kv: new MemoryKvStore(),
373
- allowPrivateAddress: true
374
- });
375
- federation.setOutboundObservers({
376
- onDelivery(_ctx, event) {
377
- deliveries.push(event);
378
- },
379
- onAttempt(_ctx, report) {
380
- reports.push(report);
381
- throw new Error("attempt observer cannot stop gateway fallback");
382
- }
383
- });
384
- const ctx = federation.createContext(new URL("https://example.com/"));
385
- ok(ctx instanceof ContextImpl);
386
- const target = portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] });
387
- const pending = operation === "send" ? ctx.sendActivity(sender, target, createActivity(), { immediate: true }) : (operation === "inbox-forward" ? ctx.toInboxContext(null, raw, raw.id, Create.typeId.href) : ctx.toOutboxContext("alice", raw, raw.id, Create.typeId.href)).forwardActivity(sender, target, {
388
- immediate: true,
389
- skipIfUnsigned: false
390
- });
391
- if (accepted) await pending;
392
- else await rejects(pending, (error) => error instanceof SendActivityError && error.statusCode === 502);
393
- strictEqual(reports.length, 2);
394
- deepStrictEqual(reports.map((report) => report.inboxUrl), [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]);
395
- notStrictEqual(reports[0].attemptId, reports[1].attemptId);
396
- strictEqual(reports[0].deliveryId, reports[1].deliveryId);
397
- deepStrictEqual(reports[0].broadcast, reports[1].broadcast);
398
- for (const report of reports) {
399
- strictEqual(report.destinationInbox, inboxOn("https://gw1.example"));
400
- strictEqual(report.portableInbox, PORTABLE_INBOX);
401
- strictEqual(report.deliveryId, deliveries[0].deliveryId);
402
- }
403
- strictEqual(reports[0].outcome.type, "failed");
404
- strictEqual(reports[1].outcome.type, accepted ? "succeeded" : "failed");
405
- for (const [index, report] of reports.entries()) {
406
- const response = report.outcome.response;
407
- ok(response.type === "final");
408
- strictEqual(response.metadata.status, index === 0 ? 503 : accepted ? 202 : 502);
409
- strictEqual(report.httpExchangeCount, index === 1 && accepted ? 1 : 2);
410
- strictEqual(response.exchangeIndex, report.httpExchangeCount - 1);
411
- }
412
- if (operation !== "send") for (const payload of submitted) deepStrictEqual(payload, raw);
413
- } finally {
414
- esm_default.hardReset();
415
- }
416
- });
417
- });
418
- test("InboxContext.forwardActivity() to a portable inbox", async (t) => {
419
- esm_default.spyGlobal();
420
- const activity = {
421
- "@context": "https://www.w3.org/ns/activitystreams",
422
- type: "Create",
423
- id: "https://example.com/activities/1",
424
- actor: "https://example.com/person2"
425
- };
426
- const recipient = portableActor({ gateways: ["https://gw1.example", "https://gw2.example"] });
427
- function createInboxContext(federation) {
428
- return new InboxContextImpl(null, activity, activity.id, "https://www.w3.org/ns/activitystreams#Create", {
429
- data: void 0,
430
- federation,
431
- url: new URL("https://example.com/"),
432
- documentLoader: mockDocumentLoader,
433
- contextLoader: mockDocumentLoader
434
- });
435
- }
436
- await t.step("immediately", async () => {
437
- esm_default.hardReset();
438
- esm_default.spyGlobal();
439
- const requests = [];
440
- esm_default.post("begin:https://gw1.example/", (call) => {
441
- requests.push(call.url);
442
- return 500;
443
- });
444
- esm_default.post("begin:https://gw2.example/", (call) => {
445
- requests.push(call.url);
446
- return 202;
447
- });
448
- const federation = new FederationImpl({
449
- kv: new MemoryKvStore(),
450
- allowPrivateAddress: true
451
- });
452
- const events = [];
453
- federation.setOutboundObservers({ onDelivery(_ctx, event) {
454
- events.push(event);
455
- } });
456
- await createInboxContext(federation).forwardActivity(sender, recipient, {
457
- immediate: true,
458
- skipIfUnsigned: false
459
- });
460
- deepStrictEqual([...new Set(requests)], [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]);
461
- deepStrictEqual(events.map((event) => event.stage), ["planned", "handoff"]);
462
- strictEqual(events[0].deliveryId, events[1].deliveryId);
463
- for (const event of events) {
464
- strictEqual(event.destinationInbox, inboxOn("https://gw1.example"));
465
- strictEqual(event.portableInbox, PORTABLE_INBOX);
466
- }
467
- const planned = events[0];
468
- ok(planned.stage === "planned");
469
- strictEqual(planned.mode, "portable-fallback");
470
- });
471
- await t.step("through the queue", async () => {
472
- esm_default.hardReset();
473
- esm_default.spyGlobal();
474
- const { queue, queued } = createQueue();
475
- const federation = new FederationImpl({
476
- kv: new MemoryKvStore(),
477
- queue,
478
- manuallyStartQueue: true,
479
- allowPrivateAddress: true
480
- });
481
- const events = [];
482
- federation.setOutboundObservers({ onDelivery(_ctx, event) {
483
- events.push(event);
484
- } });
485
- await createInboxContext(federation).forwardActivity(sender, recipient, {
486
- orderingKey: "key",
487
- skipIfUnsigned: false
488
- });
489
- strictEqual(queued.length, 1);
490
- const message = queued[0].message;
491
- strictEqual(message.inbox, inboxOn("https://gw1.example"));
492
- strictEqual(message.portableInbox, PORTABLE_INBOX);
493
- deepStrictEqual(message.gatewayInboxes, [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]);
494
- strictEqual(queued[0].options?.orderingKey, `key\n${DID}`);
495
- deepStrictEqual(events.map((event) => event.stage), ["planned", "handoff"]);
496
- strictEqual(events[0].deliveryId, events[1].deliveryId);
497
- for (const event of events) {
498
- strictEqual(event.destinationInbox, inboxOn("https://gw1.example"));
499
- strictEqual(event.portableInbox, PORTABLE_INBOX);
500
- }
501
- const planned = events[0];
502
- ok(planned.stage === "planned");
503
- strictEqual(planned.mode, "portable-fallback");
504
- });
505
- esm_default.hardReset();
506
- });
507
- test("processQueuedTask() with portable inbox gateways", async (t) => {
508
- esm_default.spyGlobal();
509
- function createMessage(gateways, overrides = {}) {
510
- const gatewayInboxes = gateways.map((g) => inboxOn(g));
511
- return {
512
- type: "outbox",
513
- id: crypto.randomUUID(),
514
- baseUrl: "https://example.com",
515
- keys: [],
516
- activity: {
517
- "@context": "https://www.w3.org/ns/activitystreams",
518
- type: "Create",
519
- id: "https://example.com/activities/1",
520
- actor: "https://example.com/person2",
521
- object: {
522
- type: "Note",
523
- content: "test"
524
- }
525
- },
526
- activityId: "https://example.com/activities/1",
527
- activityType: "https://www.w3.org/ns/activitystreams#Create",
528
- inbox: gatewayInboxes[0],
529
- sharedInbox: false,
530
- actorIds: [`ap+ef61://${DID}/actor`],
531
- started: (/* @__PURE__ */ new Date()).toISOString(),
532
- attempt: 0,
533
- headers: {},
534
- orderingKey: `key\n${DID}`,
535
- portableInbox: PORTABLE_INBOX,
536
- gatewayInboxes,
537
- traceContext: {},
538
- ...overrides
539
- };
540
- }
541
- function setup(options = {}, queueOptions = {}) {
542
- const { queue, queued } = createQueue(queueOptions);
543
- const permanentFailures = [];
544
- const federation = new FederationImpl({
545
- kv: new MemoryKvStore(),
546
- queue,
547
- manuallyStartQueue: true,
548
- allowPrivateAddress: true,
549
- ...options
550
- });
551
- federation.setOutboxPermanentFailureHandler((_ctx, values) => {
552
- permanentFailures.push({
553
- inbox: values.inbox,
554
- statusCode: values.statusCode
555
- });
556
- });
557
- return {
558
- federation,
559
- queued,
560
- permanentFailures
561
- };
562
- }
563
- function mockGateways(responses) {
564
- esm_default.hardReset();
565
- esm_default.spyGlobal();
566
- const requests = [];
567
- for (const [gateway, response] of Object.entries(responses)) esm_default.post(`begin:${gateway}/`, (call) => {
568
- const { origin } = new URL(call.url);
569
- if (requests.at(-1) !== origin) requests.push(origin);
570
- return response instanceof Response ? response.clone() : response;
571
- });
572
- return requests;
573
- }
574
- await t.step("fails over from a transport error", async () => {
575
- esm_default.hardReset();
576
- esm_default.spyGlobal();
577
- const requests = [];
578
- esm_default.post("begin:https://gw1.example/", () => {
579
- requests.push("https://gw1.example");
580
- throw new TypeError("network error");
581
- });
582
- esm_default.post("begin:https://gw2.example/", () => {
583
- requests.push("https://gw2.example");
584
- return 202;
585
- });
586
- const { federation, queued } = setup();
587
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
588
- deepStrictEqual(requests, ["https://gw1.example", "https://gw2.example"]);
589
- strictEqual(queued.length, 0);
590
- });
591
- await t.step("retries the remaining gateways as one attempt", async () => {
592
- const requests = mockGateways({
593
- "https://gw1.example": 500,
594
- "https://gw2.example": 404,
595
- "https://gw3.example": 502
596
- });
597
- const { federation, queued, permanentFailures } = setup();
598
- await federation.processQueuedTask(void 0, createMessage([
599
- "https://gw1.example",
600
- "https://gw2.example",
601
- "https://gw3.example"
602
- ]));
603
- deepStrictEqual(requests, [
604
- "https://gw1.example",
605
- "https://gw2.example",
606
- "https://gw3.example"
607
- ]);
608
- strictEqual(permanentFailures.length, 0);
609
- strictEqual(queued.length, 1);
610
- const retry = queued[0].message;
611
- strictEqual(retry.attempt, 1);
612
- strictEqual(retry.inbox, inboxOn("https://gw1.example"));
613
- deepStrictEqual(retry.gatewayInboxes, [inboxOn("https://gw1.example"), inboxOn("https://gw3.example")]);
614
- strictEqual(queued[0].options?.orderingKey, `key\n${DID}`);
615
- ok(queued[0].options?.delay != null);
616
- });
617
- await t.step("reports a permanent failure once", async () => {
618
- mockGateways({
619
- "https://gw1.example": 410,
620
- "https://gw2.example": 404
621
- });
622
- const { federation, queued, permanentFailures } = setup();
623
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
624
- strictEqual(queued.length, 0);
625
- deepStrictEqual(permanentFailures, [{
626
- inbox: new URL(inboxOn("https://gw2.example")),
627
- statusCode: 404
628
- }]);
629
- });
630
- await t.step("respects custom permanent failure statuses", async () => {
631
- mockGateways({
632
- "https://gw1.example": 404,
633
- "https://gw2.example": 500
634
- });
635
- const { federation, queued, permanentFailures } = setup({ permanentFailureStatusCodes: [500] });
636
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
637
- strictEqual(permanentFailures.length, 0);
638
- deepStrictEqual(queued[0].message.gatewayInboxes, [inboxOn("https://gw1.example")]);
639
- });
640
- await t.step("gives up when the retry policy does", async () => {
641
- mockGateways({
642
- "https://gw1.example": 500,
643
- "https://gw2.example": 500
644
- });
645
- const { federation, queued, permanentFailures } = setup({ outboxRetryPolicy: () => null });
646
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
647
- strictEqual(queued.length, 0);
648
- strictEqual(permanentFailures.length, 0);
649
- });
650
- await t.step("throws with a natively retrying queue", async () => {
651
- mockGateways({
652
- "https://gw1.example": 500,
653
- "https://gw2.example": 502
654
- });
655
- const { federation, queued } = setup({}, { nativeRetrial: true });
656
- await rejects(() => federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"])), (error) => error instanceof SendActivityError && error.statusCode === 502);
657
- strictEqual(queued.length, 0);
658
- });
659
- await t.step("excludes permanent failures from native retries", async () => {
660
- mockGateways({
661
- "https://gw1.example": 404,
662
- "https://gw2.example": 500
663
- });
664
- const { federation, queued } = setup({}, { nativeRetrial: true });
665
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
666
- strictEqual(queued.length, 1);
667
- const retry = queued[0].message;
668
- strictEqual(retry.attempt, 1);
669
- deepStrictEqual(retry.gatewayInboxes, [inboxOn("https://gw2.example")]);
670
- });
671
- await t.step("drops a held delivery deferred by Retry-After", async () => {
672
- const requests = mockGateways({
673
- "https://gw1.example": 202,
674
- "https://gw2.example": 202
675
- });
676
- const { federation, queued } = setup({ circuitBreaker: { heldActivityTtl: { hours: 1 } } });
677
- const later = Temporal.Now.instant().add({ hours: 9 }).toString();
678
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"], {
679
- circuitHeld: true,
680
- circuitHeldSince: Temporal.Now.instant().subtract({ hours: 1 }).toString(),
681
- gatewayNotBefore: {
682
- [inboxOn("https://gw1.example")]: later,
683
- [inboxOn("https://gw2.example")]: later
684
- }
685
- }));
686
- deepStrictEqual(requests, []);
687
- strictEqual(queued.length, 0);
688
- });
689
- await t.step("retries when the first gateway is due", async () => {
690
- mockGateways({
691
- "https://gw1.example": new Response(null, {
692
- status: 429,
693
- headers: { "Retry-After": "60" }
694
- }),
695
- "https://gw2.example": new Response(null, {
696
- status: 503,
697
- headers: { "Retry-After": "3600" }
698
- })
699
- });
700
- const { federation, queued } = setup();
701
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
702
- strictEqual(queued.length, 1);
703
- const retry = queued[0].message;
704
- strictEqual(retry.attempt, 1);
705
- deepStrictEqual(Object.keys(retry.gatewayNotBefore ?? {}), [inboxOn("https://gw1.example"), inboxOn("https://gw2.example")]);
706
- strictEqual(Math.round(queued[0].options.delay.total("second")), 60);
707
- });
708
- await t.step("does not wait for Retry-After of every gateway", async () => {
709
- mockGateways({
710
- "https://gw1.example": new Response(null, {
711
- status: 429,
712
- headers: { "Retry-After": "3600" }
713
- }),
714
- "https://gw2.example": 500
715
- });
716
- const { federation, queued } = setup({ outboxRetryPolicy: () => Temporal.Duration.from({ seconds: 30 }) });
717
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
718
- strictEqual(queued.length, 1);
719
- const retry = queued[0].message;
720
- deepStrictEqual(Object.keys(retry.gatewayNotBefore ?? {}), [inboxOn("https://gw1.example")]);
721
- strictEqual(Math.round(queued[0].options.delay.total("second")), 30);
722
- });
723
- await t.step("ignores a Retry-After too long to honor", async () => {
724
- const requests = mockGateways({
725
- "https://gw1.example": new Response(null, {
726
- status: 429,
727
- headers: { "Retry-After": "9000000000000" }
728
- }),
729
- "https://gw2.example": 202
730
- });
731
- const { federation, queued } = setup();
732
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
733
- deepStrictEqual(requests, ["https://gw1.example", "https://gw2.example"]);
734
- strictEqual(queued.length, 0);
735
- });
736
- await t.step("skips gateways that are not to be tried yet", async () => {
737
- const requests = mockGateways({
738
- "https://gw1.example": 202,
739
- "https://gw2.example": 202
740
- });
741
- const { federation, queued } = setup();
742
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"], { gatewayNotBefore: { [inboxOn("https://gw1.example")]: Temporal.Now.instant().add({ hours: 1 }).toString() } }));
743
- deepStrictEqual(requests, ["https://gw2.example"]);
744
- strictEqual(queued.length, 0);
745
- });
746
- await t.step("holds when every gateway is held", async () => {
747
- const requests = mockGateways({
748
- "https://gw1.example": 202,
749
- "https://gw2.example": 202
750
- });
751
- const { federation, queued } = setup();
752
- const inAnHour = Temporal.Now.instant().add({ hours: 1 }).toString();
753
- const inAMinute = Temporal.Now.instant().add({ minutes: 1 }).toString();
754
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"], { gatewayNotBefore: {
755
- [inboxOn("https://gw1.example")]: inAnHour,
756
- [inboxOn("https://gw2.example")]: inAMinute
757
- } }));
758
- deepStrictEqual(requests, []);
759
- strictEqual(queued.length, 1);
760
- const held = queued[0].message;
761
- strictEqual(held.attempt, 0);
762
- strictEqual(held.circuitHeld, void 0);
763
- ok(queued[0].options.delay.total("second") <= 60);
764
- ok(queued[0].options.delay.total("second") > 50);
765
- });
766
- await t.step("skips a gateway whose circuit is open", async () => {
767
- const requests = mockGateways({
768
- "https://gw1.example": 500,
769
- "https://gw2.example": 202
770
- });
771
- const { federation, queued } = setup({ circuitBreaker: {
772
- failureThreshold: 1,
773
- recoveryDelay: { hours: 1 }
774
- } });
775
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
776
- deepStrictEqual(requests, ["https://gw1.example", "https://gw2.example"]);
777
- strictEqual(queued.length, 0);
778
- requests.length = 0;
779
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
780
- deepStrictEqual(requests, ["https://gw2.example"]);
781
- strictEqual(queued.length, 0);
782
- });
783
- await t.step("holds a permanent failure and an open circuit", async () => {
784
- const requests = mockGateways({
785
- "https://gw1.example": 500,
786
- "https://gw2.example": 404
787
- });
788
- const { federation, queued, permanentFailures } = setup({ circuitBreaker: {
789
- failureThreshold: 1,
790
- recoveryDelay: { hours: 1 }
791
- } });
792
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"]));
793
- deepStrictEqual(requests, ["https://gw1.example", "https://gw2.example"]);
794
- strictEqual(permanentFailures.length, 0);
795
- strictEqual(queued.length, 1);
796
- const held = queued[0].message;
797
- strictEqual(held.attempt, 0);
798
- strictEqual(held.circuitHeld, true);
799
- ok(held.circuitHeldSince != null);
800
- strictEqual(held.inbox, inboxOn("https://gw1.example"));
801
- deepStrictEqual(held.gatewayInboxes, [inboxOn("https://gw1.example")]);
802
- strictEqual(Math.round(queued[0].options.delay.total("minute")), 60);
803
- });
804
- await t.step("preserves when the delivery was first held", async () => {
805
- mockGateways({
806
- "https://gw1.example": 500,
807
- "https://gw2.example": 500
808
- });
809
- const { federation, queued } = setup({ circuitBreaker: { failureThreshold: 10 } });
810
- const heldSince = Temporal.Now.instant().subtract({ hours: 1 }).toString();
811
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"], {
812
- circuitHeld: true,
813
- circuitHeldSince: heldSince
814
- }));
815
- strictEqual(queued.length, 1);
816
- const retry = queued[0].message;
817
- strictEqual(retry.attempt, 1);
818
- strictEqual(retry.circuitHeld, void 0);
819
- strictEqual(retry.circuitHeldSince, heldSince);
820
- });
821
- await t.step("drops a delivery held for too long", async () => {
822
- const requests = mockGateways({
823
- "https://gw1.example": 202,
824
- "https://gw2.example": 202
825
- });
826
- const { federation, queued } = setup({ circuitBreaker: { heldActivityTtl: { hours: 1 } } });
827
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example", "https://gw2.example"], {
828
- circuitHeld: true,
829
- circuitHeldSince: Temporal.Now.instant().subtract({ hours: 2 }).toString()
830
- }));
831
- deepStrictEqual(requests, []);
832
- strictEqual(queued.length, 0);
833
- });
834
- await t.step("falls back to the ordinary path for one gateway", async () => {
835
- const requests = mockGateways({ "https://gw1.example": 404 });
836
- const { federation, queued, permanentFailures } = setup();
837
- await federation.processQueuedTask(void 0, createMessage(["https://gw1.example"]));
838
- deepStrictEqual(requests, ["https://gw1.example"]);
839
- strictEqual(queued.length, 0);
840
- strictEqual(permanentFailures.length, 1);
841
- });
842
- esm_default.hardReset();
843
- });
844
- //#endregion
845
- export {};