@zthun/webigail-http 5.0.1 → 5.0.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.
@@ -1,37 +1,239 @@
1
+ /**
2
+ * Represents an available method for an http invocation.
3
+ */
1
4
  export declare enum ZHttpMethod {
5
+ /**
6
+ * GET
7
+ *
8
+ * Used for reads
9
+ */
2
10
  Get = "GET",
11
+ /**
12
+ * PUT
13
+ *
14
+ * Used for updates and can combine creates.
15
+ */
3
16
  Put = "PUT",
17
+ /**
18
+ * POST
19
+ *
20
+ * Use for create.
21
+ */
4
22
  Post = "POST",
23
+ /**
24
+ * DELETE.
25
+ *
26
+ * Used for....delete..duh.
27
+ */
5
28
  Delete = "DELETE",
29
+ /**
30
+ * PATCH.
31
+ *
32
+ * Used for updates but only
33
+ * partials of objects.
34
+ */
6
35
  Patch = "PATCH",
36
+ /**
37
+ * OPTIONS
38
+ *
39
+ * Used to retrieve the available methods and
40
+ * accessors for a single api. Normally used
41
+ * by the browser.
42
+ */
7
43
  Options = "OPTIONS",
44
+ /**
45
+ * HEAD
46
+ *
47
+ * Used for metadata.
48
+ */
8
49
  Head = "HEAD"
9
50
  }
51
+ /**
52
+ * Represents a http request.
53
+ */
10
54
  export interface IZHttpRequest<TBody = any> {
55
+ /**
56
+ * The method, or verb, to invoke the request with.
57
+ */
11
58
  method: ZHttpMethod;
59
+ /**
60
+ * The url to target.
61
+ */
12
62
  url: string;
63
+ /**
64
+ * The post body.
65
+ *
66
+ * Only should really be used for POST style
67
+ * calls which accept a body.
68
+ */
13
69
  body?: TBody;
70
+ /**
71
+ * Request headers.
72
+ */
14
73
  headers?: Record<string, string>;
74
+ /**
75
+ * The timeout before the rest method fails
76
+ */
15
77
  timeout?: number;
16
78
  }
79
+ /**
80
+ * Represents a builder for an http request.
81
+ */
17
82
  export declare class ZHttpRequestBuilder<TBody = any> {
18
83
  private _request;
84
+ /**
85
+ * Duplicates a request, keeping it's structure intact.
86
+ *
87
+ * The underlying headers will be duplicated, but everything
88
+ * else will be a shallow copy to preserve the body in the
89
+ * case that it is a blob or other binary structure.
90
+ *
91
+ * @param other -
92
+ * The request to duplicate.
93
+ *
94
+ * @returns
95
+ * The duplicated object.
96
+ */
19
97
  static duplicate<TBody>(other: IZHttpRequest<TBody>): IZHttpRequest<TBody>;
98
+ /**
99
+ * Initializes a new instance of this object.
100
+ */
20
101
  constructor();
102
+ /**
103
+ * Sets the method.
104
+ *
105
+ * @param method -
106
+ * The method to set.
107
+ * @param body -
108
+ * The post, put, or patch body.
109
+ *
110
+ * @returns
111
+ * This object.
112
+ */
21
113
  private _method;
114
+ /**
115
+ * Constructs a get request.
116
+ *
117
+ * @returns
118
+ * This object.
119
+ */
22
120
  get(): this;
121
+ /**
122
+ * Constructs a post request.
123
+ *
124
+ * @returns
125
+ * This object.
126
+ */
23
127
  post(body?: TBody): this;
128
+ /**
129
+ * Constructs a put request.
130
+ *
131
+ * @returns
132
+ * This object.
133
+ */
24
134
  put(body?: TBody): this;
135
+ /**
136
+ * Constructs a delete request.
137
+ *
138
+ * @returns
139
+ * This object.
140
+ */
25
141
  delete(): this;
142
+ /**
143
+ * Constructs a patch request.
144
+ *
145
+ * @returns
146
+ * This object.
147
+ */
26
148
  patch(body?: TBody): this;
149
+ /**
150
+ * Constructs a options request.
151
+ *
152
+ * @returns
153
+ * This object.
154
+ */
27
155
  options(): this;
156
+ /**
157
+ * Constructs a head request.
158
+ *
159
+ * @returns
160
+ * This object.
161
+ */
28
162
  head(): this;
163
+ /**
164
+ * Sets the url to make the request from.
165
+ *
166
+ * @param url -
167
+ * The url to make the request to.
168
+ *
169
+ * @returns
170
+ * This object.
171
+ */
29
172
  url(url: string): this;
173
+ /**
174
+ * Sets the timeout for the url.
175
+ *
176
+ * @param ms -
177
+ * The total number of milliseconds to wait.
178
+ *
179
+ * @returns
180
+ * The object.
181
+ */
30
182
  timeout(ms: number): this;
183
+ /**
184
+ * Sets the headers.
185
+ *
186
+ * @param headers -
187
+ * The headers to set.
188
+ *
189
+ * @returns
190
+ * This object.
191
+ */
31
192
  headers(headers: Record<string, string>): this;
193
+ /**
194
+ * Sets an individual header.
195
+ *
196
+ * @param key -
197
+ * The header key to set.
198
+ * @param value -
199
+ * The value to set.
200
+ *
201
+ * @returns
202
+ * This object.
203
+ */
32
204
  header(key: string, value: string | number | boolean | null): this;
205
+ /**
206
+ * Sets the content type header.
207
+ *
208
+ * @param type -
209
+ * The content mime type.
210
+ *
211
+ * @returns
212
+ * This object.
213
+ */
33
214
  content(type: string): this;
215
+ /**
216
+ * Sets the content type to json.
217
+ *
218
+ * @returns
219
+ * This object.
220
+ */
34
221
  json: () => this;
222
+ /**
223
+ * Copies other to this object.
224
+ *
225
+ * @param other -
226
+ * The request to copy.
227
+ *
228
+ * @returns
229
+ * This object.
230
+ */
35
231
  copy(other: IZHttpRequest): this;
232
+ /**
233
+ * Returns the constructed request.
234
+ *
235
+ * @returns
236
+ * The constructed request.
237
+ */
36
238
  build(): IZHttpRequest;
37
239
  }
