@japofc/baileys 2.1.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.
- package/NOTICE.md +111 -0
- package/README.md +1254 -0
- package/WAProto/index.d.ts +9 -0
- package/WAProto/index.js +142276 -0
- package/engine-requirements.js +13 -0
- package/lib/Builders/A2UI.d.ts +242 -0
- package/lib/Builders/A2UI.js +308 -0
- package/lib/Builders/AIRich.d.ts +105 -0
- package/lib/Builders/AIRich.js +2286 -0
- package/lib/Builders/Button.d.ts +103 -0
- package/lib/Builders/Button.js +883 -0
- package/lib/Builders/ButtonV2.d.ts +28 -0
- package/lib/Builders/ButtonV2.js +144 -0
- package/lib/Builders/ButtonV3.d.ts +25 -0
- package/lib/Builders/ButtonV3.js +184 -0
- package/lib/Builders/Carousel.d.ts +22 -0
- package/lib/Builders/Carousel.js +111 -0
- package/lib/Builders/JapBaileys.d.ts +34 -0
- package/lib/Builders/JapBaileys.js +108 -0
- package/lib/Builders/Poll.d.ts +25 -0
- package/lib/Builders/Poll.js +128 -0
- package/lib/Builders/index.d.ts +17 -0
- package/lib/Builders/index.js +11 -0
- package/lib/Builders/shared.d.ts +67 -0
- package/lib/Builders/shared.js +652 -0
- package/lib/Defaults/index.d.ts +154 -0
- package/lib/Defaults/index.js +178 -0
- package/lib/Framework/Bot.d.ts +61 -0
- package/lib/Framework/Bot.js +248 -0
- package/lib/Framework/Context.d.ts +21 -0
- package/lib/Framework/Context.js +89 -0
- package/lib/Framework/MediaManager.d.ts +17 -0
- package/lib/Framework/MediaManager.js +151 -0
- package/lib/Framework/SessionManager.d.ts +13 -0
- package/lib/Framework/SessionManager.js +33 -0
- package/lib/Framework/StatsManager.d.ts +26 -0
- package/lib/Framework/StatsManager.js +119 -0
- package/lib/Framework/Store/SQLiteStore.d.ts +11 -0
- package/lib/Framework/Store/SQLiteStore.js +73 -0
- package/lib/Framework/index.d.ts +9 -0
- package/lib/Framework/index.js +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.d.ts +10 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.d.ts +54 -0
- package/lib/Signal/libsignal.js +430 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +276 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +5 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.d.ts +136 -0
- package/lib/Socket/chats.js +1327 -0
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.js +439 -0
- package/lib/Socket/dugong.d.ts +117 -0
- package/lib/Socket/dugong.js +798 -0
- package/lib/Socket/groups.d.ts +285 -0
- package/lib/Socket/groups.js +354 -0
- package/lib/Socket/index.d.ts +585 -0
- package/lib/Socket/index.js +52 -0
- package/lib/Socket/messages-recv.d.ts +333 -0
- package/lib/Socket/messages-recv.js +1781 -0
- package/lib/Socket/messages-send.d.ts +353 -0
- package/lib/Socket/messages-send.js +1524 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.d.ts +286 -0
- package/lib/Socket/newsletter.js +364 -0
- package/lib/Socket/socket.d.ts +60 -0
- package/lib/Socket/socket.js +1012 -0
- package/lib/Socket/username.d.ts +82 -0
- package/lib/Socket/username.js +159 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +3 -0
- package/lib/Store/make-in-memory-store.d.ts +62 -0
- package/lib/Store/make-in-memory-store.js +428 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +5 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +6 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +62 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.d.ts +2 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.d.ts +2 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +138 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +8 -0
- package/lib/Types/State.js +55 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/index.d.ts +68 -0
- package/lib/Types/index.js +27 -0
- package/lib/Utils/MessageBuilder.d.ts +2 -0
- package/lib/Utils/MessageBuilder.js +2 -0
- package/lib/Utils/PersistentStore.d.ts +60 -0
- package/lib/Utils/PersistentStore.js +592 -0
- package/lib/Utils/anti-delete.d.ts +74 -0
- package/lib/Utils/anti-delete.js +221 -0
- package/lib/Utils/auth-secure.d.ts +86 -0
- package/lib/Utils/auth-secure.js +764 -0
- package/lib/Utils/auth-utils.d.ts +57 -0
- package/lib/Utils/auth-utils.js +306 -0
- package/lib/Utils/auto-reply.d.ts +47 -0
- package/lib/Utils/auto-reply.js +157 -0
- package/lib/Utils/baileys-event-stream.d.ts +8 -0
- package/lib/Utils/baileys-event-stream.js +62 -0
- package/lib/Utils/browser-utils.d.ts +8 -0
- package/lib/Utils/browser-utils.js +27 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +239 -0
- package/lib/Utils/button-helper-utils.d.ts +53 -0
- package/lib/Utils/button-helper-utils.js +312 -0
- package/lib/Utils/button-sender.d.ts +54 -0
- package/lib/Utils/button-sender.js +822 -0
- package/lib/Utils/chat-control.d.ts +159 -0
- package/lib/Utils/chat-control.js +230 -0
- package/lib/Utils/chat-history-helpers.d.ts +21 -0
- package/lib/Utils/chat-history-helpers.js +70 -0
- package/lib/Utils/chat-utils.d.ts +407 -0
- package/lib/Utils/chat-utils.js +885 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +147 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +316 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +635 -0
- package/lib/Utils/generics.d.ts +69 -0
- package/lib/Utils/generics.js +438 -0
- package/lib/Utils/history-share.d.ts +11 -0
- package/lib/Utils/history-share.js +70 -0
- package/lib/Utils/history.d.ts +90 -0
- package/lib/Utils/history.js +146 -0
- package/lib/Utils/humanizer.d.ts +12 -0
- package/lib/Utils/humanizer.js +73 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/index.d.ts +57 -0
- package/lib/Utils/index.js +56 -0
- package/lib/Utils/jid-tools.d.ts +6 -0
- package/lib/Utils/jid-tools.js +77 -0
- package/lib/Utils/link-preview.d.ts +12 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +26 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/media-messages.d.ts +18 -0
- package/lib/Utils/media-messages.js +70 -0
- package/lib/Utils/media-set.d.ts +13 -0
- package/lib/Utils/media-set.js +171 -0
- package/lib/Utils/message-kind.d.ts +32 -0
- package/lib/Utils/message-kind.js +136 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +264 -0
- package/lib/Utils/message-search.d.ts +44 -0
- package/lib/Utils/message-search.js +188 -0
- package/lib/Utils/messages-media.d.ts +135 -0
- package/lib/Utils/messages-media.js +868 -0
- package/lib/Utils/messages.d.ts +44 -0
- package/lib/Utils/messages.js +2326 -0
- package/lib/Utils/meta-ai.d.ts +13 -0
- package/lib/Utils/meta-ai.js +74 -0
- package/lib/Utils/mini-app.d.ts +35 -0
- package/lib/Utils/mini-app.js +213 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.d.ts +9 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/past-participants.d.ts +14 -0
- package/lib/Utils/past-participants.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +25 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.d.ts +82 -0
- package/lib/Utils/process-message.js +808 -0
- package/lib/Utils/qr-render.d.ts +59 -0
- package/lib/Utils/qr-render.js +179 -0
- package/lib/Utils/qrcodegen.d.ts +79 -0
- package/lib/Utils/qrcodegen.js +848 -0
- package/lib/Utils/reporting-utils.d.ts +12 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +444 -0
- package/lib/Utils/router.d.ts +37 -0
- package/lib/Utils/router.js +165 -0
- package/lib/Utils/scheduled-posts.d.ts +30 -0
- package/lib/Utils/scheduled-posts.js +110 -0
- package/lib/Utils/scheduling.d.ts +42 -0
- package/lib/Utils/scheduling.js +139 -0
- package/lib/Utils/signal.d.ts +82 -0
- package/lib/Utils/signal.js +200 -0
- package/lib/Utils/stanza-ack.d.ts +16 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/status.d.ts +50 -0
- package/lib/Utils/status.js +107 -0
- package/lib/Utils/stickerpack.d.ts +51 -0
- package/lib/Utils/stickerpack.js +274 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tag.d.ts +12 -0
- package/lib/Utils/tag.js +44 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/templates.d.ts +76 -0
- package/lib/Utils/templates.js +150 -0
- package/lib/Utils/transcribe.d.ts +12 -0
- package/lib/Utils/transcribe.js +107 -0
- package/lib/Utils/use-cache-manager-auth-state.d.ts +13 -0
- package/lib/Utils/use-cache-manager-auth-state.js +81 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-multi-file-auth-state.js +166 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-single-file-auth-state.js +113 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +169 -0
- package/lib/Utils/validate-connection.d.ts +42 -0
- package/lib/Utils/validate-connection.js +198 -0
- package/lib/Utils/vcard.d.ts +58 -0
- package/lib/Utils/vcard.js +104 -0
- package/lib/Utils/voice-note.d.ts +15 -0
- package/lib/Utils/voice-note.js +63 -0
- package/lib/VoIP/audio-feeder.d.ts +18 -0
- package/lib/VoIP/audio-feeder.js +160 -0
- package/lib/VoIP/call-recorder.d.ts +13 -0
- package/lib/VoIP/call-recorder.js +73 -0
- package/lib/VoIP/index.d.ts +86 -0
- package/lib/VoIP/index.js +611 -0
- package/lib/VoIP/relay-transport.d.ts +43 -0
- package/lib/VoIP/relay-transport.js +563 -0
- package/lib/VoIP/signaling.d.ts +26 -0
- package/lib/VoIP/signaling.js +662 -0
- package/lib/VoIP/types.d.ts +69 -0
- package/lib/VoIP/types.js +17 -0
- package/lib/VoIP/wasm-engine.d.ts +120 -0
- package/lib/VoIP/wasm-engine.js +1358 -0
- package/lib/VoIP/worker-bootstrap.d.ts +4 -0
- package/lib/VoIP/worker-bootstrap.js +1046 -0
- package/lib/WABinary/constants.d.ts +61 -0
- package/lib/WABinary/constants.js +1466 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.d.ts +74 -0
- package/lib/WABinary/generic-utils.js +276 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.d.ts +7 -0
- package/lib/WAUSync/Protocols/index.js +7 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +121 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/assets/wasm/loader.d.ts +5 -0
- package/lib/assets/wasm/loader.js +5 -0
- package/lib/assets/wasm/whatsapp.wasm +0 -0
- package/lib/assets/wasm/worker-modules.d.ts +5 -0
- package/lib/assets/wasm/worker-modules.js +273 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +23 -0
- package/package.json +180 -0
- package/postinstall-banner.js +82 -0
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JAP@Note 03-02-26 [WIP]
|
|
3
|
+
* Manually converted to ESM and modified by me
|
|
4
|
+
* In-memory store: chats, contacts, and message history with event bindings
|
|
5
|
+
* Minor adjustments for compatibility with baileys v7 (つ≧▽≦)つ
|
|
6
|
+
*/
|
|
7
|
+
import keyedDB from '@adiwajshing/keyed-db';
|
|
8
|
+
import { writeFileSync, readFileSync, existsSync } from 'fs';
|
|
9
|
+
import { WAProto } from '../Types/index.js';
|
|
10
|
+
import { LabelAssociationType } from '../Types/LabelAssociation.js';
|
|
11
|
+
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
|
|
12
|
+
import { md5, toNumber, updateMessageWithReceipt, updateMessageWithReaction } from '../Utils/index.js';
|
|
13
|
+
import { jidDecode, jidNormalizedUser } from '../WABinary/index.js';
|
|
14
|
+
import { makeOrderedDictionary } from './make-ordered-dictionary.js';
|
|
15
|
+
import { ObjectRepository } from './object-repository.js';
|
|
16
|
+
export const waChatKey = (pin) => ({
|
|
17
|
+
key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
|
|
18
|
+
compare: (k1, k2) => k2.localeCompare(k1)
|
|
19
|
+
});
|
|
20
|
+
export const waMessageID = (m) => m.key.id || '';
|
|
21
|
+
export const waLabelAssociationKey = {
|
|
22
|
+
key: (la) => (la.type === LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
23
|
+
compare: (k1, k2) => k2.localeCompare(k1)
|
|
24
|
+
};
|
|
25
|
+
const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID);
|
|
26
|
+
export const makeInMemoryStore = (config = {}) => {
|
|
27
|
+
const socket = config.socket;
|
|
28
|
+
const chatKey = config.chatKey || waChatKey(true);
|
|
29
|
+
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey;
|
|
30
|
+
const logger = config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
|
|
31
|
+
const KeyedDB = keyedDB?.default ?? keyedDB; // JAP@Note 03-02-26 --- Handle CJS ↔ ESM default export differences ⊂(・ω・*⊂)
|
|
32
|
+
const chats = new KeyedDB(chatKey, c => c.id);
|
|
33
|
+
const messages = {};
|
|
34
|
+
const contacts = {};
|
|
35
|
+
const groupMetadata = {};
|
|
36
|
+
const presences = {};
|
|
37
|
+
const state = { connection: 'close' };
|
|
38
|
+
const labels = new ObjectRepository();
|
|
39
|
+
const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
|
|
40
|
+
const assertMessageList = (jid) => {
|
|
41
|
+
if (!messages[jid]) {
|
|
42
|
+
messages[jid] = makeMessagesDictionary();
|
|
43
|
+
}
|
|
44
|
+
return messages[jid];
|
|
45
|
+
};
|
|
46
|
+
const contactsUpsert = (newContacts) => {
|
|
47
|
+
const oldContacts = new Set(Object.keys(contacts));
|
|
48
|
+
for (const contact of newContacts) {
|
|
49
|
+
oldContacts.delete(contact.id);
|
|
50
|
+
contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact);
|
|
51
|
+
}
|
|
52
|
+
return oldContacts;
|
|
53
|
+
};
|
|
54
|
+
const labelsUpsert = (newLabels) => {
|
|
55
|
+
for (const label of newLabels) {
|
|
56
|
+
labels.upsertById(label.id, label);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* binds to a BaileysEventEmitter.
|
|
61
|
+
* It listens to all events and constructs a state that you can query accurate data from.
|
|
62
|
+
* Eg. can use the store to fetch chats, contacts, messages etc.
|
|
63
|
+
* @param ev typically the event emitter from the socket connection
|
|
64
|
+
*/
|
|
65
|
+
const bind = (ev) => {
|
|
66
|
+
ev.on('connection.update', update => {
|
|
67
|
+
Object.assign(state, update);
|
|
68
|
+
});
|
|
69
|
+
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
|
|
70
|
+
if (syncType === WAProto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
71
|
+
// JAP@Fix (bug 38): was early-returning without saving anything.
|
|
72
|
+
// ON_DEMAND is used when loading older messages (e.g. scroll-up / .q search).
|
|
73
|
+
// We should at minimum merge the messages into the store.
|
|
74
|
+
for (const msg of newMessages) {
|
|
75
|
+
const jid = msg.key.remoteJidAlt || msg.key.remoteJid;
|
|
76
|
+
const list = assertMessageList(jid);
|
|
77
|
+
list.upsert(msg, 'prepend');
|
|
78
|
+
}
|
|
79
|
+
logger.debug({ messages: newMessages.length }, 'synced ON_DEMAND messages');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (isLatest) {
|
|
83
|
+
chats.clear();
|
|
84
|
+
for (const id in messages) {
|
|
85
|
+
delete messages[id];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const chatsAdded = chats.insertIfAbsent(...newChats).length;
|
|
89
|
+
logger.debug({ chatsAdded }, 'synced chats');
|
|
90
|
+
const oldContacts = contactsUpsert(newContacts);
|
|
91
|
+
if (isLatest) {
|
|
92
|
+
for (const jid of oldContacts) {
|
|
93
|
+
delete contacts[jid];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts');
|
|
97
|
+
for (const msg of newMessages) {
|
|
98
|
+
const jid = msg.key.remoteJidAlt || msg.key.remoteJid;
|
|
99
|
+
const list = assertMessageList(jid);
|
|
100
|
+
list.upsert(msg, 'prepend');
|
|
101
|
+
}
|
|
102
|
+
logger.debug({ messages: newMessages.length }, 'synced messages');
|
|
103
|
+
});
|
|
104
|
+
ev.on('contacts.upsert', contacts => {
|
|
105
|
+
contactsUpsert(contacts);
|
|
106
|
+
});
|
|
107
|
+
ev.on('contacts.update', async (updates) => {
|
|
108
|
+
var _a;
|
|
109
|
+
for (const update of updates) {
|
|
110
|
+
let contact;
|
|
111
|
+
if (contacts[update.id]) {
|
|
112
|
+
contact = contacts[update.id];
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
|
|
116
|
+
const { user } = jidDecode(contactId);
|
|
117
|
+
return [contactId, (await md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
|
|
118
|
+
}));
|
|
119
|
+
contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
|
|
120
|
+
}
|
|
121
|
+
if (contact) {
|
|
122
|
+
if (update.imgUrl === 'changed') {
|
|
123
|
+
contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
|
|
124
|
+
}
|
|
125
|
+
else if (update.imgUrl === 'removed') {
|
|
126
|
+
delete contact.imgUrl;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
return logger.debug({ update }, 'got update for non-existant contact');
|
|
131
|
+
}
|
|
132
|
+
Object.assign(contacts[contact.id], contact);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
ev.on('chats.upsert', newChats => {
|
|
136
|
+
chats.upsert(...newChats);
|
|
137
|
+
});
|
|
138
|
+
ev.on('chats.update', updates => {
|
|
139
|
+
for (let update of updates) {
|
|
140
|
+
const result = chats.update(update.id, chat => {
|
|
141
|
+
if (update.unreadCount > 0) {
|
|
142
|
+
update = { ...update };
|
|
143
|
+
update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
|
|
144
|
+
}
|
|
145
|
+
Object.assign(chat, update);
|
|
146
|
+
});
|
|
147
|
+
if (!result) {
|
|
148
|
+
logger.debug({ update }, 'got update for non-existant chat');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
ev.on('labels.edit', (label) => {
|
|
153
|
+
if (label.deleted) {
|
|
154
|
+
return labels.deleteById(label.id);
|
|
155
|
+
}
|
|
156
|
+
// WhatsApp can store only up to 20 labels
|
|
157
|
+
if (labels.count() < 20) {
|
|
158
|
+
return labels.upsertById(label.id, label);
|
|
159
|
+
}
|
|
160
|
+
logger.error('Labels count exceed');
|
|
161
|
+
});
|
|
162
|
+
ev.on('labels.association', ({ type, association }) => {
|
|
163
|
+
switch (type) {
|
|
164
|
+
case 'add':
|
|
165
|
+
labelAssociations.upsert(association);
|
|
166
|
+
break;
|
|
167
|
+
case 'remove':
|
|
168
|
+
labelAssociations.delete(association);
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
console.error(`unknown operation type [${type}]`);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
ev.on('presence.update', ({ id, presences: update }) => {
|
|
175
|
+
presences[id] = presences[id] || {};
|
|
176
|
+
Object.assign(presences[id], update);
|
|
177
|
+
});
|
|
178
|
+
ev.on('chats.delete', deletions => {
|
|
179
|
+
for (const item of deletions) {
|
|
180
|
+
if (chats.get(item)) {
|
|
181
|
+
chats.deleteById(item);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
ev.on('messages.upsert', ({ messages: newMessages, type }) => {
|
|
186
|
+
switch (type) {
|
|
187
|
+
case 'append':
|
|
188
|
+
case 'notify':
|
|
189
|
+
for (const msg of newMessages) {
|
|
190
|
+
const jid = jidNormalizedUser(msg.key.remoteJidAlt || msg.key.remoteJid);
|
|
191
|
+
const list = assertMessageList(jid);
|
|
192
|
+
list.upsert(msg, 'append');
|
|
193
|
+
if (type === 'notify' && !chats.get(jid)) {
|
|
194
|
+
ev.emit('chats.upsert', [
|
|
195
|
+
{
|
|
196
|
+
id: jid,
|
|
197
|
+
conversationTimestamp: toNumber(msg.messageTimestamp),
|
|
198
|
+
unreadCount: 1
|
|
199
|
+
}
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
ev.on('messages.update', updates => {
|
|
207
|
+
var _a;
|
|
208
|
+
for (const { update, key } of updates) {
|
|
209
|
+
const list = assertMessageList(jidNormalizedUser(key.remoteJid));
|
|
210
|
+
if (update === null || update === void 0 ? void 0 : update.status) {
|
|
211
|
+
const listStatus = (_a = list.get(key.id)) === null || _a === void 0 ? void 0 : _a.status;
|
|
212
|
+
if (listStatus && (update === null || update === void 0 ? void 0 : update.status) <= listStatus) {
|
|
213
|
+
logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update');
|
|
214
|
+
delete update.status;
|
|
215
|
+
logger.debug({ update }, 'new update object');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const result = list.updateAssign(key.id, update);
|
|
219
|
+
if (!result) {
|
|
220
|
+
logger.debug({ update }, 'got update for non-existent message');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
ev.on('messages.delete', item => {
|
|
225
|
+
if ('all' in item) {
|
|
226
|
+
const list = messages[item.jid];
|
|
227
|
+
list === null || list === void 0 ? void 0 : list.clear();
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
const jid = item.keys[0].remoteJidAlt || item.keys[0].remoteJid;
|
|
231
|
+
const list = messages[jid];
|
|
232
|
+
if (list) {
|
|
233
|
+
const idSet = new Set(item.keys.map(k => k.id));
|
|
234
|
+
list.filter(m => !idSet.has(m.key.id));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
ev.on('groups.update', updates => {
|
|
239
|
+
for (const update of updates) {
|
|
240
|
+
const id = update.id;
|
|
241
|
+
if (groupMetadata[id]) {
|
|
242
|
+
Object.assign(groupMetadata[id], update);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
logger.debug({ update }, 'got update for non-existant group metadata');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
ev.on('group-participants.update', ({ id, participants, action }) => {
|
|
250
|
+
const metadata = groupMetadata[id];
|
|
251
|
+
if (metadata) {
|
|
252
|
+
switch (action) {
|
|
253
|
+
case 'add':
|
|
254
|
+
metadata.participants.push(...participants.map(participant => ({ id: participant.id, phoneNumber: participant.phoneNumber, admin: participant.admin })));
|
|
255
|
+
break;
|
|
256
|
+
case 'demote':
|
|
257
|
+
case 'promote':
|
|
258
|
+
for (const participant of metadata.participants) {
|
|
259
|
+
for (const participantData of participants) {
|
|
260
|
+
if (participantData.id === participant.id || participantData.phoneNumber === participant.phoneNumber) {
|
|
261
|
+
participant.admin = action === 'promote' && 'admin';
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
break;
|
|
266
|
+
case 'remove':
|
|
267
|
+
const removeSet = new Set();
|
|
268
|
+
for (const p of participants) {
|
|
269
|
+
if (p.id)
|
|
270
|
+
removeSet.add(p.id);
|
|
271
|
+
if (p.phoneNumber)
|
|
272
|
+
removeSet.add(p.phoneNumber);
|
|
273
|
+
}
|
|
274
|
+
metadata.participants = metadata.participants.reduce((acc, p) => {
|
|
275
|
+
if (!removeSet.has(p.id) && !removeSet.has(p.phoneNumber))
|
|
276
|
+
acc.push(p);
|
|
277
|
+
return acc;
|
|
278
|
+
}, []);
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
ev.on('message-receipt.update', updates => {
|
|
284
|
+
for (const { key, receipt } of updates) {
|
|
285
|
+
const obj = messages[key.remoteJidAlt || key.remoteJid];
|
|
286
|
+
const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
|
|
287
|
+
if (msg) {
|
|
288
|
+
updateMessageWithReceipt(msg, receipt);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
ev.on('messages.reaction', (reactions) => {
|
|
293
|
+
for (const { key, reaction } of reactions) {
|
|
294
|
+
const obj = messages[key.remoteJidAlt || key.remoteJid];
|
|
295
|
+
const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
|
|
296
|
+
if (msg) {
|
|
297
|
+
updateMessageWithReaction(msg, reaction);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
const toJSON = () => ({
|
|
303
|
+
chats,
|
|
304
|
+
contacts,
|
|
305
|
+
messages,
|
|
306
|
+
labels,
|
|
307
|
+
labelAssociations
|
|
308
|
+
});
|
|
309
|
+
const fromJSON = (json) => {
|
|
310
|
+
chats.upsert(...json.chats);
|
|
311
|
+
labelAssociations.upsert(...json.labelAssociations || []);
|
|
312
|
+
contactsUpsert(Object.values(json.contacts));
|
|
313
|
+
labelsUpsert(Object.values(json.labels || {}));
|
|
314
|
+
for (const jid in json.messages) {
|
|
315
|
+
const list = assertMessageList(jid);
|
|
316
|
+
for (const msg of json.messages[jid]) {
|
|
317
|
+
list.upsert(WAProto.WebMessageInfo.fromObject(msg), 'append');
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
return {
|
|
322
|
+
chats,
|
|
323
|
+
contacts,
|
|
324
|
+
messages,
|
|
325
|
+
groupMetadata,
|
|
326
|
+
state,
|
|
327
|
+
presences,
|
|
328
|
+
labels,
|
|
329
|
+
labelAssociations,
|
|
330
|
+
bind,
|
|
331
|
+
/** loads messages from the store, if not found -- uses the legacy connection */
|
|
332
|
+
loadMessages: async (jid, count, cursor) => {
|
|
333
|
+
const list = assertMessageList(jid);
|
|
334
|
+
const mode = !cursor || 'before' in cursor ? 'before' : 'after';
|
|
335
|
+
const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined;
|
|
336
|
+
const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined;
|
|
337
|
+
let messages;
|
|
338
|
+
if (list && mode === 'before' && (!cursorKey || cursorValue)) {
|
|
339
|
+
if (cursorValue) {
|
|
340
|
+
const msgIdx = list.array.findIndex(m => m.key.id === (cursorKey === null || cursorKey === void 0 ? void 0 : cursorKey.id));
|
|
341
|
+
messages = list.array.slice(0, msgIdx);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
messages = list.array;
|
|
345
|
+
}
|
|
346
|
+
const diff = count - messages.length;
|
|
347
|
+
if (diff < 0) {
|
|
348
|
+
messages = messages.slice(-count); // get the last X messages
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
messages = [];
|
|
353
|
+
}
|
|
354
|
+
return messages;
|
|
355
|
+
},
|
|
356
|
+
/**
|
|
357
|
+
* Get all available labels for profile
|
|
358
|
+
*
|
|
359
|
+
* Keep in mind that the list is formed from predefined tags and tags
|
|
360
|
+
* that were "caught" during their editing.
|
|
361
|
+
*/
|
|
362
|
+
getLabels: () => {
|
|
363
|
+
return labels;
|
|
364
|
+
},
|
|
365
|
+
/**
|
|
366
|
+
* Get labels for chat
|
|
367
|
+
*
|
|
368
|
+
* @returns Label IDs
|
|
369
|
+
**/
|
|
370
|
+
getChatLabels: (chatId) => {
|
|
371
|
+
return labelAssociations.filter((la) => la.chatId === chatId).all();
|
|
372
|
+
},
|
|
373
|
+
/**
|
|
374
|
+
* Get labels for message
|
|
375
|
+
*
|
|
376
|
+
* @returns Label IDs
|
|
377
|
+
**/
|
|
378
|
+
getMessageLabels: (messageId) => {
|
|
379
|
+
const associations = labelAssociations
|
|
380
|
+
.filter((la) => la.messageId === messageId)
|
|
381
|
+
.all();
|
|
382
|
+
return associations.map(({ labelId }) => labelId);
|
|
383
|
+
},
|
|
384
|
+
loadMessage: async (jid, id) => { var _a; return (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.get(id); },
|
|
385
|
+
mostRecentMessage: async (jid) => {
|
|
386
|
+
var _a;
|
|
387
|
+
const message = (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.array.slice(-1)[0];
|
|
388
|
+
return message;
|
|
389
|
+
},
|
|
390
|
+
fetchImageUrl: async (jid, sock) => {
|
|
391
|
+
const contact = contacts[jid];
|
|
392
|
+
if (!contact) {
|
|
393
|
+
return sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid);
|
|
394
|
+
}
|
|
395
|
+
if (typeof contact.imgUrl === 'undefined') {
|
|
396
|
+
contact.imgUrl = await (sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid));
|
|
397
|
+
}
|
|
398
|
+
return contact.imgUrl;
|
|
399
|
+
},
|
|
400
|
+
fetchGroupMetadata: async (jid, sock) => {
|
|
401
|
+
if (!groupMetadata[jid]) {
|
|
402
|
+
const metadata = await (sock === null || sock === void 0 ? void 0 : sock.groupMetadata(jid));
|
|
403
|
+
if (metadata) {
|
|
404
|
+
groupMetadata[jid] = metadata;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return groupMetadata[jid];
|
|
408
|
+
},
|
|
409
|
+
fetchMessageReceipts: async ({ remoteJid, id }) => {
|
|
410
|
+
const list = messages[remoteJid];
|
|
411
|
+
const msg = list === null || list === void 0 ? void 0 : list.get(id);
|
|
412
|
+
return msg === null || msg === void 0 ? void 0 : msg.userReceipt;
|
|
413
|
+
},
|
|
414
|
+
toJSON,
|
|
415
|
+
fromJSON,
|
|
416
|
+
writeToFile: (path) => {
|
|
417
|
+
writeFileSync(path, JSON.stringify(toJSON()));
|
|
418
|
+
},
|
|
419
|
+
readFromFile: (path) => {
|
|
420
|
+
if (existsSync(path)) {
|
|
421
|
+
logger.debug({ path }, 'reading from file');
|
|
422
|
+
const jsonStr = readFileSync(path, { encoding: 'utf-8' });
|
|
423
|
+
const json = JSON.parse(jsonStr);
|
|
424
|
+
fromJSON(json);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function makeOrderedDictionary(idGetter: any): {
|
|
2
|
+
array: any[];
|
|
3
|
+
get: (id: any) => any;
|
|
4
|
+
upsert: (item: any, mode: any) => void;
|
|
5
|
+
update: (item: any) => boolean;
|
|
6
|
+
remove: (item: any) => boolean;
|
|
7
|
+
updateAssign: (id: any, update: any) => boolean;
|
|
8
|
+
clear: () => void;
|
|
9
|
+
filter: (contain: any) => void;
|
|
10
|
+
toJSON: () => any[];
|
|
11
|
+
fromJSON: (newItems: any) => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export function makeOrderedDictionary(idGetter) {
|
|
2
|
+
const array = [];
|
|
3
|
+
const dict = {};
|
|
4
|
+
const get = (id) => dict[id];
|
|
5
|
+
const update = (item) => {
|
|
6
|
+
const id = idGetter(item);
|
|
7
|
+
const idx = array.findIndex(i => idGetter(i) === id);
|
|
8
|
+
if (idx >= 0) {
|
|
9
|
+
array[idx] = item;
|
|
10
|
+
dict[id] = item;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
};
|
|
14
|
+
const upsert = (item, mode) => {
|
|
15
|
+
const id = idGetter(item);
|
|
16
|
+
if (get(id)) {
|
|
17
|
+
update(item);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
if (mode === 'append') {
|
|
21
|
+
array.push(item);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
array.splice(0, 0, item);
|
|
25
|
+
}
|
|
26
|
+
dict[id] = item;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const remove = (item) => {
|
|
30
|
+
const id = idGetter(item);
|
|
31
|
+
const idx = array.findIndex(i => idGetter(i) === id);
|
|
32
|
+
if (idx >= 0) {
|
|
33
|
+
array.splice(idx, 1);
|
|
34
|
+
delete dict[id];
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
array,
|
|
41
|
+
get,
|
|
42
|
+
upsert,
|
|
43
|
+
update,
|
|
44
|
+
remove,
|
|
45
|
+
updateAssign: (id, update) => {
|
|
46
|
+
const item = get(id);
|
|
47
|
+
if (item) {
|
|
48
|
+
Object.assign(item, update);
|
|
49
|
+
delete dict[id];
|
|
50
|
+
dict[idGetter(item)] = item;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
},
|
|
55
|
+
clear: () => {
|
|
56
|
+
array.splice(0, array.length);
|
|
57
|
+
for (const key of Object.keys(dict)) {
|
|
58
|
+
delete dict[key];
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
filter: (contain) => {
|
|
62
|
+
let i = 0;
|
|
63
|
+
while (i < array.length) {
|
|
64
|
+
if (!contain(array[i])) {
|
|
65
|
+
delete dict[idGetter(array[i])];
|
|
66
|
+
array.splice(i, 1);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
i += 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
toJSON: () => array,
|
|
74
|
+
fromJSON: (newItems) => {
|
|
75
|
+
array.splice(0, array.length, ...newItems);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class ObjectRepository {
|
|
2
|
+
constructor(entities?: {});
|
|
3
|
+
entityMap: Map<string, any>;
|
|
4
|
+
findById(id: any): any;
|
|
5
|
+
findAll(): any[];
|
|
6
|
+
upsertById(id: any, entity: any): Map<string, any>;
|
|
7
|
+
deleteById(id: any): boolean;
|
|
8
|
+
count(): number;
|
|
9
|
+
toJSON(): any[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class ObjectRepository {
|
|
2
|
+
constructor(entities = {}) {
|
|
3
|
+
this.entityMap = new Map(Object.entries(entities));
|
|
4
|
+
}
|
|
5
|
+
findById(id) {
|
|
6
|
+
return this.entityMap.get(id);
|
|
7
|
+
}
|
|
8
|
+
findAll() {
|
|
9
|
+
return Array.from(this.entityMap.values());
|
|
10
|
+
}
|
|
11
|
+
upsertById(id, entity) {
|
|
12
|
+
return this.entityMap.set(id, { ...entity });
|
|
13
|
+
}
|
|
14
|
+
deleteById(id) {
|
|
15
|
+
return this.entityMap.delete(id);
|
|
16
|
+
}
|
|
17
|
+
count() {
|
|
18
|
+
return this.entityMap.size;
|
|
19
|
+
}
|
|
20
|
+
toJSON() {
|
|
21
|
+
return this.findAll();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { proto } from '../../WAProto/index.js';
|
|
2
|
+
import type { Contact } from './Contact.js';
|
|
3
|
+
import type { MinimalMessage } from './Message.js';
|
|
4
|
+
export type KeyPair = {
|
|
5
|
+
public: Uint8Array;
|
|
6
|
+
private: Uint8Array;
|
|
7
|
+
};
|
|
8
|
+
export type SignedKeyPair = {
|
|
9
|
+
keyPair: KeyPair;
|
|
10
|
+
signature: Uint8Array;
|
|
11
|
+
keyId: number;
|
|
12
|
+
timestampS?: number;
|
|
13
|
+
};
|
|
14
|
+
export type ProtocolAddress = {
|
|
15
|
+
name: string;
|
|
16
|
+
deviceId: number;
|
|
17
|
+
};
|
|
18
|
+
export type SignalIdentity = {
|
|
19
|
+
identifier: ProtocolAddress;
|
|
20
|
+
identifierKey: Uint8Array;
|
|
21
|
+
};
|
|
22
|
+
export type LIDMapping = {
|
|
23
|
+
pn: string;
|
|
24
|
+
lid: string;
|
|
25
|
+
};
|
|
26
|
+
export type LTHashState = {
|
|
27
|
+
version: number;
|
|
28
|
+
hash: Buffer;
|
|
29
|
+
indexValueMap: {
|
|
30
|
+
[indexMacBase64: string]: {
|
|
31
|
+
valueMac: Uint8Array | Buffer;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export type SignalCreds = {
|
|
36
|
+
readonly signedIdentityKey: KeyPair;
|
|
37
|
+
readonly signedPreKey: SignedKeyPair;
|
|
38
|
+
readonly registrationId: number;
|
|
39
|
+
};
|
|
40
|
+
export type AccountSettings = {
|
|
41
|
+
/** unarchive chats when a new message is received */
|
|
42
|
+
unarchiveChats: boolean;
|
|
43
|
+
/** the default mode to start new conversations with */
|
|
44
|
+
defaultDisappearingMode?: Pick<any, 'ephemeralExpiration' | 'ephemeralSettingTimestamp'>;
|
|
45
|
+
};
|
|
46
|
+
export type AuthenticationCreds = SignalCreds & {
|
|
47
|
+
readonly noiseKey: KeyPair;
|
|
48
|
+
readonly pairingEphemeralKeyPair: KeyPair;
|
|
49
|
+
advSecretKey: string;
|
|
50
|
+
me?: Contact;
|
|
51
|
+
account?: any;
|
|
52
|
+
signalIdentities?: SignalIdentity[];
|
|
53
|
+
myAppStateKeyId?: string;
|
|
54
|
+
firstUnuploadedPreKeyId: number;
|
|
55
|
+
nextPreKeyId: number;
|
|
56
|
+
lastAccountSyncTimestamp?: number;
|
|
57
|
+
platform?: string;
|
|
58
|
+
processedHistoryMessages: MinimalMessage[];
|
|
59
|
+
/** number of times history & app state has been synced */
|
|
60
|
+
accountSyncCounter: number;
|
|
61
|
+
accountSettings: AccountSettings;
|
|
62
|
+
registered: boolean;
|
|
63
|
+
pairingCode: string | undefined;
|
|
64
|
+
lastPropHash: string | undefined;
|
|
65
|
+
routingInfo: Buffer | undefined;
|
|
66
|
+
additionalData?: any | undefined;
|
|
67
|
+
};
|
|
68
|
+
export type SignalDataTypeMap = {
|
|
69
|
+
'pre-key': KeyPair;
|
|
70
|
+
session: Uint8Array;
|
|
71
|
+
'sender-key': Uint8Array;
|
|
72
|
+
'sender-key-memory': {
|
|
73
|
+
[jid: string]: boolean;
|
|
74
|
+
};
|
|
75
|
+
'app-state-sync-key': any;
|
|
76
|
+
'app-state-sync-version': LTHashState;
|
|
77
|
+
'lid-mapping': string;
|
|
78
|
+
'device-list': string[];
|
|
79
|
+
tctoken: {
|
|
80
|
+
token: Buffer;
|
|
81
|
+
timestamp?: string;
|
|
82
|
+
senderTimestamp?: number;
|
|
83
|
+
};
|
|
84
|
+
'identity-key': Uint8Array;
|
|
85
|
+
};
|
|
86
|
+
export type SignalDataSet = {
|
|
87
|
+
[T in keyof SignalDataTypeMap]?: {
|
|
88
|
+
[id: string]: SignalDataTypeMap[T] | null;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
type Awaitable<T> = T | Promise<T>;
|
|
92
|
+
export type SignalKeyStore = {
|
|
93
|
+
get<T extends keyof SignalDataTypeMap>(type: T, ids: string[]): Awaitable<{
|
|
94
|
+
[id: string]: SignalDataTypeMap[T];
|
|
95
|
+
}>;
|
|
96
|
+
set(data: SignalDataSet): Awaitable<void>;
|
|
97
|
+
/** clear all the data in the store */
|
|
98
|
+
clear?(): Awaitable<void>;
|
|
99
|
+
};
|
|
100
|
+
export type SignalKeyStoreWithTransaction = SignalKeyStore & {
|
|
101
|
+
isInTransaction: () => boolean;
|
|
102
|
+
transaction<T>(exec: () => Promise<T>, key: string): Promise<T>;
|
|
103
|
+
};
|
|
104
|
+
export type TransactionCapabilityOptions = {
|
|
105
|
+
maxCommitRetries: number;
|
|
106
|
+
delayBetweenTriesMs: number;
|
|
107
|
+
};
|
|
108
|
+
export type SignalAuthState = {
|
|
109
|
+
creds: SignalCreds;
|
|
110
|
+
keys: SignalKeyStore | SignalKeyStoreWithTransaction;
|
|
111
|
+
};
|
|
112
|
+
export type AuthenticationState = {
|
|
113
|
+
creds: AuthenticationCreds;
|
|
114
|
+
keys: SignalKeyStore;
|
|
115
|
+
};
|
|
116
|
+
export {};
|
|
117
|
+
//# sourceMappingURL=Auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|