Files
paperclip/server/src/services/live-events.ts
Dotta f60c1001ec refactor: rename packages to @paperclipai and CLI binary to paperclipai
Rename all workspace packages from @paperclip/* to @paperclipai/* and
the CLI binary from `paperclip` to `paperclipai` in preparation for
npm publishing. Bump CLI version to 0.1.0 and add package metadata
(description, keywords, license, repository, files). Update all
imports, documentation, user-facing messages, and tests accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 08:45:26 -06:00

41 lines
1008 B
TypeScript

import { EventEmitter } from "node:events";
import type { LiveEvent, LiveEventType } from "@paperclipai/shared";
type LiveEventPayload = Record<string, unknown>;
type LiveEventListener = (event: LiveEvent) => void;
const emitter = new EventEmitter();
emitter.setMaxListeners(0);
let nextEventId = 0;
function toLiveEvent(input: {
companyId: string;
type: LiveEventType;
payload?: LiveEventPayload;
}): LiveEvent {
nextEventId += 1;
return {
id: nextEventId,
companyId: input.companyId,
type: input.type,
createdAt: new Date().toISOString(),
payload: input.payload ?? {},
};
}
export function publishLiveEvent(input: {
companyId: string;
type: LiveEventType;
payload?: LiveEventPayload;
}) {
const event = toLiveEvent(input);
emitter.emit(input.companyId, event);
return event;
}
export function subscribeCompanyLiveEvents(companyId: string, listener: LiveEventListener) {
emitter.on(companyId, listener);
return () => emitter.off(companyId, listener);
}