@@ -1,32 +1,185 @@
1
+ /**
2
+ * This class of status code is intended for situations in which the error seems to have been caused by the client.
3
+ *
4
+ * Except when responding to a HEAD request, the server should include an entity containing an explanation
5
+ * of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable
6
+ * to any request method. User agents should display any included entity to the user.
7
+ */
1
8
  export declare enum ZHttpCodeClient {
9
+ /**
10
+ * The server cannot or will not process the request due to an apparent client error
11
+ * (e.g., malformed request syntax, size too large, invalid request message framing,
12
+ * or deceptive request routing).
13
+ */
2
14
  BadRequest = 400,
15
+ /**
16
+ * Similar to 403 Forbidden, but specifically for use when authentication is required and has failed
17
+ * or has not yet been provided.
18
+ *
19
+ * The response must include a WWW-Authenticate header field containing a challenge applicable to the
20
+ * requested resource. See Basic access authentication and Digest access authentication. 401
21
+ * semantically means "unauthenticated",[35] i.e. the user does not have the necessary credentials.
22
+ *
23
+ * Note: Some sites issue HTTP 401 when an IP address is banned from the website (usually the website domain)
24
+ * and that specific address is refused permission to access a website.
25
+ */
3
26
  Unauthorized = 401,
27
+ /**
28
+ * Reserved for future use.
29
+ *
30
+ * The original intention was that this code might be used as part of some form of digital cash or
31
+ * micro-payment scheme, as proposed for example by GNU Taler, but that has not yet happened, and
32
+ * this code is not usually used. Google Developers API uses this status if a particular developer
33
+ * has exceeded the daily limit on requests
34
+ */
4
35
  PaymentRequired = 402,
36
+ /**
37
+ * The request was valid, but the server is refusing action.
38
+ *
39
+ * The user might not have the necessary permissions for a resource, or may need an account of some sort.
40
+ */
5
41
  Forbidden = 403,
42
+ /**
43
+ * The requested resource could not be found but may be available in the future.
44
+ *
45
+ * Subsequent requests by the client are permissible.
46
+ */
6
47
  NotFound = 404,
48
+ /**
49
+ * A request method is not supported for the requested resource; for example, a GET
50
+ * request on a form that requires data to be presented via POST, or a PUT request on
51
+ * a read-only resource.
52
+ */
7
53
  MethodNotAllowed = 405,
54
+ /**
55
+ * The requested resource is capable of generating only content not acceptable according
56
+ * to the Accept headers sent in the request.
57
+ */
8
58
  NotAcceptable = 406,
59
+ /**
60
+ * The client must first authenticate itself with the proxy.
61
+ */
9
62
  ProxyAuthenticationRequired = 407,
63
+ /**
64
+ * The server timed out waiting for the request.
65
+ *
66
+ * According to HTTP specifications: "The client did not produce a request within the
67
+ * time that the server was prepared to wait. The client MAY repeat the request without
68
+ * modifications at any later time.
69
+ */
10
70
  RequestTimeout = 408,
71
+ /**
72
+ * Indicates that the request could not be processed because of conflict in the request, such
73
+ * as an edit conflict between multiple simultaneous updates.
74
+ */
11
75
  Conflict = 409,
76
+ /**
77
+ * Indicates that the resource requested is no longer available and will not be available again.
78
+ *
79
+ * This should be used when a resource has been intentionally removed and the resource should be
80
+ * purged. Upon receiving a 410 status code, the client should not request the resource in the
81
+ * future. Clients such as search engines should remove the resource from their indices. Most use
82
+ * cases do not require clients and search engines to purge the resource, and a "404 Not Found" may
83
+ * be used instead.
84
+ */
12
85
  Gone = 410,
86
+ /**
87
+ * The request did not specify the length of its content, which is required by the requested resource.
88
+ */
13
89
  LengthRequired = 411,
90
+ /**
91
+ * The server does not meet one of the preconditions that the requester put on the request.
92
+ */
14
93
  PreconditionFailed = 412,
94
+ /**
95
+ * The request is larger than the server is willing or able to process. Previously called
96
+ * "Request Entity Too Large".
97
+ */
15
98
  PayloadTooLarge = 413,
99
+ /**
100
+ * The URI provided was too long for the server to process.
101
+ *
102
+ * Often the result of too much data being encoded as a query-string of
103
+ * a GET request, in which case it should be converted to a POST request.
104
+ * Called "Request-URI Too Long" previously.
105
+ */
16
106
  URITooLong = 414,
107
+ /**
108
+ * The request entity has a media type which the server or resource does not support.
109
+ *
110
+ * For example, the client uploads an image as image/svg+xml, but the server requires that
111
+ * images use a different format.
112
+ */
17
113
  UnsupportedMediaType = 415,
114
+ /**
115
+ * The client has asked for a portion of the file (byte serving), but the server cannot supply that portion.
116
+ *
117
+ * For example, if the client asked for a part of the file that lies beyond the end of the file.
118
+ * Called "Requested Range Not Satisfiable" previously.
119
+ */
18
120
  RangeNotSatisfiable = 416,
121
+ /**
122
+ * The server cannot meet the requirements of the Expect request-header field.
123
+ */
19
124
  ExpectationFailed = 417,
125
+ /**
126
+ * This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper
127
+ * Text Coffee Pot Control Protocol, and is not expected to be implemented by actual HTTP servers.
128
+ *
129
+ * The RFC specifies this code should be returned by teapots requested to brew coffee. This HTTP
130
+ * status is used as an Easter egg in some websites, including Google.com.
131
+ */
20
132
  ImATeapot = 418,
133
+ /**
134
+ * The request was directed at a server that is not able to produce a response[53] (for example because of connection reuse).
135
+ */
21
136
  MisdirectedRequest = 421,
137
+ /**
138
+ * The request was well-formed but was unable to be followed due to semantic errors.
139
+ */
22
140
  UnProcessableEntity = 422,
141
+ /**
142
+ * The resource that is being accessed is locked.
143
+ */
23
144
  Locked = 423,
145
+ /**
146
+ * The request failed because it depended on another request and that request failed.
147
+ */
24
148
  FailedDependency = 424,
149
+ /**
150
+ * The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.
151
+ */
25
152
  UpgradeRequired = 426,
153
+ /**
154
+ * The origin server requires the request to be conditional.
155
+ *
156
+ * Intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it,
157
+ * and PUTs it back to the server, when meanwhile a third party has modified the state on the server,
158
+ * leading to a conflict.
159
+ */
26
160
  PreconditionRequired = 428,
161
+ /**
162
+ * The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes.
163
+ */
27
164
  TooManyRequests = 429,
165
+ /**
166
+ * The server is unwilling to process the request because either an individual header field, or all the
167
+ * header fields collectively, are too large.[
168
+ */
28
169
  RequestHeaderFieldsTooLarge = 431,
170
+ /**
171
+ * A server operator has received a legal demand to deny access to a resource or to a set of resources that includes the
172
+ * requested resource.
173
+ *
174
+ * The code 451 was chosen as a reference to the novel Fahrenheit 451.
175
+ */
29
176
  UnavailableForLegalReasons = 451
30
177
  }
