@nzyme/fetch-utils 0.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/LICENSE +21 -0
- package/dist/FetchError.d.ts +6 -0
- package/dist/FetchError.js +12 -0
- package/dist/FetchError.js.map +1 -0
- package/dist/assertResponse.d.ts +1 -0
- package/dist/assertResponse.js +8 -0
- package/dist/assertResponse.js.map +1 -0
- package/dist/defineEndpoint.d.ts +9 -0
- package/dist/defineEndpoint.js +5 -0
- package/dist/defineEndpoint.js.map +1 -0
- package/dist/defineFetchClient.d.ts +10 -0
- package/dist/defineFetchClient.js +5 -0
- package/dist/defineFetchClient.js.map +1 -0
- package/dist/fetchEndpoint.d.ts +9 -0
- package/dist/fetchEndpoint.js +20 -0
- package/dist/fetchEndpoint.js.map +1 -0
- package/dist/fetchJson.d.ts +16 -0
- package/dist/fetchJson.js +26 -0
- package/dist/fetchJson.js.map +1 -0
- package/dist/fetchRequest.d.ts +9 -0
- package/dist/fetchRequest.js +10 -0
- package/dist/fetchRequest.js.map +1 -0
- package/dist/formUrlEncodedRequest.d.ts +6 -0
- package/dist/formUrlEncodedRequest.js +16 -0
- package/dist/formUrlEncodedRequest.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/jsonRequest.d.ts +6 -0
- package/dist/jsonRequest.js +14 -0
- package/dist/jsonRequest.js.map +1 -0
- package/dist/jsonResponse.d.ts +1 -0
- package/dist/jsonResponse.js +4 -0
- package/dist/jsonResponse.js.map +1 -0
- package/dist/types/HttpHeaders.d.ts +1 -0
- package/dist/types/HttpHeaders.js +2 -0
- package/dist/types/HttpHeaders.js.map +1 -0
- package/dist/types/HttpMethod.d.ts +1 -0
- package/dist/types/HttpMethod.js +2 -0
- package/dist/types/HttpMethod.js.map +1 -0
- package/dist/types/HttpResponse.d.ts +7 -0
- package/dist/types/HttpResponse.js +2 -0
- package/dist/types/HttpResponse.js.map +1 -0
- package/dist/xmlRequest.d.ts +6 -0
- package/dist/xmlRequest.js +15 -0
- package/dist/xmlRequest.js.map +1 -0
- package/dist/xmlResponse.d.ts +1 -0
- package/dist/xmlResponse.js +6 -0
- package/dist/xmlResponse.js.map +1 -0
- package/package.json +30 -0
- package/tsconfig.json +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 kedrzu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class FetchError extends Error {
|
|
2
|
+
response;
|
|
3
|
+
status;
|
|
4
|
+
url;
|
|
5
|
+
constructor(response, message) {
|
|
6
|
+
super(message || response.statusText);
|
|
7
|
+
this.response = response;
|
|
8
|
+
this.url = response.url;
|
|
9
|
+
this.status = response.status;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=FetchError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FetchError.js","sourceRoot":"","sources":["../src/FetchError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IAKb;IAJJ,MAAM,CAAS;IACf,GAAG,CAAS;IAE5B,YACoB,QAAkB,EAClC,OAAgB;QAEhB,KAAK,CAAC,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;QAHtB,aAAQ,GAAR,QAAQ,CAAU;QAIlC,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAClC,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertResponse(response: Response): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertResponse.js","sourceRoot":"","sources":["../src/assertResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FetchRequest } from './fetchRequest.js';
|
|
2
|
+
export interface Endpoint<TParams, TResult> {
|
|
3
|
+
request: (params: TParams) => FetchRequest;
|
|
4
|
+
response?: (response: Response, params: TParams) => Promise<TResult>;
|
|
5
|
+
}
|
|
6
|
+
export interface EndpointResponse<T> {
|
|
7
|
+
(response: Response): Promise<T>;
|
|
8
|
+
}
|
|
9
|
+
export declare function defineEndpoint<TParams = void, TResult = void>(endpoint: Endpoint<TParams, TResult>): Endpoint<TParams, TResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineEndpoint.js","sourceRoot":"","sources":["../src/defineEndpoint.ts"],"names":[],"mappings":"AAWA,wBAAwB;AACxB,MAAM,UAAU,cAAc,CAC1B,QAAoC;IAEpC,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Endpoint } from './defineEndpoint.js';
|
|
2
|
+
export interface FetchClient {
|
|
3
|
+
<TResult>(endpoint: Endpoint<void, TResult>): Promise<TResult>;
|
|
4
|
+
<TParams, TResult>(endpoint: Endpoint<TParams, TResult>, params: TParams): Promise<TResult>;
|
|
5
|
+
}
|
|
6
|
+
interface FetchClientInput {
|
|
7
|
+
(endpoint: Endpoint<unknown, unknown>, params?: unknown): Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
export declare function defineFetchClient(client: FetchClientInput): FetchClient;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineFetchClient.js","sourceRoot":"","sources":["../src/defineFetchClient.ts"],"names":[],"mappings":"AAWA,wBAAwB;AACxB,MAAM,UAAU,iBAAiB,CAAC,MAAwB;IACtD,OAAO,MAAqB,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Endpoint } from './defineEndpoint.js';
|
|
2
|
+
import type { FetchRequest } from './fetchRequest.js';
|
|
3
|
+
export interface FetchEndpointParams<TParams> {
|
|
4
|
+
params: TParams;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
onRequest?: (request: FetchRequest) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function fetchEndpoint<TParams, TResult>(endpoint: Endpoint<TParams, TResult>, params: FetchEndpointParams<TParams>): Promise<TResult>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { joinURL } from 'ufo';
|
|
2
|
+
import { fetchRequest } from './fetchRequest.js';
|
|
3
|
+
export async function fetchEndpoint(endpoint, params) {
|
|
4
|
+
let request = endpoint.request(params.params);
|
|
5
|
+
request = {
|
|
6
|
+
...request,
|
|
7
|
+
url: params.baseUrl ? joinURL(params.baseUrl, request.url) : request.url,
|
|
8
|
+
headers: {
|
|
9
|
+
...params.headers,
|
|
10
|
+
...request.headers,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
params.onRequest?.(request);
|
|
14
|
+
const response = await fetchRequest(request);
|
|
15
|
+
if (endpoint.response) {
|
|
16
|
+
return await endpoint.response(response, params.params);
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=fetchEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchEndpoint.js","sourceRoot":"","sources":["../src/fetchEndpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAI9B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AASjD,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,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC;IAC5B,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC;IAE7C,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,SAA+B,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { QueryObject } from 'ufo';
|
|
2
|
+
interface BaseRequest {
|
|
3
|
+
url: string;
|
|
4
|
+
query?: QueryObject;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
interface SimpleRequest extends BaseRequest {
|
|
8
|
+
method?: 'GET' | 'HEAD' | 'DELETE';
|
|
9
|
+
data?: never;
|
|
10
|
+
}
|
|
11
|
+
interface DataRequest extends BaseRequest {
|
|
12
|
+
method: 'POST' | 'PUT' | 'PATCH';
|
|
13
|
+
data?: unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare function fetchJson<T>(request: SimpleRequest | DataRequest): Promise<T | null>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { withQuery } from 'ufo';
|
|
2
|
+
import { FetchError } from './FetchError.js';
|
|
3
|
+
export async function fetchJson(request) {
|
|
4
|
+
const headers = { ...request.headers };
|
|
5
|
+
let url = request.url;
|
|
6
|
+
if (request.query) {
|
|
7
|
+
url = withQuery(url, request.query);
|
|
8
|
+
}
|
|
9
|
+
const requestInit = {
|
|
10
|
+
method: request.method || 'GET',
|
|
11
|
+
headers: headers,
|
|
12
|
+
};
|
|
13
|
+
if (request.data) {
|
|
14
|
+
headers['Content-Type'] = 'application/json';
|
|
15
|
+
requestInit.body = JSON.stringify(request.data);
|
|
16
|
+
}
|
|
17
|
+
const response = await fetch(url, requestInit);
|
|
18
|
+
if (!response.ok) {
|
|
19
|
+
throw new FetchError(response);
|
|
20
|
+
}
|
|
21
|
+
if (response.status === 204) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return (await response.json());
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=fetchJson.js.map
|
|
@@ -0,0 +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;AAkB7C,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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { QueryObject } from 'ufo';
|
|
2
|
+
import type { HttpMethod } from './types/HttpMethod.js';
|
|
3
|
+
export interface FetchRequest extends RequestInit {
|
|
4
|
+
url: string;
|
|
5
|
+
query?: QueryObject;
|
|
6
|
+
method?: HttpMethod;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export declare function fetchRequest(request: FetchRequest): Promise<Response>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { withQuery } from 'ufo';
|
|
2
|
+
import { assertResponse } from './assertResponse.js';
|
|
3
|
+
export async function fetchRequest(request) {
|
|
4
|
+
const url = request.query ? withQuery(request.url, request.query) : request.url;
|
|
5
|
+
const response = await fetch(url, request);
|
|
6
|
+
await assertResponse(response);
|
|
7
|
+
// Clone the response to avoid "Other side closed error"
|
|
8
|
+
return response.clone();
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=fetchRequest.js.map
|
|
@@ -0,0 +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;AAUrD,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,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { OmitProps } from '@nzyme/types';
|
|
2
|
+
import type { FetchRequest } from './fetchRequest.js';
|
|
3
|
+
export interface EndpointFormUrlEncodedRequest<T = unknown> extends OmitProps<FetchRequest, 'body'> {
|
|
4
|
+
body?: T;
|
|
5
|
+
}
|
|
6
|
+
export declare function formUrlEncodedRequest<T>(request: EndpointFormUrlEncodedRequest<T>): FetchRequest;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function formUrlEncodedRequest(request) {
|
|
2
|
+
if (!request.body) {
|
|
3
|
+
return request;
|
|
4
|
+
}
|
|
5
|
+
return {
|
|
6
|
+
url: request.url,
|
|
7
|
+
method: request.method,
|
|
8
|
+
query: request.query,
|
|
9
|
+
headers: {
|
|
10
|
+
...request.headers,
|
|
11
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
12
|
+
},
|
|
13
|
+
body: new URLSearchParams(request.body),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=formUrlEncodedRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formUrlEncodedRequest.js","sourceRoot":"","sources":["../src/formUrlEncodedRequest.ts"],"names":[],"mappings":"AASA,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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './assertResponse.js';
|
|
2
|
+
export * from './defineEndpoint.js';
|
|
3
|
+
export * from './defineFetchClient.js';
|
|
4
|
+
export * from './fetchEndpoint.js';
|
|
5
|
+
export * from './fetchJson.js';
|
|
6
|
+
export * from './fetchRequest.js';
|
|
7
|
+
export * from './FetchError.js';
|
|
8
|
+
export * from './formUrlEncodedRequest.js';
|
|
9
|
+
export * from './jsonRequest.js';
|
|
10
|
+
export * from './jsonResponse.js';
|
|
11
|
+
export * from './xmlRequest.js';
|
|
12
|
+
export * from './xmlResponse.js';
|
|
13
|
+
export * from './types/HttpHeaders.js';
|
|
14
|
+
export * from './types/HttpMethod.js';
|
|
15
|
+
export * from './types/HttpResponse.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './assertResponse.js';
|
|
2
|
+
export * from './defineEndpoint.js';
|
|
3
|
+
export * from './defineFetchClient.js';
|
|
4
|
+
export * from './fetchEndpoint.js';
|
|
5
|
+
export * from './fetchJson.js';
|
|
6
|
+
export * from './fetchRequest.js';
|
|
7
|
+
export * from './FetchError.js';
|
|
8
|
+
export * from './formUrlEncodedRequest.js';
|
|
9
|
+
export * from './jsonRequest.js';
|
|
10
|
+
export * from './jsonResponse.js';
|
|
11
|
+
export * from './xmlRequest.js';
|
|
12
|
+
export * from './xmlResponse.js';
|
|
13
|
+
export * from './types/HttpHeaders.js';
|
|
14
|
+
export * from './types/HttpMethod.js';
|
|
15
|
+
export * from './types/HttpResponse.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { OmitProps } from '@nzyme/types';
|
|
2
|
+
import type { FetchRequest } from './fetchRequest.js';
|
|
3
|
+
export interface EndpointJsonRequest<T = unknown> extends OmitProps<FetchRequest, 'body'> {
|
|
4
|
+
body?: T;
|
|
5
|
+
}
|
|
6
|
+
export declare function jsonRequest<T>(request: EndpointJsonRequest<T>): FetchRequest;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function jsonRequest(request) {
|
|
2
|
+
if (!request.body) {
|
|
3
|
+
return request;
|
|
4
|
+
}
|
|
5
|
+
return {
|
|
6
|
+
...request,
|
|
7
|
+
headers: {
|
|
8
|
+
...request.headers,
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify(request.body),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=jsonRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonRequest.js","sourceRoot":"","sources":["../src/jsonRequest.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,WAAW,CAAI,OAA+B;IAC1D,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,OAAuB,CAAC;IACnC,CAAC;IAED,OAAO;QACH,GAAG,OAAO;QACV,OAAO,EAAE;YACL,GAAG,OAAO,CAAC,OAAO;YAClB,cAAc,EAAE,kBAAkB;SACrC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;KACrC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function jsonResponse<T>(response: Response): Promise<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonResponse.js","sourceRoot":"","sources":["../src/jsonResponse.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAI,QAAkB;IAC9C,OAAO,QAAQ,CAAC,IAAI,EAAgB,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { IncomingHttpHeaders as HttpRequestHeaders, OutgoingHttpHeaders as HttpResponseHeaders, } from 'http';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpHeaders.js","sourceRoot":"","sources":["../../src/types/HttpHeaders.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpMethod.js","sourceRoot":"","sources":["../../src/types/HttpMethod.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpResponse.js","sourceRoot":"","sources":["../../src/types/HttpResponse.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { XmlElement } from '@nzyme/xml-utils';
|
|
2
|
+
import type { FetchRequest } from './fetchRequest.js';
|
|
3
|
+
export interface EndpointXmlRequest extends Omit<FetchRequest, 'body'> {
|
|
4
|
+
body?: XmlElement;
|
|
5
|
+
}
|
|
6
|
+
export declare function xmlRequest(request: EndpointXmlRequest): FetchRequest;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { xmlStringify } from '@nzyme/xml-utils';
|
|
2
|
+
export function xmlRequest(request) {
|
|
3
|
+
if (!request.body) {
|
|
4
|
+
return request;
|
|
5
|
+
}
|
|
6
|
+
return {
|
|
7
|
+
...request,
|
|
8
|
+
headers: {
|
|
9
|
+
...request.headers,
|
|
10
|
+
'Content-Type': 'text/xml',
|
|
11
|
+
},
|
|
12
|
+
body: xmlStringify(request.body),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=xmlRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xmlRequest.js","sourceRoot":"","sources":["../src/xmlRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAQhD,MAAM,UAAU,UAAU,CAAC,OAA2B;IAClD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,OAAuB,CAAC;IACnC,CAAC;IAED,OAAO;QACH,GAAG,OAAO;QACV,OAAO,EAAE;YACL,GAAG,OAAO,CAAC,OAAO;YAClB,cAAc,EAAE,UAAU;SAC7B;QACD,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC;KACnC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function xmlResponse(response: Response): Promise<import("@nzyme/xml-utils").XmlElement>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xmlResponse.js","sourceRoot":"","sources":["../src/xmlResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAkB;IAChD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAClC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nzyme/fetch-utils",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"repository": "https://github.com/kedrzu/nzyme.git",
|
|
10
|
+
"author": "Michał Kędrzyński <m.kedrzynski@gmail.com>",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"eslint": "eslint . --fix --cache",
|
|
16
|
+
"build": "tsc --build"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@nzyme/ioc": "^0.1.0",
|
|
20
|
+
"@nzyme/types": "^0.1.0",
|
|
21
|
+
"@nzyme/xml-utils": "^0.1.0",
|
|
22
|
+
"ufo": "^1.5.4"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@nzyme/eslint": "^0.1.0",
|
|
26
|
+
"@nzyme/tsconfig": "^0.1.0",
|
|
27
|
+
"@types/node": "^22.10.5"
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "292c98d76c39c9629a99faab3fbfe569bd289ef0"
|
|
30
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@nzyme/tsconfig/base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"tsBuildInfoFile": "./dist/.tsbuildinfo",
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"lib": ["ESNext", "DOM"]
|
|
9
|
+
},
|
|
10
|
+
"include": ["src"],
|
|
11
|
+
"references": [
|
|
12
|
+
{
|
|
13
|
+
"path": "../ioc/tsconfig.json"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"path": "../types/tsconfig.json"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"path": "../xml-utils/tsconfig.json"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|