@calo-design/cli 0.13.0 → 0.13.2
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/bin/backend.js +47 -10
- package/package.json +1 -1
package/bin/backend.js
CHANGED
|
@@ -234,7 +234,16 @@ async function cmdDeploy(args) {
|
|
|
234
234
|
async function cmdStatus(args) {
|
|
235
235
|
const root = process.cwd();
|
|
236
236
|
const slug = resolveSlug(args, root);
|
|
237
|
-
|
|
237
|
+
let text;
|
|
238
|
+
try {
|
|
239
|
+
text = await call("GET", `/v1/backend/status?slug=${encodeURIComponent(slug)}`, { raw: true });
|
|
240
|
+
} catch (e) {
|
|
241
|
+
// "no backend for this prototype" is a normal first-run answer. Under --json the
|
|
242
|
+
// contract is "the last stdout line is JSON" — honor it even here, so an agent that
|
|
243
|
+
// parses the last line gets `{ok:false,...}` instead of crashing on a human error line.
|
|
244
|
+
if (has(args, "json")) return emitJson({ ok: false, slug, provisioned: false, error: e.message, status: e.status || null });
|
|
245
|
+
throw e;
|
|
246
|
+
}
|
|
238
247
|
if (has(args, "json")) return emitJson(text);
|
|
239
248
|
const s = JSON.parse(text);
|
|
240
249
|
log(`${c.b(s.slug)} ${c.dim(`(${s.base})`)}`);
|
|
@@ -285,7 +294,16 @@ async function cmdSql(args) {
|
|
|
285
294
|
if (!query) throw new Error('usage: calo-design backend sql "SELECT * FROM items"');
|
|
286
295
|
const root = process.cwd();
|
|
287
296
|
const slug = resolveSlug(args.filter((a) => a !== query), root);
|
|
288
|
-
|
|
297
|
+
let text;
|
|
298
|
+
try {
|
|
299
|
+
text = await call("POST", "/v1/backend/sql", { body: { slug, query }, raw: true });
|
|
300
|
+
} catch (e) {
|
|
301
|
+
if (has(args, "json")) {
|
|
302
|
+
emitJson({ ok: false, error: e.message, status: e.status || null });
|
|
303
|
+
process.exit(1);
|
|
304
|
+
}
|
|
305
|
+
throw e;
|
|
306
|
+
}
|
|
289
307
|
if (has(args, "json")) return emitJson(text);
|
|
290
308
|
const body = JSON.parse(text);
|
|
291
309
|
log(JSON.stringify(body.results, null, 2));
|
|
@@ -299,14 +317,33 @@ async function cmdCheck(args) {
|
|
|
299
317
|
const bj = readBackendJson(root);
|
|
300
318
|
if (!bj || !bj.workerUrl) throw new Error("no backend.json here — run `calo-design backend init` first");
|
|
301
319
|
let res, body;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
320
|
+
// Right after a deploy, two kinds of lag are normal and NOT failures: network-level
|
|
321
|
+
// (route/DNS propagation) and 401/5xx while the fresh APP_KEY secret version reaches
|
|
322
|
+
// running isolates. Retry through both with the reason on screen; a state that
|
|
323
|
+
// persists past the retries is a real failure.
|
|
324
|
+
const TRIES = 6;
|
|
325
|
+
for (let i = 1; ; i++) {
|
|
326
|
+
try {
|
|
327
|
+
res = await fetch(`${bj.workerUrl}/__health`, {
|
|
328
|
+
headers: { authorization: `Bearer ${bj.appKey}` },
|
|
329
|
+
signal: AbortSignal.timeout(15000),
|
|
330
|
+
});
|
|
331
|
+
body = await res.json().catch(() => ({}));
|
|
332
|
+
if (res.ok || i >= TRIES) break;
|
|
333
|
+
log(c.dim(` not healthy yet (HTTP ${res.status}) — retrying ${i}/${TRIES - 1} in 5s (fresh deploys propagate for a few seconds)`));
|
|
334
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
335
|
+
} catch (e) {
|
|
336
|
+
if (i >= TRIES) {
|
|
337
|
+
const msg = `worker unreachable at ${bj.workerUrl} (${e.message}) — deployed yet? try \`calo-design backend deploy\`, then re-run \`calo-design backend check\``;
|
|
338
|
+
if (has(args, "json")) {
|
|
339
|
+
emitJson({ ok: false, reachable: false, error: msg });
|
|
340
|
+
process.exit(1);
|
|
341
|
+
}
|
|
342
|
+
throw new Error(msg);
|
|
343
|
+
}
|
|
344
|
+
log(c.dim(` worker not reachable yet (${e.message}) — retrying ${i}/${TRIES - 1} in 5s`));
|
|
345
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
346
|
+
}
|
|
310
347
|
}
|
|
311
348
|
if (has(args, "json")) return emitJson(JSON.stringify({ status: res.status, ...body }));
|
|
312
349
|
const checks = body.checks || {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calo-design/cli",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "One-line setup for Calo design tooling: logs in with your Calo email and installs the calo-design skill + design-system packages. No GitHub account needed.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"calo-design": "bin/cli.js"
|