178
+ /**
179
+ * English friendly names of the codes.
180
+ */
31
181
  export declare const ZHttpCodeClientNames: Record<ZHttpCodeClient, string>;
182
+ /**
183
+ * English friendly descriptions of HttpClientCodes
184
+ */
32
185
  export declare const ZHttpCodeClientDescriptions: Record<ZHttpCodeClient, string>;
@@ -1,8 +1,47 @@
1
+ /**
2
+ * An informational response indicates that the request was received and understood.
3
+ *
4
+ * It is issued on a provisional basis while request processing continues. It alerts the
5
+ * client to wait for a final response. The message consists only of the status line and
6
+ * optional header fields, and is terminated by an empty line. As the HTTP/1.0 standard
7
+ * did not define any 1xx status codes, servers must not[note 1] send a 1xx response to
8
+ * an HTTP/1.0 compliant client except under experimental conditions.[4]
9
+ */
1
10
  export declare enum ZHttpCodeInformationalResponse {
11
+ /**
12
+ * The server has received the request headers and the client should proceed to send the
13
+ * request body (in the case of a request for which a body needs to be sent; for example, a
14
+ * POST request).
15
+ *
16
+ * Sending a large request body to a server after a request has been rejected
17
+ * for inappropriate headers would be inefficient. To have a server check the request's headers,
18
+ * a client must send Expect: 100-continue as a header in its initial request and receive a 100 Continue status
19
+ * code in response before sending the body. If the client receives an error code such as 403 (Forbidden) or 405
20
+ * (Method Not Allowed) then it shouldn't send the request's body. The response 417 Expectation Failed indicates
21
+ * that the request should be repeated without the Expect header as it indicates that the server doesn't support
22
+ * expectations (this is the case, for example, of HTTP/1.0 servers).
23
+ */
2
24
  Continue = 100,
25
+ /**
26
+ * The requester has asked the server to switch protocols and the server has agreed to do so.
27
+ */
3
28
  SwitchingProtocols = 101,
29
+ /**
30
+ * A WebDAV request may contain many sub-requests involving file operations, requiring a long time to
31
+ * complete the request. This code indicates that the server has received and is processing the request,
32
+ * but no response is available yet. This prevents the client from timing out and assuming the request was lost.
33
+ */
4
34
  Processing = 102,
35
+ /**
36
+ * Used to return some response headers before final HTTP message.
37
+ */
5
38
  EarlyHints = 103
6
39
  }
