recker 1.0.26 → 1.0.27

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.
Files changed (171) hide show
  1. package/dist/browser/browser/cache.d.ts +40 -0
  2. package/dist/browser/browser/cache.js +199 -0
  3. package/dist/browser/browser/crypto.d.ts +24 -0
  4. package/dist/browser/browser/crypto.js +80 -0
  5. package/dist/browser/browser/index.d.ts +31 -0
  6. package/dist/browser/browser/index.js +31 -0
  7. package/dist/browser/browser/recker.d.ts +26 -0
  8. package/dist/browser/browser/recker.js +61 -0
  9. package/dist/browser/cache/basic-file-storage.d.ts +12 -0
  10. package/dist/browser/cache/basic-file-storage.js +50 -0
  11. package/dist/browser/cache/memory-limits.d.ts +20 -0
  12. package/dist/browser/cache/memory-limits.js +96 -0
  13. package/dist/browser/cache/memory-storage.d.ts +132 -0
  14. package/dist/browser/cache/memory-storage.js +454 -0
  15. package/dist/browser/cache.d.ts +40 -0
  16. package/dist/browser/cache.js +199 -0
  17. package/dist/browser/constants/http-status.d.ts +73 -0
  18. package/dist/browser/constants/http-status.js +156 -0
  19. package/dist/browser/cookies/memory-cookie-jar.d.ts +30 -0
  20. package/dist/browser/cookies/memory-cookie-jar.js +210 -0
  21. package/dist/browser/core/client.d.ts +118 -0
  22. package/dist/browser/core/client.js +667 -0
  23. package/dist/browser/core/errors.d.ts +142 -0
  24. package/dist/browser/core/errors.js +308 -0
  25. package/dist/browser/core/index.d.ts +5 -0
  26. package/dist/browser/core/index.js +5 -0
  27. package/dist/browser/core/request-promise.d.ts +23 -0
  28. package/dist/browser/core/request-promise.js +82 -0
  29. package/dist/browser/core/request.d.ts +20 -0
  30. package/dist/browser/core/request.js +76 -0
  31. package/dist/browser/core/response.d.ts +34 -0
  32. package/dist/browser/core/response.js +178 -0
  33. package/dist/browser/crypto.d.ts +24 -0
  34. package/dist/browser/crypto.js +80 -0
  35. package/dist/browser/index.d.ts +31 -0
  36. package/dist/browser/index.js +31 -0
  37. package/dist/browser/plugins/auth/api-key.d.ts +8 -0
  38. package/dist/browser/plugins/auth/api-key.js +27 -0
  39. package/dist/browser/plugins/auth/auth0.d.ts +33 -0
  40. package/dist/browser/plugins/auth/auth0.js +94 -0
  41. package/dist/browser/plugins/auth/aws-sigv4.d.ts +10 -0
  42. package/dist/browser/plugins/auth/aws-sigv4.js +88 -0
  43. package/dist/browser/plugins/auth/azure-ad.d.ts +48 -0
  44. package/dist/browser/plugins/auth/azure-ad.js +152 -0
  45. package/dist/browser/plugins/auth/basic.d.ts +7 -0
  46. package/dist/browser/plugins/auth/basic.js +13 -0
  47. package/dist/browser/plugins/auth/bearer.d.ts +8 -0
  48. package/dist/browser/plugins/auth/bearer.js +17 -0
  49. package/dist/browser/plugins/auth/cognito.d.ts +45 -0
  50. package/dist/browser/plugins/auth/cognito.js +208 -0
  51. package/dist/browser/plugins/auth/digest.d.ts +8 -0
  52. package/dist/browser/plugins/auth/digest.js +100 -0
  53. package/dist/browser/plugins/auth/firebase.d.ts +32 -0
  54. package/dist/browser/plugins/auth/firebase.js +195 -0
  55. package/dist/browser/plugins/auth/github-app.d.ts +36 -0
  56. package/dist/browser/plugins/auth/github-app.js +170 -0
  57. package/dist/browser/plugins/auth/google-service-account.d.ts +49 -0
  58. package/dist/browser/plugins/auth/google-service-account.js +172 -0
  59. package/dist/browser/plugins/auth/index.d.ts +15 -0
  60. package/dist/browser/plugins/auth/index.js +15 -0
  61. package/dist/browser/plugins/auth/mtls.d.ts +37 -0
  62. package/dist/browser/plugins/auth/mtls.js +140 -0
  63. package/dist/browser/plugins/auth/oauth2.d.ts +8 -0
  64. package/dist/browser/plugins/auth/oauth2.js +26 -0
  65. package/dist/browser/plugins/auth/oidc.d.ts +55 -0
  66. package/dist/browser/plugins/auth/oidc.js +222 -0
  67. package/dist/browser/plugins/auth/okta.d.ts +47 -0
  68. package/dist/browser/plugins/auth/okta.js +157 -0
  69. package/dist/browser/plugins/auth.d.ts +1 -0
  70. package/dist/browser/plugins/auth.js +1 -0
  71. package/dist/browser/plugins/cache.d.ts +15 -0
  72. package/dist/browser/plugins/cache.js +486 -0
  73. package/dist/browser/plugins/circuit-breaker.d.ts +13 -0
  74. package/dist/browser/plugins/circuit-breaker.js +100 -0
  75. package/dist/browser/plugins/compression.d.ts +4 -0
  76. package/dist/browser/plugins/compression.js +130 -0
  77. package/dist/browser/plugins/cookie-jar.d.ts +5 -0
  78. package/dist/browser/plugins/cookie-jar.js +72 -0
  79. package/dist/browser/plugins/dedup.d.ts +5 -0
  80. package/dist/browser/plugins/dedup.js +35 -0
  81. package/dist/browser/plugins/graphql.d.ts +13 -0
  82. package/dist/browser/plugins/graphql.js +58 -0
  83. package/dist/browser/plugins/grpc-web.d.ts +79 -0
  84. package/dist/browser/plugins/grpc-web.js +261 -0
  85. package/dist/browser/plugins/hls.d.ts +105 -0
  86. package/dist/browser/plugins/hls.js +395 -0
  87. package/dist/browser/plugins/jsonrpc.d.ts +75 -0
  88. package/dist/browser/plugins/jsonrpc.js +143 -0
  89. package/dist/browser/plugins/logger.d.ts +13 -0
  90. package/dist/browser/plugins/logger.js +108 -0
  91. package/dist/browser/plugins/odata.d.ts +181 -0
  92. package/dist/browser/plugins/odata.js +564 -0
  93. package/dist/browser/plugins/pagination.d.ts +16 -0
  94. package/dist/browser/plugins/pagination.js +105 -0
  95. package/dist/browser/plugins/rate-limit.d.ts +15 -0
  96. package/dist/browser/plugins/rate-limit.js +162 -0
  97. package/dist/browser/plugins/retry.d.ts +14 -0
  98. package/dist/browser/plugins/retry.js +116 -0
  99. package/dist/browser/plugins/scrape.d.ts +21 -0
  100. package/dist/browser/plugins/scrape.js +82 -0
  101. package/dist/browser/plugins/server-timing.d.ts +7 -0
  102. package/dist/browser/plugins/server-timing.js +24 -0
  103. package/dist/browser/plugins/soap.d.ts +72 -0
  104. package/dist/browser/plugins/soap.js +347 -0
  105. package/dist/browser/plugins/xml.d.ts +9 -0
  106. package/dist/browser/plugins/xml.js +194 -0
  107. package/dist/browser/plugins/xsrf.d.ts +9 -0
  108. package/dist/browser/plugins/xsrf.js +48 -0
  109. package/dist/browser/recker.d.ts +26 -0
  110. package/dist/browser/recker.js +61 -0
  111. package/dist/browser/runner/request-runner.d.ts +46 -0
  112. package/dist/browser/runner/request-runner.js +89 -0
  113. package/dist/browser/scrape/document.d.ts +44 -0
  114. package/dist/browser/scrape/document.js +210 -0
  115. package/dist/browser/scrape/element.d.ts +49 -0
  116. package/dist/browser/scrape/element.js +176 -0
  117. package/dist/browser/scrape/extractors.d.ts +16 -0
  118. package/dist/browser/scrape/extractors.js +356 -0
  119. package/dist/browser/scrape/types.d.ts +107 -0
  120. package/dist/browser/scrape/types.js +1 -0
  121. package/dist/browser/transport/fetch.d.ts +11 -0
  122. package/dist/browser/transport/fetch.js +143 -0
  123. package/dist/browser/transport/undici.d.ts +38 -0
  124. package/dist/browser/transport/undici.js +897 -0
  125. package/dist/browser/types/ai.d.ts +267 -0
  126. package/dist/browser/types/ai.js +1 -0
  127. package/dist/browser/types/index.d.ts +351 -0
  128. package/dist/browser/types/index.js +1 -0
  129. package/dist/browser/types/logger.d.ts +16 -0
  130. package/dist/browser/types/logger.js +66 -0
  131. package/dist/browser/types/udp.d.ts +138 -0
  132. package/dist/browser/types/udp.js +1 -0
  133. package/dist/browser/utils/agent-manager.d.ts +29 -0
  134. package/dist/browser/utils/agent-manager.js +160 -0
  135. package/dist/browser/utils/body.d.ts +10 -0
  136. package/dist/browser/utils/body.js +148 -0
  137. package/dist/browser/utils/charset.d.ts +15 -0
  138. package/dist/browser/utils/charset.js +169 -0
  139. package/dist/browser/utils/concurrency.d.ts +20 -0
  140. package/dist/browser/utils/concurrency.js +120 -0
  141. package/dist/browser/utils/dns.d.ts +6 -0
  142. package/dist/browser/utils/dns.js +26 -0
  143. package/dist/browser/utils/header-parser.d.ts +94 -0
  144. package/dist/browser/utils/header-parser.js +617 -0
  145. package/dist/browser/utils/html-cleaner.d.ts +1 -0
  146. package/dist/browser/utils/html-cleaner.js +21 -0
  147. package/dist/browser/utils/link-header.d.ts +69 -0
  148. package/dist/browser/utils/link-header.js +190 -0
  149. package/dist/browser/utils/optional-require.d.ts +19 -0
  150. package/dist/browser/utils/optional-require.js +105 -0
  151. package/dist/browser/utils/progress.d.ts +8 -0
  152. package/dist/browser/utils/progress.js +82 -0
  153. package/dist/browser/utils/request-pool.d.ts +22 -0
  154. package/dist/browser/utils/request-pool.js +101 -0
  155. package/dist/browser/utils/sse.d.ts +7 -0
  156. package/dist/browser/utils/sse.js +67 -0
  157. package/dist/browser/utils/streaming.d.ts +17 -0
  158. package/dist/browser/utils/streaming.js +84 -0
  159. package/dist/browser/utils/try-fn.d.ts +3 -0
  160. package/dist/browser/utils/try-fn.js +59 -0
  161. package/dist/browser/utils/user-agent.d.ts +44 -0
  162. package/dist/browser/utils/user-agent.js +100 -0
  163. package/dist/browser/utils/whois.d.ts +32 -0
  164. package/dist/browser/utils/whois.js +246 -0
  165. package/dist/browser/websocket/client.d.ts +65 -0
  166. package/dist/browser/websocket/client.js +313 -0
  167. package/dist/cli/index.d.ts +1 -0
  168. package/dist/cli/index.js +1 -0
  169. package/dist/transport/fetch.d.ts +7 -1
  170. package/dist/transport/fetch.js +58 -76
  171. package/package.json +34 -2
