diff --git a/docs/api.md b/docs/api.md index 705caff..75897c7 100644 --- a/docs/api.md +++ b/docs/api.md @@ -443,6 +443,8 @@ value according to its HTTP status. A few codes add fields after these two (`amb | `version_closed` | 409 | `append` to a version whose append window (`APPEND_WINDOW_HOURS`) has passed, or that is yanked. | | `file_exists` | 409 | `append` with a file name that already exists in the version. | | `upload_mismatch` | 409 | On `commit`: the size or SHA-256 of a staged file differs from the `init` declaration. | +| `artifact_mismatch` | 409 | On digest backfill: the stored artifact differs from its declared size or SHA-256. | +| `version_changed` | 409 | The publication or file declaration changed while backfill was computing digests; retry. | | `credential_exists` | 409 | `POST /api/v1/credentials` for a project that already exists. | | `ambiguous` | 409 | Generic label-selected download (8.7): more than one file matches; the body also lists `version` and the candidate `files`. | | `payload_too_large` | 413 | Request body over 4 MiB, or the `size` of a file in `init` above `MAX_UPLOAD_BYTES`. | @@ -526,7 +528,7 @@ interface PackageFile { name: string; // unique within the version size: number; sha256: string; - digests?: Record; // extra digests computed at commit (see 6.5), hex + digests?: Record; // extra digests computed at commit or admin backfill (6.5, 6.11.1), hex role?: string; // per ecosystem (6.4), e.g. "archive", "symbols", "manifest", "pom"; absent for generic labels?: Record; // generic: always present ({} when none); absent elsewhere } @@ -684,30 +686,31 @@ packages depend on, as long as they are in this registry: ## 6. Endpoints -| Method | Path | Role | Section | -| ------ | ----------------------------------------------------- | --------------------------------- | ------- | -| GET | `/api/v1/version` | none | 6.2 | -| GET | `/api/v1/whoami` | any | 6.3 | -| POST | `/api/v1/publish/init` | `publish` | 6.4 | -| POST | `/api/v1/publish/commit` | `publish` | 6.5 | -| GET | `/api/v1/packages` | `read`, `yank`, `delete`, `admin` | 6.6 | -| GET | `/api/v1/packages//` | `read`, `yank`, `delete`, `admin` | 6.7 | -| POST | `/api/v1/packages////yank` | `yank`, `admin` | 6.8 | -| DELETE | `/api/v1/packages///` | `delete`, `admin` | 6.9 | -| DELETE | `/api/v1/packages//` | `delete`, `admin` | 6.10 | -| POST | `/api/v1/packages///reindex` | `admin` | 6.11 | -| GET | `/api/v1/credentials` | `admin` | 6.12 | -| POST | `/api/v1/credentials` | `admin` | 6.13 | -| GET | `/api/v1/credentials/` | `admin` | 6.14 | -| PATCH | `/api/v1/credentials/` | `admin` | 6.15 | -| DELETE | `/api/v1/credentials/` | `admin` | 6.16 | -| POST | `/api/v1/auth/sessions` | none | 6.20 | -| POST | `/api/v1/auth/sessions/poll` | none | 6.21 | -| POST | `/api/v1/credentials//secrets` | `admin` | 6.17 | -| PATCH | `/api/v1/credentials//secrets/` | `admin` | 6.22 | -| DELETE | `/api/v1/credentials//secrets/` | `admin` | 6.18 | -| GET | `/api/v1/github/repository?name=` | `admin` | 6.19 | -| POST | `/api/v1/bucket/accept` | `admin` | 6.23 | +| Method | Path | Role | Section | +| ------ | ---------------------------------------------------------- | --------------------------------- | ------- | +| GET | `/api/v1/version` | none | 6.2 | +| GET | `/api/v1/whoami` | any | 6.3 | +| POST | `/api/v1/publish/init` | `publish` | 6.4 | +| POST | `/api/v1/publish/commit` | `publish` | 6.5 | +| GET | `/api/v1/packages` | `read`, `yank`, `delete`, `admin` | 6.6 | +| GET | `/api/v1/packages//` | `read`, `yank`, `delete`, `admin` | 6.7 | +| POST | `/api/v1/packages////yank` | `yank`, `admin` | 6.8 | +| DELETE | `/api/v1/packages///` | `delete`, `admin` | 6.9 | +| DELETE | `/api/v1/packages//` | `delete`, `admin` | 6.10 | +| POST | `/api/v1/packages///reindex` | `admin` | 6.11 | +| POST | `/api/v1/packages////backfill-digests` | `admin` | 6.11.1 | +| GET | `/api/v1/credentials` | `admin` | 6.12 | +| POST | `/api/v1/credentials` | `admin` | 6.13 | +| GET | `/api/v1/credentials/` | `admin` | 6.14 | +| PATCH | `/api/v1/credentials/` | `admin` | 6.15 | +| DELETE | `/api/v1/credentials/` | `admin` | 6.16 | +| POST | `/api/v1/auth/sessions` | none | 6.20 | +| POST | `/api/v1/auth/sessions/poll` | none | 6.21 | +| POST | `/api/v1/credentials//secrets` | `admin` | 6.17 | +| PATCH | `/api/v1/credentials//secrets/` | `admin` | 6.22 | +| DELETE | `/api/v1/credentials//secrets/` | `admin` | 6.18 | +| GET | `/api/v1/github/repository?name=` | `admin` | 6.19 | +| POST | `/api/v1/bucket/accept` | `admin` | 6.23 | ### 6.1 Auth entry identifiers @@ -1088,8 +1091,9 @@ list in the staging declaration, and `commit` computes those digests while strea staged object to its final key (a `DigestStream`) and stores them as `files[].digests` (lower-case hex) in the manifest. Listings (6.6–6.8) and the generic feed return `digests` when present; `reindex` (6.11) never recomputes them. `sha256` stays mandatory and separate: -it is declared by the client, enforced by the presigned `PUT` and checked at `commit`. Only -the maven adapter declares extra digests (`sha1`, `md5` and `sha512`, see 6.4). +it is declared by the client, enforced by the presigned `PUT` and checked at `commit`. The Composer adapter declares `sha1`; the Maven adapter declares `sha1`, `md5` and +`sha512` (see 6.4). Administrators may also enrich existing manifests through +`backfill-digests` (6.11.1), without changing the artifact bytes. The rules are checked against the state at commit time. Without `append`, the first commit of a version wins and later ones get `409 version_exists`. With `append`, a commit that finds the @@ -1346,6 +1350,32 @@ Response `200`: `manifests` is the number of version manifests the index was built from. Errors: `404 not_found` when the package has no manifests. +### 6.11.1 `POST /api/v1/packages////backfill-digests` + +Role `admin`. No body. Reads each file missing an adapter-declared digest from R2 and +computes the missing digests while streaming. It verifies the stored size and SHA-256 +against the manifest before persisting any change. Existing digests, publication metadata, +yank state and archive bytes are preserved. An adapter without extra digests is a no-op. + +Response `200`: + +```json +{ "eco": "composer", "name": "acme/sdk", "version": "1.0.0", "updated": true } +``` + +`updated` is false if there were no missing digests (including a concurrent backfill that +finished first). The manifest is updated conditionally, preserving a concurrent yank; +a deleted manifest is never recreated, and a changed publication or file declaration +aborts the operation. No partial digests are persisted if any file fails verification. +Errors: `404 not_found` for an unknown version or missing artifact, `409 artifact_mismatch` +for a size or SHA-256 mismatch, and `409 version_changed` for a changed declaration. + +This endpoint does not rebuild indexes. After processing a package, call `reindex` (6.11), +even when every version already has its digests, to recover from an interrupted earlier run. +Composer metadata emits the archive's `files[].digests.sha1` as `dist.shasum` (40 lower-case +hex characters), retaining SHA-256 in `dist.reference`. Older manifests omit `shasum` until +backfilled. Client-supplied sums are ignored. No CLI upgrade or schema migration is required. + ### 6.12 `GET /api/v1/credentials` Role `admin`. Lists credentials stored in KV (provider-backed projects are not listed), diff --git a/docs/spec.md b/docs/spec.md index 59c61c5..7a18f4b 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -220,7 +220,7 @@ The package name in the key is encoded safely: `/` and `@` in composer/npm names `native` is literally what the adapter needs to reproduce the entry in the index: for composer the whole `composer.json` of the version, for npm the `versions[v]` entry of the packument, for cargo the index line (`deps`, `features`, `cksum`). -`files[].digests` (optional): additional digests besides `sha256`, e.g. `{ "sha1": "…", "md5": "…" }`, needed by ecosystems whose clients verify other algorithms (Maven). The adapter declares in `init` the list of required algorithms (`digests: ["sha1", "md5"]`), and the Worker computes them at `commit` while streaming the object from staging to its target key, and stores them in the manifest. Without a declaration by the adapter nothing is computed; `reindex` does not recompute digests. The `sha256` field stays mandatory and separate: it is the only digest that the CLI computes before sending, that the Worker enforces in the presign (`x-amz-checksum-sha256`) and checks at `commit`, so it is the proof of the upload's integrity, while `digests` are only derivatives for clients. +`files[].digests` (optional): additional digests besides `sha256`, e.g. `{ "sha1": "…", "md5": "…" }`, needed by ecosystems whose clients verify other algorithms (Maven). The adapter declares in `init` the list of required algorithms (`digests: ["sha1", "md5"]`), and the Worker computes them at `commit` while streaming the object from staging to its target key, and stores them in the manifest. Without a declaration by the adapter nothing is computed; `reindex` does not recompute digests. The `sha256` field stays mandatory and separate: it is the only digest that the CLI computes before sending, that the Worker enforces in the presign (`x-amz-checksum-sha256`) and checks at `commit`, so it is the proof of the upload's integrity, while `digests` are only derivatives for clients. Composer requests `sha1` and exposes it as `dist.shasum`; Maven requests `sha1`, `md5` and `sha512`. An explicit admin backfill may enrich existing manifests with missing adapter-declared digests, after verifying the stored bytes against their size and SHA-256. This does not change the release artifacts or publication metadata. **Keys in KV** @@ -365,6 +365,8 @@ interface Adapter { Client: `auth.json` with `bearer` or `http-basic` and `repositories: [{ type: composer, url: https:///composer }]`, or without `auth.json`, with the token in the URL: `https://@/composer` (Composer extracts the userinfo as `http-basic`). npm and cargo do not support credentials in the URL. +Composer archives have `dist.reference` equal to their SHA-256 and, when available, `dist.shasum` equal to their SHA-1 (40 lower-case hex characters). Composer verifies downloaded ZIPs against `shasum`; `reference` alone does not enable checksum verification. Legacy versions omit `shasum` until an administrator backfills their digests and rebuilds the index. Client-supplied `dist`, `source` and file digests cannot override these computed values. + **npm** (`/npm/…`) | Endpoint | Returns |