40
+ /**
41
+ * English friendly names of the codes.
42
+ */
7
43
  export declare const ZHttpCodeInformationalResponseNames: Record<ZHttpCodeInformationalResponse, string>;
44
+ /**
45
+ * English friendly descriptions of the codes.
46
+ */
8
47
  export declare const ZHttpCodeInformationalResponseDescriptions: Record<ZHttpCodeInformationalResponse, string>;
@@ -1,13 +1,80 @@
1
+ /**
2
+ * This class of status code indicates the client must take additional action to complete the request.
3
+ *
4
+ * Many of these status codes are used in URL redirection. A user agent may carry out the additional
5
+ * action with no user interaction only if the method used in the second request is GET or HEAD.
6
+ * A user agent may automatically redirect a request. A user agent should detect and intervene
7
+ * to prevent cyclical redirects.
8
+ */
1
9
  export declare enum ZHttpCodeRedirection {
10
+ /**
11
+ * Indicates multiple options for the resource from which the client may choose
12
+ * (via agent-driven content negotiation).
13
+ *
14
+ * For example, this code could be used to present multiple video format options, to
15
+ * list files with different filename extensions, or to suggest word-sense disambiguation.
16
+ */
2
17
  MultipleChoices = 300,
18
+ /**
19
+ * This and all future requests should be directed to the given URI.
20
+ */
3
21
  MovedPermanently = 301,
22
+ /**
23
+ * Tells the client to look at (browse to) another url. 302 has been superseded by 303 and 307.
24
+ * This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945)
25
+ * required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"),
26
+ * [22] but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1
27
+ * added status codes 303 and 307 to distinguish between the two behaviors.[23] However, some Web applications
28
+ * and frameworks use the 302 status code as if it were the 303.
29
+ */
4
30
  Found = 302,
31
+ /**
32
+ * The response to the request can be found under another URI using the GET method.
33
+ *
34
+ * When received in response to a POST (or PUT/DELETE), the client should presume
35
+ * that the server has received the data and should issue a new GET request to
36
+ * the given URI.
37
+ */
5
38
  SeeOther = 303,
39
+ /**
40
+ * Indicates that the resource has not been modified since the version specified by the request headers
41
+ * If-Modified-Since or If-None-Match. In such case, there is no need to retransmit the resource since
42
+ * the client still has a previously-downloaded copy.
43
+ */
6
44
  NotModified = 304,
45
+ /**
46
+ * The requested resource is available only through a proxy, the address for which is provided in the response.
47
+ *
48
+ * Many HTTP clients (such as Mozilla[27] and Internet Explorer) do not correctly handle responses with
49
+ * this status code, primarily for security reasons.
50
+ */
7
51
  UseProxy = 305,
52
+ /**
53
+ * No longer used. Originally meant "Subsequent requests should use the specified proxy.
54
+ */
8
55
  SwitchProxy = 306,
56
+ /**
57
+ * In this case, the request should be repeated with another URI; however, future requests
58
+ * should still use the original URI.
59
+ *
60
+ * In contrast to how 302 was historically implemented, the request method is not allowed to be
61
+ * changed when reissuing the original request. For example, a POST request should be repeated using
62
+ * another POST request.
63
+ */
9
64
  TemporaryRedirect = 307,
65
+ /**
66
+ * The request and all future requests should be repeated using another URI.
67
+ *
68
+ * 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change.
69
+ * So, for example, submitting a form to a permanently redirected resource may continue smoothly.
70
+ */
10
71
  PermanentRedirect = 308
11
72
  }
