@fedify/fedify 2.0.0-pr.412.1692 → 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 (193) hide show
  1. package/README.md +3 -0
  2. package/dist/{actor-D5S46edz.js → actor-BXHc5r-q.js} +1 -1
  3. package/dist/{actor-CrTGiTZd.cjs → actor-Ba9Z1eNJ.cjs} +921 -1451
  4. package/dist/{actor-T6RyhRgk.d.ts → actor-DqFajh9s.d.ts} +2 -2
  5. package/dist/{actor-G2S5sPEA.js → actor-DzhunPC_.js} +189 -677
  6. package/dist/{actor-D6K058Tb.d.cts → actor-f2NtjyCg.d.cts} +2 -2
  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-OA47XRft.js → builder-u7usRsT3.js} +7 -8
  10. package/dist/{client-CegPX0Rn.d.cts → client-94iWEfQa.d.cts} +1 -1
  11. package/dist/{client-bgSdkFa2.d.ts → client-BsGzbnV-.d.ts} +1 -1
  12. package/dist/{client-Bmd-i8x8.js → client-pY7-3icS.js} +1 -1
  13. package/dist/compat/mod.d.cts +11 -12
  14. package/dist/compat/mod.d.ts +11 -12
  15. package/dist/compat/transformers.test.js +20 -20
  16. package/dist/{context-ByZprN0S.d.ts → context-DG0huGW-.d.ts} +124 -127
  17. package/dist/{context-C5BsZkDr.d.cts → context-DJ8aSy2Q.d.cts} +124 -127
  18. package/dist/{authdocloader-SjwloJUA.js → docloader-CrbAy9Oc.js} +17 -8
  19. package/dist/{esm-CwHz8Y8t.js → esm-C-Qa1zEM.js} +11 -11
  20. package/dist/federation/builder.test.js +8 -10
  21. package/dist/federation/collection.test.js +7 -9
  22. package/dist/federation/handler.test.js +25 -26
  23. package/dist/federation/idempotency.test.js +25 -26
  24. package/dist/federation/inbox.test.js +4 -6
  25. package/dist/federation/keycache.test.js +3 -4
  26. package/dist/federation/kv.test.js +6 -8
  27. package/dist/federation/middleware.test.js +32 -33
  28. package/dist/federation/mod.cjs +9 -11
  29. package/dist/federation/mod.d.cts +12 -13
  30. package/dist/federation/mod.d.ts +12 -13
  31. package/dist/federation/mod.js +9 -11
  32. package/dist/federation/mq.test.js +8 -10
  33. package/dist/federation/negotiation.test.js +7 -9
  34. package/dist/federation/retry.test.js +4 -5
  35. package/dist/federation/router.test.js +6 -8
  36. package/dist/federation/send.test.js +13 -15
  37. package/dist/{http-D6Uj2x2y.d.ts → http-BbO0ejuk.d.ts} +2 -2
  38. package/dist/{http-C5tC93Hn.js → http-CUVx-vzb.js} +256 -6
  39. package/dist/{http-DGjdMiLc.js → http-D2kIm9la.js} +2 -2
  40. package/dist/{http-BiBofurJ.cjs → http-Dofes42e.cjs} +289 -9
  41. package/dist/{http-D-e6AFwR.d.cts → http-M8k5mKc0.d.cts} +2 -2
  42. package/dist/{inbox-BoDY3z8G.js → inbox-HjG5peXY.js} +1 -1
  43. package/dist/{key-IxRhZpOF.js → key-CxdLUFS6.js} +3 -2
  44. package/dist/{keycache-TEniXNel.js → keycache-bU7COwsh.js} +1 -1
  45. package/dist/{keys-bZxcrZ9Z.js → keys-DMHs8XNn.js} +2 -1
  46. package/dist/kv-cache-CGXcDejL.js +122 -0
  47. package/dist/kv-cache-DN9pfMBe.js +94 -0
  48. package/dist/kv-cache-Dkvbn6rg.cjs +134 -0
  49. package/dist/{ld-DW7A0uIc.js → ld-CIhvSCCr.js} +3 -2
  50. package/dist/{lookup-cVRa2QM-.js → lookup-CHkCVZTU.js} +131 -2
  51. package/dist/lookup-CfFkONZD.cjs +272 -0
  52. package/dist/{type-NEA09tSC.js → lookup-DQRtjvb1.js} +503 -5328
  53. package/dist/middleware-Bot7EEwV.js +26 -0
  54. package/dist/middleware-CFJgmUMW.cjs +15 -0
  55. package/dist/{middleware-Cgr3PtaJ.js → middleware-CJlj5Olw.js} +44 -48
  56. package/dist/middleware-CjHl2NHA.js +15 -0
  57. package/dist/{middleware-TfuVoceY.cjs → middleware-D74TgW2E.cjs} +60 -66
  58. package/dist/{middleware-DvvYAIsd.js → middleware-DMk2Mdn9.js} +40 -46
  59. package/dist/mod-0noXw66R.d.cts +107 -0
  60. package/dist/{mod-BhUKmBJD.d.ts → mod-B2iOw50L.d.ts} +3 -3
  61. package/dist/mod-B9M-8jm2.d.ts +109 -0
  62. package/dist/{mod-DlU8ISoa.d.ts → mod-BlVovdcy.d.ts} +2 -2
  63. package/dist/{mod-D6hQoxC5.d.ts → mod-BoHnwOCs.d.ts} +2 -2
  64. package/dist/{mod-CxkWO3Mg.d.cts → mod-BxRCHTz-.d.cts} +2 -2
  65. package/dist/{mod-jQ4OODsl.d.cts → mod-C58MZ7Wx.d.cts} +1 -1
  66. package/dist/{mod-8DMWKtQE.d.cts → mod-DJcZDvjA.d.cts} +2 -2
  67. package/dist/{mod-Djzcw2ry.d.cts → mod-DgdBYYa0.d.cts} +3 -3
  68. package/dist/{mod-DBzN0aCM.d.ts → mod-Ds0mpFZU.d.ts} +1 -1
  69. package/dist/mod.cjs +19 -32
  70. package/dist/mod.d.cts +15 -16
  71. package/dist/mod.d.ts +16 -17
  72. package/dist/mod.js +14 -16
  73. package/dist/nodeinfo/client.test.js +8 -10
  74. package/dist/nodeinfo/handler.test.js +24 -25
  75. package/dist/nodeinfo/mod.cjs +2 -3
  76. package/dist/nodeinfo/mod.d.cts +2 -4
  77. package/dist/nodeinfo/mod.d.ts +2 -4
  78. package/dist/nodeinfo/mod.js +2 -3
  79. package/dist/nodeinfo/types.test.js +7 -9
  80. package/dist/{owner-BN_tO3cY.d.cts → owner-B4HbyP8s.d.cts} +3 -3
  81. package/dist/{owner-6Vc3UXXE.js → owner-Dvh7mBvr.js} +3 -2
  82. package/dist/{owner-hd9lvQcP.d.ts → owner-kQRGVXG1.d.ts} +3 -3
  83. package/dist/{proof-CRJWXFfT.cjs → proof-D0uThUvD.cjs} +17 -16
  84. package/dist/{proof-C1jhbeNv.js → proof-Dgy35fzc.js} +2 -2
  85. package/dist/{proof-Chi90OXv.js → proof-fqzaMJ4g.js} +5 -4
  86. package/dist/{send-DjATl6i3.js → send-Drp20VO9.js} +2 -2
  87. package/dist/sig/http.test.js +12 -13
  88. package/dist/sig/key.test.js +9 -11
  89. package/dist/sig/ld.test.js +8 -10
  90. package/dist/sig/mod.cjs +9 -11
  91. package/dist/sig/mod.d.cts +5 -7
  92. package/dist/sig/mod.d.ts +5 -7
  93. package/dist/sig/mod.js +5 -7
  94. package/dist/sig/owner.test.js +10 -12
  95. package/dist/sig/proof.test.js +13 -14
  96. package/dist/testing/docloader.test.js +6 -8
  97. package/dist/testing/mod.d.ts +114 -196
  98. package/dist/testing/mod.js +2 -3
  99. package/dist/{testing-BnfPB5T-.js → testing-g4UC4liW.js} +1 -2
  100. package/dist/{types-dLXLjVLf.js → types-BtUjyi5y.js} +1 -1
  101. package/dist/{types-CmmUQisS.cjs → types-CWgzGaqk.cjs} +3 -3
  102. package/dist/{runtime/authdocloader.test.js → utils/docloader.test.js} +14 -15
  103. package/dist/utils/kv-cache.test.js +209 -0
  104. package/dist/utils/mod.cjs +12 -0
  105. package/dist/utils/mod.d.cts +5 -0
  106. package/dist/utils/mod.d.ts +7 -0
  107. package/dist/utils/mod.js +11 -0
  108. package/dist/vocab/actor.test.js +8 -10
  109. package/dist/vocab/lookup.test.js +7 -9
  110. package/dist/vocab/mod.cjs +3 -4
  111. package/dist/vocab/mod.d.cts +3 -5
  112. package/dist/vocab/mod.d.ts +3 -5
  113. package/dist/vocab/mod.js +3 -4
  114. package/dist/vocab/type.test.js +2 -3
  115. package/dist/vocab/vocab.test.js +9 -10
  116. package/dist/{vocab-BI0Ak5lL.d.ts → vocab-BCWe1Ih5.d.ts} +2 -21
  117. package/dist/{vocab-rWbHpc2J.js → vocab-BnR3nIU9.js} +3 -3
  118. package/dist/{vocab-Dw1-yVGg.d.cts → vocab-CeDBzu-f.d.cts} +2 -21
  119. package/dist/{vocab-C5Y-0fGj.cjs → vocab-DFaWWYDn.cjs} +5 -5
  120. package/dist/webfinger/handler.test.js +24 -25
  121. package/dist/webfinger/lookup.test.js +7 -9
  122. package/dist/webfinger/mod.cjs +2 -3
  123. package/dist/webfinger/mod.d.cts +1 -3
  124. package/dist/webfinger/mod.d.ts +1 -3
  125. package/dist/webfinger/mod.js +2 -3
  126. package/dist/x/cfworkers.d.cts +2 -2
  127. package/dist/x/cfworkers.d.ts +2 -2
  128. package/dist/x/cfworkers.test.js +6 -8
  129. package/dist/x/hono.d.cts +10 -11
  130. package/dist/x/hono.d.ts +10 -11
  131. package/dist/x/sveltekit.d.cts +10 -11
  132. package/dist/x/sveltekit.d.ts +10 -11
  133. package/package.json +18 -17
  134. package/dist/assert_throws-BOO88avQ.js +0 -39
  135. package/dist/authdocloader-C5AvdCCi.js +0 -52
  136. package/dist/authdocloader-CQMPmpaO.cjs +0 -58
  137. package/dist/docloader-7Ey7wNHx.cjs +0 -4861
  138. package/dist/docloader-CkweNhUH.js +0 -4795
  139. package/dist/docloader-CxWcuWqQ.d.ts +0 -221
  140. package/dist/docloader-D-MrRyHl.d.cts +0 -219
  141. package/dist/key-CZR7QraT.cjs +0 -290
  142. package/dist/key-Cf8MffVe.cjs +0 -10
  143. package/dist/key-CkxrAIyp.js +0 -260
  144. package/dist/key-Dk0j88Jo.js +0 -10
  145. package/dist/key-Epcl5jpz.js +0 -10
  146. package/dist/lookup-DhQCVVja.js +0 -331
  147. package/dist/lookup-DiV4LFBg.cjs +0 -137
  148. package/dist/middleware-Be1JStOx.js +0 -17
  149. package/dist/middleware-CDOK7WOb.js +0 -26
  150. package/dist/middleware-EjIW2mZB.cjs +0 -17
  151. package/dist/mod-CerN_Sza.d.ts +0 -104
  152. package/dist/mod-Cj1tHXBR.d.cts +0 -102
  153. package/dist/runtime/docloader.test.js +0 -522
  154. package/dist/runtime/key.test.d.ts +0 -3
  155. package/dist/runtime/key.test.js +0 -103
  156. package/dist/runtime/langstr.test.d.ts +0 -3
  157. package/dist/runtime/langstr.test.js +0 -39
  158. package/dist/runtime/link.test.d.ts +0 -3
  159. package/dist/runtime/link.test.js +0 -61
  160. package/dist/runtime/mod.cjs +0 -25
  161. package/dist/runtime/mod.d.cts +0 -6
  162. package/dist/runtime/mod.d.ts +0 -8
  163. package/dist/runtime/mod.js +0 -13
  164. package/dist/runtime/multibase/multibase.test.d.ts +0 -3
  165. package/dist/runtime/multibase/multibase.test.js +0 -358
  166. package/dist/runtime/url.test.d.ts +0 -3
  167. package/dist/runtime/url.test.js +0 -45
  168. /package/dist/{assert_not_equals-f3m3epl3.js → assert_not_equals-C80BG-_5.js} +0 -0
  169. /package/dist/{collection-CcnIw1qY.js → collection-BzWsN9pB.js} +0 -0
  170. /package/dist/{denokv-Bv33Xxea.js → denokv-CCssOzMJ.js} +0 -0
  171. /package/dist/{federation-H2_En3j5.cjs → federation-CRpdnOMS.cjs} +0 -0
  172. /package/dist/{federation-D1U8YY9t.js → federation-jcR8-ZxP.js} +0 -0
  173. /package/dist/{kv-C7sopW2E.d.ts → kv-BKNZ-Tb-.d.ts} +0 -0
  174. /package/dist/{kv-63Cil1MD.d.cts → kv-Bxr0Q87_.d.cts} +0 -0
  175. /package/dist/{mod-FZd39qVq.d.cts → mod-B-hUPT2N.d.cts} +0 -0
  176. /package/dist/{mod-1pDWKvUL.d.ts → mod-CVgZgliM.d.ts} +0 -0
  177. /package/dist/{mod-g0xFzAP9.d.ts → mod-xIj-IT58.d.ts} +0 -0
  178. /package/dist/{mq-CRGm1e_F.d.ts → mq-CUKlBw08.d.ts} +0 -0
  179. /package/dist/{mq-B7R1Q-M5.d.cts → mq-DcJPkXD5.d.cts} +0 -0
  180. /package/dist/{negotiation-5NPJL6zp.js → negotiation-C4nFufNk.js} +0 -0
  181. /package/dist/{nodeinfo-DfycQ8Wf.js → nodeinfo-BnthBobC.js} +0 -0
  182. /package/dist/{nodeinfo-Co9lJrWl.cjs → nodeinfo-CdN0rEnZ.cjs} +0 -0
  183. /package/dist/{retry-D4GJ670a.js → retry-CfF8Gn4d.js} +0 -0
  184. /package/dist/{runtime-DPYEDf-o.js → sig-C34-oHBl.js} +0 -0
  185. /package/dist/{runtime-C58AJWSv.cjs → sig-YYj5tCnr.cjs} +0 -0
  186. /package/dist/{std__assert-X-_kMxKM.js → std__assert-DWivtrGR.js} +0 -0
  187. /package/dist/{types-BSuWJsOm.js → types-C2XVl6gj.js} +0 -0
  188. /package/dist/{runtime → utils}/docloader.test.d.ts +0 -0
  189. /package/dist/{runtime/authdocloader.test.d.ts → utils/kv-cache.test.d.ts} +0 -0
  190. /package/dist/{sig-Cj3tk-ig.js → utils-D-Va7aXC.js} +0 -0
  191. /package/dist/{sig-ByHXzqUi.cjs → utils-DyRU1gdZ.cjs} +0 -0
  192. /package/dist/{webfinger-De_bU0iE.js → webfinger-C72Y8lrh.js} +0 -0
  193. /package/dist/{webfinger-BjOEdFPs.cjs → webfinger-vAtLmxOF.cjs} +0 -0
