@canonry/canonry 7.51.4 → 7.51.6
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/assets/assets/AccessControls-B5TqDgeq.js +1 -0
- package/assets/assets/AuditHistoryPanel-DgxiizOW.js +1 -0
- package/assets/assets/BacklinksPage-Ay6pdphx.js +1 -0
- package/assets/assets/ChartPrimitives-DIEeZdrs.js +1 -0
- package/assets/assets/Hint-Cn4lh0Do.js +1 -0
- package/assets/assets/HistoryPage-B11eFH21.js +1 -0
- package/assets/assets/InfoTooltip-TIx9qM5h.js +1 -0
- package/assets/assets/MeasurementPropertyPage-1UYI7mzP.js +4 -0
- package/assets/assets/ProjectPage-DoY0hftd.js +8 -0
- package/assets/assets/RunsPage-BPBmuQAS.js +1 -0
- package/assets/assets/SettingsPage-ClKnP8xy.js +1 -0
- package/assets/assets/SiteHealthSection-PWjKMmEn.js +2 -0
- package/assets/assets/TrafficPage-DkfGiJXR.js +40 -0
- package/assets/assets/TrafficSourceDetailPage-DQu0YNt2.js +1 -0
- package/assets/assets/async-handler-Bj3TnIRw.js +1 -0
- package/assets/assets/card-DYMyvhB9.js +60 -0
- package/assets/assets/extract-error-message-BRM1I_3L.js +1 -0
- package/assets/assets/format-helpers-DrkFERj3.js +3 -0
- package/assets/assets/index-CG1Jox52.js +39 -0
- package/assets/assets/index-CsPsaUr7.css +1 -0
- package/assets/assets/query-client-gRFnU4VF.js +1 -0
- package/assets/assets/react-query-lH82FULK.js +1 -0
- package/assets/assets/react-sigma_core.esm.min-D09H4byP.js +3225 -0
- package/assets/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/assets/assets/service-Cx0HSnE9.js +1 -0
- package/assets/assets/vendor-lucide-BjvO55Hk.js +1 -0
- package/assets/assets/vendor-markdown-DWjffpgb.js +29 -0
- package/assets/assets/vendor-radix-BU76HM0G.js +41 -0
- package/assets/assets/vendor-recharts-CsHBXoK8.js +59 -0
- package/assets/assets/vendor-tanstack-QhOrDhIL.js +2 -0
- package/assets/assets/vendor-yaml-Y43rmNgW.js +105 -0
- package/assets/index.html +16 -8
- package/dist/ads-ABAT3K4K.js +544 -0
- package/dist/agent-5G4DRLYX.js +70 -0
- package/dist/agent-ask-UDVCZRO7.js +139 -0
- package/dist/agent-conversations-5E4JP2QZ.js +52 -0
- package/dist/agent-memory-7IIJ4HGZ.js +92 -0
- package/dist/agent-providers-BOXPUXZ4.js +55 -0
- package/dist/agent-transcript-4O56G6PQ.js +77 -0
- package/dist/analytics-PKMWX5XL.js +240 -0
- package/dist/apply-OK4XEBDA.js +175 -0
- package/dist/backfill-2OT56CX2.js +41 -0
- package/dist/backlinks-547WCHND.js +303 -0
- package/dist/bing-ZVBV4ZD5.js +418 -0
- package/dist/bootstrap-HUB7XQ73.js +326 -0
- package/dist/cdp-KQKQ4PWJ.js +162 -0
- package/dist/chunk-2G6IP3MO.js +517 -0
- package/dist/chunk-42D2LE2B.js +1273 -0
- package/dist/chunk-4MJYGB56.js +124 -0
- package/dist/chunk-63ISSSGX.js +9150 -0
- package/dist/{chunk-HHRM3H3L.js → chunk-6G6FTDWC.js} +8082 -13941
- package/dist/chunk-6GO5VVAC.js +15 -0
- package/dist/{chunk-6GNV6VF4.js → chunk-73P65KPW.js} +2 -2
- package/dist/chunk-7B2Q4NJE.js +133 -0
- package/dist/{chunk-KU4TPVZV.js → chunk-7WZ2FPB4.js} +2 -13
- package/dist/chunk-AOJU5LKX.js +8 -0
- package/dist/chunk-B2FR2ZQ4.js +420 -0
- package/dist/chunk-B5J675KK.js +6557 -0
- package/dist/{chunk-YOGHHIGE.js → chunk-D6COIM3U.js} +17155 -17164
- package/dist/{chunk-KUS7M65J.js → chunk-DGVUTH7W.js} +6809 -32243
- package/dist/chunk-ELCLGWUT.js +83 -0
- package/dist/chunk-GO2J7SYT.js +1034 -0
- package/dist/chunk-HACZUMGM.js +145 -0
- package/dist/chunk-HM4NNKLG.js +94 -0
- package/dist/chunk-I3A56PFP.js +58 -0
- package/dist/chunk-I77PLCWG.js +961 -0
- package/dist/chunk-ISOQPVPY.js +232 -0
- package/dist/chunk-KFT5LOP2.js +610 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-MMEO22MF.js +38 -0
- package/dist/chunk-NHQ2U5I4.js +78 -0
- package/dist/chunk-PCXRFT3N.js +530 -0
- package/dist/chunk-PITHTCAX.js +15376 -0
- package/dist/chunk-QWKPSFGL.js +30 -0
- package/dist/chunk-RKIXES2B.js +609 -0
- package/dist/chunk-TSENU4GG.js +18 -0
- package/dist/{chunk-P6D6P337.js → chunk-TUTKNUMV.js} +7 -5
- package/dist/chunk-U3AHE2RT.js +1160 -0
- package/dist/chunk-UQ3MOZGC.js +644 -0
- package/dist/{chunk-35QQMVO6.js → chunk-VBCE4CLX.js} +6 -4
- package/dist/chunk-VJWDBFSL.js +69 -0
- package/dist/chunk-VYMZ3QXG.js +8264 -0
- package/dist/chunk-WAULJDKO.js +2686 -0
- package/dist/chunk-WDFI5YMD.js +204 -0
- package/dist/chunk-XEBKF4N5.js +8 -0
- package/dist/chunk-Z7IUAJOF.js +13 -0
- package/dist/{chunk-RUWELF3K.js → chunk-ZWJRY5UI.js} +358 -581
- package/dist/chunk-ZXUAWVWM.js +15 -0
- package/dist/citations-UYB2RU5U.js +106 -0
- package/dist/{cli-catalog-KTQ6BHEU.js → cli-catalog-F6FI7NB2.js} +5 -3
- package/dist/cli-commands-ZG5ILKDA.js +19 -0
- package/dist/cli.js +35 -29
- package/dist/competitor-EKP4R7YY.js +561 -0
- package/dist/content-DREE6JF3.js +257 -0
- package/dist/dashboard-ZALEOLLU.js +71 -0
- package/dist/demo-JG4Y22O4.js +75 -0
- package/dist/{demo-server-26UUDUM7.js → demo-server-3A4J2C65.js} +22 -9
- package/dist/discover-W6GMD2HS.js +372 -0
- package/dist/discover-eval-CKFZHRBW.js +282 -0
- package/dist/doctor-TNGBSUMA.js +152 -0
- package/dist/evidence-3H2GFQBZ.js +57 -0
- package/dist/export-cmd-WUIKU5GK.js +49 -0
- package/dist/ga-JI6REFO4.js +911 -0
- package/dist/gbp-4ENDM5NS.js +370 -0
- package/dist/google-HKQSCLOC.js +946 -0
- package/dist/google-marketing-KQR5J2S4.js +403 -0
- package/dist/health-cmd-TS7EMMCS.js +64 -0
- package/dist/history-MSD5DK6K.js +90 -0
- package/dist/index.d.ts +194 -60
- package/dist/index.js +29 -6
- package/dist/init-L6WAEOWX.js +432 -0
- package/dist/insights-RTZ3IZTD.js +63 -0
- package/dist/intelligence-service-TH52PCNJ.js +15 -0
- package/dist/keys-625DZBRM.js +116 -0
- package/dist/keyword-CW46RNRR.js +164 -0
- package/dist/logs-V33SHBIW.js +30 -0
- package/dist/mcp-DFEDPSEG.js +14 -0
- package/dist/mcp.js +14 -5
- package/dist/measurement-plan-6W37RUOP.js +42 -0
- package/dist/notify-DSUOT7WO.js +125 -0
- package/dist/organic-evidence-BMN6L4OB.js +53 -0
- package/dist/overview-WRRMBZ6S.js +213 -0
- package/dist/project-2GJIU3FE.js +460 -0
- package/dist/query-3XPMGJUA.js +211 -0
- package/dist/research-V433CKJ4.js +200 -0
- package/dist/results-export-RGBU7QQQ.js +27 -0
- package/dist/run-NIAC6OJN.js +31 -0
- package/dist/schedule-KDWXRIE7.js +177 -0
- package/dist/search-626MPUJN.js +42 -0
- package/dist/serve-73SMMASI.js +557 -0
- package/dist/session-7WWOETZB.js +47 -0
- package/dist/settings-VKFQO6F2.js +107 -0
- package/dist/skills-5HC5H7TE.js +33 -0
- package/dist/snapshot-BSJUHFBC.js +538 -0
- package/dist/src-F6HM73TN.js +316 -0
- package/dist/status-V4OWP7LZ.js +126 -0
- package/dist/support-ARF4HER7.js +24 -0
- package/dist/technical-aeo-TG7CGU3F.js +625 -0
- package/dist/telemetry-O2IUNUBW.js +118 -0
- package/dist/tools-2GJIDKND.js +41 -0
- package/dist/traffic-XV4I3UPH.js +1295 -0
- package/dist/users-VGBLDL5K.js +170 -0
- package/dist/visibility-stats-UKJYJ6PP.js +241 -0
- package/dist/wordpress-JZA7CGC6.js +600 -0
- package/package.json +30 -30
- package/assets/assets/AuditHistoryPanel-CtWNkC6F.js +0 -1
- package/assets/assets/BacklinksPage-Cs3_j55C.js +0 -1
- package/assets/assets/ChartPrimitives-B6ryduMN.js +0 -1
- package/assets/assets/Hint-DICI5Jq9.js +0 -1
- package/assets/assets/HistoryPage-_5Vwj01m.js +0 -1
- package/assets/assets/MeasurementPropertyPage-B2yBTUZd.js +0 -4
- package/assets/assets/ProjectPage-hs-9PcoS.js +0 -8
- package/assets/assets/RunsPage-B_mhz9vj.js +0 -1
- package/assets/assets/SettingsPage-D1Lzcw03.js +0 -1
- package/assets/assets/SiteHealthSection-CGlrPdrk.js +0 -4
- package/assets/assets/TrafficPage-C27a0rQp.js +0 -40
- package/assets/assets/TrafficSourceDetailPage-DOSoQySv.js +0 -1
- package/assets/assets/extract-error-message-itBoiivg.js +0 -1
- package/assets/assets/index-Br2WtEIO.css +0 -1
- package/assets/assets/index-CdAuyP-X.js +0 -86
- package/assets/assets/react-sigma_core.esm.min-CPYhSQFc.js +0 -312
- package/assets/assets/v2-overview-adapter-DQXWmK0B.js +0 -1
- package/assets/assets/vendor-lucide-Y6jANGfG.js +0 -1
- package/assets/assets/vendor-markdown-B4giJcws.js +0 -29
- package/assets/assets/vendor-radix-twS1M3FF.js +0 -45
- package/assets/assets/vendor-recharts-D_R6YxjS.js +0 -36
- package/assets/assets/vendor-tanstack-ZXXkndVj.js +0 -1
- package/assets/assets/vendor-yaml-GWJz5H2G.js +0 -131
- package/dist/chunk-EQTVQIM2.js +0 -23082
- package/dist/chunk-GZPJ7TSE.js +0 -10872
- package/dist/cli-commands-5ZODWR4I.js +0 -15
- package/dist/intelligence-service-ZGDBVFDE.js +0 -9
|
@@ -0,0 +1,946 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createApiClient
|
|
3
|
+
} from "./chunk-B5J675KK.js";
|
|
4
|
+
import "./chunk-UQ3MOZGC.js";
|
|
5
|
+
import {
|
|
6
|
+
emitJsonl
|
|
7
|
+
} from "./chunk-Z7IUAJOF.js";
|
|
8
|
+
import {
|
|
9
|
+
dedupeGscSitemapUrls,
|
|
10
|
+
requireGscSitemapUrls,
|
|
11
|
+
resolveDiscoveredGscSitemapUrls,
|
|
12
|
+
submitGscSitemapBatches
|
|
13
|
+
} from "./chunk-HM4NNKLG.js";
|
|
14
|
+
import "./chunk-AOJU5LKX.js";
|
|
15
|
+
import {
|
|
16
|
+
CliError,
|
|
17
|
+
isMachineFormat
|
|
18
|
+
} from "./chunk-HGMYEDAQ.js";
|
|
19
|
+
import {
|
|
20
|
+
formatPercent
|
|
21
|
+
} from "./chunk-D6COIM3U.js";
|
|
22
|
+
import "./chunk-MLKGABMK.js";
|
|
23
|
+
|
|
24
|
+
// src/commands/google.ts
|
|
25
|
+
var INDEXING_API_SCOPE_NOTICE = "Note: Google's Indexing API officially supports only pages with JobPosting or BroadcastEvent (livestream VideoObject) structured data. Other URL types are outside the supported use of that API. For general pages, submit a sitemap and use URL Inspection to monitor status.";
|
|
26
|
+
function getClient() {
|
|
27
|
+
return createApiClient();
|
|
28
|
+
}
|
|
29
|
+
async function waitForRunStatus(client, runId, config) {
|
|
30
|
+
const start = Date.now();
|
|
31
|
+
process.stderr.write(config.progressLabel);
|
|
32
|
+
while (Date.now() - start < config.timeoutMs) {
|
|
33
|
+
await new Promise((resolve) => setTimeout(resolve, config.intervalMs));
|
|
34
|
+
const current = await client.getRun(runId);
|
|
35
|
+
process.stderr.write(".");
|
|
36
|
+
if (config.successStatuses.includes(current.status)) {
|
|
37
|
+
process.stderr.write("\n");
|
|
38
|
+
return current;
|
|
39
|
+
}
|
|
40
|
+
if (config.failureStatuses.includes(current.status)) {
|
|
41
|
+
process.stderr.write("\n");
|
|
42
|
+
throw new CliError({
|
|
43
|
+
code: config.failureCode,
|
|
44
|
+
message: config.failureMessage,
|
|
45
|
+
displayMessage: config.failureMessage,
|
|
46
|
+
details: {
|
|
47
|
+
runId,
|
|
48
|
+
status: current.status,
|
|
49
|
+
...config.details ?? {}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
process.stderr.write("\n");
|
|
55
|
+
throw new CliError({
|
|
56
|
+
code: config.timeoutCode,
|
|
57
|
+
message: config.timeoutMessage,
|
|
58
|
+
displayMessage: config.timeoutMessage,
|
|
59
|
+
details: {
|
|
60
|
+
runId,
|
|
61
|
+
...config.details ?? {}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async function googleConnect(project, opts) {
|
|
66
|
+
const client = getClient();
|
|
67
|
+
const { authUrl, redirectUri } = await client.googleConnect(project, {
|
|
68
|
+
type: opts.type,
|
|
69
|
+
publicUrl: opts.publicUrl
|
|
70
|
+
});
|
|
71
|
+
if (isMachineFormat(opts.format)) {
|
|
72
|
+
console.log(JSON.stringify({
|
|
73
|
+
project,
|
|
74
|
+
type: opts.type,
|
|
75
|
+
authUrl,
|
|
76
|
+
redirectUri: redirectUri ?? null
|
|
77
|
+
}, null, 2));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
console.log(`
|
|
81
|
+
Open this URL in your browser to authorize Google ${opts.type.toUpperCase()} access:
|
|
82
|
+
`);
|
|
83
|
+
console.log(` ${authUrl}
|
|
84
|
+
`);
|
|
85
|
+
if (redirectUri) {
|
|
86
|
+
console.log(`Redirect URI: ${redirectUri}`);
|
|
87
|
+
console.log("(Ensure this URI is listed in your Google Cloud Console OAuth client's authorized redirect URIs)\n");
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const { spawn } = await import("child_process");
|
|
91
|
+
const platform = process.platform;
|
|
92
|
+
const [cmd, ...extraArgs] = platform === "darwin" ? ["open", authUrl] : platform === "win32" ? ["cmd", "/c", "start", "", authUrl] : ["xdg-open", authUrl];
|
|
93
|
+
spawn(cmd, [...extraArgs], { detached: true, stdio: "ignore" }).unref();
|
|
94
|
+
console.log("(Browser opened automatically)");
|
|
95
|
+
} catch {
|
|
96
|
+
console.log("(Could not open browser automatically \u2014 please copy the URL above)");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function googleDisconnect(project, opts) {
|
|
100
|
+
const client = getClient();
|
|
101
|
+
await client.googleDisconnect(project, opts.type);
|
|
102
|
+
if (isMachineFormat(opts.format)) {
|
|
103
|
+
console.log(JSON.stringify({ project, type: opts.type, disconnected: true }, null, 2));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
console.log(`Disconnected Google ${opts.type.toUpperCase()} from project "${project}".`);
|
|
107
|
+
}
|
|
108
|
+
async function googleStatus(project, format) {
|
|
109
|
+
const client = getClient();
|
|
110
|
+
const connections = await client.googleConnections(project);
|
|
111
|
+
if (format === "json") {
|
|
112
|
+
console.log(JSON.stringify({ connections }, null, 2));
|
|
113
|
+
return;
|
|
114
|
+
} else if (format === "jsonl") {
|
|
115
|
+
emitJsonl(connections.map((conn) => ({ project, ...conn })));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (connections.length === 0) {
|
|
119
|
+
console.log(`No Google connections for project "${project}".`);
|
|
120
|
+
console.log('Run "canonry google connect <project> --type gsc" to connect.');
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
console.log(`Google connections for "${project}":
|
|
124
|
+
`);
|
|
125
|
+
for (const conn of connections) {
|
|
126
|
+
const type = conn.connectionType.toUpperCase();
|
|
127
|
+
const property = conn.propertyId ?? "(not set)";
|
|
128
|
+
console.log(` ${type}`);
|
|
129
|
+
console.log(` Property: ${property}`);
|
|
130
|
+
console.log(` Connected: ${conn.createdAt}`);
|
|
131
|
+
console.log(` Updated: ${conn.updatedAt}`);
|
|
132
|
+
console.log();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function googleProperties(project, format) {
|
|
136
|
+
const client = getClient();
|
|
137
|
+
const { sites } = await client.googleProperties(project);
|
|
138
|
+
if (format === "json") {
|
|
139
|
+
console.log(JSON.stringify({ sites }, null, 2));
|
|
140
|
+
return;
|
|
141
|
+
} else if (format === "jsonl") {
|
|
142
|
+
emitJsonl(sites.map((site) => ({ project, ...site })));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (sites.length === 0) {
|
|
146
|
+
console.log("No verified sites found for this Google account.");
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
console.log("Available GSC properties:\n");
|
|
150
|
+
const urlWidth = Math.max(10, ...sites.map((s) => s.siteUrl.length));
|
|
151
|
+
console.log(` ${"SITE URL".padEnd(urlWidth)} PERMISSION`);
|
|
152
|
+
console.log(` ${"\u2500".repeat(urlWidth)} ${"\u2500".repeat(12)}`);
|
|
153
|
+
for (const site of sites) {
|
|
154
|
+
console.log(` ${site.siteUrl.padEnd(urlWidth)} ${site.permissionLevel}`);
|
|
155
|
+
}
|
|
156
|
+
console.log(`
|
|
157
|
+
Use "canonry google set-property <project> <siteUrl>" to select a property.`);
|
|
158
|
+
}
|
|
159
|
+
async function googleSetProperty(project, propertyUrl, format) {
|
|
160
|
+
const client = getClient();
|
|
161
|
+
await client.googleSetProperty(project, "gsc", propertyUrl);
|
|
162
|
+
if (isMachineFormat(format)) {
|
|
163
|
+
console.log(JSON.stringify({ project, type: "gsc", propertyUrl }, null, 2));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
console.log(`GSC property set to "${propertyUrl}" for project "${project}".`);
|
|
167
|
+
}
|
|
168
|
+
async function googleSync(project, opts) {
|
|
169
|
+
const client = getClient();
|
|
170
|
+
const run = await client.gscSync(project, { days: opts.days, full: opts.full });
|
|
171
|
+
if (!opts.wait && isMachineFormat(opts.format)) {
|
|
172
|
+
console.log(JSON.stringify(run, null, 2));
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (!isMachineFormat(opts.format)) {
|
|
176
|
+
console.log(`GSC sync started (run ${run.id})`);
|
|
177
|
+
}
|
|
178
|
+
if (opts.wait) {
|
|
179
|
+
const current = await waitForRunStatus(client, run.id, {
|
|
180
|
+
timeoutMs: 10 * 60 * 1e3,
|
|
181
|
+
intervalMs: 2e3,
|
|
182
|
+
progressLabel: "Waiting for sync to complete",
|
|
183
|
+
successStatuses: ["completed"],
|
|
184
|
+
failureStatuses: ["failed"],
|
|
185
|
+
timeoutCode: "GOOGLE_SYNC_TIMEOUT",
|
|
186
|
+
failureCode: "GOOGLE_SYNC_FAILED",
|
|
187
|
+
timeoutMessage: "Timed out waiting for GSC sync to complete.",
|
|
188
|
+
failureMessage: "GSC sync failed.",
|
|
189
|
+
details: { project }
|
|
190
|
+
});
|
|
191
|
+
if (isMachineFormat(opts.format)) {
|
|
192
|
+
console.log(JSON.stringify({ ...run, status: current.status }, null, 2));
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
console.log("GSC sync completed successfully.");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async function googlePerformanceDaily(project, opts) {
|
|
199
|
+
const client = getClient();
|
|
200
|
+
const params = {};
|
|
201
|
+
if (opts.window) params.window = opts.window;
|
|
202
|
+
if (opts.startDate) params.startDate = opts.startDate;
|
|
203
|
+
if (opts.endDate) params.endDate = opts.endDate;
|
|
204
|
+
const data = await client.gscPerformanceDaily(project, Object.keys(params).length > 0 ? params : void 0);
|
|
205
|
+
if (opts.format === "json") {
|
|
206
|
+
console.log(JSON.stringify(data, null, 2));
|
|
207
|
+
return;
|
|
208
|
+
} else if (opts.format === "jsonl") {
|
|
209
|
+
emitJsonl(data.daily.map((row) => ({ project, window: data.window, ...row })));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (data.daily.length === 0) {
|
|
213
|
+
console.log('No GSC data found in this window. Run "canonry google sync" first.');
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const { clicks, impressions, ctr, position, days } = data.totals;
|
|
217
|
+
const win = data.window;
|
|
218
|
+
const range = win?.startDate && win.endDate ? ` ${win.startDate} to ${win.endDate}` : "";
|
|
219
|
+
console.log(`GSC daily summary (${days} day${days === 1 ? "" : "s"}${range}):
|
|
220
|
+
`);
|
|
221
|
+
const endsAtFrontier = win?.endDate !== void 0 && win.endDate === win.latestDataDate;
|
|
222
|
+
if (endsAtFrontier && (win.daysSinceLatestData ?? 0) > 0) {
|
|
223
|
+
console.log(` Search Console data through ${win.endDate} (${win.daysSinceLatestData} day${win.daysSinceLatestData === 1 ? "" : "s"} ago).`);
|
|
224
|
+
console.log();
|
|
225
|
+
} else if (win?.latestDataDate && win.endDate !== win.latestDataDate) {
|
|
226
|
+
console.log(` Showing a fixed range. Latest Search Console data is ${win.latestDataDate}.`);
|
|
227
|
+
console.log();
|
|
228
|
+
}
|
|
229
|
+
console.log(` Clicks: ${clicks.toLocaleString()}`);
|
|
230
|
+
console.log(` Impressions: ${impressions.toLocaleString()}`);
|
|
231
|
+
console.log(` CTR: ${formatPercent(ctr)}`);
|
|
232
|
+
console.log(` Position: ${position == null ? "\u2014" : position.toFixed(1)}`);
|
|
233
|
+
const fits = data.trends;
|
|
234
|
+
const trendLines = [];
|
|
235
|
+
for (const [label, trend, fmt] of [
|
|
236
|
+
["Clicks", fits?.clicks, (v) => v.toFixed(2)],
|
|
237
|
+
["Impressions", fits?.impressions, (v) => v.toFixed(2)],
|
|
238
|
+
["CTR", fits?.ctr, (v) => `${(v * 100).toFixed(3)}pp`],
|
|
239
|
+
["Position", fits?.position, (v) => v.toFixed(3)]
|
|
240
|
+
]) {
|
|
241
|
+
if (!trend) continue;
|
|
242
|
+
const better = label === "Position" ? trend.slope < 0 : trend.slope > 0;
|
|
243
|
+
const direction = trend.slope === 0 ? "flat" : better ? "improving" : "declining";
|
|
244
|
+
trendLines.push(
|
|
245
|
+
` ${`${label}:`.padEnd(13)}${fmt(trend.slope).padStart(10)}/day ${direction} (r\xB2=${trend.r2.toFixed(2)})`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
if (trendLines.length > 0) {
|
|
249
|
+
console.log(`
|
|
250
|
+
Trend (least-squares fit over ${days} day${days === 1 ? "" : "s"}):`);
|
|
251
|
+
for (const line of trendLines) console.log(line);
|
|
252
|
+
}
|
|
253
|
+
const cmp = data.periodComparison;
|
|
254
|
+
if (cmp && !cmp.comparable) {
|
|
255
|
+
console.log(
|
|
256
|
+
`
|
|
257
|
+
No period comparison: period comparison needs property-level daily data. Sync again, or pick a range covered by property totals.`
|
|
258
|
+
);
|
|
259
|
+
} else if (cmp) {
|
|
260
|
+
const pct = (ratio, prior, trailing, inverted) => {
|
|
261
|
+
if (ratio === null) {
|
|
262
|
+
if (prior !== null && trailing !== null && prior <= 0 && trailing > 0) {
|
|
263
|
+
return `new in last ${cmp.days} day${cmp.days === 1 ? "" : "s"}`;
|
|
264
|
+
}
|
|
265
|
+
if (prior === null || prior <= 0) return "no prior period to compare";
|
|
266
|
+
if (trailing === null) return `no value in last ${cmp.days} day${cmp.days === 1 ? "" : "s"}`;
|
|
267
|
+
return "comparison unavailable";
|
|
268
|
+
}
|
|
269
|
+
if (ratio === 0) return "no change";
|
|
270
|
+
const better = inverted ? ratio < 0 : ratio > 0;
|
|
271
|
+
return `${ratio > 0 ? "+" : "-"}${formatPercent(Math.abs(ratio))} ${better ? "better" : "worse"}`;
|
|
272
|
+
};
|
|
273
|
+
console.log(
|
|
274
|
+
`
|
|
275
|
+
Last ${cmp.days} day${cmp.days === 1 ? "" : "s"} (${cmp.trailing.startDate} to ${cmp.trailing.endDate}) vs prior ${cmp.days} (${cmp.prior.startDate} to ${cmp.prior.endDate}):`
|
|
276
|
+
);
|
|
277
|
+
if (cmp.basis === "split-window") {
|
|
278
|
+
console.log(
|
|
279
|
+
` (no equal-length period with synced data before this window, so it was split in two)`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
for (const [label, ratio, prior, trailing, inverted] of [
|
|
283
|
+
["Clicks", cmp.change.clicks, cmp.prior.clicks, cmp.trailing.clicks, false],
|
|
284
|
+
["Impressions", cmp.change.impressions, cmp.prior.impressions, cmp.trailing.impressions, false],
|
|
285
|
+
["CTR", cmp.change.ctr, cmp.prior.ctr, cmp.trailing.ctr, false],
|
|
286
|
+
["Position", cmp.change.position, cmp.prior.position, cmp.trailing.position, true]
|
|
287
|
+
]) {
|
|
288
|
+
console.log(` ${`${label}:`.padEnd(13)}${pct(ratio, prior, trailing, inverted)}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
console.log();
|
|
292
|
+
console.log(` ${"DATE".padEnd(12)}${"CLICKS".padStart(10)}${"IMPR".padStart(12)}${"CTR".padStart(10)}${"POS".padStart(9)}`);
|
|
293
|
+
console.log(` ${"\u2500".repeat(12)}${"\u2500".repeat(10)}${"\u2500".repeat(12)}${"\u2500".repeat(10)}${"\u2500".repeat(9)}`);
|
|
294
|
+
for (const row of data.daily) {
|
|
295
|
+
console.log(
|
|
296
|
+
` ${row.date.padEnd(12)}${row.clicks.toLocaleString().padStart(10)}${row.impressions.toLocaleString().padStart(12)}${formatPercent(row.ctr).padStart(10)}${(row.position == null ? "\u2014" : row.position.toFixed(1)).padStart(9)}`
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async function googleTopPages(project, opts) {
|
|
301
|
+
const client = getClient();
|
|
302
|
+
const params = {};
|
|
303
|
+
if (opts.window) params.window = opts.window;
|
|
304
|
+
if (opts.startDate) params.startDate = opts.startDate;
|
|
305
|
+
if (opts.endDate) params.endDate = opts.endDate;
|
|
306
|
+
if (opts.limit) params.limit = String(opts.limit);
|
|
307
|
+
const data = await client.gscTopPages(project, Object.keys(params).length > 0 ? params : void 0);
|
|
308
|
+
if (opts.format === "json") {
|
|
309
|
+
console.log(JSON.stringify(data, null, 2));
|
|
310
|
+
return;
|
|
311
|
+
} else if (opts.format === "jsonl") {
|
|
312
|
+
emitJsonl(data.rows.map((row) => ({ project, ...row })));
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (data.rows.length === 0) {
|
|
316
|
+
console.log('No GSC page data found in this window. Run "canonry google sync" first.');
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
console.log(`Top pages by clicks (${data.rows.length} page${data.rows.length === 1 ? "" : "s"}):
|
|
320
|
+
`);
|
|
321
|
+
const pageWidth = Math.min(60, Math.max(20, ...data.rows.map((row) => row.page.length)));
|
|
322
|
+
console.log(` ${"PAGE".padEnd(pageWidth)}${"CLICKS".padStart(10)}${"IMPR".padStart(12)}${"CTR".padStart(10)}`);
|
|
323
|
+
console.log(` ${"\u2500".repeat(pageWidth)}${"\u2500".repeat(10)}${"\u2500".repeat(12)}${"\u2500".repeat(10)}`);
|
|
324
|
+
for (const row of data.rows) {
|
|
325
|
+
const page = row.page.length > pageWidth ? row.page.slice(0, pageWidth - 3) + "..." : row.page;
|
|
326
|
+
console.log(
|
|
327
|
+
` ${page.padEnd(pageWidth)}${row.clicks.toLocaleString().padStart(10)}${row.impressions.toLocaleString().padStart(12)}${formatPercent(row.ctr).padStart(10)}`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
console.log();
|
|
331
|
+
if (data.totals) {
|
|
332
|
+
const { clicks, impressions, ctr, days } = data.totals;
|
|
333
|
+
console.log(`Property total (${days} day${days === 1 ? "" : "s"}, source: ${data.totalsSource}):`);
|
|
334
|
+
console.log(` Clicks: ${clicks.toLocaleString()}`);
|
|
335
|
+
console.log(` Impressions: ${impressions.toLocaleString()}`);
|
|
336
|
+
console.log(` CTR: ${formatPercent(ctr)}`);
|
|
337
|
+
console.log();
|
|
338
|
+
console.log(" The page rows above are a ranking. They do not add up to this total:");
|
|
339
|
+
console.log(" Google withholds rare queries and repeats an impression per page.");
|
|
340
|
+
} else {
|
|
341
|
+
console.log("Property total: not available for this window.");
|
|
342
|
+
console.log(' Adding up the page rows would not give it. Run "canonry google sync" to fetch it.');
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
async function googleQueryTotals(project, opts) {
|
|
346
|
+
const client = getClient();
|
|
347
|
+
const params = {};
|
|
348
|
+
if (opts.startDate) params.startDate = opts.startDate;
|
|
349
|
+
if (opts.endDate) params.endDate = opts.endDate;
|
|
350
|
+
if (opts.window) params.window = opts.window;
|
|
351
|
+
if (opts.limit !== void 0) params.limit = String(opts.limit);
|
|
352
|
+
if (opts.offset !== void 0) params.offset = String(opts.offset);
|
|
353
|
+
const data = await client.gscQueryTotals(project, Object.keys(params).length > 0 ? params : void 0);
|
|
354
|
+
const { rows, totalMatching, truncated, window } = data;
|
|
355
|
+
if (opts.format === "json") {
|
|
356
|
+
console.log(JSON.stringify(data, null, 2));
|
|
357
|
+
return;
|
|
358
|
+
} else if (opts.format === "jsonl") {
|
|
359
|
+
emitJsonl(rows.map((row) => ({ project, window, ...row })));
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (rows.length === 0) {
|
|
363
|
+
if (totalMatching > 0) {
|
|
364
|
+
console.log(
|
|
365
|
+
`Offset ${opts.offset ?? 0} is past the end of the result set (${totalMatching.toLocaleString()} queries). Lower --offset to page through them.`
|
|
366
|
+
);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
console.log('No GSC query data found in this window. Run "canonry google sync" first.');
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const range = `${window.startDate ?? "earliest"} to ${window.endDate ?? "latest"}`;
|
|
373
|
+
console.log(`GSC query totals (${rows.length.toLocaleString()} of ${totalMatching.toLocaleString()} queries, ${range}):
|
|
374
|
+
`);
|
|
375
|
+
const showSource = rows.some((row) => row.source !== "google");
|
|
376
|
+
console.log(
|
|
377
|
+
` ${"QUERY".padEnd(40)}${"CLICKS".padStart(8)}${"IMPR".padStart(10)}${"CTR".padStart(8)}${"POS".padStart(7)}${"DAYS".padStart(6)}${showSource ? " SOURCE" : ""}`
|
|
378
|
+
);
|
|
379
|
+
console.log(` ${"\u2500".repeat(40)}${"\u2500".repeat(8)}${"\u2500".repeat(10)}${"\u2500".repeat(8)}${"\u2500".repeat(7)}${"\u2500".repeat(6)}${showSource ? ` ${"\u2500".repeat(11)}` : ""}`);
|
|
380
|
+
for (const row of rows.slice(0, 50)) {
|
|
381
|
+
const query = row.query.length > 38 ? row.query.slice(0, 35) + "..." : row.query;
|
|
382
|
+
console.log(
|
|
383
|
+
` ${query.padEnd(40)}${row.clicks.toLocaleString().padStart(8)}${row.impressions.toLocaleString().padStart(10)}${formatPercent(row.ctr).padStart(8)}${row.position.toFixed(1).padStart(7)}${String(row.days).padStart(6)}${showSource ? ` ${row.source}` : ""}`
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
if (rows.length > 50) {
|
|
387
|
+
console.log(`
|
|
388
|
+
... and ${rows.length - 50} more rows on this page (use --format json for full output)`);
|
|
389
|
+
}
|
|
390
|
+
if (truncated) {
|
|
391
|
+
const nextOffset = (opts.offset ?? 0) + rows.length;
|
|
392
|
+
console.log(`
|
|
393
|
+
This is one page. Use --offset ${nextOffset} (with the same --limit) to read the next.`);
|
|
394
|
+
}
|
|
395
|
+
console.log();
|
|
396
|
+
if (showSource) {
|
|
397
|
+
console.log(" Rows marked page-summed or mixed use the legacy page table for some days. Their impressions");
|
|
398
|
+
console.log(" over-count, because one search showing several of your pages was stored once per page.");
|
|
399
|
+
console.log(` Run "canonry google sync" over the window to replace them with Google's per-query totals.`);
|
|
400
|
+
}
|
|
401
|
+
console.log(" These are the queries Google names. Google leaves rare queries out, so the rows do not add up");
|
|
402
|
+
console.log(' to the property total. Use "canonry google performance-daily" for that.');
|
|
403
|
+
}
|
|
404
|
+
async function googlePerformance(project, opts) {
|
|
405
|
+
const client = getClient();
|
|
406
|
+
const params = {};
|
|
407
|
+
if (opts.startDate || opts.endDate) {
|
|
408
|
+
if (opts.startDate) params.startDate = opts.startDate;
|
|
409
|
+
if (opts.endDate) params.endDate = opts.endDate;
|
|
410
|
+
} else if (opts.days) {
|
|
411
|
+
params.days = String(opts.days);
|
|
412
|
+
}
|
|
413
|
+
if (opts.window) params.window = opts.window;
|
|
414
|
+
if (opts.keyword) params.query = opts.keyword;
|
|
415
|
+
if (opts.page) params.page = opts.page;
|
|
416
|
+
if (opts.limit !== void 0) params.limit = String(opts.limit);
|
|
417
|
+
if (opts.offset !== void 0) params.offset = String(opts.offset);
|
|
418
|
+
if (opts.orderBy) params.orderBy = opts.orderBy;
|
|
419
|
+
const data = await client.gscPerformance(project, Object.keys(params).length > 0 ? params : void 0);
|
|
420
|
+
const { rows, totalMatching, truncated, latestAvailableDate } = data;
|
|
421
|
+
if (opts.format === "json") {
|
|
422
|
+
console.log(JSON.stringify(data, null, 2));
|
|
423
|
+
return;
|
|
424
|
+
} else if (opts.format === "jsonl") {
|
|
425
|
+
emitJsonl(rows.map((row) => ({ project, ...row })));
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (rows.length === 0) {
|
|
429
|
+
const requestedEnd = params.endDate;
|
|
430
|
+
if (totalMatching > 0 && opts.offset !== void 0 && opts.offset >= totalMatching) {
|
|
431
|
+
console.log(
|
|
432
|
+
`Offset ${opts.offset} is past the end of the result set (${totalMatching.toLocaleString()} matching rows). Lower --offset to page through them.`
|
|
433
|
+
);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (latestAvailableDate && requestedEnd && requestedEnd > latestAvailableDate) {
|
|
437
|
+
console.log(
|
|
438
|
+
`No GSC data through ${requestedEnd}. GSC reporting lag: the latest date this project holds is ${latestAvailableDate}. Syncing again will not backfill dates Google has not reported yet.`
|
|
439
|
+
);
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
console.log('No GSC data found. Run "canonry google sync" first.');
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
console.log(`GSC performance data (${rows.length} of ${totalMatching.toLocaleString()} matching rows):
|
|
446
|
+
`);
|
|
447
|
+
console.log(` ${"DATE".padEnd(12)}${"QUERY".padEnd(30)}${"CLICKS".padEnd(8)}${"IMPR".padEnd(8)}${"CTR".padEnd(8)}${"POS".padEnd(6)}`);
|
|
448
|
+
console.log(` ${"\u2500".repeat(12)}${"\u2500".repeat(30)}${"\u2500".repeat(8)}${"\u2500".repeat(8)}${"\u2500".repeat(8)}${"\u2500".repeat(6)}`);
|
|
449
|
+
for (const row of rows.slice(0, 50)) {
|
|
450
|
+
const query = row.query.length > 28 ? row.query.slice(0, 25) + "..." : row.query;
|
|
451
|
+
console.log(
|
|
452
|
+
` ${row.date.padEnd(12)}${query.padEnd(30)}${String(row.clicks).padEnd(8)}${String(row.impressions).padEnd(8)}${formatPercent(row.ctr).padStart(6)} ${row.position.toFixed(1).padStart(5)}`
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
if (rows.length > 50) {
|
|
456
|
+
console.log(`
|
|
457
|
+
... and ${rows.length - 50} more rows on this page (use --format json for full output)`);
|
|
458
|
+
}
|
|
459
|
+
if (truncated) {
|
|
460
|
+
console.log("\n This is one page. Use --limit / --offset to page through the rest, --order-by to change the ranking.");
|
|
461
|
+
}
|
|
462
|
+
if (latestAvailableDate) {
|
|
463
|
+
console.log(` Latest date held for this project: ${latestAvailableDate}`);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
async function googleInspect(project, url, format) {
|
|
467
|
+
const client = getClient();
|
|
468
|
+
const result = await client.gscInspect(project, url);
|
|
469
|
+
if (isMachineFormat(format)) {
|
|
470
|
+
console.log(JSON.stringify(result, null, 2));
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
console.log(`
|
|
474
|
+
URL Inspection: ${result.url}
|
|
475
|
+
`);
|
|
476
|
+
console.log(` Indexing State: ${result.indexingState ?? "unknown"}`);
|
|
477
|
+
console.log(` Verdict: ${result.verdict ?? "unknown"}`);
|
|
478
|
+
console.log(` Coverage: ${result.coverageState ?? "unknown"}`);
|
|
479
|
+
console.log(` Page Fetch: ${result.pageFetchState ?? "unknown"}`);
|
|
480
|
+
console.log(` Robots.txt: ${result.robotsTxtState ?? "unknown"}`);
|
|
481
|
+
console.log(` Last Crawled: ${result.crawlTime ?? "unknown"}`);
|
|
482
|
+
console.log(` Mobile Friendly: ${result.isMobileFriendly === true ? "Yes" : result.isMobileFriendly === false ? "No" : "unknown"}`);
|
|
483
|
+
console.log(` Rich Results: ${result.richResults?.length ? result.richResults.join(", ") : "none"}`);
|
|
484
|
+
console.log(` Inspected At: ${result.inspectedAt}`);
|
|
485
|
+
}
|
|
486
|
+
async function googleInspections(project, opts) {
|
|
487
|
+
const client = getClient();
|
|
488
|
+
const params = {};
|
|
489
|
+
if (opts.url) params.url = opts.url;
|
|
490
|
+
const rows = await client.gscInspections(project, Object.keys(params).length > 0 ? params : void 0);
|
|
491
|
+
if (opts.format === "json") {
|
|
492
|
+
console.log(JSON.stringify(rows, null, 2));
|
|
493
|
+
return;
|
|
494
|
+
} else if (opts.format === "jsonl") {
|
|
495
|
+
emitJsonl(rows.map((row) => ({ project, ...row })));
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
if (rows.length === 0) {
|
|
499
|
+
console.log("No URL inspections found.");
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
console.log(`URL inspection history (${rows.length} records):
|
|
503
|
+
`);
|
|
504
|
+
const urlWidth = Math.min(50, Math.max(10, ...rows.map((r) => r.url.length)));
|
|
505
|
+
console.log(` ${"URL".padEnd(urlWidth)} ${"INDEXING".padEnd(14)}${"VERDICT".padEnd(10)}${"INSPECTED".padEnd(22)}`);
|
|
506
|
+
console.log(` ${"\u2500".repeat(urlWidth)} ${"\u2500".repeat(14)}${"\u2500".repeat(10)}${"\u2500".repeat(22)}`);
|
|
507
|
+
for (const row of rows) {
|
|
508
|
+
const url = row.url.length > urlWidth ? row.url.slice(0, urlWidth - 3) + "..." : row.url;
|
|
509
|
+
console.log(
|
|
510
|
+
` ${url.padEnd(urlWidth)} ${(row.indexingState ?? "unknown").padEnd(14)}${(row.verdict ?? "-").padEnd(10)}${row.inspectedAt}`
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
async function googleCoverage(project, format) {
|
|
515
|
+
const client = getClient();
|
|
516
|
+
const result = await client.gscCoverage(project);
|
|
517
|
+
if (isMachineFormat(format)) {
|
|
518
|
+
console.log(JSON.stringify(result, null, 2));
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
const { summary } = result;
|
|
522
|
+
if (summary.total === 0) {
|
|
523
|
+
console.log('No URL inspections found. Run "canonry google inspect-sitemap <project>" first.');
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
const pctColor = summary.percentage >= 80 ? "\x1B[32m" : summary.percentage >= 50 ? "\x1B[33m" : "\x1B[31m";
|
|
527
|
+
const reset = "\x1B[0m";
|
|
528
|
+
const legacyServer = summary.indexedShare === void 0;
|
|
529
|
+
const shareText = legacyServer ? `(${formatPercent(summary.percentage, "percent")})` : `(${formatPercent(summary.indexedShare)}) \xB7 ${summary.notIndexed} not indexed (${formatPercent(summary.notIndexedShare)})`;
|
|
530
|
+
console.log(`
|
|
531
|
+
Index Coverage for "${project}"
|
|
532
|
+
`);
|
|
533
|
+
console.log(` SUMMARY: ${pctColor}${summary.indexed} / ${summary.total} pages indexed ${shareText}${reset}
|
|
534
|
+
`);
|
|
535
|
+
if (result.indexed.length > 0) {
|
|
536
|
+
console.log(` INDEXED (${result.indexed.length}):`);
|
|
537
|
+
for (const page of result.indexed) {
|
|
538
|
+
const crawl = page.crawlTime ? ` (crawled: ${page.crawlTime.split("T")[0]})` : "";
|
|
539
|
+
console.log(` ${page.url}${crawl}`);
|
|
540
|
+
}
|
|
541
|
+
console.log();
|
|
542
|
+
}
|
|
543
|
+
if (result.notIndexed.length > 0) {
|
|
544
|
+
console.log(` NOT INDEXED (${result.notIndexed.length}):`);
|
|
545
|
+
for (const page of result.notIndexed) {
|
|
546
|
+
const reason = page.coverageState ? ` \u2014 ${page.coverageState}` : "";
|
|
547
|
+
console.log(` ${page.url}${reason}`);
|
|
548
|
+
}
|
|
549
|
+
console.log();
|
|
550
|
+
}
|
|
551
|
+
if (result.deindexed.length > 0) {
|
|
552
|
+
console.log(` DEINDEXED (${result.deindexed.length}):`);
|
|
553
|
+
for (const page of result.deindexed) {
|
|
554
|
+
console.log(` ${page.url} (${page.previousState} -> ${page.currentState})`);
|
|
555
|
+
}
|
|
556
|
+
console.log();
|
|
557
|
+
}
|
|
558
|
+
if (result.lastInspectedAt) {
|
|
559
|
+
console.log(` Last inspected: ${result.lastInspectedAt}`);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
async function googleSetSitemap(project, sitemapUrl, format) {
|
|
563
|
+
const client = getClient();
|
|
564
|
+
await client.googleSetSitemap(project, "gsc", sitemapUrl);
|
|
565
|
+
if (isMachineFormat(format)) {
|
|
566
|
+
console.log(JSON.stringify({ project, type: "gsc", sitemapUrl }, null, 2));
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
console.log(`GSC sitemap URL set to "${sitemapUrl}" for project "${project}".`);
|
|
570
|
+
}
|
|
571
|
+
async function googleListSitemaps(project, opts) {
|
|
572
|
+
const client = getClient();
|
|
573
|
+
const result = await client.gscSitemaps(project);
|
|
574
|
+
if (opts.format === "json") {
|
|
575
|
+
console.log(JSON.stringify(result, null, 2));
|
|
576
|
+
return;
|
|
577
|
+
} else if (opts.format === "jsonl") {
|
|
578
|
+
emitJsonl(result.sitemaps.map((s) => ({ project, ...s })));
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
if (result.sitemaps.length === 0) {
|
|
582
|
+
console.log(
|
|
583
|
+
`No sitemaps found for project "${project}". Run "canonry google submit-sitemap ${project} <url>" to submit one.`
|
|
584
|
+
);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
console.log(`
|
|
588
|
+
Sitemaps for project "${project}":
|
|
589
|
+
`);
|
|
590
|
+
for (const s of result.sitemaps) {
|
|
591
|
+
const submitted = sitemapSubmittedUrlTotal(s.contents);
|
|
592
|
+
const isIndex = s.isSitemapsIndex ? " [index]" : "";
|
|
593
|
+
console.log(` ${s.path}${isIndex}`);
|
|
594
|
+
console.log(` Submitted URLs: ${submitted} | Last submitted: ${s.lastSubmitted ?? "unknown"}`);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function sitemapSubmittedUrlTotal(contents) {
|
|
598
|
+
if (!contents?.length) return "?";
|
|
599
|
+
return contents.reduce((total, content) => total + (Number.parseInt(content.submitted, 10) || 0), 0);
|
|
600
|
+
}
|
|
601
|
+
async function submitGscSitemaps(client, project, opts) {
|
|
602
|
+
const explicitUrls = dedupeGscSitemapUrls(opts.sitemapUrls ?? []);
|
|
603
|
+
const modes = Number(explicitUrls.length > 0) + Number(Boolean(opts.configured)) + Number(Boolean(opts.all)) + Number(Boolean(opts.allFiles));
|
|
604
|
+
if (modes !== 1) {
|
|
605
|
+
throw new CliError({
|
|
606
|
+
code: "CLI_USAGE_ERROR",
|
|
607
|
+
message: "provide sitemap URL(s), --configured, --all, or --all-files (exactly one)",
|
|
608
|
+
displayMessage: "Error: provide sitemap URL(s), --configured, --all, or --all-files (exactly one)",
|
|
609
|
+
details: { command: "google.submit-sitemap" }
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
if (explicitUrls.length > 50) {
|
|
613
|
+
throw new CliError({
|
|
614
|
+
code: "CLI_USAGE_ERROR",
|
|
615
|
+
message: "explicit sitemap URL submissions support at most 50 URLs; split the URLs into groups of 50 or use --all/--all-files for discovered sitemaps",
|
|
616
|
+
displayMessage: "Error: explicit sitemap URL submissions support at most 50 URLs; split the URLs into groups of 50 or use --all/--all-files for discovered sitemaps",
|
|
617
|
+
details: { command: "google.submit-sitemap", sitemapUrls: explicitUrls.length, maxSitemapUrls: 50 }
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
let sitemapUrls = explicitUrls;
|
|
621
|
+
if (opts.configured) {
|
|
622
|
+
const connections = await client.googleConnections(project);
|
|
623
|
+
const sitemapUrl = connections.find((connection) => connection.connectionType === "gsc")?.sitemapUrl;
|
|
624
|
+
if (!sitemapUrl || !sitemapUrl.trim()) {
|
|
625
|
+
throw new CliError({
|
|
626
|
+
code: "CLI_USAGE_ERROR",
|
|
627
|
+
message: "no configured GSC sitemap URL found; use a URL, --all, or --all-files",
|
|
628
|
+
displayMessage: "Error: no configured GSC sitemap URL found; use a URL, --all, or --all-files",
|
|
629
|
+
details: { command: "google.submit-sitemap", project }
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
sitemapUrls = dedupeGscSitemapUrls([sitemapUrl]);
|
|
633
|
+
} else if (opts.all || opts.allFiles) {
|
|
634
|
+
sitemapUrls = await resolveDiscoveredGscSitemapUrls(
|
|
635
|
+
client,
|
|
636
|
+
project,
|
|
637
|
+
opts.allFiles ? "all-files" : "indexes"
|
|
638
|
+
);
|
|
639
|
+
requireGscSitemapUrls(project, sitemapUrls);
|
|
640
|
+
}
|
|
641
|
+
return submitGscSitemapBatches(client, project, sitemapUrls, opts);
|
|
642
|
+
}
|
|
643
|
+
async function googleSubmitSitemaps(project, opts) {
|
|
644
|
+
const client = getClient();
|
|
645
|
+
const result = await submitGscSitemaps(client, project, {
|
|
646
|
+
...opts,
|
|
647
|
+
onProgress: !isMachineFormat(opts.format) && (opts.all || opts.allFiles) ? (completedBatches, totalBatches) => process.stderr.write(`Submitted sitemap batch ${completedBatches}/${totalBatches}
|
|
648
|
+
`) : void 0
|
|
649
|
+
});
|
|
650
|
+
if (opts.format === "json") {
|
|
651
|
+
console.log(JSON.stringify(result, null, 2));
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
if (opts.format === "jsonl") {
|
|
655
|
+
emitJsonl(result.results.map((entry) => ({ project, ...entry })));
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
for (const entry of result.results) {
|
|
659
|
+
if (entry.status === "accepted") {
|
|
660
|
+
console.log(`Accepted by Google for sitemap refetch: ${entry.sitemapUrl}`);
|
|
661
|
+
if (entry.submittedAt) console.log(` Submitted at: ${entry.submittedAt}`);
|
|
662
|
+
} else {
|
|
663
|
+
console.error(`Failed to submit sitemap: ${entry.sitemapUrl}`);
|
|
664
|
+
if (entry.error) console.error(` Error: ${entry.error}`);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
console.log(`Summary: ${result.summary.accepted} accepted, ${result.summary.failed} failed (${result.summary.total} total)`);
|
|
668
|
+
console.log("Google accepting a sitemap for refetch does not guarantee indexing.");
|
|
669
|
+
}
|
|
670
|
+
async function googleInspectSitemap(project, opts) {
|
|
671
|
+
const client = getClient();
|
|
672
|
+
const run = await client.gscInspectSitemap(project, {
|
|
673
|
+
sitemapUrl: opts.sitemapUrl
|
|
674
|
+
});
|
|
675
|
+
if (!opts.wait && isMachineFormat(opts.format)) {
|
|
676
|
+
console.log(JSON.stringify(run, null, 2));
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
if (!isMachineFormat(opts.format)) {
|
|
680
|
+
console.log(`Sitemap inspection started (run ${run.id})`);
|
|
681
|
+
}
|
|
682
|
+
if (opts.wait) {
|
|
683
|
+
const current = await waitForRunStatus(client, run.id, {
|
|
684
|
+
timeoutMs: 30 * 60 * 1e3,
|
|
685
|
+
intervalMs: 3e3,
|
|
686
|
+
progressLabel: "Waiting for sitemap inspection to complete",
|
|
687
|
+
successStatuses: ["completed", "partial"],
|
|
688
|
+
failureStatuses: ["failed"],
|
|
689
|
+
timeoutCode: "GOOGLE_INSPECT_SITEMAP_TIMEOUT",
|
|
690
|
+
failureCode: "GOOGLE_INSPECT_SITEMAP_FAILED",
|
|
691
|
+
timeoutMessage: "Timed out waiting for sitemap inspection to complete.",
|
|
692
|
+
failureMessage: "Sitemap inspection failed.",
|
|
693
|
+
details: { project }
|
|
694
|
+
});
|
|
695
|
+
if (isMachineFormat(opts.format)) {
|
|
696
|
+
console.log(JSON.stringify({ ...run, status: current.status }, null, 2));
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
if (current.status === "partial") {
|
|
700
|
+
console.log("Sitemap inspection completed with some errors.");
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
console.log("Sitemap inspection completed successfully.");
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
async function googleCoverageHistory(project, opts) {
|
|
707
|
+
const client = getClient();
|
|
708
|
+
const rows = await client.gscCoverageHistory(project, { limit: opts.limit });
|
|
709
|
+
if (opts.format === "json") {
|
|
710
|
+
console.log(JSON.stringify(rows, null, 2));
|
|
711
|
+
return;
|
|
712
|
+
} else if (opts.format === "jsonl") {
|
|
713
|
+
emitJsonl(rows.map((row) => ({ project, ...row })));
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
if (rows.length === 0) {
|
|
717
|
+
console.log("No coverage history found. Run a GSC sync or sitemap inspection first.");
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
console.log(`
|
|
721
|
+
GSC Coverage History for "${project}" (${rows.length} snapshots):
|
|
722
|
+
`);
|
|
723
|
+
console.log(` ${"DATE".padEnd(12)}${"INDEXED".padEnd(10)}${"NOT INDEXED".padEnd(14)}TOP REASON`);
|
|
724
|
+
console.log(` ${"\u2500".repeat(12)}${"\u2500".repeat(10)}${"\u2500".repeat(14)}${"\u2500".repeat(30)}`);
|
|
725
|
+
for (const row of rows) {
|
|
726
|
+
const topReason = Object.entries(row.reasonBreakdown).sort((a, b) => b[1] - a[1])[0];
|
|
727
|
+
const reasonStr = topReason ? `${topReason[0]} (${topReason[1]})` : "-";
|
|
728
|
+
console.log(` ${row.date.padEnd(12)}${String(row.indexed).padEnd(10)}${String(row.notIndexed).padEnd(14)}${reasonStr}`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
async function googleDiscoverSitemaps(project, opts) {
|
|
732
|
+
const client = getClient();
|
|
733
|
+
const result = await client.gscDiscoverSitemaps(project);
|
|
734
|
+
if (!opts.wait && isMachineFormat(opts.format)) {
|
|
735
|
+
console.log(JSON.stringify(result, null, 2));
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
if (!isMachineFormat(opts.format)) {
|
|
739
|
+
console.log(`
|
|
740
|
+
Discovered ${result.sitemaps.length} sitemap(s) for project "${project}":
|
|
741
|
+
`);
|
|
742
|
+
for (const s of result.sitemaps) {
|
|
743
|
+
const primary = s.path === result.primarySitemapUrl ? " (primary)" : "";
|
|
744
|
+
const submitted = sitemapSubmittedUrlTotal(s.contents);
|
|
745
|
+
console.log(` ${s.path}${primary}`);
|
|
746
|
+
console.log(` Submitted URLs: ${submitted} | Last submitted: ${s.lastSubmitted ?? "unknown"}`);
|
|
747
|
+
}
|
|
748
|
+
console.log(`
|
|
749
|
+
Primary sitemap: ${result.primarySitemapUrl}`);
|
|
750
|
+
console.log(`Sitemap URL saved. Inspection run queued (run ${result.run.id}).`);
|
|
751
|
+
}
|
|
752
|
+
if (opts.wait) {
|
|
753
|
+
const current = await waitForRunStatus(client, result.run.id, {
|
|
754
|
+
timeoutMs: 30 * 60 * 1e3,
|
|
755
|
+
intervalMs: 3e3,
|
|
756
|
+
progressLabel: "Waiting for sitemap inspection to complete",
|
|
757
|
+
successStatuses: ["completed", "partial"],
|
|
758
|
+
failureStatuses: ["failed"],
|
|
759
|
+
timeoutCode: "GOOGLE_DISCOVER_SITEMAPS_TIMEOUT",
|
|
760
|
+
failureCode: "GOOGLE_DISCOVER_SITEMAPS_FAILED",
|
|
761
|
+
timeoutMessage: "Timed out waiting for sitemap inspection to complete.",
|
|
762
|
+
failureMessage: "Sitemap inspection failed.",
|
|
763
|
+
details: { project }
|
|
764
|
+
});
|
|
765
|
+
if (isMachineFormat(opts.format)) {
|
|
766
|
+
console.log(JSON.stringify({
|
|
767
|
+
...result,
|
|
768
|
+
run: {
|
|
769
|
+
...result.run,
|
|
770
|
+
status: current.status
|
|
771
|
+
}
|
|
772
|
+
}, null, 2));
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (current.status === "partial") {
|
|
776
|
+
console.log("Sitemap inspection completed with some errors.");
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
console.log("Sitemap inspection completed successfully.");
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
async function googleRequestIndexing(project, opts) {
|
|
783
|
+
const client = getClient();
|
|
784
|
+
const body = { urls: [] };
|
|
785
|
+
if (opts.allUnindexed) {
|
|
786
|
+
body.allUnindexed = true;
|
|
787
|
+
} else if (opts.url) {
|
|
788
|
+
body.urls = [opts.url];
|
|
789
|
+
} else {
|
|
790
|
+
throw new CliError({
|
|
791
|
+
code: "CLI_USAGE_ERROR",
|
|
792
|
+
message: "provide a URL or use --all-unindexed",
|
|
793
|
+
displayMessage: "Error: provide a URL or use --all-unindexed",
|
|
794
|
+
details: { command: "google.request-indexing" }
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
if (!isMachineFormat(opts.format)) {
|
|
798
|
+
console.error(INDEXING_API_SCOPE_NOTICE);
|
|
799
|
+
console.error();
|
|
800
|
+
}
|
|
801
|
+
const result = await client.googleRequestIndexing(project, body);
|
|
802
|
+
let indexingConfirmed = false;
|
|
803
|
+
const lastInspection = /* @__PURE__ */ new Map();
|
|
804
|
+
if (opts.wait && result.results.some((r) => r.status === "success")) {
|
|
805
|
+
const successUrls = result.results.filter((r) => r.status === "success").map((r) => r.url);
|
|
806
|
+
const timeout = opts.waitTimeoutMs ?? 10 * 60 * 1e3;
|
|
807
|
+
const pollInterval = opts.waitPollIntervalMs ?? 1e4;
|
|
808
|
+
const start = Date.now();
|
|
809
|
+
process.stderr.write("Polling URL Inspection for indexed verdict");
|
|
810
|
+
while (Date.now() - start < timeout) {
|
|
811
|
+
await new Promise((r) => setTimeout(r, pollInterval));
|
|
812
|
+
process.stderr.write(".");
|
|
813
|
+
let allIndexed = true;
|
|
814
|
+
for (const url of successUrls) {
|
|
815
|
+
try {
|
|
816
|
+
const inspection = await client.gscInspect(project, url);
|
|
817
|
+
lastInspection.set(url, inspection);
|
|
818
|
+
if (inspection.verdict !== "PASS") {
|
|
819
|
+
allIndexed = false;
|
|
820
|
+
}
|
|
821
|
+
} catch {
|
|
822
|
+
allIndexed = false;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (allIndexed) {
|
|
826
|
+
process.stderr.write("\n");
|
|
827
|
+
indexingConfirmed = true;
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (!indexingConfirmed) {
|
|
832
|
+
process.stderr.write("\n");
|
|
833
|
+
const observed = successUrls.map((url) => {
|
|
834
|
+
const i = lastInspection.get(url);
|
|
835
|
+
return {
|
|
836
|
+
url,
|
|
837
|
+
verdict: i?.verdict ?? null,
|
|
838
|
+
coverageState: i?.coverageState ?? null,
|
|
839
|
+
indexingState: i?.indexingState ?? null
|
|
840
|
+
};
|
|
841
|
+
});
|
|
842
|
+
throw new CliError({
|
|
843
|
+
code: "GOOGLE_INDEXING_CONFIRMATION_TIMEOUT",
|
|
844
|
+
message: "Timed out waiting for Google to report verdict=PASS. Google typically takes hours to days to index new URLs, so this is expected and does not mean the submission failed. Re-check later with `canonry google gsc inspect <url>`.",
|
|
845
|
+
displayMessage: "Timed out waiting for Google to report verdict=PASS. Google typically takes hours to days to index new URLs \u2014 this is not a failure. Re-check later with `canonry google gsc inspect <url>`.",
|
|
846
|
+
details: {
|
|
847
|
+
project,
|
|
848
|
+
urls: successUrls,
|
|
849
|
+
lastObserved: observed
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
if (isMachineFormat(opts.format)) {
|
|
855
|
+
console.log(JSON.stringify({ ...result, ...opts.wait ? { indexingConfirmed } : {} }, null, 2));
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
for (const r of result.results) {
|
|
859
|
+
if (r.status === "success") {
|
|
860
|
+
console.log(`Indexing requested: ${r.url}`);
|
|
861
|
+
console.log(` Notified at: ${r.notifiedAt}`);
|
|
862
|
+
console.log(` Type: ${r.type}`);
|
|
863
|
+
console.log();
|
|
864
|
+
} else {
|
|
865
|
+
console.error(`Failed: ${r.url}`);
|
|
866
|
+
console.error(` Error: ${r.error}`);
|
|
867
|
+
console.log();
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
if (result.results.length > 1) {
|
|
871
|
+
console.log(`Summary: ${result.summary.succeeded} succeeded, ${result.summary.failed} failed (${result.summary.total} total)`);
|
|
872
|
+
}
|
|
873
|
+
if (indexingConfirmed) {
|
|
874
|
+
console.log("URL Inspection now reports verdict=PASS for the requested URLs (indexed in Google Search).");
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
async function googleRefresh(project, format) {
|
|
878
|
+
const client = getClient();
|
|
879
|
+
const run = await client.gscSync(project, {});
|
|
880
|
+
if (!isMachineFormat(format)) {
|
|
881
|
+
process.stderr.write("Refreshing GSC coverage data");
|
|
882
|
+
}
|
|
883
|
+
const current = await waitForRunStatus(client, run.id, {
|
|
884
|
+
timeoutMs: 10 * 60 * 1e3,
|
|
885
|
+
intervalMs: 2e3,
|
|
886
|
+
progressLabel: "",
|
|
887
|
+
successStatuses: ["completed", "partial"],
|
|
888
|
+
failureStatuses: ["failed"],
|
|
889
|
+
timeoutCode: "GOOGLE_REFRESH_TIMEOUT",
|
|
890
|
+
failureCode: "GOOGLE_REFRESH_FAILED",
|
|
891
|
+
timeoutMessage: "Timed out waiting for GSC refresh to complete.",
|
|
892
|
+
failureMessage: "GSC refresh failed.",
|
|
893
|
+
details: { project }
|
|
894
|
+
});
|
|
895
|
+
if (current.status === "partial" && !isMachineFormat(format)) {
|
|
896
|
+
process.stderr.write("Refresh completed with some errors.\n");
|
|
897
|
+
}
|
|
898
|
+
await googleCoverage(project, format);
|
|
899
|
+
}
|
|
900
|
+
async function googleDeindexed(project, format) {
|
|
901
|
+
const client = getClient();
|
|
902
|
+
const rows = await client.gscDeindexed(project);
|
|
903
|
+
if (format === "json") {
|
|
904
|
+
console.log(JSON.stringify(rows, null, 2));
|
|
905
|
+
return;
|
|
906
|
+
} else if (format === "jsonl") {
|
|
907
|
+
emitJsonl(rows.map((row) => ({ project, ...row })));
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
if (rows.length === 0) {
|
|
911
|
+
console.log("No deindexed pages detected.");
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
console.log(`Deindexed pages (${rows.length}):
|
|
915
|
+
`);
|
|
916
|
+
for (const row of rows) {
|
|
917
|
+
console.log(` ${row.url}`);
|
|
918
|
+
console.log(` ${row.previousState} -> ${row.currentState} (detected: ${row.transitionDate})`);
|
|
919
|
+
console.log();
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
export {
|
|
923
|
+
googleConnect,
|
|
924
|
+
googleCoverage,
|
|
925
|
+
googleCoverageHistory,
|
|
926
|
+
googleDeindexed,
|
|
927
|
+
googleDisconnect,
|
|
928
|
+
googleDiscoverSitemaps,
|
|
929
|
+
googleInspect,
|
|
930
|
+
googleInspectSitemap,
|
|
931
|
+
googleInspections,
|
|
932
|
+
googleListSitemaps,
|
|
933
|
+
googlePerformance,
|
|
934
|
+
googlePerformanceDaily,
|
|
935
|
+
googleProperties,
|
|
936
|
+
googleQueryTotals,
|
|
937
|
+
googleRefresh,
|
|
938
|
+
googleRequestIndexing,
|
|
939
|
+
googleSetProperty,
|
|
940
|
+
googleSetSitemap,
|
|
941
|
+
googleStatus,
|
|
942
|
+
googleSubmitSitemaps,
|
|
943
|
+
googleSync,
|
|
944
|
+
googleTopPages,
|
|
945
|
+
submitGscSitemaps
|
|
946
|
+
};
|