9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
50 lines
2.5 KiB
JavaScript
50 lines
2.5 KiB
JavaScript
// maven artifact — fetch a Maven Central artifact's recent version history.
|
|
//
|
|
// Hits Solr's `gav` core (`q=g:<groupId>+AND+a:<artifactId>` with
|
|
// `core=gav`) which returns one row per published version, newest first.
|
|
// Returns the agent-useful projection: each version + publish timestamp +
|
|
// packaging. If a specific `:version` is supplied, only that version is
|
|
// returned.
|
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { EmptyResultError } from '@jackwener/opencli/errors';
|
|
import { MAVEN_BASE, mavenFetch, epochMsToIso, requireBoundedInt, requireCoord } from './utils.js';
|
|
|
|
cli({
|
|
site: 'maven',
|
|
name: 'artifact',
|
|
access: 'read',
|
|
description: 'Fetch a Maven Central artifact\'s version history (groupId:artifactId[:version])',
|
|
domain: 'search.maven.org',
|
|
strategy: Strategy.PUBLIC,
|
|
browser: false,
|
|
args: [
|
|
{ name: 'coordinate', positional: true, required: true, help: 'Maven coord "groupId:artifactId" or "groupId:artifactId:version"' },
|
|
{ name: 'limit', type: 'int', default: 20, help: 'Max versions (1-200, ignored when version is pinned)' },
|
|
],
|
|
columns: ['groupId', 'artifactId', 'version', 'packaging', 'publishedAt', 'tags', 'url'],
|
|
func: async (args) => {
|
|
const { groupId, artifactId, version } = requireCoord(args.coordinate);
|
|
const limit = requireBoundedInt(args.limit, 20, 200);
|
|
const filters = [`g:${groupId}`, `a:${artifactId}`];
|
|
if (version) filters.push(`v:${version}`);
|
|
const q = filters.join(' AND ');
|
|
const rows = version ? 1 : limit;
|
|
const url = `${MAVEN_BASE}?q=${encodeURIComponent(q)}&core=gav&rows=${rows}&wt=json`;
|
|
const body = await mavenFetch(url, 'maven artifact');
|
|
const docs = Array.isArray(body?.response?.docs) ? body.response.docs : [];
|
|
const coordLabel = version ? `${groupId}:${artifactId}:${version}` : `${groupId}:${artifactId}`;
|
|
if (!docs.length) {
|
|
throw new EmptyResultError('maven artifact', `Maven Central has no published versions for ${coordLabel}.`);
|
|
}
|
|
return docs.map((d) => ({
|
|
groupId: String(d.g ?? groupId).trim(),
|
|
artifactId: String(d.a ?? artifactId).trim(),
|
|
version: String(d.v ?? '').trim(),
|
|
packaging: String(d.p ?? '').trim(),
|
|
publishedAt: epochMsToIso(d.timestamp),
|
|
tags: Array.isArray(d.tags) ? d.tags.filter(Boolean).join(', ') : '',
|
|
url: `https://central.sonatype.com/artifact/${groupId}/${artifactId}/${d.v ?? ''}`.replace(/\/$/, ''),
|
|
}));
|
|
},
|
|
});
|