-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy path[...pkg].get.ts
More file actions
25 lines (23 loc) · 695 Bytes
/
[...pkg].get.ts
File metadata and controls
25 lines (23 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import type { JsrPackageInfo } from '#shared/types/jsr'
/**
* Check if an npm package exists on JSR.
*
* GET /api/jsr/:pkg
*
* @example GET /api/jsr/@std/fs → { exists: true, scope: "std", name: "fs", ... }
* @example GET /api/jsr/lodash → { exists: false }
*/
export default defineCachedEventHandler<Promise<JsrPackageInfo>>(
async event => {
const pkgPath = getRouterParam(event, 'pkg')
if (!pkgPath) {
throw createError({ statusCode: 400, message: 'Package name is required' })
}
return await fetchJsrPackageInfo(pkgPath)
},
{
maxAge: 60 * 60, // 1 hour
name: 'api-jsr-package',
getKey: event => getRouterParam(event, 'pkg') ?? '',
},
)