realtimecursor
Version:
Real-time collaboration system with cursor tracking and approval workflow
156 lines (155 loc) • 4.13 kB
TypeScript
export interface RealtimeCursorConfig {
apiUrl: string;
socketUrl?: string;
token?: string;
}
export interface User {
id: string;
email: string;
firstName?: string;
lastName?: string;
fullName?: string;
role?: string;
}
export interface Project {
id: string;
name: string;
description: string;
createdBy: string;
createdByName: string;
members: string[];
memberNames: string[];
content?: string;
createdAt: string;
lastActivity?: string;
hasStagedChanges?: boolean;
}
export interface Comment {
id: string;
projectId: string;
userId: string;
userName: string;
text: string;
selectedText: string;
startPosition: number;
endPosition: number;
createdAt: string;
}
export interface StagedChange {
id: string;
userId: string;
userName: string;
originalContent: string;
proposedContent: string;
createdAt: string;
status?: string;
reviewedBy?: string;
reviewerName?: string;
reviewedAt?: string;
feedback?: string;
diff?: DiffItem[];
}
export interface DiffItem {
type: 'added' | 'removed';
line: number;
content: string;
}
export interface HistoryEntry {
id: string;
type: 'commit' | 'pull_request' | 'merge' | 'close';
action: string;
userId: string;
userName: string;
message: string;
timestamp: string;
diff?: DiffItem[];
feedback?: string;
changeId?: string;
originalAuthor?: string;
originalAuthorId?: string;
}
export interface CursorPosition {
x: number;
y: number;
textPosition?: number;
}
export interface CollaboratorInfo {
id: string;
name: string;
color: string;
socketId: string;
}
export declare class RealtimeCursorSDK {
private api;
private socket;
private config;
private token;
private currentUser;
constructor(config: RealtimeCursorConfig);
login(email: string, password: string): Promise<User>;
register(userData: {
email: string;
password: string;
firstName: string;
lastName: string;
}): Promise<User>;
getCurrentUser(): Promise<User>;
logout(): void;
getProjects(): Promise<Project[]>;
createProject(name: string, description: string): Promise<Project>;
getProject(projectId: string): Promise<Project>;
updateProjectContent(projectId: string, content: string): Promise<{
staged: boolean;
changeId?: string;
}>;
inviteUsers(projectId: string, userIds: string[]): Promise<{
invitations: number;
}>;
getComments(projectId: string): Promise<Comment[]>;
addComment(projectId: string, commentData: {
text: string;
selectedText: string;
startPosition?: number;
endPosition?: number;
}): Promise<Comment>;
getStagedChanges(projectId: string): Promise<StagedChange[]>;
reviewChange(changeId: string, approve: boolean, feedback?: string): Promise<{
approved: boolean;
}>;
getHistory(projectId: string): Promise<HistoryEntry[]>;
connectToProject(projectId: string, userInfo: {
id: string;
name: string;
color?: string;
}): void;
onContentUpdate(callback: (data: {
content: string;
user: any;
}) => void): void;
onCursorUpdate(callback: (data: {
user: any;
x: number;
y: number;
textPosition?: number;
}) => void): void;
onUserJoined(callback: (data: {
user: any;
}) => void): void;
onUserLeft(callback: (data: {
socketId: string;
}) => void): void;
onRoomUsers(callback: (users: any[]) => void): void;
updateContent(content: string, cursorPosition?: number): void;
updateCursor(position: {
x: number;
y: number;
textPosition?: number;
}): void;
updateCursorPosition(textPosition: number): void;
setTyping(isTyping: boolean): void;
notifyContentSaved(userName: string): void;
notifyHistoryUpdate(): void;
disconnect(): void;
private getRandomColor;
}
export default RealtimeCursorSDK;