@gusnips/react 0.9.13 → 0.9.15

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/README.md CHANGED
@@ -163,8 +163,10 @@ new QueryClient({
163
163
  });
164
164
  ```
165
165
 
166
- Retries 408, a transient 429, 5xx, and no-response-at-all. Nothing else — every other 4xx is an
167
- answer, and a second attempt just says it again.
166
+ Retries 408, 425, a transient 429, 5xx, and no-response-at-all. Nothing else — every other 4xx is
167
+ an answer, and a second attempt just says it again. The rule itself is
168
+ [`@gusnips/http/retry`](../http#should-this-request-be-tried-again), so an SDK with no React in it
169
+ can retry the same way.
168
170
 
169
171
  `durableLimitCodes` is the part a status code cannot tell you. A spent monthly quota and a burst
170
172
  limit both arrive as 429, but one clears by waiting and the other clears by buying. Retrying the
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;AAE3D;;;;;;;;;;;;;;;;;;GAkBG;AAEH,+CAA+C;AAC/C,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;;;;;;;;OASG;IACH,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACnC,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IAClC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,cAAc,CAAC;IACxB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,MAAM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,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CACnG;AAiED,wBAAgB,eAAe,CAAC,EAC9B,OAAO,EACP,OAAO,EACP,OAAO,EAAE,YAAY,EACrB,aAAa,EACb,OAAO,EACP,SAAkB,EAClB,kBAAsB,EACtB,mBAAyB,EACzB,gBAAwB,EACxB,eAAgC,GACjC,EAAE,gBAAgB,GAAG,SAAS,CAgL9B"}
@@ -1,5 +1,6 @@
1
1
  import { isApiError } from "@gusnips/http";
2
- import { ApiError, parseRetryAfter } from "./api-error.js";
2
+ import { parseRetryAfter } from "@gusnips/http/retry";
3
+ import { ApiError } from "./api-error.js";
3
4
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
4
5
  /**
5
6
  * One signal that fires on the caller's abort or on the deadline, whichever comes first.
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAgL3D,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAEnF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAS,YAAY,CACnB,EAAU,EACV,MAAsC;IAEtC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;QAC5B,uFAAuF;QACvF,2FAA2F;QAC3F,0CAA0C;QAC1C,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,2BAA2B,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QACr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IAAI,EAAE,KAAK,EAAQ,IAAY,EAAE,UAA0B,EAAE,EAAE,EAAE,CAC/D,QAAQ,CAAO,MAAM,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACpE,QAAQ,EAAE,KAAK,EAAQ,IAAY,EAAE,IAAc,EAAE,UAA0B,EAAE,EAAE,EAAE,CACnF,QAAQ,CAAO,MAAM,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;KAClF,CAAC;AACJ,CAAC"}
@@ -25,7 +25,7 @@ export declare class ApiError extends Error {
25
25
  * `Retry-After: 60` on every 429 and nothing in its body, so the package's only reader —
26
26
  * which looked in `details.retryAfterSecs`, the first donor's convention — found nothing, and
27
27
  * both the copy and the retry rule were flying blind on the one refusal that states its own
28
- * expiry. Two conventions, same fact; {@link retryAfterSecs} reads either.
28
+ * expiry. Two conventions, same fact; `retryAfterSecs` from `@gusnips/http/retry` reads either.
29
29
  */
30
30
  readonly retryAfterSecs: number | undefined;
31
31
  /**
@@ -45,48 +45,6 @@ export declare class ApiError extends Error {
45
45
  retryAfterSecs?: number;
46
46
  });
47
47
  }
48
- /**
49
- * Seconds until a refusal clears, from whichever place the API put them.
50
- *
51
- * The header first, because it is the standard one and it is what a limiter emits without being
52
- * asked; then `details.retryAfterSecs`, which one donor's API sends in the body instead. A
53
- * caller asking "how long" should not have to know which server it is talking to.
54
- *
55
- * It deliberately does not answer whether waiting helps at all. `null` here means "no countdown
56
- * to show", which is the right answer both for a refusal that said nothing and for one that said
57
- * waiting will never fix it — and the adopters' countdown UIs read it for exactly that. Telling
58
- * those two apart is {@link waitingNeverHelps}.
59
- */
60
- export declare function retryAfterSecs(error: ApiError): number | null;
61
- /**
62
- * Did the answer say, in so many words, that waiting will never fix this?
63
- *
64
- * The server half of this fleet sends `details.retryAfterSecs: null` on a refusal no amount of
65
- * time clears — a cap that frees only when somebody deletes something, a concurrency slot that
66
- * frees when another job ends. An explicit `null` is a claim somebody has to read; an omitted key
67
- * is invisible. That is the whole reason the two must not collapse into one answer: this is the
68
- * server naming what `durableLimitCodes` otherwise makes every app name by hand, one code at a
69
- * time, and keep in step with a backend it does not own.
70
- *
71
- * Present-and-`null` is the entire test. An absent key reads as `undefined`, so `=== null`
72
- * already separates the claim from the silence and an `in` check would only widen it to every
73
- * stated wait. Body-only by design: `Retry-After` has no spelling for "never".
74
- *
75
- * Not exported from the package, and that is the point: it is not "is this refusal durable?". It
76
- * says nothing about a durable CODE or a wait too long to hold, so an error surface branching on
77
- * it would answer differently from the retry rule for every limit the app names itself. The one
78
- * question worth asking out loud is `shouldRetry`, and `describeError` already derives the
79
- * control it offers from exactly that — invariant 8, one rule and two consumers.
80
- */
81
- export declare function waitingNeverHelps(error: ApiError): boolean;
82
- /**
83
- * `Retry-After` in either spec form: delay-seconds, or an HTTP-date.
84
- *
85
- * Both forms are real — RFC 9110 allows either and different servers pick differently — and the
86
- * date one is the half that gets skipped, which turns a stated wait into no wait at all. Clamped
87
- * at zero: a date already in the past means "now", not a negative delay.
88
- */
89
- export declare function parseRetryAfter(value: string | null | undefined): number | undefined;
90
48
  /**
91
49
  * An aborted request — the caller's own `AbortController`, or a navigation that unmounted the
92
50
  * component waiting on it.
@@ -1 +1 @@
1
- {"version":3,"file":"api-error.d.ts","sourceRoot":"","sources":["../src/api-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAA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,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,SAAS,CAAC;IAC7D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC;;;;;;;;;OASG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5C;;;;;;;;OAQG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;gBAGzB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,EAClC,IAAI,GAAE;QACJ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,cAAc,CAAC,EAAE,MAAM,CAAC;KACpB;CAaT;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD"}
package/dist/api-error.js CHANGED
@@ -24,7 +24,7 @@ export class ApiError extends Error {
24
24
  * `Retry-After: 60` on every 429 and nothing in its body, so the package's only reader —
25
25
  * which looked in `details.retryAfterSecs`, the first donor's convention — found nothing, and
26
26
  * both the copy and the retry rule were flying blind on the one refusal that states its own
27
- * expiry. Two conventions, same fact; {@link retryAfterSecs} reads either.
27
+ * expiry. Two conventions, same fact; `retryAfterSecs` from `@gusnips/http/retry` reads either.
28
28
  */
29
29
  retryAfterSecs;
30
30
  /**
@@ -50,76 +50,6 @@ export class ApiError extends Error {
50
50
  this.expected = opts.expected ?? false;
51
51
  }
52
52
  }
53
- /**
54
- * Seconds until a refusal clears, from whichever place the API put them.
55
- *
56
- * The header first, because it is the standard one and it is what a limiter emits without being
57
- * asked; then `details.retryAfterSecs`, which one donor's API sends in the body instead. A
58
- * caller asking "how long" should not have to know which server it is talking to.
59
- *
60
- * It deliberately does not answer whether waiting helps at all. `null` here means "no countdown
61
- * to show", which is the right answer both for a refusal that said nothing and for one that said
62
- * waiting will never fix it — and the adopters' countdown UIs read it for exactly that. Telling
63
- * those two apart is {@link waitingNeverHelps}.
64
- */
65
- export function retryAfterSecs(error) {
66
- if (error.retryAfterSecs !== undefined)
67
- return error.retryAfterSecs;
68
- const details = error.details;
69
- if (typeof details !== "object" || details === null)
70
- return null;
71
- const value = details.retryAfterSecs;
72
- return typeof value === "number" && Number.isFinite(value) ? value : null;
73
- }
74
- /**
75
- * Did the answer say, in so many words, that waiting will never fix this?
76
- *
77
- * The server half of this fleet sends `details.retryAfterSecs: null` on a refusal no amount of
78
- * time clears — a cap that frees only when somebody deletes something, a concurrency slot that
79
- * frees when another job ends. An explicit `null` is a claim somebody has to read; an omitted key
80
- * is invisible. That is the whole reason the two must not collapse into one answer: this is the
81
- * server naming what `durableLimitCodes` otherwise makes every app name by hand, one code at a
82
- * time, and keep in step with a backend it does not own.
83
- *
84
- * Present-and-`null` is the entire test. An absent key reads as `undefined`, so `=== null`
85
- * already separates the claim from the silence and an `in` check would only widen it to every
86
- * stated wait. Body-only by design: `Retry-After` has no spelling for "never".
87
- *
88
- * Not exported from the package, and that is the point: it is not "is this refusal durable?". It
89
- * says nothing about a durable CODE or a wait too long to hold, so an error surface branching on
90
- * it would answer differently from the retry rule for every limit the app names itself. The one
91
- * question worth asking out loud is `shouldRetry`, and `describeError` already derives the
92
- * control it offers from exactly that — invariant 8, one rule and two consumers.
93
- */
94
- export function waitingNeverHelps(error) {
95
- const details = error.details;
96
- if (typeof details !== "object" || details === null)
97
- return false;
98
- return details.retryAfterSecs === null;
99
- }
100
- /**
101
- * `Retry-After` in either spec form: delay-seconds, or an HTTP-date.
102
- *
103
- * Both forms are real — RFC 9110 allows either and different servers pick differently — and the
104
- * date one is the half that gets skipped, which turns a stated wait into no wait at all. Clamped
105
- * at zero: a date already in the past means "now", not a negative delay.
106
- */
107
- export function parseRetryAfter(value) {
108
- const raw = value?.trim();
109
- if (!raw)
110
- return undefined;
111
- // A bare integer is the delay-seconds form, malformed included: `Date.parse` accepts some of
112
- // them as years, so falling through would read "-5" as a date long past and answer 0 — a
113
- // wait invented out of a header that never stated one.
114
- if (/^[+-]?\d+$/.test(raw)) {
115
- const secs = Number(raw);
116
- return Number.isSafeInteger(secs) && secs >= 0 ? secs : undefined;
117
- }
118
- const at = Date.parse(raw);
119
- if (Number.isNaN(at))
120
- return undefined;
121
- return Math.max(0, Math.round((at - Date.now()) / 1000));
122
- }
123
53
  /**
124
54
  * An aborted request — the caller's own `AbortController`, or a navigation that unmounted the
125
55
  * component waiting on it.
@@ -1 +1 @@
1
- {"version":3,"file":"api-error.js","sourceRoot":"","sources":["../src/api-error.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,MAAM,CAAS;IACf,IAAI,CAAqB;IACzB,UAAU,CAAqB;IAC/B,MAAM,CAA8C;IACpD,OAAO,CAAU;IACjB,SAAS,CAAqB;IACvC;;;;;;;;;OASG;IACM,cAAc,CAAqB;IAE5C;;;;;;;;OAQG;IACM,QAAQ,CAAU;IAE3B,YACE,MAAc,EACd,IAAkC,EAClC,OAKI,EAAE;QAEN,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,EAAE,OAAO,IAAI,mBAAmB,MAAM,GAAG,CAAC,CAAC;QACrE,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,EAAE,IAAI,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,IAAI,EAAE,UAAU,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,CAAC;QAC3B,IAAI,CA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AAQ,CAAC,CAAC,CAAC;IAC1C;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,gGAAgG;IAChG,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,YAAY,KAAK,SAAS,CAAC;AAExD,2BAA2B;AAC3B,wBAAgB,oBAAoB,CAClC,MAAM,SAAS,MAAM,EACrB,YAAY,SAAS,MAAM,EAC3B,UAAU,SAAS,MAAM,EACzB,EACA,CAAC,EACD,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,cAAmC,EACnC,KAAU,EACV,QAAQ,EACR,iBAAsB,EACtB,gBAAgB,GACjB,EAAE,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,cAAc,CAyG9F"}
@@ -1,4 +1,5 @@
1
- import { ApiError, retryAfterSecs } from "./api-error.js";
1
+ import { retryAfterSecs } from "@gusnips/http/retry";
2
+ import { ApiError } from "./api-error.js";
2
3
  import { shouldRetry } from "./query.js";
3
4
  const PLURAL_SUFFIX = /_(zero|one|two|few|many|other)$/;
4
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"describe-error.js","sourceRoot":"","sources":["../src/describe-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA2GzC,MAAM,aAAa,GAAG,iCAAiC,CAAC;AA2BxD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,CAAoC,EACpC,IAAY,EACZ,MAAc;IAEd,+FAA+F;IAC/F,+BAA+B;IAC/B,IAAI,IAAI,GAAG,EAAE;QAA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1F,4FAA4F;YAC5F,qEAAqE;YACrE,OAAO;gBACL,KAAK,EAAE,CAAC,CAAC,GAAG,UAAU,SAAS,CAAC;gBAChC,uFAAuF;gBACvF,kFAAkF;gBAClF,GAAG,EAAE,CAAC,CAAC,GAAG,UAAU,aAAa,CAAC;gBAClC,OAAO,EAAE,OAAO;aACjB,CAAC;QACJ,CAAC;QAED,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,GAAG,GAAiB;YACxB,KAAK;YACL,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC;YAC3B,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;YACrD,QAAQ;YACR,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC;SACtC,CAAC;QAEF,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAC;QACnF,MAAM,IAAI,GAAc,GAAG,CAAC,GAAG,CAAC,CAAC;QAEjC,2FAA2F;QAC3F,sFAAsF;QACtF,0DAA0D;QAC1D,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC;QACpD,OAAO;YACL,GAAG,IAAI;YACP,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO;YACpC,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC;SAC9C,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { cn } from "./cn.ts";
2
2
  export { copyText, useCopy, type CopyOptions, type CopyState } from "./copy.ts";
3
3
  export { returnPathFromLocation, safeInternalPath, type PathParts } from "./internal-path.ts";
4
- export { ApiError, isAbortError, retryAfterSecs } from "./api-error.ts";
4
+ export { ApiError, isAbortError } from "./api-error.ts";
5
+ export { retryAfterSecs } from "@gusnips/http/retry";
5
6
  export { createApiClient, type ApiClient, type ApiClientOptions, type RefreshResult, type RequestOptions, type SessionAdapter, } from "./api-client.ts";
6
7
  export { createSseParser, readSseStream, type SseFrame } from "./sse.ts";
7
8
  export { queryDefaults, queryView, retryDelayMs, shouldRetry, type QueryDefaultsOptions, type QueryView, } from "./query.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE9F,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EACL,eAAe,EACf,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,EACL,aAAa,EACb,SAAS,EACT,YAAY,EACZ,WAAW,EACX,KAAK,oBAAoB,EACzB,KAAK,SAAS,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,aAAa,EACb,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,YA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,KAAK,kBAAkB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,SAAS,GACf,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,UAAU,GACX,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAElF,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -32,7 +32,8 @@
32
32
  export { cn } from "./cn.js";
33
33
  export { copyText, useCopy } from "./copy.js";
34
34
  export { returnPathFromLocation, safeInternalPath } from "./internal-path.js";
35
- export { ApiError, isAbortError, retryAfterSecs } from "./api-error.js";
35
+ export { ApiError, isAbortError } from "./api-error.js";
36
+ export { retryAfterSecs } from "@gusnips/http/retry";
36
37
  export { createApiClient, } from "./api-client.js";
37
38
  export { createSseParser, readSseStream } from "./sse.js";
38
39
  export { queryDefaults, queryView, retryDelayMs, shouldRetry, } from "./query.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,EAAE;AACF,2CAA2C;AAC3C,EAAE;AACF,+FAA+F;AAC/F,gGAAgG;AAChG,+FAA+F;AAC/F,iGAAiG;AACjG,0BAA0B;AAC1B,EAAE;AACF,qEAAqE;AACrE,8DAA8D;AAC9D,uEAAuE;AACvE,gEAAgE;AAChE,4EAA4E;AAC5E,4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E,eAAe,EAAwB,MAAM,WAAW,CAAC"}
package/dist/query.d.ts CHANGED
@@ -1,4 +1,32 @@
1
1
  import type { DefaultOptions } from "@tanstack/react-query";
2
+ /**
3
+ * react-query defaults — the merge of three repos that each got part of this right.
4
+ *
5
+ * The default is three blind retries, which is wrong for an API that answers refusals
6
+ * precisely: a 402, a 403 or a 451 says exactly the same thing three times, and a 429 we hammer
7
+ * is a 429 we deserve. All three donors knew that much. What each knew alone:
8
+ *
9
+ * - one allowed **408** through, the only 4xx that a second attempt genuinely fixes;
10
+ * - one refused to retry a 429 whose CODE says the limit is durable — a monthly quota or a
11
+ * spent balance clears by buying, not by waiting, so retrying burns another request against
12
+ * the limiter and cannot succeed;
13
+ * - one set **`refetchOnReconnect`**, which none of the others had, and which is the single
14
+ * most useful refetch there is: coming back from a tunnel is exactly when the screen is stale.
15
+ *
16
+ * The second migration added the fourth rule, which no donor had: **when a 429 says how long,
17
+ * believe it.** Its limiter answers `Retry-After: 60` on a per-minute window, and the default
18
+ * backoff retries at 1s and 2s — two more requests that cannot succeed, both charged against the
19
+ * same limiter, and three seconds added before the screen says anything. So a stated wait is
20
+ * waited out when it is short, and is an ANSWER when it is not.
21
+ *
22
+ * The fifth rule came from the server half of this fleet rather than from a donor: a refusal can
23
+ * state that waiting will never fix it at all, by sending `details.retryAfterSecs: null`. Read as
24
+ * "did not say how long" — which is what every version before this one did — that 429 is retried
25
+ * against a limit no amount of time moves.
26
+ *
27
+ * This is invariant 8. The rule itself lives in `@gusnips/http/retry`, so an SDK with no React
28
+ * in it follows the same one; what is here is the binding to react-query.
29
+ */
2
30
  export interface QueryDefaultsOptions {
3
31
  /**
4
32
  * Error codes that mean "this limit does not clear by waiting" — a spent monthly quota, a
@@ -34,7 +62,7 @@ export interface QueryDefaultsOptions {
34
62
  * Should this failure be retried?
35
63
  *
36
64
  * Exported on its own because an app with its own QueryClient config still wants this rule, and
37
- * because it is the part worth testing.
65
+ * because the describer derives the control it offers from it.
38
66
  */
39
67
  export declare function shouldRetry(error: unknown, durableLimitCodes?: readonly string[], maxRetryWaitSecs?: number): boolean;
40
68
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAoC5D,MAAM,WAAW,oBAAoB;IACnC;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,kFAAkF;IAClF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,iBAAiB,GAAE,SAAS,MAAM,EAAO,EACzC,gBAAgB,SAA8B,GAC7C,OAAO,CAqBT;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAKzE;AAED,wBAAgB,aAAa,CAAC,EAC5B,iBAAsB,EACtB,UAAc,EACd,gBAA8C,EAC9C,SAAyB,EACzB,MAAuB,EACvB,oBAA4B,GAC7B,GAAE,oBAAyB,GAAG,cAAc,CAe5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,IAChC;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAC7B;IAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAC/C;IAAE,QAAQ,CAAC,KAAK,EAAE,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E,oBAAyB,GAAG,cAAc,CAe5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,IAChC;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAC7B;IAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAC/C;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,IAAI,CAAA;CAAE,CAAC;AAEnF,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE;IACrC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;CAC3B,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAMlB"}
package/dist/query.js CHANGED
@@ -1,62 +1,18 @@
1
- import { ApiError, retryAfterSecs, waitingNeverHelps } from "./api-error.js";
2
- /**
3
- * react-query defaults — the merge of three repos that each got part of this right.
4
- *
5
- * The default is three blind retries, which is wrong for an API that answers refusals
6
- * precisely: a 402, a 403 or a 451 says exactly the same thing three times, and a 429 we hammer
7
- * is a 429 we deserve. All three donors knew that much. What each knew alone:
8
- *
9
- * - one allowed **408** through, the only 4xx that a second attempt genuinely fixes;
10
- * - one refused to retry a 429 whose CODE says the limit is durable — a monthly quota or a
11
- * spent balance clears by buying, not by waiting, so retrying burns another request against
12
- * the limiter and cannot succeed;
13
- * - one set **`refetchOnReconnect`**, which none of the others had, and which is the single
14
- * most useful refetch there is: coming back from a tunnel is exactly when the screen is stale.
15
- *
16
- * The second migration added the fourth rule, which no donor had: **when a 429 says how long,
17
- * believe it.** Its limiter answers `Retry-After: 60` on a per-minute window, and the default
18
- * backoff retries at 1s and 2s — two more requests that cannot succeed, both charged against the
19
- * same limiter, and three seconds added before the screen says anything. So a stated wait is
20
- * waited out when it is short, and is an ANSWER when it is not.
21
- *
22
- * The fifth rule came from the server half of this fleet rather than from a donor: a refusal can
23
- * state that waiting will never fix it at all, by sending `details.retryAfterSecs: null`. Read as
24
- * "did not say how long" — which is what every version before this one did — that 429 is retried
25
- * against a limit no amount of time moves.
26
- *
27
- * This is invariant 8.
28
- */
29
- /** 4xx statuses a second attempt can fix. Everything else in the 4xx family is an answer. */
30
- const RETRYABLE_CLIENT_STATUS = new Set([408, 429]);
31
- const DEFAULT_MAX_RETRY_WAIT_SECS = 10;
1
+ import { retryDelayMs as delayFor, shouldRetry as retryRule } from "@gusnips/http/retry";
2
+ import { ApiError } from "./api-error.js";
32
3
  /**
33
4
  * Should this failure be retried?
34
5
  *
35
6
  * Exported on its own because an app with its own QueryClient config still wants this rule, and
36
- * because it is the part worth testing.
7
+ * because the describer derives the control it offers from it.
37
8
  */
38
- export function shouldRetry(error, durableLimitCodes = [], maxRetryWaitSecs = DEFAULT_MAX_RETRY_WAIT_SECS) {
39
- // No response at all — offline, DNS, a dropped connection. The request never landed, so
40
- // nothing about it is an answer, and a second attempt is exactly right.
41
- if (!(error instanceof ApiError))
42
- return true;
43
- if (error.code !== undefined && durableLimitCodes.includes(error.code))
44
- return false;
45
- // The same judgement, made by the server instead of by a list the app maintains: an explicit
46
- // `details.retryAfterSecs: null` means waiting will never fix this. Checked before the stated
47
- // wait because the two can contradict each other, and the `null` is written by whoever raised
48
- // this particular refusal where a number can come from a limiter that attaches one to every
49
- // 429 it emits.
50
- if (waitingNeverHelps(error))
51
- return false;
52
- // It told us when it clears. A wait we are not willing to hold is a refusal, not a hiccup —
53
- // and it is the same judgement `durableLimitCodes` makes, except the server did the naming.
54
- const wait = retryAfterSecs(error);
55
- if (wait !== null && wait > maxRetryWaitSecs)
56
- return false;
57
- if (error.status >= 500)
58
- return true;
59
- return RETRYABLE_CLIENT_STATUS.has(error.status);
9
+ export function shouldRetry(error, durableLimitCodes = [], maxRetryWaitSecs) {
10
+ // Every caller here is a query, or a person pressing "try again", so the request may run twice.
11
+ return retryRule(answerOf(error), {
12
+ repeatable: true,
13
+ durableCodes: durableLimitCodes,
14
+ maxWaitSecs: maxRetryWaitSecs,
15
+ });
60
16
  }
61
17
  /**
62
18
  * How long before the next attempt: the server's stated wait when there is one, react-query's
@@ -64,13 +20,18 @@ export function shouldRetry(error, durableLimitCodes = [], maxRetryWaitSecs = DE
64
20
  * server saying "immediately", which for a client that just got refused is still too soon.
65
21
  */
66
22
  export function retryDelayMs(attemptIndex, error) {
67
- const backoff = Math.min(1000 * 2 ** attemptIndex, 30_000);
68
- if (!(error instanceof ApiError))
69
- return backoff;
70
- const wait = retryAfterSecs(error);
71
- return wait === null ? backoff : Math.max(backoff, wait * 1000);
23
+ return delayFor(attemptIndex, answerOf(error));
24
+ }
25
+ /**
26
+ * Only this client's `ApiError` is an answer. The shared rule reads any error by its fields, so a
27
+ * vendor's error with a `status` of its own would count as one — and the describer reads anything
28
+ * that is not an `ApiError` as a request that never landed, offering "try again" where the retry
29
+ * rule would refuse. Handing the rule `null` keeps the two reading one failure the same way.
30
+ */
31
+ function answerOf(error) {
32
+ return error instanceof ApiError ? error : null;
72
33
  }
73
- export function queryDefaults({ durableLimitCodes = [], maxRetries = 2, maxRetryWaitSecs = DEFAULT_MAX_RETRY_WAIT_SECS, staleTime = 2 * 60 * 1000, gcTime = 10 * 60 * 1000, refetchOnWindowFocus = false, } = {}) {
34
+ export function queryDefaults({ durableLimitCodes = [], maxRetries = 2, maxRetryWaitSecs, staleTime = 2 * 60 * 1000, gcTime = 10 * 60 * 1000, refetchOnWindowFocus = false, } = {}) {
74
35
  return {
75
36
  queries: {
76
37
  staleTime,
package/dist/query.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names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BAAgB,CAAC;YACtF,UAAU,EAAE,YAAY;YACxB,oBAAoB;YACpB,kBAAkB,EAAE,IAAI;SACzB;QACD,2FAA2F;QAC3F,yFAAyF;QACzF,SAAS,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;KAC5B,CAAC;AACJ,CAAC;AAkCD,MAAM,UAAU,SAAS,CAAO,KAG/B;IACC,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACvB,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC;IAClC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IAC7E,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACtD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC9B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gusnips/react",
3
- "version": "0.9.13",
3
+ "version": "0.9.15",
4
4
  "description": "The headless runtime under a Vite + React SPA: typed fetch client with single-flight refresh, auth store, query defaults, route guards, error boundary, stale-tab recovery, i18n bootstrap.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -80,7 +80,7 @@
80
80
  "release:major": "bun pm version major && bun publish --access public"
81
81
  },
82
82
  "dependencies": {
83
- "@gusnips/http": "0.1.1",
83
+ "@gusnips/http": "0.1.3",
84
84
  "clsx": "^2.1.1",
85
85
  "tailwind-merge": "^3.6.0"
86
86
  },
@@ -1,5 +1,6 @@
1
1
  import { afterEach, describe, expect, it, vi } from "vitest";
2
- import { ApiError, isAbortError, retryAfterSecs } from "./api-error.ts";
2
+ import { retryAfterSecs } from "@gusnips/http/retry";
3
+ import { ApiError, isAbortError } from "./api-error.ts";
3
4
  import { createApiClient, type RefreshResult, type SessionAdapter } from "./api-client.ts";
4
5
 
5
6
  function stubFetch(handler: (url: string, init: RequestInit) => Response | Promise<Response>) {
@@ -89,7 +90,7 @@ describe("createApiClient", () => {
89
90
 
90
91
  const error = await api.get("/x").catch((e: unknown) => e);
91
92
  expect(error).toMatchObject({ status: 429, retryAfterSecs: 60 });
92
- expect(retryAfterSecs(error as ApiError)).toBe(60);
93
+ expect(retryAfterSecs(error)).toBe(60);
93
94
  });
94
95
 
95
96
  it("leaves the wait unset when the answer did not state one", async () => {
@@ -102,7 +103,7 @@ describe("createApiClient", () => {
102
103
 
103
104
  const error = await api.get("/x").catch((e: unknown) => e);
104
105
  expect((error as ApiError).retryAfterSecs).toBeUndefined();
105
- expect(retryAfterSecs(error as ApiError)).toBeNull();
106
+ expect(retryAfterSecs(error)).toBeNull();
106
107
  });
107
108
 
108
109
  /**
package/src/api-client.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isApiError, type ApiSuccess } from "@gusnips/http";
2
- import { ApiError, parseRetryAfter } from "./api-error.ts";
2
+ import { parseRetryAfter } from "@gusnips/http/retry";
3
+ import { ApiError } from "./api-error.ts";
3
4
 
4
5
  /**
5
6
  * The app's one door to the API. Nothing else should call `fetch`.
package/src/api-error.ts CHANGED
@@ -26,7 +26,7 @@ export class ApiError extends Error {
26
26
  * `Retry-After: 60` on every 429 and nothing in its body, so the package's only reader —
27
27
  * which looked in `details.retryAfterSecs`, the first donor's convention — found nothing, and
28
28
  * both the copy and the retry rule were flying blind on the one refusal that states its own
29
- * expiry. Two conventions, same fact; {@link retryAfterSecs} reads either.
29
+ * expiry. Two conventions, same fact; `retryAfterSecs` from `@gusnips/http/retry` reads either.
30
30
  */
31
31
  readonly retryAfterSecs: number | undefined;
32
32
 
@@ -64,76 +64,6 @@ export class ApiError extends Error {
64
64
  }
65
65
  }
66
66
 
67
- /**
68
- * Seconds until a refusal clears, from whichever place the API put them.
69
- *
70
- * The header first, because it is the standard one and it is what a limiter emits without being
71
- * asked; then `details.retryAfterSecs`, which one donor's API sends in the body instead. A
72
- * caller asking "how long" should not have to know which server it is talking to.
73
- *
74
- * It deliberately does not answer whether waiting helps at all. `null` here means "no countdown
75
- * to show", which is the right answer both for a refusal that said nothing and for one that said
76
- * waiting will never fix it — and the adopters' countdown UIs read it for exactly that. Telling
77
- * those two apart is {@link waitingNeverHelps}.
78
- */
79
- export function retryAfterSecs(error: ApiError): number | null {
80
- if (error.retryAfterSecs !== undefined) return error.retryAfterSecs;
81
- const details = error.details;
82
- if (typeof details !== "object" || details === null) return null;
83
- const value = (details as { retryAfterSecs?: unknown }).retryAfterSecs;
84
- return typeof value === "number" && Number.isFinite(value) ? value : null;
85
- }
86
-
87
- /**
88
- * Did the answer say, in so many words, that waiting will never fix this?
89
- *
90
- * The server half of this fleet sends `details.retryAfterSecs: null` on a refusal no amount of
91
- * time clears — a cap that frees only when somebody deletes something, a concurrency slot that
92
- * frees when another job ends. An explicit `null` is a claim somebody has to read; an omitted key
93
- * is invisible. That is the whole reason the two must not collapse into one answer: this is the
94
- * server naming what `durableLimitCodes` otherwise makes every app name by hand, one code at a
95
- * time, and keep in step with a backend it does not own.
96
- *
97
- * Present-and-`null` is the entire test. An absent key reads as `undefined`, so `=== null`
98
- * already separates the claim from the silence and an `in` check would only widen it to every
99
- * stated wait. Body-only by design: `Retry-After` has no spelling for "never".
100
- *
101
- * Not exported from the package, and that is the point: it is not "is this refusal durable?". It
102
- * says nothing about a durable CODE or a wait too long to hold, so an error surface branching on
103
- * it would answer differently from the retry rule for every limit the app names itself. The one
104
- * question worth asking out loud is `shouldRetry`, and `describeError` already derives the
105
- * control it offers from exactly that — invariant 8, one rule and two consumers.
106
- */
107
- export function waitingNeverHelps(error: ApiError): boolean {
108
- const details = error.details;
109
- if (typeof details !== "object" || details === null) return false;
110
- return (details as { retryAfterSecs?: unknown }).retryAfterSecs === null;
111
- }
112
-
113
- /**
114
- * `Retry-After` in either spec form: delay-seconds, or an HTTP-date.
115
- *
116
- * Both forms are real — RFC 9110 allows either and different servers pick differently — and the
117
- * date one is the half that gets skipped, which turns a stated wait into no wait at all. Clamped
118
- * at zero: a date already in the past means "now", not a negative delay.
119
- */
120
- export function parseRetryAfter(value: string | null | undefined): number | undefined {
121
- const raw = value?.trim();
122
- if (!raw) return undefined;
123
-
124
- // A bare integer is the delay-seconds form, malformed included: `Date.parse` accepts some of
125
- // them as years, so falling through would read "-5" as a date long past and answer 0 — a
126
- // wait invented out of a header that never stated one.
127
- if (/^[+-]?\d+$/.test(raw)) {
128
- const secs = Number(raw);
129
- return Number.isSafeInteger(secs) && secs >= 0 ? secs : undefined;
130
- }
131
-
132
- const at = Date.parse(raw);
133
- if (Number.isNaN(at)) return undefined;
134
- return Math.max(0, Math.round((at - Date.now()) / 1000));
135
- }
136
-
137
67
  /**
138
68
  * An aborted request — the caller's own `AbortController`, or a navigation that unmounted the
139
69
  * component waiting on it.
@@ -1,4 +1,5 @@
1
- import { ApiError, retryAfterSecs } from "./api-error.ts";
1
+ import { retryAfterSecs } from "@gusnips/http/retry";
2
+ import { ApiError } from "./api-error.ts";
2
3
  import { shouldRetry } from "./query.ts";
3
4
 
4
5
  /**
package/src/index.ts CHANGED
@@ -34,7 +34,8 @@ export { cn } from "./cn.ts";
34
34
  export { copyText, useCopy, type CopyOptions, type CopyState } from "./copy.ts";
35
35
  export { returnPathFromLocation, safeInternalPath, type PathParts } from "./internal-path.ts";
36
36
 
37
- export { ApiError, isAbortError, retryAfterSecs } from "./api-error.ts";
37
+ export { ApiError, isAbortError } from "./api-error.ts";
38
+ export { retryAfterSecs } from "@gusnips/http/retry";
38
39
  export {
39
40
  createApiClient,
40
41
  type ApiClient,
package/src/query.test.ts CHANGED
@@ -26,6 +26,17 @@ describe("shouldRetry", () => {
26
26
  expect(shouldRetry(new TypeError("Failed to fetch"))).toBe(true);
27
27
  });
28
28
 
29
+ // The describer reads anything that is not an `ApiError` as a request that never landed and
30
+ // offers "try again". A vendor's error carrying a `status` of its own must get the same answer
31
+ // here, or the button and the retry disagree.
32
+ it("reads only its own ApiError as an answer", () => {
33
+ const vendor = Object.assign(new Error("Invalid login credentials"), { status: 400 });
34
+ expect(shouldRetry(vendor)).toBe(true);
35
+ expect(retryDelayMs(0, Object.assign(new Error("x"), { status: 429, retryAfterSecs: 5 }))).toBe(
36
+ 1000,
37
+ );
38
+ });
39
+
29
40
  it("retries 5xx", () => {
30
41
  expect(shouldRetry(refusal(500))).toBe(true);
31
42
  expect(shouldRetry(refusal(503))).toBe(true);
package/src/query.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { retryDelayMs as delayFor, shouldRetry as retryRule } from "@gusnips/http/retry";
1
2
  import type { DefaultOptions } from "@tanstack/react-query";
2
- import { ApiError, retryAfterSecs, waitingNeverHelps } from "./api-error.ts";
3
+ import { ApiError } from "./api-error.ts";
3
4
 
4
5
  /**
5
6
  * react-query defaults — the merge of three repos that each got part of this right.
@@ -26,14 +27,10 @@ import { ApiError, retryAfterSecs, waitingNeverHelps } from "./api-error.ts";
26
27
  * "did not say how long" — which is what every version before this one did — that 429 is retried
27
28
  * against a limit no amount of time moves.
28
29
  *
29
- * This is invariant 8.
30
+ * This is invariant 8. The rule itself lives in `@gusnips/http/retry`, so an SDK with no React
31
+ * in it follows the same one; what is here is the binding to react-query.
30
32
  */
31
33
 
32
- /** 4xx statuses a second attempt can fix. Everything else in the 4xx family is an answer. */
33
- const RETRYABLE_CLIENT_STATUS = new Set([408, 429]);
34
-
35
- const DEFAULT_MAX_RETRY_WAIT_SECS = 10;
36
-
37
34
  export interface QueryDefaultsOptions {
38
35
  /**
39
36
  * Error codes that mean "this limit does not clear by waiting" — a spent monthly quota, a
@@ -70,33 +67,19 @@ export interface QueryDefaultsOptions {
70
67
  * Should this failure be retried?
71
68
  *
72
69
  * Exported on its own because an app with its own QueryClient config still wants this rule, and
73
- * because it is the part worth testing.
70
+ * because the describer derives the control it offers from it.
74
71
  */
75
72
  export function shouldRetry(
76
73
  error: unknown,
77
74
  durableLimitCodes: readonly string[] = [],
78
- maxRetryWaitSecs = DEFAULT_MAX_RETRY_WAIT_SECS,
75
+ maxRetryWaitSecs?: number,
79
76
  ): boolean {
80
- // No response at all — offline, DNS, a dropped connection. The request never landed, so
81
- // nothing about it is an answer, and a second attempt is exactly right.
82
- if (!(error instanceof ApiError)) return true;
83
-
84
- if (error.code !== undefined && durableLimitCodes.includes(error.code)) return false;
85
-
86
- // The same judgement, made by the server instead of by a list the app maintains: an explicit
87
- // `details.retryAfterSecs: null` means waiting will never fix this. Checked before the stated
88
- // wait because the two can contradict each other, and the `null` is written by whoever raised
89
- // this particular refusal where a number can come from a limiter that attaches one to every
90
- // 429 it emits.
91
- if (waitingNeverHelps(error)) return false;
92
-
93
- // It told us when it clears. A wait we are not willing to hold is a refusal, not a hiccup —
94
- // and it is the same judgement `durableLimitCodes` makes, except the server did the naming.
95
- const wait = retryAfterSecs(error);
96
- if (wait !== null && wait > maxRetryWaitSecs) return false;
97
-
98
- if (error.status >= 500) return true;
99
- return RETRYABLE_CLIENT_STATUS.has(error.status);
77
+ // Every caller here is a query, or a person pressing "try again", so the request may run twice.
78
+ return retryRule(answerOf(error), {
79
+ repeatable: true,
80
+ durableCodes: durableLimitCodes,
81
+ maxWaitSecs: maxRetryWaitSecs,
82
+ });
100
83
  }
101
84
 
102
85
  /**
@@ -105,16 +88,23 @@ export function shouldRetry(
105
88
  * server saying "immediately", which for a client that just got refused is still too soon.
106
89
  */
107
90
  export function retryDelayMs(attemptIndex: number, error: unknown): number {
108
- const backoff = Math.min(1000 * 2 ** attemptIndex, 30_000);
109
- if (!(error instanceof ApiError)) return backoff;
110
- const wait = retryAfterSecs(error);
111
- return wait === null ? backoff : Math.max(backoff, wait * 1000);
91
+ return delayFor(attemptIndex, answerOf(error));
92
+ }
93
+
94
+ /**
95
+ * Only this client's `ApiError` is an answer. The shared rule reads any error by its fields, so a
96
+ * vendor's error with a `status` of its own would count as one — and the describer reads anything
97
+ * that is not an `ApiError` as a request that never landed, offering "try again" where the retry
98
+ * rule would refuse. Handing the rule `null` keeps the two reading one failure the same way.
99
+ */
100
+ function answerOf(error: unknown): ApiError | null {
101
+ return error instanceof ApiError ? error : null;
112
102
  }
113
103
 
114
104
  export function queryDefaults({
115
105
  durableLimitCodes = [],
116
106
  maxRetries = 2,
117
- maxRetryWaitSecs = DEFAULT_MAX_RETRY_WAIT_SECS,
107
+ maxRetryWaitSecs,
118
108
  staleTime = 2 * 60 * 1000,
119
109
  gcTime = 10 * 60 * 1000,
120
110
  refetchOnWindowFocus = false,
@@ -1,119 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { ApiError, parseRetryAfter, retryAfterSecs, waitingNeverHelps } from "./api-error.ts";
3
-
4
- /**
5
- * Two APIs, two places for the same fact: one states the wait in the `Retry-After` header (the
6
- * standard one), the other in `details.retryAfterSecs`. A caller asking "how long" should not
7
- * have to know which server answered.
8
- */
9
- describe("retryAfterSecs", () => {
10
- it("reads the header the client captured", () => {
11
- expect(retryAfterSecs(new ApiError(429, null, { retryAfterSecs: 60 }))).toBe(60);
12
- // Zero is a real answer — "now" — and must not read as "did not say".
13
- expect(retryAfterSecs(new ApiError(429, null, { retryAfterSecs: 0 }))).toBe(0);
14
- });
15
-
16
- it("prefers the header to the body", () => {
17
- const both = new ApiError(
18
- 429,
19
- { code: "X", message: "", details: { retryAfterSecs: 30 } },
20
- {
21
- retryAfterSecs: 60,
22
- },
23
- );
24
- expect(retryAfterSecs(both)).toBe(60);
25
- });
26
-
27
- it("reads the number out of details, and refuses anything else", () => {
28
- expect(
29
- retryAfterSecs(
30
- new ApiError(429, { code: "X", message: "", details: { retryAfterSecs: 30 } }),
31
- ),
32
- ).toBe(30);
33
- expect(
34
- retryAfterSecs(
35
- new ApiError(429, { code: "X", message: "", details: { retryAfterSecs: "30" } }),
36
- ),
37
- ).toBeNull();
38
- expect(retryAfterSecs(new ApiError(429, { code: "X", message: "", details: null }))).toBeNull();
39
- expect(retryAfterSecs(new ApiError(429, null))).toBeNull();
40
- });
41
-
42
- // And it keeps answering `null` for a stated never, which is what its callers want: there is
43
- // no countdown to show. The claim is a separate question, asked separately.
44
- it("answers null for a stated never, same as for silence", () => {
45
- const stated = new ApiError(429, {
46
- code: "X",
47
- message: "",
48
- details: { retryAfterSecs: null },
49
- });
50
- expect(retryAfterSecs(stated)).toBeNull();
51
- expect(retryAfterSecs(new ApiError(429, null))).toBeNull();
52
- });
53
- });
54
-
55
- /**
56
- * The claim `retryAfterSecs` cannot carry: an explicit `null` in the body, meaning waiting will
57
- * never fix this. It has to be told apart from an absent key, which is silence.
58
- */
59
- describe("waitingNeverHelps", () => {
60
- const withDetails = (details: unknown) => new ApiError(429, { code: "X", message: "", details });
61
-
62
- it("reads a present null as the claim", () => {
63
- expect(waitingNeverHelps(withDetails({ retryAfterSecs: null }))).toBe(true);
64
- });
65
-
66
- it("reads silence as no claim", () => {
67
- expect(waitingNeverHelps(withDetails({ scope: "account" }))).toBe(false);
68
- expect(waitingNeverHelps(withDetails({}))).toBe(false);
69
- expect(waitingNeverHelps(new ApiError(429, null))).toBe(false);
70
- });
71
-
72
- it("reads a stated wait as no claim", () => {
73
- expect(waitingNeverHelps(withDetails({ retryAfterSecs: 30 }))).toBe(false);
74
- // The header is not a channel for this — there is no `Retry-After` that says "never".
75
- expect(waitingNeverHelps(new ApiError(429, null, { retryAfterSecs: 30 }))).toBe(false);
76
- });
77
-
78
- // `details` is whatever the server put there, so the shape is a trust boundary. A JSON `null`
79
- // is the one that bites: `typeof null` is `"object"`, so a missing guard reads a property off
80
- // it and throws inside a retry rule.
81
- it("survives a details that is not an object", () => {
82
- expect(waitingNeverHelps(withDetails(null))).toBe(false);
83
- expect(waitingNeverHelps(withDetails("nope"))).toBe(false);
84
- expect(waitingNeverHelps(withDetails(7))).toBe(false);
85
- });
86
- });
87
-
88
- /**
89
- * Both spec forms are real — RFC 9110 allows delay-seconds or an HTTP-date, and servers pick
90
- * differently. The date half is the one that gets skipped, which silently turns a stated wait
91
- * into no wait at all.
92
- */
93
- describe("parseRetryAfter", () => {
94
- it("reads delay-seconds", () => {
95
- expect(parseRetryAfter("60")).toBe(60);
96
- expect(parseRetryAfter(" 60 ")).toBe(60);
97
- expect(parseRetryAfter("0")).toBe(0);
98
- });
99
-
100
- it("reads an HTTP-date", () => {
101
- const at = new Date(Date.now() + 120_000).toUTCString();
102
- expect(parseRetryAfter(at)).toBeGreaterThanOrEqual(119);
103
- expect(parseRetryAfter(at)).toBeLessThanOrEqual(120);
104
- });
105
-
106
- // A date already gone means "now", not a negative delay that would run the backoff backwards.
107
- it("clamps a date in the past to zero", () => {
108
- expect(parseRetryAfter(new Date(Date.now() - 60_000).toUTCString())).toBe(0);
109
- });
110
-
111
- it("answers nothing for a header that is missing or not a wait", () => {
112
- expect(parseRetryAfter(null)).toBeUndefined();
113
- expect(parseRetryAfter("")).toBeUndefined();
114
- expect(parseRetryAfter(" ")).toBeUndefined();
115
- expect(parseRetryAfter("soon")).toBeUndefined();
116
- expect(parseRetryAfter("-5")).toBeUndefined();
117
- expect(parseRetryAfter("9007199254740993")).toBeUndefined();
118
- });
119
- });