@fedify/vocab-runtime 2.4.0-pr.936.41 → 2.4.1

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 (152) hide show
  1. package/deno.json +4 -2
  2. package/dist/{tests/docloader-Ck8bcBir.mjs → contexts-B09jb9Pi.cjs} +173 -274
  3. package/dist/{tests/docloader-S_gQZ2tt.cjs → contexts-DWrj4AGR.js} +169 -293
  4. package/dist/{docloader-C_dir7Xb.d.ts → docloader-BMHljyYb.d.cts} +68 -2
  5. package/dist/{docloader-D2DTRiyA.d.cts → docloader-BMHljyYb.d.ts} +68 -2
  6. package/dist/internal/jsonld-cache.cjs +70 -1
  7. package/dist/internal/jsonld-cache.d.cts +35 -2
  8. package/dist/internal/jsonld-cache.d.ts +35 -2
  9. package/dist/internal/jsonld-cache.js +67 -2
  10. package/dist/internal/portable-dereference.cjs +721 -0
  11. package/dist/internal/portable-dereference.d.cts +349 -0
  12. package/dist/internal/portable-dereference.d.ts +349 -0
  13. package/dist/internal/portable-dereference.js +702 -0
  14. package/dist/internal/signed-representation.cjs +378 -0
  15. package/dist/internal/signed-representation.d.cts +144 -0
  16. package/dist/internal/signed-representation.d.ts +144 -0
  17. package/dist/internal/signed-representation.js +371 -0
  18. package/dist/jsonld.cjs +2 -2
  19. package/dist/mod.cjs +762 -4529
  20. package/dist/mod.d.cts +427 -9
  21. package/dist/mod.d.ts +427 -10
  22. package/dist/mod.js +742 -4524
  23. package/dist/portable-6Aj-7dZJ.d.cts +160 -0
  24. package/dist/portable-nkTiqH0w.d.ts +160 -0
  25. package/dist/tests/body-DpC9p-iG.mjs +130 -0
  26. package/dist/tests/body-cKLBprYm.cjs +153 -0
  27. package/dist/tests/body.test.cjs +89 -0
  28. package/dist/tests/body.test.d.cts +1 -0
  29. package/dist/tests/body.test.d.mts +1 -0
  30. package/dist/tests/body.test.mjs +90 -0
  31. package/dist/tests/contexts-C9Lj11SC.cjs +4533 -0
  32. package/dist/tests/contexts-duRA_dDC.mjs +4522 -0
  33. package/dist/tests/decimal.test.cjs +9 -7
  34. package/dist/tests/decimal.test.mjs +9 -6
  35. package/dist/tests/digest-3FeH2Y-Q.cjs +176 -0
  36. package/dist/tests/digest-COC7xDiQ.mjs +141 -0
  37. package/dist/tests/digest.test.cjs +102 -0
  38. package/dist/tests/digest.test.d.cts +1 -0
  39. package/dist/tests/digest.test.d.mts +1 -0
  40. package/dist/tests/digest.test.mjs +103 -0
  41. package/dist/tests/docloader-DyZ1JGIl.cjs +398 -0
  42. package/dist/tests/docloader-tUmMeXjU.mjs +375 -0
  43. package/dist/tests/docloader.test.cjs +816 -39
  44. package/dist/tests/docloader.test.mjs +810 -34
  45. package/dist/tests/internal/multicodec.test.cjs +2 -3
  46. package/dist/tests/internal/multicodec.test.mjs +2 -2
  47. package/dist/tests/internal/portable-dereference.test.cjs +172 -0
  48. package/dist/tests/internal/portable-dereference.test.d.cts +1 -0
  49. package/dist/tests/internal/portable-dereference.test.d.mts +1 -0
  50. package/dist/tests/internal/portable-dereference.test.mjs +173 -0
  51. package/dist/tests/jsonld-CmDhHNTx.cjs +12 -0
  52. package/dist/tests/jsonld-DweIJ07b.mjs +5 -0
  53. package/dist/tests/jsonld-cache-BEXiiM-V.cjs +386 -0
  54. package/dist/tests/jsonld-cache-DFnWsLuZ.mjs +339 -0
  55. package/dist/tests/jsonld-cache.test.cjs +102 -298
  56. package/dist/tests/jsonld-cache.test.mjs +95 -289
  57. package/dist/tests/{key-_wXwomh_.cjs → key-C-AYkdJJ.cjs} +11 -4
  58. package/dist/tests/{key-CDGDH_vC.mjs → key-C2Db_TAJ.mjs} +11 -3
  59. package/dist/tests/key.test.cjs +6 -5
  60. package/dist/tests/key.test.mjs +6 -4
  61. package/dist/tests/{langstr-Di5AvKpB.mjs → langstr-DYRmJqFn.mjs} +5 -2
  62. package/dist/tests/{langstr-CbAxaeEZ.cjs → langstr-_PqsL1ae.cjs} +5 -2
  63. package/dist/tests/langstr.test.cjs +11 -4
  64. package/dist/tests/langstr.test.mjs +9 -2
  65. package/dist/tests/langtag-CUppHs_s.mjs +45 -0
  66. package/dist/tests/langtag-Czjvxfzx.cjs +50 -0
  67. package/dist/tests/langtag.test.cjs +45 -0
  68. package/dist/tests/langtag.test.d.cts +1 -0
  69. package/dist/tests/langtag.test.d.mts +1 -0
  70. package/dist/tests/langtag.test.mjs +46 -0
  71. package/dist/tests/link.test.cjs +2 -3
  72. package/dist/tests/link.test.mjs +2 -2
  73. package/dist/tests/multibase/multibase.test.cjs +8 -9
  74. package/dist/tests/multibase/multibase.test.mjs +6 -6
  75. package/dist/tests/{multibase-Bz_UUDtL.cjs → multibase-B5Mea7Ip.cjs} +19 -2
  76. package/dist/tests/{multibase-B4bvakyA.mjs → multibase-BPnF_L4e.mjs} +12 -1
  77. package/dist/tests/portable-dereference-DmTYDy2p.mjs +250 -0
  78. package/dist/tests/portable-dereference-qTLMqe2_.cjs +279 -0
  79. package/dist/tests/portable-media-5p8azal0.cjs +153 -0
  80. package/dist/tests/portable-media-B_lt9MMA.mjs +148 -0
  81. package/dist/tests/portable-media.test.cjs +222 -0
  82. package/dist/tests/portable-media.test.d.cts +1 -0
  83. package/dist/tests/portable-media.test.d.mts +1 -0
  84. package/dist/tests/portable-media.test.mjs +223 -0
  85. package/dist/tests/portable-workers.test.cjs +36 -0
  86. package/dist/tests/portable-workers.test.d.cts +2 -0
  87. package/dist/tests/portable-workers.test.d.mts +2 -0
  88. package/dist/tests/portable-workers.test.mjs +35 -0
  89. package/dist/tests/{request-uk51rkhO.cjs → request-BgjA9wyl.cjs} +10 -4
  90. package/dist/tests/{request-C8CaGwtt.mjs → request-DodZNukP.mjs} +8 -2
  91. package/dist/tests/request.test.cjs +7 -4
  92. package/dist/tests/request.test.mjs +5 -2
  93. package/dist/tests/signed-representation.test.cjs +588 -0
  94. package/dist/tests/signed-representation.test.d.cts +1 -0
  95. package/dist/tests/signed-representation.test.d.mts +1 -0
  96. package/dist/tests/signed-representation.test.mjs +589 -0
  97. package/dist/tests/temporal.test.cjs +1 -2
  98. package/dist/tests/temporal.test.mjs +1 -1
  99. package/dist/tests/url-BNakuZ8k.cjs +998 -0
  100. package/dist/tests/url-DMxmp7ZG.mjs +859 -0
  101. package/dist/tests/url.test.cjs +489 -6
  102. package/dist/tests/url.test.mjs +489 -5
  103. package/dist/url-DrGTR8yv.cjs +993 -0
  104. package/dist/url-Dzyp-NsC.js +860 -0
  105. package/package.json +27 -4
  106. package/scripts/test-bun.mjs +17 -0
  107. package/src/body.test.ts +125 -0
  108. package/src/body.ts +152 -0
  109. package/src/contexts/cid-v1.json +114 -0
  110. package/src/contexts/fep-22cd.json +21 -0
  111. package/src/contexts/fep-6757.json +12 -0
  112. package/src/contexts/joinmastodon.json +1 -1
  113. package/src/contexts/miscellany.json +17 -0
  114. package/src/contexts.ts +47 -1
  115. package/src/digest.test.ts +220 -0
  116. package/src/digest.ts +229 -0
  117. package/src/docloader.test.ts +1066 -27
  118. package/src/docloader.ts +322 -105
  119. package/src/internal/jsonld-cache.ts +97 -1
  120. package/src/internal/portable-dereference.test.ts +254 -0
  121. package/src/internal/portable-dereference.ts +1000 -0
  122. package/src/internal/signed-representation.ts +565 -0
  123. package/src/jsonld-cache.test.ts +89 -0
  124. package/src/key.test.ts +9 -0
  125. package/src/key.ts +11 -1
  126. package/src/langstr.test.ts +18 -1
  127. package/src/langstr.ts +6 -2
  128. package/src/langtag.test.ts +53 -0
  129. package/src/langtag.ts +76 -0
  130. package/src/mod.ts +29 -0
  131. package/src/multibase/multibase.test.ts +5 -5
  132. package/src/portable-media.test.ts +293 -0
  133. package/src/portable-media.ts +264 -0
  134. package/src/portable-workers.test.ts +81 -0
  135. package/src/portable.ts +180 -0
  136. package/src/preprocessor.ts +7 -0
  137. package/src/request.test.ts +10 -1
  138. package/src/request.ts +9 -1
  139. package/src/signed-representation.test.ts +338 -0
  140. package/src/url.test.ts +823 -3
  141. package/src/url.ts +700 -23
  142. package/tsdown.config.ts +2 -0
  143. package/dist/tests/url-CsOV_B_P.cjs +0 -482
  144. package/dist/tests/url-Du7RQQgP.mjs +0 -392
  145. package/dist/url-DD4F0ULf.cjs +0 -483
  146. package/dist/url-DGVbSVVi.js +0 -393
  147. /package/dist/{chunk-M78iaK0I.cjs → rolldown-runtime-B7lfambq.cjs} +0 -0
  148. /package/dist/tests/{link-NUUWCdnK.mjs → link-Cevmc87v.mjs} +0 -0
  149. /package/dist/tests/{link-FguCydMA.cjs → link-DlKm8bEr.cjs} +0 -0
  150. /package/dist/tests/{multicodec-CxGVGa91.cjs → multicodec-CLRPeW4N.cjs} +0 -0
  151. /package/dist/tests/{multicodec-CyFp54fI.mjs → multicodec-CRIj_05H.mjs} +0 -0
  152. /package/dist/tests/{chunk-C2EiDwsr.cjs → rolldown-runtime-emK7D4bc.cjs} +0 -0
