@canonry/canonry 7.51.5 → 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.
Files changed (116) hide show
  1. package/dist/ads-ABAT3K4K.js +544 -0
  2. package/dist/agent-5G4DRLYX.js +70 -0
  3. package/dist/agent-ask-UDVCZRO7.js +139 -0
  4. package/dist/agent-conversations-5E4JP2QZ.js +52 -0
  5. package/dist/agent-memory-7IIJ4HGZ.js +92 -0
  6. package/dist/agent-providers-BOXPUXZ4.js +55 -0
  7. package/dist/agent-transcript-4O56G6PQ.js +77 -0
  8. package/dist/analytics-PKMWX5XL.js +240 -0
  9. package/dist/apply-OK4XEBDA.js +175 -0
  10. package/dist/backfill-2OT56CX2.js +41 -0
  11. package/dist/backlinks-547WCHND.js +303 -0
  12. package/dist/bing-ZVBV4ZD5.js +418 -0
  13. package/dist/bootstrap-HUB7XQ73.js +326 -0
  14. package/dist/cdp-KQKQ4PWJ.js +162 -0
  15. package/dist/chunk-2G6IP3MO.js +517 -0
  16. package/dist/chunk-42D2LE2B.js +1273 -0
  17. package/dist/chunk-4MJYGB56.js +124 -0
  18. package/dist/chunk-63ISSSGX.js +9150 -0
  19. package/dist/{chunk-PLYJX67A.js → chunk-6G6FTDWC.js} +8080 -13939
  20. package/dist/chunk-6GO5VVAC.js +15 -0
  21. package/dist/{chunk-4YCGZGA3.js → chunk-73P65KPW.js} +2 -2
  22. package/dist/chunk-7B2Q4NJE.js +133 -0
  23. package/dist/{chunk-JBZZEIM2.js → chunk-7WZ2FPB4.js} +2 -13
  24. package/dist/chunk-AOJU5LKX.js +8 -0
  25. package/dist/chunk-B2FR2ZQ4.js +420 -0
  26. package/dist/{chunk-HAHXPJQ5.js → chunk-B5J675KK.js} +16 -1684
  27. package/dist/{chunk-SFMWHPMX.js → chunk-D6COIM3U.js} +17128 -17143
  28. package/dist/{chunk-A3WSAAQS.js → chunk-DGVUTH7W.js} +9086 -34522
  29. package/dist/chunk-ELCLGWUT.js +83 -0
  30. package/dist/chunk-GO2J7SYT.js +1034 -0
  31. package/dist/chunk-HACZUMGM.js +145 -0
  32. package/dist/chunk-HM4NNKLG.js +94 -0
  33. package/dist/chunk-I3A56PFP.js +58 -0
  34. package/dist/chunk-I77PLCWG.js +961 -0
  35. package/dist/chunk-ISOQPVPY.js +232 -0
  36. package/dist/chunk-KFT5LOP2.js +610 -0
  37. package/dist/chunk-MLKGABMK.js +9 -0
  38. package/dist/chunk-MMEO22MF.js +38 -0
  39. package/dist/chunk-NHQ2U5I4.js +78 -0
  40. package/dist/chunk-PCXRFT3N.js +530 -0
  41. package/dist/chunk-PITHTCAX.js +15376 -0
  42. package/dist/chunk-QWKPSFGL.js +30 -0
  43. package/dist/chunk-RKIXES2B.js +609 -0
  44. package/dist/chunk-TSENU4GG.js +18 -0
  45. package/dist/{chunk-HLVEB5TB.js → chunk-TUTKNUMV.js} +7 -5
  46. package/dist/chunk-U3AHE2RT.js +1160 -0
  47. package/dist/chunk-UQ3MOZGC.js +644 -0
  48. package/dist/{chunk-AZFPA7JV.js → chunk-VBCE4CLX.js} +6 -4
  49. package/dist/chunk-VJWDBFSL.js +69 -0
  50. package/dist/chunk-VYMZ3QXG.js +8264 -0
  51. package/dist/chunk-WAULJDKO.js +2686 -0
  52. package/dist/chunk-WDFI5YMD.js +204 -0
  53. package/dist/chunk-XEBKF4N5.js +8 -0
  54. package/dist/chunk-Z7IUAJOF.js +13 -0
  55. package/dist/{chunk-KEATAHXH.js → chunk-ZWJRY5UI.js} +358 -581
  56. package/dist/chunk-ZXUAWVWM.js +15 -0
  57. package/dist/citations-UYB2RU5U.js +106 -0
  58. package/dist/{cli-catalog-MO6Z2CIZ.js → cli-catalog-F6FI7NB2.js} +5 -3
  59. package/dist/cli-commands-ZG5ILKDA.js +19 -0
  60. package/dist/cli.js +35 -29
  61. package/dist/competitor-EKP4R7YY.js +561 -0
  62. package/dist/content-DREE6JF3.js +257 -0
  63. package/dist/dashboard-ZALEOLLU.js +71 -0
  64. package/dist/demo-JG4Y22O4.js +75 -0
  65. package/dist/{demo-server-GIWDJGJX.js → demo-server-3A4J2C65.js} +22 -9
  66. package/dist/discover-W6GMD2HS.js +372 -0
  67. package/dist/discover-eval-CKFZHRBW.js +282 -0
  68. package/dist/doctor-TNGBSUMA.js +152 -0
  69. package/dist/evidence-3H2GFQBZ.js +57 -0
  70. package/dist/export-cmd-WUIKU5GK.js +49 -0
  71. package/dist/ga-JI6REFO4.js +911 -0
  72. package/dist/gbp-4ENDM5NS.js +370 -0
  73. package/dist/google-HKQSCLOC.js +946 -0
  74. package/dist/google-marketing-KQR5J2S4.js +403 -0
  75. package/dist/health-cmd-TS7EMMCS.js +64 -0
  76. package/dist/history-MSD5DK6K.js +90 -0
  77. package/dist/index.d.ts +47 -47
  78. package/dist/index.js +29 -6
  79. package/dist/init-L6WAEOWX.js +432 -0
  80. package/dist/insights-RTZ3IZTD.js +63 -0
  81. package/dist/intelligence-service-TH52PCNJ.js +15 -0
  82. package/dist/keys-625DZBRM.js +116 -0
  83. package/dist/keyword-CW46RNRR.js +164 -0
  84. package/dist/logs-V33SHBIW.js +30 -0
  85. package/dist/mcp-DFEDPSEG.js +14 -0
  86. package/dist/mcp.js +14 -5
  87. package/dist/measurement-plan-6W37RUOP.js +42 -0
  88. package/dist/notify-DSUOT7WO.js +125 -0
  89. package/dist/organic-evidence-BMN6L4OB.js +53 -0
  90. package/dist/overview-WRRMBZ6S.js +213 -0
  91. package/dist/project-2GJIU3FE.js +460 -0
  92. package/dist/query-3XPMGJUA.js +211 -0
  93. package/dist/research-V433CKJ4.js +200 -0
  94. package/dist/results-export-RGBU7QQQ.js +27 -0
  95. package/dist/run-NIAC6OJN.js +31 -0
  96. package/dist/schedule-KDWXRIE7.js +177 -0
  97. package/dist/search-626MPUJN.js +42 -0
  98. package/dist/serve-73SMMASI.js +557 -0
  99. package/dist/session-7WWOETZB.js +47 -0
  100. package/dist/settings-VKFQO6F2.js +107 -0
  101. package/dist/skills-5HC5H7TE.js +33 -0
  102. package/dist/snapshot-BSJUHFBC.js +538 -0
  103. package/dist/src-F6HM73TN.js +316 -0
  104. package/dist/status-V4OWP7LZ.js +126 -0
  105. package/dist/support-ARF4HER7.js +24 -0
  106. package/dist/technical-aeo-TG7CGU3F.js +625 -0
  107. package/dist/telemetry-O2IUNUBW.js +118 -0
  108. package/dist/tools-2GJIDKND.js +41 -0
  109. package/dist/traffic-XV4I3UPH.js +1295 -0
  110. package/dist/users-VGBLDL5K.js +170 -0
  111. package/dist/visibility-stats-UKJYJ6PP.js +241 -0
  112. package/dist/wordpress-JZA7CGC6.js +600 -0
  113. package/package.json +1 -1
  114. package/dist/chunk-4QQYYRHV.js +0 -23082
  115. package/dist/cli-commands-FOJR3HHU.js +0 -15
  116. package/dist/intelligence-service-XQCNWAPL.js +0 -9
