@stacksjs/http 0.74.27 → 0.74.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +96 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fetch` wrapper that aborts after `timeoutMs` and honors `Retry-After`
|
|
3
|
+
* on 429/503 responses with exponential backoff.
|
|
4
|
+
*
|
|
5
|
+
* Platform `fetch()` has no timeout — a misbehaving upstream that accepts
|
|
6
|
+
* the connection but never sends bytes leaves the caller hanging forever.
|
|
7
|
+
* Worse, every driver (Stripe webhooks, Twilio, AI providers) shares the
|
|
8
|
+
* same code path, so one slow upstream cascades into stalled queue
|
|
9
|
+
* workers. This wrapper keeps the `fetch(input, init)` API but adds a
|
|
10
|
+
* budget so failure modes stay bounded.
|
|
11
|
+
*
|
|
12
|
+
* @param input URL or Request, exactly like fetch
|
|
13
|
+
* @param init RequestInit + { timeoutMs?: number, retry?: number }
|
|
14
|
+
* - timeoutMs (default 30_000) — overall request budget
|
|
15
|
+
* - retry (default 0) — retry count on 429/503
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const res = await fetchWithBudget('https://api.example.com', {
|
|
20
|
+
* method: 'POST',
|
|
21
|
+
* body: JSON.stringify(payload),
|
|
22
|
+
* timeoutMs: 5000,
|
|
23
|
+
* retry: 3,
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function fetchWithBudget(input: RequestInfo | URL, init?: RequestInit & { timeoutMs?: number, retry?: number }): Promise<globalThis.Response>;
|
|
28
|
+
export declare enum Response {
|
|
29
|
+
// 1xx Informational
|
|
30
|
+
HTTP_CONTINUE = 100,
|
|
31
|
+
HTTP_SWITCHING_PROTOCOLS = 101,
|
|
32
|
+
|
|
33
|
+
// 2xx Success
|
|
34
|
+
HTTP_OK = 200,
|
|
35
|
+
HTTP_CREATED = 201,
|
|
36
|
+
HTTP_ACCEPTED = 202,
|
|
37
|
+
HTTP_NON_AUTHORITATIVE_INFORMATION = 203,
|
|
38
|
+
HTTP_NO_CONTENT = 204,
|
|
39
|
+
HTTP_RESET_CONTENT = 205,
|
|
40
|
+
HTTP_PARTIAL_CONTENT = 206,
|
|
41
|
+
|
|
42
|
+
// 3xx Redirection
|
|
43
|
+
HTTP_MULTIPLE_CHOICES = 300,
|
|
44
|
+
HTTP_MOVED_PERMANENTLY = 301,
|
|
45
|
+
HTTP_FOUND = 302,
|
|
46
|
+
HTTP_SEE_OTHER = 303,
|
|
47
|
+
HTTP_NOT_MODIFIED = 304,
|
|
48
|
+
HTTP_USE_PROXY = 305,
|
|
49
|
+
HTTP_UNUSED = 306,
|
|
50
|
+
HTTP_TEMPORARY_REDIRECT = 307,
|
|
51
|
+
HTTP_PERMANENT_REDIRECT = 308,
|
|
52
|
+
|
|
53
|
+
// 4xx Client Error
|
|
54
|
+
HTTP_BAD_REQUEST = 400,
|
|
55
|
+
HTTP_UNAUTHORIZED = 401,
|
|
56
|
+
HTTP_PAYMENT_REQUIRED = 402,
|
|
57
|
+
HTTP_FORBIDDEN = 403,
|
|
58
|
+
HTTP_NOT_FOUND = 404,
|
|
59
|
+
HTTP_METHOD_NOT_ALLOWED = 405,
|
|
60
|
+
HTTP_NOT_ACCEPTABLE = 406,
|
|
61
|
+
HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
62
|
+
HTTP_REQUEST_TIMEOUT = 408,
|
|
63
|
+
HTTP_CONFLICT = 409,
|
|
64
|
+
HTTP_GONE = 410,
|
|
65
|
+
HTTP_LENGTH_REQUIRED = 411,
|
|
66
|
+
HTTP_PRECONDITION_FAILED = 412,
|
|
67
|
+
HTTP_REQUEST_ENTITY_TOO_LARGE = 413,
|
|
68
|
+
HTTP_REQUEST_URI_TOO_LONG = 414,
|
|
69
|
+
HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
|
|
70
|
+
HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
|
71
|
+
HTTP_EXPECTATION_FAILED = 417,
|
|
72
|
+
HTTP_I_AM_A_TEAPOT = 418,
|
|
73
|
+
HTTP_MISDIRECTED_REQUEST = 421,
|
|
74
|
+
HTTP_UNPROCESSABLE_ENTITY = 422,
|
|
75
|
+
HTTP_LOCKED = 423,
|
|
76
|
+
HTTP_FAILED_DEPENDENCY = 424,
|
|
77
|
+
HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425,
|
|
78
|
+
HTTP_UPGRADE_REQUIRED = 426,
|
|
79
|
+
HTTP_PRECONDITION_REQUIRED = 428,
|
|
80
|
+
HTTP_TOO_MANY_REQUESTS = 429,
|
|
81
|
+
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
|
82
|
+
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
|
83
|
+
|
|
84
|
+
// 5xx Server Error
|
|
85
|
+
HTTP_INTERNAL_SERVER_ERROR = 500,
|
|
86
|
+
HTTP_NOT_IMPLEMENTED = 501,
|
|
87
|
+
HTTP_BAD_GATEWAY = 502,
|
|
88
|
+
HTTP_SERVICE_UNAVAILABLE = 503,
|
|
89
|
+
HTTP_GATEWAY_TIMEOUT = 504,
|
|
90
|
+
HTTP_VERSION_NOT_SUPPORTED = 505,
|
|
91
|
+
HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506,
|
|
92
|
+
HTTP_INSUFFICIENT_STORAGE = 507,
|
|
93
|
+
HTTP_LOOP_DETECTED = 508,
|
|
94
|
+
HTTP_NOT_EXTENDED = 510,
|
|
95
|
+
HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511,
|
|
96
|
+
}
|