# Froggy publishing API v1

Base URL: `https://www.froggy.fun/api/v1`. Authenticate with `Authorization: Bearer <token>`. A token is a Froggy publishing token, not a Supabase or X key. JSON requests require `Content-Type: application/json` and are limited to 64 KB. File bytes go directly to the signed upload URL. API calls return `{ "data": ..., "request_id": "..." }` or `{ "error": { "code": "...", "message": "...", "field": "optional" }, "request_id": "..." }`.

## Manifest for scripts/publish.mjs

```json
{
  "title": "My game",
  "platform": "GBA",
  "summary": "Describe what the player does.",
  "about": "Controls and further details.",
  "note": "Release notes.",
  "status": "released",
  "tags": ["Adventure"],
  "cartridge_style": { "color": "purple", "finish": "transparent" },
  "rights_confirmed": true,
  "license": "Your actual distribution license or permission",
  "build": "build/game.gba",
  "cartridge_art": "art/label.png",
  "screenshots": ["screenshots/title.png", "screenshots/gameplay.png"]
}
```

All paths are relative to the manifest's directory, which should be the project root. The helper writes `creation_id` before creating a game, and `game_id` after success. Keep them to update the same page. Omitted attachment fields leave existing files alone; `build: null` and `cartridge_art: null` remove those attachments; `screenshots: []` clears screenshots. Export files yourself before running the helper. New pages default to In Development (`status: "in-development"`) and private; use `status: "released"` for a Release; `released` requires a build when publishing. A distribution-rights confirmation and a nonempty license/permission note are required whenever a build is attached. Node.js 20+ is required; the helper has no external dependencies.

Use `node scripts/publish.mjs /path/to/froggy.json` to save and `node scripts/publish.mjs /path/to/froggy.json --publish` to make the page public. Use `--visibility unlisted` to share a page by direct link without listing it, `--visibility public` to list it, or `--visibility private` to restrict it to the owner. Changing visibility requires `games:publish`. Without an explicit visibility flag, a new page stays private and existing visibility is preserved. Edits to unlisted or public pages are live. `FROGGY_API_TOKEN` comes from an environment or secret manager. Do not store it in the manifest. `FROGGY_API_URL` is an optional HTTPS base URL override for development; plain HTTP is accepted only for loopback hosts.

## Permissions

- `games:read`: token check, read/list games and uploads, validate publication requirements.
- `games:write`: create and edit private game pages.
- `uploads:write`: prepare and complete uploads.
- `games:publish`: publish/unpublish and, in addition to the operation's usual permission, change a public page or its uploads.

All tokens include `games:read`. A token can be restricted to one game; such a token cannot create other game pages. Each account has up to ten active tokens. New tokens default to Never and remain valid until revoked; an optional timed expiration is 1–365 days. Revocation stops new API calls immediately. Already-issued upload URLs last up to two hours, but a revoked token cannot complete or attach an upload. Each token allows 120 requests/minute; respect `Retry-After` on 429.

## Endpoints

### GET /me

Returns `user_id`, `token_id`, optional `game_id` and granted `scopes`. Never returns token secrets or hashes.

### GET /games and GET /games/{id}

List returns `{ "games": [...] }`, at most 50 owned game pages. A single game includes `id`, `slug`, metadata, existing asset metadata, `visibility`, `updated_at`, `url` and `edit_url`. Public access to someone else's page does not give an API token access to that person's game management data.

### POST /games

Requires `games:write` and a lowercase UUID in `Idempotency-Key`.

```json
{ "title": "My game", "platform": "GBA" }
```

Returns the new private game with HTTP 201. The key becomes its game ID. Retrying the same ID/title/platform returns the existing page with HTTP 200. Reusing the ID with different details returns 409. Creation also accepts optional `cartridge_style`; use PATCH for other details or to change an existing shell.

### PATCH /games/{id}

Requires `games:write`, plus `games:publish` if the page is public. Send the latest `updated_at` timestamp in `If-Match`. Fields omitted from the object keep their current values:

| Field | Requirement |
| --- | --- |
| `title` | Nonempty text, up to 80 characters |
| `platform` | `GB`, `GBC` or `GBA`; attached assets must match |
| `cartridge_style` | `{ "color": "purple", "finish": "transparent" }`, or `null` for the default. Colors: `grey`, `ivory`, `black`, `purple`, `lavender`, `pink`, `red`, `orange`, `yellow`, `lime`, `green`, `teal`, `blue`, `clear`. Finish: `solid` or `transparent` |
| `summary` | Plain text only, up to 240 characters; no Markdown rendering |
| `about` | CommonMark Markdown, up to 2,000 characters; rendered in About. Raw HTML is disabled |
| `note` | Text, up to 1,000 characters |
| `status` | `in-development` or `released` |
| `tags` | Up to two distinct tags from the list below |
| `rights_confirmed` | Boolean; true only with the user's distribution rights |
| `license` | Actual license or permission note, up to 240 characters |
| `build_id` | Completed build upload UUID, or null to remove |
| `cartridge_art_id` | Completed cartridge upload UUID, or null to remove |
| `screenshot_ids` | Ordered array of up to six distinct completed screenshot upload UUIDs; [] removes all |

Existing asset IDs from the same game's current attachments can also be retained or reordered. Raw object paths, owner IDs, visibility and unknown fields are rejected. Available tags: Cozy, Adventure, Puzzle, Exploration, RPG, Racing, Arcade, Horror, Experimental, Action, Comedy, Music.

