Sorry, the diff of this file is too big to display
| import { createRequire as __createRequire } from 'node:module'; | ||
| import { fileURLToPath as __fileURLToPath } from 'node:url'; | ||
| import { dirname as __dirname_ } from 'node:path'; | ||
| const require = __createRequire(import.meta.url); | ||
| const __filename = __fileURLToPath(import.meta.url); | ||
| const __dirname = __dirname_(__filename); | ||
| import { | ||
| getUpdateCommand | ||
| } from "./chunk-2MDXGVZV.js"; | ||
| import { | ||
| login | ||
| } from "./chunk-AABYT6JI.js"; | ||
| import { | ||
| loginCommand | ||
| } from "./chunk-XNH2ODPG.js"; | ||
| import { | ||
| help | ||
| } from "./chunk-DOBFJJLK.js"; | ||
| import { | ||
| TelemetryClient | ||
| } from "./chunk-XB2KZC2B.js"; | ||
| import { | ||
| getFlagsSpecification, | ||
| parseArguments, | ||
| printError, | ||
| require_strip_ansi | ||
| } from "./chunk-ZLCMHY2G.js"; | ||
| import { | ||
| output_manager_default | ||
| } from "./chunk-FDJURQMQ.js"; | ||
| import { | ||
| require_source | ||
| } from "./chunk-S7KYDPEM.js"; | ||
| import { | ||
| __commonJS, | ||
| __toESM | ||
| } from "./chunk-TZ2YI2VH.js"; | ||
| // ../../node_modules/.pnpm/jaro-winkler@0.2.8/node_modules/jaro-winkler/index.js | ||
| var require_jaro_winkler = __commonJS({ | ||
| "../../node_modules/.pnpm/jaro-winkler@0.2.8/node_modules/jaro-winkler/index.js"(exports, module) { | ||
| (function(root) { | ||
| "use strict"; | ||
| function extend(a, b) { | ||
| for (var property in b) { | ||
| if (b.hasOwnProperty(property)) { | ||
| a[property] = b[property]; | ||
| } | ||
| } | ||
| return a; | ||
| } | ||
| function distance2(s1, s2, options) { | ||
| var m = 0; | ||
| var defaults = { caseSensitive: true }; | ||
| var settings = extend(defaults, options); | ||
| var i; | ||
| var j; | ||
| if (s1.length === 0 || s2.length === 0) { | ||
| return 0; | ||
| } | ||
| if (!settings.caseSensitive) { | ||
| s1 = s1.toUpperCase(); | ||
| s2 = s2.toUpperCase(); | ||
| } | ||
| if (s1 === s2) { | ||
| return 1; | ||
| } | ||
| var range = Math.floor(Math.max(s1.length, s2.length) / 2) - 1; | ||
| var s1Matches = new Array(s1.length); | ||
| var s2Matches = new Array(s2.length); | ||
| for (i = 0; i < s1.length; i++) { | ||
| var low = i >= range ? i - range : 0; | ||
| var high = i + range <= s2.length - 1 ? i + range : s2.length - 1; | ||
| for (j = low; j <= high; j++) { | ||
| if (s1Matches[i] !== true && s2Matches[j] !== true && s1[i] === s2[j]) { | ||
| ++m; | ||
| s1Matches[i] = s2Matches[j] = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| if (m === 0) { | ||
| return 0; | ||
| } | ||
| var k = 0; | ||
| var numTrans = 0; | ||
| for (i = 0; i < s1.length; i++) { | ||
| if (s1Matches[i] === true) { | ||
| for (j = k; j < s2.length; j++) { | ||
| if (s2Matches[j] === true) { | ||
| k = j + 1; | ||
| break; | ||
| } | ||
| } | ||
| if (s1[i] !== s2[j]) { | ||
| ++numTrans; | ||
| } | ||
| } | ||
| } | ||
| var weight = (m / s1.length + m / s2.length + (m - numTrans / 2) / m) / 3; | ||
| var l = 0; | ||
| var p = 0.1; | ||
| if (weight > 0.7) { | ||
| while (s1[l] === s2[l] && l < 4) { | ||
| ++l; | ||
| } | ||
| weight = weight + l * p * (1 - weight); | ||
| } | ||
| return weight; | ||
| } | ||
| if (typeof define === "function" && define.amd) { | ||
| define([], function() { | ||
| return distance2; | ||
| }); | ||
| } else if (typeof exports === "object") { | ||
| module.exports = distance2; | ||
| } else { | ||
| root.distance = distance2; | ||
| } | ||
| })(exports); | ||
| } | ||
| }); | ||
| // src/util/upgrade.ts | ||
| import { spawn } from "child_process"; | ||
| async function executeUpgrade() { | ||
| const updateCommand = await getUpdateCommand(); | ||
| const [command, ...args] = updateCommand.split(" "); | ||
| output_manager_default.log(`Upgrading Vercel CLI...`); | ||
| output_manager_default.debug(`Executing: ${updateCommand}`); | ||
| return new Promise((resolve) => { | ||
| const stdout = []; | ||
| const stderr = []; | ||
| const upgradeProcess = spawn(command, args, { | ||
| stdio: ["inherit", "pipe", "pipe"], | ||
| shell: false | ||
| }); | ||
| upgradeProcess.stdout?.on("data", (data) => { | ||
| stdout.push(data); | ||
| }); | ||
| upgradeProcess.stderr?.on("data", (data) => { | ||
| stderr.push(data); | ||
| }); | ||
| upgradeProcess.on("error", (err) => { | ||
| output_manager_default.error(`Failed to execute upgrade command: ${err.message}`); | ||
| output_manager_default.log(`You can try running the command manually: ${updateCommand}`); | ||
| resolve(1); | ||
| }); | ||
| upgradeProcess.on("close", (code) => { | ||
| if (code === 0) { | ||
| output_manager_default.success("Vercel CLI has been upgraded successfully!"); | ||
| } else { | ||
| const stdoutStr = Buffer.concat(stdout).toString(); | ||
| const stderrStr = Buffer.concat(stderr).toString(); | ||
| if (stdoutStr) { | ||
| output_manager_default.print(stdoutStr); | ||
| } | ||
| if (stderrStr) { | ||
| output_manager_default.print(stderrStr); | ||
| } | ||
| output_manager_default.error(`Upgrade failed with exit code ${code ?? "unknown"}`); | ||
| output_manager_default.log( | ||
| `You can try running the command manually: ${updateCommand}` | ||
| ); | ||
| } | ||
| resolve(code ?? 1); | ||
| }); | ||
| }); | ||
| } | ||
| // src/commands/login/index.ts | ||
| var import_chalk = __toESM(require_source(), 1); | ||
| // src/util/telemetry/commands/login/index.ts | ||
| var LoginTelemetryClient = class extends TelemetryClient { | ||
| /** | ||
| * Tracks the state of the login process. | ||
| * - `started` when the user initiates the login process. | ||
| * - `canceled` when the user cancels the login process. | ||
| * - `error` when the user encounters an error during the login process. | ||
| * - `success` when the user successfully logs in. | ||
| */ | ||
| trackState(...args) { | ||
| this.trackLoginState(...args); | ||
| } | ||
| }; | ||
| // src/commands/login/index.ts | ||
| async function login2(client, options) { | ||
| let parsedArgs = null; | ||
| const flagsSpecification = getFlagsSpecification(loginCommand.options); | ||
| const telemetry = new LoginTelemetryClient({ | ||
| opts: { | ||
| store: client.telemetryEventStore | ||
| } | ||
| }); | ||
| try { | ||
| if (options.shouldParseArgs) { | ||
| parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification); | ||
| } | ||
| } catch (error) { | ||
| printError(error); | ||
| return 1; | ||
| } | ||
| if (parsedArgs?.flags["--help"]) { | ||
| telemetry.trackCliFlagHelp("login"); | ||
| output_manager_default.print(help(loginCommand, { columns: client.stderr.columns })); | ||
| return 0; | ||
| } | ||
| if (parsedArgs?.flags["--token"]) { | ||
| output_manager_default.error('`--token` may not be used with the "login" command'); | ||
| return 2; | ||
| } | ||
| if (options.shouldParseArgs && parsedArgs) { | ||
| const obsoleteFlags = Object.keys(parsedArgs.flags).filter((flag) => { | ||
| const flagKey = flag.replace("--", ""); | ||
| const option = loginCommand.options.find((o) => o.name === flagKey); | ||
| if (!option || typeof option === "number") | ||
| return; | ||
| return "deprecated" in option && option.deprecated; | ||
| }); | ||
| if (obsoleteFlags.length) { | ||
| const flags = obsoleteFlags.map((f) => import_chalk.default.bold(f)).join(", "); | ||
| output_manager_default.warn(`The following flags are deprecated: ${flags}`); | ||
| } | ||
| const obsoleteArguments = parsedArgs.args.slice(1); | ||
| if (obsoleteArguments.length) { | ||
| const args = obsoleteArguments.map((a) => import_chalk.default.bold(a)).join(", "); | ||
| output_manager_default.warn(`The following arguments are deprecated: ${args}`); | ||
| } | ||
| if (obsoleteArguments.length || obsoleteFlags.length) { | ||
| output_manager_default.print( | ||
| `Read more in our ${output_manager_default.link("changelog", "https://vercel.com/changelog/new-vercel-cli-login-flow")}. | ||
| ` | ||
| ); | ||
| } | ||
| } | ||
| telemetry.trackState("started"); | ||
| return await login(client, telemetry); | ||
| } | ||
| // src/util/output/box.ts | ||
| var import_chalk2 = __toESM(require_source(), 1); | ||
| var import_strip_ansi = __toESM(require_strip_ansi(), 1); | ||
| var border = ["\u2500", "\u256D", "\u256E", "\u2502", "\u2502", "\u2570", "\u256F"]; | ||
| var nothing = ["\u2500", "", "", "", "", "", ""]; | ||
| function box(message, { | ||
| borderColor, | ||
| padding = 1, | ||
| textAlignment = "center", | ||
| terminalColumns: cols = process.stdout.columns || process.env.COLUMNS && parseInt(process.env.COLUMNS, 10) || 80 | ||
| } = {}) { | ||
| const lines = message.split(/\r?\n/).map((line) => [line, (0, import_strip_ansi.default)(line).length]); | ||
| const maxLine = lines.reduce((p, [, len]) => Math.max(p, len), 0); | ||
| const borderColorFn = borderColor && import_chalk2.default[borderColor] || import_chalk2.default.yellow; | ||
| const clampedSidePadding = Math.max(1, padding * 3); | ||
| const narrowMode = maxLine + 2 + clampedSidePadding * 2 > cols; | ||
| const sidePadding = narrowMode ? 0 : clampedSidePadding; | ||
| const innerWidth = Math.min(maxLine + sidePadding * 2, cols); | ||
| const [hr, topLeft, topRight, left, right, bottomLeft, bottomRight] = narrowMode ? nothing : border; | ||
| const spacerRow = narrowMode ? "\n".repeat(padding) : `${borderColorFn(`${left}${" ".repeat(innerWidth)}${right}`)} | ||
| `.repeat( | ||
| padding | ||
| ); | ||
| const renderLine = ([line, len]) => { | ||
| let leftPadding = 0; | ||
| let rightPadding = 0; | ||
| if (!narrowMode) { | ||
| leftPadding = sidePadding; | ||
| rightPadding = sidePadding; | ||
| if (textAlignment === "center") { | ||
| leftPadding += Math.floor((maxLine - len) / 2); | ||
| rightPadding += maxLine - len - leftPadding + sidePadding; | ||
| } else if (textAlignment === "right") { | ||
| leftPadding += maxLine - len; | ||
| } else if (textAlignment === "left") { | ||
| rightPadding += maxLine - len; | ||
| } | ||
| } | ||
| return borderColorFn(left) + " ".repeat(leftPadding) + line + " ".repeat(rightPadding) + borderColorFn(right); | ||
| }; | ||
| return borderColorFn(`${topLeft}${hr.repeat(innerWidth)}${topRight}`) + "\n" + spacerRow + lines.map(renderLine).join("\n") + "\n" + spacerRow + borderColorFn(`${bottomLeft}${hr.repeat(innerWidth)}${bottomRight}`); | ||
| } | ||
| // src/util/did-you-mean.ts | ||
| var import_jaro_winkler = __toESM(require_jaro_winkler(), 1); | ||
| var did_you_mean_default = didYouMean; | ||
| function didYouMean(input, list, threshold = 0.5) { | ||
| const rated = list.map((item) => [dashAwareDistance(input, item), item]); | ||
| const found = rated.filter((item) => item[0] > threshold); | ||
| if (found.length) { | ||
| const highestRated = found.reduce((accu, curr) => { | ||
| return accu[0] > curr[0] ? accu : curr; | ||
| }); | ||
| return highestRated[1]; | ||
| } | ||
| } | ||
| function dashAwareDistance(word, dashWord) { | ||
| const fullDistance = (0, import_jaro_winkler.default)(word, dashWord); | ||
| const distances = dashWord.split("-").map((w) => (0, import_jaro_winkler.default)(w, word)); | ||
| const meanDistance = distances.reduce((accu, curr) => accu + curr) / distances.length; | ||
| return fullDistance > meanDistance ? fullDistance : meanDistance; | ||
| } | ||
| export { | ||
| did_you_mean_default, | ||
| executeUpgrade, | ||
| login2 as login, | ||
| box | ||
| }; |
Sorry, the diff of this file is too big to display
| import { createRequire as __createRequire } from 'node:module'; | ||
| import { fileURLToPath as __fileURLToPath } from 'node:url'; | ||
| import { dirname as __dirname_ } from 'node:path'; | ||
| const require = __createRequire(import.meta.url); | ||
| const __filename = __fileURLToPath(import.meta.url); | ||
| const __dirname = __dirname_(__filename); | ||
| import { | ||
| handleValidationError, | ||
| normalizeRepeatableStringFilters, | ||
| outputError, | ||
| validateAllProjectMutualExclusivity, | ||
| validateOptionalIntegerRange, | ||
| validateTimeBound, | ||
| validateTimeOrder | ||
| } from "./chunk-IE7MNZ56.js"; | ||
| import { | ||
| getScope | ||
| } from "./chunk-XIQUACWR.js"; | ||
| import { | ||
| validateJsonOutput | ||
| } from "./chunk-XPKWKPWA.js"; | ||
| import { | ||
| alertsCommand | ||
| } from "./chunk-P5Q6F5IA.js"; | ||
| import { | ||
| getLinkedProject, | ||
| getProjectByNameOrId | ||
| } from "./chunk-4MTNDNUR.js"; | ||
| import "./chunk-XB2KZC2B.js"; | ||
| import "./chunk-SOTR4CXR.js"; | ||
| import { | ||
| table | ||
| } from "./chunk-LWBSOTJP.js"; | ||
| import "./chunk-7EHTK7LP.js"; | ||
| import { | ||
| require_ms | ||
| } from "./chunk-GGP5R3FU.js"; | ||
| import { | ||
| ProjectNotFound, | ||
| getFlagsSpecification, | ||
| isAPIError, | ||
| parseArguments, | ||
| printError | ||
| } from "./chunk-ZLCMHY2G.js"; | ||
| import "./chunk-3XFFP2BA.js"; | ||
| import { | ||
| output_manager_default | ||
| } from "./chunk-FDJURQMQ.js"; | ||
| import { | ||
| require_source | ||
| } from "./chunk-S7KYDPEM.js"; | ||
| import { | ||
| __toESM | ||
| } from "./chunk-TZ2YI2VH.js"; | ||
| // src/commands/alerts/list.ts | ||
| var import_ms = __toESM(require_ms(), 1); | ||
| var import_chalk = __toESM(require_source(), 1); | ||
| function handleApiError(err, jsonOutput, client) { | ||
| const message = err.status === 401 || err.status === 403 ? "You do not have access to alerts in this scope. Pass --token <TOKEN> and --scope <team-slug> with Alerts read access." : err.status >= 500 ? `The alerts endpoint failed on the server (${err.status}). Re-run with --debug and share the x-vercel-id from the failed request.` : err.serverMessage || `API error (${err.status}).`; | ||
| return outputError(client, jsonOutput, err.code || "API_ERROR", message); | ||
| } | ||
| function getDefaultRange() { | ||
| const to = /* @__PURE__ */ new Date(); | ||
| const from = new Date(to.getTime() - 24 * 60 * 60 * 1e3); | ||
| return { from: from.toISOString(), to: to.toISOString() }; | ||
| } | ||
| async function resolveScope(client, opts) { | ||
| if (opts.all || opts.project) { | ||
| const { team } = await getScope(client); | ||
| if (!team) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "NO_TEAM", | ||
| "No team context found. Run `vercel switch` to select a team, or use `vercel link` in a project directory." | ||
| ); | ||
| } | ||
| if (opts.all) { | ||
| return { | ||
| teamId: team.id | ||
| }; | ||
| } | ||
| let projectResult; | ||
| try { | ||
| projectResult = await getProjectByNameOrId( | ||
| client, | ||
| opts.project, | ||
| team.id | ||
| ); | ||
| } catch (err) { | ||
| if (isAPIError(err)) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| err.code || "API_ERROR", | ||
| err.serverMessage || (err.status === 403 ? `You do not have permission to access project "${opts.project}" in team "${team.slug}".` : `API error (${err.status}).`) | ||
| ); | ||
| } | ||
| throw err; | ||
| } | ||
| if (projectResult instanceof ProjectNotFound) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "PROJECT_NOT_FOUND", | ||
| `Project "${opts.project}" was not found in team "${team.slug}".` | ||
| ); | ||
| } | ||
| return { | ||
| teamId: team.id, | ||
| projectId: projectResult.id | ||
| }; | ||
| } | ||
| const linkedProject = await getLinkedProject(client); | ||
| if (linkedProject.status === "error") { | ||
| return linkedProject.exitCode; | ||
| } | ||
| if (linkedProject.status === "not_linked") { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "NOT_LINKED", | ||
| "No linked project found. Run `vercel link` to link a project, or use --project <name> or --all." | ||
| ); | ||
| } | ||
| return { | ||
| teamId: linkedProject.org.id, | ||
| projectId: linkedProject.project.id | ||
| }; | ||
| } | ||
| function getGroupTitle(group) { | ||
| return group.ai?.title || "Alert group"; | ||
| } | ||
| function parseDateInput(value) { | ||
| if (value === void 0) { | ||
| return void 0; | ||
| } | ||
| const epochMs = value < 1e12 ? value * 1e3 : value; | ||
| const date = new Date(epochMs); | ||
| return Number.isNaN(date.getTime()) ? void 0 : date; | ||
| } | ||
| function formatDateForDisplay(value) { | ||
| const date = parseDateInput(value); | ||
| if (!date) { | ||
| return "-"; | ||
| } | ||
| return date.toLocaleString("en-US", { | ||
| year: "numeric", | ||
| month: "short", | ||
| day: "2-digit", | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| second: "2-digit", | ||
| hour12: false, | ||
| timeZoneName: "short" | ||
| }); | ||
| } | ||
| function getStartedAt(group) { | ||
| return formatDateForDisplay(getGroupStartedAt(group)?.getTime()); | ||
| } | ||
| function getGroupStartedAt(group) { | ||
| return parseDateInput(group.recordedStartedAt) || parseDateInput(group.alerts?.[0]?.startedAt); | ||
| } | ||
| function getGroupResolvedAt(group) { | ||
| const resolvedTimes = (group.alerts ?? []).map((alert) => parseDateInput(alert.resolvedAt)).filter((d) => Boolean(d)).map((d) => d.getTime()); | ||
| if (resolvedTimes.length > 0) { | ||
| return new Date(Math.max(...resolvedTimes)); | ||
| } | ||
| return getGroupStartedAt(group); | ||
| } | ||
| function getStatus(group) { | ||
| const normalizedStatus = (group.status || "").toLowerCase(); | ||
| if (normalizedStatus === "active") { | ||
| return "active"; | ||
| } | ||
| if (normalizedStatus === "resolved") { | ||
| const startedAt = getGroupStartedAt(group); | ||
| const resolvedAt = getGroupResolvedAt(group); | ||
| if (startedAt && resolvedAt && resolvedAt.getTime() >= startedAt.getTime()) { | ||
| return `resolved after ${(0, import_ms.default)(resolvedAt.getTime() - startedAt.getTime())}`; | ||
| } | ||
| return "resolved"; | ||
| } | ||
| return group.status || "-"; | ||
| } | ||
| function getResolvedAt(group) { | ||
| const normalizedStatus = (group.status || "").toLowerCase(); | ||
| if (normalizedStatus === "active") { | ||
| return "active"; | ||
| } | ||
| return formatDateForDisplay(getGroupResolvedAt(group)?.getTime()); | ||
| } | ||
| function getAlertsCount(group) { | ||
| return String(group.alerts?.length ?? 0); | ||
| } | ||
| function printGroups(groups) { | ||
| if (groups.length === 0) { | ||
| output_manager_default.log("No alerts found."); | ||
| return; | ||
| } | ||
| const headers = ["Title", "Started At", "Type", "Status", "Alerts"].map( | ||
| (h) => import_chalk.default.cyan(h) | ||
| ); | ||
| const rows = [ | ||
| headers, | ||
| ...groups.map((group) => [ | ||
| import_chalk.default.bold(getGroupTitle(group)), | ||
| getStartedAt(group), | ||
| group.type || "-", | ||
| getStatus(group), | ||
| getAlertsCount(group) | ||
| ]) | ||
| ]; | ||
| const tableOutput = table(rows, { hsep: 3 }).split("\n").map((line) => line.trimEnd()).join("\n").replace(/^/gm, " "); | ||
| output_manager_default.print(` | ||
| ${tableOutput} | ||
| `); | ||
| } | ||
| function printAiSections(groups) { | ||
| if (groups.length === 0) { | ||
| output_manager_default.log("No alerts found."); | ||
| return; | ||
| } | ||
| const rendered = groups.map((group) => { | ||
| const title = getGroupTitle(group); | ||
| const summary = group.ai?.currentSummary || "N/A"; | ||
| const findings = group.ai?.keyFindings?.filter(Boolean) ?? []; | ||
| const findingsOutput = findings.length > 0 ? findings.map((finding) => ` - ${finding}`).join("\n") : " - N/A"; | ||
| return [ | ||
| import_chalk.default.bold(title), | ||
| ` ${import_chalk.default.cyan("Resolved At:")} ${getResolvedAt(group)}`, | ||
| ` ${import_chalk.default.cyan("Summary:")} ${summary}`, | ||
| ` ${import_chalk.default.cyan("Key Findings:")}`, | ||
| findingsOutput | ||
| ].join("\n"); | ||
| }).join("\n\n"); | ||
| output_manager_default.print(` | ||
| ${rendered} | ||
| `); | ||
| } | ||
| function trackTelemetry(flags, types, telemetry) { | ||
| telemetry.trackCliOptionType(types.length > 0 ? types : void 0); | ||
| telemetry.trackCliOptionSince(flags["--since"]); | ||
| telemetry.trackCliOptionUntil(flags["--until"]); | ||
| telemetry.trackCliOptionProject(flags["--project"]); | ||
| telemetry.trackCliFlagAll(flags["--all"]); | ||
| telemetry.trackCliFlagAi(flags["--ai"]); | ||
| telemetry.trackCliOptionLimit(flags["--limit"]); | ||
| telemetry.trackCliOptionFormat(flags["--format"]); | ||
| } | ||
| function parseFlags(client) { | ||
| const flagsSpecification = getFlagsSpecification(alertsCommand.options); | ||
| try { | ||
| const parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification); | ||
| return parsedArgs.flags; | ||
| } catch (err) { | ||
| printError(err); | ||
| return 1; | ||
| } | ||
| } | ||
| function resolveValidatedInputs(flags, client, jsonOutput) { | ||
| const types = normalizeRepeatableStringFilters(flags["--type"]); | ||
| const limitResult = validateOptionalIntegerRange(flags["--limit"], { | ||
| flag: "--limit", | ||
| min: 1, | ||
| max: 100 | ||
| }); | ||
| if (!limitResult.valid) { | ||
| return handleValidationError(limitResult, jsonOutput, client); | ||
| } | ||
| const mutualResult = validateAllProjectMutualExclusivity( | ||
| flags["--all"], | ||
| flags["--project"] | ||
| ); | ||
| if (!mutualResult.valid) { | ||
| return handleValidationError(mutualResult, jsonOutput, client); | ||
| } | ||
| const sinceResult = validateTimeBound(flags["--since"]); | ||
| if (!sinceResult.valid) { | ||
| return handleValidationError(sinceResult, jsonOutput, client); | ||
| } | ||
| const untilResult = validateTimeBound(flags["--until"]); | ||
| if (!untilResult.valid) { | ||
| return handleValidationError(untilResult, jsonOutput, client); | ||
| } | ||
| const timeOrderResult = validateTimeOrder( | ||
| sinceResult.value, | ||
| untilResult.value | ||
| ); | ||
| if (!timeOrderResult.valid) { | ||
| return handleValidationError(timeOrderResult, jsonOutput, client); | ||
| } | ||
| return { | ||
| limit: limitResult.value, | ||
| types, | ||
| since: sinceResult.value, | ||
| until: untilResult.value | ||
| }; | ||
| } | ||
| function buildAlertsQuery(scope, inputs) { | ||
| const query = new URLSearchParams({ | ||
| teamId: scope.teamId | ||
| }); | ||
| if (scope.projectId) { | ||
| query.set("projectId", scope.projectId); | ||
| } | ||
| if (inputs.limit) { | ||
| query.set("limit", String(inputs.limit)); | ||
| } | ||
| for (const type of inputs.types) { | ||
| query.append("types", type); | ||
| } | ||
| if (inputs.since) { | ||
| query.set("from", inputs.since.toISOString()); | ||
| } | ||
| if (inputs.until) { | ||
| query.set("to", inputs.until.toISOString()); | ||
| } | ||
| if (!inputs.since && !inputs.until) { | ||
| const defaultRange = getDefaultRange(); | ||
| query.set("from", defaultRange.from); | ||
| query.set("to", defaultRange.to); | ||
| } | ||
| return query; | ||
| } | ||
| async function list(client, telemetry) { | ||
| const flags = parseFlags(client); | ||
| if (typeof flags === "number") { | ||
| return flags; | ||
| } | ||
| const formatResult = validateJsonOutput(flags); | ||
| if (!formatResult.valid) { | ||
| output_manager_default.error(formatResult.error); | ||
| return 1; | ||
| } | ||
| const jsonOutput = formatResult.jsonOutput; | ||
| const types = normalizeRepeatableStringFilters(flags["--type"]); | ||
| trackTelemetry(flags, types, telemetry); | ||
| const validatedInputs = resolveValidatedInputs(flags, client, jsonOutput); | ||
| if (typeof validatedInputs === "number") { | ||
| return validatedInputs; | ||
| } | ||
| const scope = await resolveScope(client, { | ||
| project: flags["--project"], | ||
| all: flags["--all"], | ||
| jsonOutput | ||
| }); | ||
| if (typeof scope === "number") { | ||
| return scope; | ||
| } | ||
| const query = buildAlertsQuery(scope, validatedInputs); | ||
| const requestPath = `/alerts/v3/groups?${query.toString()}`; | ||
| output_manager_default.debug(`Fetching alerts from ${requestPath}`); | ||
| output_manager_default.spinner("Fetching alerts..."); | ||
| try { | ||
| const groups = await client.fetch(requestPath); | ||
| if (jsonOutput) { | ||
| client.stdout.write(`${JSON.stringify({ groups }, null, 2)} | ||
| `); | ||
| } else { | ||
| if (flags["--ai"]) { | ||
| printAiSections(groups); | ||
| } else { | ||
| printGroups(groups); | ||
| } | ||
| } | ||
| return 0; | ||
| } catch (err) { | ||
| if (isAPIError(err)) { | ||
| return handleApiError(err, jsonOutput, client); | ||
| } | ||
| output_manager_default.debug(err); | ||
| const message = `Failed to fetch alerts: ${err.message || String(err)}`; | ||
| return outputError(client, jsonOutput, "UNEXPECTED_ERROR", message); | ||
| } finally { | ||
| output_manager_default.stopSpinner(); | ||
| } | ||
| } | ||
| export { | ||
| list as default | ||
| }; |
| import { createRequire as __createRequire } from 'node:module'; | ||
| import { fileURLToPath as __fileURLToPath } from 'node:url'; | ||
| import { dirname as __dirname_ } from 'node:path'; | ||
| const require = __createRequire(import.meta.url); | ||
| const __filename = __fileURLToPath(import.meta.url); | ||
| const __dirname = __dirname_(__filename); | ||
| import { | ||
| handleValidationError, | ||
| normalizeRepeatableStringFilters, | ||
| outputError, | ||
| validateAllProjectMutualExclusivity, | ||
| validateIntegerRangeWithDefault, | ||
| validateTimeBound, | ||
| validateTimeOrder | ||
| } from "./chunk-IE7MNZ56.js"; | ||
| import { | ||
| getCommandFlags | ||
| } from "./chunk-EOZFDJSY.js"; | ||
| import { | ||
| getScope | ||
| } from "./chunk-XIQUACWR.js"; | ||
| import { | ||
| validateJsonOutput | ||
| } from "./chunk-XPKWKPWA.js"; | ||
| import { | ||
| activityCommand | ||
| } from "./chunk-LW5ZNGW7.js"; | ||
| import { | ||
| getLinkedProject, | ||
| getProjectByNameOrId | ||
| } from "./chunk-4MTNDNUR.js"; | ||
| import "./chunk-XB2KZC2B.js"; | ||
| import "./chunk-SOTR4CXR.js"; | ||
| import "./chunk-7EHTK7LP.js"; | ||
| import { | ||
| require_ms | ||
| } from "./chunk-GGP5R3FU.js"; | ||
| import { | ||
| ProjectNotFound, | ||
| getCommandName, | ||
| getFlagsSpecification, | ||
| isAPIError, | ||
| parseArguments, | ||
| printError | ||
| } from "./chunk-ZLCMHY2G.js"; | ||
| import "./chunk-3XFFP2BA.js"; | ||
| import { | ||
| output_manager_default | ||
| } from "./chunk-FDJURQMQ.js"; | ||
| import { | ||
| require_source | ||
| } from "./chunk-S7KYDPEM.js"; | ||
| import { | ||
| __toESM | ||
| } from "./chunk-TZ2YI2VH.js"; | ||
| // src/commands/activity/list.ts | ||
| var import_ms = __toESM(require_ms(), 1); | ||
| var import_chalk = __toESM(require_source(), 1); | ||
| function validateNext(next) { | ||
| if (next === void 0) { | ||
| return { valid: true, value: void 0 }; | ||
| } | ||
| if (Number.isNaN(next)) { | ||
| return { | ||
| valid: false, | ||
| code: "INVALID_NEXT", | ||
| message: "Please provide a number for flag `--next`." | ||
| }; | ||
| } | ||
| const date = new Date(next); | ||
| if (Number.isNaN(date.getTime())) { | ||
| return { | ||
| valid: false, | ||
| code: "INVALID_NEXT", | ||
| message: "Please provide a valid unix timestamp in milliseconds for `--next`." | ||
| }; | ||
| } | ||
| return { valid: true, value: date }; | ||
| } | ||
| function handleApiError(err, jsonOutput, client) { | ||
| if (err.status === 403) { | ||
| return outputError( | ||
| client, | ||
| jsonOutput, | ||
| "FORBIDDEN", | ||
| "You do not have permission to list activity events. Required permissions: Event: List or OwnEvent: List." | ||
| ); | ||
| } | ||
| return outputError( | ||
| client, | ||
| jsonOutput, | ||
| err.code || "API_ERROR", | ||
| err.serverMessage || `API error (${err.status}).` | ||
| ); | ||
| } | ||
| function formatActor(event) { | ||
| const principal = event.principal; | ||
| if (!principal) { | ||
| return event.principalId || "-"; | ||
| } | ||
| if (principal.type === "system") { | ||
| return "system"; | ||
| } | ||
| if (principal.username) { | ||
| return principal.username; | ||
| } | ||
| if (principal.name) { | ||
| return principal.name; | ||
| } | ||
| if (principal.slug) { | ||
| return principal.slug; | ||
| } | ||
| if (principal.email) { | ||
| return principal.email; | ||
| } | ||
| return event.principalId || "-"; | ||
| } | ||
| function formatAge(createdAt) { | ||
| if (!Number.isFinite(createdAt) || createdAt <= 0) { | ||
| return "-"; | ||
| } | ||
| const age = Math.max(0, Date.now() - createdAt); | ||
| return (0, import_ms.default)(age); | ||
| } | ||
| function formatEventText(text) { | ||
| return text.replace(/\s+/g, " ").trim(); | ||
| } | ||
| function printExpandedEvents(events) { | ||
| const lines = [""]; | ||
| events.forEach((event) => { | ||
| lines.push(import_chalk.default.bold(formatEventText(event.text))); | ||
| lines.push(` ${import_chalk.default.cyan("Type:")} ${event.type ?? "-"}`); | ||
| lines.push(` ${import_chalk.default.cyan("Actor:")} ${formatActor(event)}`); | ||
| lines.push(` ${import_chalk.default.cyan("Age:")} ${formatAge(event.createdAt)}`); | ||
| lines.push(` ${import_chalk.default.cyan("ID:")} ${event.id}`); | ||
| lines.push(""); | ||
| }); | ||
| output_manager_default.print(`${lines.join("\n")} | ||
| `); | ||
| } | ||
| function trackTelemetry(flags, types, telemetry) { | ||
| telemetry.trackCliOptionType(types.length > 0 ? types : void 0); | ||
| telemetry.trackCliOptionSince(flags["--since"]); | ||
| telemetry.trackCliOptionUntil(flags["--until"]); | ||
| telemetry.trackCliOptionProject(flags["--project"]); | ||
| telemetry.trackCliFlagAll(flags["--all"]); | ||
| telemetry.trackCliOptionLimit(flags["--limit"]); | ||
| telemetry.trackCliOptionNext(flags["--next"]); | ||
| telemetry.trackCliOptionFormat(flags["--format"]); | ||
| } | ||
| function parseFlags(client) { | ||
| const flagsSpecification = getFlagsSpecification(activityCommand.options); | ||
| try { | ||
| const parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification); | ||
| return parsedArgs.flags; | ||
| } catch (err) { | ||
| printError(err); | ||
| return 1; | ||
| } | ||
| } | ||
| function resolveValidatedInputs(flags, jsonOutput, client, normalizedTypes) { | ||
| const limitResult = validateIntegerRangeWithDefault(flags["--limit"], { | ||
| flag: "--limit", | ||
| min: 1, | ||
| max: 100, | ||
| defaultValue: 20 | ||
| }); | ||
| if (!limitResult.valid) { | ||
| return handleValidationError(limitResult, jsonOutput, client); | ||
| } | ||
| const mutualResult = validateAllProjectMutualExclusivity( | ||
| flags["--all"], | ||
| flags["--project"] | ||
| ); | ||
| if (!mutualResult.valid) { | ||
| return handleValidationError(mutualResult, jsonOutput, client); | ||
| } | ||
| const sinceResult = validateTimeBound(flags["--since"]); | ||
| if (!sinceResult.valid) { | ||
| return handleValidationError(sinceResult, jsonOutput, client); | ||
| } | ||
| const nextResult = validateNext(flags["--next"]); | ||
| if (!nextResult.valid) { | ||
| return handleValidationError(nextResult, jsonOutput, client); | ||
| } | ||
| let until = nextResult.value; | ||
| if (!until) { | ||
| const untilResult = validateTimeBound(flags["--until"]); | ||
| if (!untilResult.valid) { | ||
| return handleValidationError(untilResult, jsonOutput, client); | ||
| } | ||
| until = untilResult.value; | ||
| } | ||
| const since = sinceResult.value; | ||
| const timeOrderResult = validateTimeOrder(since, until); | ||
| if (!timeOrderResult.valid) { | ||
| return handleValidationError(timeOrderResult, jsonOutput, client); | ||
| } | ||
| return { | ||
| limit: limitResult.value, | ||
| types: normalizedTypes, | ||
| since, | ||
| until | ||
| }; | ||
| } | ||
| async function resolveScope(client, opts) { | ||
| if (opts.all || opts.project) { | ||
| const { team } = await getScope(client); | ||
| if (!team) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "NO_TEAM", | ||
| "No team context found. Run `vercel switch` to select a team, or use `vercel link` in a project directory." | ||
| ); | ||
| } | ||
| if (opts.all) { | ||
| return { | ||
| teamId: team.id, | ||
| teamSlug: team.slug | ||
| }; | ||
| } | ||
| let projectResult; | ||
| try { | ||
| projectResult = await getProjectByNameOrId( | ||
| client, | ||
| opts.project, | ||
| team.id | ||
| ); | ||
| } catch (err) { | ||
| if (isAPIError(err)) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| err.code || "API_ERROR", | ||
| err.serverMessage || (err.status === 403 ? `You do not have permission to access project "${opts.project}" in team "${team.slug}".` : `API error (${err.status}).`) | ||
| ); | ||
| } | ||
| throw err; | ||
| } | ||
| if (projectResult instanceof ProjectNotFound) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "PROJECT_NOT_FOUND", | ||
| `Project "${opts.project}" was not found in team "${team.slug}".` | ||
| ); | ||
| } | ||
| return { | ||
| teamId: team.id, | ||
| teamSlug: team.slug, | ||
| projectIds: [projectResult.id] | ||
| }; | ||
| } | ||
| const linkedProject = await getLinkedProject(client); | ||
| if (linkedProject.status === "error") { | ||
| return linkedProject.exitCode; | ||
| } | ||
| if (linkedProject.status === "not_linked") { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "NOT_LINKED", | ||
| "No linked project found. Run `vercel link` to link a project, or use --project <name> or --all." | ||
| ); | ||
| } | ||
| const isTeamProject = linkedProject.org.type === "team"; | ||
| return { | ||
| projectIds: [linkedProject.project.id], | ||
| teamId: isTeamProject ? linkedProject.org.id : void 0, | ||
| teamSlug: isTeamProject ? linkedProject.org.slug : void 0 | ||
| }; | ||
| } | ||
| function buildEventsQuery(params) { | ||
| const query = new URLSearchParams({ | ||
| limit: String(params.limit + 1) | ||
| }); | ||
| if (params.types.length > 0) { | ||
| query.set("types", params.types.join(",")); | ||
| } | ||
| if (params.since) { | ||
| query.set("since", params.since.toISOString()); | ||
| } | ||
| if (params.until) { | ||
| query.set("until", params.until.toISOString()); | ||
| } | ||
| if (params.scope.projectIds && params.scope.projectIds.length > 0) { | ||
| query.set("projectIds", params.scope.projectIds.join(",")); | ||
| } | ||
| if (params.scope.teamId) { | ||
| query.set("teamId", params.scope.teamId); | ||
| } | ||
| if (params.scope.teamSlug) { | ||
| query.set("slug", params.scope.teamSlug); | ||
| } | ||
| if (params.jsonOutput) { | ||
| query.set("withPayload", "true"); | ||
| } | ||
| return query; | ||
| } | ||
| function paginateEvents(allEvents, limit) { | ||
| const events = allEvents.slice(0, limit); | ||
| const hasMore = allEvents.length > limit; | ||
| const lastVisibleEvent = events[events.length - 1]; | ||
| const next = hasMore && typeof lastVisibleEvent?.createdAt === "number" ? lastVisibleEvent.createdAt - 1 : null; | ||
| return { events, next }; | ||
| } | ||
| function printNextPageHint(flags, next) { | ||
| const commandFlags = getCommandFlags(flags, ["--next"]); | ||
| output_manager_default.log( | ||
| `To display the next page, run ${getCommandName( | ||
| `activity${commandFlags} --next ${next}` | ||
| )}` | ||
| ); | ||
| } | ||
| async function list(client, telemetry) { | ||
| const flags = parseFlags(client); | ||
| if (typeof flags === "number") { | ||
| return flags; | ||
| } | ||
| const formatResult = validateJsonOutput(flags); | ||
| if (!formatResult.valid) { | ||
| output_manager_default.error(formatResult.error); | ||
| return 1; | ||
| } | ||
| const jsonOutput = formatResult.jsonOutput; | ||
| const normalizedTypes = normalizeRepeatableStringFilters(flags["--type"]); | ||
| trackTelemetry(flags, normalizedTypes, telemetry); | ||
| const validatedInputs = resolveValidatedInputs( | ||
| flags, | ||
| jsonOutput, | ||
| client, | ||
| normalizedTypes | ||
| ); | ||
| if (typeof validatedInputs === "number") { | ||
| return validatedInputs; | ||
| } | ||
| const scope = await resolveScope(client, { | ||
| project: flags["--project"], | ||
| all: flags["--all"], | ||
| jsonOutput | ||
| }); | ||
| if (typeof scope === "number") { | ||
| return scope; | ||
| } | ||
| const query = buildEventsQuery({ | ||
| limit: validatedInputs.limit, | ||
| types: validatedInputs.types, | ||
| since: validatedInputs.since, | ||
| until: validatedInputs.until, | ||
| scope, | ||
| jsonOutput | ||
| }); | ||
| output_manager_default.spinner("Fetching activity..."); | ||
| try { | ||
| const response = await client.fetch( | ||
| `/v3/events?${query.toString()}`, | ||
| { | ||
| useCurrentTeam: false | ||
| } | ||
| ); | ||
| const allEvents = Array.isArray(response.events) ? response.events : []; | ||
| const { events, next } = paginateEvents(allEvents, validatedInputs.limit); | ||
| if (jsonOutput) { | ||
| client.stdout.write( | ||
| `${JSON.stringify({ events, pagination: { next } }, null, 2)} | ||
| ` | ||
| ); | ||
| return 0; | ||
| } | ||
| if (events.length === 0) { | ||
| output_manager_default.log("No activity events found."); | ||
| return 0; | ||
| } | ||
| printExpandedEvents(events); | ||
| if (next !== null) { | ||
| printNextPageHint(flags, next); | ||
| } | ||
| return 0; | ||
| } catch (err) { | ||
| if (isAPIError(err)) { | ||
| return handleApiError(err, jsonOutput, client); | ||
| } | ||
| throw err; | ||
| } finally { | ||
| output_manager_default.stopSpinner(); | ||
| } | ||
| } | ||
| export { | ||
| list as default | ||
| }; |
@@ -16,3 +16,3 @@ import { createRequire as __createRequire } from 'node:module'; | ||
| setupDomain | ||
| } from "../../chunks/chunk-GMKRSAXH.js"; | ||
| } from "../../chunks/chunk-EFKVLLXG.js"; | ||
| import { | ||
@@ -45,3 +45,3 @@ readLocalConfig | ||
| initSubcommand | ||
| } from "../../chunks/chunk-677KLOZL.js"; | ||
| } from "../../chunks/chunk-XNH2ODPG.js"; | ||
| import "../../chunks/chunk-U6XOC6E4.js"; | ||
@@ -48,0 +48,0 @@ import "../../chunks/chunk-O7I4ZOCC.js"; |
@@ -11,6 +11,6 @@ import { createRequire as __createRequire } from 'node:module'; | ||
| import { | ||
| addSubcommand7 as addSubcommand, | ||
| addSubcommand6 as addSubcommand, | ||
| getCommandAliases, | ||
| linkCommand | ||
| } from "../../chunks/chunk-677KLOZL.js"; | ||
| } from "../../chunks/chunk-XNH2ODPG.js"; | ||
| import "../../chunks/chunk-U6XOC6E4.js"; | ||
@@ -17,0 +17,0 @@ import "../../chunks/chunk-O7I4ZOCC.js"; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| export const version = "50.31.1"; | ||
| export const version = "50.31.2"; |
+12
-12
| { | ||
| "name": "vercel", | ||
| "version": "50.31.1", | ||
| "version": "50.31.2", | ||
| "type": "module", | ||
@@ -34,21 +34,21 @@ "preferGlobal": true, | ||
| "@vercel/build-utils": "13.8.0", | ||
| "@vercel/backends": "0.0.45", | ||
| "@vercel/detect-agent": "1.2.0", | ||
| "@vercel/express": "0.1.57", | ||
| "@vercel/elysia": "0.1.48", | ||
| "@vercel/fastify": "0.1.51", | ||
| "@vercel/go": "3.4.4", | ||
| "@vercel/backends": "0.0.45", | ||
| "@vercel/h3": "0.1.57", | ||
| "@vercel/go": "3.4.4", | ||
| "@vercel/elysia": "0.1.48", | ||
| "@vercel/hono": "0.2.51", | ||
| "@vercel/hydrogen": "1.3.6", | ||
| "@vercel/nestjs": "0.2.52", | ||
| "@vercel/koa": "0.1.31", | ||
| "@vercel/next": "4.16.1", | ||
| "@vercel/node": "5.6.15", | ||
| "@vercel/next": "4.16.1", | ||
| "@vercel/nestjs": "0.2.52", | ||
| "@vercel/python": "6.22.0", | ||
| "@vercel/hono": "0.2.51", | ||
| "@vercel/redwood": "2.4.10", | ||
| "@vercel/ruby": "2.3.2", | ||
| "@vercel/rust": "1.0.5", | ||
| "@vercel/remix-builder": "5.7.0", | ||
| "@vercel/static-build": "2.9.0", | ||
| "@vercel/remix-builder": "5.7.0" | ||
| "@vercel/rust": "1.0.5" | ||
| }, | ||
@@ -182,9 +182,9 @@ "devDependencies": { | ||
| "@vercel-internals/constants": "1.0.4", | ||
| "@vercel-internals/types": "3.0.6", | ||
| "@vercel-internals/get-package-json": "1.0.0", | ||
| "@vercel/error-utils": "2.0.3", | ||
| "@vercel/frameworks": "3.21.0", | ||
| "@vercel/error-utils": "2.0.3", | ||
| "@vercel/client": "17.2.57", | ||
| "@vercel/routing-utils": "6.0.2", | ||
| "@vercel/fs-detectors": "5.10.1", | ||
| "@vercel-internals/types": "3.0.6" | ||
| "@vercel/routing-utils": "6.0.2" | ||
| }, | ||
@@ -191,0 +191,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
| import { createRequire as __createRequire } from 'node:module'; | ||
| import { fileURLToPath as __fileURLToPath } from 'node:url'; | ||
| import { dirname as __dirname_ } from 'node:path'; | ||
| const require = __createRequire(import.meta.url); | ||
| const __filename = __fileURLToPath(import.meta.url); | ||
| const __dirname = __dirname_(__filename); | ||
| import { | ||
| getUpdateCommand | ||
| } from "./chunk-2MDXGVZV.js"; | ||
| import { | ||
| login | ||
| } from "./chunk-AABYT6JI.js"; | ||
| import { | ||
| loginCommand | ||
| } from "./chunk-677KLOZL.js"; | ||
| import { | ||
| help | ||
| } from "./chunk-DOBFJJLK.js"; | ||
| import { | ||
| TelemetryClient | ||
| } from "./chunk-XB2KZC2B.js"; | ||
| import { | ||
| getFlagsSpecification, | ||
| parseArguments, | ||
| printError, | ||
| require_strip_ansi | ||
| } from "./chunk-ZLCMHY2G.js"; | ||
| import { | ||
| output_manager_default | ||
| } from "./chunk-FDJURQMQ.js"; | ||
| import { | ||
| require_source | ||
| } from "./chunk-S7KYDPEM.js"; | ||
| import { | ||
| __commonJS, | ||
| __toESM | ||
| } from "./chunk-TZ2YI2VH.js"; | ||
| // ../../node_modules/.pnpm/jaro-winkler@0.2.8/node_modules/jaro-winkler/index.js | ||
| var require_jaro_winkler = __commonJS({ | ||
| "../../node_modules/.pnpm/jaro-winkler@0.2.8/node_modules/jaro-winkler/index.js"(exports, module) { | ||
| (function(root) { | ||
| "use strict"; | ||
| function extend(a, b) { | ||
| for (var property in b) { | ||
| if (b.hasOwnProperty(property)) { | ||
| a[property] = b[property]; | ||
| } | ||
| } | ||
| return a; | ||
| } | ||
| function distance2(s1, s2, options) { | ||
| var m = 0; | ||
| var defaults = { caseSensitive: true }; | ||
| var settings = extend(defaults, options); | ||
| var i; | ||
| var j; | ||
| if (s1.length === 0 || s2.length === 0) { | ||
| return 0; | ||
| } | ||
| if (!settings.caseSensitive) { | ||
| s1 = s1.toUpperCase(); | ||
| s2 = s2.toUpperCase(); | ||
| } | ||
| if (s1 === s2) { | ||
| return 1; | ||
| } | ||
| var range = Math.floor(Math.max(s1.length, s2.length) / 2) - 1; | ||
| var s1Matches = new Array(s1.length); | ||
| var s2Matches = new Array(s2.length); | ||
| for (i = 0; i < s1.length; i++) { | ||
| var low = i >= range ? i - range : 0; | ||
| var high = i + range <= s2.length - 1 ? i + range : s2.length - 1; | ||
| for (j = low; j <= high; j++) { | ||
| if (s1Matches[i] !== true && s2Matches[j] !== true && s1[i] === s2[j]) { | ||
| ++m; | ||
| s1Matches[i] = s2Matches[j] = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| if (m === 0) { | ||
| return 0; | ||
| } | ||
| var k = 0; | ||
| var numTrans = 0; | ||
| for (i = 0; i < s1.length; i++) { | ||
| if (s1Matches[i] === true) { | ||
| for (j = k; j < s2.length; j++) { | ||
| if (s2Matches[j] === true) { | ||
| k = j + 1; | ||
| break; | ||
| } | ||
| } | ||
| if (s1[i] !== s2[j]) { | ||
| ++numTrans; | ||
| } | ||
| } | ||
| } | ||
| var weight = (m / s1.length + m / s2.length + (m - numTrans / 2) / m) / 3; | ||
| var l = 0; | ||
| var p = 0.1; | ||
| if (weight > 0.7) { | ||
| while (s1[l] === s2[l] && l < 4) { | ||
| ++l; | ||
| } | ||
| weight = weight + l * p * (1 - weight); | ||
| } | ||
| return weight; | ||
| } | ||
| if (typeof define === "function" && define.amd) { | ||
| define([], function() { | ||
| return distance2; | ||
| }); | ||
| } else if (typeof exports === "object") { | ||
| module.exports = distance2; | ||
| } else { | ||
| root.distance = distance2; | ||
| } | ||
| })(exports); | ||
| } | ||
| }); | ||
| // src/util/upgrade.ts | ||
| import { spawn } from "child_process"; | ||
| async function executeUpgrade() { | ||
| const updateCommand = await getUpdateCommand(); | ||
| const [command, ...args] = updateCommand.split(" "); | ||
| output_manager_default.log(`Upgrading Vercel CLI...`); | ||
| output_manager_default.debug(`Executing: ${updateCommand}`); | ||
| return new Promise((resolve) => { | ||
| const stdout = []; | ||
| const stderr = []; | ||
| const upgradeProcess = spawn(command, args, { | ||
| stdio: ["inherit", "pipe", "pipe"], | ||
| shell: false | ||
| }); | ||
| upgradeProcess.stdout?.on("data", (data) => { | ||
| stdout.push(data); | ||
| }); | ||
| upgradeProcess.stderr?.on("data", (data) => { | ||
| stderr.push(data); | ||
| }); | ||
| upgradeProcess.on("error", (err) => { | ||
| output_manager_default.error(`Failed to execute upgrade command: ${err.message}`); | ||
| output_manager_default.log(`You can try running the command manually: ${updateCommand}`); | ||
| resolve(1); | ||
| }); | ||
| upgradeProcess.on("close", (code) => { | ||
| if (code === 0) { | ||
| output_manager_default.success("Vercel CLI has been upgraded successfully!"); | ||
| } else { | ||
| const stdoutStr = Buffer.concat(stdout).toString(); | ||
| const stderrStr = Buffer.concat(stderr).toString(); | ||
| if (stdoutStr) { | ||
| output_manager_default.print(stdoutStr); | ||
| } | ||
| if (stderrStr) { | ||
| output_manager_default.print(stderrStr); | ||
| } | ||
| output_manager_default.error(`Upgrade failed with exit code ${code ?? "unknown"}`); | ||
| output_manager_default.log( | ||
| `You can try running the command manually: ${updateCommand}` | ||
| ); | ||
| } | ||
| resolve(code ?? 1); | ||
| }); | ||
| }); | ||
| } | ||
| // src/commands/login/index.ts | ||
| var import_chalk = __toESM(require_source(), 1); | ||
| // src/util/telemetry/commands/login/index.ts | ||
| var LoginTelemetryClient = class extends TelemetryClient { | ||
| /** | ||
| * Tracks the state of the login process. | ||
| * - `started` when the user initiates the login process. | ||
| * - `canceled` when the user cancels the login process. | ||
| * - `error` when the user encounters an error during the login process. | ||
| * - `success` when the user successfully logs in. | ||
| */ | ||
| trackState(...args) { | ||
| this.trackLoginState(...args); | ||
| } | ||
| }; | ||
| // src/commands/login/index.ts | ||
| async function login2(client, options) { | ||
| let parsedArgs = null; | ||
| const flagsSpecification = getFlagsSpecification(loginCommand.options); | ||
| const telemetry = new LoginTelemetryClient({ | ||
| opts: { | ||
| store: client.telemetryEventStore | ||
| } | ||
| }); | ||
| try { | ||
| if (options.shouldParseArgs) { | ||
| parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification); | ||
| } | ||
| } catch (error) { | ||
| printError(error); | ||
| return 1; | ||
| } | ||
| if (parsedArgs?.flags["--help"]) { | ||
| telemetry.trackCliFlagHelp("login"); | ||
| output_manager_default.print(help(loginCommand, { columns: client.stderr.columns })); | ||
| return 0; | ||
| } | ||
| if (parsedArgs?.flags["--token"]) { | ||
| output_manager_default.error('`--token` may not be used with the "login" command'); | ||
| return 2; | ||
| } | ||
| if (options.shouldParseArgs && parsedArgs) { | ||
| const obsoleteFlags = Object.keys(parsedArgs.flags).filter((flag) => { | ||
| const flagKey = flag.replace("--", ""); | ||
| const option = loginCommand.options.find((o) => o.name === flagKey); | ||
| if (!option || typeof option === "number") | ||
| return; | ||
| return "deprecated" in option && option.deprecated; | ||
| }); | ||
| if (obsoleteFlags.length) { | ||
| const flags = obsoleteFlags.map((f) => import_chalk.default.bold(f)).join(", "); | ||
| output_manager_default.warn(`The following flags are deprecated: ${flags}`); | ||
| } | ||
| const obsoleteArguments = parsedArgs.args.slice(1); | ||
| if (obsoleteArguments.length) { | ||
| const args = obsoleteArguments.map((a) => import_chalk.default.bold(a)).join(", "); | ||
| output_manager_default.warn(`The following arguments are deprecated: ${args}`); | ||
| } | ||
| if (obsoleteArguments.length || obsoleteFlags.length) { | ||
| output_manager_default.print( | ||
| `Read more in our ${output_manager_default.link("changelog", "https://vercel.com/changelog/new-vercel-cli-login-flow")}. | ||
| ` | ||
| ); | ||
| } | ||
| } | ||
| telemetry.trackState("started"); | ||
| return await login(client, telemetry); | ||
| } | ||
| // src/util/output/box.ts | ||
| var import_chalk2 = __toESM(require_source(), 1); | ||
| var import_strip_ansi = __toESM(require_strip_ansi(), 1); | ||
| var border = ["\u2500", "\u256D", "\u256E", "\u2502", "\u2502", "\u2570", "\u256F"]; | ||
| var nothing = ["\u2500", "", "", "", "", "", ""]; | ||
| function box(message, { | ||
| borderColor, | ||
| padding = 1, | ||
| textAlignment = "center", | ||
| terminalColumns: cols = process.stdout.columns || process.env.COLUMNS && parseInt(process.env.COLUMNS, 10) || 80 | ||
| } = {}) { | ||
| const lines = message.split(/\r?\n/).map((line) => [line, (0, import_strip_ansi.default)(line).length]); | ||
| const maxLine = lines.reduce((p, [, len]) => Math.max(p, len), 0); | ||
| const borderColorFn = borderColor && import_chalk2.default[borderColor] || import_chalk2.default.yellow; | ||
| const clampedSidePadding = Math.max(1, padding * 3); | ||
| const narrowMode = maxLine + 2 + clampedSidePadding * 2 > cols; | ||
| const sidePadding = narrowMode ? 0 : clampedSidePadding; | ||
| const innerWidth = Math.min(maxLine + sidePadding * 2, cols); | ||
| const [hr, topLeft, topRight, left, right, bottomLeft, bottomRight] = narrowMode ? nothing : border; | ||
| const spacerRow = narrowMode ? "\n".repeat(padding) : `${borderColorFn(`${left}${" ".repeat(innerWidth)}${right}`)} | ||
| `.repeat( | ||
| padding | ||
| ); | ||
| const renderLine = ([line, len]) => { | ||
| let leftPadding = 0; | ||
| let rightPadding = 0; | ||
| if (!narrowMode) { | ||
| leftPadding = sidePadding; | ||
| rightPadding = sidePadding; | ||
| if (textAlignment === "center") { | ||
| leftPadding += Math.floor((maxLine - len) / 2); | ||
| rightPadding += maxLine - len - leftPadding + sidePadding; | ||
| } else if (textAlignment === "right") { | ||
| leftPadding += maxLine - len; | ||
| } else if (textAlignment === "left") { | ||
| rightPadding += maxLine - len; | ||
| } | ||
| } | ||
| return borderColorFn(left) + " ".repeat(leftPadding) + line + " ".repeat(rightPadding) + borderColorFn(right); | ||
| }; | ||
| return borderColorFn(`${topLeft}${hr.repeat(innerWidth)}${topRight}`) + "\n" + spacerRow + lines.map(renderLine).join("\n") + "\n" + spacerRow + borderColorFn(`${bottomLeft}${hr.repeat(innerWidth)}${bottomRight}`); | ||
| } | ||
| // src/util/did-you-mean.ts | ||
| var import_jaro_winkler = __toESM(require_jaro_winkler(), 1); | ||
| var did_you_mean_default = didYouMean; | ||
| function didYouMean(input, list, threshold = 0.5) { | ||
| const rated = list.map((item) => [dashAwareDistance(input, item), item]); | ||
| const found = rated.filter((item) => item[0] > threshold); | ||
| if (found.length) { | ||
| const highestRated = found.reduce((accu, curr) => { | ||
| return accu[0] > curr[0] ? accu : curr; | ||
| }); | ||
| return highestRated[1]; | ||
| } | ||
| } | ||
| function dashAwareDistance(word, dashWord) { | ||
| const fullDistance = (0, import_jaro_winkler.default)(word, dashWord); | ||
| const distances = dashWord.split("-").map((w) => (0, import_jaro_winkler.default)(w, word)); | ||
| const meanDistance = distances.reduce((accu, curr) => accu + curr) / distances.length; | ||
| return fullDistance > meanDistance ? fullDistance : meanDistance; | ||
| } | ||
| export { | ||
| did_you_mean_default, | ||
| executeUpgrade, | ||
| login2 as login, | ||
| box | ||
| }; |
Sorry, the diff of this file is too big to display
| import { createRequire as __createRequire } from 'node:module'; | ||
| import { fileURLToPath as __fileURLToPath } from 'node:url'; | ||
| import { dirname as __dirname_ } from 'node:path'; | ||
| const require = __createRequire(import.meta.url); | ||
| const __filename = __fileURLToPath(import.meta.url); | ||
| const __dirname = __dirname_(__filename); | ||
| import { | ||
| handleValidationError, | ||
| normalizeRepeatableStringFilters, | ||
| outputError, | ||
| validateAllProjectMutualExclusivity, | ||
| validateIntegerRangeWithDefault, | ||
| validateTimeBound, | ||
| validateTimeOrder | ||
| } from "./chunk-IE7MNZ56.js"; | ||
| import { | ||
| getCommandFlags | ||
| } from "./chunk-EOZFDJSY.js"; | ||
| import { | ||
| getScope | ||
| } from "./chunk-XIQUACWR.js"; | ||
| import { | ||
| validateJsonOutput | ||
| } from "./chunk-XPKWKPWA.js"; | ||
| import { | ||
| activityCommand | ||
| } from "./chunk-LW5ZNGW7.js"; | ||
| import { | ||
| getLinkedProject, | ||
| getProjectByNameOrId | ||
| } from "./chunk-4MTNDNUR.js"; | ||
| import "./chunk-XB2KZC2B.js"; | ||
| import "./chunk-SOTR4CXR.js"; | ||
| import "./chunk-7EHTK7LP.js"; | ||
| import { | ||
| require_ms | ||
| } from "./chunk-GGP5R3FU.js"; | ||
| import { | ||
| ProjectNotFound, | ||
| getCommandName, | ||
| getFlagsSpecification, | ||
| isAPIError, | ||
| parseArguments, | ||
| printError | ||
| } from "./chunk-ZLCMHY2G.js"; | ||
| import "./chunk-3XFFP2BA.js"; | ||
| import { | ||
| output_manager_default | ||
| } from "./chunk-FDJURQMQ.js"; | ||
| import { | ||
| require_source | ||
| } from "./chunk-S7KYDPEM.js"; | ||
| import { | ||
| __toESM | ||
| } from "./chunk-TZ2YI2VH.js"; | ||
| // src/commands/activity/list.ts | ||
| var import_ms = __toESM(require_ms(), 1); | ||
| var import_chalk = __toESM(require_source(), 1); | ||
| function validateNext(next) { | ||
| if (next === void 0) { | ||
| return { valid: true, value: void 0 }; | ||
| } | ||
| if (Number.isNaN(next)) { | ||
| return { | ||
| valid: false, | ||
| code: "INVALID_NEXT", | ||
| message: "Please provide a number for flag `--next`." | ||
| }; | ||
| } | ||
| const date = new Date(next); | ||
| if (Number.isNaN(date.getTime())) { | ||
| return { | ||
| valid: false, | ||
| code: "INVALID_NEXT", | ||
| message: "Please provide a valid unix timestamp in milliseconds for `--next`." | ||
| }; | ||
| } | ||
| return { valid: true, value: date }; | ||
| } | ||
| function handleApiError(err, jsonOutput, client) { | ||
| if (err.status === 403) { | ||
| return outputError( | ||
| client, | ||
| jsonOutput, | ||
| "FORBIDDEN", | ||
| "You do not have permission to list activity events. Required permissions: Event: List or OwnEvent: List." | ||
| ); | ||
| } | ||
| return outputError( | ||
| client, | ||
| jsonOutput, | ||
| err.code || "API_ERROR", | ||
| err.serverMessage || `API error (${err.status}).` | ||
| ); | ||
| } | ||
| function formatActor(event) { | ||
| const principal = event.principal; | ||
| if (!principal) { | ||
| return event.principalId || "-"; | ||
| } | ||
| if (principal.type === "system") { | ||
| return "system"; | ||
| } | ||
| if (principal.username) { | ||
| return principal.username; | ||
| } | ||
| if (principal.name) { | ||
| return principal.name; | ||
| } | ||
| if (principal.slug) { | ||
| return principal.slug; | ||
| } | ||
| if (principal.email) { | ||
| return principal.email; | ||
| } | ||
| return event.principalId || "-"; | ||
| } | ||
| function formatAge(createdAt) { | ||
| if (!Number.isFinite(createdAt) || createdAt <= 0) { | ||
| return "-"; | ||
| } | ||
| const age = Math.max(0, Date.now() - createdAt); | ||
| return (0, import_ms.default)(age); | ||
| } | ||
| function formatEventText(text) { | ||
| return text.replace(/\s+/g, " ").trim(); | ||
| } | ||
| function printExpandedEvents(events) { | ||
| const lines = [""]; | ||
| events.forEach((event, index) => { | ||
| lines.push( | ||
| ` ${import_chalk.default.bold(`${index + 1}. ${formatEventText(event.text)}`)}` | ||
| ); | ||
| lines.push(` ${import_chalk.default.cyan("Type:")} ${event.type ?? "-"}`); | ||
| lines.push(` ${import_chalk.default.cyan("Actor:")} ${formatActor(event)}`); | ||
| lines.push(` ${import_chalk.default.cyan("Age:")} ${formatAge(event.createdAt)}`); | ||
| lines.push(` ${import_chalk.default.cyan("ID:")} ${event.id}`); | ||
| lines.push(""); | ||
| }); | ||
| output_manager_default.print(`${lines.join("\n")} | ||
| `); | ||
| } | ||
| function trackTelemetry(flags, types, telemetry) { | ||
| telemetry.trackCliOptionType(types.length > 0 ? types : void 0); | ||
| telemetry.trackCliOptionSince(flags["--since"]); | ||
| telemetry.trackCliOptionUntil(flags["--until"]); | ||
| telemetry.trackCliOptionProject(flags["--project"]); | ||
| telemetry.trackCliFlagAll(flags["--all"]); | ||
| telemetry.trackCliOptionLimit(flags["--limit"]); | ||
| telemetry.trackCliOptionNext(flags["--next"]); | ||
| telemetry.trackCliOptionFormat(flags["--format"]); | ||
| } | ||
| function parseFlags(client) { | ||
| const flagsSpecification = getFlagsSpecification(activityCommand.options); | ||
| try { | ||
| const parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification); | ||
| return parsedArgs.flags; | ||
| } catch (err) { | ||
| printError(err); | ||
| return 1; | ||
| } | ||
| } | ||
| function resolveValidatedInputs(flags, jsonOutput, client, normalizedTypes) { | ||
| const limitResult = validateIntegerRangeWithDefault(flags["--limit"], { | ||
| flag: "--limit", | ||
| min: 1, | ||
| max: 100, | ||
| defaultValue: 20 | ||
| }); | ||
| if (!limitResult.valid) { | ||
| return handleValidationError(limitResult, jsonOutput, client); | ||
| } | ||
| const mutualResult = validateAllProjectMutualExclusivity( | ||
| flags["--all"], | ||
| flags["--project"] | ||
| ); | ||
| if (!mutualResult.valid) { | ||
| return handleValidationError(mutualResult, jsonOutput, client); | ||
| } | ||
| const sinceResult = validateTimeBound(flags["--since"]); | ||
| if (!sinceResult.valid) { | ||
| return handleValidationError(sinceResult, jsonOutput, client); | ||
| } | ||
| const nextResult = validateNext(flags["--next"]); | ||
| if (!nextResult.valid) { | ||
| return handleValidationError(nextResult, jsonOutput, client); | ||
| } | ||
| let until = nextResult.value; | ||
| if (!until) { | ||
| const untilResult = validateTimeBound(flags["--until"]); | ||
| if (!untilResult.valid) { | ||
| return handleValidationError(untilResult, jsonOutput, client); | ||
| } | ||
| until = untilResult.value; | ||
| } | ||
| const since = sinceResult.value; | ||
| const timeOrderResult = validateTimeOrder(since, until); | ||
| if (!timeOrderResult.valid) { | ||
| return handleValidationError(timeOrderResult, jsonOutput, client); | ||
| } | ||
| return { | ||
| limit: limitResult.value, | ||
| types: normalizedTypes, | ||
| since, | ||
| until | ||
| }; | ||
| } | ||
| async function resolveScope(client, opts) { | ||
| if (opts.all || opts.project) { | ||
| const { team } = await getScope(client); | ||
| if (!team) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "NO_TEAM", | ||
| "No team context found. Run `vercel switch` to select a team, or use `vercel link` in a project directory." | ||
| ); | ||
| } | ||
| if (opts.all) { | ||
| return { | ||
| teamId: team.id, | ||
| teamSlug: team.slug | ||
| }; | ||
| } | ||
| let projectResult; | ||
| try { | ||
| projectResult = await getProjectByNameOrId( | ||
| client, | ||
| opts.project, | ||
| team.id | ||
| ); | ||
| } catch (err) { | ||
| if (isAPIError(err)) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| err.code || "API_ERROR", | ||
| err.serverMessage || (err.status === 403 ? `You do not have permission to access project "${opts.project}" in team "${team.slug}".` : `API error (${err.status}).`) | ||
| ); | ||
| } | ||
| throw err; | ||
| } | ||
| if (projectResult instanceof ProjectNotFound) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "PROJECT_NOT_FOUND", | ||
| `Project "${opts.project}" was not found in team "${team.slug}".` | ||
| ); | ||
| } | ||
| return { | ||
| teamId: team.id, | ||
| teamSlug: team.slug, | ||
| projectIds: [projectResult.id] | ||
| }; | ||
| } | ||
| const linkedProject = await getLinkedProject(client); | ||
| if (linkedProject.status === "error") { | ||
| return linkedProject.exitCode; | ||
| } | ||
| if (linkedProject.status === "not_linked") { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "NOT_LINKED", | ||
| "No linked project found. Run `vercel link` to link a project, or use --project <name> or --all." | ||
| ); | ||
| } | ||
| const isTeamProject = linkedProject.org.type === "team"; | ||
| return { | ||
| projectIds: [linkedProject.project.id], | ||
| teamId: isTeamProject ? linkedProject.org.id : void 0, | ||
| teamSlug: isTeamProject ? linkedProject.org.slug : void 0 | ||
| }; | ||
| } | ||
| function buildEventsQuery(params) { | ||
| const query = new URLSearchParams({ | ||
| limit: String(params.limit + 1) | ||
| }); | ||
| if (params.types.length > 0) { | ||
| query.set("types", params.types.join(",")); | ||
| } | ||
| if (params.since) { | ||
| query.set("since", params.since.toISOString()); | ||
| } | ||
| if (params.until) { | ||
| query.set("until", params.until.toISOString()); | ||
| } | ||
| if (params.scope.projectIds && params.scope.projectIds.length > 0) { | ||
| query.set("projectIds", params.scope.projectIds.join(",")); | ||
| } | ||
| if (params.scope.teamId) { | ||
| query.set("teamId", params.scope.teamId); | ||
| } | ||
| if (params.scope.teamSlug) { | ||
| query.set("slug", params.scope.teamSlug); | ||
| } | ||
| if (params.jsonOutput) { | ||
| query.set("withPayload", "true"); | ||
| } | ||
| return query; | ||
| } | ||
| function paginateEvents(allEvents, limit) { | ||
| const events = allEvents.slice(0, limit); | ||
| const hasMore = allEvents.length > limit; | ||
| const lastVisibleEvent = events[events.length - 1]; | ||
| const next = hasMore && typeof lastVisibleEvent?.createdAt === "number" ? lastVisibleEvent.createdAt - 1 : null; | ||
| return { events, next }; | ||
| } | ||
| function printNextPageHint(flags, next) { | ||
| const commandFlags = getCommandFlags(flags, ["--next"]); | ||
| output_manager_default.log( | ||
| `To display the next page, run ${getCommandName( | ||
| `activity${commandFlags} --next ${next}` | ||
| )}` | ||
| ); | ||
| } | ||
| async function list(client, telemetry) { | ||
| const flags = parseFlags(client); | ||
| if (typeof flags === "number") { | ||
| return flags; | ||
| } | ||
| const formatResult = validateJsonOutput(flags); | ||
| if (!formatResult.valid) { | ||
| output_manager_default.error(formatResult.error); | ||
| return 1; | ||
| } | ||
| const jsonOutput = formatResult.jsonOutput; | ||
| const normalizedTypes = normalizeRepeatableStringFilters(flags["--type"]); | ||
| trackTelemetry(flags, normalizedTypes, telemetry); | ||
| const validatedInputs = resolveValidatedInputs( | ||
| flags, | ||
| jsonOutput, | ||
| client, | ||
| normalizedTypes | ||
| ); | ||
| if (typeof validatedInputs === "number") { | ||
| return validatedInputs; | ||
| } | ||
| const scope = await resolveScope(client, { | ||
| project: flags["--project"], | ||
| all: flags["--all"], | ||
| jsonOutput | ||
| }); | ||
| if (typeof scope === "number") { | ||
| return scope; | ||
| } | ||
| const query = buildEventsQuery({ | ||
| limit: validatedInputs.limit, | ||
| types: validatedInputs.types, | ||
| since: validatedInputs.since, | ||
| until: validatedInputs.until, | ||
| scope, | ||
| jsonOutput | ||
| }); | ||
| output_manager_default.spinner("Fetching activity..."); | ||
| try { | ||
| const response = await client.fetch( | ||
| `/v3/events?${query.toString()}`, | ||
| { | ||
| useCurrentTeam: false | ||
| } | ||
| ); | ||
| const allEvents = Array.isArray(response.events) ? response.events : []; | ||
| const { events, next } = paginateEvents(allEvents, validatedInputs.limit); | ||
| if (jsonOutput) { | ||
| client.stdout.write( | ||
| `${JSON.stringify({ events, pagination: { next } }, null, 2)} | ||
| ` | ||
| ); | ||
| return 0; | ||
| } | ||
| if (events.length === 0) { | ||
| output_manager_default.log("No activity events found."); | ||
| return 0; | ||
| } | ||
| printExpandedEvents(events); | ||
| if (next !== null) { | ||
| printNextPageHint(flags, next); | ||
| } | ||
| return 0; | ||
| } catch (err) { | ||
| if (isAPIError(err)) { | ||
| return handleApiError(err, jsonOutput, client); | ||
| } | ||
| throw err; | ||
| } finally { | ||
| output_manager_default.stopSpinner(); | ||
| } | ||
| } | ||
| export { | ||
| list as default | ||
| }; |
| import { createRequire as __createRequire } from 'node:module'; | ||
| import { fileURLToPath as __fileURLToPath } from 'node:url'; | ||
| import { dirname as __dirname_ } from 'node:path'; | ||
| const require = __createRequire(import.meta.url); | ||
| const __filename = __fileURLToPath(import.meta.url); | ||
| const __dirname = __dirname_(__filename); | ||
| import { | ||
| handleValidationError, | ||
| normalizeRepeatableStringFilters, | ||
| outputError, | ||
| validateAllProjectMutualExclusivity, | ||
| validateOptionalIntegerRange, | ||
| validateTimeBound, | ||
| validateTimeOrder | ||
| } from "./chunk-IE7MNZ56.js"; | ||
| import { | ||
| getScope | ||
| } from "./chunk-XIQUACWR.js"; | ||
| import { | ||
| validateJsonOutput | ||
| } from "./chunk-XPKWKPWA.js"; | ||
| import { | ||
| alertsCommand | ||
| } from "./chunk-P5Q6F5IA.js"; | ||
| import { | ||
| getLinkedProject, | ||
| getProjectByNameOrId | ||
| } from "./chunk-4MTNDNUR.js"; | ||
| import "./chunk-XB2KZC2B.js"; | ||
| import "./chunk-SOTR4CXR.js"; | ||
| import { | ||
| table | ||
| } from "./chunk-LWBSOTJP.js"; | ||
| import "./chunk-7EHTK7LP.js"; | ||
| import { | ||
| require_ms | ||
| } from "./chunk-GGP5R3FU.js"; | ||
| import { | ||
| ProjectNotFound, | ||
| getFlagsSpecification, | ||
| isAPIError, | ||
| parseArguments, | ||
| printError | ||
| } from "./chunk-ZLCMHY2G.js"; | ||
| import "./chunk-3XFFP2BA.js"; | ||
| import { | ||
| output_manager_default | ||
| } from "./chunk-FDJURQMQ.js"; | ||
| import { | ||
| require_source | ||
| } from "./chunk-S7KYDPEM.js"; | ||
| import { | ||
| __toESM | ||
| } from "./chunk-TZ2YI2VH.js"; | ||
| // src/commands/alerts/list.ts | ||
| var import_ms = __toESM(require_ms(), 1); | ||
| var import_chalk = __toESM(require_source(), 1); | ||
| function handleApiError(err, jsonOutput, client) { | ||
| const message = err.status === 401 || err.status === 403 ? "You do not have access to alerts in this scope. Pass --token <TOKEN> and --scope <team-slug> with Alerts read access." : err.status >= 500 ? `The alerts endpoint failed on the server (${err.status}). Re-run with --debug and share the x-vercel-id from the failed request.` : err.serverMessage || `API error (${err.status}).`; | ||
| return outputError(client, jsonOutput, err.code || "API_ERROR", message); | ||
| } | ||
| function getDefaultRange() { | ||
| const to = /* @__PURE__ */ new Date(); | ||
| const from = new Date(to.getTime() - 24 * 60 * 60 * 1e3); | ||
| return { from: from.toISOString(), to: to.toISOString() }; | ||
| } | ||
| async function resolveScope(client, opts) { | ||
| if (opts.all || opts.project) { | ||
| const { team } = await getScope(client); | ||
| if (!team) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "NO_TEAM", | ||
| "No team context found. Run `vercel switch` to select a team, or use `vercel link` in a project directory." | ||
| ); | ||
| } | ||
| if (opts.all) { | ||
| return { | ||
| teamId: team.id | ||
| }; | ||
| } | ||
| let projectResult; | ||
| try { | ||
| projectResult = await getProjectByNameOrId( | ||
| client, | ||
| opts.project, | ||
| team.id | ||
| ); | ||
| } catch (err) { | ||
| if (isAPIError(err)) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| err.code || "API_ERROR", | ||
| err.serverMessage || (err.status === 403 ? `You do not have permission to access project "${opts.project}" in team "${team.slug}".` : `API error (${err.status}).`) | ||
| ); | ||
| } | ||
| throw err; | ||
| } | ||
| if (projectResult instanceof ProjectNotFound) { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "PROJECT_NOT_FOUND", | ||
| `Project "${opts.project}" was not found in team "${team.slug}".` | ||
| ); | ||
| } | ||
| return { | ||
| teamId: team.id, | ||
| projectId: projectResult.id | ||
| }; | ||
| } | ||
| const linkedProject = await getLinkedProject(client); | ||
| if (linkedProject.status === "error") { | ||
| return linkedProject.exitCode; | ||
| } | ||
| if (linkedProject.status === "not_linked") { | ||
| return outputError( | ||
| client, | ||
| opts.jsonOutput, | ||
| "NOT_LINKED", | ||
| "No linked project found. Run `vercel link` to link a project, or use --project <name> or --all." | ||
| ); | ||
| } | ||
| return { | ||
| teamId: linkedProject.org.id, | ||
| projectId: linkedProject.project.id | ||
| }; | ||
| } | ||
| function getGroupTitle(group) { | ||
| return group.ai?.title || "Alert group"; | ||
| } | ||
| function parseDateInput(value) { | ||
| if (value === void 0) { | ||
| return void 0; | ||
| } | ||
| const epochMs = value < 1e12 ? value * 1e3 : value; | ||
| const date = new Date(epochMs); | ||
| return Number.isNaN(date.getTime()) ? void 0 : date; | ||
| } | ||
| function formatDateForDisplay(value) { | ||
| const date = parseDateInput(value); | ||
| if (!date) { | ||
| return "-"; | ||
| } | ||
| return date.toLocaleString("en-US", { | ||
| year: "numeric", | ||
| month: "short", | ||
| day: "2-digit", | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| second: "2-digit", | ||
| hour12: false, | ||
| timeZoneName: "short" | ||
| }); | ||
| } | ||
| function getStartedAt(group) { | ||
| return formatDateForDisplay(getGroupStartedAt(group)?.getTime()); | ||
| } | ||
| function getGroupStartedAt(group) { | ||
| return parseDateInput(group.recordedStartedAt) || parseDateInput(group.alerts?.[0]?.startedAt); | ||
| } | ||
| function getGroupResolvedAt(group) { | ||
| const resolvedTimes = (group.alerts ?? []).map((alert) => parseDateInput(alert.resolvedAt)).filter((d) => Boolean(d)).map((d) => d.getTime()); | ||
| if (resolvedTimes.length > 0) { | ||
| return new Date(Math.max(...resolvedTimes)); | ||
| } | ||
| return getGroupStartedAt(group); | ||
| } | ||
| function getStatus(group) { | ||
| const normalizedStatus = (group.status || "").toLowerCase(); | ||
| if (normalizedStatus === "active") { | ||
| return "active"; | ||
| } | ||
| if (normalizedStatus === "resolved") { | ||
| const startedAt = getGroupStartedAt(group); | ||
| const resolvedAt = getGroupResolvedAt(group); | ||
| if (startedAt && resolvedAt && resolvedAt.getTime() >= startedAt.getTime()) { | ||
| return `resolved after ${(0, import_ms.default)(resolvedAt.getTime() - startedAt.getTime())}`; | ||
| } | ||
| return "resolved"; | ||
| } | ||
| return group.status || "-"; | ||
| } | ||
| function getResolvedAt(group) { | ||
| const normalizedStatus = (group.status || "").toLowerCase(); | ||
| if (normalizedStatus === "active") { | ||
| return "active"; | ||
| } | ||
| return formatDateForDisplay(getGroupResolvedAt(group)?.getTime()); | ||
| } | ||
| function getAlertsCount(group) { | ||
| return String(group.alerts?.length ?? 0); | ||
| } | ||
| function printGroups(groups) { | ||
| if (groups.length === 0) { | ||
| output_manager_default.log("No alerts found."); | ||
| return; | ||
| } | ||
| const headers = ["Title", "Started At", "Type", "Status", "Alerts"].map( | ||
| (h) => import_chalk.default.cyan(h) | ||
| ); | ||
| const rows = [ | ||
| headers, | ||
| ...groups.map((group) => [ | ||
| import_chalk.default.bold(getGroupTitle(group)), | ||
| getStartedAt(group), | ||
| group.type || "-", | ||
| getStatus(group), | ||
| getAlertsCount(group) | ||
| ]) | ||
| ]; | ||
| const tableOutput = table(rows, { hsep: 3 }).split("\n").map((line) => line.trimEnd()).join("\n").replace(/^/gm, " "); | ||
| output_manager_default.print(` | ||
| ${tableOutput} | ||
| `); | ||
| } | ||
| function printAiSections(groups) { | ||
| if (groups.length === 0) { | ||
| output_manager_default.log("No alerts found."); | ||
| return; | ||
| } | ||
| const rendered = groups.map((group, index) => { | ||
| const title = getGroupTitle(group); | ||
| const summary = group.ai?.currentSummary || "N/A"; | ||
| const findings = group.ai?.keyFindings?.filter(Boolean) ?? []; | ||
| const findingsOutput = findings.length > 0 ? findings.map((finding) => ` - ${finding}`).join("\n") : " - N/A"; | ||
| return [ | ||
| import_chalk.default.bold(`${index + 1}. ${title}`), | ||
| ` ${import_chalk.default.cyan("Resolved At:")} ${getResolvedAt(group)}`, | ||
| ` ${import_chalk.default.cyan("Summary:")} ${summary}`, | ||
| ` ${import_chalk.default.cyan("Key Findings:")}`, | ||
| findingsOutput | ||
| ].join("\n"); | ||
| }).join("\n\n"); | ||
| output_manager_default.print(` | ||
| ${rendered} | ||
| `); | ||
| } | ||
| function trackTelemetry(flags, types, telemetry) { | ||
| telemetry.trackCliOptionType(types.length > 0 ? types : void 0); | ||
| telemetry.trackCliOptionSince(flags["--since"]); | ||
| telemetry.trackCliOptionUntil(flags["--until"]); | ||
| telemetry.trackCliOptionProject(flags["--project"]); | ||
| telemetry.trackCliFlagAll(flags["--all"]); | ||
| telemetry.trackCliFlagAi(flags["--ai"]); | ||
| telemetry.trackCliOptionLimit(flags["--limit"]); | ||
| telemetry.trackCliOptionFormat(flags["--format"]); | ||
| } | ||
| function parseFlags(client) { | ||
| const flagsSpecification = getFlagsSpecification(alertsCommand.options); | ||
| try { | ||
| const parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification); | ||
| return parsedArgs.flags; | ||
| } catch (err) { | ||
| printError(err); | ||
| return 1; | ||
| } | ||
| } | ||
| function resolveValidatedInputs(flags, client, jsonOutput) { | ||
| const types = normalizeRepeatableStringFilters(flags["--type"]); | ||
| const limitResult = validateOptionalIntegerRange(flags["--limit"], { | ||
| flag: "--limit", | ||
| min: 1, | ||
| max: 100 | ||
| }); | ||
| if (!limitResult.valid) { | ||
| return handleValidationError(limitResult, jsonOutput, client); | ||
| } | ||
| const mutualResult = validateAllProjectMutualExclusivity( | ||
| flags["--all"], | ||
| flags["--project"] | ||
| ); | ||
| if (!mutualResult.valid) { | ||
| return handleValidationError(mutualResult, jsonOutput, client); | ||
| } | ||
| const sinceResult = validateTimeBound(flags["--since"]); | ||
| if (!sinceResult.valid) { | ||
| return handleValidationError(sinceResult, jsonOutput, client); | ||
| } | ||
| const untilResult = validateTimeBound(flags["--until"]); | ||
| if (!untilResult.valid) { | ||
| return handleValidationError(untilResult, jsonOutput, client); | ||
| } | ||
| const timeOrderResult = validateTimeOrder( | ||
| sinceResult.value, | ||
| untilResult.value | ||
| ); | ||
| if (!timeOrderResult.valid) { | ||
| return handleValidationError(timeOrderResult, jsonOutput, client); | ||
| } | ||
| return { | ||
| limit: limitResult.value, | ||
| types, | ||
| since: sinceResult.value, | ||
| until: untilResult.value | ||
| }; | ||
| } | ||
| function buildAlertsQuery(scope, inputs) { | ||
| const query = new URLSearchParams({ | ||
| teamId: scope.teamId | ||
| }); | ||
| if (scope.projectId) { | ||
| query.set("projectId", scope.projectId); | ||
| } | ||
| if (inputs.limit) { | ||
| query.set("limit", String(inputs.limit)); | ||
| } | ||
| for (const type of inputs.types) { | ||
| query.append("types", type); | ||
| } | ||
| if (inputs.since) { | ||
| query.set("from", inputs.since.toISOString()); | ||
| } | ||
| if (inputs.until) { | ||
| query.set("to", inputs.until.toISOString()); | ||
| } | ||
| if (!inputs.since && !inputs.until) { | ||
| const defaultRange = getDefaultRange(); | ||
| query.set("from", defaultRange.from); | ||
| query.set("to", defaultRange.to); | ||
| } | ||
| return query; | ||
| } | ||
| async function list(client, telemetry) { | ||
| const flags = parseFlags(client); | ||
| if (typeof flags === "number") { | ||
| return flags; | ||
| } | ||
| const formatResult = validateJsonOutput(flags); | ||
| if (!formatResult.valid) { | ||
| output_manager_default.error(formatResult.error); | ||
| return 1; | ||
| } | ||
| const jsonOutput = formatResult.jsonOutput; | ||
| const types = normalizeRepeatableStringFilters(flags["--type"]); | ||
| trackTelemetry(flags, types, telemetry); | ||
| const validatedInputs = resolveValidatedInputs(flags, client, jsonOutput); | ||
| if (typeof validatedInputs === "number") { | ||
| return validatedInputs; | ||
| } | ||
| const scope = await resolveScope(client, { | ||
| project: flags["--project"], | ||
| all: flags["--all"], | ||
| jsonOutput | ||
| }); | ||
| if (typeof scope === "number") { | ||
| return scope; | ||
| } | ||
| const query = buildAlertsQuery(scope, validatedInputs); | ||
| const requestPath = `/alerts/v3/groups?${query.toString()}`; | ||
| output_manager_default.debug(`Fetching alerts from ${requestPath}`); | ||
| output_manager_default.spinner("Fetching alerts..."); | ||
| try { | ||
| const groups = await client.fetch(requestPath); | ||
| if (jsonOutput) { | ||
| client.stdout.write(`${JSON.stringify({ groups }, null, 2)} | ||
| `); | ||
| } else { | ||
| if (flags["--ai"]) { | ||
| printAiSections(groups); | ||
| } else { | ||
| printGroups(groups); | ||
| } | ||
| } | ||
| return 0; | ||
| } catch (err) { | ||
| if (isAPIError(err)) { | ||
| return handleApiError(err, jsonOutput, client); | ||
| } | ||
| output_manager_default.debug(err); | ||
| const message = `Failed to fetch alerts: ${err.message || String(err)}`; | ||
| return outputError(client, jsonOutput, "UNEXPECTED_ERROR", message); | ||
| } finally { | ||
| output_manager_default.stopSpinner(); | ||
| } | ||
| } | ||
| export { | ||
| list as default | ||
| }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 68 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 69 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
8120217
0.4%195931
0.55%418
0.24%