@digilogiclabs/platform-core 1.24.0 → 1.25.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/auth.d.mts +23 -0
- package/dist/auth.d.ts +23 -0
- package/dist/auth.js +18 -4
- package/dist/auth.js.map +1 -1
- package/dist/auth.mjs +18 -4
- package/dist/auth.mjs.map +1 -1
- package/dist/migrate.js +0 -0
- package/package.json +11 -11
package/dist/auth.mjs
CHANGED
|
@@ -1541,9 +1541,8 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1541
1541
|
const resolvedAuditAction = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.action : auditCfg;
|
|
1542
1542
|
const resolvedAuditResource = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.resource : routeConfig.auditResource;
|
|
1543
1543
|
const resolvedGetResourceId = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.getResourceId : routeConfig.getResourceId;
|
|
1544
|
-
const
|
|
1545
|
-
if (!factoryConfig.
|
|
1546
|
-
const action = factoryConfig.blockedAuditAction ?? "unauthorized_access";
|
|
1544
|
+
const writeBlockedAudit = async (action, reason, metadata) => {
|
|
1545
|
+
if (!factoryConfig.auditLog) return;
|
|
1547
1546
|
try {
|
|
1548
1547
|
await factoryConfig.auditLog({
|
|
1549
1548
|
actor: session?.user ? {
|
|
@@ -1554,11 +1553,19 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1554
1553
|
action,
|
|
1555
1554
|
resource: resolvedAuditResource ? { type: resolvedAuditResource, id: "unknown" } : void 0,
|
|
1556
1555
|
outcome: "blocked",
|
|
1557
|
-
reason
|
|
1556
|
+
reason,
|
|
1557
|
+
metadata
|
|
1558
1558
|
});
|
|
1559
1559
|
} catch {
|
|
1560
1560
|
}
|
|
1561
1561
|
};
|
|
1562
|
+
const emitBlockedAudit = async (reason) => {
|
|
1563
|
+
if (!factoryConfig.auditOnBlocked) return;
|
|
1564
|
+
await writeBlockedAudit(
|
|
1565
|
+
factoryConfig.blockedAuditAction ?? "unauthorized_access",
|
|
1566
|
+
reason
|
|
1567
|
+
);
|
|
1568
|
+
};
|
|
1562
1569
|
try {
|
|
1563
1570
|
if (routeConfig.requireAuth || routeConfig.requireAdmin || routeConfig.requireRoles?.length) {
|
|
1564
1571
|
session = await factoryConfig.getSession();
|
|
@@ -1633,6 +1640,13 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1633
1640
|
const result = routeConfig.validate.safeParse(input);
|
|
1634
1641
|
if (!result.success) {
|
|
1635
1642
|
const fieldErrors = result.error?.flatten ? result.error.flatten().fieldErrors : void 0;
|
|
1643
|
+
if (factoryConfig.auditOnInvalidInput && resolvedAuditAction) {
|
|
1644
|
+
await writeBlockedAudit(
|
|
1645
|
+
factoryConfig.invalidInputAuditAction ?? "invalid_input",
|
|
1646
|
+
"Input validation failed",
|
|
1647
|
+
fieldErrors ? { errors: fieldErrors } : void 0
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1636
1650
|
return Response.json(
|
|
1637
1651
|
{ error: "Validation error", errors: fieldErrors },
|
|
1638
1652
|
{ status: 400, headers: { "X-Request-ID": requestId } }
|