vibeview 0.27.1 → 0.28.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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/commands/upload-app.ts
4
4
  import chalk from "chalk";
5
- import { existsSync } from "fs";
5
+ import { existsSync as existsSync2 } from "fs";
6
6
 
7
7
  // src/lib/config.ts
8
8
  import { readFileSync, writeFileSync, mkdirSync } from "fs";
@@ -83,9 +83,9 @@ function reportCommandError(json, err) {
83
83
  process.stderr.write(`error: ${message}
84
84
  `);
85
85
  }
86
- function printJsonError(err) {
86
+ function printJsonError(err, extra) {
87
87
  const message = err instanceof Error ? err.message : String(err);
88
- console.log(JSON.stringify({ event: "error", message }));
88
+ console.log(JSON.stringify({ event: "error", message, ...extra }));
89
89
  }
90
90
  var NotFoundError = class extends Error {
91
91
  constructor(message) {
@@ -93,6 +93,19 @@ var NotFoundError = class extends Error {
93
93
  this.name = "NotFoundError";
94
94
  }
95
95
  };
96
+ var ApiStatusError = class extends Error {
97
+ constructor(status, message) {
98
+ super(message);
99
+ this.status = status;
100
+ this.name = "ApiStatusError";
101
+ }
102
+ };
103
+ var NetworkError = class extends Error {
104
+ constructor(message) {
105
+ super(message);
106
+ this.name = "NetworkError";
107
+ }
108
+ };
96
109
  function extractDetail(text) {
97
110
  try {
98
111
  const parsed = JSON.parse(text);
@@ -103,6 +116,18 @@ function extractDetail(text) {
103
116
  }
104
117
  return void 0;
105
118
  }
119
+ function httpErrorMessage(status, text) {
120
+ const body = text.trim();
121
+ const looksLikeHtml = /^<(!doctype|html|head|body)\b/i.test(body) || /<\/html>\s*$/i.test(body);
122
+ const meaning = {
123
+ 502: "the server could not be reached (bad gateway) \u2014 try again in a moment",
124
+ 503: "the server is unavailable right now \u2014 try again in a moment",
125
+ 504: "the server took too long to answer (gateway timeout) \u2014 the action may still have run; check before retrying"
126
+ };
127
+ if (meaning[status]) return `API error ${status}: ${meaning[status]}`;
128
+ if (!body || looksLikeHtml) return `API error ${status}`;
129
+ return `API error ${status}: ${body.length > 300 ? `${body.slice(0, 300)}\u2026` : body}`;
130
+ }
106
131
  async function parseJsonBody(resp) {
107
132
  if (resp.status === 204 || resp.status === 205) return void 0;
108
133
  return withUtcTimestamps(await resp.json());
@@ -125,7 +150,7 @@ var ApiClient = class {
125
150
  } catch (e) {
126
151
  const cause = e.cause;
127
152
  const detail = cause?.code ? ` (${cause.code})` : "";
128
- throw new Error(
153
+ throw new NetworkError(
129
154
  `Cannot reach ${this.baseUrl}${detail}. Check the server URL (--base-url flag, VIBEVIEW_BASE_URL, or ~/.vibeview/config.json) and your network.`
130
155
  );
131
156
  }
@@ -145,7 +170,10 @@ var ApiClient = class {
145
170
  const text = await resp.text().catch(() => "");
146
171
  if (resp.status === 401) throw new AuthError();
147
172
  if (resp.status === 404) throw new NotFoundError(`Not found: ${extractDetail(text) ?? path}`);
148
- throw new Error(extractDetail(text) ?? `API error ${resp.status}: ${text}`);
173
+ throw new ApiStatusError(
174
+ resp.status,
175
+ extractDetail(text) ?? httpErrorMessage(resp.status, text)
176
+ );
149
177
  }
150
178
  return parseJsonBody(resp);
151
179
  }
@@ -217,7 +245,10 @@ var ApiClient = class {
217
245
  const text = await resp.text().catch(() => "");
218
246
  if (resp.status === 401) throw new AuthError();
219
247
  if (resp.status === 404) throw new NotFoundError(`Not found: ${extractDetail(text) ?? path}`);
220
- throw new Error(extractDetail(text) ?? `API error ${resp.status}: ${text}`);
248
+ throw new ApiStatusError(
249
+ resp.status,
250
+ extractDetail(text) ?? httpErrorMessage(resp.status, text)
251
+ );
221
252
  }
222
253
  return parseJsonBody(resp);
223
254
  }
@@ -237,7 +268,10 @@ var ApiClient = class {
237
268
  const text = await resp.text().catch(() => "");
238
269
  if (resp.status === 401) throw new AuthError();
239
270
  if (resp.status === 404) throw new NotFoundError(`Not found: ${extractDetail(text) ?? path}`);
240
- throw new Error(extractDetail(text) ?? `API error ${resp.status}: ${text}`);
271
+ throw new ApiStatusError(
272
+ resp.status,
273
+ extractDetail(text) ?? httpErrorMessage(resp.status, text)
274
+ );
241
275
  }
242
276
  return parseJsonBody(resp);
243
277
  }
@@ -397,7 +431,10 @@ var ApiClient = class {
397
431
  if (resp.status === 401) throw new AuthError();
398
432
  if (resp.status === 404)
399
433
  throw new NotFoundError(`Not found: ${extractDetail(text) ?? `/builds/${id}/artifact`}`);
400
- throw new Error(extractDetail(text) ?? `API error ${resp.status}: ${text}`);
434
+ throw new ApiStatusError(
435
+ resp.status,
436
+ extractDetail(text) ?? httpErrorMessage(resp.status, text)
437
+ );
401
438
  }
402
439
  const rawFilename = parseContentDispositionFilename(resp.headers.get("content-disposition"));
403
440
  const filename = sanitizeDownloadFilename(rawFilename) ?? `${id}.bin`;
@@ -670,6 +707,63 @@ function sanitizeDownloadFilename(raw) {
670
707
  return base;
671
708
  }
672
709
 
710
+ // src/lib/artifact.ts
711
+ import { existsSync, mkdtempSync, readdirSync, rmSync as rmSync2, statSync } from "fs";
712
+ import { spawnSync } from "child_process";
713
+ import { tmpdir } from "os";
714
+ import { basename as basename2, dirname, isAbsolute, join as join3 } from "path";
715
+ function resolveArtifact(cwd, pattern) {
716
+ const abs = isAbsolute(pattern) ? pattern : join3(cwd, pattern);
717
+ if (!basename2(abs).includes("*")) {
718
+ if (!existsSync(abs)) {
719
+ throw new Error(
720
+ `artifact not found: ${pattern} (looked at ${abs}) \u2014 did the build produce it?`
721
+ );
722
+ }
723
+ return abs;
724
+ }
725
+ const dir = dirname(abs);
726
+ const re = new RegExp("^" + basename2(abs).split("*").map(escapeRegExp).join(".*") + "$");
727
+ let entries;
728
+ try {
729
+ entries = readdirSync(dir);
730
+ } catch {
731
+ throw new Error(`artifact not found: ${pattern} (directory ${dir} does not exist)`);
732
+ }
733
+ const matches = entries.filter((e) => re.test(e)).map((e) => join3(dir, e)).sort((a, b) => statSync(b).mtimeMs - statSync(a).mtimeMs);
734
+ if (matches.length === 0) {
735
+ throw new Error(`artifact not found: no match for ${pattern} in ${dir}`);
736
+ }
737
+ return matches[0];
738
+ }
739
+ function escapeRegExp(s) {
740
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
741
+ }
742
+ function prepareUploadArtifact(path) {
743
+ if (!(statSync(path).isDirectory() && path.endsWith(".app"))) {
744
+ return { uploadPath: path, cleanup: () => {
745
+ } };
746
+ }
747
+ const tmp = mkdtempSync(join3(tmpdir(), "vibeview-zip-"));
748
+ const out = join3(tmp, `${basename2(path)}.zip`);
749
+ const res = spawnSync("zip", ["-qry", out, basename2(path)], { cwd: dirname(path) });
750
+ if (res.error) {
751
+ rmSync2(tmp, { recursive: true, force: true });
752
+ const errorCode = res.error.code;
753
+ const errorMsg = res.error.message;
754
+ throw new Error(
755
+ `failed to zip ${path}: spawn zip ${errorCode} \u2014 ${errorMsg} \u2014 is the \`zip\` command installed?`
756
+ );
757
+ }
758
+ if (res.status !== 0) {
759
+ rmSync2(tmp, { recursive: true, force: true });
760
+ throw new Error(
761
+ `failed to zip ${path}: ${res.stderr?.toString().trim() || `zip exited ${res.status}`}`
762
+ );
763
+ }
764
+ return { uploadPath: out, cleanup: () => rmSync2(tmp, { recursive: true, force: true }) };
765
+ }
766
+
673
767
  // src/lib/spinner.ts
674
768
  import ora from "ora";
675
769
  function createSpinner(text, opts = {}) {
@@ -706,13 +800,19 @@ function queueReasonCopy(reason) {
706
800
 
707
801
  // src/commands/upload-app.ts
708
802
  async function uploadAppBuild(filePath, options) {
709
- if (!existsSync(filePath)) {
803
+ if (!existsSync2(filePath)) {
710
804
  throw new Error(`File not found: ${filePath}`);
711
805
  }
712
806
  const { token, baseUrl } = resolveAuth(options);
713
807
  const client = new ApiClient(baseUrl, token);
714
808
  const note = options.note?.trim() || void 0;
715
- const result = await client.uploadApp(filePath, options.name, note);
809
+ const { uploadPath, cleanup } = prepareUploadArtifact(filePath);
810
+ let result;
811
+ try {
812
+ result = await client.uploadApp(uploadPath, options.name, note);
813
+ } finally {
814
+ cleanup();
815
+ }
716
816
  if (note && result.deduplicated && result.build_id != null) {
717
817
  await client.updateBuildNote(result.public_id, result.build_id, note);
718
818
  }
@@ -725,7 +825,7 @@ function describeBuild(result) {
725
825
  return `Build ${chalk.cyan(String(result.build_id))}${version ? ` ${version}` : ""}${dedup}`;
726
826
  }
727
827
  async function uploadApp(filePath, options) {
728
- if (!existsSync(filePath)) {
828
+ if (!existsSync2(filePath)) {
729
829
  console.error(chalk.red(`Error: File not found: ${filePath}`));
730
830
  process.exit(EXIT_INFRA_ERROR);
731
831
  }
@@ -792,6 +892,8 @@ export {
792
892
  reportCommandError,
793
893
  printJsonError,
794
894
  NotFoundError,
895
+ ApiStatusError,
896
+ NetworkError,
795
897
  ApiClient,
796
898
  createSpinner,
797
899
  EXIT_PASS,
@@ -800,6 +902,8 @@ export {
800
902
  UsageError,
801
903
  DEVICE_STATUS_FILTERS,
802
904
  queueReasonCopy,
905
+ resolveArtifact,
906
+ prepareUploadArtifact,
803
907
  uploadAppBuild,
804
908
  describeBuild,
805
909
  uploadApp