web-gatekeeper-js 1.0.5 → 1.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-gatekeeper-js",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Redis based rate limiter and throttler using sliding window and token bucket algorithms",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -21,7 +21,7 @@ export const slidingWindowScript = `
21
21
  'currentCount', 1,
22
22
  'previousCount', 0
23
23
  )
24
- redis.call('EXPIRE', key, ttl)
24
+ redis.call('EXPIRE', key, math.floor(ttl))
25
25
  return { 1, 1, limit - 1, resetAfter } -- ← 4 values
26
26
  end
27
27
 
@@ -55,7 +55,7 @@ export const slidingWindowScript = `
55
55
  'currentCount', newCurrentCount,
56
56
  'previousCount', newPreviousCount
57
57
  )
58
- redis.call('EXPIRE', key, ttl)
58
+ redis.call('EXPIRE', key, math.floor(ttl))
59
59
 
60
60
  local remaining = math.floor(limit - effectiveCount - 1)
61
61
  return { 1, newCurrentCount, remaining, resetAfter } -- ← 4 values
@@ -27,7 +27,7 @@ export const throttlerScript = `
27
27
 
28
28
  -- save and set TTL
29
29
  redis.call('HSET', key, 'nextAllowedTime', newNextAllowedTime)
30
- redis.call('EXPIRE', key, ttl)
30
+ redis.call('EXPIRE', key, math.floor(ttl))
31
31
 
32
32
  -- return allowed + waitTime so Node.js knows how long to delay
33
33
  return { 1, math.max(waitTime, 0) }
@@ -15,7 +15,7 @@ export const tokenBucketScript = `
15
15
  'time', now,
16
16
  'tokenLeft', maxToken - 1
17
17
  )
18
- redis.call('EXPIRE', key, ttl)
18
+ redis.call('EXPIRE', key, math.floor(ttl))
19
19
  return { 1, maxToken - 1 }
20
20
  end
21
21
 
@@ -29,7 +29,7 @@ export const tokenBucketScript = `
29
29
  'time', now,
30
30
  'tokenLeft', updatedToken
31
31
  )
32
- redis.call('EXPIRE', key, ttl)
32
+ redis.call('EXPIRE', key, math.floor(ttl))
33
33
 
34
34
  local retryAfter = math.ceil((1 - updatedToken) / refillRate)
35
35
  return { 0, 0, retryAfter }
@@ -40,7 +40,7 @@ export const tokenBucketScript = `
40
40
  'time', now,
41
41
  'tokenLeft', updatedToken - 1
42
42
  )
43
- redis.call('EXPIRE', key, ttl)
43
+ redis.call('EXPIRE', key, math.floor(ttl))
44
44
 
45
45
  return { 1, updatedToken - 1, 0 }
46
46
  `
@@ -19,7 +19,7 @@ export class RedisStore {
19
19
  script,
20
20
  1,
21
21
  key,
22
- ...args
22
+ ...args.map(String)
23
23
  )
24
24
  }
25
25