@autometa/http 1.4.20 → 2.0.0-rc.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/README.md +107 -2
- package/dist/assertions/http-adapters.d.ts +35 -0
- package/dist/assertions/http-assertions-plugin.d.ts +16 -0
- package/dist/assertions/http-ensure.d.ts +42 -0
- package/dist/axios-transport.d.ts +22 -0
- package/dist/default-schema.d.ts +8 -0
- package/dist/fetch-transport.d.ts +21 -0
- package/dist/http-request.d.ts +109 -0
- package/dist/http-response.d.ts +77 -0
- package/dist/http.d.ts +300 -0
- package/dist/index.cjs +2076 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +15 -1116
- package/dist/index.js +1727 -845
- package/dist/index.js.map +1 -1
- package/dist/plugins.d.ts +43 -0
- package/dist/request-meta.config.d.ts +56 -0
- package/dist/schema.map.d.ts +11 -0
- package/dist/transform-response.d.ts +1 -0
- package/dist/transport.d.ts +11 -0
- package/dist/types.d.ts +39 -0
- package/package.json +30 -30
- package/.eslintignore +0 -3
- package/.eslintrc.cjs +0 -4
- package/.turbo/turbo-lint$colon$fix.log +0 -4
- package/.turbo/turbo-prettify.log +0 -5
- package/.turbo/turbo-test.log +0 -120
- package/CHANGELOG.md +0 -335
- package/dist/esm/index.js +0 -1117
- package/dist/esm/index.js.map +0 -1
- package/dist/index.d.cts +0 -1116
- package/src/axios-client.ts +0 -35
- package/src/default-client-factory.axios.spec.ts +0 -9
- package/src/default-client-factory.other.spec.ts +0 -13
- package/src/default-client-factory.ts +0 -7
- package/src/default-schema.spec.ts +0 -74
- package/src/default-schema.ts +0 -127
- package/src/http-client.ts +0 -20
- package/src/http-request.spec.ts +0 -172
- package/src/http-request.ts +0 -201
- package/src/http-response.ts +0 -107
- package/src/http.spec.ts +0 -189
- package/src/http.ts +0 -907
- package/src/index.ts +0 -13
- package/src/node_modules/.vitest/deps/_metadata.json +0 -8
- package/src/node_modules/.vitest/deps/package.json +0 -3
- package/src/node_modules/.vitest/results.json +0 -1
- package/src/request-meta.config.spec.ts +0 -81
- package/src/request-meta.config.ts +0 -134
- package/src/request.config.ts +0 -34
- package/src/schema.map.spec.ts +0 -50
- package/src/schema.map.ts +0 -68
- package/src/transform-response.ts +0 -43
- package/src/types.ts +0 -37
- package/tsup.config.ts +0 -14
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AutomationError } from "@autometa/errors";
|
|
3
|
+
import { HTTPRequest } from "./http-request";
|
|
4
|
+
import type { HeaderPrimitive } from "./http-request";
|
|
5
|
+
import { HTTPResponse } from "./http-response";
|
|
6
|
+
import type { HTTPPlugin } from "./plugins";
|
|
7
|
+
import type { HTTPTransport } from "./transport";
|
|
8
|
+
import type { HTTPAdditionalOptions, HTTPMethod, HTTPRetryOptions, QueryParamSerializationOptions, RequestHook, ResponseHook, SchemaParser, StatusCode } from "./types";
|
|
9
|
+
export declare class HTTPError extends AutomationError {
|
|
10
|
+
readonly request: HTTPRequest<unknown>;
|
|
11
|
+
readonly response: HTTPResponse<unknown> | undefined;
|
|
12
|
+
readonly originalError: unknown;
|
|
13
|
+
constructor(message: string, request: HTTPRequest<unknown>, response?: HTTPResponse<unknown>, cause?: unknown);
|
|
14
|
+
}
|
|
15
|
+
export declare class HTTPTransportError extends HTTPError {
|
|
16
|
+
constructor(request: HTTPRequest<unknown>, cause: unknown);
|
|
17
|
+
}
|
|
18
|
+
export declare class HTTPSchemaValidationError extends HTTPError {
|
|
19
|
+
constructor(request: HTTPRequest<unknown>, response: HTTPResponse<unknown>, cause: unknown);
|
|
20
|
+
}
|
|
21
|
+
export declare class HTTPServerError extends HTTPError {
|
|
22
|
+
constructor(request: HTTPRequest<unknown>, response: HTTPResponse<unknown>);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Optional configuration applied during {@link HTTP.create}.
|
|
26
|
+
*/
|
|
27
|
+
export interface HTTPCreateOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Custom transport implementation overriding the default Fetch based transport.
|
|
30
|
+
*/
|
|
31
|
+
transport?: HTTPTransport;
|
|
32
|
+
/**
|
|
33
|
+
* Plugins that will be registered on every derived client instance.
|
|
34
|
+
*/
|
|
35
|
+
plugins?: HTTPPlugin[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Fluent HTTP client with pluggable transport, schema validation and hook support.
|
|
39
|
+
*/
|
|
40
|
+
export declare class HTTP {
|
|
41
|
+
private static sharedPlugins;
|
|
42
|
+
private transport;
|
|
43
|
+
private builder;
|
|
44
|
+
private meta;
|
|
45
|
+
private sharedPlugins;
|
|
46
|
+
private scopedPlugins;
|
|
47
|
+
private constructor();
|
|
48
|
+
/**
|
|
49
|
+
* Factory helper that prepares an {@link HTTP} instance with shared state.
|
|
50
|
+
*/
|
|
51
|
+
static create(options?: HTTPCreateOptions): HTTP;
|
|
52
|
+
/**
|
|
53
|
+
* Registers a plugin applied to every client created via {@link HTTP.create}.
|
|
54
|
+
*/
|
|
55
|
+
static registerSharedPlugin(plugin: HTTPPlugin): void;
|
|
56
|
+
/**
|
|
57
|
+
* Replaces the shared plugin registry used by {@link HTTP.create}.
|
|
58
|
+
*/
|
|
59
|
+
static setSharedPlugins(plugins: readonly HTTPPlugin[]): void;
|
|
60
|
+
/**
|
|
61
|
+
* Returns a copy of the currently registered shared plugins.
|
|
62
|
+
*/
|
|
63
|
+
static getSharedPlugins(): readonly HTTPPlugin[];
|
|
64
|
+
/**
|
|
65
|
+
* Registers a plugin that runs for every request executed by this instance and its clones.
|
|
66
|
+
*/
|
|
67
|
+
use(plugin: HTTPPlugin): this;
|
|
68
|
+
/**
|
|
69
|
+
* Returns a scoped clone with an additional plugin applied only to that clone.
|
|
70
|
+
*/
|
|
71
|
+
plugin(plugin: HTTPPlugin): HTTP;
|
|
72
|
+
/**
|
|
73
|
+
* Mutates the current instance to use a different transport implementation.
|
|
74
|
+
*/
|
|
75
|
+
useTransport(transport: HTTPTransport): this;
|
|
76
|
+
/**
|
|
77
|
+
* Produces a new client with an alternate transport without changing the original instance.
|
|
78
|
+
*/
|
|
79
|
+
withTransport(transport: HTTPTransport): HTTP;
|
|
80
|
+
/**
|
|
81
|
+
* Sets the base URL shared by subsequent requests.
|
|
82
|
+
*/
|
|
83
|
+
url(url: string): this;
|
|
84
|
+
/**
|
|
85
|
+
* Applies additional transport specific options to every request executed by this instance.
|
|
86
|
+
*/
|
|
87
|
+
sharedOptions(options: HTTPAdditionalOptions<unknown>): this;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a derived client with extra transport options applied only to that clone.
|
|
90
|
+
*/
|
|
91
|
+
withOptions(options: HTTPAdditionalOptions<unknown>): HTTP;
|
|
92
|
+
/**
|
|
93
|
+
* Registers an {@link AbortSignal} that will be forwarded to every request issued by this instance.
|
|
94
|
+
*/
|
|
95
|
+
sharedAbortSignal(signal: AbortSignal | null): this;
|
|
96
|
+
/**
|
|
97
|
+
* Returns a derived client configured with the provided {@link AbortSignal}.
|
|
98
|
+
*/
|
|
99
|
+
abortSignal(signal: AbortSignal | null): HTTP;
|
|
100
|
+
/**
|
|
101
|
+
* Configures automatic retries for this instance and all derived clients.
|
|
102
|
+
*/
|
|
103
|
+
sharedRetry(options: HTTPRetryOptions | null): this;
|
|
104
|
+
/**
|
|
105
|
+
* Returns a derived client with custom retry behaviour.
|
|
106
|
+
*/
|
|
107
|
+
retry(options: HTTPRetryOptions | null): HTTP;
|
|
108
|
+
/**
|
|
109
|
+
* Forces subsequent requests to return raw response streams without parsing.
|
|
110
|
+
*/
|
|
111
|
+
sharedStreamResponse(enabled: boolean): this;
|
|
112
|
+
/**
|
|
113
|
+
* Returns a derived client configured for streaming responses.
|
|
114
|
+
*/
|
|
115
|
+
streamResponse(enabled: boolean): HTTP;
|
|
116
|
+
/**
|
|
117
|
+
* Convenience helper that returns a clone configured for streaming responses.
|
|
118
|
+
*/
|
|
119
|
+
asStream(): HTTP;
|
|
120
|
+
/**
|
|
121
|
+
* Executes a GET request while preserving the raw response stream.
|
|
122
|
+
*/
|
|
123
|
+
stream<TResponse>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
124
|
+
/**
|
|
125
|
+
* Sets a shared timeout (in milliseconds) applied to every request from this instance.
|
|
126
|
+
*/
|
|
127
|
+
sharedTimeout(duration: number | null): this;
|
|
128
|
+
/**
|
|
129
|
+
* Returns a derived client with a per-request timeout in milliseconds.
|
|
130
|
+
*/
|
|
131
|
+
timeout(duration: number | null): HTTP;
|
|
132
|
+
/**
|
|
133
|
+
* Configures whether schema validation is required before resolving a response.
|
|
134
|
+
*/
|
|
135
|
+
requireSchema(required: boolean): this;
|
|
136
|
+
/**
|
|
137
|
+
* Returns a clone with overridden plain text handling mode.
|
|
138
|
+
*/
|
|
139
|
+
allowPlainText(allow: boolean): HTTP;
|
|
140
|
+
/**
|
|
141
|
+
* Sets plain text handling for the current instance and all future requests.
|
|
142
|
+
*/
|
|
143
|
+
sharedAllowPlainText(allow: boolean): this;
|
|
144
|
+
/**
|
|
145
|
+
* Adds path segments that will be included in every request.
|
|
146
|
+
*/
|
|
147
|
+
sharedRoute(...segments: (string | number | boolean)[]): this;
|
|
148
|
+
/**
|
|
149
|
+
* Executes a request using the provided method.
|
|
150
|
+
*
|
|
151
|
+
* Use this when the verb is dynamic (e.g. provided by a parameter). It
|
|
152
|
+
* behaves like calling {@link get}/{@link post}/{@link patch}, respecting any
|
|
153
|
+
* route/headers/body configured earlier in the chain.
|
|
154
|
+
*/
|
|
155
|
+
fetchWith<TResponse>(method: HTTPMethod | Lowercase<HTTPMethod>, options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
156
|
+
/**
|
|
157
|
+
* Returns a clone with additional path segments.
|
|
158
|
+
*/
|
|
159
|
+
route(...segments: (string | number | boolean)[]): HTTP;
|
|
160
|
+
/**
|
|
161
|
+
* Applies query serialization preferences to all future requests originating from this instance.
|
|
162
|
+
*/
|
|
163
|
+
sharedQueryFormat(options: QueryParamSerializationOptions): this;
|
|
164
|
+
/**
|
|
165
|
+
* Returns a derived client with custom query serialization that does not affect the source instance.
|
|
166
|
+
*/
|
|
167
|
+
queryFormat(options: QueryParamSerializationOptions): HTTP;
|
|
168
|
+
/**
|
|
169
|
+
* Registers schema validation for one or more status codes on the current instance.
|
|
170
|
+
*/
|
|
171
|
+
sharedSchema(parser: SchemaParser, ...codes: StatusCode[]): HTTP;
|
|
172
|
+
sharedSchema(parser: SchemaParser, ...ranges: {
|
|
173
|
+
from: StatusCode;
|
|
174
|
+
to: StatusCode;
|
|
175
|
+
}[]): HTTP;
|
|
176
|
+
/**
|
|
177
|
+
* Returns a clone with schema validation limited to the derived instance.
|
|
178
|
+
*/
|
|
179
|
+
schema(parser: SchemaParser, ...codes: StatusCode[]): HTTP;
|
|
180
|
+
schema(parser: SchemaParser, ...ranges: {
|
|
181
|
+
from: StatusCode;
|
|
182
|
+
to: StatusCode;
|
|
183
|
+
}[]): HTTP;
|
|
184
|
+
/**
|
|
185
|
+
* Sets a shared query parameter for all future requests.
|
|
186
|
+
*/
|
|
187
|
+
sharedParam(name: string, value: Record<string, unknown>): HTTP;
|
|
188
|
+
sharedParam(name: string, value: (string | number | boolean | null | undefined)[]): HTTP;
|
|
189
|
+
sharedParam(name: string, ...value: (string | number | boolean)[]): HTTP;
|
|
190
|
+
/**
|
|
191
|
+
* Derives a client with additional query parameters.
|
|
192
|
+
*/
|
|
193
|
+
param(name: string, value: Record<string, unknown>): HTTP;
|
|
194
|
+
param(name: string, value: (string | number | boolean | null | undefined)[]): HTTP;
|
|
195
|
+
param(name: string, ...value: (string | number | boolean)[]): HTTP;
|
|
196
|
+
/**
|
|
197
|
+
* Merges multiple shared query parameters into the instance.
|
|
198
|
+
*/
|
|
199
|
+
sharedParams(dict: Record<string, unknown>): this;
|
|
200
|
+
/**
|
|
201
|
+
* Derives a client with additional query parameters applied together.
|
|
202
|
+
*/
|
|
203
|
+
params(dict: Record<string, unknown>): HTTP;
|
|
204
|
+
/**
|
|
205
|
+
* Sets a shared request body used by every request from this instance.
|
|
206
|
+
*/
|
|
207
|
+
sharedData<T>(data: T | undefined): this;
|
|
208
|
+
/**
|
|
209
|
+
* Derives a client with a one-off request body.
|
|
210
|
+
*/
|
|
211
|
+
data<T>(data: T | undefined): HTTP;
|
|
212
|
+
/**
|
|
213
|
+
* Registers a header that will be resolved for every request on this instance.
|
|
214
|
+
*/
|
|
215
|
+
sharedHeader(name: string, value: string | number | boolean | null | (string | number | boolean)[] | (() => HeaderPrimitive | Promise<HeaderPrimitive>)): this;
|
|
216
|
+
/**
|
|
217
|
+
* Returns a clone with a header applied only to the resulting client.
|
|
218
|
+
*/
|
|
219
|
+
header(name: string, value: string | number | boolean | null | (string | number | boolean)[] | (() => HeaderPrimitive | Promise<HeaderPrimitive>)): HTTP;
|
|
220
|
+
/**
|
|
221
|
+
* Registers multiple shared headers for every downstream request.
|
|
222
|
+
*/
|
|
223
|
+
sharedHeaders(dict: Record<string, HeaderPrimitive | HeaderPrimitive[]>): this;
|
|
224
|
+
/**
|
|
225
|
+
* Returns a derived client with additional headers.
|
|
226
|
+
*/
|
|
227
|
+
headers(dict: Record<string, HeaderPrimitive | HeaderPrimitive[]>): HTTP;
|
|
228
|
+
/**
|
|
229
|
+
* Registers a request hook that runs before every execution on this instance.
|
|
230
|
+
*/
|
|
231
|
+
sharedOnSend(description: string, hook: RequestHook): this;
|
|
232
|
+
/**
|
|
233
|
+
* Returns a clone with a request hook used only for that clone.
|
|
234
|
+
*/
|
|
235
|
+
onSend(description: string, hook: RequestHook): HTTP;
|
|
236
|
+
/**
|
|
237
|
+
* Registers a response hook executed after every transport response.
|
|
238
|
+
*/
|
|
239
|
+
sharedOnReceive(description: string, hook: ResponseHook<unknown>): this;
|
|
240
|
+
/**
|
|
241
|
+
* Returns a derived client with a response hook limited to that client.
|
|
242
|
+
*/
|
|
243
|
+
onReceive(description: string, hook: ResponseHook<unknown>): HTTP;
|
|
244
|
+
/**
|
|
245
|
+
* Configures whether server errors (>=500) throw by default for every request.
|
|
246
|
+
*/
|
|
247
|
+
sharedThrowOnServerError(value: boolean): this;
|
|
248
|
+
/**
|
|
249
|
+
* Returns a derived client with custom server error behaviour.
|
|
250
|
+
*/
|
|
251
|
+
throwOnServerError(value: boolean): HTTP;
|
|
252
|
+
/**
|
|
253
|
+
* Executes a GET request using the current configuration.
|
|
254
|
+
*/
|
|
255
|
+
get<TResponse>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
256
|
+
/**
|
|
257
|
+
* Executes a POST request using the current configuration.
|
|
258
|
+
*/
|
|
259
|
+
post<TResponse>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
260
|
+
/**
|
|
261
|
+
* Executes a PUT request using the current configuration.
|
|
262
|
+
*/
|
|
263
|
+
put<TResponse>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
264
|
+
/**
|
|
265
|
+
* Executes a PATCH request using the current configuration.
|
|
266
|
+
*/
|
|
267
|
+
patch<TResponse>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
268
|
+
/**
|
|
269
|
+
* Executes a DELETE request using the current configuration.
|
|
270
|
+
*/
|
|
271
|
+
delete<TResponse>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
272
|
+
/**
|
|
273
|
+
* Executes a HEAD request using the current configuration.
|
|
274
|
+
*/
|
|
275
|
+
head<TResponse>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
276
|
+
/**
|
|
277
|
+
* Executes an OPTIONS request using the current configuration.
|
|
278
|
+
*/
|
|
279
|
+
options<TResponse>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
280
|
+
/**
|
|
281
|
+
* Executes a TRACE request using the current configuration.
|
|
282
|
+
*/
|
|
283
|
+
trace<TResponse>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
284
|
+
/**
|
|
285
|
+
* Executes a CONNECT request using the current configuration.
|
|
286
|
+
*/
|
|
287
|
+
connect<TResponse>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponse>>;
|
|
288
|
+
private execute;
|
|
289
|
+
private runRequestPlugins;
|
|
290
|
+
private runResponsePlugins;
|
|
291
|
+
private runErrorPlugins;
|
|
292
|
+
private runOnSendHooks;
|
|
293
|
+
private runOnReceiveHooks;
|
|
294
|
+
private validateResponse;
|
|
295
|
+
private buildResponse;
|
|
296
|
+
private plugins;
|
|
297
|
+
private shouldRetryRequest;
|
|
298
|
+
private delayRetry;
|
|
299
|
+
private derive;
|
|
300
|
+
}
|