diff --git a/src/registry/domain/events-handler.ts b/src/registry/domain/events-handler.ts index 8ea95779..bea44047 100644 --- a/src/registry/domain/events-handler.ts +++ b/src/registry/domain/events-handler.ts @@ -1,5 +1,6 @@ import type { IncomingHttpHeaders } from 'node:http'; import strings from '../../resources'; +import type { Component } from '../../types'; type Subscription = (data: T) => void; let subscriptions: Record> = {}; @@ -38,6 +39,13 @@ type Events = { status: number; error: Error; }; + 'component-published': { + componentName: string; + componentVersion: string; + packageJson: Component; + componentFolder: string; + user?: string; + }; }; type EventsHandler = { diff --git a/src/registry/routes/publish.ts b/src/registry/routes/publish.ts index 7475ada8..c38610eb 100644 --- a/src/registry/routes/publish.ts +++ b/src/registry/routes/publish.ts @@ -1,5 +1,6 @@ import type { Request, Response } from 'express'; import strings from '../../resources/index'; +import eventsHandler from '../domain/events-handler'; import extractPackage from '../domain/extract-package'; import type { Repository } from '../domain/repository'; import * as validator from '../domain/validators'; @@ -76,13 +77,28 @@ export default function publish(repository: Repository) { } try { + const componentName = req.params['componentName']; + const componentVersion = req.params['componentVersion']; + const dryRun = typeof req.query['dryRun'] !== 'undefined'; + await repository.publishComponent({ pkgDetails, - componentName: req.params['componentName'], - componentVersion: req.params['componentVersion'], - dryRun: typeof req.query['dryRun'] !== 'undefined', + componentName, + componentVersion, + dryRun, user: req.user }); + + if (!dryRun) { + eventsHandler.fire('component-published', { + componentName, + componentVersion, + packageJson: pkgDetails.packageJson, + componentFolder: pkgDetails.outputFolder, + user: req.user + }); + } + res.status(200).json({ ok: true }); } catch (err: any) { let errorMessage = err.msg || err.message;