@thezelijah/majik-message 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,166 @@
1
+ import { ThreadStatus } from "./enums";
2
+ import { ISODateString, MajikMessageAccountID, MajikMessagePublicKey, MajikMessageThreadID } from "../../types";
3
+ import { MajikUserID } from "@thezelijah/majik-user";
4
+ import { MajikMessageMailJSON } from "./mail/majik-message-mail";
5
+ import { MajikMessageIdentity } from "../system/identity";
6
+ export interface ThreadMetadata {
7
+ title?: string;
8
+ subject?: string;
9
+ tags?: string[];
10
+ category?: string;
11
+ priority?: "low" | "medium" | "high" | "urgent";
12
+ lastActivity?: ISODateString;
13
+ messageCount?: number;
14
+ }
15
+ export interface DeletionApproval {
16
+ publicKey: string;
17
+ approvalHash: string;
18
+ timestamp: Date;
19
+ }
20
+ export interface MajikMessageThreadAnalytics {
21
+ threadID: MajikMessageThreadID;
22
+ owner: MajikMessageAccountID;
23
+ userID: MajikUserID;
24
+ participantCount: number;
25
+ messageCount: number;
26
+ status: ThreadStatus;
27
+ createdAt: string;
28
+ lastActivity: string | undefined;
29
+ duration: number;
30
+ tags: string[];
31
+ category: string | undefined;
32
+ priority: string | undefined;
33
+ starred: boolean;
34
+ deletionStatus: {
35
+ isPendingDeletion: boolean;
36
+ isMarkedForDeletion: boolean;
37
+ approvalProgress: number;
38
+ approvedCount: number;
39
+ totalParticipants: number;
40
+ };
41
+ }
42
+ export interface MajikMessageThreadSummary {
43
+ id: MajikMessageThreadID;
44
+ participants: MajikMessagePublicKey[];
45
+ participant_count: number;
46
+ latest_message: MajikMessageMailJSON;
47
+ latest_message_timestamp: ISODateString;
48
+ total_messages: number;
49
+ unread_count: number;
50
+ has_unread: boolean;
51
+ starred: boolean;
52
+ }
53
+ export interface MajikMessageThreadJSON {
54
+ id: MajikMessageThreadID;
55
+ user_id: MajikUserID;
56
+ owner: MajikMessageAccountID;
57
+ metadata: ThreadMetadata;
58
+ timestamp: ISODateString;
59
+ participants: string[];
60
+ status: ThreadStatus;
61
+ hash: string;
62
+ deletion_approvals: DeletionApproval[];
63
+ starred: boolean;
64
+ }
65
+ export declare class MajikThreadError extends Error {
66
+ code: string;
67
+ constructor(message: string, code: string);
68
+ }
69
+ export declare class ValidationError extends MajikThreadError {
70
+ constructor(message: string);
71
+ }
72
+ export declare class OperationNotAllowedError extends MajikThreadError {
73
+ constructor(message: string);
74
+ }
75
+ export declare class MajikMessageThread {
76
+ private readonly _id;
77
+ private readonly _userID;
78
+ private readonly _owner;
79
+ private _metadata;
80
+ private readonly _timestamp;
81
+ private readonly _participants;
82
+ private _status;
83
+ private readonly _hash;
84
+ private _deletionApprovals;
85
+ private _starred;
86
+ private constructor();
87
+ get id(): MajikMessageThreadID;
88
+ get userID(): MajikUserID;
89
+ get owner(): MajikMessagePublicKey;
90
+ get metadata(): Readonly<ThreadMetadata>;
91
+ get timestamp(): Date;
92
+ get participants(): readonly MajikMessagePublicKey[];
93
+ get status(): ThreadStatus;
94
+ get hash(): string;
95
+ get deletionApprovals(): readonly DeletionApproval[];
96
+ get starred(): boolean;
97
+ static create(userID: MajikUserID, owner: MajikMessageIdentity, participants: MajikMessagePublicKey[], metadata?: ThreadMetadata): MajikMessageThread;
98
+ /**
99
+ * Stars the thread for the user
100
+ */
101
+ star(): void;
102
+ /**
103
+ * Unstars the thread for the user
104
+ */
105
+ unstar(): void;
106
+ /**
107
+ * Toggles the starred status of the thread
108
+ * @returns The new starred state
109
+ */
110
+ toggleStar(): boolean;
111
+ private static generateHash;
112
+ private static generateApprovalHash;
113
+ validate(): boolean;
114
+ close(): void;
115
+ requestDeletion(publicKey: string): void;
116
+ private updateDeletionStatus;
117
+ revokeDeletionRequest(publicKey: string): void;
118
+ canBeDeleted(): boolean;
119
+ getDeletionProgress(): {
120
+ approved: number;
121
+ total: number;
122
+ percentage: number;
123
+ };
124
+ /**
125
+ * Verifies that all deletion approvals have valid hashes and all participants have approved
126
+ * @returns true if all approvals are valid and complete, false otherwise
127
+ */
128
+ verifyDeletionApprovals(): boolean;
129
+ /**
130
+ * Get detailed verification status of deletion approvals
131
+ * @returns Detailed information about approval validity
132
+ */
133
+ getDeletionApprovalStatus(): {
134
+ isValid: boolean;
135
+ allParticipantsApproved: boolean;
136
+ invalidApprovals: string[];
137
+ missingApprovals: string[];
138
+ duplicateApprovals: string[];
139
+ };
140
+ updateMetadata(metadata: Partial<ThreadMetadata>): void;
141
+ toJSON(): MajikMessageThreadJSON;
142
+ static fromJSON(json: MajikMessageThreadJSON | string): MajikMessageThread;
143
+ isOwner(publicKey: string): boolean;
144
+ isParticipant(publicKey: string): boolean;
145
+ toString(): string;
146
+ /**
147
+ * Deduplicates and sorts participants to ensure consistent ordering
148
+ */
149
+ private static normalizeParticipants;
150
+ /**
151
+ * Exports the thread with finalized metadata for analytics and archival purposes.
152
+ * This method updates metadata with actual counts and stats, sets lastActivity,
153
+ * and optionally closes the thread if no deletion is pending.
154
+ *
155
+ * @param messageCount - The actual number of messages in this thread
156
+ * @param additionalTags - Optional tags to add to existing tags
157
+ * @param autoClose - Whether to automatically close the thread (default: true)
158
+ * @returns MajikMessageThreadJSON with updated metadata
159
+ */
160
+ exportFinalStats(messageCount: number, additionalTags?: string[], autoClose?: boolean): MajikMessageThreadJSON;
161
+ /**
162
+ * Exports analytics-ready data for the thread
163
+ * @returns Object with analytics metadata
164
+ */
165
+ getAnalyticsData(): MajikMessageThreadAnalytics;
166
+ }