@fgrzl/fetch 1.1.0-alpha.7 → 1.1.0
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 +50 -0
- package/CONTRIBUTING.md +327 -0
- package/README.md +50 -21
- package/dist/cjs/index.js +1110 -105
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +2 -0
- package/dist/cjs/index.min.js.map +1 -0
- package/dist/index.d.ts +1381 -10
- package/dist/index.js +1066 -91
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/package.json +14 -5
- package/dist/cjs/client/fetch-client.d.ts +0 -189
- package/dist/cjs/client/fetch-client.d.ts.map +0 -1
- package/dist/cjs/client/fetch-client.js +0 -339
- package/dist/cjs/client/fetch-client.js.map +0 -1
- package/dist/cjs/client/index.d.ts +0 -11
- package/dist/cjs/client/index.d.ts.map +0 -1
- package/dist/cjs/client/index.js +0 -14
- package/dist/cjs/client/index.js.map +0 -1
- package/dist/cjs/client/types.d.ts +0 -63
- package/dist/cjs/client/types.d.ts.map +0 -1
- package/dist/cjs/client/types.js +0 -9
- package/dist/cjs/client/types.js.map +0 -1
- package/dist/cjs/errors/index.d.ts +0 -64
- package/dist/cjs/errors/index.d.ts.map +0 -1
- package/dist/cjs/errors/index.js +0 -79
- package/dist/cjs/errors/index.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -65
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/middleware/authentication/authentication.d.ts +0 -31
- package/dist/cjs/middleware/authentication/authentication.d.ts.map +0 -1
- package/dist/cjs/middleware/authentication/authentication.js +0 -93
- package/dist/cjs/middleware/authentication/authentication.js.map +0 -1
- package/dist/cjs/middleware/authentication/index.d.ts +0 -37
- package/dist/cjs/middleware/authentication/index.d.ts.map +0 -1
- package/dist/cjs/middleware/authentication/index.js +0 -42
- package/dist/cjs/middleware/authentication/index.js.map +0 -1
- package/dist/cjs/middleware/authentication/types.d.ts +0 -73
- package/dist/cjs/middleware/authentication/types.d.ts.map +0 -1
- package/dist/cjs/middleware/authentication/types.js +0 -6
- package/dist/cjs/middleware/authentication/types.js.map +0 -1
- package/dist/cjs/middleware/authorization/authorization.d.ts +0 -30
- package/dist/cjs/middleware/authorization/authorization.d.ts.map +0 -1
- package/dist/cjs/middleware/authorization/authorization.js +0 -82
- package/dist/cjs/middleware/authorization/authorization.js.map +0 -1
- package/dist/cjs/middleware/authorization/index.d.ts +0 -36
- package/dist/cjs/middleware/authorization/index.d.ts.map +0 -1
- package/dist/cjs/middleware/authorization/index.js +0 -41
- package/dist/cjs/middleware/authorization/index.js.map +0 -1
- package/dist/cjs/middleware/authorization/types.d.ts +0 -67
- package/dist/cjs/middleware/authorization/types.d.ts.map +0 -1
- package/dist/cjs/middleware/authorization/types.js +0 -6
- package/dist/cjs/middleware/authorization/types.js.map +0 -1
- package/dist/cjs/middleware/cache/cache.d.ts +0 -41
- package/dist/cjs/middleware/cache/cache.d.ts.map +0 -1
- package/dist/cjs/middleware/cache/cache.js +0 -191
- package/dist/cjs/middleware/cache/cache.js.map +0 -1
- package/dist/cjs/middleware/cache/index.d.ts +0 -44
- package/dist/cjs/middleware/cache/index.d.ts.map +0 -1
- package/dist/cjs/middleware/cache/index.js +0 -50
- package/dist/cjs/middleware/cache/index.js.map +0 -1
- package/dist/cjs/middleware/cache/types.d.ts +0 -89
- package/dist/cjs/middleware/cache/types.d.ts.map +0 -1
- package/dist/cjs/middleware/cache/types.js +0 -6
- package/dist/cjs/middleware/cache/types.js.map +0 -1
- package/dist/cjs/middleware/csrf/csrf.d.ts +0 -34
- package/dist/cjs/middleware/csrf/csrf.d.ts.map +0 -1
- package/dist/cjs/middleware/csrf/csrf.js +0 -94
- package/dist/cjs/middleware/csrf/csrf.js.map +0 -1
- package/dist/cjs/middleware/csrf/index.d.ts +0 -57
- package/dist/cjs/middleware/csrf/index.d.ts.map +0 -1
- package/dist/cjs/middleware/csrf/index.js +0 -62
- package/dist/cjs/middleware/csrf/index.js.map +0 -1
- package/dist/cjs/middleware/csrf/types.d.ts +0 -57
- package/dist/cjs/middleware/csrf/types.d.ts.map +0 -1
- package/dist/cjs/middleware/csrf/types.js +0 -6
- package/dist/cjs/middleware/csrf/types.js.map +0 -1
- package/dist/cjs/middleware/index.d.ts +0 -115
- package/dist/cjs/middleware/index.d.ts.map +0 -1
- package/dist/cjs/middleware/index.js +0 -153
- package/dist/cjs/middleware/index.js.map +0 -1
- package/dist/cjs/middleware/logging/index.d.ts +0 -42
- package/dist/cjs/middleware/logging/index.d.ts.map +0 -1
- package/dist/cjs/middleware/logging/index.js +0 -47
- package/dist/cjs/middleware/logging/index.js.map +0 -1
- package/dist/cjs/middleware/logging/logging.d.ts +0 -29
- package/dist/cjs/middleware/logging/logging.d.ts.map +0 -1
- package/dist/cjs/middleware/logging/logging.js +0 -171
- package/dist/cjs/middleware/logging/logging.js.map +0 -1
- package/dist/cjs/middleware/logging/types.d.ts +0 -90
- package/dist/cjs/middleware/logging/types.d.ts.map +0 -1
- package/dist/cjs/middleware/logging/types.js +0 -6
- package/dist/cjs/middleware/logging/types.js.map +0 -1
- package/dist/cjs/middleware/rate-limit/index.d.ts +0 -16
- package/dist/cjs/middleware/rate-limit/index.d.ts.map +0 -1
- package/dist/cjs/middleware/rate-limit/index.js +0 -21
- package/dist/cjs/middleware/rate-limit/index.js.map +0 -1
- package/dist/cjs/middleware/rate-limit/rate-limit.d.ts +0 -14
- package/dist/cjs/middleware/rate-limit/rate-limit.d.ts.map +0 -1
- package/dist/cjs/middleware/rate-limit/rate-limit.js +0 -87
- package/dist/cjs/middleware/rate-limit/rate-limit.js.map +0 -1
- package/dist/cjs/middleware/rate-limit/types.d.ts +0 -97
- package/dist/cjs/middleware/rate-limit/types.d.ts.map +0 -1
- package/dist/cjs/middleware/rate-limit/types.js +0 -6
- package/dist/cjs/middleware/rate-limit/types.js.map +0 -1
- package/dist/cjs/middleware/retry/index.d.ts +0 -6
- package/dist/cjs/middleware/retry/index.d.ts.map +0 -1
- package/dist/cjs/middleware/retry/index.js +0 -11
- package/dist/cjs/middleware/retry/index.js.map +0 -1
- package/dist/cjs/middleware/retry/retry.d.ts +0 -39
- package/dist/cjs/middleware/retry/retry.d.ts.map +0 -1
- package/dist/cjs/middleware/retry/retry.js +0 -144
- package/dist/cjs/middleware/retry/retry.js.map +0 -1
- package/dist/cjs/middleware/retry/types.d.ts +0 -61
- package/dist/cjs/middleware/retry/types.d.ts.map +0 -1
- package/dist/cjs/middleware/retry/types.js +0 -6
- package/dist/cjs/middleware/retry/types.js.map +0 -1
- package/dist/client/fetch-client.d.ts +0 -189
- package/dist/client/fetch-client.d.ts.map +0 -1
- package/dist/client/fetch-client.js +0 -335
- package/dist/client/fetch-client.js.map +0 -1
- package/dist/client/index.d.ts +0 -11
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -10
- package/dist/client/index.js.map +0 -1
- package/dist/client/types.d.ts +0 -63
- package/dist/client/types.d.ts.map +0 -1
- package/dist/client/types.js +0 -8
- package/dist/client/types.js.map +0 -1
- package/dist/errors/index.d.ts +0 -64
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -73
- package/dist/errors/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/middleware/authentication/authentication.d.ts +0 -31
- package/dist/middleware/authentication/authentication.d.ts.map +0 -1
- package/dist/middleware/authentication/authentication.js +0 -90
- package/dist/middleware/authentication/authentication.js.map +0 -1
- package/dist/middleware/authentication/index.d.ts +0 -37
- package/dist/middleware/authentication/index.d.ts.map +0 -1
- package/dist/middleware/authentication/index.js +0 -37
- package/dist/middleware/authentication/index.js.map +0 -1
- package/dist/middleware/authentication/types.d.ts +0 -73
- package/dist/middleware/authentication/types.d.ts.map +0 -1
- package/dist/middleware/authentication/types.js +0 -5
- package/dist/middleware/authentication/types.js.map +0 -1
- package/dist/middleware/authorization/authorization.d.ts +0 -30
- package/dist/middleware/authorization/authorization.d.ts.map +0 -1
- package/dist/middleware/authorization/authorization.js +0 -79
- package/dist/middleware/authorization/authorization.js.map +0 -1
- package/dist/middleware/authorization/index.d.ts +0 -36
- package/dist/middleware/authorization/index.d.ts.map +0 -1
- package/dist/middleware/authorization/index.js +0 -36
- package/dist/middleware/authorization/index.js.map +0 -1
- package/dist/middleware/authorization/types.d.ts +0 -67
- package/dist/middleware/authorization/types.d.ts.map +0 -1
- package/dist/middleware/authorization/types.js +0 -5
- package/dist/middleware/authorization/types.js.map +0 -1
- package/dist/middleware/cache/cache.d.ts +0 -41
- package/dist/middleware/cache/cache.d.ts.map +0 -1
- package/dist/middleware/cache/cache.js +0 -186
- package/dist/middleware/cache/cache.js.map +0 -1
- package/dist/middleware/cache/index.d.ts +0 -44
- package/dist/middleware/cache/index.d.ts.map +0 -1
- package/dist/middleware/cache/index.js +0 -44
- package/dist/middleware/cache/index.js.map +0 -1
- package/dist/middleware/cache/types.d.ts +0 -89
- package/dist/middleware/cache/types.d.ts.map +0 -1
- package/dist/middleware/cache/types.js +0 -5
- package/dist/middleware/cache/types.js.map +0 -1
- package/dist/middleware/csrf/csrf.d.ts +0 -34
- package/dist/middleware/csrf/csrf.d.ts.map +0 -1
- package/dist/middleware/csrf/csrf.js +0 -91
- package/dist/middleware/csrf/csrf.js.map +0 -1
- package/dist/middleware/csrf/index.d.ts +0 -57
- package/dist/middleware/csrf/index.d.ts.map +0 -1
- package/dist/middleware/csrf/index.js +0 -57
- package/dist/middleware/csrf/index.js.map +0 -1
- package/dist/middleware/csrf/types.d.ts +0 -57
- package/dist/middleware/csrf/types.d.ts.map +0 -1
- package/dist/middleware/csrf/types.js +0 -5
- package/dist/middleware/csrf/types.js.map +0 -1
- package/dist/middleware/index.d.ts +0 -115
- package/dist/middleware/index.d.ts.map +0 -1
- package/dist/middleware/index.js +0 -134
- package/dist/middleware/index.js.map +0 -1
- package/dist/middleware/logging/index.d.ts +0 -42
- package/dist/middleware/logging/index.d.ts.map +0 -1
- package/dist/middleware/logging/index.js +0 -42
- package/dist/middleware/logging/index.js.map +0 -1
- package/dist/middleware/logging/logging.d.ts +0 -29
- package/dist/middleware/logging/logging.d.ts.map +0 -1
- package/dist/middleware/logging/logging.js +0 -168
- package/dist/middleware/logging/logging.js.map +0 -1
- package/dist/middleware/logging/types.d.ts +0 -90
- package/dist/middleware/logging/types.d.ts.map +0 -1
- package/dist/middleware/logging/types.js +0 -5
- package/dist/middleware/logging/types.js.map +0 -1
- package/dist/middleware/rate-limit/index.d.ts +0 -16
- package/dist/middleware/rate-limit/index.d.ts.map +0 -1
- package/dist/middleware/rate-limit/index.js +0 -16
- package/dist/middleware/rate-limit/index.js.map +0 -1
- package/dist/middleware/rate-limit/rate-limit.d.ts +0 -14
- package/dist/middleware/rate-limit/rate-limit.d.ts.map +0 -1
- package/dist/middleware/rate-limit/rate-limit.js +0 -84
- package/dist/middleware/rate-limit/rate-limit.js.map +0 -1
- package/dist/middleware/rate-limit/types.d.ts +0 -97
- package/dist/middleware/rate-limit/types.d.ts.map +0 -1
- package/dist/middleware/rate-limit/types.js +0 -5
- package/dist/middleware/rate-limit/types.js.map +0 -1
- package/dist/middleware/retry/index.d.ts +0 -6
- package/dist/middleware/retry/index.d.ts.map +0 -1
- package/dist/middleware/retry/index.js +0 -6
- package/dist/middleware/retry/index.js.map +0 -1
- package/dist/middleware/retry/retry.d.ts +0 -39
- package/dist/middleware/retry/retry.d.ts.map +0 -1
- package/dist/middleware/retry/retry.js +0 -141
- package/dist/middleware/retry/retry.js.map +0 -1
- package/dist/middleware/retry/types.d.ts +0 -61
- package/dist/middleware/retry/types.d.ts.map +0 -1
- package/dist/middleware/retry/types.js +0 -5
- package/dist/middleware/retry/types.js.map +0 -1
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Custom error classes - "Pit of Success" pattern.
|
|
3
|
-
*
|
|
4
|
-
* 🎯 LEVEL 1: HttpError, NetworkError - Most common error types you'll catch
|
|
5
|
-
* 🎯 LEVEL 2: FetchError - Base error class for advanced error handling
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* try {
|
|
10
|
-
* await client.get('/api/data');
|
|
11
|
-
* } catch (error) {
|
|
12
|
-
* if (error instanceof HttpError) {
|
|
13
|
-
* console.log(`HTTP ${error.status}: ${error.statusText}`);
|
|
14
|
-
* } else if (error instanceof NetworkError) {
|
|
15
|
-
* console.log('Network connection failed');
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Base error class for all fetch client errors.
|
|
22
|
-
*/
|
|
23
|
-
export declare class FetchError extends Error {
|
|
24
|
-
/** Optional underlying cause */
|
|
25
|
-
readonly cause?: Error;
|
|
26
|
-
/**
|
|
27
|
-
* Creates a new FetchError.
|
|
28
|
-
* @param message - Error message
|
|
29
|
-
* @param cause - Optional underlying cause
|
|
30
|
-
*/
|
|
31
|
-
constructor(message: string, cause?: Error);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Error thrown when an HTTP request fails with a non-2xx status code.
|
|
35
|
-
*/
|
|
36
|
-
export declare class HttpError extends FetchError {
|
|
37
|
-
/** The HTTP status code */
|
|
38
|
-
readonly status: number;
|
|
39
|
-
/** The HTTP status text */
|
|
40
|
-
readonly statusText: string;
|
|
41
|
-
/** The response body (if available) */
|
|
42
|
-
readonly body: unknown;
|
|
43
|
-
/**
|
|
44
|
-
* Creates a new HttpError.
|
|
45
|
-
* @param status - HTTP status code
|
|
46
|
-
* @param statusText - HTTP status text
|
|
47
|
-
* @param body - Response body
|
|
48
|
-
* @param url - The request URL
|
|
49
|
-
*/
|
|
50
|
-
constructor(status: number, statusText: string, body: unknown, url: string);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Error thrown when a network request fails completely.
|
|
54
|
-
*/
|
|
55
|
-
export declare class NetworkError extends FetchError {
|
|
56
|
-
/**
|
|
57
|
-
* Creates a new NetworkError.
|
|
58
|
-
* @param message - Error message
|
|
59
|
-
* @param url - The request URL
|
|
60
|
-
* @param cause - The underlying network error
|
|
61
|
-
*/
|
|
62
|
-
constructor(message: string, url: string, cause?: Error);
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,gCAAgC;IAChC,SAAgB,KAAK,CAAC,EAAE,KAAK,CAAC;IAE9B;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAO3C;AAID;;GAEG;AACH,qBAAa,SAAU,SAAQ,UAAU;IACvC,2BAA2B;IAC3B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,2BAA2B;IAC3B,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,uCAAuC;IACvC,SAAgB,IAAI,EAAE,OAAO,CAAC;IAE9B;;;;;;OAMG;gBACS,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM;CAO3E;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C;;;;;OAKG;gBACS,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAIxD"}
|
package/dist/cjs/errors/index.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Custom error classes - "Pit of Success" pattern.
|
|
4
|
-
*
|
|
5
|
-
* 🎯 LEVEL 1: HttpError, NetworkError - Most common error types you'll catch
|
|
6
|
-
* 🎯 LEVEL 2: FetchError - Base error class for advanced error handling
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* try {
|
|
11
|
-
* await client.get('/api/data');
|
|
12
|
-
* } catch (error) {
|
|
13
|
-
* if (error instanceof HttpError) {
|
|
14
|
-
* console.log(`HTTP ${error.status}: ${error.statusText}`);
|
|
15
|
-
* } else if (error instanceof NetworkError) {
|
|
16
|
-
* console.log('Network connection failed');
|
|
17
|
-
* }
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.NetworkError = exports.HttpError = exports.FetchError = void 0;
|
|
23
|
-
// 🎯 LEVEL 2: Base error class (for advanced use cases)
|
|
24
|
-
/**
|
|
25
|
-
* Base error class for all fetch client errors.
|
|
26
|
-
*/
|
|
27
|
-
class FetchError extends Error {
|
|
28
|
-
/**
|
|
29
|
-
* Creates a new FetchError.
|
|
30
|
-
* @param message - Error message
|
|
31
|
-
* @param cause - Optional underlying cause
|
|
32
|
-
*/
|
|
33
|
-
constructor(message, cause) {
|
|
34
|
-
super(message);
|
|
35
|
-
this.name = 'FetchError';
|
|
36
|
-
if (cause !== undefined) {
|
|
37
|
-
this.cause = cause;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.FetchError = FetchError;
|
|
42
|
-
// 🎯 LEVEL 1: Most commonly used error types
|
|
43
|
-
/**
|
|
44
|
-
* Error thrown when an HTTP request fails with a non-2xx status code.
|
|
45
|
-
*/
|
|
46
|
-
class HttpError extends FetchError {
|
|
47
|
-
/**
|
|
48
|
-
* Creates a new HttpError.
|
|
49
|
-
* @param status - HTTP status code
|
|
50
|
-
* @param statusText - HTTP status text
|
|
51
|
-
* @param body - Response body
|
|
52
|
-
* @param url - The request URL
|
|
53
|
-
*/
|
|
54
|
-
constructor(status, statusText, body, url) {
|
|
55
|
-
super(`HTTP ${status} ${statusText} at ${url}`);
|
|
56
|
-
this.name = 'HttpError';
|
|
57
|
-
this.status = status;
|
|
58
|
-
this.statusText = statusText;
|
|
59
|
-
this.body = body;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.HttpError = HttpError;
|
|
63
|
-
/**
|
|
64
|
-
* Error thrown when a network request fails completely.
|
|
65
|
-
*/
|
|
66
|
-
class NetworkError extends FetchError {
|
|
67
|
-
/**
|
|
68
|
-
* Creates a new NetworkError.
|
|
69
|
-
* @param message - Error message
|
|
70
|
-
* @param url - The request URL
|
|
71
|
-
* @param cause - The underlying network error
|
|
72
|
-
*/
|
|
73
|
-
constructor(message, url, cause) {
|
|
74
|
-
super(`Network error for ${url}: ${message}`, cause);
|
|
75
|
-
this.name = 'NetworkError';
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.NetworkError = NetworkError;
|
|
79
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;AAEH,wDAAwD;AAExD;;GAEG;AACH,MAAa,UAAW,SAAQ,KAAK;IAInC;;;;OAIG;IACH,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;IACH,CAAC;CACF;AAhBD,gCAgBC;AAED,6CAA6C;AAE7C;;GAEG;AACH,MAAa,SAAU,SAAQ,UAAU;IAQvC;;;;;;OAMG;IACH,YAAY,MAAc,EAAE,UAAkB,EAAE,IAAa,EAAE,GAAW;QACxE,KAAK,CAAC,QAAQ,MAAM,IAAI,UAAU,OAAO,GAAG,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAtBD,8BAsBC;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,UAAU;IAC1C;;;;;OAKG;IACH,YAAY,OAAe,EAAE,GAAW,EAAE,KAAa;QACrD,KAAK,CAAC,qBAAqB,GAAG,KAAK,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAXD,oCAWC"}
|
package/dist/cjs/index.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Main library entry point with "pit of success" architecture.
|
|
3
|
-
*
|
|
4
|
-
* This module exports everything users need in order of discoverability:
|
|
5
|
-
* 1. Pre-configured client with smart defaults (80% of users start here)
|
|
6
|
-
* 2. FetchClient for custom configurations
|
|
7
|
-
* 3. Individual middleware functions for specific needs
|
|
8
|
-
* 4. Pre-built middleware stacks for common scenarios
|
|
9
|
-
* 5. Types for TypeScript users
|
|
10
|
-
*/
|
|
11
|
-
import { FetchClient } from './client/fetch-client';
|
|
12
|
-
/**
|
|
13
|
-
* 🎯 PIT OF SUCCESS: Pre-configured fetch client (Level 1 - 80% of users)
|
|
14
|
-
*
|
|
15
|
-
* This client is ready to use out of the box with production-ready middleware:
|
|
16
|
-
* - Authentication support (configure your token provider)
|
|
17
|
-
* - Automatic retries with exponential backoff
|
|
18
|
-
* - Response caching for GET requests
|
|
19
|
-
* - Request/response logging
|
|
20
|
-
* - Rate limiting protection
|
|
21
|
-
* - Same-origin credentials for session-based auth (cookies)
|
|
22
|
-
*
|
|
23
|
-
* @example Just import and use:
|
|
24
|
-
* ```typescript
|
|
25
|
-
* import api from '@fgrzl/fetch';
|
|
26
|
-
*
|
|
27
|
-
* // Works immediately - no setup required!
|
|
28
|
-
* const users = await api.get('/api/users');
|
|
29
|
-
* const newUser = await api.post('/api/users', { name: 'John' });
|
|
30
|
-
*
|
|
31
|
-
* // With query parameters
|
|
32
|
-
* const activeUsers = await api.get('/api/users', { status: 'active', limit: 10 });
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @example Configure authentication:
|
|
36
|
-
* ```typescript
|
|
37
|
-
* import api from '@fgrzl/fetch';
|
|
38
|
-
* import { useAuthentication } from '@fgrzl/fetch/middleware';
|
|
39
|
-
*
|
|
40
|
-
* const authClient = useAuthentication(api, {
|
|
41
|
-
* tokenProvider: () => localStorage.getItem('auth-token') || ''
|
|
42
|
-
* });
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* @example For token-only auth (no cookies):
|
|
46
|
-
* ```typescript
|
|
47
|
-
* import { FetchClient, useAuthentication } from '@fgrzl/fetch';
|
|
48
|
-
*
|
|
49
|
-
* const tokenClient = useAuthentication(new FetchClient({
|
|
50
|
-
* credentials: 'omit' // Don't send cookies
|
|
51
|
-
* }), {
|
|
52
|
-
* tokenProvider: () => getJWTToken()
|
|
53
|
-
* });
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
declare const api: FetchClient;
|
|
57
|
-
export default api;
|
|
58
|
-
export { FetchClient } from './client/fetch-client';
|
|
59
|
-
export { FetchError, HttpError, NetworkError } from './errors';
|
|
60
|
-
export { useAuthentication, createAuthenticationMiddleware, useAuthorization, createAuthorizationMiddleware, useCache, createCacheMiddleware, useCSRF, useLogging, createLoggingMiddleware, useRateLimit, createRateLimitMiddleware, useRetry, createRetryMiddleware, } from './middleware';
|
|
61
|
-
export { useProductionStack, useDevelopmentStack, useBasicStack, } from './middleware';
|
|
62
|
-
export type { FetchMiddleware as InterceptMiddleware } from './client/fetch-client';
|
|
63
|
-
export type { FetchResponse, FetchClientOptions } from './client/types';
|
|
64
|
-
export type { AuthenticationOptions, AuthTokenProvider, AuthorizationOptions, UnauthorizedHandler, CacheOptions, CacheStorage, CacheEntry, CacheKeyGenerator, LoggingOptions, Logger, LogLevel, RateLimitOptions, RateLimitAlgorithm, RetryOptions, } from './middleware';
|
|
65
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,QAAA,MAAM,GAAG,aAwBR,CAAC;AAGF,eAAe,GAAG,CAAC;AAGnB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG/D,OAAO,EAEL,iBAAiB,EACjB,8BAA8B,EAE9B,gBAAgB,EAChB,6BAA6B,EAE7B,QAAQ,EACR,qBAAqB,EAErB,OAAO,EAEP,UAAU,EACV,uBAAuB,EAEvB,YAAY,EACZ,yBAAyB,EAEzB,QAAQ,EACR,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,YAAY,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACpF,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGxE,YAAY,EAEV,qBAAqB,EACrB,iBAAiB,EAEjB,oBAAoB,EACpB,mBAAmB,EAEnB,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,iBAAiB,EAEjB,cAAc,EACd,MAAM,EACN,QAAQ,EAER,gBAAgB,EAChB,kBAAkB,EAElB,YAAY,GACb,MAAM,cAAc,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Authentication middleware implementation.
|
|
3
|
-
*/
|
|
4
|
-
import type { FetchMiddleware } from '../../client/fetch-client';
|
|
5
|
-
import type { AuthenticationOptions } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* Creates authentication middleware with smart defaults.
|
|
8
|
-
* Automatically adds Bearer tokens to requests.
|
|
9
|
-
*
|
|
10
|
-
* @param options - Authentication configuration options
|
|
11
|
-
* @returns Authentication middleware for use with FetchClient
|
|
12
|
-
*
|
|
13
|
-
* @example Basic usage:
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const authClient = useAuthentication(client, {
|
|
16
|
-
* tokenProvider: () => localStorage.getItem('token') || ''
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @example Async token provider:
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const authClient = useAuthentication(client, {
|
|
23
|
-
* tokenProvider: async () => {
|
|
24
|
-
* const token = await getAuthToken();
|
|
25
|
-
* return token || '';
|
|
26
|
-
* }
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare function createAuthenticationMiddleware(options: AuthenticationOptions): FetchMiddleware;
|
|
31
|
-
//# sourceMappingURL=authentication.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../../../src/middleware/authentication/authentication.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAoCrD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,qBAAqB,GAC7B,eAAe,CAkDjB"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Authentication middleware implementation.
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createAuthenticationMiddleware = createAuthenticationMiddleware;
|
|
7
|
-
/**
|
|
8
|
-
* Checks if a URL should skip authentication based on configured patterns.
|
|
9
|
-
*/
|
|
10
|
-
function shouldSkipAuth(url, skipPatterns = []) {
|
|
11
|
-
return skipPatterns.some((pattern) => {
|
|
12
|
-
if (typeof pattern === 'string') {
|
|
13
|
-
return url.includes(pattern);
|
|
14
|
-
}
|
|
15
|
-
return pattern.test(url);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Checks if a URL should include authentication based on configured patterns.
|
|
20
|
-
*/
|
|
21
|
-
function shouldIncludeAuth(url, includePatterns) {
|
|
22
|
-
if (!includePatterns || includePatterns.length === 0) {
|
|
23
|
-
return true; // Include by default if no patterns specified
|
|
24
|
-
}
|
|
25
|
-
return includePatterns.some((pattern) => {
|
|
26
|
-
if (typeof pattern === 'string') {
|
|
27
|
-
return url.includes(pattern);
|
|
28
|
-
}
|
|
29
|
-
return pattern.test(url);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Creates authentication middleware with smart defaults.
|
|
34
|
-
* Automatically adds Bearer tokens to requests.
|
|
35
|
-
*
|
|
36
|
-
* @param options - Authentication configuration options
|
|
37
|
-
* @returns Authentication middleware for use with FetchClient
|
|
38
|
-
*
|
|
39
|
-
* @example Basic usage:
|
|
40
|
-
* ```typescript
|
|
41
|
-
* const authClient = useAuthentication(client, {
|
|
42
|
-
* tokenProvider: () => localStorage.getItem('token') || ''
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @example Async token provider:
|
|
47
|
-
* ```typescript
|
|
48
|
-
* const authClient = useAuthentication(client, {
|
|
49
|
-
* tokenProvider: async () => {
|
|
50
|
-
* const token = await getAuthToken();
|
|
51
|
-
* return token || '';
|
|
52
|
-
* }
|
|
53
|
-
* });
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
function createAuthenticationMiddleware(options) {
|
|
57
|
-
const { tokenProvider, headerName = 'Authorization', tokenType = 'Bearer', skipPatterns = [], includePatterns, } = options;
|
|
58
|
-
return async (request, next) => {
|
|
59
|
-
const url = request.url || '';
|
|
60
|
-
const parsedUrl = new URL(url);
|
|
61
|
-
const pathname = parsedUrl.pathname;
|
|
62
|
-
// Skip authentication if:
|
|
63
|
-
// 1. URL matches a skip pattern
|
|
64
|
-
// 2. URL doesn't match include patterns (if specified)
|
|
65
|
-
if (shouldSkipAuth(pathname, skipPatterns) ||
|
|
66
|
-
!shouldIncludeAuth(pathname, includePatterns)) {
|
|
67
|
-
return next(request);
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
// Get auth token (may be async)
|
|
71
|
-
const token = await tokenProvider();
|
|
72
|
-
// Skip if no token available
|
|
73
|
-
if (!token) {
|
|
74
|
-
return next(request);
|
|
75
|
-
}
|
|
76
|
-
// Add auth header to request
|
|
77
|
-
const headers = new Headers(request.headers);
|
|
78
|
-
headers.set(headerName, `${tokenType} ${token}`);
|
|
79
|
-
// Create modified request with auth header
|
|
80
|
-
const modifiedRequest = {
|
|
81
|
-
...request,
|
|
82
|
-
headers,
|
|
83
|
-
};
|
|
84
|
-
return next(modifiedRequest);
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
// If token provider fails, proceed without auth
|
|
88
|
-
// This ensures network requests don't fail due to auth issues
|
|
89
|
-
return next(request);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=authentication.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../../../src/middleware/authentication/authentication.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA+DH,wEAoDC;AA9GD;;GAEG;AACH,SAAS,cAAc,CACrB,GAAW,EACX,eAAoC,EAAE;IAEtC,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACnC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,iBAAiB,CACxB,GAAW,EACX,eAAqC;IAErC,IAAI,CAAC,eAAe,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrD,OAAO,IAAI,CAAC,CAAC,8CAA8C;IAC7D,CAAC;IAED,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACtC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,8BAA8B,CAC5C,OAA8B;IAE9B,MAAM,EACJ,aAAa,EACb,UAAU,GAAG,eAAe,EAC5B,SAAS,GAAG,QAAQ,EACpB,YAAY,GAAG,EAAE,EACjB,eAAe,GAChB,GAAG,OAAO,CAAC;IAEZ,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC7B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QAEpC,0BAA0B;QAC1B,gCAAgC;QAChC,uDAAuD;QACvD,IACE,cAAc,CAAC,QAAQ,EAAE,YAAY,CAAC;YACtC,CAAC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,CAAC,EAC7C,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAED,IAAI,CAAC;YACH,gCAAgC;YAChC,MAAM,KAAK,GAAG,MAAM,aAAa,EAAE,CAAC;YAEpC,6BAA6B;YAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YAED,6BAA6B;YAC7B,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,SAAS,IAAI,KAAK,EAAE,CAAC,CAAC;YAEjD,2CAA2C;YAC3C,MAAM,eAAe,GAAG;gBACtB,GAAG,OAAO;gBACV,OAAO;aACR,CAAC;YAEF,OAAO,IAAI,CAAC,eAAe,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,gDAAgD;YAChD,8DAA8D;YAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Authentication middleware - "pit of success" API.
|
|
3
|
-
*/
|
|
4
|
-
import type { FetchClient } from '../../client/fetch-client';
|
|
5
|
-
import type { AuthenticationOptions } from './types';
|
|
6
|
-
export type { AuthenticationOptions, AuthTokenProvider } from './types';
|
|
7
|
-
export { createAuthenticationMiddleware } from './authentication';
|
|
8
|
-
/**
|
|
9
|
-
* "Pit of success" API for adding authentication to a FetchClient.
|
|
10
|
-
* Automatically adds Bearer tokens to requests.
|
|
11
|
-
*
|
|
12
|
-
* @param client - The FetchClient to add authentication to
|
|
13
|
-
* @param options - Authentication configuration
|
|
14
|
-
* @returns A new FetchClient with authentication middleware
|
|
15
|
-
*
|
|
16
|
-
* @example Basic token from localStorage:
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const authClient = useAuthentication(client, {
|
|
19
|
-
* tokenProvider: () => localStorage.getItem('auth-token') || ''
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @example Async token with refresh:
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const authClient = useAuthentication(client, {
|
|
26
|
-
* tokenProvider: async () => {
|
|
27
|
-
* let token = localStorage.getItem('auth-token');
|
|
28
|
-
* if (!token || isExpired(token)) {
|
|
29
|
-
* token = await refreshToken();
|
|
30
|
-
* }
|
|
31
|
-
* return token || '';
|
|
32
|
-
* }
|
|
33
|
-
* });
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function useAuthentication(client: FetchClient, options: AuthenticationOptions): FetchClient;
|
|
37
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/middleware/authentication/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAIrD,YAAY,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,qBAAqB,GAC7B,WAAW,CAEb"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Authentication middleware - "pit of success" API.
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createAuthenticationMiddleware = void 0;
|
|
7
|
-
exports.useAuthentication = useAuthentication;
|
|
8
|
-
const authentication_1 = require("./authentication");
|
|
9
|
-
var authentication_2 = require("./authentication");
|
|
10
|
-
Object.defineProperty(exports, "createAuthenticationMiddleware", { enumerable: true, get: function () { return authentication_2.createAuthenticationMiddleware; } });
|
|
11
|
-
/**
|
|
12
|
-
* "Pit of success" API for adding authentication to a FetchClient.
|
|
13
|
-
* Automatically adds Bearer tokens to requests.
|
|
14
|
-
*
|
|
15
|
-
* @param client - The FetchClient to add authentication to
|
|
16
|
-
* @param options - Authentication configuration
|
|
17
|
-
* @returns A new FetchClient with authentication middleware
|
|
18
|
-
*
|
|
19
|
-
* @example Basic token from localStorage:
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const authClient = useAuthentication(client, {
|
|
22
|
-
* tokenProvider: () => localStorage.getItem('auth-token') || ''
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @example Async token with refresh:
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const authClient = useAuthentication(client, {
|
|
29
|
-
* tokenProvider: async () => {
|
|
30
|
-
* let token = localStorage.getItem('auth-token');
|
|
31
|
-
* if (!token || isExpired(token)) {
|
|
32
|
-
* token = await refreshToken();
|
|
33
|
-
* }
|
|
34
|
-
* return token || '';
|
|
35
|
-
* }
|
|
36
|
-
* });
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
function useAuthentication(client, options) {
|
|
40
|
-
return client.use((0, authentication_1.createAuthenticationMiddleware)(options));
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/middleware/authentication/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAsCH,8CAKC;AAvCD,qDAAkE;AAIlE,mDAAkE;AAAzD,gIAAA,8BAA8B,OAAA;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,iBAAiB,CAC/B,MAAmB,EACnB,OAA8B;IAE9B,OAAO,MAAM,CAAC,GAAG,CAAC,IAAA,+CAA8B,EAAC,OAAO,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Authentication middleware types and configuration.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Authentication token provider function.
|
|
6
|
-
* Should return the current auth token or empty string if not available.
|
|
7
|
-
*/
|
|
8
|
-
export type AuthTokenProvider = () => string | Promise<string>;
|
|
9
|
-
/**
|
|
10
|
-
* Authentication configuration options - optimized for "pit of success".
|
|
11
|
-
*
|
|
12
|
-
* Smart defaults:
|
|
13
|
-
* - Uses standard Authorization header with Bearer token
|
|
14
|
-
* - Applies to all requests by default
|
|
15
|
-
* - Graceful handling when token is unavailable
|
|
16
|
-
*/
|
|
17
|
-
export interface AuthenticationOptions {
|
|
18
|
-
/**
|
|
19
|
-
* Function to get the current authentication token.
|
|
20
|
-
* Can be synchronous or asynchronous.
|
|
21
|
-
*
|
|
22
|
-
* @returns The auth token or empty string if not available
|
|
23
|
-
*
|
|
24
|
-
* @example Token from localStorage:
|
|
25
|
-
* ```typescript
|
|
26
|
-
* const getToken = () => localStorage.getItem('auth-token') || '';
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @example Async token refresh:
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const getToken = async () => {
|
|
32
|
-
* const token = localStorage.getItem('auth-token');
|
|
33
|
-
* if (!token || isExpired(token)) {
|
|
34
|
-
* return await refreshToken();
|
|
35
|
-
* }
|
|
36
|
-
* return token;
|
|
37
|
-
* };
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
tokenProvider: AuthTokenProvider;
|
|
41
|
-
/**
|
|
42
|
-
* Header name for the authentication token (default: 'Authorization')
|
|
43
|
-
* The token will be prefixed with the tokenType
|
|
44
|
-
*/
|
|
45
|
-
headerName?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Token type prefix (default: 'Bearer')
|
|
48
|
-
* Common alternatives: 'Token', 'JWT', 'ApiKey'
|
|
49
|
-
*/
|
|
50
|
-
tokenType?: string;
|
|
51
|
-
/**
|
|
52
|
-
* Skip authentication for requests matching these URL patterns
|
|
53
|
-
* Useful for public endpoints that don't need auth
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* skipPatterns: [/^\/public\//, '/health', '/login']
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
skipPatterns?: (RegExp | string)[];
|
|
61
|
-
/**
|
|
62
|
-
* Only apply authentication to requests matching these patterns
|
|
63
|
-
* If specified, only these patterns will get auth headers
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* includePatterns: [/^\/api\//, '/graphql']
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
includePatterns?: (RegExp | string)[];
|
|
71
|
-
}
|
|
72
|
-
export {};
|
|
73
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/middleware/authentication/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAEnC;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CACvC;AAGD,OAAO,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/middleware/authentication/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Authorization middleware implementation.
|
|
3
|
-
*/
|
|
4
|
-
import type { FetchMiddleware } from '../../client/fetch-client';
|
|
5
|
-
import type { AuthorizationOptions } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* Creates authorization middleware with smart defaults.
|
|
8
|
-
* Handles 401/403 responses by calling configured handlers.
|
|
9
|
-
*
|
|
10
|
-
* @param options - Authorization configuration options
|
|
11
|
-
* @returns Authorization middleware for use with FetchClient
|
|
12
|
-
*
|
|
13
|
-
* @example Basic redirect on 401:
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const authzClient = useAuthorization(client, {
|
|
16
|
-
* onUnauthorized: () => window.location.href = '/login'
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @example Handle both 401 and 403:
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const authzClient = useAuthorization(client, {
|
|
23
|
-
* onUnauthorized: () => redirectToLogin(),
|
|
24
|
-
* onForbidden: () => showAccessDeniedMessage(),
|
|
25
|
-
* statusCodes: [401, 403]
|
|
26
|
-
* });
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare function createAuthorizationMiddleware(options: AuthorizationOptions): FetchMiddleware;
|
|
30
|
-
//# sourceMappingURL=authorization.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../../../src/middleware/authorization/authorization.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAyBpD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,oBAAoB,GAC5B,eAAe,CAuCjB"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Authorization middleware implementation.
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createAuthorizationMiddleware = createAuthorizationMiddleware;
|
|
7
|
-
/**
|
|
8
|
-
* Checks if a URL should skip authorization handling based on configured patterns.
|
|
9
|
-
*/
|
|
10
|
-
function shouldSkipAuth(url, skipPatterns = []) {
|
|
11
|
-
// Extract pathname from URL for pattern matching
|
|
12
|
-
let pathname;
|
|
13
|
-
try {
|
|
14
|
-
pathname = new URL(url).pathname;
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
pathname = url; // fallback if not a valid URL
|
|
18
|
-
}
|
|
19
|
-
return skipPatterns.some((pattern) => {
|
|
20
|
-
if (typeof pattern === 'string') {
|
|
21
|
-
return pathname.includes(pattern);
|
|
22
|
-
}
|
|
23
|
-
return pattern.test(pathname);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Creates authorization middleware with smart defaults.
|
|
28
|
-
* Handles 401/403 responses by calling configured handlers.
|
|
29
|
-
*
|
|
30
|
-
* @param options - Authorization configuration options
|
|
31
|
-
* @returns Authorization middleware for use with FetchClient
|
|
32
|
-
*
|
|
33
|
-
* @example Basic redirect on 401:
|
|
34
|
-
* ```typescript
|
|
35
|
-
* const authzClient = useAuthorization(client, {
|
|
36
|
-
* onUnauthorized: () => window.location.href = '/login'
|
|
37
|
-
* });
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @example Handle both 401 and 403:
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const authzClient = useAuthorization(client, {
|
|
43
|
-
* onUnauthorized: () => redirectToLogin(),
|
|
44
|
-
* onForbidden: () => showAccessDeniedMessage(),
|
|
45
|
-
* statusCodes: [401, 403]
|
|
46
|
-
* });
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
function createAuthorizationMiddleware(options) {
|
|
50
|
-
const { onUnauthorized, onForbidden, skipPatterns = [], statusCodes = [401], } = options;
|
|
51
|
-
return async (request, next) => {
|
|
52
|
-
const url = request.url || '';
|
|
53
|
-
// Skip authorization handling if URL matches skip patterns
|
|
54
|
-
if (shouldSkipAuth(url, skipPatterns)) {
|
|
55
|
-
return next(request);
|
|
56
|
-
}
|
|
57
|
-
// Execute the request
|
|
58
|
-
const response = await next(request);
|
|
59
|
-
// Check if response status requires handling
|
|
60
|
-
if (statusCodes.includes(response.status)) {
|
|
61
|
-
try {
|
|
62
|
-
if (response.status === 401 && onUnauthorized) {
|
|
63
|
-
await onUnauthorized(response, request);
|
|
64
|
-
}
|
|
65
|
-
else if (response.status === 403 && onForbidden) {
|
|
66
|
-
await onForbidden(response, request);
|
|
67
|
-
}
|
|
68
|
-
else if (onUnauthorized) {
|
|
69
|
-
// For any other configured status codes, use the first available handler
|
|
70
|
-
await onUnauthorized(response, request);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
// If handler fails, log but don't break the response chain
|
|
75
|
-
// eslint-disable-next-line no-console
|
|
76
|
-
console.warn('Authorization handler failed:', error);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return response;
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
//# sourceMappingURL=authorization.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../../src/middleware/authorization/authorization.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAmDH,sEAyCC;AAvFD;;GAEG;AACH,SAAS,cAAc,CACrB,GAAW,EACX,eAAoC,EAAE;IAEtC,iDAAiD;IACjD,IAAI,QAAgB,CAAC;IACrB,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,QAAQ,GAAG,GAAG,CAAC,CAAC,8BAA8B;IAChD,CAAC;IAED,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACnC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,6BAA6B,CAC3C,OAA6B;IAE7B,MAAM,EACJ,cAAc,EACd,WAAW,EACX,YAAY,GAAG,EAAE,EACjB,WAAW,GAAG,CAAC,GAAG,CAAC,GACpB,GAAG,OAAO,CAAC;IAEZ,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC7B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC;QAE9B,2DAA2D;QAC3D,IAAI,cAAc,CAAC,GAAG,EAAE,YAAY,CAAC,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAED,sBAAsB;QACtB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;QAErC,6CAA6C;QAC7C,IAAI,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC;gBACH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,cAAc,EAAE,CAAC;oBAC9C,MAAM,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAC1C,CAAC;qBAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC;oBAClD,MAAM,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;gBACvC,CAAC;qBAAM,IAAI,cAAc,EAAE,CAAC;oBAC1B,yEAAyE;oBACzE,MAAM,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAC1C,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,2DAA2D;gBAC3D,sCAAsC;gBACtC,OAAO,CAAC,IAAI,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC"}
|