diff --git a/package-lock.json b/package-lock.json index 52b2234..9d0565f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@sentry/cloudflare": "^10.40.0", "algoliasearch": "^5.49.1", - "hono": "^4.12.4", + "hono": "^4.12.7", "is-deflate": "^1.0.0", "is-gzip": "^2.0.0", "pako": "^2.1.0", @@ -3474,9 +3474,9 @@ } }, "node_modules/hono": { - "version": "4.12.4", - "resolved": "https://registry.npmjs.org/hono/-/hono-4.12.4.tgz", - "integrity": "sha512-ooiZW1Xy8rQ4oELQ++otI2T9DsKpV0M6c6cO6JGx4RTfav9poFFLlet9UMXHZnoM1yG0HWGlQLswBGX3RZmHtg==", + "version": "4.12.7", + "resolved": "https://registry.npmjs.org/hono/-/hono-4.12.7.tgz", + "integrity": "sha512-jq9l1DM0zVIvsm3lv9Nw9nlJnMNPOcAtsbsgiUhWcFzPE99Gvo6yRTlszSLLYacMeQ6quHD6hMfId8crVHvexw==", "engines": { "node": ">=16.9.0" } @@ -7020,9 +7020,9 @@ "dev": true }, "hono": { - "version": "4.12.4", - "resolved": "https://registry.npmjs.org/hono/-/hono-4.12.4.tgz", - "integrity": "sha512-ooiZW1Xy8rQ4oELQ++otI2T9DsKpV0M6c6cO6JGx4RTfav9poFFLlet9UMXHZnoM1yG0HWGlQLswBGX3RZmHtg==" + "version": "4.12.7", + "resolved": "https://registry.npmjs.org/hono/-/hono-4.12.7.tgz", + "integrity": "sha512-jq9l1DM0zVIvsm3lv9Nw9nlJnMNPOcAtsbsgiUhWcFzPE99Gvo6yRTlszSLLYacMeQ6quHD6hMfId8crVHvexw==" }, "html-entities": { "version": "2.6.0", diff --git a/package.json b/package.json index 4d8c8bd..cbfd932 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "dependencies": { "@sentry/cloudflare": "^10.40.0", "algoliasearch": "^5.49.1", - "hono": "^4.12.4", + "hono": "^4.12.7", "is-deflate": "^1.0.0", "is-gzip": "^2.0.0", "pako": "^2.1.0", diff --git a/src/routes/library.ts b/src/routes/library.ts index a30290f..67f3391 100644 --- a/src/routes/library.ts +++ b/src/routes/library.ts @@ -35,21 +35,25 @@ const whitelisted = (file: string) => * @param ctx Request context. */ const handleGetLibraryVersion = async (ctx: Context) => { + // Validate params (Hono already did this, but this keeps TypeScript happy) + const params = ctx.req.param(); + if (!params.library || !params.version) + throw new Error('Missing library or version param'); + // Get the library - const lib = await library(ctx.req.param('library')).catch((err) => { + const lib = await library(params.library).catch((err) => { if (err.status === 404) return; throw err; }); if (!lib) return notFound(ctx, 'Library'); // Get the version - const version = await libraryVersion( - lib.name, - ctx.req.param('version'), - ).catch((err) => { - if (err.status === 404) return; - throw err; - }); + const version = await libraryVersion(lib.name, params.version).catch( + (err) => { + if (err.status === 404) return; + throw err; + }, + ); if (!version) return notFound(ctx, 'Version'); // Generate the initial filtered response (without SRI data) @@ -57,7 +61,7 @@ const handleGetLibraryVersion = async (ctx: Context) => { const response: LibraryVersionResponse = filter( { name: lib.name, - version: ctx.req.param('version'), + version: params.version, rawFiles: version, files: version.filter(whitelisted), }, @@ -69,11 +73,11 @@ const handleGetLibraryVersion = async (ctx: Context) => { // Get SRI for version const latestSriData = await libraryVersionSri( lib.name, - ctx.req.param('version'), + params.version, ).catch(() => ({})); response.sri = sriForVersion( lib.name, - ctx.req.param('version'), + params.version, version, latestSriData, ); @@ -93,8 +97,12 @@ const handleGetLibraryVersion = async (ctx: Context) => { * @param ctx Request context. */ const handleGetLibrary = async (ctx: Context) => { + // Validate params (Hono already did this, but this keeps TypeScript happy) + const params = ctx.req.param(); + if (!params.library) throw new Error('Missing library or version param'); + // Get the library - const lib = await library(ctx.req.param('library')).catch((err) => { + const lib = await library(params.library).catch((err) => { if (err.status === 404) return; throw err; });