@opencraw/cli 0.1.53 → 0.1.55
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/dist/access/index.d.ts +2 -0
- package/dist/access/resolve-access.use-case.d.ts +12 -0
- package/dist/arguments/command.contract.d.ts +86 -0
- package/dist/arguments/index.d.ts +3 -0
- package/dist/arguments/parse-arguments.algorithm.d.ts +12 -0
- package/dist/diff/diff-files.use-case.d.ts +22 -0
- package/dist/diff/diff-report.mapper.d.ts +12 -0
- package/dist/diff/index.d.ts +3 -0
- package/dist/export/export-records.use-case.d.ts +14 -0
- package/dist/export/index.d.ts +2 -0
- package/dist/hooks-module/index.d.ts +3 -0
- package/dist/hooks-module/load-hooks.repository.d.ts +47 -0
- package/dist/index.d.ts +18 -1
- package/dist/index.esm.js +354 -740
- package/dist/main.d.ts +12 -0
- package/dist/probe/index.d.ts +6 -0
- package/dist/probe/probe-page.use-case.d.ts +65 -0
- package/dist/probe/probe-report.mapper.d.ts +59 -0
- package/dist/recipe-files/index.d.ts +3 -0
- package/dist/recipe-files/read-recipe-files.repository.d.ts +26 -0
- package/dist/run/index.d.ts +3 -0
- package/dist/run/load-for-run.use-case.d.ts +13 -0
- package/dist/run/run-recipes.use-case.d.ts +17 -0
- package/dist/studio/index.d.ts +3 -0
- package/dist/studio/run-studio.use-case.d.ts +32 -0
- package/dist/terminal/index.d.ts +3 -0
- package/dist/terminal/terminal.client.d.ts +4 -0
- package/dist/terminal/terminal.contract.d.ts +6 -0
- package/dist/validate/index.d.ts +2 -0
- package/dist/validate/validate-recipes.use-case.d.ts +10 -0
- package/package.json +10 -38
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AccessConfig } from '@opencraw/core';
|
|
2
|
+
import type { CommonOptions } from '../arguments';
|
|
3
|
+
/**
|
|
4
|
+
* The access config a command runs with: the file `--access` (or
|
|
5
|
+
* `OPENCRAW_ACCESS`) names, with `--access-profile` as its default.
|
|
6
|
+
*
|
|
7
|
+
* @param options - The command's shared options.
|
|
8
|
+
* @returns The config, or `undefined` for direct access.
|
|
9
|
+
* @throws Error when a profile is asked for without a config, or is not in it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveAccess(options: CommonOptions): Promise<AccessConfig | undefined>;
|
|
12
|
+
//# sourceMappingURL=resolve-access.use-case.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Options every command shares. */
|
|
2
|
+
export interface CommonOptions {
|
|
3
|
+
/** A browser binary other than the one Playwright installed. */
|
|
4
|
+
browserPath?: string;
|
|
5
|
+
/** Accept an intercepting proxy's certificate. */
|
|
6
|
+
insecureTls: boolean;
|
|
7
|
+
/** A user agent for requests and the browser. */
|
|
8
|
+
userAgent?: string;
|
|
9
|
+
/** An access config file (proxy profiles); `OPENCRAW_ACCESS` when not given. */
|
|
10
|
+
access?: string;
|
|
11
|
+
/** The access profile to use by default, overriding the config's `default`. */
|
|
12
|
+
accessProfile?: string;
|
|
13
|
+
/** A plugins module: hooks, access plugins; `--hooks` / `OPENCRAW_PLUGINS` / `OPENCRAW_HOOKS` too. */
|
|
14
|
+
plugins?: string;
|
|
15
|
+
}
|
|
16
|
+
export type Command = {
|
|
17
|
+
name: 'help';
|
|
18
|
+
} | {
|
|
19
|
+
name: 'version';
|
|
20
|
+
} | {
|
|
21
|
+
name: 'validate';
|
|
22
|
+
paths: string[];
|
|
23
|
+
} | {
|
|
24
|
+
name: 'export';
|
|
25
|
+
/** A finished run's JSON Lines file. */
|
|
26
|
+
records: string;
|
|
27
|
+
/** The output recipe the records were mapped to: it names the columns. */
|
|
28
|
+
output: string;
|
|
29
|
+
/** The file to write; its extension is the format. */
|
|
30
|
+
out: string;
|
|
31
|
+
options: CommonOptions;
|
|
32
|
+
} | {
|
|
33
|
+
name: 'diff';
|
|
34
|
+
previous: string;
|
|
35
|
+
current: string;
|
|
36
|
+
/** The fields that identify a record; empty uses each line's `_key`. */
|
|
37
|
+
key: string[];
|
|
38
|
+
/** Fields left out of the comparison. */
|
|
39
|
+
ignore: string[];
|
|
40
|
+
/** Where to write the changes as JSON Lines. */
|
|
41
|
+
changes?: string;
|
|
42
|
+
} | {
|
|
43
|
+
name: 'run';
|
|
44
|
+
paths: string[];
|
|
45
|
+
/** A JSON Lines file; records go to stdout without it. */
|
|
46
|
+
out?: string;
|
|
47
|
+
append: boolean;
|
|
48
|
+
resume: boolean;
|
|
49
|
+
trace: boolean;
|
|
50
|
+
/** One record per input, with the scope it was mapped from. */
|
|
51
|
+
dryRun: boolean;
|
|
52
|
+
/** Run only the input recipes with these ids. */
|
|
53
|
+
only: string[];
|
|
54
|
+
headed: boolean;
|
|
55
|
+
/** A previous run's JSON Lines file to compare this run's records with. */
|
|
56
|
+
diff?: string;
|
|
57
|
+
/** Where to write the changes `diff` finds, as JSON Lines. */
|
|
58
|
+
changes?: string;
|
|
59
|
+
/** How many input recipes run at once. */
|
|
60
|
+
parallel?: number;
|
|
61
|
+
/** Tries per request for recipes whose `limits.retry` says nothing (1 turns retrying off). */
|
|
62
|
+
retries?: number;
|
|
63
|
+
/** Where `session.browserProfile` profiles live; `OPENCRAW_PROFILES` when not given. */
|
|
64
|
+
profiles?: string;
|
|
65
|
+
/** Per-site politeness across every recipe: overrides the access config's `throttle` defaults. */
|
|
66
|
+
throttle: {
|
|
67
|
+
delayMs?: number;
|
|
68
|
+
concurrency?: number;
|
|
69
|
+
};
|
|
70
|
+
options: CommonOptions;
|
|
71
|
+
} | {
|
|
72
|
+
name: 'probe';
|
|
73
|
+
url: string;
|
|
74
|
+
/** Also render the page in a browser and watch the JSON it fetches. */
|
|
75
|
+
browser: boolean;
|
|
76
|
+
options: CommonOptions;
|
|
77
|
+
} | {
|
|
78
|
+
name: 'studio';
|
|
79
|
+
/** The recipe folder to open; the current directory when not given. */
|
|
80
|
+
folder?: string;
|
|
81
|
+
/** A hooks or plugins module to run recipes with (`--hooks`, `--plugins`, `OPENCRAW_HOOKS`, `OPENCRAW_PLUGINS`; issue #150). */
|
|
82
|
+
plugins?: string;
|
|
83
|
+
/** A folder, recipe file or document the printed link opens straight away (`--open`, issue #235). */
|
|
84
|
+
open?: string;
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=command.contract.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Command } from './command.contract';
|
|
2
|
+
export declare const USAGE = "opencraw <command> [options]\n\nCommands\n validate <recipe files or directories...> Parse and bind the recipes; list every problem with its path.\n run <recipe files or directories...> Crawl. Records go to --out (its extension picks the format), or to stdout as JSON Lines.\n probe <url> Fetch a page and report where its data lives.\n diff <previous.jsonl> <current.jsonl> Compare two runs' records by key: added, removed, changed.\n export <records.jsonl> <output recipe> --out <file>\n Write a finished run's records again in another format (the extension\n of --out chooses it, as for run).\n studio [folder] [--open <path>] Open a recipe folder in the browser: run samples, read\n the trace next to the page (needs @opencraw/studio).\n --open prints a link that opens a folder, recipe or\n document straight away.\n\nOptions for run\n --out <file> Write records to this file; the extension is the format: .jsonl, .json, .csv, .xlsx, .yml/.yaml,\n .html (a page that looks like Studio) or .pdf (that page, printed; needs Chromium). Any other\n extension is an error. Default: stdout as JSON Lines.\n --append Keep what --out holds and add to it (each line carries _key); .jsonl only.\n --resume Skip records --out already has (needs --append).\n --only <id> Run only this input recipe (repeatable).\n --dry-run One record per input, printed with the scope it was mapped from.\n --trace Print the crawl trace to stderr.\n --headed Show the browser.\n --parallel <n> Run this many input recipes at once (default 1). Iterations inside a recipe\n follow its limits.concurrency.\n --retries <n> Tries per request that fails in passing (connection, timeout, 429, 5xx), for\n recipes whose limits.retry says nothing. Default 3; 1 turns retrying off.\n --profiles <dir> Where recipes' session.browserProfile profiles live (or OPENCRAW_PROFILES;\n default .opencraw/profiles).\n --diff <file> Compare this run's records with a previous run's JSON Lines file (it may be\n --out itself: it is read before the crawl). Keys come from the output recipe.\n --host-delay <ms> At least this long between two requests to one site, across every recipe.\n --host-concurrency <n>\n At most this many requests to one site in flight, across every recipe.\n Both override the access config's \"throttle\" defaults.\n\nOptions for diff\n --key <a,b> The fields that identify a record (default: each line's _key).\n --ignore <a,b> Fields left out of the comparison (a date the crawl stamps, say).\n --changes <file> Also write every change as a JSON line (run --diff takes it too).\n\nOptions for probe\n --browser Also render the page in a browser and list the JSON it fetches.\n\nOptions for both\n --browser-path <p> A browser binary other than the one Playwright installed (or OPENCRAW_CHROMIUM).\n --insecure-tls Accept an intercepting proxy's certificate (or OPENCRAW_INSECURE_TLS=1).\n --user-agent <ua> The user agent to send.\n --access <file> An access config: proxy profiles, credentials as {{env.NAME}} (or OPENCRAW_ACCESS).\n --access-profile <name>\n The access profile to use when a recipe names none.\n --plugins <file> A JavaScript module exporting hooks (the recipes' hook steps and transforms),\n accessPlugins (for { kind: \"plugin\" } access profiles) and captchaSolvers\n (for session.captcha and captcha steps); --hooks, or OPENCRAW_PLUGINS /\n OPENCRAW_HOOKS. It runs as your code: trust it.\n --help, --version";
|
|
3
|
+
/**
|
|
4
|
+
* Turns argv into a command.
|
|
5
|
+
*
|
|
6
|
+
* @param argv - The arguments after the program name.
|
|
7
|
+
* @param env - The environment, for the defaults some options have.
|
|
8
|
+
* @returns The command.
|
|
9
|
+
* @throws Error with a usage message on bad input.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseArguments(argv: readonly string[], env?: Record<string, string | undefined>): Command;
|
|
12
|
+
//# sourceMappingURL=parse-arguments.algorithm.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RecordDiff } from '@opencraw/core';
|
|
2
|
+
import type { Command } from '../arguments';
|
|
3
|
+
import type { Terminal } from '../terminal';
|
|
4
|
+
/**
|
|
5
|
+
* Compares two runs' JSON Lines files and prints what changed; with
|
|
6
|
+
* `--changes`, writes every change as a JSON line too.
|
|
7
|
+
*
|
|
8
|
+
* @param command - The parsed `diff` command.
|
|
9
|
+
* @param terminal - Where the report goes.
|
|
10
|
+
* @returns The exit code: 0, or 1 when a file cannot be read or has no key.
|
|
11
|
+
*/
|
|
12
|
+
export declare function diffFiles(command: Extract<Command, {
|
|
13
|
+
name: 'diff';
|
|
14
|
+
}>, terminal: Terminal): Promise<number>;
|
|
15
|
+
/**
|
|
16
|
+
* Writes a diff's changes as JSON Lines: `{ change, key, before?, after?, fields? }`.
|
|
17
|
+
*
|
|
18
|
+
* @param path - The file.
|
|
19
|
+
* @param diff - The diff.
|
|
20
|
+
*/
|
|
21
|
+
export declare function writeChanges(path: string, diff: RecordDiff): Promise<void>;
|
|
22
|
+
//# sourceMappingURL=diff-files.use-case.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RecordDiff } from '@opencraw/core';
|
|
2
|
+
/**
|
|
3
|
+
* A diff as people read it: the counts, a warning when the run lost most of
|
|
4
|
+
* its records, then one line per change, `-` removed, `~` changed (with each
|
|
5
|
+
* field's before → after), `+` added.
|
|
6
|
+
*
|
|
7
|
+
* @param diff - The diff.
|
|
8
|
+
* @param limit - Changes listed at most.
|
|
9
|
+
* @returns The lines.
|
|
10
|
+
*/
|
|
11
|
+
export declare function diffReport(diff: RecordDiff, limit?: number): string[];
|
|
12
|
+
//# sourceMappingURL=diff-report.mapper.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Command } from '../arguments';
|
|
2
|
+
import type { Terminal } from '../terminal';
|
|
3
|
+
/**
|
|
4
|
+
* Writes a finished run's JSON Lines file again in another format: the extension of `--out` chooses it, as it does for `run`. The output recipe
|
|
5
|
+
* supplies the columns (its fields, in order, with their types and descriptions).
|
|
6
|
+
*
|
|
7
|
+
* @param command - The parsed `export` command.
|
|
8
|
+
* @param terminal - Where the result and errors go.
|
|
9
|
+
* @returns The exit code: 0, or 1 when a file cannot be read, the recipe is not an output recipe, or the extension names no format.
|
|
10
|
+
*/
|
|
11
|
+
export declare function exportRecords(command: Extract<Command, {
|
|
12
|
+
name: 'export';
|
|
13
|
+
}>, terminal: Terminal): Promise<number>;
|
|
14
|
+
//# sourceMappingURL=export-records.use-case.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AccessPlugin, CaptchaSolver, HookMap } from '@opencraw/core';
|
|
2
|
+
/** What a plugins module provides: hooks for `hook` steps and transforms, and plugins the engine calls. */
|
|
3
|
+
export interface PluginModule {
|
|
4
|
+
hooks: HookMap;
|
|
5
|
+
/** Access plugins: `{ kind: "plugin", name }` profiles in the access config use them. */
|
|
6
|
+
accessPlugins: AccessPlugin[];
|
|
7
|
+
/** Captcha solvers: recipes name them in `session.captcha.solver` and `captcha` steps. */
|
|
8
|
+
captchaSolvers: CaptchaSolver[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Loads a plugins module: a JavaScript module whose named exports `hooks`
|
|
12
|
+
* (`{ name: function }`), `accessPlugins` (`[{ name, lease }]`) and
|
|
13
|
+
* `captchaSolvers` (`[{ name, solve }]`) give what recipes and access profiles
|
|
14
|
+
* refer to by name:
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* export const hooks = { positive: v => v > 0 }
|
|
18
|
+
* export const accessPlugins = [{ name: 'browserbase', lease: async () => ({ cdp: { endpoint } }) }]
|
|
19
|
+
* export const captchaSolvers = [{ name: 'capsolver', solve: async (challenge, { page }) => ({ status: 'solved' }) }]
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* A module with none of those names is a bare hooks module, as before: its
|
|
23
|
+
* default export when that is an object of functions, else its named function
|
|
24
|
+
* exports.
|
|
25
|
+
*
|
|
26
|
+
* The module runs with the caller's privileges, like any code the caller
|
|
27
|
+
* imports: point this only at a file you trust.
|
|
28
|
+
*
|
|
29
|
+
* @param path - A `.mjs` / `.js` / `.cjs` file, or a `.ts` / `.mts` file on a Node that strips types (22.18+).
|
|
30
|
+
* @param importModule - How to import it; `import()` unless a test says otherwise.
|
|
31
|
+
* @returns The hooks and plugins.
|
|
32
|
+
* @throws Error naming the file when it cannot be imported, provides nothing,
|
|
33
|
+
* or provides something that is not what its name promises.
|
|
34
|
+
*/
|
|
35
|
+
export declare function loadPlugins(path: string, importModule?: ModuleImporter): Promise<PluginModule>;
|
|
36
|
+
/**
|
|
37
|
+
* Loads the hooks of a hooks or plugins module (see {@link loadPlugins}).
|
|
38
|
+
*
|
|
39
|
+
* @param path - A `.mjs` / `.js` / `.cjs` file.
|
|
40
|
+
* @param importModule - How to import it.
|
|
41
|
+
* @returns The hooks by name.
|
|
42
|
+
* @throws Error naming the file when it cannot be imported or exports no hooks.
|
|
43
|
+
*/
|
|
44
|
+
export declare function loadHooks(path: string, importModule?: ModuleImporter): Promise<HookMap>;
|
|
45
|
+
/** Imports a module by URL, returning its namespace. */
|
|
46
|
+
export type ModuleImporter = (url: string) => Promise<Record<string, unknown>>;
|
|
47
|
+
//# sourceMappingURL=load-hooks.repository.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { main } from './main';
|
|
2
|
+
export { parseArguments, USAGE } from './arguments';
|
|
3
|
+
export type { Command } from './arguments';
|
|
4
|
+
export { processTerminal } from './terminal';
|
|
5
|
+
export type { Terminal } from './terminal';
|
|
6
|
+
export { findData, probeReport, probeUrl } from './probe';
|
|
7
|
+
export type { ProbeFindings, ProbeResult, ProbeOptions } from './probe';
|
|
8
|
+
export { readRecipeFiles } from './recipe-files';
|
|
9
|
+
export type { RecipeFiles } from './recipe-files';
|
|
10
|
+
export { loadForRun } from './run';
|
|
11
|
+
export { diffReport, writeChanges } from './diff';
|
|
12
|
+
export type { CommonOptions } from './arguments';
|
|
13
|
+
export { resolveAccess } from './access';
|
|
14
|
+
export { loadHooks, loadPlugins } from './hooks-module';
|
|
15
|
+
export type { PluginModule } from './hooks-module';
|
|
16
|
+
export { runStudio } from './studio';
|
|
17
|
+
export type { StudioModule } from './studio';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|