@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,5 +1,5 @@
1
- import { DocumentLoader } from "./docloader-D-MrRyHl.cjs";
2
- import { CryptographicKey, Multikey } from "./vocab-Dw1-yVGg.cjs";
1
+ import { CryptographicKey, Multikey } from "./vocab-CeDBzu-f.cjs";
2
+ import { DocumentLoader } from "@fedify/vocab-runtime";
3
3
  import { TracerProvider } from "@opentelemetry/api";
4
4
 
5
5
  //#region src/sig/key.d.ts
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Activity, deno_default, getTypeId } from "./type-NEA09tSC.js";
6
+ import { Activity, deno_default, getTypeId } from "./lookup-DQRtjvb1.js";
7
7
  import { getLogger } from "@logtape/logtape";
8
8
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
9
9
 
@@ -3,8 +3,9 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Object as Object$1, deno_default, getDocumentLoader } from "./type-NEA09tSC.js";
7
- import { isActor } from "./actor-D5S46edz.js";
6
+ import { CryptographicKey, Object as Object$1, deno_default } from "./lookup-DQRtjvb1.js";
7
+ import { isActor } from "./actor-BXHc5r-q.js";
8
+ import { getDocumentLoader } from "@fedify/vocab-runtime";
8
9
  import { getLogger } from "@logtape/logtape";
9
10
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
10
11
 
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Multikey } from "./type-NEA09tSC.js";
6
+ import { CryptographicKey, Multikey } from "./lookup-DQRtjvb1.js";
7
7
 
8
8
  //#region src/federation/keycache.ts
9
9
  var KvKeyCache = class {
@@ -3,7 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Multikey, importSpki } from "./type-NEA09tSC.js";
6
+ import { CryptographicKey, Multikey } from "./lookup-DQRtjvb1.js";
7
+ import { importSpki } from "@fedify/vocab-runtime";
7
8
 
8
9
  //#region src/testing/keys.ts
