@fedify/fedify 2.0.0-pr.410.1558 → 2.0.0-pr.412.1692

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 (184) hide show
  1. package/dist/actor-CrTGiTZd.cjs +42609 -0
  2. package/dist/{actor-CkjTCNqi.js → actor-D5S46edz.js} +1 -1
  3. package/dist/actor-D6K058Tb.d.cts +128 -0
  4. package/dist/{actor-DmsbGzXS.js → actor-G2S5sPEA.js} +6951 -2127
  5. package/dist/{actor-C22bXuuC.d.ts → actor-T6RyhRgk.d.ts} +1 -1
  6. package/dist/{authdocloader-BwV2NPfz.js → authdocloader-C5AvdCCi.js} +6 -6
  7. package/dist/authdocloader-CQMPmpaO.cjs +58 -0
  8. package/dist/{authdocloader-BJxkviIL.js → authdocloader-SjwloJUA.js} +3 -3
  9. package/dist/{builder-DbOVAz8i.js → builder-OA47XRft.js} +10 -4
  10. package/dist/chunk-DqRYRqnO.cjs +34 -0
  11. package/dist/{client-DrNZd6r_.js → client-Bmd-i8x8.js} +3 -22
  12. package/dist/client-CegPX0Rn.d.cts +222 -0
  13. package/dist/{client-DF8anIB5.d.ts → client-bgSdkFa2.d.ts} +2 -74
  14. package/dist/compat/mod.cjs +10 -0
  15. package/dist/compat/mod.d.cts +13 -0
  16. package/dist/compat/mod.d.ts +8 -8
  17. package/dist/compat/mod.js +5 -5
  18. package/dist/compat/transformers.test.js +19 -19
  19. package/dist/compat-DmDDELst.cjs +4 -0
  20. package/dist/compat-nxUqe4Z-.js +4 -0
  21. package/dist/{context-9gCpIkiz.d.ts → context-ByZprN0S.d.ts} +67 -7
  22. package/dist/context-C5BsZkDr.d.cts +2315 -0
  23. package/dist/docloader-7Ey7wNHx.cjs +4861 -0
  24. package/dist/{docloader-DnepZfu_.js → docloader-CkweNhUH.js} +189 -9
  25. package/dist/docloader-D-MrRyHl.d.cts +219 -0
  26. package/dist/{esm-D1HqBE3n.js → esm-CwHz8Y8t.js} +1 -1
  27. package/dist/federation/builder.test.js +6 -7
  28. package/dist/federation/collection.test.js +4 -4
  29. package/dist/federation/handler.test.js +23 -143
  30. package/dist/federation/idempotency.test.js +202 -0
  31. package/dist/federation/inbox.test.js +4 -4
  32. package/dist/federation/keycache.test.js +4 -4
  33. package/dist/federation/kv.test.js +4 -3
  34. package/dist/federation/middleware.test.js +231 -52
  35. package/dist/federation/mod.cjs +29 -0
  36. package/dist/federation/mod.d.cts +13 -0
  37. package/dist/federation/mod.d.ts +8 -8
  38. package/dist/federation/mod.js +15 -15
  39. package/dist/federation/mq.test.js +3 -3
  40. package/dist/federation/negotiation.test.d.ts +3 -0
  41. package/dist/federation/negotiation.test.js +28 -0
  42. package/dist/federation/retry.test.js +3 -3
  43. package/dist/federation/router.test.js +3 -3
  44. package/dist/federation/send.test.js +10 -10
  45. package/dist/{federation-CMX7WzeL.js → federation-D1U8YY9t.js} +3 -3
  46. package/dist/federation-H2_En3j5.cjs +244 -0
  47. package/dist/fixtures/media.example.com/avatars/test-avatar.jpg.json +6 -0
  48. package/dist/http-BiBofurJ.cjs +826 -0
  49. package/dist/{http-BEJUSX6j.js → http-C5tC93Hn.js} +7 -7
  50. package/dist/http-D-e6AFwR.d.cts +253 -0
  51. package/dist/{http-DqSNLFNY.d.ts → http-D6Uj2x2y.d.ts} +1 -1
  52. package/dist/{http-BgCF3jDs.js → http-DGjdMiLc.js} +3 -3
  53. package/dist/{inbox-Bq4EChoK.js → inbox-BoDY3z8G.js} +24 -7
  54. package/dist/key-CZR7QraT.cjs +290 -0
  55. package/dist/key-Cf8MffVe.cjs +10 -0
  56. package/dist/{key-D-0OLe9C.js → key-CkxrAIyp.js} +5 -5
  57. package/dist/key-Dk0j88Jo.js +10 -0
  58. package/dist/{key-BD3lpBWw.js → key-Epcl5jpz.js} +3 -3
  59. package/dist/{key-BYNqWXyu.js → key-IxRhZpOF.js} +2 -2
  60. package/dist/{keycache-yZDAc3-e.js → keycache-TEniXNel.js} +1 -1
  61. package/dist/{keys-Dtc-g6xq.js → keys-bZxcrZ9Z.js} +1 -1
  62. package/dist/kv-63Cil1MD.d.cts +81 -0
  63. package/dist/{ld-BJ484qSg.js → ld-DW7A0uIc.js} +4 -4
  64. package/dist/{lookup-Cj0sX50U.js → lookup-DhQCVVja.js} +21 -12
  65. package/dist/lookup-DiV4LFBg.cjs +137 -0
  66. package/dist/{lookup-BzogF2gp.js → lookup-cVRa2QM-.js} +4 -4
  67. package/dist/middleware-Be1JStOx.js +17 -0
  68. package/dist/middleware-CDOK7WOb.js +26 -0
  69. package/dist/{middleware-CiH0ptqy.js → middleware-Cgr3PtaJ.js} +58 -149
  70. package/dist/{middleware-DIZ1dnwT.js → middleware-DvvYAIsd.js} +87 -91
  71. package/dist/middleware-EjIW2mZB.cjs +17 -0
  72. package/dist/middleware-TfuVoceY.cjs +4231 -0
  73. package/dist/mod-8DMWKtQE.d.cts +80 -0
  74. package/dist/{mod-Drmz72EK.d.ts → mod-BhUKmBJD.d.ts} +2 -2
  75. package/dist/mod-C2tOeRkN.d.cts +1 -0
  76. package/dist/{mod-TFoH2Ql8.d.ts → mod-CerN_Sza.d.ts} +1 -1
  77. package/dist/mod-Cj1tHXBR.d.cts +102 -0
  78. package/dist/mod-CxkWO3Mg.d.cts +307 -0
  79. package/dist/{mod-Bqxcp7eN.d.ts → mod-D6hQoxC5.d.ts} +2 -2
  80. package/dist/mod-Djzcw2ry.d.cts +266 -0
  81. package/dist/{mod-Cxt4Kpf6.d.ts → mod-DlU8ISoa.d.ts} +19 -1
  82. package/dist/mod-FZd39qVq.d.cts +1 -0
  83. package/dist/mod-jQ4OODsl.d.cts +113 -0
  84. package/dist/mod.cjs +150 -0
  85. package/dist/mod.d.cts +17 -0
  86. package/dist/mod.d.ts +11 -11
  87. package/dist/mod.js +21 -21
  88. package/dist/mq-B7R1Q-M5.d.cts +140 -0
  89. package/dist/negotiation-5NPJL6zp.js +71 -0
  90. package/dist/nodeinfo/client.test.js +27 -106
  91. package/dist/nodeinfo/handler.test.js +20 -20
  92. package/dist/nodeinfo/mod.cjs +11 -0
  93. package/dist/nodeinfo/mod.d.cts +5 -0
  94. package/dist/nodeinfo/mod.d.ts +2 -2
  95. package/dist/nodeinfo/mod.js +7 -7
  96. package/dist/nodeinfo/types.test.js +5 -10
  97. package/dist/nodeinfo-Co9lJrWl.cjs +4 -0
  98. package/dist/nodeinfo-DfycQ8Wf.js +4 -0
  99. package/dist/{owner-9FMX4wQT.js → owner-6Vc3UXXE.js} +2 -2
  100. package/dist/owner-BN_tO3cY.d.cts +67 -0
  101. package/dist/{owner-CQPnQVtf.d.ts → owner-hd9lvQcP.d.ts} +2 -2
  102. package/dist/{proof-Arx4Q9Q6.js → proof-C1jhbeNv.js} +3 -3
  103. package/dist/proof-CRJWXFfT.cjs +673 -0
  104. package/dist/{proof-DnTD0avk.js → proof-Chi90OXv.js} +9 -9
  105. package/dist/runtime/authdocloader.test.js +9 -9
  106. package/dist/runtime/docloader.test.js +4 -4
  107. package/dist/runtime/key.test.js +5 -5
  108. package/dist/runtime/langstr.test.js +3 -3
  109. package/dist/runtime/link.test.d.ts +3 -0
  110. package/dist/runtime/link.test.js +61 -0
  111. package/dist/runtime/mod.cjs +25 -0
  112. package/dist/runtime/mod.d.cts +6 -0
  113. package/dist/runtime/mod.d.ts +3 -3
  114. package/dist/runtime/mod.js +10 -10
  115. package/dist/runtime/multibase/multibase.test.js +3 -3
  116. package/dist/runtime/url.test.js +3 -3
  117. package/dist/runtime-C58AJWSv.cjs +4 -0
  118. package/dist/runtime-DPYEDf-o.js +4 -0
  119. package/dist/{send-CcxHe0p3.js → send-DjATl6i3.js} +2 -2
  120. package/dist/sig/http.test.js +9 -9
  121. package/dist/sig/key.test.js +6 -6
  122. package/dist/sig/ld.test.js +7 -7
  123. package/dist/sig/mod.cjs +30 -0
  124. package/dist/sig/mod.d.cts +8 -0
  125. package/dist/sig/mod.d.ts +5 -5
  126. package/dist/sig/mod.js +10 -10
  127. package/dist/sig/owner.test.js +7 -7
  128. package/dist/sig/proof.test.js +7 -7
  129. package/dist/sig-ByHXzqUi.cjs +4 -0
  130. package/dist/sig-Cj3tk-ig.js +4 -0
  131. package/dist/testing/docloader.test.js +3 -3
  132. package/dist/testing/mod.d.ts +273 -28
  133. package/dist/testing/mod.js +3 -3
  134. package/dist/{testing-DFgpNAI6.js → testing-BnfPB5T-.js} +2 -2
  135. package/dist/{transformers-Dna8Fg7k.js → transformers-BFT6d7J5.js} +3 -3
  136. package/dist/transformers-CoBS-oFG.cjs +116 -0
  137. package/dist/{type-B2h-NRAo.js → type-NEA09tSC.js} +7262 -2258
  138. package/dist/{types-BIgY6c-l.js → types-BSuWJsOm.js} +1 -3
  139. package/dist/types-CmmUQisS.cjs +315 -0
  140. package/dist/{types-B1QuBj5L.js → types-dLXLjVLf.js} +8 -169
  141. package/dist/vocab/actor.test.js +5 -5
  142. package/dist/vocab/lookup.test.js +255 -5
  143. package/dist/vocab/mod.cjs +87 -0
  144. package/dist/vocab/mod.d.cts +6 -0
  145. package/dist/vocab/mod.d.ts +3 -3
  146. package/dist/vocab/mod.js +7 -7
  147. package/dist/vocab/type.test.js +3 -3
  148. package/dist/vocab/vocab.test.js +433 -9
  149. package/dist/{vocab-SOE1ifCr.d.ts → vocab-BI0Ak5lL.d.ts} +290 -0
  150. package/dist/vocab-C5Y-0fGj.cjs +291 -0
  151. package/dist/vocab-Dw1-yVGg.d.cts +14922 -0
  152. package/dist/{vocab-BREfYr1a.js → vocab-rWbHpc2J.js} +26 -17
  153. package/dist/webfinger/handler.test.js +19 -19
  154. package/dist/webfinger/lookup.test.js +4 -4
  155. package/dist/webfinger/mod.cjs +9 -0
  156. package/dist/webfinger/mod.d.cts +4 -0
  157. package/dist/webfinger/mod.js +6 -6
  158. package/dist/webfinger-BjOEdFPs.cjs +4 -0
  159. package/dist/webfinger-De_bU0iE.js +4 -0
  160. package/dist/x/cfworkers.cjs +100 -0
  161. package/dist/x/cfworkers.d.cts +59 -0
  162. package/dist/x/cfworkers.js +3 -3
  163. package/dist/x/cfworkers.test.js +3 -3
  164. package/dist/x/hono.cjs +61 -0
  165. package/dist/x/hono.d.cts +54 -0
  166. package/dist/x/hono.d.ts +7 -7
  167. package/dist/x/hono.js +3 -3
  168. package/dist/x/sveltekit.cjs +69 -0
  169. package/dist/x/sveltekit.d.cts +46 -0
  170. package/dist/x/sveltekit.d.ts +7 -7
  171. package/dist/x/sveltekit.js +3 -3
  172. package/package.json +68 -13
  173. package/dist/compat-Bb5myD13.js +0 -4
  174. package/dist/key-BmFoI4_J.js +0 -10
  175. package/dist/middleware-D2W4gwdv.js +0 -17
  176. package/dist/middleware-LmK3pQ2z.js +0 -26
  177. package/dist/nodeinfo/semver.test.js +0 -143
  178. package/dist/nodeinfo-CyEbLjHs.js +0 -4
  179. package/dist/runtime-BSkOVUWM.js +0 -4
  180. package/dist/semver-dArNLkR9.js +0 -149
  181. package/dist/sig-BXJO--F9.js +0 -4
  182. package/dist/webfinger-C3GIyXIg.js +0 -4
  183. /package/dist/{collection-CSzG2j1P.js → collection-CcnIw1qY.js} +0 -0
  184. /package/dist/{nodeinfo/semver.test.d.ts → federation/idempotency.test.d.ts} +0 -0
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import "./type-B2h-NRAo.js";
7
- import "./actor-CkjTCNqi.js";
8
- import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-BYNqWXyu.js";
6
+ import "./type-NEA09tSC.js";
7
+ import "./actor-D5S46edz.js";
8
+ import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-IxRhZpOF.js";
9
9
 
