diff --git a/.changeset/ten-parents-breathe.md b/.changeset/ten-parents-breathe.md new file mode 100644 index 000000000..b4ab16753 --- /dev/null +++ b/.changeset/ten-parents-breathe.md @@ -0,0 +1,7 @@ +--- +'@verdaccio/auth': minor +'@verdaccio/fastify-migration': minor +'@verdaccio/web': minor +--- + +dist tags Implementation on Fastify diff --git a/packages/core/server/src/endpoints/dist-tags.ts b/packages/core/server/src/endpoints/dist-tags.ts new file mode 100644 index 000000000..03091cbac --- /dev/null +++ b/packages/core/server/src/endpoints/dist-tags.ts @@ -0,0 +1,55 @@ +import buildDebug from 'debug'; +import { FastifyInstance } from 'fastify'; + +const debug = buildDebug('verdaccio:api:dist-tags'); + +async function distTagsRoute(fastify: FastifyInstance) { + fastify.get('/-/package/:packageName/dist-tags', async (request, reply) => { + // @ts-ignore + const { packageName } = request.params; + debug('dist-tags: response %o', packageName); + fastify.storage.getPackage({ + name: packageName, + uplinksLook: true, + req: request.raw, + callback: function (err, info): void { + if (err) { + reply.send(err); + } + reply.code(fastify.statusCode.OK).send(info[fastify.constants.DIST_TAGS]); + }, + }); + }); + + fastify.post('/-/package/:packageName/dist-tags', async (request, reply) => { + // @ts-ignore + const { packageName } = request.params; + // @ts-ignore + fastify.storage.mergeTags(packageName, request.body, function (err): void { + if (err) { + reply.send(err); + } + reply + .code(fastify.statusCode.CREATED) + .send({ ok: fastify.constants.API_MESSAGE.TAG_UPDATED }); + }); + }); + + fastify.delete('/-/package/:packageName/dist-tags', async (request, reply) => { + // @ts-ignore + const { packageName } = request.params; + fastify.storage.getPackage({ + name: packageName, + uplinksLook: true, + req: request.raw, + callback: function (err, info): void { + if (err) { + reply.send(err); + } + reply.send(info[fastify.constants.DIST_TAGS]); + }, + }); + }); +} + +export default distTagsRoute; diff --git a/packages/core/server/src/plugins/coreUtils.ts b/packages/core/server/src/plugins/coreUtils.ts index b6fe81a1a..253f49f27 100644 --- a/packages/core/server/src/plugins/coreUtils.ts +++ b/packages/core/server/src/plugins/coreUtils.ts @@ -1,11 +1,19 @@ import fp from 'fastify-plugin'; -import { API_ERROR, API_MESSAGE, HTTP_STATUS, errorUtils, validatioUtils } from '@verdaccio/core'; +import { + API_ERROR, + API_MESSAGE, + HTTP_STATUS, + constants, + errorUtils, + validatioUtils, +} from '@verdaccio/core'; export default fp( async function (fastify) { fastify.decorate('errorUtils', errorUtils); fastify.decorate('apiError', API_ERROR); + fastify.decorate('constants', constants); fastify.decorate('apiMessage', API_MESSAGE); fastify.decorate('validatioUtils', validatioUtils); fastify.decorate('statusCode', HTTP_STATUS); @@ -21,5 +29,6 @@ declare module 'fastify' { apiMessage: typeof API_MESSAGE; statusCode: typeof HTTP_STATUS; errorUtils: typeof errorUtils; + constants: typeof constants; } } diff --git a/packages/core/server/src/server.ts b/packages/core/server/src/server.ts index 358cadea9..7da6642c9 100644 --- a/packages/core/server/src/server.ts +++ b/packages/core/server/src/server.ts @@ -4,6 +4,7 @@ import fastify from 'fastify'; import { Config as AppConfig, createAnonymousRemoteUser } from '@verdaccio/config'; import { Config as IConfig, RemoteUser } from '@verdaccio/types'; +import distTags from './endpoints/dist-tags'; import ping from './endpoints/ping'; import search from './endpoints/search'; import tarball from './endpoints/tarball'; @@ -37,6 +38,7 @@ async function startServer({ logger, config }) { instance.register(search); instance.register(whoami); instance.register(tarball); + instance.register(distTags); instance.register(readme, { prefix: '/-/verdaccio' }); instance.register(sidebar, { prefix: '/-/verdaccio' }); instance.register(login, { prefix: '/-/verdaccio' });