Skip to content

Commit 58cbc91

Browse files
authored
Merge pull request #1216 from dahlia/preloaded-contexts/fep-6757
Preload the FEP-6757 context
2 parents bf0ebff + a824ac9 commit 58cbc91

6 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎CHANGES.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ To be released.
1919
[#1207]: https://github.com/fedify-dev/fedify/issues/1207
2020
[#1208]: https://github.com/fedify-dev/fedify/pull/1208
2121

22+
### @fedify/vocab-runtime
23+
24+
- Added the [FEP-6757] context to the preloaded JSON-LD contexts. The default
25+
document loader now resolves <https://w3id.org/fep/6757> locally, so
26+
transient Codeberg Pages outages no longer prevent otherwise valid inbound
27+
documents from being parsed or verified. [[#1211], [#1216]]
28+
29+
[FEP-6757]: https://w3id.org/fep/6757
30+
[#1211]: https://github.com/fedify-dev/fedify/issues/1211
31+
[#1216]: https://github.com/fedify-dev/fedify/pull/1216
32+
2233
### @fedify/vocab-tools
2334

2435
- Fixed generated constructors and `clone()` methods to copy property
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
links:
3+
'#1211': https://github.com/fedify-dev/fedify/issues/1211
4+
'#1216': https://github.com/fedify-dev/fedify/pull/1216
5+
---
6+
- Added the [FEP-6757] context to the preloaded JSON-LD contexts. The default
7+
document loader now resolves <https://w3id.org/fep/6757> locally, so
8+
transient Codeberg Pages outages no longer prevent otherwise valid inbound
9+
documents from being parsed or verified. [[#1211], [#1216]]
10+
11+
[FEP-6757]: https://w3id.org/fep/6757

‎packages/vocab-runtime/src/contexts.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// cSpell: disable
44

55
import cidV1Context from "./contexts/cid-v1.json" with { type: "json" };
6+
import fep6757 from "./contexts/fep-6757.json" with { type: "json" };
67
import fep7aa9 from "./contexts/fep-7aa9.json" with { type: "json" };
78
import fepEf61 from "./contexts/fep-ef61.json" with { type: "json" };
89
import joinLemmyContext from "./contexts/join-lemmy.json" with { type: "json" };
@@ -4345,6 +4346,13 @@ const preloadedContexts: Record<string, unknown> = {
43454346
// https://github.com/fedify-dev/fedify/issues/1078
43464347
"https://w3id.org/fep/7aa9": fep7aa9,
43474348

4349+
// The FEP-6757 context is hosted on Codeberg Pages, whose outages can
4350+
// prevent documents with license metadata from being parsed. Resolve it
4351+
// locally so parsing does not depend on the remote context server.
4352+
// See: https://w3id.org/fep/6757
4353+
// https://github.com/fedify-dev/fedify/issues/1211
4354+
"https://w3id.org/fep/6757": fep6757,
4355+
43484356
// Lemmy's context document is served as application/json without the JSON-LD
43494357
// context Link header. The default document loader treats that as a regular
43504358
// JSON response instead of a JSON-LD context, so every Lemmy activity that
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"@context": {
3+
"license": {
4+
"@id": "http://purl.org/dc/terms/license",
5+
"@type": "@id"
6+
},
7+
"preferredLicense": {
8+
"@id": "https://w3id.org/fep/6757#preferredLicense",
9+
"@type": "@id"
10+
}
11+
}
12+
}

‎packages/vocab-runtime/src/docloader.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { gzipSync } from "node:zlib";
88
import preloadedContexts from "./contexts.ts";
99
import cidV1Context from "./contexts/cid-v1.json" with { type: "json" };
1010
import { getDocumentLoader, getRemoteDocument } from "./docloader.ts";
11+
import jsonld from "./jsonld.ts";
1112
import { FetchError } from "./request.ts";
1213
import { UrlError } from "./url.ts";
1314

@@ -367,6 +368,47 @@ test("getDocumentLoader()", async (t) => {
367368
deepStrictEqual(fetchMock.callHistory.calls(url).length, 0);
368369
});
369370

371+
// A Codeberg Pages outage must not prevent loading or expanding FEP-6757.
372+
// See: https://github.com/fedify-dev/fedify/issues/1211
373+
fetchMock.get("https://w3id.org/fep/6757", { status: 502 });
374+
await t.test("preloaded FEP-6757 context", async () => {
375+
const url = "https://w3id.org/fep/6757";
376+
deepStrictEqual(await fetchDocumentLoader(url), {
377+
contextUrl: null,
378+
documentUrl: url,
379+
document: {
380+
"@context": {
381+
license: {
382+
"@id": "http://purl.org/dc/terms/license",
383+
"@type": "@id",
384+
},
385+
preferredLicense: {
386+
"@id": "https://w3id.org/fep/6757#preferredLicense",
387+
"@type": "@id",
388+
},
389+
},
390+
},
391+
});
392+
deepStrictEqual(
393+
await jsonld.expand({
394+
"@context": ["https://www.w3.org/ns/activitystreams", url],
395+
type: "Person",
396+
license: "https://creativecommons.org/licenses/by/4.0/",
397+
preferredLicense: "https://creativecommons.org/licenses/by-nc/4.0/",
398+
}, { documentLoader: fetchDocumentLoader }),
399+
[{
400+
"@type": ["https://www.w3.org/ns/activitystreams#Person"],
401+
"http://purl.org/dc/terms/license": [{
402+
"@id": "https://creativecommons.org/licenses/by/4.0/",
403+
}],
404+
"https://w3id.org/fep/6757#preferredLicense": [{
405+
"@id": "https://creativecommons.org/licenses/by-nc/4.0/",
406+
}],
407+
}],
408+
);
409+
deepStrictEqual(fetchMock.callHistory.calls(url).length, 0);
410+
});
411+
370412
await t.test("deny non-HTTP/HTTPS", async () => {
371413
await rejects(
372414
() => fetchDocumentLoader("ftp://localhost"),

‎packages/vocab-runtime/src/docloader.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export interface GetDocumentLoaderOptions extends DocumentLoaderFactoryOptions {
280280
* - <https://w3id.org/security/multikey/v1>
281281
* - <https://w3id.org/fep/ef61>
282282
* - <https://w3id.org/fep/7aa9>
283+
* - <https://w3id.org/fep/6757>
283284
* - <https://purl.archive.org/socialweb/webfinger>
284285
* - <http://schema.org/>
285286
* @param options Options for the document loader.

0 commit comments

Comments
 (0)