package/deno.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@fedify/vocab-runtime",
3
- "version": "2.4.0-pr.936.41+59c7432c",
3
+ "version": "2.4.1",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./src/mod.ts",
7
7
  "./internal/jsonld-cache": "./src/internal/jsonld-cache.ts",
8
+ "./internal/portable-dereference": "./src/internal/portable-dereference.ts",
9
+ "./internal/signed-representation": "./src/internal/signed-representation.ts",
8
10
  "./jsonld": "./src/jsonld.ts",
9
11
  "./temporal": "./src/temporal.ts"
10
12
  },
@@ -34,6 +36,6 @@
34
36
  },
35
37
  "tasks": {
36
38
  "check": "deno fmt --check && deno lint && deno check src/*.ts",
37
- "test": "deno test"
39
+ "test": "deno test --allow-net --allow-env=LOG"
38
40
  }
39
41
  }
@@ -1,8 +1,4 @@
1
- import { a as name, i as logRequest, n as createActivityPubRequest, o as version, t as FetchError } from "./request-C8CaGwtt.mjs";
2
- import { t as HttpHeaderLink } from "./link-NUUWCdnK.mjs";
3
- import { h as validatePublicUrl, t as UrlError } from "./url-Du7RQQgP.mjs";
4
- import { getLogger } from "@logtape/logtape";
5
- import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
1
+
6
2
  //#endregion
