@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
package/dist/index.js
CHANGED
|
@@ -3,15 +3,38 @@ import {
|
|
|
3
3
|
createGoogleMarketingCredentialStore,
|
|
4
4
|
createGoogleMarketingRuntime,
|
|
5
5
|
createServer
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-6G6FTDWC.js";
|
|
7
|
+
import "./chunk-42D2LE2B.js";
|
|
8
|
+
import "./chunk-U3AHE2RT.js";
|
|
9
|
+
import "./chunk-ELCLGWUT.js";
|
|
10
|
+
import "./chunk-XEBKF4N5.js";
|
|
11
|
+
import "./chunk-NHQ2U5I4.js";
|
|
12
|
+
import "./chunk-WAULJDKO.js";
|
|
13
|
+
import "./chunk-ISOQPVPY.js";
|
|
14
|
+
import "./chunk-TSENU4GG.js";
|
|
15
|
+
import "./chunk-QWKPSFGL.js";
|
|
16
|
+
import "./chunk-RKIXES2B.js";
|
|
17
|
+
import "./chunk-PCXRFT3N.js";
|
|
18
|
+
import "./chunk-4MJYGB56.js";
|
|
19
|
+
import "./chunk-B5J675KK.js";
|
|
7
20
|
import {
|
|
8
21
|
loadConfig
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
22
|
+
} from "./chunk-UQ3MOZGC.js";
|
|
23
|
+
import "./chunk-B2FR2ZQ4.js";
|
|
24
|
+
import "./chunk-73P65KPW.js";
|
|
25
|
+
import "./chunk-ZWJRY5UI.js";
|
|
26
|
+
import "./chunk-HM4NNKLG.js";
|
|
27
|
+
import "./chunk-HACZUMGM.js";
|
|
28
|
+
import "./chunk-AOJU5LKX.js";
|
|
12
29
|
import "./chunk-HGMYEDAQ.js";
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
30
|
+
import "./chunk-GO2J7SYT.js";
|
|
31
|
+
import "./chunk-MMEO22MF.js";
|
|
32
|
+
import "./chunk-DGVUTH7W.js";
|
|
33
|
+
import "./chunk-PITHTCAX.js";
|
|
34
|
+
import "./chunk-7B2Q4NJE.js";
|
|
35
|
+
import "./chunk-63ISSSGX.js";
|
|
36
|
+
import "./chunk-D6COIM3U.js";
|
|
37
|
+
import "./chunk-MLKGABMK.js";
|
|
15
38
|
export {
|
|
16
39
|
GoogleMarketingRuntimeError,
|
|
17
40
|
createGoogleMarketingCredentialStore,
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import {
|
|
2
|
+
installMcp
|
|
3
|
+
} from "./chunk-WDFI5YMD.js";
|
|
4
|
+
import {
|
|
5
|
+
trackCliConnection
|
|
6
|
+
} from "./chunk-ZXUAWVWM.js";
|
|
7
|
+
import {
|
|
8
|
+
buildSetupState,
|
|
9
|
+
queueServeHandoff
|
|
10
|
+
} from "./chunk-I3A56PFP.js";
|
|
11
|
+
import "./chunk-VJWDBFSL.js";
|
|
12
|
+
import "./chunk-ISOQPVPY.js";
|
|
13
|
+
import "./chunk-QWKPSFGL.js";
|
|
14
|
+
import {
|
|
15
|
+
cliRuntimeContext,
|
|
16
|
+
installAttribution,
|
|
17
|
+
isTelemetryEnabled,
|
|
18
|
+
recordInstallRef,
|
|
19
|
+
showFirstRunNotice,
|
|
20
|
+
trackEvent
|
|
21
|
+
} from "./chunk-RKIXES2B.js";
|
|
22
|
+
import {
|
|
23
|
+
configExists,
|
|
24
|
+
getBootstrapEnv,
|
|
25
|
+
getConfigDir,
|
|
26
|
+
getConfigPath,
|
|
27
|
+
saveConfig,
|
|
28
|
+
withBootstrapProviderDefaults
|
|
29
|
+
} from "./chunk-UQ3MOZGC.js";
|
|
30
|
+
import {
|
|
31
|
+
installSkills
|
|
32
|
+
} from "./chunk-B2FR2ZQ4.js";
|
|
33
|
+
import "./chunk-AOJU5LKX.js";
|
|
34
|
+
import {
|
|
35
|
+
CliError,
|
|
36
|
+
isMachineFormat
|
|
37
|
+
} from "./chunk-HGMYEDAQ.js";
|
|
38
|
+
import "./chunk-7B2Q4NJE.js";
|
|
39
|
+
import {
|
|
40
|
+
apiKeys,
|
|
41
|
+
createClient,
|
|
42
|
+
migrate
|
|
43
|
+
} from "./chunk-63ISSSGX.js";
|
|
44
|
+
import {
|
|
45
|
+
describeError
|
|
46
|
+
} from "./chunk-D6COIM3U.js";
|
|
47
|
+
import "./chunk-MLKGABMK.js";
|
|
48
|
+
|
|
49
|
+
// src/commands/init.ts
|
|
50
|
+
import crypto from "crypto";
|
|
51
|
+
import fs from "fs";
|
|
52
|
+
import readline from "readline";
|
|
53
|
+
import path from "path";
|
|
54
|
+
async function promptProviderApiKey(label, envVar, promptFn = prompt, env = process.env) {
|
|
55
|
+
const fromEnv = env[envVar]?.trim();
|
|
56
|
+
if (fromEnv) {
|
|
57
|
+
const answer = await promptFn(`Found ${envVar} in your environment. Use it? [Y/n]: `);
|
|
58
|
+
if (!/^n/i.test(answer.trim())) return fromEnv;
|
|
59
|
+
}
|
|
60
|
+
return promptFn(`${label} API key (press Enter to skip): `);
|
|
61
|
+
}
|
|
62
|
+
function prompt(question) {
|
|
63
|
+
const rl = readline.createInterface({
|
|
64
|
+
input: process.stdin,
|
|
65
|
+
output: process.stdout
|
|
66
|
+
});
|
|
67
|
+
return new Promise((resolve) => {
|
|
68
|
+
rl.question(question, (answer) => {
|
|
69
|
+
rl.close();
|
|
70
|
+
resolve(answer.trim());
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
var DEFAULT_QUOTA = {
|
|
75
|
+
maxConcurrency: 2,
|
|
76
|
+
maxRequestsPerMinute: 10,
|
|
77
|
+
maxRequestsPerDay: 500
|
|
78
|
+
};
|
|
79
|
+
var PROJECT_MARKERS = [".git", "canonry.yaml", "canonry.yml", "package.json"];
|
|
80
|
+
function cwdLooksLikeProject(dir) {
|
|
81
|
+
const home = process.env.HOME ?? "";
|
|
82
|
+
if (home && path.resolve(dir) === path.resolve(home)) return false;
|
|
83
|
+
return PROJECT_MARKERS.some((marker) => fs.existsSync(path.join(dir, marker)));
|
|
84
|
+
}
|
|
85
|
+
var DEFAULT_AGENT_MODELS = {
|
|
86
|
+
anthropic: "anthropic/claude-sonnet-4-6",
|
|
87
|
+
openai: "openai/gpt-4o",
|
|
88
|
+
openrouter: "openrouter/anthropic/claude-sonnet-4-6",
|
|
89
|
+
groq: "groq/llama-4-scout-17b",
|
|
90
|
+
google: "google/gemini-3.8-flash",
|
|
91
|
+
mistral: "mistral/mistral-large-latest",
|
|
92
|
+
xai: "xai/grok-2"
|
|
93
|
+
};
|
|
94
|
+
async function initCommand(opts) {
|
|
95
|
+
const format = opts?.format ?? "text";
|
|
96
|
+
const primaryNextStep = "canonry serve";
|
|
97
|
+
if (!isMachineFormat(format)) {
|
|
98
|
+
console.log("Initializing canonry...\n");
|
|
99
|
+
}
|
|
100
|
+
if (configExists() && !opts?.force) {
|
|
101
|
+
if (isMachineFormat(format)) {
|
|
102
|
+
console.log(JSON.stringify({
|
|
103
|
+
initialized: false,
|
|
104
|
+
reason: "config_exists",
|
|
105
|
+
configPath: getConfigPath()
|
|
106
|
+
}, null, 2));
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
console.log(`Config already exists at ${getConfigPath()}`);
|
|
110
|
+
console.log('To reinitialize, run "canonry init --force".');
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
const configDir = getConfigDir();
|
|
114
|
+
if (!fs.existsSync(configDir)) {
|
|
115
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
116
|
+
}
|
|
117
|
+
const bootstrapEnv = getBootstrapEnv(process.env, {
|
|
118
|
+
GEMINI_API_KEY: opts?.geminiKey,
|
|
119
|
+
OPENAI_API_KEY: opts?.openaiKey,
|
|
120
|
+
ANTHROPIC_API_KEY: opts?.claudeKey,
|
|
121
|
+
PERPLEXITY_API_KEY: opts?.perplexityKey,
|
|
122
|
+
MUSE_API_KEY: opts?.museKey,
|
|
123
|
+
LOCAL_BASE_URL: opts?.localUrl,
|
|
124
|
+
LOCAL_MODEL: opts?.localModel,
|
|
125
|
+
LOCAL_API_KEY: opts?.localKey,
|
|
126
|
+
GOOGLE_CLIENT_ID: opts?.googleClientId,
|
|
127
|
+
GOOGLE_CLIENT_SECRET: opts?.googleClientSecret
|
|
128
|
+
});
|
|
129
|
+
if (bootstrapEnv.googleClientId && !bootstrapEnv.googleClientSecret || !bootstrapEnv.googleClientId && bootstrapEnv.googleClientSecret) {
|
|
130
|
+
throw new CliError({
|
|
131
|
+
code: "GOOGLE_OAUTH_CREDENTIALS_INCOMPLETE",
|
|
132
|
+
message: "Google OAuth requires both a client ID and client secret when configured non-interactively.",
|
|
133
|
+
displayMessage: "Google OAuth requires both a client ID and client secret when configured non-interactively.",
|
|
134
|
+
details: {
|
|
135
|
+
required: ["google-client-id", "google-client-secret"]
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const envProviders = bootstrapEnv.providers;
|
|
140
|
+
const envGoogleConfigured = !!(bootstrapEnv.googleClientId && bootstrapEnv.googleClientSecret);
|
|
141
|
+
const nonInteractive = !!(envProviders.gemini || envProviders.openai || envProviders.claude || envProviders.perplexity || envProviders.muse || envProviders.local || envGoogleConfigured);
|
|
142
|
+
const providers = {};
|
|
143
|
+
let google;
|
|
144
|
+
if (isMachineFormat(format) && !nonInteractive) {
|
|
145
|
+
throw new CliError({
|
|
146
|
+
code: "INIT_JSON_REQUIRES_NON_INTERACTIVE",
|
|
147
|
+
message: "--format json requires non-interactive provider configuration via flags or environment variables.",
|
|
148
|
+
displayMessage: '--format json requires provider flags or environment variables. For provider-free first-run setup, use "canonry bootstrap" instead.',
|
|
149
|
+
details: {
|
|
150
|
+
required: ["provider flags or environment variables"]
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (nonInteractive) {
|
|
155
|
+
for (const [name, entry] of Object.entries(envProviders)) {
|
|
156
|
+
if (entry) providers[name] = withBootstrapProviderDefaults(name, entry);
|
|
157
|
+
}
|
|
158
|
+
if (envGoogleConfigured) {
|
|
159
|
+
google = {
|
|
160
|
+
clientId: bootstrapEnv.googleClientId,
|
|
161
|
+
clientSecret: bootstrapEnv.googleClientSecret,
|
|
162
|
+
connections: []
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
console.log("Configure AI providers (at least one required):\n");
|
|
167
|
+
console.log("Tip: For non-interactive setup, pass provider flags or set");
|
|
168
|
+
console.log("GEMINI_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY, PERPLEXITY_API_KEY,");
|
|
169
|
+
console.log("MUSE_API_KEY,");
|
|
170
|
+
console.log("GOOGLE_CLIENT_ID, and GOOGLE_CLIENT_SECRET env vars.");
|
|
171
|
+
console.log('Or use "canonry bootstrap".\n');
|
|
172
|
+
const geminiApiKey = await promptProviderApiKey("Gemini", "GEMINI_API_KEY");
|
|
173
|
+
if (geminiApiKey) {
|
|
174
|
+
const geminiModel = await prompt(" Gemini model [gemini-flash-latest]: ") || "gemini-flash-latest";
|
|
175
|
+
providers.gemini = { apiKey: geminiApiKey, model: geminiModel, quota: DEFAULT_QUOTA };
|
|
176
|
+
}
|
|
177
|
+
const openaiApiKey = await promptProviderApiKey("OpenAI", "OPENAI_API_KEY");
|
|
178
|
+
if (openaiApiKey) {
|
|
179
|
+
const openaiModel = await prompt(" OpenAI model [gpt-4o]: ") || "gpt-4o";
|
|
180
|
+
providers.openai = { apiKey: openaiApiKey, model: openaiModel, quota: DEFAULT_QUOTA };
|
|
181
|
+
}
|
|
182
|
+
const claudeApiKey = await promptProviderApiKey("Anthropic", "ANTHROPIC_API_KEY");
|
|
183
|
+
if (claudeApiKey) {
|
|
184
|
+
const claudeModel = await prompt(" Claude model [claude-sonnet-4-6]: ") || "claude-sonnet-4-6";
|
|
185
|
+
providers.claude = { apiKey: claudeApiKey, model: claudeModel, quota: DEFAULT_QUOTA };
|
|
186
|
+
}
|
|
187
|
+
const perplexityApiKey = await promptProviderApiKey("Perplexity", "PERPLEXITY_API_KEY");
|
|
188
|
+
if (perplexityApiKey) {
|
|
189
|
+
const perplexityModel = await prompt(" Perplexity preset or model [fast]: ") || "fast";
|
|
190
|
+
providers.perplexity = { apiKey: perplexityApiKey, model: perplexityModel, quota: DEFAULT_QUOTA };
|
|
191
|
+
}
|
|
192
|
+
const museApiKey = await promptProviderApiKey("Muse", "MUSE_API_KEY");
|
|
193
|
+
if (museApiKey) {
|
|
194
|
+
const museModel = await prompt(" Muse model [muse-spark-1.3]: ") || "muse-spark-1.3";
|
|
195
|
+
providers.muse = { apiKey: museApiKey, model: museModel, quota: DEFAULT_QUOTA };
|
|
196
|
+
}
|
|
197
|
+
console.log("\nLocal LLM (Ollama, LM Studio, llama.cpp, vLLM \u2014 any OpenAI-compatible API):");
|
|
198
|
+
const localBaseUrl = await prompt("Local LLM base URL (press Enter to skip, e.g. http://localhost:11434/v1): ");
|
|
199
|
+
if (localBaseUrl) {
|
|
200
|
+
const localModel = await prompt(" Model name [llama3]: ") || "llama3";
|
|
201
|
+
const localApiKey = await prompt(" API key (press Enter if not needed): ") || void 0;
|
|
202
|
+
providers.local = { baseUrl: localBaseUrl, apiKey: localApiKey, model: localModel, quota: DEFAULT_QUOTA };
|
|
203
|
+
}
|
|
204
|
+
console.log("\nGoogle Search Console OAuth (optional):");
|
|
205
|
+
const googleClientId = await prompt("Google OAuth client ID (press Enter to skip): ");
|
|
206
|
+
if (googleClientId) {
|
|
207
|
+
const googleClientSecret = await prompt(" Google OAuth client secret: ");
|
|
208
|
+
if (!googleClientSecret) {
|
|
209
|
+
throw new CliError({
|
|
210
|
+
code: "GOOGLE_OAUTH_CREDENTIALS_INCOMPLETE",
|
|
211
|
+
message: "Google OAuth client secret is required when a client ID is provided.",
|
|
212
|
+
displayMessage: "\nGoogle OAuth client secret is required when a client ID is provided.",
|
|
213
|
+
details: {
|
|
214
|
+
required: ["google-client-secret"]
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
google = {
|
|
219
|
+
clientId: googleClientId,
|
|
220
|
+
clientSecret: googleClientSecret,
|
|
221
|
+
connections: []
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const hasProvider = providers.gemini || providers.openai || providers.claude || providers.perplexity || providers.muse || providers.local;
|
|
226
|
+
if (!hasProvider) {
|
|
227
|
+
throw new CliError({
|
|
228
|
+
code: "INIT_PROVIDER_REQUIRED",
|
|
229
|
+
message: "At least one provider is required.",
|
|
230
|
+
displayMessage: '\nAt least one provider is required. For provider-free first-run setup, use "canonry bootstrap" instead.',
|
|
231
|
+
details: {
|
|
232
|
+
required: ["provider"]
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
const rawApiKey = `cnry_${crypto.randomBytes(16).toString("hex")}`;
|
|
237
|
+
const keyHash = crypto.createHash("sha256").update(rawApiKey).digest("hex");
|
|
238
|
+
const keyPrefix = rawApiKey.slice(0, 9);
|
|
239
|
+
const databasePath = path.join(configDir, "data.db");
|
|
240
|
+
const db = createClient(databasePath);
|
|
241
|
+
migrate(db);
|
|
242
|
+
db.insert(apiKeys).values({
|
|
243
|
+
id: crypto.randomUUID(),
|
|
244
|
+
name: "default",
|
|
245
|
+
keyHash,
|
|
246
|
+
keyPrefix,
|
|
247
|
+
scopes: ["*"],
|
|
248
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
249
|
+
}).run();
|
|
250
|
+
saveConfig({
|
|
251
|
+
apiUrl: `http://127.0.0.1:${process.env.CANONRY_PORT || "4100"}`,
|
|
252
|
+
database: databasePath,
|
|
253
|
+
apiKey: rawApiKey,
|
|
254
|
+
providers,
|
|
255
|
+
google
|
|
256
|
+
});
|
|
257
|
+
const providerNames = Object.keys(providers);
|
|
258
|
+
let skillsSummary;
|
|
259
|
+
let skillsTip;
|
|
260
|
+
if (!opts?.skipSkills) {
|
|
261
|
+
const skillsTarget = opts?.skillsDir ?? process.cwd();
|
|
262
|
+
if (cwdLooksLikeProject(skillsTarget)) {
|
|
263
|
+
try {
|
|
264
|
+
skillsSummary = await installSkills({ dir: skillsTarget });
|
|
265
|
+
} catch (err) {
|
|
266
|
+
skillsTip = `Skills auto-install failed: ${describeError(err)}. Run "canonry skills install" manually.`;
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
skillsTip = 'Run "canonry skills install" in a project directory to add the canonry + Aero playbook to .claude/skills/ and .codex/skills/.';
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
let mcpSummary;
|
|
273
|
+
let mcpTip;
|
|
274
|
+
if (!opts?.skipMcp) {
|
|
275
|
+
const mcpTarget = opts?.skillsDir ?? process.cwd();
|
|
276
|
+
if (cwdLooksLikeProject(mcpTarget)) {
|
|
277
|
+
try {
|
|
278
|
+
const previousCwd = process.cwd();
|
|
279
|
+
try {
|
|
280
|
+
if (opts?.skillsDir) process.chdir(opts.skillsDir);
|
|
281
|
+
mcpSummary = await installMcp({ client: "claude-code", silent: true });
|
|
282
|
+
} finally {
|
|
283
|
+
process.chdir(previousCwd);
|
|
284
|
+
}
|
|
285
|
+
} catch (err) {
|
|
286
|
+
mcpTip = `MCP auto-install failed: ${describeError(err)}. Run "canonry mcp install --client claude-code" manually.`;
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
mcpTip = 'Run "canonry mcp install --client claude-code" in a project directory to register the canonry MCP server in `.mcp.json` for Claude Code sessions.';
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const nextSteps = buildNextSteps();
|
|
293
|
+
if (isMachineFormat(format)) {
|
|
294
|
+
console.log(JSON.stringify({
|
|
295
|
+
initialized: true,
|
|
296
|
+
configPath: getConfigPath(),
|
|
297
|
+
databasePath,
|
|
298
|
+
apiUrl: `http://127.0.0.1:${process.env.CANONRY_PORT || "4100"}`,
|
|
299
|
+
apiKey: rawApiKey,
|
|
300
|
+
providers: providerNames,
|
|
301
|
+
googleConfigured: !!google,
|
|
302
|
+
skills: skillsSummary,
|
|
303
|
+
skillsTip,
|
|
304
|
+
mcp: mcpSummary,
|
|
305
|
+
mcpTip,
|
|
306
|
+
primaryNextStep,
|
|
307
|
+
nextSteps
|
|
308
|
+
}, null, 2));
|
|
309
|
+
} else {
|
|
310
|
+
console.log(`
|
|
311
|
+
Config saved to ${getConfigPath()}`);
|
|
312
|
+
console.log(`Database created at ${databasePath}`);
|
|
313
|
+
console.log(`API key: ${rawApiKey}`);
|
|
314
|
+
console.log(`Providers: ${providerNames.join(", ")}`);
|
|
315
|
+
if (skillsSummary) {
|
|
316
|
+
console.log(`
|
|
317
|
+
${skillsSummary.message}`);
|
|
318
|
+
console.log(`Skills target: ${skillsSummary.targetDir}`);
|
|
319
|
+
}
|
|
320
|
+
if (skillsTip) console.log(`
|
|
321
|
+
${skillsTip}`);
|
|
322
|
+
if (mcpSummary) {
|
|
323
|
+
console.log(`
|
|
324
|
+
MCP server "${mcpSummary.serverName}" ${mcpSummary.status} for Claude Code at ${mcpSummary.configPath}.`);
|
|
325
|
+
console.log("Claude Code sessions opened in this directory will pick it up automatically.");
|
|
326
|
+
}
|
|
327
|
+
if (mcpTip) console.log(`
|
|
328
|
+
${mcpTip}`);
|
|
329
|
+
}
|
|
330
|
+
let agentLLM;
|
|
331
|
+
const agentProvider = opts?.agentProvider;
|
|
332
|
+
const agentKey = opts?.agentKey;
|
|
333
|
+
const agentModel = opts?.agentModel;
|
|
334
|
+
if (agentProvider || agentKey || agentModel) {
|
|
335
|
+
const provider = agentProvider ?? "anthropic";
|
|
336
|
+
agentLLM = {
|
|
337
|
+
provider,
|
|
338
|
+
key: agentKey,
|
|
339
|
+
model: agentModel ?? DEFAULT_AGENT_MODELS[provider]
|
|
340
|
+
};
|
|
341
|
+
} else if (!nonInteractive) {
|
|
342
|
+
console.log("\nConfigure agent LLM (the model that powers the agent):");
|
|
343
|
+
console.log("Supported providers: anthropic, openai, openrouter, groq, mistral, xai, google, cerebras\n");
|
|
344
|
+
const provider = await prompt("Provider [anthropic]: ") || "anthropic";
|
|
345
|
+
const key = await prompt("API key (press Enter to skip): ");
|
|
346
|
+
if (key) {
|
|
347
|
+
const defaultModel = DEFAULT_AGENT_MODELS[provider];
|
|
348
|
+
const modelText = defaultModel ? `Model [${defaultModel}]: ` : "Model: ";
|
|
349
|
+
const model = await prompt(modelText) || defaultModel;
|
|
350
|
+
agentLLM = { provider, key, model };
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (!isMachineFormat(format)) {
|
|
354
|
+
showFirstRunNotice();
|
|
355
|
+
console.log("\nNext: canonry serve to map your site and capture a Page Health baseline.");
|
|
356
|
+
console.log("\nNext steps:");
|
|
357
|
+
for (const line of nextSteps) {
|
|
358
|
+
console.log(` ${line}`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (isTelemetryEnabled()) {
|
|
362
|
+
const postInitSetupState = await buildSetupState();
|
|
363
|
+
recordInstallRef(opts?.ref);
|
|
364
|
+
trackEvent("cli.init", {
|
|
365
|
+
providerCount: providerNames.length,
|
|
366
|
+
providers: providerNames,
|
|
367
|
+
...postInitSetupState ? {
|
|
368
|
+
setup_state: {
|
|
369
|
+
...postInitSetupState,
|
|
370
|
+
// This snapshot represents a successfully completed init. The
|
|
371
|
+
// anonymous ID is persisted inside trackEvent immediately after
|
|
372
|
+
// properties are composed, so override the pre-send read here.
|
|
373
|
+
is_first_run: false
|
|
374
|
+
}
|
|
375
|
+
} : {},
|
|
376
|
+
googleConfigured: !!google,
|
|
377
|
+
agentConfigured: !!agentLLM,
|
|
378
|
+
// Deprecated compact field retained while existing telemetry reports
|
|
379
|
+
// migrate to the structured setup_state object.
|
|
380
|
+
setupState: encodeLegacySetupState({
|
|
381
|
+
hasProvider: !!hasProvider,
|
|
382
|
+
hasGoogle: !!google,
|
|
383
|
+
hasAgent: !!agentLLM
|
|
384
|
+
}),
|
|
385
|
+
skillsInstalled: !!skillsSummary,
|
|
386
|
+
...installAttribution(),
|
|
387
|
+
...cliRuntimeContext()
|
|
388
|
+
});
|
|
389
|
+
for (const provider of Object.keys(providers)) {
|
|
390
|
+
trackCliConnection({ integration: "provider", provider, action: "connect", status: "succeeded" });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (!isMachineFormat(format) && process.stdin.isTTY && process.stdout.isTTY) {
|
|
394
|
+
const answer = await prompt("\nStart the dashboard now? [Y/n]: ");
|
|
395
|
+
if (!/^n/i.test(answer.trim())) {
|
|
396
|
+
queueServeHandoff();
|
|
397
|
+
console.log("Handing off to the dashboard. Map your site at /setup once it is up.");
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return agentLLM;
|
|
401
|
+
}
|
|
402
|
+
function buildNextSteps() {
|
|
403
|
+
return [
|
|
404
|
+
"1. Start the dashboard and open Page Health setup:",
|
|
405
|
+
" canonry serve",
|
|
406
|
+
" \u2192 http://127.0.0.1:4100/setup",
|
|
407
|
+
"",
|
|
408
|
+
" Map your public site and capture a persisted Page Health baseline.",
|
|
409
|
+
" AI Visibility is optional and can be configured after Page Health.",
|
|
410
|
+
" On a remote or proxied host, dashboard password setup asks for the root API key (apiKey in config.yaml).",
|
|
411
|
+
"",
|
|
412
|
+
"Prefer the terminal? The same flow as CLI commands:",
|
|
413
|
+
"",
|
|
414
|
+
" a. canonry project create my-site --domain example.com --country US --language en",
|
|
415
|
+
" b. canonry technical-aeo run my-site --max-pages 100 --wait --format json",
|
|
416
|
+
" c. canonry technical-aeo score my-site --format json",
|
|
417
|
+
" d. canonry technical-aeo pages my-site --sort score-asc --limit 10 --format jsonl",
|
|
418
|
+
"",
|
|
419
|
+
'Tip: "canonry doctor" verifies your setup before you start.'
|
|
420
|
+
];
|
|
421
|
+
}
|
|
422
|
+
function encodeLegacySetupState(state) {
|
|
423
|
+
const flags = [];
|
|
424
|
+
if (state.hasProvider) flags.push("provider");
|
|
425
|
+
if (state.hasGoogle) flags.push("google");
|
|
426
|
+
if (state.hasAgent) flags.push("agent");
|
|
427
|
+
return flags.length > 0 ? flags.sort().join("|") : "none";
|
|
428
|
+
}
|
|
429
|
+
export {
|
|
430
|
+
initCommand,
|
|
431
|
+
promptProviderApiKey
|
|
432
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
isMachineFormat
|
|
11
|
+
} from "./chunk-HGMYEDAQ.js";
|
|
12
|
+
import "./chunk-D6COIM3U.js";
|
|
13
|
+
import "./chunk-MLKGABMK.js";
|
|
14
|
+
|
|
15
|
+
// src/commands/insights.ts
|
|
16
|
+
async function listInsights(project, opts) {
|
|
17
|
+
const client = createApiClient();
|
|
18
|
+
const insights = await client.getInsights(project, {
|
|
19
|
+
dismissed: opts.dismissed,
|
|
20
|
+
runId: opts.runId,
|
|
21
|
+
type: opts.type,
|
|
22
|
+
severity: opts.severity,
|
|
23
|
+
limit: opts.limit
|
|
24
|
+
});
|
|
25
|
+
if (opts.format === "json") {
|
|
26
|
+
console.log(JSON.stringify(insights, null, 2));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (opts.format === "jsonl") {
|
|
30
|
+
emitJsonl(insights.map((insight) => ({ project, ...insight })));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (insights.length === 0) {
|
|
34
|
+
console.log("No insights found.");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
for (const insight of insights) {
|
|
38
|
+
const severity = insight.severity.toUpperCase().padEnd(8);
|
|
39
|
+
const dismissed = insight.dismissed ? " [dismissed]" : "";
|
|
40
|
+
console.log(`${severity} ${insight.type.padEnd(12)} ${insight.title}${dismissed}`);
|
|
41
|
+
if (insight.recommendation) {
|
|
42
|
+
console.log(` Action: ${insight.recommendation.action}${insight.recommendation.target ? ` \u2192 ${insight.recommendation.target}` : ""}`);
|
|
43
|
+
console.log(` Reason: ${insight.recommendation.reason}`);
|
|
44
|
+
}
|
|
45
|
+
if (insight.cause) {
|
|
46
|
+
console.log(` Cause: ${insight.cause.cause}${insight.cause.competitorDomain ? ` (${insight.cause.competitorDomain})` : ""}`);
|
|
47
|
+
}
|
|
48
|
+
console.log("");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function dismissInsight(project, id, opts) {
|
|
52
|
+
const client = createApiClient();
|
|
53
|
+
const result = await client.dismissInsight(project, id);
|
|
54
|
+
if (isMachineFormat(opts.format)) {
|
|
55
|
+
console.log(JSON.stringify(result, null, 2));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
console.log(`Insight ${id} dismissed.`);
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
dismissInsight,
|
|
62
|
+
listInsights
|
|
63
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HISTORY_WINDOW_RUNS,
|
|
3
|
+
IntelligenceService
|
|
4
|
+
} from "./chunk-GO2J7SYT.js";
|
|
5
|
+
import "./chunk-MMEO22MF.js";
|
|
6
|
+
import "./chunk-DGVUTH7W.js";
|
|
7
|
+
import "./chunk-PITHTCAX.js";
|
|
8
|
+
import "./chunk-7B2Q4NJE.js";
|
|
9
|
+
import "./chunk-63ISSSGX.js";
|
|
10
|
+
import "./chunk-D6COIM3U.js";
|
|
11
|
+
import "./chunk-MLKGABMK.js";
|
|
12
|
+
export {
|
|
13
|
+
HISTORY_WINDOW_RUNS,
|
|
14
|
+
IntelligenceService
|
|
15
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
isMachineFormat
|
|
12
|
+
} from "./chunk-HGMYEDAQ.js";
|
|
13
|
+
import {
|
|
14
|
+
READ_ONLY_SCOPE,
|
|
15
|
+
formatIsoDate
|
|
16
|
+
} from "./chunk-D6COIM3U.js";
|
|
17
|
+
import "./chunk-MLKGABMK.js";
|
|
18
|
+
|
|
19
|
+
// src/commands/keys.ts
|
|
20
|
+
function getClient() {
|
|
21
|
+
return createApiClient();
|
|
22
|
+
}
|
|
23
|
+
function keyStatus(key) {
|
|
24
|
+
return key.revokedAt ? "revoked" : "active";
|
|
25
|
+
}
|
|
26
|
+
async function listApiKeys(format) {
|
|
27
|
+
const client = getClient();
|
|
28
|
+
const { keys } = await client.listApiKeys();
|
|
29
|
+
if (format === "json") {
|
|
30
|
+
console.log(JSON.stringify({ keys }, null, 2));
|
|
31
|
+
return;
|
|
32
|
+
} else if (format === "jsonl") {
|
|
33
|
+
emitJsonl(keys);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (keys.length === 0) {
|
|
37
|
+
console.log("No API keys found.");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
console.log(
|
|
41
|
+
`${"NAME".padEnd(20)} ${"PREFIX".padEnd(11)} ${"SCOPES".padEnd(20)} ${"REACH".padEnd(18)} ${"CREATED".padEnd(12)} ${"LAST USED".padEnd(12)} STATUS`
|
|
42
|
+
);
|
|
43
|
+
for (const key of keys) {
|
|
44
|
+
const scopes = key.scopes.join(",");
|
|
45
|
+
const lastUsed = key.lastUsedAt ? formatIsoDate(key.lastUsedAt) : "\u2014";
|
|
46
|
+
console.log(
|
|
47
|
+
`${key.name.padEnd(20)} ${key.keyPrefix.padEnd(11)} ${scopes.padEnd(20)} ${keyReach(key).padEnd(18)} ${formatIsoDate(key.createdAt).padEnd(12)} ${lastUsed.padEnd(12)} ${keyStatus(key)}`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function keyReach(key) {
|
|
52
|
+
if (!key.projectId) return "full instance";
|
|
53
|
+
if (typeof key.projectName === "string") return key.projectName;
|
|
54
|
+
return key.projectName === null ? "(deleted project)" : key.projectId.slice(0, 8);
|
|
55
|
+
}
|
|
56
|
+
async function createApiKey(opts) {
|
|
57
|
+
const explicitScopes = opts.scopes && opts.scopes.length > 0 ? opts.scopes : void 0;
|
|
58
|
+
if (opts.readOnly && explicitScopes) {
|
|
59
|
+
throw new CliError({
|
|
60
|
+
code: "CLI_USAGE_ERROR",
|
|
61
|
+
message: "--read-only cannot be combined with --scope",
|
|
62
|
+
displayMessage: 'Error: --read-only cannot be combined with --scope (it already implies the "read" scope).'
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const client = getClient();
|
|
66
|
+
const body = { name: opts.name };
|
|
67
|
+
const scopes = opts.readOnly ? [READ_ONLY_SCOPE] : explicitScopes;
|
|
68
|
+
if (scopes) body.scopes = scopes;
|
|
69
|
+
if (opts.project) {
|
|
70
|
+
const proj = await client.getProject(opts.project);
|
|
71
|
+
body.projectId = proj.id;
|
|
72
|
+
}
|
|
73
|
+
const created = await client.createApiKey(body);
|
|
74
|
+
if (isMachineFormat(opts.format)) {
|
|
75
|
+
console.log(JSON.stringify(created, null, 2));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
console.log(`API key "${created.name}" created.
|
|
79
|
+
`);
|
|
80
|
+
console.log(` Key: ${created.key}`);
|
|
81
|
+
console.log(` Prefix: ${created.keyPrefix}`);
|
|
82
|
+
console.log(` Scopes: ${created.scopes.join(", ")}`);
|
|
83
|
+
console.log(` Read-only: ${created.readOnly ? "yes" : "no"}`);
|
|
84
|
+
console.log(` Reach: ${keyReach(created)}`);
|
|
85
|
+
console.log("\nSave this now \u2014 it will not be shown again.");
|
|
86
|
+
}
|
|
87
|
+
async function showApiKeySelf(format) {
|
|
88
|
+
const client = getClient();
|
|
89
|
+
const key = await client.getApiKeySelf();
|
|
90
|
+
if (isMachineFormat(format)) {
|
|
91
|
+
console.log(JSON.stringify(key, null, 2));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
console.log(`API key "${key.name}" (${key.keyPrefix})`);
|
|
95
|
+
console.log(` Scopes: ${key.scopes.join(", ")}`);
|
|
96
|
+
console.log(` Read-only: ${key.readOnly ? "yes" : "no"}`);
|
|
97
|
+
console.log(` Operator: ${key.operator === true ? "yes" : "no"}`);
|
|
98
|
+
console.log(` Reach: ${keyReach(key)}`);
|
|
99
|
+
console.log(` Status: ${keyStatus(key)}`);
|
|
100
|
+
}
|
|
101
|
+
async function revokeApiKey(id, format) {
|
|
102
|
+
const client = getClient();
|
|
103
|
+
const key = await client.revokeApiKey(id);
|
|
104
|
+
if (isMachineFormat(format)) {
|
|
105
|
+
console.log(JSON.stringify(key, null, 2));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
console.log(`API key "${key.name}" (${key.keyPrefix}) revoked.`);
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
createApiKey,
|
|
112
|
+
keyReach,
|
|
113
|
+
listApiKeys,
|
|
114
|
+
revokeApiKey,
|
|
115
|
+
showApiKeySelf
|
|
116
|
+
};
|