diff --git a/README.md b/README.md index 608f542a..fd14278a 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,11 @@ npx wrangler secret put EXTENSIONS_REVALIDATE_SECRET The extension directory website is licensed under the GNU Affero General Public License Version 3. See [LICENSE](./LICENSE) for details. Individual extensions are licensed by their respective authors. + +## Manifest API contract + +The generated v2 client follows the API's manifest v1 contract: `module`, string licenses, optional `homepage_url`, package authors, and full FOSSBilling/PHP/module requirements. Author/edit/moderator forms preserve these fields; historical revision diffs also accept pre-manifest license objects and `website` fields. + +Package icons are paths relative to the distribution root. For GitHub release assets matching the declared source repository, the site resolves them against the release tag. `FOSSBilling/modules` uses its `Ucfirst(id)/` package directory; other GitHub sources use the repository root. Unsupported sources omit relative icons. Legacy HTTP(S) icons continue to work. + +API mutations and site mutations both purge the `extensions` and `developers` tags. The `developers` tag is currently a no-op reserved for future cached surfaces; developer pages are uncached. Deploy this site with the API's manifest migration and cache-tag change before enabling the updated modules publisher. Existing cached pages expire through their cache windows; deployment must coordinate the new contract and tag. Old pending revisions require resubmission using the manifest fields before approval. diff --git a/astro.config.ts b/astro.config.ts index 4a940dbf..7ae5f4e5 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -1,5 +1,6 @@ // @ts-check import { defineConfig } from 'astro/config'; +import { EXTENSIONS_CACHE_TAG } from './src/lib/cache-tags'; import tailwindcss from '@tailwindcss/vite'; import cloudflare from '@astrojs/cloudflare'; import { cacheCloudflare } from '@astrojs/cloudflare/cache'; @@ -9,17 +10,17 @@ export default defineConfig({ output: 'server', // Canonical and Open Graph URLs are built from this origin at render time. site: 'https://extensions.fossbilling.org', - // Route caching: public catalogue pages carry a Cloudflare-CDN-Cache-Control + // Route caching: public directory pages carry a Cloudflare-CDN-Cache-Control // header, so Cloudflare's zone-wide CDN serves cache hits without invoking // the worker at all. Per-colo Cache API cannot be purged remotely; these - // entries are tag-purgeable, which is what makes catalogue mutations + // entries are tag-purgeable, which is what makes directory mutations // visible within seconds instead of after a TTL (see lib/cache-invalidate). cache: { provider: cacheCloudflare(), }, routeRules: { - // New submissions enter a pending review queue, so the catalogue only - // changes when a dashboard approval (purges 'catalogue') or an api-side + // New submissions enter a pending review queue, so the directory only + // changes when a dashboard approval (purges 'extensions') or an api-side // writer (POST /api/revalidate) publishes something; between events, // maxAge+SWR bound the staleness of any other drift. // @@ -27,8 +28,8 @@ export default defineConfig({ // a session-dependent claim form vs sign-in link, and CDN hits are // served by URL without cookies, so the first visitor's variant would // leak to everyone. - '/': { maxAge: 120, swr: 60, tags: ['catalogue'] }, - '/extension/[id]': { maxAge: 300, swr: 120, tags: ['catalogue'] }, + '/': { maxAge: 120, swr: 60, tags: [EXTENSIONS_CACHE_TAG] }, + '/extension/[id]': { maxAge: 300, swr: 120, tags: [EXTENSIONS_CACHE_TAG] }, '/404': { maxAge: 60 }, }, // Prefetch is disabled entirely: Cloudflare's edge refuses diff --git a/openapi/extensions-v2.json b/openapi/extensions-v2.json index d3199f73..0586ae6c 100644 --- a/openapi/extensions-v2.json +++ b/openapi/extensions-v2.json @@ -43,15 +43,18 @@ "ExtensionListItem": { "type": "object", "properties": { + "manifest_version": { + "type": "number", + "enum": [1] + }, "type": { "type": "string", "enum": [ - "mod", + "module", "theme", "payment-gateway", "server-manager", "domain-registrar", - "hook", "translation" ] }, @@ -65,19 +68,37 @@ "minLength": 1, "maxLength": 4000 }, - "website": { + "author": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": ["name"], + "additionalProperties": false + }, + "homepage_url": { "type": ["string", "null"], "maxLength": 2048, "format": "uri", "description": "Null when a legacy URL exceeds the card length bound" }, "license": { - "$ref": "#/components/schemas/License" + "type": "string", + "minLength": 1, + "maxLength": 1000 }, "icon_url": { "type": "string", - "maxLength": 2048, - "format": "uri" + "maxLength": 2048 }, "source": { "$ref": "#/components/schemas/Repository" @@ -101,10 +122,11 @@ } }, "required": [ + "manifest_version", "type", "name", "description", - "website", + "author", "license", "source", "version", @@ -113,28 +135,6 @@ "developer" ] }, - "License": { - "type": "object", - "properties": { - "name": { - "type": "string", - "minLength": 1, - "maxLength": 100 - }, - "spdx_id": { - "type": "string", - "description": "A current SPDX license identifier (https://spdx.org/licenses/). Omitted for custom or proprietary licenses.", - "example": "MIT" - }, - "URL": { - "type": "string", - "maxLength": 2048, - "format": "uri" - } - }, - "required": ["name"], - "additionalProperties": false - }, "Repository": { "type": "object", "properties": { @@ -198,15 +198,18 @@ "published": { "type": ["object", "null"], "properties": { + "manifest_version": { + "type": "number", + "enum": [1] + }, "type": { "type": "string", "enum": [ - "mod", + "module", "theme", "payment-gateway", "server-manager", "domain-registrar", - "hook", "translation" ] }, @@ -220,19 +223,37 @@ "minLength": 1, "maxLength": 4000 }, - "website": { + "author": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": ["name"], + "additionalProperties": false + }, + "homepage_url": { "type": ["string", "null"], "maxLength": 2048, "format": "uri", "description": "Null when a legacy URL exceeds the card length bound" }, "license": { - "$ref": "#/components/schemas/License" + "type": "string", + "minLength": 1, + "maxLength": 1000 }, "icon_url": { "type": "string", - "maxLength": 2048, - "format": "uri" + "maxLength": 2048 }, "source": { "$ref": "#/components/schemas/Repository" @@ -250,10 +271,11 @@ } }, "required": [ + "manifest_version", "type", "name", "description", - "website", + "author", "license", "source", "version", @@ -397,6 +419,28 @@ { "type": "object", "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 120 + }, + "description": { + "type": "string", + "minLength": 1, + "maxLength": 4000 + }, + "license": { + "type": "string", + "minLength": 1 + }, + "icon_url": { + "type": "string" + }, + "version": { + "type": "string", + "minLength": 1, + "maxLength": 100 + }, "id": { "type": "string" }, @@ -408,6 +452,31 @@ } ] }, + "ManifestRequirements": { + "type": "object", + "properties": { + "fossbilling": { + "type": "string", + "minLength": 1, + "maxLength": 1000 + }, + "php": { + "type": "string", + "minLength": 1, + "maxLength": 1000 + }, + "modules": { + "type": "object", + "additionalProperties": { + "type": "string", + "minLength": 1, + "maxLength": 1000 + } + } + }, + "required": ["fossbilling", "php"], + "additionalProperties": false + }, "Release": { "type": "object", "properties": { @@ -431,39 +500,60 @@ "maxLength": 2048, "format": "uri" }, - "min_fossbilling_version": { - "type": "string", - "minLength": 1, - "maxLength": 100 + "requires": { + "$ref": "#/components/schemas/ManifestRequirements" } }, - "required": ["tag", "date", "download_url", "min_fossbilling_version"], + "required": ["tag", "date", "download_url", "requires"], "additionalProperties": false }, "ExtensionContent": { "type": "object", "properties": { + "manifest_version": { + "type": "number", + "enum": [1] + }, "type": { "type": "string", "enum": [ - "mod", + "module", "theme", "payment-gateway", "server-manager", "domain-registrar", - "hook", "translation" ] }, "name": { "type": "string", "minLength": 1, - "maxLength": 120 + "maxLength": 100 }, "description": { "type": "string", "minLength": 1, - "maxLength": 4000 + "maxLength": 500 + }, + "author": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": ["name"], + "additionalProperties": false + }, + "requires": { + "$ref": "#/components/schemas/ManifestRequirements" }, "releases": { "type": "array", @@ -473,18 +563,22 @@ "minItems": 1, "maxItems": 100 }, - "website": { + "homepage_url": { "type": "string", "maxLength": 2048, "format": "uri" }, "license": { - "$ref": "#/components/schemas/License" + "type": "string", + "minLength": 1, + "maxLength": 1000, + "pattern": "^[A-Za-z0-9.\\-+_:() |]+$" }, "icon_url": { "type": "string", + "minLength": 1, "maxLength": 2048, - "format": "uri" + "pattern": "^(?!\\/)(?![a-zA-Z][a-zA-Z0-9+.-]*:)(?!.*\\.\\.)[^\\\\]+$" }, "readme": { "type": "string", @@ -496,8 +590,8 @@ }, "version": { "type": "string", - "minLength": 1, - "maxLength": 100 + "maxLength": 100, + "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" }, "download_url": { "type": "string", @@ -506,11 +600,13 @@ } }, "required": [ + "manifest_version", "type", "name", "description", + "author", + "requires", "releases", - "website", "license", "readme", "source", @@ -534,6 +630,16 @@ { "type": ["object", "null"], "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 120 + }, + "description": { + "type": "string", + "minLength": 1, + "maxLength": 4000 + }, "releases": { "type": "array", "items": { @@ -549,6 +655,9 @@ "minLength": 1, "maxLength": 200, "description": "At most 100 Unicode code points in historical content" + }, + "min_fossbilling_version": { + "type": "string" } }, "additionalProperties": false @@ -556,6 +665,18 @@ ] }, "maxItems": 100 + }, + "license": { + "type": "string", + "minLength": 1 + }, + "icon_url": { + "type": "string" + }, + "version": { + "type": "string", + "minLength": 1, + "maxLength": 100 } } } @@ -584,16 +705,21 @@ "StoredExtensionContent": { "type": "object", "properties": { + "manifest_version": { + "type": "number", + "enum": [1] + }, "type": { "type": "string", "enum": [ - "mod", + "module", "theme", "payment-gateway", "server-manager", "domain-registrar", - "hook", - "translation" + "translation", + "mod", + "hook" ] }, "name": { @@ -606,6 +732,26 @@ "minLength": 1, "maxLength": 4000 }, + "author": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": ["name"], + "additionalProperties": false + }, + "requires": { + "$ref": "#/components/schemas/ManifestRequirements" + }, "releases": { "type": "array", "items": { @@ -621,6 +767,9 @@ "minLength": 1, "maxLength": 200, "description": "At most 100 Unicode code points in historical content" + }, + "min_fossbilling_version": { + "type": "string" } }, "additionalProperties": false @@ -629,18 +778,52 @@ }, "maxItems": 100 }, - "website": { + "homepage_url": { "type": "string", "maxLength": 2048, "format": "uri" }, "license": { - "$ref": "#/components/schemas/License" + "anyOf": [ + { + "type": "string", + "minLength": 1, + "maxLength": 1000, + "pattern": "^[A-Za-z0-9.\\-+_:() |]+$" + }, + { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "spdx_id": { + "type": "string" + }, + "URL": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": ["name"] + } + ] }, "icon_url": { - "type": "string", - "maxLength": 2048, - "format": "uri" + "anyOf": [ + { + "type": "string", + "minLength": 1, + "maxLength": 2048, + "pattern": "^(?!\\/)(?![a-zA-Z][a-zA-Z0-9+.-]*:)(?!.*\\.\\.)[^\\\\]+$" + }, + { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + ] }, "readme": { "type": "string", @@ -659,33 +842,61 @@ "type": "string", "maxLength": 2048, "format": "uri" + }, + "website": { + "type": "string", + "maxLength": 2048, + "format": "uri" } } }, "ExtensionCreate": { "type": "object", "properties": { + "manifest_version": { + "type": "number", + "enum": [1] + }, "type": { "type": "string", "enum": [ - "mod", + "module", "theme", "payment-gateway", "server-manager", "domain-registrar", - "hook", "translation" ] }, "name": { "type": "string", "minLength": 1, - "maxLength": 120 + "maxLength": 100 }, "description": { "type": "string", "minLength": 1, - "maxLength": 4000 + "maxLength": 500 + }, + "author": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": ["name"], + "additionalProperties": false + }, + "requires": { + "$ref": "#/components/schemas/ManifestRequirements" }, "releases": { "type": "array", @@ -695,18 +906,22 @@ "minItems": 1, "maxItems": 100 }, - "website": { + "homepage_url": { "type": "string", "maxLength": 2048, "format": "uri" }, "license": { - "$ref": "#/components/schemas/License" + "type": "string", + "minLength": 1, + "maxLength": 1000, + "pattern": "^[A-Za-z0-9.\\-+_:() |]+$" }, "icon_url": { "type": "string", + "minLength": 1, "maxLength": 2048, - "format": "uri" + "pattern": "^(?!\\/)(?![a-zA-Z][a-zA-Z0-9+.-]*:)(?!.*\\.\\.)[^\\\\]+$" }, "readme": { "type": "string", @@ -718,8 +933,8 @@ }, "version": { "type": "string", - "minLength": 1, - "maxLength": 100 + "maxLength": 100, + "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" }, "download_url": { "type": "string", @@ -728,16 +943,19 @@ }, "id": { "type": "string", - "maxLength": 200, - "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" + "minLength": 1, + "maxLength": 64, + "pattern": "^[a-z0-9_-]+$" } }, "required": [ + "manifest_version", "type", "name", "description", + "author", + "requires", "releases", - "website", "license", "readme", "source", @@ -750,27 +968,50 @@ "ExtensionUpdate": { "type": "object", "properties": { + "manifest_version": { + "type": "number", + "enum": [1] + }, "type": { "type": "string", "enum": [ - "mod", + "module", "theme", "payment-gateway", "server-manager", "domain-registrar", - "hook", "translation" ] }, "name": { "type": "string", "minLength": 1, - "maxLength": 120 + "maxLength": 100 }, "description": { "type": "string", "minLength": 1, - "maxLength": 4000 + "maxLength": 500 + }, + "author": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": ["name"], + "additionalProperties": false + }, + "requires": { + "$ref": "#/components/schemas/ManifestRequirements" }, "releases": { "type": "array", @@ -780,18 +1021,22 @@ "minItems": 1, "maxItems": 100 }, - "website": { + "homepage_url": { "type": "string", "maxLength": 2048, "format": "uri" }, "license": { - "$ref": "#/components/schemas/License" + "type": "string", + "minLength": 1, + "maxLength": 1000, + "pattern": "^[A-Za-z0-9.\\-+_:() |]+$" }, "icon_url": { "type": "string", + "minLength": 1, "maxLength": 2048, - "format": "uri" + "pattern": "^(?!\\/)(?![a-zA-Z][a-zA-Z0-9+.-]*:)(?!.*\\.\\.)[^\\\\]+$" }, "readme": { "type": "string", @@ -803,8 +1048,8 @@ }, "version": { "type": "string", - "minLength": 1, - "maxLength": 100 + "maxLength": 100, + "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" }, "download_url": { "type": "string", @@ -813,11 +1058,13 @@ } }, "required": [ + "manifest_version", "type", "name", "description", + "author", + "requires", "releases", - "website", "license", "readme", "source", @@ -1292,27 +1539,50 @@ "ModeratorCorrect": { "type": "object", "properties": { + "manifest_version": { + "type": "number", + "enum": [1] + }, "type": { "type": "string", "enum": [ - "mod", + "module", "theme", "payment-gateway", "server-manager", "domain-registrar", - "hook", "translation" ] }, "name": { "type": "string", "minLength": 1, - "maxLength": 120 + "maxLength": 100 }, "description": { "type": "string", "minLength": 1, - "maxLength": 4000 + "maxLength": 500 + }, + "author": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": ["name"], + "additionalProperties": false + }, + "requires": { + "$ref": "#/components/schemas/ManifestRequirements" }, "releases": { "type": "array", @@ -1322,18 +1592,22 @@ "minItems": 1, "maxItems": 100 }, - "website": { + "homepage_url": { "type": "string", "maxLength": 2048, "format": "uri" }, "license": { - "$ref": "#/components/schemas/License" + "type": "string", + "minLength": 1, + "maxLength": 1000, + "pattern": "^[A-Za-z0-9.\\-+_:() |]+$" }, "icon_url": { "type": "string", + "minLength": 1, "maxLength": 2048, - "format": "uri" + "pattern": "^(?!\\/)(?![a-zA-Z][a-zA-Z0-9+.-]*:)(?!.*\\.\\.)[^\\\\]+$" }, "readme": { "type": "string", @@ -1345,8 +1619,8 @@ }, "version": { "type": "string", - "minLength": 1, - "maxLength": 100 + "maxLength": 100, + "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" }, "download_url": { "type": "string", @@ -1360,11 +1634,13 @@ } }, "required": [ + "manifest_version", "type", "name", "description", + "author", + "requires", "releases", - "website", "license", "readme", "source", @@ -1553,7 +1829,7 @@ "/extensions": { "get": { "tags": ["Extensions"], - "summary": "List extensions: published catalogue (scope=public), caller's own (scope=mine), or every extension (scope=all, moderator)", + "summary": "List extensions: published extension directory (scope=public), caller's own (scope=mine), or every extension (scope=all, moderator)", "security": [ { "Bearer": [] @@ -1564,12 +1840,11 @@ "schema": { "type": "string", "enum": [ - "mod", + "module", "theme", "payment-gateway", "server-manager", "domain-registrar", - "hook", "translation" ] }, @@ -1615,10 +1890,10 @@ "type": "string", "enum": ["public", "mine", "all"], "default": "public", - "description": "public: published catalogue (anonymous allowed). mine: caller's own extensions. all: every extension (moderator only)." + "description": "public: published extension directory (anonymous allowed). mine: caller's own extensions. all: every extension (moderator only)." }, "required": false, - "description": "public: published catalogue (anonymous allowed). mine: caller's own extensions. all: every extension (moderator only).", + "description": "public: published extension directory (anonymous allowed). mine: caller's own extensions. all: every extension (moderator only).", "name": "scope", "in": "query" }, @@ -1648,7 +1923,7 @@ ], "responses": { "200": { - "description": "Extensions matching the scope: catalogue cards for scope=public, owned rows for scope=mine/all", + "description": "Extensions matching the scope: extension cards for scope=public, owned rows for scope=mine/all", "content": { "application/json": { "schema": { @@ -1718,7 +1993,7 @@ }, "responses": { "201": { - "description": "Extension created. It holds the id immediately but stays out of the public catalogue until a moderator approves the revision.", + "description": "Extension created. It holds the id immediately but stays out of the public extension listing until a moderator approves the revision.", "content": { "application/json": { "schema": { @@ -3906,7 +4181,7 @@ "/extensions/{id}/delist": { "post": { "tags": ["Moderation"], - "summary": "Remove a published extension from the public catalogue", + "summary": "Remove a published extension from the public extension listing", "security": [ { "Bearer": [] @@ -3945,7 +4220,7 @@ }, "responses": { "200": { - "description": "Extension removed from the public catalogue. Its content and history are kept, and its owner can still see and edit it.", + "description": "Extension removed from the public extension listing. Its content and history are kept, and its owner can still see and edit it.", "content": { "application/json": { "schema": { @@ -4041,7 +4316,7 @@ "/extensions/{id}/relist": { "post": { "tags": ["Moderation"], - "summary": "Restore a delisted extension to the public catalogue", + "summary": "Restore a delisted extension to the public extension listing", "security": [ { "Bearer": [] @@ -4080,7 +4355,7 @@ }, "responses": { "200": { - "description": "Extension restored to the public catalogue. Content and history unchanged.", + "description": "Extension restored to the public extension listing. Content and history unchanged.", "content": { "application/json": { "schema": { diff --git a/scripts/update-extensions-openapi.ts b/scripts/update-extensions-openapi.ts index 059ed2ba..0bbb6af0 100644 --- a/scripts/update-extensions-openapi.ts +++ b/scripts/update-extensions-openapi.ts @@ -68,10 +68,33 @@ if (!listItemProperties) { if ( Object.hasOwn(listItemProperties, 'readme') || - Object.hasOwn(listItemProperties, 'releases') + Object.hasOwn(listItemProperties, 'releases') || + Object.hasOwn(listItemProperties, 'requires') ) { throw new Error( - 'The fetched OpenAPI document must keep readme and releases out of ExtensionListItem.', + 'The fetched OpenAPI document must keep readme, releases, and requires out of ExtensionListItem.', + ); +} + +const content = schemaProperties(schemas?.ExtensionContent); +const manifestVersion = resolveSchema(content?.manifest_version); +const versions = manifestVersion?.enum; +const isManifestV1 = + (manifestVersion?.type === 'number' || manifestVersion?.type === 'integer') && + Array.isArray(versions) && + versions.length === 1 && + versions[0] === 1; +if ( + !content || + !isManifestV1 || + !Object.hasOwn(content, 'requires') || + !Object.hasOwn(content, 'author') || + !Object.hasOwn(content, 'homepage_url') || + Object.hasOwn(content, 'website') || + asObject(content.license)?.type !== 'string' +) { + throw new Error( + 'The fetched OpenAPI document must expose the manifest v1 extension contract.', ); } diff --git a/src/components/DetailsCard.astro b/src/components/DetailsCard.astro index 11169c4d..264e25a7 100644 --- a/src/components/DetailsCard.astro +++ b/src/components/DetailsCard.astro @@ -1,6 +1,6 @@ --- import type { Extension } from '@/types'; -import { getLatestRelease, repositoryURL } from '@/types'; +import { repositoryURL } from '@/types'; import { isSafeHttpUrl } from '@/lib/safe-url'; import { CircleCheck, Download, GitBranch, Scale, User } from '@lucide/astro'; @@ -9,7 +9,6 @@ interface Props { } const { ext } = Astro.props; -const latest = getLatestRelease(ext); const sourceUrl = repositoryURL(ext.source); type DetailsItem = { @@ -45,20 +44,38 @@ const details: DetailsItem[] = [ name: 'FOSSBilling Version', icon: CircleCheck, color: 'green', - text: latest - ? `FOSSBilling v${latest.min_fossbilling_version} and later` - : 'Unknown version', + text: ext.requires.fossbilling, + }, + { + name: 'PHP Version', + icon: CircleCheck, + color: 'green', + text: ext.requires.php, + }, + { + name: 'Package Author', + icon: User, + color: 'amber', + text: ext.author.name, + link: + ext.author.url && isSafeHttpUrl(ext.author.url) + ? ext.author.url + : undefined, }, { name: 'License', icon: Scale, color: 'blue', - text: ext.license.name, - link: - ext.license.URL && isSafeHttpUrl(ext.license.URL) - ? ext.license.URL - : undefined, + text: ext.license, }, + ...Object.entries(ext.requires.modules ?? {}).map( + ([id, range]): DetailsItem => ({ + name: `Module: ${id}`, + icon: CircleCheck, + color: 'green', + text: range, + }), + ), { name: 'Source Code', icon: GitBranch, diff --git a/src/components/CatalogueSection.astro b/src/components/DirectorySection.astro similarity index 87% rename from src/components/CatalogueSection.astro rename to src/components/DirectorySection.astro index 82bc2ffd..dcfe0562 100644 --- a/src/components/CatalogueSection.astro +++ b/src/components/DirectorySection.astro @@ -1,9 +1,9 @@ --- import ExtensionCard from './ExtensionCard.astro'; import type { ExtensionListResponse } from '@/lib/api/client'; -import { hasNextPage } from '@/lib/catalogue-pagination'; +import { hasNextPage } from '@/lib/directory-pagination'; -// The server-rendered catalogue skeleton that extension-catalogue.ts wires: +// The server-rendered directory skeleton that extension-directory.ts wires: // the grid, the empty state, and the load-more controls it drives. Shared by // the directory index and developer profiles so the data attributes the // script selects on can't drift between the two pages. @@ -37,12 +37,12 @@ const hasNext = pagination ? hasNextPage(pagination) : false; (emptyAsCard ? (

