@grabbit-labs/dynafetch 0.2.1 → 0.2.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Grabbit Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Binary file
Binary file
Binary file
Binary file
Binary file
package/dist/index.d.ts CHANGED
@@ -16,6 +16,12 @@ export type DynafetchStrategy =
16
16
  | "framework-probe"
17
17
  | "jsdom-fallback";
18
18
 
19
+ export type DynafetchHarvestSnapshot = {
20
+ html: string;
21
+ initialState: Record<string, unknown>;
22
+ scripts: Array<{ url?: string }>;
23
+ };
24
+
19
25
  export type DynafetchProxyScope = "page" | "api" | "assets";
20
26
 
21
27
  export type DynafetchProxyConfig = string | {
@@ -24,87 +30,20 @@ export type DynafetchProxyConfig = string | {
24
30
  };
25
31
 
26
32
  export type DynafetchOptions = {
27
- /** Target URL to fetch and render. */
28
33
  url: string;
29
-
30
- /**
31
- * Extra request headers merged on top of the default Chrome 146 headers.
32
- * Any header you set here overrides the built-in default for that key.
33
- * Headers you don't set keep their Chrome-like defaults (User-Agent,
34
- * Accept, Sec-Fetch-*, etc.).
35
- */
36
34
  headers?: Record<string, string>;
37
-
38
- /**
39
- * Cookies to include. Accepts:
40
- * - `string` — raw `Cookie` header value (`"k1=v1; k2=v2"`)
41
- * - `string[]` — individual `name=value` pairs
42
- * - `Record<string, string>` — key/value map
43
- */
44
35
  cookies?: Record<string, string> | string | string[];
45
-
46
- /**
47
- * Proxy configuration. Routes requests through an HTTP/HTTPS proxy with
48
- * TLS fingerprint preservation.
49
- *
50
- * ```ts
51
- * // Proxy all requests
52
- * proxy: "http://user:pass@ip:port"
53
- *
54
- * // Only proxy the page fetch and API calls (skip static assets)
55
- * proxy: { url: "http://user:pass@ip:port", only: ["page", "api"] }
56
- * ```
57
- */
58
36
  proxy?: DynafetchProxyConfig;
59
-
60
- /** Overall timeout for the entire operation in milliseconds. */
61
37
  timeoutMs?: number;
62
-
63
- /** TLS client profile to impersonate. @default `"chrome_146"` */
64
38
  browserProfile?: string;
65
-
66
- /** Advisory limit on sub-requests the executor may issue. */
67
39
  maxSubrequests?: number;
68
-
69
- /** Allow JSDOM-based script execution for dynamic pages. @default `true` */
70
40
  allowJsdomFallback?: boolean;
71
-
72
- /** Pre-fetch external `<script src>` tags during harvest. @default `true` */
73
41
  prefetchExternalScripts?: boolean;
74
-
75
- /** Pre-fetch `<link rel="modulepreload">` assets during harvest. @default `true` */
76
42
  prefetchModulePreloads?: boolean;
77
-
78
- /**
79
- * Controls whether non-critical third-party scripts (analytics, ads, chat
80
- * widgets) are executed.
81
- * @default `"skip-noncritical"`
82
- */
83
43
  thirdPartyPolicy?: DynafetchThirdPartyPolicy;
84
-
85
- /**
86
- * Minimum time (ms) to wait before checking if the page is idle.
87
- * @default 75
88
- */
89
44
  minWaitMs?: number;
90
-
91
- /**
92
- * How long (ms) the page must be completely idle (zero pending requests)
93
- * before we consider it settled.
94
- * @default 100
95
- */
96
45
  idleWaitMs?: number;
97
-
98
- /**
99
- * Hard upper bound (ms) on how long to wait for the page to settle.
100
- * @default 2000
101
- */
102
46
  maxWaitMs?: number;
103
-
104
- /**
105
- * Maximum time (ms) to wait for ES module bundling (esbuild) to complete.
106
- * @default 6000
107
- */
108
47
  moduleWaitMs?: number;
109
48
  };
110
49
 
@@ -133,60 +72,64 @@ export type DynafetchPlan = {
133
72
  reason: string;
134
73
  };
135
74
 
75
+ export type DynafetchNetRequest = {
76
+ method: string;
77
+ url: string;
78
+ headers: Record<string, string>;
79
+ headerOrder?: string[];
80
+ body: string;
81
+ proxy?: string;
82
+ };
83
+
84
+ export type DynafetchNetResponse = {
85
+ status: number;
86
+ body: string;
87
+ headers: Record<string, string>;
88
+ finalUrl?: string;
89
+ error?: string;
90
+ retried?: boolean;
91
+ };
92
+
93
+ export type DynafetchSessionOptions = {
94
+ browserProfile?: string;
95
+ timeoutSeconds?: number;
96
+ proxy?: string;
97
+ rpcTimeoutMs?: number;
98
+ };
99
+
100
+ export type DynafetchNetFetchOptions = DynafetchSessionOptions & {
101
+ followRedirect?: boolean;
102
+ maxRedirects?: number;
103
+ };
104
+
136
105
  export declare class DynafetchInputError extends Error {
137
106
  status: number;
138
107
  constructor(message: string, status?: number);
139
108
  }
140
109
 
141
- /**
142
- * Fetch a URL with full browser emulation — Chrome TLS fingerprinting,
143
- * JavaScript execution, and network interception — then return the
144
- * rendered HTML and metadata.
145
- *
146
- * Uses Chrome 146 headers by default. Any headers you provide are merged
147
- * on top — your values override the defaults, everything else stays.
148
- *
149
- * @example
150
- * ```ts
151
- * // Minimal
152
- * const page = await dynafetch("https://example.com");
153
- *
154
- * // With custom headers, cookies, and proxy
155
- * const page = await dynafetch({
156
- * url: "https://example.com",
157
- * headers: { "Accept-Language": "fr-FR" },
158
- * cookies: { session: "abc123" },
159
- * proxy: "http://user:pass@ip:port",
160
- * });
161
- *
162
- * // Smart proxy — only proxy the HTML page and API calls
163
- * const page = await dynafetch({
164
- * url: "https://example.com",
165
- * proxy: { url: "http://user:pass@ip:port", only: ["page", "api"] },
166
- * });
167
- * ```
168
- *
169
- * **Options at a glance:**
170
- *
171
- * | Option | Default | Description |
172
- * |---|---|---|
173
- * | `headers` | Chrome 146 | Merged on top of defaults — yours override on conflict |
174
- * | `cookies` | none | String, array, or `Record<string, string>` |
175
- * | `proxy` | none | `"http://user:pass@ip:port"` or `{ url, only: ["page","api","assets"] }` |
176
- * | `minWaitMs` | `75` | Min ms before checking if page is idle |
177
- * | `idleWaitMs` | `100` | Ms of zero pending requests = settled |
178
- * | `maxWaitMs` | `2000` | Hard cap on wait time regardless of activity |
179
- * | `moduleWaitMs` | `6000` | Max ms for ES module bundling (esbuild) |
180
- * | `timeoutMs` | none | Overall timeout for the entire operation |
181
- * | `thirdPartyPolicy` | `"skip-noncritical"` | Skip analytics/ads/chat scripts |
182
- *
183
- * **Proxy scopes** — when using `{ url, only }`:
184
- * - `"page"` — initial HTML document fetch
185
- * - `"api"` — fetch() and XHR calls from page scripts
186
- * - `"assets"` — JS scripts, ES modules, static resources
187
- *
188
- * **Speed presets:**
189
- * - Fast: `{ maxWaitMs: 1000, idleWaitMs: 50 }`
190
- * - Thorough: `{ maxWaitMs: 5000, idleWaitMs: 200 }`
191
- */
110
+ export declare function detectFramework(harvest: DynafetchHarvestSnapshot): DynafetchFramework;
111
+
112
+ export declare function planDynafetch(
113
+ framework: DynafetchFramework,
114
+ harvest: DynafetchHarvestSnapshot,
115
+ allowJsdomFallback: boolean,
116
+ ): DynafetchPlan;
117
+
118
+ export declare function withDynafetchSession<T>(
119
+ options: DynafetchSessionOptions,
120
+ run: () => Promise<T>,
121
+ ): Promise<T>;
122
+
123
+ export declare function dynafetchNetHealth(): Promise<{ ok: boolean; service: string }>;
124
+
125
+ export declare function dynafetchNetFetch(
126
+ request: DynafetchNetRequest,
127
+ options?: DynafetchNetFetchOptions,
128
+ ): Promise<DynafetchNetResponse>;
129
+
130
+ export declare function dynafetchNetBatchFetch(
131
+ requests: DynafetchNetRequest[],
132
+ options?: DynafetchNetFetchOptions,
133
+ ): Promise<DynafetchNetResponse[]>;
134
+
192
135
  export declare function dynafetch(input: string | DynafetchOptions): Promise<DynafetchResult>;