@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.js CHANGED
@@ -1237,6 +1237,13 @@ async function enforceRateLimit(request, operation, rule, options) {
1237
1237
  }
1238
1238
  );
1239
1239
  }
1240
+ if (options?.returnInfo) {
1241
+ return {
1242
+ limit: result.limit,
1243
+ remaining: result.remaining,
1244
+ resetMs: result.resetAt
1245
+ };
1246
+ }
1240
1247
  return null;
1241
1248
  }
1242
1249
  function errorResponse(error, options) {
@@ -1673,9 +1680,8 @@ function createSecureHandlerFactory(factoryConfig) {
1673
1680
  const resolvedAuditAction = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.action : auditCfg;
1674
1681
  const resolvedAuditResource = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.resource : routeConfig.auditResource;
1675
1682
  const resolvedGetResourceId = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.getResourceId : routeConfig.getResourceId;
1676
- const emitBlockedAudit = async (reason) => {
1677
- if (!factoryConfig.auditOnBlocked || !factoryConfig.auditLog) return;
1678
- const action = factoryConfig.blockedAuditAction ?? "unauthorized_access";
1683
+ const writeBlockedAudit = async (action, reason, metadata) => {
1684
+ if (!factoryConfig.auditLog) return;
1679
1685
  try {
1680
1686
  await factoryConfig.auditLog({
1681
1687
  actor: session?.user ? {
@@ -1686,11 +1692,19 @@ function createSecureHandlerFactory(factoryConfig) {
1686
1692
  action,
1687
1693
  resource: resolvedAuditResource ? { type: resolvedAuditResource, id: "unknown" } : void 0,
1688
1694
  outcome: "blocked",
1689
- reason
1695
+ reason,
1696
+ metadata
1690
1697
  });
1691
1698
  } catch {
1692
1699
  }
1693
1700
  };
1701
+ const emitBlockedAudit = async (reason) => {
1702
+ if (!factoryConfig.auditOnBlocked) return;
1703
+ await writeBlockedAudit(
1704
+ factoryConfig.blockedAuditAction ?? "unauthorized_access",
1705
+ reason
1706
+ );
1707
+ };
1694
1708
  try {
1695
1709
  if (routeConfig.requireAuth || routeConfig.requireAdmin || routeConfig.requireRoles?.length) {
1696
1710
  session = await factoryConfig.getSession();
@@ -1765,6 +1779,13 @@ function createSecureHandlerFactory(factoryConfig) {
1765
1779
  const result = routeConfig.validate.safeParse(input);
1766
1780
  if (!result.success) {
1767
1781
  const fieldErrors = result.error?.flatten ? result.error.flatten().fieldErrors : void 0;
1782
+ if (factoryConfig.auditOnInvalidInput && resolvedAuditAction) {
1783
+ await writeBlockedAudit(
1784
+ factoryConfig.invalidInputAuditAction ?? "invalid_input",
1785
+ "Input validation failed",
1786
+ fieldErrors ? { errors: fieldErrors } : void 0
1787
+ );
1788
+ }
1768
1789
  return Response.json(
1769
1790
  { error: "Validation error", errors: fieldErrors },
1770
1791
  { status: 400, headers: { "X-Request-ID": requestId } }