mindgraph 0.1.8 → 0.1.9
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/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +29 -16
- package/dist/index.mjs +29 -16
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -413,6 +413,10 @@ interface MindGraphConfig {
|
|
|
413
413
|
baseUrl: string;
|
|
414
414
|
apiKey?: string;
|
|
415
415
|
jwt?: string;
|
|
416
|
+
/** Max retries for 503 (server warming up) responses. Default: 3. Set to 0 to disable. */
|
|
417
|
+
maxRetries?: number;
|
|
418
|
+
/** Initial backoff in ms before first retry. Doubles each attempt. Default: 1000. */
|
|
419
|
+
retryBackoffMs?: number;
|
|
416
420
|
}
|
|
417
421
|
|
|
418
422
|
declare class MindGraphError extends Error {
|
|
@@ -423,6 +427,8 @@ declare class MindGraphError extends Error {
|
|
|
423
427
|
declare class MindGraph {
|
|
424
428
|
private baseUrl;
|
|
425
429
|
private headers;
|
|
430
|
+
private maxRetries;
|
|
431
|
+
private retryBackoffMs;
|
|
426
432
|
constructor(config: MindGraphConfig);
|
|
427
433
|
private request;
|
|
428
434
|
private get;
|
package/dist/index.d.ts
CHANGED
|
@@ -413,6 +413,10 @@ interface MindGraphConfig {
|
|
|
413
413
|
baseUrl: string;
|
|
414
414
|
apiKey?: string;
|
|
415
415
|
jwt?: string;
|
|
416
|
+
/** Max retries for 503 (server warming up) responses. Default: 3. Set to 0 to disable. */
|
|
417
|
+
maxRetries?: number;
|
|
418
|
+
/** Initial backoff in ms before first retry. Doubles each attempt. Default: 1000. */
|
|
419
|
+
retryBackoffMs?: number;
|
|
416
420
|
}
|
|
417
421
|
|
|
418
422
|
declare class MindGraphError extends Error {
|
|
@@ -423,6 +427,8 @@ declare class MindGraphError extends Error {
|
|
|
423
427
|
declare class MindGraph {
|
|
424
428
|
private baseUrl;
|
|
425
429
|
private headers;
|
|
430
|
+
private maxRetries;
|
|
431
|
+
private retryBackoffMs;
|
|
426
432
|
constructor(config: MindGraphConfig);
|
|
427
433
|
private request;
|
|
428
434
|
private get;
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,8 @@ var MindGraph = class {
|
|
|
43
43
|
} else if (config.jwt) {
|
|
44
44
|
this.headers["Authorization"] = `Bearer ${config.jwt}`;
|
|
45
45
|
}
|
|
46
|
+
this.maxRetries = config.maxRetries ?? 3;
|
|
47
|
+
this.retryBackoffMs = config.retryBackoffMs ?? 1e3;
|
|
46
48
|
}
|
|
47
49
|
// ---- HTTP helpers ----
|
|
48
50
|
async request(method, path, body) {
|
|
@@ -54,24 +56,35 @@ var MindGraph = class {
|
|
|
54
56
|
if (body !== void 0) {
|
|
55
57
|
init.body = JSON.stringify(body);
|
|
56
58
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
parsed
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
let lastError;
|
|
60
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
61
|
+
const res = await fetch(url, init);
|
|
62
|
+
if (!res.ok) {
|
|
63
|
+
const text2 = await res.text().catch(() => "");
|
|
64
|
+
let parsed;
|
|
65
|
+
try {
|
|
66
|
+
parsed = JSON.parse(text2);
|
|
67
|
+
} catch {
|
|
68
|
+
parsed = text2;
|
|
69
|
+
}
|
|
70
|
+
const err = new MindGraphError(
|
|
71
|
+
`${method} ${path} failed: ${res.status}`,
|
|
72
|
+
res.status,
|
|
73
|
+
parsed
|
|
74
|
+
);
|
|
75
|
+
if (res.status === 503 && attempt < this.maxRetries) {
|
|
76
|
+
lastError = err;
|
|
77
|
+
const delay = this.retryBackoffMs * 2 ** attempt;
|
|
78
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
65
82
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
parsed
|
|
70
|
-
);
|
|
83
|
+
const text = await res.text();
|
|
84
|
+
if (!text) return void 0;
|
|
85
|
+
return JSON.parse(text);
|
|
71
86
|
}
|
|
72
|
-
|
|
73
|
-
if (!text) return void 0;
|
|
74
|
-
return JSON.parse(text);
|
|
87
|
+
throw lastError;
|
|
75
88
|
}
|
|
76
89
|
get(path) {
|
|
77
90
|
return this.request("GET", path);
|
package/dist/index.mjs
CHANGED
|
@@ -16,6 +16,8 @@ var MindGraph = class {
|
|
|
16
16
|
} else if (config.jwt) {
|
|
17
17
|
this.headers["Authorization"] = `Bearer ${config.jwt}`;
|
|
18
18
|
}
|
|
19
|
+
this.maxRetries = config.maxRetries ?? 3;
|
|
20
|
+
this.retryBackoffMs = config.retryBackoffMs ?? 1e3;
|
|
19
21
|
}
|
|
20
22
|
// ---- HTTP helpers ----
|
|
21
23
|
async request(method, path, body) {
|
|
@@ -27,24 +29,35 @@ var MindGraph = class {
|
|
|
27
29
|
if (body !== void 0) {
|
|
28
30
|
init.body = JSON.stringify(body);
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
parsed
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
let lastError;
|
|
33
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
34
|
+
const res = await fetch(url, init);
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
const text2 = await res.text().catch(() => "");
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(text2);
|
|
40
|
+
} catch {
|
|
41
|
+
parsed = text2;
|
|
42
|
+
}
|
|
43
|
+
const err = new MindGraphError(
|
|
44
|
+
`${method} ${path} failed: ${res.status}`,
|
|
45
|
+
res.status,
|
|
46
|
+
parsed
|
|
47
|
+
);
|
|
48
|
+
if (res.status === 503 && attempt < this.maxRetries) {
|
|
49
|
+
lastError = err;
|
|
50
|
+
const delay = this.retryBackoffMs * 2 ** attempt;
|
|
51
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
throw err;
|
|
38
55
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
parsed
|
|
43
|
-
);
|
|
56
|
+
const text = await res.text();
|
|
57
|
+
if (!text) return void 0;
|
|
58
|
+
return JSON.parse(text);
|
|
44
59
|
}
|
|
45
|
-
|
|
46
|
-
if (!text) return void 0;
|
|
47
|
-
return JSON.parse(text);
|
|
60
|
+
throw lastError;
|
|
48
61
|
}
|
|
49
62
|
get(path) {
|
|
50
63
|
return this.request("GET", path);
|