@ladjs/api 8.0.0 → 8.0.1

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.
Files changed (2) hide show
  1. package/index.js +12 -2
  2. package/package.json +11 -10
package/index.js CHANGED
@@ -19,14 +19,17 @@ const etag = require('koa-etag');
19
19
  const json = require('koa-json');
20
20
  const koa404Handler = require('koa-404-handler');
21
21
  const koaConnect = require('koa-connect');
22
+ const ms = require('ms');
22
23
  const multimatch = require('multimatch');
24
+ const ratelimit = require('@ladjs/koa-simple-ratelimit');
23
25
  const removeTrailingSlashes = require('koa-no-trailing-slash');
24
26
  const requestId = require('express-request-id');
25
27
  const requestReceived = require('request-received');
26
28
  const responseTime = require('response-time');
27
29
  const sharedConfig = require('@ladjs/shared-config');
28
30
  const { boolean } = require('boolean');
29
- const { ratelimit } = require('koa-simple-ratelimit');
31
+
32
+ const RATE_LIMIT_EXCEEDED = `Rate limit exceeded, retry in %s.`;
30
33
 
31
34
  class API {
32
35
  constructor(config, client) {
@@ -109,7 +112,14 @@ class API {
109
112
 
110
113
  return ratelimit({
111
114
  ...this.config.rateLimit,
112
- db: this.client
115
+ db: this.client,
116
+ logger: cabin,
117
+ errorMessage(exp) {
118
+ const fn =
119
+ typeof ctx.request.t === 'function' ? ctx.request.t : util.format;
120
+ // NOTE: ms does not support i18n localization
121
+ return fn(RATE_LIMIT_EXCEEDED, ms(exp, { long: true }));
122
+ }
113
123
  })(ctx, next);
114
124
  });
115
125
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ladjs/api",
3
3
  "description": "API server for Lad",
4
- "version": "8.0.0",
4
+ "version": "8.0.1",
5
5
  "author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
6
6
  "ava": {
7
7
  "failFast": true,
@@ -22,8 +22,9 @@
22
22
  "dependencies": {
23
23
  "@koa/router": "^10.1.1",
24
24
  "@ladjs/i18n": "^7.2.6",
25
+ "@ladjs/koa-simple-ratelimit": "^3.0.0",
25
26
  "@ladjs/redis": "^1.0.7",
26
- "@ladjs/shared-config": "^6.0.0",
27
+ "@ladjs/shared-config": "^6.0.2",
27
28
  "@ladjs/store-ip-address": "^0.0.7",
28
29
  "boolean": "^3.2.0",
29
30
  "cabin": "^9.1.2",
@@ -41,29 +42,29 @@
41
42
  "koa-etag": "^4.0.0",
42
43
  "koa-json": "^2.0.2",
43
44
  "koa-no-trailing-slash": "^2.1.0",
44
- "koa-simple-ratelimit": "^5.1.1",
45
45
  "lodash": "^4.17.21",
46
+ "ms": "^2.1.3",
46
47
  "multimatch": "5",
47
48
  "request-received": "^0.0.3",
48
49
  "response-time": "^2.3.2"
49
50
  },
50
51
  "devDependencies": {
51
- "@commitlint/cli": "^16.2.4",
52
- "@commitlint/config-conventional": "^16.2.4",
52
+ "@commitlint/cli": "^17.0.1",
53
+ "@commitlint/config-conventional": "^17.0.0",
53
54
  "ava": "^4.2.0",
54
55
  "codecov": "^3.8.3",
55
56
  "cross-env": "^7.0.3",
56
- "eslint": "^8.14.0",
57
+ "eslint": "^8.16.0",
57
58
  "eslint-config-xo-lass": "^1.0.6",
58
59
  "fixpack": "^4.0.0",
59
- "husky": "^7.0.4",
60
- "lint-staged": "12.4.1",
61
- "mongoose": "^6.3.2",
60
+ "husky": "^8.0.1",
61
+ "lint-staged": "12.4.2",
62
+ "mongoose": "^6.3.4",
62
63
  "nyc": "^15.1.0",
63
64
  "remark-cli": "^10.0.1",
64
65
  "remark-preset-github": "^4.0.1",
65
66
  "supertest": "^6.2.3",
66
- "xo": "^0.48.0"
67
+ "xo": "^0.49.0"
67
68
  },
68
69
  "engines": {
69
70
  "node": ">=10.10.0"