@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
@@ -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-SK-d7Tbw.js";
7
- import { fetchKey, validateCryptoKey } from "./key-CzLv1phF.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";
@@ -182,7 +183,7 @@ async function verifySignature(jsonLd, options = {}) {
182
183
  const encoder = new TextEncoder();
183
184
  const message = sigOptsHash + docHash;
184
185
  const messageBytes = encoder.encode(message);
185
- const verified = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature, messageBytes);
186
+ const verified = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes);
186
187
  if (verified) return key;
187
188
  if (cached) {
188
189
  logger.debug("Failed to verify with the cached key {keyId}; signature {signatureValue} is invalid. Retrying with the freshly fetched key...", {
@@ -197,7 +198,7 @@ async function verifySignature(jsonLd, options = {}) {
197
198
  }
198
199
  });
199
200
  if (key$1 == null) return null;
200
- const verified$1 = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key$1.publicKey, signature, messageBytes);
201
+ const verified$1 = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key$1.publicKey, signature.slice(), messageBytes);
201
202
  return verified$1 ? key$1 : null;
202
203
  }
203
204
  logger.debug("Failed to verify with the fetched key {keyId}; signature {signatureValue} is invalid. Check if the key is correct or if the signed message is correct. The message to sign is:\n{message}", {
@@ -0,0 +1,260 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import { getLogger } from "@logtape/logtape";
6
+ import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
7
+ import { UrlError, getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
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
138
+ //#region src/webfinger/lookup.ts
139
+ const logger = getLogger([
140
+ "fedify",
141
+ "webfinger",
142
+ "lookup"
143
+ ]);
144
+ const DEFAULT_MAX_REDIRECTION = 5;
145
+ /**
146
+ * Looks up a WebFinger resource.
147
+ * @param resource The resource URL to look up.
148
+ * @param options Extra options for looking up the resource.
149
+ * @returns The resource descriptor, or `null` if not found.
150
+ * @since 0.2.0
151
+ */
152
+ async function lookupWebFinger(resource, options = {}) {
153
+ const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
154
+ const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
155
+ return await tracer.startActiveSpan("webfinger.lookup", {
156
+ kind: SpanKind.CLIENT,
157
+ attributes: {
158
+ "webfinger.resource": resource.toString(),
159
+ "webfinger.resource.scheme": typeof resource === "string" ? resource.replace(/:.*$/, "") : resource.protocol.replace(/:$/, "")
160
+ }
161
+ }, async (span) => {
162
+ try {
163
+ const result = await lookupWebFingerInternal(resource, options);
164
+ span.setStatus({ code: result === null ? SpanStatusCode.ERROR : SpanStatusCode.OK });
165
+ return result;
166
+ } catch (error) {
167
+ span.setStatus({
168
+ code: SpanStatusCode.ERROR,
169
+ message: String(error)
170
+ });
171
+ throw error;
172
+ } finally {
173
+ span.end();
174
+ }
175
+ });
176
+ }
177
+ async function lookupWebFingerInternal(resource, options = {}) {
178
+ if (typeof resource === "string") resource = new URL(resource);
179
+ let protocol = "https:";
180
+ let server;
181
+ if (resource.protocol === "acct:") {
182
+ const atPos = resource.pathname.lastIndexOf("@");
183
+ if (atPos < 0) return null;
184
+ server = resource.pathname.substring(atPos + 1);
185
+ if (server === "") return null;
186
+ } else {
187
+ protocol = resource.protocol;
188
+ server = resource.host;
189
+ }
190
+ let url = new URL(`${protocol}//${server}/.well-known/webfinger`);
191
+ url.searchParams.set("resource", resource.href);
192
+ let redirected = 0;
193
+ while (true) {
194
+ logger.debug("Fetching WebFinger resource descriptor from {url}...", { url: url.href });
195
+ let response;
196
+ if (options.allowPrivateAddress !== true) try {
197
+ await validatePublicUrl(url.href);
198
+ } catch (e) {
199
+ if (e instanceof UrlError) {
200
+ logger.error("Invalid URL for WebFinger resource descriptor: {error}", { error: e });
201
+ return null;
202
+ }
203
+ throw e;
204
+ }
205
+ try {
206
+ response = await fetch(url, {
207
+ headers: {
208
+ Accept: "application/jrd+json",
209
+ "User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
210
+ },
211
+ redirect: "manual",
212
+ signal: options.signal
213
+ });
214
+ } catch (error) {
215
+ logger.debug("Failed to fetch WebFinger resource descriptor: {error}", {
216
+ url: url.href,
217
+ error
218
+ });
219
+ return null;
220
+ }
221
+ if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
222
+ redirected++;
223
+ const maxRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION;
224
+ if (redirected >= maxRedirection) {
225
+ logger.error("Too many redirections ({redirections}) while fetching WebFinger resource descriptor.", { redirections: redirected });
226
+ return null;
227
+ }
228
+ const redirectedUrl = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? url : response.url);
229
+ if (redirectedUrl.protocol !== url.protocol) {
230
+ logger.error("Redirected to a different protocol ({protocol} to {redirectedProtocol}) while fetching WebFinger resource descriptor.", {
231
+ protocol: url.protocol,
232
+ redirectedProtocol: redirectedUrl.protocol
233
+ });
234
+ return null;
235
+ }
236
+ url = redirectedUrl;
237
+ continue;
238
+ }
239
+ if (!response.ok) {
240
+ logger.debug("Failed to fetch WebFinger resource descriptor: {status} {statusText}.", {
241
+ url: url.href,
242
+ status: response.status,
243
+ statusText: response.statusText
244
+ });
245
+ return null;
246
+ }
247
+ try {
248
+ return await response.json();
249
+ } catch (e) {
250
+ if (e instanceof SyntaxError) {
251
+ logger.debug("Failed to parse WebFinger resource descriptor as JSON: {error}", { error: e });
252
+ return null;
253
+ }
254
+ throw e;
255
+ }
256
+ }
257
+ }
258
+
259
+ //#endregion
260
+ export { deno_default, lookupWebFinger };
@@ -0,0 +1,272 @@
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 __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
7
+ const __opentelemetry_api = require_chunk.__toESM(require("@opentelemetry/api"));
8
+ const __fedify_vocab_runtime = require_chunk.__toESM(require("@fedify/vocab-runtime"));
9
+
10
+ //#region deno.json
11
+ var name = "@fedify/fedify";
12
+ var version = "2.0.0-pr.412.1794+5c393341";
13
+ var license = "MIT";
14
+ var exports$1 = {
15
+ ".": "./src/mod.ts",
16
+ "./compat": "./src/compat/mod.ts",
17
+ "./federation": "./src/federation/mod.ts",
18
+ "./nodeinfo": "./src/nodeinfo/mod.ts",
19
+ "./sig": "./src/sig/mod.ts",
20
+ "./testing": "./src/testing/mod.ts",
21
+ "./vocab": "./src/vocab/mod.ts",
22
+ "./utils": "./src/utils/mod.ts",
23
+ "./webfinger": "./src/webfinger/mod.ts",
24
+ "./x/cfworkers": "./src/x/cfworkers.ts",
25
+ "./x/denokv": "./src/x/denokv.ts",
26
+ "./x/fresh": "./src/x/fresh.ts",
27
+ "./x/hono": "./src/x/hono.ts",
28
+ "./x/sveltekit": "./src/x/sveltekit.ts"
29
+ };
30
+ var imports = {
31
+ "@cfworker/json-schema": "npm:@cfworker/json-schema@^4.1.1",
32
+ "@multiformats/base-x": "npm:@multiformats/base-x@^4.0.1",
33
+ "@opentelemetry/api": "npm:@opentelemetry/api@^1.9.0",
34
+ "@opentelemetry/semantic-conventions": "npm:@opentelemetry/semantic-conventions@^1.27.0",
35
+ "@std/assert": "jsr:@std/assert@^0.226.0",
36
+ "@std/testing": "jsr:@std/testing@^0.224.0",
37
+ "@std/url": "jsr:@std/url@^0.225.1",
38
+ "asn1js": "npm:asn1js@^3.0.5",
39
+ "es-toolkit": "jsr:@es-toolkit/es-toolkit@^1.39.5",
40
+ "fast-check": "npm:fast-check@^3.22.0",
41
+ "fetch-mock": "npm:fetch-mock@^12.5.2",
42
+ "json-canon": "npm:json-canon@^1.0.1",
43
+ "jsonld": "npm:jsonld@^8.3.2",
44
+ "multicodec": "npm:multicodec@^3.2.1",
45
+ "pkijs": "npm:pkijs@^3.2.4",
46
+ "structured-field-values": "npm:structured-field-values@^2.0.4",
47
+ "uri-template-router": "npm:uri-template-router@^0.0.17",
48
+ "url-template": "npm:url-template@^3.1.1"
49
+ };
50
+ var include = ["src/vocab/vocab.ts"];
51
+ var exclude = [
52
+ ".test-report.xml",
53
+ "apidoc/",
54
+ "dist/",
55
+ "node_modules/",
56
+ "npm/",
57
+ "pnpm-lock.yaml",
58
+ "src/cfworkers/dist/",
59
+ "src/cfworkers/fixtures/",
60
+ "src/cfworkers/imports.ts",
61
+ "src/cfworkers/README.md",
62
+ "src/cfworkers/server.ts",
63
+ "src/cfworkers/server.js",
64
+ "src/cfworkers/server.js.map",
65
+ "src/codegen/schema.yaml",
66
+ "src/vocab/*.yaml",
67
+ "!src/vocab/vocab.ts"
68
+ ];
69
+ var tasks = {
70
+ "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",
71
+ "cache": {
72
+ "command": "deno cache src/mod.ts",
73
+ "dependencies": ["codegen"]
74
+ },
75
+ "check": {
76
+ "command": "deno fmt --check && deno lint && deno check src/**/*.ts",
77
+ "dependencies": ["codegen"]
78
+ },
79
+ "test": {
80
+ "command": "deno test --check --doc --allow-read --allow-write --allow-env --unstable-kv --trace-leaks --parallel",
81
+ "dependencies": ["codegen"]
82
+ },
83
+ "coverage": "deno task test --clean --coverage && deno coverage --html coverage",
84
+ "bench": {
85
+ "command": "deno bench --allow-read --allow-write --allow-net --allow-env --allow-run --unstable-kv",
86
+ "dependencies": ["codegen"]
87
+ },
88
+ "apidoc": {
89
+ "command": "deno doc --html --name=Fedify --output=apidoc/ src/mod.ts",
90
+ "dependencies": ["codegen"]
91
+ },
92
+ "publish": {
93
+ "command": "deno publish",
94
+ "dependencies": ["codegen"]
95
+ },
96
+ "pnpm:install": "pnpm install --silent",
97
+ "pnpm:build": {
98
+ "command": "pnpm exec tsdown",
99
+ "dependencies": [
100
+ "codegen",
101
+ "pnpm:install",
102
+ "pnpm:build-vocab"
103
+ ]
104
+ },
105
+ "pnpm:build-vocab-runtime": { "command": "cd ../vocab-runtime && pnpm build" },
106
+ "pnpm:build-vocab": { "dependencies": ["pnpm:build-vocab-runtime"] },
107
+ "test:node": {
108
+ "command": "cd dist/ && node --test",
109
+ "dependencies": ["pnpm:build"]
110
+ },
111
+ "test:bun": {
112
+ "command": "cd dist/ && bun test --timeout 60000",
113
+ "dependencies": ["pnpm:build-vocab", "pnpm:build"]
114
+ },
115
+ "test:cfworkers": {
116
+ "command": "pnpm exec wrangler deploy --dry-run --outdir src/cfworkers && node --import=tsx src/cfworkers/client.ts",
117
+ "dependencies": ["pnpm:build-vocab", "pnpm:build"]
118
+ },
119
+ "test-all": { "dependencies": [
120
+ "check",
121
+ "test",
122
+ "test:node",
123
+ "test:bun",
124
+ "test:cfworkers"
125
+ ] }
126
+ };
127
+ var deno_default = {
128
+ name,
129
+ version,
130
+ license,
131
+ exports: exports$1,
132
+ imports,
133
+ include,
134
+ exclude,
135
+ tasks
136
+ };
137
+
138
+ //#endregion
139
+ //#region src/webfinger/lookup.ts
140
+ const logger = (0, __logtape_logtape.getLogger)([
141
+ "fedify",
142
+ "webfinger",
143
+ "lookup"
144
+ ]);
145
+ const DEFAULT_MAX_REDIRECTION = 5;
146
+ /**
147
+ * Looks up a WebFinger resource.
148
+ * @param resource The resource URL to look up.
149
+ * @param options Extra options for looking up the resource.
150
+ * @returns The resource descriptor, or `null` if not found.
151
+ * @since 0.2.0
152
+ */
153
+ async function lookupWebFinger(resource, options = {}) {
154
+ const tracerProvider = options.tracerProvider ?? __opentelemetry_api.trace.getTracerProvider();
155
+ const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
156
+ return await tracer.startActiveSpan("webfinger.lookup", {
157
+ kind: __opentelemetry_api.SpanKind.CLIENT,
158
+ attributes: {
159
+ "webfinger.resource": resource.toString(),
160
+ "webfinger.resource.scheme": typeof resource === "string" ? resource.replace(/:.*$/, "") : resource.protocol.replace(/:$/, "")
161
+ }
162
+ }, async (span) => {
163
+ try {
164
+ const result = await lookupWebFingerInternal(resource, options);
165
+ span.setStatus({ code: result === null ? __opentelemetry_api.SpanStatusCode.ERROR : __opentelemetry_api.SpanStatusCode.OK });
166
+ return result;
167
+ } catch (error) {
168
+ span.setStatus({
169
+ code: __opentelemetry_api.SpanStatusCode.ERROR,
170
+ message: String(error)
171
+ });
172
+ throw error;
173
+ } finally {
174
+ span.end();
175
+ }
176
+ });
177
+ }
178
+ async function lookupWebFingerInternal(resource, options = {}) {
179
+ if (typeof resource === "string") resource = new URL(resource);
180
+ let protocol = "https:";
181
+ let server;
182
+ if (resource.protocol === "acct:") {
183
+ const atPos = resource.pathname.lastIndexOf("@");
184
+ if (atPos < 0) return null;
185
+ server = resource.pathname.substring(atPos + 1);
186
+ if (server === "") return null;
187
+ } else {
188
+ protocol = resource.protocol;
189
+ server = resource.host;
190
+ }
191
+ let url = new URL(`${protocol}//${server}/.well-known/webfinger`);
192
+ url.searchParams.set("resource", resource.href);
193
+ let redirected = 0;
194
+ while (true) {
195
+ logger.debug("Fetching WebFinger resource descriptor from {url}...", { url: url.href });
196
+ let response;
197
+ if (options.allowPrivateAddress !== true) try {
198
+ await (0, __fedify_vocab_runtime.validatePublicUrl)(url.href);
199
+ } catch (e) {
200
+ if (e instanceof __fedify_vocab_runtime.UrlError) {
201
+ logger.error("Invalid URL for WebFinger resource descriptor: {error}", { error: e });
202
+ return null;
203
+ }
204
+ throw e;
205
+ }
206
+ try {
207
+ response = await fetch(url, {
208
+ headers: {
209
+ Accept: "application/jrd+json",
210
+ "User-Agent": typeof options.userAgent === "string" ? options.userAgent : (0, __fedify_vocab_runtime.getUserAgent)(options.userAgent)
211
+ },
212
+ redirect: "manual",
213
+ signal: options.signal
214
+ });
215
+ } catch (error) {
216
+ logger.debug("Failed to fetch WebFinger resource descriptor: {error}", {
217
+ url: url.href,
218
+ error
219
+ });
220
+ return null;
221
+ }
222
+ if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
223
+ redirected++;
224
+ const maxRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION;
225
+ if (redirected >= maxRedirection) {
226
+ logger.error("Too many redirections ({redirections}) while fetching WebFinger resource descriptor.", { redirections: redirected });
227
+ return null;
228
+ }
229
+ const redirectedUrl = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? url : response.url);
230
+ if (redirectedUrl.protocol !== url.protocol) {
231
+ logger.error("Redirected to a different protocol ({protocol} to {redirectedProtocol}) while fetching WebFinger resource descriptor.", {
232
+ protocol: url.protocol,
233
+ redirectedProtocol: redirectedUrl.protocol
234
+ });
235
+ return null;
236
+ }
237
+ url = redirectedUrl;
238
+ continue;
239
+ }
240
+ if (!response.ok) {
241
+ logger.debug("Failed to fetch WebFinger resource descriptor: {status} {statusText}.", {
242
+ url: url.href,
243
+ status: response.status,
244
+ statusText: response.statusText
245
+ });
246
+ return null;
247
+ }
248
+ try {
249
+ return await response.json();
250
+ } catch (e) {
251
+ if (e instanceof SyntaxError) {
252
+ logger.debug("Failed to parse WebFinger resource descriptor as JSON: {error}", { error: e });
253
+ return null;
254
+ }
255
+ throw e;
256
+ }
257
+ }
258
+ }
259
+
260
+ //#endregion
261
+ Object.defineProperty(exports, 'deno_default', {
262
+ enumerable: true,
263
+ get: function () {
264
+ return deno_default;
265
+ }
266
+ });
267
+ Object.defineProperty(exports, 'lookupWebFinger', {
268
+ enumerable: true,
269
+ get: function () {
270
+ return lookupWebFinger;
271
+ }
272
+ });