@cedvict/http-guardian 0.0.1-next.6 → 0.0.1-next.7

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE +21 -1
  3. package/README.md +76 -0
  4. package/dist/aliases.d.ts +35 -0
  5. package/dist/aliases.d.ts.map +1 -0
  6. package/dist/auth/authConfig.d.ts +91 -0
  7. package/dist/auth/authConfig.d.ts.map +1 -0
  8. package/dist/cache/inFlight.d.ts +10 -0
  9. package/dist/cache/inFlight.d.ts.map +1 -0
  10. package/dist/cache/key.d.ts +10 -0
  11. package/dist/cache/key.d.ts.map +1 -0
  12. package/dist/cache/memoryCache.d.ts +16 -0
  13. package/dist/cache/memoryCache.d.ts.map +1 -0
  14. package/dist/cache/types.d.ts +13 -0
  15. package/dist/cache/types.d.ts.map +1 -0
  16. package/dist/client/errors.d.ts +29 -0
  17. package/dist/client/errors.d.ts.map +1 -0
  18. package/dist/client/httpClient.d.ts +13 -0
  19. package/dist/client/httpClient.d.ts.map +1 -0
  20. package/dist/client/types.d.ts +84 -0
  21. package/dist/client/types.d.ts.map +1 -0
  22. package/dist/guards/cookieSafeRefreshGuard.d.ts +40 -0
  23. package/dist/guards/cookieSafeRefreshGuard.d.ts.map +1 -0
  24. package/dist/guards/instrumentGuard.d.ts +12 -0
  25. package/dist/guards/instrumentGuard.d.ts.map +1 -0
  26. package/dist/guards/retryGuard.d.ts +12 -0
  27. package/dist/guards/retryGuard.d.ts.map +1 -0
  28. package/dist/guards/types.d.ts +3 -0
  29. package/dist/guards/types.d.ts.map +1 -0
  30. package/dist/guards/unauthorizedGuard.d.ts +19 -0
  31. package/dist/guards/unauthorizedGuard.d.ts.map +1 -0
  32. package/dist/index.cjs +1413 -0
  33. package/dist/index.cjs.map +1 -0
  34. package/dist/index.d.ts +22 -322
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +643 -63
  37. package/dist/index.js.map +1 -1
  38. package/dist/internal/authGuard.d.ts +4 -0
  39. package/dist/internal/authGuard.d.ts.map +1 -0
  40. package/dist/internal/compose.d.ts +7 -0
  41. package/dist/internal/compose.d.ts.map +1 -0
  42. package/dist/internal/context.d.ts +31 -0
  43. package/dist/internal/context.d.ts.map +1 -0
  44. package/dist/internal/headersPolyfill.d.ts +25 -0
  45. package/dist/internal/headersPolyfill.d.ts.map +1 -0
  46. package/dist/internal/stableStringify.d.ts +2 -0
  47. package/dist/internal/stableStringify.d.ts.map +1 -0
  48. package/dist/internal/url.d.ts +3 -0
  49. package/dist/internal/url.d.ts.map +1 -0
  50. package/dist/notify/defaults.d.ts +9 -0
  51. package/dist/notify/defaults.d.ts.map +1 -0
  52. package/dist/notify/types.d.ts +33 -0
  53. package/dist/notify/types.d.ts.map +1 -0
  54. package/dist/parsing/presets.d.ts +15 -0
  55. package/dist/parsing/presets.d.ts.map +1 -0
  56. package/dist/parsing/schemaAdapter.d.ts +18 -0
  57. package/dist/parsing/schemaAdapter.d.ts.map +1 -0
  58. package/dist/parsing/shapeParser.d.ts +8 -0
  59. package/dist/parsing/shapeParser.d.ts.map +1 -0
  60. package/dist/plugins/types.d.ts +22 -0
  61. package/dist/plugins/types.d.ts.map +1 -0
  62. package/dist/presets/presetBuilder.d.ts +181 -0
  63. package/dist/presets/presetBuilder.d.ts.map +1 -0
  64. package/dist/publicTypes.d.ts +12 -0
  65. package/dist/publicTypes.d.ts.map +1 -0
  66. 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
  ```
@@ -42,3 +46,75 @@ else console.error(res.errors);
42
46
 
43
47
  ## Testing
44
48
  See `TESTING.md`.
49
+
50
+
51
+ ## Cookie session refresh guard (single-flight, cooldown, anti-loop)
52
+ If you use cookie-based auth and your backend exposes a refresh endpoint, you can add the safe refresh guard:
53
+
54
+ ```ts
55
+ import { createHttpClient, cookieAuth, cookieSafeRefreshGuard, createApiParserRestClassic } from "@cedvict/http-guardian";
56
+
57
+ const api = createHttpClient({
58
+ baseUrl: "https://api.example.com",
59
+ auth: cookieAuth({ credentials: "include" }),
60
+ parser: createApiParserRestClassic(),
61
+ guards: [
62
+ cookieSafeRefreshGuard({
63
+ refreshPath: "/auth/refresh", // or absolute: "https://auth.example.com/refresh"
64
+ maxRetry: 1, // anti-loop (default)
65
+ honorRetryAfter: true // cooldown on 429 (default)
66
+ })
67
+ ],
68
+ });
69
+ ```
70
+
71
+ You can disable any auth/refresh behavior per-request with `noAuth: true`:
72
+
73
+ ```ts
74
+ await api.get("/public/health", { noAuth: true });
75
+ ```
76
+
77
+ ## Notifier redaction (optional)
78
+ If you provide a custom notifier and it logs/sends events to telemetry, you can add a `redact` function
79
+ to strip secrets from the event payload (e.g. query params in `url`):
80
+
81
+ ```ts
82
+ import type { Notifier, NotifyEvent } from "@cedvict/http-guardian";
83
+
84
+ const notifier: Notifier = {
85
+ redact: (e: NotifyEvent) => ({ ...e, url: e.url.replace(/\?.*$/, "") }),
86
+ notify: (e) => console.error(e),
87
+ };
88
+ ```
89
+
90
+ ## Preset builder & aliases (stable DX)
91
+
92
+ If you want a 1-liner setup without losing access to `createHttpClient`, use the preset builder:
93
+
94
+ ```ts
95
+ import { createPresetBuilder } from "@cedvict/http-guardian";
96
+
97
+ const api = createPresetBuilder({ baseUrl: "https://api.example.com" })
98
+ .cookie({ credentials: "include" })
99
+ // opt-in only:
100
+ // .cookieRefresh({ refreshPath: "/auth/refresh", mePath: "/auth/me" })
101
+ .create();
102
+ ```
103
+
104
+ Aliases (thin wrappers around the preset builder):
105
+
106
+ - `createCookieClient({ baseUrl, refresh?: CookieSafeRefreshGuardOptions | null, ... })`
107
+ - `createBearerClient({ baseUrl, getToken, ... })`
108
+
109
+ ### Stable auth refresh policy
110
+
111
+ - **Cookie auth**: refresh is **opt-in** (add `cookieRefresh(...)` or pass `refresh` to `createCookieClient`).
112
+ - **Bearer auth**: refresh is **disabled by default**.
113
+
114
+ ## Plugins (config-time)
115
+
116
+ `plugins` are applied synchronously during `createHttpClient(...)` to mutate a draft options object.
117
+
118
+ Contract:
119
+ - Applied **in order**
120
+ - 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,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AAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,EACtD,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,UAAU,CAAC,IAAI,CAAC,EAAE;IAChC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,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,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;AAEz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1
+ import type { Guard } from "./types.js";
2
+ import type { RequestContext } from "../internal/context.js";
3
+ export type CookieSafeRefreshGuardOptions = {
4
+ /**
5
+ * Endpoint refresh (absolu ou relatif)
6
+ * ex: "/auth/refresh" ou "https://api.example.com/auth/refresh"
7
+ */
8
+ refreshPath: string;
9
+ /** Méthode refresh (souvent POST) */
10
+ refreshMethod?: "POST" | "GET";
11
+ /** Statuts qui déclenchent refresh. Default: [401, 419] */
12
+ triggerStatuses?: number[];
13
+ /** Nombre max de replays de la requête originale. Default: 1 */
14
+ maxRetry?: number;
15
+ /**
16
+ * Exclure certains paths (pathname) de la logique refresh.
17
+ * Ex: ["/auth/refresh", "/health"]
18
+ */
19
+ excludePaths?: string[];
20
+ /**
21
+ * Si refresh renvoie 429 Too Many Requests,
22
+ * on stoppe les refresh jusqu’à une date (cooldown).
23
+ * Default: true
24
+ */
25
+ honorRetryAfter?: boolean;
26
+ /** Décider si on refresh selon ctx + status */
27
+ shouldRefresh?: (ctx: RequestContext, status: number) => boolean;
28
+ /** Hook: appelé quand refresh échoue (utile pour redirect login) */
29
+ onRefreshFailed?: (info: {
30
+ status?: number;
31
+ url: string;
32
+ reason?: string;
33
+ }) => void;
34
+ /** Hook: appelé quand refresh réussit */
35
+ onRefreshSuccess?: (info: {
36
+ url: string;
37
+ }) => void;
38
+ };
39
+ export declare function cookieSafeRefreshGuard(opts: CookieSafeRefreshGuardOptions): Guard;
40
+ //# sourceMappingURL=cookieSafeRefreshGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookieSafeRefreshGuard.d.ts","sourceRoot":"","sources":["../../src/guards/cookieSafeRefreshGuard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAO7D,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB,qCAAqC;IACrC,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAE/B,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,+CAA+C;IAC/C,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAEjE,oEAAoE;IACpE,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAEpF,yCAAyC;IACzC,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACpD,CAAC;AAoDF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,6BAA6B,GAAG,KAAK,CAyIjF"}
@@ -0,0 +1,12 @@
1
+ import type { Guard } from "./types.js";
2
+ type InstrumentOptions = {
3
+ name: string;
4
+ log?: (line: string, data?: any) => void;
5
+ include?: RegExp;
6
+ exclude?: RegExp;
7
+ logInit?: boolean;
8
+ stack?: boolean;
9
+ };
10
+ export declare function instrumentGuard(opts: InstrumentOptions, guard: Guard): Guard;
11
+ export {};
12
+ //# sourceMappingURL=instrumentGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentGuard.d.ts","sourceRoot":"","sources":["../../src/guards/instrumentGuard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AASxC,KAAK,iBAAiB,GAAG;IAEvB,IAAI,EAAE,MAAM,CAAC;IAGb,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAGzC,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAIlB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AA0CF,wBAAgB,eAAe,CAAC,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAiE5E"}
@@ -0,0 +1,12 @@
1
+ import type { Guard } from "./types.js";
2
+ /**
3
+ * Simple retry guard for transient HTTP statuses.
4
+ * Note: this doesn't retry network errors thrown by fetch itself (those are handled by the client wrapper).
5
+ */
6
+ export declare function retryGuard(opts?: {
7
+ retries?: number;
8
+ retryOn?: number[];
9
+ baseDelayMs?: number;
10
+ maxDelayMs?: number;
11
+ }): Guard;
12
+ //# sourceMappingURL=retryGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retryGuard.d.ts","sourceRoot":"","sources":["../../src/guards/retryGuard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,KAAK,CAkB5H"}
@@ -0,0 +1,3 @@
1
+ import type { RequestContext } from "../internal/context.js";
2
+ export type Guard = (ctx: RequestContext, next: (ctx: RequestContext) => Promise<Response>) => Promise<Response>;
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/guards/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Guard } from "./types.js";
2
+ import type { RequestContext } from "../internal/context.js";
3
+ export type UnauthorizedGuardOptions = {
4
+ onUnauthorized: (ctx: {
5
+ url: string;
6
+ status: number;
7
+ }) => void;
8
+ statuses?: number[];
9
+ ignoreNoAuth?: boolean;
10
+ once?: boolean;
11
+ cooldownMs?: number;
12
+ shouldHandle?: (ctx: RequestContext, status: number) => boolean;
13
+ excludePaths?: string[];
14
+ };
15
+ /**
16
+ * Centralizes “unauthorized” handling (redirect/logout) with anti-spam.
17
+ */
18
+ export declare function unauthorizedGuard(opts: UnauthorizedGuardOptions): Guard;
19
+ //# sourceMappingURL=unauthorizedGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unauthorizedGuard.d.ts","sourceRoot":"","sources":["../../src/guards/unauthorizedGuard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAa7D,MAAM,MAAM,wBAAwB,GAAG;IACrC,cAAc,EAAE,CAAC,GAAG,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC/D,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAChE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,wBAAwB,GAAG,KAAK,CA6CvE"}