@equinor/fusion-framework-module-http 6.2.1 → 6.2.3
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 +350 -310
- package/dist/esm/configurator.js +2 -2
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/lib/client/client-msal.js.map +1 -1
- package/dist/esm/lib/client/client.js.map +1 -1
- package/dist/esm/lib/operators/capitalize-request-method.operator.js +3 -1
- package/dist/esm/lib/operators/capitalize-request-method.operator.js.map +1 -1
- package/dist/esm/lib/operators/fetch-request.schema.js.map +1 -1
- package/dist/esm/lib/operators/http-request-handler.js.map +1 -1
- package/dist/esm/lib/operators/process-operators.js.map +1 -1
- package/dist/esm/lib/operators/request-operator-header.js.map +1 -1
- package/dist/esm/lib/operators/request-validation.operator.js.map +1 -1
- package/dist/esm/lib/selectors/blob-selector.js.map +1 -1
- package/dist/esm/lib/selectors/json-selector.js.map +1 -1
- package/dist/esm/module.js +1 -1
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/provider.js +9 -4
- package/dist/esm/provider.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/lib/operators/process-operators.d.ts +1 -1
- package/dist/types/module.d.ts +3 -3
- package/dist/types/provider.d.ts +10 -3
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/configurator.ts +115 -116
- package/src/errors.ts +24 -24
- package/src/lib/client/client-msal.ts +34 -34
- package/src/lib/client/client.ts +298 -298
- package/src/lib/client/types.ts +147 -145
- package/src/lib/operators/capitalize-request-method.operator.ts +11 -9
- package/src/lib/operators/fetch-request.schema.ts +70 -73
- package/src/lib/operators/http-request-handler.ts +11 -11
- package/src/lib/operators/process-operators.ts +88 -88
- package/src/lib/operators/request-operator-header.ts +6 -6
- package/src/lib/operators/request-validation.operator.ts +32 -32
- package/src/lib/operators/types.ts +44 -44
- package/src/lib/selectors/blob-selector.ts +24 -24
- package/src/lib/selectors/json-selector.ts +25 -25
- package/src/module.ts +73 -69
- package/src/provider.ts +141 -139
- package/src/version.ts +1 -1
- package/tests/HttpClient.test.ts +37 -37
- package/tests/operators.test.ts +67 -67
- package/vitest.config.ts +6 -6
package/src/lib/client/types.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type StreamResponse<T> = Observable<T>;
|
|
|
16
16
|
* @returns An `ObservableInput` of type `T`.
|
|
17
17
|
*/
|
|
18
18
|
export type ResponseSelector<TResult = unknown, TResponse = Response> = (
|
|
19
|
-
|
|
19
|
+
response: TResponse,
|
|
20
20
|
) => ObservableInput<TResult>;
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -25,8 +25,8 @@ export type ResponseSelector<TResult = unknown, TResponse = Response> = (
|
|
|
25
25
|
* @property {string} path - The path of the request.
|
|
26
26
|
*/
|
|
27
27
|
export type FetchRequest = RequestInit & {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
uri: string;
|
|
29
|
+
path: string;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -35,7 +35,7 @@ export type FetchRequest = RequestInit & {
|
|
|
35
35
|
* @property {object | string | null} [body] - The request body, which can be an object, a string, or null.
|
|
36
36
|
*/
|
|
37
37
|
export type JsonRequest<TRequest extends FetchRequest = FetchRequest> = Omit<TRequest, 'body'> & {
|
|
38
|
-
|
|
38
|
+
body?: object | string | null;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -52,7 +52,7 @@ export type BlobResult = { filename?: string; blob: Blob };
|
|
|
52
52
|
* @property {() => Promise<T>} json - A method to parse the response body as JSON and return the data as type T.
|
|
53
53
|
*/
|
|
54
54
|
export type FetchResponse<T = unknown> = Response & {
|
|
55
|
-
|
|
55
|
+
json(): Promise<T>;
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -62,12 +62,12 @@ export type FetchResponse<T = unknown> = Response & {
|
|
|
62
62
|
* @template TResponse - The type of the fetch response.
|
|
63
63
|
*/
|
|
64
64
|
export type FetchRequestInit<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
TReturn = unknown,
|
|
66
|
+
TRequest = FetchRequest,
|
|
67
|
+
TResponse = FetchResponse<TReturn>,
|
|
68
68
|
> = Omit<TRequest, 'uri' | 'path'> & {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
/** response selector function */
|
|
70
|
+
selector?: ResponseSelector<TReturn, TResponse>;
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
/**
|
|
@@ -77,10 +77,12 @@ export type FetchRequestInit<
|
|
|
77
77
|
* @template TRequest - The type of the fetch request.
|
|
78
78
|
* @template TResponse - The type of the fetch response.
|
|
79
79
|
*/
|
|
80
|
-
export type ClientRequestInit<T extends IHttpClient, TReturn = unknown> =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
export type ClientRequestInit<T extends IHttpClient, TReturn = unknown> = T extends IHttpClient<
|
|
81
|
+
infer TRequest,
|
|
82
|
+
infer TResponse
|
|
83
|
+
>
|
|
84
|
+
? FetchRequestInit<TReturn, TRequest, TResponse>
|
|
85
|
+
: never;
|
|
84
86
|
|
|
85
87
|
/**
|
|
86
88
|
* Represents the available execution methods for an HTTP client.
|
|
@@ -94,8 +96,8 @@ export type ExecutionMethod = 'fetch' | 'fetch$' | 'json' | 'json$';
|
|
|
94
96
|
* @template TClient - The type of the `IHttpClient` instance.
|
|
95
97
|
*/
|
|
96
98
|
export type ExecutionMethodParameters<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
TMethod extends ExecutionMethod = 'fetch',
|
|
100
|
+
TClient extends IHttpClient = IHttpClient,
|
|
99
101
|
> = Parameters<TClient[TMethod]>;
|
|
100
102
|
|
|
101
103
|
/**
|
|
@@ -105,8 +107,8 @@ export type ExecutionMethodParameters<
|
|
|
105
107
|
* @template TClient - The type of the `IHttpClient` instance.
|
|
106
108
|
*/
|
|
107
109
|
export type ExecutionResponse<
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
TMethod extends ExecutionMethod = 'fetch',
|
|
111
|
+
TClient extends IHttpClient = IHttpClient,
|
|
110
112
|
> = ReturnType<TClient[TMethod]>;
|
|
111
113
|
|
|
112
114
|
/**
|
|
@@ -114,131 +116,131 @@ export type ExecutionResponse<
|
|
|
114
116
|
* @template TResponse request arguments @see {@link https://developer.mozilla.org/en-US/docs/Web/API/response|response}
|
|
115
117
|
*/
|
|
116
118
|
export interface IHttpClient<TRequest extends FetchRequest = FetchRequest, TResponse = Response> {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
119
|
+
uri: string;
|
|
120
|
+
/**
|
|
121
|
+
* A pre-processor for requests made by the `IHttpClient` interface.
|
|
122
|
+
* This handler can be used to modify the request before it is sent, such as adding headers, authentication, or other transformations.
|
|
123
|
+
*/
|
|
124
|
+
readonly requestHandler: IHttpRequestHandler<TRequest>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A post-processor for responses received by the `IHttpClient` interface.
|
|
128
|
+
* This handler can be used to transform the response data after it is received, such as parsing JSON, handling errors, or other transformations.
|
|
129
|
+
*/
|
|
130
|
+
readonly responseHandler: IHttpResponseHandler<TResponse>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Observable stream of requests made by the `IHttpClient` interface.
|
|
134
|
+
* This stream can be used to observe and potentially modify the requests before they are sent.
|
|
135
|
+
*/
|
|
136
|
+
readonly request$: Observable<TRequest>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Observable stream of responses received by the `IHttpClient` interface.
|
|
140
|
+
* This stream can be used to observe and potentially handle the responses after they are received.
|
|
141
|
+
*/
|
|
142
|
+
readonly response$: Observable<TResponse>;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Fetch a resource as an observable stream.
|
|
146
|
+
* This method simplifies the execution of a request and returns an observable stream of the response.
|
|
147
|
+
* The request will not be executed until the observable is subscribed to.
|
|
148
|
+
*
|
|
149
|
+
* @template T - The expected response type.
|
|
150
|
+
* @param path - The path to fetch the resource from.
|
|
151
|
+
* @param init - Optional request initialization options.
|
|
152
|
+
* @returns An observable stream of the response.
|
|
153
|
+
*
|
|
154
|
+
* @see {@link https://rxjs.dev/api/fetch/fromFetch|RxJS fromFetch}
|
|
155
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch|fetch}
|
|
156
|
+
*/
|
|
157
|
+
fetch$<T = TResponse>(
|
|
158
|
+
path: string,
|
|
159
|
+
init?: FetchRequestInit<T, TRequest, TResponse>,
|
|
160
|
+
): StreamResponse<T>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Fetch a resource as a promise.
|
|
164
|
+
*
|
|
165
|
+
* @template T - The expected response type.
|
|
166
|
+
* @param path - The path to fetch the resource from.
|
|
167
|
+
* @param init - Optional request initialization options.
|
|
168
|
+
* @returns A promise that resolves to the fetched resource.
|
|
169
|
+
*
|
|
170
|
+
* @see {@link IHttpClient.fetch$}
|
|
171
|
+
*/
|
|
172
|
+
fetch<T = TResponse>(path: string, init?: FetchRequestInit<T, TRequest, TResponse>): Promise<T>;
|
|
173
|
+
|
|
174
|
+
/** @deprecated use {@link IHttpClient.fetch} */
|
|
175
|
+
fetchAsync<T = TResponse>(
|
|
176
|
+
path: string,
|
|
177
|
+
args?: FetchRequestInit<T, TRequest, TResponse>,
|
|
178
|
+
): Promise<T>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Fetches a resource as an observable stream.
|
|
182
|
+
* This method simplifies the execution of a request and returns an observable stream of the response.
|
|
183
|
+
* The request will not be executed until the observable is subscribed to.
|
|
184
|
+
*
|
|
185
|
+
* @template T - The expected response type.
|
|
186
|
+
* @param path - The path to fetch the resource from.
|
|
187
|
+
* @param init - Optional request initialization options, including the request body, headers, and response type.
|
|
188
|
+
* @returns An observable stream of the fetched resource.
|
|
189
|
+
*
|
|
190
|
+
* @see {@link IHttpClient.fetch$}
|
|
191
|
+
*/
|
|
192
|
+
json$<T = unknown>(
|
|
193
|
+
path: string,
|
|
194
|
+
init?: FetchRequestInit<T, JsonRequest<TRequest>, TResponse>,
|
|
195
|
+
): StreamResponse<T>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Fetches a resource as a promise and returns the response as a JSON object.
|
|
199
|
+
*
|
|
200
|
+
* @template T - The expected response type.
|
|
201
|
+
* @param path - The path to fetch the resource from.
|
|
202
|
+
* @param init - Optional request initialization options, including the request body, headers, and response type.
|
|
203
|
+
* @returns A promise that resolves to the fetched resource as a JSON object.
|
|
204
|
+
*
|
|
205
|
+
* @see {@link IHttpClient.fetch} for fetching resources as an observable stream.
|
|
206
|
+
*/
|
|
207
|
+
json<T = unknown>(
|
|
208
|
+
path: string,
|
|
209
|
+
init?: FetchRequestInit<T, JsonRequest<TRequest>, TResponse>,
|
|
210
|
+
): Promise<T>;
|
|
211
|
+
|
|
212
|
+
/** @deprecated */
|
|
213
|
+
jsonAsync<T = unknown>(
|
|
214
|
+
path: string,
|
|
215
|
+
args?: FetchRequestInit<T, JsonRequest<TRequest>, TResponse>,
|
|
216
|
+
): Promise<T>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Fetches a blob resource from the specified path and returns a Promise that resolves to the fetched blob data.
|
|
220
|
+
*
|
|
221
|
+
* @param path - The path to fetch the blob from.
|
|
222
|
+
* @param args - Optional arguments for the fetch request, including the request body, headers, and response type.
|
|
223
|
+
* @returns A Promise that resolves to the fetched blob data.
|
|
224
|
+
*/
|
|
225
|
+
blob<T = BlobResult>(
|
|
226
|
+
path: string,
|
|
227
|
+
args?: FetchRequestInit<T, JsonRequest<TRequest>, TResponse>,
|
|
228
|
+
): Promise<T>;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Fetches a blob from the specified path and returns a stream response.
|
|
232
|
+
*
|
|
233
|
+
* @param path - The path to fetch the blob from.
|
|
234
|
+
* @param args - Optional arguments for the fetch request, including the request body, headers, and response type.
|
|
235
|
+
* @returns A stream response containing the fetched blob.
|
|
236
|
+
*/
|
|
237
|
+
blob$<T = BlobResult>(
|
|
238
|
+
path: string,
|
|
239
|
+
args?: FetchRequestInit<T, JsonRequest<TRequest>, TResponse>,
|
|
240
|
+
): StreamResponse<T>;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Abort all ongoing requests for the current client.
|
|
244
|
+
*/
|
|
245
|
+
abort(): void;
|
|
244
246
|
}
|
|
@@ -8,15 +8,17 @@ import type { ProcessOperator } from './types';
|
|
|
8
8
|
* @returns A new request object with the HTTP method in uppercase.
|
|
9
9
|
*/
|
|
10
10
|
export const capitalizeRequestMethodOperator =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
<T extends RequestInit>(options?: { silent?: boolean }): ProcessOperator<T> =>
|
|
12
|
+
(request): T => {
|
|
13
|
+
const { error, success, data } = requestMethodCasing().safeParse(request.method);
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
request.method = success ? data : request.method?.toUpperCase();
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
if (error && !options?.silent) {
|
|
18
|
+
for (const e of error.errors) {
|
|
19
|
+
console.warn(e.message);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
return request;
|
|
24
|
+
};
|
|
@@ -6,19 +6,19 @@ import { z } from 'zod';
|
|
|
6
6
|
* @link https://www.rfc-editor.org/rfc/rfc7231#section-4.1
|
|
7
7
|
*/
|
|
8
8
|
export const requestMethodCasing = (): z.ZodType<string> => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
return z.custom<string>(
|
|
10
|
+
(value?: string) => value === value?.toUpperCase(),
|
|
11
|
+
(value: string) => ({
|
|
12
|
+
code: z.ZodIssueCode.custom,
|
|
13
|
+
validation: 'uppercase',
|
|
14
|
+
path: ['method'],
|
|
15
|
+
message: [
|
|
16
|
+
`Provided HTTP method '${value}' must be in uppercase.`,
|
|
17
|
+
'See RFC 7231 Section 4.1 for more information',
|
|
18
|
+
'https://www.rfc-editor.org/rfc/rfc7231#section-4.1',
|
|
19
|
+
].join(' '),
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -34,22 +34,19 @@ export const requestMethodCasing = (): z.ZodType<string> => {
|
|
|
34
34
|
* @link https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
|
|
35
35
|
*/
|
|
36
36
|
export const requestMethodVerb = () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
);
|
|
37
|
+
return z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD', 'CONNECT', 'TRACE'], {
|
|
38
|
+
errorMap: (error) => {
|
|
39
|
+
const { received, options } = error as z.ZodInvalidEnumValueIssue;
|
|
40
|
+
return {
|
|
41
|
+
message: [
|
|
42
|
+
'Invalid request method.',
|
|
43
|
+
`Expected '${options.join(' | ')}', but received '${received}'.`,
|
|
44
|
+
'See RFC 2615 Section 9 for more information',
|
|
45
|
+
'https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html',
|
|
46
|
+
].join(' '),
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|
|
53
50
|
};
|
|
54
51
|
|
|
55
52
|
export const requestMethod = () => requestMethodCasing().pipe(requestMethodVerb());
|
|
@@ -62,48 +59,48 @@ export const requestMethod = () => requestMethodCasing().pipe(requestMethodVerb(
|
|
|
62
59
|
* This schema is used to ensure that the request options conform to the expected structure and types.
|
|
63
60
|
*/
|
|
64
61
|
export const requestInitSchema = z.object({
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
62
|
+
attributionReporting: z
|
|
63
|
+
.object({
|
|
64
|
+
eventSourceEligible: z.boolean().optional(),
|
|
65
|
+
triggerEligible: z.boolean().optional(),
|
|
66
|
+
})
|
|
67
|
+
.optional(),
|
|
68
|
+
body: z
|
|
69
|
+
.union([
|
|
70
|
+
z.string(),
|
|
71
|
+
z.instanceof(Blob),
|
|
72
|
+
z.instanceof(ArrayBuffer),
|
|
73
|
+
z.instanceof(FormData),
|
|
74
|
+
z.instanceof(URLSearchParams),
|
|
75
|
+
z.instanceof(ReadableStream),
|
|
76
|
+
])
|
|
77
|
+
.optional(),
|
|
78
|
+
browsingTopics: z.boolean().optional(),
|
|
79
|
+
cache: z
|
|
80
|
+
.enum(['default', 'no-store', 'reload', 'no-cache', 'force-cache', 'only-if-cached'])
|
|
81
|
+
.optional(),
|
|
82
|
+
credentials: z.enum(['omit', 'same-origin', 'include']).optional(),
|
|
83
|
+
headers: z.record(z.string(), z.string()).optional().or(z.instanceof(Headers)),
|
|
84
|
+
integrity: z.string().optional(),
|
|
85
|
+
keepalive: z.boolean().optional(),
|
|
86
|
+
method: requestMethod().optional(),
|
|
87
|
+
mode: z.enum(['same-origin', 'cors', 'no-cors', 'navigate', 'websocket']).optional(),
|
|
88
|
+
priority: z.enum(['low', 'high', 'auto']).optional(),
|
|
89
|
+
redirect: z.enum(['follow', 'error', 'manual']).optional(),
|
|
90
|
+
referrer: z.string().optional(),
|
|
91
|
+
referrerPolicy: z
|
|
92
|
+
.enum([
|
|
93
|
+
'no-referrer',
|
|
94
|
+
'no-referrer-when-downgrade',
|
|
95
|
+
'origin',
|
|
96
|
+
'origin-when-cross-origin',
|
|
97
|
+
'same-origin',
|
|
98
|
+
'strict-origin',
|
|
99
|
+
'strict-origin-when-cross-origin',
|
|
100
|
+
'unsafe-url',
|
|
101
|
+
])
|
|
102
|
+
.optional(),
|
|
103
|
+
signal: z.instanceof(AbortSignal).optional(),
|
|
107
104
|
});
|
|
108
105
|
|
|
109
106
|
/**
|
|
@@ -114,6 +111,6 @@ export const requestInitSchema = z.object({
|
|
|
114
111
|
* - `path`: An optional string representing the path of the request.
|
|
115
112
|
*/
|
|
116
113
|
export const fetchRequestSchema = requestInitSchema.extend({
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
uri: z.string(),
|
|
115
|
+
path: z.string().optional(),
|
|
119
116
|
});
|
|
@@ -13,17 +13,17 @@ import type { FetchRequest } from '../client';
|
|
|
13
13
|
* @template T - The type of the fetch request, which extends `FetchRequest`.
|
|
14
14
|
*/
|
|
15
15
|
export class HttpRequestHandler<T extends FetchRequest = FetchRequest> extends ProcessOperators<T> {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Sets a header that will apply to all requests made by the `HttpClient`.
|
|
18
|
+
*
|
|
19
|
+
* @param key - The name of the header to set.
|
|
20
|
+
* @param value - The value of the header to set.
|
|
21
|
+
* @returns The current `HttpRequestHandler` instance, allowing for method chaining.
|
|
22
|
+
*/
|
|
23
|
+
setHeader(key: string, value: string): HttpRequestHandler<T> {
|
|
24
|
+
const operator = requestOperatorHeader<T>(key, value);
|
|
25
|
+
return this.set('header-' + key, operator) as HttpRequestHandler<T>;
|
|
26
|
+
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export default HttpRequestHandler;
|