@objectstack/rest 7.0.0 → 7.1.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 +162 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +162 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1275,6 +1275,40 @@ var RestServer = class {
|
|
|
1275
1275
|
}
|
|
1276
1276
|
});
|
|
1277
1277
|
}
|
|
1278
|
+
if (metadata.endpoints.items !== false) {
|
|
1279
|
+
this.routeManager.register({
|
|
1280
|
+
method: "GET",
|
|
1281
|
+
path: `${metaPath}/diagnostics`,
|
|
1282
|
+
handler: async (req, res) => {
|
|
1283
|
+
try {
|
|
1284
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1285
|
+
const p = await this.resolveProtocol(environmentId, req);
|
|
1286
|
+
if (typeof p.getMetaDiagnostics !== "function") {
|
|
1287
|
+
res.status(501).json({
|
|
1288
|
+
error: "not_implemented",
|
|
1289
|
+
message: "protocol.getMetaDiagnostics() is not available in this kernel"
|
|
1290
|
+
});
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
const severityParam = req.query?.severity ?? "error";
|
|
1294
|
+
const severity = severityParam === "warning" ? "warning" : "error";
|
|
1295
|
+
const result = await p.getMetaDiagnostics({
|
|
1296
|
+
type: req.query?.type || void 0,
|
|
1297
|
+
severity,
|
|
1298
|
+
packageId: req.query?.package || void 0
|
|
1299
|
+
});
|
|
1300
|
+
res.json(result);
|
|
1301
|
+
} catch (error) {
|
|
1302
|
+
logError("[REST] Unhandled error:", error);
|
|
1303
|
+
sendError(res, error);
|
|
1304
|
+
}
|
|
1305
|
+
},
|
|
1306
|
+
metadata: {
|
|
1307
|
+
summary: "List metadata entries that fail spec validation",
|
|
1308
|
+
tags: ["metadata"]
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1278
1312
|
if (metadata.endpoints.items !== false) {
|
|
1279
1313
|
this.routeManager.register({
|
|
1280
1314
|
method: "GET",
|
|
@@ -1364,7 +1398,8 @@ var RestServer = class {
|
|
|
1364
1398
|
return;
|
|
1365
1399
|
}
|
|
1366
1400
|
const isAppType = req.params.type === "app";
|
|
1367
|
-
|
|
1401
|
+
const isDraftRead = typeof req.query?.state === "string" && req.query.state.toLowerCase() === "draft";
|
|
1402
|
+
if (metadata.enableCache && p.getMetaItemCached && !isAppType && !isDraftRead) {
|
|
1368
1403
|
const cacheRequest = {
|
|
1369
1404
|
ifNoneMatch: req.headers["if-none-match"],
|
|
1370
1405
|
ifModifiedSince: req.headers["if-modified-since"]
|
|
@@ -1395,10 +1430,12 @@ var RestServer = class {
|
|
|
1395
1430
|
res.json(await this.translateMetaItem(req, req.params.type, environmentId, result.data));
|
|
1396
1431
|
} else {
|
|
1397
1432
|
const packageId = req.query?.package || void 0;
|
|
1433
|
+
const stateParam = typeof req.query?.state === "string" ? req.query.state.toLowerCase() : void 0;
|
|
1398
1434
|
const item = await p.getMetaItem({
|
|
1399
1435
|
type: req.params.type,
|
|
1400
1436
|
name: req.params.name,
|
|
1401
|
-
packageId
|
|
1437
|
+
packageId,
|
|
1438
|
+
...stateParam === "draft" ? { state: "draft" } : {}
|
|
1402
1439
|
});
|
|
1403
1440
|
let visible = item;
|
|
1404
1441
|
if (isAppType && item) {
|
|
@@ -1457,7 +1494,8 @@ var RestServer = class {
|
|
|
1457
1494
|
...environmentId ? { environmentId } : {},
|
|
1458
1495
|
...parentVersion !== void 0 ? { parentVersion } : {},
|
|
1459
1496
|
...actor ? { actor } : {},
|
|
1460
|
-
...force ? { force: true } : {}
|
|
1497
|
+
...force ? { force: true } : {},
|
|
1498
|
+
...typeof req.query?.mode === "string" && req.query.mode.toLowerCase() === "draft" ? { mode: "draft" } : {}
|
|
1461
1499
|
});
|
|
1462
1500
|
res.json(result);
|
|
1463
1501
|
} catch (error) {
|
|
@@ -1487,12 +1525,14 @@ var RestServer = class {
|
|
|
1487
1525
|
const parentVersion = typeof ifMatchHeader === "string" ? ifMatchHeader.replace(/^"|"$/g, "") : void 0;
|
|
1488
1526
|
const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
|
|
1489
1527
|
const actor = typeof actorHeader === "string" ? actorHeader : void 0;
|
|
1528
|
+
const stateParam = typeof req.query?.state === "string" && req.query.state.toLowerCase() === "draft" ? "draft" : void 0;
|
|
1490
1529
|
const result = await p.deleteMetaItem({
|
|
1491
1530
|
type: req.params.type,
|
|
1492
1531
|
name: req.params.name,
|
|
1493
1532
|
...environmentId ? { environmentId } : {},
|
|
1494
1533
|
...parentVersion !== void 0 ? { parentVersion } : {},
|
|
1495
|
-
...actor ? { actor } : {}
|
|
1534
|
+
...actor ? { actor } : {},
|
|
1535
|
+
...stateParam ? { state: stateParam } : {}
|
|
1496
1536
|
});
|
|
1497
1537
|
res.json(result);
|
|
1498
1538
|
} catch (error) {
|
|
@@ -1538,6 +1578,124 @@ var RestServer = class {
|
|
|
1538
1578
|
tags: ["metadata"]
|
|
1539
1579
|
}
|
|
1540
1580
|
});
|
|
1581
|
+
this.routeManager.register({
|
|
1582
|
+
method: "POST",
|
|
1583
|
+
path: `${metaPath}/:type/:name/publish`,
|
|
1584
|
+
handler: async (req, res) => {
|
|
1585
|
+
try {
|
|
1586
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1587
|
+
const p = await this.resolveProtocol(environmentId, req);
|
|
1588
|
+
if (!p.publishMetaItem) {
|
|
1589
|
+
res.status(501).json({
|
|
1590
|
+
error: "Publish operation not supported by protocol implementation"
|
|
1591
|
+
});
|
|
1592
|
+
return;
|
|
1593
|
+
}
|
|
1594
|
+
const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
|
|
1595
|
+
const actor = typeof actorHeader === "string" ? actorHeader : void 0;
|
|
1596
|
+
const body = req.body && typeof req.body === "object" ? req.body : {};
|
|
1597
|
+
const message = typeof body.message === "string" ? body.message : void 0;
|
|
1598
|
+
const result = await p.publishMetaItem({
|
|
1599
|
+
type: req.params.type,
|
|
1600
|
+
name: req.params.name,
|
|
1601
|
+
...environmentId ? { environmentId } : {},
|
|
1602
|
+
...actor ? { actor } : {},
|
|
1603
|
+
...message ? { message } : {}
|
|
1604
|
+
});
|
|
1605
|
+
res.json(result);
|
|
1606
|
+
} catch (error) {
|
|
1607
|
+
logError("[REST] Unhandled error:", error);
|
|
1608
|
+
sendError(res, error);
|
|
1609
|
+
}
|
|
1610
|
+
},
|
|
1611
|
+
metadata: {
|
|
1612
|
+
summary: "Publish the pending draft overlay (promotes draft \u2192 active)",
|
|
1613
|
+
tags: ["metadata"]
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
this.routeManager.register({
|
|
1617
|
+
method: "POST",
|
|
1618
|
+
path: `${metaPath}/:type/:name/rollback`,
|
|
1619
|
+
handler: async (req, res) => {
|
|
1620
|
+
try {
|
|
1621
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1622
|
+
const p = await this.resolveProtocol(environmentId, req);
|
|
1623
|
+
if (!p.rollbackMetaItem) {
|
|
1624
|
+
res.status(501).json({
|
|
1625
|
+
error: "Rollback operation not supported by protocol implementation"
|
|
1626
|
+
});
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
const body = req.body && typeof req.body === "object" ? req.body : {};
|
|
1630
|
+
const toVersionRaw = body.toVersion ?? body.version ?? req.query?.toVersion;
|
|
1631
|
+
const toVersion = Number(toVersionRaw);
|
|
1632
|
+
if (!Number.isFinite(toVersion) || toVersion < 1) {
|
|
1633
|
+
res.status(400).json({
|
|
1634
|
+
error: `'toVersion' (positive integer) is required`,
|
|
1635
|
+
code: "invalid_request"
|
|
1636
|
+
});
|
|
1637
|
+
return;
|
|
1638
|
+
}
|
|
1639
|
+
const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
|
|
1640
|
+
const actor = typeof actorHeader === "string" ? actorHeader : void 0;
|
|
1641
|
+
const message = typeof body.message === "string" ? body.message : void 0;
|
|
1642
|
+
const result = await p.rollbackMetaItem({
|
|
1643
|
+
type: req.params.type,
|
|
1644
|
+
name: req.params.name,
|
|
1645
|
+
toVersion,
|
|
1646
|
+
...environmentId ? { environmentId } : {},
|
|
1647
|
+
...actor ? { actor } : {},
|
|
1648
|
+
...message ? { message } : {}
|
|
1649
|
+
});
|
|
1650
|
+
res.json(result);
|
|
1651
|
+
} catch (error) {
|
|
1652
|
+
logError("[REST] Unhandled error:", error);
|
|
1653
|
+
sendError(res, error);
|
|
1654
|
+
}
|
|
1655
|
+
},
|
|
1656
|
+
metadata: {
|
|
1657
|
+
summary: "Restore the body at the given history version as the new live row",
|
|
1658
|
+
tags: ["metadata"]
|
|
1659
|
+
}
|
|
1660
|
+
});
|
|
1661
|
+
this.routeManager.register({
|
|
1662
|
+
method: "GET",
|
|
1663
|
+
path: `${metaPath}/:type/:name/diff`,
|
|
1664
|
+
handler: async (req, res) => {
|
|
1665
|
+
try {
|
|
1666
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1667
|
+
const p = await this.resolveProtocol(environmentId, req);
|
|
1668
|
+
if (!p.diffMetaItem) {
|
|
1669
|
+
res.status(501).json({
|
|
1670
|
+
error: "Diff operation not supported by protocol implementation"
|
|
1671
|
+
});
|
|
1672
|
+
return;
|
|
1673
|
+
}
|
|
1674
|
+
const parseV = (raw) => {
|
|
1675
|
+
if (raw === void 0 || raw === null || raw === "") return void 0;
|
|
1676
|
+
const n = Number(raw);
|
|
1677
|
+
return Number.isFinite(n) ? n : void 0;
|
|
1678
|
+
};
|
|
1679
|
+
const fromVersion = parseV(req.query?.from ?? req.query?.fromVersion);
|
|
1680
|
+
const toVersion = parseV(req.query?.to ?? req.query?.toVersion);
|
|
1681
|
+
const result = await p.diffMetaItem({
|
|
1682
|
+
type: req.params.type,
|
|
1683
|
+
name: req.params.name,
|
|
1684
|
+
...environmentId ? { environmentId } : {},
|
|
1685
|
+
...fromVersion !== void 0 ? { fromVersion } : {},
|
|
1686
|
+
...toVersion !== void 0 ? { toVersion } : {}
|
|
1687
|
+
});
|
|
1688
|
+
res.json(result);
|
|
1689
|
+
} catch (error) {
|
|
1690
|
+
logError("[REST] Unhandled error:", error);
|
|
1691
|
+
sendError(res, error);
|
|
1692
|
+
}
|
|
1693
|
+
},
|
|
1694
|
+
metadata: {
|
|
1695
|
+
summary: "Diff two metadata versions (from/to query params; omit for previous-vs-current)",
|
|
1696
|
+
tags: ["metadata"]
|
|
1697
|
+
}
|
|
1698
|
+
});
|
|
1541
1699
|
if (metadata.endpoints.item !== false) {
|
|
1542
1700
|
this.routeManager.register({
|
|
1543
1701
|
method: "GET",
|