@balise.dev/cli 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/dist/index.js +24 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2050,6 +2050,25 @@ function resolveWebUrl(webUrl, frontUrl) {
2050
2050
  function formatAcceptedSummary(body, frontUrl) {
2051
2051
  return `Sync queued. Track it here: ${resolveWebUrl(body.web_url, frontUrl)}`;
2052
2052
  }
2053
+ function formatInsufficientCredits(rawBody) {
2054
+ let estimate;
2055
+ let available;
2056
+ try {
2057
+ const detail = JSON.parse(rawBody).detail;
2058
+ if (detail?.error === "insufficient_credits") {
2059
+ if (typeof detail.estimate === "number") estimate = detail.estimate;
2060
+ if (typeof detail.available === "number") available = detail.available;
2061
+ }
2062
+ } catch {
2063
+ }
2064
+ const topUp = "Top up your balance, then run `balise sync` again.\n";
2065
+ if (estimate !== void 0 && available !== void 0) {
2066
+ return `Not enough credits \u2014 this sync needs ~${fmtEstimate(estimate)} cr but only ${fmtCredits(available)} cr available.
2067
+ ${topUp}`;
2068
+ }
2069
+ return `Not enough credits to run this sync.
2070
+ ${topUp}`;
2071
+ }
2053
2072
  async function runSync(opts) {
2054
2073
  try {
2055
2074
  await runSyncInner(opts);
@@ -2264,6 +2283,10 @@ function handleUploadError(err) {
2264
2283
  );
2265
2284
  return;
2266
2285
  }
2286
+ if (err instanceof ApiError && err.status === 402) {
2287
+ process.stderr.write(formatInsufficientCredits(err.body));
2288
+ return;
2289
+ }
2267
2290
  process.stderr.write(
2268
2291
  "Something went wrong while uploading. Please try again.\n"
2269
2292
  );
@@ -2346,7 +2369,7 @@ var syncCmd = defineCommand({
2346
2369
  var main = defineCommand({
2347
2370
  meta: {
2348
2371
  name: "balise",
2349
- version: "0.1.0",
2372
+ version: "0.3.1",
2350
2373
  description: "Balise CLI \u2014 push codebase for spec extraction."
2351
2374
  },
2352
2375
  subCommands: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balise.dev/cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Balise CLI — push codebase to Balise backend for spec extraction.",
5
5
  "type": "module",
6
6
  "bin": {