@fedify/vocab-runtime 2.4.0-dev.1567 → 2.4.0-dev.1570
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.
- package/deno.json +1 -2
- package/dist/mod.cjs +190 -178
- package/dist/mod.d.cts +190 -59
- package/dist/mod.d.ts +190 -59
- package/dist/mod.js +184 -165
- package/dist/tests/decimal.test.cjs +3 -3
- package/dist/tests/decimal.test.mjs +3 -3
- package/dist/tests/{docloader-D61oV0K1.mjs → docloader-C76ldE5C.mjs} +10 -97
- package/dist/tests/{docloader-BcaQHb0Q.cjs → docloader-mvgIWKI7.cjs} +9 -102
- package/dist/tests/docloader.test.cjs +6 -58
- package/dist/tests/docloader.test.mjs +6 -58
- package/dist/tests/{key-CDGDH_vC.mjs → key-CrrK9mYh.mjs} +1 -69
- package/dist/tests/{key-_wXwomh_.cjs → key-pMmqUKuo.cjs} +0 -86
- package/dist/tests/key.test.cjs +1 -48
- package/dist/tests/key.test.mjs +1 -48
- package/dist/tests/{request-Cn0vP7Hj.mjs → request-BEXkv1ul.mjs} +1 -1
- package/dist/tests/{request-DnNWah97.cjs → request-SworbvLc.cjs} +1 -1
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.mjs +1 -1
- package/dist/tests/{url-2XwVbUS_.cjs → url-C20FhC7p.cjs} +0 -108
- package/dist/tests/{url-YWJbnRlf.mjs → url-m9Qzxy-Y.mjs} +1 -85
- package/dist/tests/url.test.cjs +1 -104
- package/dist/tests/url.test.mjs +2 -105
- package/package.json +1 -11
- package/src/contexts.ts +0 -2
- package/src/docloader.test.ts +6 -102
- package/src/docloader.ts +8 -76
- package/src/key.test.ts +0 -86
- package/src/key.ts +0 -125
- package/src/mod.ts +0 -8
- package/src/url.test.ts +1 -252
- package/src/url.ts +0 -141
- package/tsdown.config.ts +1 -6
- package/dist/docloader-DnUMWHaJ.d.cts +0 -202
- package/dist/docloader-xRGn1azD.d.ts +0 -202
- package/dist/internal/jsonld-cache.cjs +0 -279
- package/dist/internal/jsonld-cache.d.cts +0 -48
- package/dist/internal/jsonld-cache.d.ts +0 -48
- package/dist/internal/jsonld-cache.js +0 -275
- package/dist/tests/jsonld-cache.test.cjs +0 -652
- package/dist/tests/jsonld-cache.test.d.cts +0 -1
- package/dist/tests/jsonld-cache.test.d.mts +0 -1
- package/dist/tests/jsonld-cache.test.mjs +0 -651
- package/dist/url-BAdyyqAa.cjs +0 -315
- package/dist/url-BuxPHxK2.js +0 -261
- package/src/contexts/fep-7aa9.json +0 -24
- package/src/internal/jsonld-cache.ts +0 -538
- package/src/jsonld-cache.test.ts +0 -554
package/src/url.test.ts
CHANGED
|
@@ -1,264 +1,13 @@
|
|
|
1
|
-
import { deepStrictEqual, ok, rejects
|
|
1
|
+
import { deepStrictEqual, ok, rejects } from "node:assert";
|
|
2
2
|
import { test } from "node:test";
|
|
3
3
|
import {
|
|
4
4
|
expandIPv6Address,
|
|
5
|
-
formatIri,
|
|
6
|
-
haveSameIriOrigin,
|
|
7
5
|
isValidPublicIPv4Address,
|
|
8
6
|
isValidPublicIPv6Address,
|
|
9
|
-
parseIri,
|
|
10
|
-
parseJsonLdId,
|
|
11
7
|
UrlError,
|
|
12
8
|
validatePublicUrl,
|
|
13
9
|
} from "./url.ts";
|
|
14
10
|
|
|
15
|
-
test("parseIri() accepts portable ActivityPub URI schemes", () => {
|
|
16
|
-
const cases = [
|
|
17
|
-
"ap://did:key:z6Mkabc/actor",
|
|
18
|
-
"ap://did%3Akey%3Az6Mkabc/actor",
|
|
19
|
-
"ap+ef61://did:key:z6Mkabc/actor",
|
|
20
|
-
"ap+ef61://did%3Akey%3Az6Mkabc/actor",
|
|
21
|
-
"AP+EF61://did:key:z6Mkabc/actor",
|
|
22
|
-
];
|
|
23
|
-
for (const iri of cases) {
|
|
24
|
-
deepStrictEqual(
|
|
25
|
-
parseIri(iri),
|
|
26
|
-
new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"),
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("parseIri() accepts DID schemes case-insensitively", () => {
|
|
32
|
-
const cases = [
|
|
33
|
-
"ap://DID:key:z6Mkabc/actor",
|
|
34
|
-
"ap://DID%3Akey%3Az6Mkabc/actor",
|
|
35
|
-
];
|
|
36
|
-
for (const iri of cases) {
|
|
37
|
-
deepStrictEqual(
|
|
38
|
-
parseIri(iri),
|
|
39
|
-
new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"),
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("parseIri() accepts DID method names that start with digits", () => {
|
|
45
|
-
deepStrictEqual(
|
|
46
|
-
parseIri("ap://did:3:abc/actor"),
|
|
47
|
-
new URL("ap+ef61://did%3A3%3Aabc/actor"),
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("parseIri() accepts hyphens in DID method-specific IDs", () => {
|
|
52
|
-
deepStrictEqual(
|
|
53
|
-
parseIri("ap+ef61://did:web:foo-bar.example/actor"),
|
|
54
|
-
new URL("ap+ef61://did%3Aweb%3Afoo-bar.example/actor"),
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("parseIri() preserves existing URL parsing behavior", () => {
|
|
59
|
-
deepStrictEqual(
|
|
60
|
-
parseIri("/actor", new URL("https://example.com/users/alice")),
|
|
61
|
-
new URL("https://example.com/actor"),
|
|
62
|
-
);
|
|
63
|
-
deepStrictEqual(
|
|
64
|
-
parseIri("at://did:plc:example/record"),
|
|
65
|
-
new URL("at://did%3Aplc%3Aexample/record"),
|
|
66
|
-
);
|
|
67
|
-
throws(() => parseIri("ap://not-a-did/actor"), TypeError);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("parseJsonLdId() parses JSON-LD ids", () => {
|
|
71
|
-
deepStrictEqual(parseJsonLdId(undefined), undefined);
|
|
72
|
-
deepStrictEqual(parseJsonLdId("_:blank"), undefined);
|
|
73
|
-
deepStrictEqual(
|
|
74
|
-
parseJsonLdId("/actor", new URL("https://example.com/users/alice")),
|
|
75
|
-
new URL("https://example.com/actor"),
|
|
76
|
-
);
|
|
77
|
-
deepStrictEqual(
|
|
78
|
-
parseJsonLdId("ap://did:key:z6Mkabc/actor"),
|
|
79
|
-
new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"),
|
|
80
|
-
);
|
|
81
|
-
throws(() => parseJsonLdId("/actor"), {
|
|
82
|
-
name: "TypeError",
|
|
83
|
-
message: "Invalid @id: /actor",
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("parseIri() resolves relative IRIs against portable string bases", () => {
|
|
88
|
-
deepStrictEqual(
|
|
89
|
-
parseIri("/actor", "ap://did:key:z6Mkabc/objects/1"),
|
|
90
|
-
new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"),
|
|
91
|
-
);
|
|
92
|
-
deepStrictEqual(
|
|
93
|
-
parseIri("attachments/1", "ap://did:key:z6Mkabc/objects/1"),
|
|
94
|
-
new URL("ap+ef61://did%3Akey%3Az6Mkabc/objects/attachments/1"),
|
|
95
|
-
);
|
|
96
|
-
throws(
|
|
97
|
-
() => parseIri("//example.com/outbox", "ap://did:key:z6Mkabc/objects/1"),
|
|
98
|
-
TypeError,
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("parseIri() resolves relative IRIs against at:// string bases", () => {
|
|
103
|
-
deepStrictEqual(
|
|
104
|
-
parseIri("/record", "at://did:plc:example/collection/item"),
|
|
105
|
-
new URL("at://did%3Aplc%3Aexample/record"),
|
|
106
|
-
);
|
|
107
|
-
deepStrictEqual(
|
|
108
|
-
parseIri("reply", "at://did:plc:example/collection/item"),
|
|
109
|
-
new URL("at://did%3Aplc%3Aexample/collection/reply"),
|
|
110
|
-
);
|
|
111
|
-
deepStrictEqual(
|
|
112
|
-
parseIri("reply", "at://did%3Aplc%3Aexample/collection/item"),
|
|
113
|
-
new URL("at://did%3Aplc%3Aexample/collection/reply"),
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test("parseIri() rejects portable IRIs without paths", () => {
|
|
118
|
-
throws(() => parseIri("ap://did:key:z6Mkabc"), TypeError);
|
|
119
|
-
throws(
|
|
120
|
-
() =>
|
|
121
|
-
parseIri("ap://did:key:z6Mkabc?gateways=https%3A%2F%2Fserver.example"),
|
|
122
|
-
TypeError,
|
|
123
|
-
);
|
|
124
|
-
throws(() => parseIri("ap://did:key:z6Mkabc#actor"), TypeError);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test("parseIri() rejects malformed portable DID authorities", () => {
|
|
128
|
-
const cases = [
|
|
129
|
-
"ap://did:/actor",
|
|
130
|
-
"ap://did:key/actor",
|
|
131
|
-
"ap://did%3Akey%3Aabc%25zz/actor",
|
|
132
|
-
"ap://did:key:abc%25zz/actor",
|
|
133
|
-
];
|
|
134
|
-
for (const iri of cases) {
|
|
135
|
-
throws(() => parseIri(iri), TypeError);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
test("haveSameIriOrigin() compares portable IRI authorities", () => {
|
|
140
|
-
ok(haveSameIriOrigin(
|
|
141
|
-
parseIri("ap://did:key:z6Mkabc/actor"),
|
|
142
|
-
parseIri("ap://did:key:z6Mkabc/outbox"),
|
|
143
|
-
));
|
|
144
|
-
ok(haveSameIriOrigin(
|
|
145
|
-
new URL("ap://did%3Akey%3Az6Mkabc/actor"),
|
|
146
|
-
new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox"),
|
|
147
|
-
));
|
|
148
|
-
ok(haveSameIriOrigin(
|
|
149
|
-
parseIri("ap://DID:key:z6Mkabc/actor"),
|
|
150
|
-
parseIri("ap://did:key:z6Mkabc/outbox"),
|
|
151
|
-
));
|
|
152
|
-
ok(haveSameIriOrigin(
|
|
153
|
-
new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"),
|
|
154
|
-
new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox"),
|
|
155
|
-
));
|
|
156
|
-
ok(
|
|
157
|
-
!haveSameIriOrigin(
|
|
158
|
-
parseIri("ap://did:key:z6Mkabc/actor"),
|
|
159
|
-
parseIri("ap://did:key:z6Mkdef/actor"),
|
|
160
|
-
),
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test("parseIri() normalizes portable URL instances", () => {
|
|
165
|
-
deepStrictEqual(
|
|
166
|
-
parseIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")),
|
|
167
|
-
new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"),
|
|
168
|
-
);
|
|
169
|
-
throws(() => parseIri("ap+ef61://not-a-did/actor"), TypeError);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test("formatIri() emits canonical portable ActivityPub URI syntax", () => {
|
|
173
|
-
const cases = [
|
|
174
|
-
new URL("ap://did%3Akey%3Az6Mkabc/actor"),
|
|
175
|
-
new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"),
|
|
176
|
-
];
|
|
177
|
-
for (const iri of cases) {
|
|
178
|
-
deepStrictEqual(formatIri(iri), "ap+ef61://did:key:z6Mkabc/actor");
|
|
179
|
-
}
|
|
180
|
-
deepStrictEqual(
|
|
181
|
-
formatIri(new URL("https://example.com/actor")),
|
|
182
|
-
"https://example.com/actor",
|
|
183
|
-
);
|
|
184
|
-
deepStrictEqual(formatIri("/actor"), "/actor");
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
test("formatIri() preserves DID authority pct-encoded delimiters", () => {
|
|
188
|
-
const parsed = parseIri("ap://did:example:abc%2Fdef/actor");
|
|
189
|
-
deepStrictEqual(
|
|
190
|
-
parsed,
|
|
191
|
-
new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"),
|
|
192
|
-
);
|
|
193
|
-
deepStrictEqual(
|
|
194
|
-
formatIri(parsed),
|
|
195
|
-
"ap+ef61://did:example:abc%2Fdef/actor",
|
|
196
|
-
);
|
|
197
|
-
deepStrictEqual(
|
|
198
|
-
parseIri(formatIri(parsed)),
|
|
199
|
-
parsed,
|
|
200
|
-
);
|
|
201
|
-
deepStrictEqual(
|
|
202
|
-
formatIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")),
|
|
203
|
-
"ap+ef61://did:example:abc%2Fdef/actor",
|
|
204
|
-
);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
test("parseIri() normalizes equivalent encoded DID authorities", () => {
|
|
208
|
-
deepStrictEqual(
|
|
209
|
-
parseIri("ap://did:example:abc%252Fdef/actor"),
|
|
210
|
-
parseIri("ap://did%3Aexample%3Aabc%252Fdef/actor"),
|
|
211
|
-
);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test("formatIri() preserves DID-internal pct-encoded authority characters", () => {
|
|
215
|
-
const parsed = parseIri("ap://did:web:example.com%3A3000/actor");
|
|
216
|
-
deepStrictEqual(
|
|
217
|
-
parsed,
|
|
218
|
-
new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/actor"),
|
|
219
|
-
);
|
|
220
|
-
deepStrictEqual(
|
|
221
|
-
formatIri(parsed),
|
|
222
|
-
"ap+ef61://did:web:example.com%3A3000/actor",
|
|
223
|
-
);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
test("parseIri() accepts portable DID URLs with encoded DID delimiters", () => {
|
|
227
|
-
const parsed = parseIri("ap://did:web:example.com%3A3000/u/1");
|
|
228
|
-
deepStrictEqual(
|
|
229
|
-
parsed,
|
|
230
|
-
new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"),
|
|
231
|
-
);
|
|
232
|
-
deepStrictEqual(
|
|
233
|
-
formatIri(parsed),
|
|
234
|
-
"ap+ef61://did:web:example.com%3A3000/u/1",
|
|
235
|
-
);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
test("parseIri() decodes pct-encoded DID delimiters in order", () => {
|
|
239
|
-
const parsed = parseIri("ap://did%3Aweb%3Aexample.com%253A3000/u/1");
|
|
240
|
-
deepStrictEqual(
|
|
241
|
-
parsed,
|
|
242
|
-
new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"),
|
|
243
|
-
);
|
|
244
|
-
deepStrictEqual(
|
|
245
|
-
formatIri(parsed),
|
|
246
|
-
"ap+ef61://did:web:example.com%3A3000/u/1",
|
|
247
|
-
);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
test("parseIri() preserves encoded percent signs while decoding delimiters", () => {
|
|
251
|
-
const parsed = parseIri("ap://did%3Aweb%3Aexample.com%2500/u/1");
|
|
252
|
-
deepStrictEqual(
|
|
253
|
-
parsed,
|
|
254
|
-
new URL("ap+ef61://did%3Aweb%3Aexample.com%2500/u/1"),
|
|
255
|
-
);
|
|
256
|
-
deepStrictEqual(
|
|
257
|
-
formatIri(parsed),
|
|
258
|
-
"ap+ef61://did:web:example.com%00/u/1",
|
|
259
|
-
);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
11
|
test("validatePublicUrl()", async () => {
|
|
263
12
|
await rejects(() => validatePublicUrl("ftp://localhost"), UrlError);
|
|
264
13
|
await rejects(
|
package/src/url.ts
CHANGED
|
@@ -9,147 +9,6 @@ export class UrlError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const PORTABLE_IRI_PATTERN =
|
|
13
|
-
/^(ap|ap\+ef61):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i;
|
|
14
|
-
const INVALID_PERCENT_ENCODING_PATTERN = /%(?![0-9A-Fa-f]{2})/;
|
|
15
|
-
const DID_SCHEME_PATTERN = /^did:/i;
|
|
16
|
-
const DID_PATTERN = /^did:[a-z0-9]+:[-A-Za-z0-9._%]+(?::[-A-Za-z0-9._%]+)*$/i;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Parses a JSON-LD `@id` value as an IRI.
|
|
20
|
-
*/
|
|
21
|
-
export function parseJsonLdId(
|
|
22
|
-
id: string | undefined,
|
|
23
|
-
base?: string | URL,
|
|
24
|
-
): URL | undefined {
|
|
25
|
-
if (id == null || id.startsWith("_:")) return undefined;
|
|
26
|
-
try {
|
|
27
|
-
return parseIri(id, base);
|
|
28
|
-
} catch {
|
|
29
|
-
throw new TypeError("Invalid @id: " + id);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Parses an IRI as a URL, including FEP-ef61 portable ActivityPub IRIs.
|
|
35
|
-
*/
|
|
36
|
-
export function parseIri(iri: string | URL, base?: string | URL): URL {
|
|
37
|
-
if (iri instanceof URL) {
|
|
38
|
-
return normalizePortableUrl(iri) ?? new URL(iri.href);
|
|
39
|
-
}
|
|
40
|
-
const portable = parsePortableIri(iri);
|
|
41
|
-
if (portable != null) return portable;
|
|
42
|
-
base = normalizeBaseIri(base);
|
|
43
|
-
if (!URL.canParse(iri, base) && iri.startsWith("at://")) {
|
|
44
|
-
return parseAtUri(iri);
|
|
45
|
-
}
|
|
46
|
-
const parsed = new URL(iri, base);
|
|
47
|
-
return normalizePortableUrl(parsed) ?? parsed;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Formats a URL as an IRI, including FEP-ef61 portable ActivityPub IRIs.
|
|
52
|
-
*/
|
|
53
|
-
export function formatIri(iri: string | URL): string {
|
|
54
|
-
const parsed = parsePortableIri(iri instanceof URL ? iri.href : iri);
|
|
55
|
-
if (parsed == null) {
|
|
56
|
-
return iri instanceof URL
|
|
57
|
-
? iri.href
|
|
58
|
-
: URL.canParse(iri)
|
|
59
|
-
? new URL(iri).href
|
|
60
|
-
: iri;
|
|
61
|
-
}
|
|
62
|
-
const authority = decodePortableAuthority(parsed.host);
|
|
63
|
-
return `ap+ef61://${authority}${parsed.pathname}${parsed.search}${parsed.hash}`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Checks whether two IRIs have the same origin.
|
|
68
|
-
*/
|
|
69
|
-
export function haveSameIriOrigin(left: URL, right: URL): boolean {
|
|
70
|
-
return getComparableIriOrigin(left) === getComparableIriOrigin(right);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function getComparableIriOrigin(iri: URL): string {
|
|
74
|
-
iri = normalizePortableUrl(iri) ?? iri;
|
|
75
|
-
if (iri.origin !== "null") return iri.origin;
|
|
76
|
-
if (iri.host !== "") {
|
|
77
|
-
const host = iri.protocol === "ap+ef61:"
|
|
78
|
-
? encodeURIComponent(
|
|
79
|
-
decodePortableAuthority(iri.host).replace(DID_SCHEME_PATTERN, "did:"),
|
|
80
|
-
)
|
|
81
|
-
: iri.host;
|
|
82
|
-
return `${iri.protocol}//${host}`;
|
|
83
|
-
}
|
|
84
|
-
return iri.href;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function parsePortableIri(iri: string): URL | null {
|
|
88
|
-
const match = iri.match(PORTABLE_IRI_PATTERN);
|
|
89
|
-
if (match == null) return null;
|
|
90
|
-
// The readable ap://did:... authority form is not RFC 3986 compliant:
|
|
91
|
-
// colons are not valid in a URI reg-name authority. Keep accepting it for
|
|
92
|
-
// current FEP-ef61 interoperability, but normalize it to a percent-encoded
|
|
93
|
-
// URL authority internally. The ap: URI syntax may change later; see:
|
|
94
|
-
// https://bnewbold.leaflet.pub/3mph4hzvbdc2v
|
|
95
|
-
const authority = decodePortableAuthority(match[2]);
|
|
96
|
-
if (!DID_PATTERN.test(authority)) {
|
|
97
|
-
throw new TypeError("Invalid portable ActivityPub IRI authority.");
|
|
98
|
-
}
|
|
99
|
-
if (match[3] === "") {
|
|
100
|
-
throw new TypeError("Invalid portable ActivityPub IRI path.");
|
|
101
|
-
}
|
|
102
|
-
return new URL(
|
|
103
|
-
`ap+ef61://${encodeURIComponent(authority)}${match[3]}${match[4] ?? ""}${
|
|
104
|
-
match[5] ?? ""
|
|
105
|
-
}`,
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function normalizePortableUrl(iri: URL): URL | null {
|
|
110
|
-
if (iri.protocol !== "ap:" && iri.protocol !== "ap+ef61:") return null;
|
|
111
|
-
return parsePortableIri(
|
|
112
|
-
`ap+ef61://${iri.host}${iri.pathname}${iri.search}${iri.hash}`,
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function normalizeBaseIri(base?: string | URL): string | URL | undefined {
|
|
117
|
-
if (base == null) return undefined;
|
|
118
|
-
if (base instanceof URL) return normalizePortableUrl(base) ?? base;
|
|
119
|
-
return parsePortableIri(base) ??
|
|
120
|
-
(base.startsWith("at://") && !URL.canParse(".", base)
|
|
121
|
-
? parseAtUri(base)
|
|
122
|
-
: base);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function decodePortableAuthority(authority: string): string {
|
|
126
|
-
if (INVALID_PERCENT_ENCODING_PATTERN.test(authority)) {
|
|
127
|
-
throw new TypeError("Invalid portable ActivityPub IRI authority.");
|
|
128
|
-
}
|
|
129
|
-
if (DID_SCHEME_PATTERN.test(authority)) {
|
|
130
|
-
const decoded = authority.replace(/%25/gi, "%");
|
|
131
|
-
if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) {
|
|
132
|
-
throw new TypeError("Invalid portable ActivityPub IRI authority.");
|
|
133
|
-
}
|
|
134
|
-
return decoded;
|
|
135
|
-
}
|
|
136
|
-
const decoded = authority.replace(
|
|
137
|
-
/%(25|3A)/gi,
|
|
138
|
-
(match) => match.toLowerCase() === "%3a" ? ":" : "%",
|
|
139
|
-
);
|
|
140
|
-
if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) {
|
|
141
|
-
throw new TypeError("Invalid portable ActivityPub IRI authority.");
|
|
142
|
-
}
|
|
143
|
-
return decoded;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function parseAtUri(uri: string): URL {
|
|
147
|
-
const index = uri.indexOf("/", 5);
|
|
148
|
-
const authority = index >= 0 ? uri.slice(5, index) : uri.slice(5);
|
|
149
|
-
const path = index >= 0 ? uri.slice(index) : "";
|
|
150
|
-
return new URL("at://" + encodeURIComponent(authority) + path);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
12
|
/**
|
|
154
13
|
* Validates a URL to prevent SSRF attacks.
|
|
155
14
|
*/
|
package/tsdown.config.ts
CHANGED
|
@@ -4,12 +4,7 @@ import { defineConfig } from "tsdown";
|
|
|
4
4
|
|
|
5
5
|
export default [
|
|
6
6
|
defineConfig({
|
|
7
|
-
entry: [
|
|
8
|
-
"src/mod.ts",
|
|
9
|
-
"src/internal/jsonld-cache.ts",
|
|
10
|
-
"src/jsonld.ts",
|
|
11
|
-
"src/temporal.ts",
|
|
12
|
-
],
|
|
7
|
+
entry: ["src/mod.ts", "src/jsonld.ts", "src/temporal.ts"],
|
|
13
8
|
dts: { compilerOptions: { isolatedDeclarations: true, declaration: true } },
|
|
14
9
|
format: ["esm", "cjs"],
|
|
15
10
|
platform: "neutral",
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { Logger } from "@logtape/logtape";
|
|
3
|
-
|
|
4
|
-
//#region src/request.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Error thrown when fetching a JSON-LD document failed.
|
|
7
|
-
*/
|
|
8
|
-
declare class FetchError extends Error {
|
|
9
|
-
/**
|
|
10
|
-
* The URL that failed to fetch.
|
|
11
|
-
*/
|
|
12
|
-
url: URL;
|
|
13
|
-
/**
|
|
14
|
-
* The HTTP response that failed, if available.
|
|
15
|
-
*/
|
|
16
|
-
response?: Response;
|
|
17
|
-
/**
|
|
18
|
-
* Constructs a new `FetchError`.
|
|
19
|
-
*
|
|
20
|
-
* @param url The URL that failed to fetch.
|
|
21
|
-
* @param message Error message.
|
|
22
|
-
* @param response The failed HTTP response, if available.
|
|
23
|
-
*/
|
|
24
|
-
constructor(url: URL | string, message?: string, response?: Response);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Options for creating a request.
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
interface CreateRequestOptions {
|
|
31
|
-
userAgent?: GetUserAgentOptions | string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Creates a request for the given URL.
|
|
35
|
-
* @param url The URL to create the request for.
|
|
36
|
-
* @param options The options for the request.
|
|
37
|
-
* @returns The created request.
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
declare function createActivityPubRequest(url: string, options?: CreateRequestOptions): Request;
|
|
41
|
-
/**
|
|
42
|
-
* Options for making `User-Agent` string.
|
|
43
|
-
* @see {@link getUserAgent}
|
|
44
|
-
* @since 1.3.0
|
|
45
|
-
*/
|
|
46
|
-
interface GetUserAgentOptions {
|
|
47
|
-
/**
|
|
48
|
-
* An optional software name and version, e.g., `"Hollo/1.0.0"`.
|
|
49
|
-
*/
|
|
50
|
-
software?: string | null;
|
|
51
|
-
/**
|
|
52
|
-
* An optional URL to append to the user agent string.
|
|
53
|
-
* Usually the URL of the ActivityPub instance.
|
|
54
|
-
*/
|
|
55
|
-
url?: string | URL | null;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Gets the user agent string for the given application and URL.
|
|
59
|
-
* @param options The options for making the user agent string.
|
|
60
|
-
* @returns The user agent string.
|
|
61
|
-
* @since 1.3.0
|
|
62
|
-
*/
|
|
63
|
-
declare function getUserAgent({
|
|
64
|
-
software,
|
|
65
|
-
url
|
|
66
|
-
}?: GetUserAgentOptions): string;
|
|
67
|
-
/**
|
|
68
|
-
* Logs the request.
|
|
69
|
-
* @param request The request to log.
|
|
70
|
-
* @internal
|
|
71
|
-
*/
|
|
72
|
-
declare function logRequest(logger: Logger, request: Request): void;
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/docloader.d.ts
|
|
75
|
-
/**
|
|
76
|
-
* A remote JSON-LD document and its context fetched by
|
|
77
|
-
* a {@link DocumentLoader}.
|
|
78
|
-
*/
|
|
79
|
-
interface RemoteDocument {
|
|
80
|
-
/**
|
|
81
|
-
* The URL of the context document.
|
|
82
|
-
*/
|
|
83
|
-
contextUrl: string | null;
|
|
84
|
-
/**
|
|
85
|
-
* The fetched JSON-LD document.
|
|
86
|
-
*/
|
|
87
|
-
document: unknown;
|
|
88
|
-
/**
|
|
89
|
-
* The URL of the fetched document.
|
|
90
|
-
*/
|
|
91
|
-
documentUrl: string;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Options for {@link DocumentLoader}.
|
|
95
|
-
* @since 1.8.0
|
|
96
|
-
*/
|
|
97
|
-
interface DocumentLoaderOptions {
|
|
98
|
-
/**
|
|
99
|
-
* An `AbortSignal` for cancellation.
|
|
100
|
-
* @since 1.8.0
|
|
101
|
-
*/
|
|
102
|
-
signal?: AbortSignal;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* A JSON-LD document loader that fetches documents from the Web.
|
|
106
|
-
* @param url The URL of the document to load.
|
|
107
|
-
* @param options The options for the document loader.
|
|
108
|
-
* @returns The loaded remote document.
|
|
109
|
-
*/
|
|
110
|
-
type DocumentLoader = (url: string, options?: DocumentLoaderOptions) => Promise<RemoteDocument>;
|
|
111
|
-
/**
|
|
112
|
-
* A factory function that creates a {@link DocumentLoader} with options.
|
|
113
|
-
* @param options The options for the document loader.
|
|
114
|
-
* @returns The document loader.
|
|
115
|
-
* @since 1.4.0
|
|
116
|
-
*/
|
|
117
|
-
type DocumentLoaderFactory = (options?: DocumentLoaderFactoryOptions) => DocumentLoader;
|
|
118
|
-
/**
|
|
119
|
-
* Options for {@link DocumentLoaderFactory}.
|
|
120
|
-
* @see {@link DocumentLoaderFactory}
|
|
121
|
-
* @see {@link AuthenticatedDocumentLoaderFactory}
|
|
122
|
-
* @since 1.4.0
|
|
123
|
-
*/
|
|
124
|
-
interface DocumentLoaderFactoryOptions {
|
|
125
|
-
/**
|
|
126
|
-
* Whether to allow fetching private network addresses.
|
|
127
|
-
* Turned off by default.
|
|
128
|
-
* @default `false``
|
|
129
|
-
*/
|
|
130
|
-
allowPrivateAddress?: boolean;
|
|
131
|
-
/**
|
|
132
|
-
* Options for making `User-Agent` string.
|
|
133
|
-
* If a string is given, it is used as the `User-Agent` header value.
|
|
134
|
-
* If an object is given, it is passed to {@link getUserAgent} function.
|
|
135
|
-
*/
|
|
136
|
-
userAgent?: GetUserAgentOptions | string;
|
|
137
|
-
/**
|
|
138
|
-
* The maximum number of redirections to follow.
|
|
139
|
-
* @default `20`
|
|
140
|
-
* @since 2.2.0
|
|
141
|
-
*/
|
|
142
|
-
maxRedirection?: number;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* A factory function that creates an authenticated {@link DocumentLoader} for
|
|
146
|
-
* a given identity. This is used for fetching documents that require
|
|
147
|
-
* authentication.
|
|
148
|
-
* @param identity The identity to create the document loader for.
|
|
149
|
-
* The actor's key pair.
|
|
150
|
-
* @param options The options for the document loader.
|
|
151
|
-
* @returns The authenticated document loader.
|
|
152
|
-
* @since 0.4.0
|
|
153
|
-
*/
|
|
154
|
-
type AuthenticatedDocumentLoaderFactory = (identity: {
|
|
155
|
-
keyId: URL;
|
|
156
|
-
privateKey: CryptoKey;
|
|
157
|
-
}, options?: DocumentLoaderFactoryOptions) => DocumentLoader;
|
|
158
|
-
/**
|
|
159
|
-
* Gets a {@link RemoteDocument} from the given response.
|
|
160
|
-
* @param url The URL of the document to load.
|
|
161
|
-
* @param response The response to get the document from.
|
|
162
|
-
* @param fetch The function to fetch the document.
|
|
163
|
-
* @returns The loaded remote document.
|
|
164
|
-
* @throws {FetchError} If the response is not OK.
|
|
165
|
-
* @internal
|
|
166
|
-
*/
|
|
167
|
-
declare function getRemoteDocument(url: string, response: Response, fetch: (url: string, options?: DocumentLoaderOptions) => Promise<RemoteDocument>): Promise<RemoteDocument>;
|
|
168
|
-
/**
|
|
169
|
-
* Options for {@link getDocumentLoader}.
|
|
170
|
-
* @since 1.3.0
|
|
171
|
-
*/
|
|
172
|
-
interface GetDocumentLoaderOptions extends DocumentLoaderFactoryOptions {
|
|
173
|
-
/**
|
|
174
|
-
* Whether to preload the frequently used contexts.
|
|
175
|
-
*/
|
|
176
|
-
skipPreloadedContexts?: boolean;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Creates a JSON-LD document loader that utilizes the browser's `fetch` API.
|
|
180
|
-
*
|
|
181
|
-
* The created loader preloads the below frequently used contexts by default
|
|
182
|
-
* (unless `options.skipPreloadedContexts` is set to `true`):
|
|
183
|
-
*
|
|
184
|
-
* - <https://www.w3.org/ns/activitystreams>
|
|
185
|
-
* - <https://w3id.org/security/v1>
|
|
186
|
-
* - <https://w3id.org/security/data-integrity/v1>
|
|
187
|
-
* - <https://www.w3.org/ns/did/v1>
|
|
188
|
-
* - <https://w3id.org/security/multikey/v1>
|
|
189
|
-
* - <https://purl.archive.org/socialweb/webfinger>
|
|
190
|
-
* - <http://schema.org/>
|
|
191
|
-
* @param options Options for the document loader.
|
|
192
|
-
* @returns The document loader.
|
|
193
|
-
* @since 1.3.0
|
|
194
|
-
*/
|
|
195
|
-
declare function getDocumentLoader({
|
|
196
|
-
allowPrivateAddress,
|
|
197
|
-
maxRedirection,
|
|
198
|
-
skipPreloadedContexts,
|
|
199
|
-
userAgent
|
|
200
|
-
}?: GetDocumentLoaderOptions): DocumentLoader;
|
|
201
|
-
//#endregion
|
|
202
|
-
export { DocumentLoaderOptions as a, getDocumentLoader as c, FetchError as d, GetUserAgentOptions as f, logRequest as h, DocumentLoaderFactoryOptions as i, getRemoteDocument as l, getUserAgent as m, DocumentLoader as n, GetDocumentLoaderOptions as o, createActivityPubRequest as p, DocumentLoaderFactory as r, RemoteDocument as s, AuthenticatedDocumentLoaderFactory as t, CreateRequestOptions as u };
|