gscdump 1.4.0 → 1.4.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.
Files changed (71) hide show
  1. package/dist/api/batch.d.mts +12 -0
  2. package/dist/api/batch.mjs +29 -0
  3. package/dist/api/indexing.d.mts +37 -0
  4. package/dist/api/indexing.mjs +25 -0
  5. package/dist/api/inspection.d.mts +89 -0
  6. package/dist/api/inspection.mjs +128 -0
  7. package/dist/api/oauth.d.mts +48 -0
  8. package/dist/api/oauth.mjs +154 -0
  9. package/dist/api/sites.d.mts +45 -0
  10. package/dist/api/sites.mjs +34 -0
  11. package/dist/api/verification.d.mts +43 -0
  12. package/dist/api/verification.mjs +89 -0
  13. package/dist/contracts.d.mts +46 -1
  14. package/dist/core/cli-format.mjs +9 -0
  15. package/dist/core/client.d.mts +122 -0
  16. package/dist/core/client.mjs +246 -0
  17. package/dist/core/errors.d.mts +66 -0
  18. package/dist/core/errors.mjs +207 -0
  19. package/dist/core/indexing-issues.d.mts +60 -0
  20. package/dist/core/indexing-issues.mjs +139 -0
  21. package/dist/core/property.d.mts +41 -0
  22. package/dist/core/property.mjs +74 -0
  23. package/dist/core/quota.d.mts +2 -0
  24. package/dist/core/quota.mjs +2 -0
  25. package/dist/core/result.d.mts +19 -1
  26. package/dist/core/scope-values.d.mts +7 -0
  27. package/dist/core/scope-values.mjs +15 -0
  28. package/dist/core/scopes.d.mts +5 -0
  29. package/dist/core/scopes.mjs +11 -0
  30. package/dist/core/site-url.d.mts +25 -0
  31. package/dist/core/site-url.mjs +30 -0
  32. package/dist/core/types.d.mts +201 -0
  33. package/dist/core/types.mjs +1 -0
  34. package/dist/dates.d.mts +2 -2
  35. package/dist/dates.mjs +2 -2
  36. package/dist/index.d.mts +20 -814
  37. package/dist/index.mjs +19 -1243
  38. package/dist/onboarding.d.mts +2 -0
  39. package/dist/onboarding.mjs +2 -0
  40. package/dist/{_chunks → query}/builder.d.mts +2 -2
  41. package/dist/query/builder.mjs +86 -0
  42. package/dist/query/columns.d.mts +15 -0
  43. package/dist/query/columns.mjs +23 -0
  44. package/dist/query/constants.d.mts +19 -0
  45. package/dist/query/constants.mjs +16 -0
  46. package/dist/query/errors.d.mts +85 -0
  47. package/dist/query/errors.mjs +141 -0
  48. package/dist/query/index.d.mts +9 -75
  49. package/dist/query/index.mjs +7 -230
  50. package/dist/query/operator-meta.mjs +41 -0
  51. package/dist/query/operators.d.mts +24 -0
  52. package/dist/query/operators.mjs +124 -0
  53. package/dist/query/plan.d.mts +92 -2
  54. package/dist/query/plan.mjs +3 -1
  55. package/dist/query/resolver.d.mts +40 -0
  56. package/dist/query/resolver.mjs +243 -0
  57. package/dist/{_chunks → query}/types.d.mts +3 -25
  58. package/dist/query/utils/countries.d.mts +7 -0
  59. package/dist/{_chunks/resolver.mjs → query/utils/countries.mjs} +1 -434
  60. package/dist/{_chunks → query/utils}/dayjs.mjs +1 -1
  61. package/dist/sitemap.d.mts +26 -0
  62. package/dist/sitemap.mjs +70 -0
  63. package/dist/url.d.mts +9 -0
  64. package/dist/url.mjs +6 -0
  65. package/package.json +2 -2
  66. package/dist/_chunks/contracts.d.mts +0 -47
  67. package/dist/_chunks/plan.d.mts +0 -175
  68. package/dist/_chunks/result.d.mts +0 -20
  69. /package/dist/{_chunks → core}/gsc-dates.d.mts +0 -0
  70. /package/dist/{_chunks → core}/gsc-dates.mjs +0 -0
  71. /package/dist/{_chunks → query/utils}/dayjs.d.mts +0 -0
