@fedify/vocab-runtime 2.4.0-dev.1570 → 2.4.0-dev.1573

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 (48) hide show
  1. package/deno.json +2 -1
  2. package/dist/docloader-DnUMWHaJ.d.cts +202 -0
  3. package/dist/docloader-xRGn1azD.d.ts +202 -0
  4. package/dist/internal/jsonld-cache.cjs +279 -0
  5. package/dist/internal/jsonld-cache.d.cts +48 -0
  6. package/dist/internal/jsonld-cache.d.ts +48 -0
  7. package/dist/internal/jsonld-cache.js +275 -0
  8. package/dist/mod.cjs +178 -190
  9. package/dist/mod.d.cts +59 -190
  10. package/dist/mod.d.ts +59 -190
  11. package/dist/mod.js +165 -184
  12. package/dist/tests/decimal.test.cjs +3 -3
  13. package/dist/tests/decimal.test.mjs +3 -3
  14. package/dist/tests/{docloader-C76ldE5C.mjs → docloader-B5Upa3Ox.mjs} +97 -10
  15. package/dist/tests/{docloader-mvgIWKI7.cjs → docloader-C69O-D5T.cjs} +102 -9
  16. package/dist/tests/docloader.test.cjs +58 -6
  17. package/dist/tests/docloader.test.mjs +58 -6
  18. package/dist/tests/jsonld-cache.test.cjs +652 -0
  19. package/dist/tests/jsonld-cache.test.d.cts +1 -0
  20. package/dist/tests/jsonld-cache.test.d.mts +1 -0
  21. package/dist/tests/jsonld-cache.test.mjs +651 -0
  22. package/dist/tests/{key-CrrK9mYh.mjs → key-CDGDH_vC.mjs} +69 -1
  23. package/dist/tests/{key-pMmqUKuo.cjs → key-_wXwomh_.cjs} +86 -0
  24. package/dist/tests/key.test.cjs +48 -1
  25. package/dist/tests/key.test.mjs +48 -1
  26. package/dist/tests/{request-BEXkv1ul.mjs → request-BGoZTy5L.mjs} +1 -1
  27. package/dist/tests/{request-SworbvLc.cjs → request-DX4gki5x.cjs} +1 -1
  28. package/dist/tests/request.test.cjs +1 -1
  29. package/dist/tests/request.test.mjs +1 -1
  30. package/dist/tests/{url-C20FhC7p.cjs → url-2XwVbUS_.cjs} +108 -0
  31. package/dist/tests/{url-m9Qzxy-Y.mjs → url-YWJbnRlf.mjs} +85 -1
  32. package/dist/tests/url.test.cjs +104 -1
  33. package/dist/tests/url.test.mjs +105 -2
  34. package/dist/url-BAdyyqAa.cjs +315 -0
  35. package/dist/url-BuxPHxK2.js +261 -0
  36. package/package.json +11 -1
  37. package/src/contexts/fep-7aa9.json +24 -0
  38. package/src/contexts.ts +2 -0
  39. package/src/docloader.test.ts +102 -6
  40. package/src/docloader.ts +76 -8
  41. package/src/internal/jsonld-cache.ts +538 -0
  42. package/src/jsonld-cache.test.ts +554 -0
  43. package/src/key.test.ts +86 -0
  44. package/src/key.ts +125 -0
  45. package/src/mod.ts +8 -0
  46. package/src/url.test.ts +252 -1
  47. package/src/url.ts +141 -0
  48. package/tsdown.config.ts +6 -1
@@ -1,8 +1,111 @@
1
1
  require("./chunk-C2EiDwsr.cjs");
2
- const require_url = require("./url-C20FhC7p.cjs");
2
+ const require_url = require("./url-2XwVbUS_.cjs");
3
3
  let node_assert = require("node:assert");
4
4
  let node_test = require("node:test");
5
5
  //#region src/url.test.ts
