@digilogiclabs/platform-core 1.23.0 → 1.24.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.mjs CHANGED
@@ -1599,15 +1599,21 @@ function createSecureHandlerFactory(factoryConfig) {
1599
1599
  );
1600
1600
  }
1601
1601
  }
1602
+ let rateLimitInfo = null;
1602
1603
  if (!routeConfig.skipRateLimit && routeConfig.rateLimit && factoryConfig.rateLimiter) {
1603
1604
  const userId = session?.user?.id ?? void 0;
1604
- const blocked = await factoryConfig.rateLimiter.enforce(
1605
+ const result = await factoryConfig.rateLimiter.enforce(
1605
1606
  request,
1606
1607
  operation,
1607
1608
  routeConfig.rateLimit,
1608
1609
  userId
1609
1610
  );
1610
- if (blocked) return blocked;
1611
+ if (result instanceof Response) {
1612
+ return result;
1613
+ }
1614
+ if (result !== null && typeof result === "object") {
1615
+ rateLimitInfo = result;
1616
+ }
1611
1617
  }
1612
1618
  let validated = {};
1613
1619
  if (routeConfig.validate) {
@@ -1673,6 +1679,20 @@ function createSecureHandlerFactory(factoryConfig) {
1673
1679
  };
1674
1680
  const response = await handler(request, ctx);
1675
1681
  response.headers.set("X-Request-ID", requestId);
1682
+ if (rateLimitInfo) {
1683
+ response.headers.set(
1684
+ "X-RateLimit-Limit",
1685
+ String(rateLimitInfo.limit)
1686
+ );
1687
+ response.headers.set(
1688
+ "X-RateLimit-Remaining",
1689
+ String(rateLimitInfo.remaining)
1690
+ );
1691
+ response.headers.set(
1692
+ "X-RateLimit-Reset",
1693
+ String(rateLimitInfo.resetMs)
1694
+ );
1695
+ }
1676
1696
  if (resolvedAuditAction && factoryConfig.auditLog && !timedAudit) {
1677
1697
  await factoryConfig.auditLog({
1678
1698
  actor: {