fca-phantom 1.0.0

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.
Files changed (121) hide show
  1. package/LICENSE +58 -0
  2. package/README.md +534 -0
  3. package/index.js +35 -0
  4. package/package.json +101 -0
  5. package/phantom/core/builder/bootstrap.js +334 -0
  6. package/phantom/core/builder/config.js +78 -0
  7. package/phantom/core/builder/forge.js +113 -0
  8. package/phantom/core/builder/ignite.js +386 -0
  9. package/phantom/core/builder/options.js +61 -0
  10. package/phantom/core/engine.js +71 -0
  11. package/phantom/core/reactor.js +2 -0
  12. package/phantom/datastore/appState.js +2 -0
  13. package/phantom/datastore/appStateBackup.js +34 -0
  14. package/phantom/datastore/models/cipher/e2ee.js +48 -0
  15. package/phantom/datastore/models/cipher/vault.js +153 -0
  16. package/phantom/datastore/models/index.js +3 -0
  17. package/phantom/datastore/models/matrix/auth.js +151 -0
  18. package/phantom/datastore/models/matrix/cache.js +3 -0
  19. package/phantom/datastore/models/matrix/checker.js +2 -0
  20. package/phantom/datastore/models/matrix/clients.js +2 -0
  21. package/phantom/datastore/models/matrix/constants.js +2 -0
  22. package/phantom/datastore/models/matrix/credentials.js +2 -0
  23. package/phantom/datastore/models/matrix/cycle.js +2 -0
  24. package/phantom/datastore/models/matrix/gate.js +282 -0
  25. package/phantom/datastore/models/matrix/ghost.js +332 -0
  26. package/phantom/datastore/models/matrix/headers.js +193 -0
  27. package/phantom/datastore/models/matrix/heartbeat.js +298 -0
  28. package/phantom/datastore/models/matrix/identity.js +235 -0
  29. package/phantom/datastore/models/matrix/logger.js +271 -0
  30. package/phantom/datastore/models/matrix/monitor.js +2 -0
  31. package/phantom/datastore/models/matrix/net.js +316 -0
  32. package/phantom/datastore/models/matrix/response.js +193 -0
  33. package/phantom/datastore/models/matrix/revive.js +255 -0
  34. package/phantom/datastore/models/matrix/signals.js +2 -0
  35. package/phantom/datastore/models/matrix/store.js +263 -0
  36. package/phantom/datastore/models/matrix/telemetry.js +272 -0
  37. package/phantom/datastore/models/matrix/tools.js +93 -0
  38. package/phantom/datastore/models/matrix/transform/cookieParser.js +2 -0
  39. package/phantom/datastore/models/matrix/transform/cookies.js +114 -0
  40. package/phantom/datastore/models/matrix/transform/index.js +203 -0
  41. package/phantom/datastore/models/matrix/validator.js +157 -0
  42. package/phantom/datastore/models/types/index.d.ts +498 -0
  43. package/phantom/datastore/schema.js +167 -0
  44. package/phantom/datastore/session.js +129 -0
  45. package/phantom/datastore/threads.js +22 -0
  46. package/phantom/datastore/users.js +26 -0
  47. package/phantom/dispatch/addExternalModule.js +239 -0
  48. package/phantom/dispatch/addUserToGroup.js +161 -0
  49. package/phantom/dispatch/changeAdminStatus.js +142 -0
  50. package/phantom/dispatch/changeArchivedStatus.js +135 -0
  51. package/phantom/dispatch/changeAvatar.js +123 -0
  52. package/phantom/dispatch/changeBio.js +86 -0
  53. package/phantom/dispatch/changeBlockedStatus.js +86 -0
  54. package/phantom/dispatch/changeGroupImage.js +145 -0
  55. package/phantom/dispatch/changeThreadColor.js +172 -0
  56. package/phantom/dispatch/changeThreadEmoji.js +130 -0
  57. package/phantom/dispatch/comment.js +136 -0
  58. package/phantom/dispatch/createAITheme.js +333 -0
  59. package/phantom/dispatch/createNewGroup.js +99 -0
  60. package/phantom/dispatch/createPoll.js +148 -0
  61. package/phantom/dispatch/deleteMessage.js +131 -0
  62. package/phantom/dispatch/deleteThread.js +155 -0
  63. package/phantom/dispatch/e2ee.js +101 -0
  64. package/phantom/dispatch/editMessage.js +158 -0
  65. package/phantom/dispatch/emoji.js +143 -0
  66. package/phantom/dispatch/fetchThemeData.js +233 -0
  67. package/phantom/dispatch/follow.js +111 -0
  68. package/phantom/dispatch/forwardMessage.js +110 -0
  69. package/phantom/dispatch/friend.js +189 -0
  70. package/phantom/dispatch/gcmember.js +138 -0
  71. package/phantom/dispatch/gcname.js +131 -0
  72. package/phantom/dispatch/gcrule.js +111 -0
  73. package/phantom/dispatch/getAccess.js +109 -0
  74. package/phantom/dispatch/getBotInfo.js +81 -0
  75. package/phantom/dispatch/getBotInitialData.js +110 -0
  76. package/phantom/dispatch/getFriendsList.js +118 -0
  77. package/phantom/dispatch/getMessage.js +199 -0
  78. package/phantom/dispatch/getTheme.js +199 -0
  79. package/phantom/dispatch/getThemeInfo.js +160 -0
  80. package/phantom/dispatch/getThreadHistory.js +139 -0
  81. package/phantom/dispatch/getThreadInfo.js +153 -0
  82. package/phantom/dispatch/getThreadList.js +132 -0
  83. package/phantom/dispatch/getThreadPictures.js +93 -0
  84. package/phantom/dispatch/getUserID.js +147 -0
  85. package/phantom/dispatch/getUserInfo.js +513 -0
  86. package/phantom/dispatch/getUserInfoV2.js +146 -0
  87. package/phantom/dispatch/handleMessageRequest.js +50 -0
  88. package/phantom/dispatch/httpGet.js +63 -0
  89. package/phantom/dispatch/httpPost.js +89 -0
  90. package/phantom/dispatch/httpPostFormData.js +69 -0
  91. package/phantom/dispatch/listenMqtt.js +1236 -0
  92. package/phantom/dispatch/listenSpeed.js +179 -0
  93. package/phantom/dispatch/logout.js +93 -0
  94. package/phantom/dispatch/markAsDelivered.js +92 -0
  95. package/phantom/dispatch/markAsRead.js +119 -0
  96. package/phantom/dispatch/markAsReadAll.js +215 -0
  97. package/phantom/dispatch/markAsSeen.js +70 -0
  98. package/phantom/dispatch/mqttDeltaValue.js +278 -0
  99. package/phantom/dispatch/muteThread.js +253 -0
  100. package/phantom/dispatch/nickname.js +132 -0
  101. package/phantom/dispatch/notes.js +263 -0
  102. package/phantom/dispatch/pinMessage.js +238 -0
  103. package/phantom/dispatch/produceMetaTheme.js +335 -0
  104. package/phantom/dispatch/realtime.js +291 -0
  105. package/phantom/dispatch/removeUserFromGroup.js +248 -0
  106. package/phantom/dispatch/resolvePhotoUrl.js +217 -0
  107. package/phantom/dispatch/searchForThread.js +258 -0
  108. package/phantom/dispatch/sendMessage.js +354 -0
  109. package/phantom/dispatch/sendMessageMqtt.js +249 -0
  110. package/phantom/dispatch/sendTypingIndicator.js +206 -0
  111. package/phantom/dispatch/setMessageReaction.js +188 -0
  112. package/phantom/dispatch/setMessageReactionMqtt.js +248 -0
  113. package/phantom/dispatch/setThreadTheme.js +330 -0
  114. package/phantom/dispatch/setThreadThemeMqtt.js +207 -0
  115. package/phantom/dispatch/share.js +200 -0
  116. package/phantom/dispatch/shareContact.js +216 -0
  117. package/phantom/dispatch/stickers.js +395 -0
  118. package/phantom/dispatch/story.js +240 -0
  119. package/phantom/dispatch/theme.js +296 -0
  120. package/phantom/dispatch/unfriend.js +199 -0
  121. package/phantom/dispatch/unsendMessage.js +124 -0
