@cedvict/http-guardian 0.0.1-next.0 → 0.0.1-next.10
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/CHANGELOG.md +23 -0
- package/LICENSE +21 -1
- package/README.md +223 -0
- package/dist/aliases.d.ts +35 -0
- package/dist/aliases.d.ts.map +1 -0
- package/dist/auth/authConfig.d.ts +91 -0
- package/dist/auth/authConfig.d.ts.map +1 -0
- package/dist/cache/inFlight.d.ts +10 -0
- package/dist/cache/inFlight.d.ts.map +1 -0
- package/dist/cache/key.d.ts +10 -0
- package/dist/cache/key.d.ts.map +1 -0
- package/dist/cache/memoryCache.d.ts +16 -0
- package/dist/cache/memoryCache.d.ts.map +1 -0
- package/dist/cache/types.d.ts +13 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/client/errors.d.ts +29 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/httpClient.d.ts +13 -0
- package/dist/client/httpClient.d.ts.map +1 -0
- package/dist/client/types.d.ts +84 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/guards/bearerRefreshGuard.d.ts +45 -0
- package/dist/guards/bearerRefreshGuard.d.ts.map +1 -0
- package/dist/guards/cookieSafeRefreshGuard.d.ts +40 -0
- package/dist/guards/cookieSafeRefreshGuard.d.ts.map +1 -0
- package/dist/guards/correlationIdGuard.d.ts +18 -0
- package/dist/guards/correlationIdGuard.d.ts.map +1 -0
- package/dist/guards/csrfGuard.d.ts +25 -0
- package/dist/guards/csrfGuard.d.ts.map +1 -0
- package/dist/guards/idempotencyGuard.d.ts +25 -0
- package/dist/guards/idempotencyGuard.d.ts.map +1 -0
- package/dist/guards/instrumentGuard.d.ts +12 -0
- package/dist/guards/instrumentGuard.d.ts.map +1 -0
- package/dist/guards/retryGuard.d.ts +12 -0
- package/dist/guards/retryGuard.d.ts.map +1 -0
- package/dist/guards/types.d.ts +3 -0
- package/dist/guards/types.d.ts.map +1 -0
- package/dist/guards/unauthorizedGuard.d.ts +19 -0
- package/dist/guards/unauthorizedGuard.d.ts.map +1 -0
- package/dist/index.cjs +1734 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +27 -266
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1077 -42
- package/dist/index.js.map +1 -1
- package/dist/internal/authGuard.d.ts +4 -0
- package/dist/internal/authGuard.d.ts.map +1 -0
- package/dist/internal/compose.d.ts +7 -0
- package/dist/internal/compose.d.ts.map +1 -0
- package/dist/internal/context.d.ts +57 -0
- package/dist/internal/context.d.ts.map +1 -0
- package/dist/internal/headersPolyfill.d.ts +25 -0
- package/dist/internal/headersPolyfill.d.ts.map +1 -0
- package/dist/internal/stableStringify.d.ts +2 -0
- package/dist/internal/stableStringify.d.ts.map +1 -0
- package/dist/internal/url.d.ts +3 -0
- package/dist/internal/url.d.ts.map +1 -0
- package/dist/notify/defaults.d.ts +9 -0
- package/dist/notify/defaults.d.ts.map +1 -0
- package/dist/notify/types.d.ts +33 -0
- package/dist/notify/types.d.ts.map +1 -0
- package/dist/parsing/apiParserStructured.d.ts +94 -0
- package/dist/parsing/apiParserStructured.d.ts.map +1 -0
- package/dist/parsing/presets.d.ts +15 -0
- package/dist/parsing/presets.d.ts.map +1 -0
- package/dist/parsing/schemaAdapter.d.ts +18 -0
- package/dist/parsing/schemaAdapter.d.ts.map +1 -0
- package/dist/parsing/shapeParser.d.ts +8 -0
- package/dist/parsing/shapeParser.d.ts.map +1 -0
- package/dist/plugins/types.d.ts +22 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/presets/presetBuilder.d.ts +181 -0
- package/dist/presets/presetBuilder.d.ts.map +1 -0
- package/dist/publicTypes.d.ts +12 -0
- package/dist/publicTypes.d.ts.map +1 -0
- package/package.json +10 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on *Keep a Changelog*, and this project adheres to *Semantic Versioning*.
|
|
6
|
+
|
|
7
|
+
## Unreleased
|
|
8
|
+
|
|
9
|
+
### Contract (security)
|
|
10
|
+
|
|
11
|
+
- Refresh single-flight: concurrent 401s trigger only one refresh request.
|
|
12
|
+
- Refresh cooldown: honor `429` + `Retry-After` to prevent refresh storms.
|
|
13
|
+
- Refresh path resolution: absolute refresh URLs are preserved; relative paths are resolved against `baseUrl`.
|
|
14
|
+
- Bootstrap flow: `/auth/me` 401 → refresh → replay once (maxRetry=1).
|
|
15
|
+
- No refresh on network errors (fetch/CORS/abort throws): no replay, no refresh.
|
|
16
|
+
- Anti-loop: refresh+replay never triggers a second refresh for the same request attempt.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### DX (presets, aliases, plugins)
|
|
20
|
+
|
|
21
|
+
- Preset builder and alias factories are contract-tested (stable DX surface).
|
|
22
|
+
- Cookie refresh remains opt-in; bearer auth never refreshes by default.
|
|
23
|
+
- Plugins are applied synchronously in order and de-duplicated by name (first wins).
|
package/LICENSE
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
MIT
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cedvict
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
Core HTTP client (Promises) built on `fetch`.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
|
+
|
|
7
|
+
**Runtime requirement:** Node **>= 22** (or any modern browser/edge runtime with `fetch`).
|
|
8
|
+
|
|
9
|
+
If you run in an environment without a global `fetch`, pass one explicitly via `createHttpClient({ fetch })`.
|
|
6
10
|
```bash
|
|
7
11
|
npm i @cedvict/http-guardian
|
|
8
12
|
```
|
|
@@ -31,14 +35,233 @@ else console.error(res.errors);
|
|
|
31
35
|
- `createApiParserLaravel()`
|
|
32
36
|
- `createApiParserNest()`
|
|
33
37
|
- `createApiParserGraphQL({ allowPartialData? })`
|
|
38
|
+
- `createApiParserStructured({ exposeMeta?, honorRetryableHint? })` — parser
|
|
39
|
+
pour une enveloppe structurée typée :
|
|
40
|
+
`{ success, code, message, issues[], i18n, meta { traceId, spanId } }`.
|
|
41
|
+
En cas d'erreur, chaque `AppError` porte `code`/`message` et expose dans
|
|
42
|
+
`details` les champs structurés (`category`, `severity`, `retryable`, `i18n`,
|
|
43
|
+
`traceId`, `spanId`, `envelope`).
|
|
34
44
|
|
|
35
45
|
## Auth modes
|
|
36
46
|
- `bearerAuth(() => token)`
|
|
37
47
|
- `cookieAuth({ credentials: "include", csrf: { headerName, getToken } })`
|
|
38
48
|
- `noAuth()`
|
|
39
49
|
|
|
50
|
+
## Guards
|
|
51
|
+
|
|
52
|
+
Les guards composent un middleware autour de chaque requête.
|
|
53
|
+
|
|
54
|
+
### `bearerRefreshGuard({ refreshFn, onAuthFailed?, ... })`
|
|
55
|
+
|
|
56
|
+
Refresh JWT Bearer **single-flight** : sur 401, un seul `refreshFn()` est invoqué ;
|
|
57
|
+
toutes les autres requêtes 401 reçues pendant ce refresh attendent dans une queue
|
|
58
|
+
partagée puis sont rejouées avec le nouveau token. Si le refresh échoue,
|
|
59
|
+
`onAuthFailed(error)` est appelé une seule fois et toutes les requêtes en queue
|
|
60
|
+
voient le 401 d'origine.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { createHttpClient, bearerAuth, bearerRefreshGuard } from "@cedvict/http-guardian";
|
|
64
|
+
|
|
65
|
+
createHttpClient({
|
|
66
|
+
auth: bearerAuth(() => tokenStore.access()),
|
|
67
|
+
guards: [
|
|
68
|
+
bearerRefreshGuard({
|
|
69
|
+
refreshFn: async () => {
|
|
70
|
+
const { accessToken, refreshToken } = await api.refresh();
|
|
71
|
+
tokenStore.set(accessToken, refreshToken);
|
|
72
|
+
return { accessToken, refreshToken };
|
|
73
|
+
},
|
|
74
|
+
onAuthFailed: () => router.navigate("/login"),
|
|
75
|
+
skipRefreshFor: (ctx) => ctx.url.includes("/auth/"),
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### `csrfGuard({ tokenFromCookie?, tokenFromStorage?, tokenFromHeader?, headerName?, applyTo? })`
|
|
82
|
+
|
|
83
|
+
Injecte un header `X-CSRF-Token` (défaut) sur les méthodes mutantes
|
|
84
|
+
(`POST`/`PUT`/`PATCH`/`DELETE`). **SSR-safe** : si `tokenFromCookie` est utilisé
|
|
85
|
+
hors browser (`typeof document === 'undefined'`), le guard skippe silencieusement.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
csrfGuard(
|
|
89
|
+
isPlatformBrowser(platformId)
|
|
90
|
+
? { tokenFromCookie: "csrf_token" }
|
|
91
|
+
: { tokenFromStorage: () => null },
|
|
92
|
+
);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### `correlationIdGuard({ headerName?, generator?, readResponseHeader? })`
|
|
96
|
+
|
|
97
|
+
Injecte un header `X-Correlation-Id` (UUID v4 par défaut, fallback
|
|
98
|
+
`Math.random()`+timestamp si `crypto.randomUUID` absent). L'ID est **stable
|
|
99
|
+
entre retries** (mémorisé sur le ctx). Si la réponse contient le même header,
|
|
100
|
+
il est copié dans `ctx.meta.correlationId` pour les plugins downstream
|
|
101
|
+
(logger, sentry, otel).
|
|
102
|
+
|
|
103
|
+
### `idempotencyGuard({ headerName?, applyTo?, respectExisting? })`
|
|
104
|
+
|
|
105
|
+
Injecte un header `X-Idempotency-Key` (UUID par défaut) sur `POST`/`PUT`/`PATCH`.
|
|
106
|
+
La clé est **stable entre retries** — sinon l'idempotence côté serveur est cassée.
|
|
107
|
+
Respecte une clé fournie via `RequestOptions.idempotencyKey`,
|
|
108
|
+
`ctx.idempotencyKey`, ou directement via header.
|
|
109
|
+
|
|
110
|
+
## Recipe : mapper le `traceId` backend ↔ Sentry / OTel frontend
|
|
111
|
+
|
|
112
|
+
Quand le backend renvoie une enveloppe avec un `meta.traceId` (et `spanId`)
|
|
113
|
+
— typiquement via `createApiParserStructured` — il est utile de stitcher cette
|
|
114
|
+
trace avec le span/event front-end pour qu'un incident Sentry pointe directement
|
|
115
|
+
vers la trace backend correspondante (et inversement).
|
|
116
|
+
|
|
117
|
+
Le pattern repose sur deux briques :
|
|
118
|
+
1. **`correlationIdGuard`** génère un `X-Correlation-Id` propagé sur la requête,
|
|
119
|
+
et lit le header de réponse pour exposer l'ID dans `ctx.meta.correlationId`.
|
|
120
|
+
2. **`createApiParserStructured`** stocke `traceId` / `spanId` dans
|
|
121
|
+
`errors[].details` (en cas d'erreur). Pour les chemins succès, on lit le
|
|
122
|
+
header de réponse via un petit guard dédié.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import {
|
|
126
|
+
createHttpClient,
|
|
127
|
+
bearerAuth,
|
|
128
|
+
correlationIdGuard,
|
|
129
|
+
createApiParserStructured,
|
|
130
|
+
type Guard,
|
|
131
|
+
} from "@cedvict/http-guardian";
|
|
132
|
+
import { sentryPlugin } from "@cedvict/http-guardian-plugin-sentry";
|
|
133
|
+
import { otelPlugin } from "@cedvict/http-guardian-plugin-otel";
|
|
134
|
+
import * as Sentry from "@sentry/browser";
|
|
135
|
+
|
|
136
|
+
// Lit X-Trace-Id / X-Span-Id de la réponse et les pose sur ctx.meta pour
|
|
137
|
+
// les plugins downstream (sentry, otel, logger).
|
|
138
|
+
const traceMetaGuard: Guard = async (ctx, next) => {
|
|
139
|
+
const res = await next(ctx);
|
|
140
|
+
const traceId = res.headers.get("x-trace-id");
|
|
141
|
+
const spanId = res.headers.get("x-span-id");
|
|
142
|
+
if (traceId || spanId) {
|
|
143
|
+
ctx.meta ??= {};
|
|
144
|
+
if (traceId) ctx.meta.traceId = traceId;
|
|
145
|
+
if (spanId) ctx.meta.spanId = spanId;
|
|
146
|
+
}
|
|
147
|
+
return res;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const api = createHttpClient({
|
|
151
|
+
baseUrl: "https://api.example.com",
|
|
152
|
+
auth: bearerAuth(() => token),
|
|
153
|
+
parser: createApiParserStructured(),
|
|
154
|
+
guards: [correlationIdGuard(), traceMetaGuard],
|
|
155
|
+
plugins: [
|
|
156
|
+
sentryPlugin({
|
|
157
|
+
// shouldCapture reçoit le ctx → on lit ctx.meta pour tagger l'event Sentry.
|
|
158
|
+
shouldCapture: ({ status, ctx }) => {
|
|
159
|
+
if (status && status >= 500) {
|
|
160
|
+
Sentry.getCurrentScope().setTags({
|
|
161
|
+
"backend.trace_id": ctx.meta?.traceId ?? "",
|
|
162
|
+
correlation_id: ctx.meta?.correlationId ?? "",
|
|
163
|
+
});
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
},
|
|
168
|
+
}),
|
|
169
|
+
otelPlugin({
|
|
170
|
+
setAttributes: (span, ctx) => {
|
|
171
|
+
if (ctx.meta?.traceId) span.setAttribute("backend.trace_id", ctx.meta.traceId);
|
|
172
|
+
if (ctx.meta?.spanId) span.setAttribute("backend.span_id", ctx.meta.spanId);
|
|
173
|
+
if (ctx.meta?.correlationId) span.setAttribute("correlation_id", ctx.meta.correlationId);
|
|
174
|
+
},
|
|
175
|
+
}),
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Côté erreur, l'enveloppe parsée par `createApiParserStructured` expose déjà
|
|
181
|
+
`traceId` / `spanId` dans `result.errors[0].details` :
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
const r = await api.post("/orders", { json: payload });
|
|
185
|
+
if (!r.ok) {
|
|
186
|
+
const d = r.errors[0]?.details as { traceId?: string; spanId?: string } | undefined;
|
|
187
|
+
console.error("backend trace:", d?.traceId, d?.spanId);
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
40
191
|
## Redirects
|
|
41
192
|
- `redirects: { mode: "follow" | "manual" | "error", maxHops, onRedirect }`
|
|
42
193
|
|
|
43
194
|
## Testing
|
|
44
195
|
See `TESTING.md`.
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
## Cookie session refresh guard (single-flight, cooldown, anti-loop)
|
|
199
|
+
If you use cookie-based auth and your backend exposes a refresh endpoint, you can add the safe refresh guard:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import { createHttpClient, cookieAuth, cookieSafeRefreshGuard, createApiParserRestClassic } from "@cedvict/http-guardian";
|
|
203
|
+
|
|
204
|
+
const api = createHttpClient({
|
|
205
|
+
baseUrl: "https://api.example.com",
|
|
206
|
+
auth: cookieAuth({ credentials: "include" }),
|
|
207
|
+
parser: createApiParserRestClassic(),
|
|
208
|
+
guards: [
|
|
209
|
+
cookieSafeRefreshGuard({
|
|
210
|
+
refreshPath: "/auth/refresh", // or absolute: "https://auth.example.com/refresh"
|
|
211
|
+
maxRetry: 1, // anti-loop (default)
|
|
212
|
+
honorRetryAfter: true // cooldown on 429 (default)
|
|
213
|
+
})
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
You can disable any auth/refresh behavior per-request with `noAuth: true`:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
await api.get("/public/health", { noAuth: true });
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Notifier redaction (optional)
|
|
225
|
+
If you provide a custom notifier and it logs/sends events to telemetry, you can add a `redact` function
|
|
226
|
+
to strip secrets from the event payload (e.g. query params in `url`):
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
import type { Notifier, NotifyEvent } from "@cedvict/http-guardian";
|
|
230
|
+
|
|
231
|
+
const notifier: Notifier = {
|
|
232
|
+
redact: (e: NotifyEvent) => ({ ...e, url: e.url.replace(/\?.*$/, "") }),
|
|
233
|
+
notify: (e) => console.error(e),
|
|
234
|
+
};
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Preset builder & aliases (stable DX)
|
|
238
|
+
|
|
239
|
+
If you want a 1-liner setup without losing access to `createHttpClient`, use the preset builder:
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
import { createPresetBuilder } from "@cedvict/http-guardian";
|
|
243
|
+
|
|
244
|
+
const api = createPresetBuilder({ baseUrl: "https://api.example.com" })
|
|
245
|
+
.cookie({ credentials: "include" })
|
|
246
|
+
// opt-in only:
|
|
247
|
+
// .cookieRefresh({ refreshPath: "/auth/refresh", mePath: "/auth/me" })
|
|
248
|
+
.create();
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Aliases (thin wrappers around the preset builder):
|
|
252
|
+
|
|
253
|
+
- `createCookieClient({ baseUrl, refresh?: CookieSafeRefreshGuardOptions | null, ... })`
|
|
254
|
+
- `createBearerClient({ baseUrl, getToken, ... })`
|
|
255
|
+
|
|
256
|
+
### Stable auth refresh policy
|
|
257
|
+
|
|
258
|
+
- **Cookie auth**: refresh is **opt-in** (add `cookieRefresh(...)` or pass `refresh` to `createCookieClient`).
|
|
259
|
+
- **Bearer auth**: refresh is **disabled by default**.
|
|
260
|
+
|
|
261
|
+
## Plugins (config-time)
|
|
262
|
+
|
|
263
|
+
`plugins` are applied synchronously during `createHttpClient(...)` to mutate a draft options object.
|
|
264
|
+
|
|
265
|
+
Contract:
|
|
266
|
+
- Applied **in order**
|
|
267
|
+
- De-duplicated by `name` (first wins)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { HttpClientOptions } from "./client/types.js";
|
|
2
|
+
import type { ShapeParser } from "./parsing/shapeParser.js";
|
|
3
|
+
import type { AuthConfig } from "./auth/authConfig.js";
|
|
4
|
+
import type { Notifier } from "./notify/types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Alias A: minimal, safe defaults.
|
|
7
|
+
*
|
|
8
|
+
* Goal: `createHttpClient` stays максимально configurable,
|
|
9
|
+
* while `createClient` offers a “works out of the box” path.
|
|
10
|
+
*/
|
|
11
|
+
export type CreateClientOptions = {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
/** Default: createApiParserRestClassic() */
|
|
14
|
+
parser?: ShapeParser;
|
|
15
|
+
/** Default: noAuth() */
|
|
16
|
+
auth?: AuthConfig;
|
|
17
|
+
fetch?: HttpClientOptions["fetch"];
|
|
18
|
+
notifier?: Notifier;
|
|
19
|
+
defaults?: HttpClientOptions["defaults"];
|
|
20
|
+
cache?: HttpClientOptions["cache"];
|
|
21
|
+
redirects?: HttpClientOptions["redirects"];
|
|
22
|
+
guards?: HttpClientOptions["guards"];
|
|
23
|
+
};
|
|
24
|
+
export declare function createClient(opts: CreateClientOptions): {
|
|
25
|
+
get: <T>(path: string, ro?: import("./publicTypes.js").RequestOptions<T>) => Promise<import("./publicTypes.js").ClientResult<T>>;
|
|
26
|
+
post: <T>(path: string, ro?: import("./publicTypes.js").RequestOptions<T>) => Promise<import("./publicTypes.js").ClientResult<T>>;
|
|
27
|
+
put: <T>(path: string, ro?: import("./publicTypes.js").RequestOptions<T>) => Promise<import("./publicTypes.js").ClientResult<T>>;
|
|
28
|
+
patch: <T>(path: string, ro?: import("./publicTypes.js").RequestOptions<T>) => Promise<import("./publicTypes.js").ClientResult<T>>;
|
|
29
|
+
delete: <T>(path: string, ro?: import("./publicTypes.js").RequestOptions<T>) => Promise<import("./publicTypes.js").ClientResult<T>>;
|
|
30
|
+
cache: {
|
|
31
|
+
invalidateByTag: (tag: string) => number;
|
|
32
|
+
clear: () => void | undefined;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=aliases.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../src/aliases.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlD;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,wBAAwB;IACxB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACnC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC;CACtC,CAAC;AAEF,wBAAgB,YAAY,CAAC,IAAI,EAAE,mBAAmB;;;;;;;;;;EAmBrD"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export type BearerAuthConfig = {
|
|
2
|
+
mode: "bearer";
|
|
3
|
+
getToken: () => string | null | Promise<string | null>;
|
|
4
|
+
headerName?: string;
|
|
5
|
+
prefix?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Security hardening: only attach auth headers if request origin is allowed.
|
|
8
|
+
* If omitted: only same-origin as the client's baseUrl is allowed.
|
|
9
|
+
*/
|
|
10
|
+
allowedOrigins?: string[] | ((url: string) => boolean);
|
|
11
|
+
};
|
|
12
|
+
export type CookieAuthConfig = {
|
|
13
|
+
mode: "cookie";
|
|
14
|
+
/**
|
|
15
|
+
* Sets RequestInit.credentials for every request.
|
|
16
|
+
* Use "include" for cross-site cookies.
|
|
17
|
+
*/
|
|
18
|
+
credentials?: RequestCredentials;
|
|
19
|
+
/**
|
|
20
|
+
* Optional CSRF support for cookie-based sessions.
|
|
21
|
+
* If provided, a header will be injected on non-GET requests.
|
|
22
|
+
*/
|
|
23
|
+
csrf?: {
|
|
24
|
+
headerName: string;
|
|
25
|
+
getToken: () => string | null | Promise<string | null>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type BasicAuthConfig = {
|
|
29
|
+
mode: "basic";
|
|
30
|
+
/**
|
|
31
|
+
* Return either { username, password } or a pre-encoded "user:pass" string.
|
|
32
|
+
* Return null to skip auth.
|
|
33
|
+
*/
|
|
34
|
+
getCredentials: () => {
|
|
35
|
+
username: string;
|
|
36
|
+
password: string;
|
|
37
|
+
} | string | null | Promise<{
|
|
38
|
+
username: string;
|
|
39
|
+
password: string;
|
|
40
|
+
} | string | null>;
|
|
41
|
+
headerName?: string;
|
|
42
|
+
prefix?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Security hardening: only attach auth headers if request origin is allowed.
|
|
45
|
+
* If omitted: only same-origin as the client's baseUrl is allowed.
|
|
46
|
+
*/
|
|
47
|
+
allowedOrigins?: string[] | ((url: string) => boolean);
|
|
48
|
+
};
|
|
49
|
+
export type ApiKeyAuthConfig = {
|
|
50
|
+
mode: "apiKey";
|
|
51
|
+
getKey: () => string | null | Promise<string | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Header to use for API key auth (default: "X-API-Key").
|
|
54
|
+
* You can also set to "Authorization" and use prefix.
|
|
55
|
+
*/
|
|
56
|
+
headerName?: string;
|
|
57
|
+
prefix?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Security hardening: only attach API key header if request origin is allowed.
|
|
60
|
+
* If omitted: only same-origin as the client's baseUrl is allowed.
|
|
61
|
+
*/
|
|
62
|
+
allowedOrigins?: string[] | ((url: string) => boolean);
|
|
63
|
+
};
|
|
64
|
+
export type NoneAuthConfig = {
|
|
65
|
+
mode: "none";
|
|
66
|
+
};
|
|
67
|
+
export type AuthConfig = BearerAuthConfig | CookieAuthConfig | BasicAuthConfig | ApiKeyAuthConfig | NoneAuthConfig;
|
|
68
|
+
export declare function bearerAuth(getToken: () => string | null | Promise<string | null>, opts?: {
|
|
69
|
+
headerName?: string;
|
|
70
|
+
prefix?: string;
|
|
71
|
+
allowedOrigins?: BearerAuthConfig["allowedOrigins"];
|
|
72
|
+
}): BearerAuthConfig;
|
|
73
|
+
export declare function cookieAuth(opts?: {
|
|
74
|
+
credentials?: RequestCredentials;
|
|
75
|
+
csrf?: {
|
|
76
|
+
headerName: string;
|
|
77
|
+
getToken: () => string | null | Promise<string | null>;
|
|
78
|
+
};
|
|
79
|
+
}): CookieAuthConfig;
|
|
80
|
+
export declare function basicAuth(getCredentials: BasicAuthConfig["getCredentials"], opts?: {
|
|
81
|
+
headerName?: string;
|
|
82
|
+
prefix?: string;
|
|
83
|
+
allowedOrigins?: BasicAuthConfig["allowedOrigins"];
|
|
84
|
+
}): BasicAuthConfig;
|
|
85
|
+
export declare function apiKeyAuth(getKey: () => string | null | Promise<string | null>, opts?: {
|
|
86
|
+
headerName?: string;
|
|
87
|
+
prefix?: string;
|
|
88
|
+
allowedOrigins?: ApiKeyAuthConfig["allowedOrigins"];
|
|
89
|
+
}): ApiKeyAuthConfig;
|
|
90
|
+
export declare function noAuth(): NoneAuthConfig;
|
|
91
|
+
//# sourceMappingURL=authConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authConfig.d.ts","sourceRoot":"","sources":["../../src/auth/authConfig.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;;OAGG;IACH,IAAI,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;KAAE,CAAC;CACvF,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,cAAc,EAAE,MACZ;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GACtC,MAAM,GACN,IAAI,GACJ,OA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AAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;KAAE,CAAC;CACvF,GAAG,gBAAgB,CAMnB;AAED,wBAAgB,SAAS,CACvB,cAAc,EAAE,eAAe,CAAC,gBAAgB,CAAC,EACjD,IAAI,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAA;CAAE,GAClG,eAAe,CAQjB;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,EACpD,IAAI,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAA;CAAE,GACnG,gBAAgB,CAQlB;AAED,wBAAgB,MAAM,IAAI,cAAc,CAEvC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-flight request de-duplication.
|
|
3
|
+
*/
|
|
4
|
+
export declare class InFlight {
|
|
5
|
+
private readonly map;
|
|
6
|
+
get(key: string): Promise<unknown> | undefined;
|
|
7
|
+
set(key: string, p: Promise<unknown>): void;
|
|
8
|
+
clear(): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=inFlight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inFlight.d.ts","sourceRoot":"","sources":["../../src/cache/inFlight.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAuC;IAE3D,GAAG,CAAC,GAAG,EAAE,MAAM;IAIf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC;IAOpC,KAAK;CAGN"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HeadersPolyfill } from "../internal/headersPolyfill.js";
|
|
2
|
+
export declare function makeCacheKey(parts: {
|
|
3
|
+
method: string;
|
|
4
|
+
url: string;
|
|
5
|
+
headers?: Headers | HeadersPolyfill;
|
|
6
|
+
body?: unknown;
|
|
7
|
+
idempotencyKey?: string;
|
|
8
|
+
keyOverride?: string;
|
|
9
|
+
}): string;
|
|
10
|
+
//# sourceMappingURL=key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../../src/cache/key.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IAGZ,OAAO,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;IACpC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,MAAM,CAkBT"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CacheStore } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link memoryCache}.
|
|
4
|
+
*/
|
|
5
|
+
export type MemoryCacheOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Maximum number of entries kept in memory (LRU-ish).
|
|
8
|
+
* Default: 1000
|
|
9
|
+
*/
|
|
10
|
+
maxEntries?: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Simple in-memory LRU-ish cache with tag invalidation.
|
|
14
|
+
*/
|
|
15
|
+
export declare function memoryCache(opts?: MemoryCacheOptions): CacheStore;
|
|
16
|
+
//# sourceMappingURL=memoryCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoryCache.d.ts","sourceRoot":"","sources":["../../src/cache/memoryCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,YAAY,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,kBAAkB,GAAG,UAAU,CAsFjE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type CacheEntry = {
|
|
2
|
+
expiresAt: number;
|
|
3
|
+
value: unknown;
|
|
4
|
+
tags?: string[];
|
|
5
|
+
};
|
|
6
|
+
export type CacheStore = {
|
|
7
|
+
get: (key: string) => CacheEntry | undefined;
|
|
8
|
+
set: (key: string, entry: CacheEntry) => void;
|
|
9
|
+
delete: (key: string) => void;
|
|
10
|
+
invalidateByTag: (tag: string) => number;
|
|
11
|
+
clear: () => void;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cache/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEhF,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,CAAC;IAC7C,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAC9C,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,eAAe,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACzC,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type AppError = {
|
|
2
|
+
message: string;
|
|
3
|
+
code?: string;
|
|
4
|
+
field?: string;
|
|
5
|
+
details?: unknown;
|
|
6
|
+
};
|
|
7
|
+
export declare class NetworkError extends Error {
|
|
8
|
+
readonly cause?: unknown | undefined;
|
|
9
|
+
name: string;
|
|
10
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
11
|
+
}
|
|
12
|
+
export declare class TimeoutError extends Error {
|
|
13
|
+
name: string;
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class RedirectError extends Error {
|
|
17
|
+
readonly fromUrl: string;
|
|
18
|
+
readonly toUrl?: string | undefined;
|
|
19
|
+
name: string;
|
|
20
|
+
constructor(message: string, fromUrl: string, toUrl?: string | undefined);
|
|
21
|
+
}
|
|
22
|
+
export declare class ParseError extends Error {
|
|
23
|
+
readonly raw?: unknown | undefined;
|
|
24
|
+
readonly cause?: unknown | undefined;
|
|
25
|
+
name: string;
|
|
26
|
+
constructor(message: string, raw?: unknown | undefined, cause?: unknown | undefined);
|
|
27
|
+
}
|
|
28
|
+
export declare const ILLEGAL_INVOCATION_HINT = "Detected a browser fetch invocation error (\"Illegal invocation\"). This usually happens when passing a detached reference to window.fetch. Fix by configuring the client with fetch: (input, init) => window.fetch(input, init) or fetch: window.fetch.bind(window).";
|
|
29
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,qBAAa,YAAa,SAAQ,KAAK;aAEQ,KAAK,CAAC,EAAE,OAAO;IAD5D,IAAI,SAAkB;gBACV,OAAO,EAAE,MAAM,EAAkB,KAAK,CAAC,EAAE,OAAO,YAAA;CAG7D;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,SAAkB;gBACV,OAAO,SAAsB;CAG1C;AAED,qBAAa,aAAc,SAAQ,KAAK;aAEO,OAAO,EAAE,MAAM;aAAkB,KAAK,CAAC,EAAE,MAAM;IAD5F,IAAI,SAAmB;gBACX,OAAO,EAAE,MAAM,EAAkB,OAAO,EAAE,MAAM,EAAkB,KAAK,CAAC,EAAE,MAAM,YAAA;CAG7F;AAED,qBAAa,UAAW,SAAQ,KAAK;aAEU,GAAG,CAAC,EAAE,OAAO;aAAkB,KAAK,CAAC,EAAE,OAAO;IAD3F,IAAI,SAAgB;gBACR,OAAO,EAAE,MAAM,EAAkB,GAAG,CAAC,EAAE,OAAO,YAAA,EAAkB,KAAK,CAAC,EAAE,OAAO,YAAA;CAG5F;AAGD,eAAO,MAAM,uBAAuB,0QAAwQ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HttpClientOptions, RequestOptions, ClientResult } from "./types.js";
|
|
2
|
+
export declare function createHttpClient(options: HttpClientOptions): {
|
|
3
|
+
get: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
|
|
4
|
+
post: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
|
|
5
|
+
put: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
|
|
6
|
+
patch: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
|
|
7
|
+
delete: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
|
|
8
|
+
cache: {
|
|
9
|
+
invalidateByTag: (tag: string) => number;
|
|
10
|
+
clear: () => void | undefined;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=httpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpClient.d.ts","sourceRoot":"","sources":["../../src/client/httpClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAc,MAAM,YAAY,CAAC;AA2C9F,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB;UAoOjD,CAAC,QAAQ,MAAM,OAAO,cAAc,CAAC,CAAC,CAAC;WACtC,CAAC,QAAQ,MAAM,OAAO,cAAc,CAAC,CAAC,CAAC;UACxC,CAAC,QAAQ,MAAM,OAAO,cAAc,CAAC,CAAC,CAAC;YACrC,CAAC,QAAQ,MAAM,OAAO,cAAc,CAAC,CAAC,CAAC;aACtC,CAAC,QAAQ,MAAM,OAAO,cAAc,CAAC,CAAC,CAAC;;+BAChB,MAAM;;;EAEzC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { AuthConfig } from "../auth/authConfig.js";
|
|
2
|
+
import type { Guard } from "../guards/types.js";
|
|
3
|
+
import type { CacheStore } from "../cache/types.js";
|
|
4
|
+
import type { ShapeParser } from "../parsing/shapeParser.js";
|
|
5
|
+
import type { Schema } from "../parsing/schemaAdapter.js";
|
|
6
|
+
import type { Notifier } from "../notify/types.js";
|
|
7
|
+
import type { AppError } from "./errors.js";
|
|
8
|
+
import type { HttpPlugin } from "../plugins/types.js";
|
|
9
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
10
|
+
export type RedirectMode = "follow" | "manual" | "error";
|
|
11
|
+
export type RedirectPolicy = {
|
|
12
|
+
mode: RedirectMode;
|
|
13
|
+
maxHops?: number;
|
|
14
|
+
onRedirect?: (info: {
|
|
15
|
+
fromUrl: string;
|
|
16
|
+
toUrl: string;
|
|
17
|
+
status: number;
|
|
18
|
+
hop: number;
|
|
19
|
+
method: HttpMethod;
|
|
20
|
+
}) => {
|
|
21
|
+
action: "follow";
|
|
22
|
+
} | {
|
|
23
|
+
action: "deny";
|
|
24
|
+
reason?: string;
|
|
25
|
+
} | {
|
|
26
|
+
action: "modify";
|
|
27
|
+
url: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export type CacheOptions = {
|
|
31
|
+
ttlMs: number;
|
|
32
|
+
key?: string;
|
|
33
|
+
tags?: string[];
|
|
34
|
+
policy?: "networkFirst" | "cacheFirst" | "cacheOnly" | "networkOnly" | "staleWhileRevalidate";
|
|
35
|
+
dedupe?: boolean;
|
|
36
|
+
};
|
|
37
|
+
export type RequestOptions<T> = {
|
|
38
|
+
query?: Record<string, string | number | boolean | null | undefined>;
|
|
39
|
+
headers?: Record<string, string | undefined>;
|
|
40
|
+
json?: unknown;
|
|
41
|
+
body?: BodyInit;
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
cache?: CacheOptions;
|
|
45
|
+
dataSchema?: Schema<T>;
|
|
46
|
+
notifier?: Notifier;
|
|
47
|
+
noAuth?: boolean;
|
|
48
|
+
idempotencyKey?: string;
|
|
49
|
+
};
|
|
50
|
+
export type ClientResult<T> = {
|
|
51
|
+
ok: true;
|
|
52
|
+
status: number;
|
|
53
|
+
headers: Headers;
|
|
54
|
+
data: T;
|
|
55
|
+
raw: unknown;
|
|
56
|
+
url: string;
|
|
57
|
+
} | {
|
|
58
|
+
ok: false;
|
|
59
|
+
status: number;
|
|
60
|
+
headers: Headers;
|
|
61
|
+
errors: AppError[];
|
|
62
|
+
raw: unknown;
|
|
63
|
+
url: string;
|
|
64
|
+
};
|
|
65
|
+
export type HttpClientOptions = {
|
|
66
|
+
baseUrl: string;
|
|
67
|
+
fetch?: typeof fetch;
|
|
68
|
+
auth: AuthConfig;
|
|
69
|
+
parser: ShapeParser;
|
|
70
|
+
cache?: CacheStore;
|
|
71
|
+
notifier?: Notifier;
|
|
72
|
+
redirects?: RedirectPolicy;
|
|
73
|
+
plugins?: HttpPlugin[];
|
|
74
|
+
defaults?: {
|
|
75
|
+
headers?: Record<string, string>;
|
|
76
|
+
timeoutMs?: number;
|
|
77
|
+
shouldNotify?: (result: {
|
|
78
|
+
ok: boolean;
|
|
79
|
+
status: number;
|
|
80
|
+
}) => boolean;
|
|
81
|
+
};
|
|
82
|
+
guards?: Guard[];
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AACrE,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE;QAClB,O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