1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00
shields/services/npm/npm-last-update.service.js
chris48s c567f6cde4
Migrate to ESLint 9 (#10762)
* update ESLint related packages

* migrate to flat config format

* Fix prefer-const error

Fixes
'overrideLogoSize' is never reassigned. Use 'const' instead

* remove irrelevant eslint-disable comment

These comments came from a swizzled upstream
component but never did anything in our codebase.

ESLint 9 does not allow disable comments
for rules that are not registered.

* remove irrelevant eslint-disable comments

These were here because in the past we were applying
mocha lint rules to files which contained no tests

ESLint 9 now flags eslint-disable comments
that aren't doing anythings

* remove irrelevant eslint-disable comment

ESLint 9 now flags eslint-disable comments
that aren't doing anything

* there are no .tsx files in our code any more

* include .mjs files in linting and formatting

* update sort-class-members rule for openApi property

and update the handful of files violating it
2024-12-31 13:54:25 +00:00

120 lines
2.8 KiB
JavaScript

import Joi from 'joi'
import { NotFound, pathParam, queryParam } from '../index.js'
import { renderDateBadge } from '../date.js'
import NpmBase, {
packageNameDescription,
queryParamSchema,
} from './npm-base.js'
const fullSchema = Joi.object({
time: Joi.object()
.pattern(Joi.string().required(), Joi.string().required())
.required(),
'dist-tags': Joi.object()
.pattern(Joi.string().required(), Joi.string().required())
.required(),
}).required()
const abbreviatedSchema = Joi.object({
modified: Joi.string().required(),
}).required()
export class NpmLastUpdateWithTag extends NpmBase {
static category = 'activity'
static route = {
base: 'npm/last-update',
pattern: ':scope(@[^/]+)?/:packageName/:tag',
queryParamSchema,
}
static openApi = {
'/npm/last-update/{packageName}/{tag}': {
get: {
summary: 'NPM Last Update (with dist tag)',
parameters: [
pathParam({
name: 'packageName',
example: 'verdaccio',
packageNameDescription,
}),
pathParam({
name: 'tag',
example: 'next-8',
}),
queryParam({
name: 'registry_uri',
example: 'https://registry.npmjs.com',
}),
],
},
},
}
static defaultBadgeData = { label: 'last updated' }
async handle(namedParams, queryParams) {
const { scope, packageName, tag, registryUrl } =
this.constructor.unpackParams(namedParams, queryParams)
const packageData = await this.fetch({
registryUrl,
scope,
packageName,
schema: fullSchema,
})
const tagVersion = packageData['dist-tags'][tag]
if (!tagVersion) {
throw new NotFound({ prettyMessage: 'tag not found' })
}
return renderDateBadge(packageData.time[tagVersion])
}
}
export class NpmLastUpdate extends NpmBase {
static category = 'activity'
static route = this.buildRoute('npm/last-update', { withTag: false })
static openApi = {
'/npm/last-update/{packageName}': {
get: {
summary: 'NPM Last Update',
parameters: [
pathParam({
name: 'packageName',
example: 'verdaccio',
packageNameDescription,
}),
queryParam({
name: 'registry_uri',
example: 'https://registry.npmjs.com',
}),
],
},
},
}
static defaultBadgeData = { label: 'last updated' }
async handle(namedParams, queryParams) {
const { scope, packageName, registryUrl } = this.constructor.unpackParams(
namedParams,
queryParams,
)
const packageData = await this.fetch({
registryUrl,
scope,
packageName,
schema: abbreviatedSchema,
abbreviated: true,
})
return renderDateBadge(packageData.modified)
}
}