10
10
  export { validateCryptoKey };
@@ -3,8 +3,8 @@
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-B2h-NRAo.js";
7
- import { isActor } from "./actor-CkjTCNqi.js";
6
+ import { CryptographicKey, Object as Object$1, deno_default, getDocumentLoader } from "./type-NEA09tSC.js";
7
+ import { isActor } from "./actor-D5S46edz.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
10
10
 
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Multikey } from "./type-B2h-NRAo.js";
6
+ import { CryptographicKey, Multikey } from "./type-NEA09tSC.js";
7
7
 
8
8
  //#region src/federation/keycache.ts
9
9
  var KvKeyCache = class {
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Multikey, importSpki } from "./type-B2h-NRAo.js";
6
+ import { CryptographicKey, Multikey, importSpki } from "./type-NEA09tSC.js";
7
7
 
8
8
  //#region src/testing/keys.ts
9
9
  const rsaPublicKey1 = new CryptographicKey({
@@ -0,0 +1,81 @@
1
+ //#region src/federation/kv.d.ts
2
+ /**
3
+ * A key for a key–value store. An array of one or more strings.
4
+ *
5
+ * @since 0.5.0
6
+ */
7
+ type KvKey = readonly [string] | readonly [string, ...string[]];
8
+ /**
9
+ * Additional options for setting a value in a key–value store.
10
+ *
11
+ * @since 0.5.0
12
+ */
13
+ interface KvStoreSetOptions {
14
+ /**
15
+ * The time-to-live (TTL) for the value.
16
+ */
17
+ ttl?: Temporal.Duration;
18
+ }
19
+ /**
20
+ * An abstract interface for a key–value store.
21
+ *
22
+ * @since 0.5.0
23
+ */
24
+ interface KvStore {
25
+ /**
26
+ * Gets the value for the given key.
27
+ * @param key The key to get the value for.
28
+ * @returns The value for the key, or `undefined` if the key does not exist.
29
+ * @template T The type of the value to get.
30
+ */
31
+ get<T = unknown>(key: KvKey): Promise<T | undefined>;
32
+ /**
33
+ * Sets the value for the given key.
34
+ * @param key The key to set the value for.
35
+ * @param value The value to set.
36
+ * @param options Additional options for setting the value.
37
+ */
38
+ set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
39
+ /**
40
+ * Deletes the value for the given key.
41
+ * @param key The key to delete.
42
+ */
43
+ delete(key: KvKey): Promise<void>;
44
+ /**
45
+ * Compare-and-swap (CAS) operation for the key–value store.
46
+ * @param key The key to perform the CAS operation on.
47
+ * @param expectedValue The expected value for the key.
48
+ * @param newValue The new value to set if the expected value matches.
49
+ * @param options Additional options for setting the value.
50
+ * @return `true` if the CAS operation was successful, `false` otherwise.
51
+ * @since 1.8.0
52
+ */
53
+ cas?: (key: KvKey, expectedValue: unknown, newValue: unknown, options?: KvStoreSetOptions) => Promise<boolean>;
54
+ }
55
+ /**
56
+ * A key–value store that stores values in memory.
57
+ * Do not use this in production as it does not persist values.
58
+ *
59
+ * @since 0.5.0
60
+ */
61
+ declare class MemoryKvStore implements KvStore {
62
+ #private;
63
+ /**
64
+ * {@inheritDoc KvStore.get}
65
+ */
66
+ get<T = unknown>(key: KvKey): Promise<T | undefined>;
67
+ /**
68
+ * {@inheritDoc KvStore.set}
69
+ */
70
+ set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
71
+ /**
72
+ * {@inheritDoc KvStore.delete}
73
+ */
74
+ delete(key: KvKey): Promise<void>;
75
+ /**
76
+ * {@inheritDoc KvStore.cas}
77
+ */
78
+ cas(key: KvKey, expectedValue: unknown, newValue: unknown, options?: KvStoreSetOptions): Promise<boolean>;
79
+ }
80
+ //#endregion
81
+ export { KvKey, KvStore, KvStoreSetOptions, MemoryKvStore };
@@ -3,8 +3,8 @@
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-B2h-NRAo.js";
7
- import { fetchKey, validateCryptoKey } from "./key-BYNqWXyu.js";
6
+ import { Activity, CryptographicKey, Object as Object$1, deno_default, getDocumentLoader, getTypeId } from "./type-NEA09tSC.js";
7
+ import { fetchKey, validateCryptoKey } from "./key-IxRhZpOF.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
10
10
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
@@ -182,7 +182,7 @@ async function verifySignature(jsonLd, options = {}) {
182
182
  const encoder = new TextEncoder();
183
183
  const message = sigOptsHash + docHash;
184
184
  const messageBytes = encoder.encode(message);
185
- const verified = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature, messageBytes);
185
+ const verified = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes);
186
186
  if (verified) return key;
187
187
  if (cached) {
188
188
  logger.debug("Failed to verify with the cached key {keyId}; signature {signatureValue} is invalid. Retrying with the freshly fetched key...", {
@@ -197,7 +197,7 @@ async function verifySignature(jsonLd, options = {}) {
197
197
  }
198
198
  });
199
199
  if (key$1 == null) return null;
200
- const verified$1 = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key$1.publicKey, signature, messageBytes);
200
+ const verified$1 = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key$1.publicKey, signature.slice(), messageBytes);
201
201
  return verified$1 ? key$1 : null;
