hazo_scrape 1.0.1 → 1.2.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/CHANGE_LOG.md +19 -0
- package/README.md +105 -0
- package/dist/fetch/cache.d.ts +39 -0
- package/dist/fetch/cache.d.ts.map +1 -0
- package/dist/fetch/cache.js +82 -0
- package/dist/fetch/config.d.ts +44 -0
- package/dist/fetch/config.d.ts.map +1 -0
- package/dist/fetch/config.js +174 -0
- package/dist/fetch/headers.d.ts +19 -0
- package/dist/fetch/headers.d.ts.map +1 -0
- package/dist/fetch/headers.js +85 -0
- package/dist/fetch/index.d.ts +10 -0
- package/dist/fetch/index.d.ts.map +1 -0
- package/dist/fetch/index.js +326 -0
- package/dist/fetch/proxy.d.ts +43 -0
- package/dist/fetch/proxy.d.ts.map +1 -0
- package/dist/fetch/proxy.js +96 -0
- package/dist/fetch/ratelimit.d.ts +15 -0
- package/dist/fetch/ratelimit.d.ts.map +1 -0
- package/dist/fetch/ratelimit.js +35 -0
- package/dist/fetch/robots.d.ts +30 -0
- package/dist/fetch/robots.d.ts.map +1 -0
- package/dist/fetch/robots.js +84 -0
- package/dist/fetch/scrape.d.ts +29 -0
- package/dist/fetch/scrape.d.ts.map +1 -0
- package/dist/fetch/scrape.js +27 -0
- package/dist/fetch/types.d.ts +55 -0
- package/dist/fetch/types.d.ts.map +1 -0
- package/dist/fetch/types.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/package.json +10 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrape.d.ts","sourceRoot":"","sources":["../../src/fetch/scrape.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9E,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,iDAAiD;IACjD,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,EAAE,SAAS,EAAE,CAAC;IAClB,kEAAkE;IAClE,OAAO,EAAE,OAAO,CAAC;IACjB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,KAAK,CAAA;KAAE,CAAC;CAC/E;AAED,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,cAAc,EACxB,IAAI,GAAE,kBAAuB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAqBtB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// hazo_scrape/src/fetch/scrape.ts — Phase 6: scrapeTable orchestrator
|
|
2
|
+
//
|
|
3
|
+
// Wires the fetch layer (fetchDocument) to the pure, network-free parse layer
|
|
4
|
+
// (extractTable / mapColumns / mapRows). This module stays fully generic — no
|
|
5
|
+
// ASX/stock/dividend-specific logic — and never calls an LLM (`usedLlm` is
|
|
6
|
+
// always the literal `false` this session; a future phase may add an LLM
|
|
7
|
+
// fallback path that flips this at runtime).
|
|
8
|
+
import { fetchDocument } from './index.js';
|
|
9
|
+
import { extractTable, mapColumns, mapRows } from '../parse/index.js';
|
|
10
|
+
export async function scrapeTable(url, keywords, opts = {}) {
|
|
11
|
+
const res = await fetchDocument(url, opts);
|
|
12
|
+
const table = extractTable(res.body, opts.select ? { select: opts.select } : undefined);
|
|
13
|
+
const columnMap = mapColumns(table.headers, keywords, {
|
|
14
|
+
dateGuard: opts.dateGuard ?? false,
|
|
15
|
+
...(opts.required ? { required: opts.required } : {}),
|
|
16
|
+
});
|
|
17
|
+
const rows = mapRows({ headers: table.headers, rows: table.rows }, columnMap, keywords);
|
|
18
|
+
return {
|
|
19
|
+
headers: table.headers,
|
|
20
|
+
columnMap,
|
|
21
|
+
unmatched: columnMap.unmatched,
|
|
22
|
+
rows,
|
|
23
|
+
partial: !columnMap.ok,
|
|
24
|
+
...(table.warning ? { warning: table.warning } : {}),
|
|
25
|
+
source: { url, finalUrl: res.finalUrl, fromCache: res.fromCache, usedLlm: false },
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ResolvedFetchConfig } from './config.js';
|
|
2
|
+
export type EffectiveConfig = ResolvedFetchConfig;
|
|
3
|
+
export interface FetchOptions {
|
|
4
|
+
/** Optional INI config path. Omitted → defaults only (see resolveFetchConfig). */
|
|
5
|
+
configPath?: string;
|
|
6
|
+
userAgent?: string;
|
|
7
|
+
uaPool?: string[] | boolean;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
acceptLanguage?: string;
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
maxRedirects?: number;
|
|
12
|
+
retry?: {
|
|
13
|
+
maxAttempts?: number;
|
|
14
|
+
backoffMs?: number;
|
|
15
|
+
backoffFactor?: number;
|
|
16
|
+
jitter?: boolean;
|
|
17
|
+
retryOn?: number[];
|
|
18
|
+
};
|
|
19
|
+
rateLimit?: {
|
|
20
|
+
minIntervalMs?: number;
|
|
21
|
+
perHost?: boolean;
|
|
22
|
+
};
|
|
23
|
+
proxy?: {
|
|
24
|
+
urls?: string[];
|
|
25
|
+
username?: string;
|
|
26
|
+
password?: string;
|
|
27
|
+
rotation?: 'round_robin';
|
|
28
|
+
cooldownMs?: number;
|
|
29
|
+
};
|
|
30
|
+
cache?: {
|
|
31
|
+
enabled?: boolean;
|
|
32
|
+
dir?: string;
|
|
33
|
+
ttlSeconds?: number;
|
|
34
|
+
};
|
|
35
|
+
robots?: {
|
|
36
|
+
respect?: boolean;
|
|
37
|
+
};
|
|
38
|
+
/** Test seam — passed through to safeFetch's `deps.fetchImpl`. */
|
|
39
|
+
fetchImpl?: typeof fetch;
|
|
40
|
+
}
|
|
41
|
+
export interface FetchResult {
|
|
42
|
+
url: string;
|
|
43
|
+
finalUrl: string;
|
|
44
|
+
status: number;
|
|
45
|
+
statusText: string;
|
|
46
|
+
ok: boolean;
|
|
47
|
+
headers: Record<string, string>;
|
|
48
|
+
body: string;
|
|
49
|
+
contentType?: string;
|
|
50
|
+
fromCache: boolean;
|
|
51
|
+
attempts: number;
|
|
52
|
+
timingMs: number;
|
|
53
|
+
usedProxy?: string;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fetch/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAKvD,MAAM,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,kFAAkF;IAClF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE;QACN,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MA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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
// hazo_scrape/src/index.ts — Server entry point
|
|
2
2
|
// Import hazo_core via peer dep: import { HazoError } from 'hazo_core';
|
|
3
|
+
//
|
|
4
|
+
// SERVER-ONLY: this `.` entry (and the `./fetch` subpath entry) pull in
|
|
5
|
+
// undici, hazo_secure, node:fs, and node:crypto via the fetch layer below —
|
|
6
|
+
// do not import either from client/browser bundles. `./parse` remains the
|
|
7
|
+
// client-safe, network-free entry (pure HTML parsing, no I/O).
|
|
3
8
|
export * from './lib/index.js';
|
|
9
|
+
export * from './fetch/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hazo_scrape",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Generic source-agnostic web scraping engine with a network-free parse core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
"types": "./dist/parse/index.d.ts",
|
|
15
15
|
"import": "./dist/parse/index.js"
|
|
16
16
|
},
|
|
17
|
+
"./fetch": {
|
|
18
|
+
"types": "./dist/fetch/index.d.ts",
|
|
19
|
+
"import": "./dist/fetch/index.js"
|
|
20
|
+
},
|
|
17
21
|
"./package.json": "./package.json"
|
|
18
22
|
},
|
|
19
23
|
"files": [
|
|
@@ -55,6 +59,10 @@
|
|
|
55
59
|
"author": "Pubs Abayasiri",
|
|
56
60
|
"license": "MIT",
|
|
57
61
|
"dependencies": {
|
|
58
|
-
"cheerio": "^1.2.0"
|
|
62
|
+
"cheerio": "^1.2.0",
|
|
63
|
+
"hazo_config": "^2.4.1",
|
|
64
|
+
"hazo_secure": "^1.4.0",
|
|
65
|
+
"robots-parser": "^3.0.1",
|
|
66
|
+
"undici": "^7.28.0"
|
|
59
67
|
}
|
|
60
68
|
}
|