koonjs 0.4.5 → 0.5.0

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/index.d.ts CHANGED
@@ -1,18 +1,26 @@
1
1
  export type Browser =
2
+ // Desktop browsers
2
3
  | 'chrome' | 'chrome131' | 'chrome132' | 'chrome133' | 'chrome134' | 'chrome135'
3
4
  | 'chrome136' | 'chrome137' | 'chrome138' | 'chrome139' | 'chrome140'
4
5
  | 'chrome141' | 'chrome142' | 'chrome143' | 'chrome144' | 'chrome145'
5
6
  | 'firefox' | 'firefox135' | 'firefox136' | 'firefox137' | 'firefox138'
6
7
  | 'firefox139' | 'firefox140' | 'firefox141' | 'firefox142' | 'firefox143'
7
- | 'firefox144' | 'firefox145' | 'firefox146' | 'firefox147'
8
+ | 'firefox144' | 'firefox145' | 'firefox146' | 'firefox147' | 'firefox148'
8
9
  | 'safari' | 'safari156' | 'safari160' | 'safari161' | 'safari170' | 'safari171'
9
10
  | 'safari172' | 'safari173' | 'safari180' | 'safari181' | 'safari182' | 'safari183'
10
11
  | 'edge' | 'edge131' | 'edge132' | 'edge133' | 'edge134' | 'edge135'
11
12
  | 'edge136' | 'edge137' | 'edge138' | 'edge139' | 'edge140'
12
13
  | 'edge141' | 'edge142' | 'edge143' | 'edge144' | 'edge145'
13
14
  | 'opera' | 'opera124' | 'opera125' | 'opera126' | 'opera127'
15
+ // Mobile browsers
16
+ | 'chrome-mobile' | `chrome-mobile${number}`
17
+ | 'safari-mobile' | `safari-mobile${string}`
18
+ | 'firefox-mobile' | `firefox-mobile${number}`
19
+ // OkHttp (Android apps)
20
+ | 'okhttp' | 'okhttp4' | 'okhttp5'
14
21
  // OS-specific variants
15
- | `${string}-windows` | `${string}-macos` | `${string}-linux`;
22
+ | `${string}-windows` | `${string}-macos` | `${string}-linux`
23
+ | `${string}-android` | `${string}-ios`;
16
24
 
