@fedify/fedify 2.0.0-pr.449.1725 → 2.0.0-pr.451.1731
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/dist/{actor-C0gLJq8I.js → actor-CRQwUlsr.js} +190 -677
- package/dist/{actor-T6RyhRgk.d.ts → actor-Cd2CREO0.d.ts} +2 -2
- package/dist/{actor-CsRJa7wV.cjs → actor-Ci-5y3ml.cjs} +922 -1451
- package/dist/{actor-D6K058Tb.d.cts → actor-DDhZuMGl.d.cts} +2 -2
- package/dist/{actor-VrXd7EdX.js → actor-GwnlqPRv.js} +1 -1
- package/dist/{assert_rejects-DiIiJbZn.js → assert_rejects-Ce45JcFg.js} +1 -1
- package/dist/{assert_is_error-BPGph1Jx.js → assert_throws-BNXdRGWP.js} +31 -1
- package/dist/{builder-JjsppXTK.js → builder-BflZmL4k.js} +3 -4
- package/dist/{client-bgSdkFa2.d.ts → client-Bkaw0_PR.d.ts} +1 -1
- package/dist/{client-CegPX0Rn.d.cts → client-Cle5j1T1.d.cts} +1 -1
- package/dist/{client-BS-GE3XI.js → client-DylapB-t.js} +1 -1
- package/dist/compat/mod.d.cts +11 -11
- package/dist/compat/mod.d.ts +12 -12
- package/dist/compat/transformers.test.js +20 -20
- package/dist/{context-DYCJXr7J.d.cts → context-BOYzcFSe.d.cts} +10 -10
- package/dist/{context-B1X8-X33.d.ts → context-DqFifMwj.d.ts} +11 -11
- package/dist/{authdocloader-C8LXxsmU.js → docloader-BpcE9hBI.js} +18 -8
- package/dist/{esm-CvUgdJZ_.js → esm-DjbC-dsH.js} +11 -11
- package/dist/federation/builder.test.js +8 -10
- package/dist/federation/collection.test.js +7 -9
- package/dist/federation/handler.test.js +25 -26
- package/dist/federation/idempotency.test.js +25 -26
- package/dist/federation/inbox.test.js +4 -6
- package/dist/federation/keycache.test.js +3 -4
- package/dist/federation/kv.test.js +6 -8
- package/dist/federation/middleware.test.js +26 -27
- package/dist/federation/mod.cjs +10 -11
- package/dist/federation/mod.d.cts +10 -10
- package/dist/federation/mod.d.ts +12 -12
- package/dist/federation/mod.js +10 -11
- package/dist/federation/mq.test.js +8 -10
- package/dist/federation/negotiation.test.js +7 -9
- package/dist/federation/retry.test.js +4 -5
- package/dist/federation/router.test.js +6 -8
- package/dist/federation/send.test.js +13 -15
- package/dist/{http-D-e6AFwR.d.cts → http-B6SKO6NJ.d.cts} +2 -2
- package/dist/{http-D6Uj2x2y.d.ts → http-BE7aFuqn.d.ts} +2 -2
- package/dist/{http-DVQEn98K.js → http-BzsavjR2.js} +256 -6
- package/dist/{http-DbyMqL2X.js → http-CCUJdi0H.js} +2 -2
- package/dist/{http-D_BI5KHC.cjs → http-DtUGyvkU.cjs} +289 -9
- package/dist/{inbox-DQlf_-Dz.js → inbox-DizLjfhC.js} +1 -1
- package/dist/{key-BSJX6n9o.js → key-De1MJH3k.js} +3 -2
- package/dist/{keycache-CcIfdj0m.js → keycache-D2HiBv4F.js} +1 -1
- package/dist/{keys-DnSaJmvD.js → keys-B4ZjS1Ot.js} +2 -1
- package/dist/{docloader-BdF5STdg.cjs → kv-cache-3VK2-wq_.cjs} +69 -651
- package/dist/kv-cache-DNvS-egZ.js +4236 -0
- package/dist/{docloader-AMdJU291.js → kv-cache-rR-Cnl95.js} +68 -596
- package/dist/{ld-CAJ6Q2od.js → ld-Dux3_Cw2.js} +3 -2
- package/dist/{type-COb6KNlm.js → lookup-Bep-EOgr.js} +588 -5303
- package/dist/{lookup-B2Bsau2g.cjs → lookup-BmGuy-Ps.cjs} +78 -5
- package/dist/{lookup-BGCuyJRy.js → lookup-Bql--V-C.js} +63 -2
- package/dist/{middleware-1oxZY_0z.js → middleware-BBTmHKGh.js} +11 -11
- package/dist/middleware-BUZSGsQH.js +16 -0
- package/dist/middleware-BusTq7Js.cjs +16 -0
- package/dist/{middleware-BDqkoMAQ.js → middleware-D7tP9Tq6.js} +18 -17
- package/dist/{middleware-D0XMPoN8.cjs → middleware-DrpnHeGO.cjs} +31 -31
- package/dist/middleware-tZdLtCWz.js +26 -0
- package/dist/{mod-CxkWO3Mg.d.cts → mod--K7l84wp.d.cts} +3 -2
- package/dist/{mod-DBzN0aCM.d.ts → mod-CB80AlIA.d.ts} +1 -1
- package/dist/mod-CLKu6Uo_.d.cts +107 -0
- package/dist/{mod-Djzcw2ry.d.cts → mod-COlOrmr9.d.cts} +3 -3
- package/dist/{mod-DlU8ISoa.d.ts → mod-CRENK2dd.d.ts} +3 -2
- package/dist/{mod-DcKxhFQ8.d.ts → mod-CaWbCg0N.d.ts} +2 -2
- package/dist/mod-Cm97bAiT.d.ts +109 -0
- package/dist/{mod-twdvV2hR.d.cts → mod-D9XZsft2.d.cts} +2 -2
- package/dist/{mod-BhUKmBJD.d.ts → mod-DLIidI_j.d.ts} +3 -3
- package/dist/{mod-jQ4OODsl.d.cts → mod-DuclhZjh.d.cts} +1 -1
- package/dist/mod.cjs +21 -32
- package/dist/mod.d.cts +14 -14
- package/dist/mod.d.ts +17 -17
- package/dist/mod.js +15 -16
- package/dist/nodeinfo/client.test.js +8 -10
- package/dist/nodeinfo/handler.test.js +24 -25
- package/dist/nodeinfo/mod.cjs +3 -3
- package/dist/nodeinfo/mod.d.cts +2 -3
- package/dist/nodeinfo/mod.d.ts +3 -4
- package/dist/nodeinfo/mod.js +3 -3
- package/dist/nodeinfo/types.test.js +7 -9
- package/dist/{owner-hd9lvQcP.d.ts → owner-CktUdA0h.d.ts} +3 -3
- package/dist/{owner-CaIfLBwg.js → owner-Zq8du9WO.js} +3 -2
- package/dist/{owner-BN_tO3cY.d.cts → owner-dkg5OpSC.d.cts} +3 -3
- package/dist/{proof-AhyVJcNZ.cjs → proof-0PY1LDZY.cjs} +17 -16
- package/dist/{proof-BQwXHakc.js → proof-C5S_3hdJ.js} +2 -2
- package/dist/{proof-CKXppjee.js → proof-aIlK5BTc.js} +5 -4
- package/dist/request-BbHkedIU.d.cts +35 -0
- package/dist/request-Bc5CHBqO.cjs +208 -0
- package/dist/request-C0Ags1gQ.js +184 -0
- package/dist/request-U1t6zZtk.d.ts +39 -0
- package/dist/{send-DQd3R1Oc.js → send-BbVnlsQO.js} +2 -2
- package/dist/sig/http.test.js +12 -13
- package/dist/sig/key.test.js +9 -11
- package/dist/sig/ld.test.js +8 -10
- package/dist/sig/mod.cjs +10 -11
- package/dist/sig/mod.d.cts +6 -7
- package/dist/sig/mod.d.ts +6 -7
- package/dist/sig/mod.js +6 -7
- package/dist/sig/owner.test.js +10 -12
- package/dist/sig/proof.test.js +13 -14
- package/dist/testing/docloader.test.js +6 -8
- package/dist/testing/mod.d.ts +3 -62
- package/dist/testing/mod.js +2 -3
- package/dist/{testing-BljKU-GG.js → testing-BkidWE0N.js} +1 -2
- package/dist/{types-DI0yutHB.cjs → types-BDNYgodm.cjs} +3 -3
- package/dist/{types-CEn4wB51.js → types-CXnyjUdK.js} +1 -1
- package/dist/{runtime/authdocloader.test.js → utils/docloader.test.js} +13 -15
- package/dist/utils/kv-cache.test.js +208 -0
- package/dist/utils/mod.cjs +14 -0
- package/dist/utils/mod.d.cts +6 -0
- package/dist/utils/mod.d.ts +8 -0
- package/dist/utils/mod.js +12 -0
- package/dist/utils/request.test.js +48 -0
- package/dist/utils/url.test.js +41 -0
- package/dist/vocab/actor.test.js +8 -10
- package/dist/vocab/lookup.test.js +7 -9
- package/dist/vocab/mod.cjs +4 -4
- package/dist/vocab/mod.d.cts +4 -5
- package/dist/vocab/mod.d.ts +4 -5
- package/dist/vocab/mod.js +4 -4
- package/dist/vocab/type.test.js +2 -3
- package/dist/vocab/vocab.test.js +9 -10
- package/dist/{vocab-CkWH9P5l.js → vocab-BiKK7m2H.js} +4 -3
- package/dist/{vocab-Dw1-yVGg.d.cts → vocab-DCBw44JZ.d.cts} +2 -21
- package/dist/{vocab-NZXL5Pr-.cjs → vocab-Dapemq3v.cjs} +6 -5
- package/dist/{vocab-BI0Ak5lL.d.ts → vocab-ivDKb439.d.ts} +2 -21
- package/dist/webfinger/handler.test.js +24 -25
- package/dist/webfinger/lookup.test.js +7 -9
- package/dist/webfinger/mod.cjs +3 -3
- package/dist/webfinger/mod.d.cts +2 -3
- package/dist/webfinger/mod.d.ts +2 -3
- package/dist/webfinger/mod.js +3 -3
- package/dist/x/cfworkers.d.cts +1 -1
- package/dist/x/cfworkers.d.ts +2 -2
- package/dist/x/cfworkers.test.js +6 -8
- package/dist/x/hono.d.cts +10 -10
- package/dist/x/hono.d.ts +11 -11
- package/dist/x/sveltekit.d.cts +10 -10
- package/dist/x/sveltekit.d.ts +11 -11
- package/package.json +16 -14
- package/dist/assert_throws-BOO88avQ.js +0 -39
- package/dist/authdocloader-6F9IP-VO.js +0 -52
- package/dist/authdocloader-BkuVo8LL.cjs +0 -58
- package/dist/docloader-CxWcuWqQ.d.ts +0 -221
- package/dist/docloader-D-MrRyHl.d.cts +0 -219
- package/dist/key-BBzfhQGE.js +0 -10
- package/dist/key-BMz_uAnc.cjs +0 -10
- package/dist/key-D-RgWfcf.cjs +0 -290
- package/dist/key-DFefr8X2.js +0 -260
- package/dist/key-DW2DrPGl.js +0 -10
- package/dist/lookup-C3pnuyiD.js +0 -331
- package/dist/middleware-B8WWe8Q2.js +0 -26
- package/dist/middleware-DipQbJmB.js +0 -17
- package/dist/middleware-mLaQeD_Z.cjs +0 -17
- package/dist/mod-CerN_Sza.d.ts +0 -104
- package/dist/mod-Cj1tHXBR.d.cts +0 -102
- package/dist/runtime/docloader.test.js +0 -522
- package/dist/runtime/key.test.js +0 -103
- package/dist/runtime/langstr.test.d.ts +0 -3
- package/dist/runtime/langstr.test.js +0 -39
- package/dist/runtime/link.test.d.ts +0 -3
- package/dist/runtime/link.test.js +0 -61
- package/dist/runtime/mod.cjs +0 -25
- package/dist/runtime/mod.d.cts +0 -6
- package/dist/runtime/mod.d.ts +0 -8
- package/dist/runtime/mod.js +0 -13
- package/dist/runtime/multibase/multibase.test.d.ts +0 -3
- package/dist/runtime/multibase/multibase.test.js +0 -358
- package/dist/runtime/url.test.js +0 -45
- /package/dist/{assert_not_equals-f3m3epl3.js → assert_not_equals-C80BG-_5.js} +0 -0
- /package/dist/{collection-CcnIw1qY.js → collection-BzWsN9pB.js} +0 -0
- /package/dist/{denokv-Bv33Xxea.js → denokv-CCssOzMJ.js} +0 -0
- /package/dist/{federation-H2_En3j5.cjs → federation-DOuZpcAw.cjs} +0 -0
- /package/dist/{federation-D1U8YY9t.js → federation-pZJsapBn.js} +0 -0
- /package/dist/{kv-63Cil1MD.d.cts → kv-BMKIFXNW.d.cts} +0 -0
- /package/dist/{kv-C7sopW2E.d.ts → kv-Dt06smFt.d.ts} +0 -0
- /package/dist/{mod-1pDWKvUL.d.ts → mod-B-ZQqbGe.d.ts} +0 -0
- /package/dist/{mod-g0xFzAP9.d.ts → mod-CjsiSl7_.d.ts} +0 -0
- /package/dist/{mq-CRGm1e_F.d.ts → mq-CPRJk4mZ.d.ts} +0 -0
- /package/dist/{negotiation-5NPJL6zp.js → negotiation-C4nFufNk.js} +0 -0
- /package/dist/{nodeinfo-DfycQ8Wf.js → nodeinfo-B0UefMXO.js} +0 -0
- /package/dist/{nodeinfo-Co9lJrWl.cjs → nodeinfo-ByTd7HpT.cjs} +0 -0
- /package/dist/{retry-D4GJ670a.js → retry-CfF8Gn4d.js} +0 -0
- /package/dist/{runtime-C58AJWSv.cjs → sig-DE_NC_VQ.cjs} +0 -0
- /package/dist/{runtime-DPYEDf-o.js → sig-Dx59zAgn.js} +0 -0
- /package/dist/{std__assert-X-_kMxKM.js → std__assert-DWivtrGR.js} +0 -0
- /package/dist/{types-BSuWJsOm.js → types-C2XVl6gj.js} +0 -0
- /package/dist/{runtime → utils}/docloader.test.d.ts +0 -0
- /package/dist/{runtime/authdocloader.test.d.ts → utils/kv-cache.test.d.ts} +0 -0
- /package/dist/{runtime/key.test.d.ts → utils/request.test.d.ts} +0 -0
- /package/dist/{runtime → utils}/url.test.d.ts +0 -0
- /package/dist/{sig-ByHXzqUi.cjs → utils-B6yXfxAQ.cjs} +0 -0
- /package/dist/{sig-Cj3tk-ig.js → utils-BXMGcmqK.js} +0 -0
- /package/dist/{webfinger-BjOEdFPs.cjs → webfinger-C949bxcD.cjs} +0 -0
- /package/dist/{webfinger-De_bU0iE.js → webfinger-qG8R5jc3.js} +0 -0
@@ -3,136 +3,58 @@
|
|
3
3
|
const { URLPattern } = require("urlpattern-polyfill");
|
4
4
|
|
5
5
|
const require_chunk = require('./chunk-DqRYRqnO.cjs');
|
6
|
+
const require_request = require('./request-Bc5CHBqO.cjs');
|
7
|
+
const require_lookup = require('./lookup-BmGuy-Ps.cjs');
|
8
|
+
const require_http = require('./http-DtUGyvkU.cjs');
|
6
9
|
const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
|
7
|
-
const
|
8
|
-
const
|
9
|
-
const node_net = require_chunk.__toESM(require("node:net"));
|
10
|
+
const __fedify_vocab_runtime = require_chunk.__toESM(require("@fedify/vocab-runtime"));
|
11
|
+
const __fxts_core = require_chunk.__toESM(require("@fxts/core"));
|
10
12
|
|
11
|
-
//#region
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
var exclude = [
|
54
|
-
".test-report.xml",
|
55
|
-
"apidoc/",
|
56
|
-
"dist/",
|
57
|
-
"node_modules/",
|
58
|
-
"npm/",
|
59
|
-
"pnpm-lock.yaml",
|
60
|
-
"src/cfworkers/dist/",
|
61
|
-
"src/cfworkers/fixtures/",
|
62
|
-
"src/cfworkers/imports.ts",
|
63
|
-
"src/cfworkers/README.md",
|
64
|
-
"src/cfworkers/server.ts",
|
65
|
-
"src/cfworkers/server.js",
|
66
|
-
"src/cfworkers/server.js.map",
|
67
|
-
"src/codegen/schema.yaml",
|
68
|
-
"src/vocab/*.yaml",
|
69
|
-
"!src/vocab/vocab.ts"
|
70
|
-
];
|
71
|
-
var tasks = {
|
72
|
-
"codegen": "GENPATH=vocab-$(deno eval \"console.log(crypto.randomUUID());\").ts && deno run --allow-read --allow-write --check src/codegen/main.ts src/vocab/ ../runtime/ src/vocab/$GENPATH && deno fmt src/vocab/$GENPATH && mv src/vocab/$GENPATH src/vocab/vocab.ts && deno cache src/vocab/vocab.ts && deno check src/vocab/vocab.ts",
|
73
|
-
"cache": {
|
74
|
-
"command": "deno cache src/mod.ts",
|
75
|
-
"dependencies": ["codegen"]
|
76
|
-
},
|
77
|
-
"check": {
|
78
|
-
"command": "deno fmt --check && deno lint && deno check src/**/*.ts",
|
79
|
-
"dependencies": ["codegen"]
|
80
|
-
},
|
81
|
-
"test": {
|
82
|
-
"command": "deno test --check --doc --allow-read --allow-write --allow-env --unstable-kv --trace-leaks --parallel",
|
83
|
-
"dependencies": ["codegen"]
|
84
|
-
},
|
85
|
-
"coverage": "deno task test --clean --coverage && deno coverage --html coverage",
|
86
|
-
"bench": {
|
87
|
-
"command": "deno bench --allow-read --allow-write --allow-net --allow-env --allow-run --unstable-kv",
|
88
|
-
"dependencies": ["codegen"]
|
89
|
-
},
|
90
|
-
"apidoc": {
|
91
|
-
"command": "deno doc --html --name=Fedify --output=apidoc/ src/mod.ts",
|
92
|
-
"dependencies": ["codegen"]
|
93
|
-
},
|
94
|
-
"publish": {
|
95
|
-
"command": "deno publish",
|
96
|
-
"dependencies": ["codegen"]
|
97
|
-
},
|
98
|
-
"pnpm:install": "pnpm install --silent",
|
99
|
-
"pnpm:build": {
|
100
|
-
"command": "pnpm exec tsdown",
|
101
|
-
"dependencies": ["codegen", "pnpm:install"]
|
102
|
-
},
|
103
|
-
"test:node": {
|
104
|
-
"command": "cd dist/ && node --test",
|
105
|
-
"dependencies": ["pnpm:build"]
|
106
|
-
},
|
107
|
-
"test:bun": {
|
108
|
-
"command": "cd dist/ && bun test --timeout 60000",
|
109
|
-
"dependencies": ["pnpm:build"]
|
110
|
-
},
|
111
|
-
"test:cfworkers": {
|
112
|
-
"command": "pnpm exec wrangler deploy --dry-run --outdir src/cfworkers && node --import=tsx src/cfworkers/client.ts",
|
113
|
-
"dependencies": ["pnpm:build"]
|
114
|
-
},
|
115
|
-
"test-all": { "dependencies": [
|
116
|
-
"check",
|
117
|
-
"test",
|
118
|
-
"test:node",
|
119
|
-
"test:bun",
|
120
|
-
"test:cfworkers"
|
121
|
-
] }
|
122
|
-
};
|
123
|
-
var deno_default = {
|
124
|
-
name,
|
125
|
-
version,
|
126
|
-
license,
|
127
|
-
exports: exports$1,
|
128
|
-
imports,
|
129
|
-
include,
|
130
|
-
exclude,
|
131
|
-
tasks
|
132
|
-
};
|
13
|
+
//#region src/utils/docloader.ts
|
14
|
+
const logger$1 = (0, __logtape_logtape.getLogger)([
|
15
|
+
"fedify",
|
16
|
+
"utils",
|
17
|
+
"docloader"
|
18
|
+
]);
|
19
|
+
/**
|
20
|
+
* Gets an authenticated {@link DocumentLoader} for the given identity.
|
21
|
+
* Note that an authenticated document loader intentionally does not cache
|
22
|
+
* the fetched documents.
|
23
|
+
* @param identity The identity to get the document loader for.
|
24
|
+
* The actor's key pair.
|
25
|
+
* @param options The options for the document loader.
|
26
|
+
* @returns The authenticated document loader.
|
27
|
+
* @throws {TypeError} If the key is invalid or unsupported.
|
28
|
+
* @since 0.4.0
|
29
|
+
*/
|
30
|
+
function getAuthenticatedDocumentLoader(identity, { allowPrivateAddress, userAgent, specDeterminer, tracerProvider } = {}) {
|
31
|
+
require_http.validateCryptoKey(identity.privateKey);
|
32
|
+
async function load(url, options) {
|
33
|
+
if (!allowPrivateAddress) try {
|
34
|
+
await require_lookup.validatePublicUrl(url);
|
35
|
+
} catch (error) {
|
36
|
+
if (error instanceof require_lookup.UrlError) logger$1.error("Disallowed private URL: {url}", {
|
37
|
+
url,
|
38
|
+
error
|
39
|
+
});
|
40
|
+
throw error;
|
41
|
+
}
|
42
|
+
const originalRequest = require_request.createActivityPubRequest(url, { userAgent });
|
43
|
+
const response = await require_http.doubleKnock(originalRequest, identity, {
|
44
|
+
specDeterminer,
|
45
|
+
log: (0, __fxts_core.curry)(require_request.logRequest)(logger$1),
|
46
|
+
tracerProvider,
|
47
|
+
signal: options?.signal
|
48
|
+
});
|
49
|
+
return (0, __fedify_vocab_runtime.getRemoteDocument)(url, response, load);
|
50
|
+
}
|
51
|
+
return load;
|
52
|
+
}
|
53
|
+
const _fetchDocumentLoader = (0, __fedify_vocab_runtime.getDocumentLoader)();
|
54
|
+
const _fetchDocumentLoader_allowPrivateAddress = (0, __fedify_vocab_runtime.getDocumentLoader)({ allowPrivateAddress: true });
|
133
55
|
|
134
56
|
//#endregion
|
135
|
-
//#region src/
|
57
|
+
//#region src/utils/contexts.ts
|
136
58
|
const preloadedContexts = {
|
137
59
|
"https://www.w3.org/ns/activitystreams": { "@context": {
|
138
60
|
"@vocab": "_:",
|
@@ -4274,450 +4196,15 @@ const preloadedContexts = {
|
|
4274
4196
|
}
|
4275
4197
|
} }
|
4276
4198
|
};
|
4277
|
-
var contexts_default = preloadedContexts;
|
4278
4199
|
|
4279
4200
|
//#endregion
|
4280
|
-
//#region src/
|
4281
|
-
const parametersNeedLowerCase = ["rel", "type"];
|
4282
|
-
const regexpLinkWhitespace = /[\n\r\s\t]/;
|
4283
|
-
function validateURI(uri) {
|
4284
|
-
if (uri.includes("\n") || regexpLinkWhitespace.test(uri)) throw new SyntaxError(`\`${uri}\` is not a valid URI!`);
|
4285
|
-
}
|
4286
|
-
function* parseLinkFromString(input) {
|
4287
|
-
const inputFmt = input.replaceAll("\xA0", "").replaceAll("", "");
|
4288
|
-
for (let cursor = 0; cursor < inputFmt.length; cursor += 1) {
|
4289
|
-
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
4290
|
-
if (inputFmt.charAt(cursor) !== "<") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`<\`!`);
|
4291
|
-
cursor += 1;
|
4292
|
-
const cursorEndUri = inputFmt.indexOf(">", cursor);
|
4293
|
-
if (cursorEndUri === -1) throw new SyntaxError(`Missing end of URI delimiter character \`>\` after position ${cursor}!`);
|
4294
|
-
if (cursorEndUri === cursor) throw new SyntaxError(`Missing URI at position ${cursor}!`);
|
4295
|
-
const uriSlice = inputFmt.slice(cursor, cursorEndUri);
|
4296
|
-
validateURI(uriSlice);
|
4297
|
-
const uri = decodeURI(uriSlice);
|
4298
|
-
const parameters = {};
|
4299
|
-
cursor = cursorEndUri + 1;
|
4300
|
-
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
4301
|
-
if (cursor === inputFmt.length || inputFmt.charAt(cursor) === ",") {
|
4302
|
-
yield [uri, parameters];
|
4303
|
-
continue;
|
4304
|
-
}
|
4305
|
-
if (inputFmt.charAt(cursor) !== ";") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`;\`!`);
|
4306
|
-
cursor += 1;
|
4307
|
-
while (cursor < inputFmt.length) {
|
4308
|
-
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
4309
|
-
const parameterKey = inputFmt.slice(cursor).match(/^[\w-]+\*?/)?.[0].toLowerCase();
|
4310
|
-
if (typeof parameterKey === "undefined") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect a valid parameter key!`);
|
4311
|
-
cursor += parameterKey.length;
|
4312
|
-
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
4313
|
-
if (cursor === inputFmt.length || inputFmt.charAt(cursor) === ",") {
|
4314
|
-
parameters[parameterKey] = "";
|
4315
|
-
break;
|
4316
|
-
}
|
4317
|
-
if (inputFmt.charAt(cursor) === ";") {
|
4318
|
-
parameters[parameterKey] = "";
|
4319
|
-
cursor += 1;
|
4320
|
-
continue;
|
4321
|
-
}
|
4322
|
-
if (inputFmt.charAt(cursor) !== "=") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`=\`!`);
|
4323
|
-
cursor += 1;
|
4324
|
-
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
4325
|
-
let parameterValue = "";
|
4326
|
-
if (inputFmt.charAt(cursor) === "\"") {
|
4327
|
-
cursor += 1;
|
4328
|
-
while (cursor < inputFmt.length) {
|
4329
|
-
if (inputFmt.charAt(cursor) === "\"") {
|
4330
|
-
cursor += 1;
|
4331
|
-
break;
|
4332
|
-
}
|
4333
|
-
if (inputFmt.charAt(cursor) === "\\") cursor += 1;
|
4334
|
-
parameterValue += inputFmt.charAt(cursor);
|
4335
|
-
cursor += 1;
|
4336
|
-
}
|
4337
|
-
} else {
|
4338
|
-
const cursorDiffParameterValue = inputFmt.slice(cursor).search(/[\s;,]/);
|
4339
|
-
if (cursorDiffParameterValue === -1) {
|
4340
|
-
parameterValue += inputFmt.slice(cursor);
|
4341
|
-
cursor += parameterValue.length;
|
4342
|
-
} else {
|
4343
|
-
parameterValue += inputFmt.slice(cursor, cursorDiffParameterValue);
|
4344
|
-
cursor += cursorDiffParameterValue;
|
4345
|
-
}
|
4346
|
-
}
|
4347
|
-
parameters[parameterKey] = parametersNeedLowerCase.includes(parameterKey) ? parameterValue.toLowerCase() : parameterValue;
|
4348
|
-
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
4349
|
-
if (cursor === inputFmt.length || inputFmt.charAt(cursor) === ",") break;
|
4350
|
-
if (inputFmt.charAt(cursor) === ";") {
|
4351
|
-
cursor += 1;
|
4352
|
-
continue;
|
4353
|
-
}
|
4354
|
-
throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`,\`, character \`;\`, or end of the string!`);
|
4355
|
-
}
|
4356
|
-
yield [uri, parameters];
|
4357
|
-
}
|
4358
|
-
}
|
4359
|
-
/**
|
4360
|
-
* Handle the HTTP header `Link` according to the specification RFC 8288.
|
4361
|
-
*/
|
4362
|
-
var HttpHeaderLink = class HttpHeaderLink {
|
4363
|
-
get [Symbol.toStringTag]() {
|
4364
|
-
return "HTTPHeaderLink";
|
4365
|
-
}
|
4366
|
-
#entries = [];
|
4367
|
-
/**
|
4368
|
-
* Handle the HTTP header `Link` according to the specification RFC 8288.
|
4369
|
-
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
4370
|
-
*/
|
4371
|
-
constructor(...inputs) {
|
4372
|
-
if (inputs.length > 0) this.add(...inputs);
|
4373
|
-
}
|
4374
|
-
/**
|
4375
|
-
* Add entries.
|
4376
|
-
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
4377
|
-
* @returns {this}
|
4378
|
-
*/
|
4379
|
-
add(...inputs) {
|
4380
|
-
for (const input of inputs) if (input instanceof HttpHeaderLink) this.#entries.push(...structuredClone(input.#entries));
|
4381
|
-
else if (Array.isArray(input)) this.#entries.push(...input.map(([uri, parameters]) => {
|
4382
|
-
validateURI(uri);
|
4383
|
-
Object.entries(parameters).forEach(([key, value]) => {
|
4384
|
-
if (key !== key.toLowerCase() || !/^[\w-]+\*?$/.test(key)) throw new SyntaxError(`\`${key}\` is not a valid parameter key!`);
|
4385
|
-
if (parametersNeedLowerCase.includes(key) && value !== value.toLowerCase()) throw new SyntaxError(`\`${value}\` is not a valid parameter value!`);
|
4386
|
-
});
|
4387
|
-
return [uri, structuredClone(parameters)];
|
4388
|
-
}));
|
4389
|
-
else for (const entry of parseLinkFromString((input instanceof Headers || input instanceof Response ? (input instanceof Headers ? input : input.headers).get("Link") : input) ?? "")) this.#entries.push(entry);
|
4390
|
-
return this;
|
4391
|
-
}
|
4392
|
-
/**
|
4393
|
-
* Return all of the entries.
|
4394
|
-
* @returns {HttpHeaderLinkEntry[]} Entries.
|
4395
|
-
*/
|
4396
|
-
entries() {
|
4397
|
-
return structuredClone(this.#entries);
|
4398
|
-
}
|
4399
|
-
/**
|
4400
|
-
* Get entries by parameter.
|
4401
|
-
* @param {string} key Key of the parameter.
|
4402
|
-
* @param {string} value Value of the parameter.
|
4403
|
-
* @returns {HttpHeaderLinkEntry[]} Entries which match the parameter.
|
4404
|
-
*/
|
4405
|
-
getByParameter(key, value) {
|
4406
|
-
if (key !== key.toLowerCase()) throw new SyntaxError(`\`${key}\` is not a valid parameter key!`);
|
4407
|
-
if (key === "rel") return this.getByRel(value);
|
4408
|
-
return structuredClone(this.#entries.filter((entry) => {
|
4409
|
-
return entry[1][key] === value;
|
4410
|
-
}));
|
4411
|
-
}
|
4412
|
-
/**
|
4413
|
-
* Get entries by parameter `rel`.
|
4414
|
-
* @param {string} value Value of the parameter `rel`.
|
4415
|
-
* @returns {HttpHeaderLinkEntry[]} Entries which match the parameter.
|
4416
|
-
*/
|
4417
|
-
getByRel(value) {
|
4418
|
-
if (value !== value.toLowerCase()) throw new SyntaxError(`\`${value}\` is not a valid parameter \`rel\` value!`);
|
4419
|
-
return structuredClone(this.#entries.filter((entity) => {
|
4420
|
-
return entity[1].rel?.toLowerCase() === value;
|
4421
|
-
}));
|
4422
|
-
}
|
4423
|
-
/**
|
4424
|
-
* Whether have entries that match parameter.
|
4425
|
-
* @param {string} key Key of the parameter.
|
4426
|
-
* @param {string} value Value of the parameter.
|
4427
|
-
* @returns {boolean} Determine result.
|
4428
|
-
*/
|
4429
|
-
hasParameter(key, value) {
|
4430
|
-
return this.getByParameter(key, value).length > 0;
|
4431
|
-
}
|
4432
|
-
/**
|
4433
|
-
* Stringify entries.
|
4434
|
-
* @returns {string} Stringified entries.
|
4435
|
-
*/
|
4436
|
-
toString() {
|
4437
|
-
return this.#entries.map(([uri, parameters]) => {
|
4438
|
-
return [`<${encodeURI(uri)}>`, ...Object.entries(parameters).map(([key, value]) => {
|
4439
|
-
return value.length > 0 ? `${key}="${value.replaceAll("\"", "\\\"")}"` : key;
|
4440
|
-
})].join("; ");
|
4441
|
-
}).join(", ");
|
4442
|
-
}
|
4443
|
-
/**
|
4444
|
-
* Parse the HTTP header `Link` according to the specification RFC 8288.
|
4445
|
-
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
4446
|
-
* @returns {HttpHeaderLink}
|
4447
|
-
*/
|
4448
|
-
static parse(...inputs) {
|
4449
|
-
return new this(...inputs);
|
4450
|
-
}
|
4451
|
-
/**
|
4452
|
-
* Stringify as the HTTP header `Link` according to the specification RFC 8288.
|
4453
|
-
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
4454
|
-
* @returns {string}
|
4455
|
-
*/
|
4456
|
-
static stringify(...inputs) {
|
4457
|
-
return new this(...inputs).toString();
|
4458
|
-
}
|
4459
|
-
};
|
4460
|
-
|
4461
|
-
//#endregion
|
4462
|
-
//#region src/runtime/url.ts
|
4463
|
-
var UrlError = class extends Error {
|
4464
|
-
constructor(message) {
|
4465
|
-
super(message);
|
4466
|
-
this.name = "UrlError";
|
4467
|
-
}
|
4468
|
-
};
|
4469
|
-
/**
|
4470
|
-
* Validates a URL to prevent SSRF attacks.
|
4471
|
-
*/
|
4472
|
-
async function validatePublicUrl(url) {
|
4473
|
-
const parsed = new URL(url);
|
4474
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new UrlError(`Unsupported protocol: ${parsed.protocol}`);
|
4475
|
-
let hostname = parsed.hostname;
|
4476
|
-
if (hostname.startsWith("[") && hostname.endsWith("]")) hostname = hostname.substring(1, hostname.length - 2);
|
4477
|
-
if (hostname === "localhost") throw new UrlError("Localhost is not allowed");
|
4478
|
-
if ("Deno" in globalThis && !(0, node_net.isIP)(hostname)) {
|
4479
|
-
const netPermission = await Deno.permissions.query({ name: "net" });
|
4480
|
-
if (netPermission.state !== "granted") return;
|
4481
|
-
}
|
4482
|
-
if ("Bun" in globalThis) {
|
4483
|
-
if (hostname === "example.com" || hostname.endsWith(".example.com")) return;
|
4484
|
-
else if (hostname === "fedify-test.internal") throw new UrlError("Invalid or private address: fedify-test.internal");
|
4485
|
-
}
|
4486
|
-
let addresses;
|
4487
|
-
try {
|
4488
|
-
addresses = await (0, node_dns_promises.lookup)(hostname, { all: true });
|
4489
|
-
} catch {
|
4490
|
-
addresses = [];
|
4491
|
-
}
|
4492
|
-
for (const { address, family } of addresses) if (family === 4 && !isValidPublicIPv4Address(address) || family === 6 && !isValidPublicIPv6Address(address) || family < 4 || family === 5 || family > 6) throw new UrlError(`Invalid or private address: ${address}`);
|
4493
|
-
}
|
4494
|
-
function isValidPublicIPv4Address(address) {
|
4495
|
-
const parts = address.split(".");
|
4496
|
-
const first = parseInt(parts[0]);
|
4497
|
-
if (first === 0 || first === 10 || first === 127) return false;
|
4498
|
-
const second = parseInt(parts[1]);
|
4499
|
-
if (first === 169 && second === 254) return false;
|
4500
|
-
if (first === 172 && second >= 16 && second <= 31) return false;
|
4501
|
-
if (first === 192 && second === 168) return false;
|
4502
|
-
return true;
|
4503
|
-
}
|
4504
|
-
function isValidPublicIPv6Address(address) {
|
4505
|
-
address = expandIPv6Address(address);
|
4506
|
-
if (address.at(4) !== ":") return false;
|
4507
|
-
const firstWord = parseInt(address.substring(0, 4), 16);
|
4508
|
-
return !(firstWord >= 64512 && firstWord <= 65023 || firstWord >= 65152 && firstWord <= 65215 || firstWord === 0 || firstWord >= 65280);
|
4509
|
-
}
|
4510
|
-
function expandIPv6Address(address) {
|
4511
|
-
address = address.toLowerCase();
|
4512
|
-
if (address === "::") return "0000:0000:0000:0000:0000:0000:0000:0000";
|
4513
|
-
if (address.startsWith("::")) address = "0000" + address;
|
4514
|
-
if (address.endsWith("::")) address = address + "0000";
|
4515
|
-
address = address.replace("::", ":0000".repeat(8 - (address.match(/:/g) || []).length) + ":");
|
4516
|
-
const parts = address.split(":");
|
4517
|
-
return parts.map((part) => part.padStart(4, "0")).join(":");
|
4518
|
-
}
|
4519
|
-
|
4520
|
-
//#endregion
|
4521
|
-
//#region src/runtime/docloader.ts
|
4201
|
+
//#region src/utils/kv-cache.ts
|
4522
4202
|
const logger = (0, __logtape_logtape.getLogger)([
|
4523
4203
|
"fedify",
|
4524
|
-
"
|
4525
|
-
"
|
4204
|
+
"utils",
|
4205
|
+
"kv-cache"
|
4526
4206
|
]);
|
4527
4207
|
/**
|
4528
|
-
* Error thrown when fetching a JSON-LD document failed.
|
4529
|
-
*/
|
4530
|
-
var FetchError = class extends Error {
|
4531
|
-
/**
|
4532
|
-
* The URL that failed to fetch.
|
4533
|
-
*/
|
4534
|
-
url;
|
4535
|
-
/**
|
4536
|
-
* Constructs a new `FetchError`.
|
4537
|
-
*
|
4538
|
-
* @param url The URL that failed to fetch.
|
4539
|
-
* @param message Error message.
|
4540
|
-
*/
|
4541
|
-
constructor(url, message) {
|
4542
|
-
super(message == null ? url.toString() : `${url}: ${message}`);
|
4543
|
-
this.name = "FetchError";
|
4544
|
-
this.url = typeof url === "string" ? new URL(url) : url;
|
4545
|
-
}
|
4546
|
-
};
|
4547
|
-
/**
|
4548
|
-
* Creates a request for the given URL.
|
4549
|
-
* @param url The URL to create the request for.
|
4550
|
-
* @param options The options for the request.
|
4551
|
-
* @returns The created request.
|
4552
|
-
* @internal
|
4553
|
-
*/
|
4554
|
-
function createRequest(url, options = {}) {
|
4555
|
-
return new Request(url, {
|
4556
|
-
headers: {
|
4557
|
-
Accept: "application/activity+json, application/ld+json",
|
4558
|
-
"User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
|
4559
|
-
},
|
4560
|
-
redirect: "manual"
|
4561
|
-
});
|
4562
|
-
}
|
4563
|
-
/**
|
4564
|
-
* Logs the request.
|
4565
|
-
* @param request The request to log.
|
4566
|
-
* @internal
|
4567
|
-
*/
|
4568
|
-
function logRequest(request) {
|
4569
|
-
logger.debug("Fetching document: {method} {url} {headers}", {
|
4570
|
-
method: request.method,
|
4571
|
-
url: request.url,
|
4572
|
-
headers: Object.fromEntries(request.headers.entries())
|
4573
|
-
});
|
4574
|
-
}
|
4575
|
-
/**
|
4576
|
-
* Gets a {@link RemoteDocument} from the given response.
|
4577
|
-
* @param url The URL of the document to load.
|
4578
|
-
* @param response The response to get the document from.
|
4579
|
-
* @param fetch The function to fetch the document.
|
4580
|
-
* @returns The loaded remote document.
|
4581
|
-
* @throws {FetchError} If the response is not OK.
|
4582
|
-
* @internal
|
4583
|
-
*/
|
4584
|
-
async function getRemoteDocument(url, response, fetch$1) {
|
4585
|
-
const documentUrl = response.url === "" ? url : response.url;
|
4586
|
-
const docUrl = new URL(documentUrl);
|
4587
|
-
if (!response.ok) {
|
4588
|
-
logger.error("Failed to fetch document: {status} {url} {headers}", {
|
4589
|
-
status: response.status,
|
4590
|
-
url: documentUrl,
|
4591
|
-
headers: Object.fromEntries(response.headers.entries())
|
4592
|
-
});
|
4593
|
-
throw new FetchError(documentUrl, `HTTP ${response.status}: ${documentUrl}`);
|
4594
|
-
}
|
4595
|
-
const contentType = response.headers.get("Content-Type");
|
4596
|
-
const jsonLd = contentType == null || contentType === "application/activity+json" || contentType.startsWith("application/activity+json;") || contentType === "application/ld+json" || contentType.startsWith("application/ld+json;");
|
4597
|
-
const linkHeader = response.headers.get("Link");
|
4598
|
-
let contextUrl = null;
|
4599
|
-
if (linkHeader != null) {
|
4600
|
-
let link;
|
4601
|
-
try {
|
4602
|
-
link = new HttpHeaderLink(linkHeader);
|
4603
|
-
} catch (e) {
|
4604
|
-
if (e instanceof SyntaxError) link = new HttpHeaderLink();
|
4605
|
-
else throw e;
|
4606
|
-
}
|
4607
|
-
if (jsonLd) {
|
4608
|
-
const entries = link.getByRel("http://www.w3.org/ns/json-ld#context");
|
4609
|
-
for (const [uri, params] of entries) if ("type" in params && params.type === "application/ld+json") {
|
4610
|
-
contextUrl = uri;
|
4611
|
-
break;
|
4612
|
-
}
|
4613
|
-
} else {
|
4614
|
-
const entries = link.getByRel("alternate");
|
4615
|
-
for (const [uri, params] of entries) {
|
4616
|
-
const altUri = new URL(uri, docUrl);
|
4617
|
-
if ("type" in params && (params.type === "application/activity+json" || params.type === "application/ld+json" || params.type.startsWith("application/ld+json;")) && altUri.href !== docUrl.href) {
|
4618
|
-
logger.debug("Found alternate document: {alternateUrl} from {url}", {
|
4619
|
-
alternateUrl: altUri.href,
|
4620
|
-
url: documentUrl
|
4621
|
-
});
|
4622
|
-
return await fetch$1(altUri.href);
|
4623
|
-
}
|
4624
|
-
}
|
4625
|
-
}
|
4626
|
-
}
|
4627
|
-
let document;
|
4628
|
-
if (!jsonLd && (contentType === "text/html" || contentType?.startsWith("text/html;") || contentType === "application/xhtml+xml" || contentType?.startsWith("application/xhtml+xml;"))) {
|
4629
|
-
const p = /<(a|link)((\s+[a-z][a-z:_-]*=("[^"]*"|'[^']*'|[^\s>]+))+)\s*\/?>/gi;
|
4630
|
-
const p2 = /\s+([a-z][a-z:_-]*)=("([^"]*)"|'([^']*)'|([^\s>]+))/gi;
|
4631
|
-
const html = await response.text();
|
4632
|
-
let m;
|
4633
|
-
const rawAttribs = [];
|
4634
|
-
while ((m = p.exec(html)) !== null) rawAttribs.push(m[2]);
|
4635
|
-
for (const rawAttrs of rawAttribs) {
|
4636
|
-
let m2;
|
4637
|
-
const attribs = {};
|
4638
|
-
while ((m2 = p2.exec(rawAttrs)) !== null) {
|
4639
|
-
const key = m2[1].toLowerCase();
|
4640
|
-
const value = m2[3] ?? m2[4] ?? m2[5] ?? "";
|
4641
|
-
attribs[key] = value;
|
4642
|
-
}
|
4643
|
-
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) {
|
4644
|
-
logger.debug("Found alternate document: {alternateUrl} from {url}", {
|
4645
|
-
alternateUrl: attribs.href,
|
4646
|
-
url: documentUrl
|
4647
|
-
});
|
4648
|
-
return await fetch$1(new URL(attribs.href, docUrl).href);
|
4649
|
-
}
|
4650
|
-
}
|
4651
|
-
document = JSON.parse(html);
|
4652
|
-
} else document = await response.json();
|
4653
|
-
logger.debug("Fetched document: {status} {url} {headers}", {
|
4654
|
-
status: response.status,
|
4655
|
-
url: documentUrl,
|
4656
|
-
headers: Object.fromEntries(response.headers.entries())
|
4657
|
-
});
|
4658
|
-
return {
|
4659
|
-
contextUrl,
|
4660
|
-
document,
|
4661
|
-
documentUrl
|
4662
|
-
};
|
4663
|
-
}
|
4664
|
-
/**
|
4665
|
-
* Creates a JSON-LD document loader that utilizes the browser's `fetch` API.
|
4666
|
-
*
|
4667
|
-
* The created loader preloads the below frequently used contexts by default
|
4668
|
-
* (unless `options.ignorePreloadedContexts` is set to `true`):
|
4669
|
-
*
|
4670
|
-
* - <https://www.w3.org/ns/activitystreams>
|
4671
|
-
* - <https://w3id.org/security/v1>
|
4672
|
-
* - <https://w3id.org/security/data-integrity/v1>
|
4673
|
-
* - <https://www.w3.org/ns/did/v1>
|
4674
|
-
* - <https://w3id.org/security/multikey/v1>
|
4675
|
-
* - <https://purl.archive.org/socialweb/webfinger>
|
4676
|
-
* - <http://schema.org/>
|
4677
|
-
* @param options Options for the document loader.
|
4678
|
-
* @returns The document loader.
|
4679
|
-
* @since 1.3.0
|
4680
|
-
*/
|
4681
|
-
function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAgent } = {}) {
|
4682
|
-
async function load(url, options) {
|
4683
|
-
options?.signal?.throwIfAborted();
|
4684
|
-
if (!skipPreloadedContexts && url in contexts_default) {
|
4685
|
-
logger.debug("Using preloaded context: {url}.", { url });
|
4686
|
-
return {
|
4687
|
-
contextUrl: null,
|
4688
|
-
document: contexts_default[url],
|
4689
|
-
documentUrl: url
|
4690
|
-
};
|
4691
|
-
}
|
4692
|
-
if (!allowPrivateAddress) try {
|
4693
|
-
await validatePublicUrl(url);
|
4694
|
-
} catch (error) {
|
4695
|
-
if (error instanceof UrlError) logger.error("Disallowed private URL: {url}", {
|
4696
|
-
url,
|
4697
|
-
error
|
4698
|
-
});
|
4699
|
-
throw error;
|
4700
|
-
}
|
4701
|
-
const request = createRequest(url, { userAgent });
|
4702
|
-
logRequest(request);
|
4703
|
-
const response = await fetch(request, {
|
4704
|
-
redirect: "manual",
|
4705
|
-
signal: options?.signal
|
4706
|
-
});
|
4707
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) return load(response.headers.get("Location"), options);
|
4708
|
-
return getRemoteDocument(url, response, load);
|
4709
|
-
}
|
4710
|
-
return load;
|
4711
|
-
}
|
4712
|
-
const _fetchDocumentLoader = getDocumentLoader();
|
4713
|
-
const _fetchDocumentLoader_allowPrivateAddress = getDocumentLoader({ allowPrivateAddress: true });
|
4714
|
-
function fetchDocumentLoader(url, arg = false) {
|
4715
|
-
const allowPrivateAddress = typeof arg === "boolean" ? arg : false;
|
4716
|
-
logger.warn("fetchDocumentLoader() function is deprecated. Use getDocumentLoader() function instead.");
|
4717
|
-
const loader = allowPrivateAddress ? _fetchDocumentLoader_allowPrivateAddress : _fetchDocumentLoader;
|
4718
|
-
return loader(url);
|
4719
|
-
}
|
4720
|
-
/**
|
4721
4208
|
* Decorates a {@link DocumentLoader} with a cache backed by a {@link Deno.Kv}.
|
4722
4209
|
* @param parameters The parameters for the cache.
|
4723
4210
|
* @returns The decorated document loader which is cache-enabled.
|
@@ -4726,30 +4213,16 @@ function kvCache({ loader, kv, prefix, rules }) {
|
|
4726
4213
|
const keyPrefix = prefix ?? ["_fedify", "remoteDocument"];
|
4727
4214
|
rules ??= [[new URLPattern({}), Temporal.Duration.from({ minutes: 5 })]];
|
4728
4215
|
for (const [p, duration] of rules) if (Temporal.Duration.compare(duration, { days: 30 }) > 0) throw new TypeError("The maximum cache duration is 30 days: " + (p instanceof URLPattern ? `${p.protocol}://${p.username}:${p.password}@${p.hostname}:${p.port}/${p.pathname}?${p.search}#${p.hash}` : p.toString()));
|
4729
|
-
function matchRule(url) {
|
4730
|
-
for (const [pattern, duration] of rules) {
|
4731
|
-
if (typeof pattern === "string") {
|
4732
|
-
if (url === pattern) return duration;
|
4733
|
-
continue;
|
4734
|
-
}
|
4735
|
-
if (pattern instanceof URL) {
|
4736
|
-
if (pattern.href == url) return duration;
|
4737
|
-
continue;
|
4738
|
-
}
|
4739
|
-
if (pattern.test(url)) return duration;
|
4740
|
-
}
|
4741
|
-
return null;
|
4742
|
-
}
|
4743
4216
|
return async (url, options) => {
|
4744
|
-
if (url in
|
4217
|
+
if (url in preloadedContexts) {
|
4745
4218
|
logger.debug("Using preloaded context: {url}.", { url });
|
4746
4219
|
return {
|
4747
4220
|
contextUrl: null,
|
4748
|
-
document:
|
4221
|
+
document: preloadedContexts[url],
|
4749
4222
|
documentUrl: url
|
4750
4223
|
};
|
4751
4224
|
}
|
4752
|
-
const match = matchRule(url);
|
4225
|
+
const match = matchRule(url, rules);
|
4753
4226
|
if (match == null) return await loader(url, options);
|
4754
4227
|
const key = [...keyPrefix, url];
|
4755
4228
|
let cache = void 0;
|
@@ -4776,69 +4249,26 @@ function kvCache({ loader, kv, prefix, rules }) {
|
|
4776
4249
|
return cache;
|
4777
4250
|
};
|
4778
4251
|
}
|
4779
|
-
|
4780
|
-
|
4781
|
-
|
4782
|
-
|
4783
|
-
|
4784
|
-
|
4785
|
-
|
4786
|
-
|
4787
|
-
|
4788
|
-
|
4789
|
-
|
4790
|
-
|
4791
|
-
|
4792
|
-
return `${first} (${userAgent.join("; ")})`;
|
4252
|
+
function matchRule(url, rules) {
|
4253
|
+
for (const [pattern, duration] of rules) {
|
4254
|
+
if (typeof pattern === "string") {
|
4255
|
+
if (url === pattern) return duration;
|
4256
|
+
continue;
|
4257
|
+
}
|
4258
|
+
if (pattern instanceof URL) {
|
4259
|
+
if (pattern.href == url) return duration;
|
4260
|
+
continue;
|
4261
|
+
}
|
4262
|
+
if (pattern.test(url)) return duration;
|
4263
|
+
}
|
4264
|
+
return null;
|
4793
4265
|
}
|
4794
4266
|
|
4795
4267
|
//#endregion
|
4796
|
-
Object.defineProperty(exports, '
|
4797
|
-
enumerable: true,
|
4798
|
-
get: function () {
|
4799
|
-
return FetchError;
|
4800
|
-
}
|
4801
|
-
});
|
4802
|
-
Object.defineProperty(exports, 'UrlError', {
|
4803
|
-
enumerable: true,
|
4804
|
-
get: function () {
|
4805
|
-
return UrlError;
|
4806
|
-
}
|
4807
|
-
});
|
4808
|
-
Object.defineProperty(exports, 'createRequest', {
|
4809
|
-
enumerable: true,
|
4810
|
-
get: function () {
|
4811
|
-
return createRequest;
|
4812
|
-
}
|
4813
|
-
});
|
4814
|
-
Object.defineProperty(exports, 'deno_default', {
|
4815
|
-
enumerable: true,
|
4816
|
-
get: function () {
|
4817
|
-
return deno_default;
|
4818
|
-
}
|
4819
|
-
});
|
4820
|
-
Object.defineProperty(exports, 'fetchDocumentLoader', {
|
4268
|
+
Object.defineProperty(exports, 'getAuthenticatedDocumentLoader', {
|
4821
4269
|
enumerable: true,
|
4822
4270
|
get: function () {
|
4823
|
-
return
|
4824
|
-
}
|
4825
|
-
});
|
4826
|
-
Object.defineProperty(exports, 'getDocumentLoader', {
|
4827
|
-
enumerable: true,
|
4828
|
-
get: function () {
|
4829
|
-
return getDocumentLoader;
|
4830
|
-
}
|
4831
|
-
});
|
4832
|
-
Object.defineProperty(exports, 'getRemoteDocument', {
|
4833
|
-
enumerable: true,
|
4834
|
-
get: function () {
|
4835
|
-
return getRemoteDocument;
|
4836
|
-
}
|
4837
|
-
});
|
4838
|
-
Object.defineProperty(exports, 'getUserAgent', {
|
4839
|
-
enumerable: true,
|
4840
|
-
get: function () {
|
4841
|
-
return getUserAgent;
|
4271
|
+
return getAuthenticatedDocumentLoader;
|
4842
4272
|
}
|
4843
4273
|
});
|
4844
4274
|
Object.defineProperty(exports, 'kvCache', {
|
@@ -4846,16 +4276,4 @@ Object.defineProperty(exports, 'kvCache', {
|
|
4846
4276
|
get: function () {
|
4847
4277
|
return kvCache;
|
4848
4278
|
}
|
4849
|
-
});
|
4850
|
-
Object.defineProperty(exports, 'logRequest', {
|
4851
|
-
enumerable: true,
|
4852
|
-
get: function () {
|
4853
|
-
return logRequest;
|
4854
|
-
}
|
4855
|
-
});
|
4856
|
-
Object.defineProperty(exports, 'validatePublicUrl', {
|
4857
|
-
enumerable: true,
|
4858
|
-
get: function () {
|
4859
|
-
return validatePublicUrl;
|
4860
|
-
}
|
4861
4279
|
});
|