### GET /games/{id}/builds

Returns owner-only `{ "builds": [...] }`, each with `id`, a per-game sequential `number` starting at 1, verified `metadata`, `created_at` and `active`. Browser and API uploads share the same build history. Completing a build upload assigns its number but does not make it active. Repeating completion reuses the same number. Existing builds are retained when another becomes active.

To select an existing build, PATCH the game with `build_id` from this list and its current `updated_at` in `If-Match`. Pass `build_id: null` to detach the active build without deleting history. Only the active build is used for Play and Download. Private history never becomes a public download merely because the game page is public. Editing a public game still requires `games:publish`.

### GET /games/{id}/uploads

Returns `{ "uploads": [...] }` with up to 400 reservations, including `id`, `kind`, `name`, `size`, `sha256`, `completed_at`, `expires_at` and verified `metadata`. Reuse a matching completed upload instead of uploading unchanged bytes again.

### POST /games/{id}/uploads

Requires `uploads:write`, plus `games:publish` for public games. Send a UUID in `Idempotency-Key`, one per file:

```json
{
  "kind": "build",
  "name": "game.gba",
  "size": 32768,
  "content_type": "application/octet-stream",
  "sha256": "the actual lowercase 64-character SHA-256 of the file bytes"
}
```

Kind is `build`, `cartridge` or `screenshot`. ROM content type is `application/octet-stream`; image types are `image/png`, `image/jpeg`, `image/webp`.

The response supplies `id`, `completed: false`, `upload_url`, `method: "PUT"`, `headers`, `expires_in: 7200` and `complete_url`. PUT raw bytes with those headers to `upload_url`. **Do not include the Froggy bearer token.** Objects cannot be overwritten. Reusing the same reservation returns a URL for the same immutable object; if the file already arrived, complete it rather than replacing it. Reusing a completed upload ID returns `completed: true` and verified metadata.

### POST /games/{id}/uploads/{upload_id}/complete

No body required. Requires `uploads:write` and publishing permission for public pages. Verifies actual byte count, SHA-256, ROM header and system, or image encoding and exact dimensions. Returns `id`, `completed: true`, `metadata`. Completion is safe to retry. A missing file returns 409; an expired reservation returns 410; invalid file bytes return 422. Uploading does not attach the file; PATCH the game afterward.

### POST /games/{id}/validate

No body required. Returns `ready`, a list of `problems` with fields/messages, and `updated_at`. A public page needs a summary; released games also need a build. Attached builds require rights confirmation and a license/permission note.

### POST /games/{id}/publish and POST /games/{id}/unpublish

No body required. Requires `games:publish` and `If-Match` with the latest `updated_at`. Publication validates readiness, then changes visibility atomically. Unpublish makes the page private without deleting it or its files.

## File requirements

GBA builds: `.gba`, 192 bytes–32 MiB, with a valid GBA fixed header byte. GB builds: `.gb`, 336 bytes–8 MiB, with a valid header checksum; GBC-only ROMs cannot be labeled GB. GBC builds: `.gb` or `.gbc`, 336 bytes–8 MiB, with a valid header checksum and a CGB flag. These are format checks, not proof that a game plays correctly; test the exported game.

Images must be static PNG, JPG or WebP, at most 4 MiB, without EXIF rotation:

| System | Label artwork (recommended) | Legacy full cartridge | Screenshot |
| --- | --- | --- | --- |
| GBA | 1290 × 660 | 600 × 400 | 240 × 160 |
| GB / GBC | 1260 × 1110 | 600 × 680 | 160 × 144 |

Upload only the label design at the exact recommended size. Froggy layers it over a photographic shell in the chosen color and finish. Label uploads use `kind: "cartridge"`; completion detects their dimensions and returns `layout: "label"` in the attachment metadata. Legacy full-cartridge images remain supported. Omit artwork to use an automatic title label. Images are validated without resizing; an incorrect size is rejected.

Account limits: 50 pages, 400 stored game files, 512 MiB of game files, 16 pending unexpired API upload reservations. Uploaded files consume the quota even if not attached. The current API keeps previous files; game deletion through Manage your games removes that game's files. Contact Froggy if you need help clearing abandoned uploads.

## Error handling

401: token missing, invalid, expired, revoked or account unavailable. 403: missing permission or wrong game restriction. 404: resource not owned/found. 409: version/idempotency conflict, changed system or file not uploaded. 410: upload reservation expired. 413: JSON body too large. 415: JSON content type required. 422: file or publication validation failed. 428: If-Match missing. 429: rate limit. 503: temporary service/signing failure.

Retry transient failures at most three times with the same operation ID. On 409 version conflict, re-read and reconcile rather than forcing an overwrite. On 410 use a new upload UUID. If an upload PUT was ambiguous, try completion before attempting another file upload. Report `request_id` when asking for support. Do not print tokens or signed URLs.


### Set visibility

`POST /games/{id}/visibility` with `{"visibility":"private"}`, `{"visibility":"unlisted"}`, or `{"visibility":"public"}` requires `games:publish` and `If-Match` with the latest `updated_at`. Unlisted pages are accessible to anyone with the direct game URL but excluded from listings and search; links can be reshared. Public and unlisted pages need a short description, and a Release also needs a build. Private pages are owner-only. Existing publish and unpublish endpoints still set public and private respectively.