73
+ /**
74
+ * English friendly names of the redirection codes.
75
+ */
12
76
  export declare const ZHttpCodeRedirectionNames: Record<ZHttpCodeRedirection, string>;
77
+ /**
78
+ * English friendly descriptions of the redirection codes.
79
+ */
13
80
  export declare const ZHttpCodeRedirectionDescriptions: Record<ZHttpCodeRedirection, string>;
@@ -1,15 +1,73 @@
1
+ /**
2
+ * The server failed to fulfil a request.
3
+ *
4
+ * Response status codes beginning with the digit "5" indicate
5
+ * cases in which the server is aware that it has encountered an
6
+ * error or is otherwise incapable of performing the request. Except
7
+ * when responding to a HEAD request, the server should include an entity
8
+ * containing an explanation of the error situation, and indicate whether it
9
+ * is a temporary or permanent condition. Likewise, user agents should
10
+ * display any included entity to the user. These response codes are applicable
11
+ * to any request method.
12
+ */
1
13
  export declare enum ZHttpCodeServer {
14
+ /**
15
+ * A generic error message, given when an unexpected condition was encountered
16
+ * and no more specific message is suitable.
17
+ */
2
18
  InternalServerError = 500,
19
+ /**
20
+ * The server either does not recognize the request method, or it lacks the ability to
21
+ * fulfil the request. Usually this implies future availability (e.g., a new feature of
22
+ * a web-service API).
23
+ */
3
24
  NotImplemented = 501,
25
+ /**
26
+ * The server was acting as a gateway or proxy and received an invalid response
27
+ * from the upstream server.
28
+ */
4
29
  BadGateway = 502,
30
+ /**
31
+ * The server is currently unavailable (because it is overloaded or down for maintenance).
32
+ * Generally, this is a temporary state.
33
+ */
5
34
  ServiceUnavailable = 503,
35
+ /**
36
+ * The server was acting as a gateway or proxy and did not receive a timely response from
37
+ * the upstream server.
38
+ */
6
39
  GatewayTimeout = 504,
40
+ /**
41
+ * The server does not support the HTTP protocol version used in the request.
42
+ */
7
43
  HttpVersionNotSupported = 505,
44
+ /**
45
+ * Transparent content negotiation for the request results in a circular reference.
46
+ */
8
47
  VariantAlsoNegotiates = 506,
48
+ /**
49
+ * The server is unable to store the representation needed to complete the request.
50
+ */
9
51
  InsufficientStorage = 507,
52
+ /**
53
+ * The server detected an infinite loop while processing the request.
54
+ */
10
55
  LoopDetected = 508,
56
+ /**
57
+ * Further extensions to the request are required for the server to fulfil it.
58
+ */
11
59
  NotExtended = 510,
60
+ /**
61
+ * The client needs to authenticate to gain network access. Intended for use by
62
+ * intercepting proxies used to control access to the network.
63
+ */
12
64
  NetworkAuthenticationRequired = 511
13
65
  }
66
+ /**
67
+ * English friendly names of the server codes.
68
+ */
14
69
  export declare const ZHttpCodeServerNames: Record<ZHttpCodeServer, string>;
70
+ /**
71
+ * English friendly names of the server codes.
72
+ */
15
73
  export declare const ZHttpCodeServerDescriptions: Record<ZHttpCodeServer, string>;
