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 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
- const res = await fetch(url, init);
58
- if (!res.ok) {
59
- const text2 = await res.text().catch(() => "");
60
- let parsed;
61
- try {
62
- parsed = JSON.parse(text2);
63
- } catch {
64
- parsed = text2;
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
- throw new MindGraphError(
67
- `${method} ${path} failed: ${res.status}`,
68
- res.status,
69
- parsed
70
- );
83
+ const text = await res.text();
84
+ if (!text) return void 0;
85
+ return JSON.parse(text);
71
86
  }
72
- const text = await res.text();
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
- const res = await fetch(url, init);
31
- if (!res.ok) {
32
- const text2 = await res.text().catch(() => "");
33
- let parsed;
34
- try {
35
- parsed = JSON.parse(text2);
36
- } catch {
37
- parsed = text2;
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
- throw new MindGraphError(
40
- `${method} ${path} failed: ${res.status}`,
41
- res.status,
42
- parsed
43
- );
56
+ const text = await res.text();
57
+ if (!text) return void 0;
58
+ return JSON.parse(text);
44
59
  }
45
- const text = await res.text();
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindgraph",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "TypeScript client for the MindGraph Cloud API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",