gscdump 0.40.1 → 1.0.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.
@@ -1626,6 +1626,12 @@ const queryErrors = {
1626
1626
  message: "Invalid state"
1627
1627
  };
1628
1628
  },
1629
+ malformedFilterLeaf() {
1630
+ return {
1631
+ kind: "invalid-filter",
1632
+ message: "Malformed filter: each filter leaf requires a string `dimension` and `operator`"
1633
+ };
1634
+ },
1629
1635
  unsupportedCapability(capability, context) {
1630
1636
  return {
1631
1637
  kind: "unsupported-capability",
@@ -1652,15 +1658,13 @@ const QUERY_ERROR_KINDS = /* @__PURE__ */ new Set([
1652
1658
  "invalid-data-state",
1653
1659
  "invalid-aggregation-type",
1654
1660
  "invalid-builder-state",
1661
+ "invalid-filter",
1655
1662
  "unsupported-capability",
1656
1663
  "unresolvable-dataset"
1657
1664
  ]);
1658
1665
  function isQueryError(value) {
1659
1666
  return typeof value === "object" && value !== null && QUERY_ERROR_KINDS.has(value.kind) && typeof value.message === "string";
1660
1667
  }
1661
- function formatQueryError(error) {
1662
- return error.message;
1663
- }
1664
1668
  var UnsupportedLogicalCapabilityError = class extends Error {
1665
1669
  queryError;
1666
1670
  constructor(capability, context) {
@@ -1732,22 +1736,6 @@ function isRegexOperator(op) {
1732
1736
  return op === "includingRegex" || op === "excludingRegex";
1733
1737
  }
1734
1738
  const KNOWN_SEARCH_TYPES = new Set(Object.values(SearchTypes));
1735
- function isJsonFilter(value) {
1736
- return typeof value === "object" && value !== null && "_filters" in value && Array.isArray(value._filters);
1737
- }
1738
- function parseJsonFilter(json) {
1739
- return {
1740
- _constraints: {},
1741
- _filters: json._filters.map((f) => ({
1742
- dimension: f.dimension,
1743
- operator: f.operator,
1744
- expression: f.expression,
1745
- expression2: f.expression2
1746
- })),
1747
- _nestedGroups: json._nestedGroups?.map(parseJsonFilter),
1748
- _groupType: json._groupType
1749
- };
1750
- }
1751
1739
  function isWireGroupType(type) {
1752
1740
  return type === "and" || type === "or";
1753
1741
  }
@@ -1793,14 +1781,37 @@ function normalizeFilter(input) {
1793
1781
  if (isWireFilter(input)) return convertWireGroup(input) ?? void 0;
1794
1782
  if (typeof input === "object" && Array.isArray(input._filters)) return input;
1795
1783
  }
1784
+ function normalizeOrderBy(orderBy) {
1785
+ const spec = Array.isArray(orderBy) ? orderBy[0] : orderBy;
1786
+ if (!spec || typeof spec !== "object") return void 0;
1787
+ const o = spec;
1788
+ if (typeof o.column !== "string" || o.column.length === 0) return void 0;
1789
+ const dir = typeof o.dir === "string" ? o.dir.toLowerCase() === "asc" ? "asc" : "desc" : o.desc === false ? "asc" : "desc";
1790
+ return {
1791
+ column: o.column,
1792
+ dir
1793
+ };
1794
+ }
1795
+ function hasMalformedFilterLeaf(filter) {
1796
+ if (!filter || typeof filter !== "object") return false;
1797
+ if (Array.isArray(filter._filters)) {
1798
+ for (const leaf of filter._filters) if (!leaf || typeof leaf !== "object" || typeof leaf.operator !== "string" || typeof leaf.dimension !== "string") return true;
1799
+ }
1800
+ if (Array.isArray(filter._nestedGroups)) {
1801
+ for (const group of filter._nestedGroups) if (hasMalformedFilterLeaf(group)) return true;
1802
+ }
1803
+ return false;
1804
+ }
1796
1805
  function normalizeBuilderStateResult(state) {
1797
1806
  if (!state || typeof state !== "object") return err(queryErrors.invalidBuilderState(state));
1798
1807
  const s = state;
1808
+ const filter = normalizeFilter(s.filter);
1809
+ if (hasMalformedFilterLeaf(filter)) return err(queryErrors.malformedFilterLeaf());
1799
1810
  const normalized = {
1800
1811
  dimensions: Array.isArray(s.dimensions) ? s.dimensions : [],
1801
1812
  metrics: s.metrics,
1802
- filter: normalizeFilter(s.filter),
1803
- orderBy: s.orderBy,
1813
+ filter,
1814
+ orderBy: normalizeOrderBy(s.orderBy),
1804
1815
  rowLimit: s.rowLimit,
1805
1816
  startRow: s.startRow,
1806
1817
  dataState: s.dataState,
@@ -2359,4 +2370,4 @@ function today() {
2359
2370
  function daysAgo(n) {
2360
2371
  return daysAgoPst(n);
2361
2372
  }
2362
- export { Countries, Devices, SearchTypes, UnresolvableDatasetError, UnsupportedLogicalCapabilityError, and, between, buildLogicalComparisonPlan, buildLogicalComparisonPlanResult, buildLogicalPlan, buildLogicalPlanResult, clicks, contains, country, ctr, currentPstDate, date, daysAgo, device, eq, extractDateRange, extractMetricFilters, extractSearchType, extractSpecialOperatorFilters, formatQueryError, gsc, gt, gte, hour, impressions, inArray, isJsonFilter, isQueryError, like, lt, lte, ne, normalizeBuilderState, normalizeBuilderStateResult, normalizeFilter, not, notRegex, or, page, parseJsonFilter, position, query, queryCanonical, queryErrorToException, queryErrors, regex, resolveToBody, resolveToBodyResult, searchAppearance, searchType, today, topLevel };
2373
+ export { Countries, Devices, SearchTypes, UnresolvableDatasetError, UnsupportedLogicalCapabilityError, and, between, buildLogicalComparisonPlan, buildLogicalComparisonPlanResult, buildLogicalPlan, buildLogicalPlanResult, clicks, contains, country, ctr, currentPstDate, date, daysAgo, device, eq, extractDateRange, extractMetricFilters, extractSearchType, extractSpecialOperatorFilters, gsc, gt, gte, hour, impressions, inArray, isQueryError, like, lt, lte, ne, normalizeBuilderState, normalizeBuilderStateResult, normalizeFilter, not, notRegex, or, page, position, query, queryCanonical, queryErrorToException, queryErrors, regex, resolveToBody, resolveToBodyResult, searchAppearance, searchType, today, topLevel };
@@ -85,7 +85,7 @@ interface BuilderState {
85
85
  /** GSC search corpus. Wins over any `searchType` filter when both are set. */
86
86
  searchType?: SearchType;
87
87
  }
88
- type QueryErrorKind = 'missing-date-range' | 'invalid-row-limit' | 'invalid-start-row' | 'invalid-data-state' | 'invalid-aggregation-type' | 'invalid-builder-state' | 'unsupported-capability' | 'unresolvable-dataset';
88
+ type QueryErrorKind = 'missing-date-range' | 'invalid-row-limit' | 'invalid-start-row' | 'invalid-data-state' | 'invalid-aggregation-type' | 'invalid-builder-state' | 'invalid-filter' | 'unsupported-capability' | 'unresolvable-dataset';
89
89
  type QueryError = {
90
90
  kind: 'missing-date-range';
91
91
  message: string;
@@ -107,6 +107,9 @@ type QueryError = {
107
107
  kind: 'invalid-builder-state';
108
108
  message: string;
109
109
  cause?: unknown;
110
+ } | {
111
+ kind: 'invalid-filter';
112
+ message: string;
110
113
  } | {
111
114
  kind: 'unsupported-capability';
112
115
  capability: string;
@@ -85,6 +85,12 @@ const queryErrors = {
85
85
  message: "Invalid state"
86
86
  };
87
87
  },
88
+ malformedFilterLeaf() {
89
+ return {
90
+ kind: "invalid-filter",
91
+ message: "Malformed filter: each filter leaf requires a string `dimension` and `operator`"
92
+ };
93
+ },
88
94
  unsupportedCapability(capability, context) {
89
95
  return {
90
96
  kind: "unsupported-capability",
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "gscdump",
3
3
  "type": "module",
4
- "version": "0.40.1",
5
- "description": "Google Search Console API wrapper with typed query builder, streaming pagination, and SEO analysis functions",
4
+ "version": "1.0.0",
5
+ "description": "Direct Google Search Console client with typed queries, streaming pagination, URL inspection, and indexing helpers",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
8
8
  "email": "harlan@harlanzw.com",
@@ -37,11 +37,6 @@
37
37
  "import": "./dist/index.mjs",
38
38
  "default": "./dist/index.mjs"
39
39
  },
40
- "./api": {
41
- "types": "./dist/api/index.d.mts",
42
- "import": "./dist/api/index.mjs",
43
- "default": "./dist/api/index.mjs"
44
- },
45
40
  "./query": {
46
41
  "types": "./dist/query/index.d.mts",
47
42
  "import": "./dist/query/index.mjs",
@@ -84,28 +79,12 @@
84
79
  "dist"
85
80
  ],
86
81
  "engines": {
87
- "node": ">=18"
88
- },
89
- "peerDependencies": {
90
- "@googleapis/indexing": "^6.0.1",
91
- "@googleapis/searchconsole": "^6.0.1"
92
- },
93
- "peerDependenciesMeta": {
94
- "@googleapis/indexing": {
95
- "optional": true
96
- },
97
- "@googleapis/searchconsole": {
98
- "optional": true
99
- }
82
+ "node": ">=22"
100
83
  },
101
84
  "dependencies": {
102
85
  "date-fns": "^4.4.0",
103
86
  "ofetch": "^1.5.1",
104
- "@gscdump/contracts": "0.40.1"
105
- },
106
- "devDependencies": {
107
- "@googleapis/indexing": "^6.0.1",
108
- "@googleapis/searchconsole": "^6.0.1"
87
+ "@gscdump/contracts": "^1.0.0"
109
88
  },
110
89
  "scripts": {
111
90
  "dev": "obuild --stub",