@depup/vercel 50.32.5-depup.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/LICENSE +202 -0
- package/README.md +38 -0
- package/changes.json +38 -0
- package/dist/chunks/chunk-2DLBVZWU.js +197 -0
- package/dist/chunks/chunk-2HSQ7YUK.js +93 -0
- package/dist/chunks/chunk-2IQTNMUG.js +86 -0
- package/dist/chunks/chunk-3FRG2XGZ.js +466 -0
- package/dist/chunks/chunk-3KMKI2FP.js +34 -0
- package/dist/chunks/chunk-3XFFP2BA.js +110 -0
- package/dist/chunks/chunk-4S3Y3ATR.js +5383 -0
- package/dist/chunks/chunk-7EHTK7LP.js +359 -0
- package/dist/chunks/chunk-7YHZDJ4G.js +116 -0
- package/dist/chunks/chunk-A3NYPUKZ.js +17 -0
- package/dist/chunks/chunk-AA7QEJFB.js +5204 -0
- package/dist/chunks/chunk-AHU7WNL2.js +24 -0
- package/dist/chunks/chunk-AKQZ7KG3.js +4172 -0
- package/dist/chunks/chunk-AQLVWVEN.js +39155 -0
- package/dist/chunks/chunk-BQ3DXZNT.js +968 -0
- package/dist/chunks/chunk-E65JE2CC.js +102 -0
- package/dist/chunks/chunk-EKPSCRJZ.js +26 -0
- package/dist/chunks/chunk-EOZFDJSY.js +18 -0
- package/dist/chunks/chunk-FDJURQMQ.js +4676 -0
- package/dist/chunks/chunk-FLKHKWZV.js +1854 -0
- package/dist/chunks/chunk-G6BUEBF5.js +192 -0
- package/dist/chunks/chunk-GBNIO3KP.js +771 -0
- package/dist/chunks/chunk-GGP5R3FU.js +129 -0
- package/dist/chunks/chunk-H5XJSH37.js +91 -0
- package/dist/chunks/chunk-IB5L4LKZ.js +1082 -0
- package/dist/chunks/chunk-IE7MNZ56.js +149 -0
- package/dist/chunks/chunk-IK7DLK2T.js +16112 -0
- package/dist/chunks/chunk-IUGPWINM.js +104 -0
- package/dist/chunks/chunk-J7HDA5GH.js +54 -0
- package/dist/chunks/chunk-JLYZNGYY.js +293 -0
- package/dist/chunks/chunk-JQ4NA5MX.js +250 -0
- package/dist/chunks/chunk-LL26LVRR.js +81 -0
- package/dist/chunks/chunk-LW5ZNGW7.js +127 -0
- package/dist/chunks/chunk-LWBSOTJP.js +1772 -0
- package/dist/chunks/chunk-MBGJBHYD.js +388 -0
- package/dist/chunks/chunk-NUKAG3YM.js +168 -0
- package/dist/chunks/chunk-O7I4ZOCC.js +58 -0
- package/dist/chunks/chunk-OWR3XNE3.js +48 -0
- package/dist/chunks/chunk-P3SKP5WM.js +27 -0
- package/dist/chunks/chunk-P4I4DMEU.js +342 -0
- package/dist/chunks/chunk-P5Q6F5IA.js +107 -0
- package/dist/chunks/chunk-PMSMUMUO.js +30 -0
- package/dist/chunks/chunk-QXRJ52T4.js +2977 -0
- package/dist/chunks/chunk-RQXPRFRM.js +90 -0
- package/dist/chunks/chunk-S7KYDPEM.js +1564 -0
- package/dist/chunks/chunk-SGGLJFUZ.js +68 -0
- package/dist/chunks/chunk-SOTR4CXR.js +34 -0
- package/dist/chunks/chunk-TEVP63TU.js +1717 -0
- package/dist/chunks/chunk-TNBMKNET.js +323 -0
- package/dist/chunks/chunk-TZ2YI2VH.js +87 -0
- package/dist/chunks/chunk-U6XOC6E4.js +903 -0
- package/dist/chunks/chunk-V5P25P7F.js +22 -0
- package/dist/chunks/chunk-WQ5CUZWR.js +333 -0
- package/dist/chunks/chunk-WU2BPWRP.js +12237 -0
- package/dist/chunks/chunk-XPKWKPWA.js +44 -0
- package/dist/chunks/chunk-XR53KVJD.js +33 -0
- package/dist/chunks/chunk-Y4JJYHUG.js +16 -0
- package/dist/chunks/chunk-YPQSDAEW.js +29 -0
- package/dist/chunks/chunk-ZB2UO4V2.js +135 -0
- package/dist/chunks/chunk-ZLCMHY2G.js +1528 -0
- package/dist/chunks/compile-vercel-config-XU3YY2CZ.js +32 -0
- package/dist/chunks/delete-EJ2V7KQO.js +144 -0
- package/dist/chunks/disable-BKRFMX4U.js +122 -0
- package/dist/chunks/discard-4WF34DXK.js +118 -0
- package/dist/chunks/edit-FQE7JGU3.js +509 -0
- package/dist/chunks/emit-flags-datafiles-QYKPNWPX.js +17 -0
- package/dist/chunks/enable-VCNMX63U.js +122 -0
- package/dist/chunks/export-3KNVJCQR.js +133 -0
- package/dist/chunks/list-43XQCGKH.js +382 -0
- package/dist/chunks/list-DUL6PHUR.js +394 -0
- package/dist/chunks/publish-CF7GVZK3.js +128 -0
- package/dist/chunks/query-KWKO7VWO.js +954 -0
- package/dist/chunks/reorder-GU65YMIN.js +259 -0
- package/dist/chunks/restore-Q7ENGWVJ.js +158 -0
- package/dist/chunks/routes-Q5CWG44T.js +20 -0
- package/dist/chunks/schema-PJKLO2K2.js +176 -0
- package/dist/chunks/stamp-RTPE2EBB.js +15 -0
- package/dist/chunks/types-563KUQRV.js +108 -0
- package/dist/chunks/update-route-version-E3V47KNI.js +13 -0
- package/dist/commands/build/index.js +1597 -0
- package/dist/commands/deploy/index.js +1711 -0
- package/dist/commands/dev/builder-worker.cjs +95 -0
- package/dist/commands/dev/index.js +20810 -0
- package/dist/commands/env/index.js +2154 -0
- package/dist/commands/link/index.js +225 -0
- package/dist/commands/list/index.js +528 -0
- package/dist/commands-bulk.js +29627 -0
- package/dist/get-latest-worker.cjs +272 -0
- package/dist/help.js +14 -0
- package/dist/index.js +24274 -0
- package/dist/vc.js +36 -0
- package/dist/version.mjs +1 -0
- package/package.json +254 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __dirname_ } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __dirname_(__filename);
|
|
7
|
+
import {
|
|
8
|
+
ensureProjectLink,
|
|
9
|
+
getRoutes,
|
|
10
|
+
parseSubcommandArgs
|
|
11
|
+
} from "./chunk-TNBMKNET.js";
|
|
12
|
+
import {
|
|
13
|
+
exportSubcommand
|
|
14
|
+
} from "./chunk-U6XOC6E4.js";
|
|
15
|
+
import "./chunk-AQLVWVEN.js";
|
|
16
|
+
import "./chunk-P4I4DMEU.js";
|
|
17
|
+
import "./chunk-SOTR4CXR.js";
|
|
18
|
+
import "./chunk-7EHTK7LP.js";
|
|
19
|
+
import "./chunk-GGP5R3FU.js";
|
|
20
|
+
import {
|
|
21
|
+
getCommandName
|
|
22
|
+
} from "./chunk-ZLCMHY2G.js";
|
|
23
|
+
import "./chunk-3XFFP2BA.js";
|
|
24
|
+
import {
|
|
25
|
+
output_manager_default
|
|
26
|
+
} from "./chunk-FDJURQMQ.js";
|
|
27
|
+
import "./chunk-S7KYDPEM.js";
|
|
28
|
+
import "./chunk-TZ2YI2VH.js";
|
|
29
|
+
|
|
30
|
+
// src/commands/routes/export.ts
|
|
31
|
+
function cleanRoute(route) {
|
|
32
|
+
const cleaned = {};
|
|
33
|
+
for (const [key, value] of Object.entries(route)) {
|
|
34
|
+
if (value === void 0)
|
|
35
|
+
continue;
|
|
36
|
+
if (key === "middlewarePath" || key === "middlewareRawSrc" || key === "middleware" || key === "check" || key === "important") {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
cleaned[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return cleaned;
|
|
42
|
+
}
|
|
43
|
+
function routesToVercelJson(rules) {
|
|
44
|
+
const enabledRoutes = rules.filter((r) => r.enabled !== false);
|
|
45
|
+
const cleaned = enabledRoutes.map((r) => cleanRoute(r.route));
|
|
46
|
+
const config = { routes: cleaned };
|
|
47
|
+
return JSON.stringify(config, null, 2);
|
|
48
|
+
}
|
|
49
|
+
function routesToVercelTs(rules) {
|
|
50
|
+
const enabledRoutes = rules.filter((r) => r.enabled !== false);
|
|
51
|
+
const routeEntries = enabledRoutes.map((r) => {
|
|
52
|
+
const cleaned = cleanRoute(r.route);
|
|
53
|
+
const routeJson = JSON.stringify(cleaned, null, 2);
|
|
54
|
+
const indented = routeJson.split("\n").map((line, i) => i === 0 ? line : ` ${line}`).join("\n");
|
|
55
|
+
if (r.description) {
|
|
56
|
+
const safeDesc = r.description.replace(/\n/g, " ");
|
|
57
|
+
return ` // ${safeDesc}
|
|
58
|
+
${indented}`;
|
|
59
|
+
}
|
|
60
|
+
return ` ${indented}`;
|
|
61
|
+
});
|
|
62
|
+
const routesContent = routeEntries.length > 0 ? `
|
|
63
|
+
${routeEntries.join(",\n")},
|
|
64
|
+
` : "";
|
|
65
|
+
return `import type { VercelConfig } from '@vercel/config/v1';
|
|
66
|
+
|
|
67
|
+
export const config: VercelConfig = {
|
|
68
|
+
routes: [${routesContent}],
|
|
69
|
+
};
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
async function exportRoutes(client, argv) {
|
|
73
|
+
const parsed = await parseSubcommandArgs(argv, exportSubcommand);
|
|
74
|
+
if (typeof parsed === "number")
|
|
75
|
+
return parsed;
|
|
76
|
+
const link = await ensureProjectLink(client);
|
|
77
|
+
if (typeof link === "number")
|
|
78
|
+
return link;
|
|
79
|
+
const { project, org } = link;
|
|
80
|
+
const teamId = org.type === "team" ? org.id : void 0;
|
|
81
|
+
const { args, flags } = parsed;
|
|
82
|
+
const format = flags["--format"] || "json";
|
|
83
|
+
const nameOrId = args[0];
|
|
84
|
+
const validFormats = ["json", "ts"];
|
|
85
|
+
if (!validFormats.includes(format)) {
|
|
86
|
+
output_manager_default.error(
|
|
87
|
+
`Invalid format: "${format}". Valid formats: ${validFormats.join(", ")}. Usage: ${getCommandName("routes export --format json")}`
|
|
88
|
+
);
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
output_manager_default.spinner("Fetching routes");
|
|
92
|
+
try {
|
|
93
|
+
const { routes } = await getRoutes(client, project.id, { teamId });
|
|
94
|
+
if (routes.length === 0) {
|
|
95
|
+
output_manager_default.log(
|
|
96
|
+
`No routes found. Create one with ${getCommandName("routes add")}.`
|
|
97
|
+
);
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
let routesToExport = routes;
|
|
101
|
+
if (nameOrId) {
|
|
102
|
+
const query = nameOrId.toLowerCase();
|
|
103
|
+
routesToExport = routes.filter(
|
|
104
|
+
(r) => r.name.toLowerCase() === query || r.name.toLowerCase().includes(query) || r.id === nameOrId
|
|
105
|
+
);
|
|
106
|
+
if (routesToExport.length === 0) {
|
|
107
|
+
output_manager_default.error(
|
|
108
|
+
`No route found matching "${nameOrId}". Run ${getCommandName("routes list")} to see all routes.`
|
|
109
|
+
);
|
|
110
|
+
return 1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
let result;
|
|
114
|
+
switch (format) {
|
|
115
|
+
case "ts":
|
|
116
|
+
result = routesToVercelTs(routesToExport);
|
|
117
|
+
break;
|
|
118
|
+
default:
|
|
119
|
+
result = routesToVercelJson(routesToExport);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
output_manager_default.stopSpinner();
|
|
123
|
+
client.stdout.write(result.trimEnd() + "\n");
|
|
124
|
+
return 0;
|
|
125
|
+
} catch (e) {
|
|
126
|
+
const error = e;
|
|
127
|
+
output_manager_default.error(error.message || "Failed to export routes");
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
exportRoutes as default
|
|
133
|
+
};
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __dirname_ } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __dirname_(__filename);
|
|
7
|
+
import {
|
|
8
|
+
handleValidationError,
|
|
9
|
+
normalizeRepeatableStringFilters,
|
|
10
|
+
outputError,
|
|
11
|
+
validateAllProjectMutualExclusivity,
|
|
12
|
+
validateOptionalIntegerRange,
|
|
13
|
+
validateTimeBound,
|
|
14
|
+
validateTimeOrder
|
|
15
|
+
} from "./chunk-IE7MNZ56.js";
|
|
16
|
+
import {
|
|
17
|
+
getScope
|
|
18
|
+
} from "./chunk-3KMKI2FP.js";
|
|
19
|
+
import {
|
|
20
|
+
validateJsonOutput
|
|
21
|
+
} from "./chunk-XPKWKPWA.js";
|
|
22
|
+
import {
|
|
23
|
+
alertsCommand
|
|
24
|
+
} from "./chunk-P5Q6F5IA.js";
|
|
25
|
+
import {
|
|
26
|
+
getLinkedProject,
|
|
27
|
+
getProjectByNameOrId
|
|
28
|
+
} from "./chunk-AQLVWVEN.js";
|
|
29
|
+
import "./chunk-P4I4DMEU.js";
|
|
30
|
+
import "./chunk-SOTR4CXR.js";
|
|
31
|
+
import {
|
|
32
|
+
table
|
|
33
|
+
} from "./chunk-LWBSOTJP.js";
|
|
34
|
+
import "./chunk-7EHTK7LP.js";
|
|
35
|
+
import {
|
|
36
|
+
require_ms
|
|
37
|
+
} from "./chunk-GGP5R3FU.js";
|
|
38
|
+
import {
|
|
39
|
+
ProjectNotFound,
|
|
40
|
+
getFlagsSpecification,
|
|
41
|
+
isAPIError,
|
|
42
|
+
parseArguments,
|
|
43
|
+
printError
|
|
44
|
+
} from "./chunk-ZLCMHY2G.js";
|
|
45
|
+
import "./chunk-3XFFP2BA.js";
|
|
46
|
+
import {
|
|
47
|
+
output_manager_default
|
|
48
|
+
} from "./chunk-FDJURQMQ.js";
|
|
49
|
+
import {
|
|
50
|
+
require_source
|
|
51
|
+
} from "./chunk-S7KYDPEM.js";
|
|
52
|
+
import {
|
|
53
|
+
__toESM
|
|
54
|
+
} from "./chunk-TZ2YI2VH.js";
|
|
55
|
+
|
|
56
|
+
// src/commands/alerts/list.ts
|
|
57
|
+
var import_ms = __toESM(require_ms(), 1);
|
|
58
|
+
var import_chalk = __toESM(require_source(), 1);
|
|
59
|
+
function handleApiError(err, jsonOutput, client) {
|
|
60
|
+
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}).`;
|
|
61
|
+
return outputError(client, jsonOutput, err.code || "API_ERROR", message);
|
|
62
|
+
}
|
|
63
|
+
function getDefaultRange() {
|
|
64
|
+
const to = /* @__PURE__ */ new Date();
|
|
65
|
+
const from = new Date(to.getTime() - 24 * 60 * 60 * 1e3);
|
|
66
|
+
return { from: from.toISOString(), to: to.toISOString() };
|
|
67
|
+
}
|
|
68
|
+
async function resolveScope(client, opts) {
|
|
69
|
+
if (opts.all || opts.project) {
|
|
70
|
+
const { team } = await getScope(client);
|
|
71
|
+
if (!team) {
|
|
72
|
+
return outputError(
|
|
73
|
+
client,
|
|
74
|
+
opts.jsonOutput,
|
|
75
|
+
"NO_TEAM",
|
|
76
|
+
"No team context found. Run `vercel switch` to select a team, or use `vercel link` in a project directory."
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (opts.all) {
|
|
80
|
+
return {
|
|
81
|
+
teamId: team.id
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
let projectResult;
|
|
85
|
+
try {
|
|
86
|
+
projectResult = await getProjectByNameOrId(
|
|
87
|
+
client,
|
|
88
|
+
opts.project,
|
|
89
|
+
team.id
|
|
90
|
+
);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (isAPIError(err)) {
|
|
93
|
+
return outputError(
|
|
94
|
+
client,
|
|
95
|
+
opts.jsonOutput,
|
|
96
|
+
err.code || "API_ERROR",
|
|
97
|
+
err.serverMessage || (err.status === 403 ? `You do not have permission to access project "${opts.project}" in team "${team.slug}".` : `API error (${err.status}).`)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
if (projectResult instanceof ProjectNotFound) {
|
|
103
|
+
return outputError(
|
|
104
|
+
client,
|
|
105
|
+
opts.jsonOutput,
|
|
106
|
+
"PROJECT_NOT_FOUND",
|
|
107
|
+
`Project "${opts.project}" was not found in team "${team.slug}".`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
teamId: team.id,
|
|
112
|
+
projectId: projectResult.id
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const linkedProject = await getLinkedProject(client);
|
|
116
|
+
if (linkedProject.status === "error") {
|
|
117
|
+
return linkedProject.exitCode;
|
|
118
|
+
}
|
|
119
|
+
if (linkedProject.status === "not_linked") {
|
|
120
|
+
return outputError(
|
|
121
|
+
client,
|
|
122
|
+
opts.jsonOutput,
|
|
123
|
+
"NOT_LINKED",
|
|
124
|
+
"No linked project found. Run `vercel link` to link a project, or use --project <name> or --all."
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
teamId: linkedProject.org.id,
|
|
129
|
+
projectId: linkedProject.project.id
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function getGroupTitle(group) {
|
|
133
|
+
return group.ai?.title || "Alert group";
|
|
134
|
+
}
|
|
135
|
+
function parseDateInput(value) {
|
|
136
|
+
if (value === void 0) {
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
const epochMs = value < 1e12 ? value * 1e3 : value;
|
|
140
|
+
const date = new Date(epochMs);
|
|
141
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
142
|
+
}
|
|
143
|
+
function formatDateForDisplay(value) {
|
|
144
|
+
const date = parseDateInput(value);
|
|
145
|
+
if (!date) {
|
|
146
|
+
return "-";
|
|
147
|
+
}
|
|
148
|
+
return date.toLocaleString("en-US", {
|
|
149
|
+
year: "numeric",
|
|
150
|
+
month: "short",
|
|
151
|
+
day: "2-digit",
|
|
152
|
+
hour: "2-digit",
|
|
153
|
+
minute: "2-digit",
|
|
154
|
+
second: "2-digit",
|
|
155
|
+
hour12: false,
|
|
156
|
+
timeZoneName: "short"
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function getStartedAt(group) {
|
|
160
|
+
return formatDateForDisplay(getGroupStartedAt(group)?.getTime());
|
|
161
|
+
}
|
|
162
|
+
function getGroupStartedAt(group) {
|
|
163
|
+
return parseDateInput(group.recordedStartedAt) || parseDateInput(group.alerts?.[0]?.startedAt);
|
|
164
|
+
}
|
|
165
|
+
function getGroupResolvedAt(group) {
|
|
166
|
+
const resolvedTimes = (group.alerts ?? []).map((alert) => parseDateInput(alert.resolvedAt)).filter((d) => Boolean(d)).map((d) => d.getTime());
|
|
167
|
+
if (resolvedTimes.length > 0) {
|
|
168
|
+
return new Date(Math.max(...resolvedTimes));
|
|
169
|
+
}
|
|
170
|
+
return getGroupStartedAt(group);
|
|
171
|
+
}
|
|
172
|
+
function getStatus(group) {
|
|
173
|
+
const normalizedStatus = (group.status || "").toLowerCase();
|
|
174
|
+
if (normalizedStatus === "active") {
|
|
175
|
+
return "active";
|
|
176
|
+
}
|
|
177
|
+
if (normalizedStatus === "resolved") {
|
|
178
|
+
const startedAt = getGroupStartedAt(group);
|
|
179
|
+
const resolvedAt = getGroupResolvedAt(group);
|
|
180
|
+
if (startedAt && resolvedAt && resolvedAt.getTime() >= startedAt.getTime()) {
|
|
181
|
+
return `resolved after ${(0, import_ms.default)(resolvedAt.getTime() - startedAt.getTime())}`;
|
|
182
|
+
}
|
|
183
|
+
return "resolved";
|
|
184
|
+
}
|
|
185
|
+
return group.status || "-";
|
|
186
|
+
}
|
|
187
|
+
function getResolvedAt(group) {
|
|
188
|
+
const normalizedStatus = (group.status || "").toLowerCase();
|
|
189
|
+
if (normalizedStatus === "active") {
|
|
190
|
+
return "active";
|
|
191
|
+
}
|
|
192
|
+
return formatDateForDisplay(getGroupResolvedAt(group)?.getTime());
|
|
193
|
+
}
|
|
194
|
+
function getAlertsCount(group) {
|
|
195
|
+
return String(group.alerts?.length ?? 0);
|
|
196
|
+
}
|
|
197
|
+
function printGroups(groups) {
|
|
198
|
+
if (groups.length === 0) {
|
|
199
|
+
output_manager_default.log("No alerts found.");
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const headers = ["Title", "Started At", "Type", "Status", "Alerts"].map(
|
|
203
|
+
(h) => import_chalk.default.cyan(h)
|
|
204
|
+
);
|
|
205
|
+
const rows = [
|
|
206
|
+
headers,
|
|
207
|
+
...groups.map((group) => [
|
|
208
|
+
import_chalk.default.bold(getGroupTitle(group)),
|
|
209
|
+
getStartedAt(group),
|
|
210
|
+
group.type || "-",
|
|
211
|
+
getStatus(group),
|
|
212
|
+
getAlertsCount(group)
|
|
213
|
+
])
|
|
214
|
+
];
|
|
215
|
+
const tableOutput = table(rows, { hsep: 3 }).split("\n").map((line) => line.trimEnd()).join("\n").replace(/^/gm, " ");
|
|
216
|
+
output_manager_default.print(`
|
|
217
|
+
${tableOutput}
|
|
218
|
+
`);
|
|
219
|
+
}
|
|
220
|
+
function printAiSections(groups) {
|
|
221
|
+
if (groups.length === 0) {
|
|
222
|
+
output_manager_default.log("No alerts found.");
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const rendered = groups.map((group) => {
|
|
226
|
+
const title = getGroupTitle(group);
|
|
227
|
+
const summary = group.ai?.currentSummary || "N/A";
|
|
228
|
+
const findings = group.ai?.keyFindings?.filter(Boolean) ?? [];
|
|
229
|
+
const findingsOutput = findings.length > 0 ? findings.map((finding) => ` - ${finding}`).join("\n") : " - N/A";
|
|
230
|
+
return [
|
|
231
|
+
import_chalk.default.bold(title),
|
|
232
|
+
` ${import_chalk.default.cyan("Resolved At:")} ${getResolvedAt(group)}`,
|
|
233
|
+
` ${import_chalk.default.cyan("Summary:")} ${summary}`,
|
|
234
|
+
` ${import_chalk.default.cyan("Key Findings:")}`,
|
|
235
|
+
findingsOutput
|
|
236
|
+
].join("\n");
|
|
237
|
+
}).join("\n\n");
|
|
238
|
+
output_manager_default.print(`
|
|
239
|
+
${rendered}
|
|
240
|
+
`);
|
|
241
|
+
}
|
|
242
|
+
function trackTelemetry(flags, types, telemetry) {
|
|
243
|
+
telemetry.trackCliOptionType(types.length > 0 ? types : void 0);
|
|
244
|
+
telemetry.trackCliOptionSince(flags["--since"]);
|
|
245
|
+
telemetry.trackCliOptionUntil(flags["--until"]);
|
|
246
|
+
telemetry.trackCliOptionProject(flags["--project"]);
|
|
247
|
+
telemetry.trackCliFlagAll(flags["--all"]);
|
|
248
|
+
telemetry.trackCliFlagAi(flags["--ai"]);
|
|
249
|
+
telemetry.trackCliOptionLimit(flags["--limit"]);
|
|
250
|
+
telemetry.trackCliOptionFormat(flags["--format"]);
|
|
251
|
+
}
|
|
252
|
+
function parseFlags(client) {
|
|
253
|
+
const flagsSpecification = getFlagsSpecification(alertsCommand.options);
|
|
254
|
+
try {
|
|
255
|
+
const parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification);
|
|
256
|
+
return parsedArgs.flags;
|
|
257
|
+
} catch (err) {
|
|
258
|
+
printError(err);
|
|
259
|
+
return 1;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function resolveValidatedInputs(flags, client, jsonOutput) {
|
|
263
|
+
const types = normalizeRepeatableStringFilters(flags["--type"]);
|
|
264
|
+
const limitResult = validateOptionalIntegerRange(flags["--limit"], {
|
|
265
|
+
flag: "--limit",
|
|
266
|
+
min: 1,
|
|
267
|
+
max: 100
|
|
268
|
+
});
|
|
269
|
+
if (!limitResult.valid) {
|
|
270
|
+
return handleValidationError(limitResult, jsonOutput, client);
|
|
271
|
+
}
|
|
272
|
+
const mutualResult = validateAllProjectMutualExclusivity(
|
|
273
|
+
flags["--all"],
|
|
274
|
+
flags["--project"]
|
|
275
|
+
);
|
|
276
|
+
if (!mutualResult.valid) {
|
|
277
|
+
return handleValidationError(mutualResult, jsonOutput, client);
|
|
278
|
+
}
|
|
279
|
+
const sinceResult = validateTimeBound(flags["--since"]);
|
|
280
|
+
if (!sinceResult.valid) {
|
|
281
|
+
return handleValidationError(sinceResult, jsonOutput, client);
|
|
282
|
+
}
|
|
283
|
+
const untilResult = validateTimeBound(flags["--until"]);
|
|
284
|
+
if (!untilResult.valid) {
|
|
285
|
+
return handleValidationError(untilResult, jsonOutput, client);
|
|
286
|
+
}
|
|
287
|
+
const timeOrderResult = validateTimeOrder(
|
|
288
|
+
sinceResult.value,
|
|
289
|
+
untilResult.value
|
|
290
|
+
);
|
|
291
|
+
if (!timeOrderResult.valid) {
|
|
292
|
+
return handleValidationError(timeOrderResult, jsonOutput, client);
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
limit: limitResult.value,
|
|
296
|
+
types,
|
|
297
|
+
since: sinceResult.value,
|
|
298
|
+
until: untilResult.value
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function buildAlertsQuery(scope, inputs) {
|
|
302
|
+
const query = new URLSearchParams({
|
|
303
|
+
teamId: scope.teamId
|
|
304
|
+
});
|
|
305
|
+
if (scope.projectId) {
|
|
306
|
+
query.set("projectId", scope.projectId);
|
|
307
|
+
}
|
|
308
|
+
if (inputs.limit) {
|
|
309
|
+
query.set("limit", String(inputs.limit));
|
|
310
|
+
}
|
|
311
|
+
for (const type of inputs.types) {
|
|
312
|
+
query.append("types", type);
|
|
313
|
+
}
|
|
314
|
+
if (inputs.since) {
|
|
315
|
+
query.set("from", inputs.since.toISOString());
|
|
316
|
+
}
|
|
317
|
+
if (inputs.until) {
|
|
318
|
+
query.set("to", inputs.until.toISOString());
|
|
319
|
+
}
|
|
320
|
+
if (!inputs.since && !inputs.until) {
|
|
321
|
+
const defaultRange = getDefaultRange();
|
|
322
|
+
query.set("from", defaultRange.from);
|
|
323
|
+
query.set("to", defaultRange.to);
|
|
324
|
+
}
|
|
325
|
+
return query;
|
|
326
|
+
}
|
|
327
|
+
async function list(client, telemetry) {
|
|
328
|
+
const flags = parseFlags(client);
|
|
329
|
+
if (typeof flags === "number") {
|
|
330
|
+
return flags;
|
|
331
|
+
}
|
|
332
|
+
const formatResult = validateJsonOutput(flags);
|
|
333
|
+
if (!formatResult.valid) {
|
|
334
|
+
output_manager_default.error(formatResult.error);
|
|
335
|
+
return 1;
|
|
336
|
+
}
|
|
337
|
+
const jsonOutput = formatResult.jsonOutput;
|
|
338
|
+
const types = normalizeRepeatableStringFilters(flags["--type"]);
|
|
339
|
+
trackTelemetry(flags, types, telemetry);
|
|
340
|
+
const validatedInputs = resolveValidatedInputs(flags, client, jsonOutput);
|
|
341
|
+
if (typeof validatedInputs === "number") {
|
|
342
|
+
return validatedInputs;
|
|
343
|
+
}
|
|
344
|
+
const scope = await resolveScope(client, {
|
|
345
|
+
project: flags["--project"],
|
|
346
|
+
all: flags["--all"],
|
|
347
|
+
jsonOutput
|
|
348
|
+
});
|
|
349
|
+
if (typeof scope === "number") {
|
|
350
|
+
return scope;
|
|
351
|
+
}
|
|
352
|
+
const query = buildAlertsQuery(scope, validatedInputs);
|
|
353
|
+
const requestPath = `/alerts/v3/groups?${query.toString()}`;
|
|
354
|
+
output_manager_default.debug(`Fetching alerts from ${requestPath}`);
|
|
355
|
+
output_manager_default.spinner("Fetching alerts...");
|
|
356
|
+
try {
|
|
357
|
+
const groups = await client.fetch(requestPath);
|
|
358
|
+
if (jsonOutput) {
|
|
359
|
+
client.stdout.write(`${JSON.stringify({ groups }, null, 2)}
|
|
360
|
+
`);
|
|
361
|
+
} else {
|
|
362
|
+
if (flags["--ai"]) {
|
|
363
|
+
printAiSections(groups);
|
|
364
|
+
} else {
|
|
365
|
+
printGroups(groups);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return 0;
|
|
369
|
+
} catch (err) {
|
|
370
|
+
if (isAPIError(err)) {
|
|
371
|
+
return handleApiError(err, jsonOutput, client);
|
|
372
|
+
}
|
|
373
|
+
output_manager_default.debug(err);
|
|
374
|
+
const message = `Failed to fetch alerts: ${err.message || String(err)}`;
|
|
375
|
+
return outputError(client, jsonOutput, "UNEXPECTED_ERROR", message);
|
|
376
|
+
} finally {
|
|
377
|
+
output_manager_default.stopSpinner();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
export {
|
|
381
|
+
list as default
|
|
382
|
+
};
|