@gscdump/engine-gsc-api 1.4.0 → 1.4.1

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/index.d.mts CHANGED
@@ -1,205 +1,5 @@
1
- import { GoogleSearchConsoleClient } from "gscdump";
2
- import { BuilderState, Column, Dimension, SearchType } from "gscdump/query";
3
- import { SearchType as SearchType$1 } from "@gscdump/engine";
4
- import { AnalysisQuerySource } from "@gscdump/engine/source";
5
- import { GscDataState, GscSearchAnalyticsMetadata } from "gscdump/contracts";
6
- declare function canProxyToGsc(state: BuilderState): boolean;
7
- interface CreateLiveGscSourceOptions {
8
- /** GSC property URL (e.g. `sc-domain:example.com` or `https://example.com/`). */
9
- siteUrl: string;
10
- /**
11
- * Returns a valid GSC access token. Called lazily on first query so refresh
12
- * cost is paid only when the source actually runs. Host owns refresh logic.
13
- */
14
- getAccessToken: () => Promise<string>;
15
- /** Optional host client factory (for custom timeouts, fetch, or telemetry). */
16
- createClient?: (accessToken: string) => GoogleSearchConsoleClient | Promise<GoogleSearchConsoleClient>;
17
- /**
18
- * GSC `searchType` slice this source is scoped to (`web`, `discover`,
19
- * `news`, `googleNews`, `image`, `video`). When set, the slice is injected
20
- * into every outgoing builder state so the live API returns rows for that
21
- * slice only. An explicit search type already present on the state wins.
22
- */
23
- searchType?: SearchType$1;
24
- }
25
- declare function createLiveGscSource(opts: CreateLiveGscSourceOptions): AnalysisQuerySource;
26
- interface GscRange {
27
- start: string;
28
- end: string;
29
- }
30
- interface GscTopNRow {
31
- key: string;
32
- clicks: number;
33
- impressions: number;
34
- sum_position: number;
35
- }
36
- interface FetchTopNOptions<D extends Dimension> {
37
- client: GoogleSearchConsoleClient;
38
- siteUrl: string;
39
- dimension: Column<D>;
40
- range: GscRange;
41
- /**
42
- * Ask the GSC API to order by clicks desc. Skip for dimensions where GSC
43
- * already returns sensibly ranked rows (e.g. country).
44
- */
45
- orderByClicksDesc?: boolean;
46
- /** Forwarded to the GSC builder. */
47
- limit?: number;
48
- /** Trim after the fact (e.g. country has no server-side limit). */
49
- sliceTop?: number;
50
- /** GSC search corpus; callers default API-boundary omissions to web. */
51
- searchType?: SearchType;
52
- }
53
- declare function fetchGscTopN<D extends Dimension>(opts: FetchTopNOptions<D>): Promise<GscTopNRow[]>;
54
- interface GscDailyRow {
55
- date: number;
56
- clicks: number;
57
- impressions: number;
58
- sum_position: number;
59
- anonymizedImpressionsPct: number;
60
- }
61
- declare function fetchGscDaily(opts: {
62
- client: GoogleSearchConsoleClient;
63
- siteUrl: string;
64
- range: GscRange;
65
- /** GSC search corpus; callers default API-boundary omissions to web. */
66
- searchType?: SearchType;
67
- }): Promise<GscDailyRow[]>;
68
- interface GscApiQuerySourceOptions {
69
- client: GoogleSearchConsoleClient;
70
- siteUrl: string;
71
- }
72
- declare function createGscApiQuerySource(options: GscApiQuerySourceOptions): AnalysisQuerySource;
73
- interface GscApiRow {
74
- keys: string[];
75
- clicks: number;
76
- impressions: number;
77
- ctr: number;
78
- position: number;
79
- }
80
- interface SyncSliceDomainFilter {
81
- /**
82
- * Domain (eTLD+1 + subdomain) to scope the slice to — matches both
83
- * `www.` and bare variants. Strip the protocol; the regex is built here.
84
- */
85
- domain?: string;
86
- }
87
- interface SyncSliceDimensionFilter {
88
- dimension: 'page' | 'query' | 'country' | 'device' | 'searchAppearance';
89
- operator?: 'equals' | 'notEquals' | 'contains' | 'notContains' | 'includingRegex' | 'excludingRegex';
90
- expression: string;
91
- }
92
- interface RunGscSyncSliceOptions {
93
- client: GoogleSearchConsoleClient;
94
- siteUrl: string;
95
- /** One of the engine sync-fan tables. Drives the dimension list. */
96
- table: 'pages' | 'queries' | 'countries' | 'dates' | 'page_queries' | 'search_appearance' | 'search_appearance_pages' | 'search_appearance_queries' | 'search_appearance_page_queries' | 'hourly_pages';
97
- startDate: string;
98
- endDate: string;
99
- domainFilter?: SyncSliceDomainFilter | null;
100
- /** Additional AND filters, e.g. `searchAppearance = AMP_BLUE_LINK`. */
101
- dimensionFilters?: SyncSliceDimensionFilter[];
102
- /**
103
- * Override the dimension list for this slice. Defaults to
104
- * `DIMENSIONS_BY_TABLE[table]`. Hosts that need bespoke groupings (e.g.
105
- * hourly Discover variants) supply this directly.
106
- */
107
- dimensions?: string[];
108
- /**
109
- * GSC `dataState` for the query. Defaults to `'all'`. Use `'hourly_all'`
110
- * for hourly Discover slices.
111
- */
112
- dataState?: GscDataState;
113
- /**
114
- * Invoked per GSC API page with the rows fetched. Return a promise; the
115
- * loop awaits it before paging further. Throw a durable error to abort the
116
- * slice. A thrown AbortError / timeout stops the loop and returns retry
117
- * state at the current cursor so the continuation re-processes this page.
118
- */
119
- onBatch: (rows: GscApiRow[]) => Promise<void>;
120
- initialStartRow?: number;
121
- /**
122
- * Max GSC API pages per call. `Infinity` for unbounded; hosts cap this
123
- * based on path (D1 vs R2) and table.
124
- */
125
- maxPages?: number;
126
- /** GSC page size. 500 is the D1-safe default; 10k is the R2 path. */
127
- rowLimit?: number;
128
- /**
129
- * Soft CPU budget for the loop itself. Returns `hasMore` when crossed so
130
- * the continuation resumes from `nextStartRow`.
131
- */
132
- cpuBudgetMs?: number;
133
- searchType?: SearchType$1;
134
- /** Invoked once per successful GSC API page. Hosts wire telemetry here. */
135
- onPage?: (info: {
136
- searchType: SearchType$1;
137
- rowsThisPage: number;
138
- }) => void;
139
- }
140
- interface RunGscSyncSliceResult {
141
- totalRows: number;
142
- hasMore: boolean;
143
- nextStartRow: number;
144
- /**
145
- * Metadata from the LAST GSC API page seen during this slice run. When
146
- * `dataState='hourly_all'` and grouped by `hour`, this surfaces
147
- * `first_incomplete_hour` so hosts can watermark hourly progress.
148
- */
149
- metadata?: GscSearchAnalyticsMetadata;
150
- }
151
- type SearchAppearanceContextGrain = 'page' | 'query' | 'page_query';
152
- type SearchAppearanceContextTable = 'search_appearance_pages' | 'search_appearance_queries' | 'search_appearance_page_queries';
153
- interface RunGscSearchAppearanceContextSliceOptions {
154
- client: GoogleSearchConsoleClient;
155
- siteUrl: string;
156
- startDate: string;
157
- endDate: string;
158
- domainFilter?: SyncSliceDomainFilter | null;
159
- /** Use a known appearance list to skip discovery. */
160
- appearances?: string[];
161
- /** Context grain to fetch for every discovered appearance. Defaults to page_query. */
162
- grain?: SearchAppearanceContextGrain;
163
- /** Context table to fetch. Overrides `grain` when provided. */
164
- table?: SearchAppearanceContextTable;
165
- dataState?: GscDataState;
166
- rowLimit?: number;
167
- maxPages?: number;
168
- cpuBudgetMs?: number;
169
- searchType?: SearchType$1;
170
- onTotalBatch?: (rows: GscApiRow[]) => Promise<void>;
171
- onContextBatch: (batch: {
172
- searchAppearance: string;
173
- table: SearchAppearanceContextTable;
174
- rows: GscApiRow[];
175
- }) => Promise<void>;
176
- onPage?: (info: {
177
- searchType: SearchType$1;
178
- rowsThisPage: number;
179
- }) => void;
180
- continuation?: SearchAppearanceContinuation;
181
- }
182
- type SearchAppearanceContinuation = {
183
- phase: 'discovery';
184
- appearances: string[];
185
- nextStartRow: number;
186
- } | {
187
- phase: 'context';
188
- appearances: string[];
189
- appearanceIndex: number;
190
- nextStartRow: number;
191
- };
192
- interface RunGscSearchAppearanceContextSliceResult {
193
- appearances: string[];
194
- totalRows: number;
195
- hasMore: boolean;
196
- continuation?: SearchAppearanceContinuation;
197
- }
198
- declare function runGscSyncSlice(opts: RunGscSyncSliceOptions): Promise<RunGscSyncSliceResult>;
199
- /**
200
- * Implements GSC's required two-step search-appearance flow:
201
- * 1. group by `searchAppearance` alone to discover available appearances;
202
- * 2. for each appearance, filter by it and fetch page/query/date context.
203
- */
204
- declare function runGscSearchAppearanceContextSlice(opts: RunGscSearchAppearanceContextSliceOptions): Promise<RunGscSearchAppearanceContextSliceResult>;
1
+ import { CreateLiveGscSourceOptions, canProxyToGsc, createLiveGscSource } from "./live.mjs";
2
+ import { FetchTopNOptions, GscDailyRow, GscRange, GscTopNRow, fetchGscDaily, fetchGscTopN } from "./rollup-synth.mjs";
3
+ import { GscApiQuerySourceOptions, createGscApiQuerySource } from "./source.mjs";
4
+ import { GscApiRow, RunGscSearchAppearanceContextSliceOptions, RunGscSearchAppearanceContextSliceResult, RunGscSyncSliceOptions, RunGscSyncSliceResult, SearchAppearanceContextGrain, SearchAppearanceContextTable, SyncSliceDimensionFilter, SyncSliceDomainFilter, runGscSearchAppearanceContextSlice, runGscSyncSlice } from "./sync-slice.mjs";
205
5
  export { type CreateLiveGscSourceOptions, type FetchTopNOptions, type GscApiQuerySourceOptions, type GscApiRow, type GscDailyRow, type GscRange, type GscTopNRow, type RunGscSearchAppearanceContextSliceOptions, type RunGscSearchAppearanceContextSliceResult, type RunGscSyncSliceOptions, type RunGscSyncSliceResult, type SearchAppearanceContextGrain, type SearchAppearanceContextTable, type SyncSliceDimensionFilter, type SyncSliceDomainFilter, canProxyToGsc, createGscApiQuerySource, createLiveGscSource, fetchGscDaily, fetchGscTopN, runGscSearchAppearanceContextSlice, runGscSyncSlice };