@digilogiclabs/platform-core 1.16.0 → 1.17.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 +26 -5
- package/dist/auth.d.ts +26 -5
- package/dist/auth.js +17 -11
- package/dist/auth.js.map +1 -1
- package/dist/auth.mjs +17 -11
- package/dist/auth.mjs.map +1 -1
- package/dist/migrate.js +0 -0
- package/package.json +11 -11
package/dist/auth.mjs
CHANGED
|
@@ -1483,6 +1483,10 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1483
1483
|
let isAdmin = false;
|
|
1484
1484
|
let isLegacyToken = false;
|
|
1485
1485
|
let timedAudit;
|
|
1486
|
+
const auditCfg = routeConfig.audit;
|
|
1487
|
+
const resolvedAuditAction = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.action : auditCfg;
|
|
1488
|
+
const resolvedAuditResource = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.resource : routeConfig.auditResource;
|
|
1489
|
+
const resolvedGetResourceId = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.getResourceId : routeConfig.getResourceId;
|
|
1486
1490
|
try {
|
|
1487
1491
|
if (routeConfig.requireAuth || routeConfig.requireAdmin || routeConfig.requireRoles?.length) {
|
|
1488
1492
|
session = await factoryConfig.getSession();
|
|
@@ -1553,17 +1557,17 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1553
1557
|
const actorId = isLegacyToken ? "admin_token" : session?.user?.id || "anonymous";
|
|
1554
1558
|
const actorType = isLegacyToken ? "admin" : "user";
|
|
1555
1559
|
const actorEmail = session?.user?.email ?? void 0;
|
|
1556
|
-
const resourceId =
|
|
1560
|
+
const resourceId = resolvedGetResourceId ? resolvedGetResourceId(
|
|
1557
1561
|
request,
|
|
1558
1562
|
params,
|
|
1559
1563
|
validated
|
|
1560
1564
|
) : void 0;
|
|
1561
|
-
if (
|
|
1565
|
+
if (resolvedAuditAction && factoryConfig.createTimedAudit) {
|
|
1562
1566
|
timedAudit = factoryConfig.createTimedAudit(
|
|
1563
1567
|
{
|
|
1564
|
-
action:
|
|
1565
|
-
resource:
|
|
1566
|
-
type:
|
|
1568
|
+
action: resolvedAuditAction,
|
|
1569
|
+
resource: resolvedAuditResource ? {
|
|
1570
|
+
type: resolvedAuditResource,
|
|
1567
1571
|
id: resourceId
|
|
1568
1572
|
} : void 0,
|
|
1569
1573
|
actor: {
|
|
@@ -1575,9 +1579,11 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1575
1579
|
request
|
|
1576
1580
|
);
|
|
1577
1581
|
}
|
|
1582
|
+
const authMethod = isLegacyToken ? "legacy_token" : session?.user ? "session" : "none";
|
|
1578
1583
|
const ctx = {
|
|
1579
1584
|
session,
|
|
1580
1585
|
isLegacyToken,
|
|
1586
|
+
authMethod,
|
|
1581
1587
|
isAdmin,
|
|
1582
1588
|
validated,
|
|
1583
1589
|
logger: log,
|
|
@@ -1587,16 +1593,16 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1587
1593
|
};
|
|
1588
1594
|
const response = await handler(request, ctx);
|
|
1589
1595
|
response.headers.set("X-Request-ID", requestId);
|
|
1590
|
-
if (
|
|
1596
|
+
if (resolvedAuditAction && factoryConfig.auditLog && !timedAudit) {
|
|
1591
1597
|
await factoryConfig.auditLog({
|
|
1592
1598
|
actor: {
|
|
1593
1599
|
id: actorId,
|
|
1594
1600
|
type: actorType,
|
|
1595
1601
|
email: actorEmail
|
|
1596
1602
|
},
|
|
1597
|
-
action:
|
|
1598
|
-
resource:
|
|
1599
|
-
type:
|
|
1603
|
+
action: resolvedAuditAction,
|
|
1604
|
+
resource: resolvedAuditResource ? {
|
|
1605
|
+
type: resolvedAuditResource,
|
|
1600
1606
|
id: resourceId ?? "unknown"
|
|
1601
1607
|
} : void 0,
|
|
1602
1608
|
outcome: "success"
|
|
@@ -1612,13 +1618,13 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1612
1618
|
if (timedAudit) {
|
|
1613
1619
|
await timedAudit.failure(errReason).catch(() => {
|
|
1614
1620
|
});
|
|
1615
|
-
} else if (
|
|
1621
|
+
} else if (resolvedAuditAction && factoryConfig.auditLog) {
|
|
1616
1622
|
await factoryConfig.auditLog({
|
|
1617
1623
|
actor: {
|
|
1618
1624
|
id: session?.user?.id || "unknown",
|
|
1619
1625
|
type: "user"
|
|
1620
1626
|
},
|
|
1621
|
-
action:
|
|
1627
|
+
action: resolvedAuditAction,
|
|
1622
1628
|
outcome: "failure",
|
|
1623
1629
|
reason: errReason
|
|
1624
1630
|
}).catch(() => {
|