@liiift-studio/sanity-visitor-insights 0.2.0 → 0.2.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.
package/dist/server.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { S as SiteAnalyticsConfig, D as DiagnosticReport } from './ranges-DSFapooC.mjs';
2
2
  export { A as AcquisitionData, m as CheckStatus, n as ConfigProblem, C as Coverage, d as DateRange, q as DiagnosticCheck, E as EventCutover, s as ExitPage, G as GA4_PROCESSING_LAG_DAYS, t as Ga4Config, J as JourneyData, w as JourneyStep, c as MeasurementHealthData, M as MetricValue, O as OrdersConfig, P as PREEXISTING, e as REPORT_NAMES, b as RangeKey, R as ReportEnvelope, f as ReportError, a as ReportName, g as SourceName, x as SourceRow, h as SourceStatus, T as TypefaceInterestData, y as TypefaceInterestRow, U as UnavailableReason, V as VercelConfig, z as applyCoverage, B as assertValidSiteConfig, i as coverageForRange, F as coverageNotices, H as daysBetween, I as formatInTimeZone, j as isReportName, K as isValidTimeZone, o as ok, p as partial, k as previousRange, L as provisionalDates, N as provisionalNotice, r as resolveRange, Q as shiftDays, u as unavailable, v as validateSiteConfig, l as valueOrNull } from './ranges-DSFapooC.mjs';
3
- import { S as SanityQueryClient, G as Ga4Client, V as VercelClient } from './vercel-D19ArNAY.mjs';
3
+ import { S as SanityQueryClient, G as Ga4Client, V as VercelClient } from './vercel-BMEO-Jcw.mjs';
4
+ export { a as Ga4Report, b as Ga4ReportRequest, c as ServiceAccountKey, d as VercelPageviews, e as createGa4Client, f as createVercelClient, p as parseServiceAccountKey } from './vercel-BMEO-Jcw.mjs';
4
5
 
5
6
  /**
6
7
  * Request authentication and CORS for the report handler.
@@ -208,4 +209,4 @@ interface DiagnosticsInput {
208
209
  */
209
210
  declare function runDiagnostics(input: DiagnosticsInput): Promise<DiagnosticReport>;
210
211
 
211
- export { DESIGN_INDUSTRY_SOURCES, DiagnosticReport, type DiagnosticsInput, ENV_VARS, type HandlerOptions, type HandlerRequest, type HandlerResponse, JOURNEY_STEPS, SanityQueryClient, SiteAnalyticsConfig, type StudioUser, applyCors, clearCache, createVisitorInsightsHandler, requireStudioUser, runDiagnostics, verifyStudioRequest };
212
+ export { DESIGN_INDUSTRY_SOURCES, DiagnosticReport, type DiagnosticsInput, ENV_VARS, Ga4Client, type HandlerOptions, type HandlerRequest, type HandlerResponse, JOURNEY_STEPS, SanityQueryClient, SiteAnalyticsConfig, type StudioUser, VercelClient, applyCors, clearCache, createVisitorInsightsHandler, requireStudioUser, runDiagnostics, verifyStudioRequest };
package/dist/server.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { S as SiteAnalyticsConfig, D as DiagnosticReport } from './ranges-DSFapooC.js';
2
2
  export { A as AcquisitionData, m as CheckStatus, n as ConfigProblem, C as Coverage, d as DateRange, q as DiagnosticCheck, E as EventCutover, s as ExitPage, G as GA4_PROCESSING_LAG_DAYS, t as Ga4Config, J as JourneyData, w as JourneyStep, c as MeasurementHealthData, M as MetricValue, O as OrdersConfig, P as PREEXISTING, e as REPORT_NAMES, b as RangeKey, R as ReportEnvelope, f as ReportError, a as ReportName, g as SourceName, x as SourceRow, h as SourceStatus, T as TypefaceInterestData, y as TypefaceInterestRow, U as UnavailableReason, V as VercelConfig, z as applyCoverage, B as assertValidSiteConfig, i as coverageForRange, F as coverageNotices, H as daysBetween, I as formatInTimeZone, j as isReportName, K as isValidTimeZone, o as ok, p as partial, k as previousRange, L as provisionalDates, N as provisionalNotice, r as resolveRange, Q as shiftDays, u as unavailable, v as validateSiteConfig, l as valueOrNull } from './ranges-DSFapooC.js';
3
- import { S as SanityQueryClient, G as Ga4Client, V as VercelClient } from './vercel-D19ArNAY.js';
3
+ import { S as SanityQueryClient, G as Ga4Client, V as VercelClient } from './vercel-BMEO-Jcw.js';
4
+ export { a as Ga4Report, b as Ga4ReportRequest, c as ServiceAccountKey, d as VercelPageviews, e as createGa4Client, f as createVercelClient, p as parseServiceAccountKey } from './vercel-BMEO-Jcw.js';
4
5
 
5
6
  /**
6
7
  * Request authentication and CORS for the report handler.
@@ -208,4 +209,4 @@ interface DiagnosticsInput {
208
209
  */
209
210
  declare function runDiagnostics(input: DiagnosticsInput): Promise<DiagnosticReport>;
