rezo 1.0.136 → 1.0.138

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 (50) hide show
  1. package/README.md +3 -3
  2. package/dist/adapters/entries/curl.d.ts +119 -82
  3. package/dist/adapters/entries/fetch.d.ts +119 -82
  4. package/dist/adapters/entries/http.d.ts +119 -82
  5. package/dist/adapters/entries/http2.d.ts +119 -82
  6. package/dist/adapters/entries/react-native.cjs +6 -6
  7. package/dist/adapters/entries/react-native.d.ts +119 -82
  8. package/dist/adapters/entries/xhr.d.ts +119 -82
  9. package/dist/adapters/http.cjs +26 -0
  10. package/dist/adapters/http.js +26 -0
  11. package/dist/adapters/index.cjs +10 -10
  12. package/dist/adapters/index.d.ts +52 -15
  13. package/dist/cache/index.cjs +9 -9
  14. package/dist/cookies/cookie-jar.cjs +154 -9
  15. package/dist/cookies/cookie-jar.js +150 -5
  16. package/dist/cookies/index.cjs +10 -10
  17. package/dist/crawler/index.cjs +42 -42
  18. package/dist/crawler/plugin/index.cjs +1 -1
  19. package/dist/crawler.d.ts +118 -81
  20. package/dist/entries/crawler.cjs +24 -24
  21. package/dist/errors/rezo-error.cjs +3 -2
  22. package/dist/errors/rezo-error.js +3 -2
  23. package/dist/index.cjs +58 -58
  24. package/dist/index.d.ts +119 -82
  25. package/dist/internal/agents/index.cjs +14 -14
  26. package/dist/platform/browser.d.ts +119 -82
  27. package/dist/platform/bun.d.ts +119 -82
  28. package/dist/platform/deno.d.ts +119 -82
  29. package/dist/platform/node.d.ts +119 -82
  30. package/dist/platform/react-native.cjs +6 -6
  31. package/dist/platform/react-native.d.ts +119 -82
  32. package/dist/platform/worker.d.ts +119 -82
  33. package/dist/proxy/index.cjs +4 -4
  34. package/dist/queue/index.cjs +8 -8
  35. package/dist/responses/universal/index.cjs +11 -11
  36. package/dist/stealth/index.cjs +17 -17
  37. package/dist/stealth/profiles/index.cjs +10 -10
  38. package/dist/utils/agent-pool.cjs +1 -1
  39. package/dist/utils/agent-pool.js +1 -1
  40. package/dist/utils/headers.cjs +3 -0
  41. package/dist/utils/headers.js +3 -0
  42. package/dist/utils/http-config.cjs +15 -2
  43. package/dist/utils/http-config.js +15 -2
  44. package/dist/utils/staged-timeout.cjs +1 -2
  45. package/dist/utils/staged-timeout.js +1 -2
  46. package/dist/version.cjs +1 -1
  47. package/dist/version.js +1 -1
  48. package/dist/wget/index.cjs +51 -51
  49. package/dist/wget/index.d.ts +118 -81
  50. package/package.json +1 -1
@@ -2,7 +2,7 @@ import { Agent as HttpAgent, OutgoingHttpHeaders } from 'node:http';
2
2
  import { Agent as HttpsAgent } from 'node:https';
3
3
  import { Socket } from 'node:net';
4
4
  import { SecureContext, TLSSocket } from 'node:tls';
5
- import { Cookie as TouchCookie, CookieJar as TouchCookieJar, CreateCookieJarOptions, CreateCookieOptions, Nullable, Store } from 'tough-cookie';
5
+ import { Callback, Cookie as TouchCookie, CookieJar as TouchCookieJar, CreateCookieJarOptions, CreateCookieOptions, GetCookiesOptions, Nullable, SerializedCookieJar, SetCookieOptions, Store } from 'tough-cookie';
6
6
 