@@ -0,0 +1,498 @@
1
+ /// <reference types="node" />
2
+ import { ReadStream } from "fs";
3
+ import { EventEmitter } from "events";
4
+
5
+ declare module "fca-marin" {
6
+ export type UserID = string;
7
+ export type ThreadID = string;
8
+ export type MessageID = string;
9
+ export type Callback<T = any> = (err: any, result?: T) => void;
10
+
11
+ export interface Coordinates {
12
+ latitude: number;
13
+ longitude: number;
14
+ }
15
+
16
+ export interface Mention {
17
+ tag: string;
18
+ id: UserID;
19
+ fromIndex?: number;
20
+ }
21
+
22
+ export interface Reaction {
23
+ reaction: string;
24
+ userID: UserID;
25
+ }
26
+
27
+ export interface StickerPackInfo {
28
+ id: string;
29
+ name: string;
30
+ thumbnail?: string;
31
+ }
32
+
33
+ export interface StickerInfo {
34
+ type: "sticker";
35
+ ID: string;
36
+ url?: string;
37
+ animatedUrl?: string;
38
+ packID?: string;
39
+ label: string;
40
+ stickerID: string;
41
+ }
42
+
43
+ export interface AddedStickerPackInfo {
44
+ id: string;
45
+ name: string;
46
+ in_sticker_tray: boolean;
47
+ artist?: string;
48
+ preview_image?: { uri: string };
49
+ thumbnail_image?: { uri: string };
50
+ }
51
+
52
+ export interface CommentMessage {
53
+ body: string;
54
+ attachment?: ReadStream[];
55
+ mentions?: Mention[];
56
+ url?: string;
57
+ sticker?: string;
58
+ }
59
+
60
+ export interface CommentResult {
61
+ id: string;
62
+ url: string;
63
+ count: number;
64
+ }
65
+
66
+ export interface ShareResult {
67
+ postID: string;
68
+ url: string;
69
+ }
70
+
71
+ export interface Attachment {
72
+ type: "photo" | "animated_image" | "video" | "audio" | "file" | "sticker" | "share" | "location" | "unknown";
73
+ ID: string;
74
+ filename: string;
75
+ url?: string;
76
+ name?: string;
77
+ }
78
+
79
+ export interface PhotoAttachment extends Attachment {
80
+ type: "photo";
81
+ thumbnailUrl: string;
82
+ previewUrl: string;
83
+ previewWidth: number;
84
+ previewHeight: number;
85
+ largePreviewUrl: string;
86
+ largePreviewWidth: number;
87
+ largePreviewHeight: number;
88
+ width: number;
89
+ height: number;
90
+ }
91
+
92
+ export interface VideoAttachment extends Attachment {
93
+ type: "video";
94
+ duration: number;
95
+ width: number;
96
+ height: number;
97
+ previewUrl: string;
98
+ previewWidth: number;
99
+ previewHeight: number;
100
+ videoType: "file_attachment" | "native_video" | "unknown";
101
+ }
102
+
103
+ export interface AudioAttachment extends Attachment {
104
+ type: "audio";
105
+ duration: number;
106
+ audioType: string;
107
+ isVoiceMail: boolean;
108
+ }
109
+
110
+ export interface FileAttachment extends Attachment {
111
+ type: "file";
112
+ isMalicious: boolean;
113
+ contentType: string;
114
+ }
115
+
116
+ export interface StickerAttachment extends Attachment {
117
+ type: "sticker";
118
+ packID: string;
119
+ spriteUrl?: string;
120
+ spriteUrl2x?: string;
121
+ width: number;
122
+ height: number;
123
+ caption: string;
124
+ description: string;
125
+ frameCount: number;
126
+ frameRate: number;
127
+ framesPerRow: number;
128
+ framesPerCol: number;
129
+ }
130
+
131
+ export interface ShareAttachment extends Attachment {
132
+ type: "share";
133
+ title: string;
134
+ description?: string;
135
+ source?: string;
136
+ image?: string;
137
+ width?: number;
138
+ height?: number;
139
+ playable?: boolean;
140
+ subattachments?: any[];
141
+ properties: Record<string, any>;
142
+ }
143
+
144
+ export type AnyAttachment =
145
+ | PhotoAttachment
146
+ | VideoAttachment
147
+ | AudioAttachment
148
+ | FileAttachment
149
+ | StickerAttachment
150
+ | ShareAttachment;
151
+
152
+ export interface MessageReply {
153
+ messageID: MessageID;
154
+ senderID: UserID;
155
+ body: string;
156
+ attachments: AnyAttachment[];
157
+ timestamp: string;
158
+ isReply: true;
159
+ }
160
+
161
+ export interface Message {
162
+ type: "message";
163
+ senderID: UserID;
164
+ body: string;
165
+ threadID: ThreadID;
166
+ messageID: MessageID;
167
+ attachments: AnyAttachment[];
168
+ mentions: Record<string, string>;
169
+ timestamp: string;
170
+ isGroup: boolean;
171
+ participantIDs?: UserID[];
172
+ messageReply?: MessageReply;
173
+ isUnread?: boolean;
174
+ reactions?: Reaction[];
175
+ }
176
+
177
+ export interface Event {
178
+ type: "event";
179
+ threadID: ThreadID;
180
+ logMessageType: string;
181
+ logMessageData: any;
182
+ logMessageBody: string;
183
+ timestamp: string;
184
+ author: UserID;
185
+ }
186
+
187
+ export interface TypingIndicator {
188
+ type: "typ";
189
+ isTyping: boolean;
190
+ from: UserID;
191
+ threadID: ThreadID;
192
+ fromMobile: boolean;
193
+ }
194
+
195
+ export interface UnsendMessageEvent {
196
+ type: "unsend";
197
+ messageID: MessageID;
198
+ threadID: ThreadID;
199
+ senderID: UserID;
200
+ deletionTimestamp: string;
201
+ }
202
+
203
+ export interface EmojiEvent {
204
+ type: "change_thread_emoji";
205
+ threadID: ThreadID;
206
+ author: UserID;
207
+ emoji: string;
208
+ }
209
+
210
+ export interface GroupNameEvent {
211
+ type: "change_thread_name";
212
+ threadID: ThreadID;
213
+ author: UserID;
214
+ name: string;
215
+ }
216
+
217
+ export interface NicknameEvent {
218
+ type: "change_thread_nickname";
219
+ threadID: ThreadID;
220
+ author: UserID;
221
+ participantID: UserID;
222
+ nickname: string;
223
+ }
224
+
225
+ export type ListenEvent = Message | Event | TypingIndicator;
226
+
227
+ export interface UserInfo {
228
+ id: UserID;
229
+ name: string;
230
+ firstName: string;
231
+ lastName?: string;
232
+ vanity: string;
233
+ profileUrl: string;
234
+ profilePicUrl: string;
235
+ gender: string;
236
+ type: "user" | "page";
237
+ isFriend: boolean;
238
+ isBirthday: boolean;
239
+ bio?: string;
240
+ live_city?: string;
241
+ followers?: string;
242
+ following?: string;
243
+ coverPhoto?: string;
244
+ }
245
+
246
+ export interface ThreadInfo {
247
+ threadID: ThreadID;
248
+ threadName?: string;
249
+ participantIDs: UserID[];
250
+ userInfo: UserInfo[];
251
+ unreadCount: number;
252
+ messageCount: number;
253
+ imageSrc?: string;
254
+ timestamp: string;
255
+ muteUntil: number;
256
+ isGroup: boolean;
257
+ isArchived: boolean;
258
+ isSubscribed: boolean;
259
+ folder: string;
260
+ nicknames: Record<UserID, string>;
261
+ adminIDs: UserID[];
262
+ emoji?: string;
263
+ color?: string;
264
+ canReply: boolean;
265
+ inviteLink: {
266
+ enable: boolean;
267
+ link: string | null;
268
+ };
269
+ }
270
+
271
+ export interface MessageObject {
272
+ body?: string;
273
+ attachment?: ReadStream | ReadStream[];
274
+ sticker?: string;
275
+ emoji?: string;
276
+ emojiSize?: "small" | "medium" | "large";
277
+ mentions?: Mention[];
278
+ edit?: [string, number][];
279
+ url?: string;
280
+ location?: Coordinates;
281
+ }
282
+
283
+ export interface FriendInfo {
284
+ alternateName: string;
285
+ firstName: string;
286
+ gender: string;
287
+ userID: UserID;
288
+ isFriend: boolean;
289
+ fullName: string;
290
+ profilePicture: string;
291
+ type: string;
292
+ profileUrl: string;
293
+ vanity: string;
294
+ isBirthday: boolean;
295
+ }
296
+
297
+ export interface HealthStatus {
298
+ mqttConnected: boolean;
299
+ autoReconnect: boolean;
300
+ tokenRefresh: {
301
+ lastRefresh: number;
302
+ nextRefresh: number;
303
+ failureCount: number;
304
+ };
305
+ rateLimiter: {
306
+ activeRequests: number;
307
+ maxConcurrentRequests: number;
308
+ maxRequestsPerMinute: number;
309
+ threadCooldowns: number;
310
+ endpointCooldowns: number;
311
+ errorCacheSize: number;
312
+ } | null;
313
+ }
314
+
315
+ export interface API {
316
+ setOptions(options: LoginOptions): void;
317
+ getAppState(): any[];
318
+ getCurrentUserID(): UserID;
319
+ getHealthStatus(): HealthStatus;
320
+
321
+ listen(callback: (err: any, event: ListenEvent) => void): EventEmitter;
322
+
323
+ listenMqtt(callback: (err: any, event: ListenEvent) => void): void;
324
+
325
+ sendMessage(
326
+ message: string | MessageObject,
327
+ threadID: ThreadID,
328
+ replyToMessage?: MessageID | Callback<Message>,
329
+ callback?: Callback<Message>,
330
+ ): Promise<Message> | void;
331
+
332
+ sendMessageMqtt(
333
+ message: string | MessageObject,
334
+ threadID: ThreadID,
335
+ replyToMessage?: MessageID,
336
+ callback?: Callback<Message>,
337
+ ): void;
338
+
339
+ editMessage(text: string, messageID: MessageID, callback?: Callback): void;
340
+
341
+ unsendMessage(messageID: MessageID, threadID: ThreadID, callback?: Callback<UnsendMessageEvent>): Promise<UnsendMessageEvent>;
342
+
343
+ forwardMessage(messageID: MessageID, threadID: ThreadID, callback?: Callback): Promise<void>;
344
+
345
+ deleteMessage(messageIDs: MessageID | MessageID[], callback?: Callback): Promise<void>;
346
+
347
+ setMessageReaction(reaction: string, messageID: MessageID, callback?: Callback, forceCustomReaction?: boolean): Promise<void>;
348
+ setMessageReactionMqtt(reaction: string, messageID: MessageID, threadID: ThreadID, callback?: Callback): Promise<void>;
349
+
350
+ shareContact(text: string, senderID: UserID, threadID: ThreadID, callback?: Callback): void;
351
+ shareContact(senderID: UserID, threadID: ThreadID, callback?: Callback): void;
352
+ resolvePhotoUrl(photoID: string, callback?: Callback<string>): Promise<string>;
353
+
354
+ pinMessage(action: "pin" | "unpin", threadID: ThreadID, messageID: MessageID): Promise<any>;
355
+ pinMessage(action: "list", threadID: ThreadID): Promise<Message[]>;
356
+
357
+ markAsRead(threadID: ThreadID, read?: boolean, callback?: Callback): Promise<any>;
358
+ markAsReadAll(callback?: Callback): Promise<void>;
359
+ markAsSeen(timestamp?: number, callback?: Callback): Promise<void>;
360
+ markAsDelivered(threadID: ThreadID, messageID: MessageID, callback?: Callback): Promise<void>;
361
+
362
+ muteThread(threadID: ThreadID, muteSeconds: number, callback?: Callback): Promise<void>;
363
+
364
+ sendTypingIndicator(sendTyping: boolean, threadID: ThreadID, callback?: Callback): Promise<void>;
365
+
366
+ getThreadInfo(threadID: ThreadID, callback?: Callback<ThreadInfo>): Promise<ThreadInfo>;
367
+ getThreadInfo(threadID: ThreadID[], callback?: Callback<Record<ThreadID, ThreadInfo>>): Promise<Record<ThreadID, ThreadInfo>>;
368
+
369
+ getThreadList(limit: number, timestamp: number | null, tags: string[], callback?: Callback<ThreadInfo[]>): Promise<ThreadInfo[]>;
370
+ getThreadHistory(threadID: ThreadID, amount: number, timestamp: number | null, callback?: Callback<Message[]>): Promise<Message[]>;
371
+ getThreadPictures(threadID: ThreadID, offset: number, limit: number, callback?: Callback<string[]>): Promise<string[]>;
372
+
373
+ getMessage(messageID: MessageID, callback?: Callback<Message>): Promise<Message>;
374
+
375
+ getUserInfo(id: UserID, usePayload?: boolean, callback?: Callback<UserInfo>): Promise<UserInfo>;
376
+ getUserInfo(id: UserID[], usePayload?: boolean, callback?: Callback<Record<UserID, UserInfo>>): Promise<Record<UserID, UserInfo>>;
377
+ getUserInfoV2(id: UserID, callback?: Callback<UserInfo>): Promise<UserInfo>;
378
+ getUserID(name: string, callback?: Callback<{ userID: UserID; [key: string]: any }[]>): Promise<{ userID: UserID; [key: string]: any }[]>;
379
+
380
+ getFriendsList(callback?: Callback<Record<UserID, FriendInfo>>): Promise<Record<UserID, FriendInfo>>;
381
+
382
+ searchForThread(name: string, callback?: Callback<ThreadInfo[]>): Promise<ThreadInfo[]>;
383
+
384
+ createNewGroup(participantIDs: UserID[], groupName?: string, callback?: Callback<ThreadID>): Promise<ThreadID>;
385
+
386
+ addUserToGroup(userID: UserID, threadID: ThreadID, callback?: Callback): Promise<void>;
387
+ removeUserFromGroup(userID: UserID, threadID: ThreadID, callback?: Callback): Promise<void>;
388
+ changeAdminStatus(threadID: ThreadID, userID: UserID, adminStatus: boolean, callback?: Callback): Promise<void>;
389
+
390
+ changeGroupImage(image: ReadStream, threadID: ThreadID, callback?: Callback): Promise<void>;
391
+ changeThreadColor(color: string, threadID: ThreadID, callback?: Callback): Promise<void>;
392
+ changeThreadEmoji(emoji: string, threadID: ThreadID, callback?: Callback): Promise<void>;
393
+
394
+ changeArchivedStatus(threadID: ThreadID | ThreadID[], archive: boolean, callback?: Callback): Promise<void>;
395
+ changeBlockedStatus(userID: UserID, block: boolean, callback?: Callback): Promise<void>;
396
+
397
+ changeAvatar(image: ReadStream, callback?: Callback): Promise<void>;
398
+ changeBio(bio: string, publish: boolean, callback?: Callback): Promise<void>;
399
+
400
+ handleMessageRequest(threadID: ThreadID | ThreadID[], accept: boolean, callback?: Callback): Promise<void>;
401
+
402
+ deleteThread(threadID: ThreadID | ThreadID[], callback?: Callback): Promise<void>;
403
+
404
+ createPoll(title: string, threadID: ThreadID, options?: Record<string, boolean>, callback?: Callback): Promise<void>;
405
+
406
+ logout(callback?: (err: any) => void): Promise<void>;
407
+
408
+ addExternalModule(moduleObj: Record<string, Function>): void;
409
+ getAccess(authCode?: string, callback?: Callback<string>): Promise<string>;
410
+
411
+ httpGet(url: string, form?: any, customHeader?: any, callback?: Callback<string>, notAPI?: boolean): Promise<string>;
412
+ httpPost(url: string, form?: any, customHeader?: any, callback?: Callback<string>, notAPI?: boolean): Promise<string>;
413
+ httpPostFormData(url: string, form?: any, customHeader?: any, callback?: Callback<string>, notAPI?: boolean): Promise<string>;
414
+
415
+ getTheme(threadID: ThreadID): Promise<any[]>;
416
+ getThemeInfo(threadID: ThreadID): Promise<{ threadName?: string; color?: string; emoji?: string; [key: string]: any }>;
417
+ setThreadTheme(threadID: ThreadID, themeID: string, callback?: Callback): Promise<void>;
418
+ setThreadThemeMqtt(threadID: ThreadID, themeID: string, callback?: Callback): Promise<void>;
419
+ createAITheme(prompt: string): Promise<{ id: string; [key: string]: any }[]>;
420
+
421
+ follow(senderID: UserID, follow: boolean, callback?: Callback): void;
422
+ unfriend(userID: UserID, callback?: Callback): Promise<void>;
423
+ friend(userID: UserID, callback?: Callback): Promise<void>;
424
+
425
+ emoji(emoji: string, threadID?: ThreadID, callback?: Callback<EmojiEvent>): Promise<EmojiEvent>;
426
+ gcname(newName: string, threadID?: ThreadID, callback?: Callback<GroupNameEvent>): Promise<GroupNameEvent>;
427
+ nickname(nickname: string, threadID: ThreadID, participantID: UserID, callback?: Callback<NicknameEvent>): Promise<NicknameEvent>;
428
+ theme(newName: string, threadID?: ThreadID, callback?: Callback<GroupNameEvent>): Promise<GroupNameEvent>;
429
+
430
+ comment(msg: string | CommentMessage, postID: string, replyCommentID?: string, callback?: Callback<CommentResult>): Promise<CommentResult>;
431
+ share(text: string, postID: string, callback?: Callback<ShareResult>): Promise<ShareResult>;
432
+ share(postID: string, callback?: Callback<ShareResult>): Promise<ShareResult>;
433
+
434
+ stickers: {
435
+ search(query: string): Promise<StickerInfo[]>;
436
+ listPacks(): Promise<StickerPackInfo[]>;
437
+ getStorePacks(): Promise<StickerPackInfo[]>;
438
+ listAllPacks(): Promise<StickerPackInfo[]>;
439
+ addPack(packID: string): Promise<AddedStickerPackInfo>;
440
+ getStickersInPack(packID: string): Promise<StickerInfo[]>;
441
+ getAiStickers(options?: { limit?: number }): Promise<StickerInfo[]>;
442
+ };
443
+
444
+ e2ee: {
445
+ enable(): void;
446
+ disable(): void;
447
+ isEnabled(): boolean;
448
+ getPublicKey(): string;
449
+ setPeerKey(threadID: ThreadID, peerPublicKeyB64: string): void;
450
+ clearPeerKey(threadID: ThreadID): void;
451
+ hasPeer(threadID: ThreadID): boolean;
452
+ encrypt(threadID: ThreadID, text: string): string;
453
+ decrypt(threadID: ThreadID, armored: string): string | null;
454
+ };
455
+
456
+ getBotInfo(callback?: Callback): Promise<any>;
457
+ getUserInfoV2(userID: UserID, callback?: Callback<UserInfo>): Promise<UserInfo>;
458
+
459
+ [key: string]: any;
460
+ }
461
+
462
+ export interface LoginCredentials {
463
+ appState?: any;
464
+ email?: string;
465
+ password?: string;
466
+ }
467
+
468
+ export interface LoginOptions {
469
+ online?: boolean;
470
+ selfListen?: boolean;
471
+ listenEvents?: boolean;
472
+ updatePresence?: boolean;
473
+ forceLogin?: boolean;
474
+ autoMarkDelivery?: boolean;
475
+ autoMarkRead?: boolean;
476
+ listenTyping?: boolean;
477
+ proxy?: string;
478
+ autoReconnect?: boolean;
479
+ userAgent?: string;
480
+ emitReady?: boolean;
481
+ randomUserAgent?: boolean;
482
+ bypassRegion?: string;
483
+ simulateTyping?: boolean;
484
+ maxConcurrentRequests?: number;
485
+ maxRequestsPerMinute?: number;
486
+ requestCooldownMs?: number;
487
+ errorCacheTtlMs?: number;
488
+ stealthMode?: boolean;
489
+ persona?: "desktop" | "android" | "mobile";
490
+ logging?: boolean;
491
+ }
492
+
493
+ export function login(
494
+ credentials: LoginCredentials,
495
+ options: LoginOptions | Callback<API>,
496
+ callback?: Callback<API>
497
+ ): Promise<API> | void;
498
+ }
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+
3
+ const { getType } = require("./models/matrix/logger");
4
+
5
+ const THREAD_COLORS = [
6
+ "#0084ff","#44bec7","#ffc300","#fa3c4c","#d696bb",
7
+ "#6699cc","#13cf13","#ff7e29","#e68585","#7646ff",
8
+ "#20cef5","#67b868","#d4a88c","#ff5ca1","#a695c7",
9
+ ];
10
+
11
+ const KNOWN_THREAD_TYPES = new Set(["USER", "GROUP", "ROOM", "MULTI", "MARKETPLACE"]);
12
+ const REACTION_TYPES = new Set(["❤", "😍", "😆", "😮", "😢", "😡", "👍", "👎", "🙏", "💩", "🎉", "🔥", ""]);
13
+
14
+ function _pick(obj, keys, fallback = null) {
15
+ if (!obj) return fallback;
16
+ for (const k of keys) {
17
+ if (obj[k] !== undefined && obj[k] !== null) return obj[k];
18
+ }
19
+ return fallback;
20
+ }
21
+
22
+ function buildUser(raw) {
23
+ const type = raw.type || getType(raw.id);
24
+ return {
25
+ id: String(raw.id || ""),
26
+ userID: String(raw.id || raw.userId || ""),
27
+ name: raw.name || raw.full_name || "",
28
+ firstName: raw.first_name || (raw.name || "").split(" ")[0] || "",
29
+ lastName: raw.last_name || "",
30
+ alternateName: raw.alternate_name || "",
31
+ gender: raw.gender?.value || raw.gender || null,
32
+ url: raw.url || null,
33
+ profilePicture: raw.big_image_src?.uri || raw.profile_pic || raw.profile_picture?.uri || null,
34
+ profilePicSmall: raw.small_image_src?.uri || null,
35
+ type,
36
+ isVerified: raw.is_verified ?? false,
37
+ isEmployee: raw.is_employee ?? false,
38
+ isFriend: raw.is_friend ?? false,
39
+ isBirthday: raw.is_birthday ?? false,
40
+ vanity: raw.vanity || raw.username || null,
41
+ followers: raw.followers_count || 0,
42
+ thumbsrc: raw.thumbSrc || null,
43
+ resolvedAt: Date.now(),
44
+ };
45
+ }
46
+
47
+ function buildMessage(raw, extras = {}) {
48
+ const atts = (raw.blob_attachments || raw.attachments || []).filter(Boolean);
49
+
50
+ const mentions = {};
51
+ if (raw.message?.text && Array.isArray(raw.mentioned_users)) {
52
+ const text = raw.message.text;
53
+ raw.mentioned_users.forEach(u => {
54
+ const offset = u.entity?.offset ?? u.offset;
55
+ const len = u.entity?.length ?? u.length;
56
+ const id = u.entity?.id || u.id;
57
+ if (id != null && offset != null && len != null) {
58
+ mentions[String(id)] = text.substr(Number(offset), Number(len));
59
+ }
60
+ });
61
+ }
62
+
63
+ const reactions = {};
64
+ if (Array.isArray(raw.message_reactions)) {
65
+ for (const r of raw.message_reactions) {
66
+ const uid = String(r.user?.id || r.user_id || "");
67
+ const rx = r.reaction || "";
68
+ if (uid) reactions[uid] = REACTION_TYPES.has(rx) ? rx : rx;
69
+ }
70
+ }
71
+
72
+ return {
73
+ type: "message",
74
+ senderID: String(raw.message_sender?.id || raw.actor_id || extras.senderID || ""),
75
+ body: raw.message?.text || raw.body || "",
76
+ threadID: String(raw.thread_key?.thread_fbid || raw.thread_key?.other_user_id || extras.threadID || ""),
77
+ messageID: raw.message_id || raw.id || "",
78
+ clientOffset: raw.client_message_id || raw.offline_threading_id || null,
79
+ timestamp: raw.timestamp_precise ? Number(raw.timestamp_precise) : (raw.timestamp || Date.now()),
80
+ isEdited: raw.has_been_edited || !!raw.edit_count,
81
+ isUnsent: raw.is_unsent || false,
82
+ isSponsored: raw.is_sponsored || false,
83
+ isForwarded: raw.is_forwarded || false,
84
+ attachments: atts,
85
+ mentions,
86
+ reactions,
87
+ sticker: raw.sticker ? { id: raw.sticker.id } : null,
88
+ metadata: {
89
+ appID: raw.app_id || null,
90
+ isHidden: raw.is_hidden ?? false,
91
+ isBotResponse: raw.is_automated || false,
92
+ },
93
+ };
94
+ }
95
+
96
+ function buildThread(raw, users = {}) {
97
+ const threadID = String(raw.thread_key?.thread_fbid || raw.thread_key?.other_user_id || raw.threadID || "");
98
+ const isGroup = !!raw.thread_key?.thread_fbid;
99
+ const rawType = raw.thread_type || (isGroup ? "GROUP" : "USER");
100
+ const threadType = KNOWN_THREAD_TYPES.has(rawType) ? rawType : "USER";
101
+
102
+ const participantIDs = (raw.all_participants?.nodes || raw.participants || [])
103
+ .map(p => String(p.messaging_actor?.id || p.id || p))
104
+ .filter(Boolean);
105
+
106
+ const participants = {};
107
+ for (const [uid, u] of Object.entries(users)) {
108
+ if (participantIDs.includes(uid)) participants[uid] = u;
109
+ }
110
+
111
+ const colorRaw = raw.customization_info?.outgoing_bubble_color || raw.color;
112
+ const color = colorRaw ? `#${colorRaw.replace(/^#/, "")}` : THREAD_COLORS[0];
113
+
114
+ const emoji = raw.customization_info?.emoji || null;
115
+
116
+ const nicknames = {};
117
+ for (const n of (raw.customization_info?.participant_customizations || [])) {
118
+ const uid = String(n.participant_id || "");
119
+ const nick = n.nickname;
120
+ if (uid && nick) nicknames[uid] = nick;
121
+ }
122
+
123
+ return {
124
+ threadID,
125
+ name: raw.name || raw.thread_name || "",
126
+ snippet: raw.last_message?.nodes?.[0]?.message?.text || raw.snippet || "",
127
+ snippetSenderID: String(raw.last_message?.nodes?.[0]?.message_sender?.id || ""),
128
+ unreadCount: Number(raw.unread_count || 0),
129
+ messageCount: Number(raw.message_count || raw.messages_count || 0),
130
+ serverTimestamp: Number(raw.last_message?.nodes?.[0]?.timestamp_precise || raw.timestamp || Date.now()),
131
+ lastMessageTime: Number(raw.last_message?.nodes?.[0]?.timestamp_precise || raw.timestamp || Date.now()),
132
+ imageSrc: raw.image?.uri || raw.icon || null,
133
+ isArchived: raw.has_viewer_archived ?? raw.is_archived ?? false,
134
+ isSubscribed: raw.is_viewer_subscribed ?? true,
135
+ isMuted: raw.mute_until != null,
136
+ canReply: raw.can_reply ?? true,
137
+ color,
138
+ emoji,
139
+ nicknames,
140
+ isGroup,
141
+ threadType,
142
+ adminIDs: (raw.thread_admins || []).map(a => String(a.id || a)),
143
+ participantIDs,
144
+ participants,
145
+ updatedAt: Date.now(),
146
+ };
147
+ }
148
+
149
+ function validateMessage(msg, strict = false) {
150
+ const errs = [];
151
+ if (!msg) errs.push("message is null/undefined");
152
+ if (!msg?.senderID) errs.push("missing senderID");
153
+ if (typeof msg?.body !== "string") errs.push("body must be a string");
154
+ if (!msg?.threadID) errs.push("missing threadID");
155
+ if (strict && !msg?.messageID) errs.push("missing messageID");
156
+ return { valid: errs.length === 0, errors: errs };
157
+ }
158
+
159
+ module.exports = {
160
+ buildUser,
161
+ buildMessage,
162
+ buildThread,
163
+ validateMessage,
164
+ THREAD_COLORS,
165
+ KNOWN_THREAD_TYPES,
166
+ REACTION_TYPES,
167
+ };