gscdump 0.3.0 → 0.4.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.
@@ -101,6 +101,18 @@ interface BuilderState {
101
101
  rowLimit?: number;
102
102
  startRow?: number;
103
103
  }
104
+ interface JsonInternalFilter {
105
+ dimension: string;
106
+ operator: string;
107
+ expression: string;
108
+ expression2?: string;
109
+ }
110
+ interface JsonFilter {
111
+ _filters: JsonInternalFilter[];
112
+ _nestedGroups?: JsonFilter[];
113
+ _groupType?: 'and' | 'or';
114
+ }
115
+ type FilterInput = Filter<any> | JsonFilter;
104
116
  //#endregion
105
117
  //#region src/query/builder.d.ts
106
118
  type SelectableColumn = Column<Dimension> | MetricColumn<Metric>;
@@ -159,12 +171,14 @@ declare function between<D extends Dimension>(column: Column<D>, start: Dimensio
159
171
  declare function topLevel(column: Column<'page'>): Filter<object>;
160
172
  //#endregion
161
173
  //#region src/query/resolver.d.ts
162
- declare function extractDateRange(filter?: Filter<any>): {
174
+ declare function isJsonFilter(value: unknown): value is JsonFilter;
175
+ declare function parseJsonFilter(json: JsonFilter): Filter<any>;
176
+ declare function extractDateRange(input?: FilterInput): {
163
177
  startDate?: string;
164
178
  endDate?: string;
165
179
  };
166
- declare function extractMetricFilters(filter?: Filter<any>): InternalFilter[];
167
- declare function extractSpecialOperatorFilters(filter?: Filter<any>): InternalFilter[];
180
+ declare function extractMetricFilters(input?: FilterInput): InternalFilter[];
181
+ declare function extractSpecialOperatorFilters(input?: FilterInput): InternalFilter[];
168
182
  //#endregion
169
183
  //#region src/query/utils/dayjs.d.ts
170
184
  declare function dayjs(date?: _dayjs.ConfigType): Dayjs;
@@ -175,4 +189,4 @@ declare function dayjsPst(): Dayjs;
175
189
  declare function today(): string;
176
190
  declare function daysAgo(n: number): string;
177
191
  //#endregion
178
- export { type BuilderState, type Column, Countries, type Country, type Device, Devices, type Dimension, type DimensionValueMap, type Filter, type GSCQueryBuilder, type GSCResult, type GSCRow, type InternalFilter, type Metric, type MetricColumn, type QueryParam, type QueryParamName, type QueryParamValueMap, type SearchType, SearchTypes, and, between, clicks, contains, country, ctr, currentPstDate, date, dayjs, dayjsPst, daysAgo, device, eq, extractDateRange, extractMetricFilters, extractSpecialOperatorFilters, gsc, gt, gte, impressions, inArray, like, lt, lte, ne, not, notRegex, or, page, position, query, queryCanonical, regex, searchAppearance, searchType, today, topLevel };
192
+ export { type BuilderState, type Column, Countries, type Country, type Device, Devices, type Dimension, type DimensionValueMap, type Filter, type FilterInput, type GSCQueryBuilder, type GSCResult, type GSCRow, type InternalFilter, type JsonFilter, type JsonInternalFilter, type Metric, type MetricColumn, type QueryParam, type QueryParamName, type QueryParamValueMap, type SearchType, SearchTypes, and, between, clicks, contains, country, ctr, currentPstDate, date, dayjs, dayjsPst, daysAgo, device, eq, extractDateRange, extractMetricFilters, extractSpecialOperatorFilters, gsc, gt, gte, impressions, inArray, isJsonFilter, like, lt, lte, ne, not, notRegex, or, page, parseJsonFilter, position, query, queryCanonical, regex, searchAppearance, searchType, today, topLevel };
@@ -33,6 +33,26 @@ const METRIC_OPERATORS = [
33
33
  ];
34
34
  const SPECIAL_OPERATORS = ["topLevel"];
35
35
  const QUERY_PARAMS = ["searchType"];
36
+ function isJsonFilter(value) {
37
+ return typeof value === "object" && value !== null && "_filters" in value && Array.isArray(value._filters);
38
+ }
39
+ function parseJsonFilter(json) {
40
+ return {
41
+ _constraints: {},
42
+ _filters: json._filters.map((f) => ({
43
+ dimension: f.dimension,
44
+ operator: f.operator,
45
+ expression: f.expression,
46
+ expression2: f.expression2
47
+ })),
48
+ _nestedGroups: json._nestedGroups?.map(parseJsonFilter),
49
+ _groupType: json._groupType
50
+ };
51
+ }
52
+ function normalizeFilter(input) {
53
+ if (!input) return void 0;
54
+ return input;
55
+ }
36
56
  function isMetricOperator(op) {
37
57
  return METRIC_OPERATORS.includes(op);
38
58
  }
@@ -98,20 +118,22 @@ function extractSpecialFilters(filter) {
98
118
  dimensionFilter
99
119
  };
100
120
  }
101
- function extractDateRange(filter) {
102
- const { startDate, endDate } = extractSpecialFilters(filter);
121
+ function extractDateRange(input) {
122
+ const { startDate, endDate } = extractSpecialFilters(normalizeFilter(input));
103
123
  return {
104
124
  startDate,
105
125
  endDate
106
126
  };
107
127
  }
108
- function extractMetricFilters(filter) {
128
+ function extractMetricFilters(input) {
129
+ const filter = normalizeFilter(input);
109
130
  if (!filter) return [];
110
131
  const metricFilters = filter._filters.filter((f) => isMetricOperator(f.operator));
111
132
  const nested = filter._nestedGroups?.flatMap((g) => extractMetricFilters(g)) ?? [];
112
133
  return [...metricFilters, ...nested];
113
134
  }
114
- function extractSpecialOperatorFilters(filter) {
135
+ function extractSpecialOperatorFilters(input) {
136
+ const filter = normalizeFilter(input);
115
137
  if (!filter) return [];
116
138
  const special = filter._filters.filter((f) => isSpecialOperator(f.operator));
117
139
  const nested = filter._nestedGroups?.flatMap((g) => extractSpecialOperatorFilters(g)) ?? [];
@@ -1993,4 +2015,4 @@ function daysAgo(n) {
1993
2015
  }
1994
2016
 
1995
2017
  //#endregion
1996
- export { Countries, Devices, SearchTypes, and, between, clicks, contains, country, ctr, currentPstDate, date, dayjs, dayjsPst, daysAgo, device, eq, extractDateRange, extractMetricFilters, extractSpecialOperatorFilters, gsc, gt, gte, impressions, inArray, like, lt, lte, ne, not, notRegex, or, page, position, query, queryCanonical, regex, searchAppearance, searchType, today, topLevel };
2018
+ export { Countries, Devices, SearchTypes, and, between, clicks, contains, country, ctr, currentPstDate, date, dayjs, dayjsPst, daysAgo, device, eq, extractDateRange, extractMetricFilters, extractSpecialOperatorFilters, gsc, gt, gte, impressions, inArray, isJsonFilter, like, lt, lte, ne, not, notRegex, or, page, parseJsonFilter, position, query, queryCanonical, regex, searchAppearance, searchType, today, topLevel };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gscdump",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "description": "Google Search Console API wrapper with typed query builder, streaming pagination, and SEO analysis functions",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",