filecafe 0.4.0 → 0.4.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.
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as updateCachePath, c as configPath, d as readConfig, f as resolveSettings, l as deleteConfig, m as VERSION, n as fetchLatestVersion, o as updateUpdateCache, p as writeConfig, r as readUpdateCache, t as CHECK_INTERVAL_MS, u as normalizeBaseUrl } from "./update-cache-CQ0lo5cs.js";
2
+ import { a as updateCachePath, c as configPath, d as readConfig, f as resolveSettings, l as deleteConfig, m as VERSION, n as fetchLatestVersion, o as updateUpdateCache, p as writeConfig, r as readUpdateCache, t as CHECK_INTERVAL_MS, u as normalizeBaseUrl } from "./update-cache-INu00cnB.js";
3
3
  import { Command } from "commander";
4
4
  import { execFile, spawn } from "node:child_process";
5
5
  import { realpath, stat } from "node:fs/promises";
@@ -600,7 +600,7 @@ function isSignedTarget(value) {
600
600
  function planTransfer(upload, size) {
601
601
  const unexpected = (detail) => new ApiError(`Unexpected response when starting the upload: ${detail}.`, null);
602
602
  const data = upload;
603
- if (!isRecord(data) || typeof data.id !== "string" || typeof data.token !== "string") throw unexpected("missing id or token");
603
+ if (!isRecord(data) || typeof data.id !== "string") throw unexpected("missing id");
604
604
  if ("parts" in data) {
605
605
  const { parts, part_size: partSize } = data;
606
606
  if (typeof partSize !== "number" || !Number.isSafeInteger(partSize) || partSize <= 0) throw unexpected("invalid part_size");
@@ -732,13 +732,12 @@ async function uploadFile(options) {
732
732
  }
733
733
  });
734
734
  });
735
- return client.request("PUT", `/api/v1/uploads/${encodeURIComponent(started.id)}`, { token: partUrls.token() }, { idempotent: true });
735
+ return client.request("PUT", `/api/v1/uploads/${encodeURIComponent(started.id)}`, void 0, { idempotent: true });
736
736
  }
737
737
  /**
738
738
  * The URL for each part of an upload, in batches of PART_URL_BATCH_SIZE. The first batch comes
739
739
  * from the start response; later ones, and any batch older than PART_URL_MAX_AGE_MS, are fetched
740
- * when a part in them is about to be uploaded. Each fetch also renews the upload ticket, so the
741
- * latest token is the one to complete with.
740
+ * when a part in them is about to be uploaded. Each fetch also renews the upload's expiry.
742
741
  */
743
742
  function createPartUrls(options, started, targets) {
744
743
  const now = options.now ?? Date.now;
@@ -746,39 +745,31 @@ function createPartUrls(options, started, targets) {
746
745
  fetchedAt: now(),
747
746
  targets: Promise.resolve(targets.slice(0, PART_URL_BATCH_SIZE))
748
747
  }]]);
749
- let token = started.token;
750
748
  const fetchBatch = async (batch) => {
751
749
  const first = batch * PART_URL_BATCH_SIZE + 1;
752
750
  const partNumbers = Array.from({ length: Math.min(PART_URL_BATCH_SIZE, targets.length - first + 1) }, (_, i) => first + i);
753
- const response = await options.client.request("POST", `/api/v1/uploads/${encodeURIComponent(started.id)}/parts`, {
754
- token,
755
- part_numbers: partNumbers
756
- }, { idempotent: true });
751
+ const response = await options.client.request("POST", `/api/v1/uploads/${encodeURIComponent(started.id)}/parts`, { part_numbers: partNumbers }, { idempotent: true });
757
752
  const parts = isRecord(response) && Array.isArray(response.parts) ? response.parts : [];
758
753
  const fresh = partNumbers.map((partNumber) => parts.find((part) => isRecord(part) && part.part_number === partNumber));
759
- if (!isRecord(response) || typeof response.token !== "string" || !fresh.every(isSignedTarget)) throw new ApiError("Unexpected response when fetching upload URLs.", null);
760
- token = response.token;
754
+ if (!fresh.every(isSignedTarget)) throw new ApiError("Unexpected response when fetching upload URLs.", null);
761
755
  return fresh.map((part) => ({
762
756
  url: part.url,
763
757
  headers: part.headers
764
758
  }));
765
759
  };
766
- return {
767
- async target(index) {
768
- if (!("parts" in started)) return targets[index];
769
- const batch = Math.floor(index / PART_URL_BATCH_SIZE);
770
- let entry = batches.get(batch);
771
- if (!entry || now() - entry.fetchedAt > PART_URL_MAX_AGE_MS) {
772
- entry = {
773
- fetchedAt: now(),
774
- targets: fetchBatch(batch)
775
- };
776
- batches.set(batch, entry);
777
- }
778
- return (await entry.targets)[index % PART_URL_BATCH_SIZE];
779
- },
780
- token: () => token
781
- };
760
+ return { async target(index) {
761
+ if (!("parts" in started)) return targets[index];
762
+ const batch = Math.floor(index / PART_URL_BATCH_SIZE);
763
+ let entry = batches.get(batch);
764
+ if (!entry || now() - entry.fetchedAt > PART_URL_MAX_AGE_MS) {
765
+ entry = {
766
+ fetchedAt: now(),
767
+ targets: fetchBatch(batch)
768
+ };
769
+ batches.set(batch, entry);
770
+ }
771
+ return (await entry.targets)[index % PART_URL_BATCH_SIZE];
772
+ } };
782
773
  }
783
774
  // src/commands/upload.ts
784
775
  const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -3,7 +3,7 @@ import "node:os";
3
3
  import { basename, dirname, join } from "node:path";
4
4
  import { randomUUID } from "node:crypto";
5
5
  // src/version.ts
6
- const VERSION = "0.4.0";
6
+ const VERSION = "0.4.1";
7
7
  // src/config.ts
8
8
  const DEFAULT_BASE_URL = "https://file.cafe";
9
9
  /**
@@ -1,4 +1,4 @@
1
- import { i as refreshUpdateCache, m as VERSION } from "./update-cache-CQ0lo5cs.js";
1
+ import { i as refreshUpdateCache, m as VERSION } from "./update-cache-INu00cnB.js";
2
2
  // src/update-worker.ts
3
3
  /**
4
4
  * Spawned detached by the CLI to refresh the update cache, so no command ever waits on npm.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "filecafe",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Upload files to file.cafe from the command line. Built for AI coding agents, humans, and CI.",
5
5
  "keywords": [
6
6
  "file.cafe",