@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.
- package/CHANGELOG.md +23 -0
- package/LICENSE +21 -1
- package/README.md +76 -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/cookieSafeRefreshGuard.d.ts +40 -0
- package/dist/guards/cookieSafeRefreshGuard.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 +1413 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +22 -322
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +643 -63
- 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 +31 -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/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/dist/index.d.ts
CHANGED
|
@@ -1,322 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
declare function cookieAuth(opts?: {
|
|
24
|
-
credentials?: RequestCredentials;
|
|
25
|
-
csrf?: {
|
|
26
|
-
headerName: string;
|
|
27
|
-
getToken: () => string | null | Promise<string | null>;
|
|
28
|
-
};
|
|
29
|
-
}): CookieAuthConfig;
|
|
30
|
-
declare function noAuth(): NoneAuthConfig;
|
|
31
|
-
|
|
32
|
-
type AppError = {
|
|
33
|
-
message: string;
|
|
34
|
-
code?: string;
|
|
35
|
-
field?: string;
|
|
36
|
-
details?: unknown;
|
|
37
|
-
};
|
|
38
|
-
declare class NetworkError extends Error {
|
|
39
|
-
readonly cause?: unknown | undefined;
|
|
40
|
-
name: string;
|
|
41
|
-
constructor(message: string, cause?: unknown | undefined);
|
|
42
|
-
}
|
|
43
|
-
declare class TimeoutError extends Error {
|
|
44
|
-
name: string;
|
|
45
|
-
constructor(message?: string);
|
|
46
|
-
}
|
|
47
|
-
declare class RedirectError extends Error {
|
|
48
|
-
readonly fromUrl: string;
|
|
49
|
-
readonly toUrl?: string | undefined;
|
|
50
|
-
name: string;
|
|
51
|
-
constructor(message: string, fromUrl: string, toUrl?: string | undefined);
|
|
52
|
-
}
|
|
53
|
-
declare class ParseError extends Error {
|
|
54
|
-
readonly raw?: unknown | undefined;
|
|
55
|
-
readonly cause?: unknown | undefined;
|
|
56
|
-
name: string;
|
|
57
|
-
constructor(message: string, raw?: unknown | undefined, cause?: unknown | undefined);
|
|
58
|
-
}
|
|
59
|
-
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).";
|
|
60
|
-
|
|
61
|
-
type NotifyEvent = {
|
|
62
|
-
type: "http-error";
|
|
63
|
-
level: "error" | "warning";
|
|
64
|
-
title: string;
|
|
65
|
-
message: string;
|
|
66
|
-
status: number;
|
|
67
|
-
errors?: AppError[];
|
|
68
|
-
url: string;
|
|
69
|
-
} | {
|
|
70
|
-
type: "network-error";
|
|
71
|
-
level: "error";
|
|
72
|
-
title: string;
|
|
73
|
-
message: string;
|
|
74
|
-
url: string;
|
|
75
|
-
} | {
|
|
76
|
-
type: "parse-error";
|
|
77
|
-
level: "error";
|
|
78
|
-
title: string;
|
|
79
|
-
message: string;
|
|
80
|
-
url: string;
|
|
81
|
-
};
|
|
82
|
-
type Notifier = {
|
|
83
|
-
notify: (event: NotifyEvent) => void;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
type RequestContext = {
|
|
87
|
-
method: HttpMethod;
|
|
88
|
-
url: string;
|
|
89
|
-
headers: Headers;
|
|
90
|
-
credentials?: RequestCredentials;
|
|
91
|
-
redirect?: RequestRedirect;
|
|
92
|
-
body?: BodyInit;
|
|
93
|
-
signal?: AbortSignal;
|
|
94
|
-
timeoutMs?: number;
|
|
95
|
-
attempt: number;
|
|
96
|
-
auth: AuthConfig;
|
|
97
|
-
noAuth?: boolean;
|
|
98
|
-
notifier?: Notifier;
|
|
99
|
-
idempotencyKey?: string;
|
|
100
|
-
_fetch: typeof fetch;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
type Guard = (ctx: RequestContext, next: (ctx: RequestContext) => Promise<Response>) => Promise<Response>;
|
|
104
|
-
|
|
105
|
-
type CacheEntry = {
|
|
106
|
-
expiresAt: number;
|
|
107
|
-
value: unknown;
|
|
108
|
-
tags?: string[];
|
|
109
|
-
};
|
|
110
|
-
type CacheStore = {
|
|
111
|
-
get: (key: string) => CacheEntry | undefined;
|
|
112
|
-
set: (key: string, entry: CacheEntry) => void;
|
|
113
|
-
delete: (key: string) => void;
|
|
114
|
-
invalidateByTag: (tag: string) => number;
|
|
115
|
-
clear: () => void;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
type ShapeParser = {
|
|
119
|
-
isSuccess: (raw: unknown, status: number) => boolean;
|
|
120
|
-
getData: (raw: unknown) => unknown;
|
|
121
|
-
getErrors: (raw: unknown, status: number) => AppError[];
|
|
122
|
-
};
|
|
123
|
-
declare function createShapeParser(p: ShapeParser): ShapeParser;
|
|
124
|
-
|
|
125
|
-
type Schema<T> = {
|
|
126
|
-
parse: (input: unknown) => T;
|
|
127
|
-
};
|
|
128
|
-
declare function schema<T>(impl: Schema<T>): Schema<T>;
|
|
129
|
-
/**
|
|
130
|
-
* Optional helper to wrap a zod-like schema without adding a dependency.
|
|
131
|
-
*/
|
|
132
|
-
declare function fromZod<T>(zodSchema: {
|
|
133
|
-
parse?: (i: unknown) => T;
|
|
134
|
-
safeParse?: (i: unknown) => {
|
|
135
|
-
success: true;
|
|
136
|
-
data: T;
|
|
137
|
-
} | {
|
|
138
|
-
success: false;
|
|
139
|
-
error: unknown;
|
|
140
|
-
};
|
|
141
|
-
}): Schema<T>;
|
|
142
|
-
|
|
143
|
-
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
144
|
-
type RedirectMode = "follow" | "manual" | "error";
|
|
145
|
-
type RedirectPolicy = {
|
|
146
|
-
mode: RedirectMode;
|
|
147
|
-
maxHops?: number;
|
|
148
|
-
onRedirect?: (info: {
|
|
149
|
-
fromUrl: string;
|
|
150
|
-
toUrl: string;
|
|
151
|
-
status: number;
|
|
152
|
-
hop: number;
|
|
153
|
-
method: HttpMethod;
|
|
154
|
-
}) => {
|
|
155
|
-
action: "follow";
|
|
156
|
-
} | {
|
|
157
|
-
action: "deny";
|
|
158
|
-
reason?: string;
|
|
159
|
-
} | {
|
|
160
|
-
action: "modify";
|
|
161
|
-
url: string;
|
|
162
|
-
};
|
|
163
|
-
};
|
|
164
|
-
type CacheOptions = {
|
|
165
|
-
ttlMs: number;
|
|
166
|
-
key?: string;
|
|
167
|
-
tags?: string[];
|
|
168
|
-
policy?: "networkFirst" | "cacheFirst" | "cacheOnly" | "networkOnly" | "staleWhileRevalidate";
|
|
169
|
-
dedupe?: boolean;
|
|
170
|
-
};
|
|
171
|
-
type RequestOptions<T> = {
|
|
172
|
-
query?: Record<string, string | number | boolean | null | undefined>;
|
|
173
|
-
headers?: Record<string, string | undefined>;
|
|
174
|
-
json?: unknown;
|
|
175
|
-
body?: BodyInit;
|
|
176
|
-
signal?: AbortSignal;
|
|
177
|
-
timeoutMs?: number;
|
|
178
|
-
cache?: CacheOptions;
|
|
179
|
-
dataSchema?: Schema<T>;
|
|
180
|
-
notifier?: Notifier;
|
|
181
|
-
noAuth?: boolean;
|
|
182
|
-
idempotencyKey?: string;
|
|
183
|
-
};
|
|
184
|
-
type ClientResult<T> = {
|
|
185
|
-
ok: true;
|
|
186
|
-
status: number;
|
|
187
|
-
headers: Headers;
|
|
188
|
-
data: T;
|
|
189
|
-
raw: unknown;
|
|
190
|
-
url: string;
|
|
191
|
-
} | {
|
|
192
|
-
ok: false;
|
|
193
|
-
status: number;
|
|
194
|
-
headers: Headers;
|
|
195
|
-
errors: AppError[];
|
|
196
|
-
raw: unknown;
|
|
197
|
-
url: string;
|
|
198
|
-
};
|
|
199
|
-
type HttpClientOptions = {
|
|
200
|
-
baseUrl: string;
|
|
201
|
-
fetch?: typeof fetch;
|
|
202
|
-
auth: AuthConfig;
|
|
203
|
-
parser: ShapeParser;
|
|
204
|
-
cache?: CacheStore;
|
|
205
|
-
notifier?: Notifier;
|
|
206
|
-
redirects?: RedirectPolicy;
|
|
207
|
-
defaults?: {
|
|
208
|
-
headers?: Record<string, string>;
|
|
209
|
-
timeoutMs?: number;
|
|
210
|
-
shouldNotify?: (result: {
|
|
211
|
-
ok: boolean;
|
|
212
|
-
status: number;
|
|
213
|
-
}) => boolean;
|
|
214
|
-
};
|
|
215
|
-
guards?: Guard[];
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
declare function createHttpClient(opts: HttpClientOptions): {
|
|
219
|
-
get: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
|
|
220
|
-
post: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
|
|
221
|
-
put: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
|
|
222
|
-
patch: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
|
|
223
|
-
delete: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
|
|
224
|
-
cache: {
|
|
225
|
-
invalidateByTag: (tag: string) => number;
|
|
226
|
-
clear: () => void | undefined;
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Simple retry guard for transient HTTP statuses.
|
|
232
|
-
* Note: this doesn't retry network errors thrown by fetch itself (those are handled by the client wrapper).
|
|
233
|
-
*/
|
|
234
|
-
declare function retryGuard(opts?: {
|
|
235
|
-
retries?: number;
|
|
236
|
-
retryOn?: number[];
|
|
237
|
-
baseDelayMs?: number;
|
|
238
|
-
maxDelayMs?: number;
|
|
239
|
-
}): Guard;
|
|
240
|
-
|
|
241
|
-
type CookieSafeRefreshGuardOptions = {
|
|
242
|
-
/**
|
|
243
|
-
* Endpoint refresh (absolu ou relatif)
|
|
244
|
-
* ex: "/api/v1/auth/refresh"
|
|
245
|
-
*/
|
|
246
|
-
refreshPath: string;
|
|
247
|
-
/**
|
|
248
|
-
* Méthode refresh (souvent POST)
|
|
249
|
-
*/
|
|
250
|
-
refreshMethod?: "POST" | "GET";
|
|
251
|
-
/**
|
|
252
|
-
* Statuts qui déclenchent refresh
|
|
253
|
-
* 401 classique, 419 (Laravel CSRF/session)
|
|
254
|
-
*/
|
|
255
|
-
triggerStatuses?: number[];
|
|
256
|
-
/**
|
|
257
|
-
* On ne tente pas de refresh si la requête originale est déjà un refresh
|
|
258
|
-
* ou si on détecte une boucle.
|
|
259
|
-
*/
|
|
260
|
-
maxRetry?: number;
|
|
261
|
-
/**
|
|
262
|
-
* Optionnel: si tu as un endpoint /me et tu veux explicitement l’exclure
|
|
263
|
-
* (souvent inutile)
|
|
264
|
-
*/
|
|
265
|
-
excludePaths?: string[];
|
|
266
|
-
/**
|
|
267
|
-
* Si refresh renvoie 429 Too Many Requests
|
|
268
|
-
* on stoppe les refresh jusqu’à une date (cooldown).
|
|
269
|
-
* default: true
|
|
270
|
-
*/
|
|
271
|
-
honorRetryAfter?: boolean;
|
|
272
|
-
/**
|
|
273
|
-
* Custom: décider si on refresh selon le ctx + status
|
|
274
|
-
*/
|
|
275
|
-
shouldRefresh?: (ctx: RequestContext, status: number) => boolean;
|
|
276
|
-
/**
|
|
277
|
-
* Hook: appelé quand refresh échoue (utile pour redirect login)
|
|
278
|
-
*/
|
|
279
|
-
onRefreshFailed?: (info: {
|
|
280
|
-
status?: number;
|
|
281
|
-
url: string;
|
|
282
|
-
reason?: string;
|
|
283
|
-
}) => void;
|
|
284
|
-
/**
|
|
285
|
-
* Hook: appelé quand refresh réussit
|
|
286
|
-
*/
|
|
287
|
-
onRefreshSuccess?: (info: {
|
|
288
|
-
url: string;
|
|
289
|
-
}) => void;
|
|
290
|
-
};
|
|
291
|
-
declare function cookieSafeRefreshGuard(opts: CookieSafeRefreshGuardOptions): Guard;
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Simple in-memory LRU-ish cache with tag invalidation.
|
|
295
|
-
*/
|
|
296
|
-
declare function memoryCache(opts?: {
|
|
297
|
-
maxEntries?: number;
|
|
298
|
-
}): CacheStore;
|
|
299
|
-
|
|
300
|
-
declare function createApiParserRestClassic(opts?: {
|
|
301
|
-
successField?: string;
|
|
302
|
-
dataField?: string;
|
|
303
|
-
errorField?: string;
|
|
304
|
-
messageField?: string;
|
|
305
|
-
}): ShapeParser;
|
|
306
|
-
declare function createApiParserLaravel(opts?: {
|
|
307
|
-
dataField?: string;
|
|
308
|
-
}): ShapeParser;
|
|
309
|
-
declare function createApiParserNest(): ShapeParser;
|
|
310
|
-
declare function createApiParserGraphQL(opts?: {
|
|
311
|
-
allowPartialData?: boolean;
|
|
312
|
-
}): ShapeParser;
|
|
313
|
-
|
|
314
|
-
declare const consoleNotifier: Notifier;
|
|
315
|
-
declare const alertNotifier: Notifier;
|
|
316
|
-
/**
|
|
317
|
-
* Returns an HTML string you can inject in your own UI layer (Tailwind classes).
|
|
318
|
-
* Note: this package does not manipulate the DOM by itself.
|
|
319
|
-
*/
|
|
320
|
-
declare function tailwindAlertRenderer(event: NotifyEvent): string;
|
|
321
|
-
|
|
322
|
-
export { type AppError, type AuthConfig, type BearerAuthConfig, type CacheEntry, type CacheOptions, type CacheStore, type ClientResult, type CookieAuthConfig, type CookieSafeRefreshGuardOptions, type Guard, type HttpClientOptions, type HttpMethod, ILLEGAL_INVOCATION_HINT, NetworkError, type NoneAuthConfig, type Notifier, type NotifyEvent, ParseError, RedirectError, type RedirectMode, type RedirectPolicy, type RequestContext, type RequestOptions, type Schema, type ShapeParser, TimeoutError, alertNotifier, bearerAuth, consoleNotifier, cookieAuth, cookieSafeRefreshGuard, createApiParserGraphQL, createApiParserLaravel, createApiParserNest, createApiParserRestClassic, createHttpClient, createShapeParser, fromZod, memoryCache, noAuth, retryGuard, schema, tailwindAlertRenderer };
|
|
1
|
+
export * from "./client/httpClient.js";
|
|
2
|
+
export * from "./client/types.js";
|
|
3
|
+
export * from "./client/errors.js";
|
|
4
|
+
export * from "./auth/authConfig.js";
|
|
5
|
+
export * from "./guards/types.js";
|
|
6
|
+
export * from "./guards/retryGuard.js";
|
|
7
|
+
export * from "./guards/cookieSafeRefreshGuard.js";
|
|
8
|
+
export * from "./guards/unauthorizedGuard.js";
|
|
9
|
+
export * from "./guards/instrumentGuard.js";
|
|
10
|
+
export * from "./cache/types.js";
|
|
11
|
+
export * from "./cache/memoryCache.js";
|
|
12
|
+
export * from "./parsing/shapeParser.js";
|
|
13
|
+
export * from "./parsing/schemaAdapter.js";
|
|
14
|
+
export * from "./parsing/presets.js";
|
|
15
|
+
export * from "./notify/types.js";
|
|
16
|
+
export * from "./notify/defaults.js";
|
|
17
|
+
export * from "./presets/presetBuilder.js";
|
|
18
|
+
export * from "./plugins/types.js";
|
|
19
|
+
export * from "./aliases.js";
|
|
20
|
+
export type { RequestContext } from "./internal/context.js";
|
|
21
|
+
export type * from "./publicTypes.js";
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,sBAAsB,CAAC;AAErC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAE5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AAErC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AAErC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AAGnC,cAAc,cAAc,CAAC;AAG7B,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,mBAAmB,kBAAkB,CAAC"}
|