{emptyMessage}

) : ( -

+

{emptyMessage}

))} @@ -62,7 +62,7 @@ const hasNext = pagination ? hasNextPage(pagination) : false;

All extensions loaded.

) : null}

diff --git a/src/components/ExtensionCard.astro b/src/components/ExtensionCard.astro index 4750b50a..d1e67bf1 100644 --- a/src/components/ExtensionCard.astro +++ b/src/components/ExtensionCard.astro @@ -1,5 +1,6 @@ --- import type { ExtensionListItem } from '@/lib/api/client'; +import { extensionIconUrl } from '@/lib/extension-icon'; import { getSignedImageUrl } from '@/lib/signed-image-url'; interface Props { @@ -8,7 +9,7 @@ interface Props { const { ext } = Astro.props; const iconUrl = await getSignedImageUrl( - ext.icon_url, + extensionIconUrl(ext), 'icon', Astro.locals.env.sessionSecret, ); diff --git a/src/components/ExtensionForm.astro b/src/components/ExtensionForm.astro index 6543222a..b4f80685 100644 --- a/src/components/ExtensionForm.astro +++ b/src/components/ExtensionForm.astro @@ -3,7 +3,11 @@ import { EXTENSION_TYPES, SOURCE_TYPES, SPDX_LICENSE_IDS } from '@/types'; import type { Developer, Extension } from '@/types'; import { CircleAlert, SquarePen, ChevronDown } from '@lucide/astro'; import { stripUrlScheme } from '@/lib/url-prefix'; -import { OTHER_LICENSE, type ReleaseDraft } from '@/lib/extension-form'; +import { + OTHER_LICENSE, + type ExtensionFormEcho, + type ReleaseDraft, +} from '@/lib/extension-form'; import { MARKDOWN_SCROLL_CLASS } from '@/lib/revision-diff-shared'; interface Props { @@ -15,7 +19,7 @@ interface Props { // echoNewExtensionFromForm and echoExtensionFromForm). Values only: // passing an echo never flips the form into edit mode, so create keeps // its writable extension_id and create submit semantics. - echo?: Extension; + echo?: ExtensionFormEcho; error?: string | null; submitLabel?: string; cancelHref?: string; @@ -46,7 +50,7 @@ const shown = echo ?? extension; // form with no releases yet (rejected and never resubmitted). const requireRelease = !isEdit || extension!.releases.length === 0; -const existingSpdxId = shown?.license.spdx_id; +const existingSpdxId = shown?.license; // An existing license only lands in the custom bucket when it truly isn't // one of the ids this form offers — covers both genuinely custom/proprietary // licenses and (defensively) a stored spdx_id this deployed list doesn't @@ -127,6 +131,7 @@ const otherSpdxIds = SPDX_LICENSE_IDS.filter((id) => !popularSpdxIds.has(id)); type="text" id="name" name="name" + maxlength={100} required value={shown?.name} /> @@ -141,7 +146,8 @@ const otherSpdxIds = SPDX_LICENSE_IDS.filter((id) => !popularSpdxIds.has(id)); id="extension_id" name="extension_id" required - pattern="[a-z0-9]+(-[a-z0-9]+)*" + pattern="[a-z0-9_\-]+" + maxlength={64} value={shown?.id} disabled={isEdit} /> @@ -175,43 +181,38 @@ const otherSpdxIds = SPDX_LICENSE_IDS.filter((id) => !popularSpdxIds.has(id)); type="text" id="description" name="description" + maxlength={500} required value={shown?.description} />

- +
https://
- - https:// -
@@ -244,6 +245,73 @@ const otherSpdxIds = SPDX_LICENSE_IDS.filter((id) => !popularSpdxIds.has(id));
+
+ Package Author +
+ + +
+
+ + +
+
+
+ Requirements +

+ Requirements for the current version, or the new release added + below. Use version constraints such as ^0.8.9 or >=8.3 <9. +

+
+ + +
+
+ + +
+
+ + +

+ One module-id: constraint per line. +

+
+
+
License
@@ -308,7 +376,7 @@ const otherSpdxIds = SPDX_LICENSE_IDS.filter((id) => !popularSpdxIds.has(id));

- Other / Proprietary + Other / License Expression
@@ -326,7 +394,7 @@ const otherSpdxIds = SPDX_LICENSE_IDS.filter((id) => !popularSpdxIds.has(id)); hidden={!isCustomLicense} > !popularSpdxIds.has(id)); id="license_name_custom" name="license_name_custom" required={isCustomLicense} - value={isCustomLicense ? shown?.license.name : undefined} + value={isCustomLicense ? shown?.license : undefined} /> -
- -
- - https:// - - -
-
@@ -402,7 +451,7 @@ const otherSpdxIds = SPDX_LICENSE_IDS.filter((id) => !popularSpdxIds.has(id)); {extension.releases.map((r) => (
  • v{r.tag} · {r.date} · FOSSBilling{' '} - {r.min_fossbilling_version}+ + {r.requires.fossbilling}
  • ))} @@ -486,21 +535,6 @@ const otherSpdxIds = SPDX_LICENSE_IDS.filter((id) => !popularSpdxIds.has(id)); />
    -
    - - -
    @@ -601,14 +635,6 @@ const otherSpdxIds = SPDX_LICENSE_IDS.filter((id) => !popularSpdxIds.has(id)); diff --git a/src/components/ExtensionHeader.astro b/src/components/ExtensionHeader.astro index 235b74e6..13111083 100644 --- a/src/components/ExtensionHeader.astro +++ b/src/components/ExtensionHeader.astro @@ -1,6 +1,7 @@ --- import type { Extension } from '@/types'; import { ArrowLeft } from '@lucide/astro'; +import { extensionIconUrl } from '@/lib/extension-icon'; import { getSignedImageUrl } from '@/lib/signed-image-url'; interface Props { @@ -9,7 +10,7 @@ interface Props { const { ext } = Astro.props; const iconUrl = await getSignedImageUrl( - ext.icon_url, + extensionIconUrl(ext), 'icon', Astro.locals.env.sessionSecret, ); diff --git a/src/components/FlashToaster.astro b/src/components/FlashToaster.astro index 2a0c4168..d198701f 100644 --- a/src/components/FlashToaster.astro +++ b/src/components/FlashToaster.astro @@ -1,5 +1,5 @@ --- -// Server Island: renders the one-shot flash message so cached catalogue +// Server Island: renders the one-shot flash message so cached directory // pages can still surface per-request toasts. The flash lives in a signed // cookie (src/lib/flash.ts), which is read and cleared here, inside the // island endpoint's own request, so the cookie delete is guaranteed to land diff --git a/src/components/ReleasesTable.astro b/src/components/ReleasesTable.astro index a6eef931..5e7aaafd 100644 --- a/src/components/ReleasesTable.astro +++ b/src/components/ReleasesTable.astro @@ -27,6 +27,9 @@ const releases = sortReleasesDescending(ext.releases); Tag Release date + FOSSBilling + PHP + Modules Links @@ -37,6 +40,13 @@ const releases = sortReleasesDescending(ext.releases); + {release.requires.fossbilling} + {release.requires.php} + + {Object.entries(release.requires.modules ?? {}) + .map(([id, range]) => `${id}: ${range}`) + .join(', ') || '—'} +
    ; + }; releases?: Array<{ tag?: string }>; }; @@ -129,10 +136,11 @@ function renderDiff( const tdField = document.createElement('td'); tdField.className = 'py-1 pr-3 font-medium whitespace-nowrap'; tdField.textContent = label + (isChanged ? ' •' : ''); - // Source and license rows link via their own URL (type-aware for + // Source, license and author rows link via their own URL (type-aware for // sources); URL fields link via their own value. Everything else // renders as text. - const linkedField = field === 'source' || field === 'license'; + const linkedField = + field === 'source' || field === 'license' || field === 'author'; const oldHref = linkedField ? fieldUrl(field, published) : URL_FIELDS.has(field) @@ -238,7 +246,7 @@ export function initRevisionQueue(): void { label.textContent = FIELD_LABELS[field]; const value = fieldDisplay(field, revision); const href = - field === 'source' || field === 'license' + field === 'source' || field === 'license' || field === 'author' ? fieldUrl(field, revision) : URL_FIELDS.has(field) ? value diff --git a/src/lib/api/client.ts b/src/lib/api/client.ts index 8e855870..07fa4d19 100644 --- a/src/lib/api/client.ts +++ b/src/lib/api/client.ts @@ -76,7 +76,7 @@ type ListFilters = Pick< 'type' | 'developer_id' | 'status' | 'q' | 'limit' | 'cursor' >; -export type ExtensionCatalogueFilters = Pick< +export type ExtensionDirectoryFilters = Pick< ExtensionListQuery, 'type' | 'developer_id' | 'limit' | 'cursor' >; @@ -101,7 +101,7 @@ export type RevisionStatus = Exclude; export type ModerationCounts = GetModerationCountsResponse['result']; // The v2 list/detail reads are role-aware unions. These wrappers pin a scope -// (public catalogue vs mine/all) or a transport (anonymous vs authenticated), +// (public directory vs mine/all) or a transport (anonymous vs authenticated), // so they narrow to the projection that scope always returns. export interface ExtensionListResponse { result: ExtensionListItem[]; @@ -367,7 +367,7 @@ function requireOwnedExtension( } // Builds the query for the role-aware extension list reads. `scope` selects -// the projection (undefined = public catalogue); callers pass only the +// the projection (undefined = public directory); callers pass only the // filters their surface uses. function listQuery( scope: 'mine' | 'all' | undefined, @@ -397,13 +397,13 @@ function listQuery( return query; } -// The three anonymous catalogue reads below are edge-cached: their results +// The three anonymous directory reads below are edge-cached: their results // only change when a moderator approves a revision, so a short TTL absorbs // most repeat traffic without any invalidation protocol. Authenticated // reads (scope=mine/all) must never pass through this cache. export async function listExtensions( env: ApplicationEnv, - filters: ExtensionCatalogueFilters = {}, + filters: ExtensionDirectoryFilters = {}, ): Promise { const query = listQuery(undefined, filters); return cachedEdgeRead( diff --git a/src/lib/api/generated/extensions-v2/index.ts b/src/lib/api/generated/extensions-v2/index.ts index 717b5951..d1265da2 100644 --- a/src/lib/api/generated/extensions-v2/index.ts +++ b/src/lib/api/generated/extensions-v2/index.ts @@ -147,7 +147,7 @@ export type { GetUsersMeErrors, GetUsersMeResponse, GetUsersMeResponses, - License, + ManifestRequirements, ModeratorCorrect, OwnedDeveloperProfile, OwnedExtension, diff --git a/src/lib/api/generated/extensions-v2/sdk.gen.ts b/src/lib/api/generated/extensions-v2/sdk.gen.ts index ad605175..2dd2862e 100644 --- a/src/lib/api/generated/extensions-v2/sdk.gen.ts +++ b/src/lib/api/generated/extensions-v2/sdk.gen.ts @@ -141,7 +141,7 @@ export type Options< }; /** - * List extensions: published catalogue (scope=public), caller's own (scope=mine), or every extension (scope=all, moderator) + * List extensions: published extension directory (scope=public), caller's own (scope=mine), or every extension (scope=all, moderator) */ export const getExtensions = ( options?: Options, @@ -603,7 +603,7 @@ export const postExtensionsByIdRevisionsByRevisionIdReject = < }); /** - * Remove a published extension from the public catalogue + * Remove a published extension from the public extension listing */ export const postExtensionsByIdDelist = ( options: Options, @@ -627,7 +627,7 @@ export const postExtensionsByIdDelist = ( }); /** - * Restore a delisted extension to the public catalogue + * Restore a delisted extension to the public extension listing */ export const postExtensionsByIdRelist = ( options: Options, diff --git a/src/lib/api/generated/extensions-v2/types.gen.ts b/src/lib/api/generated/extensions-v2/types.gen.ts index d6ef61ac..cdabaefb 100644 --- a/src/lib/api/generated/extensions-v2/types.gen.ts +++ b/src/lib/api/generated/extensions-v2/types.gen.ts @@ -10,21 +10,25 @@ export type UnifiedExtensionListResponse = { }; export type ExtensionListItem = { + manifest_version: 1; type: - | 'mod' + | 'module' | 'theme' | 'payment-gateway' | 'server-manager' | 'domain-registrar' - | 'hook' | 'translation'; name: string; description: string; + author: { + name: string; + url?: string; + }; /** * Null when a legacy URL exceeds the card length bound */ - website: string | null; - license: License; + homepage_url?: string | null; + license: string; icon_url?: string; source: Repository; version: string; @@ -36,15 +40,6 @@ export type ExtensionListItem = { developer: PublicDeveloper; }; -export type License = { - name: string; - /** - * A current SPDX license identifier (https://spdx.org/licenses/). Omitted for custom or proprietary licenses. - */ - spdx_id?: string; - URL?: string; -}; - export type Repository = { type: 'github' | 'gitlab' | 'custom'; repo: string; @@ -64,21 +59,25 @@ export type OwnedExtensionListItem = { id: string; developer: PublicDeveloper; published: { + manifest_version: 1; type: - | 'mod' + | 'module' | 'theme' | 'payment-gateway' | 'server-manager' | 'domain-registrar' - | 'hook' | 'translation'; name: string; description: string; + author: { + name: string; + url?: string; + }; /** * Null when a legacy URL exceeds the card length bound */ - website: string | null; - license: License; + homepage_url?: string | null; + license: string; icon_url?: string; source: Repository; version: string; @@ -138,32 +137,50 @@ export type ExtensionDetailResponse = { }; export type Extension = ExtensionContent & { + name?: string; + description?: string; + license?: string; + icon_url?: string; + version?: string; id: string; developer: PublicDeveloper; }; +export type ManifestRequirements = { + fossbilling: string; + php: string; + modules?: { + [key: string]: string; + }; +}; + export type Release = { tag: string; date: string; download_url: string; changelog_url?: string; - min_fossbilling_version: string; + requires: ManifestRequirements; }; export type ExtensionContent = { + manifest_version: 1; type: - | 'mod' + | 'module' | 'theme' | 'payment-gateway' | 'server-manager' | 'domain-registrar' - | 'hook' | 'translation'; name: string; description: string; + author: { + name: string; + url?: string; + }; + requires: ManifestRequirements; releases: Array; - website: string; - license: License; + homepage_url?: string; + license: string; icon_url?: string; readme: string; source: Repository; @@ -174,14 +191,20 @@ export type ExtensionContent = { export type OwnedExtension = OwnedExtensionListItem & { published?: ExtensionContent & ({ + name?: string; + description?: string; releases?: Array< Release & { /** * At most 100 Unicode code points in historical content */ tag?: string; + min_fossbilling_version?: string; } >; + license?: string; + icon_url?: string; + version?: string; } | null); pending_revision?: PendingRevisionRef & ({ @@ -190,47 +213,67 @@ export type OwnedExtension = OwnedExtensionListItem & { }; export type StoredExtensionContent = { + manifest_version?: 1; type?: - | 'mod' + | 'module' | 'theme' | 'payment-gateway' | 'server-manager' | 'domain-registrar' - | 'hook' - | 'translation'; + | 'translation' + | 'mod' + | 'hook'; name?: string; description?: string; + author?: { + name: string; + url?: string; + }; + requires?: ManifestRequirements; releases?: Array< Release & { /** * At most 100 Unicode code points in historical content */ tag?: string; + min_fossbilling_version?: string; } >; - website?: string; - license?: License; - icon_url?: string; + homepage_url?: string; + license?: + | string + | { + name: string; + spdx_id?: string; + URL?: string; + }; + icon_url?: string | string; readme?: string; source?: Repository; version?: string; download_url?: string; + website?: string; }; export type ExtensionCreate = { + manifest_version: 1; type: - | 'mod' + | 'module' | 'theme' | 'payment-gateway' | 'server-manager' | 'domain-registrar' - | 'hook' | 'translation'; name: string; description: string; + author: { + name: string; + url?: string; + }; + requires: ManifestRequirements; releases: Array; - website: string; - license: License; + homepage_url?: string; + license: string; icon_url?: string; readme: string; source: Repository; @@ -240,19 +283,24 @@ export type ExtensionCreate = { }; export type ExtensionUpdate = { + manifest_version: 1; type: - | 'mod' + | 'module' | 'theme' | 'payment-gateway' | 'server-manager' | 'domain-registrar' - | 'hook' | 'translation'; name: string; description: string; + author: { + name: string; + url?: string; + }; + requires: ManifestRequirements; releases: Array; - website: string; - license: License; + homepage_url?: string; + license: string; icon_url?: string; readme: string; source: Repository; @@ -392,19 +440,24 @@ export type DelistReason = { }; export type ModeratorCorrect = { + manifest_version: 1; type: - | 'mod' + | 'module' | 'theme' | 'payment-gateway' | 'server-manager' | 'domain-registrar' - | 'hook' | 'translation'; name: string; description: string; + author: { + name: string; + url?: string; + }; + requires: ManifestRequirements; releases: Array; - website: string; - license: License; + homepage_url?: string; + license: string; icon_url?: string; readme: string; source: Repository; @@ -465,12 +518,11 @@ export type GetExtensionsData = { path?: never; query?: { type?: - | 'mod' + | 'module' | 'theme' | 'payment-gateway' | 'server-manager' | 'domain-registrar' - | 'hook' | 'translation'; /** * Public scope only @@ -482,7 +534,7 @@ export type GetExtensionsData = { */ cursor?: string; /** - * public: published catalogue (anonymous allowed). mine: caller's own extensions. all: every extension (moderator only). + * public: published extension directory (anonymous allowed). mine: caller's own extensions. all: every extension (moderator only). */ scope?: 'public' | 'mine' | 'all'; /** @@ -520,7 +572,7 @@ export type GetExtensionsError = GetExtensionsErrors[keyof GetExtensionsErrors]; export type GetExtensionsResponses = { /** - * Extensions matching the scope: catalogue cards for scope=public, owned rows for scope=mine/all + * Extensions matching the scope: extension cards for scope=public, owned rows for scope=mine/all */ 200: UnifiedExtensionListResponse; }; @@ -575,7 +627,7 @@ export type PostExtensionsError = export type PostExtensionsResponses = { /** - * Extension created. It holds the id immediately but stays out of the public catalogue until a moderator approves the revision. + * Extension created. It holds the id immediately but stays out of the public extension listing until a moderator approves the revision. */ 201: { result: { @@ -1635,7 +1687,7 @@ export type PostExtensionsByIdDelistError = export type PostExtensionsByIdDelistResponses = { /** - * Extension removed from the public catalogue. Its content and history are kept, and its owner can still see and edit it. + * Extension removed from the public extension listing. Its content and history are kept, and its owner can still see and edit it. */ 200: { result: { @@ -1698,7 +1750,7 @@ export type PostExtensionsByIdRelistError = export type PostExtensionsByIdRelistResponses = { /** - * Extension restored to the public catalogue. Content and history unchanged. + * Extension restored to the public extension listing. Content and history unchanged. */ 200: { result: { diff --git a/src/lib/cache-invalidate.ts b/src/lib/cache-invalidate.ts index 7c8fa894..7fb9a625 100644 --- a/src/lib/cache-invalidate.ts +++ b/src/lib/cache-invalidate.ts @@ -1,22 +1,22 @@ import type { APIContext } from 'astro'; import { markEdgeCachePurged } from './cache'; +import { EXTENSIONS_CACHE_TAGS } from './cache-tags'; -// Shared cache-tag vocabulary. astro.config.mjs's routeRules tag cached +// Shared cache-tag vocabulary. astro.config.ts's routeRules tag cached // pages with these, and both purge paths — the dashboard helpers below and // POST /api/revalidate — purge them. 'developers' currently tags no route // (developer pages are deliberately uncached — see routeRules) but is kept // accepted because the api worker sends it; purging a tag no URL carries is // a no-op, and it is reserved for any future developer-surface caching. -export const CATALOGUE_CACHE_TAGS = ['catalogue', 'developers']; -// Purging both tags together is a single CDN purge call, and every catalogue +// Purging both tags together is a single CDN purge call, and every directory // mutation touches at least one of the two surfaces. // // Mutation endpoints call this fire-and-forget right after a successful // write: the CDN purge runs on waitUntil so the redirect is not delayed, and -// route-cached catalogue pages re-render on the next request — dashboard +// route-cached directory pages re-render on the next request — dashboard // changes become visible within a second or two instead of after a TTL. -export function purgeCatalogue(context: APIContext): void { +export function purgeDirectory(context: APIContext): void { if (!context.cache.enabled) return; let purge: Promise; @@ -24,7 +24,7 @@ export function purgeCatalogue(context: APIContext): void { // Same-isolate data-cache entries must not repopulate re-renders with // pre-purge data (CDN tag purges cannot reach the per-colo Cache API). markEdgeCachePurged(); - purge = context.cache.invalidate({ tags: [...CATALOGUE_CACHE_TAGS] }); + purge = context.cache.invalidate({ tags: [...EXTENSIONS_CACHE_TAGS] }); } catch (error) { // A synchronous failure here must never fail the mutation that already // succeeded; the route-rule windows bound any staleness. diff --git a/src/lib/cache-tags.ts b/src/lib/cache-tags.ts new file mode 100644 index 00000000..9877aed4 --- /dev/null +++ b/src/lib/cache-tags.ts @@ -0,0 +1,2 @@ +export const EXTENSIONS_CACHE_TAG = 'extensions'; +export const EXTENSIONS_CACHE_TAGS = [EXTENSIONS_CACHE_TAG, 'developers']; diff --git a/src/lib/cache.ts b/src/lib/cache.ts index bba4998a..51de0533 100644 --- a/src/lib/cache.ts +++ b/src/lib/cache.ts @@ -1,11 +1,11 @@ // Edge-cache helpers for public, user-independent responses. Cloudflare // does not automatically cache Worker-generated responses, so hot public // reads are stored through the Cache API (per-colo, isolate-independent) -// with a short TTL: catalogue content only changes when a moderator +// with a short TTL: directory content only changes when a moderator // approves a revision, so a minute of staleness trades negligible // invocation and API-subrequest cost for most repeat traffic. -const CATALOGUE_CACHE_TTL_SECONDS = 60; +const DIRECTORY_CACHE_TTL_SECONDS = 60; // Per-isolate purge marker. CDN tag purges cannot reach the per-colo Cache // API entries cached here, so a page re-rendered right after a purge could @@ -113,7 +113,7 @@ export async function cachedEdgeRead( new Response(JSON.stringify({ writtenAt: missStartedAt, value }), { headers: { 'content-type': 'application/json', - 'cache-control': `public, s-maxage=${CATALOGUE_CACHE_TTL_SECONDS}`, + 'cache-control': `public, s-maxage=${DIRECTORY_CACHE_TTL_SECONDS}`, }, }), ); diff --git a/src/lib/catalogue-filters.ts b/src/lib/directory-filters.ts similarity index 76% rename from src/lib/catalogue-filters.ts rename to src/lib/directory-filters.ts index 0d12e65f..5dc5c754 100644 --- a/src/lib/catalogue-filters.ts +++ b/src/lib/directory-filters.ts @@ -1,19 +1,19 @@ -import type { ExtensionCatalogueFilters } from '@/lib/api/client'; +import type { ExtensionDirectoryFilters } from '@/lib/api/client'; import { isExtensionType } from '@/types'; -// Query parsing shared by the catalogue JSON API (/api/extensions) and the +// Query parsing shared by the directory JSON API (/api/extensions) and the // load-more fragment (/api/extensions/cards), so the two endpoints always // accept exactly the same filters. -export function parseCatalogueFilters(params: URLSearchParams): +export function parseDirectoryFilters(params: URLSearchParams): | { - filters: ExtensionCatalogueFilters; + filters: ExtensionDirectoryFilters; error: null; } | { filters: null; error: string; } { - const filters: ExtensionCatalogueFilters = {}; + const filters: ExtensionDirectoryFilters = {}; const type = params.get('type'); if (type !== null && type !== '' && !isExtensionType(type)) { return { filters: null, error: 'The extension type filter is invalid.' }; diff --git a/src/lib/catalogue-pagination.ts b/src/lib/directory-pagination.ts similarity index 66% rename from src/lib/catalogue-pagination.ts rename to src/lib/directory-pagination.ts index 2bc3d4bb..9d54ae9a 100644 --- a/src/lib/catalogue-pagination.ts +++ b/src/lib/directory-pagination.ts @@ -1,25 +1,25 @@ import type { ExtensionListItem, ExtensionListResponse } from './api/client'; -type CatalogueItem = { +type DirectoryItem = { id: string; }; -type CataloguePage = { +type DirectoryPage = { result: Item[]; pagination: ExtensionListResponse['pagination']; }; -type CataloguePageFilters = { +type DirectoryPageFilters = { type?: string; developer_id?: string; limit?: number; }; -export type CataloguePageRequest = CataloguePageFilters & { +export type DirectoryPageRequest = DirectoryPageFilters & { cursor: string; }; -type CataloguePagerState = { +type DirectoryPagerState = { items: Item[]; nextCursor: string | null; hasMore: boolean; @@ -27,16 +27,16 @@ type CataloguePagerState = { error: unknown | null; }; -type CataloguePageLoader = ( - request: CataloguePageRequest, -) => Promise>; +type DirectoryPageLoader = ( + request: DirectoryPageRequest, +) => Promise>; -export function createCataloguePager< - Item extends CatalogueItem = ExtensionListItem, +export function createDirectoryPager< + Item extends DirectoryItem = ExtensionListItem, >( - firstPage: CataloguePage, - filters: CataloguePageFilters, - loadPage: CataloguePageLoader, + firstPage: DirectoryPage, + filters: DirectoryPageFilters, + loadPage: DirectoryPageLoader, initialIds: string[] = [], ) { let state = stateFromPage(firstPage); @@ -44,14 +44,14 @@ export function createCataloguePager< ...initialIds.map((id) => id.toLowerCase()), ...state.items.map((item) => item.id.toLowerCase()), ]); - let inFlight: Promise> | null = null; + let inFlight: Promise> | null = null; return { - getState(): CataloguePagerState { + getState(): DirectoryPagerState { return state; }, - loadNextPage(): Promise> { + loadNextPage(): Promise> { if (inFlight) { return inFlight; } @@ -60,7 +60,7 @@ export function createCataloguePager< return Promise.resolve(state); } - const request: CataloguePageRequest = { + const request: DirectoryPageRequest = { ...filters, cursor: state.nextCursor, }; @@ -101,15 +101,15 @@ export function createCataloguePager< }; } -export function createCataloguePagerFromIds< - Item extends CatalogueItem = ExtensionListItem, +export function createDirectoryPagerFromIds< + Item extends DirectoryItem = ExtensionListItem, >( initialIds: string[], - pagination: CataloguePage['pagination'], - filters: CataloguePageFilters, - loadPage: CataloguePageLoader, + pagination: DirectoryPage['pagination'], + filters: DirectoryPageFilters, + loadPage: DirectoryPageLoader, ) { - return createCataloguePager( + return createDirectoryPager( { result: [], pagination }, filters, loadPage, @@ -117,9 +117,9 @@ export function createCataloguePagerFromIds< ); } -export function stateFromPage( - page: CataloguePage, -): CataloguePagerState { +export function stateFromPage( + page: DirectoryPage, +): DirectoryPagerState { return { items: [...page.result], nextCursor: page.pagination.next_cursor, @@ -129,11 +129,11 @@ export function stateFromPage( }; } -export function appendPage( - state: CataloguePagerState, - page: CataloguePage, +export function appendPage( + state: DirectoryPagerState, + page: DirectoryPage, knownIds = new Set(state.items.map((item) => item.id.toLowerCase())), -): CataloguePagerState { +): DirectoryPagerState { const newItems = page.result.filter((item) => { const key = item.id.toLowerCase(); if (knownIds.has(key)) { @@ -153,7 +153,7 @@ export function appendPage( } // Whether another page exists at all. Shared with the server-rendered -// catalogue wrappers, whose data-has-more attribute seeds the client pager. +// directory wrappers, whose data-has-more attribute seeds the client pager. export function hasNextPage( pagination: ExtensionListResponse['pagination'], ): boolean { diff --git a/src/lib/extension-form.ts b/src/lib/extension-form.ts index 705873ad..9fe00cfd 100644 --- a/src/lib/extension-form.ts +++ b/src/lib/extension-form.ts @@ -1,47 +1,71 @@ +import { isPackageIconPath } from './package-icon'; import { isExtensionType, isSourceType, SPDX_LICENSE_IDS } from '@/types'; import type { Extension, Release } from '@/types'; import type { ExtensionCreate, ExtensionUpdate } from '@/lib/api/client'; import { formString } from './form'; import { withHttpsScheme } from './url-prefix'; +export type ExtensionFormEcho = Extension & { moduleRequirementsInput: string }; + // Thrown for form-level validation failures that should be shown to the // user, distinct from ApiRequestError (the api rejecting an otherwise // well-formed payload) — see the try/catch in new.astro/edit.astro. export class ExtensionValidationError extends Error {} -// "Other / Proprietary" is a form-only sentinel, never a real spdx_id value -// — buildLicense() reads it back out of license_spdx_id to decide whether -// license_name_custom (vs. the spdx_id itself) becomes license.name. The -// single export here is what ExtensionForm.astro and edit.astro both use, -// rather than each hand-copying the string. +// The combobox offers SPDX identifiers; Other also accepts compound expressions. export const OTHER_LICENSE = 'other'; -// The License field pair: a