@@ -0,0 +1,243 @@
1
+ import { err, ok, unwrapResult } from "../core/result.mjs";
2
+ import { addDays } from "../core/gsc-dates.mjs";
3
+ import { SearchTypes } from "./constants.mjs";
4
+ import { queryErrorToException, queryErrors } from "./errors.mjs";
5
+ import { isDateOperator, isMetricOperator, isQueryParam, isSpecialOperator } from "./operator-meta.mjs";
6
+ const KNOWN_SEARCH_TYPES = new Set(Object.values(SearchTypes));
7
+ function isWireGroupType(type) {
8
+ return type === "and" || type === "or";
9
+ }
10
+ function convertWireLeaf(alt) {
11
+ if (!alt.column || !alt.type || isWireGroupType(alt.type)) return null;
12
+ const f = {
13
+ dimension: alt.column,
14
+ operator: alt.type,
15
+ expression: alt.type === "between" ? alt.from ?? "" : alt.value ?? ""
16
+ };
17
+ if (alt.type === "between" && alt.to) f.expression2 = alt.to;
18
+ return f;
19
+ }
20
+ function convertWireGroup(alt) {
21
+ if (!isWireGroupType(alt.type)) {
22
+ const leaf = convertWireLeaf(alt);
23
+ return leaf ? { _filters: [leaf] } : null;
24
+ }
25
+ const leaves = [];
26
+ const nested = [];
27
+ for (const child of alt.filters ?? []) if (isWireGroupType(child.type)) {
28
+ const sub = convertWireGroup(child);
29
+ if (sub) nested.push(sub);
30
+ } else {
31
+ const leaf = convertWireLeaf(child);
32
+ if (leaf) leaves.push(leaf);
33
+ }
34
+ if (leaves.length === 0 && nested.length === 0) return null;
35
+ return {
36
+ _filters: leaves,
37
+ _nestedGroups: nested.length > 0 ? nested : void 0,
38
+ _groupType: alt.type
39
+ };
40
+ }
41
+ function isWireFilter(input) {
42
+ if (!input || typeof input !== "object") return false;
43
+ const o = input;
44
+ if ("_filters" in o) return false;
45
+ return "type" in o && typeof o.type === "string" || "filters" in o && Array.isArray(o.filters);
46
+ }
47
+ function normalizeFilter(input) {
48
+ if (!input) return void 0;
49
+ if (isWireFilter(input)) return convertWireGroup(input) ?? void 0;
50
+ if (typeof input === "object" && Array.isArray(input._filters)) return input;
51
+ }
52
+ function normalizeOrderBy(orderBy) {
53
+ const spec = Array.isArray(orderBy) ? orderBy[0] : orderBy;
54
+ if (!spec || typeof spec !== "object") return void 0;
55
+ const o = spec;
56
+ if (typeof o.column !== "string" || o.column.length === 0) return void 0;
57
+ const dir = typeof o.dir === "string" ? o.dir.toLowerCase() === "asc" ? "asc" : "desc" : o.desc === false ? "asc" : "desc";
58
+ return {
59
+ column: o.column,
60
+ dir
61
+ };
62
+ }
63
+ function hasMalformedFilterLeaf(filter) {
64
+ if (!filter || typeof filter !== "object") return false;
65
+ if (Array.isArray(filter._filters)) {
66
+ for (const leaf of filter._filters) if (!leaf || typeof leaf !== "object" || typeof leaf.operator !== "string" || typeof leaf.dimension !== "string") return true;
67
+ }
68
+ if (Array.isArray(filter._nestedGroups)) {
69
+ for (const group of filter._nestedGroups) if (hasMalformedFilterLeaf(group)) return true;
70
+ }
71
+ return false;
72
+ }
73
+ function normalizeBuilderStateResult(state) {
74
+ if (!state || typeof state !== "object") return err(queryErrors.invalidBuilderState(state));
75
+ const s = state;
76
+ const filter = normalizeFilter(s.filter);
77
+ if (hasMalformedFilterLeaf(filter)) return err(queryErrors.malformedFilterLeaf());
78
+ const normalized = {
79
+ dimensions: Array.isArray(s.dimensions) ? s.dimensions : [],
80
+ metrics: s.metrics,
81
+ filter,
82
+ orderBy: normalizeOrderBy(s.orderBy),
83
+ rowLimit: s.rowLimit,
84
+ startRow: s.startRow,
85
+ dataState: s.dataState,
86
+ aggregationType: s.aggregationType
87
+ };
88
+ if (typeof s.searchType === "string" && KNOWN_SEARCH_TYPES.has(s.searchType)) normalized.searchType = s.searchType;
89
+ return ok(normalized);
90
+ }
91
+ function normalizeBuilderState(state) {
92
+ return unwrapResult(normalizeBuilderStateResult(state), queryErrorToException);
93
+ }
94
+ function extractSpecialFilters(filter) {
95
+ if (!filter || !Array.isArray(filter._filters)) return {};
96
+ let startDate;
97
+ let endDate;
98
+ let searchType;
99
+ const otherFilters = [];
100
+ const cleanedNestedGroups = [];
101
+ for (const f of filter._filters) if (f.dimension === "date" && isDateOperator(f.operator)) switch (f.operator) {
102
+ case "gte":
103
+ startDate = f.expression;
104
+ break;
105
+ case "gt":
106
+ startDate = addDays(f.expression, 1);
107
+ break;
108
+ case "lte":
109
+ endDate = f.expression;
110
+ break;
111
+ case "lt":
112
+ endDate = addDays(f.expression, -1);
113
+ break;
114
+ case "between":
115
+ startDate = f.expression;
116
+ endDate = f.expression2;
117
+ break;
118
+ }
119
+ else if (isQueryParam(f.dimension)) {
120
+ if (f.dimension === "searchType") searchType = f.expression;
121
+ } else if (isMetricOperator(f.operator) || isSpecialOperator(f.operator)) otherFilters.push(f);
122
+ else otherFilters.push(f);
123
+ if (filter._nestedGroups) for (const nested of filter._nestedGroups) {
124
+ const extracted = extractSpecialFilters(nested);
125
+ if (!startDate && extracted.startDate) startDate = extracted.startDate;
126
+ if (!endDate && extracted.endDate) endDate = extracted.endDate;
127
+ if (!searchType && extracted.searchType) searchType = extracted.searchType;
128
+ if (extracted.dimensionFilter) cleanedNestedGroups.push(extracted.dimensionFilter);
129
+ }
130
+ const dimensionFilter = otherFilters.length > 0 || cleanedNestedGroups.length > 0 ? {
131
+ ...filter,
132
+ _filters: otherFilters,
133
+ _nestedGroups: cleanedNestedGroups.length > 0 ? cleanedNestedGroups : void 0
134
+ } : void 0;
135
+ return {
136
+ startDate,
137
+ endDate,
138
+ searchType,
139
+ dimensionFilter
140
+ };
141
+ }
142
+ function extractDateRange(input) {
143
+ const { startDate, endDate } = extractSpecialFilters(normalizeFilter(input));
144
+ return {
145
+ startDate,
146
+ endDate
147
+ };
148
+ }
149
+ function extractMetricFilters(input) {
150
+ const filter = normalizeFilter(input);
151
+ if (!filter) return [];
152
+ const metricFilters = filter._filters.filter((f) => isMetricOperator(f.operator));
153
+ const nested = filter._nestedGroups?.flatMap((g) => extractMetricFilters(g)) ?? [];
154
+ return [...metricFilters, ...nested];
155
+ }
156
+ function extractSpecialOperatorFilters(input) {
157
+ const filter = normalizeFilter(input);
158
+ if (!filter) return [];
159
+ const special = filter._filters.filter((f) => isSpecialOperator(f.operator));
160
+ const nested = filter._nestedGroups?.flatMap((g) => extractSpecialOperatorFilters(g)) ?? [];
161
+ return [...special, ...nested];
162
+ }
163
+ function extractSearchType(state) {
164
+ if (!state) return void 0;
165
+ if (state.searchType && KNOWN_SEARCH_TYPES.has(state.searchType)) return state.searchType;
166
+ const filter = state.filter;
167
+ const raw = extractSpecialFilters(normalizeFilter(filter)).searchType;
168
+ if (typeof raw !== "string" || raw.length === 0) return void 0;
169
+ return KNOWN_SEARCH_TYPES.has(raw) ? raw : void 0;
170
+ }
171
+ function resolveToBodyResult(state) {
172
+ const { startDate, endDate, searchType, dimensionFilter } = extractSpecialFilters(state.filter);
173
+ if (!startDate || !endDate) return err(queryErrors.missingDateRange());
174
+ const body = {
175
+ dimensions: state.dimensions,
176
+ startDate,
177
+ endDate
178
+ };
179
+ const resolvedType = state.searchType ?? searchType;
180
+ if (resolvedType) body.type = resolvedType;
181
+ if (state.rowLimit !== void 0) {
182
+ if (!Number.isInteger(state.rowLimit) || state.rowLimit < 1) return err(queryErrors.invalidRowLimit(state.rowLimit));
183
+ body.rowLimit = state.rowLimit;
184
+ }
185
+ if (state.startRow !== void 0) {
186
+ if (!Number.isInteger(state.startRow) || state.startRow < 0) return err(queryErrors.invalidStartRow(state.startRow));
187
+ if (state.startRow > 0) body.startRow = state.startRow;
188
+ }
189
+ const hasHour = state.dimensions?.includes("hour");
190
+ if (hasHour && state.dataState !== "hourly_all") return err(queryErrors.hourDimensionRequiresHourlyState());
191
+ if (state.dataState === "hourly_all" && !hasHour) return err(queryErrors.hourlyStateRequiresHourDimension());
192
+ if (state.dataState) body.dataState = state.dataState;
193
+ const filterGroups = resolveFilter(dimensionFilter);
194
+ if (filterGroups.length > 0) body.dimensionFilterGroups = filterGroups;
195
+ if (state.aggregationType) {
196
+ const groupsByPage = (body.dimensions ?? []).includes("page");
197
+ const apiLeafFilters = filterGroups.flatMap((g) => g.filters ?? []);
198
+ const filtersByPage = apiLeafFilters.some((f) => f.dimension === "page");
199
+ if (state.aggregationType === "byProperty") {
200
+ if (body.type === "discover" || body.type === "googleNews") return err(queryErrors.byPropertyUnsupportedSearchType());
201
+ if (groupsByPage || filtersByPage) return err(queryErrors.byPropertyNotAllowedWithPage());
202
+ }
203
+ if (state.aggregationType === "byNewsShowcasePanel") {
204
+ if (body.type !== "discover" && body.type !== "googleNews") return err(queryErrors.byNewsShowcaseRequiresSearchType());
205
+ if (groupsByPage || filtersByPage) return err(queryErrors.byNewsShowcaseNotAllowedWithPage());
206
+ const saFilters = apiLeafFilters.filter((f) => f.dimension === "searchAppearance");
207
+ const hasNewsShowcase = saFilters.some((f) => f.operator === "equals" && f.expression === "NEWS_SHOWCASE");
208
+ const hasOther = saFilters.some((f) => !(f.operator === "equals" && f.expression === "NEWS_SHOWCASE"));
209
+ if (!hasNewsShowcase || hasOther) return err(queryErrors.byNewsShowcaseRequiresShowcaseFilter());
210
+ }
211
+ body.aggregationType = state.aggregationType;
212
+ }
213
+ return ok(body);
214
+ }
215
+ function resolveToBody(state) {
216
+ return unwrapResult(resolveToBodyResult(state), queryErrorToException);
217
+ }
218
+ function isApiFilter(f) {
219
+ return !isMetricOperator(f.operator) && !isSpecialOperator(f.operator);
220
+ }
221
+ function resolveFilter(filter) {
222
+ if (!filter) return [];
223
+ const groups = [];
224
+ const groupType = filter._groupType ?? "and";
225
+ const apiFilters = filter._filters.filter(isApiFilter);
226
+ if (groupType === "or") {
227
+ if (apiFilters.length > 0) groups.push({
228
+ groupType: "or",
229
+ filters: apiFilters.map((f) => ({
230
+ dimension: f.dimension,
231
+ operator: f.operator,
232
+ expression: f.expression
233
+ }))
234
+ });
235
+ } else if (apiFilters.length > 0) groups.push({ filters: apiFilters.map((f) => ({
236
+ dimension: f.dimension,
237
+ operator: f.operator,
238
+ expression: f.expression
239
+ })) });
240
+ if (filter._nestedGroups) for (const nested of filter._nestedGroups) groups.push(...resolveFilter(nested));
241
+ return groups;
242
+ }
243
+ export { extractDateRange, extractMetricFilters, extractSearchType, extractSpecialOperatorFilters, normalizeBuilderState, normalizeBuilderStateResult, normalizeFilter, resolveToBody, resolveToBodyResult };
@@ -1,27 +1,5 @@
1
- import { GscAggregationType, GscDataState } from "./contracts.mjs";
2
- declare const _default: {
3
- name: string;
4
- 'alpha-2': string;
5
- 'alpha-3': string;
6
- 'country-code': string;
7
- }[];
8
- declare const Devices: {
9
- readonly MOBILE: 'MOBILE';
10
- readonly DESKTOP: 'DESKTOP';
11
- readonly TABLET: 'TABLET';
12
- };
13
- type Device = typeof Devices[keyof typeof Devices];
14
- declare const SearchTypes: {
15
- readonly WEB: 'web';
16
- readonly IMAGE: 'image';
17
- readonly VIDEO: 'video';
18
- readonly NEWS: 'news';
19
- readonly DISCOVER: 'discover';
20
- readonly GOOGLE_NEWS: 'googleNews';
21
- };
22
- type SearchType = typeof SearchTypes[keyof typeof SearchTypes];
23
- declare const Countries: { [K in typeof _default[number]['alpha-3']]: Lowercase<K>; };
24
- type Country = typeof Countries[keyof typeof Countries];
1
+ import { GscAggregationType, GscDataState } from "../contracts.mjs";
2
+ import { Country, Device, SearchType } from "./constants.mjs";
25
3
  interface DimensionValueMap {
26
4
  query: string;
27
5
  queryCanonical: string;
@@ -109,4 +87,4 @@ interface JsonFilter {
109
87
  _groupType?: 'and' | 'or';
110
88
  }
111
89
  type FilterInput = Filter<any> | JsonFilter;
112
- export { BuilderState, Column, Countries, Country, Device, Devices, Dimension, DimensionValueMap, Filter, FilterInput, FilterOperator, GSCResult, GSCRow, InternalFilter, JsonFilter, JsonInternalFilter, MergeConstraints, Metric, MetricColumn, MetricOperator, QueryParam, QueryParamName, QueryParamValueMap, SearchType, SearchTypes };
90
+ export { BuilderState, Column, DateOperator, Dimension, DimensionValueMap, Filter, FilterInput, FilterOperator, GSCResult, GSCRow, InternalFilter, JsonFilter, JsonInternalFilter, MergeConstraints, Metric, MetricColumn, MetricOperator, QueryParam, QueryParamName, QueryParamValueMap, SpecialOperator, UnionToIntersection };
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ name: string;
3
+ 'alpha-2': string;
4
+ 'alpha-3': string;
5
+ 'country-code': string;
6
+ }[];
7
+ export { _default as default };