Skip to content

Commit

Permalink
[pub] Use official version endpoint for pub-service (#9802)
Browse files Browse the repository at this point in the history
* Use official version endpoint for pub-service

* run prettier

* Update schema

* make services a required property

---------

Co-authored-by: chris48s <git@chris-shaw.dev>
  • Loading branch information
sigurdm and chris48s authored Dec 12, 2023
1 parent 78f8324 commit 407fe39
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions services/pub/pub.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { BaseJsonService, redirector, pathParam, queryParam } from '../index.js'
import { baseDescription } from './pub-common.js'

const schema = Joi.object({
versions: Joi.array().items(Joi.string()).required(),
versions: Joi.array()
.items(Joi.object({ version: Joi.string().required() }))
.required(),
}).required()

const queryParamSchema = Joi.object({
Expand Down Expand Up @@ -45,14 +47,14 @@ class PubVersion extends BaseJsonService {
async fetch({ packageName }) {
return this._requestJson({
schema,
url: `https://pub.dartlang.org/packages/${packageName}.json`,
url: `https://pub.dev/api/packages/${packageName}`,
})
}

async handle({ packageName }, queryParams) {
const data = await this.fetch({ packageName })
const includePre = queryParams.include_prereleases !== undefined
const versions = data.versions
const versions = data.versions.map(x => x.version)
const version = latest(versions, { pre: includePre })
return renderVersionBadge({ version })
}
Expand Down

0 comments on commit 407fe39

Please sign in to comment.