@objectstack/rest 9.5.1 → 9.6.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 CHANGED
@@ -1586,6 +1586,56 @@ var RestServer = class {
1586
1586
  tags: ["metadata"]
1587
1587
  }
1588
1588
  });
1589
+ this.routeManager.register({
1590
+ method: "GET",
1591
+ path: `${metaPath}/book/:name/tree`,
1592
+ handler: async (req, res) => {
1593
+ try {
1594
+ const environmentId = isScoped ? req.params?.environmentId : void 0;
1595
+ const prot = await this.resolveProtocol(environmentId, req);
1596
+ const locale = this.extractLocale(req);
1597
+ const packageId = req.query?.package || void 0;
1598
+ const { resolveBookTree, deriveImplicitPackageBook, isPublicAudience, resolveDocLocale } = await import("@objectstack/spec/system");
1599
+ const norm = (raw) => Array.isArray(raw) ? raw : raw && Array.isArray(raw.items) ? raw.items : [];
1600
+ const books = norm(await prot.getMetaItems({
1601
+ type: "book",
1602
+ ...packageId ? { packageId } : {},
1603
+ ...environmentId ? { environmentId } : {}
1604
+ }));
1605
+ let book = books.find((b) => b && b.name === req.params.name);
1606
+ if (!book) {
1607
+ book = deriveImplicitPackageBook(req.params.name, req.params.name);
1608
+ }
1609
+ const ctx = await this.resolveExecCtx(environmentId, req).catch(() => void 0);
1610
+ if (!ctx?.userId && !isPublicAudience(book.audience)) {
1611
+ sendError(res, { code: "unauthorized", message: "This documentation requires sign-in", status: 401 });
1612
+ return;
1613
+ }
1614
+ const docs = norm(await prot.getMetaItems({
1615
+ type: "doc",
1616
+ ...packageId ? { packageId } : {},
1617
+ ...environmentId ? { environmentId } : {}
1618
+ })).map((d) => d && typeof d === "object" ? resolveDocLocale(d, locale) : d).map((d) => ({
1619
+ name: d.name,
1620
+ label: d.label,
1621
+ description: d.description,
1622
+ order: d.order,
1623
+ group: d.group,
1624
+ tags: d.tags,
1625
+ packageId: d._packageId
1626
+ }));
1627
+ const tree = resolveBookTree(book, docs, book._packageId);
1628
+ res.json(tree);
1629
+ } catch (error) {
1630
+ logError("[REST] Unhandled error:", error);
1631
+ sendError(res, error);
1632
+ }
1633
+ },
1634
+ metadata: {
1635
+ summary: "Resolve a documentation book spine into its rendered tree (ADR-0046 \xA76)",
1636
+ tags: ["metadata"]
1637
+ }
1638
+ });
1589
1639
  this.routeManager.register({
1590
1640
  method: "GET",
1591
1641
  path: `${metaPath}/:type/:name`,