7
7
  export interface RezoHttpHeaders {
8
8
  accept?: string | undefined;
@@ -137,6 +137,9 @@ export declare class RezoHeaders extends Headers {
137
137
  * Used by stealth adapters to match browser header ordering.
138
138
  */
139
139
  toOrderedObject(order: string[]): Record<string, string | string[]>;
140
+ toJSON(): Record<string, string> & {
141
+ "set-cookie"?: string[];
142
+ };
140
143
  toObject(omit?: Array<keyof RezoHttpHeaders> | keyof RezoHttpHeaders): Record<string, string | string[]>;
141
144
  toString(): string;
142
145
  set(name: keyof RezoHttpHeaders, value: string): void;
@@ -214,6 +217,38 @@ export declare class RezoCookieJar extends TouchCookieJar {
214
217
  constructor(cookies: Cookie[], url: string);
215
218
  constructor(store: Nullable<Store>, options?: CreateCookieJarOptions | boolean);
216
219
  private generateCookies;
220
+ setCookieSync(cookie: string | Cookie, url: string, options?: SetCookieOptions): Cookie | undefined;
221
+ setCookie(cookie: string | TouchCookie, url: string | URL, callback: Callback<TouchCookie | undefined>): void;
222
+ setCookie(cookie: string | TouchCookie, url: string | URL, options: SetCookieOptions, callback: Callback<TouchCookie | undefined>): void;
223
+ setCookie(cookie: string | TouchCookie, url: string | URL, options?: SetCookieOptions): Promise<TouchCookie | undefined>;
224
+ setCookie(cookie: string | TouchCookie, url: string | URL, options: SetCookieOptions | Callback<TouchCookie | undefined>, callback?: Callback<TouchCookie | undefined>): unknown;
225
+ getCookies(url: string, callback: Callback<TouchCookie[]>): void;
226
+ getCookies(url: string | URL, options: GetCookiesOptions | undefined, callback: Callback<TouchCookie[]>): void;
227
+ getCookies(url: string | URL, options?: GetCookiesOptions): Promise<TouchCookie[]>;
228
+ getCookies(url: string | URL, options: GetCookiesOptions | undefined | Callback<TouchCookie[]>, callback?: Callback<TouchCookie[]>): unknown;
229
+ getCookiesSync(url: string, options?: GetCookiesOptions): Cookie[];
230
+ getCookieString(url: string, callback: Callback<string | undefined>): void;
231
+ getCookieString(url: string, options: GetCookiesOptions, callback: Callback<string | undefined>): void;
232
+ getCookieString(url: string, options?: GetCookiesOptions): Promise<string>;
233
+ getCookieString(url: string, options: GetCookiesOptions | Callback<string | undefined>, callback?: Callback<string | undefined>): unknown;
234
+ getCookieStringSync(url: string, options?: GetCookiesOptions): string;
235
+ getSetCookieStrings(url: string, callback: Callback<string[] | undefined>): void;
236
+ getSetCookieStrings(url: string, options: GetCookiesOptions, callback: Callback<string[] | undefined>): void;
237
+ getSetCookieStrings(url: string, options?: GetCookiesOptions): Promise<string[] | undefined>;
238
+ getSetCookieStrings(url: string, options: GetCookiesOptions, callback?: Callback<string[] | undefined>): unknown;
239
+ getSetCookieStringsSync(url: string, options?: GetCookiesOptions): string[];
240
+ serialize(callback: Callback<SerializedCookieJar>): void;
241
+ serialize(): Promise<SerializedCookieJar>;
242
+ serializeSync(): SerializedCookieJar | undefined;
243
+ toJSON(): ReturnType<TouchCookieJar["toJSON"]>;
244
+ private toPublicSerializedJar;
245
+ private toStoredCookie;
246
+ private toPublicCookies;
247
+ private toPublicCookie;
248
+ private toStoredCookieKey;
249
+ private toPublicCookieKey;
250
+ private cookiesToCookieString;
251
+ private cookiesToSetCookieStrings;
217
252
  /**
218
253
  * Get all cookies from the cookie jar.
219
254
  *
@@ -4068,34 +4103,36 @@ export interface RezoRequestConfig<D = any> {
4068
4103
  * TLS negotiation for HTTPS).
4069
4104
  *
4070
4105
  * **Behavior:**
4071
- * - `false` (default) - Connection closes after each request. Process exits immediately.
4072
- * - `true` - Connection stays open for reuse. Idle connections close after `keepAliveMsecs`.
4106
+ * - `true` (default) - Connections are pooled and reused across requests to the
4107
+ * same host. Idle pooled sockets are closed after ~5 seconds.
4108
+ * - `false` - A fresh connection is opened for every request and closed after
4109
+ * the response. No pooling, no reuse.
4073
4110
  *
4074
- * **When to use `keepAlive: true`:**
4111
+ * **When to keep the default (`keepAlive: true`):**
4075
4112
  * - Making multiple requests to the same host in sequence
4076
4113
  * - Long-running applications (servers, bots, scrapers)
4077
4114
  * - Performance-critical applications where connection overhead matters
4078
4115
  *
4079
- * **When to use `keepAlive: false` (default):**
4080
- * - Single requests or scripts that should exit immediately
4081
- * - CLI tools that make one-off requests
4082
- * - When you need predictable process termination
4116
+ * **When to use `keepAlive: false`:**
4117
+ * - Hosts that reset reused connections aggressively
4118
+ * - Debugging connection-level issues (isolates every request)
4119
+ * - One-off requests where connection reuse buys nothing
4083
4120
  *
4084
4121
  * @example
4085
4122
  * ```typescript
4086
- * // Default: process exits immediately after request
4123
+ * // Default: pooled keep-alive connections
4087
4124
  * const { data } = await rezo.get('https://api.example.com/data');
4088
4125
  *
4089
- * // Keep connection alive for 1 minute (default) for subsequent requests
4090
- * const client = new Rezo({ keepAlive: true });
4126
+ * // Fresh connection per request for this instance
4127
+ * const client = rezo.create({ keepAlive: false });
4091
4128
  * await client.get('https://api.example.com/users');
4092
- * await client.get('https://api.example.com/posts'); // Reuses connection
4129
+ * await client.get('https://api.example.com/posts'); // New connection again
4093
4130
  *
4094
- * // Custom keep-alive timeout (30 seconds)
4095
- * const client = new Rezo({ keepAlive: true, keepAliveMsecs: 30000 });
4131
+ * // Or per request
4132
+ * await rezo.get('https://api.example.com/data', { keepAlive: false });
4096
4133
  * ```
4097
4134
  *
4098
- * @default false
4135
+ * @default true
4099
4136
  */
4100
4137
  keepAlive?: boolean;
4101
4138
  /**
@@ -4517,9 +4554,9 @@ export interface httpAdapterOverloads {
4517
4554
  request(options: RezoRequestOptions & {
4518
4555
  responseType: "blob";
4519
4556
  }): Promise<RezoResponse<Blob>>;
4520
- request(options: RezoRequestOptions & {
4557
+ request<T extends string = string>(options: RezoRequestOptions & {
4521
4558
  responseType: "text";
4522
- }): Promise<RezoResponse<string>>;
4559
+ }): Promise<RezoResponse<T>>;
4523
4560
  request(options: RezoRequestOptions & {
4524
4561
  responseType: "download";
4525
4562
  }): Promise<RezoDownloadResponse>;
@@ -4549,9 +4586,9 @@ export interface httpAdapterOverloads {
4549
4586
  get(url: string | URL, options: RezoHttpGetRequest & {
4550
4587
  responseType: "blob";
4551
4588
  }): Promise<RezoResponse<Blob>>;
4552
- get(url: string | URL, options: RezoHttpGetRequest & {
4589
+ get<T extends string = string>(url: string | URL, options: RezoHttpGetRequest & {
4553
4590
  responseType: "text";
4554
- }): Promise<RezoResponse<string>>;
4591
+ }): Promise<RezoResponse<T>>;
4555
4592
  get(url: string | URL, options: RezoHttpGetRequest & {
4556
4593
  responseType: "download";
4557
4594
  }): Promise<RezoDownloadResponse>;
@@ -4583,9 +4620,9 @@ export interface httpAdapterOverloads {
4583
4620
  delete(url: string | URL, options: RezoHttpDeleteRequest & {
4584
4621
  responseType: "blob";
4585
4622
  }): Promise<RezoResponse<Blob>>;
4586
- delete(url: string | URL, options: RezoHttpDeleteRequest & {
4623
+ delete<T extends string = string>(url: string | URL, options: RezoHttpDeleteRequest & {
4587
4624
  responseType: "text";
4588
- }): Promise<RezoResponse<string>>;
4625
+ }): Promise<RezoResponse<T>>;
4589
4626
  delete(url: string | URL, options: RezoHttpDeleteRequest & {
4590
4627
  responseType: "download";
4591
4628
  }): Promise<RezoDownloadResponse>;
@@ -4672,9 +4709,9 @@ export interface httpAdapterPostOverloads {
4672
4709
  post(url: string | URL, data: any, options: RezoHttpPostRequest & {
4673
4710
  responseType: "blob";
4674
4711
  }): Promise<RezoResponse<Blob>>;
4675
- post(url: string | URL, data: any, options: RezoHttpPostRequest & {
4712
+ post<T extends string = string>(url: string | URL, data: any, options: RezoHttpPostRequest & {
4676
4713
  responseType: "text";
4677
- }): Promise<RezoResponse<string>>;
4714
+ }): Promise<RezoResponse<T>>;
4678
4715
  post(url: string | URL, data: any, options: RezoHttpPostRequest & {
4679
4716
  responseType: "download";
4680
4717
  }): Promise<RezoDownloadResponse>;
@@ -4702,15 +4739,15 @@ export interface httpAdapterPostOverloads {
4702
4739
  postJson<T = any>(url: string | URL, nullData: null | undefined, options: RezoHttpPostRequest & {
4703
4740
  responseType: "auto" | "json";
4704
4741
  }): Promise<RezoResponse<T>>;
4705
- postJson(url: string | URL, data: Record<any, any> | Array<any>, options: RezoHttpPostRequest & {
4742
+ postJson<T extends string = string>(url: string | URL, data: Record<any, any> | Array<any>, options: RezoHttpPostRequest & {
4706
4743
  responseType: "text";
4707
- }): Promise<RezoResponse<string>>;
4708
- postJson(url: string | URL, jsonString: string, options: RezoHttpPostRequest & {
4744
+ }): Promise<RezoResponse<T>>;
4745
+ postJson<T extends string = string>(url: string | URL, jsonString: string, options: RezoHttpPostRequest & {
4709
4746
  responseType: "text";
4710
- }): Promise<RezoResponse<string>>;
4711
- postJson(url: string | URL, nullData: null | undefined, options: RezoHttpPostRequest & {
4747
+ }): Promise<RezoResponse<T>>;
4748
+ postJson<T extends string = string>(url: string | URL, nullData: null | undefined, options: RezoHttpPostRequest & {
4712
4749
  responseType: "text";
4713
- }): Promise<RezoResponse<string>>;
4750
+ }): Promise<RezoResponse<T>>;
4714
4751
  postJson(url: string | URL, data: Record<any, any> | Array<any>, options: RezoHttpPostRequest & {
4715
4752
  responseType: "arrayBuffer";
4716
4753
  }): Promise<RezoResponse<ArrayBuffer>>;
@@ -4762,15 +4799,15 @@ export interface httpAdapterPostOverloads {
4762
4799
  postForm<T = any>(url: string | URL, nullData: null | undefined, options: RezoHttpPostRequest & {
4763
4800
  responseType: "auto" | "json";
4764
4801
  }): Promise<RezoResponse<T>>;
4765
- postForm(url: string | URL, data: URLSearchParams | RezoURLSearchParams | Record<string, any>, options: RezoHttpPostRequest & {
4802
+ postForm<T extends string = string>(url: string | URL, data: URLSearchParams | RezoURLSearchParams | Record<string, any>, options: RezoHttpPostRequest & {
4766
4803
  responseType: "text";
4767
- }): Promise<RezoResponse<string>>;
4768
- postForm(url: string | URL, string: string, options: RezoHttpPostRequest & {
4804
+ }): Promise<RezoResponse<T>>;
4805
+ postForm<T extends string = string>(url: string | URL, string: string, options: RezoHttpPostRequest & {
4769
4806
  responseType: "text";
4770
- }): Promise<RezoResponse<string>>;
4771
- postForm(url: string | URL, nullData: null | undefined, options: RezoHttpPostRequest & {
4807
+ }): Promise<RezoResponse<T>>;
4808
+ postForm<T extends string = string>(url: string | URL, nullData: null | undefined, options: RezoHttpPostRequest & {
4772
4809
  responseType: "text";
4773
- }): Promise<RezoResponse<string>>;
4810
+ }): Promise<RezoResponse<T>>;
4774
4811
  postForm(url: string | URL, data: URLSearchParams | RezoURLSearchParams | Record<string, any>, options: RezoHttpPostRequest & {
4775
4812
  responseType: "arrayBuffer";
4776
4813
  }): Promise<RezoResponse<ArrayBuffer>>;
@@ -4831,15 +4868,15 @@ export interface httpAdapterPostOverloads {
4831
4868
  postMultipart<T = any>(url: string | URL, dataObject: Record<string, any>, options: RezoHttpPostRequest & {
4832
4869
  responseType: "json";
4833
4870
  }): Promise<RezoResponse<T>>;
4834
- postMultipart(url: string | URL, formData: RezoFormData, options: RezoHttpPostRequest & {
4871
+ postMultipart<T extends string = string>(url: string | URL, formData: RezoFormData, options: RezoHttpPostRequest & {
4835
4872
  responseType: "text";
4836
- }): Promise<RezoResponse<string>>;
4837
- postMultipart(url: string | URL, formData: FormData, options: RezoHttpPostRequest & {
4873
+ }): Promise<RezoResponse<T>>;
4874
+ postMultipart<T extends string = string>(url: string | URL, formData: FormData, options: RezoHttpPostRequest & {
4838
4875
  responseType: "text";
4839
- }): Promise<RezoResponse<string>>;
4840
- postMultipart(url: string | URL, dataObject: Record<string, any>, options: RezoHttpPostRequest & {
4876
+ }): Promise<RezoResponse<T>>;
4877
+ postMultipart<T extends string = string>(url: string | URL, dataObject: Record<string, any>, options: RezoHttpPostRequest & {
4841
4878
  responseType: "text";
4842
- }): Promise<RezoResponse<string>>;
4879
+ }): Promise<RezoResponse<T>>;
4843
4880
  postMultipart(url: string | URL, formData: RezoFormData, options: RezoHttpPostRequest & {
4844
4881
  responseType: "stream";
4845
4882
  }): Promise<RezoStreamResponse>;
@@ -4895,9 +4932,9 @@ export interface httpAdapterPatchOverloads {
4895
4932
  patch(url: string | URL, data: any, options: RezoHttpPatchRequest & {
4896
4933
  responseType: "blob";
4897
4934
  }): Promise<RezoResponse<Blob>>;
4898
- patch(url: string | URL, data: any, options: RezoHttpPatchRequest & {
4935
+ patch<T extends string = string>(url: string | URL, data: any, options: RezoHttpPatchRequest & {
4899
4936
  responseType: "text";
4900
- }): Promise<RezoResponse<string>>;
4937
+ }): Promise<RezoResponse<T>>;
4901
4938
  patch(url: string | URL, data: any, options: RezoHttpPatchRequest & {
4902
4939
  responseType: "download";
4903
4940
  }): RezoDownloadResponse;
@@ -4925,15 +4962,15 @@ export interface httpAdapterPatchOverloads {
4925
4962
  patchJson<T = any>(url: string | URL, nullData: null | undefined, options: RezoHttpPatchRequest & {
4926
4963
  responseType: "auto" | "json";
4927
4964
  }): Promise<RezoResponse<T>>;
4928
- patchJson(url: string | URL, data: Record<any, any> | Array<any>, options: RezoHttpPatchRequest & {
4965
+ patchJson<T extends string = string>(url: string | URL, data: Record<any, any> | Array<any>, options: RezoHttpPatchRequest & {
4929
4966
  responseType: "text";
4930
- }): Promise<RezoResponse<string>>;
4931
- patchJson(url: string | URL, jsonString: string, options: RezoHttpPatchRequest & {
4967
+ }): Promise<RezoResponse<T>>;
4968
+ patchJson<T extends string = string>(url: string | URL, jsonString: string, options: RezoHttpPatchRequest & {
4932
4969
  responseType: "text";
4933
- }): Promise<RezoResponse<string>>;
4934
- patchJson(url: string | URL, nullData: null | undefined, options: RezoHttpPatchRequest & {
4970
+ }): Promise<RezoResponse<T>>;
4971
+ patchJson<T extends string = string>(url: string | URL, nullData: null | undefined, options: RezoHttpPatchRequest & {
4935
4972
  responseType: "text";
4936
- }): Promise<RezoResponse<string>>;
4973
+ }): Promise<RezoResponse<T>>;
4937
4974
  patchJson(url: string | URL, data: Record<any, any> | Array<any>, options: RezoHttpPatchRequest & {
4938
4975
  responseType: "arrayBuffer";
4939
4976
  }): Promise<RezoResponse<ArrayBuffer>>;
@@ -4994,15 +5031,15 @@ export interface httpAdapterPatchOverloads {
4994
5031
  patchForm<T = any>(url: string | URL, nullData: null | undefined, options: RezoHttpPatchRequest & {
4995
5032
  responseType: "auto" | "json";
4996
5033
  }): Promise<RezoResponse<T>>;
4997
- patchForm(url: string | URL, data: URLSearchParams | RezoURLSearchParams | Record<string, any>, options: RezoHttpPatchRequest & {
5034
+ patchForm<T extends string = string>(url: string | URL, data: URLSearchParams | RezoURLSearchParams | Record<string, any>, options: RezoHttpPatchRequest & {
4998
5035
  responseType: "text";
4999
- }): Promise<RezoResponse<string>>;
5000
- patchForm(url: string | URL, string: string, options: RezoHttpPatchRequest & {
5036
+ }): Promise<RezoResponse<T>>;
5037
+ patchForm<T extends string = string>(url: string | URL, string: string, options: RezoHttpPatchRequest & {
5001
5038
  responseType: "text";
5002
- }): Promise<RezoResponse<string>>;
5003
- patchForm(url: string | URL, nullData: null | undefined, options: RezoHttpPatchRequest & {
5039
+ }): Promise<RezoResponse<T>>;
5040
+ patchForm<T extends string = string>(url: string | URL, nullData: null | undefined, options: RezoHttpPatchRequest & {
5004
5041
  responseType: "text";
5005
- }): Promise<RezoResponse<string>>;
5042
+ }): Promise<RezoResponse<T>>;
5006
5043
  patchForm(url: string | URL, data: URLSearchParams | RezoURLSearchParams | Record<string, any>, options: RezoHttpPatchRequest & {
5007
5044
  responseType: "arrayBuffer";
5008
5045
  }): Promise<RezoResponse<ArrayBuffer>>;
@@ -5063,15 +5100,15 @@ export interface httpAdapterPatchOverloads {
5063
5100
  patchMultipart<T = any>(url: string | URL, dataObject: Record<string, any>, options: RezoHttpPatchRequest & {
5064
5101
  responseType: "auto" | "json";
5065
5102
  }): Promise<RezoResponse<T>>;
5066
- patchMultipart(url: string | URL, formData: RezoFormData, options: RezoHttpPatchRequest & {
5103
+ patchMultipart<T extends string = string>(url: string | URL, formData: RezoFormData, options: RezoHttpPatchRequest & {
5067
5104
  responseType: "text";
5068
- }): Promise<RezoResponse<string>>;
5069
- patchMultipart(url: string | URL, formData: FormData, options: RezoHttpPatchRequest & {
5105
+ }): Promise<RezoResponse<T>>;
5106
+ patchMultipart<T extends string = string>(url: string | URL, formData: FormData, options: RezoHttpPatchRequest & {
5070
5107
  responseType: "text";
5071
- }): Promise<RezoResponse<string>>;
5072
- patchMultipart(url: string | URL, dataObject: Record<string, any>, options: RezoHttpPatchRequest & {
5108
+ }): Promise<RezoResponse<T>>;
5109
+ patchMultipart<T extends string = string>(url: string | URL, dataObject: Record<string, any>, options: RezoHttpPatchRequest & {
5073
5110
  responseType: "text";
5074
- }): Promise<RezoResponse<string>>;
5111
+ }): Promise<RezoResponse<T>>;
5075
5112
  patchMultipart(url: string | URL, formData: RezoFormData, options: RezoHttpPatchRequest & {
5076
5113
  responseType: "stream";
5077
5114
  }): RezoStreamResponse;
@@ -5136,9 +5173,9 @@ export interface httpAdapterPutOverloads {
5136
5173
  put(url: string | URL, data: any, options: RezoHttpPutRequest & {
5137
5174
  responseType: "blob";
5138
5175
  }): Promise<RezoResponse<Blob>>;
5139
- put(url: string | URL, data: any, options: RezoHttpPutRequest & {
5176
+ put<T extends string = string>(url: string | URL, data: any, options: RezoHttpPutRequest & {
5140
5177
  responseType: "text";
5141
- }): Promise<RezoResponse<string>>;
5178
+ }): Promise<RezoResponse<T>>;
5142
5179
  put(url: string | URL, data: any, options: RezoHttpPutRequest & {
5143
5180
  responseType: "download";
5144
5181
  }): RezoDownloadResponse;
@@ -5166,15 +5203,15 @@ export interface httpAdapterPutOverloads {
5166
5203
  putJson<T = any>(url: string | URL, nullData: null | undefined, options: RezoHttpPutRequest & {
5167
5204
  responseType: "auto" | "json";
5168
5205
  }): Promise<RezoResponse<T>>;
5169
- putJson(url: string | URL, data: Record<any, any> | Array<any>, options: RezoHttpPutRequest & {
5206
+ putJson<T extends string = string>(url: string | URL, data: Record<any, any> | Array<any>, options: RezoHttpPutRequest & {
5170
5207
  responseType: "text";
5171
- }): Promise<RezoResponse<string>>;
5172
- putJson(url: string | URL, jsonString: string, options: RezoHttpPutRequest & {
5208
+ }): Promise<RezoResponse<T>>;
5209
+ putJson<T extends string = string>(url: string | URL, jsonString: string, options: RezoHttpPutRequest & {
5173
5210
  responseType: "text";
5174
- }): Promise<RezoResponse<string>>;
5175
- putJson(url: string | URL, nullData: null | undefined, options: RezoHttpPutRequest & {
5211
+ }): Promise<RezoResponse<T>>;
5212
+ putJson<T extends string = string>(url: string | URL, nullData: null | undefined, options: RezoHttpPutRequest & {
5176
5213
  responseType: "text";
5177
- }): Promise<RezoResponse<string>>;
5214
+ }): Promise<RezoResponse<T>>;
5178
5215
  putJson(url: string | URL, data: Record<any, any> | Array<any>, options: RezoHttpPutRequest & {
5179
5216
  responseType: "arrayBuffer";
5180
5217
  }): Promise<RezoResponse<ArrayBuffer>>;
@@ -5235,15 +5272,15 @@ export interface httpAdapterPutOverloads {
5235
5272
  putForm<T = any>(url: string | URL, nullData: null | undefined, options: RezoHttpPutRequest & {
5236
5273
  responseType: "auto" | "json";
5237
5274
  }): Promise<RezoResponse<T>>;
5238
- putForm(url: string | URL, data: URLSearchParams | RezoURLSearchParams | Record<string, any>, options: RezoHttpPutRequest & {
5275
+ putForm<T extends string = string>(url: string | URL, data: URLSearchParams | RezoURLSearchParams | Record<string, any>, options: RezoHttpPutRequest & {
5239
5276
  responseType: "text";
5240
- }): Promise<RezoResponse<string>>;
5241
- putForm(url: string | URL, string: string, options: RezoHttpPutRequest & {
5277
+ }): Promise<RezoResponse<T>>;
5278
+ putForm<T extends string = string>(url: string | URL, string: string, options: RezoHttpPutRequest & {
5242
5279
  responseType: "text";
5243
- }): Promise<RezoResponse<string>>;
5244
- putForm(url: string | URL, nullData: null | undefined, options: RezoHttpPutRequest & {
5280
+ }): Promise<RezoResponse<T>>;
5281
+ putForm<T extends string = string>(url: string | URL, nullData: null | undefined, options: RezoHttpPutRequest & {
5245
5282
  responseType: "text";
5246
- }): Promise<RezoResponse<string>>;
5283
+ }): Promise<RezoResponse<T>>;
5247
5284
  putForm(url: string | URL, data: URLSearchParams | RezoURLSearchParams | Record<string, any>, options: RezoHttpPutRequest & {
5248
5285
  responseType: "arrayBuffer";
5249
5286
  }): Promise<RezoResponse<ArrayBuffer>>;
@@ -5304,15 +5341,15 @@ export interface httpAdapterPutOverloads {
5304
5341
  putMultipart<T = any>(url: string | URL, dataObject: Record<string, any>, options: RezoHttpPutRequest & {
5305
5342
  responseType: "auto" | "json";
5306
5343
  }): Promise<RezoResponse<T>>;
5307
- putMultipart(url: string | URL, formData: RezoFormData, options: RezoHttpPutRequest & {
5344
+ putMultipart<T extends string = string>(url: string | URL, formData: RezoFormData, options: RezoHttpPutRequest & {
5308
5345
  responseType: "text";
5309
- }): Promise<RezoResponse<string>>;
5310
- putMultipart(url: string | URL, formData: FormData, options: RezoHttpPutRequest & {
5346
+ }): Promise<RezoResponse<T>>;
5347
+ putMultipart<T extends string = string>(url: string | URL, formData: FormData, options: RezoHttpPutRequest & {
5311
5348
  responseType: "text";
5312
- }): Promise<RezoResponse<string>>;
5313
- putMultipart(url: string | URL, dataObject: Record<string, any>, options: RezoHttpPutRequest & {
5349
+ }): Promise<RezoResponse<T>>;
5350
+ putMultipart<T extends string = string>(url: string | URL, dataObject: Record<string, any>, options: RezoHttpPutRequest & {
5314
5351
  responseType: "text";
5315
- }): Promise<RezoResponse<string>>;
5352
+ }): Promise<RezoResponse<T>>;
5316
5353
  putMultipart(url: string | URL, formData: RezoFormData, options: RezoHttpPutRequest & {
5317
5354
  responseType: "stream";
5318
5355
  }): RezoStreamResponse;
@@ -6061,7 +6098,7 @@ export interface RezoInstance extends Rezo, RezoCallable {
6061
6098
  *
6062
6099
  * IMPORTANT: Update these values when bumping package version.
6063
6100
  */
6064
- export declare const VERSION = "1.0.136";
6101
+ export declare const VERSION = "1.0.138";
6065
6102
  export declare const isRezoError: typeof RezoError.isRezoError;
6066
6103
  export declare const Cancel: typeof RezoError;
6067
6104
  export declare const CancelToken: {
@@ -382,6 +382,7 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
382
382
  const ABSOLUTE_MAX_ATTEMPTS = 50;
383
383
  const visitedUrls = new Set;
384
384
  let totalAttempts = 0;
385
+ let staleSocketRetried = false;
385
386
  config.setSignal();
386
387
  const timeoutClearInstance = config.timeoutClearInstance;
387
388
  delete config.timeoutClearInstance;
@@ -414,6 +415,15 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
414
415
  duration: perform.now()
415
416
  });
416
417
  perform.reset();
418
+ if (response.isStaleSocketReset && !staleSocketRetried) {
419
+ const staleMethod = (fetchOptions.method || "GET").toUpperCase();
420
+ const staleBody = fetchOptions.body;
421
+ const bodyReplayable = staleBody === undefined || staleBody === null || typeof staleBody === "string" || Buffer.isBuffer(staleBody);
422
+ if (["GET", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE"].includes(staleMethod) && bodyReplayable) {
423
+ staleSocketRetried = true;
424
+ continue;
425
+ }
426
+ }
417
427
  if (!retryConfig) {
418
428
  throw response;
419
429
  }
@@ -734,8 +744,11 @@ async function request(config, fetchOptions, requestCount, timing, _stats, _resp
734
744
  if (timeoutManager.hasPhase("total")) {
735
745
  timeoutManager.startPhase("total");
736
746
  }
747
+ let connectionWasReused = false;
748
+ let responseReceived = false;
737
749
  try {
738
750
  const req = httpModule.request(requestOptions, async (res) => {
751
+ responseReceived = true;
739
752
  timeoutManager.clearPhase("headers");
740
753
  if (timeoutManager.hasPhase("body")) {
741
754
  timeoutManager.startPhase("body");
@@ -859,6 +872,8 @@ async function request(config, fetchOptions, requestCount, timing, _stats, _resp
859
872
  let contentLengthCounter = 0;
860
873
  if (streamResult) {
861
874
  if (isRedirected) {
875
+ timeoutManager.clearAll();
876
+ res.resume();
862
877
  resolve(null);
863
878
  return;
864
879
  }
@@ -1134,6 +1149,9 @@ async function request(config, fetchOptions, requestCount, timing, _stats, _resp
1134
1149
  }
1135
1150
  }
1136
1151
  const error = buildSmartError(config, fetchOptions, err);
1152
+ if (err?.code === "ECONNRESET" && connectionWasReused && !responseReceived) {
1153
+ error.isStaleSocketReset = true;
1154
+ }
1137
1155
  resolve(error);
1138
1156
  });
1139
1157
  req.on("socket", (socket) => {
@@ -1164,6 +1182,7 @@ async function request(config, fetchOptions, requestCount, timing, _stats, _resp
1164
1182
  });
1165
1183
  const reqContext = beginRequestContext(socket, isSecure);
1166
1184
  const telemetry = getSocketTelemetry(socket);
1185
+ connectionWasReused = reqContext.connectionReused;
1167
1186
  if (reqContext.connectionReused) {
1168
1187
  timeoutManager.clearPhase("connect");
1169
1188
  if (timeoutManager.hasPhase("headers")) {
@@ -1531,6 +1550,13 @@ function buildHTTPOptions(fetchOptions, isSecure, url) {
1531
1550
  keepAlive,
1532
1551
  keepAliveMsecs: keepAlive ? keepAliveMsecs : undefined
1533
1552
  });
1553
+ } else if (keepAlive === false) {
1554
+ agent = isSecure ? new https.Agent({
1555
+ keepAlive: false,
1556
+ ...useSecureContext ? { secureContext: createSecureContext() } : {},
1557
+ servername: url.hostname,
1558
+ rejectUnauthorized
1559
+ }) : new http.Agent({ keepAlive: false });
1534
1560
  } else if (useAgentPool) {
1535
1561
  const agentPool = getGlobalAgentPool({
1536
1562
  keepAlive: true,
@@ -382,6 +382,7 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
382
382
  const ABSOLUTE_MAX_ATTEMPTS = 50;
383
383
  const visitedUrls = new Set;
384
384
  let totalAttempts = 0;
385
+ let staleSocketRetried = false;
385
386
  config.setSignal();
386
387
  const timeoutClearInstance = config.timeoutClearInstance;
387
388
  delete config.timeoutClearInstance;
@@ -414,6 +415,15 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
414
415
  duration: perform.now()
415
416
  });
416
417
  perform.reset();
418
+ if (response.isStaleSocketReset && !staleSocketRetried) {
419
+ const staleMethod = (fetchOptions.method || "GET").toUpperCase();
420
+ const staleBody = fetchOptions.body;
421
+ const bodyReplayable = staleBody === undefined || staleBody === null || typeof staleBody === "string" || Buffer.isBuffer(staleBody);
422
+ if (["GET", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE"].includes(staleMethod) && bodyReplayable) {
423
+ staleSocketRetried = true;
424
+ continue;
425
+ }
426
+ }
417
427
  if (!retryConfig) {
418
428
  throw response;
419
429
  }
@@ -734,8 +744,11 @@ async function request(config, fetchOptions, requestCount, timing, _stats, _resp
734
744
  if (timeoutManager.hasPhase("total")) {
735
745
  timeoutManager.startPhase("total");
736
746
  }
747
+ let connectionWasReused = false;
748
+ let responseReceived = false;
737
749
  try {
738
750
  const req = httpModule.request(requestOptions, async (res) => {
751
+ responseReceived = true;
739
752
  timeoutManager.clearPhase("headers");
740
753
  if (timeoutManager.hasPhase("body")) {
741
754
  timeoutManager.startPhase("body");
@@ -859,6 +872,8 @@ async function request(config, fetchOptions, requestCount, timing, _stats, _resp
859
872
  let contentLengthCounter = 0;
860
873
  if (streamResult) {
861
874
  if (isRedirected) {
875
+ timeoutManager.clearAll();
876
+ res.resume();
862
877
  resolve(null);
863
878
  return;
864
879
  }
@@ -1134,6 +1149,9 @@ async function request(config, fetchOptions, requestCount, timing, _stats, _resp
1134
1149
  }
1135
1150
  }
1136
1151
  const error = buildSmartError(config, fetchOptions, err);
1152
+ if (err?.code === "ECONNRESET" && connectionWasReused && !responseReceived) {
1153
+ error.isStaleSocketReset = true;
1154
+ }
1137
1155
  resolve(error);
1138
1156
  });
1139
1157
  req.on("socket", (socket) => {
@@ -1164,6 +1182,7 @@ async function request(config, fetchOptions, requestCount, timing, _stats, _resp
1164
1182
  });
1165
1183
  const reqContext = beginRequestContext(socket, isSecure);
1166
1184
  const telemetry = getSocketTelemetry(socket);
1185
+ connectionWasReused = reqContext.connectionReused;
1167
1186
  if (reqContext.connectionReused) {
1168
1187
  timeoutManager.clearPhase("connect");
1169
1188
  if (timeoutManager.hasPhase("headers")) {
@@ -1531,6 +1550,13 @@ function buildHTTPOptions(fetchOptions, isSecure, url) {
1531
1550
  keepAlive,
1532
1551
  keepAliveMsecs: keepAlive ? keepAliveMsecs : undefined
1533
1552
  });
1553
+ } else if (keepAlive === false) {
1554
+ agent = isSecure ? new https.Agent({
1555
+ keepAlive: false,
1556
+ ...useSecureContext ? { secureContext: createSecureContext() } : {},
1557
+ servername: url.hostname,
1558
+ rejectUnauthorized
1559
+ }) : new http.Agent({ keepAlive: false });
1534
1560
  } else if (useAgentPool) {
1535
1561
  const agentPool = getGlobalAgentPool({
1536
1562
  keepAlive: true,
@@ -1,10 +1,10 @@
1
- const _mod_745b4d = require('./picker.cjs');
2
- exports.detectRuntime = _mod_745b4d.detectRuntime;
3
- exports.getAdapterCapabilities = _mod_745b4d.getAdapterCapabilities;
4
- exports.buildAdapterContext = _mod_745b4d.buildAdapterContext;
5
- exports.getAvailableAdapters = _mod_745b4d.getAvailableAdapters;
6
- exports.selectAdapter = _mod_745b4d.selectAdapter;
7
- exports.getAdapterDiagnostics = _mod_745b4d.getAdapterDiagnostics;
8
- exports.createAdapterPicker = _mod_745b4d.createAdapterPicker;
9
- exports.clearAdapterCache = _mod_745b4d.clearAdapterCache;
10
- exports.loadAdapter = _mod_745b4d.loadAdapter;;
1
+ const _mod_jy8lw5 = require('./picker.cjs');
2
+ exports.detectRuntime = _mod_jy8lw5.detectRuntime;
3
+ exports.getAdapterCapabilities = _mod_jy8lw5.getAdapterCapabilities;
4
+ exports.buildAdapterContext = _mod_jy8lw5.buildAdapterContext;
5
+ exports.getAvailableAdapters = _mod_jy8lw5.getAvailableAdapters;
6
+ exports.selectAdapter = _mod_jy8lw5.selectAdapter;
7
+ exports.getAdapterDiagnostics = _mod_jy8lw5.getAdapterDiagnostics;
8
+ exports.createAdapterPicker = _mod_jy8lw5.createAdapterPicker;
9
+ exports.clearAdapterCache = _mod_jy8lw5.clearAdapterCache;
10
+ exports.loadAdapter = _mod_jy8lw5.loadAdapter;;