import Joi from 'joi' import { BaseJsonService } from '../index.js' import { nonNegativeInteger } from '../validators.js' const packageMetricsSchema = Joi.object({ downloads: nonNegativeInteger, rating_score: nonNegativeInteger, latest_version: Joi.string().required(), }) const description = ` The Thunderstore badges require a package's namespace and name. Everything can be discerned from your package's URL. Thunderstore package URLs have a mostly consistent format: https://thunderstore.io/c/[community]/p/[namespace]/[packageName] For example: https://thunderstore.io/c/lethal-company/p/notnotnotswipez/MoreCompany/. :::info[Risk Of Rain 2] The 'default community', Risk of Rain 2, has an alternative URL: https://thunderstore.io/package/[namespace]/[packageName] ::: :::info[Subdomain Communities] Some communities use a 'subdomain' alternative URL, for example, Valheim: https://valheim.thunderstore.io/package/[namespace]/[packageName] ::: ` /** * Services which query Thunderstore endpoints should extend BaseThunderstoreService * * @abstract */ class BaseThunderstoreService extends BaseJsonService { static thunderstoreGreen = '23FFB0' /** * Fetches package metrics from the Thunderstore API. * * @param {object} pkg - Package specifier * @param {string} pkg.namespace - the package namespace * @param {string} pkg.packageName - the package name * @returns {Promise} - Promise containing validated package metrics */ async fetchPackageMetrics({ namespace, packageName }) { return this._requestJson({ schema: packageMetricsSchema, url: `https://thunderstore.io/api/v1/package-metrics/${namespace}/${packageName}`, }) } } export { BaseThunderstoreService, description }