@lunora/ratelimit 1.0.0-alpha.4 → 1.0.0-alpha.6

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/LICENSE.md CHANGED
@@ -103,3 +103,9 @@ Unless required by applicable law or agreed to in writing, software distributed
103
103
  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
104
  CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
105
  specific language governing permissions and limitations under the License.
106
+
107
+ <!-- DEPENDENCIES -->
108
+ <!-- /DEPENDENCIES -->
109
+
110
+ <!-- TYPE_DEPENDENCIES -->
111
+ <!-- /TYPE_DEPENDENCIES -->
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  export { availableAt, evaluate } from './packem_shared/availableAt-DN3Z6h_K.mjs';
2
- export { default as dbRateLimit } from './packem_shared/dbRateLimit-CXO7O3KO.mjs';
2
+ export { default as dbRateLimit } from './packem_shared/dbRateLimit-ChciceZm.mjs';
3
3
  export { default as RateLimitError } from './packem_shared/RateLimitError-53bWrDuJ.mjs';
4
- export { rateLimit } from './packem_shared/rateLimit-uQxVMZfh.mjs';
4
+ export { rateLimit } from './packem_shared/rateLimit-CTJq6iZx.mjs';
5
5
  export { ratelimitPlugin } from './packem_shared/ratelimitPlugin-D5_-KV1T.mjs';
6
6
  export { RateLimiter } from './packem_shared/RateLimiter-DQ9Peq-G.mjs';
7
7
  export { createDbStore, createMemoryStore, createSqlStore } from './packem_shared/createDbStore-L1kD1g1n.mjs';
@@ -1,4 +1,4 @@
1
- import { rateLimit } from './rateLimit-uQxVMZfh.mjs';
1
+ import { rateLimit } from './rateLimit-CTJq6iZx.mjs';
2
2
  import { RateLimiter } from './RateLimiter-DQ9Peq-G.mjs';
3
3
  import { createDbStore as createDatabaseStore } from './createDbStore-L1kD1g1n.mjs';
4
4
 
@@ -1,3 +1,5 @@
1
+ import { LunoraError } from '@lunora/errors';
2
+
1
3
  const STATUS_BY_REASON = {
2
4
  deny: { code: "FORBIDDEN", status: 403 },
3
5
  rate: { code: "TOO_MANY_REQUESTS", status: 429 }
@@ -18,22 +20,15 @@ const rateLimit = (limiter, name, options = {}) => async ({ ctx, next }) => {
18
20
  if (options.failOpen) {
19
21
  return next();
20
22
  }
21
- throw Object.assign(new Error(`rate limiter unavailable for "${name}"`), {
22
- cause: error,
23
- code: "SERVICE_UNAVAILABLE",
24
- name: "LunoraError",
25
- status: 503
26
- });
23
+ throw new LunoraError("SERVICE_UNAVAILABLE", `rate limiter unavailable for "${name}"`, { cause: error, status: 503 });
27
24
  }
28
25
  if (!status.ok) {
29
26
  const reason = status.reason ?? "rate";
30
27
  const mapped = STATUS_BY_REASON[reason];
31
28
  const retryAfter = Number.isFinite(status.retryAfter) ? Math.ceil(status.retryAfter) : void 0;
32
- throw Object.assign(new Error(options.message ?? defaultMessage(name, reason, retryAfter)), {
33
- code: mapped.code,
34
- name: "LunoraError",
35
- retryAfter,
36
- status: mapped.status
29
+ throw new LunoraError(mapped.code, options.message ?? defaultMessage(name, reason, retryAfter), {
30
+ status: mapped.status,
31
+ data: retryAfter === void 0 ? void 0 : { retryAfter }
37
32
  });
38
33
  }
39
34
  return next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/ratelimit",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.6",
4
4
  "description": "Rate limiting: token-bucket / fixed-window / sliding-window algorithms, deny list, sharding, pluggable stores, and procedure middleware",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,7 +46,7 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/errors": "1.0.0-alpha.1"
49
+ "@lunora/errors": "1.0.0-alpha.3"
50
50
  },
51
51
  "engines": {
52
52
  "node": "^22.15.0 || >=24.11.0"