timetable-api-node 1.8.5 → 1.8.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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/index.ts +11 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -471,6 +471,7 @@ In addition to tools, the server exposes MCP **resources** for reference data th
471
471
  - Public read-only (no authentication).
472
472
  - No mutating tools are exposed.
473
473
  - `POST /mcp` is rate-limited to **60 requests/min per IP** (in-memory, resets on restart). Excess requests receive HTTP 429 with a JSON-RPC error body.
474
+ - Requests carrying `X-Internal-Key` equal to the `INTERNAL_API_KEY` env var (the lad.lviv.ua frontend server) skip every rate limit.
474
475
  - `robots.txt` is only a best-effort discovery hint and not a protocol contract.
475
476
 
476
477
  ## REST API
package/index.ts CHANGED
@@ -15,6 +15,7 @@ import localDb from "./connections/timetableSqliteDb.ts";
15
15
 
16
16
  import notFoundAction from "./actions/notFoundAction.ts";
17
17
  import validateStopCode from "./utils/stopCodeMiddleware.ts";
18
+ import { isInternalCaller } from "./utils/internalCaller.ts";
18
19
 
19
20
  import getClosestStopsAction from "./actions/getClosestStopsAction.ts";
20
21
  import getSingleStopAction from "./actions/getSingleStopAction.ts";
@@ -85,7 +86,9 @@ const clientIpKey = (req: Request) =>
85
86
  // generates. They exist to bound the unattended callers: a scraper looping a
86
87
  // fixed set of stop codes, or an app under development replaying deploy
87
88
  // loops, both of which otherwise run against the origin with nothing to push
88
- // back. Liveness paths are exempt so a probe never trips a limit some abusive
89
+ // back. Our own frontend server is exempt from every limiter (see
90
+ // utils/internalCaller.ts): all its page renders and chat lookups share one
91
+ // address. Liveness paths are exempt so a probe never trips a limit some abusive
89
92
  // neighbour filled, and /mcp is exempt because it carries its own limiter
90
93
  // below: sharing this bucket meant the global one always emptied first (it
91
94
  // counts every path) and answered MCP clients with a body that is not
@@ -97,7 +100,10 @@ const globalRateLimiter = rateLimit({
97
100
  legacyHeaders: false,
98
101
  keyGenerator: clientIpKey,
99
102
  skip: (req) =>
100
- req.path === "/health" || req.path === "/ping" || req.path === "/mcp",
103
+ req.path === "/health" ||
104
+ req.path === "/ping" ||
105
+ req.path === "/mcp" ||
106
+ isInternalCaller(req),
101
107
  message: { error: "Rate limit exceeded. Try again later." },
102
108
  });
103
109
 
@@ -111,6 +117,7 @@ const liveDataRateLimiter = rateLimit({
111
117
  standardHeaders: true,
112
118
  legacyHeaders: false,
113
119
  keyGenerator: clientIpKey,
120
+ skip: (req) => isInternalCaller(req),
114
121
  message: { error: "Rate limit exceeded. Try again later." },
115
122
  });
116
123
 
@@ -132,6 +139,7 @@ const stopDataRateLimiter = rateLimit({
132
139
  standardHeaders: true,
133
140
  legacyHeaders: false,
134
141
  keyGenerator: clientIpKey,
142
+ skip: (req) => isInternalCaller(req),
135
143
  message: { error: "Rate limit exceeded. Try again later." },
136
144
  });
137
145
 
@@ -323,6 +331,7 @@ const mcpRateLimiter = rateLimit({
323
331
  standardHeaders: true,
324
332
  legacyHeaders: false,
325
333
  keyGenerator: clientIpKey,
334
+ skip: (req) => isInternalCaller(req),
326
335
  handler: (req, res) =>
327
336
  res.status(429).json({
328
337
  jsonrpc: "2.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "timetable-api-node",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "description": "Lviv (Ukraine) public transport REST API and read-only Model Context Protocol (MCP) server: stops, timetables, routes, live vehicle positions, GTFS/GTFS-RT. No API key required.",
5
5
  "main": "index.ts",
6
6
  "type": "module",