@fedify/fedify 2.0.0-pr.412.1559 → 2.0.0-pr.412.1794

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 (204) hide show
  1. package/README.md +3 -0
  2. package/dist/{actor-Cc6B76eG.js → actor-BXHc5r-q.js} +1 -1
  3. package/dist/actor-Ba9Z1eNJ.cjs +42079 -0
  4. package/dist/{actor-C22bXuuC.d.ts → actor-DqFajh9s.d.ts} +2 -2
  5. package/dist/{actor-CTAuCsWy.js → actor-DzhunPC_.js} +7058 -2722
  6. package/dist/actor-f2NtjyCg.d.cts +128 -0
  7. package/dist/{assert_rejects-DiIiJbZn.js → assert_rejects-Ce45JcFg.js} +1 -1
  8. package/dist/{assert_is_error-BPGph1Jx.js → assert_throws-BNXdRGWP.js} +31 -1
  9. package/dist/{builder-BOEBObR8.js → builder-u7usRsT3.js} +13 -8
  10. package/dist/chunk-DqRYRqnO.cjs +34 -0
  11. package/dist/client-94iWEfQa.d.cts +222 -0
  12. package/dist/{client-DF8anIB5.d.ts → client-BsGzbnV-.d.ts} +3 -75
  13. package/dist/{client-De-z2UnN.js → client-pY7-3icS.js} +3 -22
  14. package/dist/compat/mod.cjs +10 -0
  15. package/dist/compat/mod.d.cts +12 -0
  16. package/dist/compat/mod.d.ts +11 -12
  17. package/dist/compat/mod.js +5 -5
  18. package/dist/compat/transformers.test.js +20 -20
  19. package/dist/compat-DmDDELst.cjs +4 -0
  20. package/dist/compat-nxUqe4Z-.js +4 -0
  21. package/dist/{context-9gCpIkiz.d.ts → context-DG0huGW-.d.ts} +184 -127
  22. package/dist/context-DJ8aSy2Q.d.cts +2312 -0
  23. package/dist/{authdocloader-CLgDGafZ.js → docloader-CrbAy9Oc.js} +17 -8
  24. package/dist/{esm-CHdxdkuH.js → esm-C-Qa1zEM.js} +11 -11
  25. package/dist/federation/builder.test.js +9 -12
  26. package/dist/federation/collection.test.js +7 -9
  27. package/dist/federation/handler.test.js +27 -148
  28. package/dist/federation/idempotency.test.js +201 -0
  29. package/dist/federation/inbox.test.js +4 -6
  30. package/dist/federation/keycache.test.js +3 -4
  31. package/dist/federation/kv.test.js +7 -8
  32. package/dist/federation/middleware.test.js +242 -64
  33. package/dist/federation/mod.cjs +27 -0
  34. package/dist/federation/mod.d.cts +12 -0
  35. package/dist/federation/mod.d.ts +12 -13
  36. package/dist/federation/mod.js +13 -15
  37. package/dist/federation/mq.test.js +8 -10
  38. package/dist/federation/negotiation.test.js +26 -0
  39. package/dist/federation/retry.test.js +4 -5
  40. package/dist/federation/router.test.js +6 -8
  41. package/dist/federation/send.test.js +13 -15
  42. package/dist/federation-CRpdnOMS.cjs +244 -0
  43. package/dist/{federation-CMX7WzeL.js → federation-jcR8-ZxP.js} +3 -3
  44. package/dist/fixtures/media.example.com/avatars/test-avatar.jpg.json +6 -0
  45. package/dist/{http-DqSNLFNY.d.ts → http-BbO0ejuk.d.ts} +2 -2
  46. package/dist/{http-l0TEupZK.js → http-CUVx-vzb.js} +260 -10
  47. package/dist/{http-CcdM1brU.js → http-D2kIm9la.js} +3 -3
  48. package/dist/http-Dofes42e.cjs +1106 -0
  49. package/dist/http-M8k5mKc0.d.cts +253 -0
  50. package/dist/{inbox-B6DZbGNf.js → inbox-HjG5peXY.js} +24 -7
  51. package/dist/{key-CzLv1phF.js → key-CxdLUFS6.js} +3 -2
  52. package/dist/{keycache-B8HdZJSt.js → keycache-bU7COwsh.js} +1 -1
  53. package/dist/{keys-zZwiKkfx.js → keys-DMHs8XNn.js} +2 -1
  54. package/dist/kv-Bxr0Q87_.d.cts +81 -0
  55. package/dist/kv-cache-CGXcDejL.js +122 -0
  56. package/dist/kv-cache-DN9pfMBe.js +94 -0
  57. package/dist/kv-cache-Dkvbn6rg.cjs +134 -0
  58. package/dist/{ld-CBcQdZ6N.js → ld-CIhvSCCr.js} +5 -4
  59. package/dist/lookup-CHkCVZTU.js +260 -0
  60. package/dist/lookup-CfFkONZD.cjs +272 -0
  61. package/dist/{type-SK-d7Tbw.js → lookup-DQRtjvb1.js} +7266 -7087
  62. package/dist/middleware-Bot7EEwV.js +26 -0
  63. package/dist/middleware-CFJgmUMW.cjs +15 -0
  64. package/dist/{middleware-BRgu1IH8.js → middleware-CJlj5Olw.js} +86 -181
  65. package/dist/middleware-CjHl2NHA.js +15 -0
  66. package/dist/middleware-D74TgW2E.cjs +4225 -0
  67. package/dist/{middleware-CxEkcFW0.js → middleware-DMk2Mdn9.js} +117 -127
  68. package/dist/mod-0noXw66R.d.cts +107 -0
  69. package/dist/mod-B-hUPT2N.d.cts +1 -0
  70. package/dist/{mod-Drmz72EK.d.ts → mod-B2iOw50L.d.ts} +3 -3
  71. package/dist/mod-B9M-8jm2.d.ts +109 -0
  72. package/dist/{mod-Cxt4Kpf6.d.ts → mod-BlVovdcy.d.ts} +20 -2
  73. package/dist/{mod-Bqxcp7eN.d.ts → mod-BoHnwOCs.d.ts} +2 -2
  74. package/dist/mod-BxRCHTz-.d.cts +307 -0
  75. package/dist/mod-C2tOeRkN.d.cts +1 -0
  76. package/dist/mod-C58MZ7Wx.d.cts +113 -0
  77. package/dist/mod-DJcZDvjA.d.cts +80 -0
  78. package/dist/mod-DgdBYYa0.d.cts +266 -0
  79. package/dist/{mod-DBzN0aCM.d.ts → mod-Ds0mpFZU.d.ts} +1 -1
  80. package/dist/mod.cjs +137 -0
  81. package/dist/mod.d.cts +16 -0
  82. package/dist/mod.d.ts +16 -17
  83. package/dist/mod.js +19 -21
  84. package/dist/mq-DcJPkXD5.d.cts +140 -0
  85. package/dist/negotiation-C4nFufNk.js +71 -0
  86. package/dist/nodeinfo/client.test.js +30 -111
  87. package/dist/nodeinfo/handler.test.js +25 -26
  88. package/dist/nodeinfo/mod.cjs +10 -0
  89. package/dist/nodeinfo/mod.d.cts +3 -0
  90. package/dist/nodeinfo/mod.d.ts +3 -5
  91. package/dist/nodeinfo/mod.js +6 -7
  92. package/dist/nodeinfo/types.test.js +8 -15
  93. package/dist/nodeinfo-BnthBobC.js +4 -0
  94. package/dist/nodeinfo-CdN0rEnZ.cjs +4 -0
  95. package/dist/owner-B4HbyP8s.d.cts +67 -0
  96. package/dist/{owner-VEIjmR8r.js → owner-Dvh7mBvr.js} +3 -2
  97. package/dist/{owner-CQPnQVtf.d.ts → owner-kQRGVXG1.d.ts} +3 -3
  98. package/dist/proof-D0uThUvD.cjs +674 -0
  99. package/dist/{proof-DoSQAGkE.js → proof-Dgy35fzc.js} +3 -3
  100. package/dist/{proof-tgUlT8hw.js → proof-fqzaMJ4g.js} +11 -10
  101. package/dist/{send-BzS7w-QF.js → send-Drp20VO9.js} +2 -2
  102. package/dist/sig/http.test.js +13 -14
  103. package/dist/sig/key.test.js +9 -11
  104. package/dist/sig/ld.test.js +8 -10
  105. package/dist/sig/mod.cjs +28 -0
  106. package/dist/sig/mod.d.cts +6 -0
  107. package/dist/sig/mod.d.ts +5 -7
  108. package/dist/sig/mod.js +8 -10
  109. package/dist/sig/owner.test.js +10 -12
  110. package/dist/sig/proof.test.js +13 -14
  111. package/dist/sig-C34-oHBl.js +4 -0
  112. package/dist/sig-YYj5tCnr.cjs +4 -0
  113. package/dist/testing/docloader.test.js +6 -8
  114. package/dist/testing/mod.d.ts +387 -224
  115. package/dist/testing/mod.js +2 -3
  116. package/dist/{testing-Z2omCvKy.js → testing-g4UC4liW.js} +1 -2
  117. package/dist/{transformers-Dna8Fg7k.js → transformers-BFT6d7J5.js} +3 -3
  118. package/dist/transformers-CoBS-oFG.cjs +116 -0
  119. package/dist/{types-DgPvoUWN.js → types-BtUjyi5y.js} +8 -169
  120. package/dist/{types-BIgY6c-l.js → types-C2XVl6gj.js} +1 -3
  121. package/dist/types-CWgzGaqk.cjs +315 -0
  122. package/dist/{runtime/authdocloader.test.js → utils/docloader.test.js} +14 -15
  123. package/dist/utils/kv-cache.test.js +209 -0
  124. package/dist/utils/mod.cjs +12 -0
  125. package/dist/utils/mod.d.cts +5 -0
  126. package/dist/utils/mod.d.ts +7 -0
  127. package/dist/utils/mod.js +11 -0
  128. package/dist/utils-D-Va7aXC.js +4 -0
  129. package/dist/utils-DyRU1gdZ.cjs +4 -0
  130. package/dist/vocab/actor.test.js +8 -10
  131. package/dist/vocab/lookup.test.js +257 -9
  132. package/dist/vocab/mod.cjs +86 -0
  133. package/dist/vocab/mod.d.cts +4 -0
  134. package/dist/vocab/mod.d.ts +3 -5
  135. package/dist/vocab/mod.js +6 -7
  136. package/dist/vocab/type.test.js +2 -3
  137. package/dist/vocab/vocab.test.js +438 -15
  138. package/dist/{vocab-SOE1ifCr.d.ts → vocab-BCWe1Ih5.d.ts} +292 -21
  139. package/dist/{vocab-CvD6Vbml.js → vocab-BnR3nIU9.js} +26 -17
  140. package/dist/vocab-CeDBzu-f.d.cts +14903 -0
  141. package/dist/{lookup-Bn_HEC_d.js → vocab-DFaWWYDn.cjs} +108 -139
  142. package/dist/webfinger/handler.test.js +24 -25
  143. package/dist/webfinger/lookup.test.js +7 -9
  144. package/dist/webfinger/mod.cjs +8 -0
  145. package/dist/webfinger/mod.d.cts +2 -0
  146. package/dist/webfinger/mod.d.ts +1 -3
  147. package/dist/webfinger/mod.js +5 -6
  148. package/dist/webfinger-C72Y8lrh.js +4 -0
  149. package/dist/webfinger-vAtLmxOF.cjs +4 -0
  150. package/dist/x/cfworkers.cjs +100 -0
  151. package/dist/x/cfworkers.d.cts +59 -0
  152. package/dist/x/cfworkers.d.ts +2 -2
  153. package/dist/x/cfworkers.js +3 -3
  154. package/dist/x/cfworkers.test.js +6 -8
  155. package/dist/x/hono.cjs +61 -0
  156. package/dist/x/hono.d.cts +53 -0
  157. package/dist/x/hono.d.ts +10 -11
  158. package/dist/x/hono.js +3 -3
  159. package/dist/x/sveltekit.cjs +69 -0
  160. package/dist/x/sveltekit.d.cts +45 -0
  161. package/dist/x/sveltekit.d.ts +10 -11
  162. package/dist/x/sveltekit.js +3 -3
  163. package/package.json +79 -23
  164. package/dist/assert_throws-BOO88avQ.js +0 -39
  165. package/dist/authdocloader-BFVqUbyo.js +0 -52
  166. package/dist/compat-Bb5myD13.js +0 -4
  167. package/dist/docloader-CxWcuWqQ.d.ts +0 -221
  168. package/dist/docloader-DEhniCVa.js +0 -4615
  169. package/dist/key-CUZQgVlf.js +0 -10
  170. package/dist/key-Deb0_wWL.js +0 -10
  171. package/dist/key-DxA6xRtZ.js +0 -260
  172. package/dist/lookup-dtdr2ftf.js +0 -131
  173. package/dist/middleware-BE_geSiJ.js +0 -17
  174. package/dist/middleware-BnU6hzVp.js +0 -26
  175. package/dist/mod-TFoH2Ql8.d.ts +0 -104
  176. package/dist/nodeinfo/semver.test.js +0 -143
  177. package/dist/nodeinfo-CyEbLjHs.js +0 -4
  178. package/dist/runtime/docloader.test.js +0 -522
  179. package/dist/runtime/key.test.js +0 -103
  180. package/dist/runtime/langstr.test.d.ts +0 -3
  181. package/dist/runtime/langstr.test.js +0 -39
  182. package/dist/runtime/mod.d.ts +0 -8
  183. package/dist/runtime/mod.js +0 -13
  184. package/dist/runtime/multibase/multibase.test.d.ts +0 -3
  185. package/dist/runtime/multibase/multibase.test.js +0 -358
  186. package/dist/runtime/url.test.d.ts +0 -3
  187. package/dist/runtime/url.test.js +0 -45
  188. package/dist/runtime-BSkOVUWM.js +0 -4
  189. package/dist/semver-dArNLkR9.js +0 -149
  190. package/dist/sig-BXJO--F9.js +0 -4
  191. package/dist/webfinger-C3GIyXIg.js +0 -4
  192. /package/dist/{assert_not_equals-f3m3epl3.js → assert_not_equals-C80BG-_5.js} +0 -0
  193. /package/dist/{collection-CSzG2j1P.js → collection-BzWsN9pB.js} +0 -0
  194. /package/dist/{denokv-Bv33Xxea.js → denokv-CCssOzMJ.js} +0 -0
  195. /package/dist/{nodeinfo/semver.test.d.ts → federation/idempotency.test.d.ts} +0 -0
  196. /package/dist/{runtime/authdocloader.test.d.ts → federation/negotiation.test.d.ts} +0 -0
  197. /package/dist/{kv-C7sopW2E.d.ts → kv-BKNZ-Tb-.d.ts} +0 -0
  198. /package/dist/{mod-1pDWKvUL.d.ts → mod-CVgZgliM.d.ts} +0 -0
  199. /package/dist/{mod-g0xFzAP9.d.ts → mod-xIj-IT58.d.ts} +0 -0
  200. /package/dist/{mq-CRGm1e_F.d.ts → mq-CUKlBw08.d.ts} +0 -0
  201. /package/dist/{retry-D4GJ670a.js → retry-CfF8Gn4d.js} +0 -0
  202. /package/dist/{std__assert-X-_kMxKM.js → std__assert-DWivtrGR.js} +0 -0
  203. /package/dist/{runtime → utils}/docloader.test.d.ts +0 -0
  204. /package/dist/{runtime/key.test.d.ts → utils/kv-cache.test.d.ts} +0 -0
