@mirage-cli/dataforseo-cli 0.1.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.
@@ -0,0 +1,2 @@
1
+ export { CommandSpec, IOResult, Operand, OperandKind, Option, ParsedArgs, type ByteSource, type CommandSpecInit, type IOResultInit, type OperandInit, type OptionInit, type ParsedArgsInit, } from "./types.ts";
2
+ export { argvToInput, command, group, invoke, mountGroup, ok, toCommander, type CommandDef, type CommandDefInit, type CommandFn, type CommandFnResult, type CommandGroup, type CommandOpts, type InvokeInput, type InvokeResult, } from "./runtime.ts";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Shared option mixins (`OUTPUT_OPTIONS`, `LOC_LANG_OPTIONS`) and the
3
+ * `applyOutput()` helper that every data command uses to render its
4
+ * DfsResponse into bytes + IOResult per the user's --output/--columns/etc.
5
+ */
6
+ import type { DfsResponse } from "../lib/client.ts";
7
+ import type { CommandFnResult, CommandOpts } from "./runtime.ts";
8
+ import { Operand, Option } from "./types.ts";
9
+ export declare const OUTPUT_OPTIONS: readonly Option[];
10
+ export declare function applyOutput(resp: DfsResponse, opts: CommandOpts): CommandFnResult;
11
+ export declare const LOC_LANG_OPTIONS: readonly Option[];
12
+ export interface LocLangResolved {
13
+ locationName?: string;
14
+ locationCode?: number;
15
+ languageName?: string;
16
+ languageCode?: string;
17
+ }
18
+ export declare function resolveLocLang(opts: CommandOpts): LocLangResolved;
19
+ export declare function textOp(name: string, opts?: {
20
+ variadic?: boolean;
21
+ required?: boolean;
22
+ }): Operand;
23
+ export declare function flagStr(opts: CommandOpts, key: string, fallback?: string): string;
24
+ export declare function flagBool(opts: CommandOpts, key: string): boolean;
25
+ export declare function flagNum(opts: CommandOpts, key: string, fallback: number): number;
@@ -0,0 +1,74 @@
1
+ import { Command } from "commander";
2
+ import { CommandSpec, IOResult, type ByteSource } from "./types.ts";
3
+ /**
4
+ * Mirage-compatible command function signature: (accessor, paths, texts, opts).
5
+ * We use loose accessor/opts types since CLI commands typically don't touch
6
+ * either. When registered into a real mirage workspace, mirage supplies the
7
+ * concrete Accessor and CommandOpts.
8
+ */
9
+ export type CommandOpts = {
10
+ flags: Record<string, string | boolean>;
11
+ stdin?: ByteSource | null;
12
+ cwd?: string;
13
+ resource?: unknown;
14
+ [k: string]: unknown;
15
+ };
16
+ export type CommandFnResult = [ByteSource | null, IOResult] | null;
17
+ export type CommandFn = (accessor: unknown, paths: readonly string[], texts: readonly string[], opts: CommandOpts) => Promise<CommandFnResult> | CommandFnResult;
18
+ export interface CommandDefInit {
19
+ name: string;
20
+ /** Mirage's command() requires a resource ("ram", "s3", etc.) or null for general. */
21
+ resource?: string | string[] | null;
22
+ spec: CommandSpec;
23
+ fn: CommandFn;
24
+ /** Optional sugar — used if `spec.description` is null. */
25
+ description?: string;
26
+ }
27
+ export interface CommandDef {
28
+ readonly name: string;
29
+ readonly resource: string | string[] | null;
30
+ readonly spec: CommandSpec;
31
+ readonly fn: CommandFn;
32
+ readonly description: string | null;
33
+ }
34
+ /** Author a command. Same shape as @struktoai/mirage-core's `command()`. */
35
+ export declare function command(init: CommandDefInit): CommandDef;
36
+ /** Group commands under a namespace (CLI nesting). Mirage doesn't care about groups. */
37
+ export interface CommandGroup {
38
+ readonly name: string;
39
+ readonly description: string | null;
40
+ readonly commands: readonly CommandDef[];
41
+ readonly groups: readonly CommandGroup[];
42
+ }
43
+ export declare function group(init: {
44
+ name: string;
45
+ description?: string;
46
+ commands?: readonly CommandDef[];
47
+ groups?: readonly CommandGroup[];
48
+ }): CommandGroup;
49
+ export interface InvokeInput {
50
+ paths?: readonly string[];
51
+ texts?: readonly string[];
52
+ flags?: Record<string, string | boolean>;
53
+ stdin?: ByteSource | null;
54
+ }
55
+ export interface InvokeResult {
56
+ bytes: Uint8Array;
57
+ text: string;
58
+ result: IOResult;
59
+ }
60
+ /** Programmatically invoke a command. Pass argv tokens or a structured input. */
61
+ export declare function invoke(cmd: CommandDef, input?: InvokeInput | readonly string[]): Promise<InvokeResult>;
62
+ export declare function argvToInput(spec: CommandSpec, argv: readonly string[]): InvokeInput;
63
+ export declare function toCommander(cmd: CommandDef): Command;
64
+ export declare function mountGroup(parent: Command, g: CommandGroup): Command;
65
+ /**
66
+ * Convenience for command authors: wrap text/bytes as a CommandFnResult.
67
+ *
68
+ * `ok("hello")` → stdout="hello", exitCode=0
69
+ * `ok(bytes, { exitCode: 1, stderr: "oops" })`
70
+ */
71
+ export declare function ok(body: string | Uint8Array, init?: {
72
+ exitCode?: number;
73
+ stderr?: string | Uint8Array;
74
+ }): CommandFnResult;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Runtime classes that match @struktoai/mirage-core's shapes exactly, plus
3
+ * a thin CLI-only extension (defaultValue, required, name, variadic) carried
4
+ * on Option/Operand for commander adapter convenience.
5
+ *
6
+ * Type-only import from mirage-core: zero runtime dep, zero bundle bytes from
7
+ * mirage; tsc enforces structural parity (mirage-side change → tsc error here).
8
+ */
9
+ import type { Option as MOption, Operand as MOperand, CommandSpec as MCommandSpec, ParsedArgs as MParsedArgs, OptionInit as MOptionInit, OperandInit as MOperandInit, CommandSpecInit as MCommandSpecInit, ParsedArgsInit as MParsedArgsInit, IOResultInit as MIOResultInit, OperandKind as MOperandKind, ByteSource } from "@struktoai/mirage-core";
10
+ export type { ByteSource };
11
+ export type OperandKind = MOperandKind;
12
+ export declare const OperandKind: Readonly<{
13
+ NONE: "none";
14
+ PATH: "path";
15
+ TEXT: "text";
16
+ }>;
17
+ /** Our CLI-extended OptionInit: mirage's fields + `defaultValue` and `required` for commander. */
18
+ export interface OptionInit extends MOptionInit {
19
+ defaultValue?: string | boolean | null;
20
+ required?: boolean;
21
+ }
22
+ export declare class Option implements MOption {
23
+ readonly short: string | null;
24
+ readonly long: string | null;
25
+ readonly valueKind: OperandKind;
26
+ readonly numericShorthand: boolean;
27
+ readonly description: string | null;
28
+ readonly defaultValue: string | boolean | null;
29
+ readonly required: boolean;
30
+ constructor(init?: OptionInit);
31
+ /** Stable identifier (kebab-case) for opts.flags lookup. */
32
+ get name(): string;
33
+ }
34
+ /** Our CLI-extended OperandInit: mirage has only `kind`; we add `name`/`variadic`/`required`. */
35
+ export interface OperandInit extends MOperandInit {
36
+ name?: string;
37
+ variadic?: boolean;
38
+ required?: boolean;
39
+ }
40
+ export declare class Operand implements MOperand {
41
+ readonly kind: OperandKind;
42
+ readonly name: string;
43
+ readonly variadic: boolean;
44
+ readonly required: boolean;
45
+ constructor(init?: OperandInit);
46
+ }
47
+ export type CommandSpecInit = MCommandSpecInit;
48
+ export declare class CommandSpec implements MCommandSpec {
49
+ readonly options: readonly Option[];
50
+ readonly positional: readonly Operand[];
51
+ readonly rest: Operand | null;
52
+ readonly ignoreTokens: ReadonlySet<string>;
53
+ readonly description: string | null;
54
+ constructor(init?: CommandSpecInit);
55
+ }
56
+ export type ParsedArgsInit = MParsedArgsInit;
57
+ export declare class ParsedArgs implements MParsedArgs {
58
+ readonly flags: Record<string, string | boolean>;
59
+ readonly args: [string, OperandKind][];
60
+ readonly cachePaths: string[];
61
+ readonly pathFlagValues: string[];
62
+ constructor(init: ParsedArgsInit);
63
+ paths(): string[];
64
+ routingPaths(): string[];
65
+ texts(): string[];
66
+ flag(name: string, fallback?: string | boolean | null): string | boolean | null;
67
+ }
68
+ /**
69
+ * IOResult — partial implementation of mirage's class. We populate stdout /
70
+ * stderr / exitCode; the streaming/reads/writes/cache surface is left at
71
+ * defaults. Mirage uses these structurally, so missing methods are fine for
72
+ * simple command outputs (we don't stream).
73
+ */
74
+ export interface IOResultInit extends Omit<MIOResultInit, "stdout" | "stderr"> {
75
+ /** Accepts either bytes or a UTF-8 string (auto-encoded). */
76
+ stdout?: ByteSource | string | null;
77
+ /** Accepts either bytes or a UTF-8 string (auto-encoded). */
78
+ stderr?: ByteSource | string | null;
79
+ }
80
+ export declare class IOResult {
81
+ stdout: Uint8Array | null;
82
+ stderr: Uint8Array | null;
83
+ exitCode: number;
84
+ reads: Record<string, ByteSource>;
85
+ writes: Record<string, ByteSource>;
86
+ cache: string[];
87
+ streamSource: IOResult | null;
88
+ constructor(init?: IOResultInit);
89
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Library entry point. Three layers:
3
+ *
4
+ * 1. Pure async API functions — `keywordsSearchVolume`, `serpGoogleOrganic`, etc.
5
+ * Call them directly when you just need a `DfsResponse`.
6
+ *
7
+ * 2. Mirage-shaped command definitions — `keywordsSearchVolumeCmd`, etc.
8
+ * Built with the local `command()` factory, whose `CommandSpec` / `Option` /
9
+ * `Operand` / `OperandKind` / `IOResult` shapes match @struktoai/mirage-browser.
10
+ * Use `invoke(cmd, { texts, flags })` to run one programmatically, or
11
+ * `toCommander(cmd)` to mount it onto your own commander program.
12
+ *
13
+ * 3. `buildProgram(): Command` — a fully-assembled Commander program (same one
14
+ * the `dfs` CLI binary uses). For in-process wrappers like
15
+ * `@mirage-cli/dataforseo`.
16
+ *
17
+ * The CLI binary in `dist/dfs.js` is built from these same definitions.
18
+ */
19
+ export { buildProgram } from "./dfs.ts";
20
+ export { CommandSpec, IOResult, Operand, OperandKind, Option, ParsedArgs, argvToInput, command, group, invoke, mountGroup, ok, toCommander, type ByteSource, type CommandDef, type CommandDefInit, type CommandFn, type CommandFnResult, type CommandGroup, type CommandOpts, type CommandSpecInit, type IOResultInit, type InvokeInput, type InvokeResult, type OperandInit, type OptionInit, type ParsedArgsInit, } from "./framework/index.ts";
21
+ export { applyOutput, flagBool, flagNum, flagStr, LOC_LANG_OPTIONS, OUTPUT_OPTIONS, resolveLocLang, textOp, type LocLangResolved, } from "./framework/output.ts";
22
+ export { call, extractItems, get, type CallOptions, type DfsResponse, } from "./lib/client.ts";
23
+ export { loadCredentials, saveCredentials, basicAuthHeader, configPath, type Credentials } from "./lib/auth.ts";
24
+ export { findEndpoint, loadEndpoints, searchEndpoints, type EndpointInfo, type EndpointMethod } from "./lib/spec.ts";
25
+ export { render, type OutputFormat, type RenderOptions } from "./lib/output.ts";
26
+ export { keywordsIdeas, keywordsRanked, keywordsSearchVolume, keywordsSuggestions, type LocLang, } from "./api/keywords.ts";
27
+ export { serpGoogleImages, serpGoogleMaps, serpGoogleNews, serpGoogleOrganic, serpYoutubeOrganic, type SerpOpts, } from "./api/serp.ts";
28
+ export { backlinksAnchors, backlinksCompetitors, backlinksList, backlinksRanks, backlinksReferringDomains, backlinksSummary, } from "./api/backlinks.ts";
29
+ export { labsBulkDifficulty, labsCompetitors, labsHistorical, labsIntent, labsIntersection, labsKeywordOverview, labsOverview, labsRelated, labsTopSearches, } from "./api/labs.ts";
30
+ export { aiAsk, aiMentionMetrics, aiMentions, aiSearchVolume, aiTopDomains, aiTopPages, type AiModel, } from "./api/ai.ts";
31
+ export { trendsDemography, trendsExplore, trendsSubregion, type TrendsType } from "./api/trends.ts";
32
+ export { listLanguages, listLocations, userData } from "./api/meta.ts";
33
+ export { keywordsGroup, keywordsIdeasCmd, keywordsRankedCmd, keywordsSearchVolumeCmd, keywordsSuggestionsCmd, } from "./commands/keywords.ts";
34
+ export { serpGroup, serpGoogleImagesCmd, serpGoogleMapsCmd, serpGoogleNewsCmd, serpGoogleOrganicCmd, serpYoutubeOrganicCmd, } from "./commands/serp.ts";
35
+ export { backlinksAnchorsCmd, backlinksCompetitorsCmd, backlinksGroup, backlinksListCmd, backlinksRanksCmd, backlinksReferringDomainsCmd, backlinksSummaryCmd, } from "./commands/backlinks.ts";
36
+ export { labsBulkDifficultyCmd, labsCompetitorsCmd, labsGroup, labsHistoricalCmd, labsIntentCmd, labsIntersectionCmd, labsKeywordOverviewCmd, labsOverviewCmd, labsRelatedCmd, labsTopSearchesCmd, } from "./commands/labs.ts";
37
+ export { aiAskCmd, aiGroup, aiMentionsCmd, aiMetricsCmd, aiSearchVolumeCmd, aiTopDomainsCmd, aiTopPagesCmd, } from "./commands/ai.ts";
38
+ export { trendsDemographyCmd, trendsExploreCmd, trendsGroup, trendsSubregionCmd, } from "./commands/trends.ts";
39
+ export { languagesCmd, locationsCmd, userCmd } from "./commands/meta.ts";
40
+ export { loginCmd, whoamiCmd } from "./commands/login.ts";
41
+ export { rawCmd } from "./commands/raw.ts";
42
+ export { endpointsGroup, endpointsListCmd, endpointsShowCmd, endpointsTagsCmd } from "./commands/endpoints.ts";