7
3
  //#region src/contexts.ts
8
4
  const preloadedContexts = {
@@ -4239,6 +4235,34 @@ const preloadedContexts = {
4239
4235
  "@type": "@id"
4240
4236
  }
4241
4237
  } },
4238
+ "https://w3id.org/fep/22cd": { "@context": {
4239
+ "fep-22cd": "https://w3id.org/fep/22cd#",
4240
+ "schema": "https://schema.org/",
4241
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
4242
+ "translations": {
4243
+ "@id": "fep-22cd:translations",
4244
+ "@container": "@set"
4245
+ },
4246
+ "Translation": "fep-22cd:Translation",
4247
+ "sourceUpdated": {
4248
+ "@id": "fep-22cd:sourceUpdated",
4249
+ "@type": "xsd:dateTime"
4250
+ },
4251
+ "translator": {
4252
+ "@id": "schema:translator",
4253
+ "@type": "@id",
4254
+ "@container": "@set"
4255
+ },
4256
+ "inLanguage": "schema:inLanguage",
4257
+ "translationOfWork": {
4258
+ "@id": "schema:translationOfWork",
4259
+ "@type": "@id"
4260
+ },
4261
+ "isBasedOn": {
4262
+ "@id": "schema:isBasedOn",
4263
+ "@type": "@id"
4264
+ }
4265
+ } },
4242
4266
  "https://w3id.org/fep/5711": { "@context": {
4243
4267
  "likesOf": {
4244
4268
  "@id": "https://w3id.org/fep/5711#likesOf",
@@ -4273,6 +4297,125 @@ const preloadedContexts = {
4273
4297
  "@type": "@id"
4274
4298
  }
4275
4299
  } },
4300
+ "https://www.w3.org/ns/cid/v1": { "@context": {
4301
+ "@protected": true,
4302
+ "id": "@id",
4303
+ "type": "@type",
4304
+ "alsoKnownAs": {
4305
+ "@id": "https://www.w3.org/ns/activitystreams#alsoKnownAs",
4306
+ "@type": "@id"
4307
+ },
4308
+ "assertionMethod": {
4309
+ "@id": "https://w3id.org/security#assertionMethod",
4310
+ "@type": "@id",
4311
+ "@container": "@set"
4312
+ },
4313
+ "authentication": {
4314
+ "@id": "https://w3id.org/security#authenticationMethod",
4315
+ "@type": "@id",
4316
+ "@container": "@set"
4317
+ },
4318
+ "capabilityDelegation": {
4319
+ "@id": "https://w3id.org/security#capabilityDelegationMethod",
4320
+ "@type": "@id",
4321
+ "@container": "@set"
4322
+ },
4323
+ "capabilityInvocation": {
4324
+ "@id": "https://w3id.org/security#capabilityInvocationMethod",
4325
+ "@type": "@id",
4326
+ "@container": "@set"
4327
+ },
4328
+ "controller": {
4329
+ "@id": "https://w3id.org/security#controller",
4330
+ "@type": "@id"
4331
+ },
4332
+ "keyAgreement": {
4333
+ "@id": "https://w3id.org/security#keyAgreementMethod",
4334
+ "@type": "@id",
4335
+ "@container": "@set"
4336
+ },
4337
+ "service": {
4338
+ "@id": "https://www.w3.org/ns/did#service",
4339
+ "@type": "@id",
4340
+ "@context": {
4341
+ "@protected": true,
4342
+ "id": "@id",
4343
+ "type": "@type",
4344
+ "serviceEndpoint": {
4345
+ "@id": "https://www.w3.org/ns/did#serviceEndpoint",
4346
+ "@type": "@id"
4347
+ }
4348
+ }
4349
+ },
4350
+ "verificationMethod": {
4351
+ "@id": "https://w3id.org/security#verificationMethod",
4352
+ "@type": "@id"
4353
+ },
4354
+ "Multikey": {
4355
+ "@id": "https://w3id.org/security#Multikey",
4356
+ "@context": {
4357
+ "@protected": true,
4358
+ "id": "@id",
4359
+ "type": "@type",
4360
+ "controller": {
4361
+ "@id": "https://w3id.org/security#controller",
4362
+ "@type": "@id"
4363
+ },
4364
+ "revoked": {
4365
+ "@id": "https://w3id.org/security#revoked",
4366
+ "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
4367
+ },
4368
+ "expires": {
4369
+ "@id": "https://w3id.org/security#expiration",
4370
+ "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
4371
+ },
4372
+ "publicKeyMultibase": {
4373
+ "@id": "https://w3id.org/security#publicKeyMultibase",
4374
+ "@type": "https://w3id.org/security#multibase"
4375
+ },
4376
+ "secretKeyMultibase": {
4377
+ "@id": "https://w3id.org/security#secretKeyMultibase",
4378
+ "@type": "https://w3id.org/security#multibase"
4379
+ }
4380
+ }
4381
+ },
4382
+ "JsonWebKey": {
4383
+ "@id": "https://w3id.org/security#JsonWebKey",
4384
+ "@context": {
4385
+ "@protected": true,
4386
+ "id": "@id",
4387
+ "type": "@type",
4388
+ "controller": {
4389
+ "@id": "https://w3id.org/security#controller",
4390
+ "@type": "@id"
4391
+ },
4392
+ "revoked": {
4393
+ "@id": "https://w3id.org/security#revoked",
4394
+ "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
4395
+ },
4396
+ "expires": {
4397
+ "@id": "https://w3id.org/security#expiration",
4398
+ "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
4399
+ },
4400
+ "publicKeyJwk": {
4401
+ "@id": "https://w3id.org/security#publicKeyJwk",
4402
+ "@type": "@json"
4403
+ },
4404
+ "secretKeyJwk": {
4405
+ "@id": "https://w3id.org/security#secretKeyJwk",
4406
+ "@type": "@json"
4407
+ }
4408
+ }
4409
+ }
4410
+ } },
4411
+ "https://w3id.org/fep/ef61": { "@context": {
4412
+ "gateways": {
4413
+ "@id": "https://w3id.org/fep/ef61/gateways",
4414
+ "@type": "@id",
4415
+ "@container": "@list"
4416
+ },
4417
+ "digestMultibase": "https://www.w3.org/ns/credentials/v2#digestMultibase"
4418
+ } },
4276
4419
  "https://w3id.org/fep/7aa9": { "@context": {
4277
4420
  "FeaturedCollection": "https://w3id.org/fep/7aa9#FeaturedCollection",
4278
4421
  "FeaturedItem": "https://w3id.org/fep/7aa9#FeaturedItem",
@@ -4295,13 +4438,15 @@ const preloadedContexts = {
4295
4438
  "@type": "@id"
4296
4439
  }
4297
4440
  } },
4298
- "https://w3id.org/fep/ef61": { "@context": {
4299
- "gateways": {
4300
- "@id": "https://w3id.org/fep/ef61/gateways",
4301
- "@type": "@id",
4302
- "@container": "@list"
4441
+ "https://w3id.org/fep/6757": { "@context": {
4442
+ "license": {
4443
+ "@id": "http://purl.org/dc/terms/license",
4444
+ "@type": "@id"
4303
4445
  },
4304
- "digestMultibase": "https://www.w3.org/ns/credentials/v2#digestMultibase"
4446
+ "preferredLicense": {
4447
+ "@id": "https://w3id.org/fep/6757#preferredLicense",
4448
+ "@type": "@id"
4449
+ }
4305
4450
  } },
4306
4451
  "https://join-lemmy.org/context.json": { "@context": ["https://w3id.org/security/v1", {
4307
4452
  "as": "https://www.w3.org/ns/activitystreams#",
@@ -4354,271 +4499,25 @@ const preloadedContexts = {
4354
4499
  "suspended": "toot:suspended",
4355
4500
  "attributionDomains": {
4356
4501
  "@id": "toot:attributionDomains",
4357
- "@type": "@id"
4502
+ "@container": "@set"
4358
4503
  }
4504
+ } },
4505
+ "https://purl.archive.org/miscellany": { "@context": {
4506
+ "as": "https://www.w3.org/ns/activitystreams#",
4507
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
4508
+ "Hashtag": "as:Hashtag",
4509
+ "manuallyApprovesFollowers": { "@id": "as:manuallyApprovesFollowers" },
4510
+ "movedTo": {
4511
+ "@id": "as:movedTo",
4512
+ "@type": "@id"
4513
+ },
4514
+ "sensitive": { "@id": "as:sensitive" }
4359
4515
  } }
4360
4516
  };
4361
4517
  //#endregion
4362
- //#region src/docloader.ts
4363
- const logger = getLogger([
4364
- "fedify",
4365
- "runtime",
4366
- "docloader"
4367
- ]);
4368
- const DEFAULT_MAX_REDIRECTION = 20;
4369
- const MAX_HTML_SIZE = 1024 * 1024;
4370
- function createResponseMetadata(response) {
4371
- return new Response(null, {
4372
- headers: response.headers,
4373
- status: response.status,
4374
- statusText: response.statusText
4375
- });
4376
- }
4377
- async function cancelResponseBody(response) {
4378
- if (response.body != null) await response.body.cancel();
4379
- }
4380
- async function readBoundedText(response, maxBytes) {
4381
- const contentLength = response.headers.get("Content-Length");
4382
- if (contentLength != null) {
4383
- const size = Number(contentLength);
4384
- if (size > maxBytes) {
4385
- await cancelResponseBody(response);
4386
- return {
4387
- text: "",
4388
- size,
4389
- tooLarge: true
4390
- };
4391
- }
4392
- }
4393
- if (response.body == null) return {
4394
- text: "",
4395
- size: 0,
4396
- tooLarge: false
4397
- };
4398
- const reader = response.body.getReader();
4399
- const decoder = new TextDecoder();
4400
- let text = "";
4401
- let size = 0;
4402
- try {
4403
- while (true) {
4404
- const result = await reader.read();
4405
- if (result.done) break;
4406
- const chunkSize = result.value.byteLength;
4407
- if (size + chunkSize > maxBytes) {
4408
- size += chunkSize;
4409
- await reader.cancel();
4410
- return {
4411
- text: "",
4412
- size,
4413
- tooLarge: true
4414
- };
4415
- }
4416
- size += chunkSize;
4417
- text += decoder.decode(result.value, { stream: true });
4418
- }
4419
- text += decoder.decode();
4420
- return {
4421
- text,
4422
- size,
4423
- tooLarge: false
4424
- };
4425
- } finally {
4426
- reader.releaseLock();
4518
+ Object.defineProperty(exports, "preloadedContexts", {
4519
+ enumerable: true,
4520
+ get: function() {
4521
+ return preloadedContexts;
4427
4522
  }
4428
- }
4429
- /**
4430
- * Gets a {@link RemoteDocument} from the given response.
4431
- * @param url The URL of the document to load.
4432
- * @param response The response to get the document from.
4433
- * @param fetch The function to fetch the document.
4434
- * @returns The loaded remote document.
4435
- * @throws {FetchError} If the response is not OK.
4436
- * @internal
4437
- */
4438
- async function getRemoteDocument(url, response, fetch) {
4439
- const documentUrl = response.url === "" ? url : response.url;
4440
- const docUrl = new URL(documentUrl);
4441
- if (!response.ok) {
4442
- logger.error("Failed to fetch document: {status} {url} {headers}", {
4443
- status: response.status,
4444
- url: documentUrl,
4445
- headers: Object.fromEntries(response.headers.entries())
4446
- });
4447
- throw new FetchError(documentUrl, `HTTP ${response.status}: ${documentUrl}`, response.clone());
4448
- }
4449
- const contentType = response.headers.get("Content-Type");
4450
- const jsonLd = contentType == null || contentType === "application/activity+json" || contentType.startsWith("application/activity+json;") || contentType === "application/ld+json" || contentType.startsWith("application/ld+json;");
4451
- const linkHeader = response.headers.get("Link");
4452
- let contextUrl = null;
4453
- if (linkHeader != null) {
4454
- let link;
4455
- try {
4456
- link = new HttpHeaderLink(linkHeader);
4457
- } catch (e) {
4458
- if (e instanceof SyntaxError) link = new HttpHeaderLink();
4459
- else throw e;
4460
- }
4461
- if (jsonLd) {
4462
- const entries = link.getByRel("http://www.w3.org/ns/json-ld#context");
4463
- for (const [uri, params] of entries) if ("type" in params && params.type === "application/ld+json") {
4464
- contextUrl = uri;
4465
- break;
4466
- }
4467
- } else {
4468
- const entries = link.getByRel("alternate");
4469
- for (const [uri, params] of entries) {
4470
- const altUri = new URL(uri, docUrl);
4471
- if ("type" in params && (params.type === "application/activity+json" || params.type === "application/ld+json" || params.type.startsWith("application/ld+json;")) && altUri.href !== docUrl.href) {
4472
- logger.debug("Found alternate document: {alternateUrl} from {url}", {
4473
- alternateUrl: altUri.href,
4474
- url: documentUrl
4475
- });
4476
- return await fetch(altUri.href);
4477
- }
4478
- }
4479
- }
4480
- }
4481
- let document;
4482
- if (!jsonLd && (contentType === "text/html" || contentType?.startsWith("text/html;") || contentType === "application/xhtml+xml" || contentType?.startsWith("application/xhtml+xml;"))) {
4483
- const errorResponse = createResponseMetadata(response);
4484
- const html = await readBoundedText(response, MAX_HTML_SIZE);
4485
- if (html.tooLarge) {
4486
- logger.warn("HTML response too large, skipping alternate link discovery: {url}", {
4487
- url: documentUrl,
4488
- size: html.size
4489
- });
4490
- throw new FetchError(documentUrl, `HTML document is too large to scan for an ActivityPub alternate link (Content-Type: ${contentType})`, errorResponse);
4491
- } else {
4492
- const tagPattern = /<(a|link)\s+([^>]*?)\s*\/?>/gi;
4493
- const attrPattern = /([a-z][a-z:_-]*)=(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi;
4494
- let tagMatch;
4495
- while ((tagMatch = tagPattern.exec(html.text)) !== null) {
4496
- const tagContent = tagMatch[2];
4497
- let attrMatch;
4498
- const attribs = {};
4499
- attrPattern.lastIndex = 0;
4500
- while ((attrMatch = attrPattern.exec(tagContent)) !== null) {
4501
- const key = attrMatch[1].toLowerCase();
4502
- attribs[key] = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4] ?? "";
4503
- }
4504
- if (attribs.rel === "alternate" && "type" in attribs && (attribs.type === "application/activity+json" || attribs.type === "application/ld+json" || attribs.type.startsWith("application/ld+json;")) && "href" in attribs && new URL(attribs.href, docUrl).href !== docUrl.href) {
4505
- logger.debug("Found alternate document: {alternateUrl} from {url}", {
4506
- alternateUrl: attribs.href,
4507
- url: documentUrl
4508
- });
4509
- return await fetch(new URL(attribs.href, docUrl).href);
4510
- }
4511
- }
4512
- try {
4513
- document = JSON.parse(html.text);
4514
- } catch (error) {
4515
- if (!(error instanceof SyntaxError)) throw error;
4516
- throw new FetchError(documentUrl, `HTML document has no ActivityPub alternate link (Content-Type: ${contentType})`, errorResponse);
4517
- }
4518
- }
4519
- } else document = await response.json();
4520
- logger.debug("Fetched document: {status} {url} {headers}", {
4521
- status: response.status,
4522
- url: documentUrl,
4523
- headers: Object.fromEntries(response.headers.entries())
4524
- });
4525
- return {
4526
- contextUrl,
4527
- document,
4528
- documentUrl
4529
- };
4530
- }
4531
- /**
4532
- * Creates a JSON-LD document loader that utilizes the browser's `fetch` API.
4533
- *
4534
- * The created loader preloads the below frequently used contexts by default
4535
- * (unless `options.skipPreloadedContexts` is set to `true`):
4536
- *
4537
- * - <https://www.w3.org/ns/activitystreams>
4538
- * - <https://w3id.org/security/v1>
4539
- * - <https://w3id.org/security/data-integrity/v1>
4540
- * - <https://w3id.org/security/data-integrity/v2>
4541
- * - <https://www.w3.org/ns/did/v1>
4542
- * - <https://w3id.org/security/multikey/v1>
4543
- * - <https://w3id.org/fep/ef61>
4544
- * - <https://purl.archive.org/socialweb/webfinger>
4545
- * - <http://schema.org/>
4546
- * @param options Options for the document loader.
4547
- * @returns The document loader.
4548
- * @since 1.3.0
4549
- */
4550
- function getDocumentLoader({ allowPrivateAddress, maxRedirection, skipPreloadedContexts, userAgent } = {}) {
4551
- const tracer = trace.getTracerProvider().getTracer(name, version);
4552
- const maximumRedirection = maxRedirection ?? DEFAULT_MAX_REDIRECTION;
4553
- async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
4554
- options?.signal?.throwIfAborted();
4555
- const currentUrl = new URL(url).href;
4556
- if (!skipPreloadedContexts && currentUrl in preloadedContexts) {
4557
- logger.debug("Using preloaded context: {url}.", { url: currentUrl });
4558
- return {
4559
- contextUrl: null,
4560
- document: preloadedContexts[currentUrl],
4561
- documentUrl: currentUrl
4562
- };
4563
- }
4564
- if (!allowPrivateAddress) try {
4565
- await validatePublicUrl(currentUrl);
4566
- } catch (error) {
4567
- if (error instanceof UrlError) logger.error("Disallowed private URL: {url}", {
4568
- url: currentUrl,
4569
- error
4570
- });
4571
- throw error;
4572
- }
4573
- visited.add(currentUrl);
4574
- return await tracer.startActiveSpan("activitypub.fetch_document", {
4575
- kind: SpanKind.CLIENT,
4576
- attributes: { "url.full": currentUrl }
4577
- }, async (span) => {
4578
- try {
4579
- const request = createActivityPubRequest(currentUrl, { userAgent });
4580
- logRequest(logger, request);
4581
- const response = await fetch(request, {
4582
- redirect: "manual",
4583
- signal: options?.signal
4584
- });
4585
- span.setAttribute("http.response.status_code", response.status);
4586
- if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
4587
- if (redirected >= maximumRedirection) {
4588
- logger.error("Too many redirections ({redirections}) while fetching document.", {
4589
- redirections: redirected + 1,
4590
- url: currentUrl
4591
- });
4592
- throw new FetchError(currentUrl, `Too many redirections (${redirected + 1})`);
4593
- }
4594
- const redirectUrl = new URL(response.headers.get("Location"), response.url === "" ? currentUrl : response.url).href;
4595
- span.setAttribute("http.redirect.url", redirectUrl);
4596
- if (visited.has(redirectUrl)) {
4597
- logger.error("Detected a redirect loop while fetching document: {url} -> {redirectUrl}", {
4598
- url: currentUrl,
4599
- redirectUrl
4600
- });
4601
- throw new FetchError(currentUrl, `Redirect loop detected: ${redirectUrl}`);
4602
- }
4603
- return await load(redirectUrl, options, redirected + 1, visited);
4604
- }
4605
- const result = await getRemoteDocument(currentUrl, response, load);
4606
- span.setAttribute("docloader.document_url", result.documentUrl);
4607
- if (result.contextUrl != null) span.setAttribute("docloader.context_url", result.contextUrl);
4608
- return result;
4609
- } catch (error) {
4610
- span.recordException(error);
4611
- span.setStatus({
4612
- code: SpanStatusCode.ERROR,
4613
- message: String(error)
4614
- });
4615
- throw error;
4616
- } finally {
4617
- span.end();
4618
- }
4619
- });
4620
- }
4621
- return load;
4622
- }
4623
- //#endregion
4624
- export { getRemoteDocument as n, preloadedContexts as r, getDocumentLoader as t };
4523
+ });