@@ -1,14 +1,71 @@
1
+ /**
2
+ * This class of status codes indicates the action requested by
3
+ * the client was received, understood and accepted.
4
+ */
1
5
  export declare enum ZHttpCodeSuccess {
6
+ /**
7
+ * Standard response for successful HTTP requests.
8
+ *
9
+ * The actual response will depend on the request method used. In a GET
10
+ * request, the response will contain an entity corresponding to the
11
+ * requested resource. In a POST request, the response will contain an
12
+ * entity describing or containing the result of the action.
13
+ */
2
14
  OK = 200,
15
+ /**
16
+ * The request has been fulfilled, resulting in the creation of a new resource.
17
+ */
3
18
  Created = 201,
19
+ /**
20
+ * The request has been accepted for processing, but the processing has not been completed.
21
+ *
22
+ * The request might or might not be eventually acted upon, and may be disallowed when processing occurs.
23
+ */
4
24
  Accepted = 202,
25
+ /**
26
+ * The server is a transforming proxy (e.g. a Web accelerator) that received a 200 OK from its origin,
27
+ * but is returning a modified version of the origin's response.
28
+ */
5
29
  NonAuthoritativeInformation = 203,
30
+ /**
31
+ * The server successfully processed the request and is not returning any content.
32
+ */
6
33
  NoContent = 204,
34
+ /**
35
+ * The server successfully processed the request, but is not returning any content.
36
+ *
37
+ * Unlike a 204 response, this response requires that the requester reset the document view.
38
+ */
7
39
  ResetContent = 205,
40
+ /**
41
+ * The server is delivering only part of the resource (byte serving) due to a range header
42
+ * sent by the client.
43
+ *
44
+ * The range header is used by HTTP clients to enable resuming of interrupted downloads, or
45
+ * split a download into multiple simultaneous streams.
46
+ */
8
47
  PartialContent = 206,
48
+ /**
49
+ * The message body that follows is by default an XML message and can contain a number of separate
50
+ * response codes, depending on how many sub-requests were made.
51
+ */
9
52
  MultiStatus = 207,
53
+ /**
54
+ * The members of a DAV binding have already been enumerated in a preceding part of the
55
+ * response, and are not being included again.
56
+ */
10
57
  AlreadyReported = 208,
58
+ /**
59
+ * The server has fulfilled a request for the resource, and the response is a representation of the result
60
+ * of one or more instance-manipulations applied to the current instance.
61
+ */
11
62
  IMUsed = 226
12
63
  }
64
+ /**
65
+ * Friendly english names of success codes.
66
+ */
13
67
  export declare const ZHttpCodeSuccessNames: Record<ZHttpCodeSuccess, string>;
68
+ /**
69
+ * Friendly english descriptions of success codes.
70
+ */
14
71
  export declare const ZHttpCodeSuccessDescriptions: Record<ZHttpCodeSuccess, string>;
@@ -3,21 +3,93 @@ import { ZHttpCodeInformationalResponse } from './http-code-informational-respon
3
3
  import { ZHttpCodeRedirection } from './http-code-redirection.mjs';
4
4
  import { ZHttpCodeServer } from './http-code-server.mjs';
5
5
  import { ZHttpCodeSuccess } from './http-code-success.mjs';
6
+ /**
7
+ * Represents a category of http code.
8
+ */
6
9
  export type ZHttpCode = ZHttpCodeInformationalResponse | ZHttpCodeSuccess | ZHttpCodeRedirection | ZHttpCodeClient | ZHttpCodeServer;
10
+ /**
11
+ * Represents the category name for an http code.
12
+ */
7
13
  export declare enum ZHttpCodeCategory {
14
+ /**
15
+ * Error codes 100-199.
16
+ */
8
17
  InformationalResponse = "Informational Response",
18
+ /**
19
+ * Error codes 200-299.
20
+ */
9
21
  Success = "Success",
22
+ /**
23
+ * Error codes 300-399.
24
+ */
10
25
  Redirection = "Redirection",
26
+ /**
27
+ * Error codes 400-499.
28
+ */
11
29
  Client = "Client Error",
30
+ /**
31
+ * Error codes 500-599.
32
+ */
12
33
  Server = "Server Error"
13
34
  }
