bookstack-mcp 3.3.1 → 3.3.2
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/dist/bookstack-client.js +26 -0
- package/package.json +1 -1
package/dist/bookstack-client.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import https from 'https';
|
|
3
|
+
const MAX_RETRIES_429 = 5;
|
|
4
|
+
function parseRetryAfter(value) {
|
|
5
|
+
if (typeof value !== 'string' || !value)
|
|
6
|
+
return null;
|
|
7
|
+
const seconds = Number(value);
|
|
8
|
+
if (Number.isFinite(seconds))
|
|
9
|
+
return Math.max(0, seconds * 1000);
|
|
10
|
+
const dateMs = Date.parse(value);
|
|
11
|
+
if (Number.isFinite(dateMs))
|
|
12
|
+
return Math.max(0, dateMs - Date.now());
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
3
15
|
export class BookStackClient {
|
|
4
16
|
client;
|
|
5
17
|
enableWrite;
|
|
@@ -18,6 +30,20 @@ export class BookStackClient {
|
|
|
18
30
|
? new https.Agent({ rejectUnauthorized: false })
|
|
19
31
|
: undefined
|
|
20
32
|
});
|
|
33
|
+
this.client.interceptors.response.use(undefined, async (error) => {
|
|
34
|
+
const cfg = error.config;
|
|
35
|
+
if (!cfg || error.response?.status !== 429)
|
|
36
|
+
throw error;
|
|
37
|
+
cfg.__retry429 = (cfg.__retry429 ?? 0) + 1;
|
|
38
|
+
if (cfg.__retry429 > MAX_RETRIES_429)
|
|
39
|
+
throw error;
|
|
40
|
+
const retryAfter = parseRetryAfter(error.response.headers?.['retry-after']);
|
|
41
|
+
const backoff = Math.min(30000, 1000 * 2 ** (cfg.__retry429 - 1));
|
|
42
|
+
const delay = retryAfter ?? backoff;
|
|
43
|
+
console.error(`BookStack rate limited (429); retry ${cfg.__retry429}/${MAX_RETRIES_429} in ${delay}ms`);
|
|
44
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
45
|
+
return this.client.request(cfg);
|
|
46
|
+
});
|
|
21
47
|
}
|
|
22
48
|
applyFilters(params, filter) {
|
|
23
49
|
if (!filter)
|