layero 0.11.11 → 0.11.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +14 -4
- package/dist/bin/layero.js +10 -2
- package/dist/commands/perf.js +5 -5
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -4,6 +4,16 @@ import { looksLikeId } from "./project-ref.js";
|
|
|
4
4
|
// Один опрос логов отвечает за доли секунды. 30 с — заведомо «запрос завис»,
|
|
5
5
|
// а не «сборка идёт долго»: длительность сборки на ответ этой ручки не влияет.
|
|
6
6
|
export const POLL_TIMEOUT_MS = 30_000;
|
|
7
|
+
/** Устройство и страница замера — одинаковые у запуска и у результата. */
|
|
8
|
+
function perfQuery(opts) {
|
|
9
|
+
const q = new URLSearchParams();
|
|
10
|
+
if (opts.device)
|
|
11
|
+
q.set("device", opts.device);
|
|
12
|
+
if (opts.path)
|
|
13
|
+
q.set("path", opts.path);
|
|
14
|
+
const s = q.toString();
|
|
15
|
+
return s ? `?${s}` : "";
|
|
16
|
+
}
|
|
7
17
|
export class ApiError extends Error {
|
|
8
18
|
status;
|
|
9
19
|
body;
|
|
@@ -292,12 +302,12 @@ export class ApiClient {
|
|
|
292
302
|
}
|
|
293
303
|
// --- Замеры (AGENT-11) ----------------------------------------------
|
|
294
304
|
/** Запустить замер активного деплоя. Не ждёт: прогон асинхронный. */
|
|
295
|
-
startPerfCheck(projectId) {
|
|
296
|
-
return this.request("POST", `/projects/${projectId}/perf-check`);
|
|
305
|
+
startPerfCheck(projectId, opts = {}) {
|
|
306
|
+
return this.request("POST", `/projects/${projectId}/perf-check${perfQuery(opts)}`);
|
|
297
307
|
}
|
|
298
308
|
/** Результат последнего замера со сравнением с предыдущим деплоем. */
|
|
299
|
-
getPerfCheck(projectId) {
|
|
300
|
-
return this.request("GET", `/projects/${projectId}/perf-check`);
|
|
309
|
+
getPerfCheck(projectId, opts = {}) {
|
|
310
|
+
return this.request("GET", `/projects/${projectId}/perf-check${perfQuery(opts)}`);
|
|
301
311
|
}
|
|
302
312
|
// --- Домены (AGENT-09) ---------------------------------------------
|
|
303
313
|
listDomains(projectId) {
|
package/dist/bin/layero.js
CHANGED
|
@@ -352,14 +352,18 @@ async function main() {
|
|
|
352
352
|
.description("Measure site performance and compare it with the previous deploy.");
|
|
353
353
|
perf
|
|
354
354
|
.command("check")
|
|
355
|
-
.description("
|
|
355
|
+
.description("Measure the main branch (Lighthouse score, verdict as in the dashboard). The run is asynchronous — with --wait the command waits for the result.")
|
|
356
356
|
.option("--project <id_or_slug>", "project (default: the linked project)")
|
|
357
357
|
.option("--wait", "wait for the result (up to 4 minutes)")
|
|
358
|
+
.option("--device <desktop|mobile>", "device profile (default: desktop)")
|
|
359
|
+
.option("--path <path>", "page on the main branch, e.g. /pricing (default: /)")
|
|
358
360
|
.action(async (opts) => perfCheckCmd({ ...opts, json: program.opts().json }));
|
|
359
361
|
perf
|
|
360
362
|
.command("show")
|
|
361
363
|
.description("Show the latest measurement and the comparison with the previous deploy.")
|
|
362
364
|
.option("--project <id_or_slug>", "project (default: the linked project)")
|
|
365
|
+
.option("--device <desktop|mobile>", "device profile (default: desktop)")
|
|
366
|
+
.option("--path <path>", "page on the main branch, e.g. /pricing (default: /)")
|
|
363
367
|
.action(async (opts) => perfShowCmd({ ...opts, json: program.opts().json }));
|
|
364
368
|
const domains = program
|
|
365
369
|
.command("domains")
|
|
@@ -527,7 +531,11 @@ function asAccountStateError(err) {
|
|
|
527
531
|
: "";
|
|
528
532
|
return new LayeroError("plan_limit", what
|
|
529
533
|
? `Тариф не позволяет больше ${what}${counts}.`
|
|
530
|
-
|
|
534
|
+
// Сервер прислал готовую причину («Замер скорости доступен на тарифе
|
|
535
|
+
// Pro.») — она точнее общего текста.
|
|
536
|
+
: typeof detail.message === "string" && detail.message
|
|
537
|
+
? detail.message
|
|
538
|
+
: "Действие недоступно на текущем тарифе.", "смените тариф на app.layero.ru/billing или освободите место, удалив ненужное");
|
|
531
539
|
}
|
|
532
540
|
// 🚨 Понятный отказ сервера не имеет права превращаться в нашу поломку.
|
|
533
541
|
// 409 с `reason: reserved` и текстом «имя зарезервировано платформой»
|
package/dist/commands/perf.js
CHANGED
|
@@ -18,7 +18,7 @@ function render(d) {
|
|
|
18
18
|
if (d.score !== null && d.score !== undefined) {
|
|
19
19
|
const t = d.timings ?? {};
|
|
20
20
|
const bits = [
|
|
21
|
-
`балл ${d.score}`,
|
|
21
|
+
`балл Lighthouse ${d.score}`,
|
|
22
22
|
t.lcp_ms ? `LCP ${t.lcp_ms} мс` : null,
|
|
23
23
|
t.ttfb_ms ? `TTFB ${t.ttfb_ms} мс` : null,
|
|
24
24
|
].filter(Boolean);
|
|
@@ -32,12 +32,12 @@ export async function perfCheckCmd(opts) {
|
|
|
32
32
|
const id = await projectId(api, opts);
|
|
33
33
|
let started;
|
|
34
34
|
try {
|
|
35
|
-
started = await api.startPerfCheck(id);
|
|
35
|
+
started = await api.startPerfCheck(id, opts);
|
|
36
36
|
}
|
|
37
37
|
catch (err) {
|
|
38
38
|
if (err instanceof ApiError && err.status === 429) {
|
|
39
39
|
// Замер уже идёт — это не ошибка, а ответ на вопрос «когда будет».
|
|
40
|
-
const current = await api.getPerfCheck(id).catch(() => null);
|
|
40
|
+
const current = await api.getPerfCheck(id, opts).catch(() => null);
|
|
41
41
|
if (current) {
|
|
42
42
|
if (mode.json) {
|
|
43
43
|
emit({ event: "perf_check", ...current });
|
|
@@ -67,7 +67,7 @@ export async function perfCheckCmd(opts) {
|
|
|
67
67
|
let last = started;
|
|
68
68
|
while (Date.now() < deadline) {
|
|
69
69
|
await new Promise((r) => setTimeout(r, 8000));
|
|
70
|
-
last = await api.getPerfCheck(id);
|
|
70
|
+
last = await api.getPerfCheck(id, opts);
|
|
71
71
|
if (last.verdict !== "pending")
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
@@ -83,7 +83,7 @@ export async function perfShowCmd(opts) {
|
|
|
83
83
|
const id = await projectId(api, opts);
|
|
84
84
|
let out;
|
|
85
85
|
try {
|
|
86
|
-
out = await api.getPerfCheck(id);
|
|
86
|
+
out = await api.getPerfCheck(id, opts);
|
|
87
87
|
}
|
|
88
88
|
catch (err) {
|
|
89
89
|
if (err instanceof ApiError && err.status === 404) {
|
package/package.json
CHANGED