Files
shields/services/cookbook/cookbook.service.js
chris48s 504015c0ba migrate hapi/joi to joi (#5624)
* update joi + joi-extension-semver

* @hapi/joi --> joi

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2020-09-30 17:51:02 +00:00

33 lines
906 B
JavaScript

'use strict'
const Joi = require('joi')
const { renderVersionBadge } = require('../version')
const { BaseJsonService } = require('..')
const schema = Joi.object({ version: Joi.string().required() }).required()
module.exports = class Cookbook extends BaseJsonService {
static category = 'version'
static route = { base: 'cookbook/v', pattern: ':cookbook' }
static examples = [
{
title: 'Chef cookbook',
namedParams: { cookbook: 'chef-sugar' },
staticPreview: renderVersionBadge({ version: '5.0.0' }),
},
]
static defaultBadgeData = { label: 'cookbook' }
async fetch({ cookbook }) {
const url = `https://supermarket.getchef.com/api/v1/cookbooks/${cookbook}/versions/latest`
return this._requestJson({ schema, url })
}
async handle({ cookbook }) {
const { version } = await this.fetch({ cookbook })
return renderVersionBadge({ version })
}
}