recappi 0.1.62 → 0.1.64

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/index.js CHANGED
@@ -19296,6 +19296,13 @@ var RecappiApiClient = class {
19296
19296
  for (const filePath of files) {
19297
19297
  attemptedCount += 1;
19298
19298
  try {
19299
+ opts.onEvent?.({
19300
+ type: "progress",
19301
+ command: "upload",
19302
+ filePath,
19303
+ status: "checking_audio",
19304
+ message: `Checking ${filePath}`
19305
+ });
19299
19306
  const plan = await planAudioFile(filePath, files.length === 1 ? opts.title : void 0);
19300
19307
  const result = await this.uploadFile(plan, opts);
19301
19308
  successes.push(result);
@@ -19338,10 +19345,19 @@ var RecappiApiClient = class {
19338
19345
  async uploadFile(plan, opts) {
19339
19346
  const relative = plan.filePath;
19340
19347
  opts.onEvent?.({
19341
- type: "started",
19348
+ type: "progress",
19342
19349
  command: "upload",
19343
19350
  filePath: relative,
19344
- message: `Preparing ${relative}`
19351
+ status: "starting_upload",
19352
+ message: `Starting upload ${relative}`,
19353
+ data: {
19354
+ file: {
19355
+ title: plan.title,
19356
+ contentType: plan.contentType,
19357
+ sizeBytes: plan.sizeBytes,
19358
+ ...plan.durationMs ? { durationMs: plan.durationMs } : {}
19359
+ }
19360
+ }
19345
19361
  });
19346
19362
  const init = await this.postJson("/api/recordings", {
19347
19363
  title: plan.title,
@@ -19508,14 +19524,27 @@ var RecappiApiClient = class {
19508
19524
  }
19509
19525
  async request(method, pathname, body, opts = {}) {
19510
19526
  const token = requireToken(this.auth);
19511
- const response = await this.fetchImpl(new URL(pathname, this.auth.origin), {
19512
- method,
19513
- headers: {
19514
- authorization: `Bearer ${token}`,
19515
- ...opts.headers
19516
- },
19517
- ...body ? { body } : {}
19518
- });
19527
+ let response;
19528
+ try {
19529
+ response = await this.fetchImpl(new URL(pathname, this.auth.origin), {
19530
+ method,
19531
+ headers: {
19532
+ authorization: `Bearer ${token}`,
19533
+ ...opts.headers
19534
+ },
19535
+ ...body ? { body } : {}
19536
+ });
19537
+ } catch (error51) {
19538
+ if (error51 instanceof RecappiCliError) throw error51;
19539
+ throw cliError(
19540
+ "cloud.http_error",
19541
+ `Recappi Cloud request failed: ${transportErrorMessage(error51)}`,
19542
+ {
19543
+ retryable: true,
19544
+ hint: `Check your network connection and Recappi Cloud origin (${this.auth.origin}), then retry.`
19545
+ }
19546
+ );
19547
+ }
19519
19548
  if (!response.ok && !(opts.allowAuthFailure && (response.status === 401 || response.status === 403))) {
19520
19549
  const message = await responseMessage(response);
19521
19550
  throw new RecappiCliError(describeHttpError(response.status, message));
@@ -19523,6 +19552,10 @@ var RecappiApiClient = class {
19523
19552
  return response;
19524
19553
  }
19525
19554
  };
19555
+ function transportErrorMessage(error51) {
19556
+ if (error51 instanceof Error && error51.message) return error51.message;
19557
+ return String(error51 || "network request failed");
19558
+ }
19526
19559
  async function parseJson(response) {
19527
19560
  try {
19528
19561
  return await response.json();
@@ -20605,8 +20638,7 @@ function formatHumanProgress(event, opts) {
20605
20638
  const scope = progressScope(event);
20606
20639
  let line;
20607
20640
  if (event.type === "started") {
20608
- const label = humanFileLabel(event.filePath);
20609
- line = label ? `Preparing ${label}` : "Preparing upload";
20641
+ line = event.message;
20610
20642
  } else if (event.command === "upload") {
20611
20643
  line = formatUploadProgress(event, opts, scope);
20612
20644
  } else if (event.command === "jobs wait") {
@@ -20622,13 +20654,20 @@ function formatHumanProgress(event, opts) {
20622
20654
  return line;
20623
20655
  }
20624
20656
  function formatUploadProgress(event, opts, scope) {
20657
+ const label = event.filePath ? humanFileLabel(event.filePath) : void 0;
20658
+ if (event.status === "checking_audio") {
20659
+ return label ? `Checking ${label}` : "Checking audio file";
20660
+ }
20661
+ if (event.status === "starting_upload") {
20662
+ return label ? `Starting upload ${label}` : "Starting upload";
20663
+ }
20625
20664
  if (event.status === "uploading" && typeof event.percent === "number") {
20626
20665
  const state = opts.progress;
20627
20666
  const bucket = Math.min(100, Math.max(0, Math.floor(event.percent / 10) * 10));
20628
20667
  const previous = state?.lastUploadBucketByScope.get(scope);
20629
20668
  if (previous !== void 0 && bucket <= previous && bucket !== 100) return void 0;
20630
20669
  state?.lastUploadBucketByScope.set(scope, bucket);
20631
- return `Uploading${event.filePath ? ` ${humanFileLabel(event.filePath)}` : ""}: ${event.percent}%`;
20670
+ return `Uploading${label ? ` ${label}` : ""}: ${event.percent}%`;
20632
20671
  }
20633
20672
  if (event.status === "finishing_upload") return "Finalizing upload";
20634
20673
  if (event.status === "uploaded") {