@canonry/canonry 7.125.2 → 7.125.4
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/activity-KCUWSNHF.js +13 -0
- package/dist/{ads-5EFVWQAT.js → ads-6ZCVMSJ2.js} +4 -4
- package/dist/{agent-P5WEU72Q.js → agent-ZZJO7ET6.js} +8 -8
- package/dist/{agent-ask-DQBDMPXP.js → agent-ask-CPRHVULM.js} +4 -4
- package/dist/{agent-conversations-K6IX3LQW.js → agent-conversations-NIWKSUC2.js} +4 -4
- package/dist/{agent-journeys-72PYZCJH.js → agent-journeys-SHNRNV5E.js} +4 -4
- package/dist/{agent-memory-6GVOIDFK.js → agent-memory-4IGCNFR5.js} +4 -4
- package/dist/{agent-providers-TZJL475J.js → agent-providers-3Q7NQS7Y.js} +4 -4
- package/dist/{agent-transcript-L4IIMHXD.js → agent-transcript-M3NYHNNV.js} +4 -4
- package/dist/{analytics-7XKDB5OX.js → analytics-UHBUOG4T.js} +4 -4
- package/dist/{answerability-PE6Z2QHX.js → answerability-IRXQDOBX.js} +4 -4
- package/dist/{apply-LP2QYAOJ.js → apply-3HP75CA2.js} +4 -4
- package/dist/{backfill-FWKKCPH4.js → backfill-Y6M5HPT7.js} +11 -11
- package/dist/{backlinks-GOQOLXYQ.js → backlinks-O5IYHDAY.js} +4 -4
- package/dist/{bing-URWLP36H.js → bing-2MTKNQB2.js} +4 -4
- package/dist/{bootstrap-3D7WYMAK.js → bootstrap-O7FRHURI.js} +11 -11
- package/dist/{cdp-HTUSJ3YA.js → cdp-BTXUJFAN.js} +8 -8
- package/dist/{chunk-4JPL2SDU.js → chunk-2MDEKCDU.js} +12 -5
- package/dist/{chunk-ZJ6HMVLQ.js → chunk-32LTZWWW.js} +1 -1
- package/dist/{chunk-7M5QTA7T.js → chunk-35NITZHC.js} +1 -1
- package/dist/{chunk-NVFFBVJJ.js → chunk-3FQMXAES.js} +5 -5
- package/dist/{chunk-IM3LJ45S.js → chunk-3G5FQLF7.js} +2 -2
- package/dist/{chunk-5LZJGJFF.js → chunk-3OZ5WKRH.js} +5 -0
- package/dist/{chunk-TNV7DLA7.js → chunk-A75GIIWP.js} +1 -1
- package/dist/{chunk-PDWNORKC.js → chunk-C5EK4TJ5.js} +3 -3
- package/dist/{chunk-5QR5GEGS.js → chunk-CD3XPOHP.js} +1 -1
- package/dist/{chunk-KUO2TYF4.js → chunk-DI5EEYDP.js} +2 -2
- package/dist/{chunk-XCJSH2FJ.js → chunk-E57WK3OU.js} +5 -5
- package/dist/{chunk-HEKYXSY6.js → chunk-EE73V5GU.js} +377 -375
- package/dist/{chunk-HPRUS76O.js → chunk-FJRPVC6N.js} +6 -6
- package/dist/{chunk-CSU4E5KJ.js → chunk-IDMWQASY.js} +5 -5
- package/dist/{chunk-PR5TQK3X.js → chunk-JTIFRAGE.js} +3 -3
- package/dist/{chunk-F7ZJX5O5.js → chunk-K7BROEPL.js} +3 -3
- package/dist/{chunk-4A2GKNEM.js → chunk-KIO37ZVB.js} +4 -4
- package/dist/{chunk-BH4562RA.js → chunk-MB7VQPWX.js} +2 -2
- package/dist/{chunk-AVJIEIAV.js → chunk-ML7G6NS3.js} +2 -2
- package/dist/{chunk-LPQYGKS4.js → chunk-OH3HQENA.js} +4 -4
- package/dist/{chunk-O4S75UQI.js → chunk-OINP576M.js} +5 -5
- package/dist/{chunk-CQXIA6T6.js → chunk-OL6HAMWW.js} +2 -2
- package/dist/{chunk-FJ22V5ED.js → chunk-PAP62URW.js} +7 -6
- package/dist/{chunk-472IO3E7.js → chunk-PDSB34VB.js} +1 -1
- package/dist/{chunk-6SFT25SX.js → chunk-QCEXADUT.js} +2 -2
- package/dist/{chunk-FHJU7QBM.js → chunk-QQFTJVHT.js} +1 -1
- package/dist/{chunk-GUPHVIGW.js → chunk-QRA6GFXX.js} +1 -1
- package/dist/{chunk-IN7LINUI.js → chunk-RSZ3L5FJ.js} +1 -1
- package/dist/{chunk-BEJWFEEJ.js → chunk-U2LYHQHF.js} +1 -1
- package/dist/{chunk-7OQFD5BW.js → chunk-UG3NPUZQ.js} +4 -4
- package/dist/{chunk-WTAL4GJ4.js → chunk-UHUPDKPT.js} +8 -8
- package/dist/{chunk-TRYACZVH.js → chunk-UU3EPUFY.js} +79 -29
- package/dist/{chunk-LUA7YIQG.js → chunk-VD6Q7ZUX.js} +1 -1
- package/dist/{chunk-OTMAY3N2.js → chunk-VP3F4BOG.js} +2 -2
- package/dist/{chunk-KAFKHQCB.js → chunk-VUL3BACZ.js} +4 -4
- package/dist/{chunk-GZHLGRVL.js → chunk-XQUGLXAN.js} +2 -2
- package/dist/{chunk-U73NIQKU.js → chunk-YYBYRAMI.js} +4 -4
- package/dist/{chunk-3PPQMBTA.js → chunk-ZA624A36.js} +170 -137
- package/dist/{citations-M7RCHTBO.js → citations-5JSLIPNI.js} +5 -5
- package/dist/{cli-catalog-7WND6LOK.js → cli-catalog-U3DKCQC5.js} +4 -4
- package/dist/cli-commands-RKEFA6I6.js +18 -0
- package/dist/cli.js +14 -14
- package/dist/{competitor-4J3V4SNA.js → competitor-AMA7WPH4.js} +4 -4
- package/dist/{content-LN27FEUU.js → content-7HZ23UXM.js} +4 -4
- package/dist/{dashboard-ZYVYVNTW.js → dashboard-7DH4DFSJ.js} +7 -7
- package/dist/{demo-OKZN2MIB.js → demo-FWGWENAZ.js} +3 -3
- package/dist/{demo-server-JWBH7TVQ.js → demo-server-MQDIL5YL.js} +13 -13
- package/dist/{discover-AY7NU3SN.js → discover-TJXKEHVP.js} +5 -5
- package/dist/{discover-eval-OYO6HI5F.js → discover-eval-MUS46MSL.js} +4 -4
- package/dist/{doctor-XZOIPYYT.js → doctor-5CIMYYUA.js} +4 -4
- package/dist/{evidence-H3VPFFOR.js → evidence-MY4Z6VNC.js} +4 -4
- package/dist/{export-cmd-4SQREQZL.js → export-cmd-VBULRDSJ.js} +4 -4
- package/dist/{ga-DYT6WOA4.js → ga-ORQCNNJ6.js} +4 -4
- package/dist/{gbp-JDFCLW5K.js → gbp-LWVNCHMT.js} +4 -4
- package/dist/{google-KQAOZ5JT.js → google-U6LQOAQ3.js} +5 -5
- package/dist/{google-marketing-HQPW42FL.js → google-marketing-6RA4AOMN.js} +2 -2
- package/dist/{health-cmd-LDQC4ICZ.js → health-cmd-LQGRFFT3.js} +5 -5
- package/dist/{history-3S77KY77.js → history-LYJAA6QI.js} +4 -4
- package/dist/index.js +26 -26
- package/dist/{init-72RAXVAL.js → init-VSBN3TWT.js} +13 -13
- package/dist/{insights-GUM2MK47.js → insights-OP7ZJLC5.js} +4 -4
- package/dist/intelligence-service-HMCHOTG5.js +15 -0
- package/dist/{journeys-AG4425RQ.js → journeys-ENN25PA5.js} +4 -4
- package/dist/{keys-TWC2GRJX.js → keys-FVPHQIOM.js} +4 -4
- package/dist/{keyword-WKM3BZCJ.js → keyword-ELCUWNQC.js} +4 -4
- package/dist/{logs-7FHQF7UK.js → logs-SVKY3HXZ.js} +4 -4
- package/dist/{mcp-NRESCMDK.js → mcp-W7AMWAST.js} +5 -5
- package/dist/mcp.js +10 -10
- package/dist/{measurement-plan-2TJFII53.js → measurement-plan-F3ZZ4MCG.js} +6 -6
- package/dist/{notify-VQJKWE7U.js → notify-U253YRTY.js} +4 -4
- package/dist/{organic-evidence-UROWCQFB.js → organic-evidence-4GI6HG56.js} +4 -4
- package/dist/{overview-6CY6EEYZ.js → overview-TPZI3OKL.js} +7 -7
- package/dist/{project-6G7FIFIX.js → project-BZPMAZAH.js} +4 -4
- package/dist/{project-setup-3MPRV226.js → project-setup-2NSUAFXD.js} +4 -4
- package/dist/{query-CXUVUGB3.js → query-4AL5P6DI.js} +4 -4
- package/dist/{research-5OFFBHNJ.js → research-3WAJ6RWX.js} +4 -4
- package/dist/{results-export-WQ3ZI2RN.js → results-export-VHA6BPC2.js} +4 -4
- package/dist/{run-7IWLOX3K.js → run-3EEHYWIA.js} +6 -6
- package/dist/{schedule-7LTYEBTO.js → schedule-7CXVWV75.js} +4 -4
- package/dist/{search-UIGFCJOH.js → search-EPPXH2TK.js} +4 -4
- package/dist/{serve-SMBPWWOI.js → serve-CFXNLGUP.js} +27 -27
- package/dist/{session-XCMWUFDH.js → session-HATLEN7J.js} +14 -14
- package/dist/{settings-HNL5MRNK.js → settings-UKIPQVIX.js} +4 -4
- package/dist/{sitemaps-C6QXTFX7.js → sitemaps-L2OOCCHX.js} +4 -4
- package/dist/{skills-4SATHKAZ.js → skills-VJSJNLWC.js} +3 -3
- package/dist/{snapshot-77XTVMTM.js → snapshot-SYVUVM7F.js} +4 -4
- package/dist/{src-6UWY43K7.js → src-VYDX5USM.js} +2 -2
- package/dist/{status-GK5N7DBQ.js → status-ALZWCQ7W.js} +6 -6
- package/dist/{support-TLV5QQGD.js → support-XRKYBNND.js} +2 -2
- package/dist/{technical-aeo-BY5K3WCE.js → technical-aeo-JNYI6Q7L.js} +4 -4
- package/dist/{telemetry-3CK2V5EZ.js → telemetry-ZENJ5BDE.js} +5 -5
- package/dist/{tools-F2UCM5HU.js → tools-L7J5NNSY.js} +12 -12
- package/dist/{traffic-LVMK6SEY.js → traffic-YWF6EAN7.js} +6 -6
- package/dist/{trends-7JVT5AIN.js → trends-3755UQT3.js} +4 -4
- package/dist/{users-DMCJOD2L.js → users-7XCGU7BU.js} +4 -4
- package/dist/{visibility-stats-UWKATLY6.js → visibility-stats-QJBO7HFN.js} +5 -5
- package/dist/{wordpress-TRWQSNRK.js → wordpress-VC6UN5UK.js} +4 -4
- package/package.json +1 -1
- package/dist/activity-TDCPSQZ6.js +0 -13
- package/dist/cli-commands-BMVORBFI.js +0 -18
- package/dist/intelligence-service-7GKHJ3B4.js +0 -15
|
@@ -19,14 +19,14 @@ import {
|
|
|
19
19
|
normalizeTrafficPathPattern,
|
|
20
20
|
sessionizeJourneyRequests,
|
|
21
21
|
verifyRequestSignature
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-32LTZWWW.js";
|
|
23
23
|
import {
|
|
24
24
|
currentOutcomeAttribution,
|
|
25
25
|
getRequestContext,
|
|
26
26
|
registerRequestContext,
|
|
27
27
|
requestAuditIdentity,
|
|
28
28
|
sanitizeRequestContext
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-A75GIIWP.js";
|
|
30
30
|
import {
|
|
31
31
|
RawEventSampleEventTypes,
|
|
32
32
|
SentimentIdempotencyConflict,
|
|
@@ -191,7 +191,7 @@ import {
|
|
|
191
191
|
userSessions,
|
|
192
192
|
users,
|
|
193
193
|
writeNegativeReviewMaxStars
|
|
194
|
-
} from "./chunk-
|
|
194
|
+
} from "./chunk-35NITZHC.js";
|
|
195
195
|
import {
|
|
196
196
|
ADS_ACTIVATE_SCOPE,
|
|
197
197
|
ADS_ACTIVATION_ABSOLUTE_MAX_ENTITIES,
|
|
@@ -568,6 +568,7 @@ import {
|
|
|
568
568
|
apiKeyListDtoSchema,
|
|
569
569
|
applyHarvestSemanticNovelty,
|
|
570
570
|
applyPreviewDtoSchema,
|
|
571
|
+
asRecord,
|
|
571
572
|
auditHistoryQuerySchema,
|
|
572
573
|
auditLogEntrySchema,
|
|
573
574
|
authInvalid,
|
|
@@ -885,6 +886,7 @@ import {
|
|
|
885
886
|
indexingRequestResponseDtoSchema,
|
|
886
887
|
insightActionGroupByType,
|
|
887
888
|
instanceStatusDtoSchema,
|
|
889
|
+
integrationNotConnected,
|
|
888
890
|
integrationSettingsSummaryDtoSchema,
|
|
889
891
|
internalError,
|
|
890
892
|
intersectScopes,
|
|
@@ -1405,7 +1407,7 @@ import {
|
|
|
1405
1407
|
wordpressSchemaDeployResultDtoSchema,
|
|
1406
1408
|
wordpressSchemaStatusResultDtoSchema,
|
|
1407
1409
|
wordpressStatusDtoSchema
|
|
1408
|
-
} from "./chunk-
|
|
1410
|
+
} from "./chunk-3OZ5WKRH.js";
|
|
1409
1411
|
|
|
1410
1412
|
// ../api-routes/src/user-session.ts
|
|
1411
1413
|
import crypto2 from "crypto";
|
|
@@ -21290,7 +21292,7 @@ async function competitorSuggestionRoutes(app) {
|
|
|
21290
21292
|
import crypto25 from "crypto";
|
|
21291
21293
|
import { and as and45, eq as eq55, ne as ne9, asc as asc10, desc as desc19, inArray as inArray27, notInArray as notInArray3, or as or8, sql as sql21 } from "drizzle-orm";
|
|
21292
21294
|
import { z as z4 } from "zod";
|
|
21293
|
-
import { gte as gte12 } from "drizzle-orm";
|
|
21295
|
+
import { gte as gte12, lte as lte10 } from "drizzle-orm";
|
|
21294
21296
|
|
|
21295
21297
|
// ../api-routes/src/run-fill.ts
|
|
21296
21298
|
import crypto23 from "crypto";
|
|
@@ -22708,8 +22710,10 @@ async function runRoutes(app, opts) {
|
|
|
22708
22710
|
const limit = Number.isNaN(parsedLimit) || parsedLimit <= 0 ? void 0 : parsedLimit;
|
|
22709
22711
|
const { kind, excludeKind, excludeKinds, status } = parseListFilters(request.query);
|
|
22710
22712
|
const filters = [eq55(runs.projectId, project.id)];
|
|
22711
|
-
const since =
|
|
22713
|
+
const since = parseListTimestamp(request.query.since, "since");
|
|
22712
22714
|
if (since) filters.push(gte12(runs.createdAt, since));
|
|
22715
|
+
const until = parseListTimestamp(request.query.until, "until");
|
|
22716
|
+
if (until) filters.push(lte10(runs.createdAt, until));
|
|
22713
22717
|
if (kind) filters.push(eq55(runs.kind, kind));
|
|
22714
22718
|
if (excludeKind) filters.push(ne9(runs.kind, excludeKind));
|
|
22715
22719
|
if (excludeKinds?.length) filters.push(notInArray3(runs.kind, excludeKinds));
|
|
@@ -22766,7 +22770,7 @@ async function runRoutes(app, opts) {
|
|
|
22766
22770
|
});
|
|
22767
22771
|
app.get("/runs", async (request, reply) => {
|
|
22768
22772
|
const limit = parseListLimit(request.query.limit, 500, 5e3);
|
|
22769
|
-
const since =
|
|
22773
|
+
const since = parseListTimestamp(request.query.since, "since", new Date(Date.now() - 30 * 24 * 60 * 60 * 1e3).toISOString());
|
|
22770
22774
|
const includeProbe = request.query.includeProbe === "1" || request.query.includeProbe === "true";
|
|
22771
22775
|
const { kind, excludeKind, excludeKinds, status } = parseListFilters(request.query);
|
|
22772
22776
|
const filters = [gte12(runs.createdAt, since)];
|
|
@@ -22781,7 +22785,7 @@ async function runRoutes(app, opts) {
|
|
|
22781
22785
|
return reply.send(rows.map(formatRun));
|
|
22782
22786
|
});
|
|
22783
22787
|
app.get("/runs/attention", async (request, reply) => {
|
|
22784
|
-
const since =
|
|
22788
|
+
const since = parseListTimestamp(request.query.since, "since", new Date(Date.now() - OVERVIEW_ACTIVITY_DEFAULT_DAYS * 24 * 60 * 60 * 1e3).toISOString());
|
|
22785
22789
|
const filters = [gte12(runs.createdAt, since), notProbeRun(), notInArray3(runs.kind, [...OVERVIEW_ACTIVITY_EXCLUDED_KINDS])];
|
|
22786
22790
|
const scopedProjectId = request.apiKey?.projectId;
|
|
22787
22791
|
if (scopedProjectId) filters.push(eq55(runs.projectId, scopedProjectId));
|
|
@@ -23098,11 +23102,11 @@ function parseListFilters(query2) {
|
|
|
23098
23102
|
const message = invalid.length > 0 ? invalid.map((field) => `"${field}" must be one of: ${RUN_LIST_FILTER_OPTIONS[field].join(", ")}`).join("; ") : "Invalid run list filters";
|
|
23099
23103
|
throw validationError(message, { invalid: Object.fromEntries(invalid.map((field) => [field, query2[field]])) });
|
|
23100
23104
|
}
|
|
23101
|
-
function
|
|
23105
|
+
function parseListTimestamp(raw, field, fallback) {
|
|
23102
23106
|
if (raw === void 0) return fallback;
|
|
23103
23107
|
const date = new Date(raw);
|
|
23104
23108
|
if (Number.isNaN(date.getTime())) {
|
|
23105
|
-
throw validationError(
|
|
23109
|
+
throw validationError(`"${field}" must be a valid ISO 8601 timestamp`);
|
|
23106
23110
|
}
|
|
23107
23111
|
return date.toISOString();
|
|
23108
23112
|
}
|
|
@@ -25899,7 +25903,7 @@ async function technicalAeoRoutes(app, opts) {
|
|
|
25899
25903
|
|
|
25900
25904
|
// ../api-routes/src/visibility-report.ts
|
|
25901
25905
|
import { createHash as createHash6 } from "crypto";
|
|
25902
|
-
import { and as and48, desc as desc21, eq as eq58, gte as gte14, inArray as inArray29, isNotNull as isNotNull9, isNull as isNull12, lt as lt12, lte as
|
|
25906
|
+
import { and as and48, desc as desc21, eq as eq58, gte as gte14, inArray as inArray29, isNotNull as isNotNull9, isNull as isNull12, lt as lt12, lte as lte11, or as or10 } from "drizzle-orm";
|
|
25903
25907
|
|
|
25904
25908
|
// ../api-routes/src/visibility-report-reader.ts
|
|
25905
25909
|
import { createHash as createHash5 } from "crypto";
|
|
@@ -27142,7 +27146,7 @@ function completedVisibilityRuns(db, projectId, planless, query2) {
|
|
|
27142
27146
|
query2.runId === void 0 ? notScopedRun() : void 0,
|
|
27143
27147
|
query2.runId === void 0 ? void 0 : eq58(runs.id, query2.runId),
|
|
27144
27148
|
query2.from === void 0 ? void 0 : gte14(runs.createdAt, query2.from),
|
|
27145
|
-
query2.to === void 0 ? void 0 :
|
|
27149
|
+
query2.to === void 0 ? void 0 : lte11(runs.createdAt, query2.to)
|
|
27146
27150
|
)).orderBy(desc21(runs.createdAt), desc21(runs.id)).limit(VISIBILITY_REPORT_MAX_RUNS).all();
|
|
27147
27151
|
}
|
|
27148
27152
|
function previousEligibleVisibilityRun(db, projectId, planless, selected) {
|
|
@@ -27454,7 +27458,7 @@ function readVisibilityComparisonRuns(db, projectId, since, until, includeEviden
|
|
|
27454
27458
|
isNotNull9(runs.measurementPlanVersionId),
|
|
27455
27459
|
notScopedRun(),
|
|
27456
27460
|
gte14(runs.createdAt, since),
|
|
27457
|
-
|
|
27461
|
+
lte11(runs.createdAt, until)
|
|
27458
27462
|
)).all();
|
|
27459
27463
|
const versionRows = db.select().from(measurementPlanVersions).where(eq58(measurementPlanVersions.projectId, projectId)).all();
|
|
27460
27464
|
const rowsById = new Map(versionRows.map((version) => [version.id, version]));
|
|
@@ -36993,7 +36997,7 @@ async function applyRoutes(app, opts) {
|
|
|
36993
36997
|
}
|
|
36994
36998
|
|
|
36995
36999
|
// ../api-routes/src/history.ts
|
|
36996
|
-
import { and as and59, asc as asc15, count as count7, getTableColumns as getTableColumns2, desc as desc27, eq as eq70, gte as gte15, inArray as inArray35, like as like3, lte as
|
|
37000
|
+
import { and as and59, asc as asc15, count as count7, getTableColumns as getTableColumns2, desc as desc27, eq as eq70, gte as gte15, inArray as inArray35, like as like3, lte as lte12, ne as ne11, notInArray as notInArray4, or as or12, sql as sql26 } from "drizzle-orm";
|
|
36997
37001
|
async function historyRoutes(app) {
|
|
36998
37002
|
app.post("/projects/:name/results/clear", async (request) => {
|
|
36999
37003
|
requireAdminSession(request);
|
|
@@ -37350,7 +37354,7 @@ function parseAuditHistoryQuery(query2) {
|
|
|
37350
37354
|
}
|
|
37351
37355
|
function addAuditHistoryFilters(filters, query2) {
|
|
37352
37356
|
if (query2.since) filters.push(gte15(auditLog.createdAt, new Date(query2.since).toISOString()));
|
|
37353
|
-
if (query2.until) filters.push(
|
|
37357
|
+
if (query2.until) filters.push(lte12(auditLog.createdAt, new Date(query2.until).toISOString()));
|
|
37354
37358
|
if (query2.actionPrefix) filters.push(sql26`${auditLog.action} LIKE ${escapeLikePattern(query2.actionPrefix) + "%"} ESCAPE '\\'`);
|
|
37355
37359
|
if (query2.entityId) filters.push(eq70(auditLog.entityId, query2.entityId));
|
|
37356
37360
|
if (query2.excludeEntityTypes?.length) filters.push(notInArray4(auditLog.entityType, query2.excludeEntityTypes));
|
|
@@ -38612,7 +38616,7 @@ async function intelligenceRoutes(app) {
|
|
|
38612
38616
|
}
|
|
38613
38617
|
|
|
38614
38618
|
// ../api-routes/src/traffic-analytics.ts
|
|
38615
|
-
import { and as and64, desc as desc31, eq as eq74, gte as gte17, lt as lt16, lte as
|
|
38619
|
+
import { and as and64, desc as desc31, eq as eq74, gte as gte17, lt as lt16, lte as lte13, ne as ne12, sql as sql29 } from "drizzle-orm";
|
|
38616
38620
|
|
|
38617
38621
|
// ../api-routes/src/ai-referral-status.ts
|
|
38618
38622
|
import { and as and62, sql as sql27 } from "drizzle-orm";
|
|
@@ -38711,7 +38715,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38711
38715
|
eq74(crawlerEventsHourly.projectId, projectId),
|
|
38712
38716
|
eq74(crawlerEventsHourly.verificationStatus, VerificationStatuses.verified),
|
|
38713
38717
|
gte17(crawlerEventsHourly.tsHour, windowStartIso),
|
|
38714
|
-
exclusiveEnd ? lt16(crawlerEventsHourly.tsHour, windowEndIso) :
|
|
38718
|
+
exclusiveEnd ? lt16(crawlerEventsHourly.tsHour, windowEndIso) : lte13(crawlerEventsHourly.tsHour, windowEndIso)
|
|
38715
38719
|
)
|
|
38716
38720
|
).get()?.total ?? 0
|
|
38717
38721
|
);
|
|
@@ -38721,7 +38725,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38721
38725
|
eq74(crawlerEventsHourly.projectId, projectId),
|
|
38722
38726
|
ne12(crawlerEventsHourly.verificationStatus, VerificationStatuses.verified),
|
|
38723
38727
|
gte17(crawlerEventsHourly.tsHour, windowStartIso),
|
|
38724
|
-
exclusiveEnd ? lt16(crawlerEventsHourly.tsHour, windowEndIso) :
|
|
38728
|
+
exclusiveEnd ? lt16(crawlerEventsHourly.tsHour, windowEndIso) : lte13(crawlerEventsHourly.tsHour, windowEndIso)
|
|
38725
38729
|
)
|
|
38726
38730
|
).get()?.total ?? 0
|
|
38727
38731
|
);
|
|
@@ -38735,7 +38739,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38735
38739
|
eq74(aiReferralEventsHourly.projectId, projectId),
|
|
38736
38740
|
countableReferralCondition(),
|
|
38737
38741
|
gte17(aiReferralEventsHourly.tsHour, windowStartIso),
|
|
38738
|
-
exclusiveEnd ? lt16(aiReferralEventsHourly.tsHour, windowEndIso) :
|
|
38742
|
+
exclusiveEnd ? lt16(aiReferralEventsHourly.tsHour, windowEndIso) : lte13(aiReferralEventsHourly.tsHour, windowEndIso)
|
|
38739
38743
|
)
|
|
38740
38744
|
).get();
|
|
38741
38745
|
return aiReferralClassCounts(Number(row?.total ?? 0), Number(row?.paid ?? 0), Number(row?.organic ?? 0));
|
|
@@ -38745,7 +38749,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38745
38749
|
and64(
|
|
38746
38750
|
eq74(aiUserFetchEventsHourly.projectId, projectId),
|
|
38747
38751
|
gte17(aiUserFetchEventsHourly.tsHour, windowStartIso),
|
|
38748
|
-
exclusiveEnd ? lt16(aiUserFetchEventsHourly.tsHour, windowEndIso) :
|
|
38752
|
+
exclusiveEnd ? lt16(aiUserFetchEventsHourly.tsHour, windowEndIso) : lte13(aiUserFetchEventsHourly.tsHour, windowEndIso)
|
|
38749
38753
|
)
|
|
38750
38754
|
).get()?.total ?? 0
|
|
38751
38755
|
);
|
|
@@ -38762,7 +38766,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38762
38766
|
eq74(aiReferralEventsHourly.projectId, projectId),
|
|
38763
38767
|
nonSubresourceReferralPathCondition(),
|
|
38764
38768
|
gte17(aiReferralEventsHourly.tsHour, headlineStart),
|
|
38765
|
-
|
|
38769
|
+
lte13(aiReferralEventsHourly.tsHour, headlineEnd)
|
|
38766
38770
|
)
|
|
38767
38771
|
).get()?.total ?? 0
|
|
38768
38772
|
);
|
|
@@ -38776,7 +38780,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38776
38780
|
and64(
|
|
38777
38781
|
eq74(crawlerEventsHourly.projectId, projectId),
|
|
38778
38782
|
gte17(crawlerEventsHourly.tsHour, headlineStart),
|
|
38779
|
-
|
|
38783
|
+
lte13(crawlerEventsHourly.tsHour, headlineEnd)
|
|
38780
38784
|
)
|
|
38781
38785
|
).groupBy(crawlerEventsHourly.operator, crawlerEventsHourly.verificationStatus).all();
|
|
38782
38786
|
const crawlerByOperatorPriorRows = db.select({
|
|
@@ -38797,7 +38801,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38797
38801
|
eq74(aiReferralEventsHourly.projectId, projectId),
|
|
38798
38802
|
countableReferralCondition(),
|
|
38799
38803
|
gte17(aiReferralEventsHourly.tsHour, headlineStart),
|
|
38800
|
-
|
|
38804
|
+
lte13(aiReferralEventsHourly.tsHour, headlineEnd)
|
|
38801
38805
|
)
|
|
38802
38806
|
).groupBy(aiReferralEventsHourly.operator).all();
|
|
38803
38807
|
const userFetchByOperatorRows = db.select({
|
|
@@ -38807,7 +38811,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38807
38811
|
and64(
|
|
38808
38812
|
eq74(aiUserFetchEventsHourly.projectId, projectId),
|
|
38809
38813
|
gte17(aiUserFetchEventsHourly.tsHour, headlineStart),
|
|
38810
|
-
|
|
38814
|
+
lte13(aiUserFetchEventsHourly.tsHour, headlineEnd)
|
|
38811
38815
|
)
|
|
38812
38816
|
).groupBy(aiUserFetchEventsHourly.operator).all();
|
|
38813
38817
|
const operatorAgg = /* @__PURE__ */ new Map();
|
|
@@ -38852,7 +38856,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38852
38856
|
and64(
|
|
38853
38857
|
eq74(crawlerEventsHourly.projectId, projectId),
|
|
38854
38858
|
gte17(crawlerEventsHourly.tsHour, headlineStart),
|
|
38855
|
-
|
|
38859
|
+
lte13(crawlerEventsHourly.tsHour, headlineEnd)
|
|
38856
38860
|
)
|
|
38857
38861
|
).groupBy(crawlerEventsHourly.pathNormalized).orderBy(desc31(sql29`SUM(${crawlerEventsHourly.hits})`)).limit(SERVER_ACTIVITY_TOP_PATHS_LIMIT).all();
|
|
38858
38862
|
const topCrawledPaths = topPathsRows.map((r) => ({
|
|
@@ -38870,7 +38874,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38870
38874
|
eq74(aiReferralEventsHourly.projectId, projectId),
|
|
38871
38875
|
countableReferralCondition(),
|
|
38872
38876
|
gte17(aiReferralEventsHourly.tsHour, headlineStart),
|
|
38873
|
-
|
|
38877
|
+
lte13(aiReferralEventsHourly.tsHour, headlineEnd)
|
|
38874
38878
|
)
|
|
38875
38879
|
).groupBy(aiReferralEventsHourly.product).orderBy(desc31(sql29`SUM(${aiReferralEventsHourly.sessionsOrHits})`)).all();
|
|
38876
38880
|
const referralProducts = referralProductsRows.map((r) => ({
|
|
@@ -38887,7 +38891,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38887
38891
|
eq74(aiReferralEventsHourly.projectId, projectId),
|
|
38888
38892
|
countableReferralCondition(),
|
|
38889
38893
|
gte17(aiReferralEventsHourly.tsHour, headlineStart),
|
|
38890
|
-
|
|
38894
|
+
lte13(aiReferralEventsHourly.tsHour, headlineEnd)
|
|
38891
38895
|
)
|
|
38892
38896
|
).groupBy(aiReferralEventsHourly.landingPathNormalized).orderBy(desc31(sql29`SUM(${aiReferralEventsHourly.sessionsOrHits})`)).limit(SERVER_ACTIVITY_TOP_PATHS_LIMIT).all();
|
|
38893
38897
|
const topReferralLandingPaths = topReferralRows.map((r) => ({
|
|
@@ -38903,7 +38907,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38903
38907
|
and64(
|
|
38904
38908
|
eq74(crawlerEventsHourly.projectId, projectId),
|
|
38905
38909
|
gte17(crawlerEventsHourly.tsHour, trendStart),
|
|
38906
|
-
|
|
38910
|
+
lte13(crawlerEventsHourly.tsHour, headlineEnd)
|
|
38907
38911
|
)
|
|
38908
38912
|
).groupBy(sql29`SUBSTR(${crawlerEventsHourly.tsHour}, 1, 10)`).all();
|
|
38909
38913
|
const referralTrendRows = db.select({
|
|
@@ -38914,7 +38918,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38914
38918
|
eq74(aiReferralEventsHourly.projectId, projectId),
|
|
38915
38919
|
countableReferralCondition(),
|
|
38916
38920
|
gte17(aiReferralEventsHourly.tsHour, trendStart),
|
|
38917
|
-
|
|
38921
|
+
lte13(aiReferralEventsHourly.tsHour, headlineEnd)
|
|
38918
38922
|
)
|
|
38919
38923
|
).groupBy(sql29`SUBSTR(${aiReferralEventsHourly.tsHour}, 1, 10)`).all();
|
|
38920
38924
|
const userFetchTrendRows = db.select({
|
|
@@ -38924,7 +38928,7 @@ function readTrafficActivity(db, projectId, windowDays2) {
|
|
|
38924
38928
|
and64(
|
|
38925
38929
|
eq74(aiUserFetchEventsHourly.projectId, projectId),
|
|
38926
38930
|
gte17(aiUserFetchEventsHourly.tsHour, trendStart),
|
|
38927
|
-
|
|
38931
|
+
lte13(aiUserFetchEventsHourly.tsHour, headlineEnd)
|
|
38928
38932
|
)
|
|
38929
38933
|
).groupBy(sql29`SUBSTR(${aiUserFetchEventsHourly.tsHour}, 1, 10)`).all();
|
|
38930
38934
|
const emptyTrendEntry = () => ({ verifiedCrawlerHits: 0, unverifiedCrawlerHits: 0, userFetchHits: 0, referralArrivals: 0 });
|
|
@@ -39010,7 +39014,7 @@ async function trafficAnalyticsRoutes(app) {
|
|
|
39010
39014
|
}
|
|
39011
39015
|
|
|
39012
39016
|
// ../api-routes/src/traffic-samples.ts
|
|
39013
|
-
import { and as and65, count as count8, desc as desc32, eq as eq75, gte as gte18, inArray as inArray39, lte as
|
|
39017
|
+
import { and as and65, count as count8, desc as desc32, eq as eq75, gte as gte18, inArray as inArray39, lte as lte14, sql as sql30 } from "drizzle-orm";
|
|
39014
39018
|
var storedKind = {
|
|
39015
39019
|
[TrafficSampleKinds.crawler]: RawEventSampleEventTypes.crawler,
|
|
39016
39020
|
[TrafficSampleKinds["ai-user-fetch"]]: RawEventSampleEventTypes.aiUserFetch,
|
|
@@ -39032,7 +39036,7 @@ async function trafficSamplesRoutes(app) {
|
|
|
39032
39036
|
if (windowStart > windowEnd) throw validationError("since must not be after until", { reason: "invalid-window" });
|
|
39033
39037
|
const limit = query2.limit ?? 100;
|
|
39034
39038
|
const offset = query2.offset ?? 0;
|
|
39035
|
-
const filters = [eq75(rawEventSamples.projectId, project.id), gte18(rawEventSamples.ts, windowStart),
|
|
39039
|
+
const filters = [eq75(rawEventSamples.projectId, project.id), gte18(rawEventSamples.ts, windowStart), lte14(rawEventSamples.ts, windowEnd)];
|
|
39036
39040
|
filters.push(query2.kind && query2.kind !== "all" ? eq75(rawEventSamples.eventType, storedKind[query2.kind]) : inArray39(rawEventSamples.eventType, [storedKind[TrafficSampleKinds.crawler], storedKind[TrafficSampleKinds["ai-user-fetch"]], storedKind[TrafficSampleKinds["ai-referral"]]]));
|
|
39037
39041
|
if (query2.sourceId) filters.push(eq75(rawEventSamples.sourceId, query2.sourceId));
|
|
39038
39042
|
if (query2.path !== void 0) filters.push(sql30`${rawEventSamples.pathNormalized} LIKE ${escapeLikePattern(query2.path) + "%"} ESCAPE '\\'`);
|
|
@@ -39055,7 +39059,7 @@ async function trafficSamplesRoutes(app) {
|
|
|
39055
39059
|
}
|
|
39056
39060
|
|
|
39057
39061
|
// ../api-routes/src/traffic-unrecognized-agents.ts
|
|
39058
|
-
import { and as and66, eq as eq76, gte as gte19, lte as
|
|
39062
|
+
import { and as and66, eq as eq76, gte as gte19, lte as lte15 } from "drizzle-orm";
|
|
39059
39063
|
var DEFAULT_WINDOW_MS = 30 * 864e5;
|
|
39060
39064
|
var DEFAULT_LIMIT4 = 100;
|
|
39061
39065
|
function hourFloor(iso2) {
|
|
@@ -39077,7 +39081,7 @@ async function trafficUnrecognizedAgentsRoutes(app) {
|
|
|
39077
39081
|
if (windowStart > windowEnd) throw validationError("since must not be after until", { reason: "invalid-window" });
|
|
39078
39082
|
const scope = [eq76(unrecognizedAgentEventsHourly.projectId, project.id)];
|
|
39079
39083
|
if (query2.sourceId) scope.push(eq76(unrecognizedAgentEventsHourly.sourceId, query2.sourceId));
|
|
39080
|
-
const rows = app.db.select().from(unrecognizedAgentEventsHourly).where(and66(...scope, gte19(unrecognizedAgentEventsHourly.tsHour, hourFloor(windowStart)),
|
|
39084
|
+
const rows = app.db.select().from(unrecognizedAgentEventsHourly).where(and66(...scope, gte19(unrecognizedAgentEventsHourly.tsHour, hourFloor(windowStart)), lte15(unrecognizedAgentEventsHourly.tsHour, windowEnd))).all();
|
|
39081
39085
|
const byName = /* @__PURE__ */ new Map();
|
|
39082
39086
|
for (const row of rows) {
|
|
39083
39087
|
const agent = byName.get(row.agentName);
|
|
@@ -39120,7 +39124,7 @@ async function trafficUnrecognizedAgentsRoutes(app) {
|
|
|
39120
39124
|
}
|
|
39121
39125
|
|
|
39122
39126
|
// ../api-routes/src/agent-journeys.ts
|
|
39123
|
-
import { and as and67, asc as asc16, eq as eq77, gte as gte20, lte as
|
|
39127
|
+
import { and as and67, asc as asc16, eq as eq77, gte as gte20, lte as lte16, sql as sql31 } from "drizzle-orm";
|
|
39124
39128
|
var DAY_MS5 = 864e5;
|
|
39125
39129
|
var BROWSER_AGENT_NAMES = new Intl.ListFormat("en", { style: "long", type: "conjunction" }).format(DEFAULT_AI_CRAWLER_RULES.filter((rule) => rule.browser).map((rule) => rule.product));
|
|
39126
39130
|
var BROWSER_AGENT_LIMITATION = `Browser agent journeys (${BROWSER_AGENT_NAMES}) keep page loads, form posts and failed requests (HTTP 400-599). They leave out the files and data or API calls their pages made, ?_rsc= prefetches and client-side navigations, beacons, and HEAD and OPTIONS requests.`;
|
|
@@ -39226,17 +39230,17 @@ function readSequences(db, name, query2, recordingEnabled) {
|
|
|
39226
39230
|
const targets = active ? active.plan.schemaVersion === 2 ? active.plan.targets.map((target) => ({ stableKey: target.stableKey, label: target.label, urls: target.urlMatchers })) : active.plan.targets.map((target) => ({ stableKey: target.stableKey, label: target.label, urls: target.urls })) : [];
|
|
39227
39231
|
if (query2.targetKey && !targets.some((target) => target.stableKey === query2.targetKey)) throw validationError("Select a Property from the current measurement plan.", { reason: "unknown-target" });
|
|
39228
39232
|
const retentionCutoff = new Date(Date.now() - AGENT_JOURNEY_RETENTION_DAYS * DAY_MS5).toISOString();
|
|
39229
|
-
const filters = [eq77(agentJourneyEvents.projectId, project.id), gte20(agentJourneyEvents.ts, windowStart), gte20(agentJourneyEvents.ts, retentionCutoff),
|
|
39233
|
+
const filters = [eq77(agentJourneyEvents.projectId, project.id), gte20(agentJourneyEvents.ts, windowStart), gte20(agentJourneyEvents.ts, retentionCutoff), lte16(agentJourneyEvents.ts, windowEnd)];
|
|
39230
39234
|
if (query2.sourceId) filters.push(eq77(agentJourneyEvents.sourceId, query2.sourceId));
|
|
39231
39235
|
if (query2.agentId) filters.push(eq77(agentJourneyEvents.agentId, query2.agentId));
|
|
39232
39236
|
const rows = db.select().from(agentJourneyEvents).where(and67(...filters)).orderBy(asc16(agentJourneyEvents.ts), asc16(agentJourneyEvents.id)).limit(AGENT_JOURNEY_READ_EVENT_LIMIT + 1).all();
|
|
39233
39237
|
if (rows.length > AGENT_JOURNEY_READ_EVENT_LIMIT) throw validationError("This selection exceeds 20,000 requests. Narrow the time window, source, or agent.", { reason: "agent-journey-read-limit", limit: AGENT_JOURNEY_READ_EVENT_LIMIT });
|
|
39234
|
-
const capFilters = [eq77(agentJourneyCaptureDays.projectId, project.id), eq77(agentJourneyCaptureDays.capped, true), gte20(agentJourneyCaptureDays.day, windowStart.slice(0, 10)),
|
|
39238
|
+
const capFilters = [eq77(agentJourneyCaptureDays.projectId, project.id), eq77(agentJourneyCaptureDays.capped, true), gte20(agentJourneyCaptureDays.day, windowStart.slice(0, 10)), lte16(agentJourneyCaptureDays.day, windowEnd.slice(0, 10))];
|
|
39235
39239
|
if (query2.sourceId) capFilters.push(eq77(agentJourneyCaptureDays.sourceId, query2.sourceId));
|
|
39236
39240
|
const cappedSourceDays = db.select({ sourceId: agentJourneyCaptureDays.sourceId, day: agentJourneyCaptureDays.day }).from(agentJourneyCaptureDays).where(and67(...capFilters)).orderBy(asc16(agentJourneyCaptureDays.day), asc16(agentJourneyCaptureDays.sourceId)).all();
|
|
39237
39241
|
let likelyFakeRequests = null;
|
|
39238
39242
|
if (!query2.targetKey) {
|
|
39239
|
-
const fakeFilters = [eq77(aiUserFetchLikelyFakeHourly.projectId, project.id), gte20(aiUserFetchLikelyFakeHourly.tsHour, hourStart(windowStart)),
|
|
39243
|
+
const fakeFilters = [eq77(aiUserFetchLikelyFakeHourly.projectId, project.id), gte20(aiUserFetchLikelyFakeHourly.tsHour, hourStart(windowStart)), lte16(aiUserFetchLikelyFakeHourly.tsHour, windowEnd)];
|
|
39240
39244
|
if (query2.sourceId) fakeFilters.push(eq77(aiUserFetchLikelyFakeHourly.sourceId, query2.sourceId));
|
|
39241
39245
|
if (query2.agentId) fakeFilters.push(eq77(aiUserFetchLikelyFakeHourly.botId, query2.agentId));
|
|
39242
39246
|
likelyFakeRequests = Number(db.select({ total: sql31`COALESCE(SUM(${aiUserFetchLikelyFakeHourly.hits}), 0)` }).from(aiUserFetchLikelyFakeHourly).where(and67(...fakeFilters)).get()?.total ?? 0);
|
|
@@ -39321,7 +39325,7 @@ async function agentJourneyRoutes(app, opts) {
|
|
|
39321
39325
|
}
|
|
39322
39326
|
|
|
39323
39327
|
// ../api-routes/src/referral-assessment.ts
|
|
39324
|
-
import { and as and68, desc as desc33, eq as eq78, gte as gte21, lte as
|
|
39328
|
+
import { and as and68, desc as desc33, eq as eq78, gte as gte21, lte as lte17, ne as ne13, sql as sql32 } from "drizzle-orm";
|
|
39325
39329
|
|
|
39326
39330
|
// ../api-routes/src/ga-referral-groups.ts
|
|
39327
39331
|
var CHART_SERIES_LIMIT = 5;
|
|
@@ -39570,7 +39574,7 @@ function latestGaSyncQueriedWindow(db, projectId, startDate, endDate) {
|
|
|
39570
39574
|
const leftByAnotherSync = db.select({ id: gaAiReferrals.id }).from(gaAiReferrals).where(and68(
|
|
39571
39575
|
eq78(gaAiReferrals.projectId, projectId),
|
|
39572
39576
|
gte21(gaAiReferrals.date, summary3.start),
|
|
39573
|
-
|
|
39577
|
+
lte17(gaAiReferrals.date, summary3.end),
|
|
39574
39578
|
ne13(gaAiReferrals.syncedAt, summary3.syncedAt)
|
|
39575
39579
|
)).limit(1).get();
|
|
39576
39580
|
return leftByAnotherSync === void 0;
|
|
@@ -39588,7 +39592,7 @@ function buildReferralAssessment(db, projectName, input) {
|
|
|
39588
39592
|
const where = and68(
|
|
39589
39593
|
eq78(aiReferralEventsHourly.projectId, project.id),
|
|
39590
39594
|
gte21(aiReferralEventsHourly.tsHour, `${query2.startDate}T00:00:00.000Z`),
|
|
39591
|
-
|
|
39595
|
+
lte17(aiReferralEventsHourly.tsHour, `${query2.endDate}T23:59:59.999Z`),
|
|
39592
39596
|
query2.sourceId ? eq78(aiReferralEventsHourly.sourceId, query2.sourceId) : void 0
|
|
39593
39597
|
);
|
|
39594
39598
|
const burstThreshold = query2.burstThreshold ?? DEFAULT_BURST_THRESHOLD;
|
|
@@ -39641,7 +39645,7 @@ function buildReferralAssessment(db, projectName, input) {
|
|
|
39641
39645
|
sourceDimension: gaAiReferrals.sourceDimension,
|
|
39642
39646
|
channelGroup: gaAiReferrals.channelGroup,
|
|
39643
39647
|
sessions: sql32`sum(${gaAiReferrals.sessions})`
|
|
39644
|
-
}).from(gaAiReferrals).where(and68(eq78(gaAiReferrals.projectId, project.id), gte21(gaAiReferrals.date, query2.startDate),
|
|
39648
|
+
}).from(gaAiReferrals).where(and68(eq78(gaAiReferrals.projectId, project.id), gte21(gaAiReferrals.date, query2.startDate), lte17(gaAiReferrals.date, query2.endDate))).groupBy(gaAiReferrals.date, gaAiReferrals.source, gaAiReferrals.medium, gaAiReferrals.trafficClass, gaAiReferrals.sourceDimension, gaAiReferrals.channelGroup).all();
|
|
39645
39649
|
const gaSessions = gaRows.length ? resolveWinningDimensions(gaRows).reduce((sum, row) => sum + row.paidSessions + row.organicSessions, 0) : latestGaSyncQueriedWindow(db, project.id, query2.startDate, query2.endDate) ? 0 : null;
|
|
39646
39650
|
const observedRatio = observedRows > 0 && gaSessions !== null && gaSessions > 0 ? Math.round(countable.total / gaSessions * 100) / 100 : null;
|
|
39647
39651
|
const reasons = ["server-coverage-unproven", "ga-coverage-unproven", "ga-time-zone-unknown", "server-and-ga-units-differ"];
|
|
@@ -39683,7 +39687,7 @@ async function referralAssessmentRoutes(app) {
|
|
|
39683
39687
|
}
|
|
39684
39688
|
|
|
39685
39689
|
// ../api-routes/src/organic-evidence.ts
|
|
39686
|
-
import { and as and70, desc as desc34, eq as eq80, gte as gte23, lte as
|
|
39690
|
+
import { and as and70, desc as desc34, eq as eq80, gte as gte23, lte as lte19, or as or15, sql as sql35 } from "drizzle-orm";
|
|
39687
39691
|
|
|
39688
39692
|
// ../api-routes/src/path-prefix-condition.ts
|
|
39689
39693
|
import { or as or13, sql as sql33 } from "drizzle-orm";
|
|
@@ -39692,7 +39696,7 @@ function literalPathPrefixCondition(path8, prefix) {
|
|
|
39692
39696
|
}
|
|
39693
39697
|
|
|
39694
39698
|
// ../api-routes/src/ga-measurement-analysis.ts
|
|
39695
|
-
import { and as and69, eq as eq79, gte as gte22, inArray as inArray40, lte as
|
|
39699
|
+
import { and as and69, eq as eq79, gte as gte22, inArray as inArray40, lte as lte18, or as or14, sql as sql34 } from "drizzle-orm";
|
|
39696
39700
|
|
|
39697
39701
|
// ../api-routes/src/ga-lead-rate.ts
|
|
39698
39702
|
function resolveLeadEvents(measurement, state) {
|
|
@@ -40028,15 +40032,15 @@ function buildGaMeasurementAnalysis(db, projectName, options = {}) {
|
|
|
40028
40032
|
const gaAnchor = [acquisitionAnchor, leadAnchor].filter((date) => date !== null).sort().at(-1) ?? null;
|
|
40029
40033
|
const gaPeriods = gaAnchor ? buildPeriods(gaAnchor, days) : [];
|
|
40030
40034
|
const gaStartDate = gaPeriods[0]?.startDate;
|
|
40031
|
-
const acquisitionRows = gaStartDate ? db.select().from(gaAcquisitionDaily).where(and69(eq79(gaAcquisitionDaily.projectId, project.id), gte22(gaAcquisitionDaily.date, gaStartDate),
|
|
40032
|
-
const leadRows = gaStartDate && leadEventCondition !== null ? db.select().from(gaLeadEventsDaily).where(and69(eq79(gaLeadEventsDaily.projectId, project.id), leadEventCondition, gte22(gaLeadEventsDaily.date, gaStartDate),
|
|
40035
|
+
const acquisitionRows = gaStartDate ? db.select().from(gaAcquisitionDaily).where(and69(eq79(gaAcquisitionDaily.projectId, project.id), gte22(gaAcquisitionDaily.date, gaStartDate), lte18(gaAcquisitionDaily.date, gaAnchor))).all() : [];
|
|
40036
|
+
const leadRows = gaStartDate && leadEventCondition !== null ? db.select().from(gaLeadEventsDaily).where(and69(eq79(gaLeadEventsDaily.projectId, project.id), leadEventCondition, gte22(gaLeadEventsDaily.date, gaStartDate), lte18(gaLeadEventsDaily.date, gaAnchor))).all() : [];
|
|
40033
40037
|
const engagementAnchor = db.select({ date: sql34`max(${gaDailyTotals.date})` }).from(gaDailyTotals).where(eq79(gaDailyTotals.projectId, project.id)).get()?.date ?? null;
|
|
40034
40038
|
const engagementPeriodWindow = engagementAnchor ? buildPeriods(engagementAnchor, days) : [];
|
|
40035
40039
|
const engagementStartDate = engagementPeriodWindow[0]?.startDate;
|
|
40036
40040
|
const engagementRows = engagementStartDate ? db.select().from(gaDailyTotals).where(and69(
|
|
40037
40041
|
eq79(gaDailyTotals.projectId, project.id),
|
|
40038
40042
|
gte22(gaDailyTotals.date, engagementStartDate),
|
|
40039
|
-
|
|
40043
|
+
lte18(gaDailyTotals.date, engagementAnchor)
|
|
40040
40044
|
)).all() : [];
|
|
40041
40045
|
const engagementAvailableFrom = db.select({
|
|
40042
40046
|
date: sql34`min(${gaDailyTotals.date})`
|
|
@@ -40050,9 +40054,9 @@ function buildGaMeasurementAnalysis(db, projectName, options = {}) {
|
|
|
40050
40054
|
const gscAnchor = db.select({ date: sql34`max(${gscDailyTotals.date})` }).from(gscDailyTotals).where(eq79(gscDailyTotals.projectId, project.id)).get()?.date ?? null;
|
|
40051
40055
|
const gscPeriods = gscAnchor ? buildPeriods(gscAnchor, days) : [];
|
|
40052
40056
|
const gscStartDate = gscPeriods[0]?.startDate;
|
|
40053
|
-
const propertyRows = gscStartDate ? db.select().from(gscDailyTotals).where(and69(eq79(gscDailyTotals.projectId, project.id), gte22(gscDailyTotals.date, gscStartDate),
|
|
40054
|
-
const queryRows2 = gscStartDate ? db.select().from(gscQueryDailyTotals).where(and69(eq79(gscQueryDailyTotals.projectId, project.id), gte22(gscQueryDailyTotals.date, gscStartDate),
|
|
40055
|
-
const rawPageRows = gscStartDate ? db.select().from(gscSearchData).where(and69(eq79(gscSearchData.projectId, project.id), gte22(gscSearchData.date, gscStartDate),
|
|
40057
|
+
const propertyRows = gscStartDate ? db.select().from(gscDailyTotals).where(and69(eq79(gscDailyTotals.projectId, project.id), gte22(gscDailyTotals.date, gscStartDate), lte18(gscDailyTotals.date, gscAnchor))).all() : [];
|
|
40058
|
+
const queryRows2 = gscStartDate ? db.select().from(gscQueryDailyTotals).where(and69(eq79(gscQueryDailyTotals.projectId, project.id), gte22(gscQueryDailyTotals.date, gscStartDate), lte18(gscQueryDailyTotals.date, gscAnchor))).all() : [];
|
|
40059
|
+
const rawPageRows = gscStartDate ? db.select().from(gscSearchData).where(and69(eq79(gscSearchData.projectId, project.id), gte22(gscSearchData.date, gscStartDate), lte18(gscSearchData.date, gscAnchor))).all() : [];
|
|
40056
40060
|
const acquisition = acquisitionRows.filter((row) => {
|
|
40057
40061
|
const landingPage = normalizeLandingPage(row.landingPageNormalized ?? row.landingPage);
|
|
40058
40062
|
return hostIsIncluded(row.hostName) && pageIsIncluded(landingPage);
|
|
@@ -40461,17 +40465,17 @@ function buildOrganicEvidence(db, projectName, periodDays) {
|
|
|
40461
40465
|
const gscRows = gscStartDate && gscEndDate ? db.select().from(gscDailyTotals).where(and70(
|
|
40462
40466
|
eq80(gscDailyTotals.projectId, project.id),
|
|
40463
40467
|
gte23(gscDailyTotals.date, gscStartDate),
|
|
40464
|
-
|
|
40468
|
+
lte19(gscDailyTotals.date, gscEndDate)
|
|
40465
40469
|
)).all() : [];
|
|
40466
40470
|
const gaRows = gaStartDate && gaEndDate ? db.select().from(gaTrafficSnapshots).where(and70(
|
|
40467
40471
|
eq80(gaTrafficSnapshots.projectId, project.id),
|
|
40468
40472
|
gte23(gaTrafficSnapshots.date, gaStartDate),
|
|
40469
|
-
|
|
40473
|
+
lte19(gaTrafficSnapshots.date, gaEndDate)
|
|
40470
40474
|
)).all() : [];
|
|
40471
40475
|
const nativeAcquisitionRows = nativeAcquisitionActive && nativeStartDate && nativeEndDate ? db.select().from(gaAcquisitionDaily).where(and70(
|
|
40472
40476
|
eq80(gaAcquisitionDaily.projectId, project.id),
|
|
40473
40477
|
gte23(gaAcquisitionDaily.date, nativeStartDate),
|
|
40474
|
-
|
|
40478
|
+
lte19(gaAcquisitionDaily.date, nativeEndDate)
|
|
40475
40479
|
)).all().filter((row) => matchesMarketingHost(row.hostName, marketingHosts)) : [];
|
|
40476
40480
|
const nativeOrganicRows = nativeAcquisitionRows.filter((row) => row.channelGroup === "Organic Search");
|
|
40477
40481
|
const nativeWindowOrganicRows = nativeOrganicRows;
|
|
@@ -40510,7 +40514,7 @@ function buildOrganicEvidence(db, projectName, periodDays) {
|
|
|
40510
40514
|
const namedRows = db.select().from(gscQueryDailyTotals).where(and70(
|
|
40511
40515
|
eq80(gscQueryDailyTotals.projectId, project.id),
|
|
40512
40516
|
gte23(gscQueryDailyTotals.date, startDate),
|
|
40513
|
-
|
|
40517
|
+
lte19(gscQueryDailyTotals.date, endDate)
|
|
40514
40518
|
)).all();
|
|
40515
40519
|
for (const row of namedRows) {
|
|
40516
40520
|
const isBrand = categorizeQueryByIntent(row.query, brandTokens) === "brand";
|
|
@@ -40536,7 +40540,7 @@ function buildOrganicEvidence(db, projectName, periodDays) {
|
|
|
40536
40540
|
totals: sumSearchRows(gscRows.filter((row) => inRange(row.date, cohort.startDate, cohort.endDate)))
|
|
40537
40541
|
}))
|
|
40538
40542
|
} : null;
|
|
40539
|
-
const pageSearchRows = db.select().from(gscSearchData).where(and70(eq80(gscSearchData.projectId, project.id), gte23(gscSearchData.date, startDate),
|
|
40543
|
+
const pageSearchRows = db.select().from(gscSearchData).where(and70(eq80(gscSearchData.projectId, project.id), gte23(gscSearchData.date, startDate), lte19(gscSearchData.date, endDate))).all().filter((row) => pageMatchesMarketingHost(row.page, marketingHosts));
|
|
40540
40544
|
const gaWindow = gaStartDate && gaEndDate ? gaRows.filter((row) => inRange(row.date, gaStartDate, gaEndDate)) : [];
|
|
40541
40545
|
const legacyGaCohorts = gaCohorts.map((cohort) => ({
|
|
40542
40546
|
...cohort,
|
|
@@ -40563,7 +40567,7 @@ function buildOrganicEvidence(db, projectName, periodDays) {
|
|
|
40563
40567
|
}))
|
|
40564
40568
|
};
|
|
40565
40569
|
}
|
|
40566
|
-
const allGaAiRows = db.select().from(gaAiReferrals).where(and70(eq80(gaAiReferrals.projectId, project.id), gte23(gaAiReferrals.date, gaStartDate ?? startDate),
|
|
40570
|
+
const allGaAiRows = db.select().from(gaAiReferrals).where(and70(eq80(gaAiReferrals.projectId, project.id), gte23(gaAiReferrals.date, gaStartDate ?? startDate), lte19(gaAiReferrals.date, gaEndDate ?? endDate))).all().filter((row) => row.sourceDimension === "session");
|
|
40567
40571
|
const aiRows = gaStartDate && gaEndDate ? allGaAiRows.filter((row) => inRange(row.date, gaStartDate, gaEndDate)) : [];
|
|
40568
40572
|
const gaAiReferralSummary = allGaAiRows.length ? {
|
|
40569
40573
|
paidSessions: aiRows.filter((row) => row.trafficClass === AiReferralTrafficClasses.paid).reduce((count12, row) => count12 + row.sessions, 0),
|
|
@@ -40572,9 +40576,9 @@ function buildOrganicEvidence(db, projectName, periodDays) {
|
|
|
40572
40576
|
const serverSources = db.select().from(trafficSources).where(eq80(trafficSources.projectId, project.id)).all();
|
|
40573
40577
|
const serverStart = `${startDate}T00:00:00`;
|
|
40574
40578
|
const serverEnd = `${endDate}T23:59:59.999Z`;
|
|
40575
|
-
const allCrawlers = db.select().from(crawlerEventsHourly).where(and70(eq80(crawlerEventsHourly.projectId, project.id), gte23(crawlerEventsHourly.tsHour, serverStart),
|
|
40576
|
-
const allFetches = db.select().from(aiUserFetchEventsHourly).where(and70(eq80(aiUserFetchEventsHourly.projectId, project.id), gte23(aiUserFetchEventsHourly.tsHour, serverStart),
|
|
40577
|
-
const allReferrals = db.select().from(aiReferralEventsHourly).where(and70(eq80(aiReferralEventsHourly.projectId, project.id), countableReferralCondition(), gte23(aiReferralEventsHourly.tsHour, serverStart),
|
|
40579
|
+
const allCrawlers = db.select().from(crawlerEventsHourly).where(and70(eq80(crawlerEventsHourly.projectId, project.id), gte23(crawlerEventsHourly.tsHour, serverStart), lte19(crawlerEventsHourly.tsHour, serverEnd))).all();
|
|
40580
|
+
const allFetches = db.select().from(aiUserFetchEventsHourly).where(and70(eq80(aiUserFetchEventsHourly.projectId, project.id), gte23(aiUserFetchEventsHourly.tsHour, serverStart), lte19(aiUserFetchEventsHourly.tsHour, serverEnd))).all();
|
|
40581
|
+
const allReferrals = db.select().from(aiReferralEventsHourly).where(and70(eq80(aiReferralEventsHourly.projectId, project.id), countableReferralCondition(), gte23(aiReferralEventsHourly.tsHour, serverStart), lte19(aiReferralEventsHourly.tsHour, serverEnd))).all();
|
|
40578
40582
|
const [serverCoverageRow] = db.all(sql35`
|
|
40579
40583
|
select
|
|
40580
40584
|
min(day) as startDate,
|
|
@@ -42012,7 +42016,7 @@ function readVisibilityContinuity(db, projectName, months) {
|
|
|
42012
42016
|
}
|
|
42013
42017
|
|
|
42014
42018
|
// ../api-routes/src/results-export.ts
|
|
42015
|
-
import { and as and74, asc as asc17, eq as eq84, gte as gte24, lte as
|
|
42019
|
+
import { and as and74, asc as asc17, eq as eq84, gte as gte24, lte as lte20 } from "drizzle-orm";
|
|
42016
42020
|
var CSV_COLUMNS = [
|
|
42017
42021
|
"export_schema_version",
|
|
42018
42022
|
"project_id",
|
|
@@ -42156,7 +42160,7 @@ async function resultsExportRoutes(app) {
|
|
|
42156
42160
|
eq84(runs.kind, RunKinds["answer-visibility"]),
|
|
42157
42161
|
...includeProbes ? [] : [notProbeRun()],
|
|
42158
42162
|
...sinceIso ? [gte24(runs.createdAt, sinceIso)] : [],
|
|
42159
|
-
...untilIso ? [
|
|
42163
|
+
...untilIso ? [lte20(runs.createdAt, untilIso)] : []
|
|
42160
42164
|
];
|
|
42161
42165
|
const rows = app.db.select({
|
|
42162
42166
|
runId: runs.id,
|
|
@@ -43345,7 +43349,7 @@ import crypto37 from "crypto";
|
|
|
43345
43349
|
import { and as and78, desc as desc40, eq as eq89 } from "drizzle-orm";
|
|
43346
43350
|
|
|
43347
43351
|
// ../api-routes/src/content-data.ts
|
|
43348
|
-
import { and as and77, eq as eq88, desc as desc39, gte as gte25, inArray as inArray46, lte as
|
|
43352
|
+
import { and as and77, eq as eq88, desc as desc39, gte as gte25, inArray as inArray46, lte as lte21 } from "drizzle-orm";
|
|
43349
43353
|
var RECENT_RUNS_WINDOW = 5;
|
|
43350
43354
|
function loadOrchestratorInput(db, project, locationFilter = void 0, gscWindowDays = DEFAULT_CONTENT_GSC_WINDOW_DAYS) {
|
|
43351
43355
|
const projectId = project.id;
|
|
@@ -43514,7 +43518,7 @@ function buildGaTrafficByPage(db, projectId, window2) {
|
|
|
43514
43518
|
}).from(gaTrafficSnapshots).where(and77(
|
|
43515
43519
|
eq88(gaTrafficSnapshots.projectId, projectId),
|
|
43516
43520
|
gte25(gaTrafficSnapshots.date, window2.startDate),
|
|
43517
|
-
|
|
43521
|
+
lte21(gaTrafficSnapshots.date, window2.endDate)
|
|
43518
43522
|
)).all();
|
|
43519
43523
|
const map = /* @__PURE__ */ new Map();
|
|
43520
43524
|
for (const row of rows) {
|
|
@@ -43541,7 +43545,7 @@ function sumAiReferralSessions(db, projectId, window2) {
|
|
|
43541
43545
|
// opportunity score, so a lifetime total quietly weights the ranking
|
|
43542
43546
|
// toward whatever was true months ago.
|
|
43543
43547
|
gte25(gaAiReferrals.date, window2.startDate),
|
|
43544
|
-
|
|
43548
|
+
lte21(gaAiReferrals.date, window2.endDate)
|
|
43545
43549
|
)
|
|
43546
43550
|
).all();
|
|
43547
43551
|
return rows.reduce((acc, r) => acc + (r.sessions ?? 0), 0);
|
|
@@ -43564,7 +43568,7 @@ function buildCandidateQueries(opts) {
|
|
|
43564
43568
|
const pageRows = gscWindow ? opts.db.select().from(gscSearchData).where(and77(
|
|
43565
43569
|
eq88(gscSearchData.projectId, opts.projectId),
|
|
43566
43570
|
gte25(gscSearchData.date, gscWindow.startDate),
|
|
43567
|
-
|
|
43571
|
+
lte21(gscSearchData.date, gscWindow.endDate)
|
|
43568
43572
|
)).all() : [];
|
|
43569
43573
|
const gscByQuery = aggregateGscByQuery(
|
|
43570
43574
|
pageRows,
|
|
@@ -44976,6 +44980,12 @@ var projectRunsSinceQueryParameter = {
|
|
|
44976
44980
|
description: "Only return runs created at or after this ISO 8601 timestamp. Omitted means no lower bound.",
|
|
44977
44981
|
schema: stringSchema
|
|
44978
44982
|
};
|
|
44983
|
+
var projectRunsUntilQueryParameter = {
|
|
44984
|
+
name: "until",
|
|
44985
|
+
in: "query",
|
|
44986
|
+
description: "Only return runs created at or before this ISO 8601 timestamp, applied before the limit. Omitted means no upper bound.",
|
|
44987
|
+
schema: stringSchema
|
|
44988
|
+
};
|
|
44979
44989
|
var runsListIncludeProbeQueryParameter = {
|
|
44980
44990
|
name: "includeProbe",
|
|
44981
44991
|
in: "query",
|
|
@@ -47410,7 +47420,7 @@ var routeCatalog = [
|
|
|
47410
47420
|
path: "/api/v1/projects/{name}/runs",
|
|
47411
47421
|
summary: "List project runs",
|
|
47412
47422
|
tags: ["runs"],
|
|
47413
|
-
parameters: [nameParameter, limitQueryParameter, runsListKindQueryParameter, runsListExcludeKindQueryParameter, runsListExcludeKindsQueryParameter, runsListStatusQueryParameter, projectRunsSinceQueryParameter],
|
|
47423
|
+
parameters: [nameParameter, limitQueryParameter, runsListKindQueryParameter, runsListExcludeKindQueryParameter, runsListExcludeKindsQueryParameter, runsListStatusQueryParameter, projectRunsSinceQueryParameter, projectRunsUntilQueryParameter],
|
|
47414
47424
|
responses: {
|
|
47415
47425
|
200: jsonArrayResponse("Runs returned.", "RunDto")
|
|
47416
47426
|
}
|
|
@@ -54010,7 +54020,7 @@ async function userInvitationRoutes(app) {
|
|
|
54010
54020
|
|
|
54011
54021
|
// ../api-routes/src/chatgpt-accounts.ts
|
|
54012
54022
|
import crypto42 from "crypto";
|
|
54013
|
-
import { and as and80, eq as eq93, isNull as isNull16, lte as
|
|
54023
|
+
import { and as and80, eq as eq93, isNull as isNull16, lte as lte22 } from "drizzle-orm";
|
|
54014
54024
|
|
|
54015
54025
|
// ../api-routes/src/chatgpt-oidc.ts
|
|
54016
54026
|
import crypto41 from "crypto";
|
|
@@ -54461,7 +54471,7 @@ var ChatGptAccounts = class {
|
|
|
54461
54471
|
const scopes = this.requestedScopes();
|
|
54462
54472
|
const nowMs = this.now();
|
|
54463
54473
|
const nowIso = new Date(nowMs).toISOString();
|
|
54464
|
-
this.opts.db.delete(chatgptLoginTransactions).where(
|
|
54474
|
+
this.opts.db.delete(chatgptLoginTransactions).where(lte22(chatgptLoginTransactions.expiresAt, nowIso)).run();
|
|
54465
54475
|
this.opts.db.insert(chatgptLoginTransactions).values({
|
|
54466
54476
|
stateHash: sha2563(state),
|
|
54467
54477
|
browserHash: sha2563(binding),
|
|
@@ -58749,7 +58759,7 @@ async function googleRoutes(app, opts) {
|
|
|
58749
58759
|
const project = resolveProject(app.db, request.params.name);
|
|
58750
58760
|
const conn = store.getConnection(project.canonicalDomain, "gsc");
|
|
58751
58761
|
if (!conn) {
|
|
58752
|
-
throw
|
|
58762
|
+
throw integrationNotConnected('No GSC connection found for this domain. Run "canonry google connect" first.');
|
|
58753
58763
|
}
|
|
58754
58764
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
58755
58765
|
const runId = crypto47.randomUUID();
|
|
@@ -59773,7 +59783,7 @@ async function googleRoutes(app, opts) {
|
|
|
59773
59783
|
const store = requireConnectionStore();
|
|
59774
59784
|
const conn = store.getConnection(project.canonicalDomain, "gbp");
|
|
59775
59785
|
if (!conn) {
|
|
59776
|
-
throw
|
|
59786
|
+
throw integrationNotConnected('No GBP connection found for this project. Run "canonry gbp connect" first.');
|
|
59777
59787
|
}
|
|
59778
59788
|
const { accessToken } = await getValidToken(
|
|
59779
59789
|
store,
|
|
@@ -59862,7 +59872,7 @@ async function googleRoutes(app, opts) {
|
|
|
59862
59872
|
const store = requireConnectionStore();
|
|
59863
59873
|
const conn = store.getConnection(project.canonicalDomain, "gbp");
|
|
59864
59874
|
if (!conn) {
|
|
59865
|
-
throw
|
|
59875
|
+
throw integrationNotConnected('No GBP connection found for this project. Run "canonry gbp connect" first.');
|
|
59866
59876
|
}
|
|
59867
59877
|
const parsed = gbpSyncRequestSchema.safeParse(request.body ?? {});
|
|
59868
59878
|
if (!parsed.success) {
|
|
@@ -60302,10 +60312,15 @@ function normalizeConversionTrackingContractWrite(input) {
|
|
|
60302
60312
|
}
|
|
60303
60313
|
};
|
|
60304
60314
|
}
|
|
60305
|
-
function requiredCredential(opts, project, provider) {
|
|
60306
|
-
const credential = opts.
|
|
60315
|
+
function requiredCredential(app, opts, project, provider) {
|
|
60316
|
+
const credential = requireCredentialStore(opts).get(project, provider);
|
|
60307
60317
|
if (!credential?.accessToken) {
|
|
60308
|
-
|
|
60318
|
+
const label = provider === GoogleMarketingProviders["google-ads"] ? "Google Ads" : "Google Tag Manager";
|
|
60319
|
+
const connection = provider === GoogleMarketingProviders["google-ads"] ? app.db.select({ id: googleAdsConnections.id }).from(googleAdsConnections).where(eq100(googleAdsConnections.projectId, project.id)).get() : app.db.select({ id: gtmConnections.id }).from(gtmConnections).where(eq100(gtmConnections.projectId, project.id)).get();
|
|
60320
|
+
if (credential || connection) {
|
|
60321
|
+
throw validationError(`Saved ${label} OAuth credentials are unavailable. Reconnect before retrying.`);
|
|
60322
|
+
}
|
|
60323
|
+
throw integrationNotConnected(`No ${label} OAuth connection is available for this project.`);
|
|
60309
60324
|
}
|
|
60310
60325
|
return credential;
|
|
60311
60326
|
}
|
|
@@ -61187,7 +61202,7 @@ async function googleMarketingRoutes(app, opts) {
|
|
|
61187
61202
|
assertNotProjectScoped(request, "listing Google Ads customers");
|
|
61188
61203
|
const project = resolveProject(app.db, request.params.name);
|
|
61189
61204
|
const projectRef = asProjectRef(project);
|
|
61190
|
-
requiredCredential(opts, projectRef, GoogleMarketingProviders["google-ads"]);
|
|
61205
|
+
requiredCredential(app, opts, projectRef, GoogleMarketingProviders["google-ads"]);
|
|
61191
61206
|
const reader = requireLiveReader(opts);
|
|
61192
61207
|
let result;
|
|
61193
61208
|
try {
|
|
@@ -61202,7 +61217,7 @@ async function googleMarketingRoutes(app, opts) {
|
|
|
61202
61217
|
assertNotProjectScoped(request, "listing Google Tag Manager accounts");
|
|
61203
61218
|
const project = resolveProject(app.db, request.params.name);
|
|
61204
61219
|
const projectRef = asProjectRef(project);
|
|
61205
|
-
requiredCredential(opts, projectRef, GoogleMarketingProviders.gtm);
|
|
61220
|
+
requiredCredential(app, opts, projectRef, GoogleMarketingProviders.gtm);
|
|
61206
61221
|
const reader = requireLiveReader(opts);
|
|
61207
61222
|
try {
|
|
61208
61223
|
return gtmAccountsResponseSchema.parse(await reader.listGtmAccounts(projectRef));
|
|
@@ -61215,7 +61230,7 @@ async function googleMarketingRoutes(app, opts) {
|
|
|
61215
61230
|
assertNotProjectScoped(request, "listing Google Tag Manager containers");
|
|
61216
61231
|
const project = resolveProject(app.db, request.params.name);
|
|
61217
61232
|
const projectRef = asProjectRef(project);
|
|
61218
|
-
requiredCredential(opts, projectRef, GoogleMarketingProviders.gtm);
|
|
61233
|
+
requiredCredential(app, opts, projectRef, GoogleMarketingProviders.gtm);
|
|
61219
61234
|
const accountId = canonicalizeGtmAccountId(request.params.accountId);
|
|
61220
61235
|
if (!accountId) throw validationError("Invalid GTM account resource path.");
|
|
61221
61236
|
const reader = requireLiveReader(opts);
|
|
@@ -61230,7 +61245,7 @@ async function googleMarketingRoutes(app, opts) {
|
|
|
61230
61245
|
assertNotProjectScoped(request, "listing Google Tag Manager workspaces");
|
|
61231
61246
|
const project = resolveProject(app.db, request.params.name);
|
|
61232
61247
|
const projectRef = asProjectRef(project);
|
|
61233
|
-
requiredCredential(opts, projectRef, GoogleMarketingProviders.gtm);
|
|
61248
|
+
requiredCredential(app, opts, projectRef, GoogleMarketingProviders.gtm);
|
|
61234
61249
|
const selection = canonicalizeGtmResourceSelection({
|
|
61235
61250
|
accountId: request.params.accountId,
|
|
61236
61251
|
containerId: request.params.containerId
|
|
@@ -61276,9 +61291,9 @@ async function googleMarketingRoutes(app, opts) {
|
|
|
61276
61291
|
const project = resolveProject(app.db, request.params.name);
|
|
61277
61292
|
const projectRef = asProjectRef(project);
|
|
61278
61293
|
try {
|
|
61279
|
-
requiredCredential(opts, projectRef, GoogleMarketingProviders["google-ads"]);
|
|
61294
|
+
requiredCredential(app, opts, projectRef, GoogleMarketingProviders["google-ads"]);
|
|
61280
61295
|
} catch (err) {
|
|
61281
|
-
attempt.failed(err
|
|
61296
|
+
attempt.failed(err);
|
|
61282
61297
|
throw err;
|
|
61283
61298
|
}
|
|
61284
61299
|
const existing = app.db.select().from(googleAdsConnections).where(eq100(googleAdsConnections.projectId, project.id)).get();
|
|
@@ -61327,9 +61342,9 @@ async function googleMarketingRoutes(app, opts) {
|
|
|
61327
61342
|
const project = resolveProject(app.db, request.params.name);
|
|
61328
61343
|
const projectRef = asProjectRef(project);
|
|
61329
61344
|
try {
|
|
61330
|
-
requiredCredential(opts, projectRef, GoogleMarketingProviders.gtm);
|
|
61345
|
+
requiredCredential(app, opts, projectRef, GoogleMarketingProviders.gtm);
|
|
61331
61346
|
} catch (err) {
|
|
61332
|
-
attempt.failed(err
|
|
61347
|
+
attempt.failed(err);
|
|
61333
61348
|
throw err;
|
|
61334
61349
|
}
|
|
61335
61350
|
const existing = app.db.select().from(gtmConnections).where(eq100(gtmConnections.projectId, project.id)).get();
|
|
@@ -61378,9 +61393,9 @@ async function googleMarketingRoutes(app, opts) {
|
|
|
61378
61393
|
throw notImplemented("Google Ads sync is not configured for this deployment.");
|
|
61379
61394
|
}
|
|
61380
61395
|
const project = resolveProject(app.db, request.params.name);
|
|
61381
|
-
requiredCredential(opts, asProjectRef(project), GoogleMarketingProviders["google-ads"]);
|
|
61396
|
+
requiredCredential(app, opts, asProjectRef(project), GoogleMarketingProviders["google-ads"]);
|
|
61382
61397
|
const connection = app.db.select().from(googleAdsConnections).where(eq100(googleAdsConnections.projectId, project.id)).get();
|
|
61383
|
-
if (!connection) throw
|
|
61398
|
+
if (!connection) throw integrationNotConnected("Connect Google Ads before starting a sync.");
|
|
61384
61399
|
const candidateRun = queuedRun(project.id, RunKinds["google-ads-sync"], project.name, opts.claimScheduledSync);
|
|
61385
61400
|
let run = candidateRun;
|
|
61386
61401
|
let queued = false;
|
|
@@ -61414,9 +61429,9 @@ async function googleMarketingRoutes(app, opts) {
|
|
|
61414
61429
|
throw notImplemented("Google Tag Manager sync is not configured for this deployment.");
|
|
61415
61430
|
}
|
|
61416
61431
|
const project = resolveProject(app.db, request.params.name);
|
|
61417
|
-
requiredCredential(opts, asProjectRef(project), GoogleMarketingProviders.gtm);
|
|
61432
|
+
requiredCredential(app, opts, asProjectRef(project), GoogleMarketingProviders.gtm);
|
|
61418
61433
|
const connection = app.db.select().from(gtmConnections).where(eq100(gtmConnections.projectId, project.id)).get();
|
|
61419
|
-
if (!connection) throw
|
|
61434
|
+
if (!connection) throw integrationNotConnected("Connect Google Tag Manager before starting a sync.");
|
|
61420
61435
|
const candidateRun = queuedRun(project.id, RunKinds["gtm-sync"], project.name, opts.claimScheduledSync);
|
|
61421
61436
|
let run = candidateRun;
|
|
61422
61437
|
let queued = false;
|
|
@@ -61765,7 +61780,7 @@ async function googleMarketingRoutes(app, opts) {
|
|
|
61765
61780
|
|
|
61766
61781
|
// ../api-routes/src/ads.ts
|
|
61767
61782
|
import crypto51 from "crypto";
|
|
61768
|
-
import { eq as eq102, and as and87, asc as asc22, desc as desc45, gt as gt8, gte as gte26, lt as lt18, lte as
|
|
61783
|
+
import { eq as eq102, and as and87, asc as asc22, desc as desc45, gt as gt8, gte as gte26, lt as lt18, lte as lte24, ne as ne15, inArray as inArray49, or as or19, isNull as isNull19, isNotNull as isNotNull12, sql as sql41 } from "drizzle-orm";
|
|
61769
61784
|
|
|
61770
61785
|
// ../api-routes/src/ads-activation.ts
|
|
61771
61786
|
import crypto49 from "crypto";
|
|
@@ -63151,7 +63166,7 @@ async function executeApprovedAdsActivation(dependencies, request) {
|
|
|
63151
63166
|
|
|
63152
63167
|
// ../api-routes/src/ads-activation-routes.ts
|
|
63153
63168
|
import crypto50 from "crypto";
|
|
63154
|
-
import { and as and86, asc as asc21, eq as eq101, gt as gt7, isNotNull as isNotNull11, isNull as isNull18, lte as
|
|
63169
|
+
import { and as and86, asc as asc21, eq as eq101, gt as gt7, isNotNull as isNotNull11, isNull as isNull18, lte as lte23, or as or18, sql as sql40 } from "drizzle-orm";
|
|
63155
63170
|
var MAX_ACTIVATION_GRANT_LIFETIME_MS = 24 * 60 * 60 * 1e3;
|
|
63156
63171
|
var ACTIVATION_LEASE_MS = 5 * 6e4;
|
|
63157
63172
|
var ACTIVATION_REVOCATION_SETTLEMENT_MS = ACTIVATION_LEASE_MS;
|
|
@@ -63281,7 +63296,7 @@ function createActivationStore(app, request) {
|
|
|
63281
63296
|
isNull18(adsOperations.leaseOwner),
|
|
63282
63297
|
eq101(adsOperations.leaseOwner, input.leaseOwner),
|
|
63283
63298
|
isNull18(adsOperations.leaseExpiresAt),
|
|
63284
|
-
|
|
63299
|
+
lte23(adsOperations.leaseExpiresAt, input.now)
|
|
63285
63300
|
)
|
|
63286
63301
|
)).run();
|
|
63287
63302
|
const resumed = loadCanonicalActivation(tx, grant.id, existing.id);
|
|
@@ -63741,7 +63756,7 @@ function selectWatchdogOperations(app, nowIso, batchSize, allowLiveRevocationLea
|
|
|
63741
63756
|
const leaseAvailable = or18(
|
|
63742
63757
|
isNull18(adsOperations.leaseOwner),
|
|
63743
63758
|
isNull18(adsOperations.leaseExpiresAt),
|
|
63744
|
-
|
|
63759
|
+
lte23(adsOperations.leaseExpiresAt, nowIso)
|
|
63745
63760
|
);
|
|
63746
63761
|
const campaignHasMutationEvidence = or18(
|
|
63747
63762
|
eq101(adsOperationSteps.state, AdsOperationStepStates.executing),
|
|
@@ -63937,7 +63952,7 @@ async function sweepStaleAdsActivationsOnce(app, opts) {
|
|
|
63937
63952
|
or18(
|
|
63938
63953
|
isNull18(adsOperations.leaseOwner),
|
|
63939
63954
|
isNull18(adsOperations.leaseExpiresAt),
|
|
63940
|
-
|
|
63955
|
+
lte23(adsOperations.leaseExpiresAt, nowIso)
|
|
63941
63956
|
)
|
|
63942
63957
|
)
|
|
63943
63958
|
)
|
|
@@ -63974,7 +63989,7 @@ async function sweepStaleAdsActivationsOnce(app, opts) {
|
|
|
63974
63989
|
or18(
|
|
63975
63990
|
isNull18(adsOperations.leaseOwner),
|
|
63976
63991
|
isNull18(adsOperations.leaseExpiresAt),
|
|
63977
|
-
|
|
63992
|
+
lte23(adsOperations.leaseExpiresAt, failedAt)
|
|
63978
63993
|
)
|
|
63979
63994
|
)
|
|
63980
63995
|
)
|
|
@@ -64897,7 +64912,7 @@ function errorDetails(err) {
|
|
|
64897
64912
|
async function resolveAdsOperator(app, opts, project, verification) {
|
|
64898
64913
|
const connection = opts.adsCredentialStore?.getConnection(project.name);
|
|
64899
64914
|
if (!connection?.apiKey) {
|
|
64900
|
-
throw
|
|
64915
|
+
throw integrationNotConnected('No ads connection for this project. Run "canonry ads connect" first.');
|
|
64901
64916
|
}
|
|
64902
64917
|
if (!connection.adAccountId) {
|
|
64903
64918
|
throw validationError("Reconnect this project to bind its verified OpenAI ad account before mutating ads");
|
|
@@ -65184,13 +65199,13 @@ function claimOperationForReconciliation(app, row, leaseOwner, now, leaseMs, pol
|
|
|
65184
65199
|
const unknownCutoff = new Date(now.getTime() - backoffMs).toISOString();
|
|
65185
65200
|
const claimableState = row.state === AdsOperationStates.pending ? and87(
|
|
65186
65201
|
eq102(adsOperations.state, AdsOperationStates.pending),
|
|
65187
|
-
|
|
65202
|
+
lte24(adsOperations.updatedAt, pendingCutoff)
|
|
65188
65203
|
) : row.state === AdsOperationStates.unknown ? and87(
|
|
65189
65204
|
eq102(adsOperations.state, AdsOperationStates.unknown),
|
|
65190
|
-
enforceBackoff ?
|
|
65205
|
+
enforceBackoff ? lte24(adsOperations.updatedAt, unknownCutoff) : void 0
|
|
65191
65206
|
) : and87(
|
|
65192
65207
|
eq102(adsOperations.state, AdsOperationStates.reconciling),
|
|
65193
|
-
or19(isNull19(adsOperations.leaseExpiresAt),
|
|
65208
|
+
or19(isNull19(adsOperations.leaseExpiresAt), lte24(adsOperations.leaseExpiresAt, nowIso))
|
|
65194
65209
|
);
|
|
65195
65210
|
const claimed = app.db.update(adsOperations).set({
|
|
65196
65211
|
state: AdsOperationStates.reconciling,
|
|
@@ -65528,14 +65543,14 @@ async function sweepAdsOperationsOnce(app, opts, config) {
|
|
|
65528
65543
|
const backoffMs = config.policy.backoffBaseMs * 2 ** Math.max(0, reconcileAttempts - 1);
|
|
65529
65544
|
return and87(
|
|
65530
65545
|
eq102(adsOperations.reconcileAttempts, reconcileAttempts),
|
|
65531
|
-
|
|
65546
|
+
lte24(adsOperations.updatedAt, new Date(now.getTime() - backoffMs).toISOString())
|
|
65532
65547
|
);
|
|
65533
65548
|
}
|
|
65534
65549
|
);
|
|
65535
65550
|
const retryableStateWhere = or19(
|
|
65536
65551
|
and87(
|
|
65537
65552
|
eq102(adsOperations.state, AdsOperationStates.pending),
|
|
65538
|
-
|
|
65553
|
+
lte24(adsOperations.updatedAt, pendingCutoff)
|
|
65539
65554
|
),
|
|
65540
65555
|
and87(
|
|
65541
65556
|
eq102(adsOperations.state, AdsOperationStates.unknown),
|
|
@@ -65543,7 +65558,7 @@ async function sweepAdsOperationsOnce(app, opts, config) {
|
|
|
65543
65558
|
),
|
|
65544
65559
|
and87(
|
|
65545
65560
|
eq102(adsOperations.state, AdsOperationStates.reconciling),
|
|
65546
|
-
or19(isNull19(adsOperations.leaseExpiresAt),
|
|
65561
|
+
or19(isNull19(adsOperations.leaseExpiresAt), lte24(adsOperations.leaseExpiresAt, nowIso))
|
|
65547
65562
|
)
|
|
65548
65563
|
);
|
|
65549
65564
|
const staleReconcileWhere = and87(
|
|
@@ -65570,12 +65585,12 @@ async function sweepAdsOperationsOnce(app, opts, config) {
|
|
|
65570
65585
|
or19(
|
|
65571
65586
|
and87(
|
|
65572
65587
|
eq102(adsOperations.state, AdsOperationStates.pending),
|
|
65573
|
-
|
|
65588
|
+
lte24(adsOperations.updatedAt, pendingCutoff)
|
|
65574
65589
|
),
|
|
65575
65590
|
eq102(adsOperations.state, AdsOperationStates.unknown),
|
|
65576
65591
|
and87(
|
|
65577
65592
|
eq102(adsOperations.state, AdsOperationStates.reconciling),
|
|
65578
|
-
or19(isNull19(adsOperations.leaseExpiresAt),
|
|
65593
|
+
or19(isNull19(adsOperations.leaseExpiresAt), lte24(adsOperations.leaseExpiresAt, nowIso))
|
|
65579
65594
|
)
|
|
65580
65595
|
),
|
|
65581
65596
|
or19(
|
|
@@ -66361,7 +66376,7 @@ async function adsRoutes(app, opts) {
|
|
|
66361
66376
|
const project = resolveProject(app.db, request.params.name);
|
|
66362
66377
|
const row = app.db.select().from(adsConnections).where(eq102(adsConnections.projectId, project.id)).get();
|
|
66363
66378
|
if (!row) {
|
|
66364
|
-
throw
|
|
66379
|
+
throw integrationNotConnected('No ads connection for this project. Run "canonry ads connect" first.');
|
|
66365
66380
|
}
|
|
66366
66381
|
const inFlight2 = app.db.select({ id: runs.id, status: runs.status }).from(runs).where(and87(
|
|
66367
66382
|
eq102(runs.projectId, project.id),
|
|
@@ -66462,7 +66477,7 @@ async function adsRoutes(app, opts) {
|
|
|
66462
66477
|
if (parsedLevel) conditions.push(eq102(adsInsightsDaily.level, parsedLevel));
|
|
66463
66478
|
if (entityId) conditions.push(eq102(adsInsightsDaily.entityId, entityId));
|
|
66464
66479
|
if (from) conditions.push(gte26(adsInsightsDaily.date, from));
|
|
66465
|
-
if (to) conditions.push(
|
|
66480
|
+
if (to) conditions.push(lte24(adsInsightsDaily.date, to));
|
|
66466
66481
|
const rows = app.db.select().from(adsInsightsDaily).where(and87(...conditions)).orderBy(asc22(adsInsightsDaily.date)).all();
|
|
66467
66482
|
const conn = app.db.select().from(adsConnections).where(eq102(adsConnections.projectId, project.id)).get();
|
|
66468
66483
|
const accountToday = adsAccountToday(conn?.timezone, (/* @__PURE__ */ new Date()).toISOString());
|
|
@@ -66591,7 +66606,7 @@ async function adsRoutes(app, opts) {
|
|
|
66591
66606
|
const { campaignId, lookbackDays } = parsed.data;
|
|
66592
66607
|
const connection = app.db.select().from(adsConnections).where(eq102(adsConnections.projectId, project.id)).get();
|
|
66593
66608
|
if (!connection) {
|
|
66594
|
-
throw
|
|
66609
|
+
throw integrationNotConnected('No ads connection for this project. Run "canonry ads connect" first.');
|
|
66595
66610
|
}
|
|
66596
66611
|
const { apiKey, reader } = resolveAdsLiveDeliveryReader(opts, project.name);
|
|
66597
66612
|
const verifyAdsAccount = opts.verifyAdsAccount;
|
|
@@ -67452,7 +67467,7 @@ function isBlockingCrawlIssue(issueType) {
|
|
|
67452
67467
|
|
|
67453
67468
|
// ../api-routes/src/bing-data.ts
|
|
67454
67469
|
import crypto54 from "crypto";
|
|
67455
|
-
import { and as and88, asc as asc23, desc as desc46, eq as eq103, gte as gte27, lte as
|
|
67470
|
+
import { and as and88, asc as asc23, desc as desc46, eq as eq103, gte as gte27, lte as lte25, sql as sql42 } from "drizzle-orm";
|
|
67456
67471
|
var BING_DEFAULT_WINDOW_DAYS = 28;
|
|
67457
67472
|
var MAX_WINDOW_DAYS = 3660;
|
|
67458
67473
|
var DEFAULT_LIST_LIMIT = 100;
|
|
@@ -67620,7 +67635,7 @@ async function bingDataRoutes(app, opts) {
|
|
|
67620
67635
|
const fetchStart = priorWindowIsSynced ? priorStart : window2.startDate;
|
|
67621
67636
|
const conditions = [eq103(bingTrafficDaily.projectId, project.id)];
|
|
67622
67637
|
if (fetchStart) conditions.push(gte27(bingTrafficDaily.date, fetchStart));
|
|
67623
|
-
if (window2.endDate) conditions.push(
|
|
67638
|
+
if (window2.endDate) conditions.push(lte25(bingTrafficDaily.date, window2.endDate));
|
|
67624
67639
|
const fetched = latest === null && !request.query.startDate ? [] : app.db.select().from(bingTrafficDaily).where(and88(...conditions)).orderBy(asc23(bingTrafficDaily.date)).all();
|
|
67625
67640
|
const rows = window2.startDate ? fetched.filter((row) => row.date >= window2.startDate) : fetched;
|
|
67626
67641
|
const clicks = rows.reduce((sum, row) => sum + row.clicks, 0);
|
|
@@ -67664,7 +67679,7 @@ async function bingDataRoutes(app, opts) {
|
|
|
67664
67679
|
const between = (startDate, endDate) => {
|
|
67665
67680
|
const conditions = [...filters];
|
|
67666
67681
|
if (startDate) conditions.push(gte27(table.date, startDate));
|
|
67667
|
-
if (endDate) conditions.push(
|
|
67682
|
+
if (endDate) conditions.push(lte25(table.date, endDate));
|
|
67668
67683
|
return and88(...conditions);
|
|
67669
67684
|
};
|
|
67670
67685
|
const where = between(window2.startDate, window2.endDate);
|
|
@@ -67739,7 +67754,7 @@ async function bingDataRoutes(app, opts) {
|
|
|
67739
67754
|
const window2 = resolveBingWindow(request.query, latest);
|
|
67740
67755
|
const conditions = [eq103(bingCrawlStats.projectId, project.id)];
|
|
67741
67756
|
if (window2.startDate) conditions.push(gte27(bingCrawlStats.date, window2.startDate));
|
|
67742
|
-
if (window2.endDate) conditions.push(
|
|
67757
|
+
if (window2.endDate) conditions.push(lte25(bingCrawlStats.date, window2.endDate));
|
|
67743
67758
|
const rows = latest === null && !request.query.startDate ? [] : app.db.select().from(bingCrawlStats).where(and88(...conditions)).orderBy(desc46(bingCrawlStats.date)).all();
|
|
67744
67759
|
return {
|
|
67745
67760
|
rows: rows.map(({ id: _id, projectId: _projectId, syncRunId: _syncRunId, syncedAt: _syncedAt, ...day }) => day),
|
|
@@ -68001,7 +68016,7 @@ async function bingRoutes(app, opts) {
|
|
|
68001
68016
|
function requireConnection(store, domain) {
|
|
68002
68017
|
const conn = store.getConnection(domain);
|
|
68003
68018
|
if (!conn) {
|
|
68004
|
-
throw
|
|
68019
|
+
throw integrationNotConnected('No Bing connection found for this domain. Run "canonry bing connect <project>" first.');
|
|
68005
68020
|
}
|
|
68006
68021
|
return conn;
|
|
68007
68022
|
}
|
|
@@ -69379,7 +69394,7 @@ function keptGaWindows(windows, failures) {
|
|
|
69379
69394
|
|
|
69380
69395
|
// ../api-routes/src/ga-search-landing-pages.ts
|
|
69381
69396
|
import crypto56 from "crypto";
|
|
69382
|
-
import { and as and94, asc as asc25, count as count9, desc as desc49, eq as eq109, gte as gte28, lte as
|
|
69397
|
+
import { and as and94, asc as asc25, count as count9, desc as desc49, eq as eq109, gte as gte28, lte as lte26, sql as sql45 } from "drizzle-orm";
|
|
69383
69398
|
function searchLandingWindowsToFetch(db, projectId, propertyId, timeZone, requestedAt) {
|
|
69384
69399
|
const state = db.select().from(gaMeasurementSyncStates).where(eq109(gaMeasurementSyncStates.projectId, projectId)).get();
|
|
69385
69400
|
if (!timeZone || state?.searchLandingStatus !== "ready") return [...GA_SEARCH_LANDING_WINDOWS];
|
|
@@ -69561,7 +69576,7 @@ function searchConsoleLinkFor(db, projectId, total, windowStart, windowEnd) {
|
|
|
69561
69576
|
const stored = db.select({
|
|
69562
69577
|
days: count9(),
|
|
69563
69578
|
impressions: sql45`sum(${gscDailyTotals.impressions})`
|
|
69564
|
-
}).from(gscDailyTotals).where(and94(eq109(gscDailyTotals.projectId, projectId), gte28(gscDailyTotals.date, windowStart),
|
|
69579
|
+
}).from(gscDailyTotals).where(and94(eq109(gscDailyTotals.projectId, projectId), gte28(gscDailyTotals.date, windowStart), lte26(gscDailyTotals.date, windowEnd))).get();
|
|
69565
69580
|
const searchConsoleImpressions = stored && stored.days > 0 ? Number(stored.impressions ?? 0) : null;
|
|
69566
69581
|
if (gaSearchLandingHasSearchData(total)) return { state: "has-data", searchConsoleImpressions };
|
|
69567
69582
|
if (searchConsoleImpressions === null) return { state: "unknown", searchConsoleImpressions };
|
|
@@ -70157,6 +70172,17 @@ async function ga4Routes(app, opts) {
|
|
|
70157
70172
|
if (only !== void 0 && !gaSyncOnlySchema.safeParse(only).success) {
|
|
70158
70173
|
throw validationError(`Invalid "only" value "${only}". Must be one of: ${gaSyncOnlySchema.options.join(", ")}`);
|
|
70159
70174
|
}
|
|
70175
|
+
const outcome2 = startRouteOutcome(app, FeatureNames.ga4, "sync");
|
|
70176
|
+
const serviceAccount = opts.ga4CredentialStore?.getConnection(project.name);
|
|
70177
|
+
const oauth = opts.googleConnectionStore?.getConnection(project.canonicalDomain, "ga4");
|
|
70178
|
+
if (!serviceAccount && !oauth) {
|
|
70179
|
+
const auth = opts.ga4CredentialStore ? void 0 : opts.getGoogleAuthConfig?.();
|
|
70180
|
+
if (opts.ga4CredentialStore || opts.googleConnectionStore && auth?.clientId && auth.clientSecret) {
|
|
70181
|
+
const error = integrationNotConnected('No GA4 connection found. Run "canonry ga connect <project>" first.');
|
|
70182
|
+
outcome2.report({ status: OutcomeStatuses.failed, ...classifyOutcomeError(error) });
|
|
70183
|
+
throw error;
|
|
70184
|
+
}
|
|
70185
|
+
}
|
|
70160
70186
|
const syncTraffic = true;
|
|
70161
70187
|
const syncSummary = true;
|
|
70162
70188
|
const syncAi = !only || only === "ai";
|
|
@@ -70178,7 +70204,6 @@ async function ga4Routes(app, opts) {
|
|
|
70178
70204
|
startedAt,
|
|
70179
70205
|
createdAt: startedAt
|
|
70180
70206
|
}).run();
|
|
70181
|
-
const outcome2 = startRouteOutcome(app, FeatureNames.ga4, "sync");
|
|
70182
70207
|
let credentialsResolved = false;
|
|
70183
70208
|
let componentFailure;
|
|
70184
70209
|
try {
|
|
@@ -70647,9 +70672,17 @@ async function ga4Routes(app, opts) {
|
|
|
70647
70672
|
} catch (e) {
|
|
70648
70673
|
const msg = describeError(e);
|
|
70649
70674
|
gaLog("error", "sync.fetch-failed", { projectId: project.id, runId, error: msg });
|
|
70650
|
-
app.db.update(runs).set({ status: RunStatuses.failed, error: msg, finishedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(eq110(runs.id, runId)).run();
|
|
70675
|
+
const saved = app.db.update(runs).set({ status: RunStatuses.failed, error: msg, finishedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(eq110(runs.id, runId)).run().changes === 1;
|
|
70651
70676
|
outcome2.report({ status: OutcomeStatuses.failed, ...ga4SyncFailure(e, credentialsResolved, opts, project) });
|
|
70652
|
-
throw e;
|
|
70677
|
+
if (!saved) throw e;
|
|
70678
|
+
if (e instanceof AppError) {
|
|
70679
|
+
throw new AppError(e.code, e.message, e.statusCode, { ...e.details, runId });
|
|
70680
|
+
}
|
|
70681
|
+
const error = asRecord(e);
|
|
70682
|
+
const httpStatus = error?.statusCode ?? error?.status ?? 500;
|
|
70683
|
+
if (typeof httpStatus === "number" && httpStatus >= 400 && httpStatus < 500) throw e;
|
|
70684
|
+
app.log.error(e);
|
|
70685
|
+
throw internalError("An unexpected error occurred", { runId });
|
|
70653
70686
|
}
|
|
70654
70687
|
});
|
|
70655
70688
|
app.get("/projects/:name/ga/traffic", async (request, _reply) => {
|
|
@@ -71129,7 +71162,7 @@ async function ga4Routes(app, opts) {
|
|
|
71129
71162
|
}
|
|
71130
71163
|
|
|
71131
71164
|
// ../api-routes/src/ga-acquisition.ts
|
|
71132
|
-
import { and as and96, asc as asc26, count as count10, desc as desc51, eq as eq111, gte as gte29, lte as
|
|
71165
|
+
import { and as and96, asc as asc26, count as count10, desc as desc51, eq as eq111, gte as gte29, lte as lte27, sql as sql47 } from "drizzle-orm";
|
|
71133
71166
|
async function gaAcquisitionRoutes(app) {
|
|
71134
71167
|
app.get("/projects/:name/ga/acquisition", async (request) => {
|
|
71135
71168
|
const project = resolveProject(app.db, request.params.name);
|
|
@@ -71154,7 +71187,7 @@ async function gaAcquisitionRoutes(app) {
|
|
|
71154
71187
|
};
|
|
71155
71188
|
const windowFilters = [eq111(gaAcquisitionDaily.projectId, project.id)];
|
|
71156
71189
|
if (range.startDate) windowFilters.push(gte29(gaAcquisitionDaily.date, range.startDate));
|
|
71157
|
-
if (range.endDate) windowFilters.push(
|
|
71190
|
+
if (range.endDate) windowFilters.push(lte27(gaAcquisitionDaily.date, range.endDate));
|
|
71158
71191
|
const filters = [...windowFilters];
|
|
71159
71192
|
if (query2.channel !== void 0) filters.push(sql47`lower(${gaAcquisitionDaily.channelGroup}) = lower(${query2.channel})`);
|
|
71160
71193
|
if (query2.hostName !== void 0) filters.push(sql47`lower(${gaAcquisitionDaily.hostName}) = lower(${query2.hostName})`);
|
|
@@ -73775,7 +73808,7 @@ async function backlinksRoutes(app, opts) {
|
|
|
73775
73808
|
import crypto62 from "crypto";
|
|
73776
73809
|
import { isIP as isIP3 } from "net";
|
|
73777
73810
|
import { isDeepStrictEqual } from "util";
|
|
73778
|
-
import { and as and100, desc as desc54, eq as eq115, gt as gt9, gte as gte30, inArray as inArray53, lt as lt20, lte as
|
|
73811
|
+
import { and as and100, desc as desc54, eq as eq115, gt as gt9, gte as gte30, inArray as inArray53, lt as lt20, lte as lte29, sql as sql50 } from "drizzle-orm";
|
|
73779
73812
|
|
|
73780
73813
|
// ../integration-cloud-run/src/auth.ts
|
|
73781
73814
|
import crypto60 from "crypto";
|
|
@@ -74876,7 +74909,7 @@ async function requestJson(options, request, signal) {
|
|
|
74876
74909
|
sleep: options.sleep
|
|
74877
74910
|
});
|
|
74878
74911
|
}
|
|
74879
|
-
function
|
|
74912
|
+
function asRecord2(value, label) {
|
|
74880
74913
|
if (value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
74881
74914
|
throw new CloudflareQueueApiError(`Cloudflare Queue ${label} is malformed`, 502);
|
|
74882
74915
|
}
|
|
@@ -74897,7 +74930,7 @@ function stringField(record3, key, label) {
|
|
|
74897
74930
|
return value;
|
|
74898
74931
|
}
|
|
74899
74932
|
function metadata(record3) {
|
|
74900
|
-
const value =
|
|
74933
|
+
const value = asRecord2(record3.metadata, "message metadata");
|
|
74901
74934
|
const parsed = {};
|
|
74902
74935
|
for (const [key, entry] of Object.entries(value)) {
|
|
74903
74936
|
if (typeof entry !== "string") {
|
|
@@ -75002,11 +75035,11 @@ function decodeMessage(record3) {
|
|
|
75002
75035
|
return poison("unsupported-content-type");
|
|
75003
75036
|
}
|
|
75004
75037
|
function parsePullEnvelope(value) {
|
|
75005
|
-
const envelope =
|
|
75038
|
+
const envelope = asRecord2(value, "pull response");
|
|
75006
75039
|
if (envelope.success !== true) {
|
|
75007
75040
|
throw new CloudflareQueueApiError("Cloudflare Queue pull was not successful", 502);
|
|
75008
75041
|
}
|
|
75009
|
-
const result =
|
|
75042
|
+
const result = asRecord2(envelope.result, "pull result");
|
|
75010
75043
|
const messageBacklogCount = nonNegativeInteger(result.message_backlog_count, "message_backlog_count");
|
|
75011
75044
|
if (!Array.isArray(result.messages)) {
|
|
75012
75045
|
throw new CloudflareQueueApiError("Cloudflare Queue messages is malformed", 502);
|
|
@@ -75046,12 +75079,12 @@ function ackWarningCount(value) {
|
|
|
75046
75079
|
return Object.keys(warnings).length;
|
|
75047
75080
|
}
|
|
75048
75081
|
function parseAckEnvelope(value, expectedAckCount, expectedRetryCount) {
|
|
75049
|
-
const envelope =
|
|
75082
|
+
const envelope = asRecord2(value, "ack response");
|
|
75050
75083
|
if (envelope.success !== true) {
|
|
75051
75084
|
throw new CloudflareQueueApiError("Cloudflare Queue acknowledgement was not successful", 502);
|
|
75052
75085
|
}
|
|
75053
75086
|
if (envelope.result == null) return 0;
|
|
75054
|
-
const result =
|
|
75087
|
+
const result = asRecord2(envelope.result, "ack result");
|
|
75055
75088
|
const ackCount = optionalAckCount(result, "ackCount");
|
|
75056
75089
|
const retryCount = optionalAckCount(result, "retryCount");
|
|
75057
75090
|
if (ackCount !== void 0 && ackCount !== expectedAckCount || retryCount !== void 0 && retryCount !== expectedRetryCount) {
|
|
@@ -75113,7 +75146,7 @@ async function ackCloudflareQueueMessages(client, options) {
|
|
|
75113
75146
|
}
|
|
75114
75147
|
|
|
75115
75148
|
// ../api-routes/src/traffic-sync-lease.ts
|
|
75116
|
-
import { and as and99, eq as eq113, isNull as isNull20, lte as
|
|
75149
|
+
import { and as and99, eq as eq113, isNull as isNull20, lte as lte28, or as or20 } from "drizzle-orm";
|
|
75117
75150
|
function leaseExpiresAt(now, ttlMs) {
|
|
75118
75151
|
const nowMs = Date.parse(now);
|
|
75119
75152
|
if (!Number.isFinite(nowMs)) throw new RangeError("Traffic sync lease now must be an ISO instant");
|
|
@@ -75130,7 +75163,7 @@ function tryClaimTrafficSyncLease(input) {
|
|
|
75130
75163
|
eq113(trafficSources.id, input.sourceId),
|
|
75131
75164
|
or20(
|
|
75132
75165
|
isNull20(trafficSources.syncLeaseOwner),
|
|
75133
|
-
|
|
75166
|
+
lte28(trafficSources.syncLeaseExpiresAt, input.now),
|
|
75134
75167
|
eq113(trafficSources.syncLeaseOwner, input.owner)
|
|
75135
75168
|
)
|
|
75136
75169
|
)).run();
|
|
@@ -75948,14 +75981,14 @@ async function runBackfillTaskHoldingLease(options, signal) {
|
|
|
75948
75981
|
and100(
|
|
75949
75982
|
eq115(crawlerEventsHourly.sourceId, sourceRow2.id),
|
|
75950
75983
|
gte30(crawlerEventsHourly.tsHour, windowStartIso),
|
|
75951
|
-
|
|
75984
|
+
lte29(crawlerEventsHourly.tsHour, windowEndIso)
|
|
75952
75985
|
)
|
|
75953
75986
|
).run();
|
|
75954
75987
|
tx.delete(aiUserFetchEventsHourly).where(
|
|
75955
75988
|
and100(
|
|
75956
75989
|
eq115(aiUserFetchEventsHourly.sourceId, sourceRow2.id),
|
|
75957
75990
|
gte30(aiUserFetchEventsHourly.tsHour, windowStartIso),
|
|
75958
|
-
|
|
75991
|
+
lte29(aiUserFetchEventsHourly.tsHour, windowEndIso)
|
|
75959
75992
|
)
|
|
75960
75993
|
).run();
|
|
75961
75994
|
clearLikelyFakeAgentHits(tx, { sourceId: sourceRow2.id, windowStart: windowStartIso, windowEnd: windowEndIso });
|
|
@@ -75963,21 +75996,21 @@ async function runBackfillTaskHoldingLease(options, signal) {
|
|
|
75963
75996
|
and100(
|
|
75964
75997
|
eq115(aiReferralEventsHourly.sourceId, sourceRow2.id),
|
|
75965
75998
|
gte30(aiReferralEventsHourly.tsHour, windowStartIso),
|
|
75966
|
-
|
|
75999
|
+
lte29(aiReferralEventsHourly.tsHour, windowEndIso)
|
|
75967
76000
|
)
|
|
75968
76001
|
).run();
|
|
75969
76002
|
tx.delete(rawEventSamples).where(
|
|
75970
76003
|
and100(
|
|
75971
76004
|
eq115(rawEventSamples.sourceId, sourceRow2.id),
|
|
75972
76005
|
gte30(rawEventSamples.ts, windowStartIso),
|
|
75973
|
-
|
|
76006
|
+
lte29(rawEventSamples.ts, windowEndIso)
|
|
75974
76007
|
)
|
|
75975
76008
|
).run();
|
|
75976
76009
|
tx.delete(unrecognizedAgentEventsHourly).where(
|
|
75977
76010
|
and100(
|
|
75978
76011
|
eq115(unrecognizedAgentEventsHourly.sourceId, sourceRow2.id),
|
|
75979
76012
|
gte30(unrecognizedAgentEventsHourly.tsHour, windowStartIso),
|
|
75980
|
-
|
|
76013
|
+
lte29(unrecognizedAgentEventsHourly.tsHour, windowEndIso)
|
|
75981
76014
|
)
|
|
75982
76015
|
).run();
|
|
75983
76016
|
for (const bucket of report.crawlerEventsHourly) {
|
|
@@ -78732,7 +78765,7 @@ async function trafficRoutes(app, opts) {
|
|
|
78732
78765
|
const crawlerFilters = [
|
|
78733
78766
|
eq115(crawlerEventsHourly.projectId, project.id),
|
|
78734
78767
|
gte30(crawlerEventsHourly.tsHour, sinceIso),
|
|
78735
|
-
|
|
78768
|
+
lte29(crawlerEventsHourly.tsHour, untilIso)
|
|
78736
78769
|
];
|
|
78737
78770
|
if (sourceIdParam) crawlerFilters.push(eq115(crawlerEventsHourly.sourceId, sourceIdParam));
|
|
78738
78771
|
crawlerFilters.push(...trafficEventFilterPredicates(TRAFFIC_EVENT_TABLES.crawler, readFilters));
|
|
@@ -78814,7 +78847,7 @@ async function trafficRoutes(app, opts) {
|
|
|
78814
78847
|
const userFetchFilters = [
|
|
78815
78848
|
eq115(aiUserFetchEventsHourly.projectId, project.id),
|
|
78816
78849
|
gte30(aiUserFetchEventsHourly.tsHour, sinceIso),
|
|
78817
|
-
|
|
78850
|
+
lte29(aiUserFetchEventsHourly.tsHour, untilIso)
|
|
78818
78851
|
];
|
|
78819
78852
|
if (sourceIdParam) userFetchFilters.push(eq115(aiUserFetchEventsHourly.sourceId, sourceIdParam));
|
|
78820
78853
|
userFetchFilters.push(...trafficEventFilterPredicates(TRAFFIC_EVENT_TABLES["ai-user-fetch"], readFilters));
|
|
@@ -78860,7 +78893,7 @@ async function trafficRoutes(app, opts) {
|
|
|
78860
78893
|
const aiFilters = [
|
|
78861
78894
|
eq115(aiReferralEventsHourly.projectId, project.id),
|
|
78862
78895
|
gte30(aiReferralEventsHourly.tsHour, sinceIso),
|
|
78863
|
-
|
|
78896
|
+
lte29(aiReferralEventsHourly.tsHour, untilIso)
|
|
78864
78897
|
];
|
|
78865
78898
|
if (sourceIdParam) aiFilters.push(eq115(aiReferralEventsHourly.sourceId, sourceIdParam));
|
|
78866
78899
|
aiFilters.push(...trafficEventFilterPredicates(TRAFFIC_EVENT_TABLES["ai-referral"], readFilters));
|
|
@@ -79065,7 +79098,7 @@ async function trafficRoutes(app, opts) {
|
|
|
79065
79098
|
}
|
|
79066
79099
|
|
|
79067
79100
|
// ../api-routes/src/doctor/checks/report-sweeps.ts
|
|
79068
|
-
import { and as and101, asc as asc28, eq as eq116, gte as gte31, lte as
|
|
79101
|
+
import { and as and101, asc as asc28, eq as eq116, gte as gte31, lte as lte30 } from "drizzle-orm";
|
|
79069
79102
|
|
|
79070
79103
|
// ../api-routes/src/visibility-attribution.ts
|
|
79071
79104
|
function buildQueryAttribution2(projectQueries) {
|
|
@@ -79187,7 +79220,7 @@ var reportSweepsCheck = {
|
|
|
79187
79220
|
const graded = gradedReportMonths(reportMonths, now);
|
|
79188
79221
|
const months = reportMonths.map((month) => {
|
|
79189
79222
|
const bounds = calendarMonthBounds(month);
|
|
79190
|
-
const monthRuns = ctx.db.select().from(runs).where(and101(eq116(runs.projectId, ctx.project.id), eq116(runs.kind, RunKinds["answer-visibility"]), notProbeRun(), gte31(runs.createdAt, bounds.since),
|
|
79223
|
+
const monthRuns = ctx.db.select().from(runs).where(and101(eq116(runs.projectId, ctx.project.id), eq116(runs.kind, RunKinds["answer-visibility"]), notProbeRun(), gte31(runs.createdAt, bounds.since), lte30(runs.createdAt, bounds.until))).orderBy(asc28(runs.createdAt), asc28(runs.id)).all();
|
|
79191
79224
|
const evidence = monthRuns.map((run) => inspectSweep(ctx, run));
|
|
79192
79225
|
return {
|
|
79193
79226
|
month,
|
|
@@ -79210,7 +79243,7 @@ var reportSweepsCheck = {
|
|
|
79210
79243
|
};
|
|
79211
79244
|
|
|
79212
79245
|
// ../api-routes/src/doctor/checks/report-models.ts
|
|
79213
|
-
import { and as and102, eq as eq117, gte as gte32, inArray as inArray54, lte as
|
|
79246
|
+
import { and as and102, eq as eq117, gte as gte32, inArray as inArray54, lte as lte31 } from "drizzle-orm";
|
|
79214
79247
|
var reportModelsCheck = {
|
|
79215
79248
|
id: "report.models",
|
|
79216
79249
|
category: CheckCategories.providers,
|
|
@@ -79225,7 +79258,7 @@ var reportModelsCheck = {
|
|
|
79225
79258
|
const months = reportMonths.flatMap((month) => {
|
|
79226
79259
|
const bounds = calendarMonthBounds(month);
|
|
79227
79260
|
const previous = new Date(Date.parse(bounds.since) - 1).toISOString().slice(0, 7);
|
|
79228
|
-
const observations = ctx.db.select({ provider: querySnapshots.provider, model: querySnapshots.model, at: runs.createdAt }).from(querySnapshots).innerJoin(runs, eq117(runs.id, querySnapshots.runId)).where(and102(eq117(runs.projectId, ctx.project.id), eq117(runs.kind, RunKinds["answer-visibility"]), inArray54(runs.status, [RunStatuses.completed, RunStatuses.partial]), notProbeRun(), gte32(runs.createdAt, bounds.since),
|
|
79261
|
+
const observations = ctx.db.select({ provider: querySnapshots.provider, model: querySnapshots.model, at: runs.createdAt }).from(querySnapshots).innerJoin(runs, eq117(runs.id, querySnapshots.runId)).where(and102(eq117(runs.projectId, ctx.project.id), eq117(runs.kind, RunKinds["answer-visibility"]), inArray54(runs.status, [RunStatuses.completed, RunStatuses.partial]), notProbeRun(), gte32(runs.createdAt, bounds.since), lte31(runs.createdAt, bounds.until))).all();
|
|
79229
79262
|
return readVisibilityContinuity(ctx.db, ctx.project.name, { from: previous, to: month }).map(({ frame, continuity: continuity2 }) => ({
|
|
79230
79263
|
month,
|
|
79231
79264
|
previousMonth: previous,
|