@sdflc/backend-helpers 1.0.117 → 1.0.119

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/build/BaseCore.js CHANGED
@@ -382,6 +382,7 @@ class BaseCore {
382
382
  const ip = context.ipAddress || '';
383
383
  const spaceId = context.spaceId || '';
384
384
  if (!ip) {
385
+ this.logger.debug(`Cannot reset rate-limit counter for action '${scope}:${actionName}' as IP address is not available in context`);
385
386
  return;
386
387
  }
387
388
  // Key format must match what checkRateLimit wrote:
@@ -491,10 +492,12 @@ class BaseCore {
491
492
  const rules = this.collectRateLimitRules(actionName, callOverride);
492
493
  if (rules.length === 0) {
493
494
  // Nothing to check — skip limiter lookup entirely
495
+ this.logger.debug('No rate-limit rules apply to this action; skipping rate-limit check.');
494
496
  return null;
495
497
  }
496
498
  const limiter = this.getRateLimiter();
497
499
  if (!limiter) {
500
+ this.logger.debug('Rate-limit rules are defined but no limiter is available; skipping rate-limit check.');
498
501
  // No limiter available (no context.rateLimiter, no config.rateLimiter) — allow through
499
502
  return null;
500
503
  }
@@ -503,7 +506,6 @@ class BaseCore {
503
506
  const spaceId = context.spaceId || '';
504
507
  // Stable key segment: prefer rule.action override, then actionName, then doingWhat
505
508
  const actionKey = actionName || doingWhat;
506
- this.logger.debug(`Checking ${rules.length} rate-limit counter(s) for action '${actionKey}' from IP '${ip}' in space '${spaceId}' on ${doingWhat}`);
507
509
  // Run all counters in parallel — every applicable level is incremented on
508
510
  // every request regardless of what the others return. This ensures counters
509
511
  // stay accurate even when the request is ultimately blocked by another level.
@@ -71,7 +71,9 @@ class IpRateLimiter {
71
71
  }
72
72
  const ttlSec = await this.client.ttl(key);
73
73
  if (count > limit) {
74
- this.logger.log(`Rate limit exceeded for action '${action}' from IP '${ip}' in space '${spaceId}': ${count}/${limit} requests, resets in ${ttlSec}s`);
74
+ // this.logger.log(
75
+ // `Rate limit exceeded for action '${action}' from IP '${ip}' in space '${spaceId}': ${count}/${limit} requests, resets in ${ttlSec}s`,
76
+ // );
75
77
  return { blocked: true, count, ttlSec };
76
78
  }
77
79
  return { blocked: false, count, ttlSec };
@@ -74,7 +74,7 @@ const createContextDefault = async (args) => {
74
74
  // Priority: explicit rateLimiter arg > auto-construct from redisClient > none.
75
75
  // null is a valid explicit value meaning "disable rate limiting entirely".
76
76
  let rateLimiter = inRateLimiter;
77
- if (rateLimiter === undefined && redisClient != null) {
77
+ if (rateLimiter == null && redisClient != null) {
78
78
  rateLimiter = new IpRateLimiter_1.IpRateLimiter(redisClient, logger);
79
79
  }
80
80
  const sharedContext = {
@@ -376,6 +376,7 @@ class BaseCore {
376
376
  const ip = context.ipAddress || '';
377
377
  const spaceId = context.spaceId || '';
378
378
  if (!ip) {
379
+ this.logger.debug(`Cannot reset rate-limit counter for action '${scope}:${actionName}' as IP address is not available in context`);
379
380
  return;
380
381
  }
381
382
  // Key format must match what checkRateLimit wrote:
@@ -485,10 +486,12 @@ class BaseCore {
485
486
  const rules = this.collectRateLimitRules(actionName, callOverride);
486
487
  if (rules.length === 0) {
487
488
  // Nothing to check — skip limiter lookup entirely
489
+ this.logger.debug('No rate-limit rules apply to this action; skipping rate-limit check.');
488
490
  return null;
489
491
  }
490
492
  const limiter = this.getRateLimiter();
491
493
  if (!limiter) {
494
+ this.logger.debug('Rate-limit rules are defined but no limiter is available; skipping rate-limit check.');
492
495
  // No limiter available (no context.rateLimiter, no config.rateLimiter) — allow through
493
496
  return null;
494
497
  }
@@ -497,7 +500,6 @@ class BaseCore {
497
500
  const spaceId = context.spaceId || '';
498
501
  // Stable key segment: prefer rule.action override, then actionName, then doingWhat
499
502
  const actionKey = actionName || doingWhat;
500
- this.logger.debug(`Checking ${rules.length} rate-limit counter(s) for action '${actionKey}' from IP '${ip}' in space '${spaceId}' on ${doingWhat}`);
501
503
  // Run all counters in parallel — every applicable level is incremented on
502
504
  // every request regardless of what the others return. This ensures counters
503
505
  // stay accurate even when the request is ultimately blocked by another level.
@@ -68,7 +68,9 @@ export class IpRateLimiter {
68
68
  }
69
69
  const ttlSec = await this.client.ttl(key);
70
70
  if (count > limit) {
71
- this.logger.log(`Rate limit exceeded for action '${action}' from IP '${ip}' in space '${spaceId}': ${count}/${limit} requests, resets in ${ttlSec}s`);
71
+ // this.logger.log(
72
+ // `Rate limit exceeded for action '${action}' from IP '${ip}' in space '${spaceId}': ${count}/${limit} requests, resets in ${ttlSec}s`,
73
+ // );
72
74
  return { blocked: true, count, ttlSec };
73
75
  }
74
76
  return { blocked: false, count, ttlSec };
@@ -67,7 +67,7 @@ export const createContextDefault = async (args) => {
67
67
  // Priority: explicit rateLimiter arg > auto-construct from redisClient > none.
68
68
  // null is a valid explicit value meaning "disable rate limiting entirely".
69
69
  let rateLimiter = inRateLimiter;
70
- if (rateLimiter === undefined && redisClient != null) {
70
+ if (rateLimiter == null && redisClient != null) {
71
71
  rateLimiter = new IpRateLimiter(redisClient, logger);
72
72
  }
73
73
  const sharedContext = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdflc/backend-helpers",
3
- "version": "1.0.117",
3
+ "version": "1.0.119",
4
4
  "description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
5
5
  "type": "commonjs",
6
6
  "exports": {