35
+ /**
36
+ * Represents a classification of severity for a code.
37
+ */
14
38
  export declare enum ZHttpCodeSeverity {
39
+ /**
40
+ * Covers information response (100-199) and redirection codes (300-399).
41
+ */
15
42
  Info = "info",
43
+ /**
44
+ * Covers the success codes (200-299)
45
+ */
16
46
  Success = "success",
47
+ /**
48
+ * Covers client errors (400-499).
49
+ */
17
50
  Warning = "warning",
51
+ /**
52
+ * Covers server errors (500-599).
53
+ */
18
54
  Error = "error"
19
55
  }
56
+ /**
57
+ * Gets the english friendly name of a code.
58
+ *
59
+ * @param code -
60
+ * The code to retrieve the name for.
61
+ *
62
+ * @returns
63
+ * The english friendly name of a code.
64
+ */
20
65
  export declare function getHttpCodeName(code: ZHttpCode): string;
66
+ /**
67
+ * Gets the english friendly description of a code.
68
+ *
69
+ * @param code -
70
+ * The code to retrieve the description for.
71
+ *
72
+ * @returns
73
+ * The english friendly description of a code.
74
+ */
21
75
  export declare function getHttpCodeDescription(code: ZHttpCode): any;
76
+ /**
77
+ * Gets the severity of a code.
78
+ *
79
+ * @param code -
80
+ * The severity of a code.
81
+ *
82
+ * @returns
83
+ * The severity of a code.
84
+ */
22
85
  export declare function getHttpCodeSeverity(code: ZHttpCode): ZHttpCodeSeverity;
86
+ /**
87
+ * Gets the category of a code.
88
+ *
89
+ * @param code -
90
+ * The category of a code.
91
+ *
92
+ * @returns
93
+ * The code category.
94
+ */
23
95
  export declare function getHttpCodeCategory(code: ZHttpCode): ZHttpCodeCategory;
@@ -1,14 +1,68 @@
1
1
  import { ZHttpCode } from './http-code.mjs';
2
+ /**
3
+ * Represents a result from an http request.
4
+ */
2
5
  export interface IZHttpResult<TResult = any> {
6
+ /**
7
+ * The status code.
8
+ */
3
9
  status: ZHttpCode;
10
+ /**
11
+ * The set of headers that was returned.
12
+ */
4
13
  headers: Record<string, any>;
14
+ /**
15
+ * The actual body result of the invocation.
16
+ */
5
17
  data: TResult;
6
18
  }
19
+ /**
20
+ * Represents a builder for an IZHttpResult class.
21
+ */
7
22
  export declare class ZHttpResultBuilder<TData = any> {
8
23
  private _result;
24
+ /**
25
+ * Initializes a new instance of this object.
26
+ *
27
+ * @param data -
28
+ * The data result.
29
+ */
9
30
  constructor(data: TData);
31
+ /**
32
+ * Sets the data.
33
+ *
34
+ * @param data -
35
+ * The data to set.
36
+ *
37
+ * @returns
38
+ * This object.
39
+ */
10
40
  data(data: TData): this;
41
+ /**
42
+ * Sets the status code and the english description.
43
+ *
44
+ * @param code -
45
+ * The code to set.
46
+ *
47
+ * @returns
48
+ * This object.
49
+ */
11
50
  status(code: ZHttpCode): this;
51
+ /**
52
+ * Sets the return headers.
53
+ *
54
+ * @param headers -
55
+ * The headers to set.
56
+ *
57
+ * @returns
58
+ * This object.
59
+ */
12
60
  headers(headers?: Record<string, any>): this;
61
+ /**
62
+ * Returns the built up result.
63
+ *
64
+ * @returns
65
+ * A shallow copy of the built up result.
66
+ */
13
67
  build(): IZHttpResult;
14
68
  }
@@ -1,8 +1,32 @@
1
1
  import { IZHttpRequest, ZHttpMethod } from '../request/http-request.mjs';
2
2
  import { IZHttpResult } from '../result/http-result.mjs';
3
3
  import { IZHttpService } from './http-service.mjs';
4
+ /**
5
+ * Represents a mock http service that can be useful for demos,
6
+ * testing, and pre-api implementations.
7
+ */
4
8
  export declare class ZHttpServiceMock implements IZHttpService {
5
9
  private _mapping;
10
+ /**
11
+ * Sets the result of a given endpoint.
12
+ *
13
+ * @param endpoint -
14
+ * The endpoint to set.
15
+ * @param verb -
16
+ * The endpoint verb to respond to.
17
+ * @param invoke -
18
+ * The result method. If this is falsy, then the endpoint is removed.
19
+ */
6
20
  set<TResult = any>(endpoint: string, verb: ZHttpMethod, invoke: IZHttpResult<TResult> | ((req: IZHttpRequest) => IZHttpResult<TResult> | Promise<IZHttpResult<TResult>>)): void;
21
+ /**
22
+ * Invokes the request given the allowed api implementations.
23
+ *
24
+ * @param req -
25
+ * The request that has been made.
26
+ *
27
+ * @returns
28
+ * A promise that resolves with the given result if the status code is less than 400.
29
+ * Any status code above 400 will result in a rejected promise.
30
+ */
7
31
  request<TResult = any, TBody = any>(req: IZHttpRequest<TBody>): Promise<IZHttpResult<TResult>>;
8
32
  }