6
+ (0, node_test.test)("parseIri() accepts portable ActivityPub URI schemes", () => {
7
+ for (const iri of [
8
+ "ap://did:key:z6Mkabc/actor",
9
+ "ap://did%3Akey%3Az6Mkabc/actor",
10
+ "ap+ef61://did:key:z6Mkabc/actor",
11
+ "ap+ef61://did%3Akey%3Az6Mkabc/actor",
12
+ "AP+EF61://did:key:z6Mkabc/actor"
13
+ ]) (0, node_assert.deepStrictEqual)(require_url.parseIri(iri), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
14
+ });
15
+ (0, node_test.test)("parseIri() accepts DID schemes case-insensitively", () => {
16
+ for (const iri of ["ap://DID:key:z6Mkabc/actor", "ap://DID%3Akey%3Az6Mkabc/actor"]) (0, node_assert.deepStrictEqual)(require_url.parseIri(iri), new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"));
17
+ });
18
+ (0, node_test.test)("parseIri() accepts DID method names that start with digits", () => {
19
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("ap://did:3:abc/actor"), new URL("ap+ef61://did%3A3%3Aabc/actor"));
20
+ });
21
+ (0, node_test.test)("parseIri() accepts hyphens in DID method-specific IDs", () => {
22
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("ap+ef61://did:web:foo-bar.example/actor"), new URL("ap+ef61://did%3Aweb%3Afoo-bar.example/actor"));
23
+ });
24
+ (0, node_test.test)("parseIri() preserves existing URL parsing behavior", () => {
25
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("/actor", new URL("https://example.com/users/alice")), new URL("https://example.com/actor"));
26
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("at://did:plc:example/record"), new URL("at://did%3Aplc%3Aexample/record"));
27
+ (0, node_assert.throws)(() => require_url.parseIri("ap://not-a-did/actor"), TypeError);
28
+ });
29
+ (0, node_test.test)("parseJsonLdId() parses JSON-LD ids", () => {
30
+ (0, node_assert.deepStrictEqual)(require_url.parseJsonLdId(void 0), void 0);
31
+ (0, node_assert.deepStrictEqual)(require_url.parseJsonLdId("_:blank"), void 0);
32
+ (0, node_assert.deepStrictEqual)(require_url.parseJsonLdId("/actor", new URL("https://example.com/users/alice")), new URL("https://example.com/actor"));
33
+ (0, node_assert.deepStrictEqual)(require_url.parseJsonLdId("ap://did:key:z6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
34
+ (0, node_assert.throws)(() => require_url.parseJsonLdId("/actor"), {
35
+ name: "TypeError",
36
+ message: "Invalid @id: /actor"
37
+ });
38
+ });
39
+ (0, node_test.test)("parseIri() resolves relative IRIs against portable string bases", () => {
40
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("/actor", "ap://did:key:z6Mkabc/objects/1"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
41
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("attachments/1", "ap://did:key:z6Mkabc/objects/1"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/objects/attachments/1"));
42
+ (0, node_assert.throws)(() => require_url.parseIri("//example.com/outbox", "ap://did:key:z6Mkabc/objects/1"), TypeError);
43
+ });
44
+ (0, node_test.test)("parseIri() resolves relative IRIs against at:// string bases", () => {
45
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("/record", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/record"));
46
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("reply", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/collection/reply"));
47
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("reply", "at://did%3Aplc%3Aexample/collection/item"), new URL("at://did%3Aplc%3Aexample/collection/reply"));
48
+ });
49
+ (0, node_test.test)("parseIri() rejects portable IRIs without paths", () => {
50
+ (0, node_assert.throws)(() => require_url.parseIri("ap://did:key:z6Mkabc"), TypeError);
51
+ (0, node_assert.throws)(() => require_url.parseIri("ap://did:key:z6Mkabc?gateways=https%3A%2F%2Fserver.example"), TypeError);
52
+ (0, node_assert.throws)(() => require_url.parseIri("ap://did:key:z6Mkabc#actor"), TypeError);
53
+ });
54
+ (0, node_test.test)("parseIri() rejects malformed portable DID authorities", () => {
55
+ for (const iri of [
56
+ "ap://did:/actor",
57
+ "ap://did:key/actor",
58
+ "ap://did%3Akey%3Aabc%25zz/actor",
59
+ "ap://did:key:abc%25zz/actor"
60
+ ]) (0, node_assert.throws)(() => require_url.parseIri(iri), TypeError);
61
+ });
62
+ (0, node_test.test)("haveSameIriOrigin() compares portable IRI authorities", () => {
63
+ (0, node_assert.ok)(require_url.haveSameIriOrigin(require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkabc/outbox")));
64
+ (0, node_assert.ok)(require_url.haveSameIriOrigin(new URL("ap://did%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
65
+ (0, node_assert.ok)(require_url.haveSameIriOrigin(require_url.parseIri("ap://DID:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkabc/outbox")));
66
+ (0, node_assert.ok)(require_url.haveSameIriOrigin(new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
67
+ (0, node_assert.ok)(!require_url.haveSameIriOrigin(require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkdef/actor")));
68
+ });
69
+ (0, node_test.test)("parseIri() normalizes portable URL instances", () => {
70
+ (0, node_assert.deepStrictEqual)(require_url.parseIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
71
+ (0, node_assert.throws)(() => require_url.parseIri("ap+ef61://not-a-did/actor"), TypeError);
72
+ });
73
+ (0, node_test.test)("formatIri() emits canonical portable ActivityPub URI syntax", () => {
74
+ const cases = [new URL("ap://did%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor")];
75
+ for (const iri of cases) (0, node_assert.deepStrictEqual)(require_url.formatIri(iri), "ap+ef61://did:key:z6Mkabc/actor");
76
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(new URL("https://example.com/actor")), "https://example.com/actor");
77
+ (0, node_assert.deepStrictEqual)(require_url.formatIri("/actor"), "/actor");
78
+ });
79
+ (0, node_test.test)("formatIri() preserves DID authority pct-encoded delimiters", () => {
80
+ const parsed = require_url.parseIri("ap://did:example:abc%2Fdef/actor");
81
+ (0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
82
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:example:abc%2Fdef/actor");
83
+ (0, node_assert.deepStrictEqual)(require_url.parseIri(require_url.formatIri(parsed)), parsed);
84
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), "ap+ef61://did:example:abc%2Fdef/actor");
85
+ });
86
+ (0, node_test.test)("parseIri() normalizes equivalent encoded DID authorities", () => {
87
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("ap://did:example:abc%252Fdef/actor"), require_url.parseIri("ap://did%3Aexample%3Aabc%252Fdef/actor"));
88
+ });
89
+ (0, node_test.test)("formatIri() preserves DID-internal pct-encoded authority characters", () => {
90
+ const parsed = require_url.parseIri("ap://did:web:example.com%3A3000/actor");
91
+ (0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/actor"));
92
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/actor");
93
+ });
94
+ (0, node_test.test)("parseIri() accepts portable DID URLs with encoded DID delimiters", () => {
95
+ const parsed = require_url.parseIri("ap://did:web:example.com%3A3000/u/1");
96
+ (0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"));
97
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/u/1");
98
+ });
99
+ (0, node_test.test)("parseIri() decodes pct-encoded DID delimiters in order", () => {
100
+ const parsed = require_url.parseIri("ap://did%3Aweb%3Aexample.com%253A3000/u/1");
101
+ (0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"));
102
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/u/1");
103
+ });
104
+ (0, node_test.test)("parseIri() preserves encoded percent signs while decoding delimiters", () => {
105
+ const parsed = require_url.parseIri("ap://did%3Aweb%3Aexample.com%2500/u/1");
106
+ (0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%2500/u/1"));
107
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:web:example.com%00/u/1");
108
+ });
6
109
  (0, node_test.test)("validatePublicUrl()", async () => {
7
110
  await (0, node_assert.rejects)(() => require_url.validatePublicUrl("ftp://localhost"), require_url.UrlError);
8
111
  await (0, node_assert.rejects)(() => require_url.validatePublicUrl("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="), require_url.UrlError);
@@ -1,7 +1,110 @@
1
- import { a as validatePublicUrl, i as isValidPublicIPv6Address, n as expandIPv6Address, r as isValidPublicIPv4Address, t as UrlError } from "./url-m9Qzxy-Y.mjs";
2
- import { deepStrictEqual, ok, rejects } from "node:assert";
1
+ import { a as isValidPublicIPv4Address, c as parseJsonLdId, i as haveSameIriOrigin, l as validatePublicUrl, n as expandIPv6Address, o as isValidPublicIPv6Address, r as formatIri, s as parseIri, t as UrlError } from "./url-YWJbnRlf.mjs";
2
+ import { deepStrictEqual, ok, rejects, throws } from "node:assert";
3
3
  import { test } from "node:test";
4
4
  //#region src/url.test.ts
5
+ test("parseIri() accepts portable ActivityPub URI schemes", () => {
6
+ for (const iri of [
7
+ "ap://did:key:z6Mkabc/actor",
8
+ "ap://did%3Akey%3Az6Mkabc/actor",
9
+ "ap+ef61://did:key:z6Mkabc/actor",
10
+ "ap+ef61://did%3Akey%3Az6Mkabc/actor",
11
+ "AP+EF61://did:key:z6Mkabc/actor"
12
+ ]) deepStrictEqual(parseIri(iri), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
13
+ });
14
+ test("parseIri() accepts DID schemes case-insensitively", () => {
15
+ for (const iri of ["ap://DID:key:z6Mkabc/actor", "ap://DID%3Akey%3Az6Mkabc/actor"]) deepStrictEqual(parseIri(iri), new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"));
16
+ });
17
+ test("parseIri() accepts DID method names that start with digits", () => {
18
+ deepStrictEqual(parseIri("ap://did:3:abc/actor"), new URL("ap+ef61://did%3A3%3Aabc/actor"));
19
+ });
20
+ test("parseIri() accepts hyphens in DID method-specific IDs", () => {
21
+ deepStrictEqual(parseIri("ap+ef61://did:web:foo-bar.example/actor"), new URL("ap+ef61://did%3Aweb%3Afoo-bar.example/actor"));
22
+ });
23
+ test("parseIri() preserves existing URL parsing behavior", () => {
24
+ deepStrictEqual(parseIri("/actor", new URL("https://example.com/users/alice")), new URL("https://example.com/actor"));
25
+ deepStrictEqual(parseIri("at://did:plc:example/record"), new URL("at://did%3Aplc%3Aexample/record"));
26
+ throws(() => parseIri("ap://not-a-did/actor"), TypeError);
27
+ });
28
+ test("parseJsonLdId() parses JSON-LD ids", () => {
29
+ deepStrictEqual(parseJsonLdId(void 0), void 0);
30
+ deepStrictEqual(parseJsonLdId("_:blank"), void 0);
31
+ deepStrictEqual(parseJsonLdId("/actor", new URL("https://example.com/users/alice")), new URL("https://example.com/actor"));
32
+ deepStrictEqual(parseJsonLdId("ap://did:key:z6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
33
+ throws(() => parseJsonLdId("/actor"), {
34
+ name: "TypeError",
35
+ message: "Invalid @id: /actor"
36
+ });
37
+ });
38
+ test("parseIri() resolves relative IRIs against portable string bases", () => {
39
+ deepStrictEqual(parseIri("/actor", "ap://did:key:z6Mkabc/objects/1"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
40
+ deepStrictEqual(parseIri("attachments/1", "ap://did:key:z6Mkabc/objects/1"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/objects/attachments/1"));
41
+ throws(() => parseIri("//example.com/outbox", "ap://did:key:z6Mkabc/objects/1"), TypeError);
42
+ });
43
+ test("parseIri() resolves relative IRIs against at:// string bases", () => {
44
+ deepStrictEqual(parseIri("/record", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/record"));
45
+ deepStrictEqual(parseIri("reply", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/collection/reply"));
46
+ deepStrictEqual(parseIri("reply", "at://did%3Aplc%3Aexample/collection/item"), new URL("at://did%3Aplc%3Aexample/collection/reply"));
47
+ });
48
+ test("parseIri() rejects portable IRIs without paths", () => {
49
+ throws(() => parseIri("ap://did:key:z6Mkabc"), TypeError);
50
+ throws(() => parseIri("ap://did:key:z6Mkabc?gateways=https%3A%2F%2Fserver.example"), TypeError);
51
+ throws(() => parseIri("ap://did:key:z6Mkabc#actor"), TypeError);
52
+ });
53
+ test("parseIri() rejects malformed portable DID authorities", () => {
54
+ for (const iri of [
55
+ "ap://did:/actor",
56
+ "ap://did:key/actor",
57
+ "ap://did%3Akey%3Aabc%25zz/actor",
58
+ "ap://did:key:abc%25zz/actor"
59
+ ]) throws(() => parseIri(iri), TypeError);
60
+ });
61
+ test("haveSameIriOrigin() compares portable IRI authorities", () => {
62
+ ok(haveSameIriOrigin(parseIri("ap://did:key:z6Mkabc/actor"), parseIri("ap://did:key:z6Mkabc/outbox")));
63
+ ok(haveSameIriOrigin(new URL("ap://did%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
64
+ ok(haveSameIriOrigin(parseIri("ap://DID:key:z6Mkabc/actor"), parseIri("ap://did:key:z6Mkabc/outbox")));
65
+ ok(haveSameIriOrigin(new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
66
+ ok(!haveSameIriOrigin(parseIri("ap://did:key:z6Mkabc/actor"), parseIri("ap://did:key:z6Mkdef/actor")));
67
+ });
68
+ test("parseIri() normalizes portable URL instances", () => {
69
+ deepStrictEqual(parseIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
70
+ throws(() => parseIri("ap+ef61://not-a-did/actor"), TypeError);
71
+ });
72
+ test("formatIri() emits canonical portable ActivityPub URI syntax", () => {
73
+ const cases = [new URL("ap://did%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor")];
74
+ for (const iri of cases) deepStrictEqual(formatIri(iri), "ap+ef61://did:key:z6Mkabc/actor");
75
+ deepStrictEqual(formatIri(new URL("https://example.com/actor")), "https://example.com/actor");
76
+ deepStrictEqual(formatIri("/actor"), "/actor");
77
+ });
78
+ test("formatIri() preserves DID authority pct-encoded delimiters", () => {
79
+ const parsed = parseIri("ap://did:example:abc%2Fdef/actor");
80
+ deepStrictEqual(parsed, new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
81
+ deepStrictEqual(formatIri(parsed), "ap+ef61://did:example:abc%2Fdef/actor");
82
+ deepStrictEqual(parseIri(formatIri(parsed)), parsed);
83
+ deepStrictEqual(formatIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), "ap+ef61://did:example:abc%2Fdef/actor");
84
+ });
85
+ test("parseIri() normalizes equivalent encoded DID authorities", () => {
86
+ deepStrictEqual(parseIri("ap://did:example:abc%252Fdef/actor"), parseIri("ap://did%3Aexample%3Aabc%252Fdef/actor"));
87
+ });
88
+ test("formatIri() preserves DID-internal pct-encoded authority characters", () => {
89
+ const parsed = parseIri("ap://did:web:example.com%3A3000/actor");
90
+ deepStrictEqual(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/actor"));
91
+ deepStrictEqual(formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/actor");
92
+ });
93
+ test("parseIri() accepts portable DID URLs with encoded DID delimiters", () => {
94
+ const parsed = parseIri("ap://did:web:example.com%3A3000/u/1");
95
+ deepStrictEqual(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"));
96
+ deepStrictEqual(formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/u/1");
97
+ });
98
+ test("parseIri() decodes pct-encoded DID delimiters in order", () => {
99
+ const parsed = parseIri("ap://did%3Aweb%3Aexample.com%253A3000/u/1");
100
+ deepStrictEqual(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"));
101
+ deepStrictEqual(formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/u/1");
102
+ });
103
+ test("parseIri() preserves encoded percent signs while decoding delimiters", () => {
104
+ const parsed = parseIri("ap://did%3Aweb%3Aexample.com%2500/u/1");
105
+ deepStrictEqual(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%2500/u/1"));
106
+ deepStrictEqual(formatIri(parsed), "ap+ef61://did:web:example.com%00/u/1");
107
+ });
5
108
  test("validatePublicUrl()", async () => {
6
109
  await rejects(() => validatePublicUrl("ftp://localhost"), UrlError);
7
110
  await rejects(() => validatePublicUrl("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="), UrlError);
@@ -0,0 +1,315 @@
1
+
2
+ require("./chunk-M78iaK0I.cjs");
3
+ let node_dns_promises = require("node:dns/promises");
4
+ let node_net = require("node:net");
5
+ //#region src/url.ts
6
+ var UrlError = class extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "UrlError";
10
+ }
11
+ };
12
+ const PORTABLE_IRI_PATTERN = /^(ap|ap\+ef61):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i;
13
+ const INVALID_PERCENT_ENCODING_PATTERN = /%(?![0-9A-Fa-f]{2})/;
14
+ const DID_SCHEME_PATTERN = /^did:/i;
15
+ const DID_PATTERN = /^did:[a-z0-9]+:[-A-Za-z0-9._%]+(?::[-A-Za-z0-9._%]+)*$/i;
16
+ /**
17
+ * Parses a JSON-LD `@id` value as an IRI.
18
+ */
19
+ function parseJsonLdId(id, base) {
20
+ if (id == null || id.startsWith("_:")) return void 0;
21
+ try {
22
+ return parseIri(id, base);
23
+ } catch {
24
+ throw new TypeError("Invalid @id: " + id);
25
+ }
26
+ }
27
+ /**
28
+ * Parses an IRI as a URL, including FEP-ef61 portable ActivityPub IRIs.
29
+ */
30
+ function parseIri(iri, base) {
31
+ if (iri instanceof URL) return normalizePortableUrl(iri) ?? new URL(iri.href);
32
+ const portable = parsePortableIri(iri);
33
+ if (portable != null) return portable;
34
+ base = normalizeBaseIri(base);
35
+ if (!URL.canParse(iri, base) && iri.startsWith("at://")) return parseAtUri(iri);
36
+ const parsed = new URL(iri, base);
37
+ return normalizePortableUrl(parsed) ?? parsed;
38
+ }
39
+ /**
40
+ * Formats a URL as an IRI, including FEP-ef61 portable ActivityPub IRIs.
41
+ */
42
+ function formatIri(iri) {
43
+ const parsed = parsePortableIri(iri instanceof URL ? iri.href : iri);
44
+ if (parsed == null) return iri instanceof URL ? iri.href : URL.canParse(iri) ? new URL(iri).href : iri;
45
+ return `ap+ef61://${decodePortableAuthority(parsed.host)}${parsed.pathname}${parsed.search}${parsed.hash}`;
46
+ }
47
+ /**
48
+ * Checks whether two IRIs have the same origin.
49
+ */
50
+ function haveSameIriOrigin(left, right) {
51
+ return getComparableIriOrigin(left) === getComparableIriOrigin(right);
52
+ }
53
+ function getComparableIriOrigin(iri) {
54
+ iri = normalizePortableUrl(iri) ?? iri;
55
+ if (iri.origin !== "null") return iri.origin;
56
+ if (iri.host !== "") {
57
+ const host = iri.protocol === "ap+ef61:" ? encodeURIComponent(decodePortableAuthority(iri.host).replace(DID_SCHEME_PATTERN, "did:")) : iri.host;
58
+ return `${iri.protocol}//${host}`;
59
+ }
60
+ return iri.href;
61
+ }
62
+ function parsePortableIri(iri) {
63
+ const match = iri.match(PORTABLE_IRI_PATTERN);
64
+ if (match == null) return null;
65
+ const authority = decodePortableAuthority(match[2]);
66
+ if (!DID_PATTERN.test(authority)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
67
+ if (match[3] === "") throw new TypeError("Invalid portable ActivityPub IRI path.");
68
+ return new URL(`ap+ef61://${encodeURIComponent(authority)}${match[3]}${match[4] ?? ""}${match[5] ?? ""}`);
69
+ }
70
+ function normalizePortableUrl(iri) {
71
+ if (iri.protocol !== "ap:" && iri.protocol !== "ap+ef61:") return null;
72
+ return parsePortableIri(`ap+ef61://${iri.host}${iri.pathname}${iri.search}${iri.hash}`);
73
+ }
74
+ function normalizeBaseIri(base) {
75
+ if (base == null) return void 0;
76
+ if (base instanceof URL) return normalizePortableUrl(base) ?? base;
77
+ return parsePortableIri(base) ?? (base.startsWith("at://") && !URL.canParse(".", base) ? parseAtUri(base) : base);
78
+ }
79
+ function decodePortableAuthority(authority) {
80
+ if (INVALID_PERCENT_ENCODING_PATTERN.test(authority)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
81
+ if (DID_SCHEME_PATTERN.test(authority)) {
82
+ const decoded = authority.replace(/%25/gi, "%");
83
+ if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
84
+ return decoded;
85
+ }
86
+ const decoded = authority.replace(/%(25|3A)/gi, (match) => match.toLowerCase() === "%3a" ? ":" : "%");
87
+ if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
88
+ return decoded;
89
+ }
90
+ function parseAtUri(uri) {
91
+ const index = uri.indexOf("/", 5);
92
+ const authority = index >= 0 ? uri.slice(5, index) : uri.slice(5);
93
+ const path = index >= 0 ? uri.slice(index) : "";
94
+ return new URL("at://" + encodeURIComponent(authority) + path);
95
+ }
96
+ /**
97
+ * Validates a URL to prevent SSRF attacks.
98
+ */
99
+ async function validatePublicUrl(url) {
100
+ const parsed = new URL(url);
101
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new UrlError(`Unsupported protocol: ${parsed.protocol}`);
102
+ let hostname = parsed.hostname;
103
+ if (hostname.startsWith("[") && hostname.endsWith("]")) hostname = hostname.slice(1, -1);
104
+ if (hostname === "localhost") throw new UrlError("Localhost is not allowed");
105
+ const hostnameFamily = (0, node_net.isIP)(hostname);
106
+ if (hostnameFamily !== 0) {
107
+ validatePublicIpAddress(hostname, hostnameFamily);
108
+ return;
109
+ }
110
+ if ("Deno" in globalThis && !(0, node_net.isIP)(hostname)) {
111
+ if ((await Deno.permissions.query({ name: "net" })).state !== "granted") return;
112
+ }
113
+ if ("Bun" in globalThis) {
114
+ if (hostname === "example.com" || hostname.endsWith(".example.com")) return;
115
+ else if (hostname === "fedify-test.internal") throw new UrlError("Invalid or private address: fedify-test.internal");
116
+ }
117
+ let addresses;
118
+ try {
119
+ addresses = await (0, node_dns_promises.lookup)(hostname, { all: true });
120
+ } catch {
121
+ addresses = [];
122
+ }
123
+ for (const { address, family } of addresses) validatePublicIpAddress(address, family);
124
+ }
125
+ function validatePublicIpAddress(address, family) {
126
+ if (family === 4 && isValidPublicIPv4Address(address) || family === 6 && isValidPublicIPv6Address(address)) return;
127
+ throw new UrlError(`Invalid or private address: ${address}`);
128
+ }
129
+ function isValidPublicIPv4Address(address) {
130
+ const parts = parseIPv4Address(address);
131
+ if (parts == null) return false;
132
+ const value = ipv4PartsToNumber(parts);
133
+ return !nonPublicIPv4Prefixes.some(({ base, prefix }) => matchesIPv4Prefix(value, base, prefix));
134
+ }
135
+ function isValidPublicIPv6Address(address) {
136
+ const words = parseIPv6Address(address);
137
+ if (words == null) return false;
138
+ if (nonPublicIPv6Prefixes.some(({ words: prefixWords, prefix }) => matchesIPv6Prefix(words, prefixWords, prefix))) return false;
139
+ for (const { extractIPv4, prefix, words: prefixWords } of ipv6WithIPv4Prefixes) {
140
+ if (!matchesIPv6Prefix(words, prefixWords, prefix)) continue;
141
+ const ipv4Address = extractIPv4(words);
142
+ if (ipv4Address != null && !isValidPublicIPv4Address(ipv4Address)) return false;
143
+ }
144
+ return true;
145
+ }
146
+ function expandIPv6Address(address) {
147
+ address = address.toLowerCase();
148
+ const ipv4Delimiter = address.lastIndexOf(":");
149
+ if (address.includes(".") && ipv4Delimiter >= 0) {
150
+ const ipv4Parts = parseIPv4Address(address.substring(ipv4Delimiter + 1));
151
+ if (ipv4Parts == null) return address;
152
+ const high = (ipv4Parts[0] << 8) + ipv4Parts[1];
153
+ const low = (ipv4Parts[2] << 8) + ipv4Parts[3];
154
+ address = address.substring(0, ipv4Delimiter + 1) + high.toString(16) + ":" + low.toString(16);
155
+ }
156
+ if (address === "::") return "0000:0000:0000:0000:0000:0000:0000:0000";
157
+ if (address.startsWith("::")) address = "0000" + address;
158
+ if (address.endsWith("::")) address = address + "0000";
159
+ address = address.replace("::", ":0000".repeat(8 - (address.match(/:/g) || []).length) + ":");
160
+ return address.split(":").map((part) => part.padStart(4, "0")).join(":");
161
+ }
162
+ const nonPublicIPv4Prefixes = [
163
+ ipv4Prefix("0.0.0.0/8", "RFC 6890"),
164
+ ipv4Prefix("10.0.0.0/8", "RFC 1918"),
165
+ ipv4Prefix("100.64.0.0/10", "RFC 6598"),
166
+ ipv4Prefix("127.0.0.0/8", "RFC 1122"),
167
+ ipv4Prefix("169.254.0.0/16", "RFC 3927"),
168
+ ipv4Prefix("172.16.0.0/12", "RFC 1918"),
169
+ ipv4Prefix("192.0.0.0/24", "RFC 6890"),
170
+ ipv4Prefix("192.0.2.0/24", "RFC 5737"),
171
+ ipv4Prefix("192.88.99.0/24", "RFC 7526"),
172
+ ipv4Prefix("192.168.0.0/16", "RFC 1918"),
173
+ ipv4Prefix("198.18.0.0/15", "RFC 2544"),
174
+ ipv4Prefix("198.51.100.0/24", "RFC 5737"),
175
+ ipv4Prefix("203.0.113.0/24", "RFC 5737"),
176
+ ipv4Prefix("224.0.0.0/4", "RFC 5771"),
177
+ ipv4Prefix("240.0.0.0/4", "RFC 1112")
178
+ ];
179
+ const nonPublicIPv6Prefixes = [
180
+ ipv6Prefix("::/16", "RFC 4291"),
181
+ ipv6Prefix("2001::/32", "RFC 4380"),
182
+ ipv6Prefix("2002::/16", "RFC 3056"),
183
+ ipv6Prefix("64:ff9b:1::/48", "RFC 8215"),
184
+ ipv6Prefix("fc00::/7", "RFC 4193"),
185
+ ipv6Prefix("fe80::/10", "RFC 4291"),
186
+ ipv6Prefix("ff00::/8", "RFC 4291")
187
+ ];
188
+ const ipv6WithIPv4Prefixes = [{
189
+ ...ipv6Prefix("64:ff9b::/96", "RFC 6052"),
190
+ extractIPv4: (words) => ipv4FromWords(words[6], words[7])
191
+ }];
192
+ function ipv4Prefix(cidr, rfc) {
193
+ const [address, prefixText] = cidr.split("/");
194
+ const prefix = parseInt(prefixText, 10);
195
+ const parts = parseIPv4Address(address);
196
+ if (parts == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 32) throw new Error(`Invalid IPv4 prefix: ${cidr}`);
197
+ return {
198
+ cidr,
199
+ base: ipv4PartsToNumber(parts),
200
+ prefix,
201
+ rfc
202
+ };
203
+ }
204
+ function ipv6Prefix(cidr, rfc) {
205
+ const [address, prefixText] = cidr.split("/");
206
+ const prefix = parseInt(prefixText, 10);
207
+ const words = parseIPv6Address(address);
208
+ if (words == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 128) throw new Error(`Invalid IPv6 prefix: ${cidr}`);
209
+ return {
210
+ cidr,
211
+ words,
212
+ prefix,
213
+ rfc
214
+ };
215
+ }
216
+ function parseIPv4Address(address) {
217
+ const parts = address.split(".").map((part) => {
218
+ if (!/^\d+$/.test(part)) return NaN;
219
+ return parseInt(part, 10);
220
+ });
221
+ if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) return null;
222
+ return parts;
223
+ }
224
+ function parseIPv6Address(address) {
225
+ const parts = expandIPv6Address(address).split(":");
226
+ if (parts.length !== 8) return null;
227
+ const words = parts.map((part) => {
228
+ if (!/^[0-9a-f]{1,4}$/i.test(part)) return NaN;
229
+ return parseInt(part, 16);
230
+ });
231
+ if (words.some((word) => !Number.isInteger(word) || word < 0 || word > 65535)) return null;
232
+ return words;
233
+ }
234
+ function ipv4PartsToNumber(parts) {
235
+ return parts[0] * 2 ** 24 + parts[1] * 2 ** 16 + parts[2] * 2 ** 8 + parts[3];
236
+ }
237
+ function ipv4FromWords(highWord, lowWord) {
238
+ return [
239
+ highWord >> 8,
240
+ highWord & 255,
241
+ lowWord >> 8,
242
+ lowWord & 255
243
+ ].join(".");
244
+ }
245
+ function matchesIPv4Prefix(address, prefixBase, prefixLength) {
246
+ const blockSize = 2 ** (32 - prefixLength);
247
+ return Math.floor(address / blockSize) === Math.floor(prefixBase / blockSize);
248
+ }
249
+ function matchesIPv6Prefix(address, prefixWords, prefixLength) {
250
+ let remaining = prefixLength;
251
+ for (let i = 0; i < 8 && remaining > 0; i++) if (remaining >= 16) {
252
+ if (address[i] !== prefixWords[i]) return false;
253
+ remaining -= 16;
254
+ } else {
255
+ const mask = 65535 << 16 - remaining & 65535;
256
+ if ((address[i] & mask) !== (prefixWords[i] & mask)) return false;
257
+ remaining = 0;
258
+ }
259
+ return true;
260
+ }
261
+ //#endregion
262
+ Object.defineProperty(exports, "UrlError", {
263
+ enumerable: true,
264
+ get: function() {
265
+ return UrlError;
266
+ }
267
+ });
268
+ Object.defineProperty(exports, "expandIPv6Address", {
269
+ enumerable: true,
270
+ get: function() {
271
+ return expandIPv6Address;
272
+ }
273
+ });
274
+ Object.defineProperty(exports, "formatIri", {
275
+ enumerable: true,
276
+ get: function() {
277
+ return formatIri;
278
+ }
279
+ });
280
+ Object.defineProperty(exports, "haveSameIriOrigin", {
281
+ enumerable: true,
282
+ get: function() {
283
+ return haveSameIriOrigin;
284
+ }
285
+ });
286
+ Object.defineProperty(exports, "isValidPublicIPv4Address", {
287
+ enumerable: true,
288
+ get: function() {
289
+ return isValidPublicIPv4Address;
290
+ }
291
+ });
292
+ Object.defineProperty(exports, "isValidPublicIPv6Address", {
293
+ enumerable: true,
294
+ get: function() {
295
+ return isValidPublicIPv6Address;
296
+ }
297
+ });
298
+ Object.defineProperty(exports, "parseIri", {
299
+ enumerable: true,
300
+ get: function() {
301
+ return parseIri;
302
+ }
303
+ });
304
+ Object.defineProperty(exports, "parseJsonLdId", {
305
+ enumerable: true,
306
+ get: function() {
307
+ return parseJsonLdId;
308
+ }
309
+ });
310
+ Object.defineProperty(exports, "validatePublicUrl", {
311
+ enumerable: true,
312
+ get: function() {
313
+ return validatePublicUrl;
314
+ }
315
+ });