210
211
 
211
- export { DESIGN_INDUSTRY_SOURCES, DiagnosticReport, type DiagnosticsInput, ENV_VARS, type HandlerOptions, type HandlerRequest, type HandlerResponse, JOURNEY_STEPS, SanityQueryClient, SiteAnalyticsConfig, type StudioUser, applyCors, clearCache, createVisitorInsightsHandler, requireStudioUser, runDiagnostics, verifyStudioRequest };
212
+ export { DESIGN_INDUSTRY_SOURCES, DiagnosticReport, type DiagnosticsInput, ENV_VARS, Ga4Client, type HandlerOptions, type HandlerRequest, type HandlerResponse, JOURNEY_STEPS, SanityQueryClient, SiteAnalyticsConfig, type StudioUser, VercelClient, applyCors, clearCache, createVisitorInsightsHandler, requireStudioUser, runDiagnostics, verifyStudioRequest };
package/dist/server.js CHANGED
@@ -32,12 +32,15 @@ __export(server_exports, {
32
32
  clearCache: () => clearCache,
33
33
  coverageForRange: () => coverageForRange,
34
34
  coverageNotices: () => coverageNotices,
35
+ createGa4Client: () => createGa4Client,
36
+ createVercelClient: () => createVercelClient,
35
37
  createVisitorInsightsHandler: () => createVisitorInsightsHandler,
36
38
  daysBetween: () => daysBetween,
37
39
  formatInTimeZone: () => formatInTimeZone,
38
40
  isReportName: () => isReportName,
39
41
  isValidTimeZone: () => isValidTimeZone,
40
42
  ok: () => ok,
43
+ parseServiceAccountKey: () => parseServiceAccountKey,
41
44
  partial: () => partial,
42
45
  previousRange: () => previousRange,
43
46
  provisionalDates: () => provisionalDates,
@@ -424,33 +427,43 @@ function sumFirstMetric(report) {
424
427
  }
425
428
 
426
429
  // src/server/vercel.ts
427
- var API_BASE = "https://api.vercel.com";
430
+ var API_BASE = "https://api.vercel.com/v1/query/web-analytics";
428
431
  function createVercelClient(projectId, token, teamId) {
432
+ async function query(path, extra) {
433
+ const params = new URLSearchParams({ projectId, ...extra });
434
+ if (teamId) params.set("teamId", teamId);
435
+ const response = await fetch(`${API_BASE}/${path}?${params.toString()}`, {
436
+ headers: { Authorization: `Bearer ${token}` }
437
+ });
438
+ if (!response.ok) {
439
+ throw new Error(`Vercel Web Analytics ${path} failed with ${response.status}`);
440
+ }
441
+ return await response.json();
442
+ }
429
443
  return {
430
444
  async pageviews(start, end) {
431
- const params = new URLSearchParams({
432
- projectId,
433
- since: `${start}T00:00:00.000Z`,
434
- until: `${end}T23:59:59.999Z`
435
- });
436
- if (teamId) params.set("teamId", teamId);
437
- const response = await fetch(`${API_BASE}/v1/web-analytics/timeseries?${params.toString()}`, {
438
- headers: { Authorization: `Bearer ${token}` }
439
- });
440
- if (!response.ok) {
441
- throw new Error(`Vercel Web Analytics failed with ${response.status}`);
442
- }
443
- const body = await response.json();
445
+ const [totals, series] = await Promise.all([
446
+ query("visits/count", {
447
+ since: start,
448
+ until: end
449
+ }),
450
+ query("visits/aggregate", {
451
+ since: start,
452
+ until: end,
453
+ by: "day",
454
+ limit: "100"
455
+ })
456
+ ]);
444
457
  const byDate = {};
445
- let total = 0;
446
- for (const point of body.data ?? []) {
447
- if (!point.key) continue;
448
- const date = point.key.slice(0, 10);
449
- const count = typeof point.total === "number" ? point.total : 0;
450
- byDate[date] = (byDate[date] ?? 0) + count;
451
- total += count;
458
+ for (const row of series.data ?? []) {
459
+ if (!row.timestamp) continue;
460
+ byDate[row.timestamp.slice(0, 10)] = row.pageviews ?? 0;
452
461
  }
453
- return { byDate, total };
462
+ return {
463
+ byDate,
464
+ total: totals.data?.pageviews ?? 0,
465
+ visitors: totals.data?.visitors ?? 0
466
+ };
454
467
  }
455
468
  };
456
469
  }
@@ -1193,12 +1206,15 @@ async function runReport(report, ctx) {
1193
1206
  clearCache,
1194
1207
  coverageForRange,
1195
1208
  coverageNotices,
1209
+ createGa4Client,
1210
+ createVercelClient,
1196
1211
  createVisitorInsightsHandler,
1197
1212
  daysBetween,
1198
1213
  formatInTimeZone,
1199
1214
  isReportName,
1200
1215
  isValidTimeZone,
1201
1216
  ok,
1217
+ parseServiceAccountKey,
1202
1218
  partial,
1203
1219
  previousRange,
1204
1220
  provisionalDates,