@objectstack/rest 9.5.1 → 9.7.0
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/index.cjs +50 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1546,6 +1546,56 @@ var RestServer = class {
|
|
|
1546
1546
|
tags: ["metadata"]
|
|
1547
1547
|
}
|
|
1548
1548
|
});
|
|
1549
|
+
this.routeManager.register({
|
|
1550
|
+
method: "GET",
|
|
1551
|
+
path: `${metaPath}/book/:name/tree`,
|
|
1552
|
+
handler: async (req, res) => {
|
|
1553
|
+
try {
|
|
1554
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1555
|
+
const prot = await this.resolveProtocol(environmentId, req);
|
|
1556
|
+
const locale = this.extractLocale(req);
|
|
1557
|
+
const packageId = req.query?.package || void 0;
|
|
1558
|
+
const { resolveBookTree, deriveImplicitPackageBook, isPublicAudience, resolveDocLocale } = await import("@objectstack/spec/system");
|
|
1559
|
+
const norm = (raw) => Array.isArray(raw) ? raw : raw && Array.isArray(raw.items) ? raw.items : [];
|
|
1560
|
+
const books = norm(await prot.getMetaItems({
|
|
1561
|
+
type: "book",
|
|
1562
|
+
...packageId ? { packageId } : {},
|
|
1563
|
+
...environmentId ? { environmentId } : {}
|
|
1564
|
+
}));
|
|
1565
|
+
let book = books.find((b) => b && b.name === req.params.name);
|
|
1566
|
+
if (!book) {
|
|
1567
|
+
book = deriveImplicitPackageBook(req.params.name, req.params.name);
|
|
1568
|
+
}
|
|
1569
|
+
const ctx = await this.resolveExecCtx(environmentId, req).catch(() => void 0);
|
|
1570
|
+
if (!ctx?.userId && !isPublicAudience(book.audience)) {
|
|
1571
|
+
sendError(res, { code: "unauthorized", message: "This documentation requires sign-in", status: 401 });
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1574
|
+
const docs = norm(await prot.getMetaItems({
|
|
1575
|
+
type: "doc",
|
|
1576
|
+
...packageId ? { packageId } : {},
|
|
1577
|
+
...environmentId ? { environmentId } : {}
|
|
1578
|
+
})).map((d) => d && typeof d === "object" ? resolveDocLocale(d, locale) : d).map((d) => ({
|
|
1579
|
+
name: d.name,
|
|
1580
|
+
label: d.label,
|
|
1581
|
+
description: d.description,
|
|
1582
|
+
order: d.order,
|
|
1583
|
+
group: d.group,
|
|
1584
|
+
tags: d.tags,
|
|
1585
|
+
packageId: d._packageId
|
|
1586
|
+
}));
|
|
1587
|
+
const tree = resolveBookTree(book, docs, book._packageId);
|
|
1588
|
+
res.json(tree);
|
|
1589
|
+
} catch (error) {
|
|
1590
|
+
logError("[REST] Unhandled error:", error);
|
|
1591
|
+
sendError(res, error);
|
|
1592
|
+
}
|
|
1593
|
+
},
|
|
1594
|
+
metadata: {
|
|
1595
|
+
summary: "Resolve a documentation book spine into its rendered tree (ADR-0046 \xA76)",
|
|
1596
|
+
tags: ["metadata"]
|
|
1597
|
+
}
|
|
1598
|
+
});
|
|
1549
1599
|
this.routeManager.register({
|
|
1550
1600
|
method: "GET",
|
|
1551
1601
|
path: `${metaPath}/:type/:name`,
|