@everystack/api 0.4.1 → 0.4.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/package.json +1 -1
- package/src/client/index.ts +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@everystack/api",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "PostgREST-compatible HTTP handler + typed fetch client for Drizzle ORM",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"author": "Scalable Technology, Inc. <licensing@scalable.technology>",
|
package/src/client/index.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface ClientOptions {
|
|
|
13
13
|
getToken?: () => string | null | Promise<string | null>;
|
|
14
14
|
/** Called on 401 — return a new token to retry, or null to fail */
|
|
15
15
|
onTokenExpired?: () => Promise<string | null>;
|
|
16
|
+
/** Called when a 401 could not be recovered — refresh failed, or the retry with the refreshed token also 401/403'd */
|
|
17
|
+
onAuthFailure?: () => void;
|
|
16
18
|
/** Client credentials sent with every request */
|
|
17
19
|
clientCredentials?: {
|
|
18
20
|
id: string;
|
|
@@ -296,6 +298,8 @@ async function fetchWithRetry(
|
|
|
296
298
|
const retryResponse = await fetch(url, { ...init, headers: retryHeaders });
|
|
297
299
|
|
|
298
300
|
if (!retryResponse.ok) {
|
|
301
|
+
// Refreshed token was still rejected — unrecoverable.
|
|
302
|
+
options.onAuthFailure?.();
|
|
299
303
|
return { retried: { data: null, error: await parseError(retryResponse) } };
|
|
300
304
|
}
|
|
301
305
|
|
|
@@ -303,7 +307,8 @@ async function fetchWithRetry(
|
|
|
303
307
|
return { response: retryResponse };
|
|
304
308
|
}
|
|
305
309
|
|
|
306
|
-
// Refresh failed
|
|
310
|
+
// Refresh failed — unrecoverable.
|
|
311
|
+
options.onAuthFailure?.();
|
|
307
312
|
return { retried: { data: null, error: await parseError(response) } };
|
|
308
313
|
}
|
|
309
314
|
|