@gscdump/sdk 0.19.7 → 0.20.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.
Files changed (2) hide show
  1. package/dist/index.mjs +82 -19
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -46,6 +46,7 @@ function toPartnerError(error) {
46
46
  }
47
47
  const TRAILING_SLASH_RE$2 = /\/+$/;
48
48
  const LEADING_SLASH_RE$1 = /^\/+/;
49
+ const DEFAULT_SEARCH_TYPE$1 = "web";
49
50
  function trimApiBase$1(apiBase) {
50
51
  return (apiBase ?? "").replace(TRAILING_SLASH_RE$2, "");
51
52
  }
@@ -67,9 +68,42 @@ function shouldValidate$1(options, phase) {
67
68
  function parseWith$1(schema, value) {
68
69
  return schema ? schema.parse(value) : value;
69
70
  }
70
- function tablesQuery$1(tables) {
71
- if (!tables) return void 0;
72
- return { tables: Array.isArray(tables) ? tables.join(",") : tables };
71
+ function isAnalysisSourcesOptions$1(value) {
72
+ return !!value && typeof value === "object" && !Array.isArray(value);
73
+ }
74
+ function searchTypeQuery(searchType) {
75
+ return { searchType: searchType ?? DEFAULT_SEARCH_TYPE$1 };
76
+ }
77
+ function dateRangeOptionsQuery(options) {
78
+ const query = {};
79
+ const start = options?.start ?? options?.startDate;
80
+ const end = options?.end ?? options?.endDate;
81
+ if (start) query.start = start;
82
+ if (end) query.end = end;
83
+ return query;
84
+ }
85
+ function sourceInfoQuery(options) {
86
+ return {
87
+ ...searchTypeQuery(options?.searchType),
88
+ ...dateRangeOptionsQuery(options)
89
+ };
90
+ }
91
+ function tablesQuery$1(tablesOrOptions, options) {
92
+ const tables = isAnalysisSourcesOptions$1(tablesOrOptions) ? tablesOrOptions.tables : tablesOrOptions;
93
+ const source = isAnalysisSourcesOptions$1(tablesOrOptions) ? tablesOrOptions : options;
94
+ const query = {
95
+ ...searchTypeQuery(source?.searchType),
96
+ ...dateRangeOptionsQuery(source)
97
+ };
98
+ if (tables) query.tables = Array.isArray(tables) ? tables.join(",") : tables;
99
+ return query;
100
+ }
101
+ function withDefaultSearchType$1(value) {
102
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
103
+ return {
104
+ ...value,
105
+ searchType: value.searchType ?? DEFAULT_SEARCH_TYPE$1
106
+ };
73
107
  }
74
108
  function indexingUrlsQuery$1(params = {}) {
75
109
  const query = {};
@@ -102,22 +136,22 @@ function createAnalyticsClient(options = {}) {
102
136
  listSites() {
103
137
  return request(analyticsRoutes.sites, {}, partnerEndpointSchemas.analyticsSites.response);
104
138
  },
105
- getSourceInfo(siteId) {
106
- return request(analyticsRoutes.site.sourceInfo(siteId), {}, partnerEndpointSchemas.analyticsSourceInfo.response);
139
+ getSourceInfo(siteId, options) {
140
+ return request(analyticsRoutes.site.sourceInfo(siteId), { query: sourceInfoQuery(options) }, partnerEndpointSchemas.analyticsSourceInfo.response);
107
141
  },
108
- getAnalysisSources(siteId, tables) {
109
- return request(analyticsRoutes.site.analysisSources(siteId), { query: tablesQuery$1(tables) }, partnerEndpointSchemas.analyticsAnalysisSources.response);
142
+ getAnalysisSources(siteId, tables, options) {
143
+ return request(analyticsRoutes.site.analysisSources(siteId), { query: tablesQuery$1(tables, options) }, partnerEndpointSchemas.analyticsAnalysisSources.response);
110
144
  },
111
145
  analyze(siteId, params) {
112
146
  return request(analyticsRoutes.site.analyze(siteId), {
113
147
  method: "POST",
114
- body: params
148
+ body: withDefaultSearchType$1(params)
115
149
  });
116
150
  },
117
151
  queryRows(siteId, state) {
118
152
  return request(analyticsRoutes.site.rows(siteId), {
119
153
  method: "POST",
120
- body: state
154
+ body: withDefaultSearchType$1(state)
121
155
  }, partnerEndpointSchemas.analyticsRows.response);
122
156
  },
123
157
  getRollup(siteId, rollupId, params) {
@@ -251,6 +285,7 @@ function findLifecycleSite(lifecycle, siteIdOrPropertyUrl) {
251
285
  }
252
286
  const TRAILING_SLASH_RE$1 = /\/+$/;
253
287
  const LEADING_SLASH_RE = /^\/+/;
288
+ const DEFAULT_SEARCH_TYPE = "web";
254
289
  function trimApiBase(apiBase) {
255
290
  return (apiBase ?? "/api").replace(TRAILING_SLASH_RE$1, "");
256
291
  }
@@ -268,15 +303,32 @@ async function resolveHeaders(options) {
268
303
  if (!options.apiKey) return resolved;
269
304
  return mergeHeaders(resolved, { "x-api-key": options.apiKey });
270
305
  }
306
+ function withDefaultSearchType(state, searchType) {
307
+ const scoped = state;
308
+ return {
309
+ ...state,
310
+ searchType: searchType ?? scoped.searchType ?? DEFAULT_SEARCH_TYPE
311
+ };
312
+ }
271
313
  function dataQuery(state, options) {
272
- const query = { q: JSON.stringify(state) };
273
- if (options?.comparison) query.qc = JSON.stringify(options.comparison);
274
- if (options?.filter) query.filter = options.filter;
314
+ const opts = options;
315
+ const scoped = withDefaultSearchType(state, opts?.searchType);
316
+ const query = {
317
+ q: JSON.stringify(scoped),
318
+ searchType: scoped.searchType ?? DEFAULT_SEARCH_TYPE
319
+ };
320
+ if (opts?.comparison) query.qc = JSON.stringify(withDefaultSearchType(opts.comparison, scoped.searchType));
321
+ if (opts?.filter) query.filter = opts.filter;
275
322
  return query;
276
323
  }
277
324
  function dataDetailQuery(state, options) {
278
- const query = { q: JSON.stringify(state) };
279
- if (options?.comparison) query.qc = JSON.stringify(options.comparison);
325
+ const opts = options;
326
+ const scoped = withDefaultSearchType(state, opts?.searchType);
327
+ const query = {
328
+ q: JSON.stringify(scoped),
329
+ searchType: scoped.searchType ?? DEFAULT_SEARCH_TYPE
330
+ };
331
+ if (opts?.comparison) query.qc = JSON.stringify(withDefaultSearchType(opts.comparison, scoped.searchType));
280
332
  return query;
281
333
  }
282
334
  function assertAnalysisParams(params) {
@@ -298,6 +350,7 @@ function analysisQuery(params) {
298
350
  if (params.minPosition != null) query.minPosition = params.minPosition;
299
351
  if (params.maxPosition != null) query.maxPosition = params.maxPosition;
300
352
  if (params.maxCtr != null) query.maxCtr = params.maxCtr;
353
+ query.searchType = params.searchType ?? DEFAULT_SEARCH_TYPE;
301
354
  return query;
302
355
  }
303
356
  function indexingUrlsQuery(params = {}) {
@@ -309,9 +362,19 @@ function indexingUrlsQuery(params = {}) {
309
362
  if (params.search) query.search = params.search;
310
363
  return query;
311
364
  }
312
- function tablesQuery(tables) {
313
- if (!tables) return void 0;
314
- return { tables: Array.isArray(tables) ? tables.join(",") : tables };
365
+ function isAnalysisSourcesOptions(value) {
366
+ return !!value && typeof value === "object" && !Array.isArray(value);
367
+ }
368
+ function tablesQuery(tablesOrOptions, options) {
369
+ const tables = isAnalysisSourcesOptions(tablesOrOptions) ? tablesOrOptions.tables : tablesOrOptions;
370
+ const source = isAnalysisSourcesOptions(tablesOrOptions) ? tablesOrOptions : options;
371
+ const query = { searchType: source?.searchType ?? DEFAULT_SEARCH_TYPE };
372
+ const start = source?.start ?? source?.startDate;
373
+ const end = source?.end ?? source?.endDate;
374
+ if (start) query.start = start;
375
+ if (end) query.end = end;
376
+ if (tables) query.tables = Array.isArray(tables) ? tables.join(",") : tables;
377
+ return query;
315
378
  }
316
379
  function dateRangeQuery(params) {
317
380
  return {
@@ -441,8 +504,8 @@ function createPartnerClient(options = {}) {
441
504
  deleteSite(siteId) {
442
505
  return request(partnerRoutes.sites.byId(siteId), { method: "DELETE" });
443
506
  },
444
- getAnalysisSources(siteId, tables) {
445
- return request(partnerRoutes.sites.analysisSources(siteId), { query: tablesQuery(tables) }, partnerEndpointSchemas.getAnalysisSources.response);
507
+ getAnalysisSources(siteId, tables, options) {
508
+ return request(partnerRoutes.sites.analysisSources(siteId), { query: tablesQuery(tables, options) }, partnerEndpointSchemas.getAnalysisSources.response);
446
509
  },
447
510
  async getSiteSyncStatus(siteId, userId) {
448
511
  if (!userId) return request(partnerRoutes.sites.syncStatus(siteId));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gscdump/sdk",
3
3
  "type": "module",
4
- "version": "0.19.7",
4
+ "version": "0.20.0",
5
5
  "description": "Consumer SDK for hosted gscdump.com integrations.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -41,7 +41,7 @@
41
41
  "node": ">=18"
42
42
  },
43
43
  "peerDependencies": {
44
- "gscdump": "0.19.7"
44
+ "gscdump": "0.20.0"
45
45
  },
46
46
  "peerDependenciesMeta": {
47
47
  "gscdump": {
@@ -51,7 +51,7 @@
51
51
  "dependencies": {
52
52
  "ofetch": "^1.5.1",
53
53
  "zod": "^4.4.3",
54
- "@gscdump/contracts": "0.19.7"
54
+ "@gscdump/contracts": "0.20.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "typescript": "^6.0.3",