@@ -0,0 +1,403 @@
1
+ import {
2
+ emitJsonl
3
+ } from "./chunk-Z7IUAJOF.js";
4
+ import {
5
+ CliError,
6
+ isMachineFormat
7
+ } from "./chunk-HGMYEDAQ.js";
8
+ import {
9
+ canonicalizeGtmAccountId,
10
+ canonicalizeGtmResourceSelection,
11
+ conversionTrackingContractWriteRequestSchema,
12
+ describeError,
13
+ formatMicros,
14
+ formatPercent
15
+ } from "./chunk-D6COIM3U.js";
16
+ import "./chunk-MLKGABMK.js";
17
+
18
+ // src/commands/google-marketing.ts
19
+ import fs from "fs";
20
+ function printMachine(value, format) {
21
+ if (!isMachineFormat(format)) return false;
22
+ console.log(JSON.stringify(value, null, 2));
23
+ return true;
24
+ }
25
+ function connectionSummary(status) {
26
+ if (!status.connected) return "not connected";
27
+ if (status.status === "selection-required") return "connected; selection required";
28
+ return status.status === "stale" ? "connected; stored evidence is stale" : "connected";
29
+ }
30
+ function snapshotSummary(snapshot) {
31
+ return `${snapshot.capturedAt} ${snapshot.kind.padEnd(22)} ${snapshot.id} ${snapshot.payloadChecksum.slice(0, 12)}`;
32
+ }
33
+ function canonicalGtmReadAccountId(accountId) {
34
+ const canonical = canonicalizeGtmAccountId(accountId);
35
+ if (canonical) return canonical;
36
+ throw new CliError({
37
+ code: "GTM_RESOURCE_INPUT_INVALID",
38
+ message: "GTM account must be a safe bare ID or an accounts/{id} resource path.",
39
+ displayMessage: "Error: GTM account must be a safe bare ID or an accounts/{id} resource path."
40
+ });
41
+ }
42
+ function canonicalGtmReadSelection(accountId, containerId) {
43
+ const canonical = canonicalizeGtmResourceSelection({ accountId, containerId });
44
+ if (canonical) return canonical;
45
+ throw new CliError({
46
+ code: "GTM_RESOURCE_INPUT_INVALID",
47
+ message: "GTM account and container must be matching safe IDs or resource paths.",
48
+ displayMessage: "Error: GTM account and container must be matching safe IDs or resource paths."
49
+ });
50
+ }
51
+ function readConversionTrackingContractInput(inputPath) {
52
+ if (!inputPath) {
53
+ throw new CliError({
54
+ code: "CONVERSION_TRACKING_INPUT_REQUIRED",
55
+ message: "A conversion-tracking contract JSON input file is required",
56
+ displayMessage: "Error: --input <json-file> is required (use --input - for stdin)"
57
+ });
58
+ }
59
+ try {
60
+ const raw = fs.readFileSync(inputPath === "-" ? 0 : inputPath, "utf8");
61
+ return conversionTrackingContractWriteRequestSchema.parse(JSON.parse(raw));
62
+ } catch (err) {
63
+ const message = describeError(err);
64
+ throw new CliError({
65
+ code: "CONVERSION_TRACKING_INPUT_INVALID",
66
+ message,
67
+ displayMessage: `Error: invalid conversion-tracking contract input (${message})`,
68
+ details: { inputPath }
69
+ });
70
+ }
71
+ }
72
+ async function googleAdsDisconnect(client, project, opts) {
73
+ const result = await client.disconnectGoogleAds(project);
74
+ if (printMachine(result, opts.format)) return;
75
+ console.log(result.disconnected ? `Disconnected Google Ads from project "${project}". Stored redacted evidence was retained.` : `Google Ads was not connected to project "${project}".`);
76
+ }
77
+ async function gtmDisconnect(client, project, opts) {
78
+ const result = await client.disconnectGtm(project);
79
+ if (printMachine(result, opts.format)) return;
80
+ console.log(result.disconnected ? `Disconnected Google Tag Manager from project "${project}". Stored redacted evidence was retained.` : `Google Tag Manager was not connected to project "${project}".`);
81
+ }
82
+ async function googleAdsStatus(client, project, opts) {
83
+ const result = await client.getGoogleAdsStatus(project);
84
+ if (printMachine(result, opts.format)) return;
85
+ console.log(`Google Ads: ${connectionSummary(result)}`);
86
+ if (!result.connected) {
87
+ console.log(`Open project "${project}" in the Canonry dashboard to authorize Google Ads.`);
88
+ return;
89
+ }
90
+ const selection = result.connection.selection;
91
+ console.log(`Customer: ${selection.customerId ?? "not selected"}`);
92
+ if (selection.loginCustomerId) console.log(`Login customer: ${selection.loginCustomerId}`);
93
+ if (result.selectedCustomer) {
94
+ console.log(`Selected: ${result.selectedCustomer.descriptiveName ?? result.selectedCustomer.customerId} (${result.selectedCustomer.status})`);
95
+ }
96
+ console.log(`Last inventory snapshot: ${result.connection.lastInventorySnapshotAt ?? "none"}`);
97
+ console.log(`Last metrics snapshot: ${result.connection.lastMetricsSnapshotAt ?? "none"}`);
98
+ }
99
+ async function gtmStatus(client, project, opts) {
100
+ const result = await client.getGtmStatus(project);
101
+ if (printMachine(result, opts.format)) return;
102
+ console.log(`Google Tag Manager: ${connectionSummary(result)}`);
103
+ if (!result.connected) {
104
+ console.log(`Open project "${project}" in the Canonry dashboard to authorize Google Tag Manager.`);
105
+ return;
106
+ }
107
+ console.log(`Account: ${result.selection.accountId ?? "not selected"}`);
108
+ console.log(`Container: ${result.selection.containerId ?? "not selected"}`);
109
+ console.log(`Workspace: ${result.selection.workspaceId ?? "none (live only)"}`);
110
+ console.log(`Last snapshot: ${result.connection.lastSnapshotAt ?? "none"}`);
111
+ }
112
+ async function googleAdsCustomers(client, project, opts) {
113
+ const result = await client.listGoogleAdsCustomers(project);
114
+ if (opts.format === "jsonl") {
115
+ emitJsonl(result.customers.map((customer) => ({ project, fetchedAt: result.fetchedAt, ...customer })));
116
+ return;
117
+ }
118
+ if (printMachine(result, opts.format)) return;
119
+ if (result.customers.length === 0) {
120
+ console.log("No Google Ads customers are visible to this OAuth connection.");
121
+ return;
122
+ }
123
+ console.log(`${result.totalAccessible} accessible customer(s)${result.truncated ? " (bounded list; truncated)" : ""}:
124
+ `);
125
+ for (const customer of result.customers) {
126
+ const role = customer.manager ? "manager" : "client";
127
+ const name = customer.descriptiveName ?? "(unnamed)";
128
+ console.log(` ${customer.customerId.padEnd(16)} ${name} ${role}, ${customer.status}`);
129
+ }
130
+ console.log(`
131
+ Select one with: canonry google-ads select ${project} --customer <customer-id>`);
132
+ }
133
+ async function googleAdsSelect(client, project, request, opts) {
134
+ const result = await client.setGoogleAdsSelection(project, request);
135
+ if (printMachine(result, opts.format)) return;
136
+ console.log(`Selected Google Ads customer ${request.customerId}${request.loginCustomerId ? ` through login customer ${request.loginCustomerId}` : ""}.`);
137
+ console.log(`Run \`canonry google-ads sync ${project}\` to capture read-only conversion and goal evidence.`);
138
+ }
139
+ async function googleAdsSync(client, project, opts) {
140
+ const run = await client.triggerGoogleAdsSync(project);
141
+ if (printMachine(run, opts.format)) return;
142
+ console.log(`Google Ads read-only sync queued (run ${run.id}). Use \`canonry run show ${run.id}\` to check it.`);
143
+ }
144
+ function performanceMicros(micros, currencyCode) {
145
+ if (micros === null) return "\u2014";
146
+ if (currencyCode === null) return (micros / 1e6).toFixed(2);
147
+ return formatMicros(micros, currencyCode);
148
+ }
149
+ function performanceChange(ratio) {
150
+ if (ratio === null) return "";
151
+ const sign = ratio > 0 ? "+" : "";
152
+ return ` (${sign}${formatPercent(ratio)} vs prior period)`;
153
+ }
154
+ async function googleAdsPerformance(client, project, opts) {
155
+ const result = await client.getGoogleAdsPerformance(project, opts.window ? { window: opts.window } : {});
156
+ if (printMachine(result, opts.format)) return;
157
+ if (!result.source) {
158
+ console.log(`No stored Google Ads metrics for project "${project}".`);
159
+ console.log(`Run \`canonry google-ads sync ${project}\` after selecting a customer.`);
160
+ return;
161
+ }
162
+ const currency = result.source.currencyCode;
163
+ const { totals, comparison } = result;
164
+ console.log(`Window: ${result.startDate} \u2192 ${result.endDate} (${result.days} closed day(s), ${result.window})`);
165
+ console.log(`As of: ${result.source.asOfDate}${result.source.openDate ? ` (${result.source.openDate} still open, excluded)` : ""}`);
166
+ console.log(`Account: ${result.source.customerId} (${currency ?? "?"}, ${result.source.timeZone ?? "unknown zone"})`);
167
+ console.log(`Impressions: ${totals.impressions}${performanceChange(comparison?.change.impressions ?? null)}`);
168
+ console.log(`Clicks: ${totals.clicks} (CTR ${formatPercent(totals.ctr)})${performanceChange(comparison?.change.clicks ?? null)}`);
169
+ console.log(`Cost: ${performanceMicros(totals.costMicros, currency)} (CPC ${performanceMicros(totals.cpcMicros, currency)})${performanceChange(comparison?.change.costMicros ?? null)}`);
170
+ console.log(`Conversions: ${totals.conversions} (rate ${formatPercent(totals.conversionRate)}, cost/conv ${performanceMicros(totals.costPerConversionMicros, currency)})`);
171
+ if (!comparison) {
172
+ console.log(`Comparison: unavailable (${result.comparisonUnavailableReason ?? "unknown"})`);
173
+ }
174
+ if (result.source.campaignsInInventory > 0 && result.source.campaignsQueried < result.source.campaignsInInventory) {
175
+ console.log(`Coverage: ${result.source.campaignsQueried} of ${result.source.campaignsInInventory} campaigns; totals are a subset of the account.`);
176
+ }
177
+ if (result.source.truncated) {
178
+ console.log(`Note: the provider returned a bounded result, so these totals are a subset sum.`);
179
+ }
180
+ if (result.campaigns.length > 0) {
181
+ console.log(`
182
+ ${result.campaigns.length} campaign(s):
183
+ `);
184
+ for (const campaign of result.campaigns) {
185
+ const label = campaign.name ?? `(not in stored inventory: ${campaign.campaignId})`;
186
+ console.log(` ${label.padEnd(32).slice(0, 32)} ${campaign.status.padEnd(8)} ${String(campaign.totals.impressions).padStart(8)} impr ${String(campaign.totals.clicks).padStart(6)} clicks ${performanceMicros(campaign.totals.costMicros, currency).padStart(12)}`);
187
+ }
188
+ }
189
+ const filled = result.daily.filter((point) => point.origin === "filled").length;
190
+ if (filled > 0) {
191
+ console.log(`
192
+ ${filled} of ${result.daily.length} day(s) had no delivery and are reported as zero.`);
193
+ }
194
+ }
195
+ async function googleAdsSnapshots(client, project, opts) {
196
+ const result = await client.listGoogleAdsSnapshots(project, { limit: opts.limit, cursor: opts.cursor });
197
+ if (opts.format === "jsonl") {
198
+ emitJsonl(result.snapshots.map((snapshot) => ({ project, ...snapshot })));
199
+ return;
200
+ }
201
+ if (printMachine(result, opts.format)) return;
202
+ if (result.snapshots.length === 0) {
203
+ console.log(`No stored Google Ads snapshots. Run \`canonry google-ads sync ${project}\` after selecting a customer.`);
204
+ return;
205
+ }
206
+ console.log(`${result.total} stored Google Ads snapshot(s):
207
+ `);
208
+ for (const snapshot of result.snapshots) console.log(` ${snapshotSummary(snapshot)}`);
209
+ if (result.nextCursor) console.log(`
210
+ Next cursor: ${result.nextCursor}`);
211
+ }
212
+ async function googleAdsSnapshot(client, project, snapshotId, opts) {
213
+ const result = await client.getGoogleAdsSnapshot(project, snapshotId);
214
+ if (printMachine(result, opts.format)) return;
215
+ const { metadata, payload } = result.snapshot;
216
+ console.log(`Google Ads ${metadata.kind} snapshot ${metadata.id}`);
217
+ console.log(`Captured: ${metadata.capturedAt}`);
218
+ console.log(`Checksum: ${metadata.payloadChecksum}`);
219
+ console.log(`Payload kind: ${payload.kind}`);
220
+ }
221
+ async function gtmAccounts(client, project, opts) {
222
+ const result = await client.listGtmAccounts(project);
223
+ if (opts.format === "jsonl") {
224
+ emitJsonl(result.accounts.map((account) => ({ project, fetchedAt: result.fetchedAt, ...account })));
225
+ return;
226
+ }
227
+ if (printMachine(result, opts.format)) return;
228
+ if (result.accounts.length === 0) {
229
+ console.log("No GTM accounts are visible to this OAuth connection.");
230
+ return;
231
+ }
232
+ console.log(`${result.totalAccessible} accessible GTM account(s)${result.truncated ? " (bounded list; truncated)" : ""}:
233
+ `);
234
+ for (const account of result.accounts) console.log(` ${account.id.padEnd(16)} ${account.name}`);
235
+ console.log(`
236
+ Discover containers with: canonry gtm containers ${project} --account <account-id>`);
237
+ }
238
+ async function gtmContainers(client, project, accountId, opts) {
239
+ const canonicalAccountId = canonicalGtmReadAccountId(accountId);
240
+ const result = await client.listGtmContainers(project, canonicalAccountId);
241
+ if (opts.format === "jsonl") {
242
+ emitJsonl(result.containers.map((container) => ({ project, fetchedAt: result.fetchedAt, ...container })));
243
+ return;
244
+ }
245
+ if (printMachine(result, opts.format)) return;
246
+ if (result.containers.length === 0) {
247
+ console.log(`No GTM containers are visible under account ${accountId}.`);
248
+ return;
249
+ }
250
+ console.log(`${result.totalAccessible} GTM container(s)${result.truncated ? " (bounded list; truncated)" : ""}:
251
+ `);
252
+ for (const container of result.containers) {
253
+ const publicId = container.publicId ? ` (${container.publicId})` : "";
254
+ console.log(` ${container.id.padEnd(16)} ${container.name}${publicId}`);
255
+ }
256
+ console.log(`
257
+ Discover workspaces with: canonry gtm workspaces ${project} --account ${accountId} --container <container-id>`);
258
+ }
259
+ async function gtmWorkspaces(client, project, accountId, containerId, opts) {
260
+ const selection = canonicalGtmReadSelection(accountId, containerId);
261
+ const result = await client.listGtmWorkspaces(project, selection.accountId, selection.containerId);
262
+ if (opts.format === "jsonl") {
263
+ emitJsonl(result.workspaces.map((workspace) => ({ project, fetchedAt: result.fetchedAt, ...workspace })));
264
+ return;
265
+ }
266
+ if (printMachine(result, opts.format)) return;
267
+ if (result.workspaces.length === 0) {
268
+ console.log(`No GTM workspaces are visible for container ${containerId}. A sync can still capture the live container graph.`);
269
+ return;
270
+ }
271
+ console.log(`${result.totalAccessible} GTM workspace(s)${result.truncated ? " (bounded list; truncated)" : ""}:
272
+ `);
273
+ for (const workspace of result.workspaces) console.log(` ${workspace.id.padEnd(16)} ${workspace.name}`);
274
+ }
275
+ async function gtmSelect(client, project, request, opts) {
276
+ const result = await client.setGtmSelection(project, request);
277
+ if (printMachine(result, opts.format)) return;
278
+ console.log(`Selected GTM account ${request.accountId}, container ${request.containerId}${request.workspaceId ? `, and workspace ${request.workspaceId}` : ""}.`);
279
+ console.log(`Run \`canonry gtm sync ${project}\` to capture redacted live${request.workspaceId ? " and draft" : ""} evidence.`);
280
+ }
281
+ async function gtmSync(client, project, opts) {
282
+ const run = await client.triggerGtmSync(project);
283
+ if (printMachine(run, opts.format)) return;
284
+ console.log(`GTM read-only sync queued (run ${run.id}). Use \`canonry run show ${run.id}\` to check it.`);
285
+ }
286
+ async function gtmSnapshots(client, project, opts) {
287
+ const result = await client.listGtmSnapshots(project, { limit: opts.limit, cursor: opts.cursor });
288
+ if (opts.format === "jsonl") {
289
+ emitJsonl(result.snapshots.map((snapshot) => ({ project, ...snapshot })));
290
+ return;
291
+ }
292
+ if (printMachine(result, opts.format)) return;
293
+ if (result.snapshots.length === 0) {
294
+ console.log(`No stored GTM snapshots. Run \`canonry gtm sync ${project}\` after selecting a container.`);
295
+ return;
296
+ }
297
+ console.log(`${result.total} stored GTM snapshot(s):
298
+ `);
299
+ for (const snapshot of result.snapshots) console.log(` ${snapshotSummary(snapshot)}`);
300
+ if (result.nextCursor) console.log(`
301
+ Next cursor: ${result.nextCursor}`);
302
+ }
303
+ async function gtmSnapshot(client, project, snapshotId, opts) {
304
+ const result = await client.getGtmSnapshot(project, snapshotId);
305
+ if (printMachine(result, opts.format)) return;
306
+ const { metadata, payload } = result.snapshot;
307
+ console.log(`GTM ${metadata.kind} snapshot ${metadata.id}`);
308
+ console.log(`Captured: ${metadata.capturedAt}`);
309
+ console.log(`Checksum: ${metadata.payloadChecksum}`);
310
+ console.log(`Payload kind: ${payload.kind}`);
311
+ }
312
+ async function conversionTrackingContracts(client, project, opts) {
313
+ const contracts = await client.listConversionTrackingContracts(project);
314
+ if (opts.format === "jsonl") {
315
+ emitJsonl(contracts.map((contract) => ({ project, ...contract })));
316
+ return;
317
+ }
318
+ if (printMachine(contracts, opts.format)) return;
319
+ if (contracts.length === 0) {
320
+ console.log("No conversion-tracking contracts are declared for this project.");
321
+ return;
322
+ }
323
+ console.log(`${contracts.length} conversion-tracking contract(s):
324
+ `);
325
+ for (const contract of contracts) {
326
+ console.log(` ${contract.id.padEnd(16)} ${contract.name} event=${contract.eventName}`);
327
+ }
328
+ }
329
+ async function conversionTrackingContract(client, project, contractId, opts) {
330
+ const contract = await client.getConversionTrackingContract(project, contractId);
331
+ if (printMachine(contract, opts.format)) return;
332
+ printConversionTrackingContract(contract);
333
+ }
334
+ function printConversionTrackingContract(contract) {
335
+ console.log(`Conversion contract: ${contract.name} (${contract.id})`);
336
+ console.log(`Event: ${contract.eventName}`);
337
+ console.log(`Google Ads: customer ${contract.googleAds.customerId}, conversion action ${contract.googleAds.conversionActionId}`);
338
+ console.log(`GTM: account ${contract.gtm.accountId}, container ${contract.gtm.containerId}, tag ${contract.gtm.tagId}`);
339
+ console.log(`Runtime verification: ${contract.runtime.verificationRequired ? "required" : "not required"}`);
340
+ }
341
+ async function conversionTrackingCreate(client, project, request, opts) {
342
+ const contract = await client.createConversionTrackingContract(project, request);
343
+ if (printMachine(contract, opts.format)) return;
344
+ console.log(`Created conversion-tracking contract "${contract.name}" (${contract.id}).`);
345
+ }
346
+ async function conversionTrackingUpdate(client, project, contractId, request, opts) {
347
+ const contract = await client.updateConversionTrackingContract(project, contractId, request);
348
+ if (printMachine(contract, opts.format)) return;
349
+ console.log(`Updated conversion-tracking contract "${contract.name}" (${contract.id}).`);
350
+ }
351
+ async function conversionTrackingDelete(client, project, contractId, opts) {
352
+ await client.deleteConversionTrackingContract(project, contractId);
353
+ if (printMachine({ project, contractId, deleted: true }, opts.format)) return;
354
+ console.log(`Deleted conversion-tracking contract ${contractId}.`);
355
+ }
356
+ async function conversionTrackingIntegrity(client, project, contractId, opts) {
357
+ const result = await client.getConversionTrackingIntegrity(project, contractId);
358
+ if (opts.format === "jsonl") {
359
+ emitJsonl(result.assessment.findings.map((finding) => ({
360
+ project,
361
+ contractId: result.assessment.contract.id,
362
+ integrityStatus: result.assessment.status,
363
+ evaluatedAt: result.assessment.evaluatedAt,
364
+ ...finding
365
+ })));
366
+ return;
367
+ }
368
+ if (printMachine(result, opts.format)) return;
369
+ console.log(`Conversion integrity: ${result.assessment.contract.name} \u2014 ${result.assessment.status}`);
370
+ console.log(`Evaluated: ${result.assessment.evaluatedAt}`);
371
+ for (const finding of result.assessment.findings) {
372
+ console.log(` ${finding.outcome.toUpperCase().padEnd(7)} ${finding.code} \u2014 ${finding.subject}`);
373
+ }
374
+ if (result.assessment.status === "runtime-unverified") {
375
+ console.log("\nStatic configuration is consistent, but a GTM API snapshot cannot prove that the website event fired or Google Ads observed a conversion.");
376
+ }
377
+ }
378
+ export {
379
+ conversionTrackingContract,
380
+ conversionTrackingContracts,
381
+ conversionTrackingCreate,
382
+ conversionTrackingDelete,
383
+ conversionTrackingIntegrity,
384
+ conversionTrackingUpdate,
385
+ googleAdsCustomers,
386
+ googleAdsDisconnect,
387
+ googleAdsPerformance,
388
+ googleAdsSelect,
389
+ googleAdsSnapshot,
390
+ googleAdsSnapshots,
391
+ googleAdsStatus,
392
+ googleAdsSync,
393
+ gtmAccounts,
394
+ gtmContainers,
395
+ gtmDisconnect,
396
+ gtmSelect,
397
+ gtmSnapshot,
398
+ gtmSnapshots,
399
+ gtmStatus,
400
+ gtmSync,
401
+ gtmWorkspaces,
402
+ readConversionTrackingContractInput
403
+ };
@@ -0,0 +1,64 @@
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 "./chunk-AOJU5LKX.js";
9
+ import "./chunk-HGMYEDAQ.js";
10
+ import {
11
+ formatPercent
12
+ } from "./chunk-D6COIM3U.js";
13
+ import "./chunk-MLKGABMK.js";
14
+
15
+ // src/commands/health-cmd.ts
16
+ async function showHealth(project, opts) {
17
+ const client = createApiClient();
18
+ if (opts.history) {
19
+ const snapshots = await client.getHealthHistory(project, opts.limit);
20
+ if (opts.format === "json") {
21
+ console.log(JSON.stringify(snapshots, null, 2));
22
+ return;
23
+ } else if (opts.format === "jsonl") {
24
+ emitJsonl(snapshots.map((snap) => ({ project, ...snap })));
25
+ return;
26
+ }
27
+ if (snapshots.length === 0) {
28
+ console.log("No health history available.");
29
+ return;
30
+ }
31
+ console.log("Date Mention Rate Mentioned/Total Cited Rate Cited/Total");
32
+ console.log("\u2500".repeat(86));
33
+ for (const snap of snapshots) {
34
+ const mRate = formatPercent(snap.overallMentionRate).padStart(6);
35
+ const mRatio = `${snap.mentionedPairs}/${snap.totalPairs}`.padEnd(15);
36
+ const cRate = formatPercent(snap.overallCitedRate).padStart(6);
37
+ const cRatio = `${snap.citedPairs}/${snap.totalPairs}`;
38
+ const date = snap.createdAt.slice(0, 19).padEnd(25);
39
+ console.log(`${date} ${mRate} ${mRatio} ${cRate} ${cRatio}`);
40
+ }
41
+ return;
42
+ }
43
+ const health = await client.getHealth(project);
44
+ if (opts.format === "json" || opts.format === "jsonl") {
45
+ console.log(JSON.stringify(health, null, 2));
46
+ return;
47
+ }
48
+ if (health.status === "no-data") {
49
+ console.log("No health data yet \u2014 run a sweep first (canonry run <project>).");
50
+ return;
51
+ }
52
+ console.log(`Health: ${formatPercent(health.overallMentionRate)} mentioned (${health.mentionedPairs}/${health.totalPairs} pairs)`);
53
+ console.log(` ${formatPercent(health.overallCitedRate)} cited (${health.citedPairs}/${health.totalPairs} pairs)`);
54
+ console.log("");
55
+ if (health.providerBreakdown && Object.keys(health.providerBreakdown).length > 0) {
56
+ console.log("Provider Breakdown:");
57
+ for (const [provider, stats] of Object.entries(health.providerBreakdown)) {
58
+ console.log(` ${provider.padEnd(15)} ${formatPercent(stats.mentionRate)} mentioned (${stats.mentioned}/${stats.total}) ${formatPercent(stats.citedRate)} cited (${stats.cited}/${stats.total})`);
59
+ }
60
+ }
61
+ }
62
+ export {
63
+ showHealth
64
+ };
@@ -0,0 +1,90 @@
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 "./chunk-AOJU5LKX.js";
9
+ import {
10
+ CliError,
11
+ usageError
12
+ } from "./chunk-HGMYEDAQ.js";
13
+ import {
14
+ auditHistoryQuerySchema,
15
+ describeError,
16
+ formatValidationIssues,
17
+ resultsClearRequestSchema
18
+ } from "./chunk-D6COIM3U.js";
19
+ import "./chunk-MLKGABMK.js";
20
+
21
+ // src/commands/history.ts
22
+ function getClient() {
23
+ return createApiClient();
24
+ }
25
+ function originLabel(entry) {
26
+ const userAgent = entry.userAgent?.toLowerCase() ?? "";
27
+ if (userAgent.includes("canonry-mcp")) return "mcp";
28
+ if (userAgent.includes("canonry-cli")) return "cli";
29
+ if (userAgent.includes("mozilla/")) return "dashboard";
30
+ return entry.actor;
31
+ }
32
+ async function showHistory(project, format, opts = {}) {
33
+ const parsed = auditHistoryQuerySchema.safeParse(opts);
34
+ if (!parsed.success) throw usageError(formatValidationIssues(parsed.error.issues));
35
+ const client = getClient();
36
+ try {
37
+ const entries = project ? await client.getHistory(project, opts) : await client.getGlobalHistory(opts);
38
+ if (format === "json") {
39
+ console.log(JSON.stringify(entries, null, 2));
40
+ return;
41
+ }
42
+ if (format === "jsonl") {
43
+ emitJsonl(entries.map((entry) => ({ project: project ?? null, ...entry })));
44
+ return;
45
+ }
46
+ if (entries.length === 0) {
47
+ console.log(project ? `No audit history for "${project}".` : "No instance audit history.");
48
+ return;
49
+ }
50
+ console.log(`${project ? `Audit history for "${project}"` : "Instance audit history"} (${entries.length}):
51
+ `);
52
+ console.log(` ${project ? "" : "PROJECT "}TIMESTAMP ACTION ENTITY TYPE ACTOR ORIGIN`);
53
+ console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
54
+ for (const entry of entries) {
55
+ console.log(
56
+ ` ${project ? "" : `${(entry.project ?? entry.projectId ?? "(instance)").padEnd(20)} `}${entry.createdAt.padEnd(23)} ${entry.action.padEnd(18)} ${entry.entityType.padEnd(11)} ${entry.actor.padEnd(18)} ${originLabel(entry)}`
57
+ );
58
+ if (entry.actorSession) console.log(` session: ${entry.actorSession}`);
59
+ if (entry.diff != null) console.log(` diff: ${JSON.stringify(entry.diff)}`);
60
+ }
61
+ } catch (err) {
62
+ if (err instanceof CliError) throw err;
63
+ const message = describeError(err);
64
+ throw new CliError({
65
+ code: "HISTORY_FETCH_FAILED",
66
+ message: project ? `Failed to fetch history for project "${project}"` : "Failed to fetch instance history",
67
+ displayMessage: `Failed to fetch history: ${message}`,
68
+ details: {
69
+ project: project ?? null,
70
+ cause: message
71
+ }
72
+ });
73
+ }
74
+ }
75
+ async function clearResults(project, opts) {
76
+ const request = resultsClearRequestSchema.safeParse({ runIds: opts.runIds, researchRunIds: opts.researchRunIds, confirm: opts.confirm });
77
+ if (!request.success) throw new CliError({ code: "INVALID_ARGUMENT", message: request.error.issues.map((issue) => issue.message).join(" "), exitCode: 1 });
78
+ const result = await getClient().clearResults(project, request.data);
79
+ if (opts.format === "jsonl") emitJsonl([result]);
80
+ else if (opts.format === "json") console.log(JSON.stringify(result, null, 2));
81
+ else {
82
+ console.log(`${result.dryRun ? "Would clear" : "Cleared"} ${result.runIds.length} visibility runs and ${result.researchRunIds.length} research batches.`);
83
+ console.log(`${result.querySnapshots} saved visibility answers; ${result.researchQueries} research queries.`);
84
+ if (result.dryRun) console.log("Back up the evidence, then repeat with --confirm to delete these exact runs.");
85
+ }
86
+ }
87
+ export {
88
+ clearResults,
89
+ showHistory
90
+ };