@digilogiclabs/platform-core 1.24.0 → 1.26.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 +447 -413
- package/dist/auth.d.ts +447 -413
- package/dist/auth.js +25 -4
- package/dist/auth.js.map +1 -1
- package/dist/auth.mjs +25 -4
- package/dist/auth.mjs.map +1 -1
- package/package.json +1 -1
package/dist/auth.mjs
CHANGED
|
@@ -1105,6 +1105,13 @@ async function enforceRateLimit(request, operation, rule, options) {
|
|
|
1105
1105
|
}
|
|
1106
1106
|
);
|
|
1107
1107
|
}
|
|
1108
|
+
if (options?.returnInfo) {
|
|
1109
|
+
return {
|
|
1110
|
+
limit: result.limit,
|
|
1111
|
+
remaining: result.remaining,
|
|
1112
|
+
resetMs: result.resetAt
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1108
1115
|
return null;
|
|
1109
1116
|
}
|
|
1110
1117
|
function errorResponse(error, options) {
|
|
@@ -1541,9 +1548,8 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1541
1548
|
const resolvedAuditAction = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.action : auditCfg;
|
|
1542
1549
|
const resolvedAuditResource = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.resource : routeConfig.auditResource;
|
|
1543
1550
|
const resolvedGetResourceId = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.getResourceId : routeConfig.getResourceId;
|
|
1544
|
-
const
|
|
1545
|
-
if (!factoryConfig.
|
|
1546
|
-
const action = factoryConfig.blockedAuditAction ?? "unauthorized_access";
|
|
1551
|
+
const writeBlockedAudit = async (action, reason, metadata) => {
|
|
1552
|
+
if (!factoryConfig.auditLog) return;
|
|
1547
1553
|
try {
|
|
1548
1554
|
await factoryConfig.auditLog({
|
|
1549
1555
|
actor: session?.user ? {
|
|
@@ -1554,11 +1560,19 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1554
1560
|
action,
|
|
1555
1561
|
resource: resolvedAuditResource ? { type: resolvedAuditResource, id: "unknown" } : void 0,
|
|
1556
1562
|
outcome: "blocked",
|
|
1557
|
-
reason
|
|
1563
|
+
reason,
|
|
1564
|
+
metadata
|
|
1558
1565
|
});
|
|
1559
1566
|
} catch {
|
|
1560
1567
|
}
|
|
1561
1568
|
};
|
|
1569
|
+
const emitBlockedAudit = async (reason) => {
|
|
1570
|
+
if (!factoryConfig.auditOnBlocked) return;
|
|
1571
|
+
await writeBlockedAudit(
|
|
1572
|
+
factoryConfig.blockedAuditAction ?? "unauthorized_access",
|
|
1573
|
+
reason
|
|
1574
|
+
);
|
|
1575
|
+
};
|
|
1562
1576
|
try {
|
|
1563
1577
|
if (routeConfig.requireAuth || routeConfig.requireAdmin || routeConfig.requireRoles?.length) {
|
|
1564
1578
|
session = await factoryConfig.getSession();
|
|
@@ -1633,6 +1647,13 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1633
1647
|
const result = routeConfig.validate.safeParse(input);
|
|
1634
1648
|
if (!result.success) {
|
|
1635
1649
|
const fieldErrors = result.error?.flatten ? result.error.flatten().fieldErrors : void 0;
|
|
1650
|
+
if (factoryConfig.auditOnInvalidInput && resolvedAuditAction) {
|
|
1651
|
+
await writeBlockedAudit(
|
|
1652
|
+
factoryConfig.invalidInputAuditAction ?? "invalid_input",
|
|
1653
|
+
"Input validation failed",
|
|
1654
|
+
fieldErrors ? { errors: fieldErrors } : void 0
|
|
1655
|
+
);
|
|
1656
|
+
}
|
|
1636
1657
|
return Response.json(
|
|
1637
1658
|
{ error: "Validation error", errors: fieldErrors },
|
|
1638
1659
|
{ status: 400, headers: { "X-Request-ID": requestId } }
|