@@ -1,8 +1,31 @@
1
1
  import { IZHttpRequest } from '../request/http-request.mjs';
2
2
  import { IZHttpResult } from '../result/http-result.mjs';
3
+ /**
4
+ * Represents a service that makes http invocations.
5
+ */
3
6
  export interface IZHttpService {
7
+ /**
8
+ * Makes the request.
9
+ *
10
+ * @param req -
11
+ * The request object to make.
12
+ *
13
+ * @returns
14
+ * A promise that resolves the request if a 200 code is returned, or
15
+ * rejects if a 400 or 500 code is returned. The request is
16
+ * rerouted if a 300 code is returned.
17
+ */
4
18
  request<TResult = any, TBody = any>(req: IZHttpRequest<TBody>): Promise<IZHttpResult<TResult>>;
5
19
  }
20
+ /**
21
+ * Represents an axios based implementation of the http service.
22
+ */
6
23
  export declare class ZHttpService implements IZHttpService {
24
+ /**
25
+ * Invokes the request with a real http service.
26
+ *
27
+ * @param req -
28
+ * The request information to make.
29
+ */
7
30
  request<TResult = any, TBody = any>(req: IZHttpRequest<TBody>): Promise<IZHttpResult<TResult>>;
8
31
  }
@@ -1,2 +1,28 @@
1
+ /**
2
+ * A method that determines if an object conforms to a Request BodyInit shape.
3
+ *
4
+ * See the BodyInit interface for more information about the possible
5
+ * shapes.
6
+ *
7
+ * @param obj -
8
+ * The object to test.
9
+ *
10
+ * @returns
11
+ * True if obj is a BodyInit shape, false otherwise.
12
+ */
1
13
  export declare function isBodyInit(obj: any): obj is BodyInit;
14
+ /**
15
+ * A helper method that converts an object to a BodyInit.
16
+ *
17
+ * If obj is not a BodyInit supported object, then it will
18
+ * simply be converted to JSON.
19
+ *
20
+ * @param obj -
21
+ * The object to convert.
22
+ *
23
+ * @returns
24
+ * Obj as a body init serialization. If obj is not
25
+ * compatible with a BodyInit shape, then it is converted
26
+ * to JSON.
27
+ */
2
28
  export declare function toBodyInit(obj: any): BodyInit;
@@ -1 +1,7 @@
1
+ /**
2
+ * A helper method that takes an HTTP Fetch Response and converts the body data based on its
3
+ * content type.
4
+ *
5
+ * This will favor a blob as the default type.
6
+ */
1
7
  export declare function fromContentType(res: Response): Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zthun/webigail-http",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "description": "Http service implementation with an equivalent mock for testing.",
5
5
  "author": "Anthony Bonta",
6
6
  "license": "MIT",
@@ -25,19 +25,21 @@
25
25
  "access": "public"
26
26
  },
27
27
  "dependencies": {
28
- "@zthun/webigail-url": "^5.0.1",
28
+ "@zthun/webigail-url": "^5.0.3",
29
29
  "cross-fetch": "^4.1.0",
30
- "lodash-es": "^4.17.21"
30
+ "lodash-es": "^4.17.22"
31
31
  },
32
32
  "devDependencies": {
33
- "@zthun/janitor-build-config": "^19.4.2",
34
- "msw": "^2.11.6",
35
- "vite": "^7.1.12",
36
- "vitest": "^4.0.5"
33
+ "@zthun/janitor-build-config": "^19.5.4",
34
+ "@zthun/janitor-ts-config": "^19.5.3",
35
+ "msw": "^2.12.7",
36
+ "typescript": "~5.9.3",
37
+ "vite": "^7.3.0",
38
+ "vitest": "^4.0.16"
37
39
  },
38
40
  "files": [
39
41
  "dist"
40
42
  ],
41
43
  "sideEffects": false,
42
- "gitHead": "bbaa81daa0d781b809ea5b4eb4395c7bac635436"
44
+ "gitHead": "72e9e39897db1a5105194b6b40d5060e537a0a55"
43
45
  }