netlify 27.17.0 → 27.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/base-command.d.ts +1 -1
- package/dist/commands/base-command.js +33 -4
- package/dist/commands/deploy/deploy.js +9 -0
- package/dist/commands/init/index.js +14 -1
- package/dist/commands/init/init.d.ts +5 -1
- package/dist/commands/init/init.js +49 -7
- package/dist/commands/login/index.js +3 -1
- package/dist/commands/login/login-check.js +1 -1
- package/dist/commands/login/login.js +8 -0
- package/dist/commands/logout/logout.js +1 -1
- package/dist/commands/logs/index.js +2 -7
- package/dist/commands/logs/log-api.d.ts +5 -2
- package/dist/commands/logs/log-api.js +7 -4
- package/dist/commands/logs/logs.d.ts +2 -1
- package/dist/commands/logs/logs.js +39 -7
- package/dist/commands/logs/sources/server.d.ts +3 -1
- package/dist/commands/logs/sources/server.js +6 -2
- package/dist/commands/status/status.js +21 -2
- package/dist/lib/secure-storage.d.ts +8 -0
- package/dist/lib/secure-storage.js +98 -0
- package/dist/utils/agent-detection.js +1 -1
- package/dist/utils/command-helpers.d.ts +1 -1
- package/dist/utils/command-helpers.js +6 -7
- package/dist/utils/deploy/deploy-urls.d.ts +3 -0
- package/dist/utils/deploy/deploy-urls.js +12 -0
- package/dist/utils/init/agent-location.d.ts +6 -0
- package/dist/utils/init/agent-location.js +22 -0
- package/dist/utils/init/agent-mcp-config.d.ts +30 -0
- package/dist/utils/init/agent-mcp-config.js +206 -0
- package/dist/utils/init/agent-mcp.d.ts +57 -0
- package/dist/utils/init/agent-mcp.js +539 -0
- package/dist/utils/init/agent-skills-refresh-worker.d.ts +2 -0
- package/dist/utils/init/agent-skills-refresh-worker.js +17 -0
- package/dist/utils/init/agent-skills-refresh.d.ts +37 -0
- package/dist/utils/init/agent-skills-refresh.js +138 -0
- package/dist/utils/init/agent-skills-state.d.ts +16 -0
- package/dist/utils/init/agent-skills-state.js +42 -0
- package/dist/utils/init/agent-skills.d.ts +41 -2
- package/dist/utils/init/agent-skills.js +104 -21
- package/dist/utils/types.d.ts +5 -1
- package/package.json +5 -4
|
@@ -24,7 +24,7 @@ export declare function storeToken(globalConfig: Awaited<ReturnType<typeof getGl
|
|
|
24
24
|
name?: string;
|
|
25
25
|
email?: string;
|
|
26
26
|
accessToken: string;
|
|
27
|
-
}): void
|
|
27
|
+
}): Promise<void>;
|
|
28
28
|
/** Base command class that provides tracking and config initialization */
|
|
29
29
|
export default class BaseCommand extends Command {
|
|
30
30
|
#private;
|
|
@@ -14,11 +14,13 @@ import debug from 'debug';
|
|
|
14
14
|
import { findUp } from 'find-up';
|
|
15
15
|
import { deepMerge, pick } from '../utils/object-utilities.js';
|
|
16
16
|
import { getAgent } from '../lib/http-agent.js';
|
|
17
|
+
import { skipKeychainMigrationPrompt, writeAuthTokenForStorage } from '../lib/secure-storage.js';
|
|
17
18
|
import { NETLIFY_CYAN, USER_AGENT, chalk, logAndThrowError, logJson, exit, getRequestUserAgent, getToken, log, version, normalizeConfig, padLeft, pollForToken, sortOptions, warn, logError, } from '../utils/command-helpers.js';
|
|
18
19
|
import { handleOptionError, isOptionError } from '../utils/command-error-handler.js';
|
|
19
20
|
import { EXIT_CODES } from '../utils/exit-codes.js';
|
|
20
21
|
import { getFrameworksAPIPaths } from '../utils/frameworks-api.js';
|
|
21
22
|
import { getSiteByName } from '../utils/get-site.js';
|
|
23
|
+
import { showAgentSkillsRefreshNotice, startAgentSkillsRefresh } from '../utils/init/agent-skills-refresh.js';
|
|
22
24
|
import { getLocalApiTestOpts } from '../utils/local-api-test-opts.js';
|
|
23
25
|
import { buildAuthorizeUrl } from '../utils/login-url.js';
|
|
24
26
|
import openBrowser from '../utils/open-browser.js';
|
|
@@ -53,6 +55,25 @@ const COMMANDS_WITHOUT_WORKSPACE_OPTIONS = new Set([
|
|
|
53
55
|
* A list of commands where we need to fetch featureflags for config resolution
|
|
54
56
|
*/
|
|
55
57
|
const COMMANDS_WITH_FEATURE_FLAGS = new Set(['build', 'dev', 'deploy']);
|
|
58
|
+
/**
|
|
59
|
+
* Commands that skip the background refresh of Netlify skills. `init` syncs them itself.
|
|
60
|
+
*/
|
|
61
|
+
const COMMANDS_WITHOUT_SKILLS_REFRESH = new Set(['init', 'completion']);
|
|
62
|
+
const refreshAgentSkillsInBackground = async (command) => {
|
|
63
|
+
const { repositoryRoot } = command.netlify;
|
|
64
|
+
if (!repositoryRoot || COMMANDS_WITHOUT_SKILLS_REFRESH.has(command.name())) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
if (!process.argv.includes('--silent')) {
|
|
69
|
+
await showAgentSkillsRefreshNotice({ repositoryRoot });
|
|
70
|
+
}
|
|
71
|
+
await startAgentSkillsRefresh({ repositoryRoot });
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
debug(`${command.name()}:skills`)(error);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
56
77
|
/**
|
|
57
78
|
* Names of options whose values should be scrubbed
|
|
58
79
|
*/
|
|
@@ -114,7 +135,9 @@ async function getRepositoryRoot(cwd) {
|
|
|
114
135
|
return join(res, '..');
|
|
115
136
|
}
|
|
116
137
|
}
|
|
117
|
-
export function storeToken(globalConfig, { userId, name, email, accessToken }) {
|
|
138
|
+
export async function storeToken(globalConfig, { userId, name, email, accessToken }) {
|
|
139
|
+
globalConfig.set('userId', userId);
|
|
140
|
+
const mode = await writeAuthTokenForStorage(userId, accessToken);
|
|
118
141
|
const userData = deepMerge(globalConfig.get(`users.${userId}`), {
|
|
119
142
|
id: userId,
|
|
120
143
|
name,
|
|
@@ -127,7 +150,8 @@ export function storeToken(globalConfig, { userId, name, email, accessToken }) {
|
|
|
127
150
|
},
|
|
128
151
|
},
|
|
129
152
|
});
|
|
130
|
-
|
|
153
|
+
if (mode === 'keychain')
|
|
154
|
+
delete userData.auth?.token;
|
|
131
155
|
globalConfig.set(`users.${userId}`, userData);
|
|
132
156
|
}
|
|
133
157
|
/** Base command class that provides tracking and config initialization */
|
|
@@ -185,6 +209,7 @@ export default class BaseCommand extends Command {
|
|
|
185
209
|
debug(`${commandName}:preAction`)('start');
|
|
186
210
|
this.analytics.startTime = process.hrtime.bigint();
|
|
187
211
|
await this.init(actionCommand);
|
|
212
|
+
await refreshAgentSkillsInBackground(actionCommand);
|
|
188
213
|
debug(`${commandName}:preAction`)('end');
|
|
189
214
|
});
|
|
190
215
|
// Wrap the command's action() to set exitOverride when action is registered.
|
|
@@ -416,12 +441,12 @@ export default class BaseCommand extends Command {
|
|
|
416
441
|
if (!userId) {
|
|
417
442
|
return logAndThrowError('Could not retrieve user ID from Netlify API');
|
|
418
443
|
}
|
|
419
|
-
storeToken(this.netlify.globalConfig, { userId, name, email, accessToken });
|
|
420
444
|
await identify({
|
|
421
445
|
name,
|
|
422
446
|
email,
|
|
423
447
|
userId,
|
|
424
448
|
});
|
|
449
|
+
await storeToken(this.netlify.globalConfig, { userId, name, email, accessToken });
|
|
425
450
|
await track('user_login', {
|
|
426
451
|
email,
|
|
427
452
|
});
|
|
@@ -505,7 +530,11 @@ export default class BaseCommand extends Command {
|
|
|
505
530
|
// Retrieve Site id and build state from the state.json
|
|
506
531
|
// ==================================================
|
|
507
532
|
const state = new LocalState(this.workingDir);
|
|
508
|
-
const
|
|
533
|
+
const isDiscardingStoredToken = actionCommand.name() === 'logout' || (actionCommand.name() === 'login' && Boolean(flags.new));
|
|
534
|
+
if (isDiscardingStoredToken)
|
|
535
|
+
skipKeychainMigrationPrompt();
|
|
536
|
+
const [token, tokenLocation] = await getToken(flags.auth);
|
|
537
|
+
this.setAnalyticsPayload({ authTokenSource: tokenLocation });
|
|
509
538
|
const apiUrlOpts = {
|
|
510
539
|
userAgent: getRequestUserAgent(),
|
|
511
540
|
};
|
|
@@ -565,6 +565,9 @@ const printResults = ({ deployToProduction, uploadSourceZip, json, results, prod
|
|
|
565
565
|
'Function logs': terminalLink(results.functionLogsUrl, results.functionLogsUrl, { fallback: false }),
|
|
566
566
|
'Edge function Logs': terminalLink(results.edgeFunctionLogsUrl, results.edgeFunctionLogsUrl, { fallback: false }),
|
|
567
567
|
};
|
|
568
|
+
if (results.serverLogsUrl) {
|
|
569
|
+
msgData['Server logs'] = terminalLink(results.serverLogsUrl, results.serverLogsUrl, { fallback: false });
|
|
570
|
+
}
|
|
568
571
|
log('');
|
|
569
572
|
// Note: this is leakily mimicking the @netlify/build heading style
|
|
570
573
|
log(chalk.cyanBright.bold(`🚀 Deploy complete\n${'─'.repeat(64)}`));
|
|
@@ -579,6 +582,9 @@ const printResults = ({ deployToProduction, uploadSourceZip, json, results, prod
|
|
|
579
582
|
function_logs: results.functionLogsUrl,
|
|
580
583
|
edge_function_logs: results.edgeFunctionLogsUrl,
|
|
581
584
|
};
|
|
585
|
+
if (results.serverLogsUrl) {
|
|
586
|
+
jsonData.server_logs = results.serverLogsUrl;
|
|
587
|
+
}
|
|
582
588
|
if (deployToProduction) {
|
|
583
589
|
jsonData.url = results.siteUrl;
|
|
584
590
|
}
|
|
@@ -602,6 +608,9 @@ const printResults = ({ deployToProduction, uploadSourceZip, json, results, prod
|
|
|
602
608
|
log(`\nBuild logs: <${results.logsUrl}>`);
|
|
603
609
|
log(`Function logs: <${results.functionLogsUrl}>`);
|
|
604
610
|
log(`Edge function logs: <${results.edgeFunctionLogsUrl}>`);
|
|
611
|
+
if (results.serverLogsUrl) {
|
|
612
|
+
log(`Server logs: <${results.serverLogsUrl}>`);
|
|
613
|
+
}
|
|
605
614
|
if (!deployToProduction) {
|
|
606
615
|
log();
|
|
607
616
|
log('If everything looks good on your draft URL, deploy it to your main project URL with the --prod flag:');
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
import { Option } from 'commander';
|
|
1
2
|
import terminalLink from 'terminal-link';
|
|
3
|
+
import { AUTO_UPDATE_ENV } from '../../utils/init/agent-skills-refresh.js';
|
|
2
4
|
export const createInitCommand = (program) => program
|
|
3
5
|
.command('init')
|
|
4
6
|
.description('Configure continuous deployment for a new or existing project. To create a new project without continuous deployment, use `netlify sites:create`')
|
|
5
7
|
.option('-m, --manual', 'Manually configure a git remote for CI')
|
|
6
8
|
.option('--git-remote-name <name>', 'Name of Git remote to use. e.g. "origin"')
|
|
7
|
-
.option('--skip-agent-setup', 'Skip installing Netlify skills for AI coding agents
|
|
9
|
+
.option('--skip-agent-setup', 'Skip installing Netlify skills and adding the Netlify MCP server for AI coding agents')
|
|
10
|
+
.option('--skip-mcp-setup', 'Skip adding the Netlify MCP server to your AI coding agents')
|
|
11
|
+
.addOption(new Option('--mcp-scope <scope>', 'Add the Netlify MCP server for this project only, or for your user across all projects')
|
|
12
|
+
.choices(['project', 'user'])
|
|
13
|
+
.default('project'))
|
|
14
|
+
.option('--reset-mcp-setup', 'Forget your saved Netlify MCP server choices and ask which AI coding agents to set up')
|
|
8
15
|
.option('--reset-context', 'Replace locally edited Netlify skills with the latest release, and migrate or delete edited copies under renamed or deprecated names')
|
|
9
16
|
.addHelpText('after', () => {
|
|
10
17
|
const docsUrl = 'https://docs.netlify.com/cli/get-started/';
|
|
11
18
|
return `
|
|
19
|
+
Other commands keep the installed Netlify skills up to date in the background, checking at most once an hour.
|
|
20
|
+
Set ${AUTO_UPDATE_ENV}=false to turn that off.
|
|
21
|
+
|
|
12
22
|
For more information about getting started with Netlify CLI, see ${terminalLink(docsUrl, docsUrl, { fallback: false })}
|
|
13
23
|
`;
|
|
14
24
|
})
|
|
@@ -16,6 +26,9 @@ For more information about getting started with Netlify CLI, see ${terminalLink(
|
|
|
16
26
|
const { init } = await import('./init.js');
|
|
17
27
|
await init(options, command, {
|
|
18
28
|
setupAgentSkills: !options.skipAgentSetup,
|
|
29
|
+
setupAgentMcp: !options.skipAgentSetup && !options.skipMcpSetup,
|
|
30
|
+
resetMcpSetup: Boolean(options.resetMcpSetup),
|
|
31
|
+
mcpScope: options.mcpScope === 'user' ? 'user' : 'project',
|
|
19
32
|
resetContext: Boolean(options.resetContext),
|
|
20
33
|
});
|
|
21
34
|
});
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { OptionValues } from 'commander';
|
|
2
2
|
import type BaseCommand from '../base-command.js';
|
|
3
3
|
import type { SiteInfo } from '../../utils/types.js';
|
|
4
|
+
import { type McpScope } from '../../utils/init/agent-mcp.js';
|
|
4
5
|
import { type InitExitCode } from './constants.js';
|
|
5
6
|
type InitExitMessageCustomizer = (code: InitExitCode, defaultMessage: string) => string | undefined;
|
|
6
7
|
type InitExtraOptions = {
|
|
7
8
|
customizeExitMessage?: InitExitMessageCustomizer | undefined;
|
|
8
9
|
exitAfterConfiguringRepo?: boolean | undefined;
|
|
9
10
|
setupAgentSkills?: boolean | undefined;
|
|
11
|
+
setupAgentMcp?: boolean | undefined;
|
|
10
12
|
resetContext?: boolean | undefined;
|
|
13
|
+
resetMcpSetup?: boolean | undefined;
|
|
14
|
+
mcpScope?: McpScope | undefined;
|
|
11
15
|
};
|
|
12
|
-
export declare const init: (options: OptionValues, command: BaseCommand, { customizeExitMessage, exitAfterConfiguringRepo, setupAgentSkills: shouldSetupAgentSkills, resetContext, }?: InitExtraOptions) => Promise<SiteInfo>;
|
|
16
|
+
export declare const init: (options: OptionValues, command: BaseCommand, { customizeExitMessage, exitAfterConfiguringRepo, setupAgentSkills: shouldSetupAgentSkills, setupAgentMcp: shouldSetupAgentMcp, resetContext, resetMcpSetup, mcpScope, }?: InitExtraOptions) => Promise<SiteInfo>;
|
|
13
17
|
export {};
|
|
14
18
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -7,6 +7,8 @@ import { configureRepo } from '../../utils/init/config.js';
|
|
|
7
7
|
import { track } from '../../utils/telemetry/index.js';
|
|
8
8
|
import { link } from '../link/link.js';
|
|
9
9
|
import { sitesCreate } from '../sites/sites-create.js';
|
|
10
|
+
import { findProjectSetupBlocker } from '../../utils/init/agent-location.js';
|
|
11
|
+
import { setupAgentMcp } from '../../utils/init/agent-mcp.js';
|
|
10
12
|
import { setupAgentSkills } from '../../utils/init/agent-skills.js';
|
|
11
13
|
import { getBuildSettings, saveNetlifyToml } from '../../utils/init/utils.js';
|
|
12
14
|
import { LINKED_EXISTING_SITE_EXIT_CODE, LINKED_NEW_SITE_EXIT_CODE } from './constants.js';
|
|
@@ -213,9 +215,8 @@ const logExistingRepoSetupAndExit = ({ repoUrl, siteName, customizeExitMessage,
|
|
|
213
215
|
// TODO add support for changing GitHub repo in site:config command
|
|
214
216
|
exit();
|
|
215
217
|
};
|
|
216
|
-
const installAgentSkills = async (
|
|
217
|
-
|
|
218
|
-
const result = await setupAgentSkills({ workingDir: command.netlify.repositoryRoot, reset });
|
|
218
|
+
const installAgentSkills = async (workingDir, reset) => {
|
|
219
|
+
const result = await setupAgentSkills({ workingDir, reset });
|
|
219
220
|
await track('sites_agentSkillsSetup', {
|
|
220
221
|
installed: result.installed,
|
|
221
222
|
directories: result.directories,
|
|
@@ -224,21 +225,62 @@ const installAgentSkills = async (command, reset) => {
|
|
|
224
225
|
...result.summary,
|
|
225
226
|
});
|
|
226
227
|
};
|
|
227
|
-
|
|
228
|
+
const addAgentMcp = async (command, reset, scope) => {
|
|
229
|
+
const { repositoryRoot, state } = command.netlify;
|
|
230
|
+
const { selection, agents, failed = false, } = await setupAgentMcp({
|
|
231
|
+
workingDir: repositoryRoot,
|
|
232
|
+
store: state,
|
|
233
|
+
scope,
|
|
234
|
+
reset,
|
|
235
|
+
});
|
|
236
|
+
await track('sites_agentMcpSetup', { selection, agents, failed, scope, resetMcpSetup: reset });
|
|
237
|
+
};
|
|
238
|
+
const setUpAgents = async (command, { skills, mcp, reset, resetMcp, mcpScope, }) => {
|
|
239
|
+
if (!skills && !mcp) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const { repositoryRoot } = command.netlify;
|
|
243
|
+
log();
|
|
244
|
+
const blocker = await findProjectSetupBlocker(repositoryRoot);
|
|
245
|
+
const skillsBlocked = skills && blocker !== undefined;
|
|
246
|
+
const mcpBlocked = mcp && blocker !== undefined && (blocker.place === 'root' || mcpScope === 'project');
|
|
247
|
+
if (blocker && (skillsBlocked || mcpBlocked)) {
|
|
248
|
+
const skipped = [skillsBlocked && 'Netlify skills', mcpBlocked && 'the Netlify MCP server']
|
|
249
|
+
.filter(Boolean)
|
|
250
|
+
.join(' and ');
|
|
251
|
+
log(`Skipped setting up ${skipped}: ${blocker.reason}.`);
|
|
252
|
+
log(` Run ${chalk.cyanBright.bold(`${netlifyCommand()} init`)} from your project folder to set up ${skipped} there.`);
|
|
253
|
+
await track('sites_agentSetupSkipped', { skills: skillsBlocked, mcp: mcpBlocked });
|
|
254
|
+
}
|
|
255
|
+
if (skills && !skillsBlocked) {
|
|
256
|
+
await installAgentSkills(repositoryRoot, reset);
|
|
257
|
+
}
|
|
258
|
+
if (mcp && !mcpBlocked) {
|
|
259
|
+
await addAgentMcp(command, resetMcp, mcpScope);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
export const init = async (options, command, { customizeExitMessage, exitAfterConfiguringRepo = false, setupAgentSkills: shouldSetupAgentSkills = false, setupAgentMcp: shouldSetupAgentMcp = false, resetContext = false, resetMcpSetup = false, mcpScope = 'project', } = {}) => {
|
|
228
263
|
command.setAnalyticsPayload({
|
|
229
264
|
manual: options.manual,
|
|
230
265
|
force: options.force,
|
|
231
266
|
skipAgentSetup: options.skipAgentSetup,
|
|
267
|
+
skipMcpSetup: options.skipMcpSetup,
|
|
232
268
|
resetContext: options.resetContext,
|
|
269
|
+
resetMcpSetup: options.resetMcpSetup,
|
|
270
|
+
mcpScope,
|
|
233
271
|
});
|
|
234
272
|
const { repositoryRoot, state } = command.netlify;
|
|
235
273
|
// Check logged in status
|
|
236
274
|
await command.authenticate();
|
|
237
275
|
// Add .netlify to .gitignore file
|
|
238
276
|
await ensureNetlifyIgnore(repositoryRoot);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
277
|
+
await setUpAgents(command, {
|
|
278
|
+
skills: shouldSetupAgentSkills,
|
|
279
|
+
mcp: shouldSetupAgentMcp,
|
|
280
|
+
reset: resetContext,
|
|
281
|
+
resetMcp: resetMcpSetup,
|
|
282
|
+
mcpScope,
|
|
283
|
+
});
|
|
242
284
|
const linkedSiteInfo = await getLinkedSiteInfo(command);
|
|
243
285
|
if (linkedSiteInfo && getRepoUrl(linkedSiteInfo) && !options.force) {
|
|
244
286
|
logExistingAndExit({ siteInfo: linkedSiteInfo });
|
|
@@ -2,7 +2,9 @@ import terminalLink from 'terminal-link';
|
|
|
2
2
|
export const createLoginCommand = (program) => program
|
|
3
3
|
.command('login')
|
|
4
4
|
.description(`Login to your Netlify account
|
|
5
|
-
Opens a web browser to acquire an OAuth token
|
|
5
|
+
Opens a web browser to acquire an OAuth token, which is stored in your operating system's keychain
|
|
6
|
+
(macOS Keychain, Windows Credential Manager or Linux Secret Service) when available.
|
|
7
|
+
To store it in a plaintext config file instead, set NETLIFY_USE_LEGACY_AUTH_STORAGE=1. This is not recommended.`)
|
|
6
8
|
.option('--new', 'Login to new Netlify account')
|
|
7
9
|
.option('--request <message>', 'Create a login ticket for agent/human-in-the-loop auth')
|
|
8
10
|
.option('--check <ticket-id>', 'Check the status of a login ticket created with --request')
|
|
@@ -32,7 +32,7 @@ export const loginCheck = async (options, apiOpts, globalConfig) => {
|
|
|
32
32
|
if (!user.id) {
|
|
33
33
|
return logAndThrowError('Could not retrieve user ID from Netlify API');
|
|
34
34
|
}
|
|
35
|
-
storeToken(globalConfig, {
|
|
35
|
+
await storeToken(globalConfig, {
|
|
36
36
|
userId: user.id,
|
|
37
37
|
name: user.full_name,
|
|
38
38
|
email: user.email,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chalk, exit, getToken, log, logAndThrowError } from '../../utils/command-helpers.js';
|
|
2
|
+
import { isInteractive } from '../../utils/scripted-commands.js';
|
|
2
3
|
const msg = function (location) {
|
|
3
4
|
switch (location) {
|
|
4
5
|
case 'env':
|
|
@@ -7,6 +8,8 @@ const msg = function (location) {
|
|
|
7
8
|
return 'via CLI --auth flag';
|
|
8
9
|
case 'config':
|
|
9
10
|
return 'via netlify config on your machine';
|
|
11
|
+
case 'keychain':
|
|
12
|
+
return "via your operating system's keychain";
|
|
10
13
|
default:
|
|
11
14
|
return '';
|
|
12
15
|
}
|
|
@@ -30,6 +33,11 @@ export const login = async (options, command) => {
|
|
|
30
33
|
if (accessToken && !options.new) {
|
|
31
34
|
log(`Already logged in ${msg(location)}`);
|
|
32
35
|
log();
|
|
36
|
+
// Agents run this when an older @netlify/mcp, which only reads config.json, says they're logged out
|
|
37
|
+
if (location === 'keychain' && !isInteractive()) {
|
|
38
|
+
log(`If another tool says you're not logged in, it may not support tokens stored in your operating system's keychain yet. For the Netlify MCP server, update ${chalk.cyanBright('@netlify/mcp')}, then restart your agent or editor.`);
|
|
39
|
+
log();
|
|
40
|
+
}
|
|
33
41
|
log(`Run ${chalk.cyanBright('netlify status')} for account details`);
|
|
34
42
|
log();
|
|
35
43
|
log(`or run ${chalk.cyanBright('netlify switch')} to switch accounts`);
|
|
@@ -9,7 +9,7 @@ export const logout = async (_options, command) => {
|
|
|
9
9
|
exit();
|
|
10
10
|
}
|
|
11
11
|
await track('user_logout');
|
|
12
|
-
//
|
|
12
|
+
// Keep stored tokens so `netlify switch` can return to this account without logging in again
|
|
13
13
|
command.netlify.globalConfig.set('userId', null);
|
|
14
14
|
if (location === 'env') {
|
|
15
15
|
log('The "process.env.NETLIFY_AUTH_TOKEN" is still set in your terminal session');
|
|
@@ -74,18 +74,13 @@ export const createLogsCommand = (program) => {
|
|
|
74
74
|
.command('logs')
|
|
75
75
|
.alias('log')
|
|
76
76
|
.description('View logs from your project')
|
|
77
|
-
.addOption(new Option('-s, --source <type...>', 'Log sources to include. Defaults to functions
|
|
78
|
-
'functions',
|
|
79
|
-
'edge-functions',
|
|
80
|
-
'deploy',
|
|
81
|
-
'server',
|
|
82
|
-
]))
|
|
77
|
+
.addOption(new Option('-s, --source <type...>', 'Log sources to include. Defaults to functions, edge-functions and server').choices(['functions', 'edge-functions', 'deploy', 'server']))
|
|
83
78
|
.addOption(new Option('--function <name...>', 'Filter to specific functions by name'))
|
|
84
79
|
.addOption(new Option('--edge-function <name...>', 'Filter to specific edge functions by name or path'))
|
|
85
80
|
.addOption(new Option('--since <time>', 'Start of the historical log window. Accepts a duration (e.g. 10m, 1h, 24h) or an ISO 8601 timestamp. Defaults to 10m'))
|
|
86
81
|
.addOption(new Option('--until <time>', 'End of the historical log window. Accepts a duration or an ISO 8601 timestamp (defaults to now)'))
|
|
87
82
|
.addOption(new Option('-f, --follow', 'Stream logs in real time instead of showing historical logs'))
|
|
88
|
-
.addOption(new Option('-u, --url <url>', 'Show logs for the deploy behind the given URL. Supports deploy permalinks and branch subdomains.
|
|
83
|
+
.addOption(new Option('-u, --url <url>', 'Show logs for the deploy behind the given URL. Supports deploy permalinks and branch subdomains. Server logs support branch subdomains only.'))
|
|
89
84
|
.addOption(new Option('-d, --deploy-id <deploy-id>', 'Show logs for a specific deploy by ID, including failed builds. Can be used with all sources except server.'))
|
|
90
85
|
.addOption(new Option('-l, --level <levels...>', `Log levels to include. Choices are:${CLI_LOG_LEVEL_CHOICES_STRING}`))
|
|
91
86
|
.addOption(new Option('--json', 'Output logs as JSON Lines'))
|
|
@@ -54,11 +54,14 @@ export declare const hostnamesForSite: (siteInfo: {
|
|
|
54
54
|
canonicalHostnames: Set<string>;
|
|
55
55
|
netlifyAppBaseHost: string | null;
|
|
56
56
|
};
|
|
57
|
-
export declare const
|
|
57
|
+
export declare const resolveDeployFromUrl: (urlInput: string, client: NetlifyAPI, siteId: string, siteInfo: {
|
|
58
58
|
name?: string;
|
|
59
59
|
custom_domain?: string;
|
|
60
60
|
domain_aliases?: string[];
|
|
61
61
|
url?: string;
|
|
62
62
|
ssl_url?: string;
|
|
63
|
-
}) => Promise<
|
|
63
|
+
}) => Promise<{
|
|
64
|
+
deployId?: string;
|
|
65
|
+
branch?: string;
|
|
66
|
+
}>;
|
|
64
67
|
//# sourceMappingURL=log-api.d.ts.map
|
|
@@ -169,7 +169,9 @@ export const hostnamesForSite = (siteInfo) => {
|
|
|
169
169
|
}
|
|
170
170
|
return { canonicalHostnames: canonical, netlifyAppBaseHost };
|
|
171
171
|
};
|
|
172
|
-
|
|
172
|
+
// resolveDeployFromUrl returns nothing for the project's production URLs, a
|
|
173
|
+
// deploy ID for a permalink, and a deploy ID with its branch for a branch subdomain.
|
|
174
|
+
export const resolveDeployFromUrl = async (urlInput, client, siteId, siteInfo) => {
|
|
173
175
|
let parsed;
|
|
174
176
|
try {
|
|
175
177
|
parsed = new URL(urlInput.includes('://') ? urlInput : `https://${urlInput}`);
|
|
@@ -180,7 +182,7 @@ export const resolveDeployIdFromUrl = async (urlInput, client, siteId, siteInfo)
|
|
|
180
182
|
const hostname = parsed.hostname.toLowerCase();
|
|
181
183
|
const { canonicalHostnames, netlifyAppBaseHost } = hostnamesForSite(siteInfo);
|
|
182
184
|
if (canonicalHostnames.has(hostname)) {
|
|
183
|
-
return
|
|
185
|
+
return {};
|
|
184
186
|
}
|
|
185
187
|
const mismatchError = new Error(`The URL ${urlInput} doesn't seem to match the linked project${siteInfo.name ? ` (${siteInfo.name})` : ''}.`);
|
|
186
188
|
if (!netlifyAppBaseHost || !hostname.endsWith(`.netlify.app`)) {
|
|
@@ -197,13 +199,14 @@ export const resolveDeployIdFromUrl = async (urlInput, client, siteId, siteInfo)
|
|
|
197
199
|
throw mismatchError;
|
|
198
200
|
}
|
|
199
201
|
if (DEPLOY_ID_RE.test(prefix)) {
|
|
200
|
-
return prefix;
|
|
202
|
+
return { deployId: prefix };
|
|
201
203
|
}
|
|
202
204
|
const deploys = (await client.listSiteDeploys({ siteId, branch: prefix, per_page: 20 }));
|
|
203
205
|
const ready = deploys.find((deploy) => deploy.state === 'ready');
|
|
204
206
|
if (!ready) {
|
|
205
207
|
throw new Error(`No ready deploys found for branch ${prefix}`);
|
|
206
208
|
}
|
|
207
|
-
|
|
209
|
+
// The subdomain holds a slug of the branch, so its name comes from the deploy.
|
|
210
|
+
return { deployId: ready.id, branch: ready.branch ?? prefix };
|
|
208
211
|
};
|
|
209
212
|
//# sourceMappingURL=log-api.js.map
|
|
@@ -3,7 +3,7 @@ import type BaseCommand from '../base-command.js';
|
|
|
3
3
|
import type { LogsOptionValues } from './option_values.js';
|
|
4
4
|
type Source = 'functions' | 'edge-functions' | 'deploy' | 'server';
|
|
5
5
|
export declare const logsCommand: (options: LogsOptionValues, command: BaseCommand) => Promise<undefined>;
|
|
6
|
-
export declare const runFollowMode: ({ sources, client, siteId, accessToken, deployId, deployTargeted, functionNames, edgeFunctionNames, levelsToPrint, json, }: {
|
|
6
|
+
export declare const runFollowMode: ({ sources, client, siteId, accessToken, deployId, deployTargeted, functionNames, edgeFunctionNames, levelsToPrint, serverBranches, json, }: {
|
|
7
7
|
sources: Source[];
|
|
8
8
|
client: NetlifyAPI;
|
|
9
9
|
siteId: string;
|
|
@@ -13,6 +13,7 @@ export declare const runFollowMode: ({ sources, client, siteId, accessToken, dep
|
|
|
13
13
|
functionNames: string[];
|
|
14
14
|
edgeFunctionNames: string[];
|
|
15
15
|
levelsToPrint: string[];
|
|
16
|
+
serverBranches: string[];
|
|
16
17
|
json: boolean;
|
|
17
18
|
}) => Promise<undefined>;
|
|
18
19
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { chalk, log, logAndThrowError, logError, netlifyCommand, warn } from '../../utils/command-helpers.js';
|
|
2
|
-
import { createColorAssigner, DEPLOY_ID_RE, formatJsonLine, formatLogLine, parseTimeValue,
|
|
2
|
+
import { createColorAssigner, DEPLOY_ID_RE, formatJsonLine, formatLogLine, parseTimeValue, resolveDeployFromUrl, SOURCE_INDICATORS, SOURCE_LABELS, } from './log-api.js';
|
|
3
3
|
import { LOG_LEVELS_LIST, CLI_LOG_LEVEL_CHOICES_STRING } from './log-levels.js';
|
|
4
4
|
import { fetchDeployHistoricalLogs, findCurrentBuildingDeploy, findLatestFinishedDeploy, findLatestReadyDeploy, isDeployFinished, streamDeploy, } from './sources/deploy.js';
|
|
5
5
|
import { fetchEdgeFunctionHistoricalLogs, streamEdgeFunctions } from './sources/edge-functions.js';
|
|
@@ -8,6 +8,18 @@ import { fetchServerHistoricalLogs, streamServer } from './sources/server.js';
|
|
|
8
8
|
const VALID_SOURCES = ['functions', 'edge-functions', 'deploy', 'server'];
|
|
9
9
|
const DEFAULT_SINCE = '10m';
|
|
10
10
|
const DEPLOY_STREAM_IDLE_CLOSE_MS = 3_000;
|
|
11
|
+
// Server logs from a deploy without a branch are recorded under this branch.
|
|
12
|
+
const NO_BRANCH_PRODUCTION = '__nf-no-branch-production-traffic';
|
|
13
|
+
// getProductionBranches returns the branches that make up production, the same
|
|
14
|
+
// ones the Netlify UI shows as a server's production logs.
|
|
15
|
+
const getProductionBranches = (siteInfo) => {
|
|
16
|
+
const publishedBranch = siteInfo.published_deploy?.branch;
|
|
17
|
+
const branches = siteInfo.build_settings?.provider
|
|
18
|
+
? [siteInfo.build_settings.repo_branch, publishedBranch]
|
|
19
|
+
: // CLI deploys can have an empty branch.
|
|
20
|
+
[publishedBranch?.length ? publishedBranch : 'main'];
|
|
21
|
+
return [...new Set([...branches.filter((branch) => Boolean(branch)), NO_BRANCH_PRODUCTION])];
|
|
22
|
+
};
|
|
11
23
|
const parseSources = (rawSources) => {
|
|
12
24
|
const sources = [];
|
|
13
25
|
for (const s of rawSources) {
|
|
@@ -124,13 +136,15 @@ export const logsCommand = async (options, command) => {
|
|
|
124
136
|
}
|
|
125
137
|
if (sources.length === 0) {
|
|
126
138
|
sources = ['functions', 'edge-functions'];
|
|
139
|
+
if (siteInfo.published_deploy?.server) {
|
|
140
|
+
sources.push('server');
|
|
141
|
+
}
|
|
127
142
|
}
|
|
128
143
|
}
|
|
129
|
-
|
|
130
|
-
return logAndThrowError('Server logs cannot be filtered by deploy. Remove --deploy-id and --url, or the server source.');
|
|
131
|
-
}
|
|
144
|
+
const serverByDefault = !rawSources && sources.includes('server');
|
|
132
145
|
let deployId;
|
|
133
146
|
let deployTargeted = false;
|
|
147
|
+
let urlBranch;
|
|
134
148
|
if (options.deployId) {
|
|
135
149
|
const explicitDeployId = options.deployId.trim();
|
|
136
150
|
if (!DEPLOY_ID_RE.test(explicitDeployId)) {
|
|
@@ -144,7 +158,9 @@ export const logsCommand = async (options, command) => {
|
|
|
144
158
|
}
|
|
145
159
|
else if (options.url) {
|
|
146
160
|
try {
|
|
147
|
-
|
|
161
|
+
const resolved = await resolveDeployFromUrl(options.url, client, siteId, siteInfo);
|
|
162
|
+
deployId = resolved.deployId;
|
|
163
|
+
urlBranch = resolved.branch;
|
|
148
164
|
deployTargeted = deployId !== undefined;
|
|
149
165
|
}
|
|
150
166
|
catch (error) {
|
|
@@ -161,6 +177,18 @@ export const logsCommand = async (options, command) => {
|
|
|
161
177
|
return logAndThrowError(message);
|
|
162
178
|
}
|
|
163
179
|
}
|
|
180
|
+
// Server logs can be filtered by branch, but not by deploy.
|
|
181
|
+
if (sources.includes('server') && deployTargeted && !urlBranch) {
|
|
182
|
+
if (serverByDefault) {
|
|
183
|
+
sources = sources.filter((source) => source !== 'server');
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
return logAndThrowError(options.deployId
|
|
187
|
+
? 'Server logs cannot be filtered by deploy. Remove --deploy-id or the server source.'
|
|
188
|
+
: 'Server logs cannot be filtered by deploy. Use a branch URL instead of a deploy permalink, or remove the server source.');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const serverBranches = urlBranch ? [urlBranch] : getProductionBranches(siteInfo);
|
|
164
192
|
const now = Date.now();
|
|
165
193
|
let historicalRange;
|
|
166
194
|
if (!follow) {
|
|
@@ -213,6 +241,7 @@ export const logsCommand = async (options, command) => {
|
|
|
213
241
|
from: historicalRange.from,
|
|
214
242
|
to: historicalRange.to,
|
|
215
243
|
levelsToPrint,
|
|
244
|
+
serverBranches,
|
|
216
245
|
json,
|
|
217
246
|
timeDescription: humanizeTimeRange(sinceValue, untilValue),
|
|
218
247
|
});
|
|
@@ -231,10 +260,11 @@ export const logsCommand = async (options, command) => {
|
|
|
231
260
|
functionNames,
|
|
232
261
|
edgeFunctionNames,
|
|
233
262
|
levelsToPrint,
|
|
263
|
+
serverBranches,
|
|
234
264
|
json,
|
|
235
265
|
});
|
|
236
266
|
};
|
|
237
|
-
const runHistoricalMode = async ({ sources, client, siteId, accessToken, deployId, functionNames, edgeFunctionNames, from, to, levelsToPrint, json, timeDescription, }) => {
|
|
267
|
+
const runHistoricalMode = async ({ sources, client, siteId, accessToken, deployId, functionNames, edgeFunctionNames, from, to, levelsToPrint, serverBranches, json, timeDescription, }) => {
|
|
238
268
|
const allEntries = [];
|
|
239
269
|
if (sources.includes('deploy') && deployId) {
|
|
240
270
|
const deployEntries = await fetchDeployHistoricalLogs({
|
|
@@ -285,6 +315,7 @@ const runHistoricalMode = async ({ sources, client, siteId, accessToken, deployI
|
|
|
285
315
|
from,
|
|
286
316
|
to,
|
|
287
317
|
levels: levelsToPrint,
|
|
318
|
+
branches: serverBranches,
|
|
288
319
|
});
|
|
289
320
|
allEntries.push(...entries);
|
|
290
321
|
serverLogsTruncated = truncated;
|
|
@@ -312,7 +343,7 @@ const runHistoricalMode = async ({ sources, client, siteId, accessToken, deployI
|
|
|
312
343
|
}
|
|
313
344
|
}
|
|
314
345
|
};
|
|
315
|
-
export const runFollowMode = async ({ sources, client, siteId, accessToken, deployId, deployTargeted, functionNames, edgeFunctionNames, levelsToPrint, json, }) => {
|
|
346
|
+
export const runFollowMode = async ({ sources, client, siteId, accessToken, deployId, deployTargeted, functionNames, edgeFunctionNames, levelsToPrint, serverBranches, json, }) => {
|
|
316
347
|
const assignColor = createColorAssigner();
|
|
317
348
|
const onEntry = (entry) => {
|
|
318
349
|
const key = `${entry.source}:${entry.name}`;
|
|
@@ -355,6 +386,7 @@ export const runFollowMode = async ({ sources, client, siteId, accessToken, depl
|
|
|
355
386
|
siteId,
|
|
356
387
|
accessToken,
|
|
357
388
|
levels: levelsToPrint,
|
|
389
|
+
branches: serverBranches,
|
|
358
390
|
onEntry,
|
|
359
391
|
onError: logError,
|
|
360
392
|
});
|
|
@@ -6,15 +6,17 @@ export declare const fetchServerHistoricalLogs: (options: {
|
|
|
6
6
|
from: number;
|
|
7
7
|
to: number;
|
|
8
8
|
levels?: string[];
|
|
9
|
+
branches: string[];
|
|
9
10
|
}) => Promise<{
|
|
10
11
|
entries: LogEntry[];
|
|
11
12
|
truncated: boolean;
|
|
12
13
|
}>;
|
|
13
|
-
export declare const streamServer: ({ apiBase, siteId, accessToken, levels, onEntry, onError, intervalMs, }: {
|
|
14
|
+
export declare const streamServer: ({ apiBase, siteId, accessToken, levels, branches, onEntry, onError, intervalMs, }: {
|
|
14
15
|
apiBase: string;
|
|
15
16
|
siteId: string;
|
|
16
17
|
accessToken: string | null | undefined;
|
|
17
18
|
levels?: string[];
|
|
19
|
+
branches: string[];
|
|
18
20
|
onEntry: (entry: LogEntry) => void;
|
|
19
21
|
onError?: (error: Error) => void;
|
|
20
22
|
intervalMs?: number;
|
|
@@ -37,7 +37,7 @@ const toEntry = (line) => ({
|
|
|
37
37
|
level: line.severity ? line.severity.toUpperCase() : 'INFO',
|
|
38
38
|
message: line.body,
|
|
39
39
|
});
|
|
40
|
-
const fetchServerLogLines = async ({ apiBase, siteId, accessToken, from, to, levels, }) => {
|
|
40
|
+
const fetchServerLogLines = async ({ apiBase, siteId, accessToken, from, to, levels, branches, }) => {
|
|
41
41
|
// The API pages newest first and sends millisecond timestamps, though it
|
|
42
42
|
// orders by finer ones, so reversing is what keeps same-millisecond lines in order.
|
|
43
43
|
const lines = [];
|
|
@@ -58,6 +58,9 @@ const fetchServerLogLines = async ({ apiBase, siteId, accessToken, from, to, lev
|
|
|
58
58
|
if (severity) {
|
|
59
59
|
url.searchParams.set('severity', severity);
|
|
60
60
|
}
|
|
61
|
+
for (const branch of branches) {
|
|
62
|
+
url.searchParams.append('branch', branch);
|
|
63
|
+
}
|
|
61
64
|
const response = await debugFetch(url.toString(), {
|
|
62
65
|
headers: {
|
|
63
66
|
Authorization: `Bearer ${accessToken ?? ''}`,
|
|
@@ -79,7 +82,7 @@ export const fetchServerHistoricalLogs = async (options) => {
|
|
|
79
82
|
const { lines, truncated } = await fetchServerLogLines(options);
|
|
80
83
|
return { entries: lines.map(toEntry), truncated };
|
|
81
84
|
};
|
|
82
|
-
export const streamServer = ({ apiBase, siteId, accessToken, levels, onEntry, onError, intervalMs = POLL_INTERVAL_MS, }) => {
|
|
85
|
+
export const streamServer = ({ apiBase, siteId, accessToken, levels, branches, onEntry, onError, intervalMs = POLL_INTERVAL_MS, }) => {
|
|
83
86
|
let newest = Date.now();
|
|
84
87
|
let seen = new Map();
|
|
85
88
|
let failing = false;
|
|
@@ -93,6 +96,7 @@ export const streamServer = ({ apiBase, siteId, accessToken, levels, onEntry, on
|
|
|
93
96
|
siteId,
|
|
94
97
|
accessToken,
|
|
95
98
|
levels,
|
|
99
|
+
branches,
|
|
96
100
|
from: newest - LOOK_BACK_MS,
|
|
97
101
|
to: Date.now(),
|
|
98
102
|
});
|