gscdump 0.0.1 → 0.1.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.
@@ -0,0 +1,157 @@
1
+ import "ofetch";
2
+ import { indexing_v3 } from "@googleapis/indexing/v3";
3
+ import { searchconsole_v1 } from "@googleapis/searchconsole/v1";
4
+
5
+ //#region src/core/types.d.ts
6
+ type ApiSite = searchconsole_v1.Schema$WmxSite;
7
+ type ApiSitemap = searchconsole_v1.Schema$WmxSitemap;
8
+ type SearchAnalyticsQuery = searchconsole_v1.Schema$SearchAnalyticsQueryRequest;
9
+ type SearchAnalyticsResponse = searchconsole_v1.Schema$SearchAnalyticsQueryResponse;
10
+ type InspectUrlIndexResponse = searchconsole_v1.Schema$InspectUrlIndexResponse;
11
+ type UrlNotificationMetadata = indexing_v3.Schema$UrlNotificationMetadata;
12
+ type PublishUrlNotificationResponse = indexing_v3.Schema$PublishUrlNotificationResponse;
13
+ //#endregion
14
+ //#region src/core/client.d.ts
15
+
16
+ interface GoogleSearchConsoleClient {
17
+ sites: {
18
+ list: () => Promise<{
19
+ siteEntry?: ApiSite[];
20
+ }>;
21
+ };
22
+ sitemaps: {
23
+ list: (siteUrl: string) => Promise<{
24
+ sitemap?: ApiSitemap[];
25
+ }>;
26
+ get: (siteUrl: string, feedpath: string) => Promise<ApiSitemap>;
27
+ submit: (siteUrl: string, feedpath: string) => Promise<void>;
28
+ delete: (siteUrl: string, feedpath: string) => Promise<void>;
29
+ };
30
+ searchAnalytics: {
31
+ query: (siteUrl: string, body: SearchAnalyticsQuery) => Promise<SearchAnalyticsResponse>;
32
+ };
33
+ urlInspection: {
34
+ inspect: (siteUrl: string, inspectionUrl: string) => Promise<InspectUrlIndexResponse>;
35
+ };
36
+ indexing: {
37
+ publish: (url: string, type: 'URL_UPDATED' | 'URL_DELETED') => Promise<PublishUrlNotificationResponse>;
38
+ getMetadata: (url: string) => Promise<UrlNotificationMetadata>;
39
+ };
40
+ }
41
+ //#endregion
42
+ //#region src/utils/countries.d.ts
43
+ declare const _default: {
44
+ name: string;
45
+ 'alpha-2': string;
46
+ 'alpha-3': string;
47
+ 'country-code': string;
48
+ }[];
49
+ //#endregion
50
+ //#region src/query/constants.d.ts
51
+ declare const Device: {
52
+ readonly MOBILE: "MOBILE";
53
+ readonly DESKTOP: "DESKTOP";
54
+ readonly TABLET: "TABLET";
55
+ };
56
+ type Device = typeof Device[keyof typeof Device];
57
+ declare const Country: { [K in (typeof _default)[number]["alpha-3"]]: Lowercase<K> };
58
+ type Country = typeof Country[keyof typeof Country];
59
+ //#endregion
60
+ //#region src/query/types.d.ts
61
+ interface DimensionValueMap {
62
+ query: string;
63
+ page: string;
64
+ country: Country;
65
+ device: Device;
66
+ searchAppearance: string;
67
+ date: string;
68
+ }
69
+ type Dimension = keyof DimensionValueMap;
70
+ declare const ColumnBrand: unique symbol;
71
+ interface Column<D extends Dimension> {
72
+ readonly [ColumnBrand]: D;
73
+ readonly dimension: D;
74
+ }
75
+ type FilterOperator = 'equals' | 'notEquals' | 'contains' | 'notContains' | 'includingRegex' | 'excludingRegex';
76
+ type DateOperator = 'gte' | 'gt' | 'lte' | 'lt' | 'between';
77
+ interface InternalFilter {
78
+ dimension: Dimension;
79
+ operator: FilterOperator | DateOperator;
80
+ expression: string;
81
+ expression2?: string;
82
+ }
83
+ declare const FilterBrand: unique symbol;
84
+ interface Filter<C = object> {
85
+ readonly [FilterBrand]: true;
86
+ readonly _constraints: C;
87
+ readonly _filters: InternalFilter[];
88
+ readonly _groupType?: 'and' | 'or';
89
+ }
90
+ type MergeConstraints<F extends Filter<any>[]> = UnionToIntersection<F[number]['_constraints']>;
91
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
92
+ interface GSCResult<D extends Dimension[], C> {
93
+ rows: Array<GSCRow<D, C>>;
94
+ }
95
+ type GSCRow<D extends Dimension[], C> = { [K in D[number]]: K extends keyof C ? C[K] : DimensionValueMap[K] } & {
96
+ clicks: number;
97
+ impressions: number;
98
+ ctr: number;
99
+ position: number;
100
+ };
101
+ interface BuilderState {
102
+ dimensions: Dimension[];
103
+ filters: Filter<any>[];
104
+ siteUrl?: string;
105
+ rowLimit?: number;
106
+ startRow?: number;
107
+ }
108
+ //#endregion
109
+ //#region src/query/builder.d.ts
110
+ interface GSCQueryBuilder<D extends Dimension[] = [], C = object> {
111
+ select: <T extends Dimension[]>(...dims: T) => GSCQueryBuilder<T, C>;
112
+ where: <F extends Filter<any>>(filter: F) => GSCQueryBuilder<D, C & F['_constraints']>;
113
+ siteUrl: (url: string) => GSCQueryBuilder<D, C>;
114
+ limit: (n: number) => GSCQueryBuilder<D, C>;
115
+ offset: (n: number) => GSCQueryBuilder<D, C>;
116
+ execute: (client: GoogleSearchConsoleClient) => Promise<GSCResult<D, C>>;
117
+ toBody: () => SearchAnalyticsQuery;
118
+ /** Expose internal state for analysis functions to merge with */
119
+ getState: () => BuilderState;
120
+ }
121
+ declare const gsc: GSCQueryBuilder<[], object>;
122
+ //#endregion
123
+ //#region src/query/columns.d.ts
124
+ declare const page: Column<"page">;
125
+ declare const query: Column<"query">;
126
+ declare const device: Column<"device">;
127
+ declare const country: Column<"country">;
128
+ declare const searchAppearance: Column<"searchAppearance">;
129
+ declare const date: Column<"date">;
130
+ //#endregion
131
+ //#region src/query/operators.d.ts
132
+ declare function eq<D extends Dimension, V extends DimensionValueMap[D]>(column: Column<D>, value: V): Filter<Record<D, V>>;
133
+ declare function ne<D extends Dimension>(column: Column<D>, value: DimensionValueMap[D]): Filter<object>;
134
+ declare function inArray<D extends Dimension, V extends DimensionValueMap[D]>(column: Column<D>, values: readonly V[]): Filter<Record<D, V>>;
135
+ declare function contains<D extends Dimension>(column: Column<D>, pattern: string): Filter<object>;
136
+ declare function like<D extends Dimension>(column: Column<D>, pattern: string): Filter<object>;
137
+ declare function regex<D extends Dimension>(column: Column<D>, pattern: RegExp | string): Filter<object>;
138
+ declare function notRegex<D extends Dimension>(column: Column<D>, pattern: RegExp | string): Filter<object>;
139
+ declare function and<F extends Filter<any>[]>(...filters: F): Filter<MergeConstraints<F>>;
140
+ declare function or<F extends Filter<any>[]>(...filters: F): Filter<object>;
141
+ declare function not<F extends Filter<any>>(filter: F): Filter<object>;
142
+ declare function gte<D extends Dimension>(column: Column<D>, value: DimensionValueMap[D]): Filter<object>;
143
+ declare function gt<D extends Dimension>(column: Column<D>, value: DimensionValueMap[D]): Filter<object>;
144
+ declare function lte<D extends Dimension>(column: Column<D>, value: DimensionValueMap[D]): Filter<object>;
145
+ declare function lt<D extends Dimension>(column: Column<D>, value: DimensionValueMap[D]): Filter<object>;
146
+ declare function between<D extends Dimension>(column: Column<D>, start: DimensionValueMap[D], end: DimensionValueMap[D]): Filter<object>;
147
+ //#endregion
148
+ //#region src/query/resolver.d.ts
149
+ /**
150
+ * Extract date range from filters. Used by analysis functions to get the period.
151
+ */
152
+ declare function extractDateRange(filters: Filter<any>[]): {
153
+ startDate?: string;
154
+ endDate?: string;
155
+ };
156
+ //#endregion
157
+ export { type BuilderState, type Column, Country, type Country as CountryType, Device, type Device as DeviceType, type Dimension, type DimensionValueMap, type Filter, type GSCQueryBuilder, type GSCResult, type GSCRow, and, between, contains, country, date, device, eq, extractDateRange, gsc, gt, gte, inArray, like, lt, lte, ne, not, notRegex, or, page, query, regex, searchAppearance };