17
25
  export interface KoonOptions {
18
26
  /** Browser profile to impersonate. */
@@ -21,6 +29,8 @@ export interface KoonOptions {
21
29
  profileJson?: string;
22
30
  /** Proxy URL (http://, socks5://). */
23
31
  proxy?: string;
32
+ /** Array of proxy URLs for round-robin rotation. Takes priority over `proxy`. */
33
+ proxies?: string[];
24
34
  /** Request timeout in milliseconds. Default: 30000. */
25
35
  timeout?: number;
26
36
  /** Skip TLS certificate verification. */
@@ -39,19 +49,52 @@ export interface KoonOptions {
39
49
  sessionResumption?: boolean;
40
50
  /** DNS-over-HTTPS provider ("cloudflare", "google", or URL). */
41
51
  doh?: string;
52
+ /** Bind outgoing connections to a specific local IP address. */
53
+ localAddress?: string;
54
+ /** Observe-only hook called before each HTTP request (including redirects). */
55
+ onRequest?: (method: string, url: string) => void;
56
+ /** Observe-only hook called after each HTTP response (including redirects). */
57
+ onResponse?: (status: number, url: string, headers: Array<{ name: string; value: string }>) => void;
58
+ /** Hook called before following a redirect. Return false to stop redirecting and return the 3xx response. */
59
+ onRedirect?: (status: number, url: string, headers: Array<{ name: string; value: string }>) => boolean;
60
+ /** Number of automatic retries on transport errors. With proxy rotation, each retry uses the next proxy. Default: 0. */
61
+ retries?: number;
62
+ /** Locale for Accept-Language header generation. Overrides the profile's Accept-Language to match proxy geography. Examples: "fr-FR", "de", "ja-JP". */
63
+ locale?: string;
64
+ /** Custom headers to send in the HTTP CONNECT tunnel request. Useful for proxy session IDs, geo-targeting, or authentication. */
65
+ proxyHeaders?: Record<string, string>;
66
+ /** Restrict DNS resolution to IPv4 (4) or IPv6 (6). Useful when residential proxies only support IPv4. */
67
+ ipVersion?: 4 | 6;
42
68
  }
43
69
 
44
- export interface KoonResponse {
70
+ export class KoonResponse {
45
71
  /** HTTP status code. */
46
- status: number;
72
+ readonly status: number;
47
73
  /** Response headers as [name, value] pairs. */
48
- headers: Array<{ name: string; value: string }>;
74
+ readonly headers: Array<{ name: string; value: string }>;
49
75
  /** Response body as Buffer. */
50
- body: Buffer;
76
+ readonly body: Buffer;
51
77
  /** HTTP version string (e.g., "HTTP/2.0"). */
52
- version: string;
78
+ readonly version: string;
53
79
  /** Final URL after redirects. */
54
- url: string;
80
+ readonly url: string;
81
+ /** Whether the status code is 2xx (success). */
82
+ readonly ok: boolean;
83
+ /** Approximate bytes sent for this request (headers + body). */
84
+ readonly bytesSent: number;
85
+ /** Approximate bytes received for this response (headers + body, pre-decompression). */
86
+ readonly bytesReceived: number;
87
+ /** Whether TLS session resumption was used for this connection. */
88
+ readonly tlsResumed: boolean;
89
+ /** Whether an existing pooled connection was reused. */
90
+ readonly connectionReused: boolean;
91
+
92
+ /** Decode response body as UTF-8 string. */
93
+ text(): string;
94
+ /** Parse response body as JSON (via JSON.parse()). */
95
+ json(): any;
96
+ /** Look up a response header by name (case-insensitive). */
97
+ header(name: string): string | null;
55
98
  }
56
99
 
57
100
  export interface KoonWsMessage {
@@ -64,6 +107,8 @@ export interface KoonWsMessage {
64
107
  export interface KoonRequestOptions {
65
108
  /** Additional headers for this request. Override constructor-level headers. */
66
109
  headers?: Record<string, string>;
110
+ /** Per-request timeout in milliseconds. Overrides constructor-level timeout. */
111
+ timeout?: number;
67
112
  }
68
113
 
69
114
  export interface KoonMultipartField {
@@ -82,18 +127,31 @@ export interface KoonMultipartField {
82
127
  export class Koon {
83
128
  constructor(options?: KoonOptions);
84
129
 
130
+ /** The User-Agent string from the browser profile. Useful for Puppeteer/Playwright. */
131
+ readonly userAgent: string | null;
132
+
85
133
  get(url: string, options?: KoonRequestOptions): Promise<KoonResponse>;
86
- post(url: string, body?: Buffer, options?: KoonRequestOptions): Promise<KoonResponse>;
87
- put(url: string, body?: Buffer, options?: KoonRequestOptions): Promise<KoonResponse>;
134
+ post(url: string, body?: string | Buffer, options?: KoonRequestOptions): Promise<KoonResponse>;
135
+ put(url: string, body?: string | Buffer, options?: KoonRequestOptions): Promise<KoonResponse>;
88
136
  delete(url: string, options?: KoonRequestOptions): Promise<KoonResponse>;
89
- patch(url: string, body?: Buffer, options?: KoonRequestOptions): Promise<KoonResponse>;
137
+ patch(url: string, body?: string | Buffer, options?: KoonRequestOptions): Promise<KoonResponse>;
90
138
  head(url: string, options?: KoonRequestOptions): Promise<KoonResponse>;
91
- request(method: string, url: string, body?: Buffer, options?: KoonRequestOptions): Promise<KoonResponse>;
139
+ request(method: string, url: string, body?: string | Buffer, options?: KoonRequestOptions): Promise<KoonResponse>;
92
140
  postMultipart(url: string, fields: KoonMultipartField[], options?: KoonRequestOptions): Promise<KoonResponse>;
93
- requestStreaming(method: string, url: string, body?: Buffer, options?: KoonRequestOptions): Promise<KoonStreamingResponse>;
141
+ requestStreaming(method: string, url: string, body?: string | Buffer, options?: KoonRequestOptions): Promise<KoonStreamingResponse>;
94
142
 
95
143
  websocket(url: string, headers?: Record<string, string>): Promise<KoonWebSocket>;
96
144
 
145
+ /** Get the total number of bytes sent across all requests. */
146
+ totalBytesSent(): bigint;
147
+ /** Get the total number of bytes received across all requests. */
148
+ totalBytesReceived(): bigint;
149
+ /** Reset both cumulative byte counters to zero. */
150
+ resetCounters(): void;
151
+
152
+ /** Clear all cookies from the cookie jar. Keeps TLS sessions and connection pool. */
153
+ clearCookies(): void;
154
+
97
155
  exportProfile(): string;
98
156
  saveSession(): string;
99
157
  loadSession(json: string): void;
@@ -106,7 +164,11 @@ export class KoonStreamingResponse {
106
164
  readonly headers: Array<{ name: string; value: string }>;
107
165
  readonly version: string;
108
166
  readonly url: string;
167
+ /** Approximate bytes sent for this request. */
168
+ readonly bytesSent: number;
109
169
 
170
+ /** Approximate bytes received so far (headers + body chunks consumed). */
171
+ bytesReceived(): number;
110
172
  nextChunk(): Promise<Buffer | null>;
111
173
  collect(): Promise<Buffer>;
112
174
  }
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koonjs",
3
- "version": "0.4.5",
3
+ "version": "0.5.0",
4
4
  "description": "Browser-impersonating HTTP client with TLS/HTTP2 fingerprint spoofing",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -14,7 +14,9 @@
14
14
  "koon.*.node"
15
15
  ],
16
16
  "scripts": {
17
- "build": "cargo build --release -p koon-node",
17
+ "build": "cargo build --release -p koon-node && node -e \"require('fs').copyFileSync(require('path').resolve(__dirname,'../../target/release/koon_node.dll'), require('path').resolve(__dirname,'koon.win32-x64-msvc.node'))\"",
18
+ "build:linux": "cargo build --release -p koon-node && cp ../../target/release/libkoon_node.so koon.linux-x64-gnu.node",
19
+ "build:macos": "cargo build --release -p koon-node && cp ../../target/release/libkoon_node.dylib koon.darwin-$(uname -m).node",
18
20
  "test": "node ../../test_node.cjs"
19
21
  },
20
22
  "keywords": [