@objectstack/rest 7.0.0 → 7.2.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 +191 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +191 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1315,6 +1315,40 @@ var RestServer = class {
|
|
|
1315
1315
|
}
|
|
1316
1316
|
});
|
|
1317
1317
|
}
|
|
1318
|
+
if (metadata.endpoints.items !== false) {
|
|
1319
|
+
this.routeManager.register({
|
|
1320
|
+
method: "GET",
|
|
1321
|
+
path: `${metaPath}/diagnostics`,
|
|
1322
|
+
handler: async (req, res) => {
|
|
1323
|
+
try {
|
|
1324
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1325
|
+
const p = await this.resolveProtocol(environmentId, req);
|
|
1326
|
+
if (typeof p.getMetaDiagnostics !== "function") {
|
|
1327
|
+
res.status(501).json({
|
|
1328
|
+
error: "not_implemented",
|
|
1329
|
+
message: "protocol.getMetaDiagnostics() is not available in this kernel"
|
|
1330
|
+
});
|
|
1331
|
+
return;
|
|
1332
|
+
}
|
|
1333
|
+
const severityParam = req.query?.severity ?? "error";
|
|
1334
|
+
const severity = severityParam === "warning" ? "warning" : "error";
|
|
1335
|
+
const result = await p.getMetaDiagnostics({
|
|
1336
|
+
type: req.query?.type || void 0,
|
|
1337
|
+
severity,
|
|
1338
|
+
packageId: req.query?.package || void 0
|
|
1339
|
+
});
|
|
1340
|
+
res.json(result);
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
logError("[REST] Unhandled error:", error);
|
|
1343
|
+
sendError(res, error);
|
|
1344
|
+
}
|
|
1345
|
+
},
|
|
1346
|
+
metadata: {
|
|
1347
|
+
summary: "List metadata entries that fail spec validation",
|
|
1348
|
+
tags: ["metadata"]
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1318
1352
|
if (metadata.endpoints.items !== false) {
|
|
1319
1353
|
this.routeManager.register({
|
|
1320
1354
|
method: "GET",
|
|
@@ -1404,7 +1438,8 @@ var RestServer = class {
|
|
|
1404
1438
|
return;
|
|
1405
1439
|
}
|
|
1406
1440
|
const isAppType = req.params.type === "app";
|
|
1407
|
-
|
|
1441
|
+
const isDraftRead = typeof req.query?.state === "string" && req.query.state.toLowerCase() === "draft";
|
|
1442
|
+
if (metadata.enableCache && p.getMetaItemCached && !isAppType && !isDraftRead) {
|
|
1408
1443
|
const cacheRequest = {
|
|
1409
1444
|
ifNoneMatch: req.headers["if-none-match"],
|
|
1410
1445
|
ifModifiedSince: req.headers["if-modified-since"]
|
|
@@ -1435,10 +1470,12 @@ var RestServer = class {
|
|
|
1435
1470
|
res.json(await this.translateMetaItem(req, req.params.type, environmentId, result.data));
|
|
1436
1471
|
} else {
|
|
1437
1472
|
const packageId = req.query?.package || void 0;
|
|
1473
|
+
const stateParam = typeof req.query?.state === "string" ? req.query.state.toLowerCase() : void 0;
|
|
1438
1474
|
const item = await p.getMetaItem({
|
|
1439
1475
|
type: req.params.type,
|
|
1440
1476
|
name: req.params.name,
|
|
1441
|
-
packageId
|
|
1477
|
+
packageId,
|
|
1478
|
+
...stateParam === "draft" ? { state: "draft" } : {}
|
|
1442
1479
|
});
|
|
1443
1480
|
let visible = item;
|
|
1444
1481
|
if (isAppType && item) {
|
|
@@ -1497,7 +1534,8 @@ var RestServer = class {
|
|
|
1497
1534
|
...environmentId ? { environmentId } : {},
|
|
1498
1535
|
...parentVersion !== void 0 ? { parentVersion } : {},
|
|
1499
1536
|
...actor ? { actor } : {},
|
|
1500
|
-
...force ? { force: true } : {}
|
|
1537
|
+
...force ? { force: true } : {},
|
|
1538
|
+
...typeof req.query?.mode === "string" && req.query.mode.toLowerCase() === "draft" ? { mode: "draft" } : {}
|
|
1501
1539
|
});
|
|
1502
1540
|
res.json(result);
|
|
1503
1541
|
} catch (error) {
|
|
@@ -1527,12 +1565,14 @@ var RestServer = class {
|
|
|
1527
1565
|
const parentVersion = typeof ifMatchHeader === "string" ? ifMatchHeader.replace(/^"|"$/g, "") : void 0;
|
|
1528
1566
|
const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
|
|
1529
1567
|
const actor = typeof actorHeader === "string" ? actorHeader : void 0;
|
|
1568
|
+
const stateParam = typeof req.query?.state === "string" && req.query.state.toLowerCase() === "draft" ? "draft" : void 0;
|
|
1530
1569
|
const result = await p.deleteMetaItem({
|
|
1531
1570
|
type: req.params.type,
|
|
1532
1571
|
name: req.params.name,
|
|
1533
1572
|
...environmentId ? { environmentId } : {},
|
|
1534
1573
|
...parentVersion !== void 0 ? { parentVersion } : {},
|
|
1535
|
-
...actor ? { actor } : {}
|
|
1574
|
+
...actor ? { actor } : {},
|
|
1575
|
+
...stateParam ? { state: stateParam } : {}
|
|
1536
1576
|
});
|
|
1537
1577
|
res.json(result);
|
|
1538
1578
|
} catch (error) {
|
|
@@ -1578,6 +1618,153 @@ var RestServer = class {
|
|
|
1578
1618
|
tags: ["metadata"]
|
|
1579
1619
|
}
|
|
1580
1620
|
});
|
|
1621
|
+
this.routeManager.register({
|
|
1622
|
+
method: "GET",
|
|
1623
|
+
path: `${metaPath}/:type/:name/audit`,
|
|
1624
|
+
handler: async (req, res) => {
|
|
1625
|
+
try {
|
|
1626
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1627
|
+
const p = await this.resolveProtocol(environmentId, req);
|
|
1628
|
+
if (typeof p.auditMetaItem !== "function") {
|
|
1629
|
+
res.json({ events: [] });
|
|
1630
|
+
return;
|
|
1631
|
+
}
|
|
1632
|
+
const limit = req.query?.limit !== void 0 ? Number(req.query.limit) : void 0;
|
|
1633
|
+
const result = await p.auditMetaItem({
|
|
1634
|
+
type: req.params.type,
|
|
1635
|
+
name: req.params.name,
|
|
1636
|
+
...environmentId ? { environmentId } : {},
|
|
1637
|
+
...limit !== void 0 && Number.isFinite(limit) ? { limit } : {}
|
|
1638
|
+
});
|
|
1639
|
+
res.json(result);
|
|
1640
|
+
} catch (error) {
|
|
1641
|
+
logError("[REST] Unhandled error:", error);
|
|
1642
|
+
sendError(res, error);
|
|
1643
|
+
}
|
|
1644
|
+
},
|
|
1645
|
+
metadata: {
|
|
1646
|
+
summary: "List protection-audit events for a metadata item",
|
|
1647
|
+
tags: ["metadata"]
|
|
1648
|
+
}
|
|
1649
|
+
});
|
|
1650
|
+
this.routeManager.register({
|
|
1651
|
+
method: "POST",
|
|
1652
|
+
path: `${metaPath}/:type/:name/publish`,
|
|
1653
|
+
handler: async (req, res) => {
|
|
1654
|
+
try {
|
|
1655
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1656
|
+
const p = await this.resolveProtocol(environmentId, req);
|
|
1657
|
+
if (!p.publishMetaItem) {
|
|
1658
|
+
res.status(501).json({
|
|
1659
|
+
error: "Publish operation not supported by protocol implementation"
|
|
1660
|
+
});
|
|
1661
|
+
return;
|
|
1662
|
+
}
|
|
1663
|
+
const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
|
|
1664
|
+
const actor = typeof actorHeader === "string" ? actorHeader : void 0;
|
|
1665
|
+
const body = req.body && typeof req.body === "object" ? req.body : {};
|
|
1666
|
+
const message = typeof body.message === "string" ? body.message : void 0;
|
|
1667
|
+
const result = await p.publishMetaItem({
|
|
1668
|
+
type: req.params.type,
|
|
1669
|
+
name: req.params.name,
|
|
1670
|
+
...environmentId ? { environmentId } : {},
|
|
1671
|
+
...actor ? { actor } : {},
|
|
1672
|
+
...message ? { message } : {}
|
|
1673
|
+
});
|
|
1674
|
+
res.json(result);
|
|
1675
|
+
} catch (error) {
|
|
1676
|
+
logError("[REST] Unhandled error:", error);
|
|
1677
|
+
sendError(res, error);
|
|
1678
|
+
}
|
|
1679
|
+
},
|
|
1680
|
+
metadata: {
|
|
1681
|
+
summary: "Publish the pending draft overlay (promotes draft \u2192 active)",
|
|
1682
|
+
tags: ["metadata"]
|
|
1683
|
+
}
|
|
1684
|
+
});
|
|
1685
|
+
this.routeManager.register({
|
|
1686
|
+
method: "POST",
|
|
1687
|
+
path: `${metaPath}/:type/:name/rollback`,
|
|
1688
|
+
handler: async (req, res) => {
|
|
1689
|
+
try {
|
|
1690
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1691
|
+
const p = await this.resolveProtocol(environmentId, req);
|
|
1692
|
+
if (!p.rollbackMetaItem) {
|
|
1693
|
+
res.status(501).json({
|
|
1694
|
+
error: "Rollback operation not supported by protocol implementation"
|
|
1695
|
+
});
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1698
|
+
const body = req.body && typeof req.body === "object" ? req.body : {};
|
|
1699
|
+
const toVersionRaw = body.toVersion ?? body.version ?? req.query?.toVersion;
|
|
1700
|
+
const toVersion = Number(toVersionRaw);
|
|
1701
|
+
if (!Number.isFinite(toVersion) || toVersion < 1) {
|
|
1702
|
+
res.status(400).json({
|
|
1703
|
+
error: `'toVersion' (positive integer) is required`,
|
|
1704
|
+
code: "invalid_request"
|
|
1705
|
+
});
|
|
1706
|
+
return;
|
|
1707
|
+
}
|
|
1708
|
+
const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
|
|
1709
|
+
const actor = typeof actorHeader === "string" ? actorHeader : void 0;
|
|
1710
|
+
const message = typeof body.message === "string" ? body.message : void 0;
|
|
1711
|
+
const result = await p.rollbackMetaItem({
|
|
1712
|
+
type: req.params.type,
|
|
1713
|
+
name: req.params.name,
|
|
1714
|
+
toVersion,
|
|
1715
|
+
...environmentId ? { environmentId } : {},
|
|
1716
|
+
...actor ? { actor } : {},
|
|
1717
|
+
...message ? { message } : {}
|
|
1718
|
+
});
|
|
1719
|
+
res.json(result);
|
|
1720
|
+
} catch (error) {
|
|
1721
|
+
logError("[REST] Unhandled error:", error);
|
|
1722
|
+
sendError(res, error);
|
|
1723
|
+
}
|
|
1724
|
+
},
|
|
1725
|
+
metadata: {
|
|
1726
|
+
summary: "Restore the body at the given history version as the new live row",
|
|
1727
|
+
tags: ["metadata"]
|
|
1728
|
+
}
|
|
1729
|
+
});
|
|
1730
|
+
this.routeManager.register({
|
|
1731
|
+
method: "GET",
|
|
1732
|
+
path: `${metaPath}/:type/:name/diff`,
|
|
1733
|
+
handler: async (req, res) => {
|
|
1734
|
+
try {
|
|
1735
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1736
|
+
const p = await this.resolveProtocol(environmentId, req);
|
|
1737
|
+
if (!p.diffMetaItem) {
|
|
1738
|
+
res.status(501).json({
|
|
1739
|
+
error: "Diff operation not supported by protocol implementation"
|
|
1740
|
+
});
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
const parseV = (raw) => {
|
|
1744
|
+
if (raw === void 0 || raw === null || raw === "") return void 0;
|
|
1745
|
+
const n = Number(raw);
|
|
1746
|
+
return Number.isFinite(n) ? n : void 0;
|
|
1747
|
+
};
|
|
1748
|
+
const fromVersion = parseV(req.query?.from ?? req.query?.fromVersion);
|
|
1749
|
+
const toVersion = parseV(req.query?.to ?? req.query?.toVersion);
|
|
1750
|
+
const result = await p.diffMetaItem({
|
|
1751
|
+
type: req.params.type,
|
|
1752
|
+
name: req.params.name,
|
|
1753
|
+
...environmentId ? { environmentId } : {},
|
|
1754
|
+
...fromVersion !== void 0 ? { fromVersion } : {},
|
|
1755
|
+
...toVersion !== void 0 ? { toVersion } : {}
|
|
1756
|
+
});
|
|
1757
|
+
res.json(result);
|
|
1758
|
+
} catch (error) {
|
|
1759
|
+
logError("[REST] Unhandled error:", error);
|
|
1760
|
+
sendError(res, error);
|
|
1761
|
+
}
|
|
1762
|
+
},
|
|
1763
|
+
metadata: {
|
|
1764
|
+
summary: "Diff two metadata versions (from/to query params; omit for previous-vs-current)",
|
|
1765
|
+
tags: ["metadata"]
|
|
1766
|
+
}
|
|
1767
|
+
});
|
|
1581
1768
|
if (metadata.endpoints.item !== false) {
|
|
1582
1769
|
this.routeManager.register({
|
|
1583
1770
|
method: "GET",
|