@@ -1,102 +0,0 @@
1
- import { DocumentLoader, DocumentLoaderFactoryOptions } from "./docloader-D-MrRyHl.cjs";
2
- import { HttpMessageSignaturesSpecDeterminer } from "./http-D-e6AFwR.cjs";
3
- import { TracerProvider } from "@opentelemetry/api";
4
-
5
- //#region src/runtime/authdocloader.d.ts
6
- /**
7
- * Options for {@link getAuthenticatedDocumentLoader}.
8
- * @see {@link getAuthenticatedDocumentLoader}
9
- * @since 1.3.0
10
- */
11
- interface GetAuthenticatedDocumentLoaderOptions extends DocumentLoaderFactoryOptions {
12
- /**
13
- * An optional spec determiner for HTTP Message Signatures.
14
- * It determines the spec to use for signing requests.
15
- * It is used for double-knocking
16
- * (see <https://swicg.github.io/activitypub-http-signature/#how-to-upgrade-supported-versions>).
17
- * @since 1.6.0
18
- */
19
- specDeterminer?: HttpMessageSignaturesSpecDeterminer;
20
- /**
21
- * The OpenTelemetry tracer provider. If omitted, the global tracer provider
22
- * is used.
23
- * @since 1.6.0
24
- */
25
- tracerProvider?: TracerProvider;
26
- }
27
- /**
28
- * Gets an authenticated {@link DocumentLoader} for the given identity.
29
- * Note that an authenticated document loader intentionally does not cache
30
- * the fetched documents.
31
- * @param identity The identity to get the document loader for.
32
- * The actor's key pair.
33
- * @param options The options for the document loader.
34
- * @returns The authenticated document loader.
35
- * @throws {TypeError} If the key is invalid or unsupported.
36
- * @since 0.4.0
37
- */
38
- declare function getAuthenticatedDocumentLoader(identity: {
39
- keyId: URL;
40
- privateKey: CryptoKey;
41
- }, {
42
- allowPrivateAddress,
43
- userAgent,
44
- specDeterminer,
45
- tracerProvider
46
- }?: GetAuthenticatedDocumentLoaderOptions): DocumentLoader;
47
- //#endregion
48
- //#region src/runtime/key.d.ts
49
- /**
50
- * Imports a PEM-SPKI formatted public key.
51
- * @param pem The PEM-SPKI formatted public key.
52
- * @returns The imported public key.
53
- * @throws {TypeError} If the key is invalid or unsupported.
54
- * @since 0.5.0
55
- */
56
- declare function importSpki(pem: string): Promise<CryptoKey>;
57
- /**
58
- * Exports a public key in PEM-SPKI format.
59
- * @param key The public key to export.
60
- * @returns The exported public key in PEM-SPKI format.
61
- * @throws {TypeError} If the key is invalid or unsupported.
62
- * @since 0.5.0
63
- */
64
- declare function exportSpki(key: CryptoKey): Promise<string>;
65
- /**
66
- * Imports a PEM-PKCS#1 formatted public key.
67
- * @param pem The PEM-PKCS#1 formatted public key.
68
- * @returns The imported public key.
69
- * @throws {TypeError} If the key is invalid or unsupported.
70
- * @since 1.5.0
71
- */
72
- declare function importPkcs1(pem: string): Promise<CryptoKey>;
73
- /**
74
- * Imports a PEM formatted public key (SPKI or PKCS#1).
75
- * @param pem The PEM formatted public key to import (SPKI or PKCS#1).
76
- * @returns The imported public key.
77
- * @throws {TypeError} If the key is invalid or unsupported.
78
- * @since 1.5.0
79
- */
80
- declare function importPem(pem: string): Promise<CryptoKey>;
81
- /**
82
- * Imports a [Multibase]-encoded public key.
83
- *
84
- * [Multibase]: https://www.w3.org/TR/vc-data-integrity/#multibase-0
85
- * @param key The Multibase-encoded public key.
86
- * @returns The imported public key.
87
- * @throws {TypeError} If the key is invalid or unsupported.
88
- * @since 0.10.0
89
- */
90
- declare function importMultibaseKey(key: string): Promise<CryptoKey>;
91
- /**
92
- * Exports a public key in [Multibase] format.
93
- *
94
- * [Multibase]: https://www.w3.org/TR/vc-data-integrity/#multibase-0
95
- * @param key The public key to export.
96
- * @returns The exported public key in Multibase format.
97
- * @throws {TypeError} If the key is invalid or unsupported.
98
- * @since 0.10.0
99
- */
100
- declare function exportMultibaseKey(key: CryptoKey): Promise<string>;
101
- //#endregion
102
- export { GetAuthenticatedDocumentLoaderOptions, exportMultibaseKey, exportSpki, getAuthenticatedDocumentLoader, importMultibaseKey, importPem, importPkcs1, importSpki };
@@ -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-NEA09tSC.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-DhQCVVja.js";
12
- import { mockDocumentLoader, test } from "../testing-BnfPB5T-.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-CwHz8Y8t.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
@@ -1,3 +0,0 @@
1
- import { Temporal } from "@js-temporal/polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};