@@ -0,0 +1,142 @@
1
+ import { ReckerRequest, ReckerResponse } from '../types/index.js';
2
+ export declare class ReckerError extends Error {
3
+ request?: ReckerRequest;
4
+ response?: ReckerResponse;
5
+ suggestions: string[];
6
+ retriable: boolean;
7
+ constructor(message: string, request?: ReckerRequest, response?: ReckerResponse, suggestions?: string[], retriable?: boolean);
8
+ }
9
+ export declare class HttpError extends ReckerError {
10
+ status: number;
11
+ statusText: string;
12
+ constructor(response: ReckerResponse, request?: ReckerRequest);
13
+ }
14
+ export type TimeoutPhase = 'lookup' | 'connect' | 'secureConnect' | 'socket' | 'send' | 'response' | 'request' | 'webrtc-connect';
15
+ export declare class TimeoutError extends ReckerError {
16
+ phase: TimeoutPhase;
17
+ timeout: number;
18
+ elapsed?: number;
19
+ event: string;
20
+ constructor(request?: ReckerRequest, options?: {
21
+ phase?: TimeoutPhase;
22
+ timeout?: number;
23
+ elapsed?: number;
24
+ });
25
+ }
26
+ export declare class NetworkError extends ReckerError {
27
+ code?: string;
28
+ constructor(message: string, code?: string, request?: ReckerRequest);
29
+ }
30
+ export declare class MaxSizeExceededError extends ReckerError {
31
+ maxSize: number;
32
+ actualSize?: number;
33
+ constructor(maxSize: number, actualSize?: number, request?: ReckerRequest);
34
+ }
35
+ export declare class AbortError extends ReckerError {
36
+ reason?: string;
37
+ constructor(reason?: string, request?: ReckerRequest);
38
+ }
39
+ export declare class ConnectionError extends ReckerError {
40
+ host?: string;
41
+ port?: number;
42
+ code?: string;
43
+ constructor(message: string, options?: {
44
+ host?: string;
45
+ port?: number;
46
+ code?: string;
47
+ retriable?: boolean;
48
+ request?: ReckerRequest;
49
+ });
50
+ }
51
+ export declare class AuthenticationError extends ReckerError {
52
+ authType?: string;
53
+ constructor(message: string, options?: {
54
+ authType?: string;
55
+ request?: ReckerRequest;
56
+ });
57
+ }
58
+ export declare class ProtocolError extends ReckerError {
59
+ protocol: string;
60
+ code?: string | number;
61
+ phase?: string;
62
+ constructor(message: string, options: {
63
+ protocol: string;
64
+ code?: string | number;
65
+ phase?: string;
66
+ retriable?: boolean;
67
+ request?: ReckerRequest;
68
+ });
69
+ }
70
+ export declare class NotFoundError extends ReckerError {
71
+ resource?: string;
72
+ constructor(message: string, options?: {
73
+ resource?: string;
74
+ request?: ReckerRequest;
75
+ });
76
+ }
77
+ export declare class StateError extends ReckerError {
78
+ expectedState?: string;
79
+ actualState?: string;
80
+ constructor(message: string, options?: {
81
+ expectedState?: string;
82
+ actualState?: string;
83
+ request?: ReckerRequest;
84
+ });
85
+ }
86
+ export declare class ValidationError extends ReckerError {
87
+ field?: string;
88
+ value?: unknown;
89
+ constructor(message: string, options?: {
90
+ field?: string;
91
+ value?: unknown;
92
+ request?: ReckerRequest;
93
+ });
94
+ }
95
+ export declare class ConfigurationError extends ReckerError {
96
+ configKey?: string;
97
+ constructor(message: string, options?: {
98
+ configKey?: string;
99
+ request?: ReckerRequest;
100
+ });
101
+ }
102
+ export declare class UnsupportedError extends ReckerError {
103
+ feature?: string;
104
+ constructor(message: string, options?: {
105
+ feature?: string;
106
+ request?: ReckerRequest;
107
+ });
108
+ }
109
+ export declare class ParseError extends ReckerError {
110
+ format?: string;
111
+ position?: number;
112
+ constructor(message: string, options?: {
113
+ format?: string;
114
+ position?: number;
115
+ request?: ReckerRequest;
116
+ });
117
+ }
118
+ export declare class QueueCancelledError extends ReckerError {
119
+ queueName?: string;
120
+ constructor(message?: string, options?: {
121
+ queueName?: string;
122
+ request?: ReckerRequest;
123
+ });
124
+ }
125
+ export declare class StreamError extends ReckerError {
126
+ streamType?: string;
127
+ constructor(message: string, options?: {
128
+ streamType?: string;
129
+ retriable?: boolean;
130
+ request?: ReckerRequest;
131
+ });
132
+ }
133
+ export declare class DownloadError extends ReckerError {
134
+ url?: string;
135
+ statusCode?: number;
136
+ constructor(message: string, options?: {
137
+ url?: string;
138
+ statusCode?: number;
139
+ retriable?: boolean;
140
+ request?: ReckerRequest;
141
+ });
142
+ }
@@ -0,0 +1,308 @@
1
+ export class ReckerError extends Error {
2
+ request;
3
+ response;
4
+ suggestions;
5
+ retriable;
6
+ constructor(message, request, response, suggestions = [], retriable = false) {
7
+ super(message);
8
+ this.name = 'ReckerError';
9
+ this.request = request;
10
+ this.response = response;
11
+ this.suggestions = suggestions;
12
+ this.retriable = retriable;
13
+ }
14
+ }
15
+ export class HttpError extends ReckerError {
16
+ status;
17
+ statusText;
18
+ constructor(response, request) {
19
+ super(`Request failed with status code ${response.status} ${response.statusText}`, request, response, ['Check the upstream service response body for error details.', 'Inspect request headers/body to ensure they match the API contract.', 'Retry if this is a transient 5xx/429 error.'], isRetryableStatus(response.status));
20
+ this.name = 'HttpError';
21
+ this.status = response.status;
22
+ this.statusText = response.statusText;
23
+ }
24
+ }
25
+ export class TimeoutError extends ReckerError {
26
+ phase;
27
+ timeout;
28
+ elapsed;
29
+ event;
30
+ constructor(request, options) {
31
+ const phase = options?.phase || 'request';
32
+ const timeout = options?.timeout;
33
+ const elapsed = options?.elapsed;
34
+ const phaseMessages = {
35
+ lookup: 'DNS lookup timed out',
36
+ connect: 'TCP connection timed out',
37
+ secureConnect: 'TLS handshake timed out',
38
+ socket: 'Socket assignment timed out (connection pool exhausted)',
39
+ send: 'Request body upload timed out',
40
+ response: 'Waiting for response timed out (TTFB)',
41
+ request: 'Request timed out (total time exceeded)',
42
+ 'webrtc-connect': 'WebRTC peer connection timed out'
43
+ };
44
+ let message = phaseMessages[phase];
45
+ if (timeout !== undefined) {
46
+ message += ` after ${timeout}ms`;
47
+ }
48
+ if (elapsed !== undefined && elapsed !== timeout) {
49
+ message += ` (elapsed: ${Math.round(elapsed)}ms)`;
50
+ }
51
+ const suggestions = [
52
+ 'Verify network connectivity and DNS resolution for the target host.',
53
+ 'Increase the specific timeout phase or optimize the upstream response time.',
54
+ 'Reduce concurrent requests if the connection pool is exhausted.'
55
+ ];
56
+ super(message, request, undefined, suggestions, true);
57
+ this.name = 'TimeoutError';
58
+ this.phase = phase;
59
+ this.timeout = timeout ?? 0;
60
+ this.elapsed = elapsed;
61
+ this.event = `timeout:${phase}`;
62
+ }
63
+ }
64
+ export class NetworkError extends ReckerError {
65
+ code;
66
+ constructor(message, code, request) {
67
+ const suggestions = [
68
+ 'Confirm the host and port are reachable from this environment.',
69
+ 'Check proxy/VPN/firewall settings that might block the request.',
70
+ 'Retry the request or switch transport if this is transient.'
71
+ ];
72
+ super(message, request, undefined, suggestions, true);
73
+ this.name = 'NetworkError';
74
+ this.code = code;
75
+ }
76
+ }
77
+ export class MaxSizeExceededError extends ReckerError {
78
+ maxSize;
79
+ actualSize;
80
+ constructor(maxSize, actualSize, request) {
81
+ const sizeInfo = actualSize
82
+ ? `${actualSize} bytes (max: ${maxSize} bytes)`
83
+ : `${maxSize} bytes`;
84
+ super(`Response size exceeded maximum allowed: ${sizeInfo}`, request, undefined, [
85
+ 'Increase maxResponseSize if the larger payload is expected.',
86
+ 'Add pagination/streaming to reduce payload size.',
87
+ 'Ensure the upstream is not returning unexpected large responses.'
88
+ ], false);
89
+ this.name = 'MaxSizeExceededError';
90
+ this.maxSize = maxSize;
91
+ this.actualSize = actualSize;
92
+ }
93
+ }
94
+ function isRetryableStatus(status) {
95
+ return [408, 425, 429, 500, 502, 503, 504].includes(status);
96
+ }
97
+ export class AbortError extends ReckerError {
98
+ reason;
99
+ constructor(reason, request) {
100
+ super(reason || 'Request was aborted', request, undefined, [
101
+ 'Check if the abort was intentional (user-triggered or timeout).',
102
+ 'Increase timeout if the request needs more time to complete.',
103
+ 'Ensure AbortController is not being triggered prematurely.'
104
+ ], true);
105
+ this.name = 'AbortError';
106
+ this.reason = reason;
107
+ }
108
+ }
109
+ export class ConnectionError extends ReckerError {
110
+ host;
111
+ port;
112
+ code;
113
+ constructor(message, options) {
114
+ super(message, options?.request, undefined, [
115
+ 'Verify the host and port are correct and the service is running.',
116
+ 'Check network connectivity and firewall rules.',
117
+ 'Ensure the service is accepting connections on the specified port.'
118
+ ], options?.retriable ?? true);
119
+ this.name = 'ConnectionError';
120
+ this.host = options?.host;
121
+ this.port = options?.port;
122
+ this.code = options?.code;
123
+ }
124
+ }
125
+ export class AuthenticationError extends ReckerError {
126
+ authType;
127
+ constructor(message, options) {
128
+ super(message, options?.request, undefined, [
129
+ 'Verify credentials (username/password, API key, or certificate).',
130
+ 'Check if the account is active and has proper permissions.',
131
+ 'Ensure the authentication method matches what the server expects.'
132
+ ], false);
133
+ this.name = 'AuthenticationError';
134
+ this.authType = options?.authType;
135
+ }
136
+ }
137
+ export class ProtocolError extends ReckerError {
138
+ protocol;
139
+ code;
140
+ phase;
141
+ constructor(message, options) {
142
+ const protocolSuggestions = {
143
+ ftp: [
144
+ 'Ensure the FTP server is running and accessible.',
145
+ 'Check file/directory permissions on the server.',
146
+ 'Verify the path exists and is correct.'
147
+ ],
148
+ sftp: [
149
+ 'Verify SSH credentials and key permissions.',
150
+ 'Check that the SFTP subsystem is enabled on the server.',
151
+ 'Ensure the target path exists and is accessible.'
152
+ ],
153
+ telnet: [
154
+ 'Verify the Telnet service is running on the target host.',
155
+ 'Check login credentials and terminal settings.',
156
+ 'Ensure the expected prompts match the server output.'
157
+ ],
158
+ udp: [
159
+ 'UDP is connectionless - verify the target is listening.',
160
+ 'Check firewall rules for UDP traffic.',
161
+ 'Ensure the message format matches what the server expects.'
162
+ ],
163
+ webrtc: [
164
+ 'Verify the signaling server is reachable.',
165
+ 'Check ICE server configuration (STUN/TURN).',
166
+ 'Ensure both peers have compatible codecs and capabilities.'
167
+ ],
168
+ dns: [
169
+ 'Verify the DNS server is reachable.',
170
+ 'Check if the domain exists and has the requested record type.',
171
+ 'Try an alternative DNS resolver.'
172
+ ],
173
+ tls: [
174
+ 'Verify the certificate is valid and not expired.',
175
+ 'Check that the hostname matches the certificate.',
176
+ 'Ensure TLS version and cipher suites are compatible.'
177
+ ]
178
+ };
179
+ const suggestions = protocolSuggestions[options.protocol.toLowerCase()] || [
180
+ 'Check the protocol-specific documentation.',
181
+ 'Verify the server supports the requested operation.',
182
+ 'Review the error code for specific guidance.'
183
+ ];
184
+ super(message, options.request, undefined, suggestions, options.retriable ?? false);
185
+ this.name = 'ProtocolError';
186
+ this.protocol = options.protocol;
187
+ this.code = options.code;
188
+ this.phase = options.phase;
189
+ }
190
+ }
191
+ export class NotFoundError extends ReckerError {
192
+ resource;
193
+ constructor(message, options) {
194
+ super(message, options?.request, undefined, [
195
+ 'Verify the resource path or identifier is correct.',
196
+ 'Check if the resource was deleted or moved.',
197
+ 'Ensure you have permission to access this resource.'
198
+ ], false);
199
+ this.name = 'NotFoundError';
200
+ this.resource = options?.resource;
201
+ }
202
+ }
203
+ export class StateError extends ReckerError {
204
+ expectedState;
205
+ actualState;
206
+ constructor(message, options) {
207
+ super(message, options?.request, undefined, [
208
+ 'Ensure the required setup/initialization step was performed.',
209
+ 'Check that operations are called in the correct order.',
210
+ 'Verify the connection or resource is still valid.'
211
+ ], false);
212
+ this.name = 'StateError';
213
+ this.expectedState = options?.expectedState;
214
+ this.actualState = options?.actualState;
215
+ }
216
+ }
217
+ export class ValidationError extends ReckerError {
218
+ field;
219
+ value;
220
+ constructor(message, options) {
221
+ super(message, options?.request, undefined, [
222
+ 'Check the input format and constraints.',
223
+ 'Refer to the API documentation for valid values.',
224
+ 'Ensure required fields are provided.'
225
+ ], false);
226
+ this.name = 'ValidationError';
227
+ this.field = options?.field;
228
+ this.value = options?.value;
229
+ }
230
+ }
231
+ export class ConfigurationError extends ReckerError {
232
+ configKey;
233
+ constructor(message, options) {
234
+ super(message, options?.request, undefined, [
235
+ 'Check the configuration file or environment variables.',
236
+ 'Ensure all required configuration keys are set.',
237
+ 'Verify the configuration values are in the correct format.'
238
+ ], false);
239
+ this.name = 'ConfigurationError';
240
+ this.configKey = options?.configKey;
241
+ }
242
+ }
243
+ export class UnsupportedError extends ReckerError {
244
+ feature;
245
+ constructor(message, options) {
246
+ super(message, options?.request, undefined, [
247
+ 'Check if this feature is supported in the current context.',
248
+ 'Refer to the documentation for supported operations.',
249
+ 'Consider using an alternative approach.'
250
+ ], false);
251
+ this.name = 'UnsupportedError';
252
+ this.feature = options?.feature;
253
+ }
254
+ }
255
+ export class ParseError extends ReckerError {
256
+ format;
257
+ position;
258
+ constructor(message, options) {
259
+ super(message, options?.request, undefined, [
260
+ 'Verify the input is in the expected format.',
261
+ 'Check for malformed or corrupted data.',
262
+ 'Ensure the encoding is correct (UTF-8, etc.).'
263
+ ], false);
264
+ this.name = 'ParseError';
265
+ this.format = options?.format;
266
+ this.position = options?.position;
267
+ }
268
+ }
269
+ export class QueueCancelledError extends ReckerError {
270
+ queueName;
271
+ constructor(message, options) {
272
+ super(message || 'Queue operation was cancelled', options?.request, undefined, [
273
+ 'This is typically expected during shutdown.',
274
+ 'Check if the queue was manually cleared.',
275
+ 'Retry the operation if the queue is still active.'
276
+ ], true);
277
+ this.name = 'QueueCancelledError';
278
+ this.queueName = options?.queueName;
279
+ }
280
+ }
281
+ export class StreamError extends ReckerError {
282
+ streamType;
283
+ constructor(message, options) {
284
+ super(message, options?.request, undefined, [
285
+ 'Check if the stream was prematurely closed.',
286
+ 'Verify the data source is still available.',
287
+ 'Ensure proper error handling for stream events.'
288
+ ], options?.retriable ?? false);
289
+ this.name = 'StreamError';
290
+ this.streamType = options?.streamType;
291
+ }
292
+ }
293
+ export class DownloadError extends ReckerError {
294
+ url;
295
+ statusCode;
296
+ constructor(message, options) {
297
+ super(message, options?.request, undefined, [
298
+ 'Verify the URL is correct and accessible.',
299
+ 'Check network connectivity.',
300
+ options?.statusCode
301
+ ? `HTTP ${options.statusCode} - check server response.`
302
+ : 'Retry the download if the error is transient.'
303
+ ], options?.retriable ?? true);
304
+ this.name = 'DownloadError';
305
+ this.url = options?.url;
306
+ this.statusCode = options?.statusCode;
307
+ }
308
+ }
@@ -0,0 +1,5 @@
1
+ export * from './client.js';
2
+ export * from './errors.js';
3
+ export * from './request-promise.js';
4
+ export * from './request.js';
5
+ export * from './response.js';
@@ -0,0 +1,5 @@
1
+ export * from './client.js';
2
+ export * from './errors.js';
3
+ export * from './request-promise.js';
4
+ export * from './request.js';
5
+ export * from './response.js';
@@ -0,0 +1,23 @@
1
+ import { ReckerResponse, SSEEvent, ProgressEvent } from '../types/index.js';
2
+ import type { ZodSchema } from 'zod';
3
+ export declare class RequestPromise<T = unknown> implements Promise<ReckerResponse<T>> {
4
+ private promise;
5
+ private abortController?;
6
+ constructor(promise: Promise<ReckerResponse<T>>, abortController?: AbortController);
7
+ get [Symbol.toStringTag](): string;
8
+ then<TResult1 = ReckerResponse<T>, TResult2 = never>(onfulfilled?: ((value: ReckerResponse<T>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
9
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<ReckerResponse<T> | TResult>;
10
+ finally(onfinally?: (() => void) | null): Promise<ReckerResponse<T>>;
11
+ cancel(): void;
12
+ json<R = T>(): Promise<R>;
13
+ text(): Promise<string>;
14
+ cleanText(): Promise<string>;
15
+ blob(): Promise<Blob>;
16
+ read(): Promise<ReadableStream<Uint8Array> | null>;
17
+ write(path: string): Promise<void>;
18
+ parse<R>(schema: ZodSchema<R>): Promise<R>;
19
+ safe(): Promise<[boolean, Error | null, T | undefined]>;
20
+ sse(): AsyncGenerator<SSEEvent>;
21
+ download(): AsyncGenerator<ProgressEvent>;
22
+ [Symbol.asyncIterator](): AsyncGenerator<Uint8Array>;
23
+ }
@@ -0,0 +1,82 @@
1
+ import { createWriteStream } from 'node:fs';
2
+ import { pipeline } from 'node:stream/promises';
3
+ import { Readable } from 'node:stream';
4
+ import { tryFn } from '../utils/try-fn.js';
5
+ import { StreamError } from './errors.js';
6
+ export class RequestPromise {
7
+ promise;
8
+ abortController;
9
+ constructor(promise, abortController) {
10
+ this.promise = promise;
11
+ this.abortController = abortController;
12
+ }
13
+ get [Symbol.toStringTag]() {
14
+ return 'RequestPromise';
15
+ }
16
+ then(onfulfilled, onrejected) {
17
+ return this.promise.then(onfulfilled, onrejected);
18
+ }
19
+ catch(onrejected) {
20
+ return this.promise.catch(onrejected);
21
+ }
22
+ finally(onfinally) {
23
+ return this.promise.finally(onfinally);
24
+ }
25
+ cancel() {
26
+ if (this.abortController) {
27
+ this.abortController.abort();
28
+ }
29
+ }
30
+ async json() {
31
+ const response = await this.promise;
32
+ return response.json();
33
+ }
34
+ async text() {
35
+ const response = await this.promise;
36
+ return response.text();
37
+ }
38
+ async cleanText() {
39
+ const response = await this.promise;
40
+ return response.cleanText();
41
+ }
42
+ async blob() {
43
+ const response = await this.promise;
44
+ return response.blob();
45
+ }
46
+ async read() {
47
+ const response = await this.promise;
48
+ return response.read();
49
+ }
50
+ async write(path) {
51
+ const response = await this.promise;
52
+ const body = response.read();
53
+ if (!body) {
54
+ throw new StreamError('Response has no body to write', {
55
+ streamType: 'response',
56
+ retriable: true,
57
+ });
58
+ }
59
+ const nodeStream = Readable.fromWeb(body);
60
+ const fileStream = createWriteStream(path);
61
+ await pipeline(nodeStream, fileStream);
62
+ }
63
+ async parse(schema) {
64
+ const data = await this.json();
65
+ return schema.parse(data);
66
+ }
67
+ async safe() {
68
+ return tryFn(() => this.json());
69
+ }
70
+ async *sse() {
71
+ const response = await this.promise;
72
+ yield* response.sse();
73
+ }
74
+ async *download() {
75
+ const response = await this.promise;
76
+ yield* response.download();
77
+ }
78
+ async *[Symbol.asyncIterator]() {
79
+ const response = await this.promise;
80
+ yield* response;
81
+ }
82
+ }
@@ -0,0 +1,20 @@
1
+ import { Method, ReckerRequest, RequestOptions, ProgressCallback, TimeoutOptions, RedirectInfo } from '../types/index.js';
2
+ export declare class HttpRequest implements ReckerRequest {
3
+ readonly url: string;
4
+ readonly method: Method;
5
+ readonly headers: Headers;
6
+ readonly body: BodyInit | null;
7
+ readonly signal?: AbortSignal;
8
+ readonly throwHttpErrors?: boolean;
9
+ readonly timeout?: TimeoutOptions;
10
+ readonly onUploadProgress?: ProgressCallback;
11
+ readonly onDownloadProgress?: ProgressCallback;
12
+ readonly maxResponseSize?: number;
13
+ readonly beforeRedirect?: (info: RedirectInfo) => void | false | string | Promise<void | false | string>;
14
+ readonly maxRedirects?: number;
15
+ readonly followRedirects?: boolean;
16
+ readonly http2?: boolean;
17
+ constructor(url: string, options?: RequestOptions);
18
+ withHeader(name: string, value: string): ReckerRequest;
19
+ withBody(body: BodyInit): ReckerRequest;
20
+ }
@@ -0,0 +1,76 @@
1
+ function normalizeTimeout(timeout) {
2
+ if (timeout === undefined)
3
+ return undefined;
4
+ if (typeof timeout === 'number') {
5
+ return { request: timeout };
6
+ }
7
+ return timeout;
8
+ }
9
+ export class HttpRequest {
10
+ url;
11
+ method;
12
+ headers;
13
+ body;
14
+ signal;
15
+ throwHttpErrors;
16
+ timeout;
17
+ onUploadProgress;
18
+ onDownloadProgress;
19
+ maxResponseSize;
20
+ beforeRedirect;
21
+ maxRedirects;
22
+ followRedirects;
23
+ http2;
24
+ constructor(url, options = {}) {
25
+ this.url = url;
26
+ this.method = options.method || 'GET';
27
+ this.headers = new Headers(options.headers);
28
+ this.body = options.body || null;
29
+ this.signal = options.signal;
30
+ this.throwHttpErrors = options.throwHttpErrors !== undefined ? options.throwHttpErrors : true;
31
+ this.timeout = normalizeTimeout(options.timeout);
32
+ this.onUploadProgress = options.onUploadProgress;
33
+ this.onDownloadProgress = options.onDownloadProgress;
34
+ this.maxResponseSize = options.maxResponseSize;
35
+ this.beforeRedirect = options.beforeRedirect;
36
+ this.maxRedirects = options.maxRedirects;
37
+ this.followRedirects = options.followRedirects;
38
+ this.http2 = options.http2;
39
+ }
40
+ withHeader(name, value) {
41
+ const newHeaders = new Headers(this.headers);
42
+ newHeaders.set(name, value);
43
+ return new HttpRequest(this.url, {
44
+ method: this.method,
45
+ headers: newHeaders,
46
+ body: this.body,
47
+ signal: this.signal,
48
+ throwHttpErrors: this.throwHttpErrors,
49
+ timeout: this.timeout,
50
+ onUploadProgress: this.onUploadProgress,
51
+ onDownloadProgress: this.onDownloadProgress,
52
+ maxResponseSize: this.maxResponseSize,
53
+ beforeRedirect: this.beforeRedirect,
54
+ maxRedirects: this.maxRedirects,
55
+ followRedirects: this.followRedirects,
56
+ http2: this.http2,
57
+ });
58
+ }
59
+ withBody(body) {
60
+ return new HttpRequest(this.url, {
61
+ method: this.method,
62
+ headers: this.headers,
63
+ body: body,
64
+ signal: this.signal,
65
+ throwHttpErrors: this.throwHttpErrors,
66
+ timeout: this.timeout,
67
+ onUploadProgress: this.onUploadProgress,
68
+ onDownloadProgress: this.onDownloadProgress,
69
+ maxResponseSize: this.maxResponseSize,
70
+ beforeRedirect: this.beforeRedirect,
71
+ maxRedirects: this.maxRedirects,
72
+ followRedirects: this.followRedirects,
73
+ http2: this.http2,
74
+ });
75
+ }
76
+ }