9
10
  const rsaPublicKey1 = new CryptographicKey({
@@ -0,0 +1,122 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import { doubleKnock, validateCryptoKey } from "./http-CUVx-vzb.js";
6
+ import { getLogger } from "@logtape/logtape";
7
+ import { UrlError, createActivityPubRequest, getDocumentLoader, getRemoteDocument, logRequest, preloadedContexts, validatePublicUrl } from "@fedify/vocab-runtime";
8
+ import { curry } from "es-toolkit";
9
+
10
+ //#region src/utils/docloader.ts
11
+ const logger$1 = getLogger([
12
+ "fedify",
13
+ "utils",
14
+ "docloader"
15
+ ]);
16
+ /**
17
+ * Gets an authenticated {@link DocumentLoader} for the given identity.
18
+ * Note that an authenticated document loader intentionally does not cache
19
+ * the fetched documents.
20
+ * @param identity The identity to get the document loader for.
21
+ * The actor's key pair.
22
+ * @param options The options for the document loader.
23
+ * @returns The authenticated document loader.
24
+ * @throws {TypeError} If the key is invalid or unsupported.
25
+ * @since 0.4.0
26
+ */
27
+ function getAuthenticatedDocumentLoader(identity, { allowPrivateAddress, userAgent, specDeterminer, tracerProvider } = {}) {
28
+ validateCryptoKey(identity.privateKey);
29
+ async function load(url, options) {
30
+ if (!allowPrivateAddress) try {
31
+ await validatePublicUrl(url);
32
+ } catch (error) {
33
+ if (error instanceof UrlError) logger$1.error("Disallowed private URL: {url}", {
34
+ url,
35
+ error
36
+ });
37
+ throw error;
38
+ }
39
+ const originalRequest = createActivityPubRequest(url, { userAgent });
40
+ const response = await doubleKnock(originalRequest, identity, {
41
+ specDeterminer,
42
+ log: curry(logRequest)(logger$1),
43
+ tracerProvider,
44
+ signal: options?.signal
45
+ });
46
+ return getRemoteDocument(url, response, load);
47
+ }
48
+ return load;
49
+ }
50
+ const _fetchDocumentLoader = getDocumentLoader();
51
+ const _fetchDocumentLoader_allowPrivateAddress = getDocumentLoader({ allowPrivateAddress: true });
52
+
53
+ //#endregion
54
+ //#region src/utils/kv-cache.ts
55
+ const logger = getLogger([
56
+ "fedify",
57
+ "utils",
58
+ "kv-cache"
59
+ ]);
60
+ /**
61
+ * Decorates a {@link DocumentLoader} with a cache backed by a {@link Deno.Kv}.
62
+ * @param parameters The parameters for the cache.
63
+ * @returns The decorated document loader which is cache-enabled.
64
+ */
65
+ function kvCache({ loader, kv, prefix, rules }) {
66
+ const keyPrefix = prefix ?? ["_fedify", "remoteDocument"];
67
+ rules ??= [[new URLPattern({}), Temporal.Duration.from({ minutes: 5 })]];
68
+ for (const [p, duration] of rules) if (Temporal.Duration.compare(duration, { days: 30 }) > 0) throw new TypeError("The maximum cache duration is 30 days: " + (p instanceof URLPattern ? `${p.protocol}://${p.username}:${p.password}@${p.hostname}:${p.port}/${p.pathname}?${p.search}#${p.hash}` : p.toString()));
69
+ return async (url, options) => {
70
+ if (url in preloadedContexts) {
71
+ logger.debug("Using preloaded context: {url}.", { url });
72
+ return {
73
+ contextUrl: null,
74
+ document: preloadedContexts[url],
75
+ documentUrl: url
76
+ };
77
+ }
78
+ const match = matchRule(url, rules);
79
+ if (match == null) return await loader(url, options);
80
+ const key = [...keyPrefix, url];
81
+ let cache = void 0;
82
+ try {
83
+ cache = await kv.get(key);
84
+ } catch (error) {
85
+ if (error instanceof Error) logger.warn("Failed to get the document of {url} from the KV cache: {error}", {
86
+ url,
87
+ error
88
+ });
89
+ }
90
+ if (cache == null) {
91
+ const remoteDoc = await loader(url, options);
92
+ try {
93
+ await kv.set(key, remoteDoc, { ttl: match });
94
+ } catch (error) {
95
+ logger.warn("Failed to save the document of {url} to the KV cache: {error}", {
96
+ url,
97
+ error
98
+ });
99
+ }
100
+ return remoteDoc;
101
+ }
102
+ return cache;
103
+ };
104
+ }
105
+ function matchRule(url, rules) {
106
+ for (const [pattern, d] of rules) {
107
+ const duration = d instanceof Temporal.Duration ? d : Temporal.Duration.from(d);
108
+ if (typeof pattern === "string") {
109
+ if (url === pattern) return duration;
110
+ continue;
111
+ }
112
+ if (pattern instanceof URL) {
113
+ if (pattern.href == url) return duration;
114
+ continue;
115
+ }
116
+ if (pattern.test(url)) return duration;
117
+ }
118
+ return null;
119
+ }
120
+
121
+ //#endregion
122
+ export { getAuthenticatedDocumentLoader, kvCache };
@@ -0,0 +1,94 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import { preloadedContexts } from "@fedify/vocab-runtime";
7
+ import { getLogger } from "@logtape/logtape";
8
+
9
+ //#region src/utils/kv-cache.ts
10
+ const logger = getLogger([
11
+ "fedify",
12
+ "utils",
13
+ "kv-cache"
14
+ ]);
15
+ /**
16
+ * A mock implementation of a key–value store for testing purposes.
17
+ */
18
+ var MockKvStore = class {
19
+ #values = {};
20
+ get(key) {
21
+ return Promise.resolve(this.#values[JSON.stringify(key)]);
22
+ }
23
+ set(key, value, _options) {
24
+ this.#values[JSON.stringify(key)] = value;
25
+ return Promise.resolve();
26
+ }
27
+ async delete(_) {}
28
+ cas(..._) {
29
+ return Promise.resolve(false);
30
+ }
31
+ };
32
+ /**
33
+ * Decorates a {@link DocumentLoader} with a cache backed by a {@link Deno.Kv}.
34
+ * @param parameters The parameters for the cache.
35
+ * @returns The decorated document loader which is cache-enabled.
36
+ */
37
+ function kvCache({ loader, kv, prefix, rules }) {
38
+ const keyPrefix = prefix ?? ["_fedify", "remoteDocument"];
39
+ rules ??= [[new URLPattern({}), Temporal.Duration.from({ minutes: 5 })]];
40
+ for (const [p, duration] of rules) if (Temporal.Duration.compare(duration, { days: 30 }) > 0) throw new TypeError("The maximum cache duration is 30 days: " + (p instanceof URLPattern ? `${p.protocol}://${p.username}:${p.password}@${p.hostname}:${p.port}/${p.pathname}?${p.search}#${p.hash}` : p.toString()));
41
+ return async (url, options) => {
42
+ if (url in preloadedContexts) {
43
+ logger.debug("Using preloaded context: {url}.", { url });
44
+ return {
45
+ contextUrl: null,
46
+ document: preloadedContexts[url],
47
+ documentUrl: url
48
+ };
49
+ }
50
+ const match = matchRule(url, rules);
51
+ if (match == null) return await loader(url, options);
52
+ const key = [...keyPrefix, url];
53
+ let cache = void 0;
54
+ try {
55
+ cache = await kv.get(key);
56
+ } catch (error) {
57
+ if (error instanceof Error) logger.warn("Failed to get the document of {url} from the KV cache: {error}", {
58
+ url,
59
+ error
60
+ });
61
+ }
62
+ if (cache == null) {
63
+ const remoteDoc = await loader(url, options);
64
+ try {
65
+ await kv.set(key, remoteDoc, { ttl: match });
66
+ } catch (error) {
67
+ logger.warn("Failed to save the document of {url} to the KV cache: {error}", {
68
+ url,
69
+ error
70
+ });
71
+ }
72
+ return remoteDoc;
73
+ }
74
+ return cache;
75
+ };
76
+ }
77
+ function matchRule(url, rules) {
78
+ for (const [pattern, d] of rules) {
79
+ const duration = d instanceof Temporal.Duration ? d : Temporal.Duration.from(d);
80
+ if (typeof pattern === "string") {
81
+ if (url === pattern) return duration;
82
+ continue;
83
+ }
84
+ if (pattern instanceof URL) {
85
+ if (pattern.href == url) return duration;
86
+ continue;
87
+ }
88
+ if (pattern.test(url)) return duration;
89
+ }
90
+ return null;
91
+ }
92
+
93
+ //#endregion
94
+ export { MockKvStore, kvCache };
@@ -0,0 +1,134 @@
1
+
2
+ const { Temporal } = require("@js-temporal/polyfill");
3
+ const { URLPattern } = require("urlpattern-polyfill");
4
+
5
+ const require_chunk = require('./chunk-DqRYRqnO.cjs');
6
+ const require_http = require('./http-Dofes42e.cjs');
7
+ const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
8
+ const __fedify_vocab_runtime = require_chunk.__toESM(require("@fedify/vocab-runtime"));
9
+ const es_toolkit = require_chunk.__toESM(require("es-toolkit"));
10
+
11
+ //#region src/utils/docloader.ts
12
+ const logger$1 = (0, __logtape_logtape.getLogger)([
13
+ "fedify",
14
+ "utils",
15
+ "docloader"
16
+ ]);
17
+ /**
18
+ * Gets an authenticated {@link DocumentLoader} for the given identity.
19
+ * Note that an authenticated document loader intentionally does not cache
20
+ * the fetched documents.
21
+ * @param identity The identity to get the document loader for.
22
+ * The actor's key pair.
23
+ * @param options The options for the document loader.
24
+ * @returns The authenticated document loader.
25
+ * @throws {TypeError} If the key is invalid or unsupported.
26
+ * @since 0.4.0
27
+ */
28
+ function getAuthenticatedDocumentLoader(identity, { allowPrivateAddress, userAgent, specDeterminer, tracerProvider } = {}) {
29
+ require_http.validateCryptoKey(identity.privateKey);
30
+ async function load(url, options) {
31
+ if (!allowPrivateAddress) try {
32
+ await (0, __fedify_vocab_runtime.validatePublicUrl)(url);
33
+ } catch (error) {
34
+ if (error instanceof __fedify_vocab_runtime.UrlError) logger$1.error("Disallowed private URL: {url}", {
35
+ url,
36
+ error
37
+ });
38
+ throw error;
39
+ }
40
+ const originalRequest = (0, __fedify_vocab_runtime.createActivityPubRequest)(url, { userAgent });
41
+ const response = await require_http.doubleKnock(originalRequest, identity, {
42
+ specDeterminer,
43
+ log: (0, es_toolkit.curry)(__fedify_vocab_runtime.logRequest)(logger$1),
44
+ tracerProvider,
45
+ signal: options?.signal
46
+ });
47
+ return (0, __fedify_vocab_runtime.getRemoteDocument)(url, response, load);
48
+ }
49
+ return load;
50
+ }
51
+ const _fetchDocumentLoader = (0, __fedify_vocab_runtime.getDocumentLoader)();
52
+ const _fetchDocumentLoader_allowPrivateAddress = (0, __fedify_vocab_runtime.getDocumentLoader)({ allowPrivateAddress: true });
53
+
54
+ //#endregion
55
+ //#region src/utils/kv-cache.ts
56
+ const logger = (0, __logtape_logtape.getLogger)([
57
+ "fedify",
58
+ "utils",
59
+ "kv-cache"
60
+ ]);
61
+ /**
62
+ * Decorates a {@link DocumentLoader} with a cache backed by a {@link Deno.Kv}.
63
+ * @param parameters The parameters for the cache.
64
+ * @returns The decorated document loader which is cache-enabled.
65
+ */
66
+ function kvCache({ loader, kv, prefix, rules }) {
67
+ const keyPrefix = prefix ?? ["_fedify", "remoteDocument"];
68
+ rules ??= [[new URLPattern({}), Temporal.Duration.from({ minutes: 5 })]];
69
+ for (const [p, duration] of rules) if (Temporal.Duration.compare(duration, { days: 30 }) > 0) throw new TypeError("The maximum cache duration is 30 days: " + (p instanceof URLPattern ? `${p.protocol}://${p.username}:${p.password}@${p.hostname}:${p.port}/${p.pathname}?${p.search}#${p.hash}` : p.toString()));
70
+ return async (url, options) => {
71
+ if (url in __fedify_vocab_runtime.preloadedContexts) {
72
+ logger.debug("Using preloaded context: {url}.", { url });
73
+ return {
74
+ contextUrl: null,
75
+ document: __fedify_vocab_runtime.preloadedContexts[url],
76
+ documentUrl: url
77
+ };
78
+ }
79
+ const match = matchRule(url, rules);
80
+ if (match == null) return await loader(url, options);
81
+ const key = [...keyPrefix, url];
82
+ let cache = void 0;
83
+ try {
84
+ cache = await kv.get(key);
85
+ } catch (error) {
86
+ if (error instanceof Error) logger.warn("Failed to get the document of {url} from the KV cache: {error}", {
87
+ url,
88
+ error
89
+ });
90
+ }
91
+ if (cache == null) {
92
+ const remoteDoc = await loader(url, options);
93
+ try {
94
+ await kv.set(key, remoteDoc, { ttl: match });
95
+ } catch (error) {
96
+ logger.warn("Failed to save the document of {url} to the KV cache: {error}", {
97
+ url,
98
+ error
99
+ });
100
+ }
101
+ return remoteDoc;
102
+ }
103
+ return cache;
104
+ };
105
+ }
106
+ function matchRule(url, rules) {
107
+ for (const [pattern, d] of rules) {
108
+ const duration = d instanceof Temporal.Duration ? d : Temporal.Duration.from(d);
109
+ if (typeof pattern === "string") {
110
+ if (url === pattern) return duration;
111
+ continue;
112
+ }
113
+ if (pattern instanceof URL) {
114
+ if (pattern.href == url) return duration;
115
+ continue;
116
+ }
117
+ if (pattern.test(url)) return duration;
118
+ }
119
+ return null;
120
+ }
121
+
122
+ //#endregion
123
+ Object.defineProperty(exports, 'getAuthenticatedDocumentLoader', {
124
+ enumerable: true,
125
+ get: function () {
126
+ return getAuthenticatedDocumentLoader;
127
+ }
128
+ });
129
+ Object.defineProperty(exports, 'kvCache', {
130
+ enumerable: true,
131
+ get: function () {
132
+ return kvCache;
133
+ }
134
+ });
@@ -3,8 +3,9 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Activity, CryptographicKey, Object as Object$1, deno_default, getDocumentLoader, getTypeId } from "./type-NEA09tSC.js";
7
- import { fetchKey, validateCryptoKey } from "./key-IxRhZpOF.js";
6
+ import { Activity, CryptographicKey, Object as Object$1, deno_default, getTypeId } from "./lookup-DQRtjvb1.js";
7
+ import { fetchKey, validateCryptoKey } from "./key-CxdLUFS6.js";
8
+ import { getDocumentLoader } from "@fedify/vocab-runtime";
8
9
  import { getLogger } from "@logtape/logtape";
9
10
  import { SpanStatusCode, trace } from "@opentelemetry/api";
10
11
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
@@ -2,10 +2,139 @@
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
 
5
- import { UrlError, deno_default, getUserAgent, validatePublicUrl } from "./docloader-CkweNhUH.js";
6
5
  import { getLogger } from "@logtape/logtape";
7
6
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
7
+ import { UrlError, getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
8
8
 
9
+ //#region deno.json
10
+ var name = "@fedify/fedify";
11
+ var version = "2.0.0-pr.412.1794+5c393341";
12
+ var license = "MIT";
13
+ var exports = {
14
+ ".": "./src/mod.ts",
15
+ "./compat": "./src/compat/mod.ts",
16
+ "./federation": "./src/federation/mod.ts",
17
+ "./nodeinfo": "./src/nodeinfo/mod.ts",
18
+ "./sig": "./src/sig/mod.ts",
19
+ "./testing": "./src/testing/mod.ts",
20
+ "./vocab": "./src/vocab/mod.ts",
21
+ "./utils": "./src/utils/mod.ts",
22
+ "./webfinger": "./src/webfinger/mod.ts",
23
+ "./x/cfworkers": "./src/x/cfworkers.ts",
24
+ "./x/denokv": "./src/x/denokv.ts",
25
+ "./x/fresh": "./src/x/fresh.ts",
26
+ "./x/hono": "./src/x/hono.ts",
27
+ "./x/sveltekit": "./src/x/sveltekit.ts"
28
+ };
29
+ var imports = {
30
+ "@cfworker/json-schema": "npm:@cfworker/json-schema@^4.1.1",
31
+ "@multiformats/base-x": "npm:@multiformats/base-x@^4.0.1",
32
+ "@opentelemetry/api": "npm:@opentelemetry/api@^1.9.0",
33
+ "@opentelemetry/semantic-conventions": "npm:@opentelemetry/semantic-conventions@^1.27.0",
34
+ "@std/assert": "jsr:@std/assert@^0.226.0",
35
+ "@std/testing": "jsr:@std/testing@^0.224.0",
36
+ "@std/url": "jsr:@std/url@^0.225.1",
37
+ "asn1js": "npm:asn1js@^3.0.5",
38
+ "es-toolkit": "jsr:@es-toolkit/es-toolkit@^1.39.5",
39
+ "fast-check": "npm:fast-check@^3.22.0",
40
+ "fetch-mock": "npm:fetch-mock@^12.5.2",
41
+ "json-canon": "npm:json-canon@^1.0.1",
42
+ "jsonld": "npm:jsonld@^8.3.2",
43
+ "multicodec": "npm:multicodec@^3.2.1",
44
+ "pkijs": "npm:pkijs@^3.2.4",
45
+ "structured-field-values": "npm:structured-field-values@^2.0.4",
46
+ "uri-template-router": "npm:uri-template-router@^0.0.17",
47
+ "url-template": "npm:url-template@^3.1.1"
48
+ };
49
+ var include = ["src/vocab/vocab.ts"];
50
+ var exclude = [
51
+ ".test-report.xml",
52
+ "apidoc/",
53
+ "dist/",
54
+ "node_modules/",
55
+ "npm/",
56
+ "pnpm-lock.yaml",
57
+ "src/cfworkers/dist/",
58
+ "src/cfworkers/fixtures/",
59
+ "src/cfworkers/imports.ts",
60
+ "src/cfworkers/README.md",
61
+ "src/cfworkers/server.ts",
62
+ "src/cfworkers/server.js",
63
+ "src/cfworkers/server.js.map",
64
+ "src/codegen/schema.yaml",
65
+ "src/vocab/*.yaml",
66
+ "!src/vocab/vocab.ts"
67
+ ];
68
+ var tasks = {
69
+ "codegen": "GENPATH=vocab-$(deno eval \"console.log(crypto.randomUUID());\").ts && deno run --allow-read --allow-write --check src/codegen/main.ts src/vocab/ src/vocab/$GENPATH && deno fmt src/vocab/$GENPATH && mv src/vocab/$GENPATH src/vocab/vocab.ts && deno cache src/vocab/vocab.ts && deno check src/vocab/vocab.ts",
70
+ "cache": {
71
+ "command": "deno cache src/mod.ts",
72
+ "dependencies": ["codegen"]
73
+ },
74
+ "check": {
75
+ "command": "deno fmt --check && deno lint && deno check src/**/*.ts",
76
+ "dependencies": ["codegen"]
77
+ },
78
+ "test": {
79
+ "command": "deno test --check --doc --allow-read --allow-write --allow-env --unstable-kv --trace-leaks --parallel",
80
+ "dependencies": ["codegen"]
81
+ },
82
+ "coverage": "deno task test --clean --coverage && deno coverage --html coverage",
83
+ "bench": {
84
+ "command": "deno bench --allow-read --allow-write --allow-net --allow-env --allow-run --unstable-kv",
85
+ "dependencies": ["codegen"]
86
+ },
87
+ "apidoc": {
88
+ "command": "deno doc --html --name=Fedify --output=apidoc/ src/mod.ts",
89
+ "dependencies": ["codegen"]
90
+ },
91
+ "publish": {
92
+ "command": "deno publish",
93
+ "dependencies": ["codegen"]
94
+ },
95
+ "pnpm:install": "pnpm install --silent",
96
+ "pnpm:build": {
97
+ "command": "pnpm exec tsdown",
98
+ "dependencies": [
99
+ "codegen",
100
+ "pnpm:install",
101
+ "pnpm:build-vocab"
102
+ ]
103
+ },
104
+ "pnpm:build-vocab-runtime": { "command": "cd ../vocab-runtime && pnpm build" },
105
+ "pnpm:build-vocab": { "dependencies": ["pnpm:build-vocab-runtime"] },
106
+ "test:node": {
107
+ "command": "cd dist/ && node --test",
108
+ "dependencies": ["pnpm:build"]
109
+ },
110
+ "test:bun": {
111
+ "command": "cd dist/ && bun test --timeout 60000",
112
+ "dependencies": ["pnpm:build-vocab", "pnpm:build"]
113
+ },
114
+ "test:cfworkers": {
115
+ "command": "pnpm exec wrangler deploy --dry-run --outdir src/cfworkers && node --import=tsx src/cfworkers/client.ts",
116
+ "dependencies": ["pnpm:build-vocab", "pnpm:build"]
117
+ },
118
+ "test-all": { "dependencies": [
119
+ "check",
120
+ "test",
121
+ "test:node",
122
+ "test:bun",
123
+ "test:cfworkers"
124
+ ] }
125
+ };
126
+ var deno_default = {
127
+ name,
128
+ version,
129
+ license,
130
+ exports,
131
+ imports,
132
+ include,
133
+ exclude,
134
+ tasks
135
+ };
136
+
137
+ //#endregion
9
138
  //#region src/webfinger/lookup.ts
10
139
  const logger = getLogger([
11
140
  "fedify",
@@ -128,4 +257,4 @@ async function lookupWebFingerInternal(resource, options = {}) {
128
257
  }
129
258
 
130
259
  //#endregion
131
- export { lookupWebFinger };
260
+ export { deno_default, lookupWebFinger };