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>
41 lines
1008 B
TypeScript
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);
|
|
}
|