@@ -1,143 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import "../type-SK-d7Tbw.js";
7
- import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
- import "../assert-MZs1qjMx.js";
9
- import "../assert_instance_of-DHz7EHNU.js";
10
- import { formatSemVer, parseSemVer } from "../semver-dArNLkR9.js";
11
- import "../lookup-Bn_HEC_d.js";
12
- import { test } from "../testing-Z2omCvKy.js";
13
- import "../std__assert-X-_kMxKM.js";
14
- import "../assert_rejects-DiIiJbZn.js";
15
- import "../assert_is_error-BPGph1Jx.js";
16
- import "../assert_not_equals-f3m3epl3.js";
17
- import { assertThrows } from "../assert_throws-BOO88avQ.js";
18
-
19
- //#region src/nodeinfo/semver.test.ts
20
- test("parseSemVer() handles major", async (t) => {
21
- const versions = [
22
- ["1.2.3", 1],
23
- [" 1.2.3 ", 1],
24
- [" 2.2.3-4 ", 2],
25
- [" 3.2.3-pre ", 3],
26
- ["v5.2.3", 5],
27
- [" v8.2.3 ", 8],
28
- [" 13.2.3", 13]
29
- ];
30
- for (const [v, expected] of versions) await t.step(v, () => {
31
- const version = parseSemVer(v);
32
- assertEquals(version.major, expected);
33
- });
34
- });
35
- test("parseSemVer() handles minor", async (t) => {
36
- const versions = [
37
- ["1.1.3", 1],
38
- [" 1.1.3 ", 1],
39
- [" 1.2.3-4 ", 2],
40
- [" 1.3.3-pre ", 3],
41
- ["v1.5.3", 5],
42
- [" v1.8.3 ", 8],
43
- [" 1.13.3", 13]
44
- ];
45
- for (const [v, expected] of versions) await t.step(v, () => {
46
- const version = parseSemVer(v);
47
- assertEquals(version.minor, expected);
48
- });
49
- });
50
- test("parseSemVer() handles patch", async (t) => {
51
- const versions = [
52
- ["1.2.1", 1],
53
- [" 1.2.1 ", 1],
54
- [" 1.2.2-4 ", 2],
55
- [" 1.2.3-pre ", 3],
56
- ["v1.2.5", 5],
57
- [" v1.2.8 ", 8],
58
- [" 1.2.13", 13]
59
- ];
60
- for (const [v, expected] of versions) await t.step(v, () => {
61
- const semver = parseSemVer(v);
62
- const actual = semver.patch;
63
- assertEquals(actual, expected);
64
- });
65
- });
66
- test("parseSemVer() handles prerelease", async (t) => {
67
- const versions = [
68
- ["1.2.2-alpha.1", ["alpha", 1]],
69
- ["0.6.1-1", [1]],
70
- ["1.0.0-beta.2", ["beta", 2]],
71
- ["v0.5.4-pre", ["pre"]],
72
- ["1.2.2-alpha.1", ["alpha", 1]],
73
- ["1.2.0-1b3-4", ["1b3-4"]],
74
- ["1.2.0-3.6-pre2", [3, "6-pre2"]],
75
- ["2.0.0", []]
76
- ];
77
- for (const [v, expected] of versions) await t.step(`${v} : ${JSON.stringify(expected)}`, () => {
78
- const semver = parseSemVer(v);
79
- assertEquals(semver.prerelease, expected);
80
- });
81
- });
82
- test({
83
- name: "parseSemVer() throws on bad versions",
84
- fn: async (t) => {
85
- const versions = [
86
- ["1.2." + new Array(256).join("1")],
87
- ["1.2." + new Array(100).join("1")],
88
- [null],
89
- [void 0],
90
- [{}],
91
- [[]],
92
- [false],
93
- [true],
94
- [0],
95
- [""],
96
- ["not a version"],
97
- ["∞.∞.∞"],
98
- ["NaN.NaN.NaN"]
99
- ];
100
- for (const [v] of versions) await t.step(`${JSON.stringify(v)}`, () => {
101
- assertThrows(() => parseSemVer(v));
102
- });
103
- }
104
- });
105
- test("parseSemVer() throws on invalid versions", async (t) => {
106
- const versions = [
107
- "1.2.3.4",
108
- "NOT VALID",
109
- 1.2,
110
- null,
111
- "Infinity.NaN.Infinity"
112
- ];
113
- for (const v of versions) await t.step(`invalid ${v}`, () => {
114
- assertThrows(function() {
115
- parseSemVer(v);
116
- }, TypeError);
117
- });
118
- });
119
- test("parseSemVer() handles big numeric prerelease", function() {
120
- const r = parseSemVer(`1.2.3-beta.${Number.MAX_SAFE_INTEGER}0`);
121
- assertEquals(r.prerelease, ["beta", "90071992547409910"]);
122
- });
123
- test("formatSemVer()", async (t) => {
124
- const versions = [
125
- ["0.0.0", "0.0.0"],
126
- ["1.2.3", "1.2.3"],
127
- ["1.2.3-pre", "1.2.3-pre"],
128
- ["1.2.3-pre.0", "1.2.3-pre.0"],
129
- ["1.2.3+b", "1.2.3+b"],
130
- ["1.2.3+b.0", "1.2.3+b.0"],
131
- ["1.2.3-pre.0+b.0", "1.2.3-pre.0+b.0"]
132
- ];
133
- for (const [version, expected] of versions) await t.step({
134
- name: version,
135
- fn: () => {
136
- const v = parseSemVer(version);
137
- const actual = formatSemVer(v);
138
- assertEquals(actual, expected);
139
- }
140
- });
141
- });
142
-
143
- //#endregion
@@ -1,4 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
@@ -1,522 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import { FetchError, UrlError, contexts_default, deno_default, getDocumentLoader, getUserAgent, kvCache } from "../type-SK-d7Tbw.js";
7
- import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
- import "../assert-MZs1qjMx.js";
9
- import "../assert_instance_of-DHz7EHNU.js";
10
- import { MemoryKvStore } from "../kv-CRZrzyXm.js";
11
- import "../lookup-Bn_HEC_d.js";
12
- import { mockDocumentLoader, test } from "../testing-Z2omCvKy.js";
13
- import "../std__assert-X-_kMxKM.js";
14
- import { assertRejects } from "../assert_rejects-DiIiJbZn.js";
15
- import "../assert_is_error-BPGph1Jx.js";
16
- import "../assert_not_equals-f3m3epl3.js";
17
- import { assertThrows } from "../assert_throws-BOO88avQ.js";
18
- import { esm_default } from "../esm-CHdxdkuH.js";
19
- import process from "node:process";
20
-
21
- //#region src/runtime/docloader.test.ts
22
- test("new FetchError()", () => {
23
- const e = new FetchError("https://example.com/", "An error message.");
24
- assertEquals(e.name, "FetchError");
25
- assertEquals(e.url, new URL("https://example.com/"));
26
- assertEquals(e.message, "https://example.com/: An error message.");
27
- const e2 = new FetchError(new URL("https://example.org/"));
28
- assertEquals(e2.url, new URL("https://example.org/"));
29
- assertEquals(e2.message, "https://example.org/");
30
- });
31
- test("getDocumentLoader()", async (t) => {
32
- const fetchDocumentLoader = getDocumentLoader();
33
- esm_default.spyGlobal();
34
- esm_default.get("https://example.com/object", { body: {
35
- "@context": "https://www.w3.org/ns/activitystreams",
36
- id: "https://example.com/object",
37
- name: "Fetched object",
38
- type: "Object"
39
- } });
40
- await t.step("ok", async () => {
41
- assertEquals(await fetchDocumentLoader("https://example.com/object"), {
42
- contextUrl: null,
43
- documentUrl: "https://example.com/object",
44
- document: {
45
- "@context": "https://www.w3.org/ns/activitystreams",
46
- id: "https://example.com/object",
47
- name: "Fetched object",
48
- type: "Object"
49
- }
50
- });
51
- });
52
- esm_default.get("https://example.com/link-ctx", {
53
- body: {
54
- id: "https://example.com/link-ctx",
55
- name: "Fetched object",
56
- type: "Object"
57
- },
58
- headers: {
59
- "Content-Type": "application/activity+json",
60
- Link: "<https://www.w3.org/ns/activitystreams>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\""
61
- }
62
- });
63
- esm_default.get("https://example.com/link-obj", { headers: {
64
- "Content-Type": "text/html; charset=utf-8",
65
- Link: "<https://example.com/object>; rel=\"alternate\"; type=\"application/activity+json\""
66
- } });
67
- esm_default.get("https://example.com/link-obj-relative", { headers: {
68
- "Content-Type": "text/html; charset=utf-8",
69
- Link: "</object>; rel=\"alternate\"; type=\"application/activity+json\""
70
- } });
71
- esm_default.get("https://example.com/obj-w-wrong-link", {
72
- body: {
73
- "@context": "https://www.w3.org/ns/activitystreams",
74
- id: "https://example.com/obj-w-wrong-link",
75
- name: "Fetched object",
76
- type: "Object"
77
- },
78
- headers: {
79
- "Content-Type": "text/html; charset=utf-8",
80
- Link: "<https://example.com/object>; rel=\"alternate\"; type=\"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"\""
81
- }
82
- });
83
- await t.step("Link header", async () => {
84
- assertEquals(await fetchDocumentLoader("https://example.com/link-ctx"), {
85
- contextUrl: "https://www.w3.org/ns/activitystreams",
86
- documentUrl: "https://example.com/link-ctx",
87
- document: {
88
- id: "https://example.com/link-ctx",
89
- name: "Fetched object",
90
- type: "Object"
91
- }
92
- });
93
- assertEquals(await fetchDocumentLoader("https://example.com/link-obj"), {
94
- contextUrl: null,
95
- documentUrl: "https://example.com/object",
96
- document: {
97
- "@context": "https://www.w3.org/ns/activitystreams",
98
- id: "https://example.com/object",
99
- name: "Fetched object",
100
- type: "Object"
101
- }
102
- });
103
- });
104
- await t.step("Link header relative url", async () => {
105
- assertEquals(await fetchDocumentLoader("https://example.com/link-ctx"), {
106
- contextUrl: "https://www.w3.org/ns/activitystreams",
107
- documentUrl: "https://example.com/link-ctx",
108
- document: {
109
- id: "https://example.com/link-ctx",
110
- name: "Fetched object",
111
- type: "Object"
112
- }
113
- });
114
- assertEquals(await fetchDocumentLoader("https://example.com/link-obj-relative"), {
115
- contextUrl: null,
116
- documentUrl: "https://example.com/object",
117
- document: {
118
- "@context": "https://www.w3.org/ns/activitystreams",
119
- id: "https://example.com/object",
120
- name: "Fetched object",
121
- type: "Object"
122
- }
123
- });
124
- });
125
- await t.step("wrong Link header syntax", async () => {
126
- assertEquals(await fetchDocumentLoader("https://example.com/obj-w-wrong-link"), {
127
- contextUrl: null,
128
- documentUrl: "https://example.com/obj-w-wrong-link",
129
- document: {
130
- "@context": "https://www.w3.org/ns/activitystreams",
131
- id: "https://example.com/obj-w-wrong-link",
132
- name: "Fetched object",
133
- type: "Object"
134
- }
135
- });
136
- });
137
- esm_default.get("https://example.com/html-link", {
138
- body: `<html>
139
- <head>
140
- <meta charset=utf-8>
141
- <link
142
- rel=alternate
143
- type='application/activity+json'
144
- href="https://example.com/object">
145
- </head>
146
- </html>`,
147
- headers: { "Content-Type": "text/html; charset=utf-8" }
148
- });
149
- await t.step("HTML <link>", async () => {
150
- assertEquals(await fetchDocumentLoader("https://example.com/html-link"), {
151
- contextUrl: null,
152
- documentUrl: "https://example.com/object",
153
- document: {
154
- "@context": "https://www.w3.org/ns/activitystreams",
155
- id: "https://example.com/object",
156
- name: "Fetched object",
157
- type: "Object"
158
- }
159
- });
160
- });
161
- esm_default.get("https://example.com/xhtml-link", {
162
- body: `<html>
163
- <head>
164
- <meta charset="utf-8" />
165
- <link
166
- rel=alternate
167
- type="application/activity+json"
168
- href="https://example.com/object" />
169
- </head>
170
- </html>`,
171
- headers: { "Content-Type": "application/xhtml+xml; charset=utf-8" }
172
- });
173
- await t.step("XHTML <link>", async () => {
174
- assertEquals(await fetchDocumentLoader("https://example.com/xhtml-link"), {
175
- contextUrl: null,
176
- documentUrl: "https://example.com/object",
177
- document: {
178
- "@context": "https://www.w3.org/ns/activitystreams",
179
- id: "https://example.com/object",
180
- name: "Fetched object",
181
- type: "Object"
182
- }
183
- });
184
- });
185
- esm_default.get("https://example.com/html-a", {
186
- body: `<html>
187
- <head>
188
- <meta charset=utf-8>
189
- </head>
190
- <body>
191
- <a
192
- rel=alternate
193
- type=application/activity+json
194
- href=https://example.com/object>test</a>
195
- </body>
196
- </html>`,
197
- headers: { "Content-Type": "text/html; charset=utf-8" }
198
- });
199
- await t.step("HTML <a>", async () => {
200
- assertEquals(await fetchDocumentLoader("https://example.com/html-a"), {
201
- contextUrl: null,
202
- documentUrl: "https://example.com/object",
203
- document: {
204
- "@context": "https://www.w3.org/ns/activitystreams",
205
- id: "https://example.com/object",
206
- name: "Fetched object",
207
- type: "Object"
208
- }
209
- });
210
- });
211
- esm_default.get("https://example.com/wrong-content-type", {
212
- body: {
213
- "@context": "https://www.w3.org/ns/activitystreams",
214
- id: "https://example.com/wrong-content-type",
215
- name: "Fetched object",
216
- type: "Object"
217
- },
218
- headers: { "Content-Type": "text/html; charset=utf-8" }
219
- });
220
- await t.step("Wrong Content-Type", async () => {
221
- assertEquals(await fetchDocumentLoader("https://example.com/wrong-content-type"), {
222
- contextUrl: null,
223
- documentUrl: "https://example.com/wrong-content-type",
224
- document: {
225
- "@context": "https://www.w3.org/ns/activitystreams",
226
- id: "https://example.com/wrong-content-type",
227
- name: "Fetched object",
228
- type: "Object"
229
- }
230
- });
231
- });
232
- esm_default.get("https://example.com/404", { status: 404 });
233
- await t.step("not ok", async () => {
234
- await assertRejects(() => fetchDocumentLoader("https://example.com/404"), FetchError, "HTTP 404: https://example.com/404");
235
- });
236
- await t.step("preloaded contexts", async () => {
237
- for (const [url, document] of Object.entries(contexts_default)) assertEquals(await fetchDocumentLoader(url), {
238
- contextUrl: null,
239
- documentUrl: url,
240
- document
241
- });
242
- });
243
- await t.step("deny non-HTTP/HTTPS", async () => {
244
- await assertRejects(() => fetchDocumentLoader("ftp://localhost"), UrlError);
245
- });
246
- esm_default.get("https://example.com/localhost-redirect", {
247
- status: 302,
248
- headers: { Location: "https://localhost/object" }
249
- });
250
- esm_default.get("https://example.com/localhost-link", {
251
- body: `<html>
252
- <head>
253
- <meta charset=utf-8>
254
- <link
255
- rel=alternate
256
- type='application/activity+json'
257
- href="https://localhost/object">
258
- </head>
259
- </html>`,
260
- headers: { "Content-Type": "text/html; charset=utf-8" }
261
- });
262
- esm_default.get("https://localhost/object", { body: {
263
- "@context": "https://www.w3.org/ns/activitystreams",
264
- id: "https://localhost/object",
265
- name: "Fetched object",
266
- type: "Object"
267
- } });
268
- await t.step("allowPrivateAddress: false", async () => {
269
- await assertRejects(() => fetchDocumentLoader("https://localhost/object"), UrlError);
270
- await assertRejects(() => fetchDocumentLoader("https://example.com/localhost-redirect"), UrlError);
271
- await assertRejects(() => fetchDocumentLoader("https://example.com/localhost-link"), UrlError);
272
- });
273
- const fetchDocumentLoader2 = getDocumentLoader({ allowPrivateAddress: true });
274
- await t.step("allowPrivateAddress: true", async () => {
275
- const expected = {
276
- contextUrl: null,
277
- documentUrl: "https://localhost/object",
278
- document: {
279
- "@context": "https://www.w3.org/ns/activitystreams",
280
- id: "https://localhost/object",
281
- name: "Fetched object",
282
- type: "Object"
283
- }
284
- };
285
- assertEquals(await fetchDocumentLoader2("https://localhost/object"), expected);
286
- assertEquals(await fetchDocumentLoader2("https://example.com/localhost-redirect"), expected);
287
- assertEquals(await fetchDocumentLoader2("https://example.com/localhost-link"), expected);
288
- });
289
- esm_default.hardReset();
290
- });
291
- test("kvCache()", async (t) => {
292
- const kv = new MemoryKvStore();
293
- await t.step("cached", async () => {
294
- const loader = kvCache({
295
- kv,
296
- loader: mockDocumentLoader,
297
- rules: [
298
- ["https://example.org/", Temporal.Duration.from({ days: 1 })],
299
- [new URL("https://example.net/"), Temporal.Duration.from({ days: 1 })],
300
- [new URLPattern("https://example.com/*"), Temporal.Duration.from({ days: 30 })]
301
- ],
302
- prefix: ["_test", "cached"]
303
- });
304
- const result = await loader("https://example.com/object");
305
- assertEquals(result, {
306
- contextUrl: null,
307
- documentUrl: "https://example.com/object",
308
- document: {
309
- "@context": "https://www.w3.org/ns/activitystreams",
310
- id: "https://example.com/object",
311
- name: "Fetched object",
312
- type: "Object"
313
- }
314
- });
315
- const cache = await kv.get([
316
- "_test",
317
- "cached",
318
- "https://example.com/object"
319
- ]);
320
- assertEquals(cache, result);
321
- await kv.set([
322
- "_test",
323
- "cached",
324
- "https://example.org/"
325
- ], {
326
- contextUrl: null,
327
- documentUrl: "https://example.org/",
328
- document: { "id": "https://example.org/" }
329
- });
330
- const result2 = await loader("https://example.org/");
331
- assertEquals(result2, {
332
- contextUrl: null,
333
- documentUrl: "https://example.org/",
334
- document: { "id": "https://example.org/" }
335
- });
336
- await kv.set([
337
- "_test",
338
- "cached",
339
- "https://example.net/"
340
- ], {
341
- contextUrl: null,
342
- documentUrl: "https://example.net/",
343
- document: { "id": "https://example.net/" }
344
- });
345
- const result3 = await loader("https://example.net/");
346
- assertEquals(result3, {
347
- contextUrl: null,
348
- documentUrl: "https://example.net/",
349
- document: { "id": "https://example.net/" }
350
- });
351
- });
352
- await t.step("not cached", async () => {
353
- const loader = kvCache({
354
- kv,
355
- loader: mockDocumentLoader,
356
- rules: [],
357
- prefix: ["_test", "not cached"]
358
- });
359
- const result = await loader("https://example.com/object");
360
- assertEquals(result, {
361
- contextUrl: null,
362
- documentUrl: "https://example.com/object",
363
- document: {
364
- "@context": "https://www.w3.org/ns/activitystreams",
365
- id: "https://example.com/object",
366
- name: "Fetched object",
367
- type: "Object"
368
- }
369
- });
370
- const cache = await kv.get([
371
- "test2",
372
- "not cached",
373
- "https://example.com/object"
374
- ]);
375
- assertEquals(cache, void 0);
376
- });
377
- await t.step("maximum cache duration", () => {
378
- assertThrows(() => kvCache({
379
- kv,
380
- loader: mockDocumentLoader,
381
- rules: [["https://example.com/", Temporal.Duration.from({
382
- days: 30,
383
- seconds: 1
384
- })]]
385
- }), TypeError, "The maximum cache duration is 30 days");
386
- assertThrows(() => kvCache({
387
- kv,
388
- loader: mockDocumentLoader,
389
- rules: [[new URLPattern("https://example.com/*"), Temporal.Duration.from({
390
- days: 30,
391
- seconds: 1
392
- })]]
393
- }), TypeError, "The maximum cache duration is 30 days");
394
- });
395
- await t.step("on kv store exception", async () => {
396
- class KvStoreThrowsException {
397
- get(_key) {
398
- throw new Error("Failed to get key");
399
- }
400
- set(_key, _value, _options) {
401
- throw new Error("Failed to set key");
402
- }
403
- delete(_key) {
404
- throw new Error("Failed to delete key");
405
- }
406
- }
407
- const loader = kvCache({
408
- kv: new KvStoreThrowsException(),
409
- loader: mockDocumentLoader,
410
- rules: [
411
- ["https://example.org/", Temporal.Duration.from({ days: 1 })],
412
- [new URL("https://example.net/"), Temporal.Duration.from({ days: 1 })],
413
- [new URLPattern("https://example.com/*"), Temporal.Duration.from({ days: 30 })]
414
- ],
415
- prefix: ["_test", "not cached"]
416
- });
417
- const result = await loader("https://example.com/object");
418
- assertEquals(result, {
419
- contextUrl: null,
420
- documentUrl: "https://example.com/object",
421
- document: {
422
- "@context": "https://www.w3.org/ns/activitystreams",
423
- id: "https://example.com/object",
424
- name: "Fetched object",
425
- type: "Object"
426
- }
427
- });
428
- });
429
- await t.step("preloaded contexts bypass cache", async () => {
430
- const kv$1 = new MemoryKvStore();
431
- let loaderCalled = false;
432
- const mockLoader = (url) => {
433
- loaderCalled = true;
434
- return Promise.resolve({
435
- contextUrl: null,
436
- documentUrl: url,
437
- document: { "mock": "document" }
438
- });
439
- };
440
- const loader = kvCache({
441
- kv: kv$1,
442
- loader: mockLoader,
443
- prefix: ["_test", "preloaded"]
444
- });
445
- const activityStreamsUrl = "https://www.w3.org/ns/activitystreams";
446
- loaderCalled = false;
447
- const result = await loader(activityStreamsUrl);
448
- assertEquals(result, {
449
- contextUrl: null,
450
- documentUrl: activityStreamsUrl,
451
- document: contexts_default[activityStreamsUrl]
452
- });
453
- assertEquals(loaderCalled, false, "Loader should not be called for preloaded contexts");
454
- const cachedValue = await kv$1.get([
455
- "_test",
456
- "preloaded",
457
- activityStreamsUrl
458
- ]);
459
- assertEquals(cachedValue, void 0, "Preloaded contexts should not be cached in KV store");
460
- const securityUrl = "https://w3id.org/security/v1";
461
- loaderCalled = false;
462
- const result2 = await loader(securityUrl);
463
- assertEquals(result2, {
464
- contextUrl: null,
465
- documentUrl: securityUrl,
466
- document: contexts_default[securityUrl]
467
- });
468
- assertEquals(loaderCalled, false, "Loader should not be called for preloaded contexts");
469
- const nonPreloadedUrl = "https://example.com/not-preloaded";
470
- loaderCalled = false;
471
- const result3 = await loader(nonPreloadedUrl);
472
- assertEquals(result3, {
473
- contextUrl: null,
474
- documentUrl: nonPreloadedUrl,
475
- document: { "mock": "document" }
476
- });
477
- assertEquals(loaderCalled, true, "Loader should be called for non-preloaded URLs");
478
- const cachedValue2 = await kv$1.get([
479
- "_test",
480
- "preloaded",
481
- nonPreloadedUrl
482
- ]);
483
- assertEquals(cachedValue2, result3, "Non-preloaded URLs should be cached");
484
- });
485
- });
486
- test("getUserAgent()", () => {
487
- if ("Deno" in globalThis) {
488
- assertEquals(getUserAgent(), `Fedify/${deno_default.version} (Deno/${Deno.version.deno})`);
489
- assertEquals(getUserAgent({ software: "MyApp/1.0.0" }), `MyApp/1.0.0 (Fedify/${deno_default.version}; Deno/${Deno.version.deno})`);
490
- assertEquals(getUserAgent({ url: "https://example.com/" }), `Fedify/${deno_default.version} (Deno/${Deno.version.deno}; +https://example.com/)`);
491
- assertEquals(getUserAgent({
492
- software: "MyApp/1.0.0",
493
- url: new URL("https://example.com/")
494
- }), `MyApp/1.0.0 (Fedify/${deno_default.version}; Deno/${Deno.version.deno}; +https://example.com/)`);
495
- } else if ("Bun" in globalThis) {
496
- assertEquals(getUserAgent(), `Fedify/${deno_default.version} (Bun/${Bun.version})`);
497
- assertEquals(getUserAgent({ software: "MyApp/1.0.0" }), `MyApp/1.0.0 (Fedify/${deno_default.version}; Bun/${Bun.version})`);
498
- assertEquals(getUserAgent({ url: "https://example.com/" }), `Fedify/${deno_default.version} (Bun/${Bun.version}; +https://example.com/)`);
499
- assertEquals(getUserAgent({
500
- software: "MyApp/1.0.0",
501
- url: new URL("https://example.com/")
502
- }), `MyApp/1.0.0 (Fedify/${deno_default.version}; Bun/${Bun.version}; +https://example.com/)`);
503
- } else if (navigator.userAgent === "Cloudflare-Workers") {
504
- assertEquals(getUserAgent(), `Fedify/${deno_default.version} (Cloudflare-Workers)`);
505
- assertEquals(getUserAgent({ software: "MyApp/1.0.0" }), `MyApp/1.0.0 (Fedify/${deno_default.version}; Cloudflare-Workers)`);
506
- assertEquals(getUserAgent({ url: "https://example.com/" }), `Fedify/${deno_default.version} (Cloudflare-Workers; +https://example.com/)`);
507
- assertEquals(getUserAgent({
508
- software: "MyApp/1.0.0",
509
- url: new URL("https://example.com/")
510
- }), `MyApp/1.0.0 (Fedify/${deno_default.version}; Cloudflare-Workers; +https://example.com/)`);
511
- } else {
512
- assertEquals(getUserAgent(), `Fedify/${deno_default.version} (Node.js/${process.versions.node})`);
513
- assertEquals(getUserAgent({ software: "MyApp/1.0.0" }), `MyApp/1.0.0 (Fedify/${deno_default.version}; Node.js/${process.versions.node})`);
514
- assertEquals(getUserAgent({ url: "https://example.com/" }), `Fedify/${deno_default.version} (Node.js/${process.versions.node}; +https://example.com/)`);
515
- assertEquals(getUserAgent({
516
- software: "MyApp/1.0.0",
517
- url: new URL("https://example.com/")
518
- }), `MyApp/1.0.0 (Fedify/${deno_default.version}; Node.js/${process.versions.node}; +https://example.com/)`);
519
- }
520
- });
521
-
522
- //#endregion