@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.d.mts
CHANGED
|
@@ -624,6 +624,29 @@ interface SecureHandlerFactoryConfig<TSession extends SecureSession = SecureSess
|
|
|
624
624
|
* @default 'unauthorized_access'
|
|
625
625
|
*/
|
|
626
626
|
blockedAuditAction?: string;
|
|
627
|
+
/**
|
|
628
|
+
* Emit `outcome: 'blocked'` audit events when a request is rejected by
|
|
629
|
+
* input validation (the `validate.safeParse` 400 branch). Mirrors DLL's
|
|
630
|
+
* `INVALID_INPUT` audit. Only fires for routes that declare audit config
|
|
631
|
+
* (i.e. `audit` / `auditResource` is set) — routes without audit config
|
|
632
|
+
* are not audited on validation failure, matching the success-audit gate.
|
|
633
|
+
*
|
|
634
|
+
* The emitted event carries `metadata.errors` (the flattened field errors)
|
|
635
|
+
* when the validator exposes a `flatten()`.
|
|
636
|
+
*
|
|
637
|
+
* Requires `auditLog` to be configured — has no effect otherwise.
|
|
638
|
+
*
|
|
639
|
+
* @default false
|
|
640
|
+
*/
|
|
641
|
+
auditOnInvalidInput?: boolean;
|
|
642
|
+
/**
|
|
643
|
+
* Action string used for validation-failure audit events (when
|
|
644
|
+
* `auditOnInvalidInput: true`). Apps with structured audit-action enums
|
|
645
|
+
* should pass that enum value here (e.g. DLL's `AuditAction.INVALID_INPUT`).
|
|
646
|
+
*
|
|
647
|
+
* @default 'invalid_input'
|
|
648
|
+
*/
|
|
649
|
+
invalidInputAuditAction?: string;
|
|
627
650
|
}
|
|
628
651
|
/** Timed audit helper placed on context for handler-level audit control */
|
|
629
652
|
interface SecureTimedAudit {
|
package/dist/auth.d.ts
CHANGED
|
@@ -624,6 +624,29 @@ interface SecureHandlerFactoryConfig<TSession extends SecureSession = SecureSess
|
|
|
624
624
|
* @default 'unauthorized_access'
|
|
625
625
|
*/
|
|
626
626
|
blockedAuditAction?: string;
|
|
627
|
+
/**
|
|
628
|
+
* Emit `outcome: 'blocked'` audit events when a request is rejected by
|
|
629
|
+
* input validation (the `validate.safeParse` 400 branch). Mirrors DLL's
|
|
630
|
+
* `INVALID_INPUT` audit. Only fires for routes that declare audit config
|
|
631
|
+
* (i.e. `audit` / `auditResource` is set) — routes without audit config
|
|
632
|
+
* are not audited on validation failure, matching the success-audit gate.
|
|
633
|
+
*
|
|
634
|
+
* The emitted event carries `metadata.errors` (the flattened field errors)
|
|
635
|
+
* when the validator exposes a `flatten()`.
|
|
636
|
+
*
|
|
637
|
+
* Requires `auditLog` to be configured — has no effect otherwise.
|
|
638
|
+
*
|
|
639
|
+
* @default false
|
|
640
|
+
*/
|
|
641
|
+
auditOnInvalidInput?: boolean;
|
|
642
|
+
/**
|
|
643
|
+
* Action string used for validation-failure audit events (when
|
|
644
|
+
* `auditOnInvalidInput: true`). Apps with structured audit-action enums
|
|
645
|
+
* should pass that enum value here (e.g. DLL's `AuditAction.INVALID_INPUT`).
|
|
646
|
+
*
|
|
647
|
+
* @default 'invalid_input'
|
|
648
|
+
*/
|
|
649
|
+
invalidInputAuditAction?: string;
|
|
627
650
|
}
|
|
628
651
|
/** Timed audit helper placed on context for handler-level audit control */
|
|
629
652
|
interface SecureTimedAudit {
|
package/dist/auth.js
CHANGED
|
@@ -1673,9 +1673,8 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1673
1673
|
const resolvedAuditAction = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.action : auditCfg;
|
|
1674
1674
|
const resolvedAuditResource = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.resource : routeConfig.auditResource;
|
|
1675
1675
|
const resolvedGetResourceId = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.getResourceId : routeConfig.getResourceId;
|
|
1676
|
-
const
|
|
1677
|
-
if (!factoryConfig.
|
|
1678
|
-
const action = factoryConfig.blockedAuditAction ?? "unauthorized_access";
|
|
1676
|
+
const writeBlockedAudit = async (action, reason, metadata) => {
|
|
1677
|
+
if (!factoryConfig.auditLog) return;
|
|
1679
1678
|
try {
|
|
1680
1679
|
await factoryConfig.auditLog({
|
|
1681
1680
|
actor: session?.user ? {
|
|
@@ -1686,11 +1685,19 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1686
1685
|
action,
|
|
1687
1686
|
resource: resolvedAuditResource ? { type: resolvedAuditResource, id: "unknown" } : void 0,
|
|
1688
1687
|
outcome: "blocked",
|
|
1689
|
-
reason
|
|
1688
|
+
reason,
|
|
1689
|
+
metadata
|
|
1690
1690
|
});
|
|
1691
1691
|
} catch {
|
|
1692
1692
|
}
|
|
1693
1693
|
};
|
|
1694
|
+
const emitBlockedAudit = async (reason) => {
|
|
1695
|
+
if (!factoryConfig.auditOnBlocked) return;
|
|
1696
|
+
await writeBlockedAudit(
|
|
1697
|
+
factoryConfig.blockedAuditAction ?? "unauthorized_access",
|
|
1698
|
+
reason
|
|
1699
|
+
);
|
|
1700
|
+
};
|
|
1694
1701
|
try {
|
|
1695
1702
|
if (routeConfig.requireAuth || routeConfig.requireAdmin || routeConfig.requireRoles?.length) {
|
|
1696
1703
|
session = await factoryConfig.getSession();
|
|
@@ -1765,6 +1772,13 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1765
1772
|
const result = routeConfig.validate.safeParse(input);
|
|
1766
1773
|
if (!result.success) {
|
|
1767
1774
|
const fieldErrors = result.error?.flatten ? result.error.flatten().fieldErrors : void 0;
|
|
1775
|
+
if (factoryConfig.auditOnInvalidInput && resolvedAuditAction) {
|
|
1776
|
+
await writeBlockedAudit(
|
|
1777
|
+
factoryConfig.invalidInputAuditAction ?? "invalid_input",
|
|
1778
|
+
"Input validation failed",
|
|
1779
|
+
fieldErrors ? { errors: fieldErrors } : void 0
|
|
1780
|
+
);
|
|
1781
|
+
}
|
|
1768
1782
|
return Response.json(
|
|
1769
1783
|
{ error: "Validation error", errors: fieldErrors },
|
|
1770
1784
|
{ status: 400, headers: { "X-Request-ID": requestId } }
|