@nzyme/fetch-utils 0.14.0 → 0.15.1
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/dist/FetchError.d.ts +17 -3
- package/dist/FetchError.js +18 -5
- package/dist/FetchError.js.map +1 -1
- package/dist/HttpError.d.ts +37 -0
- package/dist/HttpError.js +36 -0
- package/dist/HttpError.js.map +1 -0
- package/dist/{types/HttpHeaders.d.ts → HttpHeaders.d.ts} +1 -1
- package/dist/{types/HttpHeaders.js.map → HttpHeaders.js.map} +1 -1
- package/dist/HttpMethod.d.ts +4 -0
- package/dist/{types/HttpMethod.js.map → HttpMethod.js.map} +1 -1
- package/dist/assertResponse.d.ts +5 -1
- package/dist/assertResponse.js +5 -1
- package/dist/assertResponse.js.map +1 -1
- package/dist/defineEndpoint.d.ts +10 -7
- package/dist/defineEndpoint.js +6 -3
- package/dist/defineEndpoint.js.map +1 -1
- package/dist/defineFetch.d.ts +9 -6
- package/dist/defineFetch.js +6 -3
- package/dist/defineFetch.js.map +1 -1
- package/dist/defineFetchClient.d.ts +21 -0
- package/dist/defineFetchClient.js +8 -1
- package/dist/defineFetchClient.js.map +1 -1
- package/dist/fetchEndpoint.d.ts +11 -5
- package/dist/fetchEndpoint.js +6 -1
- package/dist/fetchEndpoint.js.map +1 -1
- package/dist/fetchJson.d.ts +30 -6
- package/dist/fetchJson.js +8 -0
- package/dist/fetchJson.js.map +1 -1
- package/dist/fetchRequest.d.ts +23 -1
- package/dist/fetchRequest.js +7 -0
- package/dist/fetchRequest.js.map +1 -1
- package/dist/formUrlEncodedRequest.d.ts +13 -1
- package/dist/formUrlEncodedRequest.js +7 -0
- package/dist/formUrlEncodedRequest.js.map +1 -1
- package/dist/getResponseFileName.d.ts +16 -0
- package/dist/getResponseFileName.js +24 -0
- package/dist/getResponseFileName.js.map +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/jsonNullableResponse.d.ts +6 -2
- package/dist/jsonNullableResponse.js +6 -2
- package/dist/jsonNullableResponse.js.map +1 -1
- package/dist/jsonRequest.d.ts +13 -1
- package/dist/jsonRequest.js +7 -0
- package/dist/jsonRequest.js.map +1 -1
- package/dist/jsonResponse.d.ts +5 -1
- package/dist/jsonResponse.js +5 -1
- package/dist/jsonResponse.js.map +1 -1
- package/dist/xmlRequest.d.ts +13 -1
- package/dist/xmlRequest.js +8 -1
- package/dist/xmlRequest.js.map +1 -1
- package/dist/xmlResponse.d.ts +8 -2
- package/dist/xmlResponse.js +7 -2
- package/dist/xmlResponse.js.map +1 -1
- package/package.json +31 -39
- package/dist/FetchError.cjs +0 -16
- package/dist/FetchError.cjs.map +0 -1
- package/dist/assertResponse.cjs +0 -14
- package/dist/assertResponse.cjs.map +0 -1
- package/dist/defineEndpoint.cjs +0 -12
- package/dist/defineEndpoint.cjs.map +0 -1
- package/dist/defineFetch.cjs +0 -12
- package/dist/defineFetch.cjs.map +0 -1
- package/dist/defineFetchClient.cjs +0 -8
- package/dist/defineFetchClient.cjs.map +0 -1
- package/dist/fetchEndpoint.cjs +0 -30
- package/dist/fetchEndpoint.cjs.map +0 -1
- package/dist/fetchJson.cjs +0 -29
- package/dist/fetchJson.cjs.map +0 -1
- package/dist/fetchRequest.cjs +0 -13
- package/dist/fetchRequest.cjs.map +0 -1
- package/dist/formUrlEncodedRequest.cjs +0 -19
- package/dist/formUrlEncodedRequest.cjs.map +0 -1
- package/dist/index.cjs +0 -20
- package/dist/index.cjs.map +0 -1
- package/dist/jsonNullableResponse.cjs +0 -18
- package/dist/jsonNullableResponse.cjs.map +0 -1
- package/dist/jsonRequest.cjs +0 -17
- package/dist/jsonRequest.cjs.map +0 -1
- package/dist/jsonResponse.cjs +0 -12
- package/dist/jsonResponse.cjs.map +0 -1
- package/dist/types/HttpHeaders.cjs +0 -3
- package/dist/types/HttpHeaders.cjs.map +0 -1
- package/dist/types/HttpMethod.cjs +0 -3
- package/dist/types/HttpMethod.cjs.map +0 -1
- package/dist/types/HttpMethod.d.ts +0 -1
- package/dist/types/HttpResponse.cjs +0 -3
- package/dist/types/HttpResponse.cjs.map +0 -1
- package/dist/types/HttpResponse.d.ts +0 -7
- package/dist/types/HttpResponse.js +0 -2
- package/dist/types/HttpResponse.js.map +0 -1
- package/dist/xmlRequest.cjs +0 -18
- package/dist/xmlRequest.cjs.map +0 -1
- package/dist/xmlResponse.cjs +0 -14
- package/dist/xmlResponse.cjs.map +0 -1
- /package/dist/{types/HttpHeaders.js → HttpHeaders.js} +0 -0
- /package/dist/{types/HttpMethod.js → HttpMethod.js} +0 -0
package/dist/FetchError.d.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { HttpError } from './HttpError.js';
|
|
2
|
+
/**
|
|
3
|
+
* Custom error class for handling failed HTTP requests.
|
|
4
|
+
* Provides access to the original Response object and commonly needed properties.
|
|
5
|
+
*/
|
|
6
|
+
export declare class FetchError extends HttpError {
|
|
7
|
+
/** The original Response object */
|
|
2
8
|
readonly response: Response;
|
|
3
|
-
|
|
9
|
+
/** The URL that was requested */
|
|
4
10
|
readonly url: string;
|
|
5
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new FetchError instance
|
|
13
|
+
*
|
|
14
|
+
* @param response - The Response object from the failed request
|
|
15
|
+
* @param message - Optional error message (defaults to response.statusText)
|
|
16
|
+
*/
|
|
17
|
+
constructor(
|
|
18
|
+
/** The original Response object */
|
|
19
|
+
response: Response, message?: string);
|
|
6
20
|
}
|
package/dist/FetchError.js
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
import { HttpError } from './HttpError.js';
|
|
2
|
+
/**
|
|
3
|
+
* Custom error class for handling failed HTTP requests.
|
|
4
|
+
* Provides access to the original Response object and commonly needed properties.
|
|
5
|
+
*/
|
|
6
|
+
export class FetchError extends HttpError {
|
|
2
7
|
response;
|
|
3
|
-
|
|
8
|
+
/** The URL that was requested */
|
|
4
9
|
url;
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new FetchError instance
|
|
12
|
+
*
|
|
13
|
+
* @param response - The Response object from the failed request
|
|
14
|
+
* @param message - Optional error message (defaults to response.statusText)
|
|
15
|
+
*/
|
|
16
|
+
constructor(
|
|
17
|
+
/** The original Response object */
|
|
18
|
+
response, message) {
|
|
19
|
+
super(response.status, message || response.statusText);
|
|
7
20
|
this.response = response;
|
|
8
21
|
this.url = response.url;
|
|
9
|
-
this.
|
|
22
|
+
this.name = 'FetchError';
|
|
10
23
|
}
|
|
11
24
|
}
|
|
12
25
|
//# sourceMappingURL=FetchError.js.map
|
package/dist/FetchError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchError.js","sourceRoot":"","sources":["../src/FetchError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,
|
|
1
|
+
{"version":3,"file":"FetchError.js","sourceRoot":"","sources":["../src/FetchError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,SAAS;IAYjB,QAAQ;IAX5B,iCAAiC;IACjB,GAAG,CAAS;IAE5B;;;;;OAKG;IACH;IACI,mCAAmC;IACnB,QAAkB,EAClC,OAAgB;QAEhB,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;wBAHvC,QAAQ;QAIxB,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC7B,CAAC;CACJ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The payload for an HTTP error.
|
|
3
|
+
*/
|
|
4
|
+
export interface HttpErrorPayload {
|
|
5
|
+
/**
|
|
6
|
+
* The error message.
|
|
7
|
+
*/
|
|
8
|
+
message: string;
|
|
9
|
+
/**
|
|
10
|
+
* Additional error properties.
|
|
11
|
+
*/
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A custom error class for HTTP errors.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const error = new HttpError(404, 'Not Found');
|
|
19
|
+
* console.log(error.status); // 404
|
|
20
|
+
* console.log(error.message); // 'Not Found'
|
|
21
|
+
*/
|
|
22
|
+
export declare class HttpError extends Error {
|
|
23
|
+
/**
|
|
24
|
+
* The HTTP error payload.
|
|
25
|
+
*/
|
|
26
|
+
readonly payload: HttpErrorPayload;
|
|
27
|
+
/**
|
|
28
|
+
* The HTTP status code.
|
|
29
|
+
*/
|
|
30
|
+
readonly status: number;
|
|
31
|
+
/**
|
|
32
|
+
* @param status - The HTTP status code.
|
|
33
|
+
* @param message - The error message.
|
|
34
|
+
* @param options - The error options.
|
|
35
|
+
*/
|
|
36
|
+
constructor(status: number, message: string | HttpErrorPayload, options?: ErrorOptions);
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A custom error class for HTTP errors.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const error = new HttpError(404, 'Not Found');
|
|
6
|
+
* console.log(error.status); // 404
|
|
7
|
+
* console.log(error.message); // 'Not Found'
|
|
8
|
+
*/
|
|
9
|
+
export class HttpError extends Error {
|
|
10
|
+
/**
|
|
11
|
+
* The HTTP error payload.
|
|
12
|
+
*/
|
|
13
|
+
payload;
|
|
14
|
+
/**
|
|
15
|
+
* The HTTP status code.
|
|
16
|
+
*/
|
|
17
|
+
status;
|
|
18
|
+
/**
|
|
19
|
+
* @param status - The HTTP status code.
|
|
20
|
+
* @param message - The error message.
|
|
21
|
+
* @param options - The error options.
|
|
22
|
+
*/
|
|
23
|
+
constructor(status, message, options) {
|
|
24
|
+
if (typeof message === 'object') {
|
|
25
|
+
super(message.message, options);
|
|
26
|
+
this.payload = message;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
super(message, options);
|
|
30
|
+
this.payload = { message };
|
|
31
|
+
}
|
|
32
|
+
this.status = status;
|
|
33
|
+
this.name = 'HttpError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=HttpError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../src/HttpError.ts"],"names":[],"mappings":"AAeA;;;;;;;GAOG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAChC;;OAEG;IACa,OAAO,CAAmB;IAE1C;;OAEG;IACa,MAAM,CAAS;IAE/B;;;;OAIG;IACH,YAAY,MAAc,EAAE,OAAkC,EAAE,OAAsB;QAClF,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC9B,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,CAAC;aAAM,CAAC;YACJ,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,EAAE,OAAO,EAAE,CAAC;QAC/B,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC5B,CAAC;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { IncomingHttpHeaders as HttpRequestHeaders, OutgoingHttpHeaders as HttpResponseHeaders
|
|
1
|
+
export type { IncomingHttpHeaders as HttpRequestHeaders, OutgoingHttpHeaders as HttpResponseHeaders } from 'node:http';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpHeaders.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"HttpHeaders.js","sourceRoot":"","sources":["../src/HttpHeaders.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpMethod.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"HttpMethod.js","sourceRoot":"","sources":["../src/HttpMethod.ts"],"names":[],"mappings":""}
|
package/dist/assertResponse.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Validates that a fetch Response has a successful status code (2xx).
|
|
3
|
+
* If the response is not ok, reads the response body as text and throws a FetchError.
|
|
4
|
+
* @util
|
|
5
|
+
* @param response - The fetch Response object to validate
|
|
6
|
+
* @throws {FetchError} If the response status is not ok (non-2xx)
|
|
3
7
|
*/
|
|
4
8
|
export declare function assertResponse(response: Response): Promise<void>;
|
package/dist/assertResponse.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { FetchError } from './FetchError.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Validates that a fetch Response has a successful status code (2xx).
|
|
4
|
+
* If the response is not ok, reads the response body as text and throws a FetchError.
|
|
5
|
+
* @util
|
|
6
|
+
* @param response - The fetch Response object to validate
|
|
7
|
+
* @throws {FetchError} If the response status is not ok (non-2xx)
|
|
4
8
|
*/
|
|
5
9
|
export async function assertResponse(response) {
|
|
6
10
|
if (!response.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertResponse.js","sourceRoot":"","sources":["../src/assertResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C
|
|
1
|
+
{"version":3,"file":"assertResponse.js","sourceRoot":"","sources":["../src/assertResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,QAAkB;IACnD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtC,MAAM,IAAI,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;AACL,CAAC"}
|
package/dist/defineEndpoint.d.ts
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import type { FetchRequest } from './fetchRequest.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Configuration for a fetch endpoint that handles both request creation and response processing.
|
|
4
4
|
*/
|
|
5
5
|
export interface Endpoint<TParams, TResult> {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Creates a fetch request configuration based on the provided parameters.
|
|
8
8
|
*/
|
|
9
9
|
request: (params: TParams) => FetchRequest;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Optional function to transform the raw Response into the desired result type.
|
|
12
12
|
*/
|
|
13
13
|
response?: (response: Response, params: TParams) => Promise<TResult>;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* A function
|
|
16
|
+
* A function type for processing raw HTTP responses into typed results.
|
|
17
17
|
*/
|
|
18
18
|
export interface EndpointResponse<T> {
|
|
19
19
|
(response: Response): Promise<T>;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Creates a typed endpoint configuration for making HTTP requests.
|
|
23
|
+
* Use this to define reusable API endpoints with consistent request and response handling.
|
|
24
|
+
* @util
|
|
25
|
+
* @param endpoint - The endpoint configuration object
|
|
26
|
+
* @returns The provided endpoint configuration for use in HTTP requests
|
|
27
|
+
* @__NO_SIDE_EFFECTS__
|
|
25
28
|
*/
|
|
26
29
|
export declare function defineEndpoint<TParams = void, TResult = void>(endpoint: Endpoint<TParams, TResult>): Endpoint<TParams, TResult>;
|
package/dist/defineEndpoint.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Creates a typed endpoint configuration for making HTTP requests.
|
|
3
|
+
* Use this to define reusable API endpoints with consistent request and response handling.
|
|
4
|
+
* @util
|
|
5
|
+
* @param endpoint - The endpoint configuration object
|
|
6
|
+
* @returns The provided endpoint configuration for use in HTTP requests
|
|
7
|
+
* @__NO_SIDE_EFFECTS__
|
|
5
8
|
*/
|
|
6
9
|
export function defineEndpoint(endpoint) {
|
|
7
10
|
return endpoint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineEndpoint.js","sourceRoot":"","sources":["../src/defineEndpoint.ts"],"names":[],"mappings":"AAuBA
|
|
1
|
+
{"version":3,"file":"defineEndpoint.js","sourceRoot":"","sources":["../src/defineEndpoint.ts"],"names":[],"mappings":"AAuBA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAiC,QAAoC;IAC/F,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
package/dist/defineFetch.d.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import type { FetchRequest } from './fetchRequest.js';
|
|
2
2
|
/**
|
|
3
|
-
* A fetch function.
|
|
3
|
+
* A fetch function configuration object that defines how to make HTTP requests and handle responses.
|
|
4
4
|
*/
|
|
5
5
|
export interface FetchOptions<TParams, TResult> {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Creates a fetch request configuration based on the provided parameters.
|
|
8
8
|
*/
|
|
9
9
|
request: (params: TParams) => FetchRequest;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Optional function to transform the raw Response into the desired result type.
|
|
12
12
|
*/
|
|
13
13
|
response?: (response: Response, params: TParams) => Promise<TResult>;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Creates a typed fetch function with specified request and response handling.
|
|
17
|
+
* Use this to define reusable fetch operations with consistent typing.
|
|
18
|
+
* @util
|
|
19
|
+
* @param fetch - The fetch configuration object
|
|
20
|
+
* @returns The provided fetch configuration for use in HTTP requests
|
|
21
|
+
* @__NO_SIDE_EFFECTS__
|
|
19
22
|
*/
|
|
20
23
|
export declare function defineFetch<TParams = void, TResult = void>(fetch: FetchOptions<TParams, TResult>): FetchOptions<TParams, TResult>;
|
package/dist/defineFetch.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Creates a typed fetch function with specified request and response handling.
|
|
3
|
+
* Use this to define reusable fetch operations with consistent typing.
|
|
4
|
+
* @util
|
|
5
|
+
* @param fetch - The fetch configuration object
|
|
6
|
+
* @returns The provided fetch configuration for use in HTTP requests
|
|
7
|
+
* @__NO_SIDE_EFFECTS__
|
|
5
8
|
*/
|
|
6
9
|
export function defineFetch(fetch) {
|
|
7
10
|
return fetch;
|
package/dist/defineFetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineFetch.js","sourceRoot":"","sources":["../src/defineFetch.ts"],"names":[],"mappings":"AAgBA
|
|
1
|
+
{"version":3,"file":"defineFetch.js","sourceRoot":"","sources":["../src/defineFetch.ts"],"names":[],"mappings":"AAgBA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAiC,KAAqC;IAC7F,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
import type { Endpoint } from './defineEndpoint.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type definition for a fetch client that can execute endpoints with or without parameters.
|
|
4
|
+
* Provides type-safe overloads for parameterless and parameterized endpoints.
|
|
5
|
+
*/
|
|
2
6
|
export interface FetchClient {
|
|
7
|
+
/**
|
|
8
|
+
* Executes an endpoint that doesn't require parameters
|
|
9
|
+
*/
|
|
3
10
|
<TResult>(endpoint: Endpoint<void, TResult>): Promise<TResult>;
|
|
11
|
+
/**
|
|
12
|
+
* Executes an endpoint with the specified parameters
|
|
13
|
+
*/
|
|
4
14
|
<TParams, TResult>(endpoint: Endpoint<TParams, TResult>, params: TParams): Promise<TResult>;
|
|
5
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Internal type for the raw fetch client implementation
|
|
18
|
+
*/
|
|
6
19
|
interface FetchClientInput {
|
|
7
20
|
(endpoint: Endpoint<unknown, unknown>, params?: unknown): Promise<unknown>;
|
|
8
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a type-safe fetch client from a raw implementation.
|
|
24
|
+
* The client can be used to execute endpoints with proper type checking.
|
|
25
|
+
* @util
|
|
26
|
+
* @param client - The raw fetch client implementation
|
|
27
|
+
* @returns A typed fetch client for executing endpoints
|
|
28
|
+
* @__NO_SIDE_EFFECTS__
|
|
29
|
+
*/
|
|
9
30
|
export declare function defineFetchClient(client: FetchClientInput): FetchClient;
|
|
10
31
|
export {};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates a type-safe fetch client from a raw implementation.
|
|
3
|
+
* The client can be used to execute endpoints with proper type checking.
|
|
4
|
+
* @util
|
|
5
|
+
* @param client - The raw fetch client implementation
|
|
6
|
+
* @returns A typed fetch client for executing endpoints
|
|
7
|
+
* @__NO_SIDE_EFFECTS__
|
|
8
|
+
*/
|
|
2
9
|
export function defineFetchClient(client) {
|
|
3
10
|
return client;
|
|
4
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineFetchClient.js","sourceRoot":"","sources":["../src/defineFetchClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"defineFetchClient.js","sourceRoot":"","sources":["../src/defineFetchClient.ts"],"names":[],"mappings":"AAwBA;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAwB;IACtD,OAAO,MAAqB,CAAC;AACjC,CAAC"}
|
package/dist/fetchEndpoint.d.ts
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import type { Endpoint } from './defineEndpoint.js';
|
|
2
2
|
/**
|
|
3
|
-
* Parameters for a fetch endpoint.
|
|
3
|
+
* Parameters for configuring a fetch endpoint request.
|
|
4
|
+
* Includes endpoint parameters, base URL, and additional headers.
|
|
4
5
|
*/
|
|
5
6
|
export interface FetchEndpointParams<TParams> {
|
|
6
7
|
/**
|
|
7
|
-
* The parameters for the endpoint
|
|
8
|
+
* The parameters for the endpoint request
|
|
8
9
|
*/
|
|
9
10
|
params: TParams;
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* Optional base URL to prepend to the endpoint URL
|
|
12
13
|
*/
|
|
13
14
|
baseUrl?: string;
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* Optional additional headers to include in the request
|
|
16
17
|
*/
|
|
17
18
|
headers?: Record<string, string>;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
+
* Executes a fetch request for a configured endpoint.
|
|
22
|
+
* Handles URL joining, header merging, and response processing.
|
|
23
|
+
* @util
|
|
24
|
+
* @param endpoint - The endpoint configuration to execute
|
|
25
|
+
* @param params - Parameters for the endpoint request
|
|
26
|
+
* @returns A promise that resolves to the processed response
|
|
21
27
|
*/
|
|
22
28
|
export declare function fetchEndpoint<TParams, TResult>(endpoint: Endpoint<TParams, TResult>, params: FetchEndpointParams<TParams>): Promise<TResult>;
|
package/dist/fetchEndpoint.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { joinURL, withQuery } from 'ufo';
|
|
2
2
|
import { assertResponse } from './assertResponse.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Executes a fetch request for a configured endpoint.
|
|
5
|
+
* Handles URL joining, header merging, and response processing.
|
|
6
|
+
* @util
|
|
7
|
+
* @param endpoint - The endpoint configuration to execute
|
|
8
|
+
* @param params - Parameters for the endpoint request
|
|
9
|
+
* @returns A promise that resolves to the processed response
|
|
5
10
|
*/
|
|
6
11
|
export async function fetchEndpoint(endpoint, params) {
|
|
7
12
|
let request = endpoint.request(params.params);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchEndpoint.js","sourceRoot":"","sources":["../src/fetchEndpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetchEndpoint.js","sourceRoot":"","sources":["../src/fetchEndpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAsBrD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAC/B,QAAoC,EACpC,MAAoC;IAEpC,IAAI,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAE9C,OAAO,GAAG;QACN,GAAG,OAAO;QACV,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG;QACxE,OAAO,EAAE;YACL,GAAG,MAAM,CAAC,OAAO;YACjB,GAAG,OAAO,CAAC,OAAO;SACrB;KACJ,CAAC;IAEF,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IAChF,wDAAwD;IACxD,MAAM,QAAQ,GAAG,CAAC,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,EAAc,CAAC;IAEjE,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5D,CAAC;SAAM,CAAC;QACJ,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,SAA+B,CAAC;AAC3C,CAAC"}
|
package/dist/fetchJson.d.ts
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
import type { QueryObject } from 'ufo';
|
|
2
|
+
/**
|
|
3
|
+
* Base configuration for all JSON fetch requests
|
|
4
|
+
*/
|
|
2
5
|
interface BaseRequest {
|
|
6
|
+
/** The target URL for the request */
|
|
3
7
|
url: string;
|
|
8
|
+
/** Optional query parameters to append to the URL */
|
|
4
9
|
query?: QueryObject;
|
|
10
|
+
/** Optional request headers */
|
|
5
11
|
headers?: Record<string, string>;
|
|
6
12
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for methods that include a request body
|
|
15
|
+
*/
|
|
11
16
|
interface DataRequest extends BaseRequest {
|
|
12
|
-
method
|
|
17
|
+
/** HTTP method for requests with a body */
|
|
18
|
+
method: 'PATCH' | 'POST' | 'PUT';
|
|
19
|
+
/** Optional data to be sent as JSON */
|
|
13
20
|
data?: unknown;
|
|
14
21
|
}
|
|
15
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for methods that don't include a request body
|
|
24
|
+
*/
|
|
25
|
+
interface SimpleRequest extends BaseRequest {
|
|
26
|
+
/** HTTP method for requests without a body */
|
|
27
|
+
method?: 'DELETE' | 'GET' | 'HEAD';
|
|
28
|
+
/** Explicitly prevent data for these methods */
|
|
29
|
+
data?: never;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Performs a fetch request with JSON handling for both request and response.
|
|
33
|
+
* Automatically handles query parameters, JSON serialization, and common status codes.
|
|
34
|
+
* @util
|
|
35
|
+
* @param request - The request configuration
|
|
36
|
+
* @returns A promise that resolves to the parsed JSON response, or null for 204 responses
|
|
37
|
+
* @throws {FetchError} If the response status is not ok
|
|
38
|
+
*/
|
|
39
|
+
export declare function fetchJson<T>(request: DataRequest | SimpleRequest): Promise<T | null>;
|
|
16
40
|
export {};
|
package/dist/fetchJson.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { withQuery } from 'ufo';
|
|
2
2
|
import { FetchError } from './FetchError.js';
|
|
3
|
+
/**
|
|
4
|
+
* Performs a fetch request with JSON handling for both request and response.
|
|
5
|
+
* Automatically handles query parameters, JSON serialization, and common status codes.
|
|
6
|
+
* @util
|
|
7
|
+
* @param request - The request configuration
|
|
8
|
+
* @returns A promise that resolves to the parsed JSON response, or null for 204 responses
|
|
9
|
+
* @throws {FetchError} If the response status is not ok
|
|
10
|
+
*/
|
|
3
11
|
export async function fetchJson(request) {
|
|
4
12
|
const headers = { ...request.headers };
|
|
5
13
|
let url = request.url;
|
package/dist/fetchJson.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchJson.js","sourceRoot":"","sources":["../src/fetchJson.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetchJson.js","sourceRoot":"","sources":["../src/fetchJson.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAkC7C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,OAAoC;IACnE,MAAM,OAAO,GAA2B,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAC/D,IAAI,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACtB,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,WAAW,GAAgB;QAC7B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK;QAC/B,OAAO,EAAE,OAAO;KACnB,CAAC;IAEF,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,OAAO,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC;QAC7C,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IAC/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAM,CAAC;AACxC,CAAC"}
|
package/dist/fetchRequest.d.ts
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import type { QueryObject } from 'ufo';
|
|
2
|
-
import type { HttpMethod } from './
|
|
2
|
+
import type { HttpMethod } from './HttpMethod.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extended fetch request configuration that includes URL, query parameters, and standard RequestInit options.
|
|
5
|
+
*/
|
|
3
6
|
export interface FetchRequest extends RequestInit {
|
|
7
|
+
/**
|
|
8
|
+
* The target URL for the request
|
|
9
|
+
*/
|
|
4
10
|
url: string;
|
|
11
|
+
/**
|
|
12
|
+
* Optional query parameters to append to the URL
|
|
13
|
+
*/
|
|
5
14
|
query?: QueryObject;
|
|
15
|
+
/**
|
|
16
|
+
* HTTP method for the request
|
|
17
|
+
*/
|
|
6
18
|
method?: HttpMethod;
|
|
19
|
+
/**
|
|
20
|
+
* Request headers as key-value pairs
|
|
21
|
+
*/
|
|
7
22
|
headers?: Record<string, string>;
|
|
8
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Executes a fetch request with the provided configuration.
|
|
26
|
+
* Automatically handles query parameter serialization and response validation.
|
|
27
|
+
* @util
|
|
28
|
+
* @param request - The request configuration
|
|
29
|
+
* @returns A cloned Response object after validation
|
|
30
|
+
*/
|
|
9
31
|
export declare function fetchRequest(request: FetchRequest): Promise<Response>;
|
package/dist/fetchRequest.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { withQuery } from 'ufo';
|
|
2
2
|
import { assertResponse } from './assertResponse.js';
|
|
3
|
+
/**
|
|
4
|
+
* Executes a fetch request with the provided configuration.
|
|
5
|
+
* Automatically handles query parameter serialization and response validation.
|
|
6
|
+
* @util
|
|
7
|
+
* @param request - The request configuration
|
|
8
|
+
* @returns A cloned Response object after validation
|
|
9
|
+
*/
|
|
3
10
|
export async function fetchRequest(request) {
|
|
4
11
|
const url = request.query ? withQuery(request.url, request.query) : request.url;
|
|
5
12
|
const response = await fetch(url, request);
|
package/dist/fetchRequest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchRequest.js","sourceRoot":"","sources":["../src/fetchRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetchRequest.js","sourceRoot":"","sources":["../src/fetchRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAyBrD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAqB;IACpD,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IAChF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAE3C,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC/B,wDAAwD;IACxD,OAAO,QAAQ,CAAC,KAAK,EAAc,CAAC;AACxC,CAAC"}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import type { OmitProps } from '@nzyme/types';
|
|
1
|
+
import type { OmitProps } from '@nzyme/types/Object.js';
|
|
2
2
|
import type { FetchRequest } from './fetchRequest.js';
|
|
3
|
+
/**
|
|
4
|
+
* Request configuration for form URL encoded requests.
|
|
5
|
+
* Extends the base FetchRequest but allows for a typed body parameter.
|
|
6
|
+
*/
|
|
3
7
|
export interface EndpointFormUrlEncodedRequest<T = unknown> extends OmitProps<FetchRequest, 'body'> {
|
|
8
|
+
/** The request body that will be encoded as form URL parameters */
|
|
4
9
|
body?: T;
|
|
5
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a fetch request with form URL encoded body.
|
|
13
|
+
* Automatically sets the appropriate Content-Type header and converts the body to URLSearchParams.
|
|
14
|
+
* @util
|
|
15
|
+
* @param request - The request configuration with form data
|
|
16
|
+
* @returns A FetchRequest configured for form URL encoded submission
|
|
17
|
+
*/
|
|
6
18
|
export declare function formUrlEncodedRequest<T>(request: EndpointFormUrlEncodedRequest<T>): FetchRequest;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a fetch request with form URL encoded body.
|
|
3
|
+
* Automatically sets the appropriate Content-Type header and converts the body to URLSearchParams.
|
|
4
|
+
* @util
|
|
5
|
+
* @param request - The request configuration with form data
|
|
6
|
+
* @returns A FetchRequest configured for form URL encoded submission
|
|
7
|
+
*/
|
|
1
8
|
export function formUrlEncodedRequest(request) {
|
|
2
9
|
if (!request.body) {
|
|
3
10
|
return request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formUrlEncodedRequest.js","sourceRoot":"","sources":["../src/formUrlEncodedRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formUrlEncodedRequest.js","sourceRoot":"","sources":["../src/formUrlEncodedRequest.ts"],"names":[],"mappings":"AAaA;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAI,OAAyC;IAC9E,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,OAAuB,CAAC;IACnC,CAAC;IAED,OAAO;QACH,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,OAAO,EAAE;YACL,GAAG,OAAO,CAAC,OAAO;YAClB,cAAc,EAAE,mCAAmC;SACtD;QACD,IAAI,EAAE,IAAI,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC;KAC1C,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts filename from the Content-Disposition header of a Response.
|
|
3
|
+
* @util
|
|
4
|
+
* @param response - The Response object to extract filename from
|
|
5
|
+
* @returns The filename if found in Content-Disposition header, null otherwise
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const response = await fetch('https://example.com/file');
|
|
10
|
+
* const filename = getResponseFileName(response);
|
|
11
|
+
* console.log(filename); // 'document.pdf' or null
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @__NO_SIDE_EFFECTS__
|
|
15
|
+
*/
|
|
16
|
+
export declare function getResponseFileName(response: Response): string | null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts filename from the Content-Disposition header of a Response.
|
|
3
|
+
* @util
|
|
4
|
+
* @param response - The Response object to extract filename from
|
|
5
|
+
* @returns The filename if found in Content-Disposition header, null otherwise
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const response = await fetch('https://example.com/file');
|
|
10
|
+
* const filename = getResponseFileName(response);
|
|
11
|
+
* console.log(filename); // 'document.pdf' or null
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @__NO_SIDE_EFFECTS__
|
|
15
|
+
*/
|
|
16
|
+
export function getResponseFileName(response) {
|
|
17
|
+
const contentDisposition = response.headers.get('Content-Disposition');
|
|
18
|
+
if (!contentDisposition) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const match = /filename="?([^"]+)"?/.exec(contentDisposition);
|
|
22
|
+
return match?.[1] ?? null;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=getResponseFileName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getResponseFileName.js","sourceRoot":"","sources":["../src/getResponseFileName.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAkB;IAClD,MAAM,kBAAkB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAEvE,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC9D,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC9B,CAAC"}
|