202
202
  }
203
203
  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}", {
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Object as Object$1, deno_default, getDocumentLoader, getTypeId, lookupWebFinger } from "./type-B2h-NRAo.js";
6
+ import { Object as Object$1, deno_default, getDocumentLoader, getTypeId, lookupWebFinger } from "./type-NEA09tSC.js";
7
7
  import { cloneDeep, delay } from "es-toolkit";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
@@ -240,14 +240,13 @@ async function lookupObject(identifier, options = {}) {
240
240
  async function lookupObjectInternal(identifier, options = {}) {
241
241
  const documentLoader = options.documentLoader ?? getDocumentLoader({ userAgent: options.userAgent });
242
242
  if (typeof identifier === "string") identifier = toAcctUrl(identifier) ?? new URL(identifier);
243
- let document = null;
243
+ let remoteDoc = null;
244
244
  if (identifier.protocol === "http:" || identifier.protocol === "https:") try {
245
- const remoteDoc = await documentLoader(identifier.href, { signal: options.signal });
246
- document = remoteDoc.document;
245
+ remoteDoc = await documentLoader(identifier.href, { signal: options.signal });
247
246
  } catch (error) {
248
247
  logger.debug("Failed to fetch remote document:\n{error}", { error });
249
248
  }
250
- if (document == null) {
249
+ if (remoteDoc == null) {
251
250
  const jrd = await lookupWebFinger(identifier, {
252
251
  userAgent: options.userAgent,
253
252
  tracerProvider: options.tracerProvider,
@@ -258,8 +257,7 @@ async function lookupObjectInternal(identifier, options = {}) {
258
257
  for (const l of jrd.links) {
259
258
  if (l.type !== "application/activity+json" && !l.type?.match(/application\/ld\+json;\s*profile="https:\/\/www.w3.org\/ns\/activitystreams"/) || l.rel !== "self" || l.href == null) continue;
260
259
  try {
261
- const remoteDoc = await documentLoader(l.href, { signal: options.signal });
262
- document = remoteDoc.document;
260
+ remoteDoc = await documentLoader(l.href, { signal: options.signal });
263
261
  break;
264
262
  } catch (error) {
265
263
  logger.debug("Failed to fetch remote document:\n{error}", { error });
@@ -267,23 +265,34 @@ async function lookupObjectInternal(identifier, options = {}) {
267
265
  }
268
266
  }
269
267
  }
270
- if (document == null) return null;
268
+ if (remoteDoc == null) return null;
269
+ let object;
271
270
  try {
272
- return await Object$1.fromJsonLd(document, {
271
+ object = await Object$1.fromJsonLd(remoteDoc.document, {
273
272
  documentLoader,
274
273
  contextLoader: options.contextLoader,
275
- tracerProvider: options.tracerProvider
274
+ tracerProvider: options.tracerProvider,
275
+ baseUrl: new URL(remoteDoc.documentUrl)
276
276
  });
277
277
  } catch (error) {
278
278
  if (error instanceof TypeError) {
279
279
  logger.debug("Failed to parse JSON-LD document: {error}\n{document}", {
280
- error,
281
- document
280
+ ...remoteDoc,
281
+ error
282
282
  });
283
283
  return null;
284
284
  }
285
285
  throw error;
286
286
  }
287
+ if (options.crossOrigin !== "trust" && object.id != null && object.id.origin !== new URL(remoteDoc.documentUrl).origin) {
288
+ if (options.crossOrigin === "throw") throw new Error(`The object's @id (${object.id.href}) has a different origin than the document URL (${remoteDoc.documentUrl}); refusing to return the object. If you want to bypass this check and are aware of the security implications, set the crossOrigin option to "trust".`);
289
+ logger.warn("The object's @id ({objectId}) has a different origin than the document URL ({documentUrl}); refusing to return the object. If you want to bypass this check and are aware of the security implications, set the crossOrigin option to \"trust\".", {
290
+ ...remoteDoc,
291
+ objectId: object.id.href
292
+ });
293
+ return null;
294
+ }
295
+ return object;
287
296
  }
288
297
  /**
289
298
  * Traverses a collection, yielding each item in the collection.
@@ -0,0 +1,137 @@
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_docloader = require('./docloader-7Ey7wNHx.cjs');
7
+ const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
8
+ const __opentelemetry_api = require_chunk.__toESM(require("@opentelemetry/api"));
9
+
10
+ //#region src/webfinger/lookup.ts
11
+ const logger = (0, __logtape_logtape.getLogger)([
12
+ "fedify",
13
+ "webfinger",
14
+ "lookup"
15
+ ]);
16
+ const DEFAULT_MAX_REDIRECTION = 5;
17
+ /**
18
+ * Looks up a WebFinger resource.
19
+ * @param resource The resource URL to look up.
20
+ * @param options Extra options for looking up the resource.
21
+ * @returns The resource descriptor, or `null` if not found.
22
+ * @since 0.2.0
23
+ */
24
+ async function lookupWebFinger(resource, options = {}) {
25
+ const tracerProvider = options.tracerProvider ?? __opentelemetry_api.trace.getTracerProvider();
26
+ const tracer = tracerProvider.getTracer(require_docloader.deno_default.name, require_docloader.deno_default.version);
27
+ return await tracer.startActiveSpan("webfinger.lookup", {
28
+ kind: __opentelemetry_api.SpanKind.CLIENT,
29
+ attributes: {
30
+ "webfinger.resource": resource.toString(),
31
+ "webfinger.resource.scheme": typeof resource === "string" ? resource.replace(/:.*$/, "") : resource.protocol.replace(/:$/, "")
32
+ }
33
+ }, async (span) => {
34
+ try {
35
+ const result = await lookupWebFingerInternal(resource, options);
36
+ span.setStatus({ code: result === null ? __opentelemetry_api.SpanStatusCode.ERROR : __opentelemetry_api.SpanStatusCode.OK });
37
+ return result;
38
+ } catch (error) {
39
+ span.setStatus({
40
+ code: __opentelemetry_api.SpanStatusCode.ERROR,
41
+ message: String(error)
42
+ });
43
+ throw error;
44
+ } finally {
45
+ span.end();
46
+ }
47
+ });
48
+ }
49
+ async function lookupWebFingerInternal(resource, options = {}) {
50
+ if (typeof resource === "string") resource = new URL(resource);
51
+ let protocol = "https:";
52
+ let server;
53
+ if (resource.protocol === "acct:") {
54
+ const atPos = resource.pathname.lastIndexOf("@");
55
+ if (atPos < 0) return null;
56
+ server = resource.pathname.substring(atPos + 1);
57
+ if (server === "") return null;
58
+ } else {
59
+ protocol = resource.protocol;
60
+ server = resource.host;
61
+ }
62
+ let url = new URL(`${protocol}//${server}/.well-known/webfinger`);
63
+ url.searchParams.set("resource", resource.href);
64
+ let redirected = 0;
65
+ while (true) {
66
+ logger.debug("Fetching WebFinger resource descriptor from {url}...", { url: url.href });
67
+ let response;
68
+ if (options.allowPrivateAddress !== true) try {
69
+ await require_docloader.validatePublicUrl(url.href);
70
+ } catch (e) {
71
+ if (e instanceof require_docloader.UrlError) {
72
+ logger.error("Invalid URL for WebFinger resource descriptor: {error}", { error: e });
73
+ return null;
74
+ }
75
+ throw e;
76
+ }
77
+ try {
78
+ response = await fetch(url, {
79
+ headers: {
80
+ Accept: "application/jrd+json",
81
+ "User-Agent": typeof options.userAgent === "string" ? options.userAgent : require_docloader.getUserAgent(options.userAgent)
82
+ },
83
+ redirect: "manual",
84
+ signal: options.signal
85
+ });
86
+ } catch (error) {
87
+ logger.debug("Failed to fetch WebFinger resource descriptor: {error}", {
88
+ url: url.href,
89
+ error
90
+ });
91
+ return null;
92
+ }
93
+ if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
94
+ redirected++;
95
+ const maxRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION;
96
+ if (redirected >= maxRedirection) {
97
+ logger.error("Too many redirections ({redirections}) while fetching WebFinger resource descriptor.", { redirections: redirected });
98
+ return null;
99
+ }
100
+ const redirectedUrl = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? url : response.url);
101
+ if (redirectedUrl.protocol !== url.protocol) {
102
+ logger.error("Redirected to a different protocol ({protocol} to {redirectedProtocol}) while fetching WebFinger resource descriptor.", {
103
+ protocol: url.protocol,
104
+ redirectedProtocol: redirectedUrl.protocol
105
+ });
106
+ return null;
107
+ }
108
+ url = redirectedUrl;
109
+ continue;
110
+ }
111
+ if (!response.ok) {
112
+ logger.debug("Failed to fetch WebFinger resource descriptor: {status} {statusText}.", {
113
+ url: url.href,
114
+ status: response.status,
115
+ statusText: response.statusText
116
+ });
117
+ return null;
118
+ }
119
+ try {
120
+ return await response.json();
121
+ } catch (e) {
122
+ if (e instanceof SyntaxError) {
123
+ logger.debug("Failed to parse WebFinger resource descriptor as JSON: {error}", { error: e });
124
+ return null;
125
+ }
126
+ throw e;
127
+ }
128
+ }
129
+ }
130
+
131
+ //#endregion
132
+ Object.defineProperty(exports, 'lookupWebFinger', {
133
+ enumerable: true,
134
+ get: function () {
135
+ return lookupWebFinger;
136
+ }
137
+ });
@@ -1,8 +1,8 @@
1
1
 
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { UrlError, deno_default, getUserAgent, validatePublicUrl } from "./docloader-DnepZfu_.js";
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import { UrlError, deno_default, getUserAgent, validatePublicUrl } from "./docloader-CkweNhUH.js";
6
6
  import { getLogger } from "@logtape/logtape";
7
7
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
8
8
 
@@ -0,0 +1,17 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import "./transformers-BFT6d7J5.js";
6
+ import "./docloader-CkweNhUH.js";
7
+ import "./actor-G2S5sPEA.js";
8
+ import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "./middleware-DvvYAIsd.js";
9
+ import "./lookup-cVRa2QM-.js";
10
+ import "./key-CkxrAIyp.js";
11
+ import "./http-C5tC93Hn.js";
12
+ import "./proof-Chi90OXv.js";
13
+ import "./types-dLXLjVLf.js";
14
+ import "./authdocloader-C5AvdCCi.js";
15
+ import "./vocab-rWbHpc2J.js";
16
+
17
+ export { FederationImpl };
@@ -0,0 +1,26 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import "./type-NEA09tSC.js";
7
+ import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "./middleware-Cgr3PtaJ.js";
8
+ import "./client-Bmd-i8x8.js";
9
+ import "./lookup-DhQCVVja.js";
10
+ import "./types-BSuWJsOm.js";
11
+ import "./actor-D5S46edz.js";
12
+ import "./key-IxRhZpOF.js";
13
+ import "./http-DGjdMiLc.js";
14
+ import "./authdocloader-SjwloJUA.js";
15
+ import "./ld-DW7A0uIc.js";
16
+ import "./owner-6Vc3UXXE.js";
17
+ import "./proof-C1jhbeNv.js";
18
+ import "./inbox-BoDY3z8G.js";
19
+ import "./builder-OA47XRft.js";
20
+ import "./collection-CcnIw1qY.js";
21
+ import "./keycache-TEniXNel.js";
22
+ import "./negotiation-5NPJL6zp.js";
23
+ import "./retry-D4GJ670a.js";
24
+ import "./send-DjATl6i3.js";
25
+
26
+ export { FederationImpl };